13 #include <linux/module.h>
25 static inline unsigned int get_irq_flags(
struct resource *
res)
32 static struct resource *ac_irq, *usb_irq;
38 #ifdef CONFIG_USB_OTG_UTILS
50 static int new_ac_status = -1;
51 static int new_usb_status = -1;
52 static int ac_status = -1;
53 static int usb_status = -1;
55 static int pda_power_get_property(
struct power_supply *psy,
78 static char *pda_power_supplied_to[] = {
86 .supplied_to = pda_power_supplied_to,
87 .num_supplicants =
ARRAY_SIZE(pda_power_supplied_to),
88 .properties = pda_power_props,
90 .get_property = pda_power_get_property,
96 .supplied_to = pda_power_supplied_to,
97 .num_supplicants =
ARRAY_SIZE(pda_power_supplied_to),
98 .properties = pda_power_props,
100 .get_property = pda_power_get_property,
103 static void update_status(
void)
112 static void update_charger(
void)
114 static int regulator_enabled;
118 if (new_ac_status > 0) {
119 dev_dbg(dev,
"charger on (AC)\n");
121 }
else if (new_usb_status > 0) {
122 dev_dbg(dev,
"charger on (USB)\n");
128 }
else if (ac_draw) {
129 if (new_ac_status > 0) {
131 if (!regulator_enabled) {
132 dev_dbg(dev,
"charger on (AC)\n");
134 regulator_enabled = 1;
137 if (regulator_enabled) {
140 regulator_enabled = 0;
146 static void supply_timer_func(
unsigned long unused)
149 ac_status = new_ac_status;
154 usb_status = new_usb_status;
159 static void psy_changed(
void)
171 static void charger_timer_func(
unsigned long unused)
179 if (power_supply == &pda_psy_ac)
181 else if (power_supply == &pda_psy_usb)
196 static void polling_timer_func(
unsigned long unused)
204 if (!ac_irq && new_ac_status != ac_status) {
209 if (!usb_irq && new_usb_status != usb_status) {
221 #ifdef CONFIG_USB_OTG_UTILS
222 static int otg_is_usb_online(
void)
228 static int otg_is_ac_online(
void)
234 unsigned long event,
void *unused)
269 if (pdev->
id != -1) {
270 dev_err(dev,
"it's meaningless to register several "
271 "pda_powers; use id = -1\n");
276 pdata = pdev->
dev.platform_data;
279 ret = pdata->
init(dev);
285 if (IS_ERR(ac_draw)) {
286 dev_dbg(dev,
"couldn't get ac_draw regulator\n");
305 setup_timer(&charger_timer, charger_timer_func, 0);
318 #ifdef CONFIG_USB_OTG_UTILS
320 if (!IS_ERR_OR_NULL(transceiver)) {
331 dev_err(dev,
"failed to register %s power supply\n",
333 goto ac_supply_failed;
338 get_irq_flags(ac_irq), ac_irq->
name,
341 dev_err(dev,
"request ac irq failed\n");
352 dev_err(dev,
"failed to register %s power supply\n",
354 goto usb_supply_failed;
359 get_irq_flags(usb_irq),
360 usb_irq->
name, &pda_psy_usb);
362 dev_err(dev,
"request usb irq failed\n");
370 #ifdef CONFIG_USB_OTG_UTILS
372 otg_nb.notifier_call = otg_handle_notification;
373 ret = usb_register_notifier(transceiver, &otg_nb);
375 dev_err(dev,
"failure to register otg notifier\n");
376 goto otg_reg_notifier_failed;
383 dev_dbg(dev,
"will poll for status\n");
384 setup_timer(&polling_timer, polling_timer_func, 0);
389 if (ac_irq || usb_irq)
394 #ifdef CONFIG_USB_OTG_UTILS
395 otg_reg_notifier_failed:
405 #ifdef CONFIG_USB_OTG_UTILS
406 if (!IS_ERR_OR_NULL(transceiver))
440 #ifdef CONFIG_USB_OTG_UTILS
441 if (!IS_ERR_OR_NULL(transceiver))
455 static int ac_wakeup_enabled;
456 static int usb_wakeup_enabled;
461 int ret = pdata->
suspend(state);
467 if (device_may_wakeup(&pdev->
dev)) {
469 ac_wakeup_enabled = !enable_irq_wake(ac_irq->
start);
471 usb_wakeup_enabled = !enable_irq_wake(usb_irq->
start);
479 if (device_may_wakeup(&pdev->
dev)) {
480 if (usb_irq && usb_wakeup_enabled)
481 disable_irq_wake(usb_irq->
start);
482 if (ac_irq && ac_wakeup_enabled)
483 disable_irq_wake(ac_irq->
start);
492 #define pda_power_suspend NULL
493 #define pda_power_resume NULL
500 .probe = pda_power_probe,
501 .remove = pda_power_remove,