blob: 6ecb7ddae9cf22a646a9f69163f4f22e63abc616 [file] [log] [blame]
Brian Austin6387f862017-03-06 08:07:59 -06001/*
2 * cs35l35.c -- CS35L35 ALSA SoC audio driver
3 *
4 * Copyright 2017 Cirrus Logic, Inc.
5 *
6 * Author: Brian Austin <brian.austin@cirrus.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 */
13
14#include <linux/module.h>
15#include <linux/moduleparam.h>
16#include <linux/version.h>
17#include <linux/kernel.h>
18#include <linux/init.h>
19#include <linux/delay.h>
20#include <linux/i2c.h>
21#include <linux/slab.h>
22#include <linux/platform_device.h>
23#include <linux/regulator/consumer.h>
24#include <linux/gpio/consumer.h>
25#include <linux/of_device.h>
26#include <linux/of_gpio.h>
27#include <linux/regmap.h>
28#include <sound/core.h>
29#include <sound/pcm.h>
30#include <sound/pcm_params.h>
31#include <sound/soc.h>
32#include <sound/soc-dapm.h>
33#include <linux/gpio.h>
34#include <sound/initval.h>
35#include <sound/tlv.h>
36#include <sound/cs35l35.h>
37#include <linux/of_irq.h>
38#include <linux/completion.h>
39
40#include "cs35l35.h"
41
42/*
43 * Some fields take zero as a valid value so use a high bit flag that won't
44 * get written to the device to mark those.
45 */
46#define CS35L35_VALID_PDATA 0x80000000
47
48static const struct reg_default cs35l35_reg[] = {
49 {CS35L35_PWRCTL1, 0x01},
50 {CS35L35_PWRCTL2, 0x11},
51 {CS35L35_PWRCTL3, 0x00},
52 {CS35L35_CLK_CTL1, 0x04},
53 {CS35L35_CLK_CTL2, 0x10},
54 {CS35L35_CLK_CTL3, 0xCF},
55 {CS35L35_SP_FMT_CTL1, 0x20},
56 {CS35L35_SP_FMT_CTL2, 0x00},
57 {CS35L35_SP_FMT_CTL3, 0x02},
58 {CS35L35_MAG_COMP_CTL, 0x00},
59 {CS35L35_AMP_INP_DRV_CTL, 0x01},
60 {CS35L35_AMP_DIG_VOL_CTL, 0x12},
61 {CS35L35_AMP_DIG_VOL, 0x00},
62 {CS35L35_ADV_DIG_VOL, 0x00},
63 {CS35L35_PROTECT_CTL, 0x06},
64 {CS35L35_AMP_GAIN_AUD_CTL, 0x13},
65 {CS35L35_AMP_GAIN_PDM_CTL, 0x00},
66 {CS35L35_AMP_GAIN_ADV_CTL, 0x00},
67 {CS35L35_GPI_CTL, 0x00},
68 {CS35L35_BST_CVTR_V_CTL, 0x00},
69 {CS35L35_BST_PEAK_I, 0x07},
70 {CS35L35_BST_RAMP_CTL, 0x85},
71 {CS35L35_BST_CONV_COEF_1, 0x24},
72 {CS35L35_BST_CONV_COEF_2, 0x24},
73 {CS35L35_BST_CONV_SLOPE_COMP, 0x47},
74 {CS35L35_BST_CONV_SW_FREQ, 0x04},
75 {CS35L35_CLASS_H_CTL, 0x0B},
76 {CS35L35_CLASS_H_HEADRM_CTL, 0x0B},
77 {CS35L35_CLASS_H_RELEASE_RATE, 0x08},
78 {CS35L35_CLASS_H_FET_DRIVE_CTL, 0x41},
79 {CS35L35_CLASS_H_VP_CTL, 0xC5},
80 {CS35L35_VPBR_CTL, 0x0A},
81 {CS35L35_VPBR_VOL_CTL, 0x09},
82 {CS35L35_VPBR_TIMING_CTL, 0x6A},
83 {CS35L35_VPBR_MODE_VOL_CTL, 0x40},
84 {CS35L35_SPKR_MON_CTL, 0xC0},
85 {CS35L35_IMON_SCALE_CTL, 0x30},
86 {CS35L35_AUDIN_RXLOC_CTL, 0x00},
87 {CS35L35_ADVIN_RXLOC_CTL, 0x80},
88 {CS35L35_VMON_TXLOC_CTL, 0x00},
89 {CS35L35_IMON_TXLOC_CTL, 0x80},
90 {CS35L35_VPMON_TXLOC_CTL, 0x04},
91 {CS35L35_VBSTMON_TXLOC_CTL, 0x84},
92 {CS35L35_VPBR_STATUS_TXLOC_CTL, 0x04},
93 {CS35L35_ZERO_FILL_LOC_CTL, 0x00},
94 {CS35L35_AUDIN_DEPTH_CTL, 0x0F},
95 {CS35L35_SPKMON_DEPTH_CTL, 0x0F},
96 {CS35L35_SUPMON_DEPTH_CTL, 0x0F},
97 {CS35L35_ZEROFILL_DEPTH_CTL, 0x00},
98 {CS35L35_MULT_DEV_SYNCH1, 0x02},
99 {CS35L35_MULT_DEV_SYNCH2, 0x80},
100 {CS35L35_PROT_RELEASE_CTL, 0x00},
101 {CS35L35_DIAG_MODE_REG_LOCK, 0x00},
102 {CS35L35_DIAG_MODE_CTL_1, 0x40},
103 {CS35L35_DIAG_MODE_CTL_2, 0x00},
104 {CS35L35_INT_MASK_1, 0xFF},
105 {CS35L35_INT_MASK_2, 0xFF},
106 {CS35L35_INT_MASK_3, 0xFF},
107 {CS35L35_INT_MASK_4, 0xFF},
108
109};
110
111static bool cs35l35_volatile_register(struct device *dev, unsigned int reg)
112{
113 switch (reg) {
114 case CS35L35_INT_STATUS_1:
115 case CS35L35_INT_STATUS_2:
116 case CS35L35_INT_STATUS_3:
117 case CS35L35_INT_STATUS_4:
118 case CS35L35_PLL_STATUS:
119 case CS35L35_OTP_TRIM_STATUS:
120 return true;
121 default:
122 return false;
123 }
124}
125
126static bool cs35l35_readable_register(struct device *dev, unsigned int reg)
127{
128 switch (reg) {
129 case CS35L35_DEVID_AB ... CS35L35_PWRCTL3:
130 case CS35L35_CLK_CTL1 ... CS35L35_SP_FMT_CTL3:
131 case CS35L35_MAG_COMP_CTL ... CS35L35_AMP_GAIN_AUD_CTL:
132 case CS35L35_AMP_GAIN_PDM_CTL ... CS35L35_BST_PEAK_I:
133 case CS35L35_BST_RAMP_CTL ... CS35L35_BST_CONV_SW_FREQ:
134 case CS35L35_CLASS_H_CTL ... CS35L35_CLASS_H_VP_CTL:
135 case CS35L35_CLASS_H_STATUS:
136 case CS35L35_VPBR_CTL ... CS35L35_VPBR_MODE_VOL_CTL:
137 case CS35L35_VPBR_ATTEN_STATUS:
138 case CS35L35_SPKR_MON_CTL:
139 case CS35L35_IMON_SCALE_CTL ... CS35L35_ZEROFILL_DEPTH_CTL:
140 case CS35L35_MULT_DEV_SYNCH1 ... CS35L35_PROT_RELEASE_CTL:
141 case CS35L35_DIAG_MODE_REG_LOCK ... CS35L35_DIAG_MODE_CTL_2:
142 case CS35L35_INT_MASK_1 ... CS35L35_PLL_STATUS:
143 case CS35L35_OTP_TRIM_STATUS:
144 return true;
145 default:
146 return false;
147 }
148}
149
150static bool cs35l35_precious_register(struct device *dev, unsigned int reg)
151{
152 switch (reg) {
153 case CS35L35_INT_STATUS_1:
154 case CS35L35_INT_STATUS_2:
155 case CS35L35_INT_STATUS_3:
156 case CS35L35_INT_STATUS_4:
157 case CS35L35_PLL_STATUS:
158 case CS35L35_OTP_TRIM_STATUS:
159 return true;
160 default:
161 return false;
162 }
163}
164
Charles Keepax77b329d2017-04-06 13:52:13 +0100165static int cs35l35_wait_for_pdn(struct cs35l35_private *cs35l35)
166{
167 int ret;
168
169 if (cs35l35->pdata.ext_bst) {
170 usleep_range(5000, 5500);
171 return 0;
172 }
173
174 reinit_completion(&cs35l35->pdn_done);
175
176 ret = wait_for_completion_timeout(&cs35l35->pdn_done,
177 msecs_to_jiffies(100));
178 if (ret == 0) {
179 dev_err(cs35l35->dev, "PDN_DONE did not complete\n");
180 return -ETIMEDOUT;
181 }
182
183 return 0;
184}
185
Brian Austin6387f862017-03-06 08:07:59 -0600186static int cs35l35_sdin_event(struct snd_soc_dapm_widget *w,
187 struct snd_kcontrol *kcontrol, int event)
188{
189 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
190 struct cs35l35_private *cs35l35 = snd_soc_codec_get_drvdata(codec);
191 int ret = 0;
192
193 switch (event) {
194 case SND_SOC_DAPM_PRE_PMU:
195 regmap_update_bits(cs35l35->regmap, CS35L35_CLK_CTL1,
196 CS35L35_MCLK_DIS_MASK,
197 0 << CS35L35_MCLK_DIS_SHIFT);
198 regmap_update_bits(cs35l35->regmap, CS35L35_PWRCTL1,
199 CS35L35_DISCHG_FILT_MASK,
200 0 << CS35L35_DISCHG_FILT_SHIFT);
201 regmap_update_bits(cs35l35->regmap, CS35L35_PWRCTL1,
202 CS35L35_PDN_ALL_MASK, 0);
203 break;
204 case SND_SOC_DAPM_POST_PMD:
205 regmap_update_bits(cs35l35->regmap, CS35L35_PWRCTL1,
206 CS35L35_DISCHG_FILT_MASK,
207 1 << CS35L35_DISCHG_FILT_SHIFT);
208 regmap_update_bits(cs35l35->regmap, CS35L35_PWRCTL1,
209 CS35L35_PDN_ALL_MASK, 1);
210
Charles Keepax2c84afb2017-04-06 13:52:12 +0100211 /* Already muted, so disable volume ramp for faster shutdown */
212 regmap_update_bits(cs35l35->regmap, CS35L35_AMP_DIG_VOL_CTL,
213 CS35L35_AMP_DIGSFT_MASK, 0);
214
Charles Keepax77b329d2017-04-06 13:52:13 +0100215 ret = cs35l35_wait_for_pdn(cs35l35);
Brian Austin6387f862017-03-06 08:07:59 -0600216
217 regmap_update_bits(cs35l35->regmap, CS35L35_CLK_CTL1,
218 CS35L35_MCLK_DIS_MASK,
219 1 << CS35L35_MCLK_DIS_SHIFT);
Charles Keepax2c84afb2017-04-06 13:52:12 +0100220
221 regmap_update_bits(cs35l35->regmap, CS35L35_AMP_DIG_VOL_CTL,
222 CS35L35_AMP_DIGSFT_MASK,
223 1 << CS35L35_AMP_DIGSFT_SHIFT);
Brian Austin6387f862017-03-06 08:07:59 -0600224 break;
225 default:
226 dev_err(codec->dev, "Invalid event = 0x%x\n", event);
227 ret = -EINVAL;
228 }
229 return ret;
230}
231
232static int cs35l35_main_amp_event(struct snd_soc_dapm_widget *w,
233 struct snd_kcontrol *kcontrol, int event)
234{
235 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
236 struct cs35l35_private *cs35l35 = snd_soc_codec_get_drvdata(codec);
237 unsigned int reg[4];
238 int i;
239
240 switch (event) {
241 case SND_SOC_DAPM_PRE_PMU:
242 if (cs35l35->pdata.bst_pdn_fet_on)
243 regmap_update_bits(cs35l35->regmap, CS35L35_PWRCTL2,
244 CS35L35_PDN_BST_MASK,
245 0 << CS35L35_PDN_BST_FETON_SHIFT);
246 else
247 regmap_update_bits(cs35l35->regmap, CS35L35_PWRCTL2,
248 CS35L35_PDN_BST_MASK,
249 0 << CS35L35_PDN_BST_FETOFF_SHIFT);
250 break;
251 case SND_SOC_DAPM_POST_PMU:
252 usleep_range(5000, 5100);
253 /* If in PDM mode we must use VP for Voltage control */
254 if (cs35l35->pdm_mode)
255 regmap_update_bits(cs35l35->regmap,
256 CS35L35_BST_CVTR_V_CTL,
257 CS35L35_BST_CTL_MASK,
258 0 << CS35L35_BST_CTL_SHIFT);
259
260 regmap_update_bits(cs35l35->regmap, CS35L35_PROTECT_CTL,
261 CS35L35_AMP_MUTE_MASK, 0);
262
263 for (i = 0; i < 2; i++)
264 regmap_bulk_read(cs35l35->regmap, CS35L35_INT_STATUS_1,
265 &reg, ARRAY_SIZE(reg));
266
267 break;
268 case SND_SOC_DAPM_PRE_PMD:
269 regmap_update_bits(cs35l35->regmap, CS35L35_PROTECT_CTL,
270 CS35L35_AMP_MUTE_MASK,
271 1 << CS35L35_AMP_MUTE_SHIFT);
272 if (cs35l35->pdata.bst_pdn_fet_on)
273 regmap_update_bits(cs35l35->regmap, CS35L35_PWRCTL2,
274 CS35L35_PDN_BST_MASK,
275 1 << CS35L35_PDN_BST_FETON_SHIFT);
276 else
277 regmap_update_bits(cs35l35->regmap, CS35L35_PWRCTL2,
278 CS35L35_PDN_BST_MASK,
279 1 << CS35L35_PDN_BST_FETOFF_SHIFT);
280 break;
281 case SND_SOC_DAPM_POST_PMD:
282 usleep_range(5000, 5100);
283 /*
284 * If PDM mode we should switch back to pdata value
285 * for Voltage control when we go down
286 */
287 if (cs35l35->pdm_mode)
288 regmap_update_bits(cs35l35->regmap,
289 CS35L35_BST_CVTR_V_CTL,
290 CS35L35_BST_CTL_MASK,
291 cs35l35->pdata.bst_vctl
292 << CS35L35_BST_CTL_SHIFT);
293
294 break;
295 default:
296 dev_err(codec->dev, "Invalid event = 0x%x\n", event);
297 }
298 return 0;
299}
300
301static DECLARE_TLV_DB_SCALE(amp_gain_tlv, 0, 1, 1);
302static DECLARE_TLV_DB_SCALE(dig_vol_tlv, -10200, 50, 0);
303
304static const struct snd_kcontrol_new cs35l35_aud_controls[] = {
305 SOC_SINGLE_SX_TLV("Digital Audio Volume", CS35L35_AMP_DIG_VOL,
306 0, 0x34, 0xE4, dig_vol_tlv),
307 SOC_SINGLE_TLV("Analog Audio Volume", CS35L35_AMP_GAIN_AUD_CTL, 0, 19, 0,
308 amp_gain_tlv),
309 SOC_SINGLE_TLV("PDM Volume", CS35L35_AMP_GAIN_PDM_CTL, 0, 19, 0,
310 amp_gain_tlv),
311};
312
313static const struct snd_kcontrol_new cs35l35_adv_controls[] = {
314 SOC_SINGLE_SX_TLV("Digital Advisory Volume", CS35L35_ADV_DIG_VOL,
315 0, 0x34, 0xE4, dig_vol_tlv),
316 SOC_SINGLE_TLV("Analog Advisory Volume", CS35L35_AMP_GAIN_ADV_CTL, 0, 19, 0,
317 amp_gain_tlv),
318};
319
320static const struct snd_soc_dapm_widget cs35l35_dapm_widgets[] = {
321 SND_SOC_DAPM_AIF_IN_E("SDIN", NULL, 0, CS35L35_PWRCTL3, 1, 1,
322 cs35l35_sdin_event, SND_SOC_DAPM_PRE_PMU |
323 SND_SOC_DAPM_POST_PMD),
324 SND_SOC_DAPM_AIF_OUT("SDOUT", NULL, 0, CS35L35_PWRCTL3, 2, 1),
325
326 SND_SOC_DAPM_OUTPUT("SPK"),
327
328 SND_SOC_DAPM_INPUT("VP"),
329 SND_SOC_DAPM_INPUT("VBST"),
330 SND_SOC_DAPM_INPUT("ISENSE"),
331 SND_SOC_DAPM_INPUT("VSENSE"),
332
333 SND_SOC_DAPM_ADC("VMON ADC", NULL, CS35L35_PWRCTL2, 7, 1),
334 SND_SOC_DAPM_ADC("IMON ADC", NULL, CS35L35_PWRCTL2, 6, 1),
335 SND_SOC_DAPM_ADC("VPMON ADC", NULL, CS35L35_PWRCTL3, 3, 1),
336 SND_SOC_DAPM_ADC("VBSTMON ADC", NULL, CS35L35_PWRCTL3, 4, 1),
337 SND_SOC_DAPM_ADC("CLASS H", NULL, CS35L35_PWRCTL2, 5, 1),
338
339 SND_SOC_DAPM_OUT_DRV_E("Main AMP", CS35L35_PWRCTL2, 0, 1, NULL, 0,
340 cs35l35_main_amp_event, SND_SOC_DAPM_PRE_PMU |
341 SND_SOC_DAPM_POST_PMD | SND_SOC_DAPM_POST_PMU |
342 SND_SOC_DAPM_PRE_PMD),
343};
344
345static const struct snd_soc_dapm_route cs35l35_audio_map[] = {
346 {"VPMON ADC", NULL, "VP"},
347 {"VBSTMON ADC", NULL, "VBST"},
348 {"IMON ADC", NULL, "ISENSE"},
349 {"VMON ADC", NULL, "VSENSE"},
350 {"SDOUT", NULL, "IMON ADC"},
351 {"SDOUT", NULL, "VMON ADC"},
352 {"SDOUT", NULL, "VBSTMON ADC"},
353 {"SDOUT", NULL, "VPMON ADC"},
354 {"AMP Capture", NULL, "SDOUT"},
355
356 {"SDIN", NULL, "AMP Playback"},
357 {"CLASS H", NULL, "SDIN"},
358 {"Main AMP", NULL, "CLASS H"},
359 {"SPK", NULL, "Main AMP"},
360};
361
362static int cs35l35_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
363{
364 struct snd_soc_codec *codec = codec_dai->codec;
365 struct cs35l35_private *cs35l35 = snd_soc_codec_get_drvdata(codec);
366
367 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
368 case SND_SOC_DAIFMT_CBM_CFM:
369 regmap_update_bits(cs35l35->regmap, CS35L35_CLK_CTL1,
370 CS35L35_MS_MASK, 1 << CS35L35_MS_SHIFT);
371 cs35l35->slave_mode = false;
372 break;
373 case SND_SOC_DAIFMT_CBS_CFS:
374 regmap_update_bits(cs35l35->regmap, CS35L35_CLK_CTL1,
375 CS35L35_MS_MASK, 0 << CS35L35_MS_SHIFT);
376 cs35l35->slave_mode = true;
377 break;
378 default:
379 return -EINVAL;
380 }
381
382 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
383 case SND_SOC_DAIFMT_I2S:
384 cs35l35->i2s_mode = true;
385 cs35l35->pdm_mode = false;
386 break;
387 case SND_SOC_DAIFMT_PDM:
388 cs35l35->pdm_mode = true;
389 cs35l35->i2s_mode = false;
390 break;
391 default:
392 return -EINVAL;
393 }
394
395 return 0;
396}
397
398struct cs35l35_sysclk_config {
399 int sysclk;
400 int srate;
401 u8 clk_cfg;
402};
403
404static struct cs35l35_sysclk_config cs35l35_clk_ctl[] = {
405
406 /* SYSCLK, Sample Rate, Serial Port Cfg */
407 {5644800, 44100, 0x00},
408 {5644800, 88200, 0x40},
409 {6144000, 48000, 0x10},
410 {6144000, 96000, 0x50},
411 {11289600, 44100, 0x01},
412 {11289600, 88200, 0x41},
413 {11289600, 176400, 0x81},
414 {12000000, 44100, 0x03},
415 {12000000, 48000, 0x13},
416 {12000000, 88200, 0x43},
417 {12000000, 96000, 0x53},
418 {12000000, 176400, 0x83},
419 {12000000, 192000, 0x93},
420 {12288000, 48000, 0x11},
421 {12288000, 96000, 0x51},
422 {12288000, 192000, 0x91},
423 {13000000, 44100, 0x07},
424 {13000000, 48000, 0x17},
425 {13000000, 88200, 0x47},
426 {13000000, 96000, 0x57},
427 {13000000, 176400, 0x87},
428 {13000000, 192000, 0x97},
429 {22579200, 44100, 0x02},
430 {22579200, 88200, 0x42},
431 {22579200, 176400, 0x82},
432 {24000000, 44100, 0x0B},
433 {24000000, 48000, 0x1B},
434 {24000000, 88200, 0x4B},
435 {24000000, 96000, 0x5B},
436 {24000000, 176400, 0x8B},
437 {24000000, 192000, 0x9B},
438 {24576000, 48000, 0x12},
439 {24576000, 96000, 0x52},
440 {24576000, 192000, 0x92},
441 {26000000, 44100, 0x0F},
442 {26000000, 48000, 0x1F},
443 {26000000, 88200, 0x4F},
444 {26000000, 96000, 0x5F},
445 {26000000, 176400, 0x8F},
446 {26000000, 192000, 0x9F},
447};
448
449static int cs35l35_get_clk_config(int sysclk, int srate)
450{
451 int i;
452
453 for (i = 0; i < ARRAY_SIZE(cs35l35_clk_ctl); i++) {
454 if (cs35l35_clk_ctl[i].sysclk == sysclk &&
455 cs35l35_clk_ctl[i].srate == srate)
456 return cs35l35_clk_ctl[i].clk_cfg;
457 }
458 return -EINVAL;
459}
460
461static int cs35l35_hw_params(struct snd_pcm_substream *substream,
462 struct snd_pcm_hw_params *params,
463 struct snd_soc_dai *dai)
464{
465 struct snd_soc_codec *codec = dai->codec;
466 struct cs35l35_private *cs35l35 = snd_soc_codec_get_drvdata(codec);
467 struct classh_cfg *classh = &cs35l35->pdata.classh_algo;
468 int srate = params_rate(params);
469 int ret = 0;
470 u8 sp_sclks;
471 int audin_format;
472 int errata_chk;
473
474 int clk_ctl = cs35l35_get_clk_config(cs35l35->sysclk, srate);
475
476 if (clk_ctl < 0) {
477 dev_err(codec->dev, "Invalid CLK:Rate %d:%d\n",
478 cs35l35->sysclk, srate);
479 return -EINVAL;
480 }
481
482 ret = regmap_update_bits(cs35l35->regmap, CS35L35_CLK_CTL2,
483 CS35L35_CLK_CTL2_MASK, clk_ctl);
484 if (ret != 0) {
485 dev_err(codec->dev, "Failed to set port config %d\n", ret);
486 return ret;
487 }
488
489 /*
490 * Rev A0 Errata
491 * When configured for the weak-drive detection path (CH_WKFET_DIS = 0)
492 * the Class H algorithm does not enable weak-drive operation for
493 * nonzero values of CH_WKFET_DELAY if SP_RATE = 01 or 10
494 */
495 errata_chk = clk_ctl & CS35L35_SP_RATE_MASK;
496
497 if (classh->classh_wk_fet_disable == 0x00 &&
498 (errata_chk == 0x01 || errata_chk == 0x03)) {
499 ret = regmap_update_bits(cs35l35->regmap,
500 CS35L35_CLASS_H_FET_DRIVE_CTL,
501 CS35L35_CH_WKFET_DEL_MASK,
502 0 << CS35L35_CH_WKFET_DEL_SHIFT);
503 if (ret != 0) {
504 dev_err(codec->dev, "Failed to set fet config %d\n",
505 ret);
506 return ret;
507 }
508 }
509
510 /*
511 * You can pull more Monitor data from the SDOUT pin than going to SDIN
512 * Just make sure your SCLK is fast enough to fill the frame
513 */
514 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
515 switch (params_width(params)) {
516 case 8:
517 audin_format = CS35L35_SDIN_DEPTH_8;
518 break;
519 case 16:
520 audin_format = CS35L35_SDIN_DEPTH_16;
521 break;
522 case 24:
523 audin_format = CS35L35_SDIN_DEPTH_24;
524 break;
525 default:
526 dev_err(codec->dev, "Unsupported Width %d\n",
527 params_width(params));
528 return -EINVAL;
529 }
530 regmap_update_bits(cs35l35->regmap,
531 CS35L35_AUDIN_DEPTH_CTL,
532 CS35L35_AUDIN_DEPTH_MASK,
533 audin_format <<
534 CS35L35_AUDIN_DEPTH_SHIFT);
535 if (cs35l35->pdata.stereo) {
536 regmap_update_bits(cs35l35->regmap,
537 CS35L35_AUDIN_DEPTH_CTL,
538 CS35L35_ADVIN_DEPTH_MASK,
539 audin_format <<
540 CS35L35_ADVIN_DEPTH_SHIFT);
541 }
542 }
543
544 if (cs35l35->i2s_mode) {
545 /* We have to take the SCLK to derive num sclks
546 * to configure the CLOCK_CTL3 register correctly
547 */
548 if ((cs35l35->sclk / srate) % 4) {
549 dev_err(codec->dev, "Unsupported sclk/fs ratio %d:%d\n",
550 cs35l35->sclk, srate);
551 return -EINVAL;
552 }
553 sp_sclks = ((cs35l35->sclk / srate) / 4) - 1;
554
555 /* Only certain ratios are supported in I2S Slave Mode */
556 if (cs35l35->slave_mode) {
557 switch (sp_sclks) {
558 case CS35L35_SP_SCLKS_32FS:
559 case CS35L35_SP_SCLKS_48FS:
560 case CS35L35_SP_SCLKS_64FS:
561 break;
562 default:
563 dev_err(codec->dev, "ratio not supported\n");
564 return -EINVAL;
kbuild test robotf3a612a2017-03-12 09:11:32 +0800565 }
Brian Austin6387f862017-03-06 08:07:59 -0600566 } else {
567 /* Only certain ratios supported in I2S MASTER Mode */
568 switch (sp_sclks) {
569 case CS35L35_SP_SCLKS_32FS:
570 case CS35L35_SP_SCLKS_64FS:
571 break;
572 default:
573 dev_err(codec->dev, "ratio not supported\n");
574 return -EINVAL;
kbuild test robotf3a612a2017-03-12 09:11:32 +0800575 }
Brian Austin6387f862017-03-06 08:07:59 -0600576 }
577 ret = regmap_update_bits(cs35l35->regmap,
578 CS35L35_CLK_CTL3,
579 CS35L35_SP_SCLKS_MASK, sp_sclks <<
580 CS35L35_SP_SCLKS_SHIFT);
581 if (ret != 0) {
582 dev_err(codec->dev, "Failed to set fsclk %d\n", ret);
583 return ret;
584 }
585 }
586
587 return ret;
588}
589
590static const unsigned int cs35l35_src_rates[] = {
591 44100, 48000, 88200, 96000, 176400, 192000
592};
593
594static const struct snd_pcm_hw_constraint_list cs35l35_constraints = {
595 .count = ARRAY_SIZE(cs35l35_src_rates),
596 .list = cs35l35_src_rates,
597};
598
599static int cs35l35_pcm_startup(struct snd_pcm_substream *substream,
600 struct snd_soc_dai *dai)
601{
602 struct snd_soc_codec *codec = dai->codec;
603 struct cs35l35_private *cs35l35 = snd_soc_codec_get_drvdata(codec);
604
605 if (!substream->runtime)
606 return 0;
607
608 snd_pcm_hw_constraint_list(substream->runtime, 0,
609 SNDRV_PCM_HW_PARAM_RATE, &cs35l35_constraints);
610
611 regmap_update_bits(cs35l35->regmap, CS35L35_AMP_INP_DRV_CTL,
612 CS35L35_PDM_MODE_MASK,
613 0 << CS35L35_PDM_MODE_SHIFT);
614
615 return 0;
616}
617
618static const unsigned int cs35l35_pdm_rates[] = {
619 44100, 48000, 88200, 96000
620};
621
622static const struct snd_pcm_hw_constraint_list cs35l35_pdm_constraints = {
623 .count = ARRAY_SIZE(cs35l35_pdm_rates),
624 .list = cs35l35_pdm_rates,
625};
626
627static int cs35l35_pdm_startup(struct snd_pcm_substream *substream,
628 struct snd_soc_dai *dai)
629{
630 struct snd_soc_codec *codec = dai->codec;
631 struct cs35l35_private *cs35l35 = snd_soc_codec_get_drvdata(codec);
632
633 if (!substream->runtime)
634 return 0;
635
636 snd_pcm_hw_constraint_list(substream->runtime, 0,
637 SNDRV_PCM_HW_PARAM_RATE,
638 &cs35l35_pdm_constraints);
639
640 regmap_update_bits(cs35l35->regmap, CS35L35_AMP_INP_DRV_CTL,
641 CS35L35_PDM_MODE_MASK,
642 1 << CS35L35_PDM_MODE_SHIFT);
643
644 return 0;
645}
646
647static int cs35l35_dai_set_sysclk(struct snd_soc_dai *dai,
648 int clk_id, unsigned int freq, int dir)
649{
650 struct snd_soc_codec *codec = dai->codec;
651 struct cs35l35_private *cs35l35 = snd_soc_codec_get_drvdata(codec);
652
653 /* Need the SCLK Frequency regardless of sysclk source for I2S */
654 cs35l35->sclk = freq;
655
656 return 0;
657}
658
659static const struct snd_soc_dai_ops cs35l35_ops = {
660 .startup = cs35l35_pcm_startup,
661 .set_fmt = cs35l35_set_dai_fmt,
662 .hw_params = cs35l35_hw_params,
663 .set_sysclk = cs35l35_dai_set_sysclk,
664};
665
666static const struct snd_soc_dai_ops cs35l35_pdm_ops = {
667 .startup = cs35l35_pdm_startup,
668 .set_fmt = cs35l35_set_dai_fmt,
669 .hw_params = cs35l35_hw_params,
670};
671
672static struct snd_soc_dai_driver cs35l35_dai[] = {
673 {
674 .name = "cs35l35-pcm",
675 .id = 0,
676 .playback = {
677 .stream_name = "AMP Playback",
678 .channels_min = 1,
679 .channels_max = 8,
680 .rates = SNDRV_PCM_RATE_KNOT,
681 .formats = CS35L35_FORMATS,
682 },
683 .capture = {
684 .stream_name = "AMP Capture",
685 .channels_min = 1,
686 .channels_max = 8,
687 .rates = SNDRV_PCM_RATE_KNOT,
688 .formats = CS35L35_FORMATS,
689 },
690 .ops = &cs35l35_ops,
691 .symmetric_rates = 1,
692 },
693 {
694 .name = "cs35l35-pdm",
695 .id = 1,
696 .playback = {
697 .stream_name = "PDM Playback",
698 .channels_min = 1,
699 .channels_max = 2,
700 .rates = SNDRV_PCM_RATE_KNOT,
701 .formats = CS35L35_FORMATS,
702 },
703 .ops = &cs35l35_pdm_ops,
704 },
705};
706
707static int cs35l35_codec_set_sysclk(struct snd_soc_codec *codec,
708 int clk_id, int source, unsigned int freq,
709 int dir)
710{
711 struct cs35l35_private *cs35l35 = snd_soc_codec_get_drvdata(codec);
712 int clksrc;
713 int ret = 0;
714
715 switch (clk_id) {
716 case 0:
717 clksrc = CS35L35_CLK_SOURCE_MCLK;
718 break;
719 case 1:
720 clksrc = CS35L35_CLK_SOURCE_SCLK;
721 break;
722 case 2:
723 clksrc = CS35L35_CLK_SOURCE_PDM;
724 break;
725 default:
726 dev_err(codec->dev, "Invalid CLK Source\n");
727 return -EINVAL;
kbuild test robotf3a612a2017-03-12 09:11:32 +0800728 }
Brian Austin6387f862017-03-06 08:07:59 -0600729
730 switch (freq) {
731 case 5644800:
732 case 6144000:
733 case 11289600:
734 case 12000000:
735 case 12288000:
736 case 13000000:
737 case 22579200:
738 case 24000000:
739 case 24576000:
740 case 26000000:
741 cs35l35->sysclk = freq;
742 break;
743 default:
744 dev_err(codec->dev, "Invalid CLK Frequency Input : %d\n", freq);
745 return -EINVAL;
746 }
747
748 ret = regmap_update_bits(cs35l35->regmap, CS35L35_CLK_CTL1,
749 CS35L35_CLK_SOURCE_MASK,
750 clksrc << CS35L35_CLK_SOURCE_SHIFT);
751 if (ret != 0) {
752 dev_err(codec->dev, "Failed to set sysclk %d\n", ret);
753 return ret;
754 }
755
756 return ret;
757}
758
759static int cs35l35_codec_probe(struct snd_soc_codec *codec)
760{
761 struct cs35l35_private *cs35l35 = snd_soc_codec_get_drvdata(codec);
762 struct classh_cfg *classh = &cs35l35->pdata.classh_algo;
763 struct monitor_cfg *monitor_config = &cs35l35->pdata.mon_cfg;
764 int ret;
765
Brian Austin6387f862017-03-06 08:07:59 -0600766 /* Set Platform Data */
767 if (cs35l35->pdata.bst_vctl)
768 regmap_update_bits(cs35l35->regmap, CS35L35_BST_CVTR_V_CTL,
769 CS35L35_BST_CTL_MASK,
770 cs35l35->pdata.bst_vctl);
771
772 if (cs35l35->pdata.bst_ipk)
773 regmap_update_bits(cs35l35->regmap, CS35L35_BST_PEAK_I,
774 CS35L35_BST_IPK_MASK,
775 cs35l35->pdata.bst_ipk <<
776 CS35L35_BST_IPK_SHIFT);
777
778 if (cs35l35->pdata.gain_zc)
779 regmap_update_bits(cs35l35->regmap, CS35L35_PROTECT_CTL,
780 CS35L35_AMP_GAIN_ZC_MASK,
781 cs35l35->pdata.gain_zc <<
782 CS35L35_AMP_GAIN_ZC_SHIFT);
783
784 if (cs35l35->pdata.aud_channel)
785 regmap_update_bits(cs35l35->regmap,
786 CS35L35_AUDIN_RXLOC_CTL,
787 CS35L35_AUD_IN_LR_MASK,
788 cs35l35->pdata.aud_channel <<
789 CS35L35_AUD_IN_LR_SHIFT);
790
791 if (cs35l35->pdata.stereo) {
792 regmap_update_bits(cs35l35->regmap,
793 CS35L35_ADVIN_RXLOC_CTL,
794 CS35L35_ADV_IN_LR_MASK,
795 cs35l35->pdata.adv_channel <<
796 CS35L35_ADV_IN_LR_SHIFT);
797 if (cs35l35->pdata.shared_bst)
798 regmap_update_bits(cs35l35->regmap, CS35L35_CLASS_H_CTL,
799 CS35L35_CH_STEREO_MASK,
800 1 << CS35L35_CH_STEREO_SHIFT);
801 ret = snd_soc_add_codec_controls(codec, cs35l35_adv_controls,
802 ARRAY_SIZE(cs35l35_adv_controls));
803 if (ret)
804 return ret;
805 }
806
807 if (cs35l35->pdata.sp_drv_str)
808 regmap_update_bits(cs35l35->regmap, CS35L35_CLK_CTL1,
809 CS35L35_SP_DRV_MASK,
810 cs35l35->pdata.sp_drv_str <<
811 CS35L35_SP_DRV_SHIFT);
Charles Keepax8d45f2d2017-03-08 16:42:49 +0000812 if (cs35l35->pdata.sp_drv_unused)
813 regmap_update_bits(cs35l35->regmap, CS35L35_SP_FMT_CTL3,
814 CS35L35_SP_I2S_DRV_MASK,
815 cs35l35->pdata.sp_drv_unused <<
816 CS35L35_SP_I2S_DRV_SHIFT);
Brian Austin6387f862017-03-06 08:07:59 -0600817
818 if (classh->classh_algo_enable) {
819 if (classh->classh_bst_override)
820 regmap_update_bits(cs35l35->regmap,
821 CS35L35_CLASS_H_CTL,
822 CS35L35_CH_BST_OVR_MASK,
823 classh->classh_bst_override <<
824 CS35L35_CH_BST_OVR_SHIFT);
825 if (classh->classh_bst_max_limit)
826 regmap_update_bits(cs35l35->regmap,
827 CS35L35_CLASS_H_CTL,
828 CS35L35_CH_BST_LIM_MASK,
829 classh->classh_bst_max_limit <<
830 CS35L35_CH_BST_LIM_SHIFT);
831 if (classh->classh_mem_depth)
832 regmap_update_bits(cs35l35->regmap,
833 CS35L35_CLASS_H_CTL,
834 CS35L35_CH_MEM_DEPTH_MASK,
835 classh->classh_mem_depth <<
836 CS35L35_CH_MEM_DEPTH_SHIFT);
837 if (classh->classh_headroom)
838 regmap_update_bits(cs35l35->regmap,
839 CS35L35_CLASS_H_HEADRM_CTL,
840 CS35L35_CH_HDRM_CTL_MASK,
841 classh->classh_headroom <<
842 CS35L35_CH_HDRM_CTL_SHIFT);
843 if (classh->classh_release_rate)
844 regmap_update_bits(cs35l35->regmap,
845 CS35L35_CLASS_H_RELEASE_RATE,
846 CS35L35_CH_REL_RATE_MASK,
847 classh->classh_release_rate <<
848 CS35L35_CH_REL_RATE_SHIFT);
849 if (classh->classh_wk_fet_disable)
850 regmap_update_bits(cs35l35->regmap,
851 CS35L35_CLASS_H_FET_DRIVE_CTL,
852 CS35L35_CH_WKFET_DIS_MASK,
853 classh->classh_wk_fet_disable <<
854 CS35L35_CH_WKFET_DIS_SHIFT);
855 if (classh->classh_wk_fet_delay)
856 regmap_update_bits(cs35l35->regmap,
857 CS35L35_CLASS_H_FET_DRIVE_CTL,
858 CS35L35_CH_WKFET_DEL_MASK,
859 classh->classh_wk_fet_delay <<
860 CS35L35_CH_WKFET_DEL_SHIFT);
861 if (classh->classh_wk_fet_thld)
862 regmap_update_bits(cs35l35->regmap,
863 CS35L35_CLASS_H_FET_DRIVE_CTL,
864 CS35L35_CH_WKFET_THLD_MASK,
865 classh->classh_wk_fet_thld <<
866 CS35L35_CH_WKFET_THLD_SHIFT);
867 if (classh->classh_vpch_auto)
868 regmap_update_bits(cs35l35->regmap,
869 CS35L35_CLASS_H_VP_CTL,
870 CS35L35_CH_VP_AUTO_MASK,
871 classh->classh_vpch_auto <<
872 CS35L35_CH_VP_AUTO_SHIFT);
873 if (classh->classh_vpch_rate)
874 regmap_update_bits(cs35l35->regmap,
875 CS35L35_CLASS_H_VP_CTL,
876 CS35L35_CH_VP_RATE_MASK,
877 classh->classh_vpch_rate <<
878 CS35L35_CH_VP_RATE_SHIFT);
879 if (classh->classh_vpch_man)
880 regmap_update_bits(cs35l35->regmap,
881 CS35L35_CLASS_H_VP_CTL,
882 CS35L35_CH_VP_MAN_MASK,
883 classh->classh_vpch_man <<
884 CS35L35_CH_VP_MAN_SHIFT);
885 }
886
887 if (monitor_config->is_present) {
888 if (monitor_config->vmon_specs) {
889 regmap_update_bits(cs35l35->regmap,
890 CS35L35_SPKMON_DEPTH_CTL,
891 CS35L35_VMON_DEPTH_MASK,
892 monitor_config->vmon_dpth <<
893 CS35L35_VMON_DEPTH_SHIFT);
894 regmap_update_bits(cs35l35->regmap,
895 CS35L35_VMON_TXLOC_CTL,
896 CS35L35_MON_TXLOC_MASK,
897 monitor_config->vmon_loc <<
898 CS35L35_MON_TXLOC_SHIFT);
899 regmap_update_bits(cs35l35->regmap,
900 CS35L35_VMON_TXLOC_CTL,
901 CS35L35_MON_FRM_MASK,
902 monitor_config->vmon_frm <<
903 CS35L35_MON_FRM_SHIFT);
904 }
905 if (monitor_config->imon_specs) {
906 regmap_update_bits(cs35l35->regmap,
907 CS35L35_SPKMON_DEPTH_CTL,
908 CS35L35_IMON_DEPTH_MASK,
909 monitor_config->imon_dpth <<
910 CS35L35_IMON_DEPTH_SHIFT);
911 regmap_update_bits(cs35l35->regmap,
912 CS35L35_IMON_TXLOC_CTL,
913 CS35L35_MON_TXLOC_MASK,
914 monitor_config->imon_loc <<
915 CS35L35_MON_TXLOC_SHIFT);
916 regmap_update_bits(cs35l35->regmap,
917 CS35L35_IMON_TXLOC_CTL,
918 CS35L35_MON_FRM_MASK,
919 monitor_config->imon_frm <<
920 CS35L35_MON_FRM_SHIFT);
921 }
922 if (monitor_config->vpmon_specs) {
923 regmap_update_bits(cs35l35->regmap,
924 CS35L35_SUPMON_DEPTH_CTL,
925 CS35L35_VPMON_DEPTH_MASK,
926 monitor_config->vpmon_dpth <<
927 CS35L35_VPMON_DEPTH_SHIFT);
928 regmap_update_bits(cs35l35->regmap,
929 CS35L35_VPMON_TXLOC_CTL,
930 CS35L35_MON_TXLOC_MASK,
931 monitor_config->vpmon_loc <<
932 CS35L35_MON_TXLOC_SHIFT);
933 regmap_update_bits(cs35l35->regmap,
934 CS35L35_VPMON_TXLOC_CTL,
935 CS35L35_MON_FRM_MASK,
936 monitor_config->vpmon_frm <<
937 CS35L35_MON_FRM_SHIFT);
938 }
939 if (monitor_config->vbstmon_specs) {
940 regmap_update_bits(cs35l35->regmap,
941 CS35L35_SUPMON_DEPTH_CTL,
942 CS35L35_VBSTMON_DEPTH_MASK,
943 monitor_config->vpmon_dpth <<
944 CS35L35_VBSTMON_DEPTH_SHIFT);
945 regmap_update_bits(cs35l35->regmap,
946 CS35L35_VBSTMON_TXLOC_CTL,
947 CS35L35_MON_TXLOC_MASK,
948 monitor_config->vbstmon_loc <<
949 CS35L35_MON_TXLOC_SHIFT);
950 regmap_update_bits(cs35l35->regmap,
951 CS35L35_VBSTMON_TXLOC_CTL,
952 CS35L35_MON_FRM_MASK,
953 monitor_config->vbstmon_frm <<
954 CS35L35_MON_FRM_SHIFT);
955 }
956 if (monitor_config->vpbrstat_specs) {
957 regmap_update_bits(cs35l35->regmap,
958 CS35L35_SUPMON_DEPTH_CTL,
959 CS35L35_VPBRSTAT_DEPTH_MASK,
960 monitor_config->vpbrstat_dpth <<
961 CS35L35_VPBRSTAT_DEPTH_SHIFT);
962 regmap_update_bits(cs35l35->regmap,
963 CS35L35_VPBR_STATUS_TXLOC_CTL,
964 CS35L35_MON_TXLOC_MASK,
965 monitor_config->vpbrstat_loc <<
966 CS35L35_MON_TXLOC_SHIFT);
967 regmap_update_bits(cs35l35->regmap,
968 CS35L35_VPBR_STATUS_TXLOC_CTL,
969 CS35L35_MON_FRM_MASK,
970 monitor_config->vpbrstat_frm <<
971 CS35L35_MON_FRM_SHIFT);
972 }
973 if (monitor_config->zerofill_specs) {
974 regmap_update_bits(cs35l35->regmap,
975 CS35L35_SUPMON_DEPTH_CTL,
976 CS35L35_ZEROFILL_DEPTH_MASK,
977 monitor_config->zerofill_dpth <<
978 CS35L35_ZEROFILL_DEPTH_SHIFT);
979 regmap_update_bits(cs35l35->regmap,
980 CS35L35_ZERO_FILL_LOC_CTL,
981 CS35L35_MON_TXLOC_MASK,
982 monitor_config->zerofill_loc <<
983 CS35L35_MON_TXLOC_SHIFT);
984 regmap_update_bits(cs35l35->regmap,
985 CS35L35_ZERO_FILL_LOC_CTL,
986 CS35L35_MON_FRM_MASK,
987 monitor_config->zerofill_frm <<
988 CS35L35_MON_FRM_SHIFT);
989 }
990 }
991
Dan Carpenterbfe41c62017-03-13 15:32:37 +0300992 return 0;
Brian Austin6387f862017-03-06 08:07:59 -0600993}
994
995static struct snd_soc_codec_driver soc_codec_dev_cs35l35 = {
996 .probe = cs35l35_codec_probe,
997 .set_sysclk = cs35l35_codec_set_sysclk,
998 .component_driver = {
999 .dapm_widgets = cs35l35_dapm_widgets,
1000 .num_dapm_widgets = ARRAY_SIZE(cs35l35_dapm_widgets),
1001
1002 .dapm_routes = cs35l35_audio_map,
1003 .num_dapm_routes = ARRAY_SIZE(cs35l35_audio_map),
1004
1005 .controls = cs35l35_aud_controls,
1006 .num_controls = ARRAY_SIZE(cs35l35_aud_controls),
1007 },
1008
1009};
1010
1011static struct regmap_config cs35l35_regmap = {
1012 .reg_bits = 8,
1013 .val_bits = 8,
1014
1015 .max_register = CS35L35_MAX_REGISTER,
1016 .reg_defaults = cs35l35_reg,
1017 .num_reg_defaults = ARRAY_SIZE(cs35l35_reg),
1018 .volatile_reg = cs35l35_volatile_register,
1019 .readable_reg = cs35l35_readable_register,
1020 .precious_reg = cs35l35_precious_register,
1021 .cache_type = REGCACHE_RBTREE,
1022};
1023
1024static irqreturn_t cs35l35_irq(int irq, void *data)
1025{
1026 struct cs35l35_private *cs35l35 = data;
Brian Austin6387f862017-03-06 08:07:59 -06001027 unsigned int sticky1, sticky2, sticky3, sticky4;
1028 unsigned int mask1, mask2, mask3, mask4, current1;
1029
1030 /* ack the irq by reading all status registers */
1031 regmap_read(cs35l35->regmap, CS35L35_INT_STATUS_4, &sticky4);
1032 regmap_read(cs35l35->regmap, CS35L35_INT_STATUS_3, &sticky3);
1033 regmap_read(cs35l35->regmap, CS35L35_INT_STATUS_2, &sticky2);
1034 regmap_read(cs35l35->regmap, CS35L35_INT_STATUS_1, &sticky1);
1035
1036 regmap_read(cs35l35->regmap, CS35L35_INT_MASK_4, &mask4);
1037 regmap_read(cs35l35->regmap, CS35L35_INT_MASK_3, &mask3);
1038 regmap_read(cs35l35->regmap, CS35L35_INT_MASK_2, &mask2);
1039 regmap_read(cs35l35->regmap, CS35L35_INT_MASK_1, &mask1);
1040
1041 /* Check to see if unmasked bits are active */
1042 if (!(sticky1 & ~mask1) && !(sticky2 & ~mask2) && !(sticky3 & ~mask3)
1043 && !(sticky4 & ~mask4))
1044 return IRQ_NONE;
1045
1046 if (sticky2 & CS35L35_PDN_DONE)
1047 complete(&cs35l35->pdn_done);
1048
1049 /* read the current values */
1050 regmap_read(cs35l35->regmap, CS35L35_INT_STATUS_1, &current1);
1051
1052 /* handle the interrupts */
1053 if (sticky1 & CS35L35_CAL_ERR) {
Charles Keepax5d3d0ad2017-03-17 15:44:55 +00001054 dev_crit(cs35l35->dev, "Calibration Error\n");
Brian Austin6387f862017-03-06 08:07:59 -06001055
1056 /* error is no longer asserted; safe to reset */
1057 if (!(current1 & CS35L35_CAL_ERR)) {
1058 pr_debug("%s : Cal error release\n", __func__);
1059 regmap_update_bits(cs35l35->regmap,
1060 CS35L35_PROT_RELEASE_CTL,
1061 CS35L35_CAL_ERR_RLS, 0);
1062 regmap_update_bits(cs35l35->regmap,
1063 CS35L35_PROT_RELEASE_CTL,
1064 CS35L35_CAL_ERR_RLS,
1065 CS35L35_CAL_ERR_RLS);
1066 regmap_update_bits(cs35l35->regmap,
1067 CS35L35_PROT_RELEASE_CTL,
1068 CS35L35_CAL_ERR_RLS, 0);
1069 }
1070 }
1071
1072 if (sticky1 & CS35L35_AMP_SHORT) {
Charles Keepax5d3d0ad2017-03-17 15:44:55 +00001073 dev_crit(cs35l35->dev, "AMP Short Error\n");
Brian Austin6387f862017-03-06 08:07:59 -06001074 /* error is no longer asserted; safe to reset */
1075 if (!(current1 & CS35L35_AMP_SHORT)) {
Charles Keepax5d3d0ad2017-03-17 15:44:55 +00001076 dev_dbg(cs35l35->dev, "Amp short error release\n");
Brian Austin6387f862017-03-06 08:07:59 -06001077 regmap_update_bits(cs35l35->regmap,
1078 CS35L35_PROT_RELEASE_CTL,
1079 CS35L35_SHORT_RLS, 0);
1080 regmap_update_bits(cs35l35->regmap,
1081 CS35L35_PROT_RELEASE_CTL,
1082 CS35L35_SHORT_RLS,
1083 CS35L35_SHORT_RLS);
1084 regmap_update_bits(cs35l35->regmap,
1085 CS35L35_PROT_RELEASE_CTL,
1086 CS35L35_SHORT_RLS, 0);
1087 }
1088 }
1089
1090 if (sticky1 & CS35L35_OTW) {
Charles Keepax5d3d0ad2017-03-17 15:44:55 +00001091 dev_warn(cs35l35->dev, "Over temperature warning\n");
Brian Austin6387f862017-03-06 08:07:59 -06001092
1093 /* error is no longer asserted; safe to reset */
1094 if (!(current1 & CS35L35_OTW)) {
Charles Keepax5d3d0ad2017-03-17 15:44:55 +00001095 dev_dbg(cs35l35->dev, "Over temperature warn release\n");
Brian Austin6387f862017-03-06 08:07:59 -06001096 regmap_update_bits(cs35l35->regmap,
1097 CS35L35_PROT_RELEASE_CTL,
1098 CS35L35_OTW_RLS, 0);
1099 regmap_update_bits(cs35l35->regmap,
1100 CS35L35_PROT_RELEASE_CTL,
1101 CS35L35_OTW_RLS,
1102 CS35L35_OTW_RLS);
1103 regmap_update_bits(cs35l35->regmap,
1104 CS35L35_PROT_RELEASE_CTL,
1105 CS35L35_OTW_RLS, 0);
1106 }
1107 }
1108
1109 if (sticky1 & CS35L35_OTE) {
Charles Keepax5d3d0ad2017-03-17 15:44:55 +00001110 dev_crit(cs35l35->dev, "Over temperature error\n");
Brian Austin6387f862017-03-06 08:07:59 -06001111 /* error is no longer asserted; safe to reset */
1112 if (!(current1 & CS35L35_OTE)) {
Charles Keepax5d3d0ad2017-03-17 15:44:55 +00001113 dev_dbg(cs35l35->dev, "Over temperature error release\n");
Brian Austin6387f862017-03-06 08:07:59 -06001114 regmap_update_bits(cs35l35->regmap,
1115 CS35L35_PROT_RELEASE_CTL,
1116 CS35L35_OTE_RLS, 0);
1117 regmap_update_bits(cs35l35->regmap,
1118 CS35L35_PROT_RELEASE_CTL,
1119 CS35L35_OTE_RLS,
1120 CS35L35_OTE_RLS);
1121 regmap_update_bits(cs35l35->regmap,
1122 CS35L35_PROT_RELEASE_CTL,
1123 CS35L35_OTE_RLS, 0);
1124 }
1125 }
1126
1127 if (sticky3 & CS35L35_BST_HIGH) {
Charles Keepax5d3d0ad2017-03-17 15:44:55 +00001128 dev_crit(cs35l35->dev, "VBST error: powering off!\n");
Brian Austin6387f862017-03-06 08:07:59 -06001129 regmap_update_bits(cs35l35->regmap, CS35L35_PWRCTL2,
1130 CS35L35_PDN_AMP, CS35L35_PDN_AMP);
1131 regmap_update_bits(cs35l35->regmap, CS35L35_PWRCTL1,
1132 CS35L35_PDN_ALL, CS35L35_PDN_ALL);
1133 }
1134
1135 if (sticky3 & CS35L35_LBST_SHORT) {
Charles Keepax5d3d0ad2017-03-17 15:44:55 +00001136 dev_crit(cs35l35->dev, "LBST error: powering off!\n");
Brian Austin6387f862017-03-06 08:07:59 -06001137 regmap_update_bits(cs35l35->regmap, CS35L35_PWRCTL2,
1138 CS35L35_PDN_AMP, CS35L35_PDN_AMP);
1139 regmap_update_bits(cs35l35->regmap, CS35L35_PWRCTL1,
1140 CS35L35_PDN_ALL, CS35L35_PDN_ALL);
1141 }
1142
1143 if (sticky2 & CS35L35_VPBR_ERR)
Charles Keepax5d3d0ad2017-03-17 15:44:55 +00001144 dev_dbg(cs35l35->dev, "Error: Reactive Brownout\n");
Brian Austin6387f862017-03-06 08:07:59 -06001145
1146 if (sticky4 & CS35L35_VMON_OVFL)
Charles Keepax5d3d0ad2017-03-17 15:44:55 +00001147 dev_dbg(cs35l35->dev, "Error: VMON overflow\n");
Brian Austin6387f862017-03-06 08:07:59 -06001148
1149 if (sticky4 & CS35L35_IMON_OVFL)
Charles Keepax5d3d0ad2017-03-17 15:44:55 +00001150 dev_dbg(cs35l35->dev, "Error: IMON overflow\n");
Brian Austin6387f862017-03-06 08:07:59 -06001151
1152 return IRQ_HANDLED;
1153}
1154
1155
1156static int cs35l35_handle_of_data(struct i2c_client *i2c_client,
1157 struct cs35l35_platform_data *pdata)
1158{
1159 struct device_node *np = i2c_client->dev.of_node;
1160 struct device_node *classh, *signal_format;
1161 struct classh_cfg *classh_config = &pdata->classh_algo;
1162 struct monitor_cfg *monitor_config = &pdata->mon_cfg;
1163 unsigned int val32 = 0;
1164 u8 monitor_array[3];
1165 int ret = 0;
1166
1167 if (!np)
1168 return 0;
1169
1170 pdata->bst_pdn_fet_on = of_property_read_bool(np,
1171 "cirrus,boost-pdn-fet-on");
1172
1173 ret = of_property_read_u32(np, "cirrus,boost-ctl-millivolt", &val32);
1174 if (ret >= 0) {
1175 if (val32 < 2600 || val32 > 9000) {
1176 dev_err(&i2c_client->dev,
1177 "Invalid Boost Voltage %d mV\n", val32);
1178 return -EINVAL;
1179 }
1180 pdata->bst_vctl = ((val32 - 2600) / 100) + 1;
1181 }
1182
1183 ret = of_property_read_u32(np, "cirrus,boost-peak-milliamp", &val32);
1184 if (ret >= 0) {
1185 if (val32 < 1680 || val32 > 4480) {
1186 dev_err(&i2c_client->dev,
1187 "Invalid Boost Peak Current %u mA\n", val32);
1188 return -EINVAL;
1189 }
1190
1191 pdata->bst_ipk = (val32 - 1680) / 110;
1192 }
1193
1194 if (of_property_read_u32(np, "cirrus,sp-drv-strength", &val32) >= 0)
1195 pdata->sp_drv_str = val32;
Charles Keepax8d45f2d2017-03-08 16:42:49 +00001196 if (of_property_read_u32(np, "cirrus,sp-drv-unused", &val32) >= 0)
1197 pdata->sp_drv_unused = val32 | CS35L35_VALID_PDATA;
Brian Austin6387f862017-03-06 08:07:59 -06001198
1199 pdata->stereo = of_property_read_bool(np, "cirrus,stereo-config");
1200
1201 if (pdata->stereo) {
1202 ret = of_property_read_u32(np, "cirrus,audio-channel", &val32);
1203 if (ret >= 0)
1204 pdata->aud_channel = val32;
1205
1206 ret = of_property_read_u32(np, "cirrus,advisory-channel",
1207 &val32);
1208 if (ret >= 0)
1209 pdata->adv_channel = val32;
1210
1211 pdata->shared_bst = of_property_read_bool(np,
1212 "cirrus,shared-boost");
1213 }
1214
Charles Keepax77b329d2017-04-06 13:52:13 +01001215 pdata->ext_bst = of_property_read_bool(np, "cirrus,external-boost");
1216
Brian Austin6387f862017-03-06 08:07:59 -06001217 pdata->gain_zc = of_property_read_bool(np, "cirrus,amp-gain-zc");
1218
1219 classh = of_get_child_by_name(np, "cirrus,classh-internal-algo");
1220 classh_config->classh_algo_enable = classh ? true : false;
1221
1222 if (classh_config->classh_algo_enable) {
1223 classh_config->classh_bst_override =
1224 of_property_read_bool(np, "cirrus,classh-bst-overide");
1225
1226 ret = of_property_read_u32(classh,
1227 "cirrus,classh-bst-max-limit",
1228 &val32);
1229 if (ret >= 0) {
1230 val32 |= CS35L35_VALID_PDATA;
1231 classh_config->classh_bst_max_limit = val32;
1232 }
1233
1234 ret = of_property_read_u32(classh,
1235 "cirrus,classh-bst-max-limit",
1236 &val32);
1237 if (ret >= 0) {
1238 val32 |= CS35L35_VALID_PDATA;
1239 classh_config->classh_bst_max_limit = val32;
1240 }
1241
1242 ret = of_property_read_u32(classh, "cirrus,classh-mem-depth",
1243 &val32);
1244 if (ret >= 0) {
1245 val32 |= CS35L35_VALID_PDATA;
1246 classh_config->classh_mem_depth = val32;
1247 }
1248
1249 ret = of_property_read_u32(classh, "cirrus,classh-release-rate",
1250 &val32);
1251 if (ret >= 0)
1252 classh_config->classh_release_rate = val32;
1253
1254 ret = of_property_read_u32(classh, "cirrus,classh-headroom",
1255 &val32);
1256 if (ret >= 0) {
1257 val32 |= CS35L35_VALID_PDATA;
1258 classh_config->classh_headroom = val32;
1259 }
1260
1261 ret = of_property_read_u32(classh,
1262 "cirrus,classh-wk-fet-disable",
1263 &val32);
1264 if (ret >= 0)
1265 classh_config->classh_wk_fet_disable = val32;
1266
1267 ret = of_property_read_u32(classh, "cirrus,classh-wk-fet-delay",
1268 &val32);
1269 if (ret >= 0) {
1270 val32 |= CS35L35_VALID_PDATA;
1271 classh_config->classh_wk_fet_delay = val32;
1272 }
1273
1274 ret = of_property_read_u32(classh, "cirrus,classh-wk-fet-thld",
1275 &val32);
1276 if (ret >= 0)
1277 classh_config->classh_wk_fet_thld = val32;
1278
1279 ret = of_property_read_u32(classh, "cirrus,classh-vpch-auto",
1280 &val32);
1281 if (ret >= 0) {
1282 val32 |= CS35L35_VALID_PDATA;
1283 classh_config->classh_vpch_auto = val32;
1284 }
1285
1286 ret = of_property_read_u32(classh, "cirrus,classh-vpch-rate",
1287 &val32);
1288 if (ret >= 0) {
1289 val32 |= CS35L35_VALID_PDATA;
1290 classh_config->classh_vpch_rate = val32;
1291 }
1292
1293 ret = of_property_read_u32(classh, "cirrus,classh-vpch-man",
1294 &val32);
1295 if (ret >= 0)
1296 classh_config->classh_vpch_man = val32;
1297 }
1298 of_node_put(classh);
1299
1300 /* frame depth location */
1301 signal_format = of_get_child_by_name(np, "cirrus,monitor-signal-format");
1302 monitor_config->is_present = signal_format ? true : false;
1303 if (monitor_config->is_present) {
1304 ret = of_property_read_u8_array(signal_format, "cirrus,imon",
1305 monitor_array, ARRAY_SIZE(monitor_array));
1306 if (!ret) {
1307 monitor_config->imon_specs = true;
1308 monitor_config->imon_dpth = monitor_array[0];
1309 monitor_config->imon_loc = monitor_array[1];
1310 monitor_config->imon_frm = monitor_array[2];
1311 }
1312 ret = of_property_read_u8_array(signal_format, "cirrus,vmon",
1313 monitor_array, ARRAY_SIZE(monitor_array));
1314 if (!ret) {
1315 monitor_config->vmon_specs = true;
1316 monitor_config->vmon_dpth = monitor_array[0];
1317 monitor_config->vmon_loc = monitor_array[1];
1318 monitor_config->vmon_frm = monitor_array[2];
1319 }
1320 ret = of_property_read_u8_array(signal_format, "cirrus,vpmon",
1321 monitor_array, ARRAY_SIZE(monitor_array));
1322 if (!ret) {
1323 monitor_config->vpmon_specs = true;
1324 monitor_config->vpmon_dpth = monitor_array[0];
1325 monitor_config->vpmon_loc = monitor_array[1];
1326 monitor_config->vpmon_frm = monitor_array[2];
1327 }
1328 ret = of_property_read_u8_array(signal_format, "cirrus,vbstmon",
1329 monitor_array, ARRAY_SIZE(monitor_array));
1330 if (!ret) {
1331 monitor_config->vbstmon_specs = true;
1332 monitor_config->vbstmon_dpth = monitor_array[0];
1333 monitor_config->vbstmon_loc = monitor_array[1];
1334 monitor_config->vbstmon_frm = monitor_array[2];
1335 }
1336 ret = of_property_read_u8_array(signal_format, "cirrus,vpbrstat",
1337 monitor_array, ARRAY_SIZE(monitor_array));
1338 if (!ret) {
1339 monitor_config->vpbrstat_specs = true;
1340 monitor_config->vpbrstat_dpth = monitor_array[0];
1341 monitor_config->vpbrstat_loc = monitor_array[1];
1342 monitor_config->vpbrstat_frm = monitor_array[2];
1343 }
1344 ret = of_property_read_u8_array(signal_format, "cirrus,zerofill",
1345 monitor_array, ARRAY_SIZE(monitor_array));
1346 if (!ret) {
1347 monitor_config->zerofill_specs = true;
1348 monitor_config->zerofill_dpth = monitor_array[0];
1349 monitor_config->zerofill_loc = monitor_array[1];
1350 monitor_config->zerofill_frm = monitor_array[2];
1351 }
1352 }
1353 of_node_put(signal_format);
1354
1355 return 0;
1356}
1357
1358/* Errata Rev A0 */
1359static const struct reg_sequence cs35l35_errata_patch[] = {
1360
1361 { 0x7F, 0x99 },
1362 { 0x00, 0x99 },
1363 { 0x52, 0x22 },
1364 { 0x04, 0x14 },
1365 { 0x6D, 0x44 },
1366 { 0x24, 0x10 },
1367 { 0x58, 0xC4 },
1368 { 0x00, 0x98 },
1369 { 0x18, 0x08 },
1370 { 0x00, 0x00 },
1371 { 0x7F, 0x00 },
1372};
1373
1374static int cs35l35_i2c_probe(struct i2c_client *i2c_client,
1375 const struct i2c_device_id *id)
1376{
1377 struct cs35l35_private *cs35l35;
Charles Keepax1f758cd2017-03-08 16:42:50 +00001378 struct device *dev = &i2c_client->dev;
1379 struct cs35l35_platform_data *pdata = dev_get_platdata(dev);
Brian Austin6387f862017-03-06 08:07:59 -06001380 int i;
1381 int ret;
1382 unsigned int devid = 0;
1383 unsigned int reg;
1384
Charles Keepax1f758cd2017-03-08 16:42:50 +00001385 cs35l35 = devm_kzalloc(dev, sizeof(struct cs35l35_private), GFP_KERNEL);
Brian Austin6387f862017-03-06 08:07:59 -06001386 if (!cs35l35)
1387 return -ENOMEM;
1388
Charles Keepax5d3d0ad2017-03-17 15:44:55 +00001389 cs35l35->dev = dev;
1390
Brian Austin6387f862017-03-06 08:07:59 -06001391 i2c_set_clientdata(i2c_client, cs35l35);
1392 cs35l35->regmap = devm_regmap_init_i2c(i2c_client, &cs35l35_regmap);
1393 if (IS_ERR(cs35l35->regmap)) {
1394 ret = PTR_ERR(cs35l35->regmap);
Charles Keepax1f758cd2017-03-08 16:42:50 +00001395 dev_err(dev, "regmap_init() failed: %d\n", ret);
Brian Austin6387f862017-03-06 08:07:59 -06001396 goto err;
1397 }
1398
1399 for (i = 0; i < ARRAY_SIZE(cs35l35_supplies); i++)
1400 cs35l35->supplies[i].supply = cs35l35_supplies[i];
Colin Ian King03ff5702017-03-11 19:19:22 +00001401
1402 cs35l35->num_supplies = ARRAY_SIZE(cs35l35_supplies);
Brian Austin6387f862017-03-06 08:07:59 -06001403
Charles Keepax1f758cd2017-03-08 16:42:50 +00001404 ret = devm_regulator_bulk_get(dev, cs35l35->num_supplies,
1405 cs35l35->supplies);
Brian Austin6387f862017-03-06 08:07:59 -06001406 if (ret != 0) {
Charles Keepax1f758cd2017-03-08 16:42:50 +00001407 dev_err(dev, "Failed to request core supplies: %d\n", ret);
Brian Austin6387f862017-03-06 08:07:59 -06001408 return ret;
1409 }
1410
1411 if (pdata) {
1412 cs35l35->pdata = *pdata;
1413 } else {
Charles Keepax1f758cd2017-03-08 16:42:50 +00001414 pdata = devm_kzalloc(dev, sizeof(struct cs35l35_platform_data),
1415 GFP_KERNEL);
Brian Austin6387f862017-03-06 08:07:59 -06001416 if (!pdata)
1417 return -ENOMEM;
1418 if (i2c_client->dev.of_node) {
1419 ret = cs35l35_handle_of_data(i2c_client, pdata);
1420 if (ret != 0)
1421 return ret;
1422
1423 }
1424 cs35l35->pdata = *pdata;
1425 }
1426
1427 ret = regulator_bulk_enable(cs35l35->num_supplies,
1428 cs35l35->supplies);
1429 if (ret != 0) {
Charles Keepax1f758cd2017-03-08 16:42:50 +00001430 dev_err(dev, "Failed to enable core supplies: %d\n", ret);
Brian Austin6387f862017-03-06 08:07:59 -06001431 return ret;
1432 }
1433
1434 /* returning NULL can be valid if in stereo mode */
Charles Keepax1f758cd2017-03-08 16:42:50 +00001435 cs35l35->reset_gpio = devm_gpiod_get_optional(dev, "reset",
1436 GPIOD_OUT_LOW);
Brian Austin6387f862017-03-06 08:07:59 -06001437 if (IS_ERR(cs35l35->reset_gpio)) {
1438 ret = PTR_ERR(cs35l35->reset_gpio);
Charles Keepax8e713212017-03-27 16:54:27 +01001439 cs35l35->reset_gpio = NULL;
Brian Austin6387f862017-03-06 08:07:59 -06001440 if (ret == -EBUSY) {
Charles Keepax1f758cd2017-03-08 16:42:50 +00001441 dev_info(dev,
Brian Austin6387f862017-03-06 08:07:59 -06001442 "Reset line busy, assuming shared reset\n");
Brian Austin6387f862017-03-06 08:07:59 -06001443 } else {
Charles Keepax1f758cd2017-03-08 16:42:50 +00001444 dev_err(dev, "Failed to get reset GPIO: %d\n", ret);
Brian Austin6387f862017-03-06 08:07:59 -06001445 goto err;
1446 }
1447 }
1448
1449 gpiod_set_value_cansleep(cs35l35->reset_gpio, 1);
1450
1451 init_completion(&cs35l35->pdn_done);
1452
Charles Keepax1f758cd2017-03-08 16:42:50 +00001453 ret = devm_request_threaded_irq(dev, i2c_client->irq, NULL, cs35l35_irq,
Charles Keepaxbf5043d2017-03-08 16:42:51 +00001454 IRQF_ONESHOT | IRQF_TRIGGER_LOW |
1455 IRQF_SHARED, "cs35l35", cs35l35);
Brian Austin6387f862017-03-06 08:07:59 -06001456 if (ret != 0) {
Charles Keepax1f758cd2017-03-08 16:42:50 +00001457 dev_err(dev, "Failed to request IRQ: %d\n", ret);
Brian Austin6387f862017-03-06 08:07:59 -06001458 goto err;
1459 }
1460 /* initialize codec */
1461 ret = regmap_read(cs35l35->regmap, CS35L35_DEVID_AB, &reg);
1462
1463 devid = (reg & 0xFF) << 12;
1464 ret = regmap_read(cs35l35->regmap, CS35L35_DEVID_CD, &reg);
1465 devid |= (reg & 0xFF) << 4;
1466 ret = regmap_read(cs35l35->regmap, CS35L35_DEVID_E, &reg);
1467 devid |= (reg & 0xF0) >> 4;
1468
1469 if (devid != CS35L35_CHIP_ID) {
Charles Keepax1f758cd2017-03-08 16:42:50 +00001470 dev_err(dev, "CS35L35 Device ID (%X). Expected ID %X\n",
Brian Austin6387f862017-03-06 08:07:59 -06001471 devid, CS35L35_CHIP_ID);
1472 ret = -ENODEV;
1473 goto err;
1474 }
1475
1476 ret = regmap_read(cs35l35->regmap, CS35L35_REV_ID, &reg);
1477 if (ret < 0) {
Charles Keepax1f758cd2017-03-08 16:42:50 +00001478 dev_err(dev, "Get Revision ID failed: %d\n", ret);
Brian Austin6387f862017-03-06 08:07:59 -06001479 goto err;
1480 }
1481
1482 ret = regmap_register_patch(cs35l35->regmap, cs35l35_errata_patch,
1483 ARRAY_SIZE(cs35l35_errata_patch));
1484 if (ret < 0) {
Charles Keepax1f758cd2017-03-08 16:42:50 +00001485 dev_err(dev, "Failed to apply errata patch: %d\n", ret);
Brian Austin6387f862017-03-06 08:07:59 -06001486 goto err;
1487 }
1488
Charles Keepax1f758cd2017-03-08 16:42:50 +00001489 dev_info(dev, "Cirrus Logic CS35L35 (%x), Revision: %02X\n",
Axel Lin82875162017-03-11 20:57:07 +08001490 devid, reg & 0xFF);
Brian Austin6387f862017-03-06 08:07:59 -06001491
1492 /* Set the INT Masks for critical errors */
1493 regmap_write(cs35l35->regmap, CS35L35_INT_MASK_1,
1494 CS35L35_INT1_CRIT_MASK);
1495 regmap_write(cs35l35->regmap, CS35L35_INT_MASK_2,
1496 CS35L35_INT2_CRIT_MASK);
1497 regmap_write(cs35l35->regmap, CS35L35_INT_MASK_3,
1498 CS35L35_INT3_CRIT_MASK);
1499 regmap_write(cs35l35->regmap, CS35L35_INT_MASK_4,
1500 CS35L35_INT4_CRIT_MASK);
1501
1502 regmap_update_bits(cs35l35->regmap, CS35L35_PWRCTL2,
1503 CS35L35_PWR2_PDN_MASK,
1504 CS35L35_PWR2_PDN_MASK);
1505
1506 if (cs35l35->pdata.bst_pdn_fet_on)
1507 regmap_update_bits(cs35l35->regmap, CS35L35_PWRCTL2,
1508 CS35L35_PDN_BST_MASK,
1509 1 << CS35L35_PDN_BST_FETON_SHIFT);
1510 else
1511 regmap_update_bits(cs35l35->regmap, CS35L35_PWRCTL2,
1512 CS35L35_PDN_BST_MASK,
1513 1 << CS35L35_PDN_BST_FETOFF_SHIFT);
1514
1515 regmap_update_bits(cs35l35->regmap, CS35L35_PWRCTL3,
1516 CS35L35_PWR3_PDN_MASK,
1517 CS35L35_PWR3_PDN_MASK);
1518
1519 regmap_update_bits(cs35l35->regmap, CS35L35_PROTECT_CTL,
1520 CS35L35_AMP_MUTE_MASK, 1 << CS35L35_AMP_MUTE_SHIFT);
1521
Charles Keepax1f758cd2017-03-08 16:42:50 +00001522 ret = snd_soc_register_codec(dev, &soc_codec_dev_cs35l35, cs35l35_dai,
1523 ARRAY_SIZE(cs35l35_dai));
Brian Austin6387f862017-03-06 08:07:59 -06001524 if (ret < 0) {
Charles Keepax1f758cd2017-03-08 16:42:50 +00001525 dev_err(dev, "Failed to register codec: %d\n", ret);
Brian Austin6387f862017-03-06 08:07:59 -06001526 goto err;
1527 }
1528
Charles Keepax1bb06ad2017-03-08 16:42:47 +00001529 return 0;
1530
Brian Austin6387f862017-03-06 08:07:59 -06001531err:
1532 regulator_bulk_disable(cs35l35->num_supplies,
1533 cs35l35->supplies);
1534 gpiod_set_value_cansleep(cs35l35->reset_gpio, 0);
1535
1536 return ret;
1537}
1538
1539static int cs35l35_i2c_remove(struct i2c_client *client)
1540{
1541 snd_soc_unregister_codec(&client->dev);
1542 return 0;
1543}
1544
1545static const struct of_device_id cs35l35_of_match[] = {
1546 {.compatible = "cirrus,cs35l35"},
1547 {},
1548};
1549MODULE_DEVICE_TABLE(of, cs35l35_of_match);
1550
1551static const struct i2c_device_id cs35l35_id[] = {
1552 {"cs35l35", 0},
1553 {}
1554};
1555
1556MODULE_DEVICE_TABLE(i2c, cs35l35_id);
1557
1558static struct i2c_driver cs35l35_i2c_driver = {
1559 .driver = {
1560 .name = "cs35l35",
1561 .of_match_table = cs35l35_of_match,
1562 },
1563 .id_table = cs35l35_id,
1564 .probe = cs35l35_i2c_probe,
1565 .remove = cs35l35_i2c_remove,
1566};
1567
1568module_i2c_driver(cs35l35_i2c_driver);
1569
1570MODULE_DESCRIPTION("ASoC CS35L35 driver");
1571MODULE_AUTHOR("Brian Austin, Cirrus Logic Inc, <brian.austin@cirrus.com>");
1572MODULE_LICENSE("GPL");