blob: b39fa53baa2293c424970c3346d967097139b810 [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
107 /*
108 * Tell the BIOS that Linux is running on this machine.
109 * 81 is on, 80 is off
110 */
Corentin Chary7e960712011-11-26 11:00:02 +0100111 u16 set_linux;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500112};
113
114struct sabi_performance_level {
115 const char *name;
Corentin Chary7e960712011-11-26 11:00:02 +0100116 u16 value;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500117};
118
119struct sabi_config {
120 const char *test_string;
121 u16 main_function;
122 const struct sabi_header_offsets header_offsets;
123 const struct sabi_commands commands;
124 const struct sabi_performance_level performance_levels[4];
125 u8 min_brightness;
126 u8 max_brightness;
127};
128
129static const struct sabi_config sabi_configs[] = {
130 {
131 .test_string = "SECLINUX",
132
133 .main_function = 0x4c49,
134
135 .header_offsets = {
136 .port = 0x00,
137 .re_mem = 0x02,
138 .iface_func = 0x03,
139 .en_mem = 0x04,
140 .data_offset = 0x05,
141 .data_segment = 0x07,
142 },
143
144 .commands = {
145 .get_brightness = 0x00,
146 .set_brightness = 0x01,
147
148 .get_wireless_button = 0x02,
149 .set_wireless_button = 0x03,
150
151 .get_backlight = 0x04,
152 .set_backlight = 0x05,
153
154 .get_recovery_mode = 0x06,
155 .set_recovery_mode = 0x07,
156
157 .get_performance_level = 0x08,
158 .set_performance_level = 0x09,
159
160 .set_linux = 0x0a,
161 },
162
163 .performance_levels = {
164 {
165 .name = "silent",
166 .value = 0,
167 },
168 {
169 .name = "normal",
170 .value = 1,
171 },
172 { },
173 },
174 .min_brightness = 1,
175 .max_brightness = 8,
176 },
177 {
178 .test_string = "SwSmi@",
179
180 .main_function = 0x5843,
181
182 .header_offsets = {
183 .port = 0x00,
184 .re_mem = 0x04,
185 .iface_func = 0x02,
186 .en_mem = 0x03,
187 .data_offset = 0x05,
188 .data_segment = 0x07,
189 },
190
191 .commands = {
192 .get_brightness = 0x10,
193 .set_brightness = 0x11,
194
195 .get_wireless_button = 0x12,
196 .set_wireless_button = 0x13,
197
198 .get_backlight = 0x2d,
199 .set_backlight = 0x2e,
200
201 .get_recovery_mode = 0xff,
202 .set_recovery_mode = 0xff,
203
204 .get_performance_level = 0x31,
205 .set_performance_level = 0x32,
206
207 .set_linux = 0xff,
208 },
209
210 .performance_levels = {
211 {
212 .name = "normal",
213 .value = 0,
214 },
215 {
216 .name = "silent",
217 .value = 1,
218 },
219 {
220 .name = "overclock",
221 .value = 2,
222 },
223 { },
224 },
225 .min_brightness = 0,
226 .max_brightness = 8,
227 },
228 { },
229};
230
Corentin Chary5b80fc42011-11-26 11:00:03 +0100231/*
232 * samsung-laptop/ - debugfs root directory
233 * f0000_segment - dump f0000 segment
234 * command - current command
235 * data - current data
236 * d0, d1, d2, d3 - data fields
237 * call - call SABI using command and data
238 *
239 * This allow to call arbitrary sabi commands wihout
240 * modifying the driver at all.
241 * For example, setting the keyboard backlight brightness to 5
242 *
243 * echo 0x78 > command
244 * echo 0x0582 > d0
245 * echo 0 > d1
246 * echo 0 > d2
247 * echo 0 > d3
248 * cat call
249 */
250
251struct samsung_laptop_debug {
252 struct dentry *root;
253 struct sabi_data data;
254 u16 command;
255
256 struct debugfs_blob_wrapper f0000_wrapper;
257 struct debugfs_blob_wrapper data_wrapper;
258};
259
Corentin Charya6df4892011-11-26 10:59:58 +0100260struct samsung_laptop {
261 const struct sabi_config *config;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500262
Corentin Charya6df4892011-11-26 10:59:58 +0100263 void __iomem *sabi;
264 void __iomem *sabi_iface;
265 void __iomem *f0000_segment;
266
267 struct mutex sabi_mutex;
268
Corentin Chary5dea7a22011-11-26 10:59:59 +0100269 struct platform_device *platform_device;
Corentin Charya6df4892011-11-26 10:59:58 +0100270 struct backlight_device *backlight_device;
271 struct rfkill *rfk;
272
Corentin Chary5b80fc42011-11-26 11:00:03 +0100273 struct samsung_laptop_debug debug;
274
Corentin Charyf34cd9c2011-11-26 11:00:00 +0100275 bool handle_backlight;
Corentin Charya6df4892011-11-26 10:59:58 +0100276 bool has_stepping_quirk;
277};
278
Corentin Chary5dea7a22011-11-26 10:59:59 +0100279
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500280
Rusty Russell90ab5ee2012-01-13 09:32:20 +1030281static bool force;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500282module_param(force, bool, 0);
283MODULE_PARM_DESC(force,
284 "Disable the DMI check and forces the driver to be loaded");
285
Rusty Russell90ab5ee2012-01-13 09:32:20 +1030286static bool debug;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500287module_param(debug, bool, S_IRUGO | S_IWUSR);
288MODULE_PARM_DESC(debug, "Debug enabled or not");
289
Corentin Chary7e960712011-11-26 11:00:02 +0100290static int sabi_command(struct samsung_laptop *samsung, u16 command,
291 struct sabi_data *in,
292 struct sabi_data *out)
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500293{
Corentin Charya6df4892011-11-26 10:59:58 +0100294 const struct sabi_config *config = samsung->config;
Corentin Chary7e960712011-11-26 11:00:02 +0100295 int ret = 0;
Corentin Charya6df4892011-11-26 10:59:58 +0100296 u16 port = readw(samsung->sabi + config->header_offsets.port);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500297 u8 complete, iface_data;
298
Corentin Charya6df4892011-11-26 10:59:58 +0100299 mutex_lock(&samsung->sabi_mutex);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500300
Corentin Chary7e960712011-11-26 11:00:02 +0100301 if (debug) {
302 if (in)
303 pr_info("SABI 0x%04x {0x%08x, 0x%08x, 0x%04x, 0x%02x}",
304 command, in->d0, in->d1, in->d2, in->d3);
305 else
306 pr_info("SABI 0x%04x", command);
307 }
308
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500309 /* enable memory to be able to write to it */
Corentin Charya6df4892011-11-26 10:59:58 +0100310 outb(readb(samsung->sabi + config->header_offsets.en_mem), port);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500311
312 /* write out the command */
Corentin Charya6df4892011-11-26 10:59:58 +0100313 writew(config->main_function, samsung->sabi_iface + SABI_IFACE_MAIN);
314 writew(command, samsung->sabi_iface + SABI_IFACE_SUB);
315 writeb(0, samsung->sabi_iface + SABI_IFACE_COMPLETE);
Corentin Chary7e960712011-11-26 11:00:02 +0100316 if (in) {
317 writel(in->d0, samsung->sabi_iface + SABI_IFACE_DATA);
318 writel(in->d1, samsung->sabi_iface + SABI_IFACE_DATA + 4);
319 writew(in->d2, samsung->sabi_iface + SABI_IFACE_DATA + 8);
320 writeb(in->d3, samsung->sabi_iface + SABI_IFACE_DATA + 10);
321 }
Corentin Charya6df4892011-11-26 10:59:58 +0100322 outb(readb(samsung->sabi + config->header_offsets.iface_func), port);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500323
324 /* write protect memory to make it safe */
Corentin Charya6df4892011-11-26 10:59:58 +0100325 outb(readb(samsung->sabi + config->header_offsets.re_mem), port);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500326
327 /* see if the command actually succeeded */
Corentin Charya6df4892011-11-26 10:59:58 +0100328 complete = readb(samsung->sabi_iface + SABI_IFACE_COMPLETE);
329 iface_data = readb(samsung->sabi_iface + SABI_IFACE_DATA);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500330 if (complete != 0xaa || iface_data == 0xff) {
Corentin Chary7e960712011-11-26 11:00:02 +0100331 pr_warn("SABI command 0x%04x failed with"
332 " completion flag 0x%02x and interface data 0x%02x",
333 command, complete, iface_data);
334 ret = -EINVAL;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500335 goto exit;
336 }
Corentin Chary7e960712011-11-26 11:00:02 +0100337
338 if (out) {
339 out->d0 = readl(samsung->sabi_iface + SABI_IFACE_DATA);
340 out->d1 = readl(samsung->sabi_iface + SABI_IFACE_DATA + 4);
341 out->d2 = readw(samsung->sabi_iface + SABI_IFACE_DATA + 2);
342 out->d3 = readb(samsung->sabi_iface + SABI_IFACE_DATA + 1);
343 }
344
345 if (debug && out) {
346 pr_info("SABI {0x%08x, 0x%08x, 0x%04x, 0x%02x}",
347 out->d0, out->d1, out->d2, out->d3);
348 }
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500349
350exit:
Corentin Charya6df4892011-11-26 10:59:58 +0100351 mutex_unlock(&samsung->sabi_mutex);
Corentin Chary7e960712011-11-26 11:00:02 +0100352 return ret;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500353}
354
Corentin Chary7e960712011-11-26 11:00:02 +0100355/* simple wrappers usable with most commands */
356static int sabi_set_commandb(struct samsung_laptop *samsung,
357 u16 command, u8 data)
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500358{
Corentin Chary7e960712011-11-26 11:00:02 +0100359 struct sabi_data in = { .d0 = 0, .d1 = 0, .d2 = 0, .d3 = 0 };
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500360
Corentin Chary7e960712011-11-26 11:00:02 +0100361 in.data[0] = data;
362 return sabi_command(samsung, command, &in, NULL);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500363}
364
Corentin Chary5dea7a22011-11-26 10:59:59 +0100365static int read_brightness(struct samsung_laptop *samsung)
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500366{
Corentin Charya6df4892011-11-26 10:59:58 +0100367 const struct sabi_config *config = samsung->config;
368 const struct sabi_commands *commands = &samsung->config->commands;
Corentin Chary7e960712011-11-26 11:00:02 +0100369 struct sabi_data sretval;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500370 int user_brightness = 0;
371 int retval;
372
Corentin Chary7e960712011-11-26 11:00:02 +0100373 retval = sabi_command(samsung, commands->get_brightness,
374 NULL, &sretval);
375 if (retval)
376 return retval;
377
378 user_brightness = sretval.data[0];
379 if (user_brightness > config->min_brightness)
380 user_brightness -= config->min_brightness;
381 else
382 user_brightness = 0;
383
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500384 return user_brightness;
385}
386
Corentin Chary5dea7a22011-11-26 10:59:59 +0100387static void set_brightness(struct samsung_laptop *samsung, u8 user_brightness)
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500388{
Corentin Charya6df4892011-11-26 10:59:58 +0100389 const struct sabi_config *config = samsung->config;
390 const struct sabi_commands *commands = &samsung->config->commands;
391 u8 user_level = user_brightness + config->min_brightness;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500392
Corentin Charya6df4892011-11-26 10:59:58 +0100393 if (samsung->has_stepping_quirk && user_level != 0) {
Jason Stubbsac080522011-09-20 09:16:13 -0700394 /*
395 * short circuit if the specified level is what's already set
396 * to prevent the screen from flickering needlessly
397 */
Corentin Chary5dea7a22011-11-26 10:59:59 +0100398 if (user_brightness == read_brightness(samsung))
Jason Stubbsac080522011-09-20 09:16:13 -0700399 return;
400
Corentin Chary7e960712011-11-26 11:00:02 +0100401 sabi_set_commandb(samsung, commands->set_brightness, 0);
Jason Stubbsac080522011-09-20 09:16:13 -0700402 }
403
Corentin Chary7e960712011-11-26 11:00:02 +0100404 sabi_set_commandb(samsung, commands->set_brightness, user_level);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500405}
406
407static int get_brightness(struct backlight_device *bd)
408{
Corentin Chary5dea7a22011-11-26 10:59:59 +0100409 struct samsung_laptop *samsung = bl_get_data(bd);
410
411 return read_brightness(samsung);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500412}
413
Corentin Chary5dea7a22011-11-26 10:59:59 +0100414static void check_for_stepping_quirk(struct samsung_laptop *samsung)
Jason Stubbsac080522011-09-20 09:16:13 -0700415{
Corentin Chary5dea7a22011-11-26 10:59:59 +0100416 int initial_level;
417 int check_level;
418 int orig_level = read_brightness(samsung);
Jason Stubbsac080522011-09-20 09:16:13 -0700419
420 /*
421 * Some laptops exhibit the strange behaviour of stepping toward
422 * (rather than setting) the brightness except when changing to/from
423 * brightness level 0. This behaviour is checked for here and worked
424 * around in set_brightness.
425 */
426
John Serockba05b232011-10-13 06:42:01 -0400427 if (orig_level == 0)
Corentin Chary5dea7a22011-11-26 10:59:59 +0100428 set_brightness(samsung, 1);
John Serockba05b232011-10-13 06:42:01 -0400429
Corentin Chary5dea7a22011-11-26 10:59:59 +0100430 initial_level = read_brightness(samsung);
John Serockba05b232011-10-13 06:42:01 -0400431
Jason Stubbsac080522011-09-20 09:16:13 -0700432 if (initial_level <= 2)
433 check_level = initial_level + 2;
434 else
435 check_level = initial_level - 2;
436
Corentin Charya6df4892011-11-26 10:59:58 +0100437 samsung->has_stepping_quirk = false;
Corentin Chary5dea7a22011-11-26 10:59:59 +0100438 set_brightness(samsung, check_level);
Jason Stubbsac080522011-09-20 09:16:13 -0700439
Corentin Chary5dea7a22011-11-26 10:59:59 +0100440 if (read_brightness(samsung) != check_level) {
Corentin Charya6df4892011-11-26 10:59:58 +0100441 samsung->has_stepping_quirk = true;
Jason Stubbsac080522011-09-20 09:16:13 -0700442 pr_info("enabled workaround for brightness stepping quirk\n");
443 }
444
Corentin Chary5dea7a22011-11-26 10:59:59 +0100445 set_brightness(samsung, orig_level);
Jason Stubbsac080522011-09-20 09:16:13 -0700446}
447
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500448static int update_status(struct backlight_device *bd)
449{
Corentin Chary5dea7a22011-11-26 10:59:59 +0100450 struct samsung_laptop *samsung = bl_get_data(bd);
Corentin Charya6df4892011-11-26 10:59:58 +0100451 const struct sabi_commands *commands = &samsung->config->commands;
452
Corentin Chary5dea7a22011-11-26 10:59:59 +0100453 set_brightness(samsung, bd->props.brightness);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500454
455 if (bd->props.power == FB_BLANK_UNBLANK)
Corentin Chary7e960712011-11-26 11:00:02 +0100456 sabi_set_commandb(samsung, commands->set_backlight, 1);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500457 else
Corentin Chary7e960712011-11-26 11:00:02 +0100458 sabi_set_commandb(samsung, commands->set_backlight, 0);
Corentin Chary5dea7a22011-11-26 10:59:59 +0100459
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500460 return 0;
461}
462
463static const struct backlight_ops backlight_ops = {
464 .get_brightness = get_brightness,
465 .update_status = update_status,
466};
467
468static int rfkill_set(void *data, bool blocked)
469{
Corentin Chary5dea7a22011-11-26 10:59:59 +0100470 struct samsung_laptop *samsung = data;
Corentin Charya6df4892011-11-26 10:59:58 +0100471 const struct sabi_commands *commands = &samsung->config->commands;
472
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500473 /* Do something with blocked...*/
474 /*
475 * blocked == false is on
476 * blocked == true is off
477 */
478 if (blocked)
Corentin Chary7e960712011-11-26 11:00:02 +0100479 sabi_set_commandb(samsung, commands->set_wireless_button, 0);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500480 else
Corentin Chary7e960712011-11-26 11:00:02 +0100481 sabi_set_commandb(samsung, commands->set_wireless_button, 1);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500482
483 return 0;
484}
485
486static struct rfkill_ops rfkill_ops = {
487 .set_block = rfkill_set,
488};
489
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500490static ssize_t get_performance_level(struct device *dev,
491 struct device_attribute *attr, char *buf)
492{
Corentin Chary5dea7a22011-11-26 10:59:59 +0100493 struct samsung_laptop *samsung = dev_get_drvdata(dev);
Corentin Charya6df4892011-11-26 10:59:58 +0100494 const struct sabi_config *config = samsung->config;
Corentin Chary5dea7a22011-11-26 10:59:59 +0100495 const struct sabi_commands *commands = &config->commands;
Corentin Chary7e960712011-11-26 11:00:02 +0100496 struct sabi_data sretval;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500497 int retval;
498 int i;
499
500 /* Read the state */
Corentin Chary7e960712011-11-26 11:00:02 +0100501 retval = sabi_command(samsung, commands->get_performance_level,
502 NULL, &sretval);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500503 if (retval)
504 return retval;
505
506 /* The logic is backwards, yeah, lots of fun... */
Corentin Charya6df4892011-11-26 10:59:58 +0100507 for (i = 0; config->performance_levels[i].name; ++i) {
Corentin Chary7e960712011-11-26 11:00:02 +0100508 if (sretval.data[0] == config->performance_levels[i].value)
Corentin Charya6df4892011-11-26 10:59:58 +0100509 return sprintf(buf, "%s\n", config->performance_levels[i].name);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500510 }
511 return sprintf(buf, "%s\n", "unknown");
512}
513
514static ssize_t set_performance_level(struct device *dev,
515 struct device_attribute *attr, const char *buf,
516 size_t count)
517{
Corentin Chary5dea7a22011-11-26 10:59:59 +0100518 struct samsung_laptop *samsung = dev_get_drvdata(dev);
Corentin Charya6df4892011-11-26 10:59:58 +0100519 const struct sabi_config *config = samsung->config;
Corentin Chary5dea7a22011-11-26 10:59:59 +0100520 const struct sabi_commands *commands = &config->commands;
521 int i;
Corentin Charya6df4892011-11-26 10:59:58 +0100522
Corentin Chary5dea7a22011-11-26 10:59:59 +0100523 if (count < 1)
524 return count;
525
526 for (i = 0; config->performance_levels[i].name; ++i) {
527 const struct sabi_performance_level *level =
528 &config->performance_levels[i];
529 if (!strncasecmp(level->name, buf, strlen(level->name))) {
Corentin Chary7e960712011-11-26 11:00:02 +0100530 sabi_set_commandb(samsung,
531 commands->set_performance_level,
532 level->value);
Corentin Chary5dea7a22011-11-26 10:59:59 +0100533 break;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500534 }
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500535 }
Corentin Chary5dea7a22011-11-26 10:59:59 +0100536
537 if (!config->performance_levels[i].name)
538 return -EINVAL;
539
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500540 return count;
541}
Corentin Chary5dea7a22011-11-26 10:59:59 +0100542
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500543static DEVICE_ATTR(performance_level, S_IWUSR | S_IRUGO,
544 get_performance_level, set_performance_level);
545
Corentin Charya66c1662011-11-26 11:00:01 +0100546static struct attribute *platform_attributes[] = {
547 &dev_attr_performance_level.attr,
548 NULL
549};
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500550
Corentin Chary5dea7a22011-11-26 10:59:59 +0100551static int find_signature(void __iomem *memcheck, const char *testStr)
552{
553 int i = 0;
554 int loca;
555
556 for (loca = 0; loca < 0xffff; loca++) {
557 char temp = readb(memcheck + loca);
558
559 if (temp == testStr[i]) {
560 if (i == strlen(testStr)-1)
561 break;
562 ++i;
563 } else {
564 i = 0;
565 }
566 }
567 return loca;
568}
569
570static void samsung_rfkill_exit(struct samsung_laptop *samsung)
571{
572 if (samsung->rfk) {
573 rfkill_unregister(samsung->rfk);
574 rfkill_destroy(samsung->rfk);
575 samsung->rfk = NULL;
576 }
577}
578
579static int __init samsung_rfkill_init(struct samsung_laptop *samsung)
580{
581 int retval;
582
583 samsung->rfk = rfkill_alloc("samsung-wifi",
584 &samsung->platform_device->dev,
585 RFKILL_TYPE_WLAN,
586 &rfkill_ops, samsung);
587 if (!samsung->rfk)
588 return -ENOMEM;
589
590 retval = rfkill_register(samsung->rfk);
591 if (retval) {
592 rfkill_destroy(samsung->rfk);
593 samsung->rfk = NULL;
594 return -ENODEV;
595 }
596
597 return 0;
598}
599
600static void samsung_backlight_exit(struct samsung_laptop *samsung)
601{
602 if (samsung->backlight_device) {
603 backlight_device_unregister(samsung->backlight_device);
604 samsung->backlight_device = NULL;
605 }
606}
607
608static int __init samsung_backlight_init(struct samsung_laptop *samsung)
609{
610 struct backlight_device *bd;
611 struct backlight_properties props;
612
Corentin Charyf34cd9c2011-11-26 11:00:00 +0100613 if (!samsung->handle_backlight)
614 return 0;
615
Corentin Chary5dea7a22011-11-26 10:59:59 +0100616 memset(&props, 0, sizeof(struct backlight_properties));
617 props.type = BACKLIGHT_PLATFORM;
618 props.max_brightness = samsung->config->max_brightness -
619 samsung->config->min_brightness;
620
621 bd = backlight_device_register("samsung",
622 &samsung->platform_device->dev,
623 samsung, &backlight_ops,
624 &props);
625 if (IS_ERR(bd))
626 return PTR_ERR(bd);
627
628 samsung->backlight_device = bd;
629 samsung->backlight_device->props.brightness = read_brightness(samsung);
630 samsung->backlight_device->props.power = FB_BLANK_UNBLANK;
631 backlight_update_status(samsung->backlight_device);
632
633 return 0;
634}
635
Corentin Charya66c1662011-11-26 11:00:01 +0100636static mode_t samsung_sysfs_is_visible(struct kobject *kobj,
637 struct attribute *attr, int idx)
638{
639 struct device *dev = container_of(kobj, struct device, kobj);
640 struct platform_device *pdev = to_platform_device(dev);
641 struct samsung_laptop *samsung = platform_get_drvdata(pdev);
642 bool ok = true;
643
644 if (attr == &dev_attr_performance_level.attr)
645 ok = !!samsung->config->performance_levels[0].name;
646
647 return ok ? attr->mode : 0;
648}
649
650static struct attribute_group platform_attribute_group = {
651 .is_visible = samsung_sysfs_is_visible,
652 .attrs = platform_attributes
653};
654
Corentin Chary5dea7a22011-11-26 10:59:59 +0100655static void samsung_sysfs_exit(struct samsung_laptop *samsung)
656{
Corentin Charya66c1662011-11-26 11:00:01 +0100657 struct platform_device *device = samsung->platform_device;
658
659 sysfs_remove_group(&device->dev.kobj, &platform_attribute_group);
Corentin Chary5dea7a22011-11-26 10:59:59 +0100660}
661
662static int __init samsung_sysfs_init(struct samsung_laptop *samsung)
663{
Corentin Charya66c1662011-11-26 11:00:01 +0100664 struct platform_device *device = samsung->platform_device;
665
666 return sysfs_create_group(&device->dev.kobj, &platform_attribute_group);
667
Corentin Chary5dea7a22011-11-26 10:59:59 +0100668}
669
Corentin Chary5b80fc42011-11-26 11:00:03 +0100670static int show_call(struct seq_file *m, void *data)
671{
672 struct samsung_laptop *samsung = m->private;
673 struct sabi_data *sdata = &samsung->debug.data;
674 int ret;
675
676 seq_printf(m, "SABI 0x%04x {0x%08x, 0x%08x, 0x%04x, 0x%02x}\n",
677 samsung->debug.command,
678 sdata->d0, sdata->d1, sdata->d2, sdata->d3);
679
680 ret = sabi_command(samsung, samsung->debug.command, sdata, sdata);
681
682 if (ret) {
683 seq_printf(m, "SABI command 0x%04x failed\n",
684 samsung->debug.command);
685 return ret;
686 }
687
688 seq_printf(m, "SABI {0x%08x, 0x%08x, 0x%04x, 0x%02x}\n",
689 sdata->d0, sdata->d1, sdata->d2, sdata->d3);
690 return 0;
691}
692
693static int samsung_debugfs_open(struct inode *inode, struct file *file)
694{
695 return single_open(file, show_call, inode->i_private);
696}
697
698static const struct file_operations samsung_laptop_call_io_ops = {
699 .owner = THIS_MODULE,
700 .open = samsung_debugfs_open,
701 .read = seq_read,
702 .llseek = seq_lseek,
703 .release = single_release,
704};
705
706static void samsung_debugfs_exit(struct samsung_laptop *samsung)
707{
708 debugfs_remove_recursive(samsung->debug.root);
709}
710
711static int samsung_debugfs_init(struct samsung_laptop *samsung)
712{
713 struct dentry *dent;
714
715 samsung->debug.root = debugfs_create_dir("samsung-laptop", NULL);
716 if (!samsung->debug.root) {
717 pr_err("failed to create debugfs directory");
718 goto error_debugfs;
719 }
720
721 samsung->debug.f0000_wrapper.data = samsung->f0000_segment;
722 samsung->debug.f0000_wrapper.size = 0xffff;
723
724 samsung->debug.data_wrapper.data = &samsung->debug.data;
725 samsung->debug.data_wrapper.size = sizeof(samsung->debug.data);
726
727 dent = debugfs_create_u16("command", S_IRUGO | S_IWUSR,
728 samsung->debug.root, &samsung->debug.command);
729 if (!dent)
730 goto error_debugfs;
731
732 dent = debugfs_create_u32("d0", S_IRUGO | S_IWUSR, samsung->debug.root,
733 &samsung->debug.data.d0);
734 if (!dent)
735 goto error_debugfs;
736
737 dent = debugfs_create_u32("d1", S_IRUGO | S_IWUSR, samsung->debug.root,
738 &samsung->debug.data.d1);
739 if (!dent)
740 goto error_debugfs;
741
742 dent = debugfs_create_u16("d2", S_IRUGO | S_IWUSR, samsung->debug.root,
743 &samsung->debug.data.d2);
744 if (!dent)
745 goto error_debugfs;
746
747 dent = debugfs_create_u8("d3", S_IRUGO | S_IWUSR, samsung->debug.root,
748 &samsung->debug.data.d3);
749 if (!dent)
750 goto error_debugfs;
751
752 dent = debugfs_create_blob("data", S_IRUGO | S_IWUSR,
753 samsung->debug.root,
754 &samsung->debug.data_wrapper);
755 if (!dent)
756 goto error_debugfs;
757
758 dent = debugfs_create_blob("f0000_segment", S_IRUSR | S_IWUSR,
759 samsung->debug.root,
760 &samsung->debug.f0000_wrapper);
761 if (!dent)
762 goto error_debugfs;
763
764 dent = debugfs_create_file("call", S_IFREG | S_IRUGO,
765 samsung->debug.root, samsung,
766 &samsung_laptop_call_io_ops);
767 if (!dent)
768 goto error_debugfs;
769
770 return 0;
771
772error_debugfs:
773 samsung_debugfs_exit(samsung);
774 return -ENOMEM;
775}
776
Corentin Chary5dea7a22011-11-26 10:59:59 +0100777static void samsung_sabi_exit(struct samsung_laptop *samsung)
778{
779 const struct sabi_config *config = samsung->config;
780
781 /* Turn off "Linux" mode in the BIOS */
782 if (config && config->commands.set_linux != 0xff)
Corentin Chary7e960712011-11-26 11:00:02 +0100783 sabi_set_commandb(samsung, config->commands.set_linux, 0x80);
Corentin Chary5dea7a22011-11-26 10:59:59 +0100784
785 if (samsung->sabi_iface) {
786 iounmap(samsung->sabi_iface);
787 samsung->sabi_iface = NULL;
788 }
789 if (samsung->f0000_segment) {
790 iounmap(samsung->f0000_segment);
791 samsung->f0000_segment = NULL;
792 }
793
794 samsung->config = NULL;
795}
796
Corentin Chary49dd7732011-11-26 11:00:04 +0100797static __init void samsung_sabi_infos(struct samsung_laptop *samsung, int loca,
798 unsigned int ifaceP)
Corentin Chary5dea7a22011-11-26 10:59:59 +0100799{
800 const struct sabi_config *config = samsung->config;
801
802 printk(KERN_DEBUG "This computer supports SABI==%x\n",
803 loca + 0xf0000 - 6);
Corentin Chary49dd7732011-11-26 11:00:04 +0100804
Corentin Chary5dea7a22011-11-26 10:59:59 +0100805 printk(KERN_DEBUG "SABI header:\n");
806 printk(KERN_DEBUG " SMI Port Number = 0x%04x\n",
807 readw(samsung->sabi + config->header_offsets.port));
808 printk(KERN_DEBUG " SMI Interface Function = 0x%02x\n",
809 readb(samsung->sabi + config->header_offsets.iface_func));
810 printk(KERN_DEBUG " SMI enable memory buffer = 0x%02x\n",
811 readb(samsung->sabi + config->header_offsets.en_mem));
812 printk(KERN_DEBUG " SMI restore memory buffer = 0x%02x\n",
813 readb(samsung->sabi + config->header_offsets.re_mem));
814 printk(KERN_DEBUG " SABI data offset = 0x%04x\n",
815 readw(samsung->sabi + config->header_offsets.data_offset));
816 printk(KERN_DEBUG " SABI data segment = 0x%04x\n",
817 readw(samsung->sabi + config->header_offsets.data_segment));
Corentin Chary5dea7a22011-11-26 10:59:59 +0100818
Corentin Chary49dd7732011-11-26 11:00:04 +0100819 printk(KERN_DEBUG " SABI pointer = 0x%08x\n", ifaceP);
Corentin Chary5dea7a22011-11-26 10:59:59 +0100820}
821
822static int __init samsung_sabi_init(struct samsung_laptop *samsung)
823{
824 const struct sabi_config *config = NULL;
825 const struct sabi_commands *commands;
826 unsigned int ifaceP;
827 int ret = 0;
828 int i;
829 int loca;
830
831 samsung->f0000_segment = ioremap_nocache(0xf0000, 0xffff);
832 if (!samsung->f0000_segment) {
833 pr_err("Can't map the segment at 0xf0000\n");
834 ret = -EINVAL;
835 goto exit;
836 }
837
838 /* Try to find one of the signatures in memory to find the header */
839 for (i = 0; sabi_configs[i].test_string != 0; ++i) {
840 samsung->config = &sabi_configs[i];
841 loca = find_signature(samsung->f0000_segment,
842 samsung->config->test_string);
843 if (loca != 0xffff)
844 break;
845 }
846
847 if (loca == 0xffff) {
848 pr_err("This computer does not support SABI\n");
849 ret = -ENODEV;
850 goto exit;
851 }
852
853 config = samsung->config;
854 commands = &config->commands;
855
856 /* point to the SMI port Number */
857 loca += 1;
858 samsung->sabi = (samsung->f0000_segment + loca);
859
Corentin Chary5dea7a22011-11-26 10:59:59 +0100860 /* Get a pointer to the SABI Interface */
861 ifaceP = (readw(samsung->sabi + config->header_offsets.data_segment) & 0x0ffff) << 4;
862 ifaceP += readw(samsung->sabi + config->header_offsets.data_offset) & 0x0ffff;
Corentin Chary49dd7732011-11-26 11:00:04 +0100863
864 if (debug)
865 samsung_sabi_infos(samsung, loca, ifaceP);
866
Corentin Chary5dea7a22011-11-26 10:59:59 +0100867 samsung->sabi_iface = ioremap_nocache(ifaceP, 16);
868 if (!samsung->sabi_iface) {
869 pr_err("Can't remap %x\n", ifaceP);
870 ret = -EINVAL;
871 goto exit;
872 }
873
Corentin Chary5dea7a22011-11-26 10:59:59 +0100874 /* Turn on "Linux" mode in the BIOS */
875 if (commands->set_linux != 0xff) {
Corentin Chary7e960712011-11-26 11:00:02 +0100876 int retval = sabi_set_commandb(samsung,
877 commands->set_linux, 0x81);
Corentin Chary5dea7a22011-11-26 10:59:59 +0100878 if (retval) {
879 pr_warn("Linux mode was not set!\n");
880 ret = -ENODEV;
881 goto exit;
882 }
883 }
884
885 /* Check for stepping quirk */
Corentin Charyf34cd9c2011-11-26 11:00:00 +0100886 if (samsung->handle_backlight)
887 check_for_stepping_quirk(samsung);
Corentin Chary5dea7a22011-11-26 10:59:59 +0100888
889exit:
890 if (ret)
891 samsung_sabi_exit(samsung);
892
893 return ret;
894}
895
896static void samsung_platform_exit(struct samsung_laptop *samsung)
897{
898 if (samsung->platform_device) {
899 platform_device_unregister(samsung->platform_device);
900 samsung->platform_device = NULL;
901 }
902}
903
904static int __init samsung_platform_init(struct samsung_laptop *samsung)
905{
906 struct platform_device *pdev;
907
908 pdev = platform_device_register_simple("samsung", -1, NULL, 0);
909 if (IS_ERR(pdev))
910 return PTR_ERR(pdev);
911
912 samsung->platform_device = pdev;
913 platform_set_drvdata(samsung->platform_device, samsung);
914 return 0;
915}
916
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500917static int __init dmi_check_cb(const struct dmi_system_id *id)
918{
Corentin Chary5dea7a22011-11-26 10:59:59 +0100919 pr_info("found laptop model '%s'\n", id->ident);
Axel Lin27836582011-03-14 18:56:18 +0800920 return 1;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500921}
922
923static struct dmi_system_id __initdata samsung_dmi_table[] = {
924 {
925 .ident = "N128",
926 .matches = {
927 DMI_MATCH(DMI_SYS_VENDOR,
928 "SAMSUNG ELECTRONICS CO., LTD."),
929 DMI_MATCH(DMI_PRODUCT_NAME, "N128"),
930 DMI_MATCH(DMI_BOARD_NAME, "N128"),
931 },
932 .callback = dmi_check_cb,
933 },
934 {
935 .ident = "N130",
936 .matches = {
937 DMI_MATCH(DMI_SYS_VENDOR,
938 "SAMSUNG ELECTRONICS CO., LTD."),
939 DMI_MATCH(DMI_PRODUCT_NAME, "N130"),
940 DMI_MATCH(DMI_BOARD_NAME, "N130"),
941 },
942 .callback = dmi_check_cb,
943 },
944 {
J Witteveen4e2441c2011-07-03 13:15:44 +0200945 .ident = "N510",
946 .matches = {
947 DMI_MATCH(DMI_SYS_VENDOR,
948 "SAMSUNG ELECTRONICS CO., LTD."),
949 DMI_MATCH(DMI_PRODUCT_NAME, "N510"),
950 DMI_MATCH(DMI_BOARD_NAME, "N510"),
951 },
952 .callback = dmi_check_cb,
953 },
954 {
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500955 .ident = "X125",
956 .matches = {
957 DMI_MATCH(DMI_SYS_VENDOR,
958 "SAMSUNG ELECTRONICS CO., LTD."),
959 DMI_MATCH(DMI_PRODUCT_NAME, "X125"),
960 DMI_MATCH(DMI_BOARD_NAME, "X125"),
961 },
962 .callback = dmi_check_cb,
963 },
964 {
965 .ident = "X120/X170",
966 .matches = {
967 DMI_MATCH(DMI_SYS_VENDOR,
968 "SAMSUNG ELECTRONICS CO., LTD."),
969 DMI_MATCH(DMI_PRODUCT_NAME, "X120/X170"),
970 DMI_MATCH(DMI_BOARD_NAME, "X120/X170"),
971 },
972 .callback = dmi_check_cb,
973 },
974 {
975 .ident = "NC10",
976 .matches = {
977 DMI_MATCH(DMI_SYS_VENDOR,
978 "SAMSUNG ELECTRONICS CO., LTD."),
979 DMI_MATCH(DMI_PRODUCT_NAME, "NC10"),
980 DMI_MATCH(DMI_BOARD_NAME, "NC10"),
981 },
982 .callback = dmi_check_cb,
983 },
984 {
985 .ident = "NP-Q45",
986 .matches = {
987 DMI_MATCH(DMI_SYS_VENDOR,
988 "SAMSUNG ELECTRONICS CO., LTD."),
989 DMI_MATCH(DMI_PRODUCT_NAME, "SQ45S70S"),
990 DMI_MATCH(DMI_BOARD_NAME, "SQ45S70S"),
991 },
992 .callback = dmi_check_cb,
993 },
994 {
995 .ident = "X360",
996 .matches = {
997 DMI_MATCH(DMI_SYS_VENDOR,
998 "SAMSUNG ELECTRONICS CO., LTD."),
999 DMI_MATCH(DMI_PRODUCT_NAME, "X360"),
1000 DMI_MATCH(DMI_BOARD_NAME, "X360"),
1001 },
1002 .callback = dmi_check_cb,
1003 },
1004 {
Alberto Mardegan3d536ed2011-04-08 17:02:03 +02001005 .ident = "R410 Plus",
1006 .matches = {
1007 DMI_MATCH(DMI_SYS_VENDOR,
1008 "SAMSUNG ELECTRONICS CO., LTD."),
1009 DMI_MATCH(DMI_PRODUCT_NAME, "R410P"),
1010 DMI_MATCH(DMI_BOARD_NAME, "R460"),
1011 },
1012 .callback = dmi_check_cb,
1013 },
1014 {
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001015 .ident = "R518",
1016 .matches = {
1017 DMI_MATCH(DMI_SYS_VENDOR,
1018 "SAMSUNG ELECTRONICS CO., LTD."),
1019 DMI_MATCH(DMI_PRODUCT_NAME, "R518"),
1020 DMI_MATCH(DMI_BOARD_NAME, "R518"),
1021 },
1022 .callback = dmi_check_cb,
1023 },
1024 {
1025 .ident = "R519/R719",
1026 .matches = {
1027 DMI_MATCH(DMI_SYS_VENDOR,
1028 "SAMSUNG ELECTRONICS CO., LTD."),
1029 DMI_MATCH(DMI_PRODUCT_NAME, "R519/R719"),
1030 DMI_MATCH(DMI_BOARD_NAME, "R519/R719"),
1031 },
1032 .callback = dmi_check_cb,
1033 },
1034 {
Thomas Courbon78a75392011-07-20 22:57:44 +02001035 .ident = "N150/N210/N220",
1036 .matches = {
1037 DMI_MATCH(DMI_SYS_VENDOR,
1038 "SAMSUNG ELECTRONICS CO., LTD."),
1039 DMI_MATCH(DMI_PRODUCT_NAME, "N150/N210/N220"),
1040 DMI_MATCH(DMI_BOARD_NAME, "N150/N210/N220"),
1041 },
1042 .callback = dmi_check_cb,
1043 },
1044 {
Raul Gutierrez Segalesf689c872011-09-20 09:16:15 -07001045 .ident = "N220",
1046 .matches = {
1047 DMI_MATCH(DMI_SYS_VENDOR,
1048 "SAMSUNG ELECTRONICS CO., LTD."),
1049 DMI_MATCH(DMI_PRODUCT_NAME, "N220"),
1050 DMI_MATCH(DMI_BOARD_NAME, "N220"),
1051 },
1052 .callback = dmi_check_cb,
1053 },
1054 {
Greg Kroah-Hartman10165072011-04-08 17:02:04 +02001055 .ident = "N150/N210/N220/N230",
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001056 .matches = {
1057 DMI_MATCH(DMI_SYS_VENDOR,
1058 "SAMSUNG ELECTRONICS CO., LTD."),
Greg Kroah-Hartman10165072011-04-08 17:02:04 +02001059 DMI_MATCH(DMI_PRODUCT_NAME, "N150/N210/N220/N230"),
1060 DMI_MATCH(DMI_BOARD_NAME, "N150/N210/N220/N230"),
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001061 },
1062 .callback = dmi_check_cb,
1063 },
1064 {
1065 .ident = "N150P/N210P/N220P",
1066 .matches = {
1067 DMI_MATCH(DMI_SYS_VENDOR,
1068 "SAMSUNG ELECTRONICS CO., LTD."),
1069 DMI_MATCH(DMI_PRODUCT_NAME, "N150P/N210P/N220P"),
1070 DMI_MATCH(DMI_BOARD_NAME, "N150P/N210P/N220P"),
1071 },
1072 .callback = dmi_check_cb,
1073 },
1074 {
Stefan Bellerf87d0292011-09-20 09:16:08 -07001075 .ident = "R700",
1076 .matches = {
1077 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1078 DMI_MATCH(DMI_PRODUCT_NAME, "SR700"),
1079 DMI_MATCH(DMI_BOARD_NAME, "SR700"),
1080 },
1081 .callback = dmi_check_cb,
1082 },
1083 {
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001084 .ident = "R530/R730",
1085 .matches = {
1086 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1087 DMI_MATCH(DMI_PRODUCT_NAME, "R530/R730"),
1088 DMI_MATCH(DMI_BOARD_NAME, "R530/R730"),
1089 },
1090 .callback = dmi_check_cb,
1091 },
1092 {
1093 .ident = "NF110/NF210/NF310",
1094 .matches = {
1095 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1096 DMI_MATCH(DMI_PRODUCT_NAME, "NF110/NF210/NF310"),
1097 DMI_MATCH(DMI_BOARD_NAME, "NF110/NF210/NF310"),
1098 },
1099 .callback = dmi_check_cb,
1100 },
1101 {
1102 .ident = "N145P/N250P/N260P",
1103 .matches = {
1104 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1105 DMI_MATCH(DMI_PRODUCT_NAME, "N145P/N250P/N260P"),
1106 DMI_MATCH(DMI_BOARD_NAME, "N145P/N250P/N260P"),
1107 },
1108 .callback = dmi_check_cb,
1109 },
1110 {
1111 .ident = "R70/R71",
1112 .matches = {
1113 DMI_MATCH(DMI_SYS_VENDOR,
1114 "SAMSUNG ELECTRONICS CO., LTD."),
1115 DMI_MATCH(DMI_PRODUCT_NAME, "R70/R71"),
1116 DMI_MATCH(DMI_BOARD_NAME, "R70/R71"),
1117 },
1118 .callback = dmi_check_cb,
1119 },
1120 {
1121 .ident = "P460",
1122 .matches = {
1123 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1124 DMI_MATCH(DMI_PRODUCT_NAME, "P460"),
1125 DMI_MATCH(DMI_BOARD_NAME, "P460"),
1126 },
1127 .callback = dmi_check_cb,
1128 },
Smelov Andrey093ed562011-09-20 09:16:10 -07001129 {
1130 .ident = "R528/R728",
1131 .matches = {
1132 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1133 DMI_MATCH(DMI_PRODUCT_NAME, "R528/R728"),
1134 DMI_MATCH(DMI_BOARD_NAME, "R528/R728"),
1135 },
1136 .callback = dmi_check_cb,
1137 },
Jason Stubbs7b3c2572011-09-20 09:16:14 -07001138 {
1139 .ident = "NC210/NC110",
1140 .matches = {
1141 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1142 DMI_MATCH(DMI_PRODUCT_NAME, "NC210/NC110"),
1143 DMI_MATCH(DMI_BOARD_NAME, "NC210/NC110"),
1144 },
1145 .callback = dmi_check_cb,
1146 },
Tommaso Massimi7500eeb2011-09-20 09:16:09 -07001147 {
1148 .ident = "X520",
1149 .matches = {
1150 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1151 DMI_MATCH(DMI_PRODUCT_NAME, "X520"),
1152 DMI_MATCH(DMI_BOARD_NAME, "X520"),
1153 },
1154 .callback = dmi_check_cb,
1155 },
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001156 { },
1157};
1158MODULE_DEVICE_TABLE(dmi, samsung_dmi_table);
1159
Corentin Chary5dea7a22011-11-26 10:59:59 +01001160static struct platform_device *samsung_platform_device;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001161
1162static int __init samsung_init(void)
1163{
Corentin Chary5dea7a22011-11-26 10:59:59 +01001164 struct samsung_laptop *samsung;
1165 int ret;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001166
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001167 if (!force && !dmi_check_system(samsung_dmi_table))
1168 return -ENODEV;
1169
Corentin Charya6df4892011-11-26 10:59:58 +01001170 samsung = kzalloc(sizeof(*samsung), GFP_KERNEL);
1171 if (!samsung)
1172 return -ENOMEM;
1173
1174 mutex_init(&samsung->sabi_mutex);
Corentin Charyf34cd9c2011-11-26 11:00:00 +01001175 samsung->handle_backlight = true;
1176
1177#ifdef CONFIG_ACPI
1178 /* Don't handle backlight here if the acpi video already handle it */
1179 if (acpi_video_backlight_support()) {
1180 pr_info("Backlight controlled by ACPI video driver\n");
1181 samsung->handle_backlight = false;
1182 }
1183#endif
Corentin Charya6df4892011-11-26 10:59:58 +01001184
Corentin Chary5dea7a22011-11-26 10:59:59 +01001185 ret = samsung_platform_init(samsung);
1186 if (ret)
1187 goto error_platform;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001188
Corentin Chary5dea7a22011-11-26 10:59:59 +01001189 ret = samsung_sabi_init(samsung);
1190 if (ret)
1191 goto error_sabi;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001192
Corentin Chary5dea7a22011-11-26 10:59:59 +01001193 ret = samsung_sysfs_init(samsung);
1194 if (ret)
1195 goto error_sysfs;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001196
Corentin Chary5dea7a22011-11-26 10:59:59 +01001197 ret = samsung_backlight_init(samsung);
1198 if (ret)
1199 goto error_backlight;
Corentin Charya6df4892011-11-26 10:59:58 +01001200
Corentin Chary5dea7a22011-11-26 10:59:59 +01001201 ret = samsung_rfkill_init(samsung);
1202 if (ret)
1203 goto error_rfkill;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001204
Corentin Chary5b80fc42011-11-26 11:00:03 +01001205 ret = samsung_debugfs_init(samsung);
1206 if (ret)
1207 goto error_debugfs;
1208
Corentin Chary5dea7a22011-11-26 10:59:59 +01001209 samsung_platform_device = samsung->platform_device;
1210 return ret;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001211
Corentin Chary5b80fc42011-11-26 11:00:03 +01001212error_debugfs:
1213 samsung_rfkill_exit(samsung);
Corentin Chary5dea7a22011-11-26 10:59:59 +01001214error_rfkill:
1215 samsung_backlight_exit(samsung);
1216error_backlight:
1217 samsung_sysfs_exit(samsung);
1218error_sysfs:
1219 samsung_sabi_exit(samsung);
1220error_sabi:
1221 samsung_platform_exit(samsung);
1222error_platform:
Corentin Charya6df4892011-11-26 10:59:58 +01001223 kfree(samsung);
Corentin Chary5dea7a22011-11-26 10:59:59 +01001224 return ret;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001225}
1226
1227static void __exit samsung_exit(void)
1228{
Corentin Chary5dea7a22011-11-26 10:59:59 +01001229 struct samsung_laptop *samsung;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001230
Corentin Chary5dea7a22011-11-26 10:59:59 +01001231 samsung = platform_get_drvdata(samsung_platform_device);
Corentin Charya6df4892011-11-26 10:59:58 +01001232
Corentin Chary5b80fc42011-11-26 11:00:03 +01001233 samsung_debugfs_exit(samsung);
Corentin Chary5dea7a22011-11-26 10:59:59 +01001234 samsung_rfkill_exit(samsung);
1235 samsung_backlight_exit(samsung);
1236 samsung_sysfs_exit(samsung);
1237 samsung_sabi_exit(samsung);
1238 samsung_platform_exit(samsung);
1239
Corentin Charya6df4892011-11-26 10:59:58 +01001240 kfree(samsung);
Corentin Chary5dea7a22011-11-26 10:59:59 +01001241 samsung_platform_device = NULL;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001242}
1243
1244module_init(samsung_init);
1245module_exit(samsung_exit);
1246
1247MODULE_AUTHOR("Greg Kroah-Hartman <gregkh@suse.de>");
1248MODULE_DESCRIPTION("Samsung Backlight driver");
1249MODULE_LICENSE("GPL");