Merge tag 'u-boot-stm32-20211012' of https://source.denx.de/u-boot/custodians/u-boot-stm
[platform/kernel/u-boot.git] / drivers / net / smc911x.c
index 053ff9f..5d9a73f 100644 (file)
@@ -28,6 +28,7 @@ struct smc911x_priv {
        phys_addr_t             iobase;
        const struct chip_id    *chipid;
        unsigned char           enetaddr[6];
+       bool                    use_32_bit_io;
 };
 
 static const struct chip_id chip_ids[] =  {
@@ -48,36 +49,24 @@ static const struct chip_id chip_ids[] =  {
 
 #define DRIVERNAME "smc911x"
 
-#if defined (CONFIG_SMC911X_32_BIT) && \
-       defined (CONFIG_SMC911X_16_BIT)
-#error "SMC911X: Only one of CONFIG_SMC911X_32_BIT and \
-       CONFIG_SMC911X_16_BIT shall be set"
-#endif
-
-#if defined (CONFIG_SMC911X_32_BIT)
 static u32 smc911x_reg_read(struct smc911x_priv *priv, u32 offset)
 {
-       return readl(priv->iobase + offset);
-}
+       if (priv->use_32_bit_io)
+               return readl(priv->iobase + offset);
 
-static void smc911x_reg_write(struct smc911x_priv *priv, u32 offset, u32 val)
-{
-       writel(val, priv->iobase + offset);
-}
-#elif defined (CONFIG_SMC911X_16_BIT)
-static u32 smc911x_reg_read(struct smc911x_priv *priv, u32 offset)
-{
        return (readw(priv->iobase + offset) & 0xffff) |
               (readw(priv->iobase + offset + 2) << 16);
 }
+
 static void smc911x_reg_write(struct smc911x_priv *priv, u32 offset, u32 val)
 {
-       writew(val & 0xffff, priv->iobase + offset);
-       writew(val >> 16, priv->iobase + offset + 2);
+       if (priv->use_32_bit_io) {
+               writel(val, priv->iobase + offset);
+       } else {
+               writew(val & 0xffff, priv->iobase + offset);
+               writew(val >> 16, priv->iobase + offset + 2);
+       }
 }
-#else
-#error "SMC911X: undefined bus width"
-#endif /* CONFIG_SMC911X_16_BIT */
 
 static u32 smc911x_get_mac_csr(struct smc911x_priv *priv, u8 reg)
 {
@@ -436,7 +425,7 @@ static int smc911x_initialize_mii(struct smc911x_priv *priv)
        if (!mdiodev)
                return -ENOMEM;
 
-       strncpy(mdiodev->name, priv->dev.name, MDIO_NAME_LEN);
+       strlcpy(mdiodev->name, priv->dev.name, MDIO_NAME_LEN);
        mdiodev->read = smc911x_miiphy_read;
        mdiodev->write = smc911x_miiphy_write;
 
@@ -455,7 +444,7 @@ static int smc911x_initialize_mii(struct smc911x_priv *priv)
 }
 #endif
 
-static int smc911x_init(struct eth_device *dev, bd_t *bd)
+static int smc911x_init(struct eth_device *dev, struct bd_info *bd)
 {
        struct smc911x_priv *priv = container_of(dev, struct smc911x_priv, dev);
 
@@ -489,7 +478,7 @@ static int smc911x_recv(struct eth_device *dev)
        return ret;
 }
 
-int smc911x_initialize(u8 dev_num, int base_addr)
+int smc911x_initialize(u8 dev_num, phys_addr_t base_addr)
 {
        struct smc911x_priv *priv;
        int ret;
@@ -501,6 +490,8 @@ int smc911x_initialize(u8 dev_num, int base_addr)
        priv->iobase = base_addr;
        priv->dev.iobase = base_addr;
 
+       priv->use_32_bit_io = CONFIG_IS_ENABLED(SMC911X_32_BIT);
+
        /* Try to detect chip. Will fail if not present. */
        ret = smc911x_detect_chip(priv);
        if (ret) {
@@ -536,7 +527,7 @@ err_detect:
 
 static int smc911x_start(struct udevice *dev)
 {
-       struct eth_pdata *plat = dev_get_platdata(dev);
+       struct eth_pdata *plat = dev_get_plat(dev);
        struct smc911x_priv *priv = dev_get_priv(dev);
 
        memcpy(priv->enetaddr, plat->enetaddr, sizeof(plat->enetaddr));
@@ -577,7 +568,7 @@ static int smc911x_recv(struct udevice *dev, int flags, uchar **packetp)
 static int smc911x_read_rom_hwaddr(struct udevice *dev)
 {
        struct smc911x_priv *priv = dev_get_priv(dev);
-       struct eth_pdata *pdata = dev_get_platdata(dev);
+       struct eth_pdata *pdata = dev_get_plat(dev);
 
        if (!smc911x_read_mac_address(priv))
                return -ENODEV;
@@ -607,14 +598,22 @@ static int smc911x_probe(struct udevice *dev)
        return 0;
 }
 
-static int smc911x_ofdata_to_platdata(struct udevice *dev)
+static int smc911x_of_to_plat(struct udevice *dev)
 {
        struct smc911x_priv *priv = dev_get_priv(dev);
-       struct eth_pdata *pdata = dev_get_platdata(dev);
+       struct eth_pdata *pdata = dev_get_plat(dev);
+       u32 io_width;
+       int ret;
 
-       pdata->iobase = devfdt_get_addr(dev);
+       pdata->iobase = dev_read_addr(dev);
        priv->iobase = pdata->iobase;
 
+       ret = dev_read_u32(dev, "reg-io-width", &io_width);
+       if (!ret)
+               priv->use_32_bit_io = (io_width == 4);
+       else
+               priv->use_32_bit_io = CONFIG_IS_ENABLED(SMC911X_32_BIT);
+
        return 0;
 }
 
@@ -636,11 +635,11 @@ U_BOOT_DRIVER(smc911x) = {
        .id             = UCLASS_ETH,
        .of_match       = smc911x_ids,
        .bind           = smc911x_bind,
-       .ofdata_to_platdata = smc911x_ofdata_to_platdata,
+       .of_to_plat = smc911x_of_to_plat,
        .probe          = smc911x_probe,
        .ops            = &smc911x_ops,
-       .priv_auto_alloc_size = sizeof(struct smc911x_priv),
-       .platdata_auto_alloc_size = sizeof(struct eth_pdata),
+       .priv_auto      = sizeof(struct smc911x_priv),
+       .plat_auto      = sizeof(struct eth_pdata),
        .flags          = DM_FLAG_ALLOC_PRIV_DMA,
 };
 #endif