diff options
Diffstat (limited to 'sound/soc/codecs/cs4270.c')
| -rw-r--r-- | sound/soc/codecs/cs4270.c | 235 |
1 files changed, 120 insertions, 115 deletions
diff --git a/sound/soc/codecs/cs4270.c b/sound/soc/codecs/cs4270.c index 8e4779812b96..3139f03cd42b 100644 --- a/sound/soc/codecs/cs4270.c +++ b/sound/soc/codecs/cs4270.c @@ -21,6 +21,7 @@ * - Power management is supported */ +#include <linux/mod_devicetable.h> #include <linux/module.h> #include <linux/slab.h> #include <sound/core.h> @@ -29,21 +30,11 @@ #include <linux/i2c.h> #include <linux/delay.h> #include <linux/regulator/consumer.h> -#include <linux/of_device.h> -#include <linux/of_gpio.h> +#include <linux/gpio/consumer.h> -/* - * The codec isn't really big-endian or little-endian, since the I2S - * interface requires data to be sent serially with the MSbit first. - * However, to support BE and LE I2S devices, we specify both here. That - * way, ALSA will always match the bit patterns. - */ -#define CS4270_FORMATS (SNDRV_PCM_FMTBIT_S8 | \ - SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE | \ - SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE | \ - SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE | \ - SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S24_3BE | \ - SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE) +#define CS4270_FORMATS (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE | \ + SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S20_3LE | \ + SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S24_LE) /* CS4270 registers addresses */ #define CS4270_CHIPID 0x01 /* Chip ID */ @@ -137,6 +128,25 @@ struct cs4270_private { /* power domain regulators */ struct regulator_bulk_data supplies[ARRAY_SIZE(supply_names)]; + + /* reset gpio */ + struct gpio_desc *reset_gpio; +}; + +static const struct snd_soc_dapm_widget cs4270_dapm_widgets[] = { +SND_SOC_DAPM_INPUT("AINL"), +SND_SOC_DAPM_INPUT("AINR"), + +SND_SOC_DAPM_OUTPUT("AOUTL"), +SND_SOC_DAPM_OUTPUT("AOUTR"), +}; + +static const struct snd_soc_dapm_route cs4270_dapm_routes[] = { + { "Capture", NULL, "AINL" }, + { "Capture", NULL, "AINR" }, + + { "AOUTL", NULL, "Playback" }, + { "AOUTR", NULL, "Playback" }, }; /** @@ -203,7 +213,7 @@ static bool cs4270_reg_is_volatile(struct device *dev, unsigned int reg) { /* Unreadable registers are considered volatile */ if ((reg < CS4270_FIRSTREG) || (reg > CS4270_LASTREG)) - return 1; + return true; return reg == CS4270_CHIPID; } @@ -238,8 +248,8 @@ static bool cs4270_reg_is_volatile(struct device *dev, unsigned int reg) static int cs4270_set_dai_sysclk(struct snd_soc_dai *codec_dai, int clk_id, unsigned int freq, int dir) { - struct snd_soc_codec *codec = codec_dai->codec; - struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = codec_dai->component; + struct cs4270_private *cs4270 = snd_soc_component_get_drvdata(component); cs4270->mclk = freq; return 0; @@ -261,8 +271,8 @@ static int cs4270_set_dai_sysclk(struct snd_soc_dai *codec_dai, static int cs4270_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int format) { - struct snd_soc_codec *codec = codec_dai->codec; - struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = codec_dai->component; + struct cs4270_private *cs4270 = snd_soc_component_get_drvdata(component); /* set DAI format */ switch (format & SND_SOC_DAIFMT_FORMAT_MASK) { @@ -271,21 +281,21 @@ static int cs4270_set_dai_fmt(struct snd_soc_dai *codec_dai, cs4270->mode = format & SND_SOC_DAIFMT_FORMAT_MASK; break; default: - dev_err(codec->dev, "invalid dai format\n"); + dev_err(component->dev, "invalid dai format\n"); return -EINVAL; } /* set master/slave audio interface */ switch (format & SND_SOC_DAIFMT_MASTER_MASK) { - case SND_SOC_DAIFMT_CBS_CFS: + case SND_SOC_DAIFMT_CBC_CFC: cs4270->slave_mode = 1; break; - case SND_SOC_DAIFMT_CBM_CFM: + case SND_SOC_DAIFMT_CBP_CFP: cs4270->slave_mode = 0; break; default: /* all other modes are unsupported by the hardware */ - dev_err(codec->dev, "Unknown master/slave configuration\n"); + dev_err(component->dev, "Unknown master/slave configuration\n"); return -EINVAL; } @@ -310,8 +320,8 @@ static int cs4270_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) { - struct snd_soc_codec *codec = dai->codec; - struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct cs4270_private *cs4270 = snd_soc_component_get_drvdata(component); int ret; unsigned int i; unsigned int rate; @@ -330,13 +340,13 @@ static int cs4270_hw_params(struct snd_pcm_substream *substream, if (i == NUM_MCLK_RATIOS) { /* We did not find a matching ratio */ - dev_err(codec->dev, "could not find matching ratio\n"); + dev_err(component->dev, "could not find matching ratio\n"); return -EINVAL; } /* Set the sample rate */ - reg = snd_soc_read(codec, CS4270_MODE); + reg = snd_soc_component_read(component, CS4270_MODE); reg &= ~(CS4270_MODE_SPEED_MASK | CS4270_MODE_DIV_MASK); reg |= cs4270_mode_ratios[i].mclk; @@ -345,15 +355,15 @@ static int cs4270_hw_params(struct snd_pcm_substream *substream, else reg |= cs4270_mode_ratios[i].speed_mode; - ret = snd_soc_write(codec, CS4270_MODE, reg); + ret = snd_soc_component_write(component, CS4270_MODE, reg); if (ret < 0) { - dev_err(codec->dev, "i2c write failed\n"); + dev_err(component->dev, "i2c write failed\n"); return ret; } /* Set the DAI format */ - reg = snd_soc_read(codec, CS4270_FORMAT); + reg = snd_soc_component_read(component, CS4270_FORMAT); reg &= ~(CS4270_FORMAT_DAC_MASK | CS4270_FORMAT_ADC_MASK); switch (cs4270->mode) { @@ -364,13 +374,13 @@ static int cs4270_hw_params(struct snd_pcm_substream *substream, reg |= CS4270_FORMAT_DAC_LJ | CS4270_FORMAT_ADC_LJ; break; default: - dev_err(codec->dev, "unknown dai format\n"); + dev_err(component->dev, "unknown dai format\n"); return -EINVAL; } - ret = snd_soc_write(codec, CS4270_FORMAT, reg); + ret = snd_soc_component_write(component, CS4270_FORMAT, reg); if (ret < 0) { - dev_err(codec->dev, "i2c write failed\n"); + dev_err(component->dev, "i2c write failed\n"); return ret; } @@ -381,19 +391,20 @@ static int cs4270_hw_params(struct snd_pcm_substream *substream, * cs4270_dai_mute - enable/disable the CS4270 external mute * @dai: the SOC DAI * @mute: 0 = disable mute, 1 = enable mute + * @direction: (ignored) * * This function toggles the mute bits in the MUTE register. The CS4270's * mute capability is intended for external muting circuitry, so if the * board does not have the MUTEA or MUTEB pins connected to such circuitry, * then this function will do nothing. */ -static int cs4270_dai_mute(struct snd_soc_dai *dai, int mute) +static int cs4270_dai_mute(struct snd_soc_dai *dai, int mute, int direction) { - struct snd_soc_codec *codec = dai->codec; - struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = dai->component; + struct cs4270_private *cs4270 = snd_soc_component_get_drvdata(component); int reg6; - reg6 = snd_soc_read(codec, CS4270_MUTE); + reg6 = snd_soc_component_read(component, CS4270_MUTE); if (mute) reg6 |= CS4270_MUTE_DAC_A | CS4270_MUTE_DAC_B; @@ -402,7 +413,7 @@ static int cs4270_dai_mute(struct snd_soc_dai *dai, int mute) reg6 |= cs4270->manual_mute; } - return snd_soc_write(codec, CS4270_MUTE, reg6); + return snd_soc_component_write(component, CS4270_MUTE, reg6); } /** @@ -422,8 +433,8 @@ static int cs4270_dai_mute(struct snd_soc_dai *dai, int mute) static int cs4270_soc_put_mute(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); - struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec); + struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); + struct cs4270_private *cs4270 = snd_soc_component_get_drvdata(component); int left = !ucontrol->value.integer.value[0]; int right = !ucontrol->value.integer.value[1]; @@ -452,7 +463,8 @@ static const struct snd_soc_dai_ops cs4270_dai_ops = { .hw_params = cs4270_hw_params, .set_sysclk = cs4270_set_dai_sysclk, .set_fmt = cs4270_set_dai_fmt, - .digital_mute = cs4270_dai_mute, + .mute_stream = cs4270_dai_mute, + .no_capture_mute = 1, }; static struct snd_soc_dai_driver cs4270_dai = { @@ -480,33 +492,24 @@ static struct snd_soc_dai_driver cs4270_dai = { /** * cs4270_probe - ASoC probe function - * @pdev: platform device + * @component: ASoC component * * This function is called when ASoC has all the pieces it needs to * instantiate a sound driver. */ -static int cs4270_probe(struct snd_soc_codec *codec) +static int cs4270_probe(struct snd_soc_component *component) { - struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec); + struct cs4270_private *cs4270 = snd_soc_component_get_drvdata(component); int ret; - /* Tell ASoC what kind of I/O to use to read the registers. ASoC will - * then do the I2C transactions itself. - */ - ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP); - if (ret < 0) { - dev_err(codec->dev, "failed to set cache I/O (ret=%i)\n", ret); - return ret; - } - /* Disable auto-mute. This feature appears to be buggy. In some * situations, auto-mute will not deactivate when it should, so we want * this feature disabled by default. An application (e.g. alsactl) can * re-enabled it by using the controls. */ - ret = snd_soc_update_bits(codec, CS4270_MUTE, CS4270_MUTE_AUTO, 0); + ret = snd_soc_component_update_bits(component, CS4270_MUTE, CS4270_MUTE_AUTO, 0); if (ret < 0) { - dev_err(codec->dev, "i2c write failed\n"); + dev_err(component->dev, "i2c write failed\n"); return ret; } @@ -515,10 +518,10 @@ static int cs4270_probe(struct snd_soc_codec *codec) * playback has started. An application (e.g. alsactl) can * re-enabled it by using the controls. */ - ret = snd_soc_update_bits(codec, CS4270_TRANS, + ret = snd_soc_component_update_bits(component, CS4270_TRANS, CS4270_TRANS_SOFT | CS4270_TRANS_ZERO, 0); if (ret < 0) { - dev_err(codec->dev, "i2c write failed\n"); + dev_err(component->dev, "i2c write failed\n"); return ret; } @@ -530,17 +533,15 @@ static int cs4270_probe(struct snd_soc_codec *codec) /** * cs4270_remove - ASoC remove function - * @pdev: platform device + * @component: ASoC component * * This function is the counterpart to cs4270_probe(). */ -static int cs4270_remove(struct snd_soc_codec *codec) +static void cs4270_remove(struct snd_soc_component *component) { - struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec); + struct cs4270_private *cs4270 = snd_soc_component_get_drvdata(component); regulator_bulk_disable(ARRAY_SIZE(cs4270->supplies), cs4270->supplies); - - return 0; }; #ifdef CONFIG_PM @@ -554,16 +555,16 @@ static int cs4270_remove(struct snd_soc_codec *codec) * and all registers are written back to the hardware when resuming. */ -static int cs4270_soc_suspend(struct snd_soc_codec *codec) +static int cs4270_soc_suspend(struct snd_soc_component *component) { - struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec); + struct cs4270_private *cs4270 = snd_soc_component_get_drvdata(component); int reg, ret; - reg = snd_soc_read(codec, CS4270_PWRCTL) | CS4270_PWRCTL_PDN_ALL; + reg = snd_soc_component_read(component, CS4270_PWRCTL) | CS4270_PWRCTL_PDN_ALL; if (reg < 0) return reg; - ret = snd_soc_write(codec, CS4270_PWRCTL, reg); + ret = snd_soc_component_write(component, CS4270_PWRCTL, reg); if (ret < 0) return ret; @@ -573,9 +574,9 @@ static int cs4270_soc_suspend(struct snd_soc_codec *codec) return 0; } -static int cs4270_soc_resume(struct snd_soc_codec *codec) +static int cs4270_soc_resume(struct snd_soc_component *component) { - struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec); + struct cs4270_private *cs4270 = snd_soc_component_get_drvdata(component); int reg, ret; ret = regulator_bulk_enable(ARRAY_SIZE(cs4270->supplies), @@ -591,10 +592,10 @@ static int cs4270_soc_resume(struct snd_soc_codec *codec) regcache_sync(cs4270->regmap); /* ... then disable the power-down bits */ - reg = snd_soc_read(codec, CS4270_PWRCTL); + reg = snd_soc_component_read(component, CS4270_PWRCTL); reg &= ~CS4270_PWRCTL_PDN_ALL; - return snd_soc_write(codec, CS4270_PWRCTL, reg); + return snd_soc_component_write(component, CS4270_PWRCTL, reg); } #else #define cs4270_soc_suspend NULL @@ -604,14 +605,20 @@ static int cs4270_soc_resume(struct snd_soc_codec *codec) /* * ASoC codec driver structure */ -static const struct snd_soc_codec_driver soc_codec_device_cs4270 = { - .probe = cs4270_probe, - .remove = cs4270_remove, - .suspend = cs4270_soc_suspend, - .resume = cs4270_soc_resume, - - .controls = cs4270_snd_controls, - .num_controls = ARRAY_SIZE(cs4270_snd_controls), +static const struct snd_soc_component_driver soc_component_device_cs4270 = { + .probe = cs4270_probe, + .remove = cs4270_remove, + .suspend = cs4270_soc_suspend, + .resume = cs4270_soc_resume, + .controls = cs4270_snd_controls, + .num_controls = ARRAY_SIZE(cs4270_snd_controls), + .dapm_widgets = cs4270_dapm_widgets, + .num_dapm_widgets = ARRAY_SIZE(cs4270_dapm_widgets), + .dapm_routes = cs4270_dapm_routes, + .num_dapm_routes = ARRAY_SIZE(cs4270_dapm_routes), + .idle_bias_on = 1, + .use_pmdown_time = 1, + .endianness = 1, }; /* @@ -629,34 +636,44 @@ static const struct regmap_config cs4270_regmap = { .max_register = CS4270_LASTREG, .reg_defaults = cs4270_reg_defaults, .num_reg_defaults = ARRAY_SIZE(cs4270_reg_defaults), - .cache_type = REGCACHE_RBTREE, + .cache_type = REGCACHE_MAPLE, + .write_flag_mask = CS4270_I2C_INCR, .readable_reg = cs4270_reg_is_readable, .volatile_reg = cs4270_reg_is_volatile, }; /** + * cs4270_i2c_remove - deinitialize the I2C interface of the CS4270 + * @i2c_client: the I2C client object + * + * This function puts the chip into low power mode when the i2c device + * is removed. + */ +static void cs4270_i2c_remove(struct i2c_client *i2c_client) +{ + struct cs4270_private *cs4270 = i2c_get_clientdata(i2c_client); + + gpiod_set_value_cansleep(cs4270->reset_gpio, 0); +} + +/** * cs4270_i2c_probe - initialize the I2C interface of the CS4270 * @i2c_client: the I2C client object - * @id: the I2C device ID (ignored) * * This function is called whenever the I2C subsystem finds a device that * matches the device ID given via a prior call to i2c_add_driver(). */ -static int cs4270_i2c_probe(struct i2c_client *i2c_client, - const struct i2c_device_id *id) +static int cs4270_i2c_probe(struct i2c_client *i2c_client) { - struct device_node *np = i2c_client->dev.of_node; struct cs4270_private *cs4270; unsigned int val; int ret, i; cs4270 = devm_kzalloc(&i2c_client->dev, sizeof(struct cs4270_private), GFP_KERNEL); - if (!cs4270) { - dev_err(&i2c_client->dev, "could not allocate codec\n"); + if (!cs4270) return -ENOMEM; - } /* get the power supply regulators */ for (i = 0; i < ARRAY_SIZE(supply_names); i++) @@ -668,21 +685,22 @@ static int cs4270_i2c_probe(struct i2c_client *i2c_client, if (ret < 0) return ret; - /* See if we have a way to bring the codec out of reset */ - if (np) { - enum of_gpio_flags flags; - int gpio = of_get_named_gpio_flags(np, "reset-gpio", 0, &flags); - - if (gpio_is_valid(gpio)) { - ret = devm_gpio_request_one(&i2c_client->dev, gpio, - flags & OF_GPIO_ACTIVE_LOW ? - GPIOF_OUT_INIT_LOW : GPIOF_OUT_INIT_HIGH, - "cs4270 reset"); - if (ret < 0) - return ret; - } + /* reset the device */ + cs4270->reset_gpio = devm_gpiod_get_optional(&i2c_client->dev, "reset", + GPIOD_OUT_LOW); + if (IS_ERR(cs4270->reset_gpio)) { + dev_dbg(&i2c_client->dev, "Error getting CS4270 reset GPIO\n"); + return PTR_ERR(cs4270->reset_gpio); + } + + if (cs4270->reset_gpio) { + dev_dbg(&i2c_client->dev, "Found reset GPIO\n"); + gpiod_set_value_cansleep(cs4270->reset_gpio, 1); } + /* Sleep 500ns before i2c communications */ + ndelay(500); + cs4270->regmap = devm_regmap_init_i2c(i2c_client, &cs4270_regmap); if (IS_ERR(cs4270->regmap)) return PTR_ERR(cs4270->regmap); @@ -707,28 +725,16 @@ static int cs4270_i2c_probe(struct i2c_client *i2c_client, i2c_set_clientdata(i2c_client, cs4270); - ret = snd_soc_register_codec(&i2c_client->dev, - &soc_codec_device_cs4270, &cs4270_dai, 1); + ret = devm_snd_soc_register_component(&i2c_client->dev, + &soc_component_device_cs4270, &cs4270_dai, 1); return ret; } -/** - * cs4270_i2c_remove - remove an I2C device - * @i2c_client: the I2C client object - * - * This function is the counterpart to cs4270_i2c_probe(). - */ -static int cs4270_i2c_remove(struct i2c_client *i2c_client) -{ - snd_soc_unregister_codec(&i2c_client->dev); - return 0; -} - /* * cs4270_id - I2C device IDs supported by this driver */ static const struct i2c_device_id cs4270_id[] = { - {"cs4270", 0}, + {"cs4270"}, {} }; MODULE_DEVICE_TABLE(i2c, cs4270_id); @@ -742,7 +748,6 @@ MODULE_DEVICE_TABLE(i2c, cs4270_id); static struct i2c_driver cs4270_i2c_driver = { .driver = { .name = "cs4270", - .owner = THIS_MODULE, .of_match_table = cs4270_of_match, }, .id_table = cs4270_id, |
