Exemplo n.º 1
0
static void omap_ehci_soft_phy_reset(int port)
{
	struct ulpi_viewport ulpi_vp;

	ulpi_vp.viewport_addr = (u32)&ehci->insreg05_utmi_ulpi;
	ulpi_vp.port_num = port;

	ulpi_reset(&ulpi_vp);
}
Exemplo n.º 2
0
static void
imxehci_attach(device_t parent, device_t self, void *aux)
{
	struct imxusbc_attach_args *aa = aux;
	struct imxusbc_softc *usbc = device_private(parent);
	struct imxehci_softc *sc = device_private(self);
	ehci_softc_t *hsc = &sc->sc_hsc;
	bus_space_tag_t iot;
	uint16_t hcirev;
	usbd_status r;
	uint32_t id, hwhost, hwdevice;
	const char *comma;

	sc->sc_hsc.sc_dev = self;
	iot = sc->sc_iot = sc->sc_hsc.iot = aa->aa_iot;
	sc->sc_unit = aa->aa_unit;
	sc->sc_usbc = usbc;
	hsc->sc_bus.hci_private = sc;
	hsc->sc_flags |= EHCIF_ETTF;
	hsc->sc_vendor_init = imxehci_init;

	aprint_naive("\n");
	aprint_normal(": i.MX USB Controller\n");

	/* per unit registers */
	if (bus_space_subregion(iot, aa->aa_ioh,
		aa->aa_unit * IMXUSB_EHCI_SIZE, IMXUSB_EHCI_SIZE,
		&sc->sc_ioh) ||
	    bus_space_subregion(iot, aa->aa_ioh,
		aa->aa_unit * IMXUSB_EHCI_SIZE + IMXUSB_EHCIREGS,
		IMXUSB_EHCI_SIZE - IMXUSB_EHCIREGS,
		&sc->sc_hsc.ioh)) {

		aprint_error_dev(self, "can't subregion\n");
		return;
	}

	id = bus_space_read_4(iot, sc->sc_ioh, IMXUSB_ID);
	hcirev = bus_space_read_2(iot, sc->sc_hsc.ioh, EHCI_HCIVERSION);

	aprint_normal_dev(self,
	    "id=%d revision=%d HCI revision=0x%x\n",
	    (int)__SHIFTOUT(id, IMXUSB_ID_ID),
	    (int)__SHIFTOUT(id, IMXUSB_ID_REVISION),
	    hcirev);

	hwhost = bus_space_read_4(iot, sc->sc_ioh, IMXUSB_HWHOST);
	hwdevice = bus_space_read_4(iot, sc->sc_ioh, IMXUSB_HWDEVICE);

	aprint_normal_dev(self, "");

	comma = "";
	if (hwhost & HWHOST_HC) {
		int n_ports = 1 + __SHIFTOUT(hwhost, HWHOST_NPORT);
		aprint_normal("%d host port%s",
		    n_ports, n_ports > 1 ? "s" : "");
		comma = ", ";
	}

	if (hwdevice & HWDEVICE_DC) {
		int n_endpoints = __SHIFTOUT(hwdevice, HWDEVICE_DEVEP);
		aprint_normal("%sdevice capable, %d endpoint%s",
		    comma,
		    n_endpoints, n_endpoints > 1 ? "s" : "");
	}
	aprint_normal("\n");

	sc->sc_hsc.sc_bus.dmatag = aa->aa_dmat;

	sc->sc_hsc.sc_offs = bus_space_read_1(iot, sc->sc_hsc.ioh,
	    EHCI_CAPLENGTH);

	/* Platform dependent setup */
	if (usbc->sc_init_md_hook)
		usbc->sc_init_md_hook(sc);
	
	imxehci_reset(sc);
	imxehci_select_interface(sc, sc->sc_iftype);

	if (sc->sc_iftype == IMXUSBC_IF_ULPI) {
		bus_space_write_4(sc->sc_iot, sc->sc_ioh, IMXUSB_ULPIVIEW, 0);

		aprint_normal_dev(hsc->sc_dev,
		    "ULPI phy VID 0x%04x PID 0x%04x\n",
		    (imxusb_ulpi_read(sc, ULPI_VENDOR_ID_LOW) |
			imxusb_ulpi_read(sc, ULPI_VENDOR_ID_HIGH) << 8),
		    (imxusb_ulpi_read(sc, ULPI_PRODUCT_ID_LOW) |
			imxusb_ulpi_read(sc, ULPI_PRODUCT_ID_HIGH) << 8));

		ulpi_reset(sc);

	}

	if (usbc->sc_setup_md_hook)
		usbc->sc_setup_md_hook(sc, IMXUSB_HOST);

	if (sc->sc_iftype == IMXUSBC_IF_ULPI) {
#if 0
		if(hsc->sc_bus.usbrev == USBREV_2_0)
			ulpi_write(hsc, ULPI_FUNCTION_CONTROL + ULPI_REG_CLEAR, (1 << 0));
		else
			ulpi_write(hsc, ULPI_FUNCTION_CONTROL + ULPI_REG_SET, (1 << 2));
#endif

		imxusb_ulpi_write(sc, ULPI_FUNCTION_CONTROL + ULPI_REG_CLEAR,
		    OTG_CONTROL_IDPULLUP);

		imxusb_ulpi_write(sc, ULPI_OTG_CONTROL + ULPI_REG_SET,
		    OTG_CONTROL_USEEXTVBUSIND |
		    OTG_CONTROL_DRVVBUSEXT |
		    OTG_CONTROL_DRVVBUS |
		    OTG_CONTROL_CHRGVBUS
		    );
	}

	/* Disable interrupts, so we don't get any spurious ones. */
	EOWRITE4(hsc, EHCI_USBINTR, 0);

	intr_establish(aa->aa_irq, IPL_USB, IST_LEVEL, ehci_intr, hsc);

	/* Figure out vendor for root hub descriptor. */
	strlcpy(hsc->sc_vendor, "i.MX", sizeof(hsc->sc_vendor));

	r = ehci_init(hsc);
	if (r != USBD_NORMAL_COMPLETION) {
		aprint_error_dev(self, "init failed, error=%d\n", r);
		return;
	}

	/* Attach usb device. */
	hsc->sc_child = config_found(self, &hsc->sc_bus, usbctlprint);
}
Exemplo n.º 3
0
void
zynqusb_attach_common(device_t parent, device_t self, bus_space_tag_t iot,
    bus_dma_tag_t dmat, paddr_t iobase, size_t size, int intr, int flags,
    enum zynq_usb_if type, enum zynq_usb_role role)
{
	struct zynqehci_softc *sc = device_private(self);
	ehci_softc_t *hsc = &sc->sc_hsc;
	uint16_t hcirev;
	usbd_status r;
	uint32_t id, hwhost, hwdevice;
	const char *comma;

