ALSA: hda - Add quirk for Dell Vostro 1220
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / power / power_supply_leds.c
blob031a554837f78d2958b2c3368268c27466251837
1 /*
2 * LEDs triggers for power supply class
4 * Copyright © 2007 Anton Vorontsov <cbou@mail.ru>
5 * Copyright © 2004 Szabolcs Gyurko
6 * Copyright © 2003 Ian Molton <spyro@f2s.com>
8 * Modified: 2004, Oct Szabolcs Gyurko
10 * You may use this code as per GPL version 2
13 #include <linux/kernel.h>
14 #include <linux/power_supply.h>
15 #include <linux/slab.h>
17 #include "power_supply.h"
19 /* Battery specific LEDs triggers. */
21 static void power_supply_update_bat_leds(struct power_supply *psy)
23 union power_supply_propval status;
25 if (psy->get_property(psy, POWER_SUPPLY_PROP_STATUS, &status))
26 return;
28 dev_dbg(psy->dev, "%s %d\n", __func__, status.intval);
30 switch (status.intval) {
31 case POWER_SUPPLY_STATUS_FULL:
32 led_trigger_event(psy->charging_full_trig, LED_FULL);
33 led_trigger_event(psy->charging_trig, LED_OFF);
34 led_trigger_event(psy->full_trig, LED_FULL);
35 break;
36 case POWER_SUPPLY_STATUS_CHARGING:
37 led_trigger_event(psy->charging_full_trig, LED_FULL);
38 led_trigger_event(psy->charging_trig, LED_FULL);
39 led_trigger_event(psy->full_trig, LED_OFF);
40 break;
41 default:
42 led_trigger_event(psy->charging_full_trig, LED_OFF);
43 led_trigger_event(psy->charging_trig, LED_OFF);
44 led_trigger_event(psy->full_trig, LED_OFF);
45 break;
49 static int power_supply_create_bat_triggers(struct power_supply *psy)
51 int rc = 0;
53 psy->charging_full_trig_name = kasprintf(GFP_KERNEL,
54 "%s-charging-or-full", psy->name);
55 if (!psy->charging_full_trig_name)
56 goto charging_full_failed;
58 psy->charging_trig_name = kasprintf(GFP_KERNEL,
59 "%s-charging", psy->name);
60 if (!psy->charging_trig_name)
61 goto charging_failed;
63 psy->full_trig_name = kasprintf(GFP_KERNEL, "%s-full", psy->name);
64 if (!psy->full_trig_name)
65 goto full_failed;
67 led_trigger_register_simple(psy->charging_full_trig_name,
68 &psy->charging_full_trig);
69 led_trigger_register_simple(psy->charging_trig_name,
70 &psy->charging_trig);
71 led_trigger_register_simple(psy->full_trig_name,
72 &psy->full_trig);
74 goto success;
76 full_failed:
77 kfree(psy->charging_trig_name);
78 charging_failed:
79 kfree(psy->charging_full_trig_name);
80 charging_full_failed:
81 rc = -ENOMEM;
82 success:
83 return rc;
86 static void power_supply_remove_bat_triggers(struct power_supply *psy)
88 led_trigger_unregister_simple(psy->charging_full_trig);
89 led_trigger_unregister_simple(psy->charging_trig);
90 led_trigger_unregister_simple(psy->full_trig);
91 kfree(psy->full_trig_name);
92 kfree(psy->charging_trig_name);
93 kfree(psy->charging_full_trig_name);
96 /* Generated power specific LEDs triggers. */
98 static void power_supply_update_gen_leds(struct power_supply *psy)
100 union power_supply_propval online;
102 if (psy->get_property(psy, POWER_SUPPLY_PROP_ONLINE, &online))
103 return;
105 dev_dbg(psy->dev, "%s %d\n", __func__, online.intval);
107 if (online.intval)
108 led_trigger_event(psy->online_trig, LED_FULL);
109 else
110 led_trigger_event(psy->online_trig, LED_OFF);
113 static int power_supply_create_gen_triggers(struct power_supply *psy)
115 int rc = 0;
117 psy->online_trig_name = kasprintf(GFP_KERNEL, "%s-online", psy->name);
118 if (!psy->online_trig_name)
119 goto online_failed;
121 led_trigger_register_simple(psy->online_trig_name, &psy->online_trig);
123 goto success;
125 online_failed:
126 rc = -ENOMEM;
127 success:
128 return rc;
131 static void power_supply_remove_gen_triggers(struct power_supply *psy)
133 led_trigger_unregister_simple(psy->online_trig);
134 kfree(psy->online_trig_name);
137 /* Choice what triggers to create&update. */
139 void power_supply_update_leds(struct power_supply *psy)
141 if (psy->type == POWER_SUPPLY_TYPE_BATTERY)
142 power_supply_update_bat_leds(psy);
143 else
144 power_supply_update_gen_leds(psy);
147 int power_supply_create_triggers(struct power_supply *psy)
149 if (psy->type == POWER_SUPPLY_TYPE_BATTERY)
150 return power_supply_create_bat_triggers(psy);
151 return power_supply_create_gen_triggers(psy);
154 void power_supply_remove_triggers(struct power_supply *psy)
156 if (psy->type == POWER_SUPPLY_TYPE_BATTERY)
157 power_supply_remove_bat_triggers(psy);
158 else
159 power_supply_remove_gen_triggers(psy);