Anton Vorontsov | b299804 | 2007-05-04 00:32:17 +0400 | [diff] [blame] | 1 | /* |
| 2 | * Common power driver for PDAs and phones with one or two external |
| 3 | * power supplies (AC/USB) connected to main and backup batteries, |
| 4 | * and optional builtin charger. |
| 5 | * |
| 6 | * Copyright © 2007 Anton Vorontsov <cbou@mail.ru> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/platform_device.h> |
| 15 | #include <linux/interrupt.h> |
| 16 | #include <linux/power_supply.h> |
| 17 | #include <linux/pda_power.h> |
| 18 | #include <linux/timer.h> |
| 19 | #include <linux/jiffies.h> |
| 20 | |
| 21 | static inline unsigned int get_irq_flags(struct resource *res) |
| 22 | { |
Philipp Zabel | 74194cc | 2009-01-18 14:46:21 +0100 | [diff] [blame] | 23 | unsigned int flags = IRQF_SAMPLE_RANDOM | IRQF_SHARED; |
Anton Vorontsov | b299804 | 2007-05-04 00:32:17 +0400 | [diff] [blame] | 24 | |
| 25 | flags |= res->flags & IRQF_TRIGGER_MASK; |
| 26 | |
| 27 | return flags; |
| 28 | } |
| 29 | |
| 30 | static struct device *dev; |
| 31 | static struct pda_power_pdata *pdata; |
| 32 | static struct resource *ac_irq, *usb_irq; |
| 33 | static struct timer_list charger_timer; |
| 34 | static struct timer_list supply_timer; |
Anton Vorontsov | c3caeba | 2008-01-13 02:44:20 +0300 | [diff] [blame] | 35 | static struct timer_list polling_timer; |
| 36 | static int polling; |
Anton Vorontsov | b299804 | 2007-05-04 00:32:17 +0400 | [diff] [blame] | 37 | |
Anton Vorontsov | bfde266 | 2008-01-13 02:39:17 +0300 | [diff] [blame] | 38 | enum { |
| 39 | PDA_PSY_OFFLINE = 0, |
| 40 | PDA_PSY_ONLINE = 1, |
| 41 | PDA_PSY_TO_CHANGE, |
| 42 | }; |
| 43 | static int new_ac_status = -1; |
| 44 | static int new_usb_status = -1; |
| 45 | static int ac_status = -1; |
| 46 | static int usb_status = -1; |
| 47 | |
Anton Vorontsov | b299804 | 2007-05-04 00:32:17 +0400 | [diff] [blame] | 48 | static int pda_power_get_property(struct power_supply *psy, |
| 49 | enum power_supply_property psp, |
| 50 | union power_supply_propval *val) |
| 51 | { |
| 52 | switch (psp) { |
| 53 | case POWER_SUPPLY_PROP_ONLINE: |
| 54 | if (psy->type == POWER_SUPPLY_TYPE_MAINS) |
| 55 | val->intval = pdata->is_ac_online ? |
| 56 | pdata->is_ac_online() : 0; |
| 57 | else |
| 58 | val->intval = pdata->is_usb_online ? |
| 59 | pdata->is_usb_online() : 0; |
| 60 | break; |
| 61 | default: |
| 62 | return -EINVAL; |
| 63 | } |
| 64 | return 0; |
| 65 | } |
| 66 | |
| 67 | static enum power_supply_property pda_power_props[] = { |
| 68 | POWER_SUPPLY_PROP_ONLINE, |
| 69 | }; |
| 70 | |
| 71 | static char *pda_power_supplied_to[] = { |
| 72 | "main-battery", |
| 73 | "backup-battery", |
| 74 | }; |
| 75 | |
Anton Vorontsov | bfde266 | 2008-01-13 02:39:17 +0300 | [diff] [blame] | 76 | static struct power_supply pda_psy_ac = { |
| 77 | .name = "ac", |
| 78 | .type = POWER_SUPPLY_TYPE_MAINS, |
| 79 | .supplied_to = pda_power_supplied_to, |
| 80 | .num_supplicants = ARRAY_SIZE(pda_power_supplied_to), |
| 81 | .properties = pda_power_props, |
| 82 | .num_properties = ARRAY_SIZE(pda_power_props), |
| 83 | .get_property = pda_power_get_property, |
Anton Vorontsov | b299804 | 2007-05-04 00:32:17 +0400 | [diff] [blame] | 84 | }; |
| 85 | |
Anton Vorontsov | bfde266 | 2008-01-13 02:39:17 +0300 | [diff] [blame] | 86 | static struct power_supply pda_psy_usb = { |
| 87 | .name = "usb", |
| 88 | .type = POWER_SUPPLY_TYPE_USB, |
| 89 | .supplied_to = pda_power_supplied_to, |
| 90 | .num_supplicants = ARRAY_SIZE(pda_power_supplied_to), |
| 91 | .properties = pda_power_props, |
| 92 | .num_properties = ARRAY_SIZE(pda_power_props), |
| 93 | .get_property = pda_power_get_property, |
| 94 | }; |
| 95 | |
| 96 | static void update_status(void) |
| 97 | { |
| 98 | if (pdata->is_ac_online) |
| 99 | new_ac_status = !!pdata->is_ac_online(); |
| 100 | |
| 101 | if (pdata->is_usb_online) |
| 102 | new_usb_status = !!pdata->is_usb_online(); |
| 103 | } |
| 104 | |
Anton Vorontsov | b299804 | 2007-05-04 00:32:17 +0400 | [diff] [blame] | 105 | static void update_charger(void) |
| 106 | { |
| 107 | if (!pdata->set_charge) |
| 108 | return; |
| 109 | |
Anton Vorontsov | bfde266 | 2008-01-13 02:39:17 +0300 | [diff] [blame] | 110 | if (new_ac_status > 0) { |
Anton Vorontsov | b299804 | 2007-05-04 00:32:17 +0400 | [diff] [blame] | 111 | dev_dbg(dev, "charger on (AC)\n"); |
| 112 | pdata->set_charge(PDA_POWER_CHARGE_AC); |
Anton Vorontsov | bfde266 | 2008-01-13 02:39:17 +0300 | [diff] [blame] | 113 | } else if (new_usb_status > 0) { |
Anton Vorontsov | b299804 | 2007-05-04 00:32:17 +0400 | [diff] [blame] | 114 | dev_dbg(dev, "charger on (USB)\n"); |
| 115 | pdata->set_charge(PDA_POWER_CHARGE_USB); |
| 116 | } else { |
| 117 | dev_dbg(dev, "charger off\n"); |
| 118 | pdata->set_charge(0); |
| 119 | } |
Anton Vorontsov | b299804 | 2007-05-04 00:32:17 +0400 | [diff] [blame] | 120 | } |
| 121 | |
Anton Vorontsov | bfde266 | 2008-01-13 02:39:17 +0300 | [diff] [blame] | 122 | static void supply_timer_func(unsigned long unused) |
Anton Vorontsov | b299804 | 2007-05-04 00:32:17 +0400 | [diff] [blame] | 123 | { |
Anton Vorontsov | bfde266 | 2008-01-13 02:39:17 +0300 | [diff] [blame] | 124 | if (ac_status == PDA_PSY_TO_CHANGE) { |
| 125 | ac_status = new_ac_status; |
| 126 | power_supply_changed(&pda_psy_ac); |
| 127 | } |
Jeff Garzik | 5ebf6e6 | 2007-07-14 19:12:04 -0400 | [diff] [blame] | 128 | |
Anton Vorontsov | bfde266 | 2008-01-13 02:39:17 +0300 | [diff] [blame] | 129 | if (usb_status == PDA_PSY_TO_CHANGE) { |
| 130 | usb_status = new_usb_status; |
| 131 | power_supply_changed(&pda_psy_usb); |
| 132 | } |
Anton Vorontsov | b299804 | 2007-05-04 00:32:17 +0400 | [diff] [blame] | 133 | } |
| 134 | |
Anton Vorontsov | bfde266 | 2008-01-13 02:39:17 +0300 | [diff] [blame] | 135 | static void psy_changed(void) |
Anton Vorontsov | b299804 | 2007-05-04 00:32:17 +0400 | [diff] [blame] | 136 | { |
| 137 | update_charger(); |
| 138 | |
Anton Vorontsov | bfde266 | 2008-01-13 02:39:17 +0300 | [diff] [blame] | 139 | /* |
| 140 | * Okay, charger set. Now wait a bit before notifying supplicants, |
| 141 | * charge power should stabilize. |
| 142 | */ |
Anton Vorontsov | b299804 | 2007-05-04 00:32:17 +0400 | [diff] [blame] | 143 | mod_timer(&supply_timer, |
| 144 | jiffies + msecs_to_jiffies(pdata->wait_for_charger)); |
Anton Vorontsov | b299804 | 2007-05-04 00:32:17 +0400 | [diff] [blame] | 145 | } |
| 146 | |
Anton Vorontsov | bfde266 | 2008-01-13 02:39:17 +0300 | [diff] [blame] | 147 | static void charger_timer_func(unsigned long unused) |
| 148 | { |
| 149 | update_status(); |
| 150 | psy_changed(); |
| 151 | } |
| 152 | |
Jeff Garzik | 5ebf6e6 | 2007-07-14 19:12:04 -0400 | [diff] [blame] | 153 | static irqreturn_t power_changed_isr(int irq, void *power_supply) |
Anton Vorontsov | b299804 | 2007-05-04 00:32:17 +0400 | [diff] [blame] | 154 | { |
Anton Vorontsov | bfde266 | 2008-01-13 02:39:17 +0300 | [diff] [blame] | 155 | if (power_supply == &pda_psy_ac) |
| 156 | ac_status = PDA_PSY_TO_CHANGE; |
| 157 | else if (power_supply == &pda_psy_usb) |
| 158 | usb_status = PDA_PSY_TO_CHANGE; |
| 159 | else |
| 160 | return IRQ_NONE; |
| 161 | |
| 162 | /* |
| 163 | * Wait a bit before reading ac/usb line status and setting charger, |
| 164 | * because ac/usb status readings may lag from irq. |
| 165 | */ |
Anton Vorontsov | b299804 | 2007-05-04 00:32:17 +0400 | [diff] [blame] | 166 | mod_timer(&charger_timer, |
| 167 | jiffies + msecs_to_jiffies(pdata->wait_for_status)); |
Anton Vorontsov | bfde266 | 2008-01-13 02:39:17 +0300 | [diff] [blame] | 168 | |
Anton Vorontsov | b299804 | 2007-05-04 00:32:17 +0400 | [diff] [blame] | 169 | return IRQ_HANDLED; |
| 170 | } |
| 171 | |
Anton Vorontsov | c3caeba | 2008-01-13 02:44:20 +0300 | [diff] [blame] | 172 | static void polling_timer_func(unsigned long unused) |
| 173 | { |
| 174 | int changed = 0; |
| 175 | |
| 176 | dev_dbg(dev, "polling...\n"); |
| 177 | |
| 178 | update_status(); |
| 179 | |
| 180 | if (!ac_irq && new_ac_status != ac_status) { |
| 181 | ac_status = PDA_PSY_TO_CHANGE; |
| 182 | changed = 1; |
| 183 | } |
| 184 | |
| 185 | if (!usb_irq && new_usb_status != usb_status) { |
| 186 | usb_status = PDA_PSY_TO_CHANGE; |
| 187 | changed = 1; |
| 188 | } |
| 189 | |
| 190 | if (changed) |
| 191 | psy_changed(); |
| 192 | |
| 193 | mod_timer(&polling_timer, |
| 194 | jiffies + msecs_to_jiffies(pdata->polling_interval)); |
| 195 | } |
| 196 | |
Anton Vorontsov | b299804 | 2007-05-04 00:32:17 +0400 | [diff] [blame] | 197 | static int pda_power_probe(struct platform_device *pdev) |
| 198 | { |
| 199 | int ret = 0; |
| 200 | |
| 201 | dev = &pdev->dev; |
| 202 | |
| 203 | if (pdev->id != -1) { |
| 204 | dev_err(dev, "it's meaningless to register several " |
| 205 | "pda_powers; use id = -1\n"); |
| 206 | ret = -EINVAL; |
| 207 | goto wrongid; |
| 208 | } |
| 209 | |
| 210 | pdata = pdev->dev.platform_data; |
| 211 | |
Philipp Zabel | f6b6b18 | 2008-04-12 13:47:45 +0200 | [diff] [blame] | 212 | if (pdata->init) { |
| 213 | ret = pdata->init(dev); |
| 214 | if (ret < 0) |
| 215 | goto init_failed; |
| 216 | } |
| 217 | |
Anton Vorontsov | bfde266 | 2008-01-13 02:39:17 +0300 | [diff] [blame] | 218 | update_status(); |
Anton Vorontsov | b299804 | 2007-05-04 00:32:17 +0400 | [diff] [blame] | 219 | update_charger(); |
| 220 | |
| 221 | if (!pdata->wait_for_status) |
| 222 | pdata->wait_for_status = 500; |
| 223 | |
| 224 | if (!pdata->wait_for_charger) |
| 225 | pdata->wait_for_charger = 500; |
| 226 | |
Anton Vorontsov | c3caeba | 2008-01-13 02:44:20 +0300 | [diff] [blame] | 227 | if (!pdata->polling_interval) |
| 228 | pdata->polling_interval = 2000; |
| 229 | |
Anton Vorontsov | b299804 | 2007-05-04 00:32:17 +0400 | [diff] [blame] | 230 | setup_timer(&charger_timer, charger_timer_func, 0); |
| 231 | setup_timer(&supply_timer, supply_timer_func, 0); |
| 232 | |
| 233 | ac_irq = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "ac"); |
| 234 | usb_irq = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "usb"); |
Anton Vorontsov | b299804 | 2007-05-04 00:32:17 +0400 | [diff] [blame] | 235 | |
| 236 | if (pdata->supplied_to) { |
Anton Vorontsov | bfde266 | 2008-01-13 02:39:17 +0300 | [diff] [blame] | 237 | pda_psy_ac.supplied_to = pdata->supplied_to; |
| 238 | pda_psy_ac.num_supplicants = pdata->num_supplicants; |
| 239 | pda_psy_usb.supplied_to = pdata->supplied_to; |
| 240 | pda_psy_usb.num_supplicants = pdata->num_supplicants; |
Anton Vorontsov | b299804 | 2007-05-04 00:32:17 +0400 | [diff] [blame] | 241 | } |
| 242 | |
Dmitry Baryshkov | 9ef4510 | 2008-01-07 04:12:39 +0300 | [diff] [blame] | 243 | if (pdata->is_ac_online) { |
Anton Vorontsov | bfde266 | 2008-01-13 02:39:17 +0300 | [diff] [blame] | 244 | ret = power_supply_register(&pdev->dev, &pda_psy_ac); |
Anton Vorontsov | b299804 | 2007-05-04 00:32:17 +0400 | [diff] [blame] | 245 | if (ret) { |
Dmitry Baryshkov | 9ef4510 | 2008-01-07 04:12:39 +0300 | [diff] [blame] | 246 | dev_err(dev, "failed to register %s power supply\n", |
Anton Vorontsov | bfde266 | 2008-01-13 02:39:17 +0300 | [diff] [blame] | 247 | pda_psy_ac.name); |
Dmitry Baryshkov | 9ef4510 | 2008-01-07 04:12:39 +0300 | [diff] [blame] | 248 | goto ac_supply_failed; |
| 249 | } |
| 250 | |
| 251 | if (ac_irq) { |
| 252 | ret = request_irq(ac_irq->start, power_changed_isr, |
| 253 | get_irq_flags(ac_irq), ac_irq->name, |
Anton Vorontsov | bfde266 | 2008-01-13 02:39:17 +0300 | [diff] [blame] | 254 | &pda_psy_ac); |
Dmitry Baryshkov | 9ef4510 | 2008-01-07 04:12:39 +0300 | [diff] [blame] | 255 | if (ret) { |
| 256 | dev_err(dev, "request ac irq failed\n"); |
| 257 | goto ac_irq_failed; |
| 258 | } |
Anton Vorontsov | c3caeba | 2008-01-13 02:44:20 +0300 | [diff] [blame] | 259 | } else { |
| 260 | polling = 1; |
Anton Vorontsov | b299804 | 2007-05-04 00:32:17 +0400 | [diff] [blame] | 261 | } |
| 262 | } |
| 263 | |
Dmitry Baryshkov | 9ef4510 | 2008-01-07 04:12:39 +0300 | [diff] [blame] | 264 | if (pdata->is_usb_online) { |
Anton Vorontsov | bfde266 | 2008-01-13 02:39:17 +0300 | [diff] [blame] | 265 | ret = power_supply_register(&pdev->dev, &pda_psy_usb); |
Anton Vorontsov | b299804 | 2007-05-04 00:32:17 +0400 | [diff] [blame] | 266 | if (ret) { |
Dmitry Baryshkov | 9ef4510 | 2008-01-07 04:12:39 +0300 | [diff] [blame] | 267 | dev_err(dev, "failed to register %s power supply\n", |
Anton Vorontsov | bfde266 | 2008-01-13 02:39:17 +0300 | [diff] [blame] | 268 | pda_psy_usb.name); |
Dmitry Baryshkov | 9ef4510 | 2008-01-07 04:12:39 +0300 | [diff] [blame] | 269 | goto usb_supply_failed; |
| 270 | } |
| 271 | |
| 272 | if (usb_irq) { |
| 273 | ret = request_irq(usb_irq->start, power_changed_isr, |
| 274 | get_irq_flags(usb_irq), |
Anton Vorontsov | bfde266 | 2008-01-13 02:39:17 +0300 | [diff] [blame] | 275 | usb_irq->name, &pda_psy_usb); |
Dmitry Baryshkov | 9ef4510 | 2008-01-07 04:12:39 +0300 | [diff] [blame] | 276 | if (ret) { |
| 277 | dev_err(dev, "request usb irq failed\n"); |
| 278 | goto usb_irq_failed; |
| 279 | } |
Anton Vorontsov | c3caeba | 2008-01-13 02:44:20 +0300 | [diff] [blame] | 280 | } else { |
| 281 | polling = 1; |
Anton Vorontsov | b299804 | 2007-05-04 00:32:17 +0400 | [diff] [blame] | 282 | } |
| 283 | } |
| 284 | |
Anton Vorontsov | c3caeba | 2008-01-13 02:44:20 +0300 | [diff] [blame] | 285 | if (polling) { |
| 286 | dev_dbg(dev, "will poll for status\n"); |
| 287 | setup_timer(&polling_timer, polling_timer_func, 0); |
| 288 | mod_timer(&polling_timer, |
| 289 | jiffies + msecs_to_jiffies(pdata->polling_interval)); |
| 290 | } |
| 291 | |
| 292 | if (ac_irq || usb_irq) |
| 293 | device_init_wakeup(&pdev->dev, 1); |
Dmitry Baryshkov | 8f8e9b3 | 2008-01-13 02:35:43 +0300 | [diff] [blame] | 294 | |
Dmitry Baryshkov | 9ef4510 | 2008-01-07 04:12:39 +0300 | [diff] [blame] | 295 | return 0; |
Anton Vorontsov | b299804 | 2007-05-04 00:32:17 +0400 | [diff] [blame] | 296 | |
| 297 | usb_irq_failed: |
Dmitry Baryshkov | 9ef4510 | 2008-01-07 04:12:39 +0300 | [diff] [blame] | 298 | if (pdata->is_usb_online) |
Anton Vorontsov | bfde266 | 2008-01-13 02:39:17 +0300 | [diff] [blame] | 299 | power_supply_unregister(&pda_psy_usb); |
Dmitry Baryshkov | 9ef4510 | 2008-01-07 04:12:39 +0300 | [diff] [blame] | 300 | usb_supply_failed: |
| 301 | if (pdata->is_ac_online && ac_irq) |
Anton Vorontsov | bfde266 | 2008-01-13 02:39:17 +0300 | [diff] [blame] | 302 | free_irq(ac_irq->start, &pda_psy_ac); |
Anton Vorontsov | b299804 | 2007-05-04 00:32:17 +0400 | [diff] [blame] | 303 | ac_irq_failed: |
Dmitry Baryshkov | 9ef4510 | 2008-01-07 04:12:39 +0300 | [diff] [blame] | 304 | if (pdata->is_ac_online) |
Anton Vorontsov | bfde266 | 2008-01-13 02:39:17 +0300 | [diff] [blame] | 305 | power_supply_unregister(&pda_psy_ac); |
Dmitry Baryshkov | 9ef4510 | 2008-01-07 04:12:39 +0300 | [diff] [blame] | 306 | ac_supply_failed: |
Philipp Zabel | f6b6b18 | 2008-04-12 13:47:45 +0200 | [diff] [blame] | 307 | if (pdata->exit) |
| 308 | pdata->exit(dev); |
| 309 | init_failed: |
Anton Vorontsov | b299804 | 2007-05-04 00:32:17 +0400 | [diff] [blame] | 310 | wrongid: |
Anton Vorontsov | b299804 | 2007-05-04 00:32:17 +0400 | [diff] [blame] | 311 | return ret; |
| 312 | } |
| 313 | |
| 314 | static int pda_power_remove(struct platform_device *pdev) |
| 315 | { |
Dmitry Baryshkov | 9ef4510 | 2008-01-07 04:12:39 +0300 | [diff] [blame] | 316 | if (pdata->is_usb_online && usb_irq) |
Anton Vorontsov | bfde266 | 2008-01-13 02:39:17 +0300 | [diff] [blame] | 317 | free_irq(usb_irq->start, &pda_psy_usb); |
Dmitry Baryshkov | 9ef4510 | 2008-01-07 04:12:39 +0300 | [diff] [blame] | 318 | if (pdata->is_ac_online && ac_irq) |
Anton Vorontsov | bfde266 | 2008-01-13 02:39:17 +0300 | [diff] [blame] | 319 | free_irq(ac_irq->start, &pda_psy_ac); |
| 320 | |
Anton Vorontsov | c3caeba | 2008-01-13 02:44:20 +0300 | [diff] [blame] | 321 | if (polling) |
| 322 | del_timer_sync(&polling_timer); |
Anton Vorontsov | b299804 | 2007-05-04 00:32:17 +0400 | [diff] [blame] | 323 | del_timer_sync(&charger_timer); |
| 324 | del_timer_sync(&supply_timer); |
Anton Vorontsov | bfde266 | 2008-01-13 02:39:17 +0300 | [diff] [blame] | 325 | |
Dmitry Baryshkov | 9ef4510 | 2008-01-07 04:12:39 +0300 | [diff] [blame] | 326 | if (pdata->is_usb_online) |
Anton Vorontsov | bfde266 | 2008-01-13 02:39:17 +0300 | [diff] [blame] | 327 | power_supply_unregister(&pda_psy_usb); |
Dmitry Baryshkov | 9ef4510 | 2008-01-07 04:12:39 +0300 | [diff] [blame] | 328 | if (pdata->is_ac_online) |
Anton Vorontsov | bfde266 | 2008-01-13 02:39:17 +0300 | [diff] [blame] | 329 | power_supply_unregister(&pda_psy_ac); |
Philipp Zabel | f6b6b18 | 2008-04-12 13:47:45 +0200 | [diff] [blame] | 330 | if (pdata->exit) |
| 331 | pdata->exit(dev); |
Anton Vorontsov | bfde266 | 2008-01-13 02:39:17 +0300 | [diff] [blame] | 332 | |
Anton Vorontsov | b299804 | 2007-05-04 00:32:17 +0400 | [diff] [blame] | 333 | return 0; |
| 334 | } |
| 335 | |
Dmitry Baryshkov | 8f8e9b3 | 2008-01-13 02:35:43 +0300 | [diff] [blame] | 336 | #ifdef CONFIG_PM |
Robert Jarzmik | e82374f | 2008-08-11 22:22:27 +0200 | [diff] [blame] | 337 | static int ac_wakeup_enabled; |
| 338 | static int usb_wakeup_enabled; |
| 339 | |
Dmitry Baryshkov | 8f8e9b3 | 2008-01-13 02:35:43 +0300 | [diff] [blame] | 340 | static int pda_power_suspend(struct platform_device *pdev, pm_message_t state) |
| 341 | { |
| 342 | if (device_may_wakeup(&pdev->dev)) { |
| 343 | if (ac_irq) |
Robert Jarzmik | e82374f | 2008-08-11 22:22:27 +0200 | [diff] [blame] | 344 | ac_wakeup_enabled = !enable_irq_wake(ac_irq->start); |
Dmitry Baryshkov | 8f8e9b3 | 2008-01-13 02:35:43 +0300 | [diff] [blame] | 345 | if (usb_irq) |
Robert Jarzmik | e82374f | 2008-08-11 22:22:27 +0200 | [diff] [blame] | 346 | usb_wakeup_enabled = !enable_irq_wake(usb_irq->start); |
Dmitry Baryshkov | 8f8e9b3 | 2008-01-13 02:35:43 +0300 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | return 0; |
| 350 | } |
| 351 | |
| 352 | static int pda_power_resume(struct platform_device *pdev) |
| 353 | { |
| 354 | if (device_may_wakeup(&pdev->dev)) { |
Robert Jarzmik | e82374f | 2008-08-11 22:22:27 +0200 | [diff] [blame] | 355 | if (usb_irq && usb_wakeup_enabled) |
Dmitry Baryshkov | 8f8e9b3 | 2008-01-13 02:35:43 +0300 | [diff] [blame] | 356 | disable_irq_wake(usb_irq->start); |
Robert Jarzmik | e82374f | 2008-08-11 22:22:27 +0200 | [diff] [blame] | 357 | if (ac_irq && ac_wakeup_enabled) |
Dmitry Baryshkov | 8f8e9b3 | 2008-01-13 02:35:43 +0300 | [diff] [blame] | 358 | disable_irq_wake(ac_irq->start); |
| 359 | } |
| 360 | |
| 361 | return 0; |
| 362 | } |
| 363 | #else |
| 364 | #define pda_power_suspend NULL |
| 365 | #define pda_power_resume NULL |
| 366 | #endif /* CONFIG_PM */ |
| 367 | |
Kay Sievers | 2f5a5cf | 2008-07-25 01:45:46 -0700 | [diff] [blame] | 368 | MODULE_ALIAS("platform:pda-power"); |
| 369 | |
Anton Vorontsov | b299804 | 2007-05-04 00:32:17 +0400 | [diff] [blame] | 370 | static struct platform_driver pda_power_pdrv = { |
| 371 | .driver = { |
| 372 | .name = "pda-power", |
| 373 | }, |
| 374 | .probe = pda_power_probe, |
| 375 | .remove = pda_power_remove, |
Dmitry Baryshkov | 8f8e9b3 | 2008-01-13 02:35:43 +0300 | [diff] [blame] | 376 | .suspend = pda_power_suspend, |
| 377 | .resume = pda_power_resume, |
Anton Vorontsov | b299804 | 2007-05-04 00:32:17 +0400 | [diff] [blame] | 378 | }; |
| 379 | |
| 380 | static int __init pda_power_init(void) |
| 381 | { |
| 382 | return platform_driver_register(&pda_power_pdrv); |
| 383 | } |
| 384 | |
| 385 | static void __exit pda_power_exit(void) |
| 386 | { |
| 387 | platform_driver_unregister(&pda_power_pdrv); |
Anton Vorontsov | b299804 | 2007-05-04 00:32:17 +0400 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | module_init(pda_power_init); |
| 391 | module_exit(pda_power_exit); |
| 392 | MODULE_LICENSE("GPL"); |
| 393 | MODULE_AUTHOR("Anton Vorontsov <cbou@mail.ru>"); |