From: Romain Naour Date: Tue, 8 Oct 2024 07:54:28 +0000 (+0200) Subject: net: ksz9477: set i2c bus offset length only when needed X-Git-Url: http://git.dujemihanovic.xyz/html/static/git-favicon.png?a=commitdiff_plain;h=b507f1a5077f8589df000e32715978b8f43a02b6;p=u-boot.git net: ksz9477: set i2c bus offset length only when needed In order to add ksz9477 SPI bus support, check parent bus is an I2C bus before calling i2c_set_offset_len(). Doing so, ksz_i2c_probe() will now return an error (-EINVAL) if the parent bus is not the one expected by the ksz-switch u-boot driver. Indeed, the DSA KSZ devicetree binding doesn't specify anything about the underlying bus between the SoC and the DSA switch, so the same "compatible" string can be used wathever the management interface used (SPI or I2C). The ksz-switch u-boot driver currently only support I2C interface but will match a compatible "microchip,ksz9xxx" located under under an SPI bus node. Signed-off-by: Romain Naour --- diff --git a/drivers/net/ksz9477.c b/drivers/net/ksz9477.c index 3756f48c9b..ce9d4b8753 100644 --- a/drivers/net/ksz9477.c +++ b/drivers/net/ksz9477.c @@ -510,14 +510,25 @@ static int ksz_i2c_probe(struct udevice *dev) { struct dsa_pdata *pdata = dev_get_uclass_plat(dev); struct ksz_dsa_priv *priv = dev_get_priv(dev); + enum uclass_id parent_id = UCLASS_INVALID; int i, ret; u8 data8; u32 id; - ret = i2c_set_chip_offset_len(dev, 2); - if (ret) { - printf("i2c_set_chip_offset_len failed: %d\n", ret); - return ret; + parent_id = device_get_uclass_id(dev_get_parent(dev)); + switch (parent_id) { + case UCLASS_I2C: { + ret = i2c_set_chip_offset_len(dev, 2); + if (ret) { + printf("i2c_set_chip_offset_len failed: %d\n", ret); + return ret; + } + break; + } + default: + dev_err(dev, "invalid parent bus (%s)\n", + uclass_get_name(parent_id)); + return -EINVAL; } /* default config */