Loading...
1// SPDX-License-Identifier: GPL-2.0-only
2// Copyright(c) 2021 Intel Corporation.
3// Copyright(c) 2021 Nuvoton Corporation.
4
5/*
6 * Intel SOF Machine Driver with Nuvoton headphone codec NAU8825
7 * and speaker codec RT1019P MAX98360a or MAX98373
8 */
9#include <linux/i2c.h>
10#include <linux/input.h>
11#include <linux/module.h>
12#include <linux/platform_device.h>
13#include <linux/dmi.h>
14#include <sound/core.h>
15#include <sound/jack.h>
16#include <sound/pcm.h>
17#include <sound/pcm_params.h>
18#include <sound/soc.h>
19#include <sound/sof.h>
20#include <sound/soc-acpi.h>
21#include "../../codecs/nau8825.h"
22#include "../common/soc-intel-quirks.h"
23#include "sof_board_helpers.h"
24#include "sof_realtek_common.h"
25#include "sof_maxim_common.h"
26#include "sof_nuvoton_common.h"
27
28static unsigned long sof_nau8825_quirk = SOF_SSP_PORT_CODEC(0);
29
30static struct snd_soc_jack_pin jack_pins[] = {
31 {
32 .pin = "Headphone Jack",
33 .mask = SND_JACK_HEADPHONE,
34 },
35 {
36 .pin = "Headset Mic",
37 .mask = SND_JACK_MICROPHONE,
38 },
39};
40
41static int sof_nau8825_codec_init(struct snd_soc_pcm_runtime *rtd)
42{
43 struct sof_card_private *ctx = snd_soc_card_get_drvdata(rtd->card);
44 struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component;
45 struct snd_soc_jack *jack = &ctx->headset_jack;
46 int ret;
47
48 /*
49 * Headset buttons map to the google Reference headset.
50 * These can be configured by userspace.
51 */
52 ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack",
53 SND_JACK_HEADSET | SND_JACK_BTN_0 |
54 SND_JACK_BTN_1 | SND_JACK_BTN_2 |
55 SND_JACK_BTN_3,
56 jack,
57 jack_pins,
58 ARRAY_SIZE(jack_pins));
59 if (ret) {
60 dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret);
61 return ret;
62 }
63
64 snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
65 snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
66 snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
67 snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
68
69 ret = snd_soc_component_set_jack(component, jack, NULL);
70 if (ret) {
71 dev_err(rtd->dev, "Headset Jack call-back failed: %d\n", ret);
72 return ret;
73 }
74
75 return ret;
76};
77
78static void sof_nau8825_codec_exit(struct snd_soc_pcm_runtime *rtd)
79{
80 struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component;
81
82 snd_soc_component_set_jack(component, NULL, NULL);
83}
84
85static int sof_nau8825_hw_params(struct snd_pcm_substream *substream,
86 struct snd_pcm_hw_params *params)
87{
88 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
89 struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0);
90 int clk_freq, ret;
91
92 clk_freq = sof_dai_get_bclk(rtd); /* BCLK freq */
93
94 if (clk_freq <= 0) {
95 dev_err(rtd->dev, "get bclk freq failed: %d\n", clk_freq);
96 return -EINVAL;
97 }
98
99 /* Configure clock for codec */
100 ret = snd_soc_dai_set_sysclk(codec_dai, NAU8825_CLK_FLL_BLK, 0,
101 SND_SOC_CLOCK_IN);
102 if (ret < 0) {
103 dev_err(codec_dai->dev, "can't set BCLK clock %d\n", ret);
104 return ret;
105 }
106
107 /* Configure pll for codec */
108 ret = snd_soc_dai_set_pll(codec_dai, 0, 0, clk_freq,
109 params_rate(params) * 256);
110 if (ret < 0) {
111 dev_err(codec_dai->dev, "can't set BCLK: %d\n", ret);
112 return ret;
113 }
114
115 return ret;
116}
117
118static const struct snd_soc_ops sof_nau8825_ops = {
119 .hw_params = sof_nau8825_hw_params,
120};
121
122static int sof_card_late_probe(struct snd_soc_card *card)
123{
124 struct sof_card_private *ctx = snd_soc_card_get_drvdata(card);
125 struct snd_soc_dapm_context *dapm = &card->dapm;
126 int err;
127
128 if (ctx->amp_type == CODEC_MAX98373) {
129 /* Disable Left and Right Spk pin after boot */
130 snd_soc_dapm_disable_pin(dapm, "Left Spk");
131 snd_soc_dapm_disable_pin(dapm, "Right Spk");
132 err = snd_soc_dapm_sync(dapm);
133 if (err < 0)
134 return err;
135 }
136
137 return sof_intel_board_card_late_probe(card);
138}
139
140static const struct snd_kcontrol_new sof_controls[] = {
141 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
142 SOC_DAPM_PIN_SWITCH("Headset Mic"),
143};
144
145static const struct snd_soc_dapm_widget sof_widgets[] = {
146 SND_SOC_DAPM_HP("Headphone Jack", NULL),
147 SND_SOC_DAPM_MIC("Headset Mic", NULL),
148};
149
150static const struct snd_soc_dapm_route sof_map[] = {
151 /* HP jack connectors - unknown if we have jack detection */
152 { "Headphone Jack", NULL, "HPOL" },
153 { "Headphone Jack", NULL, "HPOR" },
154
155 /* other jacks */
156 { "MIC", NULL, "Headset Mic" },
157};
158
159/* sof audio machine driver for nau8825 codec */
160static struct snd_soc_card sof_audio_card_nau8825 = {
161 .name = "nau8825", /* the sof- prefix is added by the core */
162 .owner = THIS_MODULE,
163 .controls = sof_controls,
164 .num_controls = ARRAY_SIZE(sof_controls),
165 .dapm_widgets = sof_widgets,
166 .num_dapm_widgets = ARRAY_SIZE(sof_widgets),
167 .dapm_routes = sof_map,
168 .num_dapm_routes = ARRAY_SIZE(sof_map),
169 .fully_routed = true,
170 .late_probe = sof_card_late_probe,
171};
172
173static struct snd_soc_dai_link_component nau8825_component[] = {
174 {
175 .name = "i2c-10508825:00",
176 .dai_name = "nau8825-hifi",
177 }
178};
179
180static int
181sof_card_dai_links_create(struct device *dev, struct snd_soc_card *card,
182 struct sof_card_private *ctx)
183{
184 int ret;
185
186 ret = sof_intel_board_set_dai_link(dev, card, ctx);
187 if (ret)
188 return ret;
189
190 if (!ctx->codec_link) {
191 dev_err(dev, "codec link not available");
192 return -EINVAL;
193 }
194
195 /* codec-specific fields for headphone codec */
196 ctx->codec_link->codecs = nau8825_component;
197 ctx->codec_link->num_codecs = ARRAY_SIZE(nau8825_component);
198 ctx->codec_link->init = sof_nau8825_codec_init;
199 ctx->codec_link->exit = sof_nau8825_codec_exit;
200 ctx->codec_link->ops = &sof_nau8825_ops;
201
202 if (ctx->amp_type == CODEC_NONE)
203 return 0;
204
205 if (!ctx->amp_link) {
206 dev_err(dev, "amp link not available");
207 return -EINVAL;
208 }
209
210 /* codec-specific fields for speaker amplifier */
211 switch (ctx->amp_type) {
212 case CODEC_MAX98360A:
213 max_98360a_dai_link(ctx->amp_link);
214 break;
215 case CODEC_MAX98373:
216 max_98373_dai_link(dev, ctx->amp_link);
217 break;
218 case CODEC_NAU8318:
219 nau8318_set_dai_link(ctx->amp_link);
220 break;
221 case CODEC_RT1015P:
222 sof_rt1015p_dai_link(ctx->amp_link);
223 break;
224 case CODEC_RT1019P:
225 sof_rt1019p_dai_link(ctx->amp_link);
226 break;
227 default:
228 dev_err(dev, "invalid amp type %d\n", ctx->amp_type);
229 return -EINVAL;
230 }
231
232 return 0;
233}
234
235static int sof_audio_probe(struct platform_device *pdev)
236{
237 struct snd_soc_acpi_mach *mach = pdev->dev.platform_data;
238 struct sof_card_private *ctx;
239 int ret;
240
241 if (pdev->id_entry && pdev->id_entry->driver_data)
242 sof_nau8825_quirk = (unsigned long)pdev->id_entry->driver_data;
243
244 dev_dbg(&pdev->dev, "sof_nau8825_quirk = %lx\n", sof_nau8825_quirk);
245
246 /* initialize ctx with board quirk */
247 ctx = sof_intel_board_get_ctx(&pdev->dev, sof_nau8825_quirk);
248 if (!ctx)
249 return -ENOMEM;
250
251 if (mach->mach_params.codec_mask & IDISP_CODEC_MASK)
252 ctx->hdmi.idisp_codec = true;
253
254 /* update dai_link */
255 ret = sof_card_dai_links_create(&pdev->dev, &sof_audio_card_nau8825, ctx);
256 if (ret)
257 return ret;
258
259 /* update codec_conf */
260 switch (ctx->amp_type) {
261 case CODEC_MAX98373:
262 max_98373_set_codec_conf(&sof_audio_card_nau8825);
263 break;
264 case CODEC_RT1015P:
265 sof_rt1015p_codec_conf(&sof_audio_card_nau8825);
266 break;
267 case CODEC_MAX98360A:
268 case CODEC_NAU8318:
269 case CODEC_RT1019P:
270 case CODEC_NONE:
271 /* no codec conf required */
272 break;
273 default:
274 dev_err(&pdev->dev, "invalid amp type %d\n", ctx->amp_type);
275 return -EINVAL;
276 }
277
278 sof_audio_card_nau8825.dev = &pdev->dev;
279
280 /* set platform name for each dailink */
281 ret = snd_soc_fixup_dai_links_platform_name(&sof_audio_card_nau8825,
282 mach->mach_params.platform);
283 if (ret)
284 return ret;
285
286 snd_soc_card_set_drvdata(&sof_audio_card_nau8825, ctx);
287
288 return devm_snd_soc_register_card(&pdev->dev,
289 &sof_audio_card_nau8825);
290}
291
292static const struct platform_device_id board_ids[] = {
293 {
294 .name = "adl_rt1019p_8825",
295 .driver_data = (kernel_ulong_t)(SOF_SSP_PORT_CODEC(0) |
296 SOF_SSP_PORT_AMP(2) |
297 SOF_NUM_IDISP_HDMI(4)),
298 },
299 {
300 .name = "adl_nau8825_def",
301 .driver_data = (kernel_ulong_t)(SOF_SSP_PORT_CODEC(0) |
302 SOF_SSP_PORT_AMP(1) |
303 SOF_NUM_IDISP_HDMI(4) |
304 SOF_SSP_PORT_BT_OFFLOAD(2) |
305 SOF_BT_OFFLOAD_PRESENT),
306 },
307 {
308 .name = "rpl_nau8825_def",
309 .driver_data = (kernel_ulong_t)(SOF_SSP_PORT_CODEC(0) |
310 SOF_SSP_PORT_AMP(1) |
311 SOF_NUM_IDISP_HDMI(4) |
312 SOF_SSP_PORT_BT_OFFLOAD(2) |
313 SOF_BT_OFFLOAD_PRESENT),
314 },
315 {
316 .name = "mtl_nau8825_def",
317 .driver_data = (kernel_ulong_t)(SOF_SSP_PORT_CODEC(2) |
318 SOF_SSP_PORT_AMP(0) |
319 SOF_SSP_PORT_BT_OFFLOAD(1) |
320 SOF_BT_OFFLOAD_PRESENT),
321 },
322 { }
323};
324MODULE_DEVICE_TABLE(platform, board_ids);
325
326static struct platform_driver sof_audio = {
327 .probe = sof_audio_probe,
328 .driver = {
329 .name = "sof_nau8825",
330 .pm = &snd_soc_pm_ops,
331 },
332 .id_table = board_ids,
333};
334module_platform_driver(sof_audio)
335
336/* Module information */
337MODULE_DESCRIPTION("SOF Audio Machine driver for NAU8825");
338MODULE_AUTHOR("David Lin <ctlin0@nuvoton.com>");
339MODULE_AUTHOR("Mac Chiang <mac.chiang@intel.com>");
340MODULE_AUTHOR("Brent Lu <brent.lu@intel.com>");
341MODULE_LICENSE("GPL");
342MODULE_IMPORT_NS("SND_SOC_INTEL_SOF_BOARD_HELPERS");
343MODULE_IMPORT_NS("SND_SOC_INTEL_SOF_MAXIM_COMMON");
344MODULE_IMPORT_NS("SND_SOC_INTEL_SOF_NUVOTON_COMMON");
345MODULE_IMPORT_NS("SND_SOC_INTEL_SOF_REALTEK_COMMON");
1// SPDX-License-Identifier: GPL-2.0-only
2// Copyright(c) 2021 Intel Corporation.
3// Copyright(c) 2021 Nuvoton Corporation.
4
5/*
6 * Intel SOF Machine Driver with Nuvoton headphone codec NAU8825
7 * and speaker codec RT1019P MAX98360a or MAX98373
8 */
9#include <linux/i2c.h>
10#include <linux/input.h>
11#include <linux/module.h>
12#include <linux/platform_device.h>
13#include <linux/dmi.h>
14#include <sound/core.h>
15#include <sound/jack.h>
16#include <sound/pcm.h>
17#include <sound/pcm_params.h>
18#include <sound/soc.h>
19#include <sound/sof.h>
20#include <sound/soc-acpi.h>
21#include "../../codecs/nau8825.h"
22#include "../common/soc-intel-quirks.h"
23#include "sof_board_helpers.h"
24#include "sof_realtek_common.h"
25#include "sof_maxim_common.h"
26#include "sof_nuvoton_common.h"
27#include "sof_ssp_common.h"
28
29#define SOF_NAU8825_SSP_CODEC(quirk) ((quirk) & GENMASK(2, 0))
30#define SOF_NAU8825_SSP_CODEC_MASK (GENMASK(2, 0))
31#define SOF_NAU8825_SSP_AMP_SHIFT 4
32#define SOF_NAU8825_SSP_AMP_MASK (GENMASK(6, 4))
33#define SOF_NAU8825_SSP_AMP(quirk) \
34 (((quirk) << SOF_NAU8825_SSP_AMP_SHIFT) & SOF_NAU8825_SSP_AMP_MASK)
35#define SOF_NAU8825_NUM_HDMIDEV_SHIFT 7
36#define SOF_NAU8825_NUM_HDMIDEV_MASK (GENMASK(9, 7))
37#define SOF_NAU8825_NUM_HDMIDEV(quirk) \
38 (((quirk) << SOF_NAU8825_NUM_HDMIDEV_SHIFT) & SOF_NAU8825_NUM_HDMIDEV_MASK)
39
40/* BT audio offload: reserve 3 bits for future */
41#define SOF_BT_OFFLOAD_SSP_SHIFT 10
42#define SOF_BT_OFFLOAD_SSP_MASK (GENMASK(12, 10))
43#define SOF_BT_OFFLOAD_SSP(quirk) \
44 (((quirk) << SOF_BT_OFFLOAD_SSP_SHIFT) & SOF_BT_OFFLOAD_SSP_MASK)
45#define SOF_SSP_BT_OFFLOAD_PRESENT BIT(13)
46
47static unsigned long sof_nau8825_quirk = SOF_NAU8825_SSP_CODEC(0);
48
49static struct snd_soc_jack_pin jack_pins[] = {
50 {
51 .pin = "Headphone Jack",
52 .mask = SND_JACK_HEADPHONE,
53 },
54 {
55 .pin = "Headset Mic",
56 .mask = SND_JACK_MICROPHONE,
57 },
58};
59
60static int sof_nau8825_codec_init(struct snd_soc_pcm_runtime *rtd)
61{
62 struct sof_card_private *ctx = snd_soc_card_get_drvdata(rtd->card);
63 struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component;
64 struct snd_soc_jack *jack = &ctx->headset_jack;
65 int ret;
66
67 /*
68 * Headset buttons map to the google Reference headset.
69 * These can be configured by userspace.
70 */
71 ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack",
72 SND_JACK_HEADSET | SND_JACK_BTN_0 |
73 SND_JACK_BTN_1 | SND_JACK_BTN_2 |
74 SND_JACK_BTN_3,
75 jack,
76 jack_pins,
77 ARRAY_SIZE(jack_pins));
78 if (ret) {
79 dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret);
80 return ret;
81 }
82
83 snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
84 snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
85 snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
86 snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
87
88 ret = snd_soc_component_set_jack(component, jack, NULL);
89 if (ret) {
90 dev_err(rtd->dev, "Headset Jack call-back failed: %d\n", ret);
91 return ret;
92 }
93
94 return ret;
95};
96
97static void sof_nau8825_codec_exit(struct snd_soc_pcm_runtime *rtd)
98{
99 struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component;
100
101 snd_soc_component_set_jack(component, NULL, NULL);
102}
103
104static int sof_nau8825_hw_params(struct snd_pcm_substream *substream,
105 struct snd_pcm_hw_params *params)
106{
107 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
108 struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0);
109 int clk_freq, ret;
110
111 clk_freq = sof_dai_get_bclk(rtd); /* BCLK freq */
112
113 if (clk_freq <= 0) {
114 dev_err(rtd->dev, "get bclk freq failed: %d\n", clk_freq);
115 return -EINVAL;
116 }
117
118 /* Configure clock for codec */
119 ret = snd_soc_dai_set_sysclk(codec_dai, NAU8825_CLK_FLL_BLK, 0,
120 SND_SOC_CLOCK_IN);
121 if (ret < 0) {
122 dev_err(codec_dai->dev, "can't set BCLK clock %d\n", ret);
123 return ret;
124 }
125
126 /* Configure pll for codec */
127 ret = snd_soc_dai_set_pll(codec_dai, 0, 0, clk_freq,
128 params_rate(params) * 256);
129 if (ret < 0) {
130 dev_err(codec_dai->dev, "can't set BCLK: %d\n", ret);
131 return ret;
132 }
133
134 return ret;
135}
136
137static struct snd_soc_ops sof_nau8825_ops = {
138 .hw_params = sof_nau8825_hw_params,
139};
140
141static int sof_card_late_probe(struct snd_soc_card *card)
142{
143 struct sof_card_private *ctx = snd_soc_card_get_drvdata(card);
144 struct snd_soc_dapm_context *dapm = &card->dapm;
145 int err;
146
147 if (ctx->amp_type == CODEC_MAX98373) {
148 /* Disable Left and Right Spk pin after boot */
149 snd_soc_dapm_disable_pin(dapm, "Left Spk");
150 snd_soc_dapm_disable_pin(dapm, "Right Spk");
151 err = snd_soc_dapm_sync(dapm);
152 if (err < 0)
153 return err;
154 }
155
156 return sof_intel_board_card_late_probe(card);
157}
158
159static const struct snd_kcontrol_new sof_controls[] = {
160 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
161 SOC_DAPM_PIN_SWITCH("Headset Mic"),
162 SOC_DAPM_PIN_SWITCH("Left Spk"),
163 SOC_DAPM_PIN_SWITCH("Right Spk"),
164};
165
166static const struct snd_soc_dapm_widget sof_widgets[] = {
167 SND_SOC_DAPM_HP("Headphone Jack", NULL),
168 SND_SOC_DAPM_MIC("Headset Mic", NULL),
169 SND_SOC_DAPM_SPK("Left Spk", NULL),
170 SND_SOC_DAPM_SPK("Right Spk", NULL),
171};
172
173static const struct snd_soc_dapm_route sof_map[] = {
174 /* HP jack connectors - unknown if we have jack detection */
175 { "Headphone Jack", NULL, "HPOL" },
176 { "Headphone Jack", NULL, "HPOR" },
177
178 /* other jacks */
179 { "MIC", NULL, "Headset Mic" },
180};
181
182/* sof audio machine driver for nau8825 codec */
183static struct snd_soc_card sof_audio_card_nau8825 = {
184 .name = "nau8825", /* the sof- prefix is added by the core */
185 .owner = THIS_MODULE,
186 .controls = sof_controls,
187 .num_controls = ARRAY_SIZE(sof_controls),
188 .dapm_widgets = sof_widgets,
189 .num_dapm_widgets = ARRAY_SIZE(sof_widgets),
190 .dapm_routes = sof_map,
191 .num_dapm_routes = ARRAY_SIZE(sof_map),
192 .fully_routed = true,
193 .late_probe = sof_card_late_probe,
194};
195
196static struct snd_soc_dai_link_component nau8825_component[] = {
197 {
198 .name = "i2c-10508825:00",
199 .dai_name = "nau8825-hifi",
200 }
201};
202
203static int
204sof_card_dai_links_create(struct device *dev, struct snd_soc_card *card,
205 struct sof_card_private *ctx)
206{
207 int ret;
208
209 ret = sof_intel_board_set_dai_link(dev, card, ctx);
210 if (ret)
211 return ret;
212
213 if (!ctx->codec_link) {
214 dev_err(dev, "codec link not available");
215 return -EINVAL;
216 }
217
218 /* codec-specific fields for headphone codec */
219 ctx->codec_link->codecs = nau8825_component;
220 ctx->codec_link->num_codecs = ARRAY_SIZE(nau8825_component);
221 ctx->codec_link->init = sof_nau8825_codec_init;
222 ctx->codec_link->exit = sof_nau8825_codec_exit;
223 ctx->codec_link->ops = &sof_nau8825_ops;
224
225 if (ctx->amp_type == CODEC_NONE)
226 return 0;
227
228 if (!ctx->amp_link) {
229 dev_err(dev, "amp link not available");
230 return -EINVAL;
231 }
232
233 /* codec-specific fields for speaker amplifier */
234 switch (ctx->amp_type) {
235 case CODEC_MAX98360A:
236 max_98360a_dai_link(ctx->amp_link);
237 break;
238 case CODEC_MAX98373:
239 ctx->amp_link->codecs = max_98373_components;
240 ctx->amp_link->num_codecs = ARRAY_SIZE(max_98373_components);
241 ctx->amp_link->init = max_98373_spk_codec_init;
242 ctx->amp_link->ops = &max_98373_ops;
243 break;
244 case CODEC_NAU8318:
245 nau8318_set_dai_link(ctx->amp_link);
246 break;
247 case CODEC_RT1015P:
248 sof_rt1015p_dai_link(ctx->amp_link);
249 break;
250 case CODEC_RT1019P:
251 sof_rt1019p_dai_link(ctx->amp_link);
252 break;
253 default:
254 dev_err(dev, "invalid amp type %d\n", ctx->amp_type);
255 return -EINVAL;
256 }
257
258 return 0;
259}
260
261static int sof_audio_probe(struct platform_device *pdev)
262{
263 struct snd_soc_acpi_mach *mach = pdev->dev.platform_data;
264 struct sof_card_private *ctx;
265 int ret;
266
267 ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
268 if (!ctx)
269 return -ENOMEM;
270
271 if (pdev->id_entry && pdev->id_entry->driver_data)
272 sof_nau8825_quirk = (unsigned long)pdev->id_entry->driver_data;
273
274 ctx->codec_type = sof_ssp_detect_codec_type(&pdev->dev);
275 ctx->amp_type = sof_ssp_detect_amp_type(&pdev->dev);
276
277 dev_dbg(&pdev->dev, "sof_nau8825_quirk = %lx\n", sof_nau8825_quirk);
278
279 /* default number of DMIC DAI's */
280 ctx->dmic_be_num = 2;
281 ctx->hdmi_num = (sof_nau8825_quirk & SOF_NAU8825_NUM_HDMIDEV_MASK) >>
282 SOF_NAU8825_NUM_HDMIDEV_SHIFT;
283 /* default number of HDMI DAI's */
284 if (!ctx->hdmi_num)
285 ctx->hdmi_num = 3;
286
287 if (mach->mach_params.codec_mask & IDISP_CODEC_MASK)
288 ctx->hdmi.idisp_codec = true;
289
290 /* port number of peripherals attached to ssp interface */
291 ctx->ssp_bt = (sof_nau8825_quirk & SOF_BT_OFFLOAD_SSP_MASK) >>
292 SOF_BT_OFFLOAD_SSP_SHIFT;
293
294 ctx->ssp_amp = (sof_nau8825_quirk & SOF_NAU8825_SSP_AMP_MASK) >>
295 SOF_NAU8825_SSP_AMP_SHIFT;
296
297 ctx->ssp_codec = sof_nau8825_quirk & SOF_NAU8825_SSP_CODEC_MASK;
298
299 if (sof_nau8825_quirk & SOF_SSP_BT_OFFLOAD_PRESENT)
300 ctx->bt_offload_present = true;
301
302 /* update dai_link */
303 ret = sof_card_dai_links_create(&pdev->dev, &sof_audio_card_nau8825, ctx);
304 if (ret)
305 return ret;
306
307 /* update codec_conf */
308 switch (ctx->amp_type) {
309 case CODEC_MAX98373:
310 max_98373_set_codec_conf(&sof_audio_card_nau8825);
311 break;
312 case CODEC_RT1015P:
313 sof_rt1015p_codec_conf(&sof_audio_card_nau8825);
314 break;
315 case CODEC_NONE:
316 case CODEC_MAX98360A:
317 case CODEC_NAU8318:
318 case CODEC_RT1019P:
319 /* no codec conf required */
320 break;
321 default:
322 dev_err(&pdev->dev, "invalid amp type %d\n", ctx->amp_type);
323 return -EINVAL;
324 }
325
326 sof_audio_card_nau8825.dev = &pdev->dev;
327
328 /* set platform name for each dailink */
329 ret = snd_soc_fixup_dai_links_platform_name(&sof_audio_card_nau8825,
330 mach->mach_params.platform);
331 if (ret)
332 return ret;
333
334 snd_soc_card_set_drvdata(&sof_audio_card_nau8825, ctx);
335
336 return devm_snd_soc_register_card(&pdev->dev,
337 &sof_audio_card_nau8825);
338}
339
340static const struct platform_device_id board_ids[] = {
341 {
342 .name = "sof_nau8825",
343 .driver_data = (kernel_ulong_t)(SOF_NAU8825_SSP_CODEC(0) |
344 SOF_NAU8825_NUM_HDMIDEV(4) |
345 SOF_BT_OFFLOAD_SSP(2) |
346 SOF_SSP_BT_OFFLOAD_PRESENT),
347
348 },
349 {
350 .name = "adl_rt1019p_8825",
351 .driver_data = (kernel_ulong_t)(SOF_NAU8825_SSP_CODEC(0) |
352 SOF_NAU8825_SSP_AMP(2) |
353 SOF_NAU8825_NUM_HDMIDEV(4)),
354 },
355 {
356 .name = "adl_nau8825_def",
357 .driver_data = (kernel_ulong_t)(SOF_NAU8825_SSP_CODEC(0) |
358 SOF_NAU8825_SSP_AMP(1) |
359 SOF_NAU8825_NUM_HDMIDEV(4) |
360 SOF_BT_OFFLOAD_SSP(2) |
361 SOF_SSP_BT_OFFLOAD_PRESENT),
362 },
363 {
364 .name = "rpl_nau8825_def",
365 .driver_data = (kernel_ulong_t)(SOF_NAU8825_SSP_CODEC(0) |
366 SOF_NAU8825_SSP_AMP(1) |
367 SOF_NAU8825_NUM_HDMIDEV(4) |
368 SOF_BT_OFFLOAD_SSP(2) |
369 SOF_SSP_BT_OFFLOAD_PRESENT),
370 },
371 { }
372};
373MODULE_DEVICE_TABLE(platform, board_ids);
374
375static struct platform_driver sof_audio = {
376 .probe = sof_audio_probe,
377 .driver = {
378 .name = "sof_nau8825",
379 .pm = &snd_soc_pm_ops,
380 },
381 .id_table = board_ids,
382};
383module_platform_driver(sof_audio)
384
385/* Module information */
386MODULE_DESCRIPTION("SOF Audio Machine driver for NAU8825");
387MODULE_AUTHOR("David Lin <ctlin0@nuvoton.com>");
388MODULE_AUTHOR("Mac Chiang <mac.chiang@intel.com>");
389MODULE_AUTHOR("Brent Lu <brent.lu@intel.com>");
390MODULE_LICENSE("GPL");
391MODULE_IMPORT_NS(SND_SOC_INTEL_SOF_BOARD_HELPERS);
392MODULE_IMPORT_NS(SND_SOC_INTEL_SOF_MAXIM_COMMON);
393MODULE_IMPORT_NS(SND_SOC_INTEL_SOF_NUVOTON_COMMON);
394MODULE_IMPORT_NS(SND_SOC_INTEL_SOF_REALTEK_COMMON);
395MODULE_IMPORT_NS(SND_SOC_INTEL_SOF_SSP_COMMON);