Atsushi Nemoto | 0e14923 | 2009-01-06 14:42:22 -0800 | [diff] [blame] | 1 | /* |
| 2 | * TX4939 internal RTC driver |
| 3 | * Based on RBTX49xx patch from CELF patch archive. |
| 4 | * |
| 5 | * This file is subject to the terms and conditions of the GNU General Public |
| 6 | * License. See the file "COPYING" in the main directory of this archive |
| 7 | * for more details. |
| 8 | * |
| 9 | * (C) Copyright TOSHIBA CORPORATION 2005-2007 |
| 10 | */ |
| 11 | #include <linux/rtc.h> |
| 12 | #include <linux/platform_device.h> |
| 13 | #include <linux/interrupt.h> |
Paul Gortmaker | 2113852 | 2011-05-27 09:57:25 -0400 | [diff] [blame] | 14 | #include <linux/module.h> |
Atsushi Nemoto | 0e14923 | 2009-01-06 14:42:22 -0800 | [diff] [blame] | 15 | #include <linux/io.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 16 | #include <linux/gfp.h> |
Alexandre Belloni | a015106 | 2018-02-12 23:47:55 +0100 | [diff] [blame] | 17 | |
| 18 | #define TX4939_RTCCTL_ALME 0x00000080 |
| 19 | #define TX4939_RTCCTL_ALMD 0x00000040 |
| 20 | #define TX4939_RTCCTL_BUSY 0x00000020 |
| 21 | |
| 22 | #define TX4939_RTCCTL_COMMAND 0x00000007 |
| 23 | #define TX4939_RTCCTL_COMMAND_NOP 0x00000000 |
| 24 | #define TX4939_RTCCTL_COMMAND_GETTIME 0x00000001 |
| 25 | #define TX4939_RTCCTL_COMMAND_SETTIME 0x00000002 |
| 26 | #define TX4939_RTCCTL_COMMAND_GETALARM 0x00000003 |
| 27 | #define TX4939_RTCCTL_COMMAND_SETALARM 0x00000004 |
| 28 | |
| 29 | #define TX4939_RTCTBC_PM 0x00000080 |
| 30 | #define TX4939_RTCTBC_COMP 0x0000007f |
| 31 | |
| 32 | #define TX4939_RTC_REG_RAMSIZE 0x00000100 |
| 33 | #define TX4939_RTC_REG_RWBSIZE 0x00000006 |
| 34 | |
| 35 | struct tx4939_rtc_reg { |
| 36 | __u32 ctl; |
| 37 | __u32 adr; |
| 38 | __u32 dat; |
| 39 | __u32 tbc; |
| 40 | }; |
Atsushi Nemoto | 0e14923 | 2009-01-06 14:42:22 -0800 | [diff] [blame] | 41 | |
| 42 | struct tx4939rtc_plat_data { |
| 43 | struct rtc_device *rtc; |
| 44 | struct tx4939_rtc_reg __iomem *rtcreg; |
Atsushi Nemoto | af69a18 | 2009-12-15 16:46:00 -0800 | [diff] [blame] | 45 | spinlock_t lock; |
Atsushi Nemoto | 0e14923 | 2009-01-06 14:42:22 -0800 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | static struct tx4939rtc_plat_data *get_tx4939rtc_plat_data(struct device *dev) |
| 49 | { |
| 50 | return platform_get_drvdata(to_platform_device(dev)); |
| 51 | } |
| 52 | |
| 53 | static int tx4939_rtc_cmd(struct tx4939_rtc_reg __iomem *rtcreg, int cmd) |
| 54 | { |
| 55 | int i = 0; |
| 56 | |
| 57 | __raw_writel(cmd, &rtcreg->ctl); |
| 58 | /* This might take 30us (next 32.768KHz clock) */ |
| 59 | while (__raw_readl(&rtcreg->ctl) & TX4939_RTCCTL_BUSY) { |
| 60 | /* timeout on approx. 100us (@ GBUS200MHz) */ |
| 61 | if (i++ > 200 * 100) |
| 62 | return -EBUSY; |
| 63 | cpu_relax(); |
| 64 | } |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | static int tx4939_rtc_set_mmss(struct device *dev, unsigned long secs) |
| 69 | { |
| 70 | struct tx4939rtc_plat_data *pdata = get_tx4939rtc_plat_data(dev); |
| 71 | struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg; |
| 72 | int i, ret; |
| 73 | unsigned char buf[6]; |
| 74 | |
| 75 | buf[0] = 0; |
| 76 | buf[1] = 0; |
| 77 | buf[2] = secs; |
| 78 | buf[3] = secs >> 8; |
| 79 | buf[4] = secs >> 16; |
| 80 | buf[5] = secs >> 24; |
Atsushi Nemoto | af69a18 | 2009-12-15 16:46:00 -0800 | [diff] [blame] | 81 | spin_lock_irq(&pdata->lock); |
Atsushi Nemoto | 0e14923 | 2009-01-06 14:42:22 -0800 | [diff] [blame] | 82 | __raw_writel(0, &rtcreg->adr); |
| 83 | for (i = 0; i < 6; i++) |
| 84 | __raw_writel(buf[i], &rtcreg->dat); |
| 85 | ret = tx4939_rtc_cmd(rtcreg, |
| 86 | TX4939_RTCCTL_COMMAND_SETTIME | |
| 87 | (__raw_readl(&rtcreg->ctl) & TX4939_RTCCTL_ALME)); |
Atsushi Nemoto | af69a18 | 2009-12-15 16:46:00 -0800 | [diff] [blame] | 88 | spin_unlock_irq(&pdata->lock); |
Atsushi Nemoto | 0e14923 | 2009-01-06 14:42:22 -0800 | [diff] [blame] | 89 | return ret; |
| 90 | } |
| 91 | |
| 92 | static int tx4939_rtc_read_time(struct device *dev, struct rtc_time *tm) |
| 93 | { |
| 94 | struct tx4939rtc_plat_data *pdata = get_tx4939rtc_plat_data(dev); |
| 95 | struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg; |
| 96 | int i, ret; |
| 97 | unsigned long sec; |
| 98 | unsigned char buf[6]; |
| 99 | |
Atsushi Nemoto | af69a18 | 2009-12-15 16:46:00 -0800 | [diff] [blame] | 100 | spin_lock_irq(&pdata->lock); |
Atsushi Nemoto | 0e14923 | 2009-01-06 14:42:22 -0800 | [diff] [blame] | 101 | ret = tx4939_rtc_cmd(rtcreg, |
| 102 | TX4939_RTCCTL_COMMAND_GETTIME | |
| 103 | (__raw_readl(&rtcreg->ctl) & TX4939_RTCCTL_ALME)); |
| 104 | if (ret) { |
Atsushi Nemoto | af69a18 | 2009-12-15 16:46:00 -0800 | [diff] [blame] | 105 | spin_unlock_irq(&pdata->lock); |
Atsushi Nemoto | 0e14923 | 2009-01-06 14:42:22 -0800 | [diff] [blame] | 106 | return ret; |
| 107 | } |
| 108 | __raw_writel(2, &rtcreg->adr); |
| 109 | for (i = 2; i < 6; i++) |
| 110 | buf[i] = __raw_readl(&rtcreg->dat); |
Atsushi Nemoto | af69a18 | 2009-12-15 16:46:00 -0800 | [diff] [blame] | 111 | spin_unlock_irq(&pdata->lock); |
Colin Ian King | 347876a | 2018-02-15 19:36:14 +0000 | [diff] [blame] | 112 | sec = ((unsigned long)buf[5] << 24) | (buf[4] << 16) | |
| 113 | (buf[3] << 8) | buf[2]; |
Atsushi Nemoto | 0e14923 | 2009-01-06 14:42:22 -0800 | [diff] [blame] | 114 | rtc_time_to_tm(sec, tm); |
Alexandre Belloni | ab62670 | 2018-02-19 16:23:55 +0100 | [diff] [blame] | 115 | return 0; |
Atsushi Nemoto | 0e14923 | 2009-01-06 14:42:22 -0800 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | static int tx4939_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) |
| 119 | { |
| 120 | struct tx4939rtc_plat_data *pdata = get_tx4939rtc_plat_data(dev); |
| 121 | struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg; |
| 122 | int i, ret; |
| 123 | unsigned long sec; |
| 124 | unsigned char buf[6]; |
| 125 | |
| 126 | if (alrm->time.tm_sec < 0 || |
| 127 | alrm->time.tm_min < 0 || |
| 128 | alrm->time.tm_hour < 0 || |
| 129 | alrm->time.tm_mday < 0 || |
| 130 | alrm->time.tm_mon < 0 || |
| 131 | alrm->time.tm_year < 0) |
| 132 | return -EINVAL; |
| 133 | rtc_tm_to_time(&alrm->time, &sec); |
| 134 | buf[0] = 0; |
| 135 | buf[1] = 0; |
| 136 | buf[2] = sec; |
| 137 | buf[3] = sec >> 8; |
| 138 | buf[4] = sec >> 16; |
| 139 | buf[5] = sec >> 24; |
Atsushi Nemoto | af69a18 | 2009-12-15 16:46:00 -0800 | [diff] [blame] | 140 | spin_lock_irq(&pdata->lock); |
Atsushi Nemoto | 0e14923 | 2009-01-06 14:42:22 -0800 | [diff] [blame] | 141 | __raw_writel(0, &rtcreg->adr); |
| 142 | for (i = 0; i < 6; i++) |
| 143 | __raw_writel(buf[i], &rtcreg->dat); |
| 144 | ret = tx4939_rtc_cmd(rtcreg, TX4939_RTCCTL_COMMAND_SETALARM | |
| 145 | (alrm->enabled ? TX4939_RTCCTL_ALME : 0)); |
Atsushi Nemoto | af69a18 | 2009-12-15 16:46:00 -0800 | [diff] [blame] | 146 | spin_unlock_irq(&pdata->lock); |
Atsushi Nemoto | 0e14923 | 2009-01-06 14:42:22 -0800 | [diff] [blame] | 147 | return ret; |
| 148 | } |
| 149 | |
| 150 | static int tx4939_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) |
| 151 | { |
| 152 | struct tx4939rtc_plat_data *pdata = get_tx4939rtc_plat_data(dev); |
| 153 | struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg; |
| 154 | int i, ret; |
| 155 | unsigned long sec; |
| 156 | unsigned char buf[6]; |
| 157 | u32 ctl; |
| 158 | |
Atsushi Nemoto | af69a18 | 2009-12-15 16:46:00 -0800 | [diff] [blame] | 159 | spin_lock_irq(&pdata->lock); |
Atsushi Nemoto | 0e14923 | 2009-01-06 14:42:22 -0800 | [diff] [blame] | 160 | ret = tx4939_rtc_cmd(rtcreg, |
| 161 | TX4939_RTCCTL_COMMAND_GETALARM | |
| 162 | (__raw_readl(&rtcreg->ctl) & TX4939_RTCCTL_ALME)); |
| 163 | if (ret) { |
Atsushi Nemoto | af69a18 | 2009-12-15 16:46:00 -0800 | [diff] [blame] | 164 | spin_unlock_irq(&pdata->lock); |
Atsushi Nemoto | 0e14923 | 2009-01-06 14:42:22 -0800 | [diff] [blame] | 165 | return ret; |
| 166 | } |
| 167 | __raw_writel(2, &rtcreg->adr); |
| 168 | for (i = 2; i < 6; i++) |
| 169 | buf[i] = __raw_readl(&rtcreg->dat); |
| 170 | ctl = __raw_readl(&rtcreg->ctl); |
| 171 | alrm->enabled = (ctl & TX4939_RTCCTL_ALME) ? 1 : 0; |
| 172 | alrm->pending = (ctl & TX4939_RTCCTL_ALMD) ? 1 : 0; |
Atsushi Nemoto | af69a18 | 2009-12-15 16:46:00 -0800 | [diff] [blame] | 173 | spin_unlock_irq(&pdata->lock); |
Colin Ian King | 347876a | 2018-02-15 19:36:14 +0000 | [diff] [blame] | 174 | sec = ((unsigned long)buf[5] << 24) | (buf[4] << 16) | |
| 175 | (buf[3] << 8) | buf[2]; |
Atsushi Nemoto | 0e14923 | 2009-01-06 14:42:22 -0800 | [diff] [blame] | 176 | rtc_time_to_tm(sec, &alrm->time); |
| 177 | return rtc_valid_tm(&alrm->time); |
| 178 | } |
| 179 | |
| 180 | static int tx4939_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) |
| 181 | { |
| 182 | struct tx4939rtc_plat_data *pdata = get_tx4939rtc_plat_data(dev); |
| 183 | |
Atsushi Nemoto | af69a18 | 2009-12-15 16:46:00 -0800 | [diff] [blame] | 184 | spin_lock_irq(&pdata->lock); |
Atsushi Nemoto | 0e14923 | 2009-01-06 14:42:22 -0800 | [diff] [blame] | 185 | tx4939_rtc_cmd(pdata->rtcreg, |
| 186 | TX4939_RTCCTL_COMMAND_NOP | |
| 187 | (enabled ? TX4939_RTCCTL_ALME : 0)); |
Atsushi Nemoto | af69a18 | 2009-12-15 16:46:00 -0800 | [diff] [blame] | 188 | spin_unlock_irq(&pdata->lock); |
Atsushi Nemoto | 0e14923 | 2009-01-06 14:42:22 -0800 | [diff] [blame] | 189 | return 0; |
| 190 | } |
| 191 | |
| 192 | static irqreturn_t tx4939_rtc_interrupt(int irq, void *dev_id) |
| 193 | { |
| 194 | struct tx4939rtc_plat_data *pdata = get_tx4939rtc_plat_data(dev_id); |
| 195 | struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg; |
| 196 | unsigned long events = RTC_IRQF; |
| 197 | |
Atsushi Nemoto | af69a18 | 2009-12-15 16:46:00 -0800 | [diff] [blame] | 198 | spin_lock(&pdata->lock); |
Atsushi Nemoto | 0e14923 | 2009-01-06 14:42:22 -0800 | [diff] [blame] | 199 | if (__raw_readl(&rtcreg->ctl) & TX4939_RTCCTL_ALMD) { |
| 200 | events |= RTC_AF; |
| 201 | tx4939_rtc_cmd(rtcreg, TX4939_RTCCTL_COMMAND_NOP); |
| 202 | } |
Atsushi Nemoto | af69a18 | 2009-12-15 16:46:00 -0800 | [diff] [blame] | 203 | spin_unlock(&pdata->lock); |
Alexander Shiyan | 0d71915 | 2014-04-03 14:50:20 -0700 | [diff] [blame] | 204 | rtc_update_irq(pdata->rtc, 1, events); |
| 205 | |
Atsushi Nemoto | 0e14923 | 2009-01-06 14:42:22 -0800 | [diff] [blame] | 206 | return IRQ_HANDLED; |
| 207 | } |
| 208 | |
| 209 | static const struct rtc_class_ops tx4939_rtc_ops = { |
| 210 | .read_time = tx4939_rtc_read_time, |
| 211 | .read_alarm = tx4939_rtc_read_alarm, |
| 212 | .set_alarm = tx4939_rtc_set_alarm, |
| 213 | .set_mmss = tx4939_rtc_set_mmss, |
| 214 | .alarm_irq_enable = tx4939_rtc_alarm_irq_enable, |
| 215 | }; |
| 216 | |
Alexandre Belloni | dd888c6 | 2018-02-12 23:47:59 +0100 | [diff] [blame] | 217 | static int tx4939_nvram_read(void *priv, unsigned int pos, void *val, |
| 218 | size_t bytes) |
Atsushi Nemoto | 0e14923 | 2009-01-06 14:42:22 -0800 | [diff] [blame] | 219 | { |
Alexandre Belloni | dd888c6 | 2018-02-12 23:47:59 +0100 | [diff] [blame] | 220 | struct tx4939rtc_plat_data *pdata = priv; |
Atsushi Nemoto | 0e14923 | 2009-01-06 14:42:22 -0800 | [diff] [blame] | 221 | struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg; |
Alexandre Belloni | dd888c6 | 2018-02-12 23:47:59 +0100 | [diff] [blame] | 222 | u8 *buf = val; |
Atsushi Nemoto | 0e14923 | 2009-01-06 14:42:22 -0800 | [diff] [blame] | 223 | |
Atsushi Nemoto | af69a18 | 2009-12-15 16:46:00 -0800 | [diff] [blame] | 224 | spin_lock_irq(&pdata->lock); |
Alexandre Belloni | dd888c6 | 2018-02-12 23:47:59 +0100 | [diff] [blame] | 225 | for (; bytes; bytes--) { |
Atsushi Nemoto | 0e14923 | 2009-01-06 14:42:22 -0800 | [diff] [blame] | 226 | __raw_writel(pos++, &rtcreg->adr); |
| 227 | *buf++ = __raw_readl(&rtcreg->dat); |
| 228 | } |
Atsushi Nemoto | af69a18 | 2009-12-15 16:46:00 -0800 | [diff] [blame] | 229 | spin_unlock_irq(&pdata->lock); |
Alexandre Belloni | dd888c6 | 2018-02-12 23:47:59 +0100 | [diff] [blame] | 230 | return 0; |
Atsushi Nemoto | 0e14923 | 2009-01-06 14:42:22 -0800 | [diff] [blame] | 231 | } |
| 232 | |
Alexandre Belloni | dd888c6 | 2018-02-12 23:47:59 +0100 | [diff] [blame] | 233 | static int tx4939_nvram_write(void *priv, unsigned int pos, void *val, |
| 234 | size_t bytes) |
Atsushi Nemoto | 0e14923 | 2009-01-06 14:42:22 -0800 | [diff] [blame] | 235 | { |
Alexandre Belloni | dd888c6 | 2018-02-12 23:47:59 +0100 | [diff] [blame] | 236 | struct tx4939rtc_plat_data *pdata = priv; |
Atsushi Nemoto | 0e14923 | 2009-01-06 14:42:22 -0800 | [diff] [blame] | 237 | struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg; |
Alexandre Belloni | dd888c6 | 2018-02-12 23:47:59 +0100 | [diff] [blame] | 238 | u8 *buf = val; |
Atsushi Nemoto | 0e14923 | 2009-01-06 14:42:22 -0800 | [diff] [blame] | 239 | |
Atsushi Nemoto | af69a18 | 2009-12-15 16:46:00 -0800 | [diff] [blame] | 240 | spin_lock_irq(&pdata->lock); |
Alexandre Belloni | dd888c6 | 2018-02-12 23:47:59 +0100 | [diff] [blame] | 241 | for (; bytes; bytes--) { |
Atsushi Nemoto | 0e14923 | 2009-01-06 14:42:22 -0800 | [diff] [blame] | 242 | __raw_writel(pos++, &rtcreg->adr); |
| 243 | __raw_writel(*buf++, &rtcreg->dat); |
| 244 | } |
Atsushi Nemoto | af69a18 | 2009-12-15 16:46:00 -0800 | [diff] [blame] | 245 | spin_unlock_irq(&pdata->lock); |
Alexandre Belloni | dd888c6 | 2018-02-12 23:47:59 +0100 | [diff] [blame] | 246 | return 0; |
Atsushi Nemoto | 0e14923 | 2009-01-06 14:42:22 -0800 | [diff] [blame] | 247 | } |
| 248 | |
Atsushi Nemoto | 0e14923 | 2009-01-06 14:42:22 -0800 | [diff] [blame] | 249 | static int __init tx4939_rtc_probe(struct platform_device *pdev) |
| 250 | { |
| 251 | struct rtc_device *rtc; |
| 252 | struct tx4939rtc_plat_data *pdata; |
| 253 | struct resource *res; |
| 254 | int irq, ret; |
Alexandre Belloni | dd888c6 | 2018-02-12 23:47:59 +0100 | [diff] [blame] | 255 | struct nvmem_config nvmem_cfg = { |
Alexandre Belloni | 2ab7875 | 2018-09-19 03:14:58 +0200 | [diff] [blame] | 256 | .name = "tx4939_nvram", |
Alexandre Belloni | dd888c6 | 2018-02-12 23:47:59 +0100 | [diff] [blame] | 257 | .size = TX4939_RTC_REG_RAMSIZE, |
| 258 | .reg_read = tx4939_nvram_read, |
| 259 | .reg_write = tx4939_nvram_write, |
| 260 | }; |
Atsushi Nemoto | 0e14923 | 2009-01-06 14:42:22 -0800 | [diff] [blame] | 261 | |
Atsushi Nemoto | 0e14923 | 2009-01-06 14:42:22 -0800 | [diff] [blame] | 262 | irq = platform_get_irq(pdev, 0); |
| 263 | if (irq < 0) |
| 264 | return -ENODEV; |
| 265 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); |
| 266 | if (!pdata) |
| 267 | return -ENOMEM; |
| 268 | platform_set_drvdata(pdev, pdata); |
| 269 | |
Julia Lawall | 7c1d69e | 2013-09-11 14:24:27 -0700 | [diff] [blame] | 270 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 271 | pdata->rtcreg = devm_ioremap_resource(&pdev->dev, res); |
| 272 | if (IS_ERR(pdata->rtcreg)) |
| 273 | return PTR_ERR(pdata->rtcreg); |
Atsushi Nemoto | 0e14923 | 2009-01-06 14:42:22 -0800 | [diff] [blame] | 274 | |
Atsushi Nemoto | af69a18 | 2009-12-15 16:46:00 -0800 | [diff] [blame] | 275 | spin_lock_init(&pdata->lock); |
Atsushi Nemoto | 0e14923 | 2009-01-06 14:42:22 -0800 | [diff] [blame] | 276 | tx4939_rtc_cmd(pdata->rtcreg, TX4939_RTCCTL_COMMAND_NOP); |
| 277 | if (devm_request_irq(&pdev->dev, irq, tx4939_rtc_interrupt, |
Yong Zhang | 2f6e5f9 | 2012-03-23 15:02:34 -0700 | [diff] [blame] | 278 | 0, pdev->name, &pdev->dev) < 0) |
Atsushi Nemoto | 0e14923 | 2009-01-06 14:42:22 -0800 | [diff] [blame] | 279 | return -EBUSY; |
Alexandre Belloni | 68981fd | 2018-02-12 23:47:57 +0100 | [diff] [blame] | 280 | rtc = devm_rtc_allocate_device(&pdev->dev); |
Atsushi Nemoto | 0e14923 | 2009-01-06 14:42:22 -0800 | [diff] [blame] | 281 | if (IS_ERR(rtc)) |
| 282 | return PTR_ERR(rtc); |
Alexandre Belloni | 68981fd | 2018-02-12 23:47:57 +0100 | [diff] [blame] | 283 | |
| 284 | rtc->ops = &tx4939_rtc_ops; |
Alexandre Belloni | dd888c6 | 2018-02-12 23:47:59 +0100 | [diff] [blame] | 285 | rtc->nvram_old_abi = true; |
Alexandre Belloni | 68981fd | 2018-02-12 23:47:57 +0100 | [diff] [blame] | 286 | |
Atsushi Nemoto | 0e14923 | 2009-01-06 14:42:22 -0800 | [diff] [blame] | 287 | pdata->rtc = rtc; |
Alexandre Belloni | a2fa9b8 | 2018-02-12 23:47:58 +0100 | [diff] [blame] | 288 | |
Alexandre Belloni | dd888c6 | 2018-02-12 23:47:59 +0100 | [diff] [blame] | 289 | nvmem_cfg.priv = pdata; |
| 290 | ret = rtc_nvmem_register(rtc, &nvmem_cfg); |
| 291 | if (ret) |
| 292 | return ret; |
Jingoo Han | e38fc30 | 2013-04-29 16:19:18 -0700 | [diff] [blame] | 293 | |
Alexandre Belloni | dd888c6 | 2018-02-12 23:47:59 +0100 | [diff] [blame] | 294 | return rtc_register_device(rtc); |
Atsushi Nemoto | 0e14923 | 2009-01-06 14:42:22 -0800 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | static int __exit tx4939_rtc_remove(struct platform_device *pdev) |
| 298 | { |
| 299 | struct tx4939rtc_plat_data *pdata = platform_get_drvdata(pdev); |
Atsushi Nemoto | 0e14923 | 2009-01-06 14:42:22 -0800 | [diff] [blame] | 300 | |
Atsushi Nemoto | af69a18 | 2009-12-15 16:46:00 -0800 | [diff] [blame] | 301 | spin_lock_irq(&pdata->lock); |
| 302 | tx4939_rtc_cmd(pdata->rtcreg, TX4939_RTCCTL_COMMAND_NOP); |
| 303 | spin_unlock_irq(&pdata->lock); |
Atsushi Nemoto | 0e14923 | 2009-01-06 14:42:22 -0800 | [diff] [blame] | 304 | return 0; |
| 305 | } |
| 306 | |
| 307 | static struct platform_driver tx4939_rtc_driver = { |
| 308 | .remove = __exit_p(tx4939_rtc_remove), |
| 309 | .driver = { |
| 310 | .name = "tx4939rtc", |
Atsushi Nemoto | 0e14923 | 2009-01-06 14:42:22 -0800 | [diff] [blame] | 311 | }, |
| 312 | }; |
| 313 | |
Jingoo Han | 80f1def | 2013-04-29 16:18:54 -0700 | [diff] [blame] | 314 | module_platform_driver_probe(tx4939_rtc_driver, tx4939_rtc_probe); |
Atsushi Nemoto | 0e14923 | 2009-01-06 14:42:22 -0800 | [diff] [blame] | 315 | |
| 316 | MODULE_AUTHOR("Atsushi Nemoto <anemo@mba.ocn.ne.jp>"); |
| 317 | MODULE_DESCRIPTION("TX4939 internal RTC driver"); |
| 318 | MODULE_LICENSE("GPL"); |
| 319 | MODULE_ALIAS("platform:tx4939rtc"); |