.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0+ |
---|
1 | 2 | /* |
---|
2 | 3 | * PIC32 RTC driver |
---|
3 | 4 | * |
---|
4 | 5 | * Joshua Henderson <joshua.henderson@microchip.com> |
---|
5 | 6 | * Copyright (C) 2016 Microchip Technology Inc. All rights reserved. |
---|
6 | 7 | * |
---|
7 | | - * This program is free software; you can redistribute it and/or modify |
---|
8 | | - * it under the terms of the GNU General Public License as published by |
---|
9 | | - * the Free Software Foundation; either version 2 of the License, or |
---|
10 | | - * (at your option) any later version. |
---|
11 | | - * |
---|
12 | | - * This program is distributed in the hope that it will be useful, but WITHOUT |
---|
13 | | - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
14 | | - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
---|
15 | | - * more details. |
---|
16 | 8 | */ |
---|
17 | 9 | #include <linux/init.h> |
---|
18 | 10 | #include <linux/module.h> |
---|
.. | .. |
---|
170 | 162 | |
---|
171 | 163 | rtc_tm->tm_year += 100; |
---|
172 | 164 | |
---|
173 | | - dev_dbg(dev, "read time %04d.%02d.%02d %02d:%02d:%02d\n", |
---|
174 | | - 1900 + rtc_tm->tm_year, rtc_tm->tm_mon, rtc_tm->tm_mday, |
---|
175 | | - rtc_tm->tm_hour, rtc_tm->tm_min, rtc_tm->tm_sec); |
---|
| 165 | + dev_dbg(dev, "read time %ptR\n", rtc_tm); |
---|
176 | 166 | |
---|
177 | 167 | clk_disable(pdata->clk); |
---|
178 | 168 | return 0; |
---|
.. | .. |
---|
182 | 172 | { |
---|
183 | 173 | struct pic32_rtc_dev *pdata = dev_get_drvdata(dev); |
---|
184 | 174 | void __iomem *base = pdata->reg_base; |
---|
185 | | - int year = tm->tm_year - 100; |
---|
186 | 175 | |
---|
187 | | - dev_dbg(dev, "set time %04d.%02d.%02d %02d:%02d:%02d\n", |
---|
188 | | - 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday, |
---|
189 | | - tm->tm_hour, tm->tm_min, tm->tm_sec); |
---|
190 | | - |
---|
191 | | - if (year < 0 || year >= 100) { |
---|
192 | | - dev_err(dev, "rtc only supports 100 years\n"); |
---|
193 | | - return -EINVAL; |
---|
194 | | - } |
---|
| 176 | + dev_dbg(dev, "set time %ptR\n", tm); |
---|
195 | 177 | |
---|
196 | 178 | clk_enable(pdata->clk); |
---|
197 | 179 | writeb(bin2bcd(tm->tm_sec), base + PIC32_RTCSEC); |
---|
.. | .. |
---|
199 | 181 | writeb(bin2bcd(tm->tm_hour), base + PIC32_RTCHOUR); |
---|
200 | 182 | writeb(bin2bcd(tm->tm_mday), base + PIC32_RTCDAY); |
---|
201 | 183 | writeb(bin2bcd(tm->tm_mon + 1), base + PIC32_RTCMON); |
---|
202 | | - writeb(bin2bcd(year), base + PIC32_RTCYEAR); |
---|
| 184 | + writeb(bin2bcd(tm->tm_year - 100), base + PIC32_RTCYEAR); |
---|
203 | 185 | clk_disable(pdata->clk); |
---|
204 | 186 | |
---|
205 | 187 | return 0; |
---|
.. | .. |
---|
224 | 206 | |
---|
225 | 207 | alrm->enabled = (alm_en & PIC32_RTCALRM_ALRMEN) ? 1 : 0; |
---|
226 | 208 | |
---|
227 | | - dev_dbg(dev, "getalarm: %d, %04d.%02d.%02d %02d:%02d:%02d\n", |
---|
228 | | - alm_en, |
---|
229 | | - 1900 + alm_tm->tm_year, alm_tm->tm_mon, alm_tm->tm_mday, |
---|
230 | | - alm_tm->tm_hour, alm_tm->tm_min, alm_tm->tm_sec); |
---|
| 209 | + dev_dbg(dev, "getalarm: %d, %ptR\n", alm_en, alm_tm); |
---|
231 | 210 | |
---|
232 | 211 | alm_tm->tm_sec = bcd2bin(alm_tm->tm_sec); |
---|
233 | 212 | alm_tm->tm_min = bcd2bin(alm_tm->tm_min); |
---|
.. | .. |
---|
247 | 226 | void __iomem *base = pdata->reg_base; |
---|
248 | 227 | |
---|
249 | 228 | clk_enable(pdata->clk); |
---|
250 | | - dev_dbg(dev, "setalarm: %d, %04d.%02d.%02d %02d:%02d:%02d\n", |
---|
251 | | - alrm->enabled, |
---|
252 | | - 1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday, |
---|
253 | | - tm->tm_hour, tm->tm_min, tm->tm_sec); |
---|
| 229 | + dev_dbg(dev, "setalarm: %d, %ptR\n", alrm->enabled, tm); |
---|
254 | 230 | |
---|
255 | 231 | writel(0x00, base + PIC32_ALRMTIME); |
---|
256 | 232 | writel(0x00, base + PIC32_ALRMDATE); |
---|
.. | .. |
---|
322 | 298 | static int pic32_rtc_probe(struct platform_device *pdev) |
---|
323 | 299 | { |
---|
324 | 300 | struct pic32_rtc_dev *pdata; |
---|
325 | | - struct resource *res; |
---|
326 | 301 | int ret; |
---|
327 | 302 | |
---|
328 | 303 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); |
---|
.. | .. |
---|
332 | 307 | platform_set_drvdata(pdev, pdata); |
---|
333 | 308 | |
---|
334 | 309 | pdata->alarm_irq = platform_get_irq(pdev, 0); |
---|
335 | | - if (pdata->alarm_irq < 0) { |
---|
336 | | - dev_err(&pdev->dev, "no irq for alarm\n"); |
---|
| 310 | + if (pdata->alarm_irq < 0) |
---|
337 | 311 | return pdata->alarm_irq; |
---|
338 | | - } |
---|
339 | 312 | |
---|
340 | | - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
---|
341 | | - pdata->reg_base = devm_ioremap_resource(&pdev->dev, res); |
---|
| 313 | + pdata->reg_base = devm_platform_ioremap_resource(pdev, 0); |
---|
342 | 314 | if (IS_ERR(pdata->reg_base)) |
---|
343 | 315 | return PTR_ERR(pdata->reg_base); |
---|
344 | 316 | |
---|
.. | .. |
---|
352 | 324 | |
---|
353 | 325 | spin_lock_init(&pdata->alarm_lock); |
---|
354 | 326 | |
---|
| 327 | + pdata->rtc = devm_rtc_allocate_device(&pdev->dev); |
---|
| 328 | + if (IS_ERR(pdata->rtc)) |
---|
| 329 | + return PTR_ERR(pdata->rtc); |
---|
| 330 | + |
---|
355 | 331 | clk_prepare_enable(pdata->clk); |
---|
356 | 332 | |
---|
357 | 333 | pic32_rtc_enable(pdata, 1); |
---|
358 | 334 | |
---|
359 | 335 | device_init_wakeup(&pdev->dev, 1); |
---|
360 | 336 | |
---|
361 | | - pdata->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, |
---|
362 | | - &pic32_rtcops, |
---|
363 | | - THIS_MODULE); |
---|
364 | | - if (IS_ERR(pdata->rtc)) { |
---|
365 | | - ret = PTR_ERR(pdata->rtc); |
---|
| 337 | + pdata->rtc->ops = &pic32_rtcops; |
---|
| 338 | + pdata->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; |
---|
| 339 | + pdata->rtc->range_max = RTC_TIMESTAMP_END_2099; |
---|
| 340 | + |
---|
| 341 | + ret = rtc_register_device(pdata->rtc); |
---|
| 342 | + if (ret) |
---|
366 | 343 | goto err_nortc; |
---|
367 | | - } |
---|
368 | 344 | |
---|
369 | 345 | pdata->rtc->max_user_freq = 128; |
---|
370 | 346 | |
---|