Lines Matching +full:bus +full:- +full:addr

1 // SPDX-License-Identifier: GPL-2.0-or-later
15 #define DRV_NAME "mdio-aspeed"
48 static int aspeed_mdio_op(struct mii_bus *bus, u8 st, u8 op, u8 phyad, u8 regad, in aspeed_mdio_op() argument
51 struct aspeed_mdio *ctx = bus->priv; in aspeed_mdio_op()
54 dev_dbg(&bus->dev, "%s: st: %u op: %u, phyad: %u, regad: %u, data: %u\n", in aspeed_mdio_op()
64 iowrite32(ctrl, ctx->base + ASPEED_MDIO_CTRL); in aspeed_mdio_op()
66 return readl_poll_timeout(ctx->base + ASPEED_MDIO_CTRL, ctrl, in aspeed_mdio_op()
72 static int aspeed_mdio_get_data(struct mii_bus *bus) in aspeed_mdio_get_data() argument
74 struct aspeed_mdio *ctx = bus->priv; in aspeed_mdio_get_data()
78 rc = readl_poll_timeout(ctx->base + ASPEED_MDIO_DATA, data, in aspeed_mdio_get_data()
88 static int aspeed_mdio_read_c22(struct mii_bus *bus, int addr, int regnum) in aspeed_mdio_read_c22() argument
92 rc = aspeed_mdio_op(bus, ASPEED_MDIO_CTRL_ST_C22, MDIO_C22_OP_READ, in aspeed_mdio_read_c22()
93 addr, regnum, 0); in aspeed_mdio_read_c22()
97 return aspeed_mdio_get_data(bus); in aspeed_mdio_read_c22()
100 static int aspeed_mdio_write_c22(struct mii_bus *bus, int addr, int regnum, in aspeed_mdio_write_c22() argument
103 return aspeed_mdio_op(bus, ASPEED_MDIO_CTRL_ST_C22, MDIO_C22_OP_WRITE, in aspeed_mdio_write_c22()
104 addr, regnum, val); in aspeed_mdio_write_c22()
107 static int aspeed_mdio_read_c45(struct mii_bus *bus, int addr, int regnum) in aspeed_mdio_read_c45() argument
113 rc = aspeed_mdio_op(bus, ASPEED_MDIO_CTRL_ST_C45, MDIO_C45_OP_ADDR, in aspeed_mdio_read_c45()
114 addr, c45_dev, c45_addr); in aspeed_mdio_read_c45()
118 rc = aspeed_mdio_op(bus, ASPEED_MDIO_CTRL_ST_C45, MDIO_C45_OP_READ, in aspeed_mdio_read_c45()
119 addr, c45_dev, 0); in aspeed_mdio_read_c45()
123 return aspeed_mdio_get_data(bus); in aspeed_mdio_read_c45()
126 static int aspeed_mdio_write_c45(struct mii_bus *bus, int addr, int regnum, in aspeed_mdio_write_c45() argument
133 rc = aspeed_mdio_op(bus, ASPEED_MDIO_CTRL_ST_C45, MDIO_C45_OP_ADDR, in aspeed_mdio_write_c45()
134 addr, c45_dev, c45_addr); in aspeed_mdio_write_c45()
138 return aspeed_mdio_op(bus, ASPEED_MDIO_CTRL_ST_C45, MDIO_C45_OP_WRITE, in aspeed_mdio_write_c45()
139 addr, c45_dev, val); in aspeed_mdio_write_c45()
142 static int aspeed_mdio_read(struct mii_bus *bus, int addr, int regnum) in aspeed_mdio_read() argument
144 dev_dbg(&bus->dev, "%s: addr: %d, regnum: %d\n", __func__, addr, in aspeed_mdio_read()
148 return aspeed_mdio_read_c45(bus, addr, regnum); in aspeed_mdio_read()
150 return aspeed_mdio_read_c22(bus, addr, regnum); in aspeed_mdio_read()
153 static int aspeed_mdio_write(struct mii_bus *bus, int addr, int regnum, u16 val) in aspeed_mdio_write() argument
155 dev_dbg(&bus->dev, "%s: addr: %d, regnum: %d, val: 0x%x\n", in aspeed_mdio_write()
156 __func__, addr, regnum, val); in aspeed_mdio_write()
159 return aspeed_mdio_write_c45(bus, addr, regnum, val); in aspeed_mdio_write()
161 return aspeed_mdio_write_c22(bus, addr, regnum, val); in aspeed_mdio_write()
167 struct mii_bus *bus; in aspeed_mdio_probe() local
170 bus = devm_mdiobus_alloc_size(&pdev->dev, sizeof(*ctx)); in aspeed_mdio_probe()
171 if (!bus) in aspeed_mdio_probe()
172 return -ENOMEM; in aspeed_mdio_probe()
174 ctx = bus->priv; in aspeed_mdio_probe()
175 ctx->base = devm_platform_ioremap_resource(pdev, 0); in aspeed_mdio_probe()
176 if (IS_ERR(ctx->base)) in aspeed_mdio_probe()
177 return PTR_ERR(ctx->base); in aspeed_mdio_probe()
179 ctx->reset = devm_reset_control_get_optional_shared(&pdev->dev, NULL); in aspeed_mdio_probe()
180 if (IS_ERR(ctx->reset)) in aspeed_mdio_probe()
181 return PTR_ERR(ctx->reset); in aspeed_mdio_probe()
183 reset_control_deassert(ctx->reset); in aspeed_mdio_probe()
185 bus->name = DRV_NAME; in aspeed_mdio_probe()
186 snprintf(bus->id, MII_BUS_ID_SIZE, "%s%d", pdev->name, pdev->id); in aspeed_mdio_probe()
187 bus->parent = &pdev->dev; in aspeed_mdio_probe()
188 bus->read = aspeed_mdio_read; in aspeed_mdio_probe()
189 bus->write = aspeed_mdio_write; in aspeed_mdio_probe()
190 bus->probe_capabilities = MDIOBUS_C22_C45; in aspeed_mdio_probe()
192 rc = of_mdiobus_register(bus, pdev->dev.of_node); in aspeed_mdio_probe()
194 dev_err(&pdev->dev, "Cannot register MDIO bus!\n"); in aspeed_mdio_probe()
195 reset_control_assert(ctx->reset); in aspeed_mdio_probe()
199 platform_set_drvdata(pdev, bus); in aspeed_mdio_probe()
206 struct mii_bus *bus = (struct mii_bus *)platform_get_drvdata(pdev); in aspeed_mdio_remove() local
207 struct aspeed_mdio *ctx = bus->priv; in aspeed_mdio_remove()
209 reset_control_assert(ctx->reset); in aspeed_mdio_remove()
210 mdiobus_unregister(bus); in aspeed_mdio_remove()
216 { .compatible = "aspeed,ast2600-mdio", },