rtc_cmos_setup.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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/module.h>
  15. #include <linux/mc146818rtc.h>
  16. #include <asm/prom.h>
  17. static int __init add_rtc(void)
  18. {
  19. struct device_node *np;
  20. struct platform_device *pd;
  21. struct resource res[2];
  22. unsigned int num_res = 1;
  23. int ret;
  24. memset(&res, 0, sizeof(res));
  25. np = of_find_compatible_node(NULL, NULL, "pnpPNP,b00");
  26. if (!np)
  27. return -ENODEV;
  28. ret = of_address_to_resource(np, 0, &res[0]);
  29. of_node_put(np);
  30. if (ret)
  31. return ret;
  32. /*
  33. * RTC_PORT(x) is hardcoded in asm/mc146818rtc.h. Verify that the
  34. * address provided by the device node matches.
  35. */
  36. if (res[0].start != RTC_PORT(0))
  37. return -EINVAL;
  38. np = of_find_compatible_node(NULL, NULL, "chrp,iic");
  39. if (!np)
  40. np = of_find_compatible_node(NULL, NULL, "pnpPNP,000");
  41. if (np) {
  42. of_node_put(np);
  43. /*
  44. * Use a fixed interrupt value of 8 since on PPC if we are
  45. * using this its off an i8259 which we ensure has interrupt
  46. * numbers 0..15.
  47. */
  48. res[1].start = 8;
  49. res[1].end = 8;
  50. res[1].flags = IORESOURCE_IRQ;
  51. num_res++;
  52. }
  53. pd = platform_device_register_simple("rtc_cmos", -1,
  54. &res[0], num_res);
  55. return PTR_ERR_OR_ZERO(pd);
  56. }
  57. fs_initcall(add_rtc);
  58. MODULE_LICENSE("GPL");