hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/rtc/rtc-ds2404.c
....@@ -1,11 +1,5 @@
1
-/*
2
- * Copyright (C) 2012 Sven Schnelle <svens@stackframe.org>
3
- *
4
- * This program is free software; you can redistribute it and/or modify
5
- * it under the terms of the GNU General Public License version 2 as
6
- * published by the Free Software Foundation.
7
- *
8
- */
1
+// SPDX-License-Identifier: GPL-2.0
2
+// Copyright (C) 2012 Sven Schnelle <svens@stackframe.org>
93
104 #include <linux/platform_device.h>
115 #include <linux/module.h>
....@@ -29,14 +23,6 @@
2923 #define DS2404_COPY_SCRATCHPAD_CMD 0x55
3024 #define DS2404_READ_MEMORY_CMD 0xf0
3125
32
-struct ds2404;
33
-
34
-struct ds2404_chip_ops {
35
- int (*map_io)(struct ds2404 *chip, struct platform_device *pdev,
36
- struct ds2404_platform_data *pdata);
37
- void (*unmap_io)(struct ds2404 *chip);
38
-};
39
-
4026 #define DS2404_RST 0
4127 #define DS2404_CLK 1
4228 #define DS2404_DQ 2
....@@ -48,7 +34,6 @@
4834
4935 struct ds2404 {
5036 struct ds2404_gpio *gpio;
51
- const struct ds2404_chip_ops *ops;
5237 struct rtc_device *rtc;
5338 };
5439
....@@ -87,18 +72,13 @@
8772 return err;
8873 }
8974
90
-static void ds2404_gpio_unmap(struct ds2404 *chip)
75
+static void ds2404_gpio_unmap(void *data)
9176 {
9277 int i;
9378
9479 for (i = 0; i < ARRAY_SIZE(ds2404_gpio); i++)
9580 gpio_free(ds2404_gpio[i].gpio);
9681 }
97
-
98
-static const struct ds2404_chip_ops ds2404_gpio_ops = {
99
- .map_io = ds2404_gpio_map,
100
- .unmap_io = ds2404_gpio_unmap,
101
-};
10282
10383 static void ds2404_reset(struct device *dev)
10484 {
....@@ -202,24 +182,25 @@
202182 static int ds2404_read_time(struct device *dev, struct rtc_time *dt)
203183 {
204184 unsigned long time = 0;
185
+ __le32 hw_time = 0;
205186
206
- ds2404_read_memory(dev, 0x203, 4, (u8 *)&time);
207
- time = le32_to_cpu(time);
187
+ ds2404_read_memory(dev, 0x203, 4, (u8 *)&hw_time);
188
+ time = le32_to_cpu(hw_time);
208189
209
- rtc_time_to_tm(time, dt);
190
+ rtc_time64_to_tm(time, dt);
210191 return 0;
211192 }
212193
213
-static int ds2404_set_mmss(struct device *dev, unsigned long secs)
194
+static int ds2404_set_time(struct device *dev, struct rtc_time *dt)
214195 {
215
- u32 time = cpu_to_le32(secs);
196
+ u32 time = cpu_to_le32(rtc_tm_to_time64(dt));
216197 ds2404_write_memory(dev, 0x203, 4, (u8 *)&time);
217198 return 0;
218199 }
219200
220201 static const struct rtc_class_ops ds2404_rtc_ops = {
221202 .read_time = ds2404_read_time,
222
- .set_mmss = ds2404_set_mmss,
203
+ .set_time = ds2404_set_time,
223204 };
224205
225206 static int rtc_probe(struct platform_device *pdev)
....@@ -232,11 +213,17 @@
232213 if (!chip)
233214 return -ENOMEM;
234215
235
- chip->ops = &ds2404_gpio_ops;
216
+ chip->rtc = devm_rtc_allocate_device(&pdev->dev);
217
+ if (IS_ERR(chip->rtc))
218
+ return PTR_ERR(chip->rtc);
236219
237
- retval = chip->ops->map_io(chip, pdev, pdata);
220
+ retval = ds2404_gpio_map(chip, pdev, pdata);
238221 if (retval)
239
- goto err_chip;
222
+ return retval;
223
+
224
+ retval = devm_add_action_or_reset(&pdev->dev, ds2404_gpio_unmap, chip);
225
+ if (retval)
226
+ return retval;
240227
241228 dev_info(&pdev->dev, "using GPIOs RST:%d, CLK:%d, DQ:%d\n",
242229 chip->gpio[DS2404_RST].gpio, chip->gpio[DS2404_CLK].gpio,
....@@ -244,34 +231,19 @@
244231
245232 platform_set_drvdata(pdev, chip);
246233
247
- chip->rtc = devm_rtc_device_register(&pdev->dev, "ds2404",
248
- &ds2404_rtc_ops, THIS_MODULE);
249
- if (IS_ERR(chip->rtc)) {
250
- retval = PTR_ERR(chip->rtc);
251
- goto err_io;
252
- }
234
+ chip->rtc->ops = &ds2404_rtc_ops;
235
+ chip->rtc->range_max = U32_MAX;
236
+
237
+ retval = rtc_register_device(chip->rtc);
238
+ if (retval)
239
+ return retval;
253240
254241 ds2404_enable_osc(&pdev->dev);
255
- return 0;
256
-
257
-err_io:
258
- chip->ops->unmap_io(chip);
259
-err_chip:
260
- return retval;
261
-}
262
-
263
-static int rtc_remove(struct platform_device *dev)
264
-{
265
- struct ds2404 *chip = platform_get_drvdata(dev);
266
-
267
- chip->ops->unmap_io(chip);
268
-
269242 return 0;
270243 }
271244
272245 static struct platform_driver rtc_device_driver = {
273246 .probe = rtc_probe,
274
- .remove = rtc_remove,
275247 .driver = {
276248 .name = "ds2404",
277249 },