rtc_cmos_setup.c 1.6 KB

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