bytcht_es8316.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * bytcht_es8316.c - ASoc Machine driver for Intel Baytrail/Cherrytrail
  4. * platforms with Everest ES8316 SoC
  5. *
  6. * Copyright (C) 2017 Endless Mobile, Inc.
  7. * Authors: David Yang <[email protected]>,
  8. * Daniel Drake <[email protected]>
  9. *
  10. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  11. *
  12. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  13. */
  14. #include <linux/acpi.h>
  15. #include <linux/clk.h>
  16. #include <linux/device.h>
  17. #include <linux/dmi.h>
  18. #include <linux/gpio/consumer.h>
  19. #include <linux/i2c.h>
  20. #include <linux/init.h>
  21. #include <linux/input.h>
  22. #include <linux/module.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/slab.h>
  25. #include <sound/jack.h>
  26. #include <sound/pcm.h>
  27. #include <sound/pcm_params.h>
  28. #include <sound/soc.h>
  29. #include <sound/soc-acpi.h>
  30. #include "../atom/sst-atom-controls.h"
  31. #include "../common/soc-intel-quirks.h"
  32. /* jd-inv + terminating entry */
  33. #define MAX_NO_PROPS 2
  34. struct byt_cht_es8316_private {
  35. struct clk *mclk;
  36. struct snd_soc_jack jack;
  37. struct gpio_desc *speaker_en_gpio;
  38. struct device *codec_dev;
  39. bool speaker_en;
  40. };
  41. enum {
  42. BYT_CHT_ES8316_INTMIC_IN1_MAP,
  43. BYT_CHT_ES8316_INTMIC_IN2_MAP,
  44. };
  45. #define BYT_CHT_ES8316_MAP(quirk) ((quirk) & GENMASK(3, 0))
  46. #define BYT_CHT_ES8316_SSP0 BIT(16)
  47. #define BYT_CHT_ES8316_MONO_SPEAKER BIT(17)
  48. #define BYT_CHT_ES8316_JD_INVERTED BIT(18)
  49. static unsigned long quirk;
  50. static int quirk_override = -1;
  51. module_param_named(quirk, quirk_override, int, 0444);
  52. MODULE_PARM_DESC(quirk, "Board-specific quirk override");
  53. static void log_quirks(struct device *dev)
  54. {
  55. if (BYT_CHT_ES8316_MAP(quirk) == BYT_CHT_ES8316_INTMIC_IN1_MAP)
  56. dev_info(dev, "quirk IN1_MAP enabled");
  57. if (BYT_CHT_ES8316_MAP(quirk) == BYT_CHT_ES8316_INTMIC_IN2_MAP)
  58. dev_info(dev, "quirk IN2_MAP enabled");
  59. if (quirk & BYT_CHT_ES8316_SSP0)
  60. dev_info(dev, "quirk SSP0 enabled");
  61. if (quirk & BYT_CHT_ES8316_MONO_SPEAKER)
  62. dev_info(dev, "quirk MONO_SPEAKER enabled\n");
  63. if (quirk & BYT_CHT_ES8316_JD_INVERTED)
  64. dev_info(dev, "quirk JD_INVERTED enabled\n");
  65. }
  66. static int byt_cht_es8316_speaker_power_event(struct snd_soc_dapm_widget *w,
  67. struct snd_kcontrol *kcontrol, int event)
  68. {
  69. struct snd_soc_card *card = w->dapm->card;
  70. struct byt_cht_es8316_private *priv = snd_soc_card_get_drvdata(card);
  71. if (SND_SOC_DAPM_EVENT_ON(event))
  72. priv->speaker_en = true;
  73. else
  74. priv->speaker_en = false;
  75. gpiod_set_value_cansleep(priv->speaker_en_gpio, priv->speaker_en);
  76. return 0;
  77. }
  78. static const struct snd_soc_dapm_widget byt_cht_es8316_widgets[] = {
  79. SND_SOC_DAPM_SPK("Speaker", NULL),
  80. SND_SOC_DAPM_HP("Headphone", NULL),
  81. SND_SOC_DAPM_MIC("Headset Mic", NULL),
  82. SND_SOC_DAPM_MIC("Internal Mic", NULL),
  83. SND_SOC_DAPM_SUPPLY("Speaker Power", SND_SOC_NOPM, 0, 0,
  84. byt_cht_es8316_speaker_power_event,
  85. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU),
  86. };
  87. static const struct snd_soc_dapm_route byt_cht_es8316_audio_map[] = {
  88. {"Headphone", NULL, "HPOL"},
  89. {"Headphone", NULL, "HPOR"},
  90. /*
  91. * There is no separate speaker output instead the speakers are muxed to
  92. * the HP outputs. The mux is controlled by the "Speaker Power" supply.
  93. */
  94. {"Speaker", NULL, "HPOL"},
  95. {"Speaker", NULL, "HPOR"},
  96. {"Speaker", NULL, "Speaker Power"},
  97. };
  98. static const struct snd_soc_dapm_route byt_cht_es8316_intmic_in1_map[] = {
  99. {"MIC1", NULL, "Internal Mic"},
  100. {"MIC2", NULL, "Headset Mic"},
  101. };
  102. static const struct snd_soc_dapm_route byt_cht_es8316_intmic_in2_map[] = {
  103. {"MIC2", NULL, "Internal Mic"},
  104. {"MIC1", NULL, "Headset Mic"},
  105. };
  106. static const struct snd_soc_dapm_route byt_cht_es8316_ssp0_map[] = {
  107. {"Playback", NULL, "ssp0 Tx"},
  108. {"ssp0 Tx", NULL, "modem_out"},
  109. {"modem_in", NULL, "ssp0 Rx"},
  110. {"ssp0 Rx", NULL, "Capture"},
  111. };
  112. static const struct snd_soc_dapm_route byt_cht_es8316_ssp2_map[] = {
  113. {"Playback", NULL, "ssp2 Tx"},
  114. {"ssp2 Tx", NULL, "codec_out0"},
  115. {"ssp2 Tx", NULL, "codec_out1"},
  116. {"codec_in0", NULL, "ssp2 Rx" },
  117. {"codec_in1", NULL, "ssp2 Rx" },
  118. {"ssp2 Rx", NULL, "Capture"},
  119. };
  120. static const struct snd_kcontrol_new byt_cht_es8316_controls[] = {
  121. SOC_DAPM_PIN_SWITCH("Speaker"),
  122. SOC_DAPM_PIN_SWITCH("Headphone"),
  123. SOC_DAPM_PIN_SWITCH("Headset Mic"),
  124. SOC_DAPM_PIN_SWITCH("Internal Mic"),
  125. };
  126. static struct snd_soc_jack_pin byt_cht_es8316_jack_pins[] = {
  127. {
  128. .pin = "Headphone",
  129. .mask = SND_JACK_HEADPHONE,
  130. },
  131. {
  132. .pin = "Headset Mic",
  133. .mask = SND_JACK_MICROPHONE,
  134. },
  135. };
  136. static int byt_cht_es8316_init(struct snd_soc_pcm_runtime *runtime)
  137. {
  138. struct snd_soc_component *codec = asoc_rtd_to_codec(runtime, 0)->component;
  139. struct snd_soc_card *card = runtime->card;
  140. struct byt_cht_es8316_private *priv = snd_soc_card_get_drvdata(card);
  141. const struct snd_soc_dapm_route *custom_map;
  142. int num_routes;
  143. int ret;
  144. card->dapm.idle_bias_off = true;
  145. switch (BYT_CHT_ES8316_MAP(quirk)) {
  146. case BYT_CHT_ES8316_INTMIC_IN1_MAP:
  147. default:
  148. custom_map = byt_cht_es8316_intmic_in1_map;
  149. num_routes = ARRAY_SIZE(byt_cht_es8316_intmic_in1_map);
  150. break;
  151. case BYT_CHT_ES8316_INTMIC_IN2_MAP:
  152. custom_map = byt_cht_es8316_intmic_in2_map;
  153. num_routes = ARRAY_SIZE(byt_cht_es8316_intmic_in2_map);
  154. break;
  155. }
  156. ret = snd_soc_dapm_add_routes(&card->dapm, custom_map, num_routes);
  157. if (ret)
  158. return ret;
  159. if (quirk & BYT_CHT_ES8316_SSP0) {
  160. custom_map = byt_cht_es8316_ssp0_map;
  161. num_routes = ARRAY_SIZE(byt_cht_es8316_ssp0_map);
  162. } else {
  163. custom_map = byt_cht_es8316_ssp2_map;
  164. num_routes = ARRAY_SIZE(byt_cht_es8316_ssp2_map);
  165. }
  166. ret = snd_soc_dapm_add_routes(&card->dapm, custom_map, num_routes);
  167. if (ret)
  168. return ret;
  169. /*
  170. * The firmware might enable the clock at boot (this information
  171. * may or may not be reflected in the enable clock register).
  172. * To change the rate we must disable the clock first to cover these
  173. * cases. Due to common clock framework restrictions that do not allow
  174. * to disable a clock that has not been enabled, we need to enable
  175. * the clock first.
  176. */
  177. ret = clk_prepare_enable(priv->mclk);
  178. if (!ret)
  179. clk_disable_unprepare(priv->mclk);
  180. ret = clk_set_rate(priv->mclk, 19200000);
  181. if (ret)
  182. dev_err(card->dev, "unable to set MCLK rate\n");
  183. ret = clk_prepare_enable(priv->mclk);
  184. if (ret)
  185. dev_err(card->dev, "unable to enable MCLK\n");
  186. ret = snd_soc_dai_set_sysclk(asoc_rtd_to_codec(runtime, 0), 0, 19200000,
  187. SND_SOC_CLOCK_IN);
  188. if (ret < 0) {
  189. dev_err(card->dev, "can't set codec clock %d\n", ret);
  190. return ret;
  191. }
  192. ret = snd_soc_card_jack_new_pins(card, "Headset",
  193. SND_JACK_HEADSET | SND_JACK_BTN_0,
  194. &priv->jack, byt_cht_es8316_jack_pins,
  195. ARRAY_SIZE(byt_cht_es8316_jack_pins));
  196. if (ret) {
  197. dev_err(card->dev, "jack creation failed %d\n", ret);
  198. return ret;
  199. }
  200. snd_jack_set_key(priv->jack.jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
  201. snd_soc_component_set_jack(codec, &priv->jack, NULL);
  202. return 0;
  203. }
  204. static int byt_cht_es8316_codec_fixup(struct snd_soc_pcm_runtime *rtd,
  205. struct snd_pcm_hw_params *params)
  206. {
  207. struct snd_interval *rate = hw_param_interval(params,
  208. SNDRV_PCM_HW_PARAM_RATE);
  209. struct snd_interval *channels = hw_param_interval(params,
  210. SNDRV_PCM_HW_PARAM_CHANNELS);
  211. int ret, bits;
  212. /* The DSP will covert the FE rate to 48k, stereo */
  213. rate->min = rate->max = 48000;
  214. channels->min = channels->max = 2;
  215. if (quirk & BYT_CHT_ES8316_SSP0) {
  216. /* set SSP0 to 16-bit */
  217. params_set_format(params, SNDRV_PCM_FORMAT_S16_LE);
  218. bits = 16;
  219. } else {
  220. /* set SSP2 to 24-bit */
  221. params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);
  222. bits = 24;
  223. }
  224. /*
  225. * Default mode for SSP configuration is TDM 4 slot, override config
  226. * with explicit setting to I2S 2ch 24-bit. The word length is set with
  227. * dai_set_tdm_slot() since there is no other API exposed
  228. */
  229. ret = snd_soc_dai_set_fmt(asoc_rtd_to_cpu(rtd, 0),
  230. SND_SOC_DAIFMT_I2S |
  231. SND_SOC_DAIFMT_NB_NF |
  232. SND_SOC_DAIFMT_BP_FP
  233. );
  234. if (ret < 0) {
  235. dev_err(rtd->dev, "can't set format to I2S, err %d\n", ret);
  236. return ret;
  237. }
  238. ret = snd_soc_dai_set_tdm_slot(asoc_rtd_to_cpu(rtd, 0), 0x3, 0x3, 2, bits);
  239. if (ret < 0) {
  240. dev_err(rtd->dev, "can't set I2S config, err %d\n", ret);
  241. return ret;
  242. }
  243. return 0;
  244. }
  245. static int byt_cht_es8316_aif1_startup(struct snd_pcm_substream *substream)
  246. {
  247. return snd_pcm_hw_constraint_single(substream->runtime,
  248. SNDRV_PCM_HW_PARAM_RATE, 48000);
  249. }
  250. static const struct snd_soc_ops byt_cht_es8316_aif1_ops = {
  251. .startup = byt_cht_es8316_aif1_startup,
  252. };
  253. SND_SOC_DAILINK_DEF(dummy,
  254. DAILINK_COMP_ARRAY(COMP_DUMMY()));
  255. SND_SOC_DAILINK_DEF(media,
  256. DAILINK_COMP_ARRAY(COMP_CPU("media-cpu-dai")));
  257. SND_SOC_DAILINK_DEF(deepbuffer,
  258. DAILINK_COMP_ARRAY(COMP_CPU("deepbuffer-cpu-dai")));
  259. SND_SOC_DAILINK_DEF(ssp2_port,
  260. DAILINK_COMP_ARRAY(COMP_CPU("ssp2-port")));
  261. SND_SOC_DAILINK_DEF(ssp2_codec,
  262. DAILINK_COMP_ARRAY(COMP_CODEC("i2c-ESSX8316:00", "ES8316 HiFi")));
  263. SND_SOC_DAILINK_DEF(platform,
  264. DAILINK_COMP_ARRAY(COMP_PLATFORM("sst-mfld-platform")));
  265. static struct snd_soc_dai_link byt_cht_es8316_dais[] = {
  266. [MERR_DPCM_AUDIO] = {
  267. .name = "Audio Port",
  268. .stream_name = "Audio",
  269. .nonatomic = true,
  270. .dynamic = 1,
  271. .dpcm_playback = 1,
  272. .dpcm_capture = 1,
  273. .ops = &byt_cht_es8316_aif1_ops,
  274. SND_SOC_DAILINK_REG(media, dummy, platform),
  275. },
  276. [MERR_DPCM_DEEP_BUFFER] = {
  277. .name = "Deep-Buffer Audio Port",
  278. .stream_name = "Deep-Buffer Audio",
  279. .nonatomic = true,
  280. .dynamic = 1,
  281. .dpcm_playback = 1,
  282. .ops = &byt_cht_es8316_aif1_ops,
  283. SND_SOC_DAILINK_REG(deepbuffer, dummy, platform),
  284. },
  285. /* back ends */
  286. {
  287. .name = "SSP2-Codec",
  288. .id = 0,
  289. .no_pcm = 1,
  290. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
  291. | SND_SOC_DAIFMT_CBC_CFC,
  292. .be_hw_params_fixup = byt_cht_es8316_codec_fixup,
  293. .dpcm_playback = 1,
  294. .dpcm_capture = 1,
  295. .init = byt_cht_es8316_init,
  296. SND_SOC_DAILINK_REG(ssp2_port, ssp2_codec, platform),
  297. },
  298. };
  299. /* SoC card */
  300. static char codec_name[SND_ACPI_I2C_ID_LEN];
  301. #if !IS_ENABLED(CONFIG_SND_SOC_INTEL_USER_FRIENDLY_LONG_NAMES)
  302. static char long_name[50]; /* = "bytcht-es8316-*-spk-*-mic" */
  303. #endif
  304. static char components_string[32]; /* = "cfg-spk:* cfg-mic:* */
  305. static int byt_cht_es8316_suspend(struct snd_soc_card *card)
  306. {
  307. struct snd_soc_component *component;
  308. for_each_card_components(card, component) {
  309. if (!strcmp(component->name, codec_name)) {
  310. dev_dbg(component->dev, "disabling jack detect before suspend\n");
  311. snd_soc_component_set_jack(component, NULL, NULL);
  312. break;
  313. }
  314. }
  315. return 0;
  316. }
  317. static int byt_cht_es8316_resume(struct snd_soc_card *card)
  318. {
  319. struct byt_cht_es8316_private *priv = snd_soc_card_get_drvdata(card);
  320. struct snd_soc_component *component;
  321. for_each_card_components(card, component) {
  322. if (!strcmp(component->name, codec_name)) {
  323. dev_dbg(component->dev, "re-enabling jack detect after resume\n");
  324. snd_soc_component_set_jack(component, &priv->jack, NULL);
  325. break;
  326. }
  327. }
  328. /*
  329. * Some Cherry Trail boards with an ES8316 codec have a bug in their
  330. * ACPI tables where the MSSL1680 touchscreen's _PS0 and _PS3 methods
  331. * wrongly also set the speaker-enable GPIO to 1/0. Testing has shown
  332. * that this really is a bug and the GPIO has no influence on the
  333. * touchscreen at all.
  334. *
  335. * The silead.c touchscreen driver does not support runtime suspend, so
  336. * the GPIO can only be changed underneath us during a system suspend.
  337. * This resume() function runs from a pm complete() callback, and thus
  338. * is guaranteed to run after the touchscreen driver/ACPI-subsys has
  339. * brought the touchscreen back up again (and thus changed the GPIO).
  340. *
  341. * So to work around this we pass GPIOD_FLAGS_BIT_NONEXCLUSIVE when
  342. * requesting the GPIO and we set its value here to undo any changes
  343. * done by the touchscreen's broken _PS0 ACPI method.
  344. */
  345. gpiod_set_value_cansleep(priv->speaker_en_gpio, priv->speaker_en);
  346. return 0;
  347. }
  348. /* use space before codec name to simplify card ID, and simplify driver name */
  349. #define SOF_CARD_NAME "bytcht es8316" /* card name will be 'sof-bytcht es8316' */
  350. #define SOF_DRIVER_NAME "SOF"
  351. #define CARD_NAME "bytcht-es8316"
  352. #define DRIVER_NAME NULL /* card name will be used for driver name */
  353. static struct snd_soc_card byt_cht_es8316_card = {
  354. .owner = THIS_MODULE,
  355. .dai_link = byt_cht_es8316_dais,
  356. .num_links = ARRAY_SIZE(byt_cht_es8316_dais),
  357. .dapm_widgets = byt_cht_es8316_widgets,
  358. .num_dapm_widgets = ARRAY_SIZE(byt_cht_es8316_widgets),
  359. .dapm_routes = byt_cht_es8316_audio_map,
  360. .num_dapm_routes = ARRAY_SIZE(byt_cht_es8316_audio_map),
  361. .controls = byt_cht_es8316_controls,
  362. .num_controls = ARRAY_SIZE(byt_cht_es8316_controls),
  363. .fully_routed = true,
  364. .suspend_pre = byt_cht_es8316_suspend,
  365. .resume_post = byt_cht_es8316_resume,
  366. };
  367. static const struct acpi_gpio_params first_gpio = { 0, 0, false };
  368. static const struct acpi_gpio_mapping byt_cht_es8316_gpios[] = {
  369. { "speaker-enable-gpios", &first_gpio, 1 },
  370. { },
  371. };
  372. /* Please keep this list alphabetically sorted */
  373. static const struct dmi_system_id byt_cht_es8316_quirk_table[] = {
  374. { /* Irbis NB41 */
  375. .matches = {
  376. DMI_MATCH(DMI_SYS_VENDOR, "IRBIS"),
  377. DMI_MATCH(DMI_PRODUCT_NAME, "NB41"),
  378. },
  379. .driver_data = (void *)(BYT_CHT_ES8316_SSP0
  380. | BYT_CHT_ES8316_INTMIC_IN2_MAP
  381. | BYT_CHT_ES8316_JD_INVERTED),
  382. },
  383. { /* Nanote UMPC-01 */
  384. .matches = {
  385. DMI_MATCH(DMI_SYS_VENDOR, "RWC CO.,LTD"),
  386. DMI_MATCH(DMI_PRODUCT_NAME, "UMPC-01"),
  387. },
  388. .driver_data = (void *)BYT_CHT_ES8316_INTMIC_IN1_MAP,
  389. },
  390. { /* Teclast X98 Plus II */
  391. .matches = {
  392. DMI_MATCH(DMI_SYS_VENDOR, "TECLAST"),
  393. DMI_MATCH(DMI_PRODUCT_NAME, "X98 Plus II"),
  394. },
  395. .driver_data = (void *)(BYT_CHT_ES8316_INTMIC_IN1_MAP
  396. | BYT_CHT_ES8316_JD_INVERTED),
  397. },
  398. {}
  399. };
  400. static int snd_byt_cht_es8316_mc_probe(struct platform_device *pdev)
  401. {
  402. struct device *dev = &pdev->dev;
  403. static const char * const mic_name[] = { "in1", "in2" };
  404. struct snd_soc_acpi_mach *mach = dev_get_platdata(dev);
  405. struct property_entry props[MAX_NO_PROPS] = {};
  406. struct byt_cht_es8316_private *priv;
  407. const struct dmi_system_id *dmi_id;
  408. struct fwnode_handle *fwnode;
  409. const char *platform_name;
  410. struct acpi_device *adev;
  411. struct device *codec_dev;
  412. bool sof_parent;
  413. unsigned int cnt = 0;
  414. int dai_index = 0;
  415. int i;
  416. int ret = 0;
  417. priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
  418. if (!priv)
  419. return -ENOMEM;
  420. /* fix index of codec dai */
  421. for (i = 0; i < ARRAY_SIZE(byt_cht_es8316_dais); i++) {
  422. if (!strcmp(byt_cht_es8316_dais[i].codecs->name,
  423. "i2c-ESSX8316:00")) {
  424. dai_index = i;
  425. break;
  426. }
  427. }
  428. /* fixup codec name based on HID */
  429. adev = acpi_dev_get_first_match_dev(mach->id, NULL, -1);
  430. if (adev) {
  431. snprintf(codec_name, sizeof(codec_name),
  432. "i2c-%s", acpi_dev_name(adev));
  433. byt_cht_es8316_dais[dai_index].codecs->name = codec_name;
  434. } else {
  435. dev_err(dev, "Error cannot find '%s' dev\n", mach->id);
  436. return -ENXIO;
  437. }
  438. codec_dev = acpi_get_first_physical_node(adev);
  439. acpi_dev_put(adev);
  440. if (!codec_dev)
  441. return -EPROBE_DEFER;
  442. priv->codec_dev = get_device(codec_dev);
  443. /* override platform name, if required */
  444. byt_cht_es8316_card.dev = dev;
  445. platform_name = mach->mach_params.platform;
  446. ret = snd_soc_fixup_dai_links_platform_name(&byt_cht_es8316_card,
  447. platform_name);
  448. if (ret) {
  449. put_device(codec_dev);
  450. return ret;
  451. }
  452. /* Check for BYTCR or other platform and setup quirks */
  453. dmi_id = dmi_first_match(byt_cht_es8316_quirk_table);
  454. if (dmi_id) {
  455. quirk = (unsigned long)dmi_id->driver_data;
  456. } else if (soc_intel_is_byt() &&
  457. mach->mach_params.acpi_ipc_irq_index == 0) {
  458. /* On BYTCR default to SSP0, internal-mic-in2-map, mono-spk */
  459. quirk = BYT_CHT_ES8316_SSP0 | BYT_CHT_ES8316_INTMIC_IN2_MAP |
  460. BYT_CHT_ES8316_MONO_SPEAKER;
  461. } else {
  462. /* Others default to internal-mic-in1-map, mono-speaker */
  463. quirk = BYT_CHT_ES8316_INTMIC_IN1_MAP |
  464. BYT_CHT_ES8316_MONO_SPEAKER;
  465. }
  466. if (quirk_override != -1) {
  467. dev_info(dev, "Overriding quirk 0x%lx => 0x%x\n",
  468. quirk, quirk_override);
  469. quirk = quirk_override;
  470. }
  471. log_quirks(dev);
  472. if (quirk & BYT_CHT_ES8316_SSP0)
  473. byt_cht_es8316_dais[dai_index].cpus->dai_name = "ssp0-port";
  474. /* get the clock */
  475. priv->mclk = devm_clk_get(dev, "pmc_plt_clk_3");
  476. if (IS_ERR(priv->mclk)) {
  477. put_device(codec_dev);
  478. return dev_err_probe(dev, PTR_ERR(priv->mclk), "clk_get pmc_plt_clk_3 failed\n");
  479. }
  480. if (quirk & BYT_CHT_ES8316_JD_INVERTED)
  481. props[cnt++] = PROPERTY_ENTRY_BOOL("everest,jack-detect-inverted");
  482. if (cnt) {
  483. fwnode = fwnode_create_software_node(props, NULL);
  484. if (IS_ERR(fwnode)) {
  485. put_device(codec_dev);
  486. return PTR_ERR(fwnode);
  487. }
  488. ret = device_add_software_node(codec_dev, to_software_node(fwnode));
  489. fwnode_handle_put(fwnode);
  490. if (ret) {
  491. put_device(codec_dev);
  492. return ret;
  493. }
  494. }
  495. /* get speaker enable GPIO */
  496. devm_acpi_dev_add_driver_gpios(codec_dev, byt_cht_es8316_gpios);
  497. priv->speaker_en_gpio =
  498. gpiod_get_optional(codec_dev, "speaker-enable",
  499. /* see comment in byt_cht_es8316_resume() */
  500. GPIOD_OUT_LOW | GPIOD_FLAGS_BIT_NONEXCLUSIVE);
  501. if (IS_ERR(priv->speaker_en_gpio)) {
  502. ret = dev_err_probe(dev, PTR_ERR(priv->speaker_en_gpio),
  503. "get speaker GPIO failed\n");
  504. goto err_put_codec;
  505. }
  506. snprintf(components_string, sizeof(components_string),
  507. "cfg-spk:%s cfg-mic:%s",
  508. (quirk & BYT_CHT_ES8316_MONO_SPEAKER) ? "1" : "2",
  509. mic_name[BYT_CHT_ES8316_MAP(quirk)]);
  510. byt_cht_es8316_card.components = components_string;
  511. #if !IS_ENABLED(CONFIG_SND_SOC_INTEL_USER_FRIENDLY_LONG_NAMES)
  512. snprintf(long_name, sizeof(long_name), "bytcht-es8316-%s-spk-%s-mic",
  513. (quirk & BYT_CHT_ES8316_MONO_SPEAKER) ? "mono" : "stereo",
  514. mic_name[BYT_CHT_ES8316_MAP(quirk)]);
  515. byt_cht_es8316_card.long_name = long_name;
  516. #endif
  517. sof_parent = snd_soc_acpi_sof_parent(dev);
  518. /* set card and driver name */
  519. if (sof_parent) {
  520. byt_cht_es8316_card.name = SOF_CARD_NAME;
  521. byt_cht_es8316_card.driver_name = SOF_DRIVER_NAME;
  522. } else {
  523. byt_cht_es8316_card.name = CARD_NAME;
  524. byt_cht_es8316_card.driver_name = DRIVER_NAME;
  525. }
  526. /* set pm ops */
  527. if (sof_parent)
  528. dev->driver->pm = &snd_soc_pm_ops;
  529. /* register the soc card */
  530. snd_soc_card_set_drvdata(&byt_cht_es8316_card, priv);
  531. ret = devm_snd_soc_register_card(dev, &byt_cht_es8316_card);
  532. if (ret) {
  533. gpiod_put(priv->speaker_en_gpio);
  534. dev_err(dev, "snd_soc_register_card failed: %d\n", ret);
  535. goto err_put_codec;
  536. }
  537. platform_set_drvdata(pdev, &byt_cht_es8316_card);
  538. return 0;
  539. err_put_codec:
  540. device_remove_software_node(priv->codec_dev);
  541. put_device(priv->codec_dev);
  542. return ret;
  543. }
  544. static int snd_byt_cht_es8316_mc_remove(struct platform_device *pdev)
  545. {
  546. struct snd_soc_card *card = platform_get_drvdata(pdev);
  547. struct byt_cht_es8316_private *priv = snd_soc_card_get_drvdata(card);
  548. gpiod_put(priv->speaker_en_gpio);
  549. device_remove_software_node(priv->codec_dev);
  550. put_device(priv->codec_dev);
  551. return 0;
  552. }
  553. static struct platform_driver snd_byt_cht_es8316_mc_driver = {
  554. .driver = {
  555. .name = "bytcht_es8316",
  556. },
  557. .probe = snd_byt_cht_es8316_mc_probe,
  558. .remove = snd_byt_cht_es8316_mc_remove,
  559. };
  560. module_platform_driver(snd_byt_cht_es8316_mc_driver);
  561. MODULE_DESCRIPTION("ASoC Intel(R) Baytrail/Cherrytrail Machine driver");
  562. MODULE_AUTHOR("David Yang <[email protected]>");
  563. MODULE_LICENSE("GPL v2");
  564. MODULE_ALIAS("platform:bytcht_es8316");