All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] rtc: rs5c372: Add RTC_VL_READ, RTC_VL_CLR ioctls
@ 2021-11-10 14:14 Camel Guo
  2021-11-11  8:39 ` Camel Guo
  0 siblings, 1 reply; 2+ messages in thread
From: Camel Guo @ 2021-11-10 14:14 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni
  Cc: kernel, Camel Guo, linux-rtc, linux-kernel

From: Camel Guo <camelg@axis.com>

In order to make it possible to get battery voltage status, this commit
adds RTC_VL_READ, RTC_VL_CLR ioctl commands to rtc-rs5c372.

Signed-off-by: Camel Guo <camelg@axis.com>
---

v2: Set RTC_VL_BACKUP_LOW if VDET is set. Do not clear PON, XSTP in
RTC_VL_CLR ioctl

 drivers/rtc/rtc-rs5c372.c | 60 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)

diff --git a/drivers/rtc/rtc-rs5c372.c b/drivers/rtc/rtc-rs5c372.c
index 80980414890c..4ab8718d9360 100644
--- a/drivers/rtc/rtc-rs5c372.c
+++ b/drivers/rtc/rtc-rs5c372.c
@@ -485,6 +485,65 @@ static int rs5c372_rtc_proc(struct device *dev, struct seq_file *seq)
 #define	rs5c372_rtc_proc	NULL
 #endif
 
+#ifdef CONFIG_RTC_INTF_DEV
+static int rs5c372_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
+{
+	struct rs5c372	*rs5c = i2c_get_clientdata(to_i2c_client(dev));
+	unsigned char	ctrl2;
+	int		addr;
+	unsigned int	flags;
+
+	dev_dbg(dev, "%s: cmd=%x\n", __func__, cmd);
+
+	addr = RS5C_ADDR(RS5C_REG_CTRL2);
+	ctrl2 = i2c_smbus_read_byte_data(rs5c->client, addr);
+
+	switch (cmd) {
+	case RTC_VL_READ:
+		flags = 0;
+
+		switch (rs5c->type) {
+		case rtc_r2025sd:
+		case rtc_r2221tl:
+			if ((rs5c->type == rtc_r2025sd && !(ctrl2 & R2x2x_CTRL2_XSTP)) ||
+				(rs5c->type == rtc_r2221tl &&  (ctrl2 & R2x2x_CTRL2_XSTP))) {
+				flags |= RTC_VL_DATA_INVALID;
+			}
+			if (ctrl2 & R2x2x_CTRL2_VDET)
+				flags |= RTC_VL_BACKUP_LOW;
+			break;
+		default:
+			if (ctrl2 & RS5C_CTRL2_XSTP)
+				flags |= RTC_VL_DATA_INVALID;
+			break;
+		}
+
+		return put_user(flags, (unsigned int __user *)arg);
+	case RTC_VL_CLR:
+		/* clear VDET bit */
+		switch (rs5c->type) {
+		case rtc_r2025sd:
+		case rtc_r2221tl:
+			ctrl2 &= ~R2x2x_CTRL2_VDET;
+		default:
+			break;
+		}
+
+		if (i2c_smbus_write_byte_data(rs5c->client, addr, ctrl2) < 0) {
+			dev_dbg(&rs5c->client->dev, "%s: write error in line %i\n",
+					__func__, __LINE__);
+			return -EIO;
+		}
+		return 0;
+	default:
+		return -ENOIOCTLCMD;
+	}
+	return 0;
+}
+#else
+#define rs5c372_ioctl	NULL
+#endif
+
 static const struct rtc_class_ops rs5c372_rtc_ops = {
 	.proc		= rs5c372_rtc_proc,
 	.read_time	= rs5c372_rtc_read_time,
@@ -492,6 +551,7 @@ static const struct rtc_class_ops rs5c372_rtc_ops = {
 	.read_alarm	= rs5c_read_alarm,
 	.set_alarm	= rs5c_set_alarm,
 	.alarm_irq_enable = rs5c_rtc_alarm_irq_enable,
+	.ioctl		= rs5c372_ioctl,
 };
 
 #if IS_ENABLED(CONFIG_RTC_INTF_SYSFS)
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] rtc: rs5c372: Add RTC_VL_READ, RTC_VL_CLR ioctls
  2021-11-10 14:14 [PATCH v2] rtc: rs5c372: Add RTC_VL_READ, RTC_VL_CLR ioctls Camel Guo
@ 2021-11-11  8:39 ` Camel Guo
  0 siblings, 0 replies; 2+ messages in thread
From: Camel Guo @ 2021-11-11  8:39 UTC (permalink / raw)
  To: Camel Guo, Alessandro Zummo, Alexandre Belloni
  Cc: kernel, linux-rtc, linux-kernel

