apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 1 | /* |
| 2 | * cs42l51.c |
| 3 | * |
| 4 | * ASoC Driver for Cirrus Logic CS42L51 codecs |
| 5 | * |
| 6 | * Copyright (c) 2010 Arnaud Patard <apatard@mandriva.com> |
| 7 | * |
| 8 | * Based on cs4270.c - Copyright (c) Freescale Semiconductor |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License version 2 as |
| 12 | * published by the Free Software Foundation. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * For now: |
| 20 | * - Only I2C is support. Not SPI |
| 21 | * - master mode *NOT* supported |
| 22 | */ |
| 23 | |
Olivier Moysan | 318e741 | 2018-10-19 17:56:35 +0200 | [diff] [blame] | 24 | #include <linux/clk.h> |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 25 | #include <linux/module.h> |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 26 | #include <linux/slab.h> |
| 27 | #include <sound/core.h> |
| 28 | #include <sound/soc.h> |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 29 | #include <sound/tlv.h> |
| 30 | #include <sound/initval.h> |
| 31 | #include <sound/pcm_params.h> |
| 32 | #include <sound/pcm.h> |
Olivier Moysan | 11b9cd7 | 2019-04-03 15:23:33 +0200 | [diff] [blame^] | 33 | #include <linux/gpio/consumer.h> |
Mark Brown | da07148 | 2014-02-11 19:24:31 +0000 | [diff] [blame] | 34 | #include <linux/regmap.h> |
Olivier Moysan | f77b6ea | 2019-04-03 15:23:32 +0200 | [diff] [blame] | 35 | #include <linux/regulator/consumer.h> |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 36 | |
| 37 | #include "cs42l51.h" |
| 38 | |
| 39 | enum master_slave_mode { |
| 40 | MODE_SLAVE, |
| 41 | MODE_SLAVE_AUTO, |
| 42 | MODE_MASTER, |
| 43 | }; |
| 44 | |
Olivier Moysan | f77b6ea | 2019-04-03 15:23:32 +0200 | [diff] [blame] | 45 | static const char * const cs42l51_supply_names[] = { |
| 46 | "VL", |
| 47 | "VD", |
| 48 | "VA", |
| 49 | "VAHP", |
| 50 | }; |
| 51 | |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 52 | struct cs42l51_private { |
| 53 | unsigned int mclk; |
Olivier Moysan | 318e741 | 2018-10-19 17:56:35 +0200 | [diff] [blame] | 54 | struct clk *mclk_handle; |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 55 | unsigned int audio_mode; /* The mode (I2S or left-justified) */ |
| 56 | enum master_slave_mode func; |
Olivier Moysan | f77b6ea | 2019-04-03 15:23:32 +0200 | [diff] [blame] | 57 | struct regulator_bulk_data supplies[ARRAY_SIZE(cs42l51_supply_names)]; |
Olivier Moysan | 11b9cd7 | 2019-04-03 15:23:33 +0200 | [diff] [blame^] | 58 | struct gpio_desc *reset_gpio; |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 59 | }; |
| 60 | |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 61 | #define CS42L51_FORMATS ( \ |
| 62 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE | \ |
| 63 | SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE | \ |
| 64 | SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE | \ |
| 65 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE) |
| 66 | |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 67 | static int cs42l51_get_chan_mix(struct snd_kcontrol *kcontrol, |
| 68 | struct snd_ctl_elem_value *ucontrol) |
| 69 | { |
Kuninori Morimoto | 1fa4985 | 2018-01-29 03:59:02 +0000 | [diff] [blame] | 70 | struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); |
| 71 | unsigned long value = snd_soc_component_read32(component, CS42L51_PCM_MIXER)&3; |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 72 | |
| 73 | switch (value) { |
| 74 | default: |
| 75 | case 0: |
Takashi Iwai | 89300b4 | 2016-02-29 18:02:59 +0100 | [diff] [blame] | 76 | ucontrol->value.enumerated.item[0] = 0; |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 77 | break; |
| 78 | /* same value : (L+R)/2 and (R+L)/2 */ |
| 79 | case 1: |
| 80 | case 2: |
Takashi Iwai | 89300b4 | 2016-02-29 18:02:59 +0100 | [diff] [blame] | 81 | ucontrol->value.enumerated.item[0] = 1; |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 82 | break; |
| 83 | case 3: |
Takashi Iwai | 89300b4 | 2016-02-29 18:02:59 +0100 | [diff] [blame] | 84 | ucontrol->value.enumerated.item[0] = 2; |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 85 | break; |
| 86 | } |
| 87 | |
| 88 | return 0; |
| 89 | } |
| 90 | |
| 91 | #define CHAN_MIX_NORMAL 0x00 |
| 92 | #define CHAN_MIX_BOTH 0x55 |
| 93 | #define CHAN_MIX_SWAP 0xFF |
| 94 | |
| 95 | static int cs42l51_set_chan_mix(struct snd_kcontrol *kcontrol, |
| 96 | struct snd_ctl_elem_value *ucontrol) |
| 97 | { |
Kuninori Morimoto | 1fa4985 | 2018-01-29 03:59:02 +0000 | [diff] [blame] | 98 | struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 99 | unsigned char val; |
| 100 | |
Takashi Iwai | 89300b4 | 2016-02-29 18:02:59 +0100 | [diff] [blame] | 101 | switch (ucontrol->value.enumerated.item[0]) { |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 102 | default: |
| 103 | case 0: |
| 104 | val = CHAN_MIX_NORMAL; |
| 105 | break; |
| 106 | case 1: |
| 107 | val = CHAN_MIX_BOTH; |
| 108 | break; |
| 109 | case 2: |
| 110 | val = CHAN_MIX_SWAP; |
| 111 | break; |
| 112 | } |
| 113 | |
Kuninori Morimoto | 1fa4985 | 2018-01-29 03:59:02 +0000 | [diff] [blame] | 114 | snd_soc_component_write(component, CS42L51_PCM_MIXER, val); |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 115 | |
| 116 | return 1; |
| 117 | } |
| 118 | |
| 119 | static const DECLARE_TLV_DB_SCALE(adc_pcm_tlv, -5150, 50, 0); |
| 120 | static const DECLARE_TLV_DB_SCALE(tone_tlv, -1050, 150, 0); |
Brian Austin | 7272e05 | 2014-03-19 10:40:02 -0500 | [diff] [blame] | 121 | |
| 122 | static const DECLARE_TLV_DB_SCALE(aout_tlv, -10200, 50, 0); |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 123 | |
| 124 | static const DECLARE_TLV_DB_SCALE(boost_tlv, 1600, 1600, 0); |
| 125 | static const char *chan_mix[] = { |
| 126 | "L R", |
| 127 | "L+R", |
| 128 | "R L", |
| 129 | }; |
| 130 | |
Takashi Iwai | 6109ab2 | 2014-02-18 10:44:57 +0100 | [diff] [blame] | 131 | static SOC_ENUM_SINGLE_EXT_DECL(cs42l51_chan_mix, chan_mix); |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 132 | |
| 133 | static const struct snd_kcontrol_new cs42l51_snd_controls[] = { |
| 134 | SOC_DOUBLE_R_SX_TLV("PCM Playback Volume", |
| 135 | CS42L51_PCMA_VOL, CS42L51_PCMB_VOL, |
Brian Austin | 7272e05 | 2014-03-19 10:40:02 -0500 | [diff] [blame] | 136 | 0, 0x19, 0x7F, adc_pcm_tlv), |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 137 | SOC_DOUBLE_R("PCM Playback Switch", |
| 138 | CS42L51_PCMA_VOL, CS42L51_PCMB_VOL, 7, 1, 1), |
| 139 | SOC_DOUBLE_R_SX_TLV("Analog Playback Volume", |
| 140 | CS42L51_AOUTA_VOL, CS42L51_AOUTB_VOL, |
Brian Austin | 1d99f24 | 2012-03-30 10:43:55 -0500 | [diff] [blame] | 141 | 0, 0x34, 0xE4, aout_tlv), |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 142 | SOC_DOUBLE_R_SX_TLV("ADC Mixer Volume", |
| 143 | CS42L51_ADCA_VOL, CS42L51_ADCB_VOL, |
Brian Austin | 7272e05 | 2014-03-19 10:40:02 -0500 | [diff] [blame] | 144 | 0, 0x19, 0x7F, adc_pcm_tlv), |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 145 | SOC_DOUBLE_R("ADC Mixer Switch", |
| 146 | CS42L51_ADCA_VOL, CS42L51_ADCB_VOL, 7, 1, 1), |
| 147 | SOC_SINGLE("Playback Deemphasis Switch", CS42L51_DAC_CTL, 3, 1, 0), |
| 148 | SOC_SINGLE("Auto-Mute Switch", CS42L51_DAC_CTL, 2, 1, 0), |
| 149 | SOC_SINGLE("Soft Ramp Switch", CS42L51_DAC_CTL, 1, 1, 0), |
| 150 | SOC_SINGLE("Zero Cross Switch", CS42L51_DAC_CTL, 0, 0, 0), |
| 151 | SOC_DOUBLE_TLV("Mic Boost Volume", |
| 152 | CS42L51_MIC_CTL, 0, 1, 1, 0, boost_tlv), |
| 153 | SOC_SINGLE_TLV("Bass Volume", CS42L51_TONE_CTL, 0, 0xf, 1, tone_tlv), |
| 154 | SOC_SINGLE_TLV("Treble Volume", CS42L51_TONE_CTL, 4, 0xf, 1, tone_tlv), |
| 155 | SOC_ENUM_EXT("PCM channel mixer", |
| 156 | cs42l51_chan_mix, |
| 157 | cs42l51_get_chan_mix, cs42l51_set_chan_mix), |
| 158 | }; |
| 159 | |
| 160 | /* |
| 161 | * to power down, one must: |
| 162 | * 1.) Enable the PDN bit |
| 163 | * 2.) enable power-down for the select channels |
| 164 | * 3.) disable the PDN bit. |
| 165 | */ |
| 166 | static int cs42l51_pdn_event(struct snd_soc_dapm_widget *w, |
| 167 | struct snd_kcontrol *kcontrol, int event) |
| 168 | { |
Kuninori Morimoto | 1fa4985 | 2018-01-29 03:59:02 +0000 | [diff] [blame] | 169 | struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); |
Lars-Peter Clausen | ceb3c06 | 2014-11-20 21:05:38 +0100 | [diff] [blame] | 170 | |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 171 | switch (event) { |
| 172 | case SND_SOC_DAPM_PRE_PMD: |
Kuninori Morimoto | 1fa4985 | 2018-01-29 03:59:02 +0000 | [diff] [blame] | 173 | snd_soc_component_update_bits(component, CS42L51_POWER_CTL1, |
Axel Lin | e94de1e | 2011-11-01 15:17:57 +0800 | [diff] [blame] | 174 | CS42L51_POWER_CTL1_PDN, |
| 175 | CS42L51_POWER_CTL1_PDN); |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 176 | break; |
| 177 | default: |
| 178 | case SND_SOC_DAPM_POST_PMD: |
Kuninori Morimoto | 1fa4985 | 2018-01-29 03:59:02 +0000 | [diff] [blame] | 179 | snd_soc_component_update_bits(component, CS42L51_POWER_CTL1, |
Axel Lin | e94de1e | 2011-11-01 15:17:57 +0800 | [diff] [blame] | 180 | CS42L51_POWER_CTL1_PDN, 0); |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 181 | break; |
| 182 | } |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 183 | |
| 184 | return 0; |
| 185 | } |
| 186 | |
| 187 | static const char *cs42l51_dac_names[] = {"Direct PCM", |
| 188 | "DSP PCM", "ADC"}; |
Takashi Iwai | 6109ab2 | 2014-02-18 10:44:57 +0100 | [diff] [blame] | 189 | static SOC_ENUM_SINGLE_DECL(cs42l51_dac_mux_enum, |
| 190 | CS42L51_DAC_CTL, 6, cs42l51_dac_names); |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 191 | static const struct snd_kcontrol_new cs42l51_dac_mux_controls = |
| 192 | SOC_DAPM_ENUM("Route", cs42l51_dac_mux_enum); |
| 193 | |
| 194 | static const char *cs42l51_adcl_names[] = {"AIN1 Left", "AIN2 Left", |
| 195 | "MIC Left", "MIC+preamp Left"}; |
Takashi Iwai | 6109ab2 | 2014-02-18 10:44:57 +0100 | [diff] [blame] | 196 | static SOC_ENUM_SINGLE_DECL(cs42l51_adcl_mux_enum, |
| 197 | CS42L51_ADC_INPUT, 4, cs42l51_adcl_names); |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 198 | static const struct snd_kcontrol_new cs42l51_adcl_mux_controls = |
| 199 | SOC_DAPM_ENUM("Route", cs42l51_adcl_mux_enum); |
| 200 | |
| 201 | static const char *cs42l51_adcr_names[] = {"AIN1 Right", "AIN2 Right", |
| 202 | "MIC Right", "MIC+preamp Right"}; |
Takashi Iwai | 6109ab2 | 2014-02-18 10:44:57 +0100 | [diff] [blame] | 203 | static SOC_ENUM_SINGLE_DECL(cs42l51_adcr_mux_enum, |
| 204 | CS42L51_ADC_INPUT, 6, cs42l51_adcr_names); |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 205 | static const struct snd_kcontrol_new cs42l51_adcr_mux_controls = |
| 206 | SOC_DAPM_ENUM("Route", cs42l51_adcr_mux_enum); |
| 207 | |
| 208 | static const struct snd_soc_dapm_widget cs42l51_dapm_widgets[] = { |
| 209 | SND_SOC_DAPM_MICBIAS("Mic Bias", CS42L51_MIC_POWER_CTL, 1, 1), |
| 210 | SND_SOC_DAPM_PGA_E("Left PGA", CS42L51_POWER_CTL1, 3, 1, NULL, 0, |
| 211 | cs42l51_pdn_event, SND_SOC_DAPM_PRE_POST_PMD), |
| 212 | SND_SOC_DAPM_PGA_E("Right PGA", CS42L51_POWER_CTL1, 4, 1, NULL, 0, |
| 213 | cs42l51_pdn_event, SND_SOC_DAPM_PRE_POST_PMD), |
| 214 | SND_SOC_DAPM_ADC_E("Left ADC", "Left HiFi Capture", |
| 215 | CS42L51_POWER_CTL1, 1, 1, |
| 216 | cs42l51_pdn_event, SND_SOC_DAPM_PRE_POST_PMD), |
| 217 | SND_SOC_DAPM_ADC_E("Right ADC", "Right HiFi Capture", |
| 218 | CS42L51_POWER_CTL1, 2, 1, |
| 219 | cs42l51_pdn_event, SND_SOC_DAPM_PRE_POST_PMD), |
| 220 | SND_SOC_DAPM_DAC_E("Left DAC", "Left HiFi Playback", |
| 221 | CS42L51_POWER_CTL1, 5, 1, |
| 222 | cs42l51_pdn_event, SND_SOC_DAPM_PRE_POST_PMD), |
| 223 | SND_SOC_DAPM_DAC_E("Right DAC", "Right HiFi Playback", |
| 224 | CS42L51_POWER_CTL1, 6, 1, |
| 225 | cs42l51_pdn_event, SND_SOC_DAPM_PRE_POST_PMD), |
| 226 | |
| 227 | /* analog/mic */ |
| 228 | SND_SOC_DAPM_INPUT("AIN1L"), |
| 229 | SND_SOC_DAPM_INPUT("AIN1R"), |
| 230 | SND_SOC_DAPM_INPUT("AIN2L"), |
| 231 | SND_SOC_DAPM_INPUT("AIN2R"), |
| 232 | SND_SOC_DAPM_INPUT("MICL"), |
| 233 | SND_SOC_DAPM_INPUT("MICR"), |
| 234 | |
| 235 | SND_SOC_DAPM_MIXER("Mic Preamp Left", |
| 236 | CS42L51_MIC_POWER_CTL, 2, 1, NULL, 0), |
| 237 | SND_SOC_DAPM_MIXER("Mic Preamp Right", |
| 238 | CS42L51_MIC_POWER_CTL, 3, 1, NULL, 0), |
| 239 | |
| 240 | /* HP */ |
| 241 | SND_SOC_DAPM_OUTPUT("HPL"), |
| 242 | SND_SOC_DAPM_OUTPUT("HPR"), |
| 243 | |
| 244 | /* mux */ |
| 245 | SND_SOC_DAPM_MUX("DAC Mux", SND_SOC_NOPM, 0, 0, |
| 246 | &cs42l51_dac_mux_controls), |
| 247 | SND_SOC_DAPM_MUX("PGA-ADC Mux Left", SND_SOC_NOPM, 0, 0, |
| 248 | &cs42l51_adcl_mux_controls), |
| 249 | SND_SOC_DAPM_MUX("PGA-ADC Mux Right", SND_SOC_NOPM, 0, 0, |
| 250 | &cs42l51_adcr_mux_controls), |
| 251 | }; |
| 252 | |
Olivier Moysan | 5e8d63a | 2018-10-15 16:03:36 +0200 | [diff] [blame] | 253 | static const struct snd_soc_dapm_widget cs42l51_dapm_mclk_widgets[] = { |
| 254 | SND_SOC_DAPM_CLOCK_SUPPLY("MCLK") |
| 255 | }; |
| 256 | |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 257 | static const struct snd_soc_dapm_route cs42l51_routes[] = { |
| 258 | {"HPL", NULL, "Left DAC"}, |
| 259 | {"HPR", NULL, "Right DAC"}, |
| 260 | |
| 261 | {"Left ADC", NULL, "Left PGA"}, |
| 262 | {"Right ADC", NULL, "Right PGA"}, |
| 263 | |
| 264 | {"Mic Preamp Left", NULL, "MICL"}, |
| 265 | {"Mic Preamp Right", NULL, "MICR"}, |
| 266 | |
| 267 | {"PGA-ADC Mux Left", "AIN1 Left", "AIN1L" }, |
| 268 | {"PGA-ADC Mux Left", "AIN2 Left", "AIN2L" }, |
| 269 | {"PGA-ADC Mux Left", "MIC Left", "MICL" }, |
| 270 | {"PGA-ADC Mux Left", "MIC+preamp Left", "Mic Preamp Left" }, |
| 271 | {"PGA-ADC Mux Right", "AIN1 Right", "AIN1R" }, |
| 272 | {"PGA-ADC Mux Right", "AIN2 Right", "AIN2R" }, |
| 273 | {"PGA-ADC Mux Right", "MIC Right", "MICR" }, |
| 274 | {"PGA-ADC Mux Right", "MIC+preamp Right", "Mic Preamp Right" }, |
| 275 | |
| 276 | {"Left PGA", NULL, "PGA-ADC Mux Left"}, |
| 277 | {"Right PGA", NULL, "PGA-ADC Mux Right"}, |
| 278 | }; |
| 279 | |
| 280 | static int cs42l51_set_dai_fmt(struct snd_soc_dai *codec_dai, |
| 281 | unsigned int format) |
| 282 | { |
Kuninori Morimoto | 1fa4985 | 2018-01-29 03:59:02 +0000 | [diff] [blame] | 283 | struct snd_soc_component *component = codec_dai->component; |
| 284 | struct cs42l51_private *cs42l51 = snd_soc_component_get_drvdata(component); |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 285 | |
| 286 | switch (format & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 287 | case SND_SOC_DAIFMT_I2S: |
| 288 | case SND_SOC_DAIFMT_LEFT_J: |
| 289 | case SND_SOC_DAIFMT_RIGHT_J: |
| 290 | cs42l51->audio_mode = format & SND_SOC_DAIFMT_FORMAT_MASK; |
| 291 | break; |
| 292 | default: |
Kuninori Morimoto | 1fa4985 | 2018-01-29 03:59:02 +0000 | [diff] [blame] | 293 | dev_err(component->dev, "invalid DAI format\n"); |
Axel Lin | ac60155 | 2011-10-06 07:29:56 +0800 | [diff] [blame] | 294 | return -EINVAL; |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | switch (format & SND_SOC_DAIFMT_MASTER_MASK) { |
| 298 | case SND_SOC_DAIFMT_CBM_CFM: |
| 299 | cs42l51->func = MODE_MASTER; |
| 300 | break; |
| 301 | case SND_SOC_DAIFMT_CBS_CFS: |
| 302 | cs42l51->func = MODE_SLAVE_AUTO; |
| 303 | break; |
| 304 | default: |
Kuninori Morimoto | 1fa4985 | 2018-01-29 03:59:02 +0000 | [diff] [blame] | 305 | dev_err(component->dev, "Unknown master/slave configuration\n"); |
Axel Lin | ac60155 | 2011-10-06 07:29:56 +0800 | [diff] [blame] | 306 | return -EINVAL; |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 307 | } |
| 308 | |
Axel Lin | ac60155 | 2011-10-06 07:29:56 +0800 | [diff] [blame] | 309 | return 0; |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | struct cs42l51_ratios { |
| 313 | unsigned int ratio; |
| 314 | unsigned char speed_mode; |
| 315 | unsigned char mclk; |
| 316 | }; |
| 317 | |
| 318 | static struct cs42l51_ratios slave_ratios[] = { |
| 319 | { 512, CS42L51_QSM_MODE, 0 }, { 768, CS42L51_QSM_MODE, 0 }, |
| 320 | { 1024, CS42L51_QSM_MODE, 0 }, { 1536, CS42L51_QSM_MODE, 0 }, |
| 321 | { 2048, CS42L51_QSM_MODE, 0 }, { 3072, CS42L51_QSM_MODE, 0 }, |
| 322 | { 256, CS42L51_HSM_MODE, 0 }, { 384, CS42L51_HSM_MODE, 0 }, |
| 323 | { 512, CS42L51_HSM_MODE, 0 }, { 768, CS42L51_HSM_MODE, 0 }, |
| 324 | { 1024, CS42L51_HSM_MODE, 0 }, { 1536, CS42L51_HSM_MODE, 0 }, |
| 325 | { 128, CS42L51_SSM_MODE, 0 }, { 192, CS42L51_SSM_MODE, 0 }, |
| 326 | { 256, CS42L51_SSM_MODE, 0 }, { 384, CS42L51_SSM_MODE, 0 }, |
| 327 | { 512, CS42L51_SSM_MODE, 0 }, { 768, CS42L51_SSM_MODE, 0 }, |
| 328 | { 128, CS42L51_DSM_MODE, 0 }, { 192, CS42L51_DSM_MODE, 0 }, |
| 329 | { 256, CS42L51_DSM_MODE, 0 }, { 384, CS42L51_DSM_MODE, 0 }, |
| 330 | }; |
| 331 | |
| 332 | static struct cs42l51_ratios slave_auto_ratios[] = { |
| 333 | { 1024, CS42L51_QSM_MODE, 0 }, { 1536, CS42L51_QSM_MODE, 0 }, |
| 334 | { 2048, CS42L51_QSM_MODE, 1 }, { 3072, CS42L51_QSM_MODE, 1 }, |
| 335 | { 512, CS42L51_HSM_MODE, 0 }, { 768, CS42L51_HSM_MODE, 0 }, |
| 336 | { 1024, CS42L51_HSM_MODE, 1 }, { 1536, CS42L51_HSM_MODE, 1 }, |
| 337 | { 256, CS42L51_SSM_MODE, 0 }, { 384, CS42L51_SSM_MODE, 0 }, |
| 338 | { 512, CS42L51_SSM_MODE, 1 }, { 768, CS42L51_SSM_MODE, 1 }, |
| 339 | { 128, CS42L51_DSM_MODE, 0 }, { 192, CS42L51_DSM_MODE, 0 }, |
| 340 | { 256, CS42L51_DSM_MODE, 1 }, { 384, CS42L51_DSM_MODE, 1 }, |
| 341 | }; |
| 342 | |
| 343 | static int cs42l51_set_dai_sysclk(struct snd_soc_dai *codec_dai, |
| 344 | int clk_id, unsigned int freq, int dir) |
| 345 | { |
Kuninori Morimoto | 1fa4985 | 2018-01-29 03:59:02 +0000 | [diff] [blame] | 346 | struct snd_soc_component *component = codec_dai->component; |
| 347 | struct cs42l51_private *cs42l51 = snd_soc_component_get_drvdata(component); |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 348 | |
| 349 | cs42l51->mclk = freq; |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 350 | return 0; |
| 351 | } |
| 352 | |
| 353 | static int cs42l51_hw_params(struct snd_pcm_substream *substream, |
| 354 | struct snd_pcm_hw_params *params, |
| 355 | struct snd_soc_dai *dai) |
| 356 | { |
Kuninori Morimoto | 1fa4985 | 2018-01-29 03:59:02 +0000 | [diff] [blame] | 357 | struct snd_soc_component *component = dai->component; |
| 358 | struct cs42l51_private *cs42l51 = snd_soc_component_get_drvdata(component); |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 359 | int ret; |
| 360 | unsigned int i; |
| 361 | unsigned int rate; |
| 362 | unsigned int ratio; |
| 363 | struct cs42l51_ratios *ratios = NULL; |
| 364 | int nr_ratios = 0; |
| 365 | int intf_ctl, power_ctl, fmt; |
| 366 | |
| 367 | switch (cs42l51->func) { |
| 368 | case MODE_MASTER: |
| 369 | return -EINVAL; |
| 370 | case MODE_SLAVE: |
| 371 | ratios = slave_ratios; |
| 372 | nr_ratios = ARRAY_SIZE(slave_ratios); |
| 373 | break; |
| 374 | case MODE_SLAVE_AUTO: |
| 375 | ratios = slave_auto_ratios; |
| 376 | nr_ratios = ARRAY_SIZE(slave_auto_ratios); |
| 377 | break; |
| 378 | } |
| 379 | |
| 380 | /* Figure out which MCLK/LRCK ratio to use */ |
| 381 | rate = params_rate(params); /* Sampling rate, in Hz */ |
| 382 | ratio = cs42l51->mclk / rate; /* MCLK/LRCK ratio */ |
| 383 | for (i = 0; i < nr_ratios; i++) { |
| 384 | if (ratios[i].ratio == ratio) |
| 385 | break; |
| 386 | } |
| 387 | |
| 388 | if (i == nr_ratios) { |
| 389 | /* We did not find a matching ratio */ |
Kuninori Morimoto | 1fa4985 | 2018-01-29 03:59:02 +0000 | [diff] [blame] | 390 | dev_err(component->dev, "could not find matching ratio\n"); |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 391 | return -EINVAL; |
| 392 | } |
| 393 | |
Kuninori Morimoto | 1fa4985 | 2018-01-29 03:59:02 +0000 | [diff] [blame] | 394 | intf_ctl = snd_soc_component_read32(component, CS42L51_INTF_CTL); |
| 395 | power_ctl = snd_soc_component_read32(component, CS42L51_MIC_POWER_CTL); |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 396 | |
| 397 | intf_ctl &= ~(CS42L51_INTF_CTL_MASTER | CS42L51_INTF_CTL_ADC_I2S |
| 398 | | CS42L51_INTF_CTL_DAC_FORMAT(7)); |
| 399 | power_ctl &= ~(CS42L51_MIC_POWER_CTL_SPEED(3) |
| 400 | | CS42L51_MIC_POWER_CTL_MCLK_DIV2); |
| 401 | |
| 402 | switch (cs42l51->func) { |
| 403 | case MODE_MASTER: |
| 404 | intf_ctl |= CS42L51_INTF_CTL_MASTER; |
| 405 | power_ctl |= CS42L51_MIC_POWER_CTL_SPEED(ratios[i].speed_mode); |
| 406 | break; |
| 407 | case MODE_SLAVE: |
| 408 | power_ctl |= CS42L51_MIC_POWER_CTL_SPEED(ratios[i].speed_mode); |
| 409 | break; |
| 410 | case MODE_SLAVE_AUTO: |
| 411 | power_ctl |= CS42L51_MIC_POWER_CTL_AUTO; |
| 412 | break; |
| 413 | } |
| 414 | |
| 415 | switch (cs42l51->audio_mode) { |
| 416 | case SND_SOC_DAIFMT_I2S: |
| 417 | intf_ctl |= CS42L51_INTF_CTL_ADC_I2S; |
| 418 | intf_ctl |= CS42L51_INTF_CTL_DAC_FORMAT(CS42L51_DAC_DIF_I2S); |
| 419 | break; |
| 420 | case SND_SOC_DAIFMT_LEFT_J: |
| 421 | intf_ctl |= CS42L51_INTF_CTL_DAC_FORMAT(CS42L51_DAC_DIF_LJ24); |
| 422 | break; |
| 423 | case SND_SOC_DAIFMT_RIGHT_J: |
Mark Brown | 1b6b0df | 2014-01-08 19:48:20 +0000 | [diff] [blame] | 424 | switch (params_width(params)) { |
| 425 | case 16: |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 426 | fmt = CS42L51_DAC_DIF_RJ16; |
| 427 | break; |
Mark Brown | 1b6b0df | 2014-01-08 19:48:20 +0000 | [diff] [blame] | 428 | case 18: |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 429 | fmt = CS42L51_DAC_DIF_RJ18; |
| 430 | break; |
Mark Brown | 1b6b0df | 2014-01-08 19:48:20 +0000 | [diff] [blame] | 431 | case 20: |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 432 | fmt = CS42L51_DAC_DIF_RJ20; |
| 433 | break; |
Mark Brown | 1b6b0df | 2014-01-08 19:48:20 +0000 | [diff] [blame] | 434 | case 24: |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 435 | fmt = CS42L51_DAC_DIF_RJ24; |
| 436 | break; |
| 437 | default: |
Kuninori Morimoto | 1fa4985 | 2018-01-29 03:59:02 +0000 | [diff] [blame] | 438 | dev_err(component->dev, "unknown format\n"); |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 439 | return -EINVAL; |
| 440 | } |
| 441 | intf_ctl |= CS42L51_INTF_CTL_DAC_FORMAT(fmt); |
| 442 | break; |
| 443 | default: |
Kuninori Morimoto | 1fa4985 | 2018-01-29 03:59:02 +0000 | [diff] [blame] | 444 | dev_err(component->dev, "unknown format\n"); |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 445 | return -EINVAL; |
| 446 | } |
| 447 | |
| 448 | if (ratios[i].mclk) |
| 449 | power_ctl |= CS42L51_MIC_POWER_CTL_MCLK_DIV2; |
| 450 | |
Kuninori Morimoto | 1fa4985 | 2018-01-29 03:59:02 +0000 | [diff] [blame] | 451 | ret = snd_soc_component_write(component, CS42L51_INTF_CTL, intf_ctl); |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 452 | if (ret < 0) |
| 453 | return ret; |
| 454 | |
Kuninori Morimoto | 1fa4985 | 2018-01-29 03:59:02 +0000 | [diff] [blame] | 455 | ret = snd_soc_component_write(component, CS42L51_MIC_POWER_CTL, power_ctl); |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 456 | if (ret < 0) |
| 457 | return ret; |
| 458 | |
| 459 | return 0; |
| 460 | } |
| 461 | |
| 462 | static int cs42l51_dai_mute(struct snd_soc_dai *dai, int mute) |
| 463 | { |
Kuninori Morimoto | 1fa4985 | 2018-01-29 03:59:02 +0000 | [diff] [blame] | 464 | struct snd_soc_component *component = dai->component; |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 465 | int reg; |
| 466 | int mask = CS42L51_DAC_OUT_CTL_DACA_MUTE|CS42L51_DAC_OUT_CTL_DACB_MUTE; |
| 467 | |
Kuninori Morimoto | 1fa4985 | 2018-01-29 03:59:02 +0000 | [diff] [blame] | 468 | reg = snd_soc_component_read32(component, CS42L51_DAC_OUT_CTL); |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 469 | |
| 470 | if (mute) |
| 471 | reg |= mask; |
| 472 | else |
| 473 | reg &= ~mask; |
| 474 | |
Kuninori Morimoto | 1fa4985 | 2018-01-29 03:59:02 +0000 | [diff] [blame] | 475 | return snd_soc_component_write(component, CS42L51_DAC_OUT_CTL, reg); |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 476 | } |
| 477 | |
Olivier Moysan | ad6bb30 | 2019-03-29 16:37:37 +0100 | [diff] [blame] | 478 | static int cs42l51_of_xlate_dai_id(struct snd_soc_component *component, |
| 479 | struct device_node *endpoint) |
| 480 | { |
| 481 | /* return dai id 0, whatever the endpoint index */ |
| 482 | return 0; |
| 483 | } |
| 484 | |
Lars-Peter Clausen | 85e7652 | 2011-11-23 11:40:40 +0100 | [diff] [blame] | 485 | static const struct snd_soc_dai_ops cs42l51_dai_ops = { |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 486 | .hw_params = cs42l51_hw_params, |
| 487 | .set_sysclk = cs42l51_set_dai_sysclk, |
| 488 | .set_fmt = cs42l51_set_dai_fmt, |
| 489 | .digital_mute = cs42l51_dai_mute, |
| 490 | }; |
| 491 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 492 | static struct snd_soc_dai_driver cs42l51_dai = { |
| 493 | .name = "cs42l51-hifi", |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 494 | .playback = { |
| 495 | .stream_name = "Playback", |
| 496 | .channels_min = 1, |
| 497 | .channels_max = 2, |
| 498 | .rates = SNDRV_PCM_RATE_8000_96000, |
| 499 | .formats = CS42L51_FORMATS, |
| 500 | }, |
| 501 | .capture = { |
| 502 | .stream_name = "Capture", |
| 503 | .channels_min = 1, |
| 504 | .channels_max = 2, |
| 505 | .rates = SNDRV_PCM_RATE_8000_96000, |
| 506 | .formats = CS42L51_FORMATS, |
| 507 | }, |
| 508 | .ops = &cs42l51_dai_ops, |
| 509 | }; |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 510 | |
Kuninori Morimoto | 1fa4985 | 2018-01-29 03:59:02 +0000 | [diff] [blame] | 511 | static int cs42l51_component_probe(struct snd_soc_component *component) |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 512 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 513 | int ret, reg; |
Olivier Moysan | 5e8d63a | 2018-10-15 16:03:36 +0200 | [diff] [blame] | 514 | struct snd_soc_dapm_context *dapm; |
Olivier Moysan | 318e741 | 2018-10-19 17:56:35 +0200 | [diff] [blame] | 515 | struct cs42l51_private *cs42l51; |
Olivier Moysan | 5e8d63a | 2018-10-15 16:03:36 +0200 | [diff] [blame] | 516 | |
Olivier Moysan | 318e741 | 2018-10-19 17:56:35 +0200 | [diff] [blame] | 517 | cs42l51 = snd_soc_component_get_drvdata(component); |
Olivier Moysan | 5e8d63a | 2018-10-15 16:03:36 +0200 | [diff] [blame] | 518 | dapm = snd_soc_component_get_dapm(component); |
Olivier Moysan | 318e741 | 2018-10-19 17:56:35 +0200 | [diff] [blame] | 519 | |
| 520 | if (cs42l51->mclk_handle) |
| 521 | snd_soc_dapm_new_controls(dapm, cs42l51_dapm_mclk_widgets, 1); |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 522 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 523 | /* |
| 524 | * DAC configuration |
| 525 | * - Use signal processor |
| 526 | * - auto mute |
| 527 | * - vol changes immediate |
| 528 | * - no de-emphasize |
| 529 | */ |
| 530 | reg = CS42L51_DAC_CTL_DATA_SEL(1) |
| 531 | | CS42L51_DAC_CTL_AMUTE | CS42L51_DAC_CTL_DACSZ(0); |
Kuninori Morimoto | 1fa4985 | 2018-01-29 03:59:02 +0000 | [diff] [blame] | 532 | ret = snd_soc_component_write(component, CS42L51_DAC_CTL, reg); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 533 | if (ret < 0) |
| 534 | return ret; |
| 535 | |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 536 | return 0; |
| 537 | } |
| 538 | |
Kuninori Morimoto | 1fa4985 | 2018-01-29 03:59:02 +0000 | [diff] [blame] | 539 | static const struct snd_soc_component_driver soc_component_device_cs42l51 = { |
| 540 | .probe = cs42l51_component_probe, |
| 541 | .controls = cs42l51_snd_controls, |
| 542 | .num_controls = ARRAY_SIZE(cs42l51_snd_controls), |
| 543 | .dapm_widgets = cs42l51_dapm_widgets, |
| 544 | .num_dapm_widgets = ARRAY_SIZE(cs42l51_dapm_widgets), |
| 545 | .dapm_routes = cs42l51_routes, |
| 546 | .num_dapm_routes = ARRAY_SIZE(cs42l51_routes), |
Olivier Moysan | ad6bb30 | 2019-03-29 16:37:37 +0100 | [diff] [blame] | 547 | .of_xlate_dai_id = cs42l51_of_xlate_dai_id, |
Kuninori Morimoto | 1fa4985 | 2018-01-29 03:59:02 +0000 | [diff] [blame] | 548 | .idle_bias_on = 1, |
| 549 | .use_pmdown_time = 1, |
| 550 | .endianness = 1, |
| 551 | .non_legacy_dai_naming = 1, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 552 | }; |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 553 | |
Brian Austin | a1253ef | 2014-04-15 15:49:33 -0500 | [diff] [blame] | 554 | const struct regmap_config cs42l51_regmap = { |
Mark Brown | da07148 | 2014-02-11 19:24:31 +0000 | [diff] [blame] | 555 | .max_register = CS42L51_CHARGE_FREQ, |
| 556 | .cache_type = REGCACHE_RBTREE, |
| 557 | }; |
Brian Austin | a1253ef | 2014-04-15 15:49:33 -0500 | [diff] [blame] | 558 | EXPORT_SYMBOL_GPL(cs42l51_regmap); |
Mark Brown | da07148 | 2014-02-11 19:24:31 +0000 | [diff] [blame] | 559 | |
Brian Austin | a1253ef | 2014-04-15 15:49:33 -0500 | [diff] [blame] | 560 | int cs42l51_probe(struct device *dev, struct regmap *regmap) |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 561 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 562 | struct cs42l51_private *cs42l51; |
Mark Brown | da07148 | 2014-02-11 19:24:31 +0000 | [diff] [blame] | 563 | unsigned int val; |
Olivier Moysan | f77b6ea | 2019-04-03 15:23:32 +0200 | [diff] [blame] | 564 | int ret, i; |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 565 | |
Brian Austin | a1253ef | 2014-04-15 15:49:33 -0500 | [diff] [blame] | 566 | if (IS_ERR(regmap)) |
| 567 | return PTR_ERR(regmap); |
| 568 | |
| 569 | cs42l51 = devm_kzalloc(dev, sizeof(struct cs42l51_private), |
| 570 | GFP_KERNEL); |
| 571 | if (!cs42l51) |
| 572 | return -ENOMEM; |
| 573 | |
| 574 | dev_set_drvdata(dev, cs42l51); |
Mark Brown | da07148 | 2014-02-11 19:24:31 +0000 | [diff] [blame] | 575 | |
Olivier Moysan | 318e741 | 2018-10-19 17:56:35 +0200 | [diff] [blame] | 576 | cs42l51->mclk_handle = devm_clk_get(dev, "MCLK"); |
| 577 | if (IS_ERR(cs42l51->mclk_handle)) { |
| 578 | if (PTR_ERR(cs42l51->mclk_handle) != -ENOENT) |
| 579 | return PTR_ERR(cs42l51->mclk_handle); |
| 580 | cs42l51->mclk_handle = NULL; |
| 581 | } |
| 582 | |
Olivier Moysan | f77b6ea | 2019-04-03 15:23:32 +0200 | [diff] [blame] | 583 | for (i = 0; i < ARRAY_SIZE(cs42l51->supplies); i++) |
| 584 | cs42l51->supplies[i].supply = cs42l51_supply_names[i]; |
| 585 | |
| 586 | ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(cs42l51->supplies), |
| 587 | cs42l51->supplies); |
| 588 | if (ret != 0) { |
| 589 | dev_err(dev, "Failed to request supplies: %d\n", ret); |
| 590 | return ret; |
| 591 | } |
| 592 | |
| 593 | ret = regulator_bulk_enable(ARRAY_SIZE(cs42l51->supplies), |
| 594 | cs42l51->supplies); |
| 595 | if (ret != 0) { |
| 596 | dev_err(dev, "Failed to enable supplies: %d\n", ret); |
| 597 | return ret; |
| 598 | } |
| 599 | |
Olivier Moysan | 11b9cd7 | 2019-04-03 15:23:33 +0200 | [diff] [blame^] | 600 | cs42l51->reset_gpio = devm_gpiod_get_optional(dev, "reset", |
| 601 | GPIOD_OUT_LOW); |
| 602 | if (IS_ERR(cs42l51->reset_gpio)) |
| 603 | return PTR_ERR(cs42l51->reset_gpio); |
| 604 | |
| 605 | if (cs42l51->reset_gpio) { |
| 606 | dev_dbg(dev, "Release reset gpio\n"); |
| 607 | gpiod_set_value_cansleep(cs42l51->reset_gpio, 0); |
| 608 | mdelay(2); |
| 609 | } |
| 610 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 611 | /* Verify that we have a CS42L51 */ |
Mark Brown | da07148 | 2014-02-11 19:24:31 +0000 | [diff] [blame] | 612 | ret = regmap_read(regmap, CS42L51_CHIP_REV_ID, &val); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 613 | if (ret < 0) { |
Brian Austin | a1253ef | 2014-04-15 15:49:33 -0500 | [diff] [blame] | 614 | dev_err(dev, "failed to read I2C\n"); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 615 | goto error; |
| 616 | } |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 617 | |
Mark Brown | da07148 | 2014-02-11 19:24:31 +0000 | [diff] [blame] | 618 | if ((val != CS42L51_MK_CHIP_REV(CS42L51_CHIP_ID, CS42L51_CHIP_REV_A)) && |
| 619 | (val != CS42L51_MK_CHIP_REV(CS42L51_CHIP_ID, CS42L51_CHIP_REV_B))) { |
Brian Austin | a1253ef | 2014-04-15 15:49:33 -0500 | [diff] [blame] | 620 | dev_err(dev, "Invalid chip id: %x\n", val); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 621 | ret = -ENODEV; |
| 622 | goto error; |
| 623 | } |
Axel Lin | 1025c05 | 2014-04-17 16:35:43 +0800 | [diff] [blame] | 624 | dev_info(dev, "Cirrus Logic CS42L51, Revision: %02X\n", |
| 625 | val & CS42L51_CHIP_REV_MASK); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 626 | |
Kuninori Morimoto | 1fa4985 | 2018-01-29 03:59:02 +0000 | [diff] [blame] | 627 | ret = devm_snd_soc_register_component(dev, |
| 628 | &soc_component_device_cs42l51, &cs42l51_dai, 1); |
Olivier Moysan | f77b6ea | 2019-04-03 15:23:32 +0200 | [diff] [blame] | 629 | if (ret < 0) |
| 630 | goto error; |
| 631 | |
| 632 | return 0; |
| 633 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 634 | error: |
Olivier Moysan | f77b6ea | 2019-04-03 15:23:32 +0200 | [diff] [blame] | 635 | regulator_bulk_disable(ARRAY_SIZE(cs42l51->supplies), |
| 636 | cs42l51->supplies); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 637 | return ret; |
| 638 | } |
Brian Austin | a1253ef | 2014-04-15 15:49:33 -0500 | [diff] [blame] | 639 | EXPORT_SYMBOL_GPL(cs42l51_probe); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 640 | |
Olivier Moysan | f77b6ea | 2019-04-03 15:23:32 +0200 | [diff] [blame] | 641 | int cs42l51_remove(struct device *dev) |
| 642 | { |
| 643 | struct cs42l51_private *cs42l51 = dev_get_drvdata(dev); |
| 644 | |
Olivier Moysan | 11b9cd7 | 2019-04-03 15:23:33 +0200 | [diff] [blame^] | 645 | gpiod_set_value_cansleep(cs42l51->reset_gpio, 1); |
| 646 | |
Olivier Moysan | f77b6ea | 2019-04-03 15:23:32 +0200 | [diff] [blame] | 647 | return regulator_bulk_disable(ARRAY_SIZE(cs42l51->supplies), |
| 648 | cs42l51->supplies); |
| 649 | } |
| 650 | EXPORT_SYMBOL_GPL(cs42l51_remove); |
| 651 | |
Thomas Petazzoni | 2cb1e02 | 2014-11-12 15:40:44 +0100 | [diff] [blame] | 652 | const struct of_device_id cs42l51_of_match[] = { |
Thomas Petazzoni | dfd72a6 | 2014-01-30 18:14:05 +0100 | [diff] [blame] | 653 | { .compatible = "cirrus,cs42l51", }, |
| 654 | { } |
| 655 | }; |
| 656 | MODULE_DEVICE_TABLE(of, cs42l51_of_match); |
Thomas Petazzoni | 2cb1e02 | 2014-11-12 15:40:44 +0100 | [diff] [blame] | 657 | EXPORT_SYMBOL_GPL(cs42l51_of_match); |
| 658 | |
Arnaud Patard (Rtp) | 6973789 | 2010-09-09 14:10:33 +0200 | [diff] [blame] | 659 | MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>"); |
apatard@mandriva.com | 72ed5a8 | 2010-05-27 14:57:41 +0200 | [diff] [blame] | 660 | MODULE_DESCRIPTION("Cirrus Logic CS42L51 ALSA SoC Codec Driver"); |
| 661 | MODULE_LICENSE("GPL"); |