Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Intel Baytrail SST RT5640 machine driver |
| 3 | * Copyright (c) 2014, Intel Corporation. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms and conditions of the GNU General Public License, |
| 7 | * version 2, as published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | * more details. |
| 13 | */ |
| 14 | |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/platform_device.h> |
| 18 | #include <linux/acpi.h> |
| 19 | #include <linux/device.h> |
| 20 | #include <linux/slab.h> |
| 21 | #include <sound/pcm.h> |
| 22 | #include <sound/pcm_params.h> |
| 23 | #include <sound/soc.h> |
| 24 | #include <sound/jack.h> |
| 25 | #include "../codecs/rt5640.h" |
| 26 | |
| 27 | #include "sst-dsp.h" |
| 28 | |
| 29 | static const struct snd_soc_dapm_widget byt_rt5640_widgets[] = { |
| 30 | SND_SOC_DAPM_HP("Headphone", NULL), |
| 31 | SND_SOC_DAPM_MIC("Headset Mic", NULL), |
| 32 | SND_SOC_DAPM_MIC("Internal Mic", NULL), |
| 33 | SND_SOC_DAPM_SPK("Speaker", NULL), |
| 34 | }; |
| 35 | |
| 36 | static const struct snd_soc_dapm_route byt_rt5640_audio_map[] = { |
| 37 | {"IN2P", NULL, "Headset Mic"}, |
| 38 | {"IN2N", NULL, "Headset Mic"}, |
| 39 | {"DMIC1", NULL, "Internal Mic"}, |
| 40 | {"Headphone", NULL, "HPOL"}, |
| 41 | {"Headphone", NULL, "HPOR"}, |
| 42 | {"Speaker", NULL, "SPOLP"}, |
| 43 | {"Speaker", NULL, "SPOLN"}, |
| 44 | {"Speaker", NULL, "SPORP"}, |
| 45 | {"Speaker", NULL, "SPORN"}, |
| 46 | }; |
| 47 | |
| 48 | static const struct snd_kcontrol_new byt_rt5640_controls[] = { |
| 49 | SOC_DAPM_PIN_SWITCH("Headphone"), |
| 50 | SOC_DAPM_PIN_SWITCH("Headset Mic"), |
| 51 | SOC_DAPM_PIN_SWITCH("Internal Mic"), |
| 52 | SOC_DAPM_PIN_SWITCH("Speaker"), |
| 53 | }; |
| 54 | |
| 55 | static int byt_rt5640_hw_params(struct snd_pcm_substream *substream, |
| 56 | struct snd_pcm_hw_params *params) |
| 57 | { |
| 58 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 59 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 60 | int ret; |
| 61 | |
| 62 | ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_PLL1, |
| 63 | params_rate(params) * 256, |
| 64 | SND_SOC_CLOCK_IN); |
| 65 | if (ret < 0) { |
| 66 | dev_err(codec_dai->dev, "can't set codec clock %d\n", ret); |
| 67 | return ret; |
| 68 | } |
| 69 | ret = snd_soc_dai_set_pll(codec_dai, 0, RT5640_PLL1_S_BCLK1, |
| 70 | params_rate(params) * 64, |
| 71 | params_rate(params) * 256); |
| 72 | if (ret < 0) { |
| 73 | dev_err(codec_dai->dev, "can't set codec pll: %d\n", ret); |
| 74 | return ret; |
| 75 | } |
| 76 | return 0; |
| 77 | } |
| 78 | |
| 79 | static int byt_rt5640_init(struct snd_soc_pcm_runtime *runtime) |
| 80 | { |
| 81 | int ret; |
| 82 | struct snd_soc_codec *codec = runtime->codec; |
| 83 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
| 84 | struct snd_soc_card *card = runtime->card; |
| 85 | |
| 86 | card->dapm.idle_bias_off = true; |
| 87 | |
| 88 | ret = snd_soc_add_card_controls(card, byt_rt5640_controls, |
| 89 | ARRAY_SIZE(byt_rt5640_controls)); |
| 90 | if (ret) { |
| 91 | dev_err(card->dev, "unable to add card controls\n"); |
| 92 | return ret; |
| 93 | } |
| 94 | |
| 95 | snd_soc_dapm_ignore_suspend(dapm, "HPOL"); |
| 96 | snd_soc_dapm_ignore_suspend(dapm, "HPOR"); |
| 97 | |
| 98 | snd_soc_dapm_ignore_suspend(dapm, "SPOLP"); |
| 99 | snd_soc_dapm_ignore_suspend(dapm, "SPOLN"); |
| 100 | snd_soc_dapm_ignore_suspend(dapm, "SPORP"); |
| 101 | snd_soc_dapm_ignore_suspend(dapm, "SPORN"); |
| 102 | |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 103 | return ret; |
| 104 | } |
| 105 | |
| 106 | static struct snd_soc_ops byt_rt5640_ops = { |
| 107 | .hw_params = byt_rt5640_hw_params, |
| 108 | }; |
| 109 | |
| 110 | static struct snd_soc_dai_link byt_rt5640_dais[] = { |
| 111 | { |
| 112 | .name = "Baytrail Audio", |
| 113 | .stream_name = "Audio", |
Liam Girdwood | 49fee17 | 2014-05-14 17:20:54 +0300 | [diff] [blame] | 114 | .cpu_dai_name = "baytrail-pcm-audio", |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 115 | .codec_dai_name = "rt5640-aif1", |
| 116 | .codec_name = "i2c-10EC5640:00", |
| 117 | .platform_name = "baytrail-pcm-audio", |
| 118 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | |
| 119 | SND_SOC_DAIFMT_CBS_CFS, |
| 120 | .init = byt_rt5640_init, |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 121 | .ops = &byt_rt5640_ops, |
| 122 | }, |
| 123 | }; |
| 124 | |
| 125 | static struct snd_soc_card byt_rt5640_card = { |
| 126 | .name = "byt-rt5640", |
| 127 | .dai_link = byt_rt5640_dais, |
| 128 | .num_links = ARRAY_SIZE(byt_rt5640_dais), |
| 129 | .dapm_widgets = byt_rt5640_widgets, |
| 130 | .num_dapm_widgets = ARRAY_SIZE(byt_rt5640_widgets), |
| 131 | .dapm_routes = byt_rt5640_audio_map, |
| 132 | .num_dapm_routes = ARRAY_SIZE(byt_rt5640_audio_map), |
| 133 | }; |
| 134 | |
| 135 | static int byt_rt5640_probe(struct platform_device *pdev) |
| 136 | { |
| 137 | struct snd_soc_card *card = &byt_rt5640_card; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 138 | |
| 139 | card->dev = &pdev->dev; |
Jarkko Nikula | 8eb776a | 2014-05-28 12:35:39 +0300 | [diff] [blame] | 140 | return devm_snd_soc_register_card(&pdev->dev, card); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | static struct platform_driver byt_rt5640_audio = { |
| 144 | .probe = byt_rt5640_probe, |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 145 | .driver = { |
| 146 | .name = "byt-rt5640", |
| 147 | .owner = THIS_MODULE, |
Jarkko Nikula | 4af72f4 | 2014-05-26 16:56:33 +0300 | [diff] [blame] | 148 | .pm = &snd_soc_pm_ops, |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 149 | }, |
| 150 | }; |
| 151 | module_platform_driver(byt_rt5640_audio) |
| 152 | |
| 153 | MODULE_DESCRIPTION("ASoC Intel(R) Baytrail Machine driver"); |
| 154 | MODULE_AUTHOR("Omair Md Abdullah, Jarkko Nikula"); |
| 155 | MODULE_LICENSE("GPL v2"); |
| 156 | MODULE_ALIAS("platform:byt-rt5640"); |