18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci// Copyright (c) 2011-2017, The Linux Foundation. All rights reserved. 38c2ecf20Sopenharmony_ci// Copyright (c) 2018, Linaro Limited 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci#include <linux/slab.h> 68c2ecf20Sopenharmony_ci#include <linux/kernel.h> 78c2ecf20Sopenharmony_ci#include <linux/uaccess.h> 88c2ecf20Sopenharmony_ci#include <linux/wait.h> 98c2ecf20Sopenharmony_ci#include <linux/jiffies.h> 108c2ecf20Sopenharmony_ci#include <linux/sched.h> 118c2ecf20Sopenharmony_ci#include <linux/module.h> 128c2ecf20Sopenharmony_ci#include <linux/kref.h> 138c2ecf20Sopenharmony_ci#include <linux/of.h> 148c2ecf20Sopenharmony_ci#include <linux/of_platform.h> 158c2ecf20Sopenharmony_ci#include <linux/spinlock.h> 168c2ecf20Sopenharmony_ci#include <linux/delay.h> 178c2ecf20Sopenharmony_ci#include <linux/soc/qcom/apr.h> 188c2ecf20Sopenharmony_ci#include <sound/soc.h> 198c2ecf20Sopenharmony_ci#include <sound/soc-dai.h> 208c2ecf20Sopenharmony_ci#include <sound/pcm.h> 218c2ecf20Sopenharmony_ci#include <sound/pcm_params.h> 228c2ecf20Sopenharmony_ci#include "q6dsp-errno.h" 238c2ecf20Sopenharmony_ci#include "q6core.h" 248c2ecf20Sopenharmony_ci#include "q6afe.h" 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci/* AFE CMDs */ 278c2ecf20Sopenharmony_ci#define AFE_PORT_CMD_DEVICE_START 0x000100E5 288c2ecf20Sopenharmony_ci#define AFE_PORT_CMD_DEVICE_STOP 0x000100E6 298c2ecf20Sopenharmony_ci#define AFE_PORT_CMD_SET_PARAM_V2 0x000100EF 308c2ecf20Sopenharmony_ci#define AFE_SVC_CMD_SET_PARAM 0x000100f3 318c2ecf20Sopenharmony_ci#define AFE_PORT_CMDRSP_GET_PARAM_V2 0x00010106 328c2ecf20Sopenharmony_ci#define AFE_PARAM_ID_HDMI_CONFIG 0x00010210 338c2ecf20Sopenharmony_ci#define AFE_MODULE_AUDIO_DEV_INTERFACE 0x0001020C 348c2ecf20Sopenharmony_ci#define AFE_MODULE_TDM 0x0001028A 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci#define AFE_PARAM_ID_CDC_SLIMBUS_SLAVE_CFG 0x00010235 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci#define AFE_PARAM_ID_LPAIF_CLK_CONFIG 0x00010238 398c2ecf20Sopenharmony_ci#define AFE_PARAM_ID_INT_DIGITAL_CDC_CLK_CONFIG 0x00010239 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci#define AFE_PARAM_ID_SLIMBUS_CONFIG 0x00010212 428c2ecf20Sopenharmony_ci#define AFE_PARAM_ID_I2S_CONFIG 0x0001020D 438c2ecf20Sopenharmony_ci#define AFE_PARAM_ID_TDM_CONFIG 0x0001029D 448c2ecf20Sopenharmony_ci#define AFE_PARAM_ID_PORT_SLOT_MAPPING_CONFIG 0x00010297 458c2ecf20Sopenharmony_ci#define AFE_PARAM_ID_CODEC_DMA_CONFIG 0x000102B8 468c2ecf20Sopenharmony_ci#define AFE_CMD_REMOTE_LPASS_CORE_HW_VOTE_REQUEST 0x000100f4 478c2ecf20Sopenharmony_ci#define AFE_CMD_RSP_REMOTE_LPASS_CORE_HW_VOTE_REQUEST 0x000100f5 488c2ecf20Sopenharmony_ci#define AFE_CMD_REMOTE_LPASS_CORE_HW_DEVOTE_REQUEST 0x000100f6 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci/* I2S config specific */ 518c2ecf20Sopenharmony_ci#define AFE_API_VERSION_I2S_CONFIG 0x1 528c2ecf20Sopenharmony_ci#define AFE_PORT_I2S_SD0 0x1 538c2ecf20Sopenharmony_ci#define AFE_PORT_I2S_SD1 0x2 548c2ecf20Sopenharmony_ci#define AFE_PORT_I2S_SD2 0x3 558c2ecf20Sopenharmony_ci#define AFE_PORT_I2S_SD3 0x4 568c2ecf20Sopenharmony_ci#define AFE_PORT_I2S_SD0_MASK BIT(0x0) 578c2ecf20Sopenharmony_ci#define AFE_PORT_I2S_SD1_MASK BIT(0x1) 588c2ecf20Sopenharmony_ci#define AFE_PORT_I2S_SD2_MASK BIT(0x2) 598c2ecf20Sopenharmony_ci#define AFE_PORT_I2S_SD3_MASK BIT(0x3) 608c2ecf20Sopenharmony_ci#define AFE_PORT_I2S_SD0_1_MASK GENMASK(1, 0) 618c2ecf20Sopenharmony_ci#define AFE_PORT_I2S_SD2_3_MASK GENMASK(3, 2) 628c2ecf20Sopenharmony_ci#define AFE_PORT_I2S_SD0_1_2_MASK GENMASK(2, 0) 638c2ecf20Sopenharmony_ci#define AFE_PORT_I2S_SD0_1_2_3_MASK GENMASK(3, 0) 648c2ecf20Sopenharmony_ci#define AFE_PORT_I2S_QUAD01 0x5 658c2ecf20Sopenharmony_ci#define AFE_PORT_I2S_QUAD23 0x6 668c2ecf20Sopenharmony_ci#define AFE_PORT_I2S_6CHS 0x7 678c2ecf20Sopenharmony_ci#define AFE_PORT_I2S_8CHS 0x8 688c2ecf20Sopenharmony_ci#define AFE_PORT_I2S_MONO 0x0 698c2ecf20Sopenharmony_ci#define AFE_PORT_I2S_STEREO 0x1 708c2ecf20Sopenharmony_ci#define AFE_PORT_CONFIG_I2S_WS_SRC_EXTERNAL 0x0 718c2ecf20Sopenharmony_ci#define AFE_PORT_CONFIG_I2S_WS_SRC_INTERNAL 0x1 728c2ecf20Sopenharmony_ci#define AFE_LINEAR_PCM_DATA 0x0 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci/* Port IDs */ 768c2ecf20Sopenharmony_ci#define AFE_API_VERSION_HDMI_CONFIG 0x1 778c2ecf20Sopenharmony_ci#define AFE_PORT_ID_MULTICHAN_HDMI_RX 0x100E 788c2ecf20Sopenharmony_ci#define AFE_PORT_ID_HDMI_OVER_DP_RX 0x6020 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci#define AFE_API_VERSION_SLIMBUS_CONFIG 0x1 818c2ecf20Sopenharmony_ci/* Clock set API version */ 828c2ecf20Sopenharmony_ci#define AFE_API_VERSION_CLOCK_SET 1 838c2ecf20Sopenharmony_ci#define Q6AFE_LPASS_CLK_CONFIG_API_VERSION 0x1 848c2ecf20Sopenharmony_ci#define AFE_MODULE_CLOCK_SET 0x0001028F 858c2ecf20Sopenharmony_ci#define AFE_PARAM_ID_CLOCK_SET 0x00010290 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci/* SLIMbus Rx port on channel 0. */ 888c2ecf20Sopenharmony_ci#define AFE_PORT_ID_SLIMBUS_MULTI_CHAN_0_RX 0x4000 898c2ecf20Sopenharmony_ci/* SLIMbus Tx port on channel 0. */ 908c2ecf20Sopenharmony_ci#define AFE_PORT_ID_SLIMBUS_MULTI_CHAN_0_TX 0x4001 918c2ecf20Sopenharmony_ci/* SLIMbus Rx port on channel 1. */ 928c2ecf20Sopenharmony_ci#define AFE_PORT_ID_SLIMBUS_MULTI_CHAN_1_RX 0x4002 938c2ecf20Sopenharmony_ci/* SLIMbus Tx port on channel 1. */ 948c2ecf20Sopenharmony_ci#define AFE_PORT_ID_SLIMBUS_MULTI_CHAN_1_TX 0x4003 958c2ecf20Sopenharmony_ci/* SLIMbus Rx port on channel 2. */ 968c2ecf20Sopenharmony_ci#define AFE_PORT_ID_SLIMBUS_MULTI_CHAN_2_RX 0x4004 978c2ecf20Sopenharmony_ci/* SLIMbus Tx port on channel 2. */ 988c2ecf20Sopenharmony_ci#define AFE_PORT_ID_SLIMBUS_MULTI_CHAN_2_TX 0x4005 998c2ecf20Sopenharmony_ci/* SLIMbus Rx port on channel 3. */ 1008c2ecf20Sopenharmony_ci#define AFE_PORT_ID_SLIMBUS_MULTI_CHAN_3_RX 0x4006 1018c2ecf20Sopenharmony_ci/* SLIMbus Tx port on channel 3. */ 1028c2ecf20Sopenharmony_ci#define AFE_PORT_ID_SLIMBUS_MULTI_CHAN_3_TX 0x4007 1038c2ecf20Sopenharmony_ci/* SLIMbus Rx port on channel 4. */ 1048c2ecf20Sopenharmony_ci#define AFE_PORT_ID_SLIMBUS_MULTI_CHAN_4_RX 0x4008 1058c2ecf20Sopenharmony_ci/* SLIMbus Tx port on channel 4. */ 1068c2ecf20Sopenharmony_ci#define AFE_PORT_ID_SLIMBUS_MULTI_CHAN_4_TX 0x4009 1078c2ecf20Sopenharmony_ci/* SLIMbus Rx port on channel 5. */ 1088c2ecf20Sopenharmony_ci#define AFE_PORT_ID_SLIMBUS_MULTI_CHAN_5_RX 0x400a 1098c2ecf20Sopenharmony_ci/* SLIMbus Tx port on channel 5. */ 1108c2ecf20Sopenharmony_ci#define AFE_PORT_ID_SLIMBUS_MULTI_CHAN_5_TX 0x400b 1118c2ecf20Sopenharmony_ci/* SLIMbus Rx port on channel 6. */ 1128c2ecf20Sopenharmony_ci#define AFE_PORT_ID_SLIMBUS_MULTI_CHAN_6_RX 0x400c 1138c2ecf20Sopenharmony_ci/* SLIMbus Tx port on channel 6. */ 1148c2ecf20Sopenharmony_ci#define AFE_PORT_ID_SLIMBUS_MULTI_CHAN_6_TX 0x400d 1158c2ecf20Sopenharmony_ci#define AFE_PORT_ID_PRIMARY_MI2S_RX 0x1000 1168c2ecf20Sopenharmony_ci#define AFE_PORT_ID_PRIMARY_MI2S_TX 0x1001 1178c2ecf20Sopenharmony_ci#define AFE_PORT_ID_SECONDARY_MI2S_RX 0x1002 1188c2ecf20Sopenharmony_ci#define AFE_PORT_ID_SECONDARY_MI2S_TX 0x1003 1198c2ecf20Sopenharmony_ci#define AFE_PORT_ID_TERTIARY_MI2S_RX 0x1004 1208c2ecf20Sopenharmony_ci#define AFE_PORT_ID_TERTIARY_MI2S_TX 0x1005 1218c2ecf20Sopenharmony_ci#define AFE_PORT_ID_QUATERNARY_MI2S_RX 0x1006 1228c2ecf20Sopenharmony_ci#define AFE_PORT_ID_QUATERNARY_MI2S_TX 0x1007 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ci/* Start of the range of port IDs for TDM devices. */ 1258c2ecf20Sopenharmony_ci#define AFE_PORT_ID_TDM_PORT_RANGE_START 0x9000 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci/* End of the range of port IDs for TDM devices. */ 1288c2ecf20Sopenharmony_ci#define AFE_PORT_ID_TDM_PORT_RANGE_END \ 1298c2ecf20Sopenharmony_ci (AFE_PORT_ID_TDM_PORT_RANGE_START+0x50-1) 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci/* Size of the range of port IDs for TDM ports. */ 1328c2ecf20Sopenharmony_ci#define AFE_PORT_ID_TDM_PORT_RANGE_SIZE \ 1338c2ecf20Sopenharmony_ci (AFE_PORT_ID_TDM_PORT_RANGE_END - \ 1348c2ecf20Sopenharmony_ci AFE_PORT_ID_TDM_PORT_RANGE_START+1) 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci#define AFE_PORT_ID_PRIMARY_TDM_RX \ 1378c2ecf20Sopenharmony_ci (AFE_PORT_ID_TDM_PORT_RANGE_START + 0x00) 1388c2ecf20Sopenharmony_ci#define AFE_PORT_ID_PRIMARY_TDM_RX_1 \ 1398c2ecf20Sopenharmony_ci (AFE_PORT_ID_PRIMARY_TDM_RX + 0x02) 1408c2ecf20Sopenharmony_ci#define AFE_PORT_ID_PRIMARY_TDM_RX_2 \ 1418c2ecf20Sopenharmony_ci (AFE_PORT_ID_PRIMARY_TDM_RX + 0x04) 1428c2ecf20Sopenharmony_ci#define AFE_PORT_ID_PRIMARY_TDM_RX_3 \ 1438c2ecf20Sopenharmony_ci (AFE_PORT_ID_PRIMARY_TDM_RX + 0x06) 1448c2ecf20Sopenharmony_ci#define AFE_PORT_ID_PRIMARY_TDM_RX_4 \ 1458c2ecf20Sopenharmony_ci (AFE_PORT_ID_PRIMARY_TDM_RX + 0x08) 1468c2ecf20Sopenharmony_ci#define AFE_PORT_ID_PRIMARY_TDM_RX_5 \ 1478c2ecf20Sopenharmony_ci (AFE_PORT_ID_PRIMARY_TDM_RX + 0x0A) 1488c2ecf20Sopenharmony_ci#define AFE_PORT_ID_PRIMARY_TDM_RX_6 \ 1498c2ecf20Sopenharmony_ci (AFE_PORT_ID_PRIMARY_TDM_RX + 0x0C) 1508c2ecf20Sopenharmony_ci#define AFE_PORT_ID_PRIMARY_TDM_RX_7 \ 1518c2ecf20Sopenharmony_ci (AFE_PORT_ID_PRIMARY_TDM_RX + 0x0E) 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_ci#define AFE_PORT_ID_PRIMARY_TDM_TX \ 1548c2ecf20Sopenharmony_ci (AFE_PORT_ID_TDM_PORT_RANGE_START + 0x01) 1558c2ecf20Sopenharmony_ci#define AFE_PORT_ID_PRIMARY_TDM_TX_1 \ 1568c2ecf20Sopenharmony_ci (AFE_PORT_ID_PRIMARY_TDM_TX + 0x02) 1578c2ecf20Sopenharmony_ci#define AFE_PORT_ID_PRIMARY_TDM_TX_2 \ 1588c2ecf20Sopenharmony_ci (AFE_PORT_ID_PRIMARY_TDM_TX + 0x04) 1598c2ecf20Sopenharmony_ci#define AFE_PORT_ID_PRIMARY_TDM_TX_3 \ 1608c2ecf20Sopenharmony_ci (AFE_PORT_ID_PRIMARY_TDM_TX + 0x06) 1618c2ecf20Sopenharmony_ci#define AFE_PORT_ID_PRIMARY_TDM_TX_4 \ 1628c2ecf20Sopenharmony_ci (AFE_PORT_ID_PRIMARY_TDM_TX + 0x08) 1638c2ecf20Sopenharmony_ci#define AFE_PORT_ID_PRIMARY_TDM_TX_5 \ 1648c2ecf20Sopenharmony_ci (AFE_PORT_ID_PRIMARY_TDM_TX + 0x0A) 1658c2ecf20Sopenharmony_ci#define AFE_PORT_ID_PRIMARY_TDM_TX_6 \ 1668c2ecf20Sopenharmony_ci (AFE_PORT_ID_PRIMARY_TDM_TX + 0x0C) 1678c2ecf20Sopenharmony_ci#define AFE_PORT_ID_PRIMARY_TDM_TX_7 \ 1688c2ecf20Sopenharmony_ci (AFE_PORT_ID_PRIMARY_TDM_TX + 0x0E) 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_ci#define AFE_PORT_ID_SECONDARY_TDM_RX \ 1718c2ecf20Sopenharmony_ci (AFE_PORT_ID_TDM_PORT_RANGE_START + 0x10) 1728c2ecf20Sopenharmony_ci#define AFE_PORT_ID_SECONDARY_TDM_RX_1 \ 1738c2ecf20Sopenharmony_ci (AFE_PORT_ID_SECONDARY_TDM_RX + 0x02) 1748c2ecf20Sopenharmony_ci#define AFE_PORT_ID_SECONDARY_TDM_RX_2 \ 1758c2ecf20Sopenharmony_ci (AFE_PORT_ID_SECONDARY_TDM_RX + 0x04) 1768c2ecf20Sopenharmony_ci#define AFE_PORT_ID_SECONDARY_TDM_RX_3 \ 1778c2ecf20Sopenharmony_ci (AFE_PORT_ID_SECONDARY_TDM_RX + 0x06) 1788c2ecf20Sopenharmony_ci#define AFE_PORT_ID_SECONDARY_TDM_RX_4 \ 1798c2ecf20Sopenharmony_ci (AFE_PORT_ID_SECONDARY_TDM_RX + 0x08) 1808c2ecf20Sopenharmony_ci#define AFE_PORT_ID_SECONDARY_TDM_RX_5 \ 1818c2ecf20Sopenharmony_ci (AFE_PORT_ID_SECONDARY_TDM_RX + 0x0A) 1828c2ecf20Sopenharmony_ci#define AFE_PORT_ID_SECONDARY_TDM_RX_6 \ 1838c2ecf20Sopenharmony_ci (AFE_PORT_ID_SECONDARY_TDM_RX + 0x0C) 1848c2ecf20Sopenharmony_ci#define AFE_PORT_ID_SECONDARY_TDM_RX_7 \ 1858c2ecf20Sopenharmony_ci (AFE_PORT_ID_SECONDARY_TDM_RX + 0x0E) 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_ci#define AFE_PORT_ID_SECONDARY_TDM_TX \ 1888c2ecf20Sopenharmony_ci (AFE_PORT_ID_TDM_PORT_RANGE_START + 0x11) 1898c2ecf20Sopenharmony_ci#define AFE_PORT_ID_SECONDARY_TDM_TX_1 \ 1908c2ecf20Sopenharmony_ci (AFE_PORT_ID_SECONDARY_TDM_TX + 0x02) 1918c2ecf20Sopenharmony_ci#define AFE_PORT_ID_SECONDARY_TDM_TX_2 \ 1928c2ecf20Sopenharmony_ci (AFE_PORT_ID_SECONDARY_TDM_TX + 0x04) 1938c2ecf20Sopenharmony_ci#define AFE_PORT_ID_SECONDARY_TDM_TX_3 \ 1948c2ecf20Sopenharmony_ci (AFE_PORT_ID_SECONDARY_TDM_TX + 0x06) 1958c2ecf20Sopenharmony_ci#define AFE_PORT_ID_SECONDARY_TDM_TX_4 \ 1968c2ecf20Sopenharmony_ci (AFE_PORT_ID_SECONDARY_TDM_TX + 0x08) 1978c2ecf20Sopenharmony_ci#define AFE_PORT_ID_SECONDARY_TDM_TX_5 \ 1988c2ecf20Sopenharmony_ci (AFE_PORT_ID_SECONDARY_TDM_TX + 0x0A) 1998c2ecf20Sopenharmony_ci#define AFE_PORT_ID_SECONDARY_TDM_TX_6 \ 2008c2ecf20Sopenharmony_ci (AFE_PORT_ID_SECONDARY_TDM_TX + 0x0C) 2018c2ecf20Sopenharmony_ci#define AFE_PORT_ID_SECONDARY_TDM_TX_7 \ 2028c2ecf20Sopenharmony_ci (AFE_PORT_ID_SECONDARY_TDM_TX + 0x0E) 2038c2ecf20Sopenharmony_ci 2048c2ecf20Sopenharmony_ci#define AFE_PORT_ID_TERTIARY_TDM_RX \ 2058c2ecf20Sopenharmony_ci (AFE_PORT_ID_TDM_PORT_RANGE_START + 0x20) 2068c2ecf20Sopenharmony_ci#define AFE_PORT_ID_TERTIARY_TDM_RX_1 \ 2078c2ecf20Sopenharmony_ci (AFE_PORT_ID_TERTIARY_TDM_RX + 0x02) 2088c2ecf20Sopenharmony_ci#define AFE_PORT_ID_TERTIARY_TDM_RX_2 \ 2098c2ecf20Sopenharmony_ci (AFE_PORT_ID_TERTIARY_TDM_RX + 0x04) 2108c2ecf20Sopenharmony_ci#define AFE_PORT_ID_TERTIARY_TDM_RX_3 \ 2118c2ecf20Sopenharmony_ci (AFE_PORT_ID_TERTIARY_TDM_RX + 0x06) 2128c2ecf20Sopenharmony_ci#define AFE_PORT_ID_TERTIARY_TDM_RX_4 \ 2138c2ecf20Sopenharmony_ci (AFE_PORT_ID_TERTIARY_TDM_RX + 0x08) 2148c2ecf20Sopenharmony_ci#define AFE_PORT_ID_TERTIARY_TDM_RX_5 \ 2158c2ecf20Sopenharmony_ci (AFE_PORT_ID_TERTIARY_TDM_RX + 0x0A) 2168c2ecf20Sopenharmony_ci#define AFE_PORT_ID_TERTIARY_TDM_RX_6 \ 2178c2ecf20Sopenharmony_ci (AFE_PORT_ID_TERTIARY_TDM_RX + 0x0C) 2188c2ecf20Sopenharmony_ci#define AFE_PORT_ID_TERTIARY_TDM_RX_7 \ 2198c2ecf20Sopenharmony_ci (AFE_PORT_ID_TERTIARY_TDM_RX + 0x0E) 2208c2ecf20Sopenharmony_ci 2218c2ecf20Sopenharmony_ci#define AFE_PORT_ID_TERTIARY_TDM_TX \ 2228c2ecf20Sopenharmony_ci (AFE_PORT_ID_TDM_PORT_RANGE_START + 0x21) 2238c2ecf20Sopenharmony_ci#define AFE_PORT_ID_TERTIARY_TDM_TX_1 \ 2248c2ecf20Sopenharmony_ci (AFE_PORT_ID_TERTIARY_TDM_TX + 0x02) 2258c2ecf20Sopenharmony_ci#define AFE_PORT_ID_TERTIARY_TDM_TX_2 \ 2268c2ecf20Sopenharmony_ci (AFE_PORT_ID_TERTIARY_TDM_TX + 0x04) 2278c2ecf20Sopenharmony_ci#define AFE_PORT_ID_TERTIARY_TDM_TX_3 \ 2288c2ecf20Sopenharmony_ci (AFE_PORT_ID_TERTIARY_TDM_TX + 0x06) 2298c2ecf20Sopenharmony_ci#define AFE_PORT_ID_TERTIARY_TDM_TX_4 \ 2308c2ecf20Sopenharmony_ci (AFE_PORT_ID_TERTIARY_TDM_TX + 0x08) 2318c2ecf20Sopenharmony_ci#define AFE_PORT_ID_TERTIARY_TDM_TX_5 \ 2328c2ecf20Sopenharmony_ci (AFE_PORT_ID_TERTIARY_TDM_TX + 0x0A) 2338c2ecf20Sopenharmony_ci#define AFE_PORT_ID_TERTIARY_TDM_TX_6 \ 2348c2ecf20Sopenharmony_ci (AFE_PORT_ID_TERTIARY_TDM_TX + 0x0C) 2358c2ecf20Sopenharmony_ci#define AFE_PORT_ID_TERTIARY_TDM_TX_7 \ 2368c2ecf20Sopenharmony_ci (AFE_PORT_ID_TERTIARY_TDM_TX + 0x0E) 2378c2ecf20Sopenharmony_ci 2388c2ecf20Sopenharmony_ci#define AFE_PORT_ID_QUATERNARY_TDM_RX \ 2398c2ecf20Sopenharmony_ci (AFE_PORT_ID_TDM_PORT_RANGE_START + 0x30) 2408c2ecf20Sopenharmony_ci#define AFE_PORT_ID_QUATERNARY_TDM_RX_1 \ 2418c2ecf20Sopenharmony_ci (AFE_PORT_ID_QUATERNARY_TDM_RX + 0x02) 2428c2ecf20Sopenharmony_ci#define AFE_PORT_ID_QUATERNARY_TDM_RX_2 \ 2438c2ecf20Sopenharmony_ci (AFE_PORT_ID_QUATERNARY_TDM_RX + 0x04) 2448c2ecf20Sopenharmony_ci#define AFE_PORT_ID_QUATERNARY_TDM_RX_3 \ 2458c2ecf20Sopenharmony_ci (AFE_PORT_ID_QUATERNARY_TDM_RX + 0x06) 2468c2ecf20Sopenharmony_ci#define AFE_PORT_ID_QUATERNARY_TDM_RX_4 \ 2478c2ecf20Sopenharmony_ci (AFE_PORT_ID_QUATERNARY_TDM_RX + 0x08) 2488c2ecf20Sopenharmony_ci#define AFE_PORT_ID_QUATERNARY_TDM_RX_5 \ 2498c2ecf20Sopenharmony_ci (AFE_PORT_ID_QUATERNARY_TDM_RX + 0x0A) 2508c2ecf20Sopenharmony_ci#define AFE_PORT_ID_QUATERNARY_TDM_RX_6 \ 2518c2ecf20Sopenharmony_ci (AFE_PORT_ID_QUATERNARY_TDM_RX + 0x0C) 2528c2ecf20Sopenharmony_ci#define AFE_PORT_ID_QUATERNARY_TDM_RX_7 \ 2538c2ecf20Sopenharmony_ci (AFE_PORT_ID_QUATERNARY_TDM_RX + 0x0E) 2548c2ecf20Sopenharmony_ci 2558c2ecf20Sopenharmony_ci#define AFE_PORT_ID_QUATERNARY_TDM_TX \ 2568c2ecf20Sopenharmony_ci (AFE_PORT_ID_TDM_PORT_RANGE_START + 0x31) 2578c2ecf20Sopenharmony_ci#define AFE_PORT_ID_QUATERNARY_TDM_TX_1 \ 2588c2ecf20Sopenharmony_ci (AFE_PORT_ID_QUATERNARY_TDM_TX + 0x02) 2598c2ecf20Sopenharmony_ci#define AFE_PORT_ID_QUATERNARY_TDM_TX_2 \ 2608c2ecf20Sopenharmony_ci (AFE_PORT_ID_QUATERNARY_TDM_TX + 0x04) 2618c2ecf20Sopenharmony_ci#define AFE_PORT_ID_QUATERNARY_TDM_TX_3 \ 2628c2ecf20Sopenharmony_ci (AFE_PORT_ID_QUATERNARY_TDM_TX + 0x06) 2638c2ecf20Sopenharmony_ci#define AFE_PORT_ID_QUATERNARY_TDM_TX_4 \ 2648c2ecf20Sopenharmony_ci (AFE_PORT_ID_QUATERNARY_TDM_TX + 0x08) 2658c2ecf20Sopenharmony_ci#define AFE_PORT_ID_QUATERNARY_TDM_TX_5 \ 2668c2ecf20Sopenharmony_ci (AFE_PORT_ID_QUATERNARY_TDM_TX + 0x0A) 2678c2ecf20Sopenharmony_ci#define AFE_PORT_ID_QUATERNARY_TDM_TX_6 \ 2688c2ecf20Sopenharmony_ci (AFE_PORT_ID_QUATERNARY_TDM_TX + 0x0C) 2698c2ecf20Sopenharmony_ci#define AFE_PORT_ID_QUATERNARY_TDM_TX_7 \ 2708c2ecf20Sopenharmony_ci (AFE_PORT_ID_QUATERNARY_TDM_TX + 0x0E) 2718c2ecf20Sopenharmony_ci 2728c2ecf20Sopenharmony_ci#define AFE_PORT_ID_QUINARY_TDM_RX \ 2738c2ecf20Sopenharmony_ci (AFE_PORT_ID_TDM_PORT_RANGE_START + 0x40) 2748c2ecf20Sopenharmony_ci#define AFE_PORT_ID_QUINARY_TDM_RX_1 \ 2758c2ecf20Sopenharmony_ci (AFE_PORT_ID_QUINARY_TDM_RX + 0x02) 2768c2ecf20Sopenharmony_ci#define AFE_PORT_ID_QUINARY_TDM_RX_2 \ 2778c2ecf20Sopenharmony_ci (AFE_PORT_ID_QUINARY_TDM_RX + 0x04) 2788c2ecf20Sopenharmony_ci#define AFE_PORT_ID_QUINARY_TDM_RX_3 \ 2798c2ecf20Sopenharmony_ci (AFE_PORT_ID_QUINARY_TDM_RX + 0x06) 2808c2ecf20Sopenharmony_ci#define AFE_PORT_ID_QUINARY_TDM_RX_4 \ 2818c2ecf20Sopenharmony_ci (AFE_PORT_ID_QUINARY_TDM_RX + 0x08) 2828c2ecf20Sopenharmony_ci#define AFE_PORT_ID_QUINARY_TDM_RX_5 \ 2838c2ecf20Sopenharmony_ci (AFE_PORT_ID_QUINARY_TDM_RX + 0x0A) 2848c2ecf20Sopenharmony_ci#define AFE_PORT_ID_QUINARY_TDM_RX_6 \ 2858c2ecf20Sopenharmony_ci (AFE_PORT_ID_QUINARY_TDM_RX + 0x0C) 2868c2ecf20Sopenharmony_ci#define AFE_PORT_ID_QUINARY_TDM_RX_7 \ 2878c2ecf20Sopenharmony_ci (AFE_PORT_ID_QUINARY_TDM_RX + 0x0E) 2888c2ecf20Sopenharmony_ci 2898c2ecf20Sopenharmony_ci#define AFE_PORT_ID_QUINARY_TDM_TX \ 2908c2ecf20Sopenharmony_ci (AFE_PORT_ID_TDM_PORT_RANGE_START + 0x41) 2918c2ecf20Sopenharmony_ci#define AFE_PORT_ID_QUINARY_TDM_TX_1 \ 2928c2ecf20Sopenharmony_ci (AFE_PORT_ID_QUINARY_TDM_TX + 0x02) 2938c2ecf20Sopenharmony_ci#define AFE_PORT_ID_QUINARY_TDM_TX_2 \ 2948c2ecf20Sopenharmony_ci (AFE_PORT_ID_QUINARY_TDM_TX + 0x04) 2958c2ecf20Sopenharmony_ci#define AFE_PORT_ID_QUINARY_TDM_TX_3 \ 2968c2ecf20Sopenharmony_ci (AFE_PORT_ID_QUINARY_TDM_TX + 0x06) 2978c2ecf20Sopenharmony_ci#define AFE_PORT_ID_QUINARY_TDM_TX_4 \ 2988c2ecf20Sopenharmony_ci (AFE_PORT_ID_QUINARY_TDM_TX + 0x08) 2998c2ecf20Sopenharmony_ci#define AFE_PORT_ID_QUINARY_TDM_TX_5 \ 3008c2ecf20Sopenharmony_ci (AFE_PORT_ID_QUINARY_TDM_TX + 0x0A) 3018c2ecf20Sopenharmony_ci#define AFE_PORT_ID_QUINARY_TDM_TX_6 \ 3028c2ecf20Sopenharmony_ci (AFE_PORT_ID_QUINARY_TDM_TX + 0x0C) 3038c2ecf20Sopenharmony_ci#define AFE_PORT_ID_QUINARY_TDM_TX_7 \ 3048c2ecf20Sopenharmony_ci (AFE_PORT_ID_QUINARY_TDM_TX + 0x0E) 3058c2ecf20Sopenharmony_ci 3068c2ecf20Sopenharmony_ci/* AFE WSA Codec DMA Rx port 0 */ 3078c2ecf20Sopenharmony_ci#define AFE_PORT_ID_WSA_CODEC_DMA_RX_0 0xB000 3088c2ecf20Sopenharmony_ci/* AFE WSA Codec DMA Tx port 0 */ 3098c2ecf20Sopenharmony_ci#define AFE_PORT_ID_WSA_CODEC_DMA_TX_0 0xB001 3108c2ecf20Sopenharmony_ci/* AFE WSA Codec DMA Rx port 1 */ 3118c2ecf20Sopenharmony_ci#define AFE_PORT_ID_WSA_CODEC_DMA_RX_1 0xB002 3128c2ecf20Sopenharmony_ci/* AFE WSA Codec DMA Tx port 1 */ 3138c2ecf20Sopenharmony_ci#define AFE_PORT_ID_WSA_CODEC_DMA_TX_1 0xB003 3148c2ecf20Sopenharmony_ci/* AFE WSA Codec DMA Tx port 2 */ 3158c2ecf20Sopenharmony_ci#define AFE_PORT_ID_WSA_CODEC_DMA_TX_2 0xB005 3168c2ecf20Sopenharmony_ci/* AFE VA Codec DMA Tx port 0 */ 3178c2ecf20Sopenharmony_ci#define AFE_PORT_ID_VA_CODEC_DMA_TX_0 0xB021 3188c2ecf20Sopenharmony_ci/* AFE VA Codec DMA Tx port 1 */ 3198c2ecf20Sopenharmony_ci#define AFE_PORT_ID_VA_CODEC_DMA_TX_1 0xB023 3208c2ecf20Sopenharmony_ci/* AFE VA Codec DMA Tx port 2 */ 3218c2ecf20Sopenharmony_ci#define AFE_PORT_ID_VA_CODEC_DMA_TX_2 0xB025 3228c2ecf20Sopenharmony_ci/* AFE Rx Codec DMA Rx port 0 */ 3238c2ecf20Sopenharmony_ci#define AFE_PORT_ID_RX_CODEC_DMA_RX_0 0xB030 3248c2ecf20Sopenharmony_ci/* AFE Tx Codec DMA Tx port 0 */ 3258c2ecf20Sopenharmony_ci#define AFE_PORT_ID_TX_CODEC_DMA_TX_0 0xB031 3268c2ecf20Sopenharmony_ci/* AFE Rx Codec DMA Rx port 1 */ 3278c2ecf20Sopenharmony_ci#define AFE_PORT_ID_RX_CODEC_DMA_RX_1 0xB032 3288c2ecf20Sopenharmony_ci/* AFE Tx Codec DMA Tx port 1 */ 3298c2ecf20Sopenharmony_ci#define AFE_PORT_ID_TX_CODEC_DMA_TX_1 0xB033 3308c2ecf20Sopenharmony_ci/* AFE Rx Codec DMA Rx port 2 */ 3318c2ecf20Sopenharmony_ci#define AFE_PORT_ID_RX_CODEC_DMA_RX_2 0xB034 3328c2ecf20Sopenharmony_ci/* AFE Tx Codec DMA Tx port 2 */ 3338c2ecf20Sopenharmony_ci#define AFE_PORT_ID_TX_CODEC_DMA_TX_2 0xB035 3348c2ecf20Sopenharmony_ci/* AFE Rx Codec DMA Rx port 3 */ 3358c2ecf20Sopenharmony_ci#define AFE_PORT_ID_RX_CODEC_DMA_RX_3 0xB036 3368c2ecf20Sopenharmony_ci/* AFE Tx Codec DMA Tx port 3 */ 3378c2ecf20Sopenharmony_ci#define AFE_PORT_ID_TX_CODEC_DMA_TX_3 0xB037 3388c2ecf20Sopenharmony_ci/* AFE Rx Codec DMA Rx port 4 */ 3398c2ecf20Sopenharmony_ci#define AFE_PORT_ID_RX_CODEC_DMA_RX_4 0xB038 3408c2ecf20Sopenharmony_ci/* AFE Tx Codec DMA Tx port 4 */ 3418c2ecf20Sopenharmony_ci#define AFE_PORT_ID_TX_CODEC_DMA_TX_4 0xB039 3428c2ecf20Sopenharmony_ci/* AFE Rx Codec DMA Rx port 5 */ 3438c2ecf20Sopenharmony_ci#define AFE_PORT_ID_RX_CODEC_DMA_RX_5 0xB03A 3448c2ecf20Sopenharmony_ci/* AFE Tx Codec DMA Tx port 5 */ 3458c2ecf20Sopenharmony_ci#define AFE_PORT_ID_TX_CODEC_DMA_TX_5 0xB03B 3468c2ecf20Sopenharmony_ci/* AFE Rx Codec DMA Rx port 6 */ 3478c2ecf20Sopenharmony_ci#define AFE_PORT_ID_RX_CODEC_DMA_RX_6 0xB03C 3488c2ecf20Sopenharmony_ci/* AFE Rx Codec DMA Rx port 7 */ 3498c2ecf20Sopenharmony_ci#define AFE_PORT_ID_RX_CODEC_DMA_RX_7 0xB03E 3508c2ecf20Sopenharmony_ci 3518c2ecf20Sopenharmony_ci#define Q6AFE_LPASS_MODE_CLK1_VALID 1 3528c2ecf20Sopenharmony_ci#define Q6AFE_LPASS_MODE_CLK2_VALID 2 3538c2ecf20Sopenharmony_ci#define Q6AFE_LPASS_CLK_SRC_INTERNAL 1 3548c2ecf20Sopenharmony_ci#define Q6AFE_LPASS_CLK_ROOT_DEFAULT 0 3558c2ecf20Sopenharmony_ci#define AFE_API_VERSION_TDM_CONFIG 1 3568c2ecf20Sopenharmony_ci#define AFE_API_VERSION_SLOT_MAPPING_CONFIG 1 3578c2ecf20Sopenharmony_ci#define AFE_API_VERSION_CODEC_DMA_CONFIG 1 3588c2ecf20Sopenharmony_ci 3598c2ecf20Sopenharmony_ci#define TIMEOUT_MS 1000 3608c2ecf20Sopenharmony_ci#define AFE_CMD_RESP_AVAIL 0 3618c2ecf20Sopenharmony_ci#define AFE_CMD_RESP_NONE 1 3628c2ecf20Sopenharmony_ci#define AFE_CLK_TOKEN 1024 3638c2ecf20Sopenharmony_ci 3648c2ecf20Sopenharmony_cistruct q6afe { 3658c2ecf20Sopenharmony_ci struct apr_device *apr; 3668c2ecf20Sopenharmony_ci struct device *dev; 3678c2ecf20Sopenharmony_ci struct q6core_svc_api_info ainfo; 3688c2ecf20Sopenharmony_ci struct mutex lock; 3698c2ecf20Sopenharmony_ci struct aprv2_ibasic_rsp_result_t result; 3708c2ecf20Sopenharmony_ci wait_queue_head_t wait; 3718c2ecf20Sopenharmony_ci struct list_head port_list; 3728c2ecf20Sopenharmony_ci spinlock_t port_list_lock; 3738c2ecf20Sopenharmony_ci}; 3748c2ecf20Sopenharmony_ci 3758c2ecf20Sopenharmony_cistruct afe_port_cmd_device_start { 3768c2ecf20Sopenharmony_ci u16 port_id; 3778c2ecf20Sopenharmony_ci u16 reserved; 3788c2ecf20Sopenharmony_ci} __packed; 3798c2ecf20Sopenharmony_ci 3808c2ecf20Sopenharmony_cistruct afe_port_cmd_device_stop { 3818c2ecf20Sopenharmony_ci u16 port_id; 3828c2ecf20Sopenharmony_ci u16 reserved; 3838c2ecf20Sopenharmony_ci/* Reserved for 32-bit alignment. This field must be set to 0.*/ 3848c2ecf20Sopenharmony_ci} __packed; 3858c2ecf20Sopenharmony_ci 3868c2ecf20Sopenharmony_cistruct afe_port_param_data_v2 { 3878c2ecf20Sopenharmony_ci u32 module_id; 3888c2ecf20Sopenharmony_ci u32 param_id; 3898c2ecf20Sopenharmony_ci u16 param_size; 3908c2ecf20Sopenharmony_ci u16 reserved; 3918c2ecf20Sopenharmony_ci} __packed; 3928c2ecf20Sopenharmony_ci 3938c2ecf20Sopenharmony_cistruct afe_svc_cmd_set_param { 3948c2ecf20Sopenharmony_ci uint32_t payload_size; 3958c2ecf20Sopenharmony_ci uint32_t payload_address_lsw; 3968c2ecf20Sopenharmony_ci uint32_t payload_address_msw; 3978c2ecf20Sopenharmony_ci uint32_t mem_map_handle; 3988c2ecf20Sopenharmony_ci} __packed; 3998c2ecf20Sopenharmony_ci 4008c2ecf20Sopenharmony_cistruct afe_port_cmd_set_param_v2 { 4018c2ecf20Sopenharmony_ci u16 port_id; 4028c2ecf20Sopenharmony_ci u16 payload_size; 4038c2ecf20Sopenharmony_ci u32 payload_address_lsw; 4048c2ecf20Sopenharmony_ci u32 payload_address_msw; 4058c2ecf20Sopenharmony_ci u32 mem_map_handle; 4068c2ecf20Sopenharmony_ci} __packed; 4078c2ecf20Sopenharmony_ci 4088c2ecf20Sopenharmony_cistruct afe_param_id_hdmi_multi_chan_audio_cfg { 4098c2ecf20Sopenharmony_ci u32 hdmi_cfg_minor_version; 4108c2ecf20Sopenharmony_ci u16 datatype; 4118c2ecf20Sopenharmony_ci u16 channel_allocation; 4128c2ecf20Sopenharmony_ci u32 sample_rate; 4138c2ecf20Sopenharmony_ci u16 bit_width; 4148c2ecf20Sopenharmony_ci u16 reserved; 4158c2ecf20Sopenharmony_ci} __packed; 4168c2ecf20Sopenharmony_ci 4178c2ecf20Sopenharmony_cistruct afe_param_id_slimbus_cfg { 4188c2ecf20Sopenharmony_ci u32 sb_cfg_minor_version; 4198c2ecf20Sopenharmony_ci/* Minor version used for tracking the version of the SLIMBUS 4208c2ecf20Sopenharmony_ci * configuration interface. 4218c2ecf20Sopenharmony_ci * Supported values: #AFE_API_VERSION_SLIMBUS_CONFIG 4228c2ecf20Sopenharmony_ci */ 4238c2ecf20Sopenharmony_ci 4248c2ecf20Sopenharmony_ci u16 slimbus_dev_id; 4258c2ecf20Sopenharmony_ci/* SLIMbus hardware device ID, which is required to handle 4268c2ecf20Sopenharmony_ci * multiple SLIMbus hardware blocks. 4278c2ecf20Sopenharmony_ci * Supported values: - #AFE_SLIMBUS_DEVICE_1 - #AFE_SLIMBUS_DEVICE_2 4288c2ecf20Sopenharmony_ci */ 4298c2ecf20Sopenharmony_ci u16 bit_width; 4308c2ecf20Sopenharmony_ci/* Bit width of the sample. 4318c2ecf20Sopenharmony_ci * Supported values: 16, 24 4328c2ecf20Sopenharmony_ci */ 4338c2ecf20Sopenharmony_ci u16 data_format; 4348c2ecf20Sopenharmony_ci/* Data format supported by the SLIMbus hardware. The default is 4358c2ecf20Sopenharmony_ci * 0 (#AFE_SB_DATA_FORMAT_NOT_INDICATED), which indicates the 4368c2ecf20Sopenharmony_ci * hardware does not perform any format conversions before the data 4378c2ecf20Sopenharmony_ci * transfer. 4388c2ecf20Sopenharmony_ci */ 4398c2ecf20Sopenharmony_ci u16 num_channels; 4408c2ecf20Sopenharmony_ci/* Number of channels. 4418c2ecf20Sopenharmony_ci * Supported values: 1 to #AFE_PORT_MAX_AUDIO_CHAN_CNT 4428c2ecf20Sopenharmony_ci */ 4438c2ecf20Sopenharmony_ci u8 shared_ch_mapping[AFE_PORT_MAX_AUDIO_CHAN_CNT]; 4448c2ecf20Sopenharmony_ci/* Mapping of shared channel IDs (128 to 255) to which the 4458c2ecf20Sopenharmony_ci * master port is to be connected. 4468c2ecf20Sopenharmony_ci * Shared_channel_mapping[i] represents the shared channel assigned 4478c2ecf20Sopenharmony_ci * for audio channel i in multichannel audio data. 4488c2ecf20Sopenharmony_ci */ 4498c2ecf20Sopenharmony_ci u32 sample_rate; 4508c2ecf20Sopenharmony_ci/* Sampling rate of the port. 4518c2ecf20Sopenharmony_ci * Supported values: 4528c2ecf20Sopenharmony_ci * - #AFE_PORT_SAMPLE_RATE_8K 4538c2ecf20Sopenharmony_ci * - #AFE_PORT_SAMPLE_RATE_16K 4548c2ecf20Sopenharmony_ci * - #AFE_PORT_SAMPLE_RATE_48K 4558c2ecf20Sopenharmony_ci * - #AFE_PORT_SAMPLE_RATE_96K 4568c2ecf20Sopenharmony_ci * - #AFE_PORT_SAMPLE_RATE_192K 4578c2ecf20Sopenharmony_ci */ 4588c2ecf20Sopenharmony_ci} __packed; 4598c2ecf20Sopenharmony_ci 4608c2ecf20Sopenharmony_cistruct afe_clk_cfg { 4618c2ecf20Sopenharmony_ci u32 i2s_cfg_minor_version; 4628c2ecf20Sopenharmony_ci u32 clk_val1; 4638c2ecf20Sopenharmony_ci u32 clk_val2; 4648c2ecf20Sopenharmony_ci u16 clk_src; 4658c2ecf20Sopenharmony_ci u16 clk_root; 4668c2ecf20Sopenharmony_ci u16 clk_set_mode; 4678c2ecf20Sopenharmony_ci u16 reserved; 4688c2ecf20Sopenharmony_ci} __packed; 4698c2ecf20Sopenharmony_ci 4708c2ecf20Sopenharmony_cistruct afe_digital_clk_cfg { 4718c2ecf20Sopenharmony_ci u32 i2s_cfg_minor_version; 4728c2ecf20Sopenharmony_ci u32 clk_val; 4738c2ecf20Sopenharmony_ci u16 clk_root; 4748c2ecf20Sopenharmony_ci u16 reserved; 4758c2ecf20Sopenharmony_ci} __packed; 4768c2ecf20Sopenharmony_ci 4778c2ecf20Sopenharmony_cistruct afe_param_id_i2s_cfg { 4788c2ecf20Sopenharmony_ci u32 i2s_cfg_minor_version; 4798c2ecf20Sopenharmony_ci u16 bit_width; 4808c2ecf20Sopenharmony_ci u16 channel_mode; 4818c2ecf20Sopenharmony_ci u16 mono_stereo; 4828c2ecf20Sopenharmony_ci u16 ws_src; 4838c2ecf20Sopenharmony_ci u32 sample_rate; 4848c2ecf20Sopenharmony_ci u16 data_format; 4858c2ecf20Sopenharmony_ci u16 reserved; 4868c2ecf20Sopenharmony_ci} __packed; 4878c2ecf20Sopenharmony_ci 4888c2ecf20Sopenharmony_cistruct afe_param_id_tdm_cfg { 4898c2ecf20Sopenharmony_ci u32 tdm_cfg_minor_version; 4908c2ecf20Sopenharmony_ci u32 num_channels; 4918c2ecf20Sopenharmony_ci u32 sample_rate; 4928c2ecf20Sopenharmony_ci u32 bit_width; 4938c2ecf20Sopenharmony_ci u16 data_format; 4948c2ecf20Sopenharmony_ci u16 sync_mode; 4958c2ecf20Sopenharmony_ci u16 sync_src; 4968c2ecf20Sopenharmony_ci u16 nslots_per_frame; 4978c2ecf20Sopenharmony_ci u16 ctrl_data_out_enable; 4988c2ecf20Sopenharmony_ci u16 ctrl_invert_sync_pulse; 4998c2ecf20Sopenharmony_ci u16 ctrl_sync_data_delay; 5008c2ecf20Sopenharmony_ci u16 slot_width; 5018c2ecf20Sopenharmony_ci u32 slot_mask; 5028c2ecf20Sopenharmony_ci} __packed; 5038c2ecf20Sopenharmony_ci 5048c2ecf20Sopenharmony_cistruct afe_param_id_cdc_dma_cfg { 5058c2ecf20Sopenharmony_ci u32 cdc_dma_cfg_minor_version; 5068c2ecf20Sopenharmony_ci u32 sample_rate; 5078c2ecf20Sopenharmony_ci u16 bit_width; 5088c2ecf20Sopenharmony_ci u16 data_format; 5098c2ecf20Sopenharmony_ci u16 num_channels; 5108c2ecf20Sopenharmony_ci u16 active_channels_mask; 5118c2ecf20Sopenharmony_ci} __packed; 5128c2ecf20Sopenharmony_ci 5138c2ecf20Sopenharmony_ciunion afe_port_config { 5148c2ecf20Sopenharmony_ci struct afe_param_id_hdmi_multi_chan_audio_cfg hdmi_multi_ch; 5158c2ecf20Sopenharmony_ci struct afe_param_id_slimbus_cfg slim_cfg; 5168c2ecf20Sopenharmony_ci struct afe_param_id_i2s_cfg i2s_cfg; 5178c2ecf20Sopenharmony_ci struct afe_param_id_tdm_cfg tdm_cfg; 5188c2ecf20Sopenharmony_ci struct afe_param_id_cdc_dma_cfg dma_cfg; 5198c2ecf20Sopenharmony_ci} __packed; 5208c2ecf20Sopenharmony_ci 5218c2ecf20Sopenharmony_ci 5228c2ecf20Sopenharmony_cistruct afe_clk_set { 5238c2ecf20Sopenharmony_ci uint32_t clk_set_minor_version; 5248c2ecf20Sopenharmony_ci uint32_t clk_id; 5258c2ecf20Sopenharmony_ci uint32_t clk_freq_in_hz; 5268c2ecf20Sopenharmony_ci uint16_t clk_attri; 5278c2ecf20Sopenharmony_ci uint16_t clk_root; 5288c2ecf20Sopenharmony_ci uint32_t enable; 5298c2ecf20Sopenharmony_ci}; 5308c2ecf20Sopenharmony_ci 5318c2ecf20Sopenharmony_cistruct afe_param_id_slot_mapping_cfg { 5328c2ecf20Sopenharmony_ci u32 minor_version; 5338c2ecf20Sopenharmony_ci u16 num_channels; 5348c2ecf20Sopenharmony_ci u16 bitwidth; 5358c2ecf20Sopenharmony_ci u32 data_align_type; 5368c2ecf20Sopenharmony_ci u16 ch_mapping[AFE_PORT_MAX_AUDIO_CHAN_CNT]; 5378c2ecf20Sopenharmony_ci} __packed; 5388c2ecf20Sopenharmony_ci 5398c2ecf20Sopenharmony_cistruct q6afe_port { 5408c2ecf20Sopenharmony_ci wait_queue_head_t wait; 5418c2ecf20Sopenharmony_ci union afe_port_config port_cfg; 5428c2ecf20Sopenharmony_ci struct afe_param_id_slot_mapping_cfg *scfg; 5438c2ecf20Sopenharmony_ci struct aprv2_ibasic_rsp_result_t result; 5448c2ecf20Sopenharmony_ci int token; 5458c2ecf20Sopenharmony_ci int id; 5468c2ecf20Sopenharmony_ci int cfg_type; 5478c2ecf20Sopenharmony_ci struct q6afe *afe; 5488c2ecf20Sopenharmony_ci struct kref refcount; 5498c2ecf20Sopenharmony_ci struct list_head node; 5508c2ecf20Sopenharmony_ci}; 5518c2ecf20Sopenharmony_ci 5528c2ecf20Sopenharmony_cistruct afe_cmd_remote_lpass_core_hw_vote_request { 5538c2ecf20Sopenharmony_ci uint32_t hw_block_id; 5548c2ecf20Sopenharmony_ci char client_name[8]; 5558c2ecf20Sopenharmony_ci} __packed; 5568c2ecf20Sopenharmony_ci 5578c2ecf20Sopenharmony_cistruct afe_cmd_remote_lpass_core_hw_devote_request { 5588c2ecf20Sopenharmony_ci uint32_t hw_block_id; 5598c2ecf20Sopenharmony_ci uint32_t client_handle; 5608c2ecf20Sopenharmony_ci} __packed; 5618c2ecf20Sopenharmony_ci 5628c2ecf20Sopenharmony_ci 5638c2ecf20Sopenharmony_ci 5648c2ecf20Sopenharmony_cistruct afe_port_map { 5658c2ecf20Sopenharmony_ci int port_id; 5668c2ecf20Sopenharmony_ci int token; 5678c2ecf20Sopenharmony_ci int is_rx; 5688c2ecf20Sopenharmony_ci int is_dig_pcm; 5698c2ecf20Sopenharmony_ci}; 5708c2ecf20Sopenharmony_ci 5718c2ecf20Sopenharmony_ci/* 5728c2ecf20Sopenharmony_ci * Mapping between Virtual Port IDs to DSP AFE Port ID 5738c2ecf20Sopenharmony_ci * On B Family SoCs DSP Port IDs are consistent across multiple SoCs 5748c2ecf20Sopenharmony_ci * on A Family SoCs DSP port IDs are same as virtual Port IDs. 5758c2ecf20Sopenharmony_ci */ 5768c2ecf20Sopenharmony_ci 5778c2ecf20Sopenharmony_cistatic struct afe_port_map port_maps[AFE_PORT_MAX] = { 5788c2ecf20Sopenharmony_ci [HDMI_RX] = { AFE_PORT_ID_MULTICHAN_HDMI_RX, HDMI_RX, 1, 1}, 5798c2ecf20Sopenharmony_ci [SLIMBUS_0_RX] = { AFE_PORT_ID_SLIMBUS_MULTI_CHAN_0_RX, 5808c2ecf20Sopenharmony_ci SLIMBUS_0_RX, 1, 1}, 5818c2ecf20Sopenharmony_ci [SLIMBUS_1_RX] = { AFE_PORT_ID_SLIMBUS_MULTI_CHAN_1_RX, 5828c2ecf20Sopenharmony_ci SLIMBUS_1_RX, 1, 1}, 5838c2ecf20Sopenharmony_ci [SLIMBUS_2_RX] = { AFE_PORT_ID_SLIMBUS_MULTI_CHAN_2_RX, 5848c2ecf20Sopenharmony_ci SLIMBUS_2_RX, 1, 1}, 5858c2ecf20Sopenharmony_ci [SLIMBUS_3_RX] = { AFE_PORT_ID_SLIMBUS_MULTI_CHAN_3_RX, 5868c2ecf20Sopenharmony_ci SLIMBUS_3_RX, 1, 1}, 5878c2ecf20Sopenharmony_ci [SLIMBUS_4_RX] = { AFE_PORT_ID_SLIMBUS_MULTI_CHAN_4_RX, 5888c2ecf20Sopenharmony_ci SLIMBUS_4_RX, 1, 1}, 5898c2ecf20Sopenharmony_ci [SLIMBUS_5_RX] = { AFE_PORT_ID_SLIMBUS_MULTI_CHAN_5_RX, 5908c2ecf20Sopenharmony_ci SLIMBUS_5_RX, 1, 1}, 5918c2ecf20Sopenharmony_ci [SLIMBUS_6_RX] = { AFE_PORT_ID_SLIMBUS_MULTI_CHAN_6_RX, 5928c2ecf20Sopenharmony_ci SLIMBUS_6_RX, 1, 1}, 5938c2ecf20Sopenharmony_ci [SLIMBUS_0_TX] = { AFE_PORT_ID_SLIMBUS_MULTI_CHAN_0_TX, 5948c2ecf20Sopenharmony_ci SLIMBUS_0_TX, 0, 1}, 5958c2ecf20Sopenharmony_ci [SLIMBUS_1_TX] = { AFE_PORT_ID_SLIMBUS_MULTI_CHAN_1_TX, 5968c2ecf20Sopenharmony_ci SLIMBUS_1_TX, 0, 1}, 5978c2ecf20Sopenharmony_ci [SLIMBUS_2_TX] = { AFE_PORT_ID_SLIMBUS_MULTI_CHAN_2_TX, 5988c2ecf20Sopenharmony_ci SLIMBUS_2_TX, 0, 1}, 5998c2ecf20Sopenharmony_ci [SLIMBUS_3_TX] = { AFE_PORT_ID_SLIMBUS_MULTI_CHAN_3_TX, 6008c2ecf20Sopenharmony_ci SLIMBUS_3_TX, 0, 1}, 6018c2ecf20Sopenharmony_ci [SLIMBUS_4_TX] = { AFE_PORT_ID_SLIMBUS_MULTI_CHAN_4_TX, 6028c2ecf20Sopenharmony_ci SLIMBUS_4_TX, 0, 1}, 6038c2ecf20Sopenharmony_ci [SLIMBUS_5_TX] = { AFE_PORT_ID_SLIMBUS_MULTI_CHAN_5_TX, 6048c2ecf20Sopenharmony_ci SLIMBUS_5_TX, 0, 1}, 6058c2ecf20Sopenharmony_ci [SLIMBUS_6_TX] = { AFE_PORT_ID_SLIMBUS_MULTI_CHAN_6_TX, 6068c2ecf20Sopenharmony_ci SLIMBUS_6_TX, 0, 1}, 6078c2ecf20Sopenharmony_ci [PRIMARY_MI2S_RX] = { AFE_PORT_ID_PRIMARY_MI2S_RX, 6088c2ecf20Sopenharmony_ci PRIMARY_MI2S_RX, 1, 1}, 6098c2ecf20Sopenharmony_ci [PRIMARY_MI2S_TX] = { AFE_PORT_ID_PRIMARY_MI2S_TX, 6108c2ecf20Sopenharmony_ci PRIMARY_MI2S_RX, 0, 1}, 6118c2ecf20Sopenharmony_ci [SECONDARY_MI2S_RX] = { AFE_PORT_ID_SECONDARY_MI2S_RX, 6128c2ecf20Sopenharmony_ci SECONDARY_MI2S_RX, 1, 1}, 6138c2ecf20Sopenharmony_ci [SECONDARY_MI2S_TX] = { AFE_PORT_ID_SECONDARY_MI2S_TX, 6148c2ecf20Sopenharmony_ci SECONDARY_MI2S_TX, 0, 1}, 6158c2ecf20Sopenharmony_ci [TERTIARY_MI2S_RX] = { AFE_PORT_ID_TERTIARY_MI2S_RX, 6168c2ecf20Sopenharmony_ci TERTIARY_MI2S_RX, 1, 1}, 6178c2ecf20Sopenharmony_ci [TERTIARY_MI2S_TX] = { AFE_PORT_ID_TERTIARY_MI2S_TX, 6188c2ecf20Sopenharmony_ci TERTIARY_MI2S_TX, 0, 1}, 6198c2ecf20Sopenharmony_ci [QUATERNARY_MI2S_RX] = { AFE_PORT_ID_QUATERNARY_MI2S_RX, 6208c2ecf20Sopenharmony_ci QUATERNARY_MI2S_RX, 1, 1}, 6218c2ecf20Sopenharmony_ci [QUATERNARY_MI2S_TX] = { AFE_PORT_ID_QUATERNARY_MI2S_TX, 6228c2ecf20Sopenharmony_ci QUATERNARY_MI2S_TX, 0, 1}, 6238c2ecf20Sopenharmony_ci [PRIMARY_TDM_RX_0] = { AFE_PORT_ID_PRIMARY_TDM_RX, 6248c2ecf20Sopenharmony_ci PRIMARY_TDM_RX_0, 1, 1}, 6258c2ecf20Sopenharmony_ci [PRIMARY_TDM_TX_0] = { AFE_PORT_ID_PRIMARY_TDM_TX, 6268c2ecf20Sopenharmony_ci PRIMARY_TDM_TX_0, 0, 1}, 6278c2ecf20Sopenharmony_ci [PRIMARY_TDM_RX_1] = { AFE_PORT_ID_PRIMARY_TDM_RX_1, 6288c2ecf20Sopenharmony_ci PRIMARY_TDM_RX_1, 1, 1}, 6298c2ecf20Sopenharmony_ci [PRIMARY_TDM_TX_1] = { AFE_PORT_ID_PRIMARY_TDM_TX_1, 6308c2ecf20Sopenharmony_ci PRIMARY_TDM_TX_1, 0, 1}, 6318c2ecf20Sopenharmony_ci [PRIMARY_TDM_RX_2] = { AFE_PORT_ID_PRIMARY_TDM_RX_2, 6328c2ecf20Sopenharmony_ci PRIMARY_TDM_RX_2, 1, 1}, 6338c2ecf20Sopenharmony_ci [PRIMARY_TDM_TX_2] = { AFE_PORT_ID_PRIMARY_TDM_TX_2, 6348c2ecf20Sopenharmony_ci PRIMARY_TDM_TX_2, 0, 1}, 6358c2ecf20Sopenharmony_ci [PRIMARY_TDM_RX_3] = { AFE_PORT_ID_PRIMARY_TDM_RX_3, 6368c2ecf20Sopenharmony_ci PRIMARY_TDM_RX_3, 1, 1}, 6378c2ecf20Sopenharmony_ci [PRIMARY_TDM_TX_3] = { AFE_PORT_ID_PRIMARY_TDM_TX_3, 6388c2ecf20Sopenharmony_ci PRIMARY_TDM_TX_3, 0, 1}, 6398c2ecf20Sopenharmony_ci [PRIMARY_TDM_RX_4] = { AFE_PORT_ID_PRIMARY_TDM_RX_4, 6408c2ecf20Sopenharmony_ci PRIMARY_TDM_RX_4, 1, 1}, 6418c2ecf20Sopenharmony_ci [PRIMARY_TDM_TX_4] = { AFE_PORT_ID_PRIMARY_TDM_TX_4, 6428c2ecf20Sopenharmony_ci PRIMARY_TDM_TX_4, 0, 1}, 6438c2ecf20Sopenharmony_ci [PRIMARY_TDM_RX_5] = { AFE_PORT_ID_PRIMARY_TDM_RX_5, 6448c2ecf20Sopenharmony_ci PRIMARY_TDM_RX_5, 1, 1}, 6458c2ecf20Sopenharmony_ci [PRIMARY_TDM_TX_5] = { AFE_PORT_ID_PRIMARY_TDM_TX_5, 6468c2ecf20Sopenharmony_ci PRIMARY_TDM_TX_5, 0, 1}, 6478c2ecf20Sopenharmony_ci [PRIMARY_TDM_RX_6] = { AFE_PORT_ID_PRIMARY_TDM_RX_6, 6488c2ecf20Sopenharmony_ci PRIMARY_TDM_RX_6, 1, 1}, 6498c2ecf20Sopenharmony_ci [PRIMARY_TDM_TX_6] = { AFE_PORT_ID_PRIMARY_TDM_TX_6, 6508c2ecf20Sopenharmony_ci PRIMARY_TDM_TX_6, 0, 1}, 6518c2ecf20Sopenharmony_ci [PRIMARY_TDM_RX_7] = { AFE_PORT_ID_PRIMARY_TDM_RX_7, 6528c2ecf20Sopenharmony_ci PRIMARY_TDM_RX_7, 1, 1}, 6538c2ecf20Sopenharmony_ci [PRIMARY_TDM_TX_7] = { AFE_PORT_ID_PRIMARY_TDM_TX_7, 6548c2ecf20Sopenharmony_ci PRIMARY_TDM_TX_7, 0, 1}, 6558c2ecf20Sopenharmony_ci [SECONDARY_TDM_RX_0] = { AFE_PORT_ID_SECONDARY_TDM_RX, 6568c2ecf20Sopenharmony_ci SECONDARY_TDM_RX_0, 1, 1}, 6578c2ecf20Sopenharmony_ci [SECONDARY_TDM_TX_0] = { AFE_PORT_ID_SECONDARY_TDM_TX, 6588c2ecf20Sopenharmony_ci SECONDARY_TDM_TX_0, 0, 1}, 6598c2ecf20Sopenharmony_ci [SECONDARY_TDM_RX_1] = { AFE_PORT_ID_SECONDARY_TDM_RX_1, 6608c2ecf20Sopenharmony_ci SECONDARY_TDM_RX_1, 1, 1}, 6618c2ecf20Sopenharmony_ci [SECONDARY_TDM_TX_1] = { AFE_PORT_ID_SECONDARY_TDM_TX_1, 6628c2ecf20Sopenharmony_ci SECONDARY_TDM_TX_1, 0, 1}, 6638c2ecf20Sopenharmony_ci [SECONDARY_TDM_RX_2] = { AFE_PORT_ID_SECONDARY_TDM_RX_2, 6648c2ecf20Sopenharmony_ci SECONDARY_TDM_RX_2, 1, 1}, 6658c2ecf20Sopenharmony_ci [SECONDARY_TDM_TX_2] = { AFE_PORT_ID_SECONDARY_TDM_TX_2, 6668c2ecf20Sopenharmony_ci SECONDARY_TDM_TX_2, 0, 1}, 6678c2ecf20Sopenharmony_ci [SECONDARY_TDM_RX_3] = { AFE_PORT_ID_SECONDARY_TDM_RX_3, 6688c2ecf20Sopenharmony_ci SECONDARY_TDM_RX_3, 1, 1}, 6698c2ecf20Sopenharmony_ci [SECONDARY_TDM_TX_3] = { AFE_PORT_ID_SECONDARY_TDM_TX_3, 6708c2ecf20Sopenharmony_ci SECONDARY_TDM_TX_3, 0, 1}, 6718c2ecf20Sopenharmony_ci [SECONDARY_TDM_RX_4] = { AFE_PORT_ID_SECONDARY_TDM_RX_4, 6728c2ecf20Sopenharmony_ci SECONDARY_TDM_RX_4, 1, 1}, 6738c2ecf20Sopenharmony_ci [SECONDARY_TDM_TX_4] = { AFE_PORT_ID_SECONDARY_TDM_TX_4, 6748c2ecf20Sopenharmony_ci SECONDARY_TDM_TX_4, 0, 1}, 6758c2ecf20Sopenharmony_ci [SECONDARY_TDM_RX_5] = { AFE_PORT_ID_SECONDARY_TDM_RX_5, 6768c2ecf20Sopenharmony_ci SECONDARY_TDM_RX_5, 1, 1}, 6778c2ecf20Sopenharmony_ci [SECONDARY_TDM_TX_5] = { AFE_PORT_ID_SECONDARY_TDM_TX_5, 6788c2ecf20Sopenharmony_ci SECONDARY_TDM_TX_5, 0, 1}, 6798c2ecf20Sopenharmony_ci [SECONDARY_TDM_RX_6] = { AFE_PORT_ID_SECONDARY_TDM_RX_6, 6808c2ecf20Sopenharmony_ci SECONDARY_TDM_RX_6, 1, 1}, 6818c2ecf20Sopenharmony_ci [SECONDARY_TDM_TX_6] = { AFE_PORT_ID_SECONDARY_TDM_TX_6, 6828c2ecf20Sopenharmony_ci SECONDARY_TDM_TX_6, 0, 1}, 6838c2ecf20Sopenharmony_ci [SECONDARY_TDM_RX_7] = { AFE_PORT_ID_SECONDARY_TDM_RX_7, 6848c2ecf20Sopenharmony_ci SECONDARY_TDM_RX_7, 1, 1}, 6858c2ecf20Sopenharmony_ci [SECONDARY_TDM_TX_7] = { AFE_PORT_ID_SECONDARY_TDM_TX_7, 6868c2ecf20Sopenharmony_ci SECONDARY_TDM_TX_7, 0, 1}, 6878c2ecf20Sopenharmony_ci [TERTIARY_TDM_RX_0] = { AFE_PORT_ID_TERTIARY_TDM_RX, 6888c2ecf20Sopenharmony_ci TERTIARY_TDM_RX_0, 1, 1}, 6898c2ecf20Sopenharmony_ci [TERTIARY_TDM_TX_0] = { AFE_PORT_ID_TERTIARY_TDM_TX, 6908c2ecf20Sopenharmony_ci TERTIARY_TDM_TX_0, 0, 1}, 6918c2ecf20Sopenharmony_ci [TERTIARY_TDM_RX_1] = { AFE_PORT_ID_TERTIARY_TDM_RX_1, 6928c2ecf20Sopenharmony_ci TERTIARY_TDM_RX_1, 1, 1}, 6938c2ecf20Sopenharmony_ci [TERTIARY_TDM_TX_1] = { AFE_PORT_ID_TERTIARY_TDM_TX_1, 6948c2ecf20Sopenharmony_ci TERTIARY_TDM_TX_1, 0, 1}, 6958c2ecf20Sopenharmony_ci [TERTIARY_TDM_RX_2] = { AFE_PORT_ID_TERTIARY_TDM_RX_2, 6968c2ecf20Sopenharmony_ci TERTIARY_TDM_RX_2, 1, 1}, 6978c2ecf20Sopenharmony_ci [TERTIARY_TDM_TX_2] = { AFE_PORT_ID_TERTIARY_TDM_TX_2, 6988c2ecf20Sopenharmony_ci TERTIARY_TDM_TX_2, 0, 1}, 6998c2ecf20Sopenharmony_ci [TERTIARY_TDM_RX_3] = { AFE_PORT_ID_TERTIARY_TDM_RX_3, 7008c2ecf20Sopenharmony_ci TERTIARY_TDM_RX_3, 1, 1}, 7018c2ecf20Sopenharmony_ci [TERTIARY_TDM_TX_3] = { AFE_PORT_ID_TERTIARY_TDM_TX_3, 7028c2ecf20Sopenharmony_ci TERTIARY_TDM_TX_3, 0, 1}, 7038c2ecf20Sopenharmony_ci [TERTIARY_TDM_RX_4] = { AFE_PORT_ID_TERTIARY_TDM_RX_4, 7048c2ecf20Sopenharmony_ci TERTIARY_TDM_RX_4, 1, 1}, 7058c2ecf20Sopenharmony_ci [TERTIARY_TDM_TX_4] = { AFE_PORT_ID_TERTIARY_TDM_TX_4, 7068c2ecf20Sopenharmony_ci TERTIARY_TDM_TX_4, 0, 1}, 7078c2ecf20Sopenharmony_ci [TERTIARY_TDM_RX_5] = { AFE_PORT_ID_TERTIARY_TDM_RX_5, 7088c2ecf20Sopenharmony_ci TERTIARY_TDM_RX_5, 1, 1}, 7098c2ecf20Sopenharmony_ci [TERTIARY_TDM_TX_5] = { AFE_PORT_ID_TERTIARY_TDM_TX_5, 7108c2ecf20Sopenharmony_ci TERTIARY_TDM_TX_5, 0, 1}, 7118c2ecf20Sopenharmony_ci [TERTIARY_TDM_RX_6] = { AFE_PORT_ID_TERTIARY_TDM_RX_6, 7128c2ecf20Sopenharmony_ci TERTIARY_TDM_RX_6, 1, 1}, 7138c2ecf20Sopenharmony_ci [TERTIARY_TDM_TX_6] = { AFE_PORT_ID_TERTIARY_TDM_TX_6, 7148c2ecf20Sopenharmony_ci TERTIARY_TDM_TX_6, 0, 1}, 7158c2ecf20Sopenharmony_ci [TERTIARY_TDM_RX_7] = { AFE_PORT_ID_TERTIARY_TDM_RX_7, 7168c2ecf20Sopenharmony_ci TERTIARY_TDM_RX_7, 1, 1}, 7178c2ecf20Sopenharmony_ci [TERTIARY_TDM_TX_7] = { AFE_PORT_ID_TERTIARY_TDM_TX_7, 7188c2ecf20Sopenharmony_ci TERTIARY_TDM_TX_7, 0, 1}, 7198c2ecf20Sopenharmony_ci [QUATERNARY_TDM_RX_0] = { AFE_PORT_ID_QUATERNARY_TDM_RX, 7208c2ecf20Sopenharmony_ci QUATERNARY_TDM_RX_0, 1, 1}, 7218c2ecf20Sopenharmony_ci [QUATERNARY_TDM_TX_0] = { AFE_PORT_ID_QUATERNARY_TDM_TX, 7228c2ecf20Sopenharmony_ci QUATERNARY_TDM_TX_0, 0, 1}, 7238c2ecf20Sopenharmony_ci [QUATERNARY_TDM_RX_1] = { AFE_PORT_ID_QUATERNARY_TDM_RX_1, 7248c2ecf20Sopenharmony_ci QUATERNARY_TDM_RX_1, 1, 1}, 7258c2ecf20Sopenharmony_ci [QUATERNARY_TDM_TX_1] = { AFE_PORT_ID_QUATERNARY_TDM_TX_1, 7268c2ecf20Sopenharmony_ci QUATERNARY_TDM_TX_1, 0, 1}, 7278c2ecf20Sopenharmony_ci [QUATERNARY_TDM_RX_2] = { AFE_PORT_ID_QUATERNARY_TDM_RX_2, 7288c2ecf20Sopenharmony_ci QUATERNARY_TDM_RX_2, 1, 1}, 7298c2ecf20Sopenharmony_ci [QUATERNARY_TDM_TX_2] = { AFE_PORT_ID_QUATERNARY_TDM_TX_2, 7308c2ecf20Sopenharmony_ci QUATERNARY_TDM_TX_2, 0, 1}, 7318c2ecf20Sopenharmony_ci [QUATERNARY_TDM_RX_3] = { AFE_PORT_ID_QUATERNARY_TDM_RX_3, 7328c2ecf20Sopenharmony_ci QUATERNARY_TDM_RX_3, 1, 1}, 7338c2ecf20Sopenharmony_ci [QUATERNARY_TDM_TX_3] = { AFE_PORT_ID_QUATERNARY_TDM_TX_3, 7348c2ecf20Sopenharmony_ci QUATERNARY_TDM_TX_3, 0, 1}, 7358c2ecf20Sopenharmony_ci [QUATERNARY_TDM_RX_4] = { AFE_PORT_ID_QUATERNARY_TDM_RX_4, 7368c2ecf20Sopenharmony_ci QUATERNARY_TDM_RX_4, 1, 1}, 7378c2ecf20Sopenharmony_ci [QUATERNARY_TDM_TX_4] = { AFE_PORT_ID_QUATERNARY_TDM_TX_4, 7388c2ecf20Sopenharmony_ci QUATERNARY_TDM_TX_4, 0, 1}, 7398c2ecf20Sopenharmony_ci [QUATERNARY_TDM_RX_5] = { AFE_PORT_ID_QUATERNARY_TDM_RX_5, 7408c2ecf20Sopenharmony_ci QUATERNARY_TDM_RX_5, 1, 1}, 7418c2ecf20Sopenharmony_ci [QUATERNARY_TDM_TX_5] = { AFE_PORT_ID_QUATERNARY_TDM_TX_5, 7428c2ecf20Sopenharmony_ci QUATERNARY_TDM_TX_5, 0, 1}, 7438c2ecf20Sopenharmony_ci [QUATERNARY_TDM_RX_6] = { AFE_PORT_ID_QUATERNARY_TDM_RX_6, 7448c2ecf20Sopenharmony_ci QUATERNARY_TDM_RX_6, 1, 1}, 7458c2ecf20Sopenharmony_ci [QUATERNARY_TDM_TX_6] = { AFE_PORT_ID_QUATERNARY_TDM_TX_6, 7468c2ecf20Sopenharmony_ci QUATERNARY_TDM_TX_6, 0, 1}, 7478c2ecf20Sopenharmony_ci [QUATERNARY_TDM_RX_7] = { AFE_PORT_ID_QUATERNARY_TDM_RX_7, 7488c2ecf20Sopenharmony_ci QUATERNARY_TDM_RX_7, 1, 1}, 7498c2ecf20Sopenharmony_ci [QUATERNARY_TDM_TX_7] = { AFE_PORT_ID_QUATERNARY_TDM_TX_7, 7508c2ecf20Sopenharmony_ci QUATERNARY_TDM_TX_7, 0, 1}, 7518c2ecf20Sopenharmony_ci [QUINARY_TDM_RX_0] = { AFE_PORT_ID_QUINARY_TDM_RX, 7528c2ecf20Sopenharmony_ci QUINARY_TDM_RX_0, 1, 1}, 7538c2ecf20Sopenharmony_ci [QUINARY_TDM_TX_0] = { AFE_PORT_ID_QUINARY_TDM_TX, 7548c2ecf20Sopenharmony_ci QUINARY_TDM_TX_0, 0, 1}, 7558c2ecf20Sopenharmony_ci [QUINARY_TDM_RX_1] = { AFE_PORT_ID_QUINARY_TDM_RX_1, 7568c2ecf20Sopenharmony_ci QUINARY_TDM_RX_1, 1, 1}, 7578c2ecf20Sopenharmony_ci [QUINARY_TDM_TX_1] = { AFE_PORT_ID_QUINARY_TDM_TX_1, 7588c2ecf20Sopenharmony_ci QUINARY_TDM_TX_1, 0, 1}, 7598c2ecf20Sopenharmony_ci [QUINARY_TDM_RX_2] = { AFE_PORT_ID_QUINARY_TDM_RX_2, 7608c2ecf20Sopenharmony_ci QUINARY_TDM_RX_2, 1, 1}, 7618c2ecf20Sopenharmony_ci [QUINARY_TDM_TX_2] = { AFE_PORT_ID_QUINARY_TDM_TX_2, 7628c2ecf20Sopenharmony_ci QUINARY_TDM_TX_2, 0, 1}, 7638c2ecf20Sopenharmony_ci [QUINARY_TDM_RX_3] = { AFE_PORT_ID_QUINARY_TDM_RX_3, 7648c2ecf20Sopenharmony_ci QUINARY_TDM_RX_3, 1, 1}, 7658c2ecf20Sopenharmony_ci [QUINARY_TDM_TX_3] = { AFE_PORT_ID_QUINARY_TDM_TX_3, 7668c2ecf20Sopenharmony_ci QUINARY_TDM_TX_3, 0, 1}, 7678c2ecf20Sopenharmony_ci [QUINARY_TDM_RX_4] = { AFE_PORT_ID_QUINARY_TDM_RX_4, 7688c2ecf20Sopenharmony_ci QUINARY_TDM_RX_4, 1, 1}, 7698c2ecf20Sopenharmony_ci [QUINARY_TDM_TX_4] = { AFE_PORT_ID_QUINARY_TDM_TX_4, 7708c2ecf20Sopenharmony_ci QUINARY_TDM_TX_4, 0, 1}, 7718c2ecf20Sopenharmony_ci [QUINARY_TDM_RX_5] = { AFE_PORT_ID_QUINARY_TDM_RX_5, 7728c2ecf20Sopenharmony_ci QUINARY_TDM_RX_5, 1, 1}, 7738c2ecf20Sopenharmony_ci [QUINARY_TDM_TX_5] = { AFE_PORT_ID_QUINARY_TDM_TX_5, 7748c2ecf20Sopenharmony_ci QUINARY_TDM_TX_5, 0, 1}, 7758c2ecf20Sopenharmony_ci [QUINARY_TDM_RX_6] = { AFE_PORT_ID_QUINARY_TDM_RX_6, 7768c2ecf20Sopenharmony_ci QUINARY_TDM_RX_6, 1, 1}, 7778c2ecf20Sopenharmony_ci [QUINARY_TDM_TX_6] = { AFE_PORT_ID_QUINARY_TDM_TX_6, 7788c2ecf20Sopenharmony_ci QUINARY_TDM_TX_6, 0, 1}, 7798c2ecf20Sopenharmony_ci [QUINARY_TDM_RX_7] = { AFE_PORT_ID_QUINARY_TDM_RX_7, 7808c2ecf20Sopenharmony_ci QUINARY_TDM_RX_7, 1, 1}, 7818c2ecf20Sopenharmony_ci [QUINARY_TDM_TX_7] = { AFE_PORT_ID_QUINARY_TDM_TX_7, 7828c2ecf20Sopenharmony_ci QUINARY_TDM_TX_7, 0, 1}, 7838c2ecf20Sopenharmony_ci [DISPLAY_PORT_RX] = { AFE_PORT_ID_HDMI_OVER_DP_RX, 7848c2ecf20Sopenharmony_ci DISPLAY_PORT_RX, 1, 1}, 7858c2ecf20Sopenharmony_ci [WSA_CODEC_DMA_RX_0] = { AFE_PORT_ID_WSA_CODEC_DMA_RX_0, 7868c2ecf20Sopenharmony_ci WSA_CODEC_DMA_RX_0, 1, 1}, 7878c2ecf20Sopenharmony_ci [WSA_CODEC_DMA_TX_0] = { AFE_PORT_ID_WSA_CODEC_DMA_TX_0, 7888c2ecf20Sopenharmony_ci WSA_CODEC_DMA_TX_0, 0, 1}, 7898c2ecf20Sopenharmony_ci [WSA_CODEC_DMA_RX_1] = { AFE_PORT_ID_WSA_CODEC_DMA_RX_1, 7908c2ecf20Sopenharmony_ci WSA_CODEC_DMA_RX_1, 1, 1}, 7918c2ecf20Sopenharmony_ci [WSA_CODEC_DMA_TX_1] = { AFE_PORT_ID_WSA_CODEC_DMA_TX_1, 7928c2ecf20Sopenharmony_ci WSA_CODEC_DMA_TX_1, 0, 1}, 7938c2ecf20Sopenharmony_ci [WSA_CODEC_DMA_TX_2] = { AFE_PORT_ID_WSA_CODEC_DMA_TX_2, 7948c2ecf20Sopenharmony_ci WSA_CODEC_DMA_TX_2, 0, 1}, 7958c2ecf20Sopenharmony_ci [VA_CODEC_DMA_TX_0] = { AFE_PORT_ID_VA_CODEC_DMA_TX_0, 7968c2ecf20Sopenharmony_ci VA_CODEC_DMA_TX_0, 0, 1}, 7978c2ecf20Sopenharmony_ci [VA_CODEC_DMA_TX_1] = { AFE_PORT_ID_VA_CODEC_DMA_TX_1, 7988c2ecf20Sopenharmony_ci VA_CODEC_DMA_TX_1, 0, 1}, 7998c2ecf20Sopenharmony_ci [VA_CODEC_DMA_TX_2] = { AFE_PORT_ID_VA_CODEC_DMA_TX_2, 8008c2ecf20Sopenharmony_ci VA_CODEC_DMA_TX_2, 0, 1}, 8018c2ecf20Sopenharmony_ci [RX_CODEC_DMA_RX_0] = { AFE_PORT_ID_RX_CODEC_DMA_RX_0, 8028c2ecf20Sopenharmony_ci RX_CODEC_DMA_RX_0, 1, 1}, 8038c2ecf20Sopenharmony_ci [TX_CODEC_DMA_TX_0] = { AFE_PORT_ID_TX_CODEC_DMA_TX_0, 8048c2ecf20Sopenharmony_ci TX_CODEC_DMA_TX_0, 0, 1}, 8058c2ecf20Sopenharmony_ci [RX_CODEC_DMA_RX_1] = { AFE_PORT_ID_RX_CODEC_DMA_RX_1, 8068c2ecf20Sopenharmony_ci RX_CODEC_DMA_RX_1, 1, 1}, 8078c2ecf20Sopenharmony_ci [TX_CODEC_DMA_TX_1] = { AFE_PORT_ID_TX_CODEC_DMA_TX_1, 8088c2ecf20Sopenharmony_ci TX_CODEC_DMA_TX_1, 0, 1}, 8098c2ecf20Sopenharmony_ci [RX_CODEC_DMA_RX_2] = { AFE_PORT_ID_RX_CODEC_DMA_RX_2, 8108c2ecf20Sopenharmony_ci RX_CODEC_DMA_RX_2, 1, 1}, 8118c2ecf20Sopenharmony_ci [TX_CODEC_DMA_TX_2] = { AFE_PORT_ID_TX_CODEC_DMA_TX_2, 8128c2ecf20Sopenharmony_ci TX_CODEC_DMA_TX_2, 0, 1}, 8138c2ecf20Sopenharmony_ci [RX_CODEC_DMA_RX_3] = { AFE_PORT_ID_RX_CODEC_DMA_RX_3, 8148c2ecf20Sopenharmony_ci RX_CODEC_DMA_RX_3, 1, 1}, 8158c2ecf20Sopenharmony_ci [TX_CODEC_DMA_TX_3] = { AFE_PORT_ID_TX_CODEC_DMA_TX_3, 8168c2ecf20Sopenharmony_ci TX_CODEC_DMA_TX_3, 0, 1}, 8178c2ecf20Sopenharmony_ci [RX_CODEC_DMA_RX_4] = { AFE_PORT_ID_RX_CODEC_DMA_RX_4, 8188c2ecf20Sopenharmony_ci RX_CODEC_DMA_RX_4, 1, 1}, 8198c2ecf20Sopenharmony_ci [TX_CODEC_DMA_TX_4] = { AFE_PORT_ID_TX_CODEC_DMA_TX_4, 8208c2ecf20Sopenharmony_ci TX_CODEC_DMA_TX_4, 0, 1}, 8218c2ecf20Sopenharmony_ci [RX_CODEC_DMA_RX_5] = { AFE_PORT_ID_RX_CODEC_DMA_RX_5, 8228c2ecf20Sopenharmony_ci RX_CODEC_DMA_RX_5, 1, 1}, 8238c2ecf20Sopenharmony_ci [TX_CODEC_DMA_TX_5] = { AFE_PORT_ID_TX_CODEC_DMA_TX_5, 8248c2ecf20Sopenharmony_ci TX_CODEC_DMA_TX_5, 0, 1}, 8258c2ecf20Sopenharmony_ci [RX_CODEC_DMA_RX_6] = { AFE_PORT_ID_RX_CODEC_DMA_RX_6, 8268c2ecf20Sopenharmony_ci RX_CODEC_DMA_RX_6, 1, 1}, 8278c2ecf20Sopenharmony_ci [RX_CODEC_DMA_RX_7] = { AFE_PORT_ID_RX_CODEC_DMA_RX_7, 8288c2ecf20Sopenharmony_ci RX_CODEC_DMA_RX_7, 1, 1}, 8298c2ecf20Sopenharmony_ci}; 8308c2ecf20Sopenharmony_ci 8318c2ecf20Sopenharmony_cistatic void q6afe_port_free(struct kref *ref) 8328c2ecf20Sopenharmony_ci{ 8338c2ecf20Sopenharmony_ci struct q6afe_port *port; 8348c2ecf20Sopenharmony_ci struct q6afe *afe; 8358c2ecf20Sopenharmony_ci unsigned long flags; 8368c2ecf20Sopenharmony_ci 8378c2ecf20Sopenharmony_ci port = container_of(ref, struct q6afe_port, refcount); 8388c2ecf20Sopenharmony_ci afe = port->afe; 8398c2ecf20Sopenharmony_ci spin_lock_irqsave(&afe->port_list_lock, flags); 8408c2ecf20Sopenharmony_ci list_del(&port->node); 8418c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&afe->port_list_lock, flags); 8428c2ecf20Sopenharmony_ci kfree(port->scfg); 8438c2ecf20Sopenharmony_ci kfree(port); 8448c2ecf20Sopenharmony_ci} 8458c2ecf20Sopenharmony_ci 8468c2ecf20Sopenharmony_cistatic struct q6afe_port *q6afe_find_port(struct q6afe *afe, int token) 8478c2ecf20Sopenharmony_ci{ 8488c2ecf20Sopenharmony_ci struct q6afe_port *p = NULL; 8498c2ecf20Sopenharmony_ci struct q6afe_port *ret = NULL; 8508c2ecf20Sopenharmony_ci unsigned long flags; 8518c2ecf20Sopenharmony_ci 8528c2ecf20Sopenharmony_ci spin_lock_irqsave(&afe->port_list_lock, flags); 8538c2ecf20Sopenharmony_ci list_for_each_entry(p, &afe->port_list, node) 8548c2ecf20Sopenharmony_ci if (p->token == token) { 8558c2ecf20Sopenharmony_ci ret = p; 8568c2ecf20Sopenharmony_ci kref_get(&p->refcount); 8578c2ecf20Sopenharmony_ci break; 8588c2ecf20Sopenharmony_ci } 8598c2ecf20Sopenharmony_ci 8608c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&afe->port_list_lock, flags); 8618c2ecf20Sopenharmony_ci return ret; 8628c2ecf20Sopenharmony_ci} 8638c2ecf20Sopenharmony_ci 8648c2ecf20Sopenharmony_cistatic int q6afe_callback(struct apr_device *adev, struct apr_resp_pkt *data) 8658c2ecf20Sopenharmony_ci{ 8668c2ecf20Sopenharmony_ci struct q6afe *afe = dev_get_drvdata(&adev->dev); 8678c2ecf20Sopenharmony_ci struct aprv2_ibasic_rsp_result_t *res; 8688c2ecf20Sopenharmony_ci struct apr_hdr *hdr = &data->hdr; 8698c2ecf20Sopenharmony_ci struct q6afe_port *port; 8708c2ecf20Sopenharmony_ci 8718c2ecf20Sopenharmony_ci if (!data->payload_size) 8728c2ecf20Sopenharmony_ci return 0; 8738c2ecf20Sopenharmony_ci 8748c2ecf20Sopenharmony_ci res = data->payload; 8758c2ecf20Sopenharmony_ci switch (hdr->opcode) { 8768c2ecf20Sopenharmony_ci case APR_BASIC_RSP_RESULT: { 8778c2ecf20Sopenharmony_ci if (res->status) { 8788c2ecf20Sopenharmony_ci dev_err(afe->dev, "cmd = 0x%x returned error = 0x%x\n", 8798c2ecf20Sopenharmony_ci res->opcode, res->status); 8808c2ecf20Sopenharmony_ci } 8818c2ecf20Sopenharmony_ci switch (res->opcode) { 8828c2ecf20Sopenharmony_ci case AFE_PORT_CMD_SET_PARAM_V2: 8838c2ecf20Sopenharmony_ci case AFE_PORT_CMD_DEVICE_STOP: 8848c2ecf20Sopenharmony_ci case AFE_PORT_CMD_DEVICE_START: 8858c2ecf20Sopenharmony_ci case AFE_SVC_CMD_SET_PARAM: 8868c2ecf20Sopenharmony_ci port = q6afe_find_port(afe, hdr->token); 8878c2ecf20Sopenharmony_ci if (port) { 8888c2ecf20Sopenharmony_ci port->result = *res; 8898c2ecf20Sopenharmony_ci wake_up(&port->wait); 8908c2ecf20Sopenharmony_ci kref_put(&port->refcount, q6afe_port_free); 8918c2ecf20Sopenharmony_ci } else if (hdr->token == AFE_CLK_TOKEN) { 8928c2ecf20Sopenharmony_ci afe->result = *res; 8938c2ecf20Sopenharmony_ci wake_up(&afe->wait); 8948c2ecf20Sopenharmony_ci } 8958c2ecf20Sopenharmony_ci break; 8968c2ecf20Sopenharmony_ci default: 8978c2ecf20Sopenharmony_ci dev_err(afe->dev, "Unknown cmd 0x%x\n", res->opcode); 8988c2ecf20Sopenharmony_ci break; 8998c2ecf20Sopenharmony_ci } 9008c2ecf20Sopenharmony_ci } 9018c2ecf20Sopenharmony_ci break; 9028c2ecf20Sopenharmony_ci case AFE_CMD_RSP_REMOTE_LPASS_CORE_HW_VOTE_REQUEST: 9038c2ecf20Sopenharmony_ci afe->result.opcode = hdr->opcode; 9048c2ecf20Sopenharmony_ci afe->result.status = res->status; 9058c2ecf20Sopenharmony_ci wake_up(&afe->wait); 9068c2ecf20Sopenharmony_ci break; 9078c2ecf20Sopenharmony_ci default: 9088c2ecf20Sopenharmony_ci break; 9098c2ecf20Sopenharmony_ci } 9108c2ecf20Sopenharmony_ci 9118c2ecf20Sopenharmony_ci return 0; 9128c2ecf20Sopenharmony_ci} 9138c2ecf20Sopenharmony_ci 9148c2ecf20Sopenharmony_ci/** 9158c2ecf20Sopenharmony_ci * q6afe_get_port_id() - Get port id from a given port index 9168c2ecf20Sopenharmony_ci * 9178c2ecf20Sopenharmony_ci * @index: port index 9188c2ecf20Sopenharmony_ci * 9198c2ecf20Sopenharmony_ci * Return: Will be an negative on error or valid port_id on success 9208c2ecf20Sopenharmony_ci */ 9218c2ecf20Sopenharmony_ciint q6afe_get_port_id(int index) 9228c2ecf20Sopenharmony_ci{ 9238c2ecf20Sopenharmony_ci if (index < 0 || index >= AFE_PORT_MAX) 9248c2ecf20Sopenharmony_ci return -EINVAL; 9258c2ecf20Sopenharmony_ci 9268c2ecf20Sopenharmony_ci return port_maps[index].port_id; 9278c2ecf20Sopenharmony_ci} 9288c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(q6afe_get_port_id); 9298c2ecf20Sopenharmony_ci 9308c2ecf20Sopenharmony_cistatic int afe_apr_send_pkt(struct q6afe *afe, struct apr_pkt *pkt, 9318c2ecf20Sopenharmony_ci struct q6afe_port *port, uint32_t rsp_opcode) 9328c2ecf20Sopenharmony_ci{ 9338c2ecf20Sopenharmony_ci wait_queue_head_t *wait = &port->wait; 9348c2ecf20Sopenharmony_ci struct aprv2_ibasic_rsp_result_t *result; 9358c2ecf20Sopenharmony_ci int ret; 9368c2ecf20Sopenharmony_ci 9378c2ecf20Sopenharmony_ci mutex_lock(&afe->lock); 9388c2ecf20Sopenharmony_ci if (port) { 9398c2ecf20Sopenharmony_ci wait = &port->wait; 9408c2ecf20Sopenharmony_ci result = &port->result; 9418c2ecf20Sopenharmony_ci } else { 9428c2ecf20Sopenharmony_ci result = &afe->result; 9438c2ecf20Sopenharmony_ci wait = &afe->wait; 9448c2ecf20Sopenharmony_ci } 9458c2ecf20Sopenharmony_ci 9468c2ecf20Sopenharmony_ci result->opcode = 0; 9478c2ecf20Sopenharmony_ci result->status = 0; 9488c2ecf20Sopenharmony_ci 9498c2ecf20Sopenharmony_ci ret = apr_send_pkt(afe->apr, pkt); 9508c2ecf20Sopenharmony_ci if (ret < 0) { 9518c2ecf20Sopenharmony_ci dev_err(afe->dev, "packet not transmitted (%d)\n", ret); 9528c2ecf20Sopenharmony_ci ret = -EINVAL; 9538c2ecf20Sopenharmony_ci goto err; 9548c2ecf20Sopenharmony_ci } 9558c2ecf20Sopenharmony_ci 9568c2ecf20Sopenharmony_ci ret = wait_event_timeout(*wait, (result->opcode == rsp_opcode), 9578c2ecf20Sopenharmony_ci msecs_to_jiffies(TIMEOUT_MS)); 9588c2ecf20Sopenharmony_ci if (!ret) { 9598c2ecf20Sopenharmony_ci ret = -ETIMEDOUT; 9608c2ecf20Sopenharmony_ci } else if (result->status > 0) { 9618c2ecf20Sopenharmony_ci dev_err(afe->dev, "DSP returned error[%x]\n", 9628c2ecf20Sopenharmony_ci result->status); 9638c2ecf20Sopenharmony_ci ret = -EINVAL; 9648c2ecf20Sopenharmony_ci } else { 9658c2ecf20Sopenharmony_ci ret = 0; 9668c2ecf20Sopenharmony_ci } 9678c2ecf20Sopenharmony_ci 9688c2ecf20Sopenharmony_cierr: 9698c2ecf20Sopenharmony_ci mutex_unlock(&afe->lock); 9708c2ecf20Sopenharmony_ci 9718c2ecf20Sopenharmony_ci return ret; 9728c2ecf20Sopenharmony_ci} 9738c2ecf20Sopenharmony_ci 9748c2ecf20Sopenharmony_cistatic int q6afe_set_param(struct q6afe *afe, struct q6afe_port *port, 9758c2ecf20Sopenharmony_ci void *data, int param_id, int module_id, int psize, 9768c2ecf20Sopenharmony_ci int token) 9778c2ecf20Sopenharmony_ci{ 9788c2ecf20Sopenharmony_ci struct afe_svc_cmd_set_param *param; 9798c2ecf20Sopenharmony_ci struct afe_port_param_data_v2 *pdata; 9808c2ecf20Sopenharmony_ci struct apr_pkt *pkt; 9818c2ecf20Sopenharmony_ci int ret, pkt_size; 9828c2ecf20Sopenharmony_ci void *p, *pl; 9838c2ecf20Sopenharmony_ci 9848c2ecf20Sopenharmony_ci pkt_size = APR_HDR_SIZE + sizeof(*param) + sizeof(*pdata) + psize; 9858c2ecf20Sopenharmony_ci p = kzalloc(pkt_size, GFP_KERNEL); 9868c2ecf20Sopenharmony_ci if (!p) 9878c2ecf20Sopenharmony_ci return -ENOMEM; 9888c2ecf20Sopenharmony_ci 9898c2ecf20Sopenharmony_ci pkt = p; 9908c2ecf20Sopenharmony_ci param = p + APR_HDR_SIZE; 9918c2ecf20Sopenharmony_ci pdata = p + APR_HDR_SIZE + sizeof(*param); 9928c2ecf20Sopenharmony_ci pl = p + APR_HDR_SIZE + sizeof(*param) + sizeof(*pdata); 9938c2ecf20Sopenharmony_ci memcpy(pl, data, psize); 9948c2ecf20Sopenharmony_ci 9958c2ecf20Sopenharmony_ci pkt->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, 9968c2ecf20Sopenharmony_ci APR_HDR_LEN(APR_HDR_SIZE), 9978c2ecf20Sopenharmony_ci APR_PKT_VER); 9988c2ecf20Sopenharmony_ci pkt->hdr.pkt_size = pkt_size; 9998c2ecf20Sopenharmony_ci pkt->hdr.src_port = 0; 10008c2ecf20Sopenharmony_ci pkt->hdr.dest_port = 0; 10018c2ecf20Sopenharmony_ci pkt->hdr.token = token; 10028c2ecf20Sopenharmony_ci pkt->hdr.opcode = AFE_SVC_CMD_SET_PARAM; 10038c2ecf20Sopenharmony_ci 10048c2ecf20Sopenharmony_ci param->payload_size = sizeof(*pdata) + psize; 10058c2ecf20Sopenharmony_ci param->payload_address_lsw = 0x00; 10068c2ecf20Sopenharmony_ci param->payload_address_msw = 0x00; 10078c2ecf20Sopenharmony_ci param->mem_map_handle = 0x00; 10088c2ecf20Sopenharmony_ci pdata->module_id = module_id; 10098c2ecf20Sopenharmony_ci pdata->param_id = param_id; 10108c2ecf20Sopenharmony_ci pdata->param_size = psize; 10118c2ecf20Sopenharmony_ci 10128c2ecf20Sopenharmony_ci ret = afe_apr_send_pkt(afe, pkt, port, AFE_SVC_CMD_SET_PARAM); 10138c2ecf20Sopenharmony_ci if (ret) 10148c2ecf20Sopenharmony_ci dev_err(afe->dev, "AFE set params failed %d\n", ret); 10158c2ecf20Sopenharmony_ci 10168c2ecf20Sopenharmony_ci kfree(pkt); 10178c2ecf20Sopenharmony_ci return ret; 10188c2ecf20Sopenharmony_ci} 10198c2ecf20Sopenharmony_ci 10208c2ecf20Sopenharmony_cistatic int q6afe_port_set_param(struct q6afe_port *port, void *data, 10218c2ecf20Sopenharmony_ci int param_id, int module_id, int psize) 10228c2ecf20Sopenharmony_ci{ 10238c2ecf20Sopenharmony_ci return q6afe_set_param(port->afe, port, data, param_id, module_id, 10248c2ecf20Sopenharmony_ci psize, port->token); 10258c2ecf20Sopenharmony_ci} 10268c2ecf20Sopenharmony_ci 10278c2ecf20Sopenharmony_cistatic int q6afe_port_set_param_v2(struct q6afe_port *port, void *data, 10288c2ecf20Sopenharmony_ci int param_id, int module_id, int psize) 10298c2ecf20Sopenharmony_ci{ 10308c2ecf20Sopenharmony_ci struct afe_port_cmd_set_param_v2 *param; 10318c2ecf20Sopenharmony_ci struct afe_port_param_data_v2 *pdata; 10328c2ecf20Sopenharmony_ci struct q6afe *afe = port->afe; 10338c2ecf20Sopenharmony_ci struct apr_pkt *pkt; 10348c2ecf20Sopenharmony_ci u16 port_id = port->id; 10358c2ecf20Sopenharmony_ci int ret, pkt_size; 10368c2ecf20Sopenharmony_ci void *p, *pl; 10378c2ecf20Sopenharmony_ci 10388c2ecf20Sopenharmony_ci pkt_size = APR_HDR_SIZE + sizeof(*param) + sizeof(*pdata) + psize; 10398c2ecf20Sopenharmony_ci p = kzalloc(pkt_size, GFP_KERNEL); 10408c2ecf20Sopenharmony_ci if (!p) 10418c2ecf20Sopenharmony_ci return -ENOMEM; 10428c2ecf20Sopenharmony_ci 10438c2ecf20Sopenharmony_ci pkt = p; 10448c2ecf20Sopenharmony_ci param = p + APR_HDR_SIZE; 10458c2ecf20Sopenharmony_ci pdata = p + APR_HDR_SIZE + sizeof(*param); 10468c2ecf20Sopenharmony_ci pl = p + APR_HDR_SIZE + sizeof(*param) + sizeof(*pdata); 10478c2ecf20Sopenharmony_ci memcpy(pl, data, psize); 10488c2ecf20Sopenharmony_ci 10498c2ecf20Sopenharmony_ci pkt->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, 10508c2ecf20Sopenharmony_ci APR_HDR_LEN(APR_HDR_SIZE), 10518c2ecf20Sopenharmony_ci APR_PKT_VER); 10528c2ecf20Sopenharmony_ci pkt->hdr.pkt_size = pkt_size; 10538c2ecf20Sopenharmony_ci pkt->hdr.src_port = 0; 10548c2ecf20Sopenharmony_ci pkt->hdr.dest_port = 0; 10558c2ecf20Sopenharmony_ci pkt->hdr.token = port->token; 10568c2ecf20Sopenharmony_ci pkt->hdr.opcode = AFE_PORT_CMD_SET_PARAM_V2; 10578c2ecf20Sopenharmony_ci 10588c2ecf20Sopenharmony_ci param->port_id = port_id; 10598c2ecf20Sopenharmony_ci param->payload_size = sizeof(*pdata) + psize; 10608c2ecf20Sopenharmony_ci param->payload_address_lsw = 0x00; 10618c2ecf20Sopenharmony_ci param->payload_address_msw = 0x00; 10628c2ecf20Sopenharmony_ci param->mem_map_handle = 0x00; 10638c2ecf20Sopenharmony_ci pdata->module_id = module_id; 10648c2ecf20Sopenharmony_ci pdata->param_id = param_id; 10658c2ecf20Sopenharmony_ci pdata->param_size = psize; 10668c2ecf20Sopenharmony_ci 10678c2ecf20Sopenharmony_ci ret = afe_apr_send_pkt(afe, pkt, port, AFE_PORT_CMD_SET_PARAM_V2); 10688c2ecf20Sopenharmony_ci if (ret) 10698c2ecf20Sopenharmony_ci dev_err(afe->dev, "AFE enable for port 0x%x failed %d\n", 10708c2ecf20Sopenharmony_ci port_id, ret); 10718c2ecf20Sopenharmony_ci 10728c2ecf20Sopenharmony_ci kfree(pkt); 10738c2ecf20Sopenharmony_ci return ret; 10748c2ecf20Sopenharmony_ci} 10758c2ecf20Sopenharmony_ci 10768c2ecf20Sopenharmony_cistatic int q6afe_port_set_lpass_clock(struct q6afe_port *port, 10778c2ecf20Sopenharmony_ci struct afe_clk_cfg *cfg) 10788c2ecf20Sopenharmony_ci{ 10798c2ecf20Sopenharmony_ci return q6afe_port_set_param_v2(port, cfg, 10808c2ecf20Sopenharmony_ci AFE_PARAM_ID_LPAIF_CLK_CONFIG, 10818c2ecf20Sopenharmony_ci AFE_MODULE_AUDIO_DEV_INTERFACE, 10828c2ecf20Sopenharmony_ci sizeof(*cfg)); 10838c2ecf20Sopenharmony_ci} 10848c2ecf20Sopenharmony_ci 10858c2ecf20Sopenharmony_cistatic int q6afe_set_lpass_clock_v2(struct q6afe_port *port, 10868c2ecf20Sopenharmony_ci struct afe_clk_set *cfg) 10878c2ecf20Sopenharmony_ci{ 10888c2ecf20Sopenharmony_ci return q6afe_port_set_param(port, cfg, AFE_PARAM_ID_CLOCK_SET, 10898c2ecf20Sopenharmony_ci AFE_MODULE_CLOCK_SET, sizeof(*cfg)); 10908c2ecf20Sopenharmony_ci} 10918c2ecf20Sopenharmony_ci 10928c2ecf20Sopenharmony_cistatic int q6afe_set_digital_codec_core_clock(struct q6afe_port *port, 10938c2ecf20Sopenharmony_ci struct afe_digital_clk_cfg *cfg) 10948c2ecf20Sopenharmony_ci{ 10958c2ecf20Sopenharmony_ci return q6afe_port_set_param_v2(port, cfg, 10968c2ecf20Sopenharmony_ci AFE_PARAM_ID_INT_DIGITAL_CDC_CLK_CONFIG, 10978c2ecf20Sopenharmony_ci AFE_MODULE_AUDIO_DEV_INTERFACE, 10988c2ecf20Sopenharmony_ci sizeof(*cfg)); 10998c2ecf20Sopenharmony_ci} 11008c2ecf20Sopenharmony_ci 11018c2ecf20Sopenharmony_ciint q6afe_set_lpass_clock(struct device *dev, int clk_id, int attri, 11028c2ecf20Sopenharmony_ci int clk_root, unsigned int freq) 11038c2ecf20Sopenharmony_ci{ 11048c2ecf20Sopenharmony_ci struct q6afe *afe = dev_get_drvdata(dev->parent); 11058c2ecf20Sopenharmony_ci struct afe_clk_set cset = {0,}; 11068c2ecf20Sopenharmony_ci 11078c2ecf20Sopenharmony_ci cset.clk_set_minor_version = AFE_API_VERSION_CLOCK_SET; 11088c2ecf20Sopenharmony_ci cset.clk_id = clk_id; 11098c2ecf20Sopenharmony_ci cset.clk_freq_in_hz = freq; 11108c2ecf20Sopenharmony_ci cset.clk_attri = attri; 11118c2ecf20Sopenharmony_ci cset.clk_root = clk_root; 11128c2ecf20Sopenharmony_ci cset.enable = !!freq; 11138c2ecf20Sopenharmony_ci 11148c2ecf20Sopenharmony_ci return q6afe_set_param(afe, NULL, &cset, AFE_PARAM_ID_CLOCK_SET, 11158c2ecf20Sopenharmony_ci AFE_MODULE_CLOCK_SET, sizeof(cset), 11168c2ecf20Sopenharmony_ci AFE_CLK_TOKEN); 11178c2ecf20Sopenharmony_ci} 11188c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(q6afe_set_lpass_clock); 11198c2ecf20Sopenharmony_ci 11208c2ecf20Sopenharmony_ciint q6afe_port_set_sysclk(struct q6afe_port *port, int clk_id, 11218c2ecf20Sopenharmony_ci int clk_src, int clk_root, 11228c2ecf20Sopenharmony_ci unsigned int freq, int dir) 11238c2ecf20Sopenharmony_ci{ 11248c2ecf20Sopenharmony_ci struct afe_clk_cfg ccfg = {0,}; 11258c2ecf20Sopenharmony_ci struct afe_clk_set cset = {0,}; 11268c2ecf20Sopenharmony_ci struct afe_digital_clk_cfg dcfg = {0,}; 11278c2ecf20Sopenharmony_ci int ret; 11288c2ecf20Sopenharmony_ci 11298c2ecf20Sopenharmony_ci switch (clk_id) { 11308c2ecf20Sopenharmony_ci case LPAIF_DIG_CLK: 11318c2ecf20Sopenharmony_ci dcfg.i2s_cfg_minor_version = AFE_API_VERSION_I2S_CONFIG; 11328c2ecf20Sopenharmony_ci dcfg.clk_val = freq; 11338c2ecf20Sopenharmony_ci dcfg.clk_root = clk_root; 11348c2ecf20Sopenharmony_ci ret = q6afe_set_digital_codec_core_clock(port, &dcfg); 11358c2ecf20Sopenharmony_ci break; 11368c2ecf20Sopenharmony_ci case LPAIF_BIT_CLK: 11378c2ecf20Sopenharmony_ci ccfg.i2s_cfg_minor_version = AFE_API_VERSION_I2S_CONFIG; 11388c2ecf20Sopenharmony_ci ccfg.clk_val1 = freq; 11398c2ecf20Sopenharmony_ci ccfg.clk_src = clk_src; 11408c2ecf20Sopenharmony_ci ccfg.clk_root = clk_root; 11418c2ecf20Sopenharmony_ci ccfg.clk_set_mode = Q6AFE_LPASS_MODE_CLK1_VALID; 11428c2ecf20Sopenharmony_ci ret = q6afe_port_set_lpass_clock(port, &ccfg); 11438c2ecf20Sopenharmony_ci break; 11448c2ecf20Sopenharmony_ci 11458c2ecf20Sopenharmony_ci case LPAIF_OSR_CLK: 11468c2ecf20Sopenharmony_ci ccfg.i2s_cfg_minor_version = AFE_API_VERSION_I2S_CONFIG; 11478c2ecf20Sopenharmony_ci ccfg.clk_val2 = freq; 11488c2ecf20Sopenharmony_ci ccfg.clk_src = clk_src; 11498c2ecf20Sopenharmony_ci ccfg.clk_root = clk_root; 11508c2ecf20Sopenharmony_ci ccfg.clk_set_mode = Q6AFE_LPASS_MODE_CLK2_VALID; 11518c2ecf20Sopenharmony_ci ret = q6afe_port_set_lpass_clock(port, &ccfg); 11528c2ecf20Sopenharmony_ci break; 11538c2ecf20Sopenharmony_ci case Q6AFE_LPASS_CLK_ID_PRI_MI2S_IBIT ... Q6AFE_LPASS_CLK_ID_QUI_MI2S_OSR: 11548c2ecf20Sopenharmony_ci case Q6AFE_LPASS_CLK_ID_MCLK_1 ... Q6AFE_LPASS_CLK_ID_INT_MCLK_1: 11558c2ecf20Sopenharmony_ci case Q6AFE_LPASS_CLK_ID_PRI_TDM_IBIT ... Q6AFE_LPASS_CLK_ID_QUIN_TDM_EBIT: 11568c2ecf20Sopenharmony_ci case Q6AFE_LPASS_CLK_ID_WSA_CORE_MCLK ... Q6AFE_LPASS_CLK_ID_VA_CORE_2X_MCLK: 11578c2ecf20Sopenharmony_ci cset.clk_set_minor_version = AFE_API_VERSION_CLOCK_SET; 11588c2ecf20Sopenharmony_ci cset.clk_id = clk_id; 11598c2ecf20Sopenharmony_ci cset.clk_freq_in_hz = freq; 11608c2ecf20Sopenharmony_ci cset.clk_attri = clk_src; 11618c2ecf20Sopenharmony_ci cset.clk_root = clk_root; 11628c2ecf20Sopenharmony_ci cset.enable = !!freq; 11638c2ecf20Sopenharmony_ci ret = q6afe_set_lpass_clock_v2(port, &cset); 11648c2ecf20Sopenharmony_ci break; 11658c2ecf20Sopenharmony_ci default: 11668c2ecf20Sopenharmony_ci ret = -EINVAL; 11678c2ecf20Sopenharmony_ci break; 11688c2ecf20Sopenharmony_ci } 11698c2ecf20Sopenharmony_ci 11708c2ecf20Sopenharmony_ci return ret; 11718c2ecf20Sopenharmony_ci} 11728c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(q6afe_port_set_sysclk); 11738c2ecf20Sopenharmony_ci 11748c2ecf20Sopenharmony_ci/** 11758c2ecf20Sopenharmony_ci * q6afe_port_stop() - Stop a afe port 11768c2ecf20Sopenharmony_ci * 11778c2ecf20Sopenharmony_ci * @port: Instance of port to stop 11788c2ecf20Sopenharmony_ci * 11798c2ecf20Sopenharmony_ci * Return: Will be an negative on packet size on success. 11808c2ecf20Sopenharmony_ci */ 11818c2ecf20Sopenharmony_ciint q6afe_port_stop(struct q6afe_port *port) 11828c2ecf20Sopenharmony_ci{ 11838c2ecf20Sopenharmony_ci struct afe_port_cmd_device_stop *stop; 11848c2ecf20Sopenharmony_ci struct q6afe *afe = port->afe; 11858c2ecf20Sopenharmony_ci struct apr_pkt *pkt; 11868c2ecf20Sopenharmony_ci int port_id = port->id; 11878c2ecf20Sopenharmony_ci int ret = 0; 11888c2ecf20Sopenharmony_ci int index, pkt_size; 11898c2ecf20Sopenharmony_ci void *p; 11908c2ecf20Sopenharmony_ci 11918c2ecf20Sopenharmony_ci port_id = port->id; 11928c2ecf20Sopenharmony_ci index = port->token; 11938c2ecf20Sopenharmony_ci if (index < 0 || index >= AFE_PORT_MAX) { 11948c2ecf20Sopenharmony_ci dev_err(afe->dev, "AFE port index[%d] invalid!\n", index); 11958c2ecf20Sopenharmony_ci return -EINVAL; 11968c2ecf20Sopenharmony_ci } 11978c2ecf20Sopenharmony_ci 11988c2ecf20Sopenharmony_ci pkt_size = APR_HDR_SIZE + sizeof(*stop); 11998c2ecf20Sopenharmony_ci p = kzalloc(pkt_size, GFP_KERNEL); 12008c2ecf20Sopenharmony_ci if (!p) 12018c2ecf20Sopenharmony_ci return -ENOMEM; 12028c2ecf20Sopenharmony_ci 12038c2ecf20Sopenharmony_ci pkt = p; 12048c2ecf20Sopenharmony_ci stop = p + APR_HDR_SIZE; 12058c2ecf20Sopenharmony_ci 12068c2ecf20Sopenharmony_ci pkt->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, 12078c2ecf20Sopenharmony_ci APR_HDR_LEN(APR_HDR_SIZE), 12088c2ecf20Sopenharmony_ci APR_PKT_VER); 12098c2ecf20Sopenharmony_ci pkt->hdr.pkt_size = pkt_size; 12108c2ecf20Sopenharmony_ci pkt->hdr.src_port = 0; 12118c2ecf20Sopenharmony_ci pkt->hdr.dest_port = 0; 12128c2ecf20Sopenharmony_ci pkt->hdr.token = index; 12138c2ecf20Sopenharmony_ci pkt->hdr.opcode = AFE_PORT_CMD_DEVICE_STOP; 12148c2ecf20Sopenharmony_ci stop->port_id = port_id; 12158c2ecf20Sopenharmony_ci stop->reserved = 0; 12168c2ecf20Sopenharmony_ci 12178c2ecf20Sopenharmony_ci ret = afe_apr_send_pkt(afe, pkt, port, AFE_PORT_CMD_DEVICE_STOP); 12188c2ecf20Sopenharmony_ci if (ret) 12198c2ecf20Sopenharmony_ci dev_err(afe->dev, "AFE close failed %d\n", ret); 12208c2ecf20Sopenharmony_ci 12218c2ecf20Sopenharmony_ci kfree(pkt); 12228c2ecf20Sopenharmony_ci return ret; 12238c2ecf20Sopenharmony_ci} 12248c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(q6afe_port_stop); 12258c2ecf20Sopenharmony_ci 12268c2ecf20Sopenharmony_ci/** 12278c2ecf20Sopenharmony_ci * q6afe_slim_port_prepare() - Prepare slim afe port. 12288c2ecf20Sopenharmony_ci * 12298c2ecf20Sopenharmony_ci * @port: Instance of afe port 12308c2ecf20Sopenharmony_ci * @cfg: SLIM configuration for the afe port 12318c2ecf20Sopenharmony_ci * 12328c2ecf20Sopenharmony_ci */ 12338c2ecf20Sopenharmony_civoid q6afe_slim_port_prepare(struct q6afe_port *port, 12348c2ecf20Sopenharmony_ci struct q6afe_slim_cfg *cfg) 12358c2ecf20Sopenharmony_ci{ 12368c2ecf20Sopenharmony_ci union afe_port_config *pcfg = &port->port_cfg; 12378c2ecf20Sopenharmony_ci 12388c2ecf20Sopenharmony_ci pcfg->slim_cfg.sb_cfg_minor_version = AFE_API_VERSION_SLIMBUS_CONFIG; 12398c2ecf20Sopenharmony_ci pcfg->slim_cfg.sample_rate = cfg->sample_rate; 12408c2ecf20Sopenharmony_ci pcfg->slim_cfg.bit_width = cfg->bit_width; 12418c2ecf20Sopenharmony_ci pcfg->slim_cfg.num_channels = cfg->num_channels; 12428c2ecf20Sopenharmony_ci pcfg->slim_cfg.data_format = cfg->data_format; 12438c2ecf20Sopenharmony_ci pcfg->slim_cfg.shared_ch_mapping[0] = cfg->ch_mapping[0]; 12448c2ecf20Sopenharmony_ci pcfg->slim_cfg.shared_ch_mapping[1] = cfg->ch_mapping[1]; 12458c2ecf20Sopenharmony_ci pcfg->slim_cfg.shared_ch_mapping[2] = cfg->ch_mapping[2]; 12468c2ecf20Sopenharmony_ci pcfg->slim_cfg.shared_ch_mapping[3] = cfg->ch_mapping[3]; 12478c2ecf20Sopenharmony_ci 12488c2ecf20Sopenharmony_ci} 12498c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(q6afe_slim_port_prepare); 12508c2ecf20Sopenharmony_ci 12518c2ecf20Sopenharmony_ci/** 12528c2ecf20Sopenharmony_ci * q6afe_tdm_port_prepare() - Prepare tdm afe port. 12538c2ecf20Sopenharmony_ci * 12548c2ecf20Sopenharmony_ci * @port: Instance of afe port 12558c2ecf20Sopenharmony_ci * @cfg: TDM configuration for the afe port 12568c2ecf20Sopenharmony_ci * 12578c2ecf20Sopenharmony_ci */ 12588c2ecf20Sopenharmony_civoid q6afe_tdm_port_prepare(struct q6afe_port *port, 12598c2ecf20Sopenharmony_ci struct q6afe_tdm_cfg *cfg) 12608c2ecf20Sopenharmony_ci{ 12618c2ecf20Sopenharmony_ci union afe_port_config *pcfg = &port->port_cfg; 12628c2ecf20Sopenharmony_ci 12638c2ecf20Sopenharmony_ci pcfg->tdm_cfg.tdm_cfg_minor_version = AFE_API_VERSION_TDM_CONFIG; 12648c2ecf20Sopenharmony_ci pcfg->tdm_cfg.num_channels = cfg->num_channels; 12658c2ecf20Sopenharmony_ci pcfg->tdm_cfg.sample_rate = cfg->sample_rate; 12668c2ecf20Sopenharmony_ci pcfg->tdm_cfg.bit_width = cfg->bit_width; 12678c2ecf20Sopenharmony_ci pcfg->tdm_cfg.data_format = cfg->data_format; 12688c2ecf20Sopenharmony_ci pcfg->tdm_cfg.sync_mode = cfg->sync_mode; 12698c2ecf20Sopenharmony_ci pcfg->tdm_cfg.sync_src = cfg->sync_src; 12708c2ecf20Sopenharmony_ci pcfg->tdm_cfg.nslots_per_frame = cfg->nslots_per_frame; 12718c2ecf20Sopenharmony_ci 12728c2ecf20Sopenharmony_ci pcfg->tdm_cfg.slot_width = cfg->slot_width; 12738c2ecf20Sopenharmony_ci pcfg->tdm_cfg.slot_mask = cfg->slot_mask; 12748c2ecf20Sopenharmony_ci port->scfg = kzalloc(sizeof(*port->scfg), GFP_KERNEL); 12758c2ecf20Sopenharmony_ci if (!port->scfg) 12768c2ecf20Sopenharmony_ci return; 12778c2ecf20Sopenharmony_ci 12788c2ecf20Sopenharmony_ci port->scfg->minor_version = AFE_API_VERSION_SLOT_MAPPING_CONFIG; 12798c2ecf20Sopenharmony_ci port->scfg->num_channels = cfg->num_channels; 12808c2ecf20Sopenharmony_ci port->scfg->bitwidth = cfg->bit_width; 12818c2ecf20Sopenharmony_ci port->scfg->data_align_type = cfg->data_align_type; 12828c2ecf20Sopenharmony_ci memcpy(port->scfg->ch_mapping, cfg->ch_mapping, 12838c2ecf20Sopenharmony_ci sizeof(u16) * AFE_PORT_MAX_AUDIO_CHAN_CNT); 12848c2ecf20Sopenharmony_ci} 12858c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(q6afe_tdm_port_prepare); 12868c2ecf20Sopenharmony_ci 12878c2ecf20Sopenharmony_ci/** 12888c2ecf20Sopenharmony_ci * q6afe_hdmi_port_prepare() - Prepare hdmi afe port. 12898c2ecf20Sopenharmony_ci * 12908c2ecf20Sopenharmony_ci * @port: Instance of afe port 12918c2ecf20Sopenharmony_ci * @cfg: HDMI configuration for the afe port 12928c2ecf20Sopenharmony_ci * 12938c2ecf20Sopenharmony_ci */ 12948c2ecf20Sopenharmony_civoid q6afe_hdmi_port_prepare(struct q6afe_port *port, 12958c2ecf20Sopenharmony_ci struct q6afe_hdmi_cfg *cfg) 12968c2ecf20Sopenharmony_ci{ 12978c2ecf20Sopenharmony_ci union afe_port_config *pcfg = &port->port_cfg; 12988c2ecf20Sopenharmony_ci 12998c2ecf20Sopenharmony_ci pcfg->hdmi_multi_ch.hdmi_cfg_minor_version = 13008c2ecf20Sopenharmony_ci AFE_API_VERSION_HDMI_CONFIG; 13018c2ecf20Sopenharmony_ci pcfg->hdmi_multi_ch.datatype = cfg->datatype; 13028c2ecf20Sopenharmony_ci pcfg->hdmi_multi_ch.channel_allocation = cfg->channel_allocation; 13038c2ecf20Sopenharmony_ci pcfg->hdmi_multi_ch.sample_rate = cfg->sample_rate; 13048c2ecf20Sopenharmony_ci pcfg->hdmi_multi_ch.bit_width = cfg->bit_width; 13058c2ecf20Sopenharmony_ci} 13068c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(q6afe_hdmi_port_prepare); 13078c2ecf20Sopenharmony_ci 13088c2ecf20Sopenharmony_ci/** 13098c2ecf20Sopenharmony_ci * q6afe_i2s_port_prepare() - Prepare i2s afe port. 13108c2ecf20Sopenharmony_ci * 13118c2ecf20Sopenharmony_ci * @port: Instance of afe port 13128c2ecf20Sopenharmony_ci * @cfg: I2S configuration for the afe port 13138c2ecf20Sopenharmony_ci * Return: Will be an negative on error and zero on success. 13148c2ecf20Sopenharmony_ci */ 13158c2ecf20Sopenharmony_ciint q6afe_i2s_port_prepare(struct q6afe_port *port, struct q6afe_i2s_cfg *cfg) 13168c2ecf20Sopenharmony_ci{ 13178c2ecf20Sopenharmony_ci union afe_port_config *pcfg = &port->port_cfg; 13188c2ecf20Sopenharmony_ci struct device *dev = port->afe->dev; 13198c2ecf20Sopenharmony_ci int num_sd_lines; 13208c2ecf20Sopenharmony_ci 13218c2ecf20Sopenharmony_ci pcfg->i2s_cfg.i2s_cfg_minor_version = AFE_API_VERSION_I2S_CONFIG; 13228c2ecf20Sopenharmony_ci pcfg->i2s_cfg.sample_rate = cfg->sample_rate; 13238c2ecf20Sopenharmony_ci pcfg->i2s_cfg.bit_width = cfg->bit_width; 13248c2ecf20Sopenharmony_ci pcfg->i2s_cfg.data_format = AFE_LINEAR_PCM_DATA; 13258c2ecf20Sopenharmony_ci 13268c2ecf20Sopenharmony_ci switch (cfg->fmt & SND_SOC_DAIFMT_MASTER_MASK) { 13278c2ecf20Sopenharmony_ci case SND_SOC_DAIFMT_CBS_CFS: 13288c2ecf20Sopenharmony_ci pcfg->i2s_cfg.ws_src = AFE_PORT_CONFIG_I2S_WS_SRC_INTERNAL; 13298c2ecf20Sopenharmony_ci break; 13308c2ecf20Sopenharmony_ci case SND_SOC_DAIFMT_CBM_CFM: 13318c2ecf20Sopenharmony_ci /* CPU is slave */ 13328c2ecf20Sopenharmony_ci pcfg->i2s_cfg.ws_src = AFE_PORT_CONFIG_I2S_WS_SRC_EXTERNAL; 13338c2ecf20Sopenharmony_ci break; 13348c2ecf20Sopenharmony_ci default: 13358c2ecf20Sopenharmony_ci break; 13368c2ecf20Sopenharmony_ci } 13378c2ecf20Sopenharmony_ci 13388c2ecf20Sopenharmony_ci num_sd_lines = hweight_long(cfg->sd_line_mask); 13398c2ecf20Sopenharmony_ci 13408c2ecf20Sopenharmony_ci switch (num_sd_lines) { 13418c2ecf20Sopenharmony_ci case 0: 13428c2ecf20Sopenharmony_ci dev_err(dev, "no line is assigned\n"); 13438c2ecf20Sopenharmony_ci return -EINVAL; 13448c2ecf20Sopenharmony_ci case 1: 13458c2ecf20Sopenharmony_ci switch (cfg->sd_line_mask) { 13468c2ecf20Sopenharmony_ci case AFE_PORT_I2S_SD0_MASK: 13478c2ecf20Sopenharmony_ci pcfg->i2s_cfg.channel_mode = AFE_PORT_I2S_SD0; 13488c2ecf20Sopenharmony_ci break; 13498c2ecf20Sopenharmony_ci case AFE_PORT_I2S_SD1_MASK: 13508c2ecf20Sopenharmony_ci pcfg->i2s_cfg.channel_mode = AFE_PORT_I2S_SD1; 13518c2ecf20Sopenharmony_ci break; 13528c2ecf20Sopenharmony_ci case AFE_PORT_I2S_SD2_MASK: 13538c2ecf20Sopenharmony_ci pcfg->i2s_cfg.channel_mode = AFE_PORT_I2S_SD2; 13548c2ecf20Sopenharmony_ci break; 13558c2ecf20Sopenharmony_ci case AFE_PORT_I2S_SD3_MASK: 13568c2ecf20Sopenharmony_ci pcfg->i2s_cfg.channel_mode = AFE_PORT_I2S_SD3; 13578c2ecf20Sopenharmony_ci break; 13588c2ecf20Sopenharmony_ci default: 13598c2ecf20Sopenharmony_ci dev_err(dev, "Invalid SD lines\n"); 13608c2ecf20Sopenharmony_ci return -EINVAL; 13618c2ecf20Sopenharmony_ci } 13628c2ecf20Sopenharmony_ci break; 13638c2ecf20Sopenharmony_ci case 2: 13648c2ecf20Sopenharmony_ci switch (cfg->sd_line_mask) { 13658c2ecf20Sopenharmony_ci case AFE_PORT_I2S_SD0_1_MASK: 13668c2ecf20Sopenharmony_ci pcfg->i2s_cfg.channel_mode = AFE_PORT_I2S_QUAD01; 13678c2ecf20Sopenharmony_ci break; 13688c2ecf20Sopenharmony_ci case AFE_PORT_I2S_SD2_3_MASK: 13698c2ecf20Sopenharmony_ci pcfg->i2s_cfg.channel_mode = AFE_PORT_I2S_QUAD23; 13708c2ecf20Sopenharmony_ci break; 13718c2ecf20Sopenharmony_ci default: 13728c2ecf20Sopenharmony_ci dev_err(dev, "Invalid SD lines\n"); 13738c2ecf20Sopenharmony_ci return -EINVAL; 13748c2ecf20Sopenharmony_ci } 13758c2ecf20Sopenharmony_ci break; 13768c2ecf20Sopenharmony_ci case 3: 13778c2ecf20Sopenharmony_ci switch (cfg->sd_line_mask) { 13788c2ecf20Sopenharmony_ci case AFE_PORT_I2S_SD0_1_2_MASK: 13798c2ecf20Sopenharmony_ci pcfg->i2s_cfg.channel_mode = AFE_PORT_I2S_6CHS; 13808c2ecf20Sopenharmony_ci break; 13818c2ecf20Sopenharmony_ci default: 13828c2ecf20Sopenharmony_ci dev_err(dev, "Invalid SD lines\n"); 13838c2ecf20Sopenharmony_ci return -EINVAL; 13848c2ecf20Sopenharmony_ci } 13858c2ecf20Sopenharmony_ci break; 13868c2ecf20Sopenharmony_ci case 4: 13878c2ecf20Sopenharmony_ci switch (cfg->sd_line_mask) { 13888c2ecf20Sopenharmony_ci case AFE_PORT_I2S_SD0_1_2_3_MASK: 13898c2ecf20Sopenharmony_ci pcfg->i2s_cfg.channel_mode = AFE_PORT_I2S_8CHS; 13908c2ecf20Sopenharmony_ci 13918c2ecf20Sopenharmony_ci break; 13928c2ecf20Sopenharmony_ci default: 13938c2ecf20Sopenharmony_ci dev_err(dev, "Invalid SD lines\n"); 13948c2ecf20Sopenharmony_ci return -EINVAL; 13958c2ecf20Sopenharmony_ci } 13968c2ecf20Sopenharmony_ci break; 13978c2ecf20Sopenharmony_ci default: 13988c2ecf20Sopenharmony_ci dev_err(dev, "Invalid SD lines\n"); 13998c2ecf20Sopenharmony_ci return -EINVAL; 14008c2ecf20Sopenharmony_ci } 14018c2ecf20Sopenharmony_ci 14028c2ecf20Sopenharmony_ci switch (cfg->num_channels) { 14038c2ecf20Sopenharmony_ci case 1: 14048c2ecf20Sopenharmony_ci case 2: 14058c2ecf20Sopenharmony_ci switch (pcfg->i2s_cfg.channel_mode) { 14068c2ecf20Sopenharmony_ci case AFE_PORT_I2S_QUAD01: 14078c2ecf20Sopenharmony_ci case AFE_PORT_I2S_6CHS: 14088c2ecf20Sopenharmony_ci case AFE_PORT_I2S_8CHS: 14098c2ecf20Sopenharmony_ci pcfg->i2s_cfg.channel_mode = AFE_PORT_I2S_SD0; 14108c2ecf20Sopenharmony_ci break; 14118c2ecf20Sopenharmony_ci case AFE_PORT_I2S_QUAD23: 14128c2ecf20Sopenharmony_ci pcfg->i2s_cfg.channel_mode = AFE_PORT_I2S_SD2; 14138c2ecf20Sopenharmony_ci break; 14148c2ecf20Sopenharmony_ci } 14158c2ecf20Sopenharmony_ci 14168c2ecf20Sopenharmony_ci if (cfg->num_channels == 2) 14178c2ecf20Sopenharmony_ci pcfg->i2s_cfg.mono_stereo = AFE_PORT_I2S_STEREO; 14188c2ecf20Sopenharmony_ci else 14198c2ecf20Sopenharmony_ci pcfg->i2s_cfg.mono_stereo = AFE_PORT_I2S_MONO; 14208c2ecf20Sopenharmony_ci 14218c2ecf20Sopenharmony_ci break; 14228c2ecf20Sopenharmony_ci case 3: 14238c2ecf20Sopenharmony_ci case 4: 14248c2ecf20Sopenharmony_ci if (pcfg->i2s_cfg.channel_mode < AFE_PORT_I2S_QUAD01) { 14258c2ecf20Sopenharmony_ci dev_err(dev, "Invalid Channel mode\n"); 14268c2ecf20Sopenharmony_ci return -EINVAL; 14278c2ecf20Sopenharmony_ci } 14288c2ecf20Sopenharmony_ci break; 14298c2ecf20Sopenharmony_ci case 5: 14308c2ecf20Sopenharmony_ci case 6: 14318c2ecf20Sopenharmony_ci if (pcfg->i2s_cfg.channel_mode < AFE_PORT_I2S_6CHS) { 14328c2ecf20Sopenharmony_ci dev_err(dev, "Invalid Channel mode\n"); 14338c2ecf20Sopenharmony_ci return -EINVAL; 14348c2ecf20Sopenharmony_ci } 14358c2ecf20Sopenharmony_ci break; 14368c2ecf20Sopenharmony_ci case 7: 14378c2ecf20Sopenharmony_ci case 8: 14388c2ecf20Sopenharmony_ci if (pcfg->i2s_cfg.channel_mode < AFE_PORT_I2S_8CHS) { 14398c2ecf20Sopenharmony_ci dev_err(dev, "Invalid Channel mode\n"); 14408c2ecf20Sopenharmony_ci return -EINVAL; 14418c2ecf20Sopenharmony_ci } 14428c2ecf20Sopenharmony_ci break; 14438c2ecf20Sopenharmony_ci default: 14448c2ecf20Sopenharmony_ci break; 14458c2ecf20Sopenharmony_ci } 14468c2ecf20Sopenharmony_ci 14478c2ecf20Sopenharmony_ci return 0; 14488c2ecf20Sopenharmony_ci} 14498c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(q6afe_i2s_port_prepare); 14508c2ecf20Sopenharmony_ci 14518c2ecf20Sopenharmony_ci/** 14528c2ecf20Sopenharmony_ci * q6afe_dam_port_prepare() - Prepare dma afe port. 14538c2ecf20Sopenharmony_ci * 14548c2ecf20Sopenharmony_ci * @port: Instance of afe port 14558c2ecf20Sopenharmony_ci * @cfg: DMA configuration for the afe port 14568c2ecf20Sopenharmony_ci * 14578c2ecf20Sopenharmony_ci */ 14588c2ecf20Sopenharmony_civoid q6afe_cdc_dma_port_prepare(struct q6afe_port *port, 14598c2ecf20Sopenharmony_ci struct q6afe_cdc_dma_cfg *cfg) 14608c2ecf20Sopenharmony_ci{ 14618c2ecf20Sopenharmony_ci union afe_port_config *pcfg = &port->port_cfg; 14628c2ecf20Sopenharmony_ci struct afe_param_id_cdc_dma_cfg *dma_cfg = &pcfg->dma_cfg; 14638c2ecf20Sopenharmony_ci 14648c2ecf20Sopenharmony_ci dma_cfg->cdc_dma_cfg_minor_version = AFE_API_VERSION_CODEC_DMA_CONFIG; 14658c2ecf20Sopenharmony_ci dma_cfg->sample_rate = cfg->sample_rate; 14668c2ecf20Sopenharmony_ci dma_cfg->bit_width = cfg->bit_width; 14678c2ecf20Sopenharmony_ci dma_cfg->data_format = cfg->data_format; 14688c2ecf20Sopenharmony_ci dma_cfg->num_channels = cfg->num_channels; 14698c2ecf20Sopenharmony_ci if (!cfg->active_channels_mask) 14708c2ecf20Sopenharmony_ci dma_cfg->active_channels_mask = (1 << cfg->num_channels) - 1; 14718c2ecf20Sopenharmony_ci} 14728c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(q6afe_cdc_dma_port_prepare); 14738c2ecf20Sopenharmony_ci/** 14748c2ecf20Sopenharmony_ci * q6afe_port_start() - Start a afe port 14758c2ecf20Sopenharmony_ci * 14768c2ecf20Sopenharmony_ci * @port: Instance of port to start 14778c2ecf20Sopenharmony_ci * 14788c2ecf20Sopenharmony_ci * Return: Will be an negative on packet size on success. 14798c2ecf20Sopenharmony_ci */ 14808c2ecf20Sopenharmony_ciint q6afe_port_start(struct q6afe_port *port) 14818c2ecf20Sopenharmony_ci{ 14828c2ecf20Sopenharmony_ci struct afe_port_cmd_device_start *start; 14838c2ecf20Sopenharmony_ci struct q6afe *afe = port->afe; 14848c2ecf20Sopenharmony_ci int port_id = port->id; 14858c2ecf20Sopenharmony_ci int ret, param_id = port->cfg_type; 14868c2ecf20Sopenharmony_ci struct apr_pkt *pkt; 14878c2ecf20Sopenharmony_ci int pkt_size; 14888c2ecf20Sopenharmony_ci void *p; 14898c2ecf20Sopenharmony_ci 14908c2ecf20Sopenharmony_ci ret = q6afe_port_set_param_v2(port, &port->port_cfg, param_id, 14918c2ecf20Sopenharmony_ci AFE_MODULE_AUDIO_DEV_INTERFACE, 14928c2ecf20Sopenharmony_ci sizeof(port->port_cfg)); 14938c2ecf20Sopenharmony_ci if (ret) { 14948c2ecf20Sopenharmony_ci dev_err(afe->dev, "AFE enable for port 0x%x failed %d\n", 14958c2ecf20Sopenharmony_ci port_id, ret); 14968c2ecf20Sopenharmony_ci return ret; 14978c2ecf20Sopenharmony_ci } 14988c2ecf20Sopenharmony_ci 14998c2ecf20Sopenharmony_ci if (port->scfg) { 15008c2ecf20Sopenharmony_ci ret = q6afe_port_set_param_v2(port, port->scfg, 15018c2ecf20Sopenharmony_ci AFE_PARAM_ID_PORT_SLOT_MAPPING_CONFIG, 15028c2ecf20Sopenharmony_ci AFE_MODULE_TDM, sizeof(*port->scfg)); 15038c2ecf20Sopenharmony_ci if (ret) { 15048c2ecf20Sopenharmony_ci dev_err(afe->dev, "AFE enable for port 0x%x failed %d\n", 15058c2ecf20Sopenharmony_ci port_id, ret); 15068c2ecf20Sopenharmony_ci return ret; 15078c2ecf20Sopenharmony_ci } 15088c2ecf20Sopenharmony_ci } 15098c2ecf20Sopenharmony_ci 15108c2ecf20Sopenharmony_ci pkt_size = APR_HDR_SIZE + sizeof(*start); 15118c2ecf20Sopenharmony_ci p = kzalloc(pkt_size, GFP_KERNEL); 15128c2ecf20Sopenharmony_ci if (!p) 15138c2ecf20Sopenharmony_ci return -ENOMEM; 15148c2ecf20Sopenharmony_ci 15158c2ecf20Sopenharmony_ci pkt = p; 15168c2ecf20Sopenharmony_ci start = p + APR_HDR_SIZE; 15178c2ecf20Sopenharmony_ci 15188c2ecf20Sopenharmony_ci pkt->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, 15198c2ecf20Sopenharmony_ci APR_HDR_LEN(APR_HDR_SIZE), 15208c2ecf20Sopenharmony_ci APR_PKT_VER); 15218c2ecf20Sopenharmony_ci pkt->hdr.pkt_size = pkt_size; 15228c2ecf20Sopenharmony_ci pkt->hdr.src_port = 0; 15238c2ecf20Sopenharmony_ci pkt->hdr.dest_port = 0; 15248c2ecf20Sopenharmony_ci pkt->hdr.token = port->token; 15258c2ecf20Sopenharmony_ci pkt->hdr.opcode = AFE_PORT_CMD_DEVICE_START; 15268c2ecf20Sopenharmony_ci 15278c2ecf20Sopenharmony_ci start->port_id = port_id; 15288c2ecf20Sopenharmony_ci 15298c2ecf20Sopenharmony_ci ret = afe_apr_send_pkt(afe, pkt, port, AFE_PORT_CMD_DEVICE_START); 15308c2ecf20Sopenharmony_ci if (ret) 15318c2ecf20Sopenharmony_ci dev_err(afe->dev, "AFE enable for port 0x%x failed %d\n", 15328c2ecf20Sopenharmony_ci port_id, ret); 15338c2ecf20Sopenharmony_ci 15348c2ecf20Sopenharmony_ci kfree(pkt); 15358c2ecf20Sopenharmony_ci return ret; 15368c2ecf20Sopenharmony_ci} 15378c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(q6afe_port_start); 15388c2ecf20Sopenharmony_ci 15398c2ecf20Sopenharmony_ci/** 15408c2ecf20Sopenharmony_ci * q6afe_port_get_from_id() - Get port instance from a port id 15418c2ecf20Sopenharmony_ci * 15428c2ecf20Sopenharmony_ci * @dev: Pointer to afe child device. 15438c2ecf20Sopenharmony_ci * @id: port id 15448c2ecf20Sopenharmony_ci * 15458c2ecf20Sopenharmony_ci * Return: Will be an error pointer on error or a valid afe port 15468c2ecf20Sopenharmony_ci * on success. 15478c2ecf20Sopenharmony_ci */ 15488c2ecf20Sopenharmony_cistruct q6afe_port *q6afe_port_get_from_id(struct device *dev, int id) 15498c2ecf20Sopenharmony_ci{ 15508c2ecf20Sopenharmony_ci int port_id; 15518c2ecf20Sopenharmony_ci struct q6afe *afe = dev_get_drvdata(dev->parent); 15528c2ecf20Sopenharmony_ci struct q6afe_port *port; 15538c2ecf20Sopenharmony_ci unsigned long flags; 15548c2ecf20Sopenharmony_ci int cfg_type; 15558c2ecf20Sopenharmony_ci 15568c2ecf20Sopenharmony_ci if (id < 0 || id >= AFE_PORT_MAX) { 15578c2ecf20Sopenharmony_ci dev_err(dev, "AFE port token[%d] invalid!\n", id); 15588c2ecf20Sopenharmony_ci return ERR_PTR(-EINVAL); 15598c2ecf20Sopenharmony_ci } 15608c2ecf20Sopenharmony_ci 15618c2ecf20Sopenharmony_ci /* if port is multiple times bind/unbind before callback finishes */ 15628c2ecf20Sopenharmony_ci port = q6afe_find_port(afe, id); 15638c2ecf20Sopenharmony_ci if (port) { 15648c2ecf20Sopenharmony_ci dev_err(dev, "AFE Port already open\n"); 15658c2ecf20Sopenharmony_ci return port; 15668c2ecf20Sopenharmony_ci } 15678c2ecf20Sopenharmony_ci 15688c2ecf20Sopenharmony_ci port_id = port_maps[id].port_id; 15698c2ecf20Sopenharmony_ci 15708c2ecf20Sopenharmony_ci switch (port_id) { 15718c2ecf20Sopenharmony_ci case AFE_PORT_ID_MULTICHAN_HDMI_RX: 15728c2ecf20Sopenharmony_ci case AFE_PORT_ID_HDMI_OVER_DP_RX: 15738c2ecf20Sopenharmony_ci cfg_type = AFE_PARAM_ID_HDMI_CONFIG; 15748c2ecf20Sopenharmony_ci break; 15758c2ecf20Sopenharmony_ci case AFE_PORT_ID_SLIMBUS_MULTI_CHAN_0_TX: 15768c2ecf20Sopenharmony_ci case AFE_PORT_ID_SLIMBUS_MULTI_CHAN_1_TX: 15778c2ecf20Sopenharmony_ci case AFE_PORT_ID_SLIMBUS_MULTI_CHAN_2_TX: 15788c2ecf20Sopenharmony_ci case AFE_PORT_ID_SLIMBUS_MULTI_CHAN_3_TX: 15798c2ecf20Sopenharmony_ci case AFE_PORT_ID_SLIMBUS_MULTI_CHAN_4_TX: 15808c2ecf20Sopenharmony_ci case AFE_PORT_ID_SLIMBUS_MULTI_CHAN_5_TX: 15818c2ecf20Sopenharmony_ci case AFE_PORT_ID_SLIMBUS_MULTI_CHAN_6_TX: 15828c2ecf20Sopenharmony_ci case AFE_PORT_ID_SLIMBUS_MULTI_CHAN_0_RX: 15838c2ecf20Sopenharmony_ci case AFE_PORT_ID_SLIMBUS_MULTI_CHAN_1_RX: 15848c2ecf20Sopenharmony_ci case AFE_PORT_ID_SLIMBUS_MULTI_CHAN_2_RX: 15858c2ecf20Sopenharmony_ci case AFE_PORT_ID_SLIMBUS_MULTI_CHAN_3_RX: 15868c2ecf20Sopenharmony_ci case AFE_PORT_ID_SLIMBUS_MULTI_CHAN_4_RX: 15878c2ecf20Sopenharmony_ci case AFE_PORT_ID_SLIMBUS_MULTI_CHAN_5_RX: 15888c2ecf20Sopenharmony_ci case AFE_PORT_ID_SLIMBUS_MULTI_CHAN_6_RX: 15898c2ecf20Sopenharmony_ci cfg_type = AFE_PARAM_ID_SLIMBUS_CONFIG; 15908c2ecf20Sopenharmony_ci break; 15918c2ecf20Sopenharmony_ci 15928c2ecf20Sopenharmony_ci case AFE_PORT_ID_PRIMARY_MI2S_RX: 15938c2ecf20Sopenharmony_ci case AFE_PORT_ID_PRIMARY_MI2S_TX: 15948c2ecf20Sopenharmony_ci case AFE_PORT_ID_SECONDARY_MI2S_RX: 15958c2ecf20Sopenharmony_ci case AFE_PORT_ID_SECONDARY_MI2S_TX: 15968c2ecf20Sopenharmony_ci case AFE_PORT_ID_TERTIARY_MI2S_RX: 15978c2ecf20Sopenharmony_ci case AFE_PORT_ID_TERTIARY_MI2S_TX: 15988c2ecf20Sopenharmony_ci case AFE_PORT_ID_QUATERNARY_MI2S_RX: 15998c2ecf20Sopenharmony_ci case AFE_PORT_ID_QUATERNARY_MI2S_TX: 16008c2ecf20Sopenharmony_ci cfg_type = AFE_PARAM_ID_I2S_CONFIG; 16018c2ecf20Sopenharmony_ci break; 16028c2ecf20Sopenharmony_ci case AFE_PORT_ID_PRIMARY_TDM_RX ... AFE_PORT_ID_QUINARY_TDM_TX_7: 16038c2ecf20Sopenharmony_ci cfg_type = AFE_PARAM_ID_TDM_CONFIG; 16048c2ecf20Sopenharmony_ci break; 16058c2ecf20Sopenharmony_ci case AFE_PORT_ID_WSA_CODEC_DMA_RX_0 ... AFE_PORT_ID_RX_CODEC_DMA_RX_7: 16068c2ecf20Sopenharmony_ci cfg_type = AFE_PARAM_ID_CODEC_DMA_CONFIG; 16078c2ecf20Sopenharmony_ci break; 16088c2ecf20Sopenharmony_ci default: 16098c2ecf20Sopenharmony_ci dev_err(dev, "Invalid port id 0x%x\n", port_id); 16108c2ecf20Sopenharmony_ci return ERR_PTR(-EINVAL); 16118c2ecf20Sopenharmony_ci } 16128c2ecf20Sopenharmony_ci 16138c2ecf20Sopenharmony_ci port = kzalloc(sizeof(*port), GFP_KERNEL); 16148c2ecf20Sopenharmony_ci if (!port) 16158c2ecf20Sopenharmony_ci return ERR_PTR(-ENOMEM); 16168c2ecf20Sopenharmony_ci 16178c2ecf20Sopenharmony_ci init_waitqueue_head(&port->wait); 16188c2ecf20Sopenharmony_ci 16198c2ecf20Sopenharmony_ci port->token = id; 16208c2ecf20Sopenharmony_ci port->id = port_id; 16218c2ecf20Sopenharmony_ci port->afe = afe; 16228c2ecf20Sopenharmony_ci port->cfg_type = cfg_type; 16238c2ecf20Sopenharmony_ci kref_init(&port->refcount); 16248c2ecf20Sopenharmony_ci 16258c2ecf20Sopenharmony_ci spin_lock_irqsave(&afe->port_list_lock, flags); 16268c2ecf20Sopenharmony_ci list_add_tail(&port->node, &afe->port_list); 16278c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&afe->port_list_lock, flags); 16288c2ecf20Sopenharmony_ci 16298c2ecf20Sopenharmony_ci return port; 16308c2ecf20Sopenharmony_ci 16318c2ecf20Sopenharmony_ci} 16328c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(q6afe_port_get_from_id); 16338c2ecf20Sopenharmony_ci 16348c2ecf20Sopenharmony_ci/** 16358c2ecf20Sopenharmony_ci * q6afe_port_put() - Release port reference 16368c2ecf20Sopenharmony_ci * 16378c2ecf20Sopenharmony_ci * @port: Instance of port to put 16388c2ecf20Sopenharmony_ci */ 16398c2ecf20Sopenharmony_civoid q6afe_port_put(struct q6afe_port *port) 16408c2ecf20Sopenharmony_ci{ 16418c2ecf20Sopenharmony_ci kref_put(&port->refcount, q6afe_port_free); 16428c2ecf20Sopenharmony_ci} 16438c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(q6afe_port_put); 16448c2ecf20Sopenharmony_ci 16458c2ecf20Sopenharmony_ciint q6afe_unvote_lpass_core_hw(struct device *dev, uint32_t hw_block_id, 16468c2ecf20Sopenharmony_ci uint32_t client_handle) 16478c2ecf20Sopenharmony_ci{ 16488c2ecf20Sopenharmony_ci struct q6afe *afe = dev_get_drvdata(dev->parent); 16498c2ecf20Sopenharmony_ci struct afe_cmd_remote_lpass_core_hw_devote_request *vote_cfg; 16508c2ecf20Sopenharmony_ci struct apr_pkt *pkt; 16518c2ecf20Sopenharmony_ci int ret = 0; 16528c2ecf20Sopenharmony_ci int pkt_size; 16538c2ecf20Sopenharmony_ci void *p; 16548c2ecf20Sopenharmony_ci 16558c2ecf20Sopenharmony_ci pkt_size = APR_HDR_SIZE + sizeof(*vote_cfg); 16568c2ecf20Sopenharmony_ci p = kzalloc(pkt_size, GFP_KERNEL); 16578c2ecf20Sopenharmony_ci if (!p) 16588c2ecf20Sopenharmony_ci return -ENOMEM; 16598c2ecf20Sopenharmony_ci 16608c2ecf20Sopenharmony_ci pkt = p; 16618c2ecf20Sopenharmony_ci vote_cfg = p + APR_HDR_SIZE; 16628c2ecf20Sopenharmony_ci 16638c2ecf20Sopenharmony_ci pkt->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, 16648c2ecf20Sopenharmony_ci APR_HDR_LEN(APR_HDR_SIZE), 16658c2ecf20Sopenharmony_ci APR_PKT_VER); 16668c2ecf20Sopenharmony_ci pkt->hdr.pkt_size = pkt_size; 16678c2ecf20Sopenharmony_ci pkt->hdr.src_port = 0; 16688c2ecf20Sopenharmony_ci pkt->hdr.dest_port = 0; 16698c2ecf20Sopenharmony_ci pkt->hdr.token = hw_block_id; 16708c2ecf20Sopenharmony_ci pkt->hdr.opcode = AFE_CMD_REMOTE_LPASS_CORE_HW_DEVOTE_REQUEST; 16718c2ecf20Sopenharmony_ci vote_cfg->hw_block_id = hw_block_id; 16728c2ecf20Sopenharmony_ci vote_cfg->client_handle = client_handle; 16738c2ecf20Sopenharmony_ci 16748c2ecf20Sopenharmony_ci ret = apr_send_pkt(afe->apr, pkt); 16758c2ecf20Sopenharmony_ci if (ret < 0) 16768c2ecf20Sopenharmony_ci dev_err(afe->dev, "AFE failed to unvote (%d)\n", hw_block_id); 16778c2ecf20Sopenharmony_ci 16788c2ecf20Sopenharmony_ci kfree(pkt); 16798c2ecf20Sopenharmony_ci return ret; 16808c2ecf20Sopenharmony_ci} 16818c2ecf20Sopenharmony_ciEXPORT_SYMBOL(q6afe_unvote_lpass_core_hw); 16828c2ecf20Sopenharmony_ci 16838c2ecf20Sopenharmony_ciint q6afe_vote_lpass_core_hw(struct device *dev, uint32_t hw_block_id, 16848c2ecf20Sopenharmony_ci char *client_name, uint32_t *client_handle) 16858c2ecf20Sopenharmony_ci{ 16868c2ecf20Sopenharmony_ci struct q6afe *afe = dev_get_drvdata(dev->parent); 16878c2ecf20Sopenharmony_ci struct afe_cmd_remote_lpass_core_hw_vote_request *vote_cfg; 16888c2ecf20Sopenharmony_ci struct apr_pkt *pkt; 16898c2ecf20Sopenharmony_ci int ret = 0; 16908c2ecf20Sopenharmony_ci int pkt_size; 16918c2ecf20Sopenharmony_ci void *p; 16928c2ecf20Sopenharmony_ci 16938c2ecf20Sopenharmony_ci pkt_size = APR_HDR_SIZE + sizeof(*vote_cfg); 16948c2ecf20Sopenharmony_ci p = kzalloc(pkt_size, GFP_KERNEL); 16958c2ecf20Sopenharmony_ci if (!p) 16968c2ecf20Sopenharmony_ci return -ENOMEM; 16978c2ecf20Sopenharmony_ci 16988c2ecf20Sopenharmony_ci pkt = p; 16998c2ecf20Sopenharmony_ci vote_cfg = p + APR_HDR_SIZE; 17008c2ecf20Sopenharmony_ci 17018c2ecf20Sopenharmony_ci pkt->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, 17028c2ecf20Sopenharmony_ci APR_HDR_LEN(APR_HDR_SIZE), 17038c2ecf20Sopenharmony_ci APR_PKT_VER); 17048c2ecf20Sopenharmony_ci pkt->hdr.pkt_size = pkt_size; 17058c2ecf20Sopenharmony_ci pkt->hdr.src_port = 0; 17068c2ecf20Sopenharmony_ci pkt->hdr.dest_port = 0; 17078c2ecf20Sopenharmony_ci pkt->hdr.token = hw_block_id; 17088c2ecf20Sopenharmony_ci pkt->hdr.opcode = AFE_CMD_REMOTE_LPASS_CORE_HW_VOTE_REQUEST; 17098c2ecf20Sopenharmony_ci vote_cfg->hw_block_id = hw_block_id; 17108c2ecf20Sopenharmony_ci strlcpy(vote_cfg->client_name, client_name, 17118c2ecf20Sopenharmony_ci sizeof(vote_cfg->client_name)); 17128c2ecf20Sopenharmony_ci 17138c2ecf20Sopenharmony_ci ret = afe_apr_send_pkt(afe, pkt, NULL, 17148c2ecf20Sopenharmony_ci AFE_CMD_RSP_REMOTE_LPASS_CORE_HW_VOTE_REQUEST); 17158c2ecf20Sopenharmony_ci if (ret) 17168c2ecf20Sopenharmony_ci dev_err(afe->dev, "AFE failed to vote (%d)\n", hw_block_id); 17178c2ecf20Sopenharmony_ci 17188c2ecf20Sopenharmony_ci 17198c2ecf20Sopenharmony_ci kfree(pkt); 17208c2ecf20Sopenharmony_ci return ret; 17218c2ecf20Sopenharmony_ci} 17228c2ecf20Sopenharmony_ciEXPORT_SYMBOL(q6afe_vote_lpass_core_hw); 17238c2ecf20Sopenharmony_ci 17248c2ecf20Sopenharmony_cistatic int q6afe_probe(struct apr_device *adev) 17258c2ecf20Sopenharmony_ci{ 17268c2ecf20Sopenharmony_ci struct q6afe *afe; 17278c2ecf20Sopenharmony_ci struct device *dev = &adev->dev; 17288c2ecf20Sopenharmony_ci 17298c2ecf20Sopenharmony_ci afe = devm_kzalloc(dev, sizeof(*afe), GFP_KERNEL); 17308c2ecf20Sopenharmony_ci if (!afe) 17318c2ecf20Sopenharmony_ci return -ENOMEM; 17328c2ecf20Sopenharmony_ci 17338c2ecf20Sopenharmony_ci q6core_get_svc_api_info(adev->svc_id, &afe->ainfo); 17348c2ecf20Sopenharmony_ci afe->apr = adev; 17358c2ecf20Sopenharmony_ci mutex_init(&afe->lock); 17368c2ecf20Sopenharmony_ci init_waitqueue_head(&afe->wait); 17378c2ecf20Sopenharmony_ci afe->dev = dev; 17388c2ecf20Sopenharmony_ci INIT_LIST_HEAD(&afe->port_list); 17398c2ecf20Sopenharmony_ci spin_lock_init(&afe->port_list_lock); 17408c2ecf20Sopenharmony_ci 17418c2ecf20Sopenharmony_ci dev_set_drvdata(dev, afe); 17428c2ecf20Sopenharmony_ci 17438c2ecf20Sopenharmony_ci return of_platform_populate(dev->of_node, NULL, NULL, dev); 17448c2ecf20Sopenharmony_ci} 17458c2ecf20Sopenharmony_ci 17468c2ecf20Sopenharmony_cistatic int q6afe_remove(struct apr_device *adev) 17478c2ecf20Sopenharmony_ci{ 17488c2ecf20Sopenharmony_ci of_platform_depopulate(&adev->dev); 17498c2ecf20Sopenharmony_ci 17508c2ecf20Sopenharmony_ci return 0; 17518c2ecf20Sopenharmony_ci} 17528c2ecf20Sopenharmony_ci 17538c2ecf20Sopenharmony_ci#ifdef CONFIG_OF 17548c2ecf20Sopenharmony_cistatic const struct of_device_id q6afe_device_id[] = { 17558c2ecf20Sopenharmony_ci { .compatible = "qcom,q6afe" }, 17568c2ecf20Sopenharmony_ci {}, 17578c2ecf20Sopenharmony_ci}; 17588c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, q6afe_device_id); 17598c2ecf20Sopenharmony_ci#endif 17608c2ecf20Sopenharmony_ci 17618c2ecf20Sopenharmony_cistatic struct apr_driver qcom_q6afe_driver = { 17628c2ecf20Sopenharmony_ci .probe = q6afe_probe, 17638c2ecf20Sopenharmony_ci .remove = q6afe_remove, 17648c2ecf20Sopenharmony_ci .callback = q6afe_callback, 17658c2ecf20Sopenharmony_ci .driver = { 17668c2ecf20Sopenharmony_ci .name = "qcom-q6afe", 17678c2ecf20Sopenharmony_ci .of_match_table = of_match_ptr(q6afe_device_id), 17688c2ecf20Sopenharmony_ci 17698c2ecf20Sopenharmony_ci }, 17708c2ecf20Sopenharmony_ci}; 17718c2ecf20Sopenharmony_ci 17728c2ecf20Sopenharmony_cimodule_apr_driver(qcom_q6afe_driver); 17738c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Q6 Audio Front End"); 17748c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2"); 1775