18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * rt5668.c -- RT5668B ALSA SoC audio component driver 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright 2018 Realtek Semiconductor Corp. 68c2ecf20Sopenharmony_ci * Author: Bard Liao <bardliao@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/i2c.h> 158c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 168c2ecf20Sopenharmony_ci#include <linux/spi/spi.h> 178c2ecf20Sopenharmony_ci#include <linux/acpi.h> 188c2ecf20Sopenharmony_ci#include <linux/gpio.h> 198c2ecf20Sopenharmony_ci#include <linux/of_gpio.h> 208c2ecf20Sopenharmony_ci#include <linux/regulator/consumer.h> 218c2ecf20Sopenharmony_ci#include <linux/mutex.h> 228c2ecf20Sopenharmony_ci#include <sound/core.h> 238c2ecf20Sopenharmony_ci#include <sound/pcm.h> 248c2ecf20Sopenharmony_ci#include <sound/pcm_params.h> 258c2ecf20Sopenharmony_ci#include <sound/jack.h> 268c2ecf20Sopenharmony_ci#include <sound/soc.h> 278c2ecf20Sopenharmony_ci#include <sound/soc-dapm.h> 288c2ecf20Sopenharmony_ci#include <sound/initval.h> 298c2ecf20Sopenharmony_ci#include <sound/tlv.h> 308c2ecf20Sopenharmony_ci#include <sound/rt5668.h> 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci#include "rl6231.h" 338c2ecf20Sopenharmony_ci#include "rt5668.h" 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci#define RT5668_NUM_SUPPLIES 3 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_cistatic const char *rt5668_supply_names[RT5668_NUM_SUPPLIES] = { 388c2ecf20Sopenharmony_ci "AVDD", 398c2ecf20Sopenharmony_ci "MICVDD", 408c2ecf20Sopenharmony_ci "VBAT", 418c2ecf20Sopenharmony_ci}; 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_cistruct rt5668_priv { 448c2ecf20Sopenharmony_ci struct snd_soc_component *component; 458c2ecf20Sopenharmony_ci struct rt5668_platform_data pdata; 468c2ecf20Sopenharmony_ci struct regmap *regmap; 478c2ecf20Sopenharmony_ci struct snd_soc_jack *hs_jack; 488c2ecf20Sopenharmony_ci struct regulator_bulk_data supplies[RT5668_NUM_SUPPLIES]; 498c2ecf20Sopenharmony_ci struct delayed_work jack_detect_work; 508c2ecf20Sopenharmony_ci struct delayed_work jd_check_work; 518c2ecf20Sopenharmony_ci struct mutex calibrate_mutex; 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci int sysclk; 548c2ecf20Sopenharmony_ci int sysclk_src; 558c2ecf20Sopenharmony_ci int lrck[RT5668_AIFS]; 568c2ecf20Sopenharmony_ci int bclk[RT5668_AIFS]; 578c2ecf20Sopenharmony_ci int master[RT5668_AIFS]; 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci int pll_src; 608c2ecf20Sopenharmony_ci int pll_in; 618c2ecf20Sopenharmony_ci int pll_out; 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci int jack_type; 648c2ecf20Sopenharmony_ci}; 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_cistatic const struct reg_default rt5668_reg[] = { 678c2ecf20Sopenharmony_ci {0x0002, 0x8080}, 688c2ecf20Sopenharmony_ci {0x0003, 0x8000}, 698c2ecf20Sopenharmony_ci {0x0005, 0x0000}, 708c2ecf20Sopenharmony_ci {0x0006, 0x0000}, 718c2ecf20Sopenharmony_ci {0x0008, 0x800f}, 728c2ecf20Sopenharmony_ci {0x000b, 0x0000}, 738c2ecf20Sopenharmony_ci {0x0010, 0x4040}, 748c2ecf20Sopenharmony_ci {0x0011, 0x0000}, 758c2ecf20Sopenharmony_ci {0x0012, 0x1404}, 768c2ecf20Sopenharmony_ci {0x0013, 0x1000}, 778c2ecf20Sopenharmony_ci {0x0014, 0xa00a}, 788c2ecf20Sopenharmony_ci {0x0015, 0x0404}, 798c2ecf20Sopenharmony_ci {0x0016, 0x0404}, 808c2ecf20Sopenharmony_ci {0x0019, 0xafaf}, 818c2ecf20Sopenharmony_ci {0x001c, 0x2f2f}, 828c2ecf20Sopenharmony_ci {0x001f, 0x0000}, 838c2ecf20Sopenharmony_ci {0x0022, 0x5757}, 848c2ecf20Sopenharmony_ci {0x0023, 0x0039}, 858c2ecf20Sopenharmony_ci {0x0024, 0x000b}, 868c2ecf20Sopenharmony_ci {0x0026, 0xc0c4}, 878c2ecf20Sopenharmony_ci {0x0029, 0x8080}, 888c2ecf20Sopenharmony_ci {0x002a, 0xa0a0}, 898c2ecf20Sopenharmony_ci {0x002b, 0x0300}, 908c2ecf20Sopenharmony_ci {0x0030, 0x0000}, 918c2ecf20Sopenharmony_ci {0x003c, 0x0080}, 928c2ecf20Sopenharmony_ci {0x0044, 0x0c0c}, 938c2ecf20Sopenharmony_ci {0x0049, 0x0000}, 948c2ecf20Sopenharmony_ci {0x0061, 0x0000}, 958c2ecf20Sopenharmony_ci {0x0062, 0x0000}, 968c2ecf20Sopenharmony_ci {0x0063, 0x003f}, 978c2ecf20Sopenharmony_ci {0x0064, 0x0000}, 988c2ecf20Sopenharmony_ci {0x0065, 0x0000}, 998c2ecf20Sopenharmony_ci {0x0066, 0x0030}, 1008c2ecf20Sopenharmony_ci {0x0067, 0x0000}, 1018c2ecf20Sopenharmony_ci {0x006b, 0x0000}, 1028c2ecf20Sopenharmony_ci {0x006c, 0x0000}, 1038c2ecf20Sopenharmony_ci {0x006d, 0x2200}, 1048c2ecf20Sopenharmony_ci {0x006e, 0x0a10}, 1058c2ecf20Sopenharmony_ci {0x0070, 0x8000}, 1068c2ecf20Sopenharmony_ci {0x0071, 0x8000}, 1078c2ecf20Sopenharmony_ci {0x0073, 0x0000}, 1088c2ecf20Sopenharmony_ci {0x0074, 0x0000}, 1098c2ecf20Sopenharmony_ci {0x0075, 0x0002}, 1108c2ecf20Sopenharmony_ci {0x0076, 0x0001}, 1118c2ecf20Sopenharmony_ci {0x0079, 0x0000}, 1128c2ecf20Sopenharmony_ci {0x007a, 0x0000}, 1138c2ecf20Sopenharmony_ci {0x007b, 0x0000}, 1148c2ecf20Sopenharmony_ci {0x007c, 0x0100}, 1158c2ecf20Sopenharmony_ci {0x007e, 0x0000}, 1168c2ecf20Sopenharmony_ci {0x0080, 0x0000}, 1178c2ecf20Sopenharmony_ci {0x0081, 0x0000}, 1188c2ecf20Sopenharmony_ci {0x0082, 0x0000}, 1198c2ecf20Sopenharmony_ci {0x0083, 0x0000}, 1208c2ecf20Sopenharmony_ci {0x0084, 0x0000}, 1218c2ecf20Sopenharmony_ci {0x0085, 0x0000}, 1228c2ecf20Sopenharmony_ci {0x0086, 0x0005}, 1238c2ecf20Sopenharmony_ci {0x0087, 0x0000}, 1248c2ecf20Sopenharmony_ci {0x0088, 0x0000}, 1258c2ecf20Sopenharmony_ci {0x008c, 0x0003}, 1268c2ecf20Sopenharmony_ci {0x008d, 0x0000}, 1278c2ecf20Sopenharmony_ci {0x008e, 0x0060}, 1288c2ecf20Sopenharmony_ci {0x008f, 0x1000}, 1298c2ecf20Sopenharmony_ci {0x0091, 0x0c26}, 1308c2ecf20Sopenharmony_ci {0x0092, 0x0073}, 1318c2ecf20Sopenharmony_ci {0x0093, 0x0000}, 1328c2ecf20Sopenharmony_ci {0x0094, 0x0080}, 1338c2ecf20Sopenharmony_ci {0x0098, 0x0000}, 1348c2ecf20Sopenharmony_ci {0x009a, 0x0000}, 1358c2ecf20Sopenharmony_ci {0x009b, 0x0000}, 1368c2ecf20Sopenharmony_ci {0x009c, 0x0000}, 1378c2ecf20Sopenharmony_ci {0x009d, 0x0000}, 1388c2ecf20Sopenharmony_ci {0x009e, 0x100c}, 1398c2ecf20Sopenharmony_ci {0x009f, 0x0000}, 1408c2ecf20Sopenharmony_ci {0x00a0, 0x0000}, 1418c2ecf20Sopenharmony_ci {0x00a3, 0x0002}, 1428c2ecf20Sopenharmony_ci {0x00a4, 0x0001}, 1438c2ecf20Sopenharmony_ci {0x00ae, 0x2040}, 1448c2ecf20Sopenharmony_ci {0x00af, 0x0000}, 1458c2ecf20Sopenharmony_ci {0x00b6, 0x0000}, 1468c2ecf20Sopenharmony_ci {0x00b7, 0x0000}, 1478c2ecf20Sopenharmony_ci {0x00b8, 0x0000}, 1488c2ecf20Sopenharmony_ci {0x00b9, 0x0002}, 1498c2ecf20Sopenharmony_ci {0x00be, 0x0000}, 1508c2ecf20Sopenharmony_ci {0x00c0, 0x0160}, 1518c2ecf20Sopenharmony_ci {0x00c1, 0x82a0}, 1528c2ecf20Sopenharmony_ci {0x00c2, 0x0000}, 1538c2ecf20Sopenharmony_ci {0x00d0, 0x0000}, 1548c2ecf20Sopenharmony_ci {0x00d1, 0x2244}, 1558c2ecf20Sopenharmony_ci {0x00d2, 0x3300}, 1568c2ecf20Sopenharmony_ci {0x00d3, 0x2200}, 1578c2ecf20Sopenharmony_ci {0x00d4, 0x0000}, 1588c2ecf20Sopenharmony_ci {0x00d9, 0x0009}, 1598c2ecf20Sopenharmony_ci {0x00da, 0x0000}, 1608c2ecf20Sopenharmony_ci {0x00db, 0x0000}, 1618c2ecf20Sopenharmony_ci {0x00dc, 0x00c0}, 1628c2ecf20Sopenharmony_ci {0x00dd, 0x2220}, 1638c2ecf20Sopenharmony_ci {0x00de, 0x3131}, 1648c2ecf20Sopenharmony_ci {0x00df, 0x3131}, 1658c2ecf20Sopenharmony_ci {0x00e0, 0x3131}, 1668c2ecf20Sopenharmony_ci {0x00e2, 0x0000}, 1678c2ecf20Sopenharmony_ci {0x00e3, 0x4000}, 1688c2ecf20Sopenharmony_ci {0x00e4, 0x0aa0}, 1698c2ecf20Sopenharmony_ci {0x00e5, 0x3131}, 1708c2ecf20Sopenharmony_ci {0x00e6, 0x3131}, 1718c2ecf20Sopenharmony_ci {0x00e7, 0x3131}, 1728c2ecf20Sopenharmony_ci {0x00e8, 0x3131}, 1738c2ecf20Sopenharmony_ci {0x00ea, 0xb320}, 1748c2ecf20Sopenharmony_ci {0x00eb, 0x0000}, 1758c2ecf20Sopenharmony_ci {0x00f0, 0x0000}, 1768c2ecf20Sopenharmony_ci {0x00f1, 0x00d0}, 1778c2ecf20Sopenharmony_ci {0x00f2, 0x00d0}, 1788c2ecf20Sopenharmony_ci {0x00f6, 0x0000}, 1798c2ecf20Sopenharmony_ci {0x00fa, 0x0000}, 1808c2ecf20Sopenharmony_ci {0x00fb, 0x0000}, 1818c2ecf20Sopenharmony_ci {0x00fc, 0x0000}, 1828c2ecf20Sopenharmony_ci {0x00fd, 0x0000}, 1838c2ecf20Sopenharmony_ci {0x00fe, 0x10ec}, 1848c2ecf20Sopenharmony_ci {0x00ff, 0x6530}, 1858c2ecf20Sopenharmony_ci {0x0100, 0xa0a0}, 1868c2ecf20Sopenharmony_ci {0x010b, 0x0000}, 1878c2ecf20Sopenharmony_ci {0x010c, 0xae00}, 1888c2ecf20Sopenharmony_ci {0x010d, 0xaaa0}, 1898c2ecf20Sopenharmony_ci {0x010e, 0x8aa2}, 1908c2ecf20Sopenharmony_ci {0x010f, 0x02a2}, 1918c2ecf20Sopenharmony_ci {0x0110, 0xc000}, 1928c2ecf20Sopenharmony_ci {0x0111, 0x04a2}, 1938c2ecf20Sopenharmony_ci {0x0112, 0x2800}, 1948c2ecf20Sopenharmony_ci {0x0113, 0x0000}, 1958c2ecf20Sopenharmony_ci {0x0117, 0x0100}, 1968c2ecf20Sopenharmony_ci {0x0125, 0x0410}, 1978c2ecf20Sopenharmony_ci {0x0132, 0x6026}, 1988c2ecf20Sopenharmony_ci {0x0136, 0x5555}, 1998c2ecf20Sopenharmony_ci {0x0138, 0x3700}, 2008c2ecf20Sopenharmony_ci {0x013a, 0x2000}, 2018c2ecf20Sopenharmony_ci {0x013b, 0x2000}, 2028c2ecf20Sopenharmony_ci {0x013c, 0x2005}, 2038c2ecf20Sopenharmony_ci {0x013f, 0x0000}, 2048c2ecf20Sopenharmony_ci {0x0142, 0x0000}, 2058c2ecf20Sopenharmony_ci {0x0145, 0x0002}, 2068c2ecf20Sopenharmony_ci {0x0146, 0x0000}, 2078c2ecf20Sopenharmony_ci {0x0147, 0x0000}, 2088c2ecf20Sopenharmony_ci {0x0148, 0x0000}, 2098c2ecf20Sopenharmony_ci {0x0149, 0x0000}, 2108c2ecf20Sopenharmony_ci {0x0150, 0x79a1}, 2118c2ecf20Sopenharmony_ci {0x0151, 0x0000}, 2128c2ecf20Sopenharmony_ci {0x0160, 0x4ec0}, 2138c2ecf20Sopenharmony_ci {0x0161, 0x0080}, 2148c2ecf20Sopenharmony_ci {0x0162, 0x0200}, 2158c2ecf20Sopenharmony_ci {0x0163, 0x0800}, 2168c2ecf20Sopenharmony_ci {0x0164, 0x0000}, 2178c2ecf20Sopenharmony_ci {0x0165, 0x0000}, 2188c2ecf20Sopenharmony_ci {0x0166, 0x0000}, 2198c2ecf20Sopenharmony_ci {0x0167, 0x000f}, 2208c2ecf20Sopenharmony_ci {0x0168, 0x000f}, 2218c2ecf20Sopenharmony_ci {0x0169, 0x0021}, 2228c2ecf20Sopenharmony_ci {0x0190, 0x413d}, 2238c2ecf20Sopenharmony_ci {0x0194, 0x0000}, 2248c2ecf20Sopenharmony_ci {0x0195, 0x0000}, 2258c2ecf20Sopenharmony_ci {0x0197, 0x0022}, 2268c2ecf20Sopenharmony_ci {0x0198, 0x0000}, 2278c2ecf20Sopenharmony_ci {0x0199, 0x0000}, 2288c2ecf20Sopenharmony_ci {0x01af, 0x0000}, 2298c2ecf20Sopenharmony_ci {0x01b0, 0x0400}, 2308c2ecf20Sopenharmony_ci {0x01b1, 0x0000}, 2318c2ecf20Sopenharmony_ci {0x01b2, 0x0000}, 2328c2ecf20Sopenharmony_ci {0x01b3, 0x0000}, 2338c2ecf20Sopenharmony_ci {0x01b4, 0x0000}, 2348c2ecf20Sopenharmony_ci {0x01b5, 0x0000}, 2358c2ecf20Sopenharmony_ci {0x01b6, 0x01c3}, 2368c2ecf20Sopenharmony_ci {0x01b7, 0x02a0}, 2378c2ecf20Sopenharmony_ci {0x01b8, 0x03e9}, 2388c2ecf20Sopenharmony_ci {0x01b9, 0x1389}, 2398c2ecf20Sopenharmony_ci {0x01ba, 0xc351}, 2408c2ecf20Sopenharmony_ci {0x01bb, 0x0009}, 2418c2ecf20Sopenharmony_ci {0x01bc, 0x0018}, 2428c2ecf20Sopenharmony_ci {0x01bd, 0x002a}, 2438c2ecf20Sopenharmony_ci {0x01be, 0x004c}, 2448c2ecf20Sopenharmony_ci {0x01bf, 0x0097}, 2458c2ecf20Sopenharmony_ci {0x01c0, 0x433d}, 2468c2ecf20Sopenharmony_ci {0x01c1, 0x2800}, 2478c2ecf20Sopenharmony_ci {0x01c2, 0x0000}, 2488c2ecf20Sopenharmony_ci {0x01c3, 0x0000}, 2498c2ecf20Sopenharmony_ci {0x01c4, 0x0000}, 2508c2ecf20Sopenharmony_ci {0x01c5, 0x0000}, 2518c2ecf20Sopenharmony_ci {0x01c6, 0x0000}, 2528c2ecf20Sopenharmony_ci {0x01c7, 0x0000}, 2538c2ecf20Sopenharmony_ci {0x01c8, 0x40af}, 2548c2ecf20Sopenharmony_ci {0x01c9, 0x0702}, 2558c2ecf20Sopenharmony_ci {0x01ca, 0x0000}, 2568c2ecf20Sopenharmony_ci {0x01cb, 0x0000}, 2578c2ecf20Sopenharmony_ci {0x01cc, 0x5757}, 2588c2ecf20Sopenharmony_ci {0x01cd, 0x5757}, 2598c2ecf20Sopenharmony_ci {0x01ce, 0x5757}, 2608c2ecf20Sopenharmony_ci {0x01cf, 0x5757}, 2618c2ecf20Sopenharmony_ci {0x01d0, 0x5757}, 2628c2ecf20Sopenharmony_ci {0x01d1, 0x5757}, 2638c2ecf20Sopenharmony_ci {0x01d2, 0x5757}, 2648c2ecf20Sopenharmony_ci {0x01d3, 0x5757}, 2658c2ecf20Sopenharmony_ci {0x01d4, 0x5757}, 2668c2ecf20Sopenharmony_ci {0x01d5, 0x5757}, 2678c2ecf20Sopenharmony_ci {0x01d6, 0x0000}, 2688c2ecf20Sopenharmony_ci {0x01d7, 0x0008}, 2698c2ecf20Sopenharmony_ci {0x01d8, 0x0029}, 2708c2ecf20Sopenharmony_ci {0x01d9, 0x3333}, 2718c2ecf20Sopenharmony_ci {0x01da, 0x0000}, 2728c2ecf20Sopenharmony_ci {0x01db, 0x0004}, 2738c2ecf20Sopenharmony_ci {0x01dc, 0x0000}, 2748c2ecf20Sopenharmony_ci {0x01de, 0x7c00}, 2758c2ecf20Sopenharmony_ci {0x01df, 0x0320}, 2768c2ecf20Sopenharmony_ci {0x01e0, 0x06a1}, 2778c2ecf20Sopenharmony_ci {0x01e1, 0x0000}, 2788c2ecf20Sopenharmony_ci {0x01e2, 0x0000}, 2798c2ecf20Sopenharmony_ci {0x01e3, 0x0000}, 2808c2ecf20Sopenharmony_ci {0x01e4, 0x0000}, 2818c2ecf20Sopenharmony_ci {0x01e6, 0x0001}, 2828c2ecf20Sopenharmony_ci {0x01e7, 0x0000}, 2838c2ecf20Sopenharmony_ci {0x01e8, 0x0000}, 2848c2ecf20Sopenharmony_ci {0x01ea, 0x0000}, 2858c2ecf20Sopenharmony_ci {0x01eb, 0x0000}, 2868c2ecf20Sopenharmony_ci {0x01ec, 0x0000}, 2878c2ecf20Sopenharmony_ci {0x01ed, 0x0000}, 2888c2ecf20Sopenharmony_ci {0x01ee, 0x0000}, 2898c2ecf20Sopenharmony_ci {0x01ef, 0x0000}, 2908c2ecf20Sopenharmony_ci {0x01f0, 0x0000}, 2918c2ecf20Sopenharmony_ci {0x01f1, 0x0000}, 2928c2ecf20Sopenharmony_ci {0x01f2, 0x0000}, 2938c2ecf20Sopenharmony_ci {0x01f3, 0x0000}, 2948c2ecf20Sopenharmony_ci {0x01f4, 0x0000}, 2958c2ecf20Sopenharmony_ci {0x0210, 0x6297}, 2968c2ecf20Sopenharmony_ci {0x0211, 0xa005}, 2978c2ecf20Sopenharmony_ci {0x0212, 0x824c}, 2988c2ecf20Sopenharmony_ci {0x0213, 0xf7ff}, 2998c2ecf20Sopenharmony_ci {0x0214, 0xf24c}, 3008c2ecf20Sopenharmony_ci {0x0215, 0x0102}, 3018c2ecf20Sopenharmony_ci {0x0216, 0x00a3}, 3028c2ecf20Sopenharmony_ci {0x0217, 0x0048}, 3038c2ecf20Sopenharmony_ci {0x0218, 0xa2c0}, 3048c2ecf20Sopenharmony_ci {0x0219, 0x0400}, 3058c2ecf20Sopenharmony_ci {0x021a, 0x00c8}, 3068c2ecf20Sopenharmony_ci {0x021b, 0x00c0}, 3078c2ecf20Sopenharmony_ci {0x021c, 0x0000}, 3088c2ecf20Sopenharmony_ci {0x0250, 0x4500}, 3098c2ecf20Sopenharmony_ci {0x0251, 0x40b3}, 3108c2ecf20Sopenharmony_ci {0x0252, 0x0000}, 3118c2ecf20Sopenharmony_ci {0x0253, 0x0000}, 3128c2ecf20Sopenharmony_ci {0x0254, 0x0000}, 3138c2ecf20Sopenharmony_ci {0x0255, 0x0000}, 3148c2ecf20Sopenharmony_ci {0x0256, 0x0000}, 3158c2ecf20Sopenharmony_ci {0x0257, 0x0000}, 3168c2ecf20Sopenharmony_ci {0x0258, 0x0000}, 3178c2ecf20Sopenharmony_ci {0x0259, 0x0000}, 3188c2ecf20Sopenharmony_ci {0x025a, 0x0005}, 3198c2ecf20Sopenharmony_ci {0x0270, 0x0000}, 3208c2ecf20Sopenharmony_ci {0x02ff, 0x0110}, 3218c2ecf20Sopenharmony_ci {0x0300, 0x001f}, 3228c2ecf20Sopenharmony_ci {0x0301, 0x032c}, 3238c2ecf20Sopenharmony_ci {0x0302, 0x5f21}, 3248c2ecf20Sopenharmony_ci {0x0303, 0x4000}, 3258c2ecf20Sopenharmony_ci {0x0304, 0x4000}, 3268c2ecf20Sopenharmony_ci {0x0305, 0x06d5}, 3278c2ecf20Sopenharmony_ci {0x0306, 0x8000}, 3288c2ecf20Sopenharmony_ci {0x0307, 0x0700}, 3298c2ecf20Sopenharmony_ci {0x0310, 0x4560}, 3308c2ecf20Sopenharmony_ci {0x0311, 0xa4a8}, 3318c2ecf20Sopenharmony_ci {0x0312, 0x7418}, 3328c2ecf20Sopenharmony_ci {0x0313, 0x0000}, 3338c2ecf20Sopenharmony_ci {0x0314, 0x0006}, 3348c2ecf20Sopenharmony_ci {0x0315, 0xffff}, 3358c2ecf20Sopenharmony_ci {0x0316, 0xc400}, 3368c2ecf20Sopenharmony_ci {0x0317, 0x0000}, 3378c2ecf20Sopenharmony_ci {0x03c0, 0x7e00}, 3388c2ecf20Sopenharmony_ci {0x03c1, 0x8000}, 3398c2ecf20Sopenharmony_ci {0x03c2, 0x8000}, 3408c2ecf20Sopenharmony_ci {0x03c3, 0x8000}, 3418c2ecf20Sopenharmony_ci {0x03c4, 0x8000}, 3428c2ecf20Sopenharmony_ci {0x03c5, 0x8000}, 3438c2ecf20Sopenharmony_ci {0x03c6, 0x8000}, 3448c2ecf20Sopenharmony_ci {0x03c7, 0x8000}, 3458c2ecf20Sopenharmony_ci {0x03c8, 0x8000}, 3468c2ecf20Sopenharmony_ci {0x03c9, 0x8000}, 3478c2ecf20Sopenharmony_ci {0x03ca, 0x8000}, 3488c2ecf20Sopenharmony_ci {0x03cb, 0x8000}, 3498c2ecf20Sopenharmony_ci {0x03cc, 0x8000}, 3508c2ecf20Sopenharmony_ci {0x03d0, 0x0000}, 3518c2ecf20Sopenharmony_ci {0x03d1, 0x0000}, 3528c2ecf20Sopenharmony_ci {0x03d2, 0x0000}, 3538c2ecf20Sopenharmony_ci {0x03d3, 0x0000}, 3548c2ecf20Sopenharmony_ci {0x03d4, 0x2000}, 3558c2ecf20Sopenharmony_ci {0x03d5, 0x2000}, 3568c2ecf20Sopenharmony_ci {0x03d6, 0x0000}, 3578c2ecf20Sopenharmony_ci {0x03d7, 0x0000}, 3588c2ecf20Sopenharmony_ci {0x03d8, 0x2000}, 3598c2ecf20Sopenharmony_ci {0x03d9, 0x2000}, 3608c2ecf20Sopenharmony_ci {0x03da, 0x2000}, 3618c2ecf20Sopenharmony_ci {0x03db, 0x2000}, 3628c2ecf20Sopenharmony_ci {0x03dc, 0x0000}, 3638c2ecf20Sopenharmony_ci {0x03dd, 0x0000}, 3648c2ecf20Sopenharmony_ci {0x03de, 0x0000}, 3658c2ecf20Sopenharmony_ci {0x03df, 0x2000}, 3668c2ecf20Sopenharmony_ci {0x03e0, 0x0000}, 3678c2ecf20Sopenharmony_ci {0x03e1, 0x0000}, 3688c2ecf20Sopenharmony_ci {0x03e2, 0x0000}, 3698c2ecf20Sopenharmony_ci {0x03e3, 0x0000}, 3708c2ecf20Sopenharmony_ci {0x03e4, 0x0000}, 3718c2ecf20Sopenharmony_ci {0x03e5, 0x0000}, 3728c2ecf20Sopenharmony_ci {0x03e6, 0x0000}, 3738c2ecf20Sopenharmony_ci {0x03e7, 0x0000}, 3748c2ecf20Sopenharmony_ci {0x03e8, 0x0000}, 3758c2ecf20Sopenharmony_ci {0x03e9, 0x0000}, 3768c2ecf20Sopenharmony_ci {0x03ea, 0x0000}, 3778c2ecf20Sopenharmony_ci {0x03eb, 0x0000}, 3788c2ecf20Sopenharmony_ci {0x03ec, 0x0000}, 3798c2ecf20Sopenharmony_ci {0x03ed, 0x0000}, 3808c2ecf20Sopenharmony_ci {0x03ee, 0x0000}, 3818c2ecf20Sopenharmony_ci {0x03ef, 0x0000}, 3828c2ecf20Sopenharmony_ci {0x03f0, 0x0800}, 3838c2ecf20Sopenharmony_ci {0x03f1, 0x0800}, 3848c2ecf20Sopenharmony_ci {0x03f2, 0x0800}, 3858c2ecf20Sopenharmony_ci {0x03f3, 0x0800}, 3868c2ecf20Sopenharmony_ci}; 3878c2ecf20Sopenharmony_ci 3888c2ecf20Sopenharmony_cistatic bool rt5668_volatile_register(struct device *dev, unsigned int reg) 3898c2ecf20Sopenharmony_ci{ 3908c2ecf20Sopenharmony_ci switch (reg) { 3918c2ecf20Sopenharmony_ci case RT5668_RESET: 3928c2ecf20Sopenharmony_ci case RT5668_CBJ_CTRL_2: 3938c2ecf20Sopenharmony_ci case RT5668_INT_ST_1: 3948c2ecf20Sopenharmony_ci case RT5668_4BTN_IL_CMD_1: 3958c2ecf20Sopenharmony_ci case RT5668_AJD1_CTRL: 3968c2ecf20Sopenharmony_ci case RT5668_HP_CALIB_CTRL_1: 3978c2ecf20Sopenharmony_ci case RT5668_DEVICE_ID: 3988c2ecf20Sopenharmony_ci case RT5668_I2C_MODE: 3998c2ecf20Sopenharmony_ci case RT5668_HP_CALIB_CTRL_10: 4008c2ecf20Sopenharmony_ci case RT5668_EFUSE_CTRL_2: 4018c2ecf20Sopenharmony_ci case RT5668_JD_TOP_VC_VTRL: 4028c2ecf20Sopenharmony_ci case RT5668_HP_IMP_SENS_CTRL_19: 4038c2ecf20Sopenharmony_ci case RT5668_IL_CMD_1: 4048c2ecf20Sopenharmony_ci case RT5668_SAR_IL_CMD_2: 4058c2ecf20Sopenharmony_ci case RT5668_SAR_IL_CMD_4: 4068c2ecf20Sopenharmony_ci case RT5668_SAR_IL_CMD_10: 4078c2ecf20Sopenharmony_ci case RT5668_SAR_IL_CMD_11: 4088c2ecf20Sopenharmony_ci case RT5668_EFUSE_CTRL_6...RT5668_EFUSE_CTRL_11: 4098c2ecf20Sopenharmony_ci case RT5668_HP_CALIB_STA_1...RT5668_HP_CALIB_STA_11: 4108c2ecf20Sopenharmony_ci return true; 4118c2ecf20Sopenharmony_ci default: 4128c2ecf20Sopenharmony_ci return false; 4138c2ecf20Sopenharmony_ci } 4148c2ecf20Sopenharmony_ci} 4158c2ecf20Sopenharmony_ci 4168c2ecf20Sopenharmony_cistatic bool rt5668_readable_register(struct device *dev, unsigned int reg) 4178c2ecf20Sopenharmony_ci{ 4188c2ecf20Sopenharmony_ci switch (reg) { 4198c2ecf20Sopenharmony_ci case RT5668_RESET: 4208c2ecf20Sopenharmony_ci case RT5668_VERSION_ID: 4218c2ecf20Sopenharmony_ci case RT5668_VENDOR_ID: 4228c2ecf20Sopenharmony_ci case RT5668_DEVICE_ID: 4238c2ecf20Sopenharmony_ci case RT5668_HP_CTRL_1: 4248c2ecf20Sopenharmony_ci case RT5668_HP_CTRL_2: 4258c2ecf20Sopenharmony_ci case RT5668_HPL_GAIN: 4268c2ecf20Sopenharmony_ci case RT5668_HPR_GAIN: 4278c2ecf20Sopenharmony_ci case RT5668_I2C_CTRL: 4288c2ecf20Sopenharmony_ci case RT5668_CBJ_BST_CTRL: 4298c2ecf20Sopenharmony_ci case RT5668_CBJ_CTRL_1: 4308c2ecf20Sopenharmony_ci case RT5668_CBJ_CTRL_2: 4318c2ecf20Sopenharmony_ci case RT5668_CBJ_CTRL_3: 4328c2ecf20Sopenharmony_ci case RT5668_CBJ_CTRL_4: 4338c2ecf20Sopenharmony_ci case RT5668_CBJ_CTRL_5: 4348c2ecf20Sopenharmony_ci case RT5668_CBJ_CTRL_6: 4358c2ecf20Sopenharmony_ci case RT5668_CBJ_CTRL_7: 4368c2ecf20Sopenharmony_ci case RT5668_DAC1_DIG_VOL: 4378c2ecf20Sopenharmony_ci case RT5668_STO1_ADC_DIG_VOL: 4388c2ecf20Sopenharmony_ci case RT5668_STO1_ADC_BOOST: 4398c2ecf20Sopenharmony_ci case RT5668_HP_IMP_GAIN_1: 4408c2ecf20Sopenharmony_ci case RT5668_HP_IMP_GAIN_2: 4418c2ecf20Sopenharmony_ci case RT5668_SIDETONE_CTRL: 4428c2ecf20Sopenharmony_ci case RT5668_STO1_ADC_MIXER: 4438c2ecf20Sopenharmony_ci case RT5668_AD_DA_MIXER: 4448c2ecf20Sopenharmony_ci case RT5668_STO1_DAC_MIXER: 4458c2ecf20Sopenharmony_ci case RT5668_A_DAC1_MUX: 4468c2ecf20Sopenharmony_ci case RT5668_DIG_INF2_DATA: 4478c2ecf20Sopenharmony_ci case RT5668_REC_MIXER: 4488c2ecf20Sopenharmony_ci case RT5668_CAL_REC: 4498c2ecf20Sopenharmony_ci case RT5668_ALC_BACK_GAIN: 4508c2ecf20Sopenharmony_ci case RT5668_PWR_DIG_1: 4518c2ecf20Sopenharmony_ci case RT5668_PWR_DIG_2: 4528c2ecf20Sopenharmony_ci case RT5668_PWR_ANLG_1: 4538c2ecf20Sopenharmony_ci case RT5668_PWR_ANLG_2: 4548c2ecf20Sopenharmony_ci case RT5668_PWR_ANLG_3: 4558c2ecf20Sopenharmony_ci case RT5668_PWR_MIXER: 4568c2ecf20Sopenharmony_ci case RT5668_PWR_VOL: 4578c2ecf20Sopenharmony_ci case RT5668_CLK_DET: 4588c2ecf20Sopenharmony_ci case RT5668_RESET_LPF_CTRL: 4598c2ecf20Sopenharmony_ci case RT5668_RESET_HPF_CTRL: 4608c2ecf20Sopenharmony_ci case RT5668_DMIC_CTRL_1: 4618c2ecf20Sopenharmony_ci case RT5668_I2S1_SDP: 4628c2ecf20Sopenharmony_ci case RT5668_I2S2_SDP: 4638c2ecf20Sopenharmony_ci case RT5668_ADDA_CLK_1: 4648c2ecf20Sopenharmony_ci case RT5668_ADDA_CLK_2: 4658c2ecf20Sopenharmony_ci case RT5668_I2S1_F_DIV_CTRL_1: 4668c2ecf20Sopenharmony_ci case RT5668_I2S1_F_DIV_CTRL_2: 4678c2ecf20Sopenharmony_ci case RT5668_TDM_CTRL: 4688c2ecf20Sopenharmony_ci case RT5668_TDM_ADDA_CTRL_1: 4698c2ecf20Sopenharmony_ci case RT5668_TDM_ADDA_CTRL_2: 4708c2ecf20Sopenharmony_ci case RT5668_DATA_SEL_CTRL_1: 4718c2ecf20Sopenharmony_ci case RT5668_TDM_TCON_CTRL: 4728c2ecf20Sopenharmony_ci case RT5668_GLB_CLK: 4738c2ecf20Sopenharmony_ci case RT5668_PLL_CTRL_1: 4748c2ecf20Sopenharmony_ci case RT5668_PLL_CTRL_2: 4758c2ecf20Sopenharmony_ci case RT5668_PLL_TRACK_1: 4768c2ecf20Sopenharmony_ci case RT5668_PLL_TRACK_2: 4778c2ecf20Sopenharmony_ci case RT5668_PLL_TRACK_3: 4788c2ecf20Sopenharmony_ci case RT5668_PLL_TRACK_4: 4798c2ecf20Sopenharmony_ci case RT5668_PLL_TRACK_5: 4808c2ecf20Sopenharmony_ci case RT5668_PLL_TRACK_6: 4818c2ecf20Sopenharmony_ci case RT5668_PLL_TRACK_11: 4828c2ecf20Sopenharmony_ci case RT5668_SDW_REF_CLK: 4838c2ecf20Sopenharmony_ci case RT5668_DEPOP_1: 4848c2ecf20Sopenharmony_ci case RT5668_DEPOP_2: 4858c2ecf20Sopenharmony_ci case RT5668_HP_CHARGE_PUMP_1: 4868c2ecf20Sopenharmony_ci case RT5668_HP_CHARGE_PUMP_2: 4878c2ecf20Sopenharmony_ci case RT5668_MICBIAS_1: 4888c2ecf20Sopenharmony_ci case RT5668_MICBIAS_2: 4898c2ecf20Sopenharmony_ci case RT5668_PLL_TRACK_12: 4908c2ecf20Sopenharmony_ci case RT5668_PLL_TRACK_14: 4918c2ecf20Sopenharmony_ci case RT5668_PLL2_CTRL_1: 4928c2ecf20Sopenharmony_ci case RT5668_PLL2_CTRL_2: 4938c2ecf20Sopenharmony_ci case RT5668_PLL2_CTRL_3: 4948c2ecf20Sopenharmony_ci case RT5668_PLL2_CTRL_4: 4958c2ecf20Sopenharmony_ci case RT5668_RC_CLK_CTRL: 4968c2ecf20Sopenharmony_ci case RT5668_I2S_M_CLK_CTRL_1: 4978c2ecf20Sopenharmony_ci case RT5668_I2S2_F_DIV_CTRL_1: 4988c2ecf20Sopenharmony_ci case RT5668_I2S2_F_DIV_CTRL_2: 4998c2ecf20Sopenharmony_ci case RT5668_EQ_CTRL_1: 5008c2ecf20Sopenharmony_ci case RT5668_EQ_CTRL_2: 5018c2ecf20Sopenharmony_ci case RT5668_IRQ_CTRL_1: 5028c2ecf20Sopenharmony_ci case RT5668_IRQ_CTRL_2: 5038c2ecf20Sopenharmony_ci case RT5668_IRQ_CTRL_3: 5048c2ecf20Sopenharmony_ci case RT5668_IRQ_CTRL_4: 5058c2ecf20Sopenharmony_ci case RT5668_INT_ST_1: 5068c2ecf20Sopenharmony_ci case RT5668_GPIO_CTRL_1: 5078c2ecf20Sopenharmony_ci case RT5668_GPIO_CTRL_2: 5088c2ecf20Sopenharmony_ci case RT5668_GPIO_CTRL_3: 5098c2ecf20Sopenharmony_ci case RT5668_HP_AMP_DET_CTRL_1: 5108c2ecf20Sopenharmony_ci case RT5668_HP_AMP_DET_CTRL_2: 5118c2ecf20Sopenharmony_ci case RT5668_MID_HP_AMP_DET: 5128c2ecf20Sopenharmony_ci case RT5668_LOW_HP_AMP_DET: 5138c2ecf20Sopenharmony_ci case RT5668_DELAY_BUF_CTRL: 5148c2ecf20Sopenharmony_ci case RT5668_SV_ZCD_1: 5158c2ecf20Sopenharmony_ci case RT5668_SV_ZCD_2: 5168c2ecf20Sopenharmony_ci case RT5668_IL_CMD_1: 5178c2ecf20Sopenharmony_ci case RT5668_IL_CMD_2: 5188c2ecf20Sopenharmony_ci case RT5668_IL_CMD_3: 5198c2ecf20Sopenharmony_ci case RT5668_IL_CMD_4: 5208c2ecf20Sopenharmony_ci case RT5668_IL_CMD_5: 5218c2ecf20Sopenharmony_ci case RT5668_IL_CMD_6: 5228c2ecf20Sopenharmony_ci case RT5668_4BTN_IL_CMD_1: 5238c2ecf20Sopenharmony_ci case RT5668_4BTN_IL_CMD_2: 5248c2ecf20Sopenharmony_ci case RT5668_4BTN_IL_CMD_3: 5258c2ecf20Sopenharmony_ci case RT5668_4BTN_IL_CMD_4: 5268c2ecf20Sopenharmony_ci case RT5668_4BTN_IL_CMD_5: 5278c2ecf20Sopenharmony_ci case RT5668_4BTN_IL_CMD_6: 5288c2ecf20Sopenharmony_ci case RT5668_4BTN_IL_CMD_7: 5298c2ecf20Sopenharmony_ci case RT5668_ADC_STO1_HP_CTRL_1: 5308c2ecf20Sopenharmony_ci case RT5668_ADC_STO1_HP_CTRL_2: 5318c2ecf20Sopenharmony_ci case RT5668_AJD1_CTRL: 5328c2ecf20Sopenharmony_ci case RT5668_JD1_THD: 5338c2ecf20Sopenharmony_ci case RT5668_JD2_THD: 5348c2ecf20Sopenharmony_ci case RT5668_JD_CTRL_1: 5358c2ecf20Sopenharmony_ci case RT5668_DUMMY_1: 5368c2ecf20Sopenharmony_ci case RT5668_DUMMY_2: 5378c2ecf20Sopenharmony_ci case RT5668_DUMMY_3: 5388c2ecf20Sopenharmony_ci case RT5668_DAC_ADC_DIG_VOL1: 5398c2ecf20Sopenharmony_ci case RT5668_BIAS_CUR_CTRL_2: 5408c2ecf20Sopenharmony_ci case RT5668_BIAS_CUR_CTRL_3: 5418c2ecf20Sopenharmony_ci case RT5668_BIAS_CUR_CTRL_4: 5428c2ecf20Sopenharmony_ci case RT5668_BIAS_CUR_CTRL_5: 5438c2ecf20Sopenharmony_ci case RT5668_BIAS_CUR_CTRL_6: 5448c2ecf20Sopenharmony_ci case RT5668_BIAS_CUR_CTRL_7: 5458c2ecf20Sopenharmony_ci case RT5668_BIAS_CUR_CTRL_8: 5468c2ecf20Sopenharmony_ci case RT5668_BIAS_CUR_CTRL_9: 5478c2ecf20Sopenharmony_ci case RT5668_BIAS_CUR_CTRL_10: 5488c2ecf20Sopenharmony_ci case RT5668_VREF_REC_OP_FB_CAP_CTRL: 5498c2ecf20Sopenharmony_ci case RT5668_CHARGE_PUMP_1: 5508c2ecf20Sopenharmony_ci case RT5668_DIG_IN_CTRL_1: 5518c2ecf20Sopenharmony_ci case RT5668_PAD_DRIVING_CTRL: 5528c2ecf20Sopenharmony_ci case RT5668_SOFT_RAMP_DEPOP: 5538c2ecf20Sopenharmony_ci case RT5668_CHOP_DAC: 5548c2ecf20Sopenharmony_ci case RT5668_CHOP_ADC: 5558c2ecf20Sopenharmony_ci case RT5668_CALIB_ADC_CTRL: 5568c2ecf20Sopenharmony_ci case RT5668_VOL_TEST: 5578c2ecf20Sopenharmony_ci case RT5668_SPKVDD_DET_STA: 5588c2ecf20Sopenharmony_ci case RT5668_TEST_MODE_CTRL_1: 5598c2ecf20Sopenharmony_ci case RT5668_TEST_MODE_CTRL_2: 5608c2ecf20Sopenharmony_ci case RT5668_TEST_MODE_CTRL_3: 5618c2ecf20Sopenharmony_ci case RT5668_TEST_MODE_CTRL_4: 5628c2ecf20Sopenharmony_ci case RT5668_TEST_MODE_CTRL_5: 5638c2ecf20Sopenharmony_ci case RT5668_PLL1_INTERNAL: 5648c2ecf20Sopenharmony_ci case RT5668_PLL2_INTERNAL: 5658c2ecf20Sopenharmony_ci case RT5668_STO_NG2_CTRL_1: 5668c2ecf20Sopenharmony_ci case RT5668_STO_NG2_CTRL_2: 5678c2ecf20Sopenharmony_ci case RT5668_STO_NG2_CTRL_3: 5688c2ecf20Sopenharmony_ci case RT5668_STO_NG2_CTRL_4: 5698c2ecf20Sopenharmony_ci case RT5668_STO_NG2_CTRL_5: 5708c2ecf20Sopenharmony_ci case RT5668_STO_NG2_CTRL_6: 5718c2ecf20Sopenharmony_ci case RT5668_STO_NG2_CTRL_7: 5728c2ecf20Sopenharmony_ci case RT5668_STO_NG2_CTRL_8: 5738c2ecf20Sopenharmony_ci case RT5668_STO_NG2_CTRL_9: 5748c2ecf20Sopenharmony_ci case RT5668_STO_NG2_CTRL_10: 5758c2ecf20Sopenharmony_ci case RT5668_STO1_DAC_SIL_DET: 5768c2ecf20Sopenharmony_ci case RT5668_SIL_PSV_CTRL1: 5778c2ecf20Sopenharmony_ci case RT5668_SIL_PSV_CTRL2: 5788c2ecf20Sopenharmony_ci case RT5668_SIL_PSV_CTRL3: 5798c2ecf20Sopenharmony_ci case RT5668_SIL_PSV_CTRL4: 5808c2ecf20Sopenharmony_ci case RT5668_SIL_PSV_CTRL5: 5818c2ecf20Sopenharmony_ci case RT5668_HP_IMP_SENS_CTRL_01: 5828c2ecf20Sopenharmony_ci case RT5668_HP_IMP_SENS_CTRL_02: 5838c2ecf20Sopenharmony_ci case RT5668_HP_IMP_SENS_CTRL_03: 5848c2ecf20Sopenharmony_ci case RT5668_HP_IMP_SENS_CTRL_04: 5858c2ecf20Sopenharmony_ci case RT5668_HP_IMP_SENS_CTRL_05: 5868c2ecf20Sopenharmony_ci case RT5668_HP_IMP_SENS_CTRL_06: 5878c2ecf20Sopenharmony_ci case RT5668_HP_IMP_SENS_CTRL_07: 5888c2ecf20Sopenharmony_ci case RT5668_HP_IMP_SENS_CTRL_08: 5898c2ecf20Sopenharmony_ci case RT5668_HP_IMP_SENS_CTRL_09: 5908c2ecf20Sopenharmony_ci case RT5668_HP_IMP_SENS_CTRL_10: 5918c2ecf20Sopenharmony_ci case RT5668_HP_IMP_SENS_CTRL_11: 5928c2ecf20Sopenharmony_ci case RT5668_HP_IMP_SENS_CTRL_12: 5938c2ecf20Sopenharmony_ci case RT5668_HP_IMP_SENS_CTRL_13: 5948c2ecf20Sopenharmony_ci case RT5668_HP_IMP_SENS_CTRL_14: 5958c2ecf20Sopenharmony_ci case RT5668_HP_IMP_SENS_CTRL_15: 5968c2ecf20Sopenharmony_ci case RT5668_HP_IMP_SENS_CTRL_16: 5978c2ecf20Sopenharmony_ci case RT5668_HP_IMP_SENS_CTRL_17: 5988c2ecf20Sopenharmony_ci case RT5668_HP_IMP_SENS_CTRL_18: 5998c2ecf20Sopenharmony_ci case RT5668_HP_IMP_SENS_CTRL_19: 6008c2ecf20Sopenharmony_ci case RT5668_HP_IMP_SENS_CTRL_20: 6018c2ecf20Sopenharmony_ci case RT5668_HP_IMP_SENS_CTRL_21: 6028c2ecf20Sopenharmony_ci case RT5668_HP_IMP_SENS_CTRL_22: 6038c2ecf20Sopenharmony_ci case RT5668_HP_IMP_SENS_CTRL_23: 6048c2ecf20Sopenharmony_ci case RT5668_HP_IMP_SENS_CTRL_24: 6058c2ecf20Sopenharmony_ci case RT5668_HP_IMP_SENS_CTRL_25: 6068c2ecf20Sopenharmony_ci case RT5668_HP_IMP_SENS_CTRL_26: 6078c2ecf20Sopenharmony_ci case RT5668_HP_IMP_SENS_CTRL_27: 6088c2ecf20Sopenharmony_ci case RT5668_HP_IMP_SENS_CTRL_28: 6098c2ecf20Sopenharmony_ci case RT5668_HP_IMP_SENS_CTRL_29: 6108c2ecf20Sopenharmony_ci case RT5668_HP_IMP_SENS_CTRL_30: 6118c2ecf20Sopenharmony_ci case RT5668_HP_IMP_SENS_CTRL_31: 6128c2ecf20Sopenharmony_ci case RT5668_HP_IMP_SENS_CTRL_32: 6138c2ecf20Sopenharmony_ci case RT5668_HP_IMP_SENS_CTRL_33: 6148c2ecf20Sopenharmony_ci case RT5668_HP_IMP_SENS_CTRL_34: 6158c2ecf20Sopenharmony_ci case RT5668_HP_IMP_SENS_CTRL_35: 6168c2ecf20Sopenharmony_ci case RT5668_HP_IMP_SENS_CTRL_36: 6178c2ecf20Sopenharmony_ci case RT5668_HP_IMP_SENS_CTRL_37: 6188c2ecf20Sopenharmony_ci case RT5668_HP_IMP_SENS_CTRL_38: 6198c2ecf20Sopenharmony_ci case RT5668_HP_IMP_SENS_CTRL_39: 6208c2ecf20Sopenharmony_ci case RT5668_HP_IMP_SENS_CTRL_40: 6218c2ecf20Sopenharmony_ci case RT5668_HP_IMP_SENS_CTRL_41: 6228c2ecf20Sopenharmony_ci case RT5668_HP_IMP_SENS_CTRL_42: 6238c2ecf20Sopenharmony_ci case RT5668_HP_IMP_SENS_CTRL_43: 6248c2ecf20Sopenharmony_ci case RT5668_HP_LOGIC_CTRL_1: 6258c2ecf20Sopenharmony_ci case RT5668_HP_LOGIC_CTRL_2: 6268c2ecf20Sopenharmony_ci case RT5668_HP_LOGIC_CTRL_3: 6278c2ecf20Sopenharmony_ci case RT5668_HP_CALIB_CTRL_1: 6288c2ecf20Sopenharmony_ci case RT5668_HP_CALIB_CTRL_2: 6298c2ecf20Sopenharmony_ci case RT5668_HP_CALIB_CTRL_3: 6308c2ecf20Sopenharmony_ci case RT5668_HP_CALIB_CTRL_4: 6318c2ecf20Sopenharmony_ci case RT5668_HP_CALIB_CTRL_5: 6328c2ecf20Sopenharmony_ci case RT5668_HP_CALIB_CTRL_6: 6338c2ecf20Sopenharmony_ci case RT5668_HP_CALIB_CTRL_7: 6348c2ecf20Sopenharmony_ci case RT5668_HP_CALIB_CTRL_9: 6358c2ecf20Sopenharmony_ci case RT5668_HP_CALIB_CTRL_10: 6368c2ecf20Sopenharmony_ci case RT5668_HP_CALIB_CTRL_11: 6378c2ecf20Sopenharmony_ci case RT5668_HP_CALIB_STA_1: 6388c2ecf20Sopenharmony_ci case RT5668_HP_CALIB_STA_2: 6398c2ecf20Sopenharmony_ci case RT5668_HP_CALIB_STA_3: 6408c2ecf20Sopenharmony_ci case RT5668_HP_CALIB_STA_4: 6418c2ecf20Sopenharmony_ci case RT5668_HP_CALIB_STA_5: 6428c2ecf20Sopenharmony_ci case RT5668_HP_CALIB_STA_6: 6438c2ecf20Sopenharmony_ci case RT5668_HP_CALIB_STA_7: 6448c2ecf20Sopenharmony_ci case RT5668_HP_CALIB_STA_8: 6458c2ecf20Sopenharmony_ci case RT5668_HP_CALIB_STA_9: 6468c2ecf20Sopenharmony_ci case RT5668_HP_CALIB_STA_10: 6478c2ecf20Sopenharmony_ci case RT5668_HP_CALIB_STA_11: 6488c2ecf20Sopenharmony_ci case RT5668_SAR_IL_CMD_1: 6498c2ecf20Sopenharmony_ci case RT5668_SAR_IL_CMD_2: 6508c2ecf20Sopenharmony_ci case RT5668_SAR_IL_CMD_3: 6518c2ecf20Sopenharmony_ci case RT5668_SAR_IL_CMD_4: 6528c2ecf20Sopenharmony_ci case RT5668_SAR_IL_CMD_5: 6538c2ecf20Sopenharmony_ci case RT5668_SAR_IL_CMD_6: 6548c2ecf20Sopenharmony_ci case RT5668_SAR_IL_CMD_7: 6558c2ecf20Sopenharmony_ci case RT5668_SAR_IL_CMD_8: 6568c2ecf20Sopenharmony_ci case RT5668_SAR_IL_CMD_9: 6578c2ecf20Sopenharmony_ci case RT5668_SAR_IL_CMD_10: 6588c2ecf20Sopenharmony_ci case RT5668_SAR_IL_CMD_11: 6598c2ecf20Sopenharmony_ci case RT5668_SAR_IL_CMD_12: 6608c2ecf20Sopenharmony_ci case RT5668_SAR_IL_CMD_13: 6618c2ecf20Sopenharmony_ci case RT5668_EFUSE_CTRL_1: 6628c2ecf20Sopenharmony_ci case RT5668_EFUSE_CTRL_2: 6638c2ecf20Sopenharmony_ci case RT5668_EFUSE_CTRL_3: 6648c2ecf20Sopenharmony_ci case RT5668_EFUSE_CTRL_4: 6658c2ecf20Sopenharmony_ci case RT5668_EFUSE_CTRL_5: 6668c2ecf20Sopenharmony_ci case RT5668_EFUSE_CTRL_6: 6678c2ecf20Sopenharmony_ci case RT5668_EFUSE_CTRL_7: 6688c2ecf20Sopenharmony_ci case RT5668_EFUSE_CTRL_8: 6698c2ecf20Sopenharmony_ci case RT5668_EFUSE_CTRL_9: 6708c2ecf20Sopenharmony_ci case RT5668_EFUSE_CTRL_10: 6718c2ecf20Sopenharmony_ci case RT5668_EFUSE_CTRL_11: 6728c2ecf20Sopenharmony_ci case RT5668_JD_TOP_VC_VTRL: 6738c2ecf20Sopenharmony_ci case RT5668_DRC1_CTRL_0: 6748c2ecf20Sopenharmony_ci case RT5668_DRC1_CTRL_1: 6758c2ecf20Sopenharmony_ci case RT5668_DRC1_CTRL_2: 6768c2ecf20Sopenharmony_ci case RT5668_DRC1_CTRL_3: 6778c2ecf20Sopenharmony_ci case RT5668_DRC1_CTRL_4: 6788c2ecf20Sopenharmony_ci case RT5668_DRC1_CTRL_5: 6798c2ecf20Sopenharmony_ci case RT5668_DRC1_CTRL_6: 6808c2ecf20Sopenharmony_ci case RT5668_DRC1_HARD_LMT_CTRL_1: 6818c2ecf20Sopenharmony_ci case RT5668_DRC1_HARD_LMT_CTRL_2: 6828c2ecf20Sopenharmony_ci case RT5668_DRC1_PRIV_1: 6838c2ecf20Sopenharmony_ci case RT5668_DRC1_PRIV_2: 6848c2ecf20Sopenharmony_ci case RT5668_DRC1_PRIV_3: 6858c2ecf20Sopenharmony_ci case RT5668_DRC1_PRIV_4: 6868c2ecf20Sopenharmony_ci case RT5668_DRC1_PRIV_5: 6878c2ecf20Sopenharmony_ci case RT5668_DRC1_PRIV_6: 6888c2ecf20Sopenharmony_ci case RT5668_DRC1_PRIV_7: 6898c2ecf20Sopenharmony_ci case RT5668_DRC1_PRIV_8: 6908c2ecf20Sopenharmony_ci case RT5668_EQ_AUTO_RCV_CTRL1: 6918c2ecf20Sopenharmony_ci case RT5668_EQ_AUTO_RCV_CTRL2: 6928c2ecf20Sopenharmony_ci case RT5668_EQ_AUTO_RCV_CTRL3: 6938c2ecf20Sopenharmony_ci case RT5668_EQ_AUTO_RCV_CTRL4: 6948c2ecf20Sopenharmony_ci case RT5668_EQ_AUTO_RCV_CTRL5: 6958c2ecf20Sopenharmony_ci case RT5668_EQ_AUTO_RCV_CTRL6: 6968c2ecf20Sopenharmony_ci case RT5668_EQ_AUTO_RCV_CTRL7: 6978c2ecf20Sopenharmony_ci case RT5668_EQ_AUTO_RCV_CTRL8: 6988c2ecf20Sopenharmony_ci case RT5668_EQ_AUTO_RCV_CTRL9: 6998c2ecf20Sopenharmony_ci case RT5668_EQ_AUTO_RCV_CTRL10: 7008c2ecf20Sopenharmony_ci case RT5668_EQ_AUTO_RCV_CTRL11: 7018c2ecf20Sopenharmony_ci case RT5668_EQ_AUTO_RCV_CTRL12: 7028c2ecf20Sopenharmony_ci case RT5668_EQ_AUTO_RCV_CTRL13: 7038c2ecf20Sopenharmony_ci case RT5668_ADC_L_EQ_LPF1_A1: 7048c2ecf20Sopenharmony_ci case RT5668_R_EQ_LPF1_A1: 7058c2ecf20Sopenharmony_ci case RT5668_L_EQ_LPF1_H0: 7068c2ecf20Sopenharmony_ci case RT5668_R_EQ_LPF1_H0: 7078c2ecf20Sopenharmony_ci case RT5668_L_EQ_BPF1_A1: 7088c2ecf20Sopenharmony_ci case RT5668_R_EQ_BPF1_A1: 7098c2ecf20Sopenharmony_ci case RT5668_L_EQ_BPF1_A2: 7108c2ecf20Sopenharmony_ci case RT5668_R_EQ_BPF1_A2: 7118c2ecf20Sopenharmony_ci case RT5668_L_EQ_BPF1_H0: 7128c2ecf20Sopenharmony_ci case RT5668_R_EQ_BPF1_H0: 7138c2ecf20Sopenharmony_ci case RT5668_L_EQ_BPF2_A1: 7148c2ecf20Sopenharmony_ci case RT5668_R_EQ_BPF2_A1: 7158c2ecf20Sopenharmony_ci case RT5668_L_EQ_BPF2_A2: 7168c2ecf20Sopenharmony_ci case RT5668_R_EQ_BPF2_A2: 7178c2ecf20Sopenharmony_ci case RT5668_L_EQ_BPF2_H0: 7188c2ecf20Sopenharmony_ci case RT5668_R_EQ_BPF2_H0: 7198c2ecf20Sopenharmony_ci case RT5668_L_EQ_BPF3_A1: 7208c2ecf20Sopenharmony_ci case RT5668_R_EQ_BPF3_A1: 7218c2ecf20Sopenharmony_ci case RT5668_L_EQ_BPF3_A2: 7228c2ecf20Sopenharmony_ci case RT5668_R_EQ_BPF3_A2: 7238c2ecf20Sopenharmony_ci case RT5668_L_EQ_BPF3_H0: 7248c2ecf20Sopenharmony_ci case RT5668_R_EQ_BPF3_H0: 7258c2ecf20Sopenharmony_ci case RT5668_L_EQ_BPF4_A1: 7268c2ecf20Sopenharmony_ci case RT5668_R_EQ_BPF4_A1: 7278c2ecf20Sopenharmony_ci case RT5668_L_EQ_BPF4_A2: 7288c2ecf20Sopenharmony_ci case RT5668_R_EQ_BPF4_A2: 7298c2ecf20Sopenharmony_ci case RT5668_L_EQ_BPF4_H0: 7308c2ecf20Sopenharmony_ci case RT5668_R_EQ_BPF4_H0: 7318c2ecf20Sopenharmony_ci case RT5668_L_EQ_HPF1_A1: 7328c2ecf20Sopenharmony_ci case RT5668_R_EQ_HPF1_A1: 7338c2ecf20Sopenharmony_ci case RT5668_L_EQ_HPF1_H0: 7348c2ecf20Sopenharmony_ci case RT5668_R_EQ_HPF1_H0: 7358c2ecf20Sopenharmony_ci case RT5668_L_EQ_PRE_VOL: 7368c2ecf20Sopenharmony_ci case RT5668_R_EQ_PRE_VOL: 7378c2ecf20Sopenharmony_ci case RT5668_L_EQ_POST_VOL: 7388c2ecf20Sopenharmony_ci case RT5668_R_EQ_POST_VOL: 7398c2ecf20Sopenharmony_ci case RT5668_I2C_MODE: 7408c2ecf20Sopenharmony_ci return true; 7418c2ecf20Sopenharmony_ci default: 7428c2ecf20Sopenharmony_ci return false; 7438c2ecf20Sopenharmony_ci } 7448c2ecf20Sopenharmony_ci} 7458c2ecf20Sopenharmony_ci 7468c2ecf20Sopenharmony_cistatic const DECLARE_TLV_DB_SCALE(hp_vol_tlv, -2250, 150, 0); 7478c2ecf20Sopenharmony_cistatic const DECLARE_TLV_DB_SCALE(dac_vol_tlv, -65625, 375, 0); 7488c2ecf20Sopenharmony_cistatic const DECLARE_TLV_DB_SCALE(adc_vol_tlv, -17625, 375, 0); 7498c2ecf20Sopenharmony_cistatic const DECLARE_TLV_DB_SCALE(adc_bst_tlv, 0, 1200, 0); 7508c2ecf20Sopenharmony_ci 7518c2ecf20Sopenharmony_ci/* {0, +20, +24, +30, +35, +40, +44, +50, +52} dB */ 7528c2ecf20Sopenharmony_cistatic const DECLARE_TLV_DB_RANGE(bst_tlv, 7538c2ecf20Sopenharmony_ci 0, 0, TLV_DB_SCALE_ITEM(0, 0, 0), 7548c2ecf20Sopenharmony_ci 1, 1, TLV_DB_SCALE_ITEM(2000, 0, 0), 7558c2ecf20Sopenharmony_ci 2, 2, TLV_DB_SCALE_ITEM(2400, 0, 0), 7568c2ecf20Sopenharmony_ci 3, 5, TLV_DB_SCALE_ITEM(3000, 500, 0), 7578c2ecf20Sopenharmony_ci 6, 6, TLV_DB_SCALE_ITEM(4400, 0, 0), 7588c2ecf20Sopenharmony_ci 7, 7, TLV_DB_SCALE_ITEM(5000, 0, 0), 7598c2ecf20Sopenharmony_ci 8, 8, TLV_DB_SCALE_ITEM(5200, 0, 0) 7608c2ecf20Sopenharmony_ci); 7618c2ecf20Sopenharmony_ci 7628c2ecf20Sopenharmony_ci/* Interface data select */ 7638c2ecf20Sopenharmony_cistatic const char * const rt5668_data_select[] = { 7648c2ecf20Sopenharmony_ci "L/R", "R/L", "L/L", "R/R" 7658c2ecf20Sopenharmony_ci}; 7668c2ecf20Sopenharmony_ci 7678c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL(rt5668_if2_adc_enum, 7688c2ecf20Sopenharmony_ci RT5668_DIG_INF2_DATA, RT5668_IF2_ADC_SEL_SFT, rt5668_data_select); 7698c2ecf20Sopenharmony_ci 7708c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL(rt5668_if1_01_adc_enum, 7718c2ecf20Sopenharmony_ci RT5668_TDM_ADDA_CTRL_1, RT5668_IF1_ADC1_SEL_SFT, rt5668_data_select); 7728c2ecf20Sopenharmony_ci 7738c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL(rt5668_if1_23_adc_enum, 7748c2ecf20Sopenharmony_ci RT5668_TDM_ADDA_CTRL_1, RT5668_IF1_ADC2_SEL_SFT, rt5668_data_select); 7758c2ecf20Sopenharmony_ci 7768c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL(rt5668_if1_45_adc_enum, 7778c2ecf20Sopenharmony_ci RT5668_TDM_ADDA_CTRL_1, RT5668_IF1_ADC3_SEL_SFT, rt5668_data_select); 7788c2ecf20Sopenharmony_ci 7798c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL(rt5668_if1_67_adc_enum, 7808c2ecf20Sopenharmony_ci RT5668_TDM_ADDA_CTRL_1, RT5668_IF1_ADC4_SEL_SFT, rt5668_data_select); 7818c2ecf20Sopenharmony_ci 7828c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5668_if2_adc_swap_mux = 7838c2ecf20Sopenharmony_ci SOC_DAPM_ENUM("IF2 ADC Swap Mux", rt5668_if2_adc_enum); 7848c2ecf20Sopenharmony_ci 7858c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5668_if1_01_adc_swap_mux = 7868c2ecf20Sopenharmony_ci SOC_DAPM_ENUM("IF1 01 ADC Swap Mux", rt5668_if1_01_adc_enum); 7878c2ecf20Sopenharmony_ci 7888c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5668_if1_23_adc_swap_mux = 7898c2ecf20Sopenharmony_ci SOC_DAPM_ENUM("IF1 23 ADC Swap Mux", rt5668_if1_23_adc_enum); 7908c2ecf20Sopenharmony_ci 7918c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5668_if1_45_adc_swap_mux = 7928c2ecf20Sopenharmony_ci SOC_DAPM_ENUM("IF1 45 ADC Swap Mux", rt5668_if1_45_adc_enum); 7938c2ecf20Sopenharmony_ci 7948c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5668_if1_67_adc_swap_mux = 7958c2ecf20Sopenharmony_ci SOC_DAPM_ENUM("IF1 67 ADC Swap Mux", rt5668_if1_67_adc_enum); 7968c2ecf20Sopenharmony_ci 7978c2ecf20Sopenharmony_cistatic void rt5668_reset(struct regmap *regmap) 7988c2ecf20Sopenharmony_ci{ 7998c2ecf20Sopenharmony_ci regmap_write(regmap, RT5668_RESET, 0); 8008c2ecf20Sopenharmony_ci regmap_write(regmap, RT5668_I2C_MODE, 1); 8018c2ecf20Sopenharmony_ci} 8028c2ecf20Sopenharmony_ci/** 8038c2ecf20Sopenharmony_ci * rt5668_sel_asrc_clk_src - select ASRC clock source for a set of filters 8048c2ecf20Sopenharmony_ci * @component: SoC audio component device. 8058c2ecf20Sopenharmony_ci * @filter_mask: mask of filters. 8068c2ecf20Sopenharmony_ci * @clk_src: clock source 8078c2ecf20Sopenharmony_ci * 8088c2ecf20Sopenharmony_ci * The ASRC function is for asynchronous MCLK and LRCK. Also, since RT5668 can 8098c2ecf20Sopenharmony_ci * only support standard 32fs or 64fs i2s format, ASRC should be enabled to 8108c2ecf20Sopenharmony_ci * support special i2s clock format such as Intel's 100fs(100 * sampling rate). 8118c2ecf20Sopenharmony_ci * ASRC function will track i2s clock and generate a corresponding system clock 8128c2ecf20Sopenharmony_ci * for codec. This function provides an API to select the clock source for a 8138c2ecf20Sopenharmony_ci * set of filters specified by the mask. And the component driver will turn on 8148c2ecf20Sopenharmony_ci * ASRC for these filters if ASRC is selected as their clock source. 8158c2ecf20Sopenharmony_ci */ 8168c2ecf20Sopenharmony_ciint rt5668_sel_asrc_clk_src(struct snd_soc_component *component, 8178c2ecf20Sopenharmony_ci unsigned int filter_mask, unsigned int clk_src) 8188c2ecf20Sopenharmony_ci{ 8198c2ecf20Sopenharmony_ci 8208c2ecf20Sopenharmony_ci switch (clk_src) { 8218c2ecf20Sopenharmony_ci case RT5668_CLK_SEL_SYS: 8228c2ecf20Sopenharmony_ci case RT5668_CLK_SEL_I2S1_ASRC: 8238c2ecf20Sopenharmony_ci case RT5668_CLK_SEL_I2S2_ASRC: 8248c2ecf20Sopenharmony_ci break; 8258c2ecf20Sopenharmony_ci 8268c2ecf20Sopenharmony_ci default: 8278c2ecf20Sopenharmony_ci return -EINVAL; 8288c2ecf20Sopenharmony_ci } 8298c2ecf20Sopenharmony_ci 8308c2ecf20Sopenharmony_ci if (filter_mask & RT5668_DA_STEREO1_FILTER) { 8318c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5668_PLL_TRACK_2, 8328c2ecf20Sopenharmony_ci RT5668_FILTER_CLK_SEL_MASK, 8338c2ecf20Sopenharmony_ci clk_src << RT5668_FILTER_CLK_SEL_SFT); 8348c2ecf20Sopenharmony_ci } 8358c2ecf20Sopenharmony_ci 8368c2ecf20Sopenharmony_ci if (filter_mask & RT5668_AD_STEREO1_FILTER) { 8378c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5668_PLL_TRACK_3, 8388c2ecf20Sopenharmony_ci RT5668_FILTER_CLK_SEL_MASK, 8398c2ecf20Sopenharmony_ci clk_src << RT5668_FILTER_CLK_SEL_SFT); 8408c2ecf20Sopenharmony_ci } 8418c2ecf20Sopenharmony_ci 8428c2ecf20Sopenharmony_ci return 0; 8438c2ecf20Sopenharmony_ci} 8448c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(rt5668_sel_asrc_clk_src); 8458c2ecf20Sopenharmony_ci 8468c2ecf20Sopenharmony_cistatic int rt5668_button_detect(struct snd_soc_component *component) 8478c2ecf20Sopenharmony_ci{ 8488c2ecf20Sopenharmony_ci int btn_type, val; 8498c2ecf20Sopenharmony_ci 8508c2ecf20Sopenharmony_ci val = snd_soc_component_read(component, RT5668_4BTN_IL_CMD_1); 8518c2ecf20Sopenharmony_ci btn_type = val & 0xfff0; 8528c2ecf20Sopenharmony_ci snd_soc_component_write(component, RT5668_4BTN_IL_CMD_1, val); 8538c2ecf20Sopenharmony_ci pr_debug("%s btn_type=%x\n", __func__, btn_type); 8548c2ecf20Sopenharmony_ci 8558c2ecf20Sopenharmony_ci return btn_type; 8568c2ecf20Sopenharmony_ci} 8578c2ecf20Sopenharmony_ci 8588c2ecf20Sopenharmony_cistatic void rt5668_enable_push_button_irq(struct snd_soc_component *component, 8598c2ecf20Sopenharmony_ci bool enable) 8608c2ecf20Sopenharmony_ci{ 8618c2ecf20Sopenharmony_ci if (enable) { 8628c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5668_SAR_IL_CMD_1, 8638c2ecf20Sopenharmony_ci RT5668_SAR_BUTT_DET_MASK, RT5668_SAR_BUTT_DET_EN); 8648c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5668_SAR_IL_CMD_13, 8658c2ecf20Sopenharmony_ci RT5668_SAR_SOUR_MASK, RT5668_SAR_SOUR_BTN); 8668c2ecf20Sopenharmony_ci snd_soc_component_write(component, RT5668_IL_CMD_1, 0x0040); 8678c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5668_4BTN_IL_CMD_2, 8688c2ecf20Sopenharmony_ci RT5668_4BTN_IL_MASK | RT5668_4BTN_IL_RST_MASK, 8698c2ecf20Sopenharmony_ci RT5668_4BTN_IL_EN | RT5668_4BTN_IL_NOR); 8708c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5668_IRQ_CTRL_3, 8718c2ecf20Sopenharmony_ci RT5668_IL_IRQ_MASK, RT5668_IL_IRQ_EN); 8728c2ecf20Sopenharmony_ci } else { 8738c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5668_IRQ_CTRL_3, 8748c2ecf20Sopenharmony_ci RT5668_IL_IRQ_MASK, RT5668_IL_IRQ_DIS); 8758c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5668_SAR_IL_CMD_1, 8768c2ecf20Sopenharmony_ci RT5668_SAR_BUTT_DET_MASK, RT5668_SAR_BUTT_DET_DIS); 8778c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5668_4BTN_IL_CMD_2, 8788c2ecf20Sopenharmony_ci RT5668_4BTN_IL_MASK, RT5668_4BTN_IL_DIS); 8798c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5668_4BTN_IL_CMD_2, 8808c2ecf20Sopenharmony_ci RT5668_4BTN_IL_RST_MASK, RT5668_4BTN_IL_RST); 8818c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5668_SAR_IL_CMD_13, 8828c2ecf20Sopenharmony_ci RT5668_SAR_SOUR_MASK, RT5668_SAR_SOUR_TYPE); 8838c2ecf20Sopenharmony_ci } 8848c2ecf20Sopenharmony_ci} 8858c2ecf20Sopenharmony_ci 8868c2ecf20Sopenharmony_ci/** 8878c2ecf20Sopenharmony_ci * rt5668_headset_detect - Detect headset. 8888c2ecf20Sopenharmony_ci * @component: SoC audio component device. 8898c2ecf20Sopenharmony_ci * @jack_insert: Jack insert or not. 8908c2ecf20Sopenharmony_ci * 8918c2ecf20Sopenharmony_ci * Detect whether is headset or not when jack inserted. 8928c2ecf20Sopenharmony_ci * 8938c2ecf20Sopenharmony_ci * Returns detect status. 8948c2ecf20Sopenharmony_ci */ 8958c2ecf20Sopenharmony_cistatic int rt5668_headset_detect(struct snd_soc_component *component, 8968c2ecf20Sopenharmony_ci int jack_insert) 8978c2ecf20Sopenharmony_ci{ 8988c2ecf20Sopenharmony_ci struct rt5668_priv *rt5668 = snd_soc_component_get_drvdata(component); 8998c2ecf20Sopenharmony_ci struct snd_soc_dapm_context *dapm = 9008c2ecf20Sopenharmony_ci snd_soc_component_get_dapm(component); 9018c2ecf20Sopenharmony_ci unsigned int val, count; 9028c2ecf20Sopenharmony_ci 9038c2ecf20Sopenharmony_ci if (jack_insert) { 9048c2ecf20Sopenharmony_ci snd_soc_dapm_force_enable_pin(dapm, "CBJ Power"); 9058c2ecf20Sopenharmony_ci snd_soc_dapm_sync(dapm); 9068c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5668_CBJ_CTRL_1, 9078c2ecf20Sopenharmony_ci RT5668_TRIG_JD_MASK, RT5668_TRIG_JD_HIGH); 9088c2ecf20Sopenharmony_ci 9098c2ecf20Sopenharmony_ci count = 0; 9108c2ecf20Sopenharmony_ci val = snd_soc_component_read(component, RT5668_CBJ_CTRL_2) 9118c2ecf20Sopenharmony_ci & RT5668_JACK_TYPE_MASK; 9128c2ecf20Sopenharmony_ci while (val == 0 && count < 50) { 9138c2ecf20Sopenharmony_ci usleep_range(10000, 15000); 9148c2ecf20Sopenharmony_ci val = snd_soc_component_read(component, 9158c2ecf20Sopenharmony_ci RT5668_CBJ_CTRL_2) & RT5668_JACK_TYPE_MASK; 9168c2ecf20Sopenharmony_ci count++; 9178c2ecf20Sopenharmony_ci } 9188c2ecf20Sopenharmony_ci 9198c2ecf20Sopenharmony_ci switch (val) { 9208c2ecf20Sopenharmony_ci case 0x1: 9218c2ecf20Sopenharmony_ci case 0x2: 9228c2ecf20Sopenharmony_ci rt5668->jack_type = SND_JACK_HEADSET; 9238c2ecf20Sopenharmony_ci rt5668_enable_push_button_irq(component, true); 9248c2ecf20Sopenharmony_ci break; 9258c2ecf20Sopenharmony_ci default: 9268c2ecf20Sopenharmony_ci rt5668->jack_type = SND_JACK_HEADPHONE; 9278c2ecf20Sopenharmony_ci } 9288c2ecf20Sopenharmony_ci 9298c2ecf20Sopenharmony_ci } else { 9308c2ecf20Sopenharmony_ci rt5668_enable_push_button_irq(component, false); 9318c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5668_CBJ_CTRL_1, 9328c2ecf20Sopenharmony_ci RT5668_TRIG_JD_MASK, RT5668_TRIG_JD_LOW); 9338c2ecf20Sopenharmony_ci snd_soc_dapm_disable_pin(dapm, "CBJ Power"); 9348c2ecf20Sopenharmony_ci snd_soc_dapm_sync(dapm); 9358c2ecf20Sopenharmony_ci 9368c2ecf20Sopenharmony_ci rt5668->jack_type = 0; 9378c2ecf20Sopenharmony_ci } 9388c2ecf20Sopenharmony_ci 9398c2ecf20Sopenharmony_ci dev_dbg(component->dev, "jack_type = %d\n", rt5668->jack_type); 9408c2ecf20Sopenharmony_ci return rt5668->jack_type; 9418c2ecf20Sopenharmony_ci} 9428c2ecf20Sopenharmony_ci 9438c2ecf20Sopenharmony_cistatic irqreturn_t rt5668_irq(int irq, void *data) 9448c2ecf20Sopenharmony_ci{ 9458c2ecf20Sopenharmony_ci struct rt5668_priv *rt5668 = data; 9468c2ecf20Sopenharmony_ci 9478c2ecf20Sopenharmony_ci mod_delayed_work(system_power_efficient_wq, 9488c2ecf20Sopenharmony_ci &rt5668->jack_detect_work, msecs_to_jiffies(250)); 9498c2ecf20Sopenharmony_ci 9508c2ecf20Sopenharmony_ci return IRQ_HANDLED; 9518c2ecf20Sopenharmony_ci} 9528c2ecf20Sopenharmony_ci 9538c2ecf20Sopenharmony_cistatic void rt5668_jd_check_handler(struct work_struct *work) 9548c2ecf20Sopenharmony_ci{ 9558c2ecf20Sopenharmony_ci struct rt5668_priv *rt5668 = container_of(work, struct rt5668_priv, 9568c2ecf20Sopenharmony_ci jd_check_work.work); 9578c2ecf20Sopenharmony_ci 9588c2ecf20Sopenharmony_ci if (snd_soc_component_read(rt5668->component, RT5668_AJD1_CTRL) 9598c2ecf20Sopenharmony_ci & RT5668_JDH_RS_MASK) { 9608c2ecf20Sopenharmony_ci /* jack out */ 9618c2ecf20Sopenharmony_ci rt5668->jack_type = rt5668_headset_detect(rt5668->component, 0); 9628c2ecf20Sopenharmony_ci 9638c2ecf20Sopenharmony_ci snd_soc_jack_report(rt5668->hs_jack, rt5668->jack_type, 9648c2ecf20Sopenharmony_ci SND_JACK_HEADSET | 9658c2ecf20Sopenharmony_ci SND_JACK_BTN_0 | SND_JACK_BTN_1 | 9668c2ecf20Sopenharmony_ci SND_JACK_BTN_2 | SND_JACK_BTN_3); 9678c2ecf20Sopenharmony_ci } else { 9688c2ecf20Sopenharmony_ci schedule_delayed_work(&rt5668->jd_check_work, 500); 9698c2ecf20Sopenharmony_ci } 9708c2ecf20Sopenharmony_ci} 9718c2ecf20Sopenharmony_ci 9728c2ecf20Sopenharmony_cistatic int rt5668_set_jack_detect(struct snd_soc_component *component, 9738c2ecf20Sopenharmony_ci struct snd_soc_jack *hs_jack, void *data) 9748c2ecf20Sopenharmony_ci{ 9758c2ecf20Sopenharmony_ci struct rt5668_priv *rt5668 = snd_soc_component_get_drvdata(component); 9768c2ecf20Sopenharmony_ci 9778c2ecf20Sopenharmony_ci switch (rt5668->pdata.jd_src) { 9788c2ecf20Sopenharmony_ci case RT5668_JD1: 9798c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5668_CBJ_CTRL_2, 9808c2ecf20Sopenharmony_ci RT5668_EXT_JD_SRC, RT5668_EXT_JD_SRC_MANUAL); 9818c2ecf20Sopenharmony_ci snd_soc_component_write(component, RT5668_CBJ_CTRL_1, 0xd002); 9828c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5668_CBJ_CTRL_3, 9838c2ecf20Sopenharmony_ci RT5668_CBJ_IN_BUF_EN, RT5668_CBJ_IN_BUF_EN); 9848c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5668_SAR_IL_CMD_1, 9858c2ecf20Sopenharmony_ci RT5668_SAR_POW_MASK, RT5668_SAR_POW_EN); 9868c2ecf20Sopenharmony_ci regmap_update_bits(rt5668->regmap, RT5668_GPIO_CTRL_1, 9878c2ecf20Sopenharmony_ci RT5668_GP1_PIN_MASK, RT5668_GP1_PIN_IRQ); 9888c2ecf20Sopenharmony_ci regmap_update_bits(rt5668->regmap, RT5668_RC_CLK_CTRL, 9898c2ecf20Sopenharmony_ci RT5668_POW_IRQ | RT5668_POW_JDH | 9908c2ecf20Sopenharmony_ci RT5668_POW_ANA, RT5668_POW_IRQ | 9918c2ecf20Sopenharmony_ci RT5668_POW_JDH | RT5668_POW_ANA); 9928c2ecf20Sopenharmony_ci regmap_update_bits(rt5668->regmap, RT5668_PWR_ANLG_2, 9938c2ecf20Sopenharmony_ci RT5668_PWR_JDH | RT5668_PWR_JDL, 9948c2ecf20Sopenharmony_ci RT5668_PWR_JDH | RT5668_PWR_JDL); 9958c2ecf20Sopenharmony_ci regmap_update_bits(rt5668->regmap, RT5668_IRQ_CTRL_2, 9968c2ecf20Sopenharmony_ci RT5668_JD1_EN_MASK | RT5668_JD1_POL_MASK, 9978c2ecf20Sopenharmony_ci RT5668_JD1_EN | RT5668_JD1_POL_NOR); 9988c2ecf20Sopenharmony_ci mod_delayed_work(system_power_efficient_wq, 9998c2ecf20Sopenharmony_ci &rt5668->jack_detect_work, msecs_to_jiffies(250)); 10008c2ecf20Sopenharmony_ci break; 10018c2ecf20Sopenharmony_ci 10028c2ecf20Sopenharmony_ci case RT5668_JD_NULL: 10038c2ecf20Sopenharmony_ci regmap_update_bits(rt5668->regmap, RT5668_IRQ_CTRL_2, 10048c2ecf20Sopenharmony_ci RT5668_JD1_EN_MASK, RT5668_JD1_DIS); 10058c2ecf20Sopenharmony_ci regmap_update_bits(rt5668->regmap, RT5668_RC_CLK_CTRL, 10068c2ecf20Sopenharmony_ci RT5668_POW_JDH | RT5668_POW_JDL, 0); 10078c2ecf20Sopenharmony_ci break; 10088c2ecf20Sopenharmony_ci 10098c2ecf20Sopenharmony_ci default: 10108c2ecf20Sopenharmony_ci dev_warn(component->dev, "Wrong JD source\n"); 10118c2ecf20Sopenharmony_ci break; 10128c2ecf20Sopenharmony_ci } 10138c2ecf20Sopenharmony_ci 10148c2ecf20Sopenharmony_ci rt5668->hs_jack = hs_jack; 10158c2ecf20Sopenharmony_ci 10168c2ecf20Sopenharmony_ci return 0; 10178c2ecf20Sopenharmony_ci} 10188c2ecf20Sopenharmony_ci 10198c2ecf20Sopenharmony_cistatic void rt5668_jack_detect_handler(struct work_struct *work) 10208c2ecf20Sopenharmony_ci{ 10218c2ecf20Sopenharmony_ci struct rt5668_priv *rt5668 = 10228c2ecf20Sopenharmony_ci container_of(work, struct rt5668_priv, jack_detect_work.work); 10238c2ecf20Sopenharmony_ci int val, btn_type; 10248c2ecf20Sopenharmony_ci 10258c2ecf20Sopenharmony_ci if (!rt5668->component || !rt5668->component->card || 10268c2ecf20Sopenharmony_ci !rt5668->component->card->instantiated) { 10278c2ecf20Sopenharmony_ci /* card not yet ready, try later */ 10288c2ecf20Sopenharmony_ci mod_delayed_work(system_power_efficient_wq, 10298c2ecf20Sopenharmony_ci &rt5668->jack_detect_work, msecs_to_jiffies(15)); 10308c2ecf20Sopenharmony_ci return; 10318c2ecf20Sopenharmony_ci } 10328c2ecf20Sopenharmony_ci 10338c2ecf20Sopenharmony_ci mutex_lock(&rt5668->calibrate_mutex); 10348c2ecf20Sopenharmony_ci 10358c2ecf20Sopenharmony_ci val = snd_soc_component_read(rt5668->component, RT5668_AJD1_CTRL) 10368c2ecf20Sopenharmony_ci & RT5668_JDH_RS_MASK; 10378c2ecf20Sopenharmony_ci if (!val) { 10388c2ecf20Sopenharmony_ci /* jack in */ 10398c2ecf20Sopenharmony_ci if (rt5668->jack_type == 0) { 10408c2ecf20Sopenharmony_ci /* jack was out, report jack type */ 10418c2ecf20Sopenharmony_ci rt5668->jack_type = 10428c2ecf20Sopenharmony_ci rt5668_headset_detect(rt5668->component, 1); 10438c2ecf20Sopenharmony_ci } else { 10448c2ecf20Sopenharmony_ci /* jack is already in, report button event */ 10458c2ecf20Sopenharmony_ci rt5668->jack_type = SND_JACK_HEADSET; 10468c2ecf20Sopenharmony_ci btn_type = rt5668_button_detect(rt5668->component); 10478c2ecf20Sopenharmony_ci /** 10488c2ecf20Sopenharmony_ci * rt5668 can report three kinds of button behavior, 10498c2ecf20Sopenharmony_ci * one click, double click and hold. However, 10508c2ecf20Sopenharmony_ci * currently we will report button pressed/released 10518c2ecf20Sopenharmony_ci * event. So all the three button behaviors are 10528c2ecf20Sopenharmony_ci * treated as button pressed. 10538c2ecf20Sopenharmony_ci */ 10548c2ecf20Sopenharmony_ci switch (btn_type) { 10558c2ecf20Sopenharmony_ci case 0x8000: 10568c2ecf20Sopenharmony_ci case 0x4000: 10578c2ecf20Sopenharmony_ci case 0x2000: 10588c2ecf20Sopenharmony_ci rt5668->jack_type |= SND_JACK_BTN_0; 10598c2ecf20Sopenharmony_ci break; 10608c2ecf20Sopenharmony_ci case 0x1000: 10618c2ecf20Sopenharmony_ci case 0x0800: 10628c2ecf20Sopenharmony_ci case 0x0400: 10638c2ecf20Sopenharmony_ci rt5668->jack_type |= SND_JACK_BTN_1; 10648c2ecf20Sopenharmony_ci break; 10658c2ecf20Sopenharmony_ci case 0x0200: 10668c2ecf20Sopenharmony_ci case 0x0100: 10678c2ecf20Sopenharmony_ci case 0x0080: 10688c2ecf20Sopenharmony_ci rt5668->jack_type |= SND_JACK_BTN_2; 10698c2ecf20Sopenharmony_ci break; 10708c2ecf20Sopenharmony_ci case 0x0040: 10718c2ecf20Sopenharmony_ci case 0x0020: 10728c2ecf20Sopenharmony_ci case 0x0010: 10738c2ecf20Sopenharmony_ci rt5668->jack_type |= SND_JACK_BTN_3; 10748c2ecf20Sopenharmony_ci break; 10758c2ecf20Sopenharmony_ci case 0x0000: /* unpressed */ 10768c2ecf20Sopenharmony_ci break; 10778c2ecf20Sopenharmony_ci default: 10788c2ecf20Sopenharmony_ci btn_type = 0; 10798c2ecf20Sopenharmony_ci dev_err(rt5668->component->dev, 10808c2ecf20Sopenharmony_ci "Unexpected button code 0x%04x\n", 10818c2ecf20Sopenharmony_ci btn_type); 10828c2ecf20Sopenharmony_ci break; 10838c2ecf20Sopenharmony_ci } 10848c2ecf20Sopenharmony_ci } 10858c2ecf20Sopenharmony_ci } else { 10868c2ecf20Sopenharmony_ci /* jack out */ 10878c2ecf20Sopenharmony_ci rt5668->jack_type = rt5668_headset_detect(rt5668->component, 0); 10888c2ecf20Sopenharmony_ci } 10898c2ecf20Sopenharmony_ci 10908c2ecf20Sopenharmony_ci snd_soc_jack_report(rt5668->hs_jack, rt5668->jack_type, 10918c2ecf20Sopenharmony_ci SND_JACK_HEADSET | 10928c2ecf20Sopenharmony_ci SND_JACK_BTN_0 | SND_JACK_BTN_1 | 10938c2ecf20Sopenharmony_ci SND_JACK_BTN_2 | SND_JACK_BTN_3); 10948c2ecf20Sopenharmony_ci 10958c2ecf20Sopenharmony_ci if (rt5668->jack_type & (SND_JACK_BTN_0 | SND_JACK_BTN_1 | 10968c2ecf20Sopenharmony_ci SND_JACK_BTN_2 | SND_JACK_BTN_3)) 10978c2ecf20Sopenharmony_ci schedule_delayed_work(&rt5668->jd_check_work, 0); 10988c2ecf20Sopenharmony_ci else 10998c2ecf20Sopenharmony_ci cancel_delayed_work_sync(&rt5668->jd_check_work); 11008c2ecf20Sopenharmony_ci 11018c2ecf20Sopenharmony_ci mutex_unlock(&rt5668->calibrate_mutex); 11028c2ecf20Sopenharmony_ci} 11038c2ecf20Sopenharmony_ci 11048c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5668_snd_controls[] = { 11058c2ecf20Sopenharmony_ci /* Headphone Output Volume */ 11068c2ecf20Sopenharmony_ci SOC_DOUBLE_R_TLV("Headphone Playback Volume", RT5668_HPL_GAIN, 11078c2ecf20Sopenharmony_ci RT5668_HPR_GAIN, RT5668_G_HP_SFT, 15, 1, hp_vol_tlv), 11088c2ecf20Sopenharmony_ci 11098c2ecf20Sopenharmony_ci /* DAC Digital Volume */ 11108c2ecf20Sopenharmony_ci SOC_DOUBLE_TLV("DAC1 Playback Volume", RT5668_DAC1_DIG_VOL, 11118c2ecf20Sopenharmony_ci RT5668_L_VOL_SFT, RT5668_R_VOL_SFT, 175, 0, dac_vol_tlv), 11128c2ecf20Sopenharmony_ci 11138c2ecf20Sopenharmony_ci /* IN Boost Volume */ 11148c2ecf20Sopenharmony_ci SOC_SINGLE_TLV("CBJ Boost Volume", RT5668_CBJ_BST_CTRL, 11158c2ecf20Sopenharmony_ci RT5668_BST_CBJ_SFT, 8, 0, bst_tlv), 11168c2ecf20Sopenharmony_ci 11178c2ecf20Sopenharmony_ci /* ADC Digital Volume Control */ 11188c2ecf20Sopenharmony_ci SOC_DOUBLE("STO1 ADC Capture Switch", RT5668_STO1_ADC_DIG_VOL, 11198c2ecf20Sopenharmony_ci RT5668_L_MUTE_SFT, RT5668_R_MUTE_SFT, 1, 1), 11208c2ecf20Sopenharmony_ci SOC_DOUBLE_TLV("STO1 ADC Capture Volume", RT5668_STO1_ADC_DIG_VOL, 11218c2ecf20Sopenharmony_ci RT5668_L_VOL_SFT, RT5668_R_VOL_SFT, 127, 0, adc_vol_tlv), 11228c2ecf20Sopenharmony_ci 11238c2ecf20Sopenharmony_ci /* ADC Boost Volume Control */ 11248c2ecf20Sopenharmony_ci SOC_DOUBLE_TLV("STO1 ADC Boost Gain Volume", RT5668_STO1_ADC_BOOST, 11258c2ecf20Sopenharmony_ci RT5668_STO1_ADC_L_BST_SFT, RT5668_STO1_ADC_R_BST_SFT, 11268c2ecf20Sopenharmony_ci 3, 0, adc_bst_tlv), 11278c2ecf20Sopenharmony_ci}; 11288c2ecf20Sopenharmony_ci 11298c2ecf20Sopenharmony_ci 11308c2ecf20Sopenharmony_cistatic int rt5668_div_sel(struct rt5668_priv *rt5668, 11318c2ecf20Sopenharmony_ci int target, const int div[], int size) 11328c2ecf20Sopenharmony_ci{ 11338c2ecf20Sopenharmony_ci int i; 11348c2ecf20Sopenharmony_ci 11358c2ecf20Sopenharmony_ci if (rt5668->sysclk < target) { 11368c2ecf20Sopenharmony_ci pr_err("sysclk rate %d is too low\n", 11378c2ecf20Sopenharmony_ci rt5668->sysclk); 11388c2ecf20Sopenharmony_ci return 0; 11398c2ecf20Sopenharmony_ci } 11408c2ecf20Sopenharmony_ci 11418c2ecf20Sopenharmony_ci for (i = 0; i < size - 1; i++) { 11428c2ecf20Sopenharmony_ci pr_info("div[%d]=%d\n", i, div[i]); 11438c2ecf20Sopenharmony_ci if (target * div[i] == rt5668->sysclk) 11448c2ecf20Sopenharmony_ci return i; 11458c2ecf20Sopenharmony_ci if (target * div[i + 1] > rt5668->sysclk) { 11468c2ecf20Sopenharmony_ci pr_err("can't find div for sysclk %d\n", 11478c2ecf20Sopenharmony_ci rt5668->sysclk); 11488c2ecf20Sopenharmony_ci return i; 11498c2ecf20Sopenharmony_ci } 11508c2ecf20Sopenharmony_ci } 11518c2ecf20Sopenharmony_ci 11528c2ecf20Sopenharmony_ci if (target * div[i] < rt5668->sysclk) 11538c2ecf20Sopenharmony_ci pr_err("sysclk rate %d is too high\n", 11548c2ecf20Sopenharmony_ci rt5668->sysclk); 11558c2ecf20Sopenharmony_ci 11568c2ecf20Sopenharmony_ci return size - 1; 11578c2ecf20Sopenharmony_ci 11588c2ecf20Sopenharmony_ci} 11598c2ecf20Sopenharmony_ci 11608c2ecf20Sopenharmony_ci/** 11618c2ecf20Sopenharmony_ci * set_dmic_clk - Set parameter of dmic. 11628c2ecf20Sopenharmony_ci * 11638c2ecf20Sopenharmony_ci * @w: DAPM widget. 11648c2ecf20Sopenharmony_ci * @kcontrol: The kcontrol of this widget. 11658c2ecf20Sopenharmony_ci * @event: Event id. 11668c2ecf20Sopenharmony_ci * 11678c2ecf20Sopenharmony_ci * Choose dmic clock between 1MHz and 3MHz. 11688c2ecf20Sopenharmony_ci * It is better for clock to approximate 3MHz. 11698c2ecf20Sopenharmony_ci */ 11708c2ecf20Sopenharmony_cistatic int set_dmic_clk(struct snd_soc_dapm_widget *w, 11718c2ecf20Sopenharmony_ci struct snd_kcontrol *kcontrol, int event) 11728c2ecf20Sopenharmony_ci{ 11738c2ecf20Sopenharmony_ci struct snd_soc_component *component = 11748c2ecf20Sopenharmony_ci snd_soc_dapm_to_component(w->dapm); 11758c2ecf20Sopenharmony_ci struct rt5668_priv *rt5668 = snd_soc_component_get_drvdata(component); 11768c2ecf20Sopenharmony_ci int idx = -EINVAL; 11778c2ecf20Sopenharmony_ci static const int div[] = {2, 4, 6, 8, 12, 16, 24, 32, 48, 64, 96, 128}; 11788c2ecf20Sopenharmony_ci 11798c2ecf20Sopenharmony_ci idx = rt5668_div_sel(rt5668, 1500000, div, ARRAY_SIZE(div)); 11808c2ecf20Sopenharmony_ci 11818c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5668_DMIC_CTRL_1, 11828c2ecf20Sopenharmony_ci RT5668_DMIC_CLK_MASK, idx << RT5668_DMIC_CLK_SFT); 11838c2ecf20Sopenharmony_ci 11848c2ecf20Sopenharmony_ci return 0; 11858c2ecf20Sopenharmony_ci} 11868c2ecf20Sopenharmony_ci 11878c2ecf20Sopenharmony_cistatic int set_filter_clk(struct snd_soc_dapm_widget *w, 11888c2ecf20Sopenharmony_ci struct snd_kcontrol *kcontrol, int event) 11898c2ecf20Sopenharmony_ci{ 11908c2ecf20Sopenharmony_ci struct snd_soc_component *component = 11918c2ecf20Sopenharmony_ci snd_soc_dapm_to_component(w->dapm); 11928c2ecf20Sopenharmony_ci struct rt5668_priv *rt5668 = snd_soc_component_get_drvdata(component); 11938c2ecf20Sopenharmony_ci int ref, val, reg, idx = -EINVAL; 11948c2ecf20Sopenharmony_ci static const int div[] = {1, 2, 3, 4, 6, 8, 12, 16, 24, 32, 48}; 11958c2ecf20Sopenharmony_ci 11968c2ecf20Sopenharmony_ci val = snd_soc_component_read(component, RT5668_GPIO_CTRL_1) & 11978c2ecf20Sopenharmony_ci RT5668_GP4_PIN_MASK; 11988c2ecf20Sopenharmony_ci if (w->shift == RT5668_PWR_ADC_S1F_BIT && 11998c2ecf20Sopenharmony_ci val == RT5668_GP4_PIN_ADCDAT2) 12008c2ecf20Sopenharmony_ci ref = 256 * rt5668->lrck[RT5668_AIF2]; 12018c2ecf20Sopenharmony_ci else 12028c2ecf20Sopenharmony_ci ref = 256 * rt5668->lrck[RT5668_AIF1]; 12038c2ecf20Sopenharmony_ci 12048c2ecf20Sopenharmony_ci idx = rt5668_div_sel(rt5668, ref, div, ARRAY_SIZE(div)); 12058c2ecf20Sopenharmony_ci 12068c2ecf20Sopenharmony_ci if (w->shift == RT5668_PWR_ADC_S1F_BIT) 12078c2ecf20Sopenharmony_ci reg = RT5668_PLL_TRACK_3; 12088c2ecf20Sopenharmony_ci else 12098c2ecf20Sopenharmony_ci reg = RT5668_PLL_TRACK_2; 12108c2ecf20Sopenharmony_ci 12118c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, reg, 12128c2ecf20Sopenharmony_ci RT5668_FILTER_CLK_SEL_MASK, idx << RT5668_FILTER_CLK_SEL_SFT); 12138c2ecf20Sopenharmony_ci 12148c2ecf20Sopenharmony_ci return 0; 12158c2ecf20Sopenharmony_ci} 12168c2ecf20Sopenharmony_ci 12178c2ecf20Sopenharmony_cistatic int is_sys_clk_from_pll1(struct snd_soc_dapm_widget *w, 12188c2ecf20Sopenharmony_ci struct snd_soc_dapm_widget *sink) 12198c2ecf20Sopenharmony_ci{ 12208c2ecf20Sopenharmony_ci unsigned int val; 12218c2ecf20Sopenharmony_ci struct snd_soc_component *component = 12228c2ecf20Sopenharmony_ci snd_soc_dapm_to_component(w->dapm); 12238c2ecf20Sopenharmony_ci 12248c2ecf20Sopenharmony_ci val = snd_soc_component_read(component, RT5668_GLB_CLK); 12258c2ecf20Sopenharmony_ci val &= RT5668_SCLK_SRC_MASK; 12268c2ecf20Sopenharmony_ci if (val == RT5668_SCLK_SRC_PLL1) 12278c2ecf20Sopenharmony_ci return 1; 12288c2ecf20Sopenharmony_ci else 12298c2ecf20Sopenharmony_ci return 0; 12308c2ecf20Sopenharmony_ci} 12318c2ecf20Sopenharmony_ci 12328c2ecf20Sopenharmony_cistatic int is_using_asrc(struct snd_soc_dapm_widget *w, 12338c2ecf20Sopenharmony_ci struct snd_soc_dapm_widget *sink) 12348c2ecf20Sopenharmony_ci{ 12358c2ecf20Sopenharmony_ci unsigned int reg, shift, val; 12368c2ecf20Sopenharmony_ci struct snd_soc_component *component = 12378c2ecf20Sopenharmony_ci snd_soc_dapm_to_component(w->dapm); 12388c2ecf20Sopenharmony_ci 12398c2ecf20Sopenharmony_ci switch (w->shift) { 12408c2ecf20Sopenharmony_ci case RT5668_ADC_STO1_ASRC_SFT: 12418c2ecf20Sopenharmony_ci reg = RT5668_PLL_TRACK_3; 12428c2ecf20Sopenharmony_ci shift = RT5668_FILTER_CLK_SEL_SFT; 12438c2ecf20Sopenharmony_ci break; 12448c2ecf20Sopenharmony_ci case RT5668_DAC_STO1_ASRC_SFT: 12458c2ecf20Sopenharmony_ci reg = RT5668_PLL_TRACK_2; 12468c2ecf20Sopenharmony_ci shift = RT5668_FILTER_CLK_SEL_SFT; 12478c2ecf20Sopenharmony_ci break; 12488c2ecf20Sopenharmony_ci default: 12498c2ecf20Sopenharmony_ci return 0; 12508c2ecf20Sopenharmony_ci } 12518c2ecf20Sopenharmony_ci 12528c2ecf20Sopenharmony_ci val = (snd_soc_component_read(component, reg) >> shift) & 0xf; 12538c2ecf20Sopenharmony_ci switch (val) { 12548c2ecf20Sopenharmony_ci case RT5668_CLK_SEL_I2S1_ASRC: 12558c2ecf20Sopenharmony_ci case RT5668_CLK_SEL_I2S2_ASRC: 12568c2ecf20Sopenharmony_ci return 1; 12578c2ecf20Sopenharmony_ci default: 12588c2ecf20Sopenharmony_ci return 0; 12598c2ecf20Sopenharmony_ci } 12608c2ecf20Sopenharmony_ci 12618c2ecf20Sopenharmony_ci} 12628c2ecf20Sopenharmony_ci 12638c2ecf20Sopenharmony_ci/* Digital Mixer */ 12648c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5668_sto1_adc_l_mix[] = { 12658c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("ADC1 Switch", RT5668_STO1_ADC_MIXER, 12668c2ecf20Sopenharmony_ci RT5668_M_STO1_ADC_L1_SFT, 1, 1), 12678c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("ADC2 Switch", RT5668_STO1_ADC_MIXER, 12688c2ecf20Sopenharmony_ci RT5668_M_STO1_ADC_L2_SFT, 1, 1), 12698c2ecf20Sopenharmony_ci}; 12708c2ecf20Sopenharmony_ci 12718c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5668_sto1_adc_r_mix[] = { 12728c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("ADC1 Switch", RT5668_STO1_ADC_MIXER, 12738c2ecf20Sopenharmony_ci RT5668_M_STO1_ADC_R1_SFT, 1, 1), 12748c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("ADC2 Switch", RT5668_STO1_ADC_MIXER, 12758c2ecf20Sopenharmony_ci RT5668_M_STO1_ADC_R2_SFT, 1, 1), 12768c2ecf20Sopenharmony_ci}; 12778c2ecf20Sopenharmony_ci 12788c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5668_dac_l_mix[] = { 12798c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("Stereo ADC Switch", RT5668_AD_DA_MIXER, 12808c2ecf20Sopenharmony_ci RT5668_M_ADCMIX_L_SFT, 1, 1), 12818c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("DAC1 Switch", RT5668_AD_DA_MIXER, 12828c2ecf20Sopenharmony_ci RT5668_M_DAC1_L_SFT, 1, 1), 12838c2ecf20Sopenharmony_ci}; 12848c2ecf20Sopenharmony_ci 12858c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5668_dac_r_mix[] = { 12868c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("Stereo ADC Switch", RT5668_AD_DA_MIXER, 12878c2ecf20Sopenharmony_ci RT5668_M_ADCMIX_R_SFT, 1, 1), 12888c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("DAC1 Switch", RT5668_AD_DA_MIXER, 12898c2ecf20Sopenharmony_ci RT5668_M_DAC1_R_SFT, 1, 1), 12908c2ecf20Sopenharmony_ci}; 12918c2ecf20Sopenharmony_ci 12928c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5668_sto1_dac_l_mix[] = { 12938c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("DAC L1 Switch", RT5668_STO1_DAC_MIXER, 12948c2ecf20Sopenharmony_ci RT5668_M_DAC_L1_STO_L_SFT, 1, 1), 12958c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("DAC R1 Switch", RT5668_STO1_DAC_MIXER, 12968c2ecf20Sopenharmony_ci RT5668_M_DAC_R1_STO_L_SFT, 1, 1), 12978c2ecf20Sopenharmony_ci}; 12988c2ecf20Sopenharmony_ci 12998c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5668_sto1_dac_r_mix[] = { 13008c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("DAC L1 Switch", RT5668_STO1_DAC_MIXER, 13018c2ecf20Sopenharmony_ci RT5668_M_DAC_L1_STO_R_SFT, 1, 1), 13028c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("DAC R1 Switch", RT5668_STO1_DAC_MIXER, 13038c2ecf20Sopenharmony_ci RT5668_M_DAC_R1_STO_R_SFT, 1, 1), 13048c2ecf20Sopenharmony_ci}; 13058c2ecf20Sopenharmony_ci 13068c2ecf20Sopenharmony_ci/* Analog Input Mixer */ 13078c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5668_rec1_l_mix[] = { 13088c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE("CBJ Switch", RT5668_REC_MIXER, 13098c2ecf20Sopenharmony_ci RT5668_M_CBJ_RM1_L_SFT, 1, 1), 13108c2ecf20Sopenharmony_ci}; 13118c2ecf20Sopenharmony_ci 13128c2ecf20Sopenharmony_ci/* STO1 ADC1 Source */ 13138c2ecf20Sopenharmony_ci/* MX-26 [13] [5] */ 13148c2ecf20Sopenharmony_cistatic const char * const rt5668_sto1_adc1_src[] = { 13158c2ecf20Sopenharmony_ci "DAC MIX", "ADC" 13168c2ecf20Sopenharmony_ci}; 13178c2ecf20Sopenharmony_ci 13188c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL( 13198c2ecf20Sopenharmony_ci rt5668_sto1_adc1l_enum, RT5668_STO1_ADC_MIXER, 13208c2ecf20Sopenharmony_ci RT5668_STO1_ADC1L_SRC_SFT, rt5668_sto1_adc1_src); 13218c2ecf20Sopenharmony_ci 13228c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5668_sto1_adc1l_mux = 13238c2ecf20Sopenharmony_ci SOC_DAPM_ENUM("Stereo1 ADC1L Source", rt5668_sto1_adc1l_enum); 13248c2ecf20Sopenharmony_ci 13258c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL( 13268c2ecf20Sopenharmony_ci rt5668_sto1_adc1r_enum, RT5668_STO1_ADC_MIXER, 13278c2ecf20Sopenharmony_ci RT5668_STO1_ADC1R_SRC_SFT, rt5668_sto1_adc1_src); 13288c2ecf20Sopenharmony_ci 13298c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5668_sto1_adc1r_mux = 13308c2ecf20Sopenharmony_ci SOC_DAPM_ENUM("Stereo1 ADC1L Source", rt5668_sto1_adc1r_enum); 13318c2ecf20Sopenharmony_ci 13328c2ecf20Sopenharmony_ci/* STO1 ADC Source */ 13338c2ecf20Sopenharmony_ci/* MX-26 [11:10] [3:2] */ 13348c2ecf20Sopenharmony_cistatic const char * const rt5668_sto1_adc_src[] = { 13358c2ecf20Sopenharmony_ci "ADC1 L", "ADC1 R" 13368c2ecf20Sopenharmony_ci}; 13378c2ecf20Sopenharmony_ci 13388c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL( 13398c2ecf20Sopenharmony_ci rt5668_sto1_adcl_enum, RT5668_STO1_ADC_MIXER, 13408c2ecf20Sopenharmony_ci RT5668_STO1_ADCL_SRC_SFT, rt5668_sto1_adc_src); 13418c2ecf20Sopenharmony_ci 13428c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5668_sto1_adcl_mux = 13438c2ecf20Sopenharmony_ci SOC_DAPM_ENUM("Stereo1 ADCL Source", rt5668_sto1_adcl_enum); 13448c2ecf20Sopenharmony_ci 13458c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL( 13468c2ecf20Sopenharmony_ci rt5668_sto1_adcr_enum, RT5668_STO1_ADC_MIXER, 13478c2ecf20Sopenharmony_ci RT5668_STO1_ADCR_SRC_SFT, rt5668_sto1_adc_src); 13488c2ecf20Sopenharmony_ci 13498c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5668_sto1_adcr_mux = 13508c2ecf20Sopenharmony_ci SOC_DAPM_ENUM("Stereo1 ADCR Source", rt5668_sto1_adcr_enum); 13518c2ecf20Sopenharmony_ci 13528c2ecf20Sopenharmony_ci/* STO1 ADC2 Source */ 13538c2ecf20Sopenharmony_ci/* MX-26 [12] [4] */ 13548c2ecf20Sopenharmony_cistatic const char * const rt5668_sto1_adc2_src[] = { 13558c2ecf20Sopenharmony_ci "DAC MIX", "DMIC" 13568c2ecf20Sopenharmony_ci}; 13578c2ecf20Sopenharmony_ci 13588c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL( 13598c2ecf20Sopenharmony_ci rt5668_sto1_adc2l_enum, RT5668_STO1_ADC_MIXER, 13608c2ecf20Sopenharmony_ci RT5668_STO1_ADC2L_SRC_SFT, rt5668_sto1_adc2_src); 13618c2ecf20Sopenharmony_ci 13628c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5668_sto1_adc2l_mux = 13638c2ecf20Sopenharmony_ci SOC_DAPM_ENUM("Stereo1 ADC2L Source", rt5668_sto1_adc2l_enum); 13648c2ecf20Sopenharmony_ci 13658c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL( 13668c2ecf20Sopenharmony_ci rt5668_sto1_adc2r_enum, RT5668_STO1_ADC_MIXER, 13678c2ecf20Sopenharmony_ci RT5668_STO1_ADC2R_SRC_SFT, rt5668_sto1_adc2_src); 13688c2ecf20Sopenharmony_ci 13698c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5668_sto1_adc2r_mux = 13708c2ecf20Sopenharmony_ci SOC_DAPM_ENUM("Stereo1 ADC2R Source", rt5668_sto1_adc2r_enum); 13718c2ecf20Sopenharmony_ci 13728c2ecf20Sopenharmony_ci/* MX-79 [6:4] I2S1 ADC data location */ 13738c2ecf20Sopenharmony_cistatic const unsigned int rt5668_if1_adc_slot_values[] = { 13748c2ecf20Sopenharmony_ci 0, 13758c2ecf20Sopenharmony_ci 2, 13768c2ecf20Sopenharmony_ci 4, 13778c2ecf20Sopenharmony_ci 6, 13788c2ecf20Sopenharmony_ci}; 13798c2ecf20Sopenharmony_ci 13808c2ecf20Sopenharmony_cistatic const char * const rt5668_if1_adc_slot_src[] = { 13818c2ecf20Sopenharmony_ci "Slot 0", "Slot 2", "Slot 4", "Slot 6" 13828c2ecf20Sopenharmony_ci}; 13838c2ecf20Sopenharmony_ci 13848c2ecf20Sopenharmony_cistatic SOC_VALUE_ENUM_SINGLE_DECL(rt5668_if1_adc_slot_enum, 13858c2ecf20Sopenharmony_ci RT5668_TDM_CTRL, RT5668_TDM_ADC_LCA_SFT, RT5668_TDM_ADC_LCA_MASK, 13868c2ecf20Sopenharmony_ci rt5668_if1_adc_slot_src, rt5668_if1_adc_slot_values); 13878c2ecf20Sopenharmony_ci 13888c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5668_if1_adc_slot_mux = 13898c2ecf20Sopenharmony_ci SOC_DAPM_ENUM("IF1 ADC Slot location", rt5668_if1_adc_slot_enum); 13908c2ecf20Sopenharmony_ci 13918c2ecf20Sopenharmony_ci/* Analog DAC L1 Source, Analog DAC R1 Source*/ 13928c2ecf20Sopenharmony_ci/* MX-2B [4], MX-2B [0]*/ 13938c2ecf20Sopenharmony_cistatic const char * const rt5668_alg_dac1_src[] = { 13948c2ecf20Sopenharmony_ci "Stereo1 DAC Mixer", "DAC1" 13958c2ecf20Sopenharmony_ci}; 13968c2ecf20Sopenharmony_ci 13978c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL( 13988c2ecf20Sopenharmony_ci rt5668_alg_dac_l1_enum, RT5668_A_DAC1_MUX, 13998c2ecf20Sopenharmony_ci RT5668_A_DACL1_SFT, rt5668_alg_dac1_src); 14008c2ecf20Sopenharmony_ci 14018c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5668_alg_dac_l1_mux = 14028c2ecf20Sopenharmony_ci SOC_DAPM_ENUM("Analog DAC L1 Source", rt5668_alg_dac_l1_enum); 14038c2ecf20Sopenharmony_ci 14048c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL( 14058c2ecf20Sopenharmony_ci rt5668_alg_dac_r1_enum, RT5668_A_DAC1_MUX, 14068c2ecf20Sopenharmony_ci RT5668_A_DACR1_SFT, rt5668_alg_dac1_src); 14078c2ecf20Sopenharmony_ci 14088c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5668_alg_dac_r1_mux = 14098c2ecf20Sopenharmony_ci SOC_DAPM_ENUM("Analog DAC R1 Source", rt5668_alg_dac_r1_enum); 14108c2ecf20Sopenharmony_ci 14118c2ecf20Sopenharmony_ci/* Out Switch */ 14128c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new hpol_switch = 14138c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE_AUTODISABLE("Switch", RT5668_HP_CTRL_1, 14148c2ecf20Sopenharmony_ci RT5668_L_MUTE_SFT, 1, 1); 14158c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new hpor_switch = 14168c2ecf20Sopenharmony_ci SOC_DAPM_SINGLE_AUTODISABLE("Switch", RT5668_HP_CTRL_1, 14178c2ecf20Sopenharmony_ci RT5668_R_MUTE_SFT, 1, 1); 14188c2ecf20Sopenharmony_ci 14198c2ecf20Sopenharmony_cistatic int rt5668_hp_event(struct snd_soc_dapm_widget *w, 14208c2ecf20Sopenharmony_ci struct snd_kcontrol *kcontrol, int event) 14218c2ecf20Sopenharmony_ci{ 14228c2ecf20Sopenharmony_ci struct snd_soc_component *component = 14238c2ecf20Sopenharmony_ci snd_soc_dapm_to_component(w->dapm); 14248c2ecf20Sopenharmony_ci 14258c2ecf20Sopenharmony_ci switch (event) { 14268c2ecf20Sopenharmony_ci case SND_SOC_DAPM_PRE_PMU: 14278c2ecf20Sopenharmony_ci snd_soc_component_write(component, 14288c2ecf20Sopenharmony_ci RT5668_HP_LOGIC_CTRL_2, 0x0012); 14298c2ecf20Sopenharmony_ci snd_soc_component_write(component, 14308c2ecf20Sopenharmony_ci RT5668_HP_CTRL_2, 0x6000); 14318c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5668_STO_NG2_CTRL_1, 14328c2ecf20Sopenharmony_ci RT5668_NG2_EN_MASK, RT5668_NG2_EN); 14338c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, 14348c2ecf20Sopenharmony_ci RT5668_DEPOP_1, 0x60, 0x60); 14358c2ecf20Sopenharmony_ci break; 14368c2ecf20Sopenharmony_ci 14378c2ecf20Sopenharmony_ci case SND_SOC_DAPM_POST_PMD: 14388c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, 14398c2ecf20Sopenharmony_ci RT5668_DEPOP_1, 0x60, 0x0); 14408c2ecf20Sopenharmony_ci snd_soc_component_write(component, 14418c2ecf20Sopenharmony_ci RT5668_HP_CTRL_2, 0x0000); 14428c2ecf20Sopenharmony_ci break; 14438c2ecf20Sopenharmony_ci 14448c2ecf20Sopenharmony_ci default: 14458c2ecf20Sopenharmony_ci return 0; 14468c2ecf20Sopenharmony_ci } 14478c2ecf20Sopenharmony_ci 14488c2ecf20Sopenharmony_ci return 0; 14498c2ecf20Sopenharmony_ci 14508c2ecf20Sopenharmony_ci} 14518c2ecf20Sopenharmony_ci 14528c2ecf20Sopenharmony_cistatic int set_dmic_power(struct snd_soc_dapm_widget *w, 14538c2ecf20Sopenharmony_ci struct snd_kcontrol *kcontrol, int event) 14548c2ecf20Sopenharmony_ci{ 14558c2ecf20Sopenharmony_ci switch (event) { 14568c2ecf20Sopenharmony_ci case SND_SOC_DAPM_POST_PMU: 14578c2ecf20Sopenharmony_ci /*Add delay to avoid pop noise*/ 14588c2ecf20Sopenharmony_ci msleep(150); 14598c2ecf20Sopenharmony_ci break; 14608c2ecf20Sopenharmony_ci 14618c2ecf20Sopenharmony_ci default: 14628c2ecf20Sopenharmony_ci return 0; 14638c2ecf20Sopenharmony_ci } 14648c2ecf20Sopenharmony_ci 14658c2ecf20Sopenharmony_ci return 0; 14668c2ecf20Sopenharmony_ci} 14678c2ecf20Sopenharmony_ci 14688c2ecf20Sopenharmony_cistatic int rt5655_set_verf(struct snd_soc_dapm_widget *w, 14698c2ecf20Sopenharmony_ci struct snd_kcontrol *kcontrol, int event) 14708c2ecf20Sopenharmony_ci{ 14718c2ecf20Sopenharmony_ci struct snd_soc_component *component = 14728c2ecf20Sopenharmony_ci snd_soc_dapm_to_component(w->dapm); 14738c2ecf20Sopenharmony_ci 14748c2ecf20Sopenharmony_ci switch (event) { 14758c2ecf20Sopenharmony_ci case SND_SOC_DAPM_PRE_PMU: 14768c2ecf20Sopenharmony_ci switch (w->shift) { 14778c2ecf20Sopenharmony_ci case RT5668_PWR_VREF1_BIT: 14788c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, 14798c2ecf20Sopenharmony_ci RT5668_PWR_ANLG_1, RT5668_PWR_FV1, 0); 14808c2ecf20Sopenharmony_ci break; 14818c2ecf20Sopenharmony_ci 14828c2ecf20Sopenharmony_ci case RT5668_PWR_VREF2_BIT: 14838c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, 14848c2ecf20Sopenharmony_ci RT5668_PWR_ANLG_1, RT5668_PWR_FV2, 0); 14858c2ecf20Sopenharmony_ci break; 14868c2ecf20Sopenharmony_ci 14878c2ecf20Sopenharmony_ci default: 14888c2ecf20Sopenharmony_ci break; 14898c2ecf20Sopenharmony_ci } 14908c2ecf20Sopenharmony_ci break; 14918c2ecf20Sopenharmony_ci 14928c2ecf20Sopenharmony_ci case SND_SOC_DAPM_POST_PMU: 14938c2ecf20Sopenharmony_ci usleep_range(15000, 20000); 14948c2ecf20Sopenharmony_ci switch (w->shift) { 14958c2ecf20Sopenharmony_ci case RT5668_PWR_VREF1_BIT: 14968c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, 14978c2ecf20Sopenharmony_ci RT5668_PWR_ANLG_1, RT5668_PWR_FV1, 14988c2ecf20Sopenharmony_ci RT5668_PWR_FV1); 14998c2ecf20Sopenharmony_ci break; 15008c2ecf20Sopenharmony_ci 15018c2ecf20Sopenharmony_ci case RT5668_PWR_VREF2_BIT: 15028c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, 15038c2ecf20Sopenharmony_ci RT5668_PWR_ANLG_1, RT5668_PWR_FV2, 15048c2ecf20Sopenharmony_ci RT5668_PWR_FV2); 15058c2ecf20Sopenharmony_ci break; 15068c2ecf20Sopenharmony_ci 15078c2ecf20Sopenharmony_ci default: 15088c2ecf20Sopenharmony_ci break; 15098c2ecf20Sopenharmony_ci } 15108c2ecf20Sopenharmony_ci break; 15118c2ecf20Sopenharmony_ci 15128c2ecf20Sopenharmony_ci default: 15138c2ecf20Sopenharmony_ci return 0; 15148c2ecf20Sopenharmony_ci } 15158c2ecf20Sopenharmony_ci 15168c2ecf20Sopenharmony_ci return 0; 15178c2ecf20Sopenharmony_ci} 15188c2ecf20Sopenharmony_ci 15198c2ecf20Sopenharmony_cistatic const unsigned int rt5668_adcdat_pin_values[] = { 15208c2ecf20Sopenharmony_ci 1, 15218c2ecf20Sopenharmony_ci 3, 15228c2ecf20Sopenharmony_ci}; 15238c2ecf20Sopenharmony_ci 15248c2ecf20Sopenharmony_cistatic const char * const rt5668_adcdat_pin_select[] = { 15258c2ecf20Sopenharmony_ci "ADCDAT1", 15268c2ecf20Sopenharmony_ci "ADCDAT2", 15278c2ecf20Sopenharmony_ci}; 15288c2ecf20Sopenharmony_ci 15298c2ecf20Sopenharmony_cistatic SOC_VALUE_ENUM_SINGLE_DECL(rt5668_adcdat_pin_enum, 15308c2ecf20Sopenharmony_ci RT5668_GPIO_CTRL_1, RT5668_GP4_PIN_SFT, RT5668_GP4_PIN_MASK, 15318c2ecf20Sopenharmony_ci rt5668_adcdat_pin_select, rt5668_adcdat_pin_values); 15328c2ecf20Sopenharmony_ci 15338c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rt5668_adcdat_pin_ctrl = 15348c2ecf20Sopenharmony_ci SOC_DAPM_ENUM("ADCDAT", rt5668_adcdat_pin_enum); 15358c2ecf20Sopenharmony_ci 15368c2ecf20Sopenharmony_cistatic const struct snd_soc_dapm_widget rt5668_dapm_widgets[] = { 15378c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("LDO2", RT5668_PWR_ANLG_3, RT5668_PWR_LDO2_BIT, 15388c2ecf20Sopenharmony_ci 0, NULL, 0), 15398c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("PLL1", RT5668_PWR_ANLG_3, RT5668_PWR_PLL_BIT, 15408c2ecf20Sopenharmony_ci 0, NULL, 0), 15418c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("PLL2B", RT5668_PWR_ANLG_3, RT5668_PWR_PLL2B_BIT, 15428c2ecf20Sopenharmony_ci 0, NULL, 0), 15438c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("PLL2F", RT5668_PWR_ANLG_3, RT5668_PWR_PLL2F_BIT, 15448c2ecf20Sopenharmony_ci 0, NULL, 0), 15458c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("Vref1", RT5668_PWR_ANLG_1, RT5668_PWR_VREF1_BIT, 0, 15468c2ecf20Sopenharmony_ci rt5655_set_verf, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU), 15478c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("Vref2", RT5668_PWR_ANLG_1, RT5668_PWR_VREF2_BIT, 0, 15488c2ecf20Sopenharmony_ci rt5655_set_verf, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU), 15498c2ecf20Sopenharmony_ci 15508c2ecf20Sopenharmony_ci /* ASRC */ 15518c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY_S("DAC STO1 ASRC", 1, RT5668_PLL_TRACK_1, 15528c2ecf20Sopenharmony_ci RT5668_DAC_STO1_ASRC_SFT, 0, NULL, 0), 15538c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY_S("ADC STO1 ASRC", 1, RT5668_PLL_TRACK_1, 15548c2ecf20Sopenharmony_ci RT5668_ADC_STO1_ASRC_SFT, 0, NULL, 0), 15558c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY_S("AD ASRC", 1, RT5668_PLL_TRACK_1, 15568c2ecf20Sopenharmony_ci RT5668_AD_ASRC_SFT, 0, NULL, 0), 15578c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY_S("DA ASRC", 1, RT5668_PLL_TRACK_1, 15588c2ecf20Sopenharmony_ci RT5668_DA_ASRC_SFT, 0, NULL, 0), 15598c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY_S("DMIC ASRC", 1, RT5668_PLL_TRACK_1, 15608c2ecf20Sopenharmony_ci RT5668_DMIC_ASRC_SFT, 0, NULL, 0), 15618c2ecf20Sopenharmony_ci 15628c2ecf20Sopenharmony_ci /* Input Side */ 15638c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("MICBIAS1", RT5668_PWR_ANLG_2, RT5668_PWR_MB1_BIT, 15648c2ecf20Sopenharmony_ci 0, NULL, 0), 15658c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("MICBIAS2", RT5668_PWR_ANLG_2, RT5668_PWR_MB2_BIT, 15668c2ecf20Sopenharmony_ci 0, NULL, 0), 15678c2ecf20Sopenharmony_ci 15688c2ecf20Sopenharmony_ci /* Input Lines */ 15698c2ecf20Sopenharmony_ci SND_SOC_DAPM_INPUT("DMIC L1"), 15708c2ecf20Sopenharmony_ci SND_SOC_DAPM_INPUT("DMIC R1"), 15718c2ecf20Sopenharmony_ci 15728c2ecf20Sopenharmony_ci SND_SOC_DAPM_INPUT("IN1P"), 15738c2ecf20Sopenharmony_ci 15748c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("DMIC CLK", SND_SOC_NOPM, 0, 0, 15758c2ecf20Sopenharmony_ci set_dmic_clk, SND_SOC_DAPM_PRE_PMU), 15768c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("DMIC1 Power", RT5668_DMIC_CTRL_1, 15778c2ecf20Sopenharmony_ci RT5668_DMIC_1_EN_SFT, 0, set_dmic_power, SND_SOC_DAPM_POST_PMU), 15788c2ecf20Sopenharmony_ci 15798c2ecf20Sopenharmony_ci /* Boost */ 15808c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA("BST1 CBJ", SND_SOC_NOPM, 15818c2ecf20Sopenharmony_ci 0, 0, NULL, 0), 15828c2ecf20Sopenharmony_ci 15838c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("CBJ Power", RT5668_PWR_ANLG_3, 15848c2ecf20Sopenharmony_ci RT5668_PWR_CBJ_BIT, 0, NULL, 0), 15858c2ecf20Sopenharmony_ci 15868c2ecf20Sopenharmony_ci /* REC Mixer */ 15878c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("RECMIX1L", SND_SOC_NOPM, 0, 0, rt5668_rec1_l_mix, 15888c2ecf20Sopenharmony_ci ARRAY_SIZE(rt5668_rec1_l_mix)), 15898c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("RECMIX1L Power", RT5668_PWR_ANLG_2, 15908c2ecf20Sopenharmony_ci RT5668_PWR_RM1_L_BIT, 0, NULL, 0), 15918c2ecf20Sopenharmony_ci 15928c2ecf20Sopenharmony_ci /* ADCs */ 15938c2ecf20Sopenharmony_ci SND_SOC_DAPM_ADC("ADC1 L", NULL, SND_SOC_NOPM, 0, 0), 15948c2ecf20Sopenharmony_ci SND_SOC_DAPM_ADC("ADC1 R", NULL, SND_SOC_NOPM, 0, 0), 15958c2ecf20Sopenharmony_ci 15968c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("ADC1 L Power", RT5668_PWR_DIG_1, 15978c2ecf20Sopenharmony_ci RT5668_PWR_ADC_L1_BIT, 0, NULL, 0), 15988c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("ADC1 R Power", RT5668_PWR_DIG_1, 15998c2ecf20Sopenharmony_ci RT5668_PWR_ADC_R1_BIT, 0, NULL, 0), 16008c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("ADC1 clock", RT5668_CHOP_ADC, 16018c2ecf20Sopenharmony_ci RT5668_CKGEN_ADC1_SFT, 0, NULL, 0), 16028c2ecf20Sopenharmony_ci 16038c2ecf20Sopenharmony_ci /* ADC Mux */ 16048c2ecf20Sopenharmony_ci SND_SOC_DAPM_MUX("Stereo1 ADC L1 Mux", SND_SOC_NOPM, 0, 0, 16058c2ecf20Sopenharmony_ci &rt5668_sto1_adc1l_mux), 16068c2ecf20Sopenharmony_ci SND_SOC_DAPM_MUX("Stereo1 ADC R1 Mux", SND_SOC_NOPM, 0, 0, 16078c2ecf20Sopenharmony_ci &rt5668_sto1_adc1r_mux), 16088c2ecf20Sopenharmony_ci SND_SOC_DAPM_MUX("Stereo1 ADC L2 Mux", SND_SOC_NOPM, 0, 0, 16098c2ecf20Sopenharmony_ci &rt5668_sto1_adc2l_mux), 16108c2ecf20Sopenharmony_ci SND_SOC_DAPM_MUX("Stereo1 ADC R2 Mux", SND_SOC_NOPM, 0, 0, 16118c2ecf20Sopenharmony_ci &rt5668_sto1_adc2r_mux), 16128c2ecf20Sopenharmony_ci SND_SOC_DAPM_MUX("Stereo1 ADC L Mux", SND_SOC_NOPM, 0, 0, 16138c2ecf20Sopenharmony_ci &rt5668_sto1_adcl_mux), 16148c2ecf20Sopenharmony_ci SND_SOC_DAPM_MUX("Stereo1 ADC R Mux", SND_SOC_NOPM, 0, 0, 16158c2ecf20Sopenharmony_ci &rt5668_sto1_adcr_mux), 16168c2ecf20Sopenharmony_ci SND_SOC_DAPM_MUX("IF1_ADC Mux", SND_SOC_NOPM, 0, 0, 16178c2ecf20Sopenharmony_ci &rt5668_if1_adc_slot_mux), 16188c2ecf20Sopenharmony_ci 16198c2ecf20Sopenharmony_ci /* ADC Mixer */ 16208c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("ADC Stereo1 Filter", RT5668_PWR_DIG_2, 16218c2ecf20Sopenharmony_ci RT5668_PWR_ADC_S1F_BIT, 0, set_filter_clk, 16228c2ecf20Sopenharmony_ci SND_SOC_DAPM_PRE_PMU), 16238c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("Stereo1 ADC MIXL", RT5668_STO1_ADC_DIG_VOL, 16248c2ecf20Sopenharmony_ci RT5668_L_MUTE_SFT, 1, rt5668_sto1_adc_l_mix, 16258c2ecf20Sopenharmony_ci ARRAY_SIZE(rt5668_sto1_adc_l_mix)), 16268c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("Stereo1 ADC MIXR", RT5668_STO1_ADC_DIG_VOL, 16278c2ecf20Sopenharmony_ci RT5668_R_MUTE_SFT, 1, rt5668_sto1_adc_r_mix, 16288c2ecf20Sopenharmony_ci ARRAY_SIZE(rt5668_sto1_adc_r_mix)), 16298c2ecf20Sopenharmony_ci 16308c2ecf20Sopenharmony_ci /* ADC PGA */ 16318c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA("Stereo1 ADC MIX", SND_SOC_NOPM, 0, 0, NULL, 0), 16328c2ecf20Sopenharmony_ci 16338c2ecf20Sopenharmony_ci /* Digital Interface */ 16348c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("I2S1", RT5668_PWR_DIG_1, RT5668_PWR_I2S1_BIT, 16358c2ecf20Sopenharmony_ci 0, NULL, 0), 16368c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("I2S2", RT5668_PWR_DIG_1, RT5668_PWR_I2S2_BIT, 16378c2ecf20Sopenharmony_ci 0, NULL, 0), 16388c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA("IF1 DAC1", SND_SOC_NOPM, 0, 0, NULL, 0), 16398c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA("IF1 DAC1 L", SND_SOC_NOPM, 0, 0, NULL, 0), 16408c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA("IF1 DAC1 R", SND_SOC_NOPM, 0, 0, NULL, 0), 16418c2ecf20Sopenharmony_ci 16428c2ecf20Sopenharmony_ci /* Digital Interface Select */ 16438c2ecf20Sopenharmony_ci SND_SOC_DAPM_MUX("IF1 01 ADC Swap Mux", SND_SOC_NOPM, 0, 0, 16448c2ecf20Sopenharmony_ci &rt5668_if1_01_adc_swap_mux), 16458c2ecf20Sopenharmony_ci SND_SOC_DAPM_MUX("IF1 23 ADC Swap Mux", SND_SOC_NOPM, 0, 0, 16468c2ecf20Sopenharmony_ci &rt5668_if1_23_adc_swap_mux), 16478c2ecf20Sopenharmony_ci SND_SOC_DAPM_MUX("IF1 45 ADC Swap Mux", SND_SOC_NOPM, 0, 0, 16488c2ecf20Sopenharmony_ci &rt5668_if1_45_adc_swap_mux), 16498c2ecf20Sopenharmony_ci SND_SOC_DAPM_MUX("IF1 67 ADC Swap Mux", SND_SOC_NOPM, 0, 0, 16508c2ecf20Sopenharmony_ci &rt5668_if1_67_adc_swap_mux), 16518c2ecf20Sopenharmony_ci SND_SOC_DAPM_MUX("IF2 ADC Swap Mux", SND_SOC_NOPM, 0, 0, 16528c2ecf20Sopenharmony_ci &rt5668_if2_adc_swap_mux), 16538c2ecf20Sopenharmony_ci 16548c2ecf20Sopenharmony_ci SND_SOC_DAPM_MUX("ADCDAT Mux", SND_SOC_NOPM, 0, 0, 16558c2ecf20Sopenharmony_ci &rt5668_adcdat_pin_ctrl), 16568c2ecf20Sopenharmony_ci 16578c2ecf20Sopenharmony_ci /* Audio Interface */ 16588c2ecf20Sopenharmony_ci SND_SOC_DAPM_AIF_OUT("AIF1TX", "AIF1 Capture", 0, 16598c2ecf20Sopenharmony_ci RT5668_I2S1_SDP, RT5668_SEL_ADCDAT_SFT, 1), 16608c2ecf20Sopenharmony_ci SND_SOC_DAPM_AIF_OUT("AIF2TX", "AIF2 Capture", 0, 16618c2ecf20Sopenharmony_ci RT5668_I2S2_SDP, RT5668_I2S2_PIN_CFG_SFT, 1), 16628c2ecf20Sopenharmony_ci SND_SOC_DAPM_AIF_IN("AIF1RX", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0), 16638c2ecf20Sopenharmony_ci 16648c2ecf20Sopenharmony_ci /* Output Side */ 16658c2ecf20Sopenharmony_ci /* DAC mixer before sound effect */ 16668c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("DAC1 MIXL", SND_SOC_NOPM, 0, 0, 16678c2ecf20Sopenharmony_ci rt5668_dac_l_mix, ARRAY_SIZE(rt5668_dac_l_mix)), 16688c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("DAC1 MIXR", SND_SOC_NOPM, 0, 0, 16698c2ecf20Sopenharmony_ci rt5668_dac_r_mix, ARRAY_SIZE(rt5668_dac_r_mix)), 16708c2ecf20Sopenharmony_ci 16718c2ecf20Sopenharmony_ci /* DAC channel Mux */ 16728c2ecf20Sopenharmony_ci SND_SOC_DAPM_MUX("DAC L1 Source", SND_SOC_NOPM, 0, 0, 16738c2ecf20Sopenharmony_ci &rt5668_alg_dac_l1_mux), 16748c2ecf20Sopenharmony_ci SND_SOC_DAPM_MUX("DAC R1 Source", SND_SOC_NOPM, 0, 0, 16758c2ecf20Sopenharmony_ci &rt5668_alg_dac_r1_mux), 16768c2ecf20Sopenharmony_ci 16778c2ecf20Sopenharmony_ci /* DAC Mixer */ 16788c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("DAC Stereo1 Filter", RT5668_PWR_DIG_2, 16798c2ecf20Sopenharmony_ci RT5668_PWR_DAC_S1F_BIT, 0, set_filter_clk, 16808c2ecf20Sopenharmony_ci SND_SOC_DAPM_PRE_PMU), 16818c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("Stereo1 DAC MIXL", SND_SOC_NOPM, 0, 0, 16828c2ecf20Sopenharmony_ci rt5668_sto1_dac_l_mix, ARRAY_SIZE(rt5668_sto1_dac_l_mix)), 16838c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIXER("Stereo1 DAC MIXR", SND_SOC_NOPM, 0, 0, 16848c2ecf20Sopenharmony_ci rt5668_sto1_dac_r_mix, ARRAY_SIZE(rt5668_sto1_dac_r_mix)), 16858c2ecf20Sopenharmony_ci 16868c2ecf20Sopenharmony_ci /* DACs */ 16878c2ecf20Sopenharmony_ci SND_SOC_DAPM_DAC("DAC L1", NULL, RT5668_PWR_DIG_1, 16888c2ecf20Sopenharmony_ci RT5668_PWR_DAC_L1_BIT, 0), 16898c2ecf20Sopenharmony_ci SND_SOC_DAPM_DAC("DAC R1", NULL, RT5668_PWR_DIG_1, 16908c2ecf20Sopenharmony_ci RT5668_PWR_DAC_R1_BIT, 0), 16918c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY_S("DAC 1 Clock", 3, RT5668_CHOP_DAC, 16928c2ecf20Sopenharmony_ci RT5668_CKGEN_DAC1_SFT, 0, NULL, 0), 16938c2ecf20Sopenharmony_ci 16948c2ecf20Sopenharmony_ci /* HPO */ 16958c2ecf20Sopenharmony_ci SND_SOC_DAPM_PGA_S("HP Amp", 1, SND_SOC_NOPM, 0, 0, rt5668_hp_event, 16968c2ecf20Sopenharmony_ci SND_SOC_DAPM_POST_PMD | SND_SOC_DAPM_PRE_PMU), 16978c2ecf20Sopenharmony_ci 16988c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("HP Amp L", RT5668_PWR_ANLG_1, 16998c2ecf20Sopenharmony_ci RT5668_PWR_HA_L_BIT, 0, NULL, 0), 17008c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("HP Amp R", RT5668_PWR_ANLG_1, 17018c2ecf20Sopenharmony_ci RT5668_PWR_HA_R_BIT, 0, NULL, 0), 17028c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY_S("Charge Pump", 1, RT5668_DEPOP_1, 17038c2ecf20Sopenharmony_ci RT5668_PUMP_EN_SFT, 0, NULL, 0), 17048c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY_S("Capless", 2, RT5668_DEPOP_1, 17058c2ecf20Sopenharmony_ci RT5668_CAPLESS_EN_SFT, 0, NULL, 0), 17068c2ecf20Sopenharmony_ci 17078c2ecf20Sopenharmony_ci SND_SOC_DAPM_SWITCH("HPOL Playback", SND_SOC_NOPM, 0, 0, 17088c2ecf20Sopenharmony_ci &hpol_switch), 17098c2ecf20Sopenharmony_ci SND_SOC_DAPM_SWITCH("HPOR Playback", SND_SOC_NOPM, 0, 0, 17108c2ecf20Sopenharmony_ci &hpor_switch), 17118c2ecf20Sopenharmony_ci 17128c2ecf20Sopenharmony_ci /* CLK DET */ 17138c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("CLKDET SYS", RT5668_CLK_DET, 17148c2ecf20Sopenharmony_ci RT5668_SYS_CLK_DET_SFT, 0, NULL, 0), 17158c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("CLKDET PLL1", RT5668_CLK_DET, 17168c2ecf20Sopenharmony_ci RT5668_PLL1_CLK_DET_SFT, 0, NULL, 0), 17178c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("CLKDET PLL2", RT5668_CLK_DET, 17188c2ecf20Sopenharmony_ci RT5668_PLL2_CLK_DET_SFT, 0, NULL, 0), 17198c2ecf20Sopenharmony_ci SND_SOC_DAPM_SUPPLY("CLKDET", RT5668_CLK_DET, 17208c2ecf20Sopenharmony_ci RT5668_POW_CLK_DET_SFT, 0, NULL, 0), 17218c2ecf20Sopenharmony_ci 17228c2ecf20Sopenharmony_ci /* Output Lines */ 17238c2ecf20Sopenharmony_ci SND_SOC_DAPM_OUTPUT("HPOL"), 17248c2ecf20Sopenharmony_ci SND_SOC_DAPM_OUTPUT("HPOR"), 17258c2ecf20Sopenharmony_ci 17268c2ecf20Sopenharmony_ci}; 17278c2ecf20Sopenharmony_ci 17288c2ecf20Sopenharmony_cistatic const struct snd_soc_dapm_route rt5668_dapm_routes[] = { 17298c2ecf20Sopenharmony_ci /*PLL*/ 17308c2ecf20Sopenharmony_ci {"ADC Stereo1 Filter", NULL, "PLL1", is_sys_clk_from_pll1}, 17318c2ecf20Sopenharmony_ci {"DAC Stereo1 Filter", NULL, "PLL1", is_sys_clk_from_pll1}, 17328c2ecf20Sopenharmony_ci 17338c2ecf20Sopenharmony_ci /*ASRC*/ 17348c2ecf20Sopenharmony_ci {"ADC Stereo1 Filter", NULL, "ADC STO1 ASRC", is_using_asrc}, 17358c2ecf20Sopenharmony_ci {"DAC Stereo1 Filter", NULL, "DAC STO1 ASRC", is_using_asrc}, 17368c2ecf20Sopenharmony_ci {"ADC STO1 ASRC", NULL, "AD ASRC"}, 17378c2ecf20Sopenharmony_ci {"DAC STO1 ASRC", NULL, "DA ASRC"}, 17388c2ecf20Sopenharmony_ci 17398c2ecf20Sopenharmony_ci /*Vref*/ 17408c2ecf20Sopenharmony_ci {"MICBIAS1", NULL, "Vref1"}, 17418c2ecf20Sopenharmony_ci {"MICBIAS1", NULL, "Vref2"}, 17428c2ecf20Sopenharmony_ci {"MICBIAS2", NULL, "Vref1"}, 17438c2ecf20Sopenharmony_ci {"MICBIAS2", NULL, "Vref2"}, 17448c2ecf20Sopenharmony_ci 17458c2ecf20Sopenharmony_ci {"CLKDET SYS", NULL, "CLKDET"}, 17468c2ecf20Sopenharmony_ci 17478c2ecf20Sopenharmony_ci {"IN1P", NULL, "LDO2"}, 17488c2ecf20Sopenharmony_ci 17498c2ecf20Sopenharmony_ci {"BST1 CBJ", NULL, "IN1P"}, 17508c2ecf20Sopenharmony_ci {"BST1 CBJ", NULL, "CBJ Power"}, 17518c2ecf20Sopenharmony_ci {"CBJ Power", NULL, "Vref2"}, 17528c2ecf20Sopenharmony_ci 17538c2ecf20Sopenharmony_ci {"RECMIX1L", "CBJ Switch", "BST1 CBJ"}, 17548c2ecf20Sopenharmony_ci {"RECMIX1L", NULL, "RECMIX1L Power"}, 17558c2ecf20Sopenharmony_ci 17568c2ecf20Sopenharmony_ci {"ADC1 L", NULL, "RECMIX1L"}, 17578c2ecf20Sopenharmony_ci {"ADC1 L", NULL, "ADC1 L Power"}, 17588c2ecf20Sopenharmony_ci {"ADC1 L", NULL, "ADC1 clock"}, 17598c2ecf20Sopenharmony_ci 17608c2ecf20Sopenharmony_ci {"DMIC L1", NULL, "DMIC CLK"}, 17618c2ecf20Sopenharmony_ci {"DMIC L1", NULL, "DMIC1 Power"}, 17628c2ecf20Sopenharmony_ci {"DMIC R1", NULL, "DMIC CLK"}, 17638c2ecf20Sopenharmony_ci {"DMIC R1", NULL, "DMIC1 Power"}, 17648c2ecf20Sopenharmony_ci {"DMIC CLK", NULL, "DMIC ASRC"}, 17658c2ecf20Sopenharmony_ci 17668c2ecf20Sopenharmony_ci {"Stereo1 ADC L Mux", "ADC1 L", "ADC1 L"}, 17678c2ecf20Sopenharmony_ci {"Stereo1 ADC L Mux", "ADC1 R", "ADC1 R"}, 17688c2ecf20Sopenharmony_ci {"Stereo1 ADC R Mux", "ADC1 L", "ADC1 L"}, 17698c2ecf20Sopenharmony_ci {"Stereo1 ADC R Mux", "ADC1 R", "ADC1 R"}, 17708c2ecf20Sopenharmony_ci 17718c2ecf20Sopenharmony_ci {"Stereo1 ADC L1 Mux", "ADC", "Stereo1 ADC L Mux"}, 17728c2ecf20Sopenharmony_ci {"Stereo1 ADC L1 Mux", "DAC MIX", "Stereo1 DAC MIXL"}, 17738c2ecf20Sopenharmony_ci {"Stereo1 ADC L2 Mux", "DMIC", "DMIC L1"}, 17748c2ecf20Sopenharmony_ci {"Stereo1 ADC L2 Mux", "DAC MIX", "Stereo1 DAC MIXL"}, 17758c2ecf20Sopenharmony_ci 17768c2ecf20Sopenharmony_ci {"Stereo1 ADC R1 Mux", "ADC", "Stereo1 ADC R Mux"}, 17778c2ecf20Sopenharmony_ci {"Stereo1 ADC R1 Mux", "DAC MIX", "Stereo1 DAC MIXR"}, 17788c2ecf20Sopenharmony_ci {"Stereo1 ADC R2 Mux", "DMIC", "DMIC R1"}, 17798c2ecf20Sopenharmony_ci {"Stereo1 ADC R2 Mux", "DAC MIX", "Stereo1 DAC MIXR"}, 17808c2ecf20Sopenharmony_ci 17818c2ecf20Sopenharmony_ci {"Stereo1 ADC MIXL", "ADC1 Switch", "Stereo1 ADC L1 Mux"}, 17828c2ecf20Sopenharmony_ci {"Stereo1 ADC MIXL", "ADC2 Switch", "Stereo1 ADC L2 Mux"}, 17838c2ecf20Sopenharmony_ci {"Stereo1 ADC MIXL", NULL, "ADC Stereo1 Filter"}, 17848c2ecf20Sopenharmony_ci 17858c2ecf20Sopenharmony_ci {"Stereo1 ADC MIXR", "ADC1 Switch", "Stereo1 ADC R1 Mux"}, 17868c2ecf20Sopenharmony_ci {"Stereo1 ADC MIXR", "ADC2 Switch", "Stereo1 ADC R2 Mux"}, 17878c2ecf20Sopenharmony_ci {"Stereo1 ADC MIXR", NULL, "ADC Stereo1 Filter"}, 17888c2ecf20Sopenharmony_ci 17898c2ecf20Sopenharmony_ci {"Stereo1 ADC MIX", NULL, "Stereo1 ADC MIXL"}, 17908c2ecf20Sopenharmony_ci {"Stereo1 ADC MIX", NULL, "Stereo1 ADC MIXR"}, 17918c2ecf20Sopenharmony_ci 17928c2ecf20Sopenharmony_ci {"IF1 01 ADC Swap Mux", "L/R", "Stereo1 ADC MIX"}, 17938c2ecf20Sopenharmony_ci {"IF1 01 ADC Swap Mux", "L/L", "Stereo1 ADC MIX"}, 17948c2ecf20Sopenharmony_ci {"IF1 01 ADC Swap Mux", "R/L", "Stereo1 ADC MIX"}, 17958c2ecf20Sopenharmony_ci {"IF1 01 ADC Swap Mux", "R/R", "Stereo1 ADC MIX"}, 17968c2ecf20Sopenharmony_ci {"IF1 23 ADC Swap Mux", "L/R", "Stereo1 ADC MIX"}, 17978c2ecf20Sopenharmony_ci {"IF1 23 ADC Swap Mux", "R/L", "Stereo1 ADC MIX"}, 17988c2ecf20Sopenharmony_ci {"IF1 23 ADC Swap Mux", "L/L", "Stereo1 ADC MIX"}, 17998c2ecf20Sopenharmony_ci {"IF1 23 ADC Swap Mux", "R/R", "Stereo1 ADC MIX"}, 18008c2ecf20Sopenharmony_ci {"IF1 45 ADC Swap Mux", "L/R", "Stereo1 ADC MIX"}, 18018c2ecf20Sopenharmony_ci {"IF1 45 ADC Swap Mux", "R/L", "Stereo1 ADC MIX"}, 18028c2ecf20Sopenharmony_ci {"IF1 45 ADC Swap Mux", "L/L", "Stereo1 ADC MIX"}, 18038c2ecf20Sopenharmony_ci {"IF1 45 ADC Swap Mux", "R/R", "Stereo1 ADC MIX"}, 18048c2ecf20Sopenharmony_ci {"IF1 67 ADC Swap Mux", "L/R", "Stereo1 ADC MIX"}, 18058c2ecf20Sopenharmony_ci {"IF1 67 ADC Swap Mux", "R/L", "Stereo1 ADC MIX"}, 18068c2ecf20Sopenharmony_ci {"IF1 67 ADC Swap Mux", "L/L", "Stereo1 ADC MIX"}, 18078c2ecf20Sopenharmony_ci {"IF1 67 ADC Swap Mux", "R/R", "Stereo1 ADC MIX"}, 18088c2ecf20Sopenharmony_ci 18098c2ecf20Sopenharmony_ci {"IF1_ADC Mux", "Slot 0", "IF1 01 ADC Swap Mux"}, 18108c2ecf20Sopenharmony_ci {"IF1_ADC Mux", "Slot 2", "IF1 23 ADC Swap Mux"}, 18118c2ecf20Sopenharmony_ci {"IF1_ADC Mux", "Slot 4", "IF1 45 ADC Swap Mux"}, 18128c2ecf20Sopenharmony_ci {"IF1_ADC Mux", "Slot 6", "IF1 67 ADC Swap Mux"}, 18138c2ecf20Sopenharmony_ci {"IF1_ADC Mux", NULL, "I2S1"}, 18148c2ecf20Sopenharmony_ci {"ADCDAT Mux", "ADCDAT1", "IF1_ADC Mux"}, 18158c2ecf20Sopenharmony_ci {"AIF1TX", NULL, "ADCDAT Mux"}, 18168c2ecf20Sopenharmony_ci {"IF2 ADC Swap Mux", "L/R", "Stereo1 ADC MIX"}, 18178c2ecf20Sopenharmony_ci {"IF2 ADC Swap Mux", "R/L", "Stereo1 ADC MIX"}, 18188c2ecf20Sopenharmony_ci {"IF2 ADC Swap Mux", "L/L", "Stereo1 ADC MIX"}, 18198c2ecf20Sopenharmony_ci {"IF2 ADC Swap Mux", "R/R", "Stereo1 ADC MIX"}, 18208c2ecf20Sopenharmony_ci {"ADCDAT Mux", "ADCDAT2", "IF2 ADC Swap Mux"}, 18218c2ecf20Sopenharmony_ci {"AIF2TX", NULL, "ADCDAT Mux"}, 18228c2ecf20Sopenharmony_ci 18238c2ecf20Sopenharmony_ci {"IF1 DAC1 L", NULL, "AIF1RX"}, 18248c2ecf20Sopenharmony_ci {"IF1 DAC1 L", NULL, "I2S1"}, 18258c2ecf20Sopenharmony_ci {"IF1 DAC1 L", NULL, "DAC Stereo1 Filter"}, 18268c2ecf20Sopenharmony_ci {"IF1 DAC1 R", NULL, "AIF1RX"}, 18278c2ecf20Sopenharmony_ci {"IF1 DAC1 R", NULL, "I2S1"}, 18288c2ecf20Sopenharmony_ci {"IF1 DAC1 R", NULL, "DAC Stereo1 Filter"}, 18298c2ecf20Sopenharmony_ci 18308c2ecf20Sopenharmony_ci {"DAC1 MIXL", "Stereo ADC Switch", "Stereo1 ADC MIXL"}, 18318c2ecf20Sopenharmony_ci {"DAC1 MIXL", "DAC1 Switch", "IF1 DAC1 L"}, 18328c2ecf20Sopenharmony_ci {"DAC1 MIXR", "Stereo ADC Switch", "Stereo1 ADC MIXR"}, 18338c2ecf20Sopenharmony_ci {"DAC1 MIXR", "DAC1 Switch", "IF1 DAC1 R"}, 18348c2ecf20Sopenharmony_ci 18358c2ecf20Sopenharmony_ci {"Stereo1 DAC MIXL", "DAC L1 Switch", "DAC1 MIXL"}, 18368c2ecf20Sopenharmony_ci {"Stereo1 DAC MIXL", "DAC R1 Switch", "DAC1 MIXR"}, 18378c2ecf20Sopenharmony_ci 18388c2ecf20Sopenharmony_ci {"Stereo1 DAC MIXR", "DAC R1 Switch", "DAC1 MIXR"}, 18398c2ecf20Sopenharmony_ci {"Stereo1 DAC MIXR", "DAC L1 Switch", "DAC1 MIXL"}, 18408c2ecf20Sopenharmony_ci 18418c2ecf20Sopenharmony_ci {"DAC L1 Source", "DAC1", "DAC1 MIXL"}, 18428c2ecf20Sopenharmony_ci {"DAC L1 Source", "Stereo1 DAC Mixer", "Stereo1 DAC MIXL"}, 18438c2ecf20Sopenharmony_ci {"DAC R1 Source", "DAC1", "DAC1 MIXR"}, 18448c2ecf20Sopenharmony_ci {"DAC R1 Source", "Stereo1 DAC Mixer", "Stereo1 DAC MIXR"}, 18458c2ecf20Sopenharmony_ci 18468c2ecf20Sopenharmony_ci {"DAC L1", NULL, "DAC L1 Source"}, 18478c2ecf20Sopenharmony_ci {"DAC R1", NULL, "DAC R1 Source"}, 18488c2ecf20Sopenharmony_ci 18498c2ecf20Sopenharmony_ci {"DAC L1", NULL, "DAC 1 Clock"}, 18508c2ecf20Sopenharmony_ci {"DAC R1", NULL, "DAC 1 Clock"}, 18518c2ecf20Sopenharmony_ci 18528c2ecf20Sopenharmony_ci {"HP Amp", NULL, "DAC L1"}, 18538c2ecf20Sopenharmony_ci {"HP Amp", NULL, "DAC R1"}, 18548c2ecf20Sopenharmony_ci {"HP Amp", NULL, "HP Amp L"}, 18558c2ecf20Sopenharmony_ci {"HP Amp", NULL, "HP Amp R"}, 18568c2ecf20Sopenharmony_ci {"HP Amp", NULL, "Capless"}, 18578c2ecf20Sopenharmony_ci {"HP Amp", NULL, "Charge Pump"}, 18588c2ecf20Sopenharmony_ci {"HP Amp", NULL, "CLKDET SYS"}, 18598c2ecf20Sopenharmony_ci {"HP Amp", NULL, "CBJ Power"}, 18608c2ecf20Sopenharmony_ci {"HP Amp", NULL, "Vref2"}, 18618c2ecf20Sopenharmony_ci {"HPOL Playback", "Switch", "HP Amp"}, 18628c2ecf20Sopenharmony_ci {"HPOR Playback", "Switch", "HP Amp"}, 18638c2ecf20Sopenharmony_ci {"HPOL", NULL, "HPOL Playback"}, 18648c2ecf20Sopenharmony_ci {"HPOR", NULL, "HPOR Playback"}, 18658c2ecf20Sopenharmony_ci}; 18668c2ecf20Sopenharmony_ci 18678c2ecf20Sopenharmony_cistatic int rt5668_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask, 18688c2ecf20Sopenharmony_ci unsigned int rx_mask, int slots, int slot_width) 18698c2ecf20Sopenharmony_ci{ 18708c2ecf20Sopenharmony_ci struct snd_soc_component *component = dai->component; 18718c2ecf20Sopenharmony_ci unsigned int val = 0; 18728c2ecf20Sopenharmony_ci 18738c2ecf20Sopenharmony_ci switch (slots) { 18748c2ecf20Sopenharmony_ci case 4: 18758c2ecf20Sopenharmony_ci val |= RT5668_TDM_TX_CH_4; 18768c2ecf20Sopenharmony_ci val |= RT5668_TDM_RX_CH_4; 18778c2ecf20Sopenharmony_ci break; 18788c2ecf20Sopenharmony_ci case 6: 18798c2ecf20Sopenharmony_ci val |= RT5668_TDM_TX_CH_6; 18808c2ecf20Sopenharmony_ci val |= RT5668_TDM_RX_CH_6; 18818c2ecf20Sopenharmony_ci break; 18828c2ecf20Sopenharmony_ci case 8: 18838c2ecf20Sopenharmony_ci val |= RT5668_TDM_TX_CH_8; 18848c2ecf20Sopenharmony_ci val |= RT5668_TDM_RX_CH_8; 18858c2ecf20Sopenharmony_ci break; 18868c2ecf20Sopenharmony_ci case 2: 18878c2ecf20Sopenharmony_ci break; 18888c2ecf20Sopenharmony_ci default: 18898c2ecf20Sopenharmony_ci return -EINVAL; 18908c2ecf20Sopenharmony_ci } 18918c2ecf20Sopenharmony_ci 18928c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5668_TDM_CTRL, 18938c2ecf20Sopenharmony_ci RT5668_TDM_TX_CH_MASK | RT5668_TDM_RX_CH_MASK, val); 18948c2ecf20Sopenharmony_ci 18958c2ecf20Sopenharmony_ci switch (slot_width) { 18968c2ecf20Sopenharmony_ci case 16: 18978c2ecf20Sopenharmony_ci val = RT5668_TDM_CL_16; 18988c2ecf20Sopenharmony_ci break; 18998c2ecf20Sopenharmony_ci case 20: 19008c2ecf20Sopenharmony_ci val = RT5668_TDM_CL_20; 19018c2ecf20Sopenharmony_ci break; 19028c2ecf20Sopenharmony_ci case 24: 19038c2ecf20Sopenharmony_ci val = RT5668_TDM_CL_24; 19048c2ecf20Sopenharmony_ci break; 19058c2ecf20Sopenharmony_ci case 32: 19068c2ecf20Sopenharmony_ci val = RT5668_TDM_CL_32; 19078c2ecf20Sopenharmony_ci break; 19088c2ecf20Sopenharmony_ci default: 19098c2ecf20Sopenharmony_ci return -EINVAL; 19108c2ecf20Sopenharmony_ci } 19118c2ecf20Sopenharmony_ci 19128c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5668_TDM_TCON_CTRL, 19138c2ecf20Sopenharmony_ci RT5668_TDM_CL_MASK, val); 19148c2ecf20Sopenharmony_ci 19158c2ecf20Sopenharmony_ci return 0; 19168c2ecf20Sopenharmony_ci} 19178c2ecf20Sopenharmony_ci 19188c2ecf20Sopenharmony_ci 19198c2ecf20Sopenharmony_cistatic int rt5668_hw_params(struct snd_pcm_substream *substream, 19208c2ecf20Sopenharmony_ci struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) 19218c2ecf20Sopenharmony_ci{ 19228c2ecf20Sopenharmony_ci struct snd_soc_component *component = dai->component; 19238c2ecf20Sopenharmony_ci struct rt5668_priv *rt5668 = snd_soc_component_get_drvdata(component); 19248c2ecf20Sopenharmony_ci unsigned int len_1 = 0, len_2 = 0; 19258c2ecf20Sopenharmony_ci int pre_div, frame_size; 19268c2ecf20Sopenharmony_ci 19278c2ecf20Sopenharmony_ci rt5668->lrck[dai->id] = params_rate(params); 19288c2ecf20Sopenharmony_ci pre_div = rl6231_get_clk_info(rt5668->sysclk, rt5668->lrck[dai->id]); 19298c2ecf20Sopenharmony_ci 19308c2ecf20Sopenharmony_ci frame_size = snd_soc_params_to_frame_size(params); 19318c2ecf20Sopenharmony_ci if (frame_size < 0) { 19328c2ecf20Sopenharmony_ci dev_err(component->dev, "Unsupported frame size: %d\n", 19338c2ecf20Sopenharmony_ci frame_size); 19348c2ecf20Sopenharmony_ci return -EINVAL; 19358c2ecf20Sopenharmony_ci } 19368c2ecf20Sopenharmony_ci 19378c2ecf20Sopenharmony_ci dev_dbg(dai->dev, "lrck is %dHz and pre_div is %d for iis %d\n", 19388c2ecf20Sopenharmony_ci rt5668->lrck[dai->id], pre_div, dai->id); 19398c2ecf20Sopenharmony_ci 19408c2ecf20Sopenharmony_ci switch (params_width(params)) { 19418c2ecf20Sopenharmony_ci case 16: 19428c2ecf20Sopenharmony_ci break; 19438c2ecf20Sopenharmony_ci case 20: 19448c2ecf20Sopenharmony_ci len_1 |= RT5668_I2S1_DL_20; 19458c2ecf20Sopenharmony_ci len_2 |= RT5668_I2S2_DL_20; 19468c2ecf20Sopenharmony_ci break; 19478c2ecf20Sopenharmony_ci case 24: 19488c2ecf20Sopenharmony_ci len_1 |= RT5668_I2S1_DL_24; 19498c2ecf20Sopenharmony_ci len_2 |= RT5668_I2S2_DL_24; 19508c2ecf20Sopenharmony_ci break; 19518c2ecf20Sopenharmony_ci case 32: 19528c2ecf20Sopenharmony_ci len_1 |= RT5668_I2S1_DL_32; 19538c2ecf20Sopenharmony_ci len_2 |= RT5668_I2S2_DL_24; 19548c2ecf20Sopenharmony_ci break; 19558c2ecf20Sopenharmony_ci case 8: 19568c2ecf20Sopenharmony_ci len_1 |= RT5668_I2S2_DL_8; 19578c2ecf20Sopenharmony_ci len_2 |= RT5668_I2S2_DL_8; 19588c2ecf20Sopenharmony_ci break; 19598c2ecf20Sopenharmony_ci default: 19608c2ecf20Sopenharmony_ci return -EINVAL; 19618c2ecf20Sopenharmony_ci } 19628c2ecf20Sopenharmony_ci 19638c2ecf20Sopenharmony_ci switch (dai->id) { 19648c2ecf20Sopenharmony_ci case RT5668_AIF1: 19658c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5668_I2S1_SDP, 19668c2ecf20Sopenharmony_ci RT5668_I2S1_DL_MASK, len_1); 19678c2ecf20Sopenharmony_ci if (rt5668->master[RT5668_AIF1]) { 19688c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, 19698c2ecf20Sopenharmony_ci RT5668_ADDA_CLK_1, RT5668_I2S_M_DIV_MASK, 19708c2ecf20Sopenharmony_ci pre_div << RT5668_I2S_M_DIV_SFT); 19718c2ecf20Sopenharmony_ci } 19728c2ecf20Sopenharmony_ci if (params_channels(params) == 1) /* mono mode */ 19738c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, 19748c2ecf20Sopenharmony_ci RT5668_I2S1_SDP, RT5668_I2S1_MONO_MASK, 19758c2ecf20Sopenharmony_ci RT5668_I2S1_MONO_EN); 19768c2ecf20Sopenharmony_ci else 19778c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, 19788c2ecf20Sopenharmony_ci RT5668_I2S1_SDP, RT5668_I2S1_MONO_MASK, 19798c2ecf20Sopenharmony_ci RT5668_I2S1_MONO_DIS); 19808c2ecf20Sopenharmony_ci break; 19818c2ecf20Sopenharmony_ci case RT5668_AIF2: 19828c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5668_I2S2_SDP, 19838c2ecf20Sopenharmony_ci RT5668_I2S2_DL_MASK, len_2); 19848c2ecf20Sopenharmony_ci if (rt5668->master[RT5668_AIF2]) { 19858c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, 19868c2ecf20Sopenharmony_ci RT5668_I2S_M_CLK_CTRL_1, RT5668_I2S2_M_PD_MASK, 19878c2ecf20Sopenharmony_ci pre_div << RT5668_I2S2_M_PD_SFT); 19888c2ecf20Sopenharmony_ci } 19898c2ecf20Sopenharmony_ci if (params_channels(params) == 1) /* mono mode */ 19908c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, 19918c2ecf20Sopenharmony_ci RT5668_I2S2_SDP, RT5668_I2S2_MONO_MASK, 19928c2ecf20Sopenharmony_ci RT5668_I2S2_MONO_EN); 19938c2ecf20Sopenharmony_ci else 19948c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, 19958c2ecf20Sopenharmony_ci RT5668_I2S2_SDP, RT5668_I2S2_MONO_MASK, 19968c2ecf20Sopenharmony_ci RT5668_I2S2_MONO_DIS); 19978c2ecf20Sopenharmony_ci break; 19988c2ecf20Sopenharmony_ci default: 19998c2ecf20Sopenharmony_ci dev_err(component->dev, "Invalid dai->id: %d\n", dai->id); 20008c2ecf20Sopenharmony_ci return -EINVAL; 20018c2ecf20Sopenharmony_ci } 20028c2ecf20Sopenharmony_ci 20038c2ecf20Sopenharmony_ci return 0; 20048c2ecf20Sopenharmony_ci} 20058c2ecf20Sopenharmony_ci 20068c2ecf20Sopenharmony_cistatic int rt5668_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) 20078c2ecf20Sopenharmony_ci{ 20088c2ecf20Sopenharmony_ci struct snd_soc_component *component = dai->component; 20098c2ecf20Sopenharmony_ci struct rt5668_priv *rt5668 = snd_soc_component_get_drvdata(component); 20108c2ecf20Sopenharmony_ci unsigned int reg_val = 0, tdm_ctrl = 0; 20118c2ecf20Sopenharmony_ci 20128c2ecf20Sopenharmony_ci switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { 20138c2ecf20Sopenharmony_ci case SND_SOC_DAIFMT_CBM_CFM: 20148c2ecf20Sopenharmony_ci rt5668->master[dai->id] = 1; 20158c2ecf20Sopenharmony_ci break; 20168c2ecf20Sopenharmony_ci case SND_SOC_DAIFMT_CBS_CFS: 20178c2ecf20Sopenharmony_ci rt5668->master[dai->id] = 0; 20188c2ecf20Sopenharmony_ci break; 20198c2ecf20Sopenharmony_ci default: 20208c2ecf20Sopenharmony_ci return -EINVAL; 20218c2ecf20Sopenharmony_ci } 20228c2ecf20Sopenharmony_ci 20238c2ecf20Sopenharmony_ci switch (fmt & SND_SOC_DAIFMT_INV_MASK) { 20248c2ecf20Sopenharmony_ci case SND_SOC_DAIFMT_NB_NF: 20258c2ecf20Sopenharmony_ci break; 20268c2ecf20Sopenharmony_ci case SND_SOC_DAIFMT_IB_NF: 20278c2ecf20Sopenharmony_ci reg_val |= RT5668_I2S_BP_INV; 20288c2ecf20Sopenharmony_ci tdm_ctrl |= RT5668_TDM_S_BP_INV; 20298c2ecf20Sopenharmony_ci break; 20308c2ecf20Sopenharmony_ci case SND_SOC_DAIFMT_NB_IF: 20318c2ecf20Sopenharmony_ci if (dai->id == RT5668_AIF1) 20328c2ecf20Sopenharmony_ci tdm_ctrl |= RT5668_TDM_S_LP_INV | RT5668_TDM_M_BP_INV; 20338c2ecf20Sopenharmony_ci else 20348c2ecf20Sopenharmony_ci return -EINVAL; 20358c2ecf20Sopenharmony_ci break; 20368c2ecf20Sopenharmony_ci case SND_SOC_DAIFMT_IB_IF: 20378c2ecf20Sopenharmony_ci if (dai->id == RT5668_AIF1) 20388c2ecf20Sopenharmony_ci tdm_ctrl |= RT5668_TDM_S_BP_INV | RT5668_TDM_S_LP_INV | 20398c2ecf20Sopenharmony_ci RT5668_TDM_M_BP_INV | RT5668_TDM_M_LP_INV; 20408c2ecf20Sopenharmony_ci else 20418c2ecf20Sopenharmony_ci return -EINVAL; 20428c2ecf20Sopenharmony_ci break; 20438c2ecf20Sopenharmony_ci default: 20448c2ecf20Sopenharmony_ci return -EINVAL; 20458c2ecf20Sopenharmony_ci } 20468c2ecf20Sopenharmony_ci 20478c2ecf20Sopenharmony_ci switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { 20488c2ecf20Sopenharmony_ci case SND_SOC_DAIFMT_I2S: 20498c2ecf20Sopenharmony_ci break; 20508c2ecf20Sopenharmony_ci case SND_SOC_DAIFMT_LEFT_J: 20518c2ecf20Sopenharmony_ci reg_val |= RT5668_I2S_DF_LEFT; 20528c2ecf20Sopenharmony_ci tdm_ctrl |= RT5668_TDM_DF_LEFT; 20538c2ecf20Sopenharmony_ci break; 20548c2ecf20Sopenharmony_ci case SND_SOC_DAIFMT_DSP_A: 20558c2ecf20Sopenharmony_ci reg_val |= RT5668_I2S_DF_PCM_A; 20568c2ecf20Sopenharmony_ci tdm_ctrl |= RT5668_TDM_DF_PCM_A; 20578c2ecf20Sopenharmony_ci break; 20588c2ecf20Sopenharmony_ci case SND_SOC_DAIFMT_DSP_B: 20598c2ecf20Sopenharmony_ci reg_val |= RT5668_I2S_DF_PCM_B; 20608c2ecf20Sopenharmony_ci tdm_ctrl |= RT5668_TDM_DF_PCM_B; 20618c2ecf20Sopenharmony_ci break; 20628c2ecf20Sopenharmony_ci default: 20638c2ecf20Sopenharmony_ci return -EINVAL; 20648c2ecf20Sopenharmony_ci } 20658c2ecf20Sopenharmony_ci 20668c2ecf20Sopenharmony_ci switch (dai->id) { 20678c2ecf20Sopenharmony_ci case RT5668_AIF1: 20688c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5668_I2S1_SDP, 20698c2ecf20Sopenharmony_ci RT5668_I2S_DF_MASK, reg_val); 20708c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5668_TDM_TCON_CTRL, 20718c2ecf20Sopenharmony_ci RT5668_TDM_MS_MASK | RT5668_TDM_S_BP_MASK | 20728c2ecf20Sopenharmony_ci RT5668_TDM_DF_MASK | RT5668_TDM_M_BP_MASK | 20738c2ecf20Sopenharmony_ci RT5668_TDM_M_LP_MASK | RT5668_TDM_S_LP_MASK, 20748c2ecf20Sopenharmony_ci tdm_ctrl | rt5668->master[dai->id]); 20758c2ecf20Sopenharmony_ci break; 20768c2ecf20Sopenharmony_ci case RT5668_AIF2: 20778c2ecf20Sopenharmony_ci if (rt5668->master[dai->id] == 0) 20788c2ecf20Sopenharmony_ci reg_val |= RT5668_I2S2_MS_S; 20798c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5668_I2S2_SDP, 20808c2ecf20Sopenharmony_ci RT5668_I2S2_MS_MASK | RT5668_I2S_BP_MASK | 20818c2ecf20Sopenharmony_ci RT5668_I2S_DF_MASK, reg_val); 20828c2ecf20Sopenharmony_ci break; 20838c2ecf20Sopenharmony_ci default: 20848c2ecf20Sopenharmony_ci dev_err(component->dev, "Invalid dai->id: %d\n", dai->id); 20858c2ecf20Sopenharmony_ci return -EINVAL; 20868c2ecf20Sopenharmony_ci } 20878c2ecf20Sopenharmony_ci return 0; 20888c2ecf20Sopenharmony_ci} 20898c2ecf20Sopenharmony_ci 20908c2ecf20Sopenharmony_cistatic int rt5668_set_component_sysclk(struct snd_soc_component *component, 20918c2ecf20Sopenharmony_ci int clk_id, int source, unsigned int freq, int dir) 20928c2ecf20Sopenharmony_ci{ 20938c2ecf20Sopenharmony_ci struct rt5668_priv *rt5668 = snd_soc_component_get_drvdata(component); 20948c2ecf20Sopenharmony_ci unsigned int reg_val = 0, src = 0; 20958c2ecf20Sopenharmony_ci 20968c2ecf20Sopenharmony_ci if (freq == rt5668->sysclk && clk_id == rt5668->sysclk_src) 20978c2ecf20Sopenharmony_ci return 0; 20988c2ecf20Sopenharmony_ci 20998c2ecf20Sopenharmony_ci switch (clk_id) { 21008c2ecf20Sopenharmony_ci case RT5668_SCLK_S_MCLK: 21018c2ecf20Sopenharmony_ci reg_val |= RT5668_SCLK_SRC_MCLK; 21028c2ecf20Sopenharmony_ci src = RT5668_CLK_SRC_MCLK; 21038c2ecf20Sopenharmony_ci break; 21048c2ecf20Sopenharmony_ci case RT5668_SCLK_S_PLL1: 21058c2ecf20Sopenharmony_ci reg_val |= RT5668_SCLK_SRC_PLL1; 21068c2ecf20Sopenharmony_ci src = RT5668_CLK_SRC_PLL1; 21078c2ecf20Sopenharmony_ci break; 21088c2ecf20Sopenharmony_ci case RT5668_SCLK_S_PLL2: 21098c2ecf20Sopenharmony_ci reg_val |= RT5668_SCLK_SRC_PLL2; 21108c2ecf20Sopenharmony_ci src = RT5668_CLK_SRC_PLL2; 21118c2ecf20Sopenharmony_ci break; 21128c2ecf20Sopenharmony_ci case RT5668_SCLK_S_RCCLK: 21138c2ecf20Sopenharmony_ci reg_val |= RT5668_SCLK_SRC_RCCLK; 21148c2ecf20Sopenharmony_ci src = RT5668_CLK_SRC_RCCLK; 21158c2ecf20Sopenharmony_ci break; 21168c2ecf20Sopenharmony_ci default: 21178c2ecf20Sopenharmony_ci dev_err(component->dev, "Invalid clock id (%d)\n", clk_id); 21188c2ecf20Sopenharmony_ci return -EINVAL; 21198c2ecf20Sopenharmony_ci } 21208c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5668_GLB_CLK, 21218c2ecf20Sopenharmony_ci RT5668_SCLK_SRC_MASK, reg_val); 21228c2ecf20Sopenharmony_ci 21238c2ecf20Sopenharmony_ci if (rt5668->master[RT5668_AIF2]) { 21248c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, 21258c2ecf20Sopenharmony_ci RT5668_I2S_M_CLK_CTRL_1, RT5668_I2S2_SRC_MASK, 21268c2ecf20Sopenharmony_ci src << RT5668_I2S2_SRC_SFT); 21278c2ecf20Sopenharmony_ci } 21288c2ecf20Sopenharmony_ci 21298c2ecf20Sopenharmony_ci rt5668->sysclk = freq; 21308c2ecf20Sopenharmony_ci rt5668->sysclk_src = clk_id; 21318c2ecf20Sopenharmony_ci 21328c2ecf20Sopenharmony_ci dev_dbg(component->dev, "Sysclk is %dHz and clock id is %d\n", 21338c2ecf20Sopenharmony_ci freq, clk_id); 21348c2ecf20Sopenharmony_ci 21358c2ecf20Sopenharmony_ci return 0; 21368c2ecf20Sopenharmony_ci} 21378c2ecf20Sopenharmony_ci 21388c2ecf20Sopenharmony_cistatic int rt5668_set_component_pll(struct snd_soc_component *component, 21398c2ecf20Sopenharmony_ci int pll_id, int source, unsigned int freq_in, 21408c2ecf20Sopenharmony_ci unsigned int freq_out) 21418c2ecf20Sopenharmony_ci{ 21428c2ecf20Sopenharmony_ci struct rt5668_priv *rt5668 = snd_soc_component_get_drvdata(component); 21438c2ecf20Sopenharmony_ci struct rl6231_pll_code pll_code; 21448c2ecf20Sopenharmony_ci int ret; 21458c2ecf20Sopenharmony_ci 21468c2ecf20Sopenharmony_ci if (source == rt5668->pll_src && freq_in == rt5668->pll_in && 21478c2ecf20Sopenharmony_ci freq_out == rt5668->pll_out) 21488c2ecf20Sopenharmony_ci return 0; 21498c2ecf20Sopenharmony_ci 21508c2ecf20Sopenharmony_ci if (!freq_in || !freq_out) { 21518c2ecf20Sopenharmony_ci dev_dbg(component->dev, "PLL disabled\n"); 21528c2ecf20Sopenharmony_ci 21538c2ecf20Sopenharmony_ci rt5668->pll_in = 0; 21548c2ecf20Sopenharmony_ci rt5668->pll_out = 0; 21558c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5668_GLB_CLK, 21568c2ecf20Sopenharmony_ci RT5668_SCLK_SRC_MASK, RT5668_SCLK_SRC_MCLK); 21578c2ecf20Sopenharmony_ci return 0; 21588c2ecf20Sopenharmony_ci } 21598c2ecf20Sopenharmony_ci 21608c2ecf20Sopenharmony_ci switch (source) { 21618c2ecf20Sopenharmony_ci case RT5668_PLL1_S_MCLK: 21628c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5668_GLB_CLK, 21638c2ecf20Sopenharmony_ci RT5668_PLL1_SRC_MASK, RT5668_PLL1_SRC_MCLK); 21648c2ecf20Sopenharmony_ci break; 21658c2ecf20Sopenharmony_ci case RT5668_PLL1_S_BCLK1: 21668c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5668_GLB_CLK, 21678c2ecf20Sopenharmony_ci RT5668_PLL1_SRC_MASK, RT5668_PLL1_SRC_BCLK1); 21688c2ecf20Sopenharmony_ci break; 21698c2ecf20Sopenharmony_ci default: 21708c2ecf20Sopenharmony_ci dev_err(component->dev, "Unknown PLL Source %d\n", source); 21718c2ecf20Sopenharmony_ci return -EINVAL; 21728c2ecf20Sopenharmony_ci } 21738c2ecf20Sopenharmony_ci 21748c2ecf20Sopenharmony_ci ret = rl6231_pll_calc(freq_in, freq_out, &pll_code); 21758c2ecf20Sopenharmony_ci if (ret < 0) { 21768c2ecf20Sopenharmony_ci dev_err(component->dev, "Unsupport input clock %d\n", freq_in); 21778c2ecf20Sopenharmony_ci return ret; 21788c2ecf20Sopenharmony_ci } 21798c2ecf20Sopenharmony_ci 21808c2ecf20Sopenharmony_ci dev_dbg(component->dev, "bypass=%d m=%d n=%d k=%d\n", 21818c2ecf20Sopenharmony_ci pll_code.m_bp, (pll_code.m_bp ? 0 : pll_code.m_code), 21828c2ecf20Sopenharmony_ci pll_code.n_code, pll_code.k_code); 21838c2ecf20Sopenharmony_ci 21848c2ecf20Sopenharmony_ci snd_soc_component_write(component, RT5668_PLL_CTRL_1, 21858c2ecf20Sopenharmony_ci pll_code.n_code << RT5668_PLL_N_SFT | pll_code.k_code); 21868c2ecf20Sopenharmony_ci snd_soc_component_write(component, RT5668_PLL_CTRL_2, 21878c2ecf20Sopenharmony_ci (pll_code.m_bp ? 0 : pll_code.m_code) << RT5668_PLL_M_SFT | 21888c2ecf20Sopenharmony_ci pll_code.m_bp << RT5668_PLL_M_BP_SFT); 21898c2ecf20Sopenharmony_ci 21908c2ecf20Sopenharmony_ci rt5668->pll_in = freq_in; 21918c2ecf20Sopenharmony_ci rt5668->pll_out = freq_out; 21928c2ecf20Sopenharmony_ci rt5668->pll_src = source; 21938c2ecf20Sopenharmony_ci 21948c2ecf20Sopenharmony_ci return 0; 21958c2ecf20Sopenharmony_ci} 21968c2ecf20Sopenharmony_ci 21978c2ecf20Sopenharmony_cistatic int rt5668_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio) 21988c2ecf20Sopenharmony_ci{ 21998c2ecf20Sopenharmony_ci struct snd_soc_component *component = dai->component; 22008c2ecf20Sopenharmony_ci struct rt5668_priv *rt5668 = snd_soc_component_get_drvdata(component); 22018c2ecf20Sopenharmony_ci 22028c2ecf20Sopenharmony_ci rt5668->bclk[dai->id] = ratio; 22038c2ecf20Sopenharmony_ci 22048c2ecf20Sopenharmony_ci switch (ratio) { 22058c2ecf20Sopenharmony_ci case 64: 22068c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5668_ADDA_CLK_2, 22078c2ecf20Sopenharmony_ci RT5668_I2S2_BCLK_MS2_MASK, 22088c2ecf20Sopenharmony_ci RT5668_I2S2_BCLK_MS2_64); 22098c2ecf20Sopenharmony_ci break; 22108c2ecf20Sopenharmony_ci case 32: 22118c2ecf20Sopenharmony_ci snd_soc_component_update_bits(component, RT5668_ADDA_CLK_2, 22128c2ecf20Sopenharmony_ci RT5668_I2S2_BCLK_MS2_MASK, 22138c2ecf20Sopenharmony_ci RT5668_I2S2_BCLK_MS2_32); 22148c2ecf20Sopenharmony_ci break; 22158c2ecf20Sopenharmony_ci default: 22168c2ecf20Sopenharmony_ci dev_err(dai->dev, "Invalid bclk ratio %d\n", ratio); 22178c2ecf20Sopenharmony_ci return -EINVAL; 22188c2ecf20Sopenharmony_ci } 22198c2ecf20Sopenharmony_ci 22208c2ecf20Sopenharmony_ci return 0; 22218c2ecf20Sopenharmony_ci} 22228c2ecf20Sopenharmony_ci 22238c2ecf20Sopenharmony_cistatic int rt5668_set_bias_level(struct snd_soc_component *component, 22248c2ecf20Sopenharmony_ci enum snd_soc_bias_level level) 22258c2ecf20Sopenharmony_ci{ 22268c2ecf20Sopenharmony_ci struct rt5668_priv *rt5668 = snd_soc_component_get_drvdata(component); 22278c2ecf20Sopenharmony_ci 22288c2ecf20Sopenharmony_ci switch (level) { 22298c2ecf20Sopenharmony_ci case SND_SOC_BIAS_PREPARE: 22308c2ecf20Sopenharmony_ci regmap_update_bits(rt5668->regmap, RT5668_PWR_ANLG_1, 22318c2ecf20Sopenharmony_ci RT5668_PWR_MB | RT5668_PWR_BG, 22328c2ecf20Sopenharmony_ci RT5668_PWR_MB | RT5668_PWR_BG); 22338c2ecf20Sopenharmony_ci regmap_update_bits(rt5668->regmap, RT5668_PWR_DIG_1, 22348c2ecf20Sopenharmony_ci RT5668_DIG_GATE_CTRL | RT5668_PWR_LDO, 22358c2ecf20Sopenharmony_ci RT5668_DIG_GATE_CTRL | RT5668_PWR_LDO); 22368c2ecf20Sopenharmony_ci break; 22378c2ecf20Sopenharmony_ci 22388c2ecf20Sopenharmony_ci case SND_SOC_BIAS_STANDBY: 22398c2ecf20Sopenharmony_ci regmap_update_bits(rt5668->regmap, RT5668_PWR_ANLG_1, 22408c2ecf20Sopenharmony_ci RT5668_PWR_MB, RT5668_PWR_MB); 22418c2ecf20Sopenharmony_ci regmap_update_bits(rt5668->regmap, RT5668_PWR_DIG_1, 22428c2ecf20Sopenharmony_ci RT5668_DIG_GATE_CTRL, RT5668_DIG_GATE_CTRL); 22438c2ecf20Sopenharmony_ci break; 22448c2ecf20Sopenharmony_ci case SND_SOC_BIAS_OFF: 22458c2ecf20Sopenharmony_ci regmap_update_bits(rt5668->regmap, RT5668_PWR_DIG_1, 22468c2ecf20Sopenharmony_ci RT5668_DIG_GATE_CTRL | RT5668_PWR_LDO, 0); 22478c2ecf20Sopenharmony_ci regmap_update_bits(rt5668->regmap, RT5668_PWR_ANLG_1, 22488c2ecf20Sopenharmony_ci RT5668_PWR_MB | RT5668_PWR_BG, 0); 22498c2ecf20Sopenharmony_ci break; 22508c2ecf20Sopenharmony_ci 22518c2ecf20Sopenharmony_ci default: 22528c2ecf20Sopenharmony_ci break; 22538c2ecf20Sopenharmony_ci } 22548c2ecf20Sopenharmony_ci 22558c2ecf20Sopenharmony_ci return 0; 22568c2ecf20Sopenharmony_ci} 22578c2ecf20Sopenharmony_ci 22588c2ecf20Sopenharmony_cistatic int rt5668_probe(struct snd_soc_component *component) 22598c2ecf20Sopenharmony_ci{ 22608c2ecf20Sopenharmony_ci struct rt5668_priv *rt5668 = snd_soc_component_get_drvdata(component); 22618c2ecf20Sopenharmony_ci 22628c2ecf20Sopenharmony_ci rt5668->component = component; 22638c2ecf20Sopenharmony_ci 22648c2ecf20Sopenharmony_ci return 0; 22658c2ecf20Sopenharmony_ci} 22668c2ecf20Sopenharmony_ci 22678c2ecf20Sopenharmony_cistatic void rt5668_remove(struct snd_soc_component *component) 22688c2ecf20Sopenharmony_ci{ 22698c2ecf20Sopenharmony_ci struct rt5668_priv *rt5668 = snd_soc_component_get_drvdata(component); 22708c2ecf20Sopenharmony_ci 22718c2ecf20Sopenharmony_ci rt5668_reset(rt5668->regmap); 22728c2ecf20Sopenharmony_ci} 22738c2ecf20Sopenharmony_ci 22748c2ecf20Sopenharmony_ci#ifdef CONFIG_PM 22758c2ecf20Sopenharmony_cistatic int rt5668_suspend(struct snd_soc_component *component) 22768c2ecf20Sopenharmony_ci{ 22778c2ecf20Sopenharmony_ci struct rt5668_priv *rt5668 = snd_soc_component_get_drvdata(component); 22788c2ecf20Sopenharmony_ci 22798c2ecf20Sopenharmony_ci regcache_cache_only(rt5668->regmap, true); 22808c2ecf20Sopenharmony_ci regcache_mark_dirty(rt5668->regmap); 22818c2ecf20Sopenharmony_ci return 0; 22828c2ecf20Sopenharmony_ci} 22838c2ecf20Sopenharmony_ci 22848c2ecf20Sopenharmony_cistatic int rt5668_resume(struct snd_soc_component *component) 22858c2ecf20Sopenharmony_ci{ 22868c2ecf20Sopenharmony_ci struct rt5668_priv *rt5668 = snd_soc_component_get_drvdata(component); 22878c2ecf20Sopenharmony_ci 22888c2ecf20Sopenharmony_ci regcache_cache_only(rt5668->regmap, false); 22898c2ecf20Sopenharmony_ci regcache_sync(rt5668->regmap); 22908c2ecf20Sopenharmony_ci 22918c2ecf20Sopenharmony_ci return 0; 22928c2ecf20Sopenharmony_ci} 22938c2ecf20Sopenharmony_ci#else 22948c2ecf20Sopenharmony_ci#define rt5668_suspend NULL 22958c2ecf20Sopenharmony_ci#define rt5668_resume NULL 22968c2ecf20Sopenharmony_ci#endif 22978c2ecf20Sopenharmony_ci 22988c2ecf20Sopenharmony_ci#define RT5668_STEREO_RATES SNDRV_PCM_RATE_8000_192000 22998c2ecf20Sopenharmony_ci#define RT5668_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \ 23008c2ecf20Sopenharmony_ci SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S8) 23018c2ecf20Sopenharmony_ci 23028c2ecf20Sopenharmony_cistatic const struct snd_soc_dai_ops rt5668_aif1_dai_ops = { 23038c2ecf20Sopenharmony_ci .hw_params = rt5668_hw_params, 23048c2ecf20Sopenharmony_ci .set_fmt = rt5668_set_dai_fmt, 23058c2ecf20Sopenharmony_ci .set_tdm_slot = rt5668_set_tdm_slot, 23068c2ecf20Sopenharmony_ci}; 23078c2ecf20Sopenharmony_ci 23088c2ecf20Sopenharmony_cistatic const struct snd_soc_dai_ops rt5668_aif2_dai_ops = { 23098c2ecf20Sopenharmony_ci .hw_params = rt5668_hw_params, 23108c2ecf20Sopenharmony_ci .set_fmt = rt5668_set_dai_fmt, 23118c2ecf20Sopenharmony_ci .set_bclk_ratio = rt5668_set_bclk_ratio, 23128c2ecf20Sopenharmony_ci}; 23138c2ecf20Sopenharmony_ci 23148c2ecf20Sopenharmony_cistatic struct snd_soc_dai_driver rt5668_dai[] = { 23158c2ecf20Sopenharmony_ci { 23168c2ecf20Sopenharmony_ci .name = "rt5668-aif1", 23178c2ecf20Sopenharmony_ci .id = RT5668_AIF1, 23188c2ecf20Sopenharmony_ci .playback = { 23198c2ecf20Sopenharmony_ci .stream_name = "AIF1 Playback", 23208c2ecf20Sopenharmony_ci .channels_min = 1, 23218c2ecf20Sopenharmony_ci .channels_max = 2, 23228c2ecf20Sopenharmony_ci .rates = RT5668_STEREO_RATES, 23238c2ecf20Sopenharmony_ci .formats = RT5668_FORMATS, 23248c2ecf20Sopenharmony_ci }, 23258c2ecf20Sopenharmony_ci .capture = { 23268c2ecf20Sopenharmony_ci .stream_name = "AIF1 Capture", 23278c2ecf20Sopenharmony_ci .channels_min = 1, 23288c2ecf20Sopenharmony_ci .channels_max = 2, 23298c2ecf20Sopenharmony_ci .rates = RT5668_STEREO_RATES, 23308c2ecf20Sopenharmony_ci .formats = RT5668_FORMATS, 23318c2ecf20Sopenharmony_ci }, 23328c2ecf20Sopenharmony_ci .ops = &rt5668_aif1_dai_ops, 23338c2ecf20Sopenharmony_ci }, 23348c2ecf20Sopenharmony_ci { 23358c2ecf20Sopenharmony_ci .name = "rt5668-aif2", 23368c2ecf20Sopenharmony_ci .id = RT5668_AIF2, 23378c2ecf20Sopenharmony_ci .capture = { 23388c2ecf20Sopenharmony_ci .stream_name = "AIF2 Capture", 23398c2ecf20Sopenharmony_ci .channels_min = 1, 23408c2ecf20Sopenharmony_ci .channels_max = 2, 23418c2ecf20Sopenharmony_ci .rates = RT5668_STEREO_RATES, 23428c2ecf20Sopenharmony_ci .formats = RT5668_FORMATS, 23438c2ecf20Sopenharmony_ci }, 23448c2ecf20Sopenharmony_ci .ops = &rt5668_aif2_dai_ops, 23458c2ecf20Sopenharmony_ci }, 23468c2ecf20Sopenharmony_ci}; 23478c2ecf20Sopenharmony_ci 23488c2ecf20Sopenharmony_cistatic const struct snd_soc_component_driver soc_component_dev_rt5668 = { 23498c2ecf20Sopenharmony_ci .probe = rt5668_probe, 23508c2ecf20Sopenharmony_ci .remove = rt5668_remove, 23518c2ecf20Sopenharmony_ci .suspend = rt5668_suspend, 23528c2ecf20Sopenharmony_ci .resume = rt5668_resume, 23538c2ecf20Sopenharmony_ci .set_bias_level = rt5668_set_bias_level, 23548c2ecf20Sopenharmony_ci .controls = rt5668_snd_controls, 23558c2ecf20Sopenharmony_ci .num_controls = ARRAY_SIZE(rt5668_snd_controls), 23568c2ecf20Sopenharmony_ci .dapm_widgets = rt5668_dapm_widgets, 23578c2ecf20Sopenharmony_ci .num_dapm_widgets = ARRAY_SIZE(rt5668_dapm_widgets), 23588c2ecf20Sopenharmony_ci .dapm_routes = rt5668_dapm_routes, 23598c2ecf20Sopenharmony_ci .num_dapm_routes = ARRAY_SIZE(rt5668_dapm_routes), 23608c2ecf20Sopenharmony_ci .set_sysclk = rt5668_set_component_sysclk, 23618c2ecf20Sopenharmony_ci .set_pll = rt5668_set_component_pll, 23628c2ecf20Sopenharmony_ci .set_jack = rt5668_set_jack_detect, 23638c2ecf20Sopenharmony_ci .use_pmdown_time = 1, 23648c2ecf20Sopenharmony_ci .endianness = 1, 23658c2ecf20Sopenharmony_ci .non_legacy_dai_naming = 1, 23668c2ecf20Sopenharmony_ci}; 23678c2ecf20Sopenharmony_ci 23688c2ecf20Sopenharmony_cistatic const struct regmap_config rt5668_regmap = { 23698c2ecf20Sopenharmony_ci .reg_bits = 16, 23708c2ecf20Sopenharmony_ci .val_bits = 16, 23718c2ecf20Sopenharmony_ci .max_register = RT5668_I2C_MODE, 23728c2ecf20Sopenharmony_ci .volatile_reg = rt5668_volatile_register, 23738c2ecf20Sopenharmony_ci .readable_reg = rt5668_readable_register, 23748c2ecf20Sopenharmony_ci .cache_type = REGCACHE_RBTREE, 23758c2ecf20Sopenharmony_ci .reg_defaults = rt5668_reg, 23768c2ecf20Sopenharmony_ci .num_reg_defaults = ARRAY_SIZE(rt5668_reg), 23778c2ecf20Sopenharmony_ci .use_single_read = true, 23788c2ecf20Sopenharmony_ci .use_single_write = true, 23798c2ecf20Sopenharmony_ci}; 23808c2ecf20Sopenharmony_ci 23818c2ecf20Sopenharmony_cistatic const struct i2c_device_id rt5668_i2c_id[] = { 23828c2ecf20Sopenharmony_ci {"rt5668b", 0}, 23838c2ecf20Sopenharmony_ci {} 23848c2ecf20Sopenharmony_ci}; 23858c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(i2c, rt5668_i2c_id); 23868c2ecf20Sopenharmony_ci 23878c2ecf20Sopenharmony_cistatic int rt5668_parse_dt(struct rt5668_priv *rt5668, struct device *dev) 23888c2ecf20Sopenharmony_ci{ 23898c2ecf20Sopenharmony_ci 23908c2ecf20Sopenharmony_ci of_property_read_u32(dev->of_node, "realtek,dmic1-data-pin", 23918c2ecf20Sopenharmony_ci &rt5668->pdata.dmic1_data_pin); 23928c2ecf20Sopenharmony_ci of_property_read_u32(dev->of_node, "realtek,dmic1-clk-pin", 23938c2ecf20Sopenharmony_ci &rt5668->pdata.dmic1_clk_pin); 23948c2ecf20Sopenharmony_ci of_property_read_u32(dev->of_node, "realtek,jd-src", 23958c2ecf20Sopenharmony_ci &rt5668->pdata.jd_src); 23968c2ecf20Sopenharmony_ci 23978c2ecf20Sopenharmony_ci rt5668->pdata.ldo1_en = of_get_named_gpio(dev->of_node, 23988c2ecf20Sopenharmony_ci "realtek,ldo1-en-gpios", 0); 23998c2ecf20Sopenharmony_ci 24008c2ecf20Sopenharmony_ci return 0; 24018c2ecf20Sopenharmony_ci} 24028c2ecf20Sopenharmony_ci 24038c2ecf20Sopenharmony_cistatic void rt5668_calibrate(struct rt5668_priv *rt5668) 24048c2ecf20Sopenharmony_ci{ 24058c2ecf20Sopenharmony_ci int value, count; 24068c2ecf20Sopenharmony_ci 24078c2ecf20Sopenharmony_ci mutex_lock(&rt5668->calibrate_mutex); 24088c2ecf20Sopenharmony_ci 24098c2ecf20Sopenharmony_ci rt5668_reset(rt5668->regmap); 24108c2ecf20Sopenharmony_ci regmap_write(rt5668->regmap, RT5668_PWR_ANLG_1, 0xa2bf); 24118c2ecf20Sopenharmony_ci usleep_range(15000, 20000); 24128c2ecf20Sopenharmony_ci regmap_write(rt5668->regmap, RT5668_PWR_ANLG_1, 0xf2bf); 24138c2ecf20Sopenharmony_ci regmap_write(rt5668->regmap, RT5668_MICBIAS_2, 0x0380); 24148c2ecf20Sopenharmony_ci regmap_write(rt5668->regmap, RT5668_PWR_DIG_1, 0x8001); 24158c2ecf20Sopenharmony_ci regmap_write(rt5668->regmap, RT5668_TEST_MODE_CTRL_1, 0x0000); 24168c2ecf20Sopenharmony_ci regmap_write(rt5668->regmap, RT5668_STO1_DAC_MIXER, 0x2080); 24178c2ecf20Sopenharmony_ci regmap_write(rt5668->regmap, RT5668_STO1_ADC_MIXER, 0x4040); 24188c2ecf20Sopenharmony_ci regmap_write(rt5668->regmap, RT5668_DEPOP_1, 0x0069); 24198c2ecf20Sopenharmony_ci regmap_write(rt5668->regmap, RT5668_CHOP_DAC, 0x3000); 24208c2ecf20Sopenharmony_ci regmap_write(rt5668->regmap, RT5668_HP_CTRL_2, 0x6000); 24218c2ecf20Sopenharmony_ci regmap_write(rt5668->regmap, RT5668_HP_CHARGE_PUMP_1, 0x0f26); 24228c2ecf20Sopenharmony_ci regmap_write(rt5668->regmap, RT5668_CALIB_ADC_CTRL, 0x7f05); 24238c2ecf20Sopenharmony_ci regmap_write(rt5668->regmap, RT5668_STO1_ADC_MIXER, 0x686c); 24248c2ecf20Sopenharmony_ci regmap_write(rt5668->regmap, RT5668_CAL_REC, 0x0d0d); 24258c2ecf20Sopenharmony_ci regmap_write(rt5668->regmap, RT5668_HP_CALIB_CTRL_9, 0x000f); 24268c2ecf20Sopenharmony_ci regmap_write(rt5668->regmap, RT5668_PWR_DIG_1, 0x8d01); 24278c2ecf20Sopenharmony_ci regmap_write(rt5668->regmap, RT5668_HP_CALIB_CTRL_2, 0x0321); 24288c2ecf20Sopenharmony_ci regmap_write(rt5668->regmap, RT5668_HP_LOGIC_CTRL_2, 0x0004); 24298c2ecf20Sopenharmony_ci regmap_write(rt5668->regmap, RT5668_HP_CALIB_CTRL_1, 0x7c00); 24308c2ecf20Sopenharmony_ci regmap_write(rt5668->regmap, RT5668_HP_CALIB_CTRL_3, 0x06a1); 24318c2ecf20Sopenharmony_ci regmap_write(rt5668->regmap, RT5668_A_DAC1_MUX, 0x0311); 24328c2ecf20Sopenharmony_ci regmap_write(rt5668->regmap, RT5668_RESET_HPF_CTRL, 0x0000); 24338c2ecf20Sopenharmony_ci regmap_write(rt5668->regmap, RT5668_ADC_STO1_HP_CTRL_1, 0x3320); 24348c2ecf20Sopenharmony_ci 24358c2ecf20Sopenharmony_ci regmap_write(rt5668->regmap, RT5668_HP_CALIB_CTRL_1, 0xfc00); 24368c2ecf20Sopenharmony_ci 24378c2ecf20Sopenharmony_ci for (count = 0; count < 60; count++) { 24388c2ecf20Sopenharmony_ci regmap_read(rt5668->regmap, RT5668_HP_CALIB_STA_1, &value); 24398c2ecf20Sopenharmony_ci if (!(value & 0x8000)) 24408c2ecf20Sopenharmony_ci break; 24418c2ecf20Sopenharmony_ci 24428c2ecf20Sopenharmony_ci usleep_range(10000, 10005); 24438c2ecf20Sopenharmony_ci } 24448c2ecf20Sopenharmony_ci 24458c2ecf20Sopenharmony_ci if (count >= 60) 24468c2ecf20Sopenharmony_ci pr_err("HP Calibration Failure\n"); 24478c2ecf20Sopenharmony_ci 24488c2ecf20Sopenharmony_ci /* restore settings */ 24498c2ecf20Sopenharmony_ci regmap_write(rt5668->regmap, RT5668_STO1_ADC_MIXER, 0xc0c4); 24508c2ecf20Sopenharmony_ci regmap_write(rt5668->regmap, RT5668_PWR_DIG_1, 0x0000); 24518c2ecf20Sopenharmony_ci 24528c2ecf20Sopenharmony_ci mutex_unlock(&rt5668->calibrate_mutex); 24538c2ecf20Sopenharmony_ci 24548c2ecf20Sopenharmony_ci} 24558c2ecf20Sopenharmony_ci 24568c2ecf20Sopenharmony_cistatic int rt5668_i2c_probe(struct i2c_client *i2c, 24578c2ecf20Sopenharmony_ci const struct i2c_device_id *id) 24588c2ecf20Sopenharmony_ci{ 24598c2ecf20Sopenharmony_ci struct rt5668_platform_data *pdata = dev_get_platdata(&i2c->dev); 24608c2ecf20Sopenharmony_ci struct rt5668_priv *rt5668; 24618c2ecf20Sopenharmony_ci int i, ret; 24628c2ecf20Sopenharmony_ci unsigned int val; 24638c2ecf20Sopenharmony_ci 24648c2ecf20Sopenharmony_ci rt5668 = devm_kzalloc(&i2c->dev, sizeof(struct rt5668_priv), 24658c2ecf20Sopenharmony_ci GFP_KERNEL); 24668c2ecf20Sopenharmony_ci 24678c2ecf20Sopenharmony_ci if (rt5668 == NULL) 24688c2ecf20Sopenharmony_ci return -ENOMEM; 24698c2ecf20Sopenharmony_ci 24708c2ecf20Sopenharmony_ci i2c_set_clientdata(i2c, rt5668); 24718c2ecf20Sopenharmony_ci 24728c2ecf20Sopenharmony_ci if (pdata) 24738c2ecf20Sopenharmony_ci rt5668->pdata = *pdata; 24748c2ecf20Sopenharmony_ci else 24758c2ecf20Sopenharmony_ci rt5668_parse_dt(rt5668, &i2c->dev); 24768c2ecf20Sopenharmony_ci 24778c2ecf20Sopenharmony_ci rt5668->regmap = devm_regmap_init_i2c(i2c, &rt5668_regmap); 24788c2ecf20Sopenharmony_ci if (IS_ERR(rt5668->regmap)) { 24798c2ecf20Sopenharmony_ci ret = PTR_ERR(rt5668->regmap); 24808c2ecf20Sopenharmony_ci dev_err(&i2c->dev, "Failed to allocate register map: %d\n", 24818c2ecf20Sopenharmony_ci ret); 24828c2ecf20Sopenharmony_ci return ret; 24838c2ecf20Sopenharmony_ci } 24848c2ecf20Sopenharmony_ci 24858c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(rt5668->supplies); i++) 24868c2ecf20Sopenharmony_ci rt5668->supplies[i].supply = rt5668_supply_names[i]; 24878c2ecf20Sopenharmony_ci 24888c2ecf20Sopenharmony_ci ret = devm_regulator_bulk_get(&i2c->dev, ARRAY_SIZE(rt5668->supplies), 24898c2ecf20Sopenharmony_ci rt5668->supplies); 24908c2ecf20Sopenharmony_ci if (ret != 0) { 24918c2ecf20Sopenharmony_ci dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret); 24928c2ecf20Sopenharmony_ci return ret; 24938c2ecf20Sopenharmony_ci } 24948c2ecf20Sopenharmony_ci 24958c2ecf20Sopenharmony_ci ret = regulator_bulk_enable(ARRAY_SIZE(rt5668->supplies), 24968c2ecf20Sopenharmony_ci rt5668->supplies); 24978c2ecf20Sopenharmony_ci if (ret != 0) { 24988c2ecf20Sopenharmony_ci dev_err(&i2c->dev, "Failed to enable supplies: %d\n", ret); 24998c2ecf20Sopenharmony_ci return ret; 25008c2ecf20Sopenharmony_ci } 25018c2ecf20Sopenharmony_ci 25028c2ecf20Sopenharmony_ci if (gpio_is_valid(rt5668->pdata.ldo1_en)) { 25038c2ecf20Sopenharmony_ci if (devm_gpio_request_one(&i2c->dev, rt5668->pdata.ldo1_en, 25048c2ecf20Sopenharmony_ci GPIOF_OUT_INIT_HIGH, "rt5668")) 25058c2ecf20Sopenharmony_ci dev_err(&i2c->dev, "Fail gpio_request gpio_ldo\n"); 25068c2ecf20Sopenharmony_ci } 25078c2ecf20Sopenharmony_ci 25088c2ecf20Sopenharmony_ci /* Sleep for 300 ms miniumum */ 25098c2ecf20Sopenharmony_ci usleep_range(300000, 350000); 25108c2ecf20Sopenharmony_ci 25118c2ecf20Sopenharmony_ci regmap_write(rt5668->regmap, RT5668_I2C_MODE, 0x1); 25128c2ecf20Sopenharmony_ci usleep_range(10000, 15000); 25138c2ecf20Sopenharmony_ci 25148c2ecf20Sopenharmony_ci regmap_read(rt5668->regmap, RT5668_DEVICE_ID, &val); 25158c2ecf20Sopenharmony_ci if (val != DEVICE_ID) { 25168c2ecf20Sopenharmony_ci pr_err("Device with ID register %x is not rt5668\n", val); 25178c2ecf20Sopenharmony_ci return -ENODEV; 25188c2ecf20Sopenharmony_ci } 25198c2ecf20Sopenharmony_ci 25208c2ecf20Sopenharmony_ci rt5668_reset(rt5668->regmap); 25218c2ecf20Sopenharmony_ci 25228c2ecf20Sopenharmony_ci rt5668_calibrate(rt5668); 25238c2ecf20Sopenharmony_ci 25248c2ecf20Sopenharmony_ci regmap_write(rt5668->regmap, RT5668_DEPOP_1, 0x0000); 25258c2ecf20Sopenharmony_ci 25268c2ecf20Sopenharmony_ci /* DMIC pin*/ 25278c2ecf20Sopenharmony_ci if (rt5668->pdata.dmic1_data_pin != RT5668_DMIC1_NULL) { 25288c2ecf20Sopenharmony_ci switch (rt5668->pdata.dmic1_data_pin) { 25298c2ecf20Sopenharmony_ci case RT5668_DMIC1_DATA_GPIO2: /* share with LRCK2 */ 25308c2ecf20Sopenharmony_ci regmap_update_bits(rt5668->regmap, RT5668_DMIC_CTRL_1, 25318c2ecf20Sopenharmony_ci RT5668_DMIC_1_DP_MASK, RT5668_DMIC_1_DP_GPIO2); 25328c2ecf20Sopenharmony_ci regmap_update_bits(rt5668->regmap, RT5668_GPIO_CTRL_1, 25338c2ecf20Sopenharmony_ci RT5668_GP2_PIN_MASK, RT5668_GP2_PIN_DMIC_SDA); 25348c2ecf20Sopenharmony_ci break; 25358c2ecf20Sopenharmony_ci 25368c2ecf20Sopenharmony_ci case RT5668_DMIC1_DATA_GPIO5: /* share with DACDAT1 */ 25378c2ecf20Sopenharmony_ci regmap_update_bits(rt5668->regmap, RT5668_DMIC_CTRL_1, 25388c2ecf20Sopenharmony_ci RT5668_DMIC_1_DP_MASK, RT5668_DMIC_1_DP_GPIO5); 25398c2ecf20Sopenharmony_ci regmap_update_bits(rt5668->regmap, RT5668_GPIO_CTRL_1, 25408c2ecf20Sopenharmony_ci RT5668_GP5_PIN_MASK, RT5668_GP5_PIN_DMIC_SDA); 25418c2ecf20Sopenharmony_ci break; 25428c2ecf20Sopenharmony_ci 25438c2ecf20Sopenharmony_ci default: 25448c2ecf20Sopenharmony_ci dev_dbg(&i2c->dev, "invalid DMIC_DAT pin\n"); 25458c2ecf20Sopenharmony_ci break; 25468c2ecf20Sopenharmony_ci } 25478c2ecf20Sopenharmony_ci 25488c2ecf20Sopenharmony_ci switch (rt5668->pdata.dmic1_clk_pin) { 25498c2ecf20Sopenharmony_ci case RT5668_DMIC1_CLK_GPIO1: /* share with IRQ */ 25508c2ecf20Sopenharmony_ci regmap_update_bits(rt5668->regmap, RT5668_GPIO_CTRL_1, 25518c2ecf20Sopenharmony_ci RT5668_GP1_PIN_MASK, RT5668_GP1_PIN_DMIC_CLK); 25528c2ecf20Sopenharmony_ci break; 25538c2ecf20Sopenharmony_ci 25548c2ecf20Sopenharmony_ci case RT5668_DMIC1_CLK_GPIO3: /* share with BCLK2 */ 25558c2ecf20Sopenharmony_ci regmap_update_bits(rt5668->regmap, RT5668_GPIO_CTRL_1, 25568c2ecf20Sopenharmony_ci RT5668_GP3_PIN_MASK, RT5668_GP3_PIN_DMIC_CLK); 25578c2ecf20Sopenharmony_ci break; 25588c2ecf20Sopenharmony_ci 25598c2ecf20Sopenharmony_ci default: 25608c2ecf20Sopenharmony_ci dev_dbg(&i2c->dev, "invalid DMIC_CLK pin\n"); 25618c2ecf20Sopenharmony_ci break; 25628c2ecf20Sopenharmony_ci } 25638c2ecf20Sopenharmony_ci } 25648c2ecf20Sopenharmony_ci 25658c2ecf20Sopenharmony_ci regmap_update_bits(rt5668->regmap, RT5668_PWR_ANLG_1, 25668c2ecf20Sopenharmony_ci RT5668_LDO1_DVO_MASK | RT5668_HP_DRIVER_MASK, 25678c2ecf20Sopenharmony_ci RT5668_LDO1_DVO_14 | RT5668_HP_DRIVER_5X); 25688c2ecf20Sopenharmony_ci regmap_write(rt5668->regmap, RT5668_MICBIAS_2, 0x0380); 25698c2ecf20Sopenharmony_ci regmap_update_bits(rt5668->regmap, RT5668_GPIO_CTRL_1, 25708c2ecf20Sopenharmony_ci RT5668_GP4_PIN_MASK | RT5668_GP5_PIN_MASK, 25718c2ecf20Sopenharmony_ci RT5668_GP4_PIN_ADCDAT1 | RT5668_GP5_PIN_DACDAT1); 25728c2ecf20Sopenharmony_ci regmap_write(rt5668->regmap, RT5668_TEST_MODE_CTRL_1, 0x0000); 25738c2ecf20Sopenharmony_ci 25748c2ecf20Sopenharmony_ci INIT_DELAYED_WORK(&rt5668->jack_detect_work, 25758c2ecf20Sopenharmony_ci rt5668_jack_detect_handler); 25768c2ecf20Sopenharmony_ci INIT_DELAYED_WORK(&rt5668->jd_check_work, 25778c2ecf20Sopenharmony_ci rt5668_jd_check_handler); 25788c2ecf20Sopenharmony_ci 25798c2ecf20Sopenharmony_ci mutex_init(&rt5668->calibrate_mutex); 25808c2ecf20Sopenharmony_ci 25818c2ecf20Sopenharmony_ci if (i2c->irq) { 25828c2ecf20Sopenharmony_ci ret = devm_request_threaded_irq(&i2c->dev, i2c->irq, NULL, 25838c2ecf20Sopenharmony_ci rt5668_irq, IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING 25848c2ecf20Sopenharmony_ci | IRQF_ONESHOT, "rt5668", rt5668); 25858c2ecf20Sopenharmony_ci if (ret) 25868c2ecf20Sopenharmony_ci dev_err(&i2c->dev, "Failed to reguest IRQ: %d\n", ret); 25878c2ecf20Sopenharmony_ci 25888c2ecf20Sopenharmony_ci } 25898c2ecf20Sopenharmony_ci 25908c2ecf20Sopenharmony_ci return devm_snd_soc_register_component(&i2c->dev, &soc_component_dev_rt5668, 25918c2ecf20Sopenharmony_ci rt5668_dai, ARRAY_SIZE(rt5668_dai)); 25928c2ecf20Sopenharmony_ci} 25938c2ecf20Sopenharmony_ci 25948c2ecf20Sopenharmony_cistatic void rt5668_i2c_shutdown(struct i2c_client *client) 25958c2ecf20Sopenharmony_ci{ 25968c2ecf20Sopenharmony_ci struct rt5668_priv *rt5668 = i2c_get_clientdata(client); 25978c2ecf20Sopenharmony_ci 25988c2ecf20Sopenharmony_ci rt5668_reset(rt5668->regmap); 25998c2ecf20Sopenharmony_ci} 26008c2ecf20Sopenharmony_ci 26018c2ecf20Sopenharmony_ci#ifdef CONFIG_OF 26028c2ecf20Sopenharmony_cistatic const struct of_device_id rt5668_of_match[] = { 26038c2ecf20Sopenharmony_ci {.compatible = "realtek,rt5668b"}, 26048c2ecf20Sopenharmony_ci {}, 26058c2ecf20Sopenharmony_ci}; 26068c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, rt5668_of_match); 26078c2ecf20Sopenharmony_ci#endif 26088c2ecf20Sopenharmony_ci 26098c2ecf20Sopenharmony_ci#ifdef CONFIG_ACPI 26108c2ecf20Sopenharmony_cistatic const struct acpi_device_id rt5668_acpi_match[] = { 26118c2ecf20Sopenharmony_ci {"10EC5668", 0,}, 26128c2ecf20Sopenharmony_ci {}, 26138c2ecf20Sopenharmony_ci}; 26148c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(acpi, rt5668_acpi_match); 26158c2ecf20Sopenharmony_ci#endif 26168c2ecf20Sopenharmony_ci 26178c2ecf20Sopenharmony_cistatic struct i2c_driver rt5668_i2c_driver = { 26188c2ecf20Sopenharmony_ci .driver = { 26198c2ecf20Sopenharmony_ci .name = "rt5668b", 26208c2ecf20Sopenharmony_ci .of_match_table = of_match_ptr(rt5668_of_match), 26218c2ecf20Sopenharmony_ci .acpi_match_table = ACPI_PTR(rt5668_acpi_match), 26228c2ecf20Sopenharmony_ci }, 26238c2ecf20Sopenharmony_ci .probe = rt5668_i2c_probe, 26248c2ecf20Sopenharmony_ci .shutdown = rt5668_i2c_shutdown, 26258c2ecf20Sopenharmony_ci .id_table = rt5668_i2c_id, 26268c2ecf20Sopenharmony_ci}; 26278c2ecf20Sopenharmony_cimodule_i2c_driver(rt5668_i2c_driver); 26288c2ecf20Sopenharmony_ci 26298c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("ASoC RT5668B driver"); 26308c2ecf20Sopenharmony_ciMODULE_AUTHOR("Bard Liao <bardliao@realtek.com>"); 26318c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2"); 2632