| 1 |
// SPDX-License-Identifier: GPL-2.0+ |
| 2 |
// |
| 3 |
// Machine driver for AMD ACP Audio engine using DA7219 & MAX98357 codec. |
| 4 |
// |
| 5 |
//Copyright 2016 Advanced Micro Devices, Inc. |
| 6 |
|
| 7 |
#include <sound/core.h> |
| 8 |
#include <sound/soc.h> |
| 9 |
#include <sound/pcm.h> |
| 10 |
#include <sound/pcm_params.h> |
| 11 |
#include <sound/soc-dapm.h> |
| 12 |
#include <sound/jack.h> |
| 13 |
#include <linux/clk.h> |
| 14 |
#include <linux/gpio.h> |
| 15 |
#include <linux/gpio/consumer.h> |
| 16 |
#include <linux/module.h> |
| 17 |
#include <linux/i2c.h> |
| 18 |
#include <linux/input.h> |
| 19 |
#include <linux/io.h> |
| 20 |
#include <linux/acpi.h> |
| 21 |
|
| 22 |
#include "raven/acp3x.h" |
| 23 |
#include "../codecs/rt5682.h" |
| 24 |
#include "../codecs/rt1015.h" |
| 25 |
|
| 26 |
#define PCO_PLAT_CLK 48000000 |
| 27 |
#define RT5682_PLL_FREQ (48000 * 512) |
| 28 |
#define DUAL_CHANNEL 2 |
| 29 |
|
| 30 |
static struct snd_soc_jack pco_jack; |
| 31 |
static struct snd_soc_jack_pin pco_jack_pins[] = { |
| 32 |
{ |
| 33 |
.pin = "Headphone Jack", |
| 34 |
.mask = SND_JACK_HEADPHONE, |
| 35 |
}, |
| 36 |
{ |
| 37 |
.pin = "Headset Mic", |
| 38 |
.mask = SND_JACK_MICROPHONE, |
| 39 |
}, |
| 40 |
}; |
| 41 |
|
| 42 |
static struct clk *rt5682_dai_wclk; |
| 43 |
static struct clk *rt5682_dai_bclk; |
| 44 |
static struct gpio_desc *dmic_sel; |
| 45 |
void *soc_is_rltk_max(struct device *dev); |
| 46 |
|
| 47 |
enum { |
| 48 |
RT5682 = 0, |
| 49 |
MAX, |
| 50 |
EC, |
| 51 |
}; |
| 52 |
|
| 53 |
static int acp3x_5682_init(struct snd_soc_pcm_runtime *rtd) |
| 54 |
{ |
| 55 |
int ret; |
| 56 |
struct snd_soc_card *card = rtd->card; |
| 57 |
struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0); |
| 58 |
struct snd_soc_component *component = codec_dai->component; |
| 59 |
|
| 60 |
dev_info(rtd->dev, "codec dai name = %s\n", codec_dai->name); |
| 61 |
|
| 62 |
/* set rt5682 dai fmt */ |
| 63 |
ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
| 64 |
| SND_SOC_DAIFMT_NB_NF |
| 65 |
| SND_SOC_DAIFMT_CBP_CFP); |
| 66 |
if (ret < 0) { |
| 67 |
dev_err(rtd->card->dev, |
| 68 |
"Failed to set rt5682 dai fmt: %d\n", ret); |
| 69 |
return ret; |
| 70 |
} |
| 71 |
|
| 72 |
/* set codec PLL */ |
| 73 |
ret = snd_soc_dai_set_pll(codec_dai, RT5682_PLL2, RT5682_PLL2_S_MCLK, |
| 74 |
PCO_PLAT_CLK, RT5682_PLL_FREQ); |
| 75 |
if (ret < 0) { |
| 76 |
dev_err(rtd->dev, "can't set rt5682 PLL: %d\n", ret); |
| 77 |
return ret; |
| 78 |
} |
| 79 |
|
| 80 |
/* Set codec sysclk */ |
| 81 |
ret = snd_soc_dai_set_sysclk(codec_dai, RT5682_SCLK_S_PLL2, |
| 82 |
RT5682_PLL_FREQ, SND_SOC_CLOCK_IN); |
| 83 |
if (ret < 0) { |
| 84 |
dev_err(rtd->dev, |
| 85 |
"Failed to set rt5682 SYSCLK: %d\n", ret); |
| 86 |
return ret; |
| 87 |
} |
| 88 |
|
| 89 |
/* Set tdm/i2s1 master bclk ratio */ |
| 90 |
ret = snd_soc_dai_set_bclk_ratio(codec_dai, 64); |
| 91 |
if (ret < 0) { |
| 92 |
dev_err(rtd->dev, |
| 93 |
"Failed to set rt5682 tdm bclk ratio: %d\n", ret); |
| 94 |
return ret; |
| 95 |
} |
| 96 |
|
| 97 |
rt5682_dai_wclk = devm_clk_get(component->dev, "rt5682-dai-wclk"); |
| 98 |
if (IS_ERR(rt5682_dai_wclk)) |
| 99 |
return PTR_ERR(rt5682_dai_wclk); |
| 100 |
|
| 101 |
rt5682_dai_bclk = devm_clk_get(component->dev, "rt5682-dai-bclk"); |
| 102 |
if (IS_ERR(rt5682_dai_bclk)) |
| 103 |
return PTR_ERR(rt5682_dai_bclk); |
| 104 |
|
| 105 |
ret = snd_soc_card_jack_new_pins(card, "Headset Jack", |
| 106 |
SND_JACK_HEADSET | |
| 107 |
SND_JACK_BTN_0 | SND_JACK_BTN_1 | |
| 108 |
SND_JACK_BTN_2 | SND_JACK_BTN_3, |
| 109 |
&pco_jack, |
| 110 |
pco_jack_pins, |
| 111 |
ARRAY_SIZE(pco_jack_pins)); |
| 112 |
if (ret) { |
| 113 |
dev_err(card->dev, "HP jack creation failed %d\n", ret); |
| 114 |
return ret; |
| 115 |
} |
| 116 |
|
| 117 |
snd_jack_set_key(pco_jack.jack, SND_JACK_BTN_0, KEY_PLAYPAUSE); |
| 118 |
snd_jack_set_key(pco_jack.jack, SND_JACK_BTN_1, KEY_VOICECOMMAND); |
| 119 |
snd_jack_set_key(pco_jack.jack, SND_JACK_BTN_2, KEY_VOLUMEUP); |
| 120 |
snd_jack_set_key(pco_jack.jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN); |
| 121 |
|
| 122 |
ret = snd_soc_component_set_jack(component, &pco_jack, NULL); |
| 123 |
if (ret) { |
| 124 |
dev_err(rtd->dev, "Headset Jack call-back failed: %d\n", ret); |
| 125 |
return ret; |
| 126 |
} |
| 127 |
|
| 128 |
return ret; |
| 129 |
} |
| 130 |
|
| 131 |
static int rt5682_clk_enable(struct snd_pcm_substream *substream) |
| 132 |
{ |
| 133 |
int ret = 0; |
| 134 |
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); |
| 135 |
|
| 136 |
/* RT5682 will support only 48K output with 48M mclk */ |
| 137 |
clk_set_rate(rt5682_dai_wclk, 48000); |
| 138 |
clk_set_rate(rt5682_dai_bclk, 48000 * 64); |
| 139 |
ret = clk_prepare_enable(rt5682_dai_wclk); |
| 140 |
if (ret < 0) { |
| 141 |
dev_err(rtd->dev, "can't enable wclk %d\n", ret); |
| 142 |
return ret; |
| 143 |
} |
| 144 |
|
| 145 |
return ret; |
| 146 |
} |
| 147 |
|
| 148 |
static int acp3x_1015_hw_params(struct snd_pcm_substream *substream, |
| 149 |
struct snd_pcm_hw_params *params) |
| 150 |
{ |
| 151 |
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); |
| 152 |
struct snd_soc_dai *codec_dai; |
| 153 |
int srate, i, ret; |
| 154 |
|
| 155 |
ret = 0; |
| 156 |
srate = params_rate(params); |
| 157 |
|
| 158 |
for_each_rtd_codec_dais(rtd, i, codec_dai) { |
| 159 |
if (strcmp(codec_dai->name, "rt1015-aif")) |
| 160 |
continue; |
| 161 |
|
| 162 |
ret = snd_soc_dai_set_pll(codec_dai, 0, RT1015_PLL_S_BCLK, |
| 163 |
64 * srate, 256 * srate); |
| 164 |
if (ret < 0) |
| 165 |
return ret; |
| 166 |
ret = snd_soc_dai_set_sysclk(codec_dai, RT1015_SCLK_S_PLL, |
| 167 |
256 * srate, SND_SOC_CLOCK_IN); |
| 168 |
if (ret < 0) |
| 169 |
return ret; |
| 170 |
} |
| 171 |
return ret; |
| 172 |
} |
| 173 |
|
| 174 |
static void rt5682_clk_disable(void) |
| 175 |
{ |
| 176 |
clk_disable_unprepare(rt5682_dai_wclk); |
| 177 |
} |
| 178 |
|
| 179 |
static const unsigned int channels[] = { |
| 180 |
DUAL_CHANNEL, |
| 181 |
}; |
| 182 |
|
| 183 |
static const unsigned int rates[] = { |
| 184 |
48000, |
| 185 |
}; |
| 186 |
|
| 187 |
static const struct snd_pcm_hw_constraint_list constraints_rates = { |
| 188 |
.count = ARRAY_SIZE(rates), |
| 189 |
.list = rates, |
| 190 |
.mask = 0, |
| 191 |
}; |
| 192 |
|
| 193 |
static const struct snd_pcm_hw_constraint_list constraints_channels = { |
| 194 |
.count = ARRAY_SIZE(channels), |
| 195 |
.list = channels, |
| 196 |
.mask = 0, |
| 197 |
}; |
| 198 |
|
| 199 |
static int acp3x_5682_startup(struct snd_pcm_substream *substream) |
| 200 |
{ |
| 201 |
struct snd_pcm_runtime *runtime = substream->runtime; |
| 202 |
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); |
| 203 |
struct snd_soc_card *card = rtd->card; |
| 204 |
struct acp3x_platform_info *machine = snd_soc_card_get_drvdata(card); |
| 205 |
|
| 206 |
machine->play_i2s_instance = I2S_SP_INSTANCE; |
| 207 |
machine->cap_i2s_instance = I2S_SP_INSTANCE; |
| 208 |
|
| 209 |
runtime->hw.channels_max = DUAL_CHANNEL; |
| 210 |
snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, |
| 211 |
&constraints_channels); |
| 212 |
snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
| 213 |
&constraints_rates); |
| 214 |
return rt5682_clk_enable(substream); |
| 215 |
} |
| 216 |
|
| 217 |
static int acp3x_max_startup(struct snd_pcm_substream *substream) |
| 218 |
{ |
| 219 |
struct snd_pcm_runtime *runtime = substream->runtime; |
| 220 |
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); |
| 221 |
struct snd_soc_card *card = rtd->card; |
| 222 |
struct acp3x_platform_info *machine = snd_soc_card_get_drvdata(card); |
| 223 |
|
| 224 |
machine->play_i2s_instance = I2S_BT_INSTANCE; |
| 225 |
|
| 226 |
runtime->hw.channels_max = DUAL_CHANNEL; |
| 227 |
snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, |
| 228 |
&constraints_channels); |
| 229 |
snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
| 230 |
&constraints_rates); |
| 231 |
return rt5682_clk_enable(substream); |
| 232 |
} |
| 233 |
|
| 234 |
static int acp3x_ec_dmic0_startup(struct snd_pcm_substream *substream) |
| 235 |
{ |
| 236 |
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); |
| 237 |
struct snd_soc_card *card = rtd->card; |
| 238 |
struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0); |
| 239 |
struct acp3x_platform_info *machine = snd_soc_card_get_drvdata(card); |
| 240 |
|
| 241 |
machine->cap_i2s_instance = I2S_BT_INSTANCE; |
| 242 |
snd_soc_dai_set_bclk_ratio(codec_dai, 64); |
| 243 |
|
| 244 |
return rt5682_clk_enable(substream); |
| 245 |
} |
| 246 |
|
| 247 |
static int dmic_switch; |
| 248 |
|
| 249 |
static int dmic_get(struct snd_kcontrol *kcontrol, |
| 250 |
struct snd_ctl_elem_value *ucontrol) |
| 251 |
{ |
| 252 |
ucontrol->value.integer.value[0] = dmic_switch; |
| 253 |
return 0; |
| 254 |
} |
| 255 |
|
| 256 |
static int dmic_set(struct snd_kcontrol *kcontrol, |
| 257 |
struct snd_ctl_elem_value *ucontrol) |
| 258 |
{ |
| 259 |
if (dmic_sel) { |
| 260 |
dmic_switch = ucontrol->value.integer.value[0]; |
| 261 |
gpiod_set_value(dmic_sel, dmic_switch); |
| 262 |
} |
| 263 |
return 0; |
| 264 |
} |
| 265 |
|
| 266 |
static void rt5682_shutdown(struct snd_pcm_substream *substream) |
| 267 |
{ |
| 268 |
rt5682_clk_disable(); |
| 269 |
} |
| 270 |
|
| 271 |
static const struct snd_soc_ops acp3x_5682_ops = { |
| 272 |
.startup = acp3x_5682_startup, |
| 273 |
.shutdown = rt5682_shutdown, |
| 274 |
}; |
| 275 |
|
| 276 |
static const struct snd_soc_ops acp3x_max_play_ops = { |
| 277 |
.startup = acp3x_max_startup, |
| 278 |
.shutdown = rt5682_shutdown, |
| 279 |
.hw_params = acp3x_1015_hw_params, |
| 280 |
}; |
| 281 |
|
| 282 |
static const struct snd_soc_ops acp3x_ec_cap0_ops = { |
| 283 |
.startup = acp3x_ec_dmic0_startup, |
| 284 |
.shutdown = rt5682_shutdown, |
| 285 |
}; |
| 286 |
|
| 287 |
SND_SOC_DAILINK_DEF(acp3x_i2s, |
| 288 |
DAILINK_COMP_ARRAY(COMP_CPU("acp3x_i2s_playcap.0"))); |
| 289 |
SND_SOC_DAILINK_DEF(acp3x_bt, |
| 290 |
DAILINK_COMP_ARRAY(COMP_CPU("acp3x_i2s_playcap.2"))); |
| 291 |
|
| 292 |
SND_SOC_DAILINK_DEF(rt5682, |
| 293 |
DAILINK_COMP_ARRAY(COMP_CODEC("i2c-10EC5682:00", "rt5682-aif1"))); |
| 294 |
SND_SOC_DAILINK_DEF(max, |
| 295 |
DAILINK_COMP_ARRAY(COMP_CODEC("MX98357A:00", "HiFi"))); |
| 296 |
SND_SOC_DAILINK_DEF(rt1015p, |
| 297 |
DAILINK_COMP_ARRAY(COMP_CODEC("RTL1015:00", "HiFi"))); |
| 298 |
SND_SOC_DAILINK_DEF(rt1015, |
| 299 |
DAILINK_COMP_ARRAY(COMP_CODEC("i2c-10EC1015:00", "rt1015-aif"), |
| 300 |
COMP_CODEC("i2c-10EC1015:01", "rt1015-aif"))); |
| 301 |
SND_SOC_DAILINK_DEF(cros_ec, |
| 302 |
DAILINK_COMP_ARRAY(COMP_CODEC("GOOG0013:00", "EC Codec I2S RX"))); |
| 303 |
|
| 304 |
SND_SOC_DAILINK_DEF(platform, |
| 305 |
DAILINK_COMP_ARRAY(COMP_PLATFORM("acp3x_rv_i2s_dma.0"))); |
| 306 |
|
| 307 |
static struct snd_soc_codec_conf rt1015_conf[] = { |
| 308 |
{ |
| 309 |
.dlc = COMP_CODEC_CONF("i2c-10EC1015:00"), |
| 310 |
.name_prefix = "Left", |
| 311 |
}, |
| 312 |
{ |
| 313 |
.dlc = COMP_CODEC_CONF("i2c-10EC1015:01"), |
| 314 |
.name_prefix = "Right", |
| 315 |
}, |
| 316 |
}; |
| 317 |
|
| 318 |
static struct snd_soc_dai_link acp3x_dai[] = { |
| 319 |
[RT5682] = { |
| 320 |
.name = "acp3x-5682-play", |
| 321 |
.stream_name = "Playback", |
| 322 |
.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
| 323 |
| SND_SOC_DAIFMT_CBP_CFP, |
| 324 |
.init = acp3x_5682_init, |
| 325 |
.ops = &acp3x_5682_ops, |
| 326 |
SND_SOC_DAILINK_REG(acp3x_i2s, rt5682, platform), |
| 327 |
}, |
| 328 |
[MAX] = { |
| 329 |
.name = "acp3x-max98357-play", |
| 330 |
.stream_name = "HiFi Playback", |
| 331 |
.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
| 332 |
| SND_SOC_DAIFMT_CBC_CFC, |
| 333 |
.playback_only = 1, |
| 334 |
.ops = &acp3x_max_play_ops, |
| 335 |
.cpus = acp3x_bt, |
| 336 |
.num_cpus = ARRAY_SIZE(acp3x_bt), |
| 337 |
.platforms = platform, |
| 338 |
.num_platforms = ARRAY_SIZE(platform), |
| 339 |
}, |
| 340 |
[EC] = { |
| 341 |
.name = "acp3x-ec-dmic0-capture", |
| 342 |
.stream_name = "Capture DMIC0", |
| 343 |
.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
| 344 |
| SND_SOC_DAIFMT_CBC_CFC, |
| 345 |
.capture_only = 1, |
| 346 |
.ops = &acp3x_ec_cap0_ops, |
| 347 |
SND_SOC_DAILINK_REG(acp3x_bt, cros_ec, platform), |
| 348 |
}, |
| 349 |
}; |
| 350 |
|
| 351 |
static const char * const dmic_mux_text[] = { |
| 352 |
"Front Mic", |
| 353 |
"Rear Mic", |
| 354 |
}; |
| 355 |
|
| 356 |
static SOC_ENUM_SINGLE_DECL( |
| 357 |
acp3x_dmic_enum, SND_SOC_NOPM, 0, dmic_mux_text); |
| 358 |
|
| 359 |
static const struct snd_kcontrol_new acp3x_dmic_mux_control = |
| 360 |
SOC_DAPM_ENUM_EXT("DMIC Select Mux", acp3x_dmic_enum, |
| 361 |
dmic_get, dmic_set); |
| 362 |
|
| 363 |
static const struct snd_soc_dapm_widget acp3x_5682_widgets[] = { |
| 364 |
SND_SOC_DAPM_HP("Headphone Jack", NULL), |
| 365 |
SND_SOC_DAPM_SPK("Spk", NULL), |
| 366 |
SND_SOC_DAPM_MIC("Headset Mic", NULL), |
| 367 |
SND_SOC_DAPM_MUX("Dmic Mux", SND_SOC_NOPM, 0, 0, |
| 368 |
&acp3x_dmic_mux_control), |
| 369 |
}; |
| 370 |
|
| 371 |
static const struct snd_soc_dapm_route acp3x_5682_audio_route[] = { |
| 372 |
{"Headphone Jack", NULL, "HPOL"}, |
| 373 |
{"Headphone Jack", NULL, "HPOR"}, |
| 374 |
{"IN1P", NULL, "Headset Mic"}, |
| 375 |
{"Spk", NULL, "Speaker"}, |
| 376 |
{"Dmic Mux", "Front Mic", "DMIC"}, |
| 377 |
{"Dmic Mux", "Rear Mic", "DMIC"}, |
| 378 |
}; |
| 379 |
|
| 380 |
static const struct snd_kcontrol_new acp3x_5682_mc_controls[] = { |
| 381 |
SOC_DAPM_PIN_SWITCH("Headphone Jack"), |
| 382 |
SOC_DAPM_PIN_SWITCH("Spk"), |
| 383 |
SOC_DAPM_PIN_SWITCH("Headset Mic"), |
| 384 |
}; |
| 385 |
|
| 386 |
static struct snd_soc_card acp3x_5682 = { |
| 387 |
.name = "acp3xalc5682m98357", |
| 388 |
.owner = THIS_MODULE, |
| 389 |
.dai_link = acp3x_dai, |
| 390 |
.num_links = ARRAY_SIZE(acp3x_dai), |
| 391 |
.dapm_widgets = acp3x_5682_widgets, |
| 392 |
.num_dapm_widgets = ARRAY_SIZE(acp3x_5682_widgets), |
| 393 |
.dapm_routes = acp3x_5682_audio_route, |
| 394 |
.num_dapm_routes = ARRAY_SIZE(acp3x_5682_audio_route), |
| 395 |
.controls = acp3x_5682_mc_controls, |
| 396 |
.num_controls = ARRAY_SIZE(acp3x_5682_mc_controls), |
| 397 |
}; |
| 398 |
|
| 399 |
static const struct snd_soc_dapm_widget acp3x_1015_widgets[] = { |
| 400 |
SND_SOC_DAPM_HP("Headphone Jack", NULL), |
| 401 |
SND_SOC_DAPM_MIC("Headset Mic", NULL), |
| 402 |
SND_SOC_DAPM_MUX("Dmic Mux", SND_SOC_NOPM, 0, 0, |
| 403 |
&acp3x_dmic_mux_control), |
| 404 |
SND_SOC_DAPM_SPK("Left Spk", NULL), |
| 405 |
SND_SOC_DAPM_SPK("Right Spk", NULL), |
| 406 |
}; |
| 407 |
|
| 408 |
static const struct snd_soc_dapm_route acp3x_1015_route[] = { |
| 409 |
{"Headphone Jack", NULL, "HPOL"}, |
| 410 |
{"Headphone Jack", NULL, "HPOR"}, |
| 411 |
{"IN1P", NULL, "Headset Mic"}, |
| 412 |
{"Dmic Mux", "Front Mic", "DMIC"}, |
| 413 |
{"Dmic Mux", "Rear Mic", "DMIC"}, |
| 414 |
{"Left Spk", NULL, "Left SPO"}, |
| 415 |
{"Right Spk", NULL, "Right SPO"}, |
| 416 |
}; |
| 417 |
|
| 418 |
static const struct snd_kcontrol_new acp3x_mc_1015_controls[] = { |
| 419 |
SOC_DAPM_PIN_SWITCH("Headphone Jack"), |
| 420 |
SOC_DAPM_PIN_SWITCH("Headset Mic"), |
| 421 |
SOC_DAPM_PIN_SWITCH("Left Spk"), |
| 422 |
SOC_DAPM_PIN_SWITCH("Right Spk"), |
| 423 |
}; |
| 424 |
|
| 425 |
static struct snd_soc_card acp3x_1015 = { |
| 426 |
.name = "acp3xalc56821015", |
| 427 |
.owner = THIS_MODULE, |
| 428 |
.dai_link = acp3x_dai, |
| 429 |
.num_links = ARRAY_SIZE(acp3x_dai), |
| 430 |
.dapm_widgets = acp3x_1015_widgets, |
| 431 |
.num_dapm_widgets = ARRAY_SIZE(acp3x_1015_widgets), |
| 432 |
.dapm_routes = acp3x_1015_route, |
| 433 |
.num_dapm_routes = ARRAY_SIZE(acp3x_1015_route), |
| 434 |
.codec_conf = rt1015_conf, |
| 435 |
.num_configs = ARRAY_SIZE(rt1015_conf), |
| 436 |
.controls = acp3x_mc_1015_controls, |
| 437 |
.num_controls = ARRAY_SIZE(acp3x_mc_1015_controls), |
| 438 |
}; |
| 439 |
|
| 440 |
static const struct snd_soc_dapm_widget acp3x_1015p_widgets[] = { |
| 441 |
SND_SOC_DAPM_HP("Headphone Jack", NULL), |
| 442 |
SND_SOC_DAPM_MIC("Headset Mic", NULL), |
| 443 |
SND_SOC_DAPM_MUX("Dmic Mux", SND_SOC_NOPM, 0, 0, |
| 444 |
&acp3x_dmic_mux_control), |
| 445 |
SND_SOC_DAPM_SPK("Speakers", NULL), |
| 446 |
}; |
| 447 |
|
| 448 |
static const struct snd_soc_dapm_route acp3x_1015p_route[] = { |
| 449 |
{"Headphone Jack", NULL, "HPOL"}, |
| 450 |
{"Headphone Jack", NULL, "HPOR"}, |
| 451 |
{"IN1P", NULL, "Headset Mic"}, |
| 452 |
{"Dmic Mux", "Front Mic", "DMIC"}, |
| 453 |
{"Dmic Mux", "Rear Mic", "DMIC"}, |
| 454 |
/* speaker */ |
| 455 |
{ "Speakers", NULL, "Speaker" }, |
| 456 |
}; |
| 457 |
|
| 458 |
static const struct snd_kcontrol_new acp3x_mc_1015p_controls[] = { |
| 459 |
SOC_DAPM_PIN_SWITCH("Speakers"), |
| 460 |
SOC_DAPM_PIN_SWITCH("Headphone Jack"), |
| 461 |
SOC_DAPM_PIN_SWITCH("Headset Mic"), |
| 462 |
}; |
| 463 |
|
| 464 |
static struct snd_soc_card acp3x_1015p = { |
| 465 |
.name = "acp3xalc56821015p", |
| 466 |
.owner = THIS_MODULE, |
| 467 |
.dai_link = acp3x_dai, |
| 468 |
.num_links = ARRAY_SIZE(acp3x_dai), |
| 469 |
.dapm_widgets = acp3x_1015p_widgets, |
| 470 |
.num_dapm_widgets = ARRAY_SIZE(acp3x_1015p_widgets), |
| 471 |
.dapm_routes = acp3x_1015p_route, |
| 472 |
.num_dapm_routes = ARRAY_SIZE(acp3x_1015p_route), |
| 473 |
.controls = acp3x_mc_1015p_controls, |
| 474 |
.num_controls = ARRAY_SIZE(acp3x_mc_1015p_controls), |
| 475 |
}; |
| 476 |
|
| 477 |
void *soc_is_rltk_max(struct device *dev) |
| 478 |
{ |
| 479 |
const struct acpi_device_id *match; |
| 480 |
|
| 481 |
match = acpi_match_device(dev->driver->acpi_match_table, dev); |
| 482 |
if (!match) |
| 483 |
return NULL; |
| 484 |
return (void *)match->driver_data; |
| 485 |
} |
| 486 |
|
| 487 |
static void card_spk_dai_link_present(struct snd_soc_dai_link *links, |
| 488 |
const char *card_name) |
| 489 |
{ |
| 490 |
if (!strcmp(card_name, "acp3xalc56821015")) { |
| 491 |
links[1].codecs = rt1015; |
| 492 |
links[1].num_codecs = ARRAY_SIZE(rt1015); |
| 493 |
} else if (!strcmp(card_name, "acp3xalc56821015p")) { |
| 494 |
links[1].codecs = rt1015p; |
| 495 |
links[1].num_codecs = ARRAY_SIZE(rt1015p); |
| 496 |
} else { |
| 497 |
links[1].codecs = max; |
| 498 |
links[1].num_codecs = ARRAY_SIZE(max); |
| 499 |
} |
| 500 |
} |
| 501 |
|
| 502 |
static int acp3x_probe(struct platform_device *pdev) |
| 503 |
{ |
| 504 |
int ret; |
| 505 |
struct snd_soc_card *card; |
| 506 |
struct acp3x_platform_info *machine; |
| 507 |
struct device *dev = &pdev->dev; |
| 508 |
|
| 509 |
card = (struct snd_soc_card *)soc_is_rltk_max(dev); |
| 510 |
if (!card) |
| 511 |
return -ENODEV; |
| 512 |
|
| 513 |
machine = devm_kzalloc(&pdev->dev, sizeof(*machine), GFP_KERNEL); |
| 514 |
if (!machine) |
| 515 |
return -ENOMEM; |
| 516 |
|
| 517 |
card_spk_dai_link_present(card->dai_link, card->name); |
| 518 |
card->dev = &pdev->dev; |
| 519 |
platform_set_drvdata(pdev, card); |
| 520 |
snd_soc_card_set_drvdata(card, machine); |
| 521 |
|
| 522 |
dmic_sel = devm_gpiod_get(&pdev->dev, "dmic", GPIOD_OUT_LOW); |
| 523 |
if (IS_ERR(dmic_sel)) { |
| 524 |
dev_err(&pdev->dev, "DMIC gpio failed err=%ld\n", |
| 525 |
PTR_ERR(dmic_sel)); |
| 526 |
return PTR_ERR(dmic_sel); |
| 527 |
} |
| 528 |
|
| 529 |
ret = devm_snd_soc_register_card(&pdev->dev, card); |
| 530 |
if (ret) { |
| 531 |
return dev_err_probe(&pdev->dev, ret, |
| 532 |
"devm_snd_soc_register_card(%s) failed\n", |
| 533 |
card->name); |
| 534 |
} |
| 535 |
return 0; |
| 536 |
} |
| 537 |
|
| 538 |
static const struct acpi_device_id acp3x_audio_acpi_match[] = { |
| 539 |
{ "AMDI5682", (unsigned long)&acp3x_5682}, |
| 540 |
{ "AMDI1015", (unsigned long)&acp3x_1015}, |
| 541 |
{ "10021015", (unsigned long)&acp3x_1015p}, |
| 542 |
{}, |
| 543 |
}; |
| 544 |
MODULE_DEVICE_TABLE(acpi, acp3x_audio_acpi_match); |
| 545 |
|
| 546 |
static struct platform_driver acp3x_audio = { |
| 547 |
.driver = { |
| 548 |
.name = "acp3x-alc5682-max98357", |
| 549 |
.acpi_match_table = ACPI_PTR(acp3x_audio_acpi_match), |
| 550 |
.pm = &snd_soc_pm_ops, |
| 551 |
}, |
| 552 |
.probe = acp3x_probe, |
| 553 |
}; |
| 554 |
|
| 555 |
module_platform_driver(acp3x_audio); |
| 556 |
|
| 557 |
MODULE_AUTHOR("[email protected]"); |
| 558 |
MODULE_AUTHOR("[email protected]"); |
| 559 |
MODULE_AUTHOR("[email protected]"); |
| 560 |
MODULE_DESCRIPTION("ALC5682 ALC1015, ALC1015P & MAX98357 audio support"); |
| 561 |
MODULE_LICENSE("GPL v2"); |