aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/misc
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/misc')
-rw-r--r--drivers/misc/thinkpad_acpi.c613
1 files changed, 185 insertions, 428 deletions
diff --git a/drivers/misc/thinkpad_acpi.c b/drivers/misc/thinkpad_acpi.c
index 59b127cff1ec..e435b554a004 100644
--- a/drivers/misc/thinkpad_acpi.c
+++ b/drivers/misc/thinkpad_acpi.c
@@ -82,8 +82,6 @@
82 * 2004-08-09 0.1 initial release, support for X series 82 * 2004-08-09 0.1 initial release, support for X series
83 */ 83 */
84 84
85/* ==================================================== BEGIN HEADER */
86
87#include <linux/kernel.h> 85#include <linux/kernel.h>
88#include <linux/module.h> 86#include <linux/module.h>
89#include <linux/init.h> 87#include <linux/init.h>
@@ -199,79 +197,22 @@ static const char *str_supported(int is_supported);
199/* ACPI HIDs */ 197/* ACPI HIDs */
200#define IBM_HKEY_HID "IBM0068" 198#define IBM_HKEY_HID "IBM0068"
201 199
202/* ACPI helpers */
203static int __must_check acpi_evalf(acpi_handle handle,
204 void *res, char *method, char *fmt, ...);
205static int __must_check acpi_ec_read(int i, u8 * p);
206static int __must_check acpi_ec_write(int i, u8 v);
207static int __must_check _sta(acpi_handle handle);
208
209/* ACPI handles */
210static acpi_handle root_handle; /* root namespace */
211static acpi_handle ec_handle; /* EC */
212static acpi_handle ecrd_handle, ecwr_handle; /* 570 EC access */
213static acpi_handle cmos_handle, hkey_handle; /* basic thinkpad handles */
214
215static void drv_acpi_handle_init(char *name,
216 acpi_handle *handle, acpi_handle parent,
217 char **paths, int num_paths, char **path);
218#define IBM_ACPIHANDLE_INIT(object) \
219 drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \
220 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
221
222/* ThinkPad ACPI helpers */
223static int issue_thinkpad_cmos_command(int cmos_cmd);
224
225/* procfs support */
226static struct proc_dir_entry *proc_dir;
227
228/* procfs helpers */
229static int dispatch_procfs_read(char *page, char **start, off_t off,
230 int count, int *eof, void *data);
231static int dispatch_procfs_write(struct file *file,
232 const char __user * userbuf,
233 unsigned long count, void *data);
234static char *next_cmd(char **cmds);
235
236/* sysfs support */ 200/* sysfs support */
237struct attribute_set { 201struct attribute_set {
238 unsigned int members, max_members; 202 unsigned int members, max_members;
239 struct attribute_group group; 203 struct attribute_group group;
240}; 204};
241 205
242static struct attribute_set *create_attr_set(unsigned int max_members, 206/* Helpers */
243 const char* name);
244#define destroy_attr_set(_set) \
245 kfree(_set);
246static int add_to_attr_set(struct attribute_set* s, struct attribute *attr);
247static int add_many_to_attr_set(struct attribute_set* s,
248 struct attribute **attr,
249 unsigned int count);
250#define register_attr_set_with_sysfs(_attr_set, _kobj) \
251 sysfs_create_group(_kobj, &_attr_set->group)
252static void delete_attr_set(struct attribute_set* s, struct kobject *kobj);
253
254static int parse_strtoul(const char *buf, unsigned long max, 207static int parse_strtoul(const char *buf, unsigned long max,
255 unsigned long *value); 208 unsigned long *value);
256 209
257/* Device model */
258static struct platform_device *tpacpi_pdev;
259static struct platform_device *tpacpi_sensors_pdev;
260static struct device *tpacpi_hwmon;
261static struct platform_driver tpacpi_pdriver;
262static struct input_dev *tpacpi_inputdev;
263static int tpacpi_create_driver_attributes(struct device_driver *drv);
264static void tpacpi_remove_driver_attributes(struct device_driver *drv);
265
266/* Module */ 210/* Module */
267static int experimental; 211static int experimental;
268static u32 dbg_level; 212static u32 dbg_level;
269static int force_load; 213static int force_load;
270static unsigned int hotkey_report_mode; 214static unsigned int hotkey_report_mode;
271 215
272static int thinkpad_acpi_module_init(void);
273static void thinkpad_acpi_module_exit(void);
274
275 216
276/**************************************************************************** 217/****************************************************************************
277 * Subdrivers 218 * Subdrivers
@@ -354,365 +295,9 @@ struct thinkpad_id_data {
354 295
355 char *model_str; 296 char *model_str;
356}; 297};
357
358static struct thinkpad_id_data thinkpad_id; 298static struct thinkpad_id_data thinkpad_id;
359 299
360static struct list_head tpacpi_all_drivers; 300static LIST_HEAD(tpacpi_all_drivers);
361
362static struct ibm_init_struct ibms_init[];
363static int set_ibm_param(const char *val, struct kernel_param *kp);
364static int ibm_init(struct ibm_init_struct *iibm);
365static void ibm_exit(struct ibm_struct *ibm);
366
367
368/*
369 * procfs master subdriver
370 */
371static int thinkpad_acpi_driver_init(struct ibm_init_struct *iibm);
372static int thinkpad_acpi_driver_read(char *p);
373
374
375/*
376 * Bay subdriver
377 */
378
379#ifdef CONFIG_THINKPAD_ACPI_BAY
380static acpi_handle bay_handle, bay_ej_handle;
381static acpi_handle bay2_handle, bay2_ej_handle;
382
383static int bay_init(struct ibm_init_struct *iibm);
384static void bay_notify(struct ibm_struct *ibm, u32 event);
385static int bay_read(char *p);
386static int bay_write(char *buf);
387#endif /* CONFIG_THINKPAD_ACPI_BAY */
388
389
390/*
391 * Beep subdriver
392 */
393
394static acpi_handle beep_handle;
395
396static int beep_read(char *p);
397static int beep_write(char *buf);
398
399
400/*
401 * Bluetooth subdriver
402 */
403
404enum {
405 /* ACPI GBDC/SBDC bits */
406 TP_ACPI_BLUETOOTH_HWPRESENT = 0x01, /* Bluetooth hw available */
407 TP_ACPI_BLUETOOTH_RADIOSSW = 0x02, /* Bluetooth radio enabled */
408 TP_ACPI_BLUETOOTH_UNK = 0x04, /* unknown function */
409};
410
411static int bluetooth_init(struct ibm_init_struct *iibm);
412static int bluetooth_get_radiosw(void);
413static int bluetooth_set_radiosw(int radio_on);
414static int bluetooth_read(char *p);
415static int bluetooth_write(char *buf);
416
417
418/*
419 * Brightness (backlight) subdriver
420 */
421
422#define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen"
423
424static struct backlight_device *ibm_backlight_device;
425static int brightness_offset = 0x31;
426static int brightness_mode;
427static unsigned int brightness_enable; /* 0 = no, 1 = yes, 2 = auto */
428
429static int brightness_init(struct ibm_init_struct *iibm);
430static void brightness_exit(void);
431static int brightness_get(struct backlight_device *bd);
432static int brightness_set(int value);
433static int brightness_update_status(struct backlight_device *bd);
434static int brightness_read(char *p);
435static int brightness_write(char *buf);
436
437
438/*
439 * CMOS subdriver
440 */
441
442static int cmos_read(char *p);
443static int cmos_write(char *buf);
444
445
446/*
447 * Dock subdriver
448 */
449
450#ifdef CONFIG_THINKPAD_ACPI_DOCK
451static acpi_handle pci_handle;
452static acpi_handle dock_handle;
453
454static void dock_notify(struct ibm_struct *ibm, u32 event);
455static int dock_read(char *p);
456static int dock_write(char *buf);
457#endif /* CONFIG_THINKPAD_ACPI_DOCK */
458
459
460/*
461 * EC dump subdriver
462 */
463
464static int ecdump_read(char *p) ;
465static int ecdump_write(char *buf);
466
467
468/*
469 * Fan subdriver
470 */
471
472enum { /* Fan control constants */
473 fan_status_offset = 0x2f, /* EC register 0x2f */
474 fan_rpm_offset = 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
475 * 0x84 must be read before 0x85 */
476
477 TP_EC_FAN_FULLSPEED = 0x40, /* EC fan mode: full speed */
478 TP_EC_FAN_AUTO = 0x80, /* EC fan mode: auto fan control */
479
480 TPACPI_FAN_LAST_LEVEL = 0x100, /* Use cached last-seen fan level */
481};
482
483enum fan_status_access_mode {
484 TPACPI_FAN_NONE = 0, /* No fan status or control */
485 TPACPI_FAN_RD_ACPI_GFAN, /* Use ACPI GFAN */
486 TPACPI_FAN_RD_TPEC, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
487};
488
489enum fan_control_access_mode {
490 TPACPI_FAN_WR_NONE = 0, /* No fan control */
491 TPACPI_FAN_WR_ACPI_SFAN, /* Use ACPI SFAN */
492 TPACPI_FAN_WR_TPEC, /* Use ACPI EC reg 0x2f */
493 TPACPI_FAN_WR_ACPI_FANS, /* Use ACPI FANS and EC reg 0x2f */
494};
495
496enum fan_control_commands {
497 TPACPI_FAN_CMD_SPEED = 0x0001, /* speed command */
498 TPACPI_FAN_CMD_LEVEL = 0x0002, /* level command */
499 TPACPI_FAN_CMD_ENABLE = 0x0004, /* enable/disable cmd,
500 * and also watchdog cmd */
501};
502
503static int fan_control_allowed;
504
505static enum fan_status_access_mode fan_status_access_mode;
506static enum fan_control_access_mode fan_control_access_mode;
507static enum fan_control_commands fan_control_commands;
508static u8 fan_control_initial_status;
509static u8 fan_control_desired_level;
510static int fan_watchdog_maxinterval;
511
512static struct mutex fan_mutex;
513
514static acpi_handle fans_handle, gfan_handle, sfan_handle;
515
516static int fan_init(struct ibm_init_struct *iibm);
517static void fan_exit(void);
518static int fan_get_status(u8 *status);
519static int fan_get_status_safe(u8 *status);
520static int fan_get_speed(unsigned int *speed);
521static void fan_update_desired_level(u8 status);
522static void fan_watchdog_fire(struct work_struct *ignored);
523static void fan_watchdog_reset(void);
524static int fan_set_level(int level);
525static int fan_set_level_safe(int level);
526static int fan_set_enable(void);
527static int fan_set_disable(void);
528static int fan_set_speed(int speed);
529static int fan_read(char *p);
530static int fan_write(char *buf);
531static int fan_write_cmd_level(const char *cmd, int *rc);
532static int fan_write_cmd_enable(const char *cmd, int *rc);
533static int fan_write_cmd_disable(const char *cmd, int *rc);
534static int fan_write_cmd_speed(const char *cmd, int *rc);
535static int fan_write_cmd_watchdog(const char *cmd, int *rc);
536
537
538/*
539 * Hotkey subdriver
540 */
541
542enum { /* hot key scan codes (derived from ACPI DSDT) */
543 TP_ACPI_HOTKEYSCAN_FNF1 = 0,
544 TP_ACPI_HOTKEYSCAN_FNF2,
545 TP_ACPI_HOTKEYSCAN_FNF3,
546 TP_ACPI_HOTKEYSCAN_FNF4,
547 TP_ACPI_HOTKEYSCAN_FNF5,
548 TP_ACPI_HOTKEYSCAN_FNF6,
549 TP_ACPI_HOTKEYSCAN_FNF7,
550 TP_ACPI_HOTKEYSCAN_FNF8,
551 TP_ACPI_HOTKEYSCAN_FNF9,
552 TP_ACPI_HOTKEYSCAN_FNF10,
553 TP_ACPI_HOTKEYSCAN_FNF11,
554 TP_ACPI_HOTKEYSCAN_FNF12,
555 TP_ACPI_HOTKEYSCAN_FNBACKSPACE,
556 TP_ACPI_HOTKEYSCAN_FNINSERT,
557 TP_ACPI_HOTKEYSCAN_FNDELETE,
558 TP_ACPI_HOTKEYSCAN_FNHOME,
559 TP_ACPI_HOTKEYSCAN_FNEND,
560 TP_ACPI_HOTKEYSCAN_FNPAGEUP,
561 TP_ACPI_HOTKEYSCAN_FNPAGEDOWN,
562 TP_ACPI_HOTKEYSCAN_FNSPACE,
563 TP_ACPI_HOTKEYSCAN_VOLUMEUP,
564 TP_ACPI_HOTKEYSCAN_VOLUMEDOWN,
565 TP_ACPI_HOTKEYSCAN_MUTE,
566 TP_ACPI_HOTKEYSCAN_THINKPAD,
567};
568
569static int hotkey_orig_status;
570static u32 hotkey_orig_mask;
571
572static struct mutex hotkey_mutex;
573
574static int hotkey_init(struct ibm_init_struct *iibm);
575static void hotkey_exit(void);
576static void hotkey_notify(struct ibm_struct *ibm, u32 event);
577static int hotkey_read(char *p);
578static int hotkey_write(char *buf);
579
580
581/*
582 * LED subdriver
583 */
584
585enum led_access_mode {
586 TPACPI_LED_NONE = 0,
587 TPACPI_LED_570, /* 570 */
588 TPACPI_LED_OLD, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
589 TPACPI_LED_NEW, /* all others */
590};
591
592enum { /* For TPACPI_LED_OLD */
593 TPACPI_LED_EC_HLCL = 0x0c, /* EC reg to get led to power on */
594 TPACPI_LED_EC_HLBL = 0x0d, /* EC reg to blink a lit led */
595 TPACPI_LED_EC_HLMS = 0x0e, /* EC reg to select led to command */
596};
597
598static enum led_access_mode led_supported;
599static acpi_handle led_handle;
600
601static int led_init(struct ibm_init_struct *iibm);
602static int led_read(char *p);
603static int led_write(char *buf);
604
605/*
606 * Light (thinklight) subdriver
607 */
608
609static acpi_handle lght_handle, ledb_handle;
610
611static int light_init(struct ibm_init_struct *iibm);
612static int light_read(char *p);
613static int light_write(char *buf);
614
615
616/*
617 * Thermal subdriver
618 */
619
620enum thermal_access_mode {
621 TPACPI_THERMAL_NONE = 0, /* No thermal support */
622 TPACPI_THERMAL_ACPI_TMP07, /* Use ACPI TMP0-7 */
623 TPACPI_THERMAL_ACPI_UPDT, /* Use ACPI TMP0-7 with UPDT */
624 TPACPI_THERMAL_TPEC_8, /* Use ACPI EC regs, 8 sensors */
625 TPACPI_THERMAL_TPEC_16, /* Use ACPI EC regs, 16 sensors */
626};
627
628enum { /* TPACPI_THERMAL_TPEC_* */
629 TP_EC_THERMAL_TMP0 = 0x78, /* ACPI EC regs TMP 0..7 */
630 TP_EC_THERMAL_TMP8 = 0xC0, /* ACPI EC regs TMP 8..15 */
631 TP_EC_THERMAL_TMP_NA = -128, /* ACPI EC sensor not available */
632};
633
634#define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
635struct ibm_thermal_sensors_struct {
636 s32 temp[TPACPI_MAX_THERMAL_SENSORS];
637};
638
639static enum thermal_access_mode thermal_read_mode;
640
641static int thermal_init(struct ibm_init_struct *iibm);
642static int thermal_get_sensor(int idx, s32 *value);
643static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s);
644static int thermal_read(char *p);
645
646
647/*
648 * Video subdriver
649 */
650
651enum video_access_mode {
652 TPACPI_VIDEO_NONE = 0,
653 TPACPI_VIDEO_570, /* 570 */
654 TPACPI_VIDEO_770, /* 600e/x, 770e, 770x */
655 TPACPI_VIDEO_NEW, /* all others */
656};
657
658enum { /* video status flags, based on VIDEO_570 */
659 TP_ACPI_VIDEO_S_LCD = 0x01, /* LCD output enabled */
660 TP_ACPI_VIDEO_S_CRT = 0x02, /* CRT output enabled */
661 TP_ACPI_VIDEO_S_DVI = 0x08, /* DVI output enabled */
662};
663
664enum { /* TPACPI_VIDEO_570 constants */
665 TP_ACPI_VIDEO_570_PHSCMD = 0x87, /* unknown magic constant :( */
666 TP_ACPI_VIDEO_570_PHSMASK = 0x03, /* PHS bits that map to
667 * video_status_flags */
668 TP_ACPI_VIDEO_570_PHS2CMD = 0x8b, /* unknown magic constant :( */
669 TP_ACPI_VIDEO_570_PHS2SET = 0x80, /* unknown magic constant :( */
670};
671
672static enum video_access_mode video_supported;
673static int video_orig_autosw;
674static acpi_handle vid_handle, vid2_handle;
675
676static int video_init(struct ibm_init_struct *iibm);
677static void video_exit(void);
678static int video_outputsw_get(void);
679static int video_outputsw_set(int status);
680static int video_autosw_get(void);
681static int video_autosw_set(int enable);
682static int video_outputsw_cycle(void);
683static int video_expand_toggle(void);
684static int video_read(char *p);
685static int video_write(char *buf);
686
687
688/*
689 * Volume subdriver
690 */
691
692static int volume_offset = 0x30;
693
694static int volume_read(char *p);
695static int volume_write(char *buf);
696
697
698/*
699 * Wan subdriver
700 */
701
702enum {
703 /* ACPI GWAN/SWAN bits */
704 TP_ACPI_WANCARD_HWPRESENT = 0x01, /* Wan hw available */
705 TP_ACPI_WANCARD_RADIOSSW = 0x02, /* Wan radio enabled */
706 TP_ACPI_WANCARD_UNK = 0x04, /* unknown function */
707};
708
709static int wan_init(struct ibm_init_struct *iibm);
710static int wan_get_radiosw(void);
711static int wan_set_radiosw(int radio_on);
712static int wan_read(char *p);
713static int wan_write(char *buf);
714
715/* ==================================================== END HEADER */
716 301
717MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh"); 302MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh");
718MODULE_DESCRIPTION(IBM_DESC); 303MODULE_DESCRIPTION(IBM_DESC);
@@ -948,6 +533,10 @@ static int issue_thinkpad_cmos_command(int cmos_cmd)
948 * ACPI device model 533 * ACPI device model
949 */ 534 */
950 535
536#define IBM_ACPIHANDLE_INIT(object) \
537 drv_acpi_handle_init(#object, &object##_handle, *object##_parent, \
538 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
539
951static void drv_acpi_handle_init(char *name, 540static void drv_acpi_handle_init(char *name,
952 acpi_handle *handle, acpi_handle parent, 541 acpi_handle *handle, acpi_handle parent,
953 char **paths, int num_paths, char **path) 542 char **paths, int num_paths, char **path)
@@ -1298,6 +887,9 @@ static struct attribute_set *create_attr_set(unsigned int max_members,
1298 return &sobj->s; 887 return &sobj->s;
1299} 888}
1300 889
890#define destroy_attr_set(_set) \
891 kfree(_set);
892
1301/* not multi-threaded safe, use it in a single thread per set */ 893/* not multi-threaded safe, use it in a single thread per set */
1302static int add_to_attr_set(struct attribute_set* s, struct attribute *attr) 894static int add_to_attr_set(struct attribute_set* s, struct attribute *attr)
1303{ 895{
@@ -1334,6 +926,9 @@ static void delete_attr_set(struct attribute_set* s, struct kobject *kobj)
1334 destroy_attr_set(s); 926 destroy_attr_set(s);
1335} 927}
1336 928
929#define register_attr_set_with_sysfs(_attr_set, _kobj) \
930 sysfs_create_group(_kobj, &_attr_set->group)
931
1337static int parse_strtoul(const char *buf, 932static int parse_strtoul(const char *buf,
1338 unsigned long max, unsigned long *value) 933 unsigned long max, unsigned long *value)
1339{ 934{
@@ -1403,6 +998,33 @@ static struct ibm_struct thinkpad_acpi_driver_data = {
1403 * Hotkey subdriver 998 * Hotkey subdriver
1404 */ 999 */
1405 1000
1001enum { /* hot key scan codes (derived from ACPI DSDT) */
1002 TP_ACPI_HOTKEYSCAN_FNF1 = 0,
1003 TP_ACPI_HOTKEYSCAN_FNF2,
1004 TP_ACPI_HOTKEYSCAN_FNF3,
1005 TP_ACPI_HOTKEYSCAN_FNF4,
1006 TP_ACPI_HOTKEYSCAN_FNF5,
1007 TP_ACPI_HOTKEYSCAN_FNF6,
1008 TP_ACPI_HOTKEYSCAN_FNF7,
1009 TP_ACPI_HOTKEYSCAN_FNF8,
1010 TP_ACPI_HOTKEYSCAN_FNF9,
1011 TP_ACPI_HOTKEYSCAN_FNF10,
1012 TP_ACPI_HOTKEYSCAN_FNF11,
1013 TP_ACPI_HOTKEYSCAN_FNF12,
1014 TP_ACPI_HOTKEYSCAN_FNBACKSPACE,
1015 TP_ACPI_HOTKEYSCAN_FNINSERT,
1016 TP_ACPI_HOTKEYSCAN_FNDELETE,
1017 TP_ACPI_HOTKEYSCAN_FNHOME,
1018 TP_ACPI_HOTKEYSCAN_FNEND,
1019 TP_ACPI_HOTKEYSCAN_FNPAGEUP,
1020 TP_ACPI_HOTKEYSCAN_FNPAGEDOWN,
1021 TP_ACPI_HOTKEYSCAN_FNSPACE,
1022 TP_ACPI_HOTKEYSCAN_VOLUMEUP,
1023 TP_ACPI_HOTKEYSCAN_VOLUMEDOWN,
1024 TP_ACPI_HOTKEYSCAN_MUTE,
1025 TP_ACPI_HOTKEYSCAN_THINKPAD,
1026};
1027
1406enum { /* Keys available through NVRAM polling */ 1028enum { /* Keys available through NVRAM polling */
1407 TPACPI_HKEY_NVRAM_KNOWN_MASK = 0x00fb88c0U, 1029 TPACPI_HKEY_NVRAM_KNOWN_MASK = 0x00fb88c0U,
1408 TPACPI_HKEY_NVRAM_GOOD_MASK = 0x00fb8000U, 1030 TPACPI_HKEY_NVRAM_GOOD_MASK = 0x00fb8000U,
@@ -1464,6 +1086,8 @@ static unsigned int hotkey_config_change;
1464 1086
1465#endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */ 1087#endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
1466 1088
1089static struct mutex hotkey_mutex;
1090
1467static int hotkey_orig_status; 1091static int hotkey_orig_status;
1468static u32 hotkey_orig_mask; 1092static u32 hotkey_orig_mask;
1469static u32 hotkey_all_mask; 1093static u32 hotkey_all_mask;
@@ -2635,6 +2259,16 @@ static struct ibm_struct hotkey_driver_data = {
2635 * Bluetooth subdriver 2259 * Bluetooth subdriver
2636 */ 2260 */
2637 2261
2262enum {
2263 /* ACPI GBDC/SBDC bits */
2264 TP_ACPI_BLUETOOTH_HWPRESENT = 0x01, /* Bluetooth hw available */
2265 TP_ACPI_BLUETOOTH_RADIOSSW = 0x02, /* Bluetooth radio enabled */
2266 TP_ACPI_BLUETOOTH_UNK = 0x04, /* unknown function */
2267};
2268
2269static int bluetooth_get_radiosw(void);
2270static int bluetooth_set_radiosw(int radio_on);
2271
2638/* sysfs bluetooth enable ---------------------------------------------- */ 2272/* sysfs bluetooth enable ---------------------------------------------- */
2639static ssize_t bluetooth_enable_show(struct device *dev, 2273static ssize_t bluetooth_enable_show(struct device *dev,
2640 struct device_attribute *attr, 2274 struct device_attribute *attr,
@@ -2799,6 +2433,16 @@ static struct ibm_struct bluetooth_driver_data = {
2799 * Wan subdriver 2433 * Wan subdriver
2800 */ 2434 */
2801 2435
2436enum {
2437 /* ACPI GWAN/SWAN bits */
2438 TP_ACPI_WANCARD_HWPRESENT = 0x01, /* Wan hw available */
2439 TP_ACPI_WANCARD_RADIOSSW = 0x02, /* Wan radio enabled */
2440 TP_ACPI_WANCARD_UNK = 0x04, /* unknown function */
2441};
2442
2443static int wan_get_radiosw(void);
2444static int wan_set_radiosw(int radio_on);
2445
2802/* sysfs wan enable ---------------------------------------------------- */ 2446/* sysfs wan enable ---------------------------------------------------- */
2803static ssize_t wan_enable_show(struct device *dev, 2447static ssize_t wan_enable_show(struct device *dev,
2804 struct device_attribute *attr, 2448 struct device_attribute *attr,
@@ -2962,9 +2606,33 @@ static struct ibm_struct wan_driver_data = {
2962 * Video subdriver 2606 * Video subdriver
2963 */ 2607 */
2964 2608
2609enum video_access_mode {
2610 TPACPI_VIDEO_NONE = 0,
2611 TPACPI_VIDEO_570, /* 570 */
2612 TPACPI_VIDEO_770, /* 600e/x, 770e, 770x */
2613 TPACPI_VIDEO_NEW, /* all others */
2614};
2615
2616enum { /* video status flags, based on VIDEO_570 */
2617 TP_ACPI_VIDEO_S_LCD = 0x01, /* LCD output enabled */
2618 TP_ACPI_VIDEO_S_CRT = 0x02, /* CRT output enabled */
2619 TP_ACPI_VIDEO_S_DVI = 0x08, /* DVI output enabled */
2620};
2621
2622enum { /* TPACPI_VIDEO_570 constants */
2623 TP_ACPI_VIDEO_570_PHSCMD = 0x87, /* unknown magic constant :( */
2624 TP_ACPI_VIDEO_570_PHSMASK = 0x03, /* PHS bits that map to
2625 * video_status_flags */
2626 TP_ACPI_VIDEO_570_PHS2CMD = 0x8b, /* unknown magic constant :( */
2627 TP_ACPI_VIDEO_570_PHS2SET = 0x80, /* unknown magic constant :( */
2628};
2629
2965static enum video_access_mode video_supported; 2630static enum video_access_mode video_supported;
2966static int video_orig_autosw; 2631static int video_orig_autosw;
2967 2632
2633static int video_autosw_get(void);
2634static int video_autosw_set(int enable);
2635
2968IBM_HANDLE(vid, root, "\\_SB.PCI.AGP.VGA", /* 570 */ 2636IBM_HANDLE(vid, root, "\\_SB.PCI.AGP.VGA", /* 570 */
2969 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */ 2637 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
2970 "\\_SB.PCI0.VID0", /* 770e */ 2638 "\\_SB.PCI0.VID0", /* 770e */
@@ -3370,6 +3038,10 @@ static struct ibm_struct light_driver_data = {
3370 3038
3371#ifdef CONFIG_THINKPAD_ACPI_DOCK 3039#ifdef CONFIG_THINKPAD_ACPI_DOCK
3372 3040
3041static void dock_notify(struct ibm_struct *ibm, u32 event);
3042static int dock_read(char *p);
3043static int dock_write(char *buf);
3044
3373IBM_HANDLE(dock, root, "\\_SB.GDCK", /* X30, X31, X40 */ 3045IBM_HANDLE(dock, root, "\\_SB.GDCK", /* X30, X31, X40 */
3374 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */ 3046 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
3375 "\\_SB.PCI0.PCI1.DOCK", /* all others */ 3047 "\\_SB.PCI0.PCI1.DOCK", /* all others */
@@ -3524,6 +3196,7 @@ static int dock_write(char *buf)
3524 */ 3196 */
3525 3197
3526#ifdef CONFIG_THINKPAD_ACPI_BAY 3198#ifdef CONFIG_THINKPAD_ACPI_BAY
3199
3527IBM_HANDLE(bay, root, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */ 3200IBM_HANDLE(bay, root, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
3528 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */ 3201 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
3529 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */ 3202 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
@@ -3741,6 +3414,19 @@ static struct ibm_struct cmos_driver_data = {
3741 * LED subdriver 3414 * LED subdriver
3742 */ 3415 */
3743 3416
3417enum led_access_mode {
3418 TPACPI_LED_NONE = 0,
3419 TPACPI_LED_570, /* 570 */
3420 TPACPI_LED_OLD, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
3421 TPACPI_LED_NEW, /* all others */
3422};
3423
3424enum { /* For TPACPI_LED_OLD */
3425 TPACPI_LED_EC_HLCL = 0x0c, /* EC reg to get led to power on */
3426 TPACPI_LED_EC_HLBL = 0x0d, /* EC reg to blink a lit led */
3427 TPACPI_LED_EC_HLMS = 0x0e, /* EC reg to select led to command */
3428};
3429
3744static enum led_access_mode led_supported; 3430static enum led_access_mode led_supported;
3745 3431
3746IBM_HANDLE(led, ec, "SLED", /* 570 */ 3432IBM_HANDLE(led, ec, "SLED", /* 570 */
@@ -3930,8 +3616,30 @@ static struct ibm_struct beep_driver_data = {
3930 * Thermal subdriver 3616 * Thermal subdriver
3931 */ 3617 */
3932 3618
3619enum thermal_access_mode {
3620 TPACPI_THERMAL_NONE = 0, /* No thermal support */
3621 TPACPI_THERMAL_ACPI_TMP07, /* Use ACPI TMP0-7 */
3622 TPACPI_THERMAL_ACPI_UPDT, /* Use ACPI TMP0-7 with UPDT */
3623 TPACPI_THERMAL_TPEC_8, /* Use ACPI EC regs, 8 sensors */
3624 TPACPI_THERMAL_TPEC_16, /* Use ACPI EC regs, 16 sensors */
3625};
3626
3627enum { /* TPACPI_THERMAL_TPEC_* */
3628 TP_EC_THERMAL_TMP0 = 0x78, /* ACPI EC regs TMP 0..7 */
3629 TP_EC_THERMAL_TMP8 = 0xC0, /* ACPI EC regs TMP 8..15 */
3630 TP_EC_THERMAL_TMP_NA = -128, /* ACPI EC sensor not available */
3631};
3632
3633#define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
3634struct ibm_thermal_sensors_struct {
3635 s32 temp[TPACPI_MAX_THERMAL_SENSORS];
3636};
3637
3933static enum thermal_access_mode thermal_read_mode; 3638static enum thermal_access_mode thermal_read_mode;
3934 3639
3640static int thermal_get_sensor(int idx, s32 *value);
3641static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s);
3642
3935/* sysfs temp##_input -------------------------------------------------- */ 3643/* sysfs temp##_input -------------------------------------------------- */
3936 3644
3937static ssize_t thermal_temp_input_show(struct device *dev, 3645static ssize_t thermal_temp_input_show(struct device *dev,
@@ -4306,7 +4014,16 @@ static struct ibm_struct ecdump_driver_data = {
4306 * Backlight/brightness subdriver 4014 * Backlight/brightness subdriver
4307 */ 4015 */
4308 4016
4017#define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen"
4018
4309static struct backlight_device *ibm_backlight_device; 4019static struct backlight_device *ibm_backlight_device;
4020static int brightness_offset = 0x31;
4021static int brightness_mode;
4022static unsigned int brightness_enable = 2; /* 2 = auto, 0 = no, 1 = yes */
4023
4024static int brightness_get(struct backlight_device *bd);
4025static int brightness_set(int value);
4026static int brightness_update_status(struct backlight_device *bd);
4310 4027
4311static struct backlight_ops ibm_backlight_data = { 4028static struct backlight_ops ibm_backlight_data = {
4312 .get_brightness = brightness_get, 4029 .get_brightness = brightness_get,
@@ -4628,6 +4345,8 @@ static struct ibm_struct brightness_driver_data = {
4628 * Volume subdriver 4345 * Volume subdriver
4629 */ 4346 */
4630 4347
4348static int volume_offset = 0x30;
4349
4631static int volume_read(char *p) 4350static int volume_read(char *p)
4632{ 4351{
4633 int len = 0; 4352 int len = 0;
@@ -4819,15 +4538,59 @@ static struct ibm_struct volume_driver_data = {
4819 * but the ACPI tables just mention level 7. 4538 * but the ACPI tables just mention level 7.
4820 */ 4539 */
4821 4540
4541enum { /* Fan control constants */
4542 fan_status_offset = 0x2f, /* EC register 0x2f */
4543 fan_rpm_offset = 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
4544 * 0x84 must be read before 0x85 */
4545
4546 TP_EC_FAN_FULLSPEED = 0x40, /* EC fan mode: full speed */
4547 TP_EC_FAN_AUTO = 0x80, /* EC fan mode: auto fan control */
4548
4549 TPACPI_FAN_LAST_LEVEL = 0x100, /* Use cached last-seen fan level */
4550};
4551
4552enum fan_status_access_mode {
4553 TPACPI_FAN_NONE = 0, /* No fan status or control */
4554 TPACPI_FAN_RD_ACPI_GFAN, /* Use ACPI GFAN */
4555 TPACPI_FAN_RD_TPEC, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
4556};
4557
4558enum fan_control_access_mode {
4559 TPACPI_FAN_WR_NONE = 0, /* No fan control */
4560 TPACPI_FAN_WR_ACPI_SFAN, /* Use ACPI SFAN */
4561 TPACPI_FAN_WR_TPEC, /* Use ACPI EC reg 0x2f */
4562 TPACPI_FAN_WR_ACPI_FANS, /* Use ACPI FANS and EC reg 0x2f */
4563};
4564
4565enum fan_control_commands {
4566 TPACPI_FAN_CMD_SPEED = 0x0001, /* speed command */
4567 TPACPI_FAN_CMD_LEVEL = 0x0002, /* level command */
4568 TPACPI_FAN_CMD_ENABLE = 0x0004, /* enable/disable cmd,
4569 * and also watchdog cmd */
4570};
4571
4572static int fan_control_allowed;
4573
4822static enum fan_status_access_mode fan_status_access_mode; 4574static enum fan_status_access_mode fan_status_access_mode;
4823static enum fan_control_access_mode fan_control_access_mode; 4575static enum fan_control_access_mode fan_control_access_mode;
4824static enum fan_control_commands fan_control_commands; 4576static enum fan_control_commands fan_control_commands;
4825 4577
4826static u8 fan_control_initial_status; 4578static u8 fan_control_initial_status;
4827static u8 fan_control_desired_level; 4579static u8 fan_control_desired_level;
4580static int fan_watchdog_maxinterval;
4581
4582static struct mutex fan_mutex;
4828 4583
4584static int fan_get_status(u8 *status);
4585static int fan_get_status_safe(u8 *status);
4586static int fan_get_speed(unsigned int *speed);
4587static void fan_update_desired_level(u8 status);
4829static void fan_watchdog_fire(struct work_struct *ignored); 4588static void fan_watchdog_fire(struct work_struct *ignored);
4830static int fan_watchdog_maxinterval; 4589static void fan_watchdog_reset(void);
4590static int fan_set_level(int level);
4591static int fan_set_level_safe(int level);
4592static int fan_set_enable(void);
4593
4831static DECLARE_DELAYED_WORK(fan_watchdog_task, fan_watchdog_fire); 4594static DECLARE_DELAYED_WORK(fan_watchdog_task, fan_watchdog_fire);
4832 4595
4833IBM_HANDLE(fans, ec, "FANS"); /* X31, X40, X41 */ 4596IBM_HANDLE(fans, ec, "FANS"); /* X31, X40, X41 */
@@ -5710,9 +5473,6 @@ static struct device_attribute dev_attr_thinkpad_acpi_pdev_name =
5710/* /proc support */ 5473/* /proc support */
5711static struct proc_dir_entry *proc_dir; 5474static struct proc_dir_entry *proc_dir;
5712 5475
5713/* Subdriver registry */
5714static LIST_HEAD(tpacpi_all_drivers);
5715
5716 5476
5717/* 5477/*
5718 * Module and infrastructure proble, init and exit handling 5478 * Module and infrastructure proble, init and exit handling
@@ -5727,6 +5487,8 @@ static const char * __init str_supported(int is_supported)
5727} 5487}
5728#endif /* CONFIG_THINKPAD_ACPI_DEBUG */ 5488#endif /* CONFIG_THINKPAD_ACPI_DEBUG */
5729 5489
5490static void ibm_exit(struct ibm_struct *ibm);
5491
5730static int __init ibm_init(struct ibm_init_struct *iibm) 5492static int __init ibm_init(struct ibm_init_struct *iibm)
5731{ 5493{
5732 int ret; 5494 int ret;
@@ -6042,25 +5804,18 @@ static int __init set_ibm_param(const char *val, struct kernel_param *kp)
6042 return -EINVAL; 5804 return -EINVAL;
6043} 5805}
6044 5806
6045static int experimental;
6046module_param(experimental, int, 0); 5807module_param(experimental, int, 0);
6047 5808
6048static u32 dbg_level;
6049module_param_named(debug, dbg_level, uint, 0); 5809module_param_named(debug, dbg_level, uint, 0);
6050 5810
6051static int force_load;
6052module_param(force_load, bool, 0); 5811module_param(force_load, bool, 0);
6053 5812
6054static int fan_control_allowed;
6055module_param_named(fan_control, fan_control_allowed, bool, 0); 5813module_param_named(fan_control, fan_control_allowed, bool, 0);
6056 5814
6057static int brightness_mode;
6058module_param_named(brightness_mode, brightness_mode, int, 0); 5815module_param_named(brightness_mode, brightness_mode, int, 0);
6059 5816
6060static unsigned int brightness_enable = 2; /* 2 = auto, 0 = no, 1 = yes */
6061module_param(brightness_enable, uint, 0); 5817module_param(brightness_enable, uint, 0);
6062 5818
6063static unsigned int hotkey_report_mode;
6064module_param(hotkey_report_mode, uint, 0); 5819module_param(hotkey_report_mode, uint, 0);
6065 5820
6066#define IBM_PARAM(feature) \ 5821#define IBM_PARAM(feature) \
@@ -6084,6 +5839,8 @@ IBM_PARAM(brightness);
6084IBM_PARAM(volume); 5839IBM_PARAM(volume);
6085IBM_PARAM(fan); 5840IBM_PARAM(fan);
6086 5841
5842static void thinkpad_acpi_module_exit(void);
5843
6087static int __init thinkpad_acpi_module_init(void) 5844static int __init thinkpad_acpi_module_init(void)
6088{ 5845{
6089 int ret, i; 5846 int ret, i;