xref: /OK3568_Linux_fs/kernel/arch/powerpc/sysdev/rtc_cmos_setup.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Setup code for PC-style Real-Time Clock.
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Author: Wade Farnsworth <wfarnsworth@mvista.com>
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * 2007 (c) MontaVista Software, Inc. This file is licensed under
7*4882a593Smuzhiyun  * the terms of the GNU General Public License version 2. This program
8*4882a593Smuzhiyun  * is licensed "as is" without any warranty of any kind, whether express
9*4882a593Smuzhiyun  * or implied.
10*4882a593Smuzhiyun  */
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun #include <linux/platform_device.h>
13*4882a593Smuzhiyun #include <linux/err.h>
14*4882a593Smuzhiyun #include <linux/init.h>
15*4882a593Smuzhiyun #include <linux/module.h>
16*4882a593Smuzhiyun #include <linux/mc146818rtc.h>
17*4882a593Smuzhiyun 
18*4882a593Smuzhiyun #include <asm/prom.h>
19*4882a593Smuzhiyun 
add_rtc(void)20*4882a593Smuzhiyun static int  __init add_rtc(void)
21*4882a593Smuzhiyun {
22*4882a593Smuzhiyun 	struct device_node *np;
23*4882a593Smuzhiyun 	struct platform_device *pd;
24*4882a593Smuzhiyun 	struct resource res[2];
25*4882a593Smuzhiyun 	unsigned int num_res = 1;
26*4882a593Smuzhiyun 	int ret;
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun 	memset(&res, 0, sizeof(res));
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun 	np = of_find_compatible_node(NULL, NULL, "pnpPNP,b00");
31*4882a593Smuzhiyun 	if (!np)
32*4882a593Smuzhiyun 		return -ENODEV;
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun 	ret = of_address_to_resource(np, 0, &res[0]);
35*4882a593Smuzhiyun 	of_node_put(np);
36*4882a593Smuzhiyun 	if (ret)
37*4882a593Smuzhiyun 		return ret;
38*4882a593Smuzhiyun 
39*4882a593Smuzhiyun 	/*
40*4882a593Smuzhiyun 	 * RTC_PORT(x) is hardcoded in asm/mc146818rtc.h.  Verify that the
41*4882a593Smuzhiyun 	 * address provided by the device node matches.
42*4882a593Smuzhiyun 	 */
43*4882a593Smuzhiyun 	if (res[0].start != RTC_PORT(0))
44*4882a593Smuzhiyun 		return -EINVAL;
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun 	np = of_find_compatible_node(NULL, NULL, "chrp,iic");
47*4882a593Smuzhiyun 	if (!np)
48*4882a593Smuzhiyun 		np = of_find_compatible_node(NULL, NULL, "pnpPNP,000");
49*4882a593Smuzhiyun 	if (np) {
50*4882a593Smuzhiyun 		of_node_put(np);
51*4882a593Smuzhiyun 		/*
52*4882a593Smuzhiyun 		 * Use a fixed interrupt value of 8 since on PPC if we are
53*4882a593Smuzhiyun 		 * using this its off an i8259 which we ensure has interrupt
54*4882a593Smuzhiyun 		 * numbers 0..15.
55*4882a593Smuzhiyun 		 */
56*4882a593Smuzhiyun 		res[1].start = 8;
57*4882a593Smuzhiyun 		res[1].end = 8;
58*4882a593Smuzhiyun 		res[1].flags = IORESOURCE_IRQ;
59*4882a593Smuzhiyun 		num_res++;
60*4882a593Smuzhiyun 	}
61*4882a593Smuzhiyun 
62*4882a593Smuzhiyun 	pd = platform_device_register_simple("rtc_cmos", -1,
63*4882a593Smuzhiyun 					     &res[0], num_res);
64*4882a593Smuzhiyun 
65*4882a593Smuzhiyun 	return PTR_ERR_OR_ZERO(pd);
66*4882a593Smuzhiyun }
67*4882a593Smuzhiyun fs_initcall(add_rtc);
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun MODULE_LICENSE("GPL");
70