Lines Matching +full:codec +full:- +full:2
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
13 * 2. Redistributions in binary form must reproduce the above copyright
38 static MALLOC_DEFINE(M_SPICDS, "spicds", "SPI codec");
46 unsigned int type; /* codec type */
49 unsigned int dvc; /* De-emphasis and Volume Control */
56 spicds_wrbit(struct spicds_info *codec, int bit) in spicds_wrbit() argument
59 if (codec->cif) in spicds_wrbit()
67 codec->ctrl(codec->devinfo, cs, 0, cdti); in spicds_wrbit()
69 codec->ctrl(codec->devinfo, cs, 1, cdti); in spicds_wrbit()
76 spicds_wrcd(struct spicds_info *codec, int reg, u_int16_t val) in spicds_wrcd() argument
81 device_printf(codec->dev, "spicds_wrcd(codec, 0x%02x, 0x%02x)\n", reg, val); in spicds_wrcd()
84 if (codec->cif) in spicds_wrcd()
85 codec->ctrl(codec->devinfo, 1, 1, 0); in spicds_wrcd()
87 codec->ctrl(codec->devinfo, 0, 1, 0); in spicds_wrcd()
89 if (codec->type != SPICDS_TYPE_WM8770) { in spicds_wrcd()
90 if (codec->type == SPICDS_TYPE_AK4381) { in spicds_wrcd()
92 spicds_wrbit(codec, 0); in spicds_wrcd()
93 spicds_wrbit(codec, 1); in spicds_wrcd()
95 else if (codec->type == SPICDS_TYPE_AK4396) in spicds_wrcd()
98 spicds_wrbit(codec, 0); in spicds_wrcd()
99 spicds_wrbit(codec, 0); in spicds_wrcd()
103 spicds_wrbit(codec, 1); in spicds_wrcd()
104 spicds_wrbit(codec, 0); in spicds_wrcd()
107 spicds_wrbit(codec, 1); in spicds_wrcd()
110 spicds_wrbit(codec, reg & mask); in spicds_wrcd()
113 spicds_wrbit(codec, val & mask); in spicds_wrcd()
120 spicds_wrbit(codec, reg & mask); in spicds_wrcd()
123 spicds_wrbit(codec, val & mask); in spicds_wrcd()
127 if (codec->cif) { in spicds_wrcd()
128 codec->ctrl(codec->devinfo, 0, 1, 0); in spicds_wrcd()
130 codec->ctrl(codec->devinfo, 1, 1, 0); in spicds_wrcd()
133 codec->ctrl(codec->devinfo, 1, 1, 0); in spicds_wrcd()
142 struct spicds_info *codec; in spicds_create() local
147 codec = malloc(sizeof(*codec), M_SPICDS, M_NOWAIT); in spicds_create()
148 if (codec == NULL) in spicds_create()
151 snprintf(codec->name, SPICDS_NAMELEN, "%s:spicds%d", device_get_nameunit(dev), num); in spicds_create()
152 codec->lock = snd_mtxcreate(codec->name, codec->name); in spicds_create()
153 codec->dev = dev; in spicds_create()
154 codec->ctrl = ctrl; in spicds_create()
155 codec->devinfo = devinfo; in spicds_create()
156 codec->num = num; in spicds_create()
157 codec->type = SPICDS_TYPE_AK4524; in spicds_create()
158 codec->cif = 0; in spicds_create()
159 codec->format = AK452X_FORMAT_I2S | AK452X_FORMAT_256FSN | AK452X_FORMAT_1X; in spicds_create()
160 codec->dvc = AK452X_DVC_DEMOFF | AK452X_DVC_ZTM1024 | AK452X_DVC_ZCE; in spicds_create()
162 return codec; in spicds_create()
166 spicds_destroy(struct spicds_info *codec) in spicds_destroy() argument
168 snd_mtxfree(codec->lock); in spicds_destroy()
169 free(codec, M_SPICDS); in spicds_destroy()
173 spicds_settype(struct spicds_info *codec, unsigned int type) in spicds_settype() argument
175 snd_mtxlock(codec->lock); in spicds_settype()
176 codec->type = type; in spicds_settype()
177 snd_mtxunlock(codec->lock); in spicds_settype()
181 spicds_setcif(struct spicds_info *codec, unsigned int cif) in spicds_setcif() argument
183 snd_mtxlock(codec->lock); in spicds_setcif()
184 codec->cif = cif; in spicds_setcif()
185 snd_mtxunlock(codec->lock); in spicds_setcif()
189 spicds_setformat(struct spicds_info *codec, unsigned int format) in spicds_setformat() argument
191 snd_mtxlock(codec->lock); in spicds_setformat()
192 codec->format = format; in spicds_setformat()
193 snd_mtxunlock(codec->lock); in spicds_setformat()
197 spicds_setdvc(struct spicds_info *codec, unsigned int dvc) in spicds_setdvc() argument
199 snd_mtxlock(codec->lock); in spicds_setdvc()
200 codec->dvc = dvc; in spicds_setdvc()
201 snd_mtxunlock(codec->lock); in spicds_setdvc()
205 spicds_init(struct spicds_info *codec) in spicds_init() argument
208 device_printf(codec->dev, "spicds_init(codec)\n"); in spicds_init()
210 snd_mtxlock(codec->lock); in spicds_init()
211 if (codec->type == SPICDS_TYPE_AK4524 ||\ in spicds_init()
212 codec->type == SPICDS_TYPE_AK4528) { in spicds_init()
214 spicds_wrcd(codec, AK4524_POWER, 0); in spicds_init()
216 spicds_wrcd(codec, AK4524_FORMAT, codec->format); in spicds_init()
217 spicds_wrcd(codec, AK4524_DVC, codec->dvc); in spicds_init()
219 spicds_wrcd(codec, AK4524_POWER, in spicds_init()
222 spicds_wrcd(codec, AK4524_RESET, in spicds_init()
225 if (codec->type == SPICDS_TYPE_WM8770) { in spicds_init()
229 spicds_wrcd(codec, 0x1b, 0x044); /* ADC Mux (AC'97 source) */ in spicds_init()
230 spicds_wrcd(codec, 0x1c, 0x00B); /* Out Mux1 (VOUT1 = DAC+AUX, VOUT2 = DAC) */ in spicds_init()
231 spicds_wrcd(codec, 0x1d, 0x009); /* Out Mux2 (VOUT2 = DAC, VOUT3 = DAC) */ in spicds_init()
233 spicds_wrcd(codec, 0x18, 0x000); /* All power-up */ in spicds_init()
235 spicds_wrcd(codec, 0x16, 0x122); /* I2S, normal polarity, 24bit */ in spicds_init()
236 spicds_wrcd(codec, 0x17, 0x022); /* 256fs, slave mode */ in spicds_init()
238 spicds_wrcd(codec, 0x19, 0x000); /* -12dB ADC/L */ in spicds_init()
239 spicds_wrcd(codec, 0x1a, 0x000); /* -12dB ADC/R */ in spicds_init()
241 if (codec->type == SPICDS_TYPE_AK4358) in spicds_init()
242 spicds_wrcd(codec, 0x00, 0x07); /* I2S, 24bit, power-up */ in spicds_init()
243 if (codec->type == SPICDS_TYPE_AK4381) in spicds_init()
244 spicds_wrcd(codec, 0x00, 0x8f); /* I2S, 24bit, power-up */ in spicds_init()
245 if (codec->type == SPICDS_TYPE_AK4396) in spicds_init()
246 spicds_wrcd(codec, 0x00, 0x07); /* I2S, 24bit, power-up */ in spicds_init()
247 snd_mtxunlock(codec->lock); in spicds_init()
251 spicds_reinit(struct spicds_info *codec) in spicds_reinit() argument
253 snd_mtxlock(codec->lock); in spicds_reinit()
254 if (codec->type != SPICDS_TYPE_WM8770) { in spicds_reinit()
256 spicds_wrcd(codec, AK4524_RESET, 0); in spicds_reinit()
258 spicds_wrcd(codec, AK4524_FORMAT, codec->format); in spicds_reinit()
259 spicds_wrcd(codec, AK4524_DVC, codec->dvc); in spicds_reinit()
261 spicds_wrcd(codec, AK4524_RESET, in spicds_reinit()
268 snd_mtxunlock(codec->lock); in spicds_reinit()
272 spicds_set(struct spicds_info *codec, int dir, unsigned int left, unsigned int right) in spicds_set() argument
275 device_printf(codec->dev, "spicds_set(codec, %d, %d, %d)\n", dir, left, right); in spicds_set()
277 snd_mtxlock(codec->lock); in spicds_set()
279 if ((codec->type == SPICDS_TYPE_AK4381) || \ in spicds_set()
280 (codec->type == SPICDS_TYPE_AK4396)) in spicds_set()
285 switch (codec->type) { in spicds_set()
297 if ((codec->type == SPICDS_TYPE_AK4381) || \ in spicds_set()
298 (codec->type == SPICDS_TYPE_AK4396)) in spicds_set()
303 switch (codec->type) { in spicds_set()
314 if (dir == PCMDIR_REC && codec->type == SPICDS_TYPE_AK4524) { in spicds_set()
316 device_printf(codec->dev, "spicds_set(): AK4524(REC) %d/%d\n", left, right); in spicds_set()
318 spicds_wrcd(codec, AK4524_LIPGA, left); in spicds_set()
319 spicds_wrcd(codec, AK4524_RIPGA, right); in spicds_set()
321 if (dir == PCMDIR_PLAY && codec->type == SPICDS_TYPE_AK4524) { in spicds_set()
323 device_printf(codec->dev, "spicds_set(): AK4524(PLAY) %d/%d\n", left, right); in spicds_set()
325 spicds_wrcd(codec, AK4524_LOATT, left); in spicds_set()
326 spicds_wrcd(codec, AK4524_ROATT, right); in spicds_set()
328 if (dir == PCMDIR_PLAY && codec->type == SPICDS_TYPE_AK4528) { in spicds_set()
330 device_printf(codec->dev, "spicds_set(): AK4528(PLAY) %d/%d\n", left, right); in spicds_set()
332 spicds_wrcd(codec, AK4528_LOATT, left); in spicds_set()
333 spicds_wrcd(codec, AK4528_ROATT, right); in spicds_set()
335 if (dir == PCMDIR_PLAY && codec->type == SPICDS_TYPE_WM8770) { in spicds_set()
337 device_printf(codec->dev, "spicds_set(): WM8770(PLAY) %d/%d\n", left, right); in spicds_set()
339 spicds_wrcd(codec, WM8770_AOATT_L1, left | WM8770_AOATT_UPDATE); in spicds_set()
340 spicds_wrcd(codec, WM8770_AOATT_R1, right | WM8770_AOATT_UPDATE); in spicds_set()
342 if (dir == PCMDIR_PLAY && codec->type == SPICDS_TYPE_AK4358) { in spicds_set()
344 device_printf(codec->dev, "spicds_set(): AK4358(PLAY) %d/%d\n", left, right); in spicds_set()
346 spicds_wrcd(codec, AK4358_LO1ATT, left | AK4358_OATT_ENABLE); in spicds_set()
347 spicds_wrcd(codec, AK4358_RO1ATT, right | AK4358_OATT_ENABLE); in spicds_set()
349 if (dir == PCMDIR_PLAY && codec->type == SPICDS_TYPE_AK4381) { in spicds_set()
351 device_printf(codec->dev, "spicds_set(): AK4381(PLAY) %d/%d\n", left, right); in spicds_set()
353 spicds_wrcd(codec, AK4381_LOATT, left); in spicds_set()
354 spicds_wrcd(codec, AK4381_ROATT, right); in spicds_set()
357 if (dir == PCMDIR_PLAY && codec->type == SPICDS_TYPE_AK4396) { in spicds_set()
359 device_printf(codec->dev, "spicds_set(): AK4396(PLAY) %d/%d\n", left, right); in spicds_set()
361 spicds_wrcd(codec, AK4396_LOATT, left); in spicds_set()
362 spicds_wrcd(codec, AK4396_ROATT, right); in spicds_set()
365 snd_mtxunlock(codec->lock); in spicds_set()