hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/sound/soc/codecs/sgtl5000.c
....@@ -123,6 +123,13 @@
123123 I2S_LRCLK_STRENGTH_HIGH,
124124 };
125125
126
+enum {
127
+ I2S_SCLK_STRENGTH_DISABLE,
128
+ I2S_SCLK_STRENGTH_LOW,
129
+ I2S_SCLK_STRENGTH_MEDIUM,
130
+ I2S_SCLK_STRENGTH_HIGH,
131
+};
132
+
126133 enum {
127134 HP_POWER_EVENT,
128135 DAC_POWER_EVENT,
....@@ -143,19 +150,20 @@
143150 u8 micbias_resistor;
144151 u8 micbias_voltage;
145152 u8 lrclk_strength;
153
+ u8 sclk_strength;
146154 u16 mute_state[LAST_POWER_EVENT + 1];
147155 };
148156
149157 static inline int hp_sel_input(struct snd_soc_component *component)
150158 {
151
- return (snd_soc_component_read32(component, SGTL5000_CHIP_ANA_CTRL) &
159
+ return (snd_soc_component_read(component, SGTL5000_CHIP_ANA_CTRL) &
152160 SGTL5000_HP_SEL_MASK) >> SGTL5000_HP_SEL_SHIFT;
153161 }
154162
155163 static inline u16 mute_output(struct snd_soc_component *component,
156164 u16 mute_mask)
157165 {
158
- u16 mute_reg = snd_soc_component_read32(component,
166
+ u16 mute_reg = snd_soc_component_read(component,
159167 SGTL5000_CHIP_ANA_CTRL);
160168
161169 snd_soc_component_update_bits(component, SGTL5000_CHIP_ANA_CTRL,
....@@ -172,7 +180,7 @@
172180
173181 static void vag_power_on(struct snd_soc_component *component, u32 source)
174182 {
175
- if (snd_soc_component_read32(component, SGTL5000_CHIP_ANA_POWER) &
183
+ if (snd_soc_component_read(component, SGTL5000_CHIP_ANA_POWER) &
176184 SGTL5000_VAG_POWERUP)
177185 return;
178186
....@@ -217,7 +225,7 @@
217225
218226 static void vag_power_off(struct snd_soc_component *component, u32 source)
219227 {
220
- u16 ana_pwr = snd_soc_component_read32(component,
228
+ u16 ana_pwr = snd_soc_component_read(component,
221229 SGTL5000_CHIP_ANA_POWER);
222230
223231 if (!(ana_pwr & SGTL5000_VAG_POWERUP))
....@@ -537,7 +545,7 @@
537545 int l;
538546 int r;
539547
540
- reg = snd_soc_component_read32(component, SGTL5000_CHIP_DAC_VOL);
548
+ reg = snd_soc_component_read(component, SGTL5000_CHIP_DAC_VOL);
541549
542550 /* get left channel volume */
543551 l = (reg & SGTL5000_DAC_VOL_LEFT_MASK) >> SGTL5000_DAC_VOL_LEFT_SHIFT;
....@@ -625,7 +633,7 @@
625633 {
626634 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
627635 int db, i;
628
- u16 reg = snd_soc_component_read32(component, SGTL5000_DAP_AVC_THRESHOLD);
636
+ u16 reg = snd_soc_component_read(component, SGTL5000_DAP_AVC_THRESHOLD);
629637
630638 /* register value 0 => -96dB */
631639 if (!reg) {
....@@ -712,6 +720,7 @@
712720 SGTL5000_CHIP_ANA_ADC_CTRL,
713721 8, 1, 0, capture_6db_attenuate),
714722 SOC_SINGLE("Capture ZC Switch", SGTL5000_CHIP_ANA_CTRL, 1, 1, 0),
723
+ SOC_SINGLE("Capture Switch", SGTL5000_CHIP_ANA_CTRL, 0, 1, 1),
715724
716725 SOC_DOUBLE_TLV("Headphone Playback Volume",
717726 SGTL5000_CHIP_ANA_HP_CTRL,
....@@ -766,7 +775,7 @@
766775 };
767776
768777 /* mute the codec used by alsa core */
769
-static int sgtl5000_digital_mute(struct snd_soc_dai *codec_dai, int mute)
778
+static int sgtl5000_mute_stream(struct snd_soc_dai *codec_dai, int mute, int direction)
770779 {
771780 struct snd_soc_component *component = codec_dai->component;
772781 u16 i2s_pwr = SGTL5000_I2S_IN_POWERUP;
....@@ -1151,9 +1160,10 @@
11511160
11521161 static const struct snd_soc_dai_ops sgtl5000_ops = {
11531162 .hw_params = sgtl5000_pcm_hw_params,
1154
- .digital_mute = sgtl5000_digital_mute,
1163
+ .mute_stream = sgtl5000_mute_stream,
11551164 .set_fmt = sgtl5000_set_dai_fmt,
11561165 .set_sysclk = sgtl5000_set_dai_sysclk,
1166
+ .no_capture_mute = 1,
11571167 };
11581168
11591169 static struct snd_soc_dai_driver sgtl5000_dai = {
....@@ -1316,11 +1326,11 @@
13161326 }
13171327
13181328 /* reset value */
1319
- ana_pwr = snd_soc_component_read32(component, SGTL5000_CHIP_ANA_POWER);
1329
+ ana_pwr = snd_soc_component_read(component, SGTL5000_CHIP_ANA_POWER);
13201330 ana_pwr |= SGTL5000_DAC_STEREO |
13211331 SGTL5000_ADC_STEREO |
13221332 SGTL5000_REFTOP_POWERUP;
1323
- lreg_ctrl = snd_soc_component_read32(component, SGTL5000_CHIP_LINREG_CTRL);
1333
+ lreg_ctrl = snd_soc_component_read(component, SGTL5000_CHIP_LINREG_CTRL);
13241334
13251335 if (vddio < 3100 && vdda < 3100) {
13261336 /* enable internal oscillator used for charge pump */
....@@ -1335,7 +1345,8 @@
13351345 * if vddio == vdda the source of charge pump should be
13361346 * assigned manually to VDDIO
13371347 */
1338
- if (vddio == vdda) {
1348
+ if (regulator_is_equal(sgtl5000->supplies[VDDA].consumer,
1349
+ sgtl5000->supplies[VDDIO].consumer)) {
13391350 lreg_ctrl |= SGTL5000_VDDC_ASSN_OVRD;
13401351 lreg_ctrl |= SGTL5000_VDDC_MAN_ASSN_VDDIO <<
13411352 SGTL5000_VDDC_MAN_ASSN_SHIFT;
....@@ -1458,7 +1469,7 @@
14581469
14591470 /* enable small pop, introduce 400ms delay in turning off */
14601471 snd_soc_component_update_bits(component, SGTL5000_CHIP_REF_CTRL,
1461
- SGTL5000_SMALL_POP, 1);
1472
+ SGTL5000_SMALL_POP, SGTL5000_SMALL_POP);
14621473
14631474 /* disable short cut detector */
14641475 snd_soc_component_write(component, SGTL5000_CHIP_SHORT_CTRL, 0);
....@@ -1472,7 +1483,9 @@
14721483 SGTL5000_DAC_MUTE_RIGHT |
14731484 SGTL5000_DAC_MUTE_LEFT);
14741485
1475
- reg = ((sgtl5000->lrclk_strength) << SGTL5000_PAD_I2S_LRCLK_SHIFT | 0x5f);
1486
+ reg = ((sgtl5000->lrclk_strength) << SGTL5000_PAD_I2S_LRCLK_SHIFT |
1487
+ (sgtl5000->sclk_strength) << SGTL5000_PAD_I2S_SCLK_SHIFT |
1488
+ 0x1f);
14761489 snd_soc_component_write(component, SGTL5000_CHIP_PAD_STRENGTH, reg);
14771490
14781491 snd_soc_component_update_bits(component, SGTL5000_CHIP_ANA_CTRL,
....@@ -1502,6 +1515,13 @@
15021515 return ret;
15031516 }
15041517
1518
+static int sgtl5000_of_xlate_dai_id(struct snd_soc_component *component,
1519
+ struct device_node *endpoint)
1520
+{
1521
+ /* return dai id 0, whatever the endpoint index */
1522
+ return 0;
1523
+}
1524
+
15051525 static const struct snd_soc_component_driver sgtl5000_driver = {
15061526 .probe = sgtl5000_probe,
15071527 .set_bias_level = sgtl5000_set_bias_level,
....@@ -1511,6 +1531,7 @@
15111531 .num_dapm_widgets = ARRAY_SIZE(sgtl5000_dapm_widgets),
15121532 .dapm_routes = sgtl5000_dapm_routes,
15131533 .num_dapm_routes = ARRAY_SIZE(sgtl5000_dapm_routes),
1534
+ .of_xlate_dai_id = sgtl5000_of_xlate_dai_id,
15141535 .suspend_bias_off = 1,
15151536 .idle_bias_on = 1,
15161537 .use_pmdown_time = 1,
....@@ -1745,6 +1766,13 @@
17451766 sgtl5000->lrclk_strength = value;
17461767 }
17471768
1769
+ sgtl5000->sclk_strength = I2S_SCLK_STRENGTH_LOW;
1770
+ if (!of_property_read_u32(np, "sclk-strength", &value)) {
1771
+ if (value > I2S_SCLK_STRENGTH_HIGH)
1772
+ value = I2S_SCLK_STRENGTH_LOW;
1773
+ sgtl5000->sclk_strength = value;
1774
+ }
1775
+
17481776 /* Ensure sgtl5000 will start with sane register values */
17491777 sgtl5000_fill_defaults(client);
17501778
....@@ -1769,11 +1797,20 @@
17691797 {
17701798 struct sgtl5000_priv *sgtl5000 = i2c_get_clientdata(client);
17711799
1800
+ regmap_write(sgtl5000->regmap, SGTL5000_CHIP_CLK_CTRL, SGTL5000_CHIP_CLK_CTRL_DEFAULT);
1801
+ regmap_write(sgtl5000->regmap, SGTL5000_CHIP_DIG_POWER, SGTL5000_DIG_POWER_DEFAULT);
1802
+ regmap_write(sgtl5000->regmap, SGTL5000_CHIP_ANA_POWER, SGTL5000_ANA_POWER_DEFAULT);
1803
+
17721804 clk_disable_unprepare(sgtl5000->mclk);
17731805 regulator_bulk_disable(sgtl5000->num_supplies, sgtl5000->supplies);
17741806 regulator_bulk_free(sgtl5000->num_supplies, sgtl5000->supplies);
17751807
17761808 return 0;
1809
+}
1810
+
1811
+static void sgtl5000_i2c_shutdown(struct i2c_client *client)
1812
+{
1813
+ sgtl5000_i2c_remove(client);
17771814 }
17781815
17791816 static const struct i2c_device_id sgtl5000_id[] = {
....@@ -1796,6 +1833,7 @@
17961833 },
17971834 .probe = sgtl5000_i2c_probe,
17981835 .remove = sgtl5000_i2c_remove,
1836
+ .shutdown = sgtl5000_i2c_shutdown,
17991837 .id_table = sgtl5000_id,
18001838 };
18011839