diff options
| -rw-r--r-- | sound/soc/codecs/si476x.c | 64 |
1 files changed, 16 insertions, 48 deletions
diff --git a/sound/soc/codecs/si476x.c b/sound/soc/codecs/si476x.c index 38f3b105c17d..52e7cb08434b 100644 --- a/sound/soc/codecs/si476x.c +++ b/sound/soc/codecs/si476x.c | |||
| @@ -60,48 +60,6 @@ enum si476x_pcm_format { | |||
| 60 | SI476X_PCM_FORMAT_S24_LE = 6, | 60 | SI476X_PCM_FORMAT_S24_LE = 6, |
| 61 | }; | 61 | }; |
| 62 | 62 | ||
| 63 | static unsigned int si476x_codec_read(struct snd_soc_codec *codec, | ||
| 64 | unsigned int reg) | ||
| 65 | { | ||
| 66 | int err; | ||
| 67 | unsigned int val; | ||
| 68 | struct si476x_core *core = codec->control_data; | ||
| 69 | |||
| 70 | si476x_core_lock(core); | ||
| 71 | if (!si476x_core_is_powered_up(core)) | ||
| 72 | regcache_cache_only(core->regmap, true); | ||
| 73 | |||
| 74 | err = regmap_read(core->regmap, reg, &val); | ||
| 75 | |||
| 76 | if (!si476x_core_is_powered_up(core)) | ||
| 77 | regcache_cache_only(core->regmap, false); | ||
| 78 | si476x_core_unlock(core); | ||
| 79 | |||
| 80 | if (err < 0) | ||
| 81 | return err; | ||
| 82 | |||
| 83 | return val; | ||
| 84 | } | ||
| 85 | |||
| 86 | static int si476x_codec_write(struct snd_soc_codec *codec, | ||
| 87 | unsigned int reg, unsigned int val) | ||
| 88 | { | ||
| 89 | int err; | ||
| 90 | struct si476x_core *core = codec->control_data; | ||
| 91 | |||
| 92 | si476x_core_lock(core); | ||
| 93 | if (!si476x_core_is_powered_up(core)) | ||
| 94 | regcache_cache_only(core->regmap, true); | ||
| 95 | |||
| 96 | err = regmap_write(core->regmap, reg, val); | ||
| 97 | |||
| 98 | if (!si476x_core_is_powered_up(core)) | ||
| 99 | regcache_cache_only(core->regmap, false); | ||
| 100 | si476x_core_unlock(core); | ||
| 101 | |||
| 102 | return err; | ||
| 103 | } | ||
| 104 | |||
| 105 | static const struct snd_soc_dapm_widget si476x_dapm_widgets[] = { | 63 | static const struct snd_soc_dapm_widget si476x_dapm_widgets[] = { |
| 106 | SND_SOC_DAPM_OUTPUT("LOUT"), | 64 | SND_SOC_DAPM_OUTPUT("LOUT"), |
| 107 | SND_SOC_DAPM_OUTPUT("ROUT"), | 65 | SND_SOC_DAPM_OUTPUT("ROUT"), |
| @@ -115,6 +73,7 @@ static const struct snd_soc_dapm_route si476x_dapm_routes[] = { | |||
| 115 | static int si476x_codec_set_dai_fmt(struct snd_soc_dai *codec_dai, | 73 | static int si476x_codec_set_dai_fmt(struct snd_soc_dai *codec_dai, |
| 116 | unsigned int fmt) | 74 | unsigned int fmt) |
| 117 | { | 75 | { |
| 76 | struct si476x_core *core = i2c_mfd_cell_to_core(codec_dai->dev); | ||
| 118 | int err; | 77 | int err; |
| 119 | u16 format = 0; | 78 | u16 format = 0; |
| 120 | 79 | ||
| @@ -178,9 +137,14 @@ static int si476x_codec_set_dai_fmt(struct snd_soc_dai *codec_dai, | |||
| 178 | return -EINVAL; | 137 | return -EINVAL; |
| 179 | } | 138 | } |
| 180 | 139 | ||
| 140 | si476x_core_lock(core); | ||
| 141 | |||
| 181 | err = snd_soc_update_bits(codec_dai->codec, SI476X_DIGITAL_IO_OUTPUT_FORMAT, | 142 | err = snd_soc_update_bits(codec_dai->codec, SI476X_DIGITAL_IO_OUTPUT_FORMAT, |
| 182 | SI476X_DIGITAL_IO_OUTPUT_FORMAT_MASK, | 143 | SI476X_DIGITAL_IO_OUTPUT_FORMAT_MASK, |
| 183 | format); | 144 | format); |
| 145 | |||
| 146 | si476x_core_unlock(core); | ||
| 147 | |||
| 184 | if (err < 0) { | 148 | if (err < 0) { |
| 185 | dev_err(codec_dai->codec->dev, "Failed to set output format\n"); | 149 | dev_err(codec_dai->codec->dev, "Failed to set output format\n"); |
| 186 | return err; | 150 | return err; |
| @@ -193,6 +157,7 @@ static int si476x_codec_hw_params(struct snd_pcm_substream *substream, | |||
| 193 | struct snd_pcm_hw_params *params, | 157 | struct snd_pcm_hw_params *params, |
| 194 | struct snd_soc_dai *dai) | 158 | struct snd_soc_dai *dai) |
| 195 | { | 159 | { |
| 160 | struct si476x_core *core = i2c_mfd_cell_to_core(dai->dev); | ||
| 196 | int rate, width, err; | 161 | int rate, width, err; |
| 197 | 162 | ||
| 198 | rate = params_rate(params); | 163 | rate = params_rate(params); |
| @@ -218,11 +183,13 @@ static int si476x_codec_hw_params(struct snd_pcm_substream *substream, | |||
| 218 | return -EINVAL; | 183 | return -EINVAL; |
| 219 | } | 184 | } |
| 220 | 185 | ||
| 186 | si476x_core_lock(core); | ||
| 187 | |||
| 221 | err = snd_soc_write(dai->codec, SI476X_DIGITAL_IO_OUTPUT_SAMPLE_RATE, | 188 | err = snd_soc_write(dai->codec, SI476X_DIGITAL_IO_OUTPUT_SAMPLE_RATE, |
| 222 | rate); | 189 | rate); |
| 223 | if (err < 0) { | 190 | if (err < 0) { |
| 224 | dev_err(dai->codec->dev, "Failed to set sample rate\n"); | 191 | dev_err(dai->codec->dev, "Failed to set sample rate\n"); |
| 225 | return err; | 192 | goto out; |
| 226 | } | 193 | } |
| 227 | 194 | ||
| 228 | err = snd_soc_update_bits(dai->codec, SI476X_DIGITAL_IO_OUTPUT_FORMAT, | 195 | err = snd_soc_update_bits(dai->codec, SI476X_DIGITAL_IO_OUTPUT_FORMAT, |
| @@ -231,15 +198,18 @@ static int si476x_codec_hw_params(struct snd_pcm_substream *substream, | |||
| 231 | (width << SI476X_DIGITAL_IO_SAMPLE_SIZE_SHIFT)); | 198 | (width << SI476X_DIGITAL_IO_SAMPLE_SIZE_SHIFT)); |
| 232 | if (err < 0) { | 199 | if (err < 0) { |
| 233 | dev_err(dai->codec->dev, "Failed to set output width\n"); | 200 | dev_err(dai->codec->dev, "Failed to set output width\n"); |
| 234 | return err; | 201 | goto out; |
| 235 | } | 202 | } |
| 236 | 203 | ||
| 237 | return 0; | 204 | out: |
| 205 | si476x_core_unlock(core); | ||
| 206 | |||
| 207 | return err; | ||
| 238 | } | 208 | } |
| 239 | 209 | ||
| 240 | static int si476x_codec_probe(struct snd_soc_codec *codec) | 210 | static int si476x_codec_probe(struct snd_soc_codec *codec) |
| 241 | { | 211 | { |
| 242 | codec->control_data = i2c_mfd_cell_to_core(codec->dev); | 212 | codec->control_data = dev_get_regmap(codec->dev->parent, NULL); |
| 243 | return 0; | 213 | return 0; |
| 244 | } | 214 | } |
| 245 | 215 | ||
| @@ -268,8 +238,6 @@ static struct snd_soc_dai_driver si476x_dai = { | |||
| 268 | 238 | ||
| 269 | static struct snd_soc_codec_driver soc_codec_dev_si476x = { | 239 | static struct snd_soc_codec_driver soc_codec_dev_si476x = { |
| 270 | .probe = si476x_codec_probe, | 240 | .probe = si476x_codec_probe, |
| 271 | .read = si476x_codec_read, | ||
| 272 | .write = si476x_codec_write, | ||
| 273 | .dapm_widgets = si476x_dapm_widgets, | 241 | .dapm_widgets = si476x_dapm_widgets, |
| 274 | .num_dapm_widgets = ARRAY_SIZE(si476x_dapm_widgets), | 242 | .num_dapm_widgets = ARRAY_SIZE(si476x_dapm_widgets), |
| 275 | .dapm_routes = si476x_dapm_routes, | 243 | .dapm_routes = si476x_dapm_routes, |
