// SPDX-License-Identifier: GPL-2.0 /* * Copyright (C) KEBA Industrial Automation Gmbh 2024 * * Driver for LAN9252 on KEBA CP500 devices * * This driver is used for updating the configuration of the LAN9252 controller * on KEBA CP500 devices. The LAN9252 is connected over SPI, which is also named * PDI.
*/
/* wait while CSR command is busy */ for (;;) {
ret = lan9252_spi_read(spi, LAN9252_ECAT_CSR_CMD, &data); if (ret) return ret; if (!(data & LAN9252_ECAT_CSR_BUSY)) return 0;
if (ktime_compare(ktime_get(), timeout) > 0) {
ret = lan9252_spi_read(spi, LAN9252_ECAT_CSR_CMD, &data); if (ret) return ret; break;
}
}
/* wait while MII control state machine is busy */ for (;;) {
ret = lan9252_esc_read(spi, LAN9252_ESC_MII, &data); if (ret) return ret; if (data & LAN9252_ESC_MII_ERR_MASK) return -EIO; if (!(data & LAN9252_ESC_MII_BUSY)) return 0;
if (ktime_compare(ktime_get(), timeout) > 0) {
ret = lan9252_esc_read(spi, LAN9252_ESC_MII, &data); if (ret) return ret; if (data & LAN9252_ESC_MII_ERR_MASK) return -EIO; break;
}
}
ret = lan9252_esc_write(spi, LAN9252_ESC_PHY_ADDR, phy_addr); if (ret) return ret;
ret = lan9252_esc_write(spi, LAN9252_ESC_PHY_REG_ADDR, reg_addr); if (ret) return ret;
ret = lan9252_esc_write(spi, LAN9252_ESC_MII, LAN9252_ESC_MII_READ); if (ret) return ret;
ret = lan9252_esc_write(spi, LAN9252_ESC_PHY_ADDR, phy_addr); if (ret) return ret;
ret = lan9252_esc_write(spi, LAN9252_ESC_PHY_REG_ADDR, reg_addr); if (ret) return ret;
ret = lan9252_esc_write(spi, LAN9252_ESC_PHY_DATA, data); if (ret) return ret;
ret = lan9252_esc_write(spi, LAN9252_ESC_MII, LAN9252_ESC_MII_WRITE); if (ret) return ret;
return lan9252_mii_wait(spi);
}
staticint lan9252_probe(struct spi_device *spi)
{
u32 data; int retry = SPI_RETRY_COUNT; int ret;
/* enable access to MII management for PDI */
ret = lan9252_access_mii(spi, true); if (ret) {
dev_err(&spi->dev, "Can't enable access to MII management!"); return ret;
}
/* * check PHY configuration and configure if necessary * - full duplex * - auto negotiation disabled * - 100 Mbps
*/
ret = lan9252_mii_read(spi, PHY_ADDRESS, MII_BMCR, &data); if (ret) {
dev_err(&spi->dev, "Can't read LAN9252 configuration!"); goto out;
} if (!(data & BMCR_FULLDPLX) || (data & BMCR_ANENABLE) ||
!(data & BMCR_SPEED100)) { /*
*/
data &= ~(BMCR_ANENABLE);
data |= (BMCR_FULLDPLX | BMCR_SPEED100);
ret = lan9252_mii_write(spi, PHY_ADDRESS, MII_BMCR, data); if (ret)
dev_err(&spi->dev, "Can't write LAN9252 configuration!");
}
dev_info(&spi->dev, "LAN9252 PHY configuration");
out: /* disable access to MII management for PDI */
lan9252_access_mii(spi, false);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.