Path: blob/master/sound/soc/samsung/smartq_wm8987.c
10817 views
/* sound/soc/samsung/smartq_wm8987.c1*2* Copyright 2010 Maurus Cuelenaere <[email protected]>3*4* Based on smdk6410_wm8987.c5* Copyright 2007 Wolfson Microelectronics PLC. - [email protected]6* Graeme Gregory - [email protected]7*8* This program is free software; you can redistribute it and/or modify it9* under the terms of the GNU General Public License as published by the10* Free Software Foundation; either version 2 of the License, or (at your11* option) any later version.12*13*/1415#include <linux/gpio.h>1617#include <sound/soc.h>18#include <sound/jack.h>1920#include <asm/mach-types.h>2122#include "i2s.h"23#include "../codecs/wm8750.h"2425/*26* WM8987 is register compatible with WM8750, so using that as base driver.27*/2829static struct snd_soc_card snd_soc_smartq;3031static int smartq_hifi_hw_params(struct snd_pcm_substream *substream,32struct snd_pcm_hw_params *params)33{34struct snd_soc_pcm_runtime *rtd = substream->private_data;35struct snd_soc_dai *codec_dai = rtd->codec_dai;36struct snd_soc_dai *cpu_dai = rtd->cpu_dai;37unsigned int clk = 0;38int ret;3940switch (params_rate(params)) {41case 8000:42case 16000:43case 32000:44case 48000:45case 96000:46clk = 12288000;47break;48case 11025:49case 22050:50case 44100:51case 88200:52clk = 11289600;53break;54}5556/* set codec DAI configuration */57ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |58SND_SOC_DAIFMT_NB_NF |59SND_SOC_DAIFMT_CBS_CFS);60if (ret < 0)61return ret;6263/* set cpu DAI configuration */64ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |65SND_SOC_DAIFMT_NB_NF |66SND_SOC_DAIFMT_CBS_CFS);67if (ret < 0)68return ret;6970/* Use PCLK for I2S signal generation */71ret = snd_soc_dai_set_sysclk(cpu_dai, SAMSUNG_I2S_RCLKSRC_0,720, SND_SOC_CLOCK_IN);73if (ret < 0)74return ret;7576/* Gate the RCLK output on PAD */77ret = snd_soc_dai_set_sysclk(cpu_dai, SAMSUNG_I2S_CDCLK,780, SND_SOC_CLOCK_IN);79if (ret < 0)80return ret;8182/* set the codec system clock for DAC and ADC */83ret = snd_soc_dai_set_sysclk(codec_dai, WM8750_SYSCLK, clk,84SND_SOC_CLOCK_IN);85if (ret < 0)86return ret;8788return 0;89}9091/*92* SmartQ WM8987 HiFi DAI operations.93*/94static struct snd_soc_ops smartq_hifi_ops = {95.hw_params = smartq_hifi_hw_params,96};9798static struct snd_soc_jack smartq_jack;99100static struct snd_soc_jack_pin smartq_jack_pins[] = {101/* Disable speaker when headphone is plugged in */102{103.pin = "Internal Speaker",104.mask = SND_JACK_HEADPHONE,105},106};107108static struct snd_soc_jack_gpio smartq_jack_gpios[] = {109{110.gpio = S3C64XX_GPL(12),111.name = "headphone detect",112.report = SND_JACK_HEADPHONE,113.debounce_time = 200,114},115};116117static const struct snd_kcontrol_new wm8987_smartq_controls[] = {118SOC_DAPM_PIN_SWITCH("Internal Speaker"),119SOC_DAPM_PIN_SWITCH("Headphone Jack"),120SOC_DAPM_PIN_SWITCH("Internal Mic"),121};122123static int smartq_speaker_event(struct snd_soc_dapm_widget *w,124struct snd_kcontrol *k,125int event)126{127gpio_set_value(S3C64XX_GPK(12), SND_SOC_DAPM_EVENT_OFF(event));128129return 0;130}131132static const struct snd_soc_dapm_widget wm8987_dapm_widgets[] = {133SND_SOC_DAPM_SPK("Internal Speaker", smartq_speaker_event),134SND_SOC_DAPM_HP("Headphone Jack", NULL),135SND_SOC_DAPM_MIC("Internal Mic", NULL),136};137138static const struct snd_soc_dapm_route audio_map[] = {139{"Headphone Jack", NULL, "LOUT2"},140{"Headphone Jack", NULL, "ROUT2"},141142{"Internal Speaker", NULL, "LOUT2"},143{"Internal Speaker", NULL, "ROUT2"},144145{"Mic Bias", NULL, "Internal Mic"},146{"LINPUT2", NULL, "Mic Bias"},147};148149static int smartq_wm8987_init(struct snd_soc_pcm_runtime *rtd)150{151struct snd_soc_codec *codec = rtd->codec;152struct snd_soc_dapm_context *dapm = &codec->dapm;153int err = 0;154155/* Add SmartQ specific widgets */156snd_soc_dapm_new_controls(dapm, wm8987_dapm_widgets,157ARRAY_SIZE(wm8987_dapm_widgets));158159/* add SmartQ specific controls */160err = snd_soc_add_controls(codec, wm8987_smartq_controls,161ARRAY_SIZE(wm8987_smartq_controls));162163if (err < 0)164return err;165166/* setup SmartQ specific audio path */167snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));168169/* set endpoints to not connected */170snd_soc_dapm_nc_pin(dapm, "LINPUT1");171snd_soc_dapm_nc_pin(dapm, "RINPUT1");172snd_soc_dapm_nc_pin(dapm, "OUT3");173snd_soc_dapm_nc_pin(dapm, "ROUT1");174175/* set endpoints to default off mode */176snd_soc_dapm_enable_pin(dapm, "Internal Speaker");177snd_soc_dapm_enable_pin(dapm, "Internal Mic");178snd_soc_dapm_disable_pin(dapm, "Headphone Jack");179180err = snd_soc_dapm_sync(dapm);181if (err)182return err;183184/* Headphone jack detection */185err = snd_soc_jack_new(codec, "Headphone Jack",186SND_JACK_HEADPHONE, &smartq_jack);187if (err)188return err;189190err = snd_soc_jack_add_pins(&smartq_jack, ARRAY_SIZE(smartq_jack_pins),191smartq_jack_pins);192if (err)193return err;194195err = snd_soc_jack_add_gpios(&smartq_jack,196ARRAY_SIZE(smartq_jack_gpios),197smartq_jack_gpios);198199return err;200}201202static struct snd_soc_dai_link smartq_dai[] = {203{204.name = "wm8987",205.stream_name = "SmartQ Hi-Fi",206.cpu_dai_name = "samsung-i2s.0",207.codec_dai_name = "wm8750-hifi",208.platform_name = "samsung-audio",209.codec_name = "wm8750-codec.0-0x1a",210.init = smartq_wm8987_init,211.ops = &smartq_hifi_ops,212},213};214215static struct snd_soc_card snd_soc_smartq = {216.name = "SmartQ",217.dai_link = smartq_dai,218.num_links = ARRAY_SIZE(smartq_dai),219};220221static struct platform_device *smartq_snd_device;222223static int __init smartq_init(void)224{225int ret;226227if (!machine_is_smartq7() && !machine_is_smartq5()) {228pr_info("Only SmartQ is supported by this ASoC driver\n");229return -ENODEV;230}231232smartq_snd_device = platform_device_alloc("soc-audio", -1);233if (!smartq_snd_device)234return -ENOMEM;235236platform_set_drvdata(smartq_snd_device, &snd_soc_smartq);237238ret = platform_device_add(smartq_snd_device);239if (ret) {240platform_device_put(smartq_snd_device);241return ret;242}243244/* Initialise GPIOs used by amplifiers */245ret = gpio_request(S3C64XX_GPK(12), "amplifiers shutdown");246if (ret) {247dev_err(&smartq_snd_device->dev, "Failed to register GPK12\n");248goto err_unregister_device;249}250251/* Disable amplifiers */252ret = gpio_direction_output(S3C64XX_GPK(12), 1);253if (ret) {254dev_err(&smartq_snd_device->dev, "Failed to configure GPK12\n");255goto err_free_gpio_amp_shut;256}257258return 0;259260err_free_gpio_amp_shut:261gpio_free(S3C64XX_GPK(12));262err_unregister_device:263platform_device_unregister(smartq_snd_device);264265return ret;266}267268static void __exit smartq_exit(void)269{270gpio_free(S3C64XX_GPK(12));271snd_soc_jack_free_gpios(&smartq_jack, ARRAY_SIZE(smartq_jack_gpios),272smartq_jack_gpios);273274platform_device_unregister(smartq_snd_device);275}276277module_init(smartq_init);278module_exit(smartq_exit);279280/* Module information */281MODULE_AUTHOR("Maurus Cuelenaere <[email protected]>");282MODULE_DESCRIPTION("ALSA SoC SmartQ WM8987");283MODULE_LICENSE("GPL");284285286