Lines Matching +full:data +full:- +full:bus
1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright 2012-2013 Stefan Roese <sr@denx.de>
6 * Copyright 2013 Maxime Ripard <maxime.ripard@free-electrons.com>
36 static int sun4i_mdio_read(struct mii_bus *bus, int mii_id, int regnum) in sun4i_mdio_read() argument
38 struct sun4i_mdio_data *data = bus->priv; in sun4i_mdio_read() local
43 writel((mii_id << 8) | regnum, data->membase + EMAC_MAC_MADR_REG); in sun4i_mdio_read()
45 writel(0x1, data->membase + EMAC_MAC_MCMD_REG); in sun4i_mdio_read()
49 while (readl(data->membase + EMAC_MAC_MIND_REG) & 0x1) { in sun4i_mdio_read()
51 return -ETIMEDOUT; in sun4i_mdio_read()
56 writel(0x0, data->membase + EMAC_MAC_MCMD_REG); in sun4i_mdio_read()
57 /* and read data */ in sun4i_mdio_read()
58 value = readl(data->membase + EMAC_MAC_MRDD_REG); in sun4i_mdio_read()
63 static int sun4i_mdio_write(struct mii_bus *bus, int mii_id, int regnum, in sun4i_mdio_write() argument
66 struct sun4i_mdio_data *data = bus->priv; in sun4i_mdio_write() local
70 writel((mii_id << 8) | regnum, data->membase + EMAC_MAC_MADR_REG); in sun4i_mdio_write()
72 writel(0x1, data->membase + EMAC_MAC_MCMD_REG); in sun4i_mdio_write()
76 while (readl(data->membase + EMAC_MAC_MIND_REG) & 0x1) { in sun4i_mdio_write()
78 return -ETIMEDOUT; in sun4i_mdio_write()
83 writel(0x0, data->membase + EMAC_MAC_MCMD_REG); in sun4i_mdio_write()
84 /* and write data */ in sun4i_mdio_write()
85 writel(value, data->membase + EMAC_MAC_MWTD_REG); in sun4i_mdio_write()
92 struct device_node *np = pdev->dev.of_node; in sun4i_mdio_probe()
93 struct mii_bus *bus; in sun4i_mdio_probe() local
94 struct sun4i_mdio_data *data; in sun4i_mdio_probe() local
97 bus = mdiobus_alloc_size(sizeof(*data)); in sun4i_mdio_probe()
98 if (!bus) in sun4i_mdio_probe()
99 return -ENOMEM; in sun4i_mdio_probe()
101 bus->name = "sun4i_mii_bus"; in sun4i_mdio_probe()
102 bus->read = &sun4i_mdio_read; in sun4i_mdio_probe()
103 bus->write = &sun4i_mdio_write; in sun4i_mdio_probe()
104 snprintf(bus->id, MII_BUS_ID_SIZE, "%s-mii", dev_name(&pdev->dev)); in sun4i_mdio_probe()
105 bus->parent = &pdev->dev; in sun4i_mdio_probe()
107 data = bus->priv; in sun4i_mdio_probe()
108 data->membase = devm_platform_ioremap_resource(pdev, 0); in sun4i_mdio_probe()
109 if (IS_ERR(data->membase)) { in sun4i_mdio_probe()
110 ret = PTR_ERR(data->membase); in sun4i_mdio_probe()
114 data->regulator = devm_regulator_get(&pdev->dev, "phy"); in sun4i_mdio_probe()
115 if (IS_ERR(data->regulator)) { in sun4i_mdio_probe()
116 if (PTR_ERR(data->regulator) == -EPROBE_DEFER) { in sun4i_mdio_probe()
117 ret = -EPROBE_DEFER; in sun4i_mdio_probe()
121 dev_info(&pdev->dev, "no regulator found\n"); in sun4i_mdio_probe()
122 data->regulator = NULL; in sun4i_mdio_probe()
124 ret = regulator_enable(data->regulator); in sun4i_mdio_probe()
129 ret = of_mdiobus_register(bus, np); in sun4i_mdio_probe()
133 platform_set_drvdata(pdev, bus); in sun4i_mdio_probe()
138 if (data->regulator) in sun4i_mdio_probe()
139 regulator_disable(data->regulator); in sun4i_mdio_probe()
141 mdiobus_free(bus); in sun4i_mdio_probe()
147 struct mii_bus *bus = platform_get_drvdata(pdev); in sun4i_mdio_remove() local
148 struct sun4i_mdio_data *data = bus->priv; in sun4i_mdio_remove() local
150 mdiobus_unregister(bus); in sun4i_mdio_remove()
151 if (data->regulator) in sun4i_mdio_remove()
152 regulator_disable(data->regulator); in sun4i_mdio_remove()
153 mdiobus_free(bus); in sun4i_mdio_remove()
157 { .compatible = "allwinner,sun4i-a10-mdio" },
160 { .compatible = "allwinner,sun4i-mdio" },
169 .name = "sun4i-mdio",
177 MODULE_AUTHOR("Maxime Ripard <maxime.ripard@free-electrons.com>");