| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
|---|
| 1 | 2 | /* drivers/rtc/rtc-goldfish.c |
|---|
| 2 | 3 | * |
|---|
| 3 | 4 | * Copyright (C) 2007 Google, Inc. |
|---|
| 4 | 5 | * Copyright (C) 2017 Imagination Technologies Ltd. |
|---|
| 5 | | - * |
|---|
| 6 | | - * This software is licensed under the terms of the GNU General Public |
|---|
| 7 | | - * License version 2, as published by the Free Software Foundation, and |
|---|
| 8 | | - * may be copied, distributed, and modified under those terms. |
|---|
| 9 | | - * |
|---|
| 10 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 11 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 12 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 13 | | - * GNU General Public License for more details. |
|---|
| 14 | | - * |
|---|
| 15 | 6 | */ |
|---|
| 16 | 7 | |
|---|
| 8 | +#include <linux/io.h> |
|---|
| 17 | 9 | #include <linux/module.h> |
|---|
| 10 | +#include <linux/of.h> |
|---|
| 18 | 11 | #include <linux/platform_device.h> |
|---|
| 19 | 12 | #include <linux/rtc.h> |
|---|
| 20 | | -#include <linux/io.h> |
|---|
| 21 | 13 | |
|---|
| 22 | 14 | #define TIMER_TIME_LOW 0x00 /* get low bits of current time */ |
|---|
| 23 | 15 | /* and update TIMER_TIME_HIGH */ |
|---|
| .. | .. |
|---|
| 56 | 48 | do_div(rtc_alarm, NSEC_PER_SEC); |
|---|
| 57 | 49 | memset(alrm, 0, sizeof(struct rtc_wkalrm)); |
|---|
| 58 | 50 | |
|---|
| 59 | | - rtc_time_to_tm(rtc_alarm, &alrm->time); |
|---|
| 51 | + rtc_time64_to_tm(rtc_alarm, &alrm->time); |
|---|
| 60 | 52 | |
|---|
| 61 | 53 | if (readl(base + TIMER_ALARM_STATUS)) |
|---|
| 62 | 54 | alrm->enabled = 1; |
|---|
| .. | .. |
|---|
| 70 | 62 | struct rtc_wkalrm *alrm) |
|---|
| 71 | 63 | { |
|---|
| 72 | 64 | struct goldfish_rtc *rtcdrv; |
|---|
| 73 | | - unsigned long rtc_alarm; |
|---|
| 74 | 65 | u64 rtc_alarm64; |
|---|
| 75 | 66 | u64 rtc_status_reg; |
|---|
| 76 | 67 | void __iomem *base; |
|---|
| 77 | | - int ret = 0; |
|---|
| 78 | 68 | |
|---|
| 79 | 69 | rtcdrv = dev_get_drvdata(dev); |
|---|
| 80 | 70 | base = rtcdrv->base; |
|---|
| 81 | 71 | |
|---|
| 82 | 72 | if (alrm->enabled) { |
|---|
| 83 | | - ret = rtc_tm_to_time(&alrm->time, &rtc_alarm); |
|---|
| 84 | | - if (ret != 0) |
|---|
| 85 | | - return ret; |
|---|
| 86 | | - |
|---|
| 87 | | - rtc_alarm64 = rtc_alarm * NSEC_PER_SEC; |
|---|
| 73 | + rtc_alarm64 = rtc_tm_to_time64(&alrm->time) * NSEC_PER_SEC; |
|---|
| 88 | 74 | writel((rtc_alarm64 >> 32), base + TIMER_ALARM_HIGH); |
|---|
| 89 | 75 | writel(rtc_alarm64, base + TIMER_ALARM_LOW); |
|---|
| 90 | 76 | writel(1, base + TIMER_IRQ_ENABLED); |
|---|
| .. | .. |
|---|
| 99 | 85 | writel(1, base + TIMER_CLEAR_ALARM); |
|---|
| 100 | 86 | } |
|---|
| 101 | 87 | |
|---|
| 102 | | - return ret; |
|---|
| 88 | + return 0; |
|---|
| 103 | 89 | } |
|---|
| 104 | 90 | |
|---|
| 105 | 91 | static int goldfish_rtc_alarm_irq_enable(struct device *dev, |
|---|
| .. | .. |
|---|
| 148 | 134 | |
|---|
| 149 | 135 | do_div(time, NSEC_PER_SEC); |
|---|
| 150 | 136 | |
|---|
| 151 | | - rtc_time_to_tm(time, tm); |
|---|
| 137 | + rtc_time64_to_tm(time, tm); |
|---|
| 152 | 138 | |
|---|
| 153 | 139 | return 0; |
|---|
| 154 | 140 | } |
|---|
| .. | .. |
|---|
| 157 | 143 | { |
|---|
| 158 | 144 | struct goldfish_rtc *rtcdrv; |
|---|
| 159 | 145 | void __iomem *base; |
|---|
| 160 | | - unsigned long now; |
|---|
| 161 | 146 | u64 now64; |
|---|
| 162 | | - int ret; |
|---|
| 163 | 147 | |
|---|
| 164 | 148 | rtcdrv = dev_get_drvdata(dev); |
|---|
| 165 | 149 | base = rtcdrv->base; |
|---|
| 166 | 150 | |
|---|
| 167 | | - ret = rtc_tm_to_time(tm, &now); |
|---|
| 168 | | - if (ret == 0) { |
|---|
| 169 | | - now64 = now * NSEC_PER_SEC; |
|---|
| 170 | | - writel((now64 >> 32), base + TIMER_TIME_HIGH); |
|---|
| 171 | | - writel(now64, base + TIMER_TIME_LOW); |
|---|
| 172 | | - } |
|---|
| 151 | + now64 = rtc_tm_to_time64(tm) * NSEC_PER_SEC; |
|---|
| 152 | + writel((now64 >> 32), base + TIMER_TIME_HIGH); |
|---|
| 153 | + writel(now64, base + TIMER_TIME_LOW); |
|---|
| 173 | 154 | |
|---|
| 174 | | - return ret; |
|---|
| 155 | + return 0; |
|---|
| 175 | 156 | } |
|---|
| 176 | 157 | |
|---|
| 177 | 158 | static const struct rtc_class_ops goldfish_rtc_ops = { |
|---|
| .. | .. |
|---|
| 185 | 166 | static int goldfish_rtc_probe(struct platform_device *pdev) |
|---|
| 186 | 167 | { |
|---|
| 187 | 168 | struct goldfish_rtc *rtcdrv; |
|---|
| 188 | | - struct resource *r; |
|---|
| 189 | 169 | int err; |
|---|
| 190 | 170 | |
|---|
| 191 | 171 | rtcdrv = devm_kzalloc(&pdev->dev, sizeof(*rtcdrv), GFP_KERNEL); |
|---|
| .. | .. |
|---|
| 193 | 173 | return -ENOMEM; |
|---|
| 194 | 174 | |
|---|
| 195 | 175 | platform_set_drvdata(pdev, rtcdrv); |
|---|
| 196 | | - |
|---|
| 197 | | - r = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
|---|
| 198 | | - if (!r) |
|---|
| 199 | | - return -ENODEV; |
|---|
| 200 | | - |
|---|
| 201 | | - rtcdrv->base = devm_ioremap_resource(&pdev->dev, r); |
|---|
| 176 | + rtcdrv->base = devm_platform_ioremap_resource(pdev, 0); |
|---|
| 202 | 177 | if (IS_ERR(rtcdrv->base)) |
|---|
| 203 | | - return -ENODEV; |
|---|
| 178 | + return PTR_ERR(rtcdrv->base); |
|---|
| 204 | 179 | |
|---|
| 205 | 180 | rtcdrv->irq = platform_get_irq(pdev, 0); |
|---|
| 206 | 181 | if (rtcdrv->irq < 0) |
|---|
| 207 | 182 | return -ENODEV; |
|---|
| 208 | 183 | |
|---|
| 209 | | - rtcdrv->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, |
|---|
| 210 | | - &goldfish_rtc_ops, |
|---|
| 211 | | - THIS_MODULE); |
|---|
| 184 | + rtcdrv->rtc = devm_rtc_allocate_device(&pdev->dev); |
|---|
| 212 | 185 | if (IS_ERR(rtcdrv->rtc)) |
|---|
| 213 | 186 | return PTR_ERR(rtcdrv->rtc); |
|---|
| 187 | + |
|---|
| 188 | + rtcdrv->rtc->ops = &goldfish_rtc_ops; |
|---|
| 189 | + rtcdrv->rtc->range_max = U64_MAX / NSEC_PER_SEC; |
|---|
| 214 | 190 | |
|---|
| 215 | 191 | err = devm_request_irq(&pdev->dev, rtcdrv->irq, |
|---|
| 216 | 192 | goldfish_rtc_interrupt, |
|---|
| .. | .. |
|---|
| 218 | 194 | if (err) |
|---|
| 219 | 195 | return err; |
|---|
| 220 | 196 | |
|---|
| 221 | | - return 0; |
|---|
| 197 | + return rtc_register_device(rtcdrv->rtc); |
|---|
| 222 | 198 | } |
|---|
| 223 | 199 | |
|---|
| 224 | 200 | static const struct of_device_id goldfish_rtc_of_match[] = { |
|---|