Commit 800fcab8 authored by Andrew Lunn's avatar Andrew Lunn Committed by David S. Miller

net: phy: Add support for microchip SMI0 MDIO bus

SMI0 is a mangled version of MDIO. The main low level difference is
the MDIO C22 OP code is always 0, not 0x2 or 0x1 for Read/Write. The
read/write information is instead encoded in the PHY address.

Extend the bit-bang code to allow the op code to be overridden, but
default to normal C22 values. Add an extra compatible to the mdio-gpio
driver, and when this compatible is present, set the op codes to 0.

A higher level driver, sitting on top of the basic MDIO bus driver can
then implement the rest of the microchip SMI0 odderties.
Signed-off-by: default avatarAndrew Lunn <andrew@lunn.ch>
Signed-off-by: default avatarMichael Grzeschik <m.grzeschik@pengutronix.de>
Signed-off-by: default avatarOleksij Rempel <o.rempel@pengutronix.de>
Reviewed-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 61df0e7b
...@@ -158,7 +158,7 @@ int mdiobb_read(struct mii_bus *bus, int phy, int reg) ...@@ -158,7 +158,7 @@ int mdiobb_read(struct mii_bus *bus, int phy, int reg)
reg = mdiobb_cmd_addr(ctrl, phy, reg); reg = mdiobb_cmd_addr(ctrl, phy, reg);
mdiobb_cmd(ctrl, MDIO_C45_READ, phy, reg); mdiobb_cmd(ctrl, MDIO_C45_READ, phy, reg);
} else } else
mdiobb_cmd(ctrl, MDIO_READ, phy, reg); mdiobb_cmd(ctrl, ctrl->op_c22_read, phy, reg);
ctrl->ops->set_mdio_dir(ctrl, 0); ctrl->ops->set_mdio_dir(ctrl, 0);
...@@ -190,7 +190,7 @@ int mdiobb_write(struct mii_bus *bus, int phy, int reg, u16 val) ...@@ -190,7 +190,7 @@ int mdiobb_write(struct mii_bus *bus, int phy, int reg, u16 val)
reg = mdiobb_cmd_addr(ctrl, phy, reg); reg = mdiobb_cmd_addr(ctrl, phy, reg);
mdiobb_cmd(ctrl, MDIO_C45_WRITE, phy, reg); mdiobb_cmd(ctrl, MDIO_C45_WRITE, phy, reg);
} else } else
mdiobb_cmd(ctrl, MDIO_WRITE, phy, reg); mdiobb_cmd(ctrl, ctrl->op_c22_write, phy, reg);
/* send the turnaround (10) */ /* send the turnaround (10) */
mdiobb_send_bit(ctrl, 1); mdiobb_send_bit(ctrl, 1);
...@@ -217,6 +217,10 @@ struct mii_bus *alloc_mdio_bitbang(struct mdiobb_ctrl *ctrl) ...@@ -217,6 +217,10 @@ struct mii_bus *alloc_mdio_bitbang(struct mdiobb_ctrl *ctrl)
bus->read = mdiobb_read; bus->read = mdiobb_read;
bus->write = mdiobb_write; bus->write = mdiobb_write;
bus->priv = ctrl; bus->priv = ctrl;
if (!ctrl->override_op_c22) {
ctrl->op_c22_read = MDIO_READ;
ctrl->op_c22_write = MDIO_WRITE;
}
return bus; return bus;
} }
......
...@@ -132,6 +132,13 @@ static struct mii_bus *mdio_gpio_bus_init(struct device *dev, ...@@ -132,6 +132,13 @@ static struct mii_bus *mdio_gpio_bus_init(struct device *dev,
new_bus->phy_ignore_ta_mask = pdata->phy_ignore_ta_mask; new_bus->phy_ignore_ta_mask = pdata->phy_ignore_ta_mask;
} }
if (dev->of_node &&
of_device_is_compatible(dev->of_node, "microchip,mdio-smi0")) {
bitbang->ctrl.op_c22_read = 0;
bitbang->ctrl.op_c22_write = 0;
bitbang->ctrl.override_op_c22 = 1;
}
dev_set_drvdata(dev, new_bus); dev_set_drvdata(dev, new_bus);
return new_bus; return new_bus;
...@@ -196,6 +203,7 @@ static int mdio_gpio_remove(struct platform_device *pdev) ...@@ -196,6 +203,7 @@ static int mdio_gpio_remove(struct platform_device *pdev)
static const struct of_device_id mdio_gpio_of_match[] = { static const struct of_device_id mdio_gpio_of_match[] = {
{ .compatible = "virtual,mdio-gpio", }, { .compatible = "virtual,mdio-gpio", },
{ .compatible = "microchip,mdio-smi0" },
{ /* sentinel */ } { /* sentinel */ }
}; };
MODULE_DEVICE_TABLE(of, mdio_gpio_of_match); MODULE_DEVICE_TABLE(of, mdio_gpio_of_match);
......
...@@ -33,6 +33,9 @@ struct mdiobb_ops { ...@@ -33,6 +33,9 @@ struct mdiobb_ops {
struct mdiobb_ctrl { struct mdiobb_ctrl {
const struct mdiobb_ops *ops; const struct mdiobb_ops *ops;
unsigned int override_op_c22;
u8 op_c22_read;
u8 op_c22_write;
}; };
int mdiobb_read(struct mii_bus *bus, int phy, int reg); int mdiobb_read(struct mii_bus *bus, int phy, int reg);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment