rtc-ep93xx.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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, "preload\t\t: %d\n", preload);
  55. seq_printf(seq, "delete\t\t: %d\n", delete);
  56. return 0;
  57. }
  58. static struct rtc_class_ops ep93xx_rtc_ops = {
  59. .read_time = ep93xx_rtc_read_time,
  60. .set_time = ep93xx_rtc_set_time,
  61. .set_mmss = ep93xx_rtc_set_mmss,
  62. .proc = ep93xx_rtc_proc,
  63. };
  64. static ssize_t ep93xx_sysfs_show_comp_preload(struct device *dev,
  65. struct device_attribute *attr, char *buf)
  66. {
  67. unsigned short preload;
  68. ep93xx_get_swcomp(dev, &preload, NULL);
  69. return sprintf(buf, "%d\n", preload);
  70. }
  71. static DEVICE_ATTR(comp_preload, S_IRUGO, ep93xx_sysfs_show_comp_preload, NULL);
  72. static ssize_t ep93xx_sysfs_show_comp_delete(struct device *dev,
  73. struct device_attribute *attr, char *buf)
  74. {
  75. unsigned short delete;
  76. ep93xx_get_swcomp(dev, NULL, &delete);
  77. return sprintf(buf, "%d\n", delete);
  78. }
  79. static DEVICE_ATTR(comp_delete, S_IRUGO, ep93xx_sysfs_show_comp_delete, NULL);
  80. static int __devinit ep93xx_rtc_probe(struct platform_device *dev)
  81. {
  82. struct rtc_device *rtc = rtc_device_register("ep93xx",
  83. &dev->dev, &ep93xx_rtc_ops, THIS_MODULE);
  84. if (IS_ERR(rtc)) {
  85. return PTR_ERR(rtc);
  86. }
  87. platform_set_drvdata(dev, rtc);
  88. device_create_file(&dev->dev, &dev_attr_comp_preload);
  89. device_create_file(&dev->dev, &dev_attr_comp_delete);
  90. return 0;
  91. }
  92. static int __devexit ep93xx_rtc_remove(struct platform_device *dev)
  93. {
  94. struct rtc_device *rtc = platform_get_drvdata(dev);
  95. if (rtc)
  96. rtc_device_unregister(rtc);
  97. platform_set_drvdata(dev, NULL);
  98. return 0;
  99. }
  100. static struct platform_driver ep93xx_rtc_platform_driver = {
  101. .driver = {
  102. .name = "ep93xx-rtc",
  103. .owner = THIS_MODULE,
  104. },
  105. .probe = ep93xx_rtc_probe,
  106. .remove = __devexit_p(ep93xx_rtc_remove),
  107. };
  108. static int __init ep93xx_rtc_init(void)
  109. {
  110. return platform_driver_register(&ep93xx_rtc_platform_driver);
  111. }
  112. static void __exit ep93xx_rtc_exit(void)
  113. {
  114. platform_driver_unregister(&ep93xx_rtc_platform_driver);
  115. }
  116. MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
  117. MODULE_DESCRIPTION("EP93XX RTC driver");
  118. MODULE_LICENSE("GPL");
  119. MODULE_VERSION(DRV_VERSION);
  120. module_init(ep93xx_rtc_init);
  121. module_exit(ep93xx_rtc_exit);