Lines Matching +full:sun50i +full:- +full:a64 +full:- +full:usb +full:- +full:phy
1 /*-
27 * Allwinner USB PHY
46 #include <dev/phy/phy_usb.h>
125 { "allwinner,sun4i-a10-usb-phy", (uintptr_t)&a10_usbphy_conf },
126 { "allwinner,sun5i-a13-usb-phy", (uintptr_t)&a13_usbphy_conf },
127 { "allwinner,sun6i-a31-usb-phy", (uintptr_t)&a31_usbphy_conf },
128 { "allwinner,sun7i-a20-usb-phy", (uintptr_t)&a20_usbphy_conf },
129 { "allwinner,sun8i-h3-usb-phy", (uintptr_t)&h3_usbphy_conf },
130 { "allwinner,sun50i-a64-usb-phy", (uintptr_t)&a64_usbphy_conf },
131 { "allwinner,sun8i-a83t-usb-phy", (uintptr_t)&a83t_usbphy_conf },
132 { "allwinner,sun50i-h6-usb-phy", (uintptr_t)&h6_usbphy_conf },
148 /* Phy class and methods. */
149 static int awusbphy_phy_enable(struct phynode *phy, bool enable);
150 static int awusbphy_get_mode(struct phynode *phy, int *mode);
151 static int awusbphy_set_mode(struct phynode *phy, int mode);
198 if (sc->pmu[phyno] == NULL) in awusbphy_configure()
201 if (sc->phy_conf->pmu_unk1 == true) in awusbphy_configure()
202 CLR4(sc->pmu[phyno], PMU_UNK_H3, PMU_UNK_H3_CLR); in awusbphy_configure()
204 SET4(sc->pmu[phyno], PMU_IRQ_ENABLE, PMU_ULPI_BYPASS | in awusbphy_configure()
223 sc->phy_conf = (struct aw_usbphy_conf *)ofw_bus_search_compatible(dev, compat_data)->ocd_data; in awusbphy_init()
226 if (ofw_bus_find_string_index(node, "reg-names", "phy_ctrl", &rid) != 0) { in awusbphy_init()
227 device_printf(dev, "Cannot locate phy control resource\n"); in awusbphy_init()
230 sc->phy_ctrl = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, in awusbphy_init()
232 if (sc->phy_ctrl == NULL) { in awusbphy_init()
247 /* De-assert resets */ in awusbphy_init()
251 device_printf(dev, "couldn't de-assert reset %d\n", in awusbphy_init()
258 error = gpio_pin_get_by_ofw_property(dev, node, "usb0_id_det-gpios", in awusbphy_init()
259 &sc->id_det_pin); in awusbphy_init()
261 sc->id_det_valid = 1; in awusbphy_init()
262 error = gpio_pin_get_by_ofw_property(dev, node, "usb0_vbus_det-gpios", in awusbphy_init()
263 &sc->vbus_det_pin); in awusbphy_init()
265 sc->vbus_det_valid = 1; in awusbphy_init()
267 sc->reg = malloc(sizeof(*(sc->reg)) * sc->phy_conf->num_phys, M_DEVBUF, in awusbphy_init()
269 sc->pmu = malloc(sizeof(*(sc->pmu)) * sc->phy_conf->num_phys, M_DEVBUF, in awusbphy_init()
272 for (off = 0; off < sc->phy_conf->num_phys; off++) { in awusbphy_init()
273 snprintf(pname, sizeof(pname), "usb%d_vbus-supply", off); in awusbphy_init()
275 sc->reg[off] = reg; in awusbphy_init()
278 if (ofw_bus_find_string_index(node, "reg-names", in awusbphy_init()
282 sc->pmu[off] = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, in awusbphy_init()
284 if (sc->pmu[off] == NULL) { in awusbphy_init()
290 /* Enable OTG PHY for host mode */ in awusbphy_init()
291 val = bus_read_4(sc->phy_ctrl, PHY_CSR); in awusbphy_init()
298 bus_write_4(sc->phy_ctrl, PHY_CSR, val); in awusbphy_init()
312 if (sc->vbus_det_valid) { in awusbphy_vbus_detect()
313 error = gpio_pin_is_active(sc->vbus_det_pin, &active); in awusbphy_vbus_detect()
323 /* TODO check vbus_power-supply. */ in awusbphy_vbus_detect()
336 intptr_t phy; in awusbphy_phy_enable() local
342 phy = phynode_get_id(phynode); in awusbphy_phy_enable()
345 if (phy < 0 || phy >= sc->phy_conf->num_phys) in awusbphy_phy_enable()
348 /* Configure PHY */ in awusbphy_phy_enable()
349 awusbphy_configure(dev, phy); in awusbphy_phy_enable()
352 reg = sc->reg[phy]; in awusbphy_phy_enable()
356 if (phy == 0) { in awusbphy_phy_enable()
357 /* If an external vbus is detected, do not enable phy 0 */ in awusbphy_phy_enable()
362 /* TODO check vbus_power-supply as well. */ in awusbphy_phy_enable()
363 if (sc->vbus_det_valid && vbus_det == 1) { in awusbphy_phy_enable()
371 /* Depending on the PHY we need to route OTG to OHCI/EHCI */ in awusbphy_phy_enable()
379 "couldn't %s regulator for phy %jd\n", in awusbphy_phy_enable()
380 enable ? "enable" : "disable", (intmax_t)phy); in awusbphy_phy_enable()
396 *mode = sc->mode; in awusbphy_get_mode()
405 intptr_t phy; in awusbphy_set_mode() local
411 phy = phynode_get_id(phynode); in awusbphy_set_mode()
414 if (phy != 0) { in awusbphy_set_mode()
420 if (sc->mode == mode) in awusbphy_set_mode()
429 val = bus_read_4(sc->phy_ctrl, PHY_CSR); in awusbphy_set_mode()
440 if (sc->phy_conf->phy0_route) in awusbphy_set_mode()
441 CLR4(sc->phy_ctrl, OTG_PHY_CFG, OTG_PHY_ROUTE_OTG); in awusbphy_set_mode()
445 if (sc->phy_conf->phy0_route) in awusbphy_set_mode()
446 SET4(sc->phy_ctrl, OTG_PHY_CFG, OTG_PHY_ROUTE_OTG); in awusbphy_set_mode()
452 bus_write_4(sc->phy_ctrl, PHY_CSR, val); in awusbphy_set_mode()
453 sc->mode = mode; in awusbphy_set_mode()
463 if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0) in awusbphy_probe()
466 device_set_desc(dev, "Allwinner USB PHY"); in awusbphy_probe()
482 device_printf(dev, "failed to initialize USB PHY, error %d\n", in awusbphy_attach()
488 for (i = 0; i < sc->phy_conf->num_phys; i++) { in awusbphy_attach()
495 device_printf(dev, "failed to create USB PHY\n"); in awusbphy_attach()
499 device_printf(dev, "failed to create USB PHY\n"); in awusbphy_attach()