Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

rtc: omap: Add external clock enabling support

Configure the clock source to external clock if available.
External clock is preferred as it can be ticking during suspend.

Signed-off-by: Keerthy <j-keerthy@ti.com>
Acked-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>

authored by

Keerthy and committed by
Alexandre Belloni
399cf0f6 532409aa

+24 -1
+24 -1
drivers/rtc/rtc-omap.c
··· 108 108 109 109 /* OMAP_RTC_OSC_REG bit fields: */ 110 110 #define OMAP_RTC_OSC_32KCLK_EN BIT(6) 111 + #define OMAP_RTC_OSC_SEL_32KCLK_SRC BIT(3) 111 112 112 113 /* OMAP_RTC_IRQWAKEEN bit fields: */ 113 114 #define OMAP_RTC_IRQWAKEEN_ALARM_WAKEEN BIT(1) ··· 139 138 int irq_timer; 140 139 u8 interrupts_reg; 141 140 bool is_pmic_controller; 141 + bool has_ext_clk; 142 142 const struct omap_rtc_device_type *type; 143 143 }; 144 144 ··· 557 555 if (rtc->irq_alarm <= 0) 558 556 return -ENOENT; 559 557 560 - rtc->clk = devm_clk_get(&pdev->dev, "int-clk"); 558 + rtc->clk = devm_clk_get(&pdev->dev, "ext-clk"); 559 + if (!IS_ERR(rtc->clk)) 560 + rtc->has_ext_clk = true; 561 + else 562 + rtc->clk = devm_clk_get(&pdev->dev, "int-clk"); 561 563 562 564 if (!IS_ERR(rtc->clk)) 563 565 clk_prepare_enable(rtc->clk); ··· 640 634 if (reg != new_ctrl) 641 635 rtc_write(rtc, OMAP_RTC_CTRL_REG, new_ctrl); 642 636 637 + /* 638 + * If we have the external clock then switch to it so we can keep 639 + * ticking across suspend. 640 + */ 641 + if (rtc->has_ext_clk) { 642 + reg = rtc_read(rtc, OMAP_RTC_OSC_REG); 643 + rtc_write(rtc, OMAP_RTC_OSC_REG, 644 + reg | OMAP_RTC_OSC_SEL_32KCLK_SRC); 645 + } 646 + 643 647 rtc->type->lock(rtc); 644 648 645 649 device_init_wakeup(&pdev->dev, true); ··· 695 679 static int __exit omap_rtc_remove(struct platform_device *pdev) 696 680 { 697 681 struct omap_rtc *rtc = platform_get_drvdata(pdev); 682 + u8 reg; 698 683 699 684 if (pm_power_off == omap_rtc_power_off && 700 685 omap_rtc_power_off_rtc == rtc) { ··· 711 694 rtc->type->unlock(rtc); 712 695 /* leave rtc running, but disable irqs */ 713 696 rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, 0); 697 + 698 + if (rtc->has_ext_clk) { 699 + reg = rtc_read(rtc, OMAP_RTC_OSC_REG); 700 + reg &= ~OMAP_RTC_OSC_SEL_32KCLK_SRC; 701 + rtc_write(rtc, OMAP_RTC_OSC_REG, reg); 702 + } 714 703 715 704 rtc->type->lock(rtc); 716 705