Re: [PATCH net-next v3 1/2] net: phy: sfp: Add support for SMBus module access
From: Paolo Abeni
Date: Fri Mar 21 2025 - 13:51:17 EST
On 3/14/25 5:23 PM, Maxime Chevallier wrote:
> @@ -691,14 +692,71 @@ static int sfp_i2c_write(struct sfp *sfp, bool a2, u8 dev_addr, void *buf,
> return ret == ARRAY_SIZE(msgs) ? len : 0;
> }
>
> -static int sfp_i2c_configure(struct sfp *sfp, struct i2c_adapter *i2c)
> +static int sfp_smbus_byte_read(struct sfp *sfp, bool a2, u8 dev_addr,
> + void *buf, size_t len)
> {
> - if (!i2c_check_functionality(i2c, I2C_FUNC_I2C))
> - return -EINVAL;
> + u8 bus_addr = a2 ? 0x51 : 0x50;
> + union i2c_smbus_data smbus_data;
Minor nit: please respect the reverse christmas tree order above.
> + u8 *data = buf;
> + int ret;
> +
> + while (len) {
> + ret = i2c_smbus_xfer(sfp->i2c, bus_addr, 0,
> + I2C_SMBUS_READ, dev_addr,
> + I2C_SMBUS_BYTE_DATA, &smbus_data);
> + if (ret < 0)
> + return ret;
> +
> + *data = smbus_data.byte;
> +
> + len--;
> + data++;
> + dev_addr++;
> + }
> +
> + return data - (u8 *)buf;
> +}
> +
> +static int sfp_smbus_byte_write(struct sfp *sfp, bool a2, u8 dev_addr,
> + void *buf, size_t len)
> +{
> + u8 bus_addr = a2 ? 0x51 : 0x50;
> + union i2c_smbus_data smbus_data;
same here.
Thanks,
Paolo