ASoC: cs35l36: Add support for Cirrus CS35L36 Amplifier
Subsystems (4)
PATCH v2 1/2 ASoC: cs35l36: Add support for Cirrus CS35L36 Amplifier
Add driver support for Cirrus Logic CS35L36 boosted speaker amplifier
--- include/sound/cs35l36.h | 58 ++ sound/soc/codecs/Kconfig | 5 + sound/soc/codecs/Makefile | 2 + sound/soc/codecs/cs35l36-tables.c | 312 +++++++ sound/soc/codecs/cs35l36.c | 1665 +++++++++++++++++++++++++++++++++++++ sound/soc/codecs/cs35l36.h | 452 ++++++++++ 6 files changed, 2494 insertions(+) create mode 100644 include/sound/cs35l36.h create mode 100644 sound/soc/codecs/cs35l36-tables.c create mode 100644 sound/soc/codecs/cs35l36.c create mode 100644 sound/soc/codecs/cs35l36.h
include/sound/cs35l36.h new file +58 -0
@@ -0,0 +1,58 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* linux/sound/cs35l36.h -- Platform data for CS35L36 +* +* Copyright 2018 Cirrus Logic, Inc. +* +* Author: James Schulman <[email protected]> +* +*/ + +#ifndef __CS35L36_H +#define __CS35L36_H + +/* INT/GPIO pin configuration */ +struct irq_cfg { +bool is_present; +int irq_drv_sel; +int irq_pol; +int irq_gpio_sel; +int irq_out_en; +int irq_src_sel; +}; + +struct vpbr_cfg { +bool is_present; +bool vpbr_en; +int vpbr_thld; +int vpbr_atk_rate; +int vpbr_atk_vol; +int vpbr_max_attn; +int vpbr_wait; +int vpbr_rel_rate; +int vpbr_mute_en; +}; + +struct cs35l36_platform_data { +bool sclk_frc; +bool lrclk_frc; +bool multi_amp_mode; +bool dcm_mode; +int ldm_mode_sel; +bool amp_gain_zc; +bool amp_pcm_inv; +bool pdm_ldm_exit; +bool pdm_ldm_enter; +bool imon_pol_inv; +bool vmon_pol_inv; +int boost_ind; +int bst_vctl; +int bst_vctl_sel; +int bst_ipk; +bool extern_boost; +int temp_warn_thld; +struct vpbr_cfg vpbr_config; +struct irq_cfg irq_config; +}; + +#endif /* __CS35L36_H */
sound/soc/codecs/Kconfig +5 -0
@@ -53,6 +53,7 @@ config SND_SOC_ALL_CODECS select SND_SOC_CS35L33 if I2C select SND_SOC_CS35L34 if I2C select SND_SOC_CS35L35 if I2C + select SND_SOC_CS35L36 if I2C select SND_SOC_CS42L42 if I2C select SND_SOC_CS42L51_I2C if I2C select SND_SOC_CS42L52 if I2C && INPUT
@@ -465,6 +466,10 @@ config SND_SOC_CS35L35 tristate "Cirrus Logic CS35L35 CODEC" depends on I2C +config SND_SOC_CS35L36 + tristate "Cirrus Logic CS35L36 CODEC" + depends on I2C + config SND_SOC_CS42L42 tristate "Cirrus Logic CS42L42 CODEC" depends on I2C
sound/soc/codecs/Makefile +2 -0
@@ -45,6 +45,7 @@ snd-soc-cs35l32-objs := cs35l32.o snd-soc-cs35l33-objs := cs35l33.o snd-soc-cs35l34-objs := cs35l34.o snd-soc-cs35l35-objs := cs35l35.o +snd-soc-cs35l36-objs := cs35l36.o cs35l36-tables.o snd-soc-cs42l42-objs := cs42l42.o snd-soc-cs42l51-objs := cs42l51.o snd-soc-cs42l51-i2c-objs := cs42l51-i2c.o
@@ -310,6 +311,7 @@ obj-$(CONFIG_SND_SOC_CS35L32) += snd-soc-cs35l32.o obj-$(CONFIG_SND_SOC_CS35L33) += snd-soc-cs35l33.o obj-$(CONFIG_SND_SOC_CS35L34) += snd-soc-cs35l34.o obj-$(CONFIG_SND_SOC_CS35L35) += snd-soc-cs35l35.o +obj-$(CONFIG_SND_SOC_CS35L36) += snd-soc-cs35l36.o obj-$(CONFIG_SND_SOC_CS42L42) += snd-soc-cs42l42.o obj-$(CONFIG_SND_SOC_CS42L51) += snd-soc-cs42l51.o obj-$(CONFIG_SND_SOC_CS42L51_I2C) += snd-soc-cs42l51-i2c.o
sound/soc/codecs/cs35l36-tables.c new file +312 -0
312 lines not on this page · raw message
sound/soc/codecs/cs35l36.c new file +1665 -0
1,665 lines not on this page · raw message
sound/soc/codecs/cs35l36.h new file +452 -0
452 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v2 2/2 ASoC: cs35l36: Add device tree documentation for CS35L36
Add device tree documentation for Cirrus Logic CS35L36 speaker amplifier
--- .../devicetree/bindings/sound/cs35l36.txt | 193 +++++++++++++++++++++ 1 file changed, 193 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/cs35l36.txt
Documentation/devicetree/bindings/sound/cs35l36.txt new file +193 -0
@@ -0,0 +1,193 @@ +CS35L36 Speaker Amplifier + +Required properties: + + - compatible : "cirrus,cs35l36" + + - reg : the I2C address of the device for I2C + + - VA-supply, VP-supply : power supplies for the device, + as covered in + Documentation/devicetree/bindings/regulator/regulator.txt. + +Optional properties: + - cirrus,multi-amp-mode : Boolean to determine if there are more than + one amplifier in the system. If more than one it is best to Hi-Z the ASP + port to prevent bus contention on the output signal + + - cirrus,boost-ctl-millivolt : Boost Voltage Value. Configures the boost + converter's output voltage in mV. The range is from 2550mV to 12000mV with + increments of 50mV. + (Default) VP + + - cirrus,boost-ctl-select : Boost conerter control source selection. + Selects the source of the BST_CTL target VBST voltage for the boost + converter to generate. + 0x00 - Control Port Value + 0x01 - Class H Tracking (Default) + 0x10 - MultiDevice Sync Value + + - cirrus,boost-peak-milliamp : Boost-converter peak current limit in mA. + Configures the peak current by monitoring the current through the boost FET. + Range starts at 1600mA and goes to a maximum of 4500mA with increments of + 50mA. + (Default) 4.50 Amps + + - cirrus,boost-ind-nanohenry : Inductor estimation LBST reference value. + Seeds the digital boost converter's inductor estimation block with the initial + inductance value to reference. + + 1000 = 1uH (Default) + 1200 = 1.2uH + + - cirrus,amp-pcm-inv : Boolean to determine Amplifier will invert incoming + PCM data + + - cirrus,imon-pol-inv : Boolean to determine Amplifier will invert the + polarity of outbound IMON feedback data + + - cirrus,vmon-pol-inv : Boolean to determine Amplifier will invert the + polarity of outbound VMON feedback data + + - cirrus,dcm-mode-enable : Boost converter automatic DCM Mode enable. + This enables the digital boost converter to operate in a low power + (Discontinuous Conduction) mode during low loading conditions. + + - cirrus,weak-fet-disable : Boolean : The strength of the output drivers is + reduced when operating in a Weak-FET Drive Mode and must not be used to drive + a large load. + + - cirrus,classh-wk-fet-delay : Weak-FET entry delay. Controls the delay + (in ms) before the Class H algorithm switches to the weak-FET voltage + (after the audio falls and remains below the value specified in WKFET_AMP_THLD). + + 0 = 0ms + 1 = 5ms + 2 = 10ms + 3 = 50ms + 4 = 100ms (Default) + 5 = 200ms + 6 = 500ms + 7 = 1000ms + + - cirrus,classh-weak-fet-thld-millivolt : Weak-FET amplifier drive threshold. + Configures the signal threshold at which the PWM output stage enters + weak-FET operation. The range is 50mV to 700mV in 50mV increments. + + - cirrus,temp-warn-threshold : Amplifier overtemperature warning threshold. + Configures the threshold at which the overtemperature warning condition occurs. + When the threshold is met, the overtemperature warning attenuation is applied + and the TEMP_WARN_EINT interrupt status bit is set. + If TEMP_WARN_MASK = 0, INTb is asserted. + + 0 = 105C + 1 = 115C + 2 = 125C (Default) + 3 = 135C + +Optional properties for the "cirrus,vpbr-config" Sub-node + + - cirrus,vpbr-en : VBST brownout prevention enable. Configures whether the + VBST brownout prevention algorithm is enabled or disabled. + + 0 = VBST brownout prevention disabled (default) + 1 = VBST brownout prevention enabled + + See Section 7.31.1 VPBR Config for configuration options & further details + + - cirrus,vpbr-thld : Initial VPBR threshold. Configures the VP brownout + threshold voltage + + - cirrus,cirrus,vpbr-atk-rate : Attenuation attack step rate. Configures the + amount delay between consecutive volume attenuation steps when a brownout + condition is present and the VP brownout condition is in an attacking state. + + - cirrus,vpbr-atk-vol : VP brownout prevention step size. Configures the VP + brownout prevention attacking attenuation step size when operating in either + digital volume or analog gain modes. + + - cirrus,vpbr-max-attn : Maximum attenuation that the VP brownout prevention + can apply to the audio signal. + + - cirrus,vpbr-wait : Configures the delay time between a brownout condition + no longer being present and the VP brownout prevention entering an attenuation + release state. + + - cirrus,vpbr-rel-rate : Attenuation release step rate. Configures the delay + between consecutive volume attenuation release steps when a brownout condition + is not longer present and the VP brownout is in an attenuation release state. + + - cirrus,vpbr-mute-en : During the attack state, if the vpbr-max-attn value + is reached, the error condition still remains, and this bit is set, the audio + is muted. + +Optional properties for the "cirrus,irq-config" Sub-node + + - cirrus,irq-drive-select : Selects the driver type of the selected interrupt + output. + + 0 = Open-drain + 1 = Push-pull (Default) + + - cirrus,irq-polarity : Selects the polarity of the selected interrupt output + when in push-pull mode. Note - when the selected interrupt output is in + open-drain mode, INT_POL_SEL must be set to 0. + + 0 = Active-low (Default) + 1 = Active-high + + - cirrus,irq-gpio-select : Selects the pin to serve as the programmable + interrupt output. + + 0 = PDM_DATA / SWIRE_SD / INT (Default) + 1 = GPIO + + - cirrus,irq-output-enable : Enables or disables the selected interrupt output + + 0 = Disabled (Default) + 1 = Enabled + + - cirrus,irq-src-select : Selects the source of the selected interrupt output. + + 0 = PAC-based interrupt output + 1 = Interrupt handler (Default) + +Example: + +cs35l36: cs35l36@40 { + compatible = "cirrus,cs35l36"; + reg = <0x40>; + VA-supply = <&dummy_vreg>; + VP-supply = <&dummy_vreg>; + reset-gpios = <&gpio0 54 0>; + interrupt-parent = <&gpio8>; + interrupts = <3 IRQ_TYPE_LEVEL_LOW>; + + cirrus,boost-ind-nanohenry = <1000>; + cirrus,boost-ctl-millivolt = <10000>; + cirrus,boost-ctl-select = <0x00>; + cirrus,boost-peak-milliamp = <4500>; + cirrus,weak-fet-delay = <0x04>; + cirrus,weak-fet-thld = <0x01>; + cirrus,temp-warn-threshold = <0x01>; + cirrus,multi-amp-mode; + + cirrus,vpbr-config { + cirrus,vpbr-en = <0x00>; + cirrus,vpbr-thld = <0x05>; + cirrus,vpbr-atk-rate = <0x02>; + cirrus,vpbr-atk-vol = <0x01>; + cirrus,vpbr-max-attn = <0x09>; + cirrus,vpbr-wait = <0x01>; + cirrus,vpbr-rel-rate = <0x05>; + cirrus,vpbr-mute-en = <0x00>; + }; + + cirrus,irq-config { + cirrus,irq-drive-select = <0x01>; + cirrus,irq-polarity = <0x00>; + cirrus,irq-gpio-select = <0x01>; + cirrus,irq-output-enable = <0x01>; + cirrus,irq-src-select = <0x01>; + }; +};
Signature · 1 line
1.9.1
Re: [PATCH v2 2/2] ASoC: cs35l36: Add device tree documentation for CS35L36
Quoted 10 lines · James Schulman
Add device tree documentation for Cirrus Logic CS35L36 speaker amplifier
Signed-off-by James Schulman <[email protected]>---
Documentation/devicetree/bindings/sound/cs35l36.txt new file +5
-0+Optional properties for the "cirrus,irq-config" Sub-node + + - cirrus,irq-drive-select : Selects the driver type of the selected interrupt + output. +
Documentation/devicetree/bindings/sound/cs35l36.txt line 138
Quoted 10 lines
Documentation/devicetree/bindings/sound/cs35l36.txt new file +10
-0+ 0 = Open-drain + 1 = Push-pull (Default) + + - cirrus,irq-polarity : Selects the polarity of the selected interrupt output + when in push-pull mode. Note - when the selected interrupt output is in + open-drain mode, INT_POL_SEL must be set to 0. + + 0 = Active-low (Default) + 1 = Active-high +
Does this device tree entry in your example:
interrupts = <3 IRQ_TYPE_LEVEL_LOW>;
Not already convey what polarity you require? Adding a separate entry seems unnecessary.
Documentation/devicetree/bindings/sound/cs35l36.txt line 149
Quoted 11 lines
Documentation/devicetree/bindings/sound/cs35l36.txt new file +11
-0+ - cirrus,irq-gpio-select : Selects the pin to serve as the programmable + interrupt output. + + 0 = PDM_DATA / SWIRE_SD / INT (Default) + 1 = GPIO + + - cirrus,irq-output-enable : Enables or disables the selected interrupt output + + 0 = Disabled (Default) + 1 = Enabled +
Likewise here doesn't the presence/absence of the interrupts entry convey whether you want the IRQ enabled?
Documentation/devicetree/bindings/sound/cs35l36.txt line 154
Quoted 5 lines
Documentation/devicetree/bindings/sound/cs35l36.txt new file +5
-0+ - cirrus,irq-src-select : Selects the source of the selected interrupt output. + + 0 = PAC-based interrupt output + 1 = Interrupt handler (Default) +
Is there a use-case for this at the moment? This feels like it might be worth dropping until it is necessary.
Thanks,
Charles
Quoted 5 lines · James Schulman
Add driver support for Cirrus Logic CS35L36 boosted speaker amplifier
Signed-off-by James Schulman <[email protected]>---
Again just a couple of very minor nit picks from me.
Quoted 16 lines
sound/soc/codecs/cs35l36.c new file +16
-0+static int cs35l36_dai_set_sysclk (struct snd_soc_dai *dai,int clk_id, +unsigned int freq,int dir) +{ +struct snd_soc_component *component = dai->component; +struct cs35l36_private *cs35l36 = +snd_soc_component_get_drvdata (component); +int fs1, fs2, reg; + +if (freq >CS35L36_FS_NOM_6MHZ ) { + fs1 =CS35L36_FS1_DEFAULT_VAL ; + fs2 =CS35L36_FS2_DEFAULT_VAL ; + }else { + fs1 =3 * ((CS35L36_FS_NOM_6MHZ *4 + freq -1 ) / freq) +4 ; + fs2 =5 * ((CS35L36_FS_NOM_6MHZ *4 + freq -1 ) / freq) +4 ; + } +
sound/soc/codecs/cs35l36.c line 620
Quoted 10 lines
sound/soc/codecs/cs35l36.c new file +10
-0+regmap_write (cs35l36->regmap,CS35L36_TESTKEY_CTRL , +CS35L36_TEST_UNLOCK1 ); +regmap_write (cs35l36->regmap,CS35L36_TESTKEY_CTRL , +CS35L36_TEST_UNLOCK2 ); + +regmap_read (cs35l36->regmap,CS35L36_TST_FS_MON0 , ®); + reg &= ~(CS35L36_FS1_WINDOW_MASK |CS35L36_FS2_WINDOW_MASK ); + reg |= ((fs1 &CS35L36_FS1_WINDOW_MASK ) | + (fs2 <<CS35L36_FS2_WINDOW_SHIFT &CS35L36_FS2_WINDOW_MASK )); +regmap_write (cs35l36->regmap,CS35L36_TST_FS_MON0 , reg);
This is just open coding update_bits probably better to just use update_bits.
sound/soc/codecs/cs35l36.c
Quoted 10 lines
sound/soc/codecs/cs35l36.c new file +9
-0+ +regmap_write (cs35l36->regmap,CS35L36_TESTKEY_CTRL , +CS35L36_TEST_LOCK1 ); +regmap_write (cs35l36->regmap,CS35L36_TESTKEY_CTRL , +CS35L36_TEST_LOCK2 ); +return 0 ; +} + +typedef char CS35L36_MAX_NUM_REGS [__LINE__];
Not sure I am the greatest fan of this, is it perhaps just worth combining the tables file and the regular file? Then you don't need any fancyness.
Thanks,
Charles
Quoted 30 lines · Charles Keepax
Quoted 5 lines · James Schulman
Add driver support for Cirrus Logic CS35L36 boosted speaker amplifier
Signed-off-by James Schulman <[email protected]>---
Again just a couple of very minor nit picks from me.
Quoted 21 lines
sound/soc/codecs/cs35l36.c new file +21
-0+static int cs35l36_dai_set_sysclk (struct snd_soc_dai *dai,int clk_id, +unsigned int freq,int dir) +{ +struct snd_soc_component *component = dai->component; +struct cs35l36_private *cs35l36 = +snd_soc_component_get_drvdata (component); +int fs1, fs2, reg; + +if (freq >CS35L36_FS_NOM_6MHZ ) { + fs1 =CS35L36_FS1_DEFAULT_VAL ; + fs2 =CS35L36_FS2_DEFAULT_VAL ; + }else { + fs1 =3 * ((CS35L36_FS_NOM_6MHZ *4 + freq -1 ) / freq) +4 ; + fs2 =5 * ((CS35L36_FS_NOM_6MHZ *4 + freq -1 ) / freq) +4 ; + } + +regmap_write (cs35l36->regmap,CS35L36_TESTKEY_CTRL , +CS35L36_TEST_UNLOCK1 ); +regmap_write (cs35l36->regmap,CS35L36_TESTKEY_CTRL , +CS35L36_TEST_UNLOCK2 ); +
Quoted 9 lines
sound/soc/codecs/cs35l36.c line 620
Quoted 5 lines
sound/soc/codecs/cs35l36.c new file +5
-0+regmap_read (cs35l36->regmap,CS35L36_TST_FS_MON0 , ®); + reg &= ~(CS35L36_FS1_WINDOW_MASK |CS35L36_FS2_WINDOW_MASK ); + reg |= ((fs1 &CS35L36_FS1_WINDOW_MASK ) | + (fs2 <<CS35L36_FS2_WINDOW_SHIFT &CS35L36_FS2_WINDOW_MASK )); +regmap_write (cs35l36->regmap,CS35L36_TST_FS_MON0 , reg);This is just open coding
update_bitsprobably better to just useupdate_bits.
I did this because it's a register that we didn't want to be visible in userspace, but now I realize that just means it's precious. Will add it to the precious register list and resubmit.
Quoted 9 lines
Quoted 8 lines
sound/soc/codecs/cs35l36.c new file +8
-0+ +regmap_write (cs35l36->regmap,CS35L36_TESTKEY_CTRL , +CS35L36_TEST_LOCK1 ); +regmap_write (cs35l36->regmap,CS35L36_TESTKEY_CTRL , +CS35L36_TEST_LOCK2 ); +return 0 ; +} +
Quoted 6 lines
Quoted 1 line
+typedef char CS35L36_MAX_NUM_REGS[__LINE__];
Not sure I am the greatest fan of this, is it perhaps just worth combining the tables file and the regular file? Then you don't need any fancyness.
Ya it's probably not worth trying to get fancy... I'll just nuke the tables file.
Quoted 3 lines
Thanks,
Charles