dwc_otg_hisi.c revision 302408
143334Syokota/*
243334Syokota * Copyright 2015 Andrew Turner.
360107Sobrien * All rights reserved.
443334Syokota *
543334Syokota * Redistribution and use in source and binary forms, with or without
643334Syokota * modification, are permitted provided that the following conditions are
743334Syokota * met:
843334Syokota *
943334Syokota *  1. Redistributions of source code must retain the above copyright
1043334Syokota *     notice, this list of conditions and the following disclaimer.
1143334Syokota *  2. Redistributions in binary form must reproduce the above copyright
1243334Syokota *     notice, this list of conditions and the following disclaimer in the
1343334Syokota *     documentation and/or other materials provided with the distribution.
1443334Syokota *
1543334Syokota * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1643334Syokota * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1743334Syokota * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1843334Syokota * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
1943334Syokota * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2043334Syokota * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2143334Syokota * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
2243334Syokota * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
2343334Syokota * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
2443334Syokota * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
2543334Syokota * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2643334Syokota */
2743334Syokota
2843334Syokota#include <sys/cdefs.h>
2943334Syokota__FBSDID("$FreeBSD: stable/11/sys/dev/usb/controller/dwc_otg_hisi.c 287373 2015-09-01 17:13:04Z andrew $");
3043334Syokota
3143334Syokota#include <sys/param.h>
3243334Syokota#include <sys/kernel.h>
3343334Syokota#include <sys/bus.h>
3443334Syokota#include <sys/callout.h>
3543334Syokota#include <sys/condvar.h>
3643334Syokota#include <sys/module.h>
3743334Syokota
3843334Syokota#include <dev/ofw/ofw_bus_subr.h>
3943334Syokota
4043334Syokota#include <dev/usb/usb.h>
4143334Syokota#include <dev/usb/usbdi.h>
4243334Syokota
4343334Syokota#include <dev/usb/usb_busdma.h>
4443334Syokota#include <dev/usb/usb_process.h>
4543334Syokota
4643334Syokota#include <dev/usb/usb_controller.h>
4743334Syokota#include <dev/usb/usb_bus.h>
4843334Syokota
4943334Syokota#include <dev/usb/controller/dwc_otg.h>
5043334Syokota#include <dev/usb/controller/dwc_otg_fdt.h>
5143334Syokota
5243334Syokotastatic device_probe_t hisi_dwc_otg_probe;
5343334Syokotastatic device_attach_t hisi_dwc_otg_attach;
5443334Syokota
5543334Syokotastatic int
5643334Syokotahisi_dwc_otg_probe(device_t dev)
5743334Syokota{
5843334Syokota
5943334Syokota	if (!ofw_bus_status_okay(dev))
6043334Syokota		return (ENXIO);
6143334Syokota
6243334Syokota	if (!ofw_bus_is_compatible(dev, "huawei,hisi-usb"))
6343334Syokota		return (ENXIO);
6443334Syokota
6543334Syokota	device_set_desc(dev, "DWC OTG 2.0 integrated USB controller (hisilicon)");
6643334Syokota
6743334Syokota	return (BUS_PROBE_VENDOR);
6843334Syokota}
6943334Syokota
7043334Syokotastatic int
7143334Syokotahisi_dwc_otg_attach(device_t dev)
7243334Syokota{
7343334Syokota	struct dwc_otg_fdt_softc *sc;
7443334Syokota
7543334Syokota	/* Set the default to host mode. */
7643334Syokota	/* TODO: Use vbus to detect this. */
7743334Syokota	sc = device_get_softc(dev);
7843334Syokota	sc->sc_otg.sc_mode = DWC_MODE_HOST;
7943334Syokota
8043334Syokota	return (dwc_otg_attach(dev));
8143334Syokota}
8243334Syokota
8343334Syokotastatic device_method_t hisi_dwc_otg_methods[] = {
8443334Syokota	/* bus interface */
8543334Syokota	DEVMETHOD(device_probe, hisi_dwc_otg_probe),
8643334Syokota	DEVMETHOD(device_attach, hisi_dwc_otg_attach),
8743334Syokota
8843334Syokota	DEVMETHOD_END
8943334Syokota};
9043334Syokota
9143334Syokotastatic devclass_t hisi_dwc_otg_devclass;
9243334Syokota
9343334SyokotaDEFINE_CLASS_1(hisi_dwcotg, hisi_dwc_otg_driver, hisi_dwc_otg_methods,
9443334Syokota    sizeof(struct dwc_otg_fdt_softc), dwc_otg_driver);
9543334SyokotaDRIVER_MODULE(hisi_dwcotg, simplebus, hisi_dwc_otg_driver,
9643334Syokota    hisi_dwc_otg_devclass, 0, 0);
9743334SyokotaMODULE_DEPEND(hisi_dwcotg, usb, 1, 1, 1);
9843334Syokota