[PATCH 1/3] i2c: add <pbl/eeprom.h> for PBL use

Sascha Hauer sha at pengutronix.de
Tue Jun 6 04:21:48 PDT 2023


On Tue, Jun 06, 2023 at 12:50:02PM +0200, Marc Kleine-Budde wrote:
> Add a small helper to read a single page of EEPROM data.
> 
> Signed-off-by: Marc Kleine-Budde <mkl at pengutronix.de>
> ---
>  include/pbl/eeprom.h | 34 ++++++++++++++++++++++++++++++++++
>  1 file changed, 34 insertions(+)
> 
> diff --git a/include/pbl/eeprom.h b/include/pbl/eeprom.h
> new file mode 100644
> index 000000000000..b713cf154c99
> --- /dev/null
> +++ b/include/pbl/eeprom.h
> @@ -0,0 +1,34 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +#ifndef __PBL_EEPROM_H_
> +#define __PBL_EEPROM_H_
> +
> +#include <common.h>
> +#include <pbl/i2c.h>
> +
> +static inline void eeprom_read(struct pbl_i2c *i2c, u16 client_addr, u32 addr, void *buf, u16 count)
> +{
> +	u8 msgbuf[2];
> +	struct i2c_msg msg[] = {
> +		{
> +			.addr = client_addr,
> +			.buf = msgbuf,
> +		}, {
> +			.addr = client_addr,
> +			.flags = I2C_M_RD,
> +			.buf = buf,
> +			.len = count,
> +		},
> +	};
> +	int ret, i = 0;
> +
> +	if (addr & I2C_ADDR_16_BIT)
> +		msgbuf[i++] = addr >> 8;
> +	msgbuf[i++] = addr;
> +	msg->len = i;

I wasn't aware that an array can be accessed as a pointer. I would
prefer msg[0].len = i here.

Sascha

-- 
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 |



More information about the barebox mailing list