Lines Matching +full:gpio +full:- +full:ctrl

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause AND BSD-3-Clause
27 /*-
136 int ctrl; member
137 int detect_active; /* for extint-gpio */
138 int level; /* for extint-gpio */
139 struct i2s_softc *i2s; /* for extint-gpio */
195 sc->aoa.sc_dev = self; in i2s_attach()
196 sc->node = ofw_bus_get_node(self); in i2s_attach()
198 port = of_find_firstchild_byname(sc->node, "i2s-a"); in i2s_attach()
199 if (port == -1) in i2s_attach()
201 sc->soundnode = of_find_firstchild_byname(port, "sound"); in i2s_attach()
202 if (sc->soundnode == -1) in i2s_attach()
205 mtx_init(&sc->port_mtx, "port_mtx", NULL, MTX_DEF); in i2s_attach()
209 sc->reg = bus_alloc_resource_any(self, SYS_RES_MEMORY, &rid, RF_ACTIVE); in i2s_attach()
210 if (sc->reg == NULL) in i2s_attach()
215 sc->aoa.sc_odma = bus_alloc_resource_any(self, SYS_RES_MEMORY, &rid, in i2s_attach()
217 if (sc->aoa.sc_odma == NULL) in i2s_attach()
220 /* Establish the DBDMA channel edge-triggered interrupt. */ in i2s_attach()
246 i2s_delayed_attach->ich_func = i2s_postattach; in i2s_attach()
247 i2s_delayed_attach->ich_arg = sc; in i2s_attach()
256 GPIO routines.
278 enum gpio_ctrl ctrl; member
280 {"headphone-mute", HEADPHONE_MUTE},
281 {"lineout-mute", LINEOUT_MUTE},
282 {"amp-mute", AMP_MUTE},
283 {"headphone-detect", HEADPHONE_DETECT},
284 {"lineout-detect", LINEOUT_DETECT},
285 {"line-output-detect", LINEOUT_DETECT},
286 {"audio-hw-reset", AUDIO_HW_RESET},
287 {"hw-reset", AUDIO_HW_RESET},
302 sc->level = sc->detect_active; in aoagpio_int()
304 sc->level = !(sc->detect_active); in aoagpio_int()
306 if (sc->i2s) in aoagpio_int()
307 i2s_cint(sc->i2s); in aoagpio_int()
311 aoagpio_probe(device_t gpio) in aoagpio_probe() argument
319 node = ofw_bus_get_node(gpio); in aoagpio_probe()
320 if (node == 0 || node == -1) in aoagpio_probe()
324 if (OF_getprop(node, "audio-gpio", bname, sizeof(bname)) > 2) in aoagpio_probe()
327 name = ofw_bus_get_name(gpio); in aoagpio_probe()
330 for (m = gpio_controls; m->name != NULL; m++) { in aoagpio_probe()
331 if (strcmp(name, m->name) == 0) { in aoagpio_probe()
332 sc = device_get_softc(gpio); in aoagpio_probe()
333 gpio_ctrls[m->ctrl] = sc; in aoagpio_probe()
334 sc->dev = gpio; in aoagpio_probe()
335 sc->ctrl = m->ctrl; in aoagpio_probe()
336 sc->level = 0; in aoagpio_probe()
337 sc->detect_active = 0; in aoagpio_probe()
338 sc->i2s = NULL; in aoagpio_probe()
340 OF_getprop(node, "audio-gpio-active-state", in aoagpio_probe()
341 &sc->detect_active, sizeof(sc->detect_active)); in aoagpio_probe()
343 if ((1 << m->ctrl) & GPIO_CTRL_EXTINT_SET) in aoagpio_probe()
344 aoagpio_int(gpio); in aoagpio_probe()
346 device_set_desc(gpio, m->name); in aoagpio_probe()
347 device_quiet(gpio); in aoagpio_probe()
356 aoagpio_attach(device_t gpio) in aoagpio_attach() argument
363 sc = device_get_softc(gpio); in aoagpio_attach()
365 if ((1 << sc->ctrl) & GPIO_CTRL_EXTINT_SET) { in aoagpio_attach()
366 r = bus_alloc_resource_any(gpio, SYS_RES_IRQ, &rid, RF_ACTIVE); in aoagpio_attach()
377 bus_setup_intr(gpio, r, INTR_TYPE_MISC | INTR_MPSAFE | in aoagpio_attach()
378 INTR_ENTROPY, NULL, aoagpio_int, gpio, &cookie); in aoagpio_attach()
394 #define I2S_INT_CLKSTOPPEND 0x01000000 /* clock-stop interrupt pending */
486 x = (mdiv / 2) - 1; in i2s_setup()
499 x = (sdiv / 2) - 1; in i2s_setup()
533 x = bus_read_4(sc->reg, I2S_WORDSIZE); in i2s_setup()
535 bus_write_4(sc->reg, I2S_WORDSIZE, wordformat); in i2s_setup()
537 x = bus_read_4(sc->reg, I2S_FORMAT); in i2s_setup()
550 bus_space_write_4(sc->sc_tag, sc->sc_bsh, I2S_INT, in i2s_setup()
555 for (timo = 1000; timo > 0; timo--) { in i2s_setup()
556 if (bus_space_read_4(sc->sc_tag, sc->sc_bsh, in i2s_setup()
565 sc->sc_dev.dv_xname); in i2s_setup()
568 bus_space_write_4(sc->sc_tag, sc->sc_bsh, I2S_FORMAT, reg); in i2s_setup()
584 for (n = OF_child(node); n != -1; n = OF_peer(n)) { in of_find_firstchild_byname()
592 return (-1); in of_find_firstchild_byname()
596 gpio_read(enum gpio_ctrl ctrl) in gpio_read() argument
600 if ((sc = gpio_ctrls[ctrl]) == NULL) in gpio_read()
603 return (macgpio_read(sc->dev) & GPIO_DATA); in gpio_read()
607 gpio_write(enum gpio_ctrl ctrl, u_int x) in gpio_write() argument
612 if ((sc = gpio_ctrls[ctrl]) == NULL) in gpio_write()
619 macgpio_write(sc->dev, reg); in gpio_write()
628 gpio_ctrls[HEADPHONE_DETECT]->level) in i2s_cint()
632 gpio_ctrls[LINEOUT_DETECT]->level) in i2s_cint()
698 if (mask == sc->output_mask) in MUTE_CONTROL()
701 mtx_lock(&sc->port_mtx); in MUTE_CONTROL()
723 sc->output_mask = mask; in MUTE_CONTROL()
725 mtx_unlock(&sc->port_mtx); in MUTE_CONTROL()
735 self = sc->aoa.sc_dev; in i2s_postattach()
747 /* Enable GPIO interrupt callback. */ in i2s_postattach()
750 gpio_ctrls[i]->i2s = sc; in i2s_postattach()