Skip to content

Commit b7270c6

Browse files
committed
Merge tag 'rtc-6.1' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux
Pull RTC updates from Alexandre Belloni: "A great rework of the isl12022 driver makes up the bulk of the changes. There is also an important fix for CMOS and then the usual small fixes: - switch to devm_clk_get_enabled() where relevant - cmos: event handler registration fix - isl12022: code improvements" * tag 'rtc-6.1' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux: rtc: rv3028: Fix codestyle errors rtc: cmos: Fix event handler registration ordering issue rtc: k3: Use devm_clk_get_enabled() helper rtc: jz4740: Use devm_clk_get_enabled() helper rtc: mpfs: Use devm_clk_get_enabled() helper rtc: ds1685: Fix spelling of function name in comment block rtc: isl12022: switch to using regmap API rtc: isl12022: drop redundant write to HR register rtc: isl12022: use dev_set_drvdata() instead of i2c_set_clientdata() rtc: isl12022: use %ptR rtc: isl12022: simplify some expressions rtc: isl12022: drop a dev_info() rtc: isl12022: specify range_min and range_max rtc: isl12022: stop using deprecated devm_rtc_device_register() rtc: stmp3xxx: Add failure handling for stmp3xxx_wdt_register() rtc: mxc: Use devm_clk_get_enabled() helper rtc: gamecube: Always reset HW_SRNPROT after read rtc: k3: detect SoC to determine erratum fix rtc: k3: wait until the unlock field is not zero rtc: mpfs: Remove printing of stray CR
2 parents 4ce1b97 + e5f12a3 commit b7270c6

File tree

11 files changed

+98
-247
lines changed

11 files changed

+98
-247
lines changed

drivers/rtc/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ config RTC_DRV_ISL1208
423423

424424
config RTC_DRV_ISL12022
425425
tristate "Intersil ISL12022"
426+
select REGMAP_I2C
426427
help
427428
If you say yes here you get support for the
428429
Intersil ISL12022 RTC chip.

