Lines Matching +full:realtek +full:- +full:smi
1 // SPDX-License-Identifier: GPL-2.0+
7 #include "realtek.h"
11 * rtl83xx_lock() - Locks the mutex used by regmaps
19 * Context: Can sleep. Holds priv->map_lock lock.
26 mutex_lock(&priv->map_lock); in rtl83xx_lock()
31 * rtl83xx_unlock() - Unlocks the mutex used by regmaps
36 * Context: Releases priv->map_lock lock.
43 mutex_unlock(&priv->map_lock); in rtl83xx_unlock()
49 struct realtek_priv *priv = bus->priv; in rtl83xx_user_mdio_read()
51 return priv->ops->phy_read(priv, addr, regnum); in rtl83xx_user_mdio_read()
57 struct realtek_priv *priv = bus->priv; in rtl83xx_user_mdio_write()
59 return priv->ops->phy_write(priv, addr, regnum, val); in rtl83xx_user_mdio_write()
63 * rtl83xx_setup_user_mdio() - register the user mii bus driver
66 * Registers the MDIO bus for built-in Ethernet PHYs, and associates it with
74 struct realtek_priv *priv = ds->priv; in rtl83xx_setup_user_mdio()
79 mdio_np = of_get_child_by_name(priv->dev->of_node, "mdio"); in rtl83xx_setup_user_mdio()
81 dev_err(priv->dev, "no MDIO bus node\n"); in rtl83xx_setup_user_mdio()
82 return -ENODEV; in rtl83xx_setup_user_mdio()
85 bus = devm_mdiobus_alloc(priv->dev); in rtl83xx_setup_user_mdio()
87 ret = -ENOMEM; in rtl83xx_setup_user_mdio()
91 bus->priv = priv; in rtl83xx_setup_user_mdio()
92 bus->name = "Realtek user MII"; in rtl83xx_setup_user_mdio()
93 bus->read = rtl83xx_user_mdio_read; in rtl83xx_setup_user_mdio()
94 bus->write = rtl83xx_user_mdio_write; in rtl83xx_setup_user_mdio()
95 snprintf(bus->id, MII_BUS_ID_SIZE, "%s:user_mii", dev_name(priv->dev)); in rtl83xx_setup_user_mdio()
96 bus->parent = priv->dev; in rtl83xx_setup_user_mdio()
98 ret = devm_of_mdiobus_register(priv->dev, bus, mdio_np); in rtl83xx_setup_user_mdio()
100 dev_err(priv->dev, "unable to register MDIO bus %s\n", in rtl83xx_setup_user_mdio()
101 bus->id); in rtl83xx_setup_user_mdio()
105 priv->user_mii_bus = bus; in rtl83xx_setup_user_mdio()
115 * rtl83xx_probe() - probe a Realtek switch
140 .reg_read = interface_info->reg_read, in rtl83xx_probe()
141 .reg_write = interface_info->reg_write, in rtl83xx_probe()
150 return ERR_PTR(-EINVAL); in rtl83xx_probe()
152 priv = devm_kzalloc(dev, size_add(sizeof(*priv), var->chip_data_sz), in rtl83xx_probe()
155 return ERR_PTR(-ENOMEM); in rtl83xx_probe()
157 mutex_init(&priv->map_lock); in rtl83xx_probe()
160 priv->map = devm_regmap_init(dev, NULL, priv, &rc); in rtl83xx_probe()
161 if (IS_ERR(priv->map)) { in rtl83xx_probe()
162 ret = PTR_ERR(priv->map); in rtl83xx_probe()
168 priv->map_nolock = devm_regmap_init(dev, NULL, priv, &rc); in rtl83xx_probe()
169 if (IS_ERR(priv->map_nolock)) { in rtl83xx_probe()
170 ret = PTR_ERR(priv->map_nolock); in rtl83xx_probe()
176 priv->dev = dev; in rtl83xx_probe()
177 priv->variant = var; in rtl83xx_probe()
178 priv->ops = var->ops; in rtl83xx_probe()
179 priv->chip_data = (void *)priv + sizeof(*priv); in rtl83xx_probe()
181 spin_lock_init(&priv->lock); in rtl83xx_probe()
183 priv->leds_disabled = of_property_read_bool(dev->of_node, in rtl83xx_probe()
184 "realtek,disable-leds"); in rtl83xx_probe()
187 priv->reset_ctl = devm_reset_control_get_optional(dev, NULL); in rtl83xx_probe()
188 if (IS_ERR(priv->reset_ctl)) in rtl83xx_probe()
189 return dev_err_cast_probe(dev, priv->reset_ctl, in rtl83xx_probe()
192 priv->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); in rtl83xx_probe()
193 if (IS_ERR(priv->reset)) { in rtl83xx_probe()
195 return ERR_CAST(priv->reset); in rtl83xx_probe()
200 if (priv->reset_ctl || priv->reset) { in rtl83xx_probe()
214 * rtl83xx_register_switch() - detects and register a switch
220 * Context: Can sleep. Takes and releases priv->map_lock.
225 struct dsa_switch *ds = &priv->ds; in rtl83xx_register_switch()
228 ret = priv->ops->detect(priv); in rtl83xx_register_switch()
230 dev_err_probe(priv->dev, ret, "unable to detect switch\n"); in rtl83xx_register_switch()
234 ds->priv = priv; in rtl83xx_register_switch()
235 ds->dev = priv->dev; in rtl83xx_register_switch()
236 ds->ops = priv->variant->ds_ops; in rtl83xx_register_switch()
237 ds->phylink_mac_ops = priv->variant->phylink_mac_ops; in rtl83xx_register_switch()
238 ds->num_ports = priv->num_ports; in rtl83xx_register_switch()
242 dev_err_probe(priv->dev, ret, "unable to register switch\n"); in rtl83xx_register_switch()
251 * rtl83xx_unregister_switch() - unregister a switch
261 struct dsa_switch *ds = &priv->ds; in rtl83xx_unregister_switch()
268 * rtl83xx_shutdown() - shutdown a switch
272 * to prevent realtek_{smi,mdio}_remove() from running afterwards, which is
280 struct dsa_switch *ds = &priv->ds; in rtl83xx_shutdown()
284 dev_set_drvdata(priv->dev, NULL); in rtl83xx_shutdown()
289 * rtl83xx_remove() - Cleanup a realtek switch driver
306 ret = reset_control_assert(priv->reset_ctl); in rtl83xx_reset_assert()
308 dev_warn(priv->dev, in rtl83xx_reset_assert()
312 gpiod_set_value(priv->reset, true); in rtl83xx_reset_assert()
319 ret = reset_control_deassert(priv->reset_ctl); in rtl83xx_reset_deassert()
321 dev_warn(priv->dev, in rtl83xx_reset_deassert()
325 gpiod_set_value(priv->reset, false); in rtl83xx_reset_deassert()
330 MODULE_DESCRIPTION("Realtek DSA switches common module");