Loading include/sound/soc.h +10 −1 Original line number Diff line number Diff line Loading @@ -209,11 +209,20 @@ typedef int (*hw_read_t)(void *,char* ,int); extern struct snd_ac97_bus_ops soc_ac97_ops; enum snd_soc_control_type { SND_SOC_CUSTOM, SND_SOC_I2C, SND_SOC_SPI, }; int snd_soc_register_platform(struct snd_soc_platform *platform); void snd_soc_unregister_platform(struct snd_soc_platform *platform); int snd_soc_register_codec(struct snd_soc_codec *codec); void snd_soc_unregister_codec(struct snd_soc_codec *codec); int snd_soc_codec_volatile_register(struct snd_soc_codec *codec, int reg); int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec, int addr_bits, int data_bits, enum snd_soc_control_type control); #ifdef CONFIG_PM int snd_soc_suspend_device(struct device *dev); Loading Loading @@ -387,7 +396,7 @@ struct snd_soc_codec { int (*volatile_register)(unsigned int); int (*readable_register)(unsigned int); hw_write_t hw_write; hw_read_t hw_read; unsigned int (*hw_read)(struct snd_soc_codec *, unsigned int); void *reg_cache; short reg_cache_size; short reg_cache_step; Loading sound/soc/Makefile +1 −1 Original line number Diff line number Diff line snd-soc-core-objs := soc-core.o soc-dapm.o soc-jack.o snd-soc-core-objs := soc-core.o soc-dapm.o soc-jack.o soc-cache.o obj-$(CONFIG_SND_SOC) += snd-soc-core.o obj-$(CONFIG_SND_SOC) += codecs/ Loading sound/soc/codecs/tlv320aic3x.c +2 −9 Original line number Diff line number Diff line Loading @@ -145,8 +145,8 @@ static int aic3x_read(struct snd_soc_codec *codec, unsigned int reg, u8 *value) { *value = reg & 0xff; if (codec->hw_read(codec->control_data, value, 1) != 1) return -EIO; value[0] = i2c_smbus_read_byte_data(codec->control_data, value[0]); aic3x_write_reg_cache(codec, reg, *value); return 0; Loading Loading @@ -1325,12 +1325,6 @@ static struct i2c_driver aic3x_i2c_driver = { .id_table = aic3x_i2c_id, }; static int aic3x_i2c_read(struct i2c_client *client, u8 *value, int len) { value[0] = i2c_smbus_read_byte_data(client, value[0]); return (len == 1); } static int aic3x_add_i2c_device(struct platform_device *pdev, const struct aic3x_setup_data *setup) { Loading Loading @@ -1403,7 +1397,6 @@ static int aic3x_probe(struct platform_device *pdev) #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) if (setup->i2c_address) { codec->hw_write = (hw_write_t) i2c_master_send; codec->hw_read = (hw_read_t) aic3x_i2c_read; ret = aic3x_add_i2c_device(pdev, setup); } #else Loading sound/soc/codecs/wm8510.c +53 −121 Original line number Diff line number Diff line Loading @@ -58,55 +58,7 @@ static const u16 wm8510_reg[WM8510_CACHEREGNUM] = { #define WM8510_POWER1_BIASEN 0x08 #define WM8510_POWER1_BUFIOEN 0x10 /* * read wm8510 register cache */ static inline unsigned int wm8510_read_reg_cache(struct snd_soc_codec *codec, unsigned int reg) { u16 *cache = codec->reg_cache; if (reg == WM8510_RESET) return 0; if (reg >= WM8510_CACHEREGNUM) return -1; return cache[reg]; } /* * write wm8510 register cache */ static inline void wm8510_write_reg_cache(struct snd_soc_codec *codec, u16 reg, unsigned int value) { u16 *cache = codec->reg_cache; if (reg >= WM8510_CACHEREGNUM) return; cache[reg] = value; } /* * write to the WM8510 register space */ static int wm8510_write(struct snd_soc_codec *codec, unsigned int reg, unsigned int value) { u8 data[2]; /* data is * D15..D9 WM8510 register offset * D8...D0 register data */ data[0] = (reg << 1) | ((value >> 8) & 0x0001); data[1] = value & 0x00ff; wm8510_write_reg_cache(codec, reg, value); if (codec->hw_write(codec->control_data, data, 2) == 2) return 0; else return -EIO; } #define wm8510_reset(c) wm8510_write(c, WM8510_RESET, 0) #define wm8510_reset(c) snd_soc_write(c, WM8510_RESET, 0) static const char *wm8510_companding[] = { "Off", "NC", "u-law", "A-law" }; static const char *wm8510_deemp[] = { "None", "32kHz", "44.1kHz", "48kHz" }; Loading Loading @@ -327,27 +279,27 @@ static int wm8510_set_dai_pll(struct snd_soc_dai *codec_dai, if (freq_in == 0 || freq_out == 0) { /* Clock CODEC directly from MCLK */ reg = wm8510_read_reg_cache(codec, WM8510_CLOCK); wm8510_write(codec, WM8510_CLOCK, reg & 0x0ff); reg = snd_soc_read(codec, WM8510_CLOCK); snd_soc_write(codec, WM8510_CLOCK, reg & 0x0ff); /* Turn off PLL */ reg = wm8510_read_reg_cache(codec, WM8510_POWER1); wm8510_write(codec, WM8510_POWER1, reg & 0x1df); reg = snd_soc_read(codec, WM8510_POWER1); snd_soc_write(codec, WM8510_POWER1, reg & 0x1df); return 0; } pll_factors(freq_out*4, freq_in); wm8510_write(codec, WM8510_PLLN, (pll_div.pre_div << 4) | pll_div.n); wm8510_write(codec, WM8510_PLLK1, pll_div.k >> 18); wm8510_write(codec, WM8510_PLLK2, (pll_div.k >> 9) & 0x1ff); wm8510_write(codec, WM8510_PLLK3, pll_div.k & 0x1ff); reg = wm8510_read_reg_cache(codec, WM8510_POWER1); wm8510_write(codec, WM8510_POWER1, reg | 0x020); snd_soc_write(codec, WM8510_PLLN, (pll_div.pre_div << 4) | pll_div.n); snd_soc_write(codec, WM8510_PLLK1, pll_div.k >> 18); snd_soc_write(codec, WM8510_PLLK2, (pll_div.k >> 9) & 0x1ff); snd_soc_write(codec, WM8510_PLLK3, pll_div.k & 0x1ff); reg = snd_soc_read(codec, WM8510_POWER1); snd_soc_write(codec, WM8510_POWER1, reg | 0x020); /* Run CODEC from PLL instead of MCLK */ reg = wm8510_read_reg_cache(codec, WM8510_CLOCK); wm8510_write(codec, WM8510_CLOCK, reg | 0x100); reg = snd_soc_read(codec, WM8510_CLOCK); snd_soc_write(codec, WM8510_CLOCK, reg | 0x100); return 0; } Loading @@ -363,24 +315,24 @@ static int wm8510_set_dai_clkdiv(struct snd_soc_dai *codec_dai, switch (div_id) { case WM8510_OPCLKDIV: reg = wm8510_read_reg_cache(codec, WM8510_GPIO) & 0x1cf; wm8510_write(codec, WM8510_GPIO, reg | div); reg = snd_soc_read(codec, WM8510_GPIO) & 0x1cf; snd_soc_write(codec, WM8510_GPIO, reg | div); break; case WM8510_MCLKDIV: reg = wm8510_read_reg_cache(codec, WM8510_CLOCK) & 0x11f; wm8510_write(codec, WM8510_CLOCK, reg | div); reg = snd_soc_read(codec, WM8510_CLOCK) & 0x11f; snd_soc_write(codec, WM8510_CLOCK, reg | div); break; case WM8510_ADCCLK: reg = wm8510_read_reg_cache(codec, WM8510_ADC) & 0x1f7; wm8510_write(codec, WM8510_ADC, reg | div); reg = snd_soc_read(codec, WM8510_ADC) & 0x1f7; snd_soc_write(codec, WM8510_ADC, reg | div); break; case WM8510_DACCLK: reg = wm8510_read_reg_cache(codec, WM8510_DAC) & 0x1f7; wm8510_write(codec, WM8510_DAC, reg | div); reg = snd_soc_read(codec, WM8510_DAC) & 0x1f7; snd_soc_write(codec, WM8510_DAC, reg | div); break; case WM8510_BCLKDIV: reg = wm8510_read_reg_cache(codec, WM8510_CLOCK) & 0x1e3; wm8510_write(codec, WM8510_CLOCK, reg | div); reg = snd_soc_read(codec, WM8510_CLOCK) & 0x1e3; snd_soc_write(codec, WM8510_CLOCK, reg | div); break; default: return -EINVAL; Loading @@ -394,7 +346,7 @@ static int wm8510_set_dai_fmt(struct snd_soc_dai *codec_dai, { struct snd_soc_codec *codec = codec_dai->codec; u16 iface = 0; u16 clk = wm8510_read_reg_cache(codec, WM8510_CLOCK) & 0x1fe; u16 clk = snd_soc_read(codec, WM8510_CLOCK) & 0x1fe; /* set master/slave audio interface */ switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { Loading Loading @@ -441,8 +393,8 @@ static int wm8510_set_dai_fmt(struct snd_soc_dai *codec_dai, return -EINVAL; } wm8510_write(codec, WM8510_IFACE, iface); wm8510_write(codec, WM8510_CLOCK, clk); snd_soc_write(codec, WM8510_IFACE, iface); snd_soc_write(codec, WM8510_CLOCK, clk); return 0; } Loading @@ -453,8 +405,8 @@ static int wm8510_pcm_hw_params(struct snd_pcm_substream *substream, struct snd_soc_pcm_runtime *rtd = substream->private_data; struct snd_soc_device *socdev = rtd->socdev; struct snd_soc_codec *codec = socdev->card->codec; u16 iface = wm8510_read_reg_cache(codec, WM8510_IFACE) & 0x19f; u16 adn = wm8510_read_reg_cache(codec, WM8510_ADD) & 0x1f1; u16 iface = snd_soc_read(codec, WM8510_IFACE) & 0x19f; u16 adn = snd_soc_read(codec, WM8510_ADD) & 0x1f1; /* bit size */ switch (params_format(params)) { Loading Loading @@ -493,20 +445,20 @@ static int wm8510_pcm_hw_params(struct snd_pcm_substream *substream, break; } wm8510_write(codec, WM8510_IFACE, iface); wm8510_write(codec, WM8510_ADD, adn); snd_soc_write(codec, WM8510_IFACE, iface); snd_soc_write(codec, WM8510_ADD, adn); return 0; } static int wm8510_mute(struct snd_soc_dai *dai, int mute) { struct snd_soc_codec *codec = dai->codec; u16 mute_reg = wm8510_read_reg_cache(codec, WM8510_DAC) & 0xffbf; u16 mute_reg = snd_soc_read(codec, WM8510_DAC) & 0xffbf; if (mute) wm8510_write(codec, WM8510_DAC, mute_reg | 0x40); snd_soc_write(codec, WM8510_DAC, mute_reg | 0x40); else wm8510_write(codec, WM8510_DAC, mute_reg); snd_soc_write(codec, WM8510_DAC, mute_reg); return 0; } Loading @@ -514,13 +466,13 @@ static int wm8510_mute(struct snd_soc_dai *dai, int mute) static int wm8510_set_bias_level(struct snd_soc_codec *codec, enum snd_soc_bias_level level) { u16 power1 = wm8510_read_reg_cache(codec, WM8510_POWER1) & ~0x3; u16 power1 = snd_soc_read(codec, WM8510_POWER1) & ~0x3; switch (level) { case SND_SOC_BIAS_ON: case SND_SOC_BIAS_PREPARE: power1 |= 0x1; /* VMID 50k */ wm8510_write(codec, WM8510_POWER1, power1); snd_soc_write(codec, WM8510_POWER1, power1); break; case SND_SOC_BIAS_STANDBY: Loading @@ -528,18 +480,18 @@ static int wm8510_set_bias_level(struct snd_soc_codec *codec, if (codec->bias_level == SND_SOC_BIAS_OFF) { /* Initial cap charge at VMID 5k */ wm8510_write(codec, WM8510_POWER1, power1 | 0x3); snd_soc_write(codec, WM8510_POWER1, power1 | 0x3); mdelay(100); } power1 |= 0x2; /* VMID 500k */ wm8510_write(codec, WM8510_POWER1, power1); snd_soc_write(codec, WM8510_POWER1, power1); break; case SND_SOC_BIAS_OFF: wm8510_write(codec, WM8510_POWER1, 0); wm8510_write(codec, WM8510_POWER2, 0); wm8510_write(codec, WM8510_POWER3, 0); snd_soc_write(codec, WM8510_POWER1, 0); snd_soc_write(codec, WM8510_POWER2, 0); snd_soc_write(codec, WM8510_POWER3, 0); break; } Loading Loading @@ -613,15 +565,14 @@ static int wm8510_resume(struct platform_device *pdev) * initialise the WM8510 driver * register the mixer and dsp interfaces with the kernel */ static int wm8510_init(struct snd_soc_device *socdev) static int wm8510_init(struct snd_soc_device *socdev, enum snd_soc_control_type control) { struct snd_soc_codec *codec = socdev->card->codec; int ret = 0; codec->name = "WM8510"; codec->owner = THIS_MODULE; codec->read = wm8510_read_reg_cache; codec->write = wm8510_write; codec->set_bias_level = wm8510_set_bias_level; codec->dai = &wm8510_dai; codec->num_dai = 1; Loading @@ -631,13 +582,20 @@ static int wm8510_init(struct snd_soc_device *socdev) if (codec->reg_cache == NULL) return -ENOMEM; ret = snd_soc_codec_set_cache_io(codec, 7, 9, control); if (ret < 0) { printk(KERN_ERR "wm8510: failed to set cache I/O: %d\n", ret); goto err; } wm8510_reset(codec); /* register pcms */ ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); if (ret < 0) { printk(KERN_ERR "wm8510: failed to create pcms\n"); goto pcm_err; goto err; } /* power on device */ Loading @@ -656,7 +614,7 @@ static int wm8510_init(struct snd_soc_device *socdev) card_err: snd_soc_free_pcms(socdev); snd_soc_dapm_free(socdev); pcm_err: err: kfree(codec->reg_cache); return ret; } Loading @@ -679,7 +637,7 @@ static int wm8510_i2c_probe(struct i2c_client *i2c, i2c_set_clientdata(i2c, codec); codec->control_data = i2c; ret = wm8510_init(socdev); ret = wm8510_init(socdev, SND_SOC_I2C); if (ret < 0) pr_err("failed to initialise WM8510\n"); Loading Loading @@ -759,7 +717,7 @@ static int __devinit wm8510_spi_probe(struct spi_device *spi) codec->control_data = spi; ret = wm8510_init(socdev); ret = wm8510_init(socdev, SND_SOC_SPI); if (ret < 0) dev_err(&spi->dev, "failed to initialise WM8510\n"); Loading @@ -780,30 +738,6 @@ static struct spi_driver wm8510_spi_driver = { .probe = wm8510_spi_probe, .remove = __devexit_p(wm8510_spi_remove), }; static int wm8510_spi_write(struct spi_device *spi, const char *data, int len) { struct spi_transfer t; struct spi_message m; u8 msg[2]; if (len <= 0) return 0; msg[0] = data[0]; msg[1] = data[1]; spi_message_init(&m); memset(&t, 0, (sizeof t)); t.tx_buf = &msg[0]; t.len = len; spi_message_add_tail(&t, &m); spi_sync(spi, &m); return len; } #endif /* CONFIG_SPI_MASTER */ static int wm8510_probe(struct platform_device *pdev) Loading @@ -828,13 +762,11 @@ static int wm8510_probe(struct platform_device *pdev) wm8510_socdev = socdev; #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) if (setup->i2c_address) { codec->hw_write = (hw_write_t)i2c_master_send; ret = wm8510_add_i2c_device(pdev, setup); } #endif #if defined(CONFIG_SPI_MASTER) if (setup->spi) { codec->hw_write = (hw_write_t)wm8510_spi_write; ret = spi_register_driver(&wm8510_spi_driver); if (ret != 0) printk(KERN_ERR "can't add spi driver"); Loading sound/soc/codecs/wm8523.c +21 −77 Original line number Diff line number Diff line Loading @@ -62,7 +62,7 @@ static const u16 wm8523_reg[WM8523_REGISTER_COUNT] = { 0x0000, /* R8 - ZERO_DETECT */ }; static int wm8523_volatile(unsigned int reg) static int wm8523_volatile_register(unsigned int reg) { switch (reg) { case WM8523_DEVICE_ID: Loading @@ -73,71 +73,9 @@ static int wm8523_volatile(unsigned int reg) } } static int wm8523_write(struct snd_soc_codec *codec, unsigned int reg, unsigned int value) { struct wm8523_priv *wm8523 = codec->private_data; u8 data[3]; BUG_ON(reg > WM8523_MAX_REGISTER); data[0] = reg; data[1] = (value >> 8) & 0x00ff; data[2] = value & 0x00ff; if (!wm8523_volatile(reg)) wm8523->reg_cache[reg] = value; if (codec->hw_write(codec->control_data, data, 3) == 3) return 0; else return -EIO; } static int wm8523_reset(struct snd_soc_codec *codec) { return wm8523_write(codec, WM8523_DEVICE_ID, 0); } static unsigned int wm8523_read_hw(struct snd_soc_codec *codec, u8 reg) { struct i2c_msg xfer[2]; u16 data; int ret; struct i2c_client *i2c = codec->control_data; /* Write register */ xfer[0].addr = i2c->addr; xfer[0].flags = 0; xfer[0].len = 1; xfer[0].buf = ® /* Read data */ xfer[1].addr = i2c->addr; xfer[1].flags = I2C_M_RD; xfer[1].len = 2; xfer[1].buf = (u8 *)&data; ret = i2c_transfer(i2c->adapter, xfer, 2); if (ret != 2) { dev_err(codec->dev, "Failed to read 0x%x: %d\n", reg, ret); return 0; } return (data >> 8) | ((data & 0xff) << 8); } static unsigned int wm8523_read(struct snd_soc_codec *codec, unsigned int reg) { u16 *reg_cache = codec->reg_cache; BUG_ON(reg > WM8523_MAX_REGISTER); if (wm8523_volatile(reg)) return wm8523_read_hw(codec, reg); else return reg_cache[reg]; return snd_soc_write(codec, WM8523_DEVICE_ID, 0); } static const DECLARE_TLV_DB_SCALE(dac_tlv, -10000, 25, 0); Loading Loading @@ -228,8 +166,8 @@ static int wm8523_hw_params(struct snd_pcm_substream *substream, struct snd_soc_codec *codec = socdev->card->codec; struct wm8523_priv *wm8523 = codec->private_data; int i; u16 aifctrl1 = wm8523_read(codec, WM8523_AIF_CTRL1); u16 aifctrl2 = wm8523_read(codec, WM8523_AIF_CTRL2); u16 aifctrl1 = snd_soc_read(codec, WM8523_AIF_CTRL1); u16 aifctrl2 = snd_soc_read(codec, WM8523_AIF_CTRL2); /* Find a supported LRCLK ratio */ for (i = 0; i < ARRAY_SIZE(lrclk_ratios); i++) { Loading Loading @@ -263,8 +201,8 @@ static int wm8523_hw_params(struct snd_pcm_substream *substream, break; } wm8523_write(codec, WM8523_AIF_CTRL1, aifctrl1); wm8523_write(codec, WM8523_AIF_CTRL2, aifctrl2); snd_soc_write(codec, WM8523_AIF_CTRL1, aifctrl1); snd_soc_write(codec, WM8523_AIF_CTRL2, aifctrl2); return 0; } Loading Loading @@ -322,7 +260,7 @@ static int wm8523_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) { struct snd_soc_codec *codec = codec_dai->codec; u16 aifctrl1 = wm8523_read(codec, WM8523_AIF_CTRL1); u16 aifctrl1 = snd_soc_read(codec, WM8523_AIF_CTRL1); aifctrl1 &= ~(WM8523_BCLK_INV_MASK | WM8523_LRCLK_INV_MASK | WM8523_FMT_MASK | WM8523_AIF_MSTR_MASK); Loading Loading @@ -372,7 +310,7 @@ static int wm8523_set_dai_fmt(struct snd_soc_dai *codec_dai, return -EINVAL; } wm8523_write(codec, WM8523_AIF_CTRL1, aifctrl1); snd_soc_write(codec, WM8523_AIF_CTRL1, aifctrl1); return 0; } Loading Loading @@ -411,7 +349,7 @@ static int wm8523_set_bias_level(struct snd_soc_codec *codec, /* Sync back default/cached values */ for (i = WM8523_AIF_CTRL1; i < WM8523_MAX_REGISTER; i++) wm8523_write(codec, i, wm8523->reg_cache[i]); snd_soc_write(codec, i, wm8523->reg_cache[i]); msleep(100); Loading Loading @@ -543,7 +481,8 @@ struct snd_soc_codec_device soc_codec_dev_wm8523 = { }; EXPORT_SYMBOL_GPL(soc_codec_dev_wm8523); static int wm8523_register(struct wm8523_priv *wm8523) static int wm8523_register(struct wm8523_priv *wm8523, enum snd_soc_control_type control) { int ret; struct snd_soc_codec *codec = &wm8523->codec; Loading @@ -561,14 +500,13 @@ static int wm8523_register(struct wm8523_priv *wm8523) codec->private_data = wm8523; codec->name = "WM8523"; codec->owner = THIS_MODULE; codec->read = wm8523_read; codec->write = wm8523_write; codec->bias_level = SND_SOC_BIAS_OFF; codec->set_bias_level = wm8523_set_bias_level; codec->dai = &wm8523_dai; codec->num_dai = 1; codec->reg_cache_size = WM8523_REGISTER_COUNT; codec->reg_cache = &wm8523->reg_cache; codec->volatile_register = wm8523_volatile_register; wm8523->rate_constraint.list = &wm8523->rate_constraint_list[0]; wm8523->rate_constraint.count = Loading @@ -576,6 +514,12 @@ static int wm8523_register(struct wm8523_priv *wm8523) memcpy(codec->reg_cache, wm8523_reg, sizeof(wm8523_reg)); ret = snd_soc_codec_set_cache_io(codec, 8, 16, control); if (ret != 0) { dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); goto err; } for (i = 0; i < ARRAY_SIZE(wm8523->supplies); i++) wm8523->supplies[i].supply = wm8523_supply_names[i]; Loading @@ -593,7 +537,7 @@ static int wm8523_register(struct wm8523_priv *wm8523) goto err_get; } ret = wm8523_read(codec, WM8523_DEVICE_ID); ret = snd_soc_read(codec, WM8523_DEVICE_ID); if (ret < 0) { dev_err(codec->dev, "Failed to read ID register\n"); goto err_enable; Loading @@ -604,7 +548,7 @@ static int wm8523_register(struct wm8523_priv *wm8523) goto err_enable; } ret = wm8523_read(codec, WM8523_REVISION); ret = snd_soc_read(codec, WM8523_REVISION); if (ret < 0) { dev_err(codec->dev, "Failed to read revision register\n"); goto err_enable; Loading Loading @@ -684,7 +628,7 @@ static __devinit int wm8523_i2c_probe(struct i2c_client *i2c, codec->dev = &i2c->dev; return wm8523_register(wm8523); return wm8523_register(wm8523, SND_SOC_I2C); } static __devexit int wm8523_i2c_remove(struct i2c_client *client) Loading Loading
include/sound/soc.h +10 −1 Original line number Diff line number Diff line Loading @@ -209,11 +209,20 @@ typedef int (*hw_read_t)(void *,char* ,int); extern struct snd_ac97_bus_ops soc_ac97_ops; enum snd_soc_control_type { SND_SOC_CUSTOM, SND_SOC_I2C, SND_SOC_SPI, }; int snd_soc_register_platform(struct snd_soc_platform *platform); void snd_soc_unregister_platform(struct snd_soc_platform *platform); int snd_soc_register_codec(struct snd_soc_codec *codec); void snd_soc_unregister_codec(struct snd_soc_codec *codec); int snd_soc_codec_volatile_register(struct snd_soc_codec *codec, int reg); int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec, int addr_bits, int data_bits, enum snd_soc_control_type control); #ifdef CONFIG_PM int snd_soc_suspend_device(struct device *dev); Loading Loading @@ -387,7 +396,7 @@ struct snd_soc_codec { int (*volatile_register)(unsigned int); int (*readable_register)(unsigned int); hw_write_t hw_write; hw_read_t hw_read; unsigned int (*hw_read)(struct snd_soc_codec *, unsigned int); void *reg_cache; short reg_cache_size; short reg_cache_step; Loading
sound/soc/Makefile +1 −1 Original line number Diff line number Diff line snd-soc-core-objs := soc-core.o soc-dapm.o soc-jack.o snd-soc-core-objs := soc-core.o soc-dapm.o soc-jack.o soc-cache.o obj-$(CONFIG_SND_SOC) += snd-soc-core.o obj-$(CONFIG_SND_SOC) += codecs/ Loading
sound/soc/codecs/tlv320aic3x.c +2 −9 Original line number Diff line number Diff line Loading @@ -145,8 +145,8 @@ static int aic3x_read(struct snd_soc_codec *codec, unsigned int reg, u8 *value) { *value = reg & 0xff; if (codec->hw_read(codec->control_data, value, 1) != 1) return -EIO; value[0] = i2c_smbus_read_byte_data(codec->control_data, value[0]); aic3x_write_reg_cache(codec, reg, *value); return 0; Loading Loading @@ -1325,12 +1325,6 @@ static struct i2c_driver aic3x_i2c_driver = { .id_table = aic3x_i2c_id, }; static int aic3x_i2c_read(struct i2c_client *client, u8 *value, int len) { value[0] = i2c_smbus_read_byte_data(client, value[0]); return (len == 1); } static int aic3x_add_i2c_device(struct platform_device *pdev, const struct aic3x_setup_data *setup) { Loading Loading @@ -1403,7 +1397,6 @@ static int aic3x_probe(struct platform_device *pdev) #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) if (setup->i2c_address) { codec->hw_write = (hw_write_t) i2c_master_send; codec->hw_read = (hw_read_t) aic3x_i2c_read; ret = aic3x_add_i2c_device(pdev, setup); } #else Loading
sound/soc/codecs/wm8510.c +53 −121 Original line number Diff line number Diff line Loading @@ -58,55 +58,7 @@ static const u16 wm8510_reg[WM8510_CACHEREGNUM] = { #define WM8510_POWER1_BIASEN 0x08 #define WM8510_POWER1_BUFIOEN 0x10 /* * read wm8510 register cache */ static inline unsigned int wm8510_read_reg_cache(struct snd_soc_codec *codec, unsigned int reg) { u16 *cache = codec->reg_cache; if (reg == WM8510_RESET) return 0; if (reg >= WM8510_CACHEREGNUM) return -1; return cache[reg]; } /* * write wm8510 register cache */ static inline void wm8510_write_reg_cache(struct snd_soc_codec *codec, u16 reg, unsigned int value) { u16 *cache = codec->reg_cache; if (reg >= WM8510_CACHEREGNUM) return; cache[reg] = value; } /* * write to the WM8510 register space */ static int wm8510_write(struct snd_soc_codec *codec, unsigned int reg, unsigned int value) { u8 data[2]; /* data is * D15..D9 WM8510 register offset * D8...D0 register data */ data[0] = (reg << 1) | ((value >> 8) & 0x0001); data[1] = value & 0x00ff; wm8510_write_reg_cache(codec, reg, value); if (codec->hw_write(codec->control_data, data, 2) == 2) return 0; else return -EIO; } #define wm8510_reset(c) wm8510_write(c, WM8510_RESET, 0) #define wm8510_reset(c) snd_soc_write(c, WM8510_RESET, 0) static const char *wm8510_companding[] = { "Off", "NC", "u-law", "A-law" }; static const char *wm8510_deemp[] = { "None", "32kHz", "44.1kHz", "48kHz" }; Loading Loading @@ -327,27 +279,27 @@ static int wm8510_set_dai_pll(struct snd_soc_dai *codec_dai, if (freq_in == 0 || freq_out == 0) { /* Clock CODEC directly from MCLK */ reg = wm8510_read_reg_cache(codec, WM8510_CLOCK); wm8510_write(codec, WM8510_CLOCK, reg & 0x0ff); reg = snd_soc_read(codec, WM8510_CLOCK); snd_soc_write(codec, WM8510_CLOCK, reg & 0x0ff); /* Turn off PLL */ reg = wm8510_read_reg_cache(codec, WM8510_POWER1); wm8510_write(codec, WM8510_POWER1, reg & 0x1df); reg = snd_soc_read(codec, WM8510_POWER1); snd_soc_write(codec, WM8510_POWER1, reg & 0x1df); return 0; } pll_factors(freq_out*4, freq_in); wm8510_write(codec, WM8510_PLLN, (pll_div.pre_div << 4) | pll_div.n); wm8510_write(codec, WM8510_PLLK1, pll_div.k >> 18); wm8510_write(codec, WM8510_PLLK2, (pll_div.k >> 9) & 0x1ff); wm8510_write(codec, WM8510_PLLK3, pll_div.k & 0x1ff); reg = wm8510_read_reg_cache(codec, WM8510_POWER1); wm8510_write(codec, WM8510_POWER1, reg | 0x020); snd_soc_write(codec, WM8510_PLLN, (pll_div.pre_div << 4) | pll_div.n); snd_soc_write(codec, WM8510_PLLK1, pll_div.k >> 18); snd_soc_write(codec, WM8510_PLLK2, (pll_div.k >> 9) & 0x1ff); snd_soc_write(codec, WM8510_PLLK3, pll_div.k & 0x1ff); reg = snd_soc_read(codec, WM8510_POWER1); snd_soc_write(codec, WM8510_POWER1, reg | 0x020); /* Run CODEC from PLL instead of MCLK */ reg = wm8510_read_reg_cache(codec, WM8510_CLOCK); wm8510_write(codec, WM8510_CLOCK, reg | 0x100); reg = snd_soc_read(codec, WM8510_CLOCK); snd_soc_write(codec, WM8510_CLOCK, reg | 0x100); return 0; } Loading @@ -363,24 +315,24 @@ static int wm8510_set_dai_clkdiv(struct snd_soc_dai *codec_dai, switch (div_id) { case WM8510_OPCLKDIV: reg = wm8510_read_reg_cache(codec, WM8510_GPIO) & 0x1cf; wm8510_write(codec, WM8510_GPIO, reg | div); reg = snd_soc_read(codec, WM8510_GPIO) & 0x1cf; snd_soc_write(codec, WM8510_GPIO, reg | div); break; case WM8510_MCLKDIV: reg = wm8510_read_reg_cache(codec, WM8510_CLOCK) & 0x11f; wm8510_write(codec, WM8510_CLOCK, reg | div); reg = snd_soc_read(codec, WM8510_CLOCK) & 0x11f; snd_soc_write(codec, WM8510_CLOCK, reg | div); break; case WM8510_ADCCLK: reg = wm8510_read_reg_cache(codec, WM8510_ADC) & 0x1f7; wm8510_write(codec, WM8510_ADC, reg | div); reg = snd_soc_read(codec, WM8510_ADC) & 0x1f7; snd_soc_write(codec, WM8510_ADC, reg | div); break; case WM8510_DACCLK: reg = wm8510_read_reg_cache(codec, WM8510_DAC) & 0x1f7; wm8510_write(codec, WM8510_DAC, reg | div); reg = snd_soc_read(codec, WM8510_DAC) & 0x1f7; snd_soc_write(codec, WM8510_DAC, reg | div); break; case WM8510_BCLKDIV: reg = wm8510_read_reg_cache(codec, WM8510_CLOCK) & 0x1e3; wm8510_write(codec, WM8510_CLOCK, reg | div); reg = snd_soc_read(codec, WM8510_CLOCK) & 0x1e3; snd_soc_write(codec, WM8510_CLOCK, reg | div); break; default: return -EINVAL; Loading @@ -394,7 +346,7 @@ static int wm8510_set_dai_fmt(struct snd_soc_dai *codec_dai, { struct snd_soc_codec *codec = codec_dai->codec; u16 iface = 0; u16 clk = wm8510_read_reg_cache(codec, WM8510_CLOCK) & 0x1fe; u16 clk = snd_soc_read(codec, WM8510_CLOCK) & 0x1fe; /* set master/slave audio interface */ switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { Loading Loading @@ -441,8 +393,8 @@ static int wm8510_set_dai_fmt(struct snd_soc_dai *codec_dai, return -EINVAL; } wm8510_write(codec, WM8510_IFACE, iface); wm8510_write(codec, WM8510_CLOCK, clk); snd_soc_write(codec, WM8510_IFACE, iface); snd_soc_write(codec, WM8510_CLOCK, clk); return 0; } Loading @@ -453,8 +405,8 @@ static int wm8510_pcm_hw_params(struct snd_pcm_substream *substream, struct snd_soc_pcm_runtime *rtd = substream->private_data; struct snd_soc_device *socdev = rtd->socdev; struct snd_soc_codec *codec = socdev->card->codec; u16 iface = wm8510_read_reg_cache(codec, WM8510_IFACE) & 0x19f; u16 adn = wm8510_read_reg_cache(codec, WM8510_ADD) & 0x1f1; u16 iface = snd_soc_read(codec, WM8510_IFACE) & 0x19f; u16 adn = snd_soc_read(codec, WM8510_ADD) & 0x1f1; /* bit size */ switch (params_format(params)) { Loading Loading @@ -493,20 +445,20 @@ static int wm8510_pcm_hw_params(struct snd_pcm_substream *substream, break; } wm8510_write(codec, WM8510_IFACE, iface); wm8510_write(codec, WM8510_ADD, adn); snd_soc_write(codec, WM8510_IFACE, iface); snd_soc_write(codec, WM8510_ADD, adn); return 0; } static int wm8510_mute(struct snd_soc_dai *dai, int mute) { struct snd_soc_codec *codec = dai->codec; u16 mute_reg = wm8510_read_reg_cache(codec, WM8510_DAC) & 0xffbf; u16 mute_reg = snd_soc_read(codec, WM8510_DAC) & 0xffbf; if (mute) wm8510_write(codec, WM8510_DAC, mute_reg | 0x40); snd_soc_write(codec, WM8510_DAC, mute_reg | 0x40); else wm8510_write(codec, WM8510_DAC, mute_reg); snd_soc_write(codec, WM8510_DAC, mute_reg); return 0; } Loading @@ -514,13 +466,13 @@ static int wm8510_mute(struct snd_soc_dai *dai, int mute) static int wm8510_set_bias_level(struct snd_soc_codec *codec, enum snd_soc_bias_level level) { u16 power1 = wm8510_read_reg_cache(codec, WM8510_POWER1) & ~0x3; u16 power1 = snd_soc_read(codec, WM8510_POWER1) & ~0x3; switch (level) { case SND_SOC_BIAS_ON: case SND_SOC_BIAS_PREPARE: power1 |= 0x1; /* VMID 50k */ wm8510_write(codec, WM8510_POWER1, power1); snd_soc_write(codec, WM8510_POWER1, power1); break; case SND_SOC_BIAS_STANDBY: Loading @@ -528,18 +480,18 @@ static int wm8510_set_bias_level(struct snd_soc_codec *codec, if (codec->bias_level == SND_SOC_BIAS_OFF) { /* Initial cap charge at VMID 5k */ wm8510_write(codec, WM8510_POWER1, power1 | 0x3); snd_soc_write(codec, WM8510_POWER1, power1 | 0x3); mdelay(100); } power1 |= 0x2; /* VMID 500k */ wm8510_write(codec, WM8510_POWER1, power1); snd_soc_write(codec, WM8510_POWER1, power1); break; case SND_SOC_BIAS_OFF: wm8510_write(codec, WM8510_POWER1, 0); wm8510_write(codec, WM8510_POWER2, 0); wm8510_write(codec, WM8510_POWER3, 0); snd_soc_write(codec, WM8510_POWER1, 0); snd_soc_write(codec, WM8510_POWER2, 0); snd_soc_write(codec, WM8510_POWER3, 0); break; } Loading Loading @@ -613,15 +565,14 @@ static int wm8510_resume(struct platform_device *pdev) * initialise the WM8510 driver * register the mixer and dsp interfaces with the kernel */ static int wm8510_init(struct snd_soc_device *socdev) static int wm8510_init(struct snd_soc_device *socdev, enum snd_soc_control_type control) { struct snd_soc_codec *codec = socdev->card->codec; int ret = 0; codec->name = "WM8510"; codec->owner = THIS_MODULE; codec->read = wm8510_read_reg_cache; codec->write = wm8510_write; codec->set_bias_level = wm8510_set_bias_level; codec->dai = &wm8510_dai; codec->num_dai = 1; Loading @@ -631,13 +582,20 @@ static int wm8510_init(struct snd_soc_device *socdev) if (codec->reg_cache == NULL) return -ENOMEM; ret = snd_soc_codec_set_cache_io(codec, 7, 9, control); if (ret < 0) { printk(KERN_ERR "wm8510: failed to set cache I/O: %d\n", ret); goto err; } wm8510_reset(codec); /* register pcms */ ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); if (ret < 0) { printk(KERN_ERR "wm8510: failed to create pcms\n"); goto pcm_err; goto err; } /* power on device */ Loading @@ -656,7 +614,7 @@ static int wm8510_init(struct snd_soc_device *socdev) card_err: snd_soc_free_pcms(socdev); snd_soc_dapm_free(socdev); pcm_err: err: kfree(codec->reg_cache); return ret; } Loading @@ -679,7 +637,7 @@ static int wm8510_i2c_probe(struct i2c_client *i2c, i2c_set_clientdata(i2c, codec); codec->control_data = i2c; ret = wm8510_init(socdev); ret = wm8510_init(socdev, SND_SOC_I2C); if (ret < 0) pr_err("failed to initialise WM8510\n"); Loading Loading @@ -759,7 +717,7 @@ static int __devinit wm8510_spi_probe(struct spi_device *spi) codec->control_data = spi; ret = wm8510_init(socdev); ret = wm8510_init(socdev, SND_SOC_SPI); if (ret < 0) dev_err(&spi->dev, "failed to initialise WM8510\n"); Loading @@ -780,30 +738,6 @@ static struct spi_driver wm8510_spi_driver = { .probe = wm8510_spi_probe, .remove = __devexit_p(wm8510_spi_remove), }; static int wm8510_spi_write(struct spi_device *spi, const char *data, int len) { struct spi_transfer t; struct spi_message m; u8 msg[2]; if (len <= 0) return 0; msg[0] = data[0]; msg[1] = data[1]; spi_message_init(&m); memset(&t, 0, (sizeof t)); t.tx_buf = &msg[0]; t.len = len; spi_message_add_tail(&t, &m); spi_sync(spi, &m); return len; } #endif /* CONFIG_SPI_MASTER */ static int wm8510_probe(struct platform_device *pdev) Loading @@ -828,13 +762,11 @@ static int wm8510_probe(struct platform_device *pdev) wm8510_socdev = socdev; #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) if (setup->i2c_address) { codec->hw_write = (hw_write_t)i2c_master_send; ret = wm8510_add_i2c_device(pdev, setup); } #endif #if defined(CONFIG_SPI_MASTER) if (setup->spi) { codec->hw_write = (hw_write_t)wm8510_spi_write; ret = spi_register_driver(&wm8510_spi_driver); if (ret != 0) printk(KERN_ERR "can't add spi driver"); Loading
sound/soc/codecs/wm8523.c +21 −77 Original line number Diff line number Diff line Loading @@ -62,7 +62,7 @@ static const u16 wm8523_reg[WM8523_REGISTER_COUNT] = { 0x0000, /* R8 - ZERO_DETECT */ }; static int wm8523_volatile(unsigned int reg) static int wm8523_volatile_register(unsigned int reg) { switch (reg) { case WM8523_DEVICE_ID: Loading @@ -73,71 +73,9 @@ static int wm8523_volatile(unsigned int reg) } } static int wm8523_write(struct snd_soc_codec *codec, unsigned int reg, unsigned int value) { struct wm8523_priv *wm8523 = codec->private_data; u8 data[3]; BUG_ON(reg > WM8523_MAX_REGISTER); data[0] = reg; data[1] = (value >> 8) & 0x00ff; data[2] = value & 0x00ff; if (!wm8523_volatile(reg)) wm8523->reg_cache[reg] = value; if (codec->hw_write(codec->control_data, data, 3) == 3) return 0; else return -EIO; } static int wm8523_reset(struct snd_soc_codec *codec) { return wm8523_write(codec, WM8523_DEVICE_ID, 0); } static unsigned int wm8523_read_hw(struct snd_soc_codec *codec, u8 reg) { struct i2c_msg xfer[2]; u16 data; int ret; struct i2c_client *i2c = codec->control_data; /* Write register */ xfer[0].addr = i2c->addr; xfer[0].flags = 0; xfer[0].len = 1; xfer[0].buf = ® /* Read data */ xfer[1].addr = i2c->addr; xfer[1].flags = I2C_M_RD; xfer[1].len = 2; xfer[1].buf = (u8 *)&data; ret = i2c_transfer(i2c->adapter, xfer, 2); if (ret != 2) { dev_err(codec->dev, "Failed to read 0x%x: %d\n", reg, ret); return 0; } return (data >> 8) | ((data & 0xff) << 8); } static unsigned int wm8523_read(struct snd_soc_codec *codec, unsigned int reg) { u16 *reg_cache = codec->reg_cache; BUG_ON(reg > WM8523_MAX_REGISTER); if (wm8523_volatile(reg)) return wm8523_read_hw(codec, reg); else return reg_cache[reg]; return snd_soc_write(codec, WM8523_DEVICE_ID, 0); } static const DECLARE_TLV_DB_SCALE(dac_tlv, -10000, 25, 0); Loading Loading @@ -228,8 +166,8 @@ static int wm8523_hw_params(struct snd_pcm_substream *substream, struct snd_soc_codec *codec = socdev->card->codec; struct wm8523_priv *wm8523 = codec->private_data; int i; u16 aifctrl1 = wm8523_read(codec, WM8523_AIF_CTRL1); u16 aifctrl2 = wm8523_read(codec, WM8523_AIF_CTRL2); u16 aifctrl1 = snd_soc_read(codec, WM8523_AIF_CTRL1); u16 aifctrl2 = snd_soc_read(codec, WM8523_AIF_CTRL2); /* Find a supported LRCLK ratio */ for (i = 0; i < ARRAY_SIZE(lrclk_ratios); i++) { Loading Loading @@ -263,8 +201,8 @@ static int wm8523_hw_params(struct snd_pcm_substream *substream, break; } wm8523_write(codec, WM8523_AIF_CTRL1, aifctrl1); wm8523_write(codec, WM8523_AIF_CTRL2, aifctrl2); snd_soc_write(codec, WM8523_AIF_CTRL1, aifctrl1); snd_soc_write(codec, WM8523_AIF_CTRL2, aifctrl2); return 0; } Loading Loading @@ -322,7 +260,7 @@ static int wm8523_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) { struct snd_soc_codec *codec = codec_dai->codec; u16 aifctrl1 = wm8523_read(codec, WM8523_AIF_CTRL1); u16 aifctrl1 = snd_soc_read(codec, WM8523_AIF_CTRL1); aifctrl1 &= ~(WM8523_BCLK_INV_MASK | WM8523_LRCLK_INV_MASK | WM8523_FMT_MASK | WM8523_AIF_MSTR_MASK); Loading Loading @@ -372,7 +310,7 @@ static int wm8523_set_dai_fmt(struct snd_soc_dai *codec_dai, return -EINVAL; } wm8523_write(codec, WM8523_AIF_CTRL1, aifctrl1); snd_soc_write(codec, WM8523_AIF_CTRL1, aifctrl1); return 0; } Loading Loading @@ -411,7 +349,7 @@ static int wm8523_set_bias_level(struct snd_soc_codec *codec, /* Sync back default/cached values */ for (i = WM8523_AIF_CTRL1; i < WM8523_MAX_REGISTER; i++) wm8523_write(codec, i, wm8523->reg_cache[i]); snd_soc_write(codec, i, wm8523->reg_cache[i]); msleep(100); Loading Loading @@ -543,7 +481,8 @@ struct snd_soc_codec_device soc_codec_dev_wm8523 = { }; EXPORT_SYMBOL_GPL(soc_codec_dev_wm8523); static int wm8523_register(struct wm8523_priv *wm8523) static int wm8523_register(struct wm8523_priv *wm8523, enum snd_soc_control_type control) { int ret; struct snd_soc_codec *codec = &wm8523->codec; Loading @@ -561,14 +500,13 @@ static int wm8523_register(struct wm8523_priv *wm8523) codec->private_data = wm8523; codec->name = "WM8523"; codec->owner = THIS_MODULE; codec->read = wm8523_read; codec->write = wm8523_write; codec->bias_level = SND_SOC_BIAS_OFF; codec->set_bias_level = wm8523_set_bias_level; codec->dai = &wm8523_dai; codec->num_dai = 1; codec->reg_cache_size = WM8523_REGISTER_COUNT; codec->reg_cache = &wm8523->reg_cache; codec->volatile_register = wm8523_volatile_register; wm8523->rate_constraint.list = &wm8523->rate_constraint_list[0]; wm8523->rate_constraint.count = Loading @@ -576,6 +514,12 @@ static int wm8523_register(struct wm8523_priv *wm8523) memcpy(codec->reg_cache, wm8523_reg, sizeof(wm8523_reg)); ret = snd_soc_codec_set_cache_io(codec, 8, 16, control); if (ret != 0) { dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); goto err; } for (i = 0; i < ARRAY_SIZE(wm8523->supplies); i++) wm8523->supplies[i].supply = wm8523_supply_names[i]; Loading @@ -593,7 +537,7 @@ static int wm8523_register(struct wm8523_priv *wm8523) goto err_get; } ret = wm8523_read(codec, WM8523_DEVICE_ID); ret = snd_soc_read(codec, WM8523_DEVICE_ID); if (ret < 0) { dev_err(codec->dev, "Failed to read ID register\n"); goto err_enable; Loading @@ -604,7 +548,7 @@ static int wm8523_register(struct wm8523_priv *wm8523) goto err_enable; } ret = wm8523_read(codec, WM8523_REVISION); ret = snd_soc_read(codec, WM8523_REVISION); if (ret < 0) { dev_err(codec->dev, "Failed to read revision register\n"); goto err_enable; Loading Loading @@ -684,7 +628,7 @@ static __devinit int wm8523_i2c_probe(struct i2c_client *i2c, codec->dev = &i2c->dev; return wm8523_register(wm8523); return wm8523_register(wm8523, SND_SOC_I2C); } static __devexit int wm8523_i2c_remove(struct i2c_client *client) Loading