blob: b8d2145981e06b43eb24c2ebde264046ed139a19 [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>
20#include <linux/fb.h>
21#include <linux/dmi.h>
22#include <linux/platform_device.h>
23#include <linux/rfkill.h>
Corentin Charyf34cd9c2011-11-26 11:00:00 +010024#include <linux/acpi.h>
Corentin Chary5b80fc42011-11-26 11:00:03 +010025#include <linux/seq_file.h>
26#include <linux/debugfs.h>
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -050027
28/*
29 * This driver is needed because a number of Samsung laptops do not hook
30 * their control settings through ACPI. So we have to poke around in the
31 * BIOS to do things like brightness values, and "special" key controls.
32 */
33
34/*
35 * We have 0 - 8 as valid brightness levels. The specs say that level 0 should
36 * be reserved by the BIOS (which really doesn't make much sense), we tell
37 * userspace that the value is 0 - 7 and then just tell the hardware 1 - 8
38 */
39#define MAX_BRIGHT 0x07
40
41
42#define SABI_IFACE_MAIN 0x00
43#define SABI_IFACE_SUB 0x02
44#define SABI_IFACE_COMPLETE 0x04
45#define SABI_IFACE_DATA 0x05
46
Corentin Chary7e960712011-11-26 11:00:02 +010047/* Structure get/set data using sabi */
48struct sabi_data {
49 union {
50 struct {
51 u32 d0;
52 u32 d1;
53 u16 d2;
54 u8 d3;
55 };
56 u8 data[11];
57 };
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -050058};
59
60struct sabi_header_offsets {
61 u8 port;
62 u8 re_mem;
63 u8 iface_func;
64 u8 en_mem;
65 u8 data_offset;
66 u8 data_segment;
67};
68
69struct sabi_commands {
70 /*
71 * Brightness is 0 - 8, as described above.
72 * Value 0 is for the BIOS to use
73 */
Corentin Chary7e960712011-11-26 11:00:02 +010074 u16 get_brightness;
75 u16 set_brightness;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -050076
77 /*
78 * first byte:
79 * 0x00 - wireless is off
80 * 0x01 - wireless is on
81 * second byte:
82 * 0x02 - 3G is off
83 * 0x03 - 3G is on
84 * TODO, verify 3G is correct, that doesn't seem right...
85 */
Corentin Chary7e960712011-11-26 11:00:02 +010086 u16 get_wireless_button;
87 u16 set_wireless_button;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -050088
89 /* 0 is off, 1 is on */
Corentin Chary7e960712011-11-26 11:00:02 +010090 u16 get_backlight;
91 u16 set_backlight;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -050092
93 /*
94 * 0x80 or 0x00 - no action
95 * 0x81 - recovery key pressed
96 */
Corentin Chary7e960712011-11-26 11:00:02 +010097 u16 get_recovery_mode;
98 u16 set_recovery_mode;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -050099
100 /*
101 * on seclinux: 0 is low, 1 is high,
102 * on swsmi: 0 is normal, 1 is silent, 2 is turbo
103 */
Corentin Chary7e960712011-11-26 11:00:02 +0100104 u16 get_performance_level;
105 u16 set_performance_level;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500106
Corentin Charycb5b5c92011-11-26 11:00:05 +0100107 /* 0x80 is off, 0x81 is on */
108 u16 get_battery_life_extender;
109 u16 set_battery_life_extender;
110
Corentin Chary3a75d372011-11-26 11:00:06 +0100111 /* 0x80 is off, 0x81 is on */
112 u16 get_usb_charge;
113 u16 set_usb_charge;
114
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500115 /*
116 * Tell the BIOS that Linux is running on this machine.
117 * 81 is on, 80 is off
118 */
Corentin Chary7e960712011-11-26 11:00:02 +0100119 u16 set_linux;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500120};
121
122struct sabi_performance_level {
123 const char *name;
Corentin Chary7e960712011-11-26 11:00:02 +0100124 u16 value;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500125};
126
127struct sabi_config {
128 const char *test_string;
129 u16 main_function;
130 const struct sabi_header_offsets header_offsets;
131 const struct sabi_commands commands;
132 const struct sabi_performance_level performance_levels[4];
133 u8 min_brightness;
134 u8 max_brightness;
135};
136
137static const struct sabi_config sabi_configs[] = {
138 {
139 .test_string = "SECLINUX",
140
141 .main_function = 0x4c49,
142
143 .header_offsets = {
144 .port = 0x00,
145 .re_mem = 0x02,
146 .iface_func = 0x03,
147 .en_mem = 0x04,
148 .data_offset = 0x05,
149 .data_segment = 0x07,
150 },
151
152 .commands = {
153 .get_brightness = 0x00,
154 .set_brightness = 0x01,
155
156 .get_wireless_button = 0x02,
157 .set_wireless_button = 0x03,
158
159 .get_backlight = 0x04,
160 .set_backlight = 0x05,
161
162 .get_recovery_mode = 0x06,
163 .set_recovery_mode = 0x07,
164
165 .get_performance_level = 0x08,
166 .set_performance_level = 0x09,
167
Corentin Charycb5b5c92011-11-26 11:00:05 +0100168 .get_battery_life_extender = 0xFFFF,
169 .set_battery_life_extender = 0xFFFF,
170
Corentin Chary3a75d372011-11-26 11:00:06 +0100171 .get_usb_charge = 0xFFFF,
172 .set_usb_charge = 0xFFFF,
173
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500174 .set_linux = 0x0a,
175 },
176
177 .performance_levels = {
178 {
179 .name = "silent",
180 .value = 0,
181 },
182 {
183 .name = "normal",
184 .value = 1,
185 },
186 { },
187 },
188 .min_brightness = 1,
189 .max_brightness = 8,
190 },
191 {
192 .test_string = "SwSmi@",
193
194 .main_function = 0x5843,
195
196 .header_offsets = {
197 .port = 0x00,
198 .re_mem = 0x04,
199 .iface_func = 0x02,
200 .en_mem = 0x03,
201 .data_offset = 0x05,
202 .data_segment = 0x07,
203 },
204
205 .commands = {
206 .get_brightness = 0x10,
207 .set_brightness = 0x11,
208
209 .get_wireless_button = 0x12,
210 .set_wireless_button = 0x13,
211
212 .get_backlight = 0x2d,
213 .set_backlight = 0x2e,
214
215 .get_recovery_mode = 0xff,
216 .set_recovery_mode = 0xff,
217
218 .get_performance_level = 0x31,
219 .set_performance_level = 0x32,
220
Corentin Charycb5b5c92011-11-26 11:00:05 +0100221 .get_battery_life_extender = 0x65,
222 .set_battery_life_extender = 0x66,
223
Corentin Chary3a75d372011-11-26 11:00:06 +0100224 .get_usb_charge = 0x67,
225 .set_usb_charge = 0x68,
226
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500227 .set_linux = 0xff,
228 },
229
230 .performance_levels = {
231 {
232 .name = "normal",
233 .value = 0,
234 },
235 {
236 .name = "silent",
237 .value = 1,
238 },
239 {
240 .name = "overclock",
241 .value = 2,
242 },
243 { },
244 },
245 .min_brightness = 0,
246 .max_brightness = 8,
247 },
248 { },
249};
250
Corentin Chary5b80fc42011-11-26 11:00:03 +0100251/*
252 * samsung-laptop/ - debugfs root directory
253 * f0000_segment - dump f0000 segment
254 * command - current command
255 * data - current data
256 * d0, d1, d2, d3 - data fields
257 * call - call SABI using command and data
258 *
259 * This allow to call arbitrary sabi commands wihout
260 * modifying the driver at all.
261 * For example, setting the keyboard backlight brightness to 5
262 *
263 * echo 0x78 > command
264 * echo 0x0582 > d0
265 * echo 0 > d1
266 * echo 0 > d2
267 * echo 0 > d3
268 * cat call
269 */
270
271struct samsung_laptop_debug {
272 struct dentry *root;
273 struct sabi_data data;
274 u16 command;
275
276 struct debugfs_blob_wrapper f0000_wrapper;
277 struct debugfs_blob_wrapper data_wrapper;
278};
279
Corentin Charya6df4892011-11-26 10:59:58 +0100280struct samsung_laptop {
281 const struct sabi_config *config;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500282
Corentin Charya6df4892011-11-26 10:59:58 +0100283 void __iomem *sabi;
284 void __iomem *sabi_iface;
285 void __iomem *f0000_segment;
286
287 struct mutex sabi_mutex;
288
Corentin Chary5dea7a22011-11-26 10:59:59 +0100289 struct platform_device *platform_device;
Corentin Charya6df4892011-11-26 10:59:58 +0100290 struct backlight_device *backlight_device;
291 struct rfkill *rfk;
292
Corentin Chary5b80fc42011-11-26 11:00:03 +0100293 struct samsung_laptop_debug debug;
294
Corentin Charyf34cd9c2011-11-26 11:00:00 +0100295 bool handle_backlight;
Corentin Charya6df4892011-11-26 10:59:58 +0100296 bool has_stepping_quirk;
297};
298
Corentin Chary5dea7a22011-11-26 10:59:59 +0100299
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500300
Rusty Russell90ab5ee2012-01-13 09:32:20 +1030301static bool force;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500302module_param(force, bool, 0);
303MODULE_PARM_DESC(force,
304 "Disable the DMI check and forces the driver to be loaded");
305
Rusty Russell90ab5ee2012-01-13 09:32:20 +1030306static bool debug;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500307module_param(debug, bool, S_IRUGO | S_IWUSR);
308MODULE_PARM_DESC(debug, "Debug enabled or not");
309
Corentin Chary7e960712011-11-26 11:00:02 +0100310static int sabi_command(struct samsung_laptop *samsung, u16 command,
311 struct sabi_data *in,
312 struct sabi_data *out)
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500313{
Corentin Charya6df4892011-11-26 10:59:58 +0100314 const struct sabi_config *config = samsung->config;
Corentin Chary7e960712011-11-26 11:00:02 +0100315 int ret = 0;
Corentin Charya6df4892011-11-26 10:59:58 +0100316 u16 port = readw(samsung->sabi + config->header_offsets.port);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500317 u8 complete, iface_data;
318
Corentin Charya6df4892011-11-26 10:59:58 +0100319 mutex_lock(&samsung->sabi_mutex);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500320
Corentin Chary7e960712011-11-26 11:00:02 +0100321 if (debug) {
322 if (in)
323 pr_info("SABI 0x%04x {0x%08x, 0x%08x, 0x%04x, 0x%02x}",
324 command, in->d0, in->d1, in->d2, in->d3);
325 else
326 pr_info("SABI 0x%04x", command);
327 }
328
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500329 /* enable memory to be able to write to it */
Corentin Charya6df4892011-11-26 10:59:58 +0100330 outb(readb(samsung->sabi + config->header_offsets.en_mem), port);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500331
332 /* write out the command */
Corentin Charya6df4892011-11-26 10:59:58 +0100333 writew(config->main_function, samsung->sabi_iface + SABI_IFACE_MAIN);
334 writew(command, samsung->sabi_iface + SABI_IFACE_SUB);
335 writeb(0, samsung->sabi_iface + SABI_IFACE_COMPLETE);
Corentin Chary7e960712011-11-26 11:00:02 +0100336 if (in) {
337 writel(in->d0, samsung->sabi_iface + SABI_IFACE_DATA);
338 writel(in->d1, samsung->sabi_iface + SABI_IFACE_DATA + 4);
339 writew(in->d2, samsung->sabi_iface + SABI_IFACE_DATA + 8);
340 writeb(in->d3, samsung->sabi_iface + SABI_IFACE_DATA + 10);
341 }
Corentin Charya6df4892011-11-26 10:59:58 +0100342 outb(readb(samsung->sabi + config->header_offsets.iface_func), port);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500343
344 /* write protect memory to make it safe */
Corentin Charya6df4892011-11-26 10:59:58 +0100345 outb(readb(samsung->sabi + config->header_offsets.re_mem), port);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500346
347 /* see if the command actually succeeded */
Corentin Charya6df4892011-11-26 10:59:58 +0100348 complete = readb(samsung->sabi_iface + SABI_IFACE_COMPLETE);
349 iface_data = readb(samsung->sabi_iface + SABI_IFACE_DATA);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500350 if (complete != 0xaa || iface_data == 0xff) {
Corentin Chary7e960712011-11-26 11:00:02 +0100351 pr_warn("SABI command 0x%04x failed with"
352 " completion flag 0x%02x and interface data 0x%02x",
353 command, complete, iface_data);
354 ret = -EINVAL;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500355 goto exit;
356 }
Corentin Chary7e960712011-11-26 11:00:02 +0100357
358 if (out) {
359 out->d0 = readl(samsung->sabi_iface + SABI_IFACE_DATA);
360 out->d1 = readl(samsung->sabi_iface + SABI_IFACE_DATA + 4);
361 out->d2 = readw(samsung->sabi_iface + SABI_IFACE_DATA + 2);
362 out->d3 = readb(samsung->sabi_iface + SABI_IFACE_DATA + 1);
363 }
364
365 if (debug && out) {
366 pr_info("SABI {0x%08x, 0x%08x, 0x%04x, 0x%02x}",
367 out->d0, out->d1, out->d2, out->d3);
368 }
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500369
370exit:
Corentin Charya6df4892011-11-26 10:59:58 +0100371 mutex_unlock(&samsung->sabi_mutex);
Corentin Chary7e960712011-11-26 11:00:02 +0100372 return ret;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500373}
374
Corentin Chary7e960712011-11-26 11:00:02 +0100375/* simple wrappers usable with most commands */
376static int sabi_set_commandb(struct samsung_laptop *samsung,
377 u16 command, u8 data)
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500378{
Corentin Chary7e960712011-11-26 11:00:02 +0100379 struct sabi_data in = { .d0 = 0, .d1 = 0, .d2 = 0, .d3 = 0 };
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500380
Corentin Chary7e960712011-11-26 11:00:02 +0100381 in.data[0] = data;
382 return sabi_command(samsung, command, &in, NULL);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500383}
384
Corentin Chary5dea7a22011-11-26 10:59:59 +0100385static int read_brightness(struct samsung_laptop *samsung)
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500386{
Corentin Charya6df4892011-11-26 10:59:58 +0100387 const struct sabi_config *config = samsung->config;
388 const struct sabi_commands *commands = &samsung->config->commands;
Corentin Chary7e960712011-11-26 11:00:02 +0100389 struct sabi_data sretval;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500390 int user_brightness = 0;
391 int retval;
392
Corentin Chary7e960712011-11-26 11:00:02 +0100393 retval = sabi_command(samsung, commands->get_brightness,
394 NULL, &sretval);
395 if (retval)
396 return retval;
397
398 user_brightness = sretval.data[0];
399 if (user_brightness > config->min_brightness)
400 user_brightness -= config->min_brightness;
401 else
402 user_brightness = 0;
403
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500404 return user_brightness;
405}
406
Corentin Chary5dea7a22011-11-26 10:59:59 +0100407static void set_brightness(struct samsung_laptop *samsung, u8 user_brightness)
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500408{
Corentin Charya6df4892011-11-26 10:59:58 +0100409 const struct sabi_config *config = samsung->config;
410 const struct sabi_commands *commands = &samsung->config->commands;
411 u8 user_level = user_brightness + config->min_brightness;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500412
Corentin Charya6df4892011-11-26 10:59:58 +0100413 if (samsung->has_stepping_quirk && user_level != 0) {
Jason Stubbsac080522011-09-20 09:16:13 -0700414 /*
415 * short circuit if the specified level is what's already set
416 * to prevent the screen from flickering needlessly
417 */
Corentin Chary5dea7a22011-11-26 10:59:59 +0100418 if (user_brightness == read_brightness(samsung))
Jason Stubbsac080522011-09-20 09:16:13 -0700419 return;
420
Corentin Chary7e960712011-11-26 11:00:02 +0100421 sabi_set_commandb(samsung, commands->set_brightness, 0);
Jason Stubbsac080522011-09-20 09:16:13 -0700422 }
423
Corentin Chary7e960712011-11-26 11:00:02 +0100424 sabi_set_commandb(samsung, commands->set_brightness, user_level);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500425}
426
427static int get_brightness(struct backlight_device *bd)
428{
Corentin Chary5dea7a22011-11-26 10:59:59 +0100429 struct samsung_laptop *samsung = bl_get_data(bd);
430
431 return read_brightness(samsung);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500432}
433
Corentin Chary5dea7a22011-11-26 10:59:59 +0100434static void check_for_stepping_quirk(struct samsung_laptop *samsung)
Jason Stubbsac080522011-09-20 09:16:13 -0700435{
Corentin Chary5dea7a22011-11-26 10:59:59 +0100436 int initial_level;
437 int check_level;
438 int orig_level = read_brightness(samsung);
Jason Stubbsac080522011-09-20 09:16:13 -0700439
440 /*
441 * Some laptops exhibit the strange behaviour of stepping toward
442 * (rather than setting) the brightness except when changing to/from
443 * brightness level 0. This behaviour is checked for here and worked
444 * around in set_brightness.
445 */
446
John Serockba05b232011-10-13 06:42:01 -0400447 if (orig_level == 0)
Corentin Chary5dea7a22011-11-26 10:59:59 +0100448 set_brightness(samsung, 1);
John Serockba05b232011-10-13 06:42:01 -0400449
Corentin Chary5dea7a22011-11-26 10:59:59 +0100450 initial_level = read_brightness(samsung);
John Serockba05b232011-10-13 06:42:01 -0400451
Jason Stubbsac080522011-09-20 09:16:13 -0700452 if (initial_level <= 2)
453 check_level = initial_level + 2;
454 else
455 check_level = initial_level - 2;
456
Corentin Charya6df4892011-11-26 10:59:58 +0100457 samsung->has_stepping_quirk = false;
Corentin Chary5dea7a22011-11-26 10:59:59 +0100458 set_brightness(samsung, check_level);
Jason Stubbsac080522011-09-20 09:16:13 -0700459
Corentin Chary5dea7a22011-11-26 10:59:59 +0100460 if (read_brightness(samsung) != check_level) {
Corentin Charya6df4892011-11-26 10:59:58 +0100461 samsung->has_stepping_quirk = true;
Jason Stubbsac080522011-09-20 09:16:13 -0700462 pr_info("enabled workaround for brightness stepping quirk\n");
463 }
464
Corentin Chary5dea7a22011-11-26 10:59:59 +0100465 set_brightness(samsung, orig_level);
Jason Stubbsac080522011-09-20 09:16:13 -0700466}
467
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500468static int update_status(struct backlight_device *bd)
469{
Corentin Chary5dea7a22011-11-26 10:59:59 +0100470 struct samsung_laptop *samsung = bl_get_data(bd);
Corentin Charya6df4892011-11-26 10:59:58 +0100471 const struct sabi_commands *commands = &samsung->config->commands;
472
Corentin Chary5dea7a22011-11-26 10:59:59 +0100473 set_brightness(samsung, bd->props.brightness);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500474
475 if (bd->props.power == FB_BLANK_UNBLANK)
Corentin Chary7e960712011-11-26 11:00:02 +0100476 sabi_set_commandb(samsung, commands->set_backlight, 1);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500477 else
Corentin Chary7e960712011-11-26 11:00:02 +0100478 sabi_set_commandb(samsung, commands->set_backlight, 0);
Corentin Chary5dea7a22011-11-26 10:59:59 +0100479
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500480 return 0;
481}
482
483static const struct backlight_ops backlight_ops = {
484 .get_brightness = get_brightness,
485 .update_status = update_status,
486};
487
488static int rfkill_set(void *data, bool blocked)
489{
Corentin Chary5dea7a22011-11-26 10:59:59 +0100490 struct samsung_laptop *samsung = data;
Corentin Charya6df4892011-11-26 10:59:58 +0100491 const struct sabi_commands *commands = &samsung->config->commands;
492
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500493 /* Do something with blocked...*/
494 /*
495 * blocked == false is on
496 * blocked == true is off
497 */
498 if (blocked)
Corentin Chary7e960712011-11-26 11:00:02 +0100499 sabi_set_commandb(samsung, commands->set_wireless_button, 0);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500500 else
Corentin Chary7e960712011-11-26 11:00:02 +0100501 sabi_set_commandb(samsung, commands->set_wireless_button, 1);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500502
503 return 0;
504}
505
506static struct rfkill_ops rfkill_ops = {
507 .set_block = rfkill_set,
508};
509
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500510static ssize_t get_performance_level(struct device *dev,
511 struct device_attribute *attr, char *buf)
512{
Corentin Chary5dea7a22011-11-26 10:59:59 +0100513 struct samsung_laptop *samsung = dev_get_drvdata(dev);
Corentin Charya6df4892011-11-26 10:59:58 +0100514 const struct sabi_config *config = samsung->config;
Corentin Chary5dea7a22011-11-26 10:59:59 +0100515 const struct sabi_commands *commands = &config->commands;
Corentin Chary7e960712011-11-26 11:00:02 +0100516 struct sabi_data sretval;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500517 int retval;
518 int i;
519
520 /* Read the state */
Corentin Chary7e960712011-11-26 11:00:02 +0100521 retval = sabi_command(samsung, commands->get_performance_level,
522 NULL, &sretval);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500523 if (retval)
524 return retval;
525
526 /* The logic is backwards, yeah, lots of fun... */
Corentin Charya6df4892011-11-26 10:59:58 +0100527 for (i = 0; config->performance_levels[i].name; ++i) {
Corentin Chary7e960712011-11-26 11:00:02 +0100528 if (sretval.data[0] == config->performance_levels[i].value)
Corentin Charya6df4892011-11-26 10:59:58 +0100529 return sprintf(buf, "%s\n", config->performance_levels[i].name);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500530 }
531 return sprintf(buf, "%s\n", "unknown");
532}
533
534static ssize_t set_performance_level(struct device *dev,
535 struct device_attribute *attr, const char *buf,
536 size_t count)
537{
Corentin Chary5dea7a22011-11-26 10:59:59 +0100538 struct samsung_laptop *samsung = dev_get_drvdata(dev);
Corentin Charya6df4892011-11-26 10:59:58 +0100539 const struct sabi_config *config = samsung->config;
Corentin Chary5dea7a22011-11-26 10:59:59 +0100540 const struct sabi_commands *commands = &config->commands;
541 int i;
Corentin Charya6df4892011-11-26 10:59:58 +0100542
Corentin Chary5dea7a22011-11-26 10:59:59 +0100543 if (count < 1)
544 return count;
545
546 for (i = 0; config->performance_levels[i].name; ++i) {
547 const struct sabi_performance_level *level =
548 &config->performance_levels[i];
549 if (!strncasecmp(level->name, buf, strlen(level->name))) {
Corentin Chary7e960712011-11-26 11:00:02 +0100550 sabi_set_commandb(samsung,
551 commands->set_performance_level,
552 level->value);
Corentin Chary5dea7a22011-11-26 10:59:59 +0100553 break;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500554 }
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500555 }
Corentin Chary5dea7a22011-11-26 10:59:59 +0100556
557 if (!config->performance_levels[i].name)
558 return -EINVAL;
559
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500560 return count;
561}
Corentin Chary5dea7a22011-11-26 10:59:59 +0100562
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500563static DEVICE_ATTR(performance_level, S_IWUSR | S_IRUGO,
564 get_performance_level, set_performance_level);
565
Corentin Charycb5b5c92011-11-26 11:00:05 +0100566static int read_battery_life_extender(struct samsung_laptop *samsung)
567{
568 const struct sabi_commands *commands = &samsung->config->commands;
569 struct sabi_data data;
570 int retval;
571
572 if (commands->get_battery_life_extender == 0xFFFF)
573 return -ENODEV;
574
575 memset(&data, 0, sizeof(data));
576 data.data[0] = 0x80;
577 retval = sabi_command(samsung, commands->get_battery_life_extender,
578 &data, &data);
579
580 if (retval)
581 return retval;
582
583 if (data.data[0] != 0 && data.data[0] != 1)
584 return -ENODEV;
585
586 return data.data[0];
587}
588
589static int write_battery_life_extender(struct samsung_laptop *samsung,
590 int enabled)
591{
592 const struct sabi_commands *commands = &samsung->config->commands;
593 struct sabi_data data;
594
595 memset(&data, 0, sizeof(data));
596 data.data[0] = 0x80 | enabled;
597 return sabi_command(samsung, commands->set_battery_life_extender,
598 &data, NULL);
599}
600
601static ssize_t get_battery_life_extender(struct device *dev,
602 struct device_attribute *attr,
603 char *buf)
604{
605 struct samsung_laptop *samsung = dev_get_drvdata(dev);
606 int ret;
607
608 ret = read_battery_life_extender(samsung);
609 if (ret < 0)
610 return ret;
611
612 return sprintf(buf, "%d\n", ret);
613}
614
615static ssize_t set_battery_life_extender(struct device *dev,
616 struct device_attribute *attr,
617 const char *buf, size_t count)
618{
619 struct samsung_laptop *samsung = dev_get_drvdata(dev);
620 int ret, value;
621
622 if (!count || sscanf(buf, "%i", &value) != 1)
623 return -EINVAL;
624
625 ret = write_battery_life_extender(samsung, !!value);
626 if (ret < 0)
627 return ret;
628
629 return count;
630}
631
632static DEVICE_ATTR(battery_life_extender, S_IWUSR | S_IRUGO,
633 get_battery_life_extender, set_battery_life_extender);
634
Corentin Chary3a75d372011-11-26 11:00:06 +0100635static int read_usb_charge(struct samsung_laptop *samsung)
636{
637 const struct sabi_commands *commands = &samsung->config->commands;
638 struct sabi_data data;
639 int retval;
640
641 if (commands->get_usb_charge == 0xFFFF)
642 return -ENODEV;
643
644 memset(&data, 0, sizeof(data));
645 data.data[0] = 0x80;
646 retval = sabi_command(samsung, commands->get_usb_charge,
647 &data, &data);
648
649 if (retval)
650 return retval;
651
652 if (data.data[0] != 0 && data.data[0] != 1)
653 return -ENODEV;
654
655 return data.data[0];
656}
657
658static int write_usb_charge(struct samsung_laptop *samsung,
659 int enabled)
660{
661 const struct sabi_commands *commands = &samsung->config->commands;
662 struct sabi_data data;
663
664 memset(&data, 0, sizeof(data));
665 data.data[0] = 0x80 | enabled;
666 return sabi_command(samsung, commands->set_usb_charge,
667 &data, NULL);
668}
669
670static ssize_t get_usb_charge(struct device *dev,
671 struct device_attribute *attr,
672 char *buf)
673{
674 struct samsung_laptop *samsung = dev_get_drvdata(dev);
675 int ret;
676
677 ret = read_usb_charge(samsung);
678 if (ret < 0)
679 return ret;
680
681 return sprintf(buf, "%d\n", ret);
682}
683
684static ssize_t set_usb_charge(struct device *dev,
685 struct device_attribute *attr,
686 const char *buf, size_t count)
687{
688 struct samsung_laptop *samsung = dev_get_drvdata(dev);
689 int ret, value;
690
691 if (!count || sscanf(buf, "%i", &value) != 1)
692 return -EINVAL;
693
694 ret = write_usb_charge(samsung, !!value);
695 if (ret < 0)
696 return ret;
697
698 return count;
699}
700
701static DEVICE_ATTR(usb_charge, S_IWUSR | S_IRUGO,
702 get_usb_charge, set_usb_charge);
703
Corentin Charya66c1662011-11-26 11:00:01 +0100704static struct attribute *platform_attributes[] = {
705 &dev_attr_performance_level.attr,
Corentin Charycb5b5c92011-11-26 11:00:05 +0100706 &dev_attr_battery_life_extender.attr,
Corentin Chary3a75d372011-11-26 11:00:06 +0100707 &dev_attr_usb_charge.attr,
Corentin Charya66c1662011-11-26 11:00:01 +0100708 NULL
709};
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500710
Corentin Chary5dea7a22011-11-26 10:59:59 +0100711static int find_signature(void __iomem *memcheck, const char *testStr)
712{
713 int i = 0;
714 int loca;
715
716 for (loca = 0; loca < 0xffff; loca++) {
717 char temp = readb(memcheck + loca);
718
719 if (temp == testStr[i]) {
720 if (i == strlen(testStr)-1)
721 break;
722 ++i;
723 } else {
724 i = 0;
725 }
726 }
727 return loca;
728}
729
730static void samsung_rfkill_exit(struct samsung_laptop *samsung)
731{
732 if (samsung->rfk) {
733 rfkill_unregister(samsung->rfk);
734 rfkill_destroy(samsung->rfk);
735 samsung->rfk = NULL;
736 }
737}
738
739static int __init samsung_rfkill_init(struct samsung_laptop *samsung)
740{
741 int retval;
742
743 samsung->rfk = rfkill_alloc("samsung-wifi",
744 &samsung->platform_device->dev,
745 RFKILL_TYPE_WLAN,
746 &rfkill_ops, samsung);
747 if (!samsung->rfk)
748 return -ENOMEM;
749
750 retval = rfkill_register(samsung->rfk);
751 if (retval) {
752 rfkill_destroy(samsung->rfk);
753 samsung->rfk = NULL;
754 return -ENODEV;
755 }
756
757 return 0;
758}
759
760static void samsung_backlight_exit(struct samsung_laptop *samsung)
761{
762 if (samsung->backlight_device) {
763 backlight_device_unregister(samsung->backlight_device);
764 samsung->backlight_device = NULL;
765 }
766}
767
768static int __init samsung_backlight_init(struct samsung_laptop *samsung)
769{
770 struct backlight_device *bd;
771 struct backlight_properties props;
772
Corentin Charyf34cd9c2011-11-26 11:00:00 +0100773 if (!samsung->handle_backlight)
774 return 0;
775
Corentin Chary5dea7a22011-11-26 10:59:59 +0100776 memset(&props, 0, sizeof(struct backlight_properties));
777 props.type = BACKLIGHT_PLATFORM;
778 props.max_brightness = samsung->config->max_brightness -
779 samsung->config->min_brightness;
780
781 bd = backlight_device_register("samsung",
782 &samsung->platform_device->dev,
783 samsung, &backlight_ops,
784 &props);
785 if (IS_ERR(bd))
786 return PTR_ERR(bd);
787
788 samsung->backlight_device = bd;
789 samsung->backlight_device->props.brightness = read_brightness(samsung);
790 samsung->backlight_device->props.power = FB_BLANK_UNBLANK;
791 backlight_update_status(samsung->backlight_device);
792
793 return 0;
794}
795
Corentin Charya66c1662011-11-26 11:00:01 +0100796static mode_t samsung_sysfs_is_visible(struct kobject *kobj,
797 struct attribute *attr, int idx)
798{
799 struct device *dev = container_of(kobj, struct device, kobj);
800 struct platform_device *pdev = to_platform_device(dev);
801 struct samsung_laptop *samsung = platform_get_drvdata(pdev);
802 bool ok = true;
803
804 if (attr == &dev_attr_performance_level.attr)
805 ok = !!samsung->config->performance_levels[0].name;
Corentin Charycb5b5c92011-11-26 11:00:05 +0100806 if (attr == &dev_attr_battery_life_extender.attr)
807 ok = !!(read_battery_life_extender(samsung) >= 0);
Corentin Chary3a75d372011-11-26 11:00:06 +0100808 if (attr == &dev_attr_usb_charge.attr)
809 ok = !!(read_usb_charge(samsung) >= 0);
Corentin Charya66c1662011-11-26 11:00:01 +0100810
811 return ok ? attr->mode : 0;
812}
813
814static struct attribute_group platform_attribute_group = {
815 .is_visible = samsung_sysfs_is_visible,
816 .attrs = platform_attributes
817};
818
Corentin Chary5dea7a22011-11-26 10:59:59 +0100819static void samsung_sysfs_exit(struct samsung_laptop *samsung)
820{
Corentin Charya66c1662011-11-26 11:00:01 +0100821 struct platform_device *device = samsung->platform_device;
822
823 sysfs_remove_group(&device->dev.kobj, &platform_attribute_group);
Corentin Chary5dea7a22011-11-26 10:59:59 +0100824}
825
826static int __init samsung_sysfs_init(struct samsung_laptop *samsung)
827{
Corentin Charya66c1662011-11-26 11:00:01 +0100828 struct platform_device *device = samsung->platform_device;
829
830 return sysfs_create_group(&device->dev.kobj, &platform_attribute_group);
831
Corentin Chary5dea7a22011-11-26 10:59:59 +0100832}
833
Corentin Chary5b80fc42011-11-26 11:00:03 +0100834static int show_call(struct seq_file *m, void *data)
835{
836 struct samsung_laptop *samsung = m->private;
837 struct sabi_data *sdata = &samsung->debug.data;
838 int ret;
839
840 seq_printf(m, "SABI 0x%04x {0x%08x, 0x%08x, 0x%04x, 0x%02x}\n",
841 samsung->debug.command,
842 sdata->d0, sdata->d1, sdata->d2, sdata->d3);
843
844 ret = sabi_command(samsung, samsung->debug.command, sdata, sdata);
845
846 if (ret) {
847 seq_printf(m, "SABI command 0x%04x failed\n",
848 samsung->debug.command);
849 return ret;
850 }
851
852 seq_printf(m, "SABI {0x%08x, 0x%08x, 0x%04x, 0x%02x}\n",
853 sdata->d0, sdata->d1, sdata->d2, sdata->d3);
854 return 0;
855}
856
857static int samsung_debugfs_open(struct inode *inode, struct file *file)
858{
859 return single_open(file, show_call, inode->i_private);
860}
861
862static const struct file_operations samsung_laptop_call_io_ops = {
863 .owner = THIS_MODULE,
864 .open = samsung_debugfs_open,
865 .read = seq_read,
866 .llseek = seq_lseek,
867 .release = single_release,
868};
869
870static void samsung_debugfs_exit(struct samsung_laptop *samsung)
871{
872 debugfs_remove_recursive(samsung->debug.root);
873}
874
875static int samsung_debugfs_init(struct samsung_laptop *samsung)
876{
877 struct dentry *dent;
878
879 samsung->debug.root = debugfs_create_dir("samsung-laptop", NULL);
880 if (!samsung->debug.root) {
881 pr_err("failed to create debugfs directory");
882 goto error_debugfs;
883 }
884
885 samsung->debug.f0000_wrapper.data = samsung->f0000_segment;
886 samsung->debug.f0000_wrapper.size = 0xffff;
887
888 samsung->debug.data_wrapper.data = &samsung->debug.data;
889 samsung->debug.data_wrapper.size = sizeof(samsung->debug.data);
890
891 dent = debugfs_create_u16("command", S_IRUGO | S_IWUSR,
892 samsung->debug.root, &samsung->debug.command);
893 if (!dent)
894 goto error_debugfs;
895
896 dent = debugfs_create_u32("d0", S_IRUGO | S_IWUSR, samsung->debug.root,
897 &samsung->debug.data.d0);
898 if (!dent)
899 goto error_debugfs;
900
901 dent = debugfs_create_u32("d1", S_IRUGO | S_IWUSR, samsung->debug.root,
902 &samsung->debug.data.d1);
903 if (!dent)
904 goto error_debugfs;
905
906 dent = debugfs_create_u16("d2", S_IRUGO | S_IWUSR, samsung->debug.root,
907 &samsung->debug.data.d2);
908 if (!dent)
909 goto error_debugfs;
910
911 dent = debugfs_create_u8("d3", S_IRUGO | S_IWUSR, samsung->debug.root,
912 &samsung->debug.data.d3);
913 if (!dent)
914 goto error_debugfs;
915
916 dent = debugfs_create_blob("data", S_IRUGO | S_IWUSR,
917 samsung->debug.root,
918 &samsung->debug.data_wrapper);
919 if (!dent)
920 goto error_debugfs;
921
922 dent = debugfs_create_blob("f0000_segment", S_IRUSR | S_IWUSR,
923 samsung->debug.root,
924 &samsung->debug.f0000_wrapper);
925 if (!dent)
926 goto error_debugfs;
927
928 dent = debugfs_create_file("call", S_IFREG | S_IRUGO,
929 samsung->debug.root, samsung,
930 &samsung_laptop_call_io_ops);
931 if (!dent)
932 goto error_debugfs;
933
934 return 0;
935
936error_debugfs:
937 samsung_debugfs_exit(samsung);
938 return -ENOMEM;
939}
940
Corentin Chary5dea7a22011-11-26 10:59:59 +0100941static void samsung_sabi_exit(struct samsung_laptop *samsung)
942{
943 const struct sabi_config *config = samsung->config;
944
945 /* Turn off "Linux" mode in the BIOS */
946 if (config && config->commands.set_linux != 0xff)
Corentin Chary7e960712011-11-26 11:00:02 +0100947 sabi_set_commandb(samsung, config->commands.set_linux, 0x80);
Corentin Chary5dea7a22011-11-26 10:59:59 +0100948
949 if (samsung->sabi_iface) {
950 iounmap(samsung->sabi_iface);
951 samsung->sabi_iface = NULL;
952 }
953 if (samsung->f0000_segment) {
954 iounmap(samsung->f0000_segment);
955 samsung->f0000_segment = NULL;
956 }
957
958 samsung->config = NULL;
959}
960
Corentin Chary49dd7732011-11-26 11:00:04 +0100961static __init void samsung_sabi_infos(struct samsung_laptop *samsung, int loca,
962 unsigned int ifaceP)
Corentin Chary5dea7a22011-11-26 10:59:59 +0100963{
964 const struct sabi_config *config = samsung->config;
965
966 printk(KERN_DEBUG "This computer supports SABI==%x\n",
967 loca + 0xf0000 - 6);
Corentin Chary49dd7732011-11-26 11:00:04 +0100968
Corentin Chary5dea7a22011-11-26 10:59:59 +0100969 printk(KERN_DEBUG "SABI header:\n");
970 printk(KERN_DEBUG " SMI Port Number = 0x%04x\n",
971 readw(samsung->sabi + config->header_offsets.port));
972 printk(KERN_DEBUG " SMI Interface Function = 0x%02x\n",
973 readb(samsung->sabi + config->header_offsets.iface_func));
974 printk(KERN_DEBUG " SMI enable memory buffer = 0x%02x\n",
975 readb(samsung->sabi + config->header_offsets.en_mem));
976 printk(KERN_DEBUG " SMI restore memory buffer = 0x%02x\n",
977 readb(samsung->sabi + config->header_offsets.re_mem));
978 printk(KERN_DEBUG " SABI data offset = 0x%04x\n",
979 readw(samsung->sabi + config->header_offsets.data_offset));
980 printk(KERN_DEBUG " SABI data segment = 0x%04x\n",
981 readw(samsung->sabi + config->header_offsets.data_segment));
Corentin Chary5dea7a22011-11-26 10:59:59 +0100982
Corentin Chary49dd7732011-11-26 11:00:04 +0100983 printk(KERN_DEBUG " SABI pointer = 0x%08x\n", ifaceP);
Corentin Chary5dea7a22011-11-26 10:59:59 +0100984}
985
986static int __init samsung_sabi_init(struct samsung_laptop *samsung)
987{
988 const struct sabi_config *config = NULL;
989 const struct sabi_commands *commands;
990 unsigned int ifaceP;
991 int ret = 0;
992 int i;
993 int loca;
994
995 samsung->f0000_segment = ioremap_nocache(0xf0000, 0xffff);
996 if (!samsung->f0000_segment) {
997 pr_err("Can't map the segment at 0xf0000\n");
998 ret = -EINVAL;
999 goto exit;
1000 }
1001
1002 /* Try to find one of the signatures in memory to find the header */
1003 for (i = 0; sabi_configs[i].test_string != 0; ++i) {
1004 samsung->config = &sabi_configs[i];
1005 loca = find_signature(samsung->f0000_segment,
1006 samsung->config->test_string);
1007 if (loca != 0xffff)
1008 break;
1009 }
1010
1011 if (loca == 0xffff) {
1012 pr_err("This computer does not support SABI\n");
1013 ret = -ENODEV;
1014 goto exit;
1015 }
1016
1017 config = samsung->config;
1018 commands = &config->commands;
1019
1020 /* point to the SMI port Number */
1021 loca += 1;
1022 samsung->sabi = (samsung->f0000_segment + loca);
1023
Corentin Chary5dea7a22011-11-26 10:59:59 +01001024 /* Get a pointer to the SABI Interface */
1025 ifaceP = (readw(samsung->sabi + config->header_offsets.data_segment) & 0x0ffff) << 4;
1026 ifaceP += readw(samsung->sabi + config->header_offsets.data_offset) & 0x0ffff;
Corentin Chary49dd7732011-11-26 11:00:04 +01001027
1028 if (debug)
1029 samsung_sabi_infos(samsung, loca, ifaceP);
1030
Corentin Chary5dea7a22011-11-26 10:59:59 +01001031 samsung->sabi_iface = ioremap_nocache(ifaceP, 16);
1032 if (!samsung->sabi_iface) {
1033 pr_err("Can't remap %x\n", ifaceP);
1034 ret = -EINVAL;
1035 goto exit;
1036 }
1037
Corentin Chary5dea7a22011-11-26 10:59:59 +01001038 /* Turn on "Linux" mode in the BIOS */
1039 if (commands->set_linux != 0xff) {
Corentin Chary7e960712011-11-26 11:00:02 +01001040 int retval = sabi_set_commandb(samsung,
1041 commands->set_linux, 0x81);
Corentin Chary5dea7a22011-11-26 10:59:59 +01001042 if (retval) {
1043 pr_warn("Linux mode was not set!\n");
1044 ret = -ENODEV;
1045 goto exit;
1046 }
1047 }
1048
1049 /* Check for stepping quirk */
Corentin Charyf34cd9c2011-11-26 11:00:00 +01001050 if (samsung->handle_backlight)
1051 check_for_stepping_quirk(samsung);
Corentin Chary5dea7a22011-11-26 10:59:59 +01001052
1053exit:
1054 if (ret)
1055 samsung_sabi_exit(samsung);
1056
1057 return ret;
1058}
1059
1060static void samsung_platform_exit(struct samsung_laptop *samsung)
1061{
1062 if (samsung->platform_device) {
1063 platform_device_unregister(samsung->platform_device);
1064 samsung->platform_device = NULL;
1065 }
1066}
1067
1068static int __init samsung_platform_init(struct samsung_laptop *samsung)
1069{
1070 struct platform_device *pdev;
1071
1072 pdev = platform_device_register_simple("samsung", -1, NULL, 0);
1073 if (IS_ERR(pdev))
1074 return PTR_ERR(pdev);
1075
1076 samsung->platform_device = pdev;
1077 platform_set_drvdata(samsung->platform_device, samsung);
1078 return 0;
1079}
1080
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001081static int __init dmi_check_cb(const struct dmi_system_id *id)
1082{
Corentin Chary5dea7a22011-11-26 10:59:59 +01001083 pr_info("found laptop model '%s'\n", id->ident);
Axel Lin27836582011-03-14 18:56:18 +08001084 return 1;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001085}
1086
1087static struct dmi_system_id __initdata samsung_dmi_table[] = {
1088 {
1089 .ident = "N128",
1090 .matches = {
1091 DMI_MATCH(DMI_SYS_VENDOR,
1092 "SAMSUNG ELECTRONICS CO., LTD."),
1093 DMI_MATCH(DMI_PRODUCT_NAME, "N128"),
1094 DMI_MATCH(DMI_BOARD_NAME, "N128"),
1095 },
1096 .callback = dmi_check_cb,
1097 },
1098 {
1099 .ident = "N130",
1100 .matches = {
1101 DMI_MATCH(DMI_SYS_VENDOR,
1102 "SAMSUNG ELECTRONICS CO., LTD."),
1103 DMI_MATCH(DMI_PRODUCT_NAME, "N130"),
1104 DMI_MATCH(DMI_BOARD_NAME, "N130"),
1105 },
1106 .callback = dmi_check_cb,
1107 },
1108 {
J Witteveen4e2441c2011-07-03 13:15:44 +02001109 .ident = "N510",
1110 .matches = {
1111 DMI_MATCH(DMI_SYS_VENDOR,
1112 "SAMSUNG ELECTRONICS CO., LTD."),
1113 DMI_MATCH(DMI_PRODUCT_NAME, "N510"),
1114 DMI_MATCH(DMI_BOARD_NAME, "N510"),
1115 },
1116 .callback = dmi_check_cb,
1117 },
1118 {
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001119 .ident = "X125",
1120 .matches = {
1121 DMI_MATCH(DMI_SYS_VENDOR,
1122 "SAMSUNG ELECTRONICS CO., LTD."),
1123 DMI_MATCH(DMI_PRODUCT_NAME, "X125"),
1124 DMI_MATCH(DMI_BOARD_NAME, "X125"),
1125 },
1126 .callback = dmi_check_cb,
1127 },
1128 {
1129 .ident = "X120/X170",
1130 .matches = {
1131 DMI_MATCH(DMI_SYS_VENDOR,
1132 "SAMSUNG ELECTRONICS CO., LTD."),
1133 DMI_MATCH(DMI_PRODUCT_NAME, "X120/X170"),
1134 DMI_MATCH(DMI_BOARD_NAME, "X120/X170"),
1135 },
1136 .callback = dmi_check_cb,
1137 },
1138 {
1139 .ident = "NC10",
1140 .matches = {
1141 DMI_MATCH(DMI_SYS_VENDOR,
1142 "SAMSUNG ELECTRONICS CO., LTD."),
1143 DMI_MATCH(DMI_PRODUCT_NAME, "NC10"),
1144 DMI_MATCH(DMI_BOARD_NAME, "NC10"),
1145 },
1146 .callback = dmi_check_cb,
1147 },
1148 {
1149 .ident = "NP-Q45",
1150 .matches = {
1151 DMI_MATCH(DMI_SYS_VENDOR,
1152 "SAMSUNG ELECTRONICS CO., LTD."),
1153 DMI_MATCH(DMI_PRODUCT_NAME, "SQ45S70S"),
1154 DMI_MATCH(DMI_BOARD_NAME, "SQ45S70S"),
1155 },
1156 .callback = dmi_check_cb,
1157 },
1158 {
1159 .ident = "X360",
1160 .matches = {
1161 DMI_MATCH(DMI_SYS_VENDOR,
1162 "SAMSUNG ELECTRONICS CO., LTD."),
1163 DMI_MATCH(DMI_PRODUCT_NAME, "X360"),
1164 DMI_MATCH(DMI_BOARD_NAME, "X360"),
1165 },
1166 .callback = dmi_check_cb,
1167 },
1168 {
Alberto Mardegan3d536ed2011-04-08 17:02:03 +02001169 .ident = "R410 Plus",
1170 .matches = {
1171 DMI_MATCH(DMI_SYS_VENDOR,
1172 "SAMSUNG ELECTRONICS CO., LTD."),
1173 DMI_MATCH(DMI_PRODUCT_NAME, "R410P"),
1174 DMI_MATCH(DMI_BOARD_NAME, "R460"),
1175 },
1176 .callback = dmi_check_cb,
1177 },
1178 {
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001179 .ident = "R518",
1180 .matches = {
1181 DMI_MATCH(DMI_SYS_VENDOR,
1182 "SAMSUNG ELECTRONICS CO., LTD."),
1183 DMI_MATCH(DMI_PRODUCT_NAME, "R518"),
1184 DMI_MATCH(DMI_BOARD_NAME, "R518"),
1185 },
1186 .callback = dmi_check_cb,
1187 },
1188 {
1189 .ident = "R519/R719",
1190 .matches = {
1191 DMI_MATCH(DMI_SYS_VENDOR,
1192 "SAMSUNG ELECTRONICS CO., LTD."),
1193 DMI_MATCH(DMI_PRODUCT_NAME, "R519/R719"),
1194 DMI_MATCH(DMI_BOARD_NAME, "R519/R719"),
1195 },
1196 .callback = dmi_check_cb,
1197 },
1198 {
Thomas Courbon78a75392011-07-20 22:57:44 +02001199 .ident = "N150/N210/N220",
1200 .matches = {
1201 DMI_MATCH(DMI_SYS_VENDOR,
1202 "SAMSUNG ELECTRONICS CO., LTD."),
1203 DMI_MATCH(DMI_PRODUCT_NAME, "N150/N210/N220"),
1204 DMI_MATCH(DMI_BOARD_NAME, "N150/N210/N220"),
1205 },
1206 .callback = dmi_check_cb,
1207 },
1208 {
Raul Gutierrez Segalesf689c872011-09-20 09:16:15 -07001209 .ident = "N220",
1210 .matches = {
1211 DMI_MATCH(DMI_SYS_VENDOR,
1212 "SAMSUNG ELECTRONICS CO., LTD."),
1213 DMI_MATCH(DMI_PRODUCT_NAME, "N220"),
1214 DMI_MATCH(DMI_BOARD_NAME, "N220"),
1215 },
1216 .callback = dmi_check_cb,
1217 },
1218 {
Greg Kroah-Hartman10165072011-04-08 17:02:04 +02001219 .ident = "N150/N210/N220/N230",
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001220 .matches = {
1221 DMI_MATCH(DMI_SYS_VENDOR,
1222 "SAMSUNG ELECTRONICS CO., LTD."),
Greg Kroah-Hartman10165072011-04-08 17:02:04 +02001223 DMI_MATCH(DMI_PRODUCT_NAME, "N150/N210/N220/N230"),
1224 DMI_MATCH(DMI_BOARD_NAME, "N150/N210/N220/N230"),
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001225 },
1226 .callback = dmi_check_cb,
1227 },
1228 {
1229 .ident = "N150P/N210P/N220P",
1230 .matches = {
1231 DMI_MATCH(DMI_SYS_VENDOR,
1232 "SAMSUNG ELECTRONICS CO., LTD."),
1233 DMI_MATCH(DMI_PRODUCT_NAME, "N150P/N210P/N220P"),
1234 DMI_MATCH(DMI_BOARD_NAME, "N150P/N210P/N220P"),
1235 },
1236 .callback = dmi_check_cb,
1237 },
1238 {
Stefan Bellerf87d0292011-09-20 09:16:08 -07001239 .ident = "R700",
1240 .matches = {
1241 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1242 DMI_MATCH(DMI_PRODUCT_NAME, "SR700"),
1243 DMI_MATCH(DMI_BOARD_NAME, "SR700"),
1244 },
1245 .callback = dmi_check_cb,
1246 },
1247 {
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001248 .ident = "R530/R730",
1249 .matches = {
1250 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1251 DMI_MATCH(DMI_PRODUCT_NAME, "R530/R730"),
1252 DMI_MATCH(DMI_BOARD_NAME, "R530/R730"),
1253 },
1254 .callback = dmi_check_cb,
1255 },
1256 {
1257 .ident = "NF110/NF210/NF310",
1258 .matches = {
1259 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1260 DMI_MATCH(DMI_PRODUCT_NAME, "NF110/NF210/NF310"),
1261 DMI_MATCH(DMI_BOARD_NAME, "NF110/NF210/NF310"),
1262 },
1263 .callback = dmi_check_cb,
1264 },
1265 {
1266 .ident = "N145P/N250P/N260P",
1267 .matches = {
1268 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1269 DMI_MATCH(DMI_PRODUCT_NAME, "N145P/N250P/N260P"),
1270 DMI_MATCH(DMI_BOARD_NAME, "N145P/N250P/N260P"),
1271 },
1272 .callback = dmi_check_cb,
1273 },
1274 {
1275 .ident = "R70/R71",
1276 .matches = {
1277 DMI_MATCH(DMI_SYS_VENDOR,
1278 "SAMSUNG ELECTRONICS CO., LTD."),
1279 DMI_MATCH(DMI_PRODUCT_NAME, "R70/R71"),
1280 DMI_MATCH(DMI_BOARD_NAME, "R70/R71"),
1281 },
1282 .callback = dmi_check_cb,
1283 },
1284 {
1285 .ident = "P460",
1286 .matches = {
1287 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1288 DMI_MATCH(DMI_PRODUCT_NAME, "P460"),
1289 DMI_MATCH(DMI_BOARD_NAME, "P460"),
1290 },
1291 .callback = dmi_check_cb,
1292 },
Smelov Andrey093ed562011-09-20 09:16:10 -07001293 {
1294 .ident = "R528/R728",
1295 .matches = {
1296 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1297 DMI_MATCH(DMI_PRODUCT_NAME, "R528/R728"),
1298 DMI_MATCH(DMI_BOARD_NAME, "R528/R728"),
1299 },
1300 .callback = dmi_check_cb,
1301 },
Jason Stubbs7b3c2572011-09-20 09:16:14 -07001302 {
1303 .ident = "NC210/NC110",
1304 .matches = {
1305 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1306 DMI_MATCH(DMI_PRODUCT_NAME, "NC210/NC110"),
1307 DMI_MATCH(DMI_BOARD_NAME, "NC210/NC110"),
1308 },
1309 .callback = dmi_check_cb,
1310 },
Tommaso Massimi7500eeb2011-09-20 09:16:09 -07001311 {
1312 .ident = "X520",
1313 .matches = {
1314 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1315 DMI_MATCH(DMI_PRODUCT_NAME, "X520"),
1316 DMI_MATCH(DMI_BOARD_NAME, "X520"),
1317 },
1318 .callback = dmi_check_cb,
1319 },
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001320 { },
1321};
1322MODULE_DEVICE_TABLE(dmi, samsung_dmi_table);
1323
Corentin Chary5dea7a22011-11-26 10:59:59 +01001324static struct platform_device *samsung_platform_device;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001325
1326static int __init samsung_init(void)
1327{
Corentin Chary5dea7a22011-11-26 10:59:59 +01001328 struct samsung_laptop *samsung;
1329 int ret;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001330
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001331 if (!force && !dmi_check_system(samsung_dmi_table))
1332 return -ENODEV;
1333
Corentin Charya6df4892011-11-26 10:59:58 +01001334 samsung = kzalloc(sizeof(*samsung), GFP_KERNEL);
1335 if (!samsung)
1336 return -ENOMEM;
1337
1338 mutex_init(&samsung->sabi_mutex);
Corentin Charyf34cd9c2011-11-26 11:00:00 +01001339 samsung->handle_backlight = true;
1340
1341#ifdef CONFIG_ACPI
1342 /* Don't handle backlight here if the acpi video already handle it */
1343 if (acpi_video_backlight_support()) {
1344 pr_info("Backlight controlled by ACPI video driver\n");
1345 samsung->handle_backlight = false;
1346 }
1347#endif
Corentin Charya6df4892011-11-26 10:59:58 +01001348
Corentin Chary5dea7a22011-11-26 10:59:59 +01001349 ret = samsung_platform_init(samsung);
1350 if (ret)
1351 goto error_platform;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001352
Corentin Chary5dea7a22011-11-26 10:59:59 +01001353 ret = samsung_sabi_init(samsung);
1354 if (ret)
1355 goto error_sabi;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001356
Corentin Chary5dea7a22011-11-26 10:59:59 +01001357 ret = samsung_sysfs_init(samsung);
1358 if (ret)
1359 goto error_sysfs;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001360
Corentin Chary5dea7a22011-11-26 10:59:59 +01001361 ret = samsung_backlight_init(samsung);
1362 if (ret)
1363 goto error_backlight;
Corentin Charya6df4892011-11-26 10:59:58 +01001364
Corentin Chary5dea7a22011-11-26 10:59:59 +01001365 ret = samsung_rfkill_init(samsung);
1366 if (ret)
1367 goto error_rfkill;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001368
Corentin Chary5b80fc42011-11-26 11:00:03 +01001369 ret = samsung_debugfs_init(samsung);
1370 if (ret)
1371 goto error_debugfs;
1372
Corentin Chary5dea7a22011-11-26 10:59:59 +01001373 samsung_platform_device = samsung->platform_device;
1374 return ret;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001375
Corentin Chary5b80fc42011-11-26 11:00:03 +01001376error_debugfs:
1377 samsung_rfkill_exit(samsung);
Corentin Chary5dea7a22011-11-26 10:59:59 +01001378error_rfkill:
1379 samsung_backlight_exit(samsung);
1380error_backlight:
1381 samsung_sysfs_exit(samsung);
1382error_sysfs:
1383 samsung_sabi_exit(samsung);
1384error_sabi:
1385 samsung_platform_exit(samsung);
1386error_platform:
Corentin Charya6df4892011-11-26 10:59:58 +01001387 kfree(samsung);
Corentin Chary5dea7a22011-11-26 10:59:59 +01001388 return ret;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001389}
1390
1391static void __exit samsung_exit(void)
1392{
Corentin Chary5dea7a22011-11-26 10:59:59 +01001393 struct samsung_laptop *samsung;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001394
Corentin Chary5dea7a22011-11-26 10:59:59 +01001395 samsung = platform_get_drvdata(samsung_platform_device);
Corentin Charya6df4892011-11-26 10:59:58 +01001396
Corentin Chary5b80fc42011-11-26 11:00:03 +01001397 samsung_debugfs_exit(samsung);
Corentin Chary5dea7a22011-11-26 10:59:59 +01001398 samsung_rfkill_exit(samsung);
1399 samsung_backlight_exit(samsung);
1400 samsung_sysfs_exit(samsung);
1401 samsung_sabi_exit(samsung);
1402 samsung_platform_exit(samsung);
1403
Corentin Charya6df4892011-11-26 10:59:58 +01001404 kfree(samsung);
Corentin Chary5dea7a22011-11-26 10:59:59 +01001405 samsung_platform_device = NULL;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001406}
1407
1408module_init(samsung_init);
1409module_exit(samsung_exit);
1410
1411MODULE_AUTHOR("Greg Kroah-Hartman <gregkh@suse.de>");
1412MODULE_DESCRIPTION("Samsung Backlight driver");
1413MODULE_LICENSE("GPL");