drivers/rtc/rtc-cmos.c

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,10 +1352,10 @@ static void cmos_check_acpi_rtc_status(struct device *dev,
13521352

13531353
static int cmos_pnp_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)
13541354
{
1355-
cmos_wake_setup(&pnp->dev);
1355+
int irq, ret;
13561356

13571357
if (pnp_port_start(pnp, 0) == 0x70 && !pnp_irq_valid(pnp, 0)) {
1358-
unsigned int irq = 0;
1358+
irq = 0;
13591359
#ifdef CONFIG_X86
13601360
/* Some machines contain a PNP entry for the RTC, but
13611361
* don't define the IRQ. It should always be safe to
@@ -1364,13 +1364,17 @@ static int cmos_pnp_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)
13641364
if (nr_legacy_irqs())
13651365
irq = RTC_IRQ;
13661366
#endif
1367-
return cmos_do_probe(&pnp->dev,
1368-
pnp_get_resource(pnp, IORESOURCE_IO, 0), irq);
13691367
} else {
1370-
return cmos_do_probe(&pnp->dev,
1371-
pnp_get_resource(pnp, IORESOURCE_IO, 0),
1372-
pnp_irq(pnp, 0));
1368+
irq = pnp_irq(pnp, 0);
13731369
}
1370+
1371+
ret = cmos_do_probe(&pnp->dev, pnp_get_resource(pnp, IORESOURCE_IO, 0), irq);
1372+
if (ret)
1373+
return ret;
1374+
1375+
cmos_wake_setup(&pnp->dev);
1376+
1377+
return 0;
13741378
}
13751379

13761380
static void cmos_pnp_remove(struct pnp_dev *pnp)
@@ -1454,10 +1458,9 @@ static inline void cmos_of_init(struct platform_device *pdev) {}
14541458
static int __init cmos_platform_probe(struct platform_device *pdev)
14551459
{
14561460
struct resource *resource;
1457-
int irq;
1461+
int irq, ret;
14581462

14591463
cmos_of_init(pdev);
1460-
cmos_wake_setup(&pdev->dev);
14611464

14621465
if (RTC_IOMAPPED)
14631466
resource = platform_get_resource(pdev, IORESOURCE_IO, 0);
@@ -1467,7 +1470,13 @@ static int __init cmos_platform_probe(struct platform_device *pdev)
14671470
if (irq < 0)
14681471
irq = -1;
14691472

1470-
return cmos_do_probe(&pdev->dev, resource, irq);
1473+
ret = cmos_do_probe(&pdev->dev, resource, irq);
1474+
if (ret)
1475+
return ret;
1476+
1477+
cmos_wake_setup(&pdev->dev);
1478+
1479+
return 0;
14711480
}
14721481

14731482
static int cmos_platform_remove(struct platform_device *pdev)

drivers/rtc/rtc-ds1685.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ ds1685_rtc_bin2bcd(struct ds1685_priv *rtc, u8 val, u8 bin_mask, u8 bcd_mask)
132132
}
133133

134134
/**
135-
* s1685_rtc_check_mday - check validity of the day of month.
135+
* ds1685_rtc_check_mday - check validity of the day of month.
136136
* @rtc: pointer to the ds1685 rtc structure.
137137
* @mday: day of month.
138138
*

drivers/rtc/rtc-gamecube.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -265,18 +265,17 @@ static int gamecube_rtc_read_offset_from_sram(struct priv *d)
265265
* SRAM address as on previous consoles.
266266
*/
267267
ret = regmap_read(d->regmap, RTC_SRAM_BIAS, &d->rtc_bias);
268-
if (ret) {
269-
pr_err("failed to get the RTC bias\n");
270-
iounmap(hw_srnprot);
271-
return -1;
272-
}
273268

274269
/* Reset SRAM access to how it was before, our job here is done. */
275270
if (old != 0x7bf)
276271
iowrite32be(old, hw_srnprot);
272+
277273
iounmap(hw_srnprot);
278274

279-
return 0;
275+
if (ret)
276+
pr_err("failed to get the RTC bias\n");
277+
278+
return ret;
280279
}
281280

282281
static const struct regmap_range rtc_rd_ranges[] = {

drivers/rtc/rtc-isl12022.c

Lines changed: 40 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/err.h>
1717
#include <linux/of.h>
1818
#include <linux/of_device.h>
19+
#include <linux/regmap.h>
1920

2021
/* ISL register offsets */
2122
#define ISL12022_REG_SC 0x00
@@ -42,83 +43,32 @@ static struct i2c_driver isl12022_driver;
4243

4344
struct isl12022 {
4445
struct rtc_device *rtc;
45-
46-
bool write_enabled; /* true if write enable is set */
46+
struct regmap *regmap;
4747
};
4848

49-
50-
static int isl12022_read_regs(struct i2c_client *client, uint8_t reg,
51-
uint8_t *data, size_t n)
52-
{
53-
struct i2c_msg msgs[] = {
54-
{
55-
.addr = client->addr,
56-
.flags = 0,
57-
.len = 1,
58-
.buf = data
59-
}, /* setup read ptr */
60-
{
61-
.addr = client->addr,
62-
.flags = I2C_M_RD,
63-
.len = n,
64-
.buf = data
65-
}
66-
};
67-
68-
int ret;
69-
70-
data[0] = reg;
71-
ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
72-
if (ret != ARRAY_SIZE(msgs)) {
73-
dev_err(&client->dev, "%s: read error, ret=%d\n",
74-
__func__, ret);
75-
return -EIO;
76-
}
77-
78-
return 0;
79-
}
80-
81-
82-
static int isl12022_write_reg(struct i2c_client *client,
83-
uint8_t reg, uint8_t val)
84-
{
85-
uint8_t data[2] = { reg, val };
86-
int err;
87-
88-
err = i2c_master_send(client, data, sizeof(data));
89-
if (err != sizeof(data)) {
90-
dev_err(&client->dev,
91-
"%s: err=%d addr=%02x, data=%02x\n",
92-
__func__, err, data[0], data[1]);
93-
return -EIO;
94-
}
95-
96-
return 0;
97-
}
98-
99-
10049
/*
10150
* In the routines that deal directly with the isl12022 hardware, we use
10251
* rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch.
10352
*/
10453
static int isl12022_rtc_read_time(struct device *dev, struct rtc_time *tm)
10554
{
106-
struct i2c_client *client = to_i2c_client(dev);
55+
struct isl12022 *isl12022 = dev_get_drvdata(dev);
56+
struct regmap *regmap = isl12022->regmap;
10757
uint8_t buf[ISL12022_REG_INT + 1];
10858
int ret;
10959

110-
ret = isl12022_read_regs(client, ISL12022_REG_SC, buf, sizeof(buf));
60+
ret = regmap_bulk_read(regmap, ISL12022_REG_SC, buf, sizeof(buf));
11161
if (ret)
11262
return ret;
11363

11464
if (buf[ISL12022_REG_SR] & (ISL12022_SR_LBAT85 | ISL12022_SR_LBAT75)) {
115-
dev_warn(&client->dev,
65+
dev_warn(dev,
11666
"voltage dropped below %u%%, "
11767
"date and time is not reliable.\n",
11868
buf[ISL12022_REG_SR] & ISL12022_SR_LBAT85 ? 85 : 75);
11969
}
12070

121-
dev_dbg(&client->dev,
71+
dev_dbg(dev,
12272
"%s: raw data is sec=%02x, min=%02x, hr=%02x, "
12373
"mday=%02x, mon=%02x, year=%02x, wday=%02x, "
12474
"sr=%02x, int=%02x",
@@ -141,65 +91,25 @@ static int isl12022_rtc_read_time(struct device *dev, struct rtc_time *tm)
14191
tm->tm_mon = bcd2bin(buf[ISL12022_REG_MO] & 0x1F) - 1;
14292
tm->tm_year = bcd2bin(buf[ISL12022_REG_YR]) + 100;
14393

144-
dev_dbg(&client->dev, "%s: secs=%d, mins=%d, hours=%d, "
145-
"mday=%d, mon=%d, year=%d, wday=%d\n",
146-
__func__,
147-
tm->tm_sec, tm->tm_min, tm->tm_hour,
148-
tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
94+
dev_dbg(dev, "%s: %ptR\n", __func__, tm);
14995

15096
return 0;
15197
}
15298

15399
static int isl12022_rtc_set_time(struct device *dev, struct rtc_time *tm)
154100
{
155-
struct i2c_client *client = to_i2c_client(dev);
156-
struct isl12022 *isl12022 = i2c_get_clientdata(client);
157-
size_t i;
101+
struct isl12022 *isl12022 = dev_get_drvdata(dev);
102+
struct regmap *regmap = isl12022->regmap;
158103
int ret;
159104
uint8_t buf[ISL12022_REG_DW + 1];
160105

161-
dev_dbg(&client->dev, "%s: secs=%d, mins=%d, hours=%d, "
162-
"mday=%d, mon=%d, year=%d, wday=%d\n",
163-
__func__,
164-
tm->tm_sec, tm->tm_min, tm->tm_hour,
165-
tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
166-
167-
if (!isl12022->write_enabled) {
168-
169-
ret = isl12022_read_regs(client, ISL12022_REG_INT, buf, 1);
170-
if (ret)
171-
return ret;
172-
173-
/* Check if WRTC (write rtc enable) is set factory default is
174-
* 0 (not set) */
175-
if (!(buf[0] & ISL12022_INT_WRTC)) {
176-
dev_info(&client->dev,
177-
"init write enable and 24 hour format\n");
178-
179-
/* Set the write enable bit. */
180-
ret = isl12022_write_reg(client,
181-
ISL12022_REG_INT,
182-
buf[0] | ISL12022_INT_WRTC);
183-
if (ret)
184-
return ret;
185-
186-
/* Write to any RTC register to start RTC, we use the
187-
* HR register, setting the MIL bit to use the 24 hour
188-
* format. */
189-
ret = isl12022_read_regs(client, ISL12022_REG_HR,
190-
buf, 1);
191-
if (ret)
192-
return ret;
193-
194-
ret = isl12022_write_reg(client,
195-
ISL12022_REG_HR,
196-
buf[0] | ISL12022_HR_MIL);
197-
if (ret)
198-
return ret;
199-
}
200-
201-
isl12022->write_enabled = true;
202-
}
106+
dev_dbg(dev, "%s: %ptR\n", __func__, tm);
107+
108+
/* Ensure the write enable bit is set. */
109+
ret = regmap_update_bits(regmap, ISL12022_REG_INT,
110+
ISL12022_INT_WRTC, ISL12022_INT_WRTC);
111+
if (ret)
112+
return ret;
203113

204114
/* hours, minutes and seconds */
205115
buf[ISL12022_REG_SC] = bin2bcd(tm->tm_sec);
@@ -216,22 +126,21 @@ static int isl12022_rtc_set_time(struct device *dev, struct rtc_time *tm)
216126

217127
buf[ISL12022_REG_DW] = tm->tm_wday & 0x07;
218128

219-
/* write register's data */
220-
for (i = 0; i < ARRAY_SIZE(buf); i++) {
221-
ret = isl12022_write_reg(client, ISL12022_REG_SC + i,
222-
buf[ISL12022_REG_SC + i]);
223-
if (ret)
224-
return -EIO;
225-
}
226-
227-
return 0;
129+
return regmap_bulk_write(isl12022->regmap, ISL12022_REG_SC,
130+
buf, sizeof(buf));
228131
}
229132

230133
static const struct rtc_class_ops isl12022_rtc_ops = {
231134
.read_time = isl12022_rtc_read_time,
232135
.set_time = isl12022_rtc_set_time,
233136
};
234137

138+
static const struct regmap_config regmap_config = {
139+
.reg_bits = 8,
140+
.val_bits = 8,
141+
.use_single_write = true,
142+
};
143+
235144
static int isl12022_probe(struct i2c_client *client)
236145
{
237146
struct isl12022 *isl12022;
@@ -243,13 +152,23 @@ static int isl12022_probe(struct i2c_client *client)
243152
GFP_KERNEL);
244153
if (!isl12022)
245154
return -ENOMEM;
155+
dev_set_drvdata(&client->dev, isl12022);
156+
157+
isl12022->regmap = devm_regmap_init_i2c(client, &regmap_config);
158+
if (IS_ERR(isl12022->regmap)) {
159+
dev_err(&client->dev, "regmap allocation failed\n");
160+
return PTR_ERR(isl12022->regmap);
161+
}
162+
163+
isl12022->rtc = devm_rtc_allocate_device(&client->dev);
164+
if (IS_ERR(isl12022->rtc))
165+
return PTR_ERR(isl12022->rtc);
246166

247-
i2c_set_clientdata(client, isl12022);
167+
isl12022->rtc->ops = &isl12022_rtc_ops;
168+
isl12022->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
169+
isl12022->rtc->range_max = RTC_TIMESTAMP_END_2099;
248170

249-
isl12022->rtc = devm_rtc_device_register(&client->dev,
250-
isl12022_driver.driver.name,
251-
&isl12022_rtc_ops, THIS_MODULE);
252-
return PTR_ERR_OR_ZERO(isl12022->rtc);
171+
return devm_rtc_register_device(isl12022->rtc);
253172
}
254173

255174
#ifdef CONFIG_OF

drivers/rtc/rtc-jz4740.c

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,6 @@ static void jz4740_rtc_power_off(void)
257257
kernel_halt();
258258
}
259259

260-
static void jz4740_rtc_clk_disable(void *data)
261-
{
262-
clk_disable_unprepare(data);
263-
}
264-
265260
static const struct of_device_id jz4740_rtc_of_match[] = {
266261
{ .compatible = "ingenic,jz4740-rtc", .data = (void *)ID_JZ4740 },
267262
{ .compatible = "ingenic,jz4760-rtc", .data = (void *)ID_JZ4760 },
@@ -329,23 +324,9 @@ static int jz4740_rtc_probe(struct platform_device *pdev)
329324
if (IS_ERR(rtc->base))
330325
return PTR_ERR(rtc->base);
331326

332-
clk = devm_clk_get(dev, "rtc");
333-
if (IS_ERR(clk)) {
334-
dev_err(dev, "Failed to get RTC clock\n");
335-
return PTR_ERR(clk);
336-
}
337-
338-
ret = clk_prepare_enable(clk);
339-
if (ret) {
340-
dev_err(dev, "Failed to enable clock\n");
341-
return ret;
342-
}
343-
344-
ret = devm_add_action_or_reset(dev, jz4740_rtc_clk_disable, clk);
345-
if (ret) {
346-
dev_err(dev, "Failed to register devm action\n");
347-
return ret;
348-
}
327+
clk = devm_clk_get_enabled(dev, "rtc");
328+
if (IS_ERR(clk))
329+
return dev_err_probe(dev, PTR_ERR(clk), "Failed to get RTC clock\n");
349330

350331
spin_lock_init(&rtc->lock);
351332

0 commit comments

Comments
 (0)