mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v2] i2c: add pmic_reg_read() for PBL use
@ 2023-12-20 10:47 Bastian Krause
  2023-12-20 11:18 ` Ahmad Fatoum
  2024-01-02  9:15 ` Sascha Hauer
  0 siblings, 2 replies; 5+ messages in thread
From: Bastian Krause @ 2023-12-20 10:47 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum, Bastian Krause

Add a common PMIC read function to PBL which allows easy porting of
U-Boot's pmic_reg_read() in lowlevel board code.

Signed-off-by: Bastian Krause <bst@pengutronix.de>
---
Changes since (implicit) v1:
- make function static inline as suggested by Ahmad
- change void *buf to u32 *val to resemble's U-Boot's pmic_reg_read() as
  suggested by Ahmad
---
 include/pbl/pmic.h | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/include/pbl/pmic.h b/include/pbl/pmic.h
index 0f882c5649d..4eeee31d46c 100644
--- a/include/pbl/pmic.h
+++ b/include/pbl/pmic.h
@@ -9,6 +9,30 @@ struct pmic_config {
 	u8 val;
 };
 
+static inline void pmic_reg_read(struct pbl_i2c *i2c, int addr, u8 reg, u32 *val)
+{
+	int ret;
+	u8 buf[1];
+	struct i2c_msg msg[] = {
+		{
+			.addr = addr,
+			.buf = &reg,
+			.len = 1,
+		}, {
+			.addr = addr,
+			.flags = I2C_M_RD,
+			.buf = buf,
+			.len = 1,
+		},
+	};
+
+	ret = pbl_i2c_xfer(i2c, msg, ARRAY_SIZE(msg));
+	if (ret != ARRAY_SIZE(msg))
+		pr_err("Failed to read from pmic@%x: %d\n", addr, ret);
+
+	*val = buf[0];
+}
+
 static void pmic_reg_write(struct pbl_i2c *i2c, int addr, u8 reg, u8 val)
 {
 	int ret;
-- 
2.39.2




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

* Re: [PATCH v2] i2c: add pmic_reg_read() for PBL use
  2023-12-20 10:47 [PATCH v2] i2c: add pmic_reg_read() for PBL use Bastian Krause
@ 2023-12-20 11:18 ` Ahmad Fatoum
  2024-01-02  9:15 ` Sascha Hauer
  1 sibling, 0 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2023-12-20 11:18 UTC (permalink / raw)
  To: Bastian Krause, barebox

On 20.12.23 11:47, Bastian Krause wrote:
> Add a common PMIC read function to PBL which allows easy porting of
> U-Boot's pmic_reg_read() in lowlevel board code.
> 
> Signed-off-by: Bastian Krause <bst@pengutronix.de>

Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>

> ---
> Changes since (implicit) v1:
> - make function static inline as suggested by Ahmad
> - change void *buf to u32 *val to resemble's U-Boot's pmic_reg_read() as
>   suggested by Ahmad
> ---
>  include/pbl/pmic.h | 24 ++++++++++++++++++++++++
>  1 file changed, 24 insertions(+)
> 
> diff --git a/include/pbl/pmic.h b/include/pbl/pmic.h
> index 0f882c5649d..4eeee31d46c 100644
> --- a/include/pbl/pmic.h
> +++ b/include/pbl/pmic.h
> @@ -9,6 +9,30 @@ struct pmic_config {
>  	u8 val;
>  };
>  
> +static inline void pmic_reg_read(struct pbl_i2c *i2c, int addr, u8 reg, u32 *val)
> +{
> +	int ret;
> +	u8 buf[1];
> +	struct i2c_msg msg[] = {
> +		{
> +			.addr = addr,
> +			.buf = &reg,
> +			.len = 1,
> +		}, {
> +			.addr = addr,
> +			.flags = I2C_M_RD,
> +			.buf = buf,
> +			.len = 1,
> +		},
> +	};
> +
> +	ret = pbl_i2c_xfer(i2c, msg, ARRAY_SIZE(msg));
> +	if (ret != ARRAY_SIZE(msg))
> +		pr_err("Failed to read from pmic@%x: %d\n", addr, ret);
> +
> +	*val = buf[0];
> +}
> +
>  static void pmic_reg_write(struct pbl_i2c *i2c, int addr, u8 reg, u8 val)
>  {
>  	int ret;

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |




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

* Re: [PATCH v2] i2c: add pmic_reg_read() for PBL use
  2023-12-20 10:47 [PATCH v2] i2c: add pmic_reg_read() for PBL use Bastian Krause
  2023-12-20 11:18 ` Ahmad Fatoum
@ 2024-01-02  9:15 ` Sascha Hauer
  2024-01-02 11:32   ` Sascha Hauer
  1 sibling, 1 reply; 5+ messages in thread
From: Sascha Hauer @ 2024-01-02  9:15 UTC (permalink / raw)
  To: Bastian Krause; +Cc: barebox, Ahmad Fatoum

On Wed, Dec 20, 2023 at 11:47:39AM +0100, Bastian Krause wrote:
> Add a common PMIC read function to PBL which allows easy porting of
> U-Boot's pmic_reg_read() in lowlevel board code.
> 
> Signed-off-by: Bastian Krause <bst@pengutronix.de>
> ---
> Changes since (implicit) v1:
> - make function static inline as suggested by Ahmad
> - change void *buf to u32 *val to resemble's U-Boot's pmic_reg_read() as
>   suggested by Ahmad
> ---
>  include/pbl/pmic.h | 24 ++++++++++++++++++++++++
>  1 file changed, 24 insertions(+)
> 
> diff --git a/include/pbl/pmic.h b/include/pbl/pmic.h
> index 0f882c5649d..4eeee31d46c 100644
> --- a/include/pbl/pmic.h
> +++ b/include/pbl/pmic.h
> @@ -9,6 +9,30 @@ struct pmic_config {
>  	u8 val;
>  };
>  
> +static inline void pmic_reg_read(struct pbl_i2c *i2c, int addr, u8 reg, u32 *val)

I didn't notice there is a v2 when replying to v1, so here again:

Why not make *val a u8 *?

Sascha

> +{
> +	int ret;
> +	u8 buf[1];
> +	struct i2c_msg msg[] = {
> +		{
> +			.addr = addr,
> +			.buf = &reg,
> +			.len = 1,
> +		}, {
> +			.addr = addr,
> +			.flags = I2C_M_RD,
> +			.buf = buf,
> +			.len = 1,
> +		},
> +	};
> +
> +	ret = pbl_i2c_xfer(i2c, msg, ARRAY_SIZE(msg));
> +	if (ret != ARRAY_SIZE(msg))
> +		pr_err("Failed to read from pmic@%x: %d\n", addr, ret);
> +
> +	*val = buf[0];
> +}
> +
>  static void pmic_reg_write(struct pbl_i2c *i2c, int addr, u8 reg, u8 val)
>  {
>  	int ret;
> -- 
> 2.39.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



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

* Re: [PATCH v2] i2c: add pmic_reg_read() for PBL use
  2024-01-02  9:15 ` Sascha Hauer
@ 2024-01-02 11:32   ` Sascha Hauer
  2024-01-04 13:11     ` Bastian Krause
  0 siblings, 1 reply; 5+ messages in thread
From: Sascha Hauer @ 2024-01-02 11:32 UTC (permalink / raw)
  To: Bastian Krause; +Cc: barebox, Ahmad Fatoum

On Tue, Jan 02, 2024 at 10:15:38AM +0100, Sascha Hauer wrote:
> On Wed, Dec 20, 2023 at 11:47:39AM +0100, Bastian Krause wrote:
> > Add a common PMIC read function to PBL which allows easy porting of
> > U-Boot's pmic_reg_read() in lowlevel board code.
> > 
> > Signed-off-by: Bastian Krause <bst@pengutronix.de>
> > ---
> > Changes since (implicit) v1:
> > - make function static inline as suggested by Ahmad
> > - change void *buf to u32 *val to resemble's U-Boot's pmic_reg_read() as
> >   suggested by Ahmad
> > ---
> >  include/pbl/pmic.h | 24 ++++++++++++++++++++++++
> >  1 file changed, 24 insertions(+)
> > 
> > diff --git a/include/pbl/pmic.h b/include/pbl/pmic.h
> > index 0f882c5649d..4eeee31d46c 100644
> > --- a/include/pbl/pmic.h
> > +++ b/include/pbl/pmic.h
> > @@ -9,6 +9,30 @@ struct pmic_config {
> >  	u8 val;
> >  };
> >  
> > +static inline void pmic_reg_read(struct pbl_i2c *i2c, int addr, u8 reg, u32 *val)
> 
> I didn't notice there is a v2 when replying to v1, so here again:
> 
> Why not make *val a u8 *?

I renamed this to pmic_reg_read8() and changed the data type to u8 *,
see the patch I just sent.

Sascha

> 
> Sascha
> 
> > +{
> > +	int ret;
> > +	u8 buf[1];
> > +	struct i2c_msg msg[] = {
> > +		{
> > +			.addr = addr,
> > +			.buf = &reg,
> > +			.len = 1,
> > +		}, {
> > +			.addr = addr,
> > +			.flags = I2C_M_RD,
> > +			.buf = buf,
> > +			.len = 1,
> > +		},
> > +	};
> > +
> > +	ret = pbl_i2c_xfer(i2c, msg, ARRAY_SIZE(msg));
> > +	if (ret != ARRAY_SIZE(msg))
> > +		pr_err("Failed to read from pmic@%x: %d\n", addr, ret);
> > +
> > +	*val = buf[0];
> > +}
> > +
> >  static void pmic_reg_write(struct pbl_i2c *i2c, int addr, u8 reg, u8 val)
> >  {
> >  	int ret;
> > -- 
> > 2.39.2
> > 
> > 
> > 
> 
> -- 
> Pengutronix e.K.                           |                             |
> Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
> 31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



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

* Re: [PATCH v2] i2c: add pmic_reg_read() for PBL use
  2024-01-02 11:32   ` Sascha Hauer
@ 2024-01-04 13:11     ` Bastian Krause
  0 siblings, 0 replies; 5+ messages in thread
From: Bastian Krause @ 2024-01-04 13:11 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox, Ahmad Fatoum

On 1/2/24 12:32, Sascha Hauer wrote:
> On Tue, Jan 02, 2024 at 10:15:38AM +0100, Sascha Hauer wrote:
>> On Wed, Dec 20, 2023 at 11:47:39AM +0100, Bastian Krause wrote:
>>> Add a common PMIC read function to PBL which allows easy porting of
>>> U-Boot's pmic_reg_read() in lowlevel board code.
>>>
>>> Signed-off-by: Bastian Krause <bst@pengutronix.de>
>>> ---
>>> Changes since (implicit) v1:
>>> - make function static inline as suggested by Ahmad
>>> - change void *buf to u32 *val to resemble's U-Boot's pmic_reg_read() as
>>>    suggested by Ahmad
>>> ---
>>>   include/pbl/pmic.h | 24 ++++++++++++++++++++++++
>>>   1 file changed, 24 insertions(+)
>>>
>>> diff --git a/include/pbl/pmic.h b/include/pbl/pmic.h
>>> index 0f882c5649d..4eeee31d46c 100644
>>> --- a/include/pbl/pmic.h
>>> +++ b/include/pbl/pmic.h
>>> @@ -9,6 +9,30 @@ struct pmic_config {
>>>   	u8 val;
>>>   };
>>>   
>>> +static inline void pmic_reg_read(struct pbl_i2c *i2c, int addr, u8 reg, u32 *val)
>>
>> I didn't notice there is a v2 when replying to v1, so here again:
>>
>> Why not make *val a u8 *?
> 
> I renamed this to pmic_reg_read8() and changed the data type to u8 *,
> see the patch I just sent.

Works for me, thanks!

Bastian

> 
> Sascha
> 
>>
>> Sascha
>>
>>> +{
>>> +	int ret;
>>> +	u8 buf[1];
>>> +	struct i2c_msg msg[] = {
>>> +		{
>>> +			.addr = addr,
>>> +			.buf = &reg,
>>> +			.len = 1,
>>> +		}, {
>>> +			.addr = addr,
>>> +			.flags = I2C_M_RD,
>>> +			.buf = buf,
>>> +			.len = 1,
>>> +		},
>>> +	};
>>> +
>>> +	ret = pbl_i2c_xfer(i2c, msg, ARRAY_SIZE(msg));
>>> +	if (ret != ARRAY_SIZE(msg))
>>> +		pr_err("Failed to read from pmic@%x: %d\n", addr, ret);
>>> +
>>> +	*val = buf[0];
>>> +}
>>> +
>>>   static void pmic_reg_write(struct pbl_i2c *i2c, int addr, u8 reg, u8 val)
>>>   {
>>>   	int ret;
>>> -- 
>>> 2.39.2
>>>
>>>
>>>
>>
>> -- 
>> Pengutronix e.K.                           |                             |
>> Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
>> 31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
>> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
>>
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |




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

end of thread, other threads:[~2024-01-04 13:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-20 10:47 [PATCH v2] i2c: add pmic_reg_read() for PBL use Bastian Krause
2023-12-20 11:18 ` Ahmad Fatoum
2024-01-02  9:15 ` Sascha Hauer
2024-01-02 11:32   ` Sascha Hauer
2024-01-04 13:11     ` Bastian Krause

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox