diff mbox series

[1/2] media: max9271: Fix GPIO enable/disable

Message ID 20201120161529.236447-2-jacopo+renesas@jmondi.org
State Accepted
Commit 909a0a189c677307edd461e21fd962784370d27f
Headers show
Series media: max9271: Fix GPIO handling | expand

Commit Message

Jacopo Mondi Nov. 20, 2020, 4:15 p.m. UTC
Fix GPIO enable/disable operations which wrongly read the 0x0f register
to obtain the current mask of the enabled lines instead of using
the correct 0x0e register.

Also fix access to bit 0 of the register which is marked as reserved.

Fixes: 34009bffc1c6 ("media: i2c: Add RDACM20 driver")
Signed-off-by: Jacopo Mondi <jacopo+renesas@jmondi.org>
---
 drivers/media/i2c/max9271.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Kieran Bingham Nov. 23, 2020, 2:14 p.m. UTC | #1
Hi Jacopo,

On 20/11/2020 16:15, Jacopo Mondi wrote:
> Fix GPIO enable/disable operations which wrongly read the 0x0f register

> to obtain the current mask of the enabled lines instead of using

> the correct 0x0e register.

> 

> Also fix access to bit 0 of the register which is marked as reserved.

> 

> Fixes: 34009bffc1c6 ("media: i2c: Add RDACM20 driver")

> Signed-off-by: Jacopo Mondi <jacopo+renesas@jmondi.org>


Took me a few reads of this and the datasheet to be sure :S

But now I am :-D

Reviewed-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>


> ---

>  drivers/media/i2c/max9271.c | 8 ++++----

>  1 file changed, 4 insertions(+), 4 deletions(-)

> 

> diff --git a/drivers/media/i2c/max9271.c b/drivers/media/i2c/max9271.c

> index 0f6f7a092a46..c247db569bab 100644

> --- a/drivers/media/i2c/max9271.c

> +++ b/drivers/media/i2c/max9271.c

> @@ -223,12 +223,12 @@ int max9271_enable_gpios(struct max9271_device *dev, u8 gpio_mask)

>  {

>  	int ret;

>  

> -	ret = max9271_read(dev, 0x0f);

> +	ret = max9271_read(dev, 0x0e);

>  	if (ret < 0)

>  		return 0;

>  

>  	/* BIT(0) reserved: GPO is always enabled. */

> -	ret |= gpio_mask | BIT(0);

> +	ret |= (gpio_mask & ~BIT(0));

>  	ret = max9271_write(dev, 0x0e, ret);

>  	if (ret < 0) {

>  		dev_err(&dev->client->dev, "Failed to enable gpio (%d)\n", ret);

> @@ -245,12 +245,12 @@ int max9271_disable_gpios(struct max9271_device *dev, u8 gpio_mask)

>  {

>  	int ret;

>  

> -	ret = max9271_read(dev, 0x0f);

> +	ret = max9271_read(dev, 0x0e);

>  	if (ret < 0)

>  		return 0;

>  

>  	/* BIT(0) reserved: GPO cannot be disabled */

> -	ret &= (~gpio_mask | BIT(0));

> +	ret &= ~(gpio_mask | BIT(0));

>  	ret = max9271_write(dev, 0x0e, ret);

>  	if (ret < 0) {

>  		dev_err(&dev->client->dev, "Failed to disable gpio (%d)\n", ret);

>
Sergei Shtylyov Nov. 23, 2020, 3:59 p.m. UTC | #2
On 11/20/20 7:15 PM, Jacopo Mondi wrote:

> Fix GPIO enable/disable operations which wrongly read the 0x0f register

> to obtain the current mask of the enabled lines instead of using

> the correct 0x0e register.

> 

> Also fix access to bit 0 of the register which is marked as reserved.

> 

> Fixes: 34009bffc1c6 ("media: i2c: Add RDACM20 driver")

> Signed-off-by: Jacopo Mondi <jacopo+renesas@jmondi.org>

> ---

>  drivers/media/i2c/max9271.c | 8 ++++----

>  1 file changed, 4 insertions(+), 4 deletions(-)

> 

> diff --git a/drivers/media/i2c/max9271.c b/drivers/media/i2c/max9271.c

> index 0f6f7a092a46..c247db569bab 100644

> --- a/drivers/media/i2c/max9271.c

> +++ b/drivers/media/i2c/max9271.c

> @@ -223,12 +223,12 @@ int max9271_enable_gpios(struct max9271_device *dev, u8 gpio_mask)

>  {

>  	int ret;

>  

> -	ret = max9271_read(dev, 0x0f);

> +	ret = max9271_read(dev, 0x0e);

>  	if (ret < 0)

>  		return 0;

>  

>  	/* BIT(0) reserved: GPO is always enabled. */

> -	ret |= gpio_mask | BIT(0);

> +	ret |= (gpio_mask & ~BIT(0));


   () hardly needed here, = and <op>= have very low prio...

[...]

MBR, Sergei
diff mbox series

Patch

diff --git a/drivers/media/i2c/max9271.c b/drivers/media/i2c/max9271.c
index 0f6f7a092a46..c247db569bab 100644
--- a/drivers/media/i2c/max9271.c
+++ b/drivers/media/i2c/max9271.c
@@ -223,12 +223,12 @@  int max9271_enable_gpios(struct max9271_device *dev, u8 gpio_mask)
 {
 	int ret;
 
-	ret = max9271_read(dev, 0x0f);
+	ret = max9271_read(dev, 0x0e);
 	if (ret < 0)
 		return 0;
 
 	/* BIT(0) reserved: GPO is always enabled. */
-	ret |= gpio_mask | BIT(0);
+	ret |= (gpio_mask & ~BIT(0));
 	ret = max9271_write(dev, 0x0e, ret);
 	if (ret < 0) {
 		dev_err(&dev->client->dev, "Failed to enable gpio (%d)\n", ret);
@@ -245,12 +245,12 @@  int max9271_disable_gpios(struct max9271_device *dev, u8 gpio_mask)
 {
 	int ret;
 
-	ret = max9271_read(dev, 0x0f);
+	ret = max9271_read(dev, 0x0e);
 	if (ret < 0)
 		return 0;
 
 	/* BIT(0) reserved: GPO cannot be disabled */
-	ret &= (~gpio_mask | BIT(0));
+	ret &= ~(gpio_mask | BIT(0));
 	ret = max9271_write(dev, 0x0e, ret);
 	if (ret < 0) {
 		dev_err(&dev->client->dev, "Failed to disable gpio (%d)\n", ret);