blob: 5a59665122776d036cc43e885ec56845ea6b362b [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 Fleminge0094242013-01-03 09:02:37 +000029#include <linux/efi.h>
Scott Thrasher0ca849e2014-05-06 08:06:42 -070030#include <linux/suspend.h>
Corentin Charya979e2e2012-03-22 14:08:19 +010031#include <acpi/video.h>
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -050032
33/*
34 * This driver is needed because a number of Samsung laptops do not hook
35 * their control settings through ACPI. So we have to poke around in the
36 * BIOS to do things like brightness values, and "special" key controls.
37 */
38
39/*
40 * We have 0 - 8 as valid brightness levels. The specs say that level 0 should
41 * be reserved by the BIOS (which really doesn't make much sense), we tell
42 * userspace that the value is 0 - 7 and then just tell the hardware 1 - 8
43 */
44#define MAX_BRIGHT 0x07
45
46
47#define SABI_IFACE_MAIN 0x00
48#define SABI_IFACE_SUB 0x02
49#define SABI_IFACE_COMPLETE 0x04
50#define SABI_IFACE_DATA 0x05
51
Corentin Chary84d482f2011-11-26 11:00:09 +010052#define WL_STATUS_WLAN 0x0
53#define WL_STATUS_BT 0x2
54
Corentin Chary7e960712011-11-26 11:00:02 +010055/* Structure get/set data using sabi */
56struct sabi_data {
57 union {
58 struct {
59 u32 d0;
60 u32 d1;
61 u16 d2;
62 u8 d3;
63 };
64 u8 data[11];
65 };
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -050066};
67
68struct sabi_header_offsets {
69 u8 port;
70 u8 re_mem;
71 u8 iface_func;
72 u8 en_mem;
73 u8 data_offset;
74 u8 data_segment;
75};
76
77struct sabi_commands {
78 /*
79 * Brightness is 0 - 8, as described above.
80 * Value 0 is for the BIOS to use
81 */
Corentin Chary7e960712011-11-26 11:00:02 +010082 u16 get_brightness;
83 u16 set_brightness;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -050084
85 /*
86 * first byte:
87 * 0x00 - wireless is off
88 * 0x01 - wireless is on
89 * second byte:
90 * 0x02 - 3G is off
91 * 0x03 - 3G is on
92 * TODO, verify 3G is correct, that doesn't seem right...
93 */
Corentin Chary7e960712011-11-26 11:00:02 +010094 u16 get_wireless_button;
95 u16 set_wireless_button;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -050096
97 /* 0 is off, 1 is on */
Corentin Chary7e960712011-11-26 11:00:02 +010098 u16 get_backlight;
99 u16 set_backlight;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500100
101 /*
102 * 0x80 or 0x00 - no action
103 * 0x81 - recovery key pressed
104 */
Corentin Chary7e960712011-11-26 11:00:02 +0100105 u16 get_recovery_mode;
106 u16 set_recovery_mode;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500107
108 /*
109 * on seclinux: 0 is low, 1 is high,
110 * on swsmi: 0 is normal, 1 is silent, 2 is turbo
111 */
Corentin Chary7e960712011-11-26 11:00:02 +0100112 u16 get_performance_level;
113 u16 set_performance_level;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500114
Corentin Charycb5b5c92011-11-26 11:00:05 +0100115 /* 0x80 is off, 0x81 is on */
116 u16 get_battery_life_extender;
117 u16 set_battery_life_extender;
118
Corentin Chary3a75d372011-11-26 11:00:06 +0100119 /* 0x80 is off, 0x81 is on */
120 u16 get_usb_charge;
121 u16 set_usb_charge;
122
Corentin Chary84d482f2011-11-26 11:00:09 +0100123 /* the first byte is for bluetooth and the third one is for wlan */
124 u16 get_wireless_status;
125 u16 set_wireless_status;
126
Corentin Charyf674ebf2011-11-26 11:00:08 +0100127 /* 0x81 to read, (0x82 | level << 8) to set, 0xaabb to enable */
128 u16 kbd_backlight;
129
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500130 /*
131 * Tell the BIOS that Linux is running on this machine.
132 * 81 is on, 80 is off
133 */
Corentin Chary7e960712011-11-26 11:00:02 +0100134 u16 set_linux;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500135};
136
137struct sabi_performance_level {
138 const char *name;
Corentin Chary7e960712011-11-26 11:00:02 +0100139 u16 value;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500140};
141
142struct sabi_config {
Corentin Chary84d482f2011-11-26 11:00:09 +0100143 int sabi_version;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500144 const char *test_string;
145 u16 main_function;
146 const struct sabi_header_offsets header_offsets;
147 const struct sabi_commands commands;
148 const struct sabi_performance_level performance_levels[4];
149 u8 min_brightness;
150 u8 max_brightness;
151};
152
153static const struct sabi_config sabi_configs[] = {
154 {
Corentin Chary84d482f2011-11-26 11:00:09 +0100155 /* I don't know if it is really 2, but it it is
156 * less than 3 anyway */
157 .sabi_version = 2,
158
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500159 .test_string = "SECLINUX",
160
161 .main_function = 0x4c49,
162
163 .header_offsets = {
164 .port = 0x00,
165 .re_mem = 0x02,
166 .iface_func = 0x03,
167 .en_mem = 0x04,
168 .data_offset = 0x05,
169 .data_segment = 0x07,
170 },
171
172 .commands = {
173 .get_brightness = 0x00,
174 .set_brightness = 0x01,
175
176 .get_wireless_button = 0x02,
177 .set_wireless_button = 0x03,
178
179 .get_backlight = 0x04,
180 .set_backlight = 0x05,
181
182 .get_recovery_mode = 0x06,
183 .set_recovery_mode = 0x07,
184
185 .get_performance_level = 0x08,
186 .set_performance_level = 0x09,
187
Corentin Charycb5b5c92011-11-26 11:00:05 +0100188 .get_battery_life_extender = 0xFFFF,
189 .set_battery_life_extender = 0xFFFF,
190
Corentin Chary3a75d372011-11-26 11:00:06 +0100191 .get_usb_charge = 0xFFFF,
192 .set_usb_charge = 0xFFFF,
193
Corentin Chary84d482f2011-11-26 11:00:09 +0100194 .get_wireless_status = 0xFFFF,
195 .set_wireless_status = 0xFFFF,
196
Corentin Charyf674ebf2011-11-26 11:00:08 +0100197 .kbd_backlight = 0xFFFF,
198
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500199 .set_linux = 0x0a,
200 },
201
202 .performance_levels = {
203 {
204 .name = "silent",
205 .value = 0,
206 },
207 {
208 .name = "normal",
209 .value = 1,
210 },
211 { },
212 },
213 .min_brightness = 1,
214 .max_brightness = 8,
215 },
216 {
Corentin Chary84d482f2011-11-26 11:00:09 +0100217 .sabi_version = 3,
218
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500219 .test_string = "SwSmi@",
220
221 .main_function = 0x5843,
222
223 .header_offsets = {
224 .port = 0x00,
225 .re_mem = 0x04,
226 .iface_func = 0x02,
227 .en_mem = 0x03,
228 .data_offset = 0x05,
229 .data_segment = 0x07,
230 },
231
232 .commands = {
233 .get_brightness = 0x10,
234 .set_brightness = 0x11,
235
236 .get_wireless_button = 0x12,
237 .set_wireless_button = 0x13,
238
239 .get_backlight = 0x2d,
240 .set_backlight = 0x2e,
241
242 .get_recovery_mode = 0xff,
243 .set_recovery_mode = 0xff,
244
245 .get_performance_level = 0x31,
246 .set_performance_level = 0x32,
247
Corentin Charycb5b5c92011-11-26 11:00:05 +0100248 .get_battery_life_extender = 0x65,
249 .set_battery_life_extender = 0x66,
250
Corentin Chary3a75d372011-11-26 11:00:06 +0100251 .get_usb_charge = 0x67,
252 .set_usb_charge = 0x68,
253
Corentin Chary84d482f2011-11-26 11:00:09 +0100254 .get_wireless_status = 0x69,
255 .set_wireless_status = 0x6a,
256
Corentin Charyf674ebf2011-11-26 11:00:08 +0100257 .kbd_backlight = 0x78,
258
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500259 .set_linux = 0xff,
260 },
261
262 .performance_levels = {
263 {
264 .name = "normal",
265 .value = 0,
266 },
267 {
268 .name = "silent",
269 .value = 1,
270 },
271 {
272 .name = "overclock",
273 .value = 2,
274 },
275 { },
276 },
277 .min_brightness = 0,
278 .max_brightness = 8,
279 },
280 { },
281};
282
Corentin Chary5b80fc42011-11-26 11:00:03 +0100283/*
284 * samsung-laptop/ - debugfs root directory
285 * f0000_segment - dump f0000 segment
286 * command - current command
287 * data - current data
288 * d0, d1, d2, d3 - data fields
289 * call - call SABI using command and data
290 *
291 * This allow to call arbitrary sabi commands wihout
292 * modifying the driver at all.
293 * For example, setting the keyboard backlight brightness to 5
294 *
295 * echo 0x78 > command
296 * echo 0x0582 > d0
297 * echo 0 > d1
298 * echo 0 > d2
299 * echo 0 > d3
300 * cat call
301 */
302
303struct samsung_laptop_debug {
304 struct dentry *root;
305 struct sabi_data data;
306 u16 command;
307
308 struct debugfs_blob_wrapper f0000_wrapper;
309 struct debugfs_blob_wrapper data_wrapper;
Corentin Chary6f6ae062011-11-26 11:00:11 +0100310 struct debugfs_blob_wrapper sdiag_wrapper;
Corentin Chary5b80fc42011-11-26 11:00:03 +0100311};
312
Corentin Chary84d482f2011-11-26 11:00:09 +0100313struct samsung_laptop;
314
315struct samsung_rfkill {
316 struct samsung_laptop *samsung;
317 struct rfkill *rfkill;
318 enum rfkill_type type;
319};
320
Corentin Charya6df4892011-11-26 10:59:58 +0100321struct samsung_laptop {
322 const struct sabi_config *config;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500323
Corentin Charya6df4892011-11-26 10:59:58 +0100324 void __iomem *sabi;
325 void __iomem *sabi_iface;
326 void __iomem *f0000_segment;
327
328 struct mutex sabi_mutex;
329
Corentin Chary5dea7a22011-11-26 10:59:59 +0100330 struct platform_device *platform_device;
Corentin Charya6df4892011-11-26 10:59:58 +0100331 struct backlight_device *backlight_device;
Corentin Chary84d482f2011-11-26 11:00:09 +0100332
333 struct samsung_rfkill wlan;
334 struct samsung_rfkill bluetooth;
Corentin Charya6df4892011-11-26 10:59:58 +0100335
Corentin Charyf674ebf2011-11-26 11:00:08 +0100336 struct led_classdev kbd_led;
337 int kbd_led_wk;
338 struct workqueue_struct *led_workqueue;
339 struct work_struct kbd_led_work;
340
Corentin Chary5b80fc42011-11-26 11:00:03 +0100341 struct samsung_laptop_debug debug;
Corentin Charya979e2e2012-03-22 14:08:19 +0100342 struct samsung_quirks *quirks;
Corentin Chary5b80fc42011-11-26 11:00:03 +0100343
Scott Thrasher0ca849e2014-05-06 08:06:42 -0700344 struct notifier_block pm_nb;
345
Corentin Charyf34cd9c2011-11-26 11:00:00 +0100346 bool handle_backlight;
Corentin Charya6df4892011-11-26 10:59:58 +0100347 bool has_stepping_quirk;
Corentin Chary6f6ae062011-11-26 11:00:11 +0100348
349 char sdiag[64];
Corentin Charya6df4892011-11-26 10:59:58 +0100350};
351
Corentin Charya979e2e2012-03-22 14:08:19 +0100352struct samsung_quirks {
353 bool broken_acpi_video;
Scott Thrasher0ca849e2014-05-06 08:06:42 -0700354 bool four_kbd_backlight_levels;
355 bool enable_kbd_backlight;
Corentin Charya979e2e2012-03-22 14:08:19 +0100356};
Corentin Chary5dea7a22011-11-26 10:59:59 +0100357
Corentin Charya979e2e2012-03-22 14:08:19 +0100358static struct samsung_quirks samsung_unknown = {};
359
360static struct samsung_quirks samsung_broken_acpi_video = {
361 .broken_acpi_video = true,
362};
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500363
Scott Thrasher0ca849e2014-05-06 08:06:42 -0700364static struct samsung_quirks samsung_np740u3e = {
365 .four_kbd_backlight_levels = true,
366 .enable_kbd_backlight = true,
367};
368
Rusty Russell90ab5ee2012-01-13 09:32:20 +1030369static bool force;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500370module_param(force, bool, 0);
371MODULE_PARM_DESC(force,
372 "Disable the DMI check and forces the driver to be loaded");
373
Rusty Russell90ab5ee2012-01-13 09:32:20 +1030374static bool debug;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500375module_param(debug, bool, S_IRUGO | S_IWUSR);
376MODULE_PARM_DESC(debug, "Debug enabled or not");
377
Corentin Chary7e960712011-11-26 11:00:02 +0100378static int sabi_command(struct samsung_laptop *samsung, u16 command,
379 struct sabi_data *in,
380 struct sabi_data *out)
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500381{
Corentin Charya6df4892011-11-26 10:59:58 +0100382 const struct sabi_config *config = samsung->config;
Corentin Chary7e960712011-11-26 11:00:02 +0100383 int ret = 0;
Corentin Charya6df4892011-11-26 10:59:58 +0100384 u16 port = readw(samsung->sabi + config->header_offsets.port);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500385 u8 complete, iface_data;
386
Corentin Charya6df4892011-11-26 10:59:58 +0100387 mutex_lock(&samsung->sabi_mutex);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500388
Corentin Chary7e960712011-11-26 11:00:02 +0100389 if (debug) {
390 if (in)
Corentin Chary2e777182011-11-26 11:00:12 +0100391 pr_info("SABI command:0x%04x "
392 "data:{0x%08x, 0x%08x, 0x%04x, 0x%02x}",
Corentin Chary7e960712011-11-26 11:00:02 +0100393 command, in->d0, in->d1, in->d2, in->d3);
394 else
Corentin Chary2e777182011-11-26 11:00:12 +0100395 pr_info("SABI command:0x%04x", command);
Corentin Chary7e960712011-11-26 11:00:02 +0100396 }
397
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500398 /* enable memory to be able to write to it */
Corentin Charya6df4892011-11-26 10:59:58 +0100399 outb(readb(samsung->sabi + config->header_offsets.en_mem), port);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500400
401 /* write out the command */
Corentin Charya6df4892011-11-26 10:59:58 +0100402 writew(config->main_function, samsung->sabi_iface + SABI_IFACE_MAIN);
403 writew(command, samsung->sabi_iface + SABI_IFACE_SUB);
404 writeb(0, samsung->sabi_iface + SABI_IFACE_COMPLETE);
Corentin Chary7e960712011-11-26 11:00:02 +0100405 if (in) {
406 writel(in->d0, samsung->sabi_iface + SABI_IFACE_DATA);
407 writel(in->d1, samsung->sabi_iface + SABI_IFACE_DATA + 4);
408 writew(in->d2, samsung->sabi_iface + SABI_IFACE_DATA + 8);
409 writeb(in->d3, samsung->sabi_iface + SABI_IFACE_DATA + 10);
410 }
Corentin Charya6df4892011-11-26 10:59:58 +0100411 outb(readb(samsung->sabi + config->header_offsets.iface_func), port);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500412
413 /* write protect memory to make it safe */
Corentin Charya6df4892011-11-26 10:59:58 +0100414 outb(readb(samsung->sabi + config->header_offsets.re_mem), port);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500415
416 /* see if the command actually succeeded */
Corentin Charya6df4892011-11-26 10:59:58 +0100417 complete = readb(samsung->sabi_iface + SABI_IFACE_COMPLETE);
418 iface_data = readb(samsung->sabi_iface + SABI_IFACE_DATA);
Corentin Chary2e777182011-11-26 11:00:12 +0100419
420 /* iface_data = 0xFF happens when a command is not known
421 * so we only add a warning in debug mode since we will
422 * probably issue some unknown command at startup to find
423 * out which features are supported */
424 if (complete != 0xaa || (iface_data == 0xff && debug))
Corentin Chary7e960712011-11-26 11:00:02 +0100425 pr_warn("SABI command 0x%04x failed with"
426 " completion flag 0x%02x and interface data 0x%02x",
427 command, complete, iface_data);
Corentin Chary2e777182011-11-26 11:00:12 +0100428
429 if (complete != 0xaa || iface_data == 0xff) {
Corentin Chary7e960712011-11-26 11:00:02 +0100430 ret = -EINVAL;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500431 goto exit;
432 }
Corentin Chary7e960712011-11-26 11:00:02 +0100433
434 if (out) {
435 out->d0 = readl(samsung->sabi_iface + SABI_IFACE_DATA);
436 out->d1 = readl(samsung->sabi_iface + SABI_IFACE_DATA + 4);
437 out->d2 = readw(samsung->sabi_iface + SABI_IFACE_DATA + 2);
438 out->d3 = readb(samsung->sabi_iface + SABI_IFACE_DATA + 1);
439 }
440
441 if (debug && out) {
Corentin Chary2e777182011-11-26 11:00:12 +0100442 pr_info("SABI return data:{0x%08x, 0x%08x, 0x%04x, 0x%02x}",
Corentin Chary7e960712011-11-26 11:00:02 +0100443 out->d0, out->d1, out->d2, out->d3);
444 }
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500445
446exit:
Corentin Charya6df4892011-11-26 10:59:58 +0100447 mutex_unlock(&samsung->sabi_mutex);
Corentin Chary7e960712011-11-26 11:00:02 +0100448 return ret;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500449}
450
Corentin Chary7e960712011-11-26 11:00:02 +0100451/* simple wrappers usable with most commands */
452static int sabi_set_commandb(struct samsung_laptop *samsung,
453 u16 command, u8 data)
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500454{
David Rientjes85229442012-03-20 09:53:05 +0100455 struct sabi_data in = { { { .d0 = 0, .d1 = 0, .d2 = 0, .d3 = 0 } } };
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500456
Corentin Chary7e960712011-11-26 11:00:02 +0100457 in.data[0] = data;
458 return sabi_command(samsung, command, &in, NULL);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500459}
460
Corentin Chary5dea7a22011-11-26 10:59:59 +0100461static int read_brightness(struct samsung_laptop *samsung)
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500462{
Corentin Charya6df4892011-11-26 10:59:58 +0100463 const struct sabi_config *config = samsung->config;
464 const struct sabi_commands *commands = &samsung->config->commands;
Corentin Chary7e960712011-11-26 11:00:02 +0100465 struct sabi_data sretval;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500466 int user_brightness = 0;
467 int retval;
468
Corentin Chary7e960712011-11-26 11:00:02 +0100469 retval = sabi_command(samsung, commands->get_brightness,
470 NULL, &sretval);
471 if (retval)
472 return retval;
473
474 user_brightness = sretval.data[0];
475 if (user_brightness > config->min_brightness)
476 user_brightness -= config->min_brightness;
477 else
478 user_brightness = 0;
479
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500480 return user_brightness;
481}
482
Corentin Chary5dea7a22011-11-26 10:59:59 +0100483static void set_brightness(struct samsung_laptop *samsung, u8 user_brightness)
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500484{
Corentin Charya6df4892011-11-26 10:59:58 +0100485 const struct sabi_config *config = samsung->config;
486 const struct sabi_commands *commands = &samsung->config->commands;
487 u8 user_level = user_brightness + config->min_brightness;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500488
Corentin Charya6df4892011-11-26 10:59:58 +0100489 if (samsung->has_stepping_quirk && user_level != 0) {
Jason Stubbsac080522011-09-20 09:16:13 -0700490 /*
491 * short circuit if the specified level is what's already set
492 * to prevent the screen from flickering needlessly
493 */
Corentin Chary5dea7a22011-11-26 10:59:59 +0100494 if (user_brightness == read_brightness(samsung))
Jason Stubbsac080522011-09-20 09:16:13 -0700495 return;
496
Corentin Chary7e960712011-11-26 11:00:02 +0100497 sabi_set_commandb(samsung, commands->set_brightness, 0);
Jason Stubbsac080522011-09-20 09:16:13 -0700498 }
499
Corentin Chary7e960712011-11-26 11:00:02 +0100500 sabi_set_commandb(samsung, commands->set_brightness, user_level);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500501}
502
503static int get_brightness(struct backlight_device *bd)
504{
Corentin Chary5dea7a22011-11-26 10:59:59 +0100505 struct samsung_laptop *samsung = bl_get_data(bd);
506
507 return read_brightness(samsung);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500508}
509
Corentin Chary5dea7a22011-11-26 10:59:59 +0100510static void check_for_stepping_quirk(struct samsung_laptop *samsung)
Jason Stubbsac080522011-09-20 09:16:13 -0700511{
Corentin Chary5dea7a22011-11-26 10:59:59 +0100512 int initial_level;
513 int check_level;
514 int orig_level = read_brightness(samsung);
Jason Stubbsac080522011-09-20 09:16:13 -0700515
516 /*
517 * Some laptops exhibit the strange behaviour of stepping toward
518 * (rather than setting) the brightness except when changing to/from
519 * brightness level 0. This behaviour is checked for here and worked
520 * around in set_brightness.
521 */
522
John Serockba05b232011-10-13 06:42:01 -0400523 if (orig_level == 0)
Corentin Chary5dea7a22011-11-26 10:59:59 +0100524 set_brightness(samsung, 1);
John Serockba05b232011-10-13 06:42:01 -0400525
Corentin Chary5dea7a22011-11-26 10:59:59 +0100526 initial_level = read_brightness(samsung);
John Serockba05b232011-10-13 06:42:01 -0400527
Jason Stubbsac080522011-09-20 09:16:13 -0700528 if (initial_level <= 2)
529 check_level = initial_level + 2;
530 else
531 check_level = initial_level - 2;
532
Corentin Charya6df4892011-11-26 10:59:58 +0100533 samsung->has_stepping_quirk = false;
Corentin Chary5dea7a22011-11-26 10:59:59 +0100534 set_brightness(samsung, check_level);
Jason Stubbsac080522011-09-20 09:16:13 -0700535
Corentin Chary5dea7a22011-11-26 10:59:59 +0100536 if (read_brightness(samsung) != check_level) {
Corentin Charya6df4892011-11-26 10:59:58 +0100537 samsung->has_stepping_quirk = true;
Jason Stubbsac080522011-09-20 09:16:13 -0700538 pr_info("enabled workaround for brightness stepping quirk\n");
539 }
540
Corentin Chary5dea7a22011-11-26 10:59:59 +0100541 set_brightness(samsung, orig_level);
Jason Stubbsac080522011-09-20 09:16:13 -0700542}
543
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500544static int update_status(struct backlight_device *bd)
545{
Corentin Chary5dea7a22011-11-26 10:59:59 +0100546 struct samsung_laptop *samsung = bl_get_data(bd);
Corentin Charya6df4892011-11-26 10:59:58 +0100547 const struct sabi_commands *commands = &samsung->config->commands;
548
Corentin Chary5dea7a22011-11-26 10:59:59 +0100549 set_brightness(samsung, bd->props.brightness);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500550
551 if (bd->props.power == FB_BLANK_UNBLANK)
Corentin Chary7e960712011-11-26 11:00:02 +0100552 sabi_set_commandb(samsung, commands->set_backlight, 1);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500553 else
Corentin Chary7e960712011-11-26 11:00:02 +0100554 sabi_set_commandb(samsung, commands->set_backlight, 0);
Corentin Chary5dea7a22011-11-26 10:59:59 +0100555
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500556 return 0;
557}
558
559static const struct backlight_ops backlight_ops = {
560 .get_brightness = get_brightness,
561 .update_status = update_status,
562};
563
Corentin Chary84d482f2011-11-26 11:00:09 +0100564static int seclinux_rfkill_set(void *data, bool blocked)
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500565{
Corentin Chary20db88e2011-12-15 08:27:39 +0100566 struct samsung_rfkill *srfkill = data;
567 struct samsung_laptop *samsung = srfkill->samsung;
Corentin Charya6df4892011-11-26 10:59:58 +0100568 const struct sabi_commands *commands = &samsung->config->commands;
569
Corentin Chary84d482f2011-11-26 11:00:09 +0100570 return sabi_set_commandb(samsung, commands->set_wireless_button,
571 !blocked);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500572}
573
Corentin Chary84d482f2011-11-26 11:00:09 +0100574static struct rfkill_ops seclinux_rfkill_ops = {
575 .set_block = seclinux_rfkill_set,
576};
577
578static int swsmi_wireless_status(struct samsung_laptop *samsung,
579 struct sabi_data *data)
580{
581 const struct sabi_commands *commands = &samsung->config->commands;
582
583 return sabi_command(samsung, commands->get_wireless_status,
584 NULL, data);
585}
586
587static int swsmi_rfkill_set(void *priv, bool blocked)
588{
589 struct samsung_rfkill *srfkill = priv;
590 struct samsung_laptop *samsung = srfkill->samsung;
591 const struct sabi_commands *commands = &samsung->config->commands;
592 struct sabi_data data;
593 int ret, i;
594
595 ret = swsmi_wireless_status(samsung, &data);
596 if (ret)
597 return ret;
598
599 /* Don't set the state for non-present devices */
600 for (i = 0; i < 4; i++)
601 if (data.data[i] == 0x02)
602 data.data[1] = 0;
603
604 if (srfkill->type == RFKILL_TYPE_WLAN)
605 data.data[WL_STATUS_WLAN] = !blocked;
606 else if (srfkill->type == RFKILL_TYPE_BLUETOOTH)
607 data.data[WL_STATUS_BT] = !blocked;
608
609 return sabi_command(samsung, commands->set_wireless_status,
610 &data, &data);
611}
612
613static void swsmi_rfkill_query(struct rfkill *rfkill, void *priv)
614{
615 struct samsung_rfkill *srfkill = priv;
616 struct samsung_laptop *samsung = srfkill->samsung;
617 struct sabi_data data;
618 int ret;
619
620 ret = swsmi_wireless_status(samsung, &data);
621 if (ret)
622 return ;
623
624 if (srfkill->type == RFKILL_TYPE_WLAN)
625 ret = data.data[WL_STATUS_WLAN];
626 else if (srfkill->type == RFKILL_TYPE_BLUETOOTH)
627 ret = data.data[WL_STATUS_BT];
628 else
629 return ;
630
631 rfkill_set_sw_state(rfkill, !ret);
632}
633
634static struct rfkill_ops swsmi_rfkill_ops = {
635 .set_block = swsmi_rfkill_set,
636 .query = swsmi_rfkill_query,
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500637};
638
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500639static ssize_t get_performance_level(struct device *dev,
640 struct device_attribute *attr, char *buf)
641{
Corentin Chary5dea7a22011-11-26 10:59:59 +0100642 struct samsung_laptop *samsung = dev_get_drvdata(dev);
Corentin Charya6df4892011-11-26 10:59:58 +0100643 const struct sabi_config *config = samsung->config;
Corentin Chary5dea7a22011-11-26 10:59:59 +0100644 const struct sabi_commands *commands = &config->commands;
Corentin Chary7e960712011-11-26 11:00:02 +0100645 struct sabi_data sretval;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500646 int retval;
647 int i;
648
649 /* Read the state */
Corentin Chary7e960712011-11-26 11:00:02 +0100650 retval = sabi_command(samsung, commands->get_performance_level,
651 NULL, &sretval);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500652 if (retval)
653 return retval;
654
655 /* The logic is backwards, yeah, lots of fun... */
Corentin Charya6df4892011-11-26 10:59:58 +0100656 for (i = 0; config->performance_levels[i].name; ++i) {
Corentin Chary7e960712011-11-26 11:00:02 +0100657 if (sretval.data[0] == config->performance_levels[i].value)
Corentin Charya6df4892011-11-26 10:59:58 +0100658 return sprintf(buf, "%s\n", config->performance_levels[i].name);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500659 }
660 return sprintf(buf, "%s\n", "unknown");
661}
662
663static ssize_t set_performance_level(struct device *dev,
664 struct device_attribute *attr, const char *buf,
665 size_t count)
666{
Corentin Chary5dea7a22011-11-26 10:59:59 +0100667 struct samsung_laptop *samsung = dev_get_drvdata(dev);
Corentin Charya6df4892011-11-26 10:59:58 +0100668 const struct sabi_config *config = samsung->config;
Corentin Chary5dea7a22011-11-26 10:59:59 +0100669 const struct sabi_commands *commands = &config->commands;
670 int i;
Corentin Charya6df4892011-11-26 10:59:58 +0100671
Corentin Chary5dea7a22011-11-26 10:59:59 +0100672 if (count < 1)
673 return count;
674
675 for (i = 0; config->performance_levels[i].name; ++i) {
676 const struct sabi_performance_level *level =
677 &config->performance_levels[i];
678 if (!strncasecmp(level->name, buf, strlen(level->name))) {
Corentin Chary7e960712011-11-26 11:00:02 +0100679 sabi_set_commandb(samsung,
680 commands->set_performance_level,
681 level->value);
Corentin Chary5dea7a22011-11-26 10:59:59 +0100682 break;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500683 }
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500684 }
Corentin Chary5dea7a22011-11-26 10:59:59 +0100685
686 if (!config->performance_levels[i].name)
687 return -EINVAL;
688
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500689 return count;
690}
Corentin Chary5dea7a22011-11-26 10:59:59 +0100691
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500692static DEVICE_ATTR(performance_level, S_IWUSR | S_IRUGO,
693 get_performance_level, set_performance_level);
694
Corentin Charycb5b5c92011-11-26 11:00:05 +0100695static int read_battery_life_extender(struct samsung_laptop *samsung)
696{
697 const struct sabi_commands *commands = &samsung->config->commands;
698 struct sabi_data data;
699 int retval;
700
701 if (commands->get_battery_life_extender == 0xFFFF)
702 return -ENODEV;
703
704 memset(&data, 0, sizeof(data));
705 data.data[0] = 0x80;
706 retval = sabi_command(samsung, commands->get_battery_life_extender,
707 &data, &data);
708
709 if (retval)
710 return retval;
711
712 if (data.data[0] != 0 && data.data[0] != 1)
713 return -ENODEV;
714
715 return data.data[0];
716}
717
718static int write_battery_life_extender(struct samsung_laptop *samsung,
719 int enabled)
720{
721 const struct sabi_commands *commands = &samsung->config->commands;
722 struct sabi_data data;
723
724 memset(&data, 0, sizeof(data));
725 data.data[0] = 0x80 | enabled;
726 return sabi_command(samsung, commands->set_battery_life_extender,
727 &data, NULL);
728}
729
730static ssize_t get_battery_life_extender(struct device *dev,
731 struct device_attribute *attr,
732 char *buf)
733{
734 struct samsung_laptop *samsung = dev_get_drvdata(dev);
735 int ret;
736
737 ret = read_battery_life_extender(samsung);
738 if (ret < 0)
739 return ret;
740
741 return sprintf(buf, "%d\n", ret);
742}
743
744static ssize_t set_battery_life_extender(struct device *dev,
745 struct device_attribute *attr,
746 const char *buf, size_t count)
747{
748 struct samsung_laptop *samsung = dev_get_drvdata(dev);
749 int ret, value;
750
751 if (!count || sscanf(buf, "%i", &value) != 1)
752 return -EINVAL;
753
754 ret = write_battery_life_extender(samsung, !!value);
755 if (ret < 0)
756 return ret;
757
758 return count;
759}
760
761static DEVICE_ATTR(battery_life_extender, S_IWUSR | S_IRUGO,
762 get_battery_life_extender, set_battery_life_extender);
763
Corentin Chary3a75d372011-11-26 11:00:06 +0100764static int read_usb_charge(struct samsung_laptop *samsung)
765{
766 const struct sabi_commands *commands = &samsung->config->commands;
767 struct sabi_data data;
768 int retval;
769
770 if (commands->get_usb_charge == 0xFFFF)
771 return -ENODEV;
772
773 memset(&data, 0, sizeof(data));
774 data.data[0] = 0x80;
775 retval = sabi_command(samsung, commands->get_usb_charge,
776 &data, &data);
777
778 if (retval)
779 return retval;
780
781 if (data.data[0] != 0 && data.data[0] != 1)
782 return -ENODEV;
783
784 return data.data[0];
785}
786
787static int write_usb_charge(struct samsung_laptop *samsung,
788 int enabled)
789{
790 const struct sabi_commands *commands = &samsung->config->commands;
791 struct sabi_data data;
792
793 memset(&data, 0, sizeof(data));
794 data.data[0] = 0x80 | enabled;
795 return sabi_command(samsung, commands->set_usb_charge,
796 &data, NULL);
797}
798
799static ssize_t get_usb_charge(struct device *dev,
800 struct device_attribute *attr,
801 char *buf)
802{
803 struct samsung_laptop *samsung = dev_get_drvdata(dev);
804 int ret;
805
806 ret = read_usb_charge(samsung);
807 if (ret < 0)
808 return ret;
809
810 return sprintf(buf, "%d\n", ret);
811}
812
813static ssize_t set_usb_charge(struct device *dev,
814 struct device_attribute *attr,
815 const char *buf, size_t count)
816{
817 struct samsung_laptop *samsung = dev_get_drvdata(dev);
818 int ret, value;
819
820 if (!count || sscanf(buf, "%i", &value) != 1)
821 return -EINVAL;
822
823 ret = write_usb_charge(samsung, !!value);
824 if (ret < 0)
825 return ret;
826
827 return count;
828}
829
830static DEVICE_ATTR(usb_charge, S_IWUSR | S_IRUGO,
831 get_usb_charge, set_usb_charge);
832
Corentin Charya66c1662011-11-26 11:00:01 +0100833static struct attribute *platform_attributes[] = {
834 &dev_attr_performance_level.attr,
Corentin Charycb5b5c92011-11-26 11:00:05 +0100835 &dev_attr_battery_life_extender.attr,
Corentin Chary3a75d372011-11-26 11:00:06 +0100836 &dev_attr_usb_charge.attr,
Corentin Charya66c1662011-11-26 11:00:01 +0100837 NULL
838};
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500839
Corentin Chary5dea7a22011-11-26 10:59:59 +0100840static int find_signature(void __iomem *memcheck, const char *testStr)
841{
842 int i = 0;
843 int loca;
844
845 for (loca = 0; loca < 0xffff; loca++) {
846 char temp = readb(memcheck + loca);
847
848 if (temp == testStr[i]) {
849 if (i == strlen(testStr)-1)
850 break;
851 ++i;
852 } else {
853 i = 0;
854 }
855 }
856 return loca;
857}
858
859static void samsung_rfkill_exit(struct samsung_laptop *samsung)
860{
Corentin Chary84d482f2011-11-26 11:00:09 +0100861 if (samsung->wlan.rfkill) {
862 rfkill_unregister(samsung->wlan.rfkill);
863 rfkill_destroy(samsung->wlan.rfkill);
864 samsung->wlan.rfkill = NULL;
Corentin Chary5dea7a22011-11-26 10:59:59 +0100865 }
Corentin Chary84d482f2011-11-26 11:00:09 +0100866 if (samsung->bluetooth.rfkill) {
867 rfkill_unregister(samsung->bluetooth.rfkill);
868 rfkill_destroy(samsung->bluetooth.rfkill);
869 samsung->bluetooth.rfkill = NULL;
870 }
871}
872
873static int samsung_new_rfkill(struct samsung_laptop *samsung,
874 struct samsung_rfkill *arfkill,
875 const char *name, enum rfkill_type type,
876 const struct rfkill_ops *ops,
877 int blocked)
878{
879 struct rfkill **rfkill = &arfkill->rfkill;
880 int ret;
881
882 arfkill->type = type;
883 arfkill->samsung = samsung;
884
885 *rfkill = rfkill_alloc(name, &samsung->platform_device->dev,
886 type, ops, arfkill);
887
888 if (!*rfkill)
889 return -EINVAL;
890
891 if (blocked != -1)
892 rfkill_init_sw_state(*rfkill, blocked);
893
894 ret = rfkill_register(*rfkill);
895 if (ret) {
896 rfkill_destroy(*rfkill);
897 *rfkill = NULL;
898 return ret;
899 }
900 return 0;
901}
902
903static int __init samsung_rfkill_init_seclinux(struct samsung_laptop *samsung)
904{
905 return samsung_new_rfkill(samsung, &samsung->wlan, "samsung-wlan",
906 RFKILL_TYPE_WLAN, &seclinux_rfkill_ops, -1);
907}
908
909static int __init samsung_rfkill_init_swsmi(struct samsung_laptop *samsung)
910{
911 struct sabi_data data;
912 int ret;
913
914 ret = swsmi_wireless_status(samsung, &data);
Corentin Chary20db88e2011-12-15 08:27:39 +0100915 if (ret) {
916 /* Some swsmi laptops use the old seclinux way to control
917 * wireless devices */
918 if (ret == -EINVAL)
919 ret = samsung_rfkill_init_seclinux(samsung);
Corentin Chary84d482f2011-11-26 11:00:09 +0100920 return ret;
Corentin Chary20db88e2011-12-15 08:27:39 +0100921 }
Corentin Chary84d482f2011-11-26 11:00:09 +0100922
923 /* 0x02 seems to mean that the device is no present/available */
924
925 if (data.data[WL_STATUS_WLAN] != 0x02)
926 ret = samsung_new_rfkill(samsung, &samsung->wlan,
927 "samsung-wlan",
928 RFKILL_TYPE_WLAN,
929 &swsmi_rfkill_ops,
930 !data.data[WL_STATUS_WLAN]);
931 if (ret)
932 goto exit;
933
934 if (data.data[WL_STATUS_BT] != 0x02)
935 ret = samsung_new_rfkill(samsung, &samsung->bluetooth,
936 "samsung-bluetooth",
937 RFKILL_TYPE_BLUETOOTH,
938 &swsmi_rfkill_ops,
939 !data.data[WL_STATUS_BT]);
940 if (ret)
941 goto exit;
942
943exit:
944 if (ret)
945 samsung_rfkill_exit(samsung);
946
947 return ret;
Corentin Chary5dea7a22011-11-26 10:59:59 +0100948}
949
950static int __init samsung_rfkill_init(struct samsung_laptop *samsung)
951{
Corentin Chary84d482f2011-11-26 11:00:09 +0100952 if (samsung->config->sabi_version == 2)
953 return samsung_rfkill_init_seclinux(samsung);
954 if (samsung->config->sabi_version == 3)
955 return samsung_rfkill_init_swsmi(samsung);
Corentin Chary5dea7a22011-11-26 10:59:59 +0100956 return 0;
957}
958
Corentin Charyf674ebf2011-11-26 11:00:08 +0100959static int kbd_backlight_enable(struct samsung_laptop *samsung)
960{
961 const struct sabi_commands *commands = &samsung->config->commands;
962 struct sabi_data data;
963 int retval;
964
965 if (commands->kbd_backlight == 0xFFFF)
966 return -ENODEV;
967
968 memset(&data, 0, sizeof(data));
969 data.d0 = 0xaabb;
970 retval = sabi_command(samsung, commands->kbd_backlight,
971 &data, &data);
972
973 if (retval)
974 return retval;
975
976 if (data.d0 != 0xccdd)
977 return -ENODEV;
978 return 0;
979}
980
981static int kbd_backlight_read(struct samsung_laptop *samsung)
982{
983 const struct sabi_commands *commands = &samsung->config->commands;
984 struct sabi_data data;
985 int retval;
986
987 memset(&data, 0, sizeof(data));
988 data.data[0] = 0x81;
989 retval = sabi_command(samsung, commands->kbd_backlight,
990 &data, &data);
991
992 if (retval)
993 return retval;
994
995 return data.data[0];
996}
997
998static int kbd_backlight_write(struct samsung_laptop *samsung, int brightness)
999{
1000 const struct sabi_commands *commands = &samsung->config->commands;
1001 struct sabi_data data;
1002
1003 memset(&data, 0, sizeof(data));
1004 data.d0 = 0x82 | ((brightness & 0xFF) << 8);
1005 return sabi_command(samsung, commands->kbd_backlight,
1006 &data, NULL);
1007}
1008
1009static void kbd_led_update(struct work_struct *work)
1010{
1011 struct samsung_laptop *samsung;
1012
1013 samsung = container_of(work, struct samsung_laptop, kbd_led_work);
1014 kbd_backlight_write(samsung, samsung->kbd_led_wk);
1015}
1016
1017static void kbd_led_set(struct led_classdev *led_cdev,
1018 enum led_brightness value)
1019{
1020 struct samsung_laptop *samsung;
1021
1022 samsung = container_of(led_cdev, struct samsung_laptop, kbd_led);
1023
1024 if (value > samsung->kbd_led.max_brightness)
1025 value = samsung->kbd_led.max_brightness;
1026 else if (value < 0)
1027 value = 0;
1028
1029 samsung->kbd_led_wk = value;
1030 queue_work(samsung->led_workqueue, &samsung->kbd_led_work);
1031}
1032
1033static enum led_brightness kbd_led_get(struct led_classdev *led_cdev)
1034{
1035 struct samsung_laptop *samsung;
1036
1037 samsung = container_of(led_cdev, struct samsung_laptop, kbd_led);
1038 return kbd_backlight_read(samsung);
1039}
1040
1041static void samsung_leds_exit(struct samsung_laptop *samsung)
1042{
1043 if (!IS_ERR_OR_NULL(samsung->kbd_led.dev))
1044 led_classdev_unregister(&samsung->kbd_led);
1045 if (samsung->led_workqueue)
1046 destroy_workqueue(samsung->led_workqueue);
1047}
1048
1049static int __init samsung_leds_init(struct samsung_laptop *samsung)
1050{
1051 int ret = 0;
1052
1053 samsung->led_workqueue = create_singlethread_workqueue("led_workqueue");
1054 if (!samsung->led_workqueue)
1055 return -ENOMEM;
1056
1057 if (kbd_backlight_enable(samsung) >= 0) {
1058 INIT_WORK(&samsung->kbd_led_work, kbd_led_update);
1059
1060 samsung->kbd_led.name = "samsung::kbd_backlight";
1061 samsung->kbd_led.brightness_set = kbd_led_set;
1062 samsung->kbd_led.brightness_get = kbd_led_get;
1063 samsung->kbd_led.max_brightness = 8;
Scott Thrasher0ca849e2014-05-06 08:06:42 -07001064 if (samsung->quirks->four_kbd_backlight_levels)
1065 samsung->kbd_led.max_brightness = 4;
Corentin Charyf674ebf2011-11-26 11:00:08 +01001066
1067 ret = led_classdev_register(&samsung->platform_device->dev,
1068 &samsung->kbd_led);
1069 }
1070
1071 if (ret)
1072 samsung_leds_exit(samsung);
1073
1074 return ret;
1075}
1076
Corentin Chary5dea7a22011-11-26 10:59:59 +01001077static void samsung_backlight_exit(struct samsung_laptop *samsung)
1078{
1079 if (samsung->backlight_device) {
1080 backlight_device_unregister(samsung->backlight_device);
1081 samsung->backlight_device = NULL;
1082 }
1083}
1084
1085static int __init samsung_backlight_init(struct samsung_laptop *samsung)
1086{
1087 struct backlight_device *bd;
1088 struct backlight_properties props;
1089
Corentin Charyf34cd9c2011-11-26 11:00:00 +01001090 if (!samsung->handle_backlight)
1091 return 0;
1092
Corentin Chary5dea7a22011-11-26 10:59:59 +01001093 memset(&props, 0, sizeof(struct backlight_properties));
1094 props.type = BACKLIGHT_PLATFORM;
1095 props.max_brightness = samsung->config->max_brightness -
1096 samsung->config->min_brightness;
1097
1098 bd = backlight_device_register("samsung",
1099 &samsung->platform_device->dev,
1100 samsung, &backlight_ops,
1101 &props);
1102 if (IS_ERR(bd))
1103 return PTR_ERR(bd);
1104
1105 samsung->backlight_device = bd;
1106 samsung->backlight_device->props.brightness = read_brightness(samsung);
1107 samsung->backlight_device->props.power = FB_BLANK_UNBLANK;
1108 backlight_update_status(samsung->backlight_device);
1109
1110 return 0;
1111}
1112
Dan Carpenterbde9e502012-03-20 09:53:07 +01001113static umode_t samsung_sysfs_is_visible(struct kobject *kobj,
Corentin Charya66c1662011-11-26 11:00:01 +01001114 struct attribute *attr, int idx)
1115{
1116 struct device *dev = container_of(kobj, struct device, kobj);
1117 struct platform_device *pdev = to_platform_device(dev);
1118 struct samsung_laptop *samsung = platform_get_drvdata(pdev);
1119 bool ok = true;
1120
1121 if (attr == &dev_attr_performance_level.attr)
1122 ok = !!samsung->config->performance_levels[0].name;
Corentin Charycb5b5c92011-11-26 11:00:05 +01001123 if (attr == &dev_attr_battery_life_extender.attr)
1124 ok = !!(read_battery_life_extender(samsung) >= 0);
Corentin Chary3a75d372011-11-26 11:00:06 +01001125 if (attr == &dev_attr_usb_charge.attr)
1126 ok = !!(read_usb_charge(samsung) >= 0);
Corentin Charya66c1662011-11-26 11:00:01 +01001127
1128 return ok ? attr->mode : 0;
1129}
1130
1131static struct attribute_group platform_attribute_group = {
1132 .is_visible = samsung_sysfs_is_visible,
1133 .attrs = platform_attributes
1134};
1135
Corentin Chary5dea7a22011-11-26 10:59:59 +01001136static void samsung_sysfs_exit(struct samsung_laptop *samsung)
1137{
Corentin Charya66c1662011-11-26 11:00:01 +01001138 struct platform_device *device = samsung->platform_device;
1139
1140 sysfs_remove_group(&device->dev.kobj, &platform_attribute_group);
Corentin Chary5dea7a22011-11-26 10:59:59 +01001141}
1142
1143static int __init samsung_sysfs_init(struct samsung_laptop *samsung)
1144{
Corentin Charya66c1662011-11-26 11:00:01 +01001145 struct platform_device *device = samsung->platform_device;
1146
1147 return sysfs_create_group(&device->dev.kobj, &platform_attribute_group);
1148
Corentin Chary5dea7a22011-11-26 10:59:59 +01001149}
1150
Corentin Chary5b80fc42011-11-26 11:00:03 +01001151static int show_call(struct seq_file *m, void *data)
1152{
1153 struct samsung_laptop *samsung = m->private;
1154 struct sabi_data *sdata = &samsung->debug.data;
1155 int ret;
1156
1157 seq_printf(m, "SABI 0x%04x {0x%08x, 0x%08x, 0x%04x, 0x%02x}\n",
1158 samsung->debug.command,
1159 sdata->d0, sdata->d1, sdata->d2, sdata->d3);
1160
1161 ret = sabi_command(samsung, samsung->debug.command, sdata, sdata);
1162
1163 if (ret) {
1164 seq_printf(m, "SABI command 0x%04x failed\n",
1165 samsung->debug.command);
1166 return ret;
1167 }
1168
1169 seq_printf(m, "SABI {0x%08x, 0x%08x, 0x%04x, 0x%02x}\n",
1170 sdata->d0, sdata->d1, sdata->d2, sdata->d3);
1171 return 0;
1172}
1173
1174static int samsung_debugfs_open(struct inode *inode, struct file *file)
1175{
1176 return single_open(file, show_call, inode->i_private);
1177}
1178
1179static const struct file_operations samsung_laptop_call_io_ops = {
1180 .owner = THIS_MODULE,
1181 .open = samsung_debugfs_open,
1182 .read = seq_read,
1183 .llseek = seq_lseek,
1184 .release = single_release,
1185};
1186
1187static void samsung_debugfs_exit(struct samsung_laptop *samsung)
1188{
1189 debugfs_remove_recursive(samsung->debug.root);
1190}
1191
1192static int samsung_debugfs_init(struct samsung_laptop *samsung)
1193{
1194 struct dentry *dent;
1195
1196 samsung->debug.root = debugfs_create_dir("samsung-laptop", NULL);
1197 if (!samsung->debug.root) {
1198 pr_err("failed to create debugfs directory");
1199 goto error_debugfs;
1200 }
1201
1202 samsung->debug.f0000_wrapper.data = samsung->f0000_segment;
1203 samsung->debug.f0000_wrapper.size = 0xffff;
1204
1205 samsung->debug.data_wrapper.data = &samsung->debug.data;
1206 samsung->debug.data_wrapper.size = sizeof(samsung->debug.data);
1207
Corentin Chary6f6ae062011-11-26 11:00:11 +01001208 samsung->debug.sdiag_wrapper.data = samsung->sdiag;
1209 samsung->debug.sdiag_wrapper.size = strlen(samsung->sdiag);
1210
Corentin Chary5b80fc42011-11-26 11:00:03 +01001211 dent = debugfs_create_u16("command", S_IRUGO | S_IWUSR,
1212 samsung->debug.root, &samsung->debug.command);
1213 if (!dent)
1214 goto error_debugfs;
1215
1216 dent = debugfs_create_u32("d0", S_IRUGO | S_IWUSR, samsung->debug.root,
1217 &samsung->debug.data.d0);
1218 if (!dent)
1219 goto error_debugfs;
1220
1221 dent = debugfs_create_u32("d1", S_IRUGO | S_IWUSR, samsung->debug.root,
1222 &samsung->debug.data.d1);
1223 if (!dent)
1224 goto error_debugfs;
1225
1226 dent = debugfs_create_u16("d2", S_IRUGO | S_IWUSR, samsung->debug.root,
1227 &samsung->debug.data.d2);
1228 if (!dent)
1229 goto error_debugfs;
1230
1231 dent = debugfs_create_u8("d3", S_IRUGO | S_IWUSR, samsung->debug.root,
1232 &samsung->debug.data.d3);
1233 if (!dent)
1234 goto error_debugfs;
1235
1236 dent = debugfs_create_blob("data", S_IRUGO | S_IWUSR,
1237 samsung->debug.root,
1238 &samsung->debug.data_wrapper);
1239 if (!dent)
1240 goto error_debugfs;
1241
1242 dent = debugfs_create_blob("f0000_segment", S_IRUSR | S_IWUSR,
1243 samsung->debug.root,
1244 &samsung->debug.f0000_wrapper);
1245 if (!dent)
1246 goto error_debugfs;
1247
1248 dent = debugfs_create_file("call", S_IFREG | S_IRUGO,
1249 samsung->debug.root, samsung,
1250 &samsung_laptop_call_io_ops);
1251 if (!dent)
1252 goto error_debugfs;
1253
Corentin Chary6f6ae062011-11-26 11:00:11 +01001254 dent = debugfs_create_blob("sdiag", S_IRUGO | S_IWUSR,
1255 samsung->debug.root,
1256 &samsung->debug.sdiag_wrapper);
1257 if (!dent)
1258 goto error_debugfs;
1259
Corentin Chary5b80fc42011-11-26 11:00:03 +01001260 return 0;
1261
1262error_debugfs:
1263 samsung_debugfs_exit(samsung);
1264 return -ENOMEM;
1265}
1266
Corentin Chary5dea7a22011-11-26 10:59:59 +01001267static void samsung_sabi_exit(struct samsung_laptop *samsung)
1268{
1269 const struct sabi_config *config = samsung->config;
1270
1271 /* Turn off "Linux" mode in the BIOS */
1272 if (config && config->commands.set_linux != 0xff)
Corentin Chary7e960712011-11-26 11:00:02 +01001273 sabi_set_commandb(samsung, config->commands.set_linux, 0x80);
Corentin Chary5dea7a22011-11-26 10:59:59 +01001274
1275 if (samsung->sabi_iface) {
1276 iounmap(samsung->sabi_iface);
1277 samsung->sabi_iface = NULL;
1278 }
1279 if (samsung->f0000_segment) {
1280 iounmap(samsung->f0000_segment);
1281 samsung->f0000_segment = NULL;
1282 }
1283
1284 samsung->config = NULL;
1285}
1286
Corentin Chary49dd7732011-11-26 11:00:04 +01001287static __init void samsung_sabi_infos(struct samsung_laptop *samsung, int loca,
1288 unsigned int ifaceP)
Corentin Chary5dea7a22011-11-26 10:59:59 +01001289{
1290 const struct sabi_config *config = samsung->config;
1291
1292 printk(KERN_DEBUG "This computer supports SABI==%x\n",
1293 loca + 0xf0000 - 6);
Corentin Chary49dd7732011-11-26 11:00:04 +01001294
Corentin Chary5dea7a22011-11-26 10:59:59 +01001295 printk(KERN_DEBUG "SABI header:\n");
1296 printk(KERN_DEBUG " SMI Port Number = 0x%04x\n",
1297 readw(samsung->sabi + config->header_offsets.port));
1298 printk(KERN_DEBUG " SMI Interface Function = 0x%02x\n",
1299 readb(samsung->sabi + config->header_offsets.iface_func));
1300 printk(KERN_DEBUG " SMI enable memory buffer = 0x%02x\n",
1301 readb(samsung->sabi + config->header_offsets.en_mem));
1302 printk(KERN_DEBUG " SMI restore memory buffer = 0x%02x\n",
1303 readb(samsung->sabi + config->header_offsets.re_mem));
1304 printk(KERN_DEBUG " SABI data offset = 0x%04x\n",
1305 readw(samsung->sabi + config->header_offsets.data_offset));
1306 printk(KERN_DEBUG " SABI data segment = 0x%04x\n",
1307 readw(samsung->sabi + config->header_offsets.data_segment));
Corentin Chary5dea7a22011-11-26 10:59:59 +01001308
Corentin Chary49dd7732011-11-26 11:00:04 +01001309 printk(KERN_DEBUG " SABI pointer = 0x%08x\n", ifaceP);
Corentin Chary5dea7a22011-11-26 10:59:59 +01001310}
1311
Corentin Chary6f6ae062011-11-26 11:00:11 +01001312static void __init samsung_sabi_diag(struct samsung_laptop *samsung)
1313{
1314 int loca = find_signature(samsung->f0000_segment, "SDiaG@");
1315 int i;
1316
1317 if (loca == 0xffff)
1318 return ;
1319
1320 /* Example:
1321 * Ident: @SDiaG@686XX-N90X3A/966-SEC-07HL-S90X3A
1322 *
1323 * Product name: 90X3A
1324 * BIOS Version: 07HL
1325 */
1326 loca += 1;
1327 for (i = 0; loca < 0xffff && i < sizeof(samsung->sdiag) - 1; loca++) {
1328 char temp = readb(samsung->f0000_segment + loca);
1329
1330 if (isalnum(temp) || temp == '/' || temp == '-')
1331 samsung->sdiag[i++] = temp;
1332 else
1333 break ;
1334 }
1335
1336 if (debug && samsung->sdiag[0])
1337 pr_info("sdiag: %s", samsung->sdiag);
1338}
1339
Corentin Chary5dea7a22011-11-26 10:59:59 +01001340static int __init samsung_sabi_init(struct samsung_laptop *samsung)
1341{
1342 const struct sabi_config *config = NULL;
1343 const struct sabi_commands *commands;
1344 unsigned int ifaceP;
1345 int ret = 0;
1346 int i;
1347 int loca;
1348
1349 samsung->f0000_segment = ioremap_nocache(0xf0000, 0xffff);
1350 if (!samsung->f0000_segment) {
Corentin Chary3be324a2011-11-26 11:00:10 +01001351 if (debug || force)
1352 pr_err("Can't map the segment at 0xf0000\n");
Corentin Chary5dea7a22011-11-26 10:59:59 +01001353 ret = -EINVAL;
1354 goto exit;
1355 }
1356
Corentin Chary6f6ae062011-11-26 11:00:11 +01001357 samsung_sabi_diag(samsung);
1358
Corentin Chary5dea7a22011-11-26 10:59:59 +01001359 /* Try to find one of the signatures in memory to find the header */
1360 for (i = 0; sabi_configs[i].test_string != 0; ++i) {
1361 samsung->config = &sabi_configs[i];
1362 loca = find_signature(samsung->f0000_segment,
1363 samsung->config->test_string);
1364 if (loca != 0xffff)
1365 break;
1366 }
1367
1368 if (loca == 0xffff) {
Corentin Chary3be324a2011-11-26 11:00:10 +01001369 if (debug || force)
1370 pr_err("This computer does not support SABI\n");
Corentin Chary5dea7a22011-11-26 10:59:59 +01001371 ret = -ENODEV;
1372 goto exit;
1373 }
1374
1375 config = samsung->config;
1376 commands = &config->commands;
1377
1378 /* point to the SMI port Number */
1379 loca += 1;
1380 samsung->sabi = (samsung->f0000_segment + loca);
1381
Corentin Chary5dea7a22011-11-26 10:59:59 +01001382 /* Get a pointer to the SABI Interface */
1383 ifaceP = (readw(samsung->sabi + config->header_offsets.data_segment) & 0x0ffff) << 4;
1384 ifaceP += readw(samsung->sabi + config->header_offsets.data_offset) & 0x0ffff;
Corentin Chary49dd7732011-11-26 11:00:04 +01001385
1386 if (debug)
1387 samsung_sabi_infos(samsung, loca, ifaceP);
1388
Corentin Chary5dea7a22011-11-26 10:59:59 +01001389 samsung->sabi_iface = ioremap_nocache(ifaceP, 16);
1390 if (!samsung->sabi_iface) {
1391 pr_err("Can't remap %x\n", ifaceP);
1392 ret = -EINVAL;
1393 goto exit;
1394 }
1395
Corentin Chary5dea7a22011-11-26 10:59:59 +01001396 /* Turn on "Linux" mode in the BIOS */
1397 if (commands->set_linux != 0xff) {
Corentin Chary7e960712011-11-26 11:00:02 +01001398 int retval = sabi_set_commandb(samsung,
1399 commands->set_linux, 0x81);
Corentin Chary5dea7a22011-11-26 10:59:59 +01001400 if (retval) {
1401 pr_warn("Linux mode was not set!\n");
1402 ret = -ENODEV;
1403 goto exit;
1404 }
1405 }
1406
1407 /* Check for stepping quirk */
Corentin Charyf34cd9c2011-11-26 11:00:00 +01001408 if (samsung->handle_backlight)
1409 check_for_stepping_quirk(samsung);
Corentin Chary5dea7a22011-11-26 10:59:59 +01001410
Corentin Chary2e777182011-11-26 11:00:12 +01001411 pr_info("detected SABI interface: %s\n",
1412 samsung->config->test_string);
1413
Corentin Chary5dea7a22011-11-26 10:59:59 +01001414exit:
1415 if (ret)
1416 samsung_sabi_exit(samsung);
1417
1418 return ret;
1419}
1420
1421static void samsung_platform_exit(struct samsung_laptop *samsung)
1422{
1423 if (samsung->platform_device) {
1424 platform_device_unregister(samsung->platform_device);
1425 samsung->platform_device = NULL;
1426 }
1427}
1428
Scott Thrasher0ca849e2014-05-06 08:06:42 -07001429static int samsung_pm_notification(struct notifier_block *nb,
1430 unsigned long val, void *ptr)
1431{
1432 struct samsung_laptop *samsung;
1433
1434 samsung = container_of(nb, struct samsung_laptop, pm_nb);
1435 if (val == PM_POST_HIBERNATION &&
1436 samsung->quirks->enable_kbd_backlight)
1437 kbd_backlight_enable(samsung);
1438
1439 return 0;
1440}
1441
Corentin Chary5dea7a22011-11-26 10:59:59 +01001442static int __init samsung_platform_init(struct samsung_laptop *samsung)
1443{
1444 struct platform_device *pdev;
1445
1446 pdev = platform_device_register_simple("samsung", -1, NULL, 0);
1447 if (IS_ERR(pdev))
1448 return PTR_ERR(pdev);
1449
1450 samsung->platform_device = pdev;
1451 platform_set_drvdata(samsung->platform_device, samsung);
1452 return 0;
1453}
1454
Corentin Charya979e2e2012-03-22 14:08:19 +01001455static struct samsung_quirks *quirks;
1456
1457static int __init samsung_dmi_matched(const struct dmi_system_id *d)
1458{
1459 quirks = d->driver_data;
1460 return 0;
1461}
1462
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001463static struct dmi_system_id __initdata samsung_dmi_table[] = {
1464 {
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001465 .matches = {
1466 DMI_MATCH(DMI_SYS_VENDOR,
1467 "SAMSUNG ELECTRONICS CO., LTD."),
Corentin Chary3be324a2011-11-26 11:00:10 +01001468 DMI_MATCH(DMI_CHASSIS_TYPE, "8"), /* Portable */
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001469 },
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001470 },
1471 {
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001472 .matches = {
1473 DMI_MATCH(DMI_SYS_VENDOR,
1474 "SAMSUNG ELECTRONICS CO., LTD."),
Corentin Chary3be324a2011-11-26 11:00:10 +01001475 DMI_MATCH(DMI_CHASSIS_TYPE, "9"), /* Laptop */
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001476 },
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001477 },
1478 {
J Witteveen4e2441c2011-07-03 13:15:44 +02001479 .matches = {
1480 DMI_MATCH(DMI_SYS_VENDOR,
1481 "SAMSUNG ELECTRONICS CO., LTD."),
Corentin Chary3be324a2011-11-26 11:00:10 +01001482 DMI_MATCH(DMI_CHASSIS_TYPE, "10"), /* Notebook */
J Witteveen4e2441c2011-07-03 13:15:44 +02001483 },
J Witteveen4e2441c2011-07-03 13:15:44 +02001484 },
1485 {
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001486 .matches = {
1487 DMI_MATCH(DMI_SYS_VENDOR,
1488 "SAMSUNG ELECTRONICS CO., LTD."),
Corentin Chary3be324a2011-11-26 11:00:10 +01001489 DMI_MATCH(DMI_CHASSIS_TYPE, "14"), /* Sub-Notebook */
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001490 },
Tommaso Massimi7500eeb2011-09-20 09:16:09 -07001491 },
Corentin Charye0520672012-06-13 09:32:05 +02001492 /* DMI ids for laptops with bad Chassis Type */
1493 {
1494 .ident = "R40/R41",
1495 .matches = {
1496 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1497 DMI_MATCH(DMI_PRODUCT_NAME, "R40/R41"),
1498 DMI_MATCH(DMI_BOARD_NAME, "R40/R41"),
1499 },
1500 },
Corentin Charya979e2e2012-03-22 14:08:19 +01001501 /* Specific DMI ids for laptop with quirks */
1502 {
1503 .callback = samsung_dmi_matched,
1504 .ident = "N150P",
1505 .matches = {
1506 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1507 DMI_MATCH(DMI_PRODUCT_NAME, "N150P"),
1508 DMI_MATCH(DMI_BOARD_NAME, "N150P"),
1509 },
1510 .driver_data = &samsung_broken_acpi_video,
1511 },
1512 {
1513 .callback = samsung_dmi_matched,
1514 .ident = "N145P/N250P/N260P",
1515 .matches = {
1516 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1517 DMI_MATCH(DMI_PRODUCT_NAME, "N145P/N250P/N260P"),
1518 DMI_MATCH(DMI_BOARD_NAME, "N145P/N250P/N260P"),
1519 },
1520 .driver_data = &samsung_broken_acpi_video,
1521 },
1522 {
1523 .callback = samsung_dmi_matched,
1524 .ident = "N150/N210/N220",
1525 .matches = {
1526 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1527 DMI_MATCH(DMI_PRODUCT_NAME, "N150/N210/N220"),
1528 DMI_MATCH(DMI_BOARD_NAME, "N150/N210/N220"),
1529 },
1530 .driver_data = &samsung_broken_acpi_video,
1531 },
1532 {
1533 .callback = samsung_dmi_matched,
1534 .ident = "NF110/NF210/NF310",
1535 .matches = {
1536 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1537 DMI_MATCH(DMI_PRODUCT_NAME, "NF110/NF210/NF310"),
1538 DMI_MATCH(DMI_BOARD_NAME, "NF110/NF210/NF310"),
1539 },
1540 .driver_data = &samsung_broken_acpi_video,
1541 },
Corentin Chary09d56772012-06-13 09:32:03 +02001542 {
1543 .callback = samsung_dmi_matched,
1544 .ident = "X360",
1545 .matches = {
1546 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1547 DMI_MATCH(DMI_PRODUCT_NAME, "X360"),
1548 DMI_MATCH(DMI_BOARD_NAME, "X360"),
1549 },
1550 .driver_data = &samsung_broken_acpi_video,
1551 },
Seth Forsheee04c2002012-12-05 16:08:33 -06001552 {
1553 .callback = samsung_dmi_matched,
1554 .ident = "N250P",
1555 .matches = {
1556 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1557 DMI_MATCH(DMI_PRODUCT_NAME, "N250P"),
1558 DMI_MATCH(DMI_BOARD_NAME, "N250P"),
1559 },
1560 .driver_data = &samsung_broken_acpi_video,
1561 },
Scott Thrasher0ca849e2014-05-06 08:06:42 -07001562 {
1563 .callback = samsung_dmi_matched,
1564 .ident = "730U3E/740U3E",
1565 .matches = {
1566 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1567 DMI_MATCH(DMI_PRODUCT_NAME, "730U3E/740U3E"),
1568 },
1569 .driver_data = &samsung_np740u3e,
1570 },
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001571 { },
1572};
1573MODULE_DEVICE_TABLE(dmi, samsung_dmi_table);
1574
Corentin Chary5dea7a22011-11-26 10:59:59 +01001575static struct platform_device *samsung_platform_device;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001576
1577static int __init samsung_init(void)
1578{
Corentin Chary5dea7a22011-11-26 10:59:59 +01001579 struct samsung_laptop *samsung;
1580 int ret;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001581
Matt Fleminge0094242013-01-03 09:02:37 +00001582 if (efi_enabled(EFI_BOOT))
1583 return -ENODEV;
1584
Corentin Charya979e2e2012-03-22 14:08:19 +01001585 quirks = &samsung_unknown;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001586 if (!force && !dmi_check_system(samsung_dmi_table))
1587 return -ENODEV;
1588
Corentin Charya6df4892011-11-26 10:59:58 +01001589 samsung = kzalloc(sizeof(*samsung), GFP_KERNEL);
1590 if (!samsung)
1591 return -ENOMEM;
1592
1593 mutex_init(&samsung->sabi_mutex);
Corentin Charyf34cd9c2011-11-26 11:00:00 +01001594 samsung->handle_backlight = true;
Corentin Charya979e2e2012-03-22 14:08:19 +01001595 samsung->quirks = quirks;
Corentin Charyf34cd9c2011-11-26 11:00:00 +01001596
Corentin Charya979e2e2012-03-22 14:08:19 +01001597
Corentin Charya60b2172012-06-13 09:32:02 +02001598#ifdef CONFIG_ACPI
1599 if (samsung->quirks->broken_acpi_video)
1600 acpi_video_dmi_promote_vendor();
1601
Corentin Charyf34cd9c2011-11-26 11:00:00 +01001602 /* Don't handle backlight here if the acpi video already handle it */
Corentin Charya979e2e2012-03-22 14:08:19 +01001603 if (acpi_video_backlight_support()) {
Corentin Charya60b2172012-06-13 09:32:02 +02001604 samsung->handle_backlight = false;
1605 } else if (samsung->quirks->broken_acpi_video) {
1606 pr_info("Disabling ACPI video driver\n");
Corentin Charya60b2172012-06-13 09:32:02 +02001607 acpi_video_unregister();
Corentin Charya979e2e2012-03-22 14:08:19 +01001608 }
Corentin Charyf34cd9c2011-11-26 11:00:00 +01001609#endif
Corentin Charya979e2e2012-03-22 14:08:19 +01001610
Corentin Chary5dea7a22011-11-26 10:59:59 +01001611 ret = samsung_platform_init(samsung);
1612 if (ret)
1613 goto error_platform;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001614
Corentin Chary5dea7a22011-11-26 10:59:59 +01001615 ret = samsung_sabi_init(samsung);
1616 if (ret)
1617 goto error_sabi;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001618
Corentin Chary3be324a2011-11-26 11:00:10 +01001619#ifdef CONFIG_ACPI
1620 /* Only log that if we are really on a sabi platform */
Corentin Charya60b2172012-06-13 09:32:02 +02001621 if (acpi_video_backlight_support())
Corentin Chary3be324a2011-11-26 11:00:10 +01001622 pr_info("Backlight controlled by ACPI video driver\n");
1623#endif
1624
Corentin Chary5dea7a22011-11-26 10:59:59 +01001625 ret = samsung_sysfs_init(samsung);
1626 if (ret)
1627 goto error_sysfs;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001628
Corentin Chary5dea7a22011-11-26 10:59:59 +01001629 ret = samsung_backlight_init(samsung);
1630 if (ret)
1631 goto error_backlight;
Corentin Charya6df4892011-11-26 10:59:58 +01001632
Corentin Chary5dea7a22011-11-26 10:59:59 +01001633 ret = samsung_rfkill_init(samsung);
1634 if (ret)
1635 goto error_rfkill;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001636
Corentin Charyf674ebf2011-11-26 11:00:08 +01001637 ret = samsung_leds_init(samsung);
1638 if (ret)
1639 goto error_leds;
1640
Corentin Chary5b80fc42011-11-26 11:00:03 +01001641 ret = samsung_debugfs_init(samsung);
1642 if (ret)
1643 goto error_debugfs;
1644
Scott Thrasher0ca849e2014-05-06 08:06:42 -07001645 samsung->pm_nb.notifier_call = samsung_pm_notification;
1646 register_pm_notifier(&samsung->pm_nb);
1647
Corentin Chary5dea7a22011-11-26 10:59:59 +01001648 samsung_platform_device = samsung->platform_device;
1649 return ret;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001650
Corentin Chary5b80fc42011-11-26 11:00:03 +01001651error_debugfs:
Corentin Charyf674ebf2011-11-26 11:00:08 +01001652 samsung_leds_exit(samsung);
1653error_leds:
Corentin Chary5b80fc42011-11-26 11:00:03 +01001654 samsung_rfkill_exit(samsung);
Corentin Chary5dea7a22011-11-26 10:59:59 +01001655error_rfkill:
1656 samsung_backlight_exit(samsung);
1657error_backlight:
1658 samsung_sysfs_exit(samsung);
1659error_sysfs:
1660 samsung_sabi_exit(samsung);
1661error_sabi:
1662 samsung_platform_exit(samsung);
1663error_platform:
Corentin Charya6df4892011-11-26 10:59:58 +01001664 kfree(samsung);
Corentin Chary5dea7a22011-11-26 10:59:59 +01001665 return ret;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001666}
1667
1668static void __exit samsung_exit(void)
1669{
Corentin Chary5dea7a22011-11-26 10:59:59 +01001670 struct samsung_laptop *samsung;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001671
Corentin Chary5dea7a22011-11-26 10:59:59 +01001672 samsung = platform_get_drvdata(samsung_platform_device);
Scott Thrasher0ca849e2014-05-06 08:06:42 -07001673 unregister_pm_notifier(&samsung->pm_nb);
Corentin Charya6df4892011-11-26 10:59:58 +01001674
Corentin Chary5b80fc42011-11-26 11:00:03 +01001675 samsung_debugfs_exit(samsung);
Corentin Charyf674ebf2011-11-26 11:00:08 +01001676 samsung_leds_exit(samsung);
Corentin Chary5dea7a22011-11-26 10:59:59 +01001677 samsung_rfkill_exit(samsung);
1678 samsung_backlight_exit(samsung);
1679 samsung_sysfs_exit(samsung);
1680 samsung_sabi_exit(samsung);
1681 samsung_platform_exit(samsung);
1682
Corentin Charya6df4892011-11-26 10:59:58 +01001683 kfree(samsung);
Corentin Chary5dea7a22011-11-26 10:59:59 +01001684 samsung_platform_device = NULL;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001685}
1686
1687module_init(samsung_init);
1688module_exit(samsung_exit);
1689
1690MODULE_AUTHOR("Greg Kroah-Hartman <gregkh@suse.de>");
1691MODULE_DESCRIPTION("Samsung Backlight driver");
1692MODULE_LICENSE("GPL");