Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ASoC: amd: acp: Add sound support for a line of

Merge series from Marian Postevca <posteuca@mutex.one>:

This series adds support for a line of HUAWEI laptops with
AMD CPUs that connect using the ACP3x module to a ES8336 CODEC.

The CODEC driver must be extended to support the S32 LE format
and the MCLK div by 2 option. MCLK div by 2 is needed for one specific
SKU, which uses a 48Mhz MCLK, which seems to be too high of a frequency
for the CODEC and must be divided by 2.

The acp legacy driver must also be extended by using callbacks so that
the more complicated handling of this specific CODEC can be moved
outside the more generic ACP code.

+735 -26
+70
sound/soc/amd/acp-config.c
··· 61 61 {} 62 62 }, 63 63 }, 64 + { 65 + .flags = FLAG_AMD_LEGACY, 66 + .device = ACP_PCI_DEV_ID, 67 + .dmi_table = (const struct dmi_system_id []) { 68 + { 69 + .matches = { 70 + DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "HUAWEI"), 71 + DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "KLVL-WXXW"), 72 + DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "M1010"), 73 + }, 74 + }, 75 + {} 76 + }, 77 + }, 78 + { 79 + .flags = FLAG_AMD_LEGACY, 80 + .device = ACP_PCI_DEV_ID, 81 + .dmi_table = (const struct dmi_system_id []) { 82 + { 83 + .matches = { 84 + DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "HUAWEI"), 85 + DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "KLVL-WXX9"), 86 + DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "M1010"), 87 + }, 88 + }, 89 + {} 90 + }, 91 + }, 92 + { 93 + .flags = FLAG_AMD_LEGACY, 94 + .device = ACP_PCI_DEV_ID, 95 + .dmi_table = (const struct dmi_system_id []) { 96 + { 97 + .matches = { 98 + DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "HUAWEI"), 99 + DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "BOM-WXX9"), 100 + DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "M1010"), 101 + }, 102 + }, 103 + {} 104 + }, 105 + }, 106 + { 107 + .flags = FLAG_AMD_LEGACY, 108 + .device = ACP_PCI_DEV_ID, 109 + .dmi_table = (const struct dmi_system_id []) { 110 + { 111 + .matches = { 112 + DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "HUAWEI"), 113 + DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HVY-WXX9"), 114 + DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "M1020"), 115 + }, 116 + }, 117 + {} 118 + }, 119 + }, 120 + { 121 + .flags = FLAG_AMD_LEGACY, 122 + .device = ACP_PCI_DEV_ID, 123 + .dmi_table = (const struct dmi_system_id []) { 124 + { 125 + .matches = { 126 + DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "HUAWEI"), 127 + DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HVY-WXX9"), 128 + DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "M1040"), 129 + }, 130 + }, 131 + {} 132 + }, 133 + }, 64 134 }; 65 135 66 136 int snd_amd_acp_find_config(struct pci_dev *pci)
+1 -1
sound/soc/amd/acp/Makefile
··· 17 17 18 18 #machine specific driver 19 19 snd-acp-mach-objs := acp-mach-common.o 20 - snd-acp-legacy-mach-objs := acp-legacy-mach.o 20 + snd-acp-legacy-mach-objs := acp-legacy-mach.o acp3x-es83xx/acp3x-es83xx.o 21 21 snd-acp-sof-mach-objs := acp-sof-mach.o 22 22 23 23 obj-$(CONFIG_SND_SOC_AMD_ACP_PCM) += snd-acp-pcm.o
+91 -11
sound/soc/amd/acp/acp-legacy-mach.c
··· 20 20 #include <linux/module.h> 21 21 22 22 #include "acp-mach.h" 23 + #include "acp3x-es83xx/acp3x-es83xx.h" 23 24 24 25 static struct acp_card_drvdata rt5682_rt1019_data = { 25 26 .hs_cpu_id = I2S_SP, ··· 52 51 .tdm_mode = false, 53 52 }; 54 53 54 + static struct acp_card_drvdata es83xx_rn_data = { 55 + .hs_cpu_id = I2S_SP, 56 + .dmic_cpu_id = DMIC, 57 + .hs_codec_id = ES83XX, 58 + .dmic_codec_id = DMIC, 59 + .platform = RENOIR, 60 + }; 61 + 55 62 static struct acp_card_drvdata max_nau8825_data = { 56 63 .hs_cpu_id = I2S_HS, 57 64 .amp_cpu_id = I2S_HS, ··· 84 75 .tdm_mode = false, 85 76 }; 86 77 78 + static bool acp_asoc_init_ops(struct acp_card_drvdata *priv) 79 + { 80 + bool has_ops = false; 81 + 82 + if (priv->hs_codec_id == ES83XX) { 83 + has_ops = true; 84 + acp3x_es83xx_init_ops(&priv->ops); 85 + } 86 + return has_ops; 87 + } 88 + 89 + static int acp_asoc_suspend_pre(struct snd_soc_card *card) 90 + { 91 + int ret; 92 + 93 + ret = acp_ops_suspend_pre(card); 94 + if (ret == 1) 95 + return 0; 96 + else 97 + return ret; 98 + } 99 + 100 + static int acp_asoc_resume_post(struct snd_soc_card *card) 101 + { 102 + int ret; 103 + 104 + ret = acp_ops_resume_post(card); 105 + if (ret == 1) 106 + return 0; 107 + else 108 + return ret; 109 + } 110 + 87 111 static int acp_asoc_probe(struct platform_device *pdev) 88 112 { 89 113 struct snd_soc_card *card = NULL; ··· 125 83 struct acp_card_drvdata *acp_card_drvdata; 126 84 int ret; 127 85 128 - if (!pdev->id_entry) 129 - return -EINVAL; 86 + if (!pdev->id_entry) { 87 + ret = -EINVAL; 88 + goto out; 89 + } 130 90 131 91 card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL); 132 - if (!card) 133 - return -ENOMEM; 92 + if (!card) { 93 + ret = -ENOMEM; 94 + goto out; 95 + } 134 96 97 + card->drvdata = (struct acp_card_drvdata *)pdev->id_entry->driver_data; 98 + acp_card_drvdata = card->drvdata; 99 + acp_card_drvdata->acpi_mach = (struct snd_soc_acpi_mach *)pdev->dev.platform_data; 135 100 card->dev = dev; 136 101 card->owner = THIS_MODULE; 137 102 card->name = pdev->id_entry->name; 138 - card->drvdata = (struct acp_card_drvdata *)pdev->id_entry->driver_data; 139 - /* Widgets and controls added per-codec in acp-mach-common.c */ 140 103 141 - acp_card_drvdata = card->drvdata; 104 + acp_asoc_init_ops(card->drvdata); 105 + 106 + /* If widgets and controls are not set in specific callback, 107 + * they will be added per-codec in acp-mach-common.c 108 + */ 109 + ret = acp_ops_configure_widgets(card); 110 + if (ret < 0) { 111 + dev_err(&pdev->dev, 112 + "Cannot configure widgets for card (%s): %d\n", 113 + card->name, ret); 114 + goto out; 115 + } 116 + card->suspend_pre = acp_asoc_suspend_pre; 117 + card->resume_post = acp_asoc_resume_post; 118 + 119 + ret = acp_ops_probe(card); 120 + if (ret < 0) { 121 + dev_err(&pdev->dev, 122 + "Cannot probe card (%s): %d\n", 123 + card->name, ret); 124 + goto out; 125 + } 126 + 142 127 dmi_id = dmi_first_match(acp_quirk_table); 143 128 if (dmi_id && dmi_id->driver_data) 144 129 acp_card_drvdata->tdm_mode = dmi_id->driver_data; 145 130 146 - acp_legacy_dai_links_create(card); 131 + ret = acp_legacy_dai_links_create(card); 132 + if (ret) { 133 + dev_err(&pdev->dev, 134 + "Cannot create dai links for card (%s): %d\n", 135 + card->name, ret); 136 + goto out; 137 + } 147 138 148 139 ret = devm_snd_soc_register_card(&pdev->dev, card); 149 140 if (ret) { 150 141 dev_err(&pdev->dev, 151 142 "devm_snd_soc_register_card(%s) failed: %d\n", 152 143 card->name, ret); 153 - return ret; 144 + goto out; 154 145 } 155 - 156 - return 0; 146 + out: 147 + return ret; 157 148 } 158 149 159 150 static const struct platform_device_id board_ids[] = { ··· 201 126 { 202 127 .name = "acp3xalc5682s1019", 203 128 .driver_data = (kernel_ulong_t)&rt5682s_rt1019_data, 129 + }, 130 + { 131 + .name = "acp3x-es83xx", 132 + .driver_data = (kernel_ulong_t)&es83xx_rn_data, 204 133 }, 205 134 { 206 135 .name = "rmb-nau8825-max", ··· 232 153 MODULE_ALIAS("platform:acp3xalc56821019"); 233 154 MODULE_ALIAS("platform:acp3xalc5682sm98360"); 234 155 MODULE_ALIAS("platform:acp3xalc5682s1019"); 156 + MODULE_ALIAS("platform:acp3x-es83xx"); 235 157 MODULE_ALIAS("platform:rmb-nau8825-max"); 236 158 MODULE_ALIAS("platform:rmb-rt5682s-rt1019"); 237 159 MODULE_LICENSE("GPL v2");
+8
sound/soc/amd/acp/acp-mach-common.c
··· 1513 1513 struct device *dev = card->dev; 1514 1514 struct acp_card_drvdata *drv_data = card->drvdata; 1515 1515 int i = 0, num_links = 0; 1516 + int rc; 1516 1517 1517 1518 if (drv_data->hs_cpu_id) 1518 1519 num_links++; ··· 1551 1550 links[i].num_codecs = ARRAY_SIZE(rt5682s); 1552 1551 links[i].init = acp_card_rt5682s_init; 1553 1552 links[i].ops = &acp_card_rt5682s_ops; 1553 + } 1554 + if (drv_data->hs_codec_id == ES83XX) { 1555 + rc = acp_ops_configure_link(card, &links[i]); 1556 + if (rc != 0) { 1557 + dev_err(dev, "Failed to configure link for ES83XX: %d\n", rc); 1558 + return rc; 1559 + } 1554 1560 } 1555 1561 i++; 1556 1562 }
+67
sound/soc/amd/acp/acp-mach.h
··· 20 20 21 21 #define TDM_CHANNELS 8 22 22 23 + #define ACP_OPS(priv, cb) ((priv)->ops.cb) 24 + 25 + #define acp_get_drvdata(card) ((struct acp_card_drvdata *)(card)->drvdata) 26 + 23 27 enum be_id { 24 28 HEADSET_BE_ID = 0, 25 29 AMP_BE_ID, ··· 47 43 NAU8825, 48 44 NAU8821, 49 45 MAX98388, 46 + ES83XX, 50 47 }; 51 48 52 49 enum platform_end_point { 53 50 RENOIR = 0, 54 51 REMBRANDT, 52 + }; 53 + 54 + struct acp_mach_ops { 55 + int (*probe)(struct snd_soc_card *card); 56 + int (*configure_link)(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link); 57 + int (*configure_widgets)(struct snd_soc_card *card); 58 + int (*suspend_pre)(struct snd_soc_card *card); 59 + int (*resume_post)(struct snd_soc_card *card); 55 60 }; 56 61 57 62 struct acp_card_drvdata { ··· 74 61 unsigned int platform; 75 62 struct clk *wclk; 76 63 struct clk *bclk; 64 + struct acp_mach_ops ops; 65 + struct snd_soc_acpi_mach *acpi_mach; 66 + void *mach_priv; 77 67 bool soc_mclk; 78 68 bool tdm_mode; 79 69 }; ··· 84 68 int acp_sofdsp_dai_links_create(struct snd_soc_card *card); 85 69 int acp_legacy_dai_links_create(struct snd_soc_card *card); 86 70 extern const struct dmi_system_id acp_quirk_table[]; 71 + 72 + static inline int acp_ops_probe(struct snd_soc_card *card) 73 + { 74 + int ret = 1; 75 + struct acp_card_drvdata *priv = acp_get_drvdata(card); 76 + 77 + if (ACP_OPS(priv, probe)) 78 + ret = ACP_OPS(priv, probe)(card); 79 + return ret; 80 + } 81 + 82 + static inline int acp_ops_configure_link(struct snd_soc_card *card, 83 + struct snd_soc_dai_link *dai_link) 84 + { 85 + int ret = 1; 86 + struct acp_card_drvdata *priv = acp_get_drvdata(card); 87 + 88 + if (ACP_OPS(priv, configure_link)) 89 + ret = ACP_OPS(priv, configure_link)(card, dai_link); 90 + return ret; 91 + } 92 + 93 + static inline int acp_ops_configure_widgets(struct snd_soc_card *card) 94 + { 95 + int ret = 1; 96 + struct acp_card_drvdata *priv = acp_get_drvdata(card); 97 + 98 + if (ACP_OPS(priv, configure_widgets)) 99 + ret = ACP_OPS(priv, configure_widgets)(card); 100 + return ret; 101 + } 102 + 103 + static inline int acp_ops_suspend_pre(struct snd_soc_card *card) 104 + { 105 + int ret = 1; 106 + struct acp_card_drvdata *priv = acp_get_drvdata(card); 107 + 108 + if (ACP_OPS(priv, suspend_pre)) 109 + ret = ACP_OPS(priv, suspend_pre)(card); 110 + return ret; 111 + } 112 + 113 + static inline int acp_ops_resume_post(struct snd_soc_card *card) 114 + { 115 + int ret = 1; 116 + struct acp_card_drvdata *priv = acp_get_drvdata(card); 117 + 118 + if (ACP_OPS(priv, resume_post)) 119 + ret = ACP_OPS(priv, resume_post)(card); 120 + return ret; 121 + } 87 122 88 123 #endif
+4
sound/soc/amd/acp/acp-renoir.c
··· 69 69 .id = "AMDI1019", 70 70 .drv_name = "renoir-acp", 71 71 }, 72 + { 73 + .id = "ESSX8336", 74 + .drv_name = "acp3x-es83xx", 75 + }, 72 76 {}, 73 77 }; 74 78
+443
sound/soc/amd/acp/acp3x-es83xx/acp3x-es83xx.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + // 3 + // Machine driver for AMD ACP Audio engine using ES8336 codec. 4 + // 5 + // Copyright 2023 Marian Postevca <posteuca@mutex.one> 6 + #include <sound/core.h> 7 + #include <sound/soc.h> 8 + #include <sound/pcm.h> 9 + #include <sound/pcm_params.h> 10 + #include <sound/soc-dapm.h> 11 + #include <sound/jack.h> 12 + #include <sound/soc-acpi.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 + #include <linux/dmi.h> 22 + #include "../acp-mach.h" 23 + 24 + #define get_mach_priv(card) ((struct acp3x_es83xx_private *)((acp_get_drvdata(card))->mach_priv)) 25 + 26 + #define DUAL_CHANNEL 2 27 + 28 + #define ES83XX_ENABLE_DMIC BIT(4) 29 + #define ES83XX_48_MHZ_MCLK BIT(5) 30 + 31 + struct acp3x_es83xx_private { 32 + bool speaker_on; 33 + bool headphone_on; 34 + unsigned long quirk; 35 + struct snd_soc_component *codec; 36 + struct device *codec_dev; 37 + struct gpio_desc *gpio_speakers, *gpio_headphone; 38 + struct acpi_gpio_params enable_spk_gpio, enable_hp_gpio; 39 + struct acpi_gpio_mapping gpio_mapping[3]; 40 + struct snd_soc_dapm_route mic_map[2]; 41 + }; 42 + 43 + static const unsigned int channels[] = { 44 + DUAL_CHANNEL, 45 + }; 46 + 47 + static const struct snd_pcm_hw_constraint_list constraints_channels = { 48 + .count = ARRAY_SIZE(channels), 49 + .list = channels, 50 + .mask = 0, 51 + }; 52 + 53 + #define ES83xx_12288_KHZ_MCLK_FREQ (48000 * 256) 54 + #define ES83xx_48_MHZ_MCLK_FREQ (48000 * 1000) 55 + 56 + static int acp3x_es83xx_headphone_power_event(struct snd_soc_dapm_widget *w, 57 + struct snd_kcontrol *kcontrol, int event); 58 + static int acp3x_es83xx_speaker_power_event(struct snd_soc_dapm_widget *w, 59 + struct snd_kcontrol *kcontrol, int event); 60 + 61 + static int acp3x_es83xx_codec_startup(struct snd_pcm_substream *substream) 62 + { 63 + struct snd_pcm_runtime *runtime; 64 + struct snd_soc_pcm_runtime *rtd; 65 + struct snd_soc_dai *codec_dai; 66 + struct acp3x_es83xx_private *priv; 67 + unsigned int freq; 68 + int ret; 69 + 70 + runtime = substream->runtime; 71 + rtd = asoc_substream_to_rtd(substream); 72 + codec_dai = asoc_rtd_to_codec(rtd, 0); 73 + priv = get_mach_priv(rtd->card); 74 + 75 + if (priv->quirk & ES83XX_48_MHZ_MCLK) { 76 + dev_dbg(priv->codec_dev, "using a 48Mhz MCLK\n"); 77 + freq = ES83xx_48_MHZ_MCLK_FREQ; 78 + } else { 79 + dev_dbg(priv->codec_dev, "using a 12.288Mhz MCLK\n"); 80 + freq = ES83xx_12288_KHZ_MCLK_FREQ; 81 + } 82 + 83 + ret = snd_soc_dai_set_sysclk(codec_dai, 0, freq, SND_SOC_CLOCK_OUT); 84 + if (ret < 0) { 85 + dev_err(rtd->dev, "can't set codec sysclk: %d\n", ret); 86 + return ret; 87 + } 88 + 89 + runtime->hw.channels_max = DUAL_CHANNEL; 90 + snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 91 + &constraints_channels); 92 + 93 + return 0; 94 + } 95 + 96 + static struct snd_soc_jack es83xx_jack; 97 + 98 + static struct snd_soc_jack_pin es83xx_jack_pins[] = { 99 + { 100 + .pin = "Headphone", 101 + .mask = SND_JACK_HEADPHONE, 102 + }, 103 + { 104 + .pin = "Headset Mic", 105 + .mask = SND_JACK_MICROPHONE, 106 + }, 107 + }; 108 + 109 + static const struct snd_soc_dapm_widget acp3x_es83xx_widgets[] = { 110 + SND_SOC_DAPM_SPK("Speaker", NULL), 111 + SND_SOC_DAPM_HP("Headphone", NULL), 112 + SND_SOC_DAPM_MIC("Headset Mic", NULL), 113 + SND_SOC_DAPM_MIC("Internal Mic", NULL), 114 + 115 + SND_SOC_DAPM_SUPPLY("Headphone Power", SND_SOC_NOPM, 0, 0, 116 + acp3x_es83xx_headphone_power_event, 117 + SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), 118 + SND_SOC_DAPM_SUPPLY("Speaker Power", SND_SOC_NOPM, 0, 0, 119 + acp3x_es83xx_speaker_power_event, 120 + SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), 121 + }; 122 + 123 + static const struct snd_soc_dapm_route acp3x_es83xx_audio_map[] = { 124 + {"Headphone", NULL, "HPOL"}, 125 + {"Headphone", NULL, "HPOR"}, 126 + {"Headphone", NULL, "Headphone Power"}, 127 + 128 + /* 129 + * There is no separate speaker output instead the speakers are muxed to 130 + * the HP outputs. The mux is controlled Speaker and/or headphone switch. 131 + */ 132 + {"Speaker", NULL, "HPOL"}, 133 + {"Speaker", NULL, "HPOR"}, 134 + {"Speaker", NULL, "Speaker Power"}, 135 + }; 136 + 137 + 138 + static const struct snd_kcontrol_new acp3x_es83xx_controls[] = { 139 + SOC_DAPM_PIN_SWITCH("Speaker"), 140 + SOC_DAPM_PIN_SWITCH("Headphone"), 141 + SOC_DAPM_PIN_SWITCH("Headset Mic"), 142 + SOC_DAPM_PIN_SWITCH("Internal Mic"), 143 + }; 144 + 145 + static int acp3x_es83xx_configure_widgets(struct snd_soc_card *card) 146 + { 147 + card->dapm_widgets = acp3x_es83xx_widgets; 148 + card->num_dapm_widgets = ARRAY_SIZE(acp3x_es83xx_widgets); 149 + card->controls = acp3x_es83xx_controls; 150 + card->num_controls = ARRAY_SIZE(acp3x_es83xx_controls); 151 + card->dapm_routes = acp3x_es83xx_audio_map; 152 + card->num_dapm_routes = ARRAY_SIZE(acp3x_es83xx_audio_map); 153 + 154 + return 0; 155 + } 156 + 157 + static int acp3x_es83xx_headphone_power_event(struct snd_soc_dapm_widget *w, 158 + struct snd_kcontrol *kcontrol, int event) 159 + { 160 + struct acp3x_es83xx_private *priv = get_mach_priv(w->dapm->card); 161 + 162 + dev_dbg(priv->codec_dev, "headphone power event = %d\n", event); 163 + if (SND_SOC_DAPM_EVENT_ON(event)) 164 + priv->headphone_on = true; 165 + else 166 + priv->headphone_on = false; 167 + 168 + gpiod_set_value_cansleep(priv->gpio_speakers, priv->speaker_on); 169 + gpiod_set_value_cansleep(priv->gpio_headphone, priv->headphone_on); 170 + 171 + return 0; 172 + } 173 + 174 + static int acp3x_es83xx_speaker_power_event(struct snd_soc_dapm_widget *w, 175 + struct snd_kcontrol *kcontrol, int event) 176 + { 177 + struct acp3x_es83xx_private *priv = get_mach_priv(w->dapm->card); 178 + 179 + dev_dbg(priv->codec_dev, "speaker power event: %d\n", event); 180 + if (SND_SOC_DAPM_EVENT_ON(event)) 181 + priv->speaker_on = true; 182 + else 183 + priv->speaker_on = false; 184 + 185 + gpiod_set_value_cansleep(priv->gpio_speakers, priv->speaker_on); 186 + gpiod_set_value_cansleep(priv->gpio_headphone, priv->headphone_on); 187 + 188 + return 0; 189 + } 190 + 191 + static int acp3x_es83xx_suspend_pre(struct snd_soc_card *card) 192 + { 193 + struct acp3x_es83xx_private *priv = get_mach_priv(card); 194 + 195 + /* We need to disable the jack in the machine driver suspend 196 + * callback so that the CODEC suspend callback actually gets 197 + * called. Without doing it, the CODEC suspend/resume 198 + * callbacks do not get called if headphones are plugged in. 199 + * This is because plugging in headphones keeps some supplies 200 + * active, this in turn means that the lowest bias level 201 + * that the CODEC can go to is SND_SOC_BIAS_STANDBY. 202 + * If components do not set idle_bias_on to true then 203 + * their suspend/resume callbacks do not get called. 204 + */ 205 + dev_dbg(priv->codec_dev, "card suspend\n"); 206 + snd_soc_component_set_jack(priv->codec, NULL, NULL); 207 + return 0; 208 + } 209 + 210 + static int acp3x_es83xx_resume_post(struct snd_soc_card *card) 211 + { 212 + struct acp3x_es83xx_private *priv = get_mach_priv(card); 213 + 214 + /* We disabled jack detection in suspend callback, 215 + * enable it back. 216 + */ 217 + dev_dbg(priv->codec_dev, "card resume\n"); 218 + snd_soc_component_set_jack(priv->codec, &es83xx_jack, NULL); 219 + return 0; 220 + } 221 + 222 + static int acp3x_es83xx_configure_gpios(struct acp3x_es83xx_private *priv) 223 + { 224 + int ret = 0; 225 + 226 + priv->enable_spk_gpio.crs_entry_index = 0; 227 + priv->enable_hp_gpio.crs_entry_index = 1; 228 + 229 + priv->enable_spk_gpio.active_low = false; 230 + priv->enable_hp_gpio.active_low = false; 231 + 232 + priv->gpio_mapping[0].name = "speakers-enable-gpios"; 233 + priv->gpio_mapping[0].data = &priv->enable_spk_gpio; 234 + priv->gpio_mapping[0].size = 1; 235 + priv->gpio_mapping[0].quirks = ACPI_GPIO_QUIRK_ONLY_GPIOIO; 236 + 237 + priv->gpio_mapping[1].name = "headphone-enable-gpios"; 238 + priv->gpio_mapping[1].data = &priv->enable_hp_gpio; 239 + priv->gpio_mapping[1].size = 1; 240 + priv->gpio_mapping[1].quirks = ACPI_GPIO_QUIRK_ONLY_GPIOIO; 241 + 242 + dev_info(priv->codec_dev, "speaker gpio %d active %s, headphone gpio %d active %s\n", 243 + priv->enable_spk_gpio.crs_entry_index, 244 + priv->enable_spk_gpio.active_low ? "low" : "high", 245 + priv->enable_hp_gpio.crs_entry_index, 246 + priv->enable_hp_gpio.active_low ? "low" : "high"); 247 + return ret; 248 + } 249 + 250 + static int acp3x_es83xx_configure_mics(struct acp3x_es83xx_private *priv) 251 + { 252 + int num_routes = 0; 253 + int i; 254 + 255 + if (!(priv->quirk & ES83XX_ENABLE_DMIC)) { 256 + priv->mic_map[num_routes].sink = "MIC1"; 257 + priv->mic_map[num_routes].source = "Internal Mic"; 258 + num_routes++; 259 + } 260 + 261 + priv->mic_map[num_routes].sink = "MIC2"; 262 + priv->mic_map[num_routes].source = "Headset Mic"; 263 + num_routes++; 264 + 265 + for (i = 0; i < num_routes; i++) 266 + dev_info(priv->codec_dev, "%s is %s\n", 267 + priv->mic_map[i].source, priv->mic_map[i].sink); 268 + 269 + return num_routes; 270 + } 271 + 272 + static int acp3x_es83xx_init(struct snd_soc_pcm_runtime *runtime) 273 + { 274 + struct snd_soc_component *codec = asoc_rtd_to_codec(runtime, 0)->component; 275 + struct snd_soc_card *card = runtime->card; 276 + struct acp3x_es83xx_private *priv = get_mach_priv(card); 277 + int ret = 0; 278 + int num_routes; 279 + 280 + ret = snd_soc_card_jack_new_pins(card, "Headset", 281 + SND_JACK_HEADSET | SND_JACK_BTN_0, 282 + &es83xx_jack, es83xx_jack_pins, 283 + ARRAY_SIZE(es83xx_jack_pins)); 284 + if (ret) { 285 + dev_err(card->dev, "jack creation failed %d\n", ret); 286 + return ret; 287 + } 288 + 289 + snd_jack_set_key(es83xx_jack.jack, SND_JACK_BTN_0, KEY_PLAYPAUSE); 290 + 291 + snd_soc_component_set_jack(codec, &es83xx_jack, NULL); 292 + 293 + priv->codec = codec; 294 + acp3x_es83xx_configure_gpios(priv); 295 + 296 + ret = devm_acpi_dev_add_driver_gpios(priv->codec_dev, priv->gpio_mapping); 297 + if (ret) 298 + dev_warn(priv->codec_dev, "failed to add speaker gpio\n"); 299 + 300 + priv->gpio_speakers = gpiod_get_optional(priv->codec_dev, "speakers-enable", 301 + priv->enable_spk_gpio.active_low ? GPIOD_OUT_LOW : GPIOD_OUT_HIGH); 302 + if (IS_ERR(priv->gpio_speakers)) { 303 + dev_err(priv->codec_dev, "could not get speakers-enable GPIO\n"); 304 + return PTR_ERR(priv->gpio_speakers); 305 + } 306 + 307 + priv->gpio_headphone = gpiod_get_optional(priv->codec_dev, "headphone-enable", 308 + priv->enable_hp_gpio.active_low ? GPIOD_OUT_LOW : GPIOD_OUT_HIGH); 309 + if (IS_ERR(priv->gpio_headphone)) { 310 + dev_err(priv->codec_dev, "could not get headphone-enable GPIO\n"); 311 + return PTR_ERR(priv->gpio_headphone); 312 + } 313 + 314 + num_routes = acp3x_es83xx_configure_mics(priv); 315 + if (num_routes > 0) { 316 + ret = snd_soc_dapm_add_routes(&card->dapm, priv->mic_map, num_routes); 317 + if (ret != 0) 318 + device_remove_software_node(priv->codec_dev); 319 + } 320 + 321 + return ret; 322 + } 323 + 324 + static const struct snd_soc_ops acp3x_es83xx_ops = { 325 + .startup = acp3x_es83xx_codec_startup, 326 + }; 327 + 328 + 329 + SND_SOC_DAILINK_DEF(codec, 330 + DAILINK_COMP_ARRAY(COMP_CODEC("i2c-ESSX8336:00", "ES8316 HiFi"))); 331 + 332 + static const struct dmi_system_id acp3x_es83xx_dmi_table[] = { 333 + { 334 + .matches = { 335 + DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "HUAWEI"), 336 + DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "KLVL-WXXW"), 337 + DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "M1010"), 338 + }, 339 + .driver_data = (void *)(ES83XX_ENABLE_DMIC), 340 + }, 341 + { 342 + .matches = { 343 + DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "HUAWEI"), 344 + DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "KLVL-WXX9"), 345 + DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "M1010"), 346 + }, 347 + .driver_data = (void *)(ES83XX_ENABLE_DMIC), 348 + }, 349 + { 350 + .matches = { 351 + DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "HUAWEI"), 352 + DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "BOM-WXX9"), 353 + DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "M1010"), 354 + }, 355 + .driver_data = (void *)(ES83XX_ENABLE_DMIC|ES83XX_48_MHZ_MCLK), 356 + }, 357 + { 358 + .matches = { 359 + DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "HUAWEI"), 360 + DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HVY-WXX9"), 361 + DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "M1020"), 362 + }, 363 + .driver_data = (void *)(ES83XX_ENABLE_DMIC), 364 + }, 365 + { 366 + .matches = { 367 + DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "HUAWEI"), 368 + DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HVY-WXX9"), 369 + DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "M1040"), 370 + }, 371 + .driver_data = (void *)(ES83XX_ENABLE_DMIC), 372 + }, 373 + {} 374 + }; 375 + 376 + static int acp3x_es83xx_configure_link(struct snd_soc_card *card, struct snd_soc_dai_link *link) 377 + { 378 + link->codecs = codec; 379 + link->num_codecs = ARRAY_SIZE(codec); 380 + link->init = acp3x_es83xx_init; 381 + link->ops = &acp3x_es83xx_ops; 382 + link->dai_fmt = SND_SOC_DAIFMT_I2S 383 + | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBP_CFP; 384 + 385 + return 0; 386 + } 387 + 388 + static int acp3x_es83xx_probe(struct snd_soc_card *card) 389 + { 390 + int ret = 0; 391 + struct device *dev = card->dev; 392 + const struct dmi_system_id *dmi_id; 393 + 394 + dmi_id = dmi_first_match(acp3x_es83xx_dmi_table); 395 + if (dmi_id && dmi_id->driver_data) { 396 + struct acp3x_es83xx_private *priv; 397 + struct acp_card_drvdata *acp_drvdata; 398 + struct acpi_device *adev; 399 + struct device *codec_dev; 400 + 401 + acp_drvdata = (struct acp_card_drvdata *)card->drvdata; 402 + 403 + dev_info(dev, "matched DMI table with this system, trying to register sound card\n"); 404 + 405 + adev = acpi_dev_get_first_match_dev(acp_drvdata->acpi_mach->id, NULL, -1); 406 + if (!adev) { 407 + dev_err(dev, "Error cannot find '%s' dev\n", acp_drvdata->acpi_mach->id); 408 + return -ENXIO; 409 + } 410 + 411 + codec_dev = acpi_get_first_physical_node(adev); 412 + acpi_dev_put(adev); 413 + if (!codec_dev) { 414 + dev_warn(dev, "Error cannot find codec device, will defer probe\n"); 415 + return -EPROBE_DEFER; 416 + } 417 + 418 + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 419 + if (!priv) { 420 + put_device(codec_dev); 421 + return -ENOMEM; 422 + } 423 + 424 + priv->codec_dev = codec_dev; 425 + priv->quirk = (unsigned long)dmi_id->driver_data; 426 + acp_drvdata->mach_priv = priv; 427 + dev_info(dev, "successfully probed the sound card\n"); 428 + } else { 429 + ret = -ENODEV; 430 + dev_warn(dev, "this system has a ES83xx codec defined in ACPI, but the driver doesn't have this system registered in DMI table\n"); 431 + } 432 + return ret; 433 + } 434 + 435 + 436 + void acp3x_es83xx_init_ops(struct acp_mach_ops *ops) 437 + { 438 + ops->probe = acp3x_es83xx_probe; 439 + ops->configure_widgets = acp3x_es83xx_configure_widgets; 440 + ops->configure_link = acp3x_es83xx_configure_link; 441 + ops->suspend_pre = acp3x_es83xx_suspend_pre; 442 + ops->resume_post = acp3x_es83xx_resume_post; 443 + }
+12
sound/soc/amd/acp/acp3x-es83xx/acp3x-es83xx.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0+ */ 2 + /* 3 + * Copyright 2023 Marian Postevca <posteuca@mutex.one> 4 + */ 5 + 6 + #ifndef __ACP3X_ES83XX_H 7 + #define __ACP3X_ES83XX_H 8 + 9 + void acp3x_es83xx_init_ops(struct acp_mach_ops *ops); 10 + 11 + #endif 12 +
+36 -14
sound/soc/codecs/es8316.c
··· 27 27 * MCLK/LRCK ratios, but we also add ratio 400, which is commonly used on 28 28 * Intel Cherry Trail platforms (19.2MHz MCLK, 48kHz LRCK). 29 29 */ 30 - #define NR_SUPPORTED_MCLK_LRCK_RATIOS ARRAY_SIZE(supported_mclk_lrck_ratios) 31 30 static const unsigned int supported_mclk_lrck_ratios[] = { 32 31 256, 384, 400, 500, 512, 768, 1024 33 32 }; ··· 39 40 struct snd_soc_jack *jack; 40 41 int irq; 41 42 unsigned int sysclk; 42 - unsigned int allowed_rates[NR_SUPPORTED_MCLK_LRCK_RATIOS]; 43 + unsigned int allowed_rates[ARRAY_SIZE(supported_mclk_lrck_ratios)]; 43 44 struct snd_pcm_hw_constraint_list sysclk_constraints; 44 45 bool jd_inverted; 45 46 }; ··· 381 382 /* Limit supported sample rates to ones that can be autodetected 382 383 * by the codec running in slave mode. 383 384 */ 384 - for (i = 0; i < NR_SUPPORTED_MCLK_LRCK_RATIOS; i++) { 385 + for (i = 0; i < ARRAY_SIZE(supported_mclk_lrck_ratios); i++) { 385 386 const unsigned int ratio = supported_mclk_lrck_ratios[i]; 386 387 387 388 if (freq % ratio == 0) ··· 469 470 u8 bclk_divider; 470 471 u16 lrck_divider; 471 472 int i; 473 + unsigned int clk = es8316->sysclk / 2; 474 + bool clk_valid = false; 472 475 473 - /* Validate supported sample rates that are autodetected from MCLK */ 474 - for (i = 0; i < NR_SUPPORTED_MCLK_LRCK_RATIOS; i++) { 475 - const unsigned int ratio = supported_mclk_lrck_ratios[i]; 476 + /* We will start with halved sysclk and see if we can use it 477 + * for proper clocking. This is to minimise the risk of running 478 + * the CODEC with a too high frequency. We have an SKU where 479 + * the sysclk frequency is 48Mhz and this causes the sound to be 480 + * sped up. If we can run with a halved sysclk, we will use it, 481 + * if we can't use it, then full sysclk will be used. 482 + */ 483 + do { 484 + /* Validate supported sample rates that are autodetected from MCLK */ 485 + for (i = 0; i < ARRAY_SIZE(supported_mclk_lrck_ratios); i++) { 486 + const unsigned int ratio = supported_mclk_lrck_ratios[i]; 476 487 477 - if (es8316->sysclk % ratio != 0) 478 - continue; 479 - if (es8316->sysclk / ratio == params_rate(params)) 480 - break; 488 + if (clk % ratio != 0) 489 + continue; 490 + if (clk / ratio == params_rate(params)) 491 + break; 492 + } 493 + if (i == ARRAY_SIZE(supported_mclk_lrck_ratios)) { 494 + if (clk == es8316->sysclk) 495 + return -EINVAL; 496 + clk = es8316->sysclk; 497 + } else { 498 + clk_valid = true; 499 + } 500 + } while (!clk_valid); 501 + 502 + if (clk != es8316->sysclk) { 503 + snd_soc_component_update_bits(component, ES8316_CLKMGR_CLKSW, 504 + ES8316_CLKMGR_CLKSW_MCLK_DIV, 505 + ES8316_CLKMGR_CLKSW_MCLK_DIV); 481 506 } 482 - if (i == NR_SUPPORTED_MCLK_LRCK_RATIOS) 483 - return -EINVAL; 484 - lrck_divider = es8316->sysclk / params_rate(params); 507 + 508 + lrck_divider = clk / params_rate(params); 485 509 bclk_divider = lrck_divider / 4; 486 510 switch (params_format(params)) { 487 511 case SNDRV_PCM_FORMAT_S16_LE: ··· 548 526 } 549 527 550 528 #define ES8316_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \ 551 - SNDRV_PCM_FMTBIT_S24_LE) 529 + SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE) 552 530 553 531 static const struct snd_soc_dai_ops es8316_ops = { 554 532 .startup = es8316_pcm_startup,
+3
sound/soc/codecs/es8316.h
··· 129 129 #define ES8316_GPIO_FLAG_GM_NOT_SHORTED 0x02 130 130 #define ES8316_GPIO_FLAG_HP_NOT_INSERTED 0x04 131 131 132 + /* ES8316_CLKMGR_CLKSW */ 133 + #define ES8316_CLKMGR_CLKSW_MCLK_DIV 0x80 134 + 132 135 #endif