xref: /kernel/linux/linux-5.10/sound/pci/ice1712/ews.c (revision 8c2ecf20)
18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *   ALSA driver for ICEnsemble ICE1712 (Envy24)
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci *   Lowlevel functions for Terratec EWS88MT/D, EWX24/96, DMX 6Fire
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci *	Copyright (c) 2000 Jaroslav Kysela <perex@perex.cz>
88c2ecf20Sopenharmony_ci *                    2002 Takashi Iwai <tiwai@suse.de>
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include <linux/delay.h>
128c2ecf20Sopenharmony_ci#include <linux/interrupt.h>
138c2ecf20Sopenharmony_ci#include <linux/init.h>
148c2ecf20Sopenharmony_ci#include <linux/slab.h>
158c2ecf20Sopenharmony_ci#include <sound/core.h>
168c2ecf20Sopenharmony_ci#include <sound/cs8427.h>
178c2ecf20Sopenharmony_ci#include <sound/asoundef.h>
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#include "ice1712.h"
208c2ecf20Sopenharmony_ci#include "ews.h"
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci#define SND_CS8404
238c2ecf20Sopenharmony_ci#include <sound/cs8403.h>
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_cienum {
268c2ecf20Sopenharmony_ci	EWS_I2C_CS8404 = 0, EWS_I2C_PCF1, EWS_I2C_PCF2,
278c2ecf20Sopenharmony_ci	EWS_I2C_88D = 0,
288c2ecf20Sopenharmony_ci	EWS_I2C_6FIRE = 0
298c2ecf20Sopenharmony_ci};
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci/* additional i2c devices for EWS boards */
338c2ecf20Sopenharmony_cistruct ews_spec {
348c2ecf20Sopenharmony_ci	struct snd_i2c_device *i2cdevs[3];
358c2ecf20Sopenharmony_ci};
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci/*
388c2ecf20Sopenharmony_ci * access via i2c mode (for EWX 24/96, EWS 88MT&D)
398c2ecf20Sopenharmony_ci */
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci/* send SDA and SCL */
428c2ecf20Sopenharmony_cistatic void ewx_i2c_setlines(struct snd_i2c_bus *bus, int clk, int data)
438c2ecf20Sopenharmony_ci{
448c2ecf20Sopenharmony_ci	struct snd_ice1712 *ice = bus->private_data;
458c2ecf20Sopenharmony_ci	unsigned char tmp = 0;
468c2ecf20Sopenharmony_ci	if (clk)
478c2ecf20Sopenharmony_ci		tmp |= ICE1712_EWX2496_SERIAL_CLOCK;
488c2ecf20Sopenharmony_ci	if (data)
498c2ecf20Sopenharmony_ci		tmp |= ICE1712_EWX2496_SERIAL_DATA;
508c2ecf20Sopenharmony_ci	snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
518c2ecf20Sopenharmony_ci	udelay(5);
528c2ecf20Sopenharmony_ci}
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_cistatic int ewx_i2c_getclock(struct snd_i2c_bus *bus)
558c2ecf20Sopenharmony_ci{
568c2ecf20Sopenharmony_ci	struct snd_ice1712 *ice = bus->private_data;
578c2ecf20Sopenharmony_ci	return snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & ICE1712_EWX2496_SERIAL_CLOCK ? 1 : 0;
588c2ecf20Sopenharmony_ci}
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_cistatic int ewx_i2c_getdata(struct snd_i2c_bus *bus, int ack)
618c2ecf20Sopenharmony_ci{
628c2ecf20Sopenharmony_ci	struct snd_ice1712 *ice = bus->private_data;
638c2ecf20Sopenharmony_ci	int bit;
648c2ecf20Sopenharmony_ci	/* set RW pin to low */
658c2ecf20Sopenharmony_ci	snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~ICE1712_EWX2496_RW);
668c2ecf20Sopenharmony_ci	snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, 0);
678c2ecf20Sopenharmony_ci	if (ack)
688c2ecf20Sopenharmony_ci		udelay(5);
698c2ecf20Sopenharmony_ci	bit = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & ICE1712_EWX2496_SERIAL_DATA ? 1 : 0;
708c2ecf20Sopenharmony_ci	/* set RW pin to high */
718c2ecf20Sopenharmony_ci	snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, ICE1712_EWX2496_RW);
728c2ecf20Sopenharmony_ci	/* reset write mask */
738c2ecf20Sopenharmony_ci	snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~ICE1712_EWX2496_SERIAL_CLOCK);
748c2ecf20Sopenharmony_ci	return bit;
758c2ecf20Sopenharmony_ci}
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_cistatic void ewx_i2c_start(struct snd_i2c_bus *bus)
788c2ecf20Sopenharmony_ci{
798c2ecf20Sopenharmony_ci	struct snd_ice1712 *ice = bus->private_data;
808c2ecf20Sopenharmony_ci	unsigned char mask;
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci	snd_ice1712_save_gpio_status(ice);
838c2ecf20Sopenharmony_ci	/* set RW high */
848c2ecf20Sopenharmony_ci	mask = ICE1712_EWX2496_RW;
858c2ecf20Sopenharmony_ci	switch (ice->eeprom.subvendor) {
868c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_EWX2496:
878c2ecf20Sopenharmony_ci		mask |= ICE1712_EWX2496_AK4524_CS; /* CS high also */
888c2ecf20Sopenharmony_ci		break;
898c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_DMX6FIRE:
908c2ecf20Sopenharmony_ci		mask |= ICE1712_6FIRE_AK4524_CS_MASK; /* CS high also */
918c2ecf20Sopenharmony_ci		break;
928c2ecf20Sopenharmony_ci	}
938c2ecf20Sopenharmony_ci	snd_ice1712_gpio_write_bits(ice, mask, mask);
948c2ecf20Sopenharmony_ci}
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_cistatic void ewx_i2c_stop(struct snd_i2c_bus *bus)
978c2ecf20Sopenharmony_ci{
988c2ecf20Sopenharmony_ci	struct snd_ice1712 *ice = bus->private_data;
998c2ecf20Sopenharmony_ci	snd_ice1712_restore_gpio_status(ice);
1008c2ecf20Sopenharmony_ci}
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_cistatic void ewx_i2c_direction(struct snd_i2c_bus *bus, int clock, int data)
1038c2ecf20Sopenharmony_ci{
1048c2ecf20Sopenharmony_ci	struct snd_ice1712 *ice = bus->private_data;
1058c2ecf20Sopenharmony_ci	unsigned char mask = 0;
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci	if (clock)
1088c2ecf20Sopenharmony_ci		mask |= ICE1712_EWX2496_SERIAL_CLOCK; /* write SCL */
1098c2ecf20Sopenharmony_ci	if (data)
1108c2ecf20Sopenharmony_ci		mask |= ICE1712_EWX2496_SERIAL_DATA; /* write SDA */
1118c2ecf20Sopenharmony_ci	ice->gpio.direction &= ~(ICE1712_EWX2496_SERIAL_CLOCK|ICE1712_EWX2496_SERIAL_DATA);
1128c2ecf20Sopenharmony_ci	ice->gpio.direction |= mask;
1138c2ecf20Sopenharmony_ci	snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, ice->gpio.direction);
1148c2ecf20Sopenharmony_ci	snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~mask);
1158c2ecf20Sopenharmony_ci}
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_cistatic struct snd_i2c_bit_ops snd_ice1712_ewx_cs8427_bit_ops = {
1188c2ecf20Sopenharmony_ci	.start = ewx_i2c_start,
1198c2ecf20Sopenharmony_ci	.stop = ewx_i2c_stop,
1208c2ecf20Sopenharmony_ci	.direction = ewx_i2c_direction,
1218c2ecf20Sopenharmony_ci	.setlines = ewx_i2c_setlines,
1228c2ecf20Sopenharmony_ci	.getclock = ewx_i2c_getclock,
1238c2ecf20Sopenharmony_ci	.getdata = ewx_i2c_getdata,
1248c2ecf20Sopenharmony_ci};
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci/*
1288c2ecf20Sopenharmony_ci * AK4524 access
1298c2ecf20Sopenharmony_ci */
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci/* AK4524 chip select; address 0x48 bit 0-3 */
1328c2ecf20Sopenharmony_cistatic int snd_ice1712_ews88mt_chip_select(struct snd_ice1712 *ice, int chip_mask)
1338c2ecf20Sopenharmony_ci{
1348c2ecf20Sopenharmony_ci	struct ews_spec *spec = ice->spec;
1358c2ecf20Sopenharmony_ci	unsigned char data, ndata;
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci	if (snd_BUG_ON(chip_mask < 0 || chip_mask > 0x0f))
1388c2ecf20Sopenharmony_ci		return -EINVAL;
1398c2ecf20Sopenharmony_ci	snd_i2c_lock(ice->i2c);
1408c2ecf20Sopenharmony_ci	if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_PCF2], &data, 1) != 1)
1418c2ecf20Sopenharmony_ci		goto __error;
1428c2ecf20Sopenharmony_ci	ndata = (data & 0xf0) | chip_mask;
1438c2ecf20Sopenharmony_ci	if (ndata != data)
1448c2ecf20Sopenharmony_ci		if (snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_PCF2], &ndata, 1)
1458c2ecf20Sopenharmony_ci		    != 1)
1468c2ecf20Sopenharmony_ci			goto __error;
1478c2ecf20Sopenharmony_ci	snd_i2c_unlock(ice->i2c);
1488c2ecf20Sopenharmony_ci	return 0;
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci     __error:
1518c2ecf20Sopenharmony_ci	snd_i2c_unlock(ice->i2c);
1528c2ecf20Sopenharmony_ci	dev_err(ice->card->dev,
1538c2ecf20Sopenharmony_ci		"AK4524 chip select failed, check cable to the front module\n");
1548c2ecf20Sopenharmony_ci	return -EIO;
1558c2ecf20Sopenharmony_ci}
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci/* start callback for EWS88MT, needs to select a certain chip mask */
1588c2ecf20Sopenharmony_cistatic void ews88mt_ak4524_lock(struct snd_akm4xxx *ak, int chip)
1598c2ecf20Sopenharmony_ci{
1608c2ecf20Sopenharmony_ci	struct snd_ice1712 *ice = ak->private_data[0];
1618c2ecf20Sopenharmony_ci	unsigned char tmp;
1628c2ecf20Sopenharmony_ci	/* assert AK4524 CS */
1638c2ecf20Sopenharmony_ci	if (snd_ice1712_ews88mt_chip_select(ice, ~(1 << chip) & 0x0f) < 0)
1648c2ecf20Sopenharmony_ci		dev_err(ice->card->dev, "fatal error (ews88mt chip select)\n");
1658c2ecf20Sopenharmony_ci	snd_ice1712_save_gpio_status(ice);
1668c2ecf20Sopenharmony_ci	tmp = ICE1712_EWS88_SERIAL_DATA |
1678c2ecf20Sopenharmony_ci		ICE1712_EWS88_SERIAL_CLOCK |
1688c2ecf20Sopenharmony_ci		ICE1712_EWS88_RW;
1698c2ecf20Sopenharmony_ci	snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION,
1708c2ecf20Sopenharmony_ci			  ice->gpio.direction | tmp);
1718c2ecf20Sopenharmony_ci	snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~tmp);
1728c2ecf20Sopenharmony_ci}
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_ci/* stop callback for EWS88MT, needs to deselect chip mask */
1758c2ecf20Sopenharmony_cistatic void ews88mt_ak4524_unlock(struct snd_akm4xxx *ak, int chip)
1768c2ecf20Sopenharmony_ci{
1778c2ecf20Sopenharmony_ci	struct snd_ice1712 *ice = ak->private_data[0];
1788c2ecf20Sopenharmony_ci	snd_ice1712_restore_gpio_status(ice);
1798c2ecf20Sopenharmony_ci	udelay(1);
1808c2ecf20Sopenharmony_ci	snd_ice1712_ews88mt_chip_select(ice, 0x0f);
1818c2ecf20Sopenharmony_ci}
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_ci/* start callback for EWX24/96 */
1848c2ecf20Sopenharmony_cistatic void ewx2496_ak4524_lock(struct snd_akm4xxx *ak, int chip)
1858c2ecf20Sopenharmony_ci{
1868c2ecf20Sopenharmony_ci	struct snd_ice1712 *ice = ak->private_data[0];
1878c2ecf20Sopenharmony_ci	unsigned char tmp;
1888c2ecf20Sopenharmony_ci	snd_ice1712_save_gpio_status(ice);
1898c2ecf20Sopenharmony_ci	tmp =  ICE1712_EWX2496_SERIAL_DATA |
1908c2ecf20Sopenharmony_ci		ICE1712_EWX2496_SERIAL_CLOCK |
1918c2ecf20Sopenharmony_ci		ICE1712_EWX2496_AK4524_CS |
1928c2ecf20Sopenharmony_ci		ICE1712_EWX2496_RW;
1938c2ecf20Sopenharmony_ci	snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION,
1948c2ecf20Sopenharmony_ci			  ice->gpio.direction | tmp);
1958c2ecf20Sopenharmony_ci	snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~tmp);
1968c2ecf20Sopenharmony_ci}
1978c2ecf20Sopenharmony_ci
1988c2ecf20Sopenharmony_ci/* start callback for DMX 6fire */
1998c2ecf20Sopenharmony_cistatic void dmx6fire_ak4524_lock(struct snd_akm4xxx *ak, int chip)
2008c2ecf20Sopenharmony_ci{
2018c2ecf20Sopenharmony_ci	struct snd_ak4xxx_private *priv = (void *)ak->private_value[0];
2028c2ecf20Sopenharmony_ci	struct snd_ice1712 *ice = ak->private_data[0];
2038c2ecf20Sopenharmony_ci	unsigned char tmp;
2048c2ecf20Sopenharmony_ci	snd_ice1712_save_gpio_status(ice);
2058c2ecf20Sopenharmony_ci	tmp = priv->cs_mask = priv->cs_addr = (1 << chip) & ICE1712_6FIRE_AK4524_CS_MASK;
2068c2ecf20Sopenharmony_ci	tmp |= ICE1712_6FIRE_SERIAL_DATA |
2078c2ecf20Sopenharmony_ci		ICE1712_6FIRE_SERIAL_CLOCK |
2088c2ecf20Sopenharmony_ci		ICE1712_6FIRE_RW;
2098c2ecf20Sopenharmony_ci	snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION,
2108c2ecf20Sopenharmony_ci			  ice->gpio.direction | tmp);
2118c2ecf20Sopenharmony_ci	snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~tmp);
2128c2ecf20Sopenharmony_ci}
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_ci/*
2158c2ecf20Sopenharmony_ci * CS8404 interface on EWS88MT/D
2168c2ecf20Sopenharmony_ci */
2178c2ecf20Sopenharmony_ci
2188c2ecf20Sopenharmony_cistatic void snd_ice1712_ews_cs8404_spdif_write(struct snd_ice1712 *ice, unsigned char bits)
2198c2ecf20Sopenharmony_ci{
2208c2ecf20Sopenharmony_ci	struct ews_spec *spec = ice->spec;
2218c2ecf20Sopenharmony_ci	unsigned char bytes[2];
2228c2ecf20Sopenharmony_ci
2238c2ecf20Sopenharmony_ci	snd_i2c_lock(ice->i2c);
2248c2ecf20Sopenharmony_ci	switch (ice->eeprom.subvendor) {
2258c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_EWS88MT:
2268c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_EWS88MT_NEW:
2278c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_PHASE88:
2288c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_TS88:
2298c2ecf20Sopenharmony_ci		if (snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_CS8404], &bits, 1)
2308c2ecf20Sopenharmony_ci		    != 1)
2318c2ecf20Sopenharmony_ci			goto _error;
2328c2ecf20Sopenharmony_ci		break;
2338c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_EWS88D:
2348c2ecf20Sopenharmony_ci		if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_88D], bytes, 2)
2358c2ecf20Sopenharmony_ci		    != 2)
2368c2ecf20Sopenharmony_ci			goto _error;
2378c2ecf20Sopenharmony_ci		if (bits != bytes[1]) {
2388c2ecf20Sopenharmony_ci			bytes[1] = bits;
2398c2ecf20Sopenharmony_ci			if (snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_88D],
2408c2ecf20Sopenharmony_ci					      bytes, 2) != 2)
2418c2ecf20Sopenharmony_ci				goto _error;
2428c2ecf20Sopenharmony_ci		}
2438c2ecf20Sopenharmony_ci		break;
2448c2ecf20Sopenharmony_ci	}
2458c2ecf20Sopenharmony_ci _error:
2468c2ecf20Sopenharmony_ci	snd_i2c_unlock(ice->i2c);
2478c2ecf20Sopenharmony_ci}
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_ci/*
2508c2ecf20Sopenharmony_ci */
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_cistatic void ews88_spdif_default_get(struct snd_ice1712 *ice, struct snd_ctl_elem_value *ucontrol)
2538c2ecf20Sopenharmony_ci{
2548c2ecf20Sopenharmony_ci	snd_cs8404_decode_spdif_bits(&ucontrol->value.iec958, ice->spdif.cs8403_bits);
2558c2ecf20Sopenharmony_ci}
2568c2ecf20Sopenharmony_ci
2578c2ecf20Sopenharmony_cistatic int ews88_spdif_default_put(struct snd_ice1712 *ice, struct snd_ctl_elem_value *ucontrol)
2588c2ecf20Sopenharmony_ci{
2598c2ecf20Sopenharmony_ci	unsigned int val;
2608c2ecf20Sopenharmony_ci	int change;
2618c2ecf20Sopenharmony_ci
2628c2ecf20Sopenharmony_ci	val = snd_cs8404_encode_spdif_bits(&ucontrol->value.iec958);
2638c2ecf20Sopenharmony_ci	spin_lock_irq(&ice->reg_lock);
2648c2ecf20Sopenharmony_ci	change = ice->spdif.cs8403_bits != val;
2658c2ecf20Sopenharmony_ci	ice->spdif.cs8403_bits = val;
2668c2ecf20Sopenharmony_ci	if (change && ice->playback_pro_substream == NULL) {
2678c2ecf20Sopenharmony_ci		spin_unlock_irq(&ice->reg_lock);
2688c2ecf20Sopenharmony_ci		snd_ice1712_ews_cs8404_spdif_write(ice, val);
2698c2ecf20Sopenharmony_ci	} else {
2708c2ecf20Sopenharmony_ci		spin_unlock_irq(&ice->reg_lock);
2718c2ecf20Sopenharmony_ci	}
2728c2ecf20Sopenharmony_ci	return change;
2738c2ecf20Sopenharmony_ci}
2748c2ecf20Sopenharmony_ci
2758c2ecf20Sopenharmony_cistatic void ews88_spdif_stream_get(struct snd_ice1712 *ice, struct snd_ctl_elem_value *ucontrol)
2768c2ecf20Sopenharmony_ci{
2778c2ecf20Sopenharmony_ci	snd_cs8404_decode_spdif_bits(&ucontrol->value.iec958, ice->spdif.cs8403_stream_bits);
2788c2ecf20Sopenharmony_ci}
2798c2ecf20Sopenharmony_ci
2808c2ecf20Sopenharmony_cistatic int ews88_spdif_stream_put(struct snd_ice1712 *ice, struct snd_ctl_elem_value *ucontrol)
2818c2ecf20Sopenharmony_ci{
2828c2ecf20Sopenharmony_ci	unsigned int val;
2838c2ecf20Sopenharmony_ci	int change;
2848c2ecf20Sopenharmony_ci
2858c2ecf20Sopenharmony_ci	val = snd_cs8404_encode_spdif_bits(&ucontrol->value.iec958);
2868c2ecf20Sopenharmony_ci	spin_lock_irq(&ice->reg_lock);
2878c2ecf20Sopenharmony_ci	change = ice->spdif.cs8403_stream_bits != val;
2888c2ecf20Sopenharmony_ci	ice->spdif.cs8403_stream_bits = val;
2898c2ecf20Sopenharmony_ci	if (change && ice->playback_pro_substream != NULL) {
2908c2ecf20Sopenharmony_ci		spin_unlock_irq(&ice->reg_lock);
2918c2ecf20Sopenharmony_ci		snd_ice1712_ews_cs8404_spdif_write(ice, val);
2928c2ecf20Sopenharmony_ci	} else {
2938c2ecf20Sopenharmony_ci		spin_unlock_irq(&ice->reg_lock);
2948c2ecf20Sopenharmony_ci	}
2958c2ecf20Sopenharmony_ci	return change;
2968c2ecf20Sopenharmony_ci}
2978c2ecf20Sopenharmony_ci
2988c2ecf20Sopenharmony_ci
2998c2ecf20Sopenharmony_ci/* open callback */
3008c2ecf20Sopenharmony_cistatic void ews88_open_spdif(struct snd_ice1712 *ice, struct snd_pcm_substream *substream)
3018c2ecf20Sopenharmony_ci{
3028c2ecf20Sopenharmony_ci	ice->spdif.cs8403_stream_bits = ice->spdif.cs8403_bits;
3038c2ecf20Sopenharmony_ci}
3048c2ecf20Sopenharmony_ci
3058c2ecf20Sopenharmony_ci/* set up SPDIF for EWS88MT / EWS88D */
3068c2ecf20Sopenharmony_cistatic void ews88_setup_spdif(struct snd_ice1712 *ice, int rate)
3078c2ecf20Sopenharmony_ci{
3088c2ecf20Sopenharmony_ci	unsigned long flags;
3098c2ecf20Sopenharmony_ci	unsigned char tmp;
3108c2ecf20Sopenharmony_ci	int change;
3118c2ecf20Sopenharmony_ci
3128c2ecf20Sopenharmony_ci	spin_lock_irqsave(&ice->reg_lock, flags);
3138c2ecf20Sopenharmony_ci	tmp = ice->spdif.cs8403_stream_bits;
3148c2ecf20Sopenharmony_ci	if (tmp & 0x10)		/* consumer */
3158c2ecf20Sopenharmony_ci		tmp &= (tmp & 0x01) ? ~0x06 : ~0x60;
3168c2ecf20Sopenharmony_ci	switch (rate) {
3178c2ecf20Sopenharmony_ci	case 32000: tmp |= (tmp & 0x01) ? 0x02 : 0x00; break;
3188c2ecf20Sopenharmony_ci	case 44100: tmp |= (tmp & 0x01) ? 0x06 : 0x40; break;
3198c2ecf20Sopenharmony_ci	case 48000: tmp |= (tmp & 0x01) ? 0x04 : 0x20; break;
3208c2ecf20Sopenharmony_ci	default: tmp |= (tmp & 0x01) ? 0x06 : 0x40; break;
3218c2ecf20Sopenharmony_ci	}
3228c2ecf20Sopenharmony_ci	change = ice->spdif.cs8403_stream_bits != tmp;
3238c2ecf20Sopenharmony_ci	ice->spdif.cs8403_stream_bits = tmp;
3248c2ecf20Sopenharmony_ci	spin_unlock_irqrestore(&ice->reg_lock, flags);
3258c2ecf20Sopenharmony_ci	if (change)
3268c2ecf20Sopenharmony_ci		snd_ctl_notify(ice->card, SNDRV_CTL_EVENT_MASK_VALUE, &ice->spdif.stream_ctl->id);
3278c2ecf20Sopenharmony_ci	snd_ice1712_ews_cs8404_spdif_write(ice, tmp);
3288c2ecf20Sopenharmony_ci}
3298c2ecf20Sopenharmony_ci
3308c2ecf20Sopenharmony_ci
3318c2ecf20Sopenharmony_ci/*
3328c2ecf20Sopenharmony_ci */
3338c2ecf20Sopenharmony_cistatic const struct snd_akm4xxx akm_ews88mt = {
3348c2ecf20Sopenharmony_ci	.num_adcs = 8,
3358c2ecf20Sopenharmony_ci	.num_dacs = 8,
3368c2ecf20Sopenharmony_ci	.type = SND_AK4524,
3378c2ecf20Sopenharmony_ci	.ops = {
3388c2ecf20Sopenharmony_ci		.lock = ews88mt_ak4524_lock,
3398c2ecf20Sopenharmony_ci		.unlock = ews88mt_ak4524_unlock
3408c2ecf20Sopenharmony_ci	}
3418c2ecf20Sopenharmony_ci};
3428c2ecf20Sopenharmony_ci
3438c2ecf20Sopenharmony_cistatic const struct snd_ak4xxx_private akm_ews88mt_priv = {
3448c2ecf20Sopenharmony_ci	.caddr = 2,
3458c2ecf20Sopenharmony_ci	.cif = 1, /* CIF high */
3468c2ecf20Sopenharmony_ci	.data_mask = ICE1712_EWS88_SERIAL_DATA,
3478c2ecf20Sopenharmony_ci	.clk_mask = ICE1712_EWS88_SERIAL_CLOCK,
3488c2ecf20Sopenharmony_ci	.cs_mask = 0,
3498c2ecf20Sopenharmony_ci	.cs_addr = 0,
3508c2ecf20Sopenharmony_ci	.cs_none = 0, /* no chip select on gpio */
3518c2ecf20Sopenharmony_ci	.add_flags = ICE1712_EWS88_RW, /* set rw bit high */
3528c2ecf20Sopenharmony_ci	.mask_flags = 0,
3538c2ecf20Sopenharmony_ci};
3548c2ecf20Sopenharmony_ci
3558c2ecf20Sopenharmony_cistatic const struct snd_akm4xxx akm_ewx2496 = {
3568c2ecf20Sopenharmony_ci	.num_adcs = 2,
3578c2ecf20Sopenharmony_ci	.num_dacs = 2,
3588c2ecf20Sopenharmony_ci	.type = SND_AK4524,
3598c2ecf20Sopenharmony_ci	.ops = {
3608c2ecf20Sopenharmony_ci		.lock = ewx2496_ak4524_lock
3618c2ecf20Sopenharmony_ci	}
3628c2ecf20Sopenharmony_ci};
3638c2ecf20Sopenharmony_ci
3648c2ecf20Sopenharmony_cistatic const struct snd_ak4xxx_private akm_ewx2496_priv = {
3658c2ecf20Sopenharmony_ci	.caddr = 2,
3668c2ecf20Sopenharmony_ci	.cif = 1, /* CIF high */
3678c2ecf20Sopenharmony_ci	.data_mask = ICE1712_EWS88_SERIAL_DATA,
3688c2ecf20Sopenharmony_ci	.clk_mask = ICE1712_EWS88_SERIAL_CLOCK,
3698c2ecf20Sopenharmony_ci	.cs_mask = ICE1712_EWX2496_AK4524_CS,
3708c2ecf20Sopenharmony_ci	.cs_addr = ICE1712_EWX2496_AK4524_CS,
3718c2ecf20Sopenharmony_ci	.cs_none = 0,
3728c2ecf20Sopenharmony_ci	.add_flags = ICE1712_EWS88_RW, /* set rw bit high */
3738c2ecf20Sopenharmony_ci	.mask_flags = 0,
3748c2ecf20Sopenharmony_ci};
3758c2ecf20Sopenharmony_ci
3768c2ecf20Sopenharmony_cistatic const struct snd_akm4xxx akm_6fire = {
3778c2ecf20Sopenharmony_ci	.num_adcs = 6,
3788c2ecf20Sopenharmony_ci	.num_dacs = 6,
3798c2ecf20Sopenharmony_ci	.type = SND_AK4524,
3808c2ecf20Sopenharmony_ci	.ops = {
3818c2ecf20Sopenharmony_ci		.lock = dmx6fire_ak4524_lock
3828c2ecf20Sopenharmony_ci	}
3838c2ecf20Sopenharmony_ci};
3848c2ecf20Sopenharmony_ci
3858c2ecf20Sopenharmony_cistatic const struct snd_ak4xxx_private akm_6fire_priv = {
3868c2ecf20Sopenharmony_ci	.caddr = 2,
3878c2ecf20Sopenharmony_ci	.cif = 1, /* CIF high */
3888c2ecf20Sopenharmony_ci	.data_mask = ICE1712_6FIRE_SERIAL_DATA,
3898c2ecf20Sopenharmony_ci	.clk_mask = ICE1712_6FIRE_SERIAL_CLOCK,
3908c2ecf20Sopenharmony_ci	.cs_mask = 0,
3918c2ecf20Sopenharmony_ci	.cs_addr = 0, /* set later */
3928c2ecf20Sopenharmony_ci	.cs_none = 0,
3938c2ecf20Sopenharmony_ci	.add_flags = ICE1712_6FIRE_RW, /* set rw bit high */
3948c2ecf20Sopenharmony_ci	.mask_flags = 0,
3958c2ecf20Sopenharmony_ci};
3968c2ecf20Sopenharmony_ci
3978c2ecf20Sopenharmony_ci/*
3988c2ecf20Sopenharmony_ci * initialize the chip
3998c2ecf20Sopenharmony_ci */
4008c2ecf20Sopenharmony_ci
4018c2ecf20Sopenharmony_ci/* 6fire specific */
4028c2ecf20Sopenharmony_ci#define PCF9554_REG_INPUT      0
4038c2ecf20Sopenharmony_ci#define PCF9554_REG_OUTPUT     1
4048c2ecf20Sopenharmony_ci#define PCF9554_REG_POLARITY   2
4058c2ecf20Sopenharmony_ci#define PCF9554_REG_CONFIG     3
4068c2ecf20Sopenharmony_ci
4078c2ecf20Sopenharmony_cistatic int snd_ice1712_6fire_write_pca(struct snd_ice1712 *ice, unsigned char reg, unsigned char data);
4088c2ecf20Sopenharmony_ci
4098c2ecf20Sopenharmony_cistatic int snd_ice1712_ews_init(struct snd_ice1712 *ice)
4108c2ecf20Sopenharmony_ci{
4118c2ecf20Sopenharmony_ci	int err;
4128c2ecf20Sopenharmony_ci	struct snd_akm4xxx *ak;
4138c2ecf20Sopenharmony_ci	struct ews_spec *spec;
4148c2ecf20Sopenharmony_ci
4158c2ecf20Sopenharmony_ci	/* set the analog DACs */
4168c2ecf20Sopenharmony_ci	switch (ice->eeprom.subvendor) {
4178c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_EWX2496:
4188c2ecf20Sopenharmony_ci		ice->num_total_dacs = 2;
4198c2ecf20Sopenharmony_ci		ice->num_total_adcs = 2;
4208c2ecf20Sopenharmony_ci		break;
4218c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_EWS88MT:
4228c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_EWS88MT_NEW:
4238c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_PHASE88:
4248c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_TS88:
4258c2ecf20Sopenharmony_ci		ice->num_total_dacs = 8;
4268c2ecf20Sopenharmony_ci		ice->num_total_adcs = 8;
4278c2ecf20Sopenharmony_ci		break;
4288c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_EWS88D:
4298c2ecf20Sopenharmony_ci		/* Note: not analog but ADAT I/O */
4308c2ecf20Sopenharmony_ci		ice->num_total_dacs = 8;
4318c2ecf20Sopenharmony_ci		ice->num_total_adcs = 8;
4328c2ecf20Sopenharmony_ci		break;
4338c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_DMX6FIRE:
4348c2ecf20Sopenharmony_ci		ice->num_total_dacs = 6;
4358c2ecf20Sopenharmony_ci		ice->num_total_adcs = 6;
4368c2ecf20Sopenharmony_ci		break;
4378c2ecf20Sopenharmony_ci	}
4388c2ecf20Sopenharmony_ci
4398c2ecf20Sopenharmony_ci	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4408c2ecf20Sopenharmony_ci	if (!spec)
4418c2ecf20Sopenharmony_ci		return -ENOMEM;
4428c2ecf20Sopenharmony_ci	ice->spec = spec;
4438c2ecf20Sopenharmony_ci
4448c2ecf20Sopenharmony_ci	/* create i2c */
4458c2ecf20Sopenharmony_ci	if ((err = snd_i2c_bus_create(ice->card, "ICE1712 GPIO 1", NULL, &ice->i2c)) < 0) {
4468c2ecf20Sopenharmony_ci		dev_err(ice->card->dev, "unable to create I2C bus\n");
4478c2ecf20Sopenharmony_ci		return err;
4488c2ecf20Sopenharmony_ci	}
4498c2ecf20Sopenharmony_ci	ice->i2c->private_data = ice;
4508c2ecf20Sopenharmony_ci	ice->i2c->hw_ops.bit = &snd_ice1712_ewx_cs8427_bit_ops;
4518c2ecf20Sopenharmony_ci
4528c2ecf20Sopenharmony_ci	/* create i2c devices */
4538c2ecf20Sopenharmony_ci	switch (ice->eeprom.subvendor) {
4548c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_DMX6FIRE:
4558c2ecf20Sopenharmony_ci		err = snd_i2c_device_create(ice->i2c, "PCF9554",
4568c2ecf20Sopenharmony_ci					    ICE1712_6FIRE_PCF9554_ADDR,
4578c2ecf20Sopenharmony_ci					    &spec->i2cdevs[EWS_I2C_6FIRE]);
4588c2ecf20Sopenharmony_ci		if (err < 0) {
4598c2ecf20Sopenharmony_ci			dev_err(ice->card->dev,
4608c2ecf20Sopenharmony_ci				"PCF9554 initialization failed\n");
4618c2ecf20Sopenharmony_ci			return err;
4628c2ecf20Sopenharmony_ci		}
4638c2ecf20Sopenharmony_ci		snd_ice1712_6fire_write_pca(ice, PCF9554_REG_CONFIG, 0x80);
4648c2ecf20Sopenharmony_ci		break;
4658c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_EWS88MT:
4668c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_EWS88MT_NEW:
4678c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_PHASE88:
4688c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_TS88:
4698c2ecf20Sopenharmony_ci
4708c2ecf20Sopenharmony_ci		err = snd_i2c_device_create(ice->i2c, "CS8404",
4718c2ecf20Sopenharmony_ci					    ICE1712_EWS88MT_CS8404_ADDR,
4728c2ecf20Sopenharmony_ci					    &spec->i2cdevs[EWS_I2C_CS8404]);
4738c2ecf20Sopenharmony_ci		if (err < 0)
4748c2ecf20Sopenharmony_ci			return err;
4758c2ecf20Sopenharmony_ci		err = snd_i2c_device_create(ice->i2c, "PCF8574 (1st)",
4768c2ecf20Sopenharmony_ci					    ICE1712_EWS88MT_INPUT_ADDR,
4778c2ecf20Sopenharmony_ci					    &spec->i2cdevs[EWS_I2C_PCF1]);
4788c2ecf20Sopenharmony_ci		if (err < 0)
4798c2ecf20Sopenharmony_ci			return err;
4808c2ecf20Sopenharmony_ci		err = snd_i2c_device_create(ice->i2c, "PCF8574 (2nd)",
4818c2ecf20Sopenharmony_ci					    ICE1712_EWS88MT_OUTPUT_ADDR,
4828c2ecf20Sopenharmony_ci					    &spec->i2cdevs[EWS_I2C_PCF2]);
4838c2ecf20Sopenharmony_ci		if (err < 0)
4848c2ecf20Sopenharmony_ci			return err;
4858c2ecf20Sopenharmony_ci		/* Check if the front module is connected */
4868c2ecf20Sopenharmony_ci		if ((err = snd_ice1712_ews88mt_chip_select(ice, 0x0f)) < 0)
4878c2ecf20Sopenharmony_ci			return err;
4888c2ecf20Sopenharmony_ci		break;
4898c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_EWS88D:
4908c2ecf20Sopenharmony_ci		err = snd_i2c_device_create(ice->i2c, "PCF8575",
4918c2ecf20Sopenharmony_ci					    ICE1712_EWS88D_PCF_ADDR,
4928c2ecf20Sopenharmony_ci					    &spec->i2cdevs[EWS_I2C_88D]);
4938c2ecf20Sopenharmony_ci		if (err < 0)
4948c2ecf20Sopenharmony_ci			return err;
4958c2ecf20Sopenharmony_ci		break;
4968c2ecf20Sopenharmony_ci	}
4978c2ecf20Sopenharmony_ci
4988c2ecf20Sopenharmony_ci	/* set up SPDIF interface */
4998c2ecf20Sopenharmony_ci	switch (ice->eeprom.subvendor) {
5008c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_EWX2496:
5018c2ecf20Sopenharmony_ci		if ((err = snd_ice1712_init_cs8427(ice, CS8427_BASE_ADDR)) < 0)
5028c2ecf20Sopenharmony_ci			return err;
5038c2ecf20Sopenharmony_ci		snd_cs8427_reg_write(ice->cs8427, CS8427_REG_RECVERRMASK, CS8427_UNLOCK | CS8427_CONF | CS8427_BIP | CS8427_PAR);
5048c2ecf20Sopenharmony_ci		break;
5058c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_DMX6FIRE:
5068c2ecf20Sopenharmony_ci		if ((err = snd_ice1712_init_cs8427(ice, ICE1712_6FIRE_CS8427_ADDR)) < 0)
5078c2ecf20Sopenharmony_ci			return err;
5088c2ecf20Sopenharmony_ci		snd_cs8427_reg_write(ice->cs8427, CS8427_REG_RECVERRMASK, CS8427_UNLOCK | CS8427_CONF | CS8427_BIP | CS8427_PAR);
5098c2ecf20Sopenharmony_ci		break;
5108c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_EWS88MT:
5118c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_EWS88MT_NEW:
5128c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_PHASE88:
5138c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_TS88:
5148c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_EWS88D:
5158c2ecf20Sopenharmony_ci		/* set up CS8404 */
5168c2ecf20Sopenharmony_ci		ice->spdif.ops.open = ews88_open_spdif;
5178c2ecf20Sopenharmony_ci		ice->spdif.ops.setup_rate = ews88_setup_spdif;
5188c2ecf20Sopenharmony_ci		ice->spdif.ops.default_get = ews88_spdif_default_get;
5198c2ecf20Sopenharmony_ci		ice->spdif.ops.default_put = ews88_spdif_default_put;
5208c2ecf20Sopenharmony_ci		ice->spdif.ops.stream_get = ews88_spdif_stream_get;
5218c2ecf20Sopenharmony_ci		ice->spdif.ops.stream_put = ews88_spdif_stream_put;
5228c2ecf20Sopenharmony_ci		/* Set spdif defaults */
5238c2ecf20Sopenharmony_ci		snd_ice1712_ews_cs8404_spdif_write(ice, ice->spdif.cs8403_bits);
5248c2ecf20Sopenharmony_ci		break;
5258c2ecf20Sopenharmony_ci	}
5268c2ecf20Sopenharmony_ci
5278c2ecf20Sopenharmony_ci	/* no analog? */
5288c2ecf20Sopenharmony_ci	switch (ice->eeprom.subvendor) {
5298c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_EWS88D:
5308c2ecf20Sopenharmony_ci		return 0;
5318c2ecf20Sopenharmony_ci	}
5328c2ecf20Sopenharmony_ci
5338c2ecf20Sopenharmony_ci	/* analog section */
5348c2ecf20Sopenharmony_ci	ak = ice->akm = kzalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL);
5358c2ecf20Sopenharmony_ci	if (! ak)
5368c2ecf20Sopenharmony_ci		return -ENOMEM;
5378c2ecf20Sopenharmony_ci	ice->akm_codecs = 1;
5388c2ecf20Sopenharmony_ci
5398c2ecf20Sopenharmony_ci	switch (ice->eeprom.subvendor) {
5408c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_EWS88MT:
5418c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_EWS88MT_NEW:
5428c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_PHASE88:
5438c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_TS88:
5448c2ecf20Sopenharmony_ci		err = snd_ice1712_akm4xxx_init(ak, &akm_ews88mt, &akm_ews88mt_priv, ice);
5458c2ecf20Sopenharmony_ci		break;
5468c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_EWX2496:
5478c2ecf20Sopenharmony_ci		err = snd_ice1712_akm4xxx_init(ak, &akm_ewx2496, &akm_ewx2496_priv, ice);
5488c2ecf20Sopenharmony_ci		break;
5498c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_DMX6FIRE:
5508c2ecf20Sopenharmony_ci		err = snd_ice1712_akm4xxx_init(ak, &akm_6fire, &akm_6fire_priv, ice);
5518c2ecf20Sopenharmony_ci		break;
5528c2ecf20Sopenharmony_ci	default:
5538c2ecf20Sopenharmony_ci		err = 0;
5548c2ecf20Sopenharmony_ci	}
5558c2ecf20Sopenharmony_ci
5568c2ecf20Sopenharmony_ci	return err;
5578c2ecf20Sopenharmony_ci}
5588c2ecf20Sopenharmony_ci
5598c2ecf20Sopenharmony_ci/*
5608c2ecf20Sopenharmony_ci * EWX 24/96 specific controls
5618c2ecf20Sopenharmony_ci */
5628c2ecf20Sopenharmony_ci
5638c2ecf20Sopenharmony_ci/* i/o sensitivity - this callback is shared among other devices, too */
5648c2ecf20Sopenharmony_cistatic int snd_ice1712_ewx_io_sense_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo){
5658c2ecf20Sopenharmony_ci
5668c2ecf20Sopenharmony_ci	static const char * const texts[2] = {
5678c2ecf20Sopenharmony_ci		"+4dBu", "-10dBV",
5688c2ecf20Sopenharmony_ci	};
5698c2ecf20Sopenharmony_ci	return snd_ctl_enum_info(uinfo, 1, 2, texts);
5708c2ecf20Sopenharmony_ci}
5718c2ecf20Sopenharmony_ci
5728c2ecf20Sopenharmony_cistatic int snd_ice1712_ewx_io_sense_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
5738c2ecf20Sopenharmony_ci{
5748c2ecf20Sopenharmony_ci	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
5758c2ecf20Sopenharmony_ci	unsigned char mask = kcontrol->private_value & 0xff;
5768c2ecf20Sopenharmony_ci
5778c2ecf20Sopenharmony_ci	snd_ice1712_save_gpio_status(ice);
5788c2ecf20Sopenharmony_ci	ucontrol->value.enumerated.item[0] = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & mask ? 1 : 0;
5798c2ecf20Sopenharmony_ci	snd_ice1712_restore_gpio_status(ice);
5808c2ecf20Sopenharmony_ci	return 0;
5818c2ecf20Sopenharmony_ci}
5828c2ecf20Sopenharmony_ci
5838c2ecf20Sopenharmony_cistatic int snd_ice1712_ewx_io_sense_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
5848c2ecf20Sopenharmony_ci{
5858c2ecf20Sopenharmony_ci	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
5868c2ecf20Sopenharmony_ci	unsigned char mask = kcontrol->private_value & 0xff;
5878c2ecf20Sopenharmony_ci	int val, nval;
5888c2ecf20Sopenharmony_ci
5898c2ecf20Sopenharmony_ci	if (kcontrol->private_value & (1 << 31))
5908c2ecf20Sopenharmony_ci		return -EPERM;
5918c2ecf20Sopenharmony_ci	nval = ucontrol->value.enumerated.item[0] ? mask : 0;
5928c2ecf20Sopenharmony_ci	snd_ice1712_save_gpio_status(ice);
5938c2ecf20Sopenharmony_ci	val = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
5948c2ecf20Sopenharmony_ci	nval |= val & ~mask;
5958c2ecf20Sopenharmony_ci	snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, nval);
5968c2ecf20Sopenharmony_ci	snd_ice1712_restore_gpio_status(ice);
5978c2ecf20Sopenharmony_ci	return val != nval;
5988c2ecf20Sopenharmony_ci}
5998c2ecf20Sopenharmony_ci
6008c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new snd_ice1712_ewx2496_controls[] = {
6018c2ecf20Sopenharmony_ci	{
6028c2ecf20Sopenharmony_ci		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6038c2ecf20Sopenharmony_ci		.name = "Input Sensitivity Switch",
6048c2ecf20Sopenharmony_ci		.info = snd_ice1712_ewx_io_sense_info,
6058c2ecf20Sopenharmony_ci		.get = snd_ice1712_ewx_io_sense_get,
6068c2ecf20Sopenharmony_ci		.put = snd_ice1712_ewx_io_sense_put,
6078c2ecf20Sopenharmony_ci		.private_value = ICE1712_EWX2496_AIN_SEL,
6088c2ecf20Sopenharmony_ci	},
6098c2ecf20Sopenharmony_ci	{
6108c2ecf20Sopenharmony_ci		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6118c2ecf20Sopenharmony_ci		.name = "Output Sensitivity Switch",
6128c2ecf20Sopenharmony_ci		.info = snd_ice1712_ewx_io_sense_info,
6138c2ecf20Sopenharmony_ci		.get = snd_ice1712_ewx_io_sense_get,
6148c2ecf20Sopenharmony_ci		.put = snd_ice1712_ewx_io_sense_put,
6158c2ecf20Sopenharmony_ci		.private_value = ICE1712_EWX2496_AOUT_SEL,
6168c2ecf20Sopenharmony_ci	},
6178c2ecf20Sopenharmony_ci};
6188c2ecf20Sopenharmony_ci
6198c2ecf20Sopenharmony_ci
6208c2ecf20Sopenharmony_ci/*
6218c2ecf20Sopenharmony_ci * EWS88MT specific controls
6228c2ecf20Sopenharmony_ci */
6238c2ecf20Sopenharmony_ci/* analog output sensitivity;; address 0x48 bit 6 */
6248c2ecf20Sopenharmony_cistatic int snd_ice1712_ews88mt_output_sense_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
6258c2ecf20Sopenharmony_ci{
6268c2ecf20Sopenharmony_ci	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
6278c2ecf20Sopenharmony_ci	struct ews_spec *spec = ice->spec;
6288c2ecf20Sopenharmony_ci	unsigned char data;
6298c2ecf20Sopenharmony_ci
6308c2ecf20Sopenharmony_ci	snd_i2c_lock(ice->i2c);
6318c2ecf20Sopenharmony_ci	if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_PCF2], &data, 1) != 1) {
6328c2ecf20Sopenharmony_ci		snd_i2c_unlock(ice->i2c);
6338c2ecf20Sopenharmony_ci		return -EIO;
6348c2ecf20Sopenharmony_ci	}
6358c2ecf20Sopenharmony_ci	snd_i2c_unlock(ice->i2c);
6368c2ecf20Sopenharmony_ci	ucontrol->value.enumerated.item[0] = data & ICE1712_EWS88MT_OUTPUT_SENSE ? 1 : 0; /* high = -10dBV, low = +4dBu */
6378c2ecf20Sopenharmony_ci	return 0;
6388c2ecf20Sopenharmony_ci}
6398c2ecf20Sopenharmony_ci
6408c2ecf20Sopenharmony_ci/* analog output sensitivity;; address 0x48 bit 6 */
6418c2ecf20Sopenharmony_cistatic int snd_ice1712_ews88mt_output_sense_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
6428c2ecf20Sopenharmony_ci{
6438c2ecf20Sopenharmony_ci	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
6448c2ecf20Sopenharmony_ci	struct ews_spec *spec = ice->spec;
6458c2ecf20Sopenharmony_ci	unsigned char data, ndata;
6468c2ecf20Sopenharmony_ci
6478c2ecf20Sopenharmony_ci	snd_i2c_lock(ice->i2c);
6488c2ecf20Sopenharmony_ci	if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_PCF2], &data, 1) != 1) {
6498c2ecf20Sopenharmony_ci		snd_i2c_unlock(ice->i2c);
6508c2ecf20Sopenharmony_ci		return -EIO;
6518c2ecf20Sopenharmony_ci	}
6528c2ecf20Sopenharmony_ci	ndata = (data & ~ICE1712_EWS88MT_OUTPUT_SENSE) | (ucontrol->value.enumerated.item[0] ? ICE1712_EWS88MT_OUTPUT_SENSE : 0);
6538c2ecf20Sopenharmony_ci	if (ndata != data && snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_PCF2],
6548c2ecf20Sopenharmony_ci					       &ndata, 1) != 1) {
6558c2ecf20Sopenharmony_ci		snd_i2c_unlock(ice->i2c);
6568c2ecf20Sopenharmony_ci		return -EIO;
6578c2ecf20Sopenharmony_ci	}
6588c2ecf20Sopenharmony_ci	snd_i2c_unlock(ice->i2c);
6598c2ecf20Sopenharmony_ci	return ndata != data;
6608c2ecf20Sopenharmony_ci}
6618c2ecf20Sopenharmony_ci
6628c2ecf20Sopenharmony_ci/* analog input sensitivity; address 0x46 */
6638c2ecf20Sopenharmony_cistatic int snd_ice1712_ews88mt_input_sense_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
6648c2ecf20Sopenharmony_ci{
6658c2ecf20Sopenharmony_ci	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
6668c2ecf20Sopenharmony_ci	struct ews_spec *spec = ice->spec;
6678c2ecf20Sopenharmony_ci	int channel = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
6688c2ecf20Sopenharmony_ci	unsigned char data;
6698c2ecf20Sopenharmony_ci
6708c2ecf20Sopenharmony_ci	if (snd_BUG_ON(channel < 0 || channel > 7))
6718c2ecf20Sopenharmony_ci		return 0;
6728c2ecf20Sopenharmony_ci	snd_i2c_lock(ice->i2c);
6738c2ecf20Sopenharmony_ci	if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_PCF1], &data, 1) != 1) {
6748c2ecf20Sopenharmony_ci		snd_i2c_unlock(ice->i2c);
6758c2ecf20Sopenharmony_ci		return -EIO;
6768c2ecf20Sopenharmony_ci	}
6778c2ecf20Sopenharmony_ci	/* reversed; high = +4dBu, low = -10dBV */
6788c2ecf20Sopenharmony_ci	ucontrol->value.enumerated.item[0] = data & (1 << channel) ? 0 : 1;
6798c2ecf20Sopenharmony_ci	snd_i2c_unlock(ice->i2c);
6808c2ecf20Sopenharmony_ci	return 0;
6818c2ecf20Sopenharmony_ci}
6828c2ecf20Sopenharmony_ci
6838c2ecf20Sopenharmony_ci/* analog output sensitivity; address 0x46 */
6848c2ecf20Sopenharmony_cistatic int snd_ice1712_ews88mt_input_sense_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
6858c2ecf20Sopenharmony_ci{
6868c2ecf20Sopenharmony_ci	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
6878c2ecf20Sopenharmony_ci	struct ews_spec *spec = ice->spec;
6888c2ecf20Sopenharmony_ci	int channel = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
6898c2ecf20Sopenharmony_ci	unsigned char data, ndata;
6908c2ecf20Sopenharmony_ci
6918c2ecf20Sopenharmony_ci	if (snd_BUG_ON(channel < 0 || channel > 7))
6928c2ecf20Sopenharmony_ci		return 0;
6938c2ecf20Sopenharmony_ci	snd_i2c_lock(ice->i2c);
6948c2ecf20Sopenharmony_ci	if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_PCF1], &data, 1) != 1) {
6958c2ecf20Sopenharmony_ci		snd_i2c_unlock(ice->i2c);
6968c2ecf20Sopenharmony_ci		return -EIO;
6978c2ecf20Sopenharmony_ci	}
6988c2ecf20Sopenharmony_ci	ndata = (data & ~(1 << channel)) | (ucontrol->value.enumerated.item[0] ? 0 : (1 << channel));
6998c2ecf20Sopenharmony_ci	if (ndata != data && snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_PCF1],
7008c2ecf20Sopenharmony_ci					       &ndata, 1) != 1) {
7018c2ecf20Sopenharmony_ci		snd_i2c_unlock(ice->i2c);
7028c2ecf20Sopenharmony_ci		return -EIO;
7038c2ecf20Sopenharmony_ci	}
7048c2ecf20Sopenharmony_ci	snd_i2c_unlock(ice->i2c);
7058c2ecf20Sopenharmony_ci	return ndata != data;
7068c2ecf20Sopenharmony_ci}
7078c2ecf20Sopenharmony_ci
7088c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new snd_ice1712_ews88mt_input_sense = {
7098c2ecf20Sopenharmony_ci	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7108c2ecf20Sopenharmony_ci	.name = "Input Sensitivity Switch",
7118c2ecf20Sopenharmony_ci	.info = snd_ice1712_ewx_io_sense_info,
7128c2ecf20Sopenharmony_ci	.get = snd_ice1712_ews88mt_input_sense_get,
7138c2ecf20Sopenharmony_ci	.put = snd_ice1712_ews88mt_input_sense_put,
7148c2ecf20Sopenharmony_ci	.count = 8,
7158c2ecf20Sopenharmony_ci};
7168c2ecf20Sopenharmony_ci
7178c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new snd_ice1712_ews88mt_output_sense = {
7188c2ecf20Sopenharmony_ci	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7198c2ecf20Sopenharmony_ci	.name = "Output Sensitivity Switch",
7208c2ecf20Sopenharmony_ci	.info = snd_ice1712_ewx_io_sense_info,
7218c2ecf20Sopenharmony_ci	.get = snd_ice1712_ews88mt_output_sense_get,
7228c2ecf20Sopenharmony_ci	.put = snd_ice1712_ews88mt_output_sense_put,
7238c2ecf20Sopenharmony_ci};
7248c2ecf20Sopenharmony_ci
7258c2ecf20Sopenharmony_ci
7268c2ecf20Sopenharmony_ci/*
7278c2ecf20Sopenharmony_ci * EWS88D specific controls
7288c2ecf20Sopenharmony_ci */
7298c2ecf20Sopenharmony_ci
7308c2ecf20Sopenharmony_ci#define snd_ice1712_ews88d_control_info		snd_ctl_boolean_mono_info
7318c2ecf20Sopenharmony_ci
7328c2ecf20Sopenharmony_cistatic int snd_ice1712_ews88d_control_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
7338c2ecf20Sopenharmony_ci{
7348c2ecf20Sopenharmony_ci	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
7358c2ecf20Sopenharmony_ci	struct ews_spec *spec = ice->spec;
7368c2ecf20Sopenharmony_ci	int shift = kcontrol->private_value & 0xff;
7378c2ecf20Sopenharmony_ci	int invert = (kcontrol->private_value >> 8) & 1;
7388c2ecf20Sopenharmony_ci	unsigned char data[2];
7398c2ecf20Sopenharmony_ci
7408c2ecf20Sopenharmony_ci	snd_i2c_lock(ice->i2c);
7418c2ecf20Sopenharmony_ci	if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_88D], data, 2) != 2) {
7428c2ecf20Sopenharmony_ci		snd_i2c_unlock(ice->i2c);
7438c2ecf20Sopenharmony_ci		return -EIO;
7448c2ecf20Sopenharmony_ci	}
7458c2ecf20Sopenharmony_ci	snd_i2c_unlock(ice->i2c);
7468c2ecf20Sopenharmony_ci	data[0] = (data[shift >> 3] >> (shift & 7)) & 0x01;
7478c2ecf20Sopenharmony_ci	if (invert)
7488c2ecf20Sopenharmony_ci		data[0] ^= 0x01;
7498c2ecf20Sopenharmony_ci	ucontrol->value.integer.value[0] = data[0];
7508c2ecf20Sopenharmony_ci	return 0;
7518c2ecf20Sopenharmony_ci}
7528c2ecf20Sopenharmony_ci
7538c2ecf20Sopenharmony_cistatic int snd_ice1712_ews88d_control_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
7548c2ecf20Sopenharmony_ci{
7558c2ecf20Sopenharmony_ci	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
7568c2ecf20Sopenharmony_ci	struct ews_spec *spec = ice->spec;
7578c2ecf20Sopenharmony_ci	int shift = kcontrol->private_value & 0xff;
7588c2ecf20Sopenharmony_ci	int invert = (kcontrol->private_value >> 8) & 1;
7598c2ecf20Sopenharmony_ci	unsigned char data[2], ndata[2];
7608c2ecf20Sopenharmony_ci	int change;
7618c2ecf20Sopenharmony_ci
7628c2ecf20Sopenharmony_ci	snd_i2c_lock(ice->i2c);
7638c2ecf20Sopenharmony_ci	if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_88D], data, 2) != 2) {
7648c2ecf20Sopenharmony_ci		snd_i2c_unlock(ice->i2c);
7658c2ecf20Sopenharmony_ci		return -EIO;
7668c2ecf20Sopenharmony_ci	}
7678c2ecf20Sopenharmony_ci	ndata[shift >> 3] = data[shift >> 3] & ~(1 << (shift & 7));
7688c2ecf20Sopenharmony_ci	if (invert) {
7698c2ecf20Sopenharmony_ci		if (! ucontrol->value.integer.value[0])
7708c2ecf20Sopenharmony_ci			ndata[shift >> 3] |= (1 << (shift & 7));
7718c2ecf20Sopenharmony_ci	} else {
7728c2ecf20Sopenharmony_ci		if (ucontrol->value.integer.value[0])
7738c2ecf20Sopenharmony_ci			ndata[shift >> 3] |= (1 << (shift & 7));
7748c2ecf20Sopenharmony_ci	}
7758c2ecf20Sopenharmony_ci	change = (data[shift >> 3] != ndata[shift >> 3]);
7768c2ecf20Sopenharmony_ci	if (change &&
7778c2ecf20Sopenharmony_ci	    snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_88D], data, 2) != 2) {
7788c2ecf20Sopenharmony_ci		snd_i2c_unlock(ice->i2c);
7798c2ecf20Sopenharmony_ci		return -EIO;
7808c2ecf20Sopenharmony_ci	}
7818c2ecf20Sopenharmony_ci	snd_i2c_unlock(ice->i2c);
7828c2ecf20Sopenharmony_ci	return change;
7838c2ecf20Sopenharmony_ci}
7848c2ecf20Sopenharmony_ci
7858c2ecf20Sopenharmony_ci#define EWS88D_CONTROL(xiface, xname, xshift, xinvert, xaccess) \
7868c2ecf20Sopenharmony_ci{ .iface = xiface,\
7878c2ecf20Sopenharmony_ci  .name = xname,\
7888c2ecf20Sopenharmony_ci  .access = xaccess,\
7898c2ecf20Sopenharmony_ci  .info = snd_ice1712_ews88d_control_info,\
7908c2ecf20Sopenharmony_ci  .get = snd_ice1712_ews88d_control_get,\
7918c2ecf20Sopenharmony_ci  .put = snd_ice1712_ews88d_control_put,\
7928c2ecf20Sopenharmony_ci  .private_value = xshift | (xinvert << 8),\
7938c2ecf20Sopenharmony_ci}
7948c2ecf20Sopenharmony_ci
7958c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new snd_ice1712_ews88d_controls[] = {
7968c2ecf20Sopenharmony_ci	EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "IEC958 Input Optical", 0, 1, 0), /* inverted */
7978c2ecf20Sopenharmony_ci	EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "ADAT Output Optical", 1, 0, 0),
7988c2ecf20Sopenharmony_ci	EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "ADAT External Master Clock", 2, 0, 0),
7998c2ecf20Sopenharmony_ci	EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "Enable ADAT", 3, 0, 0),
8008c2ecf20Sopenharmony_ci	EWS88D_CONTROL(SNDRV_CTL_ELEM_IFACE_MIXER, "ADAT Through", 4, 1, 0),
8018c2ecf20Sopenharmony_ci};
8028c2ecf20Sopenharmony_ci
8038c2ecf20Sopenharmony_ci
8048c2ecf20Sopenharmony_ci/*
8058c2ecf20Sopenharmony_ci * DMX 6Fire specific controls
8068c2ecf20Sopenharmony_ci */
8078c2ecf20Sopenharmony_ci
8088c2ecf20Sopenharmony_cistatic int snd_ice1712_6fire_read_pca(struct snd_ice1712 *ice, unsigned char reg)
8098c2ecf20Sopenharmony_ci{
8108c2ecf20Sopenharmony_ci	unsigned char byte;
8118c2ecf20Sopenharmony_ci	struct ews_spec *spec = ice->spec;
8128c2ecf20Sopenharmony_ci
8138c2ecf20Sopenharmony_ci	snd_i2c_lock(ice->i2c);
8148c2ecf20Sopenharmony_ci	byte = reg;
8158c2ecf20Sopenharmony_ci	if (snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_6FIRE], &byte, 1) != 1) {
8168c2ecf20Sopenharmony_ci		snd_i2c_unlock(ice->i2c);
8178c2ecf20Sopenharmony_ci		dev_err(ice->card->dev, "cannot send pca\n");
8188c2ecf20Sopenharmony_ci		return -EIO;
8198c2ecf20Sopenharmony_ci	}
8208c2ecf20Sopenharmony_ci
8218c2ecf20Sopenharmony_ci	byte = 0;
8228c2ecf20Sopenharmony_ci	if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_6FIRE], &byte, 1) != 1) {
8238c2ecf20Sopenharmony_ci		snd_i2c_unlock(ice->i2c);
8248c2ecf20Sopenharmony_ci		dev_err(ice->card->dev, "cannot read pca\n");
8258c2ecf20Sopenharmony_ci		return -EIO;
8268c2ecf20Sopenharmony_ci	}
8278c2ecf20Sopenharmony_ci	snd_i2c_unlock(ice->i2c);
8288c2ecf20Sopenharmony_ci	return byte;
8298c2ecf20Sopenharmony_ci}
8308c2ecf20Sopenharmony_ci
8318c2ecf20Sopenharmony_cistatic int snd_ice1712_6fire_write_pca(struct snd_ice1712 *ice, unsigned char reg, unsigned char data)
8328c2ecf20Sopenharmony_ci{
8338c2ecf20Sopenharmony_ci	unsigned char bytes[2];
8348c2ecf20Sopenharmony_ci	struct ews_spec *spec = ice->spec;
8358c2ecf20Sopenharmony_ci
8368c2ecf20Sopenharmony_ci	snd_i2c_lock(ice->i2c);
8378c2ecf20Sopenharmony_ci	bytes[0] = reg;
8388c2ecf20Sopenharmony_ci	bytes[1] = data;
8398c2ecf20Sopenharmony_ci	if (snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_6FIRE], bytes, 2) != 2) {
8408c2ecf20Sopenharmony_ci		snd_i2c_unlock(ice->i2c);
8418c2ecf20Sopenharmony_ci		return -EIO;
8428c2ecf20Sopenharmony_ci	}
8438c2ecf20Sopenharmony_ci	snd_i2c_unlock(ice->i2c);
8448c2ecf20Sopenharmony_ci	return 0;
8458c2ecf20Sopenharmony_ci}
8468c2ecf20Sopenharmony_ci
8478c2ecf20Sopenharmony_ci#define snd_ice1712_6fire_control_info		snd_ctl_boolean_mono_info
8488c2ecf20Sopenharmony_ci
8498c2ecf20Sopenharmony_cistatic int snd_ice1712_6fire_control_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
8508c2ecf20Sopenharmony_ci{
8518c2ecf20Sopenharmony_ci	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
8528c2ecf20Sopenharmony_ci	int shift = kcontrol->private_value & 0xff;
8538c2ecf20Sopenharmony_ci	int invert = (kcontrol->private_value >> 8) & 1;
8548c2ecf20Sopenharmony_ci	int data;
8558c2ecf20Sopenharmony_ci
8568c2ecf20Sopenharmony_ci	if ((data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT)) < 0)
8578c2ecf20Sopenharmony_ci		return data;
8588c2ecf20Sopenharmony_ci	data = (data >> shift) & 1;
8598c2ecf20Sopenharmony_ci	if (invert)
8608c2ecf20Sopenharmony_ci		data ^= 1;
8618c2ecf20Sopenharmony_ci	ucontrol->value.integer.value[0] = data;
8628c2ecf20Sopenharmony_ci	return 0;
8638c2ecf20Sopenharmony_ci}
8648c2ecf20Sopenharmony_ci
8658c2ecf20Sopenharmony_cistatic int snd_ice1712_6fire_control_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
8668c2ecf20Sopenharmony_ci{
8678c2ecf20Sopenharmony_ci	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
8688c2ecf20Sopenharmony_ci	int shift = kcontrol->private_value & 0xff;
8698c2ecf20Sopenharmony_ci	int invert = (kcontrol->private_value >> 8) & 1;
8708c2ecf20Sopenharmony_ci	int data, ndata;
8718c2ecf20Sopenharmony_ci
8728c2ecf20Sopenharmony_ci	if ((data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT)) < 0)
8738c2ecf20Sopenharmony_ci		return data;
8748c2ecf20Sopenharmony_ci	ndata = data & ~(1 << shift);
8758c2ecf20Sopenharmony_ci	if (ucontrol->value.integer.value[0])
8768c2ecf20Sopenharmony_ci		ndata |= (1 << shift);
8778c2ecf20Sopenharmony_ci	if (invert)
8788c2ecf20Sopenharmony_ci		ndata ^= (1 << shift);
8798c2ecf20Sopenharmony_ci	if (data != ndata) {
8808c2ecf20Sopenharmony_ci		snd_ice1712_6fire_write_pca(ice, PCF9554_REG_OUTPUT, (unsigned char)ndata);
8818c2ecf20Sopenharmony_ci		return 1;
8828c2ecf20Sopenharmony_ci	}
8838c2ecf20Sopenharmony_ci	return 0;
8848c2ecf20Sopenharmony_ci}
8858c2ecf20Sopenharmony_ci
8868c2ecf20Sopenharmony_cistatic int snd_ice1712_6fire_select_input_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
8878c2ecf20Sopenharmony_ci{
8888c2ecf20Sopenharmony_ci	static const char * const texts[4] = {
8898c2ecf20Sopenharmony_ci		"Internal", "Front Input", "Rear Input", "Wave Table"
8908c2ecf20Sopenharmony_ci	};
8918c2ecf20Sopenharmony_ci	return snd_ctl_enum_info(uinfo, 1, 4, texts);
8928c2ecf20Sopenharmony_ci}
8938c2ecf20Sopenharmony_ci
8948c2ecf20Sopenharmony_cistatic int snd_ice1712_6fire_select_input_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
8958c2ecf20Sopenharmony_ci{
8968c2ecf20Sopenharmony_ci	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
8978c2ecf20Sopenharmony_ci	int data;
8988c2ecf20Sopenharmony_ci
8998c2ecf20Sopenharmony_ci	if ((data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT)) < 0)
9008c2ecf20Sopenharmony_ci		return data;
9018c2ecf20Sopenharmony_ci	ucontrol->value.integer.value[0] = data & 3;
9028c2ecf20Sopenharmony_ci	return 0;
9038c2ecf20Sopenharmony_ci}
9048c2ecf20Sopenharmony_ci
9058c2ecf20Sopenharmony_cistatic int snd_ice1712_6fire_select_input_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
9068c2ecf20Sopenharmony_ci{
9078c2ecf20Sopenharmony_ci	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
9088c2ecf20Sopenharmony_ci	int data, ndata;
9098c2ecf20Sopenharmony_ci
9108c2ecf20Sopenharmony_ci	if ((data = snd_ice1712_6fire_read_pca(ice, PCF9554_REG_OUTPUT)) < 0)
9118c2ecf20Sopenharmony_ci		return data;
9128c2ecf20Sopenharmony_ci	ndata = data & ~3;
9138c2ecf20Sopenharmony_ci	ndata |= (ucontrol->value.integer.value[0] & 3);
9148c2ecf20Sopenharmony_ci	if (data != ndata) {
9158c2ecf20Sopenharmony_ci		snd_ice1712_6fire_write_pca(ice, PCF9554_REG_OUTPUT, (unsigned char)ndata);
9168c2ecf20Sopenharmony_ci		return 1;
9178c2ecf20Sopenharmony_ci	}
9188c2ecf20Sopenharmony_ci	return 0;
9198c2ecf20Sopenharmony_ci}
9208c2ecf20Sopenharmony_ci
9218c2ecf20Sopenharmony_ci
9228c2ecf20Sopenharmony_ci#define DMX6FIRE_CONTROL(xname, xshift, xinvert) \
9238c2ecf20Sopenharmony_ci{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,\
9248c2ecf20Sopenharmony_ci  .name = xname,\
9258c2ecf20Sopenharmony_ci  .info = snd_ice1712_6fire_control_info,\
9268c2ecf20Sopenharmony_ci  .get = snd_ice1712_6fire_control_get,\
9278c2ecf20Sopenharmony_ci  .put = snd_ice1712_6fire_control_put,\
9288c2ecf20Sopenharmony_ci  .private_value = xshift | (xinvert << 8),\
9298c2ecf20Sopenharmony_ci}
9308c2ecf20Sopenharmony_ci
9318c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new snd_ice1712_6fire_controls[] = {
9328c2ecf20Sopenharmony_ci	{
9338c2ecf20Sopenharmony_ci		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9348c2ecf20Sopenharmony_ci		.name = "Analog Input Select",
9358c2ecf20Sopenharmony_ci		.info = snd_ice1712_6fire_select_input_info,
9368c2ecf20Sopenharmony_ci		.get = snd_ice1712_6fire_select_input_get,
9378c2ecf20Sopenharmony_ci		.put = snd_ice1712_6fire_select_input_put,
9388c2ecf20Sopenharmony_ci	},
9398c2ecf20Sopenharmony_ci	DMX6FIRE_CONTROL("Front Digital Input Switch", 2, 1),
9408c2ecf20Sopenharmony_ci	// DMX6FIRE_CONTROL("Master Clock Select", 3, 0),
9418c2ecf20Sopenharmony_ci	DMX6FIRE_CONTROL("Optical Digital Input Switch", 4, 0),
9428c2ecf20Sopenharmony_ci	DMX6FIRE_CONTROL("Phono Analog Input Switch", 5, 0),
9438c2ecf20Sopenharmony_ci	DMX6FIRE_CONTROL("Breakbox LED", 6, 0),
9448c2ecf20Sopenharmony_ci};
9458c2ecf20Sopenharmony_ci
9468c2ecf20Sopenharmony_ci
9478c2ecf20Sopenharmony_cistatic int snd_ice1712_ews_add_controls(struct snd_ice1712 *ice)
9488c2ecf20Sopenharmony_ci{
9498c2ecf20Sopenharmony_ci	unsigned int idx;
9508c2ecf20Sopenharmony_ci	int err;
9518c2ecf20Sopenharmony_ci
9528c2ecf20Sopenharmony_ci	/* all terratec cards have spdif, but cs8427 module builds it's own controls */
9538c2ecf20Sopenharmony_ci	if (ice->cs8427 == NULL) {
9548c2ecf20Sopenharmony_ci		err = snd_ice1712_spdif_build_controls(ice);
9558c2ecf20Sopenharmony_ci		if (err < 0)
9568c2ecf20Sopenharmony_ci			return err;
9578c2ecf20Sopenharmony_ci	}
9588c2ecf20Sopenharmony_ci
9598c2ecf20Sopenharmony_ci	/* ak4524 controls */
9608c2ecf20Sopenharmony_ci	switch (ice->eeprom.subvendor) {
9618c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_EWX2496:
9628c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_EWS88MT:
9638c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_EWS88MT_NEW:
9648c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_PHASE88:
9658c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_TS88:
9668c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_DMX6FIRE:
9678c2ecf20Sopenharmony_ci		err = snd_ice1712_akm4xxx_build_controls(ice);
9688c2ecf20Sopenharmony_ci		if (err < 0)
9698c2ecf20Sopenharmony_ci			return err;
9708c2ecf20Sopenharmony_ci		break;
9718c2ecf20Sopenharmony_ci	}
9728c2ecf20Sopenharmony_ci
9738c2ecf20Sopenharmony_ci	/* card specific controls */
9748c2ecf20Sopenharmony_ci	switch (ice->eeprom.subvendor) {
9758c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_EWX2496:
9768c2ecf20Sopenharmony_ci		for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_ewx2496_controls); idx++) {
9778c2ecf20Sopenharmony_ci			err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ewx2496_controls[idx], ice));
9788c2ecf20Sopenharmony_ci			if (err < 0)
9798c2ecf20Sopenharmony_ci				return err;
9808c2ecf20Sopenharmony_ci		}
9818c2ecf20Sopenharmony_ci		break;
9828c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_EWS88MT:
9838c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_EWS88MT_NEW:
9848c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_PHASE88:
9858c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_TS88:
9868c2ecf20Sopenharmony_ci		err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88mt_input_sense, ice));
9878c2ecf20Sopenharmony_ci		if (err < 0)
9888c2ecf20Sopenharmony_ci			return err;
9898c2ecf20Sopenharmony_ci		err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88mt_output_sense, ice));
9908c2ecf20Sopenharmony_ci		if (err < 0)
9918c2ecf20Sopenharmony_ci			return err;
9928c2ecf20Sopenharmony_ci		break;
9938c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_EWS88D:
9948c2ecf20Sopenharmony_ci		for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_ews88d_controls); idx++) {
9958c2ecf20Sopenharmony_ci			err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88d_controls[idx], ice));
9968c2ecf20Sopenharmony_ci			if (err < 0)
9978c2ecf20Sopenharmony_ci				return err;
9988c2ecf20Sopenharmony_ci		}
9998c2ecf20Sopenharmony_ci		break;
10008c2ecf20Sopenharmony_ci	case ICE1712_SUBDEVICE_DMX6FIRE:
10018c2ecf20Sopenharmony_ci		for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_6fire_controls); idx++) {
10028c2ecf20Sopenharmony_ci			err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_6fire_controls[idx], ice));
10038c2ecf20Sopenharmony_ci			if (err < 0)
10048c2ecf20Sopenharmony_ci				return err;
10058c2ecf20Sopenharmony_ci		}
10068c2ecf20Sopenharmony_ci		break;
10078c2ecf20Sopenharmony_ci	}
10088c2ecf20Sopenharmony_ci	return 0;
10098c2ecf20Sopenharmony_ci}
10108c2ecf20Sopenharmony_ci
10118c2ecf20Sopenharmony_ci
10128c2ecf20Sopenharmony_ci/* entry point */
10138c2ecf20Sopenharmony_cistruct snd_ice1712_card_info snd_ice1712_ews_cards[] = {
10148c2ecf20Sopenharmony_ci	{
10158c2ecf20Sopenharmony_ci		.subvendor = ICE1712_SUBDEVICE_EWX2496,
10168c2ecf20Sopenharmony_ci		.name = "TerraTec EWX24/96",
10178c2ecf20Sopenharmony_ci		.model = "ewx2496",
10188c2ecf20Sopenharmony_ci		.chip_init = snd_ice1712_ews_init,
10198c2ecf20Sopenharmony_ci		.build_controls = snd_ice1712_ews_add_controls,
10208c2ecf20Sopenharmony_ci	},
10218c2ecf20Sopenharmony_ci	{
10228c2ecf20Sopenharmony_ci		.subvendor = ICE1712_SUBDEVICE_EWS88MT,
10238c2ecf20Sopenharmony_ci		.name = "TerraTec EWS88MT",
10248c2ecf20Sopenharmony_ci		.model = "ews88mt",
10258c2ecf20Sopenharmony_ci		.chip_init = snd_ice1712_ews_init,
10268c2ecf20Sopenharmony_ci		.build_controls = snd_ice1712_ews_add_controls,
10278c2ecf20Sopenharmony_ci	},
10288c2ecf20Sopenharmony_ci	{
10298c2ecf20Sopenharmony_ci		.subvendor = ICE1712_SUBDEVICE_EWS88MT_NEW,
10308c2ecf20Sopenharmony_ci		.name = "TerraTec EWS88MT",
10318c2ecf20Sopenharmony_ci		.model = "ews88mt_new",
10328c2ecf20Sopenharmony_ci		.chip_init = snd_ice1712_ews_init,
10338c2ecf20Sopenharmony_ci		.build_controls = snd_ice1712_ews_add_controls,
10348c2ecf20Sopenharmony_ci	},
10358c2ecf20Sopenharmony_ci	{
10368c2ecf20Sopenharmony_ci		.subvendor = ICE1712_SUBDEVICE_PHASE88,
10378c2ecf20Sopenharmony_ci		.name = "TerraTec Phase88",
10388c2ecf20Sopenharmony_ci		.model = "phase88",
10398c2ecf20Sopenharmony_ci		.chip_init = snd_ice1712_ews_init,
10408c2ecf20Sopenharmony_ci		.build_controls = snd_ice1712_ews_add_controls,
10418c2ecf20Sopenharmony_ci	},
10428c2ecf20Sopenharmony_ci	{
10438c2ecf20Sopenharmony_ci		.subvendor = ICE1712_SUBDEVICE_TS88,
10448c2ecf20Sopenharmony_ci		.name = "terrasoniq TS88",
10458c2ecf20Sopenharmony_ci		.model = "phase88",
10468c2ecf20Sopenharmony_ci		.chip_init = snd_ice1712_ews_init,
10478c2ecf20Sopenharmony_ci		.build_controls = snd_ice1712_ews_add_controls,
10488c2ecf20Sopenharmony_ci	},
10498c2ecf20Sopenharmony_ci	{
10508c2ecf20Sopenharmony_ci		.subvendor = ICE1712_SUBDEVICE_EWS88D,
10518c2ecf20Sopenharmony_ci		.name = "TerraTec EWS88D",
10528c2ecf20Sopenharmony_ci		.model = "ews88d",
10538c2ecf20Sopenharmony_ci		.chip_init = snd_ice1712_ews_init,
10548c2ecf20Sopenharmony_ci		.build_controls = snd_ice1712_ews_add_controls,
10558c2ecf20Sopenharmony_ci	},
10568c2ecf20Sopenharmony_ci	{
10578c2ecf20Sopenharmony_ci		.subvendor = ICE1712_SUBDEVICE_DMX6FIRE,
10588c2ecf20Sopenharmony_ci		.name = "TerraTec DMX6Fire",
10598c2ecf20Sopenharmony_ci		.model = "dmx6fire",
10608c2ecf20Sopenharmony_ci		.chip_init = snd_ice1712_ews_init,
10618c2ecf20Sopenharmony_ci		.build_controls = snd_ice1712_ews_add_controls,
10628c2ecf20Sopenharmony_ci		.mpu401_1_name = "MIDI-Front DMX6fire",
10638c2ecf20Sopenharmony_ci		.mpu401_2_name = "Wavetable DMX6fire",
10648c2ecf20Sopenharmony_ci		.mpu401_2_info_flags = MPU401_INFO_OUTPUT,
10658c2ecf20Sopenharmony_ci	},
10668c2ecf20Sopenharmony_ci	{ } /* terminator */
10678c2ecf20Sopenharmony_ci};
1068