Skip to content

Commit a7efd19

Browse files
committed
Merge tag 'rtc-5.13' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux
Pull RTC updates from Alexandre Belloni: "Mostly small fixes and two drivers gaining alarm support. Summary: Subsystem: - UIE emulation has been reworked to avoid calling driver callbacks when it is known it will not work Drivers: - ab-eoz9: add alarm support - pcf8523: add alarm support" * tag 'rtc-5.13' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux: (27 commits) rtc: sysfs: check features instead of ops rtc: omap: use rtc_write to access OMAP_RTC_OSC_REG rtc: s5m: Remove reference to parent's device pdata rtc: ds1307: Fix wday settings for rx8130 rtc: pcf8523: report oscillator failures rtc: pcf8523: add alarm support rtc: pcf8523: remove useless define rtc: rtc_update_irq_enable: rework UIE emulation rtc: ds1307: remove flags rtc: ds1307: replace HAS_ALARM by RTC_FEATURE_ALARM rtc: imx-sc: remove .read_alarm rtc: ds1511: remove unused function rtc: fsl-ftm-alarm: add MODULE_TABLE() rtc: rtc-spear: replace spin_lock_irqsave by spin_lock in hard IRQ dt-bindings: rtc: qcom-pm8xxx-rtc: Add qcom pm8xxx rtc bindings rtc: pm8xxx: Add RTC support for PMIC PMK8350 rtc: ab-eoz9: make use of RTC_FEATURE_ALARM rtc: ab-eoz9: add alarm support rtc: ab-eoz9: set regmap max_register rtc: pcf85063: fallback to parent of_node ...
2 parents 9b1f61d + 4d0185e commit a7efd19

21 files changed

+450
-111
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
2+
%YAML 1.2
3+
---
4+
$id: http://devicetree.org/schemas/rtc/qcom-pm8xxx-rtc.yaml#
5+
$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+
title: Qualcomm PM8xxx PMIC RTC device
8+
9+
maintainers:
10+
- Satya Priya <[email protected]>
11+
12+
properties:
13+
compatible:
14+
enum:
15+
- qcom,pm8058-rtc
16+
- qcom,pm8921-rtc
17+
- qcom,pm8941-rtc
18+
- qcom,pm8018-rtc
19+
- qcom,pmk8350-rtc
20+
21+
reg:
22+
maxItems: 1
23+
24+
interrupts:
25+
maxItems: 1
26+
27+
allow-set-time:
28+
$ref: /schemas/types.yaml#/definitions/flag
29+
description:
30+
Indicates that the setting of RTC time is allowed by the host CPU.
31+
32+
required:
33+
- compatible
34+
- reg
35+
- interrupts
36+
37+
additionalProperties: false
38+
39+
examples:
40+
- |
41+
#include <dt-bindings/spmi/spmi.h>
42+
spmi_bus: spmi@c440000 {
43+
reg = <0x0c440000 0x1100>;
44+
#address-cells = <2>;
45+
#size-cells = <0>;
46+
pmicintc: pmic@0 {
47+
reg = <0x0 SPMI_USID>;
48+
compatible = "qcom,pm8921";
49+
interrupts = <104 8>;
50+
#interrupt-cells = <2>;
51+
interrupt-controller;
52+
#address-cells = <1>;
53+
#size-cells = <0>;
54+
55+
pm8921_rtc: rtc@11d {
56+
compatible = "qcom,pm8921-rtc";
57+
reg = <0x11d>;
58+
interrupts = <0x27 0>;
59+
};
60+
};
61+
};
62+
...

drivers/rtc/Kconfig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1339,6 +1339,7 @@ config RTC_DRV_DIGICOLOR
13391339
config RTC_DRV_IMXDI
13401340
tristate "Freescale IMX DryIce Real Time Clock"
13411341
depends on ARCH_MXC
1342+
depends on OF
13421343
help
13431344
Support for Freescale IMX DryIce RTC
13441345

@@ -1906,7 +1907,7 @@ config RTC_DRV_HID_SENSOR_TIME
19061907

