MCPcopy Create free account
hub / github.com/F-Stack/f-stack / codec_attach

Function codec_attach

freebsd/mips/ingenic/jz4780_codec.c:219–279  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

217}
218
219static int
220codec_attach(device_t dev)
221{
222 struct codec_softc *sc;
223 uint8_t reg;
224
225 sc = device_get_softc(dev);
226 sc->dev = dev;
227
228 if (bus_alloc_resources(dev, codec_spec, sc->res)) {
229 device_printf(dev, "could not allocate resources for device\n");
230 return (ENXIO);
231 }
232
233 /* Memory interface */
234 sc->bst = rman_get_bustag(sc->res[0]);
235 sc->bsh = rman_get_bushandle(sc->res[0]);
236
237 if (clk_get_by_ofw_name(dev, 0, "i2s", &sc->clk) != 0) {
238 device_printf(dev, "could not get i2s clock\n");
239 bus_release_resources(dev, codec_spec, sc->res);
240 return (ENXIO);
241 }
242
243 /* Initialize codec. */
244 reg = codec_read(sc, CR_VIC);
245 reg &= ~(VIC_SB_SLEEP | VIC_SB);
246 codec_write(sc, CR_VIC, reg);
247
248 DELAY(20000);
249
250 reg = codec_read(sc, CR_DAC);
251 reg &= ~(DAC_SB | DAC_MUTE);
252 codec_write(sc, CR_DAC, reg);
253
254 DELAY(10000);
255
256 /* I2S, 16-bit, 48 kHz. */
257 reg = codec_read(sc, AICR_DAC);
258 reg &= ~(AICR_DAC_SB | DAC_ADWL_M);
259 reg |= DAC_ADWL_16;
260 reg &= ~(AUDIOIF_M);
261 reg |= AUDIOIF_I2S;
262 codec_write(sc, AICR_DAC, reg);
263
264 DELAY(10000);
265
266 reg = FCR_DAC_48;
267 codec_write(sc, FCR_DAC, reg);
268
269 DELAY(10000);
270
271 /* Unmute headphones. */
272 reg = codec_read(sc, CR_HP);
273 reg &= ~(HP_SB | HP_MUTE);
274 codec_write(sc, CR_HP, reg);
275
276 ci20_hp_unmute(sc);

Callers

nothing calls this directly

Calls 10

device_get_softcFunction · 0.85
bus_alloc_resourcesFunction · 0.85
device_printfFunction · 0.85
rman_get_bustagFunction · 0.85
rman_get_bushandleFunction · 0.85
bus_release_resourcesFunction · 0.85
codec_readFunction · 0.85
codec_writeFunction · 0.85
ci20_hp_unmuteFunction · 0.85
DELAYFunction · 0.70

Tested by

no test coverage detected