Lines Matching full:idt821034

3 // IDT821034 ALSA SoC driver
25 struct idt821034 { struct
51 static int idt821034_8bit_write(struct idt821034 *idt821034, u8 val) in idt821034_8bit_write() argument
55 .tx_buf = &idt821034->spi_tx_buf, in idt821034_8bit_write()
59 .tx_buf = &idt821034->spi_tx_buf, in idt821034_8bit_write()
64 idt821034->spi_tx_buf = val; in idt821034_8bit_write()
66 dev_vdbg(&idt821034->spi->dev, "spi xfer wr 0x%x\n", val); in idt821034_8bit_write()
68 return spi_sync_transfer(idt821034->spi, xfer, 2); in idt821034_8bit_write()
71 static int idt821034_2x8bit_write(struct idt821034 *idt821034, u8 val1, u8 val2) in idt821034_2x8bit_write() argument
75 ret = idt821034_8bit_write(idt821034, val1); in idt821034_2x8bit_write()
78 return idt821034_8bit_write(idt821034, val2); in idt821034_2x8bit_write()
81 static int idt821034_8bit_read(struct idt821034 *idt821034, u8 valw, u8 *valr) in idt821034_8bit_read() argument
85 .tx_buf = &idt821034->spi_tx_buf, in idt821034_8bit_read()
86 .rx_buf = &idt821034->spi_rx_buf, in idt821034_8bit_read()
90 .tx_buf = &idt821034->spi_tx_buf, in idt821034_8bit_read()
96 idt821034->spi_tx_buf = valw; in idt821034_8bit_read()
98 ret = spi_sync_transfer(idt821034->spi, xfer, 2); in idt821034_8bit_read()
102 *valr = idt821034->spi_rx_buf; in idt821034_8bit_read()
104 dev_vdbg(&idt821034->spi->dev, "spi xfer wr 0x%x, rd 0x%x\n", in idt821034_8bit_read()
119 static int idt821034_set_channel_power(struct idt821034 *idt821034, u8 ch, u8 power) in idt821034_set_channel_power() argument
124 dev_dbg(&idt821034->spi->dev, "set_channel_power(%u, 0x%x)\n", ch, power); in idt821034_set_channel_power()
126 conf = IDT821034_MODE_CODEC(ch) | idt821034->cache.codec_conf; in idt821034_set_channel_power()
129 ret = idt821034_2x8bit_write(idt821034, in idt821034_set_channel_power()
131 idt821034->cache.ch[ch].rx_slot); in idt821034_set_channel_power()
136 ret = idt821034_2x8bit_write(idt821034, in idt821034_set_channel_power()
138 idt821034->cache.ch[ch].tx_slot); in idt821034_set_channel_power()
143 ret = idt821034_2x8bit_write(idt821034, conf, 0); in idt821034_set_channel_power()
148 idt821034->cache.ch[ch].power = power; in idt821034_set_channel_power()
153 static u8 idt821034_get_channel_power(struct idt821034 *idt821034, u8 ch) in idt821034_get_channel_power() argument
155 return idt821034->cache.ch[ch].power; in idt821034_get_channel_power()
162 static int idt821034_set_codec_conf(struct idt821034 *idt821034, u8 codec_conf) in idt821034_set_codec_conf() argument
168 dev_dbg(&idt821034->spi->dev, "set_codec_conf(0x%x)\n", codec_conf); in idt821034_set_codec_conf()
180 if (idt821034->cache.ch[0].power & IDT821034_CONF_PWRUP_RX) { in idt821034_set_codec_conf()
182 ts = idt821034->cache.ch[0].rx_slot; in idt821034_set_codec_conf()
183 } else if (idt821034->cache.ch[0].power & IDT821034_CONF_PWRUP_TX) { in idt821034_set_codec_conf()
185 ts = idt821034->cache.ch[0].tx_slot; in idt821034_set_codec_conf()
191 ret = idt821034_2x8bit_write(idt821034, conf, ts); in idt821034_set_codec_conf()
195 idt821034->cache.codec_conf = codec_conf; in idt821034_set_codec_conf()
199 static u8 idt821034_get_codec_conf(struct idt821034 *idt821034) in idt821034_get_codec_conf() argument
201 return idt821034->cache.codec_conf; in idt821034_get_codec_conf()
208 static int idt821034_set_channel_ts(struct idt821034 *idt821034, u8 ch, u8 ch_dir, u8 ts_num) in idt821034_set_channel_ts() argument
213 dev_dbg(&idt821034->spi->dev, "set_channel_ts(%u, 0x%x, %d)\n", ch, ch_dir, ts_num); in idt821034_set_channel_ts()
215 conf = IDT821034_MODE_CODEC(ch) | idt821034->cache.codec_conf; in idt821034_set_channel_ts()
218 if (idt821034->cache.ch[ch].power & IDT821034_CONF_PWRUP_RX) { in idt821034_set_channel_ts()
219 ret = idt821034_2x8bit_write(idt821034, in idt821034_set_channel_ts()
225 idt821034->cache.ch[ch].rx_slot = ts_num; in idt821034_set_channel_ts()
228 if (idt821034->cache.ch[ch].power & IDT821034_CONF_PWRUP_TX) { in idt821034_set_channel_ts()
229 ret = idt821034_2x8bit_write(idt821034, in idt821034_set_channel_ts()
235 idt821034->cache.ch[ch].tx_slot = ts_num; in idt821034_set_channel_ts()
245 static int idt821034_set_slic_conf(struct idt821034 *idt821034, u8 ch, u8 slic_dir) in idt821034_set_slic_conf() argument
250 dev_dbg(&idt821034->spi->dev, "set_slic_conf(%u, 0x%x)\n", ch, slic_dir); in idt821034_set_slic_conf()
253 ret = idt821034_2x8bit_write(idt821034, conf, idt821034->cache.ch[ch].slic_control); in idt821034_set_slic_conf()
257 idt821034->cache.ch[ch].slic_conf = slic_dir; in idt821034_set_slic_conf()
262 static u8 idt821034_get_slic_conf(struct idt821034 *idt821034, u8 ch) in idt821034_get_slic_conf() argument
264 return idt821034->cache.ch[ch].slic_conf; in idt821034_get_slic_conf()
267 static int idt821034_write_slic_raw(struct idt821034 *idt821034, u8 ch, u8 slic_raw) in idt821034_write_slic_raw() argument
272 dev_dbg(&idt821034->spi->dev, "write_slic_raw(%u, 0x%x)\n", ch, slic_raw); in idt821034_write_slic_raw()
283 conf = IDT821034_MODE_SLIC(ch) | idt821034->cache.ch[ch].slic_conf; in idt821034_write_slic_raw()
284 ret = idt821034_2x8bit_write(idt821034, conf, slic_raw); in idt821034_write_slic_raw()
288 idt821034->cache.ch[ch].slic_control = slic_raw; in idt821034_write_slic_raw()
292 static u8 idt821034_get_written_slic_raw(struct idt821034 *idt821034, u8 ch) in idt821034_get_written_slic_raw() argument
294 return idt821034->cache.ch[ch].slic_control; in idt821034_get_written_slic_raw()
297 static int idt821034_read_slic_raw(struct idt821034 *idt821034, u8 ch, u8 *slic_raw) in idt821034_read_slic_raw() argument
314 val = IDT821034_MODE_SLIC(ch) | idt821034->cache.ch[ch].slic_conf; in idt821034_read_slic_raw()
315 ret = idt821034_8bit_write(idt821034, val); in idt821034_read_slic_raw()
319 ret = idt821034_8bit_read(idt821034, idt821034->cache.ch[ch].slic_control, slic_raw); in idt821034_read_slic_raw()
323 dev_dbg(&idt821034->spi->dev, "read_slic_raw(%i) 0x%x\n", ch, *slic_raw); in idt821034_read_slic_raw()
332 static int idt821034_set_gain_channel(struct idt821034 *idt821034, u8 ch, in idt821034_set_gain_channel() argument
338 dev_dbg(&idt821034->spi->dev, "set_gain_channel(%u, 0x%x, 0x%x-%d)\n", in idt821034_set_gain_channel()
379 ret = idt821034_2x8bit_write(idt821034, conf | 0x00, gain_val & 0x007F); in idt821034_set_gain_channel()
383 ret = idt821034_2x8bit_write(idt821034, conf | 0x01, (gain_val >> 7) & 0x7F); in idt821034_set_gain_channel()
406 struct idt821034 *idt821034 = snd_soc_component_get_drvdata(component); in idt821034_kctrl_gain_get() local
416 mutex_lock(&idt821034->mutex); in idt821034_kctrl_gain_get()
418 val = idt821034->amps.ch[ch].amp_out.gain; in idt821034_kctrl_gain_get()
420 val = idt821034->amps.ch[ch].amp_in.gain; in idt821034_kctrl_gain_get()
421 mutex_unlock(&idt821034->mutex); in idt821034_kctrl_gain_get()
437 struct idt821034 *idt821034 = snd_soc_component_get_drvdata(component); in idt821034_kctrl_gain_put() local
459 mutex_lock(&idt821034->mutex); in idt821034_kctrl_gain_put()
462 amp = &idt821034->amps.ch[ch].amp_out; in idt821034_kctrl_gain_put()
465 amp = &idt821034->amps.ch[ch].amp_in; in idt821034_kctrl_gain_put()
475 ret = idt821034_set_gain_channel(idt821034, ch, gain_type, val); in idt821034_kctrl_gain_put()
483 mutex_unlock(&idt821034->mutex); in idt821034_kctrl_gain_put()
491 struct idt821034 *idt821034 = snd_soc_component_get_drvdata(component); in idt821034_kctrl_mute_get() local
498 mutex_lock(&idt821034->mutex); in idt821034_kctrl_mute_get()
500 idt821034->amps.ch[ch].amp_out.is_muted : in idt821034_kctrl_mute_get()
501 idt821034->amps.ch[ch].amp_in.is_muted; in idt821034_kctrl_mute_get()
502 mutex_unlock(&idt821034->mutex); in idt821034_kctrl_mute_get()
513 struct idt821034 *idt821034 = snd_soc_component_get_drvdata(component); in idt821034_kctrl_mute_put() local
524 mutex_lock(&idt821034->mutex); in idt821034_kctrl_mute_put()
527 amp = &idt821034->amps.ch[ch].amp_out; in idt821034_kctrl_mute_put()
530 amp = &idt821034->amps.ch[ch].amp_in; in idt821034_kctrl_mute_put()
539 ret = idt821034_set_gain_channel(idt821034, ch, gain_type, in idt821034_kctrl_mute_put()
547 mutex_unlock(&idt821034->mutex); in idt821034_kctrl_mute_put()
623 struct idt821034 *idt821034 = snd_soc_component_get_drvdata(component); in idt821034_power_event() local
632 mutex_lock(&idt821034->mutex); in idt821034_power_event()
634 power = idt821034_get_channel_power(idt821034, ch); in idt821034_power_event()
639 ret = idt821034_set_channel_power(idt821034, ch, power); in idt821034_power_event()
641 mutex_unlock(&idt821034->mutex); in idt821034_power_event()
700 struct idt821034 *idt821034 = snd_soc_component_get_drvdata(dai->component); in idt821034_dai_set_tdm_slot() local
720 mutex_lock(&idt821034->mutex); in idt821034_dai_set_tdm_slot()
721 ret = idt821034_set_channel_ts(idt821034, ch, IDT821034_CH_RX, slot); in idt821034_dai_set_tdm_slot()
722 mutex_unlock(&idt821034->mutex); in idt821034_dai_set_tdm_slot()
738 idt821034->max_ch_playback = ch; in idt821034_dai_set_tdm_slot()
745 mutex_lock(&idt821034->mutex); in idt821034_dai_set_tdm_slot()
746 ret = idt821034_set_channel_ts(idt821034, ch, IDT821034_CH_TX, slot); in idt821034_dai_set_tdm_slot()
747 mutex_unlock(&idt821034->mutex); in idt821034_dai_set_tdm_slot()
763 idt821034->max_ch_capture = ch; in idt821034_dai_set_tdm_slot()
770 struct idt821034 *idt821034 = snd_soc_component_get_drvdata(dai->component); in idt821034_dai_set_fmt() local
774 mutex_lock(&idt821034->mutex); in idt821034_dai_set_fmt()
776 conf = idt821034_get_codec_conf(idt821034); in idt821034_dai_set_fmt()
791 ret = idt821034_set_codec_conf(idt821034, conf); in idt821034_dai_set_fmt()
793 mutex_unlock(&idt821034->mutex); in idt821034_dai_set_fmt()
801 struct idt821034 *idt821034 = snd_soc_component_get_drvdata(dai->component); in idt821034_dai_hw_params() local
805 mutex_lock(&idt821034->mutex); in idt821034_dai_hw_params()
807 conf = idt821034_get_codec_conf(idt821034); in idt821034_dai_hw_params()
822 ret = idt821034_set_codec_conf(idt821034, conf); in idt821034_dai_hw_params()
824 mutex_unlock(&idt821034->mutex); in idt821034_dai_hw_params()
838 struct idt821034 *idt821034 = snd_soc_component_get_drvdata(dai->component); in idt821034_dai_startup() local
843 idt821034->max_ch_playback : idt821034->max_ch_capture; in idt821034_dai_startup()
878 .name = "idt821034",
896 static int idt821034_reset_audio(struct idt821034 *idt821034) in idt821034_reset_audio() argument
901 mutex_lock(&idt821034->mutex); in idt821034_reset_audio()
903 ret = idt821034_set_codec_conf(idt821034, 0); in idt821034_reset_audio()
908 idt821034->amps.ch[i].amp_out.gain = IDT821034_GAIN_OUT_INIT_RAW; in idt821034_reset_audio()
909 idt821034->amps.ch[i].amp_out.is_muted = false; in idt821034_reset_audio()
910 ret = idt821034_set_gain_channel(idt821034, i, IDT821034_GAIN_RX, in idt821034_reset_audio()
911 idt821034->amps.ch[i].amp_out.gain); in idt821034_reset_audio()
915 idt821034->amps.ch[i].amp_in.gain = IDT821034_GAIN_IN_INIT_RAW; in idt821034_reset_audio()
916 idt821034->amps.ch[i].amp_in.is_muted = false; in idt821034_reset_audio()
917 ret = idt821034_set_gain_channel(idt821034, i, IDT821034_GAIN_TX, in idt821034_reset_audio()
918 idt821034->amps.ch[i].amp_in.gain); in idt821034_reset_audio()
922 ret = idt821034_set_channel_power(idt821034, i, 0); in idt821034_reset_audio()
929 mutex_unlock(&idt821034->mutex); in idt821034_reset_audio()
935 struct idt821034 *idt821034 = snd_soc_component_get_drvdata(component); in idt821034_component_probe() local
938 /* reset idt821034 audio part*/ in idt821034_component_probe()
939 ret = idt821034_reset_audio(idt821034); in idt821034_component_probe()
964 struct idt821034 *idt821034 = gpiochip_get_data(c); in idt821034_chip_gpio_set() local
968 mutex_lock(&idt821034->mutex); in idt821034_chip_gpio_set()
970 slic_raw = idt821034_get_written_slic_raw(idt821034, ch); in idt821034_chip_gpio_set()
975 ret = idt821034_write_slic_raw(idt821034, ch, slic_raw); in idt821034_chip_gpio_set()
977 dev_err(&idt821034->spi->dev, "set gpio %d (%u, 0x%x) failed (%d)\n", in idt821034_chip_gpio_set()
981 mutex_unlock(&idt821034->mutex); in idt821034_chip_gpio_set()
988 struct idt821034 *idt821034 = gpiochip_get_data(c); in idt821034_chip_gpio_get() local
992 mutex_lock(&idt821034->mutex); in idt821034_chip_gpio_get()
993 ret = idt821034_read_slic_raw(idt821034, ch, &slic_raw); in idt821034_chip_gpio_get()
994 mutex_unlock(&idt821034->mutex); in idt821034_chip_gpio_get()
996 dev_err(&idt821034->spi->dev, "get gpio %d (%u, 0x%x) failed (%d)\n", in idt821034_chip_gpio_get()
1013 struct idt821034 *idt821034 = gpiochip_get_data(c); in idt821034_chip_get_direction() local
1016 mutex_lock(&idt821034->mutex); in idt821034_chip_get_direction()
1017 slic_dir = idt821034_get_slic_conf(idt821034, ch); in idt821034_chip_get_direction()
1018 mutex_unlock(&idt821034->mutex); in idt821034_chip_get_direction()
1027 struct idt821034 *idt821034 = gpiochip_get_data(c); in idt821034_chip_direction_input() local
1035 mutex_lock(&idt821034->mutex); in idt821034_chip_direction_input()
1037 slic_conf = idt821034_get_slic_conf(idt821034, ch) | mask; in idt821034_chip_direction_input()
1039 ret = idt821034_set_slic_conf(idt821034, ch, slic_conf); in idt821034_chip_direction_input()
1041 dev_err(&idt821034->spi->dev, "dir in gpio %d (%u, 0x%x) failed (%d)\n", in idt821034_chip_direction_input()
1045 mutex_unlock(&idt821034->mutex); in idt821034_chip_direction_input()
1053 struct idt821034 *idt821034 = gpiochip_get_data(c); in idt821034_chip_direction_output() local
1059 mutex_lock(&idt821034->mutex); in idt821034_chip_direction_output()
1061 slic_conf = idt821034_get_slic_conf(idt821034, ch) & ~mask; in idt821034_chip_direction_output()
1063 ret = idt821034_set_slic_conf(idt821034, ch, slic_conf); in idt821034_chip_direction_output()
1065 dev_err(&idt821034->spi->dev, "dir in gpio %d (%u, 0x%x) failed (%d)\n", in idt821034_chip_direction_output()
1069 mutex_unlock(&idt821034->mutex); in idt821034_chip_direction_output()
1073 static int idt821034_reset_gpio(struct idt821034 *idt821034) in idt821034_reset_gpio() argument
1078 mutex_lock(&idt821034->mutex); in idt821034_reset_gpio()
1082 ret = idt821034_set_slic_conf(idt821034, i, in idt821034_reset_gpio()
1087 ret = idt821034_write_slic_raw(idt821034, i, 0); in idt821034_reset_gpio()
1094 mutex_unlock(&idt821034->mutex); in idt821034_reset_gpio()
1098 static int idt821034_gpio_init(struct idt821034 *idt821034) in idt821034_gpio_init() argument
1102 ret = idt821034_reset_gpio(idt821034); in idt821034_gpio_init()
1106 idt821034->gpio_chip.owner = THIS_MODULE; in idt821034_gpio_init()
1107 idt821034->gpio_chip.label = dev_name(&idt821034->spi->dev); in idt821034_gpio_init()
1108 idt821034->gpio_chip.parent = &idt821034->spi->dev; in idt821034_gpio_init()
1109 idt821034->gpio_chip.base = -1; in idt821034_gpio_init()
1110 idt821034->gpio_chip.ngpio = 5 * 4; /* 5 GPIOs on 4 channels */ in idt821034_gpio_init()
1111 idt821034->gpio_chip.get_direction = idt821034_chip_get_direction; in idt821034_gpio_init()
1112 idt821034->gpio_chip.direction_input = idt821034_chip_direction_input; in idt821034_gpio_init()
1113 idt821034->gpio_chip.direction_output = idt821034_chip_direction_output; in idt821034_gpio_init()
1114 idt821034->gpio_chip.get = idt821034_chip_gpio_get; in idt821034_gpio_init()
1115 idt821034->gpio_chip.set = idt821034_chip_gpio_set; in idt821034_gpio_init()
1116 idt821034->gpio_chip.can_sleep = true; in idt821034_gpio_init()
1118 return devm_gpiochip_add_data(&idt821034->spi->dev, &idt821034->gpio_chip, in idt821034_gpio_init()
1119 idt821034); in idt821034_gpio_init()
1124 struct idt821034 *idt821034; in idt821034_spi_probe() local
1132 idt821034 = devm_kzalloc(&spi->dev, sizeof(*idt821034), GFP_KERNEL); in idt821034_spi_probe()
1133 if (!idt821034) in idt821034_spi_probe()
1136 idt821034->spi = spi; in idt821034_spi_probe()
1138 mutex_init(&idt821034->mutex); in idt821034_spi_probe()
1140 spi_set_drvdata(spi, idt821034); in idt821034_spi_probe()
1148 return idt821034_gpio_init(idt821034); in idt821034_spi_probe()
1154 { .compatible = "renesas,idt821034", },
1160 { "idt821034", 0 },
1167 .name = "idt821034",
1177 MODULE_DESCRIPTION("IDT821034 ALSA SoC driver");