Message ID | 1411119994-8234-1-git-send-email-lokeshvutla@ti.com |
---|---|
State | Superseded |
Headers | show |
+linux-omap, linux-arm-kernel, devicetree On Friday 19 September 2014 03:16 PM, Lokesh Vutla wrote: > On some Soc's RTC is powered by an external power regulator. > e.g. RTC on DRA7 SoC. Make the OMAP RTC driver support a > power regulator. > And also making the driver as module_platform_driver to > support probe deferal. > > Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com> > --- > Tested on DRA7. Logs here: http://fpaste.org/134804/11200041/ > > Documentation/devicetree/bindings/rtc/rtc-omap.txt | 3 +++ > drivers/rtc/rtc-omap.c | 28 ++++++++++++++++++++-- > 2 files changed, 29 insertions(+), 2 deletions(-) > > diff --git a/Documentation/devicetree/bindings/rtc/rtc-omap.txt b/Documentation/devicetree/bindings/rtc/rtc-omap.txt > index 5a0f02d..c9f963a 100644 > --- a/Documentation/devicetree/bindings/rtc/rtc-omap.txt > +++ b/Documentation/devicetree/bindings/rtc/rtc-omap.txt > @@ -10,6 +10,9 @@ Required properties: > - interrupts: rtc timer, alarm interrupts in order > - interrupt-parent: phandle for the interrupt controller > > +Optional Properties: > + - rtc-supply : phandle to the regulator device tree node if needed. > + > Example: > > rtc@1c23000 { > diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c > index 21142e6..4473d1d 100644 > --- a/drivers/rtc/rtc-omap.c > +++ b/drivers/rtc/rtc-omap.c > @@ -24,6 +24,7 @@ > #include <linux/of_device.h> > #include <linux/pm_runtime.h> > #include <linux/io.h> > +#include <linux/regulator/consumer.h> > > /* The OMAP1 RTC is a year/month/day/hours/minutes/seconds BCD clock > * with century-range alarm matching, driven by the 32kHz clock. > @@ -121,6 +122,7 @@ > #define OMAP_RTC_HAS_32KCLK_EN BIT(2) > > static void __iomem *rtc_base; > +static struct regulator *rtc_reg; > > #define rtc_read(addr) readb(rtc_base + (addr)) > #define rtc_write(val, addr) writeb(val, rtc_base + (addr)) > @@ -372,11 +374,12 @@ static const struct of_device_id omap_rtc_of_match[] = { > }; > MODULE_DEVICE_TABLE(of, omap_rtc_of_match); > > -static int __init omap_rtc_probe(struct platform_device *pdev) > +static int omap_rtc_probe(struct platform_device *pdev) > { > struct resource *res; > struct rtc_device *rtc; > u8 reg, new_ctrl; > + int ret; > const struct platform_device_id *id_entry; > const struct of_device_id *of_id; > > @@ -402,6 +405,23 @@ static int __init omap_rtc_probe(struct platform_device *pdev) > return -ENOENT; > } > > + rtc_reg = devm_regulator_get_optional(&pdev->dev, "rtc"); > + if (IS_ERR(rtc_reg)) { > + if (PTR_ERR(rtc_reg) == -EPROBE_DEFER) { > + dev_err(&pdev->dev, "regulator not ready, retry\n"); > + return -EPROBE_DEFER; > + } > + rtc_reg = NULL; > + } > + > + if (rtc_reg) { > + ret = regulator_enable(rtc_reg); > + if (ret) { > + dev_dbg(&pdev->dev, "regulator enable failed\n"); > + return ret; > + } > + } > + > res = platform_get_resource(pdev, IORESOURCE_MEM, 0); > rtc_base = devm_ioremap_resource(&pdev->dev, res); > if (IS_ERR(rtc_base)) > @@ -517,6 +537,9 @@ static int __exit omap_rtc_remove(struct platform_device *pdev) > pm_runtime_put_sync(&pdev->dev); > pm_runtime_disable(&pdev->dev); > > + if (rtc_reg) > + regulator_disable(rtc_reg); > + > return 0; > } > > @@ -565,6 +588,7 @@ static void omap_rtc_shutdown(struct platform_device *pdev) > > MODULE_ALIAS("platform:omap_rtc"); > static struct platform_driver omap_rtc_driver = { > + .probe = omap_rtc_probe, > .remove = __exit_p(omap_rtc_remove), > .shutdown = omap_rtc_shutdown, > .driver = { > @@ -576,7 +600,7 @@ static struct platform_driver omap_rtc_driver = { > .id_table = omap_rtc_devtype, > }; > > -module_platform_driver_probe(omap_rtc_driver, omap_rtc_probe); > +module_platform_driver(omap_rtc_driver); > > MODULE_AUTHOR("George G. Davis (and others)"); > MODULE_LICENSE("GPL"); >
On 09/19/2014 04:48 AM, Lokesh Vutla wrote: > +linux-omap, linux-arm-kernel, devicetree > On Friday 19 September 2014 03:16 PM, Lokesh Vutla wrote: >> On some Soc's RTC is powered by an external power regulator. >> e.g. RTC on DRA7 SoC. Make the OMAP RTC driver support a >> power regulator. >> And also making the driver as module_platform_driver to >> support probe deferal. >> >> Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com> >> --- >> Tested on DRA7. Logs here: http://fpaste.org/134804/11200041/ Is that the only platform using rtc-omap.c? >> >> Documentation/devicetree/bindings/rtc/rtc-omap.txt | 3 +++ >> drivers/rtc/rtc-omap.c | 28 ++++++++++++++++++++-- >> 2 files changed, 29 insertions(+), 2 deletions(-) >> >> diff --git a/Documentation/devicetree/bindings/rtc/rtc-omap.txt b/Documentation/devicetree/bindings/rtc/rtc-omap.txt >> index 5a0f02d..c9f963a 100644 >> --- a/Documentation/devicetree/bindings/rtc/rtc-omap.txt >> +++ b/Documentation/devicetree/bindings/rtc/rtc-omap.txt >> @@ -10,6 +10,9 @@ Required properties: >> - interrupts: rtc timer, alarm interrupts in order >> - interrupt-parent: phandle for the interrupt controller >> >> +Optional Properties: >> + - rtc-supply : phandle to the regulator device tree node if needed. >> + >> Example: >> >> rtc@1c23000 { >> diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c >> index 21142e6..4473d1d 100644 >> --- a/drivers/rtc/rtc-omap.c >> +++ b/drivers/rtc/rtc-omap.c >> @@ -24,6 +24,7 @@ >> #include <linux/of_device.h> >> #include <linux/pm_runtime.h> >> #include <linux/io.h> >> +#include <linux/regulator/consumer.h> >> >> /* The OMAP1 RTC is a year/month/day/hours/minutes/seconds BCD clock >> * with century-range alarm matching, driven by the 32kHz clock. >> @@ -121,6 +122,7 @@ >> #define OMAP_RTC_HAS_32KCLK_EN BIT(2) >> >> static void __iomem *rtc_base; ^^ this can easily be removed by allocating data in probe. >> +static struct regulator *rtc_reg; So, two instances cannot have different RTC supplies? we dont need to do this. >> >> #define rtc_read(addr) readb(rtc_base + (addr)) >> #define rtc_write(val, addr) writeb(val, rtc_base + (addr)) >> @@ -372,11 +374,12 @@ static const struct of_device_id omap_rtc_of_match[] = { >> }; >> MODULE_DEVICE_TABLE(of, omap_rtc_of_match); >> >> -static int __init omap_rtc_probe(struct platform_device *pdev) >> +static int omap_rtc_probe(struct platform_device *pdev) >> { >> struct resource *res; >> struct rtc_device *rtc; >> u8 reg, new_ctrl; >> + int ret; >> const struct platform_device_id *id_entry; >> const struct of_device_id *of_id; >> >> @@ -402,6 +405,23 @@ static int __init omap_rtc_probe(struct platform_device *pdev) >> return -ENOENT; >> } >> >> + rtc_reg = devm_regulator_get_optional(&pdev->dev, "rtc"); >> + if (IS_ERR(rtc_reg)) { >> + if (PTR_ERR(rtc_reg) == -EPROBE_DEFER) { >> + dev_err(&pdev->dev, "regulator not ready, retry\n"); >> + return -EPROBE_DEFER; >> + } >> + rtc_reg = NULL; >> + } >> + >> + if (rtc_reg) { >> + ret = regulator_enable(rtc_reg); >> + if (ret) { >> + dev_dbg(&pdev->dev, "regulator enable failed\n"); >> + return ret; >> + } >> + } >> + Do you have a specific voltage you need for your rtc device? >> res = platform_get_resource(pdev, IORESOURCE_MEM, 0); >> rtc_base = devm_ioremap_resource(&pdev->dev, res); >> if (IS_ERR(rtc_base)) >> @@ -517,6 +537,9 @@ static int __exit omap_rtc_remove(struct platform_device *pdev) >> pm_runtime_put_sync(&pdev->dev); >> pm_runtime_disable(&pdev->dev); >> >> + if (rtc_reg) >> + regulator_disable(rtc_reg); >> + >> return 0; >> } >> >> @@ -565,6 +588,7 @@ static void omap_rtc_shutdown(struct platform_device *pdev) >> >> MODULE_ALIAS("platform:omap_rtc"); >> static struct platform_driver omap_rtc_driver = { >> + .probe = omap_rtc_probe, >> .remove = __exit_p(omap_rtc_remove), >> .shutdown = omap_rtc_shutdown, >> .driver = { >> @@ -576,7 +600,7 @@ static struct platform_driver omap_rtc_driver = { >> .id_table = omap_rtc_devtype, >> }; >> >> -module_platform_driver_probe(omap_rtc_driver, omap_rtc_probe); >> +module_platform_driver(omap_rtc_driver); >> >> MODULE_AUTHOR("George G. Davis (and others)"); >> MODULE_LICENSE("GPL"); >> >
On Fri, Sep 19, 2014 at 03:16:34PM +0530, Lokesh Vutla wrote: > On some Soc's RTC is powered by an external power regulator. > e.g. RTC on DRA7 SoC. Make the OMAP RTC driver support a > power regulator. > And also making the driver as module_platform_driver to > support probe deferal. I would split module_platform_driver() change to its own patch. > Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com> > --- > Tested on DRA7. Logs here: http://fpaste.org/134804/11200041/ > > Documentation/devicetree/bindings/rtc/rtc-omap.txt | 3 +++ > drivers/rtc/rtc-omap.c | 28 ++++++++++++++++++++-- > 2 files changed, 29 insertions(+), 2 deletions(-) > > diff --git a/Documentation/devicetree/bindings/rtc/rtc-omap.txt b/Documentation/devicetree/bindings/rtc/rtc-omap.txt > index 5a0f02d..c9f963a 100644 > --- a/Documentation/devicetree/bindings/rtc/rtc-omap.txt > +++ b/Documentation/devicetree/bindings/rtc/rtc-omap.txt > @@ -10,6 +10,9 @@ Required properties: > - interrupts: rtc timer, alarm interrupts in order > - interrupt-parent: phandle for the interrupt controller > > +Optional Properties: > + - rtc-supply : phandle to the regulator device tree node if needed. > + > Example: > > rtc@1c23000 { > diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c > index 21142e6..4473d1d 100644 > --- a/drivers/rtc/rtc-omap.c > +++ b/drivers/rtc/rtc-omap.c > @@ -24,6 +24,7 @@ > #include <linux/of_device.h> > #include <linux/pm_runtime.h> > #include <linux/io.h> > +#include <linux/regulator/consumer.h> > > /* The OMAP1 RTC is a year/month/day/hours/minutes/seconds BCD clock > * with century-range alarm matching, driven by the 32kHz clock. > @@ -121,6 +122,7 @@ > #define OMAP_RTC_HAS_32KCLK_EN BIT(2) > > static void __iomem *rtc_base; > +static struct regulator *rtc_reg; while at that, can you do a proper cleanup and introduce a struct rtc_omap of some sorts which gets allocated during probe ?
Hi Felipe, On Friday 19 September 2014 07:08 PM, Felipe Balbi wrote: > On Fri, Sep 19, 2014 at 03:16:34PM +0530, Lokesh Vutla wrote: >> On some Soc's RTC is powered by an external power regulator. >> e.g. RTC on DRA7 SoC. Make the OMAP RTC driver support a >> power regulator. >> And also making the driver as module_platform_driver to >> support probe deferal. > > I would split module_platform_driver() change to its own patch. Okay will do this. > >> Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com> >> --- >> Tested on DRA7. Logs here: http://fpaste.org/134804/11200041/ >> >> Documentation/devicetree/bindings/rtc/rtc-omap.txt | 3 +++ >> drivers/rtc/rtc-omap.c | 28 ++++++++++++++++++++-- >> 2 files changed, 29 insertions(+), 2 deletions(-) >> >> diff --git a/Documentation/devicetree/bindings/rtc/rtc-omap.txt b/Documentation/devicetree/bindings/rtc/rtc-omap.txt >> index 5a0f02d..c9f963a 100644 >> --- a/Documentation/devicetree/bindings/rtc/rtc-omap.txt >> +++ b/Documentation/devicetree/bindings/rtc/rtc-omap.txt >> @@ -10,6 +10,9 @@ Required properties: >> - interrupts: rtc timer, alarm interrupts in order >> - interrupt-parent: phandle for the interrupt controller >> >> +Optional Properties: >> + - rtc-supply : phandle to the regulator device tree node if needed. >> + >> Example: >> >> rtc@1c23000 { >> diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c >> index 21142e6..4473d1d 100644 >> --- a/drivers/rtc/rtc-omap.c >> +++ b/drivers/rtc/rtc-omap.c >> @@ -24,6 +24,7 @@ >> #include <linux/of_device.h> >> #include <linux/pm_runtime.h> >> #include <linux/io.h> >> +#include <linux/regulator/consumer.h> >> >> /* The OMAP1 RTC is a year/month/day/hours/minutes/seconds BCD clock >> * with century-range alarm matching, driven by the 32kHz clock. >> @@ -121,6 +122,7 @@ >> #define OMAP_RTC_HAS_32KCLK_EN BIT(2) >> >> static void __iomem *rtc_base; >> +static struct regulator *rtc_reg; > > while at that, can you do a proper cleanup and introduce a struct > rtc_omap of some sorts which gets allocated during probe ? Yep, this makes more sense. Will do a proper cleanup and resend the patches. Thanks and regards, Lokesh >
diff --git a/Documentation/devicetree/bindings/rtc/rtc-omap.txt b/Documentation/devicetree/bindings/rtc/rtc-omap.txt index 5a0f02d..c9f963a 100644 --- a/Documentation/devicetree/bindings/rtc/rtc-omap.txt +++ b/Documentation/devicetree/bindings/rtc/rtc-omap.txt @@ -10,6 +10,9 @@ Required properties: - interrupts: rtc timer, alarm interrupts in order - interrupt-parent: phandle for the interrupt controller +Optional Properties: + - rtc-supply : phandle to the regulator device tree node if needed. + Example: rtc@1c23000 { diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c index 21142e6..4473d1d 100644 --- a/drivers/rtc/rtc-omap.c +++ b/drivers/rtc/rtc-omap.c @@ -24,6 +24,7 @@ #include <linux/of_device.h> #include <linux/pm_runtime.h> #include <linux/io.h> +#include <linux/regulator/consumer.h> /* The OMAP1 RTC is a year/month/day/hours/minutes/seconds BCD clock * with century-range alarm matching, driven by the 32kHz clock. @@ -121,6 +122,7 @@ #define OMAP_RTC_HAS_32KCLK_EN BIT(2) static void __iomem *rtc_base; +static struct regulator *rtc_reg; #define rtc_read(addr) readb(rtc_base + (addr)) #define rtc_write(val, addr) writeb(val, rtc_base + (addr)) @@ -372,11 +374,12 @@ static const struct of_device_id omap_rtc_of_match[] = { }; MODULE_DEVICE_TABLE(of, omap_rtc_of_match); -static int __init omap_rtc_probe(struct platform_device *pdev) +static int omap_rtc_probe(struct platform_device *pdev) { struct resource *res; struct rtc_device *rtc; u8 reg, new_ctrl; + int ret; const struct platform_device_id *id_entry; const struct of_device_id *of_id; @@ -402,6 +405,23 @@ static int __init omap_rtc_probe(struct platform_device *pdev) return -ENOENT; } + rtc_reg = devm_regulator_get_optional(&pdev->dev, "rtc"); + if (IS_ERR(rtc_reg)) { + if (PTR_ERR(rtc_reg) == -EPROBE_DEFER) { + dev_err(&pdev->dev, "regulator not ready, retry\n"); + return -EPROBE_DEFER; + } + rtc_reg = NULL; + } + + if (rtc_reg) { + ret = regulator_enable(rtc_reg); + if (ret) { + dev_dbg(&pdev->dev, "regulator enable failed\n"); + return ret; + } + } + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); rtc_base = devm_ioremap_resource(&pdev->dev, res); if (IS_ERR(rtc_base)) @@ -517,6 +537,9 @@ static int __exit omap_rtc_remove(struct platform_device *pdev) pm_runtime_put_sync(&pdev->dev); pm_runtime_disable(&pdev->dev); + if (rtc_reg) + regulator_disable(rtc_reg); + return 0; } @@ -565,6 +588,7 @@ static void omap_rtc_shutdown(struct platform_device *pdev) MODULE_ALIAS("platform:omap_rtc"); static struct platform_driver omap_rtc_driver = { + .probe = omap_rtc_probe, .remove = __exit_p(omap_rtc_remove), .shutdown = omap_rtc_shutdown, .driver = { @@ -576,7 +600,7 @@ static struct platform_driver omap_rtc_driver = { .id_table = omap_rtc_devtype, }; -module_platform_driver_probe(omap_rtc_driver, omap_rtc_probe); +module_platform_driver(omap_rtc_driver); MODULE_AUTHOR("George G. Davis (and others)"); MODULE_LICENSE("GPL");
On some Soc's RTC is powered by an external power regulator. e.g. RTC on DRA7 SoC. Make the OMAP RTC driver support a power regulator. And also making the driver as module_platform_driver to support probe deferal. Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com> --- Tested on DRA7. Logs here: http://fpaste.org/134804/11200041/ Documentation/devicetree/bindings/rtc/rtc-omap.txt | 3 +++ drivers/rtc/rtc-omap.c | 28 ++++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-)