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; 23ada3ea6fSKumar Gala struct resource res[2]; 24*e517881eSAnton Vorontsov unsigned int num_res = 1; 2593ab4718SWade Farnsworth int ret; 2693ab4718SWade Farnsworth 27ada3ea6fSKumar Gala memset(&res, 0, sizeof(res)); 28ada3ea6fSKumar Gala 2993ab4718SWade Farnsworth np = of_find_compatible_node(NULL, NULL, "pnpPNP,b00"); 3093ab4718SWade Farnsworth if (!np) 3193ab4718SWade Farnsworth return -ENODEV; 3293ab4718SWade Farnsworth 33ada3ea6fSKumar Gala ret = of_address_to_resource(np, 0, &res[0]); 3493ab4718SWade Farnsworth of_node_put(np); 3593ab4718SWade Farnsworth if (ret) 3693ab4718SWade Farnsworth return ret; 3793ab4718SWade Farnsworth 3893ab4718SWade Farnsworth /* 3993ab4718SWade Farnsworth * RTC_PORT(x) is hardcoded in asm/mc146818rtc.h. Verify that the 4093ab4718SWade Farnsworth * address provided by the device node matches. 4193ab4718SWade Farnsworth */ 42ada3ea6fSKumar Gala if (res[0].start != RTC_PORT(0)) 4393ab4718SWade Farnsworth return -EINVAL; 4493ab4718SWade Farnsworth 45*e517881eSAnton Vorontsov np = of_find_compatible_node(NULL, NULL, "chrp,iic"); 46*e517881eSAnton Vorontsov if (!np) 47*e517881eSAnton Vorontsov np = of_find_compatible_node(NULL, NULL, "pnpPNP,000"); 48*e517881eSAnton Vorontsov if (np) { 49*e517881eSAnton Vorontsov of_node_put(np); 50*e517881eSAnton Vorontsov /* 51*e517881eSAnton Vorontsov * Use a fixed interrupt value of 8 since on PPC if we are 52*e517881eSAnton Vorontsov * using this its off an i8259 which we ensure has interrupt 53*e517881eSAnton Vorontsov * numbers 0..15. 54*e517881eSAnton Vorontsov */ 55ada3ea6fSKumar Gala res[1].start = 8; 56ada3ea6fSKumar Gala res[1].end = 8; 57ada3ea6fSKumar Gala res[1].flags = IORESOURCE_IRQ; 58*e517881eSAnton Vorontsov num_res++; 59*e517881eSAnton Vorontsov } 60ada3ea6fSKumar Gala 6193ab4718SWade Farnsworth pd = platform_device_register_simple("rtc_cmos", -1, 62*e517881eSAnton Vorontsov &res[0], num_res); 63ada3ea6fSKumar Gala 6493ab4718SWade Farnsworth if (IS_ERR(pd)) 6593ab4718SWade Farnsworth return PTR_ERR(pd); 6693ab4718SWade Farnsworth 6793ab4718SWade Farnsworth return 0; 6893ab4718SWade Farnsworth } 6993ab4718SWade Farnsworth fs_initcall(add_rtc); 703fbe9d41SAdrian Bunk 713fbe9d41SAdrian Bunk MODULE_LICENSE("GPL"); 72