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> |
Jarkko Nikula | f8a770c | 2014-09-29 16:58:16 +0300 | [diff] [blame] | 20 | #include <linux/dmi.h> |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 21 | #include <linux/slab.h> |
| 22 | #include <sound/pcm.h> |
| 23 | #include <sound/pcm_params.h> |
| 24 | #include <sound/soc.h> |
| 25 | #include <sound/jack.h> |
| 26 | #include "../codecs/rt5640.h" |
| 27 | |
| 28 | #include "sst-dsp.h" |
| 29 | |
| 30 | static const struct snd_soc_dapm_widget byt_rt5640_widgets[] = { |
| 31 | SND_SOC_DAPM_HP("Headphone", NULL), |
| 32 | SND_SOC_DAPM_MIC("Headset Mic", NULL), |
| 33 | SND_SOC_DAPM_MIC("Internal Mic", NULL), |
| 34 | SND_SOC_DAPM_SPK("Speaker", NULL), |
| 35 | }; |
| 36 | |
| 37 | static const struct snd_soc_dapm_route byt_rt5640_audio_map[] = { |
Jarkko Nikula | c9a8e3b | 2014-06-09 14:39:06 +0300 | [diff] [blame] | 38 | {"Headset Mic", NULL, "MICBIAS1"}, |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 39 | {"IN2P", NULL, "Headset Mic"}, |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 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 | |
Jarkko Nikula | f8a770c | 2014-09-29 16:58:16 +0300 | [diff] [blame] | 48 | static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic1_map[] = { |
| 49 | {"DMIC1", NULL, "Internal Mic"}, |
| 50 | }; |
| 51 | |
Jarkko Nikula | 24221dc | 2014-10-02 13:29:08 +0300 | [diff] [blame] | 52 | static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic2_map[] = { |
| 53 | {"DMIC2", NULL, "Internal Mic"}, |
| 54 | }; |
| 55 | |
Jarkko Nikula | f8a770c | 2014-09-29 16:58:16 +0300 | [diff] [blame] | 56 | static const struct snd_soc_dapm_route byt_rt5640_intmic_in1_map[] = { |
| 57 | {"Internal Mic", NULL, "MICBIAS1"}, |
| 58 | {"IN1P", NULL, "Internal Mic"}, |
| 59 | }; |
| 60 | |
| 61 | enum { |
| 62 | BYT_RT5640_DMIC1_MAP, |
Jarkko Nikula | 24221dc | 2014-10-02 13:29:08 +0300 | [diff] [blame] | 63 | BYT_RT5640_DMIC2_MAP, |
Jarkko Nikula | f8a770c | 2014-09-29 16:58:16 +0300 | [diff] [blame] | 64 | BYT_RT5640_IN1_MAP, |
| 65 | }; |
| 66 | |
Jarkko Nikula | a5f0ab0 | 2014-10-01 15:08:15 +0300 | [diff] [blame] | 67 | #define BYT_RT5640_MAP(quirk) ((quirk) & 0xff) |
| 68 | #define BYT_RT5640_DMIC_EN BIT(16) |
| 69 | |
| 70 | static unsigned long byt_rt5640_quirk = BYT_RT5640_DMIC1_MAP | |
| 71 | BYT_RT5640_DMIC_EN; |
Jarkko Nikula | f8a770c | 2014-09-29 16:58:16 +0300 | [diff] [blame] | 72 | |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 73 | static const struct snd_kcontrol_new byt_rt5640_controls[] = { |
| 74 | SOC_DAPM_PIN_SWITCH("Headphone"), |
| 75 | SOC_DAPM_PIN_SWITCH("Headset Mic"), |
| 76 | SOC_DAPM_PIN_SWITCH("Internal Mic"), |
| 77 | SOC_DAPM_PIN_SWITCH("Speaker"), |
| 78 | }; |
| 79 | |
| 80 | static int byt_rt5640_hw_params(struct snd_pcm_substream *substream, |
| 81 | struct snd_pcm_hw_params *params) |
| 82 | { |
| 83 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 84 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 85 | int ret; |
| 86 | |
| 87 | ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_PLL1, |
| 88 | params_rate(params) * 256, |
| 89 | SND_SOC_CLOCK_IN); |
| 90 | if (ret < 0) { |
| 91 | dev_err(codec_dai->dev, "can't set codec clock %d\n", ret); |
| 92 | return ret; |
| 93 | } |
| 94 | ret = snd_soc_dai_set_pll(codec_dai, 0, RT5640_PLL1_S_BCLK1, |
| 95 | params_rate(params) * 64, |
| 96 | params_rate(params) * 256); |
| 97 | if (ret < 0) { |
| 98 | dev_err(codec_dai->dev, "can't set codec pll: %d\n", ret); |
| 99 | return ret; |
| 100 | } |
| 101 | return 0; |
| 102 | } |
| 103 | |
Jarkko Nikula | f8a770c | 2014-09-29 16:58:16 +0300 | [diff] [blame] | 104 | static int byt_rt5640_quirk_cb(const struct dmi_system_id *id) |
| 105 | { |
Jarkko Nikula | a5f0ab0 | 2014-10-01 15:08:15 +0300 | [diff] [blame] | 106 | byt_rt5640_quirk = (unsigned long)id->driver_data; |
Jarkko Nikula | f8a770c | 2014-09-29 16:58:16 +0300 | [diff] [blame] | 107 | return 1; |
| 108 | } |
| 109 | |
| 110 | static const struct dmi_system_id byt_rt5640_quirk_table[] = { |
| 111 | { |
| 112 | .callback = byt_rt5640_quirk_cb, |
| 113 | .matches = { |
| 114 | DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."), |
| 115 | DMI_MATCH(DMI_PRODUCT_NAME, "T100TA"), |
| 116 | }, |
| 117 | .driver_data = (unsigned long *)BYT_RT5640_IN1_MAP, |
| 118 | }, |
Jarkko Nikula | 24221dc | 2014-10-02 13:29:08 +0300 | [diff] [blame] | 119 | { |
| 120 | .callback = byt_rt5640_quirk_cb, |
| 121 | .matches = { |
| 122 | DMI_MATCH(DMI_SYS_VENDOR, "DellInc."), |
| 123 | DMI_MATCH(DMI_PRODUCT_NAME, "Venue 8 Pro 5830"), |
| 124 | }, |
| 125 | .driver_data = (unsigned long *)(BYT_RT5640_DMIC2_MAP | |
| 126 | BYT_RT5640_DMIC_EN), |
| 127 | }, |
Jarkko Nikula | f8a770c | 2014-09-29 16:58:16 +0300 | [diff] [blame] | 128 | {} |
| 129 | }; |
| 130 | |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 131 | static int byt_rt5640_init(struct snd_soc_pcm_runtime *runtime) |
| 132 | { |
| 133 | int ret; |
| 134 | struct snd_soc_codec *codec = runtime->codec; |
| 135 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
| 136 | struct snd_soc_card *card = runtime->card; |
Jarkko Nikula | f8a770c | 2014-09-29 16:58:16 +0300 | [diff] [blame] | 137 | const struct snd_soc_dapm_route *custom_map; |
| 138 | int num_routes; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 139 | |
| 140 | card->dapm.idle_bias_off = true; |
| 141 | |
| 142 | ret = snd_soc_add_card_controls(card, byt_rt5640_controls, |
| 143 | ARRAY_SIZE(byt_rt5640_controls)); |
| 144 | if (ret) { |
| 145 | dev_err(card->dev, "unable to add card controls\n"); |
| 146 | return ret; |
| 147 | } |
| 148 | |
Jarkko Nikula | f8a770c | 2014-09-29 16:58:16 +0300 | [diff] [blame] | 149 | dmi_check_system(byt_rt5640_quirk_table); |
Jarkko Nikula | a5f0ab0 | 2014-10-01 15:08:15 +0300 | [diff] [blame] | 150 | switch (BYT_RT5640_MAP(byt_rt5640_quirk)) { |
Jarkko Nikula | f8a770c | 2014-09-29 16:58:16 +0300 | [diff] [blame] | 151 | case BYT_RT5640_IN1_MAP: |
| 152 | custom_map = byt_rt5640_intmic_in1_map; |
| 153 | num_routes = ARRAY_SIZE(byt_rt5640_intmic_in1_map); |
| 154 | break; |
Jarkko Nikula | 24221dc | 2014-10-02 13:29:08 +0300 | [diff] [blame] | 155 | case BYT_RT5640_DMIC2_MAP: |
| 156 | custom_map = byt_rt5640_intmic_dmic2_map; |
| 157 | num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic2_map); |
| 158 | break; |
Jarkko Nikula | f8a770c | 2014-09-29 16:58:16 +0300 | [diff] [blame] | 159 | default: |
| 160 | custom_map = byt_rt5640_intmic_dmic1_map; |
| 161 | num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic1_map); |
Fengguang Wu | bb78cdd | 2014-10-04 19:09:33 +0100 | [diff] [blame] | 162 | } |
Jarkko Nikula | f8a770c | 2014-09-29 16:58:16 +0300 | [diff] [blame] | 163 | |
| 164 | ret = snd_soc_dapm_add_routes(dapm, custom_map, num_routes); |
| 165 | if (ret) |
| 166 | return ret; |
| 167 | |
Jarkko Nikula | a5f0ab0 | 2014-10-01 15:08:15 +0300 | [diff] [blame] | 168 | if (byt_rt5640_quirk & BYT_RT5640_DMIC_EN) { |
| 169 | ret = rt5640_dmic_enable(codec, 0, 0); |
| 170 | if (ret) |
| 171 | return ret; |
| 172 | } |
| 173 | |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 174 | snd_soc_dapm_ignore_suspend(dapm, "HPOL"); |
| 175 | snd_soc_dapm_ignore_suspend(dapm, "HPOR"); |
| 176 | |
| 177 | snd_soc_dapm_ignore_suspend(dapm, "SPOLP"); |
| 178 | snd_soc_dapm_ignore_suspend(dapm, "SPOLN"); |
| 179 | snd_soc_dapm_ignore_suspend(dapm, "SPORP"); |
| 180 | snd_soc_dapm_ignore_suspend(dapm, "SPORN"); |
| 181 | |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 182 | return ret; |
| 183 | } |
| 184 | |
| 185 | static struct snd_soc_ops byt_rt5640_ops = { |
| 186 | .hw_params = byt_rt5640_hw_params, |
| 187 | }; |
| 188 | |
| 189 | static struct snd_soc_dai_link byt_rt5640_dais[] = { |
| 190 | { |
| 191 | .name = "Baytrail Audio", |
| 192 | .stream_name = "Audio", |
Liam Girdwood | 49fee17 | 2014-05-14 17:20:54 +0300 | [diff] [blame] | 193 | .cpu_dai_name = "baytrail-pcm-audio", |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 194 | .codec_dai_name = "rt5640-aif1", |
| 195 | .codec_name = "i2c-10EC5640:00", |
| 196 | .platform_name = "baytrail-pcm-audio", |
| 197 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | |
| 198 | SND_SOC_DAIFMT_CBS_CFS, |
| 199 | .init = byt_rt5640_init, |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 200 | .ops = &byt_rt5640_ops, |
| 201 | }, |
| 202 | }; |
| 203 | |
| 204 | static struct snd_soc_card byt_rt5640_card = { |
| 205 | .name = "byt-rt5640", |
| 206 | .dai_link = byt_rt5640_dais, |
| 207 | .num_links = ARRAY_SIZE(byt_rt5640_dais), |
| 208 | .dapm_widgets = byt_rt5640_widgets, |
| 209 | .num_dapm_widgets = ARRAY_SIZE(byt_rt5640_widgets), |
| 210 | .dapm_routes = byt_rt5640_audio_map, |
| 211 | .num_dapm_routes = ARRAY_SIZE(byt_rt5640_audio_map), |
Jarkko Nikula | c47a39a | 2014-10-02 13:29:09 +0300 | [diff] [blame] | 212 | .fully_routed = true, |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 213 | }; |
| 214 | |
| 215 | static int byt_rt5640_probe(struct platform_device *pdev) |
| 216 | { |
| 217 | struct snd_soc_card *card = &byt_rt5640_card; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 218 | |
| 219 | card->dev = &pdev->dev; |
Jarkko Nikula | 8eb776a | 2014-05-28 12:35:39 +0300 | [diff] [blame] | 220 | return devm_snd_soc_register_card(&pdev->dev, card); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | static struct platform_driver byt_rt5640_audio = { |
| 224 | .probe = byt_rt5640_probe, |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 225 | .driver = { |
| 226 | .name = "byt-rt5640", |
| 227 | .owner = THIS_MODULE, |
Jarkko Nikula | 4af72f4 | 2014-05-26 16:56:33 +0300 | [diff] [blame] | 228 | .pm = &snd_soc_pm_ops, |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 229 | }, |
| 230 | }; |
| 231 | module_platform_driver(byt_rt5640_audio) |
| 232 | |
| 233 | MODULE_DESCRIPTION("ASoC Intel(R) Baytrail Machine driver"); |
| 234 | MODULE_AUTHOR("Omair Md Abdullah, Jarkko Nikula"); |
| 235 | MODULE_LICENSE("GPL v2"); |
| 236 | MODULE_ALIAS("platform:byt-rt5640"); |