18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * rt1305.c -- RT1305 ALSA SoC amplifier component driver 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright 2018 Realtek Semiconductor Corp. 68c2ecf20Sopenharmony_ci * Author: Shuming Fan <shumingf@realtek.com> 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include <linux/module.h> 108c2ecf20Sopenharmony_ci#include <linux/moduleparam.h> 118c2ecf20Sopenharmony_ci#include <linux/init.h> 128c2ecf20Sopenharmony_ci#include <linux/delay.h> 138c2ecf20Sopenharmony_ci#include <linux/pm.h> 148c2ecf20Sopenharmony_ci#include <linux/acpi.h> 158c2ecf20Sopenharmony_ci#include <linux/gpio.h> 168c2ecf20Sopenharmony_ci#include <linux/i2c.h> 178c2ecf20Sopenharmony_ci#include <linux/regmap.h> 188c2ecf20Sopenharmony_ci#include <linux/of_gpio.h> 198c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 208c2ecf20Sopenharmony_ci#include <linux/firmware.h> 218c2ecf20Sopenharmony_ci#include <sound/core.h> 228c2ecf20Sopenharmony_ci#include <sound/pcm.h> 238c2ecf20Sopenharmony_ci#include <sound/pcm_params.h> 248c2ecf20Sopenharmony_ci#include <sound/soc.h> 258c2ecf20Sopenharmony_ci#include <sound/soc-dapm.h> 268c2ecf20Sopenharmony_ci#include <sound/initval.h> 278c2ecf20Sopenharmony_ci#include <sound/tlv.h> 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci#include "rl6231.h" 308c2ecf20Sopenharmony_ci#include "rt1305.h" 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci#define RT1305_PR_RANGE_BASE (0xff + 1) 348c2ecf20Sopenharmony_ci#define RT1305_PR_SPACING 0x100 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci#define RT1305_PR_BASE (RT1305_PR_RANGE_BASE + (0 * RT1305_PR_SPACING)) 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_cistatic const struct regmap_range_cfg rt1305_ranges[] = { 408c2ecf20Sopenharmony_ci { 418c2ecf20Sopenharmony_ci .name = "PR", 428c2ecf20Sopenharmony_ci .range_min = RT1305_PR_BASE, 438c2ecf20Sopenharmony_ci .range_max = RT1305_PR_BASE + 0xff, 448c2ecf20Sopenharmony_ci .selector_reg = RT1305_PRIV_INDEX, 458c2ecf20Sopenharmony_ci .selector_mask = 0xff, 468c2ecf20Sopenharmony_ci .selector_shift = 0x0, 478c2ecf20Sopenharmony_ci .window_start = RT1305_PRIV_DATA, 488c2ecf20Sopenharmony_ci .window_len = 0x1, 498c2ecf20Sopenharmony_ci }, 508c2ecf20Sopenharmony_ci}; 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_cistatic const struct reg_sequence init_list[] = { 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci { RT1305_PR_BASE + 0xcf, 0x5548 }, 568c2ecf20Sopenharmony_ci { RT1305_PR_BASE + 0x5d, 0x0442 }, 578c2ecf20Sopenharmony_ci { RT1305_PR_BASE + 0xc1, 0x0320 }, 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci { RT1305_POWER_STATUS, 0x0000 }, 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci { RT1305_SPK_TEMP_PROTECTION_1, 0xd6de }, 628c2ecf20Sopenharmony_ci { RT1305_SPK_TEMP_PROTECTION_2, 0x0707 }, 638c2ecf20Sopenharmony_ci { RT1305_SPK_TEMP_PROTECTION_3, 0x4090 }, 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci { RT1305_DAC_SET_1, 0xdfdf }, /* 4 ohm 2W */ 668c2ecf20Sopenharmony_ci { RT1305_ADC_SET_3, 0x0219 }, 678c2ecf20Sopenharmony_ci { RT1305_ADC_SET_1, 0x170f }, /* 0.2 ohm RSense*/ 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci}; 708c2ecf20Sopenharmony_ci#define RT1305_INIT_REG_LEN ARRAY_SIZE(init_list) 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_cistruct rt1305_priv { 738c2ecf20Sopenharmony_ci struct snd_soc_component *component; 748c2ecf20Sopenharmony_ci struct regmap *regmap; 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci int sysclk; 778c2ecf20Sopenharmony_ci int sysclk_src; 788c2ecf20Sopenharmony_ci int lrck; 798c2ecf20Sopenharmony_ci int bclk; 808c2ecf20Sopenharmony_ci int master; 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci int pll_src; 838c2ecf20Sopenharmony_ci int pll_in; 848c2ecf20Sopenharmony_ci int pll_out; 858c2ecf20Sopenharmony_ci}; 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_cistatic const struct reg_default rt1305_reg[] = { 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci { 0x04, 0x0400 }, 908c2ecf20Sopenharmony_ci { 0x05, 0x0880 }, 918c2ecf20Sopenharmony_ci { 0x06, 0x0000 }, 928c2ecf20Sopenharmony_ci { 0x07, 0x3100 }, 938c2ecf20Sopenharmony_ci { 0x08, 0x8000 }, 948c2ecf20Sopenharmony_ci { 0x09, 0x0000 }, 958c2ecf20Sopenharmony_ci { 0x0a, 0x087e }, 968c2ecf20Sopenharmony_ci { 0x0b, 0x0020 }, 978c2ecf20Sopenharmony_ci { 0x0c, 0x0802 }, 988c2ecf20Sopenharmony_ci { 0x0d, 0x0020 }, 998c2ecf20Sopenharmony_ci { 0x10, 0x1d1d }, 1008c2ecf20Sopenharmony_ci { 0x11, 0x1d1d }, 1018c2ecf20Sopenharmony_ci { 0x12, 0xffff }, 1028c2ecf20Sopenharmony_ci { 0x14, 0x000c }, 1038c2ecf20Sopenharmony_ci { 0x16, 0x1717 }, 1048c2ecf20Sopenharmony_ci { 0x17, 0x4000 }, 1058c2ecf20Sopenharmony_ci { 0x18, 0x0019 }, 1068c2ecf20Sopenharmony_ci { 0x20, 0x0000 }, 1078c2ecf20Sopenharmony_ci { 0x22, 0x0000 }, 1088c2ecf20Sopenharmony_ci { 0x24, 0x0000 }, 1098c2ecf20Sopenharmony_ci { 0x26, 0x0000 }, 1108c2ecf20Sopenharmony_ci { 0x28, 0x0000 }, 1118c2ecf20Sopenharmony_ci { 0x2a, 0x4000 }, 1128c2ecf20Sopenharmony_ci { 0x2b, 0x3000 }, 1138c2ecf20Sopenharmony_ci { 0x2d, 0x6000 }, 1148c2ecf20Sopenharmony_ci { 0x2e, 0x0000 }, 1158c2ecf20Sopenharmony_ci { 0x2f, 0x8000 }, 1168c2ecf20Sopenharmony_ci { 0x32, 0x0000 }, 1178c2ecf20Sopenharmony_ci { 0x39, 0x0001 }, 1188c2ecf20Sopenharmony_ci { 0x3a, 0x0000 }, 1198c2ecf20Sopenharmony_ci { 0x3b, 0x1020 }, 1208c2ecf20Sopenharmony_ci { 0x3c, 0x0000 }, 1218c2ecf20Sopenharmony_ci { 0x3d, 0x0000 }, 1228c2ecf20Sopenharmony_ci { 0x3e, 0x4c00 }, 1238c2ecf20Sopenharmony_ci { 0x3f, 0x3000 }, 1248c2ecf20Sopenharmony_ci { 0x40, 0x000c }, 1258c2ecf20Sopenharmony_ci { 0x42, 0x0400 }, 1268c2ecf20Sopenharmony_ci { 0x46, 0xc22c }, 1278c2ecf20Sopenharmony_ci { 0x47, 0x0000 }, 1288c2ecf20Sopenharmony_ci { 0x4b, 0x0000 }, 1298c2ecf20Sopenharmony_ci { 0x4c, 0x0300 }, 1308c2ecf20Sopenharmony_ci { 0x4f, 0xf000 }, 1318c2ecf20Sopenharmony_ci { 0x50, 0xc200 }, 1328c2ecf20Sopenharmony_ci { 0x51, 0x1f1f }, 1338c2ecf20Sopenharmony_ci { 0x52, 0x01f0 }, 1348c2ecf20Sopenharmony_ci { 0x53, 0x407f }, 1358c2ecf20Sopenharmony_ci { 0x54, 0xffff }, 1368c2ecf20Sopenharmony_ci { 0x58, 0x4005 }, 1378c2ecf20Sopenharmony_ci { 0x5e, 0x0000 }, 1388c2ecf20Sopenharmony_ci { 0x5f, 0x0000 }, 1398c2ecf20Sopenharmony_ci { 0x60, 0xee13 }, 1408c2ecf20Sopenharmony_ci { 0x62, 0x0000 }, 1418c2ecf20Sopenharmony_ci { 0x63, 0x5f5f }, 1428c2ecf20Sopenharmony_ci { 0x64, 0x0040 }, 1438c2ecf20Sopenharmony_ci { 0x65, 0x4000 }, 1448c2ecf20Sopenharmony_ci { 0x66, 0x4004 }, 1458c2ecf20Sopenharmony_ci { 0x67, 0x0306 }, 1468c2ecf20Sopenharmony_ci { 0x68, 0x8c04 }, 1478c2ecf20Sopenharmony_ci { 0x69, 0xe021 }, 1488c2ecf20Sopenharmony_ci { 0x6a, 0x0000 }, 1498c2ecf20Sopenharmony_ci { 0x6c, 0xaaaa }, 1508c2ecf20Sopenharmony_ci { 0x70, 0x0333 }, 1518c2ecf20Sopenharmony_ci { 0x71, 0x3330 }, 1528c2ecf20Sopenharmony_ci { 0x72, 0x3333 }, 1538c2ecf20Sopenharmony_ci { 0x73, 0x3300 }, 1548c2ecf20Sopenharmony_ci { 0x74, 0x0000 }, 1558c2ecf20Sopenharmony_ci { 0x75, 0x0000 }, 1568c2ecf20Sopenharmony_ci { 0x76, 0x0000 }, 1578c2ecf20Sopenharmony_ci { 0x7a, 0x0003 }, 1588c2ecf20Sopenharmony_ci { 0x7c, 0x10ec }, 1598c2ecf20Sopenharmony_ci { 0x7e, 0x6251 }, 1608c2ecf20Sopenharmony_ci { 0x80, 0x0800 }, 1618c2ecf20Sopenharmony_ci { 0x81, 0x4000 }, 1628c2ecf20Sopenharmony_ci { 0x82, 0x0000 }, 1638c2ecf20Sopenharmony_ci { 0x90, 0x7a01 }, 1648c2ecf20Sopenharmony_ci { 0x91, 0x8431 }, 1658c2ecf20Sopenharmony_ci { 0x92, 0x0180 }, 1668c2ecf20Sopenharmony_ci { 0x93, 0x0000 }, 1678c2ecf20Sopenharmony_ci { 0x94, 0x0000 }, 1688c2ecf20Sopenharmony_ci { 0x95, 0x0000 }, 1698c2ecf20Sopenharmony_ci { 0x96, 0x0000 }, 1708c2ecf20Sopenharmony_ci { 0x97, 0x0000 }, 1718c2ecf20Sopenharmony_ci { 0x98, 0x0000 }, 1728c2ecf20Sopenharmony_ci { 0x99, 0x0000 }, 1738c2ecf20Sopenharmony_ci { 0x9a, 0x0000 }, 1748c2ecf20Sopenharmony_ci { 0x9b, 0x0000 }, 1758c2ecf20Sopenharmony_ci { 0x9c, 0x0000 }, 1768c2ecf20Sopenharmony_ci { 0x9d, 0x0000 }, 1778c2ecf20Sopenharmony_ci { 0x9e, 0x0000 }, 1788c2ecf20Sopenharmony_ci { 0x9f, 0x0000 }, 1798c2ecf20Sopenharmony_ci { 0xa0, 0x0000 }, 1808c2ecf20Sopenharmony_ci { 0xb0, 0x8200 }, 1818c2ecf20Sopenharmony_ci { 0xb1, 0x00ff }, 1828c2ecf20Sopenharmony_ci { 0xb2, 0x0008 }, 1838c2ecf20Sopenharmony_ci { 0xc0, 0x0200 }, 1848c2ecf20Sopenharmony_ci { 0xc1, 0x0000 }, 1858c2ecf20Sopenharmony_ci { 0xc2, 0x0000 }, 1868c2ecf20Sopenharmony_ci { 0xc3, 0x0000 }, 1878c2ecf20Sopenharmony_ci { 0xc4, 0x0000 }, 1888c2ecf20Sopenharmony_ci { 0xc5, 0x0000 }, 1898c2ecf20Sopenharmony_ci { 0xc6, 0x0000 }, 1908c2ecf20Sopenharmony_ci { 0xc7, 0x0000 }, 1918c2ecf20Sopenharmony_ci { 0xc8, 0x0000 }, 1928c2ecf20Sopenharmony_ci { 0xc9, 0x0000 }, 1938c2ecf20Sopenharmony_ci { 0xca, 0x0200 }, 1948c2ecf20Sopenharmony_ci { 0xcb, 0x0000 }, 1958c2ecf20Sopenharmony_ci { 0xcc, 0x0000 }, 1968c2ecf20Sopenharmony_ci { 0xcd, 0x0000 }, 1978c2ecf20Sopenharmony_ci { 0xce, 0x0000 }, 1988c2ecf20Sopenharmony_ci { 0xcf, 0x0000 }, 1998c2ecf20Sopenharmony_ci { 0xd0, 0x0000 }, 2008c2ecf20Sopenharmony_ci { 0xd1, 0x0000 }, 2018c2ecf20Sopenharmony_ci { 0xd2, 0x0000 }, 2028c2ecf20Sopenharmony_ci { 0xd3, 0x0000 }, 2038c2ecf20Sopenharmony_ci { 0xd4, 0x0200 }, 2048c2ecf20Sopenharmony_ci { 0xd5, 0x0000 }, 2058c2ecf20Sopenharmony_ci { 0xd6, 0x0000 }, 2068c2ecf20Sopenharmony_ci { 0xd7, 0x0000 }, 2078c2ecf20Sopenharmony_ci { 0xd8, 0x0000 }, 2088c2ecf20Sopenharmony_ci { 0xd9, 0x0000 }, 2098c2ecf20Sopenharmony_ci { 0xda, 0x0000 }, 2108c2ecf20Sopenharmony_ci { 0xdb, 0x0000 }, 2118c2ecf20Sopenharmony_ci { 0xdc, 0x0000 }, 2128c2ecf20Sopenharmony_ci { 0xdd, 0x0000 }, 2138c2ecf20Sopenharmony_ci { 0xde, 0x0200 }, 2148c2ecf20Sopenharmony_ci { 0xdf, 0x0000 }, 2158c2ecf20Sopenharmony_ci { 0xe0, 0x0000 }, 2168c2ecf20Sopenharmony_ci { 0xe1, 0x0000 }, 2178c2ecf20Sopenharmony_ci { 0xe2, 0x0000 }, 2188c2ecf20Sopenharmony_ci { 0xe3, 0x0000 }, 2198c2ecf20Sopenharmony_ci { 0xe4, 0x0000 }, 2208c2ecf20Sopenharmony_ci { 0xe5, 0x0000 }, 2218c2ecf20Sopenharmony_ci { 0xe6, 0x0000 }, 2228c2ecf20Sopenharmony_ci { 0xe7, 0x0000 }, 2238c2ecf20Sopenharmony_ci { 0xe8, 0x0200 }, 2248c2ecf20Sopenharmony_ci { 0xe9, 0x0000 }, 2258c2ecf20Sopenharmony_ci { 0xea, 0x0000 }, 2268c2ecf20Sopenharmony_ci { 0xeb, 0x0000 }, 2278c2ecf20Sopenharmony_ci { 0xec, 0x0000 }, 2288c2ecf20Sopenharmony_ci { 0xed, 0x0000 }, 2298c2ecf20Sopenharmony_ci { 0xee, 0x0000 }, 2308c2ecf20Sopenharmony_ci { 0xef, 0x0000 }, 2318c2ecf20Sopenharmony_ci { 0xf0, 0x0000 }, 2328c2ecf20Sopenharmony_ci { 0xf1, 0x0000 }, 2338c2ecf20Sopenharmony_ci { 0xf2, 0x0200 }, 2348c2ecf20Sopenharmony_ci { 0xf3, 0x0000 }, 2358c2ecf20Sopenharmony_ci { 0xf4, 0x0000 }, 2368c2ecf20Sopenharmony_ci { 0xf5, 0x0000 }, 2378c2ecf20Sopenharmony_ci { 0xf6, 0x0000 }, 2388c2ecf20Sopenharmony_ci { 0xf7, 0x0000 }, 2398c2ecf20Sopenharmony_ci { 0xf8, 0x0000 }, 2408c2ecf20Sopenharmony_ci { 0xf9, 0x0000 }, 2418c2ecf20Sopenharmony_ci { 0xfa, 0x0000 }, 2428c2ecf20Sopenharmony_ci { 0xfb, 0x0000 }, 2438c2ecf20Sopenharmony_ci}; 2448c2ecf20Sopenharmony_ci 2458c2ecf20Sopenharmony_cistatic int rt1305_reg_init(struct snd_soc_component *component) 2468c2ecf20Sopenharmony_ci{ 2478c2ecf20Sopenharmony_ci struct rt1305_priv *rt1305 = snd_soc_component_get_drvdata(component); 2488c2ecf20Sopenharmony_ci 2498c2ecf20Sopenharmony_ci regmap_multi_reg_write(rt1305->regmap, init_list, RT1305_INIT_REG_LEN); 2508c2ecf20Sopenharmony_ci return 0; 2518c2ecf20Sopenharmony_ci} 2528c2ecf20Sopenharmony_ci 2538c2ecf20Sopenharmony_cistatic bool rt1305_volatile_register(struct device *dev, unsigned int reg) 2548c2ecf20Sopenharmony_ci{ 2558c2ecf20Sopenharmony_ci int i; 2568c2ecf20Sopenharmony_ci 2578c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(rt1305_ranges); i++) { 2588c2ecf20Sopenharmony_ci if (reg >= rt1305_ranges[i].range_min && 2598c2ecf20Sopenharmony_ci reg <= rt1305_ranges[i].range_max) { 2608c2ecf20Sopenharmony_ci return true; 2618c2ecf20Sopenharmony_ci } 2628c2ecf20Sopenharmony_ci } 2638c2ecf20Sopenharmony_ci 2648c2ecf20Sopenharmony_ci switch (reg) { 2658c2ecf20Sopenharmony_ci case RT1305_RESET: 2668c2ecf20Sopenharmony_ci case RT1305_SPDIF_IN_SET_1: 2678c2ecf20Sopenharmony_ci case RT1305_SPDIF_IN_SET_2: 2688c2ecf20Sopenharmony_ci case RT1305_SPDIF_IN_SET_3: 2698c2ecf20Sopenharmony_ci case RT1305_POWER_CTRL_2: 2708c2ecf20Sopenharmony_ci case RT1305_CLOCK_DETECT: 2718c2ecf20Sopenharmony_ci case RT1305_BIQUAD_SET_1: 2728c2ecf20Sopenharmony_ci case RT1305_BIQUAD_SET_2: 2738c2ecf20Sopenharmony_ci case RT1305_EQ_SET_2: 2748c2ecf20Sopenharmony_ci case RT1305_SPK_TEMP_PROTECTION_0: 2758c2ecf20Sopenharmony_ci case RT1305_SPK_TEMP_PROTECTION_2: 2768c2ecf20Sopenharmony_ci case RT1305_SPK_DC_DETECT_1: 2778c2ecf20Sopenharmony_ci case RT1305_SILENCE_DETECT: 2788c2ecf20Sopenharmony_ci case RT1305_VERSION_ID: 2798c2ecf20Sopenharmony_ci case RT1305_VENDOR_ID: 2808c2ecf20Sopenharmony_ci case RT1305_DEVICE_ID: 2818c2ecf20Sopenharmony_ci case RT1305_EFUSE_1: 2828c2ecf20Sopenharmony_ci case RT1305_EFUSE_3: 2838c2ecf20Sopenharmony_ci case RT1305_DC_CALIB_1: 2848c2ecf20Sopenharmony_ci case RT1305_DC_CALIB_3: 2858c2ecf20Sopenharmony_ci case RT1305_DAC_OFFSET_1: 2868c2ecf20Sopenharmony_ci case RT1305_DAC_OFFSET_2: 2878c2ecf20Sopenharmony_ci case RT1305_DAC_OFFSET_3: 2888c2ecf20Sopenharmony_ci case RT1305_DAC_OFFSET_4: 2898c2ecf20Sopenharmony_ci case RT1305_DAC_OFFSET_5: 2908c2ecf20Sopenharmony_ci case RT1305_DAC_OFFSET_6: 2918c2ecf20Sopenharmony_ci case RT1305_DAC_OFFSET_7: 2928c2ecf20Sopenharmony_ci case RT1305_DAC_OFFSET_8: 2938c2ecf20Sopenharmony_ci case RT1305_DAC_OFFSET_9: 2948c2ecf20Sopenharmony_ci case RT1305_DAC_OFFSET_10: 2958c2ecf20Sopenharmony_ci case RT1305_DAC_OFFSET_11: 2968c2ecf20Sopenharmony_ci case RT1305_TRIM_1: 2978c2ecf20Sopenharmony_ci case RT1305_TRIM_2: 2988c2ecf20Sopenharmony_ci return true; 2998c2ecf20Sopenharmony_ci 3008c2ecf20Sopenharmony_ci default: 3018c2ecf20Sopenharmony_ci return false; 3028c2ecf20Sopenharmony_ci } 3038c2ecf20Sopenharmony_ci} 3048c2ecf20Sopenharmony_ci 3058c2ecf20Sopenharmony_cistatic bool rt1305_readable_register(struct device *dev, unsigned int reg) 3068c2ecf20Sopenharmony_ci{ 3078c2ecf20Sopenharmony_ci int i; 3088c2ecf20Sopenharmony_ci 3098c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(rt1305_ranges); i++) { 3108c2ecf20Sopenharmony_ci if (reg >= rt1305_ranges[i].range_min && 3118c2ecf20Sopenharmony_ci reg <= rt1305_ranges[i].range_max) { 3128c2ecf20Sopenharmony_ci return true; 3138c2ecf20Sopenharmony_ci } 3148c2ecf20Sopenharmony_ci } 3158c2ecf20Sopenharmony_ci 3168c2ecf20Sopenharmony_ci switch (reg) { 3178c2ecf20Sopenharmony_ci case RT1305_RESET: 3188c2ecf20Sopenharmony_ci case RT1305_CLK_1 ... RT1305_CAL_EFUSE_CLOCK: 3198c2ecf20Sopenharmony_ci case RT1305_PLL0_1 ... RT1305_PLL1_2: 3208c2ecf20Sopenharmony_ci case RT1305_MIXER_CTRL_1: 3218c2ecf20Sopenharmony_ci case RT1305_MIXER_CTRL_2: 3228c2ecf20Sopenharmony_ci case RT1305_DAC_SET_1: 3238c2ecf20Sopenharmony_ci case RT1305_DAC_SET_2: 3248c2ecf20Sopenharmony_ci case RT1305_ADC_SET_1: 3258c2ecf20Sopenharmony_ci case RT1305_ADC_SET_2: 3268c2ecf20Sopenharmony_ci case RT1305_ADC_SET_3: 3278c2ecf20Sopenharmony_ci case RT1305_PATH_SET: 3288c2ecf20Sopenharmony_ci case RT1305_SPDIF_IN_SET_1: 3298c2ecf20Sopenharmony_ci case RT1305_SPDIF_IN_SET_2: 3308c2ecf20Sopenharmony_ci case RT1305_SPDIF_IN_SET_3: 3318c2ecf20Sopenharmony_ci case RT1305_SPDIF_OUT_SET_1: 3328c2ecf20Sopenharmony_ci case RT1305_SPDIF_OUT_SET_2: 3338c2ecf20Sopenharmony_ci case RT1305_SPDIF_OUT_SET_3: 3348c2ecf20Sopenharmony_ci case RT1305_I2S_SET_1: 3358c2ecf20Sopenharmony_ci case RT1305_I2S_SET_2: 3368c2ecf20Sopenharmony_ci case RT1305_PBTL_MONO_MODE_SRC: 3378c2ecf20Sopenharmony_ci case RT1305_MANUALLY_I2C_DEVICE: 3388c2ecf20Sopenharmony_ci case RT1305_POWER_STATUS: 3398c2ecf20Sopenharmony_ci case RT1305_POWER_CTRL_1: 3408c2ecf20Sopenharmony_ci case RT1305_POWER_CTRL_2: 3418c2ecf20Sopenharmony_ci case RT1305_POWER_CTRL_3: 3428c2ecf20Sopenharmony_ci case RT1305_POWER_CTRL_4: 3438c2ecf20Sopenharmony_ci case RT1305_POWER_CTRL_5: 3448c2ecf20Sopenharmony_ci case RT1305_CLOCK_DETECT: 3458c2ecf20Sopenharmony_ci case RT1305_BIQUAD_SET_1: 3468c2ecf20Sopenharmony_ci case RT1305_BIQUAD_SET_2: 3478c2ecf20Sopenharmony_ci case RT1305_ADJUSTED_HPF_1: 3488c2ecf20Sopenharmony_ci case RT1305_ADJUSTED_HPF_2: 3498c2ecf20Sopenharmony_ci case RT1305_EQ_SET_1: 3508c2ecf20Sopenharmony_ci case RT1305_EQ_SET_2: 3518c2ecf20Sopenharmony_ci case RT1305_SPK_TEMP_PROTECTION_0: 3528c2ecf20Sopenharmony_ci case RT1305_SPK_TEMP_PROTECTION_1: 3538c2ecf20Sopenharmony_ci case RT1305_SPK_TEMP_PROTECTION_2: 3548c2ecf20Sopenharmony_ci case RT1305_SPK_TEMP_PROTECTION_3: 3558c2ecf20Sopenharmony_ci case RT1305_SPK_DC_DETECT_1: 3568c2ecf20Sopenharmony_ci case RT1305_SPK_DC_DETECT_2: 3578c2ecf20Sopenharmony_ci case RT1305_LOUDNESS: 3588c2ecf20Sopenharmony_ci case RT1305_THERMAL_FOLD_BACK_1: 3598c2ecf20Sopenharmony_ci case RT1305_THERMAL_FOLD_BACK_2: 3608c2ecf20Sopenharmony_ci case RT1305_SILENCE_DETECT ... RT1305_SPK_EXCURSION_LIMITER_7: 3618c2ecf20Sopenharmony_ci case RT1305_VERSION_ID: 3628c2ecf20Sopenharmony_ci case RT1305_VENDOR_ID: 3638c2ecf20Sopenharmony_ci case RT1305_DEVICE_ID: 3648c2ecf20Sopenharmony_ci case RT1305_EFUSE_1: 3658c2ecf20Sopenharmony_ci case RT1305_EFUSE_2: 3668c2ecf20Sopenharmony_ci case RT1305_EFUSE_3: 3678c2ecf20Sopenharmony_ci case RT1305_DC_CALIB_1: 3688c2ecf20Sopenharmony_ci case RT1305_DC_CALIB_2: 3698c2ecf20Sopenharmony_ci case RT1305_DC_CALIB_3: 3708c2ecf20Sopenharmony_ci case RT1305_DAC_OFFSET_1 ... RT1305_DAC_OFFSET_14: 3718c2ecf20Sopenharmony_ci case RT1305_TRIM_1: 3728c2ecf20Sopenharmony_ci case RT1305_TRIM_2: 3738c2ecf20Sopenharmony_ci case RT1305_TUNE_INTERNAL_OSC: 3748c2ecf20Sopenharmony_ci case RT1305_BIQUAD1_H0_L_28_16 ... RT1305_BIQUAD3_A2_R_15_0: 3758c2ecf20Sopenharmony_ci return true; 3768c2ecf20Sopenharmony_ci default: 3778c2ecf20Sopenharmony_ci return false; 3788c2ecf20Sopenharmony_ci } 3798c2ecf20Sopenharmony_ci} 3808c2ecf20Sopenharmony_ci 3818c2ecf20Sopenharmony_cistatic const DECLARE_TLV_DB_SCALE(dac_vol_tlv, -9435, 37, 0); 3828c2ecf20Sopenharmony_ci 3838c2ecf20Sopenharmony_cistatic const char * const rt1305_rx_data_ch_select[] = { 3848c2ecf20Sopenharmony_ci "LR", 3858c2ecf20Sopenharmony_ci "RL", 3868c2ecf20Sopenharmony_ci "Copy L", 3878c2ecf20Sopenharmony_ci "Copy R", 3888c2ecf20Sopenharmony_ci}; 3898c2ecf20Sopenharmony_ci 3908c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL(rt1305_rx_data_ch_enum, RT1305_I2S_SET_2, 2, 3918c2ecf20Sopenharmony_ci rt1305_rx_data_ch_select); 3928c2ecf20Sopenharmony_ci 3938c2ecf20Sopenharmony_cistatic void rt1305_reset(struct regmap *regmap) 3948c2ecf20Sopenharmony_ci{ 3958c2ecf20Sopenharmony_ci regmap_write(regmap, RT1305_RESET, 0); 3968c2ecf20Sopenharmony_ci} 3978c2ecf20Sopenharmony_ci 3988c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt1305_snd_controls[] = { 3998c2ecf20Sopenharmony_ci SOC_DOUBLE_TLV("DAC Playback Volume", RT1305_DAC_SET_1, 4008c2ecf20Sopenharmony_ci 8, 0, 0xff, 0, dac_vol_tlv), 4018c2ecf20Sopenharmony_ci 4028c2ecf20Sopenharmony_ci /* I2S Data Channel Selection */ 4038c2ecf20Sopenharmony_ci SOC_ENUM("RX Channel Select", rt1305_rx_data_ch_enum), 4048c2ecf20Sopenharmony_ci}; 4058c2ecf20Sopenharmony_ci 4068c2ecf20Sopenharmony_cistatic int rt1305_is_rc_clk_from_pll(struct snd_soc_dapm_widget *source, 4078c2ecf20Sopenharmony_ci struct snd_soc_dapm_widget *sink) 4088c2ecf20Sopenharmony_ci{ 4098c2ecf20Sopenharmony_ci struct snd_soc_component *component = 4108c2ecf20Sopenharmony_ci snd_soc_dapm_to_component(source->dapm); 4118c2ecf20Sopenharmony_ci struct rt1305_priv *rt1305 = snd_soc_component_get_drvdata(component); 4128c2ecf20Sopenharmony_ci unsigned int val; 4138c2ecf20Sopenharmony_ci 4148c2ecf20Sopenharmony_ci val = snd_soc_component_read(component, RT1305_CLK_1); 4158c2ecf20Sopenharmony_ci 4168c2ecf20Sopenharmony_ci if (rt1305->sysclk_src == RT1305_FS_SYS_PRE_S_PLL1 && 4178c2ecf20Sopenharmony_ci (val & RT1305_SEL_PLL_SRC_2_RCCLK)) 4188c2ecf20Sopenharmony_ci return 1; 4198c2ecf20Sopenharmony_ci else 4208c2ecf20Sopenharmony_ci return 0; 4218c2ecf20Sopenharmony_ci} 4228c2ecf20Sopenharmony_ci 4238c2ecf20Sopenharmony_cistatic int rt1305_is_sys_clk_from_pll(struct snd_soc_dapm_widget *source, 4248c2ecf20Sopenharmony_ci struct snd_soc_dapm_widget *sink) 4258c2ecf20Sopenharmony_ci{ 4268c2ecf20Sopenharmony_ci struct snd_soc_component *component = 4278c2ecf20Sopenharmony_ci snd_soc_dapm_to_component(source->dapm); 4288c2ecf20Sopenharmony_ci struct rt1305_priv *rt1305 = snd_soc_component_get_drvdata(component); 4298c2ecf20Sopenharmony_ci 4308c2ecf20Sopenharmony_ci if (rt1305->sysclk_src == RT1305_FS_SYS_PRE_S_PLL1) 4318c2ecf20Sopenharmony_ci return 1; 4328c2ecf20Sopenharmony_ci else 4338c2ecf20Sopenharmony_ci return 0; 4348c2ecf20Sopenharmony_ci} 4358c2ecf20Sopenharmony_ci 4368c2ecf20Sopenharmony_cistatic int rt1305_classd_event(struct snd_soc_dapm_widget *w, 4378c2ecf20Sopenharmony_ci struct snd_kcontrol *kcontrol, int event) 4388c2ecf20Sopenharmony_ci{ 4398c2ecf20Sopenharmony_ci struct snd_soc_component *component = 4408c2ecf20Sopenharmony_ci snd_soc_dapm_to_component(w->dapm); 4418c2ecf20Sopenharmony_ci 4428c2ecf20Sopenharmony_ci switch (event) { 4438c2ecf20Sopenharmony_ci case SND_SOC_DAPM_POST_PMU: 4448c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT1305_POWER_CTRL_1, 4458c2ecf20Sopenharmony_ci RT1305_POW_PDB_JD_MASK, RT1305_POW_PDB_JD); 4468c2ecf20Sopenharmony_ci break; 4478c2ecf20Sopenharmony_ci case SND_SOC_DAPM_PRE_PMD: 4488c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT1305_POWER_CTRL_1, 4498c2ecf20Sopenharmony_ci RT1305_POW_PDB_JD_MASK, 0); 4508c2ecf20Sopenharmony_ci usleep_range(150000, 200000); 4518c2ecf20Sopenharmony_ci break; 4528c2ecf20Sopenharmony_ci 4538c2ecf20Sopenharmony_ci default: 4548c2ecf20Sopenharmony_ci return 0; 4558c2ecf20Sopenharmony_ci } 4568c2ecf20Sopenharmony_ci 4578c2ecf20Sopenharmony_ci return 0; 4588c2ecf20Sopenharmony_ci} 4598c2ecf20Sopenharmony_ci 4608c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt1305_sto_dac_l = 4618c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("Switch", RT1305_DAC_SET_2, 4628c2ecf20Sopenharmony_ci RT1305_DVOL_MUTE_L_EN_SFT, 1, 1); 4638c2ecf20Sopenharmony_ci 4648c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt1305_sto_dac_r = 4658c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("Switch", RT1305_DAC_SET_2, 4668c2ecf20Sopenharmony_ci RT1305_DVOL_MUTE_R_EN_SFT, 1, 1); 4678c2ecf20Sopenharmony_ci 4688c2ecf20Sopenharmony_cistatic const struct snd_soc_dapm_widget rt1305_dapm_widgets[] = { 4698c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("PLL0", RT1305_POWER_CTRL_1, 4708c2ecf20Sopenharmony_ci RT1305_POW_PLL0_EN_BIT, 0, NULL, 0), 4718c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("PLL1", RT1305_POWER_CTRL_1, 4728c2ecf20Sopenharmony_ci RT1305_POW_PLL1_EN_BIT, 0, NULL, 0), 4738c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("MBIAS", RT1305_POWER_CTRL_1, 4748c2ecf20Sopenharmony_ci RT1305_POW_MBIAS_LV_BIT, 0, NULL, 0), 4758c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("BG MBIAS", RT1305_POWER_CTRL_1, 4768c2ecf20Sopenharmony_ci RT1305_POW_BG_MBIAS_LV_BIT, 0, NULL, 0), 4778c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("LDO2", RT1305_POWER_CTRL_1, 4788c2ecf20Sopenharmony_ci RT1305_POW_LDO2_BIT, 0, NULL, 0), 4798c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("BG2", RT1305_POWER_CTRL_1, 4808c2ecf20Sopenharmony_ci RT1305_POW_BG2_BIT, 0, NULL, 0), 4818c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("LDO2 IB2", RT1305_POWER_CTRL_1, 4828c2ecf20Sopenharmony_ci RT1305_POW_LDO2_IB2_BIT, 0, NULL, 0), 4838c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("VREF", RT1305_POWER_CTRL_1, 4848c2ecf20Sopenharmony_ci RT1305_POW_VREF_BIT, 0, NULL, 0), 4858c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("VREF1", RT1305_POWER_CTRL_1, 4868c2ecf20Sopenharmony_ci RT1305_POW_VREF1_BIT, 0, NULL, 0), 4878c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("VREF2", RT1305_POWER_CTRL_1, 4888c2ecf20Sopenharmony_ci RT1305_POW_VREF2_BIT, 0, NULL, 0), 4898c2ecf20Sopenharmony_ci 4908c2ecf20Sopenharmony_ci 4918c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("DISC VREF", RT1305_POWER_CTRL_2, 4928c2ecf20Sopenharmony_ci RT1305_POW_DISC_VREF_BIT, 0, NULL, 0), 4938c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("FASTB VREF", RT1305_POWER_CTRL_2, 4948c2ecf20Sopenharmony_ci RT1305_POW_FASTB_VREF_BIT, 0, NULL, 0), 4958c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("ULTRA FAST VREF", RT1305_POWER_CTRL_2, 4968c2ecf20Sopenharmony_ci RT1305_POW_ULTRA_FAST_VREF_BIT, 0, NULL, 0), 4978c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("CHOP DAC", RT1305_POWER_CTRL_2, 4988c2ecf20Sopenharmony_ci RT1305_POW_CKXEN_DAC_BIT, 0, NULL, 0), 4998c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("CKGEN DAC", RT1305_POWER_CTRL_2, 5008c2ecf20Sopenharmony_ci RT1305_POW_EN_CKGEN_DAC_BIT, 0, NULL, 0), 5018c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("CLAMP", RT1305_POWER_CTRL_2, 5028c2ecf20Sopenharmony_ci RT1305_POW_CLAMP_BIT, 0, NULL, 0), 5038c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("BUFL", RT1305_POWER_CTRL_2, 5048c2ecf20Sopenharmony_ci RT1305_POW_BUFL_BIT, 0, NULL, 0), 5058c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("BUFR", RT1305_POWER_CTRL_2, 5068c2ecf20Sopenharmony_ci RT1305_POW_BUFR_BIT, 0, NULL, 0), 5078c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("CKGEN ADC", RT1305_POWER_CTRL_2, 5088c2ecf20Sopenharmony_ci RT1305_POW_EN_CKGEN_ADC_BIT, 0, NULL, 0), 5098c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("ADC3 L", RT1305_POWER_CTRL_2, 5108c2ecf20Sopenharmony_ci RT1305_POW_ADC3_L_BIT, 0, NULL, 0), 5118c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("ADC3 R", RT1305_POWER_CTRL_2, 5128c2ecf20Sopenharmony_ci RT1305_POW_ADC3_R_BIT, 0, NULL, 0), 5138c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("TRIOSC", RT1305_POWER_CTRL_2, 5148c2ecf20Sopenharmony_ci RT1305_POW_TRIOSC_BIT, 0, NULL, 0), 5158c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("AVDD1", RT1305_POWER_CTRL_2, 5168c2ecf20Sopenharmony_ci RT1305_POR_AVDD1_BIT, 0, NULL, 0), 5178c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("AVDD2", RT1305_POWER_CTRL_2, 5188c2ecf20Sopenharmony_ci RT1305_POR_AVDD2_BIT, 0, NULL, 0), 5198c2ecf20Sopenharmony_ci 5208c2ecf20Sopenharmony_ci 5218c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("VSENSE R", RT1305_POWER_CTRL_3, 5228c2ecf20Sopenharmony_ci RT1305_POW_VSENSE_RCH_BIT, 0, NULL, 0), 5238c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("VSENSE L", RT1305_POWER_CTRL_3, 5248c2ecf20Sopenharmony_ci RT1305_POW_VSENSE_LCH_BIT, 0, NULL, 0), 5258c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("ISENSE R", RT1305_POWER_CTRL_3, 5268c2ecf20Sopenharmony_ci RT1305_POW_ISENSE_RCH_BIT, 0, NULL, 0), 5278c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("ISENSE L", RT1305_POWER_CTRL_3, 5288c2ecf20Sopenharmony_ci RT1305_POW_ISENSE_LCH_BIT, 0, NULL, 0), 5298c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("POR AVDD1", RT1305_POWER_CTRL_3, 5308c2ecf20Sopenharmony_ci RT1305_POW_POR_AVDD1_BIT, 0, NULL, 0), 5318c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("POR AVDD2", RT1305_POWER_CTRL_3, 5328c2ecf20Sopenharmony_ci RT1305_POW_POR_AVDD2_BIT, 0, NULL, 0), 5338c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("VCM 6172", RT1305_POWER_CTRL_3, 5348c2ecf20Sopenharmony_ci RT1305_EN_VCM_6172_BIT, 0, NULL, 0), 5358c2ecf20Sopenharmony_ci 5368c2ecf20Sopenharmony_ci 5378c2ecf20Sopenharmony_ci /* Audio Interface */ 5388c2ecf20Sopenharmony_ci SND_SOC_DAPM_AIF_IN("AIF1RX", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0), 5398c2ecf20Sopenharmony_ci 5408c2ecf20Sopenharmony_ci /* Digital Interface */ 5418c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("DAC L Power", RT1305_POWER_CTRL_2, 5428c2ecf20Sopenharmony_ci RT1305_POW_DAC1_L_BIT, 0, NULL, 0), 5438c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("DAC R Power", RT1305_POWER_CTRL_2, 5448c2ecf20Sopenharmony_ci RT1305_POW_DAC1_R_BIT, 0, NULL, 0), 5458c2ecf20Sopenharmony_ci SND_SOC_DAPM_DAC("DAC", NULL, SND_SOC_NOPM, 0, 0), 5468c2ecf20Sopenharmony_ci SND_SOC_DAPM_SWITCH("DAC L", SND_SOC_NOPM, 0, 0, &rt1305_sto_dac_l), 5478c2ecf20Sopenharmony_ci SND_SOC_DAPM_SWITCH("DAC R", SND_SOC_NOPM, 0, 0, &rt1305_sto_dac_r), 5488c2ecf20Sopenharmony_ci 5498c2ecf20Sopenharmony_ci /* Output Lines */ 5508c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA_E("CLASS D", SND_SOC_NOPM, 0, 0, NULL, 0, 5518c2ecf20Sopenharmony_ci rt1305_classd_event, 5528c2ecf20Sopenharmony_ci SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), 5538c2ecf20Sopenharmony_ci SND_SOC_DAPM_OUTPUT("SPOL"), 5548c2ecf20Sopenharmony_ci SND_SOC_DAPM_OUTPUT("SPOR"), 5558c2ecf20Sopenharmony_ci}; 5568c2ecf20Sopenharmony_ci 5578c2ecf20Sopenharmony_cistatic const struct snd_soc_dapm_route rt1305_dapm_routes[] = { 5588c2ecf20Sopenharmony_ci 5598c2ecf20Sopenharmony_ci { "DAC", NULL, "AIF1RX" }, 5608c2ecf20Sopenharmony_ci 5618c2ecf20Sopenharmony_ci { "DAC", NULL, "PLL0", rt1305_is_rc_clk_from_pll }, 5628c2ecf20Sopenharmony_ci { "DAC", NULL, "PLL1", rt1305_is_sys_clk_from_pll }, 5638c2ecf20Sopenharmony_ci 5648c2ecf20Sopenharmony_ci { "DAC", NULL, "MBIAS" }, 5658c2ecf20Sopenharmony_ci { "DAC", NULL, "BG MBIAS" }, 5668c2ecf20Sopenharmony_ci { "DAC", NULL, "LDO2" }, 5678c2ecf20Sopenharmony_ci { "DAC", NULL, "BG2" }, 5688c2ecf20Sopenharmony_ci { "DAC", NULL, "LDO2 IB2" }, 5698c2ecf20Sopenharmony_ci { "DAC", NULL, "VREF" }, 5708c2ecf20Sopenharmony_ci { "DAC", NULL, "VREF1" }, 5718c2ecf20Sopenharmony_ci { "DAC", NULL, "VREF2" }, 5728c2ecf20Sopenharmony_ci 5738c2ecf20Sopenharmony_ci { "DAC", NULL, "DISC VREF" }, 5748c2ecf20Sopenharmony_ci { "DAC", NULL, "FASTB VREF" }, 5758c2ecf20Sopenharmony_ci { "DAC", NULL, "ULTRA FAST VREF" }, 5768c2ecf20Sopenharmony_ci { "DAC", NULL, "CHOP DAC" }, 5778c2ecf20Sopenharmony_ci { "DAC", NULL, "CKGEN DAC" }, 5788c2ecf20Sopenharmony_ci { "DAC", NULL, "CLAMP" }, 5798c2ecf20Sopenharmony_ci { "DAC", NULL, "CKGEN ADC" }, 5808c2ecf20Sopenharmony_ci { "DAC", NULL, "TRIOSC" }, 5818c2ecf20Sopenharmony_ci { "DAC", NULL, "AVDD1" }, 5828c2ecf20Sopenharmony_ci { "DAC", NULL, "AVDD2" }, 5838c2ecf20Sopenharmony_ci 5848c2ecf20Sopenharmony_ci { "DAC", NULL, "POR AVDD1" }, 5858c2ecf20Sopenharmony_ci { "DAC", NULL, "POR AVDD2" }, 5868c2ecf20Sopenharmony_ci { "DAC", NULL, "VCM 6172" }, 5878c2ecf20Sopenharmony_ci 5888c2ecf20Sopenharmony_ci { "DAC L", "Switch", "DAC" }, 5898c2ecf20Sopenharmony_ci { "DAC R", "Switch", "DAC" }, 5908c2ecf20Sopenharmony_ci 5918c2ecf20Sopenharmony_ci { "DAC R", NULL, "VSENSE R" }, 5928c2ecf20Sopenharmony_ci { "DAC L", NULL, "VSENSE L" }, 5938c2ecf20Sopenharmony_ci { "DAC R", NULL, "ISENSE R" }, 5948c2ecf20Sopenharmony_ci { "DAC L", NULL, "ISENSE L" }, 5958c2ecf20Sopenharmony_ci { "DAC L", NULL, "ADC3 L" }, 5968c2ecf20Sopenharmony_ci { "DAC R", NULL, "ADC3 R" }, 5978c2ecf20Sopenharmony_ci { "DAC L", NULL, "BUFL" }, 5988c2ecf20Sopenharmony_ci { "DAC R", NULL, "BUFR" }, 5998c2ecf20Sopenharmony_ci { "DAC L", NULL, "DAC L Power" }, 6008c2ecf20Sopenharmony_ci { "DAC R", NULL, "DAC R Power" }, 6018c2ecf20Sopenharmony_ci 6028c2ecf20Sopenharmony_ci { "CLASS D", NULL, "DAC L" }, 6038c2ecf20Sopenharmony_ci { "CLASS D", NULL, "DAC R" }, 6048c2ecf20Sopenharmony_ci 6058c2ecf20Sopenharmony_ci { "SPOL", NULL, "CLASS D" }, 6068c2ecf20Sopenharmony_ci { "SPOR", NULL, "CLASS D" }, 6078c2ecf20Sopenharmony_ci}; 6088c2ecf20Sopenharmony_ci 6098c2ecf20Sopenharmony_cistatic int rt1305_get_clk_info(int sclk, int rate) 6108c2ecf20Sopenharmony_ci{ 6118c2ecf20Sopenharmony_ci int i; 6128c2ecf20Sopenharmony_ci static const int pd[] = {1, 2, 3, 4, 6, 8, 12, 16}; 6138c2ecf20Sopenharmony_ci 6148c2ecf20Sopenharmony_ci if (sclk <= 0 || rate <= 0) 6158c2ecf20Sopenharmony_ci return -EINVAL; 6168c2ecf20Sopenharmony_ci 6178c2ecf20Sopenharmony_ci rate = rate << 8; 6188c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(pd); i++) 6198c2ecf20Sopenharmony_ci if (sclk == rate * pd[i]) 6208c2ecf20Sopenharmony_ci return i; 6218c2ecf20Sopenharmony_ci 6228c2ecf20Sopenharmony_ci return -EINVAL; 6238c2ecf20Sopenharmony_ci} 6248c2ecf20Sopenharmony_ci 6258c2ecf20Sopenharmony_cistatic int rt1305_hw_params(struct snd_pcm_substream *substream, 6268c2ecf20Sopenharmony_ci struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) 6278c2ecf20Sopenharmony_ci{ 6288c2ecf20Sopenharmony_ci struct snd_soc_component *component = dai->component; 6298c2ecf20Sopenharmony_ci struct rt1305_priv *rt1305 = snd_soc_component_get_drvdata(component); 6308c2ecf20Sopenharmony_ci unsigned int val_len = 0, val_clk, mask_clk; 6318c2ecf20Sopenharmony_ci int pre_div, bclk_ms, frame_size; 6328c2ecf20Sopenharmony_ci 6338c2ecf20Sopenharmony_ci rt1305->lrck = params_rate(params); 6348c2ecf20Sopenharmony_ci pre_div = rt1305_get_clk_info(rt1305->sysclk, rt1305->lrck); 6358c2ecf20Sopenharmony_ci if (pre_div < 0) { 6368c2ecf20Sopenharmony_ci dev_warn(component->dev, "Force using PLL "); 6378c2ecf20Sopenharmony_ci snd_soc_dai_set_pll(dai, 0, RT1305_PLL1_S_BCLK, 6388c2ecf20Sopenharmony_ci rt1305->lrck * 64, rt1305->lrck * 256); 6398c2ecf20Sopenharmony_ci snd_soc_dai_set_sysclk(dai, RT1305_FS_SYS_PRE_S_PLL1, 6408c2ecf20Sopenharmony_ci rt1305->lrck * 256, SND_SOC_CLOCK_IN); 6418c2ecf20Sopenharmony_ci pre_div = 0; 6428c2ecf20Sopenharmony_ci } 6438c2ecf20Sopenharmony_ci frame_size = snd_soc_params_to_frame_size(params); 6448c2ecf20Sopenharmony_ci if (frame_size < 0) { 6458c2ecf20Sopenharmony_ci dev_err(component->dev, "Unsupported frame size: %d\n", 6468c2ecf20Sopenharmony_ci frame_size); 6478c2ecf20Sopenharmony_ci return -EINVAL; 6488c2ecf20Sopenharmony_ci } 6498c2ecf20Sopenharmony_ci 6508c2ecf20Sopenharmony_ci bclk_ms = frame_size > 32; 6518c2ecf20Sopenharmony_ci rt1305->bclk = rt1305->lrck * (32 << bclk_ms); 6528c2ecf20Sopenharmony_ci 6538c2ecf20Sopenharmony_ci dev_dbg(component->dev, "bclk_ms is %d and pre_div is %d for iis %d\n", 6548c2ecf20Sopenharmony_ci bclk_ms, pre_div, dai->id); 6558c2ecf20Sopenharmony_ci 6568c2ecf20Sopenharmony_ci dev_dbg(component->dev, "lrck is %dHz and pre_div is %d for iis %d\n", 6578c2ecf20Sopenharmony_ci rt1305->lrck, pre_div, dai->id); 6588c2ecf20Sopenharmony_ci 6598c2ecf20Sopenharmony_ci switch (params_width(params)) { 6608c2ecf20Sopenharmony_ci case 16: 6618c2ecf20Sopenharmony_ci val_len |= RT1305_I2S_DL_SEL_16B; 6628c2ecf20Sopenharmony_ci break; 6638c2ecf20Sopenharmony_ci case 20: 6648c2ecf20Sopenharmony_ci val_len |= RT1305_I2S_DL_SEL_20B; 6658c2ecf20Sopenharmony_ci break; 6668c2ecf20Sopenharmony_ci case 24: 6678c2ecf20Sopenharmony_ci val_len |= RT1305_I2S_DL_SEL_24B; 6688c2ecf20Sopenharmony_ci break; 6698c2ecf20Sopenharmony_ci case 8: 6708c2ecf20Sopenharmony_ci val_len |= RT1305_I2S_DL_SEL_8B; 6718c2ecf20Sopenharmony_ci break; 6728c2ecf20Sopenharmony_ci default: 6738c2ecf20Sopenharmony_ci return -EINVAL; 6748c2ecf20Sopenharmony_ci } 6758c2ecf20Sopenharmony_ci 6768c2ecf20Sopenharmony_ci switch (dai->id) { 6778c2ecf20Sopenharmony_ci case RT1305_AIF1: 6788c2ecf20Sopenharmony_ci mask_clk = RT1305_DIV_FS_SYS_MASK; 6798c2ecf20Sopenharmony_ci val_clk = pre_div << RT1305_DIV_FS_SYS_SFT; 6808c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT1305_I2S_SET_2, 6818c2ecf20Sopenharmony_ci RT1305_I2S_DL_SEL_MASK, 6828c2ecf20Sopenharmony_ci val_len); 6838c2ecf20Sopenharmony_ci break; 6848c2ecf20Sopenharmony_ci default: 6858c2ecf20Sopenharmony_ci dev_err(component->dev, "Invalid dai->id: %d\n", dai->id); 6868c2ecf20Sopenharmony_ci return -EINVAL; 6878c2ecf20Sopenharmony_ci } 6888c2ecf20Sopenharmony_ci 6898c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT1305_CLK_2, 6908c2ecf20Sopenharmony_ci mask_clk, val_clk); 6918c2ecf20Sopenharmony_ci 6928c2ecf20Sopenharmony_ci return 0; 6938c2ecf20Sopenharmony_ci} 6948c2ecf20Sopenharmony_ci 6958c2ecf20Sopenharmony_cistatic int rt1305_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) 6968c2ecf20Sopenharmony_ci{ 6978c2ecf20Sopenharmony_ci struct snd_soc_component *component = dai->component; 6988c2ecf20Sopenharmony_ci struct rt1305_priv *rt1305 = snd_soc_component_get_drvdata(component); 6998c2ecf20Sopenharmony_ci unsigned int reg_val = 0, reg1_val = 0; 7008c2ecf20Sopenharmony_ci 7018c2ecf20Sopenharmony_ci switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { 7028c2ecf20Sopenharmony_ci case SND_SOC_DAIFMT_CBM_CFM: 7038c2ecf20Sopenharmony_ci reg_val |= RT1305_SEL_I2S_OUT_MODE_M; 7048c2ecf20Sopenharmony_ci rt1305->master = 1; 7058c2ecf20Sopenharmony_ci break; 7068c2ecf20Sopenharmony_ci case SND_SOC_DAIFMT_CBS_CFS: 7078c2ecf20Sopenharmony_ci reg_val |= RT1305_SEL_I2S_OUT_MODE_S; 7088c2ecf20Sopenharmony_ci rt1305->master = 0; 7098c2ecf20Sopenharmony_ci break; 7108c2ecf20Sopenharmony_ci default: 7118c2ecf20Sopenharmony_ci return -EINVAL; 7128c2ecf20Sopenharmony_ci } 7138c2ecf20Sopenharmony_ci 7148c2ecf20Sopenharmony_ci switch (fmt & SND_SOC_DAIFMT_INV_MASK) { 7158c2ecf20Sopenharmony_ci case SND_SOC_DAIFMT_NB_NF: 7168c2ecf20Sopenharmony_ci break; 7178c2ecf20Sopenharmony_ci case SND_SOC_DAIFMT_IB_NF: 7188c2ecf20Sopenharmony_ci reg1_val |= RT1305_I2S_BCLK_INV; 7198c2ecf20Sopenharmony_ci break; 7208c2ecf20Sopenharmony_ci default: 7218c2ecf20Sopenharmony_ci return -EINVAL; 7228c2ecf20Sopenharmony_ci } 7238c2ecf20Sopenharmony_ci 7248c2ecf20Sopenharmony_ci switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { 7258c2ecf20Sopenharmony_ci case SND_SOC_DAIFMT_I2S: 7268c2ecf20Sopenharmony_ci break; 7278c2ecf20Sopenharmony_ci case SND_SOC_DAIFMT_LEFT_J: 7288c2ecf20Sopenharmony_ci reg1_val |= RT1305_I2S_DF_SEL_LEFT; 7298c2ecf20Sopenharmony_ci break; 7308c2ecf20Sopenharmony_ci case SND_SOC_DAIFMT_DSP_A: 7318c2ecf20Sopenharmony_ci reg1_val |= RT1305_I2S_DF_SEL_PCM_A; 7328c2ecf20Sopenharmony_ci break; 7338c2ecf20Sopenharmony_ci case SND_SOC_DAIFMT_DSP_B: 7348c2ecf20Sopenharmony_ci reg1_val |= RT1305_I2S_DF_SEL_PCM_B; 7358c2ecf20Sopenharmony_ci break; 7368c2ecf20Sopenharmony_ci default: 7378c2ecf20Sopenharmony_ci return -EINVAL; 7388c2ecf20Sopenharmony_ci } 7398c2ecf20Sopenharmony_ci 7408c2ecf20Sopenharmony_ci switch (dai->id) { 7418c2ecf20Sopenharmony_ci case RT1305_AIF1: 7428c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT1305_I2S_SET_1, 7438c2ecf20Sopenharmony_ci RT1305_SEL_I2S_OUT_MODE_MASK, reg_val); 7448c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT1305_I2S_SET_2, 7458c2ecf20Sopenharmony_ci RT1305_I2S_DF_SEL_MASK | RT1305_I2S_BCLK_MASK, 7468c2ecf20Sopenharmony_ci reg1_val); 7478c2ecf20Sopenharmony_ci break; 7488c2ecf20Sopenharmony_ci default: 7498c2ecf20Sopenharmony_ci dev_err(component->dev, "Invalid dai->id: %d\n", dai->id); 7508c2ecf20Sopenharmony_ci return -EINVAL; 7518c2ecf20Sopenharmony_ci } 7528c2ecf20Sopenharmony_ci return 0; 7538c2ecf20Sopenharmony_ci} 7548c2ecf20Sopenharmony_ci 7558c2ecf20Sopenharmony_cistatic int rt1305_set_component_sysclk(struct snd_soc_component *component, 7568c2ecf20Sopenharmony_ci int clk_id, int source, unsigned int freq, int dir) 7578c2ecf20Sopenharmony_ci{ 7588c2ecf20Sopenharmony_ci struct rt1305_priv *rt1305 = snd_soc_component_get_drvdata(component); 7598c2ecf20Sopenharmony_ci unsigned int reg_val = 0; 7608c2ecf20Sopenharmony_ci 7618c2ecf20Sopenharmony_ci if (freq == rt1305->sysclk && clk_id == rt1305->sysclk_src) 7628c2ecf20Sopenharmony_ci return 0; 7638c2ecf20Sopenharmony_ci 7648c2ecf20Sopenharmony_ci switch (clk_id) { 7658c2ecf20Sopenharmony_ci case RT1305_FS_SYS_PRE_S_MCLK: 7668c2ecf20Sopenharmony_ci reg_val |= RT1305_SEL_FS_SYS_PRE_MCLK; 7678c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, 7688c2ecf20Sopenharmony_ci RT1305_CLOCK_DETECT, RT1305_SEL_CLK_DET_SRC_MASK, 7698c2ecf20Sopenharmony_ci RT1305_SEL_CLK_DET_SRC_MCLK); 7708c2ecf20Sopenharmony_ci break; 7718c2ecf20Sopenharmony_ci case RT1305_FS_SYS_PRE_S_PLL1: 7728c2ecf20Sopenharmony_ci reg_val |= RT1305_SEL_FS_SYS_PRE_PLL; 7738c2ecf20Sopenharmony_ci break; 7748c2ecf20Sopenharmony_ci case RT1305_FS_SYS_PRE_S_RCCLK: 7758c2ecf20Sopenharmony_ci reg_val |= RT1305_SEL_FS_SYS_PRE_RCCLK; 7768c2ecf20Sopenharmony_ci break; 7778c2ecf20Sopenharmony_ci default: 7788c2ecf20Sopenharmony_ci dev_err(component->dev, "Invalid clock id (%d)\n", clk_id); 7798c2ecf20Sopenharmony_ci return -EINVAL; 7808c2ecf20Sopenharmony_ci } 7818c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT1305_CLK_1, 7828c2ecf20Sopenharmony_ci RT1305_SEL_FS_SYS_PRE_MASK, reg_val); 7838c2ecf20Sopenharmony_ci rt1305->sysclk = freq; 7848c2ecf20Sopenharmony_ci rt1305->sysclk_src = clk_id; 7858c2ecf20Sopenharmony_ci 7868c2ecf20Sopenharmony_ci dev_dbg(component->dev, "Sysclk is %dHz and clock id is %d\n", 7878c2ecf20Sopenharmony_ci freq, clk_id); 7888c2ecf20Sopenharmony_ci 7898c2ecf20Sopenharmony_ci return 0; 7908c2ecf20Sopenharmony_ci} 7918c2ecf20Sopenharmony_ci 7928c2ecf20Sopenharmony_cistatic int rt1305_set_component_pll(struct snd_soc_component *component, 7938c2ecf20Sopenharmony_ci int pll_id, int source, unsigned int freq_in, 7948c2ecf20Sopenharmony_ci unsigned int freq_out) 7958c2ecf20Sopenharmony_ci{ 7968c2ecf20Sopenharmony_ci struct rt1305_priv *rt1305 = snd_soc_component_get_drvdata(component); 7978c2ecf20Sopenharmony_ci struct rl6231_pll_code pll_code; 7988c2ecf20Sopenharmony_ci int ret; 7998c2ecf20Sopenharmony_ci 8008c2ecf20Sopenharmony_ci if (source == rt1305->pll_src && freq_in == rt1305->pll_in && 8018c2ecf20Sopenharmony_ci freq_out == rt1305->pll_out) 8028c2ecf20Sopenharmony_ci return 0; 8038c2ecf20Sopenharmony_ci 8048c2ecf20Sopenharmony_ci if (!freq_in || !freq_out) { 8058c2ecf20Sopenharmony_ci dev_dbg(component->dev, "PLL disabled\n"); 8068c2ecf20Sopenharmony_ci 8078c2ecf20Sopenharmony_ci rt1305->pll_in = 0; 8088c2ecf20Sopenharmony_ci rt1305->pll_out = 0; 8098c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT1305_CLK_1, 8108c2ecf20Sopenharmony_ci RT1305_SEL_FS_SYS_PRE_MASK | RT1305_SEL_PLL_SRC_1_MASK, 8118c2ecf20Sopenharmony_ci RT1305_SEL_FS_SYS_PRE_PLL | RT1305_SEL_PLL_SRC_1_BCLK); 8128c2ecf20Sopenharmony_ci return 0; 8138c2ecf20Sopenharmony_ci } 8148c2ecf20Sopenharmony_ci 8158c2ecf20Sopenharmony_ci switch (source) { 8168c2ecf20Sopenharmony_ci case RT1305_PLL2_S_MCLK: 8178c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT1305_CLK_1, 8188c2ecf20Sopenharmony_ci RT1305_SEL_PLL_SRC_2_MASK | RT1305_SEL_PLL_SRC_1_MASK | 8198c2ecf20Sopenharmony_ci RT1305_DIV_PLL_SRC_2_MASK, 8208c2ecf20Sopenharmony_ci RT1305_SEL_PLL_SRC_2_MCLK | RT1305_SEL_PLL_SRC_1_PLL2); 8218c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, 8228c2ecf20Sopenharmony_ci RT1305_CLOCK_DETECT, RT1305_SEL_CLK_DET_SRC_MASK, 8238c2ecf20Sopenharmony_ci RT1305_SEL_CLK_DET_SRC_MCLK); 8248c2ecf20Sopenharmony_ci break; 8258c2ecf20Sopenharmony_ci case RT1305_PLL1_S_BCLK: 8268c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, 8278c2ecf20Sopenharmony_ci RT1305_CLK_1, RT1305_SEL_PLL_SRC_1_MASK, 8288c2ecf20Sopenharmony_ci RT1305_SEL_PLL_SRC_1_BCLK); 8298c2ecf20Sopenharmony_ci break; 8308c2ecf20Sopenharmony_ci case RT1305_PLL2_S_RCCLK: 8318c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT1305_CLK_1, 8328c2ecf20Sopenharmony_ci RT1305_SEL_PLL_SRC_2_MASK | RT1305_SEL_PLL_SRC_1_MASK | 8338c2ecf20Sopenharmony_ci RT1305_DIV_PLL_SRC_2_MASK, 8348c2ecf20Sopenharmony_ci RT1305_SEL_PLL_SRC_2_RCCLK | RT1305_SEL_PLL_SRC_1_PLL2); 8358c2ecf20Sopenharmony_ci freq_in = 98304000; 8368c2ecf20Sopenharmony_ci break; 8378c2ecf20Sopenharmony_ci default: 8388c2ecf20Sopenharmony_ci dev_err(component->dev, "Unknown PLL Source %d\n", source); 8398c2ecf20Sopenharmony_ci return -EINVAL; 8408c2ecf20Sopenharmony_ci } 8418c2ecf20Sopenharmony_ci 8428c2ecf20Sopenharmony_ci ret = rl6231_pll_calc(freq_in, freq_out, &pll_code); 8438c2ecf20Sopenharmony_ci if (ret < 0) { 8448c2ecf20Sopenharmony_ci dev_err(component->dev, "Unsupport input clock %d\n", freq_in); 8458c2ecf20Sopenharmony_ci return ret; 8468c2ecf20Sopenharmony_ci } 8478c2ecf20Sopenharmony_ci 8488c2ecf20Sopenharmony_ci dev_dbg(component->dev, "bypass=%d m=%d n=%d k=%d\n", 8498c2ecf20Sopenharmony_ci pll_code.m_bp, (pll_code.m_bp ? 0 : pll_code.m_code), 8508c2ecf20Sopenharmony_ci pll_code.n_code, pll_code.k_code); 8518c2ecf20Sopenharmony_ci 8528c2ecf20Sopenharmony_ci snd_soc_component_write(component, RT1305_PLL1_1, 8538c2ecf20Sopenharmony_ci (pll_code.m_bp ? 0 : pll_code.m_code) << RT1305_PLL_1_M_SFT | 8548c2ecf20Sopenharmony_ci pll_code.m_bp << RT1305_PLL_1_M_BYPASS_SFT | 8558c2ecf20Sopenharmony_ci pll_code.n_code); 8568c2ecf20Sopenharmony_ci snd_soc_component_write(component, RT1305_PLL1_2, 8578c2ecf20Sopenharmony_ci pll_code.k_code); 8588c2ecf20Sopenharmony_ci 8598c2ecf20Sopenharmony_ci rt1305->pll_in = freq_in; 8608c2ecf20Sopenharmony_ci rt1305->pll_out = freq_out; 8618c2ecf20Sopenharmony_ci rt1305->pll_src = source; 8628c2ecf20Sopenharmony_ci 8638c2ecf20Sopenharmony_ci return 0; 8648c2ecf20Sopenharmony_ci} 8658c2ecf20Sopenharmony_ci 8668c2ecf20Sopenharmony_cistatic int rt1305_probe(struct snd_soc_component *component) 8678c2ecf20Sopenharmony_ci{ 8688c2ecf20Sopenharmony_ci struct rt1305_priv *rt1305 = snd_soc_component_get_drvdata(component); 8698c2ecf20Sopenharmony_ci 8708c2ecf20Sopenharmony_ci rt1305->component = component; 8718c2ecf20Sopenharmony_ci 8728c2ecf20Sopenharmony_ci /* initial settings */ 8738c2ecf20Sopenharmony_ci rt1305_reg_init(component); 8748c2ecf20Sopenharmony_ci 8758c2ecf20Sopenharmony_ci return 0; 8768c2ecf20Sopenharmony_ci} 8778c2ecf20Sopenharmony_ci 8788c2ecf20Sopenharmony_cistatic void rt1305_remove(struct snd_soc_component *component) 8798c2ecf20Sopenharmony_ci{ 8808c2ecf20Sopenharmony_ci struct rt1305_priv *rt1305 = snd_soc_component_get_drvdata(component); 8818c2ecf20Sopenharmony_ci 8828c2ecf20Sopenharmony_ci rt1305_reset(rt1305->regmap); 8838c2ecf20Sopenharmony_ci} 8848c2ecf20Sopenharmony_ci 8858c2ecf20Sopenharmony_ci#ifdef CONFIG_PM 8868c2ecf20Sopenharmony_cistatic int rt1305_suspend(struct snd_soc_component *component) 8878c2ecf20Sopenharmony_ci{ 8888c2ecf20Sopenharmony_ci struct rt1305_priv *rt1305 = snd_soc_component_get_drvdata(component); 8898c2ecf20Sopenharmony_ci 8908c2ecf20Sopenharmony_ci regcache_cache_only(rt1305->regmap, true); 8918c2ecf20Sopenharmony_ci regcache_mark_dirty(rt1305->regmap); 8928c2ecf20Sopenharmony_ci 8938c2ecf20Sopenharmony_ci return 0; 8948c2ecf20Sopenharmony_ci} 8958c2ecf20Sopenharmony_ci 8968c2ecf20Sopenharmony_cistatic int rt1305_resume(struct snd_soc_component *component) 8978c2ecf20Sopenharmony_ci{ 8988c2ecf20Sopenharmony_ci struct rt1305_priv *rt1305 = snd_soc_component_get_drvdata(component); 8998c2ecf20Sopenharmony_ci 9008c2ecf20Sopenharmony_ci regcache_cache_only(rt1305->regmap, false); 9018c2ecf20Sopenharmony_ci regcache_sync(rt1305->regmap); 9028c2ecf20Sopenharmony_ci 9038c2ecf20Sopenharmony_ci return 0; 9048c2ecf20Sopenharmony_ci} 9058c2ecf20Sopenharmony_ci#else 9068c2ecf20Sopenharmony_ci#define rt1305_suspend NULL 9078c2ecf20Sopenharmony_ci#define rt1305_resume NULL 9088c2ecf20Sopenharmony_ci#endif 9098c2ecf20Sopenharmony_ci 9108c2ecf20Sopenharmony_ci#define RT1305_STEREO_RATES SNDRV_PCM_RATE_8000_192000 9118c2ecf20Sopenharmony_ci#define RT1305_FORMATS (SNDRV_PCM_FMTBIT_S8 | \ 9128c2ecf20Sopenharmony_ci SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S16_LE | \ 9138c2ecf20Sopenharmony_ci SNDRV_PCM_FMTBIT_S24_LE) 9148c2ecf20Sopenharmony_ci 9158c2ecf20Sopenharmony_cistatic const struct snd_soc_dai_ops rt1305_aif_dai_ops = { 9168c2ecf20Sopenharmony_ci .hw_params = rt1305_hw_params, 9178c2ecf20Sopenharmony_ci .set_fmt = rt1305_set_dai_fmt, 9188c2ecf20Sopenharmony_ci}; 9198c2ecf20Sopenharmony_ci 9208c2ecf20Sopenharmony_cistatic struct snd_soc_dai_driver rt1305_dai[] = { 9218c2ecf20Sopenharmony_ci { 9228c2ecf20Sopenharmony_ci .name = "rt1305-aif", 9238c2ecf20Sopenharmony_ci .playback = { 9248c2ecf20Sopenharmony_ci .stream_name = "AIF1 Playback", 9258c2ecf20Sopenharmony_ci .channels_min = 1, 9268c2ecf20Sopenharmony_ci .channels_max = 2, 9278c2ecf20Sopenharmony_ci .rates = RT1305_STEREO_RATES, 9288c2ecf20Sopenharmony_ci .formats = RT1305_FORMATS, 9298c2ecf20Sopenharmony_ci }, 9308c2ecf20Sopenharmony_ci .ops = &rt1305_aif_dai_ops, 9318c2ecf20Sopenharmony_ci }, 9328c2ecf20Sopenharmony_ci}; 9338c2ecf20Sopenharmony_ci 9348c2ecf20Sopenharmony_cistatic const struct snd_soc_component_driver soc_component_dev_rt1305 = { 9358c2ecf20Sopenharmony_ci .probe = rt1305_probe, 9368c2ecf20Sopenharmony_ci .remove = rt1305_remove, 9378c2ecf20Sopenharmony_ci .suspend = rt1305_suspend, 9388c2ecf20Sopenharmony_ci .resume = rt1305_resume, 9398c2ecf20Sopenharmony_ci .controls = rt1305_snd_controls, 9408c2ecf20Sopenharmony_ci .num_controls = ARRAY_SIZE(rt1305_snd_controls), 9418c2ecf20Sopenharmony_ci .dapm_widgets = rt1305_dapm_widgets, 9428c2ecf20Sopenharmony_ci .num_dapm_widgets = ARRAY_SIZE(rt1305_dapm_widgets), 9438c2ecf20Sopenharmony_ci .dapm_routes = rt1305_dapm_routes, 9448c2ecf20Sopenharmony_ci .num_dapm_routes = ARRAY_SIZE(rt1305_dapm_routes), 9458c2ecf20Sopenharmony_ci .set_sysclk = rt1305_set_component_sysclk, 9468c2ecf20Sopenharmony_ci .set_pll = rt1305_set_component_pll, 9478c2ecf20Sopenharmony_ci .use_pmdown_time = 1, 9488c2ecf20Sopenharmony_ci .endianness = 1, 9498c2ecf20Sopenharmony_ci .non_legacy_dai_naming = 1, 9508c2ecf20Sopenharmony_ci}; 9518c2ecf20Sopenharmony_ci 9528c2ecf20Sopenharmony_cistatic const struct regmap_config rt1305_regmap = { 9538c2ecf20Sopenharmony_ci .reg_bits = 8, 9548c2ecf20Sopenharmony_ci .val_bits = 16, 9558c2ecf20Sopenharmony_ci .max_register = RT1305_MAX_REG + 1 + (ARRAY_SIZE(rt1305_ranges) * 9568c2ecf20Sopenharmony_ci RT1305_PR_SPACING), 9578c2ecf20Sopenharmony_ci .volatile_reg = rt1305_volatile_register, 9588c2ecf20Sopenharmony_ci .readable_reg = rt1305_readable_register, 9598c2ecf20Sopenharmony_ci .cache_type = REGCACHE_RBTREE, 9608c2ecf20Sopenharmony_ci .reg_defaults = rt1305_reg, 9618c2ecf20Sopenharmony_ci .num_reg_defaults = ARRAY_SIZE(rt1305_reg), 9628c2ecf20Sopenharmony_ci .ranges = rt1305_ranges, 9638c2ecf20Sopenharmony_ci .num_ranges = ARRAY_SIZE(rt1305_ranges), 9648c2ecf20Sopenharmony_ci .use_single_read = true, 9658c2ecf20Sopenharmony_ci .use_single_write = true, 9668c2ecf20Sopenharmony_ci}; 9678c2ecf20Sopenharmony_ci 9688c2ecf20Sopenharmony_ci#if defined(CONFIG_OF) 9698c2ecf20Sopenharmony_cistatic const struct of_device_id rt1305_of_match[] = { 9708c2ecf20Sopenharmony_ci { .compatible = "realtek,rt1305", }, 9718c2ecf20Sopenharmony_ci { .compatible = "realtek,rt1306", }, 9728c2ecf20Sopenharmony_ci {}, 9738c2ecf20Sopenharmony_ci}; 9748c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, rt1305_of_match); 9758c2ecf20Sopenharmony_ci#endif 9768c2ecf20Sopenharmony_ci 9778c2ecf20Sopenharmony_ci#ifdef CONFIG_ACPI 9788c2ecf20Sopenharmony_cistatic struct acpi_device_id rt1305_acpi_match[] = { 9798c2ecf20Sopenharmony_ci {"10EC1305", 0,}, 9808c2ecf20Sopenharmony_ci {"10EC1306", 0,}, 9818c2ecf20Sopenharmony_ci {}, 9828c2ecf20Sopenharmony_ci}; 9838c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(acpi, rt1305_acpi_match); 9848c2ecf20Sopenharmony_ci#endif 9858c2ecf20Sopenharmony_ci 9868c2ecf20Sopenharmony_cistatic const struct i2c_device_id rt1305_i2c_id[] = { 9878c2ecf20Sopenharmony_ci { "rt1305", 0 }, 9888c2ecf20Sopenharmony_ci { "rt1306", 0 }, 9898c2ecf20Sopenharmony_ci { } 9908c2ecf20Sopenharmony_ci}; 9918c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(i2c, rt1305_i2c_id); 9928c2ecf20Sopenharmony_ci 9938c2ecf20Sopenharmony_cistatic void rt1305_calibrate(struct rt1305_priv *rt1305) 9948c2ecf20Sopenharmony_ci{ 9958c2ecf20Sopenharmony_ci unsigned int valmsb, vallsb, offsetl, offsetr; 9968c2ecf20Sopenharmony_ci unsigned int rh, rl, rhl, r0ohm; 9978c2ecf20Sopenharmony_ci u64 r0l, r0r; 9988c2ecf20Sopenharmony_ci 9998c2ecf20Sopenharmony_ci regcache_cache_bypass(rt1305->regmap, true); 10008c2ecf20Sopenharmony_ci 10018c2ecf20Sopenharmony_ci rt1305_reset(rt1305->regmap); 10028c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_ADC_SET_3, 0x0219); 10038c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_PR_BASE + 0xcf, 0x5548); 10048c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_PR_BASE + 0xc1, 0x0320); 10058c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_CLOCK_DETECT, 0x1000); 10068c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_CLK_1, 0x0600); 10078c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_POWER_CTRL_3, 0xffd0); 10088c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_EFUSE_1, 0x0080); 10098c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_EFUSE_1, 0x0880); 10108c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_POWER_CTRL_1, 0x0dfe); 10118c2ecf20Sopenharmony_ci 10128c2ecf20Sopenharmony_ci /* Sin Gen */ 10138c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_PR_BASE + 0x5d, 0x0442); 10148c2ecf20Sopenharmony_ci 10158c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_CAL_EFUSE_CLOCK, 0xb000); 10168c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_PR_BASE + 0xc3, 0xd4a0); 10178c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_PR_BASE + 0xcc, 0x00cc); 10188c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_PR_BASE + 0xc1, 0x0320); 10198c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_POWER_STATUS, 0x0000); 10208c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_POWER_CTRL_2, 0xffff); 10218c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_POWER_CTRL_3, 0xfc20); 10228c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_PR_BASE + 0x06, 0x00c0); 10238c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_POWER_CTRL_3, 0xfca0); 10248c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_POWER_CTRL_3, 0xfce0); 10258c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_POWER_CTRL_3, 0xfcf0); 10268c2ecf20Sopenharmony_ci 10278c2ecf20Sopenharmony_ci /* EFUSE read */ 10288c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_EFUSE_1, 0x0080); 10298c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_EFUSE_1, 0x0880); 10308c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_EFUSE_1, 0x0880); 10318c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_POWER_CTRL_3, 0xfce0); 10328c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_POWER_CTRL_3, 0xfca0); 10338c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_POWER_CTRL_3, 0xfc20); 10348c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_PR_BASE + 0x06, 0x0000); 10358c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_EFUSE_1, 0x0000); 10368c2ecf20Sopenharmony_ci 10378c2ecf20Sopenharmony_ci regmap_read(rt1305->regmap, RT1305_DAC_OFFSET_5, &valmsb); 10388c2ecf20Sopenharmony_ci regmap_read(rt1305->regmap, RT1305_DAC_OFFSET_6, &vallsb); 10398c2ecf20Sopenharmony_ci offsetl = valmsb << 16 | vallsb; 10408c2ecf20Sopenharmony_ci regmap_read(rt1305->regmap, RT1305_DAC_OFFSET_7, &valmsb); 10418c2ecf20Sopenharmony_ci regmap_read(rt1305->regmap, RT1305_DAC_OFFSET_8, &vallsb); 10428c2ecf20Sopenharmony_ci offsetr = valmsb << 16 | vallsb; 10438c2ecf20Sopenharmony_ci pr_info("DC offsetl=0x%x, offsetr=0x%x\n", offsetl, offsetr); 10448c2ecf20Sopenharmony_ci 10458c2ecf20Sopenharmony_ci /* R0 calibration */ 10468c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_PR_BASE + 0x5d, 0x9542); 10478c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_POWER_CTRL_3, 0xfcf0); 10488c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_POWER_CTRL_2, 0xffff); 10498c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_POWER_CTRL_1, 0x1dfe); 10508c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_SILENCE_DETECT, 0x0e13); 10518c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_CLK_1, 0x0650); 10528c2ecf20Sopenharmony_ci 10538c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_PR_BASE + 0x50, 0x0064); 10548c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_PR_BASE + 0x51, 0x0770); 10558c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_PR_BASE + 0x52, 0xc30c); 10568c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_SPK_TEMP_PROTECTION_1, 0x8200); 10578c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_PR_BASE + 0xd4, 0xfb00); 10588c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_PR_BASE + 0xd4, 0xff80); 10598c2ecf20Sopenharmony_ci msleep(2000); 10608c2ecf20Sopenharmony_ci regmap_read(rt1305->regmap, RT1305_PR_BASE + 0x55, &rh); 10618c2ecf20Sopenharmony_ci regmap_read(rt1305->regmap, RT1305_PR_BASE + 0x56, &rl); 10628c2ecf20Sopenharmony_ci rhl = (rh << 16) | rl; 10638c2ecf20Sopenharmony_ci r0ohm = (rhl*10) / 33554432; 10648c2ecf20Sopenharmony_ci 10658c2ecf20Sopenharmony_ci pr_debug("Left_rhl = 0x%x rh=0x%x rl=0x%x\n", rhl, rh, rl); 10668c2ecf20Sopenharmony_ci pr_info("Left channel %d.%dohm\n", (r0ohm/10), (r0ohm%10)); 10678c2ecf20Sopenharmony_ci 10688c2ecf20Sopenharmony_ci r0l = 562949953421312ULL; 10698c2ecf20Sopenharmony_ci if (rhl != 0) 10708c2ecf20Sopenharmony_ci do_div(r0l, rhl); 10718c2ecf20Sopenharmony_ci pr_debug("Left_r0 = 0x%llx\n", r0l); 10728c2ecf20Sopenharmony_ci 10738c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_SPK_TEMP_PROTECTION_1, 0x9200); 10748c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_PR_BASE + 0xd4, 0xfb00); 10758c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_PR_BASE + 0xd4, 0xff80); 10768c2ecf20Sopenharmony_ci msleep(2000); 10778c2ecf20Sopenharmony_ci regmap_read(rt1305->regmap, RT1305_PR_BASE + 0x55, &rh); 10788c2ecf20Sopenharmony_ci regmap_read(rt1305->regmap, RT1305_PR_BASE + 0x56, &rl); 10798c2ecf20Sopenharmony_ci rhl = (rh << 16) | rl; 10808c2ecf20Sopenharmony_ci r0ohm = (rhl*10) / 33554432; 10818c2ecf20Sopenharmony_ci 10828c2ecf20Sopenharmony_ci pr_debug("Right_rhl = 0x%x rh=0x%x rl=0x%x\n", rhl, rh, rl); 10838c2ecf20Sopenharmony_ci pr_info("Right channel %d.%dohm\n", (r0ohm/10), (r0ohm%10)); 10848c2ecf20Sopenharmony_ci 10858c2ecf20Sopenharmony_ci r0r = 562949953421312ULL; 10868c2ecf20Sopenharmony_ci if (rhl != 0) 10878c2ecf20Sopenharmony_ci do_div(r0r, rhl); 10888c2ecf20Sopenharmony_ci pr_debug("Right_r0 = 0x%llx\n", r0r); 10898c2ecf20Sopenharmony_ci 10908c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_SPK_TEMP_PROTECTION_1, 0xc2ec); 10918c2ecf20Sopenharmony_ci 10928c2ecf20Sopenharmony_ci if ((r0l > R0_UPPER) && (r0l < R0_LOWER) && 10938c2ecf20Sopenharmony_ci (r0r > R0_UPPER) && (r0r < R0_LOWER)) { 10948c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_PR_BASE + 0x4e, 10958c2ecf20Sopenharmony_ci (r0l >> 16) & 0xffff); 10968c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_PR_BASE + 0x4f, 10978c2ecf20Sopenharmony_ci r0l & 0xffff); 10988c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_PR_BASE + 0xfe, 10998c2ecf20Sopenharmony_ci ((r0r >> 16) & 0xffff) | 0xf800); 11008c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_PR_BASE + 0xfd, 11018c2ecf20Sopenharmony_ci r0r & 0xffff); 11028c2ecf20Sopenharmony_ci } else { 11038c2ecf20Sopenharmony_ci pr_err("R0 calibration failed\n"); 11048c2ecf20Sopenharmony_ci } 11058c2ecf20Sopenharmony_ci 11068c2ecf20Sopenharmony_ci /* restore some registers */ 11078c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_POWER_CTRL_1, 0x0dfe); 11088c2ecf20Sopenharmony_ci usleep_range(200000, 400000); 11098c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_PR_BASE + 0x5d, 0x0442); 11108c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_CLOCK_DETECT, 0x3000); 11118c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_CLK_1, 0x0400); 11128c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_POWER_CTRL_1, 0x0000); 11138c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_CAL_EFUSE_CLOCK, 0x8000); 11148c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_POWER_CTRL_2, 0x1020); 11158c2ecf20Sopenharmony_ci regmap_write(rt1305->regmap, RT1305_POWER_CTRL_3, 0x0000); 11168c2ecf20Sopenharmony_ci 11178c2ecf20Sopenharmony_ci regcache_cache_bypass(rt1305->regmap, false); 11188c2ecf20Sopenharmony_ci} 11198c2ecf20Sopenharmony_ci 11208c2ecf20Sopenharmony_cistatic int rt1305_i2c_probe(struct i2c_client *i2c, 11218c2ecf20Sopenharmony_ci const struct i2c_device_id *id) 11228c2ecf20Sopenharmony_ci{ 11238c2ecf20Sopenharmony_ci struct rt1305_priv *rt1305; 11248c2ecf20Sopenharmony_ci int ret; 11258c2ecf20Sopenharmony_ci unsigned int val; 11268c2ecf20Sopenharmony_ci 11278c2ecf20Sopenharmony_ci rt1305 = devm_kzalloc(&i2c->dev, sizeof(struct rt1305_priv), 11288c2ecf20Sopenharmony_ci GFP_KERNEL); 11298c2ecf20Sopenharmony_ci if (rt1305 == NULL) 11308c2ecf20Sopenharmony_ci return -ENOMEM; 11318c2ecf20Sopenharmony_ci 11328c2ecf20Sopenharmony_ci i2c_set_clientdata(i2c, rt1305); 11338c2ecf20Sopenharmony_ci 11348c2ecf20Sopenharmony_ci rt1305->regmap = devm_regmap_init_i2c(i2c, &rt1305_regmap); 11358c2ecf20Sopenharmony_ci if (IS_ERR(rt1305->regmap)) { 11368c2ecf20Sopenharmony_ci ret = PTR_ERR(rt1305->regmap); 11378c2ecf20Sopenharmony_ci dev_err(&i2c->dev, "Failed to allocate register map: %d\n", 11388c2ecf20Sopenharmony_ci ret); 11398c2ecf20Sopenharmony_ci return ret; 11408c2ecf20Sopenharmony_ci } 11418c2ecf20Sopenharmony_ci 11428c2ecf20Sopenharmony_ci regmap_read(rt1305->regmap, RT1305_DEVICE_ID, &val); 11438c2ecf20Sopenharmony_ci if (val != RT1305_DEVICE_ID_NUM) { 11448c2ecf20Sopenharmony_ci dev_err(&i2c->dev, 11458c2ecf20Sopenharmony_ci "Device with ID register %x is not rt1305\n", val); 11468c2ecf20Sopenharmony_ci return -ENODEV; 11478c2ecf20Sopenharmony_ci } 11488c2ecf20Sopenharmony_ci 11498c2ecf20Sopenharmony_ci rt1305_reset(rt1305->regmap); 11508c2ecf20Sopenharmony_ci rt1305_calibrate(rt1305); 11518c2ecf20Sopenharmony_ci 11528c2ecf20Sopenharmony_ci return devm_snd_soc_register_component(&i2c->dev, 11538c2ecf20Sopenharmony_ci &soc_component_dev_rt1305, 11548c2ecf20Sopenharmony_ci rt1305_dai, ARRAY_SIZE(rt1305_dai)); 11558c2ecf20Sopenharmony_ci} 11568c2ecf20Sopenharmony_ci 11578c2ecf20Sopenharmony_cistatic void rt1305_i2c_shutdown(struct i2c_client *client) 11588c2ecf20Sopenharmony_ci{ 11598c2ecf20Sopenharmony_ci struct rt1305_priv *rt1305 = i2c_get_clientdata(client); 11608c2ecf20Sopenharmony_ci 11618c2ecf20Sopenharmony_ci rt1305_reset(rt1305->regmap); 11628c2ecf20Sopenharmony_ci} 11638c2ecf20Sopenharmony_ci 11648c2ecf20Sopenharmony_ci 11658c2ecf20Sopenharmony_cistatic struct i2c_driver rt1305_i2c_driver = { 11668c2ecf20Sopenharmony_ci .driver = { 11678c2ecf20Sopenharmony_ci .name = "rt1305", 11688c2ecf20Sopenharmony_ci#if defined(CONFIG_OF) 11698c2ecf20Sopenharmony_ci .of_match_table = rt1305_of_match, 11708c2ecf20Sopenharmony_ci#endif 11718c2ecf20Sopenharmony_ci#if defined(CONFIG_ACPI) 11728c2ecf20Sopenharmony_ci .acpi_match_table = ACPI_PTR(rt1305_acpi_match) 11738c2ecf20Sopenharmony_ci#endif 11748c2ecf20Sopenharmony_ci }, 11758c2ecf20Sopenharmony_ci .probe = rt1305_i2c_probe, 11768c2ecf20Sopenharmony_ci .shutdown = rt1305_i2c_shutdown, 11778c2ecf20Sopenharmony_ci .id_table = rt1305_i2c_id, 11788c2ecf20Sopenharmony_ci}; 11798c2ecf20Sopenharmony_cimodule_i2c_driver(rt1305_i2c_driver); 11808c2ecf20Sopenharmony_ci 11818c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("ASoC RT1305 amplifier driver"); 11828c2ecf20Sopenharmony_ciMODULE_AUTHOR("Shuming Fan <shumingf@realtek.com>"); 11838c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2"); 1184