ASoC: tas27{64,70}: improve support for Apple codec variants
v4 cover ASoC: tas27{64,70}: improve support for Apple codec variants
Hi all,
This series introduces a number of changes to the drivers for the Texas Instruments TAS2764 and TAS2770 amplifiers in order to introduce (and improve in the case of TAS2770) support for the variants of these amps found in Apple Silicon Macs.
Apple's variant of TAS2764 is known as SN012776, and as always with Apple is a subtly incompatible variant with a number of quirks. It is not publicly available. The TAS2770 variant is known as TAS5770L, and does not require incompatible handling.
Much as with the Cirrus codec patches, I do not
expect that we will get any official acknowledgement that these parts exist from TI, however I would be delighted to be proven wrong.
This series has been living in the downstream Asahi kernel tree[1] for over two years, and has been tested by many thousands of users by this point[2].
v4 drops the TDM idle TX slot behaviour patches. I experimented with the API discussed in v3, however this did not work on any of the machines I tested it with. More tweaking is probably needed.
[1] https://github.com/AsahiLinux/linux/tree/asahi-wip
[2] https://stats.asahilinux.org/
---
Changes in v4:
- Moved remaining changes to the top of the set
- Dropped already merged commits
- hwmon now reads temp from regmap
- Bumped regmap max reg patch above Apple quirks patch
- Dropped TDM idle slot TX behaviour patches
- Link to v3: https://lore.kernel.org/r/[email protected]
Changes in v3:
- Add Rob's Acked-by to Devicetree compatible additions
- Dropped cherry-picked patches
- Droped abuse of regulator API
- Droped bespoke sysfs interface
- Rationalised temperature reading for hwmon interface
- Set SN012776 device ID with OF match data
- Changed probe ops reliant on device ID to case/switch statement
- Added documentation for new Devicetree properties
- Improved a number of poor quality commit messages
- Documented behaviour of die temperature ADC
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Changed author field of patch to match Martin's Signed-off-by
- Added Neal's Reviewed-by to reviewed patches
- Moved fixes to existing code to the top of the series
- Removed tas2764's explicit dependency on OF
- Removed complicated single-use tas2764 quirks macro and replaced with
if block
- Added hwmon interface for codec die temp
- Fixed a malformed commit message
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Hector Martin (4):
ASoC: tas2770: Power cycle amp on ISENSE/VSENSE change
ASoC: tas2770: Support setting the PDM TX slot
ASoC: tas2770: Set the SDOUT polarity correctly
ASoC: tas2764: Enable main IRQs
James Calligeros (2):
ASoC: tas2770: expose die temp to hwmon
ASoC: tas2764: expose die temp to hwmon
Martin Povišer (4):
ASoC: tas2764: Reinit cache on part reset
ASoC: tas2764: Crop SDOUT zero-out mask based on BCLK ratio
ASoC: tas2764: Raise regmap range maximum
ASoC: tas2764: Apply Apple quirks
sound/soc/codecs/tas2764-quirks.h | 180 +++++++++++++++++++++++++ sound/soc/codecs/tas2764.c | 176 +++++++++++++++++++++++- sound/soc/codecs/tas2764.h | 3 + sound/soc/codecs/tas2770.c | 160 +++++++++++++++++++++- sound/soc/codecs/tas2770.h | 6 + 5 files changed, 519 insertions(+), 6 deletions(-)
---
base-commit: 3a0f0a4355df0240485ed62b6bd6afa5b3e689c5
change-id: 20250214-apple-codec-changes-6e656dc1e24d
Best regards,
Signature · 1 line
James Calligeros <[email protected]>
PATCH v4 1/10 ASoC: tas2770: Power cycle amp on ISENSE/VSENSE change
From: Hector Martin <[email protected]>
The ISENSE/VSENSE blocks are only powered up when the amplifier transitions from shutdown to active. This means that if those controls are flipped on while the amplifier is already playing back audio, they will have no effect.
Fix this by forcing a power cycle around transitions in those controls.
--- sound/soc/codecs/tas2770.c | 30 +++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-)
sound/soc/codecs/tas2770.c +28 -2
@@ -156,11 +156,37 @@ static const struct snd_kcontrol_new isense_switch =static const struct snd_kcontrol_new vsense_switch =SOC_DAPM_SINGLE ("Switch" ,TAS2770_PWR_CTRL ,2 ,1 ,1 ); +static int sense_event (struct snd_soc_dapm_widget *w, +struct snd_kcontrol *kcontrol,int event) +{ +struct snd_soc_component *component =snd_soc_dapm_to_component (w->dapm); +struct tas2770_priv *tas2770 =snd_soc_component_get_drvdata (component); + +/* +* Powering up ISENSE/VSENSE requires a trip through the shutdown state. +* Do that here to ensure that our changes are applied properly, otherwise +* we might end up with non-functional IVSENSE if playback started earlier, +* which would break software speaker protection. +*/ +switch (event) { +case SND_SOC_DAPM_PRE_REG : +return snd_soc_component_update_bits (component,TAS2770_PWR_CTRL , +TAS2770_PWR_CTRL_MASK , +TAS2770_PWR_CTRL_SHUTDOWN ); +case SND_SOC_DAPM_POST_REG : +return tas2770_update_pwr_ctrl (tas2770); +default : +return 0 ; + } +} +static const struct snd_soc_dapm_widget tas2770_dapm_widgets[] = {SND_SOC_DAPM_AIF_IN ("ASI1" ,"ASI1 Playback" ,0 ,SND_SOC_NOPM ,0 ,0 ),SND_SOC_DAPM_MUX ("ASI1 Sel" ,SND_SOC_NOPM ,0 ,0 , &tas2770_asi1_mux), -SND_SOC_DAPM_SWITCH ("ISENSE" ,TAS2770_PWR_CTRL ,3 ,1 , &isense_switch), -SND_SOC_DAPM_SWITCH ("VSENSE" ,TAS2770_PWR_CTRL ,2 ,1 , &vsense_switch), +SND_SOC_DAPM_SWITCH_E ("ISENSE" ,TAS2770_PWR_CTRL ,3 ,1 , &isense_switch, + sense_event,SND_SOC_DAPM_PRE_REG |SND_SOC_DAPM_POST_REG ), +SND_SOC_DAPM_SWITCH_E ("VSENSE" ,TAS2770_PWR_CTRL ,2 ,1 , &vsense_switch, + sense_event,SND_SOC_DAPM_PRE_REG |SND_SOC_DAPM_POST_REG ),SND_SOC_DAPM_DAC_E ("DAC" ,NULL ,SND_SOC_NOPM ,0 ,0 , tas2770_dac_event,SND_SOC_DAPM_POST_PMU |SND_SOC_DAPM_PRE_PMD ),SND_SOC_DAPM_OUTPUT ("OUT" ),
Signature · 1 line
2.49.0
PATCH v4 2/10 ASoC: tas2770: Support setting the PDM TX slot
In reply to James CalligerosFrom: Hector Martin <[email protected]>
We don't actually support configuring the PDM input right now. Rather, this is useful as a hack.
On Apple Silicon machines, amps are split between two I2S buses which are logically ANDed internally at the SoC. Odd and even slot groups are driven by amps on either bus respectively. Since the signals are ANDed, unused slot groups must be driven as zero to avoid corrupting the data from the other side.
On most recent machines (TAS2764-based), this is accomplished using the "SDOUT zero mask" feature of that chip. Unfortunately, TAS2770 does not support this. It does support zeroing out *all* unused slots, which works well for machines with a single amp per I2S bus. That is all, except one.
The 13" M1 MacBook Pro is the only machine using TAS2770 and two amps per I2S bus:
L Bus: SPK0I SPK0V Hi-Z Hi-Z SPK2I SPK2V Hi-Z Hi-Z R Bus: Hi-Z Hi-Z SPK1I SPK2V Hi-Z Hi-Z SPK3I SPK3V
To ensure uncorrupted data, we need to force all the Hi-Z periods to zero. We cannot use the "force all zero" feature, as that would cause a bus conflict between both amps. We can use the pull-down feature, but that leaves a few bits of garbage on the trailing edge of the speaker data, since the pull-down is weak.
This is where the PDM transmit feature comes in. With PDM grounded and disabled (the default state), the PDM slot is transmitted as all zeroes. We can use that to force a zero 16-bit slot after the voltage data for each speaker, cleaning it up. Then the pull-down ensures the line stays low for the subsequent slot:
L Bus: SPK0I SPK0V PDM0 PulDn SPK2I SPK2V PDM0 PulDn R Bus: PDM0 PulDn SPK1I SPK2V PDM0 PulDn SPK3I SPK3V
Yes, this is a horrible hack, but it beats adding dummy slots that would be visible to the userspace capture side. There may be some other way to fix the logical AND behavior on the MCA side... that would make this unnecessary.
("How does Apple deal with this"? - they don't, macOS does not use IVSENSE on TAS2770 machines even though it's physically wired up, but we want to do so on Linux.)
--- sound/soc/codecs/tas2770.c | 25 +++++++++++++++++++++++++ sound/soc/codecs/tas2770.h | 6 ++++++ 2 files changed, 31 insertions(+)
sound/soc/codecs/tas2770.c +25 -0
@@ -240,6 +240,19 @@ static int tas2770_set_ivsense_transmit(struct tas2770_priv *tas2770,return 0 ; } +static int tas2770_set_pdm_transmit (struct tas2770_priv *tas2770,int slot) +{ +struct snd_soc_component *component = tas2770->component; +int ret; + + ret =snd_soc_component_update_bits (component,TAS2770_TDM_CFG_REG7 , +TAS2770_TDM_CFG_REG7_PDM_MASK | +TAS2770_TDM_CFG_REG7_50_MASK , +TAS2770_TDM_CFG_REG7_PDM_ENABLE | + slot); +return ret; +} +static int tas2770_set_bitwidth (struct tas2770_priv *tas2770,int bitwidth) {int ret;
@@ -543,6 +556,13 @@ static int tas2770_codec_probe(struct snd_soc_component *component)return ret; } +if (tas2770->pdm_slot !=-1 ) { + ret =tas2770_set_pdm_transmit (tas2770, tas2770->pdm_slot); + +if (ret <0 ) +return ret; + } +return 0 ; }
@@ -682,6 +702,11 @@ static int tas2770_parse_dt(struct device *dev, struct tas2770_priv *tas2770) tas2770->v_sense_slot =-1 ; } + rc =fwnode_property_read_u32 (dev->fwnode,"ti,pdm-slot-no" , + &tas2770->pdm_slot); +if (rc) + tas2770->pdm_slot =-1 ; + tas2770->sdz_gpio =devm_gpiod_get_optional (dev,"shutdown" ,GPIOD_OUT_HIGH );if (IS_ERR (tas2770->sdz_gpio)) {if (PTR_ERR (tas2770->sdz_gpio) == -EPROBE_DEFER )
sound/soc/codecs/tas2770.h +6 -0
@@ -77,6 +77,11 @@#define TAS2770_TDM_CFG_REG6_ISNS_MASK BIT(6)#define TAS2770_TDM_CFG_REG6_ISNS_ENABLE BIT(6)#define TAS2770_TDM_CFG_REG6_50_MASK GENMASK(5, 0) +/* TDM Configuration Reg10 */ +#define TAS2770_TDM_CFG_REG7 TAS2770_REG(0X0, 0x11) +#define TAS2770_TDM_CFG_REG7_PDM_MASK BIT(6) +#define TAS2770_TDM_CFG_REG7_PDM_ENABLE BIT(6) +#define TAS2770_TDM_CFG_REG7_50_MASK GENMASK(5, 0)/* Brown Out Prevention Reg0 */ #define TAS2770_BO_PRV_REG0 TAS2770_REG(0X0, 0x1B)/* Interrupt MASK Reg0 */
@@ -138,6 +143,7 @@ struct tas2770_priv {struct device *dev;int v_sense_slot;int i_sense_slot; +int pdm_slot;bool dac_powered;bool unmuted; };
Signature · 1 line
2.49.0
PATCH v4 3/10 ASoC: tas2770: Set the SDOUT polarity correctly
In reply to James CalligerosFrom: Hector Martin <[email protected]>
TX launch polarity needs to be the opposite of RX capture polarity, to generate the right bit slot alignment.
--- sound/soc/codecs/tas2770.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
sound/soc/codecs/tas2770.c +8 -1
@@ -351,7 +351,7 @@ static int tas2770_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)struct snd_soc_component *component = dai->component;struct tas2770_priv *tas2770 =snd_soc_component_get_drvdata (component); -u8 tdm_rx_start_slot =0 , invert_fpol =0 , fpol_preinv =0 , asi_cfg_1 =0 ; +u8 tdm_rx_start_slot =0 , invert_fpol =0 , fpol_preinv =0 , asi_cfg_1 =0 , asi_cfg_4 =0 ;int ret;switch (fmt &SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK ) {
@@ -368,6 +368,7 @@ static int tas2770_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) fallthrough;case SND_SOC_DAIFMT_NB_NF : asi_cfg_1 |=TAS2770_TDM_CFG_REG1_RX_RSING ; + asi_cfg_4 |=TAS2770_TDM_CFG_REG4_TX_EDGE_FALLING ;break ;case SND_SOC_DAIFMT_IB_IF : invert_fpol =1 ;
@@ -386,6 +387,12 @@ static int tas2770_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)if (ret <0 )return ret; + ret =snd_soc_component_update_bits (component,TAS2770_TDM_CFG_REG4 , +TAS2770_TDM_CFG_REG4_TX_EDGE_FALLING , + asi_cfg_4); +if (ret <0 ) +return ret; +switch (fmt &SND_SOC_DAIFMT_FORMAT_MASK ) {case SND_SOC_DAIFMT_I2S : tdm_rx_start_slot =1 ;
Signature · 1 line
2.49.0
kernel test robot
build botRe: [PATCH v4 03/10] ASoC: tas2770: Set the SDOUT polarity correctly
kernel test robot noticed the following build errors:
Hi James,
kernel test robot noticed the following build errors:
[auto build test ERROR on 3a0f0a4355df0240485ed62b6bd6afa5b3e689c5]
url: https://github.com/intel-lab-lkp/linux/commits/James-Calligeros/ASoC-tas2770-Power-cycle-amp-on-ISENSE-VSENSE-change/20250405-081800 base: 3a0f0a4355df0240485ed62b6bd6afa5b3e689c5 patch link: https://lore.kernel.org/r/20250405-apple-codec-changes-v4-3-d007e46ce4a2%40gmail.com patch subject: [PATCH v4 03/10] ASoC: tas2770: Set the SDOUT polarity correctly config: arc-randconfig-001-20250406 (https://download.01.org/0day-ci/archive/20250406/[email protected]/config) compiler: arc-linux-gcc (GCC) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250406/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
sound/soc/codecs/tas2770.c: In function 'tas2770_set_fmt':
>> sound/soc/codecs/tas2770.c:371:30: error: 'TAS2770_TDM_CFG_REG4_TX_EDGE_FALLING' undeclared (first use in this function); did you mean 'TAS2770_TDM_CFG_REG1_RX_FALING'?
371 | asi_cfg_4 |= TAS2770_TDM_CFG_REG4_TX_EDGE_FALLING;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| TAS2770_TDM_CFG_REG1_RX_FALING
sound/soc/codecs/tas2770.c:371:30: note: each undeclared identifier is reported only once for each function it appears in
>> sound/soc/codecs/tas2770.c:390:56: error: 'TAS2770_TDM_CFG_REG4' undeclared (first use in this function); did you mean 'TAS2770_TDM_CFG_REG7'?
390 | ret = snd_soc_component_update_bits(component, TAS2770_TDM_CFG_REG4,
| ^~~~~~~~~~~~~~~~~~~~
| TAS2770_TDM_CFG_REG7vim +371 sound/soc/codecs/tas2770.c
348
349 static int tas2770_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
350 {
351 struct snd_soc_component *component = dai->component;
352 struct tas2770_priv *tas2770 =
353 snd_soc_component_get_drvdata(component);
354 u8 tdm_rx_start_slot = 0, invert_fpol = 0, fpol_preinv = 0, asi_cfg_1 = 0, asi_cfg_4 = 0;
355 int ret;
356
357 switch (fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) {
358 case SND_SOC_DAIFMT_CBC_CFC:
359 break;
360 default:
361 dev_err(tas2770->dev, "ASI invalid DAI clocking\n");
362 return -EINVAL;
363 }
364
365 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
366 case SND_SOC_DAIFMT_NB_IF:
367 invert_fpol = 1;
368 fallthrough;
369 case SND_SOC_DAIFMT_NB_NF:
370 asi_cfg_1 |= TAS2770_TDM_CFG_REG1_RX_RSING;
> 371 asi_cfg_4 |= TAS2770_TDM_CFG_REG4_TX_EDGE_FALLING; 372 break; 373 case SND_SOC_DAIFMT_IB_IF: 374 invert_fpol = 1; 375 fallthrough; 376 case SND_SOC_DAIFMT_IB_NF: 377 asi_cfg_1 |= TAS2770_TDM_CFG_REG1_RX_FALING; 378 break; 379 default: 380 dev_err(tas2770->dev, "ASI format Inverse is not found\n"); 381 return -EINVAL; 382 } 383 384 ret = snd_soc_component_update_bits(component, TAS2770_TDM_CFG_REG1, 385 TAS2770_TDM_CFG_REG1_RX_MASK, 386 asi_cfg_1); 387 if (ret < 0) 388 return ret; 389 > 390 ret = snd_soc_component_update_bits(component, TAS2770_TDM_CFG_REG4,
391 TAS2770_TDM_CFG_REG4_TX_EDGE_FALLING,
392 asi_cfg_4);
393 if (ret < 0)
394 return ret;
395
396 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
397 case SND_SOC_DAIFMT_I2S:
398 tdm_rx_start_slot = 1;
399 fpol_preinv = 0;
400 break;
401 case SND_SOC_DAIFMT_DSP_A:
402 tdm_rx_start_slot = 0;
403 fpol_preinv = 1;
404 break;
405 case SND_SOC_DAIFMT_DSP_B:
406 tdm_rx_start_slot = 1;
407 fpol_preinv = 1;
408 break;
409 case SND_SOC_DAIFMT_LEFT_J:
410 tdm_rx_start_slot = 0;
411 fpol_preinv = 1;
412 break;
413 default:
414 dev_err(tas2770->dev,
415 "DAI Format is not found, fmt=0x%x\n", fmt);
416 return -EINVAL;
417 }
418
419 ret = snd_soc_component_update_bits(component, TAS2770_TDM_CFG_REG1,
420 TAS2770_TDM_CFG_REG1_MASK,
421 (tdm_rx_start_slot << TAS2770_TDM_CFG_REG1_51_SHIFT));
422 if (ret < 0)
423 return ret;
424
425 ret = snd_soc_component_update_bits(component, TAS2770_TDM_CFG_REG0,
426 TAS2770_TDM_CFG_REG0_FPOL_MASK,
427 (fpol_preinv ^ invert_fpol)
428 ? TAS2770_TDM_CFG_REG0_FPOL_RSING
429 : TAS2770_TDM_CFG_REG0_FPOL_FALING);
430 if (ret < 0)
431 return ret;
432
433 return 0;
434 }
435
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
PATCH v4 4/10 ASoC: tas2764: Reinit cache on part reset
In reply to James CalligerosFrom: Martin Povišer <[email protected]>
When the part is reset in component_probe, do not forget to reinit the regcache, otherwise the cache can get out of sync with the part's actual state. This fix is similar to commit 0a0342ede303 ("ASoC: tas2770: Reinit regcache on reset") which concerned the tas2770 driver.
--- sound/soc/codecs/tas2764.c | 3 +++ 1 file changed, 3 insertions(+)
sound/soc/codecs/tas2764.c +3 -0
@@ -546,6 +546,8 @@ static uint8_t sn012776_bop_presets[] = { 0x06, 0x3e, 0x37, 0x30, 0xff, 0xe6 }; +static const struct regmap_config tas2764_i2c_regmap; +static int tas2764_codec_probe (struct snd_soc_component *component) {struct tas2764_priv *tas2764 =snd_soc_component_get_drvdata (component);
@@ -559,6 +561,7 @@ static int tas2764_codec_probe(struct snd_soc_component *component) }tas2764_reset (tas2764); +regmap_reinit_cache (tas2764->regmap, &tas2764_i2c_regmap);if (tas2764->irq) { ret =snd_soc_component_write (tas2764->component,TAS2764_INT_MASK0 ,0xff );
Signature · 1 line
2.49.0
PATCH v4 5/10 ASoC: tas2764: Enable main IRQs
In reply to James CalligerosFrom: Hector Martin <[email protected]>
IRQ handling was added in commit dae191fb957f ("ASoC: tas2764: Add IRQ handling") however that same commit masks all interrupts coming from the chip. Unmask the "main" interrupts so that we can see and deal with a number of errors including clock, voltage, and current.
--- sound/soc/codecs/tas2764.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/codecs/tas2764.c +1 -1
@@ -564,7 +564,7 @@ static int tas2764_codec_probe(struct snd_soc_component *component)regmap_reinit_cache (tas2764->regmap, &tas2764_i2c_regmap);if (tas2764->irq) { - ret =snd_soc_component_write (tas2764->component,TAS2764_INT_MASK0 ,0xff ); + ret =snd_soc_component_write (tas2764->component,TAS2764_INT_MASK0 ,0x00 );if (ret <0 )return ret;
Signature · 1 line
2.49.0
PATCH v4 6/10 ASoC: tas2764: Crop SDOUT zero-out mask based on BCLK ratio
In reply to James CalligerosFrom: Martin Povišer <[email protected]>
As per the datasheet, SDOUT bits must be zeroed out if the corresponding TDM slot is invalid for a given clock ratio.
--- sound/soc/codecs/tas2764.c | 39 +++++++++++++++++++++++++ 1 file changed, 39 insertions(+)
sound/soc/codecs/tas2764.c +39 -0
@@ -367,6 +367,44 @@ static int tas2764_hw_params(struct snd_pcm_substream *substream,return tas2764_set_samplerate (tas2764,params_rate (params)); } +static int tas2764_write_sdout_zero_mask (struct tas2764_priv *tas2764,int bclk_ratio) +{ +struct snd_soc_component *component = tas2764->component; +int nsense_slots = bclk_ratio /8 ; +u32 cropped_mask; +int i, ret; + +if (!tas2764->sdout_zero_mask) +return 0 ; + + cropped_mask = tas2764->sdout_zero_mask &GENMASK (nsense_slots -1 ,0 ); + +for (i =0 ; i <4 ; i++) { + ret =snd_soc_component_write (component,TAS2764_SDOUT_HIZ_1 + i, + (cropped_mask >> (i *8 )) &0xff ); + +if (ret <0 ) +return ret; + } + + ret =snd_soc_component_update_bits (component,TAS2764_SDOUT_HIZ_9 , +TAS2764_SDOUT_HIZ_9_FORCE_0_EN , +TAS2764_SDOUT_HIZ_9_FORCE_0_EN ); + +if (ret <0 ) +return ret; + +return 0 ; +} + +static int tas2764_set_bclk_ratio (struct snd_soc_dai *dai,unsigned int ratio) +{ +struct snd_soc_component *component = dai->component; +struct tas2764_priv *tas2764 =snd_soc_component_get_drvdata (component); + +return tas2764_write_sdout_zero_mask (tas2764, ratio); +} +static int tas2764_set_fmt (struct snd_soc_dai *dai,unsigned int fmt) {struct snd_soc_component *component = dai->component;
@@ -506,6 +544,7 @@ static int tas2764_set_dai_tdm_slot(struct snd_soc_dai *dai,static const struct snd_soc_dai_ops tas2764_dai_ops = { .mute_stream = tas2764_mute, .hw_params = tas2764_hw_params, + .set_bclk_ratio = tas2764_set_bclk_ratio, .set_fmt = tas2764_set_fmt, .set_tdm_slot = tas2764_set_dai_tdm_slot, .no_capture_mute =1 ,
Signature · 1 line
2.49.0
kernel test robot
build botRe: [PATCH v4 06/10] ASoC: tas2764: Crop SDOUT zero-out mask based on BCLK ratio
kernel test robot noticed the following build errors:
Hi James,
kernel test robot noticed the following build errors:
[auto build test ERROR on 3a0f0a4355df0240485ed62b6bd6afa5b3e689c5]
url: https://github.com/intel-lab-lkp/linux/commits/James-Calligeros/ASoC-tas2770-Power-cycle-amp-on-ISENSE-VSENSE-change/20250405-081800 base: 3a0f0a4355df0240485ed62b6bd6afa5b3e689c5 patch link: https://lore.kernel.org/r/20250405-apple-codec-changes-v4-6-d007e46ce4a2%40gmail.com patch subject: [PATCH v4 06/10] ASoC: tas2764: Crop SDOUT zero-out mask based on BCLK ratio config: arm-randconfig-001-20250406 (https://download.01.org/0day-ci/archive/20250406/[email protected]/config) compiler: clang version 21.0.0git (https://github.com/llvm/llvm-project 92c93f5286b9ff33f27ff694d2dc33da1c07afdd) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250406/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
>> sound/soc/codecs/tas2764.c:377:16: error: no member named 'sdout_zero_mask' in 'struct tas2764_priv'
377 | if (!tas2764->sdout_zero_mask)
| ~~~~~~~ ^
sound/soc/codecs/tas2764.c:380:26: error: no member named 'sdout_zero_mask' in 'struct tas2764_priv'
380 | cropped_mask = tas2764->sdout_zero_mask & GENMASK(nsense_slots - 1, 0);
| ~~~~~~~ ^
>> sound/soc/codecs/tas2764.c:383:44: error: use of undeclared identifier 'TAS2764_SDOUT_HIZ_1'
383 | ret = snd_soc_component_write(component, TAS2764_SDOUT_HIZ_1 + i,
| ^
>> sound/soc/codecs/tas2764.c:390:49: error: use of undeclared identifier 'TAS2764_SDOUT_HIZ_9'
390 | ret = snd_soc_component_update_bits(component, TAS2764_SDOUT_HIZ_9,
| ^
>> sound/soc/codecs/tas2764.c:391:10: error: use of undeclared identifier 'TAS2764_SDOUT_HIZ_9_FORCE_0_EN'
391 | TAS2764_SDOUT_HIZ_9_FORCE_0_EN,
| ^
sound/soc/codecs/tas2764.c:392:10: error: use of undeclared identifier 'TAS2764_SDOUT_HIZ_9_FORCE_0_EN'
392 | TAS2764_SDOUT_HIZ_9_FORCE_0_EN);
| ^6 errors generated.
vim +377 sound/soc/codecs/tas2764.c
369
370 static int tas2764_write_sdout_zero_mask(struct tas2764_priv *tas2764, int bclk_ratio)
371 {
372 struct snd_soc_component *component = tas2764->component;
373 int nsense_slots = bclk_ratio / 8;
374 u32 cropped_mask;
375 int i, ret;
376
> 377 if (!tas2764->sdout_zero_mask)
378 return 0;
379
> 380 cropped_mask = tas2764->sdout_zero_mask & GENMASK(nsense_slots - 1, 0);
381
382 for (i = 0; i < 4; i++) {
> 383 ret = snd_soc_component_write(component, TAS2764_SDOUT_HIZ_1 + i,
384 (cropped_mask >> (i * 8)) & 0xff);
385
386 if (ret < 0)
387 return ret;
388 }
389
> 390 ret = snd_soc_component_update_bits(component, TAS2764_SDOUT_HIZ_9,
> 391 TAS2764_SDOUT_HIZ_9_FORCE_0_EN, 392 TAS2764_SDOUT_HIZ_9_FORCE_0_EN);
393
394 if (ret < 0)
395 return ret;
396
397 return 0;
398 }
399
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [PATCH v4 06/10] ASoC: tas2764: Crop SDOUT zero-out mask based on BCLK ratio
In reply to James Calligeroskernel test robot noticed the following build errors:
Hi James,
kernel test robot noticed the following build errors:
[auto build test ERROR on 3a0f0a4355df0240485ed62b6bd6afa5b3e689c5]
url: https://github.com/intel-lab-lkp/linux/commits/James-Calligeros/ASoC-tas2770-Power-cycle-amp-on-ISENSE-VSENSE-change/20250405-081800 base: 3a0f0a4355df0240485ed62b6bd6afa5b3e689c5 patch link: https://lore.kernel.org/r/20250405-apple-codec-changes-v4-6-d007e46ce4a2%40gmail.com patch subject: [PATCH v4 06/10] ASoC: tas2764: Crop SDOUT zero-out mask based on BCLK ratio config: arc-randconfig-001-20250406 (https://download.01.org/0day-ci/archive/20250406/[email protected]/config) compiler: arc-linux-gcc (GCC) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250406/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
sound/soc/codecs/tas2764.c: In function 'tas2764_write_sdout_zero_mask':
>> sound/soc/codecs/tas2764.c:377:21: error: 'struct tas2764_priv' has no member named 'sdout_zero_mask'
377 | if (!tas2764->sdout_zero_mask)
| ^~
sound/soc/codecs/tas2764.c:380:31: error: 'struct tas2764_priv' has no member named 'sdout_zero_mask'
380 | cropped_mask = tas2764->sdout_zero_mask & GENMASK(nsense_slots - 1, 0);
| ^~
>> sound/soc/codecs/tas2764.c:383:58: error: 'TAS2764_SDOUT_HIZ_1' undeclared (first use in this function)
383 | ret = snd_soc_component_write(component, TAS2764_SDOUT_HIZ_1 + i,
| ^~~~~~~~~~~~~~~~~~~
sound/soc/codecs/tas2764.c:383:58: note: each undeclared identifier is reported only once for each function it appears in
>> sound/soc/codecs/tas2764.c:390:56: error: 'TAS2764_SDOUT_HIZ_9' undeclared (first use in this function)
390 | ret = snd_soc_component_update_bits(component, TAS2764_SDOUT_HIZ_9,
| ^~~~~~~~~~~~~~~~~~~
>> sound/soc/codecs/tas2764.c:391:45: error: 'TAS2764_SDOUT_HIZ_9_FORCE_0_EN' undeclared (first use in this function)
391 | TAS2764_SDOUT_HIZ_9_FORCE_0_EN,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~vim +377 sound/soc/codecs/tas2764.c
369
370 static int tas2764_write_sdout_zero_mask(struct tas2764_priv *tas2764, int bclk_ratio)
371 {
372 struct snd_soc_component *component = tas2764->component;
373 int nsense_slots = bclk_ratio / 8;
374 u32 cropped_mask;
375 int i, ret;
376
> 377 if (!tas2764->sdout_zero_mask)
378 return 0;
379
380 cropped_mask = tas2764->sdout_zero_mask & GENMASK(nsense_slots - 1, 0);
381
382 for (i = 0; i < 4; i++) {
> 383 ret = snd_soc_component_write(component, TAS2764_SDOUT_HIZ_1 + i,
384 (cropped_mask >> (i * 8)) & 0xff);
385
386 if (ret < 0)
387 return ret;
388 }
389
> 390 ret = snd_soc_component_update_bits(component, TAS2764_SDOUT_HIZ_9,
> 391 TAS2764_SDOUT_HIZ_9_FORCE_0_EN, 392 TAS2764_SDOUT_HIZ_9_FORCE_0_EN);
393
394 if (ret < 0)
395 return ret;
396
397 return 0;
398 }
399
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
PATCH v4 7/10 ASoC: tas2764: Raise regmap range maximum
In reply to James CalligerosFrom: Martin Povišer <[email protected]>
TAS2764 has a number of undocumented registers between page 0xf0 and 0xff. These are used to apply in-silicon quirks and workarounds at runtime.
Raise the regmap max register to 0xffff to cover any quirks registers.
--- sound/soc/codecs/tas2764.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
sound/soc/codecs/tas2764.c +2 -2
@@ -724,7 +724,7 @@ static const struct reg_default tas2764_reg_defaults[] = {static const struct regmap_range_cfg tas2764_regmap_ranges[] = { { .range_min =0 , - .range_max =1 *128 , + .range_max =0xffff , .selector_reg =TAS2764_PAGE , .selector_mask =0xff , .selector_shift =0 ,
@@ -754,7 +754,7 @@ static const struct regmap_config tas2764_i2c_regmap = { .cache_type = REGCACHE_RBTREE, .ranges = tas2764_regmap_ranges, .num_ranges = ARRAY_SIZE(tas2764_regmap_ranges), - .max_register = 1 * 128, + .max_register = 0xffff, };static int tas2764_parse_dt (struct device *dev,struct tas2764_priv *tas2764)
Signature · 1 line
2.49.0
PATCH v4 8/10 ASoC: tas2764: Apply Apple quirks
In reply to James CalligerosFrom: Martin Povišer <[email protected]>
Apple's SN012776 driver has some peculiar aspects to its behavior that are suspected to work around issues in the codec part. Add a module parameter for enabling individual quirks that should be imitated after the Apple driver.
Setting some of these by default seems to be required. For example, setting 0xf fixes an issue with transient overcurrent errors which can crash the chip until the next system reboot. To be safe, let's enable all of them by default.
--- sound/soc/codecs/tas2764-quirks.h | 180 +++++++++++++++++++++++++ sound/soc/codecs/tas2764.c | 39 ++++++ 2 files changed, 219 insertions(+)
sound/soc/codecs/tas2764-quirks.h new file +180 -0
@@ -0,0 +1,180 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __TAS2764_QUIRKS__ +#define __TAS2764_QUIRKS__ + +#include <linux/regmap.h> + +#include "tas2764.h" + +/* Bitmask of enabled Apple quirks */ +#define ENABLED_APPLE_QUIRKS 0x3f + +/* +* Disable noise gate and flip down reserved bit in NS_CFG0 +*/ +#define TAS2764_NOISE_GATE_DISABLE BIT(0) + +static const struct reg_sequence tas2764_noise_gate_dis_seq[] = { +REG_SEQ0 (TAS2764_REG (0x0 ,0x35 ),0xb0 ) +}; + +/* +* CONV_VBAT_PVDD_MODE=1 +*/ +#define TAS2764_CONV_VBAT_PVDD_MODE BIT(1) + +static const struct reg_sequence tas2764_conv_vbat_pvdd_mode_seq[] = { +REG_SEQ0 (TAS2764_REG (0x0 ,0x6b ),0x41 ) +}; + +/* +* Reset of DAC modulator when DSP is OFF +*/ +#define TAS2764_DMOD_RST BIT(2) + +static const struct reg_sequence tas2764_dmod_rst_seq[] = { +REG_SEQ0 (TAS2764_REG (0x0 ,0x76 ),0x0 ) +}; + +/* +* Unknown 0x133/0x137 writes (maybe TDM related) +*/ +#define TAS2764_UNK_SEQ0 BIT(3) + +static const struct reg_sequence tas2764_unk_seq0[] = { +REG_SEQ0 (TAS2764_REG (0x1 ,0x33 ),0x80 ), +REG_SEQ0 (TAS2764_REG (0x1 ,0x37 ),0x3a ), +}; + +/* +* Unknown 0x614 - 0x61f writes +*/ +#define TAS2764_APPLE_UNK_SEQ1 BIT(4) + +static const struct reg_sequence tas2764_unk_seq1[] = { +REG_SEQ0 (TAS2764_REG (0x6 ,0x14 ),0x0 ), +REG_SEQ0 (TAS2764_REG (0x6 ,0x15 ),0x13 ), +REG_SEQ0 (TAS2764_REG (0x6 ,0x16 ),0x52 ), +REG_SEQ0 (TAS2764_REG (0x6 ,0x17 ),0x0 ), +REG_SEQ0 (TAS2764_REG (0x6 ,0x18 ),0xe4 ), +REG_SEQ0 (TAS2764_REG (0x6 ,0x19 ),0xc ), +REG_SEQ0 (TAS2764_REG (0x6 ,0x16 ),0xaa ), +REG_SEQ0 (TAS2764_REG (0x6 ,0x1b ),0x0 ), +REG_SEQ0 (TAS2764_REG (0x6 ,0x1c ),0x12 ), +REG_SEQ0 (TAS2764_REG (0x6 ,0x1d ),0xa0 ), +REG_SEQ0 (TAS2764_REG (0x6 ,0x1e ),0xd8 ), +REG_SEQ0 (TAS2764_REG (0x6 ,0x1f ),0x0 ), +}; + +/* +* Unknown writes in the 0xfd page (with secondary paging inside) +*/ +#define TAS2764_APPLE_UNK_SEQ2 BIT(5) + +static const struct reg_sequence tas2764_unk_seq2[] = { +REG_SEQ0 (TAS2764_REG (0xfd ,0x0d ),0xd ), +REG_SEQ0 (TAS2764_REG (0xfd ,0x6c ),0x2 ), +REG_SEQ0 (TAS2764_REG (0xfd ,0x6d ),0xf ), +REG_SEQ0 (TAS2764_REG (0xfd ,0x0d ),0x0 ), +}; + +/* +* Disable 'Thermal Threshold 1' +*/ +#define TAS2764_THERMAL_TH1_DISABLE BIT(6) + +static const struct reg_sequence tas2764_thermal_th1_dis_seq[] = { +REG_SEQ0 (TAS2764_REG (0x1 ,0x47 ),0x2 ), +}; + +/* +* Imitate Apple's shutdown dance +*/ +#define TAS2764_SHUTDOWN_DANCE BIT(7) + +static const struct reg_sequence tas2764_shutdown_dance_init_seq[] = { +/* +* SDZ_MODE=01 (immediate) +* +* We want the shutdown to happen under the influence of +* the magic writes in the 0xfdXX region, so make sure +* the shutdown is immediate and there's no grace period +* followed by the codec part. +*/ +REG_SEQ0 (TAS2764_REG (0x0 ,0x7 ),0x60 ), +}; + +static const struct reg_sequence tas2764_pre_shutdown_seq[] = { +REG_SEQ0 (TAS2764_REG (0xfd ,0x0d ),0xd ),/* switch hidden page */ +REG_SEQ0 (TAS2764_REG (0xfd ,0x64 ),0x4 ),/* do write (unknown semantics) */ +REG_SEQ0 (TAS2764_REG (0xfd ,0x0d ),0x0 ),/* switch hidden page back */ +}; + +static const struct reg_sequence tas2764_post_shutdown_seq[] = { +REG_SEQ0 (TAS2764_REG (0xfd ,0x0d ),0xd ), +REG_SEQ0 (TAS2764_REG (0xfd ,0x64 ),0x0 ),/* revert write from pre sequence */ +REG_SEQ0 (TAS2764_REG (0xfd ,0x0d ),0x0 ), +}; + +static int tas2764_do_quirky_pwr_ctrl_change (struct tas2764_priv *tas2764, +unsigned int target) +{ +unsigned int curr; +int ret; + + curr =snd_soc_component_read_field (tas2764->component, +TAS2764_PWR_CTRL , +TAS2764_PWR_CTRL_MASK ); + +if (target == curr) +return 0 ; + +/* Handle power state transition to shutdown */ +if (target ==TAS2764_PWR_CTRL_SHUTDOWN && + (curr ==TAS2764_PWR_CTRL_MUTE || curr ==TAS2764_PWR_CTRL_ACTIVE )) { + ret =regmap_multi_reg_write (tas2764->regmap, tas2764_pre_shutdown_seq, +ARRAY_SIZE (tas2764_pre_shutdown_seq)); +if (!ret) + ret =snd_soc_component_update_bits (tas2764->component, +TAS2764_PWR_CTRL , +TAS2764_PWR_CTRL_MASK , +TAS2764_PWR_CTRL_SHUTDOWN ); +if (!ret) + ret =regmap_multi_reg_write (tas2764->regmap, + tas2764_post_shutdown_seq, +ARRAY_SIZE (tas2764_post_shutdown_seq)); + } + + ret =snd_soc_component_update_bits (tas2764->component,TAS2764_PWR_CTRL , +TAS2764_PWR_CTRL_MASK , target); + +return ret; +} + +/* +* Via devicetree (TODO): +* - switch from spread spectrum to class-D switching +* - disable edge control +* - set BOP settings (the BOP config bits *and* BOP_SRC) +*/ + +/* +* Other setup TODOs: +* - DVC ramp rate +*/ + +static const struct tas2764_quirk_init_sequence { +const struct reg_sequence *seq; +int len; +} tas2764_quirk_init_sequences[] = { + { tas2764_noise_gate_dis_seq,ARRAY_SIZE (tas2764_noise_gate_dis_seq) }, + { tas2764_dmod_rst_seq,ARRAY_SIZE (tas2764_dmod_rst_seq) }, + { tas2764_conv_vbat_pvdd_mode_seq,ARRAY_SIZE (tas2764_conv_vbat_pvdd_mode_seq) }, + { tas2764_unk_seq0,ARRAY_SIZE (tas2764_unk_seq0) }, + { tas2764_unk_seq1,ARRAY_SIZE (tas2764_unk_seq1) }, + { tas2764_unk_seq2,ARRAY_SIZE (tas2764_unk_seq2) }, + { tas2764_thermal_th1_dis_seq,ARRAY_SIZE (tas2764_thermal_th1_dis_seq) }, + { tas2764_shutdown_dance_init_seq,ARRAY_SIZE (tas2764_shutdown_dance_init_seq) }, +}; + +#endif /* __TAS2764_QUIRKS__ */
sound/soc/codecs/tas2764.c +39 -0
@@ -45,6 +45,8 @@ struct tas2764_priv {bool unmuted; }; +#include "tas2764-quirks.h" +static const char *tas2764_int_ltch0_msgs[8 ] = {"fault: over temperature" ,/* INT_LTCH0 & BIT(0) */ "fault: over current" ,
@@ -122,6 +124,9 @@ static int tas2764_update_pwr_ctrl(struct tas2764_priv *tas2764)else val =TAS2764_PWR_CTRL_SHUTDOWN ; +if (ENABLED_APPLE_QUIRKS &TAS2764_SHUTDOWN_DANCE ) +return tas2764_do_quirky_pwr_ctrl_change (tas2764, val); + ret =snd_soc_component_update_bits (component,TAS2764_PWR_CTRL ,TAS2764_PWR_CTRL_MASK , val);if (ret <0 )
@@ -587,6 +592,30 @@ static uint8_t sn012776_bop_presets[] = {static const struct regmap_config tas2764_i2c_regmap; +static int tas2764_apply_init_quirks (struct tas2764_priv *tas2764) +{ +int ret, i; + +for (i =0 ; i <ARRAY_SIZE (tas2764_quirk_init_sequences); i++) { +const struct tas2764_quirk_init_sequence *init_seq = + &tas2764_quirk_init_sequences[i]; + +if (!init_seq->seq) +continue ; + +if (!(BIT (i) &ENABLED_APPLE_QUIRKS )) +continue ; + + ret =regmap_multi_reg_write (tas2764->regmap, init_seq->seq, + init_seq->len); + +if (ret <0 ) +return ret; + } + +return 0 ; +} +static int tas2764_codec_probe (struct snd_soc_component *component) {struct tas2764_priv *tas2764 =snd_soc_component_get_drvdata (component);
@@ -656,6 +685,13 @@ static int tas2764_codec_probe(struct snd_soc_component *component)if (ret <0 )return ret; } + +/* Apply all enabled Apple quirks */ + ret =tas2764_apply_init_quirks (tas2764); + +if (ret <0 ) +return ret; +break ;default :break ;
@@ -740,6 +776,9 @@ static bool tas2764_volatile_register(struct device *dev, unsigned int reg) case TAS2764_INT_LTCH0 ... TAS2764_INT_LTCH4:case TAS2764_INT_CLK_CFG :return true; + case TAS2764_REG(0xf0, 0x0) ... TAS2764_REG(0xff, 0x0): +/* TI's undocumented registers for the application of quirks */ +return true;default :return false; }
Signature · 1 line
2.49.0
PATCH v4 9/10 ASoC: tas2770: expose die temp to hwmon
In reply to James CalligerosTAS2770 includes an ADC which reports the chip's die temperature. As per the datasheet, the temperature in degrees Celsius is derived by taking the raw value stored in the ADC's registers, dividing by 16, then subtracting 93.
Create and register a hwmon device to expose the chip's die temperature to the hwmon interface.
The ADC is shut down during software shutdown mode, and its registers are initialised to 0 on reset. This means that the die temperature will read -93 *C until the chip has been fully powered up at least once (e.g. the PCM its attached to is opened). Once the chip is put into software shutdown again, the ADC will also shut down. The last value sampled before this happens will persist in the ADC's registers.
--- sound/soc/codecs/tas2770.c | 96 +++++++++++++++++++++++++ 1 file changed, 96 insertions(+)
sound/soc/codecs/tas2770.c +96 -0
@@ -12,6 +12,7 @@#include <linux/err.h> #include <linux/init.h> #include <linux/delay.h> +#include <linux/hwmon.h> #include <linux/pm.h> #include <linux/i2c.h> #include <linux/gpio/consumer.h>
@@ -537,6 +538,88 @@ static struct snd_soc_dai_driver tas2770_dai_driver[] = { }, }; +static int tas2770_read_die_temp (struct tas2770_priv *tas2770,long *result) +{ +int ret =0 ; +int reading, msb, lsb; + + ret =regmap_read (tas2770->regmap,TAS2770_TEMP_MSB , &msb); +if (ret) +return ret; + + ret =regmap_read (tas2770->regmap,TAS2770_TEMP_LSB , &lsb); +if (ret) +return ret; + + reading = (msb <<4 ) | (lsb >>4 ); + +/* +* As per datasheet: divide register by 16 and subtract 93 to get +* degrees Celsius. hwmon requires millidegrees. Let's avoid rounding +* errors by subtracting 93 * 16 then multiplying by 1000 / 16. +* +* NOTE: The ADC registers are initialised to 0 on reset. This means +* that the temperature will read -93 *C until the chip is brought out +* of software shutdown (e.g. the PCM it's attached to is opened). The +* ADC is also shut down in software shutdown/low-power mode, so the +* value read back from its registers will be the last value sampled +* before entering software shutdown. +*/ + *result = (reading - (93 *16 )) * (1000 /16 ); +return 0 ; +} + +static umode_t tas2770_hwmon_is_visible (const void *data, +enum hwmon_sensor_types type,u32 attr, +int channel) +{ +if (type != hwmon_temp) +return 0 ; + +switch (attr) { +case hwmon_temp_input: +return 0444 ; +default : +break ; + } + +return 0 ; +} + +static int tas2770_hwmon_read (struct device *dev, +enum hwmon_sensor_types type, +u32 attr,int channel,long *val) +{ +struct tas2770_priv *tas2770 =dev_get_drvdata (dev); +int ret; + +switch (attr) { +case hwmon_temp_input: + ret =tas2770_read_die_temp (tas2770, val); +break ; +default : + ret = -EOPNOTSUPP ; +break ; + } + +return ret; +} + +static const struct hwmon_channel_info *const tas2770_hwmon_info[] = { +HWMON_CHANNEL_INFO (temp,HWMON_T_INPUT ), +NULL +}; + +static const struct hwmon_ops tas2770_hwmon_ops = { + .is_visible = tas2770_hwmon_is_visible, + .read = tas2770_hwmon_read, +}; + +static const struct hwmon_chip_info tas2770_hwmon_chip_info = { + .ops = &tas2770_hwmon_ops, + .info = tas2770_hwmon_info, +}; +static const struct regmap_config tas2770_i2c_regmap;static int tas2770_codec_probe (struct snd_soc_component *component)
@@ -765,6 +848,19 @@ static int tas2770_i2c_probe(struct i2c_client *client) } } +if (IS_REACHABLE (CONFIG_HWMON )) { +struct device *hwmon; + + hwmon =devm_hwmon_device_register_with_info (&client->dev,"tas2770" , + tas2770, + &tas2770_hwmon_chip_info, +NULL ); +if (IS_ERR (hwmon)) { +return dev_err_probe (&client->dev,PTR_ERR (hwmon), +"Failed to register temp sensor\n" ); + } + } + result =tas2770_register_codec (tas2770);if (result)dev_err (tas2770->dev,"Register codec failed.\n" );
Signature · 1 line
2.49.0
PATCH v4 10/10 ASoC: tas2764: expose die temp to hwmon
In reply to James CalligerosTAS2764 contains an ADC that reports the chip's die temperature. The temperature in degrees Celsius is yielded by subtracting 93 from the raw value reported by the ADC.
Expose the codec die temperature to the hwmon interface.
The chip will initialise the temperature register to 2.6 *C to avoid triggering over temp protection. As the ADC is powered down during software shutdown, this value will persist until the chip is fully powered up (e.g. when the PCM it's attached to is opened). When the chip is powered back down, the last value sampled will persist in the register.
--- sound/soc/codecs/tas2764.c | 89 +++++++++++++++++++++++++ sound/soc/codecs/tas2764.h | 3 + 2 files changed, 92 insertions(+)
sound/soc/codecs/tas2764.c +89 -0
@@ -8,6 +8,7 @@#include <linux/err.h> #include <linux/init.h> #include <linux/delay.h> +#include <linux/hwmon.h> #include <linux/pm.h> #include <linux/i2c.h> #include <linux/gpio/consumer.h>
@@ -616,6 +617,80 @@ static int tas2764_apply_init_quirks(struct tas2764_priv *tas2764)return 0 ; } +static int tas2764_read_die_temp (struct tas2764_priv *tas2764,long *result) +{ +int ret, reg; + + ret =regmap_read (tas2764->regmap,TAS2764_TEMP , ®); +if (ret) +return ret; +/* +* As per datasheet, subtract 93 from raw value to get degrees +* Celsius. hwmon wants millidegrees. +* +* NOTE: The chip will initialise the TAS2764_TEMP register to +* 2.6 *C to avoid triggering temperature protection. Since the +* ADC is powered down during software shutdown, this value will +* persist until the chip is fully powered up (e.g. the PCM it's +* attached to is opened). The ADC will power down again when +* the chip is put back into software shutdown, with the last +* value sampled persisting in the ADC's register. +*/ + *result = (reg -93 ) *1000 ; +return 0 ; +} + +static umode_t tas2764_hwmon_is_visible (const void *data, +enum hwmon_sensor_types type,u32 attr, +int channel) +{ +if (type != hwmon_temp) +return 0 ; + +switch (attr) { +case hwmon_temp_input: +return 0444 ; +default : +break ; + } + +return 0 ; +} + +static int tas2764_hwmon_read (struct device *dev, +enum hwmon_sensor_types type, +u32 attr,int channel,long *val) +{ +struct tas2764_priv *tas2764 =dev_get_drvdata (dev); +int ret; + +switch (attr) { +case hwmon_temp_input: + ret =tas2764_read_die_temp (tas2764, val); +break ; +default : + ret = -EOPNOTSUPP ; +break ; + } + +return ret; +} + +static const struct hwmon_channel_info *const tas2764_hwmon_info[] = { +HWMON_CHANNEL_INFO (temp,HWMON_T_INPUT ), +NULL +}; + +static const struct hwmon_ops tas2764_hwmon_ops = { + .is_visible = tas2764_hwmon_is_visible, + .read = tas2764_hwmon_read, +}; + +static const struct hwmon_chip_info tas2764_hwmon_chip_info = { + .ops = &tas2764_hwmon_ops, + .info = tas2764_hwmon_info, +}; +static int tas2764_codec_probe (struct snd_soc_component *component) {struct tas2764_priv *tas2764 =snd_soc_component_get_drvdata (component);
@@ -864,6 +939,20 @@ static int tas2764_i2c_probe(struct i2c_client *client) } } +if (IS_REACHABLE (CONFIG_HWMON )) { +struct device *hwmon; + + hwmon =devm_hwmon_device_register_with_info (&client->dev,"tas2764" , + tas2764, + &tas2764_hwmon_chip_info, +NULL ); +if (IS_ERR (hwmon)) { +return dev_err_probe (&client->dev,PTR_ERR (hwmon), +"Failed to register temp sensor\n" ); + } + } + + return devm_snd_soc_register_component(tas2764->dev, &soc_component_driver_tas2764, tas2764_dai_driver,
sound/soc/codecs/tas2764.h +3 -0
@@ -117,6 +117,9 @@#define TAS2764_INT_LTCH3 TAS2764_REG(0x0, 0x50)#define TAS2764_INT_LTCH4 TAS2764_REG(0x0, 0x51) +/* Readout Registers */ +#define TAS2764_TEMP TAS2764_REG(0x0, 0x56) +/* Clock/IRQ Settings */ #define TAS2764_INT_CLK_CFG TAS2764_REG(0x0, 0x5c)#define TAS2764_INT_CLK_CFG_IRQZ_CLR BIT(2)
Signature · 1 line
2.49.0