1d6e65bb7SShuming Fan // SPDX-License-Identifier: GPL-2.0
2d6e65bb7SShuming Fan /*
3d6e65bb7SShuming Fan * rt1011.c -- rt1011 ALSA SoC amplifier component driver
4d6e65bb7SShuming Fan *
5d6e65bb7SShuming Fan * Copyright(c) 2019 Realtek Semiconductor Corp.
6d6e65bb7SShuming Fan *
7d6e65bb7SShuming Fan * Author: Shuming Fan <shumingf@realtek.com>
8d6e65bb7SShuming Fan *
9d6e65bb7SShuming Fan */
10d6e65bb7SShuming Fan
11d6e65bb7SShuming Fan #include <linux/module.h>
12d6e65bb7SShuming Fan #include <linux/moduleparam.h>
13d6e65bb7SShuming Fan #include <linux/init.h>
14d6e65bb7SShuming Fan #include <linux/delay.h>
15d6e65bb7SShuming Fan #include <linux/pm.h>
16d6e65bb7SShuming Fan #include <linux/i2c.h>
17d6e65bb7SShuming Fan #include <linux/acpi.h>
18d6e65bb7SShuming Fan #include <linux/regmap.h>
19d6e65bb7SShuming Fan #include <linux/platform_device.h>
20d6e65bb7SShuming Fan #include <linux/firmware.h>
21d6e65bb7SShuming Fan #include <sound/core.h>
22d6e65bb7SShuming Fan #include <sound/pcm.h>
23d6e65bb7SShuming Fan #include <sound/pcm_params.h>
24d6e65bb7SShuming Fan #include <sound/soc.h>
25d6e65bb7SShuming Fan #include <sound/soc-dapm.h>
26d6e65bb7SShuming Fan #include <sound/initval.h>
27d6e65bb7SShuming Fan #include <sound/tlv.h>
28d6e65bb7SShuming Fan
29d6e65bb7SShuming Fan #include "rl6231.h"
30d6e65bb7SShuming Fan #include "rt1011.h"
31d6e65bb7SShuming Fan
32d6e65bb7SShuming Fan static int rt1011_calibrate(struct rt1011_priv *rt1011,
33d6e65bb7SShuming Fan unsigned char cali_flag);
34d6e65bb7SShuming Fan
35d6e65bb7SShuming Fan static const struct reg_sequence init_list[] = {
36d6e65bb7SShuming Fan
37d6e65bb7SShuming Fan { RT1011_POWER_9, 0xa840 },
38d6e65bb7SShuming Fan
39d6e65bb7SShuming Fan { RT1011_ADC_SET_5, 0x0a20 },
4009297c2fSShuming Fan { RT1011_DAC_SET_2, 0xa032 },
41d6e65bb7SShuming Fan
42d6e65bb7SShuming Fan { RT1011_SPK_PRO_DC_DET_1, 0xb00c },
43d6e65bb7SShuming Fan { RT1011_SPK_PRO_DC_DET_2, 0xcccc },
44d6e65bb7SShuming Fan
45d6e65bb7SShuming Fan { RT1011_A_TIMING_1, 0x6054 },
46d6e65bb7SShuming Fan
47d6e65bb7SShuming Fan { RT1011_POWER_7, 0x3e55 },
48d6e65bb7SShuming Fan { RT1011_POWER_8, 0x0520 },
49d6e65bb7SShuming Fan { RT1011_BOOST_CON_1, 0xe188 },
50d6e65bb7SShuming Fan { RT1011_POWER_4, 0x16f2 },
51d6e65bb7SShuming Fan
52d6e65bb7SShuming Fan { RT1011_CROSS_BQ_SET_1, 0x0004 },
53d6e65bb7SShuming Fan { RT1011_SIL_DET, 0xc313 },
54d6e65bb7SShuming Fan { RT1011_SINE_GEN_REG_1, 0x0707 },
55d6e65bb7SShuming Fan
56d6e65bb7SShuming Fan { RT1011_DC_CALIB_CLASSD_3, 0xcb00 },
57d6e65bb7SShuming Fan
58d6e65bb7SShuming Fan { RT1011_DAC_SET_1, 0xe702 },
59d6e65bb7SShuming Fan { RT1011_DAC_SET_3, 0x2004 },
60d6e65bb7SShuming Fan };
61d6e65bb7SShuming Fan
62d6e65bb7SShuming Fan static const struct reg_default rt1011_reg[] = {
63d6e65bb7SShuming Fan {0x0000, 0x0000},
64d6e65bb7SShuming Fan {0x0002, 0x0000},
65d6e65bb7SShuming Fan {0x0004, 0xa000},
66d6e65bb7SShuming Fan {0x0006, 0x0000},
67d6e65bb7SShuming Fan {0x0008, 0x0003},
68d6e65bb7SShuming Fan {0x000a, 0x087e},
69d6e65bb7SShuming Fan {0x000c, 0x0020},
70d6e65bb7SShuming Fan {0x000e, 0x9002},
71d6e65bb7SShuming Fan {0x0010, 0x0000},
72d6e65bb7SShuming Fan {0x0012, 0x0000},
73d6e65bb7SShuming Fan {0x0020, 0x0c40},
74d6e65bb7SShuming Fan {0x0022, 0x4313},
75d6e65bb7SShuming Fan {0x0076, 0x0000},
76d6e65bb7SShuming Fan {0x0078, 0x0000},
77d6e65bb7SShuming Fan {0x007a, 0x0000},
78d6e65bb7SShuming Fan {0x007c, 0x10ec},
79d6e65bb7SShuming Fan {0x007d, 0x1011},
80d6e65bb7SShuming Fan {0x00f0, 0x5000},
81d6e65bb7SShuming Fan {0x00f2, 0x0374},
82d6e65bb7SShuming Fan {0x00f3, 0x0000},
83d6e65bb7SShuming Fan {0x00f4, 0x0000},
84d6e65bb7SShuming Fan {0x0100, 0x0038},
85d6e65bb7SShuming Fan {0x0102, 0xff02},
86d6e65bb7SShuming Fan {0x0104, 0x0232},
87d6e65bb7SShuming Fan {0x0106, 0x200c},
88d6e65bb7SShuming Fan {0x0107, 0x0000},
89d6e65bb7SShuming Fan {0x0108, 0x2f2f},
90d6e65bb7SShuming Fan {0x010a, 0x2f2f},
91d6e65bb7SShuming Fan {0x010c, 0x002f},
92d6e65bb7SShuming Fan {0x010e, 0xe000},
93d6e65bb7SShuming Fan {0x0110, 0x0820},
94d6e65bb7SShuming Fan {0x0111, 0x4010},
95d6e65bb7SShuming Fan {0x0112, 0x0000},
96d6e65bb7SShuming Fan {0x0114, 0x0000},
97d6e65bb7SShuming Fan {0x0116, 0x0000},
98d6e65bb7SShuming Fan {0x0118, 0x0000},
99d6e65bb7SShuming Fan {0x011a, 0x0101},
100d6e65bb7SShuming Fan {0x011c, 0x4567},
101d6e65bb7SShuming Fan {0x011e, 0x0000},
102d6e65bb7SShuming Fan {0x0120, 0x0000},
103d6e65bb7SShuming Fan {0x0122, 0x0000},
104d6e65bb7SShuming Fan {0x0124, 0x0123},
105d6e65bb7SShuming Fan {0x0126, 0x4567},
106d6e65bb7SShuming Fan {0x0200, 0x0000},
107d6e65bb7SShuming Fan {0x0300, 0xffdd},
108d6e65bb7SShuming Fan {0x0302, 0x001e},
109d6e65bb7SShuming Fan {0x0311, 0x0000},
110d6e65bb7SShuming Fan {0x0313, 0x5254},
111d6e65bb7SShuming Fan {0x0314, 0x0062},
112d6e65bb7SShuming Fan {0x0316, 0x7f40},
113d6e65bb7SShuming Fan {0x0319, 0x000f},
114d6e65bb7SShuming Fan {0x031a, 0xffff},
115d6e65bb7SShuming Fan {0x031b, 0x0000},
116d6e65bb7SShuming Fan {0x031c, 0x009f},
117d6e65bb7SShuming Fan {0x031d, 0xffff},
118d6e65bb7SShuming Fan {0x031e, 0x0000},
119d6e65bb7SShuming Fan {0x031f, 0x0000},
120d6e65bb7SShuming Fan {0x0320, 0xe31c},
121d6e65bb7SShuming Fan {0x0321, 0x0000},
122d6e65bb7SShuming Fan {0x0322, 0x0000},
123d6e65bb7SShuming Fan {0x0324, 0x0000},
124d6e65bb7SShuming Fan {0x0326, 0x0002},
125d6e65bb7SShuming Fan {0x0328, 0x20b2},
126d6e65bb7SShuming Fan {0x0329, 0x0175},
127d6e65bb7SShuming Fan {0x032a, 0x32ad},
128d6e65bb7SShuming Fan {0x032b, 0x3455},
129d6e65bb7SShuming Fan {0x032c, 0x0528},
130d6e65bb7SShuming Fan {0x032d, 0xa800},
131d6e65bb7SShuming Fan {0x032e, 0x030e},
132d6e65bb7SShuming Fan {0x0330, 0x2080},
133d6e65bb7SShuming Fan {0x0332, 0x0034},
134d6e65bb7SShuming Fan {0x0334, 0x0000},
135d6e65bb7SShuming Fan {0x0508, 0x0010},
136d6e65bb7SShuming Fan {0x050a, 0x0018},
137d6e65bb7SShuming Fan {0x050c, 0x0000},
138d6e65bb7SShuming Fan {0x050d, 0xffff},
139d6e65bb7SShuming Fan {0x050e, 0x1f1f},
140d6e65bb7SShuming Fan {0x050f, 0x04ff},
141d6e65bb7SShuming Fan {0x0510, 0x4020},
142d6e65bb7SShuming Fan {0x0511, 0x01f0},
143d6e65bb7SShuming Fan {0x0512, 0x0702},
144d6e65bb7SShuming Fan {0x0516, 0xbb80},
145d6e65bb7SShuming Fan {0x0517, 0xffff},
146d6e65bb7SShuming Fan {0x0518, 0xffff},
147d6e65bb7SShuming Fan {0x0519, 0x307f},
148d6e65bb7SShuming Fan {0x051a, 0xffff},
149d6e65bb7SShuming Fan {0x051b, 0x0000},
150d6e65bb7SShuming Fan {0x051c, 0x0000},
151d6e65bb7SShuming Fan {0x051d, 0x2000},
152d6e65bb7SShuming Fan {0x051e, 0x0000},
153d6e65bb7SShuming Fan {0x051f, 0x0000},
154d6e65bb7SShuming Fan {0x0520, 0x0000},
155d6e65bb7SShuming Fan {0x0521, 0x1001},
156d6e65bb7SShuming Fan {0x0522, 0x7fff},
157d6e65bb7SShuming Fan {0x0524, 0x7fff},
158d6e65bb7SShuming Fan {0x0526, 0x0000},
159d6e65bb7SShuming Fan {0x0528, 0x0000},
160d6e65bb7SShuming Fan {0x052a, 0x0000},
161d6e65bb7SShuming Fan {0x0530, 0x0401},
162d6e65bb7SShuming Fan {0x0532, 0x3000},
163d6e65bb7SShuming Fan {0x0534, 0x0000},
164d6e65bb7SShuming Fan {0x0535, 0xffff},
165d6e65bb7SShuming Fan {0x0536, 0x101c},
166d6e65bb7SShuming Fan {0x0538, 0x1814},
167d6e65bb7SShuming Fan {0x053a, 0x100c},
168d6e65bb7SShuming Fan {0x053c, 0x0804},
169d6e65bb7SShuming Fan {0x053d, 0x0000},
170d6e65bb7SShuming Fan {0x053e, 0x0000},
171d6e65bb7SShuming Fan {0x053f, 0x0000},
172d6e65bb7SShuming Fan {0x0540, 0x0000},
173d6e65bb7SShuming Fan {0x0541, 0x0000},
174d6e65bb7SShuming Fan {0x0542, 0x0000},
175d6e65bb7SShuming Fan {0x0543, 0x0000},
176d6e65bb7SShuming Fan {0x0544, 0x001c},
177d6e65bb7SShuming Fan {0x0545, 0x1814},
178d6e65bb7SShuming Fan {0x0546, 0x100c},
179d6e65bb7SShuming Fan {0x0547, 0x0804},
180d6e65bb7SShuming Fan {0x0548, 0x0000},
181d6e65bb7SShuming Fan {0x0549, 0x0000},
182d6e65bb7SShuming Fan {0x054a, 0x0000},
183d6e65bb7SShuming Fan {0x054b, 0x0000},
184d6e65bb7SShuming Fan {0x054c, 0x0000},
185d6e65bb7SShuming Fan {0x054d, 0x0000},
186d6e65bb7SShuming Fan {0x054e, 0x0000},
187d6e65bb7SShuming Fan {0x054f, 0x0000},
188d6e65bb7SShuming Fan {0x0566, 0x0000},
189d6e65bb7SShuming Fan {0x0568, 0x20f1},
190d6e65bb7SShuming Fan {0x056a, 0x0007},
191d6e65bb7SShuming Fan {0x0600, 0x9d00},
192d6e65bb7SShuming Fan {0x0611, 0x2000},
193d6e65bb7SShuming Fan {0x0612, 0x505f},
194d6e65bb7SShuming Fan {0x0613, 0x0444},
195d6e65bb7SShuming Fan {0x0614, 0x4000},
196d6e65bb7SShuming Fan {0x0615, 0x4004},
197d6e65bb7SShuming Fan {0x0616, 0x0606},
198d6e65bb7SShuming Fan {0x0617, 0x8904},
199d6e65bb7SShuming Fan {0x0618, 0xe021},
200d6e65bb7SShuming Fan {0x0621, 0x2000},
201d6e65bb7SShuming Fan {0x0622, 0x505f},
202d6e65bb7SShuming Fan {0x0623, 0x0444},
203d6e65bb7SShuming Fan {0x0624, 0x4000},
204d6e65bb7SShuming Fan {0x0625, 0x4004},
205d6e65bb7SShuming Fan {0x0626, 0x0606},
206d6e65bb7SShuming Fan {0x0627, 0x8704},
207d6e65bb7SShuming Fan {0x0628, 0xe021},
208d6e65bb7SShuming Fan {0x0631, 0x2000},
209d6e65bb7SShuming Fan {0x0632, 0x517f},
210d6e65bb7SShuming Fan {0x0633, 0x0440},
211d6e65bb7SShuming Fan {0x0634, 0x4000},
212d6e65bb7SShuming Fan {0x0635, 0x4104},
213d6e65bb7SShuming Fan {0x0636, 0x0306},
214d6e65bb7SShuming Fan {0x0637, 0x8904},
215d6e65bb7SShuming Fan {0x0638, 0xe021},
216d6e65bb7SShuming Fan {0x0702, 0x0014},
217d6e65bb7SShuming Fan {0x0704, 0x0000},
218d6e65bb7SShuming Fan {0x0706, 0x0014},
219d6e65bb7SShuming Fan {0x0708, 0x0000},
220d6e65bb7SShuming Fan {0x070a, 0x0000},
221d6e65bb7SShuming Fan {0x0710, 0x0200},
222d6e65bb7SShuming Fan {0x0711, 0x0000},
223d6e65bb7SShuming Fan {0x0712, 0x0200},
224d6e65bb7SShuming Fan {0x0713, 0x0000},
225d6e65bb7SShuming Fan {0x0720, 0x0200},
226d6e65bb7SShuming Fan {0x0721, 0x0000},
227d6e65bb7SShuming Fan {0x0722, 0x0000},
228d6e65bb7SShuming Fan {0x0723, 0x0000},
229d6e65bb7SShuming Fan {0x0724, 0x0000},
230d6e65bb7SShuming Fan {0x0725, 0x0000},
231d6e65bb7SShuming Fan {0x0726, 0x0000},
232d6e65bb7SShuming Fan {0x0727, 0x0000},
233d6e65bb7SShuming Fan {0x0728, 0x0000},
234d6e65bb7SShuming Fan {0x0729, 0x0000},
235d6e65bb7SShuming Fan {0x0730, 0x0200},
236d6e65bb7SShuming Fan {0x0731, 0x0000},
237d6e65bb7SShuming Fan {0x0732, 0x0000},
238d6e65bb7SShuming Fan {0x0733, 0x0000},
239d6e65bb7SShuming Fan {0x0734, 0x0000},
240d6e65bb7SShuming Fan {0x0735, 0x0000},
241d6e65bb7SShuming Fan {0x0736, 0x0000},
242d6e65bb7SShuming Fan {0x0737, 0x0000},
243d6e65bb7SShuming Fan {0x0738, 0x0000},
244d6e65bb7SShuming Fan {0x0739, 0x0000},
245d6e65bb7SShuming Fan {0x0740, 0x0200},
246d6e65bb7SShuming Fan {0x0741, 0x0000},
247d6e65bb7SShuming Fan {0x0742, 0x0000},
248d6e65bb7SShuming Fan {0x0743, 0x0000},
249d6e65bb7SShuming Fan {0x0744, 0x0000},
250d6e65bb7SShuming Fan {0x0745, 0x0000},
251d6e65bb7SShuming Fan {0x0746, 0x0000},
252d6e65bb7SShuming Fan {0x0747, 0x0000},
253d6e65bb7SShuming Fan {0x0748, 0x0000},
254d6e65bb7SShuming Fan {0x0749, 0x0000},
255d6e65bb7SShuming Fan {0x0750, 0x0200},
256d6e65bb7SShuming Fan {0x0751, 0x0000},
257d6e65bb7SShuming Fan {0x0752, 0x0000},
258d6e65bb7SShuming Fan {0x0753, 0x0000},
259d6e65bb7SShuming Fan {0x0754, 0x0000},
260d6e65bb7SShuming Fan {0x0755, 0x0000},
261d6e65bb7SShuming Fan {0x0756, 0x0000},
262d6e65bb7SShuming Fan {0x0757, 0x0000},
263d6e65bb7SShuming Fan {0x0758, 0x0000},
264d6e65bb7SShuming Fan {0x0759, 0x0000},
265d6e65bb7SShuming Fan {0x0760, 0x0200},
266d6e65bb7SShuming Fan {0x0761, 0x0000},
267d6e65bb7SShuming Fan {0x0762, 0x0000},
268d6e65bb7SShuming Fan {0x0763, 0x0000},
269d6e65bb7SShuming Fan {0x0764, 0x0000},
270d6e65bb7SShuming Fan {0x0765, 0x0000},
271d6e65bb7SShuming Fan {0x0766, 0x0000},
272d6e65bb7SShuming Fan {0x0767, 0x0000},
273d6e65bb7SShuming Fan {0x0768, 0x0000},
274d6e65bb7SShuming Fan {0x0769, 0x0000},
275d6e65bb7SShuming Fan {0x0770, 0x0200},
276d6e65bb7SShuming Fan {0x0771, 0x0000},
277d6e65bb7SShuming Fan {0x0772, 0x0000},
278d6e65bb7SShuming Fan {0x0773, 0x0000},
279d6e65bb7SShuming Fan {0x0774, 0x0000},
280d6e65bb7SShuming Fan {0x0775, 0x0000},
281d6e65bb7SShuming Fan {0x0776, 0x0000},
282d6e65bb7SShuming Fan {0x0777, 0x0000},
283d6e65bb7SShuming Fan {0x0778, 0x0000},
284d6e65bb7SShuming Fan {0x0779, 0x0000},
285d6e65bb7SShuming Fan {0x0780, 0x0200},
286d6e65bb7SShuming Fan {0x0781, 0x0000},
287d6e65bb7SShuming Fan {0x0782, 0x0000},
288d6e65bb7SShuming Fan {0x0783, 0x0000},
289d6e65bb7SShuming Fan {0x0784, 0x0000},
290d6e65bb7SShuming Fan {0x0785, 0x0000},
291d6e65bb7SShuming Fan {0x0786, 0x0000},
292d6e65bb7SShuming Fan {0x0787, 0x0000},
293d6e65bb7SShuming Fan {0x0788, 0x0000},
294d6e65bb7SShuming Fan {0x0789, 0x0000},
295d6e65bb7SShuming Fan {0x0790, 0x0200},
296d6e65bb7SShuming Fan {0x0791, 0x0000},
297d6e65bb7SShuming Fan {0x0792, 0x0000},
298d6e65bb7SShuming Fan {0x0793, 0x0000},
299d6e65bb7SShuming Fan {0x0794, 0x0000},
300d6e65bb7SShuming Fan {0x0795, 0x0000},
301d6e65bb7SShuming Fan {0x0796, 0x0000},
302d6e65bb7SShuming Fan {0x0797, 0x0000},
303d6e65bb7SShuming Fan {0x0798, 0x0000},
304d6e65bb7SShuming Fan {0x0799, 0x0000},
305d6e65bb7SShuming Fan {0x07a0, 0x0200},
306d6e65bb7SShuming Fan {0x07a1, 0x0000},
307d6e65bb7SShuming Fan {0x07a2, 0x0000},
308d6e65bb7SShuming Fan {0x07a3, 0x0000},
309d6e65bb7SShuming Fan {0x07a4, 0x0000},
310d6e65bb7SShuming Fan {0x07a5, 0x0000},
311d6e65bb7SShuming Fan {0x07a6, 0x0000},
312d6e65bb7SShuming Fan {0x07a7, 0x0000},
313d6e65bb7SShuming Fan {0x07a8, 0x0000},
314d6e65bb7SShuming Fan {0x07a9, 0x0000},
315d6e65bb7SShuming Fan {0x07b0, 0x0200},
316d6e65bb7SShuming Fan {0x07b1, 0x0000},
317d6e65bb7SShuming Fan {0x07b2, 0x0000},
318d6e65bb7SShuming Fan {0x07b3, 0x0000},
319d6e65bb7SShuming Fan {0x07b4, 0x0000},
320d6e65bb7SShuming Fan {0x07b5, 0x0000},
321d6e65bb7SShuming Fan {0x07b6, 0x0000},
322d6e65bb7SShuming Fan {0x07b7, 0x0000},
323d6e65bb7SShuming Fan {0x07b8, 0x0000},
324d6e65bb7SShuming Fan {0x07b9, 0x0000},
325d6e65bb7SShuming Fan {0x07c0, 0x0200},
326d6e65bb7SShuming Fan {0x07c1, 0x0000},
327d6e65bb7SShuming Fan {0x07c2, 0x0000},
328d6e65bb7SShuming Fan {0x07c3, 0x0000},
329d6e65bb7SShuming Fan {0x07c4, 0x0000},
330d6e65bb7SShuming Fan {0x07c5, 0x0000},
331d6e65bb7SShuming Fan {0x07c6, 0x0000},
332d6e65bb7SShuming Fan {0x07c7, 0x0000},
333d6e65bb7SShuming Fan {0x07c8, 0x0000},
334d6e65bb7SShuming Fan {0x07c9, 0x0000},
335d6e65bb7SShuming Fan {0x1000, 0x4040},
336d6e65bb7SShuming Fan {0x1002, 0x6505},
337d6e65bb7SShuming Fan {0x1004, 0x5405},
338d6e65bb7SShuming Fan {0x1006, 0x5555},
339d6e65bb7SShuming Fan {0x1007, 0x003f},
340d6e65bb7SShuming Fan {0x1008, 0x7fd7},
341d6e65bb7SShuming Fan {0x1009, 0x770f},
342d6e65bb7SShuming Fan {0x100a, 0xfffe},
343d6e65bb7SShuming Fan {0x100b, 0xe000},
344d6e65bb7SShuming Fan {0x100c, 0x0000},
345d6e65bb7SShuming Fan {0x100d, 0x0007},
346d6e65bb7SShuming Fan {0x1010, 0xa433},
347d6e65bb7SShuming Fan {0x1020, 0x0000},
348d6e65bb7SShuming Fan {0x1022, 0x0000},
349d6e65bb7SShuming Fan {0x1024, 0x0000},
350d6e65bb7SShuming Fan {0x1200, 0x5a01},
351d6e65bb7SShuming Fan {0x1202, 0x6324},
352d6e65bb7SShuming Fan {0x1204, 0x0b00},
353d6e65bb7SShuming Fan {0x1206, 0x0000},
354d6e65bb7SShuming Fan {0x1208, 0x0000},
355d6e65bb7SShuming Fan {0x120a, 0x0024},
356d6e65bb7SShuming Fan {0x120c, 0x0000},
357d6e65bb7SShuming Fan {0x120e, 0x000e},
358d6e65bb7SShuming Fan {0x1210, 0x0000},
359d6e65bb7SShuming Fan {0x1212, 0x0000},
360d6e65bb7SShuming Fan {0x1300, 0x0701},
361d6e65bb7SShuming Fan {0x1302, 0x12f9},
362d6e65bb7SShuming Fan {0x1304, 0x3405},
363d6e65bb7SShuming Fan {0x1305, 0x0844},
364d6e65bb7SShuming Fan {0x1306, 0x5611},
365d6e65bb7SShuming Fan {0x1308, 0x555e},
366d6e65bb7SShuming Fan {0x130a, 0xa605},
367d6e65bb7SShuming Fan {0x130c, 0x2000},
368d6e65bb7SShuming Fan {0x130e, 0x0000},
369d6e65bb7SShuming Fan {0x130f, 0x0001},
370d6e65bb7SShuming Fan {0x1310, 0xaa48},
371d6e65bb7SShuming Fan {0x1312, 0x0285},
372d6e65bb7SShuming Fan {0x1314, 0xaaaa},
373d6e65bb7SShuming Fan {0x1316, 0xaaa0},
374d6e65bb7SShuming Fan {0x1318, 0x2aaa},
375d6e65bb7SShuming Fan {0x131a, 0xaa07},
376d6e65bb7SShuming Fan {0x1322, 0x0029},
377d6e65bb7SShuming Fan {0x1323, 0x4a52},
378d6e65bb7SShuming Fan {0x1324, 0x002c},
379d6e65bb7SShuming Fan {0x1325, 0x0b02},
380d6e65bb7SShuming Fan {0x1326, 0x002d},
381d6e65bb7SShuming Fan {0x1327, 0x6b5a},
382d6e65bb7SShuming Fan {0x1328, 0x002e},
383d6e65bb7SShuming Fan {0x1329, 0xcbb2},
384d6e65bb7SShuming Fan {0x132a, 0x0030},
385d6e65bb7SShuming Fan {0x132b, 0x2c0b},
386d6e65bb7SShuming Fan {0x1330, 0x0031},
387d6e65bb7SShuming Fan {0x1331, 0x8c63},
388d6e65bb7SShuming Fan {0x1332, 0x0032},
389d6e65bb7SShuming Fan {0x1333, 0xecbb},
390d6e65bb7SShuming Fan {0x1334, 0x0034},
391d6e65bb7SShuming Fan {0x1335, 0x4d13},
392d6e65bb7SShuming Fan {0x1336, 0x0037},
393d6e65bb7SShuming Fan {0x1337, 0x0dc3},
394d6e65bb7SShuming Fan {0x1338, 0x003d},
395d6e65bb7SShuming Fan {0x1339, 0xef7b},
396d6e65bb7SShuming Fan {0x133a, 0x0044},
397d6e65bb7SShuming Fan {0x133b, 0xd134},
398d6e65bb7SShuming Fan {0x133c, 0x0047},
399d6e65bb7SShuming Fan {0x133d, 0x91e4},
400d6e65bb7SShuming Fan {0x133e, 0x004d},
401d6e65bb7SShuming Fan {0x133f, 0xc370},
402d6e65bb7SShuming Fan {0x1340, 0x0053},
403d6e65bb7SShuming Fan {0x1341, 0xf4fd},
404d6e65bb7SShuming Fan {0x1342, 0x0060},
405d6e65bb7SShuming Fan {0x1343, 0x5816},
406d6e65bb7SShuming Fan {0x1344, 0x006c},
407d6e65bb7SShuming Fan {0x1345, 0xbb2e},
408d6e65bb7SShuming Fan {0x1346, 0x0072},
409d6e65bb7SShuming Fan {0x1347, 0xecbb},
410d6e65bb7SShuming Fan {0x1348, 0x0076},
411d6e65bb7SShuming Fan {0x1349, 0x5d97},
412d6e65bb7SShuming Fan {0x1500, 0x0702},
413d6e65bb7SShuming Fan {0x1502, 0x002f},
414d6e65bb7SShuming Fan {0x1504, 0x0000},
415d6e65bb7SShuming Fan {0x1510, 0x0064},
416d6e65bb7SShuming Fan {0x1512, 0x0000},
417d6e65bb7SShuming Fan {0x1514, 0xdf47},
418d6e65bb7SShuming Fan {0x1516, 0x079c},
419d6e65bb7SShuming Fan {0x1518, 0xfbf5},
420d6e65bb7SShuming Fan {0x151a, 0x00bc},
421d6e65bb7SShuming Fan {0x151c, 0x3b85},
422d6e65bb7SShuming Fan {0x151e, 0x02b3},
423d6e65bb7SShuming Fan {0x1520, 0x3333},
424d6e65bb7SShuming Fan {0x1522, 0x0000},
425d6e65bb7SShuming Fan {0x1524, 0x4000},
426d6e65bb7SShuming Fan {0x1528, 0x0064},
427d6e65bb7SShuming Fan {0x152a, 0x0000},
428d6e65bb7SShuming Fan {0x152c, 0x0000},
429d6e65bb7SShuming Fan {0x152e, 0x0000},
430d6e65bb7SShuming Fan {0x1530, 0x0000},
431d6e65bb7SShuming Fan {0x1532, 0x0000},
432d6e65bb7SShuming Fan {0x1534, 0x0000},
433d6e65bb7SShuming Fan {0x1536, 0x0000},
434d6e65bb7SShuming Fan {0x1538, 0x0040},
435d6e65bb7SShuming Fan {0x1539, 0x0000},
436d6e65bb7SShuming Fan {0x153a, 0x0040},
437d6e65bb7SShuming Fan {0x153b, 0x0000},
438d6e65bb7SShuming Fan {0x153c, 0x0064},
439d6e65bb7SShuming Fan {0x153e, 0x0bf9},
440d6e65bb7SShuming Fan {0x1540, 0xb2a9},
441d6e65bb7SShuming Fan {0x1544, 0x0200},
442d6e65bb7SShuming Fan {0x1546, 0x0000},
443d6e65bb7SShuming Fan {0x1548, 0x00ca},
444d6e65bb7SShuming Fan {0x1552, 0x03ff},
445d6e65bb7SShuming Fan {0x1554, 0x017f},
446d6e65bb7SShuming Fan {0x1556, 0x017f},
447d6e65bb7SShuming Fan {0x155a, 0x0000},
448d6e65bb7SShuming Fan {0x155c, 0x0000},
449d6e65bb7SShuming Fan {0x1560, 0x0040},
450d6e65bb7SShuming Fan {0x1562, 0x0000},
451d6e65bb7SShuming Fan {0x1570, 0x03ff},
452d6e65bb7SShuming Fan {0x1571, 0xdcff},
453d6e65bb7SShuming Fan {0x1572, 0x1e00},
454d6e65bb7SShuming Fan {0x1573, 0x224f},
455d6e65bb7SShuming Fan {0x1574, 0x0000},
456d6e65bb7SShuming Fan {0x1575, 0x0000},
457d6e65bb7SShuming Fan {0x1576, 0x1e00},
458d6e65bb7SShuming Fan {0x1577, 0x0000},
459d6e65bb7SShuming Fan {0x1578, 0x0000},
460d6e65bb7SShuming Fan {0x1579, 0x1128},
461d6e65bb7SShuming Fan {0x157a, 0x03ff},
462d6e65bb7SShuming Fan {0x157b, 0xdcff},
463d6e65bb7SShuming Fan {0x157c, 0x1e00},
464d6e65bb7SShuming Fan {0x157d, 0x224f},
465d6e65bb7SShuming Fan {0x157e, 0x0000},
466d6e65bb7SShuming Fan {0x157f, 0x0000},
467d6e65bb7SShuming Fan {0x1580, 0x1e00},
468d6e65bb7SShuming Fan {0x1581, 0x0000},
469d6e65bb7SShuming Fan {0x1582, 0x0000},
470d6e65bb7SShuming Fan {0x1583, 0x1128},
471d6e65bb7SShuming Fan {0x1590, 0x03ff},
472d6e65bb7SShuming Fan {0x1591, 0xdcff},
473d6e65bb7SShuming Fan {0x1592, 0x1e00},
474d6e65bb7SShuming Fan {0x1593, 0x224f},
475d6e65bb7SShuming Fan {0x1594, 0x0000},
476d6e65bb7SShuming Fan {0x1595, 0x0000},
477d6e65bb7SShuming Fan {0x1596, 0x1e00},
478d6e65bb7SShuming Fan {0x1597, 0x0000},
479d6e65bb7SShuming Fan {0x1598, 0x0000},
480d6e65bb7SShuming Fan {0x1599, 0x1128},
481d6e65bb7SShuming Fan {0x159a, 0x03ff},
482d6e65bb7SShuming Fan {0x159b, 0xdcff},
483d6e65bb7SShuming Fan {0x159c, 0x1e00},
484d6e65bb7SShuming Fan {0x159d, 0x224f},
485d6e65bb7SShuming Fan {0x159e, 0x0000},
486d6e65bb7SShuming Fan {0x159f, 0x0000},
487d6e65bb7SShuming Fan {0x15a0, 0x1e00},
488d6e65bb7SShuming Fan {0x15a1, 0x0000},
489d6e65bb7SShuming Fan {0x15a2, 0x0000},
490d6e65bb7SShuming Fan {0x15a3, 0x1128},
491d6e65bb7SShuming Fan {0x15b0, 0x007f},
492d6e65bb7SShuming Fan {0x15b1, 0xffff},
493d6e65bb7SShuming Fan {0x15b2, 0x007f},
494d6e65bb7SShuming Fan {0x15b3, 0xffff},
495d6e65bb7SShuming Fan {0x15b4, 0x007f},
496d6e65bb7SShuming Fan {0x15b5, 0xffff},
497d6e65bb7SShuming Fan {0x15b8, 0x007f},
498d6e65bb7SShuming Fan {0x15b9, 0xffff},
499d6e65bb7SShuming Fan {0x15bc, 0x0000},
500d6e65bb7SShuming Fan {0x15bd, 0x0000},
501d6e65bb7SShuming Fan {0x15be, 0xff00},
502d6e65bb7SShuming Fan {0x15bf, 0x0000},
503d6e65bb7SShuming Fan {0x15c0, 0xff00},
504d6e65bb7SShuming Fan {0x15c1, 0x0000},
505d6e65bb7SShuming Fan {0x15c3, 0xfc00},
506d6e65bb7SShuming Fan {0x15c4, 0xbb80},
507d6e65bb7SShuming Fan {0x15d0, 0x0000},
508d6e65bb7SShuming Fan {0x15d1, 0x0000},
509d6e65bb7SShuming Fan {0x15d2, 0x0000},
510d6e65bb7SShuming Fan {0x15d3, 0x0000},
511d6e65bb7SShuming Fan {0x15d4, 0x0000},
512d6e65bb7SShuming Fan {0x15d5, 0x0000},
513d6e65bb7SShuming Fan {0x15d6, 0x0000},
514d6e65bb7SShuming Fan {0x15d7, 0x0000},
515d6e65bb7SShuming Fan {0x15d8, 0x0200},
516d6e65bb7SShuming Fan {0x15d9, 0x0000},
517d6e65bb7SShuming Fan {0x15da, 0x0000},
518d6e65bb7SShuming Fan {0x15db, 0x0000},
519d6e65bb7SShuming Fan {0x15dc, 0x0000},
520d6e65bb7SShuming Fan {0x15dd, 0x0000},
521d6e65bb7SShuming Fan {0x15de, 0x0000},
522d6e65bb7SShuming Fan {0x15df, 0x0000},
523d6e65bb7SShuming Fan {0x15e0, 0x0000},
524d6e65bb7SShuming Fan {0x15e1, 0x0000},
525d6e65bb7SShuming Fan {0x15e2, 0x0200},
526d6e65bb7SShuming Fan {0x15e3, 0x0000},
527d6e65bb7SShuming Fan {0x15e4, 0x0000},
528d6e65bb7SShuming Fan {0x15e5, 0x0000},
529d6e65bb7SShuming Fan {0x15e6, 0x0000},
530d6e65bb7SShuming Fan {0x15e7, 0x0000},
531d6e65bb7SShuming Fan {0x15e8, 0x0000},
532d6e65bb7SShuming Fan {0x15e9, 0x0000},
533d6e65bb7SShuming Fan {0x15ea, 0x0000},
534d6e65bb7SShuming Fan {0x15eb, 0x0000},
535d6e65bb7SShuming Fan {0x15ec, 0x0200},
536d6e65bb7SShuming Fan {0x15ed, 0x0000},
537d6e65bb7SShuming Fan {0x15ee, 0x0000},
538d6e65bb7SShuming Fan {0x15ef, 0x0000},
539d6e65bb7SShuming Fan {0x15f0, 0x0000},
540d6e65bb7SShuming Fan {0x15f1, 0x0000},
541d6e65bb7SShuming Fan {0x15f2, 0x0000},
542d6e65bb7SShuming Fan {0x15f3, 0x0000},
543d6e65bb7SShuming Fan {0x15f4, 0x0000},
544d6e65bb7SShuming Fan {0x15f5, 0x0000},
545d6e65bb7SShuming Fan {0x15f6, 0x0200},
546d6e65bb7SShuming Fan {0x15f7, 0x0200},
547d6e65bb7SShuming Fan {0x15f8, 0x8200},
548d6e65bb7SShuming Fan {0x15f9, 0x0000},
549d6e65bb7SShuming Fan {0x1600, 0x007d},
550d6e65bb7SShuming Fan {0x1601, 0xa178},
551d6e65bb7SShuming Fan {0x1602, 0x00c2},
552d6e65bb7SShuming Fan {0x1603, 0x5383},
553d6e65bb7SShuming Fan {0x1604, 0x0000},
554d6e65bb7SShuming Fan {0x1605, 0x02c1},
555d6e65bb7SShuming Fan {0x1606, 0x007d},
556d6e65bb7SShuming Fan {0x1607, 0xa178},
557d6e65bb7SShuming Fan {0x1608, 0x00c2},
558d6e65bb7SShuming Fan {0x1609, 0x5383},
559d6e65bb7SShuming Fan {0x160a, 0x003e},
560d6e65bb7SShuming Fan {0x160b, 0xd37d},
561d6e65bb7SShuming Fan {0x1611, 0x3210},
562d6e65bb7SShuming Fan {0x1612, 0x7418},
563d6e65bb7SShuming Fan {0x1613, 0xc0ff},
564d6e65bb7SShuming Fan {0x1614, 0x0000},
565d6e65bb7SShuming Fan {0x1615, 0x00ff},
566d6e65bb7SShuming Fan {0x1616, 0x0000},
567d6e65bb7SShuming Fan {0x1617, 0x0000},
568d6e65bb7SShuming Fan {0x1621, 0x6210},
569d6e65bb7SShuming Fan {0x1622, 0x7418},
570d6e65bb7SShuming Fan {0x1623, 0xc0ff},
571d6e65bb7SShuming Fan {0x1624, 0x0000},
572d6e65bb7SShuming Fan {0x1625, 0x00ff},
573d6e65bb7SShuming Fan {0x1626, 0x0000},
574d6e65bb7SShuming Fan {0x1627, 0x0000},
575d6e65bb7SShuming Fan {0x1631, 0x3a14},
576d6e65bb7SShuming Fan {0x1632, 0x7418},
577d6e65bb7SShuming Fan {0x1633, 0xc3ff},
578d6e65bb7SShuming Fan {0x1634, 0x0000},
579d6e65bb7SShuming Fan {0x1635, 0x00ff},
580d6e65bb7SShuming Fan {0x1636, 0x0000},
581d6e65bb7SShuming Fan {0x1637, 0x0000},
582d6e65bb7SShuming Fan {0x1638, 0x0000},
583d6e65bb7SShuming Fan {0x163a, 0x0000},
584d6e65bb7SShuming Fan {0x163c, 0x0000},
585d6e65bb7SShuming Fan {0x163e, 0x0000},
586d6e65bb7SShuming Fan {0x1640, 0x0000},
587d6e65bb7SShuming Fan {0x1642, 0x0000},
588d6e65bb7SShuming Fan {0x1644, 0x0000},
589d6e65bb7SShuming Fan {0x1646, 0x0000},
590d6e65bb7SShuming Fan {0x1648, 0x0000},
591d6e65bb7SShuming Fan {0x1650, 0x0000},
592d6e65bb7SShuming Fan {0x1652, 0x0000},
593d6e65bb7SShuming Fan {0x1654, 0x0000},
594d6e65bb7SShuming Fan {0x1656, 0x0000},
595d6e65bb7SShuming Fan {0x1658, 0x0000},
596d6e65bb7SShuming Fan {0x1660, 0x0000},
597d6e65bb7SShuming Fan {0x1662, 0x0000},
598d6e65bb7SShuming Fan {0x1664, 0x0000},
599d6e65bb7SShuming Fan {0x1666, 0x0000},
600d6e65bb7SShuming Fan {0x1668, 0x0000},
601d6e65bb7SShuming Fan {0x1670, 0x0000},
602d6e65bb7SShuming Fan {0x1672, 0x0000},
603d6e65bb7SShuming Fan {0x1674, 0x0000},
604d6e65bb7SShuming Fan {0x1676, 0x0000},
605d6e65bb7SShuming Fan {0x1678, 0x0000},
606d6e65bb7SShuming Fan {0x1680, 0x0000},
607d6e65bb7SShuming Fan {0x1682, 0x0000},
608d6e65bb7SShuming Fan {0x1684, 0x0000},
609d6e65bb7SShuming Fan {0x1686, 0x0000},
610d6e65bb7SShuming Fan {0x1688, 0x0000},
611d6e65bb7SShuming Fan {0x1690, 0x0000},
612d6e65bb7SShuming Fan {0x1692, 0x0000},
613d6e65bb7SShuming Fan {0x1694, 0x0000},
614d6e65bb7SShuming Fan {0x1696, 0x0000},
615d6e65bb7SShuming Fan {0x1698, 0x0000},
616d6e65bb7SShuming Fan {0x1700, 0x0000},
617d6e65bb7SShuming Fan {0x1702, 0x0000},
618d6e65bb7SShuming Fan {0x1704, 0x0000},
619d6e65bb7SShuming Fan {0x1706, 0x0000},
620d6e65bb7SShuming Fan {0x1708, 0x0000},
621d6e65bb7SShuming Fan {0x1710, 0x0000},
622d6e65bb7SShuming Fan {0x1712, 0x0000},
623d6e65bb7SShuming Fan {0x1714, 0x0000},
624d6e65bb7SShuming Fan {0x1716, 0x0000},
625d6e65bb7SShuming Fan {0x1718, 0x0000},
626d6e65bb7SShuming Fan {0x1720, 0x0000},
627d6e65bb7SShuming Fan {0x1722, 0x0000},
628d6e65bb7SShuming Fan {0x1724, 0x0000},
629d6e65bb7SShuming Fan {0x1726, 0x0000},
630d6e65bb7SShuming Fan {0x1728, 0x0000},
631d6e65bb7SShuming Fan {0x1730, 0x0000},
632d6e65bb7SShuming Fan {0x1732, 0x0000},
633d6e65bb7SShuming Fan {0x1734, 0x0000},
634d6e65bb7SShuming Fan {0x1736, 0x0000},
635d6e65bb7SShuming Fan {0x1738, 0x0000},
636d6e65bb7SShuming Fan {0x173a, 0x0000},
637d6e65bb7SShuming Fan {0x173c, 0x0000},
638d6e65bb7SShuming Fan {0x173e, 0x0000},
639d6e65bb7SShuming Fan {0x17bb, 0x0500},
640d6e65bb7SShuming Fan {0x17bd, 0x0004},
641d6e65bb7SShuming Fan {0x17bf, 0x0004},
642d6e65bb7SShuming Fan {0x17c1, 0x0004},
643d6e65bb7SShuming Fan {0x17c2, 0x7fff},
644d6e65bb7SShuming Fan {0x17c3, 0x0000},
645d6e65bb7SShuming Fan {0x17c5, 0x0000},
646d6e65bb7SShuming Fan {0x17c7, 0x0000},
647d6e65bb7SShuming Fan {0x17c9, 0x0000},
648d6e65bb7SShuming Fan {0x17cb, 0x2010},
649d6e65bb7SShuming Fan {0x17cd, 0x0000},
650d6e65bb7SShuming Fan {0x17cf, 0x0000},
651d6e65bb7SShuming Fan {0x17d1, 0x0000},
652d6e65bb7SShuming Fan {0x17d3, 0x0000},
653d6e65bb7SShuming Fan {0x17d5, 0x0000},
654d6e65bb7SShuming Fan {0x17d7, 0x0000},
655d6e65bb7SShuming Fan {0x17d9, 0x0000},
656d6e65bb7SShuming Fan {0x17db, 0x0000},
657d6e65bb7SShuming Fan {0x17dd, 0x0000},
658d6e65bb7SShuming Fan {0x17df, 0x0000},
659d6e65bb7SShuming Fan {0x17e1, 0x0000},
660d6e65bb7SShuming Fan {0x17e3, 0x0000},
661d6e65bb7SShuming Fan {0x17e5, 0x0000},
662d6e65bb7SShuming Fan {0x17e7, 0x0000},
663d6e65bb7SShuming Fan {0x17e9, 0x0000},
664d6e65bb7SShuming Fan {0x17eb, 0x0000},
665d6e65bb7SShuming Fan {0x17ed, 0x0000},
666d6e65bb7SShuming Fan {0x17ef, 0x0000},
667d6e65bb7SShuming Fan {0x17f1, 0x0000},
668d6e65bb7SShuming Fan {0x17f3, 0x0000},
669d6e65bb7SShuming Fan {0x17f5, 0x0000},
670d6e65bb7SShuming Fan {0x17f7, 0x0000},
671d6e65bb7SShuming Fan {0x17f9, 0x0000},
672d6e65bb7SShuming Fan {0x17fb, 0x0000},
673d6e65bb7SShuming Fan {0x17fd, 0x0000},
674d6e65bb7SShuming Fan {0x17ff, 0x0000},
675d6e65bb7SShuming Fan {0x1801, 0x0000},
676d6e65bb7SShuming Fan {0x1803, 0x0000},
677d6e65bb7SShuming Fan };
678d6e65bb7SShuming Fan
rt1011_reg_init(struct snd_soc_component * component)679d6e65bb7SShuming Fan static int rt1011_reg_init(struct snd_soc_component *component)
680d6e65bb7SShuming Fan {
681d6e65bb7SShuming Fan struct rt1011_priv *rt1011 = snd_soc_component_get_drvdata(component);
682d6e65bb7SShuming Fan
683683b8515SShuming Fan regmap_multi_reg_write(rt1011->regmap,
684683b8515SShuming Fan init_list, ARRAY_SIZE(init_list));
685d6e65bb7SShuming Fan return 0;
686d6e65bb7SShuming Fan }
687d6e65bb7SShuming Fan
rt1011_volatile_register(struct device * dev,unsigned int reg)688d6e65bb7SShuming Fan static bool rt1011_volatile_register(struct device *dev, unsigned int reg)
689d6e65bb7SShuming Fan {
690d6e65bb7SShuming Fan switch (reg) {
691d6e65bb7SShuming Fan case RT1011_RESET:
692d6e65bb7SShuming Fan case RT1011_SRC_2:
693d6e65bb7SShuming Fan case RT1011_CLK_DET:
694d6e65bb7SShuming Fan case RT1011_SIL_DET:
695d6e65bb7SShuming Fan case RT1011_VERSION_ID:
696d6e65bb7SShuming Fan case RT1011_VENDOR_ID:
697d6e65bb7SShuming Fan case RT1011_DEVICE_ID:
698d6e65bb7SShuming Fan case RT1011_DUM_RO:
699d6e65bb7SShuming Fan case RT1011_DAC_SET_3:
700d6e65bb7SShuming Fan case RT1011_PWM_CAL:
701d6e65bb7SShuming Fan case RT1011_SPK_VOL_TEST_OUT:
702d6e65bb7SShuming Fan case RT1011_VBAT_VOL_DET_1:
703d6e65bb7SShuming Fan case RT1011_VBAT_TEST_OUT_1:
704d6e65bb7SShuming Fan case RT1011_VBAT_TEST_OUT_2:
705d6e65bb7SShuming Fan case RT1011_VBAT_PROTECTION:
706d6e65bb7SShuming Fan case RT1011_VBAT_DET:
707d6e65bb7SShuming Fan case RT1011_BOOST_CON_1:
708d6e65bb7SShuming Fan case RT1011_SHORT_CIRCUIT_DET_1:
709d6e65bb7SShuming Fan case RT1011_SPK_TEMP_PROTECT_3:
710d6e65bb7SShuming Fan case RT1011_SPK_TEMP_PROTECT_6:
711d6e65bb7SShuming Fan case RT1011_SPK_PRO_DC_DET_3:
712d6e65bb7SShuming Fan case RT1011_SPK_PRO_DC_DET_7:
713d6e65bb7SShuming Fan case RT1011_SPK_PRO_DC_DET_8:
714d6e65bb7SShuming Fan case RT1011_SPL_1:
715d6e65bb7SShuming Fan case RT1011_SPL_4:
716d6e65bb7SShuming Fan case RT1011_EXCUR_PROTECT_1:
717d6e65bb7SShuming Fan case RT1011_CROSS_BQ_SET_1:
718d6e65bb7SShuming Fan case RT1011_CROSS_BQ_SET_2:
719d6e65bb7SShuming Fan case RT1011_BQ_SET_0:
720d6e65bb7SShuming Fan case RT1011_BQ_SET_1:
721d6e65bb7SShuming Fan case RT1011_BQ_SET_2:
722d6e65bb7SShuming Fan case RT1011_TEST_PAD_STATUS:
723d6e65bb7SShuming Fan case RT1011_DC_CALIB_CLASSD_1:
724d6e65bb7SShuming Fan case RT1011_DC_CALIB_CLASSD_5:
725d6e65bb7SShuming Fan case RT1011_DC_CALIB_CLASSD_6:
726d6e65bb7SShuming Fan case RT1011_DC_CALIB_CLASSD_7:
727d6e65bb7SShuming Fan case RT1011_DC_CALIB_CLASSD_8:
728d6e65bb7SShuming Fan case RT1011_SINE_GEN_REG_2:
729d6e65bb7SShuming Fan case RT1011_STP_CALIB_RS_TEMP:
730d6e65bb7SShuming Fan case RT1011_SPK_RESISTANCE_1:
731d6e65bb7SShuming Fan case RT1011_SPK_RESISTANCE_2:
732d6e65bb7SShuming Fan case RT1011_SPK_THERMAL:
733d6e65bb7SShuming Fan case RT1011_ALC_BK_GAIN_O:
734d6e65bb7SShuming Fan case RT1011_ALC_BK_GAIN_O_PRE:
735d6e65bb7SShuming Fan case RT1011_SPK_DC_O_23_16:
736d6e65bb7SShuming Fan case RT1011_SPK_DC_O_15_0:
737d6e65bb7SShuming Fan case RT1011_INIT_RECIPROCAL_SYN_24_16:
738d6e65bb7SShuming Fan case RT1011_INIT_RECIPROCAL_SYN_15_0:
739d6e65bb7SShuming Fan case RT1011_SPK_EXCURSION_23_16:
740d6e65bb7SShuming Fan case RT1011_SPK_EXCURSION_15_0:
741d6e65bb7SShuming Fan case RT1011_SEP_MAIN_OUT_23_16:
742d6e65bb7SShuming Fan case RT1011_SEP_MAIN_OUT_15_0:
743d6e65bb7SShuming Fan case RT1011_ALC_DRC_HB_INTERNAL_5:
744d6e65bb7SShuming Fan case RT1011_ALC_DRC_HB_INTERNAL_6:
745d6e65bb7SShuming Fan case RT1011_ALC_DRC_HB_INTERNAL_7:
746d6e65bb7SShuming Fan case RT1011_ALC_DRC_BB_INTERNAL_5:
747d6e65bb7SShuming Fan case RT1011_ALC_DRC_BB_INTERNAL_6:
748d6e65bb7SShuming Fan case RT1011_ALC_DRC_BB_INTERNAL_7:
749d6e65bb7SShuming Fan case RT1011_ALC_DRC_POS_INTERNAL_5:
750d6e65bb7SShuming Fan case RT1011_ALC_DRC_POS_INTERNAL_6:
751d6e65bb7SShuming Fan case RT1011_ALC_DRC_POS_INTERNAL_7:
752d6e65bb7SShuming Fan case RT1011_ALC_DRC_POS_INTERNAL_8:
753d6e65bb7SShuming Fan case RT1011_ALC_DRC_POS_INTERNAL_9:
754d6e65bb7SShuming Fan case RT1011_ALC_DRC_POS_INTERNAL_10:
755d6e65bb7SShuming Fan case RT1011_ALC_DRC_POS_INTERNAL_11:
756d6e65bb7SShuming Fan case RT1011_IRQ_1:
757d6e65bb7SShuming Fan case RT1011_EFUSE_CONTROL_1:
758d6e65bb7SShuming Fan case RT1011_EFUSE_CONTROL_2:
759d6e65bb7SShuming Fan case RT1011_EFUSE_MATCH_DONE ... RT1011_EFUSE_READ_R0_3_15_0:
760d6e65bb7SShuming Fan return true;
761d6e65bb7SShuming Fan
762d6e65bb7SShuming Fan default:
763d6e65bb7SShuming Fan return false;
764d6e65bb7SShuming Fan }
765d6e65bb7SShuming Fan }
766d6e65bb7SShuming Fan
rt1011_readable_register(struct device * dev,unsigned int reg)767d6e65bb7SShuming Fan static bool rt1011_readable_register(struct device *dev, unsigned int reg)
768d6e65bb7SShuming Fan {
769d6e65bb7SShuming Fan switch (reg) {
770d6e65bb7SShuming Fan case RT1011_RESET:
771d6e65bb7SShuming Fan case RT1011_CLK_1:
772d6e65bb7SShuming Fan case RT1011_CLK_2:
773d6e65bb7SShuming Fan case RT1011_CLK_3:
774d6e65bb7SShuming Fan case RT1011_CLK_4:
775d6e65bb7SShuming Fan case RT1011_PLL_1:
776d6e65bb7SShuming Fan case RT1011_PLL_2:
777d6e65bb7SShuming Fan case RT1011_SRC_1:
778d6e65bb7SShuming Fan case RT1011_SRC_2:
779d6e65bb7SShuming Fan case RT1011_SRC_3:
780d6e65bb7SShuming Fan case RT1011_CLK_DET:
781d6e65bb7SShuming Fan case RT1011_SIL_DET:
782d6e65bb7SShuming Fan case RT1011_PRIV_INDEX:
783d6e65bb7SShuming Fan case RT1011_PRIV_DATA:
784d6e65bb7SShuming Fan case RT1011_CUSTOMER_ID:
785d6e65bb7SShuming Fan case RT1011_FM_VER:
786d6e65bb7SShuming Fan case RT1011_VERSION_ID:
787d6e65bb7SShuming Fan case RT1011_VENDOR_ID:
788d6e65bb7SShuming Fan case RT1011_DEVICE_ID:
789d6e65bb7SShuming Fan case RT1011_DUM_RW_0:
790d6e65bb7SShuming Fan case RT1011_DUM_YUN:
791d6e65bb7SShuming Fan case RT1011_DUM_RW_1:
792d6e65bb7SShuming Fan case RT1011_DUM_RO:
793d6e65bb7SShuming Fan case RT1011_MAN_I2C_DEV:
794d6e65bb7SShuming Fan case RT1011_DAC_SET_1:
795d6e65bb7SShuming Fan case RT1011_DAC_SET_2:
796d6e65bb7SShuming Fan case RT1011_DAC_SET_3:
797d6e65bb7SShuming Fan case RT1011_ADC_SET:
798d6e65bb7SShuming Fan case RT1011_ADC_SET_1:
799d6e65bb7SShuming Fan case RT1011_ADC_SET_2:
800d6e65bb7SShuming Fan case RT1011_ADC_SET_3:
801d6e65bb7SShuming Fan case RT1011_ADC_SET_4:
802d6e65bb7SShuming Fan case RT1011_ADC_SET_5:
803d6e65bb7SShuming Fan case RT1011_TDM_TOTAL_SET:
804d6e65bb7SShuming Fan case RT1011_TDM1_SET_TCON:
805d6e65bb7SShuming Fan case RT1011_TDM1_SET_1:
806d6e65bb7SShuming Fan case RT1011_TDM1_SET_2:
807d6e65bb7SShuming Fan case RT1011_TDM1_SET_3:
808d6e65bb7SShuming Fan case RT1011_TDM1_SET_4:
809d6e65bb7SShuming Fan case RT1011_TDM1_SET_5:
810d6e65bb7SShuming Fan case RT1011_TDM2_SET_1:
811d6e65bb7SShuming Fan case RT1011_TDM2_SET_2:
812d6e65bb7SShuming Fan case RT1011_TDM2_SET_3:
813d6e65bb7SShuming Fan case RT1011_TDM2_SET_4:
814d6e65bb7SShuming Fan case RT1011_TDM2_SET_5:
815d6e65bb7SShuming Fan case RT1011_PWM_CAL:
816d6e65bb7SShuming Fan case RT1011_MIXER_1:
817d6e65bb7SShuming Fan case RT1011_MIXER_2:
818d6e65bb7SShuming Fan case RT1011_ADRC_LIMIT:
819d6e65bb7SShuming Fan case RT1011_A_PRO:
820d6e65bb7SShuming Fan case RT1011_A_TIMING_1:
821d6e65bb7SShuming Fan case RT1011_A_TIMING_2:
822d6e65bb7SShuming Fan case RT1011_A_TEMP_SEN:
823d6e65bb7SShuming Fan case RT1011_SPK_VOL_DET_1:
824d6e65bb7SShuming Fan case RT1011_SPK_VOL_DET_2:
825d6e65bb7SShuming Fan case RT1011_SPK_VOL_TEST_OUT:
826d6e65bb7SShuming Fan case RT1011_VBAT_VOL_DET_1:
827d6e65bb7SShuming Fan case RT1011_VBAT_VOL_DET_2:
828d6e65bb7SShuming Fan case RT1011_VBAT_TEST_OUT_1:
829d6e65bb7SShuming Fan case RT1011_VBAT_TEST_OUT_2:
830d6e65bb7SShuming Fan case RT1011_VBAT_PROTECTION:
831d6e65bb7SShuming Fan case RT1011_VBAT_DET:
832d6e65bb7SShuming Fan case RT1011_POWER_1:
833d6e65bb7SShuming Fan case RT1011_POWER_2:
834d6e65bb7SShuming Fan case RT1011_POWER_3:
835d6e65bb7SShuming Fan case RT1011_POWER_4:
836d6e65bb7SShuming Fan case RT1011_POWER_5:
837d6e65bb7SShuming Fan case RT1011_POWER_6:
838d6e65bb7SShuming Fan case RT1011_POWER_7:
839d6e65bb7SShuming Fan case RT1011_POWER_8:
840d6e65bb7SShuming Fan case RT1011_POWER_9:
841d6e65bb7SShuming Fan case RT1011_CLASS_D_POS:
842d6e65bb7SShuming Fan case RT1011_BOOST_CON_1:
843d6e65bb7SShuming Fan case RT1011_BOOST_CON_2:
844d6e65bb7SShuming Fan case RT1011_ANALOG_CTRL:
845d6e65bb7SShuming Fan case RT1011_POWER_SEQ:
846d6e65bb7SShuming Fan case RT1011_SHORT_CIRCUIT_DET_1:
847d6e65bb7SShuming Fan case RT1011_SHORT_CIRCUIT_DET_2:
848d6e65bb7SShuming Fan case RT1011_SPK_TEMP_PROTECT_0:
849d6e65bb7SShuming Fan case RT1011_SPK_TEMP_PROTECT_1:
850d6e65bb7SShuming Fan case RT1011_SPK_TEMP_PROTECT_2:
851d6e65bb7SShuming Fan case RT1011_SPK_TEMP_PROTECT_3:
852d6e65bb7SShuming Fan case RT1011_SPK_TEMP_PROTECT_4:
853d6e65bb7SShuming Fan case RT1011_SPK_TEMP_PROTECT_5:
854d6e65bb7SShuming Fan case RT1011_SPK_TEMP_PROTECT_6:
855d6e65bb7SShuming Fan case RT1011_SPK_TEMP_PROTECT_7:
856d6e65bb7SShuming Fan case RT1011_SPK_TEMP_PROTECT_8:
857d6e65bb7SShuming Fan case RT1011_SPK_TEMP_PROTECT_9:
858d6e65bb7SShuming Fan case RT1011_SPK_PRO_DC_DET_1:
859d6e65bb7SShuming Fan case RT1011_SPK_PRO_DC_DET_2:
860d6e65bb7SShuming Fan case RT1011_SPK_PRO_DC_DET_3:
861d6e65bb7SShuming Fan case RT1011_SPK_PRO_DC_DET_4:
862d6e65bb7SShuming Fan case RT1011_SPK_PRO_DC_DET_5:
863d6e65bb7SShuming Fan case RT1011_SPK_PRO_DC_DET_6:
864d6e65bb7SShuming Fan case RT1011_SPK_PRO_DC_DET_7:
865d6e65bb7SShuming Fan case RT1011_SPK_PRO_DC_DET_8:
866d6e65bb7SShuming Fan case RT1011_SPL_1:
867d6e65bb7SShuming Fan case RT1011_SPL_2:
868d6e65bb7SShuming Fan case RT1011_SPL_3:
869d6e65bb7SShuming Fan case RT1011_SPL_4:
870d6e65bb7SShuming Fan case RT1011_THER_FOLD_BACK_1:
871d6e65bb7SShuming Fan case RT1011_THER_FOLD_BACK_2:
872d6e65bb7SShuming Fan case RT1011_EXCUR_PROTECT_1:
873d6e65bb7SShuming Fan case RT1011_EXCUR_PROTECT_2:
874d6e65bb7SShuming Fan case RT1011_EXCUR_PROTECT_3:
875d6e65bb7SShuming Fan case RT1011_EXCUR_PROTECT_4:
876d6e65bb7SShuming Fan case RT1011_BAT_GAIN_1:
877d6e65bb7SShuming Fan case RT1011_BAT_GAIN_2:
878d6e65bb7SShuming Fan case RT1011_BAT_GAIN_3:
879d6e65bb7SShuming Fan case RT1011_BAT_GAIN_4:
880d6e65bb7SShuming Fan case RT1011_BAT_GAIN_5:
881d6e65bb7SShuming Fan case RT1011_BAT_GAIN_6:
882d6e65bb7SShuming Fan case RT1011_BAT_GAIN_7:
883d6e65bb7SShuming Fan case RT1011_BAT_GAIN_8:
884d6e65bb7SShuming Fan case RT1011_BAT_GAIN_9:
885d6e65bb7SShuming Fan case RT1011_BAT_GAIN_10:
886d6e65bb7SShuming Fan case RT1011_BAT_GAIN_11:
887d6e65bb7SShuming Fan case RT1011_BAT_RT_THMAX_1:
888d6e65bb7SShuming Fan case RT1011_BAT_RT_THMAX_2:
889d6e65bb7SShuming Fan case RT1011_BAT_RT_THMAX_3:
890d6e65bb7SShuming Fan case RT1011_BAT_RT_THMAX_4:
891d6e65bb7SShuming Fan case RT1011_BAT_RT_THMAX_5:
892d6e65bb7SShuming Fan case RT1011_BAT_RT_THMAX_6:
893d6e65bb7SShuming Fan case RT1011_BAT_RT_THMAX_7:
894d6e65bb7SShuming Fan case RT1011_BAT_RT_THMAX_8:
895d6e65bb7SShuming Fan case RT1011_BAT_RT_THMAX_9:
896d6e65bb7SShuming Fan case RT1011_BAT_RT_THMAX_10:
897d6e65bb7SShuming Fan case RT1011_BAT_RT_THMAX_11:
898d6e65bb7SShuming Fan case RT1011_BAT_RT_THMAX_12:
899d6e65bb7SShuming Fan case RT1011_SPREAD_SPECTURM:
900d6e65bb7SShuming Fan case RT1011_PRO_GAIN_MODE:
901d6e65bb7SShuming Fan case RT1011_RT_DRC_CROSS:
902d6e65bb7SShuming Fan case RT1011_RT_DRC_HB_1:
903d6e65bb7SShuming Fan case RT1011_RT_DRC_HB_2:
904d6e65bb7SShuming Fan case RT1011_RT_DRC_HB_3:
905d6e65bb7SShuming Fan case RT1011_RT_DRC_HB_4:
906d6e65bb7SShuming Fan case RT1011_RT_DRC_HB_5:
907d6e65bb7SShuming Fan case RT1011_RT_DRC_HB_6:
908d6e65bb7SShuming Fan case RT1011_RT_DRC_HB_7:
909d6e65bb7SShuming Fan case RT1011_RT_DRC_HB_8:
910d6e65bb7SShuming Fan case RT1011_RT_DRC_BB_1:
911d6e65bb7SShuming Fan case RT1011_RT_DRC_BB_2:
912d6e65bb7SShuming Fan case RT1011_RT_DRC_BB_3:
913d6e65bb7SShuming Fan case RT1011_RT_DRC_BB_4:
914d6e65bb7SShuming Fan case RT1011_RT_DRC_BB_5:
915d6e65bb7SShuming Fan case RT1011_RT_DRC_BB_6:
916d6e65bb7SShuming Fan case RT1011_RT_DRC_BB_7:
917d6e65bb7SShuming Fan case RT1011_RT_DRC_BB_8:
918d6e65bb7SShuming Fan case RT1011_RT_DRC_POS_1:
919d6e65bb7SShuming Fan case RT1011_RT_DRC_POS_2:
920d6e65bb7SShuming Fan case RT1011_RT_DRC_POS_3:
921d6e65bb7SShuming Fan case RT1011_RT_DRC_POS_4:
922d6e65bb7SShuming Fan case RT1011_RT_DRC_POS_5:
923d6e65bb7SShuming Fan case RT1011_RT_DRC_POS_6:
924d6e65bb7SShuming Fan case RT1011_RT_DRC_POS_7:
925d6e65bb7SShuming Fan case RT1011_RT_DRC_POS_8:
926d6e65bb7SShuming Fan case RT1011_CROSS_BQ_SET_1:
927d6e65bb7SShuming Fan case RT1011_CROSS_BQ_SET_2:
928d6e65bb7SShuming Fan case RT1011_BQ_SET_0:
929d6e65bb7SShuming Fan case RT1011_BQ_SET_1:
930d6e65bb7SShuming Fan case RT1011_BQ_SET_2:
931d6e65bb7SShuming Fan case RT1011_BQ_PRE_GAIN_28_16:
932d6e65bb7SShuming Fan case RT1011_BQ_PRE_GAIN_15_0:
933d6e65bb7SShuming Fan case RT1011_BQ_POST_GAIN_28_16:
934d6e65bb7SShuming Fan case RT1011_BQ_POST_GAIN_15_0:
935d6e65bb7SShuming Fan case RT1011_BQ_H0_28_16 ... RT1011_BQ_A2_15_0:
936d6e65bb7SShuming Fan case RT1011_BQ_1_H0_28_16 ... RT1011_BQ_1_A2_15_0:
937d6e65bb7SShuming Fan case RT1011_BQ_2_H0_28_16 ... RT1011_BQ_2_A2_15_0:
938d6e65bb7SShuming Fan case RT1011_BQ_3_H0_28_16 ... RT1011_BQ_3_A2_15_0:
939d6e65bb7SShuming Fan case RT1011_BQ_4_H0_28_16 ... RT1011_BQ_4_A2_15_0:
940d6e65bb7SShuming Fan case RT1011_BQ_5_H0_28_16 ... RT1011_BQ_5_A2_15_0:
941d6e65bb7SShuming Fan case RT1011_BQ_6_H0_28_16 ... RT1011_BQ_6_A2_15_0:
942d6e65bb7SShuming Fan case RT1011_BQ_7_H0_28_16 ... RT1011_BQ_7_A2_15_0:
943d6e65bb7SShuming Fan case RT1011_BQ_8_H0_28_16 ... RT1011_BQ_8_A2_15_0:
944d6e65bb7SShuming Fan case RT1011_BQ_9_H0_28_16 ... RT1011_BQ_9_A2_15_0:
945d6e65bb7SShuming Fan case RT1011_BQ_10_H0_28_16 ... RT1011_BQ_10_A2_15_0:
946d6e65bb7SShuming Fan case RT1011_TEST_PAD_STATUS ... RT1011_PLL_INTERNAL_SET:
947d6e65bb7SShuming Fan case RT1011_TEST_OUT_1 ... RT1011_TEST_OUT_3:
948d6e65bb7SShuming Fan case RT1011_DC_CALIB_CLASSD_1 ... RT1011_DC_CALIB_CLASSD_10:
949d6e65bb7SShuming Fan case RT1011_CLASSD_INTERNAL_SET_1 ... RT1011_VREF_LV_1:
950d6e65bb7SShuming Fan case RT1011_SMART_BOOST_TIMING_1 ... RT1011_SMART_BOOST_TIMING_36:
951d6e65bb7SShuming Fan case RT1011_SINE_GEN_REG_1 ... RT1011_SINE_GEN_REG_3:
952d6e65bb7SShuming Fan case RT1011_STP_INITIAL_RS_TEMP ... RT1011_SPK_THERMAL:
953d6e65bb7SShuming Fan case RT1011_STP_OTP_TH ... RT1011_INIT_RECIPROCAL_SYN_15_0:
954d6e65bb7SShuming Fan case RT1011_STP_BQ_1_A1_L_28_16 ... RT1011_STP_BQ_1_H0_R_15_0:
955d6e65bb7SShuming Fan case RT1011_STP_BQ_2_A1_L_28_16 ... RT1011_SEP_RE_REG_15_0:
956d6e65bb7SShuming Fan case RT1011_DRC_CF_PARAMS_1 ... RT1011_DRC_CF_PARAMS_12:
957d6e65bb7SShuming Fan case RT1011_ALC_DRC_HB_INTERNAL_1 ... RT1011_ALC_DRC_HB_INTERNAL_7:
958d6e65bb7SShuming Fan case RT1011_ALC_DRC_BB_INTERNAL_1 ... RT1011_ALC_DRC_BB_INTERNAL_7:
959d6e65bb7SShuming Fan case RT1011_ALC_DRC_POS_INTERNAL_1 ... RT1011_ALC_DRC_POS_INTERNAL_8:
960d6e65bb7SShuming Fan case RT1011_ALC_DRC_POS_INTERNAL_9 ... RT1011_BQ_1_PARAMS_CHECK_5:
961d6e65bb7SShuming Fan case RT1011_BQ_2_PARAMS_CHECK_1 ... RT1011_BQ_2_PARAMS_CHECK_5:
962d6e65bb7SShuming Fan case RT1011_BQ_3_PARAMS_CHECK_1 ... RT1011_BQ_3_PARAMS_CHECK_5:
963d6e65bb7SShuming Fan case RT1011_BQ_4_PARAMS_CHECK_1 ... RT1011_BQ_4_PARAMS_CHECK_5:
964d6e65bb7SShuming Fan case RT1011_BQ_5_PARAMS_CHECK_1 ... RT1011_BQ_5_PARAMS_CHECK_5:
965d6e65bb7SShuming Fan case RT1011_BQ_6_PARAMS_CHECK_1 ... RT1011_BQ_6_PARAMS_CHECK_5:
966d6e65bb7SShuming Fan case RT1011_BQ_7_PARAMS_CHECK_1 ... RT1011_BQ_7_PARAMS_CHECK_5:
967d6e65bb7SShuming Fan case RT1011_BQ_8_PARAMS_CHECK_1 ... RT1011_BQ_8_PARAMS_CHECK_5:
968d6e65bb7SShuming Fan case RT1011_BQ_9_PARAMS_CHECK_1 ... RT1011_BQ_9_PARAMS_CHECK_5:
969d6e65bb7SShuming Fan case RT1011_BQ_10_PARAMS_CHECK_1 ... RT1011_BQ_10_PARAMS_CHECK_5:
970d6e65bb7SShuming Fan case RT1011_IRQ_1 ... RT1011_PART_NUMBER_EFUSE:
971d6e65bb7SShuming Fan case RT1011_EFUSE_CONTROL_1 ... RT1011_EFUSE_READ_R0_3_15_0:
972d6e65bb7SShuming Fan return true;
973d6e65bb7SShuming Fan default:
974d6e65bb7SShuming Fan return false;
975d6e65bb7SShuming Fan }
976d6e65bb7SShuming Fan }
977d6e65bb7SShuming Fan
978d6e65bb7SShuming Fan static const char * const rt1011_din_source_select[] = {
979d6e65bb7SShuming Fan "Left",
980d6e65bb7SShuming Fan "Right",
981d6e65bb7SShuming Fan "Left + Right average",
982d6e65bb7SShuming Fan };
983d6e65bb7SShuming Fan
984d6e65bb7SShuming Fan static SOC_ENUM_SINGLE_DECL(rt1011_din_source_enum, RT1011_CROSS_BQ_SET_1, 5,
985d6e65bb7SShuming Fan rt1011_din_source_select);
986d6e65bb7SShuming Fan
987d6e65bb7SShuming Fan static const char * const rt1011_tdm_data_out_select[] = {
988d6e65bb7SShuming Fan "TDM_O_LR", "BQ1", "DVOL", "BQ10", "ALC", "DMIX", "ADC_SRC_LR",
989d6e65bb7SShuming Fan "ADC_O_LR", "ADC_MONO", "RSPK_BPF_LR", "DMIX_ADD", "ENVELOPE_FS",
990d6e65bb7SShuming Fan "SEP_O_GAIN", "ALC_BK_GAIN", "STP_V_C", "DMIX_ABST"
991d6e65bb7SShuming Fan };
992d6e65bb7SShuming Fan
993d6e65bb7SShuming Fan static const char * const rt1011_tdm_l_ch_data_select[] = {
994d6e65bb7SShuming Fan "Slot0", "Slot1", "Slot2", "Slot3", "Slot4", "Slot5", "Slot6", "Slot7"
995d6e65bb7SShuming Fan };
996d6e65bb7SShuming Fan static SOC_ENUM_SINGLE_DECL(rt1011_tdm1_l_dac1_enum, RT1011_TDM1_SET_4, 12,
997d6e65bb7SShuming Fan rt1011_tdm_l_ch_data_select);
998d6e65bb7SShuming Fan static SOC_ENUM_SINGLE_DECL(rt1011_tdm2_l_dac1_enum, RT1011_TDM2_SET_4, 12,
999d6e65bb7SShuming Fan rt1011_tdm_l_ch_data_select);
1000d6e65bb7SShuming Fan
1001d6e65bb7SShuming Fan static SOC_ENUM_SINGLE_DECL(rt1011_tdm1_adc1_dat_enum,
1002d6e65bb7SShuming Fan RT1011_ADCDAT_OUT_SOURCE, 0, rt1011_tdm_data_out_select);
1003d6e65bb7SShuming Fan static SOC_ENUM_SINGLE_DECL(rt1011_tdm1_adc1_loc_enum, RT1011_TDM1_SET_2, 0,
1004d6e65bb7SShuming Fan rt1011_tdm_l_ch_data_select);
1005d6e65bb7SShuming Fan
1006d6e65bb7SShuming Fan static const char * const rt1011_adc_data_mode_select[] = {
1007d6e65bb7SShuming Fan "Stereo", "Mono"
1008d6e65bb7SShuming Fan };
1009d6e65bb7SShuming Fan static SOC_ENUM_SINGLE_DECL(rt1011_adc_dout_mode_enum, RT1011_TDM1_SET_1, 12,
1010d6e65bb7SShuming Fan rt1011_adc_data_mode_select);
1011d6e65bb7SShuming Fan
1012d6e65bb7SShuming Fan static const char * const rt1011_tdm_adc_data_len_control[] = {
1013d6e65bb7SShuming Fan "1CH", "2CH", "3CH", "4CH", "5CH", "6CH", "7CH", "8CH"
1014d6e65bb7SShuming Fan };
1015d6e65bb7SShuming Fan static SOC_ENUM_SINGLE_DECL(rt1011_tdm1_dout_len_enum, RT1011_TDM1_SET_2, 13,
1016d6e65bb7SShuming Fan rt1011_tdm_adc_data_len_control);
1017d6e65bb7SShuming Fan static SOC_ENUM_SINGLE_DECL(rt1011_tdm2_dout_len_enum, RT1011_TDM2_SET_2, 13,
1018d6e65bb7SShuming Fan rt1011_tdm_adc_data_len_control);
1019d6e65bb7SShuming Fan
1020d6e65bb7SShuming Fan static const char * const rt1011_tdm_adc_swap_select[] = {
1021d6e65bb7SShuming Fan "L/R", "R/L", "L/L", "R/R"
1022d6e65bb7SShuming Fan };
1023d6e65bb7SShuming Fan
1024d6e65bb7SShuming Fan static SOC_ENUM_SINGLE_DECL(rt1011_tdm_adc1_1_enum, RT1011_TDM1_SET_3, 6,
1025d6e65bb7SShuming Fan rt1011_tdm_adc_swap_select);
10263403b808SShuming Fan static SOC_ENUM_SINGLE_DECL(rt1011_tdm_adc2_1_enum, RT1011_TDM1_SET_3, 4,
10273403b808SShuming Fan rt1011_tdm_adc_swap_select);
1028d6e65bb7SShuming Fan
rt1011_reset(struct regmap * regmap)1029d6e65bb7SShuming Fan static void rt1011_reset(struct regmap *regmap)
1030d6e65bb7SShuming Fan {
1031d6e65bb7SShuming Fan regmap_write(regmap, RT1011_RESET, 0);
1032d6e65bb7SShuming Fan }
1033d6e65bb7SShuming Fan
rt1011_recv_spk_mode_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1034d6e65bb7SShuming Fan static int rt1011_recv_spk_mode_get(struct snd_kcontrol *kcontrol,
1035d6e65bb7SShuming Fan struct snd_ctl_elem_value *ucontrol)
1036d6e65bb7SShuming Fan {
1037d6e65bb7SShuming Fan struct snd_soc_component *component =
1038d6e65bb7SShuming Fan snd_soc_kcontrol_component(kcontrol);
1039d6e65bb7SShuming Fan struct rt1011_priv *rt1011 =
1040d6e65bb7SShuming Fan snd_soc_component_get_drvdata(component);
1041d6e65bb7SShuming Fan
1042d6e65bb7SShuming Fan ucontrol->value.integer.value[0] = rt1011->recv_spk_mode;
1043d6e65bb7SShuming Fan
1044d6e65bb7SShuming Fan return 0;
1045d6e65bb7SShuming Fan }
1046d6e65bb7SShuming Fan
rt1011_recv_spk_mode_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1047d6e65bb7SShuming Fan static int rt1011_recv_spk_mode_put(struct snd_kcontrol *kcontrol,
1048d6e65bb7SShuming Fan struct snd_ctl_elem_value *ucontrol)
1049d6e65bb7SShuming Fan {
1050d6e65bb7SShuming Fan struct snd_soc_component *component =
1051d6e65bb7SShuming Fan snd_soc_kcontrol_component(kcontrol);
1052d6e65bb7SShuming Fan struct rt1011_priv *rt1011 =
1053d6e65bb7SShuming Fan snd_soc_component_get_drvdata(component);
1054d6e65bb7SShuming Fan
1055d6e65bb7SShuming Fan if (ucontrol->value.integer.value[0] == rt1011->recv_spk_mode)
1056d6e65bb7SShuming Fan return 0;
1057d6e65bb7SShuming Fan
1058d6e65bb7SShuming Fan if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_OFF) {
1059d6e65bb7SShuming Fan rt1011->recv_spk_mode = ucontrol->value.integer.value[0];
1060d6e65bb7SShuming Fan
1061d6e65bb7SShuming Fan if (rt1011->recv_spk_mode) {
1062d6e65bb7SShuming Fan
1063d6e65bb7SShuming Fan /* 1: recevier mode on */
1064d6e65bb7SShuming Fan snd_soc_component_update_bits(component,
1065d6e65bb7SShuming Fan RT1011_CLASSD_INTERNAL_SET_3,
1066d6e65bb7SShuming Fan RT1011_REG_GAIN_CLASSD_RI_SPK_MASK,
1067d6e65bb7SShuming Fan RT1011_REG_GAIN_CLASSD_RI_410K);
1068d6e65bb7SShuming Fan snd_soc_component_update_bits(component,
1069d6e65bb7SShuming Fan RT1011_CLASSD_INTERNAL_SET_1,
1070d6e65bb7SShuming Fan RT1011_RECV_MODE_SPK_MASK,
1071d6e65bb7SShuming Fan RT1011_RECV_MODE);
1072d6e65bb7SShuming Fan } else {
1073d6e65bb7SShuming Fan /* 0: speaker mode on */
1074d6e65bb7SShuming Fan snd_soc_component_update_bits(component,
1075d6e65bb7SShuming Fan RT1011_CLASSD_INTERNAL_SET_3,
1076d6e65bb7SShuming Fan RT1011_REG_GAIN_CLASSD_RI_SPK_MASK,
1077d6e65bb7SShuming Fan RT1011_REG_GAIN_CLASSD_RI_72P5K);
1078d6e65bb7SShuming Fan snd_soc_component_update_bits(component,
1079d6e65bb7SShuming Fan RT1011_CLASSD_INTERNAL_SET_1,
1080d6e65bb7SShuming Fan RT1011_RECV_MODE_SPK_MASK,
1081d6e65bb7SShuming Fan RT1011_SPK_MODE);
1082d6e65bb7SShuming Fan }
1083d6e65bb7SShuming Fan }
1084d6e65bb7SShuming Fan
1085d6e65bb7SShuming Fan return 0;
1086d6e65bb7SShuming Fan }
1087d6e65bb7SShuming Fan
rt1011_validate_bq_drc_coeff(unsigned short reg)1088d6e65bb7SShuming Fan static bool rt1011_validate_bq_drc_coeff(unsigned short reg)
1089d6e65bb7SShuming Fan {
1090f7c5c168SPierre-Louis Bossart if ((reg == RT1011_DAC_SET_1) ||
1091f7c5c168SPierre-Louis Bossart (reg >= RT1011_ADC_SET && reg <= RT1011_ADC_SET_1) ||
1092f7c5c168SPierre-Louis Bossart (reg == RT1011_ADC_SET_4) || (reg == RT1011_ADC_SET_5) ||
1093f7c5c168SPierre-Louis Bossart (reg == RT1011_MIXER_1) ||
1094f7c5c168SPierre-Louis Bossart (reg == RT1011_A_TIMING_1) ||
1095f7c5c168SPierre-Louis Bossart (reg >= RT1011_POWER_7 && reg <= RT1011_POWER_8) ||
1096f7c5c168SPierre-Louis Bossart (reg == RT1011_CLASS_D_POS) || (reg == RT1011_ANALOG_CTRL) ||
1097f7c5c168SPierre-Louis Bossart (reg >= RT1011_SPK_TEMP_PROTECT_0 && reg <= RT1011_SPK_TEMP_PROTECT_6) ||
1098f7c5c168SPierre-Louis Bossart (reg >= RT1011_SPK_PRO_DC_DET_5 && reg <= RT1011_BAT_GAIN_1) ||
1099f7c5c168SPierre-Louis Bossart (reg >= RT1011_RT_DRC_CROSS && reg <= RT1011_RT_DRC_POS_8) ||
1100f7c5c168SPierre-Louis Bossart (reg >= RT1011_CROSS_BQ_SET_1 && reg <= RT1011_BQ_10_A2_15_0) ||
1101f7c5c168SPierre-Louis Bossart (reg >= RT1011_SMART_BOOST_TIMING_1 && reg <= RT1011_SMART_BOOST_TIMING_36) ||
1102f7c5c168SPierre-Louis Bossart (reg == RT1011_SINE_GEN_REG_1) ||
1103f7c5c168SPierre-Louis Bossart (reg >= RT1011_STP_ALPHA_RECIPROCAL_MSB && reg <= RT1011_BQ_6_PARAMS_CHECK_5) ||
1104f7c5c168SPierre-Louis Bossart (reg >= RT1011_BQ_7_PARAMS_CHECK_1 && reg <= RT1011_BQ_10_PARAMS_CHECK_5))
1105d6e65bb7SShuming Fan return true;
1106d6e65bb7SShuming Fan
1107d6e65bb7SShuming Fan return false;
1108d6e65bb7SShuming Fan }
1109d6e65bb7SShuming Fan
rt1011_bq_drc_coeff_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1110d6e65bb7SShuming Fan static int rt1011_bq_drc_coeff_get(struct snd_kcontrol *kcontrol,
1111d6e65bb7SShuming Fan struct snd_ctl_elem_value *ucontrol)
1112d6e65bb7SShuming Fan {
1113d6e65bb7SShuming Fan struct snd_soc_component *component =
1114d6e65bb7SShuming Fan snd_soc_kcontrol_component(kcontrol);
1115d6e65bb7SShuming Fan struct rt1011_priv *rt1011 =
1116d6e65bb7SShuming Fan snd_soc_component_get_drvdata(component);
1117d6e65bb7SShuming Fan struct rt1011_bq_drc_params *bq_drc_info;
1118d6e65bb7SShuming Fan struct rt1011_bq_drc_params *params =
1119d6e65bb7SShuming Fan (struct rt1011_bq_drc_params *)ucontrol->value.integer.value;
1120d6e65bb7SShuming Fan unsigned int i, mode_idx = 0;
1121d6e65bb7SShuming Fan
1122d6e65bb7SShuming Fan if (strstr(ucontrol->id.name, "AdvanceMode Initial Set"))
1123d6e65bb7SShuming Fan mode_idx = RT1011_ADVMODE_INITIAL_SET;
1124d6e65bb7SShuming Fan else if (strstr(ucontrol->id.name, "AdvanceMode SEP BQ Coeff"))
1125d6e65bb7SShuming Fan mode_idx = RT1011_ADVMODE_SEP_BQ_COEFF;
1126d6e65bb7SShuming Fan else if (strstr(ucontrol->id.name, "AdvanceMode EQ BQ Coeff"))
1127d6e65bb7SShuming Fan mode_idx = RT1011_ADVMODE_EQ_BQ_COEFF;
1128d6e65bb7SShuming Fan else if (strstr(ucontrol->id.name, "AdvanceMode BQ UI Coeff"))
1129d6e65bb7SShuming Fan mode_idx = RT1011_ADVMODE_BQ_UI_COEFF;
1130d6e65bb7SShuming Fan else if (strstr(ucontrol->id.name, "AdvanceMode SmartBoost Coeff"))
1131d6e65bb7SShuming Fan mode_idx = RT1011_ADVMODE_SMARTBOOST_COEFF;
1132d6e65bb7SShuming Fan else
1133d6e65bb7SShuming Fan return -EINVAL;
1134d6e65bb7SShuming Fan
1135d6e65bb7SShuming Fan pr_info("%s, id.name=%s, mode_idx=%d\n", __func__,
1136d6e65bb7SShuming Fan ucontrol->id.name, mode_idx);
1137d6e65bb7SShuming Fan bq_drc_info = rt1011->bq_drc_params[mode_idx];
1138d6e65bb7SShuming Fan
1139d6e65bb7SShuming Fan for (i = 0; i < RT1011_BQ_DRC_NUM; i++) {
114064429a87SShuming Fan params[i].reg = bq_drc_info[i].reg;
114164429a87SShuming Fan params[i].val = bq_drc_info[i].val;
1142d6e65bb7SShuming Fan }
1143d6e65bb7SShuming Fan
1144d6e65bb7SShuming Fan return 0;
1145d6e65bb7SShuming Fan }
1146d6e65bb7SShuming Fan
rt1011_bq_drc_coeff_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1147d6e65bb7SShuming Fan static int rt1011_bq_drc_coeff_put(struct snd_kcontrol *kcontrol,
1148d6e65bb7SShuming Fan struct snd_ctl_elem_value *ucontrol)
1149d6e65bb7SShuming Fan {
1150d6e65bb7SShuming Fan struct snd_soc_component *component =
1151d6e65bb7SShuming Fan snd_soc_kcontrol_component(kcontrol);
1152d6e65bb7SShuming Fan struct rt1011_priv *rt1011 =
1153d6e65bb7SShuming Fan snd_soc_component_get_drvdata(component);
1154d6e65bb7SShuming Fan struct rt1011_bq_drc_params *bq_drc_info;
1155d6e65bb7SShuming Fan struct rt1011_bq_drc_params *params =
1156d6e65bb7SShuming Fan (struct rt1011_bq_drc_params *)ucontrol->value.integer.value;
1157d6e65bb7SShuming Fan unsigned int i, mode_idx = 0;
1158d6e65bb7SShuming Fan
1159d6e65bb7SShuming Fan if (strstr(ucontrol->id.name, "AdvanceMode Initial Set"))
1160d6e65bb7SShuming Fan mode_idx = RT1011_ADVMODE_INITIAL_SET;
1161d6e65bb7SShuming Fan else if (strstr(ucontrol->id.name, "AdvanceMode SEP BQ Coeff"))
1162d6e65bb7SShuming Fan mode_idx = RT1011_ADVMODE_SEP_BQ_COEFF;
1163d6e65bb7SShuming Fan else if (strstr(ucontrol->id.name, "AdvanceMode EQ BQ Coeff"))
1164d6e65bb7SShuming Fan mode_idx = RT1011_ADVMODE_EQ_BQ_COEFF;
1165d6e65bb7SShuming Fan else if (strstr(ucontrol->id.name, "AdvanceMode BQ UI Coeff"))
1166d6e65bb7SShuming Fan mode_idx = RT1011_ADVMODE_BQ_UI_COEFF;
1167d6e65bb7SShuming Fan else if (strstr(ucontrol->id.name, "AdvanceMode SmartBoost Coeff"))
1168d6e65bb7SShuming Fan mode_idx = RT1011_ADVMODE_SMARTBOOST_COEFF;
1169d6e65bb7SShuming Fan else
1170d6e65bb7SShuming Fan return -EINVAL;
1171d6e65bb7SShuming Fan
1172d6e65bb7SShuming Fan bq_drc_info = rt1011->bq_drc_params[mode_idx];
1173d6e65bb7SShuming Fan memset(bq_drc_info, 0,
1174d6e65bb7SShuming Fan sizeof(struct rt1011_bq_drc_params) * RT1011_BQ_DRC_NUM);
1175d6e65bb7SShuming Fan
1176d6e65bb7SShuming Fan pr_info("%s, id.name=%s, mode_idx=%d\n", __func__,
1177d6e65bb7SShuming Fan ucontrol->id.name, mode_idx);
1178d6e65bb7SShuming Fan for (i = 0; i < RT1011_BQ_DRC_NUM; i++) {
117964429a87SShuming Fan bq_drc_info[i].reg = params[i].reg;
118064429a87SShuming Fan bq_drc_info[i].val = params[i].val;
1181d6e65bb7SShuming Fan }
1182d6e65bb7SShuming Fan
1183d6e65bb7SShuming Fan for (i = 0; i < RT1011_BQ_DRC_NUM; i++) {
1184d6e65bb7SShuming Fan if (bq_drc_info[i].reg == 0)
1185d6e65bb7SShuming Fan break;
1186d6e65bb7SShuming Fan else if (rt1011_validate_bq_drc_coeff(bq_drc_info[i].reg)) {
1187d6e65bb7SShuming Fan snd_soc_component_write(component, bq_drc_info[i].reg,
1188d6e65bb7SShuming Fan bq_drc_info[i].val);
1189d6e65bb7SShuming Fan }
1190d6e65bb7SShuming Fan }
1191d6e65bb7SShuming Fan
1192d6e65bb7SShuming Fan return 0;
1193d6e65bb7SShuming Fan }
1194d6e65bb7SShuming Fan
rt1011_bq_drc_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)1195d6e65bb7SShuming Fan static int rt1011_bq_drc_info(struct snd_kcontrol *kcontrol,
1196d6e65bb7SShuming Fan struct snd_ctl_elem_info *uinfo)
1197d6e65bb7SShuming Fan {
1198d6e65bb7SShuming Fan uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1199d6e65bb7SShuming Fan uinfo->count = 128;
1200d6e65bb7SShuming Fan uinfo->value.integer.max = 0x17ffffff;
1201d6e65bb7SShuming Fan
1202d6e65bb7SShuming Fan return 0;
1203d6e65bb7SShuming Fan }
1204d6e65bb7SShuming Fan
1205d6e65bb7SShuming Fan #define RT1011_BQ_DRC(xname) \
1206d6e65bb7SShuming Fan { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1207d6e65bb7SShuming Fan .info = rt1011_bq_drc_info, \
1208d6e65bb7SShuming Fan .get = rt1011_bq_drc_coeff_get, \
1209d6e65bb7SShuming Fan .put = rt1011_bq_drc_coeff_put \
1210d6e65bb7SShuming Fan }
1211d6e65bb7SShuming Fan
rt1011_r0_cali_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1212d6e65bb7SShuming Fan static int rt1011_r0_cali_get(struct snd_kcontrol *kcontrol,
1213d6e65bb7SShuming Fan struct snd_ctl_elem_value *ucontrol)
1214d6e65bb7SShuming Fan {
12150922c7a5SShuming Fan struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
12160922c7a5SShuming Fan struct rt1011_priv *rt1011 = snd_soc_component_get_drvdata(component);
12170922c7a5SShuming Fan
12180922c7a5SShuming Fan ucontrol->value.integer.value[0] = rt1011->cali_done;
1219d6e65bb7SShuming Fan
1220d6e65bb7SShuming Fan return 0;
1221d6e65bb7SShuming Fan }
1222d6e65bb7SShuming Fan
rt1011_r0_cali_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1223d6e65bb7SShuming Fan static int rt1011_r0_cali_put(struct snd_kcontrol *kcontrol,
1224d6e65bb7SShuming Fan struct snd_ctl_elem_value *ucontrol)
1225d6e65bb7SShuming Fan {
1226d6e65bb7SShuming Fan struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
1227d6e65bb7SShuming Fan struct rt1011_priv *rt1011 = snd_soc_component_get_drvdata(component);
1228d6e65bb7SShuming Fan
12290922c7a5SShuming Fan rt1011->cali_done = 0;
1230d6e65bb7SShuming Fan if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_OFF &&
1231d6e65bb7SShuming Fan ucontrol->value.integer.value[0])
1232d6e65bb7SShuming Fan rt1011_calibrate(rt1011, 1);
1233d6e65bb7SShuming Fan
1234d6e65bb7SShuming Fan return 0;
1235d6e65bb7SShuming Fan }
1236d6e65bb7SShuming Fan
rt1011_r0_load(struct rt1011_priv * rt1011)1237d6e65bb7SShuming Fan static int rt1011_r0_load(struct rt1011_priv *rt1011)
1238d6e65bb7SShuming Fan {
1239d6e65bb7SShuming Fan if (!rt1011->r0_reg)
1240d6e65bb7SShuming Fan return -EINVAL;
1241d6e65bb7SShuming Fan
1242d6e65bb7SShuming Fan /* write R0 to register */
1243d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_INIT_RECIPROCAL_REG_24_16,
1244d6e65bb7SShuming Fan ((rt1011->r0_reg>>16) & 0x1ff));
1245d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_INIT_RECIPROCAL_REG_15_0,
1246d6e65bb7SShuming Fan (rt1011->r0_reg & 0xffff));
1247d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_SPK_TEMP_PROTECT_4, 0x4080);
1248d6e65bb7SShuming Fan
1249d6e65bb7SShuming Fan return 0;
1250d6e65bb7SShuming Fan }
1251d6e65bb7SShuming Fan
rt1011_r0_load_mode_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1252d6e65bb7SShuming Fan static int rt1011_r0_load_mode_get(struct snd_kcontrol *kcontrol,
1253d6e65bb7SShuming Fan struct snd_ctl_elem_value *ucontrol)
1254d6e65bb7SShuming Fan {
1255d6e65bb7SShuming Fan struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
1256d6e65bb7SShuming Fan struct rt1011_priv *rt1011 = snd_soc_component_get_drvdata(component);
1257d6e65bb7SShuming Fan
1258d6e65bb7SShuming Fan ucontrol->value.integer.value[0] = rt1011->r0_reg;
1259d6e65bb7SShuming Fan
1260d6e65bb7SShuming Fan return 0;
1261d6e65bb7SShuming Fan }
1262d6e65bb7SShuming Fan
rt1011_r0_load_mode_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1263d6e65bb7SShuming Fan static int rt1011_r0_load_mode_put(struct snd_kcontrol *kcontrol,
1264d6e65bb7SShuming Fan struct snd_ctl_elem_value *ucontrol)
1265d6e65bb7SShuming Fan {
1266d6e65bb7SShuming Fan struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
1267d6e65bb7SShuming Fan struct rt1011_priv *rt1011 = snd_soc_component_get_drvdata(component);
1268d6e65bb7SShuming Fan struct device *dev;
1269d6e65bb7SShuming Fan unsigned int r0_integer, r0_factor, format;
1270d6e65bb7SShuming Fan
1271d6e65bb7SShuming Fan if (ucontrol->value.integer.value[0] == rt1011->r0_reg)
1272d6e65bb7SShuming Fan return 0;
1273d6e65bb7SShuming Fan
127464429a87SShuming Fan if (ucontrol->value.integer.value[0] == 0)
127564429a87SShuming Fan return -EINVAL;
127664429a87SShuming Fan
1277d6e65bb7SShuming Fan dev = regmap_get_device(rt1011->regmap);
1278d6e65bb7SShuming Fan if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_OFF) {
1279d6e65bb7SShuming Fan rt1011->r0_reg = ucontrol->value.integer.value[0];
1280d6e65bb7SShuming Fan
128183a6edbbSNathan Chancellor format = 2147483648U; /* 2^24 * 128 */
1282d6e65bb7SShuming Fan r0_integer = format / rt1011->r0_reg / 128;
1283d6e65bb7SShuming Fan r0_factor = ((format / rt1011->r0_reg * 100) / 128)
1284d6e65bb7SShuming Fan - (r0_integer * 100);
1285d6e65bb7SShuming Fan dev_info(dev, "New r0 resistance about %d.%02d ohm, reg=0x%X\n",
1286d6e65bb7SShuming Fan r0_integer, r0_factor, rt1011->r0_reg);
1287d6e65bb7SShuming Fan
1288d6e65bb7SShuming Fan if (rt1011->r0_reg)
1289d6e65bb7SShuming Fan rt1011_r0_load(rt1011);
1290d6e65bb7SShuming Fan }
1291d6e65bb7SShuming Fan
1292d6e65bb7SShuming Fan return 0;
1293d6e65bb7SShuming Fan }
1294d6e65bb7SShuming Fan
rt1011_r0_load_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)1295d6e65bb7SShuming Fan static int rt1011_r0_load_info(struct snd_kcontrol *kcontrol,
1296d6e65bb7SShuming Fan struct snd_ctl_elem_info *uinfo)
1297d6e65bb7SShuming Fan {
1298d6e65bb7SShuming Fan uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1299d6e65bb7SShuming Fan uinfo->count = 1;
1300d6e65bb7SShuming Fan uinfo->value.integer.max = 0x1ffffff;
1301d6e65bb7SShuming Fan
1302d6e65bb7SShuming Fan return 0;
1303d6e65bb7SShuming Fan }
1304d6e65bb7SShuming Fan
1305d6e65bb7SShuming Fan #define RT1011_R0_LOAD(xname) \
1306d6e65bb7SShuming Fan { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1307d6e65bb7SShuming Fan .info = rt1011_r0_load_info, \
1308d6e65bb7SShuming Fan .get = rt1011_r0_load_mode_get, \
1309d6e65bb7SShuming Fan .put = rt1011_r0_load_mode_put \
1310d6e65bb7SShuming Fan }
1311d6e65bb7SShuming Fan
1312a382285bSJack Yu static const char * const rt1011_i2s_ref[] = {
1313a382285bSJack Yu "None", "Left Channel", "Right Channel"
131487f40af2SJack Yu };
131587f40af2SJack Yu
1316a382285bSJack Yu static SOC_ENUM_SINGLE_DECL(rt1011_i2s_ref_enum, 0, 0,
1317a382285bSJack Yu rt1011_i2s_ref);
1318a382285bSJack Yu
rt1011_i2s_ref_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1319a382285bSJack Yu static int rt1011_i2s_ref_put(struct snd_kcontrol *kcontrol,
1320a382285bSJack Yu struct snd_ctl_elem_value *ucontrol)
1321a382285bSJack Yu {
1322a382285bSJack Yu struct snd_soc_component *component =
1323a382285bSJack Yu snd_soc_kcontrol_component(kcontrol);
1324a382285bSJack Yu struct rt1011_priv *rt1011 =
1325a382285bSJack Yu snd_soc_component_get_drvdata(component);
1326a382285bSJack Yu
1327a382285bSJack Yu rt1011->i2s_ref = ucontrol->value.enumerated.item[0];
1328a382285bSJack Yu switch (rt1011->i2s_ref) {
1329a382285bSJack Yu case RT1011_I2S_REF_LEFT_CH:
1330a382285bSJack Yu regmap_write(rt1011->regmap, RT1011_TDM_TOTAL_SET, 0x0240);
1331a382285bSJack Yu regmap_write(rt1011->regmap, RT1011_TDM1_SET_2, 0x8);
1332a382285bSJack Yu regmap_write(rt1011->regmap, RT1011_TDM1_SET_1, 0x1022);
1333a382285bSJack Yu regmap_write(rt1011->regmap, RT1011_ADCDAT_OUT_SOURCE, 0x4);
1334a382285bSJack Yu break;
1335a382285bSJack Yu case RT1011_I2S_REF_RIGHT_CH:
1336a382285bSJack Yu regmap_write(rt1011->regmap, RT1011_TDM_TOTAL_SET, 0x0240);
1337a382285bSJack Yu regmap_write(rt1011->regmap, RT1011_TDM1_SET_2, 0x8);
1338a382285bSJack Yu regmap_write(rt1011->regmap, RT1011_TDM1_SET_1, 0x10a2);
1339a382285bSJack Yu regmap_write(rt1011->regmap, RT1011_ADCDAT_OUT_SOURCE, 0x4);
1340a382285bSJack Yu break;
1341a382285bSJack Yu default:
1342a382285bSJack Yu dev_info(component->dev, "I2S Reference: Do nothing\n");
1343a382285bSJack Yu }
1344a382285bSJack Yu
1345a382285bSJack Yu return 0;
1346a382285bSJack Yu }
1347a382285bSJack Yu
rt1011_i2s_ref_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1348a382285bSJack Yu static int rt1011_i2s_ref_get(struct snd_kcontrol *kcontrol,
1349a382285bSJack Yu struct snd_ctl_elem_value *ucontrol)
1350a382285bSJack Yu {
1351a382285bSJack Yu struct snd_soc_component *component =
1352a382285bSJack Yu snd_soc_kcontrol_component(kcontrol);
1353a382285bSJack Yu struct rt1011_priv *rt1011 =
1354a382285bSJack Yu snd_soc_component_get_drvdata(component);
1355a382285bSJack Yu
1356a382285bSJack Yu ucontrol->value.enumerated.item[0] = rt1011->i2s_ref;
1357a382285bSJack Yu
1358a382285bSJack Yu return 0;
1359a382285bSJack Yu }
136087f40af2SJack Yu
1361d6e65bb7SShuming Fan static const struct snd_kcontrol_new rt1011_snd_controls[] = {
1362d6e65bb7SShuming Fan /* I2S Data In Selection */
1363d6e65bb7SShuming Fan SOC_ENUM("DIN Source", rt1011_din_source_enum),
1364d6e65bb7SShuming Fan
1365d6e65bb7SShuming Fan /* TDM Data In Selection */
1366d6e65bb7SShuming Fan SOC_ENUM("TDM1 DIN Source", rt1011_tdm1_l_dac1_enum),
1367d6e65bb7SShuming Fan SOC_ENUM("TDM2 DIN Source", rt1011_tdm2_l_dac1_enum),
1368d6e65bb7SShuming Fan
1369d6e65bb7SShuming Fan /* TDM1 Data Out Selection */
1370d6e65bb7SShuming Fan SOC_ENUM("TDM1 DOUT Source", rt1011_tdm1_adc1_dat_enum),
1371d6e65bb7SShuming Fan SOC_ENUM("TDM1 DOUT Location", rt1011_tdm1_adc1_loc_enum),
13723403b808SShuming Fan SOC_ENUM("TDM1 ADC1DAT Swap Select", rt1011_tdm_adc1_1_enum),
13733403b808SShuming Fan SOC_ENUM("TDM1 ADC2DAT Swap Select", rt1011_tdm_adc2_1_enum),
1374d6e65bb7SShuming Fan
1375d6e65bb7SShuming Fan /* Data Out Mode */
1376d6e65bb7SShuming Fan SOC_ENUM("I2S ADC DOUT Mode", rt1011_adc_dout_mode_enum),
1377d6e65bb7SShuming Fan SOC_ENUM("TDM1 DOUT Length", rt1011_tdm1_dout_len_enum),
1378d6e65bb7SShuming Fan SOC_ENUM("TDM2 DOUT Length", rt1011_tdm2_dout_len_enum),
1379d6e65bb7SShuming Fan
1380d6e65bb7SShuming Fan /* Speaker/Receiver Mode */
1381d6e65bb7SShuming Fan SOC_SINGLE_EXT("RECV SPK Mode", SND_SOC_NOPM, 0, 1, 0,
1382d6e65bb7SShuming Fan rt1011_recv_spk_mode_get, rt1011_recv_spk_mode_put),
1383d6e65bb7SShuming Fan
1384d6e65bb7SShuming Fan /* BiQuad/DRC/SmartBoost Settings */
1385d6e65bb7SShuming Fan RT1011_BQ_DRC("AdvanceMode Initial Set"),
1386d6e65bb7SShuming Fan RT1011_BQ_DRC("AdvanceMode SEP BQ Coeff"),
1387d6e65bb7SShuming Fan RT1011_BQ_DRC("AdvanceMode EQ BQ Coeff"),
1388d6e65bb7SShuming Fan RT1011_BQ_DRC("AdvanceMode BQ UI Coeff"),
1389d6e65bb7SShuming Fan RT1011_BQ_DRC("AdvanceMode SmartBoost Coeff"),
1390d6e65bb7SShuming Fan
1391d6e65bb7SShuming Fan /* R0 */
1392d6e65bb7SShuming Fan SOC_SINGLE_EXT("R0 Calibration", SND_SOC_NOPM, 0, 1, 0,
1393d6e65bb7SShuming Fan rt1011_r0_cali_get, rt1011_r0_cali_put),
1394d6e65bb7SShuming Fan RT1011_R0_LOAD("R0 Load Mode"),
13953403b808SShuming Fan
13963403b808SShuming Fan /* R0 temperature */
13973403b808SShuming Fan SOC_SINGLE("R0 Temperature", RT1011_STP_INITIAL_RESISTANCE_TEMP,
13983403b808SShuming Fan 2, 255, 0),
139987f40af2SJack Yu /* I2S Reference */
1400a382285bSJack Yu SOC_ENUM_EXT("I2S Reference", rt1011_i2s_ref_enum,
1401a382285bSJack Yu rt1011_i2s_ref_get, rt1011_i2s_ref_put),
1402d6e65bb7SShuming Fan };
1403d6e65bb7SShuming Fan
rt1011_is_sys_clk_from_pll(struct snd_soc_dapm_widget * source,struct snd_soc_dapm_widget * sink)1404d6e65bb7SShuming Fan static int rt1011_is_sys_clk_from_pll(struct snd_soc_dapm_widget *source,
1405d6e65bb7SShuming Fan struct snd_soc_dapm_widget *sink)
1406d6e65bb7SShuming Fan {
1407d6e65bb7SShuming Fan struct snd_soc_component *component =
1408d6e65bb7SShuming Fan snd_soc_dapm_to_component(source->dapm);
1409d6e65bb7SShuming Fan struct rt1011_priv *rt1011 = snd_soc_component_get_drvdata(component);
1410d6e65bb7SShuming Fan
1411d6e65bb7SShuming Fan if (rt1011->sysclk_src == RT1011_FS_SYS_PRE_S_PLL1)
1412d6e65bb7SShuming Fan return 1;
1413d6e65bb7SShuming Fan else
1414d6e65bb7SShuming Fan return 0;
1415d6e65bb7SShuming Fan }
1416d6e65bb7SShuming Fan
rt1011_dac_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)1417d6e65bb7SShuming Fan static int rt1011_dac_event(struct snd_soc_dapm_widget *w,
1418d6e65bb7SShuming Fan struct snd_kcontrol *kcontrol, int event)
1419d6e65bb7SShuming Fan {
1420d6e65bb7SShuming Fan struct snd_soc_component *component =
1421d6e65bb7SShuming Fan snd_soc_dapm_to_component(w->dapm);
1422d6e65bb7SShuming Fan
1423d6e65bb7SShuming Fan switch (event) {
1424d6e65bb7SShuming Fan case SND_SOC_DAPM_POST_PMU:
1425d6e65bb7SShuming Fan snd_soc_component_update_bits(component,
1426d6e65bb7SShuming Fan RT1011_SPK_TEMP_PROTECT_0,
1427d6e65bb7SShuming Fan RT1011_STP_EN_MASK | RT1011_STP_RS_CLB_EN_MASK,
1428d6e65bb7SShuming Fan RT1011_STP_EN | RT1011_STP_RS_CLB_EN);
1429d6e65bb7SShuming Fan snd_soc_component_update_bits(component, RT1011_POWER_9,
1430d6e65bb7SShuming Fan RT1011_POW_MNL_SDB_MASK, RT1011_POW_MNL_SDB);
1431d6e65bb7SShuming Fan msleep(50);
1432d6e65bb7SShuming Fan snd_soc_component_update_bits(component,
1433d6e65bb7SShuming Fan RT1011_CLASSD_INTERNAL_SET_1,
1434d6e65bb7SShuming Fan RT1011_DRIVER_READY_SPK, RT1011_DRIVER_READY_SPK);
1435d6e65bb7SShuming Fan break;
1436d6e65bb7SShuming Fan case SND_SOC_DAPM_PRE_PMD:
1437d6e65bb7SShuming Fan snd_soc_component_update_bits(component, RT1011_POWER_9,
1438d6e65bb7SShuming Fan RT1011_POW_MNL_SDB_MASK, 0);
1439d6e65bb7SShuming Fan snd_soc_component_update_bits(component,
1440d6e65bb7SShuming Fan RT1011_SPK_TEMP_PROTECT_0,
1441d6e65bb7SShuming Fan RT1011_STP_EN_MASK | RT1011_STP_RS_CLB_EN_MASK, 0);
1442d6e65bb7SShuming Fan msleep(200);
1443d6e65bb7SShuming Fan snd_soc_component_update_bits(component,
1444d6e65bb7SShuming Fan RT1011_CLASSD_INTERNAL_SET_1,
1445d6e65bb7SShuming Fan RT1011_DRIVER_READY_SPK, 0);
1446d6e65bb7SShuming Fan break;
1447d6e65bb7SShuming Fan
1448d6e65bb7SShuming Fan default:
1449d6e65bb7SShuming Fan return 0;
1450d6e65bb7SShuming Fan }
1451d6e65bb7SShuming Fan
1452d6e65bb7SShuming Fan return 0;
1453d6e65bb7SShuming Fan }
1454d6e65bb7SShuming Fan
1455d6e65bb7SShuming Fan
1456d6e65bb7SShuming Fan static const struct snd_soc_dapm_widget rt1011_dapm_widgets[] = {
1457d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("LDO2", RT1011_POWER_1,
1458d6e65bb7SShuming Fan RT1011_POW_LDO2_BIT, 0, NULL, 0),
1459d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("ISENSE SPK", RT1011_POWER_1,
1460d6e65bb7SShuming Fan RT1011_POW_ISENSE_SPK_BIT, 0, NULL, 0),
1461d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("VSENSE SPK", RT1011_POWER_1,
1462d6e65bb7SShuming Fan RT1011_POW_VSENSE_SPK_BIT, 0, NULL, 0),
1463d6e65bb7SShuming Fan
1464d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("PLL", RT1011_POWER_2,
1465d6e65bb7SShuming Fan RT1011_PLLEN_BIT, 0, NULL, 0),
1466d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("BG", RT1011_POWER_2,
1467d6e65bb7SShuming Fan RT1011_POW_BG_BIT, 0, NULL, 0),
1468d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("BG MBIAS", RT1011_POWER_2,
1469d6e65bb7SShuming Fan RT1011_POW_BG_MBIAS_LV_BIT, 0, NULL, 0),
1470d6e65bb7SShuming Fan
1471d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("DET VBAT", RT1011_POWER_3,
1472d6e65bb7SShuming Fan RT1011_POW_DET_VBAT_BIT, 0, NULL, 0),
1473d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("MBIAS", RT1011_POWER_3,
1474d6e65bb7SShuming Fan RT1011_POW_MBIAS_LV_BIT, 0, NULL, 0),
1475d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("ADC I", RT1011_POWER_3,
1476d6e65bb7SShuming Fan RT1011_POW_ADC_I_BIT, 0, NULL, 0),
1477d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("ADC V", RT1011_POWER_3,
1478d6e65bb7SShuming Fan RT1011_POW_ADC_V_BIT, 0, NULL, 0),
1479d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("ADC T", RT1011_POWER_3,
1480d6e65bb7SShuming Fan RT1011_POW_ADC_T_BIT, 0, NULL, 0),
1481d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("DITHER ADC T", RT1011_POWER_3,
1482d6e65bb7SShuming Fan RT1011_POWD_ADC_T_BIT, 0, NULL, 0),
1483d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("MIX I", RT1011_POWER_3,
1484d6e65bb7SShuming Fan RT1011_POW_MIX_I_BIT, 0, NULL, 0),
1485d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("MIX V", RT1011_POWER_3,
1486d6e65bb7SShuming Fan RT1011_POW_MIX_V_BIT, 0, NULL, 0),
1487d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("SUM I", RT1011_POWER_3,
1488d6e65bb7SShuming Fan RT1011_POW_SUM_I_BIT, 0, NULL, 0),
1489d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("SUM V", RT1011_POWER_3,
1490d6e65bb7SShuming Fan RT1011_POW_SUM_V_BIT, 0, NULL, 0),
1491d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("MIX T", RT1011_POWER_3,
1492d6e65bb7SShuming Fan RT1011_POW_MIX_T_BIT, 0, NULL, 0),
1493d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("VREF", RT1011_POWER_3,
1494d6e65bb7SShuming Fan RT1011_POW_VREF_LV_BIT, 0, NULL, 0),
1495d6e65bb7SShuming Fan
1496d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("BOOST SWR", RT1011_POWER_4,
1497d6e65bb7SShuming Fan RT1011_POW_EN_SWR_BIT, 0, NULL, 0),
1498d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("BGOK SWR", RT1011_POWER_4,
1499d6e65bb7SShuming Fan RT1011_POW_EN_PASS_BGOK_SWR_BIT, 0, NULL, 0),
1500d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("VPOK SWR", RT1011_POWER_4,
1501d6e65bb7SShuming Fan RT1011_POW_EN_PASS_VPOK_SWR_BIT, 0, NULL, 0),
1502d6e65bb7SShuming Fan
1503d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("TEMP REG", RT1011_A_TEMP_SEN,
1504d6e65bb7SShuming Fan RT1011_POW_TEMP_REG_BIT, 0, NULL, 0),
1505d6e65bb7SShuming Fan
1506d6e65bb7SShuming Fan /* Audio Interface */
1507d6e65bb7SShuming Fan SND_SOC_DAPM_AIF_IN("AIF1RX", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0),
1508d6e65bb7SShuming Fan /* Digital Interface */
1509d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("DAC Power", RT1011_POWER_1,
1510d6e65bb7SShuming Fan RT1011_POW_DAC_BIT, 0, NULL, 0),
1511d6e65bb7SShuming Fan SND_SOC_DAPM_SUPPLY("CLK12M", RT1011_POWER_1,
1512d6e65bb7SShuming Fan RT1011_POW_CLK12M_BIT, 0, NULL, 0),
1513d6e65bb7SShuming Fan SND_SOC_DAPM_DAC_E("DAC", NULL, RT1011_DAC_SET_3,
1514d6e65bb7SShuming Fan RT1011_DA_MUTE_EN_SFT, 1, rt1011_dac_event,
1515d6e65bb7SShuming Fan SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU),
1516d6e65bb7SShuming Fan
1517d6e65bb7SShuming Fan /* Output Lines */
1518d6e65bb7SShuming Fan SND_SOC_DAPM_OUTPUT("SPO"),
1519d6e65bb7SShuming Fan };
1520d6e65bb7SShuming Fan
1521d6e65bb7SShuming Fan static const struct snd_soc_dapm_route rt1011_dapm_routes[] = {
1522d6e65bb7SShuming Fan
1523d6e65bb7SShuming Fan { "DAC", NULL, "AIF1RX" },
1524d6e65bb7SShuming Fan { "DAC", NULL, "DAC Power" },
1525d6e65bb7SShuming Fan { "DAC", NULL, "LDO2" },
1526d6e65bb7SShuming Fan { "DAC", NULL, "ISENSE SPK" },
1527d6e65bb7SShuming Fan { "DAC", NULL, "VSENSE SPK" },
1528d6e65bb7SShuming Fan { "DAC", NULL, "CLK12M" },
1529d6e65bb7SShuming Fan
1530d6e65bb7SShuming Fan { "DAC", NULL, "PLL", rt1011_is_sys_clk_from_pll },
1531d6e65bb7SShuming Fan { "DAC", NULL, "BG" },
1532d6e65bb7SShuming Fan { "DAC", NULL, "BG MBIAS" },
1533d6e65bb7SShuming Fan
1534d6e65bb7SShuming Fan { "DAC", NULL, "BOOST SWR" },
1535d6e65bb7SShuming Fan { "DAC", NULL, "BGOK SWR" },
1536d6e65bb7SShuming Fan { "DAC", NULL, "VPOK SWR" },
1537d6e65bb7SShuming Fan
1538d6e65bb7SShuming Fan { "DAC", NULL, "DET VBAT" },
1539d6e65bb7SShuming Fan { "DAC", NULL, "MBIAS" },
1540d6e65bb7SShuming Fan { "DAC", NULL, "VREF" },
1541d6e65bb7SShuming Fan { "DAC", NULL, "ADC I" },
1542d6e65bb7SShuming Fan { "DAC", NULL, "ADC V" },
1543d6e65bb7SShuming Fan { "DAC", NULL, "ADC T" },
1544d6e65bb7SShuming Fan { "DAC", NULL, "DITHER ADC T" },
1545d6e65bb7SShuming Fan { "DAC", NULL, "MIX I" },
1546d6e65bb7SShuming Fan { "DAC", NULL, "MIX V" },
1547d6e65bb7SShuming Fan { "DAC", NULL, "SUM I" },
1548d6e65bb7SShuming Fan { "DAC", NULL, "SUM V" },
1549d6e65bb7SShuming Fan { "DAC", NULL, "MIX T" },
1550d6e65bb7SShuming Fan
1551d6e65bb7SShuming Fan { "DAC", NULL, "TEMP REG" },
1552d6e65bb7SShuming Fan
1553d6e65bb7SShuming Fan { "SPO", NULL, "DAC" },
1554d6e65bb7SShuming Fan };
1555d6e65bb7SShuming Fan
rt1011_get_clk_info(int sclk,int rate)1556d6e65bb7SShuming Fan static int rt1011_get_clk_info(int sclk, int rate)
1557d6e65bb7SShuming Fan {
15582b70d577SColin Ian King int i;
15592b70d577SColin Ian King static const int pd[] = {1, 2, 3, 4, 6, 8, 12, 16};
1560d6e65bb7SShuming Fan
1561d6e65bb7SShuming Fan if (sclk <= 0 || rate <= 0)
1562d6e65bb7SShuming Fan return -EINVAL;
1563d6e65bb7SShuming Fan
1564d6e65bb7SShuming Fan rate = rate << 8;
1565d6e65bb7SShuming Fan for (i = 0; i < ARRAY_SIZE(pd); i++)
1566d6e65bb7SShuming Fan if (sclk == rate * pd[i])
1567d6e65bb7SShuming Fan return i;
1568d6e65bb7SShuming Fan
1569d6e65bb7SShuming Fan return -EINVAL;
1570d6e65bb7SShuming Fan }
1571d6e65bb7SShuming Fan
rt1011_hw_params(struct snd_pcm_substream * substream,struct snd_pcm_hw_params * params,struct snd_soc_dai * dai)1572d6e65bb7SShuming Fan static int rt1011_hw_params(struct snd_pcm_substream *substream,
1573d6e65bb7SShuming Fan struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
1574d6e65bb7SShuming Fan {
1575d6e65bb7SShuming Fan struct snd_soc_component *component = dai->component;
1576d6e65bb7SShuming Fan struct rt1011_priv *rt1011 = snd_soc_component_get_drvdata(component);
1577d6e65bb7SShuming Fan unsigned int val_len = 0, ch_len = 0, val_clk, mask_clk;
1578d6e65bb7SShuming Fan int pre_div, bclk_ms, frame_size;
1579d6e65bb7SShuming Fan
1580d6e65bb7SShuming Fan rt1011->lrck = params_rate(params);
1581d6e65bb7SShuming Fan pre_div = rt1011_get_clk_info(rt1011->sysclk, rt1011->lrck);
1582d6e65bb7SShuming Fan if (pre_div < 0) {
1583d6e65bb7SShuming Fan dev_warn(component->dev, "Force using PLL ");
1584d6e65bb7SShuming Fan snd_soc_dai_set_pll(dai, 0, RT1011_PLL1_S_BCLK,
1585d6e65bb7SShuming Fan rt1011->lrck * 64, rt1011->lrck * 256);
1586d6e65bb7SShuming Fan snd_soc_dai_set_sysclk(dai, RT1011_FS_SYS_PRE_S_PLL1,
1587d6e65bb7SShuming Fan rt1011->lrck * 256, SND_SOC_CLOCK_IN);
1588d6e65bb7SShuming Fan pre_div = 0;
1589d6e65bb7SShuming Fan }
1590d6e65bb7SShuming Fan frame_size = snd_soc_params_to_frame_size(params);
1591d6e65bb7SShuming Fan if (frame_size < 0) {
1592d6e65bb7SShuming Fan dev_err(component->dev, "Unsupported frame size: %d\n",
1593d6e65bb7SShuming Fan frame_size);
1594d6e65bb7SShuming Fan return -EINVAL;
1595d6e65bb7SShuming Fan }
1596d6e65bb7SShuming Fan
1597d6e65bb7SShuming Fan bclk_ms = frame_size > 32;
1598d6e65bb7SShuming Fan rt1011->bclk = rt1011->lrck * (32 << bclk_ms);
1599d6e65bb7SShuming Fan
1600d6e65bb7SShuming Fan dev_dbg(component->dev, "bclk_ms is %d and pre_div is %d for iis %d\n",
1601d6e65bb7SShuming Fan bclk_ms, pre_div, dai->id);
1602d6e65bb7SShuming Fan
1603d6e65bb7SShuming Fan dev_dbg(component->dev, "lrck is %dHz and pre_div is %d for iis %d\n",
1604d6e65bb7SShuming Fan rt1011->lrck, pre_div, dai->id);
1605d6e65bb7SShuming Fan
1606d6e65bb7SShuming Fan switch (params_width(params)) {
1607d6e65bb7SShuming Fan case 16:
1608d6e65bb7SShuming Fan val_len |= RT1011_I2S_TX_DL_16B;
1609d6e65bb7SShuming Fan val_len |= RT1011_I2S_RX_DL_16B;
1610d6e65bb7SShuming Fan ch_len |= RT1011_I2S_CH_TX_LEN_16B;
1611d6e65bb7SShuming Fan ch_len |= RT1011_I2S_CH_RX_LEN_16B;
1612d6e65bb7SShuming Fan break;
1613d6e65bb7SShuming Fan case 20:
1614d6e65bb7SShuming Fan val_len |= RT1011_I2S_TX_DL_20B;
1615d6e65bb7SShuming Fan val_len |= RT1011_I2S_RX_DL_20B;
1616d6e65bb7SShuming Fan ch_len |= RT1011_I2S_CH_TX_LEN_20B;
1617d6e65bb7SShuming Fan ch_len |= RT1011_I2S_CH_RX_LEN_20B;
1618d6e65bb7SShuming Fan break;
1619d6e65bb7SShuming Fan case 24:
1620d6e65bb7SShuming Fan val_len |= RT1011_I2S_TX_DL_24B;
1621d6e65bb7SShuming Fan val_len |= RT1011_I2S_RX_DL_24B;
1622d6e65bb7SShuming Fan ch_len |= RT1011_I2S_CH_TX_LEN_24B;
1623d6e65bb7SShuming Fan ch_len |= RT1011_I2S_CH_RX_LEN_24B;
1624d6e65bb7SShuming Fan break;
1625d6e65bb7SShuming Fan case 32:
1626d6e65bb7SShuming Fan val_len |= RT1011_I2S_TX_DL_32B;
1627d6e65bb7SShuming Fan val_len |= RT1011_I2S_RX_DL_32B;
1628d6e65bb7SShuming Fan ch_len |= RT1011_I2S_CH_TX_LEN_32B;
1629d6e65bb7SShuming Fan ch_len |= RT1011_I2S_CH_RX_LEN_32B;
1630d6e65bb7SShuming Fan break;
1631d6e65bb7SShuming Fan case 8:
1632d6e65bb7SShuming Fan val_len |= RT1011_I2S_TX_DL_8B;
1633d6e65bb7SShuming Fan val_len |= RT1011_I2S_RX_DL_8B;
1634d6e65bb7SShuming Fan ch_len |= RT1011_I2S_CH_TX_LEN_8B;
1635d6e65bb7SShuming Fan ch_len |= RT1011_I2S_CH_RX_LEN_8B;
1636d6e65bb7SShuming Fan break;
1637d6e65bb7SShuming Fan default:
1638d6e65bb7SShuming Fan return -EINVAL;
1639d6e65bb7SShuming Fan }
1640d6e65bb7SShuming Fan
1641d6e65bb7SShuming Fan switch (dai->id) {
1642d6e65bb7SShuming Fan case RT1011_AIF1:
1643d6e65bb7SShuming Fan mask_clk = RT1011_FS_SYS_DIV_MASK;
1644d6e65bb7SShuming Fan val_clk = pre_div << RT1011_FS_SYS_DIV_SFT;
1645d6e65bb7SShuming Fan snd_soc_component_update_bits(component, RT1011_TDM_TOTAL_SET,
1646d6e65bb7SShuming Fan RT1011_I2S_TX_DL_MASK | RT1011_I2S_RX_DL_MASK,
1647d6e65bb7SShuming Fan val_len);
1648d6e65bb7SShuming Fan snd_soc_component_update_bits(component, RT1011_TDM1_SET_1,
1649d6e65bb7SShuming Fan RT1011_I2S_CH_TX_LEN_MASK |
1650d6e65bb7SShuming Fan RT1011_I2S_CH_RX_LEN_MASK,
1651d6e65bb7SShuming Fan ch_len);
1652d6e65bb7SShuming Fan break;
1653d6e65bb7SShuming Fan default:
1654d6e65bb7SShuming Fan dev_err(component->dev, "Invalid dai->id: %d\n", dai->id);
1655d6e65bb7SShuming Fan return -EINVAL;
1656d6e65bb7SShuming Fan }
1657d6e65bb7SShuming Fan
1658d6e65bb7SShuming Fan snd_soc_component_update_bits(component,
1659d6e65bb7SShuming Fan RT1011_CLK_2, mask_clk, val_clk);
1660d6e65bb7SShuming Fan
1661d6e65bb7SShuming Fan return 0;
1662d6e65bb7SShuming Fan }
1663d6e65bb7SShuming Fan
rt1011_set_dai_fmt(struct snd_soc_dai * dai,unsigned int fmt)1664d6e65bb7SShuming Fan static int rt1011_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
1665d6e65bb7SShuming Fan {
1666d6e65bb7SShuming Fan struct snd_soc_component *component = dai->component;
1667e9e897d5SShuming Fan struct snd_soc_dapm_context *dapm =
1668e9e897d5SShuming Fan snd_soc_component_get_dapm(component);
1669d6e65bb7SShuming Fan unsigned int reg_val = 0, reg_bclk_inv = 0;
1670e9e897d5SShuming Fan int ret = 0;
1671d6e65bb7SShuming Fan
1672e9e897d5SShuming Fan snd_soc_dapm_mutex_lock(dapm);
1673d6e65bb7SShuming Fan switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
1674d6e65bb7SShuming Fan case SND_SOC_DAIFMT_CBS_CFS:
1675d6e65bb7SShuming Fan reg_val |= RT1011_I2S_TDM_MS_S;
1676d6e65bb7SShuming Fan break;
1677d6e65bb7SShuming Fan default:
1678e9e897d5SShuming Fan ret = -EINVAL;
16795cf93491SShuming Fan goto _set_fmt_err_;
1680d6e65bb7SShuming Fan }
1681d6e65bb7SShuming Fan
1682d6e65bb7SShuming Fan switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
1683d6e65bb7SShuming Fan case SND_SOC_DAIFMT_NB_NF:
1684d6e65bb7SShuming Fan break;
1685d6e65bb7SShuming Fan case SND_SOC_DAIFMT_IB_NF:
1686d6e65bb7SShuming Fan reg_bclk_inv |= RT1011_TDM_INV_BCLK;
1687d6e65bb7SShuming Fan break;
1688d6e65bb7SShuming Fan default:
1689e9e897d5SShuming Fan ret = -EINVAL;
16905cf93491SShuming Fan goto _set_fmt_err_;
1691d6e65bb7SShuming Fan }
1692d6e65bb7SShuming Fan
1693d6e65bb7SShuming Fan switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
1694d6e65bb7SShuming Fan case SND_SOC_DAIFMT_I2S:
1695d6e65bb7SShuming Fan break;
1696d6e65bb7SShuming Fan case SND_SOC_DAIFMT_LEFT_J:
1697d6e65bb7SShuming Fan reg_val |= RT1011_I2S_TDM_DF_LEFT;
1698d6e65bb7SShuming Fan break;
1699d6e65bb7SShuming Fan case SND_SOC_DAIFMT_DSP_A:
1700d6e65bb7SShuming Fan reg_val |= RT1011_I2S_TDM_DF_PCM_A;
1701d6e65bb7SShuming Fan break;
1702d6e65bb7SShuming Fan case SND_SOC_DAIFMT_DSP_B:
1703d6e65bb7SShuming Fan reg_val |= RT1011_I2S_TDM_DF_PCM_B;
1704d6e65bb7SShuming Fan break;
1705d6e65bb7SShuming Fan default:
1706e9e897d5SShuming Fan ret = -EINVAL;
17075cf93491SShuming Fan goto _set_fmt_err_;
1708d6e65bb7SShuming Fan }
1709d6e65bb7SShuming Fan
1710d6e65bb7SShuming Fan switch (dai->id) {
1711d6e65bb7SShuming Fan case RT1011_AIF1:
1712d6e65bb7SShuming Fan snd_soc_component_update_bits(component, RT1011_TDM_TOTAL_SET,
1713d6e65bb7SShuming Fan RT1011_I2S_TDM_MS_MASK | RT1011_I2S_TDM_DF_MASK,
1714d6e65bb7SShuming Fan reg_val);
1715d6e65bb7SShuming Fan snd_soc_component_update_bits(component, RT1011_TDM1_SET_1,
1716d6e65bb7SShuming Fan RT1011_TDM_INV_BCLK_MASK, reg_bclk_inv);
1717d6e65bb7SShuming Fan snd_soc_component_update_bits(component, RT1011_TDM2_SET_1,
1718d6e65bb7SShuming Fan RT1011_TDM_INV_BCLK_MASK, reg_bclk_inv);
1719d6e65bb7SShuming Fan break;
1720d6e65bb7SShuming Fan default:
1721d6e65bb7SShuming Fan dev_err(component->dev, "Invalid dai->id: %d\n", dai->id);
1722e9e897d5SShuming Fan ret = -EINVAL;
1723d6e65bb7SShuming Fan }
1724e9e897d5SShuming Fan
17255cf93491SShuming Fan _set_fmt_err_:
1726e9e897d5SShuming Fan snd_soc_dapm_mutex_unlock(dapm);
1727e9e897d5SShuming Fan return ret;
1728d6e65bb7SShuming Fan }
1729d6e65bb7SShuming Fan
rt1011_set_component_sysclk(struct snd_soc_component * component,int clk_id,int source,unsigned int freq,int dir)1730d6e65bb7SShuming Fan static int rt1011_set_component_sysclk(struct snd_soc_component *component,
1731d6e65bb7SShuming Fan int clk_id, int source, unsigned int freq, int dir)
1732d6e65bb7SShuming Fan {
1733d6e65bb7SShuming Fan struct rt1011_priv *rt1011 = snd_soc_component_get_drvdata(component);
1734d6e65bb7SShuming Fan unsigned int reg_val = 0;
1735d6e65bb7SShuming Fan
1736d6e65bb7SShuming Fan if (freq == rt1011->sysclk && clk_id == rt1011->sysclk_src)
1737d6e65bb7SShuming Fan return 0;
1738d6e65bb7SShuming Fan
1739d6e65bb7SShuming Fan /* disable MCLK detect in default */
1740d6e65bb7SShuming Fan snd_soc_component_update_bits(component, RT1011_CLK_DET,
1741d6e65bb7SShuming Fan RT1011_EN_MCLK_DET_MASK, 0);
1742d6e65bb7SShuming Fan
1743d6e65bb7SShuming Fan switch (clk_id) {
1744d6e65bb7SShuming Fan case RT1011_FS_SYS_PRE_S_MCLK:
1745d6e65bb7SShuming Fan reg_val |= RT1011_FS_SYS_PRE_MCLK;
1746d6e65bb7SShuming Fan snd_soc_component_update_bits(component, RT1011_CLK_DET,
1747d6e65bb7SShuming Fan RT1011_EN_MCLK_DET_MASK, RT1011_EN_MCLK_DET);
1748d6e65bb7SShuming Fan break;
1749d6e65bb7SShuming Fan case RT1011_FS_SYS_PRE_S_BCLK:
1750d6e65bb7SShuming Fan reg_val |= RT1011_FS_SYS_PRE_BCLK;
1751d6e65bb7SShuming Fan break;
1752d6e65bb7SShuming Fan case RT1011_FS_SYS_PRE_S_PLL1:
1753d6e65bb7SShuming Fan reg_val |= RT1011_FS_SYS_PRE_PLL1;
1754d6e65bb7SShuming Fan break;
1755d6e65bb7SShuming Fan case RT1011_FS_SYS_PRE_S_RCCLK:
1756d6e65bb7SShuming Fan reg_val |= RT1011_FS_SYS_PRE_RCCLK;
1757d6e65bb7SShuming Fan break;
1758d6e65bb7SShuming Fan default:
1759d6e65bb7SShuming Fan dev_err(component->dev, "Invalid clock id (%d)\n", clk_id);
1760d6e65bb7SShuming Fan return -EINVAL;
1761d6e65bb7SShuming Fan }
1762d6e65bb7SShuming Fan snd_soc_component_update_bits(component, RT1011_CLK_2,
1763d6e65bb7SShuming Fan RT1011_FS_SYS_PRE_MASK, reg_val);
1764d6e65bb7SShuming Fan rt1011->sysclk = freq;
1765d6e65bb7SShuming Fan rt1011->sysclk_src = clk_id;
1766d6e65bb7SShuming Fan
1767d6e65bb7SShuming Fan dev_dbg(component->dev, "Sysclk is %dHz and clock id is %d\n",
1768d6e65bb7SShuming Fan freq, clk_id);
1769d6e65bb7SShuming Fan
1770d6e65bb7SShuming Fan return 0;
1771d6e65bb7SShuming Fan }
1772d6e65bb7SShuming Fan
rt1011_set_component_pll(struct snd_soc_component * component,int pll_id,int source,unsigned int freq_in,unsigned int freq_out)1773d6e65bb7SShuming Fan static int rt1011_set_component_pll(struct snd_soc_component *component,
1774d6e65bb7SShuming Fan int pll_id, int source, unsigned int freq_in,
1775d6e65bb7SShuming Fan unsigned int freq_out)
1776d6e65bb7SShuming Fan {
1777d6e65bb7SShuming Fan struct rt1011_priv *rt1011 = snd_soc_component_get_drvdata(component);
1778d6e65bb7SShuming Fan struct rl6231_pll_code pll_code;
1779d6e65bb7SShuming Fan int ret;
1780d6e65bb7SShuming Fan
1781d6e65bb7SShuming Fan if (source == rt1011->pll_src && freq_in == rt1011->pll_in &&
1782d6e65bb7SShuming Fan freq_out == rt1011->pll_out)
1783d6e65bb7SShuming Fan return 0;
1784d6e65bb7SShuming Fan
1785d6e65bb7SShuming Fan if (!freq_in || !freq_out) {
1786d6e65bb7SShuming Fan dev_dbg(component->dev, "PLL disabled\n");
1787d6e65bb7SShuming Fan
1788d6e65bb7SShuming Fan rt1011->pll_in = 0;
1789d6e65bb7SShuming Fan rt1011->pll_out = 0;
1790d6e65bb7SShuming Fan snd_soc_component_update_bits(component, RT1011_CLK_2,
1791d6e65bb7SShuming Fan RT1011_FS_SYS_PRE_MASK, RT1011_FS_SYS_PRE_BCLK);
1792d6e65bb7SShuming Fan return 0;
1793d6e65bb7SShuming Fan }
1794d6e65bb7SShuming Fan
1795d6e65bb7SShuming Fan switch (source) {
1796d6e65bb7SShuming Fan case RT1011_PLL2_S_MCLK:
1797d6e65bb7SShuming Fan snd_soc_component_update_bits(component, RT1011_CLK_2,
1798d6e65bb7SShuming Fan RT1011_PLL2_SRC_MASK, RT1011_PLL2_SRC_MCLK);
1799d6e65bb7SShuming Fan snd_soc_component_update_bits(component, RT1011_CLK_2,
1800d6e65bb7SShuming Fan RT1011_PLL1_SRC_MASK, RT1011_PLL1_SRC_PLL2);
1801d6e65bb7SShuming Fan snd_soc_component_update_bits(component, RT1011_CLK_DET,
1802d6e65bb7SShuming Fan RT1011_EN_MCLK_DET_MASK, RT1011_EN_MCLK_DET);
1803d6e65bb7SShuming Fan break;
1804d6e65bb7SShuming Fan case RT1011_PLL1_S_BCLK:
1805d6e65bb7SShuming Fan snd_soc_component_update_bits(component, RT1011_CLK_2,
1806d6e65bb7SShuming Fan RT1011_PLL1_SRC_MASK, RT1011_PLL1_SRC_BCLK);
1807d6e65bb7SShuming Fan break;
1808d6e65bb7SShuming Fan case RT1011_PLL2_S_RCCLK:
1809d6e65bb7SShuming Fan snd_soc_component_update_bits(component, RT1011_CLK_2,
1810d6e65bb7SShuming Fan RT1011_PLL2_SRC_MASK, RT1011_PLL2_SRC_RCCLK);
1811d6e65bb7SShuming Fan snd_soc_component_update_bits(component, RT1011_CLK_2,
1812d6e65bb7SShuming Fan RT1011_PLL1_SRC_MASK, RT1011_PLL1_SRC_PLL2);
1813d6e65bb7SShuming Fan break;
1814d6e65bb7SShuming Fan default:
1815d6e65bb7SShuming Fan dev_err(component->dev, "Unknown PLL Source %d\n", source);
1816d6e65bb7SShuming Fan return -EINVAL;
1817d6e65bb7SShuming Fan }
1818d6e65bb7SShuming Fan
1819d6e65bb7SShuming Fan ret = rl6231_pll_calc(freq_in, freq_out, &pll_code);
1820d6e65bb7SShuming Fan if (ret < 0) {
1821683b8515SShuming Fan dev_err(component->dev, "Unsupported input clock %d\n",
1822683b8515SShuming Fan freq_in);
1823d6e65bb7SShuming Fan return ret;
1824d6e65bb7SShuming Fan }
1825d6e65bb7SShuming Fan
1826d6e65bb7SShuming Fan dev_dbg(component->dev, "bypass=%d m=%d n=%d k=%d\n",
1827d6e65bb7SShuming Fan pll_code.m_bp, (pll_code.m_bp ? 0 : pll_code.m_code),
1828d6e65bb7SShuming Fan pll_code.n_code, pll_code.k_code);
1829d6e65bb7SShuming Fan
1830d6e65bb7SShuming Fan snd_soc_component_write(component, RT1011_PLL_1,
18315a242992SPierre-Louis Bossart ((pll_code.m_bp ? 0 : pll_code.m_code) << RT1011_PLL1_QM_SFT) |
18325a242992SPierre-Louis Bossart (pll_code.m_bp << RT1011_PLL1_BPM_SFT) |
18335a242992SPierre-Louis Bossart pll_code.n_code);
1834d6e65bb7SShuming Fan snd_soc_component_write(component, RT1011_PLL_2,
1835d6e65bb7SShuming Fan pll_code.k_code);
1836d6e65bb7SShuming Fan
1837d6e65bb7SShuming Fan rt1011->pll_in = freq_in;
1838d6e65bb7SShuming Fan rt1011->pll_out = freq_out;
1839d6e65bb7SShuming Fan rt1011->pll_src = source;
1840d6e65bb7SShuming Fan
1841d6e65bb7SShuming Fan return 0;
1842d6e65bb7SShuming Fan }
1843d6e65bb7SShuming Fan
rt1011_set_tdm_slot(struct snd_soc_dai * dai,unsigned int tx_mask,unsigned int rx_mask,int slots,int slot_width)1844d6e65bb7SShuming Fan static int rt1011_set_tdm_slot(struct snd_soc_dai *dai,
1845d6e65bb7SShuming Fan unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width)
1846d6e65bb7SShuming Fan {
1847d6e65bb7SShuming Fan struct snd_soc_component *component = dai->component;
1848e9e897d5SShuming Fan struct snd_soc_dapm_context *dapm =
1849e9e897d5SShuming Fan snd_soc_component_get_dapm(component);
185081bd644fSShuming Fan unsigned int val = 0, tdm_en = 0, rx_slotnum, tx_slotnum;
185181bd644fSShuming Fan int ret = 0, first_bit, last_bit;
1852d6e65bb7SShuming Fan
1853e9e897d5SShuming Fan snd_soc_dapm_mutex_lock(dapm);
1854d6e65bb7SShuming Fan if (rx_mask || tx_mask)
1855d6e65bb7SShuming Fan tdm_en = RT1011_TDM_I2S_DOCK_EN_1;
1856d6e65bb7SShuming Fan
1857d6e65bb7SShuming Fan switch (slots) {
1858d6e65bb7SShuming Fan case 4:
1859d6e65bb7SShuming Fan val |= RT1011_I2S_TX_4CH;
1860d6e65bb7SShuming Fan val |= RT1011_I2S_RX_4CH;
1861d6e65bb7SShuming Fan break;
1862d6e65bb7SShuming Fan case 6:
1863d6e65bb7SShuming Fan val |= RT1011_I2S_TX_6CH;
1864d6e65bb7SShuming Fan val |= RT1011_I2S_RX_6CH;
1865d6e65bb7SShuming Fan break;
1866d6e65bb7SShuming Fan case 8:
1867d6e65bb7SShuming Fan val |= RT1011_I2S_TX_8CH;
1868d6e65bb7SShuming Fan val |= RT1011_I2S_RX_8CH;
1869d6e65bb7SShuming Fan break;
1870d6e65bb7SShuming Fan case 2:
1871d6e65bb7SShuming Fan break;
1872d6e65bb7SShuming Fan default:
1873e9e897d5SShuming Fan ret = -EINVAL;
187481bd644fSShuming Fan goto _set_tdm_err_;
1875d6e65bb7SShuming Fan }
1876d6e65bb7SShuming Fan
1877d6e65bb7SShuming Fan switch (slot_width) {
1878d6e65bb7SShuming Fan case 20:
1879d6e65bb7SShuming Fan val |= RT1011_I2S_CH_TX_LEN_20B;
1880d6e65bb7SShuming Fan val |= RT1011_I2S_CH_RX_LEN_20B;
1881d6e65bb7SShuming Fan break;
1882d6e65bb7SShuming Fan case 24:
1883d6e65bb7SShuming Fan val |= RT1011_I2S_CH_TX_LEN_24B;
1884d6e65bb7SShuming Fan val |= RT1011_I2S_CH_RX_LEN_24B;
1885d6e65bb7SShuming Fan break;
1886d6e65bb7SShuming Fan case 32:
1887d6e65bb7SShuming Fan val |= RT1011_I2S_CH_TX_LEN_32B;
1888d6e65bb7SShuming Fan val |= RT1011_I2S_CH_RX_LEN_32B;
1889d6e65bb7SShuming Fan break;
1890d6e65bb7SShuming Fan case 16:
1891d6e65bb7SShuming Fan break;
1892d6e65bb7SShuming Fan default:
1893e9e897d5SShuming Fan ret = -EINVAL;
189481bd644fSShuming Fan goto _set_tdm_err_;
189581bd644fSShuming Fan }
189681bd644fSShuming Fan
189781bd644fSShuming Fan /* Rx slot configuration */
189881bd644fSShuming Fan rx_slotnum = hweight_long(rx_mask);
1899ee8a41cdSFred Oh if (rx_slotnum > 1 || !rx_slotnum) {
190081bd644fSShuming Fan ret = -EINVAL;
1901ee8a41cdSFred Oh dev_err(component->dev, "too many rx slots or zero slot\n");
190281bd644fSShuming Fan goto _set_tdm_err_;
190381bd644fSShuming Fan }
190481bd644fSShuming Fan
1905ee8a41cdSFred Oh first_bit = __ffs(rx_mask);
190681bd644fSShuming Fan switch (first_bit) {
190781bd644fSShuming Fan case 0:
190881bd644fSShuming Fan case 2:
190981bd644fSShuming Fan case 4:
191081bd644fSShuming Fan case 6:
191181bd644fSShuming Fan snd_soc_component_update_bits(component,
191281bd644fSShuming Fan RT1011_CROSS_BQ_SET_1, RT1011_MONO_LR_SEL_MASK,
191381bd644fSShuming Fan RT1011_MONO_L_CHANNEL);
191481bd644fSShuming Fan snd_soc_component_update_bits(component,
191581bd644fSShuming Fan RT1011_TDM1_SET_4,
191681bd644fSShuming Fan RT1011_TDM_I2S_TX_L_DAC1_1_MASK |
191781bd644fSShuming Fan RT1011_TDM_I2S_TX_R_DAC1_1_MASK,
191881bd644fSShuming Fan (first_bit << RT1011_TDM_I2S_TX_L_DAC1_1_SFT) |
191981bd644fSShuming Fan ((first_bit+1) << RT1011_TDM_I2S_TX_R_DAC1_1_SFT));
192081bd644fSShuming Fan break;
192181bd644fSShuming Fan case 1:
192281bd644fSShuming Fan case 3:
192381bd644fSShuming Fan case 5:
192481bd644fSShuming Fan case 7:
192581bd644fSShuming Fan snd_soc_component_update_bits(component,
192681bd644fSShuming Fan RT1011_CROSS_BQ_SET_1, RT1011_MONO_LR_SEL_MASK,
192781bd644fSShuming Fan RT1011_MONO_R_CHANNEL);
192881bd644fSShuming Fan snd_soc_component_update_bits(component,
192981bd644fSShuming Fan RT1011_TDM1_SET_4,
193081bd644fSShuming Fan RT1011_TDM_I2S_TX_L_DAC1_1_MASK |
193181bd644fSShuming Fan RT1011_TDM_I2S_TX_R_DAC1_1_MASK,
193281bd644fSShuming Fan ((first_bit-1) << RT1011_TDM_I2S_TX_L_DAC1_1_SFT) |
193381bd644fSShuming Fan (first_bit << RT1011_TDM_I2S_TX_R_DAC1_1_SFT));
193481bd644fSShuming Fan break;
193581bd644fSShuming Fan default:
193681bd644fSShuming Fan ret = -EINVAL;
193781bd644fSShuming Fan goto _set_tdm_err_;
193881bd644fSShuming Fan }
193981bd644fSShuming Fan
194081bd644fSShuming Fan /* Tx slot configuration */
194181bd644fSShuming Fan tx_slotnum = hweight_long(tx_mask);
1942ee8a41cdSFred Oh if (tx_slotnum > 2 || !tx_slotnum) {
194381bd644fSShuming Fan ret = -EINVAL;
1944ee8a41cdSFred Oh dev_err(component->dev, "too many tx slots or zero slot\n");
1945ee8a41cdSFred Oh goto _set_tdm_err_;
1946ee8a41cdSFred Oh }
1947ee8a41cdSFred Oh
1948ee8a41cdSFred Oh first_bit = __ffs(tx_mask);
1949ee8a41cdSFred Oh last_bit = __fls(tx_mask);
1950ee8a41cdSFred Oh if (last_bit - first_bit > 1) {
1951ee8a41cdSFred Oh ret = -EINVAL;
1952ee8a41cdSFred Oh dev_err(component->dev, "tx slot location error\n");
195381bd644fSShuming Fan goto _set_tdm_err_;
195481bd644fSShuming Fan }
195581bd644fSShuming Fan
195681bd644fSShuming Fan if (tx_slotnum == 1) {
195781bd644fSShuming Fan snd_soc_component_update_bits(component, RT1011_TDM1_SET_2,
195881bd644fSShuming Fan RT1011_TDM_I2S_DOCK_ADCDAT_LEN_1_MASK |
195981bd644fSShuming Fan RT1011_TDM_ADCDAT1_DATA_LOCATION, first_bit);
196081bd644fSShuming Fan switch (first_bit) {
196181bd644fSShuming Fan case 1:
196281bd644fSShuming Fan snd_soc_component_update_bits(component,
196381bd644fSShuming Fan RT1011_TDM1_SET_3,
196481bd644fSShuming Fan RT1011_TDM_I2S_RX_ADC1_1_MASK,
196581bd644fSShuming Fan RT1011_TDM_I2S_RX_ADC1_1_LL);
196681bd644fSShuming Fan break;
196781bd644fSShuming Fan case 3:
196881bd644fSShuming Fan snd_soc_component_update_bits(component,
196981bd644fSShuming Fan RT1011_TDM1_SET_3,
197081bd644fSShuming Fan RT1011_TDM_I2S_RX_ADC2_1_MASK,
197181bd644fSShuming Fan RT1011_TDM_I2S_RX_ADC2_1_LL);
197281bd644fSShuming Fan break;
197381bd644fSShuming Fan case 5:
197481bd644fSShuming Fan snd_soc_component_update_bits(component,
197581bd644fSShuming Fan RT1011_TDM1_SET_3,
197681bd644fSShuming Fan RT1011_TDM_I2S_RX_ADC3_1_MASK,
197781bd644fSShuming Fan RT1011_TDM_I2S_RX_ADC3_1_LL);
197881bd644fSShuming Fan break;
197981bd644fSShuming Fan case 7:
198081bd644fSShuming Fan snd_soc_component_update_bits(component,
198181bd644fSShuming Fan RT1011_TDM1_SET_3,
198281bd644fSShuming Fan RT1011_TDM_I2S_RX_ADC4_1_MASK,
198381bd644fSShuming Fan RT1011_TDM_I2S_RX_ADC4_1_LL);
198481bd644fSShuming Fan break;
198581bd644fSShuming Fan case 0:
198681bd644fSShuming Fan snd_soc_component_update_bits(component,
198781bd644fSShuming Fan RT1011_TDM1_SET_3,
198881bd644fSShuming Fan RT1011_TDM_I2S_RX_ADC1_1_MASK, 0);
198981bd644fSShuming Fan break;
199081bd644fSShuming Fan case 2:
199181bd644fSShuming Fan snd_soc_component_update_bits(component,
199281bd644fSShuming Fan RT1011_TDM1_SET_3,
199381bd644fSShuming Fan RT1011_TDM_I2S_RX_ADC2_1_MASK, 0);
199481bd644fSShuming Fan break;
199581bd644fSShuming Fan case 4:
199681bd644fSShuming Fan snd_soc_component_update_bits(component,
199781bd644fSShuming Fan RT1011_TDM1_SET_3,
199881bd644fSShuming Fan RT1011_TDM_I2S_RX_ADC3_1_MASK, 0);
199981bd644fSShuming Fan break;
200081bd644fSShuming Fan case 6:
200181bd644fSShuming Fan snd_soc_component_update_bits(component,
200281bd644fSShuming Fan RT1011_TDM1_SET_3,
200381bd644fSShuming Fan RT1011_TDM_I2S_RX_ADC4_1_MASK, 0);
200481bd644fSShuming Fan break;
200581bd644fSShuming Fan default:
200681bd644fSShuming Fan ret = -EINVAL;
200781bd644fSShuming Fan dev_dbg(component->dev,
200881bd644fSShuming Fan "tx slot location error\n");
200981bd644fSShuming Fan goto _set_tdm_err_;
201081bd644fSShuming Fan }
201181bd644fSShuming Fan } else if (tx_slotnum == 2) {
201281bd644fSShuming Fan switch (first_bit) {
201381bd644fSShuming Fan case 0:
201481bd644fSShuming Fan case 2:
201581bd644fSShuming Fan case 4:
201681bd644fSShuming Fan case 6:
201781bd644fSShuming Fan snd_soc_component_update_bits(component,
201881bd644fSShuming Fan RT1011_TDM1_SET_2,
201981bd644fSShuming Fan RT1011_TDM_I2S_DOCK_ADCDAT_LEN_1_MASK |
202081bd644fSShuming Fan RT1011_TDM_ADCDAT1_DATA_LOCATION,
202181bd644fSShuming Fan RT1011_TDM_I2S_DOCK_ADCDAT_2CH | first_bit);
202281bd644fSShuming Fan break;
202381bd644fSShuming Fan default:
202481bd644fSShuming Fan ret = -EINVAL;
202581bd644fSShuming Fan dev_dbg(component->dev,
202681bd644fSShuming Fan "tx slot location should be paired and start from slot0/2/4/6\n");
202781bd644fSShuming Fan goto _set_tdm_err_;
202881bd644fSShuming Fan }
2029d6e65bb7SShuming Fan }
2030d6e65bb7SShuming Fan
2031d6e65bb7SShuming Fan snd_soc_component_update_bits(component, RT1011_TDM1_SET_1,
2032d6e65bb7SShuming Fan RT1011_I2S_CH_TX_MASK | RT1011_I2S_CH_RX_MASK |
2033d6e65bb7SShuming Fan RT1011_I2S_CH_TX_LEN_MASK | RT1011_I2S_CH_RX_LEN_MASK, val);
2034d6e65bb7SShuming Fan snd_soc_component_update_bits(component, RT1011_TDM2_SET_1,
2035d6e65bb7SShuming Fan RT1011_I2S_CH_TX_MASK | RT1011_I2S_CH_RX_MASK |
2036d6e65bb7SShuming Fan RT1011_I2S_CH_TX_LEN_MASK | RT1011_I2S_CH_RX_LEN_MASK, val);
2037d6e65bb7SShuming Fan snd_soc_component_update_bits(component, RT1011_TDM1_SET_2,
2038d6e65bb7SShuming Fan RT1011_TDM_I2S_DOCK_EN_1_MASK, tdm_en);
2039d6e65bb7SShuming Fan snd_soc_component_update_bits(component, RT1011_TDM2_SET_2,
2040d6e65bb7SShuming Fan RT1011_TDM_I2S_DOCK_EN_2_MASK, tdm_en);
20417e66f162SPierre-Louis Bossart
2042d6e65bb7SShuming Fan snd_soc_component_update_bits(component, RT1011_TDM_TOTAL_SET,
2043d6e65bb7SShuming Fan RT1011_ADCDAT1_PIN_CONFIG | RT1011_ADCDAT2_PIN_CONFIG,
2044d6e65bb7SShuming Fan RT1011_ADCDAT1_OUTPUT | RT1011_ADCDAT2_OUTPUT);
2045d6e65bb7SShuming Fan
204681bd644fSShuming Fan _set_tdm_err_:
2047e9e897d5SShuming Fan snd_soc_dapm_mutex_unlock(dapm);
2048e9e897d5SShuming Fan return ret;
2049d6e65bb7SShuming Fan }
2050d6e65bb7SShuming Fan
rt1011_probe(struct snd_soc_component * component)2051d6e65bb7SShuming Fan static int rt1011_probe(struct snd_soc_component *component)
2052d6e65bb7SShuming Fan {
2053d6e65bb7SShuming Fan struct rt1011_priv *rt1011 = snd_soc_component_get_drvdata(component);
2054d6e65bb7SShuming Fan int i;
2055d6e65bb7SShuming Fan
2056d6e65bb7SShuming Fan rt1011->component = component;
2057d6e65bb7SShuming Fan
2058d6e65bb7SShuming Fan schedule_work(&rt1011->cali_work);
2059d6e65bb7SShuming Fan
2060a382285bSJack Yu rt1011->i2s_ref = 0;
2061d6e65bb7SShuming Fan rt1011->bq_drc_params = devm_kcalloc(component->dev,
2062d6e65bb7SShuming Fan RT1011_ADVMODE_NUM, sizeof(struct rt1011_bq_drc_params *),
2063d6e65bb7SShuming Fan GFP_KERNEL);
2064d6e65bb7SShuming Fan if (!rt1011->bq_drc_params)
2065d6e65bb7SShuming Fan return -ENOMEM;
2066d6e65bb7SShuming Fan
2067d6e65bb7SShuming Fan for (i = 0; i < RT1011_ADVMODE_NUM; i++) {
2068d6e65bb7SShuming Fan rt1011->bq_drc_params[i] = devm_kcalloc(component->dev,
2069d6e65bb7SShuming Fan RT1011_BQ_DRC_NUM, sizeof(struct rt1011_bq_drc_params),
2070d6e65bb7SShuming Fan GFP_KERNEL);
2071d6e65bb7SShuming Fan if (!rt1011->bq_drc_params[i])
2072d6e65bb7SShuming Fan return -ENOMEM;
2073d6e65bb7SShuming Fan }
2074d6e65bb7SShuming Fan
2075d6e65bb7SShuming Fan return 0;
2076d6e65bb7SShuming Fan }
2077d6e65bb7SShuming Fan
rt1011_remove(struct snd_soc_component * component)2078d6e65bb7SShuming Fan static void rt1011_remove(struct snd_soc_component *component)
2079d6e65bb7SShuming Fan {
2080d6e65bb7SShuming Fan struct rt1011_priv *rt1011 = snd_soc_component_get_drvdata(component);
2081d6e65bb7SShuming Fan
2082d6e65bb7SShuming Fan cancel_work_sync(&rt1011->cali_work);
2083d6e65bb7SShuming Fan rt1011_reset(rt1011->regmap);
2084d6e65bb7SShuming Fan }
2085d6e65bb7SShuming Fan
2086d6e65bb7SShuming Fan #ifdef CONFIG_PM
rt1011_suspend(struct snd_soc_component * component)2087d6e65bb7SShuming Fan static int rt1011_suspend(struct snd_soc_component *component)
2088d6e65bb7SShuming Fan {
2089d6e65bb7SShuming Fan struct rt1011_priv *rt1011 = snd_soc_component_get_drvdata(component);
2090d6e65bb7SShuming Fan
2091d6e65bb7SShuming Fan regcache_cache_only(rt1011->regmap, true);
2092d6e65bb7SShuming Fan regcache_mark_dirty(rt1011->regmap);
2093d6e65bb7SShuming Fan
2094d6e65bb7SShuming Fan return 0;
2095d6e65bb7SShuming Fan }
2096d6e65bb7SShuming Fan
rt1011_resume(struct snd_soc_component * component)2097d6e65bb7SShuming Fan static int rt1011_resume(struct snd_soc_component *component)
2098d6e65bb7SShuming Fan {
2099d6e65bb7SShuming Fan struct rt1011_priv *rt1011 = snd_soc_component_get_drvdata(component);
2100d6e65bb7SShuming Fan
2101d6e65bb7SShuming Fan regcache_cache_only(rt1011->regmap, false);
2102d6e65bb7SShuming Fan regcache_sync(rt1011->regmap);
2103d6e65bb7SShuming Fan
2104d6e65bb7SShuming Fan return 0;
2105d6e65bb7SShuming Fan }
2106d6e65bb7SShuming Fan #else
2107d6e65bb7SShuming Fan #define rt1011_suspend NULL
2108d6e65bb7SShuming Fan #define rt1011_resume NULL
2109d6e65bb7SShuming Fan #endif
2110d6e65bb7SShuming Fan
rt1011_set_bias_level(struct snd_soc_component * component,enum snd_soc_bias_level level)2111d6e65bb7SShuming Fan static int rt1011_set_bias_level(struct snd_soc_component *component,
2112d6e65bb7SShuming Fan enum snd_soc_bias_level level)
2113d6e65bb7SShuming Fan {
2114d6e65bb7SShuming Fan switch (level) {
2115d6e65bb7SShuming Fan case SND_SOC_BIAS_OFF:
2116d6e65bb7SShuming Fan snd_soc_component_write(component,
2117d6e65bb7SShuming Fan RT1011_SYSTEM_RESET_1, 0x0000);
2118d6e65bb7SShuming Fan snd_soc_component_write(component,
2119d6e65bb7SShuming Fan RT1011_SYSTEM_RESET_2, 0x0000);
2120d6e65bb7SShuming Fan snd_soc_component_write(component,
212109297c2fSShuming Fan RT1011_SYSTEM_RESET_3, 0x0001);
2122d6e65bb7SShuming Fan snd_soc_component_write(component,
2123d6e65bb7SShuming Fan RT1011_SYSTEM_RESET_1, 0x003f);
2124d6e65bb7SShuming Fan snd_soc_component_write(component,
2125d6e65bb7SShuming Fan RT1011_SYSTEM_RESET_2, 0x7fd7);
2126d6e65bb7SShuming Fan snd_soc_component_write(component,
2127d6e65bb7SShuming Fan RT1011_SYSTEM_RESET_3, 0x770f);
2128d6e65bb7SShuming Fan break;
2129d6e65bb7SShuming Fan default:
2130d6e65bb7SShuming Fan break;
2131d6e65bb7SShuming Fan }
2132d6e65bb7SShuming Fan
2133d6e65bb7SShuming Fan return 0;
2134d6e65bb7SShuming Fan }
2135d6e65bb7SShuming Fan
2136d6e65bb7SShuming Fan #define RT1011_STEREO_RATES SNDRV_PCM_RATE_8000_192000
2137d6e65bb7SShuming Fan #define RT1011_FORMATS (SNDRV_PCM_FMTBIT_S8 | \
2138d6e65bb7SShuming Fan SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S16_LE | \
2139d6e65bb7SShuming Fan SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
2140d6e65bb7SShuming Fan
2141d6e65bb7SShuming Fan static const struct snd_soc_dai_ops rt1011_aif_dai_ops = {
2142d6e65bb7SShuming Fan .hw_params = rt1011_hw_params,
2143d6e65bb7SShuming Fan .set_fmt = rt1011_set_dai_fmt,
2144d6e65bb7SShuming Fan .set_tdm_slot = rt1011_set_tdm_slot,
2145d6e65bb7SShuming Fan };
2146d6e65bb7SShuming Fan
2147d6e65bb7SShuming Fan static struct snd_soc_dai_driver rt1011_dai[] = {
2148d6e65bb7SShuming Fan {
2149d6e65bb7SShuming Fan .name = "rt1011-aif",
2150d6e65bb7SShuming Fan .playback = {
2151d6e65bb7SShuming Fan .stream_name = "AIF1 Playback",
2152d6e65bb7SShuming Fan .channels_min = 1,
2153d6e65bb7SShuming Fan .channels_max = 2,
2154d6e65bb7SShuming Fan .rates = RT1011_STEREO_RATES,
2155d6e65bb7SShuming Fan .formats = RT1011_FORMATS,
2156d6e65bb7SShuming Fan },
2157d6e65bb7SShuming Fan .ops = &rt1011_aif_dai_ops,
2158d6e65bb7SShuming Fan },
2159d6e65bb7SShuming Fan };
2160d6e65bb7SShuming Fan
2161d6e65bb7SShuming Fan static const struct snd_soc_component_driver soc_component_dev_rt1011 = {
2162d6e65bb7SShuming Fan .probe = rt1011_probe,
2163d6e65bb7SShuming Fan .remove = rt1011_remove,
2164d6e65bb7SShuming Fan .suspend = rt1011_suspend,
2165d6e65bb7SShuming Fan .resume = rt1011_resume,
2166d6e65bb7SShuming Fan .set_bias_level = rt1011_set_bias_level,
2167d6e65bb7SShuming Fan .controls = rt1011_snd_controls,
2168d6e65bb7SShuming Fan .num_controls = ARRAY_SIZE(rt1011_snd_controls),
2169d6e65bb7SShuming Fan .dapm_widgets = rt1011_dapm_widgets,
2170d6e65bb7SShuming Fan .num_dapm_widgets = ARRAY_SIZE(rt1011_dapm_widgets),
2171d6e65bb7SShuming Fan .dapm_routes = rt1011_dapm_routes,
2172d6e65bb7SShuming Fan .num_dapm_routes = ARRAY_SIZE(rt1011_dapm_routes),
2173d6e65bb7SShuming Fan .set_sysclk = rt1011_set_component_sysclk,
2174d6e65bb7SShuming Fan .set_pll = rt1011_set_component_pll,
2175d6e65bb7SShuming Fan .use_pmdown_time = 1,
2176d6e65bb7SShuming Fan .endianness = 1,
2177d6e65bb7SShuming Fan };
2178d6e65bb7SShuming Fan
2179d6e65bb7SShuming Fan static const struct regmap_config rt1011_regmap = {
2180d6e65bb7SShuming Fan .reg_bits = 16,
2181d6e65bb7SShuming Fan .val_bits = 16,
2182d6e65bb7SShuming Fan .max_register = RT1011_MAX_REG + 1,
2183d6e65bb7SShuming Fan .volatile_reg = rt1011_volatile_register,
2184d6e65bb7SShuming Fan .readable_reg = rt1011_readable_register,
2185*39da3e15SMark Brown .cache_type = REGCACHE_MAPLE,
2186d6e65bb7SShuming Fan .reg_defaults = rt1011_reg,
2187d6e65bb7SShuming Fan .num_reg_defaults = ARRAY_SIZE(rt1011_reg),
2188d6e65bb7SShuming Fan .use_single_read = true,
2189d6e65bb7SShuming Fan .use_single_write = true,
2190d6e65bb7SShuming Fan };
2191d6e65bb7SShuming Fan
2192d6e65bb7SShuming Fan #if defined(CONFIG_OF)
2193d6e65bb7SShuming Fan static const struct of_device_id rt1011_of_match[] = {
2194d6e65bb7SShuming Fan { .compatible = "realtek,rt1011", },
2195d6e65bb7SShuming Fan {},
2196d6e65bb7SShuming Fan };
2197d6e65bb7SShuming Fan MODULE_DEVICE_TABLE(of, rt1011_of_match);
2198d6e65bb7SShuming Fan #endif
2199d6e65bb7SShuming Fan
2200d6e65bb7SShuming Fan #ifdef CONFIG_ACPI
22013084e5f7SRikard Falkeborn static const struct acpi_device_id rt1011_acpi_match[] = {
2202d6e65bb7SShuming Fan {"10EC1011", 0,},
2203d6e65bb7SShuming Fan {},
2204d6e65bb7SShuming Fan };
2205d6e65bb7SShuming Fan MODULE_DEVICE_TABLE(acpi, rt1011_acpi_match);
2206d6e65bb7SShuming Fan #endif
2207d6e65bb7SShuming Fan
2208d6e65bb7SShuming Fan static const struct i2c_device_id rt1011_i2c_id[] = {
2209d6e65bb7SShuming Fan { "rt1011", 0 },
2210d6e65bb7SShuming Fan { }
2211d6e65bb7SShuming Fan };
2212d6e65bb7SShuming Fan MODULE_DEVICE_TABLE(i2c, rt1011_i2c_id);
2213d6e65bb7SShuming Fan
rt1011_calibrate(struct rt1011_priv * rt1011,unsigned char cali_flag)2214d6e65bb7SShuming Fan static int rt1011_calibrate(struct rt1011_priv *rt1011, unsigned char cali_flag)
2215d6e65bb7SShuming Fan {
2216d6e65bb7SShuming Fan unsigned int value, count = 0, r0[3];
2217d6e65bb7SShuming Fan unsigned int chk_cnt = 50; /* DONT change this */
2218d6e65bb7SShuming Fan unsigned int dc_offset;
2219d6e65bb7SShuming Fan unsigned int r0_integer, r0_factor, format;
2220d6e65bb7SShuming Fan struct device *dev = regmap_get_device(rt1011->regmap);
2221d6e65bb7SShuming Fan struct snd_soc_dapm_context *dapm =
2222d6e65bb7SShuming Fan snd_soc_component_get_dapm(rt1011->component);
2223d6e65bb7SShuming Fan int ret = 0;
2224d6e65bb7SShuming Fan
2225d6e65bb7SShuming Fan snd_soc_dapm_mutex_lock(dapm);
2226d6e65bb7SShuming Fan regcache_cache_bypass(rt1011->regmap, true);
2227d6e65bb7SShuming Fan
2228d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_RESET, 0x0000);
2229d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_SYSTEM_RESET_3, 0x740f);
2230d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_SYSTEM_RESET_3, 0x770f);
2231d6e65bb7SShuming Fan
2232d6e65bb7SShuming Fan /* RC clock */
2233d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_CLK_2, 0x9400);
2234d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_PLL_1, 0x0800);
2235d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_PLL_2, 0x0020);
2236d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_CLK_DET, 0x0800);
2237d6e65bb7SShuming Fan
2238d6e65bb7SShuming Fan /* ADC/DAC setting */
2239d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_ADC_SET_5, 0x0a20);
2240d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_DAC_SET_2, 0xe232);
2241d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_ADC_SET_4, 0xc000);
2242d6e65bb7SShuming Fan
2243d6e65bb7SShuming Fan /* DC detection */
2244d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_SPK_PRO_DC_DET_1, 0xb00c);
2245d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_SPK_PRO_DC_DET_2, 0xcccc);
2246d6e65bb7SShuming Fan
2247d6e65bb7SShuming Fan /* Power */
2248d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_POWER_1, 0xe0e0);
2249d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_POWER_3, 0x5003);
2250d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_POWER_9, 0xa860);
2251d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_DAC_SET_2, 0xa032);
2252d6e65bb7SShuming Fan
2253d6e65bb7SShuming Fan /* POW_PLL / POW_BG / POW_BG_MBIAS_LV / POW_V/I */
2254d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_POWER_2, 0x0007);
2255d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_POWER_3, 0x5ff7);
2256d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_A_TEMP_SEN, 0x7f44);
2257d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_A_TIMING_1, 0x4054);
2258d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_BAT_GAIN_1, 0x309c);
2259d6e65bb7SShuming Fan
2260d6e65bb7SShuming Fan /* DC offset from EFUSE */
2261d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_DC_CALIB_CLASSD_3, 0xcb00);
2262d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_BOOST_CON_1, 0xe080);
2263d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_POWER_4, 0x16f2);
2264d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_POWER_6, 0x36ad);
2265d6e65bb7SShuming Fan
2266d6e65bb7SShuming Fan /* mixer */
2267d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_MIXER_1, 0x3f1d);
2268d6e65bb7SShuming Fan
2269d6e65bb7SShuming Fan /* EFUSE read */
2270d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_EFUSE_CONTROL_1, 0x0d0a);
2271d6e65bb7SShuming Fan msleep(30);
2272d6e65bb7SShuming Fan
2273d6e65bb7SShuming Fan regmap_read(rt1011->regmap, RT1011_EFUSE_ADC_OFFSET_18_16, &value);
2274d6e65bb7SShuming Fan dc_offset = value << 16;
2275d6e65bb7SShuming Fan regmap_read(rt1011->regmap, RT1011_EFUSE_ADC_OFFSET_15_0, &value);
2276d6e65bb7SShuming Fan dc_offset |= (value & 0xffff);
2277d6e65bb7SShuming Fan dev_info(dev, "ADC offset=0x%x\n", dc_offset);
2278d6e65bb7SShuming Fan regmap_read(rt1011->regmap, RT1011_EFUSE_DAC_OFFSET_G0_20_16, &value);
2279d6e65bb7SShuming Fan dc_offset = value << 16;
2280d6e65bb7SShuming Fan regmap_read(rt1011->regmap, RT1011_EFUSE_DAC_OFFSET_G0_15_0, &value);
2281d6e65bb7SShuming Fan dc_offset |= (value & 0xffff);
2282d6e65bb7SShuming Fan dev_info(dev, "Gain0 offset=0x%x\n", dc_offset);
2283d6e65bb7SShuming Fan regmap_read(rt1011->regmap, RT1011_EFUSE_DAC_OFFSET_G1_20_16, &value);
2284d6e65bb7SShuming Fan dc_offset = value << 16;
2285d6e65bb7SShuming Fan regmap_read(rt1011->regmap, RT1011_EFUSE_DAC_OFFSET_G1_15_0, &value);
2286d6e65bb7SShuming Fan dc_offset |= (value & 0xffff);
2287d6e65bb7SShuming Fan dev_info(dev, "Gain1 offset=0x%x\n", dc_offset);
2288d6e65bb7SShuming Fan
2289d6e65bb7SShuming Fan if (cali_flag) {
22900e4ba029SShuming Fan
22910e4ba029SShuming Fan regmap_write(rt1011->regmap, RT1011_ADC_SET_1, 0x2925);
2292d6e65bb7SShuming Fan /* Class D on */
2293d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_CLASS_D_POS, 0x010e);
2294d6e65bb7SShuming Fan regmap_write(rt1011->regmap,
2295d6e65bb7SShuming Fan RT1011_CLASSD_INTERNAL_SET_1, 0x1701);
2296d6e65bb7SShuming Fan
2297d6e65bb7SShuming Fan /* STP enable */
2298d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_SPK_TEMP_PROTECT_0, 0x8000);
2299d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_SPK_TEMP_PROTECT_7, 0xf000);
2300d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_SPK_TEMP_PROTECT_4, 0x4040);
2301d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_SPK_TEMP_PROTECT_0, 0xc000);
2302d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_SPK_TEMP_PROTECT_6, 0x07c2);
2303d6e65bb7SShuming Fan
2304d6e65bb7SShuming Fan r0[0] = r0[1] = r0[2] = count = 0;
2305d6e65bb7SShuming Fan while (count < chk_cnt) {
2306d6e65bb7SShuming Fan msleep(100);
2307d6e65bb7SShuming Fan regmap_read(rt1011->regmap,
2308d6e65bb7SShuming Fan RT1011_INIT_RECIPROCAL_SYN_24_16, &value);
2309d6e65bb7SShuming Fan r0[count%3] = value << 16;
2310d6e65bb7SShuming Fan regmap_read(rt1011->regmap,
2311d6e65bb7SShuming Fan RT1011_INIT_RECIPROCAL_SYN_15_0, &value);
2312d6e65bb7SShuming Fan r0[count%3] |= value;
2313d6e65bb7SShuming Fan
2314d6e65bb7SShuming Fan if (r0[count%3] == 0)
2315d6e65bb7SShuming Fan continue;
2316d6e65bb7SShuming Fan
2317d6e65bb7SShuming Fan count++;
2318d6e65bb7SShuming Fan
2319d6e65bb7SShuming Fan if (r0[0] == r0[1] && r0[1] == r0[2])
2320d6e65bb7SShuming Fan break;
2321d6e65bb7SShuming Fan }
2322d6e65bb7SShuming Fan if (count > chk_cnt) {
2323d6e65bb7SShuming Fan dev_err(dev, "Calibrate R0 Failure\n");
2324d6e65bb7SShuming Fan ret = -EAGAIN;
2325d6e65bb7SShuming Fan } else {
232683a6edbbSNathan Chancellor format = 2147483648U; /* 2^24 * 128 */
2327d6e65bb7SShuming Fan r0_integer = format / r0[0] / 128;
2328d6e65bb7SShuming Fan r0_factor = ((format / r0[0] * 100) / 128)
2329d6e65bb7SShuming Fan - (r0_integer * 100);
2330d6e65bb7SShuming Fan rt1011->r0_reg = r0[0];
23310922c7a5SShuming Fan rt1011->cali_done = 1;
2332d6e65bb7SShuming Fan dev_info(dev, "r0 resistance about %d.%02d ohm, reg=0x%X\n",
2333d6e65bb7SShuming Fan r0_integer, r0_factor, r0[0]);
2334d6e65bb7SShuming Fan }
2335d6e65bb7SShuming Fan }
2336d6e65bb7SShuming Fan
2337d6e65bb7SShuming Fan /* depop */
2338d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_SPK_TEMP_PROTECT_0, 0x0000);
2339d6e65bb7SShuming Fan msleep(400);
2340d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_POWER_9, 0xa840);
2341d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_SPK_TEMP_PROTECT_6, 0x0702);
2342d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_MIXER_1, 0xffdd);
2343d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_CLASSD_INTERNAL_SET_1, 0x0701);
2344d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_DAC_SET_3, 0xe004);
2345d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_A_TEMP_SEN, 0x7f40);
2346d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_POWER_1, 0x0000);
2347d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_POWER_2, 0x0000);
2348d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_POWER_3, 0x0002);
2349d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_POWER_4, 0x00f2);
2350d6e65bb7SShuming Fan
2351d6e65bb7SShuming Fan regmap_write(rt1011->regmap, RT1011_RESET, 0x0000);
2352d6e65bb7SShuming Fan
2353d6e65bb7SShuming Fan if (cali_flag) {
2354d6e65bb7SShuming Fan if (count <= chk_cnt) {
2355d6e65bb7SShuming Fan regmap_write(rt1011->regmap,
2356d6e65bb7SShuming Fan RT1011_INIT_RECIPROCAL_REG_24_16,
2357d6e65bb7SShuming Fan ((r0[0]>>16) & 0x1ff));
2358d6e65bb7SShuming Fan regmap_write(rt1011->regmap,
2359d6e65bb7SShuming Fan RT1011_INIT_RECIPROCAL_REG_15_0,
2360d6e65bb7SShuming Fan (r0[0] & 0xffff));
2361d6e65bb7SShuming Fan regmap_write(rt1011->regmap,
2362d6e65bb7SShuming Fan RT1011_SPK_TEMP_PROTECT_4, 0x4080);
2363d6e65bb7SShuming Fan }
2364d6e65bb7SShuming Fan }
2365d6e65bb7SShuming Fan
2366d6e65bb7SShuming Fan regcache_cache_bypass(rt1011->regmap, false);
2367d6e65bb7SShuming Fan regcache_mark_dirty(rt1011->regmap);
2368d6e65bb7SShuming Fan regcache_sync(rt1011->regmap);
2369d6e65bb7SShuming Fan snd_soc_dapm_mutex_unlock(dapm);
2370d6e65bb7SShuming Fan
2371d6e65bb7SShuming Fan return ret;
2372d6e65bb7SShuming Fan }
2373d6e65bb7SShuming Fan
rt1011_calibration_work(struct work_struct * work)2374d6e65bb7SShuming Fan static void rt1011_calibration_work(struct work_struct *work)
2375d6e65bb7SShuming Fan {
2376d6e65bb7SShuming Fan struct rt1011_priv *rt1011 =
2377d6e65bb7SShuming Fan container_of(work, struct rt1011_priv, cali_work);
2378d6e65bb7SShuming Fan struct snd_soc_component *component = rt1011->component;
23798de6e755SShuming Fan unsigned int r0_integer, r0_factor, format;
2380d6e65bb7SShuming Fan
23818de6e755SShuming Fan if (rt1011->r0_calib)
23828de6e755SShuming Fan rt1011_calibrate(rt1011, 0);
23838de6e755SShuming Fan else
2384d6e65bb7SShuming Fan rt1011_calibrate(rt1011, 1);
2385d6e65bb7SShuming Fan
23860922c7a5SShuming Fan /*
23870922c7a5SShuming Fan * This flag should reset after booting.
23880922c7a5SShuming Fan * The factory test will do calibration again and use this flag to check
23890922c7a5SShuming Fan * whether the calibration completed
23900922c7a5SShuming Fan */
23910922c7a5SShuming Fan rt1011->cali_done = 0;
23920922c7a5SShuming Fan
2393d6e65bb7SShuming Fan /* initial */
2394d6e65bb7SShuming Fan rt1011_reg_init(component);
23958de6e755SShuming Fan
23968de6e755SShuming Fan /* Apply temperature and calibration data from device property */
239798b6b8dfSShuming Fan if (rt1011->temperature_calib <= 0xff &&
239898b6b8dfSShuming Fan rt1011->temperature_calib > 0) {
23998de6e755SShuming Fan snd_soc_component_update_bits(component,
24008de6e755SShuming Fan RT1011_STP_INITIAL_RESISTANCE_TEMP, 0x3ff,
24018de6e755SShuming Fan (rt1011->temperature_calib << 2));
24028de6e755SShuming Fan }
24038de6e755SShuming Fan
24048de6e755SShuming Fan if (rt1011->r0_calib) {
24058de6e755SShuming Fan rt1011->r0_reg = rt1011->r0_calib;
24068de6e755SShuming Fan
24078de6e755SShuming Fan format = 2147483648U; /* 2^24 * 128 */
24088de6e755SShuming Fan r0_integer = format / rt1011->r0_reg / 128;
24098de6e755SShuming Fan r0_factor = ((format / rt1011->r0_reg * 100) / 128)
24108de6e755SShuming Fan - (r0_integer * 100);
24118de6e755SShuming Fan dev_info(component->dev, "DP r0 resistance about %d.%02d ohm, reg=0x%X\n",
24128de6e755SShuming Fan r0_integer, r0_factor, rt1011->r0_reg);
24138de6e755SShuming Fan
24148de6e755SShuming Fan rt1011_r0_load(rt1011);
24158de6e755SShuming Fan }
24160e4ba029SShuming Fan
24170e4ba029SShuming Fan snd_soc_component_write(component, RT1011_ADC_SET_1, 0x2925);
24188de6e755SShuming Fan }
24198de6e755SShuming Fan
rt1011_parse_dp(struct rt1011_priv * rt1011,struct device * dev)24208de6e755SShuming Fan static int rt1011_parse_dp(struct rt1011_priv *rt1011, struct device *dev)
24218de6e755SShuming Fan {
24228de6e755SShuming Fan device_property_read_u32(dev, "realtek,temperature_calib",
24238de6e755SShuming Fan &rt1011->temperature_calib);
24248de6e755SShuming Fan device_property_read_u32(dev, "realtek,r0_calib",
24258de6e755SShuming Fan &rt1011->r0_calib);
24268de6e755SShuming Fan
2427349959a9SColin Ian King dev_dbg(dev, "%s: r0_calib: 0x%x, temperature_calib: 0x%x",
24288de6e755SShuming Fan __func__, rt1011->r0_calib, rt1011->temperature_calib);
24298de6e755SShuming Fan
24308de6e755SShuming Fan return 0;
2431d6e65bb7SShuming Fan }
2432d6e65bb7SShuming Fan
rt1011_i2c_probe(struct i2c_client * i2c)243335b88858SStephen Kitt static int rt1011_i2c_probe(struct i2c_client *i2c)
2434d6e65bb7SShuming Fan {
2435d6e65bb7SShuming Fan struct rt1011_priv *rt1011;
2436d6e65bb7SShuming Fan int ret;
2437d6e65bb7SShuming Fan unsigned int val;
2438d6e65bb7SShuming Fan
2439d6e65bb7SShuming Fan rt1011 = devm_kzalloc(&i2c->dev, sizeof(struct rt1011_priv),
2440d6e65bb7SShuming Fan GFP_KERNEL);
2441683b8515SShuming Fan if (!rt1011)
2442d6e65bb7SShuming Fan return -ENOMEM;
2443d6e65bb7SShuming Fan
2444d6e65bb7SShuming Fan i2c_set_clientdata(i2c, rt1011);
2445d6e65bb7SShuming Fan
24468de6e755SShuming Fan rt1011_parse_dp(rt1011, &i2c->dev);
24478de6e755SShuming Fan
2448d6e65bb7SShuming Fan rt1011->regmap = devm_regmap_init_i2c(i2c, &rt1011_regmap);
2449d6e65bb7SShuming Fan if (IS_ERR(rt1011->regmap)) {
2450d6e65bb7SShuming Fan ret = PTR_ERR(rt1011->regmap);
2451d6e65bb7SShuming Fan dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
2452d6e65bb7SShuming Fan ret);
2453d6e65bb7SShuming Fan return ret;
2454d6e65bb7SShuming Fan }
2455d6e65bb7SShuming Fan
2456d6e65bb7SShuming Fan regmap_read(rt1011->regmap, RT1011_DEVICE_ID, &val);
2457d6e65bb7SShuming Fan if (val != RT1011_DEVICE_ID_NUM) {
2458d6e65bb7SShuming Fan dev_err(&i2c->dev,
2459d6e65bb7SShuming Fan "Device with ID register %x is not rt1011\n", val);
2460d6e65bb7SShuming Fan return -ENODEV;
2461d6e65bb7SShuming Fan }
2462d6e65bb7SShuming Fan
2463d6e65bb7SShuming Fan INIT_WORK(&rt1011->cali_work, rt1011_calibration_work);
2464d6e65bb7SShuming Fan
2465d6e65bb7SShuming Fan return devm_snd_soc_register_component(&i2c->dev,
2466d6e65bb7SShuming Fan &soc_component_dev_rt1011,
2467d6e65bb7SShuming Fan rt1011_dai, ARRAY_SIZE(rt1011_dai));
2468d6e65bb7SShuming Fan
2469d6e65bb7SShuming Fan }
2470d6e65bb7SShuming Fan
rt1011_i2c_shutdown(struct i2c_client * client)2471d6e65bb7SShuming Fan static void rt1011_i2c_shutdown(struct i2c_client *client)
2472d6e65bb7SShuming Fan {
2473d6e65bb7SShuming Fan struct rt1011_priv *rt1011 = i2c_get_clientdata(client);
2474d6e65bb7SShuming Fan
2475d6e65bb7SShuming Fan rt1011_reset(rt1011->regmap);
2476d6e65bb7SShuming Fan }
2477d6e65bb7SShuming Fan
2478d6e65bb7SShuming Fan static struct i2c_driver rt1011_i2c_driver = {
2479d6e65bb7SShuming Fan .driver = {
2480d6e65bb7SShuming Fan .name = "rt1011",
2481d6e65bb7SShuming Fan .of_match_table = of_match_ptr(rt1011_of_match),
2482d6e65bb7SShuming Fan .acpi_match_table = ACPI_PTR(rt1011_acpi_match)
2483d6e65bb7SShuming Fan },
24849abcd240SUwe Kleine-König .probe = rt1011_i2c_probe,
2485d6e65bb7SShuming Fan .shutdown = rt1011_i2c_shutdown,
2486d6e65bb7SShuming Fan .id_table = rt1011_i2c_id,
2487d6e65bb7SShuming Fan };
2488d6e65bb7SShuming Fan module_i2c_driver(rt1011_i2c_driver);
2489d6e65bb7SShuming Fan
2490d6e65bb7SShuming Fan MODULE_DESCRIPTION("ASoC RT1011 amplifier driver");
2491d6e65bb7SShuming Fan MODULE_AUTHOR("Shuming Fan <shumingf@realtek.com>");
2492d6e65bb7SShuming Fan MODULE_LICENSE("GPL");
2493