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> 157dfe293cSPaul Gortmaker #include <linux/module.h> 1693ab4718SWade Farnsworth #include <linux/mc146818rtc.h> 1793ab4718SWade Farnsworth 1893ab4718SWade Farnsworth #include <asm/prom.h> 1993ab4718SWade Farnsworth 2093ab4718SWade Farnsworth static int __init add_rtc(void) 2193ab4718SWade Farnsworth { 2293ab4718SWade Farnsworth struct device_node *np; 2393ab4718SWade Farnsworth struct platform_device *pd; 24ada3ea6fSKumar Gala struct resource res[2]; 25e517881eSAnton Vorontsov unsigned int num_res = 1; 2693ab4718SWade Farnsworth int ret; 2793ab4718SWade Farnsworth 28ada3ea6fSKumar Gala memset(&res, 0, sizeof(res)); 29ada3ea6fSKumar Gala 3093ab4718SWade Farnsworth np = of_find_compatible_node(NULL, NULL, "pnpPNP,b00"); 3193ab4718SWade Farnsworth if (!np) 3293ab4718SWade Farnsworth return -ENODEV; 3393ab4718SWade Farnsworth 34ada3ea6fSKumar Gala ret = of_address_to_resource(np, 0, &res[0]); 3593ab4718SWade Farnsworth of_node_put(np); 3693ab4718SWade Farnsworth if (ret) 3793ab4718SWade Farnsworth return ret; 3893ab4718SWade Farnsworth 3993ab4718SWade Farnsworth /* 4093ab4718SWade Farnsworth * RTC_PORT(x) is hardcoded in asm/mc146818rtc.h. Verify that the 4193ab4718SWade Farnsworth * address provided by the device node matches. 4293ab4718SWade Farnsworth */ 43ada3ea6fSKumar Gala if (res[0].start != RTC_PORT(0)) 4493ab4718SWade Farnsworth return -EINVAL; 4593ab4718SWade Farnsworth 46e517881eSAnton Vorontsov np = of_find_compatible_node(NULL, NULL, "chrp,iic"); 47e517881eSAnton Vorontsov if (!np) 48e517881eSAnton Vorontsov np = of_find_compatible_node(NULL, NULL, "pnpPNP,000"); 49e517881eSAnton Vorontsov if (np) { 50e517881eSAnton Vorontsov of_node_put(np); 51e517881eSAnton Vorontsov /* 52e517881eSAnton Vorontsov * Use a fixed interrupt value of 8 since on PPC if we are 53e517881eSAnton Vorontsov * using this its off an i8259 which we ensure has interrupt 54e517881eSAnton Vorontsov * numbers 0..15. 55e517881eSAnton Vorontsov */ 56ada3ea6fSKumar Gala res[1].start = 8; 57ada3ea6fSKumar Gala res[1].end = 8; 58ada3ea6fSKumar Gala res[1].flags = IORESOURCE_IRQ; 59e517881eSAnton Vorontsov num_res++; 60e517881eSAnton Vorontsov } 61ada3ea6fSKumar Gala 6293ab4718SWade Farnsworth pd = platform_device_register_simple("rtc_cmos", -1, 63e517881eSAnton Vorontsov &res[0], num_res); 64ada3ea6fSKumar Gala 65*8c6ffba0SRusty Russell return PTR_ERR_OR_ZERO(pd); 6693ab4718SWade Farnsworth } 6793ab4718SWade Farnsworth fs_initcall(add_rtc); 683fbe9d41SAdrian Bunk 693fbe9d41SAdrian Bunk MODULE_LICENSE("GPL"); 70