diff mbox series

[1/2] power: twl4030: Add twl4030_i2c_read() function

Message ID 20201026213616.20816-1-pali@kernel.org
State Accepted
Commit 4fcc084eeb8cd7db77263672c6a43da629a4ed48
Delegated to: Lokesh Vutla
Headers show
Series [1/2] power: twl4030: Add twl4030_i2c_read() function | expand

Commit Message

Pali Rohár Oct. 26, 2020, 9:36 p.m. UTC
Function twl4030_i2c_read() is like twl4030_i2c_read_u8() but instead of
single value it rather returns array of values.

Signed-off-by: Pali Rohár <pali@kernel.org>
---
 drivers/power/twl4030.c |  7 +++----
 include/twl4030.h       | 12 +++++++++---
 2 files changed, 12 insertions(+), 7 deletions(-)

Comments

Jaehoon Chung Oct. 27, 2020, 9:45 p.m. UTC | #1
Hi,

On 10/27/20 6:36 AM, Pali Rohár wrote:
> Function twl4030_i2c_read() is like twl4030_i2c_read_u8() but instead of
> single value it rather returns array of values.

Just minor comment.
Is there a reason not to touch twl4030_i2c_write_u8()?

Best Regards,
Jaehoon Chung

> 
> Signed-off-by: Pali Rohár <pali@kernel.org>
> ---
>  drivers/power/twl4030.c |  7 +++----
>  include/twl4030.h       | 12 +++++++++---
>  2 files changed, 12 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/power/twl4030.c b/drivers/power/twl4030.c
> index b0d5cba2c4..f48af84e17 100644
> --- a/drivers/power/twl4030.c
> +++ b/drivers/power/twl4030.c
> @@ -201,7 +201,7 @@ int twl4030_i2c_write_u8(u8 chip_no, u8 reg, u8 val)
>  	return 0;
>  }
>  
> -int twl4030_i2c_read_u8(u8 chip_no, u8 reg, u8 *valp)
> +int twl4030_i2c_read(u8 chip_no, u8 reg, u8 *valp, int len)
>  {
>  	struct udevice *dev;
>  	int ret;
> @@ -211,12 +211,11 @@ int twl4030_i2c_read_u8(u8 chip_no, u8 reg, u8 *valp)
>  		pr_err("unable to get I2C bus. ret %d\n", ret);
>  		return ret;
>  	}
> -	ret = dm_i2c_reg_read(dev, reg);
> -	if (ret < 0) {
> +	ret = dm_i2c_read(dev, reg, valp, len);
> +	if (ret) {
>  		pr_err("reading from twl4030 failed. ret %d\n", ret);
>  		return ret;
>  	}
> -	*valp = (u8)ret;
>  	return 0;
>  }
>  #endif
> diff --git a/include/twl4030.h b/include/twl4030.h
> index c27ad615ee..ef05193996 100644
> --- a/include/twl4030.h
> +++ b/include/twl4030.h
> @@ -654,14 +654,20 @@ static inline int twl4030_i2c_write_u8(u8 chip_no, u8 reg, u8 val)
>  	return i2c_write(chip_no, reg, 1, &val, 1);
>  }
>  
> -static inline int twl4030_i2c_read_u8(u8 chip_no, u8 reg, u8 *val)
> +static inline int twl4030_i2c_read(u8 chip_no, u8 reg, u8 *val, int len)
>  {
> -	return i2c_read(chip_no, reg, 1, val, 1);
> +	return i2c_read(chip_no, reg, 1, val, len);
>  }
>  #else
>  int twl4030_i2c_write_u8(u8 chip_no, u8 reg, u8 val);
> -int twl4030_i2c_read_u8(u8 chip_no, u8 reg, u8 *val);
> +int twl4030_i2c_read(u8 chip_no, u8 reg, u8 *val, int len);
>  #endif
> +
> +static inline int twl4030_i2c_read_u8(u8 chip_no, u8 reg, u8 *val)
> +{
> +	return twl4030_i2c_read(chip_no, reg, val, 1);
> +}
> +
>  /*
>   * Power
>   */
>
Pali Rohár Oct. 27, 2020, 9:57 p.m. UTC | #2
On Wednesday 28 October 2020 06:45:51 Jaehoon Chung wrote:
> Hi,
> 
> On 10/27/20 6:36 AM, Pali Rohár wrote:
> > Function twl4030_i2c_read() is like twl4030_i2c_read_u8() but instead of
> > single value it rather returns array of values.
> 
> Just minor comment.
> Is there a reason not to touch twl4030_i2c_write_u8()?

Well, it is because I have no usage for twl4030_i2c_write() yet. So I have
not touched write functions.

This new twl4030_i2c_read() function is used in PATCH 2/2.

