diff mbox series

[v2,3/3] i2c: s3c24xx: add support for atomic transfers

Message ID 20231025121725.46028-4-m.szyprowski@samsung.com (mailing list archive)
State Accepted
Commit 187432b82173c86e0450d0e3d516b415ab2455f8
Headers show
Series Add atomic transfers to s3c24xx i2c driver | expand

Commit Message

Marek Szyprowski Oct. 25, 2023, 12:17 p.m. UTC
Add support for atomic transfers using polling mode with interrupts
intentionally disabled to get rid of the warning introduced by commit
63b96983a5dd ("i2c: core: introduce callbacks for atomic transfers")
during system reboot and power-off.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
---
 drivers/i2c/busses/i2c-s3c2410.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

Comments

Chanho Park Oct. 27, 2023, 10:54 a.m. UTC | #1
> -----Original Message-----
> From: Marek Szyprowski <m.szyprowski@samsung.com>
> Sent: Wednesday, October 25, 2023 9:17 PM
> To: linux-samsung-soc@vger.kernel.org; linux-i2c@vger.kernel.org
> Cc: Marek Szyprowski <m.szyprowski@samsung.com>; Krzysztof Kozlowski
> <krzysztof.kozlowski@linaro.org>; Alim Akhtar <alim.akhtar@samsung.com>;
> Andi Shyti <andi.shyti@kernel.org>; Wolfram Sang <wsa@kernel.org>
> Subject: [PATCH v2 3/3] i2c: s3c24xx: add support for atomic transfers
> 
> 
> Add support for atomic transfers using polling mode with interrupts
> intentionally disabled to get rid of the warning introduced by commit
> 63b96983a5dd ("i2c: core: introduce callbacks for atomic transfers")
> during system reboot and power-off.
> 
> Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>

Reviewed-by: Chanho Park <chanho61.park@samsung.com>

