xref: /OK3568_Linux_fs/kernel/sound/soc/codecs/max98504.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * MAX98504 ALSA SoC Audio driver
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright 2013 - 2014 Maxim Integrated Products
6*4882a593Smuzhiyun  * Copyright 2016 Samsung Electronics Co., Ltd.
7*4882a593Smuzhiyun  */
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #include <linux/delay.h>
10*4882a593Smuzhiyun #include <linux/i2c.h>
11*4882a593Smuzhiyun #include <linux/module.h>
12*4882a593Smuzhiyun #include <linux/regulator/consumer.h>
13*4882a593Smuzhiyun #include <linux/slab.h>
14*4882a593Smuzhiyun #include <linux/types.h>
15*4882a593Smuzhiyun #include <sound/soc.h>
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun #include "max98504.h"
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun static const char * const max98504_supply_names[] = {
20*4882a593Smuzhiyun 	"DVDD",
21*4882a593Smuzhiyun 	"DIOVDD",
22*4882a593Smuzhiyun 	"PVDD",
23*4882a593Smuzhiyun };
24*4882a593Smuzhiyun #define MAX98504_NUM_SUPPLIES ARRAY_SIZE(max98504_supply_names)
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun struct max98504_priv {
27*4882a593Smuzhiyun 	struct regmap *regmap;
28*4882a593Smuzhiyun 	struct regulator_bulk_data supplies[MAX98504_NUM_SUPPLIES];
29*4882a593Smuzhiyun 	unsigned int pcm_rx_channels;
30*4882a593Smuzhiyun 	bool brownout_enable;
31*4882a593Smuzhiyun 	unsigned int brownout_threshold;
32*4882a593Smuzhiyun 	unsigned int brownout_attenuation;
33*4882a593Smuzhiyun 	unsigned int brownout_attack_hold;
34*4882a593Smuzhiyun 	unsigned int brownout_timed_hold;
35*4882a593Smuzhiyun 	unsigned int brownout_release_rate;
36*4882a593Smuzhiyun };
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun static struct reg_default max98504_reg_defaults[] = {
39*4882a593Smuzhiyun 	{ 0x01,	0},
40*4882a593Smuzhiyun 	{ 0x02,	0},
41*4882a593Smuzhiyun 	{ 0x03,	0},
42*4882a593Smuzhiyun 	{ 0x04,	0},
43*4882a593Smuzhiyun 	{ 0x10, 0},
44*4882a593Smuzhiyun 	{ 0x11, 0},
45*4882a593Smuzhiyun 	{ 0x12, 0},
46*4882a593Smuzhiyun 	{ 0x13, 0},
47*4882a593Smuzhiyun 	{ 0x14, 0},
48*4882a593Smuzhiyun 	{ 0x15, 0},
49*4882a593Smuzhiyun 	{ 0x16, 0},
50*4882a593Smuzhiyun 	{ 0x17, 0},
51*4882a593Smuzhiyun 	{ 0x18, 0},
52*4882a593Smuzhiyun 	{ 0x19, 0},
53*4882a593Smuzhiyun 	{ 0x1A, 0},
54*4882a593Smuzhiyun 	{ 0x20, 0},
55*4882a593Smuzhiyun 	{ 0x21, 0},
56*4882a593Smuzhiyun 	{ 0x22, 0},
57*4882a593Smuzhiyun 	{ 0x23, 0},
58*4882a593Smuzhiyun 	{ 0x24, 0},
59*4882a593Smuzhiyun 	{ 0x25, 0},
60*4882a593Smuzhiyun 	{ 0x26, 0},
61*4882a593Smuzhiyun 	{ 0x27, 0},
62*4882a593Smuzhiyun 	{ 0x28, 0},
63*4882a593Smuzhiyun 	{ 0x30, 0},
64*4882a593Smuzhiyun 	{ 0x31, 0},
65*4882a593Smuzhiyun 	{ 0x32, 0},
66*4882a593Smuzhiyun 	{ 0x33, 0},
67*4882a593Smuzhiyun 	{ 0x34, 0},
68*4882a593Smuzhiyun 	{ 0x35, 0},
69*4882a593Smuzhiyun 	{ 0x36, 0},
70*4882a593Smuzhiyun 	{ 0x37, 0},
71*4882a593Smuzhiyun 	{ 0x38, 0},
72*4882a593Smuzhiyun 	{ 0x39, 0},
73*4882a593Smuzhiyun 	{ 0x40, 0},
74*4882a593Smuzhiyun 	{ 0x41, 0},
75*4882a593Smuzhiyun };
76*4882a593Smuzhiyun 
max98504_volatile_register(struct device * dev,unsigned int reg)77*4882a593Smuzhiyun static bool max98504_volatile_register(struct device *dev, unsigned int reg)
78*4882a593Smuzhiyun {
79*4882a593Smuzhiyun 	switch (reg) {
80*4882a593Smuzhiyun 	case MAX98504_INTERRUPT_STATUS:
81*4882a593Smuzhiyun 	case MAX98504_INTERRUPT_FLAGS:
82*4882a593Smuzhiyun 	case MAX98504_INTERRUPT_FLAG_CLEARS:
83*4882a593Smuzhiyun 	case MAX98504_WATCHDOG_CLEAR:
84*4882a593Smuzhiyun 	case MAX98504_GLOBAL_ENABLE:
85*4882a593Smuzhiyun 	case MAX98504_SOFTWARE_RESET:
86*4882a593Smuzhiyun 		return true;
87*4882a593Smuzhiyun 	default:
88*4882a593Smuzhiyun 		return false;
89*4882a593Smuzhiyun 	}
90*4882a593Smuzhiyun }
91*4882a593Smuzhiyun 
max98504_readable_register(struct device * dev,unsigned int reg)92*4882a593Smuzhiyun static bool max98504_readable_register(struct device *dev, unsigned int reg)
93*4882a593Smuzhiyun {
94*4882a593Smuzhiyun 	switch (reg) {
95*4882a593Smuzhiyun 	case MAX98504_SOFTWARE_RESET:
96*4882a593Smuzhiyun 	case MAX98504_WATCHDOG_CLEAR:
97*4882a593Smuzhiyun 	case MAX98504_INTERRUPT_FLAG_CLEARS:
98*4882a593Smuzhiyun 		return false;
99*4882a593Smuzhiyun 	default:
100*4882a593Smuzhiyun 		return true;
101*4882a593Smuzhiyun 	}
102*4882a593Smuzhiyun }
103*4882a593Smuzhiyun 
max98504_pcm_rx_ev(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)104*4882a593Smuzhiyun static int max98504_pcm_rx_ev(struct snd_soc_dapm_widget *w,
105*4882a593Smuzhiyun 			      struct snd_kcontrol *kcontrol, int event)
106*4882a593Smuzhiyun {
107*4882a593Smuzhiyun 	struct snd_soc_component *c = snd_soc_dapm_to_component(w->dapm);
108*4882a593Smuzhiyun 	struct max98504_priv *max98504 = snd_soc_component_get_drvdata(c);
109*4882a593Smuzhiyun 
110*4882a593Smuzhiyun 	switch (event) {
111*4882a593Smuzhiyun 	case SND_SOC_DAPM_PRE_PMU:
112*4882a593Smuzhiyun 		regmap_write(max98504->regmap, MAX98504_PCM_RX_ENABLE,
113*4882a593Smuzhiyun 			     max98504->pcm_rx_channels);
114*4882a593Smuzhiyun 		break;
115*4882a593Smuzhiyun 	case SND_SOC_DAPM_POST_PMD:
116*4882a593Smuzhiyun 		regmap_write(max98504->regmap, MAX98504_PCM_RX_ENABLE, 0);
117*4882a593Smuzhiyun 		break;
118*4882a593Smuzhiyun 	}
119*4882a593Smuzhiyun 
120*4882a593Smuzhiyun 	return 0;
121*4882a593Smuzhiyun }
122*4882a593Smuzhiyun 
max98504_component_probe(struct snd_soc_component * c)123*4882a593Smuzhiyun static int max98504_component_probe(struct snd_soc_component *c)
124*4882a593Smuzhiyun {
125*4882a593Smuzhiyun 	struct max98504_priv *max98504 = snd_soc_component_get_drvdata(c);
126*4882a593Smuzhiyun 	struct regmap *map = max98504->regmap;
127*4882a593Smuzhiyun 	int ret;
128*4882a593Smuzhiyun 
129*4882a593Smuzhiyun 	ret = regulator_bulk_enable(MAX98504_NUM_SUPPLIES, max98504->supplies);
130*4882a593Smuzhiyun 	if (ret < 0)
131*4882a593Smuzhiyun 		return ret;
132*4882a593Smuzhiyun 
133*4882a593Smuzhiyun 	regmap_write(map, MAX98504_SOFTWARE_RESET, 0x1);
134*4882a593Smuzhiyun 	msleep(20);
135*4882a593Smuzhiyun 
136*4882a593Smuzhiyun 	if (!max98504->brownout_enable)
137*4882a593Smuzhiyun 		return 0;
138*4882a593Smuzhiyun 
139*4882a593Smuzhiyun 	regmap_write(map, MAX98504_PVDD_BROWNOUT_ENABLE, 0x1);
140*4882a593Smuzhiyun 
141*4882a593Smuzhiyun 	regmap_write(map, MAX98504_PVDD_BROWNOUT_CONFIG_1,
142*4882a593Smuzhiyun 		     (max98504->brownout_threshold & 0x1f) << 3 |
143*4882a593Smuzhiyun 		     (max98504->brownout_attenuation & 0x3));
144*4882a593Smuzhiyun 
145*4882a593Smuzhiyun 	regmap_write(map, MAX98504_PVDD_BROWNOUT_CONFIG_2,
146*4882a593Smuzhiyun 		     max98504->brownout_attack_hold & 0xff);
147*4882a593Smuzhiyun 
148*4882a593Smuzhiyun 	regmap_write(map, MAX98504_PVDD_BROWNOUT_CONFIG_3,
149*4882a593Smuzhiyun 		     max98504->brownout_timed_hold & 0xff);
150*4882a593Smuzhiyun 
151*4882a593Smuzhiyun 	regmap_write(map, MAX98504_PVDD_BROWNOUT_CONFIG_4,
152*4882a593Smuzhiyun 		     max98504->brownout_release_rate & 0xff);
153*4882a593Smuzhiyun 
154*4882a593Smuzhiyun 	return 0;
155*4882a593Smuzhiyun }
156*4882a593Smuzhiyun 
max98504_component_remove(struct snd_soc_component * c)157*4882a593Smuzhiyun static void max98504_component_remove(struct snd_soc_component *c)
158*4882a593Smuzhiyun {
159*4882a593Smuzhiyun 	struct max98504_priv *max98504 = snd_soc_component_get_drvdata(c);
160*4882a593Smuzhiyun 
161*4882a593Smuzhiyun 	regulator_bulk_disable(MAX98504_NUM_SUPPLIES, max98504->supplies);
162*4882a593Smuzhiyun }
163*4882a593Smuzhiyun 
164*4882a593Smuzhiyun static const char *spk_source_mux_text[] = {
165*4882a593Smuzhiyun 	"PCM Monomix", "Analog In", "PDM Left", "PDM Right"
166*4882a593Smuzhiyun };
167*4882a593Smuzhiyun 
168*4882a593Smuzhiyun static const struct soc_enum spk_source_mux_enum =
169*4882a593Smuzhiyun 	SOC_ENUM_SINGLE(MAX98504_SPEAKER_SOURCE_SELECT,
170*4882a593Smuzhiyun 			0, ARRAY_SIZE(spk_source_mux_text),
171*4882a593Smuzhiyun 			spk_source_mux_text);
172*4882a593Smuzhiyun 
173*4882a593Smuzhiyun static const struct snd_kcontrol_new spk_source_mux =
174*4882a593Smuzhiyun 	SOC_DAPM_ENUM("SPK Source", spk_source_mux_enum);
175*4882a593Smuzhiyun 
176*4882a593Smuzhiyun static const struct snd_soc_dapm_route max98504_dapm_routes[] = {
177*4882a593Smuzhiyun 	{ "SPKOUT", NULL, "Global Enable" },
178*4882a593Smuzhiyun 	{ "SPK Source", "PCM Monomix", "DAC PCM" },
179*4882a593Smuzhiyun 	{ "SPK Source", "Analog In", "AIN" },
180*4882a593Smuzhiyun 	{ "SPK Source", "PDM Left", "DAC PDM" },
181*4882a593Smuzhiyun 	{ "SPK Source", "PDM Right", "DAC PDM" },
182*4882a593Smuzhiyun };
183*4882a593Smuzhiyun 
184*4882a593Smuzhiyun static const struct snd_soc_dapm_widget max98504_dapm_widgets[] = {
185*4882a593Smuzhiyun 	SND_SOC_DAPM_SUPPLY("Global Enable", MAX98504_GLOBAL_ENABLE,
186*4882a593Smuzhiyun 		0, 0, NULL, 0),
187*4882a593Smuzhiyun 	SND_SOC_DAPM_INPUT("AIN"),
188*4882a593Smuzhiyun 	SND_SOC_DAPM_AIF_OUT("AIF2OUTL", "AIF2 Capture", 0, SND_SOC_NOPM, 0, 0),
189*4882a593Smuzhiyun 	SND_SOC_DAPM_AIF_OUT("AIF2OUTR", "AIF2 Capture", 1, SND_SOC_NOPM, 0, 0),
190*4882a593Smuzhiyun 	SND_SOC_DAPM_DAC_E("DAC PCM", NULL, SND_SOC_NOPM, 0, 0,
191*4882a593Smuzhiyun 		max98504_pcm_rx_ev,
192*4882a593Smuzhiyun 		SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
193*4882a593Smuzhiyun 	SND_SOC_DAPM_DAC("DAC PDM", NULL, MAX98504_PDM_RX_ENABLE, 0, 0),
194*4882a593Smuzhiyun 	SND_SOC_DAPM_MUX("SPK Source", SND_SOC_NOPM, 0, 0, &spk_source_mux),
195*4882a593Smuzhiyun 	SND_SOC_DAPM_REG(snd_soc_dapm_spk, "SPKOUT",
196*4882a593Smuzhiyun 		MAX98504_SPEAKER_ENABLE, 0, 1, 1, 0),
197*4882a593Smuzhiyun };
198*4882a593Smuzhiyun 
max98504_set_tdm_slot(struct snd_soc_dai * dai,unsigned int tx_mask,unsigned int rx_mask,int slots,int slot_width)199*4882a593Smuzhiyun static int max98504_set_tdm_slot(struct snd_soc_dai *dai,
200*4882a593Smuzhiyun 		unsigned int tx_mask, unsigned int rx_mask,
201*4882a593Smuzhiyun 		int slots, int slot_width)
202*4882a593Smuzhiyun {
203*4882a593Smuzhiyun 	struct max98504_priv *max98504 = snd_soc_dai_get_drvdata(dai);
204*4882a593Smuzhiyun 	struct regmap *map = max98504->regmap;
205*4882a593Smuzhiyun 
206*4882a593Smuzhiyun 
207*4882a593Smuzhiyun 	switch (dai->id) {
208*4882a593Smuzhiyun 	case MAX98504_DAI_ID_PCM:
209*4882a593Smuzhiyun 		regmap_write(map, MAX98504_PCM_TX_ENABLE, tx_mask);
210*4882a593Smuzhiyun 		max98504->pcm_rx_channels = rx_mask;
211*4882a593Smuzhiyun 		break;
212*4882a593Smuzhiyun 
213*4882a593Smuzhiyun 	case MAX98504_DAI_ID_PDM:
214*4882a593Smuzhiyun 		regmap_write(map, MAX98504_PDM_TX_ENABLE, tx_mask);
215*4882a593Smuzhiyun 		break;
216*4882a593Smuzhiyun 	default:
217*4882a593Smuzhiyun 		WARN_ON(1);
218*4882a593Smuzhiyun 	}
219*4882a593Smuzhiyun 
220*4882a593Smuzhiyun 	return 0;
221*4882a593Smuzhiyun }
max98504_set_channel_map(struct snd_soc_dai * dai,unsigned int tx_num,unsigned int * tx_slot,unsigned int rx_num,unsigned int * rx_slot)222*4882a593Smuzhiyun static int max98504_set_channel_map(struct snd_soc_dai *dai,
223*4882a593Smuzhiyun 		unsigned int tx_num, unsigned int *tx_slot,
224*4882a593Smuzhiyun 		unsigned int rx_num, unsigned int *rx_slot)
225*4882a593Smuzhiyun {
226*4882a593Smuzhiyun 	struct max98504_priv *max98504 = snd_soc_dai_get_drvdata(dai);
227*4882a593Smuzhiyun 	struct regmap *map = max98504->regmap;
228*4882a593Smuzhiyun 	unsigned int i, sources = 0;
229*4882a593Smuzhiyun 
230*4882a593Smuzhiyun 	for (i = 0; i < tx_num; i++)
231*4882a593Smuzhiyun 		if (tx_slot[i])
232*4882a593Smuzhiyun 			sources |= (1 << i);
233*4882a593Smuzhiyun 
234*4882a593Smuzhiyun 	switch (dai->id) {
235*4882a593Smuzhiyun 	case MAX98504_DAI_ID_PCM:
236*4882a593Smuzhiyun 		regmap_write(map, MAX98504_PCM_TX_CHANNEL_SOURCES,
237*4882a593Smuzhiyun 			     sources);
238*4882a593Smuzhiyun 		break;
239*4882a593Smuzhiyun 
240*4882a593Smuzhiyun 	case MAX98504_DAI_ID_PDM:
241*4882a593Smuzhiyun 		regmap_write(map, MAX98504_PDM_TX_CONTROL, sources);
242*4882a593Smuzhiyun 		break;
243*4882a593Smuzhiyun 	default:
244*4882a593Smuzhiyun 		WARN_ON(1);
245*4882a593Smuzhiyun 	}
246*4882a593Smuzhiyun 
247*4882a593Smuzhiyun 	regmap_write(map, MAX98504_MEASUREMENT_ENABLE, sources ? 0x3 : 0x01);
248*4882a593Smuzhiyun 
249*4882a593Smuzhiyun 	return 0;
250*4882a593Smuzhiyun }
251*4882a593Smuzhiyun 
252*4882a593Smuzhiyun static const struct snd_soc_dai_ops max98504_dai_ops = {
253*4882a593Smuzhiyun 	.set_tdm_slot		= max98504_set_tdm_slot,
254*4882a593Smuzhiyun 	.set_channel_map	= max98504_set_channel_map,
255*4882a593Smuzhiyun };
256*4882a593Smuzhiyun 
257*4882a593Smuzhiyun #define MAX98504_FORMATS	(SNDRV_PCM_FMTBIT_S8|SNDRV_PCM_FMTBIT_S16_LE|\
258*4882a593Smuzhiyun 				SNDRV_PCM_FMTBIT_S24_LE|SNDRV_PCM_FMTBIT_S32_LE)
259*4882a593Smuzhiyun #define MAX98504_PDM_RATES	(SNDRV_PCM_RATE_8000|SNDRV_PCM_RATE_16000|\
260*4882a593Smuzhiyun 				SNDRV_PCM_RATE_32000|SNDRV_PCM_RATE_44100|\
261*4882a593Smuzhiyun 				SNDRV_PCM_RATE_48000|SNDRV_PCM_RATE_88200|\
262*4882a593Smuzhiyun 				SNDRV_PCM_RATE_96000)
263*4882a593Smuzhiyun 
264*4882a593Smuzhiyun static struct snd_soc_dai_driver max98504_dai[] = {
265*4882a593Smuzhiyun 	/* TODO: Add the PCM interface definitions */
266*4882a593Smuzhiyun 	{
267*4882a593Smuzhiyun 		.name = "max98504-aif2",
268*4882a593Smuzhiyun 		.id = MAX98504_DAI_ID_PDM,
269*4882a593Smuzhiyun 		.playback = {
270*4882a593Smuzhiyun 			.stream_name	= "AIF2 Playback",
271*4882a593Smuzhiyun 			.channels_min	= 1,
272*4882a593Smuzhiyun 			.channels_max	= 2,
273*4882a593Smuzhiyun 			.rates		= MAX98504_PDM_RATES,
274*4882a593Smuzhiyun 			.formats	= MAX98504_FORMATS,
275*4882a593Smuzhiyun 		},
276*4882a593Smuzhiyun 		.capture = {
277*4882a593Smuzhiyun 			.stream_name	= "AIF2 Capture",
278*4882a593Smuzhiyun 			.channels_min	= 1,
279*4882a593Smuzhiyun 			.channels_max	= 2,
280*4882a593Smuzhiyun 			.rates		= MAX98504_PDM_RATES,
281*4882a593Smuzhiyun 			.formats	= MAX98504_FORMATS,
282*4882a593Smuzhiyun 		},
283*4882a593Smuzhiyun 		.ops = &max98504_dai_ops,
284*4882a593Smuzhiyun 	},
285*4882a593Smuzhiyun };
286*4882a593Smuzhiyun 
287*4882a593Smuzhiyun static const struct snd_soc_component_driver max98504_component_driver = {
288*4882a593Smuzhiyun 	.probe			= max98504_component_probe,
289*4882a593Smuzhiyun 	.remove			= max98504_component_remove,
290*4882a593Smuzhiyun 	.dapm_widgets		= max98504_dapm_widgets,
291*4882a593Smuzhiyun 	.num_dapm_widgets	= ARRAY_SIZE(max98504_dapm_widgets),
292*4882a593Smuzhiyun 	.dapm_routes		= max98504_dapm_routes,
293*4882a593Smuzhiyun 	.num_dapm_routes	= ARRAY_SIZE(max98504_dapm_routes),
294*4882a593Smuzhiyun };
295*4882a593Smuzhiyun 
296*4882a593Smuzhiyun static const struct regmap_config max98504_regmap = {
297*4882a593Smuzhiyun 	.reg_bits		= 16,
298*4882a593Smuzhiyun 	.val_bits		= 8,
299*4882a593Smuzhiyun 	.max_register		= MAX98504_MAX_REGISTER,
300*4882a593Smuzhiyun 	.reg_defaults		= max98504_reg_defaults,
301*4882a593Smuzhiyun 	.num_reg_defaults	= ARRAY_SIZE(max98504_reg_defaults),
302*4882a593Smuzhiyun 	.volatile_reg		= max98504_volatile_register,
303*4882a593Smuzhiyun 	.readable_reg		= max98504_readable_register,
304*4882a593Smuzhiyun 	.cache_type		= REGCACHE_RBTREE,
305*4882a593Smuzhiyun };
306*4882a593Smuzhiyun 
max98504_i2c_probe(struct i2c_client * client,const struct i2c_device_id * id)307*4882a593Smuzhiyun static int max98504_i2c_probe(struct i2c_client *client,
308*4882a593Smuzhiyun 			      const struct i2c_device_id *id)
309*4882a593Smuzhiyun {
310*4882a593Smuzhiyun 	struct device *dev = &client->dev;
311*4882a593Smuzhiyun 	struct device_node *node = dev->of_node;
312*4882a593Smuzhiyun 	struct max98504_priv *max98504;
313*4882a593Smuzhiyun 	int i, ret;
314*4882a593Smuzhiyun 
315*4882a593Smuzhiyun 	max98504 = devm_kzalloc(dev, sizeof(*max98504), GFP_KERNEL);
316*4882a593Smuzhiyun 	if (!max98504)
317*4882a593Smuzhiyun 		return -ENOMEM;
318*4882a593Smuzhiyun 
319*4882a593Smuzhiyun 	if (node) {
320*4882a593Smuzhiyun 		if (!of_property_read_u32(node, "maxim,brownout-threshold",
321*4882a593Smuzhiyun 					&max98504->brownout_threshold))
322*4882a593Smuzhiyun 			max98504->brownout_enable = true;
323*4882a593Smuzhiyun 
324*4882a593Smuzhiyun 		of_property_read_u32(node, "maxim,brownout-attenuation",
325*4882a593Smuzhiyun 					&max98504->brownout_attenuation);
326*4882a593Smuzhiyun 		of_property_read_u32(node, "maxim,brownout-attack-hold-ms",
327*4882a593Smuzhiyun 					&max98504->brownout_attack_hold);
328*4882a593Smuzhiyun 		of_property_read_u32(node, "maxim,brownout-timed-hold-ms",
329*4882a593Smuzhiyun 					&max98504->brownout_timed_hold);
330*4882a593Smuzhiyun 		of_property_read_u32(node, "maxim,brownout-release-rate-ms",
331*4882a593Smuzhiyun 					&max98504->brownout_release_rate);
332*4882a593Smuzhiyun 	}
333*4882a593Smuzhiyun 
334*4882a593Smuzhiyun 	max98504->regmap = devm_regmap_init_i2c(client, &max98504_regmap);
335*4882a593Smuzhiyun 	if (IS_ERR(max98504->regmap)) {
336*4882a593Smuzhiyun 		ret = PTR_ERR(max98504->regmap);
337*4882a593Smuzhiyun 		dev_err(&client->dev, "regmap initialization failed: %d\n", ret);
338*4882a593Smuzhiyun 		return ret;
339*4882a593Smuzhiyun 	}
340*4882a593Smuzhiyun 
341*4882a593Smuzhiyun 	for (i = 0; i < MAX98504_NUM_SUPPLIES; i++)
342*4882a593Smuzhiyun 		max98504->supplies[i].supply = max98504_supply_names[i];
343*4882a593Smuzhiyun 
344*4882a593Smuzhiyun 	ret = devm_regulator_bulk_get(dev, MAX98504_NUM_SUPPLIES,
345*4882a593Smuzhiyun 				      max98504->supplies);
346*4882a593Smuzhiyun 	if (ret < 0)
347*4882a593Smuzhiyun 		return ret;
348*4882a593Smuzhiyun 
349*4882a593Smuzhiyun 	i2c_set_clientdata(client, max98504);
350*4882a593Smuzhiyun 
351*4882a593Smuzhiyun 	return devm_snd_soc_register_component(dev, &max98504_component_driver,
352*4882a593Smuzhiyun 				max98504_dai, ARRAY_SIZE(max98504_dai));
353*4882a593Smuzhiyun }
354*4882a593Smuzhiyun 
355*4882a593Smuzhiyun #ifdef CONFIG_OF
356*4882a593Smuzhiyun static const struct of_device_id max98504_of_match[] = {
357*4882a593Smuzhiyun 	{ .compatible = "maxim,max98504" },
358*4882a593Smuzhiyun 	{ },
359*4882a593Smuzhiyun };
360*4882a593Smuzhiyun MODULE_DEVICE_TABLE(of, max98504_of_match);
361*4882a593Smuzhiyun #endif
362*4882a593Smuzhiyun 
363*4882a593Smuzhiyun static const struct i2c_device_id max98504_i2c_id[] = {
364*4882a593Smuzhiyun 	{ "max98504" },
365*4882a593Smuzhiyun 	{ }
366*4882a593Smuzhiyun };
367*4882a593Smuzhiyun MODULE_DEVICE_TABLE(i2c, max98504_i2c_id);
368*4882a593Smuzhiyun 
369*4882a593Smuzhiyun static struct i2c_driver max98504_i2c_driver = {
370*4882a593Smuzhiyun 	.driver = {
371*4882a593Smuzhiyun 		.name = "max98504",
372*4882a593Smuzhiyun 		.of_match_table = of_match_ptr(max98504_of_match),
373*4882a593Smuzhiyun 	},
374*4882a593Smuzhiyun 	.probe = max98504_i2c_probe,
375*4882a593Smuzhiyun 	.id_table = max98504_i2c_id,
376*4882a593Smuzhiyun };
377*4882a593Smuzhiyun module_i2c_driver(max98504_i2c_driver);
378*4882a593Smuzhiyun 
379*4882a593Smuzhiyun MODULE_DESCRIPTION("ASoC MAX98504 driver");
380*4882a593Smuzhiyun MODULE_LICENSE("GPL");
381