Lines Matching refs:smi
49 static inline void realtek_smi_clk_delay(struct realtek_smi *smi) in realtek_smi_clk_delay() argument
51 ndelay(smi->clk_delay); in realtek_smi_clk_delay()
54 static void realtek_smi_start(struct realtek_smi *smi) in realtek_smi_start() argument
59 gpiod_direction_output(smi->mdc, 0); in realtek_smi_start()
60 gpiod_direction_output(smi->mdio, 1); in realtek_smi_start()
61 realtek_smi_clk_delay(smi); in realtek_smi_start()
64 gpiod_set_value(smi->mdc, 1); in realtek_smi_start()
65 realtek_smi_clk_delay(smi); in realtek_smi_start()
66 gpiod_set_value(smi->mdc, 0); in realtek_smi_start()
67 realtek_smi_clk_delay(smi); in realtek_smi_start()
70 gpiod_set_value(smi->mdc, 1); in realtek_smi_start()
71 realtek_smi_clk_delay(smi); in realtek_smi_start()
72 gpiod_set_value(smi->mdio, 0); in realtek_smi_start()
73 realtek_smi_clk_delay(smi); in realtek_smi_start()
74 gpiod_set_value(smi->mdc, 0); in realtek_smi_start()
75 realtek_smi_clk_delay(smi); in realtek_smi_start()
76 gpiod_set_value(smi->mdio, 1); in realtek_smi_start()
79 static void realtek_smi_stop(struct realtek_smi *smi) in realtek_smi_stop() argument
81 realtek_smi_clk_delay(smi); in realtek_smi_stop()
82 gpiod_set_value(smi->mdio, 0); in realtek_smi_stop()
83 gpiod_set_value(smi->mdc, 1); in realtek_smi_stop()
84 realtek_smi_clk_delay(smi); in realtek_smi_stop()
85 gpiod_set_value(smi->mdio, 1); in realtek_smi_stop()
86 realtek_smi_clk_delay(smi); in realtek_smi_stop()
87 gpiod_set_value(smi->mdc, 1); in realtek_smi_stop()
88 realtek_smi_clk_delay(smi); in realtek_smi_stop()
89 gpiod_set_value(smi->mdc, 0); in realtek_smi_stop()
90 realtek_smi_clk_delay(smi); in realtek_smi_stop()
91 gpiod_set_value(smi->mdc, 1); in realtek_smi_stop()
94 realtek_smi_clk_delay(smi); in realtek_smi_stop()
95 gpiod_set_value(smi->mdc, 0); in realtek_smi_stop()
96 realtek_smi_clk_delay(smi); in realtek_smi_stop()
97 gpiod_set_value(smi->mdc, 1); in realtek_smi_stop()
100 gpiod_direction_input(smi->mdio); in realtek_smi_stop()
101 gpiod_direction_input(smi->mdc); in realtek_smi_stop()
104 static void realtek_smi_write_bits(struct realtek_smi *smi, u32 data, u32 len) in realtek_smi_write_bits() argument
107 realtek_smi_clk_delay(smi); in realtek_smi_write_bits()
110 gpiod_set_value(smi->mdio, !!(data & (1 << (len - 1)))); in realtek_smi_write_bits()
111 realtek_smi_clk_delay(smi); in realtek_smi_write_bits()
114 gpiod_set_value(smi->mdc, 1); in realtek_smi_write_bits()
115 realtek_smi_clk_delay(smi); in realtek_smi_write_bits()
116 gpiod_set_value(smi->mdc, 0); in realtek_smi_write_bits()
120 static void realtek_smi_read_bits(struct realtek_smi *smi, u32 len, u32 *data) in realtek_smi_read_bits() argument
122 gpiod_direction_input(smi->mdio); in realtek_smi_read_bits()
127 realtek_smi_clk_delay(smi); in realtek_smi_read_bits()
130 gpiod_set_value(smi->mdc, 1); in realtek_smi_read_bits()
131 realtek_smi_clk_delay(smi); in realtek_smi_read_bits()
132 u = !!gpiod_get_value(smi->mdio); in realtek_smi_read_bits()
133 gpiod_set_value(smi->mdc, 0); in realtek_smi_read_bits()
138 gpiod_direction_output(smi->mdio, 0); in realtek_smi_read_bits()
141 static int realtek_smi_wait_for_ack(struct realtek_smi *smi) in realtek_smi_wait_for_ack() argument
149 realtek_smi_read_bits(smi, 1, &ack); in realtek_smi_wait_for_ack()
154 dev_err(smi->dev, "ACK timeout\n"); in realtek_smi_wait_for_ack()
162 static int realtek_smi_write_byte(struct realtek_smi *smi, u8 data) in realtek_smi_write_byte() argument
164 realtek_smi_write_bits(smi, data, 8); in realtek_smi_write_byte()
165 return realtek_smi_wait_for_ack(smi); in realtek_smi_write_byte()
168 static int realtek_smi_write_byte_noack(struct realtek_smi *smi, u8 data) in realtek_smi_write_byte_noack() argument
170 realtek_smi_write_bits(smi, data, 8); in realtek_smi_write_byte_noack()
174 static int realtek_smi_read_byte0(struct realtek_smi *smi, u8 *data) in realtek_smi_read_byte0() argument
179 realtek_smi_read_bits(smi, 8, &t); in realtek_smi_read_byte0()
183 realtek_smi_write_bits(smi, 0x00, 1); in realtek_smi_read_byte0()
188 static int realtek_smi_read_byte1(struct realtek_smi *smi, u8 *data) in realtek_smi_read_byte1() argument
193 realtek_smi_read_bits(smi, 8, &t); in realtek_smi_read_byte1()
197 realtek_smi_write_bits(smi, 0x01, 1); in realtek_smi_read_byte1()
202 static int realtek_smi_read_reg(struct realtek_smi *smi, u32 addr, u32 *data) in realtek_smi_read_reg() argument
209 spin_lock_irqsave(&smi->lock, flags); in realtek_smi_read_reg()
211 realtek_smi_start(smi); in realtek_smi_read_reg()
214 ret = realtek_smi_write_byte(smi, smi->cmd_read); in realtek_smi_read_reg()
219 ret = realtek_smi_write_byte(smi, addr & 0xff); in realtek_smi_read_reg()
224 ret = realtek_smi_write_byte(smi, addr >> 8); in realtek_smi_read_reg()
229 realtek_smi_read_byte0(smi, &lo); in realtek_smi_read_reg()
231 realtek_smi_read_byte1(smi, &hi); in realtek_smi_read_reg()
238 realtek_smi_stop(smi); in realtek_smi_read_reg()
239 spin_unlock_irqrestore(&smi->lock, flags); in realtek_smi_read_reg()
244 static int realtek_smi_write_reg(struct realtek_smi *smi, in realtek_smi_write_reg() argument
250 spin_lock_irqsave(&smi->lock, flags); in realtek_smi_write_reg()
252 realtek_smi_start(smi); in realtek_smi_write_reg()
255 ret = realtek_smi_write_byte(smi, smi->cmd_write); in realtek_smi_write_reg()
260 ret = realtek_smi_write_byte(smi, addr & 0xff); in realtek_smi_write_reg()
265 ret = realtek_smi_write_byte(smi, addr >> 8); in realtek_smi_write_reg()
270 ret = realtek_smi_write_byte(smi, data & 0xff); in realtek_smi_write_reg()
276 ret = realtek_smi_write_byte(smi, data >> 8); in realtek_smi_write_reg()
278 ret = realtek_smi_write_byte_noack(smi, data >> 8); in realtek_smi_write_reg()
285 realtek_smi_stop(smi); in realtek_smi_write_reg()
286 spin_unlock_irqrestore(&smi->lock, flags); in realtek_smi_write_reg()
295 int realtek_smi_write_reg_noack(struct realtek_smi *smi, u32 addr, in realtek_smi_write_reg_noack() argument
298 return realtek_smi_write_reg(smi, addr, data, false); in realtek_smi_write_reg_noack()
306 struct realtek_smi *smi = ctx; in realtek_smi_write() local
308 return realtek_smi_write_reg(smi, reg, val, true); in realtek_smi_write()
313 struct realtek_smi *smi = ctx; in realtek_smi_read() local
315 return realtek_smi_read_reg(smi, reg, val); in realtek_smi_read()
332 struct realtek_smi *smi = bus->priv; in realtek_smi_mdio_read() local
334 return smi->ops->phy_read(smi, addr, regnum); in realtek_smi_mdio_read()
340 struct realtek_smi *smi = bus->priv; in realtek_smi_mdio_write() local
342 return smi->ops->phy_write(smi, addr, regnum, val); in realtek_smi_mdio_write()
345 int realtek_smi_setup_mdio(struct realtek_smi *smi) in realtek_smi_setup_mdio() argument
350 mdio_np = of_get_compatible_child(smi->dev->of_node, "realtek,smi-mdio"); in realtek_smi_setup_mdio()
352 dev_err(smi->dev, "no MDIO bus node\n"); in realtek_smi_setup_mdio()
356 smi->slave_mii_bus = devm_mdiobus_alloc(smi->dev); in realtek_smi_setup_mdio()
357 if (!smi->slave_mii_bus) { in realtek_smi_setup_mdio()
361 smi->slave_mii_bus->priv = smi; in realtek_smi_setup_mdio()
362 smi->slave_mii_bus->name = "SMI slave MII"; in realtek_smi_setup_mdio()
363 smi->slave_mii_bus->read = realtek_smi_mdio_read; in realtek_smi_setup_mdio()
364 smi->slave_mii_bus->write = realtek_smi_mdio_write; in realtek_smi_setup_mdio()
365 snprintf(smi->slave_mii_bus->id, MII_BUS_ID_SIZE, "SMI-%d", in realtek_smi_setup_mdio()
366 smi->ds->index); in realtek_smi_setup_mdio()
367 smi->slave_mii_bus->dev.of_node = mdio_np; in realtek_smi_setup_mdio()
368 smi->slave_mii_bus->parent = smi->dev; in realtek_smi_setup_mdio()
369 smi->ds->slave_mii_bus = smi->slave_mii_bus; in realtek_smi_setup_mdio()
371 ret = of_mdiobus_register(smi->slave_mii_bus, mdio_np); in realtek_smi_setup_mdio()
373 dev_err(smi->dev, "unable to register MDIO bus %s\n", in realtek_smi_setup_mdio()
374 smi->slave_mii_bus->id); in realtek_smi_setup_mdio()
390 struct realtek_smi *smi; in realtek_smi_probe() local
397 smi = devm_kzalloc(dev, sizeof(*smi), GFP_KERNEL); in realtek_smi_probe()
398 if (!smi) in realtek_smi_probe()
400 smi->map = devm_regmap_init(dev, NULL, smi, in realtek_smi_probe()
402 if (IS_ERR(smi->map)) { in realtek_smi_probe()
403 ret = PTR_ERR(smi->map); in realtek_smi_probe()
409 smi->dev = dev; in realtek_smi_probe()
410 smi->clk_delay = var->clk_delay; in realtek_smi_probe()
411 smi->cmd_read = var->cmd_read; in realtek_smi_probe()
412 smi->cmd_write = var->cmd_write; in realtek_smi_probe()
413 smi->ops = var->ops; in realtek_smi_probe()
415 dev_set_drvdata(dev, smi); in realtek_smi_probe()
416 spin_lock_init(&smi->lock); in realtek_smi_probe()
421 smi->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); in realtek_smi_probe()
422 if (IS_ERR(smi->reset)) { in realtek_smi_probe()
424 return PTR_ERR(smi->reset); in realtek_smi_probe()
427 gpiod_set_value(smi->reset, 0); in realtek_smi_probe()
432 smi->mdc = devm_gpiod_get_optional(dev, "mdc", GPIOD_OUT_LOW); in realtek_smi_probe()
433 if (IS_ERR(smi->mdc)) in realtek_smi_probe()
434 return PTR_ERR(smi->mdc); in realtek_smi_probe()
435 smi->mdio = devm_gpiod_get_optional(dev, "mdio", GPIOD_OUT_LOW); in realtek_smi_probe()
436 if (IS_ERR(smi->mdio)) in realtek_smi_probe()
437 return PTR_ERR(smi->mdio); in realtek_smi_probe()
439 smi->leds_disabled = of_property_read_bool(np, "realtek,disable-leds"); in realtek_smi_probe()
441 ret = smi->ops->detect(smi); in realtek_smi_probe()
447 smi->ds = dsa_switch_alloc(dev, smi->num_ports); in realtek_smi_probe()
448 if (!smi->ds) in realtek_smi_probe()
450 smi->ds->priv = smi; in realtek_smi_probe()
452 smi->ds->ops = var->ds_ops; in realtek_smi_probe()
453 ret = dsa_register_switch(smi->ds); in realtek_smi_probe()
463 struct realtek_smi *smi = dev_get_drvdata(&pdev->dev); in realtek_smi_remove() local
465 dsa_unregister_switch(smi->ds); in realtek_smi_remove()
466 if (smi->slave_mii_bus) in realtek_smi_remove()
467 of_node_put(smi->slave_mii_bus->dev.of_node); in realtek_smi_remove()
468 gpiod_set_value(smi->reset, 1); in realtek_smi_remove()