Lines Matching full:sc

57 mtkswitch_phy_read_locked(struct mtkswitch_softc *sc, int phy, int reg)  in mtkswitch_phy_read_locked()  argument
61 MTKSWITCH_WRITE(sc, MTKSWITCH_PIAC, PIAC_PHY_ACS_ST | PIAC_MDIO_ST | in mtkswitch_phy_read_locked()
64 while ((data = MTKSWITCH_READ(sc, MTKSWITCH_PIAC)) & PIAC_PHY_ACS_ST); in mtkswitch_phy_read_locked()
72 struct mtkswitch_softc *sc = device_get_softc(dev); in mtkswitch_phy_read() local
78 MTKSWITCH_LOCK_ASSERT(sc, MA_NOTOWNED); in mtkswitch_phy_read()
79 MTKSWITCH_LOCK(sc); in mtkswitch_phy_read()
80 data = mtkswitch_phy_read_locked(sc, phy, reg); in mtkswitch_phy_read()
81 MTKSWITCH_UNLOCK(sc); in mtkswitch_phy_read()
87 mtkswitch_phy_write_locked(struct mtkswitch_softc *sc, int phy, int reg, in mtkswitch_phy_write_locked() argument
91 MTKSWITCH_WRITE(sc, MTKSWITCH_PIAC, PIAC_PHY_ACS_ST | PIAC_MDIO_ST | in mtkswitch_phy_write_locked()
94 while (MTKSWITCH_READ(sc, MTKSWITCH_PIAC) & PIAC_PHY_ACS_ST); in mtkswitch_phy_write_locked()
102 struct mtkswitch_softc *sc = device_get_softc(dev); in mtkswitch_phy_write() local
108 MTKSWITCH_LOCK_ASSERT(sc, MA_NOTOWNED); in mtkswitch_phy_write()
109 MTKSWITCH_LOCK(sc); in mtkswitch_phy_write()
110 res = mtkswitch_phy_write_locked(sc, phy, reg, val); in mtkswitch_phy_write()
111 MTKSWITCH_UNLOCK(sc); in mtkswitch_phy_write()
117 mtkswitch_reg_read32(struct mtkswitch_softc *sc, int reg) in mtkswitch_reg_read32() argument
120 return (MTKSWITCH_READ(sc, reg)); in mtkswitch_reg_read32()
124 mtkswitch_reg_write32(struct mtkswitch_softc *sc, int reg, uint32_t val) in mtkswitch_reg_write32() argument
127 MTKSWITCH_WRITE(sc, reg, val); in mtkswitch_reg_write32()
132 mtkswitch_reg_read32_mt7621(struct mtkswitch_softc *sc, int reg) in mtkswitch_reg_read32_mt7621() argument
136 mtkswitch_phy_write_locked(sc, MTKSWITCH_GLOBAL_PHY, in mtkswitch_reg_read32_mt7621()
138 low = mtkswitch_phy_read_locked(sc, MTKSWITCH_GLOBAL_PHY, in mtkswitch_reg_read32_mt7621()
140 hi = mtkswitch_phy_read_locked(sc, MTKSWITCH_GLOBAL_PHY, in mtkswitch_reg_read32_mt7621()
146 mtkswitch_reg_write32_mt7621(struct mtkswitch_softc *sc, int reg, uint32_t val) in mtkswitch_reg_write32_mt7621() argument
149 mtkswitch_phy_write_locked(sc, MTKSWITCH_GLOBAL_PHY, in mtkswitch_reg_write32_mt7621()
151 mtkswitch_phy_write_locked(sc, MTKSWITCH_GLOBAL_PHY, in mtkswitch_reg_write32_mt7621()
153 mtkswitch_phy_write_locked(sc, MTKSWITCH_GLOBAL_PHY, in mtkswitch_reg_write32_mt7621()
161 struct mtkswitch_softc *sc = device_get_softc(dev); in mtkswitch_reg_read() local
164 val = sc->hal.mtkswitch_read(sc, MTKSWITCH_REG32(reg)); in mtkswitch_reg_read()
173 struct mtkswitch_softc *sc = device_get_softc(dev); in mtkswitch_reg_write() local
176 tmp = sc->hal.mtkswitch_read(sc, MTKSWITCH_REG32(reg)); in mtkswitch_reg_write()
184 sc->hal.mtkswitch_write(sc, MTKSWITCH_REG32(reg), tmp); in mtkswitch_reg_write()
190 mtkswitch_reset(struct mtkswitch_softc *sc) in mtkswitch_reset() argument
198 mtkswitch_hw_setup(struct mtkswitch_softc *sc) in mtkswitch_hw_setup() argument
211 mtkswitch_hw_global_setup(struct mtkswitch_softc *sc) in mtkswitch_hw_global_setup() argument
220 mtkswitch_port_init(struct mtkswitch_softc *sc, int port) in mtkswitch_port_init() argument
227 val = sc->hal.mtkswitch_read(sc, MTKSWITCH_PCR(port)); in mtkswitch_port_init()
229 sc->hal.mtkswitch_write(sc, MTKSWITCH_PCR(port), val); in mtkswitch_port_init()
232 val = sc->hal.mtkswitch_read(sc, MTKSWITCH_PVC(port)); in mtkswitch_port_init()
234 sc->hal.mtkswitch_write(sc, MTKSWITCH_PVC(port), val); in mtkswitch_port_init()
237 if (port == sc->cpuport) in mtkswitch_port_init()
241 sc->hal.mtkswitch_write(sc, MTKSWITCH_PMCR(port), val); in mtkswitch_port_init()
245 mtkswitch_get_port_status(struct mtkswitch_softc *sc, int port) in mtkswitch_get_port_status() argument
249 MTKSWITCH_LOCK_ASSERT(sc, MA_OWNED); in mtkswitch_get_port_status()
251 val = sc->hal.mtkswitch_read(sc, MTKSWITCH_PMSR(port)); in mtkswitch_get_port_status()
273 mtkswitch_atu_flush(struct mtkswitch_softc *sc) in mtkswitch_atu_flush() argument
276 MTKSWITCH_LOCK_ASSERT(sc, MA_OWNED); in mtkswitch_atu_flush()
279 while (sc->hal.mtkswitch_read(sc, MTKSWITCH_ATC) & ATC_BUSY); in mtkswitch_atu_flush()
280 sc->hal.mtkswitch_write(sc, MTKSWITCH_ATC, ATC_BUSY | in mtkswitch_atu_flush()
282 while (sc->hal.mtkswitch_read(sc, MTKSWITCH_ATC) & ATC_BUSY); in mtkswitch_atu_flush()
288 mtkswitch_port_vlan_setup(struct mtkswitch_softc *sc, etherswitch_port_t *p) in mtkswitch_port_vlan_setup() argument
300 MTKSWITCH_LOCK_ASSERT(sc, MA_NOTOWNED); in mtkswitch_port_vlan_setup()
301 MTKSWITCH_LOCK(sc); in mtkswitch_port_vlan_setup()
305 err = sc->hal.mtkswitch_vlan_set_pvid(sc, p->es_port, in mtkswitch_port_vlan_setup()
308 MTKSWITCH_UNLOCK(sc); in mtkswitch_port_vlan_setup()
313 MTKSWITCH_UNLOCK(sc); in mtkswitch_port_vlan_setup()
319 mtkswitch_port_vlan_get(struct mtkswitch_softc *sc, etherswitch_port_t *p) in mtkswitch_port_vlan_get() argument
322 MTKSWITCH_LOCK_ASSERT(sc, MA_NOTOWNED); in mtkswitch_port_vlan_get()
323 MTKSWITCH_LOCK(sc); in mtkswitch_port_vlan_get()
326 sc->hal.mtkswitch_vlan_get_pvid(sc, p->es_port, &p->es_pvid); in mtkswitch_port_vlan_get()
334 MTKSWITCH_UNLOCK(sc); in mtkswitch_port_vlan_get()
340 mtkswitch_invalidate_vlan(struct mtkswitch_softc *sc, uint32_t vid) in mtkswitch_invalidate_vlan() argument
343 while (sc->hal.mtkswitch_read(sc, MTKSWITCH_VTCR) & VTCR_BUSY); in mtkswitch_invalidate_vlan()
344 sc->hal.mtkswitch_write(sc, MTKSWITCH_VTCR, VTCR_BUSY | in mtkswitch_invalidate_vlan()
346 while (sc->hal.mtkswitch_read(sc, MTKSWITCH_VTCR) & VTCR_BUSY); in mtkswitch_invalidate_vlan()
350 mtkswitch_vlan_init_hw(struct mtkswitch_softc *sc) in mtkswitch_vlan_init_hw() argument
354 MTKSWITCH_LOCK_ASSERT(sc, MA_NOTOWNED); in mtkswitch_vlan_init_hw()
355 MTKSWITCH_LOCK(sc); in mtkswitch_vlan_init_hw()
357 for (i = 0; i < sc->info.es_nvlangroups; i++) { in mtkswitch_vlan_init_hw()
358 mtkswitch_invalidate_vlan(sc, i); in mtkswitch_vlan_init_hw()
359 if (sc->sc_switchtype == MTK_SWITCH_MT7620) { in mtkswitch_vlan_init_hw()
360 val = sc->hal.mtkswitch_read(sc, MTKSWITCH_VTIM(i)); in mtkswitch_vlan_init_hw()
363 sc->hal.mtkswitch_write(sc, MTKSWITCH_VTIM(i), val); in mtkswitch_vlan_init_hw()
368 if (sc->sc_switchtype == MTK_SWITCH_MT7620) { in mtkswitch_vlan_init_hw()
376 for (i = 0; i < sc->info.es_nports; i++) in mtkswitch_vlan_init_hw()
378 sc->hal.mtkswitch_write(sc, MTKSWITCH_VAWD1, val); in mtkswitch_vlan_init_hw()
379 sc->hal.mtkswitch_write(sc, MTKSWITCH_VAWD2, 0); in mtkswitch_vlan_init_hw()
381 sc->hal.mtkswitch_write(sc, MTKSWITCH_VTCR, val); in mtkswitch_vlan_init_hw()
384 for (i = 0; i < sc->info.es_nports; i++) { in mtkswitch_vlan_init_hw()
385 sc->hal.mtkswitch_vlan_set_pvid(sc, i, 1); in mtkswitch_vlan_init_hw()
388 MTKSWITCH_UNLOCK(sc); in mtkswitch_vlan_init_hw()
392 mtkswitch_vlan_getvgroup(struct mtkswitch_softc *sc, etherswitch_vlangroup_t *v) in mtkswitch_vlan_getvgroup() argument
396 MTKSWITCH_LOCK_ASSERT(sc, MA_NOTOWNED); in mtkswitch_vlan_getvgroup()
398 if ((sc->vlan_mode != ETHERSWITCH_VLAN_DOT1Q) || in mtkswitch_vlan_getvgroup()
399 (v->es_vlangroup > sc->info.es_nvlangroups)) in mtkswitch_vlan_getvgroup()
409 MTKSWITCH_LOCK(sc); in mtkswitch_vlan_getvgroup()
410 if (sc->sc_switchtype == MTK_SWITCH_MT7620) { in mtkswitch_vlan_getvgroup()
411 v->es_vid = (sc->hal.mtkswitch_read(sc, in mtkswitch_vlan_getvgroup()
418 while (sc->hal.mtkswitch_read(sc, MTKSWITCH_VTCR) & VTCR_BUSY); in mtkswitch_vlan_getvgroup()
419 sc->hal.mtkswitch_write(sc, MTKSWITCH_VTCR, VTCR_BUSY | in mtkswitch_vlan_getvgroup()
421 while ((val = sc->hal.mtkswitch_read(sc, MTKSWITCH_VTCR)) & VTCR_BUSY); in mtkswitch_vlan_getvgroup()
423 MTKSWITCH_UNLOCK(sc); in mtkswitch_vlan_getvgroup()
427 val = sc->hal.mtkswitch_read(sc, MTKSWITCH_VAWD1); in mtkswitch_vlan_getvgroup()
431 MTKSWITCH_UNLOCK(sc); in mtkswitch_vlan_getvgroup()
436 val = sc->hal.mtkswitch_read(sc, MTKSWITCH_VAWD2); in mtkswitch_vlan_getvgroup()
437 for (i = 0; i < sc->info.es_nports; i++) { in mtkswitch_vlan_getvgroup()
442 MTKSWITCH_UNLOCK(sc); in mtkswitch_vlan_getvgroup()
447 mtkswitch_vlan_setvgroup(struct mtkswitch_softc *sc, etherswitch_vlangroup_t *v) in mtkswitch_vlan_setvgroup() argument
451 MTKSWITCH_LOCK_ASSERT(sc, MA_NOTOWNED); in mtkswitch_vlan_setvgroup()
453 if ((sc->vlan_mode != ETHERSWITCH_VLAN_DOT1Q) || in mtkswitch_vlan_setvgroup()
454 (v->es_vlangroup > sc->info.es_nvlangroups)) in mtkswitch_vlan_setvgroup()
461 MTKSWITCH_LOCK(sc); in mtkswitch_vlan_setvgroup()
462 while (sc->hal.mtkswitch_read(sc, MTKSWITCH_VTCR) & VTCR_BUSY); in mtkswitch_vlan_setvgroup()
463 if (sc->sc_switchtype == MTK_SWITCH_MT7620) { in mtkswitch_vlan_setvgroup()
464 val = sc->hal.mtkswitch_read(sc, in mtkswitch_vlan_setvgroup()
468 sc->hal.mtkswitch_write(sc, MTKSWITCH_VTIM(v->es_vlangroup), in mtkswitch_vlan_setvgroup()
477 sc->hal.mtkswitch_write(sc, MTKSWITCH_VAWD1, val); in mtkswitch_vlan_setvgroup()
481 for (i = 0; i < sc->info.es_nports; i++) in mtkswitch_vlan_setvgroup()
484 sc->hal.mtkswitch_write(sc, MTKSWITCH_VAWD2, val); in mtkswitch_vlan_setvgroup()
487 sc->hal.mtkswitch_write(sc, MTKSWITCH_VTCR, VTCR_BUSY | in mtkswitch_vlan_setvgroup()
489 while ((val = sc->hal.mtkswitch_read(sc, MTKSWITCH_VTCR)) & VTCR_BUSY); in mtkswitch_vlan_setvgroup()
491 MTKSWITCH_UNLOCK(sc); in mtkswitch_vlan_setvgroup()
500 mtkswitch_vlan_get_pvid(struct mtkswitch_softc *sc, int port, int *pvid) in mtkswitch_vlan_get_pvid() argument
503 MTKSWITCH_LOCK_ASSERT(sc, MA_OWNED); in mtkswitch_vlan_get_pvid()
505 *pvid = sc->hal.mtkswitch_read(sc, MTKSWITCH_PPBV1(port)); in mtkswitch_vlan_get_pvid()
512 mtkswitch_vlan_set_pvid(struct mtkswitch_softc *sc, int port, int pvid) in mtkswitch_vlan_set_pvid() argument
516 MTKSWITCH_LOCK_ASSERT(sc, MA_OWNED); in mtkswitch_vlan_set_pvid()
518 sc->hal.mtkswitch_write(sc, MTKSWITCH_PPBV1(port), val); in mtkswitch_vlan_set_pvid()
519 sc->hal.mtkswitch_write(sc, MTKSWITCH_PPBV2(port), val); in mtkswitch_vlan_set_pvid()
525 mtk_attach_switch_mt7620(struct mtkswitch_softc *sc) in mtk_attach_switch_mt7620() argument
528 sc->portmap = 0x7f; in mtk_attach_switch_mt7620()
529 sc->phymap = 0x1f; in mtk_attach_switch_mt7620()
531 sc->info.es_nports = 7; in mtk_attach_switch_mt7620()
532 sc->info.es_vlan_caps = ETHERSWITCH_VLAN_DOT1Q; in mtk_attach_switch_mt7620()
533 sc->info.es_nvlangroups = 16; in mtk_attach_switch_mt7620()
534 sprintf(sc->info.es_name, "Mediatek GSW"); in mtk_attach_switch_mt7620()
536 if (sc->sc_switchtype == MTK_SWITCH_MT7621) { in mtk_attach_switch_mt7620()
537 sc->hal.mtkswitch_read = mtkswitch_reg_read32_mt7621; in mtk_attach_switch_mt7620()
538 sc->hal.mtkswitch_write = mtkswitch_reg_write32_mt7621; in mtk_attach_switch_mt7620()
539 sc->info.es_nvlangroups = 4096; in mtk_attach_switch_mt7620()
541 sc->hal.mtkswitch_read = mtkswitch_reg_read32; in mtk_attach_switch_mt7620()
542 sc->hal.mtkswitch_write = mtkswitch_reg_write32; in mtk_attach_switch_mt7620()
545 sc->hal.mtkswitch_reset = mtkswitch_reset; in mtk_attach_switch_mt7620()
546 sc->hal.mtkswitch_hw_setup = mtkswitch_hw_setup; in mtk_attach_switch_mt7620()
547 sc->hal.mtkswitch_hw_global_setup = mtkswitch_hw_global_setup; in mtk_attach_switch_mt7620()
548 sc->hal.mtkswitch_port_init = mtkswitch_port_init; in mtk_attach_switch_mt7620()
549 sc->hal.mtkswitch_get_port_status = mtkswitch_get_port_status; in mtk_attach_switch_mt7620()
550 sc->hal.mtkswitch_atu_flush = mtkswitch_atu_flush; in mtk_attach_switch_mt7620()
551 sc->hal.mtkswitch_port_vlan_setup = mtkswitch_port_vlan_setup; in mtk_attach_switch_mt7620()
552 sc->hal.mtkswitch_port_vlan_get = mtkswitch_port_vlan_get; in mtk_attach_switch_mt7620()
553 sc->hal.mtkswitch_vlan_init_hw = mtkswitch_vlan_init_hw; in mtk_attach_switch_mt7620()
554 sc->hal.mtkswitch_vlan_getvgroup = mtkswitch_vlan_getvgroup; in mtk_attach_switch_mt7620()
555 sc->hal.mtkswitch_vlan_setvgroup = mtkswitch_vlan_setvgroup; in mtk_attach_switch_mt7620()
556 sc->hal.mtkswitch_vlan_get_pvid = mtkswitch_vlan_get_pvid; in mtk_attach_switch_mt7620()
557 sc->hal.mtkswitch_vlan_set_pvid = mtkswitch_vlan_set_pvid; in mtk_attach_switch_mt7620()
558 sc->hal.mtkswitch_phy_read = mtkswitch_phy_read; in mtk_attach_switch_mt7620()
559 sc->hal.mtkswitch_phy_write = mtkswitch_phy_write; in mtk_attach_switch_mt7620()
560 sc->hal.mtkswitch_reg_read = mtkswitch_reg_read; in mtk_attach_switch_mt7620()
561 sc->hal.mtkswitch_reg_write = mtkswitch_reg_write; in mtk_attach_switch_mt7620()