19071908
config RTC_DRV_GOLDFISH
19081909
tristate "Goldfish Real Time Clock"
1909-
depends on OF && HAS_IOMEM
1910+
depends on HAS_IOMEM
19101911
help
19111912
Say yes to enable RTC driver for the Goldfish based virtual platform.
19121913

drivers/rtc/interface.c

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ EXPORT_SYMBOL_GPL(rtc_alarm_irq_enable);
545545

546546
int rtc_update_irq_enable(struct rtc_device *rtc, unsigned int enabled)
547547
{
548-
int rc = 0, err;
548+
int err;
549549

550550
err = mutex_lock_interruptible(&rtc->ops_lock);
551551
if (err)
@@ -561,17 +561,21 @@ int rtc_update_irq_enable(struct rtc_device *rtc, unsigned int enabled)
561561
if (rtc->uie_rtctimer.enabled == enabled)
562562
goto out;
563563

564-
if (rtc->uie_unsupported) {
565-
err = -EINVAL;
566-
goto out;
564+
if (rtc->uie_unsupported || !test_bit(RTC_FEATURE_ALARM, rtc->features)) {
565+
mutex_unlock(&rtc->ops_lock);
566+
#ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL
567+
return rtc_dev_update_irq_enable_emul(rtc, enabled);
568+
#else
569+
return -EINVAL;
570+
#endif
567571
}
568572

569573
if (enabled) {
570574
struct rtc_time tm;
571575
ktime_t now, onesec;
572576

573-
rc = __rtc_read_time(rtc, &tm);
574-
if (rc)
577+
err = __rtc_read_time(rtc, &tm);
578+
if (err)
575579
goto out;
576580
onesec = ktime_set(1, 0);
577581
now = rtc_tm_to_ktime(tm);
@@ -585,24 +589,6 @@ int rtc_update_irq_enable(struct rtc_device *rtc, unsigned int enabled)
585589
out:
586590
mutex_unlock(&rtc->ops_lock);
587591

588-
/*
589-
* __rtc_read_time() failed, this probably means that the RTC time has
590-
* never been set or less probably there is a transient error on the
591-
* bus. In any case, avoid enabling emulation has this will fail when
592-
* reading the time too.
593-
*/
594-
if (rc)
595-
return rc;
596-
597-
#ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL
598-
/*
599-
* Enable emulation if the driver returned -EINVAL to signal that it has
600-
* been configured without interrupts or they are not available at the
601-
* moment.
602-
*/
603-
if (err == -EINVAL)
604-
err = rtc_dev_update_irq_enable_emul(rtc, enabled);
605-
#endif
606592
return err;
607593
}
608594
EXPORT_SYMBOL_GPL(rtc_update_irq_enable);

drivers/rtc/rtc-ab-eoz9.c

Lines changed: 134 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/bcd.h>
1212
#include <linux/of.h>
1313
#include <linux/regmap.h>
14+
#include <linux/bitfield.h>
1415
#include <linux/hwmon.h>
1516
#include <linux/hwmon-sysfs.h>
1617

@@ -57,6 +58,24 @@
5758

5859
#define ABEOZ9_SEC_LEN 7
5960

61+
#define ABEOZ9_REG_ALARM_SEC 0x10
62+
#define ABEOZ9_BIT_ALARM_SEC GENMASK(6, 0)
63+
#define ABEOZ9_REG_ALARM_MIN 0x11
64+
#define ABEOZ9_BIT_ALARM_MIN GENMASK(6, 0)
65+
#define ABEOZ9_REG_ALARM_HOURS 0x12
66+
#define ABEOZ9_BIT_ALARM_HOURS_PM BIT(5)
67+
#define ABEOZ9_BIT_ALARM_HOURS GENMASK(4, 0)
68+
#define ABEOZ9_REG_ALARM_DAYS 0x13
69+
#define ABEOZ9_BIT_ALARM_DAYS GENMASK(5, 0)
70+
#define ABEOZ9_REG_ALARM_WEEKDAYS 0x14
71+
#define ABEOZ9_BIT_ALARM_WEEKDAYS GENMASK(2, 0)
72+
#define ABEOZ9_REG_ALARM_MONTHS 0x15
73+
#define ABEOZ9_BIT_ALARM_MONTHS GENMASK(4, 0)
74+
#define ABEOZ9_REG_ALARM_YEARS 0x16
75+
76+
#define ABEOZ9_ALARM_LEN 7
77+
#define ABEOZ9_BIT_ALARM_AE BIT(7)
78+
6079
#define ABEOZ9_REG_REG_TEMP 0x20
6180
#define ABEOZ953_TEMP_MAX 120
6281
#define ABEOZ953_TEMP_MIN -60
@@ -186,6 +205,98 @@ static int abeoz9_rtc_set_time(struct device *dev, struct rtc_time *tm)
186205
return abeoz9_reset_validity(regmap);
187206
}
188207

208+
static int abeoz9_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
209+
{
210+
struct abeoz9_rtc_data *data = dev_get_drvdata(dev);
211+
struct regmap *regmap = data->regmap;
212+
u8 regs[ABEOZ9_ALARM_LEN];
213+
u8 val[2];
214+
int ret;
215+
216+
ret = abeoz9_check_validity(dev);
217+
if (ret)
218+
return ret;
219+
220+
ret = regmap_bulk_read(regmap, ABEOZ9_REG_CTRL_INT, val, sizeof(val));
221+
if (ret)
222+
return ret;
223+
224+
alarm->enabled = val[0] & ABEOZ9_REG_CTRL_INT_AIE;
225+
alarm->pending = val[1] & ABEOZ9_REG_CTRL_INT_FLAG_AF;
226+
227+
ret = regmap_bulk_read(regmap, ABEOZ9_REG_ALARM_SEC, regs, sizeof(regs));
228+
if (ret)
229+
return ret;
230+
231+
alarm->time.tm_sec = bcd2bin(FIELD_GET(ABEOZ9_BIT_ALARM_SEC, regs[0]));
232+
alarm->time.tm_min = bcd2bin(FIELD_GET(ABEOZ9_BIT_ALARM_MIN, regs[1]));
233+
alarm->time.tm_hour = bcd2bin(FIELD_GET(ABEOZ9_BIT_ALARM_HOURS, regs[2]));
234+
if (FIELD_GET(ABEOZ9_BIT_ALARM_HOURS_PM, regs[2]))
235+
alarm->time.tm_hour += 12;
236+
237+
alarm->time.tm_mday = bcd2bin(FIELD_GET(ABEOZ9_BIT_ALARM_DAYS, regs[3]));
238+
239+
return 0;
240+
}
241+
242+
static int abeoz9_rtc_alarm_irq_enable(struct device *dev, u32 enable)
243+
{
244+
struct abeoz9_rtc_data *data = dev_get_drvdata(dev);
245+
246+
return regmap_update_bits(data->regmap, ABEOZ9_REG_CTRL_INT,
247+
ABEOZ9_REG_CTRL_INT_AIE,
248+
FIELD_PREP(ABEOZ9_REG_CTRL_INT_AIE, enable));
249+
}
250+
251+
static int abeoz9_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
252+
{
253+
struct abeoz9_rtc_data *data = dev_get_drvdata(dev);
254+
u8 regs[ABEOZ9_ALARM_LEN] = {0};
255+
int ret;
256+
257+
ret = regmap_update_bits(data->regmap, ABEOZ9_REG_CTRL_INT_FLAG,
258+
ABEOZ9_REG_CTRL_INT_FLAG_AF, 0);
259+
if (ret)
260+
return ret;
261+
262+
regs[0] = ABEOZ9_BIT_ALARM_AE | FIELD_PREP(ABEOZ9_BIT_ALARM_SEC,
263+
bin2bcd(alarm->time.tm_sec));
264+
regs[1] = ABEOZ9_BIT_ALARM_AE | FIELD_PREP(ABEOZ9_BIT_ALARM_MIN,
265+
bin2bcd(alarm->time.tm_min));
266+
regs[2] = ABEOZ9_BIT_ALARM_AE | FIELD_PREP(ABEOZ9_BIT_ALARM_HOURS,
267+
bin2bcd(alarm->time.tm_hour));
268+
regs[3] = ABEOZ9_BIT_ALARM_AE | FIELD_PREP(ABEOZ9_BIT_ALARM_DAYS,
269+
bin2bcd(alarm->time.tm_mday));
270+
271+
ret = regmap_bulk_write(data->regmap, ABEOZ9_REG_ALARM_SEC, regs,
272+
sizeof(regs));
273+
if (ret)
274+
return ret;
275+
276+
return abeoz9_rtc_alarm_irq_enable(dev, alarm->enabled);
277+
}
278+
279+
static irqreturn_t abeoz9_rtc_irq(int irq, void *dev)
280+
{
281+
struct abeoz9_rtc_data *data = dev_get_drvdata(dev);
282+
unsigned int val;
283+
int ret;
284+
285+
ret = regmap_read(data->regmap, ABEOZ9_REG_CTRL_INT_FLAG, &val);
286+
if (ret)
287+
return IRQ_NONE;
288+
289+
if (!FIELD_GET(ABEOZ9_REG_CTRL_INT_FLAG_AF, val))
290+
return IRQ_NONE;
291+
292+
regmap_update_bits(data->regmap, ABEOZ9_REG_CTRL_INT_FLAG,
293+
ABEOZ9_REG_CTRL_INT_FLAG_AF, 0);
294+
295+
rtc_update_irq(data->rtc, 1, RTC_IRQF | RTC_AF);
296+
297+
return IRQ_HANDLED;
298+
}
299+
189300
static int abeoz9_trickle_parse_dt(struct device_node *node)
190301
{
191302
u32 ohms = 0;
@@ -258,12 +369,16 @@ static int abeoz9_rtc_setup(struct device *dev, struct device_node *node)
258369

259370
static const struct rtc_class_ops rtc_ops = {
260371
.read_time = abeoz9_rtc_get_time,
261-
.set_time = abeoz9_rtc_set_time,
372+
.set_time = abeoz9_rtc_set_time,
373+
.read_alarm = abeoz9_rtc_read_alarm,
374+
.set_alarm = abeoz9_rtc_set_alarm,
375+
.alarm_irq_enable = abeoz9_rtc_alarm_irq_enable,
262376
};
263377

264378
static const struct regmap_config abeoz9_rtc_regmap_config = {
265379
.reg_bits = 8,
266380
.val_bits = 8,
381+
.max_register = 0x3f,
267382
};
268383

269384
#if IS_REACHABLE(CONFIG_HWMON)
@@ -419,6 +534,24 @@ static int abeoz9_probe(struct i2c_client *client,
419534
data->rtc->ops = &rtc_ops;
420535
data->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
421536
data->rtc->range_max = RTC_TIMESTAMP_END_2099;
537+
data->rtc->uie_unsupported = 1;
538+
clear_bit(RTC_FEATURE_ALARM, data->rtc->features);
539+
540+
if (client->irq > 0) {
541+
ret = devm_request_threaded_irq(dev, client->irq, NULL,
542+
abeoz9_rtc_irq,
543+
IRQF_TRIGGER_LOW | IRQF_ONESHOT,
544+
dev_name(dev), dev);
545+
if (ret) {
546+
dev_err(dev, "failed to request alarm irq\n");
547+
return ret;
548+
}
549+
}
550+
551+
if (client->irq > 0 || device_property_read_bool(dev, "wakeup-source")) {
552+
ret = device_init_wakeup(dev, true);
553+
set_bit(RTC_FEATURE_ALARM, data->rtc->features);
554+
}
422555

423556
ret = devm_rtc_register_device(data->rtc);
424557
if (ret)

0 commit comments

Comments
 (0)