Thomas Hommel | 0296411 | 2007-07-21 04:37:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * A RTC driver for the Simtek STK17TA8 |
| 3 | * |
| 4 | * By Thomas Hommel <thomas.hommel@gefanuc.com> |
| 5 | * |
| 6 | * Based on the DS1553 driver from |
| 7 | * Atsushi Nemoto <anemo@mba.ocn.ne.jp> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 as |
| 11 | * published by the Free Software Foundation. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/bcd.h> |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/kernel.h> |
| 17 | #include <linux/delay.h> |
| 18 | #include <linux/jiffies.h> |
| 19 | #include <linux/interrupt.h> |
| 20 | #include <linux/rtc.h> |
| 21 | #include <linux/platform_device.h> |
| 22 | #include <linux/io.h> |
| 23 | |
| 24 | #define DRV_VERSION "0.1" |
| 25 | |
| 26 | #define RTC_REG_SIZE 0x20000 |
| 27 | #define RTC_OFFSET 0x1fff0 |
| 28 | |
| 29 | #define RTC_FLAGS (RTC_OFFSET + 0) |
| 30 | #define RTC_CENTURY (RTC_OFFSET + 1) |
| 31 | #define RTC_SECONDS_ALARM (RTC_OFFSET + 2) |
| 32 | #define RTC_MINUTES_ALARM (RTC_OFFSET + 3) |
| 33 | #define RTC_HOURS_ALARM (RTC_OFFSET + 4) |
| 34 | #define RTC_DATE_ALARM (RTC_OFFSET + 5) |
| 35 | #define RTC_INTERRUPTS (RTC_OFFSET + 6) |
| 36 | #define RTC_WATCHDOG (RTC_OFFSET + 7) |
| 37 | #define RTC_CALIBRATION (RTC_OFFSET + 8) |
| 38 | #define RTC_SECONDS (RTC_OFFSET + 9) |
| 39 | #define RTC_MINUTES (RTC_OFFSET + 10) |
| 40 | #define RTC_HOURS (RTC_OFFSET + 11) |
| 41 | #define RTC_DAY (RTC_OFFSET + 12) |
| 42 | #define RTC_DATE (RTC_OFFSET + 13) |
| 43 | #define RTC_MONTH (RTC_OFFSET + 14) |
| 44 | #define RTC_YEAR (RTC_OFFSET + 15) |
| 45 | |
| 46 | #define RTC_SECONDS_MASK 0x7f |
| 47 | #define RTC_DAY_MASK 0x07 |
| 48 | #define RTC_CAL_MASK 0x3f |
| 49 | |
| 50 | /* Bits in the Calibration register */ |
| 51 | #define RTC_STOP 0x80 |
| 52 | |
| 53 | /* Bits in the Flags register */ |
| 54 | #define RTC_FLAGS_AF 0x40 |
| 55 | #define RTC_FLAGS_PF 0x20 |
| 56 | #define RTC_WRITE 0x02 |
| 57 | #define RTC_READ 0x01 |
| 58 | |
| 59 | /* Bits in the Interrupts register */ |
| 60 | #define RTC_INTS_AIE 0x40 |
| 61 | |
| 62 | struct rtc_plat_data { |
| 63 | struct rtc_device *rtc; |
| 64 | void __iomem *ioaddr; |
Thomas Hommel | 0296411 | 2007-07-21 04:37:58 -0700 | [diff] [blame] | 65 | unsigned long last_jiffies; |
| 66 | int irq; |
| 67 | unsigned int irqen; |
| 68 | int alrm_sec; |
| 69 | int alrm_min; |
| 70 | int alrm_hour; |
| 71 | int alrm_mday; |
Atsushi Nemoto | 3151520 | 2009-12-15 16:46:04 -0800 | [diff] [blame] | 72 | spinlock_t lock; |
Thomas Hommel | 0296411 | 2007-07-21 04:37:58 -0700 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | static int stk17ta8_rtc_set_time(struct device *dev, struct rtc_time *tm) |
| 76 | { |
| 77 | struct platform_device *pdev = to_platform_device(dev); |
| 78 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); |
| 79 | void __iomem *ioaddr = pdata->ioaddr; |
| 80 | u8 flags; |
| 81 | |
| 82 | flags = readb(pdata->ioaddr + RTC_FLAGS); |
| 83 | writeb(flags | RTC_WRITE, pdata->ioaddr + RTC_FLAGS); |
| 84 | |
Adrian Bunk | fe20ba7 | 2008-10-18 20:28:41 -0700 | [diff] [blame] | 85 | writeb(bin2bcd(tm->tm_year % 100), ioaddr + RTC_YEAR); |
| 86 | writeb(bin2bcd(tm->tm_mon + 1), ioaddr + RTC_MONTH); |
| 87 | writeb(bin2bcd(tm->tm_wday) & RTC_DAY_MASK, ioaddr + RTC_DAY); |
| 88 | writeb(bin2bcd(tm->tm_mday), ioaddr + RTC_DATE); |
| 89 | writeb(bin2bcd(tm->tm_hour), ioaddr + RTC_HOURS); |
| 90 | writeb(bin2bcd(tm->tm_min), ioaddr + RTC_MINUTES); |
| 91 | writeb(bin2bcd(tm->tm_sec) & RTC_SECONDS_MASK, ioaddr + RTC_SECONDS); |
| 92 | writeb(bin2bcd((tm->tm_year + 1900) / 100), ioaddr + RTC_CENTURY); |
Thomas Hommel | 0296411 | 2007-07-21 04:37:58 -0700 | [diff] [blame] | 93 | |
| 94 | writeb(flags & ~RTC_WRITE, pdata->ioaddr + RTC_FLAGS); |
| 95 | return 0; |
| 96 | } |
| 97 | |
| 98 | static int stk17ta8_rtc_read_time(struct device *dev, struct rtc_time *tm) |
| 99 | { |
| 100 | struct platform_device *pdev = to_platform_device(dev); |
| 101 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); |
| 102 | void __iomem *ioaddr = pdata->ioaddr; |
| 103 | unsigned int year, month, day, hour, minute, second, week; |
| 104 | unsigned int century; |
| 105 | u8 flags; |
| 106 | |
| 107 | /* give enough time to update RTC in case of continuous read */ |
| 108 | if (pdata->last_jiffies == jiffies) |
| 109 | msleep(1); |
| 110 | pdata->last_jiffies = jiffies; |
| 111 | |
| 112 | flags = readb(pdata->ioaddr + RTC_FLAGS); |
| 113 | writeb(flags | RTC_READ, ioaddr + RTC_FLAGS); |
| 114 | second = readb(ioaddr + RTC_SECONDS) & RTC_SECONDS_MASK; |
| 115 | minute = readb(ioaddr + RTC_MINUTES); |
| 116 | hour = readb(ioaddr + RTC_HOURS); |
| 117 | day = readb(ioaddr + RTC_DATE); |
| 118 | week = readb(ioaddr + RTC_DAY) & RTC_DAY_MASK; |
| 119 | month = readb(ioaddr + RTC_MONTH); |
| 120 | year = readb(ioaddr + RTC_YEAR); |
| 121 | century = readb(ioaddr + RTC_CENTURY); |
| 122 | writeb(flags & ~RTC_READ, ioaddr + RTC_FLAGS); |
Adrian Bunk | fe20ba7 | 2008-10-18 20:28:41 -0700 | [diff] [blame] | 123 | tm->tm_sec = bcd2bin(second); |
| 124 | tm->tm_min = bcd2bin(minute); |
| 125 | tm->tm_hour = bcd2bin(hour); |
| 126 | tm->tm_mday = bcd2bin(day); |
| 127 | tm->tm_wday = bcd2bin(week); |
| 128 | tm->tm_mon = bcd2bin(month) - 1; |
Thomas Hommel | 0296411 | 2007-07-21 04:37:58 -0700 | [diff] [blame] | 129 | /* year is 1900 + tm->tm_year */ |
Adrian Bunk | fe20ba7 | 2008-10-18 20:28:41 -0700 | [diff] [blame] | 130 | tm->tm_year = bcd2bin(year) + bcd2bin(century) * 100 - 1900; |
Thomas Hommel | 0296411 | 2007-07-21 04:37:58 -0700 | [diff] [blame] | 131 | |
| 132 | if (rtc_valid_tm(tm) < 0) { |
| 133 | dev_err(dev, "retrieved date/time is not valid.\n"); |
| 134 | rtc_time_to_tm(0, tm); |
| 135 | } |
| 136 | return 0; |
| 137 | } |
| 138 | |
| 139 | static void stk17ta8_rtc_update_alarm(struct rtc_plat_data *pdata) |
| 140 | { |
| 141 | void __iomem *ioaddr = pdata->ioaddr; |
| 142 | unsigned long irqflags; |
| 143 | u8 flags; |
| 144 | |
Atsushi Nemoto | 3151520 | 2009-12-15 16:46:04 -0800 | [diff] [blame] | 145 | spin_lock_irqsave(&pdata->lock, irqflags); |
Thomas Hommel | 0296411 | 2007-07-21 04:37:58 -0700 | [diff] [blame] | 146 | |
| 147 | flags = readb(ioaddr + RTC_FLAGS); |
| 148 | writeb(flags | RTC_WRITE, ioaddr + RTC_FLAGS); |
| 149 | |
| 150 | writeb(pdata->alrm_mday < 0 || (pdata->irqen & RTC_UF) ? |
Adrian Bunk | fe20ba7 | 2008-10-18 20:28:41 -0700 | [diff] [blame] | 151 | 0x80 : bin2bcd(pdata->alrm_mday), |
Thomas Hommel | 0296411 | 2007-07-21 04:37:58 -0700 | [diff] [blame] | 152 | ioaddr + RTC_DATE_ALARM); |
| 153 | writeb(pdata->alrm_hour < 0 || (pdata->irqen & RTC_UF) ? |
Adrian Bunk | fe20ba7 | 2008-10-18 20:28:41 -0700 | [diff] [blame] | 154 | 0x80 : bin2bcd(pdata->alrm_hour), |
Thomas Hommel | 0296411 | 2007-07-21 04:37:58 -0700 | [diff] [blame] | 155 | ioaddr + RTC_HOURS_ALARM); |
| 156 | writeb(pdata->alrm_min < 0 || (pdata->irqen & RTC_UF) ? |
Adrian Bunk | fe20ba7 | 2008-10-18 20:28:41 -0700 | [diff] [blame] | 157 | 0x80 : bin2bcd(pdata->alrm_min), |
Thomas Hommel | 0296411 | 2007-07-21 04:37:58 -0700 | [diff] [blame] | 158 | ioaddr + RTC_MINUTES_ALARM); |
| 159 | writeb(pdata->alrm_sec < 0 || (pdata->irqen & RTC_UF) ? |
Adrian Bunk | fe20ba7 | 2008-10-18 20:28:41 -0700 | [diff] [blame] | 160 | 0x80 : bin2bcd(pdata->alrm_sec), |
Thomas Hommel | 0296411 | 2007-07-21 04:37:58 -0700 | [diff] [blame] | 161 | ioaddr + RTC_SECONDS_ALARM); |
| 162 | writeb(pdata->irqen ? RTC_INTS_AIE : 0, ioaddr + RTC_INTERRUPTS); |
| 163 | readb(ioaddr + RTC_FLAGS); /* clear interrupts */ |
| 164 | writeb(flags & ~RTC_WRITE, ioaddr + RTC_FLAGS); |
Atsushi Nemoto | 3151520 | 2009-12-15 16:46:04 -0800 | [diff] [blame] | 165 | spin_unlock_irqrestore(&pdata->lock, irqflags); |
Thomas Hommel | 0296411 | 2007-07-21 04:37:58 -0700 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | static int stk17ta8_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) |
| 169 | { |
| 170 | struct platform_device *pdev = to_platform_device(dev); |
| 171 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); |
| 172 | |
Anton Vorontsov | 2fac667 | 2009-01-06 14:42:11 -0800 | [diff] [blame] | 173 | if (pdata->irq <= 0) |
Thomas Hommel | 0296411 | 2007-07-21 04:37:58 -0700 | [diff] [blame] | 174 | return -EINVAL; |
| 175 | pdata->alrm_mday = alrm->time.tm_mday; |
| 176 | pdata->alrm_hour = alrm->time.tm_hour; |
| 177 | pdata->alrm_min = alrm->time.tm_min; |
| 178 | pdata->alrm_sec = alrm->time.tm_sec; |
| 179 | if (alrm->enabled) |
| 180 | pdata->irqen |= RTC_AF; |
| 181 | stk17ta8_rtc_update_alarm(pdata); |
| 182 | return 0; |
| 183 | } |
| 184 | |
| 185 | static int stk17ta8_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) |
| 186 | { |
| 187 | struct platform_device *pdev = to_platform_device(dev); |
| 188 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); |
| 189 | |
Anton Vorontsov | 2fac667 | 2009-01-06 14:42:11 -0800 | [diff] [blame] | 190 | if (pdata->irq <= 0) |
Thomas Hommel | 0296411 | 2007-07-21 04:37:58 -0700 | [diff] [blame] | 191 | return -EINVAL; |
| 192 | alrm->time.tm_mday = pdata->alrm_mday < 0 ? 0 : pdata->alrm_mday; |
| 193 | alrm->time.tm_hour = pdata->alrm_hour < 0 ? 0 : pdata->alrm_hour; |
| 194 | alrm->time.tm_min = pdata->alrm_min < 0 ? 0 : pdata->alrm_min; |
| 195 | alrm->time.tm_sec = pdata->alrm_sec < 0 ? 0 : pdata->alrm_sec; |
| 196 | alrm->enabled = (pdata->irqen & RTC_AF) ? 1 : 0; |
| 197 | return 0; |
| 198 | } |
| 199 | |
| 200 | static irqreturn_t stk17ta8_rtc_interrupt(int irq, void *dev_id) |
| 201 | { |
| 202 | struct platform_device *pdev = dev_id; |
| 203 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); |
| 204 | void __iomem *ioaddr = pdata->ioaddr; |
Atsushi Nemoto | 3151520 | 2009-12-15 16:46:04 -0800 | [diff] [blame] | 205 | unsigned long events = 0; |
Thomas Hommel | 0296411 | 2007-07-21 04:37:58 -0700 | [diff] [blame] | 206 | |
Atsushi Nemoto | 3151520 | 2009-12-15 16:46:04 -0800 | [diff] [blame] | 207 | spin_lock(&pdata->lock); |
Thomas Hommel | 0296411 | 2007-07-21 04:37:58 -0700 | [diff] [blame] | 208 | /* read and clear interrupt */ |
Atsushi Nemoto | 3151520 | 2009-12-15 16:46:04 -0800 | [diff] [blame] | 209 | if (readb(ioaddr + RTC_FLAGS) & RTC_FLAGS_AF) { |
| 210 | events = RTC_IRQF; |
| 211 | if (readb(ioaddr + RTC_SECONDS_ALARM) & 0x80) |
| 212 | events |= RTC_UF; |
| 213 | else |
| 214 | events |= RTC_AF; |
| 215 | if (likely(pdata->rtc)) |
| 216 | rtc_update_irq(pdata->rtc, 1, events); |
| 217 | } |
| 218 | spin_unlock(&pdata->lock); |
| 219 | return events ? IRQ_HANDLED : IRQ_NONE; |
Thomas Hommel | 0296411 | 2007-07-21 04:37:58 -0700 | [diff] [blame] | 220 | } |
| 221 | |
Atsushi Nemoto | 3151520 | 2009-12-15 16:46:04 -0800 | [diff] [blame] | 222 | static int stk17ta8_rtc_alarm_irq_enable(struct device *dev, |
| 223 | unsigned int enabled) |
Thomas Hommel | 0296411 | 2007-07-21 04:37:58 -0700 | [diff] [blame] | 224 | { |
| 225 | struct platform_device *pdev = to_platform_device(dev); |
| 226 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); |
| 227 | |
Anton Vorontsov | 2fac667 | 2009-01-06 14:42:11 -0800 | [diff] [blame] | 228 | if (pdata->irq <= 0) |
Atsushi Nemoto | 3151520 | 2009-12-15 16:46:04 -0800 | [diff] [blame] | 229 | return -EINVAL; |
| 230 | if (enabled) |
Thomas Hommel | 0296411 | 2007-07-21 04:37:58 -0700 | [diff] [blame] | 231 | pdata->irqen |= RTC_AF; |
Atsushi Nemoto | 3151520 | 2009-12-15 16:46:04 -0800 | [diff] [blame] | 232 | else |
| 233 | pdata->irqen &= ~RTC_AF; |
| 234 | stk17ta8_rtc_update_alarm(pdata); |
Thomas Hommel | 0296411 | 2007-07-21 04:37:58 -0700 | [diff] [blame] | 235 | return 0; |
| 236 | } |
| 237 | |
| 238 | static const struct rtc_class_ops stk17ta8_rtc_ops = { |
Atsushi Nemoto | 3151520 | 2009-12-15 16:46:04 -0800 | [diff] [blame] | 239 | .read_time = stk17ta8_rtc_read_time, |
| 240 | .set_time = stk17ta8_rtc_set_time, |
| 241 | .read_alarm = stk17ta8_rtc_read_alarm, |
| 242 | .set_alarm = stk17ta8_rtc_set_alarm, |
| 243 | .alarm_irq_enable = stk17ta8_rtc_alarm_irq_enable, |
Thomas Hommel | 0296411 | 2007-07-21 04:37:58 -0700 | [diff] [blame] | 244 | }; |
| 245 | |
Al Viro | c98dbe5 | 2007-07-26 17:32:49 +0100 | [diff] [blame] | 246 | static ssize_t stk17ta8_nvram_read(struct kobject *kobj, |
| 247 | struct bin_attribute *attr, char *buf, |
Thomas Hommel | 0296411 | 2007-07-21 04:37:58 -0700 | [diff] [blame] | 248 | loff_t pos, size_t size) |
| 249 | { |
Atsushi Nemoto | 50e49be | 2009-12-15 16:46:04 -0800 | [diff] [blame] | 250 | struct device *dev = container_of(kobj, struct device, kobj); |
| 251 | struct platform_device *pdev = to_platform_device(dev); |
Thomas Hommel | 0296411 | 2007-07-21 04:37:58 -0700 | [diff] [blame] | 252 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); |
| 253 | void __iomem *ioaddr = pdata->ioaddr; |
| 254 | ssize_t count; |
| 255 | |
| 256 | for (count = 0; size > 0 && pos < RTC_OFFSET; count++, size--) |
| 257 | *buf++ = readb(ioaddr + pos++); |
| 258 | return count; |
| 259 | } |
| 260 | |
Al Viro | c98dbe5 | 2007-07-26 17:32:49 +0100 | [diff] [blame] | 261 | static ssize_t stk17ta8_nvram_write(struct kobject *kobj, |
| 262 | struct bin_attribute *attr, char *buf, |
Thomas Hommel | 0296411 | 2007-07-21 04:37:58 -0700 | [diff] [blame] | 263 | loff_t pos, size_t size) |
| 264 | { |
Atsushi Nemoto | 50e49be | 2009-12-15 16:46:04 -0800 | [diff] [blame] | 265 | struct device *dev = container_of(kobj, struct device, kobj); |
| 266 | struct platform_device *pdev = to_platform_device(dev); |
Thomas Hommel | 0296411 | 2007-07-21 04:37:58 -0700 | [diff] [blame] | 267 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); |
| 268 | void __iomem *ioaddr = pdata->ioaddr; |
| 269 | ssize_t count; |
| 270 | |
| 271 | for (count = 0; size > 0 && pos < RTC_OFFSET; count++, size--) |
| 272 | writeb(*buf++, ioaddr + pos++); |
| 273 | return count; |
| 274 | } |
| 275 | |
| 276 | static struct bin_attribute stk17ta8_nvram_attr = { |
| 277 | .attr = { |
| 278 | .name = "nvram", |
David Brownell | a4b1d50 | 2007-11-14 16:58:30 -0800 | [diff] [blame] | 279 | .mode = S_IRUGO | S_IWUSR, |
Thomas Hommel | 0296411 | 2007-07-21 04:37:58 -0700 | [diff] [blame] | 280 | }, |
| 281 | .size = RTC_OFFSET, |
| 282 | .read = stk17ta8_nvram_read, |
| 283 | .write = stk17ta8_nvram_write, |
| 284 | }; |
| 285 | |
Uwe Kleine-König | 81e627e | 2009-07-11 22:53:05 +0200 | [diff] [blame] | 286 | static int __devinit stk17ta8_rtc_probe(struct platform_device *pdev) |
Thomas Hommel | 0296411 | 2007-07-21 04:37:58 -0700 | [diff] [blame] | 287 | { |
Thomas Hommel | 0296411 | 2007-07-21 04:37:58 -0700 | [diff] [blame] | 288 | struct resource *res; |
| 289 | unsigned int cal; |
| 290 | unsigned int flags; |
| 291 | struct rtc_plat_data *pdata; |
Atsushi Nemoto | 3151520 | 2009-12-15 16:46:04 -0800 | [diff] [blame] | 292 | void __iomem *ioaddr; |
Thomas Hommel | 0296411 | 2007-07-21 04:37:58 -0700 | [diff] [blame] | 293 | int ret = 0; |
| 294 | |
| 295 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 296 | if (!res) |
| 297 | return -ENODEV; |
| 298 | |
Atsushi Nemoto | 3151520 | 2009-12-15 16:46:04 -0800 | [diff] [blame] | 299 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); |
Thomas Hommel | 0296411 | 2007-07-21 04:37:58 -0700 | [diff] [blame] | 300 | if (!pdata) |
| 301 | return -ENOMEM; |
Atsushi Nemoto | 3151520 | 2009-12-15 16:46:04 -0800 | [diff] [blame] | 302 | if (!devm_request_mem_region(&pdev->dev, res->start, RTC_REG_SIZE, |
| 303 | pdev->name)) |
| 304 | return -EBUSY; |
| 305 | ioaddr = devm_ioremap(&pdev->dev, res->start, RTC_REG_SIZE); |
| 306 | if (!ioaddr) |
| 307 | return -ENOMEM; |
Thomas Hommel | 0296411 | 2007-07-21 04:37:58 -0700 | [diff] [blame] | 308 | pdata->ioaddr = ioaddr; |
| 309 | pdata->irq = platform_get_irq(pdev, 0); |
| 310 | |
| 311 | /* turn RTC on if it was not on */ |
| 312 | cal = readb(ioaddr + RTC_CALIBRATION); |
| 313 | if (cal & RTC_STOP) { |
| 314 | cal &= RTC_CAL_MASK; |
| 315 | flags = readb(ioaddr + RTC_FLAGS); |
| 316 | writeb(flags | RTC_WRITE, ioaddr + RTC_FLAGS); |
| 317 | writeb(cal, ioaddr + RTC_CALIBRATION); |
| 318 | writeb(flags & ~RTC_WRITE, ioaddr + RTC_FLAGS); |
| 319 | } |
| 320 | if (readb(ioaddr + RTC_FLAGS) & RTC_FLAGS_PF) |
| 321 | dev_warn(&pdev->dev, "voltage-low detected.\n"); |
| 322 | |
Atsushi Nemoto | 3151520 | 2009-12-15 16:46:04 -0800 | [diff] [blame] | 323 | spin_lock_init(&pdata->lock); |
| 324 | pdata->last_jiffies = jiffies; |
| 325 | platform_set_drvdata(pdev, pdata); |
Anton Vorontsov | 2fac667 | 2009-01-06 14:42:11 -0800 | [diff] [blame] | 326 | if (pdata->irq > 0) { |
Thomas Hommel | 0296411 | 2007-07-21 04:37:58 -0700 | [diff] [blame] | 327 | writeb(0, ioaddr + RTC_INTERRUPTS); |
Atsushi Nemoto | 3151520 | 2009-12-15 16:46:04 -0800 | [diff] [blame] | 328 | if (devm_request_irq(&pdev->dev, pdata->irq, |
| 329 | stk17ta8_rtc_interrupt, |
Thomas Hommel | 0296411 | 2007-07-21 04:37:58 -0700 | [diff] [blame] | 330 | IRQF_DISABLED | IRQF_SHARED, |
| 331 | pdev->name, pdev) < 0) { |
| 332 | dev_warn(&pdev->dev, "interrupt not available.\n"); |
Anton Vorontsov | 2fac667 | 2009-01-06 14:42:11 -0800 | [diff] [blame] | 333 | pdata->irq = 0; |
Thomas Hommel | 0296411 | 2007-07-21 04:37:58 -0700 | [diff] [blame] | 334 | } |
| 335 | } |
| 336 | |
Alessandro Zummo | b74d2ca | 2009-12-15 16:45:53 -0800 | [diff] [blame] | 337 | pdata->rtc = rtc_device_register(pdev->name, &pdev->dev, |
| 338 | &stk17ta8_rtc_ops, THIS_MODULE); |
Atsushi Nemoto | 3151520 | 2009-12-15 16:46:04 -0800 | [diff] [blame] | 339 | if (IS_ERR(pdata->rtc)) |
| 340 | return PTR_ERR(pdata->rtc); |
Alessandro Zummo | b74d2ca | 2009-12-15 16:45:53 -0800 | [diff] [blame] | 341 | |
| 342 | ret = sysfs_create_bin_file(&pdev->dev.kobj, &stk17ta8_nvram_attr); |
Atsushi Nemoto | 3151520 | 2009-12-15 16:46:04 -0800 | [diff] [blame] | 343 | if (ret) |
Alessandro Zummo | b74d2ca | 2009-12-15 16:45:53 -0800 | [diff] [blame] | 344 | rtc_device_unregister(pdata->rtc); |
Thomas Hommel | 0296411 | 2007-07-21 04:37:58 -0700 | [diff] [blame] | 345 | return ret; |
| 346 | } |
| 347 | |
| 348 | static int __devexit stk17ta8_rtc_remove(struct platform_device *pdev) |
| 349 | { |
| 350 | struct rtc_plat_data *pdata = platform_get_drvdata(pdev); |
| 351 | |
| 352 | sysfs_remove_bin_file(&pdev->dev.kobj, &stk17ta8_nvram_attr); |
| 353 | rtc_device_unregister(pdata->rtc); |
Atsushi Nemoto | 3151520 | 2009-12-15 16:46:04 -0800 | [diff] [blame] | 354 | if (pdata->irq > 0) |
Thomas Hommel | 0296411 | 2007-07-21 04:37:58 -0700 | [diff] [blame] | 355 | writeb(0, pdata->ioaddr + RTC_INTERRUPTS); |
Thomas Hommel | 0296411 | 2007-07-21 04:37:58 -0700 | [diff] [blame] | 356 | return 0; |
| 357 | } |
| 358 | |
Kay Sievers | ad28a07 | 2008-04-10 21:29:25 -0700 | [diff] [blame] | 359 | /* work with hotplug and coldplug */ |
| 360 | MODULE_ALIAS("platform:stk17ta8"); |
| 361 | |
Thomas Hommel | 0296411 | 2007-07-21 04:37:58 -0700 | [diff] [blame] | 362 | static struct platform_driver stk17ta8_rtc_driver = { |
| 363 | .probe = stk17ta8_rtc_probe, |
| 364 | .remove = __devexit_p(stk17ta8_rtc_remove), |
| 365 | .driver = { |
| 366 | .name = "stk17ta8", |
| 367 | .owner = THIS_MODULE, |
| 368 | }, |
| 369 | }; |
| 370 | |
| 371 | static __init int stk17ta8_init(void) |
| 372 | { |
| 373 | return platform_driver_register(&stk17ta8_rtc_driver); |
| 374 | } |
| 375 | |
| 376 | static __exit void stk17ta8_exit(void) |
| 377 | { |
Hannes Eder | 277835a | 2008-11-28 17:11:47 +0100 | [diff] [blame] | 378 | platform_driver_unregister(&stk17ta8_rtc_driver); |
Thomas Hommel | 0296411 | 2007-07-21 04:37:58 -0700 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | module_init(stk17ta8_init); |
| 382 | module_exit(stk17ta8_exit); |
| 383 | |
| 384 | MODULE_AUTHOR("Thomas Hommel <thomas.hommel@gefanuc.com>"); |
| 385 | MODULE_DESCRIPTION("Simtek STK17TA8 RTC driver"); |
| 386 | MODULE_LICENSE("GPL"); |
| 387 | MODULE_VERSION(DRV_VERSION); |