* [PATCH] rtc: abx80x: Implement procfs interface
@ 2019-06-23 12:08 Marek Vasut
2019-06-23 12:38 ` Alexandre Belloni
0 siblings, 1 reply; 4+ messages in thread
From: Marek Vasut @ 2019-06-23 12:08 UTC (permalink / raw)
To: linux-rtc; +Cc: Marek Vasut, Alexandre Belloni
Implement procfs interface for polling battery status of the RTC
via /proc/driver/rtc .
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Alexandre Belloni <alexandre.belloni@free-electrons.com>
---
drivers/rtc/rtc-abx80x.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/drivers/rtc/rtc-abx80x.c b/drivers/rtc/rtc-abx80x.c
index 73830670a41f..4fab024fb508 100644
--- a/drivers/rtc/rtc-abx80x.c
+++ b/drivers/rtc/rtc-abx80x.c
@@ -78,6 +78,10 @@
#define ABX8XX_REG_ID0 0x28
+#define ABX8XX_REG_ANA_STATUS 0x2f
+#define ABX8XX_ANA_BREFD BIT(7)
+#define ABX8XX_ANA_BMIN BIT(6)
+
#define ABX8XX_REG_OUT_CTRL 0x30
#define ABX8XX_OUT_CTRL_EXDS BIT(4)
@@ -548,6 +552,25 @@ static int abx80x_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
}
}
+static int abx80x_proc(struct device *dev, struct seq_file *seq)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ int status, tmp;
+
+ status = i2c_smbus_read_byte_data(client, ABX8XX_REG_ANA_STATUS);
+ if (status < 0)
+ return status;
+
+ if (status & ABX8XX_ANA_BREFD)
+ seq_printf(seq, "battery\t\t: ok\n");
+ else if (status & ABX8XX_ANA_BMIN)
+ seq_printf(seq, "battery\t\t: low\n");
+ else
+ seq_printf(seq, "battery\t\t: exhausted\n");
+
+ return 0;
+}
+
static const struct rtc_class_ops abx80x_rtc_ops = {
.read_time = abx80x_rtc_read_time,
.set_time = abx80x_rtc_set_time,
@@ -555,6 +578,7 @@ static const struct rtc_class_ops abx80x_rtc_ops = {
.set_alarm = abx80x_set_alarm,
.alarm_irq_enable = abx80x_alarm_irq_enable,
.ioctl = abx80x_ioctl,
+ .proc = abx80x_proc,
};
static int abx80x_dt_trickle_cfg(struct device_node *np)
--
2.20.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] rtc: abx80x: Implement procfs interface
2019-06-23 12:08 [PATCH] rtc: abx80x: Implement procfs interface Marek Vasut
@ 2019-06-23 12:38 ` Alexandre Belloni
2019-06-23 13:20 ` Marek Vasut
0 siblings, 1 reply; 4+ messages in thread
From: Alexandre Belloni @ 2019-06-23 12:38 UTC (permalink / raw)
To: Marek Vasut; +Cc: linux-rtc
Hi Marek,
On 23/06/2019 14:08:54+0200, Marek Vasut wrote:
> Implement procfs interface for polling battery status of the RTC
> via /proc/driver/rtc .
>
Please don't, this interface is deprecated and doesn't work well. Use
RTC_VL_READ instead.
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Alexandre Belloni <alexandre.belloni@free-electrons.com>
> ---
> drivers/rtc/rtc-abx80x.c | 24 ++++++++++++++++++++++++
> 1 file changed, 24 insertions(+)
>
> diff --git a/drivers/rtc/rtc-abx80x.c b/drivers/rtc/rtc-abx80x.c
> index 73830670a41f..4fab024fb508 100644
> --- a/drivers/rtc/rtc-abx80x.c
> +++ b/drivers/rtc/rtc-abx80x.c
> @@ -78,6 +78,10 @@
>
> #define ABX8XX_REG_ID0 0x28
>
> +#define ABX8XX_REG_ANA_STATUS 0x2f
> +#define ABX8XX_ANA_BREFD BIT(7)
> +#define ABX8XX_ANA_BMIN BIT(6)
> +
> #define ABX8XX_REG_OUT_CTRL 0x30
> #define ABX8XX_OUT_CTRL_EXDS BIT(4)
>
> @@ -548,6 +552,25 @@ static int abx80x_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
> }
> }
>
> +static int abx80x_proc(struct device *dev, struct seq_file *seq)
> +{
> + struct i2c_client *client = to_i2c_client(dev);
> + int status, tmp;
> +
> + status = i2c_smbus_read_byte_data(client, ABX8XX_REG_ANA_STATUS);
> + if (status < 0)
> + return status;
> +
> + if (status & ABX8XX_ANA_BREFD)
> + seq_printf(seq, "battery\t\t: ok\n");
> + else if (status & ABX8XX_ANA_BMIN)
> + seq_printf(seq, "battery\t\t: low\n");
> + else
> + seq_printf(seq, "battery\t\t: exhausted\n");
> +
> + return 0;
> +}
> +
> static const struct rtc_class_ops abx80x_rtc_ops = {
> .read_time = abx80x_rtc_read_time,
> .set_time = abx80x_rtc_set_time,
> @@ -555,6 +578,7 @@ static const struct rtc_class_ops abx80x_rtc_ops = {
> .set_alarm = abx80x_set_alarm,
> .alarm_irq_enable = abx80x_alarm_irq_enable,
> .ioctl = abx80x_ioctl,
> + .proc = abx80x_proc,
> };
>
> static int abx80x_dt_trickle_cfg(struct device_node *np)
> --
> 2.20.1
>
--
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] rtc: abx80x: Implement procfs interface
2019-06-23 12:38 ` Alexandre Belloni
@ 2019-06-23 13:20 ` Marek Vasut
2019-06-29 12:01 ` Marek Vasut
0 siblings, 1 reply; 4+ messages in thread
From: Marek Vasut @ 2019-06-23 13:20 UTC (permalink / raw)
To: Alexandre Belloni; +Cc: linux-rtc
On 6/23/19 2:38 PM, Alexandre Belloni wrote:
> Hi Marek,
>
> On 23/06/2019 14:08:54+0200, Marek Vasut wrote:
>> Implement procfs interface for polling battery status of the RTC
>> via /proc/driver/rtc .
>>
>
> Please don't, this interface is deprecated and doesn't work well. Use
> RTC_VL_READ instead.
That's already implemented, the procfs one isn't, but fine by me.
--
Best regards,
Marek Vasut
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] rtc: abx80x: Implement procfs interface
2019-06-23 13:20 ` Marek Vasut
@ 2019-06-29 12:01 ` Marek Vasut
0 siblings, 0 replies; 4+ messages in thread
From: Marek Vasut @ 2019-06-29 12:01 UTC (permalink / raw)
To: Alexandre Belloni; +Cc: linux-rtc
On 6/23/19 3:20 PM, Marek Vasut wrote:
> On 6/23/19 2:38 PM, Alexandre Belloni wrote:
>> Hi Marek,
>>
>> On 23/06/2019 14:08:54+0200, Marek Vasut wrote:
>>> Implement procfs interface for polling battery status of the RTC
>>> via /proc/driver/rtc .
>>>
>>
>> Please don't, this interface is deprecated and doesn't work well. Use
>> RTC_VL_READ instead.
> That's already implemented, the procfs one isn't, but fine by me.
Oh, one more thing. The RTC_VL_READ only provides 1 bit of information,
the state of BLF bit (Battery low/failed IIRC). The procfs interface is
more verbose and provides explicit battery status (OK/low/exhausted). Is
there an ioctl for this too ?
--
Best regards,
Marek Vasut
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-06-29 12:01 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-23 12:08 [PATCH] rtc: abx80x: Implement procfs interface Marek Vasut
2019-06-23 12:38 ` Alexandre Belloni
2019-06-23 13:20 ` Marek Vasut
2019-06-29 12:01 ` Marek Vasut
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).