mdio_bus: Issue GPIO RESET to PHYs.

Some boards [1] leave the PHYs at an invalid state
during system power-up or reset thus causing unreliability
issues with the PHY which manifests as PHY not being detected
or link not functional. To fix this, these PHYs need to be RESET
via a GPIO connected to the PHY's RESET pin.

Some boards have a single GPIO controlling the PHY RESET pin of all
PHYs on the bus whereas some others have separate GPIOs controlling
individual PHY RESETs.

In both cases, the RESET de-assertion cannot be done in the PHY driver
as the PHY will not probe till its reset is de-asserted.
So do the RESET de-assertion in the MDIO bus driver.

[1] - am572x-idk, am571x-idk, a437x-idk

Signed-off-by: Roger Quadros <rogerq@ti.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Esse commit está contido em:
Roger Quadros
2017-04-21 16:15:38 +03:00
commit de David S. Miller
commit 69226896ad
4 arquivos alterados com 94 adições e 0 exclusões

Ver arquivo

@@ -22,8 +22,11 @@
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/gpio.h>
#include <linux/gpio/consumer.h>
#include <linux/of_device.h>
#include <linux/of_mdio.h>
#include <linux/of_gpio.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/skbuff.h>
@@ -337,6 +340,7 @@ int __mdiobus_register(struct mii_bus *bus, struct module *owner)
{
struct mdio_device *mdiodev;
int i, err;
struct gpio_desc *gpiod;
if (NULL == bus || NULL == bus->name ||
NULL == bus->read || NULL == bus->write)
@@ -363,6 +367,35 @@ int __mdiobus_register(struct mii_bus *bus, struct module *owner)
if (bus->reset)
bus->reset(bus);
/* de-assert bus level PHY GPIO resets */
if (bus->num_reset_gpios > 0) {
bus->reset_gpiod = devm_kcalloc(&bus->dev,
bus->num_reset_gpios,
sizeof(struct gpio_desc *),
GFP_KERNEL);
if (!bus->reset_gpiod)
return -ENOMEM;
}
for (i = 0; i < bus->num_reset_gpios; i++) {
gpiod = devm_gpiod_get_index(&bus->dev, "reset", i,
GPIOD_OUT_LOW);
if (IS_ERR(gpiod)) {
err = PTR_ERR(gpiod);
if (err != -ENOENT) {
dev_err(&bus->dev,
"mii_bus %s couldn't get reset GPIO\n",
bus->id);
return err;
}
} else {
bus->reset_gpiod[i] = gpiod;
gpiod_set_value_cansleep(gpiod, 1);
udelay(bus->reset_delay_us);
gpiod_set_value_cansleep(gpiod, 0);
}
}
for (i = 0; i < PHY_MAX_ADDR; i++) {
if ((bus->phy_mask & (1 << i)) == 0) {
struct phy_device *phydev;
@@ -390,6 +423,13 @@ error:
mdiodev->device_remove(mdiodev);
mdiodev->device_free(mdiodev);
}
/* Put PHYs in RESET to save power */
for (i = 0; i < bus->num_reset_gpios; i++) {
if (bus->reset_gpiod[i])
gpiod_set_value_cansleep(bus->reset_gpiod[i], 1);
}
device_del(&bus->dev);
return err;
}
@@ -411,6 +451,13 @@ void mdiobus_unregister(struct mii_bus *bus)
mdiodev->device_remove(mdiodev);
mdiodev->device_free(mdiodev);
}
/* Put PHYs in RESET to save power */
for (i = 0; i < bus->num_reset_gpios; i++) {
if (bus->reset_gpiod[i])
gpiod_set_value_cansleep(bus->reset_gpiod[i], 1);
}
device_del(&bus->dev);
}
EXPORT_SYMBOL(mdiobus_unregister);