1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753 |
- // SPDX-License-Identifier: GPL-2.0-only
- /*
- * Copyright (c) 2016-2021, The Linux Foundation. All rights reserved.
- */
- #include <linux/clk.h>
- #include <linux/delay.h>
- #include <linux/gpio.h>
- #include <linux/of_gpio.h>
- #include <linux/platform_device.h>
- #include <linux/slab.h>
- #include <linux/io.h>
- #include <linux/module.h>
- #include <linux/input.h>
- #include <linux/of_device.h>
- #include <linux/soc/qcom/fsa4480-i2c.h>
- #include <linux/pm_qos.h>
- #include <sound/control.h>
- #include <sound/core.h>
- #include <sound/soc.h>
- #include <sound/soc-dapm.h>
- #include <sound/pcm.h>
- #include <sound/pcm_params.h>
- #include <sound/info.h>
- #include <soc/snd_event.h>
- #include <dsp/audio_prm.h>
- #include <soc/swr-common.h>
- #include <soc/soundwire.h>
- #include "device_event.h"
- #include "asoc/msm-cdc-pinctrl.h"
- #include "asoc/wcd-mbhc-v2.h"
- #include "codecs/wcd938x/wcd938x-mbhc.h"
- #include "codecs/wsa883x/wsa883x.h"
- #include "codecs/wcd938x/wcd938x.h"
- #include "codecs/lpass-cdc/lpass-cdc.h"
- #include <bindings/audio-codec-port-types.h>
- #include "codecs/lpass-cdc/lpass-cdc-wsa-macro.h"
- #include "waipio-port-config.h"
- #include "msm-audio-defs.h"
- #include "msm_common.h"
- #include "msm_dailink.h"
- #define DRV_NAME "waipio-asoc-snd"
- #define __CHIPSET__ "WAIPIO "
- #define MSM_DAILINK_NAME(name) (__CHIPSET__#name)
- #define WCD9XXX_MBHC_DEF_RLOADS 5
- #define WCD9XXX_MBHC_DEF_BUTTONS 8
- #define CODEC_EXT_CLK_RATE 9600000
- #define DEV_NAME_STR_LEN 32
- #define WCD_MBHC_HS_V_MAX 1600
- #define MSM_LL_QOS_VALUE 300 /* time in us to ensure LPM doesn't go in C3/C4 */
- #define WCN_CDC_SLIM_RX_CH_MAX 2
- #define WCN_CDC_SLIM_TX_CH_MAX 2
- #define WCN_CDC_SLIM_TX_CH_MAX_LITO 3
- struct msm_asoc_mach_data {
- struct snd_info_entry *codec_root;
- struct msm_common_pdata *common_pdata;
- int usbc_en2_gpio; /* used by gpio driver API */
- struct device_node *dmic01_gpio_p; /* used by pinctrl API */
- struct device_node *dmic23_gpio_p; /* used by pinctrl API */
- struct device_node *dmic45_gpio_p; /* used by pinctrl API */
- struct pinctrl *usbc_en2_gpio_p; /* used by pinctrl API */
- bool is_afe_config_done;
- struct device_node *fsa_handle;
- struct clk *lpass_audio_hw_vote;
- int core_audio_vote_count;
- u32 wsa_max_devs;
- int wcd_disabled;
- };
- static bool is_initial_boot;
- static bool codec_reg_done;
- static struct snd_soc_card snd_soc_card_waipio_msm;
- static int dmic_0_1_gpio_cnt;
- static int dmic_2_3_gpio_cnt;
- static int dmic_4_5_gpio_cnt;
- static void *def_wcd_mbhc_cal(void);
- static int msm_rx_tx_codec_init(struct snd_soc_pcm_runtime*);
- static int msm_int_wsa_init(struct snd_soc_pcm_runtime*);
- /*
- * Need to report LINEIN
- * if R/L channel impedance is larger than 5K ohm
- */
- static struct wcd_mbhc_config wcd_mbhc_cfg = {
- .read_fw_bin = false,
- .calibration = NULL,
- .detect_extn_cable = true,
- .mono_stero_detection = false,
- .swap_gnd_mic = NULL,
- .hs_ext_micbias = true,
- .key_code[0] = KEY_MEDIA,
- .key_code[1] = KEY_VOICECOMMAND,
- .key_code[2] = KEY_VOLUMEUP,
- .key_code[3] = KEY_VOLUMEDOWN,
- .key_code[4] = 0,
- .key_code[5] = 0,
- .key_code[6] = 0,
- .key_code[7] = 0,
- .linein_th = 5000,
- .moisture_en = false,
- .mbhc_micbias = MIC_BIAS_2,
- .anc_micbias = MIC_BIAS_2,
- .enable_anc_mic_detect = false,
- .moisture_duty_cycle_en = true,
- };
- #ifdef PM_QOS_ENABLE
- /* set audio task affinity to core 1 & 2 */
- static const unsigned int audio_core_list[] = {1, 2};
- static cpumask_t audio_cpu_map = CPU_MASK_NONE;
- static struct dev_pm_qos_request *msm_audio_req = NULL;
- static void msm_audio_add_qos_request()
- {
- int i;
- int cpu = 0;
- msm_audio_req = kzalloc(sizeof(struct dev_pm_qos_request) * NR_CPUS,
- GFP_KERNEL);
- if (!msm_audio_req) {
- pr_err("%s failed to alloc mem for qos req.\n", __func__);
- return;
- }
- for (i = 0; i < ARRAY_SIZE(audio_core_list); i++) {
- if (audio_core_list[i] >= NR_CPUS)
- pr_err("%s incorrect cpu id: %d specified.\n", __func__, audio_core_list[i]);
- else
- cpumask_set_cpu(audio_core_list[i], &audio_cpu_map);
- }
- for_each_cpu(cpu, &audio_cpu_map) {
- dev_pm_qos_add_request(get_cpu_device(cpu),
- &msm_audio_req[cpu],
- DEV_PM_QOS_RESUME_LATENCY,
- PM_QOS_CPU_LATENCY_DEFAULT_VALUE);
- pr_debug("%s set cpu affinity to core %d.\n", __func__, cpu);
- }
- }
- static void msm_audio_remove_qos_request()
- {
- int cpu = 0;
- if (msm_audio_req) {
- for_each_cpu(cpu, &audio_cpu_map) {
- dev_pm_qos_remove_request(
- &msm_audio_req[cpu]);
- pr_debug("%s remove cpu affinity of core %d.\n", __func__, cpu);
- }
- kfree(msm_audio_req);
- }
- }
- #endif
- static bool msm_usbc_swap_gnd_mic(struct snd_soc_component *component, bool active)
- {
- struct snd_soc_card *card = component->card;
- struct msm_asoc_mach_data *pdata =
- snd_soc_card_get_drvdata(card);
- if (!pdata->fsa_handle)
- return false;
- return fsa4480_switch_event(pdata->fsa_handle, FSA_MIC_GND_SWAP);
- }
- static struct snd_soc_ops msm_common_be_ops = {
- .startup = msm_common_snd_startup,
- .shutdown = msm_common_snd_shutdown,
- };
- static int msm_dmic_event(struct snd_soc_dapm_widget *w,
- struct snd_kcontrol *kcontrol, int event)
- {
- struct msm_asoc_mach_data *pdata = NULL;
- struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
- int ret = 0;
- u32 dmic_idx;
- int *dmic_gpio_cnt;
- struct device_node *dmic_gpio;
- char *wname;
- wname = strpbrk(w->name, "012345");
- if (!wname) {
- dev_err(component->dev, "%s: widget not found\n", __func__);
- return -EINVAL;
- }
- ret = kstrtouint(wname, 10, &dmic_idx);
- if (ret < 0) {
- dev_err(component->dev, "%s: Invalid DMIC line on the codec\n",
- __func__);
- return -EINVAL;
- }
- pdata = snd_soc_card_get_drvdata(component->card);
- switch (dmic_idx) {
- case 0:
- case 1:
- dmic_gpio_cnt = &dmic_0_1_gpio_cnt;
- dmic_gpio = pdata->dmic01_gpio_p;
- break;
- case 2:
- case 3:
- dmic_gpio_cnt = &dmic_2_3_gpio_cnt;
- dmic_gpio = pdata->dmic23_gpio_p;
- break;
- case 4:
- case 5:
- dmic_gpio_cnt = &dmic_4_5_gpio_cnt;
- dmic_gpio = pdata->dmic45_gpio_p;
- break;
- default:
- dev_err(component->dev, "%s: Invalid DMIC Selection\n",
- __func__);
- return -EINVAL;
- }
- dev_dbg(component->dev, "%s: event %d DMIC%d dmic_gpio_cnt %d\n",
- __func__, event, dmic_idx, *dmic_gpio_cnt);
- switch (event) {
- case SND_SOC_DAPM_PRE_PMU:
- (*dmic_gpio_cnt)++;
- if (*dmic_gpio_cnt == 1) {
- ret = msm_cdc_pinctrl_select_active_state(
- dmic_gpio);
- if (ret < 0) {
- pr_err("%s: gpio set cannot be activated %sd",
- __func__, "dmic_gpio");
- return ret;
- }
- }
- break;
- case SND_SOC_DAPM_POST_PMD:
- (*dmic_gpio_cnt)--;
- if (*dmic_gpio_cnt == 0) {
- ret = msm_cdc_pinctrl_select_sleep_state(
- dmic_gpio);
- if (ret < 0) {
- pr_err("%s: gpio set cannot be de-activated %sd",
- __func__, "dmic_gpio");
- return ret;
- }
- }
- break;
- default:
- pr_err("%s: invalid DAPM event %d\n", __func__, event);
- return -EINVAL;
- }
- return 0;
- }
- static const struct snd_soc_dapm_widget msm_int_dapm_widgets[] = {
- SND_SOC_DAPM_MIC("Analog Mic1", NULL),
- SND_SOC_DAPM_MIC("Analog Mic2", NULL),
- SND_SOC_DAPM_MIC("Analog Mic3", NULL),
- SND_SOC_DAPM_MIC("Analog Mic4", NULL),
- SND_SOC_DAPM_MIC("Analog Mic5", NULL),
- SND_SOC_DAPM_MIC("Digital Mic0", msm_dmic_event),
- SND_SOC_DAPM_MIC("Digital Mic1", msm_dmic_event),
- SND_SOC_DAPM_MIC("Digital Mic2", msm_dmic_event),
- SND_SOC_DAPM_MIC("Digital Mic3", msm_dmic_event),
- SND_SOC_DAPM_MIC("Digital Mic4", msm_dmic_event),
- SND_SOC_DAPM_MIC("Digital Mic5", msm_dmic_event),
- SND_SOC_DAPM_MIC("Digital Mic6", NULL),
- SND_SOC_DAPM_MIC("Digital Mic7", NULL),
- };
- static int msm_wcn_init(struct snd_soc_pcm_runtime *rtd)
- {
- unsigned int rx_ch[WCN_CDC_SLIM_RX_CH_MAX] = {157, 158};
- unsigned int tx_ch[WCN_CDC_SLIM_TX_CH_MAX] = {159, 160};
- struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
- int ret = 0;
- ret = snd_soc_dai_set_channel_map(codec_dai, ARRAY_SIZE(tx_ch),
- tx_ch, ARRAY_SIZE(rx_ch), rx_ch);
- if (ret)
- return ret;
- msm_common_dai_link_init(rtd);
- return ret;
- }
- static struct snd_info_entry *msm_snd_info_create_subdir(struct module *mod,
- const char *name,
- struct snd_info_entry *parent)
- {
- struct snd_info_entry *entry;
- entry = snd_info_create_module_entry(mod, name, parent);
- if (!entry)
- return NULL;
- entry->mode = S_IFDIR | 0555;
- if (snd_info_register(entry) < 0) {
- snd_info_free_entry(entry);
- return NULL;
- }
- return entry;
- }
- static void *def_wcd_mbhc_cal(void)
- {
- void *wcd_mbhc_cal;
- struct wcd_mbhc_btn_detect_cfg *btn_cfg;
- u16 *btn_high;
- wcd_mbhc_cal = kzalloc(WCD_MBHC_CAL_SIZE(WCD_MBHC_DEF_BUTTONS,
- WCD9XXX_MBHC_DEF_RLOADS), GFP_KERNEL);
- if (!wcd_mbhc_cal)
- return NULL;
- WCD_MBHC_CAL_PLUG_TYPE_PTR(wcd_mbhc_cal)->v_hs_max = WCD_MBHC_HS_V_MAX;
- WCD_MBHC_CAL_BTN_DET_PTR(wcd_mbhc_cal)->num_btn = WCD_MBHC_DEF_BUTTONS;
- btn_cfg = WCD_MBHC_CAL_BTN_DET_PTR(wcd_mbhc_cal);
- btn_high = ((void *)&btn_cfg->_v_btn_low) +
- (sizeof(btn_cfg->_v_btn_low[0]) * btn_cfg->num_btn);
- btn_high[0] = 75;
- btn_high[1] = 150;
- btn_high[2] = 237;
- btn_high[3] = 500;
- btn_high[4] = 500;
- btn_high[5] = 500;
- btn_high[6] = 500;
- btn_high[7] = 500;
- return wcd_mbhc_cal;
- }
- /* Digital audio interface glue - connects codec <---> CPU */
- static struct snd_soc_dai_link msm_common_be_dai_links[] = {
- /* Proxy Tx BACK END DAI Link */
- {
- .name = LPASS_BE_RT_PROXY_PCM_TX,
- .stream_name = LPASS_BE_RT_PROXY_PCM_TX,
- .capture_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ignore_suspend = 1,
- .ops = &msm_common_be_ops,
- SND_SOC_DAILINK_REG(proxy_tx),
- },
- /* Proxy Rx BACK END DAI Link */
- {
- .name = LPASS_BE_RT_PROXY_PCM_RX,
- .stream_name = LPASS_BE_RT_PROXY_PCM_RX,
- .playback_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ignore_pmdown_time = 1,
- .ignore_suspend = 1,
- .ops = &msm_common_be_ops,
- SND_SOC_DAILINK_REG(proxy_rx),
- },
- {
- .name = LPASS_BE_USB_AUDIO_RX,
- .stream_name = LPASS_BE_USB_AUDIO_RX,
- .playback_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ignore_pmdown_time = 1,
- .ignore_suspend = 1,
- .ops = &msm_common_be_ops,
- SND_SOC_DAILINK_REG(usb_audio_rx),
- },
- {
- .name = LPASS_BE_USB_AUDIO_TX,
- .stream_name = LPASS_BE_USB_AUDIO_TX,
- .capture_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ignore_suspend = 1,
- .ops = &msm_common_be_ops,
- SND_SOC_DAILINK_REG(usb_audio_tx),
- },
- {
- .name = LPASS_BE_WSA_CDC_DMA_TX_0,
- .stream_name = LPASS_BE_WSA_CDC_DMA_TX_0,
- .capture_only = 1,
- .ignore_suspend = 1,
- .ops = &msm_common_be_ops,
- /* .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, */
- SND_SOC_DAILINK_REG(vi_feedback),
- },
- #if 0
- {
- .name = LPASS_BE_WSA2_CDC_DMA_TX_0,
- .stream_name = LPASS_BE_WSA2_CDC_DMA_TX_0,
- .capture_only = 1,
- .ignore_suspend = 1,
- .ops = &msm_common_be_ops,
- /* .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, */
- SND_SOC_DAILINK_REG(wsa2_vi_feedback),
- },
- #endif
- };
- static struct snd_soc_dai_link msm_wcn_be_dai_links[] = {
- {
- .name = LPASS_BE_SLIMBUS_7_RX,
- .stream_name = LPASS_BE_SLIMBUS_7_RX,
- .playback_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .init = &msm_wcn_init,
- .ops = &msm_common_be_ops,
- /* dai link has playback support */
- .ignore_pmdown_time = 1,
- .ignore_suspend = 1,
- SND_SOC_DAILINK_REG(slimbus_7_rx),
- },
- {
- .name = LPASS_BE_SLIMBUS_7_TX,
- .stream_name = LPASS_BE_SLIMBUS_7_TX,
- .capture_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ops = &msm_common_be_ops,
- .ignore_suspend = 1,
- SND_SOC_DAILINK_REG(slimbus_7_tx),
- },
- };
- #if IS_ENABLED(CONFIG_AUDIO_QGKI)
- static struct snd_soc_dai_link ext_disp_be_dai_link[] = {
- /* DISP PORT BACK END DAI Link */
- {
- .name = LPASS_BE_DISPLAY_PORT_RX,
- .stream_name = LPASS_BE_DISPLAY_PORT_RX,
- .playback_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ignore_pmdown_time = 1,
- .ignore_suspend = 1,
- SND_SOC_DAILINK_REG(display_port),
- },
- };
- #endif
- static struct snd_soc_dai_link msm_wsa_cdc_dma_be_dai_links[] = {
- /* WSA CDC DMA Backend DAI Links */
- {
- .name = LPASS_BE_WSA_CDC_DMA_RX_0,
- .stream_name = LPASS_BE_WSA_CDC_DMA_RX_0,
- .playback_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ignore_pmdown_time = 1,
- .ignore_suspend = 1,
- .ops = &msm_common_be_ops,
- SND_SOC_DAILINK_REG(wsa_dma_rx0),
- .init = &msm_int_wsa_init,
- },
- {
- .name = LPASS_BE_WSA_CDC_DMA_RX_1,
- .stream_name = LPASS_BE_WSA_CDC_DMA_RX_1,
- .playback_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ignore_pmdown_time = 1,
- .ignore_suspend = 1,
- .ops = &msm_common_be_ops,
- SND_SOC_DAILINK_REG(wsa_dma_rx1),
- },
- {
- .name = LPASS_BE_WSA_CDC_DMA_TX_1,
- .stream_name = LPASS_BE_WSA_CDC_DMA_TX_1,
- .capture_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ignore_suspend = 1,
- .ops = &msm_common_be_ops,
- SND_SOC_DAILINK_REG(wsa_dma_tx1),
- },
- };
- #if 0
- static struct snd_soc_dai_link msm_wsa2_cdc_dma_be_dai_links[] = {
- /* WSA2 CDC DMA Backend DAI Links */
- {
- .name = LPASS_BE_WSA2_CDC_DMA_RX_0,
- .stream_name = LPASS_BE_WSA2_CDC_DMA_RX_0,
- .playback_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ignore_pmdown_time = 1,
- .ignore_suspend = 1,
- .ops = &msm_common_be_ops,
- SND_SOC_DAILINK_REG(wsa2_dma_rx0),
- },
- {
- .name = LPASS_BE_WSA2_CDC_DMA_RX_1,
- .stream_name = LPASS_BE_WSA2_CDC_DMA_RX_1,
- .playback_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ignore_pmdown_time = 1,
- .ignore_suspend = 1,
- .ops = &msm_common_be_ops,
- SND_SOC_DAILINK_REG(wsa2_dma_rx1),
- },
- {
- .name = LPASS_BE_WSA2_CDC_DMA_TX_1,
- .stream_name = LPASS_BE_WSA2_CDC_DMA_TX_1,
- .capture_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ignore_suspend = 1,
- .ops = &msm_common_be_ops,
- SND_SOC_DAILINK_REG(wsa2_dma_tx1),
- },
- };
- #endif
- static struct snd_soc_dai_link msm_rx_tx_cdc_dma_be_dai_links[] = {
- /* RX CDC DMA Backend DAI Links */
- {
- .name = LPASS_BE_RX_CDC_DMA_RX_0,
- .stream_name = LPASS_BE_RX_CDC_DMA_RX_0,
- .playback_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ignore_pmdown_time = 1,
- .ignore_suspend = 1,
- .ops = &msm_common_be_ops,
- SND_SOC_DAILINK_REG(rx_dma_rx0),
- .init = &msm_rx_tx_codec_init,
- },
- {
- .name = LPASS_BE_RX_CDC_DMA_RX_1,
- .stream_name = LPASS_BE_RX_CDC_DMA_RX_1,
- .playback_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ignore_pmdown_time = 1,
- .ignore_suspend = 1,
- .ops = &msm_common_be_ops,
- SND_SOC_DAILINK_REG(rx_dma_rx1),
- },
- {
- .name = LPASS_BE_RX_CDC_DMA_RX_2,
- .stream_name = LPASS_BE_RX_CDC_DMA_RX_2,
- .playback_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ignore_pmdown_time = 1,
- .ignore_suspend = 1,
- .ops = &msm_common_be_ops,
- SND_SOC_DAILINK_REG(rx_dma_rx2),
- },
- {
- .name = LPASS_BE_RX_CDC_DMA_RX_3,
- .stream_name = LPASS_BE_RX_CDC_DMA_RX_3,
- .playback_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ignore_pmdown_time = 1,
- .ignore_suspend = 1,
- .ops = &msm_common_be_ops,
- SND_SOC_DAILINK_REG(rx_dma_rx3),
- },
- {
- .name = LPASS_BE_RX_CDC_DMA_RX_5,
- .stream_name = LPASS_BE_RX_CDC_DMA_RX_5,
- .playback_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ignore_pmdown_time = 1,
- .ignore_suspend = 1,
- .ops = &msm_common_be_ops,
- SND_SOC_DAILINK_REG(rx_dma_rx5),
- },
- {
- .name = LPASS_BE_RX_CDC_DMA_RX_6,
- .stream_name = LPASS_BE_RX_CDC_DMA_RX_6,
- .playback_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ignore_pmdown_time = 1,
- .ignore_suspend = 1,
- .ops = &msm_common_be_ops,
- SND_SOC_DAILINK_REG(rx_dma_rx6),
- },
- /* TX CDC DMA Backend DAI Links */
- {
- .name = LPASS_BE_TX_CDC_DMA_TX_3,
- .stream_name = LPASS_BE_TX_CDC_DMA_TX_3,
- .capture_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ignore_suspend = 1,
- .ops = &msm_common_be_ops,
- SND_SOC_DAILINK_REG(tx_dma_tx3),
- },
- {
- .name = LPASS_BE_TX_CDC_DMA_TX_4,
- .stream_name = LPASS_BE_TX_CDC_DMA_TX_4,
- .capture_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ignore_suspend = 1,
- .ops = &msm_common_be_ops,
- SND_SOC_DAILINK_REG(tx_dma_tx4),
- },
- };
- static struct snd_soc_dai_link msm_va_cdc_dma_be_dai_links[] = {
- {
- .name = LPASS_BE_VA_CDC_DMA_TX_0,
- .stream_name = LPASS_BE_VA_CDC_DMA_TX_0,
- .capture_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ignore_suspend = 1,
- .ops = &msm_common_be_ops,
- SND_SOC_DAILINK_REG(va_dma_tx0),
- },
- {
- .name = LPASS_BE_VA_CDC_DMA_TX_1,
- .stream_name = LPASS_BE_VA_CDC_DMA_TX_1,
- .capture_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ignore_suspend = 1,
- .ops = &msm_common_be_ops,
- SND_SOC_DAILINK_REG(va_dma_tx1),
- },
- {
- .name = LPASS_BE_VA_CDC_DMA_TX_2,
- .stream_name = LPASS_BE_VA_CDC_DMA_TX_2,
- .capture_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ignore_suspend = 1,
- .ops = &msm_common_be_ops,
- SND_SOC_DAILINK_REG(va_dma_tx2),
- },
- };
- /*
- * I2S interface pinctrl mapping
- * ------------------------------------
- * Primary - pri_mi2s
- * Secondary - lpi_i2s3
- * Tertiary - tert_mi2s
- * Quaternary - quat_mi2s (lpi_i2s0)
- * Quinary - lpi_i2s1
- * Senary - lpi_i2s2
- * ------------------------------------
- */
- static struct snd_soc_dai_link msm_mi2s_dai_links[] = {
- {
- .name = LPASS_BE_PRI_MI2S_RX,
- .stream_name = LPASS_BE_PRI_MI2S_RX,
- .playback_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ops = &msm_common_be_ops,
- .ignore_suspend = 1,
- .ignore_pmdown_time = 1,
- SND_SOC_DAILINK_REG(pri_mi2s_rx),
- },
- {
- .name = LPASS_BE_PRI_MI2S_TX,
- .stream_name = LPASS_BE_PRI_MI2S_TX,
- .capture_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ops = &msm_common_be_ops,
- .ignore_suspend = 1,
- SND_SOC_DAILINK_REG(pri_mi2s_tx),
- },
- {
- .name = LPASS_BE_SEC_MI2S_RX,
- .stream_name = LPASS_BE_SEC_MI2S_RX,
- .playback_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ops = &msm_common_be_ops,
- .ignore_suspend = 1,
- .ignore_pmdown_time = 1,
- SND_SOC_DAILINK_REG(sec_mi2s_rx),
- },
- {
- .name = LPASS_BE_SEC_MI2S_TX,
- .stream_name = LPASS_BE_SEC_MI2S_TX,
- .capture_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ops = &msm_common_be_ops,
- .ignore_suspend = 1,
- SND_SOC_DAILINK_REG(sec_mi2s_tx),
- },
- {
- .name = LPASS_BE_TERT_MI2S_RX,
- .stream_name = LPASS_BE_TERT_MI2S_RX,
- .playback_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ops = &msm_common_be_ops,
- .ignore_suspend = 1,
- .ignore_pmdown_time = 1,
- SND_SOC_DAILINK_REG(tert_mi2s_rx),
- },
- {
- .name = LPASS_BE_TERT_MI2S_TX,
- .stream_name = LPASS_BE_TERT_MI2S_TX,
- .capture_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ops = &msm_common_be_ops,
- .ignore_suspend = 1,
- SND_SOC_DAILINK_REG(tert_mi2s_tx),
- },
- {
- .name = LPASS_BE_QUAT_MI2S_RX,
- .stream_name = LPASS_BE_QUAT_MI2S_RX,
- .playback_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ops = &msm_common_be_ops,
- .ignore_suspend = 1,
- .ignore_pmdown_time = 1,
- SND_SOC_DAILINK_REG(quat_mi2s_rx),
- },
- {
- .name = LPASS_BE_QUAT_MI2S_TX,
- .stream_name = LPASS_BE_QUAT_MI2S_TX,
- .capture_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ops = &msm_common_be_ops,
- .ignore_suspend = 1,
- SND_SOC_DAILINK_REG(quat_mi2s_tx),
- },
- {
- .name = LPASS_BE_QUIN_MI2S_RX,
- .stream_name = LPASS_BE_QUIN_MI2S_RX,
- .playback_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ops = &msm_common_be_ops,
- .ignore_suspend = 1,
- .ignore_pmdown_time = 1,
- SND_SOC_DAILINK_REG(quin_mi2s_rx),
- },
- {
- .name = LPASS_BE_QUIN_MI2S_TX,
- .stream_name = LPASS_BE_QUIN_MI2S_TX,
- .capture_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ops = &msm_common_be_ops,
- .ignore_suspend = 1,
- SND_SOC_DAILINK_REG(quin_mi2s_tx),
- },
- {
- .name = LPASS_BE_SEN_MI2S_RX,
- .stream_name = LPASS_BE_SEN_MI2S_RX,
- .playback_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ops = &msm_common_be_ops,
- .ignore_suspend = 1,
- .ignore_pmdown_time = 1,
- SND_SOC_DAILINK_REG(sen_mi2s_rx),
- },
- {
- .name = LPASS_BE_SEN_MI2S_TX,
- .stream_name = LPASS_BE_SEN_MI2S_TX,
- .capture_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ops = &msm_common_be_ops,
- .ignore_suspend = 1,
- SND_SOC_DAILINK_REG(sen_mi2s_tx),
- },
- };
- static struct snd_soc_dai_link msm_tdm_dai_links[] = {
- {
- .name = LPASS_BE_PRI_TDM_RX_0,
- .stream_name = LPASS_BE_PRI_TDM_RX_0,
- .playback_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ops = &msm_common_be_ops,
- .ignore_suspend = 1,
- .ignore_pmdown_time = 1,
- SND_SOC_DAILINK_REG(pri_tdm_rx_0),
- },
- {
- .name = LPASS_BE_PRI_TDM_TX_0,
- .stream_name = LPASS_BE_PRI_TDM_TX_0,
- .capture_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ops = &msm_common_be_ops,
- .ignore_suspend = 1,
- SND_SOC_DAILINK_REG(pri_tdm_tx_0),
- },
- {
- .name = LPASS_BE_SEC_TDM_RX_0,
- .stream_name = LPASS_BE_SEC_TDM_RX_0,
- .playback_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ops = &msm_common_be_ops,
- .ignore_suspend = 1,
- .ignore_pmdown_time = 1,
- SND_SOC_DAILINK_REG(sec_tdm_rx_0),
- },
- {
- .name = LPASS_BE_SEC_TDM_TX_0,
- .stream_name = LPASS_BE_SEC_TDM_TX_0,
- .capture_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ops = &msm_common_be_ops,
- .ignore_suspend = 1,
- SND_SOC_DAILINK_REG(sec_tdm_tx_0),
- },
- {
- .name = LPASS_BE_TERT_TDM_RX_0,
- .stream_name = LPASS_BE_TERT_TDM_RX_0,
- .playback_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ops = &msm_common_be_ops,
- .ignore_suspend = 1,
- .ignore_pmdown_time = 1,
- SND_SOC_DAILINK_REG(tert_tdm_rx_0),
- },
- {
- .name = LPASS_BE_TERT_TDM_TX_0,
- .stream_name = LPASS_BE_TERT_TDM_TX_0,
- .capture_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ops = &msm_common_be_ops,
- .ignore_suspend = 1,
- SND_SOC_DAILINK_REG(tert_tdm_tx_0),
- },
- {
- .name = LPASS_BE_QUAT_TDM_RX_0,
- .stream_name = LPASS_BE_QUAT_TDM_RX_0,
- .playback_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ops = &msm_common_be_ops,
- .ignore_suspend = 1,
- .ignore_pmdown_time = 1,
- SND_SOC_DAILINK_REG(quat_tdm_rx_0),
- },
- {
- .name = LPASS_BE_QUAT_TDM_TX_0,
- .stream_name = LPASS_BE_QUAT_TDM_TX_0,
- .capture_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ops = &msm_common_be_ops,
- .ignore_suspend = 1,
- SND_SOC_DAILINK_REG(quat_tdm_tx_0),
- },
- {
- .name = LPASS_BE_QUIN_TDM_RX_0,
- .stream_name = LPASS_BE_QUIN_TDM_RX_0,
- .playback_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ops = &msm_common_be_ops,
- .ignore_suspend = 1,
- .ignore_pmdown_time = 1,
- SND_SOC_DAILINK_REG(quin_tdm_rx_0),
- },
- {
- .name = LPASS_BE_QUIN_TDM_TX_0,
- .stream_name = LPASS_BE_QUIN_TDM_TX_0,
- .capture_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ops = &msm_common_be_ops,
- .ignore_suspend = 1,
- SND_SOC_DAILINK_REG(quin_tdm_tx_0),
- },
- {
- .name = LPASS_BE_SEN_TDM_RX_0,
- .stream_name = LPASS_BE_SEN_TDM_RX_0,
- .playback_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ops = &msm_common_be_ops,
- .ignore_suspend = 1,
- .ignore_pmdown_time = 1,
- SND_SOC_DAILINK_REG(sen_tdm_rx_0),
- },
- {
- .name = LPASS_BE_SEN_TDM_TX_0,
- .stream_name = LPASS_BE_SEN_TDM_TX_0,
- .capture_only = 1,
- .trigger = {SND_SOC_DPCM_TRIGGER_POST,
- SND_SOC_DPCM_TRIGGER_POST},
- .ops = &msm_common_be_ops,
- .ignore_suspend = 1,
- SND_SOC_DAILINK_REG(sen_tdm_tx_0),
- },
- };
- static struct snd_soc_dai_link msm_waipio_dai_links[
- ARRAY_SIZE(msm_wsa_cdc_dma_be_dai_links) +
- #if 0
- ARRAY_SIZE(msm_wsa2_cdc_dma_be_dai_links) +
- #endif
- ARRAY_SIZE(msm_rx_tx_cdc_dma_be_dai_links) +
- ARRAY_SIZE(msm_va_cdc_dma_be_dai_links) +
- #if IS_ENABLED(CONFIG_AUDIO_QGKI)
- ARRAY_SIZE(ext_disp_be_dai_link) +
- #endif
- ARRAY_SIZE(msm_common_be_dai_links) +
- ARRAY_SIZE(msm_wcn_be_dai_links) +
- ARRAY_SIZE(msm_mi2s_dai_links) +
- ARRAY_SIZE(msm_tdm_dai_links)];
- static int msm_populate_dai_link_component_of_node(
- struct snd_soc_card *card)
- {
- int i, j, index, ret = 0;
- struct device *cdev = card->dev;
- struct snd_soc_dai_link *dai_link = card->dai_link;
- struct device_node *np = NULL;
- int codecs_enabled = 0;
- struct snd_soc_dai_link_component *codecs_comp = NULL;
- if (!cdev) {
- dev_err(cdev, "%s: Sound card device memory NULL\n", __func__);
- return -ENODEV;
- }
- for (i = 0; i < card->num_links; i++) {
- if (dai_link[i].init == NULL)
- dai_link[i].init = &msm_common_dai_link_init;
- /* populate codec_of_node for snd card dai links */
- if (dai_link[i].num_codecs > 0) {
- for (j = 0; j < dai_link[i].num_codecs; j++) {
- if (dai_link[i].codecs[j].of_node ||
- !dai_link[i].codecs[j].name)
- continue;
- index = of_property_match_string(cdev->of_node,
- "asoc-codec-names",
- dai_link[i].codecs[j].name);
- if (index < 0)
- continue;
- np = of_parse_phandle(cdev->of_node,
- "asoc-codec",
- index);
- if (!np) {
- dev_err(cdev, "%s: retrieving phandle for codec %s failed\n",
- __func__,
- dai_link[i].codecs[j].name);
- ret = -ENODEV;
- goto err;
- }
- dai_link[i].codecs[j].of_node = np;
- dai_link[i].codecs[j].name = NULL;
- }
- }
- }
- /* In multi-codec scenario, check if codecs are enabled for this platform */
- for (i = 0; i < card->num_links; i++) {
- codecs_enabled = 0;
- if (dai_link[i].num_codecs > 1) {
- for (j = 0; j < dai_link[i].num_codecs; j++) {
- if (!dai_link[i].codecs[j].of_node)
- continue;
- np = dai_link[i].codecs[j].of_node;
- if (!of_device_is_available(np)) {
- dev_err(cdev, "%s: codec is disabled: %s\n",
- __func__,
- np->full_name);
- dai_link[i].codecs[j].of_node = NULL;
- continue;
- }
- codecs_enabled++;
- }
- if (codecs_enabled > 0 &&
- codecs_enabled < dai_link[i].num_codecs) {
- codecs_comp = devm_kzalloc(cdev,
- sizeof(struct snd_soc_dai_link_component)
- * codecs_enabled, GFP_KERNEL);
- if (!codecs_comp) {
- dev_err(cdev, "%s: %s dailink codec component alloc failed\n",
- __func__, dai_link[i].name);
- ret = -ENOMEM;
- goto err;
- }
- index = 0;
- for (j = 0; j < dai_link[i].num_codecs; j++) {
- if(dai_link[i].codecs[j].of_node) {
- codecs_comp[index].of_node =
- dai_link[i].codecs[j].of_node;
- codecs_comp[index].dai_name =
- dai_link[i].codecs[j].dai_name;
- codecs_comp[index].name = NULL;
- index++;
- }
- }
- dai_link[i].codecs = codecs_comp;
- dai_link[i].num_codecs = codecs_enabled;
- }
- }
- }
- err:
- return ret;
- }
- static int msm_audrx_stub_init(struct snd_soc_pcm_runtime *rtd)
- {
- return 0;
- }
- static int msm_snd_stub_hw_params(struct snd_pcm_substream *substream,
- struct snd_pcm_hw_params *params)
- {
- return 0;
- }
- static struct snd_soc_ops msm_stub_be_ops = {
- .hw_params = msm_snd_stub_hw_params,
- };
- struct snd_soc_card snd_soc_card_stub_msm = {
- .name = "waipio-stub-snd-card",
- };
- static struct snd_soc_dai_link msm_stub_be_dai_links[] = {
- /* Backend DAI Links */
- {
- .name = LPASS_BE_PRI_AUXPCM_RX,
- .stream_name = LPASS_BE_PRI_AUXPCM_RX,
- .playback_only = 1,
- .init = &msm_audrx_stub_init,
- .ignore_pmdown_time = 1,
- .ignore_suspend = 1,
- .ops = &msm_stub_be_ops,
- SND_SOC_DAILINK_REG(auxpcm_rx),
- },
- {
- .name = LPASS_BE_PRI_AUXPCM_TX,
- .stream_name = LPASS_BE_PRI_AUXPCM_TX,
- .capture_only = 1,
- .ignore_suspend = 1,
- .ops = &msm_stub_be_ops,
- SND_SOC_DAILINK_REG(auxpcm_tx),
- },
- };
- static struct snd_soc_dai_link msm_stub_dai_links[
- ARRAY_SIZE(msm_stub_be_dai_links)];
- static const struct of_device_id waipio_asoc_machine_of_match[] = {
- { .compatible = "qcom,waipio-asoc-snd",
- .data = "codec"},
- { .compatible = "qcom,waipio-asoc-snd-stub",
- .data = "stub_codec"},
- {},
- };
- static int msm_snd_card_late_probe(struct snd_soc_card *card)
- {
- struct snd_soc_component *component = NULL;
- struct snd_soc_pcm_runtime *rtd;
- int ret = 0;
- void *mbhc_calibration;
- rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
- if (!rtd) {
- dev_err(card->dev,
- "%s: snd_soc_get_pcm_runtime for %s failed!\n",
- __func__, card->dai_link[0]);
- return -EINVAL;
- }
- component = snd_soc_rtdcom_lookup(rtd, WCD938X_DRV_NAME);
- if (!component) {
- pr_err("%s component is NULL\n", __func__);
- return -EINVAL;
- }
- mbhc_calibration = def_wcd_mbhc_cal();
- if (!mbhc_calibration)
- return -ENOMEM;
- wcd_mbhc_cfg.calibration = mbhc_calibration;
- ret = wcd938x_mbhc_hs_detect(component, &wcd_mbhc_cfg);
- if (ret) {
- dev_err(component->dev, "%s: mbhc hs detect failed, err:%d\n",
- __func__, ret);
- goto err_hs_detect;
- }
- return 0;
- err_hs_detect:
- kfree(mbhc_calibration);
- return ret;
- }
- static struct snd_soc_card *populate_snd_card_dailinks(struct device *dev)
- {
- struct snd_soc_card *card = NULL;
- struct snd_soc_dai_link *dailink = NULL;
- int total_links = 0;
- int rc = 0;
- u32 val = 0;
- const struct of_device_id *match;
- match = of_match_node(waipio_asoc_machine_of_match, dev->of_node);
- if (!match) {
- dev_err(dev, "%s: No DT match found for sound card\n",
- __func__);
- return NULL;
- }
- if (!strcmp(match->data, "codec")) {
- card = &snd_soc_card_waipio_msm;
- /* late probe uses dai link at index '0' to get wcd component */
- memcpy(msm_waipio_dai_links + total_links,
- msm_rx_tx_cdc_dma_be_dai_links,
- sizeof(msm_rx_tx_cdc_dma_be_dai_links));
- total_links +=
- ARRAY_SIZE(msm_rx_tx_cdc_dma_be_dai_links);
- memcpy(msm_waipio_dai_links + total_links,
- msm_wsa_cdc_dma_be_dai_links,
- sizeof(msm_wsa_cdc_dma_be_dai_links));
- total_links += ARRAY_SIZE(msm_wsa_cdc_dma_be_dai_links);
- #if 0
- memcpy(msm_waipio_dai_links + total_links,
- msm_wsa2_cdc_dma_be_dai_links,
- sizeof(msm_wsa2_cdc_dma_be_dai_links));
- total_links += ARRAY_SIZE(msm_wsa2_cdc_dma_be_dai_links);
- #endif
- memcpy(msm_waipio_dai_links + total_links,
- msm_va_cdc_dma_be_dai_links,
- sizeof(msm_va_cdc_dma_be_dai_links));
- total_links += ARRAY_SIZE(msm_va_cdc_dma_be_dai_links);
- memcpy(msm_waipio_dai_links + total_links,
- msm_common_be_dai_links,
- sizeof(msm_common_be_dai_links));
- total_links += ARRAY_SIZE(msm_common_be_dai_links);
- rc = of_property_read_u32(dev->of_node,
- "qcom,mi2s-audio-intf", &val);
- if (!rc && val) {
- memcpy(msm_waipio_dai_links + total_links,
- msm_mi2s_dai_links,
- sizeof(msm_mi2s_dai_links));
- total_links += ARRAY_SIZE(msm_mi2s_dai_links);
- }
- rc = of_property_read_u32(dev->of_node,
- "qcom,tdm-audio-intf", &val);
- if (!rc && val) {
- memcpy(msm_waipio_dai_links + total_links,
- msm_tdm_dai_links,
- sizeof(msm_tdm_dai_links));
- total_links += ARRAY_SIZE(msm_tdm_dai_links);
- }
- #if IS_ENABLED(CONFIG_AUDIO_QGKI)
- rc = of_property_read_u32(dev->of_node,
- "qcom,ext-disp-audio-rx", &val);
- if (!rc && val) {
- dev_dbg(dev, "%s(): ext disp audio support present\n",
- __func__);
- memcpy(msm_waipio_dai_links + total_links,
- ext_disp_be_dai_link,
- sizeof(ext_disp_be_dai_link));
- total_links += ARRAY_SIZE(ext_disp_be_dai_link);
- }
- #endif
- rc = of_property_read_u32(dev->of_node, "qcom,wcn-bt", &val);
- if (!rc && val) {
- dev_dbg(dev, "%s(): WCN BT support present\n",
- __func__);
- memcpy(msm_waipio_dai_links + total_links,
- msm_wcn_be_dai_links,
- sizeof(msm_wcn_be_dai_links));
- total_links += ARRAY_SIZE(msm_wcn_be_dai_links);
- }
- dailink = msm_waipio_dai_links;
- } else if(!strcmp(match->data, "stub_codec")) {
- card = &snd_soc_card_stub_msm;
- memcpy(msm_stub_dai_links,
- msm_stub_be_dai_links,
- sizeof(msm_stub_be_dai_links));
- dailink = msm_stub_dai_links;
- total_links = ARRAY_SIZE(msm_stub_be_dai_links);
- }
- if (card) {
- card->dai_link = dailink;
- card->num_links = total_links;
- card->late_probe = msm_snd_card_late_probe;
- }
- return card;
- }
- static int msm_int_wsa_init(struct snd_soc_pcm_runtime *rtd)
- {
- u8 spkleft_ports[WSA883X_MAX_SWR_PORTS] = {0, 1, 2, 3};
- u8 spkright_ports[WSA883X_MAX_SWR_PORTS] = {0, 1, 2, 3};
- u8 spkleft_port_types[WSA883X_MAX_SWR_PORTS] = {SPKR_L, SPKR_L_COMP,
- SPKR_L_BOOST, SPKR_L_VI};
- u8 spkright_port_types[WSA883X_MAX_SWR_PORTS] = {SPKR_R, SPKR_R_COMP,
- SPKR_R_BOOST, SPKR_R_VI};
- unsigned int ch_rate[WSA883X_MAX_SWR_PORTS] = {SWR_CLK_RATE_2P4MHZ, SWR_CLK_RATE_0P6MHZ,
- SWR_CLK_RATE_0P3MHZ, SWR_CLK_RATE_1P2MHZ};
- unsigned int ch_mask[WSA883X_MAX_SWR_PORTS] = {0x1, 0xF, 0x3, 0x3};
- struct snd_soc_component *component = NULL;
- struct snd_soc_dapm_context *dapm = NULL;
- struct msm_asoc_mach_data *pdata =
- snd_soc_card_get_drvdata(rtd->card);
- if (pdata->wsa_max_devs > 0) {
- component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.1");
- if (!component) {
- pr_err("%s: wsa-codec.1 component is NULL\n", __func__);
- return -EINVAL;
- }
- dapm = snd_soc_component_get_dapm(component);
- wsa883x_set_channel_map(component, &spkleft_ports[0],
- WSA883X_MAX_SWR_PORTS, &ch_mask[0],
- &ch_rate[0], &spkleft_port_types[0]);
- if (dapm->component) {
- snd_soc_dapm_ignore_suspend(dapm, "spkrLeft IN");
- snd_soc_dapm_ignore_suspend(dapm, "spkrLeft SPKR");
- }
- wsa883x_codec_info_create_codec_entry(pdata->codec_root,
- component);
- }
- /* If current platform has more than one WSA */
- if (pdata->wsa_max_devs > 1) {
- component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.2");
- if (!component) {
- pr_err("%s: wsa-codec.2 component is NULL\n", __func__);
- return -EINVAL;
- }
- dapm = snd_soc_component_get_dapm(component);
- wsa883x_set_channel_map(component, &spkright_ports[0],
- WSA883X_MAX_SWR_PORTS, &ch_mask[0],
- &ch_rate[0], &spkright_port_types[0]);
- if (dapm->component) {
- snd_soc_dapm_ignore_suspend(dapm, "spkrRight IN");
- snd_soc_dapm_ignore_suspend(dapm, "spkrRight SPKR");
- }
- wsa883x_codec_info_create_codec_entry(pdata->codec_root,
- component);
- }
- #if 0
- if (pdata->wsa_max_devs > 2) {
- component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.3");
- if (!component) {
- pr_err("%s: wsa-codec.3 component is NULL\n", __func__);
- return -EINVAL;
- }
- dapm = snd_soc_component_get_dapm(component);
- wsa883x_set_channel_map(component, &spkleft_ports[0],
- WSA883X_MAX_SWR_PORTS, &ch_mask[0],
- &ch_rate[0], &spkleft_port_types[0]);
- if (dapm->component) {
- snd_soc_dapm_ignore_suspend(dapm, "spkr2Left IN");
- snd_soc_dapm_ignore_suspend(dapm, "spkr2Left SPKR");
- }
- wsa883x_codec_info_create_codec_entry(pdata->codec_root,
- component);
- }
- if (pdata->wsa_max_devs > 3) {
- component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.4");
- if (!component) {
- pr_err("%s: wsa-codec.4 component is NULL\n", __func__);
- return -EINVAL;
- }
- dapm = snd_soc_component_get_dapm(component);
- wsa883x_set_channel_map(component, &spkright_ports[0],
- WSA883X_MAX_SWR_PORTS, &ch_mask[0],
- &ch_rate[0], &spkright_port_types[0]);
- if (dapm->component) {
- snd_soc_dapm_ignore_suspend(dapm, "spkr2Right IN");
- snd_soc_dapm_ignore_suspend(dapm, "spkr2Right SPKR");
- }
- wsa883x_codec_info_create_codec_entry(pdata->codec_root,
- component);
- }
- #endif
- snd_soc_dapm_ignore_suspend(dapm, "WSA_SPK1 OUT");
- snd_soc_dapm_ignore_suspend(dapm, "WSA_SPK2 OUT");
- #if 0
- snd_soc_dapm_ignore_suspend(dapm, "WSA2_SPK1 OUT");
- snd_soc_dapm_ignore_suspend(dapm, "WSA2_SPK2 OUT");
- #endif
- snd_soc_dapm_ignore_suspend(dapm, "WSA AIF VI");
- snd_soc_dapm_ignore_suspend(dapm, "VIINPUT_WSA");
- snd_soc_dapm_sync(dapm);
- msm_common_dai_link_init(rtd);
- return 0;
- }
- static int msm_rx_tx_codec_init(struct snd_soc_pcm_runtime *rtd)
- {
- struct snd_soc_component *component = NULL;
- struct snd_soc_dapm_context *dapm = NULL;
- struct snd_info_entry *entry = NULL;
- struct snd_card *card = NULL;
- struct msm_asoc_mach_data *pdata =
- snd_soc_card_get_drvdata(rtd->card);
- int ret = 0;
- component = snd_soc_rtdcom_lookup(rtd, "lpass-cdc");
- if (!component) {
- pr_err("%s: could not find component for lpass-cdc\n",
- __func__);
- return ret;
- }
- dapm = snd_soc_component_get_dapm(component);
- snd_soc_dapm_new_controls(dapm, msm_int_dapm_widgets,
- ARRAY_SIZE(msm_int_dapm_widgets));
- snd_soc_dapm_ignore_suspend(dapm, "Digital Mic0");
- snd_soc_dapm_ignore_suspend(dapm, "Digital Mic1");
- snd_soc_dapm_ignore_suspend(dapm, "Digital Mic2");
- snd_soc_dapm_ignore_suspend(dapm, "Digital Mic3");
- snd_soc_dapm_ignore_suspend(dapm, "Digital Mic4");
- snd_soc_dapm_ignore_suspend(dapm, "Digital Mic5");
- snd_soc_dapm_ignore_suspend(dapm, "Digital Mic6");
- snd_soc_dapm_ignore_suspend(dapm, "Digital Mic7");
- snd_soc_dapm_ignore_suspend(dapm, "Analog Mic1");
- snd_soc_dapm_ignore_suspend(dapm, "Analog Mic2");
- snd_soc_dapm_ignore_suspend(dapm, "Analog Mic3");
- snd_soc_dapm_ignore_suspend(dapm, "Analog Mic4");
- snd_soc_dapm_ignore_suspend(dapm, "Analog Mic5");
- lpass_cdc_set_port_map(component, ARRAY_SIZE(sm_port_map), sm_port_map);
- card = rtd->card->snd_card;
- if (!pdata->codec_root) {
- entry = msm_snd_info_create_subdir(card->module, "codecs",
- card->proc_root);
- if (!entry) {
- pr_debug("%s: Cannot create codecs module entry\n",
- __func__);
- return ret;
- }
- pdata->codec_root = entry;
- }
- lpass_cdc_info_create_codec_entry(pdata->codec_root, component);
- lpass_cdc_register_wake_irq(component, false);
- if (pdata->wcd_disabled)
- goto done;
- component = snd_soc_rtdcom_lookup(rtd, WCD938X_DRV_NAME);
- if (!component) {
- pr_err("%s component is NULL\n", __func__);
- return -EINVAL;
- }
- dapm = snd_soc_component_get_dapm(component);
- card = component->card->snd_card;
- snd_soc_dapm_ignore_suspend(dapm, "EAR");
- snd_soc_dapm_ignore_suspend(dapm, "AUX");
- snd_soc_dapm_ignore_suspend(dapm, "HPHL");
- snd_soc_dapm_ignore_suspend(dapm, "HPHR");
- snd_soc_dapm_ignore_suspend(dapm, "AMIC1");
- snd_soc_dapm_ignore_suspend(dapm, "AMIC2");
- snd_soc_dapm_ignore_suspend(dapm, "AMIC3");
- snd_soc_dapm_ignore_suspend(dapm, "AMIC4");
- snd_soc_dapm_sync(dapm);
- pdata = snd_soc_card_get_drvdata(component->card);
- if (!pdata->codec_root) {
- entry = msm_snd_info_create_subdir(card->module, "codecs",
- card->proc_root);
- if (!entry) {
- dev_dbg(component->dev, "%s: Cannot create codecs module entry\n",
- __func__);
- return 0;
- }
- pdata->codec_root = entry;
- }
- wcd938x_info_create_codec_entry(pdata->codec_root, component);
- #if 0
- codec_variant = wcd938x_get_codec_variant(component);
- dev_dbg(component->dev, "%s: variant %d\n", __func__, codec_variant);
- if (codec_variant == WCD9380)
- ret = snd_soc_add_component_controls(component,
- msm_int_wcd9380_snd_controls,
- ARRAY_SIZE(msm_int_wcd9380_snd_controls));
- else if (codec_variant == WCD9385)
- ret = snd_soc_add_component_controls(component,
- msm_int_wcd9385_snd_controls,
- ARRAY_SIZE(msm_int_wcd9385_snd_controls));
- if (ret < 0) {
- dev_err(component->dev, "%s: add codec specific snd controls failed: %d\n",
- __func__, ret);
- return ret;
- }
- #endif
- done:
- codec_reg_done = true;
- msm_common_dai_link_init(rtd);
- return ret;
- }
- static int waipio_ssr_enable(struct device *dev, void *data)
- {
- struct platform_device *pdev = to_platform_device(dev);
- struct snd_soc_card *card = platform_get_drvdata(pdev);
- int ret = 0;
- if (!card) {
- dev_err(dev, "%s: card is NULL\n", __func__);
- ret = -EINVAL;
- goto err;
- }
- if (!strcmp(card->name, "waipio-stub-snd-card")) {
- /* TODO */
- dev_dbg(dev, "%s: TODO \n", __func__);
- }
- snd_card_notify_user(1);
- dev_dbg(dev, "%s: setting snd_card to ONLINE\n", __func__);
- err:
- return ret;
- }
- static void waipio_ssr_disable(struct device *dev, void *data)
- {
- struct platform_device *pdev = to_platform_device(dev);
- struct snd_soc_card *card = platform_get_drvdata(pdev);
- if (!card) {
- dev_err(dev, "%s: card is NULL\n", __func__);
- return;
- }
- dev_dbg(dev, "%s: setting snd_card to OFFLINE\n", __func__);
- snd_card_notify_user(0);
- if (!strcmp(card->name, "waipio-stub-snd-card")) {
- /* TODO */
- dev_dbg(dev, "%s: TODO \n", __func__);
- }
- }
- static const struct snd_event_ops waipio_ssr_ops = {
- .enable = waipio_ssr_enable,
- .disable = waipio_ssr_disable,
- };
- static int msm_audio_ssr_compare(struct device *dev, void *data)
- {
- struct device_node *node = data;
- dev_dbg(dev, "%s: dev->of_node = 0x%p, node = 0x%p\n",
- __func__, dev->of_node, node);
- return (dev->of_node && dev->of_node == node);
- }
- static int msm_audio_ssr_register(struct device *dev)
- {
- struct device_node *np = dev->of_node;
- struct snd_event_clients *ssr_clients = NULL;
- struct device_node *node = NULL;
- int ret = 0;
- int i = 0;
- for (i = 0; ; i++) {
- node = of_parse_phandle(np, "qcom,msm_audio_ssr_devs", i);
- if (!node)
- break;
- snd_event_mstr_add_client(&ssr_clients,
- msm_audio_ssr_compare, node);
- }
- ret = snd_event_master_register(dev, &waipio_ssr_ops,
- ssr_clients, NULL);
- if (!ret)
- snd_event_notify(dev, SND_EVENT_UP);
- return ret;
- }
- struct msm_common_pdata *msm_common_get_pdata(struct snd_soc_card *card)
- {
- struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
- if (!pdata)
- return NULL;
- return pdata->common_pdata;
- }
- void msm_common_set_pdata(struct snd_soc_card *card,
- struct msm_common_pdata *common_pdata)
- {
- struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
- if (!pdata)
- return;
- pdata->common_pdata = common_pdata;
- }
- static int msm_asoc_machine_probe(struct platform_device *pdev)
- {
- struct snd_soc_card *card = NULL;
- struct msm_asoc_mach_data *pdata = NULL;
- int ret = 0;
- struct clk *lpass_audio_hw_vote = NULL;
- if (!pdev->dev.of_node) {
- dev_err(&pdev->dev, "%s: No platform supplied from device tree\n", __func__);
- return -EINVAL;
- }
- pdata = devm_kzalloc(&pdev->dev,
- sizeof(struct msm_asoc_mach_data), GFP_KERNEL);
- if (!pdata)
- return -ENOMEM;
- of_property_read_u32(pdev->dev.of_node,
- "qcom,wcd-disabled",
- &pdata->wcd_disabled);
- card = populate_snd_card_dailinks(&pdev->dev);
- if (!card) {
- dev_err(&pdev->dev, "%s: Card uninitialized\n", __func__);
- ret = -EINVAL;
- goto err;
- }
- card->dev = &pdev->dev;
- platform_set_drvdata(pdev, card);
- snd_soc_card_set_drvdata(card, pdata);
- ret = snd_soc_of_parse_card_name(card, "qcom,model");
- if (ret) {
- dev_err(&pdev->dev, "%s: parse card name failed, err:%d\n",
- __func__, ret);
- goto err;
- }
- ret = snd_soc_of_parse_audio_routing(card, "qcom,audio-routing");
- if (ret) {
- dev_err(&pdev->dev, "%s: parse audio routing failed, err:%d\n",
- __func__, ret);
- goto err;
- }
- ret = msm_populate_dai_link_component_of_node(card);
- if (ret) {
- ret = -EPROBE_DEFER;
- goto err;
- }
- /* Get maximum WSA device count for this platform */
- ret = of_property_read_u32(pdev->dev.of_node,
- "qcom,wsa-max-devs", &pdata->wsa_max_devs);
- if (ret) {
- dev_info(&pdev->dev,
- "%s: wsa-max-devs property missing in DT %s, ret = %d\n",
- __func__, pdev->dev.of_node->full_name, ret);
- pdata->wsa_max_devs = 0;
- }
- ret = devm_snd_soc_register_card(&pdev->dev, card);
- if (ret == -EPROBE_DEFER) {
- if (codec_reg_done)
- ret = -EINVAL;
- goto err;
- } else if (ret) {
- dev_err(&pdev->dev, "%s: snd_soc_register_card failed (%d)\n",
- __func__, ret);
- goto err;
- }
- dev_info(&pdev->dev, "%s: Sound card %s registered\n",
- __func__, card->name);
- if (wcd_mbhc_cfg.enable_usbc_analog)
- wcd_mbhc_cfg.swap_gnd_mic = msm_usbc_swap_gnd_mic;
- pdata->fsa_handle = of_parse_phandle(pdev->dev.of_node,
- "fsa4480-i2c-handle", 0);
- if (!pdata->fsa_handle)
- dev_dbg(&pdev->dev, "property %s not detected in node %s\n",
- "fsa4480-i2c-handle", pdev->dev.of_node->full_name);
- pdata->dmic01_gpio_p = of_parse_phandle(pdev->dev.of_node,
- "qcom,cdc-dmic01-gpios",
- 0);
- pdata->dmic23_gpio_p = of_parse_phandle(pdev->dev.of_node,
- "qcom,cdc-dmic23-gpios",
- 0);
- pdata->dmic45_gpio_p = of_parse_phandle(pdev->dev.of_node,
- "qcom,cdc-dmic45-gpios",
- 0);
- if (pdata->dmic01_gpio_p)
- msm_cdc_pinctrl_set_wakeup_capable(pdata->dmic01_gpio_p, false);
- if (pdata->dmic23_gpio_p)
- msm_cdc_pinctrl_set_wakeup_capable(pdata->dmic23_gpio_p, false);
- if (pdata->dmic45_gpio_p)
- msm_cdc_pinctrl_set_wakeup_capable(pdata->dmic45_gpio_p, false);
- msm_common_snd_init(pdev, card);
- /* Register LPASS audio hw vote */
- lpass_audio_hw_vote = devm_clk_get(&pdev->dev, "lpass_audio_hw_vote");
- if (IS_ERR(lpass_audio_hw_vote)) {
- ret = PTR_ERR(lpass_audio_hw_vote);
- dev_dbg(&pdev->dev, "%s: clk get %s failed %d\n",
- __func__, "lpass_audio_hw_vote", ret);
- lpass_audio_hw_vote = NULL;
- ret = 0;
- }
- pdata->lpass_audio_hw_vote = lpass_audio_hw_vote;
- pdata->core_audio_vote_count = 0;
- ret = msm_audio_ssr_register(&pdev->dev);
- if (ret)
- pr_err("%s: Registration with SND event FWK failed ret = %d\n",
- __func__, ret);
- is_initial_boot = true;
- #ifdef PM_QOS_ENABLE
- /* Add QoS request for audio tasks */
- msm_audio_add_qos_request();
- #endif
- return 0;
- err:
- devm_kfree(&pdev->dev, pdata);
- return ret;
- }
- static int msm_asoc_machine_remove(struct platform_device *pdev)
- {
- struct snd_soc_card *card = platform_get_drvdata(pdev);
- struct msm_asoc_mach_data *pdata = NULL;
- struct msm_common_pdata *common_pdata = NULL;
- if (card)
- pdata = snd_soc_card_get_drvdata(card);
- if (pdata)
- common_pdata = pdata->common_pdata;
- msm_common_snd_deinit(common_pdata);
- snd_event_master_deregister(&pdev->dev);
- snd_soc_unregister_card(card);
- #ifdef PM_QOS_ENABLE
- msm_audio_remove_qos_request();
- #endif
- return 0;
- }
- static struct platform_driver waipio_asoc_machine_driver = {
- .driver = {
- .name = DRV_NAME,
- .owner = THIS_MODULE,
- .pm = &snd_soc_pm_ops,
- .of_match_table = waipio_asoc_machine_of_match,
- .suppress_bind_attrs = true,
- },
- .probe = msm_asoc_machine_probe,
- .remove = msm_asoc_machine_remove,
- };
- static int __init msm_asoc_machine_init(void)
- {
- snd_card_sysfs_init();
- return platform_driver_register(&waipio_asoc_machine_driver);
- }
- module_init(msm_asoc_machine_init);
- static void __exit msm_asoc_machine_exit(void)
- {
- platform_driver_unregister(&waipio_asoc_machine_driver);
- }
- module_exit(msm_asoc_machine_exit);
- MODULE_SOFTDEP("pre: bt_fm_slim");
- MODULE_DESCRIPTION("ALSA SoC msm");
- MODULE_LICENSE("GPL v2");
- MODULE_ALIAS("platform:" DRV_NAME);
- MODULE_DEVICE_TABLE(of, waipio_asoc_machine_of_match);
|