Lines Matching +full:sun4i +full:- +full:a10 +full:- +full:musb

1 /*-
7 * Cambridge Computer Laboratory under DARPA/AFRL contract FA8750-10-C-0237
33 * Allwinner USB Dual-Role Device (DRD) controller
78 #define bs_parent_space(bs) ((bs)->bs_parent)
88 { "allwinner,sun4i-a10-musb", AWUSB_OKAY },
89 { "allwinner,sun6i-a31-musb", AWUSB_OKAY },
90 { "allwinner,sun8i-a33-musb", AWUSB_OKAY | AWUSB_NO_CONFDATA },
91 { "allwinner,sun8i-h3-musb", AWUSB_OKAY | AWUSB_NO_CONFDATA },
92 { "allwinner,sun20i-d1-musb", AWUSB_OKAY | AWUSB_NO_CONFDATA },
103 .ep_end = -1,
114 .ep_end = -1,
131 { -1, 0 }
353 intusb = MUSB2_READ_1(&sc->sc, MUSB2_REG_INTUSB);
354 inttx = MUSB2_READ_2(&sc->sc, MUSB2_REG_INTTX);
355 intrx = MUSB2_READ_2(&sc->sc, MUSB2_REG_INTRX);
360 MUSB2_WRITE_1(&sc->sc, MUSB2_REG_INTUSB, intusb);
362 MUSB2_WRITE_2(&sc->sc, MUSB2_REG_INTTX, inttx);
364 MUSB2_WRITE_2(&sc->sc, MUSB2_REG_INTRX, intrx);
375 if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0)
392 sc->flags = ofw_bus_search_compatible(dev, compat_data)->ocd_data;
394 error = bus_alloc_resources(dev, awusbdrd_spec, sc->res);
402 usb_mode[sizeof(usb_mode) - 1] = 0;
411 * XXX phy has PHY_USB_MODE_OTG, but MUSB does not have
413 * from phy layer (that detects them) to MUSB.
424 error = clk_get_by_ofw_index(dev, 0, 0, &sc->clk);
429 (void)hwreset_get_by_ofw_idx(dev, 0, 0, &sc->reset);
432 error = clk_enable(sc->clk);
437 if (sc->reset != NULL) {
438 error = hwreset_deassert(sc->reset);
440 device_printf(dev, "failed to de-assert reset: %d\n",
447 (void)phy_get_by_ofw_name(dev, 0, "usb", &sc->phy);
448 if (sc->phy != NULL) {
451 error = phy_enable(sc->phy);
457 error = phy_usb_set_mode(sc->phy, phy_mode);
464 sc->sc.sc_bus.parent = dev;
465 sc->sc.sc_bus.devices = sc->sc.sc_devices;
466 sc->sc.sc_bus.devices_max = MUSB2_MAX_DEVICES;
467 sc->sc.sc_bus.dma_bits = 32;
469 error = usb_bus_mem_alloc_all(&sc->sc.sc_bus, USB_GET_DMA_TAG(dev),
477 sc->bs.bs_parent = rman_get_bustag(sc->res[0]);
479 sc->bs.bs_cookie = rman_get_bustag(sc->res[0]);
482 if ((sc->flags & AWUSB_NO_CONFDATA) == AWUSB_NO_CONFDATA)
483 sc->bs.bs_r_1 = awusbdrd_bs_r_1_noconf;
485 sc->bs.bs_r_1 = awusbdrd_bs_r_1;
486 sc->bs.bs_r_2 = awusbdrd_bs_r_2;
487 sc->bs.bs_w_1 = awusbdrd_bs_w_1;
488 sc->bs.bs_w_2 = awusbdrd_bs_w_2;
489 sc->bs.bs_rm_1 = awusbdrd_bs_rm_1;
490 sc->bs.bs_rm_4 = awusbdrd_bs_rm_4;
491 sc->bs.bs_wm_1 = awusbdrd_bs_wm_1;
492 sc->bs.bs_wm_4 = awusbdrd_bs_wm_4;
494 sc->sc.sc_io_tag = &sc->bs;
495 sc->sc.sc_io_hdl = rman_get_bushandle(sc->res[0]);
496 sc->sc.sc_io_size = rman_get_size(sc->res[0]);
498 sc->sc.sc_bus.bdev = device_add_child(dev, "usbus", DEVICE_UNIT_ANY);
499 if (sc->sc.sc_bus.bdev == NULL) {
503 device_set_ivars(sc->sc.sc_bus.bdev, &sc->sc.sc_bus);
504 sc->sc.sc_id = 0;
505 sc->sc.sc_platform_data = sc;
506 sc->sc.sc_mode = musb_mode;
507 if (ofw_bus_is_compatible(dev, "allwinner,sun8i-h3-musb")) {
508 sc->sc.sc_ep_cfg = musbotg_ep_allwinner_h3;
509 sc->sc.sc_ep_max = DRD_EP_MAX_H3;
511 sc->sc.sc_ep_cfg = musbotg_ep_allwinner;
512 sc->sc.sc_ep_max = DRD_EP_MAX;
515 error = bus_setup_intr(dev, sc->res[1], INTR_MPSAFE | INTR_TYPE_BIO,
516 NULL, awusbdrd_intr, sc, &sc->sc.sc_intr_hdl);
521 bus_write_1(sc->res[0], MUSB2_REG_AWIN_VEND0, VEND0_PIO_MODE);
524 /* Map SRAMD area to USB0 (sun4i/sun7i only) */
533 error = musbotg_init(&sc->sc);
537 error = device_probe_and_attach(sc->sc.sc_bus.bdev);
541 musbotg_vbus_interrupt(&sc->sc, 1); /* XXX VBUS */
546 if (sc->phy != NULL) {
548 (void)phy_disable(sc->phy);
549 phy_release(sc->phy);
551 if (sc->reset != NULL) {
552 hwreset_assert(sc->reset);
553 hwreset_release(sc->reset);
555 if (sc->clk != NULL)
556 clk_release(sc->clk);
557 bus_release_resources(dev, awusbdrd_spec, sc->res);
573 musbotg_uninit(&sc->sc);
574 error = bus_teardown_intr(dev, sc->res[1], sc->sc.sc_intr_hdl);
578 usb_bus_mem_free_all(&sc->sc.sc_bus, NULL);
580 if (sc->phy != NULL) {
581 if (sc->sc.sc_mode == MUSB2_HOST_MODE)
582 phy_disable(sc->phy);
583 phy_release(sc->phy);
585 if (sc->reset != NULL) {
586 if (hwreset_assert(sc->reset) != 0)
588 hwreset_release(sc->reset);
590 if (sc->clk != NULL)
591 clk_release(sc->clk);
593 bus_release_resources(dev, awusbdrd_spec, sc->res);