> Best Regards,
> Jaehoon Chung
> 
> > 
> > Signed-off-by: Pali Rohár <pali@kernel.org>
> > ---
> >  drivers/power/twl4030.c |  7 +++----
> >  include/twl4030.h       | 12 +++++++++---
> >  2 files changed, 12 insertions(+), 7 deletions(-)
> > 
> > diff --git a/drivers/power/twl4030.c b/drivers/power/twl4030.c
> > index b0d5cba2c4..f48af84e17 100644
> > --- a/drivers/power/twl4030.c
> > +++ b/drivers/power/twl4030.c
> > @@ -201,7 +201,7 @@ int twl4030_i2c_write_u8(u8 chip_no, u8 reg, u8 val)
> >  	return 0;
> >  }
> >  
> > -int twl4030_i2c_read_u8(u8 chip_no, u8 reg, u8 *valp)
> > +int twl4030_i2c_read(u8 chip_no, u8 reg, u8 *valp, int len)
> >  {
> >  	struct udevice *dev;
> >  	int ret;
> > @@ -211,12 +211,11 @@ int twl4030_i2c_read_u8(u8 chip_no, u8 reg, u8 *valp)
> >  		pr_err("unable to get I2C bus. ret %d\n", ret);
> >  		return ret;
> >  	}
> > -	ret = dm_i2c_reg_read(dev, reg);
> > -	if (ret < 0) {
> > +	ret = dm_i2c_read(dev, reg, valp, len);
> > +	if (ret) {
> >  		pr_err("reading from twl4030 failed. ret %d\n", ret);
> >  		return ret;
> >  	}
> > -	*valp = (u8)ret;
> >  	return 0;
> >  }
> >  #endif
> > diff --git a/include/twl4030.h b/include/twl4030.h
> > index c27ad615ee..ef05193996 100644
> > --- a/include/twl4030.h
> > +++ b/include/twl4030.h
> > @@ -654,14 +654,20 @@ static inline int twl4030_i2c_write_u8(u8 chip_no, u8 reg, u8 val)
> >  	return i2c_write(chip_no, reg, 1, &val, 1);
> >  }
> >  
> > -static inline int twl4030_i2c_read_u8(u8 chip_no, u8 reg, u8 *val)
> > +static inline int twl4030_i2c_read(u8 chip_no, u8 reg, u8 *val, int len)
> >  {
> > -	return i2c_read(chip_no, reg, 1, val, 1);
> > +	return i2c_read(chip_no, reg, 1, val, len);
> >  }
> >  #else
> >  int twl4030_i2c_write_u8(u8 chip_no, u8 reg, u8 val);
> > -int twl4030_i2c_read_u8(u8 chip_no, u8 reg, u8 *val);
> > +int twl4030_i2c_read(u8 chip_no, u8 reg, u8 *val, int len);
> >  #endif
> > +
> > +static inline int twl4030_i2c_read_u8(u8 chip_no, u8 reg, u8 *val)
> > +{
> > +	return twl4030_i2c_read(chip_no, reg, val, 1);
> > +}
> > +
> >  /*
> >   * Power
> >   */
> > 
>
Jaehoon Chung Oct. 27, 2020, 10:56 p.m. UTC | #3
On 10/28/20 6:57 AM, Pali Rohár wrote:
> On Wednesday 28 October 2020 06:45:51 Jaehoon Chung wrote:
>> Hi,
>>
>> On 10/27/20 6:36 AM, Pali Rohár wrote:
>>> Function twl4030_i2c_read() is like twl4030_i2c_read_u8() but instead of
>>> single value it rather returns array of values.
>>
>> Just minor comment.
>> Is there a reason not to touch twl4030_i2c_write_u8()?
> 
> Well, it is because I have no usage for twl4030_i2c_write() yet. So I have
> not touched write functions.
> 
> This new twl4030_i2c_read() function is used in PATCH 2/2.
> 
>> Best Regards,
>> Jaehoon Chung
>>
>>>
>>> Signed-off-by: Pali Rohár <pali@kernel.org>

Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

Best Regards,
Jaehoon Chung

