blob: 584a032b3cb17f25480e27201a68a2cfc68402a0 [file] [log] [blame]
Philipp Zabelb7482f52008-05-28 17:58:06 +01001/*
2 * uda1380.c - Philips UDA1380 ALSA SoC audio driver
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
Philipp Zabel1abd9182009-06-15 22:18:23 +02008 * Copyright (c) 2007-2009 Philipp Zabel <philipp.zabel@gmail.com>
Philipp Zabelb7482f52008-05-28 17:58:06 +01009 *
10 * Modified by Richard Purdie <richard@openedhand.com> to fit into SoC
11 * codec model.
12 *
13 * Copyright (c) 2005 Giorgio Padrin <giorgio@mandarinlogiq.org>
14 * Copyright 2005 Openedhand Ltd.
15 */
16
17#include <linux/module.h>
18#include <linux/init.h>
19#include <linux/types.h>
Philipp Zabelb7482f52008-05-28 17:58:06 +010020#include <linux/slab.h>
21#include <linux/errno.h>
Philipp Zabel1abd9182009-06-15 22:18:23 +020022#include <linux/gpio.h>
Philipp Zabelb7482f52008-05-28 17:58:06 +010023#include <linux/delay.h>
24#include <linux/i2c.h>
Philipp Zabelef9e5e52009-03-03 16:10:54 +010025#include <linux/workqueue.h>
Philipp Zabelb7482f52008-05-28 17:58:06 +010026#include <sound/core.h>
27#include <sound/control.h>
28#include <sound/initval.h>
Philipp Zabelb7482f52008-05-28 17:58:06 +010029#include <sound/soc.h>
Philipp Zabelb7482f52008-05-28 17:58:06 +010030#include <sound/tlv.h>
Philipp Zabel1abd9182009-06-15 22:18:23 +020031#include <sound/uda1380.h>
Philipp Zabelb7482f52008-05-28 17:58:06 +010032
33#include "uda1380.h"
34
Philipp Zabel1abd9182009-06-15 22:18:23 +020035/* codec private data */
36struct uda1380_priv {
Kuninori Morimotob40822d2018-01-29 04:44:09 +000037 struct snd_soc_component *component;
Philipp Zabel1abd9182009-06-15 22:18:23 +020038 unsigned int dac_clk;
39 struct work_struct work;
Kuninori Morimotoeaa53212017-11-09 00:19:33 +000040 struct i2c_client *i2c;
Kuninori Morimotoc001bf62017-11-14 01:04:08 +000041 u16 *reg_cache;
Philipp Zabel1abd9182009-06-15 22:18:23 +020042};
43
Philipp Zabelb7482f52008-05-28 17:58:06 +010044/*
45 * uda1380 register cache
46 */
47static const u16 uda1380_reg[UDA1380_CACHEREGNUM] = {
48 0x0502, 0x0000, 0x0000, 0x3f3f,
49 0x0202, 0x0000, 0x0000, 0x0000,
50 0x0000, 0x0000, 0x0000, 0x0000,
51 0x0000, 0x0000, 0x0000, 0x0000,
52 0x0000, 0xff00, 0x0000, 0x4800,
53 0x0000, 0x0000, 0x0000, 0x0000,
54 0x0000, 0x0000, 0x0000, 0x0000,
55 0x0000, 0x0000, 0x0000, 0x0000,
56 0x0000, 0x8000, 0x0002, 0x0000,
57};
58
Philipp Zabelef9e5e52009-03-03 16:10:54 +010059static unsigned long uda1380_cache_dirty;
60
Philipp Zabelb7482f52008-05-28 17:58:06 +010061/*
62 * read uda1380 register cache
63 */
Kuninori Morimotob40822d2018-01-29 04:44:09 +000064static inline unsigned int uda1380_read_reg_cache(struct snd_soc_component *component,
Philipp Zabelb7482f52008-05-28 17:58:06 +010065 unsigned int reg)
66{
Kuninori Morimotob40822d2018-01-29 04:44:09 +000067 struct uda1380_priv *uda1380 = snd_soc_component_get_drvdata(component);
Kuninori Morimotoc001bf62017-11-14 01:04:08 +000068 u16 *cache = uda1380->reg_cache;
69
Philipp Zabelb7482f52008-05-28 17:58:06 +010070 if (reg == UDA1380_RESET)
71 return 0;
72 if (reg >= UDA1380_CACHEREGNUM)
73 return -1;
74 return cache[reg];
75}
76
77/*
78 * write uda1380 register cache
79 */
Kuninori Morimotob40822d2018-01-29 04:44:09 +000080static inline void uda1380_write_reg_cache(struct snd_soc_component *component,
Philipp Zabelb7482f52008-05-28 17:58:06 +010081 u16 reg, unsigned int value)
82{
Kuninori Morimotob40822d2018-01-29 04:44:09 +000083 struct uda1380_priv *uda1380 = snd_soc_component_get_drvdata(component);
Kuninori Morimotoc001bf62017-11-14 01:04:08 +000084 u16 *cache = uda1380->reg_cache;
Philipp Zabelef9e5e52009-03-03 16:10:54 +010085
Philipp Zabelb7482f52008-05-28 17:58:06 +010086 if (reg >= UDA1380_CACHEREGNUM)
87 return;
Philipp Zabelef9e5e52009-03-03 16:10:54 +010088 if ((reg >= 0x10) && (cache[reg] != value))
89 set_bit(reg - 0x10, &uda1380_cache_dirty);
Philipp Zabelb7482f52008-05-28 17:58:06 +010090 cache[reg] = value;
91}
92
93/*
94 * write to the UDA1380 register space
95 */
Kuninori Morimotob40822d2018-01-29 04:44:09 +000096static int uda1380_write(struct snd_soc_component *component, unsigned int reg,
Philipp Zabelb7482f52008-05-28 17:58:06 +010097 unsigned int value)
98{
Kuninori Morimotob40822d2018-01-29 04:44:09 +000099 struct uda1380_priv *uda1380 = snd_soc_component_get_drvdata(component);
Philipp Zabelb7482f52008-05-28 17:58:06 +0100100 u8 data[3];
101
102 /* data is
103 * data[0] is register offset
104 * data[1] is MS byte
105 * data[2] is LS byte
106 */
107 data[0] = reg;
108 data[1] = (value & 0xff00) >> 8;
109 data[2] = value & 0x00ff;
110
Kuninori Morimotob40822d2018-01-29 04:44:09 +0000111 uda1380_write_reg_cache(component, reg, value);
Philipp Zabelb7482f52008-05-28 17:58:06 +0100112
113 /* the interpolator & decimator regs must only be written when the
114 * codec DAI is active.
115 */
Kuninori Morimotob40822d2018-01-29 04:44:09 +0000116 if (!snd_soc_component_is_active(component) && (reg >= UDA1380_MVOL))
Philipp Zabelb7482f52008-05-28 17:58:06 +0100117 return 0;
118 pr_debug("uda1380: hw write %x val %x\n", reg, value);
Kuninori Morimotoeaa53212017-11-09 00:19:33 +0000119 if (i2c_master_send(uda1380->i2c, data, 3) == 3) {
Philipp Zabelb7482f52008-05-28 17:58:06 +0100120 unsigned int val;
Kuninori Morimotoeaa53212017-11-09 00:19:33 +0000121 i2c_master_send(uda1380->i2c, data, 1);
122 i2c_master_recv(uda1380->i2c, data, 2);
Philipp Zabelb7482f52008-05-28 17:58:06 +0100123 val = (data[0]<<8) | data[1];
124 if (val != value) {
125 pr_debug("uda1380: READ BACK VAL %x\n",
126 (data[0]<<8) | data[1]);
127 return -EIO;
128 }
Philipp Zabelef9e5e52009-03-03 16:10:54 +0100129 if (reg >= 0x10)
130 clear_bit(reg - 0x10, &uda1380_cache_dirty);
Philipp Zabelb7482f52008-05-28 17:58:06 +0100131 return 0;
132 } else
133 return -EIO;
134}
135
Kuninori Morimotob40822d2018-01-29 04:44:09 +0000136static void uda1380_sync_cache(struct snd_soc_component *component)
Vasily Khoruzhick8614d3102010-08-30 11:28:07 +0300137{
Kuninori Morimotob40822d2018-01-29 04:44:09 +0000138 struct uda1380_priv *uda1380 = snd_soc_component_get_drvdata(component);
Vasily Khoruzhick8614d3102010-08-30 11:28:07 +0300139 int reg;
140 u8 data[3];
Kuninori Morimotoc001bf62017-11-14 01:04:08 +0000141 u16 *cache = uda1380->reg_cache;
Vasily Khoruzhick8614d3102010-08-30 11:28:07 +0300142
143 /* Sync reg_cache with the hardware */
144 for (reg = 0; reg < UDA1380_MVOL; reg++) {
145 data[0] = reg;
146 data[1] = (cache[reg] & 0xff00) >> 8;
147 data[2] = cache[reg] & 0x00ff;
Kuninori Morimotoeaa53212017-11-09 00:19:33 +0000148 if (i2c_master_send(uda1380->i2c, data, 3) != 3)
Kuninori Morimotob40822d2018-01-29 04:44:09 +0000149 dev_err(component->dev, "%s: write to reg 0x%x failed\n",
Vasily Khoruzhick8614d3102010-08-30 11:28:07 +0300150 __func__, reg);
151 }
152}
153
Kuninori Morimotob40822d2018-01-29 04:44:09 +0000154static int uda1380_reset(struct snd_soc_component *component)
Vasily Khoruzhick8614d3102010-08-30 11:28:07 +0300155{
Kuninori Morimotob40822d2018-01-29 04:44:09 +0000156 struct uda1380_platform_data *pdata = component->dev->platform_data;
157 struct uda1380_priv *uda1380 = snd_soc_component_get_drvdata(component);
Vasily Khoruzhick8614d3102010-08-30 11:28:07 +0300158
159 if (gpio_is_valid(pdata->gpio_reset)) {
160 gpio_set_value(pdata->gpio_reset, 1);
161 mdelay(1);
162 gpio_set_value(pdata->gpio_reset, 0);
163 } else {
164 u8 data[3];
165
166 data[0] = UDA1380_RESET;
167 data[1] = 0;
168 data[2] = 0;
169
Kuninori Morimotoeaa53212017-11-09 00:19:33 +0000170 if (i2c_master_send(uda1380->i2c, data, 3) != 3) {
Kuninori Morimotob40822d2018-01-29 04:44:09 +0000171 dev_err(component->dev, "%s: failed\n", __func__);
Vasily Khoruzhick8614d3102010-08-30 11:28:07 +0300172 return -EIO;
173 }
174 }
175
176 return 0;
177}
Philipp Zabelb7482f52008-05-28 17:58:06 +0100178
Philipp Zabelef9e5e52009-03-03 16:10:54 +0100179static void uda1380_flush_work(struct work_struct *work)
180{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000181 struct uda1380_priv *uda1380 = container_of(work, struct uda1380_priv, work);
Kuninori Morimotob40822d2018-01-29 04:44:09 +0000182 struct snd_soc_component *uda1380_component = uda1380->component;
Philipp Zabelef9e5e52009-03-03 16:10:54 +0100183 int bit, reg;
184
Akinobu Mita984b3f52010-03-05 13:41:37 -0800185 for_each_set_bit(bit, &uda1380_cache_dirty, UDA1380_CACHEREGNUM - 0x10) {
Philipp Zabelef9e5e52009-03-03 16:10:54 +0100186 reg = 0x10 + bit;
187 pr_debug("uda1380: flush reg %x val %x:\n", reg,
Kuninori Morimotob40822d2018-01-29 04:44:09 +0000188 uda1380_read_reg_cache(uda1380_component, reg));
189 uda1380_write(uda1380_component, reg,
190 uda1380_read_reg_cache(uda1380_component, reg));
Philipp Zabelef9e5e52009-03-03 16:10:54 +0100191 clear_bit(bit, &uda1380_cache_dirty);
192 }
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000193
Philipp Zabelef9e5e52009-03-03 16:10:54 +0100194}
195
Philipp Zabelb7482f52008-05-28 17:58:06 +0100196/* declarations of ALSA reg_elem_REAL controls */
197static const char *uda1380_deemp[] = {
198 "None",
199 "32kHz",
200 "44.1kHz",
201 "48kHz",
202 "96kHz",
203};
204static const char *uda1380_input_sel[] = {
205 "Line",
206 "Mic + Line R",
207 "Line L",
208 "Mic",
209};
210static const char *uda1380_output_sel[] = {
211 "DAC",
212 "Analog Mixer",
213};
214static const char *uda1380_spf_mode[] = {
215 "Flat",
216 "Minimum1",
217 "Minimum2",
218 "Maximum"
219};
220static const char *uda1380_capture_sel[] = {
221 "ADC",
222 "Digital Mixer"
223};
224static const char *uda1380_sel_ns[] = {
225 "3rd-order",
226 "5th-order"
227};
228static const char *uda1380_mix_control[] = {
229 "off",
230 "PCM only",
231 "before sound processing",
232 "after sound processing"
233};
234static const char *uda1380_sdet_setting[] = {
235 "3200",
236 "4800",
237 "9600",
238 "19200"
239};
240static const char *uda1380_os_setting[] = {
241 "single-speed",
242 "double-speed (no mixing)",
243 "quad-speed (no mixing)"
244};
245
246static const struct soc_enum uda1380_deemp_enum[] = {
Takashi Iwai1dbb3482014-02-18 10:32:16 +0100247 SOC_ENUM_SINGLE(UDA1380_DEEMP, 8, ARRAY_SIZE(uda1380_deemp),
248 uda1380_deemp),
249 SOC_ENUM_SINGLE(UDA1380_DEEMP, 0, ARRAY_SIZE(uda1380_deemp),
250 uda1380_deemp),
Philipp Zabelb7482f52008-05-28 17:58:06 +0100251};
Takashi Iwai1dbb3482014-02-18 10:32:16 +0100252static SOC_ENUM_SINGLE_DECL(uda1380_input_sel_enum,
253 UDA1380_ADC, 2, uda1380_input_sel); /* SEL_MIC, SEL_LNA */
254static SOC_ENUM_SINGLE_DECL(uda1380_output_sel_enum,
255 UDA1380_PM, 7, uda1380_output_sel); /* R02_EN_AVC */
256static SOC_ENUM_SINGLE_DECL(uda1380_spf_enum,
257 UDA1380_MODE, 14, uda1380_spf_mode); /* M */
258static SOC_ENUM_SINGLE_DECL(uda1380_capture_sel_enum,
259 UDA1380_IFACE, 6, uda1380_capture_sel); /* SEL_SOURCE */
260static SOC_ENUM_SINGLE_DECL(uda1380_sel_ns_enum,
261 UDA1380_MIXER, 14, uda1380_sel_ns); /* SEL_NS */
262static SOC_ENUM_SINGLE_DECL(uda1380_mix_enum,
263 UDA1380_MIXER, 12, uda1380_mix_control); /* MIX, MIX_POS */
264static SOC_ENUM_SINGLE_DECL(uda1380_sdet_enum,
265 UDA1380_MIXER, 4, uda1380_sdet_setting); /* SD_VALUE */
266static SOC_ENUM_SINGLE_DECL(uda1380_os_enum,
267 UDA1380_MIXER, 0, uda1380_os_setting); /* OS */
Philipp Zabelb7482f52008-05-28 17:58:06 +0100268
269/*
270 * from -48 dB in 1.5 dB steps (mute instead of -49.5 dB)
271 */
272static DECLARE_TLV_DB_SCALE(amix_tlv, -4950, 150, 1);
273
274/*
275 * from -78 dB in 1 dB steps (3 dB steps, really. LSB are ignored),
276 * from -66 dB in 0.5 dB steps (2 dB steps, really) and
277 * from -52 dB in 0.25 dB steps
278 */
Lars-Peter Clausen5ee0b8f2015-08-02 17:19:57 +0200279static const DECLARE_TLV_DB_RANGE(mvol_tlv,
Philipp Zabelb7482f52008-05-28 17:58:06 +0100280 0, 15, TLV_DB_SCALE_ITEM(-8200, 100, 1),
281 16, 43, TLV_DB_SCALE_ITEM(-6600, 50, 0),
Lars-Peter Clausen5ee0b8f2015-08-02 17:19:57 +0200282 44, 252, TLV_DB_SCALE_ITEM(-5200, 25, 0)
283);
Philipp Zabelb7482f52008-05-28 17:58:06 +0100284
285/*
286 * from -72 dB in 1.5 dB steps (6 dB steps really),
287 * from -66 dB in 0.75 dB steps (3 dB steps really),
288 * from -60 dB in 0.5 dB steps (2 dB steps really) and
289 * from -46 dB in 0.25 dB steps
290 */
Lars-Peter Clausen5ee0b8f2015-08-02 17:19:57 +0200291static const DECLARE_TLV_DB_RANGE(vc_tlv,
Philipp Zabelb7482f52008-05-28 17:58:06 +0100292 0, 7, TLV_DB_SCALE_ITEM(-7800, 150, 1),
293 8, 15, TLV_DB_SCALE_ITEM(-6600, 75, 0),
294 16, 43, TLV_DB_SCALE_ITEM(-6000, 50, 0),
Lars-Peter Clausen5ee0b8f2015-08-02 17:19:57 +0200295 44, 228, TLV_DB_SCALE_ITEM(-4600, 25, 0)
296);
Philipp Zabelb7482f52008-05-28 17:58:06 +0100297
298/* from 0 to 6 dB in 2 dB steps if SPF mode != flat */
299static DECLARE_TLV_DB_SCALE(tr_tlv, 0, 200, 0);
300
301/* from 0 to 24 dB in 2 dB steps, if SPF mode == maximum, otherwise cuts
302 * off at 18 dB max) */
303static DECLARE_TLV_DB_SCALE(bb_tlv, 0, 200, 0);
304
305/* from -63 to 24 dB in 0.5 dB steps (-128...48) */
306static DECLARE_TLV_DB_SCALE(dec_tlv, -6400, 50, 1);
307
308/* from 0 to 24 dB in 3 dB steps */
309static DECLARE_TLV_DB_SCALE(pga_tlv, 0, 300, 0);
310
311/* from 0 to 30 dB in 2 dB steps */
312static DECLARE_TLV_DB_SCALE(vga_tlv, 0, 200, 0);
313
314static const struct snd_kcontrol_new uda1380_snd_controls[] = {
315 SOC_DOUBLE_TLV("Analog Mixer Volume", UDA1380_AMIX, 0, 8, 44, 1, amix_tlv), /* AVCR, AVCL */
316 SOC_DOUBLE_TLV("Master Playback Volume", UDA1380_MVOL, 0, 8, 252, 1, mvol_tlv), /* MVCL, MVCR */
317 SOC_SINGLE_TLV("ADC Playback Volume", UDA1380_MIXVOL, 8, 228, 1, vc_tlv), /* VC2 */
318 SOC_SINGLE_TLV("PCM Playback Volume", UDA1380_MIXVOL, 0, 228, 1, vc_tlv), /* VC1 */
319 SOC_ENUM("Sound Processing Filter", uda1380_spf_enum), /* M */
320 SOC_DOUBLE_TLV("Tone Control - Treble", UDA1380_MODE, 4, 12, 3, 0, tr_tlv), /* TRL, TRR */
321 SOC_DOUBLE_TLV("Tone Control - Bass", UDA1380_MODE, 0, 8, 15, 0, bb_tlv), /* BBL, BBR */
322/**/ SOC_SINGLE("Master Playback Switch", UDA1380_DEEMP, 14, 1, 1), /* MTM */
323 SOC_SINGLE("ADC Playback Switch", UDA1380_DEEMP, 11, 1, 1), /* MT2 from decimation filter */
324 SOC_ENUM("ADC Playback De-emphasis", uda1380_deemp_enum[0]), /* DE2 */
325 SOC_SINGLE("PCM Playback Switch", UDA1380_DEEMP, 3, 1, 1), /* MT1, from digital data input */
326 SOC_ENUM("PCM Playback De-emphasis", uda1380_deemp_enum[1]), /* DE1 */
327 SOC_SINGLE("DAC Polarity inverting Switch", UDA1380_MIXER, 15, 1, 0), /* DA_POL_INV */
328 SOC_ENUM("Noise Shaper", uda1380_sel_ns_enum), /* SEL_NS */
329 SOC_ENUM("Digital Mixer Signal Control", uda1380_mix_enum), /* MIX_POS, MIX */
Philipp Zabelb7482f52008-05-28 17:58:06 +0100330 SOC_SINGLE("Silence Detector Switch", UDA1380_MIXER, 6, 1, 0), /* SDET_ON */
331 SOC_ENUM("Silence Detector Setting", uda1380_sdet_enum), /* SD_VALUE */
332 SOC_ENUM("Oversampling Input", uda1380_os_enum), /* OS */
333 SOC_DOUBLE_S8_TLV("ADC Capture Volume", UDA1380_DEC, -128, 48, dec_tlv), /* ML_DEC, MR_DEC */
334/**/ SOC_SINGLE("ADC Capture Switch", UDA1380_PGA, 15, 1, 1), /* MT_ADC */
335 SOC_DOUBLE_TLV("Line Capture Volume", UDA1380_PGA, 0, 8, 8, 0, pga_tlv), /* PGA_GAINCTRLL, PGA_GAINCTRLR */
336 SOC_SINGLE("ADC Polarity inverting Switch", UDA1380_ADC, 12, 1, 0), /* ADCPOL_INV */
337 SOC_SINGLE_TLV("Mic Capture Volume", UDA1380_ADC, 8, 15, 0, vga_tlv), /* VGA_CTRL */
338 SOC_SINGLE("DC Filter Bypass Switch", UDA1380_ADC, 1, 1, 0), /* SKIP_DCFIL (before decimator) */
339 SOC_SINGLE("DC Filter Enable Switch", UDA1380_ADC, 0, 1, 0), /* EN_DCFIL (at output of decimator) */
340 SOC_SINGLE("AGC Timing", UDA1380_AGC, 8, 7, 0), /* TODO: enum, see table 62 */
341 SOC_SINGLE("AGC Target level", UDA1380_AGC, 2, 3, 1), /* AGC_LEVEL */
342 /* -5.5, -8, -11.5, -14 dBFS */
343 SOC_SINGLE("AGC Switch", UDA1380_AGC, 0, 1, 0),
344};
345
Philipp Zabelb7482f52008-05-28 17:58:06 +0100346/* Input mux */
347static const struct snd_kcontrol_new uda1380_input_mux_control =
348 SOC_DAPM_ENUM("Route", uda1380_input_sel_enum);
349
350/* Output mux */
351static const struct snd_kcontrol_new uda1380_output_mux_control =
352 SOC_DAPM_ENUM("Route", uda1380_output_sel_enum);
353
354/* Capture mux */
355static const struct snd_kcontrol_new uda1380_capture_mux_control =
356 SOC_DAPM_ENUM("Route", uda1380_capture_sel_enum);
357
358
359static const struct snd_soc_dapm_widget uda1380_dapm_widgets[] = {
360 SND_SOC_DAPM_MUX("Input Mux", SND_SOC_NOPM, 0, 0,
361 &uda1380_input_mux_control),
362 SND_SOC_DAPM_MUX("Output Mux", SND_SOC_NOPM, 0, 0,
363 &uda1380_output_mux_control),
364 SND_SOC_DAPM_MUX("Capture Mux", SND_SOC_NOPM, 0, 0,
365 &uda1380_capture_mux_control),
366 SND_SOC_DAPM_PGA("Left PGA", UDA1380_PM, 3, 0, NULL, 0),
367 SND_SOC_DAPM_PGA("Right PGA", UDA1380_PM, 1, 0, NULL, 0),
368 SND_SOC_DAPM_PGA("Mic LNA", UDA1380_PM, 4, 0, NULL, 0),
369 SND_SOC_DAPM_ADC("Left ADC", "Left Capture", UDA1380_PM, 2, 0),
370 SND_SOC_DAPM_ADC("Right ADC", "Right Capture", UDA1380_PM, 0, 0),
371 SND_SOC_DAPM_INPUT("VINM"),
372 SND_SOC_DAPM_INPUT("VINL"),
373 SND_SOC_DAPM_INPUT("VINR"),
374 SND_SOC_DAPM_MIXER("Analog Mixer", UDA1380_PM, 6, 0, NULL, 0),
375 SND_SOC_DAPM_OUTPUT("VOUTLHP"),
376 SND_SOC_DAPM_OUTPUT("VOUTRHP"),
377 SND_SOC_DAPM_OUTPUT("VOUTL"),
378 SND_SOC_DAPM_OUTPUT("VOUTR"),
379 SND_SOC_DAPM_DAC("DAC", "Playback", UDA1380_PM, 10, 0),
380 SND_SOC_DAPM_PGA("HeadPhone Driver", UDA1380_PM, 13, 0, NULL, 0),
381};
382
Axel Lin58fa8e42011-12-19 13:54:38 +0800383static const struct snd_soc_dapm_route uda1380_dapm_routes[] = {
Philipp Zabelb7482f52008-05-28 17:58:06 +0100384
385 /* output mux */
386 {"HeadPhone Driver", NULL, "Output Mux"},
387 {"VOUTR", NULL, "Output Mux"},
388 {"VOUTL", NULL, "Output Mux"},
389
390 {"Analog Mixer", NULL, "VINR"},
391 {"Analog Mixer", NULL, "VINL"},
392 {"Analog Mixer", NULL, "DAC"},
393
394 {"Output Mux", "DAC", "DAC"},
395 {"Output Mux", "Analog Mixer", "Analog Mixer"},
396
397 /* {"DAC", "Digital Mixer", "I2S" } */
398
399 /* headphone driver */
400 {"VOUTLHP", NULL, "HeadPhone Driver"},
401 {"VOUTRHP", NULL, "HeadPhone Driver"},
402
403 /* input mux */
404 {"Left ADC", NULL, "Input Mux"},
405 {"Input Mux", "Mic", "Mic LNA"},
406 {"Input Mux", "Mic + Line R", "Mic LNA"},
407 {"Input Mux", "Line L", "Left PGA"},
408 {"Input Mux", "Line", "Left PGA"},
409
410 /* right input */
411 {"Right ADC", "Mic + Line R", "Right PGA"},
412 {"Right ADC", "Line", "Right PGA"},
413
414 /* inputs */
415 {"Mic LNA", NULL, "VINM"},
416 {"Left PGA", NULL, "VINL"},
417 {"Right PGA", NULL, "VINR"},
418};
419
Philipp Zabel5b247442009-02-03 17:19:40 +0100420static int uda1380_set_dai_fmt_both(struct snd_soc_dai *codec_dai,
Philipp Zabelb7482f52008-05-28 17:58:06 +0100421 unsigned int fmt)
422{
Kuninori Morimotob40822d2018-01-29 04:44:09 +0000423 struct snd_soc_component *component = codec_dai->component;
Philipp Zabelb7482f52008-05-28 17:58:06 +0100424 int iface;
425
426 /* set up DAI based upon fmt */
Kuninori Morimotob40822d2018-01-29 04:44:09 +0000427 iface = uda1380_read_reg_cache(component, UDA1380_IFACE);
Philipp Zabelb7482f52008-05-28 17:58:06 +0100428 iface &= ~(R01_SFORI_MASK | R01_SIM | R01_SFORO_MASK);
429
Philipp Zabelb7482f52008-05-28 17:58:06 +0100430 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
431 case SND_SOC_DAIFMT_I2S:
432 iface |= R01_SFORI_I2S | R01_SFORO_I2S;
433 break;
434 case SND_SOC_DAIFMT_LSB:
Philipp Zabel5b247442009-02-03 17:19:40 +0100435 iface |= R01_SFORI_LSB16 | R01_SFORO_LSB16;
Philipp Zabelb7482f52008-05-28 17:58:06 +0100436 break;
437 case SND_SOC_DAIFMT_MSB:
Philipp Zabel5b247442009-02-03 17:19:40 +0100438 iface |= R01_SFORI_MSB | R01_SFORO_MSB;
439 }
440
Philipp Zabel5f2a9382009-03-03 16:10:52 +0100441 /* DATAI is slave only, so in single-link mode, this has to be slave */
442 if ((fmt & SND_SOC_DAIFMT_MASTER_MASK) != SND_SOC_DAIFMT_CBS_CFS)
443 return -EINVAL;
Philipp Zabel5b247442009-02-03 17:19:40 +0100444
Kuninori Morimotob40822d2018-01-29 04:44:09 +0000445 uda1380_write_reg_cache(component, UDA1380_IFACE, iface);
Philipp Zabel5b247442009-02-03 17:19:40 +0100446
447 return 0;
448}
449
450static int uda1380_set_dai_fmt_playback(struct snd_soc_dai *codec_dai,
451 unsigned int fmt)
452{
Kuninori Morimotob40822d2018-01-29 04:44:09 +0000453 struct snd_soc_component *component = codec_dai->component;
Philipp Zabel5b247442009-02-03 17:19:40 +0100454 int iface;
455
456 /* set up DAI based upon fmt */
Kuninori Morimotob40822d2018-01-29 04:44:09 +0000457 iface = uda1380_read_reg_cache(component, UDA1380_IFACE);
Philipp Zabel5b247442009-02-03 17:19:40 +0100458 iface &= ~R01_SFORI_MASK;
459
460 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
461 case SND_SOC_DAIFMT_I2S:
462 iface |= R01_SFORI_I2S;
463 break;
464 case SND_SOC_DAIFMT_LSB:
465 iface |= R01_SFORI_LSB16;
466 break;
467 case SND_SOC_DAIFMT_MSB:
468 iface |= R01_SFORI_MSB;
469 }
470
Philipp Zabel5f2a9382009-03-03 16:10:52 +0100471 /* DATAI is slave only, so this has to be slave */
472 if ((fmt & SND_SOC_DAIFMT_MASTER_MASK) != SND_SOC_DAIFMT_CBS_CFS)
473 return -EINVAL;
474
Kuninori Morimotob40822d2018-01-29 04:44:09 +0000475 uda1380_write(component, UDA1380_IFACE, iface);
Philipp Zabel5b247442009-02-03 17:19:40 +0100476
477 return 0;
478}
479
480static int uda1380_set_dai_fmt_capture(struct snd_soc_dai *codec_dai,
481 unsigned int fmt)
482{
Kuninori Morimotob40822d2018-01-29 04:44:09 +0000483 struct snd_soc_component *component = codec_dai->component;
Philipp Zabel5b247442009-02-03 17:19:40 +0100484 int iface;
485
486 /* set up DAI based upon fmt */
Kuninori Morimotob40822d2018-01-29 04:44:09 +0000487 iface = uda1380_read_reg_cache(component, UDA1380_IFACE);
Philipp Zabel5b247442009-02-03 17:19:40 +0100488 iface &= ~(R01_SIM | R01_SFORO_MASK);
489
490 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
491 case SND_SOC_DAIFMT_I2S:
492 iface |= R01_SFORO_I2S;
493 break;
494 case SND_SOC_DAIFMT_LSB:
495 iface |= R01_SFORO_LSB16;
496 break;
497 case SND_SOC_DAIFMT_MSB:
498 iface |= R01_SFORO_MSB;
Philipp Zabelb7482f52008-05-28 17:58:06 +0100499 }
500
501 if ((fmt & SND_SOC_DAIFMT_MASTER_MASK) == SND_SOC_DAIFMT_CBM_CFM)
502 iface |= R01_SIM;
503
Kuninori Morimotob40822d2018-01-29 04:44:09 +0000504 uda1380_write(component, UDA1380_IFACE, iface);
Philipp Zabelb7482f52008-05-28 17:58:06 +0100505
506 return 0;
507}
508
Philipp Zabelef9e5e52009-03-03 16:10:54 +0100509static int uda1380_trigger(struct snd_pcm_substream *substream, int cmd,
510 struct snd_soc_dai *dai)
Philipp Zabelb7482f52008-05-28 17:58:06 +0100511{
Kuninori Morimotob40822d2018-01-29 04:44:09 +0000512 struct snd_soc_component *component = dai->component;
513 struct uda1380_priv *uda1380 = snd_soc_component_get_drvdata(component);
514 int mixer = uda1380_read_reg_cache(component, UDA1380_MIXER);
Philipp Zabelb7482f52008-05-28 17:58:06 +0100515
Philipp Zabelef9e5e52009-03-03 16:10:54 +0100516 switch (cmd) {
517 case SNDRV_PCM_TRIGGER_START:
518 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
Kuninori Morimotob40822d2018-01-29 04:44:09 +0000519 uda1380_write_reg_cache(component, UDA1380_MIXER,
Philipp Zabelef9e5e52009-03-03 16:10:54 +0100520 mixer & ~R14_SILENCE);
Philipp Zabel1abd9182009-06-15 22:18:23 +0200521 schedule_work(&uda1380->work);
Philipp Zabelef9e5e52009-03-03 16:10:54 +0100522 break;
523 case SNDRV_PCM_TRIGGER_STOP:
524 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
Kuninori Morimotob40822d2018-01-29 04:44:09 +0000525 uda1380_write_reg_cache(component, UDA1380_MIXER,
Philipp Zabelef9e5e52009-03-03 16:10:54 +0100526 mixer | R14_SILENCE);
Philipp Zabel1abd9182009-06-15 22:18:23 +0200527 schedule_work(&uda1380->work);
Philipp Zabelef9e5e52009-03-03 16:10:54 +0100528 break;
Philipp Zabelb7482f52008-05-28 17:58:06 +0100529 }
Philipp Zabelb7482f52008-05-28 17:58:06 +0100530 return 0;
531}
532
533static int uda1380_pcm_hw_params(struct snd_pcm_substream *substream,
Mark Browndee89c42008-11-18 22:11:38 +0000534 struct snd_pcm_hw_params *params,
535 struct snd_soc_dai *dai)
Philipp Zabelb7482f52008-05-28 17:58:06 +0100536{
Kuninori Morimotob40822d2018-01-29 04:44:09 +0000537 struct snd_soc_component *component = dai->component;
538 u16 clk = uda1380_read_reg_cache(component, UDA1380_CLK);
Philipp Zabelb7482f52008-05-28 17:58:06 +0100539
540 /* set WSPLL power and divider if running from this clock */
541 if (clk & R00_DAC_CLK) {
542 int rate = params_rate(params);
Kuninori Morimotob40822d2018-01-29 04:44:09 +0000543 u16 pm = uda1380_read_reg_cache(component, UDA1380_PM);
Philipp Zabelb7482f52008-05-28 17:58:06 +0100544 clk &= ~0x3; /* clear SEL_LOOP_DIV */
545 switch (rate) {
546 case 6250 ... 12500:
547 clk |= 0x0;
548 break;
549 case 12501 ... 25000:
550 clk |= 0x1;
551 break;
552 case 25001 ... 50000:
553 clk |= 0x2;
554 break;
555 case 50001 ... 100000:
556 clk |= 0x3;
557 break;
558 }
Kuninori Morimotob40822d2018-01-29 04:44:09 +0000559 uda1380_write(component, UDA1380_PM, R02_PON_PLL | pm);
Philipp Zabelb7482f52008-05-28 17:58:06 +0100560 }
561
562 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
563 clk |= R00_EN_DAC | R00_EN_INT;
564 else
565 clk |= R00_EN_ADC | R00_EN_DEC;
566
Kuninori Morimotob40822d2018-01-29 04:44:09 +0000567 uda1380_write(component, UDA1380_CLK, clk);
Philipp Zabelb7482f52008-05-28 17:58:06 +0100568 return 0;
569}
570
Mark Browndee89c42008-11-18 22:11:38 +0000571static void uda1380_pcm_shutdown(struct snd_pcm_substream *substream,
572 struct snd_soc_dai *dai)
Philipp Zabelb7482f52008-05-28 17:58:06 +0100573{
Kuninori Morimotob40822d2018-01-29 04:44:09 +0000574 struct snd_soc_component *component = dai->component;
575 u16 clk = uda1380_read_reg_cache(component, UDA1380_CLK);
Philipp Zabelb7482f52008-05-28 17:58:06 +0100576
577 /* shut down WSPLL power if running from this clock */
578 if (clk & R00_DAC_CLK) {
Kuninori Morimotob40822d2018-01-29 04:44:09 +0000579 u16 pm = uda1380_read_reg_cache(component, UDA1380_PM);
580 uda1380_write(component, UDA1380_PM, ~R02_PON_PLL & pm);
Philipp Zabelb7482f52008-05-28 17:58:06 +0100581 }
582
583 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
584 clk &= ~(R00_EN_DAC | R00_EN_INT);
585 else
586 clk &= ~(R00_EN_ADC | R00_EN_DEC);
587
Kuninori Morimotob40822d2018-01-29 04:44:09 +0000588 uda1380_write(component, UDA1380_CLK, clk);
Philipp Zabelb7482f52008-05-28 17:58:06 +0100589}
590
Kuninori Morimotob40822d2018-01-29 04:44:09 +0000591static int uda1380_set_bias_level(struct snd_soc_component *component,
Philipp Zabelb7482f52008-05-28 17:58:06 +0100592 enum snd_soc_bias_level level)
593{
Kuninori Morimotob40822d2018-01-29 04:44:09 +0000594 int pm = uda1380_read_reg_cache(component, UDA1380_PM);
Vasily Khoruzhick8614d3102010-08-30 11:28:07 +0300595 int reg;
Kuninori Morimotob40822d2018-01-29 04:44:09 +0000596 struct uda1380_platform_data *pdata = component->dev->platform_data;
Vasily Khoruzhick8614d3102010-08-30 11:28:07 +0300597
Philipp Zabelb7482f52008-05-28 17:58:06 +0100598 switch (level) {
599 case SND_SOC_BIAS_ON:
600 case SND_SOC_BIAS_PREPARE:
Vasily Khoruzhick8614d3102010-08-30 11:28:07 +0300601 /* ADC, DAC on */
Kuninori Morimotob40822d2018-01-29 04:44:09 +0000602 uda1380_write(component, UDA1380_PM, R02_PON_BIAS | pm);
Philipp Zabelb7482f52008-05-28 17:58:06 +0100603 break;
604 case SND_SOC_BIAS_STANDBY:
Kuninori Morimotob40822d2018-01-29 04:44:09 +0000605 if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_OFF) {
Vasily Khoruzhick8614d3102010-08-30 11:28:07 +0300606 if (gpio_is_valid(pdata->gpio_power)) {
607 gpio_set_value(pdata->gpio_power, 1);
Vasily Khoruzhick8e3dce42010-09-07 17:04:17 +0300608 mdelay(1);
Kuninori Morimotob40822d2018-01-29 04:44:09 +0000609 uda1380_reset(component);
Vasily Khoruzhick8614d3102010-08-30 11:28:07 +0300610 }
611
Kuninori Morimotob40822d2018-01-29 04:44:09 +0000612 uda1380_sync_cache(component);
Vasily Khoruzhick8614d3102010-08-30 11:28:07 +0300613 }
Kuninori Morimotob40822d2018-01-29 04:44:09 +0000614 uda1380_write(component, UDA1380_PM, 0x0);
Philipp Zabelb7482f52008-05-28 17:58:06 +0100615 break;
Vasily Khoruzhick8614d3102010-08-30 11:28:07 +0300616 case SND_SOC_BIAS_OFF:
617 if (!gpio_is_valid(pdata->gpio_power))
618 break;
619
620 gpio_set_value(pdata->gpio_power, 0);
621
622 /* Mark mixer regs cache dirty to sync them with
623 * codec regs on power on.
624 */
625 for (reg = UDA1380_MVOL; reg < UDA1380_CACHEREGNUM; reg++)
626 set_bit(reg - 0x10, &uda1380_cache_dirty);
Philipp Zabelb7482f52008-05-28 17:58:06 +0100627 }
Philipp Zabelb7482f52008-05-28 17:58:06 +0100628 return 0;
629}
630
631#define UDA1380_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
632 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 |\
633 SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000)
634
Lars-Peter Clausen85e76522011-11-23 11:40:40 +0100635static const struct snd_soc_dai_ops uda1380_dai_ops = {
Eric Miao6335d052009-03-03 09:41:00 +0800636 .hw_params = uda1380_pcm_hw_params,
637 .shutdown = uda1380_pcm_shutdown,
Mark Brown65ec1cd2009-03-11 16:51:31 +0000638 .trigger = uda1380_trigger,
Eric Miao6335d052009-03-03 09:41:00 +0800639 .set_fmt = uda1380_set_dai_fmt_both,
640};
641
Lars-Peter Clausen85e76522011-11-23 11:40:40 +0100642static const struct snd_soc_dai_ops uda1380_dai_ops_playback = {
Eric Miao6335d052009-03-03 09:41:00 +0800643 .hw_params = uda1380_pcm_hw_params,
644 .shutdown = uda1380_pcm_shutdown,
Mark Brown65ec1cd2009-03-11 16:51:31 +0000645 .trigger = uda1380_trigger,
Eric Miao6335d052009-03-03 09:41:00 +0800646 .set_fmt = uda1380_set_dai_fmt_playback,
647};
648
Lars-Peter Clausen85e76522011-11-23 11:40:40 +0100649static const struct snd_soc_dai_ops uda1380_dai_ops_capture = {
Eric Miao6335d052009-03-03 09:41:00 +0800650 .hw_params = uda1380_pcm_hw_params,
651 .shutdown = uda1380_pcm_shutdown,
Mark Brown65ec1cd2009-03-11 16:51:31 +0000652 .trigger = uda1380_trigger,
Eric Miao6335d052009-03-03 09:41:00 +0800653 .set_fmt = uda1380_set_dai_fmt_capture,
654};
655
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000656static struct snd_soc_dai_driver uda1380_dai[] = {
Philipp Zabelb7482f52008-05-28 17:58:06 +0100657{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000658 .name = "uda1380-hifi",
Philipp Zabelb7482f52008-05-28 17:58:06 +0100659 .playback = {
660 .stream_name = "Playback",
661 .channels_min = 1,
662 .channels_max = 2,
663 .rates = UDA1380_RATES,
664 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
665 .capture = {
666 .stream_name = "Capture",
667 .channels_min = 1,
668 .channels_max = 2,
669 .rates = UDA1380_RATES,
670 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
Eric Miao6335d052009-03-03 09:41:00 +0800671 .ops = &uda1380_dai_ops,
Philipp Zabelb7482f52008-05-28 17:58:06 +0100672},
673{ /* playback only - dual interface */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000674 .name = "uda1380-hifi-playback",
Philipp Zabelb7482f52008-05-28 17:58:06 +0100675 .playback = {
676 .stream_name = "Playback",
677 .channels_min = 1,
678 .channels_max = 2,
679 .rates = UDA1380_RATES,
680 .formats = SNDRV_PCM_FMTBIT_S16_LE,
681 },
Eric Miao6335d052009-03-03 09:41:00 +0800682 .ops = &uda1380_dai_ops_playback,
Philipp Zabelb7482f52008-05-28 17:58:06 +0100683},
684{ /* capture only - dual interface*/
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000685 .name = "uda1380-hifi-capture",
Philipp Zabelb7482f52008-05-28 17:58:06 +0100686 .capture = {
687 .stream_name = "Capture",
688 .channels_min = 1,
689 .channels_max = 2,
690 .rates = UDA1380_RATES,
691 .formats = SNDRV_PCM_FMTBIT_S16_LE,
692 },
Eric Miao6335d052009-03-03 09:41:00 +0800693 .ops = &uda1380_dai_ops_capture,
Philipp Zabelb7482f52008-05-28 17:58:06 +0100694},
695};
Philipp Zabelb7482f52008-05-28 17:58:06 +0100696
Kuninori Morimotob40822d2018-01-29 04:44:09 +0000697static int uda1380_probe(struct snd_soc_component *component)
Philipp Zabelb7482f52008-05-28 17:58:06 +0100698{
Kuninori Morimotob40822d2018-01-29 04:44:09 +0000699 struct uda1380_platform_data *pdata =component->dev->platform_data;
700 struct uda1380_priv *uda1380 = snd_soc_component_get_drvdata(component);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000701 int ret;
Philipp Zabelb7482f52008-05-28 17:58:06 +0100702
Kuninori Morimotob40822d2018-01-29 04:44:09 +0000703 uda1380->component = component;
Philipp Zabelb7482f52008-05-28 17:58:06 +0100704
Lars-Peter Clausen222e7282016-11-23 10:30:11 +0100705 if (!gpio_is_valid(pdata->gpio_power)) {
Kuninori Morimotob40822d2018-01-29 04:44:09 +0000706 ret = uda1380_reset(component);
Axel Lin68020db2011-12-05 07:58:25 +0800707 if (ret)
Lars-Peter Clausen222e7282016-11-23 10:30:11 +0100708 return ret;
Philipp Zabelb7482f52008-05-28 17:58:06 +0100709 }
710
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000711 INIT_WORK(&uda1380->work, uda1380_flush_work);
712
Philipp Zabelb7482f52008-05-28 17:58:06 +0100713 /* set clock input */
Philipp Zabel1abd9182009-06-15 22:18:23 +0200714 switch (pdata->dac_clk) {
Philipp Zabelb7482f52008-05-28 17:58:06 +0100715 case UDA1380_DAC_CLK_SYSCLK:
Kuninori Morimotob40822d2018-01-29 04:44:09 +0000716 uda1380_write_reg_cache(component, UDA1380_CLK, 0);
Philipp Zabelb7482f52008-05-28 17:58:06 +0100717 break;
718 case UDA1380_DAC_CLK_WSPLL:
Kuninori Morimotob40822d2018-01-29 04:44:09 +0000719 uda1380_write_reg_cache(component, UDA1380_CLK,
Vasily Khoruzhick8614d3102010-08-30 11:28:07 +0300720 R00_DAC_CLK);
Philipp Zabelb7482f52008-05-28 17:58:06 +0100721 break;
722 }
723
Philipp Zabel1abd9182009-06-15 22:18:23 +0200724 return 0;
Philipp Zabel1abd9182009-06-15 22:18:23 +0200725}
Philipp Zabelb7482f52008-05-28 17:58:06 +0100726
Kuninori Morimotob40822d2018-01-29 04:44:09 +0000727static const struct snd_soc_component_driver soc_component_dev_uda1380 = {
728 .probe = uda1380_probe,
729 .read = uda1380_read_reg_cache,
730 .write = uda1380_write,
731 .set_bias_level = uda1380_set_bias_level,
732 .controls = uda1380_snd_controls,
733 .num_controls = ARRAY_SIZE(uda1380_snd_controls),
734 .dapm_widgets = uda1380_dapm_widgets,
735 .num_dapm_widgets = ARRAY_SIZE(uda1380_dapm_widgets),
736 .dapm_routes = uda1380_dapm_routes,
737 .num_dapm_routes = ARRAY_SIZE(uda1380_dapm_routes),
738 .suspend_bias_off = 1,
739 .idle_bias_on = 1,
740 .use_pmdown_time = 1,
741 .endianness = 1,
742 .non_legacy_dai_naming = 1,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000743};
744
Bill Pemberton7a79e942012-12-07 09:26:37 -0500745static int uda1380_i2c_probe(struct i2c_client *i2c,
746 const struct i2c_device_id *id)
Philipp Zabelb7482f52008-05-28 17:58:06 +0100747{
Lars-Peter Clausen222e7282016-11-23 10:30:11 +0100748 struct uda1380_platform_data *pdata = i2c->dev.platform_data;
Philipp Zabel1abd9182009-06-15 22:18:23 +0200749 struct uda1380_priv *uda1380;
Philipp Zabelb7482f52008-05-28 17:58:06 +0100750 int ret;
751
Lars-Peter Clausen222e7282016-11-23 10:30:11 +0100752 if (!pdata)
753 return -EINVAL;
754
Axel Lin6ce91ad2011-12-26 20:58:14 +0800755 uda1380 = devm_kzalloc(&i2c->dev, sizeof(struct uda1380_priv),
756 GFP_KERNEL);
Philipp Zabel1abd9182009-06-15 22:18:23 +0200757 if (uda1380 == NULL)
758 return -ENOMEM;
759
Lars-Peter Clausen222e7282016-11-23 10:30:11 +0100760 if (gpio_is_valid(pdata->gpio_reset)) {
761 ret = devm_gpio_request_one(&i2c->dev, pdata->gpio_reset,
762 GPIOF_OUT_INIT_LOW, "uda1380 reset");
763 if (ret)
764 return ret;
765 }
766
767 if (gpio_is_valid(pdata->gpio_power)) {
768 ret = devm_gpio_request_one(&i2c->dev, pdata->gpio_power,
769 GPIOF_OUT_INIT_LOW, "uda1380 power");
770 if (ret)
771 return ret;
772 }
773
Kuninori Morimotoc001bf62017-11-14 01:04:08 +0000774 uda1380->reg_cache = devm_kmemdup(&i2c->dev,
775 uda1380_reg,
776 ARRAY_SIZE(uda1380_reg) * sizeof(u16),
777 GFP_KERNEL);
778 if (!uda1380->reg_cache)
779 return -ENOMEM;
780
Philipp Zabel1abd9182009-06-15 22:18:23 +0200781 i2c_set_clientdata(i2c, uda1380);
Kuninori Morimotoeaa53212017-11-09 00:19:33 +0000782 uda1380->i2c = i2c;
Philipp Zabelb7482f52008-05-28 17:58:06 +0100783
Kuninori Morimotob40822d2018-01-29 04:44:09 +0000784 ret = devm_snd_soc_register_component(&i2c->dev,
785 &soc_component_dev_uda1380, uda1380_dai, ARRAY_SIZE(uda1380_dai));
Philipp Zabelb7482f52008-05-28 17:58:06 +0100786 return ret;
787}
788
Jean Delvare88fc39d2008-09-01 18:46:58 +0100789static const struct i2c_device_id uda1380_i2c_id[] = {
790 { "uda1380", 0 },
791 { }
792};
793MODULE_DEVICE_TABLE(i2c, uda1380_i2c_id);
Philipp Zabelb7482f52008-05-28 17:58:06 +0100794
Javier Martinez Canillasea22a262017-04-04 15:26:28 -0400795static const struct of_device_id uda1380_of_match[] = {
796 { .compatible = "nxp,uda1380", },
797 { }
798};
799MODULE_DEVICE_TABLE(of, uda1380_of_match);
800
Philipp Zabelb7482f52008-05-28 17:58:06 +0100801static struct i2c_driver uda1380_i2c_driver = {
802 .driver = {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000803 .name = "uda1380-codec",
Javier Martinez Canillasea22a262017-04-04 15:26:28 -0400804 .of_match_table = uda1380_of_match,
Philipp Zabelb7482f52008-05-28 17:58:06 +0100805 },
Jean Delvare88fc39d2008-09-01 18:46:58 +0100806 .probe = uda1380_i2c_probe,
Jean Delvare88fc39d2008-09-01 18:46:58 +0100807 .id_table = uda1380_i2c_id,
Philipp Zabelb7482f52008-05-28 17:58:06 +0100808};
Philipp Zabelb7482f52008-05-28 17:58:06 +0100809
Kuninori Morimoto4a5cf132016-11-17 01:12:30 +0000810module_i2c_driver(uda1380_i2c_driver);
Mark Brown64089b82008-12-08 19:17:58 +0000811
Philipp Zabelb7482f52008-05-28 17:58:06 +0100812MODULE_AUTHOR("Giorgio Padrin");
813MODULE_DESCRIPTION("Audio support for codec Philips UDA1380");
814MODULE_LICENSE("GPL");