| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * TX4939 internal RTC driver |
|---|
| 3 | 4 | * 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 | 5 | * |
|---|
| 9 | 6 | * (C) Copyright TOSHIBA CORPORATION 2005-2007 |
|---|
| 10 | 7 | */ |
|---|
| .. | .. |
|---|
| 45 | 42 | spinlock_t lock; |
|---|
| 46 | 43 | }; |
|---|
| 47 | 44 | |
|---|
| 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 | 45 | static int tx4939_rtc_cmd(struct tx4939_rtc_reg __iomem *rtcreg, int cmd) |
|---|
| 54 | 46 | { |
|---|
| 55 | 47 | int i = 0; |
|---|
| .. | .. |
|---|
| 65 | 57 | return 0; |
|---|
| 66 | 58 | } |
|---|
| 67 | 59 | |
|---|
| 68 | | -static int tx4939_rtc_set_mmss(struct device *dev, unsigned long secs) |
|---|
| 60 | +static int tx4939_rtc_set_time(struct device *dev, struct rtc_time *tm) |
|---|
| 69 | 61 | { |
|---|
| 70 | | - struct tx4939rtc_plat_data *pdata = get_tx4939rtc_plat_data(dev); |
|---|
| 62 | + struct tx4939rtc_plat_data *pdata = dev_get_drvdata(dev); |
|---|
| 71 | 63 | struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg; |
|---|
| 64 | + unsigned long secs = rtc_tm_to_time64(tm); |
|---|
| 72 | 65 | int i, ret; |
|---|
| 73 | 66 | unsigned char buf[6]; |
|---|
| 74 | 67 | |
|---|
| .. | .. |
|---|
| 91 | 84 | |
|---|
| 92 | 85 | static int tx4939_rtc_read_time(struct device *dev, struct rtc_time *tm) |
|---|
| 93 | 86 | { |
|---|
| 94 | | - struct tx4939rtc_plat_data *pdata = get_tx4939rtc_plat_data(dev); |
|---|
| 87 | + struct tx4939rtc_plat_data *pdata = dev_get_drvdata(dev); |
|---|
| 95 | 88 | struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg; |
|---|
| 96 | 89 | int i, ret; |
|---|
| 97 | 90 | unsigned long sec; |
|---|
| .. | .. |
|---|
| 111 | 104 | spin_unlock_irq(&pdata->lock); |
|---|
| 112 | 105 | sec = ((unsigned long)buf[5] << 24) | (buf[4] << 16) | |
|---|
| 113 | 106 | (buf[3] << 8) | buf[2]; |
|---|
| 114 | | - rtc_time_to_tm(sec, tm); |
|---|
| 107 | + rtc_time64_to_tm(sec, tm); |
|---|
| 115 | 108 | return 0; |
|---|
| 116 | 109 | } |
|---|
| 117 | 110 | |
|---|
| 118 | 111 | static int tx4939_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) |
|---|
| 119 | 112 | { |
|---|
| 120 | | - struct tx4939rtc_plat_data *pdata = get_tx4939rtc_plat_data(dev); |
|---|
| 113 | + struct tx4939rtc_plat_data *pdata = dev_get_drvdata(dev); |
|---|
| 121 | 114 | struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg; |
|---|
| 122 | 115 | int i, ret; |
|---|
| 123 | 116 | unsigned long sec; |
|---|
| 124 | 117 | unsigned char buf[6]; |
|---|
| 125 | 118 | |
|---|
| 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); |
|---|
| 119 | + sec = rtc_tm_to_time64(&alrm->time); |
|---|
| 134 | 120 | buf[0] = 0; |
|---|
| 135 | 121 | buf[1] = 0; |
|---|
| 136 | 122 | buf[2] = sec; |
|---|
| .. | .. |
|---|
| 149 | 135 | |
|---|
| 150 | 136 | static int tx4939_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) |
|---|
| 151 | 137 | { |
|---|
| 152 | | - struct tx4939rtc_plat_data *pdata = get_tx4939rtc_plat_data(dev); |
|---|
| 138 | + struct tx4939rtc_plat_data *pdata = dev_get_drvdata(dev); |
|---|
| 153 | 139 | struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg; |
|---|
| 154 | 140 | int i, ret; |
|---|
| 155 | 141 | unsigned long sec; |
|---|
| .. | .. |
|---|
| 173 | 159 | spin_unlock_irq(&pdata->lock); |
|---|
| 174 | 160 | sec = ((unsigned long)buf[5] << 24) | (buf[4] << 16) | |
|---|
| 175 | 161 | (buf[3] << 8) | buf[2]; |
|---|
| 176 | | - rtc_time_to_tm(sec, &alrm->time); |
|---|
| 162 | + rtc_time64_to_tm(sec, &alrm->time); |
|---|
| 177 | 163 | return rtc_valid_tm(&alrm->time); |
|---|
| 178 | 164 | } |
|---|
| 179 | 165 | |
|---|
| 180 | 166 | static int tx4939_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) |
|---|
| 181 | 167 | { |
|---|
| 182 | | - struct tx4939rtc_plat_data *pdata = get_tx4939rtc_plat_data(dev); |
|---|
| 168 | + struct tx4939rtc_plat_data *pdata = dev_get_drvdata(dev); |
|---|
| 183 | 169 | |
|---|
| 184 | 170 | spin_lock_irq(&pdata->lock); |
|---|
| 185 | 171 | tx4939_rtc_cmd(pdata->rtcreg, |
|---|
| .. | .. |
|---|
| 191 | 177 | |
|---|
| 192 | 178 | static irqreturn_t tx4939_rtc_interrupt(int irq, void *dev_id) |
|---|
| 193 | 179 | { |
|---|
| 194 | | - struct tx4939rtc_plat_data *pdata = get_tx4939rtc_plat_data(dev_id); |
|---|
| 180 | + struct tx4939rtc_plat_data *pdata = dev_get_drvdata(dev_id); |
|---|
| 195 | 181 | struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg; |
|---|
| 196 | 182 | unsigned long events = RTC_IRQF; |
|---|
| 197 | 183 | |
|---|
| .. | .. |
|---|
| 210 | 196 | .read_time = tx4939_rtc_read_time, |
|---|
| 211 | 197 | .read_alarm = tx4939_rtc_read_alarm, |
|---|
| 212 | 198 | .set_alarm = tx4939_rtc_set_alarm, |
|---|
| 213 | | - .set_mmss = tx4939_rtc_set_mmss, |
|---|
| 199 | + .set_time = tx4939_rtc_set_time, |
|---|
| 214 | 200 | .alarm_irq_enable = tx4939_rtc_alarm_irq_enable, |
|---|
| 215 | 201 | }; |
|---|
| 216 | 202 | |
|---|
| .. | .. |
|---|
| 250 | 236 | { |
|---|
| 251 | 237 | struct rtc_device *rtc; |
|---|
| 252 | 238 | struct tx4939rtc_plat_data *pdata; |
|---|
| 253 | | - struct resource *res; |
|---|
| 254 | 239 | int irq, ret; |
|---|
| 255 | 240 | struct nvmem_config nvmem_cfg = { |
|---|
| 256 | 241 | .name = "tx4939_nvram", |
|---|
| .. | .. |
|---|
| 267 | 252 | return -ENOMEM; |
|---|
| 268 | 253 | platform_set_drvdata(pdev, pdata); |
|---|
| 269 | 254 | |
|---|
| 270 | | - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
|---|
| 271 | | - pdata->rtcreg = devm_ioremap_resource(&pdev->dev, res); |
|---|
| 255 | + pdata->rtcreg = devm_platform_ioremap_resource(pdev, 0); |
|---|
| 272 | 256 | if (IS_ERR(pdata->rtcreg)) |
|---|
| 273 | 257 | return PTR_ERR(pdata->rtcreg); |
|---|
| 274 | 258 | |
|---|
| .. | .. |
|---|
| 283 | 267 | |
|---|
| 284 | 268 | rtc->ops = &tx4939_rtc_ops; |
|---|
| 285 | 269 | rtc->nvram_old_abi = true; |
|---|
| 270 | + rtc->range_max = U32_MAX; |
|---|
| 286 | 271 | |
|---|
| 287 | 272 | pdata->rtc = rtc; |
|---|
| 288 | 273 | |
|---|
| .. | .. |
|---|
| 315 | 300 | |
|---|
| 316 | 301 | MODULE_AUTHOR("Atsushi Nemoto <anemo@mba.ocn.ne.jp>"); |
|---|
| 317 | 302 | MODULE_DESCRIPTION("TX4939 internal RTC driver"); |
|---|
| 318 | | -MODULE_LICENSE("GPL"); |
|---|
| 303 | +MODULE_LICENSE("GPL v2"); |
|---|
| 319 | 304 | MODULE_ALIAS("platform:tx4939rtc"); |
|---|