[PATCH v1 1/3] net: port support for microchip SMI0 MDIO bus
Sascha Hauer
sha at pengutronix.de
Thu Sep 22 02:29:02 PDT 2022
On Tue, Sep 20, 2022 at 02:55:31PM +0200, Oleksij Rempel wrote:
> 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.
>
> This code was ported from the kernel v6.0-rc2.
>
> Signed-off-by: Oleksij Rempel <o.rempel at pengutronix.de>
> ---
> drivers/net/phy/mdio-bitbang.c | 8 ++++++--
> drivers/net/phy/mdio-gpio.c | 8 ++++++++
> include/linux/mdio-bitbang.h | 3 +++
> 3 files changed, 17 insertions(+), 2 deletions(-)
Applied, thanks
Sascha
>
> diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
> index 839a7d1eb8..656557589d 100644
> --- a/drivers/net/phy/mdio-bitbang.c
> +++ b/drivers/net/phy/mdio-bitbang.c
> @@ -158,7 +158,7 @@ static int mdiobb_read(struct mii_bus *bus, int phy, int reg)
> reg = mdiobb_cmd_addr(ctrl, phy, reg);
> mdiobb_cmd(ctrl, MDIO_C45_READ, phy, reg);
> } else
> - mdiobb_cmd(ctrl, MDIO_READ, phy, reg);
> + mdiobb_cmd(ctrl, ctrl->op_c22_read, phy, reg);
>
> ctrl->ops->set_mdio_dir(ctrl, 0);
>
> @@ -188,7 +188,7 @@ static int mdiobb_write(struct mii_bus *bus, int phy, int reg, u16 val)
> reg = mdiobb_cmd_addr(ctrl, phy, reg);
> mdiobb_cmd(ctrl, MDIO_C45_WRITE, phy, reg);
> } else
> - mdiobb_cmd(ctrl, MDIO_WRITE, phy, reg);
> + mdiobb_cmd(ctrl, ctrl->op_c22_write, phy, reg);
>
> /* send the turnaround (10) */
> mdiobb_send_bit(ctrl, 1);
> @@ -219,6 +219,10 @@ struct mii_bus *alloc_mdio_bitbang(struct mdiobb_ctrl *ctrl)
> bus->write = mdiobb_write;
> bus->reset = mdiobb_reset;
> bus->priv = ctrl;
> + if (!ctrl->override_op_c22) {
> + ctrl->op_c22_read = MDIO_READ;
> + ctrl->op_c22_write = MDIO_WRITE;
> + }
>
> return bus;
> }
> diff --git a/drivers/net/phy/mdio-gpio.c b/drivers/net/phy/mdio-gpio.c
> index 80d2394f4b..c64f2b3925 100644
> --- a/drivers/net/phy/mdio-gpio.c
> +++ b/drivers/net/phy/mdio-gpio.c
> @@ -193,6 +193,13 @@ static int mdio_gpio_probe(struct device_d *dev)
> goto free_mdo;
> }
>
> + if (np &&
> + of_device_is_compatible(np, "microchip,mdio-smi0")) {
> + info->ctrl.op_c22_read = 0;
> + info->ctrl.op_c22_write = 0;
> + info->ctrl.override_op_c22 = 1;
> + }
> +
> bus = alloc_mdio_bitbang(&info->ctrl);
> bus->parent = dev;
> bus->dev.device_node = np;
> @@ -217,6 +224,7 @@ free_info:
>
> static const struct of_device_id gpio_mdio_dt_ids[] = {
> { .compatible = "virtual,mdio-gpio", },
> + { .compatible = "microchip,mdio-smi0" },
> { /* sentinel */ }
> };
>
> diff --git a/include/linux/mdio-bitbang.h b/include/linux/mdio-bitbang.h
> index a6e6057886..49fe435429 100644
> --- a/include/linux/mdio-bitbang.h
> +++ b/include/linux/mdio-bitbang.h
> @@ -36,6 +36,9 @@ struct mdiobb_ctrl {
> const struct mdiobb_ops *ops;
> /* reset callback */
> int (*reset)(struct mii_bus *bus);
> + unsigned int override_op_c22;
> + u8 op_c22_read;
> + u8 op_c22_write;
> };
>
> /* The returned bus is not yet registered with the phy layer. */
> --
> 2.30.2
>
>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
More information about the barebox
mailing list