18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Mediatek 8173 ALSA SoC AFE platform driver 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (c) 2015 MediaTek Inc. 68c2ecf20Sopenharmony_ci * Author: Koro Chen <koro.chen@mediatek.com> 78c2ecf20Sopenharmony_ci * Sascha Hauer <s.hauer@pengutronix.de> 88c2ecf20Sopenharmony_ci * Hidalgo Huang <hidalgo.huang@mediatek.com> 98c2ecf20Sopenharmony_ci * Ir Lian <ir.lian@mediatek.com> 108c2ecf20Sopenharmony_ci */ 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#include <linux/delay.h> 138c2ecf20Sopenharmony_ci#include <linux/module.h> 148c2ecf20Sopenharmony_ci#include <linux/of.h> 158c2ecf20Sopenharmony_ci#include <linux/of_address.h> 168c2ecf20Sopenharmony_ci#include <linux/dma-mapping.h> 178c2ecf20Sopenharmony_ci#include <linux/pm_runtime.h> 188c2ecf20Sopenharmony_ci#include <sound/soc.h> 198c2ecf20Sopenharmony_ci#include "mt8173-afe-common.h" 208c2ecf20Sopenharmony_ci#include "../common/mtk-base-afe.h" 218c2ecf20Sopenharmony_ci#include "../common/mtk-afe-platform-driver.h" 228c2ecf20Sopenharmony_ci#include "../common/mtk-afe-fe-dai.h" 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci/***************************************************************************** 258c2ecf20Sopenharmony_ci * R E G I S T E R D E F I N I T I O N 268c2ecf20Sopenharmony_ci *****************************************************************************/ 278c2ecf20Sopenharmony_ci#define AUDIO_TOP_CON0 0x0000 288c2ecf20Sopenharmony_ci#define AUDIO_TOP_CON1 0x0004 298c2ecf20Sopenharmony_ci#define AFE_DAC_CON0 0x0010 308c2ecf20Sopenharmony_ci#define AFE_DAC_CON1 0x0014 318c2ecf20Sopenharmony_ci#define AFE_I2S_CON1 0x0034 328c2ecf20Sopenharmony_ci#define AFE_I2S_CON2 0x0038 338c2ecf20Sopenharmony_ci#define AFE_CONN_24BIT 0x006c 348c2ecf20Sopenharmony_ci#define AFE_MEMIF_MSB 0x00cc 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci#define AFE_CONN1 0x0024 378c2ecf20Sopenharmony_ci#define AFE_CONN2 0x0028 388c2ecf20Sopenharmony_ci#define AFE_CONN3 0x002c 398c2ecf20Sopenharmony_ci#define AFE_CONN7 0x0460 408c2ecf20Sopenharmony_ci#define AFE_CONN8 0x0464 418c2ecf20Sopenharmony_ci#define AFE_HDMI_CONN0 0x0390 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci/* Memory interface */ 448c2ecf20Sopenharmony_ci#define AFE_DL1_BASE 0x0040 458c2ecf20Sopenharmony_ci#define AFE_DL1_CUR 0x0044 468c2ecf20Sopenharmony_ci#define AFE_DL1_END 0x0048 478c2ecf20Sopenharmony_ci#define AFE_DL2_BASE 0x0050 488c2ecf20Sopenharmony_ci#define AFE_DL2_CUR 0x0054 498c2ecf20Sopenharmony_ci#define AFE_AWB_BASE 0x0070 508c2ecf20Sopenharmony_ci#define AFE_AWB_CUR 0x007c 518c2ecf20Sopenharmony_ci#define AFE_VUL_BASE 0x0080 528c2ecf20Sopenharmony_ci#define AFE_VUL_CUR 0x008c 538c2ecf20Sopenharmony_ci#define AFE_VUL_END 0x0088 548c2ecf20Sopenharmony_ci#define AFE_DAI_BASE 0x0090 558c2ecf20Sopenharmony_ci#define AFE_DAI_CUR 0x009c 568c2ecf20Sopenharmony_ci#define AFE_MOD_PCM_BASE 0x0330 578c2ecf20Sopenharmony_ci#define AFE_MOD_PCM_CUR 0x033c 588c2ecf20Sopenharmony_ci#define AFE_HDMI_OUT_BASE 0x0374 598c2ecf20Sopenharmony_ci#define AFE_HDMI_OUT_CUR 0x0378 608c2ecf20Sopenharmony_ci#define AFE_HDMI_OUT_END 0x037c 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci#define AFE_ADDA_TOP_CON0 0x0120 638c2ecf20Sopenharmony_ci#define AFE_ADDA2_TOP_CON0 0x0600 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci#define AFE_HDMI_OUT_CON0 0x0370 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci#define AFE_IRQ_MCU_CON 0x03a0 688c2ecf20Sopenharmony_ci#define AFE_IRQ_STATUS 0x03a4 698c2ecf20Sopenharmony_ci#define AFE_IRQ_CLR 0x03a8 708c2ecf20Sopenharmony_ci#define AFE_IRQ_CNT1 0x03ac 718c2ecf20Sopenharmony_ci#define AFE_IRQ_CNT2 0x03b0 728c2ecf20Sopenharmony_ci#define AFE_IRQ_MCU_EN 0x03b4 738c2ecf20Sopenharmony_ci#define AFE_IRQ_CNT5 0x03bc 748c2ecf20Sopenharmony_ci#define AFE_IRQ_CNT7 0x03dc 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci#define AFE_TDM_CON1 0x0548 778c2ecf20Sopenharmony_ci#define AFE_TDM_CON2 0x054c 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci#define AFE_IRQ_STATUS_BITS 0xff 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci/* AUDIO_TOP_CON0 (0x0000) */ 828c2ecf20Sopenharmony_ci#define AUD_TCON0_PDN_SPDF (0x1 << 21) 838c2ecf20Sopenharmony_ci#define AUD_TCON0_PDN_HDMI (0x1 << 20) 848c2ecf20Sopenharmony_ci#define AUD_TCON0_PDN_24M (0x1 << 9) 858c2ecf20Sopenharmony_ci#define AUD_TCON0_PDN_22M (0x1 << 8) 868c2ecf20Sopenharmony_ci#define AUD_TCON0_PDN_AFE (0x1 << 2) 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci/* AFE_I2S_CON1 (0x0034) */ 898c2ecf20Sopenharmony_ci#define AFE_I2S_CON1_LOW_JITTER_CLK (0x1 << 12) 908c2ecf20Sopenharmony_ci#define AFE_I2S_CON1_RATE(x) (((x) & 0xf) << 8) 918c2ecf20Sopenharmony_ci#define AFE_I2S_CON1_FORMAT_I2S (0x1 << 3) 928c2ecf20Sopenharmony_ci#define AFE_I2S_CON1_EN (0x1 << 0) 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci/* AFE_I2S_CON2 (0x0038) */ 958c2ecf20Sopenharmony_ci#define AFE_I2S_CON2_LOW_JITTER_CLK (0x1 << 12) 968c2ecf20Sopenharmony_ci#define AFE_I2S_CON2_RATE(x) (((x) & 0xf) << 8) 978c2ecf20Sopenharmony_ci#define AFE_I2S_CON2_FORMAT_I2S (0x1 << 3) 988c2ecf20Sopenharmony_ci#define AFE_I2S_CON2_EN (0x1 << 0) 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci/* AFE_CONN_24BIT (0x006c) */ 1018c2ecf20Sopenharmony_ci#define AFE_CONN_24BIT_O04 (0x1 << 4) 1028c2ecf20Sopenharmony_ci#define AFE_CONN_24BIT_O03 (0x1 << 3) 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci/* AFE_HDMI_CONN0 (0x0390) */ 1058c2ecf20Sopenharmony_ci#define AFE_HDMI_CONN0_O37_I37 (0x7 << 21) 1068c2ecf20Sopenharmony_ci#define AFE_HDMI_CONN0_O36_I36 (0x6 << 18) 1078c2ecf20Sopenharmony_ci#define AFE_HDMI_CONN0_O35_I33 (0x3 << 15) 1088c2ecf20Sopenharmony_ci#define AFE_HDMI_CONN0_O34_I32 (0x2 << 12) 1098c2ecf20Sopenharmony_ci#define AFE_HDMI_CONN0_O33_I35 (0x5 << 9) 1108c2ecf20Sopenharmony_ci#define AFE_HDMI_CONN0_O32_I34 (0x4 << 6) 1118c2ecf20Sopenharmony_ci#define AFE_HDMI_CONN0_O31_I31 (0x1 << 3) 1128c2ecf20Sopenharmony_ci#define AFE_HDMI_CONN0_O30_I30 (0x0 << 0) 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci/* AFE_TDM_CON1 (0x0548) */ 1158c2ecf20Sopenharmony_ci#define AFE_TDM_CON1_LRCK_WIDTH(x) (((x) - 1) << 24) 1168c2ecf20Sopenharmony_ci#define AFE_TDM_CON1_32_BCK_CYCLES (0x2 << 12) 1178c2ecf20Sopenharmony_ci#define AFE_TDM_CON1_WLEN_32BIT (0x2 << 8) 1188c2ecf20Sopenharmony_ci#define AFE_TDM_CON1_MSB_ALIGNED (0x1 << 4) 1198c2ecf20Sopenharmony_ci#define AFE_TDM_CON1_1_BCK_DELAY (0x1 << 3) 1208c2ecf20Sopenharmony_ci#define AFE_TDM_CON1_LRCK_INV (0x1 << 2) 1218c2ecf20Sopenharmony_ci#define AFE_TDM_CON1_BCK_INV (0x1 << 1) 1228c2ecf20Sopenharmony_ci#define AFE_TDM_CON1_EN (0x1 << 0) 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_cienum afe_tdm_ch_start { 1258c2ecf20Sopenharmony_ci AFE_TDM_CH_START_O30_O31 = 0, 1268c2ecf20Sopenharmony_ci AFE_TDM_CH_START_O32_O33, 1278c2ecf20Sopenharmony_ci AFE_TDM_CH_START_O34_O35, 1288c2ecf20Sopenharmony_ci AFE_TDM_CH_START_O36_O37, 1298c2ecf20Sopenharmony_ci AFE_TDM_CH_ZERO, 1308c2ecf20Sopenharmony_ci}; 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_cistatic const unsigned int mt8173_afe_backup_list[] = { 1338c2ecf20Sopenharmony_ci AUDIO_TOP_CON0, 1348c2ecf20Sopenharmony_ci AFE_CONN1, 1358c2ecf20Sopenharmony_ci AFE_CONN2, 1368c2ecf20Sopenharmony_ci AFE_CONN7, 1378c2ecf20Sopenharmony_ci AFE_CONN8, 1388c2ecf20Sopenharmony_ci AFE_DAC_CON1, 1398c2ecf20Sopenharmony_ci AFE_DL1_BASE, 1408c2ecf20Sopenharmony_ci AFE_DL1_END, 1418c2ecf20Sopenharmony_ci AFE_VUL_BASE, 1428c2ecf20Sopenharmony_ci AFE_VUL_END, 1438c2ecf20Sopenharmony_ci AFE_HDMI_OUT_BASE, 1448c2ecf20Sopenharmony_ci AFE_HDMI_OUT_END, 1458c2ecf20Sopenharmony_ci AFE_HDMI_CONN0, 1468c2ecf20Sopenharmony_ci AFE_DAC_CON0, 1478c2ecf20Sopenharmony_ci}; 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_cistruct mt8173_afe_private { 1508c2ecf20Sopenharmony_ci struct clk *clocks[MT8173_CLK_NUM]; 1518c2ecf20Sopenharmony_ci}; 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_cistatic const struct snd_pcm_hardware mt8173_afe_hardware = { 1548c2ecf20Sopenharmony_ci .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 1558c2ecf20Sopenharmony_ci SNDRV_PCM_INFO_MMAP_VALID), 1568c2ecf20Sopenharmony_ci .buffer_bytes_max = 256 * 1024, 1578c2ecf20Sopenharmony_ci .period_bytes_min = 512, 1588c2ecf20Sopenharmony_ci .period_bytes_max = 128 * 1024, 1598c2ecf20Sopenharmony_ci .periods_min = 2, 1608c2ecf20Sopenharmony_ci .periods_max = 256, 1618c2ecf20Sopenharmony_ci .fifo_size = 0, 1628c2ecf20Sopenharmony_ci}; 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_cistruct mt8173_afe_rate { 1658c2ecf20Sopenharmony_ci unsigned int rate; 1668c2ecf20Sopenharmony_ci unsigned int regvalue; 1678c2ecf20Sopenharmony_ci}; 1688c2ecf20Sopenharmony_ci 1698c2ecf20Sopenharmony_cistatic const struct mt8173_afe_rate mt8173_afe_i2s_rates[] = { 1708c2ecf20Sopenharmony_ci { .rate = 8000, .regvalue = 0 }, 1718c2ecf20Sopenharmony_ci { .rate = 11025, .regvalue = 1 }, 1728c2ecf20Sopenharmony_ci { .rate = 12000, .regvalue = 2 }, 1738c2ecf20Sopenharmony_ci { .rate = 16000, .regvalue = 4 }, 1748c2ecf20Sopenharmony_ci { .rate = 22050, .regvalue = 5 }, 1758c2ecf20Sopenharmony_ci { .rate = 24000, .regvalue = 6 }, 1768c2ecf20Sopenharmony_ci { .rate = 32000, .regvalue = 8 }, 1778c2ecf20Sopenharmony_ci { .rate = 44100, .regvalue = 9 }, 1788c2ecf20Sopenharmony_ci { .rate = 48000, .regvalue = 10 }, 1798c2ecf20Sopenharmony_ci { .rate = 88000, .regvalue = 11 }, 1808c2ecf20Sopenharmony_ci { .rate = 96000, .regvalue = 12 }, 1818c2ecf20Sopenharmony_ci { .rate = 174000, .regvalue = 13 }, 1828c2ecf20Sopenharmony_ci { .rate = 192000, .regvalue = 14 }, 1838c2ecf20Sopenharmony_ci}; 1848c2ecf20Sopenharmony_ci 1858c2ecf20Sopenharmony_cistatic int mt8173_afe_i2s_fs(unsigned int sample_rate) 1868c2ecf20Sopenharmony_ci{ 1878c2ecf20Sopenharmony_ci int i; 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(mt8173_afe_i2s_rates); i++) 1908c2ecf20Sopenharmony_ci if (mt8173_afe_i2s_rates[i].rate == sample_rate) 1918c2ecf20Sopenharmony_ci return mt8173_afe_i2s_rates[i].regvalue; 1928c2ecf20Sopenharmony_ci 1938c2ecf20Sopenharmony_ci return -EINVAL; 1948c2ecf20Sopenharmony_ci} 1958c2ecf20Sopenharmony_ci 1968c2ecf20Sopenharmony_cistatic int mt8173_afe_set_i2s(struct mtk_base_afe *afe, unsigned int rate) 1978c2ecf20Sopenharmony_ci{ 1988c2ecf20Sopenharmony_ci unsigned int val; 1998c2ecf20Sopenharmony_ci int fs = mt8173_afe_i2s_fs(rate); 2008c2ecf20Sopenharmony_ci 2018c2ecf20Sopenharmony_ci if (fs < 0) 2028c2ecf20Sopenharmony_ci return -EINVAL; 2038c2ecf20Sopenharmony_ci 2048c2ecf20Sopenharmony_ci /* from external ADC */ 2058c2ecf20Sopenharmony_ci regmap_update_bits(afe->regmap, AFE_ADDA_TOP_CON0, 0x1, 0x1); 2068c2ecf20Sopenharmony_ci regmap_update_bits(afe->regmap, AFE_ADDA2_TOP_CON0, 0x1, 0x1); 2078c2ecf20Sopenharmony_ci 2088c2ecf20Sopenharmony_ci /* set input */ 2098c2ecf20Sopenharmony_ci val = AFE_I2S_CON2_LOW_JITTER_CLK | 2108c2ecf20Sopenharmony_ci AFE_I2S_CON2_RATE(fs) | 2118c2ecf20Sopenharmony_ci AFE_I2S_CON2_FORMAT_I2S; 2128c2ecf20Sopenharmony_ci 2138c2ecf20Sopenharmony_ci regmap_update_bits(afe->regmap, AFE_I2S_CON2, ~AFE_I2S_CON2_EN, val); 2148c2ecf20Sopenharmony_ci 2158c2ecf20Sopenharmony_ci /* set output */ 2168c2ecf20Sopenharmony_ci val = AFE_I2S_CON1_LOW_JITTER_CLK | 2178c2ecf20Sopenharmony_ci AFE_I2S_CON1_RATE(fs) | 2188c2ecf20Sopenharmony_ci AFE_I2S_CON1_FORMAT_I2S; 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_ci regmap_update_bits(afe->regmap, AFE_I2S_CON1, ~AFE_I2S_CON1_EN, val); 2218c2ecf20Sopenharmony_ci return 0; 2228c2ecf20Sopenharmony_ci} 2238c2ecf20Sopenharmony_ci 2248c2ecf20Sopenharmony_cistatic void mt8173_afe_set_i2s_enable(struct mtk_base_afe *afe, bool enable) 2258c2ecf20Sopenharmony_ci{ 2268c2ecf20Sopenharmony_ci unsigned int val; 2278c2ecf20Sopenharmony_ci 2288c2ecf20Sopenharmony_ci regmap_read(afe->regmap, AFE_I2S_CON2, &val); 2298c2ecf20Sopenharmony_ci if (!!(val & AFE_I2S_CON2_EN) == enable) 2308c2ecf20Sopenharmony_ci return; 2318c2ecf20Sopenharmony_ci 2328c2ecf20Sopenharmony_ci /* input */ 2338c2ecf20Sopenharmony_ci regmap_update_bits(afe->regmap, AFE_I2S_CON2, 0x1, enable); 2348c2ecf20Sopenharmony_ci 2358c2ecf20Sopenharmony_ci /* output */ 2368c2ecf20Sopenharmony_ci regmap_update_bits(afe->regmap, AFE_I2S_CON1, 0x1, enable); 2378c2ecf20Sopenharmony_ci} 2388c2ecf20Sopenharmony_ci 2398c2ecf20Sopenharmony_cistatic int mt8173_afe_dais_enable_clks(struct mtk_base_afe *afe, 2408c2ecf20Sopenharmony_ci struct clk *m_ck, struct clk *b_ck) 2418c2ecf20Sopenharmony_ci{ 2428c2ecf20Sopenharmony_ci int ret; 2438c2ecf20Sopenharmony_ci 2448c2ecf20Sopenharmony_ci if (m_ck) { 2458c2ecf20Sopenharmony_ci ret = clk_prepare_enable(m_ck); 2468c2ecf20Sopenharmony_ci if (ret) { 2478c2ecf20Sopenharmony_ci dev_err(afe->dev, "Failed to enable m_ck\n"); 2488c2ecf20Sopenharmony_ci return ret; 2498c2ecf20Sopenharmony_ci } 2508c2ecf20Sopenharmony_ci } 2518c2ecf20Sopenharmony_ci 2528c2ecf20Sopenharmony_ci if (b_ck) { 2538c2ecf20Sopenharmony_ci ret = clk_prepare_enable(b_ck); 2548c2ecf20Sopenharmony_ci if (ret) { 2558c2ecf20Sopenharmony_ci dev_err(afe->dev, "Failed to enable b_ck\n"); 2568c2ecf20Sopenharmony_ci return ret; 2578c2ecf20Sopenharmony_ci } 2588c2ecf20Sopenharmony_ci } 2598c2ecf20Sopenharmony_ci return 0; 2608c2ecf20Sopenharmony_ci} 2618c2ecf20Sopenharmony_ci 2628c2ecf20Sopenharmony_cistatic int mt8173_afe_dais_set_clks(struct mtk_base_afe *afe, 2638c2ecf20Sopenharmony_ci struct clk *m_ck, unsigned int mck_rate, 2648c2ecf20Sopenharmony_ci struct clk *b_ck, unsigned int bck_rate) 2658c2ecf20Sopenharmony_ci{ 2668c2ecf20Sopenharmony_ci int ret; 2678c2ecf20Sopenharmony_ci 2688c2ecf20Sopenharmony_ci if (m_ck) { 2698c2ecf20Sopenharmony_ci ret = clk_set_rate(m_ck, mck_rate); 2708c2ecf20Sopenharmony_ci if (ret) { 2718c2ecf20Sopenharmony_ci dev_err(afe->dev, "Failed to set m_ck rate\n"); 2728c2ecf20Sopenharmony_ci return ret; 2738c2ecf20Sopenharmony_ci } 2748c2ecf20Sopenharmony_ci } 2758c2ecf20Sopenharmony_ci 2768c2ecf20Sopenharmony_ci if (b_ck) { 2778c2ecf20Sopenharmony_ci ret = clk_set_rate(b_ck, bck_rate); 2788c2ecf20Sopenharmony_ci if (ret) { 2798c2ecf20Sopenharmony_ci dev_err(afe->dev, "Failed to set b_ck rate\n"); 2808c2ecf20Sopenharmony_ci return ret; 2818c2ecf20Sopenharmony_ci } 2828c2ecf20Sopenharmony_ci } 2838c2ecf20Sopenharmony_ci return 0; 2848c2ecf20Sopenharmony_ci} 2858c2ecf20Sopenharmony_ci 2868c2ecf20Sopenharmony_cistatic void mt8173_afe_dais_disable_clks(struct mtk_base_afe *afe, 2878c2ecf20Sopenharmony_ci struct clk *m_ck, struct clk *b_ck) 2888c2ecf20Sopenharmony_ci{ 2898c2ecf20Sopenharmony_ci if (m_ck) 2908c2ecf20Sopenharmony_ci clk_disable_unprepare(m_ck); 2918c2ecf20Sopenharmony_ci if (b_ck) 2928c2ecf20Sopenharmony_ci clk_disable_unprepare(b_ck); 2938c2ecf20Sopenharmony_ci} 2948c2ecf20Sopenharmony_ci 2958c2ecf20Sopenharmony_cistatic int mt8173_afe_i2s_startup(struct snd_pcm_substream *substream, 2968c2ecf20Sopenharmony_ci struct snd_soc_dai *dai) 2978c2ecf20Sopenharmony_ci{ 2988c2ecf20Sopenharmony_ci struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai); 2998c2ecf20Sopenharmony_ci 3008c2ecf20Sopenharmony_ci if (snd_soc_dai_active(dai)) 3018c2ecf20Sopenharmony_ci return 0; 3028c2ecf20Sopenharmony_ci 3038c2ecf20Sopenharmony_ci regmap_update_bits(afe->regmap, AUDIO_TOP_CON0, 3048c2ecf20Sopenharmony_ci AUD_TCON0_PDN_22M | AUD_TCON0_PDN_24M, 0); 3058c2ecf20Sopenharmony_ci return 0; 3068c2ecf20Sopenharmony_ci} 3078c2ecf20Sopenharmony_ci 3088c2ecf20Sopenharmony_cistatic void mt8173_afe_i2s_shutdown(struct snd_pcm_substream *substream, 3098c2ecf20Sopenharmony_ci struct snd_soc_dai *dai) 3108c2ecf20Sopenharmony_ci{ 3118c2ecf20Sopenharmony_ci struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai); 3128c2ecf20Sopenharmony_ci 3138c2ecf20Sopenharmony_ci if (snd_soc_dai_active(dai)) 3148c2ecf20Sopenharmony_ci return; 3158c2ecf20Sopenharmony_ci 3168c2ecf20Sopenharmony_ci mt8173_afe_set_i2s_enable(afe, false); 3178c2ecf20Sopenharmony_ci regmap_update_bits(afe->regmap, AUDIO_TOP_CON0, 3188c2ecf20Sopenharmony_ci AUD_TCON0_PDN_22M | AUD_TCON0_PDN_24M, 3198c2ecf20Sopenharmony_ci AUD_TCON0_PDN_22M | AUD_TCON0_PDN_24M); 3208c2ecf20Sopenharmony_ci} 3218c2ecf20Sopenharmony_ci 3228c2ecf20Sopenharmony_cistatic int mt8173_afe_i2s_prepare(struct snd_pcm_substream *substream, 3238c2ecf20Sopenharmony_ci struct snd_soc_dai *dai) 3248c2ecf20Sopenharmony_ci{ 3258c2ecf20Sopenharmony_ci struct snd_pcm_runtime * const runtime = substream->runtime; 3268c2ecf20Sopenharmony_ci struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai); 3278c2ecf20Sopenharmony_ci struct mt8173_afe_private *afe_priv = afe->platform_priv; 3288c2ecf20Sopenharmony_ci int ret; 3298c2ecf20Sopenharmony_ci 3308c2ecf20Sopenharmony_ci mt8173_afe_dais_set_clks(afe, afe_priv->clocks[MT8173_CLK_I2S1_M], 3318c2ecf20Sopenharmony_ci runtime->rate * 256, NULL, 0); 3328c2ecf20Sopenharmony_ci mt8173_afe_dais_set_clks(afe, afe_priv->clocks[MT8173_CLK_I2S2_M], 3338c2ecf20Sopenharmony_ci runtime->rate * 256, NULL, 0); 3348c2ecf20Sopenharmony_ci /* config I2S */ 3358c2ecf20Sopenharmony_ci ret = mt8173_afe_set_i2s(afe, substream->runtime->rate); 3368c2ecf20Sopenharmony_ci if (ret) 3378c2ecf20Sopenharmony_ci return ret; 3388c2ecf20Sopenharmony_ci 3398c2ecf20Sopenharmony_ci mt8173_afe_set_i2s_enable(afe, true); 3408c2ecf20Sopenharmony_ci 3418c2ecf20Sopenharmony_ci return 0; 3428c2ecf20Sopenharmony_ci} 3438c2ecf20Sopenharmony_ci 3448c2ecf20Sopenharmony_cistatic int mt8173_afe_hdmi_startup(struct snd_pcm_substream *substream, 3458c2ecf20Sopenharmony_ci struct snd_soc_dai *dai) 3468c2ecf20Sopenharmony_ci{ 3478c2ecf20Sopenharmony_ci struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai); 3488c2ecf20Sopenharmony_ci struct mt8173_afe_private *afe_priv = afe->platform_priv; 3498c2ecf20Sopenharmony_ci 3508c2ecf20Sopenharmony_ci if (snd_soc_dai_active(dai)) 3518c2ecf20Sopenharmony_ci return 0; 3528c2ecf20Sopenharmony_ci 3538c2ecf20Sopenharmony_ci mt8173_afe_dais_enable_clks(afe, afe_priv->clocks[MT8173_CLK_I2S3_M], 3548c2ecf20Sopenharmony_ci afe_priv->clocks[MT8173_CLK_I2S3_B]); 3558c2ecf20Sopenharmony_ci return 0; 3568c2ecf20Sopenharmony_ci} 3578c2ecf20Sopenharmony_ci 3588c2ecf20Sopenharmony_cistatic void mt8173_afe_hdmi_shutdown(struct snd_pcm_substream *substream, 3598c2ecf20Sopenharmony_ci struct snd_soc_dai *dai) 3608c2ecf20Sopenharmony_ci{ 3618c2ecf20Sopenharmony_ci struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai); 3628c2ecf20Sopenharmony_ci struct mt8173_afe_private *afe_priv = afe->platform_priv; 3638c2ecf20Sopenharmony_ci 3648c2ecf20Sopenharmony_ci if (snd_soc_dai_active(dai)) 3658c2ecf20Sopenharmony_ci return; 3668c2ecf20Sopenharmony_ci 3678c2ecf20Sopenharmony_ci mt8173_afe_dais_disable_clks(afe, afe_priv->clocks[MT8173_CLK_I2S3_M], 3688c2ecf20Sopenharmony_ci afe_priv->clocks[MT8173_CLK_I2S3_B]); 3698c2ecf20Sopenharmony_ci} 3708c2ecf20Sopenharmony_ci 3718c2ecf20Sopenharmony_cistatic int mt8173_afe_hdmi_prepare(struct snd_pcm_substream *substream, 3728c2ecf20Sopenharmony_ci struct snd_soc_dai *dai) 3738c2ecf20Sopenharmony_ci{ 3748c2ecf20Sopenharmony_ci struct snd_pcm_runtime * const runtime = substream->runtime; 3758c2ecf20Sopenharmony_ci struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai); 3768c2ecf20Sopenharmony_ci struct mt8173_afe_private *afe_priv = afe->platform_priv; 3778c2ecf20Sopenharmony_ci 3788c2ecf20Sopenharmony_ci unsigned int val; 3798c2ecf20Sopenharmony_ci 3808c2ecf20Sopenharmony_ci mt8173_afe_dais_set_clks(afe, afe_priv->clocks[MT8173_CLK_I2S3_M], 3818c2ecf20Sopenharmony_ci runtime->rate * 128, 3828c2ecf20Sopenharmony_ci afe_priv->clocks[MT8173_CLK_I2S3_B], 3838c2ecf20Sopenharmony_ci runtime->rate * runtime->channels * 32); 3848c2ecf20Sopenharmony_ci 3858c2ecf20Sopenharmony_ci val = AFE_TDM_CON1_BCK_INV | 3868c2ecf20Sopenharmony_ci AFE_TDM_CON1_LRCK_INV | 3878c2ecf20Sopenharmony_ci AFE_TDM_CON1_1_BCK_DELAY | 3888c2ecf20Sopenharmony_ci AFE_TDM_CON1_MSB_ALIGNED | /* I2S mode */ 3898c2ecf20Sopenharmony_ci AFE_TDM_CON1_WLEN_32BIT | 3908c2ecf20Sopenharmony_ci AFE_TDM_CON1_32_BCK_CYCLES | 3918c2ecf20Sopenharmony_ci AFE_TDM_CON1_LRCK_WIDTH(32); 3928c2ecf20Sopenharmony_ci regmap_update_bits(afe->regmap, AFE_TDM_CON1, ~AFE_TDM_CON1_EN, val); 3938c2ecf20Sopenharmony_ci 3948c2ecf20Sopenharmony_ci /* set tdm2 config */ 3958c2ecf20Sopenharmony_ci switch (runtime->channels) { 3968c2ecf20Sopenharmony_ci case 1: 3978c2ecf20Sopenharmony_ci case 2: 3988c2ecf20Sopenharmony_ci val = AFE_TDM_CH_START_O30_O31; 3998c2ecf20Sopenharmony_ci val |= (AFE_TDM_CH_ZERO << 4); 4008c2ecf20Sopenharmony_ci val |= (AFE_TDM_CH_ZERO << 8); 4018c2ecf20Sopenharmony_ci val |= (AFE_TDM_CH_ZERO << 12); 4028c2ecf20Sopenharmony_ci break; 4038c2ecf20Sopenharmony_ci case 3: 4048c2ecf20Sopenharmony_ci case 4: 4058c2ecf20Sopenharmony_ci val = AFE_TDM_CH_START_O30_O31; 4068c2ecf20Sopenharmony_ci val |= (AFE_TDM_CH_START_O32_O33 << 4); 4078c2ecf20Sopenharmony_ci val |= (AFE_TDM_CH_ZERO << 8); 4088c2ecf20Sopenharmony_ci val |= (AFE_TDM_CH_ZERO << 12); 4098c2ecf20Sopenharmony_ci break; 4108c2ecf20Sopenharmony_ci case 5: 4118c2ecf20Sopenharmony_ci case 6: 4128c2ecf20Sopenharmony_ci val = AFE_TDM_CH_START_O30_O31; 4138c2ecf20Sopenharmony_ci val |= (AFE_TDM_CH_START_O32_O33 << 4); 4148c2ecf20Sopenharmony_ci val |= (AFE_TDM_CH_START_O34_O35 << 8); 4158c2ecf20Sopenharmony_ci val |= (AFE_TDM_CH_ZERO << 12); 4168c2ecf20Sopenharmony_ci break; 4178c2ecf20Sopenharmony_ci case 7: 4188c2ecf20Sopenharmony_ci case 8: 4198c2ecf20Sopenharmony_ci val = AFE_TDM_CH_START_O30_O31; 4208c2ecf20Sopenharmony_ci val |= (AFE_TDM_CH_START_O32_O33 << 4); 4218c2ecf20Sopenharmony_ci val |= (AFE_TDM_CH_START_O34_O35 << 8); 4228c2ecf20Sopenharmony_ci val |= (AFE_TDM_CH_START_O36_O37 << 12); 4238c2ecf20Sopenharmony_ci break; 4248c2ecf20Sopenharmony_ci default: 4258c2ecf20Sopenharmony_ci val = 0; 4268c2ecf20Sopenharmony_ci } 4278c2ecf20Sopenharmony_ci regmap_update_bits(afe->regmap, AFE_TDM_CON2, 0x0000ffff, val); 4288c2ecf20Sopenharmony_ci 4298c2ecf20Sopenharmony_ci regmap_update_bits(afe->regmap, AFE_HDMI_OUT_CON0, 4308c2ecf20Sopenharmony_ci 0x000000f0, runtime->channels << 4); 4318c2ecf20Sopenharmony_ci return 0; 4328c2ecf20Sopenharmony_ci} 4338c2ecf20Sopenharmony_ci 4348c2ecf20Sopenharmony_cistatic int mt8173_afe_hdmi_trigger(struct snd_pcm_substream *substream, int cmd, 4358c2ecf20Sopenharmony_ci struct snd_soc_dai *dai) 4368c2ecf20Sopenharmony_ci{ 4378c2ecf20Sopenharmony_ci struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai); 4388c2ecf20Sopenharmony_ci 4398c2ecf20Sopenharmony_ci dev_info(afe->dev, "%s cmd=%d %s\n", __func__, cmd, dai->name); 4408c2ecf20Sopenharmony_ci 4418c2ecf20Sopenharmony_ci switch (cmd) { 4428c2ecf20Sopenharmony_ci case SNDRV_PCM_TRIGGER_START: 4438c2ecf20Sopenharmony_ci case SNDRV_PCM_TRIGGER_RESUME: 4448c2ecf20Sopenharmony_ci regmap_update_bits(afe->regmap, AUDIO_TOP_CON0, 4458c2ecf20Sopenharmony_ci AUD_TCON0_PDN_HDMI | AUD_TCON0_PDN_SPDF, 0); 4468c2ecf20Sopenharmony_ci 4478c2ecf20Sopenharmony_ci /* set connections: O30~O37: L/R/LS/RS/C/LFE/CH7/CH8 */ 4488c2ecf20Sopenharmony_ci regmap_write(afe->regmap, AFE_HDMI_CONN0, 4498c2ecf20Sopenharmony_ci AFE_HDMI_CONN0_O30_I30 | 4508c2ecf20Sopenharmony_ci AFE_HDMI_CONN0_O31_I31 | 4518c2ecf20Sopenharmony_ci AFE_HDMI_CONN0_O32_I34 | 4528c2ecf20Sopenharmony_ci AFE_HDMI_CONN0_O33_I35 | 4538c2ecf20Sopenharmony_ci AFE_HDMI_CONN0_O34_I32 | 4548c2ecf20Sopenharmony_ci AFE_HDMI_CONN0_O35_I33 | 4558c2ecf20Sopenharmony_ci AFE_HDMI_CONN0_O36_I36 | 4568c2ecf20Sopenharmony_ci AFE_HDMI_CONN0_O37_I37); 4578c2ecf20Sopenharmony_ci 4588c2ecf20Sopenharmony_ci /* enable Out control */ 4598c2ecf20Sopenharmony_ci regmap_update_bits(afe->regmap, AFE_HDMI_OUT_CON0, 0x1, 0x1); 4608c2ecf20Sopenharmony_ci 4618c2ecf20Sopenharmony_ci /* enable tdm */ 4628c2ecf20Sopenharmony_ci regmap_update_bits(afe->regmap, AFE_TDM_CON1, 0x1, 0x1); 4638c2ecf20Sopenharmony_ci 4648c2ecf20Sopenharmony_ci return 0; 4658c2ecf20Sopenharmony_ci case SNDRV_PCM_TRIGGER_STOP: 4668c2ecf20Sopenharmony_ci case SNDRV_PCM_TRIGGER_SUSPEND: 4678c2ecf20Sopenharmony_ci /* disable tdm */ 4688c2ecf20Sopenharmony_ci regmap_update_bits(afe->regmap, AFE_TDM_CON1, 0x1, 0); 4698c2ecf20Sopenharmony_ci 4708c2ecf20Sopenharmony_ci /* disable Out control */ 4718c2ecf20Sopenharmony_ci regmap_update_bits(afe->regmap, AFE_HDMI_OUT_CON0, 0x1, 0); 4728c2ecf20Sopenharmony_ci 4738c2ecf20Sopenharmony_ci regmap_update_bits(afe->regmap, AUDIO_TOP_CON0, 4748c2ecf20Sopenharmony_ci AUD_TCON0_PDN_HDMI | AUD_TCON0_PDN_SPDF, 4758c2ecf20Sopenharmony_ci AUD_TCON0_PDN_HDMI | AUD_TCON0_PDN_SPDF); 4768c2ecf20Sopenharmony_ci return 0; 4778c2ecf20Sopenharmony_ci default: 4788c2ecf20Sopenharmony_ci return -EINVAL; 4798c2ecf20Sopenharmony_ci } 4808c2ecf20Sopenharmony_ci} 4818c2ecf20Sopenharmony_ci 4828c2ecf20Sopenharmony_cistatic int mt8173_memif_fs(struct snd_pcm_substream *substream, 4838c2ecf20Sopenharmony_ci unsigned int rate) 4848c2ecf20Sopenharmony_ci{ 4858c2ecf20Sopenharmony_ci struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); 4868c2ecf20Sopenharmony_ci struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME); 4878c2ecf20Sopenharmony_ci struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component); 4888c2ecf20Sopenharmony_ci struct mtk_base_afe_memif *memif = &afe->memif[asoc_rtd_to_cpu(rtd, 0)->id]; 4898c2ecf20Sopenharmony_ci int fs; 4908c2ecf20Sopenharmony_ci 4918c2ecf20Sopenharmony_ci if (memif->data->id == MT8173_AFE_MEMIF_DAI || 4928c2ecf20Sopenharmony_ci memif->data->id == MT8173_AFE_MEMIF_MOD_DAI) { 4938c2ecf20Sopenharmony_ci switch (rate) { 4948c2ecf20Sopenharmony_ci case 8000: 4958c2ecf20Sopenharmony_ci fs = 0; 4968c2ecf20Sopenharmony_ci break; 4978c2ecf20Sopenharmony_ci case 16000: 4988c2ecf20Sopenharmony_ci fs = 1; 4998c2ecf20Sopenharmony_ci break; 5008c2ecf20Sopenharmony_ci case 32000: 5018c2ecf20Sopenharmony_ci fs = 2; 5028c2ecf20Sopenharmony_ci break; 5038c2ecf20Sopenharmony_ci default: 5048c2ecf20Sopenharmony_ci return -EINVAL; 5058c2ecf20Sopenharmony_ci } 5068c2ecf20Sopenharmony_ci } else { 5078c2ecf20Sopenharmony_ci fs = mt8173_afe_i2s_fs(rate); 5088c2ecf20Sopenharmony_ci } 5098c2ecf20Sopenharmony_ci return fs; 5108c2ecf20Sopenharmony_ci} 5118c2ecf20Sopenharmony_ci 5128c2ecf20Sopenharmony_cistatic int mt8173_irq_fs(struct snd_pcm_substream *substream, unsigned int rate) 5138c2ecf20Sopenharmony_ci{ 5148c2ecf20Sopenharmony_ci return mt8173_afe_i2s_fs(rate); 5158c2ecf20Sopenharmony_ci} 5168c2ecf20Sopenharmony_ci 5178c2ecf20Sopenharmony_ci/* BE DAIs */ 5188c2ecf20Sopenharmony_cistatic const struct snd_soc_dai_ops mt8173_afe_i2s_ops = { 5198c2ecf20Sopenharmony_ci .startup = mt8173_afe_i2s_startup, 5208c2ecf20Sopenharmony_ci .shutdown = mt8173_afe_i2s_shutdown, 5218c2ecf20Sopenharmony_ci .prepare = mt8173_afe_i2s_prepare, 5228c2ecf20Sopenharmony_ci}; 5238c2ecf20Sopenharmony_ci 5248c2ecf20Sopenharmony_cistatic const struct snd_soc_dai_ops mt8173_afe_hdmi_ops = { 5258c2ecf20Sopenharmony_ci .startup = mt8173_afe_hdmi_startup, 5268c2ecf20Sopenharmony_ci .shutdown = mt8173_afe_hdmi_shutdown, 5278c2ecf20Sopenharmony_ci .prepare = mt8173_afe_hdmi_prepare, 5288c2ecf20Sopenharmony_ci .trigger = mt8173_afe_hdmi_trigger, 5298c2ecf20Sopenharmony_ci}; 5308c2ecf20Sopenharmony_ci 5318c2ecf20Sopenharmony_cistatic struct snd_soc_dai_driver mt8173_afe_pcm_dais[] = { 5328c2ecf20Sopenharmony_ci /* FE DAIs: memory intefaces to CPU */ 5338c2ecf20Sopenharmony_ci { 5348c2ecf20Sopenharmony_ci .name = "DL1", /* downlink 1 */ 5358c2ecf20Sopenharmony_ci .id = MT8173_AFE_MEMIF_DL1, 5368c2ecf20Sopenharmony_ci .playback = { 5378c2ecf20Sopenharmony_ci .stream_name = "DL1", 5388c2ecf20Sopenharmony_ci .channels_min = 1, 5398c2ecf20Sopenharmony_ci .channels_max = 2, 5408c2ecf20Sopenharmony_ci .rates = SNDRV_PCM_RATE_8000_48000, 5418c2ecf20Sopenharmony_ci .formats = SNDRV_PCM_FMTBIT_S16_LE, 5428c2ecf20Sopenharmony_ci }, 5438c2ecf20Sopenharmony_ci .ops = &mtk_afe_fe_ops, 5448c2ecf20Sopenharmony_ci }, { 5458c2ecf20Sopenharmony_ci .name = "VUL", /* voice uplink */ 5468c2ecf20Sopenharmony_ci .id = MT8173_AFE_MEMIF_VUL, 5478c2ecf20Sopenharmony_ci .capture = { 5488c2ecf20Sopenharmony_ci .stream_name = "VUL", 5498c2ecf20Sopenharmony_ci .channels_min = 1, 5508c2ecf20Sopenharmony_ci .channels_max = 2, 5518c2ecf20Sopenharmony_ci .rates = SNDRV_PCM_RATE_8000_48000, 5528c2ecf20Sopenharmony_ci .formats = SNDRV_PCM_FMTBIT_S16_LE, 5538c2ecf20Sopenharmony_ci }, 5548c2ecf20Sopenharmony_ci .ops = &mtk_afe_fe_ops, 5558c2ecf20Sopenharmony_ci }, { 5568c2ecf20Sopenharmony_ci /* BE DAIs */ 5578c2ecf20Sopenharmony_ci .name = "I2S", 5588c2ecf20Sopenharmony_ci .id = MT8173_AFE_IO_I2S, 5598c2ecf20Sopenharmony_ci .playback = { 5608c2ecf20Sopenharmony_ci .stream_name = "I2S Playback", 5618c2ecf20Sopenharmony_ci .channels_min = 1, 5628c2ecf20Sopenharmony_ci .channels_max = 2, 5638c2ecf20Sopenharmony_ci .rates = SNDRV_PCM_RATE_8000_48000, 5648c2ecf20Sopenharmony_ci .formats = SNDRV_PCM_FMTBIT_S16_LE, 5658c2ecf20Sopenharmony_ci }, 5668c2ecf20Sopenharmony_ci .capture = { 5678c2ecf20Sopenharmony_ci .stream_name = "I2S Capture", 5688c2ecf20Sopenharmony_ci .channels_min = 1, 5698c2ecf20Sopenharmony_ci .channels_max = 2, 5708c2ecf20Sopenharmony_ci .rates = SNDRV_PCM_RATE_8000_48000, 5718c2ecf20Sopenharmony_ci .formats = SNDRV_PCM_FMTBIT_S16_LE, 5728c2ecf20Sopenharmony_ci }, 5738c2ecf20Sopenharmony_ci .ops = &mt8173_afe_i2s_ops, 5748c2ecf20Sopenharmony_ci .symmetric_rates = 1, 5758c2ecf20Sopenharmony_ci }, 5768c2ecf20Sopenharmony_ci}; 5778c2ecf20Sopenharmony_ci 5788c2ecf20Sopenharmony_cistatic struct snd_soc_dai_driver mt8173_afe_hdmi_dais[] = { 5798c2ecf20Sopenharmony_ci /* FE DAIs */ 5808c2ecf20Sopenharmony_ci { 5818c2ecf20Sopenharmony_ci .name = "HDMI", 5828c2ecf20Sopenharmony_ci .id = MT8173_AFE_MEMIF_HDMI, 5838c2ecf20Sopenharmony_ci .playback = { 5848c2ecf20Sopenharmony_ci .stream_name = "HDMI", 5858c2ecf20Sopenharmony_ci .channels_min = 2, 5868c2ecf20Sopenharmony_ci .channels_max = 8, 5878c2ecf20Sopenharmony_ci .rates = SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | 5888c2ecf20Sopenharmony_ci SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | 5898c2ecf20Sopenharmony_ci SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_176400 | 5908c2ecf20Sopenharmony_ci SNDRV_PCM_RATE_192000, 5918c2ecf20Sopenharmony_ci .formats = SNDRV_PCM_FMTBIT_S16_LE, 5928c2ecf20Sopenharmony_ci }, 5938c2ecf20Sopenharmony_ci .ops = &mtk_afe_fe_ops, 5948c2ecf20Sopenharmony_ci }, { 5958c2ecf20Sopenharmony_ci /* BE DAIs */ 5968c2ecf20Sopenharmony_ci .name = "HDMIO", 5978c2ecf20Sopenharmony_ci .id = MT8173_AFE_IO_HDMI, 5988c2ecf20Sopenharmony_ci .playback = { 5998c2ecf20Sopenharmony_ci .stream_name = "HDMIO Playback", 6008c2ecf20Sopenharmony_ci .channels_min = 2, 6018c2ecf20Sopenharmony_ci .channels_max = 8, 6028c2ecf20Sopenharmony_ci .rates = SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | 6038c2ecf20Sopenharmony_ci SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | 6048c2ecf20Sopenharmony_ci SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_176400 | 6058c2ecf20Sopenharmony_ci SNDRV_PCM_RATE_192000, 6068c2ecf20Sopenharmony_ci .formats = SNDRV_PCM_FMTBIT_S16_LE, 6078c2ecf20Sopenharmony_ci }, 6088c2ecf20Sopenharmony_ci .ops = &mt8173_afe_hdmi_ops, 6098c2ecf20Sopenharmony_ci }, 6108c2ecf20Sopenharmony_ci}; 6118c2ecf20Sopenharmony_ci 6128c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new mt8173_afe_o03_mix[] = { 6138c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE_AUTODISABLE("I05 Switch", AFE_CONN1, 21, 1, 0), 6148c2ecf20Sopenharmony_ci}; 6158c2ecf20Sopenharmony_ci 6168c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new mt8173_afe_o04_mix[] = { 6178c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE_AUTODISABLE("I06 Switch", AFE_CONN2, 6, 1, 0), 6188c2ecf20Sopenharmony_ci}; 6198c2ecf20Sopenharmony_ci 6208c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new mt8173_afe_o09_mix[] = { 6218c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE_AUTODISABLE("I03 Switch", AFE_CONN3, 0, 1, 0), 6228c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE_AUTODISABLE("I17 Switch", AFE_CONN7, 30, 1, 0), 6238c2ecf20Sopenharmony_ci}; 6248c2ecf20Sopenharmony_ci 6258c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new mt8173_afe_o10_mix[] = { 6268c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE_AUTODISABLE("I04 Switch", AFE_CONN3, 3, 1, 0), 6278c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE_AUTODISABLE("I18 Switch", AFE_CONN8, 0, 1, 0), 6288c2ecf20Sopenharmony_ci}; 6298c2ecf20Sopenharmony_ci 6308c2ecf20Sopenharmony_cistatic const struct snd_soc_dapm_widget mt8173_afe_pcm_widgets[] = { 6318c2ecf20Sopenharmony_ci /* inter-connections */ 6328c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("I03", SND_SOC_NOPM, 0, 0, NULL, 0), 6338c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("I04", SND_SOC_NOPM, 0, 0, NULL, 0), 6348c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("I05", SND_SOC_NOPM, 0, 0, NULL, 0), 6358c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("I06", SND_SOC_NOPM, 0, 0, NULL, 0), 6368c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("I17", SND_SOC_NOPM, 0, 0, NULL, 0), 6378c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("I18", SND_SOC_NOPM, 0, 0, NULL, 0), 6388c2ecf20Sopenharmony_ci 6398c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("O03", SND_SOC_NOPM, 0, 0, 6408c2ecf20Sopenharmony_ci mt8173_afe_o03_mix, ARRAY_SIZE(mt8173_afe_o03_mix)), 6418c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("O04", SND_SOC_NOPM, 0, 0, 6428c2ecf20Sopenharmony_ci mt8173_afe_o04_mix, ARRAY_SIZE(mt8173_afe_o04_mix)), 6438c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("O09", SND_SOC_NOPM, 0, 0, 6448c2ecf20Sopenharmony_ci mt8173_afe_o09_mix, ARRAY_SIZE(mt8173_afe_o09_mix)), 6458c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("O10", SND_SOC_NOPM, 0, 0, 6468c2ecf20Sopenharmony_ci mt8173_afe_o10_mix, ARRAY_SIZE(mt8173_afe_o10_mix)), 6478c2ecf20Sopenharmony_ci}; 6488c2ecf20Sopenharmony_ci 6498c2ecf20Sopenharmony_cistatic const struct snd_soc_dapm_route mt8173_afe_pcm_routes[] = { 6508c2ecf20Sopenharmony_ci {"I05", NULL, "DL1"}, 6518c2ecf20Sopenharmony_ci {"I06", NULL, "DL1"}, 6528c2ecf20Sopenharmony_ci {"I2S Playback", NULL, "O03"}, 6538c2ecf20Sopenharmony_ci {"I2S Playback", NULL, "O04"}, 6548c2ecf20Sopenharmony_ci {"VUL", NULL, "O09"}, 6558c2ecf20Sopenharmony_ci {"VUL", NULL, "O10"}, 6568c2ecf20Sopenharmony_ci {"I03", NULL, "I2S Capture"}, 6578c2ecf20Sopenharmony_ci {"I04", NULL, "I2S Capture"}, 6588c2ecf20Sopenharmony_ci {"I17", NULL, "I2S Capture"}, 6598c2ecf20Sopenharmony_ci {"I18", NULL, "I2S Capture"}, 6608c2ecf20Sopenharmony_ci { "O03", "I05 Switch", "I05" }, 6618c2ecf20Sopenharmony_ci { "O04", "I06 Switch", "I06" }, 6628c2ecf20Sopenharmony_ci { "O09", "I17 Switch", "I17" }, 6638c2ecf20Sopenharmony_ci { "O09", "I03 Switch", "I03" }, 6648c2ecf20Sopenharmony_ci { "O10", "I18 Switch", "I18" }, 6658c2ecf20Sopenharmony_ci { "O10", "I04 Switch", "I04" }, 6668c2ecf20Sopenharmony_ci}; 6678c2ecf20Sopenharmony_ci 6688c2ecf20Sopenharmony_cistatic const struct snd_soc_dapm_route mt8173_afe_hdmi_routes[] = { 6698c2ecf20Sopenharmony_ci {"HDMIO Playback", NULL, "HDMI"}, 6708c2ecf20Sopenharmony_ci}; 6718c2ecf20Sopenharmony_ci 6728c2ecf20Sopenharmony_cistatic const struct snd_soc_component_driver mt8173_afe_pcm_dai_component = { 6738c2ecf20Sopenharmony_ci .name = "mt8173-afe-pcm-dai", 6748c2ecf20Sopenharmony_ci .dapm_widgets = mt8173_afe_pcm_widgets, 6758c2ecf20Sopenharmony_ci .num_dapm_widgets = ARRAY_SIZE(mt8173_afe_pcm_widgets), 6768c2ecf20Sopenharmony_ci .dapm_routes = mt8173_afe_pcm_routes, 6778c2ecf20Sopenharmony_ci .num_dapm_routes = ARRAY_SIZE(mt8173_afe_pcm_routes), 6788c2ecf20Sopenharmony_ci .suspend = mtk_afe_suspend, 6798c2ecf20Sopenharmony_ci .resume = mtk_afe_resume, 6808c2ecf20Sopenharmony_ci}; 6818c2ecf20Sopenharmony_ci 6828c2ecf20Sopenharmony_cistatic const struct snd_soc_component_driver mt8173_afe_hdmi_dai_component = { 6838c2ecf20Sopenharmony_ci .name = "mt8173-afe-hdmi-dai", 6848c2ecf20Sopenharmony_ci .dapm_routes = mt8173_afe_hdmi_routes, 6858c2ecf20Sopenharmony_ci .num_dapm_routes = ARRAY_SIZE(mt8173_afe_hdmi_routes), 6868c2ecf20Sopenharmony_ci .suspend = mtk_afe_suspend, 6878c2ecf20Sopenharmony_ci .resume = mtk_afe_resume, 6888c2ecf20Sopenharmony_ci}; 6898c2ecf20Sopenharmony_ci 6908c2ecf20Sopenharmony_cistatic const char *aud_clks[MT8173_CLK_NUM] = { 6918c2ecf20Sopenharmony_ci [MT8173_CLK_INFRASYS_AUD] = "infra_sys_audio_clk", 6928c2ecf20Sopenharmony_ci [MT8173_CLK_TOP_PDN_AUD] = "top_pdn_audio", 6938c2ecf20Sopenharmony_ci [MT8173_CLK_TOP_PDN_AUD_BUS] = "top_pdn_aud_intbus", 6948c2ecf20Sopenharmony_ci [MT8173_CLK_I2S0_M] = "i2s0_m", 6958c2ecf20Sopenharmony_ci [MT8173_CLK_I2S1_M] = "i2s1_m", 6968c2ecf20Sopenharmony_ci [MT8173_CLK_I2S2_M] = "i2s2_m", 6978c2ecf20Sopenharmony_ci [MT8173_CLK_I2S3_M] = "i2s3_m", 6988c2ecf20Sopenharmony_ci [MT8173_CLK_I2S3_B] = "i2s3_b", 6998c2ecf20Sopenharmony_ci [MT8173_CLK_BCK0] = "bck0", 7008c2ecf20Sopenharmony_ci [MT8173_CLK_BCK1] = "bck1", 7018c2ecf20Sopenharmony_ci}; 7028c2ecf20Sopenharmony_ci 7038c2ecf20Sopenharmony_cistatic const struct mtk_base_memif_data memif_data[MT8173_AFE_MEMIF_NUM] = { 7048c2ecf20Sopenharmony_ci { 7058c2ecf20Sopenharmony_ci .name = "DL1", 7068c2ecf20Sopenharmony_ci .id = MT8173_AFE_MEMIF_DL1, 7078c2ecf20Sopenharmony_ci .reg_ofs_base = AFE_DL1_BASE, 7088c2ecf20Sopenharmony_ci .reg_ofs_cur = AFE_DL1_CUR, 7098c2ecf20Sopenharmony_ci .fs_reg = AFE_DAC_CON1, 7108c2ecf20Sopenharmony_ci .fs_shift = 0, 7118c2ecf20Sopenharmony_ci .fs_maskbit = 0xf, 7128c2ecf20Sopenharmony_ci .mono_reg = AFE_DAC_CON1, 7138c2ecf20Sopenharmony_ci .mono_shift = 21, 7148c2ecf20Sopenharmony_ci .hd_reg = -1, 7158c2ecf20Sopenharmony_ci .enable_reg = AFE_DAC_CON0, 7168c2ecf20Sopenharmony_ci .enable_shift = 1, 7178c2ecf20Sopenharmony_ci .msb_reg = AFE_MEMIF_MSB, 7188c2ecf20Sopenharmony_ci .msb_shift = 0, 7198c2ecf20Sopenharmony_ci .agent_disable_reg = -1, 7208c2ecf20Sopenharmony_ci }, { 7218c2ecf20Sopenharmony_ci .name = "DL2", 7228c2ecf20Sopenharmony_ci .id = MT8173_AFE_MEMIF_DL2, 7238c2ecf20Sopenharmony_ci .reg_ofs_base = AFE_DL2_BASE, 7248c2ecf20Sopenharmony_ci .reg_ofs_cur = AFE_DL2_CUR, 7258c2ecf20Sopenharmony_ci .fs_reg = AFE_DAC_CON1, 7268c2ecf20Sopenharmony_ci .fs_shift = 4, 7278c2ecf20Sopenharmony_ci .fs_maskbit = 0xf, 7288c2ecf20Sopenharmony_ci .mono_reg = AFE_DAC_CON1, 7298c2ecf20Sopenharmony_ci .mono_shift = 22, 7308c2ecf20Sopenharmony_ci .hd_reg = -1, 7318c2ecf20Sopenharmony_ci .enable_reg = AFE_DAC_CON0, 7328c2ecf20Sopenharmony_ci .enable_shift = 2, 7338c2ecf20Sopenharmony_ci .msb_reg = AFE_MEMIF_MSB, 7348c2ecf20Sopenharmony_ci .msb_shift = 1, 7358c2ecf20Sopenharmony_ci .agent_disable_reg = -1, 7368c2ecf20Sopenharmony_ci }, { 7378c2ecf20Sopenharmony_ci .name = "VUL", 7388c2ecf20Sopenharmony_ci .id = MT8173_AFE_MEMIF_VUL, 7398c2ecf20Sopenharmony_ci .reg_ofs_base = AFE_VUL_BASE, 7408c2ecf20Sopenharmony_ci .reg_ofs_cur = AFE_VUL_CUR, 7418c2ecf20Sopenharmony_ci .fs_reg = AFE_DAC_CON1, 7428c2ecf20Sopenharmony_ci .fs_shift = 16, 7438c2ecf20Sopenharmony_ci .fs_maskbit = 0xf, 7448c2ecf20Sopenharmony_ci .mono_reg = AFE_DAC_CON1, 7458c2ecf20Sopenharmony_ci .mono_shift = 27, 7468c2ecf20Sopenharmony_ci .hd_reg = -1, 7478c2ecf20Sopenharmony_ci .enable_reg = AFE_DAC_CON0, 7488c2ecf20Sopenharmony_ci .enable_shift = 3, 7498c2ecf20Sopenharmony_ci .msb_reg = AFE_MEMIF_MSB, 7508c2ecf20Sopenharmony_ci .msb_shift = 6, 7518c2ecf20Sopenharmony_ci .agent_disable_reg = -1, 7528c2ecf20Sopenharmony_ci }, { 7538c2ecf20Sopenharmony_ci .name = "DAI", 7548c2ecf20Sopenharmony_ci .id = MT8173_AFE_MEMIF_DAI, 7558c2ecf20Sopenharmony_ci .reg_ofs_base = AFE_DAI_BASE, 7568c2ecf20Sopenharmony_ci .reg_ofs_cur = AFE_DAI_CUR, 7578c2ecf20Sopenharmony_ci .fs_reg = AFE_DAC_CON0, 7588c2ecf20Sopenharmony_ci .fs_shift = 24, 7598c2ecf20Sopenharmony_ci .fs_maskbit = 0x3, 7608c2ecf20Sopenharmony_ci .mono_reg = -1, 7618c2ecf20Sopenharmony_ci .mono_shift = -1, 7628c2ecf20Sopenharmony_ci .hd_reg = -1, 7638c2ecf20Sopenharmony_ci .enable_reg = AFE_DAC_CON0, 7648c2ecf20Sopenharmony_ci .enable_shift = 4, 7658c2ecf20Sopenharmony_ci .msb_reg = AFE_MEMIF_MSB, 7668c2ecf20Sopenharmony_ci .msb_shift = 5, 7678c2ecf20Sopenharmony_ci .agent_disable_reg = -1, 7688c2ecf20Sopenharmony_ci }, { 7698c2ecf20Sopenharmony_ci .name = "AWB", 7708c2ecf20Sopenharmony_ci .id = MT8173_AFE_MEMIF_AWB, 7718c2ecf20Sopenharmony_ci .reg_ofs_base = AFE_AWB_BASE, 7728c2ecf20Sopenharmony_ci .reg_ofs_cur = AFE_AWB_CUR, 7738c2ecf20Sopenharmony_ci .fs_reg = AFE_DAC_CON1, 7748c2ecf20Sopenharmony_ci .fs_shift = 12, 7758c2ecf20Sopenharmony_ci .fs_maskbit = 0xf, 7768c2ecf20Sopenharmony_ci .mono_reg = AFE_DAC_CON1, 7778c2ecf20Sopenharmony_ci .mono_shift = 24, 7788c2ecf20Sopenharmony_ci .hd_reg = -1, 7798c2ecf20Sopenharmony_ci .enable_reg = AFE_DAC_CON0, 7808c2ecf20Sopenharmony_ci .enable_shift = 6, 7818c2ecf20Sopenharmony_ci .msb_reg = AFE_MEMIF_MSB, 7828c2ecf20Sopenharmony_ci .msb_shift = 3, 7838c2ecf20Sopenharmony_ci .agent_disable_reg = -1, 7848c2ecf20Sopenharmony_ci }, { 7858c2ecf20Sopenharmony_ci .name = "MOD_DAI", 7868c2ecf20Sopenharmony_ci .id = MT8173_AFE_MEMIF_MOD_DAI, 7878c2ecf20Sopenharmony_ci .reg_ofs_base = AFE_MOD_PCM_BASE, 7888c2ecf20Sopenharmony_ci .reg_ofs_cur = AFE_MOD_PCM_CUR, 7898c2ecf20Sopenharmony_ci .fs_reg = AFE_DAC_CON1, 7908c2ecf20Sopenharmony_ci .fs_shift = 30, 7918c2ecf20Sopenharmony_ci .fs_maskbit = 0x3, 7928c2ecf20Sopenharmony_ci .mono_reg = AFE_DAC_CON1, 7938c2ecf20Sopenharmony_ci .mono_shift = 30, 7948c2ecf20Sopenharmony_ci .hd_reg = -1, 7958c2ecf20Sopenharmony_ci .enable_reg = AFE_DAC_CON0, 7968c2ecf20Sopenharmony_ci .enable_shift = 7, 7978c2ecf20Sopenharmony_ci .msb_reg = AFE_MEMIF_MSB, 7988c2ecf20Sopenharmony_ci .msb_shift = 4, 7998c2ecf20Sopenharmony_ci .agent_disable_reg = -1, 8008c2ecf20Sopenharmony_ci }, { 8018c2ecf20Sopenharmony_ci .name = "HDMI", 8028c2ecf20Sopenharmony_ci .id = MT8173_AFE_MEMIF_HDMI, 8038c2ecf20Sopenharmony_ci .reg_ofs_base = AFE_HDMI_OUT_BASE, 8048c2ecf20Sopenharmony_ci .reg_ofs_cur = AFE_HDMI_OUT_CUR, 8058c2ecf20Sopenharmony_ci .fs_reg = -1, 8068c2ecf20Sopenharmony_ci .fs_shift = -1, 8078c2ecf20Sopenharmony_ci .fs_maskbit = -1, 8088c2ecf20Sopenharmony_ci .mono_reg = -1, 8098c2ecf20Sopenharmony_ci .mono_shift = -1, 8108c2ecf20Sopenharmony_ci .hd_reg = -1, 8118c2ecf20Sopenharmony_ci .enable_reg = -1, 8128c2ecf20Sopenharmony_ci .msb_reg = AFE_MEMIF_MSB, 8138c2ecf20Sopenharmony_ci .msb_shift = 8, 8148c2ecf20Sopenharmony_ci .agent_disable_reg = -1, 8158c2ecf20Sopenharmony_ci }, 8168c2ecf20Sopenharmony_ci}; 8178c2ecf20Sopenharmony_ci 8188c2ecf20Sopenharmony_cistatic const struct mtk_base_irq_data irq_data[MT8173_AFE_IRQ_NUM] = { 8198c2ecf20Sopenharmony_ci { 8208c2ecf20Sopenharmony_ci .id = MT8173_AFE_IRQ_DL1, 8218c2ecf20Sopenharmony_ci .irq_cnt_reg = AFE_IRQ_CNT1, 8228c2ecf20Sopenharmony_ci .irq_cnt_shift = 0, 8238c2ecf20Sopenharmony_ci .irq_cnt_maskbit = 0x3ffff, 8248c2ecf20Sopenharmony_ci .irq_en_reg = AFE_IRQ_MCU_CON, 8258c2ecf20Sopenharmony_ci .irq_en_shift = 0, 8268c2ecf20Sopenharmony_ci .irq_fs_reg = AFE_IRQ_MCU_CON, 8278c2ecf20Sopenharmony_ci .irq_fs_shift = 4, 8288c2ecf20Sopenharmony_ci .irq_fs_maskbit = 0xf, 8298c2ecf20Sopenharmony_ci .irq_clr_reg = AFE_IRQ_CLR, 8308c2ecf20Sopenharmony_ci .irq_clr_shift = 0, 8318c2ecf20Sopenharmony_ci }, { 8328c2ecf20Sopenharmony_ci .id = MT8173_AFE_IRQ_DL2, 8338c2ecf20Sopenharmony_ci .irq_cnt_reg = AFE_IRQ_CNT1, 8348c2ecf20Sopenharmony_ci .irq_cnt_shift = 20, 8358c2ecf20Sopenharmony_ci .irq_cnt_maskbit = 0x3ffff, 8368c2ecf20Sopenharmony_ci .irq_en_reg = AFE_IRQ_MCU_CON, 8378c2ecf20Sopenharmony_ci .irq_en_shift = 2, 8388c2ecf20Sopenharmony_ci .irq_fs_reg = AFE_IRQ_MCU_CON, 8398c2ecf20Sopenharmony_ci .irq_fs_shift = 16, 8408c2ecf20Sopenharmony_ci .irq_fs_maskbit = 0xf, 8418c2ecf20Sopenharmony_ci .irq_clr_reg = AFE_IRQ_CLR, 8428c2ecf20Sopenharmony_ci .irq_clr_shift = 2, 8438c2ecf20Sopenharmony_ci 8448c2ecf20Sopenharmony_ci }, { 8458c2ecf20Sopenharmony_ci .id = MT8173_AFE_IRQ_VUL, 8468c2ecf20Sopenharmony_ci .irq_cnt_reg = AFE_IRQ_CNT2, 8478c2ecf20Sopenharmony_ci .irq_cnt_shift = 0, 8488c2ecf20Sopenharmony_ci .irq_cnt_maskbit = 0x3ffff, 8498c2ecf20Sopenharmony_ci .irq_en_reg = AFE_IRQ_MCU_CON, 8508c2ecf20Sopenharmony_ci .irq_en_shift = 1, 8518c2ecf20Sopenharmony_ci .irq_fs_reg = AFE_IRQ_MCU_CON, 8528c2ecf20Sopenharmony_ci .irq_fs_shift = 8, 8538c2ecf20Sopenharmony_ci .irq_fs_maskbit = 0xf, 8548c2ecf20Sopenharmony_ci .irq_clr_reg = AFE_IRQ_CLR, 8558c2ecf20Sopenharmony_ci .irq_clr_shift = 1, 8568c2ecf20Sopenharmony_ci }, { 8578c2ecf20Sopenharmony_ci .id = MT8173_AFE_IRQ_DAI, 8588c2ecf20Sopenharmony_ci .irq_cnt_reg = AFE_IRQ_CNT2, 8598c2ecf20Sopenharmony_ci .irq_cnt_shift = 20, 8608c2ecf20Sopenharmony_ci .irq_cnt_maskbit = 0x3ffff, 8618c2ecf20Sopenharmony_ci .irq_en_reg = AFE_IRQ_MCU_CON, 8628c2ecf20Sopenharmony_ci .irq_en_shift = 3, 8638c2ecf20Sopenharmony_ci .irq_fs_reg = AFE_IRQ_MCU_CON, 8648c2ecf20Sopenharmony_ci .irq_fs_shift = 20, 8658c2ecf20Sopenharmony_ci .irq_fs_maskbit = 0xf, 8668c2ecf20Sopenharmony_ci .irq_clr_reg = AFE_IRQ_CLR, 8678c2ecf20Sopenharmony_ci .irq_clr_shift = 3, 8688c2ecf20Sopenharmony_ci }, { 8698c2ecf20Sopenharmony_ci .id = MT8173_AFE_IRQ_AWB, 8708c2ecf20Sopenharmony_ci .irq_cnt_reg = AFE_IRQ_CNT7, 8718c2ecf20Sopenharmony_ci .irq_cnt_shift = 0, 8728c2ecf20Sopenharmony_ci .irq_cnt_maskbit = 0x3ffff, 8738c2ecf20Sopenharmony_ci .irq_en_reg = AFE_IRQ_MCU_CON, 8748c2ecf20Sopenharmony_ci .irq_en_shift = 14, 8758c2ecf20Sopenharmony_ci .irq_fs_reg = AFE_IRQ_MCU_CON, 8768c2ecf20Sopenharmony_ci .irq_fs_shift = 24, 8778c2ecf20Sopenharmony_ci .irq_fs_maskbit = 0xf, 8788c2ecf20Sopenharmony_ci .irq_clr_reg = AFE_IRQ_CLR, 8798c2ecf20Sopenharmony_ci .irq_clr_shift = 6, 8808c2ecf20Sopenharmony_ci }, { 8818c2ecf20Sopenharmony_ci .id = MT8173_AFE_IRQ_DAI, 8828c2ecf20Sopenharmony_ci .irq_cnt_reg = AFE_IRQ_CNT2, 8838c2ecf20Sopenharmony_ci .irq_cnt_shift = 20, 8848c2ecf20Sopenharmony_ci .irq_cnt_maskbit = 0x3ffff, 8858c2ecf20Sopenharmony_ci .irq_en_reg = AFE_IRQ_MCU_CON, 8868c2ecf20Sopenharmony_ci .irq_en_shift = 3, 8878c2ecf20Sopenharmony_ci .irq_fs_reg = AFE_IRQ_MCU_CON, 8888c2ecf20Sopenharmony_ci .irq_fs_shift = 20, 8898c2ecf20Sopenharmony_ci .irq_fs_maskbit = 0xf, 8908c2ecf20Sopenharmony_ci .irq_clr_reg = AFE_IRQ_CLR, 8918c2ecf20Sopenharmony_ci .irq_clr_shift = 3, 8928c2ecf20Sopenharmony_ci }, { 8938c2ecf20Sopenharmony_ci .id = MT8173_AFE_IRQ_HDMI, 8948c2ecf20Sopenharmony_ci .irq_cnt_reg = AFE_IRQ_CNT5, 8958c2ecf20Sopenharmony_ci .irq_cnt_shift = 0, 8968c2ecf20Sopenharmony_ci .irq_cnt_maskbit = 0x3ffff, 8978c2ecf20Sopenharmony_ci .irq_en_reg = AFE_IRQ_MCU_CON, 8988c2ecf20Sopenharmony_ci .irq_en_shift = 12, 8998c2ecf20Sopenharmony_ci .irq_fs_reg = -1, 9008c2ecf20Sopenharmony_ci .irq_fs_maskbit = -1, 9018c2ecf20Sopenharmony_ci .irq_clr_reg = AFE_IRQ_CLR, 9028c2ecf20Sopenharmony_ci .irq_clr_shift = 4, 9038c2ecf20Sopenharmony_ci }, 9048c2ecf20Sopenharmony_ci}; 9058c2ecf20Sopenharmony_ci 9068c2ecf20Sopenharmony_cistatic const struct regmap_config mt8173_afe_regmap_config = { 9078c2ecf20Sopenharmony_ci .reg_bits = 32, 9088c2ecf20Sopenharmony_ci .reg_stride = 4, 9098c2ecf20Sopenharmony_ci .val_bits = 32, 9108c2ecf20Sopenharmony_ci .max_register = AFE_ADDA2_TOP_CON0, 9118c2ecf20Sopenharmony_ci .cache_type = REGCACHE_NONE, 9128c2ecf20Sopenharmony_ci}; 9138c2ecf20Sopenharmony_ci 9148c2ecf20Sopenharmony_cistatic irqreturn_t mt8173_afe_irq_handler(int irq, void *dev_id) 9158c2ecf20Sopenharmony_ci{ 9168c2ecf20Sopenharmony_ci struct mtk_base_afe *afe = dev_id; 9178c2ecf20Sopenharmony_ci unsigned int reg_value; 9188c2ecf20Sopenharmony_ci int i, ret; 9198c2ecf20Sopenharmony_ci 9208c2ecf20Sopenharmony_ci ret = regmap_read(afe->regmap, AFE_IRQ_STATUS, ®_value); 9218c2ecf20Sopenharmony_ci if (ret) { 9228c2ecf20Sopenharmony_ci dev_err(afe->dev, "%s irq status err\n", __func__); 9238c2ecf20Sopenharmony_ci reg_value = AFE_IRQ_STATUS_BITS; 9248c2ecf20Sopenharmony_ci goto err_irq; 9258c2ecf20Sopenharmony_ci } 9268c2ecf20Sopenharmony_ci 9278c2ecf20Sopenharmony_ci for (i = 0; i < MT8173_AFE_MEMIF_NUM; i++) { 9288c2ecf20Sopenharmony_ci struct mtk_base_afe_memif *memif = &afe->memif[i]; 9298c2ecf20Sopenharmony_ci struct mtk_base_afe_irq *irq; 9308c2ecf20Sopenharmony_ci 9318c2ecf20Sopenharmony_ci if (memif->irq_usage < 0) 9328c2ecf20Sopenharmony_ci continue; 9338c2ecf20Sopenharmony_ci 9348c2ecf20Sopenharmony_ci irq = &afe->irqs[memif->irq_usage]; 9358c2ecf20Sopenharmony_ci 9368c2ecf20Sopenharmony_ci if (!(reg_value & (1 << irq->irq_data->irq_clr_shift))) 9378c2ecf20Sopenharmony_ci continue; 9388c2ecf20Sopenharmony_ci 9398c2ecf20Sopenharmony_ci snd_pcm_period_elapsed(memif->substream); 9408c2ecf20Sopenharmony_ci } 9418c2ecf20Sopenharmony_ci 9428c2ecf20Sopenharmony_cierr_irq: 9438c2ecf20Sopenharmony_ci /* clear irq */ 9448c2ecf20Sopenharmony_ci regmap_write(afe->regmap, AFE_IRQ_CLR, 9458c2ecf20Sopenharmony_ci reg_value & AFE_IRQ_STATUS_BITS); 9468c2ecf20Sopenharmony_ci 9478c2ecf20Sopenharmony_ci return IRQ_HANDLED; 9488c2ecf20Sopenharmony_ci} 9498c2ecf20Sopenharmony_ci 9508c2ecf20Sopenharmony_cistatic int mt8173_afe_runtime_suspend(struct device *dev) 9518c2ecf20Sopenharmony_ci{ 9528c2ecf20Sopenharmony_ci struct mtk_base_afe *afe = dev_get_drvdata(dev); 9538c2ecf20Sopenharmony_ci struct mt8173_afe_private *afe_priv = afe->platform_priv; 9548c2ecf20Sopenharmony_ci 9558c2ecf20Sopenharmony_ci /* disable AFE */ 9568c2ecf20Sopenharmony_ci regmap_update_bits(afe->regmap, AFE_DAC_CON0, 0x1, 0); 9578c2ecf20Sopenharmony_ci 9588c2ecf20Sopenharmony_ci /* disable AFE clk */ 9598c2ecf20Sopenharmony_ci regmap_update_bits(afe->regmap, AUDIO_TOP_CON0, 9608c2ecf20Sopenharmony_ci AUD_TCON0_PDN_AFE, AUD_TCON0_PDN_AFE); 9618c2ecf20Sopenharmony_ci 9628c2ecf20Sopenharmony_ci clk_disable_unprepare(afe_priv->clocks[MT8173_CLK_I2S1_M]); 9638c2ecf20Sopenharmony_ci clk_disable_unprepare(afe_priv->clocks[MT8173_CLK_I2S2_M]); 9648c2ecf20Sopenharmony_ci clk_disable_unprepare(afe_priv->clocks[MT8173_CLK_BCK0]); 9658c2ecf20Sopenharmony_ci clk_disable_unprepare(afe_priv->clocks[MT8173_CLK_BCK1]); 9668c2ecf20Sopenharmony_ci clk_disable_unprepare(afe_priv->clocks[MT8173_CLK_TOP_PDN_AUD]); 9678c2ecf20Sopenharmony_ci clk_disable_unprepare(afe_priv->clocks[MT8173_CLK_TOP_PDN_AUD_BUS]); 9688c2ecf20Sopenharmony_ci clk_disable_unprepare(afe_priv->clocks[MT8173_CLK_INFRASYS_AUD]); 9698c2ecf20Sopenharmony_ci return 0; 9708c2ecf20Sopenharmony_ci} 9718c2ecf20Sopenharmony_ci 9728c2ecf20Sopenharmony_cistatic int mt8173_afe_runtime_resume(struct device *dev) 9738c2ecf20Sopenharmony_ci{ 9748c2ecf20Sopenharmony_ci struct mtk_base_afe *afe = dev_get_drvdata(dev); 9758c2ecf20Sopenharmony_ci struct mt8173_afe_private *afe_priv = afe->platform_priv; 9768c2ecf20Sopenharmony_ci int ret; 9778c2ecf20Sopenharmony_ci 9788c2ecf20Sopenharmony_ci ret = clk_prepare_enable(afe_priv->clocks[MT8173_CLK_INFRASYS_AUD]); 9798c2ecf20Sopenharmony_ci if (ret) 9808c2ecf20Sopenharmony_ci return ret; 9818c2ecf20Sopenharmony_ci 9828c2ecf20Sopenharmony_ci ret = clk_prepare_enable(afe_priv->clocks[MT8173_CLK_TOP_PDN_AUD_BUS]); 9838c2ecf20Sopenharmony_ci if (ret) 9848c2ecf20Sopenharmony_ci goto err_infra; 9858c2ecf20Sopenharmony_ci 9868c2ecf20Sopenharmony_ci ret = clk_prepare_enable(afe_priv->clocks[MT8173_CLK_TOP_PDN_AUD]); 9878c2ecf20Sopenharmony_ci if (ret) 9888c2ecf20Sopenharmony_ci goto err_top_aud_bus; 9898c2ecf20Sopenharmony_ci 9908c2ecf20Sopenharmony_ci ret = clk_prepare_enable(afe_priv->clocks[MT8173_CLK_BCK0]); 9918c2ecf20Sopenharmony_ci if (ret) 9928c2ecf20Sopenharmony_ci goto err_top_aud; 9938c2ecf20Sopenharmony_ci 9948c2ecf20Sopenharmony_ci ret = clk_prepare_enable(afe_priv->clocks[MT8173_CLK_BCK1]); 9958c2ecf20Sopenharmony_ci if (ret) 9968c2ecf20Sopenharmony_ci goto err_bck0; 9978c2ecf20Sopenharmony_ci ret = clk_prepare_enable(afe_priv->clocks[MT8173_CLK_I2S1_M]); 9988c2ecf20Sopenharmony_ci if (ret) 9998c2ecf20Sopenharmony_ci goto err_i2s1_m; 10008c2ecf20Sopenharmony_ci ret = clk_prepare_enable(afe_priv->clocks[MT8173_CLK_I2S2_M]); 10018c2ecf20Sopenharmony_ci if (ret) 10028c2ecf20Sopenharmony_ci goto err_i2s2_m; 10038c2ecf20Sopenharmony_ci 10048c2ecf20Sopenharmony_ci /* enable AFE clk */ 10058c2ecf20Sopenharmony_ci regmap_update_bits(afe->regmap, AUDIO_TOP_CON0, AUD_TCON0_PDN_AFE, 0); 10068c2ecf20Sopenharmony_ci 10078c2ecf20Sopenharmony_ci /* set O3/O4 16bits */ 10088c2ecf20Sopenharmony_ci regmap_update_bits(afe->regmap, AFE_CONN_24BIT, 10098c2ecf20Sopenharmony_ci AFE_CONN_24BIT_O03 | AFE_CONN_24BIT_O04, 0); 10108c2ecf20Sopenharmony_ci 10118c2ecf20Sopenharmony_ci /* unmask all IRQs */ 10128c2ecf20Sopenharmony_ci regmap_update_bits(afe->regmap, AFE_IRQ_MCU_EN, 0xff, 0xff); 10138c2ecf20Sopenharmony_ci 10148c2ecf20Sopenharmony_ci /* enable AFE */ 10158c2ecf20Sopenharmony_ci regmap_update_bits(afe->regmap, AFE_DAC_CON0, 0x1, 0x1); 10168c2ecf20Sopenharmony_ci return 0; 10178c2ecf20Sopenharmony_ci 10188c2ecf20Sopenharmony_cierr_i2s1_m: 10198c2ecf20Sopenharmony_ci clk_disable_unprepare(afe_priv->clocks[MT8173_CLK_I2S1_M]); 10208c2ecf20Sopenharmony_cierr_i2s2_m: 10218c2ecf20Sopenharmony_ci clk_disable_unprepare(afe_priv->clocks[MT8173_CLK_I2S2_M]); 10228c2ecf20Sopenharmony_cierr_bck0: 10238c2ecf20Sopenharmony_ci clk_disable_unprepare(afe_priv->clocks[MT8173_CLK_BCK0]); 10248c2ecf20Sopenharmony_cierr_top_aud: 10258c2ecf20Sopenharmony_ci clk_disable_unprepare(afe_priv->clocks[MT8173_CLK_TOP_PDN_AUD]); 10268c2ecf20Sopenharmony_cierr_top_aud_bus: 10278c2ecf20Sopenharmony_ci clk_disable_unprepare(afe_priv->clocks[MT8173_CLK_TOP_PDN_AUD_BUS]); 10288c2ecf20Sopenharmony_cierr_infra: 10298c2ecf20Sopenharmony_ci clk_disable_unprepare(afe_priv->clocks[MT8173_CLK_INFRASYS_AUD]); 10308c2ecf20Sopenharmony_ci return ret; 10318c2ecf20Sopenharmony_ci} 10328c2ecf20Sopenharmony_ci 10338c2ecf20Sopenharmony_cistatic int mt8173_afe_init_audio_clk(struct mtk_base_afe *afe) 10348c2ecf20Sopenharmony_ci{ 10358c2ecf20Sopenharmony_ci size_t i; 10368c2ecf20Sopenharmony_ci struct mt8173_afe_private *afe_priv = afe->platform_priv; 10378c2ecf20Sopenharmony_ci 10388c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(aud_clks); i++) { 10398c2ecf20Sopenharmony_ci afe_priv->clocks[i] = devm_clk_get(afe->dev, aud_clks[i]); 10408c2ecf20Sopenharmony_ci if (IS_ERR(afe_priv->clocks[i])) { 10418c2ecf20Sopenharmony_ci dev_err(afe->dev, "%s devm_clk_get %s fail\n", 10428c2ecf20Sopenharmony_ci __func__, aud_clks[i]); 10438c2ecf20Sopenharmony_ci return PTR_ERR(afe_priv->clocks[i]); 10448c2ecf20Sopenharmony_ci } 10458c2ecf20Sopenharmony_ci } 10468c2ecf20Sopenharmony_ci clk_set_rate(afe_priv->clocks[MT8173_CLK_BCK0], 22579200); /* 22M */ 10478c2ecf20Sopenharmony_ci clk_set_rate(afe_priv->clocks[MT8173_CLK_BCK1], 24576000); /* 24M */ 10488c2ecf20Sopenharmony_ci return 0; 10498c2ecf20Sopenharmony_ci} 10508c2ecf20Sopenharmony_ci 10518c2ecf20Sopenharmony_cistatic int mt8173_afe_pcm_dev_probe(struct platform_device *pdev) 10528c2ecf20Sopenharmony_ci{ 10538c2ecf20Sopenharmony_ci int ret, i; 10548c2ecf20Sopenharmony_ci int irq_id; 10558c2ecf20Sopenharmony_ci struct mtk_base_afe *afe; 10568c2ecf20Sopenharmony_ci struct mt8173_afe_private *afe_priv; 10578c2ecf20Sopenharmony_ci struct snd_soc_component *comp_pcm, *comp_hdmi; 10588c2ecf20Sopenharmony_ci 10598c2ecf20Sopenharmony_ci ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(33)); 10608c2ecf20Sopenharmony_ci if (ret) 10618c2ecf20Sopenharmony_ci return ret; 10628c2ecf20Sopenharmony_ci 10638c2ecf20Sopenharmony_ci afe = devm_kzalloc(&pdev->dev, sizeof(*afe), GFP_KERNEL); 10648c2ecf20Sopenharmony_ci if (!afe) 10658c2ecf20Sopenharmony_ci return -ENOMEM; 10668c2ecf20Sopenharmony_ci 10678c2ecf20Sopenharmony_ci afe->platform_priv = devm_kzalloc(&pdev->dev, sizeof(*afe_priv), 10688c2ecf20Sopenharmony_ci GFP_KERNEL); 10698c2ecf20Sopenharmony_ci afe_priv = afe->platform_priv; 10708c2ecf20Sopenharmony_ci if (!afe_priv) 10718c2ecf20Sopenharmony_ci return -ENOMEM; 10728c2ecf20Sopenharmony_ci 10738c2ecf20Sopenharmony_ci afe->dev = &pdev->dev; 10748c2ecf20Sopenharmony_ci 10758c2ecf20Sopenharmony_ci irq_id = platform_get_irq(pdev, 0); 10768c2ecf20Sopenharmony_ci if (irq_id <= 0) 10778c2ecf20Sopenharmony_ci return irq_id < 0 ? irq_id : -ENXIO; 10788c2ecf20Sopenharmony_ci 10798c2ecf20Sopenharmony_ci afe->base_addr = devm_platform_ioremap_resource(pdev, 0); 10808c2ecf20Sopenharmony_ci if (IS_ERR(afe->base_addr)) 10818c2ecf20Sopenharmony_ci return PTR_ERR(afe->base_addr); 10828c2ecf20Sopenharmony_ci 10838c2ecf20Sopenharmony_ci afe->regmap = devm_regmap_init_mmio(&pdev->dev, afe->base_addr, 10848c2ecf20Sopenharmony_ci &mt8173_afe_regmap_config); 10858c2ecf20Sopenharmony_ci if (IS_ERR(afe->regmap)) 10868c2ecf20Sopenharmony_ci return PTR_ERR(afe->regmap); 10878c2ecf20Sopenharmony_ci 10888c2ecf20Sopenharmony_ci /* initial audio related clock */ 10898c2ecf20Sopenharmony_ci ret = mt8173_afe_init_audio_clk(afe); 10908c2ecf20Sopenharmony_ci if (ret) { 10918c2ecf20Sopenharmony_ci dev_err(afe->dev, "mt8173_afe_init_audio_clk fail\n"); 10928c2ecf20Sopenharmony_ci return ret; 10938c2ecf20Sopenharmony_ci } 10948c2ecf20Sopenharmony_ci 10958c2ecf20Sopenharmony_ci /* memif % irq initialize*/ 10968c2ecf20Sopenharmony_ci afe->memif_size = MT8173_AFE_MEMIF_NUM; 10978c2ecf20Sopenharmony_ci afe->memif = devm_kcalloc(afe->dev, afe->memif_size, 10988c2ecf20Sopenharmony_ci sizeof(*afe->memif), GFP_KERNEL); 10998c2ecf20Sopenharmony_ci if (!afe->memif) 11008c2ecf20Sopenharmony_ci return -ENOMEM; 11018c2ecf20Sopenharmony_ci 11028c2ecf20Sopenharmony_ci afe->irqs_size = MT8173_AFE_IRQ_NUM; 11038c2ecf20Sopenharmony_ci afe->irqs = devm_kcalloc(afe->dev, afe->irqs_size, 11048c2ecf20Sopenharmony_ci sizeof(*afe->irqs), GFP_KERNEL); 11058c2ecf20Sopenharmony_ci if (!afe->irqs) 11068c2ecf20Sopenharmony_ci return -ENOMEM; 11078c2ecf20Sopenharmony_ci 11088c2ecf20Sopenharmony_ci for (i = 0; i < afe->irqs_size; i++) { 11098c2ecf20Sopenharmony_ci afe->memif[i].data = &memif_data[i]; 11108c2ecf20Sopenharmony_ci afe->irqs[i].irq_data = &irq_data[i]; 11118c2ecf20Sopenharmony_ci afe->irqs[i].irq_occupyed = true; 11128c2ecf20Sopenharmony_ci afe->memif[i].irq_usage = i; 11138c2ecf20Sopenharmony_ci afe->memif[i].const_irq = 1; 11148c2ecf20Sopenharmony_ci } 11158c2ecf20Sopenharmony_ci 11168c2ecf20Sopenharmony_ci afe->mtk_afe_hardware = &mt8173_afe_hardware; 11178c2ecf20Sopenharmony_ci afe->memif_fs = mt8173_memif_fs; 11188c2ecf20Sopenharmony_ci afe->irq_fs = mt8173_irq_fs; 11198c2ecf20Sopenharmony_ci 11208c2ecf20Sopenharmony_ci platform_set_drvdata(pdev, afe); 11218c2ecf20Sopenharmony_ci 11228c2ecf20Sopenharmony_ci pm_runtime_enable(&pdev->dev); 11238c2ecf20Sopenharmony_ci if (!pm_runtime_enabled(&pdev->dev)) { 11248c2ecf20Sopenharmony_ci ret = mt8173_afe_runtime_resume(&pdev->dev); 11258c2ecf20Sopenharmony_ci if (ret) 11268c2ecf20Sopenharmony_ci goto err_pm_disable; 11278c2ecf20Sopenharmony_ci } 11288c2ecf20Sopenharmony_ci 11298c2ecf20Sopenharmony_ci afe->reg_back_up_list = mt8173_afe_backup_list; 11308c2ecf20Sopenharmony_ci afe->reg_back_up_list_num = ARRAY_SIZE(mt8173_afe_backup_list); 11318c2ecf20Sopenharmony_ci afe->runtime_resume = mt8173_afe_runtime_resume; 11328c2ecf20Sopenharmony_ci afe->runtime_suspend = mt8173_afe_runtime_suspend; 11338c2ecf20Sopenharmony_ci 11348c2ecf20Sopenharmony_ci ret = devm_snd_soc_register_component(&pdev->dev, 11358c2ecf20Sopenharmony_ci &mtk_afe_pcm_platform, 11368c2ecf20Sopenharmony_ci NULL, 0); 11378c2ecf20Sopenharmony_ci if (ret) 11388c2ecf20Sopenharmony_ci goto err_pm_disable; 11398c2ecf20Sopenharmony_ci 11408c2ecf20Sopenharmony_ci comp_pcm = devm_kzalloc(&pdev->dev, sizeof(*comp_pcm), GFP_KERNEL); 11418c2ecf20Sopenharmony_ci if (!comp_pcm) { 11428c2ecf20Sopenharmony_ci ret = -ENOMEM; 11438c2ecf20Sopenharmony_ci goto err_pm_disable; 11448c2ecf20Sopenharmony_ci } 11458c2ecf20Sopenharmony_ci 11468c2ecf20Sopenharmony_ci ret = snd_soc_component_initialize(comp_pcm, 11478c2ecf20Sopenharmony_ci &mt8173_afe_pcm_dai_component, 11488c2ecf20Sopenharmony_ci &pdev->dev); 11498c2ecf20Sopenharmony_ci if (ret) 11508c2ecf20Sopenharmony_ci goto err_pm_disable; 11518c2ecf20Sopenharmony_ci 11528c2ecf20Sopenharmony_ci#ifdef CONFIG_DEBUG_FS 11538c2ecf20Sopenharmony_ci comp_pcm->debugfs_prefix = "pcm"; 11548c2ecf20Sopenharmony_ci#endif 11558c2ecf20Sopenharmony_ci 11568c2ecf20Sopenharmony_ci ret = snd_soc_add_component(comp_pcm, 11578c2ecf20Sopenharmony_ci mt8173_afe_pcm_dais, 11588c2ecf20Sopenharmony_ci ARRAY_SIZE(mt8173_afe_pcm_dais)); 11598c2ecf20Sopenharmony_ci if (ret) 11608c2ecf20Sopenharmony_ci goto err_pm_disable; 11618c2ecf20Sopenharmony_ci 11628c2ecf20Sopenharmony_ci comp_hdmi = devm_kzalloc(&pdev->dev, sizeof(*comp_hdmi), GFP_KERNEL); 11638c2ecf20Sopenharmony_ci if (!comp_hdmi) { 11648c2ecf20Sopenharmony_ci ret = -ENOMEM; 11658c2ecf20Sopenharmony_ci goto err_cleanup_components; 11668c2ecf20Sopenharmony_ci } 11678c2ecf20Sopenharmony_ci 11688c2ecf20Sopenharmony_ci ret = snd_soc_component_initialize(comp_hdmi, 11698c2ecf20Sopenharmony_ci &mt8173_afe_hdmi_dai_component, 11708c2ecf20Sopenharmony_ci &pdev->dev); 11718c2ecf20Sopenharmony_ci if (ret) 11728c2ecf20Sopenharmony_ci goto err_cleanup_components; 11738c2ecf20Sopenharmony_ci 11748c2ecf20Sopenharmony_ci#ifdef CONFIG_DEBUG_FS 11758c2ecf20Sopenharmony_ci comp_hdmi->debugfs_prefix = "hdmi"; 11768c2ecf20Sopenharmony_ci#endif 11778c2ecf20Sopenharmony_ci 11788c2ecf20Sopenharmony_ci ret = snd_soc_add_component(comp_hdmi, 11798c2ecf20Sopenharmony_ci mt8173_afe_hdmi_dais, 11808c2ecf20Sopenharmony_ci ARRAY_SIZE(mt8173_afe_hdmi_dais)); 11818c2ecf20Sopenharmony_ci if (ret) 11828c2ecf20Sopenharmony_ci goto err_cleanup_components; 11838c2ecf20Sopenharmony_ci 11848c2ecf20Sopenharmony_ci ret = devm_request_irq(afe->dev, irq_id, mt8173_afe_irq_handler, 11858c2ecf20Sopenharmony_ci 0, "Afe_ISR_Handle", (void *)afe); 11868c2ecf20Sopenharmony_ci if (ret) { 11878c2ecf20Sopenharmony_ci dev_err(afe->dev, "could not request_irq\n"); 11888c2ecf20Sopenharmony_ci goto err_cleanup_components; 11898c2ecf20Sopenharmony_ci } 11908c2ecf20Sopenharmony_ci 11918c2ecf20Sopenharmony_ci dev_info(&pdev->dev, "MT8173 AFE driver initialized.\n"); 11928c2ecf20Sopenharmony_ci return 0; 11938c2ecf20Sopenharmony_ci 11948c2ecf20Sopenharmony_cierr_cleanup_components: 11958c2ecf20Sopenharmony_ci snd_soc_unregister_component(&pdev->dev); 11968c2ecf20Sopenharmony_cierr_pm_disable: 11978c2ecf20Sopenharmony_ci pm_runtime_disable(&pdev->dev); 11988c2ecf20Sopenharmony_ci return ret; 11998c2ecf20Sopenharmony_ci} 12008c2ecf20Sopenharmony_ci 12018c2ecf20Sopenharmony_cistatic int mt8173_afe_pcm_dev_remove(struct platform_device *pdev) 12028c2ecf20Sopenharmony_ci{ 12038c2ecf20Sopenharmony_ci snd_soc_unregister_component(&pdev->dev); 12048c2ecf20Sopenharmony_ci 12058c2ecf20Sopenharmony_ci pm_runtime_disable(&pdev->dev); 12068c2ecf20Sopenharmony_ci if (!pm_runtime_status_suspended(&pdev->dev)) 12078c2ecf20Sopenharmony_ci mt8173_afe_runtime_suspend(&pdev->dev); 12088c2ecf20Sopenharmony_ci return 0; 12098c2ecf20Sopenharmony_ci} 12108c2ecf20Sopenharmony_ci 12118c2ecf20Sopenharmony_cistatic const struct of_device_id mt8173_afe_pcm_dt_match[] = { 12128c2ecf20Sopenharmony_ci { .compatible = "mediatek,mt8173-afe-pcm", }, 12138c2ecf20Sopenharmony_ci { } 12148c2ecf20Sopenharmony_ci}; 12158c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, mt8173_afe_pcm_dt_match); 12168c2ecf20Sopenharmony_ci 12178c2ecf20Sopenharmony_cistatic const struct dev_pm_ops mt8173_afe_pm_ops = { 12188c2ecf20Sopenharmony_ci SET_RUNTIME_PM_OPS(mt8173_afe_runtime_suspend, 12198c2ecf20Sopenharmony_ci mt8173_afe_runtime_resume, NULL) 12208c2ecf20Sopenharmony_ci}; 12218c2ecf20Sopenharmony_ci 12228c2ecf20Sopenharmony_cistatic struct platform_driver mt8173_afe_pcm_driver = { 12238c2ecf20Sopenharmony_ci .driver = { 12248c2ecf20Sopenharmony_ci .name = "mt8173-afe-pcm", 12258c2ecf20Sopenharmony_ci .of_match_table = mt8173_afe_pcm_dt_match, 12268c2ecf20Sopenharmony_ci .pm = &mt8173_afe_pm_ops, 12278c2ecf20Sopenharmony_ci }, 12288c2ecf20Sopenharmony_ci .probe = mt8173_afe_pcm_dev_probe, 12298c2ecf20Sopenharmony_ci .remove = mt8173_afe_pcm_dev_remove, 12308c2ecf20Sopenharmony_ci}; 12318c2ecf20Sopenharmony_ci 12328c2ecf20Sopenharmony_cimodule_platform_driver(mt8173_afe_pcm_driver); 12338c2ecf20Sopenharmony_ci 12348c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Mediatek ALSA SoC AFE platform driver"); 12358c2ecf20Sopenharmony_ciMODULE_AUTHOR("Koro Chen <koro.chen@mediatek.com>"); 12368c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2"); 1237