> ---
>  drivers/i2c/busses/i2c-s3c2410.c | 21 +++++++++++++++++++--
>  1 file changed, 19 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-
> s3c2410.c
> index 8da85cb42980..586b82b30bdf 100644
> --- a/drivers/i2c/busses/i2c-s3c2410.c
> +++ b/drivers/i2c/busses/i2c-s3c2410.c
> @@ -76,6 +76,7 @@
>  #define QUIRK_HDMIPHY		(1 << 1)
>  #define QUIRK_NO_GPIO		(1 << 2)
>  #define QUIRK_POLL		(1 << 3)
> +#define QUIRK_ATOMIC		(1 << 4)
> 
>  /* Max time to wait for bus to become idle after a xfer (in us) */
>  #define S3C2410_IDLE_TIMEOUT	5000
> @@ -174,7 +175,7 @@ static inline void s3c24xx_i2c_master_complete(struct
> s3c24xx_i2c *i2c, int ret)
>  	if (ret)
>  		i2c->msg_idx = ret;
> 
> -	if (!(i2c->quirks & QUIRK_POLL))
> +	if (!(i2c->quirks & (QUIRK_POLL | QUIRK_ATOMIC)))
>  		wake_up(&i2c->wait);
>  }
> 
> @@ -700,7 +701,7 @@ static int s3c24xx_i2c_doxfer(struct s3c24xx_i2c *i2c,
>  	s3c24xx_i2c_enable_irq(i2c);
>  	s3c24xx_i2c_message_start(i2c, msgs);
> 
> -	if (i2c->quirks & QUIRK_POLL) {
> +	if (i2c->quirks & (QUIRK_POLL | QUIRK_ATOMIC)) {
>  		while ((i2c->msg_num != 0) && is_ack(i2c)) {
>  			unsigned long stat = readl(i2c->regs +
> S3C2410_IICSTAT);
> 
> @@ -774,6 +775,21 @@ static int s3c24xx_i2c_xfer(struct i2c_adapter *adap,
>  	return -EREMOTEIO;
>  }
> 
> +static int s3c24xx_i2c_xfer_atomic(struct i2c_adapter *adap,
> +				   struct i2c_msg *msgs, int num)
> +{
> +	struct s3c24xx_i2c *i2c = (struct s3c24xx_i2c *)adap->algo_data;
> +	int ret;
> +
> +	disable_irq(i2c->irq);
> +	i2c->quirks |= QUIRK_ATOMIC;
> +	ret = s3c24xx_i2c_xfer(adap, msgs, num);
> +	i2c->quirks &= ~QUIRK_ATOMIC;
> +	enable_irq(i2c->irq);
> +
> +	return ret;
> +}
> +
>  /* declare our i2c functionality */
>  static u32 s3c24xx_i2c_func(struct i2c_adapter *adap)
>  {
> @@ -784,6 +800,7 @@ static u32 s3c24xx_i2c_func(struct i2c_adapter *adap)
>  /* i2c bus registration info */
>  static const struct i2c_algorithm s3c24xx_i2c_algorithm = {
>  	.master_xfer		= s3c24xx_i2c_xfer,
> +	.master_xfer_atomic     = s3c24xx_i2c_xfer_atomic,
>  	.functionality		= s3c24xx_i2c_func,
>  };
> 
> --
> 2.34.1
diff mbox series

Patch

diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
index 8da85cb42980..586b82b30bdf 100644
--- a/drivers/i2c/busses/i2c-s3c2410.c
+++ b/drivers/i2c/busses/i2c-s3c2410.c
@@ -76,6 +76,7 @@ 
 #define QUIRK_HDMIPHY		(1 << 1)
 #define QUIRK_NO_GPIO		(1 << 2)
 #define QUIRK_POLL		(1 << 3)
+#define QUIRK_ATOMIC		(1 << 4)
 
 /* Max time to wait for bus to become idle after a xfer (in us) */
 #define S3C2410_IDLE_TIMEOUT	5000
@@ -174,7 +175,7 @@  static inline void s3c24xx_i2c_master_complete(struct s3c24xx_i2c *i2c, int ret)
 	if (ret)
 		i2c->msg_idx = ret;
 
-	if (!(i2c->quirks & QUIRK_POLL))
+	if (!(i2c->quirks & (QUIRK_POLL | QUIRK_ATOMIC)))
 		wake_up(&i2c->wait);
 }
 
@@ -700,7 +701,7 @@  static int s3c24xx_i2c_doxfer(struct s3c24xx_i2c *i2c,
 	s3c24xx_i2c_enable_irq(i2c);
 	s3c24xx_i2c_message_start(i2c, msgs);
 
-	if (i2c->quirks & QUIRK_POLL) {
+	if (i2c->quirks & (QUIRK_POLL | QUIRK_ATOMIC)) {
 		while ((i2c->msg_num != 0) && is_ack(i2c)) {
 			unsigned long stat = readl(i2c->regs + S3C2410_IICSTAT);
 
@@ -774,6 +775,21 @@  static int s3c24xx_i2c_xfer(struct i2c_adapter *adap,
 	return -EREMOTEIO;
 }
 
+static int s3c24xx_i2c_xfer_atomic(struct i2c_adapter *adap,
+				   struct i2c_msg *msgs, int num)
+{
+	struct s3c24xx_i2c *i2c = (struct s3c24xx_i2c *)adap->algo_data;
+	int ret;
+
+	disable_irq(i2c->irq);
+	i2c->quirks |= QUIRK_ATOMIC;
+	ret = s3c24xx_i2c_xfer(adap, msgs, num);
+	i2c->quirks &= ~QUIRK_ATOMIC;
+	enable_irq(i2c->irq);
+
+	return ret;
+}
+
 /* declare our i2c functionality */
 static u32 s3c24xx_i2c_func(struct i2c_adapter *adap)
 {
@@ -784,6 +800,7 @@  static u32 s3c24xx_i2c_func(struct i2c_adapter *adap)
 /* i2c bus registration info */
 static const struct i2c_algorithm s3c24xx_i2c_algorithm = {
 	.master_xfer		= s3c24xx_i2c_xfer,
+	.master_xfer_atomic     = s3c24xx_i2c_xfer_atomic,
 	.functionality		= s3c24xx_i2c_func,
 };