Path: blob/master/sound/soc/intel/boards/bytcht_es8316.c
53399 views
// SPDX-License-Identifier: GPL-2.0-only1/*2* bytcht_es8316.c - ASoc Machine driver for Intel Baytrail/Cherrytrail3* platforms with Everest ES8316 SoC4*5* Copyright (C) 2017 Endless Mobile, Inc.6* Authors: David Yang <[email protected]>,7* Daniel Drake <[email protected]>8*9* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~10*11* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~12*/13#include <linux/acpi.h>14#include <linux/clk.h>15#include <linux/device.h>16#include <linux/dmi.h>17#include <linux/gpio/consumer.h>18#include <linux/i2c.h>19#include <linux/init.h>20#include <linux/input.h>21#include <linux/module.h>22#include <linux/platform_device.h>23#include <linux/slab.h>24#include <sound/jack.h>25#include <sound/pcm.h>26#include <sound/pcm_params.h>27#include <sound/soc.h>28#include <sound/soc-acpi.h>29#include "../../codecs/es83xx-dsm-common.h"30#include "../atom/sst-atom-controls.h"31#include "../common/soc-intel-quirks.h"3233/* jd-inv + terminating entry */34#define MAX_NO_PROPS 23536struct byt_cht_es8316_private {37struct clk *mclk;38struct snd_soc_jack jack;39struct gpio_desc *speaker_en_gpio;40struct device *codec_dev;41bool speaker_en;42};4344enum {45BYT_CHT_ES8316_INTMIC_IN1_MAP,46BYT_CHT_ES8316_INTMIC_IN2_MAP,47};4849#define BYT_CHT_ES8316_MAP_MASK GENMASK(3, 0)50#define BYT_CHT_ES8316_MAP(quirk) ((quirk) & BYT_CHT_ES8316_MAP_MASK)51#define BYT_CHT_ES8316_SSP0 BIT(16)52#define BYT_CHT_ES8316_MONO_SPEAKER BIT(17)53#define BYT_CHT_ES8316_JD_INVERTED BIT(18)5455static unsigned long quirk;5657static int quirk_override = -1;58module_param_named(quirk, quirk_override, int, 0444);59MODULE_PARM_DESC(quirk, "Board-specific quirk override");6061static void log_quirks(struct device *dev)62{63int map;6465map = BYT_CHT_ES8316_MAP(quirk);66switch (map) {67case BYT_CHT_ES8316_INTMIC_IN1_MAP:68dev_info(dev, "quirk IN1_MAP enabled");69break;70case BYT_CHT_ES8316_INTMIC_IN2_MAP:71dev_info(dev, "quirk IN2_MAP enabled");72break;73default:74dev_warn_once(dev, "quirk sets invalid input map: 0x%x, default to INTMIC_IN1_MAP\n", map);75quirk &= ~BYT_CHT_ES8316_MAP_MASK;76quirk |= BYT_CHT_ES8316_INTMIC_IN1_MAP;77break;78}7980if (quirk & BYT_CHT_ES8316_SSP0)81dev_info(dev, "quirk SSP0 enabled");82if (quirk & BYT_CHT_ES8316_MONO_SPEAKER)83dev_info(dev, "quirk MONO_SPEAKER enabled\n");84if (quirk & BYT_CHT_ES8316_JD_INVERTED)85dev_info(dev, "quirk JD_INVERTED enabled\n");86}8788static int byt_cht_es8316_speaker_power_event(struct snd_soc_dapm_widget *w,89struct snd_kcontrol *kcontrol, int event)90{91struct snd_soc_card *card = snd_soc_dapm_to_card(w->dapm);92struct byt_cht_es8316_private *priv = snd_soc_card_get_drvdata(card);9394if (SND_SOC_DAPM_EVENT_ON(event))95priv->speaker_en = true;96else97priv->speaker_en = false;9899gpiod_set_value_cansleep(priv->speaker_en_gpio, priv->speaker_en);100101return 0;102}103104static const struct snd_soc_dapm_widget byt_cht_es8316_widgets[] = {105SND_SOC_DAPM_SPK("Speaker", NULL),106SND_SOC_DAPM_HP("Headphone", NULL),107SND_SOC_DAPM_MIC("Headset Mic", NULL),108SND_SOC_DAPM_MIC("Internal Mic", NULL),109110SND_SOC_DAPM_SUPPLY("Speaker Power", SND_SOC_NOPM, 0, 0,111byt_cht_es8316_speaker_power_event,112SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU),113};114115static const struct snd_soc_dapm_route byt_cht_es8316_audio_map[] = {116{"Headphone", NULL, "HPOL"},117{"Headphone", NULL, "HPOR"},118119/*120* There is no separate speaker output instead the speakers are muxed to121* the HP outputs. The mux is controlled by the "Speaker Power" supply.122*/123{"Speaker", NULL, "HPOL"},124{"Speaker", NULL, "HPOR"},125{"Speaker", NULL, "Speaker Power"},126};127128static const struct snd_soc_dapm_route byt_cht_es8316_intmic_in1_map[] = {129{"MIC1", NULL, "Internal Mic"},130{"MIC2", NULL, "Headset Mic"},131};132133static const struct snd_soc_dapm_route byt_cht_es8316_intmic_in2_map[] = {134{"MIC2", NULL, "Internal Mic"},135{"MIC1", NULL, "Headset Mic"},136};137138static const struct snd_soc_dapm_route byt_cht_es8316_ssp0_map[] = {139{"Playback", NULL, "ssp0 Tx"},140{"ssp0 Tx", NULL, "modem_out"},141{"modem_in", NULL, "ssp0 Rx"},142{"ssp0 Rx", NULL, "Capture"},143};144145static const struct snd_soc_dapm_route byt_cht_es8316_ssp2_map[] = {146{"Playback", NULL, "ssp2 Tx"},147{"ssp2 Tx", NULL, "codec_out0"},148{"ssp2 Tx", NULL, "codec_out1"},149{"codec_in0", NULL, "ssp2 Rx" },150{"codec_in1", NULL, "ssp2 Rx" },151{"ssp2 Rx", NULL, "Capture"},152};153154static const struct snd_kcontrol_new byt_cht_es8316_controls[] = {155SOC_DAPM_PIN_SWITCH("Speaker"),156SOC_DAPM_PIN_SWITCH("Headphone"),157SOC_DAPM_PIN_SWITCH("Headset Mic"),158SOC_DAPM_PIN_SWITCH("Internal Mic"),159};160161static struct snd_soc_jack_pin byt_cht_es8316_jack_pins[] = {162{163.pin = "Headphone",164.mask = SND_JACK_HEADPHONE,165},166{167.pin = "Headset Mic",168.mask = SND_JACK_MICROPHONE,169},170};171172static int byt_cht_es8316_init(struct snd_soc_pcm_runtime *runtime)173{174struct snd_soc_component *codec = snd_soc_rtd_to_codec(runtime, 0)->component;175struct snd_soc_card *card = runtime->card;176struct snd_soc_dapm_context *dapm = snd_soc_card_to_dapm(card);177struct byt_cht_es8316_private *priv = snd_soc_card_get_drvdata(card);178const struct snd_soc_dapm_route *custom_map;179int num_routes;180int ret;181182snd_soc_dapm_set_idle_bias(dapm, false);183184switch (BYT_CHT_ES8316_MAP(quirk)) {185case BYT_CHT_ES8316_INTMIC_IN1_MAP:186default:187custom_map = byt_cht_es8316_intmic_in1_map;188num_routes = ARRAY_SIZE(byt_cht_es8316_intmic_in1_map);189break;190case BYT_CHT_ES8316_INTMIC_IN2_MAP:191custom_map = byt_cht_es8316_intmic_in2_map;192num_routes = ARRAY_SIZE(byt_cht_es8316_intmic_in2_map);193break;194}195ret = snd_soc_dapm_add_routes(dapm, custom_map, num_routes);196if (ret)197return ret;198199if (quirk & BYT_CHT_ES8316_SSP0) {200custom_map = byt_cht_es8316_ssp0_map;201num_routes = ARRAY_SIZE(byt_cht_es8316_ssp0_map);202} else {203custom_map = byt_cht_es8316_ssp2_map;204num_routes = ARRAY_SIZE(byt_cht_es8316_ssp2_map);205}206ret = snd_soc_dapm_add_routes(dapm, custom_map, num_routes);207if (ret)208return ret;209210/*211* The firmware might enable the clock at boot (this information212* may or may not be reflected in the enable clock register).213* To change the rate we must disable the clock first to cover these214* cases. Due to common clock framework restrictions that do not allow215* to disable a clock that has not been enabled, we need to enable216* the clock first.217*/218ret = clk_prepare_enable(priv->mclk);219if (!ret)220clk_disable_unprepare(priv->mclk);221222ret = clk_set_rate(priv->mclk, 19200000);223if (ret)224dev_err(card->dev, "unable to set MCLK rate\n");225226ret = clk_prepare_enable(priv->mclk);227if (ret)228dev_err(card->dev, "unable to enable MCLK\n");229230ret = snd_soc_dai_set_sysclk(snd_soc_rtd_to_codec(runtime, 0), 0, 19200000,231SND_SOC_CLOCK_IN);232if (ret < 0) {233dev_err(card->dev, "can't set codec clock %d\n", ret);234return ret;235}236237ret = snd_soc_card_jack_new_pins(card, "Headset",238SND_JACK_HEADSET | SND_JACK_BTN_0,239&priv->jack, byt_cht_es8316_jack_pins,240ARRAY_SIZE(byt_cht_es8316_jack_pins));241if (ret) {242dev_err(card->dev, "jack creation failed %d\n", ret);243return ret;244}245246snd_jack_set_key(priv->jack.jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);247snd_soc_component_set_jack(codec, &priv->jack, NULL);248249return 0;250}251252static int byt_cht_es8316_codec_fixup(struct snd_soc_pcm_runtime *rtd,253struct snd_pcm_hw_params *params)254{255struct snd_interval *rate = hw_param_interval(params,256SNDRV_PCM_HW_PARAM_RATE);257struct snd_interval *channels = hw_param_interval(params,258SNDRV_PCM_HW_PARAM_CHANNELS);259int ret, bits;260261/* The DSP will convert the FE rate to 48k, stereo */262rate->min = rate->max = 48000;263channels->min = channels->max = 2;264265if (quirk & BYT_CHT_ES8316_SSP0) {266/* set SSP0 to 16-bit */267params_set_format(params, SNDRV_PCM_FORMAT_S16_LE);268bits = 16;269} else {270/* set SSP2 to 24-bit */271params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);272bits = 24;273}274275/*276* Default mode for SSP configuration is TDM 4 slot, override config277* with explicit setting to I2S 2ch 24-bit. The word length is set with278* dai_set_tdm_slot() since there is no other API exposed279*/280ret = snd_soc_dai_set_fmt(snd_soc_rtd_to_cpu(rtd, 0),281SND_SOC_DAIFMT_I2S |282SND_SOC_DAIFMT_NB_NF |283SND_SOC_DAIFMT_BP_FP284);285if (ret < 0) {286dev_err(rtd->dev, "can't set format to I2S, err %d\n", ret);287return ret;288}289290ret = snd_soc_dai_set_tdm_slot(snd_soc_rtd_to_cpu(rtd, 0), 0x3, 0x3, 2, bits);291if (ret < 0) {292dev_err(rtd->dev, "can't set I2S config, err %d\n", ret);293return ret;294}295296return 0;297}298299static int byt_cht_es8316_aif1_startup(struct snd_pcm_substream *substream)300{301return snd_pcm_hw_constraint_single(substream->runtime,302SNDRV_PCM_HW_PARAM_RATE, 48000);303}304305static const struct snd_soc_ops byt_cht_es8316_aif1_ops = {306.startup = byt_cht_es8316_aif1_startup,307};308309SND_SOC_DAILINK_DEF(dummy,310DAILINK_COMP_ARRAY(COMP_DUMMY()));311312SND_SOC_DAILINK_DEF(media,313DAILINK_COMP_ARRAY(COMP_CPU("media-cpu-dai")));314315SND_SOC_DAILINK_DEF(deepbuffer,316DAILINK_COMP_ARRAY(COMP_CPU("deepbuffer-cpu-dai")));317318SND_SOC_DAILINK_DEF(ssp2_port,319DAILINK_COMP_ARRAY(COMP_CPU("ssp2-port")));320SND_SOC_DAILINK_DEF(ssp2_codec,321DAILINK_COMP_ARRAY(COMP_CODEC("i2c-ESSX8316:00", "ES8316 HiFi")));322323SND_SOC_DAILINK_DEF(platform,324DAILINK_COMP_ARRAY(COMP_PLATFORM("sst-mfld-platform")));325326static struct snd_soc_dai_link byt_cht_es8316_dais[] = {327[MERR_DPCM_AUDIO] = {328.name = "Audio Port",329.stream_name = "Audio",330.nonatomic = true,331.dynamic = 1,332.ops = &byt_cht_es8316_aif1_ops,333SND_SOC_DAILINK_REG(media, dummy, platform),334},335336[MERR_DPCM_DEEP_BUFFER] = {337.name = "Deep-Buffer Audio Port",338.stream_name = "Deep-Buffer Audio",339.nonatomic = true,340.dynamic = 1,341.playback_only = 1,342.ops = &byt_cht_es8316_aif1_ops,343SND_SOC_DAILINK_REG(deepbuffer, dummy, platform),344},345346/* back ends */347{348.name = "SSP2-Codec",349.id = 0,350.no_pcm = 1,351.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF352| SND_SOC_DAIFMT_CBC_CFC,353.be_hw_params_fixup = byt_cht_es8316_codec_fixup,354.init = byt_cht_es8316_init,355SND_SOC_DAILINK_REG(ssp2_port, ssp2_codec, platform),356},357};358359360/* SoC card */361static char codec_name[SND_ACPI_I2C_ID_LEN];362#if !IS_ENABLED(CONFIG_SND_SOC_INTEL_USER_FRIENDLY_LONG_NAMES)363static char long_name[50]; /* = "bytcht-es8316-*-spk-*-mic" */364#endif365static char components_string[32]; /* = "cfg-spk:* cfg-mic:* */366367static int byt_cht_es8316_suspend(struct snd_soc_card *card)368{369struct snd_soc_component *component;370371for_each_card_components(card, component) {372if (!strcmp(component->name, codec_name)) {373dev_dbg(component->dev, "disabling jack detect before suspend\n");374snd_soc_component_set_jack(component, NULL, NULL);375break;376}377}378379return 0;380}381382static int byt_cht_es8316_resume(struct snd_soc_card *card)383{384struct byt_cht_es8316_private *priv = snd_soc_card_get_drvdata(card);385struct snd_soc_component *component;386387for_each_card_components(card, component) {388if (!strcmp(component->name, codec_name)) {389dev_dbg(component->dev, "re-enabling jack detect after resume\n");390snd_soc_component_set_jack(component, &priv->jack, NULL);391break;392}393}394395/*396* Some Cherry Trail boards with an ES8316 codec have a bug in their397* ACPI tables where the MSSL1680 touchscreen's _PS0 and _PS3 methods398* wrongly also set the speaker-enable GPIO to 1/0. Testing has shown399* that this really is a bug and the GPIO has no influence on the400* touchscreen at all.401*402* The silead.c touchscreen driver does not support runtime suspend, so403* the GPIO can only be changed underneath us during a system suspend.404* This resume() function runs from a pm complete() callback, and thus405* is guaranteed to run after the touchscreen driver/ACPI-subsys has406* brought the touchscreen back up again (and thus changed the GPIO).407*408* So to work around this we pass GPIOD_FLAGS_BIT_NONEXCLUSIVE when409* requesting the GPIO and we set its value here to undo any changes410* done by the touchscreen's broken _PS0 ACPI method.411*/412gpiod_set_value_cansleep(priv->speaker_en_gpio, priv->speaker_en);413414return 0;415}416417/* use space before codec name to simplify card ID, and simplify driver name */418#define SOF_CARD_NAME "bytcht es8316" /* card name will be 'sof-bytcht es8316' */419#define SOF_DRIVER_NAME "SOF"420421#define CARD_NAME "bytcht-es8316"422#define DRIVER_NAME NULL /* card name will be used for driver name */423424static struct snd_soc_card byt_cht_es8316_card = {425.owner = THIS_MODULE,426.dai_link = byt_cht_es8316_dais,427.num_links = ARRAY_SIZE(byt_cht_es8316_dais),428.dapm_widgets = byt_cht_es8316_widgets,429.num_dapm_widgets = ARRAY_SIZE(byt_cht_es8316_widgets),430.dapm_routes = byt_cht_es8316_audio_map,431.num_dapm_routes = ARRAY_SIZE(byt_cht_es8316_audio_map),432.controls = byt_cht_es8316_controls,433.num_controls = ARRAY_SIZE(byt_cht_es8316_controls),434.fully_routed = true,435.suspend_pre = byt_cht_es8316_suspend,436.resume_post = byt_cht_es8316_resume,437};438439static const struct acpi_gpio_params first_gpio = { 0, 0, false };440441static const struct acpi_gpio_mapping byt_cht_es8316_gpios[] = {442{ "speaker-enable-gpios", &first_gpio, 1 },443{ },444};445446/* Please keep this list alphabetically sorted */447static const struct dmi_system_id byt_cht_es8316_quirk_table[] = {448{ /* Irbis NB41 */449.matches = {450DMI_MATCH(DMI_SYS_VENDOR, "IRBIS"),451DMI_MATCH(DMI_PRODUCT_NAME, "NB41"),452},453.driver_data = (void *)(BYT_CHT_ES8316_SSP0454| BYT_CHT_ES8316_INTMIC_IN2_MAP455| BYT_CHT_ES8316_JD_INVERTED),456},457{ /* Nanote UMPC-01 */458.matches = {459DMI_MATCH(DMI_SYS_VENDOR, "RWC CO.,LTD"),460DMI_MATCH(DMI_PRODUCT_NAME, "UMPC-01"),461},462.driver_data = (void *)BYT_CHT_ES8316_INTMIC_IN1_MAP,463},464{ /* Teclast X98 Plus II */465.matches = {466DMI_MATCH(DMI_SYS_VENDOR, "TECLAST"),467DMI_MATCH(DMI_PRODUCT_NAME, "X98 Plus II"),468},469.driver_data = (void *)(BYT_CHT_ES8316_INTMIC_IN1_MAP470| BYT_CHT_ES8316_JD_INVERTED),471},472{}473};474475static int byt_cht_es8316_get_quirks_from_dsm(struct byt_cht_es8316_private *priv,476bool is_bytcr)477{478int ret, val1, val2, dsm_quirk = 0;479480if (is_bytcr)481dsm_quirk |= BYT_CHT_ES8316_SSP0;482483ret = es83xx_dsm(priv->codec_dev, PLATFORM_MAINMIC_TYPE_ARG, &val1);484if (ret < 0)485return ret;486487ret = es83xx_dsm(priv->codec_dev, PLATFORM_HPMIC_TYPE_ARG, &val2);488if (ret < 0)489return ret;490491if (val1 == PLATFORM_MIC_AMIC_LIN1RIN1 && val2 == PLATFORM_MIC_AMIC_LIN2RIN2) {492dsm_quirk |= BYT_CHT_ES8316_INTMIC_IN1_MAP;493} else if (val1 == PLATFORM_MIC_AMIC_LIN2RIN2 && val2 == PLATFORM_MIC_AMIC_LIN1RIN1) {494dsm_quirk |= BYT_CHT_ES8316_INTMIC_IN2_MAP;495} else {496dev_warn(priv->codec_dev, "Unknown mic settings mainmic 0x%02x hpmic 0x%02x\n",497val1, val2);498return -EINVAL;499}500501ret = es83xx_dsm(priv->codec_dev, PLATFORM_SPK_TYPE_ARG, &val1);502if (ret < 0)503return ret;504505switch (val1) {506case PLATFORM_SPK_MONO:507dsm_quirk |= BYT_CHT_ES8316_MONO_SPEAKER;508break;509case PLATFORM_SPK_STEREO:510break;511default:512dev_warn(priv->codec_dev, "Unknown speaker setting 0x%02x\n", val1);513return -EINVAL;514}515516ret = es83xx_dsm(priv->codec_dev, PLATFORM_HPDET_INV_ARG, &val1);517if (ret < 0)518return ret;519520switch (val1) {521case PLATFORM_HPDET_NORMAL:522break;523case PLATFORM_HPDET_INVERTED:524dsm_quirk |= BYT_CHT_ES8316_JD_INVERTED;525break;526default:527dev_warn(priv->codec_dev, "Unknown hpdet-inv setting 0x%02x\n", val1);528return -EINVAL;529}530531quirk = dsm_quirk;532return 0;533}534535static int snd_byt_cht_es8316_mc_probe(struct platform_device *pdev)536{537struct device *dev = &pdev->dev;538static const char * const mic_name[] = { "in1", "in2" };539struct snd_soc_acpi_mach *mach = dev_get_platdata(dev);540struct property_entry props[MAX_NO_PROPS] = {};541struct byt_cht_es8316_private *priv;542const struct dmi_system_id *dmi_id;543struct fwnode_handle *fwnode;544bool sof_parent, is_bytcr;545const char *platform_name;546struct acpi_device *adev;547struct device *codec_dev;548unsigned int cnt = 0;549int dai_index = 0;550int i;551int ret = 0;552553priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);554if (!priv)555return -ENOMEM;556557/* fix index of codec dai */558for (i = 0; i < ARRAY_SIZE(byt_cht_es8316_dais); i++) {559if (byt_cht_es8316_dais[i].num_codecs &&560!strcmp(byt_cht_es8316_dais[i].codecs->name,561"i2c-ESSX8316:00")) {562dai_index = i;563break;564}565}566567/* fixup codec name based on HID */568adev = acpi_dev_get_first_match_dev(mach->id, NULL, -1);569if (adev) {570snprintf(codec_name, sizeof(codec_name),571"i2c-%s", acpi_dev_name(adev));572byt_cht_es8316_dais[dai_index].codecs->name = codec_name;573} else {574dev_err(dev, "Error cannot find '%s' dev\n", mach->id);575return -ENOENT;576}577578codec_dev = acpi_get_first_physical_node(adev);579acpi_dev_put(adev);580if (!codec_dev)581return -EPROBE_DEFER;582priv->codec_dev = get_device(codec_dev);583584/* override platform name, if required */585byt_cht_es8316_card.dev = dev;586platform_name = mach->mach_params.platform;587588ret = snd_soc_fixup_dai_links_platform_name(&byt_cht_es8316_card,589platform_name);590if (ret) {591put_device(codec_dev);592return ret;593}594595es83xx_dsm_dump(priv->codec_dev);596597/* Check for BYTCR or other platform and setup quirks */598is_bytcr = soc_intel_is_byt() && mach->mach_params.acpi_ipc_irq_index == 0;599dmi_id = dmi_first_match(byt_cht_es8316_quirk_table);600if (dmi_id) {601quirk = (unsigned long)dmi_id->driver_data;602} else if (!byt_cht_es8316_get_quirks_from_dsm(priv, is_bytcr)) {603dev_info(dev, "Using ACPI DSM info for quirks\n");604} else if (is_bytcr) {605/* On BYTCR default to SSP0, internal-mic-in2-map, mono-spk */606quirk = BYT_CHT_ES8316_SSP0 | BYT_CHT_ES8316_INTMIC_IN2_MAP |607BYT_CHT_ES8316_MONO_SPEAKER;608} else {609/* Others default to internal-mic-in1-map, mono-speaker */610quirk = BYT_CHT_ES8316_INTMIC_IN1_MAP |611BYT_CHT_ES8316_MONO_SPEAKER;612}613if (quirk_override != -1) {614dev_info(dev, "Overriding quirk 0x%lx => 0x%x\n",615quirk, quirk_override);616quirk = quirk_override;617}618log_quirks(dev);619620if (quirk & BYT_CHT_ES8316_SSP0)621byt_cht_es8316_dais[dai_index].cpus->dai_name = "ssp0-port";622623/* get the clock */624priv->mclk = devm_clk_get(dev, "pmc_plt_clk_3");625if (IS_ERR(priv->mclk)) {626put_device(codec_dev);627return dev_err_probe(dev, PTR_ERR(priv->mclk), "clk_get pmc_plt_clk_3 failed\n");628}629630if (quirk & BYT_CHT_ES8316_JD_INVERTED)631props[cnt++] = PROPERTY_ENTRY_BOOL("everest,jack-detect-inverted");632633if (cnt) {634fwnode = fwnode_create_software_node(props, NULL);635if (IS_ERR(fwnode)) {636put_device(codec_dev);637return PTR_ERR(fwnode);638}639640ret = device_add_software_node(codec_dev, to_software_node(fwnode));641642fwnode_handle_put(fwnode);643644if (ret) {645put_device(codec_dev);646return ret;647}648}649650/* get speaker enable GPIO */651devm_acpi_dev_add_driver_gpios(codec_dev, byt_cht_es8316_gpios);652priv->speaker_en_gpio =653gpiod_get_optional(codec_dev, "speaker-enable",654/* see comment in byt_cht_es8316_resume() */655GPIOD_OUT_LOW | GPIOD_FLAGS_BIT_NONEXCLUSIVE);656if (IS_ERR(priv->speaker_en_gpio)) {657ret = dev_err_probe(dev, PTR_ERR(priv->speaker_en_gpio),658"get speaker GPIO failed\n");659goto err_put_codec;660}661662snprintf(components_string, sizeof(components_string),663"cfg-spk:%s cfg-mic:%s",664(quirk & BYT_CHT_ES8316_MONO_SPEAKER) ? "1" : "2",665mic_name[BYT_CHT_ES8316_MAP(quirk)]);666byt_cht_es8316_card.components = components_string;667#if !IS_ENABLED(CONFIG_SND_SOC_INTEL_USER_FRIENDLY_LONG_NAMES)668snprintf(long_name, sizeof(long_name), "bytcht-es8316-%s-spk-%s-mic",669(quirk & BYT_CHT_ES8316_MONO_SPEAKER) ? "mono" : "stereo",670mic_name[BYT_CHT_ES8316_MAP(quirk)]);671byt_cht_es8316_card.long_name = long_name;672#endif673674sof_parent = snd_soc_acpi_sof_parent(dev);675676/* set card and driver name */677if (sof_parent) {678byt_cht_es8316_card.name = SOF_CARD_NAME;679byt_cht_es8316_card.driver_name = SOF_DRIVER_NAME;680} else {681byt_cht_es8316_card.name = CARD_NAME;682byt_cht_es8316_card.driver_name = DRIVER_NAME;683}684685/* set pm ops */686if (sof_parent)687dev->driver->pm = &snd_soc_pm_ops;688689/* register the soc card */690snd_soc_card_set_drvdata(&byt_cht_es8316_card, priv);691692ret = devm_snd_soc_register_card(dev, &byt_cht_es8316_card);693if (ret) {694gpiod_put(priv->speaker_en_gpio);695dev_err(dev, "snd_soc_register_card failed: %d\n", ret);696goto err_put_codec;697}698platform_set_drvdata(pdev, &byt_cht_es8316_card);699return 0;700701err_put_codec:702device_remove_software_node(priv->codec_dev);703put_device(priv->codec_dev);704return ret;705}706707static void snd_byt_cht_es8316_mc_remove(struct platform_device *pdev)708{709struct snd_soc_card *card = platform_get_drvdata(pdev);710struct byt_cht_es8316_private *priv = snd_soc_card_get_drvdata(card);711712gpiod_put(priv->speaker_en_gpio);713device_remove_software_node(priv->codec_dev);714put_device(priv->codec_dev);715}716717static struct platform_driver snd_byt_cht_es8316_mc_driver = {718.driver = {719.name = "bytcht_es8316",720},721.probe = snd_byt_cht_es8316_mc_probe,722.remove = snd_byt_cht_es8316_mc_remove,723};724725module_platform_driver(snd_byt_cht_es8316_mc_driver);726MODULE_DESCRIPTION("ASoC Intel(R) Baytrail/Cherrytrail Machine driver");727MODULE_AUTHOR("David Yang <[email protected]>");728MODULE_LICENSE("GPL v2");729MODULE_ALIAS("platform:bytcht_es8316");730731732