| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Driver for the RTC in Marvell SoCs. |
|---|
| 3 | | - * |
|---|
| 4 | | - * This file is licensed under the terms of the GNU General Public |
|---|
| 5 | | - * License version 2. This program is licensed "as is" without any |
|---|
| 6 | | - * warranty of any kind, whether express or implied. |
|---|
| 7 | 4 | */ |
|---|
| 8 | 5 | |
|---|
| 9 | 6 | #include <linux/init.h> |
|---|
| .. | .. |
|---|
| 60 | 57 | |
|---|
| 61 | 58 | rtc_reg = (bin2bcd(tm->tm_mday) << RTC_MDAY_OFFS) | |
|---|
| 62 | 59 | (bin2bcd(tm->tm_mon + 1) << RTC_MONTH_OFFS) | |
|---|
| 63 | | - (bin2bcd(tm->tm_year % 100) << RTC_YEAR_OFFS); |
|---|
| 60 | + (bin2bcd(tm->tm_year - 100) << RTC_YEAR_OFFS); |
|---|
| 64 | 61 | writel(rtc_reg, ioaddr + RTC_DATE_REG_OFFS); |
|---|
| 65 | 62 | |
|---|
| 66 | 63 | return 0; |
|---|
| .. | .. |
|---|
| 125 | 122 | /* hw counts from year 2000, but tm_year is relative to 1900 */ |
|---|
| 126 | 123 | alm->time.tm_year = bcd2bin(year) + 100; |
|---|
| 127 | 124 | |
|---|
| 128 | | - if (rtc_valid_tm(&alm->time) < 0) { |
|---|
| 129 | | - dev_err(dev, "retrieved alarm date/time is not valid.\n"); |
|---|
| 130 | | - rtc_time_to_tm(0, &alm->time); |
|---|
| 131 | | - } |
|---|
| 132 | | - |
|---|
| 133 | 125 | alm->enabled = !!readl(ioaddr + RTC_ALARM_INTERRUPT_MASK_REG_OFFS); |
|---|
| 134 | | - return 0; |
|---|
| 126 | + |
|---|
| 127 | + return rtc_valid_tm(&alm->time); |
|---|
| 135 | 128 | } |
|---|
| 136 | 129 | |
|---|
| 137 | 130 | static int mv_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm) |
|---|
| .. | .. |
|---|
| 163 | 156 | << RTC_MONTH_OFFS; |
|---|
| 164 | 157 | |
|---|
| 165 | 158 | if (alm->time.tm_year >= 0) |
|---|
| 166 | | - rtc_reg |= (RTC_ALARM_VALID | bin2bcd(alm->time.tm_year % 100)) |
|---|
| 159 | + rtc_reg |= (RTC_ALARM_VALID | bin2bcd(alm->time.tm_year - 100)) |
|---|
| 167 | 160 | << RTC_YEAR_OFFS; |
|---|
| 168 | 161 | |
|---|
| 169 | 162 | writel(rtc_reg, ioaddr + RTC_ALARM_DATE_REG_OFFS); |
|---|
| .. | .. |
|---|
| 219 | 212 | |
|---|
| 220 | 213 | static int __init mv_rtc_probe(struct platform_device *pdev) |
|---|
| 221 | 214 | { |
|---|
| 222 | | - struct resource *res; |
|---|
| 223 | 215 | struct rtc_plat_data *pdata; |
|---|
| 224 | 216 | u32 rtc_time; |
|---|
| 225 | 217 | int ret = 0; |
|---|
| .. | .. |
|---|
| 228 | 220 | if (!pdata) |
|---|
| 229 | 221 | return -ENOMEM; |
|---|
| 230 | 222 | |
|---|
| 231 | | - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
|---|
| 232 | | - pdata->ioaddr = devm_ioremap_resource(&pdev->dev, res); |
|---|
| 223 | + pdata->ioaddr = devm_platform_ioremap_resource(pdev, 0); |
|---|
| 233 | 224 | if (IS_ERR(pdata->ioaddr)) |
|---|
| 234 | 225 | return PTR_ERR(pdata->ioaddr); |
|---|
| 235 | 226 | |
|---|
| .. | .. |
|---|
| 261 | 252 | |
|---|
| 262 | 253 | platform_set_drvdata(pdev, pdata); |
|---|
| 263 | 254 | |
|---|
| 264 | | - if (pdata->irq >= 0) { |
|---|
| 265 | | - device_init_wakeup(&pdev->dev, 1); |
|---|
| 266 | | - pdata->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, |
|---|
| 267 | | - &mv_rtc_alarm_ops, |
|---|
| 268 | | - THIS_MODULE); |
|---|
| 269 | | - } else { |
|---|
| 270 | | - pdata->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, |
|---|
| 271 | | - &mv_rtc_ops, THIS_MODULE); |
|---|
| 272 | | - } |
|---|
| 255 | + pdata->rtc = devm_rtc_allocate_device(&pdev->dev); |
|---|
| 273 | 256 | if (IS_ERR(pdata->rtc)) { |
|---|
| 274 | 257 | ret = PTR_ERR(pdata->rtc); |
|---|
| 275 | 258 | goto out; |
|---|
| .. | .. |
|---|
| 285 | 268 | } |
|---|
| 286 | 269 | } |
|---|
| 287 | 270 | |
|---|
| 288 | | - return 0; |
|---|
| 271 | + if (pdata->irq >= 0) { |
|---|
| 272 | + device_init_wakeup(&pdev->dev, 1); |
|---|
| 273 | + pdata->rtc->ops = &mv_rtc_alarm_ops; |
|---|
| 274 | + } else { |
|---|
| 275 | + pdata->rtc->ops = &mv_rtc_ops; |
|---|
| 276 | + } |
|---|
| 277 | + |
|---|
| 278 | + pdata->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; |
|---|
| 279 | + pdata->rtc->range_max = RTC_TIMESTAMP_END_2099; |
|---|
| 280 | + |
|---|
| 281 | + ret = rtc_register_device(pdata->rtc); |
|---|
| 282 | + if (!ret) |
|---|
| 283 | + return 0; |
|---|
| 289 | 284 | out: |
|---|
| 290 | 285 | if (!IS_ERR(pdata->clk)) |
|---|
| 291 | 286 | clk_disable_unprepare(pdata->clk); |
|---|