blob: 41c4b126114de0836db05a4a0ed6993f442eda4a [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Mark Brown9e6e96a2010-01-29 17:47:12 +00002/*
3 * wm8994.h -- WM8994 Soc Audio driver
Mark Brown9e6e96a2010-01-29 17:47:12 +00004 */
5
6#ifndef _WM8994_H
7#define _WM8994_H
8
Sylwester Nawrocki419e2f52019-09-20 15:02:12 +02009#include <linux/clk.h>
Mark Brown9e6e96a2010-01-29 17:47:12 +000010#include <sound/soc.h>
Mark Brownfbbf5922011-03-11 18:09:04 +000011#include <linux/firmware.h>
Mark Brownc7ebf932011-07-12 19:47:59 +090012#include <linux/completion.h>
Mark Browne9b54de42012-05-09 19:20:59 +010013#include <linux/workqueue.h>
Lars-Peter Clausenfabfad22014-11-09 17:01:02 +010014#include <linux/mutex.h>
Mark Brown9e6e96a2010-01-29 17:47:12 +000015
Mark Brownf701a2e2011-03-09 19:31:01 +000016#include "wm_hubs.h"
17
Sylwester Nawrocki419e2f52019-09-20 15:02:12 +020018enum {
19 WM8994_MCLK1,
20 WM8994_MCLK2,
21 WM8994_NUM_MCLK
22};
23
Mark Brown9e6e96a2010-01-29 17:47:12 +000024/* Sources for AIF1/2 SYSCLK - use with set_dai_sysclk() */
25#define WM8994_SYSCLK_MCLK1 1
26#define WM8994_SYSCLK_MCLK2 2
27#define WM8994_SYSCLK_FLL1 3
28#define WM8994_SYSCLK_FLL2 4
29
Mark Brown66b47fd2010-07-08 11:25:43 +090030/* OPCLK is also configured with set_dai_sysclk, specify division*10 as rate. */
31#define WM8994_SYSCLK_OPCLK 5
32
Mark Brown9e6e96a2010-01-29 17:47:12 +000033#define WM8994_FLL1 1
34#define WM8994_FLL2 2
35
Mark Brownfbfe6982012-07-23 20:14:43 +010036#define WM8994_FLL_SRC_MCLK1 1
37#define WM8994_FLL_SRC_MCLK2 2
38#define WM8994_FLL_SRC_LRCLK 3
39#define WM8994_FLL_SRC_BCLK 4
40#define WM8994_FLL_SRC_INTERNAL 5
Mark Brown136ff2a2010-04-20 12:56:18 +090041
Mark Brown22f8d052012-03-19 17:32:06 +000042enum wm8994_vmid_mode {
43 WM8994_VMID_NORMAL,
44 WM8994_VMID_FORCE,
45};
46
Mark Brown63dd5452012-11-22 20:44:32 +090047typedef void (*wm1811_micdet_cb)(void *data);
Mark Brown98869f62012-12-03 16:14:37 +090048typedef void (*wm1811_mic_id_cb)(void *data, u16 status);
Mark Brown821edd22010-11-26 15:21:09 +000049
Kuninori Morimoto00a69412018-01-29 03:12:21 +000050int wm8994_mic_detect(struct snd_soc_component *component, struct snd_soc_jack *jack,
Mark Brown87092e32012-02-06 18:50:39 +000051 int micbias);
Kuninori Morimoto00a69412018-01-29 03:12:21 +000052int wm8958_mic_detect(struct snd_soc_component *component, struct snd_soc_jack *jack,
Mark Brown98869f62012-12-03 16:14:37 +090053 wm1811_micdet_cb cb, void *det_cb_data,
54 wm1811_mic_id_cb id_cb, void *id_cb_data);
Mark Brown88766982010-03-29 20:57:12 +010055
Kuninori Morimoto00a69412018-01-29 03:12:21 +000056int wm8994_vmid_mode(struct snd_soc_component *component, enum wm8994_vmid_mode mode);
Mark Brown22f8d052012-03-19 17:32:06 +000057
Mark Brownf701a2e2011-03-09 19:31:01 +000058int wm8958_aif_ev(struct snd_soc_dapm_widget *w,
59 struct snd_kcontrol *kcontrol, int event);
60
Kuninori Morimoto00a69412018-01-29 03:12:21 +000061void wm8958_dsp2_init(struct snd_soc_component *component);
Mark Brownf701a2e2011-03-09 19:31:01 +000062
63struct wm8994_micdet {
64 struct snd_soc_jack *jack;
Mark Brown87092e32012-02-06 18:50:39 +000065 bool detecting;
Mark Brownf701a2e2011-03-09 19:31:01 +000066};
67
68/* codec private data */
69struct wm8994_fll_config {
70 int src;
71 int in;
72 int out;
73};
74
75#define WM8994_NUM_DRC 3
76#define WM8994_NUM_EQ 3
77
Mark Brown2a8a8562011-07-24 12:20:41 +010078struct wm8994;
79
Mark Brownf701a2e2011-03-09 19:31:01 +000080struct wm8994_priv {
81 struct wm_hubs_data hubs;
Mark Brown2a8a8562011-07-24 12:20:41 +010082 struct wm8994 *wm8994;
Sylwester Nawrocki419e2f52019-09-20 15:02:12 +020083 struct clk_bulk_data mclk[WM8994_NUM_MCLK];
Mark Brownf701a2e2011-03-09 19:31:01 +000084 int sysclk[2];
85 int sysclk_rate[2];
Sylwester Nawrocki419e2f52019-09-20 15:02:12 +020086 int mclk_rate[2];
Mark Brownf701a2e2011-03-09 19:31:01 +000087 int aifclk[2];
Mark Brownd3725762013-01-29 23:17:12 +080088 int aifdiv[2];
Mark Brown79748cd2012-10-01 15:28:30 +010089 int channels[2];
Mark Brownf701a2e2011-03-09 19:31:01 +000090 struct wm8994_fll_config fll[2], fll_suspend[2];
Mark Brownc7ebf932011-07-12 19:47:59 +090091 struct completion fll_locked[2];
92 bool fll_locked_irq;
Mark Brown20dc24a2012-04-05 12:55:20 +010093 bool fll_byp;
Mark Brown99af79d2012-07-25 23:03:36 +010094 bool clk_has_run;
Mark Brownf701a2e2011-03-09 19:31:01 +000095
Mark Brown4b7ed832011-08-10 17:47:33 +090096 int vmid_refcount;
Mark Brownaf6b6fe2011-11-30 20:32:05 +000097 int active_refcount;
Mark Brown22f8d052012-03-19 17:32:06 +000098 enum wm8994_vmid_mode vmid_mode;
Mark Brown4b7ed832011-08-10 17:47:33 +090099
Mark Brownf701a2e2011-03-09 19:31:01 +0000100 int dac_rates[2];
101 int lrclk_shared[2];
102
103 int mbc_ena[3];
Mark Brown09e10d72011-03-16 22:57:47 +0000104 int hpf1_ena[3];
105 int hpf2_ena[3];
106 int vss_ena[3];
Mark Brown31215872011-03-17 20:23:43 +0000107 int enh_eq_ena[3];
Mark Brownf701a2e2011-03-09 19:31:01 +0000108
109 /* Platform dependant DRC configuration */
110 const char **drc_texts;
111 int drc_cfg[WM8994_NUM_DRC];
112 struct soc_enum drc_enum;
113
114 /* Platform dependant ReTune mobile configuration */
115 int num_retune_mobile_texts;
116 const char **retune_mobile_texts;
117 int retune_mobile_cfg[WM8994_NUM_EQ];
118 struct soc_enum retune_mobile_enum;
119
120 /* Platform dependant MBC configuration */
121 int mbc_cfg;
122 const char **mbc_texts;
123 struct soc_enum mbc_enum;
124
Mark Brown09e10d72011-03-16 22:57:47 +0000125 /* Platform dependant VSS configuration */
126 int vss_cfg;
127 const char **vss_texts;
128 struct soc_enum vss_enum;
129
130 /* Platform dependant VSS HPF configuration */
131 int vss_hpf_cfg;
132 const char **vss_hpf_texts;
133 struct soc_enum vss_hpf_enum;
134
Mark Brown31215872011-03-17 20:23:43 +0000135 /* Platform dependant enhanced EQ configuration */
136 int enh_eq_cfg;
137 const char **enh_eq_texts;
138 struct soc_enum enh_eq_enum;
139
Mark Brownaf6b6fe2011-11-30 20:32:05 +0000140 struct mutex accdet_lock;
Mark Brownf701a2e2011-03-09 19:31:01 +0000141 struct wm8994_micdet micdet[2];
Mark Browne9b54de42012-05-09 19:20:59 +0100142 struct delayed_work mic_work;
Mark Brown70bd3b22013-05-29 20:28:16 +0100143 struct delayed_work open_circuit_work;
Mark Brown2da1c4b2013-05-30 13:42:29 +0100144 struct delayed_work mic_complete_work;
145 u16 mic_status;
Mark Brown157a75e2011-11-30 13:43:51 +0000146 bool mic_detecting;
Mark Brownb00adf72011-08-13 11:57:18 +0900147 bool jack_mic;
Mark Brown4585790d2011-11-30 10:55:14 +0000148 int btn_mask;
Mark Brownaf6b6fe2011-11-30 20:32:05 +0000149 bool jackdet;
Mark Brown4752a882012-03-04 02:16:01 +0000150 int jackdet_mode;
Mark Brown99af79d2012-07-25 23:03:36 +0100151 struct delayed_work jackdet_bootstrap;
Mark Brownf701a2e2011-03-09 19:31:01 +0000152
Mark Brownf701a2e2011-03-09 19:31:01 +0000153 int micdet_irq;
Mark Brown63dd5452012-11-22 20:44:32 +0900154 wm1811_micdet_cb micd_cb;
155 void *micd_cb_data;
Mark Brown98869f62012-12-03 16:14:37 +0900156 wm1811_mic_id_cb mic_id_cb;
157 void *mic_id_cb_data;
Mark Brownf701a2e2011-03-09 19:31:01 +0000158
Mark Brownf701a2e2011-03-09 19:31:01 +0000159 unsigned int aif1clk_enable:1;
160 unsigned int aif2clk_enable:1;
161
162 unsigned int aif1clk_disable:1;
163 unsigned int aif2clk_disable:1;
Mark Brownfbbf5922011-03-11 18:09:04 +0000164
Lars-Peter Clausenfabfad22014-11-09 17:01:02 +0100165 struct mutex fw_lock;
Mark Brownf20d77c2011-03-16 20:55:37 +0000166 int dsp_active;
Mark Brownfbbf5922011-03-11 18:09:04 +0000167 const struct firmware *cur_fw;
168 const struct firmware *mbc;
Mark Brown09e10d72011-03-16 22:57:47 +0000169 const struct firmware *mbc_vss;
Mark Brown31215872011-03-17 20:23:43 +0000170 const struct firmware *enh_eq;
Mark Brownf701a2e2011-03-09 19:31:01 +0000171};
172
Mark Brown9e6e96a2010-01-29 17:47:12 +0000173#endif