xref: /OK3568_Linux_fs/kernel/arch/powerpc/sysdev/of_rtc.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-or-later
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Instantiate mmio-mapped RTC chips based on device tree information
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright 2007 David Gibson <dwg@au1.ibm.com>, IBM Corporation.
6*4882a593Smuzhiyun  */
7*4882a593Smuzhiyun #include <linux/kernel.h>
8*4882a593Smuzhiyun #include <linux/of.h>
9*4882a593Smuzhiyun #include <linux/init.h>
10*4882a593Smuzhiyun #include <linux/of_address.h>
11*4882a593Smuzhiyun #include <linux/of_platform.h>
12*4882a593Smuzhiyun #include <linux/slab.h>
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun static __initdata struct {
15*4882a593Smuzhiyun 	const char *compatible;
16*4882a593Smuzhiyun 	char *plat_name;
17*4882a593Smuzhiyun } of_rtc_table[] = {
18*4882a593Smuzhiyun 	{ "ds1743-nvram", "rtc-ds1742" },
19*4882a593Smuzhiyun };
20*4882a593Smuzhiyun 
of_instantiate_rtc(void)21*4882a593Smuzhiyun void __init of_instantiate_rtc(void)
22*4882a593Smuzhiyun {
23*4882a593Smuzhiyun 	struct device_node *node;
24*4882a593Smuzhiyun 	int err;
25*4882a593Smuzhiyun 	int i;
26*4882a593Smuzhiyun 
27*4882a593Smuzhiyun 	for (i = 0; i < ARRAY_SIZE(of_rtc_table); i++) {
28*4882a593Smuzhiyun 		char *plat_name = of_rtc_table[i].plat_name;
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun 		for_each_compatible_node(node, NULL,
31*4882a593Smuzhiyun 					 of_rtc_table[i].compatible) {
32*4882a593Smuzhiyun 			struct resource *res;
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun 			res = kmalloc(sizeof(*res), GFP_KERNEL);
35*4882a593Smuzhiyun 			if (!res) {
36*4882a593Smuzhiyun 				printk(KERN_ERR "OF RTC: Out of memory "
37*4882a593Smuzhiyun 				       "allocating resource structure for %pOF\n",
38*4882a593Smuzhiyun 				       node);
39*4882a593Smuzhiyun 				continue;
40*4882a593Smuzhiyun 			}
41*4882a593Smuzhiyun 
42*4882a593Smuzhiyun 			err = of_address_to_resource(node, 0, res);
43*4882a593Smuzhiyun 			if (err) {
44*4882a593Smuzhiyun 				printk(KERN_ERR "OF RTC: Error "
45*4882a593Smuzhiyun 				       "translating resources for %pOF\n",
46*4882a593Smuzhiyun 				       node);
47*4882a593Smuzhiyun 				continue;
48*4882a593Smuzhiyun 			}
49*4882a593Smuzhiyun 
50*4882a593Smuzhiyun 			printk(KERN_INFO "OF_RTC: %pOF is a %s @ 0x%llx-0x%llx\n",
51*4882a593Smuzhiyun 			       node, plat_name,
52*4882a593Smuzhiyun 			       (unsigned long long)res->start,
53*4882a593Smuzhiyun 			       (unsigned long long)res->end);
54*4882a593Smuzhiyun 			platform_device_register_simple(plat_name, -1, res, 1);
55*4882a593Smuzhiyun 		}
56*4882a593Smuzhiyun 	}
57*4882a593Smuzhiyun }
58