Skip to content

Commit 0b0e299

Browse files
vladimirolteandavem330
authored andcommitted
net: dsa: sja1105: use detected device id instead of DT one on mismatch
Although we can detect the chip revision 100% at runtime, it is useful to specify it in the device tree compatible string too, because otherwise there would be no way to assess the correctness of device tree bindings statically, without booting a board (only some switch versions have internal RGMII delays and/or an SGMII port). But for testing the P/Q/R/S support, what I have is a reworked board with the SJA1105T replaced by a pin-compatible SJA1105Q, and I don't want to keep a separate device tree blob just for this one-off board. Since just the chip has been replaced, its RGMII delay setup is inherently the same (meaning: delays added by the PHY on the slave ports, and by PCB traces on the fixed-link CPU port). For this board, I'd rather have the driver shout at me, but go ahead and use what it found even if it doesn't match what it's been told is there. [ 2.970826] sja1105 spi0.1: Device tree specifies chip SJA1105T but found SJA1105Q, please fix it! [ 2.980010] sja1105 spi0.1: Probed switch chip: SJA1105Q [ 3.005082] sja1105 spi0.1: Enabled switch tagging Signed-off-by: Vladimir Oltean <[email protected]> Reviewed-by: Florian Fainelli <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 273d405 commit 0b0e299

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

drivers/net/dsa/sja1105/sja1105_main.c

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3391,11 +3391,14 @@ static const struct dsa_switch_ops sja1105_switch_ops = {
33913391
.devlink_param_set = sja1105_devlink_param_set,
33923392
};
33933393

3394+
static const struct of_device_id sja1105_dt_ids[];
3395+
33943396
static int sja1105_check_device_id(struct sja1105_private *priv)
33953397
{
33963398
const struct sja1105_regs *regs = priv->info->regs;
33973399
u8 prod_id[SJA1105_SIZE_DEVICE_ID] = {0};
33983400
struct device *dev = &priv->spidev->dev;
3401+
const struct of_device_id *match;
33993402
u32 device_id;
34003403
u64 part_no;
34013404
int rc;
@@ -3405,26 +3408,36 @@ static int sja1105_check_device_id(struct sja1105_private *priv)
34053408
if (rc < 0)
34063409
return rc;
34073410

3408-
if (device_id != priv->info->device_id) {
3409-
dev_err(dev, "Expected device ID 0x%llx but read 0x%x\n",
3410-
priv->info->device_id, device_id);
3411-
return -ENODEV;
3412-
}
3413-
34143411
rc = sja1105_xfer_buf(priv, SPI_READ, regs->prod_id, prod_id,
34153412
SJA1105_SIZE_DEVICE_ID);
34163413
if (rc < 0)
34173414
return rc;
34183415

34193416
sja1105_unpack(prod_id, &part_no, 19, 4, SJA1105_SIZE_DEVICE_ID);
34203417

3421-
if (part_no != priv->info->part_no) {
3422-
dev_err(dev, "Expected part number 0x%llx but read 0x%llx\n",
3423-
priv->info->part_no, part_no);
3424-
return -ENODEV;
3418+
for (match = sja1105_dt_ids; match->compatible; match++) {
3419+
const struct sja1105_info *info = match->data;
3420+
3421+
/* Is what's been probed in our match table at all? */
3422+
if (info->device_id != device_id || info->part_no != part_no)
3423+
continue;
3424+
3425+
/* But is it what's in the device tree? */
3426+
if (priv->info->device_id != device_id ||
3427+
priv->info->part_no != part_no) {
3428+
dev_warn(dev, "Device tree specifies chip %s but found %s, please fix it!\n",
3429+
priv->info->name, info->name);
3430+
/* It isn't. No problem, pick that up. */
3431+
priv->info = info;
3432+
}
3433+
3434+
return 0;
34253435
}
34263436

3427-
return 0;
3437+
dev_err(dev, "Unexpected {device ID, part number}: 0x%x 0x%llx\n",
3438+
device_id, part_no);
3439+
3440+
return -ENODEV;
34283441
}
34293442

34303443
static int sja1105_probe(struct spi_device *spi)

0 commit comments

Comments
 (0)