# --- T2-COPYRIGHT-NOTE-BEGIN --- # This copyright note is auto-generated by ./scripts/Create-CopyPatch. # # T2 SDE: package/.../linux26/applesmc-led.patch # Copyright (C) 2008 - 2011 The T2 SDE Project # # More information can be found in the files COPYING and README. # # This patch file is dual-licensed. It is available under the license the # patched project is licensed under, as long as it is an OpenSource license # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms # of the GNU General Public License as published by the Free Software # Foundation; either version 2 of the License, or (at your option) any later # version. # --- T2-COPYRIGHT-NOTE-END --- LED activity indicator for Apple Intel hardware thru applesmc. The SMC key used might not be perfect, it should rise the off level, however the other ones sounding more appropriate did not work. Signed-off-by: René Rebe --- linux-2.6.38/drivers/hwmon/applesmc.c.vanilla 2011-03-24 13:45:26.000000000 +0000 +++ linux-2.6.38/drivers/hwmon/applesmc.c 2011-03-24 14:08:37.000000000 +0000 @@ -68,6 +68,7 @@ #define LIGHT_SENSOR_LEFT_KEY "ALV0" /* r-o {alv (6-10 bytes) */ #define LIGHT_SENSOR_RIGHT_KEY "ALV1" /* r-o {alv (6-10 bytes) */ #define BACKLIGHT_KEY "LKSB" /* w-o {lkb (2 bytes) */ +#define LED_KEY "LSLF" /* r-w ui16 */ #define CLAMSHELL_KEY "MSLD" /* r-o ui8 (unused) */ @@ -138,6 +139,7 @@ int num_light_sensors; /* number of light sensors */ bool has_accelerometer; /* has motion sensor */ bool has_key_backlight; /* has keyboard backlight */ + bool has_key_led; /* has case led light */ bool init_complete; /* true when fully initialized */ struct applesmc_entry *cache; /* cached key entries */ } smcreg = { @@ -148,7 +150,7 @@ static struct platform_device *pdev; static s16 rest_x; static s16 rest_y; -static u8 backlight_state[2]; +static u8 backlight_state[2], backlight_state2[2]; static struct device *hwmon_dev; static struct input_polled_dev *applesmc_idev; @@ -159,7 +161,7 @@ */ static unsigned int key_at_index; -static struct workqueue_struct *applesmc_led_wq; +static struct workqueue_struct *applesmc_led_wq, *applesmc_led2_wq; /* * __wait_status - Wait up to 32ms for the status port to get a certain value @@ -525,6 +527,9 @@ ret = applesmc_has_key(BACKLIGHT_KEY, &s->has_key_backlight); if (ret) return ret; + ret = applesmc_has_key(LED_KEY, &s->has_key_led); + if (ret) + return ret; s->num_light_sensors = left_light_sensor + right_light_sensor; s->init_complete = true; @@ -897,6 +903,24 @@ printk(KERN_DEBUG "applesmc: work was already on the queue.\n"); } +static void applesmc_backlight2_set(struct work_struct *work) +{ + applesmc_write_key(LED_KEY, backlight_state2, 2); +} +static DECLARE_WORK(backlight2_work, &applesmc_backlight2_set); + +static void applesmc_brightness2_set(struct led_classdev *led_cdev, + enum led_brightness value) +{ + int ret; + + backlight_state2[0] = value; + ret = queue_work(applesmc_led2_wq, &backlight2_work); + + if (debug && (!ret)) + printk(KERN_DEBUG "applesmc: work was already on the queue.\n"); +} + static ssize_t applesmc_key_count_show(struct device *dev, struct device_attribute *attr, char *sysfsbuf) { @@ -991,6 +1015,12 @@ .brightness_set = applesmc_brightness_set, }; +static struct led_classdev applesmc_led = { + .name = "smc::case-led", + .default_trigger = "ide-disk", + .brightness_set = applesmc_brightness2_set, +}; + static struct applesmc_node_group info_group[] = { { "name", applesmc_name_show }, { "key_count", applesmc_key_count_show }, @@ -1184,6 +1214,24 @@ destroy_workqueue(applesmc_led_wq); } +static int applesmc_create_case_led(void) +{ + if (!smcreg.has_key_led) + return 0; + applesmc_led2_wq = create_singlethread_workqueue("applesmc-led2"); + if (!applesmc_led2_wq) + return -ENOMEM; + return led_classdev_register(&pdev->dev, &applesmc_led); +} + +static void applesmc_release_case_led(void) +{ + if (!smcreg.has_key_led) + return; + led_classdev_unregister(&applesmc_led); + destroy_workqueue(applesmc_led2_wq); +} + static int applesmc_dmi_match(const struct dmi_system_id *id) { return 1; @@ -1275,6 +1323,10 @@ if (ret) goto out_light_sysfs; + ret = applesmc_create_case_led(); + if (ret) + goto out_led_sysfs; + hwmon_dev = hwmon_device_register(&pdev->dev); if (IS_ERR(hwmon_dev)) { ret = PTR_ERR(hwmon_dev); @@ -1284,6 +1336,8 @@ return 0; out_light_ledclass: + applesmc_release_case_led(); +out_led_sysfs: applesmc_release_key_backlight(); out_light_sysfs: applesmc_release_light_sensor(); @@ -1311,6 +1365,7 @@ static void __exit applesmc_exit(void) { hwmon_device_unregister(hwmon_dev); + applesmc_release_case_led(); applesmc_release_key_backlight(); applesmc_release_light_sensor(); applesmc_release_accelerometer();