--- zzzz-none-000/linux-3.10.107/sound/soc/codecs/tlv320aic26.c 2017-06-27 09:49:32.000000000 +0000 +++ scorpion-7490-727/linux-3.10.107/sound/soc/codecs/tlv320aic26.c 2021-02-04 17:41:59.000000000 +0000 @@ -29,7 +29,8 @@ /* AIC26 driver private data */ struct aic26 { struct spi_device *spi; - struct snd_soc_codec codec; + struct regmap *regmap; + struct snd_soc_codec *codec; int master; int datfm; int mclk; @@ -40,84 +41,21 @@ int keyclick_len; }; -/* --------------------------------------------------------------------- - * Register access routines - */ -static unsigned int aic26_reg_read(struct snd_soc_codec *codec, - unsigned int reg) -{ - struct aic26 *aic26 = snd_soc_codec_get_drvdata(codec); - u16 *cache = codec->reg_cache; - u16 cmd, value; - u8 buffer[2]; - int rc; - - if (reg >= AIC26_NUM_REGS) { - WARN_ON_ONCE(1); - return 0; - } - - /* Do SPI transfer; first 16bits are command; remaining is - * register contents */ - cmd = AIC26_READ_COMMAND_WORD(reg); - buffer[0] = (cmd >> 8) & 0xff; - buffer[1] = cmd & 0xff; - rc = spi_write_then_read(aic26->spi, buffer, 2, buffer, 2); - if (rc) { - dev_err(&aic26->spi->dev, "AIC26 reg read error\n"); - return -EIO; - } - value = (buffer[0] << 8) | buffer[1]; - - /* Update the cache before returning with the value */ - cache[reg] = value; - return value; -} - -static unsigned int aic26_reg_read_cache(struct snd_soc_codec *codec, - unsigned int reg) -{ - u16 *cache = codec->reg_cache; - - if (reg >= AIC26_NUM_REGS) { - WARN_ON_ONCE(1); - return 0; - } - - return cache[reg]; -} - -static int aic26_reg_write(struct snd_soc_codec *codec, unsigned int reg, - unsigned int value) -{ - struct aic26 *aic26 = snd_soc_codec_get_drvdata(codec); - u16 *cache = codec->reg_cache; - u16 cmd; - u8 buffer[4]; - int rc; +static const struct snd_soc_dapm_widget tlv320aic26_dapm_widgets[] = { +SND_SOC_DAPM_INPUT("MICIN"), +SND_SOC_DAPM_INPUT("AUX"), - if (reg >= AIC26_NUM_REGS) { - WARN_ON_ONCE(1); - return -EINVAL; - } +SND_SOC_DAPM_OUTPUT("HPL"), +SND_SOC_DAPM_OUTPUT("HPR"), +}; - /* Do SPI transfer; first 16bits are command; remaining is data - * to write into register */ - cmd = AIC26_WRITE_COMMAND_WORD(reg); - buffer[0] = (cmd >> 8) & 0xff; - buffer[1] = cmd & 0xff; - buffer[2] = value >> 8; - buffer[3] = value; - rc = spi_write(aic26->spi, buffer, 4); - if (rc) { - dev_err(&aic26->spi->dev, "AIC26 reg read error\n"); - return -EIO; - } +static const struct snd_soc_dapm_route tlv320aic26_dapm_routes[] = { + { "Capture", NULL, "MICIN" }, + { "Capture", NULL, "AUX" }, - /* update cache before returning */ - cache[reg] = value; - return 0; -} + { "HPL", NULL, "Playback" }, + { "HPR", NULL, "Playback" }, +}; /* --------------------------------------------------------------------- * Digital Audio Interface Operations @@ -133,8 +71,8 @@ dev_dbg(&aic26->spi->dev, "aic26_hw_params(substream=%p, params=%p)\n", substream, params); - dev_dbg(&aic26->spi->dev, "rate=%i format=%i\n", params_rate(params), - params_format(params)); + dev_dbg(&aic26->spi->dev, "rate=%i width=%d\n", params_rate(params), + params_width(params)); switch (params_rate(params)) { case 8000: fsref = 48000; divisor = AIC26_DIV_6; break; @@ -151,11 +89,11 @@ } /* select data word length */ - switch (params_format(params)) { - case SNDRV_PCM_FORMAT_S8: wlen = AIC26_WLEN_16; break; - case SNDRV_PCM_FORMAT_S16_BE: wlen = AIC26_WLEN_16; break; - case SNDRV_PCM_FORMAT_S24_BE: wlen = AIC26_WLEN_24; break; - case SNDRV_PCM_FORMAT_S32_BE: wlen = AIC26_WLEN_32; break; + switch (params_width(params)) { + case 8: wlen = AIC26_WLEN_16; break; + case 16: wlen = AIC26_WLEN_16; break; + case 24: wlen = AIC26_WLEN_24; break; + case 32: wlen = AIC26_WLEN_32; break; default: dev_dbg(&aic26->spi->dev, "bad format\n"); return -EINVAL; } @@ -174,24 +112,20 @@ dev_dbg(&aic26->spi->dev, "Setting PLLM to %d.%04d\n", jval, dval); qval = 0; reg = 0x8000 | qval << 11 | pval << 8 | jval << 2; - aic26_reg_write(codec, AIC26_REG_PLL_PROG1, reg); + snd_soc_write(codec, AIC26_REG_PLL_PROG1, reg); reg = dval << 2; - aic26_reg_write(codec, AIC26_REG_PLL_PROG2, reg); + snd_soc_write(codec, AIC26_REG_PLL_PROG2, reg); /* Audio Control 3 (master mode, fsref rate) */ - reg = aic26_reg_read_cache(codec, AIC26_REG_AUDIO_CTRL3); - reg &= ~0xf800; if (aic26->master) - reg |= 0x0800; + reg = 0x0800; if (fsref == 48000) - reg |= 0x2000; - aic26_reg_write(codec, AIC26_REG_AUDIO_CTRL3, reg); + reg = 0x2000; + snd_soc_update_bits(codec, AIC26_REG_AUDIO_CTRL3, 0xf800, reg); /* Audio Control 1 (FSref divisor) */ - reg = aic26_reg_read_cache(codec, AIC26_REG_AUDIO_CTRL1); - reg &= ~0x0fff; - reg |= wlen | aic26->datfm | (divisor << 3) | divisor; - aic26_reg_write(codec, AIC26_REG_AUDIO_CTRL1, reg); + reg = wlen | aic26->datfm | (divisor << 3) | divisor; + snd_soc_update_bits(codec, AIC26_REG_AUDIO_CTRL1, 0xfff, reg); return 0; } @@ -203,16 +137,16 @@ { struct snd_soc_codec *codec = dai->codec; struct aic26 *aic26 = snd_soc_codec_get_drvdata(codec); - u16 reg = aic26_reg_read_cache(codec, AIC26_REG_DAC_GAIN); + u16 reg; dev_dbg(&aic26->spi->dev, "aic26_mute(dai=%p, mute=%i)\n", dai, mute); if (mute) - reg |= 0x8080; + reg = 0x8080; else - reg &= ~0x8080; - aic26_reg_write(codec, AIC26_REG_DAC_GAIN, reg); + reg = 0; + snd_soc_update_bits(codec, AIC26_REG_DAC_GAIN, 0x8000, reg); return 0; } @@ -304,8 +238,9 @@ * ALSA controls */ static const char *aic26_capture_src_text[] = {"Mic", "Aux"}; -static const struct soc_enum aic26_capture_src_enum = - SOC_ENUM_SINGLE(AIC26_REG_AUDIO_CTRL1, 12, 2, aic26_capture_src_text); +static SOC_ENUM_SINGLE_DECL(aic26_capture_src_enum, + AIC26_REG_AUDIO_CTRL1, 12, + aic26_capture_src_text); static const struct snd_kcontrol_new aic26_snd_controls[] = { /* Output */ @@ -330,7 +265,7 @@ struct aic26 *aic26 = dev_get_drvdata(dev); int val, amp, freq, len; - val = aic26_reg_read_cache(&aic26->codec, AIC26_REG_AUDIO_CTRL2); + val = snd_soc_read(aic26->codec, AIC26_REG_AUDIO_CTRL2); amp = (val >> 12) & 0x7; freq = (125 << ((val >> 8) & 0x7)) >> 1; len = 2 * (1 + ((val >> 4) & 0xf)); @@ -344,11 +279,9 @@ const char *buf, size_t count) { struct aic26 *aic26 = dev_get_drvdata(dev); - int val; - val = aic26_reg_read_cache(&aic26->codec, AIC26_REG_AUDIO_CTRL2); - val |= 0x8000; - aic26_reg_write(&aic26->codec, AIC26_REG_AUDIO_CTRL2, val); + snd_soc_update_bits(aic26->codec, AIC26_REG_AUDIO_CTRL2, + 0x8000, 0x800); return count; } @@ -360,25 +293,22 @@ */ static int aic26_probe(struct snd_soc_codec *codec) { - int ret, err, i, reg; + struct aic26 *aic26 = dev_get_drvdata(codec->dev); + int ret, reg; - dev_info(codec->dev, "Probing AIC26 SoC CODEC driver\n"); + aic26->codec = codec; /* Reset the codec to power on defaults */ - aic26_reg_write(codec, AIC26_REG_RESET, 0xBB00); + snd_soc_write(codec, AIC26_REG_RESET, 0xBB00); /* Power up CODEC */ - aic26_reg_write(codec, AIC26_REG_POWER_CTRL, 0); + snd_soc_write(codec, AIC26_REG_POWER_CTRL, 0); /* Audio Control 3 (master mode, fsref rate) */ - reg = aic26_reg_read(codec, AIC26_REG_AUDIO_CTRL3); + reg = snd_soc_read(codec, AIC26_REG_AUDIO_CTRL3); reg &= ~0xf800; reg |= 0x0800; /* set master mode */ - aic26_reg_write(codec, AIC26_REG_AUDIO_CTRL3, reg); - - /* Fill register cache */ - for (i = 0; i < codec->driver->reg_cache_size; i++) - aic26_reg_read(codec, i); + snd_soc_write(codec, AIC26_REG_AUDIO_CTRL3, reg); /* Register the sysfs files for debugging */ /* Create SysFS files */ @@ -386,21 +316,22 @@ if (ret) dev_info(codec->dev, "error creating sysfs files\n"); - /* register controls */ - dev_dbg(codec->dev, "Registering controls\n"); - err = snd_soc_add_codec_controls(codec, aic26_snd_controls, - ARRAY_SIZE(aic26_snd_controls)); - WARN_ON(err < 0); - return 0; } static struct snd_soc_codec_driver aic26_soc_codec_dev = { .probe = aic26_probe, - .read = aic26_reg_read, - .write = aic26_reg_write, - .reg_cache_size = AIC26_NUM_REGS, - .reg_word_size = sizeof(u16), + .controls = aic26_snd_controls, + .num_controls = ARRAY_SIZE(aic26_snd_controls), + .dapm_widgets = tlv320aic26_dapm_widgets, + .num_dapm_widgets = ARRAY_SIZE(tlv320aic26_dapm_widgets), + .dapm_routes = tlv320aic26_dapm_routes, + .num_dapm_routes = ARRAY_SIZE(tlv320aic26_dapm_routes), +}; + +static const struct regmap_config aic26_regmap = { + .reg_bits = 16, + .val_bits = 16, }; /* --------------------------------------------------------------------- @@ -419,6 +350,10 @@ if (!aic26) return -ENOMEM; + aic26->regmap = devm_regmap_init_spi(spi, &aic26_regmap); + if (IS_ERR(aic26->regmap)) + return PTR_ERR(aic26->regmap); + /* Initialize the driver data */ aic26->spi = spi; dev_set_drvdata(&spi->dev, aic26); @@ -438,7 +373,6 @@ static struct spi_driver aic26_spi = { .driver = { .name = "tlv320aic26-codec", - .owner = THIS_MODULE, }, .probe = aic26_spi_probe, .remove = aic26_spi_remove,