| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * A driver for the RTC embedded in the Cirrus Logic EP93XX processors |
|---|
| 3 | 4 | * Copyright (c) 2006 Tower Technologies |
|---|
| 4 | 5 | * |
|---|
| 5 | 6 | * Author: Alessandro Zummo <a.zummo@towertech.it> |
|---|
| 6 | | - * |
|---|
| 7 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 8 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 9 | | - * published by the Free Software Foundation. |
|---|
| 10 | 7 | */ |
|---|
| 11 | 8 | |
|---|
| 12 | 9 | #include <linux/module.h> |
|---|
| .. | .. |
|---|
| 18 | 15 | #define EP93XX_RTC_DATA 0x000 |
|---|
| 19 | 16 | #define EP93XX_RTC_MATCH 0x004 |
|---|
| 20 | 17 | #define EP93XX_RTC_STATUS 0x008 |
|---|
| 21 | | -#define EP93XX_RTC_STATUS_INTR (1<<0) |
|---|
| 18 | +#define EP93XX_RTC_STATUS_INTR BIT(0) |
|---|
| 22 | 19 | #define EP93XX_RTC_LOAD 0x00C |
|---|
| 23 | 20 | #define EP93XX_RTC_CONTROL 0x010 |
|---|
| 24 | | -#define EP93XX_RTC_CONTROL_MIE (1<<0) |
|---|
| 21 | +#define EP93XX_RTC_CONTROL_MIE BIT(0) |
|---|
| 25 | 22 | #define EP93XX_RTC_SWCOMP 0x108 |
|---|
| 26 | 23 | #define EP93XX_RTC_SWCOMP_DEL_MASK 0x001f0000 |
|---|
| 27 | 24 | #define EP93XX_RTC_SWCOMP_DEL_SHIFT 16 |
|---|
| 28 | 25 | #define EP93XX_RTC_SWCOMP_INT_MASK 0x0000ffff |
|---|
| 29 | 26 | #define EP93XX_RTC_SWCOMP_INT_SHIFT 0 |
|---|
| 30 | 27 | |
|---|
| 31 | | -/* |
|---|
| 32 | | - * struct device dev.platform_data is used to store our private data |
|---|
| 33 | | - * because struct rtc_device does not have a variable to hold it. |
|---|
| 34 | | - */ |
|---|
| 35 | 28 | struct ep93xx_rtc { |
|---|
| 36 | 29 | void __iomem *mmio_base; |
|---|
| 37 | 30 | struct rtc_device *rtc; |
|---|
| 38 | 31 | }; |
|---|
| 39 | 32 | |
|---|
| 40 | 33 | static int ep93xx_rtc_get_swcomp(struct device *dev, unsigned short *preload, |
|---|
| 41 | | - unsigned short *delete) |
|---|
| 34 | + unsigned short *delete) |
|---|
| 42 | 35 | { |
|---|
| 43 | | - struct ep93xx_rtc *ep93xx_rtc = dev_get_platdata(dev); |
|---|
| 36 | + struct ep93xx_rtc *ep93xx_rtc = dev_get_drvdata(dev); |
|---|
| 44 | 37 | unsigned long comp; |
|---|
| 45 | 38 | |
|---|
| 46 | 39 | comp = readl(ep93xx_rtc->mmio_base + EP93XX_RTC_SWCOMP); |
|---|
| .. | .. |
|---|
| 58 | 51 | |
|---|
| 59 | 52 | static int ep93xx_rtc_read_time(struct device *dev, struct rtc_time *tm) |
|---|
| 60 | 53 | { |
|---|
| 61 | | - struct ep93xx_rtc *ep93xx_rtc = dev_get_platdata(dev); |
|---|
| 54 | + struct ep93xx_rtc *ep93xx_rtc = dev_get_drvdata(dev); |
|---|
| 62 | 55 | unsigned long time; |
|---|
| 63 | 56 | |
|---|
| 64 | | - time = readl(ep93xx_rtc->mmio_base + EP93XX_RTC_DATA); |
|---|
| 57 | + time = readl(ep93xx_rtc->mmio_base + EP93XX_RTC_DATA); |
|---|
| 65 | 58 | |
|---|
| 66 | | - rtc_time_to_tm(time, tm); |
|---|
| 59 | + rtc_time64_to_tm(time, tm); |
|---|
| 67 | 60 | return 0; |
|---|
| 68 | 61 | } |
|---|
| 69 | 62 | |
|---|
| 70 | | -static int ep93xx_rtc_set_mmss(struct device *dev, unsigned long secs) |
|---|
| 63 | +static int ep93xx_rtc_set_time(struct device *dev, struct rtc_time *tm) |
|---|
| 71 | 64 | { |
|---|
| 72 | | - struct ep93xx_rtc *ep93xx_rtc = dev_get_platdata(dev); |
|---|
| 65 | + struct ep93xx_rtc *ep93xx_rtc = dev_get_drvdata(dev); |
|---|
| 66 | + unsigned long secs = rtc_tm_to_time64(tm); |
|---|
| 73 | 67 | |
|---|
| 74 | 68 | writel(secs + 1, ep93xx_rtc->mmio_base + EP93XX_RTC_LOAD); |
|---|
| 75 | 69 | return 0; |
|---|
| .. | .. |
|---|
| 89 | 83 | |
|---|
| 90 | 84 | static const struct rtc_class_ops ep93xx_rtc_ops = { |
|---|
| 91 | 85 | .read_time = ep93xx_rtc_read_time, |
|---|
| 92 | | - .set_mmss = ep93xx_rtc_set_mmss, |
|---|
| 86 | + .set_time = ep93xx_rtc_set_time, |
|---|
| 93 | 87 | .proc = ep93xx_rtc_proc, |
|---|
| 94 | 88 | }; |
|---|
| 95 | 89 | |
|---|
| 96 | | -static ssize_t ep93xx_rtc_show_comp_preload(struct device *dev, |
|---|
| 97 | | - struct device_attribute *attr, char *buf) |
|---|
| 90 | +static ssize_t comp_preload_show(struct device *dev, |
|---|
| 91 | + struct device_attribute *attr, char *buf) |
|---|
| 98 | 92 | { |
|---|
| 99 | 93 | unsigned short preload; |
|---|
| 100 | 94 | |
|---|
| 101 | | - ep93xx_rtc_get_swcomp(dev, &preload, NULL); |
|---|
| 95 | + ep93xx_rtc_get_swcomp(dev->parent, &preload, NULL); |
|---|
| 102 | 96 | |
|---|
| 103 | 97 | return sprintf(buf, "%d\n", preload); |
|---|
| 104 | 98 | } |
|---|
| 105 | | -static DEVICE_ATTR(comp_preload, S_IRUGO, ep93xx_rtc_show_comp_preload, NULL); |
|---|
| 99 | +static DEVICE_ATTR_RO(comp_preload); |
|---|
| 106 | 100 | |
|---|
| 107 | | -static ssize_t ep93xx_rtc_show_comp_delete(struct device *dev, |
|---|
| 108 | | - struct device_attribute *attr, char *buf) |
|---|
| 101 | +static ssize_t comp_delete_show(struct device *dev, |
|---|
| 102 | + struct device_attribute *attr, char *buf) |
|---|
| 109 | 103 | { |
|---|
| 110 | 104 | unsigned short delete; |
|---|
| 111 | 105 | |
|---|
| 112 | | - ep93xx_rtc_get_swcomp(dev, NULL, &delete); |
|---|
| 106 | + ep93xx_rtc_get_swcomp(dev->parent, NULL, &delete); |
|---|
| 113 | 107 | |
|---|
| 114 | 108 | return sprintf(buf, "%d\n", delete); |
|---|
| 115 | 109 | } |
|---|
| 116 | | -static DEVICE_ATTR(comp_delete, S_IRUGO, ep93xx_rtc_show_comp_delete, NULL); |
|---|
| 110 | +static DEVICE_ATTR_RO(comp_delete); |
|---|
| 117 | 111 | |
|---|
| 118 | 112 | static struct attribute *ep93xx_rtc_attrs[] = { |
|---|
| 119 | 113 | &dev_attr_comp_preload.attr, |
|---|
| .. | .. |
|---|
| 128 | 122 | static int ep93xx_rtc_probe(struct platform_device *pdev) |
|---|
| 129 | 123 | { |
|---|
| 130 | 124 | struct ep93xx_rtc *ep93xx_rtc; |
|---|
| 131 | | - struct resource *res; |
|---|
| 132 | 125 | int err; |
|---|
| 133 | 126 | |
|---|
| 134 | 127 | ep93xx_rtc = devm_kzalloc(&pdev->dev, sizeof(*ep93xx_rtc), GFP_KERNEL); |
|---|
| 135 | 128 | if (!ep93xx_rtc) |
|---|
| 136 | 129 | return -ENOMEM; |
|---|
| 137 | 130 | |
|---|
| 138 | | - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
|---|
| 139 | | - ep93xx_rtc->mmio_base = devm_ioremap_resource(&pdev->dev, res); |
|---|
| 131 | + ep93xx_rtc->mmio_base = devm_platform_ioremap_resource(pdev, 0); |
|---|
| 140 | 132 | if (IS_ERR(ep93xx_rtc->mmio_base)) |
|---|
| 141 | 133 | return PTR_ERR(ep93xx_rtc->mmio_base); |
|---|
| 142 | 134 | |
|---|
| 143 | | - pdev->dev.platform_data = ep93xx_rtc; |
|---|
| 144 | 135 | platform_set_drvdata(pdev, ep93xx_rtc); |
|---|
| 145 | 136 | |
|---|
| 146 | | - ep93xx_rtc->rtc = devm_rtc_device_register(&pdev->dev, |
|---|
| 147 | | - pdev->name, &ep93xx_rtc_ops, THIS_MODULE); |
|---|
| 148 | | - if (IS_ERR(ep93xx_rtc->rtc)) { |
|---|
| 149 | | - err = PTR_ERR(ep93xx_rtc->rtc); |
|---|
| 150 | | - goto exit; |
|---|
| 151 | | - } |
|---|
| 137 | + ep93xx_rtc->rtc = devm_rtc_allocate_device(&pdev->dev); |
|---|
| 138 | + if (IS_ERR(ep93xx_rtc->rtc)) |
|---|
| 139 | + return PTR_ERR(ep93xx_rtc->rtc); |
|---|
| 152 | 140 | |
|---|
| 153 | | - err = sysfs_create_group(&pdev->dev.kobj, &ep93xx_rtc_sysfs_files); |
|---|
| 141 | + ep93xx_rtc->rtc->ops = &ep93xx_rtc_ops; |
|---|
| 142 | + ep93xx_rtc->rtc->range_max = U32_MAX; |
|---|
| 143 | + |
|---|
| 144 | + err = rtc_add_group(ep93xx_rtc->rtc, &ep93xx_rtc_sysfs_files); |
|---|
| 154 | 145 | if (err) |
|---|
| 155 | | - goto exit; |
|---|
| 146 | + return err; |
|---|
| 156 | 147 | |
|---|
| 157 | | - return 0; |
|---|
| 158 | | - |
|---|
| 159 | | -exit: |
|---|
| 160 | | - pdev->dev.platform_data = NULL; |
|---|
| 161 | | - return err; |
|---|
| 162 | | -} |
|---|
| 163 | | - |
|---|
| 164 | | -static int ep93xx_rtc_remove(struct platform_device *pdev) |
|---|
| 165 | | -{ |
|---|
| 166 | | - sysfs_remove_group(&pdev->dev.kobj, &ep93xx_rtc_sysfs_files); |
|---|
| 167 | | - pdev->dev.platform_data = NULL; |
|---|
| 168 | | - |
|---|
| 169 | | - return 0; |
|---|
| 148 | + return rtc_register_device(ep93xx_rtc->rtc); |
|---|
| 170 | 149 | } |
|---|
| 171 | 150 | |
|---|
| 172 | 151 | static struct platform_driver ep93xx_rtc_driver = { |
|---|
| .. | .. |
|---|
| 174 | 153 | .name = "ep93xx-rtc", |
|---|
| 175 | 154 | }, |
|---|
| 176 | 155 | .probe = ep93xx_rtc_probe, |
|---|
| 177 | | - .remove = ep93xx_rtc_remove, |
|---|
| 178 | 156 | }; |
|---|
| 179 | 157 | |
|---|
| 180 | 158 | module_platform_driver(ep93xx_rtc_driver); |
|---|