xref: /linux/arch/powerpc/sysdev/rtc_cmos_setup.c (revision ada3ea6fcde45abc55e2af0e564455fd7f943a79)
193ab4718SWade Farnsworth /*
293ab4718SWade Farnsworth  * Setup code for PC-style Real-Time Clock.
393ab4718SWade Farnsworth  *
493ab4718SWade Farnsworth  * Author: Wade Farnsworth <wfarnsworth@mvista.com>
593ab4718SWade Farnsworth  *
693ab4718SWade Farnsworth  * 2007 (c) MontaVista Software, Inc. This file is licensed under
793ab4718SWade Farnsworth  * the terms of the GNU General Public License version 2. This program
893ab4718SWade Farnsworth  * is licensed "as is" without any warranty of any kind, whether express
993ab4718SWade Farnsworth  * or implied.
1093ab4718SWade Farnsworth  */
1193ab4718SWade Farnsworth 
1293ab4718SWade Farnsworth #include <linux/platform_device.h>
1393ab4718SWade Farnsworth #include <linux/err.h>
1493ab4718SWade Farnsworth #include <linux/init.h>
1593ab4718SWade Farnsworth #include <linux/mc146818rtc.h>
1693ab4718SWade Farnsworth 
1793ab4718SWade Farnsworth #include <asm/prom.h>
1893ab4718SWade Farnsworth 
1993ab4718SWade Farnsworth static int  __init add_rtc(void)
2093ab4718SWade Farnsworth {
2193ab4718SWade Farnsworth 	struct device_node *np;
2293ab4718SWade Farnsworth 	struct platform_device *pd;
23*ada3ea6fSKumar Gala 	struct resource res[2];
2493ab4718SWade Farnsworth 	int ret;
2593ab4718SWade Farnsworth 
26*ada3ea6fSKumar Gala 	memset(&res, 0, sizeof(res));
27*ada3ea6fSKumar Gala 
2893ab4718SWade Farnsworth 	np = of_find_compatible_node(NULL, NULL, "pnpPNP,b00");
2993ab4718SWade Farnsworth 	if (!np)
3093ab4718SWade Farnsworth 		return -ENODEV;
3193ab4718SWade Farnsworth 
32*ada3ea6fSKumar Gala 	ret = of_address_to_resource(np, 0, &res[0]);
3393ab4718SWade Farnsworth 	of_node_put(np);
3493ab4718SWade Farnsworth 	if (ret)
3593ab4718SWade Farnsworth 		return ret;
3693ab4718SWade Farnsworth 
3793ab4718SWade Farnsworth 	/*
3893ab4718SWade Farnsworth 	 * RTC_PORT(x) is hardcoded in asm/mc146818rtc.h.  Verify that the
3993ab4718SWade Farnsworth 	 * address provided by the device node matches.
4093ab4718SWade Farnsworth 	 */
41*ada3ea6fSKumar Gala 	if (res[0].start != RTC_PORT(0))
4293ab4718SWade Farnsworth 		return -EINVAL;
4393ab4718SWade Farnsworth 
44*ada3ea6fSKumar Gala 	/* Use a fixed interrupt value of 8 since on PPC if we are using this
45*ada3ea6fSKumar Gala 	 * its off an i8259 which we ensure has interrupt numbers 0..15. */
46*ada3ea6fSKumar Gala 	res[1].start = 8;
47*ada3ea6fSKumar Gala 	res[1].end = 8;
48*ada3ea6fSKumar Gala 	res[1].flags = IORESOURCE_IRQ;
49*ada3ea6fSKumar Gala 
5093ab4718SWade Farnsworth 	pd = platform_device_register_simple("rtc_cmos", -1,
51*ada3ea6fSKumar Gala 					     &res[0], 2);
52*ada3ea6fSKumar Gala 
5393ab4718SWade Farnsworth 	if (IS_ERR(pd))
5493ab4718SWade Farnsworth 		return PTR_ERR(pd);
5593ab4718SWade Farnsworth 
5693ab4718SWade Farnsworth 	return 0;
5793ab4718SWade Farnsworth }
5893ab4718SWade Farnsworth fs_initcall(add_rtc);
59