pcm1681.c (cf40a76e7d5874bb25f4404eecc58a2e033af885) | pcm1681.c (7dbbaa5180cb380ac28f023dda8663d8dd3b8b56) |
---|---|
1/* 2 * PCM1681 ASoC codec driver 3 * 4 * Copyright (c) StreamUnlimited GmbH 2013 5 * Marek Belisko <marek.belisko@streamunlimited.com> 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License --- 76 unchanged lines hidden (view full) --- 85 /* Current deemphasis status */ 86 unsigned int deemph; 87 /* Current rate for deemphasis control */ 88 unsigned int rate; 89}; 90 91static const int pcm1681_deemph[] = { 44100, 48000, 32000 }; 92 | 1/* 2 * PCM1681 ASoC codec driver 3 * 4 * Copyright (c) StreamUnlimited GmbH 2013 5 * Marek Belisko <marek.belisko@streamunlimited.com> 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License --- 76 unchanged lines hidden (view full) --- 85 /* Current deemphasis status */ 86 unsigned int deemph; 87 /* Current rate for deemphasis control */ 88 unsigned int rate; 89}; 90 91static const int pcm1681_deemph[] = { 44100, 48000, 32000 }; 92 |
93static int pcm1681_set_deemph(struct snd_soc_codec *codec) | 93static int pcm1681_set_deemph(struct snd_soc_component *component) |
94{ | 94{ |
95 struct pcm1681_private *priv = snd_soc_codec_get_drvdata(codec); | 95 struct pcm1681_private *priv = snd_soc_component_get_drvdata(component); |
96 int i = 0, val = -1, enable = 0; 97 98 if (priv->deemph) { 99 for (i = 0; i < ARRAY_SIZE(pcm1681_deemph); i++) { 100 if (pcm1681_deemph[i] == priv->rate) { 101 val = i; 102 break; 103 } --- 11 unchanged lines hidden (view full) --- 115 /* enable/disable deemphasis functionality */ 116 return regmap_update_bits(priv->regmap, PCM1681_DEEMPH_CONTROL, 117 PCM1681_DEEMPH_MASK, enable); 118} 119 120static int pcm1681_get_deemph(struct snd_kcontrol *kcontrol, 121 struct snd_ctl_elem_value *ucontrol) 122{ | 96 int i = 0, val = -1, enable = 0; 97 98 if (priv->deemph) { 99 for (i = 0; i < ARRAY_SIZE(pcm1681_deemph); i++) { 100 if (pcm1681_deemph[i] == priv->rate) { 101 val = i; 102 break; 103 } --- 11 unchanged lines hidden (view full) --- 115 /* enable/disable deemphasis functionality */ 116 return regmap_update_bits(priv->regmap, PCM1681_DEEMPH_CONTROL, 117 PCM1681_DEEMPH_MASK, enable); 118} 119 120static int pcm1681_get_deemph(struct snd_kcontrol *kcontrol, 121 struct snd_ctl_elem_value *ucontrol) 122{ |
123 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); 124 struct pcm1681_private *priv = snd_soc_codec_get_drvdata(codec); | 123 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); 124 struct pcm1681_private *priv = snd_soc_component_get_drvdata(component); |
125 126 ucontrol->value.integer.value[0] = priv->deemph; 127 128 return 0; 129} 130 131static int pcm1681_put_deemph(struct snd_kcontrol *kcontrol, 132 struct snd_ctl_elem_value *ucontrol) 133{ | 125 126 ucontrol->value.integer.value[0] = priv->deemph; 127 128 return 0; 129} 130 131static int pcm1681_put_deemph(struct snd_kcontrol *kcontrol, 132 struct snd_ctl_elem_value *ucontrol) 133{ |
134 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); 135 struct pcm1681_private *priv = snd_soc_codec_get_drvdata(codec); | 134 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); 135 struct pcm1681_private *priv = snd_soc_component_get_drvdata(component); |
136 137 priv->deemph = ucontrol->value.integer.value[0]; 138 | 136 137 priv->deemph = ucontrol->value.integer.value[0]; 138 |
139 return pcm1681_set_deemph(codec); | 139 return pcm1681_set_deemph(component); |
140} 141 142static int pcm1681_set_dai_fmt(struct snd_soc_dai *codec_dai, 143 unsigned int format) 144{ | 140} 141 142static int pcm1681_set_dai_fmt(struct snd_soc_dai *codec_dai, 143 unsigned int format) 144{ |
145 struct snd_soc_codec *codec = codec_dai->codec; 146 struct pcm1681_private *priv = snd_soc_codec_get_drvdata(codec); | 145 struct snd_soc_component *component = codec_dai->component; 146 struct pcm1681_private *priv = snd_soc_component_get_drvdata(component); |
147 148 /* The PCM1681 can only be slave to all clocks */ 149 if ((format & SND_SOC_DAIFMT_MASTER_MASK) != SND_SOC_DAIFMT_CBS_CFS) { | 147 148 /* The PCM1681 can only be slave to all clocks */ 149 if ((format & SND_SOC_DAIFMT_MASTER_MASK) != SND_SOC_DAIFMT_CBS_CFS) { |
150 dev_err(codec->dev, "Invalid clocking mode\n"); | 150 dev_err(component->dev, "Invalid clocking mode\n"); |
151 return -EINVAL; 152 } 153 154 priv->format = format; 155 156 return 0; 157} 158 159static int pcm1681_digital_mute(struct snd_soc_dai *dai, int mute) 160{ | 151 return -EINVAL; 152 } 153 154 priv->format = format; 155 156 return 0; 157} 158 159static int pcm1681_digital_mute(struct snd_soc_dai *dai, int mute) 160{ |
161 struct snd_soc_codec *codec = dai->codec; 162 struct pcm1681_private *priv = snd_soc_codec_get_drvdata(codec); | 161 struct snd_soc_component *component = dai->component; 162 struct pcm1681_private *priv = snd_soc_component_get_drvdata(component); |
163 int val; 164 165 if (mute) 166 val = PCM1681_SOFT_MUTE_ALL; 167 else 168 val = 0; 169 170 return regmap_write(priv->regmap, PCM1681_SOFT_MUTE, val); 171} 172 173static int pcm1681_hw_params(struct snd_pcm_substream *substream, 174 struct snd_pcm_hw_params *params, 175 struct snd_soc_dai *dai) 176{ | 163 int val; 164 165 if (mute) 166 val = PCM1681_SOFT_MUTE_ALL; 167 else 168 val = 0; 169 170 return regmap_write(priv->regmap, PCM1681_SOFT_MUTE, val); 171} 172 173static int pcm1681_hw_params(struct snd_pcm_substream *substream, 174 struct snd_pcm_hw_params *params, 175 struct snd_soc_dai *dai) 176{ |
177 struct snd_soc_codec *codec = dai->codec; 178 struct pcm1681_private *priv = snd_soc_codec_get_drvdata(codec); | 177 struct snd_soc_component *component = dai->component; 178 struct pcm1681_private *priv = snd_soc_component_get_drvdata(component); |
179 int val = 0, ret; 180 181 priv->rate = params_rate(params); 182 183 switch (priv->format & SND_SOC_DAIFMT_FORMAT_MASK) { 184 case SND_SOC_DAIFMT_RIGHT_J: 185 switch (params_width(params)) { 186 case 24: --- 8 unchanged lines hidden (view full) --- 195 break; 196 case SND_SOC_DAIFMT_I2S: 197 val = 0x04; 198 break; 199 case SND_SOC_DAIFMT_LEFT_J: 200 val = 0x05; 201 break; 202 default: | 179 int val = 0, ret; 180 181 priv->rate = params_rate(params); 182 183 switch (priv->format & SND_SOC_DAIFMT_FORMAT_MASK) { 184 case SND_SOC_DAIFMT_RIGHT_J: 185 switch (params_width(params)) { 186 case 24: --- 8 unchanged lines hidden (view full) --- 195 break; 196 case SND_SOC_DAIFMT_I2S: 197 val = 0x04; 198 break; 199 case SND_SOC_DAIFMT_LEFT_J: 200 val = 0x05; 201 break; 202 default: |
203 dev_err(codec->dev, "Invalid DAI format\n"); | 203 dev_err(component->dev, "Invalid DAI format\n"); |
204 return -EINVAL; 205 } 206 207 ret = regmap_update_bits(priv->regmap, PCM1681_FMT_CONTROL, 0x0f, val); 208 if (ret < 0) 209 return ret; 210 | 204 return -EINVAL; 205 } 206 207 ret = regmap_update_bits(priv->regmap, PCM1681_FMT_CONTROL, 0x0f, val); 208 if (ret < 0) 209 return ret; 210 |
211 return pcm1681_set_deemph(codec); | 211 return pcm1681_set_deemph(component); |
212} 213 214static const struct snd_soc_dai_ops pcm1681_dai_ops = { 215 .set_fmt = pcm1681_set_dai_fmt, 216 .hw_params = pcm1681_hw_params, 217 .digital_mute = pcm1681_digital_mute, 218}; 219 --- 63 unchanged lines hidden (view full) --- 283 .val_bits = 8, 284 .max_register = 0x13, 285 .reg_defaults = pcm1681_reg_defaults, 286 .num_reg_defaults = ARRAY_SIZE(pcm1681_reg_defaults), 287 .writeable_reg = pcm1681_writeable_reg, 288 .readable_reg = pcm1681_accessible_reg, 289}; 290 | 212} 213 214static const struct snd_soc_dai_ops pcm1681_dai_ops = { 215 .set_fmt = pcm1681_set_dai_fmt, 216 .hw_params = pcm1681_hw_params, 217 .digital_mute = pcm1681_digital_mute, 218}; 219 --- 63 unchanged lines hidden (view full) --- 283 .val_bits = 8, 284 .max_register = 0x13, 285 .reg_defaults = pcm1681_reg_defaults, 286 .num_reg_defaults = ARRAY_SIZE(pcm1681_reg_defaults), 287 .writeable_reg = pcm1681_writeable_reg, 288 .readable_reg = pcm1681_accessible_reg, 289}; 290 |
291static const struct snd_soc_codec_driver soc_codec_dev_pcm1681 = { 292 .component_driver = { 293 .controls = pcm1681_controls, 294 .num_controls = ARRAY_SIZE(pcm1681_controls), 295 .dapm_widgets = pcm1681_dapm_widgets, 296 .num_dapm_widgets = ARRAY_SIZE(pcm1681_dapm_widgets), 297 .dapm_routes = pcm1681_dapm_routes, 298 .num_dapm_routes = ARRAY_SIZE(pcm1681_dapm_routes), 299 }, | 291static const struct snd_soc_component_driver soc_component_dev_pcm1681 = { 292 .controls = pcm1681_controls, 293 .num_controls = ARRAY_SIZE(pcm1681_controls), 294 .dapm_widgets = pcm1681_dapm_widgets, 295 .num_dapm_widgets = ARRAY_SIZE(pcm1681_dapm_widgets), 296 .dapm_routes = pcm1681_dapm_routes, 297 .num_dapm_routes = ARRAY_SIZE(pcm1681_dapm_routes), 298 .idle_bias_on = 1, 299 .use_pmdown_time = 1, 300 .endianness = 1, 301 .non_legacy_dai_naming = 1, |
300}; 301 302static const struct i2c_device_id pcm1681_i2c_id[] = { 303 {"pcm1681", 0}, 304 {} 305}; 306MODULE_DEVICE_TABLE(i2c, pcm1681_i2c_id); 307 --- 11 unchanged lines hidden (view full) --- 319 if (IS_ERR(priv->regmap)) { 320 ret = PTR_ERR(priv->regmap); 321 dev_err(&client->dev, "Failed to create regmap: %d\n", ret); 322 return ret; 323 } 324 325 i2c_set_clientdata(client, priv); 326 | 302}; 303 304static const struct i2c_device_id pcm1681_i2c_id[] = { 305 {"pcm1681", 0}, 306 {} 307}; 308MODULE_DEVICE_TABLE(i2c, pcm1681_i2c_id); 309 --- 11 unchanged lines hidden (view full) --- 321 if (IS_ERR(priv->regmap)) { 322 ret = PTR_ERR(priv->regmap); 323 dev_err(&client->dev, "Failed to create regmap: %d\n", ret); 324 return ret; 325 } 326 327 i2c_set_clientdata(client, priv); 328 |
327 return snd_soc_register_codec(&client->dev, &soc_codec_dev_pcm1681, | 329 return devm_snd_soc_register_component(&client->dev, 330 &soc_component_dev_pcm1681, |
328 &pcm1681_dai, 1); 329} 330 | 331 &pcm1681_dai, 1); 332} 333 |
331static int pcm1681_i2c_remove(struct i2c_client *client) 332{ 333 snd_soc_unregister_codec(&client->dev); 334 return 0; 335} 336 | |
337static struct i2c_driver pcm1681_i2c_driver = { 338 .driver = { 339 .name = "pcm1681", 340 .of_match_table = of_match_ptr(pcm1681_dt_ids), 341 }, 342 .id_table = pcm1681_i2c_id, 343 .probe = pcm1681_i2c_probe, | 334static struct i2c_driver pcm1681_i2c_driver = { 335 .driver = { 336 .name = "pcm1681", 337 .of_match_table = of_match_ptr(pcm1681_dt_ids), 338 }, 339 .id_table = pcm1681_i2c_id, 340 .probe = pcm1681_i2c_probe, |
344 .remove = pcm1681_i2c_remove, | |
345}; 346 347module_i2c_driver(pcm1681_i2c_driver); 348 349MODULE_DESCRIPTION("Texas Instruments PCM1681 ALSA SoC Codec Driver"); 350MODULE_AUTHOR("Marek Belisko <marek.belisko@streamunlimited.com>"); 351MODULE_LICENSE("GPL"); | 341}; 342 343module_i2c_driver(pcm1681_i2c_driver); 344 345MODULE_DESCRIPTION("Texas Instruments PCM1681 ALSA SoC Codec Driver"); 346MODULE_AUTHOR("Marek Belisko <marek.belisko@streamunlimited.com>"); 347MODULE_LICENSE("GPL"); |