blob: 9fbf5c0d364633814bb689b4e0aee650bbd9ddf6 [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>
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -050025
26/*
27 * This driver is needed because a number of Samsung laptops do not hook
28 * their control settings through ACPI. So we have to poke around in the
29 * BIOS to do things like brightness values, and "special" key controls.
30 */
31
32/*
33 * We have 0 - 8 as valid brightness levels. The specs say that level 0 should
34 * be reserved by the BIOS (which really doesn't make much sense), we tell
35 * userspace that the value is 0 - 7 and then just tell the hardware 1 - 8
36 */
37#define MAX_BRIGHT 0x07
38
39
40#define SABI_IFACE_MAIN 0x00
41#define SABI_IFACE_SUB 0x02
42#define SABI_IFACE_COMPLETE 0x04
43#define SABI_IFACE_DATA 0x05
44
45/* Structure to get data back to the calling function */
46struct sabi_retval {
47 u8 retval[20];
48};
49
50struct sabi_header_offsets {
51 u8 port;
52 u8 re_mem;
53 u8 iface_func;
54 u8 en_mem;
55 u8 data_offset;
56 u8 data_segment;
57};
58
59struct sabi_commands {
60 /*
61 * Brightness is 0 - 8, as described above.
62 * Value 0 is for the BIOS to use
63 */
64 u8 get_brightness;
65 u8 set_brightness;
66
67 /*
68 * first byte:
69 * 0x00 - wireless is off
70 * 0x01 - wireless is on
71 * second byte:
72 * 0x02 - 3G is off
73 * 0x03 - 3G is on
74 * TODO, verify 3G is correct, that doesn't seem right...
75 */
76 u8 get_wireless_button;
77 u8 set_wireless_button;
78
79 /* 0 is off, 1 is on */
80 u8 get_backlight;
81 u8 set_backlight;
82
83 /*
84 * 0x80 or 0x00 - no action
85 * 0x81 - recovery key pressed
86 */
87 u8 get_recovery_mode;
88 u8 set_recovery_mode;
89
90 /*
91 * on seclinux: 0 is low, 1 is high,
92 * on swsmi: 0 is normal, 1 is silent, 2 is turbo
93 */
94 u8 get_performance_level;
95 u8 set_performance_level;
96
97 /*
98 * Tell the BIOS that Linux is running on this machine.
99 * 81 is on, 80 is off
100 */
101 u8 set_linux;
102};
103
104struct sabi_performance_level {
105 const char *name;
106 u8 value;
107};
108
109struct sabi_config {
110 const char *test_string;
111 u16 main_function;
112 const struct sabi_header_offsets header_offsets;
113 const struct sabi_commands commands;
114 const struct sabi_performance_level performance_levels[4];
115 u8 min_brightness;
116 u8 max_brightness;
117};
118
119static const struct sabi_config sabi_configs[] = {
120 {
121 .test_string = "SECLINUX",
122
123 .main_function = 0x4c49,
124
125 .header_offsets = {
126 .port = 0x00,
127 .re_mem = 0x02,
128 .iface_func = 0x03,
129 .en_mem = 0x04,
130 .data_offset = 0x05,
131 .data_segment = 0x07,
132 },
133
134 .commands = {
135 .get_brightness = 0x00,
136 .set_brightness = 0x01,
137
138 .get_wireless_button = 0x02,
139 .set_wireless_button = 0x03,
140
141 .get_backlight = 0x04,
142 .set_backlight = 0x05,
143
144 .get_recovery_mode = 0x06,
145 .set_recovery_mode = 0x07,
146
147 .get_performance_level = 0x08,
148 .set_performance_level = 0x09,
149
150 .set_linux = 0x0a,
151 },
152
153 .performance_levels = {
154 {
155 .name = "silent",
156 .value = 0,
157 },
158 {
159 .name = "normal",
160 .value = 1,
161 },
162 { },
163 },
164 .min_brightness = 1,
165 .max_brightness = 8,
166 },
167 {
168 .test_string = "SwSmi@",
169
170 .main_function = 0x5843,
171
172 .header_offsets = {
173 .port = 0x00,
174 .re_mem = 0x04,
175 .iface_func = 0x02,
176 .en_mem = 0x03,
177 .data_offset = 0x05,
178 .data_segment = 0x07,
179 },
180
181 .commands = {
182 .get_brightness = 0x10,
183 .set_brightness = 0x11,
184
185 .get_wireless_button = 0x12,
186 .set_wireless_button = 0x13,
187
188 .get_backlight = 0x2d,
189 .set_backlight = 0x2e,
190
191 .get_recovery_mode = 0xff,
192 .set_recovery_mode = 0xff,
193
194 .get_performance_level = 0x31,
195 .set_performance_level = 0x32,
196
197 .set_linux = 0xff,
198 },
199
200 .performance_levels = {
201 {
202 .name = "normal",
203 .value = 0,
204 },
205 {
206 .name = "silent",
207 .value = 1,
208 },
209 {
210 .name = "overclock",
211 .value = 2,
212 },
213 { },
214 },
215 .min_brightness = 0,
216 .max_brightness = 8,
217 },
218 { },
219};
220
Corentin Charya6df4892011-11-26 10:59:58 +0100221struct samsung_laptop {
222 const struct sabi_config *config;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500223
Corentin Charya6df4892011-11-26 10:59:58 +0100224 void __iomem *sabi;
225 void __iomem *sabi_iface;
226 void __iomem *f0000_segment;
227
228 struct mutex sabi_mutex;
229
Corentin Chary5dea7a22011-11-26 10:59:59 +0100230 struct platform_device *platform_device;
Corentin Charya6df4892011-11-26 10:59:58 +0100231 struct backlight_device *backlight_device;
232 struct rfkill *rfk;
233
Corentin Charyf34cd9c2011-11-26 11:00:00 +0100234 bool handle_backlight;
Corentin Charya6df4892011-11-26 10:59:58 +0100235 bool has_stepping_quirk;
236};
237
Corentin Chary5dea7a22011-11-26 10:59:59 +0100238
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500239
Rusty Russell90ab5ee2012-01-13 09:32:20 +1030240static bool force;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500241module_param(force, bool, 0);
242MODULE_PARM_DESC(force,
243 "Disable the DMI check and forces the driver to be loaded");
244
Rusty Russell90ab5ee2012-01-13 09:32:20 +1030245static bool debug;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500246module_param(debug, bool, S_IRUGO | S_IWUSR);
247MODULE_PARM_DESC(debug, "Debug enabled or not");
248
Corentin Chary5dea7a22011-11-26 10:59:59 +0100249static int sabi_get_command(struct samsung_laptop *samsung,
250 u8 command, struct sabi_retval *sretval)
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500251{
Corentin Charya6df4892011-11-26 10:59:58 +0100252 const struct sabi_config *config = samsung->config;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500253 int retval = 0;
Corentin Charya6df4892011-11-26 10:59:58 +0100254 u16 port = readw(samsung->sabi + config->header_offsets.port);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500255 u8 complete, iface_data;
256
Corentin Charya6df4892011-11-26 10:59:58 +0100257 mutex_lock(&samsung->sabi_mutex);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500258
259 /* enable memory to be able to write to it */
Corentin Charya6df4892011-11-26 10:59:58 +0100260 outb(readb(samsung->sabi + config->header_offsets.en_mem), port);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500261
262 /* write out the command */
Corentin Charya6df4892011-11-26 10:59:58 +0100263 writew(config->main_function, samsung->sabi_iface + SABI_IFACE_MAIN);
264 writew(command, samsung->sabi_iface + SABI_IFACE_SUB);
265 writeb(0, samsung->sabi_iface + SABI_IFACE_COMPLETE);
266 outb(readb(samsung->sabi + config->header_offsets.iface_func), port);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500267
268 /* write protect memory to make it safe */
Corentin Charya6df4892011-11-26 10:59:58 +0100269 outb(readb(samsung->sabi + config->header_offsets.re_mem), port);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500270
271 /* see if the command actually succeeded */
Corentin Charya6df4892011-11-26 10:59:58 +0100272 complete = readb(samsung->sabi_iface + SABI_IFACE_COMPLETE);
273 iface_data = readb(samsung->sabi_iface + SABI_IFACE_DATA);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500274 if (complete != 0xaa || iface_data == 0xff) {
275 pr_warn("SABI get command 0x%02x failed with completion flag 0x%02x and data 0x%02x\n",
276 command, complete, iface_data);
277 retval = -EINVAL;
278 goto exit;
279 }
280 /*
281 * Save off the data into a structure so the caller use it.
282 * Right now we only want the first 4 bytes,
283 * There are commands that need more, but not for the ones we
284 * currently care about.
285 */
Corentin Charya6df4892011-11-26 10:59:58 +0100286 sretval->retval[0] = readb(samsung->sabi_iface + SABI_IFACE_DATA);
287 sretval->retval[1] = readb(samsung->sabi_iface + SABI_IFACE_DATA + 1);
288 sretval->retval[2] = readb(samsung->sabi_iface + SABI_IFACE_DATA + 2);
289 sretval->retval[3] = readb(samsung->sabi_iface + SABI_IFACE_DATA + 3);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500290
291exit:
Corentin Charya6df4892011-11-26 10:59:58 +0100292 mutex_unlock(&samsung->sabi_mutex);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500293 return retval;
294
295}
296
Corentin Chary5dea7a22011-11-26 10:59:59 +0100297static int sabi_set_command(struct samsung_laptop *samsung,
298 u8 command, u8 data)
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500299{
Corentin Charya6df4892011-11-26 10:59:58 +0100300 const struct sabi_config *config = samsung->config;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500301 int retval = 0;
Corentin Charya6df4892011-11-26 10:59:58 +0100302 u16 port = readw(samsung->sabi + config->header_offsets.port);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500303 u8 complete, iface_data;
304
Corentin Charya6df4892011-11-26 10:59:58 +0100305 mutex_lock(&samsung->sabi_mutex);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500306
307 /* enable memory to be able to write to it */
Corentin Charya6df4892011-11-26 10:59:58 +0100308 outb(readb(samsung->sabi + config->header_offsets.en_mem), port);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500309
310 /* write out the command */
Corentin Charya6df4892011-11-26 10:59:58 +0100311 writew(config->main_function, samsung->sabi_iface + SABI_IFACE_MAIN);
312 writew(command, samsung->sabi_iface + SABI_IFACE_SUB);
313 writeb(0, samsung->sabi_iface + SABI_IFACE_COMPLETE);
314 writeb(data, samsung->sabi_iface + SABI_IFACE_DATA);
315 outb(readb(samsung->sabi + config->header_offsets.iface_func), port);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500316
317 /* write protect memory to make it safe */
Corentin Charya6df4892011-11-26 10:59:58 +0100318 outb(readb(samsung->sabi + config->header_offsets.re_mem), port);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500319
320 /* see if the command actually succeeded */
Corentin Charya6df4892011-11-26 10:59:58 +0100321 complete = readb(samsung->sabi_iface + SABI_IFACE_COMPLETE);
322 iface_data = readb(samsung->sabi_iface + SABI_IFACE_DATA);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500323 if (complete != 0xaa || iface_data == 0xff) {
324 pr_warn("SABI set command 0x%02x failed with completion flag 0x%02x and data 0x%02x\n",
325 command, complete, iface_data);
326 retval = -EINVAL;
327 }
328
Corentin Charya6df4892011-11-26 10:59:58 +0100329 mutex_unlock(&samsung->sabi_mutex);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500330 return retval;
331}
332
Corentin Chary5dea7a22011-11-26 10:59:59 +0100333static void test_backlight(struct samsung_laptop *samsung)
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500334{
Corentin Charya6df4892011-11-26 10:59:58 +0100335 const struct sabi_commands *commands = &samsung->config->commands;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500336 struct sabi_retval sretval;
337
Corentin Chary5dea7a22011-11-26 10:59:59 +0100338 sabi_get_command(samsung, commands->get_backlight, &sretval);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500339 printk(KERN_DEBUG "backlight = 0x%02x\n", sretval.retval[0]);
340
Corentin Chary5dea7a22011-11-26 10:59:59 +0100341 sabi_set_command(samsung, commands->set_backlight, 0);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500342 printk(KERN_DEBUG "backlight should be off\n");
343
Corentin Chary5dea7a22011-11-26 10:59:59 +0100344 sabi_get_command(samsung, commands->get_backlight, &sretval);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500345 printk(KERN_DEBUG "backlight = 0x%02x\n", sretval.retval[0]);
346
347 msleep(1000);
348
Corentin Chary5dea7a22011-11-26 10:59:59 +0100349 sabi_set_command(samsung, commands->set_backlight, 1);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500350 printk(KERN_DEBUG "backlight should be on\n");
351
Corentin Chary5dea7a22011-11-26 10:59:59 +0100352 sabi_get_command(samsung, commands->get_backlight, &sretval);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500353 printk(KERN_DEBUG "backlight = 0x%02x\n", sretval.retval[0]);
354}
355
Corentin Chary5dea7a22011-11-26 10:59:59 +0100356static void test_wireless(struct samsung_laptop *samsung)
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500357{
Corentin Charya6df4892011-11-26 10:59:58 +0100358 const struct sabi_commands *commands = &samsung->config->commands;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500359 struct sabi_retval sretval;
360
Corentin Chary5dea7a22011-11-26 10:59:59 +0100361 sabi_get_command(samsung, commands->get_wireless_button, &sretval);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500362 printk(KERN_DEBUG "wireless led = 0x%02x\n", sretval.retval[0]);
363
Corentin Chary5dea7a22011-11-26 10:59:59 +0100364 sabi_set_command(samsung, commands->set_wireless_button, 0);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500365 printk(KERN_DEBUG "wireless led should be off\n");
366
Corentin Chary5dea7a22011-11-26 10:59:59 +0100367 sabi_get_command(samsung, commands->get_wireless_button, &sretval);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500368 printk(KERN_DEBUG "wireless led = 0x%02x\n", sretval.retval[0]);
369
370 msleep(1000);
371
Corentin Chary5dea7a22011-11-26 10:59:59 +0100372 sabi_set_command(samsung, commands->set_wireless_button, 1);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500373 printk(KERN_DEBUG "wireless led should be on\n");
374
Corentin Chary5dea7a22011-11-26 10:59:59 +0100375 sabi_get_command(samsung, commands->get_wireless_button, &sretval);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500376 printk(KERN_DEBUG "wireless led = 0x%02x\n", sretval.retval[0]);
377}
378
Corentin Chary5dea7a22011-11-26 10:59:59 +0100379static int read_brightness(struct samsung_laptop *samsung)
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500380{
Corentin Charya6df4892011-11-26 10:59:58 +0100381 const struct sabi_config *config = samsung->config;
382 const struct sabi_commands *commands = &samsung->config->commands;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500383 struct sabi_retval sretval;
384 int user_brightness = 0;
385 int retval;
386
Corentin Chary5dea7a22011-11-26 10:59:59 +0100387 retval = sabi_get_command(samsung, commands->get_brightness,
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500388 &sretval);
389 if (!retval) {
390 user_brightness = sretval.retval[0];
Corentin Charya6df4892011-11-26 10:59:58 +0100391 if (user_brightness > config->min_brightness)
392 user_brightness -= config->min_brightness;
Jason Stubbsbee460b2011-09-20 09:16:11 -0700393 else
394 user_brightness = 0;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500395 }
396 return user_brightness;
397}
398
Corentin Chary5dea7a22011-11-26 10:59:59 +0100399static void set_brightness(struct samsung_laptop *samsung, u8 user_brightness)
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500400{
Corentin Charya6df4892011-11-26 10:59:58 +0100401 const struct sabi_config *config = samsung->config;
402 const struct sabi_commands *commands = &samsung->config->commands;
403 u8 user_level = user_brightness + config->min_brightness;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500404
Corentin Charya6df4892011-11-26 10:59:58 +0100405 if (samsung->has_stepping_quirk && user_level != 0) {
Jason Stubbsac080522011-09-20 09:16:13 -0700406 /*
407 * short circuit if the specified level is what's already set
408 * to prevent the screen from flickering needlessly
409 */
Corentin Chary5dea7a22011-11-26 10:59:59 +0100410 if (user_brightness == read_brightness(samsung))
Jason Stubbsac080522011-09-20 09:16:13 -0700411 return;
412
Corentin Chary5dea7a22011-11-26 10:59:59 +0100413 sabi_set_command(samsung, commands->set_brightness, 0);
Jason Stubbsac080522011-09-20 09:16:13 -0700414 }
415
Corentin Chary5dea7a22011-11-26 10:59:59 +0100416 sabi_set_command(samsung, commands->set_brightness, user_level);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500417}
418
419static int get_brightness(struct backlight_device *bd)
420{
Corentin Chary5dea7a22011-11-26 10:59:59 +0100421 struct samsung_laptop *samsung = bl_get_data(bd);
422
423 return read_brightness(samsung);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500424}
425
Corentin Chary5dea7a22011-11-26 10:59:59 +0100426static void check_for_stepping_quirk(struct samsung_laptop *samsung)
Jason Stubbsac080522011-09-20 09:16:13 -0700427{
Corentin Chary5dea7a22011-11-26 10:59:59 +0100428 int initial_level;
429 int check_level;
430 int orig_level = read_brightness(samsung);
Jason Stubbsac080522011-09-20 09:16:13 -0700431
432 /*
433 * Some laptops exhibit the strange behaviour of stepping toward
434 * (rather than setting) the brightness except when changing to/from
435 * brightness level 0. This behaviour is checked for here and worked
436 * around in set_brightness.
437 */
438
John Serockba05b232011-10-13 06:42:01 -0400439 if (orig_level == 0)
Corentin Chary5dea7a22011-11-26 10:59:59 +0100440 set_brightness(samsung, 1);
John Serockba05b232011-10-13 06:42:01 -0400441
Corentin Chary5dea7a22011-11-26 10:59:59 +0100442 initial_level = read_brightness(samsung);
John Serockba05b232011-10-13 06:42:01 -0400443
Jason Stubbsac080522011-09-20 09:16:13 -0700444 if (initial_level <= 2)
445 check_level = initial_level + 2;
446 else
447 check_level = initial_level - 2;
448
Corentin Charya6df4892011-11-26 10:59:58 +0100449 samsung->has_stepping_quirk = false;
Corentin Chary5dea7a22011-11-26 10:59:59 +0100450 set_brightness(samsung, check_level);
Jason Stubbsac080522011-09-20 09:16:13 -0700451
Corentin Chary5dea7a22011-11-26 10:59:59 +0100452 if (read_brightness(samsung) != check_level) {
Corentin Charya6df4892011-11-26 10:59:58 +0100453 samsung->has_stepping_quirk = true;
Jason Stubbsac080522011-09-20 09:16:13 -0700454 pr_info("enabled workaround for brightness stepping quirk\n");
455 }
456
Corentin Chary5dea7a22011-11-26 10:59:59 +0100457 set_brightness(samsung, orig_level);
Jason Stubbsac080522011-09-20 09:16:13 -0700458}
459
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500460static int update_status(struct backlight_device *bd)
461{
Corentin Chary5dea7a22011-11-26 10:59:59 +0100462 struct samsung_laptop *samsung = bl_get_data(bd);
Corentin Charya6df4892011-11-26 10:59:58 +0100463 const struct sabi_commands *commands = &samsung->config->commands;
464
Corentin Chary5dea7a22011-11-26 10:59:59 +0100465 set_brightness(samsung, bd->props.brightness);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500466
467 if (bd->props.power == FB_BLANK_UNBLANK)
Corentin Chary5dea7a22011-11-26 10:59:59 +0100468 sabi_set_command(samsung, commands->set_backlight, 1);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500469 else
Corentin Chary5dea7a22011-11-26 10:59:59 +0100470 sabi_set_command(samsung, commands->set_backlight, 0);
471
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500472 return 0;
473}
474
475static const struct backlight_ops backlight_ops = {
476 .get_brightness = get_brightness,
477 .update_status = update_status,
478};
479
480static int rfkill_set(void *data, bool blocked)
481{
Corentin Chary5dea7a22011-11-26 10:59:59 +0100482 struct samsung_laptop *samsung = data;
Corentin Charya6df4892011-11-26 10:59:58 +0100483 const struct sabi_commands *commands = &samsung->config->commands;
484
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500485 /* Do something with blocked...*/
486 /*
487 * blocked == false is on
488 * blocked == true is off
489 */
490 if (blocked)
Corentin Chary5dea7a22011-11-26 10:59:59 +0100491 sabi_set_command(samsung, commands->set_wireless_button, 0);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500492 else
Corentin Chary5dea7a22011-11-26 10:59:59 +0100493 sabi_set_command(samsung, commands->set_wireless_button, 1);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500494
495 return 0;
496}
497
498static struct rfkill_ops rfkill_ops = {
499 .set_block = rfkill_set,
500};
501
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500502static ssize_t get_performance_level(struct device *dev,
503 struct device_attribute *attr, char *buf)
504{
Corentin Chary5dea7a22011-11-26 10:59:59 +0100505 struct samsung_laptop *samsung = dev_get_drvdata(dev);
Corentin Charya6df4892011-11-26 10:59:58 +0100506 const struct sabi_config *config = samsung->config;
Corentin Chary5dea7a22011-11-26 10:59:59 +0100507 const struct sabi_commands *commands = &config->commands;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500508 struct sabi_retval sretval;
509 int retval;
510 int i;
511
512 /* Read the state */
Corentin Chary5dea7a22011-11-26 10:59:59 +0100513 retval = sabi_get_command(samsung, commands->get_performance_level,
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500514 &sretval);
515 if (retval)
516 return retval;
517
518 /* The logic is backwards, yeah, lots of fun... */
Corentin Charya6df4892011-11-26 10:59:58 +0100519 for (i = 0; config->performance_levels[i].name; ++i) {
520 if (sretval.retval[0] == config->performance_levels[i].value)
521 return sprintf(buf, "%s\n", config->performance_levels[i].name);
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500522 }
523 return sprintf(buf, "%s\n", "unknown");
524}
525
526static ssize_t set_performance_level(struct device *dev,
527 struct device_attribute *attr, const char *buf,
528 size_t count)
529{
Corentin Chary5dea7a22011-11-26 10:59:59 +0100530 struct samsung_laptop *samsung = dev_get_drvdata(dev);
Corentin Charya6df4892011-11-26 10:59:58 +0100531 const struct sabi_config *config = samsung->config;
Corentin Chary5dea7a22011-11-26 10:59:59 +0100532 const struct sabi_commands *commands = &config->commands;
533 int i;
Corentin Charya6df4892011-11-26 10:59:58 +0100534
Corentin Chary5dea7a22011-11-26 10:59:59 +0100535 if (count < 1)
536 return count;
537
538 for (i = 0; config->performance_levels[i].name; ++i) {
539 const struct sabi_performance_level *level =
540 &config->performance_levels[i];
541 if (!strncasecmp(level->name, buf, strlen(level->name))) {
542 sabi_set_command(samsung,
543 commands->set_performance_level,
544 level->value);
545 break;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500546 }
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500547 }
Corentin Chary5dea7a22011-11-26 10:59:59 +0100548
549 if (!config->performance_levels[i].name)
550 return -EINVAL;
551
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500552 return count;
553}
Corentin Chary5dea7a22011-11-26 10:59:59 +0100554
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500555static DEVICE_ATTR(performance_level, S_IWUSR | S_IRUGO,
556 get_performance_level, set_performance_level);
557
Corentin Charya66c1662011-11-26 11:00:01 +0100558static struct attribute *platform_attributes[] = {
559 &dev_attr_performance_level.attr,
560 NULL
561};
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500562
Corentin Chary5dea7a22011-11-26 10:59:59 +0100563static int find_signature(void __iomem *memcheck, const char *testStr)
564{
565 int i = 0;
566 int loca;
567
568 for (loca = 0; loca < 0xffff; loca++) {
569 char temp = readb(memcheck + loca);
570
571 if (temp == testStr[i]) {
572 if (i == strlen(testStr)-1)
573 break;
574 ++i;
575 } else {
576 i = 0;
577 }
578 }
579 return loca;
580}
581
582static void samsung_rfkill_exit(struct samsung_laptop *samsung)
583{
584 if (samsung->rfk) {
585 rfkill_unregister(samsung->rfk);
586 rfkill_destroy(samsung->rfk);
587 samsung->rfk = NULL;
588 }
589}
590
591static int __init samsung_rfkill_init(struct samsung_laptop *samsung)
592{
593 int retval;
594
595 samsung->rfk = rfkill_alloc("samsung-wifi",
596 &samsung->platform_device->dev,
597 RFKILL_TYPE_WLAN,
598 &rfkill_ops, samsung);
599 if (!samsung->rfk)
600 return -ENOMEM;
601
602 retval = rfkill_register(samsung->rfk);
603 if (retval) {
604 rfkill_destroy(samsung->rfk);
605 samsung->rfk = NULL;
606 return -ENODEV;
607 }
608
609 return 0;
610}
611
612static void samsung_backlight_exit(struct samsung_laptop *samsung)
613{
614 if (samsung->backlight_device) {
615 backlight_device_unregister(samsung->backlight_device);
616 samsung->backlight_device = NULL;
617 }
618}
619
620static int __init samsung_backlight_init(struct samsung_laptop *samsung)
621{
622 struct backlight_device *bd;
623 struct backlight_properties props;
624
Corentin Charyf34cd9c2011-11-26 11:00:00 +0100625 if (!samsung->handle_backlight)
626 return 0;
627
Corentin Chary5dea7a22011-11-26 10:59:59 +0100628 memset(&props, 0, sizeof(struct backlight_properties));
629 props.type = BACKLIGHT_PLATFORM;
630 props.max_brightness = samsung->config->max_brightness -
631 samsung->config->min_brightness;
632
633 bd = backlight_device_register("samsung",
634 &samsung->platform_device->dev,
635 samsung, &backlight_ops,
636 &props);
637 if (IS_ERR(bd))
638 return PTR_ERR(bd);
639
640 samsung->backlight_device = bd;
641 samsung->backlight_device->props.brightness = read_brightness(samsung);
642 samsung->backlight_device->props.power = FB_BLANK_UNBLANK;
643 backlight_update_status(samsung->backlight_device);
644
645 return 0;
646}
647
Corentin Charya66c1662011-11-26 11:00:01 +0100648static mode_t samsung_sysfs_is_visible(struct kobject *kobj,
649 struct attribute *attr, int idx)
650{
651 struct device *dev = container_of(kobj, struct device, kobj);
652 struct platform_device *pdev = to_platform_device(dev);
653 struct samsung_laptop *samsung = platform_get_drvdata(pdev);
654 bool ok = true;
655
656 if (attr == &dev_attr_performance_level.attr)
657 ok = !!samsung->config->performance_levels[0].name;
658
659 return ok ? attr->mode : 0;
660}
661
662static struct attribute_group platform_attribute_group = {
663 .is_visible = samsung_sysfs_is_visible,
664 .attrs = platform_attributes
665};
666
Corentin Chary5dea7a22011-11-26 10:59:59 +0100667static void samsung_sysfs_exit(struct samsung_laptop *samsung)
668{
Corentin Charya66c1662011-11-26 11:00:01 +0100669 struct platform_device *device = samsung->platform_device;
670
671 sysfs_remove_group(&device->dev.kobj, &platform_attribute_group);
Corentin Chary5dea7a22011-11-26 10:59:59 +0100672}
673
674static int __init samsung_sysfs_init(struct samsung_laptop *samsung)
675{
Corentin Charya66c1662011-11-26 11:00:01 +0100676 struct platform_device *device = samsung->platform_device;
677
678 return sysfs_create_group(&device->dev.kobj, &platform_attribute_group);
679
Corentin Chary5dea7a22011-11-26 10:59:59 +0100680}
681
682static void samsung_sabi_exit(struct samsung_laptop *samsung)
683{
684 const struct sabi_config *config = samsung->config;
685
686 /* Turn off "Linux" mode in the BIOS */
687 if (config && config->commands.set_linux != 0xff)
688 sabi_set_command(samsung, config->commands.set_linux, 0x80);
689
690 if (samsung->sabi_iface) {
691 iounmap(samsung->sabi_iface);
692 samsung->sabi_iface = NULL;
693 }
694 if (samsung->f0000_segment) {
695 iounmap(samsung->f0000_segment);
696 samsung->f0000_segment = NULL;
697 }
698
699 samsung->config = NULL;
700}
701
702static __init void samsung_sabi_infos(struct samsung_laptop *samsung, int loca)
703{
704 const struct sabi_config *config = samsung->config;
705
706 printk(KERN_DEBUG "This computer supports SABI==%x\n",
707 loca + 0xf0000 - 6);
708 printk(KERN_DEBUG "SABI header:\n");
709 printk(KERN_DEBUG " SMI Port Number = 0x%04x\n",
710 readw(samsung->sabi + config->header_offsets.port));
711 printk(KERN_DEBUG " SMI Interface Function = 0x%02x\n",
712 readb(samsung->sabi + config->header_offsets.iface_func));
713 printk(KERN_DEBUG " SMI enable memory buffer = 0x%02x\n",
714 readb(samsung->sabi + config->header_offsets.en_mem));
715 printk(KERN_DEBUG " SMI restore memory buffer = 0x%02x\n",
716 readb(samsung->sabi + config->header_offsets.re_mem));
717 printk(KERN_DEBUG " SABI data offset = 0x%04x\n",
718 readw(samsung->sabi + config->header_offsets.data_offset));
719 printk(KERN_DEBUG " SABI data segment = 0x%04x\n",
720 readw(samsung->sabi + config->header_offsets.data_segment));
721}
722
723static void __init samsung_sabi_selftest(struct samsung_laptop *samsung,
724 unsigned int ifaceP)
725{
726 const struct sabi_config *config = samsung->config;
727 struct sabi_retval sretval;
728
729 printk(KERN_DEBUG "ifaceP = 0x%08x\n", ifaceP);
730 printk(KERN_DEBUG "sabi_iface = %p\n", samsung->sabi_iface);
731
Corentin Charyf34cd9c2011-11-26 11:00:00 +0100732 if (samsung->handle_backlight)
733 test_backlight(samsung);
Corentin Chary5dea7a22011-11-26 10:59:59 +0100734 test_wireless(samsung);
735
736 sabi_get_command(samsung, config->commands.get_brightness, &sretval);
737 printk(KERN_DEBUG "brightness = 0x%02x\n", sretval.retval[0]);
738}
739
740static int __init samsung_sabi_init(struct samsung_laptop *samsung)
741{
742 const struct sabi_config *config = NULL;
743 const struct sabi_commands *commands;
744 unsigned int ifaceP;
745 int ret = 0;
746 int i;
747 int loca;
748
749 samsung->f0000_segment = ioremap_nocache(0xf0000, 0xffff);
750 if (!samsung->f0000_segment) {
751 pr_err("Can't map the segment at 0xf0000\n");
752 ret = -EINVAL;
753 goto exit;
754 }
755
756 /* Try to find one of the signatures in memory to find the header */
757 for (i = 0; sabi_configs[i].test_string != 0; ++i) {
758 samsung->config = &sabi_configs[i];
759 loca = find_signature(samsung->f0000_segment,
760 samsung->config->test_string);
761 if (loca != 0xffff)
762 break;
763 }
764
765 if (loca == 0xffff) {
766 pr_err("This computer does not support SABI\n");
767 ret = -ENODEV;
768 goto exit;
769 }
770
771 config = samsung->config;
772 commands = &config->commands;
773
774 /* point to the SMI port Number */
775 loca += 1;
776 samsung->sabi = (samsung->f0000_segment + loca);
777
778 if (debug)
779 samsung_sabi_infos(samsung, loca);
780
781 /* Get a pointer to the SABI Interface */
782 ifaceP = (readw(samsung->sabi + config->header_offsets.data_segment) & 0x0ffff) << 4;
783 ifaceP += readw(samsung->sabi + config->header_offsets.data_offset) & 0x0ffff;
784 samsung->sabi_iface = ioremap_nocache(ifaceP, 16);
785 if (!samsung->sabi_iface) {
786 pr_err("Can't remap %x\n", ifaceP);
787 ret = -EINVAL;
788 goto exit;
789 }
790
791 if (debug)
792 samsung_sabi_selftest(samsung, ifaceP);
793
794 /* Turn on "Linux" mode in the BIOS */
795 if (commands->set_linux != 0xff) {
796 int retval = sabi_set_command(samsung,
797 commands->set_linux, 0x81);
798 if (retval) {
799 pr_warn("Linux mode was not set!\n");
800 ret = -ENODEV;
801 goto exit;
802 }
803 }
804
805 /* Check for stepping quirk */
Corentin Charyf34cd9c2011-11-26 11:00:00 +0100806 if (samsung->handle_backlight)
807 check_for_stepping_quirk(samsung);
Corentin Chary5dea7a22011-11-26 10:59:59 +0100808
809exit:
810 if (ret)
811 samsung_sabi_exit(samsung);
812
813 return ret;
814}
815
816static void samsung_platform_exit(struct samsung_laptop *samsung)
817{
818 if (samsung->platform_device) {
819 platform_device_unregister(samsung->platform_device);
820 samsung->platform_device = NULL;
821 }
822}
823
824static int __init samsung_platform_init(struct samsung_laptop *samsung)
825{
826 struct platform_device *pdev;
827
828 pdev = platform_device_register_simple("samsung", -1, NULL, 0);
829 if (IS_ERR(pdev))
830 return PTR_ERR(pdev);
831
832 samsung->platform_device = pdev;
833 platform_set_drvdata(samsung->platform_device, samsung);
834 return 0;
835}
836
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500837static int __init dmi_check_cb(const struct dmi_system_id *id)
838{
Corentin Chary5dea7a22011-11-26 10:59:59 +0100839 pr_info("found laptop model '%s'\n", id->ident);
Axel Lin27836582011-03-14 18:56:18 +0800840 return 1;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500841}
842
843static struct dmi_system_id __initdata samsung_dmi_table[] = {
844 {
845 .ident = "N128",
846 .matches = {
847 DMI_MATCH(DMI_SYS_VENDOR,
848 "SAMSUNG ELECTRONICS CO., LTD."),
849 DMI_MATCH(DMI_PRODUCT_NAME, "N128"),
850 DMI_MATCH(DMI_BOARD_NAME, "N128"),
851 },
852 .callback = dmi_check_cb,
853 },
854 {
855 .ident = "N130",
856 .matches = {
857 DMI_MATCH(DMI_SYS_VENDOR,
858 "SAMSUNG ELECTRONICS CO., LTD."),
859 DMI_MATCH(DMI_PRODUCT_NAME, "N130"),
860 DMI_MATCH(DMI_BOARD_NAME, "N130"),
861 },
862 .callback = dmi_check_cb,
863 },
864 {
J Witteveen4e2441c2011-07-03 13:15:44 +0200865 .ident = "N510",
866 .matches = {
867 DMI_MATCH(DMI_SYS_VENDOR,
868 "SAMSUNG ELECTRONICS CO., LTD."),
869 DMI_MATCH(DMI_PRODUCT_NAME, "N510"),
870 DMI_MATCH(DMI_BOARD_NAME, "N510"),
871 },
872 .callback = dmi_check_cb,
873 },
874 {
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500875 .ident = "X125",
876 .matches = {
877 DMI_MATCH(DMI_SYS_VENDOR,
878 "SAMSUNG ELECTRONICS CO., LTD."),
879 DMI_MATCH(DMI_PRODUCT_NAME, "X125"),
880 DMI_MATCH(DMI_BOARD_NAME, "X125"),
881 },
882 .callback = dmi_check_cb,
883 },
884 {
885 .ident = "X120/X170",
886 .matches = {
887 DMI_MATCH(DMI_SYS_VENDOR,
888 "SAMSUNG ELECTRONICS CO., LTD."),
889 DMI_MATCH(DMI_PRODUCT_NAME, "X120/X170"),
890 DMI_MATCH(DMI_BOARD_NAME, "X120/X170"),
891 },
892 .callback = dmi_check_cb,
893 },
894 {
895 .ident = "NC10",
896 .matches = {
897 DMI_MATCH(DMI_SYS_VENDOR,
898 "SAMSUNG ELECTRONICS CO., LTD."),
899 DMI_MATCH(DMI_PRODUCT_NAME, "NC10"),
900 DMI_MATCH(DMI_BOARD_NAME, "NC10"),
901 },
902 .callback = dmi_check_cb,
903 },
904 {
905 .ident = "NP-Q45",
906 .matches = {
907 DMI_MATCH(DMI_SYS_VENDOR,
908 "SAMSUNG ELECTRONICS CO., LTD."),
909 DMI_MATCH(DMI_PRODUCT_NAME, "SQ45S70S"),
910 DMI_MATCH(DMI_BOARD_NAME, "SQ45S70S"),
911 },
912 .callback = dmi_check_cb,
913 },
914 {
915 .ident = "X360",
916 .matches = {
917 DMI_MATCH(DMI_SYS_VENDOR,
918 "SAMSUNG ELECTRONICS CO., LTD."),
919 DMI_MATCH(DMI_PRODUCT_NAME, "X360"),
920 DMI_MATCH(DMI_BOARD_NAME, "X360"),
921 },
922 .callback = dmi_check_cb,
923 },
924 {
Alberto Mardegan3d536ed2011-04-08 17:02:03 +0200925 .ident = "R410 Plus",
926 .matches = {
927 DMI_MATCH(DMI_SYS_VENDOR,
928 "SAMSUNG ELECTRONICS CO., LTD."),
929 DMI_MATCH(DMI_PRODUCT_NAME, "R410P"),
930 DMI_MATCH(DMI_BOARD_NAME, "R460"),
931 },
932 .callback = dmi_check_cb,
933 },
934 {
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500935 .ident = "R518",
936 .matches = {
937 DMI_MATCH(DMI_SYS_VENDOR,
938 "SAMSUNG ELECTRONICS CO., LTD."),
939 DMI_MATCH(DMI_PRODUCT_NAME, "R518"),
940 DMI_MATCH(DMI_BOARD_NAME, "R518"),
941 },
942 .callback = dmi_check_cb,
943 },
944 {
945 .ident = "R519/R719",
946 .matches = {
947 DMI_MATCH(DMI_SYS_VENDOR,
948 "SAMSUNG ELECTRONICS CO., LTD."),
949 DMI_MATCH(DMI_PRODUCT_NAME, "R519/R719"),
950 DMI_MATCH(DMI_BOARD_NAME, "R519/R719"),
951 },
952 .callback = dmi_check_cb,
953 },
954 {
Thomas Courbon78a75392011-07-20 22:57:44 +0200955 .ident = "N150/N210/N220",
956 .matches = {
957 DMI_MATCH(DMI_SYS_VENDOR,
958 "SAMSUNG ELECTRONICS CO., LTD."),
959 DMI_MATCH(DMI_PRODUCT_NAME, "N150/N210/N220"),
960 DMI_MATCH(DMI_BOARD_NAME, "N150/N210/N220"),
961 },
962 .callback = dmi_check_cb,
963 },
964 {
Raul Gutierrez Segalesf689c872011-09-20 09:16:15 -0700965 .ident = "N220",
966 .matches = {
967 DMI_MATCH(DMI_SYS_VENDOR,
968 "SAMSUNG ELECTRONICS CO., LTD."),
969 DMI_MATCH(DMI_PRODUCT_NAME, "N220"),
970 DMI_MATCH(DMI_BOARD_NAME, "N220"),
971 },
972 .callback = dmi_check_cb,
973 },
974 {
Greg Kroah-Hartman10165072011-04-08 17:02:04 +0200975 .ident = "N150/N210/N220/N230",
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500976 .matches = {
977 DMI_MATCH(DMI_SYS_VENDOR,
978 "SAMSUNG ELECTRONICS CO., LTD."),
Greg Kroah-Hartman10165072011-04-08 17:02:04 +0200979 DMI_MATCH(DMI_PRODUCT_NAME, "N150/N210/N220/N230"),
980 DMI_MATCH(DMI_BOARD_NAME, "N150/N210/N220/N230"),
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -0500981 },
982 .callback = dmi_check_cb,
983 },
984 {
985 .ident = "N150P/N210P/N220P",
986 .matches = {
987 DMI_MATCH(DMI_SYS_VENDOR,
988 "SAMSUNG ELECTRONICS CO., LTD."),
989 DMI_MATCH(DMI_PRODUCT_NAME, "N150P/N210P/N220P"),
990 DMI_MATCH(DMI_BOARD_NAME, "N150P/N210P/N220P"),
991 },
992 .callback = dmi_check_cb,
993 },
994 {
Stefan Bellerf87d0292011-09-20 09:16:08 -0700995 .ident = "R700",
996 .matches = {
997 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
998 DMI_MATCH(DMI_PRODUCT_NAME, "SR700"),
999 DMI_MATCH(DMI_BOARD_NAME, "SR700"),
1000 },
1001 .callback = dmi_check_cb,
1002 },
1003 {
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001004 .ident = "R530/R730",
1005 .matches = {
1006 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1007 DMI_MATCH(DMI_PRODUCT_NAME, "R530/R730"),
1008 DMI_MATCH(DMI_BOARD_NAME, "R530/R730"),
1009 },
1010 .callback = dmi_check_cb,
1011 },
1012 {
1013 .ident = "NF110/NF210/NF310",
1014 .matches = {
1015 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1016 DMI_MATCH(DMI_PRODUCT_NAME, "NF110/NF210/NF310"),
1017 DMI_MATCH(DMI_BOARD_NAME, "NF110/NF210/NF310"),
1018 },
1019 .callback = dmi_check_cb,
1020 },
1021 {
1022 .ident = "N145P/N250P/N260P",
1023 .matches = {
1024 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1025 DMI_MATCH(DMI_PRODUCT_NAME, "N145P/N250P/N260P"),
1026 DMI_MATCH(DMI_BOARD_NAME, "N145P/N250P/N260P"),
1027 },
1028 .callback = dmi_check_cb,
1029 },
1030 {
1031 .ident = "R70/R71",
1032 .matches = {
1033 DMI_MATCH(DMI_SYS_VENDOR,
1034 "SAMSUNG ELECTRONICS CO., LTD."),
1035 DMI_MATCH(DMI_PRODUCT_NAME, "R70/R71"),
1036 DMI_MATCH(DMI_BOARD_NAME, "R70/R71"),
1037 },
1038 .callback = dmi_check_cb,
1039 },
1040 {
1041 .ident = "P460",
1042 .matches = {
1043 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1044 DMI_MATCH(DMI_PRODUCT_NAME, "P460"),
1045 DMI_MATCH(DMI_BOARD_NAME, "P460"),
1046 },
1047 .callback = dmi_check_cb,
1048 },
Smelov Andrey093ed562011-09-20 09:16:10 -07001049 {
1050 .ident = "R528/R728",
1051 .matches = {
1052 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1053 DMI_MATCH(DMI_PRODUCT_NAME, "R528/R728"),
1054 DMI_MATCH(DMI_BOARD_NAME, "R528/R728"),
1055 },
1056 .callback = dmi_check_cb,
1057 },
Jason Stubbs7b3c2572011-09-20 09:16:14 -07001058 {
1059 .ident = "NC210/NC110",
1060 .matches = {
1061 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1062 DMI_MATCH(DMI_PRODUCT_NAME, "NC210/NC110"),
1063 DMI_MATCH(DMI_BOARD_NAME, "NC210/NC110"),
1064 },
1065 .callback = dmi_check_cb,
1066 },
Tommaso Massimi7500eeb2011-09-20 09:16:09 -07001067 {
1068 .ident = "X520",
1069 .matches = {
1070 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1071 DMI_MATCH(DMI_PRODUCT_NAME, "X520"),
1072 DMI_MATCH(DMI_BOARD_NAME, "X520"),
1073 },
1074 .callback = dmi_check_cb,
1075 },
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001076 { },
1077};
1078MODULE_DEVICE_TABLE(dmi, samsung_dmi_table);
1079
Corentin Chary5dea7a22011-11-26 10:59:59 +01001080static struct platform_device *samsung_platform_device;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001081
1082static int __init samsung_init(void)
1083{
Corentin Chary5dea7a22011-11-26 10:59:59 +01001084 struct samsung_laptop *samsung;
1085 int ret;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001086
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001087 if (!force && !dmi_check_system(samsung_dmi_table))
1088 return -ENODEV;
1089
Corentin Charya6df4892011-11-26 10:59:58 +01001090 samsung = kzalloc(sizeof(*samsung), GFP_KERNEL);
1091 if (!samsung)
1092 return -ENOMEM;
1093
1094 mutex_init(&samsung->sabi_mutex);
Corentin Charyf34cd9c2011-11-26 11:00:00 +01001095 samsung->handle_backlight = true;
1096
1097#ifdef CONFIG_ACPI
1098 /* Don't handle backlight here if the acpi video already handle it */
1099 if (acpi_video_backlight_support()) {
1100 pr_info("Backlight controlled by ACPI video driver\n");
1101 samsung->handle_backlight = false;
1102 }
1103#endif
Corentin Charya6df4892011-11-26 10:59:58 +01001104
Corentin Chary5dea7a22011-11-26 10:59:59 +01001105 ret = samsung_platform_init(samsung);
1106 if (ret)
1107 goto error_platform;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001108
Corentin Chary5dea7a22011-11-26 10:59:59 +01001109 ret = samsung_sabi_init(samsung);
1110 if (ret)
1111 goto error_sabi;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001112
Corentin Chary5dea7a22011-11-26 10:59:59 +01001113 ret = samsung_sysfs_init(samsung);
1114 if (ret)
1115 goto error_sysfs;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001116
Corentin Chary5dea7a22011-11-26 10:59:59 +01001117 ret = samsung_backlight_init(samsung);
1118 if (ret)
1119 goto error_backlight;
Corentin Charya6df4892011-11-26 10:59:58 +01001120
Corentin Chary5dea7a22011-11-26 10:59:59 +01001121 ret = samsung_rfkill_init(samsung);
1122 if (ret)
1123 goto error_rfkill;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001124
Corentin Chary5dea7a22011-11-26 10:59:59 +01001125 samsung_platform_device = samsung->platform_device;
1126 return ret;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001127
Corentin Chary5dea7a22011-11-26 10:59:59 +01001128error_rfkill:
1129 samsung_backlight_exit(samsung);
1130error_backlight:
1131 samsung_sysfs_exit(samsung);
1132error_sysfs:
1133 samsung_sabi_exit(samsung);
1134error_sabi:
1135 samsung_platform_exit(samsung);
1136error_platform:
Corentin Charya6df4892011-11-26 10:59:58 +01001137 kfree(samsung);
Corentin Chary5dea7a22011-11-26 10:59:59 +01001138 return ret;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001139}
1140
1141static void __exit samsung_exit(void)
1142{
Corentin Chary5dea7a22011-11-26 10:59:59 +01001143 struct samsung_laptop *samsung;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001144
Corentin Chary5dea7a22011-11-26 10:59:59 +01001145 samsung = platform_get_drvdata(samsung_platform_device);
Corentin Charya6df4892011-11-26 10:59:58 +01001146
Corentin Chary5dea7a22011-11-26 10:59:59 +01001147 samsung_rfkill_exit(samsung);
1148 samsung_backlight_exit(samsung);
1149 samsung_sysfs_exit(samsung);
1150 samsung_sabi_exit(samsung);
1151 samsung_platform_exit(samsung);
1152
Corentin Charya6df4892011-11-26 10:59:58 +01001153 kfree(samsung);
Corentin Chary5dea7a22011-11-26 10:59:59 +01001154 samsung_platform_device = NULL;
Greg Kroah-Hartman2d70b732011-03-11 12:41:19 -05001155}
1156
1157module_init(samsung_init);
1158module_exit(samsung_exit);
1159
1160MODULE_AUTHOR("Greg Kroah-Hartman <gregkh@suse.de>");
1161MODULE_DESCRIPTION("Samsung Backlight driver");
1162MODULE_LICENSE("GPL");