18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * wm8983.c  --  WM8983 ALSA SoC Audio driver
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright 2011 Wolfson Microelectronics plc
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Author: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#include <linux/module.h>
118c2ecf20Sopenharmony_ci#include <linux/moduleparam.h>
128c2ecf20Sopenharmony_ci#include <linux/init.h>
138c2ecf20Sopenharmony_ci#include <linux/delay.h>
148c2ecf20Sopenharmony_ci#include <linux/pm.h>
158c2ecf20Sopenharmony_ci#include <linux/i2c.h>
168c2ecf20Sopenharmony_ci#include <linux/regmap.h>
178c2ecf20Sopenharmony_ci#include <linux/spi/spi.h>
188c2ecf20Sopenharmony_ci#include <linux/slab.h>
198c2ecf20Sopenharmony_ci#include <sound/core.h>
208c2ecf20Sopenharmony_ci#include <sound/pcm.h>
218c2ecf20Sopenharmony_ci#include <sound/pcm_params.h>
228c2ecf20Sopenharmony_ci#include <sound/soc.h>
238c2ecf20Sopenharmony_ci#include <sound/initval.h>
248c2ecf20Sopenharmony_ci#include <sound/tlv.h>
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#include "wm8983.h"
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_cistatic const struct reg_default wm8983_defaults[] = {
298c2ecf20Sopenharmony_ci	{ 0x01, 0x0000 },     /* R1  - Power management 1 */
308c2ecf20Sopenharmony_ci	{ 0x02, 0x0000 },     /* R2  - Power management 2 */
318c2ecf20Sopenharmony_ci	{ 0x03, 0x0000 },     /* R3  - Power management 3 */
328c2ecf20Sopenharmony_ci	{ 0x04, 0x0050 },     /* R4  - Audio Interface */
338c2ecf20Sopenharmony_ci	{ 0x05, 0x0000 },     /* R5  - Companding control */
348c2ecf20Sopenharmony_ci	{ 0x06, 0x0140 },     /* R6  - Clock Gen control */
358c2ecf20Sopenharmony_ci	{ 0x07, 0x0000 },     /* R7  - Additional control */
368c2ecf20Sopenharmony_ci	{ 0x08, 0x0000 },     /* R8  - GPIO Control */
378c2ecf20Sopenharmony_ci	{ 0x09, 0x0000 },     /* R9  - Jack Detect Control 1 */
388c2ecf20Sopenharmony_ci	{ 0x0A, 0x0000 },     /* R10 - DAC Control */
398c2ecf20Sopenharmony_ci	{ 0x0B, 0x00FF },     /* R11 - Left DAC digital Vol */
408c2ecf20Sopenharmony_ci	{ 0x0C, 0x00FF },     /* R12 - Right DAC digital vol */
418c2ecf20Sopenharmony_ci	{ 0x0D, 0x0000 },     /* R13 - Jack Detect Control 2 */
428c2ecf20Sopenharmony_ci	{ 0x0E, 0x0100 },     /* R14 - ADC Control */
438c2ecf20Sopenharmony_ci	{ 0x0F, 0x00FF },     /* R15 - Left ADC Digital Vol */
448c2ecf20Sopenharmony_ci	{ 0x10, 0x00FF },     /* R16 - Right ADC Digital Vol */
458c2ecf20Sopenharmony_ci	{ 0x12, 0x012C },     /* R18 - EQ1 - low shelf */
468c2ecf20Sopenharmony_ci	{ 0x13, 0x002C },     /* R19 - EQ2 - peak 1 */
478c2ecf20Sopenharmony_ci	{ 0x14, 0x002C },     /* R20 - EQ3 - peak 2 */
488c2ecf20Sopenharmony_ci	{ 0x15, 0x002C },     /* R21 - EQ4 - peak 3 */
498c2ecf20Sopenharmony_ci	{ 0x16, 0x002C },     /* R22 - EQ5 - high shelf */
508c2ecf20Sopenharmony_ci	{ 0x18, 0x0032 },     /* R24 - DAC Limiter 1 */
518c2ecf20Sopenharmony_ci	{ 0x19, 0x0000 },     /* R25 - DAC Limiter 2 */
528c2ecf20Sopenharmony_ci	{ 0x1B, 0x0000 },     /* R27 - Notch Filter 1 */
538c2ecf20Sopenharmony_ci	{ 0x1C, 0x0000 },     /* R28 - Notch Filter 2 */
548c2ecf20Sopenharmony_ci	{ 0x1D, 0x0000 },     /* R29 - Notch Filter 3 */
558c2ecf20Sopenharmony_ci	{ 0x1E, 0x0000 },     /* R30 - Notch Filter 4 */
568c2ecf20Sopenharmony_ci	{ 0x20, 0x0038 },     /* R32 - ALC control 1 */
578c2ecf20Sopenharmony_ci	{ 0x21, 0x000B },     /* R33 - ALC control 2 */
588c2ecf20Sopenharmony_ci	{ 0x22, 0x0032 },     /* R34 - ALC control 3 */
598c2ecf20Sopenharmony_ci	{ 0x23, 0x0000 },     /* R35 - Noise Gate */
608c2ecf20Sopenharmony_ci	{ 0x24, 0x0008 },     /* R36 - PLL N */
618c2ecf20Sopenharmony_ci	{ 0x25, 0x000C },     /* R37 - PLL K 1 */
628c2ecf20Sopenharmony_ci	{ 0x26, 0x0093 },     /* R38 - PLL K 2 */
638c2ecf20Sopenharmony_ci	{ 0x27, 0x00E9 },     /* R39 - PLL K 3 */
648c2ecf20Sopenharmony_ci	{ 0x29, 0x0000 },     /* R41 - 3D control */
658c2ecf20Sopenharmony_ci	{ 0x2A, 0x0000 },     /* R42 - OUT4 to ADC */
668c2ecf20Sopenharmony_ci	{ 0x2B, 0x0000 },     /* R43 - Beep control */
678c2ecf20Sopenharmony_ci	{ 0x2C, 0x0033 },     /* R44 - Input ctrl */
688c2ecf20Sopenharmony_ci	{ 0x2D, 0x0010 },     /* R45 - Left INP PGA gain ctrl */
698c2ecf20Sopenharmony_ci	{ 0x2E, 0x0010 },     /* R46 - Right INP PGA gain ctrl */
708c2ecf20Sopenharmony_ci	{ 0x2F, 0x0100 },     /* R47 - Left ADC BOOST ctrl */
718c2ecf20Sopenharmony_ci	{ 0x30, 0x0100 },     /* R48 - Right ADC BOOST ctrl */
728c2ecf20Sopenharmony_ci	{ 0x31, 0x0002 },     /* R49 - Output ctrl */
738c2ecf20Sopenharmony_ci	{ 0x32, 0x0001 },     /* R50 - Left mixer ctrl */
748c2ecf20Sopenharmony_ci	{ 0x33, 0x0001 },     /* R51 - Right mixer ctrl */
758c2ecf20Sopenharmony_ci	{ 0x34, 0x0039 },     /* R52 - LOUT1 (HP) volume ctrl */
768c2ecf20Sopenharmony_ci	{ 0x35, 0x0039 },     /* R53 - ROUT1 (HP) volume ctrl */
778c2ecf20Sopenharmony_ci	{ 0x36, 0x0039 },     /* R54 - LOUT2 (SPK) volume ctrl */
788c2ecf20Sopenharmony_ci	{ 0x37, 0x0039 },     /* R55 - ROUT2 (SPK) volume ctrl */
798c2ecf20Sopenharmony_ci	{ 0x38, 0x0001 },     /* R56 - OUT3 mixer ctrl */
808c2ecf20Sopenharmony_ci	{ 0x39, 0x0001 },     /* R57 - OUT4 (MONO) mix ctrl */
818c2ecf20Sopenharmony_ci	{ 0x3D, 0x0000 },      /* R61 - BIAS CTRL */
828c2ecf20Sopenharmony_ci};
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci/* vol/gain update regs */
858c2ecf20Sopenharmony_cistatic const int vol_update_regs[] = {
868c2ecf20Sopenharmony_ci	WM8983_LEFT_DAC_DIGITAL_VOL,
878c2ecf20Sopenharmony_ci	WM8983_RIGHT_DAC_DIGITAL_VOL,
888c2ecf20Sopenharmony_ci	WM8983_LEFT_ADC_DIGITAL_VOL,
898c2ecf20Sopenharmony_ci	WM8983_RIGHT_ADC_DIGITAL_VOL,
908c2ecf20Sopenharmony_ci	WM8983_LOUT1_HP_VOLUME_CTRL,
918c2ecf20Sopenharmony_ci	WM8983_ROUT1_HP_VOLUME_CTRL,
928c2ecf20Sopenharmony_ci	WM8983_LOUT2_SPK_VOLUME_CTRL,
938c2ecf20Sopenharmony_ci	WM8983_ROUT2_SPK_VOLUME_CTRL,
948c2ecf20Sopenharmony_ci	WM8983_LEFT_INP_PGA_GAIN_CTRL,
958c2ecf20Sopenharmony_ci	WM8983_RIGHT_INP_PGA_GAIN_CTRL
968c2ecf20Sopenharmony_ci};
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_cistruct wm8983_priv {
998c2ecf20Sopenharmony_ci	struct regmap *regmap;
1008c2ecf20Sopenharmony_ci	u32 sysclk;
1018c2ecf20Sopenharmony_ci	u32 bclk;
1028c2ecf20Sopenharmony_ci};
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_cistatic const struct {
1058c2ecf20Sopenharmony_ci	int div;
1068c2ecf20Sopenharmony_ci	int ratio;
1078c2ecf20Sopenharmony_ci} fs_ratios[] = {
1088c2ecf20Sopenharmony_ci	{ 10, 128 },
1098c2ecf20Sopenharmony_ci	{ 15, 192 },
1108c2ecf20Sopenharmony_ci	{ 20, 256 },
1118c2ecf20Sopenharmony_ci	{ 30, 384 },
1128c2ecf20Sopenharmony_ci	{ 40, 512 },
1138c2ecf20Sopenharmony_ci	{ 60, 768 },
1148c2ecf20Sopenharmony_ci	{ 80, 1024 },
1158c2ecf20Sopenharmony_ci	{ 120, 1536 }
1168c2ecf20Sopenharmony_ci};
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_cistatic const int srates[] = { 48000, 32000, 24000, 16000, 12000, 8000 };
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_cistatic const int bclk_divs[] = {
1218c2ecf20Sopenharmony_ci	1, 2, 4, 8, 16, 32
1228c2ecf20Sopenharmony_ci};
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_cistatic int eqmode_get(struct snd_kcontrol *kcontrol,
1258c2ecf20Sopenharmony_ci		      struct snd_ctl_elem_value *ucontrol);
1268c2ecf20Sopenharmony_cistatic int eqmode_put(struct snd_kcontrol *kcontrol,
1278c2ecf20Sopenharmony_ci		      struct snd_ctl_elem_value *ucontrol);
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_cistatic const DECLARE_TLV_DB_SCALE(dac_tlv, -12700, 50, 1);
1308c2ecf20Sopenharmony_cistatic const DECLARE_TLV_DB_SCALE(adc_tlv, -12700, 50, 1);
1318c2ecf20Sopenharmony_cistatic const DECLARE_TLV_DB_SCALE(out_tlv, -5700, 100, 0);
1328c2ecf20Sopenharmony_cistatic const DECLARE_TLV_DB_SCALE(lim_thresh_tlv, -600, 100, 0);
1338c2ecf20Sopenharmony_cistatic const DECLARE_TLV_DB_SCALE(lim_boost_tlv, 0, 100, 0);
1348c2ecf20Sopenharmony_cistatic const DECLARE_TLV_DB_SCALE(alc_min_tlv, -1200, 600, 0);
1358c2ecf20Sopenharmony_cistatic const DECLARE_TLV_DB_SCALE(alc_max_tlv, -675, 600, 0);
1368c2ecf20Sopenharmony_cistatic const DECLARE_TLV_DB_SCALE(alc_tar_tlv, -2250, 150, 0);
1378c2ecf20Sopenharmony_cistatic const DECLARE_TLV_DB_SCALE(pga_vol_tlv, -1200, 75, 0);
1388c2ecf20Sopenharmony_cistatic const DECLARE_TLV_DB_SCALE(boost_tlv, -1200, 300, 1);
1398c2ecf20Sopenharmony_cistatic const DECLARE_TLV_DB_SCALE(eq_tlv, -1200, 100, 0);
1408c2ecf20Sopenharmony_cistatic const DECLARE_TLV_DB_SCALE(aux_tlv, -1500, 300, 0);
1418c2ecf20Sopenharmony_cistatic const DECLARE_TLV_DB_SCALE(bypass_tlv, -1500, 300, 0);
1428c2ecf20Sopenharmony_cistatic const DECLARE_TLV_DB_SCALE(pga_boost_tlv, 0, 2000, 0);
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_cistatic const char *alc_sel_text[] = { "Off", "Right", "Left", "Stereo" };
1458c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL(alc_sel, WM8983_ALC_CONTROL_1, 7, alc_sel_text);
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_cistatic const char *alc_mode_text[] = { "ALC", "Limiter" };
1488c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL(alc_mode, WM8983_ALC_CONTROL_3, 8, alc_mode_text);
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_cistatic const char *filter_mode_text[] = { "Audio", "Application" };
1518c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL(filter_mode, WM8983_ADC_CONTROL, 7,
1528c2ecf20Sopenharmony_ci			    filter_mode_text);
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_cistatic const char *eq_bw_text[] = { "Narrow", "Wide" };
1558c2ecf20Sopenharmony_cistatic const char *eqmode_text[] = { "Capture", "Playback" };
1568c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_EXT_DECL(eqmode, eqmode_text);
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_cistatic const char *eq1_cutoff_text[] = {
1598c2ecf20Sopenharmony_ci	"80Hz", "105Hz", "135Hz", "175Hz"
1608c2ecf20Sopenharmony_ci};
1618c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL(eq1_cutoff, WM8983_EQ1_LOW_SHELF, 5,
1628c2ecf20Sopenharmony_ci			    eq1_cutoff_text);
1638c2ecf20Sopenharmony_cistatic const char *eq2_cutoff_text[] = {
1648c2ecf20Sopenharmony_ci	"230Hz", "300Hz", "385Hz", "500Hz"
1658c2ecf20Sopenharmony_ci};
1668c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL(eq2_bw, WM8983_EQ2_PEAK_1, 8, eq_bw_text);
1678c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL(eq2_cutoff, WM8983_EQ2_PEAK_1, 5, eq2_cutoff_text);
1688c2ecf20Sopenharmony_cistatic const char *eq3_cutoff_text[] = {
1698c2ecf20Sopenharmony_ci	"650Hz", "850Hz", "1.1kHz", "1.4kHz"
1708c2ecf20Sopenharmony_ci};
1718c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL(eq3_bw, WM8983_EQ3_PEAK_2, 8, eq_bw_text);
1728c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL(eq3_cutoff, WM8983_EQ3_PEAK_2, 5, eq3_cutoff_text);
1738c2ecf20Sopenharmony_cistatic const char *eq4_cutoff_text[] = {
1748c2ecf20Sopenharmony_ci	"1.8kHz", "2.4kHz", "3.2kHz", "4.1kHz"
1758c2ecf20Sopenharmony_ci};
1768c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL(eq4_bw, WM8983_EQ4_PEAK_3, 8, eq_bw_text);
1778c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL(eq4_cutoff, WM8983_EQ4_PEAK_3, 5, eq4_cutoff_text);
1788c2ecf20Sopenharmony_cistatic const char *eq5_cutoff_text[] = {
1798c2ecf20Sopenharmony_ci	"5.3kHz", "6.9kHz", "9kHz", "11.7kHz"
1808c2ecf20Sopenharmony_ci};
1818c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL(eq5_cutoff, WM8983_EQ5_HIGH_SHELF, 5,
1828c2ecf20Sopenharmony_ci			    eq5_cutoff_text);
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_cistatic const char *depth_3d_text[] = {
1858c2ecf20Sopenharmony_ci	"Off",
1868c2ecf20Sopenharmony_ci	"6.67%",
1878c2ecf20Sopenharmony_ci	"13.3%",
1888c2ecf20Sopenharmony_ci	"20%",
1898c2ecf20Sopenharmony_ci	"26.7%",
1908c2ecf20Sopenharmony_ci	"33.3%",
1918c2ecf20Sopenharmony_ci	"40%",
1928c2ecf20Sopenharmony_ci	"46.6%",
1938c2ecf20Sopenharmony_ci	"53.3%",
1948c2ecf20Sopenharmony_ci	"60%",
1958c2ecf20Sopenharmony_ci	"66.7%",
1968c2ecf20Sopenharmony_ci	"73.3%",
1978c2ecf20Sopenharmony_ci	"80%",
1988c2ecf20Sopenharmony_ci	"86.7%",
1998c2ecf20Sopenharmony_ci	"93.3%",
2008c2ecf20Sopenharmony_ci	"100%"
2018c2ecf20Sopenharmony_ci};
2028c2ecf20Sopenharmony_cistatic SOC_ENUM_SINGLE_DECL(depth_3d, WM8983_3D_CONTROL, 0,
2038c2ecf20Sopenharmony_ci			    depth_3d_text);
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new wm8983_snd_controls[] = {
2068c2ecf20Sopenharmony_ci	SOC_SINGLE("Digital Loopback Switch", WM8983_COMPANDING_CONTROL,
2078c2ecf20Sopenharmony_ci		   0, 1, 0),
2088c2ecf20Sopenharmony_ci
2098c2ecf20Sopenharmony_ci	SOC_ENUM("ALC Capture Function", alc_sel),
2108c2ecf20Sopenharmony_ci	SOC_SINGLE_TLV("ALC Capture Max Volume", WM8983_ALC_CONTROL_1,
2118c2ecf20Sopenharmony_ci		       3, 7, 0, alc_max_tlv),
2128c2ecf20Sopenharmony_ci	SOC_SINGLE_TLV("ALC Capture Min Volume", WM8983_ALC_CONTROL_1,
2138c2ecf20Sopenharmony_ci		       0, 7, 0, alc_min_tlv),
2148c2ecf20Sopenharmony_ci	SOC_SINGLE_TLV("ALC Capture Target Volume", WM8983_ALC_CONTROL_2,
2158c2ecf20Sopenharmony_ci		       0, 15, 0, alc_tar_tlv),
2168c2ecf20Sopenharmony_ci	SOC_SINGLE("ALC Capture Attack", WM8983_ALC_CONTROL_3, 0, 10, 0),
2178c2ecf20Sopenharmony_ci	SOC_SINGLE("ALC Capture Hold", WM8983_ALC_CONTROL_2, 4, 10, 0),
2188c2ecf20Sopenharmony_ci	SOC_SINGLE("ALC Capture Decay", WM8983_ALC_CONTROL_3, 4, 10, 0),
2198c2ecf20Sopenharmony_ci	SOC_ENUM("ALC Mode", alc_mode),
2208c2ecf20Sopenharmony_ci	SOC_SINGLE("ALC Capture NG Switch", WM8983_NOISE_GATE,
2218c2ecf20Sopenharmony_ci		   3, 1, 0),
2228c2ecf20Sopenharmony_ci	SOC_SINGLE("ALC Capture NG Threshold", WM8983_NOISE_GATE,
2238c2ecf20Sopenharmony_ci		   0, 7, 1),
2248c2ecf20Sopenharmony_ci
2258c2ecf20Sopenharmony_ci	SOC_DOUBLE_R_TLV("Capture Volume", WM8983_LEFT_ADC_DIGITAL_VOL,
2268c2ecf20Sopenharmony_ci			 WM8983_RIGHT_ADC_DIGITAL_VOL, 0, 255, 0, adc_tlv),
2278c2ecf20Sopenharmony_ci	SOC_DOUBLE_R("Capture PGA ZC Switch", WM8983_LEFT_INP_PGA_GAIN_CTRL,
2288c2ecf20Sopenharmony_ci		     WM8983_RIGHT_INP_PGA_GAIN_CTRL, 7, 1, 0),
2298c2ecf20Sopenharmony_ci	SOC_DOUBLE_R_TLV("Capture PGA Volume", WM8983_LEFT_INP_PGA_GAIN_CTRL,
2308c2ecf20Sopenharmony_ci			 WM8983_RIGHT_INP_PGA_GAIN_CTRL, 0, 63, 0, pga_vol_tlv),
2318c2ecf20Sopenharmony_ci
2328c2ecf20Sopenharmony_ci	SOC_DOUBLE_R_TLV("Capture PGA Boost Volume",
2338c2ecf20Sopenharmony_ci			 WM8983_LEFT_ADC_BOOST_CTRL, WM8983_RIGHT_ADC_BOOST_CTRL,
2348c2ecf20Sopenharmony_ci			 8, 1, 0, pga_boost_tlv),
2358c2ecf20Sopenharmony_ci
2368c2ecf20Sopenharmony_ci	SOC_DOUBLE("ADC Inversion Switch", WM8983_ADC_CONTROL, 0, 1, 1, 0),
2378c2ecf20Sopenharmony_ci	SOC_SINGLE("ADC 128x Oversampling Switch", WM8983_ADC_CONTROL, 8, 1, 0),
2388c2ecf20Sopenharmony_ci
2398c2ecf20Sopenharmony_ci	SOC_DOUBLE_R_TLV("Playback Volume", WM8983_LEFT_DAC_DIGITAL_VOL,
2408c2ecf20Sopenharmony_ci			 WM8983_RIGHT_DAC_DIGITAL_VOL, 0, 255, 0, dac_tlv),
2418c2ecf20Sopenharmony_ci
2428c2ecf20Sopenharmony_ci	SOC_SINGLE("DAC Playback Limiter Switch", WM8983_DAC_LIMITER_1, 8, 1, 0),
2438c2ecf20Sopenharmony_ci	SOC_SINGLE("DAC Playback Limiter Decay", WM8983_DAC_LIMITER_1, 4, 10, 0),
2448c2ecf20Sopenharmony_ci	SOC_SINGLE("DAC Playback Limiter Attack", WM8983_DAC_LIMITER_1, 0, 11, 0),
2458c2ecf20Sopenharmony_ci	SOC_SINGLE_TLV("DAC Playback Limiter Threshold", WM8983_DAC_LIMITER_2,
2468c2ecf20Sopenharmony_ci		       4, 7, 1, lim_thresh_tlv),
2478c2ecf20Sopenharmony_ci	SOC_SINGLE_TLV("DAC Playback Limiter Boost Volume", WM8983_DAC_LIMITER_2,
2488c2ecf20Sopenharmony_ci		       0, 12, 0, lim_boost_tlv),
2498c2ecf20Sopenharmony_ci	SOC_DOUBLE("DAC Inversion Switch", WM8983_DAC_CONTROL, 0, 1, 1, 0),
2508c2ecf20Sopenharmony_ci	SOC_SINGLE("DAC Auto Mute Switch", WM8983_DAC_CONTROL, 2, 1, 0),
2518c2ecf20Sopenharmony_ci	SOC_SINGLE("DAC 128x Oversampling Switch", WM8983_DAC_CONTROL, 3, 1, 0),
2528c2ecf20Sopenharmony_ci
2538c2ecf20Sopenharmony_ci	SOC_DOUBLE_R_TLV("Headphone Playback Volume", WM8983_LOUT1_HP_VOLUME_CTRL,
2548c2ecf20Sopenharmony_ci			 WM8983_ROUT1_HP_VOLUME_CTRL, 0, 63, 0, out_tlv),
2558c2ecf20Sopenharmony_ci	SOC_DOUBLE_R("Headphone Playback ZC Switch", WM8983_LOUT1_HP_VOLUME_CTRL,
2568c2ecf20Sopenharmony_ci		     WM8983_ROUT1_HP_VOLUME_CTRL, 7, 1, 0),
2578c2ecf20Sopenharmony_ci	SOC_DOUBLE_R("Headphone Switch", WM8983_LOUT1_HP_VOLUME_CTRL,
2588c2ecf20Sopenharmony_ci		     WM8983_ROUT1_HP_VOLUME_CTRL, 6, 1, 1),
2598c2ecf20Sopenharmony_ci
2608c2ecf20Sopenharmony_ci	SOC_DOUBLE_R_TLV("Speaker Playback Volume", WM8983_LOUT2_SPK_VOLUME_CTRL,
2618c2ecf20Sopenharmony_ci			 WM8983_ROUT2_SPK_VOLUME_CTRL, 0, 63, 0, out_tlv),
2628c2ecf20Sopenharmony_ci	SOC_DOUBLE_R("Speaker Playback ZC Switch", WM8983_LOUT2_SPK_VOLUME_CTRL,
2638c2ecf20Sopenharmony_ci		     WM8983_ROUT2_SPK_VOLUME_CTRL, 7, 1, 0),
2648c2ecf20Sopenharmony_ci	SOC_DOUBLE_R("Speaker Switch", WM8983_LOUT2_SPK_VOLUME_CTRL,
2658c2ecf20Sopenharmony_ci		     WM8983_ROUT2_SPK_VOLUME_CTRL, 6, 1, 1),
2668c2ecf20Sopenharmony_ci
2678c2ecf20Sopenharmony_ci	SOC_SINGLE("OUT3 Switch", WM8983_OUT3_MIXER_CTRL,
2688c2ecf20Sopenharmony_ci		   6, 1, 1),
2698c2ecf20Sopenharmony_ci
2708c2ecf20Sopenharmony_ci	SOC_SINGLE("OUT4 Switch", WM8983_OUT4_MONO_MIX_CTRL,
2718c2ecf20Sopenharmony_ci		   6, 1, 1),
2728c2ecf20Sopenharmony_ci
2738c2ecf20Sopenharmony_ci	SOC_SINGLE("High Pass Filter Switch", WM8983_ADC_CONTROL, 8, 1, 0),
2748c2ecf20Sopenharmony_ci	SOC_ENUM("High Pass Filter Mode", filter_mode),
2758c2ecf20Sopenharmony_ci	SOC_SINGLE("High Pass Filter Cutoff", WM8983_ADC_CONTROL, 4, 7, 0),
2768c2ecf20Sopenharmony_ci
2778c2ecf20Sopenharmony_ci	SOC_DOUBLE_R_TLV("Aux Bypass Volume",
2788c2ecf20Sopenharmony_ci			 WM8983_LEFT_MIXER_CTRL, WM8983_RIGHT_MIXER_CTRL, 6, 7, 0,
2798c2ecf20Sopenharmony_ci			 aux_tlv),
2808c2ecf20Sopenharmony_ci
2818c2ecf20Sopenharmony_ci	SOC_DOUBLE_R_TLV("Input PGA Bypass Volume",
2828c2ecf20Sopenharmony_ci			 WM8983_LEFT_MIXER_CTRL, WM8983_RIGHT_MIXER_CTRL, 2, 7, 0,
2838c2ecf20Sopenharmony_ci			 bypass_tlv),
2848c2ecf20Sopenharmony_ci
2858c2ecf20Sopenharmony_ci	SOC_ENUM_EXT("Equalizer Function", eqmode, eqmode_get, eqmode_put),
2868c2ecf20Sopenharmony_ci	SOC_ENUM("EQ1 Cutoff", eq1_cutoff),
2878c2ecf20Sopenharmony_ci	SOC_SINGLE_TLV("EQ1 Volume", WM8983_EQ1_LOW_SHELF,  0, 24, 1, eq_tlv),
2888c2ecf20Sopenharmony_ci	SOC_ENUM("EQ2 Bandwidth", eq2_bw),
2898c2ecf20Sopenharmony_ci	SOC_ENUM("EQ2 Cutoff", eq2_cutoff),
2908c2ecf20Sopenharmony_ci	SOC_SINGLE_TLV("EQ2 Volume", WM8983_EQ2_PEAK_1, 0, 24, 1, eq_tlv),
2918c2ecf20Sopenharmony_ci	SOC_ENUM("EQ3 Bandwidth", eq3_bw),
2928c2ecf20Sopenharmony_ci	SOC_ENUM("EQ3 Cutoff", eq3_cutoff),
2938c2ecf20Sopenharmony_ci	SOC_SINGLE_TLV("EQ3 Volume", WM8983_EQ3_PEAK_2, 0, 24, 1, eq_tlv),
2948c2ecf20Sopenharmony_ci	SOC_ENUM("EQ4 Bandwidth", eq4_bw),
2958c2ecf20Sopenharmony_ci	SOC_ENUM("EQ4 Cutoff", eq4_cutoff),
2968c2ecf20Sopenharmony_ci	SOC_SINGLE_TLV("EQ4 Volume", WM8983_EQ4_PEAK_3, 0, 24, 1, eq_tlv),
2978c2ecf20Sopenharmony_ci	SOC_ENUM("EQ5 Cutoff", eq5_cutoff),
2988c2ecf20Sopenharmony_ci	SOC_SINGLE_TLV("EQ5 Volume", WM8983_EQ5_HIGH_SHELF, 0, 24, 1, eq_tlv),
2998c2ecf20Sopenharmony_ci
3008c2ecf20Sopenharmony_ci	SOC_ENUM("3D Depth", depth_3d),
3018c2ecf20Sopenharmony_ci};
3028c2ecf20Sopenharmony_ci
3038c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new left_out_mixer[] = {
3048c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("Line Switch", WM8983_LEFT_MIXER_CTRL, 1, 1, 0),
3058c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("Aux Switch", WM8983_LEFT_MIXER_CTRL, 5, 1, 0),
3068c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("PCM Switch", WM8983_LEFT_MIXER_CTRL, 0, 1, 0),
3078c2ecf20Sopenharmony_ci};
3088c2ecf20Sopenharmony_ci
3098c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new right_out_mixer[] = {
3108c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("Line Switch", WM8983_RIGHT_MIXER_CTRL, 1, 1, 0),
3118c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("Aux Switch", WM8983_RIGHT_MIXER_CTRL, 5, 1, 0),
3128c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("PCM Switch", WM8983_RIGHT_MIXER_CTRL, 0, 1, 0),
3138c2ecf20Sopenharmony_ci};
3148c2ecf20Sopenharmony_ci
3158c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new left_input_mixer[] = {
3168c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("L2 Switch", WM8983_INPUT_CTRL, 2, 1, 0),
3178c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("MicN Switch", WM8983_INPUT_CTRL, 1, 1, 0),
3188c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("MicP Switch", WM8983_INPUT_CTRL, 0, 1, 0),
3198c2ecf20Sopenharmony_ci};
3208c2ecf20Sopenharmony_ci
3218c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new right_input_mixer[] = {
3228c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("R2 Switch", WM8983_INPUT_CTRL, 6, 1, 0),
3238c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("MicN Switch", WM8983_INPUT_CTRL, 5, 1, 0),
3248c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("MicP Switch", WM8983_INPUT_CTRL, 4, 1, 0),
3258c2ecf20Sopenharmony_ci};
3268c2ecf20Sopenharmony_ci
3278c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new left_boost_mixer[] = {
3288c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE_TLV("L2 Volume", WM8983_LEFT_ADC_BOOST_CTRL,
3298c2ecf20Sopenharmony_ci			    4, 7, 0, boost_tlv),
3308c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE_TLV("AUXL Volume", WM8983_LEFT_ADC_BOOST_CTRL,
3318c2ecf20Sopenharmony_ci			    0, 7, 0, boost_tlv)
3328c2ecf20Sopenharmony_ci};
3338c2ecf20Sopenharmony_ci
3348c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new out3_mixer[] = {
3358c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("LMIX2OUT3 Switch", WM8983_OUT3_MIXER_CTRL,
3368c2ecf20Sopenharmony_ci			1, 1, 0),
3378c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("LDAC2OUT3 Switch", WM8983_OUT3_MIXER_CTRL,
3388c2ecf20Sopenharmony_ci			0, 1, 0),
3398c2ecf20Sopenharmony_ci};
3408c2ecf20Sopenharmony_ci
3418c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new out4_mixer[] = {
3428c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("LMIX2OUT4 Switch", WM8983_OUT4_MONO_MIX_CTRL,
3438c2ecf20Sopenharmony_ci			4, 1, 0),
3448c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("RMIX2OUT4 Switch", WM8983_OUT4_MONO_MIX_CTRL,
3458c2ecf20Sopenharmony_ci			1, 1, 0),
3468c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("LDAC2OUT4 Switch", WM8983_OUT4_MONO_MIX_CTRL,
3478c2ecf20Sopenharmony_ci			3, 1, 0),
3488c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("RDAC2OUT4 Switch", WM8983_OUT4_MONO_MIX_CTRL,
3498c2ecf20Sopenharmony_ci			0, 1, 0),
3508c2ecf20Sopenharmony_ci};
3518c2ecf20Sopenharmony_ci
3528c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new right_boost_mixer[] = {
3538c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE_TLV("R2 Volume", WM8983_RIGHT_ADC_BOOST_CTRL,
3548c2ecf20Sopenharmony_ci			    4, 7, 0, boost_tlv),
3558c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE_TLV("AUXR Volume", WM8983_RIGHT_ADC_BOOST_CTRL,
3568c2ecf20Sopenharmony_ci			    0, 7, 0, boost_tlv)
3578c2ecf20Sopenharmony_ci};
3588c2ecf20Sopenharmony_ci
3598c2ecf20Sopenharmony_cistatic const struct snd_soc_dapm_widget wm8983_dapm_widgets[] = {
3608c2ecf20Sopenharmony_ci	SND_SOC_DAPM_DAC("Left DAC", "Left Playback", WM8983_POWER_MANAGEMENT_3,
3618c2ecf20Sopenharmony_ci			 0, 0),
3628c2ecf20Sopenharmony_ci	SND_SOC_DAPM_DAC("Right DAC", "Right Playback", WM8983_POWER_MANAGEMENT_3,
3638c2ecf20Sopenharmony_ci			 1, 0),
3648c2ecf20Sopenharmony_ci	SND_SOC_DAPM_ADC("Left ADC", "Left Capture", WM8983_POWER_MANAGEMENT_2,
3658c2ecf20Sopenharmony_ci			 0, 0),
3668c2ecf20Sopenharmony_ci	SND_SOC_DAPM_ADC("Right ADC", "Right Capture", WM8983_POWER_MANAGEMENT_2,
3678c2ecf20Sopenharmony_ci			 1, 0),
3688c2ecf20Sopenharmony_ci
3698c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MIXER("Left Output Mixer", WM8983_POWER_MANAGEMENT_3,
3708c2ecf20Sopenharmony_ci			   2, 0, left_out_mixer, ARRAY_SIZE(left_out_mixer)),
3718c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MIXER("Right Output Mixer", WM8983_POWER_MANAGEMENT_3,
3728c2ecf20Sopenharmony_ci			   3, 0, right_out_mixer, ARRAY_SIZE(right_out_mixer)),
3738c2ecf20Sopenharmony_ci
3748c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MIXER("Left Input Mixer", WM8983_POWER_MANAGEMENT_2,
3758c2ecf20Sopenharmony_ci			   2, 0, left_input_mixer, ARRAY_SIZE(left_input_mixer)),
3768c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MIXER("Right Input Mixer", WM8983_POWER_MANAGEMENT_2,
3778c2ecf20Sopenharmony_ci			   3, 0, right_input_mixer, ARRAY_SIZE(right_input_mixer)),
3788c2ecf20Sopenharmony_ci
3798c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MIXER("Left Boost Mixer", WM8983_POWER_MANAGEMENT_2,
3808c2ecf20Sopenharmony_ci			   4, 0, left_boost_mixer, ARRAY_SIZE(left_boost_mixer)),
3818c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MIXER("Right Boost Mixer", WM8983_POWER_MANAGEMENT_2,
3828c2ecf20Sopenharmony_ci			   5, 0, right_boost_mixer, ARRAY_SIZE(right_boost_mixer)),
3838c2ecf20Sopenharmony_ci
3848c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MIXER("OUT3 Mixer", WM8983_POWER_MANAGEMENT_1,
3858c2ecf20Sopenharmony_ci			   6, 0, out3_mixer, ARRAY_SIZE(out3_mixer)),
3868c2ecf20Sopenharmony_ci
3878c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MIXER("OUT4 Mixer", WM8983_POWER_MANAGEMENT_1,
3888c2ecf20Sopenharmony_ci			   7, 0, out4_mixer, ARRAY_SIZE(out4_mixer)),
3898c2ecf20Sopenharmony_ci
3908c2ecf20Sopenharmony_ci	SND_SOC_DAPM_PGA("Left Capture PGA", WM8983_LEFT_INP_PGA_GAIN_CTRL,
3918c2ecf20Sopenharmony_ci			 6, 1, NULL, 0),
3928c2ecf20Sopenharmony_ci	SND_SOC_DAPM_PGA("Right Capture PGA", WM8983_RIGHT_INP_PGA_GAIN_CTRL,
3938c2ecf20Sopenharmony_ci			 6, 1, NULL, 0),
3948c2ecf20Sopenharmony_ci
3958c2ecf20Sopenharmony_ci	SND_SOC_DAPM_PGA("Left Headphone Out", WM8983_POWER_MANAGEMENT_2,
3968c2ecf20Sopenharmony_ci			 7, 0, NULL, 0),
3978c2ecf20Sopenharmony_ci	SND_SOC_DAPM_PGA("Right Headphone Out", WM8983_POWER_MANAGEMENT_2,
3988c2ecf20Sopenharmony_ci			 8, 0, NULL, 0),
3998c2ecf20Sopenharmony_ci
4008c2ecf20Sopenharmony_ci	SND_SOC_DAPM_PGA("Left Speaker Out", WM8983_POWER_MANAGEMENT_3,
4018c2ecf20Sopenharmony_ci			 5, 0, NULL, 0),
4028c2ecf20Sopenharmony_ci	SND_SOC_DAPM_PGA("Right Speaker Out", WM8983_POWER_MANAGEMENT_3,
4038c2ecf20Sopenharmony_ci			 6, 0, NULL, 0),
4048c2ecf20Sopenharmony_ci
4058c2ecf20Sopenharmony_ci	SND_SOC_DAPM_PGA("OUT3 Out", WM8983_POWER_MANAGEMENT_3,
4068c2ecf20Sopenharmony_ci			 7, 0, NULL, 0),
4078c2ecf20Sopenharmony_ci
4088c2ecf20Sopenharmony_ci	SND_SOC_DAPM_PGA("OUT4 Out", WM8983_POWER_MANAGEMENT_3,
4098c2ecf20Sopenharmony_ci			 8, 0, NULL, 0),
4108c2ecf20Sopenharmony_ci
4118c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("Mic Bias", WM8983_POWER_MANAGEMENT_1, 4, 0,
4128c2ecf20Sopenharmony_ci			    NULL, 0),
4138c2ecf20Sopenharmony_ci
4148c2ecf20Sopenharmony_ci	SND_SOC_DAPM_INPUT("LIN"),
4158c2ecf20Sopenharmony_ci	SND_SOC_DAPM_INPUT("LIP"),
4168c2ecf20Sopenharmony_ci	SND_SOC_DAPM_INPUT("RIN"),
4178c2ecf20Sopenharmony_ci	SND_SOC_DAPM_INPUT("RIP"),
4188c2ecf20Sopenharmony_ci	SND_SOC_DAPM_INPUT("AUXL"),
4198c2ecf20Sopenharmony_ci	SND_SOC_DAPM_INPUT("AUXR"),
4208c2ecf20Sopenharmony_ci	SND_SOC_DAPM_INPUT("L2"),
4218c2ecf20Sopenharmony_ci	SND_SOC_DAPM_INPUT("R2"),
4228c2ecf20Sopenharmony_ci	SND_SOC_DAPM_OUTPUT("HPL"),
4238c2ecf20Sopenharmony_ci	SND_SOC_DAPM_OUTPUT("HPR"),
4248c2ecf20Sopenharmony_ci	SND_SOC_DAPM_OUTPUT("SPKL"),
4258c2ecf20Sopenharmony_ci	SND_SOC_DAPM_OUTPUT("SPKR"),
4268c2ecf20Sopenharmony_ci	SND_SOC_DAPM_OUTPUT("OUT3"),
4278c2ecf20Sopenharmony_ci	SND_SOC_DAPM_OUTPUT("OUT4")
4288c2ecf20Sopenharmony_ci};
4298c2ecf20Sopenharmony_ci
4308c2ecf20Sopenharmony_cistatic const struct snd_soc_dapm_route wm8983_audio_map[] = {
4318c2ecf20Sopenharmony_ci	{ "OUT3 Mixer", "LMIX2OUT3 Switch", "Left Output Mixer" },
4328c2ecf20Sopenharmony_ci	{ "OUT3 Mixer", "LDAC2OUT3 Switch", "Left DAC" },
4338c2ecf20Sopenharmony_ci
4348c2ecf20Sopenharmony_ci	{ "OUT3 Out", NULL, "OUT3 Mixer" },
4358c2ecf20Sopenharmony_ci	{ "OUT3", NULL, "OUT3 Out" },
4368c2ecf20Sopenharmony_ci
4378c2ecf20Sopenharmony_ci	{ "OUT4 Mixer", "LMIX2OUT4 Switch", "Left Output Mixer" },
4388c2ecf20Sopenharmony_ci	{ "OUT4 Mixer", "RMIX2OUT4 Switch", "Right Output Mixer" },
4398c2ecf20Sopenharmony_ci	{ "OUT4 Mixer", "LDAC2OUT4 Switch", "Left DAC" },
4408c2ecf20Sopenharmony_ci	{ "OUT4 Mixer", "RDAC2OUT4 Switch", "Right DAC" },
4418c2ecf20Sopenharmony_ci
4428c2ecf20Sopenharmony_ci	{ "OUT4 Out", NULL, "OUT4 Mixer" },
4438c2ecf20Sopenharmony_ci	{ "OUT4", NULL, "OUT4 Out" },
4448c2ecf20Sopenharmony_ci
4458c2ecf20Sopenharmony_ci	{ "Right Output Mixer", "PCM Switch", "Right DAC" },
4468c2ecf20Sopenharmony_ci	{ "Right Output Mixer", "Aux Switch", "AUXR" },
4478c2ecf20Sopenharmony_ci	{ "Right Output Mixer", "Line Switch", "Right Boost Mixer" },
4488c2ecf20Sopenharmony_ci
4498c2ecf20Sopenharmony_ci	{ "Left Output Mixer", "PCM Switch", "Left DAC" },
4508c2ecf20Sopenharmony_ci	{ "Left Output Mixer", "Aux Switch", "AUXL" },
4518c2ecf20Sopenharmony_ci	{ "Left Output Mixer", "Line Switch", "Left Boost Mixer" },
4528c2ecf20Sopenharmony_ci
4538c2ecf20Sopenharmony_ci	{ "Right Headphone Out", NULL, "Right Output Mixer" },
4548c2ecf20Sopenharmony_ci	{ "HPR", NULL, "Right Headphone Out" },
4558c2ecf20Sopenharmony_ci
4568c2ecf20Sopenharmony_ci	{ "Left Headphone Out", NULL, "Left Output Mixer" },
4578c2ecf20Sopenharmony_ci	{ "HPL", NULL, "Left Headphone Out" },
4588c2ecf20Sopenharmony_ci
4598c2ecf20Sopenharmony_ci	{ "Right Speaker Out", NULL, "Right Output Mixer" },
4608c2ecf20Sopenharmony_ci	{ "SPKR", NULL, "Right Speaker Out" },
4618c2ecf20Sopenharmony_ci
4628c2ecf20Sopenharmony_ci	{ "Left Speaker Out", NULL, "Left Output Mixer" },
4638c2ecf20Sopenharmony_ci	{ "SPKL", NULL, "Left Speaker Out" },
4648c2ecf20Sopenharmony_ci
4658c2ecf20Sopenharmony_ci	{ "Right ADC", NULL, "Right Boost Mixer" },
4668c2ecf20Sopenharmony_ci
4678c2ecf20Sopenharmony_ci	{ "Right Boost Mixer", "AUXR Volume", "AUXR" },
4688c2ecf20Sopenharmony_ci	{ "Right Boost Mixer", NULL, "Right Capture PGA" },
4698c2ecf20Sopenharmony_ci	{ "Right Boost Mixer", "R2 Volume", "R2" },
4708c2ecf20Sopenharmony_ci
4718c2ecf20Sopenharmony_ci	{ "Left ADC", NULL, "Left Boost Mixer" },
4728c2ecf20Sopenharmony_ci
4738c2ecf20Sopenharmony_ci	{ "Left Boost Mixer", "AUXL Volume", "AUXL" },
4748c2ecf20Sopenharmony_ci	{ "Left Boost Mixer", NULL, "Left Capture PGA" },
4758c2ecf20Sopenharmony_ci	{ "Left Boost Mixer", "L2 Volume", "L2" },
4768c2ecf20Sopenharmony_ci
4778c2ecf20Sopenharmony_ci	{ "Right Capture PGA", NULL, "Right Input Mixer" },
4788c2ecf20Sopenharmony_ci	{ "Left Capture PGA", NULL, "Left Input Mixer" },
4798c2ecf20Sopenharmony_ci
4808c2ecf20Sopenharmony_ci	{ "Right Input Mixer", "R2 Switch", "R2" },
4818c2ecf20Sopenharmony_ci	{ "Right Input Mixer", "MicN Switch", "RIN" },
4828c2ecf20Sopenharmony_ci	{ "Right Input Mixer", "MicP Switch", "RIP" },
4838c2ecf20Sopenharmony_ci
4848c2ecf20Sopenharmony_ci	{ "Left Input Mixer", "L2 Switch", "L2" },
4858c2ecf20Sopenharmony_ci	{ "Left Input Mixer", "MicN Switch", "LIN" },
4868c2ecf20Sopenharmony_ci	{ "Left Input Mixer", "MicP Switch", "LIP" },
4878c2ecf20Sopenharmony_ci};
4888c2ecf20Sopenharmony_ci
4898c2ecf20Sopenharmony_cistatic int eqmode_get(struct snd_kcontrol *kcontrol,
4908c2ecf20Sopenharmony_ci		      struct snd_ctl_elem_value *ucontrol)
4918c2ecf20Sopenharmony_ci{
4928c2ecf20Sopenharmony_ci	struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
4938c2ecf20Sopenharmony_ci	unsigned int reg;
4948c2ecf20Sopenharmony_ci
4958c2ecf20Sopenharmony_ci	reg = snd_soc_component_read(component, WM8983_EQ1_LOW_SHELF);
4968c2ecf20Sopenharmony_ci	if (reg & WM8983_EQ3DMODE)
4978c2ecf20Sopenharmony_ci		ucontrol->value.enumerated.item[0] = 1;
4988c2ecf20Sopenharmony_ci	else
4998c2ecf20Sopenharmony_ci		ucontrol->value.enumerated.item[0] = 0;
5008c2ecf20Sopenharmony_ci
5018c2ecf20Sopenharmony_ci	return 0;
5028c2ecf20Sopenharmony_ci}
5038c2ecf20Sopenharmony_ci
5048c2ecf20Sopenharmony_cistatic int eqmode_put(struct snd_kcontrol *kcontrol,
5058c2ecf20Sopenharmony_ci		      struct snd_ctl_elem_value *ucontrol)
5068c2ecf20Sopenharmony_ci{
5078c2ecf20Sopenharmony_ci	struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
5088c2ecf20Sopenharmony_ci	unsigned int regpwr2, regpwr3;
5098c2ecf20Sopenharmony_ci	unsigned int reg_eq;
5108c2ecf20Sopenharmony_ci
5118c2ecf20Sopenharmony_ci	if (ucontrol->value.enumerated.item[0] != 0
5128c2ecf20Sopenharmony_ci	    && ucontrol->value.enumerated.item[0] != 1)
5138c2ecf20Sopenharmony_ci		return -EINVAL;
5148c2ecf20Sopenharmony_ci
5158c2ecf20Sopenharmony_ci	reg_eq = snd_soc_component_read(component, WM8983_EQ1_LOW_SHELF);
5168c2ecf20Sopenharmony_ci	switch ((reg_eq & WM8983_EQ3DMODE) >> WM8983_EQ3DMODE_SHIFT) {
5178c2ecf20Sopenharmony_ci	case 0:
5188c2ecf20Sopenharmony_ci		if (!ucontrol->value.enumerated.item[0])
5198c2ecf20Sopenharmony_ci			return 0;
5208c2ecf20Sopenharmony_ci		break;
5218c2ecf20Sopenharmony_ci	case 1:
5228c2ecf20Sopenharmony_ci		if (ucontrol->value.enumerated.item[0])
5238c2ecf20Sopenharmony_ci			return 0;
5248c2ecf20Sopenharmony_ci		break;
5258c2ecf20Sopenharmony_ci	}
5268c2ecf20Sopenharmony_ci
5278c2ecf20Sopenharmony_ci	regpwr2 = snd_soc_component_read(component, WM8983_POWER_MANAGEMENT_2);
5288c2ecf20Sopenharmony_ci	regpwr3 = snd_soc_component_read(component, WM8983_POWER_MANAGEMENT_3);
5298c2ecf20Sopenharmony_ci	/* disable the DACs and ADCs */
5308c2ecf20Sopenharmony_ci	snd_soc_component_update_bits(component, WM8983_POWER_MANAGEMENT_2,
5318c2ecf20Sopenharmony_ci			    WM8983_ADCENR_MASK | WM8983_ADCENL_MASK, 0);
5328c2ecf20Sopenharmony_ci	snd_soc_component_update_bits(component, WM8983_POWER_MANAGEMENT_3,
5338c2ecf20Sopenharmony_ci			    WM8983_DACENR_MASK | WM8983_DACENL_MASK, 0);
5348c2ecf20Sopenharmony_ci	/* set the desired eqmode */
5358c2ecf20Sopenharmony_ci	snd_soc_component_update_bits(component, WM8983_EQ1_LOW_SHELF,
5368c2ecf20Sopenharmony_ci			    WM8983_EQ3DMODE_MASK,
5378c2ecf20Sopenharmony_ci			    ucontrol->value.enumerated.item[0]
5388c2ecf20Sopenharmony_ci			    << WM8983_EQ3DMODE_SHIFT);
5398c2ecf20Sopenharmony_ci	/* restore DAC/ADC configuration */
5408c2ecf20Sopenharmony_ci	snd_soc_component_write(component, WM8983_POWER_MANAGEMENT_2, regpwr2);
5418c2ecf20Sopenharmony_ci	snd_soc_component_write(component, WM8983_POWER_MANAGEMENT_3, regpwr3);
5428c2ecf20Sopenharmony_ci	return 0;
5438c2ecf20Sopenharmony_ci}
5448c2ecf20Sopenharmony_ci
5458c2ecf20Sopenharmony_cistatic bool wm8983_writeable(struct device *dev, unsigned int reg)
5468c2ecf20Sopenharmony_ci{
5478c2ecf20Sopenharmony_ci	switch (reg) {
5488c2ecf20Sopenharmony_ci	case WM8983_SOFTWARE_RESET ... WM8983_RIGHT_ADC_DIGITAL_VOL:
5498c2ecf20Sopenharmony_ci	case WM8983_EQ1_LOW_SHELF ... WM8983_DAC_LIMITER_2:
5508c2ecf20Sopenharmony_ci	case WM8983_NOTCH_FILTER_1 ... WM8983_NOTCH_FILTER_4:
5518c2ecf20Sopenharmony_ci	case WM8983_ALC_CONTROL_1 ... WM8983_PLL_K_3:
5528c2ecf20Sopenharmony_ci	case WM8983_3D_CONTROL ... WM8983_OUT4_MONO_MIX_CTRL:
5538c2ecf20Sopenharmony_ci	case WM8983_BIAS_CTRL:
5548c2ecf20Sopenharmony_ci		return true;
5558c2ecf20Sopenharmony_ci	default:
5568c2ecf20Sopenharmony_ci		return false;
5578c2ecf20Sopenharmony_ci	}
5588c2ecf20Sopenharmony_ci}
5598c2ecf20Sopenharmony_ci
5608c2ecf20Sopenharmony_cistatic int wm8983_dac_mute(struct snd_soc_dai *dai, int mute, int direction)
5618c2ecf20Sopenharmony_ci{
5628c2ecf20Sopenharmony_ci	struct snd_soc_component *component = dai->component;
5638c2ecf20Sopenharmony_ci
5648c2ecf20Sopenharmony_ci	return snd_soc_component_update_bits(component, WM8983_DAC_CONTROL,
5658c2ecf20Sopenharmony_ci				   WM8983_SOFTMUTE_MASK,
5668c2ecf20Sopenharmony_ci				   !!mute << WM8983_SOFTMUTE_SHIFT);
5678c2ecf20Sopenharmony_ci}
5688c2ecf20Sopenharmony_ci
5698c2ecf20Sopenharmony_cistatic int wm8983_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
5708c2ecf20Sopenharmony_ci{
5718c2ecf20Sopenharmony_ci	struct snd_soc_component *component = dai->component;
5728c2ecf20Sopenharmony_ci	u16 format, master, bcp, lrp;
5738c2ecf20Sopenharmony_ci
5748c2ecf20Sopenharmony_ci	switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
5758c2ecf20Sopenharmony_ci	case SND_SOC_DAIFMT_I2S:
5768c2ecf20Sopenharmony_ci		format = 0x2;
5778c2ecf20Sopenharmony_ci		break;
5788c2ecf20Sopenharmony_ci	case SND_SOC_DAIFMT_RIGHT_J:
5798c2ecf20Sopenharmony_ci		format = 0x0;
5808c2ecf20Sopenharmony_ci		break;
5818c2ecf20Sopenharmony_ci	case SND_SOC_DAIFMT_LEFT_J:
5828c2ecf20Sopenharmony_ci		format = 0x1;
5838c2ecf20Sopenharmony_ci		break;
5848c2ecf20Sopenharmony_ci	case SND_SOC_DAIFMT_DSP_A:
5858c2ecf20Sopenharmony_ci	case SND_SOC_DAIFMT_DSP_B:
5868c2ecf20Sopenharmony_ci		format = 0x3;
5878c2ecf20Sopenharmony_ci		break;
5888c2ecf20Sopenharmony_ci	default:
5898c2ecf20Sopenharmony_ci		dev_err(dai->dev, "Unknown dai format\n");
5908c2ecf20Sopenharmony_ci		return -EINVAL;
5918c2ecf20Sopenharmony_ci	}
5928c2ecf20Sopenharmony_ci
5938c2ecf20Sopenharmony_ci	snd_soc_component_update_bits(component, WM8983_AUDIO_INTERFACE,
5948c2ecf20Sopenharmony_ci			    WM8983_FMT_MASK, format << WM8983_FMT_SHIFT);
5958c2ecf20Sopenharmony_ci
5968c2ecf20Sopenharmony_ci	switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
5978c2ecf20Sopenharmony_ci	case SND_SOC_DAIFMT_CBM_CFM:
5988c2ecf20Sopenharmony_ci		master = 1;
5998c2ecf20Sopenharmony_ci		break;
6008c2ecf20Sopenharmony_ci	case SND_SOC_DAIFMT_CBS_CFS:
6018c2ecf20Sopenharmony_ci		master = 0;
6028c2ecf20Sopenharmony_ci		break;
6038c2ecf20Sopenharmony_ci	default:
6048c2ecf20Sopenharmony_ci		dev_err(dai->dev, "Unknown master/slave configuration\n");
6058c2ecf20Sopenharmony_ci		return -EINVAL;
6068c2ecf20Sopenharmony_ci	}
6078c2ecf20Sopenharmony_ci
6088c2ecf20Sopenharmony_ci	snd_soc_component_update_bits(component, WM8983_CLOCK_GEN_CONTROL,
6098c2ecf20Sopenharmony_ci			    WM8983_MS_MASK, master << WM8983_MS_SHIFT);
6108c2ecf20Sopenharmony_ci
6118c2ecf20Sopenharmony_ci	/* FIXME: We don't currently support DSP A/B modes */
6128c2ecf20Sopenharmony_ci	switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
6138c2ecf20Sopenharmony_ci	case SND_SOC_DAIFMT_DSP_A:
6148c2ecf20Sopenharmony_ci	case SND_SOC_DAIFMT_DSP_B:
6158c2ecf20Sopenharmony_ci		dev_err(dai->dev, "DSP A/B modes are not supported\n");
6168c2ecf20Sopenharmony_ci		return -EINVAL;
6178c2ecf20Sopenharmony_ci	default:
6188c2ecf20Sopenharmony_ci		break;
6198c2ecf20Sopenharmony_ci	}
6208c2ecf20Sopenharmony_ci
6218c2ecf20Sopenharmony_ci	bcp = lrp = 0;
6228c2ecf20Sopenharmony_ci	switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
6238c2ecf20Sopenharmony_ci	case SND_SOC_DAIFMT_NB_NF:
6248c2ecf20Sopenharmony_ci		break;
6258c2ecf20Sopenharmony_ci	case SND_SOC_DAIFMT_IB_IF:
6268c2ecf20Sopenharmony_ci		bcp = lrp = 1;
6278c2ecf20Sopenharmony_ci		break;
6288c2ecf20Sopenharmony_ci	case SND_SOC_DAIFMT_IB_NF:
6298c2ecf20Sopenharmony_ci		bcp = 1;
6308c2ecf20Sopenharmony_ci		break;
6318c2ecf20Sopenharmony_ci	case SND_SOC_DAIFMT_NB_IF:
6328c2ecf20Sopenharmony_ci		lrp = 1;
6338c2ecf20Sopenharmony_ci		break;
6348c2ecf20Sopenharmony_ci	default:
6358c2ecf20Sopenharmony_ci		dev_err(dai->dev, "Unknown polarity configuration\n");
6368c2ecf20Sopenharmony_ci		return -EINVAL;
6378c2ecf20Sopenharmony_ci	}
6388c2ecf20Sopenharmony_ci
6398c2ecf20Sopenharmony_ci	snd_soc_component_update_bits(component, WM8983_AUDIO_INTERFACE,
6408c2ecf20Sopenharmony_ci			    WM8983_LRCP_MASK, lrp << WM8983_LRCP_SHIFT);
6418c2ecf20Sopenharmony_ci	snd_soc_component_update_bits(component, WM8983_AUDIO_INTERFACE,
6428c2ecf20Sopenharmony_ci			    WM8983_BCP_MASK, bcp << WM8983_BCP_SHIFT);
6438c2ecf20Sopenharmony_ci	return 0;
6448c2ecf20Sopenharmony_ci}
6458c2ecf20Sopenharmony_ci
6468c2ecf20Sopenharmony_cistatic int wm8983_hw_params(struct snd_pcm_substream *substream,
6478c2ecf20Sopenharmony_ci			    struct snd_pcm_hw_params *params,
6488c2ecf20Sopenharmony_ci			    struct snd_soc_dai *dai)
6498c2ecf20Sopenharmony_ci{
6508c2ecf20Sopenharmony_ci	int i;
6518c2ecf20Sopenharmony_ci	struct snd_soc_component *component = dai->component;
6528c2ecf20Sopenharmony_ci	struct wm8983_priv *wm8983 = snd_soc_component_get_drvdata(component);
6538c2ecf20Sopenharmony_ci	u16 blen, srate_idx;
6548c2ecf20Sopenharmony_ci	u32 tmp;
6558c2ecf20Sopenharmony_ci	int srate_best;
6568c2ecf20Sopenharmony_ci	int ret;
6578c2ecf20Sopenharmony_ci
6588c2ecf20Sopenharmony_ci	ret = snd_soc_params_to_bclk(params);
6598c2ecf20Sopenharmony_ci	if (ret < 0) {
6608c2ecf20Sopenharmony_ci		dev_err(component->dev, "Failed to convert params to bclk: %d\n", ret);
6618c2ecf20Sopenharmony_ci		return ret;
6628c2ecf20Sopenharmony_ci	}
6638c2ecf20Sopenharmony_ci
6648c2ecf20Sopenharmony_ci	wm8983->bclk = ret;
6658c2ecf20Sopenharmony_ci
6668c2ecf20Sopenharmony_ci	switch (params_width(params)) {
6678c2ecf20Sopenharmony_ci	case 16:
6688c2ecf20Sopenharmony_ci		blen = 0x0;
6698c2ecf20Sopenharmony_ci		break;
6708c2ecf20Sopenharmony_ci	case 20:
6718c2ecf20Sopenharmony_ci		blen = 0x1;
6728c2ecf20Sopenharmony_ci		break;
6738c2ecf20Sopenharmony_ci	case 24:
6748c2ecf20Sopenharmony_ci		blen = 0x2;
6758c2ecf20Sopenharmony_ci		break;
6768c2ecf20Sopenharmony_ci	case 32:
6778c2ecf20Sopenharmony_ci		blen = 0x3;
6788c2ecf20Sopenharmony_ci		break;
6798c2ecf20Sopenharmony_ci	default:
6808c2ecf20Sopenharmony_ci		dev_err(dai->dev, "Unsupported word length %u\n",
6818c2ecf20Sopenharmony_ci			params_width(params));
6828c2ecf20Sopenharmony_ci		return -EINVAL;
6838c2ecf20Sopenharmony_ci	}
6848c2ecf20Sopenharmony_ci
6858c2ecf20Sopenharmony_ci	snd_soc_component_update_bits(component, WM8983_AUDIO_INTERFACE,
6868c2ecf20Sopenharmony_ci			    WM8983_WL_MASK, blen << WM8983_WL_SHIFT);
6878c2ecf20Sopenharmony_ci
6888c2ecf20Sopenharmony_ci	/*
6898c2ecf20Sopenharmony_ci	 * match to the nearest possible sample rate and rely
6908c2ecf20Sopenharmony_ci	 * on the array index to configure the SR register
6918c2ecf20Sopenharmony_ci	 */
6928c2ecf20Sopenharmony_ci	srate_idx = 0;
6938c2ecf20Sopenharmony_ci	srate_best = abs(srates[0] - params_rate(params));
6948c2ecf20Sopenharmony_ci	for (i = 1; i < ARRAY_SIZE(srates); ++i) {
6958c2ecf20Sopenharmony_ci		if (abs(srates[i] - params_rate(params)) >= srate_best)
6968c2ecf20Sopenharmony_ci			continue;
6978c2ecf20Sopenharmony_ci		srate_idx = i;
6988c2ecf20Sopenharmony_ci		srate_best = abs(srates[i] - params_rate(params));
6998c2ecf20Sopenharmony_ci	}
7008c2ecf20Sopenharmony_ci
7018c2ecf20Sopenharmony_ci	dev_dbg(dai->dev, "Selected SRATE = %d\n", srates[srate_idx]);
7028c2ecf20Sopenharmony_ci	snd_soc_component_update_bits(component, WM8983_ADDITIONAL_CONTROL,
7038c2ecf20Sopenharmony_ci			    WM8983_SR_MASK, srate_idx << WM8983_SR_SHIFT);
7048c2ecf20Sopenharmony_ci
7058c2ecf20Sopenharmony_ci	dev_dbg(dai->dev, "Target BCLK = %uHz\n", wm8983->bclk);
7068c2ecf20Sopenharmony_ci	dev_dbg(dai->dev, "SYSCLK = %uHz\n", wm8983->sysclk);
7078c2ecf20Sopenharmony_ci
7088c2ecf20Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(fs_ratios); ++i) {
7098c2ecf20Sopenharmony_ci		if (wm8983->sysclk / params_rate(params)
7108c2ecf20Sopenharmony_ci		    == fs_ratios[i].ratio)
7118c2ecf20Sopenharmony_ci			break;
7128c2ecf20Sopenharmony_ci	}
7138c2ecf20Sopenharmony_ci
7148c2ecf20Sopenharmony_ci	if (i == ARRAY_SIZE(fs_ratios)) {
7158c2ecf20Sopenharmony_ci		dev_err(dai->dev, "Unable to configure MCLK ratio %u/%u\n",
7168c2ecf20Sopenharmony_ci			wm8983->sysclk, params_rate(params));
7178c2ecf20Sopenharmony_ci		return -EINVAL;
7188c2ecf20Sopenharmony_ci	}
7198c2ecf20Sopenharmony_ci
7208c2ecf20Sopenharmony_ci	dev_dbg(dai->dev, "MCLK ratio = %dfs\n", fs_ratios[i].ratio);
7218c2ecf20Sopenharmony_ci	snd_soc_component_update_bits(component, WM8983_CLOCK_GEN_CONTROL,
7228c2ecf20Sopenharmony_ci			    WM8983_MCLKDIV_MASK, i << WM8983_MCLKDIV_SHIFT);
7238c2ecf20Sopenharmony_ci
7248c2ecf20Sopenharmony_ci	/* select the appropriate bclk divider */
7258c2ecf20Sopenharmony_ci	tmp = (wm8983->sysclk / fs_ratios[i].div) * 10;
7268c2ecf20Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(bclk_divs); ++i) {
7278c2ecf20Sopenharmony_ci		if (wm8983->bclk == tmp / bclk_divs[i])
7288c2ecf20Sopenharmony_ci			break;
7298c2ecf20Sopenharmony_ci	}
7308c2ecf20Sopenharmony_ci
7318c2ecf20Sopenharmony_ci	if (i == ARRAY_SIZE(bclk_divs)) {
7328c2ecf20Sopenharmony_ci		dev_err(dai->dev, "No matching BCLK divider found\n");
7338c2ecf20Sopenharmony_ci		return -EINVAL;
7348c2ecf20Sopenharmony_ci	}
7358c2ecf20Sopenharmony_ci
7368c2ecf20Sopenharmony_ci	dev_dbg(dai->dev, "BCLK div = %d\n", i);
7378c2ecf20Sopenharmony_ci	snd_soc_component_update_bits(component, WM8983_CLOCK_GEN_CONTROL,
7388c2ecf20Sopenharmony_ci			    WM8983_BCLKDIV_MASK, i << WM8983_BCLKDIV_SHIFT);
7398c2ecf20Sopenharmony_ci
7408c2ecf20Sopenharmony_ci	return 0;
7418c2ecf20Sopenharmony_ci}
7428c2ecf20Sopenharmony_ci
7438c2ecf20Sopenharmony_cistruct pll_div {
7448c2ecf20Sopenharmony_ci	u32 div2:1;
7458c2ecf20Sopenharmony_ci	u32 n:4;
7468c2ecf20Sopenharmony_ci	u32 k:24;
7478c2ecf20Sopenharmony_ci};
7488c2ecf20Sopenharmony_ci
7498c2ecf20Sopenharmony_ci#define FIXED_PLL_SIZE ((1ULL << 24) * 10)
7508c2ecf20Sopenharmony_cistatic int pll_factors(struct pll_div *pll_div, unsigned int target,
7518c2ecf20Sopenharmony_ci		       unsigned int source)
7528c2ecf20Sopenharmony_ci{
7538c2ecf20Sopenharmony_ci	u64 Kpart;
7548c2ecf20Sopenharmony_ci	unsigned long int K, Ndiv, Nmod;
7558c2ecf20Sopenharmony_ci
7568c2ecf20Sopenharmony_ci	pll_div->div2 = 0;
7578c2ecf20Sopenharmony_ci	Ndiv = target / source;
7588c2ecf20Sopenharmony_ci	if (Ndiv < 6) {
7598c2ecf20Sopenharmony_ci		source >>= 1;
7608c2ecf20Sopenharmony_ci		pll_div->div2 = 1;
7618c2ecf20Sopenharmony_ci		Ndiv = target / source;
7628c2ecf20Sopenharmony_ci	}
7638c2ecf20Sopenharmony_ci
7648c2ecf20Sopenharmony_ci	if (Ndiv < 6 || Ndiv > 12) {
7658c2ecf20Sopenharmony_ci		printk(KERN_ERR "%s: WM8983 N value is not within"
7668c2ecf20Sopenharmony_ci		       " the recommended range: %lu\n", __func__, Ndiv);
7678c2ecf20Sopenharmony_ci		return -EINVAL;
7688c2ecf20Sopenharmony_ci	}
7698c2ecf20Sopenharmony_ci	pll_div->n = Ndiv;
7708c2ecf20Sopenharmony_ci
7718c2ecf20Sopenharmony_ci	Nmod = target % source;
7728c2ecf20Sopenharmony_ci	Kpart = FIXED_PLL_SIZE * (u64)Nmod;
7738c2ecf20Sopenharmony_ci
7748c2ecf20Sopenharmony_ci	do_div(Kpart, source);
7758c2ecf20Sopenharmony_ci
7768c2ecf20Sopenharmony_ci	K = Kpart & 0xffffffff;
7778c2ecf20Sopenharmony_ci	if ((K % 10) >= 5)
7788c2ecf20Sopenharmony_ci		K += 5;
7798c2ecf20Sopenharmony_ci	K /= 10;
7808c2ecf20Sopenharmony_ci	pll_div->k = K;
7818c2ecf20Sopenharmony_ci	return 0;
7828c2ecf20Sopenharmony_ci}
7838c2ecf20Sopenharmony_ci
7848c2ecf20Sopenharmony_cistatic int wm8983_set_pll(struct snd_soc_dai *dai, int pll_id,
7858c2ecf20Sopenharmony_ci			  int source, unsigned int freq_in,
7868c2ecf20Sopenharmony_ci			  unsigned int freq_out)
7878c2ecf20Sopenharmony_ci{
7888c2ecf20Sopenharmony_ci	int ret;
7898c2ecf20Sopenharmony_ci	struct snd_soc_component *component;
7908c2ecf20Sopenharmony_ci	struct pll_div pll_div;
7918c2ecf20Sopenharmony_ci
7928c2ecf20Sopenharmony_ci	component = dai->component;
7938c2ecf20Sopenharmony_ci	if (!freq_in || !freq_out) {
7948c2ecf20Sopenharmony_ci		/* disable the PLL */
7958c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, WM8983_POWER_MANAGEMENT_1,
7968c2ecf20Sopenharmony_ci				    WM8983_PLLEN_MASK, 0);
7978c2ecf20Sopenharmony_ci		return 0;
7988c2ecf20Sopenharmony_ci	} else {
7998c2ecf20Sopenharmony_ci		ret = pll_factors(&pll_div, freq_out * 4 * 2, freq_in);
8008c2ecf20Sopenharmony_ci		if (ret)
8018c2ecf20Sopenharmony_ci			return ret;
8028c2ecf20Sopenharmony_ci
8038c2ecf20Sopenharmony_ci		/* disable the PLL before re-programming it */
8048c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, WM8983_POWER_MANAGEMENT_1,
8058c2ecf20Sopenharmony_ci				    WM8983_PLLEN_MASK, 0);
8068c2ecf20Sopenharmony_ci
8078c2ecf20Sopenharmony_ci		/* set PLLN and PRESCALE */
8088c2ecf20Sopenharmony_ci		snd_soc_component_write(component, WM8983_PLL_N,
8098c2ecf20Sopenharmony_ci			(pll_div.div2 << WM8983_PLL_PRESCALE_SHIFT)
8108c2ecf20Sopenharmony_ci			| pll_div.n);
8118c2ecf20Sopenharmony_ci		/* set PLLK */
8128c2ecf20Sopenharmony_ci		snd_soc_component_write(component, WM8983_PLL_K_3, pll_div.k & 0x1ff);
8138c2ecf20Sopenharmony_ci		snd_soc_component_write(component, WM8983_PLL_K_2, (pll_div.k >> 9) & 0x1ff);
8148c2ecf20Sopenharmony_ci		snd_soc_component_write(component, WM8983_PLL_K_1, (pll_div.k >> 18));
8158c2ecf20Sopenharmony_ci		/* enable the PLL */
8168c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, WM8983_POWER_MANAGEMENT_1,
8178c2ecf20Sopenharmony_ci					WM8983_PLLEN_MASK, WM8983_PLLEN);
8188c2ecf20Sopenharmony_ci	}
8198c2ecf20Sopenharmony_ci
8208c2ecf20Sopenharmony_ci	return 0;
8218c2ecf20Sopenharmony_ci}
8228c2ecf20Sopenharmony_ci
8238c2ecf20Sopenharmony_cistatic int wm8983_set_sysclk(struct snd_soc_dai *dai,
8248c2ecf20Sopenharmony_ci			     int clk_id, unsigned int freq, int dir)
8258c2ecf20Sopenharmony_ci{
8268c2ecf20Sopenharmony_ci	struct snd_soc_component *component = dai->component;
8278c2ecf20Sopenharmony_ci	struct wm8983_priv *wm8983 = snd_soc_component_get_drvdata(component);
8288c2ecf20Sopenharmony_ci
8298c2ecf20Sopenharmony_ci	switch (clk_id) {
8308c2ecf20Sopenharmony_ci	case WM8983_CLKSRC_MCLK:
8318c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, WM8983_CLOCK_GEN_CONTROL,
8328c2ecf20Sopenharmony_ci				    WM8983_CLKSEL_MASK, 0);
8338c2ecf20Sopenharmony_ci		break;
8348c2ecf20Sopenharmony_ci	case WM8983_CLKSRC_PLL:
8358c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, WM8983_CLOCK_GEN_CONTROL,
8368c2ecf20Sopenharmony_ci				    WM8983_CLKSEL_MASK, WM8983_CLKSEL);
8378c2ecf20Sopenharmony_ci		break;
8388c2ecf20Sopenharmony_ci	default:
8398c2ecf20Sopenharmony_ci		dev_err(dai->dev, "Unknown clock source: %d\n", clk_id);
8408c2ecf20Sopenharmony_ci		return -EINVAL;
8418c2ecf20Sopenharmony_ci	}
8428c2ecf20Sopenharmony_ci
8438c2ecf20Sopenharmony_ci	wm8983->sysclk = freq;
8448c2ecf20Sopenharmony_ci	return 0;
8458c2ecf20Sopenharmony_ci}
8468c2ecf20Sopenharmony_ci
8478c2ecf20Sopenharmony_cistatic int wm8983_set_bias_level(struct snd_soc_component *component,
8488c2ecf20Sopenharmony_ci				 enum snd_soc_bias_level level)
8498c2ecf20Sopenharmony_ci{
8508c2ecf20Sopenharmony_ci	struct wm8983_priv *wm8983 = snd_soc_component_get_drvdata(component);
8518c2ecf20Sopenharmony_ci	int ret;
8528c2ecf20Sopenharmony_ci
8538c2ecf20Sopenharmony_ci	switch (level) {
8548c2ecf20Sopenharmony_ci	case SND_SOC_BIAS_ON:
8558c2ecf20Sopenharmony_ci	case SND_SOC_BIAS_PREPARE:
8568c2ecf20Sopenharmony_ci		/* VMID at 100k */
8578c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, WM8983_POWER_MANAGEMENT_1,
8588c2ecf20Sopenharmony_ci				    WM8983_VMIDSEL_MASK,
8598c2ecf20Sopenharmony_ci				    1 << WM8983_VMIDSEL_SHIFT);
8608c2ecf20Sopenharmony_ci		break;
8618c2ecf20Sopenharmony_ci	case SND_SOC_BIAS_STANDBY:
8628c2ecf20Sopenharmony_ci		if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_OFF) {
8638c2ecf20Sopenharmony_ci			ret = regcache_sync(wm8983->regmap);
8648c2ecf20Sopenharmony_ci			if (ret < 0) {
8658c2ecf20Sopenharmony_ci				dev_err(component->dev, "Failed to sync cache: %d\n", ret);
8668c2ecf20Sopenharmony_ci				return ret;
8678c2ecf20Sopenharmony_ci			}
8688c2ecf20Sopenharmony_ci			/* enable anti-pop features */
8698c2ecf20Sopenharmony_ci			snd_soc_component_update_bits(component, WM8983_OUT4_TO_ADC,
8708c2ecf20Sopenharmony_ci					    WM8983_POBCTRL_MASK | WM8983_DELEN_MASK,
8718c2ecf20Sopenharmony_ci					    WM8983_POBCTRL | WM8983_DELEN);
8728c2ecf20Sopenharmony_ci			/* enable thermal shutdown */
8738c2ecf20Sopenharmony_ci			snd_soc_component_update_bits(component, WM8983_OUTPUT_CTRL,
8748c2ecf20Sopenharmony_ci					    WM8983_TSDEN_MASK, WM8983_TSDEN);
8758c2ecf20Sopenharmony_ci			/* enable BIASEN */
8768c2ecf20Sopenharmony_ci			snd_soc_component_update_bits(component, WM8983_POWER_MANAGEMENT_1,
8778c2ecf20Sopenharmony_ci					    WM8983_BIASEN_MASK, WM8983_BIASEN);
8788c2ecf20Sopenharmony_ci			/* VMID at 100k */
8798c2ecf20Sopenharmony_ci			snd_soc_component_update_bits(component, WM8983_POWER_MANAGEMENT_1,
8808c2ecf20Sopenharmony_ci					    WM8983_VMIDSEL_MASK,
8818c2ecf20Sopenharmony_ci					    1 << WM8983_VMIDSEL_SHIFT);
8828c2ecf20Sopenharmony_ci			msleep(250);
8838c2ecf20Sopenharmony_ci			/* disable anti-pop features */
8848c2ecf20Sopenharmony_ci			snd_soc_component_update_bits(component, WM8983_OUT4_TO_ADC,
8858c2ecf20Sopenharmony_ci					    WM8983_POBCTRL_MASK |
8868c2ecf20Sopenharmony_ci					    WM8983_DELEN_MASK, 0);
8878c2ecf20Sopenharmony_ci		}
8888c2ecf20Sopenharmony_ci
8898c2ecf20Sopenharmony_ci		/* VMID at 500k */
8908c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, WM8983_POWER_MANAGEMENT_1,
8918c2ecf20Sopenharmony_ci				    WM8983_VMIDSEL_MASK,
8928c2ecf20Sopenharmony_ci				    2 << WM8983_VMIDSEL_SHIFT);
8938c2ecf20Sopenharmony_ci		break;
8948c2ecf20Sopenharmony_ci	case SND_SOC_BIAS_OFF:
8958c2ecf20Sopenharmony_ci		/* disable thermal shutdown */
8968c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, WM8983_OUTPUT_CTRL,
8978c2ecf20Sopenharmony_ci				    WM8983_TSDEN_MASK, 0);
8988c2ecf20Sopenharmony_ci		/* disable VMIDSEL and BIASEN */
8998c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, WM8983_POWER_MANAGEMENT_1,
9008c2ecf20Sopenharmony_ci				    WM8983_VMIDSEL_MASK | WM8983_BIASEN_MASK,
9018c2ecf20Sopenharmony_ci				    0);
9028c2ecf20Sopenharmony_ci		/* wait for VMID to discharge */
9038c2ecf20Sopenharmony_ci		msleep(100);
9048c2ecf20Sopenharmony_ci		snd_soc_component_write(component, WM8983_POWER_MANAGEMENT_1, 0);
9058c2ecf20Sopenharmony_ci		snd_soc_component_write(component, WM8983_POWER_MANAGEMENT_2, 0);
9068c2ecf20Sopenharmony_ci		snd_soc_component_write(component, WM8983_POWER_MANAGEMENT_3, 0);
9078c2ecf20Sopenharmony_ci		break;
9088c2ecf20Sopenharmony_ci	}
9098c2ecf20Sopenharmony_ci
9108c2ecf20Sopenharmony_ci	return 0;
9118c2ecf20Sopenharmony_ci}
9128c2ecf20Sopenharmony_ci
9138c2ecf20Sopenharmony_cistatic int wm8983_probe(struct snd_soc_component *component)
9148c2ecf20Sopenharmony_ci{
9158c2ecf20Sopenharmony_ci	int ret;
9168c2ecf20Sopenharmony_ci	int i;
9178c2ecf20Sopenharmony_ci
9188c2ecf20Sopenharmony_ci	ret = snd_soc_component_write(component, WM8983_SOFTWARE_RESET, 0);
9198c2ecf20Sopenharmony_ci	if (ret < 0) {
9208c2ecf20Sopenharmony_ci		dev_err(component->dev, "Failed to issue reset: %d\n", ret);
9218c2ecf20Sopenharmony_ci		return ret;
9228c2ecf20Sopenharmony_ci	}
9238c2ecf20Sopenharmony_ci
9248c2ecf20Sopenharmony_ci	/* set the vol/gain update bits */
9258c2ecf20Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(vol_update_regs); ++i)
9268c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, vol_update_regs[i],
9278c2ecf20Sopenharmony_ci				    0x100, 0x100);
9288c2ecf20Sopenharmony_ci
9298c2ecf20Sopenharmony_ci	/* mute all outputs and set PGAs to minimum gain */
9308c2ecf20Sopenharmony_ci	for (i = WM8983_LOUT1_HP_VOLUME_CTRL;
9318c2ecf20Sopenharmony_ci	     i <= WM8983_OUT4_MONO_MIX_CTRL; ++i)
9328c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, i, 0x40, 0x40);
9338c2ecf20Sopenharmony_ci
9348c2ecf20Sopenharmony_ci	/* enable soft mute */
9358c2ecf20Sopenharmony_ci	snd_soc_component_update_bits(component, WM8983_DAC_CONTROL,
9368c2ecf20Sopenharmony_ci			    WM8983_SOFTMUTE_MASK,
9378c2ecf20Sopenharmony_ci			    WM8983_SOFTMUTE);
9388c2ecf20Sopenharmony_ci
9398c2ecf20Sopenharmony_ci	/* enable BIASCUT */
9408c2ecf20Sopenharmony_ci	snd_soc_component_update_bits(component, WM8983_BIAS_CTRL,
9418c2ecf20Sopenharmony_ci			    WM8983_BIASCUT, WM8983_BIASCUT);
9428c2ecf20Sopenharmony_ci	return 0;
9438c2ecf20Sopenharmony_ci}
9448c2ecf20Sopenharmony_ci
9458c2ecf20Sopenharmony_cistatic const struct snd_soc_dai_ops wm8983_dai_ops = {
9468c2ecf20Sopenharmony_ci	.mute_stream = wm8983_dac_mute,
9478c2ecf20Sopenharmony_ci	.hw_params = wm8983_hw_params,
9488c2ecf20Sopenharmony_ci	.set_fmt = wm8983_set_fmt,
9498c2ecf20Sopenharmony_ci	.set_sysclk = wm8983_set_sysclk,
9508c2ecf20Sopenharmony_ci	.set_pll = wm8983_set_pll,
9518c2ecf20Sopenharmony_ci	.no_capture_mute = 1,
9528c2ecf20Sopenharmony_ci};
9538c2ecf20Sopenharmony_ci
9548c2ecf20Sopenharmony_ci#define WM8983_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
9558c2ecf20Sopenharmony_ci			SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
9568c2ecf20Sopenharmony_ci
9578c2ecf20Sopenharmony_cistatic struct snd_soc_dai_driver wm8983_dai = {
9588c2ecf20Sopenharmony_ci	.name = "wm8983-hifi",
9598c2ecf20Sopenharmony_ci	.playback = {
9608c2ecf20Sopenharmony_ci		.stream_name = "Playback",
9618c2ecf20Sopenharmony_ci		.channels_min = 2,
9628c2ecf20Sopenharmony_ci		.channels_max = 2,
9638c2ecf20Sopenharmony_ci		.rates = SNDRV_PCM_RATE_8000_48000,
9648c2ecf20Sopenharmony_ci		.formats = WM8983_FORMATS,
9658c2ecf20Sopenharmony_ci	},
9668c2ecf20Sopenharmony_ci	.capture = {
9678c2ecf20Sopenharmony_ci		.stream_name = "Capture",
9688c2ecf20Sopenharmony_ci		.channels_min = 2,
9698c2ecf20Sopenharmony_ci		.channels_max = 2,
9708c2ecf20Sopenharmony_ci		.rates = SNDRV_PCM_RATE_8000_48000,
9718c2ecf20Sopenharmony_ci		.formats = WM8983_FORMATS,
9728c2ecf20Sopenharmony_ci	},
9738c2ecf20Sopenharmony_ci	.ops = &wm8983_dai_ops,
9748c2ecf20Sopenharmony_ci	.symmetric_rates = 1
9758c2ecf20Sopenharmony_ci};
9768c2ecf20Sopenharmony_ci
9778c2ecf20Sopenharmony_cistatic const struct snd_soc_component_driver soc_component_dev_wm8983 = {
9788c2ecf20Sopenharmony_ci	.probe			= wm8983_probe,
9798c2ecf20Sopenharmony_ci	.set_bias_level		= wm8983_set_bias_level,
9808c2ecf20Sopenharmony_ci	.controls		= wm8983_snd_controls,
9818c2ecf20Sopenharmony_ci	.num_controls		= ARRAY_SIZE(wm8983_snd_controls),
9828c2ecf20Sopenharmony_ci	.dapm_widgets		= wm8983_dapm_widgets,
9838c2ecf20Sopenharmony_ci	.num_dapm_widgets	= ARRAY_SIZE(wm8983_dapm_widgets),
9848c2ecf20Sopenharmony_ci	.dapm_routes		= wm8983_audio_map,
9858c2ecf20Sopenharmony_ci	.num_dapm_routes	= ARRAY_SIZE(wm8983_audio_map),
9868c2ecf20Sopenharmony_ci	.suspend_bias_off	= 1,
9878c2ecf20Sopenharmony_ci	.idle_bias_on		= 1,
9888c2ecf20Sopenharmony_ci	.use_pmdown_time	= 1,
9898c2ecf20Sopenharmony_ci	.endianness		= 1,
9908c2ecf20Sopenharmony_ci	.non_legacy_dai_naming	= 1,
9918c2ecf20Sopenharmony_ci};
9928c2ecf20Sopenharmony_ci
9938c2ecf20Sopenharmony_cistatic const struct regmap_config wm8983_regmap = {
9948c2ecf20Sopenharmony_ci	.reg_bits = 7,
9958c2ecf20Sopenharmony_ci	.val_bits = 9,
9968c2ecf20Sopenharmony_ci
9978c2ecf20Sopenharmony_ci	.reg_defaults = wm8983_defaults,
9988c2ecf20Sopenharmony_ci	.num_reg_defaults = ARRAY_SIZE(wm8983_defaults),
9998c2ecf20Sopenharmony_ci	.cache_type = REGCACHE_RBTREE,
10008c2ecf20Sopenharmony_ci	.max_register = WM8983_MAX_REGISTER,
10018c2ecf20Sopenharmony_ci
10028c2ecf20Sopenharmony_ci	.writeable_reg = wm8983_writeable,
10038c2ecf20Sopenharmony_ci};
10048c2ecf20Sopenharmony_ci
10058c2ecf20Sopenharmony_ci#if defined(CONFIG_SPI_MASTER)
10068c2ecf20Sopenharmony_cistatic int wm8983_spi_probe(struct spi_device *spi)
10078c2ecf20Sopenharmony_ci{
10088c2ecf20Sopenharmony_ci	struct wm8983_priv *wm8983;
10098c2ecf20Sopenharmony_ci	int ret;
10108c2ecf20Sopenharmony_ci
10118c2ecf20Sopenharmony_ci	wm8983 = devm_kzalloc(&spi->dev, sizeof *wm8983, GFP_KERNEL);
10128c2ecf20Sopenharmony_ci	if (!wm8983)
10138c2ecf20Sopenharmony_ci		return -ENOMEM;
10148c2ecf20Sopenharmony_ci
10158c2ecf20Sopenharmony_ci	wm8983->regmap = devm_regmap_init_spi(spi, &wm8983_regmap);
10168c2ecf20Sopenharmony_ci	if (IS_ERR(wm8983->regmap)) {
10178c2ecf20Sopenharmony_ci		ret = PTR_ERR(wm8983->regmap);
10188c2ecf20Sopenharmony_ci		dev_err(&spi->dev, "Failed to init regmap: %d\n", ret);
10198c2ecf20Sopenharmony_ci		return ret;
10208c2ecf20Sopenharmony_ci	}
10218c2ecf20Sopenharmony_ci
10228c2ecf20Sopenharmony_ci	spi_set_drvdata(spi, wm8983);
10238c2ecf20Sopenharmony_ci
10248c2ecf20Sopenharmony_ci	ret = devm_snd_soc_register_component(&spi->dev,
10258c2ecf20Sopenharmony_ci				&soc_component_dev_wm8983, &wm8983_dai, 1);
10268c2ecf20Sopenharmony_ci	return ret;
10278c2ecf20Sopenharmony_ci}
10288c2ecf20Sopenharmony_ci
10298c2ecf20Sopenharmony_cistatic struct spi_driver wm8983_spi_driver = {
10308c2ecf20Sopenharmony_ci	.driver = {
10318c2ecf20Sopenharmony_ci		.name = "wm8983",
10328c2ecf20Sopenharmony_ci	},
10338c2ecf20Sopenharmony_ci	.probe = wm8983_spi_probe,
10348c2ecf20Sopenharmony_ci};
10358c2ecf20Sopenharmony_ci#endif
10368c2ecf20Sopenharmony_ci
10378c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_I2C)
10388c2ecf20Sopenharmony_cistatic int wm8983_i2c_probe(struct i2c_client *i2c,
10398c2ecf20Sopenharmony_ci			    const struct i2c_device_id *id)
10408c2ecf20Sopenharmony_ci{
10418c2ecf20Sopenharmony_ci	struct wm8983_priv *wm8983;
10428c2ecf20Sopenharmony_ci	int ret;
10438c2ecf20Sopenharmony_ci
10448c2ecf20Sopenharmony_ci	wm8983 = devm_kzalloc(&i2c->dev, sizeof *wm8983, GFP_KERNEL);
10458c2ecf20Sopenharmony_ci	if (!wm8983)
10468c2ecf20Sopenharmony_ci		return -ENOMEM;
10478c2ecf20Sopenharmony_ci
10488c2ecf20Sopenharmony_ci	wm8983->regmap = devm_regmap_init_i2c(i2c, &wm8983_regmap);
10498c2ecf20Sopenharmony_ci	if (IS_ERR(wm8983->regmap)) {
10508c2ecf20Sopenharmony_ci		ret = PTR_ERR(wm8983->regmap);
10518c2ecf20Sopenharmony_ci		dev_err(&i2c->dev, "Failed to init regmap: %d\n", ret);
10528c2ecf20Sopenharmony_ci		return ret;
10538c2ecf20Sopenharmony_ci	}
10548c2ecf20Sopenharmony_ci
10558c2ecf20Sopenharmony_ci	i2c_set_clientdata(i2c, wm8983);
10568c2ecf20Sopenharmony_ci
10578c2ecf20Sopenharmony_ci	ret = devm_snd_soc_register_component(&i2c->dev,
10588c2ecf20Sopenharmony_ci				&soc_component_dev_wm8983, &wm8983_dai, 1);
10598c2ecf20Sopenharmony_ci
10608c2ecf20Sopenharmony_ci	return ret;
10618c2ecf20Sopenharmony_ci}
10628c2ecf20Sopenharmony_ci
10638c2ecf20Sopenharmony_cistatic const struct i2c_device_id wm8983_i2c_id[] = {
10648c2ecf20Sopenharmony_ci	{ "wm8983", 0 },
10658c2ecf20Sopenharmony_ci	{ }
10668c2ecf20Sopenharmony_ci};
10678c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(i2c, wm8983_i2c_id);
10688c2ecf20Sopenharmony_ci
10698c2ecf20Sopenharmony_cistatic struct i2c_driver wm8983_i2c_driver = {
10708c2ecf20Sopenharmony_ci	.driver = {
10718c2ecf20Sopenharmony_ci		.name = "wm8983",
10728c2ecf20Sopenharmony_ci	},
10738c2ecf20Sopenharmony_ci	.probe = wm8983_i2c_probe,
10748c2ecf20Sopenharmony_ci	.id_table = wm8983_i2c_id
10758c2ecf20Sopenharmony_ci};
10768c2ecf20Sopenharmony_ci#endif
10778c2ecf20Sopenharmony_ci
10788c2ecf20Sopenharmony_cistatic int __init wm8983_modinit(void)
10798c2ecf20Sopenharmony_ci{
10808c2ecf20Sopenharmony_ci	int ret = 0;
10818c2ecf20Sopenharmony_ci
10828c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_I2C)
10838c2ecf20Sopenharmony_ci	ret = i2c_add_driver(&wm8983_i2c_driver);
10848c2ecf20Sopenharmony_ci	if (ret) {
10858c2ecf20Sopenharmony_ci		printk(KERN_ERR "Failed to register wm8983 I2C driver: %d\n",
10868c2ecf20Sopenharmony_ci		       ret);
10878c2ecf20Sopenharmony_ci	}
10888c2ecf20Sopenharmony_ci#endif
10898c2ecf20Sopenharmony_ci#if defined(CONFIG_SPI_MASTER)
10908c2ecf20Sopenharmony_ci	ret = spi_register_driver(&wm8983_spi_driver);
10918c2ecf20Sopenharmony_ci	if (ret != 0) {
10928c2ecf20Sopenharmony_ci		printk(KERN_ERR "Failed to register wm8983 SPI driver: %d\n",
10938c2ecf20Sopenharmony_ci		       ret);
10948c2ecf20Sopenharmony_ci	}
10958c2ecf20Sopenharmony_ci#endif
10968c2ecf20Sopenharmony_ci	return ret;
10978c2ecf20Sopenharmony_ci}
10988c2ecf20Sopenharmony_cimodule_init(wm8983_modinit);
10998c2ecf20Sopenharmony_ci
11008c2ecf20Sopenharmony_cistatic void __exit wm8983_exit(void)
11018c2ecf20Sopenharmony_ci{
11028c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_I2C)
11038c2ecf20Sopenharmony_ci	i2c_del_driver(&wm8983_i2c_driver);
11048c2ecf20Sopenharmony_ci#endif
11058c2ecf20Sopenharmony_ci#if defined(CONFIG_SPI_MASTER)
11068c2ecf20Sopenharmony_ci	spi_unregister_driver(&wm8983_spi_driver);
11078c2ecf20Sopenharmony_ci#endif
11088c2ecf20Sopenharmony_ci}
11098c2ecf20Sopenharmony_cimodule_exit(wm8983_exit);
11108c2ecf20Sopenharmony_ci
11118c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("ASoC WM8983 driver");
11128c2ecf20Sopenharmony_ciMODULE_AUTHOR("Dimitris Papastamos <dp@opensource.wolfsonmicro.com>");
11138c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL");
1114