c042ed5b0bce46669b0e2a7dc60bb0fad8ec5478
[deliverable/linux.git] / drivers / staging / samsung-laptop / samsung-laptop.c
1 /*
2 * Samsung Laptop driver
3 *
4 * Copyright (C) 2009 Greg Kroah-Hartman (gregkh@suse.de)
5 * Copyright (C) 2009 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 #include <linux/kernel.h>
13 #include <linux/init.h>
14 #include <linux/module.h>
15 #include <linux/delay.h>
16 #include <linux/pci.h>
17 #include <linux/backlight.h>
18 #include <linux/fb.h>
19 #include <linux/dmi.h>
20 #include <linux/platform_device.h>
21 #include <linux/rfkill.h>
22
23 /*
24 * This driver is needed because a number of Samsung laptops do not hook
25 * their control settings through ACPI. So we have to poke around in the
26 * BIOS to do things like brightness values, and "special" key controls.
27 */
28
29 /*
30 * We have 0 - 8 as valid brightness levels. The specs say that level 0 should
31 * be reserved by the BIOS (which really doesn't make much sense), we tell
32 * userspace that the value is 0 - 7 and then just tell the hardware 1 - 8
33 */
34 #define MAX_BRIGHT 0x07
35
36
37 #define SABI_IFACE_MAIN 0x00
38 #define SABI_IFACE_SUB 0x02
39 #define SABI_IFACE_COMPLETE 0x04
40 #define SABI_IFACE_DATA 0x05
41
42 /* Structure to get data back to the calling function */
43 struct sabi_retval {
44 u8 retval[20];
45 };
46
47 struct sabi_header_offsets {
48 u8 port;
49 u8 re_mem;
50 u8 iface_func;
51 u8 en_mem;
52 u8 data_offset;
53 u8 data_segment;
54 };
55
56 struct sabi_commands {
57 /*
58 * Brightness is 0 - 8, as described above.
59 * Value 0 is for the BIOS to use
60 */
61 u8 get_brightness;
62 u8 set_brightness;
63
64 /*
65 * first byte:
66 * 0x00 - wireless is off
67 * 0x01 - wireless is on
68 * second byte:
69 * 0x02 - 3G is off
70 * 0x03 - 3G is on
71 * TODO, verify 3G is correct, that doesn't seem right...
72 */
73 u8 get_wireless_button;
74 u8 set_wireless_button;
75
76 /* 0 is off, 1 is on */
77 u8 get_backlight;
78 u8 set_backlight;
79
80 /*
81 * 0x80 or 0x00 - no action
82 * 0x81 - recovery key pressed
83 */
84 u8 get_recovery_mode;
85 u8 set_recovery_mode;
86
87 /*
88 * on seclinux: 0 is low, 1 is high,
89 * on swsmi: 0 is normal, 1 is silent, 2 is turbo
90 */
91 u8 get_performance_level;
92 u8 set_performance_level;
93
94 /*
95 * Tell the BIOS that Linux is running on this machine.
96 * 81 is on, 80 is off
97 */
98 u8 set_linux;
99 };
100
101 struct sabi_performance_level {
102 const char *name;
103 u8 value;
104 };
105
106 struct sabi_config {
107 const char *test_string;
108 u16 main_function;
109 struct sabi_header_offsets header_offsets;
110 struct sabi_commands commands;
111 struct sabi_performance_level performance_levels[4];
112 };
113
114 static struct sabi_config sabi_configs[] = {
115 {
116 .test_string = "SECLINUX",
117
118 .main_function = 0x4c59,
119
120 .header_offsets = {
121 .port = 0x00,
122 .re_mem = 0x02,
123 .iface_func = 0x03,
124 .en_mem = 0x04,
125 .data_offset = 0x05,
126 .data_segment = 0x07,
127 },
128
129 .commands = {
130 .get_brightness = 0x00,
131 .set_brightness = 0x01,
132
133 .get_wireless_button = 0x02,
134 .set_wireless_button = 0x03,
135
136 .get_backlight = 0x04,
137 .set_backlight = 0x05,
138
139 .get_recovery_mode = 0x06,
140 .set_recovery_mode = 0x07,
141
142 .get_performance_level = 0x08,
143 .set_performance_level = 0x09,
144
145 .set_linux = 0x0a,
146 },
147
148 .performance_levels = {
149 {
150 .name = "silent",
151 .value = 0,
152 },
153 {
154 .name = "normal",
155 .value = 1,
156 },
157 { },
158 },
159 },
160 {
161 .test_string = "SwSmi@",
162
163 .main_function = 0x5843,
164
165 .header_offsets = {
166 .port = 0x00,
167 .re_mem = 0x04,
168 .iface_func = 0x02,
169 .en_mem = 0x03,
170 .data_offset = 0x05,
171 .data_segment = 0x07,
172 },
173
174 .commands = {
175 .get_brightness = 0x10,
176 .set_brightness = 0x11,
177
178 .get_wireless_button = 0x12,
179 .set_wireless_button = 0x13,
180
181 .get_backlight = 0x2d,
182 .set_backlight = 0x2e,
183
184 .get_recovery_mode = 0xff,
185 .set_recovery_mode = 0xff,
186
187 .get_performance_level = 0x31,
188 .set_performance_level = 0x32,
189
190 .set_linux = 0xff,
191 },
192
193 .performance_levels = {
194 {
195 .name = "normal",
196 .value = 0,
197 },
198 {
199 .name = "silent",
200 .value = 1,
201 },
202 {
203 .name = "overclock",
204 .value = 2,
205 },
206 { },
207 },
208 },
209 { },
210 };
211
212 static struct sabi_config *sabi_config;
213
214 static void __iomem *sabi;
215 static void __iomem *sabi_iface;
216 static void __iomem *f0000_segment;
217 static struct backlight_device *backlight_device;
218 static struct mutex sabi_mutex;
219 static struct platform_device *sdev;
220 static struct rfkill *rfk;
221
222 static int force;
223 module_param(force, bool, 0);
224 MODULE_PARM_DESC(force,
225 "Disable the DMI check and forces the driver to be loaded");
226
227 static int debug;
228 module_param(debug, bool, S_IRUGO | S_IWUSR);
229 MODULE_PARM_DESC(debug, "Debug enabled or not");
230
231 static int sabi_get_command(u8 command, struct sabi_retval *sretval)
232 {
233 int retval = 0;
234 u16 port = readw(sabi + sabi_config->header_offsets.port);
235
236 mutex_lock(&sabi_mutex);
237
238 /* enable memory to be able to write to it */
239 outb(readb(sabi + sabi_config->header_offsets.en_mem), port);
240
241 /* write out the command */
242 writew(sabi_config->main_function, sabi_iface + SABI_IFACE_MAIN);
243 writew(command, sabi_iface + SABI_IFACE_SUB);
244 writeb(0, sabi_iface + SABI_IFACE_COMPLETE);
245 outb(readb(sabi + sabi_config->header_offsets.iface_func), port);
246
247 /* write protect memory to make it safe */
248 outb(readb(sabi + sabi_config->header_offsets.re_mem), port);
249
250 /* see if the command actually succeeded */
251 if (readb(sabi_iface + SABI_IFACE_COMPLETE) == 0xaa &&
252 readb(sabi_iface + SABI_IFACE_DATA) != 0xff) {
253 /*
254 * It did!
255 * Save off the data into a structure so the caller use it.
256 * Right now we only care about the first 4 bytes,
257 * I suppose there are commands that need more, but I don't
258 * know about them.
259 */
260 sretval->retval[0] = readb(sabi_iface + SABI_IFACE_DATA);
261 sretval->retval[1] = readb(sabi_iface + SABI_IFACE_DATA + 1);
262 sretval->retval[2] = readb(sabi_iface + SABI_IFACE_DATA + 2);
263 sretval->retval[3] = readb(sabi_iface + SABI_IFACE_DATA + 3);
264 goto exit;
265 }
266
267 /* Something bad happened, so report it and error out */
268 printk(KERN_WARNING "SABI command 0x%02x failed with completion flag 0x%02x and output 0x%02x\n",
269 command, readb(sabi_iface + SABI_IFACE_COMPLETE),
270 readb(sabi_iface + SABI_IFACE_DATA));
271 retval = -EINVAL;
272 exit:
273 mutex_unlock(&sabi_mutex);
274 return retval;
275
276 }
277
278 static int sabi_set_command(u8 command, u8 data)
279 {
280 int retval = 0;
281 u16 port = readw(sabi + sabi_config->header_offsets.port);
282
283 mutex_lock(&sabi_mutex);
284
285 /* enable memory to be able to write to it */
286 outb(readb(sabi + sabi_config->header_offsets.en_mem), port);
287
288 /* write out the command */
289 writew(sabi_config->main_function, sabi_iface + SABI_IFACE_MAIN);
290 writew(command, sabi_iface + SABI_IFACE_SUB);
291 writeb(0, sabi_iface + SABI_IFACE_COMPLETE);
292 writeb(data, sabi_iface + SABI_IFACE_DATA);
293 outb(readb(sabi + sabi_config->header_offsets.iface_func), port);
294
295 /* write protect memory to make it safe */
296 outb(readb(sabi + sabi_config->header_offsets.re_mem), port);
297
298 /* see if the command actually succeeded */
299 if (readb(sabi_iface + SABI_IFACE_COMPLETE) == 0xaa &&
300 readb(sabi_iface + SABI_IFACE_DATA) != 0xff) {
301 /* it did! */
302 goto exit;
303 }
304
305 /* Something bad happened, so report it and error out */
306 printk(KERN_WARNING "SABI command 0x%02x failed with completion flag 0x%02x and output 0x%02x\n",
307 command, readb(sabi_iface + SABI_IFACE_COMPLETE),
308 readb(sabi_iface + SABI_IFACE_DATA));
309 retval = -EINVAL;
310 exit:
311 mutex_unlock(&sabi_mutex);
312 return retval;
313 }
314
315 static void test_backlight(void)
316 {
317 struct sabi_retval sretval;
318
319 sabi_get_command(sabi_config->commands.get_backlight, &sretval);
320 printk(KERN_DEBUG "backlight = 0x%02x\n", sretval.retval[0]);
321
322 sabi_set_command(sabi_config->commands.set_backlight, 0);
323 printk(KERN_DEBUG "backlight should be off\n");
324
325 sabi_get_command(sabi_config->commands.get_backlight, &sretval);
326 printk(KERN_DEBUG "backlight = 0x%02x\n", sretval.retval[0]);
327
328 msleep(1000);
329
330 sabi_set_command(sabi_config->commands.set_backlight, 1);
331 printk(KERN_DEBUG "backlight should be on\n");
332
333 sabi_get_command(sabi_config->commands.get_backlight, &sretval);
334 printk(KERN_DEBUG "backlight = 0x%02x\n", sretval.retval[0]);
335 }
336
337 static void test_wireless(void)
338 {
339 struct sabi_retval sretval;
340
341 sabi_get_command(sabi_config->commands.get_wireless_button, &sretval);
342 printk(KERN_DEBUG "wireless led = 0x%02x\n", sretval.retval[0]);
343
344 sabi_set_command(sabi_config->commands.set_wireless_button, 0);
345 printk(KERN_DEBUG "wireless led should be off\n");
346
347 sabi_get_command(sabi_config->commands.get_wireless_button, &sretval);
348 printk(KERN_DEBUG "wireless led = 0x%02x\n", sretval.retval[0]);
349
350 msleep(1000);
351
352 sabi_set_command(sabi_config->commands.set_wireless_button, 1);
353 printk(KERN_DEBUG "wireless led should be on\n");
354
355 sabi_get_command(sabi_config->commands.get_wireless_button, &sretval);
356 printk(KERN_DEBUG "wireless led = 0x%02x\n", sretval.retval[0]);
357 }
358
359 static u8 read_brightness(void)
360 {
361 struct sabi_retval sretval;
362 int user_brightness = 0;
363 int retval;
364
365 retval = sabi_get_command(sabi_config->commands.get_brightness,
366 &sretval);
367 if (!retval)
368 user_brightness = sretval.retval[0];
369 if (user_brightness != 0)
370 --user_brightness;
371 return user_brightness;
372 }
373
374 static void set_brightness(u8 user_brightness)
375 {
376 sabi_set_command(sabi_config->commands.set_brightness,
377 user_brightness + 1);
378 }
379
380 static int get_brightness(struct backlight_device *bd)
381 {
382 return (int)read_brightness();
383 }
384
385 static int update_status(struct backlight_device *bd)
386 {
387 set_brightness(bd->props.brightness);
388
389 if (bd->props.power == FB_BLANK_UNBLANK)
390 sabi_set_command(sabi_config->commands.set_backlight, 1);
391 else
392 sabi_set_command(sabi_config->commands.set_backlight, 0);
393 return 0;
394 }
395
396 static const struct backlight_ops backlight_ops = {
397 .get_brightness = get_brightness,
398 .update_status = update_status,
399 };
400
401 static int rfkill_set(void *data, bool blocked)
402 {
403 /* Do something with blocked...*/
404 /*
405 * blocked == false is on
406 * blocked == true is off
407 */
408 if (blocked)
409 sabi_set_command(sabi_config->commands.set_wireless_button, 0);
410 else
411 sabi_set_command(sabi_config->commands.set_wireless_button, 1);
412
413 return 0;
414 }
415
416 static struct rfkill_ops rfkill_ops = {
417 .set_block = rfkill_set,
418 };
419
420 static int init_wireless(struct platform_device *sdev)
421 {
422 int retval;
423
424 rfk = rfkill_alloc("samsung-wifi", &sdev->dev, RFKILL_TYPE_WLAN,
425 &rfkill_ops, NULL);
426 if (!rfk)
427 return -ENOMEM;
428
429 retval = rfkill_register(rfk);
430 if (retval) {
431 rfkill_destroy(rfk);
432 return -ENODEV;
433 }
434
435 return 0;
436 }
437
438 static void destroy_wireless(void)
439 {
440 rfkill_unregister(rfk);
441 rfkill_destroy(rfk);
442 }
443
444 static ssize_t get_performance_level(struct device *dev,
445 struct device_attribute *attr, char *buf)
446 {
447 struct sabi_retval sretval;
448 int retval;
449 int i;
450
451 /* Read the state */
452 retval = sabi_get_command(sabi_config->commands.get_performance_level,
453 &sretval);
454 if (retval)
455 return retval;
456
457 /* The logic is backwards, yeah, lots of fun... */
458 for (i = 0; sabi_config->performance_levels[i].name; ++i) {
459 if (sretval.retval[0] == sabi_config->performance_levels[i].value)
460 return sprintf(buf, "%s\n", sabi_config->performance_levels[i].name);
461 }
462 return sprintf(buf, "%s\n", "unknown");
463 }
464
465 static ssize_t set_performance_level(struct device *dev,
466 struct device_attribute *attr, const char *buf,
467 size_t count)
468 {
469 if (count >= 1) {
470 int i;
471 for (i = 0; sabi_config->performance_levels[i].name; ++i) {
472 struct sabi_performance_level *level =
473 &sabi_config->performance_levels[i];
474 if (!strncasecmp(level->name, buf, strlen(level->name))) {
475 sabi_set_command(sabi_config->commands.set_performance_level,
476 level->value);
477 break;
478 }
479 }
480 if (!sabi_config->performance_levels[i].name)
481 return -EINVAL;
482 }
483 return count;
484 }
485 static DEVICE_ATTR(performance_level, S_IWUSR | S_IRUGO,
486 get_performance_level, set_performance_level);
487
488
489 static int __init dmi_check_cb(const struct dmi_system_id *id)
490 {
491 printk(KERN_INFO KBUILD_MODNAME ": found laptop model '%s'\n",
492 id->ident);
493 return 0;
494 }
495
496 static struct dmi_system_id __initdata samsung_dmi_table[] = {
497 {
498 .ident = "N128",
499 .matches = {
500 DMI_MATCH(DMI_SYS_VENDOR,
501 "SAMSUNG ELECTRONICS CO., LTD."),
502 DMI_MATCH(DMI_PRODUCT_NAME, "N128"),
503 DMI_MATCH(DMI_BOARD_NAME, "N128"),
504 },
505 .callback = dmi_check_cb,
506 },
507 {
508 .ident = "N130",
509 .matches = {
510 DMI_MATCH(DMI_SYS_VENDOR,
511 "SAMSUNG ELECTRONICS CO., LTD."),
512 DMI_MATCH(DMI_PRODUCT_NAME, "N130"),
513 DMI_MATCH(DMI_BOARD_NAME, "N130"),
514 },
515 .callback = dmi_check_cb,
516 },
517 {
518 .ident = "X125",
519 .matches = {
520 DMI_MATCH(DMI_SYS_VENDOR,
521 "SAMSUNG ELECTRONICS CO., LTD."),
522 DMI_MATCH(DMI_PRODUCT_NAME, "X125"),
523 DMI_MATCH(DMI_BOARD_NAME, "X125"),
524 },
525 .callback = dmi_check_cb,
526 },
527 {
528 .ident = "NC10",
529 .matches = {
530 DMI_MATCH(DMI_SYS_VENDOR,
531 "SAMSUNG ELECTRONICS CO., LTD."),
532 DMI_MATCH(DMI_PRODUCT_NAME, "NC10"),
533 DMI_MATCH(DMI_BOARD_NAME, "NC10"),
534 },
535 .callback = dmi_check_cb,
536 },
537 {
538 .ident = "NP-Q45",
539 .matches = {
540 DMI_MATCH(DMI_SYS_VENDOR,
541 "SAMSUNG ELECTRONICS CO., LTD."),
542 DMI_MATCH(DMI_PRODUCT_NAME, "SQ45S70S"),
543 DMI_MATCH(DMI_BOARD_NAME, "SQ45S70S"),
544 },
545 .callback = dmi_check_cb,
546 },
547 {
548 .ident = "X360",
549 .matches = {
550 DMI_MATCH(DMI_SYS_VENDOR,
551 "SAMSUNG ELECTRONICS CO., LTD."),
552 DMI_MATCH(DMI_PRODUCT_NAME, "X360"),
553 DMI_MATCH(DMI_BOARD_NAME, "X360"),
554 },
555 .callback = dmi_check_cb,
556 },
557 {
558 .ident = "R518",
559 .matches = {
560 DMI_MATCH(DMI_SYS_VENDOR,
561 "SAMSUNG ELECTRONICS CO., LTD."),
562 DMI_MATCH(DMI_PRODUCT_NAME, "R518"),
563 DMI_MATCH(DMI_BOARD_NAME, "R518"),
564 },
565 .callback = dmi_check_cb,
566 },
567 {
568 .ident = "N150/N210/N220",
569 .matches = {
570 DMI_MATCH(DMI_SYS_VENDOR,
571 "SAMSUNG ELECTRONICS CO., LTD."),
572 DMI_MATCH(DMI_PRODUCT_NAME, "N150/N210/N220"),
573 DMI_MATCH(DMI_BOARD_NAME, "N150/N210/N220"),
574 },
575 .callback = dmi_check_cb,
576 },
577 {
578 .ident = "R530/R730",
579 .matches = {
580 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
581 DMI_MATCH(DMI_PRODUCT_NAME, "R530/R730"),
582 DMI_MATCH(DMI_BOARD_NAME, "R530/R730"),
583 },
584 .callback = dmi_check_cb,
585 },
586 {
587 .ident = "NF110/NF210/NF310",
588 .matches = {
589 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
590 DMI_MATCH(DMI_PRODUCT_NAME, "NF110/NF210/NF310"),
591 DMI_MATCH(DMI_BOARD_NAME, "NF110/NF210/NF310"),
592 },
593 .callback = dmi_check_cb,
594 },
595 {
596 .ident = "N145P/N250P/N260P",
597 .matches = {
598 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
599 DMI_MATCH(DMI_PRODUCT_NAME, "N145P/N250P/N260P"),
600 DMI_MATCH(DMI_BOARD_NAME, "N145P/N250P/N260P"),
601 },
602 .callback = dmi_check_cb,
603 },
604 {
605 .ident = "R70/R71",
606 .matches = {
607 DMI_MATCH(DMI_SYS_VENDOR,
608 "SAMSUNG ELECTRONICS CO., LTD."),
609 DMI_MATCH(DMI_PRODUCT_NAME, "R70/R71"),
610 DMI_MATCH(DMI_BOARD_NAME, "R70/R71"),
611 },
612 .callback = dmi_check_cb,
613 },
614 { },
615 };
616 MODULE_DEVICE_TABLE(dmi, samsung_dmi_table);
617
618 static int find_signature(void __iomem *memcheck, const char *testStr)
619 {
620 int i = 0;
621 int loca;
622
623 for (loca = 0; loca < 0xffff; loca++) {
624 char temp = readb(memcheck + loca);
625
626 if (temp == testStr[i]) {
627 if (i == strlen(testStr)-1)
628 break;
629 ++i;
630 } else {
631 i = 0;
632 }
633 }
634 return loca;
635 }
636
637 static int __init samsung_init(void)
638 {
639 struct backlight_properties props;
640 struct sabi_retval sretval;
641 unsigned int ifaceP;
642 int i;
643 int loca;
644 int retval;
645
646 mutex_init(&sabi_mutex);
647
648 if (!force && !dmi_check_system(samsung_dmi_table))
649 return -ENODEV;
650
651 f0000_segment = ioremap(0xf0000, 0xffff);
652 if (!f0000_segment) {
653 printk(KERN_ERR "Can't map the segment at 0xf0000\n");
654 return -EINVAL;
655 }
656
657 /* Try to find one of the signatures in memory to find the header */
658 for (i = 0; sabi_configs[i].test_string != 0; ++i) {
659 sabi_config = &sabi_configs[i];
660 loca = find_signature(f0000_segment, sabi_config->test_string);
661 if (loca != 0xffff)
662 break;
663 }
664
665 if (loca == 0xffff) {
666 printk(KERN_ERR "This computer does not support SABI\n");
667 goto error_no_signature;
668 }
669
670 /* point to the SMI port Number */
671 loca += 1;
672 sabi = (f0000_segment + loca);
673
674 if (debug) {
675 printk(KERN_DEBUG "This computer supports SABI==%x\n",
676 loca + 0xf0000 - 6);
677 printk(KERN_DEBUG "SABI header:\n");
678 printk(KERN_DEBUG " SMI Port Number = 0x%04x\n",
679 readw(sabi + sabi_config->header_offsets.port));
680 printk(KERN_DEBUG " SMI Interface Function = 0x%02x\n",
681 readb(sabi + sabi_config->header_offsets.iface_func));
682 printk(KERN_DEBUG " SMI enable memory buffer = 0x%02x\n",
683 readb(sabi + sabi_config->header_offsets.en_mem));
684 printk(KERN_DEBUG " SMI restore memory buffer = 0x%02x\n",
685 readb(sabi + sabi_config->header_offsets.re_mem));
686 printk(KERN_DEBUG " SABI data offset = 0x%04x\n",
687 readw(sabi + sabi_config->header_offsets.data_offset));
688 printk(KERN_DEBUG " SABI data segment = 0x%04x\n",
689 readw(sabi + sabi_config->header_offsets.data_segment));
690 }
691
692 /* Get a pointer to the SABI Interface */
693 ifaceP = (readw(sabi + sabi_config->header_offsets.data_segment) & 0x0ffff) << 4;
694 ifaceP += readw(sabi + sabi_config->header_offsets.data_offset) & 0x0ffff;
695 sabi_iface = ioremap(ifaceP, 16);
696 if (!sabi_iface) {
697 printk(KERN_ERR "Can't remap %x\n", ifaceP);
698 goto exit;
699 }
700 if (debug) {
701 printk(KERN_DEBUG "ifaceP = 0x%08x\n", ifaceP);
702 printk(KERN_DEBUG "sabi_iface = %p\n", sabi_iface);
703
704 test_backlight();
705 test_wireless();
706
707 retval = sabi_get_command(sabi_config->commands.get_brightness,
708 &sretval);
709 printk(KERN_DEBUG "brightness = 0x%02x\n", sretval.retval[0]);
710 }
711
712 /* Turn on "Linux" mode in the BIOS */
713 if (sabi_config->commands.set_linux != 0xff) {
714 retval = sabi_set_command(sabi_config->commands.set_linux,
715 0x81);
716 if (retval) {
717 printk(KERN_ERR KBUILD_MODNAME ": Linux mode was not set!\n");
718 goto error_no_platform;
719 }
720 }
721
722 /* knock up a platform device to hang stuff off of */
723 sdev = platform_device_register_simple("samsung", -1, NULL, 0);
724 if (IS_ERR(sdev))
725 goto error_no_platform;
726
727 /* create a backlight device to talk to this one */
728 memset(&props, 0, sizeof(struct backlight_properties));
729 props.max_brightness = MAX_BRIGHT;
730 backlight_device = backlight_device_register("samsung", &sdev->dev,
731 NULL, &backlight_ops,
732 &props);
733 if (IS_ERR(backlight_device))
734 goto error_no_backlight;
735
736 backlight_device->props.brightness = read_brightness();
737 backlight_device->props.power = FB_BLANK_UNBLANK;
738 backlight_update_status(backlight_device);
739
740 retval = init_wireless(sdev);
741 if (retval)
742 goto error_no_rfk;
743
744 retval = device_create_file(&sdev->dev, &dev_attr_performance_level);
745 if (retval)
746 goto error_file_create;
747
748 exit:
749 return 0;
750
751 error_file_create:
752 destroy_wireless();
753
754 error_no_rfk:
755 backlight_device_unregister(backlight_device);
756
757 error_no_backlight:
758 platform_device_unregister(sdev);
759
760 error_no_platform:
761 iounmap(sabi_iface);
762
763 error_no_signature:
764 iounmap(f0000_segment);
765 return -EINVAL;
766 }
767
768 static void __exit samsung_exit(void)
769 {
770 /* Turn off "Linux" mode in the BIOS */
771 if (sabi_config->commands.set_linux != 0xff)
772 sabi_set_command(sabi_config->commands.set_linux, 0x80);
773
774 device_remove_file(&sdev->dev, &dev_attr_performance_level);
775 backlight_device_unregister(backlight_device);
776 destroy_wireless();
777 iounmap(sabi_iface);
778 iounmap(f0000_segment);
779 platform_device_unregister(sdev);
780 }
781
782 module_init(samsung_init);
783 module_exit(samsung_exit);
784
785 MODULE_AUTHOR("Greg Kroah-Hartman <gregkh@suse.de>");
786 MODULE_DESCRIPTION("Samsung Backlight driver");
787 MODULE_LICENSE("GPL");
This page took 0.058945 seconds and 4 git commands to generate.