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