Skip to contentSkip to conversation

Create add_rtc() function to enable the RTC CMOS driver

PATCH Superseded Wade Farnsworth 4 participants 10 messages Jun 20, 2007 – Jul 10, 2007 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Create add_rtc() function to enable the RTC CMOS driver

In order to use the RTC CMOS driver, each architecture must register a platform device for the RTC.

This creates a function to register the platform device based on the RTC device node and verifies that the RTC port against the hard-coded value in asm/mc146818rtc.h. It also sets the RTC to 24-hr mode as 12-hr mode is not currently supported by the driver.

---

 arch/powerpc/sysdev/Makefile         |    1 
 arch/powerpc/sysdev/rtc_cmos_setup.c |   54 +++++++++++++++++++++++++
 2 files changed, 55 insertions(+)
arch/powerpc/sysdev/Makefile +1 -0
Index: linux-2.6-powerpc-8641/arch/powerpc/sysdev/Makefile
===================================================================
@@ -18,6 +18,7 @@ obj-$(CONFIG_TSI108_BRIDGE)	+= tsi108_pc
 obj-$(CONFIG_QUICC_ENGINE)	+= qe_lib/
 mv64x60-$(CONFIG_PCI)		+= mv64x60_pci.o
 obj-$(CONFIG_MV64X60)		+= $(mv64x60-y) mv64x60_pic.o mv64x60_dev.o
+obj-$(CONFIG_RTC_DRV_CMOS)	+= rtc_cmos_setup.o
 
 # contains only the suspend handler for time
 obj-$(CONFIG_PM)		+= timer.o
arch/powerpc/sysdev/rtc_cmos_setup.c new file +54 -0

54 lines not on this page · raw message

#1 lore raw
Quoted 4 lines

This creates a function to register the platform device based on the RTC device node and verifies that the RTC port against the hard-coded value in asm/mc146818rtc.h. It also sets the RTC to 24-hr mode as 12-hr mode is not currently supported by the driver.

The 24h thing should be set in the driver itself. Does the driver handle binary vs. decimal mode btw? If not, you'll want to do the analogue thing for that.

Segher

#2 lore raw
Quoted 10 lines · Segher Boessenkool
Quoted 5 lines

This creates a function to register the platform device based on the RTC
device node and verifies that the RTC port against the hard-coded value in asm/mc146818rtc.h. It also sets the RTC to 24-hr mode as 12-hr mode is not currently supported by the driver.

The 24h thing should be set in the driver itself. Does the driver handle binary vs. decimal mode btw? If not, you'll want to do the analogue thing for that.

OK, I'll look into putting the 24h fix into the driver.

It looks like binary mode is also not supported, so I'll add a fix for that as well.

Thanks,

--Wade

#3 lore raw

PATCH v3 1/1 Create add_rtc() function to enable the RTC CMOS driver

In reply to Wade Farnsworth

In order to use the RTC CMOS driver, each architecture must register a platform device for the RTC.

This creates a function to register the platform device based on the RTC device node and verifies that the RTC port against the hard-coded value in asm/mc146818rtc.h.

---

 arch/powerpc/sysdev/Makefile         |    1 
 arch/powerpc/sysdev/rtc_cmos_setup.c |   51 +++++++++++++++++++++++++
 2 files changed, 52 insertions(+)
arch/powerpc/sysdev/Makefile +1 -0
Index: linux-2.6-powerpc-8641/arch/powerpc/sysdev/Makefile
===================================================================
@@ -18,6 +18,7 @@ obj-$(CONFIG_TSI108_BRIDGE)	+= tsi108_pc
 obj-$(CONFIG_QUICC_ENGINE)	+= qe_lib/
 mv64x60-$(CONFIG_PCI)		+= mv64x60_pci.o
 obj-$(CONFIG_MV64X60)		+= $(mv64x60-y) mv64x60_pic.o mv64x60_dev.o
+obj-$(CONFIG_RTC_DRV_CMOS)	+= rtc_cmos_setup.o
 
 # contains only the suspend handler for time
 obj-$(CONFIG_PM)		+= timer.o