On 11/10/21 3:14 PM, Camel Guo wrote:
> From: Camel Guo <camelg@axis.com>
> 
> In order to make it possible to get battery voltage status, this commit
> adds RTC_VL_READ, RTC_VL_CLR ioctl commands to rtc-rs5c372.
> 
> Signed-off-by: Camel Guo <camelg@axis.com>
> ---
> 
> v2: Set RTC_VL_BACKUP_LOW if VDET is set. Do not clear PON, XSTP in
> RTC_VL_CLR ioctl
> 
>   drivers/rtc/rtc-rs5c372.c | 60 +++++++++++++++++++++++++++++++++++++++
>   1 file changed, 60 insertions(+)
> 
> diff --git a/drivers/rtc/rtc-rs5c372.c b/drivers/rtc/rtc-rs5c372.c
> index 80980414890c..4ab8718d9360 100644
> --- a/drivers/rtc/rtc-rs5c372.c
> +++ b/drivers/rtc/rtc-rs5c372.c
> @@ -485,6 +485,65 @@ static int rs5c372_rtc_proc(struct device *dev, 
> struct seq_file *seq)
>   #define rs5c372_rtc_proc        NULL
>   #endif
> 
> +#ifdef CONFIG_RTC_INTF_DEV
> +static int rs5c372_ioctl(struct device *dev, unsigned int cmd, unsigned 
> long arg)
> +{
> +       struct rs5c372  *rs5c = i2c_get_clientdata(to_i2c_client(dev));
> +       unsigned char   ctrl2;
> +       int             addr;
> +       unsigned int    flags;
> +
> +       dev_dbg(dev, "%s: cmd=%x\n", __func__, cmd);
> +
> +       addr = RS5C_ADDR(RS5C_REG_CTRL2);
> +       ctrl2 = i2c_smbus_read_byte_data(rs5c->client, addr);
> +
> +       switch (cmd) {
> +       case RTC_VL_READ:
> +               flags = 0;
> +
> +               switch (rs5c->type) {
> +               case rtc_r2025sd:
> +               case rtc_r2221tl:
> +                       if ((rs5c->type == rtc_r2025sd && !(ctrl2 & 
> R2x2x_CTRL2_XSTP)) ||
> +                               (rs5c->type == rtc_r2221tl &&  (ctrl2 & 
> R2x2x_CTRL2_XSTP))) {
> +                               flags |= RTC_VL_DATA_INVALID;
> +                       }
> +                       if (ctrl2 & R2x2x_CTRL2_VDET)
> +                               flags |= RTC_VL_BACKUP_LOW;
> +                       break;
> +               default:
> +                       if (ctrl2 & RS5C_CTRL2_XSTP)
> +                               flags |= RTC_VL_DATA_INVALID;
> +                       break;
> +               }
> +
> +               return put_user(flags, (unsigned int __user *)arg);
> +       case RTC_VL_CLR:
> +               /* clear VDET bit */
> +               switch (rs5c->type) {
> +               case rtc_r2025sd:
> +               case rtc_r2221tl:
> +                       ctrl2 &= ~R2x2x_CTRL2_VDET;
> +               default:
> +                       break;
> +               }
> +
> +               if (i2c_smbus_write_byte_data(rs5c->client, addr, ctrl2) 
> < 0) {
> +                       dev_dbg(&rs5c->client->dev, "%s: write error in 
> line %i\n",
> +                                       __func__, __LINE__);
> +                       return -EIO;
> +               }
> +               return 0;
> +       default:
> +               return -ENOIOCTLCMD;
> +       }
> +       return 0;
> +}
> +#else
> +#define rs5c372_ioctl  NULL
> +#endif
> +
>   static const struct rtc_class_ops rs5c372_rtc_ops = {
>           .proc           = rs5c372_rtc_proc,
>           .read_time      = rs5c372_rtc_read_time,
> @@ -492,6 +551,7 @@ static const struct rtc_class_ops rs5c372_rtc_ops = {
>           .read_alarm     = rs5c_read_alarm,
>           .set_alarm      = rs5c_set_alarm,
>           .alarm_irq_enable = rs5c_rtc_alarm_irq_enable,
> +       .ioctl          = rs5c372_ioctl,
>   };
> 
>   #if IS_ENABLED(CONFIG_RTC_INTF_SYSFS)
> -- 
> 2.20.1
> 

PATCH v3 is uploaded with the fix of avoiding setting ctrl2 register 
when unnecessary.  Please review v3 instead.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-11-11  8:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-10 14:14 [PATCH v2] rtc: rs5c372: Add RTC_VL_READ, RTC_VL_CLR ioctls Camel Guo
2021-11-11  8:39 ` Camel Guo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.