Commit | Line | Data |
---|---|---|
3fd6e7d9 KC |
1 | /* |
2 | * TAS571x amplifier audio driver | |
3 | * | |
4 | * Copyright (C) 2015 Google, Inc. | |
5 | * Copyright (c) 2013 Daniel Mack <zonque@gmail.com> | |
6 | * | |
23a282c4 PK |
7 | * TAS5721 support: |
8 | * Copyright (C) 2016 Petr Kulhavy, Barix AG <petr@barix.com> | |
9 | * | |
3fd6e7d9 KC |
10 | * This program is free software; you can redistribute it and/or modify |
11 | * it under the terms of the GNU General Public License as published by | |
12 | * the Free Software Foundation; either version 2 of the License, or | |
13 | * (at your option) any later version. | |
14 | */ | |
15 | ||
16 | #include <linux/clk.h> | |
17 | #include <linux/delay.h> | |
18 | #include <linux/device.h> | |
19 | #include <linux/gpio/consumer.h> | |
20 | #include <linux/i2c.h> | |
21 | #include <linux/init.h> | |
22 | #include <linux/kernel.h> | |
23 | #include <linux/module.h> | |
24 | #include <linux/of_device.h> | |
25 | #include <linux/regmap.h> | |
26 | #include <linux/regulator/consumer.h> | |
27 | #include <linux/stddef.h> | |
28 | #include <sound/pcm_params.h> | |
29 | #include <sound/soc.h> | |
30 | #include <sound/tlv.h> | |
31 | ||
32 | #include "tas571x.h" | |
33 | ||
34 | #define TAS571X_MAX_SUPPLIES 6 | |
35 | ||
36 | struct tas571x_chip { | |
37 | const char *const *supply_names; | |
38 | int num_supply_names; | |
39 | const struct snd_kcontrol_new *controls; | |
40 | int num_controls; | |
41 | const struct regmap_config *regmap_config; | |
42 | int vol_reg_size; | |
43 | }; | |
44 | ||
45 | struct tas571x_private { | |
46 | const struct tas571x_chip *chip; | |
47 | struct regmap *regmap; | |
48 | struct regulator_bulk_data supplies[TAS571X_MAX_SUPPLIES]; | |
49 | struct clk *mclk; | |
50 | unsigned int format; | |
51 | struct gpio_desc *reset_gpio; | |
52 | struct gpio_desc *pdn_gpio; | |
53 | struct snd_soc_codec_driver codec_driver; | |
54 | }; | |
55 | ||
56 | static int tas571x_register_size(struct tas571x_private *priv, unsigned int reg) | |
57 | { | |
58 | switch (reg) { | |
59 | case TAS571X_MVOL_REG: | |
60 | case TAS571X_CH1_VOL_REG: | |
61 | case TAS571X_CH2_VOL_REG: | |
62 | return priv->chip->vol_reg_size; | |
a593ed09 PK |
63 | case TAS571X_INPUT_MUX_REG: |
64 | case TAS571X_CH4_SRC_SELECT_REG: | |
65 | case TAS571X_PWM_MUX_REG: | |
66 | return 4; | |
3fd6e7d9 KC |
67 | default: |
68 | return 1; | |
69 | } | |
70 | } | |
71 | ||
72 | static int tas571x_reg_write(void *context, unsigned int reg, | |
73 | unsigned int value) | |
74 | { | |
75 | struct i2c_client *client = context; | |
76 | struct tas571x_private *priv = i2c_get_clientdata(client); | |
77 | unsigned int i, size; | |
78 | uint8_t buf[5]; | |
79 | int ret; | |
80 | ||
81 | size = tas571x_register_size(priv, reg); | |
82 | buf[0] = reg; | |
83 | ||
84 | for (i = size; i >= 1; --i) { | |
85 | buf[i] = value; | |
86 | value >>= 8; | |
87 | } | |
88 | ||
89 | ret = i2c_master_send(client, buf, size + 1); | |
90 | if (ret == size + 1) | |
91 | return 0; | |
92 | else if (ret < 0) | |
93 | return ret; | |
94 | else | |
95 | return -EIO; | |
96 | } | |
97 | ||
98 | static int tas571x_reg_read(void *context, unsigned int reg, | |
99 | unsigned int *value) | |
100 | { | |
101 | struct i2c_client *client = context; | |
102 | struct tas571x_private *priv = i2c_get_clientdata(client); | |
103 | uint8_t send_buf, recv_buf[4]; | |
104 | struct i2c_msg msgs[2]; | |
105 | unsigned int size; | |
106 | unsigned int i; | |
107 | int ret; | |
108 | ||
109 | size = tas571x_register_size(priv, reg); | |
110 | send_buf = reg; | |
111 | ||
112 | msgs[0].addr = client->addr; | |
113 | msgs[0].len = sizeof(send_buf); | |
114 | msgs[0].buf = &send_buf; | |
115 | msgs[0].flags = 0; | |
116 | ||
117 | msgs[1].addr = client->addr; | |
118 | msgs[1].len = size; | |
119 | msgs[1].buf = recv_buf; | |
120 | msgs[1].flags = I2C_M_RD; | |
121 | ||
122 | ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); | |
123 | if (ret < 0) | |
124 | return ret; | |
125 | else if (ret != ARRAY_SIZE(msgs)) | |
126 | return -EIO; | |
127 | ||
128 | *value = 0; | |
129 | ||
130 | for (i = 0; i < size; i++) { | |
131 | *value <<= 8; | |
132 | *value |= recv_buf[i]; | |
133 | } | |
134 | ||
135 | return 0; | |
136 | } | |
137 | ||
138 | static int tas571x_set_dai_fmt(struct snd_soc_dai *dai, unsigned int format) | |
139 | { | |
140 | struct tas571x_private *priv = snd_soc_codec_get_drvdata(dai->codec); | |
141 | ||
142 | priv->format = format; | |
143 | ||
144 | return 0; | |
145 | } | |
146 | ||
147 | static int tas571x_hw_params(struct snd_pcm_substream *substream, | |
148 | struct snd_pcm_hw_params *params, | |
149 | struct snd_soc_dai *dai) | |
150 | { | |
151 | struct tas571x_private *priv = snd_soc_codec_get_drvdata(dai->codec); | |
152 | u32 val; | |
153 | ||
154 | switch (priv->format & SND_SOC_DAIFMT_FORMAT_MASK) { | |
155 | case SND_SOC_DAIFMT_RIGHT_J: | |
156 | val = 0x00; | |
157 | break; | |
158 | case SND_SOC_DAIFMT_I2S: | |
159 | val = 0x03; | |
160 | break; | |
161 | case SND_SOC_DAIFMT_LEFT_J: | |
162 | val = 0x06; | |
163 | break; | |
164 | default: | |
165 | return -EINVAL; | |
166 | } | |
167 | ||
168 | if (params_width(params) >= 24) | |
169 | val += 2; | |
170 | else if (params_width(params) >= 20) | |
171 | val += 1; | |
172 | ||
173 | return regmap_update_bits(priv->regmap, TAS571X_SDI_REG, | |
174 | TAS571X_SDI_FMT_MASK, val); | |
175 | } | |
176 | ||
04004850 PK |
177 | static int tas571x_mute(struct snd_soc_dai *dai, int mute) |
178 | { | |
179 | struct snd_soc_codec *codec = dai->codec; | |
180 | u8 sysctl2; | |
181 | int ret; | |
182 | ||
183 | sysctl2 = mute ? TAS571X_SYS_CTRL_2_SDN_MASK : 0; | |
184 | ||
185 | ret = snd_soc_update_bits(codec, | |
186 | TAS571X_SYS_CTRL_2_REG, | |
187 | TAS571X_SYS_CTRL_2_SDN_MASK, | |
188 | sysctl2); | |
189 | usleep_range(1000, 2000); | |
190 | ||
191 | return ret; | |
192 | } | |
193 | ||
3fd6e7d9 KC |
194 | static int tas571x_set_bias_level(struct snd_soc_codec *codec, |
195 | enum snd_soc_bias_level level) | |
196 | { | |
197 | struct tas571x_private *priv = snd_soc_codec_get_drvdata(codec); | |
198 | int ret; | |
199 | ||
200 | switch (level) { | |
201 | case SND_SOC_BIAS_ON: | |
202 | break; | |
203 | case SND_SOC_BIAS_PREPARE: | |
204 | break; | |
205 | case SND_SOC_BIAS_STANDBY: | |
8f218fa9 | 206 | if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) { |
3fd6e7d9 KC |
207 | if (!IS_ERR(priv->mclk)) { |
208 | ret = clk_prepare_enable(priv->mclk); | |
209 | if (ret) { | |
210 | dev_err(codec->dev, | |
211 | "Failed to enable master clock: %d\n", | |
212 | ret); | |
213 | return ret; | |
214 | } | |
215 | } | |
216 | ||
217 | gpiod_set_value(priv->pdn_gpio, 0); | |
218 | usleep_range(5000, 6000); | |
219 | ||
220 | regcache_cache_only(priv->regmap, false); | |
221 | ret = regcache_sync(priv->regmap); | |
222 | if (ret) | |
223 | return ret; | |
224 | } | |
225 | break; | |
226 | case SND_SOC_BIAS_OFF: | |
227 | regcache_cache_only(priv->regmap, true); | |
228 | gpiod_set_value(priv->pdn_gpio, 1); | |
229 | ||
230 | if (!IS_ERR(priv->mclk)) | |
231 | clk_disable_unprepare(priv->mclk); | |
232 | break; | |
233 | } | |
234 | ||
3fd6e7d9 KC |
235 | return 0; |
236 | } | |
237 | ||
238 | static const struct snd_soc_dai_ops tas571x_dai_ops = { | |
239 | .set_fmt = tas571x_set_dai_fmt, | |
240 | .hw_params = tas571x_hw_params, | |
04004850 | 241 | .digital_mute = tas571x_mute, |
3fd6e7d9 KC |
242 | }; |
243 | ||
244 | static const char *const tas5711_supply_names[] = { | |
245 | "AVDD", | |
246 | "DVDD", | |
247 | "PVDD_A", | |
248 | "PVDD_B", | |
249 | "PVDD_C", | |
250 | "PVDD_D", | |
251 | }; | |
252 | ||
253 | static const DECLARE_TLV_DB_SCALE(tas5711_volume_tlv, -10350, 50, 1); | |
254 | ||
255 | static const struct snd_kcontrol_new tas5711_controls[] = { | |
256 | SOC_SINGLE_TLV("Master Volume", | |
257 | TAS571X_MVOL_REG, | |
258 | 0, 0xff, 1, tas5711_volume_tlv), | |
259 | SOC_DOUBLE_R_TLV("Speaker Volume", | |
260 | TAS571X_CH1_VOL_REG, | |
261 | TAS571X_CH2_VOL_REG, | |
262 | 0, 0xff, 1, tas5711_volume_tlv), | |
263 | SOC_DOUBLE("Speaker Switch", | |
264 | TAS571X_SOFT_MUTE_REG, | |
265 | TAS571X_SOFT_MUTE_CH1_SHIFT, TAS571X_SOFT_MUTE_CH2_SHIFT, | |
266 | 1, 1), | |
267 | }; | |
268 | ||
a593ed09 PK |
269 | static const struct regmap_range tas571x_readonly_regs_range[] = { |
270 | regmap_reg_range(TAS571X_CLK_CTRL_REG, TAS571X_DEV_ID_REG), | |
271 | }; | |
272 | ||
273 | static const struct regmap_range tas571x_volatile_regs_range[] = { | |
274 | regmap_reg_range(TAS571X_CLK_CTRL_REG, TAS571X_ERR_STATUS_REG), | |
275 | regmap_reg_range(TAS571X_OSC_TRIM_REG, TAS571X_OSC_TRIM_REG), | |
276 | }; | |
277 | ||
278 | static const struct regmap_access_table tas571x_write_regs = { | |
279 | .no_ranges = tas571x_readonly_regs_range, | |
280 | .n_no_ranges = ARRAY_SIZE(tas571x_readonly_regs_range), | |
281 | }; | |
282 | ||
283 | static const struct regmap_access_table tas571x_volatile_regs = { | |
284 | .yes_ranges = tas571x_volatile_regs_range, | |
285 | .n_yes_ranges = ARRAY_SIZE(tas571x_volatile_regs_range), | |
286 | ||
287 | }; | |
288 | ||
3fd6e7d9 KC |
289 | static const struct reg_default tas5711_reg_defaults[] = { |
290 | { 0x04, 0x05 }, | |
291 | { 0x05, 0x40 }, | |
292 | { 0x06, 0x00 }, | |
293 | { 0x07, 0xff }, | |
294 | { 0x08, 0x30 }, | |
295 | { 0x09, 0x30 }, | |
296 | { 0x1b, 0x82 }, | |
297 | }; | |
298 | ||
299 | static const struct regmap_config tas5711_regmap_config = { | |
300 | .reg_bits = 8, | |
301 | .val_bits = 32, | |
302 | .max_register = 0xff, | |
303 | .reg_read = tas571x_reg_read, | |
304 | .reg_write = tas571x_reg_write, | |
305 | .reg_defaults = tas5711_reg_defaults, | |
306 | .num_reg_defaults = ARRAY_SIZE(tas5711_reg_defaults), | |
307 | .cache_type = REGCACHE_RBTREE, | |
a593ed09 PK |
308 | .wr_table = &tas571x_write_regs, |
309 | .volatile_table = &tas571x_volatile_regs, | |
3fd6e7d9 KC |
310 | }; |
311 | ||
312 | static const struct tas571x_chip tas5711_chip = { | |
313 | .supply_names = tas5711_supply_names, | |
314 | .num_supply_names = ARRAY_SIZE(tas5711_supply_names), | |
315 | .controls = tas5711_controls, | |
316 | .num_controls = ARRAY_SIZE(tas5711_controls), | |
317 | .regmap_config = &tas5711_regmap_config, | |
318 | .vol_reg_size = 1, | |
319 | }; | |
320 | ||
321 | static const char *const tas5717_supply_names[] = { | |
322 | "AVDD", | |
323 | "DVDD", | |
324 | "HPVDD", | |
325 | "PVDD_AB", | |
326 | "PVDD_CD", | |
327 | }; | |
328 | ||
329 | static const DECLARE_TLV_DB_SCALE(tas5717_volume_tlv, -10375, 25, 0); | |
330 | ||
331 | static const struct snd_kcontrol_new tas5717_controls[] = { | |
332 | /* MVOL LSB is ignored - see comments in tas571x_i2c_probe() */ | |
333 | SOC_SINGLE_TLV("Master Volume", | |
334 | TAS571X_MVOL_REG, 1, 0x1ff, 1, | |
335 | tas5717_volume_tlv), | |
336 | SOC_DOUBLE_R_TLV("Speaker Volume", | |
337 | TAS571X_CH1_VOL_REG, TAS571X_CH2_VOL_REG, | |
338 | 1, 0x1ff, 1, tas5717_volume_tlv), | |
339 | SOC_DOUBLE("Speaker Switch", | |
340 | TAS571X_SOFT_MUTE_REG, | |
341 | TAS571X_SOFT_MUTE_CH1_SHIFT, TAS571X_SOFT_MUTE_CH2_SHIFT, | |
342 | 1, 1), | |
343 | }; | |
344 | ||
345 | static const struct reg_default tas5717_reg_defaults[] = { | |
346 | { 0x04, 0x05 }, | |
347 | { 0x05, 0x40 }, | |
348 | { 0x06, 0x00 }, | |
349 | { 0x07, 0x03ff }, | |
350 | { 0x08, 0x00c0 }, | |
351 | { 0x09, 0x00c0 }, | |
352 | { 0x1b, 0x82 }, | |
353 | }; | |
354 | ||
355 | static const struct regmap_config tas5717_regmap_config = { | |
356 | .reg_bits = 8, | |
357 | .val_bits = 32, | |
358 | .max_register = 0xff, | |
359 | .reg_read = tas571x_reg_read, | |
360 | .reg_write = tas571x_reg_write, | |
361 | .reg_defaults = tas5717_reg_defaults, | |
362 | .num_reg_defaults = ARRAY_SIZE(tas5717_reg_defaults), | |
363 | .cache_type = REGCACHE_RBTREE, | |
a593ed09 PK |
364 | .wr_table = &tas571x_write_regs, |
365 | .volatile_table = &tas571x_volatile_regs, | |
3fd6e7d9 KC |
366 | }; |
367 | ||
368 | /* This entry is reused for tas5719 as the software interface is identical. */ | |
369 | static const struct tas571x_chip tas5717_chip = { | |
370 | .supply_names = tas5717_supply_names, | |
371 | .num_supply_names = ARRAY_SIZE(tas5717_supply_names), | |
372 | .controls = tas5717_controls, | |
373 | .num_controls = ARRAY_SIZE(tas5717_controls), | |
374 | .regmap_config = &tas5717_regmap_config, | |
375 | .vol_reg_size = 2, | |
376 | }; | |
377 | ||
23a282c4 PK |
378 | static const char *const tas5721_supply_names[] = { |
379 | "AVDD", | |
380 | "DVDD", | |
381 | "DRVDD", | |
382 | "PVDD", | |
383 | }; | |
384 | ||
385 | static const struct snd_kcontrol_new tas5721_controls[] = { | |
386 | SOC_SINGLE_TLV("Master Volume", | |
387 | TAS571X_MVOL_REG, | |
388 | 0, 0xff, 1, tas5711_volume_tlv), | |
389 | SOC_DOUBLE_R_TLV("Speaker Volume", | |
390 | TAS571X_CH1_VOL_REG, | |
391 | TAS571X_CH2_VOL_REG, | |
392 | 0, 0xff, 1, tas5711_volume_tlv), | |
393 | SOC_DOUBLE("Speaker Switch", | |
394 | TAS571X_SOFT_MUTE_REG, | |
395 | TAS571X_SOFT_MUTE_CH1_SHIFT, TAS571X_SOFT_MUTE_CH2_SHIFT, | |
396 | 1, 1), | |
397 | }; | |
398 | ||
399 | static const struct reg_default tas5721_reg_defaults[] = { | |
400 | {TAS571X_CLK_CTRL_REG, 0x6c}, | |
401 | {TAS571X_DEV_ID_REG, 0x00}, | |
402 | {TAS571X_ERR_STATUS_REG, 0x00}, | |
403 | {TAS571X_SYS_CTRL_1_REG, 0xa0}, | |
404 | {TAS571X_SDI_REG, 0x05}, | |
405 | {TAS571X_SYS_CTRL_2_REG, 0x40}, | |
406 | {TAS571X_SOFT_MUTE_REG, 0x00}, | |
407 | {TAS571X_MVOL_REG, 0xff}, | |
408 | {TAS571X_CH1_VOL_REG, 0x30}, | |
409 | {TAS571X_CH2_VOL_REG, 0x30}, | |
410 | {TAS571X_CH3_VOL_REG, 0x30}, | |
411 | {TAS571X_VOL_CFG_REG, 0x91}, | |
412 | {TAS571X_MODULATION_LIMIT_REG, 0x02}, | |
413 | {TAS571X_IC_DELAY_CH1_REG, 0xac}, | |
414 | {TAS571X_IC_DELAY_CH2_REG, 0x54}, | |
415 | {TAS571X_IC_DELAY_CH3_REG, 0xac}, | |
416 | {TAS571X_IC_DELAY_CH4_REG, 0x54}, | |
417 | {TAS571X_PWM_CH_SDN_GROUP_REG, 0x30}, | |
418 | {TAS571X_START_STOP_PERIOD_REG, 0x0f}, | |
419 | {TAS571X_OSC_TRIM_REG, 0x82}, | |
420 | {TAS571X_BKND_ERR_REG, 0x02}, | |
421 | {TAS571X_INPUT_MUX_REG, 0x17772}, | |
422 | {TAS571X_CH4_SRC_SELECT_REG, 0x4303}, | |
423 | {TAS571X_PWM_MUX_REG, 0x1021345}, | |
424 | }; | |
425 | ||
426 | static const struct regmap_config tas5721_regmap_config = { | |
427 | .reg_bits = 8, | |
428 | .val_bits = 32, | |
429 | .max_register = 0xff, | |
430 | .reg_read = tas571x_reg_read, | |
431 | .reg_write = tas571x_reg_write, | |
432 | .reg_defaults = tas5721_reg_defaults, | |
433 | .num_reg_defaults = ARRAY_SIZE(tas5721_reg_defaults), | |
434 | .cache_type = REGCACHE_RBTREE, | |
435 | .wr_table = &tas571x_write_regs, | |
436 | .volatile_table = &tas571x_volatile_regs, | |
437 | }; | |
438 | ||
439 | ||
440 | static const struct tas571x_chip tas5721_chip = { | |
441 | .supply_names = tas5721_supply_names, | |
442 | .num_supply_names = ARRAY_SIZE(tas5721_supply_names), | |
443 | .controls = tas5711_controls, | |
444 | .num_controls = ARRAY_SIZE(tas5711_controls), | |
445 | .regmap_config = &tas5721_regmap_config, | |
446 | .vol_reg_size = 1, | |
447 | }; | |
448 | ||
3fd6e7d9 KC |
449 | static const struct snd_soc_dapm_widget tas571x_dapm_widgets[] = { |
450 | SND_SOC_DAPM_DAC("DACL", NULL, SND_SOC_NOPM, 0, 0), | |
451 | SND_SOC_DAPM_DAC("DACR", NULL, SND_SOC_NOPM, 0, 0), | |
452 | ||
453 | SND_SOC_DAPM_OUTPUT("OUT_A"), | |
454 | SND_SOC_DAPM_OUTPUT("OUT_B"), | |
455 | SND_SOC_DAPM_OUTPUT("OUT_C"), | |
456 | SND_SOC_DAPM_OUTPUT("OUT_D"), | |
457 | }; | |
458 | ||
459 | static const struct snd_soc_dapm_route tas571x_dapm_routes[] = { | |
460 | { "DACL", NULL, "Playback" }, | |
461 | { "DACR", NULL, "Playback" }, | |
462 | ||
463 | { "OUT_A", NULL, "DACL" }, | |
464 | { "OUT_B", NULL, "DACL" }, | |
465 | { "OUT_C", NULL, "DACR" }, | |
466 | { "OUT_D", NULL, "DACR" }, | |
467 | }; | |
468 | ||
469 | static const struct snd_soc_codec_driver tas571x_codec = { | |
470 | .set_bias_level = tas571x_set_bias_level, | |
471 | .idle_bias_off = true, | |
472 | ||
473 | .dapm_widgets = tas571x_dapm_widgets, | |
474 | .num_dapm_widgets = ARRAY_SIZE(tas571x_dapm_widgets), | |
475 | .dapm_routes = tas571x_dapm_routes, | |
476 | .num_dapm_routes = ARRAY_SIZE(tas571x_dapm_routes), | |
477 | }; | |
478 | ||
479 | static struct snd_soc_dai_driver tas571x_dai = { | |
480 | .name = "tas571x-hifi", | |
481 | .playback = { | |
482 | .stream_name = "Playback", | |
483 | .channels_min = 2, | |
484 | .channels_max = 2, | |
485 | .rates = SNDRV_PCM_RATE_8000_48000, | |
486 | .formats = SNDRV_PCM_FMTBIT_S32_LE | | |
487 | SNDRV_PCM_FMTBIT_S24_LE | | |
488 | SNDRV_PCM_FMTBIT_S16_LE, | |
489 | }, | |
490 | .ops = &tas571x_dai_ops, | |
491 | }; | |
492 | ||
493 | static const struct of_device_id tas571x_of_match[]; | |
494 | ||
495 | static int tas571x_i2c_probe(struct i2c_client *client, | |
496 | const struct i2c_device_id *id) | |
497 | { | |
498 | struct tas571x_private *priv; | |
499 | struct device *dev = &client->dev; | |
97fceb4d | 500 | const struct of_device_id *of_id; |
3fd6e7d9 KC |
501 | int i, ret; |
502 | ||
503 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); | |
504 | if (!priv) | |
505 | return -ENOMEM; | |
506 | i2c_set_clientdata(client, priv); | |
507 | ||
97fceb4d | 508 | of_id = of_match_device(tas571x_of_match, dev); |
630e413d PK |
509 | if (of_id) |
510 | priv->chip = of_id->data; | |
511 | else | |
512 | priv->chip = (void *) id->driver_data; | |
3fd6e7d9 KC |
513 | |
514 | priv->mclk = devm_clk_get(dev, "mclk"); | |
515 | if (IS_ERR(priv->mclk) && PTR_ERR(priv->mclk) != -ENOENT) { | |
516 | dev_err(dev, "Failed to request mclk: %ld\n", | |
517 | PTR_ERR(priv->mclk)); | |
518 | return PTR_ERR(priv->mclk); | |
519 | } | |
520 | ||
521 | BUG_ON(priv->chip->num_supply_names > TAS571X_MAX_SUPPLIES); | |
522 | for (i = 0; i < priv->chip->num_supply_names; i++) | |
523 | priv->supplies[i].supply = priv->chip->supply_names[i]; | |
524 | ||
525 | ret = devm_regulator_bulk_get(dev, priv->chip->num_supply_names, | |
526 | priv->supplies); | |
527 | if (ret) { | |
528 | dev_err(dev, "Failed to get supplies: %d\n", ret); | |
529 | return ret; | |
530 | } | |
531 | ret = regulator_bulk_enable(priv->chip->num_supply_names, | |
532 | priv->supplies); | |
533 | if (ret) { | |
534 | dev_err(dev, "Failed to enable supplies: %d\n", ret); | |
535 | return ret; | |
536 | } | |
537 | ||
538 | priv->regmap = devm_regmap_init(dev, NULL, client, | |
539 | priv->chip->regmap_config); | |
540 | if (IS_ERR(priv->regmap)) | |
541 | return PTR_ERR(priv->regmap); | |
542 | ||
543 | priv->pdn_gpio = devm_gpiod_get_optional(dev, "pdn", GPIOD_OUT_LOW); | |
544 | if (IS_ERR(priv->pdn_gpio)) { | |
545 | dev_err(dev, "error requesting pdn_gpio: %ld\n", | |
546 | PTR_ERR(priv->pdn_gpio)); | |
547 | return PTR_ERR(priv->pdn_gpio); | |
548 | } | |
549 | ||
550 | priv->reset_gpio = devm_gpiod_get_optional(dev, "reset", | |
551 | GPIOD_OUT_HIGH); | |
552 | if (IS_ERR(priv->reset_gpio)) { | |
553 | dev_err(dev, "error requesting reset_gpio: %ld\n", | |
554 | PTR_ERR(priv->reset_gpio)); | |
555 | return PTR_ERR(priv->reset_gpio); | |
556 | } else if (priv->reset_gpio) { | |
557 | /* pulse the active low reset line for ~100us */ | |
558 | usleep_range(100, 200); | |
559 | gpiod_set_value(priv->reset_gpio, 0); | |
560 | usleep_range(12000, 20000); | |
561 | } | |
562 | ||
563 | ret = regmap_write(priv->regmap, TAS571X_OSC_TRIM_REG, 0); | |
564 | if (ret) | |
565 | return ret; | |
566 | ||
3fd6e7d9 KC |
567 | |
568 | memcpy(&priv->codec_driver, &tas571x_codec, sizeof(priv->codec_driver)); | |
569 | priv->codec_driver.controls = priv->chip->controls; | |
570 | priv->codec_driver.num_controls = priv->chip->num_controls; | |
571 | ||
572 | if (priv->chip->vol_reg_size == 2) { | |
573 | /* | |
574 | * The master volume defaults to 0x3ff (mute), but we ignore | |
575 | * (zero) the LSB because the hardware step size is 0.125 dB | |
576 | * and TLV_DB_SCALE_ITEM has a resolution of 0.01 dB. | |
577 | */ | |
578 | ret = regmap_update_bits(priv->regmap, TAS571X_MVOL_REG, 1, 0); | |
579 | if (ret) | |
580 | return ret; | |
581 | } | |
582 | ||
583 | regcache_cache_only(priv->regmap, true); | |
584 | gpiod_set_value(priv->pdn_gpio, 1); | |
585 | ||
586 | return snd_soc_register_codec(&client->dev, &priv->codec_driver, | |
587 | &tas571x_dai, 1); | |
588 | } | |
589 | ||
590 | static int tas571x_i2c_remove(struct i2c_client *client) | |
591 | { | |
592 | struct tas571x_private *priv = i2c_get_clientdata(client); | |
593 | ||
594 | snd_soc_unregister_codec(&client->dev); | |
595 | regulator_bulk_disable(priv->chip->num_supply_names, priv->supplies); | |
596 | ||
597 | return 0; | |
598 | } | |
599 | ||
600 | static const struct of_device_id tas571x_of_match[] = { | |
601 | { .compatible = "ti,tas5711", .data = &tas5711_chip, }, | |
602 | { .compatible = "ti,tas5717", .data = &tas5717_chip, }, | |
603 | { .compatible = "ti,tas5719", .data = &tas5717_chip, }, | |
23a282c4 | 604 | { .compatible = "ti,tas5721", .data = &tas5721_chip, }, |
3fd6e7d9 KC |
605 | { } |
606 | }; | |
607 | MODULE_DEVICE_TABLE(of, tas571x_of_match); | |
608 | ||
609 | static const struct i2c_device_id tas571x_i2c_id[] = { | |
630e413d PK |
610 | { "tas5711", (kernel_ulong_t) &tas5711_chip }, |
611 | { "tas5717", (kernel_ulong_t) &tas5717_chip }, | |
612 | { "tas5719", (kernel_ulong_t) &tas5717_chip }, | |
23a282c4 | 613 | { "tas5721", (kernel_ulong_t) &tas5721_chip }, |
3fd6e7d9 KC |
614 | { } |
615 | }; | |
616 | MODULE_DEVICE_TABLE(i2c, tas571x_i2c_id); | |
617 | ||
618 | static struct i2c_driver tas571x_i2c_driver = { | |
619 | .driver = { | |
620 | .name = "tas571x", | |
621 | .of_match_table = of_match_ptr(tas571x_of_match), | |
622 | }, | |
623 | .probe = tas571x_i2c_probe, | |
624 | .remove = tas571x_i2c_remove, | |
625 | .id_table = tas571x_i2c_id, | |
626 | }; | |
627 | module_i2c_driver(tas571x_i2c_driver); | |
628 | ||
629 | MODULE_DESCRIPTION("ASoC TAS571x driver"); | |
630 | MODULE_AUTHOR("Kevin Cernekee <cernekee@chromium.org>"); | |
631 | MODULE_LICENSE("GPL"); |