Lines Matching +full:realtek +full:- +full:smi

1 // SPDX-License-Identifier: GPL-2.0+
2 /* Realtek Simple Management Interface (SMI) driver
5 * The SMI protocol piggy-backs the MDIO MDC and MDIO signals levels
6 * but the protocol is not MDIO at all. Instead it is a Realtek
7 * pecularity that need to bit-bang the lines in a special way to
12 * RTL8366 - The original version, apparently
13 * RTL8369 - Similar enough to have the same datsheet as RTL8366
14 * RTL8366RB - Probably reads out "RTL8366 revision B", has a quite
16 * RTL8366S - Is this "RTL8366 super"?
17 * RTL8367 - Has an OpenWRT driver as well
18 * RTL8368S - Seems to be an alternative name for RTL8366RB
19 * RTL8370 - Also uses SMI
25 * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
41 #include "realtek.h"
42 #include "realtek-smi.h"
49 ndelay(priv->variant->clk_delay); in realtek_smi_clk_delay()
57 gpiod_direction_output(priv->mdc, 0); in realtek_smi_start()
58 gpiod_direction_output(priv->mdio, 1); in realtek_smi_start()
61 /* CLK 1: 0 -> 1, 1 -> 0 */ in realtek_smi_start()
62 gpiod_set_value(priv->mdc, 1); in realtek_smi_start()
64 gpiod_set_value(priv->mdc, 0); in realtek_smi_start()
68 gpiod_set_value(priv->mdc, 1); in realtek_smi_start()
70 gpiod_set_value(priv->mdio, 0); in realtek_smi_start()
72 gpiod_set_value(priv->mdc, 0); in realtek_smi_start()
74 gpiod_set_value(priv->mdio, 1); in realtek_smi_start()
80 gpiod_set_value(priv->mdio, 0); in realtek_smi_stop()
81 gpiod_set_value(priv->mdc, 1); in realtek_smi_stop()
83 gpiod_set_value(priv->mdio, 1); in realtek_smi_stop()
85 gpiod_set_value(priv->mdc, 1); in realtek_smi_stop()
87 gpiod_set_value(priv->mdc, 0); in realtek_smi_stop()
89 gpiod_set_value(priv->mdc, 1); in realtek_smi_stop()
93 gpiod_set_value(priv->mdc, 0); in realtek_smi_stop()
95 gpiod_set_value(priv->mdc, 1); in realtek_smi_stop()
98 gpiod_direction_input(priv->mdio); in realtek_smi_stop()
99 gpiod_direction_input(priv->mdc); in realtek_smi_stop()
104 for (; len > 0; len--) { in realtek_smi_write_bits()
108 gpiod_set_value(priv->mdio, !!(data & (1 << (len - 1)))); in realtek_smi_write_bits()
112 gpiod_set_value(priv->mdc, 1); in realtek_smi_write_bits()
114 gpiod_set_value(priv->mdc, 0); in realtek_smi_write_bits()
120 gpiod_direction_input(priv->mdio); in realtek_smi_read_bits()
122 for (*data = 0; len > 0; len--) { in realtek_smi_read_bits()
128 gpiod_set_value(priv->mdc, 1); in realtek_smi_read_bits()
130 u = !!gpiod_get_value(priv->mdio); in realtek_smi_read_bits()
131 gpiod_set_value(priv->mdc, 0); in realtek_smi_read_bits()
133 *data |= (u << (len - 1)); in realtek_smi_read_bits()
136 gpiod_direction_output(priv->mdio, 0); in realtek_smi_read_bits()
152 dev_err(priv->dev, "ACK timeout\n"); in realtek_smi_wait_for_ack()
153 return -ETIMEDOUT; in realtek_smi_wait_for_ack()
207 spin_lock_irqsave(&priv->lock, flags); in realtek_smi_read_reg()
212 ret = realtek_smi_write_byte(priv, priv->variant->cmd_read); in realtek_smi_read_reg()
237 spin_unlock_irqrestore(&priv->lock, flags); in realtek_smi_read_reg()
248 spin_lock_irqsave(&priv->lock, flags); in realtek_smi_write_reg()
253 ret = realtek_smi_write_byte(priv, priv->variant->cmd_write); in realtek_smi_write_reg()
284 spin_unlock_irqrestore(&priv->lock, flags); in realtek_smi_write_reg()
320 * realtek_smi_probe() - Probe a platform device for an SMI-connected switch
325 * values specific for SMI-connected devices. Finally, it calls a common
328 * Context: Can sleep. Takes and releases priv->map_lock.
333 struct device *dev = &pdev->dev; in realtek_smi_probe()
342 priv->mdc = devm_gpiod_get_optional(dev, "mdc", GPIOD_OUT_LOW); in realtek_smi_probe()
343 if (IS_ERR(priv->mdc)) { in realtek_smi_probe()
345 return PTR_ERR(priv->mdc); in realtek_smi_probe()
348 priv->mdio = devm_gpiod_get_optional(dev, "mdio", GPIOD_OUT_LOW); in realtek_smi_probe()
349 if (IS_ERR(priv->mdio)) { in realtek_smi_probe()
351 return PTR_ERR(priv->mdio); in realtek_smi_probe()
354 priv->write_reg_noack = realtek_smi_write_reg_noack; in realtek_smi_probe()
367 * realtek_smi_remove() - Remove the driver of a SMI-connected switch
390 * realtek_smi_shutdown() - Shutdown the driver of a SMI-connected switch