* [PATCH v2] rtc/cmos: add OF bindings
@ 2010-12-01 10:17 Sebastian Andrzej Siewior
[not found] ` <20101201101756.GA31624-Hfxr4Dq0UpYb1SvskN2V4Q@public.gmane.org>
0 siblings, 1 reply; 5+ messages in thread
From: Sebastian Andrzej Siewior @ 2010-12-01 10:17 UTC (permalink / raw)
To: Alessandro Zummo
Cc: sodaville-hfZtesqFncYOwBW4kG4KsQ,
devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
rtc-linux-/JYPxA39Uh5TLH3MbocFFw
This allows to load the OF driver based informations from the device
tree. Systems without BIOS may need to perform some initialization.
PowerPC creates a PNP device from the OF information and performs this
kind of initialization in their private PCI quirk. This looks more
generic.
Signed-off-by: Sebastian Andrzej Siewior <bigeasy-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
CC: rtc-linux-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
Signed-off-by: Dirk Brandewie <dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
v1 - v2:
- changed ctrl_reg & freq_reg to changed ctrl-reg & freq-reg as
recommended by Benh
- added missing get_rtc_time()
- set the default day to 1
- added binding info
Documentation/powerpc/dts-bindings/rtc-cmos.txt | 28 ++++++
drivers/rtc/rtc-cmos.c | 108 +++++++++++++++++++++++
2 files changed, 136 insertions(+), 0 deletions(-)
create mode 100644 Documentation/powerpc/dts-bindings/rtc-cmos.txt
diff --git a/Documentation/powerpc/dts-bindings/rtc-cmos.txt b/Documentation/powerpc/dts-bindings/rtc-cmos.txt
new file mode 100644
index 0000000..7382989
--- /dev/null
+++ b/Documentation/powerpc/dts-bindings/rtc-cmos.txt
@@ -0,0 +1,28 @@
+ Motorola mc146818 compatible RTC
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Required properties:
+ - compatible : "motorola,mc146818"
+ - reg : should contain registers location and length.
+
+Optional properties:
+ - interrupts : should contain interrupt.
+ - interrupt-parent : interrupt source phandle.
+ - ctrl-reg : Contains the initial value of the control register also
+ called "Register B".
+ - freq-reg : Contains the initial value of the frequency register also
+ called "Regsiter A".
+
+"Register A" and "B" are usually initialized by the firmware (BIOS for
+instance). If this is not done, it can be performed by the driver.
+
+ISA Example:
+
+ rtc@70 {
+ compatible = "motorola,mc146818";
+ interrupts = <8 3>;
+ interrupt-parent = <&ioapic1>;
+ ctrl-reg = <2>;
+ freq-reg = <0x26>;
+ reg = <1 0x70 2>;
+ };
diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
index 5856167..e516a4b 100644
--- a/drivers/rtc/rtc-cmos.c
+++ b/drivers/rtc/rtc-cmos.c
@@ -36,6 +36,9 @@
#include <linux/platform_device.h>
#include <linux/mod_devicetable.h>
#include <linux/log2.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/of_platform.h>
/* this is for "generic access to PC-style RTC" using CMOS_READ/CMOS_WRITE */
#include <asm-generic/rtc.h>
@@ -1120,6 +1123,98 @@ static struct pnp_driver cmos_pnp_driver = {
};
#endif /* CONFIG_PNP */
+#ifdef CONFIG_OF
+static bool of_driver_registered;
+
+static const struct of_device_id of_cmos_match[] = {
+ {
+ .compatible = "motorola,mc146818",
+ },
+ { },
+};
+MODULE_DEVICE_TABLE(of, of_cmos_match);
+
+static int __init of_cmos_probe(struct platform_device *dev,
+ const struct of_device_id *match)
+{
+ struct resource res;
+ struct device_node *node = dev->dev.of_node;
+ struct rtc_time time;
+ int ret;
+ int virq;
+ const __be32 *val;
+
+ ret = of_address_to_resource(node, 0, &res);
+ if (ret)
+ return ret;
+
+ virq = irq_of_parse_and_map(node, 0);
+
+ val = of_get_property(node, "ctrl-reg", NULL);
+ if (val)
+ CMOS_WRITE(be32_to_cpup(val), RTC_CONTROL);
+
+ val = of_get_property(node, "freq-reg", NULL);
+ if (val)
+ CMOS_WRITE(be32_to_cpup(val), RTC_FREQ_SELECT);
+
+ get_rtc_time(&time);
+ ret = rtc_valid_tm(&time);
+ if (ret) {
+ struct rtc_time def_time = {
+ .tm_year = 1,
+ .tm_mday = 1,
+ };
+ set_rtc_time(&def_time);
+ }
+
+ return cmos_do_probe(&dev->dev, &res, virq);
+}
+
+static int __exit of_cmos_remove(struct platform_device *dev)
+{
+ cmos_do_remove(&dev->dev);
+ return 0;
+}
+
+static int of_cmos_shutdown(struct platform_device *dev)
+{
+ if (system_state == SYSTEM_POWER_OFF && !cmos_poweroff(&dev->dev))
+ return 0;
+
+ cmos_do_shutdown();
+ return 0;
+}
+
+#ifdef CONFIG_PM
+static int of_cmos_suspend(struct platform_device *dev, pm_message_t mesg)
+{
+ return cmos_suspend(&dev->dev, mesg);
+}
+
+static int of_cmos_resume(struct platform_device *dev)
+{
+ return cmos_resume(&dev->dev);
+}
+#else
+#define of_cmos_suspend NULL
+#define of_cmos_resume NULL
+#endif
+
+static struct of_platform_driver cmos_of_driver_probe = {
+ .driver = {
+ .name = "motorola-mc146818",
+ .owner = THIS_MODULE,
+ .of_match_table = of_cmos_match,
+ },
+ .probe = of_cmos_probe,
+ .remove = of_cmos_remove,
+ .shutdown = of_cmos_shutdown,
+ .suspend = of_cmos_suspend,
+ .resume = of_cmos_resume,
+};
+#endif
+
/*----------------------------------------------------------------*/
@@ -1176,6 +1271,11 @@ static int __init cmos_init(void)
if (retval == 0)
pnp_driver_registered = true;
#endif
+#ifdef CONFIG_OF
+ retval = of_register_platform_driver(&cmos_of_driver_probe);
+ if (retval == 0)
+ of_driver_registered = true;
+#endif
if (!cmos_rtc.dev) {
retval = platform_driver_probe(&cmos_platform_driver,
@@ -1191,6 +1291,10 @@ static int __init cmos_init(void)
if (pnp_driver_registered)
pnp_unregister_driver(&cmos_pnp_driver);
#endif
+#ifdef CONFIG_OF
+ if (of_driver_registered)
+ of_unregister_platform_driver(&cmos_of_driver_probe);
+#endif
return retval;
}
module_init(cmos_init);
@@ -1201,6 +1305,10 @@ static void __exit cmos_exit(void)
if (pnp_driver_registered)
pnp_unregister_driver(&cmos_pnp_driver);
#endif
+#ifdef CONFIG_OF
+ if (of_driver_registered)
+ of_unregister_platform_driver(&cmos_of_driver_probe);
+#endif
if (platform_driver_registered)
platform_driver_unregister(&cmos_platform_driver);
}
--
1.7.3.2
^ permalink raw reply related [flat|nested] 5+ messages in thread[parent not found: <20101201101756.GA31624-Hfxr4Dq0UpYb1SvskN2V4Q@public.gmane.org>]
* Re: [PATCH v2] rtc/cmos: add OF bindings [not found] ` <20101201101756.GA31624-Hfxr4Dq0UpYb1SvskN2V4Q@public.gmane.org> @ 2010-12-02 5:30 ` David Gibson 2010-12-02 6:46 ` Grant Likely 1 sibling, 0 replies; 5+ messages in thread From: David Gibson @ 2010-12-02 5:30 UTC (permalink / raw) To: Sebastian Andrzej Siewior Cc: Alessandro Zummo, devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ, rtc-linux-/JYPxA39Uh5TLH3MbocFFw, sodaville-hfZtesqFncYOwBW4kG4KsQ On Wed, Dec 01, 2010 at 11:17:56AM +0100, Sebastian Andrzej Siewior wrote: > This allows to load the OF driver based informations from the device > tree. Systems without BIOS may need to perform some initialization. > PowerPC creates a PNP device from the OF information and performs this > kind of initialization in their private PCI quirk. This looks more > generic. Nice. We should also get this up on Grant's new wiki for device tree bindings at: http://www.devicetree.org/ Longer term, that will be a better place to collect bindings than inside the kernel documentation. -- David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] rtc/cmos: add OF bindings [not found] ` <20101201101756.GA31624-Hfxr4Dq0UpYb1SvskN2V4Q@public.gmane.org> 2010-12-02 5:30 ` David Gibson @ 2010-12-02 6:46 ` Grant Likely [not found] ` <AANLkTinF8GVv-HwKWCRx2jJoCZVWwNzBou3shi8OJj3S-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 1 sibling, 1 reply; 5+ messages in thread From: Grant Likely @ 2010-12-02 6:46 UTC (permalink / raw) To: Sebastian Andrzej Siewior Cc: Alessandro Zummo, devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ, rtc-linux-/JYPxA39Uh5TLH3MbocFFw, sodaville-hfZtesqFncYOwBW4kG4KsQ On Wed, Dec 1, 2010 at 2:17 AM, Sebastian Andrzej Siewior <bigeasy-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org> wrote: > This allows to load the OF driver based informations from the device > tree. Systems without BIOS may need to perform some initialization. > PowerPC creates a PNP device from the OF information and performs this > kind of initialization in their private PCI quirk. This looks more > generic. > > Signed-off-by: Sebastian Andrzej Siewior <bigeasy-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org> > CC: rtc-linux-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > Signed-off-by: Dirk Brandewie <dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > --- Hi Sebastian. > +static struct of_platform_driver cmos_of_driver_probe = { of_platform_drivers are deprecated and being removed. Regular platform_drivers can be assigned an of_match_table and the platform_bus_type will use it to match drivers to devices. Instead of doing it this way, you can look for a device tree node in the existing platform_drivers probe hook and if it exists then fetch the additional data there. g. ^ permalink raw reply [flat|nested] 5+ messages in thread
[parent not found: <AANLkTinF8GVv-HwKWCRx2jJoCZVWwNzBou3shi8OJj3S-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* [PATCH v3] rtc/cmos: add OF bindings [not found] ` <AANLkTinF8GVv-HwKWCRx2jJoCZVWwNzBou3shi8OJj3S-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2010-12-02 13:35 ` Sebastian Andrzej Siewior 2010-12-02 13:38 ` [PATCH] x86/rtc: don't register rtc if we have an OF node for it Sebastian Andrzej Siewior 1 sibling, 0 replies; 5+ messages in thread From: Sebastian Andrzej Siewior @ 2010-12-02 13:35 UTC (permalink / raw) To: Grant Likely Cc: Alessandro Zummo, devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ, rtc-linux-/JYPxA39Uh5TLH3MbocFFw, sodaville-hfZtesqFncYOwBW4kG4KsQ This allows to load the OF driver based informations from the device tree. Systems without BIOS may need to perform some initialization. PowerPC creates a PNP device from the OF information and performs this kind of initialization in their private PCI quirk. This looks more generic. Signed-off-by: Sebastian Andrzej Siewior <bigeasy-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org> CC: rtc-linux-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org --- Documentation/powerpc/dts-bindings/rtc-cmos.txt | 28 ++++++++++++++++ drivers/rtc/rtc-cmos.c | 39 +++++++++++++++++++++++ 2 files changed, 67 insertions(+), 0 deletions(-) create mode 100644 Documentation/powerpc/dts-bindings/rtc-cmos.txt diff --git a/Documentation/powerpc/dts-bindings/rtc-cmos.txt b/Documentation/powerpc/dts-bindings/rtc-cmos.txt new file mode 100644 index 0000000..7382989 --- /dev/null +++ b/Documentation/powerpc/dts-bindings/rtc-cmos.txt @@ -0,0 +1,28 @@ + Motorola mc146818 compatible RTC +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Required properties: + - compatible : "motorola,mc146818" + - reg : should contain registers location and length. + +Optional properties: + - interrupts : should contain interrupt. + - interrupt-parent : interrupt source phandle. + - ctrl-reg : Contains the initial value of the control register also + called "Register B". + - freq-reg : Contains the initial value of the frequency register also + called "Regsiter A". + +"Register A" and "B" are usually initialized by the firmware (BIOS for +instance). If this is not done, it can be performed by the driver. + +ISA Example: + + rtc@70 { + compatible = "motorola,mc146818"; + interrupts = <8 3>; + interrupt-parent = <&ioapic1>; + ctrl-reg = <2>; + freq-reg = <0x26>; + reg = <1 0x70 2>; + }; diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c index 5856167..dbb95b3 100644 --- a/drivers/rtc/rtc-cmos.c +++ b/drivers/rtc/rtc-cmos.c @@ -36,6 +36,8 @@ #include <linux/platform_device.h> #include <linux/mod_devicetable.h> #include <linux/log2.h> +#include <linux/of.h> +#include <linux/of_platform.h> /* this is for "generic access to PC-style RTC" using CMOS_READ/CMOS_WRITE */ #include <asm-generic/rtc.h> @@ -1121,6 +1123,15 @@ static struct pnp_driver cmos_pnp_driver = { #endif /* CONFIG_PNP */ +#ifdef CONFIG_OF +static const struct of_device_id of_cmos_match[] = { + { + .compatible = "motorola,mc146818", + }, + { }, +}; +MODULE_DEVICE_TABLE(of, of_cmos_match); +#endif /*----------------------------------------------------------------*/ /* Platform setup should have set up an RTC device, when PNP is @@ -1129,6 +1140,31 @@ static struct pnp_driver cmos_pnp_driver = { static int __init cmos_platform_probe(struct platform_device *pdev) { + if (pdev->dev.of_node) { + struct device_node *node = pdev->dev.of_node; + struct rtc_time time; + int ret; + const __be32 *val; + + val = of_get_property(node, "ctrl-reg", NULL); + if (val) + CMOS_WRITE(be32_to_cpup(val), RTC_CONTROL); + + val = of_get_property(node, "freq-reg", NULL); + if (val) + CMOS_WRITE(be32_to_cpup(val), RTC_FREQ_SELECT); + + get_rtc_time(&time); + ret = rtc_valid_tm(&time); + if (ret) { + struct rtc_time def_time = { + .tm_year = 1, + .tm_mday = 1, + }; + set_rtc_time(&def_time); + } + } + cmos_wake_setup(&pdev->dev); return cmos_do_probe(&pdev->dev, platform_get_resource(pdev, IORESOURCE_IO, 0), @@ -1157,6 +1193,9 @@ static struct platform_driver cmos_platform_driver = { .shutdown = cmos_platform_shutdown, .driver = { .name = (char *) driver_name, +#if defined(CONFIG_OF) + .of_match_table = of_cmos_match, +#endif .suspend = cmos_suspend, .resume = cmos_resume, } -- 1.7.3.2 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH] x86/rtc: don't register rtc if we have an OF node for it [not found] ` <AANLkTinF8GVv-HwKWCRx2jJoCZVWwNzBou3shi8OJj3S-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 2010-12-02 13:35 ` [PATCH v3] " Sebastian Andrzej Siewior @ 2010-12-02 13:38 ` Sebastian Andrzej Siewior 1 sibling, 0 replies; 5+ messages in thread From: Sebastian Andrzej Siewior @ 2010-12-02 13:38 UTC (permalink / raw) To: Grant Likely Cc: Alessandro Zummo, rtc-linux-/JYPxA39Uh5TLH3MbocFFw, Sebastian Andrzej Siewior, x86-DgEjT+Ai2ygdnm+yROfE0A, linux-kernel-u79uwXL29TY76Z2rM5mHXA, sodaville-hfZtesqFncYOwBW4kG4KsQ, devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ or the rtc driver will probe for two devices: the static platform device the OF device. Signed-off-by: Sebastian Andrzej Siewior <bigeasy-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org> --- arch/x86/kernel/rtc.c | 23 +++++++++++++++++++++++ 1 files changed, 23 insertions(+), 0 deletions(-) diff --git a/arch/x86/kernel/rtc.c b/arch/x86/kernel/rtc.c index 1cfbbfc..382c6cb 100644 --- a/arch/x86/kernel/rtc.c +++ b/arch/x86/kernel/rtc.c @@ -6,6 +6,7 @@ #include <linux/acpi.h> #include <linux/bcd.h> #include <linux/pnp.h> +#include <linux/of.h> #include <asm/vsyscall.h> #include <asm/x86_init.h> @@ -218,6 +219,25 @@ static struct platform_device rtc_device = { .num_resources = ARRAY_SIZE(rtc_resources), }; +#ifdef CONFIG_OF +static __init int have_rtc_of_node(void) +{ + struct device_node *n; + + n = of_find_compatible_node(NULL, NULL, "motorola,mc146818"); + if (n) { + of_node_put(n); + return 1; + } + return 0; +} +#else +static inline int have_rtc_of_node(void) +{ + return 0; +} +#endif + static __init int add_rtc_cmos(void) { #ifdef CONFIG_PNP @@ -237,6 +257,9 @@ static __init int add_rtc_cmos(void) } #endif + if (have_rtc_of_node()) + return 0; + platform_device_register(&rtc_device); dev_info(&rtc_device.dev, "registered platform RTC device (no PNP device found)\n"); -- 1.7.3.2 ^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-12-02 13:38 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-01 10:17 [PATCH v2] rtc/cmos: add OF bindings Sebastian Andrzej Siewior
[not found] ` <20101201101756.GA31624-Hfxr4Dq0UpYb1SvskN2V4Q@public.gmane.org>
2010-12-02 5:30 ` David Gibson
2010-12-02 6:46 ` Grant Likely
[not found] ` <AANLkTinF8GVv-HwKWCRx2jJoCZVWwNzBou3shi8OJj3S-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-12-02 13:35 ` [PATCH v3] " Sebastian Andrzej Siewior
2010-12-02 13:38 ` [PATCH] x86/rtc: don't register rtc if we have an OF node for it Sebastian Andrzej Siewior
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox