sgtl5000.c (60e9eabf41fa916d2ef68c5bf929197975917578) sgtl5000.c (54b5927067dd79b58032a4938ee13b233f1a368c)
1// SPDX-License-Identifier: GPL-2.0
2//
3// sgtl5000.c -- SGTL5000 ALSA SoC Audio driver
4//
5// Copyright 2010-2011 Freescale Semiconductor, Inc. All Rights Reserved.
6
7#include <linux/module.h>
8#include <linux/moduleparam.h>

--- 142 unchanged lines hidden (view full) ---

151 u8 micbias_voltage;
152 u8 lrclk_strength;
153 u8 sclk_strength;
154 u16 mute_state[LAST_POWER_EVENT + 1];
155};
156
157static inline int hp_sel_input(struct snd_soc_component *component)
158{
1// SPDX-License-Identifier: GPL-2.0
2//
3// sgtl5000.c -- SGTL5000 ALSA SoC Audio driver
4//
5// Copyright 2010-2011 Freescale Semiconductor, Inc. All Rights Reserved.
6
7#include <linux/module.h>
8#include <linux/moduleparam.h>

--- 142 unchanged lines hidden (view full) ---

151 u8 micbias_voltage;
152 u8 lrclk_strength;
153 u8 sclk_strength;
154 u16 mute_state[LAST_POWER_EVENT + 1];
155};
156
157static inline int hp_sel_input(struct snd_soc_component *component)
158{
159 return (snd_soc_component_read32(component, SGTL5000_CHIP_ANA_CTRL) &
159 return (snd_soc_component_read(component, SGTL5000_CHIP_ANA_CTRL) &
160 SGTL5000_HP_SEL_MASK) >> SGTL5000_HP_SEL_SHIFT;
161}
162
163static inline u16 mute_output(struct snd_soc_component *component,
164 u16 mute_mask)
165{
160 SGTL5000_HP_SEL_MASK) >> SGTL5000_HP_SEL_SHIFT;
161}
162
163static inline u16 mute_output(struct snd_soc_component *component,
164 u16 mute_mask)
165{
166 u16 mute_reg = snd_soc_component_read32(component,
166 u16 mute_reg = snd_soc_component_read(component,
167 SGTL5000_CHIP_ANA_CTRL);
168
169 snd_soc_component_update_bits(component, SGTL5000_CHIP_ANA_CTRL,
170 mute_mask, mute_mask);
171 return mute_reg;
172}
173
174static inline void restore_output(struct snd_soc_component *component,
175 u16 mute_mask, u16 mute_reg)
176{
177 snd_soc_component_update_bits(component, SGTL5000_CHIP_ANA_CTRL,
178 mute_mask, mute_reg);
179}
180
181static void vag_power_on(struct snd_soc_component *component, u32 source)
182{
167 SGTL5000_CHIP_ANA_CTRL);
168
169 snd_soc_component_update_bits(component, SGTL5000_CHIP_ANA_CTRL,
170 mute_mask, mute_mask);
171 return mute_reg;
172}
173
174static inline void restore_output(struct snd_soc_component *component,
175 u16 mute_mask, u16 mute_reg)
176{
177 snd_soc_component_update_bits(component, SGTL5000_CHIP_ANA_CTRL,
178 mute_mask, mute_reg);
179}
180
181static void vag_power_on(struct snd_soc_component *component, u32 source)
182{
183 if (snd_soc_component_read32(component, SGTL5000_CHIP_ANA_POWER) &
183 if (snd_soc_component_read(component, SGTL5000_CHIP_ANA_POWER) &
184 SGTL5000_VAG_POWERUP)
185 return;
186
187 snd_soc_component_update_bits(component, SGTL5000_CHIP_ANA_POWER,
188 SGTL5000_VAG_POWERUP, SGTL5000_VAG_POWERUP);
189
190 /* When VAG powering on to get local loop from Line-In, the sleep
191 * is required to avoid loud pop.

--- 28 unchanged lines hidden (view full) ---

220 consumers++;
221 }
222
223 return consumers;
224}
225
226static void vag_power_off(struct snd_soc_component *component, u32 source)
227{
184 SGTL5000_VAG_POWERUP)
185 return;
186
187 snd_soc_component_update_bits(component, SGTL5000_CHIP_ANA_POWER,
188 SGTL5000_VAG_POWERUP, SGTL5000_VAG_POWERUP);
189
190 /* When VAG powering on to get local loop from Line-In, the sleep
191 * is required to avoid loud pop.

--- 28 unchanged lines hidden (view full) ---

220 consumers++;
221 }
222
223 return consumers;
224}
225
226static void vag_power_off(struct snd_soc_component *component, u32 source)
227{
228 u16 ana_pwr = snd_soc_component_read32(component,
228 u16 ana_pwr = snd_soc_component_read(component,
229 SGTL5000_CHIP_ANA_POWER);
230
231 if (!(ana_pwr & SGTL5000_VAG_POWERUP))
232 return;
233
234 /*
235 * This function calls when any of VAG power consumers is disappearing.
236 * Thus, if there is more than one consumer at the moment, as minimum

--- 303 unchanged lines hidden (view full) ---

540static int dac_get_volsw(struct snd_kcontrol *kcontrol,
541 struct snd_ctl_elem_value *ucontrol)
542{
543 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
544 int reg;
545 int l;
546 int r;
547
229 SGTL5000_CHIP_ANA_POWER);
230
231 if (!(ana_pwr & SGTL5000_VAG_POWERUP))
232 return;
233
234 /*
235 * This function calls when any of VAG power consumers is disappearing.
236 * Thus, if there is more than one consumer at the moment, as minimum

--- 303 unchanged lines hidden (view full) ---

540static int dac_get_volsw(struct snd_kcontrol *kcontrol,
541 struct snd_ctl_elem_value *ucontrol)
542{
543 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
544 int reg;
545 int l;
546 int r;
547
548 reg = snd_soc_component_read32(component, SGTL5000_CHIP_DAC_VOL);
548 reg = snd_soc_component_read(component, SGTL5000_CHIP_DAC_VOL);
549
550 /* get left channel volume */
551 l = (reg & SGTL5000_DAC_VOL_LEFT_MASK) >> SGTL5000_DAC_VOL_LEFT_SHIFT;
552
553 /* get right channel volume */
554 r = (reg & SGTL5000_DAC_VOL_RIGHT_MASK) >> SGTL5000_DAC_VOL_RIGHT_SHIFT;
555
556 /* make sure value fall in (0x3c,0xfc) */

--- 71 unchanged lines hidden (view full) ---

628 * As this calculation is expensive and the threshold dB values may not exceed
629 * 0 to 96 we use pre-calculated values.
630 */
631static int avc_get_threshold(struct snd_kcontrol *kcontrol,
632 struct snd_ctl_elem_value *ucontrol)
633{
634 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
635 int db, i;
549
550 /* get left channel volume */
551 l = (reg & SGTL5000_DAC_VOL_LEFT_MASK) >> SGTL5000_DAC_VOL_LEFT_SHIFT;
552
553 /* get right channel volume */
554 r = (reg & SGTL5000_DAC_VOL_RIGHT_MASK) >> SGTL5000_DAC_VOL_RIGHT_SHIFT;
555
556 /* make sure value fall in (0x3c,0xfc) */

--- 71 unchanged lines hidden (view full) ---

628 * As this calculation is expensive and the threshold dB values may not exceed
629 * 0 to 96 we use pre-calculated values.
630 */
631static int avc_get_threshold(struct snd_kcontrol *kcontrol,
632 struct snd_ctl_elem_value *ucontrol)
633{
634 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
635 int db, i;
636 u16 reg = snd_soc_component_read32(component, SGTL5000_DAP_AVC_THRESHOLD);
636 u16 reg = snd_soc_component_read(component, SGTL5000_DAP_AVC_THRESHOLD);
637
638 /* register value 0 => -96dB */
639 if (!reg) {
640 ucontrol->value.integer.value[0] = 96;
641 ucontrol->value.integer.value[1] = 96;
642 return 0;
643 }
644

--- 125 unchanged lines hidden (view full) ---

770 SOC_SINGLE_TLV("BASS 3", SGTL5000_DAP_EQ_BASS_BAND3,
771 0, 0x5F, 0, bass_band),
772
773 SOC_SINGLE_TLV("BASS 4", SGTL5000_DAP_EQ_BASS_BAND4,
774 0, 0x5F, 0, bass_band),
775};
776
777/* mute the codec used by alsa core */
637
638 /* register value 0 => -96dB */
639 if (!reg) {
640 ucontrol->value.integer.value[0] = 96;
641 ucontrol->value.integer.value[1] = 96;
642 return 0;
643 }
644

--- 125 unchanged lines hidden (view full) ---

770 SOC_SINGLE_TLV("BASS 3", SGTL5000_DAP_EQ_BASS_BAND3,
771 0, 0x5F, 0, bass_band),
772
773 SOC_SINGLE_TLV("BASS 4", SGTL5000_DAP_EQ_BASS_BAND4,
774 0, 0x5F, 0, bass_band),
775};
776
777/* mute the codec used by alsa core */
778static int sgtl5000_digital_mute(struct snd_soc_dai *codec_dai, int mute)
778static int sgtl5000_mute_stream(struct snd_soc_dai *codec_dai, int mute, int direction)
779{
780 struct snd_soc_component *component = codec_dai->component;
781 u16 i2s_pwr = SGTL5000_I2S_IN_POWERUP;
782
783 /*
784 * During 'digital mute' do not mute DAC
785 * because LINE_IN would be muted aswell. We want to mute
786 * only I2S block - this can be done by powering it off

--- 368 unchanged lines hidden (view full) ---

1155
1156#define SGTL5000_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
1157 SNDRV_PCM_FMTBIT_S20_3LE |\
1158 SNDRV_PCM_FMTBIT_S24_LE |\
1159 SNDRV_PCM_FMTBIT_S32_LE)
1160
1161static const struct snd_soc_dai_ops sgtl5000_ops = {
1162 .hw_params = sgtl5000_pcm_hw_params,
779{
780 struct snd_soc_component *component = codec_dai->component;
781 u16 i2s_pwr = SGTL5000_I2S_IN_POWERUP;
782
783 /*
784 * During 'digital mute' do not mute DAC
785 * because LINE_IN would be muted aswell. We want to mute
786 * only I2S block - this can be done by powering it off

--- 368 unchanged lines hidden (view full) ---

1155
1156#define SGTL5000_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
1157 SNDRV_PCM_FMTBIT_S20_3LE |\
1158 SNDRV_PCM_FMTBIT_S24_LE |\
1159 SNDRV_PCM_FMTBIT_S32_LE)
1160
1161static const struct snd_soc_dai_ops sgtl5000_ops = {
1162 .hw_params = sgtl5000_pcm_hw_params,
1163 .digital_mute = sgtl5000_digital_mute,
1163 .mute_stream = sgtl5000_mute_stream,
1164 .set_fmt = sgtl5000_set_dai_fmt,
1165 .set_sysclk = sgtl5000_set_dai_sysclk,
1164 .set_fmt = sgtl5000_set_dai_fmt,
1165 .set_sysclk = sgtl5000_set_dai_sysclk,
1166 .no_capture_mute = 1,
1166};
1167
1168static struct snd_soc_dai_driver sgtl5000_dai = {
1169 .name = "sgtl5000",
1170 .playback = {
1171 .stream_name = "Playback",
1172 .channels_min = 1,
1173 .channels_max = 2,

--- 146 unchanged lines hidden (view full) ---

1320 dev_err(component->dev,
1321 "exceed max voltage vdda %dmV vddio %dmV vddd %dmV\n",
1322 vdda, vddio, vddd);
1323
1324 return -EINVAL;
1325 }
1326
1327 /* reset value */
1167};
1168
1169static struct snd_soc_dai_driver sgtl5000_dai = {
1170 .name = "sgtl5000",
1171 .playback = {
1172 .stream_name = "Playback",
1173 .channels_min = 1,
1174 .channels_max = 2,

--- 146 unchanged lines hidden (view full) ---

1321 dev_err(component->dev,
1322 "exceed max voltage vdda %dmV vddio %dmV vddd %dmV\n",
1323 vdda, vddio, vddd);
1324
1325 return -EINVAL;
1326 }
1327
1328 /* reset value */
1328 ana_pwr = snd_soc_component_read32(component, SGTL5000_CHIP_ANA_POWER);
1329 ana_pwr = snd_soc_component_read(component, SGTL5000_CHIP_ANA_POWER);
1329 ana_pwr |= SGTL5000_DAC_STEREO |
1330 SGTL5000_ADC_STEREO |
1331 SGTL5000_REFTOP_POWERUP;
1330 ana_pwr |= SGTL5000_DAC_STEREO |
1331 SGTL5000_ADC_STEREO |
1332 SGTL5000_REFTOP_POWERUP;
1332 lreg_ctrl = snd_soc_component_read32(component, SGTL5000_CHIP_LINREG_CTRL);
1333 lreg_ctrl = snd_soc_component_read(component, SGTL5000_CHIP_LINREG_CTRL);
1333
1334 if (vddio < 3100 && vdda < 3100) {
1335 /* enable internal oscillator used for charge pump */
1336 snd_soc_component_update_bits(component, SGTL5000_CHIP_CLK_TOP_CTRL,
1337 SGTL5000_INT_OSC_EN,
1338 SGTL5000_INT_OSC_EN);
1339 /* Enable VDDC charge pump */
1340 ana_pwr |= SGTL5000_VDDC_CHRGPMP_POWERUP;

--- 493 unchanged lines hidden ---
1334
1335 if (vddio < 3100 && vdda < 3100) {
1336 /* enable internal oscillator used for charge pump */
1337 snd_soc_component_update_bits(component, SGTL5000_CHIP_CLK_TOP_CTRL,
1338 SGTL5000_INT_OSC_EN,
1339 SGTL5000_INT_OSC_EN);
1340 /* Enable VDDC charge pump */
1341 ana_pwr |= SGTL5000_VDDC_CHRGPMP_POWERUP;

--- 493 unchanged lines hidden ---