Lines Matching refs:priv

47 static inline void realtek_smi_clk_delay(struct realtek_priv *priv)  in realtek_smi_clk_delay()  argument
49 ndelay(priv->variant->clk_delay); in realtek_smi_clk_delay()
52 static void realtek_smi_start(struct realtek_priv *priv) in realtek_smi_start() argument
57 gpiod_direction_output(priv->mdc, 0); in realtek_smi_start()
58 gpiod_direction_output(priv->mdio, 1); in realtek_smi_start()
59 realtek_smi_clk_delay(priv); in realtek_smi_start()
62 gpiod_set_value(priv->mdc, 1); in realtek_smi_start()
63 realtek_smi_clk_delay(priv); in realtek_smi_start()
64 gpiod_set_value(priv->mdc, 0); in realtek_smi_start()
65 realtek_smi_clk_delay(priv); in realtek_smi_start()
68 gpiod_set_value(priv->mdc, 1); in realtek_smi_start()
69 realtek_smi_clk_delay(priv); in realtek_smi_start()
70 gpiod_set_value(priv->mdio, 0); in realtek_smi_start()
71 realtek_smi_clk_delay(priv); in realtek_smi_start()
72 gpiod_set_value(priv->mdc, 0); in realtek_smi_start()
73 realtek_smi_clk_delay(priv); in realtek_smi_start()
74 gpiod_set_value(priv->mdio, 1); in realtek_smi_start()
77 static void realtek_smi_stop(struct realtek_priv *priv) in realtek_smi_stop() argument
79 realtek_smi_clk_delay(priv); in realtek_smi_stop()
80 gpiod_set_value(priv->mdio, 0); in realtek_smi_stop()
81 gpiod_set_value(priv->mdc, 1); in realtek_smi_stop()
82 realtek_smi_clk_delay(priv); in realtek_smi_stop()
83 gpiod_set_value(priv->mdio, 1); in realtek_smi_stop()
84 realtek_smi_clk_delay(priv); in realtek_smi_stop()
85 gpiod_set_value(priv->mdc, 1); in realtek_smi_stop()
86 realtek_smi_clk_delay(priv); in realtek_smi_stop()
87 gpiod_set_value(priv->mdc, 0); in realtek_smi_stop()
88 realtek_smi_clk_delay(priv); in realtek_smi_stop()
89 gpiod_set_value(priv->mdc, 1); in realtek_smi_stop()
92 realtek_smi_clk_delay(priv); in realtek_smi_stop()
93 gpiod_set_value(priv->mdc, 0); in realtek_smi_stop()
94 realtek_smi_clk_delay(priv); 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()
102 static void realtek_smi_write_bits(struct realtek_priv *priv, u32 data, u32 len) in realtek_smi_write_bits() argument
105 realtek_smi_clk_delay(priv); in realtek_smi_write_bits()
108 gpiod_set_value(priv->mdio, !!(data & (1 << (len - 1)))); in realtek_smi_write_bits()
109 realtek_smi_clk_delay(priv); in realtek_smi_write_bits()
112 gpiod_set_value(priv->mdc, 1); in realtek_smi_write_bits()
113 realtek_smi_clk_delay(priv); in realtek_smi_write_bits()
114 gpiod_set_value(priv->mdc, 0); in realtek_smi_write_bits()
118 static void realtek_smi_read_bits(struct realtek_priv *priv, u32 len, u32 *data) in realtek_smi_read_bits() argument
120 gpiod_direction_input(priv->mdio); in realtek_smi_read_bits()
125 realtek_smi_clk_delay(priv); in realtek_smi_read_bits()
128 gpiod_set_value(priv->mdc, 1); in realtek_smi_read_bits()
129 realtek_smi_clk_delay(priv); 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()
136 gpiod_direction_output(priv->mdio, 0); in realtek_smi_read_bits()
139 static int realtek_smi_wait_for_ack(struct realtek_priv *priv) in realtek_smi_wait_for_ack() argument
147 realtek_smi_read_bits(priv, 1, &ack); in realtek_smi_wait_for_ack()
152 dev_err(priv->dev, "ACK timeout\n"); in realtek_smi_wait_for_ack()
160 static int realtek_smi_write_byte(struct realtek_priv *priv, u8 data) in realtek_smi_write_byte() argument
162 realtek_smi_write_bits(priv, data, 8); in realtek_smi_write_byte()
163 return realtek_smi_wait_for_ack(priv); in realtek_smi_write_byte()
166 static int realtek_smi_write_byte_noack(struct realtek_priv *priv, u8 data) in realtek_smi_write_byte_noack() argument
168 realtek_smi_write_bits(priv, data, 8); in realtek_smi_write_byte_noack()
172 static int realtek_smi_read_byte0(struct realtek_priv *priv, u8 *data) in realtek_smi_read_byte0() argument
177 realtek_smi_read_bits(priv, 8, &t); in realtek_smi_read_byte0()
181 realtek_smi_write_bits(priv, 0x00, 1); in realtek_smi_read_byte0()
186 static int realtek_smi_read_byte1(struct realtek_priv *priv, u8 *data) in realtek_smi_read_byte1() argument
191 realtek_smi_read_bits(priv, 8, &t); in realtek_smi_read_byte1()
195 realtek_smi_write_bits(priv, 0x01, 1); in realtek_smi_read_byte1()
200 static int realtek_smi_read_reg(struct realtek_priv *priv, u32 addr, u32 *data) in realtek_smi_read_reg() argument
207 spin_lock_irqsave(&priv->lock, flags); in realtek_smi_read_reg()
209 realtek_smi_start(priv); in realtek_smi_read_reg()
212 ret = realtek_smi_write_byte(priv, priv->variant->cmd_read); in realtek_smi_read_reg()
217 ret = realtek_smi_write_byte(priv, addr & 0xff); in realtek_smi_read_reg()
222 ret = realtek_smi_write_byte(priv, addr >> 8); in realtek_smi_read_reg()
227 realtek_smi_read_byte0(priv, &lo); in realtek_smi_read_reg()
229 realtek_smi_read_byte1(priv, &hi); in realtek_smi_read_reg()
236 realtek_smi_stop(priv); in realtek_smi_read_reg()
237 spin_unlock_irqrestore(&priv->lock, flags); in realtek_smi_read_reg()
242 static int realtek_smi_write_reg(struct realtek_priv *priv, in realtek_smi_write_reg() argument
248 spin_lock_irqsave(&priv->lock, flags); in realtek_smi_write_reg()
250 realtek_smi_start(priv); in realtek_smi_write_reg()
253 ret = realtek_smi_write_byte(priv, priv->variant->cmd_write); in realtek_smi_write_reg()
258 ret = realtek_smi_write_byte(priv, addr & 0xff); in realtek_smi_write_reg()
263 ret = realtek_smi_write_byte(priv, addr >> 8); in realtek_smi_write_reg()
268 ret = realtek_smi_write_byte(priv, data & 0xff); in realtek_smi_write_reg()
274 ret = realtek_smi_write_byte(priv, data >> 8); in realtek_smi_write_reg()
276 ret = realtek_smi_write_byte_noack(priv, data >> 8); in realtek_smi_write_reg()
283 realtek_smi_stop(priv); in realtek_smi_write_reg()
284 spin_unlock_irqrestore(&priv->lock, flags); in realtek_smi_write_reg()
302 struct realtek_priv *priv = ctx; in realtek_smi_write() local
304 return realtek_smi_write_reg(priv, reg, val, true); in realtek_smi_write()
309 struct realtek_priv *priv = ctx; in realtek_smi_read() local
311 return realtek_smi_read_reg(priv, reg, val); in realtek_smi_read()
334 struct realtek_priv *priv; in realtek_smi_probe() local
337 priv = rtl83xx_probe(dev, &realtek_smi_info); in realtek_smi_probe()
338 if (IS_ERR(priv)) in realtek_smi_probe()
339 return PTR_ERR(priv); 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()
344 rtl83xx_remove(priv); 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()
350 rtl83xx_remove(priv); 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()
356 ret = rtl83xx_register_switch(priv); in realtek_smi_probe()
358 rtl83xx_remove(priv); in realtek_smi_probe()
378 struct realtek_priv *priv = platform_get_drvdata(pdev); in realtek_smi_remove() local
380 if (!priv) in realtek_smi_remove()
383 rtl83xx_unregister_switch(priv); in realtek_smi_remove()
385 rtl83xx_remove(priv); in realtek_smi_remove()
401 struct realtek_priv *priv = platform_get_drvdata(pdev); in realtek_smi_shutdown() local
403 if (!priv) in realtek_smi_shutdown()
406 rtl83xx_shutdown(priv); in realtek_smi_shutdown()