Lines Matching refs:rtc
110 static int __sh_rtc_interrupt(struct sh_rtc *rtc) in __sh_rtc_interrupt() argument
114 tmp = readb(rtc->regbase + RCR1); in __sh_rtc_interrupt()
117 writeb(tmp, rtc->regbase + RCR1); in __sh_rtc_interrupt()
120 if (pending && rtc->periodic_freq & PF_OXS) in __sh_rtc_interrupt()
121 rtc_update_irq(rtc->rtc_dev, 1, RTC_UF | RTC_IRQF); in __sh_rtc_interrupt()
126 static int __sh_rtc_alarm(struct sh_rtc *rtc) in __sh_rtc_alarm() argument
130 tmp = readb(rtc->regbase + RCR1); in __sh_rtc_alarm()
133 writeb(tmp, rtc->regbase + RCR1); in __sh_rtc_alarm()
136 rtc_update_irq(rtc->rtc_dev, 1, RTC_AF | RTC_IRQF); in __sh_rtc_alarm()
141 static int __sh_rtc_periodic(struct sh_rtc *rtc) in __sh_rtc_periodic() argument
145 tmp = readb(rtc->regbase + RCR2); in __sh_rtc_periodic()
148 writeb(tmp, rtc->regbase + RCR2); in __sh_rtc_periodic()
154 if ((rtc->periodic_freq & PF_HP) && (rtc->periodic_freq & PF_COUNT)) in __sh_rtc_periodic()
155 rtc->periodic_freq &= ~PF_COUNT; in __sh_rtc_periodic()
157 if (rtc->periodic_freq & PF_HP) in __sh_rtc_periodic()
158 rtc->periodic_freq |= PF_COUNT; in __sh_rtc_periodic()
159 rtc_update_irq(rtc->rtc_dev, 1, RTC_PF | RTC_IRQF); in __sh_rtc_periodic()
167 struct sh_rtc *rtc = dev_id; in sh_rtc_interrupt() local
170 spin_lock(&rtc->lock); in sh_rtc_interrupt()
171 ret = __sh_rtc_interrupt(rtc); in sh_rtc_interrupt()
172 spin_unlock(&rtc->lock); in sh_rtc_interrupt()
179 struct sh_rtc *rtc = dev_id; in sh_rtc_alarm() local
182 spin_lock(&rtc->lock); in sh_rtc_alarm()
183 ret = __sh_rtc_alarm(rtc); in sh_rtc_alarm()
184 spin_unlock(&rtc->lock); in sh_rtc_alarm()
191 struct sh_rtc *rtc = dev_id; in sh_rtc_periodic() local
194 spin_lock(&rtc->lock); in sh_rtc_periodic()
195 ret = __sh_rtc_periodic(rtc); in sh_rtc_periodic()
196 spin_unlock(&rtc->lock); in sh_rtc_periodic()
203 struct sh_rtc *rtc = dev_id; in sh_rtc_shared() local
206 spin_lock(&rtc->lock); in sh_rtc_shared()
207 ret = __sh_rtc_interrupt(rtc); in sh_rtc_shared()
208 ret |= __sh_rtc_alarm(rtc); in sh_rtc_shared()
209 ret |= __sh_rtc_periodic(rtc); in sh_rtc_shared()
210 spin_unlock(&rtc->lock); in sh_rtc_shared()
217 struct sh_rtc *rtc = dev_get_drvdata(dev); in sh_rtc_setaie() local
220 spin_lock_irq(&rtc->lock); in sh_rtc_setaie()
222 tmp = readb(rtc->regbase + RCR1); in sh_rtc_setaie()
229 writeb(tmp, rtc->regbase + RCR1); in sh_rtc_setaie()
231 spin_unlock_irq(&rtc->lock); in sh_rtc_setaie()
236 struct sh_rtc *rtc = dev_get_drvdata(dev); in sh_rtc_proc() local
239 tmp = readb(rtc->regbase + RCR1); in sh_rtc_proc()
242 tmp = readb(rtc->regbase + RCR2); in sh_rtc_proc()
251 struct sh_rtc *rtc = dev_get_drvdata(dev); in sh_rtc_setcie() local
254 spin_lock_irq(&rtc->lock); in sh_rtc_setcie()
256 tmp = readb(rtc->regbase + RCR1); in sh_rtc_setcie()
263 writeb(tmp, rtc->regbase + RCR1); in sh_rtc_setcie()
265 spin_unlock_irq(&rtc->lock); in sh_rtc_setcie()
276 struct sh_rtc *rtc = dev_get_drvdata(dev); in sh_rtc_read_time() local
279 if (!(readb(rtc->regbase + RCR2) & RCR2_RTCEN)) in sh_rtc_read_time()
285 spin_lock_irq(&rtc->lock); in sh_rtc_read_time()
287 tmp = readb(rtc->regbase + RCR1); in sh_rtc_read_time()
290 writeb(tmp, rtc->regbase + RCR1); in sh_rtc_read_time()
292 sec128 = readb(rtc->regbase + R64CNT); in sh_rtc_read_time()
294 tm->tm_sec = bcd2bin(readb(rtc->regbase + RSECCNT)); in sh_rtc_read_time()
295 tm->tm_min = bcd2bin(readb(rtc->regbase + RMINCNT)); in sh_rtc_read_time()
296 tm->tm_hour = bcd2bin(readb(rtc->regbase + RHRCNT)); in sh_rtc_read_time()
297 tm->tm_wday = bcd2bin(readb(rtc->regbase + RWKCNT)); in sh_rtc_read_time()
298 tm->tm_mday = bcd2bin(readb(rtc->regbase + RDAYCNT)); in sh_rtc_read_time()
299 tm->tm_mon = bcd2bin(readb(rtc->regbase + RMONCNT)) - 1; in sh_rtc_read_time()
301 if (rtc->capabilities & RTC_CAP_4_DIGIT_YEAR) { in sh_rtc_read_time()
302 yr = readw(rtc->regbase + RYRCNT); in sh_rtc_read_time()
306 yr = readb(rtc->regbase + RYRCNT); in sh_rtc_read_time()
312 sec2 = readb(rtc->regbase + R64CNT); in sh_rtc_read_time()
313 cf_bit = readb(rtc->regbase + RCR1) & RCR1_CF; in sh_rtc_read_time()
315 spin_unlock_irq(&rtc->lock); in sh_rtc_read_time()
324 if (!(rtc->periodic_freq & PF_OXS)) in sh_rtc_read_time()
338 struct sh_rtc *rtc = dev_get_drvdata(dev); in sh_rtc_set_time() local
342 spin_lock_irq(&rtc->lock); in sh_rtc_set_time()
345 tmp = readb(rtc->regbase + RCR2); in sh_rtc_set_time()
348 writeb(tmp, rtc->regbase + RCR2); in sh_rtc_set_time()
350 writeb(bin2bcd(tm->tm_sec), rtc->regbase + RSECCNT); in sh_rtc_set_time()
351 writeb(bin2bcd(tm->tm_min), rtc->regbase + RMINCNT); in sh_rtc_set_time()
352 writeb(bin2bcd(tm->tm_hour), rtc->regbase + RHRCNT); in sh_rtc_set_time()
353 writeb(bin2bcd(tm->tm_wday), rtc->regbase + RWKCNT); in sh_rtc_set_time()
354 writeb(bin2bcd(tm->tm_mday), rtc->regbase + RDAYCNT); in sh_rtc_set_time()
355 writeb(bin2bcd(tm->tm_mon + 1), rtc->regbase + RMONCNT); in sh_rtc_set_time()
357 if (rtc->capabilities & RTC_CAP_4_DIGIT_YEAR) { in sh_rtc_set_time()
360 writew(year, rtc->regbase + RYRCNT); in sh_rtc_set_time()
363 writeb(bin2bcd(year), rtc->regbase + RYRCNT); in sh_rtc_set_time()
367 tmp = readb(rtc->regbase + RCR2); in sh_rtc_set_time()
370 writeb(tmp, rtc->regbase + RCR2); in sh_rtc_set_time()
372 spin_unlock_irq(&rtc->lock); in sh_rtc_set_time()
377 static inline int sh_rtc_read_alarm_value(struct sh_rtc *rtc, int reg_off) in sh_rtc_read_alarm_value() argument
382 byte = readb(rtc->regbase + reg_off); in sh_rtc_read_alarm_value()
393 struct sh_rtc *rtc = dev_get_drvdata(dev); in sh_rtc_read_alarm() local
396 spin_lock_irq(&rtc->lock); in sh_rtc_read_alarm()
398 tm->tm_sec = sh_rtc_read_alarm_value(rtc, RSECAR); in sh_rtc_read_alarm()
399 tm->tm_min = sh_rtc_read_alarm_value(rtc, RMINAR); in sh_rtc_read_alarm()
400 tm->tm_hour = sh_rtc_read_alarm_value(rtc, RHRAR); in sh_rtc_read_alarm()
401 tm->tm_wday = sh_rtc_read_alarm_value(rtc, RWKAR); in sh_rtc_read_alarm()
402 tm->tm_mday = sh_rtc_read_alarm_value(rtc, RDAYAR); in sh_rtc_read_alarm()
403 tm->tm_mon = sh_rtc_read_alarm_value(rtc, RMONAR); in sh_rtc_read_alarm()
407 wkalrm->enabled = (readb(rtc->regbase + RCR1) & RCR1_AIE) ? 1 : 0; in sh_rtc_read_alarm()
409 spin_unlock_irq(&rtc->lock); in sh_rtc_read_alarm()
414 static inline void sh_rtc_write_alarm_value(struct sh_rtc *rtc, in sh_rtc_write_alarm_value() argument
419 writeb(0, rtc->regbase + reg_off); in sh_rtc_write_alarm_value()
421 writeb(bin2bcd(value) | AR_ENB, rtc->regbase + reg_off); in sh_rtc_write_alarm_value()
426 struct sh_rtc *rtc = dev_get_drvdata(dev); in sh_rtc_set_alarm() local
431 spin_lock_irq(&rtc->lock); in sh_rtc_set_alarm()
434 rcr1 = readb(rtc->regbase + RCR1); in sh_rtc_set_alarm()
436 writeb(rcr1, rtc->regbase + RCR1); in sh_rtc_set_alarm()
439 sh_rtc_write_alarm_value(rtc, tm->tm_sec, RSECAR); in sh_rtc_set_alarm()
440 sh_rtc_write_alarm_value(rtc, tm->tm_min, RMINAR); in sh_rtc_set_alarm()
441 sh_rtc_write_alarm_value(rtc, tm->tm_hour, RHRAR); in sh_rtc_set_alarm()
442 sh_rtc_write_alarm_value(rtc, tm->tm_wday, RWKAR); in sh_rtc_set_alarm()
443 sh_rtc_write_alarm_value(rtc, tm->tm_mday, RDAYAR); in sh_rtc_set_alarm()
447 sh_rtc_write_alarm_value(rtc, mon, RMONAR); in sh_rtc_set_alarm()
451 writeb(rcr1, rtc->regbase + RCR1); in sh_rtc_set_alarm()
454 spin_unlock_irq(&rtc->lock); in sh_rtc_set_alarm()
470 struct sh_rtc *rtc; in sh_rtc_probe() local
475 rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); in sh_rtc_probe()
476 if (unlikely(!rtc)) in sh_rtc_probe()
479 spin_lock_init(&rtc->lock); in sh_rtc_probe()
488 rtc->periodic_irq = ret; in sh_rtc_probe()
489 rtc->carry_irq = platform_get_irq(pdev, 1); in sh_rtc_probe()
490 rtc->alarm_irq = platform_get_irq(pdev, 2); in sh_rtc_probe()
500 rtc->regsize = resource_size(res); in sh_rtc_probe()
502 rtc->res = devm_request_mem_region(&pdev->dev, res->start, in sh_rtc_probe()
503 rtc->regsize, pdev->name); in sh_rtc_probe()
504 if (unlikely(!rtc->res)) in sh_rtc_probe()
507 rtc->regbase = devm_ioremap(&pdev->dev, rtc->res->start, rtc->regsize); in sh_rtc_probe()
508 if (unlikely(!rtc->regbase)) in sh_rtc_probe()
521 rtc->clk = devm_clk_get(&pdev->dev, clk_name); in sh_rtc_probe()
522 if (IS_ERR(rtc->clk)) { in sh_rtc_probe()
529 rtc->clk = NULL; in sh_rtc_probe()
532 rtc->rtc_dev = devm_rtc_allocate_device(&pdev->dev); in sh_rtc_probe()
533 if (IS_ERR(rtc->rtc_dev)) in sh_rtc_probe()
534 return PTR_ERR(rtc->rtc_dev); in sh_rtc_probe()
536 clk_enable(rtc->clk); in sh_rtc_probe()
538 rtc->capabilities = RTC_DEF_CAPABILITIES; in sh_rtc_probe()
549 rtc->capabilities |= pinfo->capabilities; in sh_rtc_probe()
553 if (rtc->carry_irq <= 0) { in sh_rtc_probe()
555 ret = devm_request_irq(&pdev->dev, rtc->periodic_irq, in sh_rtc_probe()
556 sh_rtc_shared, 0, "sh-rtc", rtc); in sh_rtc_probe()
560 rtc->periodic_irq); in sh_rtc_probe()
565 ret = devm_request_irq(&pdev->dev, rtc->periodic_irq, in sh_rtc_probe()
566 sh_rtc_periodic, 0, "sh-rtc period", rtc); in sh_rtc_probe()
570 ret, rtc->periodic_irq); in sh_rtc_probe()
574 ret = devm_request_irq(&pdev->dev, rtc->carry_irq, in sh_rtc_probe()
575 sh_rtc_interrupt, 0, "sh-rtc carry", rtc); in sh_rtc_probe()
579 ret, rtc->carry_irq); in sh_rtc_probe()
583 ret = devm_request_irq(&pdev->dev, rtc->alarm_irq, in sh_rtc_probe()
584 sh_rtc_alarm, 0, "sh-rtc alarm", rtc); in sh_rtc_probe()
588 ret, rtc->alarm_irq); in sh_rtc_probe()
593 platform_set_drvdata(pdev, rtc); in sh_rtc_probe()
599 rtc->rtc_dev->ops = &sh_rtc_ops; in sh_rtc_probe()
600 rtc->rtc_dev->max_user_freq = 256; in sh_rtc_probe()
602 if (rtc->capabilities & RTC_CAP_4_DIGIT_YEAR) { in sh_rtc_probe()
603 rtc->rtc_dev->range_min = RTC_TIMESTAMP_BEGIN_1900; in sh_rtc_probe()
604 rtc->rtc_dev->range_max = RTC_TIMESTAMP_END_9999; in sh_rtc_probe()
606 rtc->rtc_dev->range_min = mktime64(1999, 1, 1, 0, 0, 0); in sh_rtc_probe()
607 rtc->rtc_dev->range_max = mktime64(2098, 12, 31, 23, 59, 59); in sh_rtc_probe()
610 ret = devm_rtc_register_device(rtc->rtc_dev); in sh_rtc_probe()
618 clk_disable(rtc->clk); in sh_rtc_probe()
625 struct sh_rtc *rtc = platform_get_drvdata(pdev); in sh_rtc_remove() local
630 clk_disable(rtc->clk); in sh_rtc_remove()
637 struct sh_rtc *rtc = dev_get_drvdata(dev); in sh_rtc_set_irq_wake() local
639 irq_set_irq_wake(rtc->periodic_irq, enabled); in sh_rtc_set_irq_wake()
641 if (rtc->carry_irq > 0) { in sh_rtc_set_irq_wake()
642 irq_set_irq_wake(rtc->carry_irq, enabled); in sh_rtc_set_irq_wake()
643 irq_set_irq_wake(rtc->alarm_irq, enabled); in sh_rtc_set_irq_wake()