	sc->sc_hsc.sc_dev = self;
	sc->sc_iot = sc->sc_hsc.iot = iot;
	sc->sc_iftype = type;
	sc->sc_role = role;

	hsc->sc_bus.hci_private = sc;
	hsc->sc_bus.usbrev = USBREV_2_0;
	hsc->sc_flags |= EHCIF_ETTF;
	hsc->sc_vendor_init = zynqusb_init;

	aprint_normal("\n");

	if (bus_space_map(iot, iobase, size, 0, &sc->sc_ioh)) {

		aprint_error_dev(self, "unable to map device\n");
		return;
	}

	if (bus_space_subregion(iot, sc->sc_ioh,
		ZYNQUSB_EHCIREGS, ZYNQUSB_EHCI_SIZE - ZYNQUSB_EHCIREGS,
		&sc->sc_hsc.ioh)) {

		aprint_error_dev(self, "unable to map subregion\n");
		return;
	}

	id = bus_space_read_4(iot, sc->sc_ioh, ZYNQUSB_ID);
	hcirev = bus_space_read_2(iot, sc->sc_hsc.ioh, EHCI_HCIVERSION);

	aprint_normal_dev(self,
	    "Zynq USB Controller id=%d revision=%d version=%d\n",
	    (int)__SHIFTOUT(id, ZYNQUSB_ID_ID),
	    (int)__SHIFTOUT(id, ZYNQUSB_ID_REVISION),
	    (int)__SHIFTOUT(id, ZYNQUSB_ID_VERSION));
	aprint_normal_dev(self, "HCI revision=0x%x\n", hcirev);

