Path: blob/master/sound/soc/intel/boards/bytcht_es8316.c
26493 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(quirk) ((quirk) & GENMASK(3, 0))50#define BYT_CHT_ES8316_SSP0 BIT(16)51#define BYT_CHT_ES8316_MONO_SPEAKER BIT(17)52#define BYT_CHT_ES8316_JD_INVERTED BIT(18)5354static unsigned long quirk;5556static int quirk_override = -1;57module_param_named(quirk, quirk_override, int, 0444);58MODULE_PARM_DESC(quirk, "Board-specific quirk override");5960static void log_quirks(struct device *dev)61{62if (BYT_CHT_ES8316_MAP(quirk) == BYT_CHT_ES8316_INTMIC_IN1_MAP)63dev_info(dev, "quirk IN1_MAP enabled");64if (BYT_CHT_ES8316_MAP(quirk) == BYT_CHT_ES8316_INTMIC_IN2_MAP)65dev_info(dev, "quirk IN2_MAP enabled");66if (quirk & BYT_CHT_ES8316_SSP0)67dev_info(dev, "quirk SSP0 enabled");68if (quirk & BYT_CHT_ES8316_MONO_SPEAKER)69dev_info(dev, "quirk MONO_SPEAKER enabled\n");70if (quirk & BYT_CHT_ES8316_JD_INVERTED)71dev_info(dev, "quirk JD_INVERTED enabled\n");72}7374static int byt_cht_es8316_speaker_power_event(struct snd_soc_dapm_widget *w,75struct snd_kcontrol *kcontrol, int event)76{77struct snd_soc_card *card = w->dapm->card;78struct byt_cht_es8316_private *priv = snd_soc_card_get_drvdata(card);7980if (SND_SOC_DAPM_EVENT_ON(event))81priv->speaker_en = true;82else83priv->speaker_en = false;8485gpiod_set_value_cansleep(priv->speaker_en_gpio, priv->speaker_en);8687return 0;88}8990static const struct snd_soc_dapm_widget byt_cht_es8316_widgets[] = {91SND_SOC_DAPM_SPK("Speaker", NULL),92SND_SOC_DAPM_HP("Headphone", NULL),93SND_SOC_DAPM_MIC("Headset Mic", NULL),94SND_SOC_DAPM_MIC("Internal Mic", NULL),9596SND_SOC_DAPM_SUPPLY("Speaker Power", SND_SOC_NOPM, 0, 0,97byt_cht_es8316_speaker_power_event,98SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU),99};100101static const struct snd_soc_dapm_route byt_cht_es8316_audio_map[] = {102{"Headphone", NULL, "HPOL"},103{"Headphone", NULL, "HPOR"},104105/*106* There is no separate speaker output instead the speakers are muxed to107* the HP outputs. The mux is controlled by the "Speaker Power" supply.108*/109{"Speaker", NULL, "HPOL"},110{"Speaker", NULL, "HPOR"},111{"Speaker", NULL, "Speaker Power"},112};113114static const struct snd_soc_dapm_route byt_cht_es8316_intmic_in1_map[] = {115{"MIC1", NULL, "Internal Mic"},116{"MIC2", NULL, "Headset Mic"},117};118119static const struct snd_soc_dapm_route byt_cht_es8316_intmic_in2_map[] = {120{"MIC2", NULL, "Internal Mic"},121{"MIC1", NULL, "Headset Mic"},122};123124static const struct snd_soc_dapm_route byt_cht_es8316_ssp0_map[] = {125{"Playback", NULL, "ssp0 Tx"},126{"ssp0 Tx", NULL, "modem_out"},127{"modem_in", NULL, "ssp0 Rx"},128{"ssp0 Rx", NULL, "Capture"},129};130131static const struct snd_soc_dapm_route byt_cht_es8316_ssp2_map[] = {132{"Playback", NULL, "ssp2 Tx"},133{"ssp2 Tx", NULL, "codec_out0"},134{"ssp2 Tx", NULL, "codec_out1"},135{"codec_in0", NULL, "ssp2 Rx" },136{"codec_in1", NULL, "ssp2 Rx" },137{"ssp2 Rx", NULL, "Capture"},138};139140static const struct snd_kcontrol_new byt_cht_es8316_controls[] = {141SOC_DAPM_PIN_SWITCH("Speaker"),142SOC_DAPM_PIN_SWITCH("Headphone"),143SOC_DAPM_PIN_SWITCH("Headset Mic"),144SOC_DAPM_PIN_SWITCH("Internal Mic"),145};146147static struct snd_soc_jack_pin byt_cht_es8316_jack_pins[] = {148{149.pin = "Headphone",150.mask = SND_JACK_HEADPHONE,151},152{153.pin = "Headset Mic",154.mask = SND_JACK_MICROPHONE,155},156};157158static int byt_cht_es8316_init(struct snd_soc_pcm_runtime *runtime)159{160struct snd_soc_component *codec = snd_soc_rtd_to_codec(runtime, 0)->component;161struct snd_soc_card *card = runtime->card;162struct byt_cht_es8316_private *priv = snd_soc_card_get_drvdata(card);163const struct snd_soc_dapm_route *custom_map;164int num_routes;165int ret;166167card->dapm.idle_bias_off = true;168169switch (BYT_CHT_ES8316_MAP(quirk)) {170case BYT_CHT_ES8316_INTMIC_IN1_MAP:171default:172custom_map = byt_cht_es8316_intmic_in1_map;173num_routes = ARRAY_SIZE(byt_cht_es8316_intmic_in1_map);174break;175case BYT_CHT_ES8316_INTMIC_IN2_MAP:176custom_map = byt_cht_es8316_intmic_in2_map;177num_routes = ARRAY_SIZE(byt_cht_es8316_intmic_in2_map);178break;179}180ret = snd_soc_dapm_add_routes(&card->dapm, custom_map, num_routes);181if (ret)182return ret;183184if (quirk & BYT_CHT_ES8316_SSP0) {185custom_map = byt_cht_es8316_ssp0_map;186num_routes = ARRAY_SIZE(byt_cht_es8316_ssp0_map);187} else {188custom_map = byt_cht_es8316_ssp2_map;189num_routes = ARRAY_SIZE(byt_cht_es8316_ssp2_map);190}191ret = snd_soc_dapm_add_routes(&card->dapm, custom_map, num_routes);192if (ret)193return ret;194195/*196* The firmware might enable the clock at boot (this information197* may or may not be reflected in the enable clock register).198* To change the rate we must disable the clock first to cover these199* cases. Due to common clock framework restrictions that do not allow200* to disable a clock that has not been enabled, we need to enable201* the clock first.202*/203ret = clk_prepare_enable(priv->mclk);204if (!ret)205clk_disable_unprepare(priv->mclk);206207ret = clk_set_rate(priv->mclk, 19200000);208if (ret)209dev_err(card->dev, "unable to set MCLK rate\n");210211ret = clk_prepare_enable(priv->mclk);212if (ret)213dev_err(card->dev, "unable to enable MCLK\n");214215ret = snd_soc_dai_set_sysclk(snd_soc_rtd_to_codec(runtime, 0), 0, 19200000,216SND_SOC_CLOCK_IN);217if (ret < 0) {218dev_err(card->dev, "can't set codec clock %d\n", ret);219return ret;220}221222ret = snd_soc_card_jack_new_pins(card, "Headset",223SND_JACK_HEADSET | SND_JACK_BTN_0,224&priv->jack, byt_cht_es8316_jack_pins,225ARRAY_SIZE(byt_cht_es8316_jack_pins));226if (ret) {227dev_err(card->dev, "jack creation failed %d\n", ret);228return ret;229}230231snd_jack_set_key(priv->jack.jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);232snd_soc_component_set_jack(codec, &priv->jack, NULL);233234return 0;235}236237static int byt_cht_es8316_codec_fixup(struct snd_soc_pcm_runtime *rtd,238struct snd_pcm_hw_params *params)239{240struct snd_interval *rate = hw_param_interval(params,241SNDRV_PCM_HW_PARAM_RATE);242struct snd_interval *channels = hw_param_interval(params,243SNDRV_PCM_HW_PARAM_CHANNELS);244int ret, bits;245246/* The DSP will convert the FE rate to 48k, stereo */247rate->min = rate->max = 48000;248channels->min = channels->max = 2;249250if (quirk & BYT_CHT_ES8316_SSP0) {251/* set SSP0 to 16-bit */252params_set_format(params, SNDRV_PCM_FORMAT_S16_LE);253bits = 16;254} else {255/* set SSP2 to 24-bit */256params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);257bits = 24;258}259260/*261* Default mode for SSP configuration is TDM 4 slot, override config262* with explicit setting to I2S 2ch 24-bit. The word length is set with263* dai_set_tdm_slot() since there is no other API exposed264*/265ret = snd_soc_dai_set_fmt(snd_soc_rtd_to_cpu(rtd, 0),266SND_SOC_DAIFMT_I2S |267SND_SOC_DAIFMT_NB_NF |268SND_SOC_DAIFMT_BP_FP269);270if (ret < 0) {271dev_err(rtd->dev, "can't set format to I2S, err %d\n", ret);272return ret;273}274275ret = snd_soc_dai_set_tdm_slot(snd_soc_rtd_to_cpu(rtd, 0), 0x3, 0x3, 2, bits);276if (ret < 0) {277dev_err(rtd->dev, "can't set I2S config, err %d\n", ret);278return ret;279}280281return 0;282}283284static int byt_cht_es8316_aif1_startup(struct snd_pcm_substream *substream)285{286return snd_pcm_hw_constraint_single(substream->runtime,287SNDRV_PCM_HW_PARAM_RATE, 48000);288}289290static const struct snd_soc_ops byt_cht_es8316_aif1_ops = {291.startup = byt_cht_es8316_aif1_startup,292};293294SND_SOC_DAILINK_DEF(dummy,295DAILINK_COMP_ARRAY(COMP_DUMMY()));296297SND_SOC_DAILINK_DEF(media,298DAILINK_COMP_ARRAY(COMP_CPU("media-cpu-dai")));299300SND_SOC_DAILINK_DEF(deepbuffer,301DAILINK_COMP_ARRAY(COMP_CPU("deepbuffer-cpu-dai")));302303SND_SOC_DAILINK_DEF(ssp2_port,304DAILINK_COMP_ARRAY(COMP_CPU("ssp2-port")));305SND_SOC_DAILINK_DEF(ssp2_codec,306DAILINK_COMP_ARRAY(COMP_CODEC("i2c-ESSX8316:00", "ES8316 HiFi")));307308SND_SOC_DAILINK_DEF(platform,309DAILINK_COMP_ARRAY(COMP_PLATFORM("sst-mfld-platform")));310311static struct snd_soc_dai_link byt_cht_es8316_dais[] = {312[MERR_DPCM_AUDIO] = {313.name = "Audio Port",314.stream_name = "Audio",315.nonatomic = true,316.dynamic = 1,317.ops = &byt_cht_es8316_aif1_ops,318SND_SOC_DAILINK_REG(media, dummy, platform),319},320321[MERR_DPCM_DEEP_BUFFER] = {322.name = "Deep-Buffer Audio Port",323.stream_name = "Deep-Buffer Audio",324.nonatomic = true,325.dynamic = 1,326.playback_only = 1,327.ops = &byt_cht_es8316_aif1_ops,328SND_SOC_DAILINK_REG(deepbuffer, dummy, platform),329},330331/* back ends */332{333.name = "SSP2-Codec",334.id = 0,335.no_pcm = 1,336.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF337| SND_SOC_DAIFMT_CBC_CFC,338.be_hw_params_fixup = byt_cht_es8316_codec_fixup,339.init = byt_cht_es8316_init,340SND_SOC_DAILINK_REG(ssp2_port, ssp2_codec, platform),341},342};343344345/* SoC card */346static char codec_name[SND_ACPI_I2C_ID_LEN];347#if !IS_ENABLED(CONFIG_SND_SOC_INTEL_USER_FRIENDLY_LONG_NAMES)348static char long_name[50]; /* = "bytcht-es8316-*-spk-*-mic" */349#endif350static char components_string[32]; /* = "cfg-spk:* cfg-mic:* */351352static int byt_cht_es8316_suspend(struct snd_soc_card *card)353{354struct snd_soc_component *component;355356for_each_card_components(card, component) {357if (!strcmp(component->name, codec_name)) {358dev_dbg(component->dev, "disabling jack detect before suspend\n");359snd_soc_component_set_jack(component, NULL, NULL);360break;361}362}363364return 0;365}366367static int byt_cht_es8316_resume(struct snd_soc_card *card)368{369struct byt_cht_es8316_private *priv = snd_soc_card_get_drvdata(card);370struct snd_soc_component *component;371372for_each_card_components(card, component) {373if (!strcmp(component->name, codec_name)) {374dev_dbg(component->dev, "re-enabling jack detect after resume\n");375snd_soc_component_set_jack(component, &priv->jack, NULL);376break;377}378}379380/*381* Some Cherry Trail boards with an ES8316 codec have a bug in their382* ACPI tables where the MSSL1680 touchscreen's _PS0 and _PS3 methods383* wrongly also set the speaker-enable GPIO to 1/0. Testing has shown384* that this really is a bug and the GPIO has no influence on the385* touchscreen at all.386*387* The silead.c touchscreen driver does not support runtime suspend, so388* the GPIO can only be changed underneath us during a system suspend.389* This resume() function runs from a pm complete() callback, and thus390* is guaranteed to run after the touchscreen driver/ACPI-subsys has391* brought the touchscreen back up again (and thus changed the GPIO).392*393* So to work around this we pass GPIOD_FLAGS_BIT_NONEXCLUSIVE when394* requesting the GPIO and we set its value here to undo any changes395* done by the touchscreen's broken _PS0 ACPI method.396*/397gpiod_set_value_cansleep(priv->speaker_en_gpio, priv->speaker_en);398399return 0;400}401402/* use space before codec name to simplify card ID, and simplify driver name */403#define SOF_CARD_NAME "bytcht es8316" /* card name will be 'sof-bytcht es8316' */404#define SOF_DRIVER_NAME "SOF"405406#define CARD_NAME "bytcht-es8316"407#define DRIVER_NAME NULL /* card name will be used for driver name */408409static struct snd_soc_card byt_cht_es8316_card = {410.owner = THIS_MODULE,411.dai_link = byt_cht_es8316_dais,412.num_links = ARRAY_SIZE(byt_cht_es8316_dais),413.dapm_widgets = byt_cht_es8316_widgets,414.num_dapm_widgets = ARRAY_SIZE(byt_cht_es8316_widgets),415.dapm_routes = byt_cht_es8316_audio_map,416.num_dapm_routes = ARRAY_SIZE(byt_cht_es8316_audio_map),417.controls = byt_cht_es8316_controls,418.num_controls = ARRAY_SIZE(byt_cht_es8316_controls),419.fully_routed = true,420.suspend_pre = byt_cht_es8316_suspend,421.resume_post = byt_cht_es8316_resume,422};423424static const struct acpi_gpio_params first_gpio = { 0, 0, false };425426static const struct acpi_gpio_mapping byt_cht_es8316_gpios[] = {427{ "speaker-enable-gpios", &first_gpio, 1 },428{ },429};430431/* Please keep this list alphabetically sorted */432static const struct dmi_system_id byt_cht_es8316_quirk_table[] = {433{ /* Irbis NB41 */434.matches = {435DMI_MATCH(DMI_SYS_VENDOR, "IRBIS"),436DMI_MATCH(DMI_PRODUCT_NAME, "NB41"),437},438.driver_data = (void *)(BYT_CHT_ES8316_SSP0439| BYT_CHT_ES8316_INTMIC_IN2_MAP440| BYT_CHT_ES8316_JD_INVERTED),441},442{ /* Nanote UMPC-01 */443.matches = {444DMI_MATCH(DMI_SYS_VENDOR, "RWC CO.,LTD"),445DMI_MATCH(DMI_PRODUCT_NAME, "UMPC-01"),446},447.driver_data = (void *)BYT_CHT_ES8316_INTMIC_IN1_MAP,448},449{ /* Teclast X98 Plus II */450.matches = {451DMI_MATCH(DMI_SYS_VENDOR, "TECLAST"),452DMI_MATCH(DMI_PRODUCT_NAME, "X98 Plus II"),453},454.driver_data = (void *)(BYT_CHT_ES8316_INTMIC_IN1_MAP455| BYT_CHT_ES8316_JD_INVERTED),456},457{}458};459460static int byt_cht_es8316_get_quirks_from_dsm(struct byt_cht_es8316_private *priv,461bool is_bytcr)462{463int ret, val1, val2, dsm_quirk = 0;464465if (is_bytcr)466dsm_quirk |= BYT_CHT_ES8316_SSP0;467468ret = es83xx_dsm(priv->codec_dev, PLATFORM_MAINMIC_TYPE_ARG, &val1);469if (ret < 0)470return ret;471472ret = es83xx_dsm(priv->codec_dev, PLATFORM_HPMIC_TYPE_ARG, &val2);473if (ret < 0)474return ret;475476if (val1 == PLATFORM_MIC_AMIC_LIN1RIN1 && val2 == PLATFORM_MIC_AMIC_LIN2RIN2) {477dsm_quirk |= BYT_CHT_ES8316_INTMIC_IN1_MAP;478} else if (val1 == PLATFORM_MIC_AMIC_LIN2RIN2 && val2 == PLATFORM_MIC_AMIC_LIN1RIN1) {479dsm_quirk |= BYT_CHT_ES8316_INTMIC_IN2_MAP;480} else {481dev_warn(priv->codec_dev, "Unknown mic settings mainmic 0x%02x hpmic 0x%02x\n",482val1, val2);483return -EINVAL;484}485486ret = es83xx_dsm(priv->codec_dev, PLATFORM_SPK_TYPE_ARG, &val1);487if (ret < 0)488return ret;489490switch (val1) {491case PLATFORM_SPK_MONO:492dsm_quirk |= BYT_CHT_ES8316_MONO_SPEAKER;493break;494case PLATFORM_SPK_STEREO:495break;496default:497dev_warn(priv->codec_dev, "Unknown speaker setting 0x%02x\n", val1);498return -EINVAL;499}500501ret = es83xx_dsm(priv->codec_dev, PLATFORM_HPDET_INV_ARG, &val1);502if (ret < 0)503return ret;504505switch (val1) {506case PLATFORM_HPDET_NORMAL:507break;508case PLATFORM_HPDET_INVERTED:509dsm_quirk |= BYT_CHT_ES8316_JD_INVERTED;510break;511default:512dev_warn(priv->codec_dev, "Unknown hpdet-inv setting 0x%02x\n", val1);513return -EINVAL;514}515516quirk = dsm_quirk;517return 0;518}519520static int snd_byt_cht_es8316_mc_probe(struct platform_device *pdev)521{522struct device *dev = &pdev->dev;523static const char * const mic_name[] = { "in1", "in2" };524struct snd_soc_acpi_mach *mach = dev_get_platdata(dev);525struct property_entry props[MAX_NO_PROPS] = {};526struct byt_cht_es8316_private *priv;527const struct dmi_system_id *dmi_id;528struct fwnode_handle *fwnode;529bool sof_parent, is_bytcr;530const char *platform_name;531struct acpi_device *adev;532struct device *codec_dev;533unsigned int cnt = 0;534int dai_index = 0;535int i;536int ret = 0;537538priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);539if (!priv)540return -ENOMEM;541542/* fix index of codec dai */543for (i = 0; i < ARRAY_SIZE(byt_cht_es8316_dais); i++) {544if (byt_cht_es8316_dais[i].num_codecs &&545!strcmp(byt_cht_es8316_dais[i].codecs->name,546"i2c-ESSX8316:00")) {547dai_index = i;548break;549}550}551552/* fixup codec name based on HID */553adev = acpi_dev_get_first_match_dev(mach->id, NULL, -1);554if (adev) {555snprintf(codec_name, sizeof(codec_name),556"i2c-%s", acpi_dev_name(adev));557byt_cht_es8316_dais[dai_index].codecs->name = codec_name;558} else {559dev_err(dev, "Error cannot find '%s' dev\n", mach->id);560return -ENOENT;561}562563codec_dev = acpi_get_first_physical_node(adev);564acpi_dev_put(adev);565if (!codec_dev)566return -EPROBE_DEFER;567priv->codec_dev = get_device(codec_dev);568569/* override platform name, if required */570byt_cht_es8316_card.dev = dev;571platform_name = mach->mach_params.platform;572573ret = snd_soc_fixup_dai_links_platform_name(&byt_cht_es8316_card,574platform_name);575if (ret) {576put_device(codec_dev);577return ret;578}579580es83xx_dsm_dump(priv->codec_dev);581582/* Check for BYTCR or other platform and setup quirks */583is_bytcr = soc_intel_is_byt() && mach->mach_params.acpi_ipc_irq_index == 0;584dmi_id = dmi_first_match(byt_cht_es8316_quirk_table);585if (dmi_id) {586quirk = (unsigned long)dmi_id->driver_data;587} else if (!byt_cht_es8316_get_quirks_from_dsm(priv, is_bytcr)) {588dev_info(dev, "Using ACPI DSM info for quirks\n");589} else if (is_bytcr) {590/* On BYTCR default to SSP0, internal-mic-in2-map, mono-spk */591quirk = BYT_CHT_ES8316_SSP0 | BYT_CHT_ES8316_INTMIC_IN2_MAP |592BYT_CHT_ES8316_MONO_SPEAKER;593} else {594/* Others default to internal-mic-in1-map, mono-speaker */595quirk = BYT_CHT_ES8316_INTMIC_IN1_MAP |596BYT_CHT_ES8316_MONO_SPEAKER;597}598if (quirk_override != -1) {599dev_info(dev, "Overriding quirk 0x%lx => 0x%x\n",600quirk, quirk_override);601quirk = quirk_override;602}603log_quirks(dev);604605if (quirk & BYT_CHT_ES8316_SSP0)606byt_cht_es8316_dais[dai_index].cpus->dai_name = "ssp0-port";607608/* get the clock */609priv->mclk = devm_clk_get(dev, "pmc_plt_clk_3");610if (IS_ERR(priv->mclk)) {611put_device(codec_dev);612return dev_err_probe(dev, PTR_ERR(priv->mclk), "clk_get pmc_plt_clk_3 failed\n");613}614615if (quirk & BYT_CHT_ES8316_JD_INVERTED)616props[cnt++] = PROPERTY_ENTRY_BOOL("everest,jack-detect-inverted");617618if (cnt) {619fwnode = fwnode_create_software_node(props, NULL);620if (IS_ERR(fwnode)) {621put_device(codec_dev);622return PTR_ERR(fwnode);623}624625ret = device_add_software_node(codec_dev, to_software_node(fwnode));626627fwnode_handle_put(fwnode);628629if (ret) {630put_device(codec_dev);631return ret;632}633}634635/* get speaker enable GPIO */636devm_acpi_dev_add_driver_gpios(codec_dev, byt_cht_es8316_gpios);637priv->speaker_en_gpio =638gpiod_get_optional(codec_dev, "speaker-enable",639/* see comment in byt_cht_es8316_resume() */640GPIOD_OUT_LOW | GPIOD_FLAGS_BIT_NONEXCLUSIVE);641if (IS_ERR(priv->speaker_en_gpio)) {642ret = dev_err_probe(dev, PTR_ERR(priv->speaker_en_gpio),643"get speaker GPIO failed\n");644goto err_put_codec;645}646647snprintf(components_string, sizeof(components_string),648"cfg-spk:%s cfg-mic:%s",649(quirk & BYT_CHT_ES8316_MONO_SPEAKER) ? "1" : "2",650mic_name[BYT_CHT_ES8316_MAP(quirk)]);651byt_cht_es8316_card.components = components_string;652#if !IS_ENABLED(CONFIG_SND_SOC_INTEL_USER_FRIENDLY_LONG_NAMES)653snprintf(long_name, sizeof(long_name), "bytcht-es8316-%s-spk-%s-mic",654(quirk & BYT_CHT_ES8316_MONO_SPEAKER) ? "mono" : "stereo",655mic_name[BYT_CHT_ES8316_MAP(quirk)]);656byt_cht_es8316_card.long_name = long_name;657#endif658659sof_parent = snd_soc_acpi_sof_parent(dev);660661/* set card and driver name */662if (sof_parent) {663byt_cht_es8316_card.name = SOF_CARD_NAME;664byt_cht_es8316_card.driver_name = SOF_DRIVER_NAME;665} else {666byt_cht_es8316_card.name = CARD_NAME;667byt_cht_es8316_card.driver_name = DRIVER_NAME;668}669670/* set pm ops */671if (sof_parent)672dev->driver->pm = &snd_soc_pm_ops;673674/* register the soc card */675snd_soc_card_set_drvdata(&byt_cht_es8316_card, priv);676677ret = devm_snd_soc_register_card(dev, &byt_cht_es8316_card);678if (ret) {679gpiod_put(priv->speaker_en_gpio);680dev_err(dev, "snd_soc_register_card failed: %d\n", ret);681goto err_put_codec;682}683platform_set_drvdata(pdev, &byt_cht_es8316_card);684return 0;685686err_put_codec:687device_remove_software_node(priv->codec_dev);688put_device(priv->codec_dev);689return ret;690}691692static void snd_byt_cht_es8316_mc_remove(struct platform_device *pdev)693{694struct snd_soc_card *card = platform_get_drvdata(pdev);695struct byt_cht_es8316_private *priv = snd_soc_card_get_drvdata(card);696697gpiod_put(priv->speaker_en_gpio);698device_remove_software_node(priv->codec_dev);699put_device(priv->codec_dev);700}701702static struct platform_driver snd_byt_cht_es8316_mc_driver = {703.driver = {704.name = "bytcht_es8316",705},706.probe = snd_byt_cht_es8316_mc_probe,707.remove = snd_byt_cht_es8316_mc_remove,708};709710module_platform_driver(snd_byt_cht_es8316_mc_driver);711MODULE_DESCRIPTION("ASoC Intel(R) Baytrail/Cherrytrail Machine driver");712MODULE_AUTHOR("David Yang <[email protected]>");713MODULE_LICENSE("GPL v2");714MODULE_ALIAS("platform:bytcht_es8316");715716717