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