hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/rtc/rtc-rs5c348.c
....@@ -1,11 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * A SPI driver for the Ricoh RS5C348 RTC
34 *
45 * Copyright (C) 2006 Atsushi Nemoto <anemo@mba.ocn.ne.jp>
5
- *
6
- * This program is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License version 2 as
8
- * published by the Free Software Foundation.
96 *
107 * The board specific init code should provide characteristics of this
118 * device:
....@@ -66,6 +63,17 @@
6663 u8 txbuf[5+7], *txp;
6764 int ret;
6865
66
+ ret = spi_w8r8(spi, RS5C348_CMD_R(RS5C348_REG_CTL2));
67
+ if (ret < 0)
68
+ return ret;
69
+ if (ret & RS5C348_BIT_XSTP) {
70
+ txbuf[0] = RS5C348_CMD_W(RS5C348_REG_CTL2);
71
+ txbuf[1] = 0;
72
+ ret = spi_write_then_read(spi, txbuf, 2, NULL, 0);
73
+ if (ret < 0)
74
+ return ret;
75
+ }
76
+
6977 /* Transfer 5 bytes before writing SEC. This gives 31us for carry. */
7078 txp = txbuf;
7179 txbuf[0] = RS5C348_CMD_R(RS5C348_REG_CTL2); /* cmd, ctl2 */
....@@ -101,6 +109,16 @@
101109 struct rs5c348_plat_data *pdata = dev_get_platdata(&spi->dev);
102110 u8 txbuf[5], rxbuf[7];
103111 int ret;
112
+
113
+ ret = spi_w8r8(spi, RS5C348_CMD_R(RS5C348_REG_CTL2));
114
+ if (ret < 0)
115
+ return ret;
116
+ if (ret & RS5C348_BIT_VDET)
117
+ dev_warn(&spi->dev, "voltage-low detected.\n");
118
+ if (ret & RS5C348_BIT_XSTP) {
119
+ dev_warn(&spi->dev, "oscillator-stop detected.\n");
120
+ return -EINVAL;
121
+ }
104122
105123 /* Transfer 5 byte befores reading SEC. This gives 31us for carry. */
106124 txbuf[0] = RS5C348_CMD_R(RS5C348_REG_CTL2); /* cmd, ctl2 */
....@@ -143,8 +161,6 @@
143161 .set_time = rs5c348_rtc_set_time,
144162 };
145163
146
-static struct spi_driver rs5c348_driver;
147
-
148164 static int rs5c348_probe(struct spi_device *spi)
149165 {
150166 int ret;
....@@ -161,53 +177,27 @@
161177 ret = spi_w8r8(spi, RS5C348_CMD_R(RS5C348_REG_SECS));
162178 if (ret < 0 || (ret & 0x80)) {
163179 dev_err(&spi->dev, "not found.\n");
164
- goto kfree_exit;
180
+ return ret;
165181 }
166182
167183 dev_info(&spi->dev, "spiclk %u KHz.\n",
168184 (spi->max_speed_hz + 500) / 1000);
169185
170
- /* turn RTC on if it was not on */
171
- ret = spi_w8r8(spi, RS5C348_CMD_R(RS5C348_REG_CTL2));
172
- if (ret < 0)
173
- goto kfree_exit;
174
- if (ret & (RS5C348_BIT_XSTP | RS5C348_BIT_VDET)) {
175
- u8 buf[2];
176
- struct rtc_time tm;
177
- if (ret & RS5C348_BIT_VDET)
178
- dev_warn(&spi->dev, "voltage-low detected.\n");
179
- if (ret & RS5C348_BIT_XSTP)
180
- dev_warn(&spi->dev, "oscillator-stop detected.\n");
181
- rtc_time_to_tm(0, &tm); /* 1970/1/1 */
182
- ret = rs5c348_rtc_set_time(&spi->dev, &tm);
183
- if (ret < 0)
184
- goto kfree_exit;
185
- buf[0] = RS5C348_CMD_W(RS5C348_REG_CTL2);
186
- buf[1] = 0;
187
- ret = spi_write_then_read(spi, buf, sizeof(buf), NULL, 0);
188
- if (ret < 0)
189
- goto kfree_exit;
190
- }
191
-
192186 ret = spi_w8r8(spi, RS5C348_CMD_R(RS5C348_REG_CTL1));
193187 if (ret < 0)
194
- goto kfree_exit;
188
+ return ret;
195189 if (ret & RS5C348_BIT_24H)
196190 pdata->rtc_24h = 1;
197191
198
- rtc = devm_rtc_device_register(&spi->dev, rs5c348_driver.driver.name,
199
- &rs5c348_rtc_ops, THIS_MODULE);
200
-
201
- if (IS_ERR(rtc)) {
202
- ret = PTR_ERR(rtc);
203
- goto kfree_exit;
204
- }
192
+ rtc = devm_rtc_allocate_device(&spi->dev);
193
+ if (IS_ERR(rtc))
194
+ return PTR_ERR(rtc);
205195
206196 pdata->rtc = rtc;
207197
208
- return 0;
209
- kfree_exit:
210
- return ret;
198
+ rtc->ops = &rs5c348_rtc_ops;
199
+
200
+ return rtc_register_device(rtc);
211201 }
212202
213203 static struct spi_driver rs5c348_driver = {