Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * via-pmu LED class device
0003  *
0004  * Copyright 2006 Johannes Berg <johannes@sipsolutions.net>
0005  *
0006  * This program is free software; you can redistribute it and/or modify
0007  * it under the terms of the GNU General Public License as published by
0008  * the Free Software Foundation; either version 2 of the License, or
0009  * (at your option) any later version.
0010  *
0011  * This program is distributed in the hope that it will be useful, but
0012  * WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
0014  * NON INFRINGEMENT.  See the GNU General Public License for more
0015  * details.
0016  *
0017  * You should have received a copy of the GNU General Public License
0018  * along with this program; if not, write to the Free Software
0019  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
0020  *
0021  */
0022 #include <linux/types.h>
0023 #include <linux/kernel.h>
0024 #include <linux/device.h>
0025 #include <linux/leds.h>
0026 #include <linux/adb.h>
0027 #include <linux/pmu.h>
0028 #include <linux/of.h>
0029 
0030 static spinlock_t pmu_blink_lock;
0031 static struct adb_request pmu_blink_req;
0032 /* -1: no change, 0: request off, 1: request on */
0033 static int requested_change;
0034 
0035 static void pmu_req_done(struct adb_request * req)
0036 {
0037     unsigned long flags;
0038 
0039     spin_lock_irqsave(&pmu_blink_lock, flags);
0040     /* if someone requested a change in the meantime
0041      * (we only see the last one which is fine)
0042      * then apply it now */
0043     if (requested_change != -1 && !pmu_sys_suspended)
0044         pmu_request(&pmu_blink_req, NULL, 4, 0xee, 4, 0, requested_change);
0045     /* reset requested change */
0046     requested_change = -1;
0047     spin_unlock_irqrestore(&pmu_blink_lock, flags);
0048 }
0049 
0050 static void pmu_led_set(struct led_classdev *led_cdev,
0051             enum led_brightness brightness)
0052 {
0053     unsigned long flags;
0054 
0055     spin_lock_irqsave(&pmu_blink_lock, flags);
0056     switch (brightness) {
0057     case LED_OFF:
0058         requested_change = 0;
0059         break;
0060     case LED_FULL:
0061         requested_change = 1;
0062         break;
0063     default:
0064         goto out;
0065         break;
0066     }
0067     /* if request isn't done, then don't do anything */
0068     if (pmu_blink_req.complete && !pmu_sys_suspended)
0069         pmu_request(&pmu_blink_req, NULL, 4, 0xee, 4, 0, requested_change);
0070  out:
0071     spin_unlock_irqrestore(&pmu_blink_lock, flags);
0072 }
0073 
0074 static struct led_classdev pmu_led = {
0075     .name = "pmu-led::front",
0076 #ifdef CONFIG_ADB_PMU_LED_DISK
0077     .default_trigger = "disk-activity",
0078 #endif
0079     .brightness_set = pmu_led_set,
0080 };
0081 
0082 static int __init via_pmu_led_init(void)
0083 {
0084     struct device_node *dt;
0085     const char *model;
0086 
0087     /* only do this on keylargo based models */
0088     if (pmu_get_model() != PMU_KEYLARGO_BASED)
0089         return -ENODEV;
0090 
0091     dt = of_find_node_by_path("/");
0092     if (dt == NULL)
0093         return -ENODEV;
0094     model = of_get_property(dt, "model", NULL);
0095     if (model == NULL) {
0096         of_node_put(dt);
0097         return -ENODEV;
0098     }
0099     if (strncmp(model, "PowerBook", strlen("PowerBook")) != 0 &&
0100         strncmp(model, "iBook", strlen("iBook")) != 0 &&
0101         strcmp(model, "PowerMac7,2") != 0 &&
0102         strcmp(model, "PowerMac7,3") != 0) {
0103         of_node_put(dt);
0104         /* ignore */
0105         return -ENODEV;
0106     }
0107     of_node_put(dt);
0108 
0109     spin_lock_init(&pmu_blink_lock);
0110     /* no outstanding req */
0111     pmu_blink_req.complete = 1;
0112     pmu_blink_req.done = pmu_req_done;
0113 
0114     return led_classdev_register(NULL, &pmu_led);
0115 }
0116 
0117 late_initcall(via_pmu_led_init);