diff options
| -rw-r--r-- | arch/arm/mach-ep93xx/core.c | 15 | ||||
| -rw-r--r-- | arch/arm/mach-ep93xx/include/mach/ep93xx-regs.h | 1 | ||||
| -rw-r--r-- | drivers/rtc/rtc-ep93xx.c | 149 |
3 files changed, 125 insertions, 40 deletions
diff --git a/arch/arm/mach-ep93xx/core.c b/arch/arm/mach-ep93xx/core.c index ae24486f858a..c535e8805a3b 100644 --- a/arch/arm/mach-ep93xx/core.c +++ b/arch/arm/mach-ep93xx/core.c | |||
| @@ -450,10 +450,19 @@ static struct amba_device uart3_device = { | |||
| 450 | }; | 450 | }; |
| 451 | 451 | ||
| 452 | 452 | ||
| 453 | static struct resource ep93xx_rtc_resource[] = { | ||
| 454 | { | ||
| 455 | .start = EP93XX_RTC_PHYS_BASE, | ||
| 456 | .end = EP93XX_RTC_PHYS_BASE + 0x10c - 1, | ||
| 457 | .flags = IORESOURCE_MEM, | ||
| 458 | }, | ||
| 459 | }; | ||
| 460 | |||
| 453 | static struct platform_device ep93xx_rtc_device = { | 461 | static struct platform_device ep93xx_rtc_device = { |
| 454 | .name = "ep93xx-rtc", | 462 | .name = "ep93xx-rtc", |
| 455 | .id = -1, | 463 | .id = -1, |
| 456 | .num_resources = 0, | 464 | .num_resources = ARRAY_SIZE(ep93xx_rtc_resource), |
| 465 | .resource = ep93xx_rtc_resource, | ||
| 457 | }; | 466 | }; |
| 458 | 467 | ||
| 459 | 468 | ||
diff --git a/arch/arm/mach-ep93xx/include/mach/ep93xx-regs.h b/arch/arm/mach-ep93xx/include/mach/ep93xx-regs.h index f66be12b856e..78ac1bddc8bc 100644 --- a/arch/arm/mach-ep93xx/include/mach/ep93xx-regs.h +++ b/arch/arm/mach-ep93xx/include/mach/ep93xx-regs.h | |||
| @@ -147,6 +147,7 @@ | |||
| 147 | #define EP93XX_PWM_BASE (EP93XX_APB_VIRT_BASE + 0x00110000) | 147 | #define EP93XX_PWM_BASE (EP93XX_APB_VIRT_BASE + 0x00110000) |
| 148 | 148 | ||
| 149 | #define EP93XX_RTC_BASE (EP93XX_APB_VIRT_BASE + 0x00120000) | 149 | #define EP93XX_RTC_BASE (EP93XX_APB_VIRT_BASE + 0x00120000) |
| 150 | #define EP93XX_RTC_PHYS_BASE (EP93XX_APB_PHYS_BASE + 0x00120000) | ||
| 150 | 151 | ||
| 151 | #define EP93XX_SYSCON_BASE (EP93XX_APB_VIRT_BASE + 0x00130000) | 152 | #define EP93XX_SYSCON_BASE (EP93XX_APB_VIRT_BASE + 0x00130000) |
| 152 | #define EP93XX_SYSCON_REG(x) (EP93XX_SYSCON_BASE + (x)) | 153 | #define EP93XX_SYSCON_REG(x) (EP93XX_SYSCON_BASE + (x)) |
diff --git a/drivers/rtc/rtc-ep93xx.c b/drivers/rtc/rtc-ep93xx.c index f7a3283dd029..551332e4ed02 100644 --- a/drivers/rtc/rtc-ep93xx.c +++ b/drivers/rtc/rtc-ep93xx.c | |||
| @@ -12,32 +12,56 @@ | |||
| 12 | #include <linux/module.h> | 12 | #include <linux/module.h> |
| 13 | #include <linux/rtc.h> | 13 | #include <linux/rtc.h> |
| 14 | #include <linux/platform_device.h> | 14 | #include <linux/platform_device.h> |
| 15 | #include <mach/hardware.h> | 15 | #include <linux/io.h> |
| 16 | |||
| 17 | #define EP93XX_RTC_DATA 0x000 | ||
| 18 | #define EP93XX_RTC_MATCH 0x004 | ||
| 19 | #define EP93XX_RTC_STATUS 0x008 | ||
| 20 | #define EP93XX_RTC_STATUS_INTR (1<<0) | ||
| 21 | #define EP93XX_RTC_LOAD 0x00C | ||
| 22 | #define EP93XX_RTC_CONTROL 0x010 | ||
| 23 | #define EP93XX_RTC_CONTROL_MIE (1<<0) | ||
| 24 | #define EP93XX_RTC_SWCOMP 0x108 | ||
| 25 | #define EP93XX_RTC_SWCOMP_DEL_MASK 0x001f0000 | ||
| 26 | #define EP93XX_RTC_SWCOMP_DEL_SHIFT 16 | ||
| 27 | #define EP93XX_RTC_SWCOMP_INT_MASK 0x0000ffff | ||
| 28 | #define EP93XX_RTC_SWCOMP_INT_SHIFT 0 | ||
| 29 | |||
| 30 | #define DRV_VERSION "0.3" | ||
| 16 | 31 | ||
| 17 | #define EP93XX_RTC_REG(x) (EP93XX_RTC_BASE + (x)) | 32 | /* |
| 18 | #define EP93XX_RTC_DATA EP93XX_RTC_REG(0x0000) | 33 | * struct device dev.platform_data is used to store our private data |
| 19 | #define EP93XX_RTC_LOAD EP93XX_RTC_REG(0x000C) | 34 | * because struct rtc_device does not have a variable to hold it. |
| 20 | #define EP93XX_RTC_SWCOMP EP93XX_RTC_REG(0x0108) | 35 | */ |
| 21 | 36 | struct ep93xx_rtc { | |
| 22 | #define DRV_VERSION "0.2" | 37 | void __iomem *mmio_base; |
| 38 | }; | ||
| 23 | 39 | ||
| 24 | static int ep93xx_get_swcomp(struct device *dev, unsigned short *preload, | 40 | static int ep93xx_rtc_get_swcomp(struct device *dev, unsigned short *preload, |
| 25 | unsigned short *delete) | 41 | unsigned short *delete) |
| 26 | { | 42 | { |
| 27 | unsigned short comp = __raw_readl(EP93XX_RTC_SWCOMP); | 43 | struct ep93xx_rtc *ep93xx_rtc = dev->platform_data; |
| 44 | unsigned long comp; | ||
| 45 | |||
| 46 | comp = __raw_readl(ep93xx_rtc->mmio_base + EP93XX_RTC_SWCOMP); | ||
| 28 | 47 | ||
| 29 | if (preload) | 48 | if (preload) |
| 30 | *preload = comp & 0xffff; | 49 | *preload = (comp & EP93XX_RTC_SWCOMP_INT_MASK) |
| 50 | >> EP93XX_RTC_SWCOMP_INT_SHIFT; | ||
| 31 | 51 | ||
| 32 | if (delete) | 52 | if (delete) |
| 33 | *delete = (comp >> 16) & 0x1f; | 53 | *delete = (comp & EP93XX_RTC_SWCOMP_DEL_MASK) |
| 54 | >> EP93XX_RTC_SWCOMP_DEL_SHIFT; | ||
| 34 | 55 | ||
| 35 | return 0; | 56 | return 0; |
| 36 | } | 57 | } |
| 37 | 58 | ||
| 38 | static int ep93xx_rtc_read_time(struct device *dev, struct rtc_time *tm) | 59 | static int ep93xx_rtc_read_time(struct device *dev, struct rtc_time *tm) |
| 39 | { | 60 | { |
| 40 | unsigned long time = __raw_readl(EP93XX_RTC_DATA); | 61 | struct ep93xx_rtc *ep93xx_rtc = dev->platform_data; |
| 62 | unsigned long time; | ||
| 63 | |||
| 64 | time = __raw_readl(ep93xx_rtc->mmio_base + EP93XX_RTC_DATA); | ||
| 41 | 65 | ||
| 42 | rtc_time_to_tm(time, tm); | 66 | rtc_time_to_tm(time, tm); |
| 43 | return 0; | 67 | return 0; |
| @@ -45,7 +69,9 @@ static int ep93xx_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
| 45 | 69 | ||
| 46 | static int ep93xx_rtc_set_mmss(struct device *dev, unsigned long secs) | 70 | static int ep93xx_rtc_set_mmss(struct device *dev, unsigned long secs) |
| 47 | { | 71 | { |
| 48 | __raw_writel(secs + 1, EP93XX_RTC_LOAD); | 72 | struct ep93xx_rtc *ep93xx_rtc = dev->platform_data; |
| 73 | |||
| 74 | __raw_writel(secs + 1, ep93xx_rtc->mmio_base + EP93XX_RTC_LOAD); | ||
| 49 | return 0; | 75 | return 0; |
| 50 | } | 76 | } |
| 51 | 77 | ||
| @@ -53,7 +79,7 @@ static int ep93xx_rtc_proc(struct device *dev, struct seq_file *seq) | |||
| 53 | { | 79 | { |
| 54 | unsigned short preload, delete; | 80 | unsigned short preload, delete; |
| 55 | 81 | ||
| 56 | ep93xx_get_swcomp(dev, &preload, &delete); | 82 | ep93xx_rtc_get_swcomp(dev, &preload, &delete); |
| 57 | 83 | ||
| 58 | seq_printf(seq, "preload\t\t: %d\n", preload); | 84 | seq_printf(seq, "preload\t\t: %d\n", preload); |
| 59 | seq_printf(seq, "delete\t\t: %d\n", delete); | 85 | seq_printf(seq, "delete\t\t: %d\n", delete); |
| @@ -67,54 +93,104 @@ static const struct rtc_class_ops ep93xx_rtc_ops = { | |||
| 67 | .proc = ep93xx_rtc_proc, | 93 | .proc = ep93xx_rtc_proc, |
| 68 | }; | 94 | }; |
| 69 | 95 | ||
| 70 | static ssize_t ep93xx_sysfs_show_comp_preload(struct device *dev, | 96 | static ssize_t ep93xx_rtc_show_comp_preload(struct device *dev, |
| 71 | struct device_attribute *attr, char *buf) | 97 | struct device_attribute *attr, char *buf) |
| 72 | { | 98 | { |
| 73 | unsigned short preload; | 99 | unsigned short preload; |
| 74 | 100 | ||
| 75 | ep93xx_get_swcomp(dev, &preload, NULL); | 101 | ep93xx_rtc_get_swcomp(dev, &preload, NULL); |
| 76 | 102 | ||
| 77 | return sprintf(buf, "%d\n", preload); | 103 | return sprintf(buf, "%d\n", preload); |
| 78 | } | 104 | } |
| 79 | static DEVICE_ATTR(comp_preload, S_IRUGO, ep93xx_sysfs_show_comp_preload, NULL); | 105 | static DEVICE_ATTR(comp_preload, S_IRUGO, ep93xx_rtc_show_comp_preload, NULL); |
| 80 | 106 | ||
| 81 | static ssize_t ep93xx_sysfs_show_comp_delete(struct device *dev, | 107 | static ssize_t ep93xx_rtc_show_comp_delete(struct device *dev, |
| 82 | struct device_attribute *attr, char *buf) | 108 | struct device_attribute *attr, char *buf) |
| 83 | { | 109 | { |
| 84 | unsigned short delete; | 110 | unsigned short delete; |
| 85 | 111 | ||
| 86 | ep93xx_get_swcomp(dev, NULL, &delete); | 112 | ep93xx_rtc_get_swcomp(dev, NULL, &delete); |
| 87 | 113 | ||
| 88 | return sprintf(buf, "%d\n", delete); | 114 | return sprintf(buf, "%d\n", delete); |
| 89 | } | 115 | } |
| 90 | static DEVICE_ATTR(comp_delete, S_IRUGO, ep93xx_sysfs_show_comp_delete, NULL); | 116 | static DEVICE_ATTR(comp_delete, S_IRUGO, ep93xx_rtc_show_comp_delete, NULL); |
| 91 | 117 | ||
| 92 | 118 | ||
| 93 | static int __devinit ep93xx_rtc_probe(struct platform_device *dev) | 119 | static int __init ep93xx_rtc_probe(struct platform_device *pdev) |
| 94 | { | 120 | { |
| 95 | struct rtc_device *rtc = rtc_device_register("ep93xx", | 121 | struct ep93xx_rtc *ep93xx_rtc; |
| 96 | &dev->dev, &ep93xx_rtc_ops, THIS_MODULE); | 122 | struct resource *res; |
| 123 | struct rtc_device *rtc; | ||
| 124 | int err; | ||
| 125 | |||
| 126 | ep93xx_rtc = kzalloc(sizeof(struct ep93xx_rtc), GFP_KERNEL); | ||
| 127 | if (ep93xx_rtc == NULL) | ||
| 128 | return -ENOMEM; | ||
| 129 | |||
| 130 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
| 131 | if (res == NULL) | ||
| 132 | return -ENXIO; | ||
| 133 | |||
| 134 | res = request_mem_region(res->start, resource_size(res), pdev->name); | ||
| 135 | if (res == NULL) | ||
| 136 | return -EBUSY; | ||
| 137 | |||
| 138 | ep93xx_rtc->mmio_base = ioremap(res->start, resource_size(res)); | ||
| 139 | if (ep93xx_rtc->mmio_base == NULL) { | ||
| 140 | err = -ENXIO; | ||
| 141 | goto fail; | ||
| 142 | } | ||
| 97 | 143 | ||
| 144 | pdev->dev.platform_data = ep93xx_rtc; | ||
| 145 | |||
| 146 | rtc = rtc_device_register(pdev->name, | ||
| 147 | &pdev->dev, &ep93xx_rtc_ops, THIS_MODULE); | ||
| 98 | if (IS_ERR(rtc)) { | 148 | if (IS_ERR(rtc)) { |
| 99 | return PTR_ERR(rtc); | 149 | err = PTR_ERR(rtc); |
| 150 | goto fail; | ||
| 100 | } | 151 | } |
| 101 | 152 | ||
| 102 | platform_set_drvdata(dev, rtc); | 153 | platform_set_drvdata(pdev, rtc); |
| 103 | 154 | ||
| 104 | device_create_file(&dev->dev, &dev_attr_comp_preload); | 155 | err = device_create_file(&pdev->dev, &dev_attr_comp_preload); |
| 105 | device_create_file(&dev->dev, &dev_attr_comp_delete); | 156 | if (err) |
| 157 | goto fail; | ||
| 158 | err = device_create_file(&pdev->dev, &dev_attr_comp_delete); | ||
| 159 | if (err) { | ||
| 160 | device_remove_file(&pdev->dev, &dev_attr_comp_preload); | ||
| 161 | goto fail; | ||
| 162 | } | ||
| 106 | 163 | ||
| 107 | return 0; | 164 | return 0; |
| 165 | |||
| 166 | fail: | ||
| 167 | if (ep93xx_rtc->mmio_base) { | ||
| 168 | iounmap(ep93xx_rtc->mmio_base); | ||
| 169 | pdev->dev.platform_data = NULL; | ||
| 170 | } | ||
| 171 | release_mem_region(res->start, resource_size(res)); | ||
| 172 | return err; | ||
| 108 | } | 173 | } |
| 109 | 174 | ||
| 110 | static int __devexit ep93xx_rtc_remove(struct platform_device *dev) | 175 | static int __exit ep93xx_rtc_remove(struct platform_device *pdev) |
| 111 | { | 176 | { |
| 112 | struct rtc_device *rtc = platform_get_drvdata(dev); | 177 | struct rtc_device *rtc = platform_get_drvdata(pdev); |
| 178 | struct ep93xx_rtc *ep93xx_rtc = pdev->dev.platform_data; | ||
| 179 | struct resource *res; | ||
| 180 | |||
| 181 | /* cleanup sysfs */ | ||
| 182 | device_remove_file(&pdev->dev, &dev_attr_comp_delete); | ||
| 183 | device_remove_file(&pdev->dev, &dev_attr_comp_preload); | ||
| 184 | |||
| 185 | rtc_device_unregister(rtc); | ||
| 186 | |||
| 187 | iounmap(ep93xx_rtc->mmio_base); | ||
| 188 | pdev->dev.platform_data = NULL; | ||
| 113 | 189 | ||
| 114 | if (rtc) | 190 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 115 | rtc_device_unregister(rtc); | 191 | release_mem_region(res->start, resource_size(res)); |
| 116 | 192 | ||
| 117 | platform_set_drvdata(dev, NULL); | 193 | platform_set_drvdata(pdev, NULL); |
| 118 | 194 | ||
| 119 | return 0; | 195 | return 0; |
| 120 | } | 196 | } |
| @@ -122,23 +198,22 @@ static int __devexit ep93xx_rtc_remove(struct platform_device *dev) | |||
| 122 | /* work with hotplug and coldplug */ | 198 | /* work with hotplug and coldplug */ |
| 123 | MODULE_ALIAS("platform:ep93xx-rtc"); | 199 | MODULE_ALIAS("platform:ep93xx-rtc"); |
| 124 | 200 | ||
| 125 | static struct platform_driver ep93xx_rtc_platform_driver = { | 201 | static struct platform_driver ep93xx_rtc_driver = { |
| 126 | .driver = { | 202 | .driver = { |
| 127 | .name = "ep93xx-rtc", | 203 | .name = "ep93xx-rtc", |
| 128 | .owner = THIS_MODULE, | 204 | .owner = THIS_MODULE, |
| 129 | }, | 205 | }, |
| 130 | .probe = ep93xx_rtc_probe, | 206 | .remove = __exit_p(ep93xx_rtc_remove), |
| 131 | .remove = __devexit_p(ep93xx_rtc_remove), | ||
| 132 | }; | 207 | }; |
| 133 | 208 | ||
| 134 | static int __init ep93xx_rtc_init(void) | 209 | static int __init ep93xx_rtc_init(void) |
| 135 | { | 210 | { |
| 136 | return platform_driver_register(&ep93xx_rtc_platform_driver); | 211 | return platform_driver_probe(&ep93xx_rtc_driver, ep93xx_rtc_probe); |
| 137 | } | 212 | } |
| 138 | 213 | ||
| 139 | static void __exit ep93xx_rtc_exit(void) | 214 | static void __exit ep93xx_rtc_exit(void) |
| 140 | { | 215 | { |
| 141 | platform_driver_unregister(&ep93xx_rtc_platform_driver); | 216 | platform_driver_unregister(&ep93xx_rtc_driver); |
| 142 | } | 217 | } |
| 143 | 218 | ||
| 144 | MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>"); | 219 | MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>"); |
