Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ASoC: tlv320aic26: Convert to direct regmap API usage

This moves us towards being able to remove the duplicated register I/O
code in ASoC.

The datasheet and the driver document the device as having a register map
divided into pages but since the paging is actually done by sending the
page address and the register address with each transaction this is no
different to having a simple register address. The datasheet does also
document the low five bits of the 16 bit "command" as unused which we could
represent as padding but it seems simpler and less confusing to things
that use block transfers or autoincrement to represent these as part of
the register address.

Signed-off-by: Mark Brown <broonie@linaro.org>

+13 -72
+12 -68
sound/soc/codecs/tlv320aic26.c
··· 29 29 /* AIC26 driver private data */ 30 30 struct aic26 { 31 31 struct spi_device *spi; 32 + struct regmap *regmap; 32 33 struct snd_soc_codec *codec; 33 34 int master; 34 35 int datfm; ··· 40 39 int keyclick_freq; 41 40 int keyclick_len; 42 41 }; 43 - 44 - /* --------------------------------------------------------------------- 45 - * Register access routines 46 - */ 47 - static unsigned int aic26_reg_read(struct snd_soc_codec *codec, 48 - unsigned int reg) 49 - { 50 - struct aic26 *aic26 = snd_soc_codec_get_drvdata(codec); 51 - u16 *cache = codec->reg_cache; 52 - u16 cmd, value; 53 - u8 buffer[2]; 54 - int rc; 55 - 56 - if (reg >= AIC26_NUM_REGS) { 57 - WARN_ON_ONCE(1); 58 - return 0; 59 - } 60 - 61 - /* Do SPI transfer; first 16bits are command; remaining is 62 - * register contents */ 63 - cmd = AIC26_READ_COMMAND_WORD(reg); 64 - buffer[0] = (cmd >> 8) & 0xff; 65 - buffer[1] = cmd & 0xff; 66 - rc = spi_write_then_read(aic26->spi, buffer, 2, buffer, 2); 67 - if (rc) { 68 - dev_err(&aic26->spi->dev, "AIC26 reg read error\n"); 69 - return -EIO; 70 - } 71 - value = (buffer[0] << 8) | buffer[1]; 72 - 73 - /* Update the cache before returning with the value */ 74 - cache[reg] = value; 75 - return value; 76 - } 77 - 78 - static int aic26_reg_write(struct snd_soc_codec *codec, unsigned int reg, 79 - unsigned int value) 80 - { 81 - struct aic26 *aic26 = snd_soc_codec_get_drvdata(codec); 82 - u16 *cache = codec->reg_cache; 83 - u16 cmd; 84 - u8 buffer[4]; 85 - int rc; 86 - 87 - if (reg >= AIC26_NUM_REGS) { 88 - WARN_ON_ONCE(1); 89 - return -EINVAL; 90 - } 91 - 92 - /* Do SPI transfer; first 16bits are command; remaining is data 93 - * to write into register */ 94 - cmd = AIC26_WRITE_COMMAND_WORD(reg); 95 - buffer[0] = (cmd >> 8) & 0xff; 96 - buffer[1] = cmd & 0xff; 97 - buffer[2] = value >> 8; 98 - buffer[3] = value; 99 - rc = spi_write(aic26->spi, buffer, 4); 100 - if (rc) { 101 - dev_err(&aic26->spi->dev, "AIC26 reg read error\n"); 102 - return -EIO; 103 - } 104 - 105 - /* update cache before returning */ 106 - cache[reg] = value; 107 - return 0; 108 - } 109 42 110 43 static const struct snd_soc_dapm_widget tlv320aic26_dapm_widgets[] = { 111 44 SND_SOC_DAPM_INPUT("MICIN"), ··· 295 360 struct aic26 *aic26 = dev_get_drvdata(codec->dev); 296 361 int ret, reg; 297 362 363 + snd_soc_codec_set_cache_io(codec, 16, 16, SND_SOC_REGMAP); 364 + 298 365 aic26->codec = codec; 299 366 300 367 /* Reset the codec to power on defaults */ ··· 322 385 323 386 static struct snd_soc_codec_driver aic26_soc_codec_dev = { 324 387 .probe = aic26_probe, 325 - .read = aic26_reg_read, 326 - .write = aic26_reg_write, 327 388 .controls = aic26_snd_controls, 328 389 .num_controls = ARRAY_SIZE(aic26_snd_controls), 329 390 .dapm_widgets = tlv320aic26_dapm_widgets, 330 391 .num_dapm_widgets = ARRAY_SIZE(tlv320aic26_dapm_widgets), 331 392 .dapm_routes = tlv320aic26_dapm_routes, 332 393 .num_dapm_routes = ARRAY_SIZE(tlv320aic26_dapm_routes), 394 + }; 395 + 396 + static const struct regmap_config aic26_regmap = { 397 + .reg_bits = 16, 398 + .val_bits = 16, 333 399 }; 334 400 335 401 /* --------------------------------------------------------------------- ··· 350 410 aic26 = devm_kzalloc(&spi->dev, sizeof *aic26, GFP_KERNEL); 351 411 if (!aic26) 352 412 return -ENOMEM; 413 + 414 + aic26->regmap = devm_regmap_init_spi(spi, &aic26_regmap); 415 + if (IS_ERR(aic26->regmap)) 416 + return PTR_ERR(aic26->regmap); 353 417 354 418 /* Initialize the driver data */ 355 419 aic26->spi = spi;
+1 -4
sound/soc/codecs/tlv320aic26.h
··· 9 9 #define _TLV320AIC16_H_ 10 10 11 11 /* AIC26 Registers */ 12 - #define AIC26_READ_COMMAND_WORD(addr) ((1 << 15) | (addr << 5)) 13 - #define AIC26_WRITE_COMMAND_WORD(addr) ((0 << 15) | (addr << 5)) 14 - #define AIC26_PAGE_ADDR(page, offset) ((page << 6) | offset) 15 - #define AIC26_NUM_REGS AIC26_PAGE_ADDR(3, 0) 12 + #define AIC26_PAGE_ADDR(page, offset) ((page << 11) | offset << 5) 16 13 17 14 /* Page 0: Auxiliary data registers */ 18 15 #define AIC26_REG_BAT1 AIC26_PAGE_ADDR(0, 0x05)