pda_power: implement polling

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

+46 -1
+45 -1
drivers/power/pda_power.c
··· 32 32 static struct resource *ac_irq, *usb_irq; 33 33 static struct timer_list charger_timer; 34 34 static struct timer_list supply_timer; 35 + static struct timer_list polling_timer; 36 + static int polling; 35 37 36 38 enum { 37 39 PDA_PSY_OFFLINE = 0, ··· 169 167 return IRQ_HANDLED; 170 168 } 171 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 + 172 195 static int pda_power_probe(struct platform_device *pdev) 173 196 { 174 197 int ret = 0; ··· 217 190 218 191 if (!pdata->wait_for_charger) 219 192 pdata->wait_for_charger = 500; 193 + 194 + if (!pdata->polling_interval) 195 + pdata->polling_interval = 2000; 220 196 221 197 setup_timer(&charger_timer, charger_timer_func, 0); 222 198 setup_timer(&supply_timer, supply_timer_func, 0); ··· 250 220 dev_err(dev, "request ac irq failed\n"); 251 221 goto ac_irq_failed; 252 222 } 223 + } else { 224 + polling = 1; 253 225 } 254 226 } 255 227 ··· 271 239 dev_err(dev, "request usb irq failed\n"); 272 240 goto usb_irq_failed; 273 241 } 242 + } else { 243 + polling = 1; 274 244 } 275 245 } 276 246 277 - device_init_wakeup(&pdev->dev, 1); 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); 278 256 279 257 return 0; 280 258 ··· 309 267 if (pdata->is_ac_online && ac_irq) 310 268 free_irq(ac_irq->start, &pda_psy_ac); 311 269 270 + if (polling) 271 + del_timer_sync(&polling_timer); 312 272 del_timer_sync(&charger_timer); 313 273 del_timer_sync(&supply_timer); 314 274
+1
include/linux/pda_power.h
··· 26 26 27 27 unsigned int wait_for_status; /* msecs, default is 500 */ 28 28 unsigned int wait_for_charger; /* msecs, default is 500 */ 29 + unsigned int polling_interval; /* msecs, default is 2000 */ 29 30 }; 30 31 31 32 #endif /* __PDA_POWER_H__ */