Lines Matching +full:realtek +full:- +full:mdio

1 // SPDX-License-Identifier: GPL-2.0+
2 /* Realtek MDIO interface driver
6 * RTL8366 - The original version, apparently
7 * RTL8369 - Similar enough to have the same datsheet as RTL8366
8 * RTL8366RB - Probably reads out "RTL8366 revision B", has a quite
10 * RTL8366S - Is this "RTL8366 super"?
11 * RTL8367 - Has an OpenWRT driver as well
12 * RTL8368S - Seems to be an alternative name for RTL8366RB
13 * RTL8370 - Also uses SMI
19 * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
26 #include "realtek.h"
44 struct mii_bus *bus = priv->bus; in realtek_mdio_write()
47 mutex_lock(&bus->mdio_lock); in realtek_mdio_write()
49 ret = bus->write(bus, priv->mdio_addr, REALTEK_MDIO_CTRL0_REG, REALTEK_MDIO_ADDR_OP); in realtek_mdio_write()
53 ret = bus->write(bus, priv->mdio_addr, REALTEK_MDIO_ADDRESS_REG, reg); in realtek_mdio_write()
57 ret = bus->write(bus, priv->mdio_addr, REALTEK_MDIO_DATA_WRITE_REG, val); in realtek_mdio_write()
61 ret = bus->write(bus, priv->mdio_addr, REALTEK_MDIO_CTRL1_REG, REALTEK_MDIO_WRITE_OP); in realtek_mdio_write()
64 mutex_unlock(&bus->mdio_lock); in realtek_mdio_write()
72 struct mii_bus *bus = priv->bus; in realtek_mdio_read()
75 mutex_lock(&bus->mdio_lock); in realtek_mdio_read()
77 ret = bus->write(bus, priv->mdio_addr, REALTEK_MDIO_CTRL0_REG, REALTEK_MDIO_ADDR_OP); in realtek_mdio_read()
81 ret = bus->write(bus, priv->mdio_addr, REALTEK_MDIO_ADDRESS_REG, reg); in realtek_mdio_read()
85 ret = bus->write(bus, priv->mdio_addr, REALTEK_MDIO_CTRL1_REG, REALTEK_MDIO_READ_OP); in realtek_mdio_read()
89 ret = bus->read(bus, priv->mdio_addr, REALTEK_MDIO_DATA_READ_REG); in realtek_mdio_read()
96 mutex_unlock(&bus->mdio_lock); in realtek_mdio_read()
105 mutex_lock(&priv->map_lock); in realtek_mdio_lock()
112 mutex_unlock(&priv->map_lock); in realtek_mdio_unlock()
145 struct device *dev = &mdiodev->dev; in realtek_mdio_probe()
153 return -EINVAL; in realtek_mdio_probe()
155 priv = devm_kzalloc(&mdiodev->dev, sizeof(*priv), GFP_KERNEL); in realtek_mdio_probe()
157 return -ENOMEM; in realtek_mdio_probe()
159 mutex_init(&priv->map_lock); in realtek_mdio_probe()
163 priv->map = devm_regmap_init(dev, NULL, priv, &rc); in realtek_mdio_probe()
164 if (IS_ERR(priv->map)) { in realtek_mdio_probe()
165 ret = PTR_ERR(priv->map); in realtek_mdio_probe()
171 priv->map_nolock = devm_regmap_init(dev, NULL, priv, &rc); in realtek_mdio_probe()
172 if (IS_ERR(priv->map_nolock)) { in realtek_mdio_probe()
173 ret = PTR_ERR(priv->map_nolock); in realtek_mdio_probe()
178 priv->mdio_addr = mdiodev->addr; in realtek_mdio_probe()
179 priv->bus = mdiodev->bus; in realtek_mdio_probe()
180 priv->dev = &mdiodev->dev; in realtek_mdio_probe()
181 priv->chip_data = (void *)priv + sizeof(*priv); in realtek_mdio_probe()
183 priv->clk_delay = var->clk_delay; in realtek_mdio_probe()
184 priv->cmd_read = var->cmd_read; in realtek_mdio_probe()
185 priv->cmd_write = var->cmd_write; in realtek_mdio_probe()
186 priv->ops = var->ops; in realtek_mdio_probe()
188 priv->write_reg_noack = realtek_mdio_write; in realtek_mdio_probe()
190 np = dev->of_node; in realtek_mdio_probe()
195 priv->leds_disabled = of_property_read_bool(np, "realtek,disable-leds"); in realtek_mdio_probe()
197 priv->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); in realtek_mdio_probe()
198 if (IS_ERR(priv->reset)) { in realtek_mdio_probe()
200 return PTR_ERR(priv->reset); in realtek_mdio_probe()
203 if (priv->reset) { in realtek_mdio_probe()
204 gpiod_set_value(priv->reset, 1); in realtek_mdio_probe()
207 gpiod_set_value(priv->reset, 0); in realtek_mdio_probe()
212 ret = priv->ops->detect(priv); in realtek_mdio_probe()
218 priv->ds = devm_kzalloc(dev, sizeof(*priv->ds), GFP_KERNEL); in realtek_mdio_probe()
219 if (!priv->ds) in realtek_mdio_probe()
220 return -ENOMEM; in realtek_mdio_probe()
222 priv->ds->dev = dev; in realtek_mdio_probe()
223 priv->ds->num_ports = priv->num_ports; in realtek_mdio_probe()
224 priv->ds->priv = priv; in realtek_mdio_probe()
225 priv->ds->ops = var->ds_ops_mdio; in realtek_mdio_probe()
227 ret = dsa_register_switch(priv->ds); in realtek_mdio_probe()
229 dev_err(priv->dev, "unable to register switch ret = %d\n", ret); in realtek_mdio_probe()
238 struct realtek_priv *priv = dev_get_drvdata(&mdiodev->dev); in realtek_mdio_remove()
243 dsa_unregister_switch(priv->ds); in realtek_mdio_remove()
246 if (priv->reset) in realtek_mdio_remove()
247 gpiod_set_value(priv->reset, 1); in realtek_mdio_remove()
252 struct realtek_priv *priv = dev_get_drvdata(&mdiodev->dev); in realtek_mdio_shutdown()
257 dsa_switch_shutdown(priv->ds); in realtek_mdio_shutdown()
259 dev_set_drvdata(&mdiodev->dev, NULL); in realtek_mdio_shutdown()
264 { .compatible = "realtek,rtl8366rb", .data = &rtl8366rb_variant, },
267 { .compatible = "realtek,rtl8365mb", .data = &rtl8365mb_variant, },
275 .name = "realtek-mdio",
286 MODULE_DESCRIPTION("Driver for Realtek ethernet switch connected via MDIO interface");