1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
4 # T2 SDE: package/.../linux26/applesmc-led.patch
5 # Copyright (C) 2008 - 2011 The T2 SDE Project
7 # More information can be found in the files COPYING and README.
9 # This patch file is dual-licensed. It is available under the license the
10 # patched project is licensed under, as long as it is an OpenSource license
11 # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
12 # of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
15 # --- T2-COPYRIGHT-NOTE-END ---
17 LED activity indicator for Apple Intel hardware thru applesmc.
19 The SMC key used might not be perfect, it should rise the off
20 level, however the other ones sounding more appropriate did
23 Signed-off-by: René Rebe <rene@exactcode.de>
25 --- linux-2.6.38/drivers/hwmon/applesmc.c.vanilla 2011-03-24 13:45:26.000000000 +0000
26 +++ linux-2.6.38/drivers/hwmon/applesmc.c 2011-03-24 14:08:37.000000000 +0000
28 #define LIGHT_SENSOR_LEFT_KEY "ALV0" /* r-o {alv (6-10 bytes) */
29 #define LIGHT_SENSOR_RIGHT_KEY "ALV1" /* r-o {alv (6-10 bytes) */
30 #define BACKLIGHT_KEY "LKSB" /* w-o {lkb (2 bytes) */
31 +#define LED_KEY "LSLF" /* r-w ui16 */
33 #define CLAMSHELL_KEY "MSLD" /* r-o ui8 (unused) */
36 int num_light_sensors; /* number of light sensors */
37 bool has_accelerometer; /* has motion sensor */
38 bool has_key_backlight; /* has keyboard backlight */
39 + bool has_key_led; /* has case led light */
40 bool init_complete; /* true when fully initialized */
41 struct applesmc_entry *cache; /* cached key entries */
44 static struct platform_device *pdev;
47 -static u8 backlight_state[2];
48 +static u8 backlight_state[2], backlight_state2[2];
50 static struct device *hwmon_dev;
51 static struct input_polled_dev *applesmc_idev;
54 static unsigned int key_at_index;
56 -static struct workqueue_struct *applesmc_led_wq;
57 +static struct workqueue_struct *applesmc_led_wq, *applesmc_led2_wq;
60 * __wait_status - Wait up to 32ms for the status port to get a certain value
62 ret = applesmc_has_key(BACKLIGHT_KEY, &s->has_key_backlight);
65 + ret = applesmc_has_key(LED_KEY, &s->has_key_led);
69 s->num_light_sensors = left_light_sensor + right_light_sensor;
70 s->init_complete = true;
72 printk(KERN_DEBUG "applesmc: work was already on the queue.\n");
75 +static void applesmc_backlight2_set(struct work_struct *work)
77 + applesmc_write_key(LED_KEY, backlight_state2, 2);
79 +static DECLARE_WORK(backlight2_work, &applesmc_backlight2_set);
81 +static void applesmc_brightness2_set(struct led_classdev *led_cdev,
82 + enum led_brightness value)
86 + backlight_state2[0] = value;
87 + ret = queue_work(applesmc_led2_wq, &backlight2_work);
89 + if (debug && (!ret))
90 + printk(KERN_DEBUG "applesmc: work was already on the queue.\n");
93 static ssize_t applesmc_key_count_show(struct device *dev,
94 struct device_attribute *attr, char *sysfsbuf)
97 .brightness_set = applesmc_brightness_set,
100 +static struct led_classdev applesmc_led = {
101 + .name = "smc::case-led",
102 + .default_trigger = "ide-disk",
103 + .brightness_set = applesmc_brightness2_set,
106 static struct applesmc_node_group info_group[] = {
107 { "name", applesmc_name_show },
108 { "key_count", applesmc_key_count_show },
109 @@ -1184,6 +1214,24 @@
110 destroy_workqueue(applesmc_led_wq);
113 +static int applesmc_create_case_led(void)
115 + if (!smcreg.has_key_led)
117 + applesmc_led2_wq = create_singlethread_workqueue("applesmc-led2");
118 + if (!applesmc_led2_wq)
120 + return led_classdev_register(&pdev->dev, &applesmc_led);
123 +static void applesmc_release_case_led(void)
125 + if (!smcreg.has_key_led)
127 + led_classdev_unregister(&applesmc_led);
128 + destroy_workqueue(applesmc_led2_wq);
131 static int applesmc_dmi_match(const struct dmi_system_id *id)
134 @@ -1275,6 +1323,10 @@
136 goto out_light_sysfs;
138 + ret = applesmc_create_case_led();
140 + goto out_led_sysfs;
142 hwmon_dev = hwmon_device_register(&pdev->dev);
143 if (IS_ERR(hwmon_dev)) {
144 ret = PTR_ERR(hwmon_dev);
145 @@ -1284,6 +1336,8 @@
149 + applesmc_release_case_led();
151 applesmc_release_key_backlight();
153 applesmc_release_light_sensor();
154 @@ -1311,6 +1365,7 @@
155 static void __exit applesmc_exit(void)
157 hwmon_device_unregister(hwmon_dev);
158 + applesmc_release_case_led();
159 applesmc_release_key_backlight();
160 applesmc_release_light_sensor();
161 applesmc_release_accelerometer();