blob: de9f432cf22d10fabc0b9ca3b5782ebdd602fabb [file] [log] [blame]
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001/*
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>
Corentin Charyf674ebf2011-11-26 11:00:08 +010020#include <linux/leds.h>
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -050021#include <linux/fb.h>
22#include <linux/dmi.h>
23#include <linux/platform_device.h>
24#include <linux/rfkill.h>
Corentin Charyf34cd9c2011-11-26 11:00:00 +010025#include <linux/acpi.h>
Corentin Chary5b80fc42011-11-26 11:00:03 +010026#include <linux/seq_file.h>
27#include <linux/debugfs.h>
David Rientjes82c333a2012-03-20 09:53:06 +010028#include <linux/ctype.h>
Matt Fleming7f8d73f2013-01-03 09:02:37 +000029#include <linux/efi.h>
Corentin Charya979e2e2012-03-22 14:08:19 +010030#if (defined CONFIG_ACPI_VIDEO || defined CONFIG_ACPI_VIDEO_MODULE)
31#include <acpi/video.h>
32#endif
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -050033
34/*
35 * This driver is needed because a number of Samsung laptops do not hook
36 * their control settings through ACPI. So we have to poke around in the
37 * BIOS to do things like brightness values, and "special" key controls.
38 */
39
40/*
41 * We have 0 - 8 as valid brightness levels. The specs say that level 0 should
42 * be reserved by the BIOS (which really doesn't make much sense), we tell
43 * userspace that the value is 0 - 7 and then just tell the hardware 1 - 8
44 */
45#define MAX_BRIGHT 0x07
46
47
48#define SABI_IFACE_MAIN 0x00
49#define SABI_IFACE_SUB 0x02
50#define SABI_IFACE_COMPLETE 0x04
51#define SABI_IFACE_DATA 0x05
52
Corentin Chary84d482f2011-11-26 11:00:09 +010053#define WL_STATUS_WLAN 0x0
54#define WL_STATUS_BT 0x2
55
Corentin Chary7e960712011-11-26 11:00:02 +010056/* Structure get/set data using sabi */
57struct sabi_data {
58 union {
59 struct {
60 u32 d0;
61 u32 d1;
62 u16 d2;
63 u8 d3;
64 };
65 u8 data[11];
66 };
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -050067};
68
69struct sabi_header_offsets {
70 u8 port;
71 u8 re_mem;
72 u8 iface_func;
73 u8 en_mem;
74 u8 data_offset;
75 u8 data_segment;
76};
77
78struct sabi_commands {
79 /*
80 * Brightness is 0 - 8, as described above.
81 * Value 0 is for the BIOS to use
82 */
Corentin Chary7e960712011-11-26 11:00:02 +010083 u16 get_brightness;
84 u16 set_brightness;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -050085
86 /*
87 * first byte:
88 * 0x00 - wireless is off
89 * 0x01 - wireless is on
90 * second byte:
91 * 0x02 - 3G is off
92 * 0x03 - 3G is on
93 * TODO, verify 3G is correct, that doesn't seem right...
94 */
Corentin Chary7e960712011-11-26 11:00:02 +010095 u16 get_wireless_button;
96 u16 set_wireless_button;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -050097
98 /* 0 is off, 1 is on */
Corentin Chary7e960712011-11-26 11:00:02 +010099 u16 get_backlight;
100 u16 set_backlight;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500101
102 /*
103 * 0x80 or 0x00 - no action
104 * 0x81 - recovery key pressed
105 */
Corentin Chary7e960712011-11-26 11:00:02 +0100106 u16 get_recovery_mode;
107 u16 set_recovery_mode;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500108
109 /*
110 * on seclinux: 0 is low, 1 is high,
111 * on swsmi: 0 is normal, 1 is silent, 2 is turbo
112 */
Corentin Chary7e960712011-11-26 11:00:02 +0100113 u16 get_performance_level;
114 u16 set_performance_level;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500115
Corentin Charycb5b5c92011-11-26 11:00:05 +0100116 /* 0x80 is off, 0x81 is on */
117 u16 get_battery_life_extender;
118 u16 set_battery_life_extender;
119
Corentin Chary3a75d372011-11-26 11:00:06 +0100120 /* 0x80 is off, 0x81 is on */
121 u16 get_usb_charge;
122 u16 set_usb_charge;
123
Corentin Chary84d482f2011-11-26 11:00:09 +0100124 /* the first byte is for bluetooth and the third one is for wlan */
125 u16 get_wireless_status;
126 u16 set_wireless_status;
127
Corentin Charyf674ebf2011-11-26 11:00:08 +0100128 /* 0x81 to read, (0x82 | level << 8) to set, 0xaabb to enable */
129 u16 kbd_backlight;
130
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500131 /*
132 * Tell the BIOS that Linux is running on this machine.
133 * 81 is on, 80 is off
134 */
Corentin Chary7e960712011-11-26 11:00:02 +0100135 u16 set_linux;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500136};
137
138struct sabi_performance_level {
139 const char *name;
Corentin Chary7e960712011-11-26 11:00:02 +0100140 u16 value;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500141};
142
143struct sabi_config {
Corentin Chary84d482f2011-11-26 11:00:09 +0100144 int sabi_version;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500145 const char *test_string;
146 u16 main_function;
147 const struct sabi_header_offsets header_offsets;
148 const struct sabi_commands commands;
149 const struct sabi_performance_level performance_levels[4];
150 u8 min_brightness;
151 u8 max_brightness;
152};
153
154static const struct sabi_config sabi_configs[] = {
155 {
Corentin Chary84d482f2011-11-26 11:00:09 +0100156 /* I don't know if it is really 2, but it it is
157 * less than 3 anyway */
158 .sabi_version = 2,
159
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500160 .test_string = "SECLINUX",
161
162 .main_function = 0x4c49,
163
164 .header_offsets = {
165 .port = 0x00,
166 .re_mem = 0x02,
167 .iface_func = 0x03,
168 .en_mem = 0x04,
169 .data_offset = 0x05,
170 .data_segment = 0x07,
171 },
172
173 .commands = {
174 .get_brightness = 0x00,
175 .set_brightness = 0x01,
176
177 .get_wireless_button = 0x02,
178 .set_wireless_button = 0x03,
179
180 .get_backlight = 0x04,
181 .set_backlight = 0x05,
182
183 .get_recovery_mode = 0x06,
184 .set_recovery_mode = 0x07,
185
186 .get_performance_level = 0x08,
187 .set_performance_level = 0x09,
188
Corentin Charycb5b5c92011-11-26 11:00:05 +0100189 .get_battery_life_extender = 0xFFFF,
190 .set_battery_life_extender = 0xFFFF,
191
Corentin Chary3a75d372011-11-26 11:00:06 +0100192 .get_usb_charge = 0xFFFF,
193 .set_usb_charge = 0xFFFF,
194
Corentin Chary84d482f2011-11-26 11:00:09 +0100195 .get_wireless_status = 0xFFFF,
196 .set_wireless_status = 0xFFFF,
197
Corentin Charyf674ebf2011-11-26 11:00:08 +0100198 .kbd_backlight = 0xFFFF,
199
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500200 .set_linux = 0x0a,
201 },
202
203 .performance_levels = {
204 {
205 .name = "silent",
206 .value = 0,
207 },
208 {
209 .name = "normal",
210 .value = 1,
211 },
212 { },
213 },
214 .min_brightness = 1,
215 .max_brightness = 8,
216 },
217 {
Corentin Chary84d482f2011-11-26 11:00:09 +0100218 .sabi_version = 3,
219
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500220 .test_string = "SwSmi@",
221
222 .main_function = 0x5843,
223
224 .header_offsets = {
225 .port = 0x00,
226 .re_mem = 0x04,
227 .iface_func = 0x02,
228 .en_mem = 0x03,
229 .data_offset = 0x05,
230 .data_segment = 0x07,
231 },
232
233 .commands = {
234 .get_brightness = 0x10,
235 .set_brightness = 0x11,
236
237 .get_wireless_button = 0x12,
238 .set_wireless_button = 0x13,
239
240 .get_backlight = 0x2d,
241 .set_backlight = 0x2e,
242
243 .get_recovery_mode = 0xff,
244 .set_recovery_mode = 0xff,
245
246 .get_performance_level = 0x31,
247 .set_performance_level = 0x32,
248
Corentin Charycb5b5c92011-11-26 11:00:05 +0100249 .get_battery_life_extender = 0x65,
250 .set_battery_life_extender = 0x66,
251
Corentin Chary3a75d372011-11-26 11:00:06 +0100252 .get_usb_charge = 0x67,
253 .set_usb_charge = 0x68,
254
Corentin Chary84d482f2011-11-26 11:00:09 +0100255 .get_wireless_status = 0x69,
256 .set_wireless_status = 0x6a,
257
Corentin Charyf674ebf2011-11-26 11:00:08 +0100258 .kbd_backlight = 0x78,
259
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500260 .set_linux = 0xff,
261 },
262
263 .performance_levels = {
264 {
265 .name = "normal",
266 .value = 0,
267 },
268 {
269 .name = "silent",
270 .value = 1,
271 },
272 {
273 .name = "overclock",
274 .value = 2,
275 },
276 { },
277 },
278 .min_brightness = 0,
279 .max_brightness = 8,
280 },
281 { },
282};
283
Corentin Chary5b80fc42011-11-26 11:00:03 +0100284/*
285 * samsung-laptop/ - debugfs root directory
286 * f0000_segment - dump f0000 segment
287 * command - current command
288 * data - current data
289 * d0, d1, d2, d3 - data fields
290 * call - call SABI using command and data
291 *
292 * This allow to call arbitrary sabi commands wihout
293 * modifying the driver at all.
294 * For example, setting the keyboard backlight brightness to 5
295 *
296 * echo 0x78 > command
297 * echo 0x0582 > d0
298 * echo 0 > d1
299 * echo 0 > d2
300 * echo 0 > d3
301 * cat call
302 */
303
304struct samsung_laptop_debug {
305 struct dentry *root;
306 struct sabi_data data;
307 u16 command;
308
309 struct debugfs_blob_wrapper f0000_wrapper;
310 struct debugfs_blob_wrapper data_wrapper;
Corentin Chary6f6ae062011-11-26 11:00:11 +0100311 struct debugfs_blob_wrapper sdiag_wrapper;
Corentin Chary5b80fc42011-11-26 11:00:03 +0100312};
313
Corentin Chary84d482f2011-11-26 11:00:09 +0100314struct samsung_laptop;
315
316struct samsung_rfkill {
317 struct samsung_laptop *samsung;
318 struct rfkill *rfkill;
319 enum rfkill_type type;
320};
321
Corentin Charya6df4892011-11-26 10:59:58 +0100322struct samsung_laptop {
323 const struct sabi_config *config;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500324
Corentin Charya6df4892011-11-26 10:59:58 +0100325 void __iomem *sabi;
326 void __iomem *sabi_iface;
327 void __iomem *f0000_segment;
328
329 struct mutex sabi_mutex;
330
Corentin Chary5dea7a22011-11-26 10:59:59 +0100331 struct platform_device *platform_device;
Corentin Charya6df4892011-11-26 10:59:58 +0100332 struct backlight_device *backlight_device;
Corentin Chary84d482f2011-11-26 11:00:09 +0100333
334 struct samsung_rfkill wlan;
335 struct samsung_rfkill bluetooth;
Corentin Charya6df4892011-11-26 10:59:58 +0100336
Corentin Charyf674ebf2011-11-26 11:00:08 +0100337 struct led_classdev kbd_led;
338 int kbd_led_wk;
339 struct workqueue_struct *led_workqueue;
340 struct work_struct kbd_led_work;
341
Corentin Chary5b80fc42011-11-26 11:00:03 +0100342 struct samsung_laptop_debug debug;
Corentin Charya979e2e2012-03-22 14:08:19 +0100343 struct samsung_quirks *quirks;
Corentin Chary5b80fc42011-11-26 11:00:03 +0100344
Corentin Charyf34cd9c2011-11-26 11:00:00 +0100345 bool handle_backlight;
Corentin Charya6df4892011-11-26 10:59:58 +0100346 bool has_stepping_quirk;
Corentin Chary6f6ae062011-11-26 11:00:11 +0100347
348 char sdiag[64];
Corentin Charya6df4892011-11-26 10:59:58 +0100349};
350
Corentin Charya979e2e2012-03-22 14:08:19 +0100351struct samsung_quirks {
352 bool broken_acpi_video;
353};
Corentin Chary5dea7a22011-11-26 10:59:59 +0100354
Corentin Charya979e2e2012-03-22 14:08:19 +0100355static struct samsung_quirks samsung_unknown = {};
356
357static struct samsung_quirks samsung_broken_acpi_video = {
358 .broken_acpi_video = true,
359};
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500360
Rusty Russell90ab5ee2012-01-13 09:32:20 +1030361static bool force;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500362module_param(force, bool, 0);
363MODULE_PARM_DESC(force,
364 "Disable the DMI check and forces the driver to be loaded");
365
Rusty Russell90ab5ee2012-01-13 09:32:20 +1030366static bool debug;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500367module_param(debug, bool, S_IRUGO | S_IWUSR);
368MODULE_PARM_DESC(debug, "Debug enabled or not");
369
Corentin Chary7e960712011-11-26 11:00:02 +0100370static int sabi_command(struct samsung_laptop *samsung, u16 command,
371 struct sabi_data *in,
372 struct sabi_data *out)
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500373{
Corentin Charya6df4892011-11-26 10:59:58 +0100374 const struct sabi_config *config = samsung->config;
Corentin Chary7e960712011-11-26 11:00:02 +0100375 int ret = 0;
Corentin Charya6df4892011-11-26 10:59:58 +0100376 u16 port = readw(samsung->sabi + config->header_offsets.port);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500377 u8 complete, iface_data;
378
Corentin Charya6df4892011-11-26 10:59:58 +0100379 mutex_lock(&samsung->sabi_mutex);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500380
Corentin Chary7e960712011-11-26 11:00:02 +0100381 if (debug) {
382 if (in)
Corentin Chary2e777182011-11-26 11:00:12 +0100383 pr_info("SABI command:0x%04x "
384 "data:{0x%08x, 0x%08x, 0x%04x, 0x%02x}",
Corentin Chary7e960712011-11-26 11:00:02 +0100385 command, in->d0, in->d1, in->d2, in->d3);
386 else
Corentin Chary2e777182011-11-26 11:00:12 +0100387 pr_info("SABI command:0x%04x", command);
Corentin Chary7e960712011-11-26 11:00:02 +0100388 }
389
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500390 /* enable memory to be able to write to it */
Corentin Charya6df4892011-11-26 10:59:58 +0100391 outb(readb(samsung->sabi + config->header_offsets.en_mem), port);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500392
393 /* write out the command */
Corentin Charya6df4892011-11-26 10:59:58 +0100394 writew(config->main_function, samsung->sabi_iface + SABI_IFACE_MAIN);
395 writew(command, samsung->sabi_iface + SABI_IFACE_SUB);
396 writeb(0, samsung->sabi_iface + SABI_IFACE_COMPLETE);
Corentin Chary7e960712011-11-26 11:00:02 +0100397 if (in) {
398 writel(in->d0, samsung->sabi_iface + SABI_IFACE_DATA);
399 writel(in->d1, samsung->sabi_iface + SABI_IFACE_DATA + 4);
400 writew(in->d2, samsung->sabi_iface + SABI_IFACE_DATA + 8);
401 writeb(in->d3, samsung->sabi_iface + SABI_IFACE_DATA + 10);
402 }
Corentin Charya6df4892011-11-26 10:59:58 +0100403 outb(readb(samsung->sabi + config->header_offsets.iface_func), port);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500404
405 /* write protect memory to make it safe */
Corentin Charya6df4892011-11-26 10:59:58 +0100406 outb(readb(samsung->sabi + config->header_offsets.re_mem), port);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500407
408 /* see if the command actually succeeded */
Corentin Charya6df4892011-11-26 10:59:58 +0100409 complete = readb(samsung->sabi_iface + SABI_IFACE_COMPLETE);
410 iface_data = readb(samsung->sabi_iface + SABI_IFACE_DATA);
Corentin Chary2e777182011-11-26 11:00:12 +0100411
412 /* iface_data = 0xFF happens when a command is not known
413 * so we only add a warning in debug mode since we will
414 * probably issue some unknown command at startup to find
415 * out which features are supported */
416 if (complete != 0xaa || (iface_data == 0xff && debug))
Corentin Chary7e960712011-11-26 11:00:02 +0100417 pr_warn("SABI command 0x%04x failed with"
418 " completion flag 0x%02x and interface data 0x%02x",
419 command, complete, iface_data);
Corentin Chary2e777182011-11-26 11:00:12 +0100420
421 if (complete != 0xaa || iface_data == 0xff) {
Corentin Chary7e960712011-11-26 11:00:02 +0100422 ret = -EINVAL;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500423 goto exit;
424 }
Corentin Chary7e960712011-11-26 11:00:02 +0100425
426 if (out) {
427 out->d0 = readl(samsung->sabi_iface + SABI_IFACE_DATA);
428 out->d1 = readl(samsung->sabi_iface + SABI_IFACE_DATA + 4);
429 out->d2 = readw(samsung->sabi_iface + SABI_IFACE_DATA + 2);
430 out->d3 = readb(samsung->sabi_iface + SABI_IFACE_DATA + 1);
431 }
432
433 if (debug && out) {
Corentin Chary2e777182011-11-26 11:00:12 +0100434 pr_info("SABI return data:{0x%08x, 0x%08x, 0x%04x, 0x%02x}",
Corentin Chary7e960712011-11-26 11:00:02 +0100435 out->d0, out->d1, out->d2, out->d3);
436 }
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500437
438exit:
Corentin Charya6df4892011-11-26 10:59:58 +0100439 mutex_unlock(&samsung->sabi_mutex);
Corentin Chary7e960712011-11-26 11:00:02 +0100440 return ret;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500441}
442
Corentin Chary7e960712011-11-26 11:00:02 +0100443/* simple wrappers usable with most commands */
444static int sabi_set_commandb(struct samsung_laptop *samsung,
445 u16 command, u8 data)
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500446{
David Rientjes85229442012-03-20 09:53:05 +0100447 struct sabi_data in = { { { .d0 = 0, .d1 = 0, .d2 = 0, .d3 = 0 } } };
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500448
Corentin Chary7e960712011-11-26 11:00:02 +0100449 in.data[0] = data;
450 return sabi_command(samsung, command, &in, NULL);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500451}
452
Corentin Chary5dea7a22011-11-26 10:59:59 +0100453static int read_brightness(struct samsung_laptop *samsung)
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500454{
Corentin Charya6df4892011-11-26 10:59:58 +0100455 const struct sabi_config *config = samsung->config;
456 const struct sabi_commands *commands = &samsung->config->commands;
Corentin Chary7e960712011-11-26 11:00:02 +0100457 struct sabi_data sretval;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500458 int user_brightness = 0;
459 int retval;
460
Corentin Chary7e960712011-11-26 11:00:02 +0100461 retval = sabi_command(samsung, commands->get_brightness,
462 NULL, &sretval);
463 if (retval)
464 return retval;
465
466 user_brightness = sretval.data[0];
467 if (user_brightness > config->min_brightness)
468 user_brightness -= config->min_brightness;
469 else
470 user_brightness = 0;
471
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500472 return user_brightness;
473}
474
Corentin Chary5dea7a22011-11-26 10:59:59 +0100475static void set_brightness(struct samsung_laptop *samsung, u8 user_brightness)
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500476{
Corentin Charya6df4892011-11-26 10:59:58 +0100477 const struct sabi_config *config = samsung->config;
478 const struct sabi_commands *commands = &samsung->config->commands;
479 u8 user_level = user_brightness + config->min_brightness;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500480
Corentin Charya6df4892011-11-26 10:59:58 +0100481 if (samsung->has_stepping_quirk && user_level != 0) {
Jason Stubbsac080522011-09-20 09:16:13 -0700482 /*
483 * short circuit if the specified level is what's already set
484 * to prevent the screen from flickering needlessly
485 */
Corentin Chary5dea7a22011-11-26 10:59:59 +0100486 if (user_brightness == read_brightness(samsung))
Jason Stubbsac080522011-09-20 09:16:13 -0700487 return;
488
Corentin Chary7e960712011-11-26 11:00:02 +0100489 sabi_set_commandb(samsung, commands->set_brightness, 0);
Jason Stubbsac080522011-09-20 09:16:13 -0700490 }
491
Corentin Chary7e960712011-11-26 11:00:02 +0100492 sabi_set_commandb(samsung, commands->set_brightness, user_level);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500493}
494
495static int get_brightness(struct backlight_device *bd)
496{
Corentin Chary5dea7a22011-11-26 10:59:59 +0100497 struct samsung_laptop *samsung = bl_get_data(bd);
498
499 return read_brightness(samsung);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500500}
501
Corentin Chary5dea7a22011-11-26 10:59:59 +0100502static void check_for_stepping_quirk(struct samsung_laptop *samsung)
Jason Stubbsac080522011-09-20 09:16:13 -0700503{
Corentin Chary5dea7a22011-11-26 10:59:59 +0100504 int initial_level;
505 int check_level;
506 int orig_level = read_brightness(samsung);
Jason Stubbsac080522011-09-20 09:16:13 -0700507
508 /*
509 * Some laptops exhibit the strange behaviour of stepping toward
510 * (rather than setting) the brightness except when changing to/from
511 * brightness level 0. This behaviour is checked for here and worked
512 * around in set_brightness.
513 */
514
John Serockba05b232011-10-13 06:42:01 -0400515 if (orig_level == 0)
Corentin Chary5dea7a22011-11-26 10:59:59 +0100516 set_brightness(samsung, 1);
John Serockba05b232011-10-13 06:42:01 -0400517
Corentin Chary5dea7a22011-11-26 10:59:59 +0100518 initial_level = read_brightness(samsung);
John Serockba05b232011-10-13 06:42:01 -0400519
Jason Stubbsac080522011-09-20 09:16:13 -0700520 if (initial_level <= 2)
521 check_level = initial_level + 2;
522 else
523 check_level = initial_level - 2;
524
Corentin Charya6df4892011-11-26 10:59:58 +0100525 samsung->has_stepping_quirk = false;
Corentin Chary5dea7a22011-11-26 10:59:59 +0100526 set_brightness(samsung, check_level);
Jason Stubbsac080522011-09-20 09:16:13 -0700527
Corentin Chary5dea7a22011-11-26 10:59:59 +0100528 if (read_brightness(samsung) != check_level) {
Corentin Charya6df4892011-11-26 10:59:58 +0100529 samsung->has_stepping_quirk = true;
Jason Stubbsac080522011-09-20 09:16:13 -0700530 pr_info("enabled workaround for brightness stepping quirk\n");
531 }
532
Corentin Chary5dea7a22011-11-26 10:59:59 +0100533 set_brightness(samsung, orig_level);
Jason Stubbsac080522011-09-20 09:16:13 -0700534}
535
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500536static int update_status(struct backlight_device *bd)
537{
Corentin Chary5dea7a22011-11-26 10:59:59 +0100538 struct samsung_laptop *samsung = bl_get_data(bd);
Corentin Charya6df4892011-11-26 10:59:58 +0100539 const struct sabi_commands *commands = &samsung->config->commands;
540
Corentin Chary5dea7a22011-11-26 10:59:59 +0100541 set_brightness(samsung, bd->props.brightness);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500542
543 if (bd->props.power == FB_BLANK_UNBLANK)
Corentin Chary7e960712011-11-26 11:00:02 +0100544 sabi_set_commandb(samsung, commands->set_backlight, 1);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500545 else
Corentin Chary7e960712011-11-26 11:00:02 +0100546 sabi_set_commandb(samsung, commands->set_backlight, 0);
Corentin Chary5dea7a22011-11-26 10:59:59 +0100547
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500548 return 0;
549}
550
551static const struct backlight_ops backlight_ops = {
552 .get_brightness = get_brightness,
553 .update_status = update_status,
554};
555
Corentin Chary84d482f2011-11-26 11:00:09 +0100556static int seclinux_rfkill_set(void *data, bool blocked)
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500557{
Corentin Chary20db88e2011-12-15 08:27:39 +0100558 struct samsung_rfkill *srfkill = data;
559 struct samsung_laptop *samsung = srfkill->samsung;
Corentin Charya6df4892011-11-26 10:59:58 +0100560 const struct sabi_commands *commands = &samsung->config->commands;
561
Corentin Chary84d482f2011-11-26 11:00:09 +0100562 return sabi_set_commandb(samsung, commands->set_wireless_button,
563 !blocked);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500564}
565
Corentin Chary84d482f2011-11-26 11:00:09 +0100566static struct rfkill_ops seclinux_rfkill_ops = {
567 .set_block = seclinux_rfkill_set,
568};
569
570static int swsmi_wireless_status(struct samsung_laptop *samsung,
571 struct sabi_data *data)
572{
573 const struct sabi_commands *commands = &samsung->config->commands;
574
575 return sabi_command(samsung, commands->get_wireless_status,
576 NULL, data);
577}
578
579static int swsmi_rfkill_set(void *priv, bool blocked)
580{
581 struct samsung_rfkill *srfkill = priv;
582 struct samsung_laptop *samsung = srfkill->samsung;
583 const struct sabi_commands *commands = &samsung->config->commands;
584 struct sabi_data data;
585 int ret, i;
586
587 ret = swsmi_wireless_status(samsung, &data);
588 if (ret)
589 return ret;
590
591 /* Don't set the state for non-present devices */
592 for (i = 0; i < 4; i++)
593 if (data.data[i] == 0x02)
594 data.data[1] = 0;
595
596 if (srfkill->type == RFKILL_TYPE_WLAN)
597 data.data[WL_STATUS_WLAN] = !blocked;
598 else if (srfkill->type == RFKILL_TYPE_BLUETOOTH)
599 data.data[WL_STATUS_BT] = !blocked;
600
601 return sabi_command(samsung, commands->set_wireless_status,
602 &data, &data);
603}
604
605static void swsmi_rfkill_query(struct rfkill *rfkill, void *priv)
606{
607 struct samsung_rfkill *srfkill = priv;
608 struct samsung_laptop *samsung = srfkill->samsung;
609 struct sabi_data data;
610 int ret;
611
612 ret = swsmi_wireless_status(samsung, &data);
613 if (ret)
614 return ;
615
616 if (srfkill->type == RFKILL_TYPE_WLAN)
617 ret = data.data[WL_STATUS_WLAN];
618 else if (srfkill->type == RFKILL_TYPE_BLUETOOTH)
619 ret = data.data[WL_STATUS_BT];
620 else
621 return ;
622
623 rfkill_set_sw_state(rfkill, !ret);
624}
625
626static struct rfkill_ops swsmi_rfkill_ops = {
627 .set_block = swsmi_rfkill_set,
628 .query = swsmi_rfkill_query,
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500629};
630
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500631static ssize_t get_performance_level(struct device *dev,
632 struct device_attribute *attr, char *buf)
633{
Corentin Chary5dea7a22011-11-26 10:59:59 +0100634 struct samsung_laptop *samsung = dev_get_drvdata(dev);
Corentin Charya6df4892011-11-26 10:59:58 +0100635 const struct sabi_config *config = samsung->config;
Corentin Chary5dea7a22011-11-26 10:59:59 +0100636 const struct sabi_commands *commands = &config->commands;
Corentin Chary7e960712011-11-26 11:00:02 +0100637 struct sabi_data sretval;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500638 int retval;
639 int i;
640
641 /* Read the state */
Corentin Chary7e960712011-11-26 11:00:02 +0100642 retval = sabi_command(samsung, commands->get_performance_level,
643 NULL, &sretval);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500644 if (retval)
645 return retval;
646
647 /* The logic is backwards, yeah, lots of fun... */
Corentin Charya6df4892011-11-26 10:59:58 +0100648 for (i = 0; config->performance_levels[i].name; ++i) {
Corentin Chary7e960712011-11-26 11:00:02 +0100649 if (sretval.data[0] == config->performance_levels[i].value)
Corentin Charya6df4892011-11-26 10:59:58 +0100650 return sprintf(buf, "%s\n", config->performance_levels[i].name);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500651 }
652 return sprintf(buf, "%s\n", "unknown");
653}
654
655static ssize_t set_performance_level(struct device *dev,
656 struct device_attribute *attr, const char *buf,
657 size_t count)
658{
Corentin Chary5dea7a22011-11-26 10:59:59 +0100659 struct samsung_laptop *samsung = dev_get_drvdata(dev);
Corentin Charya6df4892011-11-26 10:59:58 +0100660 const struct sabi_config *config = samsung->config;
Corentin Chary5dea7a22011-11-26 10:59:59 +0100661 const struct sabi_commands *commands = &config->commands;
662 int i;
Corentin Charya6df4892011-11-26 10:59:58 +0100663
Corentin Chary5dea7a22011-11-26 10:59:59 +0100664 if (count < 1)
665 return count;
666
667 for (i = 0; config->performance_levels[i].name; ++i) {
668 const struct sabi_performance_level *level =
669 &config->performance_levels[i];
670 if (!strncasecmp(level->name, buf, strlen(level->name))) {
Corentin Chary7e960712011-11-26 11:00:02 +0100671 sabi_set_commandb(samsung,
672 commands->set_performance_level,
673 level->value);
Corentin Chary5dea7a22011-11-26 10:59:59 +0100674 break;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500675 }
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500676 }
Corentin Chary5dea7a22011-11-26 10:59:59 +0100677
678 if (!config->performance_levels[i].name)
679 return -EINVAL;
680
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500681 return count;
682}
Corentin Chary5dea7a22011-11-26 10:59:59 +0100683
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500684static DEVICE_ATTR(performance_level, S_IWUSR | S_IRUGO,
685 get_performance_level, set_performance_level);
686
Corentin Charycb5b5c92011-11-26 11:00:05 +0100687static int read_battery_life_extender(struct samsung_laptop *samsung)
688{
689 const struct sabi_commands *commands = &samsung->config->commands;
690 struct sabi_data data;
691 int retval;
692
693 if (commands->get_battery_life_extender == 0xFFFF)
694 return -ENODEV;
695
696 memset(&data, 0, sizeof(data));
697 data.data[0] = 0x80;
698 retval = sabi_command(samsung, commands->get_battery_life_extender,
699 &data, &data);
700
701 if (retval)
702 return retval;
703
704 if (data.data[0] != 0 && data.data[0] != 1)
705 return -ENODEV;
706
707 return data.data[0];
708}
709
710static int write_battery_life_extender(struct samsung_laptop *samsung,
711 int enabled)
712{
713 const struct sabi_commands *commands = &samsung->config->commands;
714 struct sabi_data data;
715
716 memset(&data, 0, sizeof(data));
717 data.data[0] = 0x80 | enabled;
718 return sabi_command(samsung, commands->set_battery_life_extender,
719 &data, NULL);
720}
721
722static ssize_t get_battery_life_extender(struct device *dev,
723 struct device_attribute *attr,
724 char *buf)
725{
726 struct samsung_laptop *samsung = dev_get_drvdata(dev);
727 int ret;
728
729 ret = read_battery_life_extender(samsung);
730 if (ret < 0)
731 return ret;
732
733 return sprintf(buf, "%d\n", ret);
734}
735
736static ssize_t set_battery_life_extender(struct device *dev,
737 struct device_attribute *attr,
738 const char *buf, size_t count)
739{
740 struct samsung_laptop *samsung = dev_get_drvdata(dev);
741 int ret, value;
742
743 if (!count || sscanf(buf, "%i", &value) != 1)
744 return -EINVAL;
745
746 ret = write_battery_life_extender(samsung, !!value);
747 if (ret < 0)
748 return ret;
749
750 return count;
751}
752
753static DEVICE_ATTR(battery_life_extender, S_IWUSR | S_IRUGO,
754 get_battery_life_extender, set_battery_life_extender);
755
Corentin Chary3a75d372011-11-26 11:00:06 +0100756static int read_usb_charge(struct samsung_laptop *samsung)
757{
758 const struct sabi_commands *commands = &samsung->config->commands;
759 struct sabi_data data;
760 int retval;
761
762 if (commands->get_usb_charge == 0xFFFF)
763 return -ENODEV;
764
765 memset(&data, 0, sizeof(data));
766 data.data[0] = 0x80;
767 retval = sabi_command(samsung, commands->get_usb_charge,
768 &data, &data);
769
770 if (retval)
771 return retval;
772
773 if (data.data[0] != 0 && data.data[0] != 1)
774 return -ENODEV;
775
776 return data.data[0];
777}
778
779static int write_usb_charge(struct samsung_laptop *samsung,
780 int enabled)
781{
782 const struct sabi_commands *commands = &samsung->config->commands;
783 struct sabi_data data;
784
785 memset(&data, 0, sizeof(data));
786 data.data[0] = 0x80 | enabled;
787 return sabi_command(samsung, commands->set_usb_charge,
788 &data, NULL);
789}
790
791static ssize_t get_usb_charge(struct device *dev,
792 struct device_attribute *attr,
793 char *buf)
794{
795 struct samsung_laptop *samsung = dev_get_drvdata(dev);
796 int ret;
797
798 ret = read_usb_charge(samsung);
799 if (ret < 0)
800 return ret;
801
802 return sprintf(buf, "%d\n", ret);
803}
804
805static ssize_t set_usb_charge(struct device *dev,
806 struct device_attribute *attr,
807 const char *buf, size_t count)
808{
809 struct samsung_laptop *samsung = dev_get_drvdata(dev);
810 int ret, value;
811
812 if (!count || sscanf(buf, "%i", &value) != 1)
813 return -EINVAL;
814
815 ret = write_usb_charge(samsung, !!value);
816 if (ret < 0)
817 return ret;
818
819 return count;
820}
821
822static DEVICE_ATTR(usb_charge, S_IWUSR | S_IRUGO,
823 get_usb_charge, set_usb_charge);
824
Corentin Charya66c1662011-11-26 11:00:01 +0100825static struct attribute *platform_attributes[] = {
826 &dev_attr_performance_level.attr,
Corentin Charycb5b5c92011-11-26 11:00:05 +0100827 &dev_attr_battery_life_extender.attr,
Corentin Chary3a75d372011-11-26 11:00:06 +0100828 &dev_attr_usb_charge.attr,
Corentin Charya66c1662011-11-26 11:00:01 +0100829 NULL
830};
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500831
Corentin Chary5dea7a22011-11-26 10:59:59 +0100832static int find_signature(void __iomem *memcheck, const char *testStr)
833{
834 int i = 0;
835 int loca;
836
837 for (loca = 0; loca < 0xffff; loca++) {
838 char temp = readb(memcheck + loca);
839
840 if (temp == testStr[i]) {
841 if (i == strlen(testStr)-1)
842 break;
843 ++i;
844 } else {
845 i = 0;
846 }
847 }
848 return loca;
849}
850
851static void samsung_rfkill_exit(struct samsung_laptop *samsung)
852{
Corentin Chary84d482f2011-11-26 11:00:09 +0100853 if (samsung->wlan.rfkill) {
854 rfkill_unregister(samsung->wlan.rfkill);
855 rfkill_destroy(samsung->wlan.rfkill);
856 samsung->wlan.rfkill = NULL;
Corentin Chary5dea7a22011-11-26 10:59:59 +0100857 }
Corentin Chary84d482f2011-11-26 11:00:09 +0100858 if (samsung->bluetooth.rfkill) {
859 rfkill_unregister(samsung->bluetooth.rfkill);
860 rfkill_destroy(samsung->bluetooth.rfkill);
861 samsung->bluetooth.rfkill = NULL;
862 }
863}
864
865static int samsung_new_rfkill(struct samsung_laptop *samsung,
866 struct samsung_rfkill *arfkill,
867 const char *name, enum rfkill_type type,
868 const struct rfkill_ops *ops,
869 int blocked)
870{
871 struct rfkill **rfkill = &arfkill->rfkill;
872 int ret;
873
874 arfkill->type = type;
875 arfkill->samsung = samsung;
876
877 *rfkill = rfkill_alloc(name, &samsung->platform_device->dev,
878 type, ops, arfkill);
879
880 if (!*rfkill)
881 return -EINVAL;
882
883 if (blocked != -1)
884 rfkill_init_sw_state(*rfkill, blocked);
885
886 ret = rfkill_register(*rfkill);
887 if (ret) {
888 rfkill_destroy(*rfkill);
889 *rfkill = NULL;
890 return ret;
891 }
892 return 0;
893}
894
895static int __init samsung_rfkill_init_seclinux(struct samsung_laptop *samsung)
896{
897 return samsung_new_rfkill(samsung, &samsung->wlan, "samsung-wlan",
898 RFKILL_TYPE_WLAN, &seclinux_rfkill_ops, -1);
899}
900
901static int __init samsung_rfkill_init_swsmi(struct samsung_laptop *samsung)
902{
903 struct sabi_data data;
904 int ret;
905
906 ret = swsmi_wireless_status(samsung, &data);
Corentin Chary20db88e2011-12-15 08:27:39 +0100907 if (ret) {
908 /* Some swsmi laptops use the old seclinux way to control
909 * wireless devices */
910 if (ret == -EINVAL)
911 ret = samsung_rfkill_init_seclinux(samsung);
Corentin Chary84d482f2011-11-26 11:00:09 +0100912 return ret;
Corentin Chary20db88e2011-12-15 08:27:39 +0100913 }
Corentin Chary84d482f2011-11-26 11:00:09 +0100914
915 /* 0x02 seems to mean that the device is no present/available */
916
917 if (data.data[WL_STATUS_WLAN] != 0x02)
918 ret = samsung_new_rfkill(samsung, &samsung->wlan,
919 "samsung-wlan",
920 RFKILL_TYPE_WLAN,
921 &swsmi_rfkill_ops,
922 !data.data[WL_STATUS_WLAN]);
923 if (ret)
924 goto exit;
925
926 if (data.data[WL_STATUS_BT] != 0x02)
927 ret = samsung_new_rfkill(samsung, &samsung->bluetooth,
928 "samsung-bluetooth",
929 RFKILL_TYPE_BLUETOOTH,
930 &swsmi_rfkill_ops,
931 !data.data[WL_STATUS_BT]);
932 if (ret)
933 goto exit;
934
935exit:
936 if (ret)
937 samsung_rfkill_exit(samsung);
938
939 return ret;
Corentin Chary5dea7a22011-11-26 10:59:59 +0100940}
941
942static int __init samsung_rfkill_init(struct samsung_laptop *samsung)
943{
Corentin Chary84d482f2011-11-26 11:00:09 +0100944 if (samsung->config->sabi_version == 2)
945 return samsung_rfkill_init_seclinux(samsung);
946 if (samsung->config->sabi_version == 3)
947 return samsung_rfkill_init_swsmi(samsung);
Corentin Chary5dea7a22011-11-26 10:59:59 +0100948 return 0;
949}
950
Corentin Charyf674ebf2011-11-26 11:00:08 +0100951static int kbd_backlight_enable(struct samsung_laptop *samsung)
952{
953 const struct sabi_commands *commands = &samsung->config->commands;
954 struct sabi_data data;
955 int retval;
956
957 if (commands->kbd_backlight == 0xFFFF)
958 return -ENODEV;
959
960 memset(&data, 0, sizeof(data));
961 data.d0 = 0xaabb;
962 retval = sabi_command(samsung, commands->kbd_backlight,
963 &data, &data);
964
965 if (retval)
966 return retval;
967
968 if (data.d0 != 0xccdd)
969 return -ENODEV;
970 return 0;
971}
972
973static int kbd_backlight_read(struct samsung_laptop *samsung)
974{
975 const struct sabi_commands *commands = &samsung->config->commands;
976 struct sabi_data data;
977 int retval;
978
979 memset(&data, 0, sizeof(data));
980 data.data[0] = 0x81;
981 retval = sabi_command(samsung, commands->kbd_backlight,
982 &data, &data);
983
984 if (retval)
985 return retval;
986
987 return data.data[0];
988}
989
990static int kbd_backlight_write(struct samsung_laptop *samsung, int brightness)
991{
992 const struct sabi_commands *commands = &samsung->config->commands;
993 struct sabi_data data;
994
995 memset(&data, 0, sizeof(data));
996 data.d0 = 0x82 | ((brightness & 0xFF) << 8);
997 return sabi_command(samsung, commands->kbd_backlight,
998 &data, NULL);
999}
1000
1001static void kbd_led_update(struct work_struct *work)
1002{
1003 struct samsung_laptop *samsung;
1004
1005 samsung = container_of(work, struct samsung_laptop, kbd_led_work);
1006 kbd_backlight_write(samsung, samsung->kbd_led_wk);
1007}
1008
1009static void kbd_led_set(struct led_classdev *led_cdev,
1010 enum led_brightness value)
1011{
1012 struct samsung_laptop *samsung;
1013
1014 samsung = container_of(led_cdev, struct samsung_laptop, kbd_led);
1015
1016 if (value > samsung->kbd_led.max_brightness)
1017 value = samsung->kbd_led.max_brightness;
1018 else if (value < 0)
1019 value = 0;
1020
1021 samsung->kbd_led_wk = value;
1022 queue_work(samsung->led_workqueue, &samsung->kbd_led_work);
1023}
1024
1025static enum led_brightness kbd_led_get(struct led_classdev *led_cdev)
1026{
1027 struct samsung_laptop *samsung;
1028
1029 samsung = container_of(led_cdev, struct samsung_laptop, kbd_led);
1030 return kbd_backlight_read(samsung);
1031}
1032
1033static void samsung_leds_exit(struct samsung_laptop *samsung)
1034{
1035 if (!IS_ERR_OR_NULL(samsung->kbd_led.dev))
1036 led_classdev_unregister(&samsung->kbd_led);
1037 if (samsung->led_workqueue)
1038 destroy_workqueue(samsung->led_workqueue);
1039}
1040
1041static int __init samsung_leds_init(struct samsung_laptop *samsung)
1042{
1043 int ret = 0;
1044
1045 samsung->led_workqueue = create_singlethread_workqueue("led_workqueue");
1046 if (!samsung->led_workqueue)
1047 return -ENOMEM;
1048
1049 if (kbd_backlight_enable(samsung) >= 0) {
1050 INIT_WORK(&samsung->kbd_led_work, kbd_led_update);
1051
1052 samsung->kbd_led.name = "samsung::kbd_backlight";
1053 samsung->kbd_led.brightness_set = kbd_led_set;
1054 samsung->kbd_led.brightness_get = kbd_led_get;
1055 samsung->kbd_led.max_brightness = 8;
1056
1057 ret = led_classdev_register(&samsung->platform_device->dev,
1058 &samsung->kbd_led);
1059 }
1060
1061 if (ret)
1062 samsung_leds_exit(samsung);
1063
1064 return ret;
1065}
1066
Corentin Chary5dea7a22011-11-26 10:59:59 +01001067static void samsung_backlight_exit(struct samsung_laptop *samsung)
1068{
1069 if (samsung->backlight_device) {
1070 backlight_device_unregister(samsung->backlight_device);
1071 samsung->backlight_device = NULL;
1072 }
1073}
1074
1075static int __init samsung_backlight_init(struct samsung_laptop *samsung)
1076{
1077 struct backlight_device *bd;
1078 struct backlight_properties props;
1079
Corentin Charyf34cd9c2011-11-26 11:00:00 +01001080 if (!samsung->handle_backlight)
1081 return 0;
1082
Corentin Chary5dea7a22011-11-26 10:59:59 +01001083 memset(&props, 0, sizeof(struct backlight_properties));
1084 props.type = BACKLIGHT_PLATFORM;
1085 props.max_brightness = samsung->config->max_brightness -
1086 samsung->config->min_brightness;
1087
1088 bd = backlight_device_register("samsung",
1089 &samsung->platform_device->dev,
1090 samsung, &backlight_ops,
1091 &props);
1092 if (IS_ERR(bd))
1093 return PTR_ERR(bd);
1094
1095 samsung->backlight_device = bd;
1096 samsung->backlight_device->props.brightness = read_brightness(samsung);
1097 samsung->backlight_device->props.power = FB_BLANK_UNBLANK;
1098 backlight_update_status(samsung->backlight_device);
1099
1100 return 0;
1101}
1102
Dan Carpenterbde9e502012-03-20 09:53:07 +01001103static umode_t samsung_sysfs_is_visible(struct kobject *kobj,
Corentin Charya66c1662011-11-26 11:00:01 +01001104 struct attribute *attr, int idx)
1105{
1106 struct device *dev = container_of(kobj, struct device, kobj);
1107 struct platform_device *pdev = to_platform_device(dev);
1108 struct samsung_laptop *samsung = platform_get_drvdata(pdev);
1109 bool ok = true;
1110
1111 if (attr == &dev_attr_performance_level.attr)
1112 ok = !!samsung->config->performance_levels[0].name;
Corentin Charycb5b5c92011-11-26 11:00:05 +01001113 if (attr == &dev_attr_battery_life_extender.attr)
1114 ok = !!(read_battery_life_extender(samsung) >= 0);
Corentin Chary3a75d372011-11-26 11:00:06 +01001115 if (attr == &dev_attr_usb_charge.attr)
1116 ok = !!(read_usb_charge(samsung) >= 0);
Corentin Charya66c1662011-11-26 11:00:01 +01001117
1118 return ok ? attr->mode : 0;
1119}
1120
1121static struct attribute_group platform_attribute_group = {
1122 .is_visible = samsung_sysfs_is_visible,
1123 .attrs = platform_attributes
1124};
1125
Corentin Chary5dea7a22011-11-26 10:59:59 +01001126static void samsung_sysfs_exit(struct samsung_laptop *samsung)
1127{
Corentin Charya66c1662011-11-26 11:00:01 +01001128 struct platform_device *device = samsung->platform_device;
1129
1130 sysfs_remove_group(&device->dev.kobj, &platform_attribute_group);
Corentin Chary5dea7a22011-11-26 10:59:59 +01001131}
1132
1133static int __init samsung_sysfs_init(struct samsung_laptop *samsung)
1134{
Corentin Charya66c1662011-11-26 11:00:01 +01001135 struct platform_device *device = samsung->platform_device;
1136
1137 return sysfs_create_group(&device->dev.kobj, &platform_attribute_group);
1138
Corentin Chary5dea7a22011-11-26 10:59:59 +01001139}
1140
Corentin Chary5b80fc42011-11-26 11:00:03 +01001141static int show_call(struct seq_file *m, void *data)
1142{
1143 struct samsung_laptop *samsung = m->private;
1144 struct sabi_data *sdata = &samsung->debug.data;
1145 int ret;
1146
1147 seq_printf(m, "SABI 0x%04x {0x%08x, 0x%08x, 0x%04x, 0x%02x}\n",
1148 samsung->debug.command,
1149 sdata->d0, sdata->d1, sdata->d2, sdata->d3);
1150
1151 ret = sabi_command(samsung, samsung->debug.command, sdata, sdata);
1152
1153 if (ret) {
1154 seq_printf(m, "SABI command 0x%04x failed\n",
1155 samsung->debug.command);
1156 return ret;
1157 }
1158
1159 seq_printf(m, "SABI {0x%08x, 0x%08x, 0x%04x, 0x%02x}\n",
1160 sdata->d0, sdata->d1, sdata->d2, sdata->d3);
1161 return 0;
1162}
1163
1164static int samsung_debugfs_open(struct inode *inode, struct file *file)
1165{
1166 return single_open(file, show_call, inode->i_private);
1167}
1168
1169static const struct file_operations samsung_laptop_call_io_ops = {
1170 .owner = THIS_MODULE,
1171 .open = samsung_debugfs_open,
1172 .read = seq_read,
1173 .llseek = seq_lseek,
1174 .release = single_release,
1175};
1176
1177static void samsung_debugfs_exit(struct samsung_laptop *samsung)
1178{
1179 debugfs_remove_recursive(samsung->debug.root);
1180}
1181
1182static int samsung_debugfs_init(struct samsung_laptop *samsung)
1183{
1184 struct dentry *dent;
1185
1186 samsung->debug.root = debugfs_create_dir("samsung-laptop", NULL);
1187 if (!samsung->debug.root) {
1188 pr_err("failed to create debugfs directory");
1189 goto error_debugfs;
1190 }
1191
1192 samsung->debug.f0000_wrapper.data = samsung->f0000_segment;
1193 samsung->debug.f0000_wrapper.size = 0xffff;
1194
1195 samsung->debug.data_wrapper.data = &samsung->debug.data;
1196 samsung->debug.data_wrapper.size = sizeof(samsung->debug.data);
1197
Corentin Chary6f6ae062011-11-26 11:00:11 +01001198 samsung->debug.sdiag_wrapper.data = samsung->sdiag;
1199 samsung->debug.sdiag_wrapper.size = strlen(samsung->sdiag);
1200
Corentin Chary5b80fc42011-11-26 11:00:03 +01001201 dent = debugfs_create_u16("command", S_IRUGO | S_IWUSR,
1202 samsung->debug.root, &samsung->debug.command);
1203 if (!dent)
1204 goto error_debugfs;
1205
1206 dent = debugfs_create_u32("d0", S_IRUGO | S_IWUSR, samsung->debug.root,
1207 &samsung->debug.data.d0);
1208 if (!dent)
1209 goto error_debugfs;
1210
1211 dent = debugfs_create_u32("d1", S_IRUGO | S_IWUSR, samsung->debug.root,
1212 &samsung->debug.data.d1);
1213 if (!dent)
1214 goto error_debugfs;
1215
1216 dent = debugfs_create_u16("d2", S_IRUGO | S_IWUSR, samsung->debug.root,
1217 &samsung->debug.data.d2);
1218 if (!dent)
1219 goto error_debugfs;
1220
1221 dent = debugfs_create_u8("d3", S_IRUGO | S_IWUSR, samsung->debug.root,
1222 &samsung->debug.data.d3);
1223 if (!dent)
1224 goto error_debugfs;
1225
1226 dent = debugfs_create_blob("data", S_IRUGO | S_IWUSR,
1227 samsung->debug.root,
1228 &samsung->debug.data_wrapper);
1229 if (!dent)
1230 goto error_debugfs;
1231
1232 dent = debugfs_create_blob("f0000_segment", S_IRUSR | S_IWUSR,
1233 samsung->debug.root,
1234 &samsung->debug.f0000_wrapper);
1235 if (!dent)
1236 goto error_debugfs;
1237
1238 dent = debugfs_create_file("call", S_IFREG | S_IRUGO,
1239 samsung->debug.root, samsung,
1240 &samsung_laptop_call_io_ops);
1241 if (!dent)
1242 goto error_debugfs;
1243
Corentin Chary6f6ae062011-11-26 11:00:11 +01001244 dent = debugfs_create_blob("sdiag", S_IRUGO | S_IWUSR,
1245 samsung->debug.root,
1246 &samsung->debug.sdiag_wrapper);
1247 if (!dent)
1248 goto error_debugfs;
1249
Corentin Chary5b80fc42011-11-26 11:00:03 +01001250 return 0;
1251
1252error_debugfs:
1253 samsung_debugfs_exit(samsung);
1254 return -ENOMEM;
1255}
1256
Corentin Chary5dea7a22011-11-26 10:59:59 +01001257static void samsung_sabi_exit(struct samsung_laptop *samsung)
1258{
1259 const struct sabi_config *config = samsung->config;
1260
1261 /* Turn off "Linux" mode in the BIOS */
1262 if (config && config->commands.set_linux != 0xff)
Corentin Chary7e960712011-11-26 11:00:02 +01001263 sabi_set_commandb(samsung, config->commands.set_linux, 0x80);
Corentin Chary5dea7a22011-11-26 10:59:59 +01001264
1265 if (samsung->sabi_iface) {
1266 iounmap(samsung->sabi_iface);
1267 samsung->sabi_iface = NULL;
1268 }
1269 if (samsung->f0000_segment) {
1270 iounmap(samsung->f0000_segment);
1271 samsung->f0000_segment = NULL;
1272 }
1273
1274 samsung->config = NULL;
1275}
1276
Corentin Chary49dd7732011-11-26 11:00:04 +01001277static __init void samsung_sabi_infos(struct samsung_laptop *samsung, int loca,
1278 unsigned int ifaceP)
Corentin Chary5dea7a22011-11-26 10:59:59 +01001279{
1280 const struct sabi_config *config = samsung->config;
1281
1282 printk(KERN_DEBUG "This computer supports SABI==%x\n",
1283 loca + 0xf0000 - 6);
Corentin Chary49dd7732011-11-26 11:00:04 +01001284
Corentin Chary5dea7a22011-11-26 10:59:59 +01001285 printk(KERN_DEBUG "SABI header:\n");
1286 printk(KERN_DEBUG " SMI Port Number = 0x%04x\n",
1287 readw(samsung->sabi + config->header_offsets.port));
1288 printk(KERN_DEBUG " SMI Interface Function = 0x%02x\n",
1289 readb(samsung->sabi + config->header_offsets.iface_func));
1290 printk(KERN_DEBUG " SMI enable memory buffer = 0x%02x\n",
1291 readb(samsung->sabi + config->header_offsets.en_mem));
1292 printk(KERN_DEBUG " SMI restore memory buffer = 0x%02x\n",
1293 readb(samsung->sabi + config->header_offsets.re_mem));
1294 printk(KERN_DEBUG " SABI data offset = 0x%04x\n",
1295 readw(samsung->sabi + config->header_offsets.data_offset));
1296 printk(KERN_DEBUG " SABI data segment = 0x%04x\n",
1297 readw(samsung->sabi + config->header_offsets.data_segment));
Corentin Chary5dea7a22011-11-26 10:59:59 +01001298
Corentin Chary49dd7732011-11-26 11:00:04 +01001299 printk(KERN_DEBUG " SABI pointer = 0x%08x\n", ifaceP);
Corentin Chary5dea7a22011-11-26 10:59:59 +01001300}
1301
Corentin Chary6f6ae062011-11-26 11:00:11 +01001302static void __init samsung_sabi_diag(struct samsung_laptop *samsung)
1303{
1304 int loca = find_signature(samsung->f0000_segment, "SDiaG@");
1305 int i;
1306
1307 if (loca == 0xffff)
1308 return ;
1309
1310 /* Example:
1311 * Ident: @SDiaG@686XX-N90X3A/966-SEC-07HL-S90X3A
1312 *
1313 * Product name: 90X3A
1314 * BIOS Version: 07HL
1315 */
1316 loca += 1;
1317 for (i = 0; loca < 0xffff && i < sizeof(samsung->sdiag) - 1; loca++) {
1318 char temp = readb(samsung->f0000_segment + loca);
1319
1320 if (isalnum(temp) || temp == '/' || temp == '-')
1321 samsung->sdiag[i++] = temp;
1322 else
1323 break ;
1324 }
1325
1326 if (debug && samsung->sdiag[0])
1327 pr_info("sdiag: %s", samsung->sdiag);
1328}
1329
Corentin Chary5dea7a22011-11-26 10:59:59 +01001330static int __init samsung_sabi_init(struct samsung_laptop *samsung)
1331{
1332 const struct sabi_config *config = NULL;
1333 const struct sabi_commands *commands;
1334 unsigned int ifaceP;
1335 int ret = 0;
1336 int i;
1337 int loca;
1338
1339 samsung->f0000_segment = ioremap_nocache(0xf0000, 0xffff);
1340 if (!samsung->f0000_segment) {
Corentin Chary3be324a2011-11-26 11:00:10 +01001341 if (debug || force)
1342 pr_err("Can't map the segment at 0xf0000\n");
Corentin Chary5dea7a22011-11-26 10:59:59 +01001343 ret = -EINVAL;
1344 goto exit;
1345 }
1346
Corentin Chary6f6ae062011-11-26 11:00:11 +01001347 samsung_sabi_diag(samsung);
1348
Corentin Chary5dea7a22011-11-26 10:59:59 +01001349 /* Try to find one of the signatures in memory to find the header */
1350 for (i = 0; sabi_configs[i].test_string != 0; ++i) {
1351 samsung->config = &sabi_configs[i];
1352 loca = find_signature(samsung->f0000_segment,
1353 samsung->config->test_string);
1354 if (loca != 0xffff)
1355 break;
1356 }
1357
1358 if (loca == 0xffff) {
Corentin Chary3be324a2011-11-26 11:00:10 +01001359 if (debug || force)
1360 pr_err("This computer does not support SABI\n");
Corentin Chary5dea7a22011-11-26 10:59:59 +01001361 ret = -ENODEV;
1362 goto exit;
1363 }
1364
1365 config = samsung->config;
1366 commands = &config->commands;
1367
1368 /* point to the SMI port Number */
1369 loca += 1;
1370 samsung->sabi = (samsung->f0000_segment + loca);
1371
Corentin Chary5dea7a22011-11-26 10:59:59 +01001372 /* Get a pointer to the SABI Interface */
1373 ifaceP = (readw(samsung->sabi + config->header_offsets.data_segment) & 0x0ffff) << 4;
1374 ifaceP += readw(samsung->sabi + config->header_offsets.data_offset) & 0x0ffff;
Corentin Chary49dd7732011-11-26 11:00:04 +01001375
1376 if (debug)
1377 samsung_sabi_infos(samsung, loca, ifaceP);
1378
Corentin Chary5dea7a22011-11-26 10:59:59 +01001379 samsung->sabi_iface = ioremap_nocache(ifaceP, 16);
1380 if (!samsung->sabi_iface) {
1381 pr_err("Can't remap %x\n", ifaceP);
1382 ret = -EINVAL;
1383 goto exit;
1384 }
1385
Corentin Chary5dea7a22011-11-26 10:59:59 +01001386 /* Turn on "Linux" mode in the BIOS */
1387 if (commands->set_linux != 0xff) {
Corentin Chary7e960712011-11-26 11:00:02 +01001388 int retval = sabi_set_commandb(samsung,
1389 commands->set_linux, 0x81);
Corentin Chary5dea7a22011-11-26 10:59:59 +01001390 if (retval) {
1391 pr_warn("Linux mode was not set!\n");
1392 ret = -ENODEV;
1393 goto exit;
1394 }
1395 }
1396
1397 /* Check for stepping quirk */
Corentin Charyf34cd9c2011-11-26 11:00:00 +01001398 if (samsung->handle_backlight)
1399 check_for_stepping_quirk(samsung);
Corentin Chary5dea7a22011-11-26 10:59:59 +01001400
Corentin Chary2e777182011-11-26 11:00:12 +01001401 pr_info("detected SABI interface: %s\n",
1402 samsung->config->test_string);
1403
Corentin Chary5dea7a22011-11-26 10:59:59 +01001404exit:
1405 if (ret)
1406 samsung_sabi_exit(samsung);
1407
1408 return ret;
1409}
1410
1411static void samsung_platform_exit(struct samsung_laptop *samsung)
1412{
1413 if (samsung->platform_device) {
1414 platform_device_unregister(samsung->platform_device);
1415 samsung->platform_device = NULL;
1416 }
1417}
1418
1419static int __init samsung_platform_init(struct samsung_laptop *samsung)
1420{
1421 struct platform_device *pdev;
1422
1423 pdev = platform_device_register_simple("samsung", -1, NULL, 0);
1424 if (IS_ERR(pdev))
1425 return PTR_ERR(pdev);
1426
1427 samsung->platform_device = pdev;
1428 platform_set_drvdata(samsung->platform_device, samsung);
1429 return 0;
1430}
1431
Corentin Charya979e2e2012-03-22 14:08:19 +01001432static struct samsung_quirks *quirks;
1433
1434static int __init samsung_dmi_matched(const struct dmi_system_id *d)
1435{
1436 quirks = d->driver_data;
1437 return 0;
1438}
1439
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001440static struct dmi_system_id __initdata samsung_dmi_table[] = {
1441 {
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001442 .matches = {
1443 DMI_MATCH(DMI_SYS_VENDOR,
1444 "SAMSUNG ELECTRONICS CO., LTD."),
Corentin Chary3be324a2011-11-26 11:00:10 +01001445 DMI_MATCH(DMI_CHASSIS_TYPE, "8"), /* Portable */
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001446 },
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001447 },
1448 {
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001449 .matches = {
1450 DMI_MATCH(DMI_SYS_VENDOR,
1451 "SAMSUNG ELECTRONICS CO., LTD."),
Corentin Chary3be324a2011-11-26 11:00:10 +01001452 DMI_MATCH(DMI_CHASSIS_TYPE, "9"), /* Laptop */
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001453 },
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001454 },
1455 {
J Witteveen4e2441c2011-07-03 13:15:44 +02001456 .matches = {
1457 DMI_MATCH(DMI_SYS_VENDOR,
1458 "SAMSUNG ELECTRONICS CO., LTD."),
Corentin Chary3be324a2011-11-26 11:00:10 +01001459 DMI_MATCH(DMI_CHASSIS_TYPE, "10"), /* Notebook */
J Witteveen4e2441c2011-07-03 13:15:44 +02001460 },
J Witteveen4e2441c2011-07-03 13:15:44 +02001461 },
1462 {
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001463 .matches = {
1464 DMI_MATCH(DMI_SYS_VENDOR,
1465 "SAMSUNG ELECTRONICS CO., LTD."),
Corentin Chary3be324a2011-11-26 11:00:10 +01001466 DMI_MATCH(DMI_CHASSIS_TYPE, "14"), /* Sub-Notebook */
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001467 },
Tommaso Massimi7500eeb2011-09-20 09:16:09 -07001468 },
Corentin Charya979e2e2012-03-22 14:08:19 +01001469 /* Specific DMI ids for laptop with quirks */
1470 {
1471 .callback = samsung_dmi_matched,
1472 .ident = "N150P",
1473 .matches = {
1474 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1475 DMI_MATCH(DMI_PRODUCT_NAME, "N150P"),
1476 DMI_MATCH(DMI_BOARD_NAME, "N150P"),
1477 },
1478 .driver_data = &samsung_broken_acpi_video,
1479 },
1480 {
1481 .callback = samsung_dmi_matched,
1482 .ident = "N145P/N250P/N260P",
1483 .matches = {
1484 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1485 DMI_MATCH(DMI_PRODUCT_NAME, "N145P/N250P/N260P"),
1486 DMI_MATCH(DMI_BOARD_NAME, "N145P/N250P/N260P"),
1487 },
1488 .driver_data = &samsung_broken_acpi_video,
1489 },
1490 {
1491 .callback = samsung_dmi_matched,
1492 .ident = "N150/N210/N220",
1493 .matches = {
1494 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1495 DMI_MATCH(DMI_PRODUCT_NAME, "N150/N210/N220"),
1496 DMI_MATCH(DMI_BOARD_NAME, "N150/N210/N220"),
1497 },
1498 .driver_data = &samsung_broken_acpi_video,
1499 },
1500 {
1501 .callback = samsung_dmi_matched,
1502 .ident = "NF110/NF210/NF310",
1503 .matches = {
1504 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1505 DMI_MATCH(DMI_PRODUCT_NAME, "NF110/NF210/NF310"),
1506 DMI_MATCH(DMI_BOARD_NAME, "NF110/NF210/NF310"),
1507 },
1508 .driver_data = &samsung_broken_acpi_video,
1509 },
Seth Forshee2c3a3712012-12-05 16:08:33 -06001510 {
1511 .callback = samsung_dmi_matched,
1512 .ident = "N250P",
1513 .matches = {
1514 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1515 DMI_MATCH(DMI_PRODUCT_NAME, "N250P"),
1516 DMI_MATCH(DMI_BOARD_NAME, "N250P"),
1517 },
1518 .driver_data = &samsung_broken_acpi_video,
1519 },
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001520 { },
1521};
1522MODULE_DEVICE_TABLE(dmi, samsung_dmi_table);
1523
Corentin Chary5dea7a22011-11-26 10:59:59 +01001524static struct platform_device *samsung_platform_device;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001525
1526static int __init samsung_init(void)
1527{
Corentin Chary5dea7a22011-11-26 10:59:59 +01001528 struct samsung_laptop *samsung;
1529 int ret;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001530
Matt Fleming7f8d73f2013-01-03 09:02:37 +00001531 if (efi_enabled(EFI_BOOT))
1532 return -ENODEV;
1533
Corentin Charya979e2e2012-03-22 14:08:19 +01001534 quirks = &samsung_unknown;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001535 if (!force && !dmi_check_system(samsung_dmi_table))
1536 return -ENODEV;
1537
Corentin Charya6df4892011-11-26 10:59:58 +01001538 samsung = kzalloc(sizeof(*samsung), GFP_KERNEL);
1539 if (!samsung)
1540 return -ENOMEM;
1541
1542 mutex_init(&samsung->sabi_mutex);
Corentin Charyf34cd9c2011-11-26 11:00:00 +01001543 samsung->handle_backlight = true;
Corentin Charya979e2e2012-03-22 14:08:19 +01001544 samsung->quirks = quirks;
Corentin Charyf34cd9c2011-11-26 11:00:00 +01001545
Corentin Charya979e2e2012-03-22 14:08:19 +01001546
1547#if (defined CONFIG_ACPI_VIDEO || defined CONFIG_ACPI_VIDEO_MODULE)
Corentin Charyf34cd9c2011-11-26 11:00:00 +01001548 /* Don't handle backlight here if the acpi video already handle it */
Corentin Charya979e2e2012-03-22 14:08:19 +01001549 if (acpi_video_backlight_support()) {
1550 if (samsung->quirks->broken_acpi_video) {
1551 pr_info("Disabling ACPI video driver\n");
1552 acpi_video_unregister();
1553 } else {
1554 samsung->handle_backlight = false;
1555 }
1556 }
Corentin Charyf34cd9c2011-11-26 11:00:00 +01001557#endif
Corentin Charya979e2e2012-03-22 14:08:19 +01001558
Corentin Chary5dea7a22011-11-26 10:59:59 +01001559 ret = samsung_platform_init(samsung);
1560 if (ret)
1561 goto error_platform;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001562
Corentin Chary5dea7a22011-11-26 10:59:59 +01001563 ret = samsung_sabi_init(samsung);
1564 if (ret)
1565 goto error_sabi;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001566
Corentin Chary3be324a2011-11-26 11:00:10 +01001567#ifdef CONFIG_ACPI
1568 /* Only log that if we are really on a sabi platform */
Corentin Charya979e2e2012-03-22 14:08:19 +01001569 if (acpi_video_backlight_support() &&
1570 !samsung->quirks->broken_acpi_video)
Corentin Chary3be324a2011-11-26 11:00:10 +01001571 pr_info("Backlight controlled by ACPI video driver\n");
1572#endif
1573
Corentin Chary5dea7a22011-11-26 10:59:59 +01001574 ret = samsung_sysfs_init(samsung);
1575 if (ret)
1576 goto error_sysfs;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001577
Corentin Chary5dea7a22011-11-26 10:59:59 +01001578 ret = samsung_backlight_init(samsung);
1579 if (ret)
1580 goto error_backlight;
Corentin Charya6df4892011-11-26 10:59:58 +01001581
Corentin Chary5dea7a22011-11-26 10:59:59 +01001582 ret = samsung_rfkill_init(samsung);
1583 if (ret)
1584 goto error_rfkill;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001585
Corentin Charyf674ebf2011-11-26 11:00:08 +01001586 ret = samsung_leds_init(samsung);
1587 if (ret)
1588 goto error_leds;
1589
Corentin Chary5b80fc42011-11-26 11:00:03 +01001590 ret = samsung_debugfs_init(samsung);
1591 if (ret)
1592 goto error_debugfs;
1593
Corentin Chary5dea7a22011-11-26 10:59:59 +01001594 samsung_platform_device = samsung->platform_device;
1595 return ret;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001596
Corentin Chary5b80fc42011-11-26 11:00:03 +01001597error_debugfs:
Corentin Charyf674ebf2011-11-26 11:00:08 +01001598 samsung_leds_exit(samsung);
1599error_leds:
Corentin Chary5b80fc42011-11-26 11:00:03 +01001600 samsung_rfkill_exit(samsung);
Corentin Chary5dea7a22011-11-26 10:59:59 +01001601error_rfkill:
1602 samsung_backlight_exit(samsung);
1603error_backlight:
1604 samsung_sysfs_exit(samsung);
1605error_sysfs:
1606 samsung_sabi_exit(samsung);
1607error_sabi:
1608 samsung_platform_exit(samsung);
1609error_platform:
Corentin Charya6df4892011-11-26 10:59:58 +01001610 kfree(samsung);
Corentin Chary5dea7a22011-11-26 10:59:59 +01001611 return ret;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001612}
1613
1614static void __exit samsung_exit(void)
1615{
Corentin Chary5dea7a22011-11-26 10:59:59 +01001616 struct samsung_laptop *samsung;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001617
Corentin Chary5dea7a22011-11-26 10:59:59 +01001618 samsung = platform_get_drvdata(samsung_platform_device);
Corentin Charya6df4892011-11-26 10:59:58 +01001619
Corentin Chary5b80fc42011-11-26 11:00:03 +01001620 samsung_debugfs_exit(samsung);
Corentin Charyf674ebf2011-11-26 11:00:08 +01001621 samsung_leds_exit(samsung);
Corentin Chary5dea7a22011-11-26 10:59:59 +01001622 samsung_rfkill_exit(samsung);
1623 samsung_backlight_exit(samsung);
1624 samsung_sysfs_exit(samsung);
1625 samsung_sabi_exit(samsung);
1626 samsung_platform_exit(samsung);
1627
Corentin Charya6df4892011-11-26 10:59:58 +01001628 kfree(samsung);
Corentin Chary5dea7a22011-11-26 10:59:59 +01001629 samsung_platform_device = NULL;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001630}
1631
1632module_init(samsung_init);
1633module_exit(samsung_exit);
1634
1635MODULE_AUTHOR("Greg Kroah-Hartman <gregkh@suse.de>");
1636MODULE_DESCRIPTION("Samsung Backlight driver");
1637MODULE_LICENSE("GPL");