ASoC: Codec driver for Texas Instruments tlv320dac33 codec
Subsystems (3)
PATCH 1/1 ASoC: Codec driver for Texas Instruments tlv320dac33 codec
Driver for Texas Instruments TLV320DAC33 (SLAS546) low power stereo audio DAC.
TLV320DAC33 is a stereo audio codec with integrated 24KB FIFO for low power audio playback.
The digital interface can use I2S, DSP (A or B), Right and Left justified formats.
DAC33 has stereo analog input, which can be bypassed to the analog outputs.
Regarding to the internal 24KB FIFO the driver implements 'FIFO bypass' mode (default) and nSample mode (FIFO is in use).
a) In 'FIFO bypass' mode the internal FIFO is not in use, the codec is working synchronously as a normal codec (it needs constant stream of data on the digital interface).
b) The nSample mode implementation uses one interrupt line from DAC33 to the host:
Alarm threshold is set to 10ms of audio data (limit by the driver implementation).
DAC33 will signal an interrupt, when the FIFO level goes under the Alarm threshold.
The host will write to nSample register a value (number of stereo samples), to tell DAC33 how many samples it should read in a burst from the host. When the DAC33 received the number of samples, it disables the clocks on the I2S bus. When the FIFO use again goes under the Alarm threshold, DAC33 signals the host with an interrupt, and the process is repeated.
--- include/sound/tlv320dac33-plat.h | 20 + sound/soc/codecs/Kconfig | 4 + sound/soc/codecs/Makefile | 2 + sound/soc/codecs/tlv320dac33.c | 1178 ++++++++++++++++++++++++++++++++++++++ sound/soc/codecs/tlv320dac33.h | 267 +++++++++ 5 files changed, 1471 insertions(+), 0 deletions(-) create mode 100644 include/sound/tlv320dac33-plat.h create mode 100644 sound/soc/codecs/tlv320dac33.c create mode 100644 sound/soc/codecs/tlv320dac33.h
include/sound/tlv320dac33-plat.h new file +20 -0
@@ -0,0 +1,20 @@ +/* +* Platform header for Texas Instruments TLV320DAC33 codec driver +* +* Author: Peter Ujfalusi <[email protected]> +* +* Copyright: (C) 2009 Nokia Corporation +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#ifndef __TLV320DAC33_PLAT_H +#define __TLV320DAC33_PLAT_H + +struct tlv320dac33_platform_data { +int power_gpio; +}; + +#endif /* __TLV320DAC33_PLAT_H */
sound/soc/codecs/Kconfig +4 -0
@@ -29,6 +29,7 @@ config SND_SOC_ALL_CODECS select SND_SOC_TLV320AIC23 if I2C select SND_SOC_TLV320AIC26 if SPI_MASTER select SND_SOC_TLV320AIC3X if I2C + select SND_SOC_TLV320DAC33 if I2C select SND_SOC_TPA6130A2 if I2C select SND_SOC_TWL4030 if TWL4030_CORE select SND_SOC_UDA134X
@@ -142,6 +143,9 @@ config SND_SOC_TLV320AIC26 config SND_SOC_TLV320AIC3X tristate +config SND_SOC_TLV320DAC33 + tristate + config SND_SOC_TWL4030 tristate
sound/soc/codecs/Makefile +2 -0
@@ -17,6 +17,7 @@ snd-soc-stac9766-objs := stac9766.o snd-soc-tlv320aic23-objs := tlv320aic23.o snd-soc-tlv320aic26-objs := tlv320aic26.o snd-soc-tlv320aic3x-objs := tlv320aic3x.o +snd-soc-tlv320dac33-objs := tlv320dac33.o snd-soc-twl4030-objs := twl4030.o snd-soc-uda134x-objs := uda134x.o snd-soc-uda1380-objs := uda1380.o
@@ -70,6 +71,7 @@ obj-$(CONFIG_SND_SOC_STAC9766) += snd-soc-stac9766.o obj-$(CONFIG_SND_SOC_TLV320AIC23) += snd-soc-tlv320aic23.o obj-$(CONFIG_SND_SOC_TLV320AIC26) += snd-soc-tlv320aic26.o obj-$(CONFIG_SND_SOC_TLV320AIC3X) += snd-soc-tlv320aic3x.o +obj-$(CONFIG_SND_SOC_TLV320DAC33) += snd-soc-tlv320dac33.o obj-$(CONFIG_SND_SOC_TWL4030) += snd-soc-twl4030.o obj-$(CONFIG_SND_SOC_UDA134X) += snd-soc-uda134x.o obj-$(CONFIG_SND_SOC_UDA1380) += snd-soc-uda1380.o
sound/soc/codecs/tlv320dac33.c new file +1178 -0
1,178 lines not on this page · raw message
sound/soc/codecs/tlv320dac33.h new file +267 -0
267 lines not on this page · raw message
Signature · 1 line
1.6.5.rc2
PATCH 1/1 ASoC: TPA6130A2: Make tpa6130a2_power as static
The power for the amplifier should be handled internally by the tpa6130a2 driver.
--- sound/soc/codecs/tpa6130a2.c | 2 +- sound/soc/codecs/tpa6130a2.h | 1 - 2 files changed, 1 insertions(+), 2 deletions(-)
sound/soc/codecs/tpa6130a2.c +1 -1
@@ -106,7 +106,7 @@ static void tpa6130a2_initialize(void)tpa6130a2_i2c_write (i, data->regs[i]); } -void tpa6130a2_power (int power) +static void tpa6130a2_power (int power) {struct tpa6130a2_data *data;u8 val;
sound/soc/codecs/tpa6130a2.h +0 -1
@@ -57,6 +57,5 @@#define TPA6130A2_VERSION_MASK (0x0f)extern int tpa6130a2_add_controls (struct snd_soc_codec *codec); -extern void tpa6130a2_power (int power);#endif /* __TPA6130A2_H__ */
--
1.6.5.rc2
sound/soc/codecs/tlv320dac33.c line 83
Quoted 3 lines · Peter Ujfalusi
sound/soc/codecs/tlv320dac33.c new file +2
-0+static struct i2c_client *tlv320dac33_client; +static struct workqueue_struct *dac33_wq;
I'm surprised to see these done as static variables - is there any great reason for doing that?
sound/soc/codecs/tlv320dac33.c line 163
Quoted 13 lines
sound/soc/codecs/tlv320dac33.c new file +13
-0+static int dac33_read (struct snd_soc_codec *codec,unsigned int reg, +u8 *value) +{ +struct tlv320dac33_priv *dac33 = codec->private_data; +int val; + + *value = reg &0xff ; + +/* If powered off, return the cached value */ +mutex_lock (&dac33->mutex); +if (dac33->power_state) { + val =i2c_smbus_read_byte_data (codec->control_data, value[0 ]); +if (val <0 ) {
This is happening a lot - it should probably be factored into the shared register cache code, there's a lot of devices which could use something like this especially as regulator support is added to more and more drivers.
sound/soc/codecs/tlv320dac33.c line 164
Quoted 1 line
sound/soc/codecs/tlv320dac33.c new file +1
-0+dev_err (codec->dev,"Read failed\n" );
It'd be useful to print val here.
sound/soc/codecs/tlv320dac33.c line 223
Quoted 8 lines
sound/soc/codecs/tlv320dac33.c new file +8
-0+* data is +* D23..D16 dac33 register offset +* D15..D8 register data MSB +* D7...D0 register data LSB +*/ + data[0 ] = reg &0xff ; + data[1 ] = (value >>8 ) &0xff ; + data[2 ] = value &0xff ;
This looks just like a 16 bit register write - would it make sense to just treat the CODEC as having 16 bit registers and deal with the autoincrement fun by latching the top bit of each 16 bit register in the cache? That seems to be equivalent to what the current code is doing but it's a little more direct.
sound/soc/codecs/tlv320dac33.c line 263
Quoted 12 lines
sound/soc/codecs/tlv320dac33.c new file +12
-0+static void dac33_set_power (struct snd_soc_codec *codec,int power) +{ +struct tlv320dac33_priv *dac33 = codec->private_data; + +if (power) { +if (dac33->power_gpio >=0 ) { +mutex_lock (&dac33->mutex); +gpio_set_value (dac33->power_gpio,1 ); + dac33->power_state =1 ; +mutex_unlock (&dac33->mutex); + } +dac33_soft_power (codec,1 );
What exactly is the mutex protecting here? I'd expect it to cover the soft power function too.
sound/soc/codecs/tlv320dac33.c line 299
Quoted 13 lines
sound/soc/codecs/tlv320dac33.c new file +13
-0+static int dac33_set_nsample (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) +{ +struct snd_soc_codec *codec =snd_kcontrol_chip (kcontrol); +struct tlv320dac33_priv *dac33 = codec->private_data; +int ret = -EINVAL ; + +if (dac33->nsample == ucontrol->value.integer.value[0 ]) +return 0 ; +if (ucontrol->value.integer.value[0 ] < dac33->nsample_min) + dac33->nsample = dac33->nsample_min; +else if (ucontrol->value.integer.value[0 ] > dac33->nsample_max) + dac33->nsample = dac33->nsample_max;
I'd expect these cases to just return the error and not update the driver state?
Quoted 7 lines
sound/soc/codecs/tlv320dac33.c new file +7
-0+static int dac33_set_nsample_switch (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) +{ +struct snd_soc_codec *codec =snd_kcontrol_chip (kcontrol); +struct tlv320dac33_priv *dac33 = codec->private_data; +int ret = -EINVAL ; +
sound/soc/codecs/tlv320dac33.c line 335
Quoted 10 lines
sound/soc/codecs/tlv320dac33.c new file +10
-0+if (dac33->nsample_switch == ucontrol->value.integer.value[0 ]) +return 0 ; +if (ucontrol->value.integer.value[0 ] <0 ) + dac33->nsample_switch =0 ; +else if (ucontrol->value.integer.value[0 ] >1 ) + dac33->nsample_switch =1 ; +else { + dac33->nsample_switch = ucontrol->value.integer.value[0 ]; + ret =0 ; + }
Similarly here.
Quoted 6 lines
sound/soc/codecs/tlv320dac33.c new file +6
-0+static int dac33_set_bias_level (struct snd_soc_codec *codec, +enum snd_soc_bias_level level) +{ +switch (level) { +case SND_SOC_BIAS_ON : +dac33_soft_power (codec,1 );
sound/soc/codecs/tlv320dac33.c line 435
Quoted 10 lines
sound/soc/codecs/tlv320dac33.c new file +10
-0+break ; +case SND_SOC_BIAS_PREPARE : +break ; +case SND_SOC_BIAS_STANDBY : +dac33_soft_power (codec,0 ); +break ; +case SND_SOC_BIAS_OFF : +dac33_set_power (codec,0 ); +break ; + }
Hrm. I'm finding the set_power/soft_power thing a little abstruse here, partly due to the very close naming and partly due to the asymmetry in the calls - I can see what they do but it's not entirely obvious. I'd also expect to see one of these functions doing a register cache restore which none of these do.
I think some refactoring would clarify things here but I don't have a sufficiently clear understanding of how all the pieces fit together to offer any concrete suggestions.
sound/soc/codecs/tlv320dac33.c line 494
Quoted 11 lines
sound/soc/codecs/tlv320dac33.c new file +11
-0+static int dac33_startup (struct snd_pcm_substream *substream, +struct snd_soc_dai *dai) +{ +struct snd_soc_pcm_runtime *rtd = substream->private_data; +struct snd_soc_device *socdev = rtd->socdev; +struct snd_soc_codec *codec = socdev->card->codec; +struct tlv320dac33_priv *dac33 = codec->private_data; +int err; + +/* Save the nsample mode to be used until the stream terminates */ + dac33->nsmaple_cmode = dac33->nsample_switch;
If you're doing this I'd suggest making the control unwritable while playback is active in order to avoid confusion.
sound/soc/codecs/tlv320dac33.c line 505
Quoted 10 lines
sound/soc/codecs/tlv320dac33.c new file +10
-0+/* We only need the interrupt in nSample mode */ +if (dac33->nsmaple_cmode) { + err =request_irq (dac33->irq, dac33_interrupt_handler, +IRQF_TRIGGER_RISING |IRQF_DISABLED , + codec->name, codec); +if (err <0 ) { +dev_err (codec->dev,"Could not request IRQ\n" ); +return err; + } + }
It'd be better to request the IRQ at startup and refuse to offer nsample mode if you don't have it rather than requesting at the start of each stream - that's more the expected usage from an IRQ point of view and it would improve usability since users wouldn't be able to set the mode if it can't be used.
sound/soc/codecs/tlv320dac33.c line 525
Quoted 3 lines
sound/soc/codecs/tlv320dac33.c new file +3
-0+ pwr_ctrl =dac33_read_reg_cache (codec,DAC33_PWR_CTRL ); + pwr_ctrl &= ~(OSCPDNB |DACRPDNB |DACLPDNB ); +dac33_write (codec,DAC33_PWR_CTRL , pwr_ctrl);
This looks like a case for DAPM?
sound/soc/codecs/tlv320dac33.c line 757
Quoted 8 lines
sound/soc/codecs/tlv320dac33.c new file +8
-0+switch (cmd) { +case SNDRV_PCM_TRIGGER_START : +case SNDRV_PCM_TRIGGER_RESUME : +case SNDRV_PCM_TRIGGER_PAUSE_RELEASE : +if (dac33->nsmaple_cmode) { + dac33->state =DAC33_PREFILL ; +queue_work (dac33_wq, &dac33->work); + }
I don't see anything that cancels this work or synchronises with it on shutdown?
sound/soc/codecs/tlv320dac33.c line 868
Quoted 9 lines
sound/soc/codecs/tlv320dac33.c new file +9
-0+static void dac33_init_chip (struct snd_soc_codec *codec) +{ +/* 44-46: DAC Control Registers */ +/* A : DAC sample rate Fsref/1.5 */ +dac33_write (codec,DAC33_DAC_CTRL_A ,DACRATE (1 )); +/* B : DAC src=normal, not muted */ +dac33_write (codec,DAC33_DAC_CTRL_B ,DACSRCR_RIGHT |DACSRCL_LEFT ); +/* C : (defaults) */ +dac33_write (codec,DAC33_DAC_CTRL_C ,0x00 );
Is there any great reason for setting all of this stuff rather than using the hardware defaults?
Quoted 1 line
+/* Bit definitions */
Pretty much all the bit definitions need to be namespaced - a lot of them are very generic and likely to generate clashes.
Quoted 7 lines · ext Mark Brown
Quoted 7 lines
sound/soc/codecs/tlv320dac33.c new file +7
-0+static void dac33_set_power (struct snd_soc_codec *codec,int power) +{ +struct tlv320dac33_priv *dac33 = codec->private_data; + +if (power) { +if (dac33->power_gpio >=0 ) { +mutex_lock (&dac33->mutex);
Quoted 8 lines
sound/soc/codecs/tlv320dac33.c line 263
Quoted 5 lines
sound/soc/codecs/tlv320dac33.c new file +5
-0+gpio_set_value (dac33->power_gpio,1 ); + dac33->power_state =1 ; +mutex_unlock (&dac33->mutex); + } +dac33_soft_power (codec,1 );What exactly is the mutex protecting here? I'd expect it to cover the soft power function too.
Agreed the mutex doesn't help any on the power on path. However, if you hold the mutex already with the call to dac33_soft_power(), that will eventually deadlock - as currently the mutex is taken for every i2c transaction out there. But for the power off path, it's more than desired.
The use of this mutex appears quite aggressive - it's taken for every i2c transaction. But it does cover the fatal case - where the dac33 is powered down (just imagine what happens to an i2c transaction if the RST line is being asserted during i2c read/write to the chip).
I guess the mutex may be brought higher in the hierarchy at some point of time. That is to also say that the dac33 i2c write sequences would then become "linear", which would be nice for the robustness overall; quoting the few lines:
"+ * tlv320dac33 is strict on the sequence of the register writes, if the register
+ * writes happens in different order, than dac33 might end up in unknown state."
it seems that indeed linearizing i2c write(read) sequences would not be a bad idea after all.
Quoted 7 lines · On Monday 12 October 2009 18:18:00 ext Mark Brown wrote:
sound/soc/codecs/tlv320dac33.c line 83
Quoted 3 lines · Peter Ujfalusi
sound/soc/codecs/tlv320dac33.c new file +2
-0+static struct i2c_client *tlv320dac33_client; +static struct workqueue_struct *dac33_wq;I'm surprised to see these done as static variables - is there any great reason for doing that?
Hmm, I'm surprised as well, will be fixed.
Quoted 11 lines
Quoted 11 lines
sound/soc/codecs/tlv320dac33.c new file +10
-0+static int dac33_read (struct snd_soc_codec *codec,unsigned int reg, +u8 *value) +{ +struct tlv320dac33_priv *dac33 = codec->private_data; +int val; + + *value = reg &0xff ; + +/* If powered off, return the cached value */ +mutex_lock (&dac33->mutex);
Quoted 8 lines
sound/soc/codecs/tlv320dac33.c line 163
Quoted 3 lines
sound/soc/codecs/tlv320dac33.c new file +3
-0+if (dac33->power_state) { + val =i2c_smbus_read_byte_data (codec->control_data, value[0 ]); +if (val <0 ) {This is happening a lot - it should probably be factored into the shared register cache code, there's a lot of devices which could use something like this especially as regulator support is added to more and more drivers.
Actually this does not happen that much, since the reg_cache is used for most of the read operation, but the write through I2C might be happening more.
Quoted 4 lines
sound/soc/codecs/tlv320dac33.c line 164
Quoted 2 lines
sound/soc/codecs/tlv320dac33.c new file +1
-0+dev_err (codec->dev,"Read failed\n" );It'd be useful to print val here.
Sure.
Quoted 15 lines
sound/soc/codecs/tlv320dac33.c line 223
Quoted 9 lines
sound/soc/codecs/tlv320dac33.c new file +8
-0+* data is +* D23..D16 dac33 register offset +* D15..D8 register data MSB +* D7...D0 register data LSB +*/ + data[0 ] = reg &0xff ; + data[1 ] = (value >>8 ) &0xff ; + data[2 ] = value &0xff ;This looks just like a 16 bit register write - would it make sense to just treat the CODEC as having 16 bit registers and deal with the autoincrement fun by latching the top bit of each 16 bit register in the cache? That seems to be equivalent to what the current code is doing but it's a little more direct.
Most of the registers are 8 bit, there are few exception to this, where 2 registers holds the MSB and LSB of the value, that's justify the existence of this function. I could have used two writes for the registers, but in this way the code looks cleaner.
Quoted 16 lines
sound/soc/codecs/tlv320dac33.c line 263
Quoted 13 lines
sound/soc/codecs/tlv320dac33.c new file +12
-0+static void dac33_set_power (struct snd_soc_codec *codec,int power) +{ +struct tlv320dac33_priv *dac33 = codec->private_data; + +if (power) { +if (dac33->power_gpio >=0 ) { +mutex_lock (&dac33->mutex); +gpio_set_value (dac33->power_gpio,1 ); + dac33->power_state =1 ; +mutex_unlock (&dac33->mutex); + } +dac33_soft_power (codec,1 );What exactly is the mutex protecting here? I'd expect it to cover the soft power function too.
It suppose to protect the dac33->power_state, which is checked when accessing to the chip (via I2C). Probably there would be no problems, if I don't use the mutex for protecting the dac33->power_state...
Basically nothing will brake, but the I2C access would fail and the driver would print an error to the log.
I'm not sure how to make sure that we can access to the chip, and at the same time do not use extensive mutex lock/unlock for the I2C accesses. Ideas?
Quoted 17 lines
Quoted 4 lines
sound/soc/codecs/tlv320dac33.c new file +3
-0+static int dac33_set_nsample (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) +{sound/soc/codecs/tlv320dac33.c line 299
Quoted 10 lines
sound/soc/codecs/tlv320dac33.c new file +10
-0+struct snd_soc_codec *codec =snd_kcontrol_chip (kcontrol); +struct tlv320dac33_priv *dac33 = codec->private_data; +int ret = -EINVAL ; + +if (dac33->nsample == ucontrol->value.integer.value[0 ]) +return 0 ; +if (ucontrol->value.integer.value[0 ] < dac33->nsample_min) + dac33->nsample = dac33->nsample_min; +else if (ucontrol->value.integer.value[0 ] > dac33->nsample_max) + dac33->nsample = dac33->nsample_max;I'd expect these cases to just return the error and not update the driver state?
Will do that.
Quoted 12 lines
Quoted 12 lines
sound/soc/codecs/tlv320dac33.c new file +11
-0+static int dac33_set_nsample_switch (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) +{ +struct snd_soc_codec *codec =snd_kcontrol_chip (kcontrol); +struct tlv320dac33_priv *dac33 = codec->private_data; +int ret = -EINVAL ; + +if (dac33->nsample_switch == ucontrol->value.integer.value[0 ]) +return 0 ; +if (ucontrol->value.integer.value[0 ] <0 ) + dac33->nsample_switch =0 ;
Quoted 8 lines
sound/soc/codecs/tlv320dac33.c line 335
Quoted 6 lines
sound/soc/codecs/tlv320dac33.c new file +6
-0+else if (ucontrol->value.integer.value[0 ] >1 ) + dac33->nsample_switch =1 ; +else { + dac33->nsample_switch = ucontrol->value.integer.value[0 ]; + ret =0 ; + }Similarly here.
I'll fix this as well.
Quoted 13 lines
Quoted 13 lines
sound/soc/codecs/tlv320dac33.c new file +12
-0+static int dac33_set_bias_level (struct snd_soc_codec *codec, +enum snd_soc_bias_level level) +{ +switch (level) { +case SND_SOC_BIAS_ON : +dac33_soft_power (codec,1 ); +break ; +case SND_SOC_BIAS_PREPARE : +break ; +case SND_SOC_BIAS_STANDBY : +dac33_soft_power (codec,0 ); +break ;
Quoted 8 lines
sound/soc/codecs/tlv320dac33.c line 435
Quoted 4 lines
sound/soc/codecs/tlv320dac33.c new file +4
-0+case SND_SOC_BIAS_OFF : +dac33_set_power (codec,0 ); +break ; + }Hrm. I'm finding the set_power/soft_power thing a little abstruse here, partly due to the very close naming and partly due to the asymmetry in the calls - I can see what they do but it's not entirely obvious.
Hmm, yes you are right, it is kind of a mess...
I can think of the following:dac33_set_power -> dac33_hard_resetdac33_soft_power -> dac33_soft_reset
In dac33_set_bias_level only toggle the dac33_soft_reset.
In dac33_soc_suspend/dac33_soc_resume I can use the dac33_hard_reset with register restore.
Does it makes it a bit cleaner?
Quoted 2 lines
I'd also expect to see one of these functions doing a register cache restore which none of these do.
After dac33_set_power(1) there is a place for restoring the registers, yes. At the moment the only place where this is happening is in dac33_soc_resume, there I can add the register restore.
Quoted 5 lines
I think some refactoring would clarify things here but I don't have a sufficiently clear understanding of how all the pieces fit together to offer any concrete suggestions.
Quoted 14 lines
sound/soc/codecs/tlv320dac33.c line 494
Quoted 11 lines
sound/soc/codecs/tlv320dac33.c new file +11
-0+static int dac33_startup (struct snd_pcm_substream *substream, +struct snd_soc_dai *dai) +{ +struct snd_soc_pcm_runtime *rtd = substream->private_data; +struct snd_soc_device *socdev = rtd->socdev; +struct snd_soc_codec *codec = socdev->card->codec; +struct tlv320dac33_priv *dac33 = codec->private_data; +int err; + +/* Save the nsample mode to be used until the stream terminates */ + dac33->nsmaple_cmode = dac33->nsample_switch;If you're doing this I'd suggest making the control unwritable while playback is active in order to avoid confusion.
Yes, than I don't need the nsample_cmode.
Quoted 17 lines
sound/soc/codecs/tlv320dac33.c line 505
Quoted 11 lines
sound/soc/codecs/tlv320dac33.c new file +10
-0+/* We only need the interrupt in nSample mode */ +if (dac33->nsmaple_cmode) { + err =request_irq (dac33->irq, dac33_interrupt_handler, +IRQF_TRIGGER_RISING |IRQF_DISABLED , + codec->name, codec); +if (err <0 ) { +dev_err (codec->dev,"Could not request IRQ\n" ); +return err; + } + }It'd be better to request the IRQ at startup and refuse to offer nsample mode if you don't have it rather than requesting at the start of each stream - that's more the expected usage from an IRQ point of view and it would improve usability since users wouldn't be able to set the mode if it can't be used.
Good point.
Quoted 6 lines
sound/soc/codecs/tlv320dac33.c line 525
Quoted 4 lines
sound/soc/codecs/tlv320dac33.c new file +3
-0+ pwr_ctrl =dac33_read_reg_cache (codec,DAC33_PWR_CTRL ); + pwr_ctrl &= ~(OSCPDNB |DACRPDNB |DACLPDNB ); +dac33_write (codec,DAC33_PWR_CTRL , pwr_ctrl);This looks like a case for DAPM?
Well, yes. I have tried that. The problem is that tlv320dac33 is really picky on the sequence of the register writes. what I mean by 'picky' is that if the register accesses are not in certain order, than dac33 would be not operational. This particular shutdown is in place, because otherwise dac33 would be dead in certain cases...
There might be a possibility to find another sequence, which is working, but this is really time consuming process.
I'd also like to move these to DAPM domain, but for now, I'd like to leave this as it is and fix it later, if it is possible at all.
Quoted 10 lines
sound/soc/codecs/tlv320dac33.c line 757
Quoted 9 lines
sound/soc/codecs/tlv320dac33.c new file +8
-0+switch (cmd) { +case SNDRV_PCM_TRIGGER_START : +case SNDRV_PCM_TRIGGER_RESUME : +case SNDRV_PCM_TRIGGER_PAUSE_RELEASE : +if (dac33->nsmaple_cmode) { + dac33->state =DAC33_PREFILL ; +queue_work (dac33_wq, &dac33->work); + }
Quoted 2 lines
I don't see anything that cancels this work or synchronises with it on shutdown?
Good point, also the dac33->state is not really protected, which can cause some interesting behavior, I think.
I'll look at this as well..
Quoted 13 lines
sound/soc/codecs/tlv320dac33.c line 868
Quoted 10 lines
sound/soc/codecs/tlv320dac33.c new file +9
-0+static void dac33_init_chip (struct snd_soc_codec *codec) +{ +/* 44-46: DAC Control Registers */ +/* A : DAC sample rate Fsref/1.5 */ +dac33_write (codec,DAC33_DAC_CTRL_A ,DACRATE (1 )); +/* B : DAC src=normal, not muted */ +dac33_write (codec,DAC33_DAC_CTRL_B ,DACSRCR_RIGHT |DACSRCL_LEFT ); +/* C : (defaults) */ +dac33_write (codec,DAC33_DAC_CTRL_C ,0x00 );Is there any great reason for setting all of this stuff rather than using the hardware defaults?
Yes and no. I can wipe out the unneeded things, but most of the settings here is needed to get the dac33 working. If we use the HW defaults, than dac33 would not work.
The DAC_CTRL_B register for example controls the digital routing to the DACs. I will try to find a way to use user controls for most of the settings in a future, if it is OK.
Quoted 5 lines
Quoted 2 lines
+/* Bit definitions */
Pretty much all the bit definitions need to be namespaced - a lot of them are very generic and likely to generate clashes.
I'll go through all of them.
Thanks,
Péter
Quoted 11 lines · Peter Ujfalusi
Quoted 8 lines · On Monday 12 October 2009 18:18:00 ext Mark Brown wrote:
sound/soc/codecs/tlv320dac33.c line 163
Quoted 3 lines
sound/soc/codecs/tlv320dac33.c new file +3
-0+if (dac33->power_state) { + val =i2c_smbus_read_byte_data (codec->control_data, value[0 ]); +if (val <0 ) {This is happening a lot - it should probably be factored into the shared register cache code, there's a lot of devices which could use something like this especially as regulator support is added to more and more drivers.
Quoted 2 lines
Actually this does not happen that much, since the
reg_cacheis used for most of the read operation, but the write through I2C might be happening more.
I mean the pattern of suppressing I2C writes while the chip is powered down rather than the
Quoted 3 lines
I'm not sure how to make sure that we can access to the chip, and at the same time do not use extensive mutex lock/unlock for the I2C accesses. Ideas?
Perhaps just call the mutex something more descriptive like chip_power or something might be enough make it clear what it's protecting?
Quoted 9 lines
Quoted 3 lines
Hrm. I'm finding the set_power/soft_power thing a little abstruse here, partly due to the very close naming and partly due to the asymmetry in the calls - I can see what they do but it's not entirely obvious.
Hmm, yes you are right, it is kind of a mess...
I can think of the following:dac33_set_power->dac33_hard_resetdac33_soft_power->dac33_soft_reset
Quoted 5 lines
In
dac33_set_bias_levelonly toggle thedac33_soft_reset.
In dac33_soc_suspend/dac33_soc_resume I can use thedac33_hard_resetwith register restore.Does it makes it a bit cleaner?
I think so - it'd probably also help if the cache restore were merged into one of the functions too. I'd be inclined to keep _power too.
Quoted 8 lines
Quoted 4 lines
sound/soc/codecs/tlv320dac33.c line 525
Quoted 2 lines
sound/soc/codecs/tlv320dac33.c new file +2
-0+ pwr_ctrl &= ~(OSCPDNB |DACRPDNB |DACLPDNB ); +dac33_write (codec,DAC33_PWR_CTRL , pwr_ctrl);This looks like a case for DAPM?
Well, yes. I have tried that. The problem is that tlv320dac33 is really picky on the sequence of the register writes. what I mean by 'picky' is that if the
OK, fair enough.
Quoted 9 lines
Quoted 2 lines
Is there any great reason for setting all of this stuff rather than using the hardware defaults?
Yes and no. I can wipe out the unneeded things, but most of the settings here is needed to get the dac33 working. If we use the HW defaults, than dac33 would not work.
TheDAC_CTRL_Bregister for example controls the digital routing to the DACs. I will try to find a way to use user controls for most of the settings in a future, if it is OK.
OK. I'd expect that at some point people will want to control things like the digital routing.
Quoted 2 lines · On Tuesday 13 October 2009 12:26:22 ext Mark Brown wrote:
I mean the pattern of suppressing I2C writes while the chip is powered down rather than the
I guess I have some good way of handling this (thanks to Eero for the idea)
Quoted 7 lines
Quoted 4 lines
I'm not sure how to make sure that we can access to the chip, and at the same time do not use extensive mutex lock/unlock for the I2C accesses. Ideas?
Perhaps just call the mutex something more descriptive like
chip_poweror something might be enough make it clear what it's protecting?
Now that the mutex handling is cleaner in the chip power sense, I'll use the same mutex to protect the state as well (when the dac33 is in nSample mode). It fits there nicely as well.
Quoted 5 lines
Quoted 5 lines
Hmm, yes you are right, it is kind of a mess...
I can think of the following:dac33_set_power->dac33_hard_resetdac33_soft_power->dac33_soft_reset
Quoted 8 lines
Quoted 5 lines
In
dac33_set_bias_levelonly toggle thedac33_soft_reset.
In dac33_soc_suspend/dac33_soc_resume I can use thedac33_hard_resetwith register restore.Does it makes it a bit cleaner?
I think so - it'd probably also help if the cache restore were merged into one of the functions too. I'd be inclined to keep
_powertoo.
You mean something like this:dac33_set_power -> dac33_hard_powerdac33_soft_power -> dac33_soft_power
Or keeping the old names, but make the use of these more consequent?
Quoted 2 lines
OK. I'd expect that at some point people will want to control things like the digital routing.
I think, I will have the controls implemented before anyone would realize that they need control for those ;)
But it will be done in the future since it needs lot's of tries to get things sorted out.
Signature · 1 line
Péter
Quoted 8 lines · Peter Ujfalusi
Quoted 2 lines · On Tuesday 13 October 2009 12:26:22 ext Mark Brown wrote:
I think so - it'd probably also help if the cache restore were merged into one of the functions too. I'd be inclined to keep
_powertoo.You mean something like this:
dac33_set_power->dac33_hard_powerdac33_soft_power->dac33_soft_power
Yes but...
Quoted 1 line
Or keeping the old names, but make the use of these more consequent?
...also the second bit of this :)