bytcr_rt5640.c 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428
  1. /*
  2. * byt_cr_dpcm_rt5640.c - ASoc Machine driver for Intel Byt CR platform
  3. *
  4. * Copyright (C) 2014 Intel Corp
  5. * Author: Subhransu S. Prusty <subhransu.s.prusty@intel.com>
  6. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; version 2 of the License.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  18. */
  19. #include <linux/i2c.h>
  20. #include <linux/init.h>
  21. #include <linux/module.h>
  22. #include <linux/moduleparam.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/acpi.h>
  25. #include <linux/clk.h>
  26. #include <linux/device.h>
  27. #include <linux/dmi.h>
  28. #include <linux/input.h>
  29. #include <linux/slab.h>
  30. #include <asm/cpu_device_id.h>
  31. #include <asm/platform_sst_audio.h>
  32. #include <sound/pcm.h>
  33. #include <sound/pcm_params.h>
  34. #include <sound/soc.h>
  35. #include <sound/jack.h>
  36. #include <sound/soc-acpi.h>
  37. #include <dt-bindings/sound/rt5640.h>
  38. #include "../../codecs/rt5640.h"
  39. #include "../atom/sst-atom-controls.h"
  40. #include "../common/sst-dsp.h"
  41. enum {
  42. BYT_RT5640_DMIC1_MAP,
  43. BYT_RT5640_DMIC2_MAP,
  44. BYT_RT5640_IN1_MAP,
  45. BYT_RT5640_IN3_MAP,
  46. };
  47. enum {
  48. BYT_RT5640_JD_SRC_GPIO1 = (RT5640_JD_SRC_GPIO1 << 4),
  49. BYT_RT5640_JD_SRC_JD1_IN4P = (RT5640_JD_SRC_JD1_IN4P << 4),
  50. BYT_RT5640_JD_SRC_JD2_IN4N = (RT5640_JD_SRC_JD2_IN4N << 4),
  51. BYT_RT5640_JD_SRC_GPIO2 = (RT5640_JD_SRC_GPIO2 << 4),
  52. BYT_RT5640_JD_SRC_GPIO3 = (RT5640_JD_SRC_GPIO3 << 4),
  53. BYT_RT5640_JD_SRC_GPIO4 = (RT5640_JD_SRC_GPIO4 << 4),
  54. };
  55. enum {
  56. BYT_RT5640_OVCD_TH_600UA = (6 << 8),
  57. BYT_RT5640_OVCD_TH_1500UA = (15 << 8),
  58. BYT_RT5640_OVCD_TH_2000UA = (20 << 8),
  59. };
  60. enum {
  61. BYT_RT5640_OVCD_SF_0P5 = (RT5640_OVCD_SF_0P5 << 13),
  62. BYT_RT5640_OVCD_SF_0P75 = (RT5640_OVCD_SF_0P75 << 13),
  63. BYT_RT5640_OVCD_SF_1P0 = (RT5640_OVCD_SF_1P0 << 13),
  64. BYT_RT5640_OVCD_SF_1P5 = (RT5640_OVCD_SF_1P5 << 13),
  65. };
  66. #define BYT_RT5640_MAP(quirk) ((quirk) & GENMASK(3, 0))
  67. #define BYT_RT5640_JDSRC(quirk) (((quirk) & GENMASK(7, 4)) >> 4)
  68. #define BYT_RT5640_OVCD_TH(quirk) (((quirk) & GENMASK(12, 8)) >> 8)
  69. #define BYT_RT5640_OVCD_SF(quirk) (((quirk) & GENMASK(14, 13)) >> 13)
  70. #define BYT_RT5640_JD_NOT_INV BIT(16)
  71. #define BYT_RT5640_MONO_SPEAKER BIT(17)
  72. #define BYT_RT5640_DIFF_MIC BIT(18) /* default is single-ended */
  73. #define BYT_RT5640_SSP2_AIF2 BIT(19) /* default is using AIF1 */
  74. #define BYT_RT5640_SSP0_AIF1 BIT(20)
  75. #define BYT_RT5640_SSP0_AIF2 BIT(21)
  76. #define BYT_RT5640_MCLK_EN BIT(22)
  77. #define BYT_RT5640_MCLK_25MHZ BIT(23)
  78. #define BYTCR_INPUT_DEFAULTS \
  79. (BYT_RT5640_IN3_MAP | \
  80. BYT_RT5640_JD_SRC_JD1_IN4P | \
  81. BYT_RT5640_OVCD_TH_2000UA | \
  82. BYT_RT5640_OVCD_SF_0P75 | \
  83. BYT_RT5640_DIFF_MIC)
  84. /* in-diff or dmic-pin + jdsrc + ovcd-th + -sf + jd-inv + terminating entry */
  85. #define MAX_NO_PROPS 6
  86. struct byt_rt5640_private {
  87. struct snd_soc_jack jack;
  88. struct clk *mclk;
  89. };
  90. static bool is_bytcr;
  91. static unsigned long byt_rt5640_quirk = BYT_RT5640_MCLK_EN;
  92. static unsigned int quirk_override;
  93. module_param_named(quirk, quirk_override, uint, 0444);
  94. MODULE_PARM_DESC(quirk, "Board-specific quirk override");
  95. static void log_quirks(struct device *dev)
  96. {
  97. int map;
  98. bool has_mclk = false;
  99. bool has_ssp0 = false;
  100. bool has_ssp0_aif1 = false;
  101. bool has_ssp0_aif2 = false;
  102. bool has_ssp2_aif2 = false;
  103. map = BYT_RT5640_MAP(byt_rt5640_quirk);
  104. switch (map) {
  105. case BYT_RT5640_DMIC1_MAP:
  106. dev_info(dev, "quirk DMIC1_MAP enabled\n");
  107. break;
  108. case BYT_RT5640_DMIC2_MAP:
  109. dev_info(dev, "quirk DMIC2_MAP enabled\n");
  110. break;
  111. case BYT_RT5640_IN1_MAP:
  112. dev_info(dev, "quirk IN1_MAP enabled\n");
  113. break;
  114. case BYT_RT5640_IN3_MAP:
  115. dev_info(dev, "quirk IN3_MAP enabled\n");
  116. break;
  117. default:
  118. dev_err(dev, "quirk map 0x%x is not supported, microphone input will not work\n", map);
  119. break;
  120. }
  121. if (BYT_RT5640_JDSRC(byt_rt5640_quirk)) {
  122. dev_info(dev, "quirk realtek,jack-detect-source %ld\n",
  123. BYT_RT5640_JDSRC(byt_rt5640_quirk));
  124. dev_info(dev, "quirk realtek,over-current-threshold-microamp %ld\n",
  125. BYT_RT5640_OVCD_TH(byt_rt5640_quirk) * 100);
  126. dev_info(dev, "quirk realtek,over-current-scale-factor %ld\n",
  127. BYT_RT5640_OVCD_SF(byt_rt5640_quirk));
  128. }
  129. if (byt_rt5640_quirk & BYT_RT5640_JD_NOT_INV)
  130. dev_info(dev, "quirk JD_NOT_INV enabled\n");
  131. if (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER)
  132. dev_info(dev, "quirk MONO_SPEAKER enabled\n");
  133. if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC)
  134. dev_info(dev, "quirk DIFF_MIC enabled\n");
  135. if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) {
  136. dev_info(dev, "quirk SSP0_AIF1 enabled\n");
  137. has_ssp0 = true;
  138. has_ssp0_aif1 = true;
  139. }
  140. if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2) {
  141. dev_info(dev, "quirk SSP0_AIF2 enabled\n");
  142. has_ssp0 = true;
  143. has_ssp0_aif2 = true;
  144. }
  145. if (byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) {
  146. dev_info(dev, "quirk SSP2_AIF2 enabled\n");
  147. has_ssp2_aif2 = true;
  148. }
  149. if (is_bytcr && !has_ssp0)
  150. dev_err(dev, "Invalid routing, bytcr detected but no SSP0-based quirk, audio cannot work with SSP2 on bytcr\n");
  151. if (has_ssp0_aif1 && has_ssp0_aif2)
  152. dev_err(dev, "Invalid routing, SSP0 cannot be connected to both AIF1 and AIF2\n");
  153. if (has_ssp0 && has_ssp2_aif2)
  154. dev_err(dev, "Invalid routing, cannot have both SSP0 and SSP2 connected to codec\n");
  155. if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
  156. dev_info(dev, "quirk MCLK_EN enabled\n");
  157. has_mclk = true;
  158. }
  159. if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ) {
  160. if (has_mclk)
  161. dev_info(dev, "quirk MCLK_25MHZ enabled\n");
  162. else
  163. dev_err(dev, "quirk MCLK_25MHZ enabled but quirk MCLK not selected, will be ignored\n");
  164. }
  165. }
  166. static int byt_rt5640_prepare_and_enable_pll1(struct snd_soc_dai *codec_dai,
  167. int rate)
  168. {
  169. int ret;
  170. /* Configure the PLL before selecting it */
  171. if (!(byt_rt5640_quirk & BYT_RT5640_MCLK_EN)) {
  172. /* use bitclock as PLL input */
  173. if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) ||
  174. (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
  175. /* 2x16 bit slots on SSP0 */
  176. ret = snd_soc_dai_set_pll(codec_dai, 0,
  177. RT5640_PLL1_S_BCLK1,
  178. rate * 32, rate * 512);
  179. } else {
  180. /* 2x15 bit slots on SSP2 */
  181. ret = snd_soc_dai_set_pll(codec_dai, 0,
  182. RT5640_PLL1_S_BCLK1,
  183. rate * 50, rate * 512);
  184. }
  185. } else {
  186. if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ) {
  187. ret = snd_soc_dai_set_pll(codec_dai, 0,
  188. RT5640_PLL1_S_MCLK,
  189. 25000000, rate * 512);
  190. } else {
  191. ret = snd_soc_dai_set_pll(codec_dai, 0,
  192. RT5640_PLL1_S_MCLK,
  193. 19200000, rate * 512);
  194. }
  195. }
  196. if (ret < 0) {
  197. dev_err(codec_dai->component->dev, "can't set pll: %d\n", ret);
  198. return ret;
  199. }
  200. ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_PLL1,
  201. rate * 512, SND_SOC_CLOCK_IN);
  202. if (ret < 0) {
  203. dev_err(codec_dai->component->dev, "can't set clock %d\n", ret);
  204. return ret;
  205. }
  206. return 0;
  207. }
  208. #define BYT_CODEC_DAI1 "rt5640-aif1"
  209. #define BYT_CODEC_DAI2 "rt5640-aif2"
  210. static int platform_clock_control(struct snd_soc_dapm_widget *w,
  211. struct snd_kcontrol *k, int event)
  212. {
  213. struct snd_soc_dapm_context *dapm = w->dapm;
  214. struct snd_soc_card *card = dapm->card;
  215. struct snd_soc_dai *codec_dai;
  216. struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
  217. int ret;
  218. codec_dai = snd_soc_card_get_codec_dai(card, BYT_CODEC_DAI1);
  219. if (!codec_dai)
  220. codec_dai = snd_soc_card_get_codec_dai(card, BYT_CODEC_DAI2);
  221. if (!codec_dai) {
  222. dev_err(card->dev,
  223. "Codec dai not found; Unable to set platform clock\n");
  224. return -EIO;
  225. }
  226. if (SND_SOC_DAPM_EVENT_ON(event)) {
  227. if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
  228. ret = clk_prepare_enable(priv->mclk);
  229. if (ret < 0) {
  230. dev_err(card->dev,
  231. "could not configure MCLK state\n");
  232. return ret;
  233. }
  234. }
  235. ret = byt_rt5640_prepare_and_enable_pll1(codec_dai, 48000);
  236. } else {
  237. /*
  238. * Set codec clock source to internal clock before
  239. * turning off the platform clock. Codec needs clock
  240. * for Jack detection and button press
  241. */
  242. ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_RCCLK,
  243. 48000 * 512,
  244. SND_SOC_CLOCK_IN);
  245. if (!ret) {
  246. if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN)
  247. clk_disable_unprepare(priv->mclk);
  248. }
  249. }
  250. if (ret < 0) {
  251. dev_err(card->dev, "can't set codec sysclk: %d\n", ret);
  252. return ret;
  253. }
  254. return 0;
  255. }
  256. static const struct snd_soc_dapm_widget byt_rt5640_widgets[] = {
  257. SND_SOC_DAPM_HP("Headphone", NULL),
  258. SND_SOC_DAPM_MIC("Headset Mic", NULL),
  259. SND_SOC_DAPM_MIC("Internal Mic", NULL),
  260. SND_SOC_DAPM_SPK("Speaker", NULL),
  261. SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0,
  262. platform_clock_control, SND_SOC_DAPM_PRE_PMU |
  263. SND_SOC_DAPM_POST_PMD),
  264. };
  265. static const struct snd_soc_dapm_route byt_rt5640_audio_map[] = {
  266. {"Headphone", NULL, "Platform Clock"},
  267. {"Headset Mic", NULL, "Platform Clock"},
  268. {"Internal Mic", NULL, "Platform Clock"},
  269. {"Speaker", NULL, "Platform Clock"},
  270. {"Headset Mic", NULL, "MICBIAS1"},
  271. {"IN2P", NULL, "Headset Mic"},
  272. {"Headphone", NULL, "HPOL"},
  273. {"Headphone", NULL, "HPOR"},
  274. };
  275. static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic1_map[] = {
  276. {"DMIC1", NULL, "Internal Mic"},
  277. };
  278. static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic2_map[] = {
  279. {"DMIC2", NULL, "Internal Mic"},
  280. };
  281. static const struct snd_soc_dapm_route byt_rt5640_intmic_in1_map[] = {
  282. {"Internal Mic", NULL, "MICBIAS1"},
  283. {"IN1P", NULL, "Internal Mic"},
  284. };
  285. static const struct snd_soc_dapm_route byt_rt5640_intmic_in3_map[] = {
  286. {"Internal Mic", NULL, "MICBIAS1"},
  287. {"IN3P", NULL, "Internal Mic"},
  288. };
  289. static const struct snd_soc_dapm_route byt_rt5640_ssp2_aif1_map[] = {
  290. {"ssp2 Tx", NULL, "codec_out0"},
  291. {"ssp2 Tx", NULL, "codec_out1"},
  292. {"codec_in0", NULL, "ssp2 Rx"},
  293. {"codec_in1", NULL, "ssp2 Rx"},
  294. {"AIF1 Playback", NULL, "ssp2 Tx"},
  295. {"ssp2 Rx", NULL, "AIF1 Capture"},
  296. };
  297. static const struct snd_soc_dapm_route byt_rt5640_ssp2_aif2_map[] = {
  298. {"ssp2 Tx", NULL, "codec_out0"},
  299. {"ssp2 Tx", NULL, "codec_out1"},
  300. {"codec_in0", NULL, "ssp2 Rx"},
  301. {"codec_in1", NULL, "ssp2 Rx"},
  302. {"AIF2 Playback", NULL, "ssp2 Tx"},
  303. {"ssp2 Rx", NULL, "AIF2 Capture"},
  304. };
  305. static const struct snd_soc_dapm_route byt_rt5640_ssp0_aif1_map[] = {
  306. {"ssp0 Tx", NULL, "modem_out"},
  307. {"modem_in", NULL, "ssp0 Rx"},
  308. {"AIF1 Playback", NULL, "ssp0 Tx"},
  309. {"ssp0 Rx", NULL, "AIF1 Capture"},
  310. };
  311. static const struct snd_soc_dapm_route byt_rt5640_ssp0_aif2_map[] = {
  312. {"ssp0 Tx", NULL, "modem_out"},
  313. {"modem_in", NULL, "ssp0 Rx"},
  314. {"AIF2 Playback", NULL, "ssp0 Tx"},
  315. {"ssp0 Rx", NULL, "AIF2 Capture"},
  316. };
  317. static const struct snd_soc_dapm_route byt_rt5640_stereo_spk_map[] = {
  318. {"Speaker", NULL, "SPOLP"},
  319. {"Speaker", NULL, "SPOLN"},
  320. {"Speaker", NULL, "SPORP"},
  321. {"Speaker", NULL, "SPORN"},
  322. };
  323. static const struct snd_soc_dapm_route byt_rt5640_mono_spk_map[] = {
  324. {"Speaker", NULL, "SPOLP"},
  325. {"Speaker", NULL, "SPOLN"},
  326. };
  327. static const struct snd_kcontrol_new byt_rt5640_controls[] = {
  328. SOC_DAPM_PIN_SWITCH("Headphone"),
  329. SOC_DAPM_PIN_SWITCH("Headset Mic"),
  330. SOC_DAPM_PIN_SWITCH("Internal Mic"),
  331. SOC_DAPM_PIN_SWITCH("Speaker"),
  332. };
  333. static struct snd_soc_jack_pin rt5640_pins[] = {
  334. {
  335. .pin = "Headphone",
  336. .mask = SND_JACK_HEADPHONE,
  337. },
  338. {
  339. .pin = "Headset Mic",
  340. .mask = SND_JACK_MICROPHONE,
  341. },
  342. };
  343. static int byt_rt5640_aif1_hw_params(struct snd_pcm_substream *substream,
  344. struct snd_pcm_hw_params *params)
  345. {
  346. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  347. struct snd_soc_dai *dai = rtd->codec_dai;
  348. return byt_rt5640_prepare_and_enable_pll1(dai, params_rate(params));
  349. }
  350. /* Please keep this list alphabetically sorted */
  351. static const struct dmi_system_id byt_rt5640_quirk_table[] = {
  352. { /* Acer Iconia Tab 8 W1-810 */
  353. .matches = {
  354. DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Acer"),
  355. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Iconia W1-810"),
  356. },
  357. .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
  358. BYT_RT5640_JD_SRC_JD1_IN4P |
  359. BYT_RT5640_OVCD_TH_1500UA |
  360. BYT_RT5640_OVCD_SF_0P75 |
  361. BYT_RT5640_SSP0_AIF1 |
  362. BYT_RT5640_MCLK_EN),
  363. },
  364. { /* Acer One 10 S1002 */
  365. .matches = {
  366. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  367. DMI_MATCH(DMI_PRODUCT_NAME, "One S1002"),
  368. },
  369. .driver_data = (void *)(BYT_RT5640_IN1_MAP |
  370. BYT_RT5640_JD_SRC_JD2_IN4N |
  371. BYT_RT5640_OVCD_TH_2000UA |
  372. BYT_RT5640_OVCD_SF_0P75 |
  373. BYT_RT5640_DIFF_MIC |
  374. BYT_RT5640_SSP0_AIF2 |
  375. BYT_RT5640_MCLK_EN),
  376. },
  377. {
  378. .matches = {
  379. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  380. DMI_MATCH(DMI_PRODUCT_NAME, "Aspire SW5-012"),
  381. },
  382. .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
  383. BYT_RT5640_JD_SRC_JD2_IN4N |
  384. BYT_RT5640_OVCD_TH_2000UA |
  385. BYT_RT5640_OVCD_SF_0P75 |
  386. BYT_RT5640_SSP0_AIF1 |
  387. BYT_RT5640_MCLK_EN),
  388. },
  389. {
  390. .matches = {
  391. DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ARCHOS"),
  392. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "ARCHOS 80 Cesium"),
  393. },
  394. .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
  395. BYT_RT5640_MONO_SPEAKER |
  396. BYT_RT5640_SSP0_AIF1 |
  397. BYT_RT5640_MCLK_EN),
  398. },
  399. {
  400. .matches = {
  401. DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ARCHOS"),
  402. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "ARCHOS 140 CESIUM"),
  403. },
  404. .driver_data = (void *)(BYT_RT5640_IN1_MAP |
  405. BYT_RT5640_JD_SRC_JD2_IN4N |
  406. BYT_RT5640_OVCD_TH_2000UA |
  407. BYT_RT5640_OVCD_SF_0P75 |
  408. BYT_RT5640_SSP0_AIF1 |
  409. BYT_RT5640_MCLK_EN),
  410. },
  411. {
  412. .matches = {
  413. DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
  414. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TA"),
  415. },
  416. .driver_data = (void *)(BYT_RT5640_IN1_MAP |
  417. BYT_RT5640_JD_SRC_JD2_IN4N |
  418. BYT_RT5640_OVCD_TH_2000UA |
  419. BYT_RT5640_OVCD_SF_0P75 |
  420. BYT_RT5640_MCLK_EN),
  421. },
  422. {
  423. .matches = {
  424. DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
  425. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TAF"),
  426. },
  427. .driver_data = (void *)(BYT_RT5640_IN1_MAP |
  428. BYT_RT5640_JD_SRC_JD2_IN4N |
  429. BYT_RT5640_OVCD_TH_2000UA |
  430. BYT_RT5640_OVCD_SF_0P75 |
  431. BYT_RT5640_MONO_SPEAKER |
  432. BYT_RT5640_DIFF_MIC |
  433. BYT_RT5640_SSP0_AIF2 |
  434. BYT_RT5640_MCLK_EN),
  435. },
  436. { /* Chuwi Vi8 (CWI506) */
  437. .matches = {
  438. DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Insyde"),
  439. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "i86"),
  440. /* The above are too generic, also match BIOS info */
  441. DMI_MATCH(DMI_BIOS_VERSION, "CHUWI.D86JLBNR"),
  442. },
  443. .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
  444. BYT_RT5640_MONO_SPEAKER |
  445. BYT_RT5640_SSP0_AIF1 |
  446. BYT_RT5640_MCLK_EN),
  447. },
  448. {
  449. /* Chuwi Vi10 (CWI505) */
  450. .matches = {
  451. DMI_MATCH(DMI_BOARD_VENDOR, "Hampoo"),
  452. DMI_MATCH(DMI_BOARD_NAME, "BYT-PF02"),
  453. DMI_MATCH(DMI_SYS_VENDOR, "ilife"),
  454. DMI_MATCH(DMI_PRODUCT_NAME, "S165"),
  455. },
  456. .driver_data = (void *)(BYT_RT5640_IN1_MAP |
  457. BYT_RT5640_JD_SRC_JD2_IN4N |
  458. BYT_RT5640_OVCD_TH_2000UA |
  459. BYT_RT5640_OVCD_SF_0P75 |
  460. BYT_RT5640_DIFF_MIC |
  461. BYT_RT5640_SSP0_AIF1 |
  462. BYT_RT5640_MCLK_EN),
  463. },
  464. {
  465. /* Chuwi Hi8 (CWI509) */
  466. .matches = {
  467. DMI_MATCH(DMI_BOARD_VENDOR, "Hampoo"),
  468. DMI_MATCH(DMI_BOARD_NAME, "BYT-PA03C"),
  469. DMI_MATCH(DMI_SYS_VENDOR, "ilife"),
  470. DMI_MATCH(DMI_PRODUCT_NAME, "S806"),
  471. },
  472. .driver_data = (void *)(BYT_RT5640_IN1_MAP |
  473. BYT_RT5640_JD_SRC_JD2_IN4N |
  474. BYT_RT5640_OVCD_TH_2000UA |
  475. BYT_RT5640_OVCD_SF_0P75 |
  476. BYT_RT5640_MONO_SPEAKER |
  477. BYT_RT5640_DIFF_MIC |
  478. BYT_RT5640_SSP0_AIF1 |
  479. BYT_RT5640_MCLK_EN),
  480. },
  481. {
  482. .matches = {
  483. DMI_MATCH(DMI_SYS_VENDOR, "Circuitco"),
  484. DMI_MATCH(DMI_PRODUCT_NAME, "Minnowboard Max B3 PLATFORM"),
  485. },
  486. .driver_data = (void *)(BYT_RT5640_DMIC1_MAP),
  487. },
  488. { /* Connect Tablet 9 */
  489. .matches = {
  490. DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Connect"),
  491. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Tablet 9"),
  492. },
  493. .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
  494. BYT_RT5640_MONO_SPEAKER |
  495. BYT_RT5640_SSP0_AIF1 |
  496. BYT_RT5640_MCLK_EN),
  497. },
  498. {
  499. .matches = {
  500. DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  501. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Venue 8 Pro 5830"),
  502. },
  503. .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
  504. BYT_RT5640_JD_SRC_JD2_IN4N |
  505. BYT_RT5640_OVCD_TH_2000UA |
  506. BYT_RT5640_OVCD_SF_0P75 |
  507. BYT_RT5640_MONO_SPEAKER |
  508. BYT_RT5640_MCLK_EN),
  509. },
  510. { /* Estar Beauty HD MID 7316R */
  511. .matches = {
  512. DMI_MATCH(DMI_SYS_VENDOR, "Estar"),
  513. DMI_MATCH(DMI_PRODUCT_NAME, "eSTAR BEAUTY HD Intel Quad core"),
  514. },
  515. .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
  516. BYT_RT5640_MONO_SPEAKER |
  517. BYT_RT5640_SSP0_AIF1 |
  518. BYT_RT5640_MCLK_EN),
  519. },
  520. {
  521. .matches = {
  522. DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  523. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HP ElitePad 1000 G2"),
  524. },
  525. .driver_data = (void *)(BYT_RT5640_IN1_MAP |
  526. BYT_RT5640_MCLK_EN),
  527. },
  528. { /* HP Pavilion x2 10-n000nd */
  529. .matches = {
  530. DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  531. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HP Pavilion x2 Detachable"),
  532. },
  533. .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
  534. BYT_RT5640_JD_SRC_JD2_IN4N |
  535. BYT_RT5640_OVCD_TH_1500UA |
  536. BYT_RT5640_OVCD_SF_0P75 |
  537. BYT_RT5640_SSP0_AIF1 |
  538. BYT_RT5640_MCLK_EN),
  539. },
  540. { /* HP Stream 7 */
  541. .matches = {
  542. DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  543. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HP Stream 7 Tablet"),
  544. },
  545. .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
  546. BYT_RT5640_MONO_SPEAKER |
  547. BYT_RT5640_JD_NOT_INV |
  548. BYT_RT5640_SSP0_AIF1 |
  549. BYT_RT5640_MCLK_EN),
  550. },
  551. { /* I.T.Works TW891 */
  552. .matches = {
  553. DMI_EXACT_MATCH(DMI_SYS_VENDOR, "To be filled by O.E.M."),
  554. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TW891"),
  555. DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "To be filled by O.E.M."),
  556. DMI_EXACT_MATCH(DMI_BOARD_NAME, "TW891"),
  557. },
  558. .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
  559. BYT_RT5640_MONO_SPEAKER |
  560. BYT_RT5640_SSP0_AIF1 |
  561. BYT_RT5640_MCLK_EN),
  562. },
  563. { /* Lamina I8270 / T701BR.SE */
  564. .matches = {
  565. DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "Lamina"),
  566. DMI_EXACT_MATCH(DMI_BOARD_NAME, "T701BR.SE"),
  567. },
  568. .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
  569. BYT_RT5640_MONO_SPEAKER |
  570. BYT_RT5640_JD_NOT_INV |
  571. BYT_RT5640_SSP0_AIF1 |
  572. BYT_RT5640_MCLK_EN),
  573. },
  574. { /* Lenovo Miix 2 8 */
  575. .matches = {
  576. DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LENOVO"),
  577. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "20326"),
  578. DMI_EXACT_MATCH(DMI_BOARD_NAME, "Hiking"),
  579. },
  580. .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
  581. BYT_RT5640_JD_SRC_JD2_IN4N |
  582. BYT_RT5640_OVCD_TH_2000UA |
  583. BYT_RT5640_OVCD_SF_0P75 |
  584. BYT_RT5640_MONO_SPEAKER |
  585. BYT_RT5640_MCLK_EN),
  586. },
  587. { /* Linx Linx7 tablet */
  588. .matches = {
  589. DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LINX"),
  590. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "LINX7"),
  591. },
  592. .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
  593. BYT_RT5640_MONO_SPEAKER |
  594. BYT_RT5640_JD_NOT_INV |
  595. BYT_RT5640_SSP0_AIF1 |
  596. BYT_RT5640_MCLK_EN),
  597. },
  598. { /* MPMAN Converter 9, similar hw as the I.T.Works TW891 2-in-1 */
  599. .matches = {
  600. DMI_MATCH(DMI_SYS_VENDOR, "MPMAN"),
  601. DMI_MATCH(DMI_PRODUCT_NAME, "Converter9"),
  602. },
  603. .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
  604. BYT_RT5640_MONO_SPEAKER |
  605. BYT_RT5640_SSP0_AIF1 |
  606. BYT_RT5640_MCLK_EN),
  607. },
  608. {
  609. /* MPMAN MPWIN895CL */
  610. .matches = {
  611. DMI_EXACT_MATCH(DMI_SYS_VENDOR, "MPMAN"),
  612. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "MPWIN8900CL"),
  613. },
  614. .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
  615. BYT_RT5640_MONO_SPEAKER |
  616. BYT_RT5640_SSP0_AIF1 |
  617. BYT_RT5640_MCLK_EN),
  618. },
  619. { /* MSI S100 tablet */
  620. .matches = {
  621. DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Micro-Star International Co., Ltd."),
  622. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "S100"),
  623. },
  624. .driver_data = (void *)(BYT_RT5640_IN1_MAP |
  625. BYT_RT5640_JD_SRC_JD2_IN4N |
  626. BYT_RT5640_OVCD_TH_2000UA |
  627. BYT_RT5640_OVCD_SF_0P75 |
  628. BYT_RT5640_MONO_SPEAKER |
  629. BYT_RT5640_DIFF_MIC |
  630. BYT_RT5640_MCLK_EN),
  631. },
  632. { /* Nuvison/TMax TM800W560 */
  633. .matches = {
  634. DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TMAX"),
  635. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TM800W560L"),
  636. },
  637. .driver_data = (void *)(BYT_RT5640_IN1_MAP |
  638. BYT_RT5640_JD_SRC_JD2_IN4N |
  639. BYT_RT5640_OVCD_TH_2000UA |
  640. BYT_RT5640_OVCD_SF_0P75 |
  641. BYT_RT5640_JD_NOT_INV |
  642. BYT_RT5640_DIFF_MIC |
  643. BYT_RT5640_SSP0_AIF1 |
  644. BYT_RT5640_MCLK_EN),
  645. },
  646. { /* Onda v975w */
  647. .matches = {
  648. DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
  649. DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
  650. /* The above are too generic, also match BIOS info */
  651. DMI_EXACT_MATCH(DMI_BIOS_VERSION, "5.6.5"),
  652. DMI_EXACT_MATCH(DMI_BIOS_DATE, "07/25/2014"),
  653. },
  654. .driver_data = (void *)(BYT_RT5640_IN1_MAP |
  655. BYT_RT5640_JD_SRC_JD2_IN4N |
  656. BYT_RT5640_OVCD_TH_2000UA |
  657. BYT_RT5640_OVCD_SF_0P75 |
  658. BYT_RT5640_DIFF_MIC |
  659. BYT_RT5640_MCLK_EN),
  660. },
  661. { /* Pipo W4 */
  662. .matches = {
  663. DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
  664. DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
  665. /* The above are too generic, also match BIOS info */
  666. DMI_MATCH(DMI_BIOS_VERSION, "V8L_WIN32_CHIPHD"),
  667. },
  668. .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
  669. BYT_RT5640_MONO_SPEAKER |
  670. BYT_RT5640_SSP0_AIF1 |
  671. BYT_RT5640_MCLK_EN),
  672. },
  673. { /* Point of View Mobii TAB-P800W (V2.0) */
  674. .matches = {
  675. DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
  676. DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
  677. /* The above are too generic, also match BIOS info */
  678. DMI_EXACT_MATCH(DMI_BIOS_VERSION, "3BAIR1014"),
  679. DMI_EXACT_MATCH(DMI_BIOS_DATE, "10/24/2014"),
  680. },
  681. .driver_data = (void *)(BYT_RT5640_IN1_MAP |
  682. BYT_RT5640_JD_SRC_JD2_IN4N |
  683. BYT_RT5640_OVCD_TH_2000UA |
  684. BYT_RT5640_OVCD_SF_0P75 |
  685. BYT_RT5640_MONO_SPEAKER |
  686. BYT_RT5640_DIFF_MIC |
  687. BYT_RT5640_SSP0_AIF2 |
  688. BYT_RT5640_MCLK_EN),
  689. },
  690. { /* Point of View Mobii TAB-P800W (V2.1) */
  691. .matches = {
  692. DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
  693. DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
  694. /* The above are too generic, also match BIOS info */
  695. DMI_EXACT_MATCH(DMI_BIOS_VERSION, "3BAIR1013"),
  696. DMI_EXACT_MATCH(DMI_BIOS_DATE, "08/22/2014"),
  697. },
  698. .driver_data = (void *)(BYT_RT5640_IN1_MAP |
  699. BYT_RT5640_JD_SRC_JD2_IN4N |
  700. BYT_RT5640_OVCD_TH_2000UA |
  701. BYT_RT5640_OVCD_SF_0P75 |
  702. BYT_RT5640_MONO_SPEAKER |
  703. BYT_RT5640_DIFF_MIC |
  704. BYT_RT5640_SSP0_AIF2 |
  705. BYT_RT5640_MCLK_EN),
  706. },
  707. {
  708. /* Teclast X89 */
  709. .matches = {
  710. DMI_MATCH(DMI_BOARD_VENDOR, "TECLAST"),
  711. DMI_MATCH(DMI_BOARD_NAME, "tPAD"),
  712. },
  713. .driver_data = (void *)(BYT_RT5640_IN3_MAP |
  714. BYT_RT5640_JD_SRC_JD1_IN4P |
  715. BYT_RT5640_OVCD_TH_2000UA |
  716. BYT_RT5640_OVCD_SF_1P0 |
  717. BYT_RT5640_SSP0_AIF1 |
  718. BYT_RT5640_MCLK_EN),
  719. },
  720. { /* Toshiba Satellite Click Mini L9W-B */
  721. .matches = {
  722. DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  723. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "SATELLITE Click Mini L9W-B"),
  724. },
  725. .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
  726. BYT_RT5640_JD_SRC_JD2_IN4N |
  727. BYT_RT5640_OVCD_TH_1500UA |
  728. BYT_RT5640_OVCD_SF_0P75 |
  729. BYT_RT5640_SSP0_AIF1 |
  730. BYT_RT5640_MCLK_EN),
  731. },
  732. { /* Toshiba Encore WT8-A */
  733. .matches = {
  734. DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  735. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TOSHIBA WT8-A"),
  736. },
  737. .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
  738. BYT_RT5640_JD_SRC_JD2_IN4N |
  739. BYT_RT5640_OVCD_TH_2000UA |
  740. BYT_RT5640_OVCD_SF_0P75 |
  741. BYT_RT5640_JD_NOT_INV |
  742. BYT_RT5640_MCLK_EN),
  743. },
  744. { /* Toshiba Encore WT10-A */
  745. .matches = {
  746. DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  747. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TOSHIBA WT10-A-103"),
  748. },
  749. .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
  750. BYT_RT5640_JD_SRC_JD1_IN4P |
  751. BYT_RT5640_OVCD_TH_2000UA |
  752. BYT_RT5640_OVCD_SF_0P75 |
  753. BYT_RT5640_SSP0_AIF2 |
  754. BYT_RT5640_MCLK_EN),
  755. },
  756. { /* Voyo Winpad A15 */
  757. .matches = {
  758. DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
  759. DMI_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
  760. /* Above strings are too generic, also match on BIOS date */
  761. DMI_MATCH(DMI_BIOS_DATE, "11/20/2014"),
  762. },
  763. .driver_data = (void *)(BYT_RT5640_IN1_MAP |
  764. BYT_RT5640_JD_SRC_JD2_IN4N |
  765. BYT_RT5640_OVCD_TH_2000UA |
  766. BYT_RT5640_OVCD_SF_0P75 |
  767. BYT_RT5640_DIFF_MIC |
  768. BYT_RT5640_MCLK_EN),
  769. },
  770. { /* Catch-all for generic Insyde tablets, must be last */
  771. .matches = {
  772. DMI_MATCH(DMI_SYS_VENDOR, "Insyde"),
  773. },
  774. .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
  775. BYT_RT5640_MCLK_EN |
  776. BYT_RT5640_SSP0_AIF1),
  777. },
  778. {}
  779. };
  780. /*
  781. * Note this MUST be called before snd_soc_register_card(), so that the props
  782. * are in place before the codec component driver's probe function parses them.
  783. */
  784. static int byt_rt5640_add_codec_device_props(const char *i2c_dev_name)
  785. {
  786. struct property_entry props[MAX_NO_PROPS] = {};
  787. struct device *i2c_dev;
  788. int ret, cnt = 0;
  789. i2c_dev = bus_find_device_by_name(&i2c_bus_type, NULL, i2c_dev_name);
  790. if (!i2c_dev)
  791. return -EPROBE_DEFER;
  792. switch (BYT_RT5640_MAP(byt_rt5640_quirk)) {
  793. case BYT_RT5640_DMIC1_MAP:
  794. props[cnt++] = PROPERTY_ENTRY_U32("realtek,dmic1-data-pin",
  795. RT5640_DMIC1_DATA_PIN_IN1P);
  796. break;
  797. case BYT_RT5640_DMIC2_MAP:
  798. props[cnt++] = PROPERTY_ENTRY_U32("realtek,dmic2-data-pin",
  799. RT5640_DMIC2_DATA_PIN_IN1N);
  800. break;
  801. case BYT_RT5640_IN1_MAP:
  802. if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC)
  803. props[cnt++] =
  804. PROPERTY_ENTRY_BOOL("realtek,in1-differential");
  805. break;
  806. case BYT_RT5640_IN3_MAP:
  807. if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC)
  808. props[cnt++] =
  809. PROPERTY_ENTRY_BOOL("realtek,in3-differential");
  810. break;
  811. }
  812. if (BYT_RT5640_JDSRC(byt_rt5640_quirk)) {
  813. props[cnt++] = PROPERTY_ENTRY_U32(
  814. "realtek,jack-detect-source",
  815. BYT_RT5640_JDSRC(byt_rt5640_quirk));
  816. props[cnt++] = PROPERTY_ENTRY_U32(
  817. "realtek,over-current-threshold-microamp",
  818. BYT_RT5640_OVCD_TH(byt_rt5640_quirk) * 100);
  819. props[cnt++] = PROPERTY_ENTRY_U32(
  820. "realtek,over-current-scale-factor",
  821. BYT_RT5640_OVCD_SF(byt_rt5640_quirk));
  822. }
  823. if (byt_rt5640_quirk & BYT_RT5640_JD_NOT_INV)
  824. props[cnt++] = PROPERTY_ENTRY_BOOL("realtek,jack-detect-not-inverted");
  825. ret = device_add_properties(i2c_dev, props);
  826. put_device(i2c_dev);
  827. return ret;
  828. }
  829. static int byt_rt5640_init(struct snd_soc_pcm_runtime *runtime)
  830. {
  831. struct snd_soc_card *card = runtime->card;
  832. struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
  833. struct snd_soc_component *component = runtime->codec_dai->component;
  834. const struct snd_soc_dapm_route *custom_map;
  835. int num_routes;
  836. int ret;
  837. card->dapm.idle_bias_off = true;
  838. /* Start with RC clk for jack-detect (we disable MCLK below) */
  839. if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN)
  840. snd_soc_component_update_bits(component, RT5640_GLB_CLK,
  841. RT5640_SCLK_SRC_MASK, RT5640_SCLK_SRC_RCCLK);
  842. rt5640_sel_asrc_clk_src(component,
  843. RT5640_DA_STEREO_FILTER |
  844. RT5640_DA_MONO_L_FILTER |
  845. RT5640_DA_MONO_R_FILTER |
  846. RT5640_AD_STEREO_FILTER |
  847. RT5640_AD_MONO_L_FILTER |
  848. RT5640_AD_MONO_R_FILTER,
  849. RT5640_CLK_SEL_ASRC);
  850. ret = snd_soc_add_card_controls(card, byt_rt5640_controls,
  851. ARRAY_SIZE(byt_rt5640_controls));
  852. if (ret) {
  853. dev_err(card->dev, "unable to add card controls\n");
  854. return ret;
  855. }
  856. switch (BYT_RT5640_MAP(byt_rt5640_quirk)) {
  857. case BYT_RT5640_IN1_MAP:
  858. custom_map = byt_rt5640_intmic_in1_map;
  859. num_routes = ARRAY_SIZE(byt_rt5640_intmic_in1_map);
  860. break;
  861. case BYT_RT5640_IN3_MAP:
  862. custom_map = byt_rt5640_intmic_in3_map;
  863. num_routes = ARRAY_SIZE(byt_rt5640_intmic_in3_map);
  864. break;
  865. case BYT_RT5640_DMIC2_MAP:
  866. custom_map = byt_rt5640_intmic_dmic2_map;
  867. num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic2_map);
  868. break;
  869. default:
  870. custom_map = byt_rt5640_intmic_dmic1_map;
  871. num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic1_map);
  872. }
  873. ret = snd_soc_dapm_add_routes(&card->dapm, custom_map, num_routes);
  874. if (ret)
  875. return ret;
  876. if (byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) {
  877. ret = snd_soc_dapm_add_routes(&card->dapm,
  878. byt_rt5640_ssp2_aif2_map,
  879. ARRAY_SIZE(byt_rt5640_ssp2_aif2_map));
  880. } else if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) {
  881. ret = snd_soc_dapm_add_routes(&card->dapm,
  882. byt_rt5640_ssp0_aif1_map,
  883. ARRAY_SIZE(byt_rt5640_ssp0_aif1_map));
  884. } else if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2) {
  885. ret = snd_soc_dapm_add_routes(&card->dapm,
  886. byt_rt5640_ssp0_aif2_map,
  887. ARRAY_SIZE(byt_rt5640_ssp0_aif2_map));
  888. } else {
  889. ret = snd_soc_dapm_add_routes(&card->dapm,
  890. byt_rt5640_ssp2_aif1_map,
  891. ARRAY_SIZE(byt_rt5640_ssp2_aif1_map));
  892. }
  893. if (ret)
  894. return ret;
  895. if (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER) {
  896. ret = snd_soc_dapm_add_routes(&card->dapm,
  897. byt_rt5640_mono_spk_map,
  898. ARRAY_SIZE(byt_rt5640_mono_spk_map));
  899. } else {
  900. ret = snd_soc_dapm_add_routes(&card->dapm,
  901. byt_rt5640_stereo_spk_map,
  902. ARRAY_SIZE(byt_rt5640_stereo_spk_map));
  903. }
  904. if (ret)
  905. return ret;
  906. snd_soc_dapm_ignore_suspend(&card->dapm, "Headphone");
  907. snd_soc_dapm_ignore_suspend(&card->dapm, "Speaker");
  908. if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
  909. /*
  910. * The firmware might enable the clock at
  911. * boot (this information may or may not
  912. * be reflected in the enable clock register).
  913. * To change the rate we must disable the clock
  914. * first to cover these cases. Due to common
  915. * clock framework restrictions that do not allow
  916. * to disable a clock that has not been enabled,
  917. * we need to enable the clock first.
  918. */
  919. ret = clk_prepare_enable(priv->mclk);
  920. if (!ret)
  921. clk_disable_unprepare(priv->mclk);
  922. if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ)
  923. ret = clk_set_rate(priv->mclk, 25000000);
  924. else
  925. ret = clk_set_rate(priv->mclk, 19200000);
  926. if (ret) {
  927. dev_err(card->dev, "unable to set MCLK rate\n");
  928. return ret;
  929. }
  930. }
  931. if (BYT_RT5640_JDSRC(byt_rt5640_quirk)) {
  932. ret = snd_soc_card_jack_new(card, "Headset",
  933. SND_JACK_HEADSET | SND_JACK_BTN_0,
  934. &priv->jack, rt5640_pins,
  935. ARRAY_SIZE(rt5640_pins));
  936. if (ret) {
  937. dev_err(card->dev, "Jack creation failed %d\n", ret);
  938. return ret;
  939. }
  940. snd_jack_set_key(priv->jack.jack, SND_JACK_BTN_0,
  941. KEY_PLAYPAUSE);
  942. snd_soc_component_set_jack(component, &priv->jack, NULL);
  943. }
  944. return 0;
  945. }
  946. static const struct snd_soc_pcm_stream byt_rt5640_dai_params = {
  947. .formats = SNDRV_PCM_FMTBIT_S24_LE,
  948. .rate_min = 48000,
  949. .rate_max = 48000,
  950. .channels_min = 2,
  951. .channels_max = 2,
  952. };
  953. static int byt_rt5640_codec_fixup(struct snd_soc_pcm_runtime *rtd,
  954. struct snd_pcm_hw_params *params)
  955. {
  956. struct snd_interval *rate = hw_param_interval(params,
  957. SNDRV_PCM_HW_PARAM_RATE);
  958. struct snd_interval *channels = hw_param_interval(params,
  959. SNDRV_PCM_HW_PARAM_CHANNELS);
  960. int ret;
  961. /* The DSP will covert the FE rate to 48k, stereo */
  962. rate->min = rate->max = 48000;
  963. channels->min = channels->max = 2;
  964. if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) ||
  965. (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
  966. /* set SSP0 to 16-bit */
  967. params_set_format(params, SNDRV_PCM_FORMAT_S16_LE);
  968. /*
  969. * Default mode for SSP configuration is TDM 4 slot, override config
  970. * with explicit setting to I2S 2ch 16-bit. The word length is set with
  971. * dai_set_tdm_slot() since there is no other API exposed
  972. */
  973. ret = snd_soc_dai_set_fmt(rtd->cpu_dai,
  974. SND_SOC_DAIFMT_I2S |
  975. SND_SOC_DAIFMT_NB_NF |
  976. SND_SOC_DAIFMT_CBS_CFS
  977. );
  978. if (ret < 0) {
  979. dev_err(rtd->dev, "can't set format to I2S, err %d\n", ret);
  980. return ret;
  981. }
  982. ret = snd_soc_dai_set_tdm_slot(rtd->cpu_dai, 0x3, 0x3, 2, 16);
  983. if (ret < 0) {
  984. dev_err(rtd->dev, "can't set I2S config, err %d\n", ret);
  985. return ret;
  986. }
  987. } else {
  988. /* set SSP2 to 24-bit */
  989. params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);
  990. /*
  991. * Default mode for SSP configuration is TDM 4 slot, override config
  992. * with explicit setting to I2S 2ch 24-bit. The word length is set with
  993. * dai_set_tdm_slot() since there is no other API exposed
  994. */
  995. ret = snd_soc_dai_set_fmt(rtd->cpu_dai,
  996. SND_SOC_DAIFMT_I2S |
  997. SND_SOC_DAIFMT_NB_NF |
  998. SND_SOC_DAIFMT_CBS_CFS
  999. );
  1000. if (ret < 0) {
  1001. dev_err(rtd->dev, "can't set format to I2S, err %d\n", ret);
  1002. return ret;
  1003. }
  1004. ret = snd_soc_dai_set_tdm_slot(rtd->cpu_dai, 0x3, 0x3, 2, 24);
  1005. if (ret < 0) {
  1006. dev_err(rtd->dev, "can't set I2S config, err %d\n", ret);
  1007. return ret;
  1008. }
  1009. }
  1010. return 0;
  1011. }
  1012. static int byt_rt5640_aif1_startup(struct snd_pcm_substream *substream)
  1013. {
  1014. return snd_pcm_hw_constraint_single(substream->runtime,
  1015. SNDRV_PCM_HW_PARAM_RATE, 48000);
  1016. }
  1017. static const struct snd_soc_ops byt_rt5640_aif1_ops = {
  1018. .startup = byt_rt5640_aif1_startup,
  1019. };
  1020. static const struct snd_soc_ops byt_rt5640_be_ssp2_ops = {
  1021. .hw_params = byt_rt5640_aif1_hw_params,
  1022. };
  1023. static struct snd_soc_dai_link byt_rt5640_dais[] = {
  1024. [MERR_DPCM_AUDIO] = {
  1025. .name = "Baytrail Audio Port",
  1026. .stream_name = "Baytrail Audio",
  1027. .cpu_dai_name = "media-cpu-dai",
  1028. .codec_dai_name = "snd-soc-dummy-dai",
  1029. .codec_name = "snd-soc-dummy",
  1030. .platform_name = "sst-mfld-platform",
  1031. .nonatomic = true,
  1032. .dynamic = 1,
  1033. .dpcm_playback = 1,
  1034. .dpcm_capture = 1,
  1035. .ops = &byt_rt5640_aif1_ops,
  1036. },
  1037. [MERR_DPCM_DEEP_BUFFER] = {
  1038. .name = "Deep-Buffer Audio Port",
  1039. .stream_name = "Deep-Buffer Audio",
  1040. .cpu_dai_name = "deepbuffer-cpu-dai",
  1041. .codec_dai_name = "snd-soc-dummy-dai",
  1042. .codec_name = "snd-soc-dummy",
  1043. .platform_name = "sst-mfld-platform",
  1044. .nonatomic = true,
  1045. .dynamic = 1,
  1046. .dpcm_playback = 1,
  1047. .ops = &byt_rt5640_aif1_ops,
  1048. },
  1049. /* back ends */
  1050. {
  1051. .name = "SSP2-Codec",
  1052. .id = 0,
  1053. .cpu_dai_name = "ssp2-port", /* overwritten for ssp0 routing */
  1054. .platform_name = "sst-mfld-platform",
  1055. .no_pcm = 1,
  1056. .codec_dai_name = "rt5640-aif1", /* changed w/ quirk */
  1057. .codec_name = "i2c-10EC5640:00", /* overwritten with HID */
  1058. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
  1059. | SND_SOC_DAIFMT_CBS_CFS,
  1060. .be_hw_params_fixup = byt_rt5640_codec_fixup,
  1061. .ignore_suspend = 1,
  1062. .nonatomic = true,
  1063. .dpcm_playback = 1,
  1064. .dpcm_capture = 1,
  1065. .init = byt_rt5640_init,
  1066. .ops = &byt_rt5640_be_ssp2_ops,
  1067. },
  1068. };
  1069. /* SoC card */
  1070. static char byt_rt5640_codec_name[SND_ACPI_I2C_ID_LEN];
  1071. static char byt_rt5640_codec_aif_name[12]; /* = "rt5640-aif[1|2]" */
  1072. static char byt_rt5640_cpu_dai_name[10]; /* = "ssp[0|2]-port" */
  1073. static char byt_rt5640_long_name[40]; /* = "bytcr-rt5640-*-spk-*-mic" */
  1074. static int byt_rt5640_suspend(struct snd_soc_card *card)
  1075. {
  1076. struct snd_soc_component *component;
  1077. if (!BYT_RT5640_JDSRC(byt_rt5640_quirk))
  1078. return 0;
  1079. list_for_each_entry(component, &card->component_dev_list, card_list) {
  1080. if (!strcmp(component->name, byt_rt5640_codec_name)) {
  1081. dev_dbg(component->dev, "disabling jack detect before suspend\n");
  1082. snd_soc_component_set_jack(component, NULL, NULL);
  1083. break;
  1084. }
  1085. }
  1086. return 0;
  1087. }
  1088. static int byt_rt5640_resume(struct snd_soc_card *card)
  1089. {
  1090. struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
  1091. struct snd_soc_component *component;
  1092. if (!BYT_RT5640_JDSRC(byt_rt5640_quirk))
  1093. return 0;
  1094. list_for_each_entry(component, &card->component_dev_list, card_list) {
  1095. if (!strcmp(component->name, byt_rt5640_codec_name)) {
  1096. dev_dbg(component->dev, "re-enabling jack detect after resume\n");
  1097. snd_soc_component_set_jack(component, &priv->jack, NULL);
  1098. break;
  1099. }
  1100. }
  1101. return 0;
  1102. }
  1103. static struct snd_soc_card byt_rt5640_card = {
  1104. .name = "bytcr-rt5640",
  1105. .owner = THIS_MODULE,
  1106. .dai_link = byt_rt5640_dais,
  1107. .num_links = ARRAY_SIZE(byt_rt5640_dais),
  1108. .dapm_widgets = byt_rt5640_widgets,
  1109. .num_dapm_widgets = ARRAY_SIZE(byt_rt5640_widgets),
  1110. .dapm_routes = byt_rt5640_audio_map,
  1111. .num_dapm_routes = ARRAY_SIZE(byt_rt5640_audio_map),
  1112. .fully_routed = true,
  1113. .suspend_pre = byt_rt5640_suspend,
  1114. .resume_post = byt_rt5640_resume,
  1115. };
  1116. static bool is_valleyview(void)
  1117. {
  1118. static const struct x86_cpu_id cpu_ids[] = {
  1119. { X86_VENDOR_INTEL, 6, 55 }, /* Valleyview, Bay Trail */
  1120. {}
  1121. };
  1122. if (!x86_match_cpu(cpu_ids))
  1123. return false;
  1124. return true;
  1125. }
  1126. struct acpi_chan_package { /* ACPICA seems to require 64 bit integers */
  1127. u64 aif_value; /* 1: AIF1, 2: AIF2 */
  1128. u64 mclock_value; /* usually 25MHz (0x17d7940), ignored */
  1129. };
  1130. static int snd_byt_rt5640_mc_probe(struct platform_device *pdev)
  1131. {
  1132. const char * const map_name[] = { "dmic1", "dmic2", "in1", "in3" };
  1133. const struct dmi_system_id *dmi_id;
  1134. struct byt_rt5640_private *priv;
  1135. struct snd_soc_acpi_mach *mach;
  1136. const char *i2c_name = NULL;
  1137. int ret_val = 0;
  1138. int dai_index = 0;
  1139. int i;
  1140. is_bytcr = false;
  1141. priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
  1142. if (!priv)
  1143. return -ENOMEM;
  1144. /* register the soc card */
  1145. byt_rt5640_card.dev = &pdev->dev;
  1146. mach = byt_rt5640_card.dev->platform_data;
  1147. snd_soc_card_set_drvdata(&byt_rt5640_card, priv);
  1148. /* fix index of codec dai */
  1149. for (i = 0; i < ARRAY_SIZE(byt_rt5640_dais); i++) {
  1150. if (!strcmp(byt_rt5640_dais[i].codec_name, "i2c-10EC5640:00")) {
  1151. dai_index = i;
  1152. break;
  1153. }
  1154. }
  1155. /* fixup codec name based on HID */
  1156. i2c_name = acpi_dev_get_first_match_name(mach->id, NULL, -1);
  1157. if (i2c_name) {
  1158. snprintf(byt_rt5640_codec_name, sizeof(byt_rt5640_codec_name),
  1159. "%s%s", "i2c-", i2c_name);
  1160. byt_rt5640_dais[dai_index].codec_name = byt_rt5640_codec_name;
  1161. }
  1162. /*
  1163. * swap SSP0 if bytcr is detected
  1164. * (will be overridden if DMI quirk is detected)
  1165. */
  1166. if (is_valleyview()) {
  1167. struct sst_platform_info *p_info = mach->pdata;
  1168. const struct sst_res_info *res_info = p_info->res_info;
  1169. if (res_info->acpi_ipc_irq_index == 0)
  1170. is_bytcr = true;
  1171. }
  1172. if (is_bytcr) {
  1173. /*
  1174. * Baytrail CR platforms may have CHAN package in BIOS, try
  1175. * to find relevant routing quirk based as done on Windows
  1176. * platforms. We have to read the information directly from the
  1177. * BIOS, at this stage the card is not created and the links
  1178. * with the codec driver/pdata are non-existent
  1179. */
  1180. struct acpi_chan_package chan_package;
  1181. /* format specified: 2 64-bit integers */
  1182. struct acpi_buffer format = {sizeof("NN"), "NN"};
  1183. struct acpi_buffer state = {0, NULL};
  1184. struct snd_soc_acpi_package_context pkg_ctx;
  1185. bool pkg_found = false;
  1186. state.length = sizeof(chan_package);
  1187. state.pointer = &chan_package;
  1188. pkg_ctx.name = "CHAN";
  1189. pkg_ctx.length = 2;
  1190. pkg_ctx.format = &format;
  1191. pkg_ctx.state = &state;
  1192. pkg_ctx.data_valid = false;
  1193. pkg_found = snd_soc_acpi_find_package_from_hid(mach->id,
  1194. &pkg_ctx);
  1195. if (pkg_found) {
  1196. if (chan_package.aif_value == 1) {
  1197. dev_info(&pdev->dev, "BIOS Routing: AIF1 connected\n");
  1198. byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF1;
  1199. } else if (chan_package.aif_value == 2) {
  1200. dev_info(&pdev->dev, "BIOS Routing: AIF2 connected\n");
  1201. byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF2;
  1202. } else {
  1203. dev_info(&pdev->dev, "BIOS Routing isn't valid, ignored\n");
  1204. pkg_found = false;
  1205. }
  1206. }
  1207. if (!pkg_found) {
  1208. /* no BIOS indications, assume SSP0-AIF2 connection */
  1209. byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF2;
  1210. }
  1211. /* change defaults for Baytrail-CR capture */
  1212. byt_rt5640_quirk |= BYTCR_INPUT_DEFAULTS;
  1213. } else {
  1214. byt_rt5640_quirk |= BYT_RT5640_DMIC1_MAP |
  1215. BYT_RT5640_JD_SRC_JD2_IN4N |
  1216. BYT_RT5640_OVCD_TH_2000UA |
  1217. BYT_RT5640_OVCD_SF_0P75;
  1218. }
  1219. /* check quirks before creating card */
  1220. dmi_id = dmi_first_match(byt_rt5640_quirk_table);
  1221. if (dmi_id)
  1222. byt_rt5640_quirk = (unsigned long)dmi_id->driver_data;
  1223. if (quirk_override) {
  1224. dev_info(&pdev->dev, "Overriding quirk 0x%x => 0x%x\n",
  1225. (unsigned int)byt_rt5640_quirk, quirk_override);
  1226. byt_rt5640_quirk = quirk_override;
  1227. }
  1228. /* Must be called before register_card, also see declaration comment. */
  1229. ret_val = byt_rt5640_add_codec_device_props(byt_rt5640_codec_name);
  1230. if (ret_val)
  1231. return ret_val;
  1232. log_quirks(&pdev->dev);
  1233. if ((byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) ||
  1234. (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
  1235. /* fixup codec aif name */
  1236. snprintf(byt_rt5640_codec_aif_name,
  1237. sizeof(byt_rt5640_codec_aif_name),
  1238. "%s", "rt5640-aif2");
  1239. byt_rt5640_dais[dai_index].codec_dai_name =
  1240. byt_rt5640_codec_aif_name;
  1241. }
  1242. if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) ||
  1243. (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
  1244. /* fixup cpu dai name name */
  1245. snprintf(byt_rt5640_cpu_dai_name,
  1246. sizeof(byt_rt5640_cpu_dai_name),
  1247. "%s", "ssp0-port");
  1248. byt_rt5640_dais[dai_index].cpu_dai_name =
  1249. byt_rt5640_cpu_dai_name;
  1250. }
  1251. if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
  1252. priv->mclk = devm_clk_get(&pdev->dev, "pmc_plt_clk_3");
  1253. if (IS_ERR(priv->mclk)) {
  1254. ret_val = PTR_ERR(priv->mclk);
  1255. dev_err(&pdev->dev,
  1256. "Failed to get MCLK from pmc_plt_clk_3: %d\n",
  1257. ret_val);
  1258. /*
  1259. * Fall back to bit clock usage for -ENOENT (clock not
  1260. * available likely due to missing dependencies), bail
  1261. * for all other errors, including -EPROBE_DEFER
  1262. */
  1263. if (ret_val != -ENOENT)
  1264. return ret_val;
  1265. byt_rt5640_quirk &= ~BYT_RT5640_MCLK_EN;
  1266. }
  1267. }
  1268. snprintf(byt_rt5640_long_name, sizeof(byt_rt5640_long_name),
  1269. "bytcr-rt5640-%s-spk-%s-mic",
  1270. (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER) ?
  1271. "mono" : "stereo",
  1272. map_name[BYT_RT5640_MAP(byt_rt5640_quirk)]);
  1273. byt_rt5640_card.long_name = byt_rt5640_long_name;
  1274. ret_val = devm_snd_soc_register_card(&pdev->dev, &byt_rt5640_card);
  1275. if (ret_val) {
  1276. dev_err(&pdev->dev, "devm_snd_soc_register_card failed %d\n",
  1277. ret_val);
  1278. return ret_val;
  1279. }
  1280. platform_set_drvdata(pdev, &byt_rt5640_card);
  1281. return ret_val;
  1282. }
  1283. static struct platform_driver snd_byt_rt5640_mc_driver = {
  1284. .driver = {
  1285. .name = "bytcr_rt5640",
  1286. },
  1287. .probe = snd_byt_rt5640_mc_probe,
  1288. };
  1289. module_platform_driver(snd_byt_rt5640_mc_driver);
  1290. MODULE_DESCRIPTION("ASoC Intel(R) Baytrail CR Machine driver");
  1291. MODULE_AUTHOR("Subhransu S. Prusty <subhransu.s.prusty@intel.com>");
  1292. MODULE_LICENSE("GPL v2");
  1293. MODULE_ALIAS("platform:bytcr_rt5640");