13 #include <linux/module.h>
18 #include <linux/i2c.h>
23 #include <linux/slab.h>
33 #define WM8804_NUM_SUPPLIES 2
39 static const struct reg_default wm8804_reg_defaults[] = {
79 #define WM8804_REGULATOR_EVENT(n) \
80 static int wm8804_regulator_event_##n(struct notifier_block *nb, \
81 unsigned long event, void *data) \
83 struct wm8804_priv *wm8804 = container_of(nb, struct wm8804_priv, \
85 if (event & REGULATOR_EVENT_DISABLE) { \
86 regcache_mark_dirty(wm8804->regmap); \
94 static
const char *txsrc_text[] = {
"S/PDIF RX",
"AIF" };
98 SOC_ENUM_EXT(
"Input Source", txsrc, txsrc_get, txsrc_put),
112 ucontrol->
value.integer.value[0] = 1;
114 ucontrol->
value.integer.value[0] = 0;
123 unsigned int src, txpwr;
127 if (ucontrol->
value.integer.value[0] != 0
128 && ucontrol->
value.integer.value[0] != 1)
132 switch ((src & 0x40) >> 6) {
134 if (!ucontrol->
value.integer.value[0])
138 if (ucontrol->
value.integer.value[1])
149 ucontrol->
value.integer.value[0] << 6);
151 if (ucontrol->
value.integer.value[0]) {
168 static bool wm8804_volatile(
struct device *
dev,
unsigned int reg)
230 dev_err(dai->
dev,
"Unknown master/slave configuration\n");
251 dev_err(dai->
dev,
"Unknown polarity configuration\n");
257 (bcp << 4) | (lrp << 5));
259 (bcp << 4) | (lrp << 5));
283 dev_err(dai->
dev,
"Unsupported word length: %u\n",
319 #define FIXED_PLL_SIZE ((1ULL << 22) * 10)
324 unsigned long int K, Ndiv, Nmod,
tmp;
331 for (i = 0; i <
ARRAY_SIZE(post_table); i++) {
332 tmp = target * post_table[
i].div;
333 if (tmp >= 90000000 && tmp <= 100000000) {
334 pll_div->
freqmode = post_table[
i].freqmode;
335 pll_div->
mclkdiv = post_table[
i].mclkdiv;
336 target *= post_table[
i].div;
342 pr_err(
"%s: Unable to scale output frequency: %uHz\n",
355 if (Ndiv < 5 || Ndiv > 13) {
356 pr_err(
"%s: WM8804 N value is not within the recommended range: %lu\n",
367 K = Kpart & 0xffffffff;
376 static int wm8804_set_pll(
struct snd_soc_dai *dai,
int pll_id,
377 int source,
unsigned int freq_in,
378 unsigned int freq_out)
383 if (!freq_in || !freq_out) {
398 if (!freq_in || !freq_out)
419 static int wm8804_set_sysclk(
struct snd_soc_dai *dai,
420 int clk_id,
unsigned int freq,
int dir)
428 if ((freq >= 10000000 && freq <= 14400000)
429 || (freq >= 16280000 && freq <= 27000000))
432 dev_err(dai->
dev,
"OSCCLOCK is not within the "
433 "recommended range: %uHz\n", freq);
447 dev_err(dai->
dev,
"Unknown clock source: %d\n", clk_id);
454 static int wm8804_set_clkdiv(
struct snd_soc_dai *dai,
466 dev_err(dai->
dev,
"Unknown clock divider: %d\n", div_id);
472 static int wm8804_set_bias_level(
struct snd_soc_codec *codec,
478 wm8804 = snd_soc_codec_get_drvdata(codec);
492 "Failed to enable supplies: %d\n",
526 #define wm8804_suspend NULL
527 #define wm8804_resume NULL
535 wm8804 = snd_soc_codec_get_drvdata(codec);
550 wm8804 = snd_soc_codec_get_drvdata(codec);
556 dev_err(codec->
dev,
"Failed to set cache i/o: %d\n", ret);
561 wm8804->
supplies[i].supply = wm8804_supply_names[i];
566 dev_err(codec->
dev,
"Failed to request supplies: %d\n", ret);
570 wm8804->
disable_nb[0].notifier_call = wm8804_regulator_event_0;
571 wm8804->
disable_nb[1].notifier_call = wm8804_regulator_event_1;
579 "Failed to register regulator notifier: %d\n",
587 dev_err(codec->
dev,
"Failed to enable supplies: %d\n", ret);
593 dev_err(codec->
dev,
"Failed to read device ID: %d\n", id1);
600 dev_err(codec->
dev,
"Failed to read device ID: %d\n", id2);
605 id2 = (id2 << 8) | id1;
608 dev_err(codec->
dev,
"Invalid device ID: %#x\n", id2);
615 dev_err(codec->
dev,
"Failed to read device revision: %d\n",
621 ret = wm8804_reset(codec);
623 dev_err(codec->
dev,
"Failed to issue reset: %d\n", ret);
639 .hw_params = wm8804_hw_params,
640 .set_fmt = wm8804_set_fmt,
641 .set_sysclk = wm8804_set_sysclk,
642 .set_clkdiv = wm8804_set_clkdiv,
643 .set_pll = wm8804_set_pll
646 #define WM8804_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
647 SNDRV_PCM_FMTBIT_S24_LE)
649 #define WM8804_RATES (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
650 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_64000 | \
651 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | \
652 SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000)
655 .name =
"wm8804-spdif",
657 .stream_name =
"Playback",
664 .stream_name =
"Capture",
670 .ops = &wm8804_dai_ops,
675 .probe = wm8804_probe,
676 .remove = wm8804_remove,
679 .set_bias_level = wm8804_set_bias_level,
680 .idle_bias_off =
true,
682 .controls = wm8804_snd_controls,
683 .num_controls =
ARRAY_SIZE(wm8804_snd_controls),
687 { .compatible =
"wlf,wm8804", },
692 static struct regmap_config wm8804_regmap_config = {
697 .volatile_reg = wm8804_volatile,
700 .reg_defaults = wm8804_reg_defaults,
701 .num_reg_defaults =
ARRAY_SIZE(wm8804_reg_defaults),
704 #if defined(CONFIG_SPI_MASTER)
715 if (IS_ERR(wm8804->
regmap)) {
716 ret = PTR_ERR(wm8804->
regmap);
720 spi_set_drvdata(spi, wm8804);
723 &soc_codec_dev_wm8804, &wm8804_dai, 1);
736 static struct spi_driver wm8804_spi_driver = {
740 .of_match_table = wm8804_of_match,
742 .probe = wm8804_spi_probe,
747 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
759 if (IS_ERR(wm8804->
regmap)) {
760 ret = PTR_ERR(wm8804->
regmap);
764 i2c_set_clientdata(i2c, wm8804);
767 &soc_codec_dev_wm8804, &wm8804_dai, 1);
780 struct wm8804_priv *wm8804 = i2c_get_clientdata(i2c);
794 static struct i2c_driver wm8804_i2c_driver = {
798 .of_match_table = wm8804_of_match,
800 .probe = wm8804_i2c_probe,
802 .id_table = wm8804_i2c_id
806 static int __init wm8804_modinit(
void)
810 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
811 ret = i2c_add_driver(&wm8804_i2c_driver);
817 #if defined(CONFIG_SPI_MASTER)
828 static void __exit wm8804_exit(
void)
830 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
833 #if defined(CONFIG_SPI_MASTER)
834 spi_unregister_driver(&wm8804_spi_driver);