arch/powerpc/sysdev/rtc_cmos_setup.c new file +8 -0
Index: linux-2.6-powerpc-8641/arch/powerpc/sysdev/rtc_cmos_setup.c
===================================================================
@@ -0,0 +1,51 @@
+/*
+ * Setup code for PC-style Real-Time Clock.
+ *
+ * Author: Wade Farnsworth <[email protected]>
+ *
+ * 2007 (c) MontaVista Software, Inc. This file is licensed under
+ * the terms of the GNU General Public License version 2. This program
+ * is licensed "as is" without any warranty of any kind, whether

express
+ * or implied.
+ */
+
+#include <linux/platform_device.h>
+#include <linux/err.h>
+#include <linux/init.h>
+#include <linux/mc146818rtc.h>
+
+#include <asm/prom.h>
+
+static int __init add_rtc(void)
+{
+ struct device_node *np;
+ struct platform_device *pd;
+ struct resource res;
+
+ np = of_find_compatible_node(NULL, NULL, "pnpPNP,b00");
+ if (!np)
+ return -ENODEV;
+
+ if (of_address_to_resource(np, 0, &res)) {
+ of_node_put(np);
+ return -ENODEV;
+ }
+
+ /*
+ * RTC_PORT(x) is hardcoded in asm/mc146818rtc.h. Verify that the
+ * address provided by the device node matches.
+ */
+ if (res.start != RTC_PORT(0)) {
+ of_node_put(np);
+ return -ENODEV;
+ }
+
+ pd = platform_device_register_simple("rtc_cmos", -1,
+ &res, 1);
+ of_node_put(np);
+ if (IS_ERR(pd))
+ return PTR_ERR(pd);
+
+ return 0;
+}
+fs_initcall(add_rtc);

#4 lore raw

Review

Quoted 8 lines
(quoted diff) +8 -0
+	/*
+	 * RTC_PORT(x) is hardcoded in asm/mc146818rtc.h.  Verify that the
+	 * address provided by the device node matches.
+	 */
+	if (res.start != RTC_PORT(0)) {
+		of_node_put(np);
+		return -ENODEV;
+	}

You can place the of_node_put() here and remove the previous one, and the following one.

Review

Quoted 3 lines
(quoted diff) +3 -0
+	pd = platform_device_register_simple("rtc_cmos", -1,
+					     &res, 1);
+	of_node_put(np);

Code looks fine, with or without that change.

Segher

#5 lore raw
In reply to Wade Farnsworth
Quoted 8 lines · Wade Farnsworth

In order to use the RTC CMOS driver, each architecture must register a platform device for the RTC.

This creates a function to register the platform device based on the RTC device node and verifies that the RTC port against the hard-coded value in asm/mc146818rtc.h.

Hrm. It seems rather specific. Can we do this more generally, by creating an of_platform device which binds to rtc nodes, then registers an appropriate platform device for each so that the generic rtc drivers pick them up. Obviously we'd need some sort of table mapping the device node compatible properties to the appropriate platform device names.

Quoted 49 lines

Index: linux-2.6-powerpc-8641/arch/powerpc/sysdev/Makefile
===================================================================

arch/powerpc/sysdev/Makefile +1 -0
@@ -18,6 +18,7 @@ obj-$(CONFIG_TSI108_BRIDGE)	+= tsi108_pc
 obj-$(CONFIG_QUICC_ENGINE)	+= qe_lib/
 mv64x60-$(CONFIG_PCI)		+= mv64x60_pci.o
 obj-$(CONFIG_MV64X60)		+= $(mv64x60-y) mv64x60_pic.o mv64x60_dev.o
+obj-$(CONFIG_RTC_DRV_CMOS)	+= rtc_cmos_setup.o
 
 # contains only the suspend handler for time
 obj-$(CONFIG_PM)		+= timer.o

Index: linux-2.6-powerpc-8641/arch/powerpc/sysdev/rtc_cmos_setup.c
===================================================================

arch/powerpc/sysdev/rtc_cmos_setup.c new file +8 -0
@@ -0,0 +1,51 @@
+/*
+ * Setup code for PC-style Real-Time Clock.
+ *
+ * Author: Wade Farnsworth <[email protected]>
+ *
+ * 2007 (c) MontaVista Software, Inc. This file is licensed under
+ * the terms of the GNU General Public License version 2. This program
+ * is licensed "as is" without any warranty of any kind, whether

express
+ * or implied.
+ */

arch/powerpc/sysdev/rtc_cmos_setup.c new file +21 -0
+
+#include <linux/platform_device.h>
+#include <linux/err.h>
+#include <linux/init.h>
+#include <linux/mc146818rtc.h>
+
+#include <asm/prom.h>
+
+static int  __init add_rtc(void)
+{
+	struct device_node *np;
+	struct platform_device *pd;
+	struct resource res;
+
+	np = of_find_compatible_node(NULL, NULL, "pnpPNP,b00");
+	if (!np)
+		return -ENODEV;
+
+	if (of_address_to_resource(np, 0, &res)) {
+		of_node_put(np);
+		return -ENODEV;

arch/powerpc/sysdev/rtc_cmos_setup.c

Quoted 10 lines
arch/powerpc/sysdev/rtc_cmos_setup.c new file +10 -0
+	}
+
+	/*
+	 * RTC_PORT(x) is hardcoded in asm/mc146818rtc.h.  Verify that the
+	 * address provided by the device node matches.
+	 */
+	if (res.start != RTC_PORT(0)) {
+		of_node_put(np);
+		return -ENODEV;
+	}

This looks totally bogus. If we have a device tree we should be using the address information from there, not using hardcoded magic. Sounds like asm/mc146818rtc.h needs some serious fixing.

Quoted 17 lines
arch/powerpc/sysdev/rtc_cmos_setup.c new file +10 -0
+
+	pd = platform_device_register_simple("rtc_cmos", -1,
+					     &res, 1);
+	of_node_put(np);
+	if (IS_ERR(pd))
+		return PTR_ERR(pd);
+
+	return 0;
+}
+fs_initcall(add_rtc);

