rtc_cmos_setup.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. int ret;
  22. memset(&res, 0, sizeof(res));
  23. np = of_find_compatible_node(NULL, NULL, "pnpPNP,b00");
  24. if (!np)
  25. return -ENODEV;
  26. ret = of_address_to_resource(np, 0, &res[0]);
  27. of_node_put(np);
  28. if (ret)
  29. return ret;
  30. /*
  31. * RTC_PORT(x) is hardcoded in asm/mc146818rtc.h. Verify that the
  32. * address provided by the device node matches.
  33. */
  34. if (res[0].start != RTC_PORT(0))
  35. return -EINVAL;
  36. /* Use a fixed interrupt value of 8 since on PPC if we are using this
  37. * its off an i8259 which we ensure has interrupt numbers 0..15. */
  38. res[1].start = 8;
  39. res[1].end = 8;
  40. res[1].flags = IORESOURCE_IRQ;
  41. pd = platform_device_register_simple("rtc_cmos", -1,
  42. &res[0], 2);
  43. if (IS_ERR(pd))
  44. return PTR_ERR(pd);
  45. return 0;
  46. }
  47. fs_initcall(add_rtc);