sof_nau8825.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. // Copyright(c) 2021 Intel Corporation.
  3. // Copyright(c) 2021 Nuvoton Corporation.
  4. /*
  5. * Intel SOF Machine Driver with Nuvoton headphone codec NAU8825
  6. * and speaker codec RT1019P MAX98360a or MAX98373
  7. */
  8. #include <linux/i2c.h>
  9. #include <linux/input.h>
  10. #include <linux/module.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/dmi.h>
  13. #include <sound/core.h>
  14. #include <sound/jack.h>
  15. #include <sound/pcm.h>
  16. #include <sound/pcm_params.h>
  17. #include <sound/soc.h>
  18. #include <sound/sof.h>
  19. #include <sound/soc-acpi.h>
  20. #include "../../codecs/nau8825.h"
  21. #include "../common/soc-intel-quirks.h"
  22. #include "hda_dsp_common.h"
  23. #include "sof_realtek_common.h"
  24. #include "sof_maxim_common.h"
  25. #define NAME_SIZE 32
  26. #define SOF_NAU8825_SSP_CODEC(quirk) ((quirk) & GENMASK(2, 0))
  27. #define SOF_NAU8825_SSP_CODEC_MASK (GENMASK(2, 0))
  28. #define SOF_SPEAKER_AMP_PRESENT BIT(3)
  29. #define SOF_NAU8825_SSP_AMP_SHIFT 4
  30. #define SOF_NAU8825_SSP_AMP_MASK (GENMASK(6, 4))
  31. #define SOF_NAU8825_SSP_AMP(quirk) \
  32. (((quirk) << SOF_NAU8825_SSP_AMP_SHIFT) & SOF_NAU8825_SSP_AMP_MASK)
  33. #define SOF_NAU8825_NUM_HDMIDEV_SHIFT 7
  34. #define SOF_NAU8825_NUM_HDMIDEV_MASK (GENMASK(9, 7))
  35. #define SOF_NAU8825_NUM_HDMIDEV(quirk) \
  36. (((quirk) << SOF_NAU8825_NUM_HDMIDEV_SHIFT) & SOF_NAU8825_NUM_HDMIDEV_MASK)
  37. /* BT audio offload: reserve 3 bits for future */
  38. #define SOF_BT_OFFLOAD_SSP_SHIFT 10
  39. #define SOF_BT_OFFLOAD_SSP_MASK (GENMASK(12, 10))
  40. #define SOF_BT_OFFLOAD_SSP(quirk) \
  41. (((quirk) << SOF_BT_OFFLOAD_SSP_SHIFT) & SOF_BT_OFFLOAD_SSP_MASK)
  42. #define SOF_SSP_BT_OFFLOAD_PRESENT BIT(13)
  43. #define SOF_RT1019P_SPEAKER_AMP_PRESENT BIT(14)
  44. #define SOF_MAX98373_SPEAKER_AMP_PRESENT BIT(15)
  45. #define SOF_MAX98360A_SPEAKER_AMP_PRESENT BIT(16)
  46. #define SOF_RT1015P_SPEAKER_AMP_PRESENT BIT(17)
  47. static unsigned long sof_nau8825_quirk = SOF_NAU8825_SSP_CODEC(0);
  48. struct sof_hdmi_pcm {
  49. struct list_head head;
  50. struct snd_soc_dai *codec_dai;
  51. int device;
  52. };
  53. struct sof_card_private {
  54. struct clk *mclk;
  55. struct snd_soc_jack sof_headset;
  56. struct list_head hdmi_pcm_list;
  57. };
  58. static int sof_hdmi_init(struct snd_soc_pcm_runtime *rtd)
  59. {
  60. struct sof_card_private *ctx = snd_soc_card_get_drvdata(rtd->card);
  61. struct snd_soc_dai *dai = asoc_rtd_to_codec(rtd, 0);
  62. struct sof_hdmi_pcm *pcm;
  63. pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
  64. if (!pcm)
  65. return -ENOMEM;
  66. /* dai_link id is 1:1 mapped to the PCM device */
  67. pcm->device = rtd->dai_link->id;
  68. pcm->codec_dai = dai;
  69. list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
  70. return 0;
  71. }
  72. static struct snd_soc_jack_pin jack_pins[] = {
  73. {
  74. .pin = "Headphone Jack",
  75. .mask = SND_JACK_HEADPHONE,
  76. },
  77. {
  78. .pin = "Headset Mic",
  79. .mask = SND_JACK_MICROPHONE,
  80. },
  81. };
  82. static int sof_nau8825_codec_init(struct snd_soc_pcm_runtime *rtd)
  83. {
  84. struct sof_card_private *ctx = snd_soc_card_get_drvdata(rtd->card);
  85. struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
  86. struct snd_soc_jack *jack;
  87. int ret;
  88. /*
  89. * Headset buttons map to the google Reference headset.
  90. * These can be configured by userspace.
  91. */
  92. ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack",
  93. SND_JACK_HEADSET | SND_JACK_BTN_0 |
  94. SND_JACK_BTN_1 | SND_JACK_BTN_2 |
  95. SND_JACK_BTN_3,
  96. &ctx->sof_headset,
  97. jack_pins,
  98. ARRAY_SIZE(jack_pins));
  99. if (ret) {
  100. dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret);
  101. return ret;
  102. }
  103. jack = &ctx->sof_headset;
  104. snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
  105. snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
  106. snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
  107. snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
  108. ret = snd_soc_component_set_jack(component, jack, NULL);
  109. if (ret) {
  110. dev_err(rtd->dev, "Headset Jack call-back failed: %d\n", ret);
  111. return ret;
  112. }
  113. return ret;
  114. };
  115. static void sof_nau8825_codec_exit(struct snd_soc_pcm_runtime *rtd)
  116. {
  117. struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
  118. snd_soc_component_set_jack(component, NULL, NULL);
  119. }
  120. static int sof_nau8825_hw_params(struct snd_pcm_substream *substream,
  121. struct snd_pcm_hw_params *params)
  122. {
  123. struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
  124. struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
  125. int clk_freq, ret;
  126. clk_freq = sof_dai_get_bclk(rtd); /* BCLK freq */
  127. if (clk_freq <= 0) {
  128. dev_err(rtd->dev, "get bclk freq failed: %d\n", clk_freq);
  129. return -EINVAL;
  130. }
  131. /* Configure clock for codec */
  132. ret = snd_soc_dai_set_sysclk(codec_dai, NAU8825_CLK_FLL_BLK, 0,
  133. SND_SOC_CLOCK_IN);
  134. if (ret < 0) {
  135. dev_err(codec_dai->dev, "can't set BCLK clock %d\n", ret);
  136. return ret;
  137. }
  138. /* Configure pll for codec */
  139. ret = snd_soc_dai_set_pll(codec_dai, 0, 0, clk_freq,
  140. params_rate(params) * 256);
  141. if (ret < 0) {
  142. dev_err(codec_dai->dev, "can't set BCLK: %d\n", ret);
  143. return ret;
  144. }
  145. return ret;
  146. }
  147. static struct snd_soc_ops sof_nau8825_ops = {
  148. .hw_params = sof_nau8825_hw_params,
  149. };
  150. static struct snd_soc_dai_link_component platform_component[] = {
  151. {
  152. /* name might be overridden during probe */
  153. .name = "0000:00:1f.3"
  154. }
  155. };
  156. static int sof_card_late_probe(struct snd_soc_card *card)
  157. {
  158. struct sof_card_private *ctx = snd_soc_card_get_drvdata(card);
  159. struct snd_soc_dapm_context *dapm = &card->dapm;
  160. struct sof_hdmi_pcm *pcm;
  161. int err;
  162. if (sof_nau8825_quirk & SOF_MAX98373_SPEAKER_AMP_PRESENT) {
  163. /* Disable Left and Right Spk pin after boot */
  164. snd_soc_dapm_disable_pin(dapm, "Left Spk");
  165. snd_soc_dapm_disable_pin(dapm, "Right Spk");
  166. err = snd_soc_dapm_sync(dapm);
  167. if (err < 0)
  168. return err;
  169. }
  170. if (list_empty(&ctx->hdmi_pcm_list))
  171. return -EINVAL;
  172. pcm = list_first_entry(&ctx->hdmi_pcm_list, struct sof_hdmi_pcm, head);
  173. return hda_dsp_hdmi_build_controls(card, pcm->codec_dai->component);
  174. }
  175. static const struct snd_kcontrol_new sof_controls[] = {
  176. SOC_DAPM_PIN_SWITCH("Headphone Jack"),
  177. SOC_DAPM_PIN_SWITCH("Headset Mic"),
  178. SOC_DAPM_PIN_SWITCH("Left Spk"),
  179. SOC_DAPM_PIN_SWITCH("Right Spk"),
  180. };
  181. static const struct snd_kcontrol_new speaker_controls[] = {
  182. SOC_DAPM_PIN_SWITCH("Spk"),
  183. };
  184. static const struct snd_soc_dapm_widget sof_widgets[] = {
  185. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  186. SND_SOC_DAPM_MIC("Headset Mic", NULL),
  187. SND_SOC_DAPM_SPK("Left Spk", NULL),
  188. SND_SOC_DAPM_SPK("Right Spk", NULL),
  189. };
  190. static const struct snd_soc_dapm_widget speaker_widgets[] = {
  191. SND_SOC_DAPM_SPK("Spk", NULL),
  192. };
  193. static const struct snd_soc_dapm_widget dmic_widgets[] = {
  194. SND_SOC_DAPM_MIC("SoC DMIC", NULL),
  195. };
  196. static const struct snd_soc_dapm_route sof_map[] = {
  197. /* HP jack connectors - unknown if we have jack detection */
  198. { "Headphone Jack", NULL, "HPOL" },
  199. { "Headphone Jack", NULL, "HPOR" },
  200. /* other jacks */
  201. { "MIC", NULL, "Headset Mic" },
  202. };
  203. static const struct snd_soc_dapm_route speaker_map[] = {
  204. /* speaker */
  205. { "Spk", NULL, "Speaker" },
  206. };
  207. static const struct snd_soc_dapm_route dmic_map[] = {
  208. /* digital mics */
  209. {"DMic", NULL, "SoC DMIC"},
  210. };
  211. static int speaker_codec_init(struct snd_soc_pcm_runtime *rtd)
  212. {
  213. struct snd_soc_card *card = rtd->card;
  214. int ret;
  215. ret = snd_soc_dapm_new_controls(&card->dapm, speaker_widgets,
  216. ARRAY_SIZE(speaker_widgets));
  217. if (ret) {
  218. dev_err(rtd->dev, "unable to add dapm controls, ret %d\n", ret);
  219. /* Don't need to add routes if widget addition failed */
  220. return ret;
  221. }
  222. ret = snd_soc_add_card_controls(card, speaker_controls,
  223. ARRAY_SIZE(speaker_controls));
  224. if (ret) {
  225. dev_err(rtd->dev, "unable to add card controls, ret %d\n", ret);
  226. return ret;
  227. }
  228. ret = snd_soc_dapm_add_routes(&card->dapm, speaker_map,
  229. ARRAY_SIZE(speaker_map));
  230. if (ret)
  231. dev_err(rtd->dev, "Speaker map addition failed: %d\n", ret);
  232. return ret;
  233. }
  234. static int dmic_init(struct snd_soc_pcm_runtime *rtd)
  235. {
  236. struct snd_soc_card *card = rtd->card;
  237. int ret;
  238. ret = snd_soc_dapm_new_controls(&card->dapm, dmic_widgets,
  239. ARRAY_SIZE(dmic_widgets));
  240. if (ret) {
  241. dev_err(card->dev, "DMic widget addition failed: %d\n", ret);
  242. /* Don't need to add routes if widget addition failed */
  243. return ret;
  244. }
  245. ret = snd_soc_dapm_add_routes(&card->dapm, dmic_map,
  246. ARRAY_SIZE(dmic_map));
  247. if (ret)
  248. dev_err(card->dev, "DMic map addition failed: %d\n", ret);
  249. return ret;
  250. }
  251. /* sof audio machine driver for nau8825 codec */
  252. static struct snd_soc_card sof_audio_card_nau8825 = {
  253. .name = "nau8825", /* the sof- prefix is added by the core */
  254. .owner = THIS_MODULE,
  255. .controls = sof_controls,
  256. .num_controls = ARRAY_SIZE(sof_controls),
  257. .dapm_widgets = sof_widgets,
  258. .num_dapm_widgets = ARRAY_SIZE(sof_widgets),
  259. .dapm_routes = sof_map,
  260. .num_dapm_routes = ARRAY_SIZE(sof_map),
  261. .fully_routed = true,
  262. .late_probe = sof_card_late_probe,
  263. };
  264. static struct snd_soc_dai_link_component nau8825_component[] = {
  265. {
  266. .name = "i2c-10508825:00",
  267. .dai_name = "nau8825-hifi",
  268. }
  269. };
  270. static struct snd_soc_dai_link_component dmic_component[] = {
  271. {
  272. .name = "dmic-codec",
  273. .dai_name = "dmic-hifi",
  274. }
  275. };
  276. static struct snd_soc_dai_link_component rt1019p_component[] = {
  277. {
  278. .name = "RTL1019:00",
  279. .dai_name = "HiFi",
  280. }
  281. };
  282. static struct snd_soc_dai_link_component dummy_component[] = {
  283. {
  284. .name = "snd-soc-dummy",
  285. .dai_name = "snd-soc-dummy-dai",
  286. }
  287. };
  288. static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev,
  289. int ssp_codec,
  290. int ssp_amp,
  291. int dmic_be_num,
  292. int hdmi_num)
  293. {
  294. struct snd_soc_dai_link_component *idisp_components;
  295. struct snd_soc_dai_link_component *cpus;
  296. struct snd_soc_dai_link *links;
  297. int i, id = 0;
  298. links = devm_kcalloc(dev, sof_audio_card_nau8825.num_links,
  299. sizeof(struct snd_soc_dai_link), GFP_KERNEL);
  300. cpus = devm_kcalloc(dev, sof_audio_card_nau8825.num_links,
  301. sizeof(struct snd_soc_dai_link_component), GFP_KERNEL);
  302. if (!links || !cpus)
  303. goto devm_err;
  304. /* codec SSP */
  305. links[id].name = devm_kasprintf(dev, GFP_KERNEL,
  306. "SSP%d-Codec", ssp_codec);
  307. if (!links[id].name)
  308. goto devm_err;
  309. links[id].id = id;
  310. links[id].codecs = nau8825_component;
  311. links[id].num_codecs = ARRAY_SIZE(nau8825_component);
  312. links[id].platforms = platform_component;
  313. links[id].num_platforms = ARRAY_SIZE(platform_component);
  314. links[id].init = sof_nau8825_codec_init;
  315. links[id].exit = sof_nau8825_codec_exit;
  316. links[id].ops = &sof_nau8825_ops;
  317. links[id].dpcm_playback = 1;
  318. links[id].dpcm_capture = 1;
  319. links[id].no_pcm = 1;
  320. links[id].cpus = &cpus[id];
  321. links[id].num_cpus = 1;
  322. links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
  323. "SSP%d Pin",
  324. ssp_codec);
  325. if (!links[id].cpus->dai_name)
  326. goto devm_err;
  327. id++;
  328. /* dmic */
  329. if (dmic_be_num > 0) {
  330. /* at least we have dmic01 */
  331. links[id].name = "dmic01";
  332. links[id].cpus = &cpus[id];
  333. links[id].cpus->dai_name = "DMIC01 Pin";
  334. links[id].init = dmic_init;
  335. if (dmic_be_num > 1) {
  336. /* set up 2 BE links at most */
  337. links[id + 1].name = "dmic16k";
  338. links[id + 1].cpus = &cpus[id + 1];
  339. links[id + 1].cpus->dai_name = "DMIC16k Pin";
  340. dmic_be_num = 2;
  341. }
  342. }
  343. for (i = 0; i < dmic_be_num; i++) {
  344. links[id].id = id;
  345. links[id].num_cpus = 1;
  346. links[id].codecs = dmic_component;
  347. links[id].num_codecs = ARRAY_SIZE(dmic_component);
  348. links[id].platforms = platform_component;
  349. links[id].num_platforms = ARRAY_SIZE(platform_component);
  350. links[id].ignore_suspend = 1;
  351. links[id].dpcm_capture = 1;
  352. links[id].no_pcm = 1;
  353. id++;
  354. }
  355. /* HDMI */
  356. if (hdmi_num > 0) {
  357. idisp_components = devm_kcalloc(dev,
  358. hdmi_num,
  359. sizeof(struct snd_soc_dai_link_component),
  360. GFP_KERNEL);
  361. if (!idisp_components)
  362. goto devm_err;
  363. }
  364. for (i = 1; i <= hdmi_num; i++) {
  365. links[id].name = devm_kasprintf(dev, GFP_KERNEL,
  366. "iDisp%d", i);
  367. if (!links[id].name)
  368. goto devm_err;
  369. links[id].id = id;
  370. links[id].cpus = &cpus[id];
  371. links[id].num_cpus = 1;
  372. links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
  373. "iDisp%d Pin", i);
  374. if (!links[id].cpus->dai_name)
  375. goto devm_err;
  376. idisp_components[i - 1].name = "ehdaudio0D2";
  377. idisp_components[i - 1].dai_name = devm_kasprintf(dev,
  378. GFP_KERNEL,
  379. "intel-hdmi-hifi%d",
  380. i);
  381. if (!idisp_components[i - 1].dai_name)
  382. goto devm_err;
  383. links[id].codecs = &idisp_components[i - 1];
  384. links[id].num_codecs = 1;
  385. links[id].platforms = platform_component;
  386. links[id].num_platforms = ARRAY_SIZE(platform_component);
  387. links[id].init = sof_hdmi_init;
  388. links[id].dpcm_playback = 1;
  389. links[id].no_pcm = 1;
  390. id++;
  391. }
  392. /* speaker amp */
  393. if (sof_nau8825_quirk & SOF_SPEAKER_AMP_PRESENT) {
  394. links[id].name = devm_kasprintf(dev, GFP_KERNEL,
  395. "SSP%d-Codec", ssp_amp);
  396. if (!links[id].name)
  397. goto devm_err;
  398. links[id].id = id;
  399. if (sof_nau8825_quirk & SOF_RT1019P_SPEAKER_AMP_PRESENT) {
  400. links[id].codecs = rt1019p_component;
  401. links[id].num_codecs = ARRAY_SIZE(rt1019p_component);
  402. links[id].init = speaker_codec_init;
  403. } else if (sof_nau8825_quirk &
  404. SOF_MAX98373_SPEAKER_AMP_PRESENT) {
  405. links[id].codecs = max_98373_components;
  406. links[id].num_codecs = ARRAY_SIZE(max_98373_components);
  407. links[id].init = max_98373_spk_codec_init;
  408. links[id].ops = &max_98373_ops;
  409. } else if (sof_nau8825_quirk &
  410. SOF_MAX98360A_SPEAKER_AMP_PRESENT) {
  411. max_98360a_dai_link(&links[id]);
  412. } else if (sof_nau8825_quirk & SOF_RT1015P_SPEAKER_AMP_PRESENT) {
  413. sof_rt1015p_dai_link(&links[id]);
  414. } else {
  415. goto devm_err;
  416. }
  417. links[id].platforms = platform_component;
  418. links[id].num_platforms = ARRAY_SIZE(platform_component);
  419. links[id].dpcm_playback = 1;
  420. /* feedback stream or firmware-generated echo reference */
  421. links[id].dpcm_capture = 1;
  422. links[id].no_pcm = 1;
  423. links[id].cpus = &cpus[id];
  424. links[id].num_cpus = 1;
  425. links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
  426. "SSP%d Pin",
  427. ssp_amp);
  428. if (!links[id].cpus->dai_name)
  429. goto devm_err;
  430. id++;
  431. }
  432. /* BT audio offload */
  433. if (sof_nau8825_quirk & SOF_SSP_BT_OFFLOAD_PRESENT) {
  434. int port = (sof_nau8825_quirk & SOF_BT_OFFLOAD_SSP_MASK) >>
  435. SOF_BT_OFFLOAD_SSP_SHIFT;
  436. links[id].id = id;
  437. links[id].cpus = &cpus[id];
  438. links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
  439. "SSP%d Pin", port);
  440. if (!links[id].cpus->dai_name)
  441. goto devm_err;
  442. links[id].name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d-BT", port);
  443. if (!links[id].name)
  444. goto devm_err;
  445. links[id].codecs = dummy_component;
  446. links[id].num_codecs = ARRAY_SIZE(dummy_component);
  447. links[id].platforms = platform_component;
  448. links[id].num_platforms = ARRAY_SIZE(platform_component);
  449. links[id].dpcm_playback = 1;
  450. links[id].dpcm_capture = 1;
  451. links[id].no_pcm = 1;
  452. links[id].num_cpus = 1;
  453. }
  454. return links;
  455. devm_err:
  456. return NULL;
  457. }
  458. static int sof_audio_probe(struct platform_device *pdev)
  459. {
  460. struct snd_soc_dai_link *dai_links;
  461. struct snd_soc_acpi_mach *mach;
  462. struct sof_card_private *ctx;
  463. int dmic_be_num, hdmi_num;
  464. int ret, ssp_amp, ssp_codec;
  465. ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
  466. if (!ctx)
  467. return -ENOMEM;
  468. if (pdev->id_entry && pdev->id_entry->driver_data)
  469. sof_nau8825_quirk = (unsigned long)pdev->id_entry->driver_data;
  470. mach = pdev->dev.platform_data;
  471. /* A speaker amp might not be present when the quirk claims one is.
  472. * Detect this via whether the machine driver match includes quirk_data.
  473. */
  474. if ((sof_nau8825_quirk & SOF_SPEAKER_AMP_PRESENT) && !mach->quirk_data)
  475. sof_nau8825_quirk &= ~SOF_SPEAKER_AMP_PRESENT;
  476. dev_dbg(&pdev->dev, "sof_nau8825_quirk = %lx\n", sof_nau8825_quirk);
  477. /* default number of DMIC DAI's */
  478. dmic_be_num = 2;
  479. hdmi_num = (sof_nau8825_quirk & SOF_NAU8825_NUM_HDMIDEV_MASK) >>
  480. SOF_NAU8825_NUM_HDMIDEV_SHIFT;
  481. /* default number of HDMI DAI's */
  482. if (!hdmi_num)
  483. hdmi_num = 3;
  484. ssp_amp = (sof_nau8825_quirk & SOF_NAU8825_SSP_AMP_MASK) >>
  485. SOF_NAU8825_SSP_AMP_SHIFT;
  486. ssp_codec = sof_nau8825_quirk & SOF_NAU8825_SSP_CODEC_MASK;
  487. /* compute number of dai links */
  488. sof_audio_card_nau8825.num_links = 1 + dmic_be_num + hdmi_num;
  489. if (sof_nau8825_quirk & SOF_SPEAKER_AMP_PRESENT)
  490. sof_audio_card_nau8825.num_links++;
  491. if (sof_nau8825_quirk & SOF_MAX98373_SPEAKER_AMP_PRESENT)
  492. max_98373_set_codec_conf(&sof_audio_card_nau8825);
  493. else if (sof_nau8825_quirk & SOF_RT1015P_SPEAKER_AMP_PRESENT)
  494. sof_rt1015p_codec_conf(&sof_audio_card_nau8825);
  495. if (sof_nau8825_quirk & SOF_SSP_BT_OFFLOAD_PRESENT)
  496. sof_audio_card_nau8825.num_links++;
  497. dai_links = sof_card_dai_links_create(&pdev->dev, ssp_codec, ssp_amp,
  498. dmic_be_num, hdmi_num);
  499. if (!dai_links)
  500. return -ENOMEM;
  501. sof_audio_card_nau8825.dai_link = dai_links;
  502. INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
  503. sof_audio_card_nau8825.dev = &pdev->dev;
  504. /* set platform name for each dailink */
  505. ret = snd_soc_fixup_dai_links_platform_name(&sof_audio_card_nau8825,
  506. mach->mach_params.platform);
  507. if (ret)
  508. return ret;
  509. snd_soc_card_set_drvdata(&sof_audio_card_nau8825, ctx);
  510. return devm_snd_soc_register_card(&pdev->dev,
  511. &sof_audio_card_nau8825);
  512. }
  513. static const struct platform_device_id board_ids[] = {
  514. {
  515. .name = "sof_nau8825",
  516. .driver_data = (kernel_ulong_t)(SOF_NAU8825_SSP_CODEC(0) |
  517. SOF_NAU8825_NUM_HDMIDEV(4) |
  518. SOF_BT_OFFLOAD_SSP(2) |
  519. SOF_SSP_BT_OFFLOAD_PRESENT),
  520. },
  521. {
  522. .name = "adl_rt1019p_8825",
  523. .driver_data = (kernel_ulong_t)(SOF_NAU8825_SSP_CODEC(0) |
  524. SOF_SPEAKER_AMP_PRESENT |
  525. SOF_RT1019P_SPEAKER_AMP_PRESENT |
  526. SOF_NAU8825_SSP_AMP(2) |
  527. SOF_NAU8825_NUM_HDMIDEV(4)),
  528. },
  529. {
  530. .name = "adl_max98373_8825",
  531. .driver_data = (kernel_ulong_t)(SOF_NAU8825_SSP_CODEC(0) |
  532. SOF_SPEAKER_AMP_PRESENT |
  533. SOF_MAX98373_SPEAKER_AMP_PRESENT |
  534. SOF_NAU8825_SSP_AMP(1) |
  535. SOF_NAU8825_NUM_HDMIDEV(4) |
  536. SOF_BT_OFFLOAD_SSP(2) |
  537. SOF_SSP_BT_OFFLOAD_PRESENT),
  538. },
  539. {
  540. /* The limitation of length of char array, shorten the name */
  541. .name = "adl_mx98360a_8825",
  542. .driver_data = (kernel_ulong_t)(SOF_NAU8825_SSP_CODEC(0) |
  543. SOF_SPEAKER_AMP_PRESENT |
  544. SOF_MAX98360A_SPEAKER_AMP_PRESENT |
  545. SOF_NAU8825_SSP_AMP(1) |
  546. SOF_NAU8825_NUM_HDMIDEV(4) |
  547. SOF_BT_OFFLOAD_SSP(2) |
  548. SOF_SSP_BT_OFFLOAD_PRESENT),
  549. },
  550. {
  551. .name = "adl_rt1015p_8825",
  552. .driver_data = (kernel_ulong_t)(SOF_NAU8825_SSP_CODEC(0) |
  553. SOF_SPEAKER_AMP_PRESENT |
  554. SOF_RT1015P_SPEAKER_AMP_PRESENT |
  555. SOF_NAU8825_SSP_AMP(1) |
  556. SOF_NAU8825_NUM_HDMIDEV(4) |
  557. SOF_BT_OFFLOAD_SSP(2) |
  558. SOF_SSP_BT_OFFLOAD_PRESENT),
  559. },
  560. { }
  561. };
  562. MODULE_DEVICE_TABLE(platform, board_ids);
  563. static struct platform_driver sof_audio = {
  564. .probe = sof_audio_probe,
  565. .driver = {
  566. .name = "sof_nau8825",
  567. .pm = &snd_soc_pm_ops,
  568. },
  569. .id_table = board_ids,
  570. };
  571. module_platform_driver(sof_audio)
  572. /* Module information */
  573. MODULE_DESCRIPTION("SOF Audio Machine driver for NAU8825");
  574. MODULE_AUTHOR("David Lin <[email protected]>");
  575. MODULE_AUTHOR("Mac Chiang <[email protected]>");
  576. MODULE_LICENSE("GPL");
  577. MODULE_IMPORT_NS(SND_SOC_INTEL_HDA_DSP_COMMON);
  578. MODULE_IMPORT_NS(SND_SOC_INTEL_SOF_MAXIM_COMMON);
  579. MODULE_IMPORT_NS(SND_SOC_INTEL_SOF_REALTEK_COMMON);