_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://ozlabs.org/mailman/listinfo/linuxppc-dev

Signature · 4 lines
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
#6 lore raw
Quoted 7 lines

Hrm. It seems rather specific. Can we do this more generally, by creating an of_platform device which binds to rtc nodes, then registers an appropriate platform device for each so that the generic rtc drivers pick them up. Obviously we'd need some sort of table mapping the device node compatible properties to the appropriate platform device names.

Quoted 11 lines

Review

Quoted 7 lines
(quoted diff) +7 -0
+	 * RTC_PORT(x) is hardcoded in asm/mc146818rtc.h.  Verify that the
+	 * address provided by the device node matches.
+	 */
+	if (res.start != RTC_PORT(0)) {
+		of_node_put(np);
+		return -ENODEV;
+	}

This looks totally bogus. If we have a device tree we should be using the address information from there, not using hardcoded magic. Sounds like asm/mc146818rtc.h needs some serious fixing.

Both of your comments would be nice extensions (and the right way forwards), but Wade's patch is good as-is already.

Segher

#7 lore raw
Quoted 19 lines · Segher Boessenkool
Quoted 7 lines

Hrm. It seems rather specific. Can we do this more generally, by creating an of_platform device which binds to rtc nodes, then registers an appropriate platform device for each so that the generic rtc drivers pick them up. Obviously we'd need some sort of table mapping the device node compatible properties to the appropriate platform device names.

Quoted 11 lines

Review

Quoted 7 lines
(quoted diff) +7 -0
+	 * RTC_PORT(x) is hardcoded in asm/mc146818rtc.h.  Verify that the
+	 * address provided by the device node matches.
+	 */
+	if (res.start != RTC_PORT(0)) {
+		of_node_put(np);
+		return -ENODEV;
+	}

This looks totally bogus. If we have a device tree we should be using the address information from there, not using hardcoded magic. Sounds like asm/mc146818rtc.h needs some serious fixing.

Quoted 2 lines

Both of your comments would be nice extensions (and the right way forwards), but Wade's patch is good as-is already.

True enough.

Signature · 4 lines
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
#8 lore raw
In reply to Wade Farnsworth
Quoted 6 lines · Wade Farnsworth

In order to use the RTC CMOS driver, each architecture must register a platform device for the RTC.

This creates a function to register the platform device based on the RTC device node and verifies that the RTC port against the hard-coded value in asm/mc146818rtc.h.

The patch appears to be line-wrapped. Please re-send.

Paul.

#9 lore raw

PATCH v4 1/1 Create add_rtc() function to enable the RTC CMOS driver

In order to use the RTC CMOS driver, each architecture must register a platform device for the RTC.

This creates a function to register the platform device based on the RTC device node and verifies that the RTC port against the hard-coded value in asm/mc146818rtc.h.

---

Fixed line wrapping.

 arch/powerpc/sysdev/Makefile         |    1 
 arch/powerpc/sysdev/rtc_cmos_setup.c |   49 +++++++++++++++++++++++++
 2 files changed, 50 insertions(+)
arch/powerpc/sysdev/Makefile +1 -0
index 7d8ac1b..f65078c 100644
@@ -16,6 +16,7 @@ obj-$(CONFIG_TSI108_BRIDGE)	+= tsi108_pci.o tsi108_dev.o
 obj-$(CONFIG_QUICC_ENGINE)	+= qe_lib/
 mv64x60-$(CONFIG_PCI)		+= mv64x60_pci.o
 obj-$(CONFIG_MV64X60)		+= $(mv64x60-y) mv64x60_pic.o mv64x60_dev.o
+obj-$(CONFIG_RTC_DRV_CMOS)	+= rtc_cmos_setup.o
 
 # contains only the suspend handler for time
 ifeq ($(CONFIG_RTC_CLASS),)
arch/powerpc/sysdev/rtc_cmos_setup.c new file +49 -0

49 lines not on this page · raw message