wm8750_zaudio.c revision 1.1.18.2       1 /*	$NetBSD: wm8750_zaudio.c,v 1.1.18.2 2017/12/03 11:36:52 jdolecek Exp $	*/
      2 /*	$OpenBSD: zaurus_audio.c,v 1.8 2005/08/18 13:23:02 robert Exp $	*/
      3 
      4 /*
      5  * Copyright (c) 2005 Christopher Pascoe <pascoe (at) openbsd.org>
      6  *
      7  * Permission to use, copy, modify, and distribute this software for any
      8  * purpose with or without fee is hereby granted, provided that the above
      9  * copyright notice and this permission notice appear in all copies.
     10  *
     11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
     12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
     14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
     17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     18  */
     19 
     20 /*-
     21  * Copyright (C) 2009 NONAKA Kimihiro <nonaka (at) netbsd.org>
     22  * All rights reserved.
     23  *
     24  * Redistribution and use in source and binary forms, with or without
     25  * modification, are permitted provided that the following conditions
     26  * are met:
     27  * 1. Redistributions of source code must retain the above copyright
     28  *    notice, this list of conditions and the following disclaimer.
     29  * 2. Redistributions in binary form must reproduce the above copyright
     30  *    notice, this list of conditions and the following disclaimer in the
     31  *    documentation and/or other materials provided with the distribution.
     32  *
     33  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     34  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     35  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     36  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     37  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     38  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     39  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     40  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     41  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     42  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     43  */
     44 
     45 /*
     46  * TODO:
     47  *	- powerhooks (currently only works until first suspend)
     48  */
     49 
     50 #include "opt_cputypes.h"
     51 #include "opt_zaudio.h"
     52 
     53 #include <sys/cdefs.h>
     54 __KERNEL_RCSID(0, "$NetBSD: wm8750_zaudio.c,v 1.1.18.2 2017/12/03 11:36:52 jdolecek Exp $");
     55 
     56 #include <sys/param.h>
     57 #include <sys/systm.h>
     58 #include <sys/callout.h>
     59 #include <sys/device.h>
     60 #include <sys/kmem.h>
     61 #include <sys/kernel.h>
     62 #include <sys/audioio.h>
     63 #include <sys/mutex.h>
     64 #include <sys/intr.h>
     65 #include <sys/bus.h>
     66 
     67 #include <dev/audio_if.h>
     68 #include <dev/mulaw.h>
     69 #include <dev/auconv.h>
     70 
     71 #include <dev/i2c/i2cvar.h>
     72 
     73 #include <arm/xscale/pxa2x0reg.h>
     74 #include <arm/xscale/pxa2x0var.h>
     75 #include <arm/xscale/pxa2x0_i2c.h>
     76 #include <arm/xscale/pxa2x0_i2s.h>
     77 #include <arm/xscale/pxa2x0_dmac.h>
     78 #include <arm/xscale/pxa2x0_gpio.h>
     79 
     80 #include <zaurus/zaurus/zaurus_var.h>
     81 #include <zaurus/dev/zaudiovar.h>
     82 #include <zaurus/dev/wm8750reg.h>
     83 #include <zaurus/dev/wm8750var.h>
     84 #include <zaurus/dev/scoopvar.h>
     85 #include <zaurus/dev/ioexpvar.h>
     86 
     87 #define WM8750_ADDRESS  0x1B
     88 
     89 /* GPIO pins */
     90 #define GPIO_HP_IN_C3000	116
     91 
     92 #define WM8750_OP_SPKR	0
     93 #define WM8750_OP_HP	1
     94 #define WM8750_OP_MIC	2
     95 #define WM8750_OP_NUM	3
     96 
     97 #define ZAUDIO_JACK_STATE_OUT	0
     98 #define ZAUDIO_JACK_STATE_IN	1
     99 #define ZAUDIO_JACK_STATE_INS	2
    100 #define ZAUDIO_JACK_STATE_REM	3
    101 
    102 static int	wm8750_finalize(device_t);
    103 static bool	wm8750_suspend(device_t, const pmf_qual_t *);
    104 static bool	wm8750_resume(device_t, const pmf_qual_t *);
    105 static void	wm8750_volume_up(device_t);
    106 static void	wm8750_volume_down(device_t);
    107 static void	wm8750_volume_toggle(device_t);
    108 
    109 static struct audio_device wm8750_device = {
    110 	"WM8750",
    111 	"1.0",
    112 	"wm"
    113 };
    114 
    115 static const struct audio_format wm8750_formats[] = {
    116 	{
    117 		.driver_data	= NULL,
    118 		.mode		= AUMODE_PLAY | AUMODE_RECORD,
    119 		.encoding	= AUDIO_ENCODING_SLINEAR_LE,
    120 		.validbits	= 16,
    121 		.precision	= 16,
    122 		.channels	= 2,
    123 		.channel_mask	= AUFMT_STEREO,
    124 		.frequency_type	= 0,
    125 		.frequency	= { 4000, 48000 }
    126 	},
    127 	{
    128 		.driver_data	= NULL,
    129 		.mode		= AUMODE_PLAY | AUMODE_RECORD,
    130 		.encoding	= AUDIO_ENCODING_SLINEAR_LE,
    131 		.validbits	= 16,
    132 		.precision	= 16,
    133 		.channels	= 1,
    134 		.channel_mask	= AUFMT_MONAURAL,
    135 		.frequency_type	= 0,
    136 		.frequency	= { 4000, 48000 }
    137 	},
    138 	{
    139 		.driver_data	= NULL,
    140 		.mode		= AUMODE_PLAY | AUMODE_RECORD,
    141 		.encoding	= AUDIO_ENCODING_ULINEAR_LE,
    142 		.validbits	= 8,
    143 		.precision	= 8,
    144 		.channels	= 2,
    145 		.channel_mask	= AUFMT_STEREO,
    146 		.frequency_type	= 0,
    147 		.frequency	= { 4000, 48000 }
    148 	},
    149 	{
    150 		.driver_data	= NULL,
    151 		.mode		= AUMODE_PLAY | AUMODE_RECORD,
    152 		.encoding	= AUDIO_ENCODING_ULINEAR_LE,
    153 		.validbits	= 8,
    154 		.precision	= 8,
    155 		.channels	= 1,
    156 		.channel_mask	= AUFMT_MONAURAL,
    157 		.frequency_type	= 0,
    158 		.frequency	= { 4000, 48000 }
    159 	},
    160 };
    161 static const int wm8750_nformats = (int)__arraycount(wm8750_formats);
    162 
    163 static void wm8750_init(struct zaudio_softc *);
    164 static int wm8750_jack_intr(void *);
    165 static void wm8750_jack(void *);
    166 static void wm8750_standby(struct zaudio_softc *);
    167 static void wm8750_update_volume(struct zaudio_softc *, int);
    168 static void wm8750_update_mutes(struct zaudio_softc *, int);
    169 static void wm8750_play_setup(struct zaudio_softc *);
    170 /*static*/ void wm8750_record_setup(struct zaudio_softc *);
    171 static int wm8750_query_encoding(void *, struct audio_encoding *);
    172 static int wm8750_set_params(void *, int, int, audio_params_t *,
    173     audio_params_t *, stream_filter_list_t *, stream_filter_list_t *);
    174 static int wm8750_start_output(void *, void *, int, void (*)(void *), void *);
    175 static int wm8750_start_input(void *, void *, int, void (*)(void *), void *);
    176 static int wm8750_halt_output(void *);
    177 static int wm8750_halt_input(void *);
    178 static int wm8750_getdev(void *, struct audio_device *);
    179 static int wm8750_set_port(void *, struct mixer_ctrl *);
    180 static int wm8750_get_port(void *, struct mixer_ctrl *);
    181 static int wm8750_query_devinfo(void *, struct mixer_devinfo *);
    182 
    183 static struct audio_hw_if wm8750_hw_if = {
    184 	.open			= zaudio_open,
    185 	.close			= zaudio_close,
    186 	.drain			= NULL,
    187 	.query_encoding		= wm8750_query_encoding,
    188 	.set_params		= wm8750_set_params,
    189 	.round_blocksize	= zaudio_round_blocksize,
    190 	.commit_settings	= NULL,
    191 	.init_output		= NULL,
    192 	.init_input		= NULL,
    193 	.start_output		= wm8750_start_output,
    194 	.start_input		= wm8750_start_input,
    195 	.halt_output		= wm8750_halt_output,
    196 	.halt_input		= wm8750_halt_input,
    197 	.speaker_ctl		= NULL,
    198 	.getdev			= wm8750_getdev,
    199 	.setfd			= NULL,
    200 	.set_port		= wm8750_set_port,
    201 	.get_port		= wm8750_get_port,
    202 	.query_devinfo		= wm8750_query_devinfo,
    203 	.allocm			= zaudio_allocm,
    204 	.freem			= zaudio_freem,
    205 	.round_buffersize	= zaudio_round_buffersize,
    206 	.mappage		= zaudio_mappage,
    207 	.get_props		= zaudio_get_props,
    208 	.trigger_output		= NULL,
    209 	.trigger_input		= NULL,
    210 	.dev_ioctl		= NULL,
    211 	.get_locks		= zaudio_get_locks,
    212 };
    213 
    214 static const uint16_t playback_regs[][2] = {
    215 	/* Unmute DAC */
    216 	{ ADCDACCTL_REG, 0x000 },
    217 
    218 	/* 16 bit audio words */
    219 	{ AUDINT_REG, AUDINT_SET_FORMAT(2) },
    220 
    221 	/* Enable thermal protection, power */
    222 	{ ADCTL1_REG, ADCTL1_TSDEN | ADCTL1_SET_VSEL(3) },
    223 
    224 	/* Enable speaker driver, DAC oversampling */
    225 	{ ADCTL2_REG, ADCTL2_ROUT2INV | ADCTL2_DACOSR },
    226 
    227 	/* Set DAC voltage references */
    228 	{ PWRMGMT1_REG, PWRMGMT1_SET_VMIDSEL(1) | PWRMGMT1_VREF },
    229 
    230 	/* Direct DACs to output mixers */
    231 	{ LOUTMIX1_REG, LOUTMIX1_LD2LO },
    232 	{ LOUTMIX2_REG, 0x000 },
    233 	{ ROUTMIX1_REG, 0x000 },
    234 	{ ROUTMIX2_REG, ROUTMIX2_RD2RO },
    235 
    236 	/* End of list */
    237 	{ 0xffff, 0xffff }
    238 };
    239 
    240 static const uint16_t record_regs[][2] = {
    241 	/* Unmute DAC */
    242 	{ ADCDACCTL_REG, 0x000 },
    243 
    244 	/* 16 bit audio words */
    245 	{ AUDINT_REG, AUDINT_SET_FORMAT(2) },
    246 
    247 	/* Enable thermal protection, power, left DAC for both channel */
    248 	{ ADCTL1_REG, ADCTL1_TSDEN | ADCTL1_SET_VSEL(3)
    249 	              | ADCTL1_SET_DATSEL(1) },
    250 
    251 	/* Diffrential input select: LINPUT1-RINPUT1, stereo */
    252 	{ ADCINPMODE_REG, 0x000 },
    253 
    254 	/* L-R differential, micboost 20dB */
    255 	{ ADCLSPATH_REG, ADCLSPATH_SET_LINSEL(3) | ADCLSPATH_SET_LMICBOOST(2) },
    256 	{ ADCRSPATH_REG, ADCRSPATH_SET_RINSEL(3) | ADCRSPATH_SET_RMICBOOST(2) },
    257 
    258 	/* End of list */
    259 	{ 0xffff, 0xffff }
    260 };
    261 
    262 static __inline int
    263 wm8750_write(struct zaudio_softc *sc, int reg, int val)
    264 {
    265 	uint16_t tmp;
    266 	uint8_t cmd;
    267 	uint8_t data;
    268 
    269 	tmp = (reg << 9) | (val & 0x1ff);
    270 	cmd = tmp >> 8;
    271 	data = tmp;
    272 	return iic_exec(sc->sc_i2c, I2C_OP_WRITE_WITH_STOP, WM8750_ADDRESS,
    273 	    &cmd, 1, &data, 1, 0);
    274 }
    275 
    276 int
    277 wm8750_match(device_t parent, cfdata_t cf, struct i2c_attach_args *ia)
    278 {
    279 
    280 	if (ZAURUS_ISC860)
    281 		return 0;
    282 
    283 	if (ia->ia_name) {
    284 		/* direct config - check name */
    285 		if (strcmp(ia->ia_name, "zaudio") == 0)
    286 			return 1;
    287 	} else {
    288 		/* indirect config - check typical address */
    289 		if (ia->ia_addr == WM8750_ADDRESS)
    290 			return 1;
    291 	}
    292 	return 0;
    293 }
    294 
    295 void
    296 wm8750_attach(device_t parent, device_t self, struct i2c_attach_args *ia)
    297 {
    298 	struct zaudio_softc *sc = device_private(self);
    299 	int error;
    300 
    301 	aprint_normal(": I2S, WM8750 Audio\n");
    302 	aprint_naive("\n");
    303 
    304 	/* Check for an I2C response from the wm8750 */
    305 	iic_acquire_bus(sc->sc_i2c, 0);
    306 	error = wm8750_write(sc, RESET_REG, 0);
    307 	iic_release_bus(sc->sc_i2c, 0);
    308 	if (error) {
    309 		aprint_error_dev(self, "codec failed to respond\n");
    310 		goto fail_i2c;
    311 	}
    312 	delay(100);
    313 
    314 	/* Allocate memory for volume & mute operations */
    315 	sc->sc_volume = kmem_zalloc(sizeof(*sc->sc_volume) * WM8750_OP_NUM,
    316 	    KM_SLEEP);
    317 	sc->sc_unmute = kmem_zalloc(sizeof(*sc->sc_unmute) * WM8750_OP_NUM,
    318 	    KM_SLEEP);
    319 	sc->sc_unmute_toggle = kmem_zalloc(
    320 	    sizeof(*sc->sc_unmute_toggle) * WM8750_OP_NUM, KM_SLEEP);
    321 
    322 	/* Speaker on, headphones off by default. */
    323 	sc->sc_volume[WM8750_OP_SPKR].left = 180;
    324 	sc->sc_jack = FALSE;
    325 	UNMUTE(sc, WM8750_OP_SPKR, 1);
    326 	sc->sc_volume[WM8750_OP_HP].left = 180;
    327 	sc->sc_volume[WM8750_OP_HP].right = 180;
    328 	UNMUTE(sc, WM8750_OP_HP, 0);
    329 	sc->sc_volume[WM8750_OP_MIC].left = 180;
    330 	UNMUTE(sc, WM8750_OP_MIC, 0);
    331 
    332 	/* Configure headphone jack state change handling. */
    333 	callout_setfunc(&sc->sc_to, wm8750_jack, sc);
    334 	pxa2x0_gpio_set_function(GPIO_HP_IN_C3000, GPIO_IN);
    335 	(void) pxa2x0_gpio_intr_establish(GPIO_HP_IN_C3000, IST_EDGE_BOTH,
    336 	    IPL_BIO, wm8750_jack_intr, sc);
    337 
    338 	/* wm8750_init() implicitly depends on ioexp or scoop */
    339 	config_finalize_register(self, wm8750_finalize);
    340 
    341 	audio_attach_mi(&wm8750_hw_if, sc, self);
    342 
    343 	if (!pmf_device_register(self, wm8750_suspend, wm8750_resume))
    344 		aprint_error_dev(self, "couldn't establish power handler\n");
    345 	if (!pmf_event_register(self, PMFE_AUDIO_VOLUME_UP,
    346 	    wm8750_volume_up, true))
    347 		aprint_error_dev(self, "couldn't register event handler\n");
    348 	if (!pmf_event_register(self, PMFE_AUDIO_VOLUME_DOWN,
    349 	    wm8750_volume_down, true))
    350 		aprint_error_dev(self, "couldn't register event handler\n");
    351 	if (!pmf_event_register(self, PMFE_AUDIO_VOLUME_TOGGLE,
    352 	    wm8750_volume_toggle, true))
    353 		aprint_error_dev(self, "couldn't register event handler\n");
    354 
    355 	return;
    356 
    357 fail_i2c:
    358 	pxa2x0_i2s_detach_sub(&sc->sc_i2s);
    359 }
    360 
    361 static int
    362 wm8750_finalize(device_t dv)
    363 {
    364 	struct zaudio_softc *sc = device_private(dv);
    365 
    366 	wm8750_init(sc);
    367 	return 0;
    368 }
    369 
    370 static bool
    371 wm8750_suspend(device_t dv, const pmf_qual_t *qual)
    372 {
    373 	struct zaudio_softc *sc = device_private(dv);
    374 
    375 	callout_stop(&sc->sc_to);
    376 	wm8750_standby(sc);
    377 
    378 	return true;
    379 }
    380 
    381 static bool
    382 wm8750_resume(device_t dv, const pmf_qual_t *qual)
    383 {
    384 	struct zaudio_softc *sc = device_private(dv);
    385 
    386 	pxa2x0_i2s_init(&sc->sc_i2s);
    387 	wm8750_init(sc);
    388 
    389 	return true;
    390 }
    391 
    392 static __inline uint8_t
    393 vol_sadd(int vol, int stride)
    394 {
    395 
    396 	vol += stride;
    397 	if (vol > 255)
    398 		return 255;
    399 	return (uint8_t)vol;
    400 }
    401 
    402 #ifndef	ZAUDIO_VOLUME_STRIDE
    403 #define	ZAUDIO_VOLUME_STRIDE	8
    404 #endif
    405 
    406 static void
    407 wm8750_volume_up(device_t dv)
    408 {
    409 	struct zaudio_softc *sc = device_private(dv);
    410 	int s;
    411 
    412 	s = splbio();
    413 	iic_acquire_bus(sc->sc_i2c, 0);
    414 
    415 	sc->sc_volume[WM8750_OP_SPKR].left =
    416 	    vol_sadd(sc->sc_volume[WM8750_OP_SPKR].left, ZAUDIO_VOLUME_STRIDE);
    417 	sc->sc_volume[WM8750_OP_HP].left =
    418 	    vol_sadd(sc->sc_volume[WM8750_OP_HP].left, ZAUDIO_VOLUME_STRIDE);
    419 	sc->sc_volume[WM8750_OP_HP].right =
    420 	    vol_sadd(sc->sc_volume[WM8750_OP_HP].right, ZAUDIO_VOLUME_STRIDE);
    421 
    422 	wm8750_update_volume(sc, WM8750_OP_SPKR);
    423 	wm8750_update_volume(sc, WM8750_OP_HP);
    424 
    425 	iic_release_bus(sc->sc_i2c, 0);
    426 	splx(s);
    427 }
    428 
    429 static __inline uint8_t
    430 vol_ssub(int vol, int stride)
    431 {
    432 
    433 	vol -= stride;
    434 	if (vol < 0)
    435 		return 0;
    436 	return (uint8_t)vol;
    437 }
    438 
    439 static void
    440 wm8750_volume_down(device_t dv)
    441 {
    442 	struct zaudio_softc *sc = device_private(dv);
    443 	int s;
    444 
    445 	s = splbio();
    446 	iic_acquire_bus(sc->sc_i2c, 0);
    447 
    448 	sc->sc_volume[WM8750_OP_SPKR].left =
    449 	    vol_ssub(sc->sc_volume[WM8750_OP_SPKR].left, ZAUDIO_VOLUME_STRIDE);
    450 	sc->sc_volume[WM8750_OP_HP].left =
    451 	    vol_ssub(sc->sc_volume[WM8750_OP_HP].left, ZAUDIO_VOLUME_STRIDE);
    452 	sc->sc_volume[WM8750_OP_HP].right =
    453 	    vol_ssub(sc->sc_volume[WM8750_OP_HP].right, ZAUDIO_VOLUME_STRIDE);
    454 
    455 	wm8750_update_volume(sc, WM8750_OP_SPKR);
    456 	wm8750_update_volume(sc, WM8750_OP_HP);
    457 
    458 	iic_release_bus(sc->sc_i2c, 0);
    459 	splx(s);
    460 }
    461 
    462 static void
    463 wm8750_volume_toggle(device_t dv)
    464 {
    465 	struct zaudio_softc *sc = device_private(dv);
    466 	int s;
    467 
    468 	s = splbio();
    469 	iic_acquire_bus(sc->sc_i2c, 0);
    470 
    471 	if (!sc->sc_unmute[WM8750_OP_SPKR] && !sc->sc_unmute[WM8750_OP_HP]) {
    472 		sc->sc_unmute[WM8750_OP_SPKR] =
    473 		    sc->sc_unmute_toggle[WM8750_OP_SPKR];
    474 		sc->sc_unmute[WM8750_OP_HP] =
    475 		    sc->sc_unmute_toggle[WM8750_OP_HP];
    476 	} else {
    477 		sc->sc_unmute[WM8750_OP_SPKR] = 0;
    478 		sc->sc_unmute[WM8750_OP_HP] = 0;
    479 	}
    480 	wm8750_update_mutes(sc, 1);
    481 
    482 	iic_release_bus(sc->sc_i2c, 0);
    483 	splx(s);
    484 }
    485 
    486 static void
    487 wm8750_init(struct zaudio_softc *sc)
    488 {
    489 
    490 	iic_acquire_bus(sc->sc_i2c, 0);
    491 
    492 	/* Reset the codec */
    493 	wm8750_write(sc, RESET_REG, 0);
    494 	delay(100);
    495 
    496 	/* Switch to standby power only */
    497 	wm8750_write(sc, PWRMGMT1_REG, PWRMGMT1_SET_VMIDSEL(2));
    498 	wm8750_write(sc, PWRMGMT2_REG, 0);
    499 
    500 	/* Configure digital interface for I2S */
    501 	wm8750_write(sc, AUDINT_REG, AUDINT_SET_FORMAT(2));
    502 
    503 	/* Initialise volume levels */
    504 	wm8750_update_volume(sc, WM8750_OP_SPKR);
    505 	wm8750_update_volume(sc, WM8750_OP_HP);
    506 	wm8750_update_volume(sc, WM8750_OP_MIC);
    507 
    508 	scoop_set_headphone(0);
    509 	if (ZAURUS_ISC1000)
    510 		ioexp_set_mic_bias(0);
    511 	else
    512 		scoop_set_mic_bias(0);
    513 
    514 	iic_release_bus(sc->sc_i2c, 0);
    515 
    516 	/* Assume that the jack state has changed. */
    517 	wm8750_jack(sc);
    518 }
    519 
    520 static int
    521 wm8750_jack_intr(void *v)
    522 {
    523 	struct zaudio_softc *sc = v;
    524 
    525 	if (!callout_active(&sc->sc_to))
    526 		wm8750_jack(sc);
    527 
    528 	return 1;
    529 }
    530 
    531 static void
    532 wm8750_jack(void *v)
    533 {
    534 	struct zaudio_softc *sc = v;
    535 
    536 	switch (sc->sc_state) {
    537 	case ZAUDIO_JACK_STATE_OUT:
    538 		if (pxa2x0_gpio_get_bit(GPIO_HP_IN_C3000)) {
    539 			sc->sc_state = ZAUDIO_JACK_STATE_INS;
    540 			sc->sc_icount = 0;
    541 		}
    542 		break;
    543 
    544 	case ZAUDIO_JACK_STATE_INS:
    545 		if (sc->sc_icount++ > 2) {
    546 			if (pxa2x0_gpio_get_bit(GPIO_HP_IN_C3000)) {
    547 				sc->sc_state = ZAUDIO_JACK_STATE_IN;
    548 				sc->sc_jack = TRUE;
    549 				UNMUTE(sc, WM8750_OP_SPKR, 0);
    550 				UNMUTE(sc, WM8750_OP_HP, 1);
    551 				UNMUTE(sc, WM8750_OP_MIC, 1);
    552 				goto update_mutes;
    553 			} else
    554 				sc->sc_state = ZAUDIO_JACK_STATE_OUT;
    555 		}
    556 		break;
    557 
    558 	case ZAUDIO_JACK_STATE_IN:
    559 		if (!pxa2x0_gpio_get_bit(GPIO_HP_IN_C3000)) {
    560 			sc->sc_state = ZAUDIO_JACK_STATE_REM;
    561 			sc->sc_icount = 0;
    562 		}
    563 		break;
    564 
    565 	case ZAUDIO_JACK_STATE_REM:
    566 		if (sc->sc_icount++ > 2) {
    567 			if (!pxa2x0_gpio_get_bit(GPIO_HP_IN_C3000)) {
    568 				sc->sc_state = ZAUDIO_JACK_STATE_OUT;
    569 				sc->sc_jack = FALSE;
    570 				UNMUTE(sc, WM8750_OP_SPKR, 1);
    571 				UNMUTE(sc, WM8750_OP_HP, 0);
    572 				UNMUTE(sc, WM8750_OP_MIC, 0);
    573 				goto update_mutes;
    574 			} else
    575 				sc->sc_state = ZAUDIO_JACK_STATE_IN;
    576 		}
    577 		break;
    578 	}
    579 
    580 	callout_schedule(&sc->sc_to, hz/4);
    581 
    582 	return;
    583 
    584 update_mutes:
    585 	callout_stop(&sc->sc_to);
    586 
    587 	if (sc->sc_playing || sc->sc_recording) {
    588 		iic_acquire_bus(sc->sc_i2c, 0);
    589 		if (sc->sc_playing)
    590 			wm8750_update_mutes(sc, 1);
    591 		if (sc->sc_recording)
    592 			wm8750_update_mutes(sc, 2);
    593 		iic_release_bus(sc->sc_i2c, 0);
    594 	}
    595 }
    596 
    597 static void
    598 wm8750_standby(struct zaudio_softc *sc)
    599 {
    600 
    601 	iic_acquire_bus(sc->sc_i2c, 0);
    602 
    603 	/* Switch codec to standby power only */
    604 	wm8750_write(sc, PWRMGMT1_REG, PWRMGMT1_SET_VMIDSEL(2));
    605 	wm8750_write(sc, PWRMGMT2_REG, 0);
    606 
    607 	scoop_set_headphone(0);
    608 	if (ZAURUS_ISC1000)
    609 		ioexp_set_mic_bias(0);
    610 	else
    611 		scoop_set_mic_bias(0);
    612 
    613 	iic_release_bus(sc->sc_i2c, 0);
    614 }
    615 
    616 static void
    617 wm8750_update_volume(struct zaudio_softc *sc, int output)
    618 {
    619 
    620 	switch (output) {
    621 	case WM8750_OP_SPKR:
    622 		wm8750_write(sc, LOUT2VOL_REG, LOUT2VOL_LO2VU | LOUT2VOL_LO2ZC |
    623 		    LOUT2VOL_SET_LOUT2VOL(sc->sc_volume[WM8750_OP_SPKR].left >> 1));
    624 		wm8750_write(sc, ROUT2VOL_REG, ROUT2VOL_RO2VU | ROUT2VOL_RO2ZC |
    625 		    ROUT2VOL_SET_ROUT2VOL(sc->sc_volume[WM8750_OP_SPKR].left >> 1));
    626 		break;
    627 
    628 	case WM8750_OP_HP:
    629 		wm8750_write(sc, LOUT1VOL_REG, LOUT1VOL_LO1VU | LOUT1VOL_LO1ZC |
    630 		    LOUT1VOL_SET_LOUT1VOL(sc->sc_volume[WM8750_OP_HP].left >> 1));
    631 		wm8750_write(sc, ROUT1VOL_REG, ROUT1VOL_RO1VU | ROUT1VOL_RO1ZC |
    632 		    ROUT1VOL_SET_ROUT1VOL(sc->sc_volume[WM8750_OP_HP].right >> 1));
    633 		break;
    634 
    635 	case WM8750_OP_MIC:
    636 		wm8750_write(sc, LINVOL_REG, LINVOL_LIVU |
    637 		    LINVOL_SET_LINVOL(sc->sc_volume[WM8750_OP_MIC].left >> 2));
    638 		wm8750_write(sc, RINVOL_REG, RINVOL_RIVU |
    639 		    RINVOL_SET_RINVOL(sc->sc_volume[WM8750_OP_MIC].left >> 2));
    640 		break;
    641 	}
    642 }
    643 
    644 static void
    645 wm8750_update_mutes(struct zaudio_softc *sc, int mask)
    646 {
    647 	uint16_t val;
    648 
    649 	/* playback */
    650 	if (mask & 1) {
    651 		val = PWRMGMT2_DACL | PWRMGMT2_DACR;
    652 		if (sc->sc_unmute[WM8750_OP_SPKR])
    653 			val |= PWRMGMT2_LOUT2 | PWRMGMT2_ROUT2;
    654 		if (sc->sc_unmute[WM8750_OP_HP])
    655 			val |= PWRMGMT2_LOUT1 | PWRMGMT2_ROUT1;
    656 		wm8750_write(sc, PWRMGMT2_REG, val);
    657 		scoop_set_headphone(sc->sc_unmute[WM8750_OP_HP]);
    658 	}
    659 
    660 	/* record */
    661 	if (mask & 2) {
    662 		val = PWRMGMT1_SET_VMIDSEL(1) | PWRMGMT1_VREF;
    663 		if (sc->sc_unmute[WM8750_OP_MIC]) {
    664 			val |= PWRMGMT1_AINL | PWRMGMT1_AINR
    665 			       | PWRMGMT1_ADCL | PWRMGMT1_ADCR | PWRMGMT1_MICB;
    666 		}
    667 		wm8750_write(sc, PWRMGMT1_REG, val);
    668 		if (ZAURUS_ISC1000)
    669 			ioexp_set_mic_bias(sc->sc_unmute[WM8750_OP_MIC]);
    670 		else
    671 			scoop_set_mic_bias(sc->sc_unmute[WM8750_OP_MIC]);
    672 	}
    673 }
    674 
    675 static void
    676 wm8750_play_setup(struct zaudio_softc *sc)
    677 {
    678 	int i;
    679 
    680 	iic_acquire_bus(sc->sc_i2c, 0);
    681 
    682 	/* Program the codec with playback settings */
    683 	for (i = 0; playback_regs[i][0] != 0xffff; i++) {
    684 		wm8750_write(sc, playback_regs[i][0], playback_regs[i][1]);
    685 	}
    686 	wm8750_update_mutes(sc, 1);
    687 
    688 	iic_release_bus(sc->sc_i2c, 0);
    689 }
    690 
    691 /*static*/ void
    692 wm8750_record_setup(struct zaudio_softc *sc)
    693 {
    694 	int i;
    695 
    696 	iic_acquire_bus(sc->sc_i2c, 0);
    697 
    698 	/* Program the codec with playback settings */
    699 	for (i = 0; record_regs[i][0] != 0xffff; i++) {
    700 		wm8750_write(sc, record_regs[i][0], record_regs[i][1]);
    701 	}
    702 	wm8750_update_mutes(sc, 2);
    703 
    704 	iic_release_bus(sc->sc_i2c, 0);
    705 }
    706 
    707 static int
    708 wm8750_query_encoding(void *hdl, struct audio_encoding *aep)
    709 {
    710 
    711 	switch (aep->index) {
    712 	case 0:
    713 		strlcpy(aep->name, AudioEulinear, sizeof(aep->name));
    714 		aep->encoding = AUDIO_ENCODING_ULINEAR;
    715 		aep->precision = 8;
    716 		aep->flags = 0;
    717 		break;
    718 
    719 	case 1:
    720 		strlcpy(aep->name, AudioEmulaw, sizeof(aep->name));
    721 		aep->encoding = AUDIO_ENCODING_ULAW;
    722 		aep->precision = 8;
    723 		aep->flags = AUDIO_ENCODINGFLAG_EMULATED;
    724 		break;
    725 
    726 	case 2:
    727 		strlcpy(aep->name, AudioEalaw, sizeof(aep->name));
    728 		aep->encoding = AUDIO_ENCODING_ALAW;
    729 		aep->precision = 8;
    730 		aep->flags = AUDIO_ENCODINGFLAG_EMULATED;
    731 		break;
    732 
    733 	case 3:
    734 		strlcpy(aep->name, AudioEslinear, sizeof(aep->name));
    735 		aep->encoding = AUDIO_ENCODING_SLINEAR;
    736 		aep->precision = 8;
    737 		aep->flags = AUDIO_ENCODINGFLAG_EMULATED;
    738 		break;
    739 
    740 	case 4:
    741 		strlcpy(aep->name, AudioEslinear_le, sizeof(aep->name));
    742 		aep->encoding = AUDIO_ENCODING_SLINEAR_LE;
    743 		aep->precision = 16;
    744 		aep->flags = 0;
    745 		break;
    746 
    747 	case 5:
    748 		strlcpy(aep->name, AudioEulinear_le, sizeof(aep->name));
    749 		aep->encoding = AUDIO_ENCODING_ULINEAR_LE;
    750 		aep->precision = 16;
    751 		aep->flags = AUDIO_ENCODINGFLAG_EMULATED;
    752 		break;
    753 
    754 	case 6:
    755 		strlcpy(aep->name, AudioEslinear_be, sizeof(aep->name));
    756 		aep->encoding = AUDIO_ENCODING_SLINEAR_BE;
    757 		aep->precision = 16;
    758 		aep->flags = AUDIO_ENCODINGFLAG_EMULATED;
    759 		break;
    760 
    761 	case 7:
    762 		strlcpy(aep->name, AudioEulinear_be, sizeof(aep->name));
    763 		aep->encoding = AUDIO_ENCODING_ULINEAR_BE;
    764 		aep->precision = 16;
    765 		aep->flags = AUDIO_ENCODINGFLAG_EMULATED;
    766 		break;
    767 
    768 	default:
    769 		return EINVAL;
    770 	}
    771 
    772 	return 0;
    773 }
    774 
    775 static int
    776 wm8750_set_params(void *hdl, int setmode, int usemode, audio_params_t *play,
    777     audio_params_t *rec, stream_filter_list_t *pfil, stream_filter_list_t *rfil)
    778 {
    779 	struct zaudio_softc *sc = hdl;
    780 	struct audio_params *p;
    781 	stream_filter_list_t *fil;
    782 	int mode, i;
    783 
    784 	if (play->sample_rate != rec->sample_rate &&
    785 	    usemode == (AUMODE_PLAY | AUMODE_RECORD)) {
    786 		if (setmode == AUMODE_PLAY) {
    787 			rec->sample_rate = play->sample_rate;
    788 			setmode |= AUMODE_RECORD;
    789 		} else if (setmode == AUMODE_RECORD) {
    790 			play->sample_rate = rec->sample_rate;
    791 			setmode |= AUMODE_PLAY;
    792 		} else
    793 			return EINVAL;
    794 	}
    795 
    796 	for (mode = AUMODE_RECORD; mode != -1;
    797 	     mode = (mode == AUMODE_RECORD) ? AUMODE_PLAY : -1) {
    798 		if ((setmode & mode) == 0)
    799 			continue;
    800 
    801 		p = (mode == AUMODE_PLAY) ? play : rec;
    802 
    803 		if (p->sample_rate < 4000 || p->sample_rate > 48000 ||
    804 		    (p->precision != 8 && p->precision != 16) ||
    805 		    (p->channels != 1 && p->channels != 2))
    806 			return EINVAL;
    807 
    808 		fil = (mode == AUMODE_PLAY) ? pfil : rfil;
    809 		i = auconv_set_converter(wm8750_formats, wm8750_nformats,
    810 		    mode, p, false, fil);
    811 		if (i < 0)
    812 			return EINVAL;
    813 	}
    814 
    815 	if (setmode == AUMODE_RECORD)
    816 		pxa2x0_i2s_setspeed(&sc->sc_i2s, &rec->sample_rate);
    817 	else
    818 		pxa2x0_i2s_setspeed(&sc->sc_i2s, &play->sample_rate);
    819 
    820 	return 0;
    821 }
    822 
    823 static int
    824 wm8750_halt_output(void *hdl)
    825 {
    826 	struct zaudio_softc *sc = hdl;
    827 	int rv;
    828 
    829 	rv = pxa2x0_i2s_halt_output(&sc->sc_i2s);
    830 	if (!sc->sc_recording)
    831 		wm8750_standby(sc);
    832 	sc->sc_playing = 0;
    833 
    834 	return rv;
    835 }
    836 
    837 static int
    838 wm8750_halt_input(void *hdl)
    839 {
    840 	struct zaudio_softc *sc = hdl;
    841 	int rv;
    842 
    843 	rv = pxa2x0_i2s_halt_input(&sc->sc_i2s);
    844 	if (!sc->sc_playing)
    845 		wm8750_standby(sc);
    846 	sc->sc_recording = 0;
    847 
    848 	return rv;
    849 }
    850 
    851 static int
    852 wm8750_getdev(void *hdl, struct audio_device *ret)
    853 {
    854 
    855 	*ret = wm8750_device;
    856 	return 0;
    857 }
    858 
    859 #define WM8750_SPKR_LVL		0
    860 #define WM8750_SPKR_MUTE	1
    861 #define WM8750_HP_LVL		2
    862 #define WM8750_HP_MUTE		3
    863 #define WM8750_MIC_LVL		4
    864 #define WM8750_MIC_MUTE		5
    865 #define WM8750_RECORD_SOURCE	6
    866 #define WM8750_OUTPUT_CLASS	7
    867 #define WM8750_INPUT_CLASS	8
    868 #define WM8750_RECORD_CLASS	9
    869 
    870 static int
    871 wm8750_set_port(void *hdl, struct mixer_ctrl *mc)
    872 {
    873 	struct zaudio_softc *sc = hdl;
    874 	int error = EINVAL;
    875 	int s;
    876 
    877 	s = splbio();
    878 	iic_acquire_bus(sc->sc_i2c, 0);
    879 
    880 	switch (mc->dev) {
    881 	case WM8750_SPKR_LVL:
    882 		if (mc->type != AUDIO_MIXER_VALUE)
    883 			break;
    884 		if (mc->un.value.num_channels == 1)
    885 			sc->sc_volume[WM8750_OP_SPKR].left =
    886 			    mc->un.value.level[AUDIO_MIXER_LEVEL_MONO];
    887 		else
    888 			break;
    889 		wm8750_update_volume(sc, WM8750_OP_SPKR);
    890 		error = 0;
    891 		break;
    892 
    893 	case WM8750_SPKR_MUTE:
    894 		if (mc->type != AUDIO_MIXER_ENUM)
    895 			break;
    896 		UNMUTE(sc, WM8750_OP_SPKR, mc->un.ord ? 1 : 0);
    897 		wm8750_update_mutes(sc, 1);
    898 		error = 0;
    899 		break;
    900 
    901 	case WM8750_HP_LVL:
    902 		if (mc->type != AUDIO_MIXER_VALUE)
    903 			break;
    904 		if (mc->un.value.num_channels == 1) {
    905 			sc->sc_volume[WM8750_OP_HP].left =
    906 			    mc->un.value.level[AUDIO_MIXER_LEVEL_MONO];
    907 			sc->sc_volume[WM8750_OP_HP].right =
    908 			    mc->un.value.level[AUDIO_MIXER_LEVEL_MONO];
    909 		} else if (mc->un.value.num_channels == 2) {
    910 			sc->sc_volume[WM8750_OP_HP].left =
    911 			    mc->un.value.level[AUDIO_MIXER_LEVEL_LEFT];
    912 			sc->sc_volume[WM8750_OP_HP].right =
    913 			    mc->un.value.level[AUDIO_MIXER_LEVEL_RIGHT];
    914 		}
    915 		else
    916 			break;
    917 		wm8750_update_volume(sc, WM8750_OP_HP);
    918 		error = 0;
    919 		break;
    920 
    921 	case WM8750_HP_MUTE:
    922 		if (mc->type != AUDIO_MIXER_ENUM)
    923 			break;
    924 		UNMUTE(sc, WM8750_OP_HP, mc->un.ord ? 1 : 0);
    925 		wm8750_update_mutes(sc, 1);
    926 		error = 0;
    927 		break;
    928 
    929 	case WM8750_MIC_LVL:
    930 		if (mc->type != AUDIO_MIXER_VALUE)
    931 			break;
    932 		if (mc->un.value.num_channels == 1)
    933 			sc->sc_volume[WM8750_OP_MIC].left =
    934 			    mc->un.value.level[AUDIO_MIXER_LEVEL_MONO];
    935 		else
    936 			break;
    937 		wm8750_update_volume(sc, WM8750_OP_MIC);
    938 		error = 0;
    939 		break;
    940 
    941 	case WM8750_MIC_MUTE:
    942 		if (mc->type != AUDIO_MIXER_ENUM)
    943 			break;
    944 		UNMUTE(sc, WM8750_OP_MIC, mc->un.ord ? 1 : 0);
    945 		wm8750_update_mutes(sc, 2);
    946 		error = 0;
    947 		break;
    948 
    949 	case WM8750_RECORD_SOURCE:
    950 		if (mc->type != AUDIO_MIXER_ENUM)
    951 			break;
    952 		if (mc->un.ord != 0)
    953 			break;
    954 		/* MIC only */
    955 		error = 0;
    956 		break;
    957 	}
    958 
    959 	iic_release_bus(sc->sc_i2c, 0);
    960 	splx(s);
    961 
    962 	return error;
    963 }
    964 
    965 static int
    966 wm8750_get_port(void *hdl, struct mixer_ctrl *mc)
    967 {
    968 	struct zaudio_softc *sc = hdl;
    969 	int error = EINVAL;
    970 
    971 	switch (mc->dev) {
    972 	case WM8750_SPKR_LVL:
    973 		if (mc->type != AUDIO_MIXER_VALUE)
    974 			break;
    975 		if (mc->un.value.num_channels == 1)
    976 			mc->un.value.level[AUDIO_MIXER_LEVEL_MONO] =
    977 			    sc->sc_volume[WM8750_OP_SPKR].left;
    978 		else
    979 			break;
    980 		error = 0;
    981 		break;
    982 
    983 	case WM8750_SPKR_MUTE:
    984 		if (mc->type != AUDIO_MIXER_ENUM)
    985 			break;
    986 		mc->un.ord = sc->sc_unmute[WM8750_OP_SPKR] ? 1 : 0;
    987 		error = 0;
    988 		break;
    989 
    990 	case WM8750_HP_LVL:
    991 		if (mc->type != AUDIO_MIXER_VALUE)
    992 			break;
    993 		if (mc->un.value.num_channels == 1)
    994 			mc->un.value.level[AUDIO_MIXER_LEVEL_MONO] =
    995 			    sc->sc_volume[WM8750_OP_HP].left;
    996 		else if (mc->un.value.num_channels == 2) {
    997 			mc->un.value.level[AUDIO_MIXER_LEVEL_LEFT] =
    998 			    sc->sc_volume[WM8750_OP_HP].left;
    999 			mc->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] =
   1000 			    sc->sc_volume[WM8750_OP_HP].right;
   1001 		}
   1002 		else
   1003 			break;
   1004 		error = 0;
   1005 		break;
   1006 
   1007 	case WM8750_HP_MUTE:
   1008 		if (mc->type != AUDIO_MIXER_ENUM)
   1009 			break;
   1010 		mc->un.ord = sc->sc_unmute[WM8750_OP_HP] ? 1 : 0;
   1011 		error = 0;
   1012 		break;
   1013 
   1014 	case WM8750_MIC_LVL:
   1015 		if (mc->type != AUDIO_MIXER_VALUE)
   1016 			break;
   1017 		if (mc->un.value.num_channels == 1)
   1018 			mc->un.value.level[AUDIO_MIXER_LEVEL_MONO] =
   1019 			    sc->sc_volume[WM8750_OP_MIC].left;
   1020 		else
   1021 			break;
   1022 		error = 0;
   1023 		break;
   1024 
   1025 	case WM8750_MIC_MUTE:
   1026 		if (mc->type != AUDIO_MIXER_ENUM)
   1027 			break;
   1028 		mc->un.ord = sc->sc_unmute[WM8750_OP_MIC] ? 1 : 0;
   1029 		error = 0;
   1030 		break;
   1031 
   1032 	case WM8750_RECORD_SOURCE:
   1033 		if (mc->type != AUDIO_MIXER_ENUM)
   1034 			break;
   1035 		mc->un.ord = 0; /* MIC only */
   1036 		error = 0;
   1037 		break;
   1038 	}
   1039 
   1040 	return error;
   1041 }
   1042 
   1043 /*ARGSUSED*/
   1044 static int
   1045 wm8750_query_devinfo(void *hdl, struct mixer_devinfo *di)
   1046 {
   1047 
   1048 	switch (di->index) {
   1049 	case WM8750_SPKR_LVL:
   1050 		di->type = AUDIO_MIXER_VALUE;
   1051 		di->mixer_class = WM8750_OUTPUT_CLASS;
   1052 		di->prev = AUDIO_MIXER_LAST;
   1053 		di->next = WM8750_SPKR_MUTE;
   1054 		strlcpy(di->label.name, AudioNspeaker, sizeof(di->label.name));
   1055 		strlcpy(di->un.v.units.name, AudioNvolume,
   1056 		    sizeof(di->un.v.units.name));
   1057 		di->un.v.num_channels = 1;
   1058 		break;
   1059 
   1060 	case WM8750_SPKR_MUTE:
   1061 		di->type = AUDIO_MIXER_ENUM;
   1062 		di->mixer_class = WM8750_OUTPUT_CLASS;
   1063 		di->prev = WM8750_SPKR_LVL;
   1064 		di->next = AUDIO_MIXER_LAST;
   1065 		goto mute;
   1066 
   1067 	case WM8750_HP_LVL:
   1068 		di->type = AUDIO_MIXER_VALUE;
   1069 		di->mixer_class = WM8750_OUTPUT_CLASS;
   1070 		di->prev = AUDIO_MIXER_LAST;
   1071 		di->next = WM8750_HP_MUTE;
   1072 		strlcpy(di->label.name, AudioNheadphone,
   1073 		    sizeof(di->label.name));
   1074 		di->un.v.num_channels = 1;
   1075 		strlcpy(di->un.v.units.name, AudioNvolume,
   1076 		    sizeof(di->un.v.units.name));
   1077 		break;
   1078 
   1079 	case WM8750_HP_MUTE:
   1080 		di->type = AUDIO_MIXER_ENUM;
   1081 		di->mixer_class = WM8750_OUTPUT_CLASS;
   1082 		di->prev = WM8750_HP_LVL;
   1083 		di->next = AUDIO_MIXER_LAST;
   1084 mute:
   1085 		strlcpy(di->label.name, AudioNmute, sizeof(di->label.name));
   1086 		di->un.e.num_mem = 2;
   1087 		strlcpy(di->un.e.member[0].label.name, AudioNon,
   1088 		    sizeof(di->un.e.member[0].label.name));
   1089 		di->un.e.member[0].ord = 0;
   1090 		strlcpy(di->un.e.member[1].label.name, AudioNoff,
   1091 		    sizeof(di->un.e.member[1].label.name));
   1092 		di->un.e.member[1].ord = 1;
   1093 		break;
   1094 
   1095 	case WM8750_MIC_LVL:
   1096 		di->type = AUDIO_MIXER_VALUE;
   1097 		di->mixer_class = WM8750_INPUT_CLASS;
   1098 		di->prev = AUDIO_MIXER_LAST;
   1099 		di->next = WM8750_MIC_MUTE;
   1100 		strlcpy(di->label.name, AudioNmicrophone,
   1101 		    sizeof(di->label.name));
   1102 		strlcpy(di->un.v.units.name, AudioNvolume,
   1103 		    sizeof(di->un.v.units.name));
   1104 		di->un.v.num_channels = 1;
   1105 		break;
   1106 
   1107 	case WM8750_MIC_MUTE:
   1108 		di->type = AUDIO_MIXER_ENUM;
   1109 		di->mixer_class = WM8750_INPUT_CLASS;
   1110 		di->prev = WM8750_MIC_LVL;
   1111 		di->next = AUDIO_MIXER_LAST;
   1112 		goto mute;
   1113 
   1114 	case WM8750_RECORD_SOURCE:
   1115 		di->type = AUDIO_MIXER_ENUM;
   1116 		di->mixer_class = WM8750_RECORD_CLASS;
   1117 		di->prev = AUDIO_MIXER_LAST;
   1118 		di->next = AUDIO_MIXER_LAST;
   1119 		strlcpy(di->label.name, AudioNsource, sizeof(di->label.name));
   1120 		di->un.e.num_mem = 1;
   1121 		strlcpy(di->un.e.member[0].label.name, AudioNmicrophone,
   1122 		    sizeof(di->un.e.member[0].label.name));
   1123 		di->un.e.member[0].ord = 0;
   1124 		break;
   1125 
   1126 	case WM8750_OUTPUT_CLASS:
   1127 		di->type = AUDIO_MIXER_CLASS;
   1128 		di->mixer_class = WM8750_OUTPUT_CLASS;
   1129 		di->prev = AUDIO_MIXER_LAST;
   1130 		di->next = AUDIO_MIXER_LAST;
   1131 		strlcpy(di->label.name, AudioCoutputs, sizeof(di->label.name));
   1132 		break;
   1133 
   1134 	case WM8750_INPUT_CLASS:
   1135 		di->type = AUDIO_MIXER_CLASS;
   1136 		di->mixer_class = WM8750_INPUT_CLASS;
   1137 		di->prev = AUDIO_MIXER_LAST;
   1138 		di->next = AUDIO_MIXER_LAST;
   1139 		strlcpy(di->label.name, AudioCinputs, sizeof(di->label.name));
   1140 		break;
   1141 
   1142 	case WM8750_RECORD_CLASS:
   1143 		di->type = AUDIO_MIXER_CLASS;
   1144 		di->mixer_class = WM8750_RECORD_CLASS;
   1145 		di->prev = AUDIO_MIXER_LAST;
   1146 		di->next = AUDIO_MIXER_LAST;
   1147 		strlcpy(di->label.name, AudioCinputs, sizeof(di->label.name));
   1148 		break;
   1149 
   1150 	default:
   1151 		return ENXIO;
   1152 	}
   1153 
   1154 	return 0;
   1155 }
   1156 
   1157 static int
   1158 wm8750_start_output(void *hdl, void *block, int bsize, void (*intr)(void *),
   1159     void *intrarg)
   1160 {
   1161 	struct zaudio_softc *sc = hdl;
   1162 	int rv;
   1163 
   1164 	/* Power up codec if we are not already playing. */
   1165 	if (!sc->sc_playing) {
   1166 		sc->sc_playing = 1;
   1167 		wm8750_play_setup(sc);
   1168 	}
   1169 
   1170 	/* Start DMA via I2S */
   1171 	rv = pxa2x0_i2s_start_output(&sc->sc_i2s, block, bsize, intr, intrarg);
   1172 	if (rv) {
   1173 		if (!sc->sc_recording)
   1174 			wm8750_standby(sc);
   1175 		sc->sc_playing = 0;
   1176 	}
   1177 
   1178 	return rv;
   1179 }
   1180 
   1181 static int
   1182 wm8750_start_input(void *hdl, void *block, int bsize, void (*intr)(void *),
   1183     void *intrarg)
   1184 {
   1185 	struct zaudio_softc *sc = hdl;
   1186 	int rv;
   1187 
   1188 	/* Power up codec if we are not already recording. */
   1189 	if (!sc->sc_recording) {
   1190 		sc->sc_recording = 1;
   1191 		wm8750_record_setup(sc);
   1192 	}
   1193 
   1194 	/* Start DMA via I2S */
   1195 	rv = pxa2x0_i2s_start_input(&sc->sc_i2s, block, bsize, intr, intrarg);
   1196 	if (rv) {
   1197 		if (!sc->sc_playing)
   1198 			wm8750_standby(sc);
   1199 		sc->sc_recording = 0;
   1200 	}
   1201 	return rv;
   1202 }
   1203