aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc/rtc-twl4030.c
diff options
context:
space:
mode:
authorAlessandro Zummo <a.zummo@towertech.it>2009-01-15 16:50:52 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2009-01-15 19:39:36 -0500
commita748384bba1754409383ba9f0738bffdfa3fd431 (patch)
tree906b6a0d111c9b054242ec96d0bbde386bc95c7a /drivers/rtc/rtc-twl4030.c
parentfb144adc517d9ebe8fd8d98a5696fb68ec91e1f5 (diff)
rtc: tw4030 add alarm/update interfaces
- implement alarm_irq_enable - return correct error code when registering fails [dbrownell@users.sourceforge.net: build fixes, force 1/sec irqs] Signed-off-by: Alessandro Zummo <a.zummo@towertech.it> Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Cc: Tony Lindgren <tony@atomide.com> Cc: Samuel Ortiz <sameo@openedhand.com> Cc: rtc-linux@googlegroups.com Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/rtc/rtc-twl4030.c')
-rw-r--r--drivers/rtc/rtc-twl4030.c44
1 files changed, 10 insertions, 34 deletions
diff --git a/drivers/rtc/rtc-twl4030.c b/drivers/rtc/rtc-twl4030.c
index 8ce5f74ee45b..25dc3e1cedbe 100644
--- a/drivers/rtc/rtc-twl4030.c
+++ b/drivers/rtc/rtc-twl4030.c
@@ -120,7 +120,7 @@ static int twl4030_rtc_write_u8(u8 data, u8 reg)
120static unsigned char rtc_irq_bits; 120static unsigned char rtc_irq_bits;
121 121
122/* 122/*
123 * Enable timer and/or alarm interrupts. 123 * Enable 1/second update and/or alarm interrupts.
124 */ 124 */
125static int set_rtc_irq_bit(unsigned char bit) 125static int set_rtc_irq_bit(unsigned char bit)
126{ 126{
@@ -128,6 +128,7 @@ static int set_rtc_irq_bit(unsigned char bit)
128 int ret; 128 int ret;
129 129
130 val = rtc_irq_bits | bit; 130 val = rtc_irq_bits | bit;
131 val &= ~BIT_RTC_INTERRUPTS_REG_EVERY_M;
131 ret = twl4030_rtc_write_u8(val, REG_RTC_INTERRUPTS_REG); 132 ret = twl4030_rtc_write_u8(val, REG_RTC_INTERRUPTS_REG);
132 if (ret == 0) 133 if (ret == 0)
133 rtc_irq_bits = val; 134 rtc_irq_bits = val;
@@ -136,7 +137,7 @@ static int set_rtc_irq_bit(unsigned char bit)
136} 137}
137 138
138/* 139/*
139 * Disable timer and/or alarm interrupts. 140 * Disable update and/or alarm interrupts.
140 */ 141 */
141static int mask_rtc_irq_bit(unsigned char bit) 142static int mask_rtc_irq_bit(unsigned char bit)
142{ 143{
@@ -151,7 +152,7 @@ static int mask_rtc_irq_bit(unsigned char bit)
151 return ret; 152 return ret;
152} 153}
153 154
154static inline int twl4030_rtc_alarm_irq_set_state(int enabled) 155static int twl4030_rtc_alarm_irq_enable(struct device *dev, unsigned enabled)
155{ 156{
156 int ret; 157 int ret;
157 158
@@ -163,7 +164,7 @@ static inline int twl4030_rtc_alarm_irq_set_state(int enabled)
163 return ret; 164 return ret;
164} 165}
165 166
166static inline int twl4030_rtc_irq_set_state(int enabled) 167static int twl4030_rtc_update_irq_enable(struct device *dev, unsigned enabled)
167{ 168{
168 int ret; 169 int ret;
169 170
@@ -292,7 +293,7 @@ static int twl4030_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
292 unsigned char alarm_data[ALL_TIME_REGS + 1]; 293 unsigned char alarm_data[ALL_TIME_REGS + 1];
293 int ret; 294 int ret;
294 295
295 ret = twl4030_rtc_alarm_irq_set_state(0); 296 ret = twl4030_rtc_alarm_irq_enable(dev, 0);
296 if (ret) 297 if (ret)
297 goto out; 298 goto out;
298 299
@@ -312,35 +313,11 @@ static int twl4030_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
312 } 313 }
313 314
314 if (alm->enabled) 315 if (alm->enabled)
315 ret = twl4030_rtc_alarm_irq_set_state(1); 316 ret = twl4030_rtc_alarm_irq_enable(dev, 1);
316out: 317out:
317 return ret; 318 return ret;
318} 319}
319 320
320#ifdef CONFIG_RTC_INTF_DEV
321
322static int twl4030_rtc_ioctl(struct device *dev, unsigned int cmd,
323 unsigned long arg)
324{
325 switch (cmd) {
326 case RTC_AIE_OFF:
327 return twl4030_rtc_alarm_irq_set_state(0);
328 case RTC_AIE_ON:
329 return twl4030_rtc_alarm_irq_set_state(1);
330 case RTC_UIE_OFF:
331 return twl4030_rtc_irq_set_state(0);
332 case RTC_UIE_ON:
333 return twl4030_rtc_irq_set_state(1);
334
335 default:
336 return -ENOIOCTLCMD;
337 }
338}
339
340#else
341#define twl4030_rtc_ioctl NULL
342#endif
343
344static irqreturn_t twl4030_rtc_interrupt(int irq, void *rtc) 321static irqreturn_t twl4030_rtc_interrupt(int irq, void *rtc)
345{ 322{
346 unsigned long events = 0; 323 unsigned long events = 0;
@@ -400,11 +377,12 @@ out:
400} 377}
401 378
402static struct rtc_class_ops twl4030_rtc_ops = { 379static struct rtc_class_ops twl4030_rtc_ops = {
403 .ioctl = twl4030_rtc_ioctl,
404 .read_time = twl4030_rtc_read_time, 380 .read_time = twl4030_rtc_read_time,
405 .set_time = twl4030_rtc_set_time, 381 .set_time = twl4030_rtc_set_time,
406 .read_alarm = twl4030_rtc_read_alarm, 382 .read_alarm = twl4030_rtc_read_alarm,
407 .set_alarm = twl4030_rtc_set_alarm, 383 .set_alarm = twl4030_rtc_set_alarm,
384 .alarm_irq_enable = twl4030_rtc_alarm_irq_enable,
385 .update_irq_enable = twl4030_rtc_update_irq_enable,
408}; 386};
409 387
410/*----------------------------------------------------------------------*/ 388/*----------------------------------------------------------------------*/
@@ -422,7 +400,7 @@ static int __devinit twl4030_rtc_probe(struct platform_device *pdev)
422 rtc = rtc_device_register(pdev->name, 400 rtc = rtc_device_register(pdev->name,
423 &pdev->dev, &twl4030_rtc_ops, THIS_MODULE); 401 &pdev->dev, &twl4030_rtc_ops, THIS_MODULE);
424 if (IS_ERR(rtc)) { 402 if (IS_ERR(rtc)) {
425 ret = -EINVAL; 403 ret = PTR_ERR(rtc);
426 dev_err(&pdev->dev, "can't register RTC device, err %ld\n", 404 dev_err(&pdev->dev, "can't register RTC device, err %ld\n",
427 PTR_ERR(rtc)); 405 PTR_ERR(rtc));
428 goto out0; 406 goto out0;
@@ -432,7 +410,6 @@ static int __devinit twl4030_rtc_probe(struct platform_device *pdev)
432 platform_set_drvdata(pdev, rtc); 410 platform_set_drvdata(pdev, rtc);
433 411
434 ret = twl4030_rtc_read_u8(&rd_reg, REG_RTC_STATUS_REG); 412 ret = twl4030_rtc_read_u8(&rd_reg, REG_RTC_STATUS_REG);
435
436 if (ret < 0) 413 if (ret < 0)
437 goto out1; 414 goto out1;
438 415
@@ -475,7 +452,6 @@ static int __devinit twl4030_rtc_probe(struct platform_device *pdev)
475 452
476 return ret; 453 return ret;
477 454
478
479out2: 455out2:
480 free_irq(irq, rtc); 456 free_irq(irq, rtc);
481out1: 457out1: