]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/platform/x86/samsung-laptop.c
samsung-laptop: dump model and version informations
[karo-tx-linux.git] / drivers / platform / x86 / samsung-laptop.c
1 /*
2  * Samsung Laptop driver
3  *
4  * Copyright (C) 2009,2011 Greg Kroah-Hartman (gregkh@suse.de)
5  * Copyright (C) 2009,2011 Novell Inc.
6  *
7  * This program is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License version 2 as published by
9  * the Free Software Foundation.
10  *
11  */
12 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13
14 #include <linux/kernel.h>
15 #include <linux/init.h>
16 #include <linux/module.h>
17 #include <linux/delay.h>
18 #include <linux/pci.h>
19 #include <linux/backlight.h>
20 #include <linux/leds.h>
21 #include <linux/fb.h>
22 #include <linux/dmi.h>
23 #include <linux/platform_device.h>
24 #include <linux/rfkill.h>
25 #include <linux/acpi.h>
26 #include <linux/seq_file.h>
27 #include <linux/debugfs.h>
28
29 /*
30  * This driver is needed because a number of Samsung laptops do not hook
31  * their control settings through ACPI.  So we have to poke around in the
32  * BIOS to do things like brightness values, and "special" key controls.
33  */
34
35 /*
36  * We have 0 - 8 as valid brightness levels.  The specs say that level 0 should
37  * be reserved by the BIOS (which really doesn't make much sense), we tell
38  * userspace that the value is 0 - 7 and then just tell the hardware 1 - 8
39  */
40 #define MAX_BRIGHT      0x07
41
42
43 #define SABI_IFACE_MAIN                 0x00
44 #define SABI_IFACE_SUB                  0x02
45 #define SABI_IFACE_COMPLETE             0x04
46 #define SABI_IFACE_DATA                 0x05
47
48 #define WL_STATUS_WLAN                  0x0
49 #define WL_STATUS_BT                    0x2
50
51 /* Structure get/set data using sabi */
52 struct sabi_data {
53         union {
54                 struct {
55                         u32 d0;
56                         u32 d1;
57                         u16 d2;
58                         u8  d3;
59                 };
60                 u8 data[11];
61         };
62 };
63
64 struct sabi_header_offsets {
65         u8 port;
66         u8 re_mem;
67         u8 iface_func;
68         u8 en_mem;
69         u8 data_offset;
70         u8 data_segment;
71 };
72
73 struct sabi_commands {
74         /*
75          * Brightness is 0 - 8, as described above.
76          * Value 0 is for the BIOS to use
77          */
78         u16 get_brightness;
79         u16 set_brightness;
80
81         /*
82          * first byte:
83          * 0x00 - wireless is off
84          * 0x01 - wireless is on
85          * second byte:
86          * 0x02 - 3G is off
87          * 0x03 - 3G is on
88          * TODO, verify 3G is correct, that doesn't seem right...
89          */
90         u16 get_wireless_button;
91         u16 set_wireless_button;
92
93         /* 0 is off, 1 is on */
94         u16 get_backlight;
95         u16 set_backlight;
96
97         /*
98          * 0x80 or 0x00 - no action
99          * 0x81 - recovery key pressed
100          */
101         u16 get_recovery_mode;
102         u16 set_recovery_mode;
103
104         /*
105          * on seclinux: 0 is low, 1 is high,
106          * on swsmi: 0 is normal, 1 is silent, 2 is turbo
107          */
108         u16 get_performance_level;
109         u16 set_performance_level;
110
111         /* 0x80 is off, 0x81 is on */
112         u16 get_battery_life_extender;
113         u16 set_battery_life_extender;
114
115         /* 0x80 is off, 0x81 is on */
116         u16 get_usb_charge;
117         u16 set_usb_charge;
118
119         /* the first byte is for bluetooth and the third one is for wlan */
120         u16 get_wireless_status;
121         u16 set_wireless_status;
122
123         /* 0x81 to read, (0x82 | level << 8) to set, 0xaabb to enable */
124         u16 kbd_backlight;
125
126         /*
127          * Tell the BIOS that Linux is running on this machine.
128          * 81 is on, 80 is off
129          */
130         u16 set_linux;
131 };
132
133 struct sabi_performance_level {
134         const char *name;
135         u16 value;
136 };
137
138 struct sabi_config {
139         int sabi_version;
140         const char *test_string;
141         u16 main_function;
142         const struct sabi_header_offsets header_offsets;
143         const struct sabi_commands commands;
144         const struct sabi_performance_level performance_levels[4];
145         u8 min_brightness;
146         u8 max_brightness;
147 };
148
149 static const struct sabi_config sabi_configs[] = {
150         {
151                 /* I don't know if it is really 2, but it it is
152                  * less than 3 anyway */
153                 .sabi_version = 2,
154
155                 .test_string = "SECLINUX",
156
157                 .main_function = 0x4c49,
158
159                 .header_offsets = {
160                         .port = 0x00,
161                         .re_mem = 0x02,
162                         .iface_func = 0x03,
163                         .en_mem = 0x04,
164                         .data_offset = 0x05,
165                         .data_segment = 0x07,
166                 },
167
168                 .commands = {
169                         .get_brightness = 0x00,
170                         .set_brightness = 0x01,
171
172                         .get_wireless_button = 0x02,
173                         .set_wireless_button = 0x03,
174
175                         .get_backlight = 0x04,
176                         .set_backlight = 0x05,
177
178                         .get_recovery_mode = 0x06,
179                         .set_recovery_mode = 0x07,
180
181                         .get_performance_level = 0x08,
182                         .set_performance_level = 0x09,
183
184                         .get_battery_life_extender = 0xFFFF,
185                         .set_battery_life_extender = 0xFFFF,
186
187                         .get_usb_charge = 0xFFFF,
188                         .set_usb_charge = 0xFFFF,
189
190                         .get_wireless_status = 0xFFFF,
191                         .set_wireless_status = 0xFFFF,
192
193                         .kbd_backlight = 0xFFFF,
194
195                         .set_linux = 0x0a,
196                 },
197
198                 .performance_levels = {
199                         {
200                                 .name = "silent",
201                                 .value = 0,
202                         },
203                         {
204                                 .name = "normal",
205                                 .value = 1,
206                         },
207                         { },
208                 },
209                 .min_brightness = 1,
210                 .max_brightness = 8,
211         },
212         {
213                 .sabi_version = 3,
214
215                 .test_string = "SwSmi@",
216
217                 .main_function = 0x5843,
218
219                 .header_offsets = {
220                         .port = 0x00,
221                         .re_mem = 0x04,
222                         .iface_func = 0x02,
223                         .en_mem = 0x03,
224                         .data_offset = 0x05,
225                         .data_segment = 0x07,
226                 },
227
228                 .commands = {
229                         .get_brightness = 0x10,
230                         .set_brightness = 0x11,
231
232                         .get_wireless_button = 0x12,
233                         .set_wireless_button = 0x13,
234
235                         .get_backlight = 0x2d,
236                         .set_backlight = 0x2e,
237
238                         .get_recovery_mode = 0xff,
239                         .set_recovery_mode = 0xff,
240
241                         .get_performance_level = 0x31,
242                         .set_performance_level = 0x32,
243
244                         .get_battery_life_extender = 0x65,
245                         .set_battery_life_extender = 0x66,
246
247                         .get_usb_charge = 0x67,
248                         .set_usb_charge = 0x68,
249
250                         .get_wireless_status = 0x69,
251                         .set_wireless_status = 0x6a,
252
253                         .kbd_backlight = 0x78,
254
255                         .set_linux = 0xff,
256                 },
257
258                 .performance_levels = {
259                         {
260                                 .name = "normal",
261                                 .value = 0,
262                         },
263                         {
264                                 .name = "silent",
265                                 .value = 1,
266                         },
267                         {
268                                 .name = "overclock",
269                                 .value = 2,
270                         },
271                         { },
272                 },
273                 .min_brightness = 0,
274                 .max_brightness = 8,
275         },
276         { },
277 };
278
279 /*
280  * samsung-laptop/    - debugfs root directory
281  *   f0000_segment    - dump f0000 segment
282  *   command          - current command
283  *   data             - current data
284  *   d0, d1, d2, d3   - data fields
285  *   call             - call SABI using command and data
286  *
287  * This allow to call arbitrary sabi commands wihout
288  * modifying the driver at all.
289  * For example, setting the keyboard backlight brightness to 5
290  *
291  *  echo 0x78 > command
292  *  echo 0x0582 > d0
293  *  echo 0 > d1
294  *  echo 0 > d2
295  *  echo 0 > d3
296  *  cat call
297  */
298
299 struct samsung_laptop_debug {
300         struct dentry *root;
301         struct sabi_data data;
302         u16 command;
303
304         struct debugfs_blob_wrapper f0000_wrapper;
305         struct debugfs_blob_wrapper data_wrapper;
306         struct debugfs_blob_wrapper sdiag_wrapper;
307 };
308
309 struct samsung_laptop;
310
311 struct samsung_rfkill {
312         struct samsung_laptop *samsung;
313         struct rfkill *rfkill;
314         enum rfkill_type type;
315 };
316
317 struct samsung_laptop {
318         const struct sabi_config *config;
319
320         void __iomem *sabi;
321         void __iomem *sabi_iface;
322         void __iomem *f0000_segment;
323
324         struct mutex sabi_mutex;
325
326         struct platform_device *platform_device;
327         struct backlight_device *backlight_device;
328
329         struct samsung_rfkill wlan;
330         struct samsung_rfkill bluetooth;
331
332         struct led_classdev kbd_led;
333         int kbd_led_wk;
334         struct workqueue_struct *led_workqueue;
335         struct work_struct kbd_led_work;
336
337         struct samsung_laptop_debug debug;
338
339         bool handle_backlight;
340         bool has_stepping_quirk;
341
342         char sdiag[64];
343 };
344
345
346
347 static bool force;
348 module_param(force, bool, 0);
349 MODULE_PARM_DESC(force,
350                 "Disable the DMI check and forces the driver to be loaded");
351
352 static bool debug;
353 module_param(debug, bool, S_IRUGO | S_IWUSR);
354 MODULE_PARM_DESC(debug, "Debug enabled or not");
355
356 static int sabi_command(struct samsung_laptop *samsung, u16 command,
357                         struct sabi_data *in,
358                         struct sabi_data *out)
359 {
360         const struct sabi_config *config = samsung->config;
361         int ret = 0;
362         u16 port = readw(samsung->sabi + config->header_offsets.port);
363         u8 complete, iface_data;
364
365         mutex_lock(&samsung->sabi_mutex);
366
367         if (debug) {
368                 if (in)
369                         pr_info("SABI 0x%04x {0x%08x, 0x%08x, 0x%04x, 0x%02x}",
370                                 command, in->d0, in->d1, in->d2, in->d3);
371                 else
372                         pr_info("SABI 0x%04x", command);
373         }
374
375         /* enable memory to be able to write to it */
376         outb(readb(samsung->sabi + config->header_offsets.en_mem), port);
377
378         /* write out the command */
379         writew(config->main_function, samsung->sabi_iface + SABI_IFACE_MAIN);
380         writew(command, samsung->sabi_iface + SABI_IFACE_SUB);
381         writeb(0, samsung->sabi_iface + SABI_IFACE_COMPLETE);
382         if (in) {
383                 writel(in->d0, samsung->sabi_iface + SABI_IFACE_DATA);
384                 writel(in->d1, samsung->sabi_iface + SABI_IFACE_DATA + 4);
385                 writew(in->d2, samsung->sabi_iface + SABI_IFACE_DATA + 8);
386                 writeb(in->d3, samsung->sabi_iface + SABI_IFACE_DATA + 10);
387         }
388         outb(readb(samsung->sabi + config->header_offsets.iface_func), port);
389
390         /* write protect memory to make it safe */
391         outb(readb(samsung->sabi + config->header_offsets.re_mem), port);
392
393         /* see if the command actually succeeded */
394         complete = readb(samsung->sabi_iface + SABI_IFACE_COMPLETE);
395         iface_data = readb(samsung->sabi_iface + SABI_IFACE_DATA);
396         if (complete != 0xaa || iface_data == 0xff) {
397                 pr_warn("SABI command 0x%04x failed with"
398                         " completion flag 0x%02x and interface data 0x%02x",
399                         command, complete, iface_data);
400                 ret = -EINVAL;
401                 goto exit;
402         }
403
404         if (out) {
405                 out->d0 = readl(samsung->sabi_iface + SABI_IFACE_DATA);
406                 out->d1 = readl(samsung->sabi_iface + SABI_IFACE_DATA + 4);
407                 out->d2 = readw(samsung->sabi_iface + SABI_IFACE_DATA + 2);
408                 out->d3 = readb(samsung->sabi_iface + SABI_IFACE_DATA + 1);
409         }
410
411         if (debug && out) {
412                 pr_info("SABI {0x%08x, 0x%08x, 0x%04x, 0x%02x}",
413                         out->d0, out->d1, out->d2, out->d3);
414         }
415
416 exit:
417         mutex_unlock(&samsung->sabi_mutex);
418         return ret;
419 }
420
421 /* simple wrappers usable with most commands */
422 static int sabi_set_commandb(struct samsung_laptop *samsung,
423                              u16 command, u8 data)
424 {
425         struct sabi_data in = { .d0 = 0, .d1 = 0, .d2 = 0, .d3 = 0 };
426
427         in.data[0] = data;
428         return sabi_command(samsung, command, &in, NULL);
429 }
430
431 static int read_brightness(struct samsung_laptop *samsung)
432 {
433         const struct sabi_config *config = samsung->config;
434         const struct sabi_commands *commands = &samsung->config->commands;
435         struct sabi_data sretval;
436         int user_brightness = 0;
437         int retval;
438
439         retval = sabi_command(samsung, commands->get_brightness,
440                               NULL, &sretval);
441         if (retval)
442                 return retval;
443
444         user_brightness = sretval.data[0];
445         if (user_brightness > config->min_brightness)
446                 user_brightness -= config->min_brightness;
447         else
448                 user_brightness = 0;
449
450         return user_brightness;
451 }
452
453 static void set_brightness(struct samsung_laptop *samsung, u8 user_brightness)
454 {
455         const struct sabi_config *config = samsung->config;
456         const struct sabi_commands *commands = &samsung->config->commands;
457         u8 user_level = user_brightness + config->min_brightness;
458
459         if (samsung->has_stepping_quirk && user_level != 0) {
460                 /*
461                  * short circuit if the specified level is what's already set
462                  * to prevent the screen from flickering needlessly
463                  */
464                 if (user_brightness == read_brightness(samsung))
465                         return;
466
467                 sabi_set_commandb(samsung, commands->set_brightness, 0);
468         }
469
470         sabi_set_commandb(samsung, commands->set_brightness, user_level);
471 }
472
473 static int get_brightness(struct backlight_device *bd)
474 {
475         struct samsung_laptop *samsung = bl_get_data(bd);
476
477         return read_brightness(samsung);
478 }
479
480 static void check_for_stepping_quirk(struct samsung_laptop *samsung)
481 {
482         int initial_level;
483         int check_level;
484         int orig_level = read_brightness(samsung);
485
486         /*
487          * Some laptops exhibit the strange behaviour of stepping toward
488          * (rather than setting) the brightness except when changing to/from
489          * brightness level 0. This behaviour is checked for here and worked
490          * around in set_brightness.
491          */
492
493         if (orig_level == 0)
494                 set_brightness(samsung, 1);
495
496         initial_level = read_brightness(samsung);
497
498         if (initial_level <= 2)
499                 check_level = initial_level + 2;
500         else
501                 check_level = initial_level - 2;
502
503         samsung->has_stepping_quirk = false;
504         set_brightness(samsung, check_level);
505
506         if (read_brightness(samsung) != check_level) {
507                 samsung->has_stepping_quirk = true;
508                 pr_info("enabled workaround for brightness stepping quirk\n");
509         }
510
511         set_brightness(samsung, orig_level);
512 }
513
514 static int update_status(struct backlight_device *bd)
515 {
516         struct samsung_laptop *samsung = bl_get_data(bd);
517         const struct sabi_commands *commands = &samsung->config->commands;
518
519         set_brightness(samsung, bd->props.brightness);
520
521         if (bd->props.power == FB_BLANK_UNBLANK)
522                 sabi_set_commandb(samsung, commands->set_backlight, 1);
523         else
524                 sabi_set_commandb(samsung, commands->set_backlight, 0);
525
526         return 0;
527 }
528
529 static const struct backlight_ops backlight_ops = {
530         .get_brightness = get_brightness,
531         .update_status  = update_status,
532 };
533
534 static int seclinux_rfkill_set(void *data, bool blocked)
535 {
536         struct samsung_laptop *samsung = data;
537         const struct sabi_commands *commands = &samsung->config->commands;
538
539         return sabi_set_commandb(samsung, commands->set_wireless_button,
540                                  !blocked);
541 }
542
543 static struct rfkill_ops seclinux_rfkill_ops = {
544         .set_block = seclinux_rfkill_set,
545 };
546
547 static int swsmi_wireless_status(struct samsung_laptop *samsung,
548                                  struct sabi_data *data)
549 {
550         const struct sabi_commands *commands = &samsung->config->commands;
551
552         return sabi_command(samsung, commands->get_wireless_status,
553                             NULL, data);
554 }
555
556 static int swsmi_rfkill_set(void *priv, bool blocked)
557 {
558         struct samsung_rfkill *srfkill = priv;
559         struct samsung_laptop *samsung = srfkill->samsung;
560         const struct sabi_commands *commands = &samsung->config->commands;
561         struct sabi_data data;
562         int ret, i;
563
564         ret = swsmi_wireless_status(samsung, &data);
565         if (ret)
566                 return ret;
567
568         /* Don't set the state for non-present devices */
569         for (i = 0; i < 4; i++)
570                 if (data.data[i] == 0x02)
571                         data.data[1] = 0;
572
573         if (srfkill->type == RFKILL_TYPE_WLAN)
574                 data.data[WL_STATUS_WLAN] = !blocked;
575         else if (srfkill->type == RFKILL_TYPE_BLUETOOTH)
576                 data.data[WL_STATUS_BT] = !blocked;
577
578         return sabi_command(samsung, commands->set_wireless_status,
579                             &data, &data);
580 }
581
582 static void swsmi_rfkill_query(struct rfkill *rfkill, void *priv)
583 {
584         struct samsung_rfkill *srfkill = priv;
585         struct samsung_laptop *samsung = srfkill->samsung;
586         struct sabi_data data;
587         int ret;
588
589         ret = swsmi_wireless_status(samsung, &data);
590         if (ret)
591                 return ;
592
593         if (srfkill->type == RFKILL_TYPE_WLAN)
594                 ret = data.data[WL_STATUS_WLAN];
595         else if (srfkill->type == RFKILL_TYPE_BLUETOOTH)
596                 ret = data.data[WL_STATUS_BT];
597         else
598                 return ;
599
600         rfkill_set_sw_state(rfkill, !ret);
601 }
602
603 static struct rfkill_ops swsmi_rfkill_ops = {
604         .set_block = swsmi_rfkill_set,
605         .query = swsmi_rfkill_query,
606 };
607
608 static ssize_t get_performance_level(struct device *dev,
609                                      struct device_attribute *attr, char *buf)
610 {
611         struct samsung_laptop *samsung = dev_get_drvdata(dev);
612         const struct sabi_config *config = samsung->config;
613         const struct sabi_commands *commands = &config->commands;
614         struct sabi_data sretval;
615         int retval;
616         int i;
617
618         /* Read the state */
619         retval = sabi_command(samsung, commands->get_performance_level,
620                               NULL, &sretval);
621         if (retval)
622                 return retval;
623
624         /* The logic is backwards, yeah, lots of fun... */
625         for (i = 0; config->performance_levels[i].name; ++i) {
626                 if (sretval.data[0] == config->performance_levels[i].value)
627                         return sprintf(buf, "%s\n", config->performance_levels[i].name);
628         }
629         return sprintf(buf, "%s\n", "unknown");
630 }
631
632 static ssize_t set_performance_level(struct device *dev,
633                                 struct device_attribute *attr, const char *buf,
634                                 size_t count)
635 {
636         struct samsung_laptop *samsung = dev_get_drvdata(dev);
637         const struct sabi_config *config = samsung->config;
638         const struct sabi_commands *commands = &config->commands;
639         int i;
640
641         if (count < 1)
642                 return count;
643
644         for (i = 0; config->performance_levels[i].name; ++i) {
645                 const struct sabi_performance_level *level =
646                         &config->performance_levels[i];
647                 if (!strncasecmp(level->name, buf, strlen(level->name))) {
648                         sabi_set_commandb(samsung,
649                                           commands->set_performance_level,
650                                           level->value);
651                         break;
652                 }
653         }
654
655         if (!config->performance_levels[i].name)
656                 return -EINVAL;
657
658         return count;
659 }
660
661 static DEVICE_ATTR(performance_level, S_IWUSR | S_IRUGO,
662                    get_performance_level, set_performance_level);
663
664 static int read_battery_life_extender(struct samsung_laptop *samsung)
665 {
666         const struct sabi_commands *commands = &samsung->config->commands;
667         struct sabi_data data;
668         int retval;
669
670         if (commands->get_battery_life_extender == 0xFFFF)
671                 return -ENODEV;
672
673         memset(&data, 0, sizeof(data));
674         data.data[0] = 0x80;
675         retval = sabi_command(samsung, commands->get_battery_life_extender,
676                               &data, &data);
677
678         if (retval)
679                 return retval;
680
681         if (data.data[0] != 0 && data.data[0] != 1)
682                 return -ENODEV;
683
684         return data.data[0];
685 }
686
687 static int write_battery_life_extender(struct samsung_laptop *samsung,
688                                        int enabled)
689 {
690         const struct sabi_commands *commands = &samsung->config->commands;
691         struct sabi_data data;
692
693         memset(&data, 0, sizeof(data));
694         data.data[0] = 0x80 | enabled;
695         return sabi_command(samsung, commands->set_battery_life_extender,
696                             &data, NULL);
697 }
698
699 static ssize_t get_battery_life_extender(struct device *dev,
700                                          struct device_attribute *attr,
701                                          char *buf)
702 {
703         struct samsung_laptop *samsung = dev_get_drvdata(dev);
704         int ret;
705
706         ret = read_battery_life_extender(samsung);
707         if (ret < 0)
708                 return ret;
709
710         return sprintf(buf, "%d\n", ret);
711 }
712
713 static ssize_t set_battery_life_extender(struct device *dev,
714                                         struct device_attribute *attr,
715                                         const char *buf, size_t count)
716 {
717         struct samsung_laptop *samsung = dev_get_drvdata(dev);
718         int ret, value;
719
720         if (!count || sscanf(buf, "%i", &value) != 1)
721                 return -EINVAL;
722
723         ret = write_battery_life_extender(samsung, !!value);
724         if (ret < 0)
725                 return ret;
726
727         return count;
728 }
729
730 static DEVICE_ATTR(battery_life_extender, S_IWUSR | S_IRUGO,
731                    get_battery_life_extender, set_battery_life_extender);
732
733 static int read_usb_charge(struct samsung_laptop *samsung)
734 {
735         const struct sabi_commands *commands = &samsung->config->commands;
736         struct sabi_data data;
737         int retval;
738
739         if (commands->get_usb_charge == 0xFFFF)
740                 return -ENODEV;
741
742         memset(&data, 0, sizeof(data));
743         data.data[0] = 0x80;
744         retval = sabi_command(samsung, commands->get_usb_charge,
745                               &data, &data);
746
747         if (retval)
748                 return retval;
749
750         if (data.data[0] != 0 && data.data[0] != 1)
751                 return -ENODEV;
752
753         return data.data[0];
754 }
755
756 static int write_usb_charge(struct samsung_laptop *samsung,
757                             int enabled)
758 {
759         const struct sabi_commands *commands = &samsung->config->commands;
760         struct sabi_data data;
761
762         memset(&data, 0, sizeof(data));
763         data.data[0] = 0x80 | enabled;
764         return sabi_command(samsung, commands->set_usb_charge,
765                             &data, NULL);
766 }
767
768 static ssize_t get_usb_charge(struct device *dev,
769                               struct device_attribute *attr,
770                               char *buf)
771 {
772         struct samsung_laptop *samsung = dev_get_drvdata(dev);
773         int ret;
774
775         ret = read_usb_charge(samsung);
776         if (ret < 0)
777                 return ret;
778
779         return sprintf(buf, "%d\n", ret);
780 }
781
782 static ssize_t set_usb_charge(struct device *dev,
783                               struct device_attribute *attr,
784                               const char *buf, size_t count)
785 {
786         struct samsung_laptop *samsung = dev_get_drvdata(dev);
787         int ret, value;
788
789         if (!count || sscanf(buf, "%i", &value) != 1)
790                 return -EINVAL;
791
792         ret = write_usb_charge(samsung, !!value);
793         if (ret < 0)
794                 return ret;
795
796         return count;
797 }
798
799 static DEVICE_ATTR(usb_charge, S_IWUSR | S_IRUGO,
800                    get_usb_charge, set_usb_charge);
801
802 static struct attribute *platform_attributes[] = {
803         &dev_attr_performance_level.attr,
804         &dev_attr_battery_life_extender.attr,
805         &dev_attr_usb_charge.attr,
806         NULL
807 };
808
809 static int find_signature(void __iomem *memcheck, const char *testStr)
810 {
811         int i = 0;
812         int loca;
813
814         for (loca = 0; loca < 0xffff; loca++) {
815                 char temp = readb(memcheck + loca);
816
817                 if (temp == testStr[i]) {
818                         if (i == strlen(testStr)-1)
819                                 break;
820                         ++i;
821                 } else {
822                         i = 0;
823                 }
824         }
825         return loca;
826 }
827
828 static void samsung_rfkill_exit(struct samsung_laptop *samsung)
829 {
830         if (samsung->wlan.rfkill) {
831                 rfkill_unregister(samsung->wlan.rfkill);
832                 rfkill_destroy(samsung->wlan.rfkill);
833                 samsung->wlan.rfkill = NULL;
834         }
835         if (samsung->bluetooth.rfkill) {
836                 rfkill_unregister(samsung->bluetooth.rfkill);
837                 rfkill_destroy(samsung->bluetooth.rfkill);
838                 samsung->bluetooth.rfkill = NULL;
839         }
840 }
841
842 static int samsung_new_rfkill(struct samsung_laptop *samsung,
843                               struct samsung_rfkill *arfkill,
844                               const char *name, enum rfkill_type type,
845                               const struct rfkill_ops *ops,
846                               int blocked)
847 {
848         struct rfkill **rfkill = &arfkill->rfkill;
849         int ret;
850
851         arfkill->type = type;
852         arfkill->samsung = samsung;
853
854         *rfkill = rfkill_alloc(name, &samsung->platform_device->dev,
855                                type, ops, arfkill);
856
857         if (!*rfkill)
858                 return -EINVAL;
859
860         if (blocked != -1)
861                 rfkill_init_sw_state(*rfkill, blocked);
862
863         ret = rfkill_register(*rfkill);
864         if (ret) {
865                 rfkill_destroy(*rfkill);
866                 *rfkill = NULL;
867                 return ret;
868         }
869         return 0;
870 }
871
872 static int __init samsung_rfkill_init_seclinux(struct samsung_laptop *samsung)
873 {
874         return samsung_new_rfkill(samsung, &samsung->wlan, "samsung-wlan",
875                                   RFKILL_TYPE_WLAN, &seclinux_rfkill_ops, -1);
876 }
877
878 static int __init samsung_rfkill_init_swsmi(struct samsung_laptop *samsung)
879 {
880         struct sabi_data data;
881         int ret;
882
883         ret = swsmi_wireless_status(samsung, &data);
884         if (ret)
885                 return ret;
886
887         /* 0x02 seems to mean that the device is no present/available */
888
889         if (data.data[WL_STATUS_WLAN] != 0x02)
890                 ret = samsung_new_rfkill(samsung, &samsung->wlan,
891                                          "samsung-wlan",
892                                          RFKILL_TYPE_WLAN,
893                                          &swsmi_rfkill_ops,
894                                          !data.data[WL_STATUS_WLAN]);
895         if (ret)
896                 goto exit;
897
898         if (data.data[WL_STATUS_BT] != 0x02)
899                 ret = samsung_new_rfkill(samsung, &samsung->bluetooth,
900                                          "samsung-bluetooth",
901                                          RFKILL_TYPE_BLUETOOTH,
902                                          &swsmi_rfkill_ops,
903                                          !data.data[WL_STATUS_BT]);
904         if (ret)
905                 goto exit;
906
907 exit:
908         if (ret)
909                 samsung_rfkill_exit(samsung);
910
911         return ret;
912 }
913
914 static int __init samsung_rfkill_init(struct samsung_laptop *samsung)
915 {
916         if (samsung->config->sabi_version == 2)
917                 return samsung_rfkill_init_seclinux(samsung);
918         if (samsung->config->sabi_version == 3)
919                 return samsung_rfkill_init_swsmi(samsung);
920         return 0;
921 }
922
923 static int kbd_backlight_enable(struct samsung_laptop *samsung)
924 {
925         const struct sabi_commands *commands = &samsung->config->commands;
926         struct sabi_data data;
927         int retval;
928
929         if (commands->kbd_backlight == 0xFFFF)
930                 return -ENODEV;
931
932         memset(&data, 0, sizeof(data));
933         data.d0 = 0xaabb;
934         retval = sabi_command(samsung, commands->kbd_backlight,
935                               &data, &data);
936
937         if (retval)
938                 return retval;
939
940         if (data.d0 != 0xccdd)
941                 return -ENODEV;
942         return 0;
943 }
944
945 static int kbd_backlight_read(struct samsung_laptop *samsung)
946 {
947         const struct sabi_commands *commands = &samsung->config->commands;
948         struct sabi_data data;
949         int retval;
950
951         memset(&data, 0, sizeof(data));
952         data.data[0] = 0x81;
953         retval = sabi_command(samsung, commands->kbd_backlight,
954                               &data, &data);
955
956         if (retval)
957                 return retval;
958
959         return data.data[0];
960 }
961
962 static int kbd_backlight_write(struct samsung_laptop *samsung, int brightness)
963 {
964         const struct sabi_commands *commands = &samsung->config->commands;
965         struct sabi_data data;
966
967         memset(&data, 0, sizeof(data));
968         data.d0 = 0x82 | ((brightness & 0xFF) << 8);
969         return sabi_command(samsung, commands->kbd_backlight,
970                             &data, NULL);
971 }
972
973 static void kbd_led_update(struct work_struct *work)
974 {
975         struct samsung_laptop *samsung;
976
977         samsung = container_of(work, struct samsung_laptop, kbd_led_work);
978         kbd_backlight_write(samsung, samsung->kbd_led_wk);
979 }
980
981 static void kbd_led_set(struct led_classdev *led_cdev,
982                         enum led_brightness value)
983 {
984         struct samsung_laptop *samsung;
985
986         samsung = container_of(led_cdev, struct samsung_laptop, kbd_led);
987
988         if (value > samsung->kbd_led.max_brightness)
989                 value = samsung->kbd_led.max_brightness;
990         else if (value < 0)
991                 value = 0;
992
993         samsung->kbd_led_wk = value;
994         queue_work(samsung->led_workqueue, &samsung->kbd_led_work);
995 }
996
997 static enum led_brightness kbd_led_get(struct led_classdev *led_cdev)
998 {
999         struct samsung_laptop *samsung;
1000
1001         samsung = container_of(led_cdev, struct samsung_laptop, kbd_led);
1002         return kbd_backlight_read(samsung);
1003 }
1004
1005 static void samsung_leds_exit(struct samsung_laptop *samsung)
1006 {
1007         if (!IS_ERR_OR_NULL(samsung->kbd_led.dev))
1008                 led_classdev_unregister(&samsung->kbd_led);
1009         if (samsung->led_workqueue)
1010                 destroy_workqueue(samsung->led_workqueue);
1011 }
1012
1013 static int __init samsung_leds_init(struct samsung_laptop *samsung)
1014 {
1015         int ret = 0;
1016
1017         samsung->led_workqueue = create_singlethread_workqueue("led_workqueue");
1018         if (!samsung->led_workqueue)
1019                 return -ENOMEM;
1020
1021         if (kbd_backlight_enable(samsung) >= 0) {
1022                 INIT_WORK(&samsung->kbd_led_work, kbd_led_update);
1023
1024                 samsung->kbd_led.name = "samsung::kbd_backlight";
1025                 samsung->kbd_led.brightness_set = kbd_led_set;
1026                 samsung->kbd_led.brightness_get = kbd_led_get;
1027                 samsung->kbd_led.max_brightness = 8;
1028
1029                 ret = led_classdev_register(&samsung->platform_device->dev,
1030                                            &samsung->kbd_led);
1031         }
1032
1033         if (ret)
1034                 samsung_leds_exit(samsung);
1035
1036         return ret;
1037 }
1038
1039 static void samsung_backlight_exit(struct samsung_laptop *samsung)
1040 {
1041         if (samsung->backlight_device) {
1042                 backlight_device_unregister(samsung->backlight_device);
1043                 samsung->backlight_device = NULL;
1044         }
1045 }
1046
1047 static int __init samsung_backlight_init(struct samsung_laptop *samsung)
1048 {
1049         struct backlight_device *bd;
1050         struct backlight_properties props;
1051
1052         if (!samsung->handle_backlight)
1053                 return 0;
1054
1055         memset(&props, 0, sizeof(struct backlight_properties));
1056         props.type = BACKLIGHT_PLATFORM;
1057         props.max_brightness = samsung->config->max_brightness -
1058                 samsung->config->min_brightness;
1059
1060         bd = backlight_device_register("samsung",
1061                                        &samsung->platform_device->dev,
1062                                        samsung, &backlight_ops,
1063                                        &props);
1064         if (IS_ERR(bd))
1065                 return PTR_ERR(bd);
1066
1067         samsung->backlight_device = bd;
1068         samsung->backlight_device->props.brightness = read_brightness(samsung);
1069         samsung->backlight_device->props.power = FB_BLANK_UNBLANK;
1070         backlight_update_status(samsung->backlight_device);
1071
1072         return 0;
1073 }
1074
1075 static mode_t samsung_sysfs_is_visible(struct kobject *kobj,
1076                                        struct attribute *attr, int idx)
1077 {
1078         struct device *dev = container_of(kobj, struct device, kobj);
1079         struct platform_device *pdev = to_platform_device(dev);
1080         struct samsung_laptop *samsung = platform_get_drvdata(pdev);
1081         bool ok = true;
1082
1083         if (attr == &dev_attr_performance_level.attr)
1084                 ok = !!samsung->config->performance_levels[0].name;
1085         if (attr == &dev_attr_battery_life_extender.attr)
1086                 ok = !!(read_battery_life_extender(samsung) >= 0);
1087         if (attr == &dev_attr_usb_charge.attr)
1088                 ok = !!(read_usb_charge(samsung) >= 0);
1089
1090         return ok ? attr->mode : 0;
1091 }
1092
1093 static struct attribute_group platform_attribute_group = {
1094         .is_visible = samsung_sysfs_is_visible,
1095         .attrs = platform_attributes
1096 };
1097
1098 static void samsung_sysfs_exit(struct samsung_laptop *samsung)
1099 {
1100         struct platform_device *device = samsung->platform_device;
1101
1102         sysfs_remove_group(&device->dev.kobj, &platform_attribute_group);
1103 }
1104
1105 static int __init samsung_sysfs_init(struct samsung_laptop *samsung)
1106 {
1107         struct platform_device *device = samsung->platform_device;
1108
1109         return sysfs_create_group(&device->dev.kobj, &platform_attribute_group);
1110
1111 }
1112
1113 static int show_call(struct seq_file *m, void *data)
1114 {
1115         struct samsung_laptop *samsung = m->private;
1116         struct sabi_data *sdata = &samsung->debug.data;
1117         int ret;
1118
1119         seq_printf(m, "SABI 0x%04x {0x%08x, 0x%08x, 0x%04x, 0x%02x}\n",
1120                    samsung->debug.command,
1121                    sdata->d0, sdata->d1, sdata->d2, sdata->d3);
1122
1123         ret = sabi_command(samsung, samsung->debug.command, sdata, sdata);
1124
1125         if (ret) {
1126                 seq_printf(m, "SABI command 0x%04x failed\n",
1127                            samsung->debug.command);
1128                 return ret;
1129         }
1130
1131         seq_printf(m, "SABI {0x%08x, 0x%08x, 0x%04x, 0x%02x}\n",
1132                    sdata->d0, sdata->d1, sdata->d2, sdata->d3);
1133         return 0;
1134 }
1135
1136 static int samsung_debugfs_open(struct inode *inode, struct file *file)
1137 {
1138         return single_open(file, show_call, inode->i_private);
1139 }
1140
1141 static const struct file_operations samsung_laptop_call_io_ops = {
1142         .owner = THIS_MODULE,
1143         .open = samsung_debugfs_open,
1144         .read = seq_read,
1145         .llseek = seq_lseek,
1146         .release = single_release,
1147 };
1148
1149 static void samsung_debugfs_exit(struct samsung_laptop *samsung)
1150 {
1151         debugfs_remove_recursive(samsung->debug.root);
1152 }
1153
1154 static int samsung_debugfs_init(struct samsung_laptop *samsung)
1155 {
1156         struct dentry *dent;
1157
1158         samsung->debug.root = debugfs_create_dir("samsung-laptop", NULL);
1159         if (!samsung->debug.root) {
1160                 pr_err("failed to create debugfs directory");
1161                 goto error_debugfs;
1162         }
1163
1164         samsung->debug.f0000_wrapper.data = samsung->f0000_segment;
1165         samsung->debug.f0000_wrapper.size = 0xffff;
1166
1167         samsung->debug.data_wrapper.data = &samsung->debug.data;
1168         samsung->debug.data_wrapper.size = sizeof(samsung->debug.data);
1169
1170         samsung->debug.sdiag_wrapper.data = samsung->sdiag;
1171         samsung->debug.sdiag_wrapper.size = strlen(samsung->sdiag);
1172
1173         dent = debugfs_create_u16("command", S_IRUGO | S_IWUSR,
1174                                   samsung->debug.root, &samsung->debug.command);
1175         if (!dent)
1176                 goto error_debugfs;
1177
1178         dent = debugfs_create_u32("d0", S_IRUGO | S_IWUSR, samsung->debug.root,
1179                                   &samsung->debug.data.d0);
1180         if (!dent)
1181                 goto error_debugfs;
1182
1183         dent = debugfs_create_u32("d1", S_IRUGO | S_IWUSR, samsung->debug.root,
1184                                   &samsung->debug.data.d1);
1185         if (!dent)
1186                 goto error_debugfs;
1187
1188         dent = debugfs_create_u16("d2", S_IRUGO | S_IWUSR, samsung->debug.root,
1189                                   &samsung->debug.data.d2);
1190         if (!dent)
1191                 goto error_debugfs;
1192
1193         dent = debugfs_create_u8("d3", S_IRUGO | S_IWUSR, samsung->debug.root,
1194                                  &samsung->debug.data.d3);
1195         if (!dent)
1196                 goto error_debugfs;
1197
1198         dent = debugfs_create_blob("data", S_IRUGO | S_IWUSR,
1199                                    samsung->debug.root,
1200                                    &samsung->debug.data_wrapper);
1201         if (!dent)
1202                 goto error_debugfs;
1203
1204         dent = debugfs_create_blob("f0000_segment", S_IRUSR | S_IWUSR,
1205                                    samsung->debug.root,
1206                                    &samsung->debug.f0000_wrapper);
1207         if (!dent)
1208                 goto error_debugfs;
1209
1210         dent = debugfs_create_file("call", S_IFREG | S_IRUGO,
1211                                    samsung->debug.root, samsung,
1212                                    &samsung_laptop_call_io_ops);
1213         if (!dent)
1214                 goto error_debugfs;
1215
1216         dent = debugfs_create_blob("sdiag", S_IRUGO | S_IWUSR,
1217                                    samsung->debug.root,
1218                                    &samsung->debug.sdiag_wrapper);
1219         if (!dent)
1220                 goto error_debugfs;
1221
1222         return 0;
1223
1224 error_debugfs:
1225         samsung_debugfs_exit(samsung);
1226         return -ENOMEM;
1227 }
1228
1229 static void samsung_sabi_exit(struct samsung_laptop *samsung)
1230 {
1231         const struct sabi_config *config = samsung->config;
1232
1233         /* Turn off "Linux" mode in the BIOS */
1234         if (config && config->commands.set_linux != 0xff)
1235                 sabi_set_commandb(samsung, config->commands.set_linux, 0x80);
1236
1237         if (samsung->sabi_iface) {
1238                 iounmap(samsung->sabi_iface);
1239                 samsung->sabi_iface = NULL;
1240         }
1241         if (samsung->f0000_segment) {
1242                 iounmap(samsung->f0000_segment);
1243                 samsung->f0000_segment = NULL;
1244         }
1245
1246         samsung->config = NULL;
1247 }
1248
1249 static __init void samsung_sabi_infos(struct samsung_laptop *samsung, int loca,
1250                                       unsigned int ifaceP)
1251 {
1252         const struct sabi_config *config = samsung->config;
1253
1254         printk(KERN_DEBUG "This computer supports SABI==%x\n",
1255                loca + 0xf0000 - 6);
1256
1257         printk(KERN_DEBUG "SABI header:\n");
1258         printk(KERN_DEBUG " SMI Port Number = 0x%04x\n",
1259                readw(samsung->sabi + config->header_offsets.port));
1260         printk(KERN_DEBUG " SMI Interface Function = 0x%02x\n",
1261                readb(samsung->sabi + config->header_offsets.iface_func));
1262         printk(KERN_DEBUG " SMI enable memory buffer = 0x%02x\n",
1263                readb(samsung->sabi + config->header_offsets.en_mem));
1264         printk(KERN_DEBUG " SMI restore memory buffer = 0x%02x\n",
1265                readb(samsung->sabi + config->header_offsets.re_mem));
1266         printk(KERN_DEBUG " SABI data offset = 0x%04x\n",
1267                readw(samsung->sabi + config->header_offsets.data_offset));
1268         printk(KERN_DEBUG " SABI data segment = 0x%04x\n",
1269                readw(samsung->sabi + config->header_offsets.data_segment));
1270
1271         printk(KERN_DEBUG " SABI pointer = 0x%08x\n", ifaceP);
1272 }
1273
1274 static void __init samsung_sabi_diag(struct samsung_laptop *samsung)
1275 {
1276         int loca = find_signature(samsung->f0000_segment, "SDiaG@");
1277         int i;
1278
1279         if (loca == 0xffff)
1280                 return ;
1281
1282         /* Example:
1283          * Ident: @SDiaG@686XX-N90X3A/966-SEC-07HL-S90X3A
1284          *
1285          * Product name: 90X3A
1286          * BIOS Version: 07HL
1287          */
1288         loca += 1;
1289         for (i = 0; loca < 0xffff && i < sizeof(samsung->sdiag) - 1; loca++) {
1290                 char temp = readb(samsung->f0000_segment + loca);
1291
1292                 if (isalnum(temp) || temp == '/' || temp == '-')
1293                         samsung->sdiag[i++] = temp;
1294                 else
1295                         break ;
1296         }
1297
1298         if (debug && samsung->sdiag[0])
1299                 pr_info("sdiag: %s", samsung->sdiag);
1300 }
1301
1302 static int __init samsung_sabi_init(struct samsung_laptop *samsung)
1303 {
1304         const struct sabi_config *config = NULL;
1305         const struct sabi_commands *commands;
1306         unsigned int ifaceP;
1307         int ret = 0;
1308         int i;
1309         int loca;
1310
1311         samsung->f0000_segment = ioremap_nocache(0xf0000, 0xffff);
1312         if (!samsung->f0000_segment) {
1313                 if (debug || force)
1314                         pr_err("Can't map the segment at 0xf0000\n");
1315                 ret = -EINVAL;
1316                 goto exit;
1317         }
1318
1319         samsung_sabi_diag(samsung);
1320
1321         /* Try to find one of the signatures in memory to find the header */
1322         for (i = 0; sabi_configs[i].test_string != 0; ++i) {
1323                 samsung->config = &sabi_configs[i];
1324                 loca = find_signature(samsung->f0000_segment,
1325                                       samsung->config->test_string);
1326                 if (loca != 0xffff)
1327                         break;
1328         }
1329
1330         if (loca == 0xffff) {
1331                 if (debug || force)
1332                         pr_err("This computer does not support SABI\n");
1333                 ret = -ENODEV;
1334                 goto exit;
1335         }
1336
1337         config = samsung->config;
1338         commands = &config->commands;
1339
1340         /* point to the SMI port Number */
1341         loca += 1;
1342         samsung->sabi = (samsung->f0000_segment + loca);
1343
1344         /* Get a pointer to the SABI Interface */
1345         ifaceP = (readw(samsung->sabi + config->header_offsets.data_segment) & 0x0ffff) << 4;
1346         ifaceP += readw(samsung->sabi + config->header_offsets.data_offset) & 0x0ffff;
1347
1348         if (debug)
1349                 samsung_sabi_infos(samsung, loca, ifaceP);
1350
1351         samsung->sabi_iface = ioremap_nocache(ifaceP, 16);
1352         if (!samsung->sabi_iface) {
1353                 pr_err("Can't remap %x\n", ifaceP);
1354                 ret = -EINVAL;
1355                 goto exit;
1356         }
1357
1358         /* Turn on "Linux" mode in the BIOS */
1359         if (commands->set_linux != 0xff) {
1360                 int retval = sabi_set_commandb(samsung,
1361                                                commands->set_linux, 0x81);
1362                 if (retval) {
1363                         pr_warn("Linux mode was not set!\n");
1364                         ret = -ENODEV;
1365                         goto exit;
1366                 }
1367         }
1368
1369         /* Check for stepping quirk */
1370         if (samsung->handle_backlight)
1371                 check_for_stepping_quirk(samsung);
1372
1373 exit:
1374         if (ret)
1375                 samsung_sabi_exit(samsung);
1376
1377         return ret;
1378 }
1379
1380 static void samsung_platform_exit(struct samsung_laptop *samsung)
1381 {
1382         if (samsung->platform_device) {
1383                 platform_device_unregister(samsung->platform_device);
1384                 samsung->platform_device = NULL;
1385         }
1386 }
1387
1388 static int __init samsung_platform_init(struct samsung_laptop *samsung)
1389 {
1390         struct platform_device *pdev;
1391
1392         pdev = platform_device_register_simple("samsung", -1, NULL, 0);
1393         if (IS_ERR(pdev))
1394                 return PTR_ERR(pdev);
1395
1396         samsung->platform_device = pdev;
1397         platform_set_drvdata(samsung->platform_device, samsung);
1398         return 0;
1399 }
1400
1401 static struct dmi_system_id __initdata samsung_dmi_table[] = {
1402         {
1403                 .matches = {
1404                         DMI_MATCH(DMI_SYS_VENDOR,
1405                                         "SAMSUNG ELECTRONICS CO., LTD."),
1406                         DMI_MATCH(DMI_CHASSIS_TYPE, "8"), /* Portable */
1407                 },
1408         },
1409         {
1410                 .matches = {
1411                         DMI_MATCH(DMI_SYS_VENDOR,
1412                                         "SAMSUNG ELECTRONICS CO., LTD."),
1413                         DMI_MATCH(DMI_CHASSIS_TYPE, "9"), /* Laptop */
1414                 },
1415         },
1416         {
1417                 .matches = {
1418                         DMI_MATCH(DMI_SYS_VENDOR,
1419                                         "SAMSUNG ELECTRONICS CO., LTD."),
1420                         DMI_MATCH(DMI_CHASSIS_TYPE, "10"), /* Notebook */
1421                 },
1422         },
1423         {
1424                 .matches = {
1425                         DMI_MATCH(DMI_SYS_VENDOR,
1426                                         "SAMSUNG ELECTRONICS CO., LTD."),
1427                         DMI_MATCH(DMI_CHASSIS_TYPE, "14"), /* Sub-Notebook */
1428                 },
1429         },
1430         { },
1431 };
1432 MODULE_DEVICE_TABLE(dmi, samsung_dmi_table);
1433
1434 static struct platform_device *samsung_platform_device;
1435
1436 static int __init samsung_init(void)
1437 {
1438         struct samsung_laptop *samsung;
1439         int ret;
1440
1441         if (!force && !dmi_check_system(samsung_dmi_table))
1442                 return -ENODEV;
1443
1444         samsung = kzalloc(sizeof(*samsung), GFP_KERNEL);
1445         if (!samsung)
1446                 return -ENOMEM;
1447
1448         mutex_init(&samsung->sabi_mutex);
1449         samsung->handle_backlight = true;
1450
1451 #ifdef CONFIG_ACPI
1452         /* Don't handle backlight here if the acpi video already handle it */
1453         if (acpi_video_backlight_support())
1454                 samsung->handle_backlight = false;
1455 #endif
1456         ret = samsung_platform_init(samsung);
1457         if (ret)
1458                 goto error_platform;
1459
1460         ret = samsung_sabi_init(samsung);
1461         if (ret)
1462                 goto error_sabi;
1463
1464 #ifdef CONFIG_ACPI
1465         /* Only log that if we are really on a sabi platform */
1466         if (acpi_video_backlight_support())
1467                 pr_info("Backlight controlled by ACPI video driver\n");
1468 #endif
1469
1470         ret = samsung_sysfs_init(samsung);
1471         if (ret)
1472                 goto error_sysfs;
1473
1474         ret = samsung_backlight_init(samsung);
1475         if (ret)
1476                 goto error_backlight;
1477
1478         ret = samsung_rfkill_init(samsung);
1479         if (ret)
1480                 goto error_rfkill;
1481
1482         ret = samsung_leds_init(samsung);
1483         if (ret)
1484                 goto error_leds;
1485
1486         ret = samsung_debugfs_init(samsung);
1487         if (ret)
1488                 goto error_debugfs;
1489
1490         samsung_platform_device = samsung->platform_device;
1491         return ret;
1492
1493 error_debugfs:
1494         samsung_leds_exit(samsung);
1495 error_leds:
1496         samsung_rfkill_exit(samsung);
1497 error_rfkill:
1498         samsung_backlight_exit(samsung);
1499 error_backlight:
1500         samsung_sysfs_exit(samsung);
1501 error_sysfs:
1502         samsung_sabi_exit(samsung);
1503 error_sabi:
1504         samsung_platform_exit(samsung);
1505 error_platform:
1506         kfree(samsung);
1507         return ret;
1508 }
1509
1510 static void __exit samsung_exit(void)
1511 {
1512         struct samsung_laptop *samsung;
1513
1514         samsung = platform_get_drvdata(samsung_platform_device);
1515
1516         samsung_debugfs_exit(samsung);
1517         samsung_leds_exit(samsung);
1518         samsung_rfkill_exit(samsung);
1519         samsung_backlight_exit(samsung);
1520         samsung_sysfs_exit(samsung);
1521         samsung_sabi_exit(samsung);
1522         samsung_platform_exit(samsung);
1523
1524         kfree(samsung);
1525         samsung_platform_device = NULL;
1526 }
1527
1528 module_init(samsung_init);
1529 module_exit(samsung_exit);
1530
1531 MODULE_AUTHOR("Greg Kroah-Hartman <gregkh@suse.de>");
1532 MODULE_DESCRIPTION("Samsung Backlight driver");
1533 MODULE_LICENSE("GPL");