Lines Matching +full:mux +full:- +full:int +full:- +full:port

1 /*-
49 #include <dt-bindings/pinctrl/pinctrl-tegra-xusb.h>
170 #define WR4(_sc, _r, _v) bus_write_4((_sc)->mem_res, (_r), (_v))
171 #define RD4(_sc, _r) bus_read_4((_sc)->mem_res, (_r))
177 int phy_ena_cnt;
190 {"nvidia,tegra124-xusb-padctl", 1},
207 int idx;
208 int (*init)(struct padctl_softc *sc,
209 struct padctl_port *port);
219 static int usb3_port_init(struct padctl_softc *sc, struct padctl_port *port);
221 #define PORT(t, n, p, i) { \ macro
223 .name = n "-" #p, \
229 PORT(PADCTL_PORT_USB2, "usb2", 0, NULL),
230 PORT(PADCTL_PORT_USB2, "usb2", 1, NULL),
231 PORT(PADCTL_PORT_USB2, "usb2", 2, NULL),
232 PORT(PADCTL_PORT_ULPI, "ulpi", 0, NULL),
233 PORT(PADCTL_PORT_HSIC, "hsic", 0, NULL),
234 PORT(PADCTL_PORT_HSIC, "hsic", 1, NULL),
235 PORT(PADCTL_PORT_USB3, "usb3", 0, usb3_port_init),
236 PORT(PADCTL_PORT_USB3, "usb3", 1, usb3_port_init),
239 /* Pads - a group of lannes. */
252 int (*powerup)(struct padctl_softc *sc,
254 int (*powerdown)(struct padctl_softc *sc,
259 int nlanes;
262 static int usb2_powerup(struct padctl_softc *sc, struct padctl_lane *lane);
263 static int usb2_powerdown(struct padctl_softc *sc, struct padctl_lane *lane);
264 static int pcie_powerup(struct padctl_softc *sc, struct padctl_lane *lane);
265 static int pcie_powerdown(struct padctl_softc *sc, struct padctl_lane *lane);
266 static int sata_powerup(struct padctl_softc *sc, struct padctl_lane *lane);
267 static int sata_powerdown(struct padctl_softc *sc, struct padctl_lane *lane);
286 static char *pci_mux[] = {"pcie", "usb3-ss", "sata", "rsvd"};
290 int idx;
294 char **mux; member
295 int nmux;
299 struct padctl_port *port; member
300 int mux_idx;
305 .name = n "-" #p, \
310 .mux = mx, \
328 /* Define all possible mappings for USB3 port lanes */
330 int port_idx;
332 int lane_idx;
341 LANE_MAP(0, PADCTL_PAD_PCIE, 0), /* port USB3-0 -> lane PCIE-0 */
342 LANE_MAP(1, PADCTL_PAD_PCIE, 1), /* port USB3-1 -> lane PCIE-1 */
343 /* -- or -- */
344 LANE_MAP(1, PADCTL_PAD_SATA, 0), /* port USB3-1 -> lane SATA-0 */
348 static int xusbpadctl_phy_enable(struct phynode *phy, bool enable);
359 /* -------------------------------------------------------------------------
363 static int
364 usb3_port_init(struct padctl_softc *sc, struct padctl_port *port) in usb3_port_init() argument
369 if (port->internal) in usb3_port_init()
370 reg &= ~SS_PORT_MAP_PORT_INTERNAL(port->idx); in usb3_port_init()
372 reg |= SS_PORT_MAP_PORT_INTERNAL(port->idx); in usb3_port_init()
373 reg &= ~SS_PORT_MAP_PORT_MAP(port->idx, ~0); in usb3_port_init()
374 reg |= SS_PORT_MAP_PORT_MAP(port->idx, port->companion); in usb3_port_init()
377 reg = RD4(sc, XUSB_PADCTL_IOPHY_USB3_PAD_CTL2(port->idx)); in usb3_port_init()
384 WR4(sc, XUSB_PADCTL_IOPHY_USB3_PAD_CTL2(port->idx), reg); in usb3_port_init()
386 WR4(sc, XUSB_PADCTL_IOPHY_USB3_PAD_CTL4(port->idx), in usb3_port_init()
390 reg &= ~ELPG_PROGRAM_SSP_ELPG_VCORE_DOWN(port->idx); in usb3_port_init()
395 reg &= ~ELPG_PROGRAM_SSP_ELPG_CLAMP_EN_EARLY(port->idx); in usb3_port_init()
400 reg &= ~ELPG_PROGRAM_SSP_ELPG_CLAMP_EN(port->idx); in usb3_port_init()
407 static int
411 int i; in pcie_powerup()
430 for (i = 100; i > 0; i--) { in pcie_powerup()
437 device_printf(sc->dev, "Failed to power up PCIe phy\n"); in pcie_powerup()
441 reg |= USB3_PAD_MUX_PCIE_IDDQ_DISABLE(lane->idx); in pcie_powerup()
447 static int
453 reg &= ~USB3_PAD_MUX_PCIE_IDDQ_DISABLE(lane->idx); in pcie_powerdown()
465 static int
469 int i; in sata_powerup()
489 for (i = 100; i >= 0; i--) { in sata_powerup()
496 device_printf(sc->dev, "Failed to power up SATA phy\n"); in sata_powerup()
510 static int
544 static int
548 struct padctl_port *port; in usb2_powerup() local
549 int rv; in usb2_powerup()
551 port = search_lane_port(sc, lane); in usb2_powerup()
552 if (port == NULL) { in usb2_powerup()
553 device_printf(sc->dev, "Cannot find port for lane: %s\n", in usb2_powerup()
554 lane->name); in usb2_powerup()
559 reg |= USB2_BIAS_PAD_CTL0_HS_SQUELCH_LEVEL(sc->hs_squelch_level); in usb2_powerup()
564 reg &= ~USB2_PORT_CAP_PORT_CAP(lane->idx, ~0); in usb2_powerup()
565 reg |= USB2_PORT_CAP_PORT_CAP(lane->idx, USB2_PORT_CAP_PORT_CAP_HOST); in usb2_powerup()
568 reg = RD4(sc, XUSB_PADCTL_USB2_OTG_PAD_CTL0(lane->idx)); in usb2_powerup()
577 if (lane->idx == 0) { in usb2_powerup()
578 reg |= USB2_OTG_PAD_CTL0_HS_CURR_LEVEL(sc->hs_curr_level_0); in usb2_powerup()
581 reg |= USB2_OTG_PAD_CTL0_HS_CURR_LEVEL(sc->hs_curr_level_123); in usb2_powerup()
584 WR4(sc, XUSB_PADCTL_USB2_OTG_PAD_CTL0(lane->idx), reg); in usb2_powerup()
586 reg = RD4(sc, XUSB_PADCTL_USB2_OTG_PAD_CTL1(lane->idx)); in usb2_powerup()
593 reg |= USB2_OTG_PAD_CTL1_TERM_RANGE_ADJ(sc->hs_term_range_adj); in usb2_powerup()
594 reg |= USB2_OTG_PAD_CTL1_HS_IREF_CAP(sc->hs_iref_cap); in usb2_powerup()
595 WR4(sc, XUSB_PADCTL_USB2_OTG_PAD_CTL1(lane->idx), reg); in usb2_powerup()
597 if (port != NULL && port->supply_vbus != NULL) { in usb2_powerup()
598 rv = regulator_enable(port->supply_vbus); in usb2_powerup()
600 device_printf(sc->dev, in usb2_powerup()
612 static int
616 struct padctl_port *port; in usb2_powerdown() local
617 int rv; in usb2_powerdown()
619 port = search_lane_port(sc, lane); in usb2_powerdown()
620 if (port == NULL) { in usb2_powerdown()
621 device_printf(sc->dev, "Cannot find port for lane: %s\n", in usb2_powerdown()
622 lane->name); in usb2_powerdown()
628 if (port != NULL && port->supply_vbus != NULL) { in usb2_powerdown()
629 rv = regulator_enable(port->supply_vbus); in usb2_powerdown()
631 device_printf(sc->dev, in usb2_powerdown()
639 static int
662 static int
685 static int
693 int rv; in xusbpadctl_phy_enable()
704 if (!lane->enabled) { in xusbpadctl_phy_enable()
706 lane->name); in xusbpadctl_phy_enable()
709 pad = lane->pad; in xusbpadctl_phy_enable()
711 if (sc->phy_ena_cnt == 0) { in xusbpadctl_phy_enable()
716 sc->phy_ena_cnt++; in xusbpadctl_phy_enable()
720 rv = pad->powerup(sc, lane); in xusbpadctl_phy_enable()
722 rv = pad->powerdown(sc, lane); in xusbpadctl_phy_enable()
727 if (sc->phy_ena_cnt == 1) { in xusbpadctl_phy_enable()
732 sc->phy_ena_cnt--; in xusbpadctl_phy_enable()
738 /* -------------------------------------------------------------------------
745 int i; in search_port()
757 int i; in search_lane_port()
771 int i; in search_lane()
781 search_pad_lane(struct padctl_softc *sc, enum padctl_pad_type type, int idx) in search_pad_lane()
783 int i; in search_pad_lane()
788 if (type == lanes_tbl[i].pad->type && idx == lanes_tbl[i].idx) in search_pad_lane()
795 search_usb3_pad_lane(struct padctl_softc *sc, int idx) in search_usb3_pad_lane()
797 int i; in search_usb3_pad_lane()
808 if (strcmp(tmp->mux[tmp->mux_idx], "usb3-ss") != 0) in search_usb3_pad_lane()
811 device_printf(sc->dev, "Duplicated mappings found for" in search_usb3_pad_lane()
812 " lanes: %s and %s\n", lane->name, tmp->name); in search_usb3_pad_lane()
823 int i; in search_pad()
832 static int
835 int i; in search_mux()
837 for (i = 0; i < lane->nmux; i++) { in search_mux()
838 if (strcmp(fnc_name, lane->mux[i]) == 0) in search_mux()
841 return (-1); in search_mux()
844 static int
849 reg = RD4(sc, lane->reg); in config_lane()
850 reg &= ~(lane->mask << lane->shift); in config_lane()
851 reg |= (lane->mux_idx & lane->mask) << lane->shift; in config_lane()
852 WR4(sc, lane->reg, reg); in config_lane()
856 static int
864 int rv; in process_lane()
870 device_printf(sc->dev, "Cannot read lane name.\n"); in process_lane()
876 device_printf(sc->dev, "Unknown lane: %s\n", name); in process_lane()
881 /* Read function (mux) settings. */ in process_lane()
884 device_printf(sc->dev, "Cannot read lane function.\n"); in process_lane()
889 lane->mux_idx = search_mux(sc, lane, function); in process_lane()
890 if (lane->mux_idx == ~0) { in process_lane()
891 device_printf(sc->dev, "Unknown function %s for lane %s\n", in process_lane()
899 device_printf(sc->dev, "Cannot configure lane: %s: %d\n", in process_lane()
904 lane->pad = pad; in process_lane()
905 lane->enabled = true; in process_lane()
906 pad->lanes[pad->nlanes++] = lane; in process_lane()
910 phy_init.id = lane - lanes_tbl; in process_lane()
912 phynode = phynode_create(sc->dev, &xusbpadctl_phynode_class, &phy_init); in process_lane()
914 device_printf(sc->dev, "Cannot create phy\n"); in process_lane()
919 device_printf(sc->dev, "Cannot create phy\n"); in process_lane()
933 static int
938 int rv; in process_pad()
943 device_printf(sc->dev, "Cannot read pad name.\n"); in process_pad()
948 device_printf(sc->dev, "Unknown pad: %s\n", name); in process_pad()
956 device_printf(sc->dev, "Cannot find regulators subnode\n"); in process_pad()
969 pad->enabled = true; in process_pad()
977 static int
981 struct padctl_port *port; in process_port() local
983 int rv; in process_port()
988 device_printf(sc->dev, "Cannot read port name.\n"); in process_port()
992 port = search_port(sc, name); in process_port()
993 if (port == NULL) { in process_port()
994 device_printf(sc->dev, "Unknown port: %s\n", name); in process_port()
999 if (port->type == PADCTL_PORT_USB3) { in process_port()
1000 rv = OF_getencprop(node, "nvidia,usb2-companion", in process_port()
1001 &(port->companion), sizeof(port->companion)); in process_port()
1003 device_printf(sc->dev, in process_port()
1004 "Missing 'nvidia,usb2-companion' property " in process_port()
1005 "for port: %s\n", name); in process_port()
1011 if (OF_hasprop(node, "vbus-supply")) { in process_port()
1012 rv = regulator_get_by_ofw_property(sc->dev, 0, in process_port()
1013 "vbus-supply", &port->supply_vbus); in process_port()
1015 device_printf(sc->dev, in process_port()
1016 "Cannot get 'vbus-supply' regulator " in process_port()
1017 "for port: %s\n", name); in process_port()
1024 port->internal = true; in process_port()
1026 if (port->lane == NULL) { in process_port()
1027 switch(port->type) { in process_port()
1030 port->lane = search_pad_lane(sc, PADCTL_PAD_USB2, in process_port()
1031 port->idx); in process_port()
1034 port->lane = search_pad_lane(sc, PADCTL_PAD_ULPI, in process_port()
1035 port->idx); in process_port()
1038 port->lane = search_pad_lane(sc, PADCTL_PAD_HSIC, in process_port()
1039 port->idx); in process_port()
1042 port->lane = search_usb3_pad_lane(sc, port->idx); in process_port()
1046 if (port->lane == NULL) { in process_port()
1047 device_printf(sc->dev, "Cannot find lane for port: %s\n", name); in process_port()
1051 port->enabled = true; in process_port()
1059 static int
1063 int rv; in parse_fdt()
1069 device_printf(sc->dev, "Cannot find pads subnode.\n"); in parse_fdt()
1082 device_printf(sc->dev, "Cannot find ports subnode.\n"); in parse_fdt()
1103 sc->hs_curr_level_0 = FUSE_XUSB_CALIB_HS_CURR_LEVEL_0(reg); in load_calibration()
1104 sc->hs_curr_level_123 = FUSE_XUSB_CALIB_HS_CURR_LEVEL_123(reg); in load_calibration()
1105 sc->hs_iref_cap = FUSE_XUSB_CALIB_HS_IREF_CAP(reg); in load_calibration()
1106 sc->hs_squelch_level = FUSE_XUSB_CALIB_HS_SQUELCH_LEVEL(reg); in load_calibration()
1107 sc->hs_term_range_adj = FUSE_XUSB_CALIB_HS_TERM_RANGE_ADJ(reg); in load_calibration()
1110 /* -------------------------------------------------------------------------
1114 static int
1121 if (!ofw_bus_search_compatible(dev, compat_data)->ocd_data) in xusbpadctl_probe()
1128 static int
1136 static int
1140 int i, rid, rv; in xusbpadctl_attach()
1141 struct padctl_port *port; in xusbpadctl_attach() local
1145 sc->dev = dev; in xusbpadctl_attach()
1149 sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, in xusbpadctl_attach()
1151 if (sc->mem_res == NULL) { in xusbpadctl_attach()
1156 rv = hwreset_get_by_ofw_name(dev, 0, "padctl", &sc->rst); in xusbpadctl_attach()
1161 rv = hwreset_deassert(sc->rst); in xusbpadctl_attach()
1175 port = ports_tbl + i; in xusbpadctl_attach()
1176 if (!port->enabled) in xusbpadctl_attach()
1178 if (port->init == NULL) in xusbpadctl_attach()
1180 rv = port->init(sc, port); in xusbpadctl_attach()
1182 device_printf(dev, "Cannot init port '%s'\n", in xusbpadctl_attach()
1183 port->name); in xusbpadctl_attach()