Linux 3.12.39
[linux/fpc-iii.git] / drivers / platform / x86 / samsung-laptop.c
blobd1f0300531766f64ab741ccbd4d388db0644d427
1 /*
2 * Samsung Laptop driver
4 * Copyright (C) 2009,2011 Greg Kroah-Hartman (gregkh@suse.de)
5 * Copyright (C) 2009,2011 Novell Inc.
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.
12 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
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 #include <linux/ctype.h>
29 #include <linux/efi.h>
30 #include <acpi/video.h>
33 * This driver is needed because a number of Samsung laptops do not hook
34 * their control settings through ACPI. So we have to poke around in the
35 * BIOS to do things like brightness values, and "special" key controls.
39 * We have 0 - 8 as valid brightness levels. The specs say that level 0 should
40 * be reserved by the BIOS (which really doesn't make much sense), we tell
41 * userspace that the value is 0 - 7 and then just tell the hardware 1 - 8
43 #define MAX_BRIGHT 0x07
46 #define SABI_IFACE_MAIN 0x00
47 #define SABI_IFACE_SUB 0x02
48 #define SABI_IFACE_COMPLETE 0x04
49 #define SABI_IFACE_DATA 0x05
51 #define WL_STATUS_WLAN 0x0
52 #define WL_STATUS_BT 0x2
54 /* Structure get/set data using sabi */
55 struct sabi_data {
56 union {
57 struct {
58 u32 d0;
59 u32 d1;
60 u16 d2;
61 u8 d3;
63 u8 data[11];
67 struct sabi_header_offsets {
68 u8 port;
69 u8 re_mem;
70 u8 iface_func;
71 u8 en_mem;
72 u8 data_offset;
73 u8 data_segment;
76 struct sabi_commands {
78 * Brightness is 0 - 8, as described above.
79 * Value 0 is for the BIOS to use
81 u16 get_brightness;
82 u16 set_brightness;
85 * first byte:
86 * 0x00 - wireless is off
87 * 0x01 - wireless is on
88 * second byte:
89 * 0x02 - 3G is off
90 * 0x03 - 3G is on
91 * TODO, verify 3G is correct, that doesn't seem right...
93 u16 get_wireless_button;
94 u16 set_wireless_button;
96 /* 0 is off, 1 is on */
97 u16 get_backlight;
98 u16 set_backlight;
101 * 0x80 or 0x00 - no action
102 * 0x81 - recovery key pressed
104 u16 get_recovery_mode;
105 u16 set_recovery_mode;
108 * on seclinux: 0 is low, 1 is high,
109 * on swsmi: 0 is normal, 1 is silent, 2 is turbo
111 u16 get_performance_level;
112 u16 set_performance_level;
114 /* 0x80 is off, 0x81 is on */
115 u16 get_battery_life_extender;
116 u16 set_battery_life_extender;
118 /* 0x80 is off, 0x81 is on */
119 u16 get_usb_charge;
120 u16 set_usb_charge;
122 /* the first byte is for bluetooth and the third one is for wlan */
123 u16 get_wireless_status;
124 u16 set_wireless_status;
126 /* 0x81 to read, (0x82 | level << 8) to set, 0xaabb to enable */
127 u16 kbd_backlight;
130 * Tell the BIOS that Linux is running on this machine.
131 * 81 is on, 80 is off
133 u16 set_linux;
136 struct sabi_performance_level {
137 const char *name;
138 u16 value;
141 struct sabi_config {
142 int sabi_version;
143 const char *test_string;
144 u16 main_function;
145 const struct sabi_header_offsets header_offsets;
146 const struct sabi_commands commands;
147 const struct sabi_performance_level performance_levels[4];
148 u8 min_brightness;
149 u8 max_brightness;
152 static const struct sabi_config sabi_configs[] = {
154 /* I don't know if it is really 2, but it it is
155 * less than 3 anyway */
156 .sabi_version = 2,
158 .test_string = "SECLINUX",
160 .main_function = 0x4c49,
162 .header_offsets = {
163 .port = 0x00,
164 .re_mem = 0x02,
165 .iface_func = 0x03,
166 .en_mem = 0x04,
167 .data_offset = 0x05,
168 .data_segment = 0x07,
171 .commands = {
172 .get_brightness = 0x00,
173 .set_brightness = 0x01,
175 .get_wireless_button = 0x02,
176 .set_wireless_button = 0x03,
178 .get_backlight = 0x04,
179 .set_backlight = 0x05,
181 .get_recovery_mode = 0x06,
182 .set_recovery_mode = 0x07,
184 .get_performance_level = 0x08,
185 .set_performance_level = 0x09,
187 .get_battery_life_extender = 0xFFFF,
188 .set_battery_life_extender = 0xFFFF,
190 .get_usb_charge = 0xFFFF,
191 .set_usb_charge = 0xFFFF,
193 .get_wireless_status = 0xFFFF,
194 .set_wireless_status = 0xFFFF,
196 .kbd_backlight = 0xFFFF,
198 .set_linux = 0x0a,
201 .performance_levels = {
203 .name = "silent",
204 .value = 0,
207 .name = "normal",
208 .value = 1,
210 { },
212 .min_brightness = 1,
213 .max_brightness = 8,
216 .sabi_version = 3,
218 .test_string = "SwSmi@",
220 .main_function = 0x5843,
222 .header_offsets = {
223 .port = 0x00,
224 .re_mem = 0x04,
225 .iface_func = 0x02,
226 .en_mem = 0x03,
227 .data_offset = 0x05,
228 .data_segment = 0x07,
231 .commands = {
232 .get_brightness = 0x10,
233 .set_brightness = 0x11,
235 .get_wireless_button = 0x12,
236 .set_wireless_button = 0x13,
238 .get_backlight = 0x2d,
239 .set_backlight = 0x2e,
241 .get_recovery_mode = 0xff,
242 .set_recovery_mode = 0xff,
244 .get_performance_level = 0x31,
245 .set_performance_level = 0x32,
247 .get_battery_life_extender = 0x65,
248 .set_battery_life_extender = 0x66,
250 .get_usb_charge = 0x67,
251 .set_usb_charge = 0x68,
253 .get_wireless_status = 0x69,
254 .set_wireless_status = 0x6a,
256 .kbd_backlight = 0x78,
258 .set_linux = 0xff,
261 .performance_levels = {
263 .name = "normal",
264 .value = 0,
267 .name = "silent",
268 .value = 1,
271 .name = "overclock",
272 .value = 2,
274 { },
276 .min_brightness = 0,
277 .max_brightness = 8,
279 { },
283 * samsung-laptop/ - debugfs root directory
284 * f0000_segment - dump f0000 segment
285 * command - current command
286 * data - current data
287 * d0, d1, d2, d3 - data fields
288 * call - call SABI using command and data
290 * This allow to call arbitrary sabi commands wihout
291 * modifying the driver at all.
292 * For example, setting the keyboard backlight brightness to 5
294 * echo 0x78 > command
295 * echo 0x0582 > d0
296 * echo 0 > d1
297 * echo 0 > d2
298 * echo 0 > d3
299 * cat call
302 struct samsung_laptop_debug {
303 struct dentry *root;
304 struct sabi_data data;
305 u16 command;
307 struct debugfs_blob_wrapper f0000_wrapper;
308 struct debugfs_blob_wrapper data_wrapper;
309 struct debugfs_blob_wrapper sdiag_wrapper;
312 struct samsung_laptop;
314 struct samsung_rfkill {
315 struct samsung_laptop *samsung;
316 struct rfkill *rfkill;
317 enum rfkill_type type;
320 struct samsung_laptop {
321 const struct sabi_config *config;
323 void __iomem *sabi;
324 void __iomem *sabi_iface;
325 void __iomem *f0000_segment;
327 struct mutex sabi_mutex;
329 struct platform_device *platform_device;
330 struct backlight_device *backlight_device;
332 struct samsung_rfkill wlan;
333 struct samsung_rfkill bluetooth;
335 struct led_classdev kbd_led;
336 int kbd_led_wk;
337 struct workqueue_struct *led_workqueue;
338 struct work_struct kbd_led_work;
340 struct samsung_laptop_debug debug;
341 struct samsung_quirks *quirks;
343 bool handle_backlight;
344 bool has_stepping_quirk;
346 char sdiag[64];
349 struct samsung_quirks {
350 bool broken_acpi_video;
353 static struct samsung_quirks samsung_unknown = {};
355 static struct samsung_quirks samsung_broken_acpi_video = {
356 .broken_acpi_video = true,
359 static bool force;
360 module_param(force, bool, 0);
361 MODULE_PARM_DESC(force,
362 "Disable the DMI check and forces the driver to be loaded");
364 static bool debug;
365 module_param(debug, bool, S_IRUGO | S_IWUSR);
366 MODULE_PARM_DESC(debug, "Debug enabled or not");
368 static int sabi_command(struct samsung_laptop *samsung, u16 command,
369 struct sabi_data *in,
370 struct sabi_data *out)
372 const struct sabi_config *config = samsung->config;
373 int ret = 0;
374 u16 port = readw(samsung->sabi + config->header_offsets.port);
375 u8 complete, iface_data;
377 mutex_lock(&samsung->sabi_mutex);
379 if (debug) {
380 if (in)
381 pr_info("SABI command:0x%04x "
382 "data:{0x%08x, 0x%08x, 0x%04x, 0x%02x}",
383 command, in->d0, in->d1, in->d2, in->d3);
384 else
385 pr_info("SABI command:0x%04x", command);
388 /* enable memory to be able to write to it */
389 outb(readb(samsung->sabi + config->header_offsets.en_mem), port);
391 /* write out the command */
392 writew(config->main_function, samsung->sabi_iface + SABI_IFACE_MAIN);
393 writew(command, samsung->sabi_iface + SABI_IFACE_SUB);
394 writeb(0, samsung->sabi_iface + SABI_IFACE_COMPLETE);
395 if (in) {
396 writel(in->d0, samsung->sabi_iface + SABI_IFACE_DATA);
397 writel(in->d1, samsung->sabi_iface + SABI_IFACE_DATA + 4);
398 writew(in->d2, samsung->sabi_iface + SABI_IFACE_DATA + 8);
399 writeb(in->d3, samsung->sabi_iface + SABI_IFACE_DATA + 10);
401 outb(readb(samsung->sabi + config->header_offsets.iface_func), port);
403 /* write protect memory to make it safe */
404 outb(readb(samsung->sabi + config->header_offsets.re_mem), port);
406 /* see if the command actually succeeded */
407 complete = readb(samsung->sabi_iface + SABI_IFACE_COMPLETE);
408 iface_data = readb(samsung->sabi_iface + SABI_IFACE_DATA);
410 /* iface_data = 0xFF happens when a command is not known
411 * so we only add a warning in debug mode since we will
412 * probably issue some unknown command at startup to find
413 * out which features are supported */
414 if (complete != 0xaa || (iface_data == 0xff && debug))
415 pr_warn("SABI command 0x%04x failed with"
416 " completion flag 0x%02x and interface data 0x%02x",
417 command, complete, iface_data);
419 if (complete != 0xaa || iface_data == 0xff) {
420 ret = -EINVAL;
421 goto exit;
424 if (out) {
425 out->d0 = readl(samsung->sabi_iface + SABI_IFACE_DATA);
426 out->d1 = readl(samsung->sabi_iface + SABI_IFACE_DATA + 4);
427 out->d2 = readw(samsung->sabi_iface + SABI_IFACE_DATA + 2);
428 out->d3 = readb(samsung->sabi_iface + SABI_IFACE_DATA + 1);
431 if (debug && out) {
432 pr_info("SABI return data:{0x%08x, 0x%08x, 0x%04x, 0x%02x}",
433 out->d0, out->d1, out->d2, out->d3);
436 exit:
437 mutex_unlock(&samsung->sabi_mutex);
438 return ret;
441 /* simple wrappers usable with most commands */
442 static int sabi_set_commandb(struct samsung_laptop *samsung,
443 u16 command, u8 data)
445 struct sabi_data in = { { { .d0 = 0, .d1 = 0, .d2 = 0, .d3 = 0 } } };
447 in.data[0] = data;
448 return sabi_command(samsung, command, &in, NULL);
451 static int read_brightness(struct samsung_laptop *samsung)
453 const struct sabi_config *config = samsung->config;
454 const struct sabi_commands *commands = &samsung->config->commands;
455 struct sabi_data sretval;
456 int user_brightness = 0;
457 int retval;
459 retval = sabi_command(samsung, commands->get_brightness,
460 NULL, &sretval);
461 if (retval)
462 return retval;
464 user_brightness = sretval.data[0];
465 if (user_brightness > config->min_brightness)
466 user_brightness -= config->min_brightness;
467 else
468 user_brightness = 0;
470 return user_brightness;
473 static void set_brightness(struct samsung_laptop *samsung, u8 user_brightness)
475 const struct sabi_config *config = samsung->config;
476 const struct sabi_commands *commands = &samsung->config->commands;
477 u8 user_level = user_brightness + config->min_brightness;
479 if (samsung->has_stepping_quirk && user_level != 0) {
481 * short circuit if the specified level is what's already set
482 * to prevent the screen from flickering needlessly
484 if (user_brightness == read_brightness(samsung))
485 return;
487 sabi_set_commandb(samsung, commands->set_brightness, 0);
490 sabi_set_commandb(samsung, commands->set_brightness, user_level);
493 static int get_brightness(struct backlight_device *bd)
495 struct samsung_laptop *samsung = bl_get_data(bd);
497 return read_brightness(samsung);
500 static void check_for_stepping_quirk(struct samsung_laptop *samsung)
502 int initial_level;
503 int check_level;
504 int orig_level = read_brightness(samsung);
507 * Some laptops exhibit the strange behaviour of stepping toward
508 * (rather than setting) the brightness except when changing to/from
509 * brightness level 0. This behaviour is checked for here and worked
510 * around in set_brightness.
513 if (orig_level == 0)
514 set_brightness(samsung, 1);
516 initial_level = read_brightness(samsung);
518 if (initial_level <= 2)
519 check_level = initial_level + 2;
520 else
521 check_level = initial_level - 2;
523 samsung->has_stepping_quirk = false;
524 set_brightness(samsung, check_level);
526 if (read_brightness(samsung) != check_level) {
527 samsung->has_stepping_quirk = true;
528 pr_info("enabled workaround for brightness stepping quirk\n");
531 set_brightness(samsung, orig_level);
534 static int update_status(struct backlight_device *bd)
536 struct samsung_laptop *samsung = bl_get_data(bd);
537 const struct sabi_commands *commands = &samsung->config->commands;
539 set_brightness(samsung, bd->props.brightness);
541 if (bd->props.power == FB_BLANK_UNBLANK)
542 sabi_set_commandb(samsung, commands->set_backlight, 1);
543 else
544 sabi_set_commandb(samsung, commands->set_backlight, 0);
546 return 0;
549 static const struct backlight_ops backlight_ops = {
550 .get_brightness = get_brightness,
551 .update_status = update_status,
554 static int seclinux_rfkill_set(void *data, bool blocked)
556 struct samsung_rfkill *srfkill = data;
557 struct samsung_laptop *samsung = srfkill->samsung;
558 const struct sabi_commands *commands = &samsung->config->commands;
560 return sabi_set_commandb(samsung, commands->set_wireless_button,
561 !blocked);
564 static struct rfkill_ops seclinux_rfkill_ops = {
565 .set_block = seclinux_rfkill_set,
568 static int swsmi_wireless_status(struct samsung_laptop *samsung,
569 struct sabi_data *data)
571 const struct sabi_commands *commands = &samsung->config->commands;
573 return sabi_command(samsung, commands->get_wireless_status,
574 NULL, data);
577 static int swsmi_rfkill_set(void *priv, bool blocked)
579 struct samsung_rfkill *srfkill = priv;
580 struct samsung_laptop *samsung = srfkill->samsung;
581 const struct sabi_commands *commands = &samsung->config->commands;
582 struct sabi_data data;
583 int ret, i;
585 ret = swsmi_wireless_status(samsung, &data);
586 if (ret)
587 return ret;
589 /* Don't set the state for non-present devices */
590 for (i = 0; i < 4; i++)
591 if (data.data[i] == 0x02)
592 data.data[1] = 0;
594 if (srfkill->type == RFKILL_TYPE_WLAN)
595 data.data[WL_STATUS_WLAN] = !blocked;
596 else if (srfkill->type == RFKILL_TYPE_BLUETOOTH)
597 data.data[WL_STATUS_BT] = !blocked;
599 return sabi_command(samsung, commands->set_wireless_status,
600 &data, &data);
603 static void swsmi_rfkill_query(struct rfkill *rfkill, void *priv)
605 struct samsung_rfkill *srfkill = priv;
606 struct samsung_laptop *samsung = srfkill->samsung;
607 struct sabi_data data;
608 int ret;
610 ret = swsmi_wireless_status(samsung, &data);
611 if (ret)
612 return ;
614 if (srfkill->type == RFKILL_TYPE_WLAN)
615 ret = data.data[WL_STATUS_WLAN];
616 else if (srfkill->type == RFKILL_TYPE_BLUETOOTH)
617 ret = data.data[WL_STATUS_BT];
618 else
619 return ;
621 rfkill_set_sw_state(rfkill, !ret);
624 static struct rfkill_ops swsmi_rfkill_ops = {
625 .set_block = swsmi_rfkill_set,
626 .query = swsmi_rfkill_query,
629 static ssize_t get_performance_level(struct device *dev,
630 struct device_attribute *attr, char *buf)
632 struct samsung_laptop *samsung = dev_get_drvdata(dev);
633 const struct sabi_config *config = samsung->config;
634 const struct sabi_commands *commands = &config->commands;
635 struct sabi_data sretval;
636 int retval;
637 int i;
639 /* Read the state */
640 retval = sabi_command(samsung, commands->get_performance_level,
641 NULL, &sretval);
642 if (retval)
643 return retval;
645 /* The logic is backwards, yeah, lots of fun... */
646 for (i = 0; config->performance_levels[i].name; ++i) {
647 if (sretval.data[0] == config->performance_levels[i].value)
648 return sprintf(buf, "%s\n", config->performance_levels[i].name);
650 return sprintf(buf, "%s\n", "unknown");
653 static ssize_t set_performance_level(struct device *dev,
654 struct device_attribute *attr, const char *buf,
655 size_t count)
657 struct samsung_laptop *samsung = dev_get_drvdata(dev);
658 const struct sabi_config *config = samsung->config;
659 const struct sabi_commands *commands = &config->commands;
660 int i;
662 if (count < 1)
663 return count;
665 for (i = 0; config->performance_levels[i].name; ++i) {
666 const struct sabi_performance_level *level =
667 &config->performance_levels[i];
668 if (!strncasecmp(level->name, buf, strlen(level->name))) {
669 sabi_set_commandb(samsung,
670 commands->set_performance_level,
671 level->value);
672 break;
676 if (!config->performance_levels[i].name)
677 return -EINVAL;
679 return count;
682 static DEVICE_ATTR(performance_level, S_IWUSR | S_IRUGO,
683 get_performance_level, set_performance_level);
685 static int read_battery_life_extender(struct samsung_laptop *samsung)
687 const struct sabi_commands *commands = &samsung->config->commands;
688 struct sabi_data data;
689 int retval;
691 if (commands->get_battery_life_extender == 0xFFFF)
692 return -ENODEV;
694 memset(&data, 0, sizeof(data));
695 data.data[0] = 0x80;
696 retval = sabi_command(samsung, commands->get_battery_life_extender,
697 &data, &data);
699 if (retval)
700 return retval;
702 if (data.data[0] != 0 && data.data[0] != 1)
703 return -ENODEV;
705 return data.data[0];
708 static int write_battery_life_extender(struct samsung_laptop *samsung,
709 int enabled)
711 const struct sabi_commands *commands = &samsung->config->commands;
712 struct sabi_data data;
714 memset(&data, 0, sizeof(data));
715 data.data[0] = 0x80 | enabled;
716 return sabi_command(samsung, commands->set_battery_life_extender,
717 &data, NULL);
720 static ssize_t get_battery_life_extender(struct device *dev,
721 struct device_attribute *attr,
722 char *buf)
724 struct samsung_laptop *samsung = dev_get_drvdata(dev);
725 int ret;
727 ret = read_battery_life_extender(samsung);
728 if (ret < 0)
729 return ret;
731 return sprintf(buf, "%d\n", ret);
734 static ssize_t set_battery_life_extender(struct device *dev,
735 struct device_attribute *attr,
736 const char *buf, size_t count)
738 struct samsung_laptop *samsung = dev_get_drvdata(dev);
739 int ret, value;
741 if (!count || sscanf(buf, "%i", &value) != 1)
742 return -EINVAL;
744 ret = write_battery_life_extender(samsung, !!value);
745 if (ret < 0)
746 return ret;
748 return count;
751 static DEVICE_ATTR(battery_life_extender, S_IWUSR | S_IRUGO,
752 get_battery_life_extender, set_battery_life_extender);
754 static int read_usb_charge(struct samsung_laptop *samsung)
756 const struct sabi_commands *commands = &samsung->config->commands;
757 struct sabi_data data;
758 int retval;
760 if (commands->get_usb_charge == 0xFFFF)
761 return -ENODEV;
763 memset(&data, 0, sizeof(data));
764 data.data[0] = 0x80;
765 retval = sabi_command(samsung, commands->get_usb_charge,
766 &data, &data);
768 if (retval)
769 return retval;
771 if (data.data[0] != 0 && data.data[0] != 1)
772 return -ENODEV;
774 return data.data[0];
777 static int write_usb_charge(struct samsung_laptop *samsung,
778 int enabled)
780 const struct sabi_commands *commands = &samsung->config->commands;
781 struct sabi_data data;
783 memset(&data, 0, sizeof(data));
784 data.data[0] = 0x80 | enabled;
785 return sabi_command(samsung, commands->set_usb_charge,
786 &data, NULL);
789 static ssize_t get_usb_charge(struct device *dev,
790 struct device_attribute *attr,
791 char *buf)
793 struct samsung_laptop *samsung = dev_get_drvdata(dev);
794 int ret;
796 ret = read_usb_charge(samsung);
797 if (ret < 0)
798 return ret;
800 return sprintf(buf, "%d\n", ret);
803 static ssize_t set_usb_charge(struct device *dev,
804 struct device_attribute *attr,
805 const char *buf, size_t count)
807 struct samsung_laptop *samsung = dev_get_drvdata(dev);
808 int ret, value;
810 if (!count || sscanf(buf, "%i", &value) != 1)
811 return -EINVAL;
813 ret = write_usb_charge(samsung, !!value);
814 if (ret < 0)
815 return ret;
817 return count;
820 static DEVICE_ATTR(usb_charge, S_IWUSR | S_IRUGO,
821 get_usb_charge, set_usb_charge);
823 static struct attribute *platform_attributes[] = {
824 &dev_attr_performance_level.attr,
825 &dev_attr_battery_life_extender.attr,
826 &dev_attr_usb_charge.attr,
827 NULL
830 static int find_signature(void __iomem *memcheck, const char *testStr)
832 int i = 0;
833 int loca;
835 for (loca = 0; loca < 0xffff; loca++) {
836 char temp = readb(memcheck + loca);
838 if (temp == testStr[i]) {
839 if (i == strlen(testStr)-1)
840 break;
841 ++i;
842 } else {
843 i = 0;
846 return loca;
849 static void samsung_rfkill_exit(struct samsung_laptop *samsung)
851 if (samsung->wlan.rfkill) {
852 rfkill_unregister(samsung->wlan.rfkill);
853 rfkill_destroy(samsung->wlan.rfkill);
854 samsung->wlan.rfkill = NULL;
856 if (samsung->bluetooth.rfkill) {
857 rfkill_unregister(samsung->bluetooth.rfkill);
858 rfkill_destroy(samsung->bluetooth.rfkill);
859 samsung->bluetooth.rfkill = NULL;
863 static int samsung_new_rfkill(struct samsung_laptop *samsung,
864 struct samsung_rfkill *arfkill,
865 const char *name, enum rfkill_type type,
866 const struct rfkill_ops *ops,
867 int blocked)
869 struct rfkill **rfkill = &arfkill->rfkill;
870 int ret;
872 arfkill->type = type;
873 arfkill->samsung = samsung;
875 *rfkill = rfkill_alloc(name, &samsung->platform_device->dev,
876 type, ops, arfkill);
878 if (!*rfkill)
879 return -EINVAL;
881 if (blocked != -1)
882 rfkill_init_sw_state(*rfkill, blocked);
884 ret = rfkill_register(*rfkill);
885 if (ret) {
886 rfkill_destroy(*rfkill);
887 *rfkill = NULL;
888 return ret;
890 return 0;
893 static int __init samsung_rfkill_init_seclinux(struct samsung_laptop *samsung)
895 return samsung_new_rfkill(samsung, &samsung->wlan, "samsung-wlan",
896 RFKILL_TYPE_WLAN, &seclinux_rfkill_ops, -1);
899 static int __init samsung_rfkill_init_swsmi(struct samsung_laptop *samsung)
901 struct sabi_data data;
902 int ret;
904 ret = swsmi_wireless_status(samsung, &data);
905 if (ret) {
906 /* Some swsmi laptops use the old seclinux way to control
907 * wireless devices */
908 if (ret == -EINVAL)
909 ret = samsung_rfkill_init_seclinux(samsung);
910 return ret;
913 /* 0x02 seems to mean that the device is no present/available */
915 if (data.data[WL_STATUS_WLAN] != 0x02)
916 ret = samsung_new_rfkill(samsung, &samsung->wlan,
917 "samsung-wlan",
918 RFKILL_TYPE_WLAN,
919 &swsmi_rfkill_ops,
920 !data.data[WL_STATUS_WLAN]);
921 if (ret)
922 goto exit;
924 if (data.data[WL_STATUS_BT] != 0x02)
925 ret = samsung_new_rfkill(samsung, &samsung->bluetooth,
926 "samsung-bluetooth",
927 RFKILL_TYPE_BLUETOOTH,
928 &swsmi_rfkill_ops,
929 !data.data[WL_STATUS_BT]);
930 if (ret)
931 goto exit;
933 exit:
934 if (ret)
935 samsung_rfkill_exit(samsung);
937 return ret;
940 static int __init samsung_rfkill_init(struct samsung_laptop *samsung)
942 if (samsung->config->sabi_version == 2)
943 return samsung_rfkill_init_seclinux(samsung);
944 if (samsung->config->sabi_version == 3)
945 return samsung_rfkill_init_swsmi(samsung);
946 return 0;
949 static int kbd_backlight_enable(struct samsung_laptop *samsung)
951 const struct sabi_commands *commands = &samsung->config->commands;
952 struct sabi_data data;
953 int retval;
955 if (commands->kbd_backlight == 0xFFFF)
956 return -ENODEV;
958 memset(&data, 0, sizeof(data));
959 data.d0 = 0xaabb;
960 retval = sabi_command(samsung, commands->kbd_backlight,
961 &data, &data);
963 if (retval)
964 return retval;
966 if (data.d0 != 0xccdd)
967 return -ENODEV;
968 return 0;
971 static int kbd_backlight_read(struct samsung_laptop *samsung)
973 const struct sabi_commands *commands = &samsung->config->commands;
974 struct sabi_data data;
975 int retval;
977 memset(&data, 0, sizeof(data));
978 data.data[0] = 0x81;
979 retval = sabi_command(samsung, commands->kbd_backlight,
980 &data, &data);
982 if (retval)
983 return retval;
985 return data.data[0];
988 static int kbd_backlight_write(struct samsung_laptop *samsung, int brightness)
990 const struct sabi_commands *commands = &samsung->config->commands;
991 struct sabi_data data;
993 memset(&data, 0, sizeof(data));
994 data.d0 = 0x82 | ((brightness & 0xFF) << 8);
995 return sabi_command(samsung, commands->kbd_backlight,
996 &data, NULL);
999 static void kbd_led_update(struct work_struct *work)
1001 struct samsung_laptop *samsung;
1003 samsung = container_of(work, struct samsung_laptop, kbd_led_work);
1004 kbd_backlight_write(samsung, samsung->kbd_led_wk);
1007 static void kbd_led_set(struct led_classdev *led_cdev,
1008 enum led_brightness value)
1010 struct samsung_laptop *samsung;
1012 samsung = container_of(led_cdev, struct samsung_laptop, kbd_led);
1014 if (value > samsung->kbd_led.max_brightness)
1015 value = samsung->kbd_led.max_brightness;
1016 else if (value < 0)
1017 value = 0;
1019 samsung->kbd_led_wk = value;
1020 queue_work(samsung->led_workqueue, &samsung->kbd_led_work);
1023 static enum led_brightness kbd_led_get(struct led_classdev *led_cdev)
1025 struct samsung_laptop *samsung;
1027 samsung = container_of(led_cdev, struct samsung_laptop, kbd_led);
1028 return kbd_backlight_read(samsung);
1031 static void samsung_leds_exit(struct samsung_laptop *samsung)
1033 if (!IS_ERR_OR_NULL(samsung->kbd_led.dev))
1034 led_classdev_unregister(&samsung->kbd_led);
1035 if (samsung->led_workqueue)
1036 destroy_workqueue(samsung->led_workqueue);
1039 static int __init samsung_leds_init(struct samsung_laptop *samsung)
1041 int ret = 0;
1043 samsung->led_workqueue = create_singlethread_workqueue("led_workqueue");
1044 if (!samsung->led_workqueue)
1045 return -ENOMEM;
1047 if (kbd_backlight_enable(samsung) >= 0) {
1048 INIT_WORK(&samsung->kbd_led_work, kbd_led_update);
1050 samsung->kbd_led.name = "samsung::kbd_backlight";
1051 samsung->kbd_led.brightness_set = kbd_led_set;
1052 samsung->kbd_led.brightness_get = kbd_led_get;
1053 samsung->kbd_led.max_brightness = 8;
1055 ret = led_classdev_register(&samsung->platform_device->dev,
1056 &samsung->kbd_led);
1059 if (ret)
1060 samsung_leds_exit(samsung);
1062 return ret;
1065 static void samsung_backlight_exit(struct samsung_laptop *samsung)
1067 if (samsung->backlight_device) {
1068 backlight_device_unregister(samsung->backlight_device);
1069 samsung->backlight_device = NULL;
1073 static int __init samsung_backlight_init(struct samsung_laptop *samsung)
1075 struct backlight_device *bd;
1076 struct backlight_properties props;
1078 if (!samsung->handle_backlight)
1079 return 0;
1081 memset(&props, 0, sizeof(struct backlight_properties));
1082 props.type = BACKLIGHT_PLATFORM;
1083 props.max_brightness = samsung->config->max_brightness -
1084 samsung->config->min_brightness;
1086 bd = backlight_device_register("samsung",
1087 &samsung->platform_device->dev,
1088 samsung, &backlight_ops,
1089 &props);
1090 if (IS_ERR(bd))
1091 return PTR_ERR(bd);
1093 samsung->backlight_device = bd;
1094 samsung->backlight_device->props.brightness = read_brightness(samsung);
1095 samsung->backlight_device->props.power = FB_BLANK_UNBLANK;
1096 backlight_update_status(samsung->backlight_device);
1098 return 0;
1101 static umode_t samsung_sysfs_is_visible(struct kobject *kobj,
1102 struct attribute *attr, int idx)
1104 struct device *dev = container_of(kobj, struct device, kobj);
1105 struct platform_device *pdev = to_platform_device(dev);
1106 struct samsung_laptop *samsung = platform_get_drvdata(pdev);
1107 bool ok = true;
1109 if (attr == &dev_attr_performance_level.attr)
1110 ok = !!samsung->config->performance_levels[0].name;
1111 if (attr == &dev_attr_battery_life_extender.attr)
1112 ok = !!(read_battery_life_extender(samsung) >= 0);
1113 if (attr == &dev_attr_usb_charge.attr)
1114 ok = !!(read_usb_charge(samsung) >= 0);
1116 return ok ? attr->mode : 0;
1119 static struct attribute_group platform_attribute_group = {
1120 .is_visible = samsung_sysfs_is_visible,
1121 .attrs = platform_attributes
1124 static void samsung_sysfs_exit(struct samsung_laptop *samsung)
1126 struct platform_device *device = samsung->platform_device;
1128 sysfs_remove_group(&device->dev.kobj, &platform_attribute_group);
1131 static int __init samsung_sysfs_init(struct samsung_laptop *samsung)
1133 struct platform_device *device = samsung->platform_device;
1135 return sysfs_create_group(&device->dev.kobj, &platform_attribute_group);
1139 static int show_call(struct seq_file *m, void *data)
1141 struct samsung_laptop *samsung = m->private;
1142 struct sabi_data *sdata = &samsung->debug.data;
1143 int ret;
1145 seq_printf(m, "SABI 0x%04x {0x%08x, 0x%08x, 0x%04x, 0x%02x}\n",
1146 samsung->debug.command,
1147 sdata->d0, sdata->d1, sdata->d2, sdata->d3);
1149 ret = sabi_command(samsung, samsung->debug.command, sdata, sdata);
1151 if (ret) {
1152 seq_printf(m, "SABI command 0x%04x failed\n",
1153 samsung->debug.command);
1154 return ret;
1157 seq_printf(m, "SABI {0x%08x, 0x%08x, 0x%04x, 0x%02x}\n",
1158 sdata->d0, sdata->d1, sdata->d2, sdata->d3);
1159 return 0;
1162 static int samsung_debugfs_open(struct inode *inode, struct file *file)
1164 return single_open(file, show_call, inode->i_private);
1167 static const struct file_operations samsung_laptop_call_io_ops = {
1168 .owner = THIS_MODULE,
1169 .open = samsung_debugfs_open,
1170 .read = seq_read,
1171 .llseek = seq_lseek,
1172 .release = single_release,
1175 static void samsung_debugfs_exit(struct samsung_laptop *samsung)
1177 debugfs_remove_recursive(samsung->debug.root);
1180 static int samsung_debugfs_init(struct samsung_laptop *samsung)
1182 struct dentry *dent;
1184 samsung->debug.root = debugfs_create_dir("samsung-laptop", NULL);
1185 if (!samsung->debug.root) {
1186 pr_err("failed to create debugfs directory");
1187 goto error_debugfs;
1190 samsung->debug.f0000_wrapper.data = samsung->f0000_segment;
1191 samsung->debug.f0000_wrapper.size = 0xffff;
1193 samsung->debug.data_wrapper.data = &samsung->debug.data;
1194 samsung->debug.data_wrapper.size = sizeof(samsung->debug.data);
1196 samsung->debug.sdiag_wrapper.data = samsung->sdiag;
1197 samsung->debug.sdiag_wrapper.size = strlen(samsung->sdiag);
1199 dent = debugfs_create_u16("command", S_IRUGO | S_IWUSR,
1200 samsung->debug.root, &samsung->debug.command);
1201 if (!dent)
1202 goto error_debugfs;
1204 dent = debugfs_create_u32("d0", S_IRUGO | S_IWUSR, samsung->debug.root,
1205 &samsung->debug.data.d0);
1206 if (!dent)
1207 goto error_debugfs;
1209 dent = debugfs_create_u32("d1", S_IRUGO | S_IWUSR, samsung->debug.root,
1210 &samsung->debug.data.d1);
1211 if (!dent)
1212 goto error_debugfs;
1214 dent = debugfs_create_u16("d2", S_IRUGO | S_IWUSR, samsung->debug.root,
1215 &samsung->debug.data.d2);
1216 if (!dent)
1217 goto error_debugfs;
1219 dent = debugfs_create_u8("d3", S_IRUGO | S_IWUSR, samsung->debug.root,
1220 &samsung->debug.data.d3);
1221 if (!dent)
1222 goto error_debugfs;
1224 dent = debugfs_create_blob("data", S_IRUGO | S_IWUSR,
1225 samsung->debug.root,
1226 &samsung->debug.data_wrapper);
1227 if (!dent)
1228 goto error_debugfs;
1230 dent = debugfs_create_blob("f0000_segment", S_IRUSR | S_IWUSR,
1231 samsung->debug.root,
1232 &samsung->debug.f0000_wrapper);
1233 if (!dent)
1234 goto error_debugfs;
1236 dent = debugfs_create_file("call", S_IFREG | S_IRUGO,
1237 samsung->debug.root, samsung,
1238 &samsung_laptop_call_io_ops);
1239 if (!dent)
1240 goto error_debugfs;
1242 dent = debugfs_create_blob("sdiag", S_IRUGO | S_IWUSR,
1243 samsung->debug.root,
1244 &samsung->debug.sdiag_wrapper);
1245 if (!dent)
1246 goto error_debugfs;
1248 return 0;
1250 error_debugfs:
1251 samsung_debugfs_exit(samsung);
1252 return -ENOMEM;
1255 static void samsung_sabi_exit(struct samsung_laptop *samsung)
1257 const struct sabi_config *config = samsung->config;
1259 /* Turn off "Linux" mode in the BIOS */
1260 if (config && config->commands.set_linux != 0xff)
1261 sabi_set_commandb(samsung, config->commands.set_linux, 0x80);
1263 if (samsung->sabi_iface) {
1264 iounmap(samsung->sabi_iface);
1265 samsung->sabi_iface = NULL;
1267 if (samsung->f0000_segment) {
1268 iounmap(samsung->f0000_segment);
1269 samsung->f0000_segment = NULL;
1272 samsung->config = NULL;
1275 static __init void samsung_sabi_infos(struct samsung_laptop *samsung, int loca,
1276 unsigned int ifaceP)
1278 const struct sabi_config *config = samsung->config;
1280 printk(KERN_DEBUG "This computer supports SABI==%x\n",
1281 loca + 0xf0000 - 6);
1283 printk(KERN_DEBUG "SABI header:\n");
1284 printk(KERN_DEBUG " SMI Port Number = 0x%04x\n",
1285 readw(samsung->sabi + config->header_offsets.port));
1286 printk(KERN_DEBUG " SMI Interface Function = 0x%02x\n",
1287 readb(samsung->sabi + config->header_offsets.iface_func));
1288 printk(KERN_DEBUG " SMI enable memory buffer = 0x%02x\n",
1289 readb(samsung->sabi + config->header_offsets.en_mem));
1290 printk(KERN_DEBUG " SMI restore memory buffer = 0x%02x\n",
1291 readb(samsung->sabi + config->header_offsets.re_mem));
1292 printk(KERN_DEBUG " SABI data offset = 0x%04x\n",
1293 readw(samsung->sabi + config->header_offsets.data_offset));
1294 printk(KERN_DEBUG " SABI data segment = 0x%04x\n",
1295 readw(samsung->sabi + config->header_offsets.data_segment));
1297 printk(KERN_DEBUG " SABI pointer = 0x%08x\n", ifaceP);
1300 static void __init samsung_sabi_diag(struct samsung_laptop *samsung)
1302 int loca = find_signature(samsung->f0000_segment, "SDiaG@");
1303 int i;
1305 if (loca == 0xffff)
1306 return ;
1308 /* Example:
1309 * Ident: @SDiaG@686XX-N90X3A/966-SEC-07HL-S90X3A
1311 * Product name: 90X3A
1312 * BIOS Version: 07HL
1314 loca += 1;
1315 for (i = 0; loca < 0xffff && i < sizeof(samsung->sdiag) - 1; loca++) {
1316 char temp = readb(samsung->f0000_segment + loca);
1318 if (isalnum(temp) || temp == '/' || temp == '-')
1319 samsung->sdiag[i++] = temp;
1320 else
1321 break ;
1324 if (debug && samsung->sdiag[0])
1325 pr_info("sdiag: %s", samsung->sdiag);
1328 static int __init samsung_sabi_init(struct samsung_laptop *samsung)
1330 const struct sabi_config *config = NULL;
1331 const struct sabi_commands *commands;
1332 unsigned int ifaceP;
1333 int ret = 0;
1334 int i;
1335 int loca;
1337 samsung->f0000_segment = ioremap_nocache(0xf0000, 0xffff);
1338 if (!samsung->f0000_segment) {
1339 if (debug || force)
1340 pr_err("Can't map the segment at 0xf0000\n");
1341 ret = -EINVAL;
1342 goto exit;
1345 samsung_sabi_diag(samsung);
1347 /* Try to find one of the signatures in memory to find the header */
1348 for (i = 0; sabi_configs[i].test_string != 0; ++i) {
1349 samsung->config = &sabi_configs[i];
1350 loca = find_signature(samsung->f0000_segment,
1351 samsung->config->test_string);
1352 if (loca != 0xffff)
1353 break;
1356 if (loca == 0xffff) {
1357 if (debug || force)
1358 pr_err("This computer does not support SABI\n");
1359 ret = -ENODEV;
1360 goto exit;
1363 config = samsung->config;
1364 commands = &config->commands;
1366 /* point to the SMI port Number */
1367 loca += 1;
1368 samsung->sabi = (samsung->f0000_segment + loca);
1370 /* Get a pointer to the SABI Interface */
1371 ifaceP = (readw(samsung->sabi + config->header_offsets.data_segment) & 0x0ffff) << 4;
1372 ifaceP += readw(samsung->sabi + config->header_offsets.data_offset) & 0x0ffff;
1374 if (debug)
1375 samsung_sabi_infos(samsung, loca, ifaceP);
1377 samsung->sabi_iface = ioremap_nocache(ifaceP, 16);
1378 if (!samsung->sabi_iface) {
1379 pr_err("Can't remap %x\n", ifaceP);
1380 ret = -EINVAL;
1381 goto exit;
1384 /* Turn on "Linux" mode in the BIOS */
1385 if (commands->set_linux != 0xff) {
1386 int retval = sabi_set_commandb(samsung,
1387 commands->set_linux, 0x81);
1388 if (retval) {
1389 pr_warn("Linux mode was not set!\n");
1390 ret = -ENODEV;
1391 goto exit;
1395 /* Check for stepping quirk */
1396 if (samsung->handle_backlight)
1397 check_for_stepping_quirk(samsung);
1399 pr_info("detected SABI interface: %s\n",
1400 samsung->config->test_string);
1402 exit:
1403 if (ret)
1404 samsung_sabi_exit(samsung);
1406 return ret;
1409 static void samsung_platform_exit(struct samsung_laptop *samsung)
1411 if (samsung->platform_device) {
1412 platform_device_unregister(samsung->platform_device);
1413 samsung->platform_device = NULL;
1417 static int __init samsung_platform_init(struct samsung_laptop *samsung)
1419 struct platform_device *pdev;
1421 pdev = platform_device_register_simple("samsung", -1, NULL, 0);
1422 if (IS_ERR(pdev))
1423 return PTR_ERR(pdev);
1425 samsung->platform_device = pdev;
1426 platform_set_drvdata(samsung->platform_device, samsung);
1427 return 0;
1430 static struct samsung_quirks *quirks;
1432 static int __init samsung_dmi_matched(const struct dmi_system_id *d)
1434 quirks = d->driver_data;
1435 return 0;
1438 static struct dmi_system_id __initdata samsung_dmi_table[] = {
1440 .matches = {
1441 DMI_MATCH(DMI_SYS_VENDOR,
1442 "SAMSUNG ELECTRONICS CO., LTD."),
1443 DMI_MATCH(DMI_CHASSIS_TYPE, "8"), /* Portable */
1447 .matches = {
1448 DMI_MATCH(DMI_SYS_VENDOR,
1449 "SAMSUNG ELECTRONICS CO., LTD."),
1450 DMI_MATCH(DMI_CHASSIS_TYPE, "9"), /* Laptop */
1454 .matches = {
1455 DMI_MATCH(DMI_SYS_VENDOR,
1456 "SAMSUNG ELECTRONICS CO., LTD."),
1457 DMI_MATCH(DMI_CHASSIS_TYPE, "10"), /* Notebook */
1461 .matches = {
1462 DMI_MATCH(DMI_SYS_VENDOR,
1463 "SAMSUNG ELECTRONICS CO., LTD."),
1464 DMI_MATCH(DMI_CHASSIS_TYPE, "14"), /* Sub-Notebook */
1467 /* DMI ids for laptops with bad Chassis Type */
1469 .ident = "R40/R41",
1470 .matches = {
1471 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1472 DMI_MATCH(DMI_PRODUCT_NAME, "R40/R41"),
1473 DMI_MATCH(DMI_BOARD_NAME, "R40/R41"),
1476 /* Specific DMI ids for laptop with quirks */
1478 .callback = samsung_dmi_matched,
1479 .ident = "N150P",
1480 .matches = {
1481 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1482 DMI_MATCH(DMI_PRODUCT_NAME, "N150P"),
1483 DMI_MATCH(DMI_BOARD_NAME, "N150P"),
1485 .driver_data = &samsung_broken_acpi_video,
1488 .callback = samsung_dmi_matched,
1489 .ident = "N145P/N250P/N260P",
1490 .matches = {
1491 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1492 DMI_MATCH(DMI_PRODUCT_NAME, "N145P/N250P/N260P"),
1493 DMI_MATCH(DMI_BOARD_NAME, "N145P/N250P/N260P"),
1495 .driver_data = &samsung_broken_acpi_video,
1498 .callback = samsung_dmi_matched,
1499 .ident = "N150/N210/N220",
1500 .matches = {
1501 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1502 DMI_MATCH(DMI_PRODUCT_NAME, "N150/N210/N220"),
1503 DMI_MATCH(DMI_BOARD_NAME, "N150/N210/N220"),
1505 .driver_data = &samsung_broken_acpi_video,
1508 .callback = samsung_dmi_matched,
1509 .ident = "NF110/NF210/NF310",
1510 .matches = {
1511 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1512 DMI_MATCH(DMI_PRODUCT_NAME, "NF110/NF210/NF310"),
1513 DMI_MATCH(DMI_BOARD_NAME, "NF110/NF210/NF310"),
1515 .driver_data = &samsung_broken_acpi_video,
1518 .callback = samsung_dmi_matched,
1519 .ident = "X360",
1520 .matches = {
1521 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1522 DMI_MATCH(DMI_PRODUCT_NAME, "X360"),
1523 DMI_MATCH(DMI_BOARD_NAME, "X360"),
1525 .driver_data = &samsung_broken_acpi_video,
1528 .callback = samsung_dmi_matched,
1529 .ident = "N250P",
1530 .matches = {
1531 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1532 DMI_MATCH(DMI_PRODUCT_NAME, "N250P"),
1533 DMI_MATCH(DMI_BOARD_NAME, "N250P"),
1535 .driver_data = &samsung_broken_acpi_video,
1537 { },
1539 MODULE_DEVICE_TABLE(dmi, samsung_dmi_table);
1541 static struct platform_device *samsung_platform_device;
1543 static int __init samsung_init(void)
1545 struct samsung_laptop *samsung;
1546 int ret;
1548 if (efi_enabled(EFI_BOOT))
1549 return -ENODEV;
1551 quirks = &samsung_unknown;
1552 if (!force && !dmi_check_system(samsung_dmi_table))
1553 return -ENODEV;
1555 samsung = kzalloc(sizeof(*samsung), GFP_KERNEL);
1556 if (!samsung)
1557 return -ENOMEM;
1559 mutex_init(&samsung->sabi_mutex);
1560 samsung->handle_backlight = true;
1561 samsung->quirks = quirks;
1564 #ifdef CONFIG_ACPI
1565 if (samsung->quirks->broken_acpi_video)
1566 acpi_video_dmi_promote_vendor();
1568 /* Don't handle backlight here if the acpi video already handle it */
1569 if (acpi_video_backlight_support()) {
1570 samsung->handle_backlight = false;
1571 } else if (samsung->quirks->broken_acpi_video) {
1572 pr_info("Disabling ACPI video driver\n");
1573 acpi_video_unregister();
1575 #endif
1577 ret = samsung_platform_init(samsung);
1578 if (ret)
1579 goto error_platform;
1581 ret = samsung_sabi_init(samsung);
1582 if (ret)
1583 goto error_sabi;
1585 #ifdef CONFIG_ACPI
1586 /* Only log that if we are really on a sabi platform */
1587 if (acpi_video_backlight_support())
1588 pr_info("Backlight controlled by ACPI video driver\n");
1589 #endif
1591 ret = samsung_sysfs_init(samsung);
1592 if (ret)
1593 goto error_sysfs;
1595 ret = samsung_backlight_init(samsung);
1596 if (ret)
1597 goto error_backlight;
1599 ret = samsung_rfkill_init(samsung);
1600 if (ret)
1601 goto error_rfkill;
1603 ret = samsung_leds_init(samsung);
1604 if (ret)
1605 goto error_leds;
1607 ret = samsung_debugfs_init(samsung);
1608 if (ret)
1609 goto error_debugfs;
1611 samsung_platform_device = samsung->platform_device;
1612 return ret;
1614 error_debugfs:
1615 samsung_leds_exit(samsung);
1616 error_leds:
1617 samsung_rfkill_exit(samsung);
1618 error_rfkill:
1619 samsung_backlight_exit(samsung);
1620 error_backlight:
1621 samsung_sysfs_exit(samsung);
1622 error_sysfs:
1623 samsung_sabi_exit(samsung);
1624 error_sabi:
1625 samsung_platform_exit(samsung);
1626 error_platform:
1627 kfree(samsung);
1628 return ret;
1631 static void __exit samsung_exit(void)
1633 struct samsung_laptop *samsung;
1635 samsung = platform_get_drvdata(samsung_platform_device);
1637 samsung_debugfs_exit(samsung);
1638 samsung_leds_exit(samsung);
1639 samsung_rfkill_exit(samsung);
1640 samsung_backlight_exit(samsung);
1641 samsung_sysfs_exit(samsung);
1642 samsung_sabi_exit(samsung);
1643 samsung_platform_exit(samsung);
1645 kfree(samsung);
1646 samsung_platform_device = NULL;
1649 module_init(samsung_init);
1650 module_exit(samsung_exit);
1652 MODULE_AUTHOR("Greg Kroah-Hartman <gregkh@suse.de>");
1653 MODULE_DESCRIPTION("Samsung Backlight driver");
1654 MODULE_LICENSE("GPL");