pda_power: implement polling

Signed-off-by: Anton Vorontsov <cbou@mail.ru>

+46 -1
+45 -1
drivers/power/pda_power.c
··· 32 static struct resource *ac_irq, *usb_irq; 33 static struct timer_list charger_timer; 34 static struct timer_list supply_timer; 35 36 enum { 37 PDA_PSY_OFFLINE = 0, ··· 169 return IRQ_HANDLED; 170 } 171 172 static int pda_power_probe(struct platform_device *pdev) 173 { 174 int ret = 0; ··· 217 218 if (!pdata->wait_for_charger) 219 pdata->wait_for_charger = 500; 220 221 setup_timer(&charger_timer, charger_timer_func, 0); 222 setup_timer(&supply_timer, supply_timer_func, 0); ··· 250 dev_err(dev, "request ac irq failed\n"); 251 goto ac_irq_failed; 252 } 253 } 254 } 255 ··· 271 dev_err(dev, "request usb irq failed\n"); 272 goto usb_irq_failed; 273 } 274 } 275 } 276 277 - device_init_wakeup(&pdev->dev, 1); 278 279 return 0; 280 ··· 309 if (pdata->is_ac_online && ac_irq) 310 free_irq(ac_irq->start, &pda_psy_ac); 311 312 del_timer_sync(&charger_timer); 313 del_timer_sync(&supply_timer); 314
··· 32 static struct resource *ac_irq, *usb_irq; 33 static struct timer_list charger_timer; 34 static struct timer_list supply_timer; 35 + static struct timer_list polling_timer; 36 + static int polling; 37 38 enum { 39 PDA_PSY_OFFLINE = 0, ··· 167 return IRQ_HANDLED; 168 } 169 170 + static void polling_timer_func(unsigned long unused) 171 + { 172 + int changed = 0; 173 + 174 + dev_dbg(dev, "polling...\n"); 175 + 176 + update_status(); 177 + 178 + if (!ac_irq && new_ac_status != ac_status) { 179 + ac_status = PDA_PSY_TO_CHANGE; 180 + changed = 1; 181 + } 182 + 183 + if (!usb_irq && new_usb_status != usb_status) { 184 + usb_status = PDA_PSY_TO_CHANGE; 185 + changed = 1; 186 + } 187 + 188 + if (changed) 189 + psy_changed(); 190 + 191 + mod_timer(&polling_timer, 192 + jiffies + msecs_to_jiffies(pdata->polling_interval)); 193 + } 194 + 195 static int pda_power_probe(struct platform_device *pdev) 196 { 197 int ret = 0; ··· 190 191 if (!pdata->wait_for_charger) 192 pdata->wait_for_charger = 500; 193 + 194 + if (!pdata->polling_interval) 195 + pdata->polling_interval = 2000; 196 197 setup_timer(&charger_timer, charger_timer_func, 0); 198 setup_timer(&supply_timer, supply_timer_func, 0); ··· 220 dev_err(dev, "request ac irq failed\n"); 221 goto ac_irq_failed; 222 } 223 + } else { 224 + polling = 1; 225 } 226 } 227 ··· 239 dev_err(dev, "request usb irq failed\n"); 240 goto usb_irq_failed; 241 } 242 + } else { 243 + polling = 1; 244 } 245 } 246 247 + if (polling) { 248 + dev_dbg(dev, "will poll for status\n"); 249 + setup_timer(&polling_timer, polling_timer_func, 0); 250 + mod_timer(&polling_timer, 251 + jiffies + msecs_to_jiffies(pdata->polling_interval)); 252 + } 253 + 254 + if (ac_irq || usb_irq) 255 + device_init_wakeup(&pdev->dev, 1); 256 257 return 0; 258 ··· 267 if (pdata->is_ac_online && ac_irq) 268 free_irq(ac_irq->start, &pda_psy_ac); 269 270 + if (polling) 271 + del_timer_sync(&polling_timer); 272 del_timer_sync(&charger_timer); 273 del_timer_sync(&supply_timer); 274
+1
include/linux/pda_power.h
··· 26 27 unsigned int wait_for_status; /* msecs, default is 500 */ 28 unsigned int wait_for_charger; /* msecs, default is 500 */ 29 }; 30 31 #endif /* __PDA_POWER_H__ */
··· 26 27 unsigned int wait_for_status; /* msecs, default is 500 */ 28 unsigned int wait_for_charger; /* msecs, default is 500 */ 29 + unsigned int polling_interval; /* msecs, default is 2000 */ 30 }; 31 32 #endif /* __PDA_POWER_H__ */