diff options
Diffstat (limited to 'sound/soc/codecs/wm8753.c')
-rw-r--r-- | sound/soc/codecs/wm8753.c | 404 |
1 files changed, 141 insertions, 263 deletions
diff --git a/sound/soc/codecs/wm8753.c b/sound/soc/codecs/wm8753.c index b59f349c5218..8f679a13f2bc 100644 --- a/sound/soc/codecs/wm8753.c +++ b/sound/soc/codecs/wm8753.c @@ -57,7 +57,7 @@ module_param(caps_charge, int, 0); MODULE_PARM_DESC(caps_charge, "WM8753 cap charge time (msecs)"); static void wm8753_set_dai_mode(struct snd_soc_codec *codec, - unsigned int mode); + struct snd_soc_dai *dai, unsigned int hifi); /* * wm8753 register cache @@ -85,10 +85,11 @@ static const u16 wm8753_reg[] = { /* codec private data */ struct wm8753_priv { + enum snd_soc_control_type control_type; unsigned int sysclk; unsigned int pcmclk; - struct snd_soc_codec codec; u16 reg_cache[ARRAY_SIZE(wm8753_reg)]; + int dai_func; }; /* @@ -228,6 +229,7 @@ static int wm8753_set_dai(struct snd_kcontrol *kcontrol, { struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); int mode = wm8753_read_reg_cache(codec, WM8753_IOCTL); + struct wm8753_priv *wm8753 = snd_soc_codec_get_drvdata(codec); if (((mode & 0xc) >> 2) == ucontrol->value.integer.value[0]) return 0; @@ -235,8 +237,7 @@ static int wm8753_set_dai(struct snd_kcontrol *kcontrol, mode &= 0xfff3; mode |= (ucontrol->value.integer.value[0] << 2); - wm8753_write(codec, WM8753_IOCTL, mode); - wm8753_set_dai_mode(codec, ucontrol->value.integer.value[0]); + wm8753->dai_func = ucontrol->value.integer.value[0]; return 1; } @@ -904,6 +905,13 @@ static int wm8753_vdac_adc_set_dai_fmt(struct snd_soc_dai *codec_dai, return 0; } +static int wm8753_pcm_startup(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + wm8753_set_dai_mode(dai->codec, dai, 0); + return 0; +} + /* * Set PCM DAI bit size and sample rate. */ @@ -912,8 +920,7 @@ static int wm8753_pcm_hw_params(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { struct snd_soc_pcm_runtime *rtd = substream->private_data; - struct snd_soc_device *socdev = rtd->socdev; - struct snd_soc_codec *codec = socdev->card->codec; + struct snd_soc_codec *codec = rtd->codec; struct wm8753_priv *wm8753 = snd_soc_codec_get_drvdata(codec); u16 voice = wm8753_read_reg_cache(codec, WM8753_PCM) & 0x01f3; u16 srate = wm8753_read_reg_cache(codec, WM8753_SRATE1) & 0x017f; @@ -1138,6 +1145,13 @@ static int wm8753_i2s_set_dai_fmt(struct snd_soc_dai *codec_dai, return 0; } +static int wm8753_i2s_startup(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + wm8753_set_dai_mode(dai->codec, dai, 1); + return 0; +} + /* * Set PCM DAI bit size and sample rate. */ @@ -1146,8 +1160,7 @@ static int wm8753_i2s_hw_params(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { struct snd_soc_pcm_runtime *rtd = substream->private_data; - struct snd_soc_device *socdev = rtd->socdev; - struct snd_soc_codec *codec = socdev->card->codec; + struct snd_soc_codec *codec = rtd->codec; struct wm8753_priv *wm8753 = snd_soc_codec_get_drvdata(codec); u16 srate = wm8753_read_reg_cache(codec, WM8753_SRATE1) & 0x01c0; u16 hifi = wm8753_read_reg_cache(codec, WM8753_HIFI) & 0x01f3; @@ -1240,12 +1253,12 @@ static int wm8753_mute(struct snd_soc_dai *dai, int mute) { struct snd_soc_codec *codec = dai->codec; u16 mute_reg = wm8753_read_reg_cache(codec, WM8753_DAC) & 0xfff7; + struct wm8753_priv *wm8753 = snd_soc_codec_get_drvdata(codec); /* the digital mute covers the HiFi and Voice DAC's on the WM8753. * make sure we check if they are not both active when we mute */ - if (mute && dai->id == 1) { - if (!wm8753_dai[WM8753_DAI_VOICE].playback.active || - !wm8753_dai[WM8753_DAI_HIFI].playback.active) + if (mute && wm8753->dai_func == 1) { + if (!codec->active) wm8753_write(codec, WM8753_DAC, mute_reg | 0x8); } else { if (mute) @@ -1303,6 +1316,7 @@ static int wm8753_set_bias_level(struct snd_soc_codec *codec, * 4. Voice disabled - HIFI over HIFI, uses voice DAI LRC for capture */ static struct snd_soc_dai_ops wm8753_dai_ops_hifi_mode1 = { + .startup = wm8753_i2s_startup, .hw_params = wm8753_i2s_hw_params, .digital_mute = wm8753_mute, .set_fmt = wm8753_mode1h_set_dai_fmt, @@ -1312,6 +1326,7 @@ static struct snd_soc_dai_ops wm8753_dai_ops_hifi_mode1 = { }; static struct snd_soc_dai_ops wm8753_dai_ops_voice_mode1 = { + .startup = wm8753_pcm_startup, .hw_params = wm8753_pcm_hw_params, .digital_mute = wm8753_mute, .set_fmt = wm8753_mode1v_set_dai_fmt, @@ -1321,6 +1336,7 @@ static struct snd_soc_dai_ops wm8753_dai_ops_voice_mode1 = { }; static struct snd_soc_dai_ops wm8753_dai_ops_voice_mode2 = { + .startup = wm8753_pcm_startup, .hw_params = wm8753_pcm_hw_params, .digital_mute = wm8753_mute, .set_fmt = wm8753_mode2_set_dai_fmt, @@ -1330,6 +1346,7 @@ static struct snd_soc_dai_ops wm8753_dai_ops_voice_mode2 = { }; static struct snd_soc_dai_ops wm8753_dai_ops_hifi_mode3 = { + .startup = wm8753_i2s_startup, .hw_params = wm8753_i2s_hw_params, .digital_mute = wm8753_mute, .set_fmt = wm8753_mode3_4_set_dai_fmt, @@ -1339,6 +1356,7 @@ static struct snd_soc_dai_ops wm8753_dai_ops_hifi_mode3 = { }; static struct snd_soc_dai_ops wm8753_dai_ops_hifi_mode4 = { + .startup = wm8753_i2s_startup, .hw_params = wm8753_i2s_hw_params, .digital_mute = wm8753_mute, .set_fmt = wm8753_mode3_4_set_dai_fmt, @@ -1347,10 +1365,9 @@ static struct snd_soc_dai_ops wm8753_dai_ops_hifi_mode4 = { .set_sysclk = wm8753_set_dai_sysclk, }; -static const struct snd_soc_dai wm8753_all_dai[] = { +static struct snd_soc_dai_driver wm8753_all_dai[] = { /* DAI HiFi mode 1 */ -{ .name = "WM8753 HiFi", - .id = 1, +{ .name = "wm8753-hifi", .playback = { .stream_name = "HiFi Playback", .channels_min = 1, @@ -1366,8 +1383,7 @@ static const struct snd_soc_dai wm8753_all_dai[] = { .ops = &wm8753_dai_ops_hifi_mode1, }, /* DAI Voice mode 1 */ -{ .name = "WM8753 Voice", - .id = 1, +{ .name = "wm8753-voice", .playback = { .stream_name = "Voice Playback", .channels_min = 1, @@ -1383,12 +1399,10 @@ static const struct snd_soc_dai wm8753_all_dai[] = { .ops = &wm8753_dai_ops_voice_mode1, }, /* DAI HiFi mode 2 - dummy */ -{ .name = "WM8753 HiFi", - .id = 2, +{ .name = "wm8753-hifi", }, /* DAI Voice mode 2 */ -{ .name = "WM8753 Voice", - .id = 2, +{ .name = "wm8753-voice", .playback = { .stream_name = "Voice Playback", .channels_min = 1, @@ -1404,8 +1418,7 @@ static const struct snd_soc_dai wm8753_all_dai[] = { .ops = &wm8753_dai_ops_voice_mode2, }, /* DAI HiFi mode 3 */ -{ .name = "WM8753 HiFi", - .id = 3, +{ .name = "wm8753-hifi", .playback = { .stream_name = "HiFi Playback", .channels_min = 1, @@ -1421,12 +1434,10 @@ static const struct snd_soc_dai wm8753_all_dai[] = { .ops = &wm8753_dai_ops_hifi_mode3, }, /* DAI Voice mode 3 - dummy */ -{ .name = "WM8753 Voice", - .id = 3, +{ .name = "wm8753-voice", }, /* DAI HiFi mode 4 */ -{ .name = "WM8753 HiFi", - .id = 4, +{ .name = "wm8753-hifi", .playback = { .stream_name = "HiFi Playback", .channels_min = 1, @@ -1442,58 +1453,31 @@ static const struct snd_soc_dai wm8753_all_dai[] = { .ops = &wm8753_dai_ops_hifi_mode4, }, /* DAI Voice mode 4 - dummy */ -{ .name = "WM8753 Voice", - .id = 4, +{ .name = "wm8753-voice", }, }; -struct snd_soc_dai wm8753_dai[] = { +static struct snd_soc_dai_driver wm8753_dai[] = { { - .name = "WM8753 DAI 0", + .name = "wm8753-aif0", }, { - .name = "WM8753 DAI 1", + .name = "wm8753-aif1", }, }; -EXPORT_SYMBOL_GPL(wm8753_dai); -static void wm8753_set_dai_mode(struct snd_soc_codec *codec, unsigned int mode) +static void wm8753_set_dai_mode(struct snd_soc_codec *codec, + struct snd_soc_dai *dai, unsigned int hifi) { - if (mode < 4) { - int playback_active, capture_active, codec_active, pop_wait; - void *private_data; - struct list_head list; - - playback_active = wm8753_dai[0].playback.active; - capture_active = wm8753_dai[0].capture.active; - codec_active = wm8753_dai[0].active; - private_data = wm8753_dai[0].private_data; - pop_wait = wm8753_dai[0].pop_wait; - list = wm8753_dai[0].list; - wm8753_dai[0] = wm8753_all_dai[mode << 1]; - wm8753_dai[0].playback.active = playback_active; - wm8753_dai[0].capture.active = capture_active; - wm8753_dai[0].active = codec_active; - wm8753_dai[0].private_data = private_data; - wm8753_dai[0].pop_wait = pop_wait; - wm8753_dai[0].list = list; - - playback_active = wm8753_dai[1].playback.active; - capture_active = wm8753_dai[1].capture.active; - codec_active = wm8753_dai[1].active; - private_data = wm8753_dai[1].private_data; - pop_wait = wm8753_dai[1].pop_wait; - list = wm8753_dai[1].list; - wm8753_dai[1] = wm8753_all_dai[(mode << 1) + 1]; - wm8753_dai[1].playback.active = playback_active; - wm8753_dai[1].capture.active = capture_active; - wm8753_dai[1].active = codec_active; - wm8753_dai[1].private_data = private_data; - wm8753_dai[1].pop_wait = pop_wait; - wm8753_dai[1].list = list; + struct wm8753_priv *wm8753 = snd_soc_codec_get_drvdata(codec); + + if (wm8753->dai_func < 4) { + if (hifi) + dai->driver = &wm8753_all_dai[wm8753->dai_func << 1]; + else + dai->driver = &wm8753_all_dai[(wm8753->dai_func << 1) + 1]; } - wm8753_dai[0].codec = codec; - wm8753_dai[1].codec = codec; + wm8753_write(codec, WM8753_IOCTL, wm8753->dai_func); } static void wm8753_work(struct work_struct *work) @@ -1503,19 +1487,14 @@ static void wm8753_work(struct work_struct *work) wm8753_set_bias_level(codec, codec->bias_level); } -static int wm8753_suspend(struct platform_device *pdev, pm_message_t state) +static int wm8753_suspend(struct snd_soc_codec *codec, pm_message_t state) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; - wm8753_set_bias_level(codec, SND_SOC_BIAS_OFF); return 0; } -static int wm8753_resume(struct platform_device *pdev) +static int wm8753_resume(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec = socdev->card->codec; int i; u8 data[2]; u16 *cache = codec->reg_cache; @@ -1547,41 +1526,6 @@ static int wm8753_resume(struct platform_device *pdev) return 0; } -static struct snd_soc_codec *wm8753_codec; - -static int wm8753_probe(struct platform_device *pdev) -{ - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - struct snd_soc_codec *codec; - int ret = 0; - - if (!wm8753_codec) { - dev_err(&pdev->dev, "WM8753 codec not yet registered\n"); - return -EINVAL; - } - - socdev->card->codec = wm8753_codec; - codec = wm8753_codec; - - wm8753_set_dai_mode(codec, 0); - - /* register pcms */ - ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); - if (ret < 0) { - printk(KERN_ERR "wm8753: failed to create pcms\n"); - goto pcm_err; - } - - snd_soc_add_controls(codec, wm8753_snd_controls, - ARRAY_SIZE(wm8753_snd_controls)); - wm8753_add_widgets(codec); - - return 0; - -pcm_err: - return ret; -} - /* * This function forces any delayed work to be queued and run. */ @@ -1601,62 +1545,28 @@ static int run_delayed_work(struct delayed_work *dwork) return ret; } -/* power down chip */ -static int wm8753_remove(struct platform_device *pdev) +static int wm8753_probe(struct snd_soc_codec *codec) { - struct snd_soc_device *socdev = platform_get_drvdata(pdev); - - snd_soc_free_pcms(socdev); - snd_soc_dapm_free(socdev); - - return 0; -} - -struct snd_soc_codec_device soc_codec_dev_wm8753 = { - .probe = wm8753_probe, - .remove = wm8753_remove, - .suspend = wm8753_suspend, - .resume = wm8753_resume, -}; -EXPORT_SYMBOL_GPL(soc_codec_dev_wm8753); + struct wm8753_priv *wm8753 = snd_soc_codec_get_drvdata(codec); + int ret = 0, reg; -static int wm8753_register(struct wm8753_priv *wm8753) -{ - int ret, i; - struct snd_soc_codec *codec = &wm8753->codec; - u16 reg; + INIT_DELAYED_WORK(&codec->delayed_work, wm8753_work); - if (wm8753_codec) { - dev_err(codec->dev, "Multiple WM8753 devices not supported\n"); - ret = -EINVAL; - goto err; + ret = snd_soc_codec_set_cache_io(codec, 7, 9, wm8753->control_type); + if (ret < 0) { + dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); + return ret; } - mutex_init(&codec->mutex); - INIT_LIST_HEAD(&codec->dapm_widgets); - INIT_LIST_HEAD(&codec->dapm_paths); - - codec->name = "WM8753"; - codec->owner = THIS_MODULE; - codec->read = wm8753_read_reg_cache; - codec->write = wm8753_write; - codec->bias_level = SND_SOC_BIAS_STANDBY; - codec->set_bias_level = wm8753_set_bias_level; - codec->dai = wm8753_dai; - codec->num_dai = 2; - codec->reg_cache_size = ARRAY_SIZE(wm8753->reg_cache) + 1; - codec->reg_cache = &wm8753->reg_cache; - snd_soc_codec_set_drvdata(codec, wm8753); - - memcpy(codec->reg_cache, wm8753_reg, sizeof(wm8753->reg_cache)); - INIT_DELAYED_WORK(&codec->delayed_work, wm8753_work); - ret = wm8753_reset(codec); if (ret < 0) { - dev_err(codec->dev, "Failed to issue reset\n"); - goto err; + dev_err(codec->dev, "Failed to issue reset: %d\n", ret); + return ret; } + wm8753_set_bias_level(codec, SND_SOC_BIAS_STANDBY); + wm8753->dai_func = 0; + /* charge output caps */ wm8753_set_bias_level(codec, SND_SOC_BIAS_PREPARE); schedule_delayed_work(&codec->delayed_work, @@ -1684,165 +1594,133 @@ static int wm8753_register(struct wm8753_priv *wm8753) reg = wm8753_read_reg_cache(codec, WM8753_RINVOL); wm8753_write(codec, WM8753_RINVOL, reg | 0x0100); - wm8753_codec = codec; - - for (i = 0; i < ARRAY_SIZE(wm8753_dai); i++) - wm8753_dai[i].dev = codec->dev; - - ret = snd_soc_register_codec(codec); - if (ret != 0) { - dev_err(codec->dev, "Failed to register codec: %d\n", ret); - goto err; - } - - ret = snd_soc_register_dais(&wm8753_dai[0], ARRAY_SIZE(wm8753_dai)); - if (ret != 0) { - dev_err(codec->dev, "Failed to register DAIs: %d\n", ret); - goto err_codec; - } + snd_soc_add_controls(codec, wm8753_snd_controls, + ARRAY_SIZE(wm8753_snd_controls)); + wm8753_add_widgets(codec); return 0; - -err_codec: - run_delayed_work(&codec->delayed_work); - snd_soc_unregister_codec(codec); -err: - kfree(wm8753); - return ret; } -static void wm8753_unregister(struct wm8753_priv *wm8753) +/* power down chip */ +static int wm8753_remove(struct snd_soc_codec *codec) { - wm8753_set_bias_level(&wm8753->codec, SND_SOC_BIAS_OFF); - run_delayed_work(&wm8753->codec.delayed_work); - snd_soc_unregister_dais(&wm8753_dai[0], ARRAY_SIZE(wm8753_dai)); - snd_soc_unregister_codec(&wm8753->codec); - kfree(wm8753); - wm8753_codec = NULL; + run_delayed_work(&codec->delayed_work); + wm8753_set_bias_level(codec, SND_SOC_BIAS_OFF); + + return 0; } -#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) +static struct snd_soc_codec_driver soc_codec_dev_wm8753 = { + .probe = wm8753_probe, + .remove = wm8753_remove, + .suspend = wm8753_suspend, + .resume = wm8753_resume, + .set_bias_level = wm8753_set_bias_level, + .reg_cache_size = ARRAY_SIZE(wm8753_reg), + .reg_word_size = sizeof(u16), + .reg_cache_default = wm8753_reg, +}; -static int wm8753_i2c_probe(struct i2c_client *i2c, - const struct i2c_device_id *id) +#if defined(CONFIG_SPI_MASTER) +static int __devinit wm8753_spi_probe(struct spi_device *spi) { - struct snd_soc_codec *codec; struct wm8753_priv *wm8753; + int ret; wm8753 = kzalloc(sizeof(struct wm8753_priv), GFP_KERNEL); if (wm8753 == NULL) return -ENOMEM; - codec = &wm8753->codec; - codec->hw_write = (hw_write_t)i2c_master_send; - codec->control_data = i2c; - i2c_set_clientdata(i2c, wm8753); - - codec->dev = &i2c->dev; + wm8753->control_type = SND_SOC_SPI; + spi_set_drvdata(spi, wm8753); - return wm8753_register(wm8753); + ret = snd_soc_register_codec(&spi->dev, + &soc_codec_dev_wm8753, wm8753_dai, ARRAY_SIZE(wm8753_dai)); + if (ret < 0) + kfree(wm8753); + return ret; } -static int wm8753_i2c_remove(struct i2c_client *client) +static int __devexit wm8753_spi_remove(struct spi_device *spi) { - struct wm8753_priv *wm8753 = i2c_get_clientdata(client); - wm8753_unregister(wm8753); - return 0; + snd_soc_unregister_codec(&spi->dev); + kfree(spi_get_drvdata(spi)); + return 0; } -static const struct i2c_device_id wm8753_i2c_id[] = { - { "wm8753", 0 }, - { } -}; -MODULE_DEVICE_TABLE(i2c, wm8753_i2c_id); - -static struct i2c_driver wm8753_i2c_driver = { +static struct spi_driver wm8753_spi_driver = { .driver = { - .name = "wm8753", - .owner = THIS_MODULE, + .name = "wm8753-codec", + .owner = THIS_MODULE, }, - .probe = wm8753_i2c_probe, - .remove = wm8753_i2c_remove, - .id_table = wm8753_i2c_id, + .probe = wm8753_spi_probe, + .remove = __devexit_p(wm8753_spi_remove), }; -#endif - -#if defined(CONFIG_SPI_MASTER) -static int wm8753_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; +#endif /* CONFIG_SPI_MASTER */ - 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; -} - -static int __devinit wm8753_spi_probe(struct spi_device *spi) +#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) +static __devinit int wm8753_i2c_probe(struct i2c_client *i2c, + const struct i2c_device_id *id) { - struct snd_soc_codec *codec; struct wm8753_priv *wm8753; + int ret; wm8753 = kzalloc(sizeof(struct wm8753_priv), GFP_KERNEL); if (wm8753 == NULL) return -ENOMEM; - codec = &wm8753->codec; - codec->control_data = spi; - codec->hw_write = (hw_write_t)wm8753_spi_write; - codec->dev = &spi->dev; + i2c_set_clientdata(i2c, wm8753); + wm8753->control_type = SND_SOC_I2C; - dev_set_drvdata(&spi->dev, wm8753); - - return wm8753_register(wm8753); + ret = snd_soc_register_codec(&i2c->dev, + &soc_codec_dev_wm8753, wm8753_dai, ARRAY_SIZE(wm8753_dai)); + if (ret < 0) + kfree(wm8753); + return ret; } -static int __devexit wm8753_spi_remove(struct spi_device *spi) +static __devexit int wm8753_i2c_remove(struct i2c_client *client) { - struct wm8753_priv *wm8753 = dev_get_drvdata(&spi->dev); - wm8753_unregister(wm8753); + snd_soc_unregister_codec(&client->dev); + kfree(i2c_get_clientdata(client)); return 0; } -static struct spi_driver wm8753_spi_driver = { +static const struct i2c_device_id wm8753_i2c_id[] = { + { "wm8753", 0 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, wm8753_i2c_id); + +static struct i2c_driver wm8753_i2c_driver = { .driver = { - .name = "wm8753", - .bus = &spi_bus_type, - .owner = THIS_MODULE, + .name = "wm8753-codec", + .owner = THIS_MODULE, }, - .probe = wm8753_spi_probe, - .remove = __devexit_p(wm8753_spi_remove), + .probe = wm8753_i2c_probe, + .remove = __devexit_p(wm8753_i2c_remove), + .id_table = wm8753_i2c_id, }; #endif static int __init wm8753_modinit(void) { - int ret; + int ret = 0; #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) ret = i2c_add_driver(&wm8753_i2c_driver); - if (ret != 0) - pr_err("Failed to register WM8753 I2C driver: %d\n", ret); + if (ret != 0) { + printk(KERN_ERR "Failed to register wm8753 I2C driver: %d\n", + ret); + } #endif #if defined(CONFIG_SPI_MASTER) ret = spi_register_driver(&wm8753_spi_driver); - if (ret != 0) - pr_err("Failed to register WM8753 SPI driver: %d\n", ret); + if (ret != 0) { + printk(KERN_ERR "Failed to register wm8753 SPI driver: %d\n", + ret); + } #endif - return 0; + return ret; } module_init(wm8753_modinit); |