	hwhost = bus_space_read_4(iot, sc->sc_ioh, ZYNQUSB_HWHOST);
	hwdevice = bus_space_read_4(iot, sc->sc_ioh, ZYNQUSB_HWDEVICE);

	aprint_normal_dev(self, "");

	comma = "";
	if (hwhost & HWHOST_HC) {
		int n_ports = 1 + __SHIFTOUT(hwhost, HWHOST_NPORT);
		aprint_normal("%d host port%s",
		    n_ports, n_ports > 1 ? "s" : "");
		comma = ", ";
	}

	if (hwdevice & HWDEVICE_DC) {
		int n_endpoints = __SHIFTOUT(hwdevice, HWDEVICE_DEVEP);
		aprint_normal("%sdevice capable, %d endpoint%s",
		    comma,
		    n_endpoints, n_endpoints > 1 ? "s" : "");
	}
	aprint_normal("\n");

	sc->sc_hsc.sc_bus.dmatag = dmat;

	sc->sc_hsc.sc_offs = bus_space_read_1(iot, sc->sc_hsc.ioh,
	    EHCI_CAPLENGTH);

	zynqusb_reset(sc);
	zynqusb_select_interface(sc, sc->sc_iftype);

	if (sc->sc_iftype == ZYNQUSBC_IF_ULPI) {
		bus_space_write_4(sc->sc_iot, sc->sc_ioh, ZYNQUSB_ULPIVIEW, 0);

		aprint_normal_dev(hsc->sc_dev,
		    "ULPI phy VID 0x%04x PID 0x%04x\n",
		    (ulpi_read(sc, ULPI_VENDOR_ID_LOW) |
			ulpi_read(sc, ULPI_VENDOR_ID_HIGH) << 8),
		    (ulpi_read(sc, ULPI_PRODUCT_ID_LOW) |
			ulpi_read(sc, ULPI_PRODUCT_ID_HIGH) << 8));

		ulpi_reset(sc);
	}

	if (sc->sc_iftype == ZYNQUSBC_IF_ULPI) {
		if(hsc->sc_bus.usbrev == USBREV_2_0) {
			ulpi_write(sc, ULPI_FUNCTION_CONTROL + ULPI_REG_CLEAR,
			    FUNCTION_CONTROL_XCVRSELECT);
			ulpi_write(sc, ULPI_FUNCTION_CONTROL + ULPI_REG_SET,
			    FUNCTION_CONTROL_TERMSELECT);
		} else {
			ulpi_write(sc, ULPI_FUNCTION_CONTROL + ULPI_REG_SET,
			    XCVRSELECT_FSLS);
			ulpi_write(sc, ULPI_FUNCTION_CONTROL + ULPI_REG_CLEAR,
			    FUNCTION_CONTROL_TERMSELECT);
		}

		ulpi_write(sc, ULPI_OTG_CONTROL + ULPI_REG_SET,
		    OTG_CONTROL_USEEXTVBUSIND |
		    OTG_CONTROL_DRVVBUSEXT |
		    OTG_CONTROL_DRVVBUS |
		    OTG_CONTROL_CHRGVBUS);
	}

	/* Disable interrupts, so we don't get any spurious ones. */
	EOWRITE4(hsc, EHCI_USBINTR, 0);

	intr_establish(intr, IPL_USB, IST_LEVEL, ehci_intr, hsc);

	/* Figure out vendor for root hub descriptor. */
	strlcpy(hsc->sc_vendor, "Xilinx", sizeof(hsc->sc_vendor));

	r = ehci_init(hsc);
	if (r != USBD_NORMAL_COMPLETION) {
		aprint_error_dev(self, "init failed, error=%d\n", r);
		return;
	}

	/* Attach usb device. */
	hsc->sc_child = config_found(self, &hsc->sc_bus, usbctlprint);
}