Lines Matching +full:adc +full:- +full:dev
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
41 #include <dev/ofw/ofw_bus.h>
42 #include <dev/ofw/ofw_bus_subr.h>
44 #include <dev/clk/clk.h>
45 #include <dev/hwreset/hwreset.h>
47 #include <dev/gpio/gpiobusvar.h>
50 #include <dev/sound/pcm/sound.h>
51 #include <dev/sound/fdt/audio_dai.h>
133 { "allwinner,sun8i-a33-codec", 1},
140 { -1, 0 }
144 device_t dev; member
152 #define CODEC_LOCK(sc) mtx_lock(&(sc)->mtx)
153 #define CODEC_UNLOCK(sc) mtx_unlock(&(sc)->mtx)
154 #define CODEC_READ(sc, reg) bus_read_4((sc)->res[0], (reg))
155 #define CODEC_WRITE(sc, reg, val) bus_write_4((sc)->res[0], (reg), (val))
157 static int sun8i_codec_probe(device_t dev);
158 static int sun8i_codec_attach(device_t dev);
159 static int sun8i_codec_detach(device_t dev);
162 sun8i_codec_probe(device_t dev) in sun8i_codec_probe() argument
164 if (!ofw_bus_status_okay(dev)) in sun8i_codec_probe()
167 if (!ofw_bus_search_compatible(dev, compat_data)->ocd_data) in sun8i_codec_probe()
170 device_set_desc(dev, "Allwinner Codec"); in sun8i_codec_probe()
175 sun8i_codec_attach(device_t dev) in sun8i_codec_attach() argument
183 sc = device_get_softc(dev); in sun8i_codec_attach()
184 sc->dev = dev; in sun8i_codec_attach()
185 node = ofw_bus_get_node(dev); in sun8i_codec_attach()
187 mtx_init(&sc->mtx, device_get_nameunit(dev), NULL, MTX_DEF); in sun8i_codec_attach()
189 if (bus_alloc_resources(dev, sun8i_codec_spec, sc->res) != 0) { in sun8i_codec_attach()
190 device_printf(dev, "cannot allocate resources for device\n"); in sun8i_codec_attach()
195 error = clk_get_by_ofw_name(dev, 0, "mod", &sc->clk_mod); in sun8i_codec_attach()
197 device_printf(dev, "cannot get \"mod\" clock\n"); in sun8i_codec_attach()
201 error = clk_get_by_ofw_name(dev, 0, "bus", &sc->clk_gate); in sun8i_codec_attach()
203 device_printf(dev, "cannot get \"bus\" clock\n"); in sun8i_codec_attach()
207 error = clk_enable(sc->clk_gate); in sun8i_codec_attach()
209 device_printf(dev, "cannot enable \"bus\" clock\n"); in sun8i_codec_attach()
234 /* Set AIF1 to 16-bit */ in sun8i_codec_attach()
246 /* Enable AIF1 ADC timelot 0 */ in sun8i_codec_attach()
260 /* ADC mixer source select */ in sun8i_codec_attach()
270 if (gpio_pin_get_by_ofw_property(dev, node, "allwinner,pa-gpios", in sun8i_codec_attach()
274 device_printf(dev, "failed to unmute PA\n"); in sun8i_codec_attach()
277 OF_device_register_xref(OF_xref_from_node(node), dev); in sun8i_codec_attach()
282 sun8i_codec_detach(dev); in sun8i_codec_attach()
287 sun8i_codec_detach(device_t dev) in sun8i_codec_detach() argument
291 sc = device_get_softc(dev); in sun8i_codec_detach()
293 if (sc->clk_gate) in sun8i_codec_detach()
294 clk_release(sc->clk_gate); in sun8i_codec_detach()
296 if (sc->clk_mod) in sun8i_codec_detach()
297 clk_release(sc->clk_mod); in sun8i_codec_detach()
299 if (sc->intrhand != NULL) in sun8i_codec_detach()
300 bus_teardown_intr(sc->dev, sc->res[1], sc->intrhand); in sun8i_codec_detach()
302 bus_release_resources(dev, sun8i_codec_spec, sc->res); in sun8i_codec_detach()
303 mtx_destroy(&sc->mtx); in sun8i_codec_detach()
309 sun8i_codec_dai_init(device_t dev, uint32_t format) in sun8i_codec_dai_init() argument
315 sc = device_get_softc(dev); in sun8i_codec_dai_init()
372 sun8i_codec_dai_trigger(device_t dev, int go, int pcm_dir) in sun8i_codec_dai_trigger() argument
379 sun8i_codec_dai_setup_mixer(device_t dev, device_t pcmdev) in sun8i_codec_dai_setup_mixer() argument