Path: blob/master/sound/soc/intel/boards/bytcht_cx2072x.c
26493 views
// SPDX-License-Identifier: GPL-2.0-only1//2// ASoC DPCM Machine driver for Baytrail / Cherrytrail platforms with3// CX2072X codec4//56#include <linux/acpi.h>7#include <linux/device.h>8#include <linux/gpio/consumer.h>9#include <linux/module.h>10#include <linux/platform_device.h>11#include <linux/slab.h>12#include <sound/pcm.h>13#include <sound/pcm_params.h>14#include <sound/jack.h>15#include <sound/soc.h>16#include <sound/soc-acpi.h>17#include "../../codecs/cx2072x.h"18#include "../atom/sst-atom-controls.h"1920static const struct snd_soc_dapm_widget byt_cht_cx2072x_widgets[] = {21SND_SOC_DAPM_HP("Headphone", NULL),22SND_SOC_DAPM_MIC("Headset Mic", NULL),23SND_SOC_DAPM_MIC("Int Mic", NULL),24SND_SOC_DAPM_SPK("Ext Spk", NULL),25};2627static const struct snd_soc_dapm_route byt_cht_cx2072x_audio_map[] = {28/* External Speakers: HFL, HFR */29{"Headphone", NULL, "PORTA"},30{"Ext Spk", NULL, "PORTG"},31{"PORTC", NULL, "Int Mic"},32{"PORTD", NULL, "Headset Mic"},3334{"Playback", NULL, "ssp2 Tx"},35{"ssp2 Tx", NULL, "codec_out0"},36{"ssp2 Tx", NULL, "codec_out1"},37{"codec_in0", NULL, "ssp2 Rx"},38{"codec_in1", NULL, "ssp2 Rx"},39{"ssp2 Rx", NULL, "Capture"},40};4142static const struct snd_kcontrol_new byt_cht_cx2072x_controls[] = {43SOC_DAPM_PIN_SWITCH("Headphone"),44SOC_DAPM_PIN_SWITCH("Headset Mic"),45SOC_DAPM_PIN_SWITCH("Int Mic"),46SOC_DAPM_PIN_SWITCH("Ext Spk"),47};4849static struct snd_soc_jack byt_cht_cx2072x_headset;5051/* Headset jack detection DAPM pins */52static struct snd_soc_jack_pin byt_cht_cx2072x_headset_pins[] = {53{54.pin = "Headset Mic",55.mask = SND_JACK_MICROPHONE,56},57{58.pin = "Headphone",59.mask = SND_JACK_HEADPHONE,60},61};6263static const struct acpi_gpio_params byt_cht_cx2072x_headset_gpios;64static const struct acpi_gpio_mapping byt_cht_cx2072x_acpi_gpios[] = {65{ "headset-gpios", &byt_cht_cx2072x_headset_gpios, 1 },66{},67};6869static int byt_cht_cx2072x_init(struct snd_soc_pcm_runtime *rtd)70{71struct snd_soc_card *card = rtd->card;72struct snd_soc_component *codec = snd_soc_rtd_to_codec(rtd, 0)->component;73int ret;7475if (devm_acpi_dev_add_driver_gpios(codec->dev,76byt_cht_cx2072x_acpi_gpios))77dev_warn(rtd->dev, "Unable to add GPIO mapping table\n");7879card->dapm.idle_bias_off = true;8081/* set the default PLL rate, the clock is handled by the codec driver */82ret = snd_soc_dai_set_sysclk(snd_soc_rtd_to_codec(rtd, 0), CX2072X_MCLK_EXTERNAL_PLL,8319200000, SND_SOC_CLOCK_IN);84if (ret) {85dev_err(rtd->dev, "Could not set sysclk\n");86return ret;87}8889ret = snd_soc_card_jack_new_pins(card, "Headset",90SND_JACK_HEADSET | SND_JACK_BTN_0,91&byt_cht_cx2072x_headset,92byt_cht_cx2072x_headset_pins,93ARRAY_SIZE(byt_cht_cx2072x_headset_pins));94if (ret)95return ret;9697snd_soc_component_set_jack(codec, &byt_cht_cx2072x_headset, NULL);9899snd_soc_dai_set_bclk_ratio(snd_soc_rtd_to_codec(rtd, 0), 50);100101return 0;102}103104static int byt_cht_cx2072x_fixup(struct snd_soc_pcm_runtime *rtd,105struct snd_pcm_hw_params *params)106{107struct snd_interval *rate =108hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);109struct snd_interval *channels =110hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);111int ret;112113/* The DSP will convert the FE rate to 48k, stereo, 24bits */114rate->min = rate->max = 48000;115channels->min = channels->max = 2;116117/* set SSP2 to 24-bit */118params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);119120/*121* Default mode for SSP configuration is TDM 4 slot, override config122* with explicit setting to I2S 2ch 24-bit. The word length is set with123* dai_set_tdm_slot() since there is no other API exposed124*/125ret = snd_soc_dai_set_fmt(snd_soc_rtd_to_cpu(rtd, 0),126SND_SOC_DAIFMT_I2S |127SND_SOC_DAIFMT_NB_NF |128SND_SOC_DAIFMT_BP_FP);129if (ret < 0) {130dev_err(rtd->dev, "can't set format to I2S, err %d\n", ret);131return ret;132}133134ret = snd_soc_dai_set_tdm_slot(snd_soc_rtd_to_cpu(rtd, 0), 0x3, 0x3, 2, 24);135if (ret < 0) {136dev_err(rtd->dev, "can't set I2S config, err %d\n", ret);137return ret;138}139140return 0;141}142143static int byt_cht_cx2072x_aif1_startup(struct snd_pcm_substream *substream)144{145return snd_pcm_hw_constraint_single(substream->runtime,146SNDRV_PCM_HW_PARAM_RATE, 48000);147}148149static const struct snd_soc_ops byt_cht_cx2072x_aif1_ops = {150.startup = byt_cht_cx2072x_aif1_startup,151};152153SND_SOC_DAILINK_DEF(dummy,154DAILINK_COMP_ARRAY(COMP_DUMMY()));155156SND_SOC_DAILINK_DEF(media,157DAILINK_COMP_ARRAY(COMP_CPU("media-cpu-dai")));158159SND_SOC_DAILINK_DEF(deepbuffer,160DAILINK_COMP_ARRAY(COMP_CPU("deepbuffer-cpu-dai")));161162SND_SOC_DAILINK_DEF(ssp2,163DAILINK_COMP_ARRAY(COMP_CPU("ssp2-port")));164165SND_SOC_DAILINK_DEF(cx2072x,166DAILINK_COMP_ARRAY(COMP_CODEC("i2c-14F10720:00", "cx2072x-hifi")));167168SND_SOC_DAILINK_DEF(platform,169DAILINK_COMP_ARRAY(COMP_PLATFORM("sst-mfld-platform")));170171static struct snd_soc_dai_link byt_cht_cx2072x_dais[] = {172[MERR_DPCM_AUDIO] = {173.name = "Audio Port",174.stream_name = "Audio",175.nonatomic = true,176.dynamic = 1,177.ops = &byt_cht_cx2072x_aif1_ops,178SND_SOC_DAILINK_REG(media, dummy, platform),179},180[MERR_DPCM_DEEP_BUFFER] = {181.name = "Deep-Buffer Audio Port",182.stream_name = "Deep-Buffer Audio",183.nonatomic = true,184.dynamic = 1,185.playback_only = 1,186.ops = &byt_cht_cx2072x_aif1_ops,187SND_SOC_DAILINK_REG(deepbuffer, dummy, platform),188},189/* back ends */190{191.name = "SSP2-Codec",192.id = 0,193.no_pcm = 1,194.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF195| SND_SOC_DAIFMT_CBC_CFC,196.init = byt_cht_cx2072x_init,197.be_hw_params_fixup = byt_cht_cx2072x_fixup,198SND_SOC_DAILINK_REG(ssp2, cx2072x, platform),199},200};201202/* use space before codec name to simplify card ID, and simplify driver name */203#define SOF_CARD_NAME "bytcht cx2072x" /* card name will be 'sof-bytcht cx2072x' */204#define SOF_DRIVER_NAME "SOF"205206#define CARD_NAME "bytcht-cx2072x"207#define DRIVER_NAME NULL /* card name will be used for driver name */208209/* SoC card */210static struct snd_soc_card byt_cht_cx2072x_card = {211.name = CARD_NAME,212.driver_name = DRIVER_NAME,213.owner = THIS_MODULE,214.dai_link = byt_cht_cx2072x_dais,215.num_links = ARRAY_SIZE(byt_cht_cx2072x_dais),216.dapm_widgets = byt_cht_cx2072x_widgets,217.num_dapm_widgets = ARRAY_SIZE(byt_cht_cx2072x_widgets),218.dapm_routes = byt_cht_cx2072x_audio_map,219.num_dapm_routes = ARRAY_SIZE(byt_cht_cx2072x_audio_map),220.controls = byt_cht_cx2072x_controls,221.num_controls = ARRAY_SIZE(byt_cht_cx2072x_controls),222};223224static char codec_name[SND_ACPI_I2C_ID_LEN];225226static int snd_byt_cht_cx2072x_probe(struct platform_device *pdev)227{228struct snd_soc_acpi_mach *mach;229struct acpi_device *adev;230int dai_index = 0;231bool sof_parent;232int i, ret;233234byt_cht_cx2072x_card.dev = &pdev->dev;235mach = dev_get_platdata(&pdev->dev);236237/* fix index of codec dai */238for (i = 0; i < ARRAY_SIZE(byt_cht_cx2072x_dais); i++) {239if (byt_cht_cx2072x_dais[i].num_codecs &&240!strcmp(byt_cht_cx2072x_dais[i].codecs->name,241"i2c-14F10720:00")) {242dai_index = i;243break;244}245}246247/* fixup codec name based on HID */248adev = acpi_dev_get_first_match_dev(mach->id, NULL, -1);249if (adev) {250snprintf(codec_name, sizeof(codec_name), "i2c-%s",251acpi_dev_name(adev));252byt_cht_cx2072x_dais[dai_index].codecs->name = codec_name;253} else {254dev_err(&pdev->dev, "Error cannot find '%s' dev\n", mach->id);255return -ENOENT;256}257258acpi_dev_put(adev);259260/* override platform name, if required */261ret = snd_soc_fixup_dai_links_platform_name(&byt_cht_cx2072x_card,262mach->mach_params.platform);263if (ret)264return ret;265266sof_parent = snd_soc_acpi_sof_parent(&pdev->dev);267268/* set card and driver name */269if (sof_parent) {270byt_cht_cx2072x_card.name = SOF_CARD_NAME;271byt_cht_cx2072x_card.driver_name = SOF_DRIVER_NAME;272} else {273byt_cht_cx2072x_card.name = CARD_NAME;274byt_cht_cx2072x_card.driver_name = DRIVER_NAME;275}276277/* set pm ops */278if (sof_parent)279pdev->dev.driver->pm = &snd_soc_pm_ops;280281return devm_snd_soc_register_card(&pdev->dev, &byt_cht_cx2072x_card);282}283284static struct platform_driver snd_byt_cht_cx2072x_driver = {285.driver = {286.name = "bytcht_cx2072x",287},288.probe = snd_byt_cht_cx2072x_probe,289};290module_platform_driver(snd_byt_cht_cx2072x_driver);291292MODULE_DESCRIPTION("ASoC Intel(R) Baytrail/Cherrytrail Machine driver");293MODULE_LICENSE("GPL v2");294MODULE_ALIAS("platform:bytcht_cx2072x");295296297