>>> ---
>>>  drivers/power/twl4030.c |  7 +++----
>>>  include/twl4030.h       | 12 +++++++++---
>>>  2 files changed, 12 insertions(+), 7 deletions(-)
>>>
>>> diff --git a/drivers/power/twl4030.c b/drivers/power/twl4030.c
>>> index b0d5cba2c4..f48af84e17 100644
>>> --- a/drivers/power/twl4030.c
>>> +++ b/drivers/power/twl4030.c
>>> @@ -201,7 +201,7 @@ int twl4030_i2c_write_u8(u8 chip_no, u8 reg, u8 val)
>>>  	return 0;
>>>  }
>>>  
>>> -int twl4030_i2c_read_u8(u8 chip_no, u8 reg, u8 *valp)
>>> +int twl4030_i2c_read(u8 chip_no, u8 reg, u8 *valp, int len)
>>>  {
>>>  	struct udevice *dev;
>>>  	int ret;
>>> @@ -211,12 +211,11 @@ int twl4030_i2c_read_u8(u8 chip_no, u8 reg, u8 *valp)
>>>  		pr_err("unable to get I2C bus. ret %d\n", ret);
>>>  		return ret;
>>>  	}
>>> -	ret = dm_i2c_reg_read(dev, reg);
>>> -	if (ret < 0) {
>>> +	ret = dm_i2c_read(dev, reg, valp, len);
>>> +	if (ret) {
>>>  		pr_err("reading from twl4030 failed. ret %d\n", ret);
>>>  		return ret;
>>>  	}
>>> -	*valp = (u8)ret;
>>>  	return 0;
>>>  }
>>>  #endif
>>> diff --git a/include/twl4030.h b/include/twl4030.h
>>> index c27ad615ee..ef05193996 100644
>>> --- a/include/twl4030.h
>>> +++ b/include/twl4030.h
>>> @@ -654,14 +654,20 @@ static inline int twl4030_i2c_write_u8(u8 chip_no, u8 reg, u8 val)
>>>  	return i2c_write(chip_no, reg, 1, &val, 1);
>>>  }
>>>  
>>> -static inline int twl4030_i2c_read_u8(u8 chip_no, u8 reg, u8 *val)
>>> +static inline int twl4030_i2c_read(u8 chip_no, u8 reg, u8 *val, int len)
>>>  {
>>> -	return i2c_read(chip_no, reg, 1, val, 1);
>>> +	return i2c_read(chip_no, reg, 1, val, len);
>>>  }
>>>  #else
>>>  int twl4030_i2c_write_u8(u8 chip_no, u8 reg, u8 val);
>>> -int twl4030_i2c_read_u8(u8 chip_no, u8 reg, u8 *val);
>>> +int twl4030_i2c_read(u8 chip_no, u8 reg, u8 *val, int len);
>>>  #endif
>>> +
>>> +static inline int twl4030_i2c_read_u8(u8 chip_no, u8 reg, u8 *val)
>>> +{
>>> +	return twl4030_i2c_read(chip_no, reg, val, 1);
>>> +}
>>> +
>>>  /*
>>>   * Power
>>>   */
>>>
>>
>
diff mbox series

Patch

diff --git a/drivers/power/twl4030.c b/drivers/power/twl4030.c
index b0d5cba2c4..f48af84e17 100644
--- a/drivers/power/twl4030.c
+++ b/drivers/power/twl4030.c
@@ -201,7 +201,7 @@  int twl4030_i2c_write_u8(u8 chip_no, u8 reg, u8 val)
 	return 0;
 }
 
-int twl4030_i2c_read_u8(u8 chip_no, u8 reg, u8 *valp)
+int twl4030_i2c_read(u8 chip_no, u8 reg, u8 *valp, int len)
 {
 	struct udevice *dev;
 	int ret;
@@ -211,12 +211,11 @@  int twl4030_i2c_read_u8(u8 chip_no, u8 reg, u8 *valp)
 		pr_err("unable to get I2C bus. ret %d\n", ret);
 		return ret;
 	}
-	ret = dm_i2c_reg_read(dev, reg);
-	if (ret < 0) {
+	ret = dm_i2c_read(dev, reg, valp, len);
+	if (ret) {
 		pr_err("reading from twl4030 failed. ret %d\n", ret);
 		return ret;
 	}
-	*valp = (u8)ret;
 	return 0;
 }
 #endif
diff --git a/include/twl4030.h b/include/twl4030.h
index c27ad615ee..ef05193996 100644
--- a/include/twl4030.h
+++ b/include/twl4030.h
@@ -654,14 +654,20 @@  static inline int twl4030_i2c_write_u8(u8 chip_no, u8 reg, u8 val)
 	return i2c_write(chip_no, reg, 1, &val, 1);
 }
 
-static inline int twl4030_i2c_read_u8(u8 chip_no, u8 reg, u8 *val)
+static inline int twl4030_i2c_read(u8 chip_no, u8 reg, u8 *val, int len)
 {
-	return i2c_read(chip_no, reg, 1, val, 1);
+	return i2c_read(chip_no, reg, 1, val, len);
 }
 #else
 int twl4030_i2c_write_u8(u8 chip_no, u8 reg, u8 val);
-int twl4030_i2c_read_u8(u8 chip_no, u8 reg, u8 *val);
+int twl4030_i2c_read(u8 chip_no, u8 reg, u8 *val, int len);
 #endif
+
+static inline int twl4030_i2c_read_u8(u8 chip_no, u8 reg, u8 *val)
+{
+	return twl4030_i2c_read(chip_no, reg, val, 1);
+}
+
 /*
  * Power
  */