Path: blob/master/sound/soc/intel/boards/bytcht_es8316.c
29268 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 = w->dapm->card;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 byt_cht_es8316_private *priv = snd_soc_card_get_drvdata(card);177const struct snd_soc_dapm_route *custom_map;178int num_routes;179int ret;180181card->dapm.idle_bias = false;182183switch (BYT_CHT_ES8316_MAP(quirk)) {184case BYT_CHT_ES8316_INTMIC_IN1_MAP:185default:186custom_map = byt_cht_es8316_intmic_in1_map;187num_routes = ARRAY_SIZE(byt_cht_es8316_intmic_in1_map);188break;189case BYT_CHT_ES8316_INTMIC_IN2_MAP:190custom_map = byt_cht_es8316_intmic_in2_map;191num_routes = ARRAY_SIZE(byt_cht_es8316_intmic_in2_map);192break;193}194ret = snd_soc_dapm_add_routes(&card->dapm, custom_map, num_routes);195if (ret)196return ret;197198if (quirk & BYT_CHT_ES8316_SSP0) {199custom_map = byt_cht_es8316_ssp0_map;200num_routes = ARRAY_SIZE(byt_cht_es8316_ssp0_map);201} else {202custom_map = byt_cht_es8316_ssp2_map;203num_routes = ARRAY_SIZE(byt_cht_es8316_ssp2_map);204}205ret = snd_soc_dapm_add_routes(&card->dapm, custom_map, num_routes);206if (ret)207return ret;208209/*210* The firmware might enable the clock at boot (this information211* may or may not be reflected in the enable clock register).212* To change the rate we must disable the clock first to cover these213* cases. Due to common clock framework restrictions that do not allow214* to disable a clock that has not been enabled, we need to enable215* the clock first.216*/217ret = clk_prepare_enable(priv->mclk);218if (!ret)219clk_disable_unprepare(priv->mclk);220221ret = clk_set_rate(priv->mclk, 19200000);222if (ret)223dev_err(card->dev, "unable to set MCLK rate\n");224225ret = clk_prepare_enable(priv->mclk);226if (ret)227dev_err(card->dev, "unable to enable MCLK\n");228229ret = snd_soc_dai_set_sysclk(snd_soc_rtd_to_codec(runtime, 0), 0, 19200000,230SND_SOC_CLOCK_IN);231if (ret < 0) {232dev_err(card->dev, "can't set codec clock %d\n", ret);233return ret;234}235236ret = snd_soc_card_jack_new_pins(card, "Headset",237SND_JACK_HEADSET | SND_JACK_BTN_0,238&priv->jack, byt_cht_es8316_jack_pins,239ARRAY_SIZE(byt_cht_es8316_jack_pins));240if (ret) {241dev_err(card->dev, "jack creation failed %d\n", ret);242return ret;243}244245snd_jack_set_key(priv->jack.jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);246snd_soc_component_set_jack(codec, &priv->jack, NULL);247248return 0;249}250251static int byt_cht_es8316_codec_fixup(struct snd_soc_pcm_runtime *rtd,252struct snd_pcm_hw_params *params)253{254struct snd_interval *rate = hw_param_interval(params,255SNDRV_PCM_HW_PARAM_RATE);256struct snd_interval *channels = hw_param_interval(params,257SNDRV_PCM_HW_PARAM_CHANNELS);258int ret, bits;259260/* The DSP will convert the FE rate to 48k, stereo */261rate->min = rate->max = 48000;262channels->min = channels->max = 2;263264if (quirk & BYT_CHT_ES8316_SSP0) {265/* set SSP0 to 16-bit */266params_set_format(params, SNDRV_PCM_FORMAT_S16_LE);267bits = 16;268} else {269/* set SSP2 to 24-bit */270params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);271bits = 24;272}273274/*275* Default mode for SSP configuration is TDM 4 slot, override config276* with explicit setting to I2S 2ch 24-bit. The word length is set with277* dai_set_tdm_slot() since there is no other API exposed278*/279ret = snd_soc_dai_set_fmt(snd_soc_rtd_to_cpu(rtd, 0),280SND_SOC_DAIFMT_I2S |281SND_SOC_DAIFMT_NB_NF |282SND_SOC_DAIFMT_BP_FP283);284if (ret < 0) {285dev_err(rtd->dev, "can't set format to I2S, err %d\n", ret);286return ret;287}288289ret = snd_soc_dai_set_tdm_slot(snd_soc_rtd_to_cpu(rtd, 0), 0x3, 0x3, 2, bits);290if (ret < 0) {291dev_err(rtd->dev, "can't set I2S config, err %d\n", ret);292return ret;293}294295return 0;296}297298static int byt_cht_es8316_aif1_startup(struct snd_pcm_substream *substream)299{300return snd_pcm_hw_constraint_single(substream->runtime,301SNDRV_PCM_HW_PARAM_RATE, 48000);302}303304static const struct snd_soc_ops byt_cht_es8316_aif1_ops = {305.startup = byt_cht_es8316_aif1_startup,306};307308SND_SOC_DAILINK_DEF(dummy,309DAILINK_COMP_ARRAY(COMP_DUMMY()));310311SND_SOC_DAILINK_DEF(media,312DAILINK_COMP_ARRAY(COMP_CPU("media-cpu-dai")));313314SND_SOC_DAILINK_DEF(deepbuffer,315DAILINK_COMP_ARRAY(COMP_CPU("deepbuffer-cpu-dai")));316317SND_SOC_DAILINK_DEF(ssp2_port,318DAILINK_COMP_ARRAY(COMP_CPU("ssp2-port")));319SND_SOC_DAILINK_DEF(ssp2_codec,320DAILINK_COMP_ARRAY(COMP_CODEC("i2c-ESSX8316:00", "ES8316 HiFi")));321322SND_SOC_DAILINK_DEF(platform,323DAILINK_COMP_ARRAY(COMP_PLATFORM("sst-mfld-platform")));324325static struct snd_soc_dai_link byt_cht_es8316_dais[] = {326[MERR_DPCM_AUDIO] = {327.name = "Audio Port",328.stream_name = "Audio",329.nonatomic = true,330.dynamic = 1,331.ops = &byt_cht_es8316_aif1_ops,332SND_SOC_DAILINK_REG(media, dummy, platform),333},334335[MERR_DPCM_DEEP_BUFFER] = {336.name = "Deep-Buffer Audio Port",337.stream_name = "Deep-Buffer Audio",338.nonatomic = true,339.dynamic = 1,340.playback_only = 1,341.ops = &byt_cht_es8316_aif1_ops,342SND_SOC_DAILINK_REG(deepbuffer, dummy, platform),343},344345/* back ends */346{347.name = "SSP2-Codec",348.id = 0,349.no_pcm = 1,350.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF351| SND_SOC_DAIFMT_CBC_CFC,352.be_hw_params_fixup = byt_cht_es8316_codec_fixup,353.init = byt_cht_es8316_init,354SND_SOC_DAILINK_REG(ssp2_port, ssp2_codec, platform),355},356};357358359/* SoC card */360static char codec_name[SND_ACPI_I2C_ID_LEN];361#if !IS_ENABLED(CONFIG_SND_SOC_INTEL_USER_FRIENDLY_LONG_NAMES)362static char long_name[50]; /* = "bytcht-es8316-*-spk-*-mic" */363#endif364static char components_string[32]; /* = "cfg-spk:* cfg-mic:* */365366static int byt_cht_es8316_suspend(struct snd_soc_card *card)367{368struct snd_soc_component *component;369370for_each_card_components(card, component) {371if (!strcmp(component->name, codec_name)) {372dev_dbg(component->dev, "disabling jack detect before suspend\n");373snd_soc_component_set_jack(component, NULL, NULL);374break;375}376}377378return 0;379}380381static int byt_cht_es8316_resume(struct snd_soc_card *card)382{383struct byt_cht_es8316_private *priv = snd_soc_card_get_drvdata(card);384struct snd_soc_component *component;385386for_each_card_components(card, component) {387if (!strcmp(component->name, codec_name)) {388dev_dbg(component->dev, "re-enabling jack detect after resume\n");389snd_soc_component_set_jack(component, &priv->jack, NULL);390break;391}392}393394/*395* Some Cherry Trail boards with an ES8316 codec have a bug in their396* ACPI tables where the MSSL1680 touchscreen's _PS0 and _PS3 methods397* wrongly also set the speaker-enable GPIO to 1/0. Testing has shown398* that this really is a bug and the GPIO has no influence on the399* touchscreen at all.400*401* The silead.c touchscreen driver does not support runtime suspend, so402* the GPIO can only be changed underneath us during a system suspend.403* This resume() function runs from a pm complete() callback, and thus404* is guaranteed to run after the touchscreen driver/ACPI-subsys has405* brought the touchscreen back up again (and thus changed the GPIO).406*407* So to work around this we pass GPIOD_FLAGS_BIT_NONEXCLUSIVE when408* requesting the GPIO and we set its value here to undo any changes409* done by the touchscreen's broken _PS0 ACPI method.410*/411gpiod_set_value_cansleep(priv->speaker_en_gpio, priv->speaker_en);412413return 0;414}415416/* use space before codec name to simplify card ID, and simplify driver name */417#define SOF_CARD_NAME "bytcht es8316" /* card name will be 'sof-bytcht es8316' */418#define SOF_DRIVER_NAME "SOF"419420#define CARD_NAME "bytcht-es8316"421#define DRIVER_NAME NULL /* card name will be used for driver name */422423static struct snd_soc_card byt_cht_es8316_card = {424.owner = THIS_MODULE,425.dai_link = byt_cht_es8316_dais,426.num_links = ARRAY_SIZE(byt_cht_es8316_dais),427.dapm_widgets = byt_cht_es8316_widgets,428.num_dapm_widgets = ARRAY_SIZE(byt_cht_es8316_widgets),429.dapm_routes = byt_cht_es8316_audio_map,430.num_dapm_routes = ARRAY_SIZE(byt_cht_es8316_audio_map),431.controls = byt_cht_es8316_controls,432.num_controls = ARRAY_SIZE(byt_cht_es8316_controls),433.fully_routed = true,434.suspend_pre = byt_cht_es8316_suspend,435.resume_post = byt_cht_es8316_resume,436};437438static const struct acpi_gpio_params first_gpio = { 0, 0, false };439440static const struct acpi_gpio_mapping byt_cht_es8316_gpios[] = {441{ "speaker-enable-gpios", &first_gpio, 1 },442{ },443};444445/* Please keep this list alphabetically sorted */446static const struct dmi_system_id byt_cht_es8316_quirk_table[] = {447{ /* Irbis NB41 */448.matches = {449DMI_MATCH(DMI_SYS_VENDOR, "IRBIS"),450DMI_MATCH(DMI_PRODUCT_NAME, "NB41"),451},452.driver_data = (void *)(BYT_CHT_ES8316_SSP0453| BYT_CHT_ES8316_INTMIC_IN2_MAP454| BYT_CHT_ES8316_JD_INVERTED),455},456{ /* Nanote UMPC-01 */457.matches = {458DMI_MATCH(DMI_SYS_VENDOR, "RWC CO.,LTD"),459DMI_MATCH(DMI_PRODUCT_NAME, "UMPC-01"),460},461.driver_data = (void *)BYT_CHT_ES8316_INTMIC_IN1_MAP,462},463{ /* Teclast X98 Plus II */464.matches = {465DMI_MATCH(DMI_SYS_VENDOR, "TECLAST"),466DMI_MATCH(DMI_PRODUCT_NAME, "X98 Plus II"),467},468.driver_data = (void *)(BYT_CHT_ES8316_INTMIC_IN1_MAP469| BYT_CHT_ES8316_JD_INVERTED),470},471{}472};473474static int byt_cht_es8316_get_quirks_from_dsm(struct byt_cht_es8316_private *priv,475bool is_bytcr)476{477int ret, val1, val2, dsm_quirk = 0;478479if (is_bytcr)480dsm_quirk |= BYT_CHT_ES8316_SSP0;481482ret = es83xx_dsm(priv->codec_dev, PLATFORM_MAINMIC_TYPE_ARG, &val1);483if (ret < 0)484return ret;485486ret = es83xx_dsm(priv->codec_dev, PLATFORM_HPMIC_TYPE_ARG, &val2);487if (ret < 0)488return ret;489490if (val1 == PLATFORM_MIC_AMIC_LIN1RIN1 && val2 == PLATFORM_MIC_AMIC_LIN2RIN2) {491dsm_quirk |= BYT_CHT_ES8316_INTMIC_IN1_MAP;492} else if (val1 == PLATFORM_MIC_AMIC_LIN2RIN2 && val2 == PLATFORM_MIC_AMIC_LIN1RIN1) {493dsm_quirk |= BYT_CHT_ES8316_INTMIC_IN2_MAP;494} else {495dev_warn(priv->codec_dev, "Unknown mic settings mainmic 0x%02x hpmic 0x%02x\n",496val1, val2);497return -EINVAL;498}499500ret = es83xx_dsm(priv->codec_dev, PLATFORM_SPK_TYPE_ARG, &val1);501if (ret < 0)502return ret;503504switch (val1) {505case PLATFORM_SPK_MONO:506dsm_quirk |= BYT_CHT_ES8316_MONO_SPEAKER;507break;508case PLATFORM_SPK_STEREO:509break;510default:511dev_warn(priv->codec_dev, "Unknown speaker setting 0x%02x\n", val1);512return -EINVAL;513}514515ret = es83xx_dsm(priv->codec_dev, PLATFORM_HPDET_INV_ARG, &val1);516if (ret < 0)517return ret;518519switch (val1) {520case PLATFORM_HPDET_NORMAL:521break;522case PLATFORM_HPDET_INVERTED:523dsm_quirk |= BYT_CHT_ES8316_JD_INVERTED;524break;525default:526dev_warn(priv->codec_dev, "Unknown hpdet-inv setting 0x%02x\n", val1);527return -EINVAL;528}529530quirk = dsm_quirk;531return 0;532}533534static int snd_byt_cht_es8316_mc_probe(struct platform_device *pdev)535{536struct device *dev = &pdev->dev;537static const char * const mic_name[] = { "in1", "in2" };538struct snd_soc_acpi_mach *mach = dev_get_platdata(dev);539struct property_entry props[MAX_NO_PROPS] = {};540struct byt_cht_es8316_private *priv;541const struct dmi_system_id *dmi_id;542struct fwnode_handle *fwnode;543bool sof_parent, is_bytcr;544const char *platform_name;545struct acpi_device *adev;546struct device *codec_dev;547unsigned int cnt = 0;548int dai_index = 0;549int i;550int ret = 0;551552priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);553if (!priv)554return -ENOMEM;555556/* fix index of codec dai */557for (i = 0; i < ARRAY_SIZE(byt_cht_es8316_dais); i++) {558if (byt_cht_es8316_dais[i].num_codecs &&559!strcmp(byt_cht_es8316_dais[i].codecs->name,560"i2c-ESSX8316:00")) {561dai_index = i;562break;563}564}565566/* fixup codec name based on HID */567adev = acpi_dev_get_first_match_dev(mach->id, NULL, -1);568if (adev) {569snprintf(codec_name, sizeof(codec_name),570"i2c-%s", acpi_dev_name(adev));571byt_cht_es8316_dais[dai_index].codecs->name = codec_name;572} else {573dev_err(dev, "Error cannot find '%s' dev\n", mach->id);574return -ENOENT;575}576577codec_dev = acpi_get_first_physical_node(adev);578acpi_dev_put(adev);579if (!codec_dev)580return -EPROBE_DEFER;581priv->codec_dev = get_device(codec_dev);582583/* override platform name, if required */584byt_cht_es8316_card.dev = dev;585platform_name = mach->mach_params.platform;586587ret = snd_soc_fixup_dai_links_platform_name(&byt_cht_es8316_card,588platform_name);589if (ret) {590put_device(codec_dev);591return ret;592}593594es83xx_dsm_dump(priv->codec_dev);595596/* Check for BYTCR or other platform and setup quirks */597is_bytcr = soc_intel_is_byt() && mach->mach_params.acpi_ipc_irq_index == 0;598dmi_id = dmi_first_match(byt_cht_es8316_quirk_table);599if (dmi_id) {600quirk = (unsigned long)dmi_id->driver_data;601} else if (!byt_cht_es8316_get_quirks_from_dsm(priv, is_bytcr)) {602dev_info(dev, "Using ACPI DSM info for quirks\n");603} else if (is_bytcr) {604/* On BYTCR default to SSP0, internal-mic-in2-map, mono-spk */605quirk = BYT_CHT_ES8316_SSP0 | BYT_CHT_ES8316_INTMIC_IN2_MAP |606BYT_CHT_ES8316_MONO_SPEAKER;607} else {608/* Others default to internal-mic-in1-map, mono-speaker */609quirk = BYT_CHT_ES8316_INTMIC_IN1_MAP |610BYT_CHT_ES8316_MONO_SPEAKER;611}612if (quirk_override != -1) {613dev_info(dev, "Overriding quirk 0x%lx => 0x%x\n",614quirk, quirk_override);615quirk = quirk_override;616}617log_quirks(dev);618619if (quirk & BYT_CHT_ES8316_SSP0)620byt_cht_es8316_dais[dai_index].cpus->dai_name = "ssp0-port";621622/* get the clock */623priv->mclk = devm_clk_get(dev, "pmc_plt_clk_3");624if (IS_ERR(priv->mclk)) {625put_device(codec_dev);626return dev_err_probe(dev, PTR_ERR(priv->mclk), "clk_get pmc_plt_clk_3 failed\n");627}628629if (quirk & BYT_CHT_ES8316_JD_INVERTED)630props[cnt++] = PROPERTY_ENTRY_BOOL("everest,jack-detect-inverted");631632if (cnt) {633fwnode = fwnode_create_software_node(props, NULL);634if (IS_ERR(fwnode)) {635put_device(codec_dev);636return PTR_ERR(fwnode);637}638639ret = device_add_software_node(codec_dev, to_software_node(fwnode));640641fwnode_handle_put(fwnode);642643if (ret) {644put_device(codec_dev);645return ret;646}647}648649/* get speaker enable GPIO */650devm_acpi_dev_add_driver_gpios(codec_dev, byt_cht_es8316_gpios);651priv->speaker_en_gpio =652gpiod_get_optional(codec_dev, "speaker-enable",653/* see comment in byt_cht_es8316_resume() */654GPIOD_OUT_LOW | GPIOD_FLAGS_BIT_NONEXCLUSIVE);655if (IS_ERR(priv->speaker_en_gpio)) {656ret = dev_err_probe(dev, PTR_ERR(priv->speaker_en_gpio),657"get speaker GPIO failed\n");658goto err_put_codec;659}660661snprintf(components_string, sizeof(components_string),662"cfg-spk:%s cfg-mic:%s",663(quirk & BYT_CHT_ES8316_MONO_SPEAKER) ? "1" : "2",664mic_name[BYT_CHT_ES8316_MAP(quirk)]);665byt_cht_es8316_card.components = components_string;666#if !IS_ENABLED(CONFIG_SND_SOC_INTEL_USER_FRIENDLY_LONG_NAMES)667snprintf(long_name, sizeof(long_name), "bytcht-es8316-%s-spk-%s-mic",668(quirk & BYT_CHT_ES8316_MONO_SPEAKER) ? "mono" : "stereo",669mic_name[BYT_CHT_ES8316_MAP(quirk)]);670byt_cht_es8316_card.long_name = long_name;671#endif672673sof_parent = snd_soc_acpi_sof_parent(dev);674675/* set card and driver name */676if (sof_parent) {677byt_cht_es8316_card.name = SOF_CARD_NAME;678byt_cht_es8316_card.driver_name = SOF_DRIVER_NAME;679} else {680byt_cht_es8316_card.name = CARD_NAME;681byt_cht_es8316_card.driver_name = DRIVER_NAME;682}683684/* set pm ops */685if (sof_parent)686dev->driver->pm = &snd_soc_pm_ops;687688/* register the soc card */689snd_soc_card_set_drvdata(&byt_cht_es8316_card, priv);690691ret = devm_snd_soc_register_card(dev, &byt_cht_es8316_card);692if (ret) {693gpiod_put(priv->speaker_en_gpio);694dev_err(dev, "snd_soc_register_card failed: %d\n", ret);695goto err_put_codec;696}697platform_set_drvdata(pdev, &byt_cht_es8316_card);698return 0;699700err_put_codec:701device_remove_software_node(priv->codec_dev);702put_device(priv->codec_dev);703return ret;704}705706static void snd_byt_cht_es8316_mc_remove(struct platform_device *pdev)707{708struct snd_soc_card *card = platform_get_drvdata(pdev);709struct byt_cht_es8316_private *priv = snd_soc_card_get_drvdata(card);710711gpiod_put(priv->speaker_en_gpio);712device_remove_software_node(priv->codec_dev);713put_device(priv->codec_dev);714}715716static struct platform_driver snd_byt_cht_es8316_mc_driver = {717.driver = {718.name = "bytcht_es8316",719},720.probe = snd_byt_cht_es8316_mc_probe,721.remove = snd_byt_cht_es8316_mc_remove,722};723724module_platform_driver(snd_byt_cht_es8316_mc_driver);725MODULE_DESCRIPTION("ASoC Intel(R) Baytrail/Cherrytrail Machine driver");726MODULE_AUTHOR("David Yang <[email protected]>");727MODULE_LICENSE("GPL v2");728MODULE_ALIAS("platform:bytcht_es8316");729730731