Lines Matching +full:syscon +full:- +full:dev

1 /*-
46 #include <dev/ofw/openfirm.h>
47 #include <dev/ofw/ofw_bus.h>
48 #include <dev/ofw/ofw_bus_subr.h>
50 #include <dev/usb/usb.h>
51 #include <dev/usb/usbdi.h>
53 #include <dev/usb/usb_core.h>
54 #include <dev/usb/usb_busdma.h>
55 #include <dev/usb/usb_process.h>
56 #include <dev/usb/usb_util.h>
60 #include <dev/usb/usb_controller.h>
61 #include <dev/usb/usb_bus.h>
62 #include <dev/usb/controller/musb_otg.h>
63 #include <dev/usb/usb_debug.h>
69 #include <dev/clk/clk.h>
70 #include <dev/syscon/syscon.h>
99 bus_write_4((sc)->sc_mem_res[idx], (reg), (val)); \
102 #define USB_READ4(sc, idx, reg) bus_read_4((sc)->sc_mem_res[idx], (reg))
112 { -1, 0, 0 }
133 struct syscon *syscon; member
141 if (sc->sc_otg.sc_mode == MUSB2_DEVICE_MODE) in musbotg_vbus_poll()
142 musbotg_vbus_interrupt(&sc->sc_otg, 1); in musbotg_vbus_poll()
145 musbotg_vbus_interrupt(&sc->sc_otg, stat & 1); in musbotg_vbus_poll()
163 ssc = sc->sc_platform_data; in musbotg_clocks_on()
165 reg = SYSCON_READ_4(ssc->syscon, USB_CTRL[sc->sc_id]); in musbotg_clocks_on()
170 SYSCON_WRITE_4(ssc->syscon, USB_CTRL[sc->sc_id], reg); in musbotg_clocks_on()
181 ssc = sc->sc_platform_data; in musbotg_clocks_off()
184 reg = SYSCON_READ_4(ssc->syscon, USB_CTRL[sc->sc_id]); in musbotg_clocks_off()
185 SYSCON_WRITE_4(ssc->syscon, USB_CTRL[sc->sc_id], reg | 3); in musbotg_clocks_off()
191 struct musbotg_super_softc *ssc = sc->sc_platform_data; in musbotg_ep_int_set()
206 struct musbotg_super_softc *ssc = sc->sc_platform_data; in musbotg_wrapper_interrupt()
218 sc->sc_id, stat0, stat1, stat); in musbotg_wrapper_interrupt()
228 musbotg_probe(device_t dev) in musbotg_probe() argument
230 if (!ofw_bus_status_okay(dev)) in musbotg_probe()
233 if (!ofw_bus_is_compatible(dev, "ti,musb-am33xx")) in musbotg_probe()
236 device_set_desc(dev, "TI AM33xx integrated USB OTG controller"); in musbotg_probe()
242 musbotg_attach(device_t dev) in musbotg_attach() argument
244 struct musbotg_super_softc *sc = device_get_softc(dev); in musbotg_attach()
251 sc->sc_otg.sc_id = device_get_unit(dev); in musbotg_attach()
256 err = clk_get_by_name(dev, "usbotg_fck@47c", &clk_usbotg_fck); in musbotg_attach()
258 device_printf(dev, "Can not find usbotg_fck@47c\n"); in musbotg_attach()
264 device_printf(dev, "Can not enable usbotg_fck@47c\n"); in musbotg_attach()
268 /* FIXME: For now; Go and kidnap syscon from opp-table */ in musbotg_attach()
269 opp_table = OF_finddevice("/opp-table"); in musbotg_attach()
270 if (opp_table == -1) { in musbotg_attach()
271 device_printf(dev, "Cant find /opp-table\n"); in musbotg_attach()
274 if (!OF_hasprop(opp_table, "syscon")) { in musbotg_attach()
275 device_printf(dev, "/opp-table missing syscon property\n"); in musbotg_attach()
278 err = syscon_get_by_ofw_property(dev, opp_table, "syscon", &sc->syscon); in musbotg_attach()
280 device_printf(dev, "Failed to get syscon\n"); in musbotg_attach()
285 err = bus_alloc_resources(dev, am335x_musbotg_mem_spec, in musbotg_attach()
286 sc->sc_mem_res); in musbotg_attach()
288 device_printf(dev, in musbotg_attach()
294 sc->sc_otg.sc_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, in musbotg_attach()
295 &sc->sc_irq_rid, RF_ACTIVE); in musbotg_attach()
296 if (sc->sc_otg.sc_irq_res == NULL) { in musbotg_attach()
297 device_printf(dev, in musbotg_attach()
303 sc->sc_otg.sc_clocks_on = &musbotg_clocks_on; in musbotg_attach()
304 sc->sc_otg.sc_clocks_off = &musbotg_clocks_off; in musbotg_attach()
305 sc->sc_otg.sc_clocks_arg = &sc->sc_otg; in musbotg_attach()
307 sc->sc_otg.sc_ep_int_set = musbotg_ep_int_set; in musbotg_attach()
310 sc->sc_otg.sc_bus.parent = dev; in musbotg_attach()
311 sc->sc_otg.sc_bus.devices = sc->sc_otg.sc_devices; in musbotg_attach()
312 sc->sc_otg.sc_bus.devices_max = MUSB2_MAX_DEVICES; in musbotg_attach()
313 sc->sc_otg.sc_bus.dma_bits = 32; in musbotg_attach()
316 if (usb_bus_mem_alloc_all(&sc->sc_otg.sc_bus, in musbotg_attach()
317 USB_GET_DMA_TAG(dev), NULL)) { in musbotg_attach()
318 device_printf(dev, in musbotg_attach()
322 sc->sc_otg.sc_io_res = sc->sc_mem_res[RES_USBCORE]; in musbotg_attach()
323 sc->sc_otg.sc_io_tag = in musbotg_attach()
324 rman_get_bustag(sc->sc_otg.sc_io_res); in musbotg_attach()
325 sc->sc_otg.sc_io_hdl = in musbotg_attach()
326 rman_get_bushandle(sc->sc_otg.sc_io_res); in musbotg_attach()
327 sc->sc_otg.sc_io_size = in musbotg_attach()
328 rman_get_size(sc->sc_otg.sc_io_res); in musbotg_attach()
330 sc->sc_otg.sc_bus.bdev = device_add_child(dev, "usbus", DEVICE_UNIT_ANY); in musbotg_attach()
331 if (!(sc->sc_otg.sc_bus.bdev)) { in musbotg_attach()
332 device_printf(dev, "No busdev for musb\n"); in musbotg_attach()
335 device_set_ivars(sc->sc_otg.sc_bus.bdev, in musbotg_attach()
336 &sc->sc_otg.sc_bus); in musbotg_attach()
338 err = bus_setup_intr(dev, sc->sc_otg.sc_irq_res, in musbotg_attach()
341 &sc->sc_otg, &sc->sc_otg.sc_intr_hdl); in musbotg_attach()
343 sc->sc_otg.sc_intr_hdl = NULL; in musbotg_attach()
344 device_printf(dev, in musbotg_attach()
349 sc->sc_otg.sc_platform_data = sc; in musbotg_attach()
350 if (OF_getprop(ofw_bus_get_node(dev), "dr_mode", mode, in musbotg_attach()
353 sc->sc_otg.sc_mode = MUSB2_HOST_MODE; in musbotg_attach()
355 sc->sc_otg.sc_mode = MUSB2_DEVICE_MODE; in musbotg_attach()
358 if (sc->sc_otg.sc_id == 0) in musbotg_attach()
359 sc->sc_otg.sc_mode = MUSB2_DEVICE_MODE; in musbotg_attach()
361 sc->sc_otg.sc_mode = MUSB2_HOST_MODE; in musbotg_attach()
365 * software-controlled function in musbotg_attach()
368 if (sc->sc_otg.sc_mode == MUSB2_HOST_MODE) { in musbotg_attach()
386 err = musbotg_init(&sc->sc_otg); in musbotg_attach()
388 err = device_probe_and_attach(sc->sc_otg.sc_bus.bdev); in musbotg_attach()
399 musbotg_detach(dev); in musbotg_attach()
404 musbotg_detach(device_t dev) in musbotg_detach() argument
406 struct musbotg_super_softc *sc = device_get_softc(dev); in musbotg_detach()
410 error = bus_generic_detach(dev); in musbotg_detach()
414 if (sc->sc_otg.sc_irq_res && sc->sc_otg.sc_intr_hdl) { in musbotg_detach()
418 musbotg_uninit(&sc->sc_otg); in musbotg_detach()
420 bus_teardown_intr(dev, sc->sc_otg.sc_irq_res, in musbotg_detach()
421 sc->sc_otg.sc_intr_hdl); in musbotg_detach()
422 sc->sc_otg.sc_intr_hdl = NULL; in musbotg_detach()
425 usb_bus_mem_free_all(&sc->sc_otg.sc_bus, NULL); in musbotg_detach()
428 if (sc->sc_mem_res[0]) in musbotg_detach()
429 bus_release_resources(dev, am335x_musbotg_mem_spec, in musbotg_detach()
430 sc->sc_mem_res); in musbotg_detach()
432 if (sc->sc_otg.sc_irq_res) in musbotg_detach()
433 bus_release_resource(dev, SYS_RES_IRQ, sc->sc_irq_rid, in musbotg_detach()
434 sc->sc_otg.sc_irq_res); in musbotg_detach()