Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Setup code for PC-style Real-Time Clock.
0003  *
0004  * Author: Wade Farnsworth <wfarnsworth@mvista.com>
0005  *
0006  * 2007 (c) MontaVista Software, Inc. This file is licensed under
0007  * the terms of the GNU General Public License version 2. This program
0008  * is licensed "as is" without any warranty of any kind, whether express
0009  * or implied.
0010  */
0011 
0012 #include <linux/platform_device.h>
0013 #include <linux/err.h>
0014 #include <linux/init.h>
0015 #include <linux/module.h>
0016 #include <linux/mc146818rtc.h>
0017 #include <linux/of_address.h>
0018 
0019 
0020 static int  __init add_rtc(void)
0021 {
0022     struct device_node *np;
0023     struct platform_device *pd;
0024     struct resource res[2];
0025     unsigned int num_res = 1;
0026     int ret;
0027 
0028     memset(&res, 0, sizeof(res));
0029 
0030     np = of_find_compatible_node(NULL, NULL, "pnpPNP,b00");
0031     if (!np)
0032         return -ENODEV;
0033 
0034     ret = of_address_to_resource(np, 0, &res[0]);
0035     of_node_put(np);
0036     if (ret)
0037         return ret;
0038 
0039     /*
0040      * RTC_PORT(x) is hardcoded in asm/mc146818rtc.h.  Verify that the
0041      * address provided by the device node matches.
0042      */
0043     if (res[0].start != RTC_PORT(0))
0044         return -EINVAL;
0045 
0046     np = of_find_compatible_node(NULL, NULL, "chrp,iic");
0047     if (!np)
0048         np = of_find_compatible_node(NULL, NULL, "pnpPNP,000");
0049     if (np) {
0050         of_node_put(np);
0051         /*
0052          * Use a fixed interrupt value of 8 since on PPC if we are
0053          * using this its off an i8259 which we ensure has interrupt
0054          * numbers 0..15.
0055          */
0056         res[1].start = 8;
0057         res[1].end = 8;
0058         res[1].flags = IORESOURCE_IRQ;
0059         num_res++;
0060     }
0061 
0062     pd = platform_device_register_simple("rtc_cmos", -1,
0063                          &res[0], num_res);
0064 
0065     return PTR_ERR_OR_ZERO(pd);
0066 }
0067 fs_initcall(add_rtc);
0068 
0069 MODULE_LICENSE("GPL");