rtc-ep93xx.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * A driver for the RTC embedded in the Cirrus Logic EP93XX processors
  3. * Copyright (c) 2006 Tower Technologies
  4. *
  5. * Author: Alessandro Zummo <a.zummo@towertech.it>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/rtc.h>
  13. #include <linux/platform_device.h>
  14. #include <asm/hardware.h>
  15. #define EP93XX_RTC_REG(x) (EP93XX_RTC_BASE + (x))
  16. #define EP93XX_RTC_DATA EP93XX_RTC_REG(0x0000)
  17. #define EP93XX_RTC_LOAD EP93XX_RTC_REG(0x000C)
  18. #define EP93XX_RTC_SWCOMP EP93XX_RTC_REG(0x0108)
  19. #define DRV_VERSION "0.2"
  20. static int ep93xx_get_swcomp(struct device *dev, unsigned short *preload,
  21. unsigned short *delete)
  22. {
  23. unsigned short comp = __raw_readl(EP93XX_RTC_SWCOMP);
  24. if (preload)
  25. *preload = comp & 0xffff;
  26. if (delete)
  27. *delete = (comp >> 16) & 0x1f;
  28. return 0;
  29. }
  30. static int ep93xx_rtc_read_time(struct device *dev, struct rtc_time *tm)
  31. {
  32. unsigned long time = __raw_readl(EP93XX_RTC_DATA);
  33. rtc_time_to_tm(time, tm);
  34. return 0;
  35. }
  36. static int ep93xx_rtc_set_mmss(struct device *dev, unsigned long secs)
  37. {
  38. __raw_writel(secs + 1, EP93XX_RTC_LOAD);
  39. return 0;
  40. }
  41. static int ep93xx_rtc_set_time(struct device *dev, struct rtc_time *tm)
  42. {
  43. int err;
  44. unsigned long secs;
  45. err = rtc_tm_to_time(tm, &secs);
  46. if (err != 0)
  47. return err;
  48. return ep93xx_rtc_set_mmss(dev, secs);
  49. }
  50. static int ep93xx_rtc_proc(struct device *dev, struct seq_file *seq)
  51. {
  52. unsigned short preload, delete;
  53. ep93xx_get_swcomp(dev, &preload, &delete);
  54. seq_printf(seq, "24hr\t\t: yes\n");
  55. seq_printf(seq, "preload\t\t: %d\n", preload);
  56. seq_printf(seq, "delete\t\t: %d\n", delete);
  57. return 0;
  58. }
  59. static struct rtc_class_ops ep93xx_rtc_ops = {
  60. .read_time = ep93xx_rtc_read_time,
  61. .set_time = ep93xx_rtc_set_time,
  62. .set_mmss = ep93xx_rtc_set_mmss,
  63. .proc = ep93xx_rtc_proc,
  64. };
  65. static ssize_t ep93xx_sysfs_show_comp_preload(struct device *dev,
  66. struct device_attribute *attr, char *buf)
  67. {
  68. unsigned short preload;
  69. ep93xx_get_swcomp(dev, &preload, NULL);
  70. return sprintf(buf, "%d\n", preload);
  71. }
  72. static DEVICE_ATTR(comp_preload, S_IRUGO, ep93xx_sysfs_show_comp_preload, NULL);
  73. static ssize_t ep93xx_sysfs_show_comp_delete(struct device *dev,
  74. struct device_attribute *attr, char *buf)
  75. {
  76. unsigned short delete;
  77. ep93xx_get_swcomp(dev, NULL, &delete);
  78. return sprintf(buf, "%d\n", delete);
  79. }
  80. static DEVICE_ATTR(comp_delete, S_IRUGO, ep93xx_sysfs_show_comp_delete, NULL);
  81. static int __devinit ep93xx_rtc_probe(struct platform_device *dev)
  82. {
  83. struct rtc_device *rtc = rtc_device_register("ep93xx",
  84. &dev->dev, &ep93xx_rtc_ops, THIS_MODULE);
  85. if (IS_ERR(rtc)) {
  86. dev_err(&dev->dev, "unable to register\n");
  87. return PTR_ERR(rtc);
  88. }
  89. platform_set_drvdata(dev, rtc);
  90. device_create_file(&dev->dev, &dev_attr_comp_preload);
  91. device_create_file(&dev->dev, &dev_attr_comp_delete);
  92. return 0;
  93. }
  94. static int __devexit ep93xx_rtc_remove(struct platform_device *dev)
  95. {
  96. struct rtc_device *rtc = platform_get_drvdata(dev);
  97. if (rtc)
  98. rtc_device_unregister(rtc);
  99. platform_set_drvdata(dev, NULL);
  100. return 0;
  101. }
  102. static struct platform_driver ep93xx_rtc_platform_driver = {
  103. .driver = {
  104. .name = "ep93xx-rtc",
  105. .owner = THIS_MODULE,
  106. },
  107. .probe = ep93xx_rtc_probe,
  108. .remove = __devexit_p(ep93xx_rtc_remove),
  109. };
  110. static int __init ep93xx_rtc_init(void)
  111. {
  112. return platform_driver_register(&ep93xx_rtc_platform_driver);
  113. }
  114. static void __exit ep93xx_rtc_exit(void)
  115. {
  116. platform_driver_unregister(&ep93xx_rtc_platform_driver);
  117. }
  118. MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
  119. MODULE_DESCRIPTION("EP93XX RTC driver");
  120. MODULE_LICENSE("GPL");
  121. MODULE_VERSION(DRV_VERSION);
  122. module_init(ep93xx_rtc_init);
  123. module_exit(ep93xx_rtc_exit);