mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <sha@pengutronix.de>
To: Bastian Krause <bst@pengutronix.de>
Cc: barebox@lists.infradead.org, Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: Re: [PATCH v2] i2c: add pmic_reg_read() for PBL use
Date: Tue, 2 Jan 2024 10:15:38 +0100	[thread overview]
Message-ID: <20240102091538.GW1318922@pengutronix.de> (raw)
In-Reply-To: <20231220104739.10700-1-bst@pengutronix.de>

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 |



  parent reply	other threads:[~2024-01-02  9:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-20 10:47 Bastian Krause
2023-12-20 11:18 ` Ahmad Fatoum
2024-01-02  9:15 ` Sascha Hauer [this message]
2024-01-02 11:32   ` Sascha Hauer
2024-01-04 13:11     ` Bastian Krause

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240102091538.GW1318922@pengutronix.de \
    --to=sha@pengutronix.de \
    --cc=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=bst@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox