From: David Gibson <hidden> Date: 2007-12-21 02:21:30
This patch extends the Ebony and Walnut platform code to instantiate
the existing ds1742 RTC class driver for the DS1743 RTC/NVRAM chip
found on both those boards. The patch uses a helper function to scan
the device tree and instantiate the appropriate platform_device based
on it, so it should be easy to extend for other boards which have mmio
mapped RTC chips.
Along with this, the device tree binding for the ds1743 chips is
tweaked, based on the existing DS1385 OF binding found at:
http://playground.sun.com/1275/proposals/Closed/Remanded/Accepted/346-it.txt
Although that document covers the NVRAM portion of the chip, whereas
here we're interested in the RTC portion, so it's not entirely clear
if that's a good model.
This implements only RTC class driver support - that is /dev/rtc0, not
/dev/rtc, and the low-level get/set time callbacks remain
unimplemented. That means in order to get at the clock you will
either need a modified version of hwclock which will look at
/dev/rtc0, or you'll need to configure udev to symlink rtc0 to rtc.
Signed-off-by: David Gibson <redacted>
Index: working-2.6/arch/powerpc/boot/dts/ebony.dts
===================================================================
@@ -27,6 +27,7 @@ obj-$(CONFIG_PPC_I8259) += i8259.oobj-$(CONFIG_PPC_83xx)+=ipic.oobj-$(CONFIG_4xx)+=uic.oobj-$(CONFIG_XILINX_VIRTEX)+=xilinx_intc.o+obj-$(CONFIG_OF_RTC)+=of_rtc.oendif# Temporary hack until we have migrated to asm-powerpc
@@ -0,0 +1,59 @@+/*+*Instantiatemmio-mappedRTCchipsbasedondevicetreeinformation+*+*Copyright2007DavidGibson<dwg@au1.ibm.com>,IBMCorporation.+*+*Thisprogramisfreesoftware;youcanredistributeitand/ormodifyit+*underthetermsoftheGNUGeneralPublicLicenseaspublishedbythe+*FreeSoftwareFoundation;eitherversion2oftheLicense,or(atyour+*option)anylaterversion.+*/+#include<linux/kernel.h>+#include<linux/of.h>+#include<linux/init.h>+#include<asm/of_platform.h>++staticstruct{+char*compatible;+char*plat_name;+}of_rtc_table[]={+{"ds1743-nvram","rtc-ds1742"},+};++void__initof_instantiate_rtc(void)+{+structdevice_node*node;+interr;+inti;++for(i=0;i<ARRAY_SIZE(of_rtc_table);i++){+char*compatible=of_rtc_table[i].compatible;+char*plat_name=of_rtc_table[i].plat_name;++for_each_compatible_node(node,NULL,compatible){+structresource*res;++res=kmalloc(sizeof(*res),GFP_KERNEL);+if(!res){+printk(KERN_ERR"OF RTC: Out of memory "+"allocating resource structure for %s\n",+node->full_name);+continue;+}++err=of_address_to_resource(node,0,res);+if(err){+printk(KERN_ERR"OF RTC: Error "+"translating resources for %s\n",+node->full_name);+continue;+}++printk(KERN_INFO"OF_RTC: %s is a %s @ 0x%llx-0x%llx\n",+node->full_name,plat_name,+(unsignedlonglong)res->start,+(unsignedlonglong)res->end);+platform_device_register_simple(plat_name,-1,res,1);+}+}+}
@@ -39,6 +39,7 @@ static int __init walnut_device_probe(vo/* FIXME: do bus probe here */of_platform_bus_probe(NULL,walnut_of_bus,NULL);+of_instantiate_rtc();return0;}
--
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
const (ok, no, thanks to platform_device_register_simple()).
+} of_rtc_table[] = {
+ { "ds1743-nvram", "rtc-ds1742" },
+};
+
+void __init of_instantiate_rtc(void)
+{
+ struct device_node *node;
+ int err;
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(of_rtc_table); i++) {
+ char *compatible = of_rtc_table[i].compatible;
const (or maybe just use of_rtc_table[i].compatible directly in the one
place it is used).
--
Cheers,
Stephen Rothwell sfr@canb.auug.org.au
http://www.canb.auug.org.au/~sfr/
New config options should have descriptions, even if they're silent
ones.
Uh.. but if there's a description, won't kconfig prompt for the
option? This one should only ever be selected by the platform
options.
--
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
New config options should have descriptions, even if they're silent
ones.
Uh.. but if there's a description, won't kconfig prompt for the
option? This one should only ever be selected by the platform
options.
Sorry, should have said "should have help texts to describe them". Yes,
the one-line description will trigger a question, but adding a short
help text describing what the config option is for does not.
-Olof
From: David Gibson <hidden> Date: 2008-01-11 03:25:39
This patch extends the Ebony and Walnut platform code to instantiate
the existing ds1742 RTC class driver for the DS1743 RTC/NVRAM chip
found on both those boards. The patch uses a helper function to scan
the device tree and instantiate the appropriate platform_device based
on it, so it should be easy to extend for other boards which have mmio
mapped RTC chips.
Along with this, the device tree binding for the ds1743 chips is
tweaked, based on the existing DS1385 OF binding found at:
http://playground.sun.com/1275/proposals/Closed/Remanded/Accepted/346-it.txt
Although that document covers the NVRAM portion of the chip, whereas
here we're interested in the RTC portion, so it's not entirely clear
if that's a good model.
This implements only RTC class driver support - that is /dev/rtc0, not
/dev/rtc, and the low-level get/set time callbacks remain
unimplemented. That means in order to get at the clock you will
either need a modified version of hwclock which will look at
/dev/rtc0, or you'll need to configure udev to symlink rtc0 to rtc.
Signed-off-by: David Gibson <redacted>
---
Updated for kernel changes and feedback.
Index: working-2.6/arch/powerpc/boot/dts/ebony.dts
===================================================================
@@ -0,0 +1,59 @@+/*+*Instantiatemmio-mappedRTCchipsbasedondevicetreeinformation+*+*Copyright2007DavidGibson<dwg@au1.ibm.com>,IBMCorporation.+*+*Thisprogramisfreesoftware;youcanredistributeitand/ormodifyit+*underthetermsoftheGNUGeneralPublicLicenseaspublishedbythe+*FreeSoftwareFoundation;eitherversion2oftheLicense,or(atyour+*option)anylaterversion.+*/+#include<linux/kernel.h>+#include<linux/of.h>+#include<linux/init.h>+#include<linux/of_platform.h>++static__initdatastruct{+constchar*compatible;+char*plat_name;+}of_rtc_table[]={+{"ds1743-nvram","rtc-ds1742"},+};++void__initof_instantiate_rtc(void)+{+structdevice_node*node;+interr;+inti;++for(i=0;i<ARRAY_SIZE(of_rtc_table);i++){+char*plat_name=of_rtc_table[i].plat_name;++for_each_compatible_node(node,NULL,+of_rtc_table[i].compatible){+structresource*res;++res=kmalloc(sizeof(*res),GFP_KERNEL);+if(!res){+printk(KERN_ERR"OF RTC: Out of memory "+"allocating resource structure for %s\n",+node->full_name);+continue;+}++err=of_address_to_resource(node,0,res);+if(err){+printk(KERN_ERR"OF RTC: Error "+"translating resources for %s\n",+node->full_name);+continue;+}++printk(KERN_INFO"OF_RTC: %s is a %s @ 0x%llx-0x%llx\n",+node->full_name,plat_name,+(unsignedlonglong)res->start,+(unsignedlonglong)res->end);+platform_device_register_simple(plat_name,-1,res,1);+}+}+}
--
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
If you make this an array, then the string will become __initdata as well.
Well, yes, but then I'd have to pick a specific size for the string.
Since this is supposed to be a stopgap until I can build a more
general constructor mechanism..
Well.. sort of, but there's not really any sane way of reporting it.
This will be called from early platform init code, failures shouldn't
cause us not to boot, and failure to register one rtc shouldn't cause
us not to attempt to register others if they're present.
--
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