Loading...
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * max9850.c -- codec driver for max9850
4 *
5 * Copyright (C) 2011 taskit GmbH
6 *
7 * Author: Christian Glindkamp <christian.glindkamp@taskit.de>
8 *
9 * Initial development of this code was funded by
10 * MICRONIC Computer Systeme GmbH, https://www.mcsberlin.de/
11 */
12
13#include <linux/module.h>
14#include <linux/init.h>
15#include <linux/i2c.h>
16#include <linux/regmap.h>
17#include <linux/slab.h>
18#include <sound/pcm.h>
19#include <sound/pcm_params.h>
20#include <sound/soc.h>
21#include <sound/tlv.h>
22
23#include "max9850.h"
24
25struct max9850_priv {
26 struct regmap *regmap;
27 unsigned int sysclk;
28};
29
30/* these registers are not used at the moment but provided for the sake of
31 * completeness */
32static bool max9850_volatile_register(struct device *dev, unsigned int reg)
33{
34 switch (reg) {
35 case MAX9850_STATUSA:
36 case MAX9850_STATUSB:
37 return true;
38 default:
39 return false;
40 }
41}
42
43static const struct regmap_config max9850_regmap = {
44 .reg_bits = 8,
45 .val_bits = 8,
46
47 .max_register = MAX9850_DIGITAL_AUDIO,
48 .volatile_reg = max9850_volatile_register,
49 .cache_type = REGCACHE_RBTREE,
50};
51
52static const DECLARE_TLV_DB_RANGE(max9850_tlv,
53 0x18, 0x1f, TLV_DB_SCALE_ITEM(-7450, 400, 0),
54 0x20, 0x33, TLV_DB_SCALE_ITEM(-4150, 200, 0),
55 0x34, 0x37, TLV_DB_SCALE_ITEM(-150, 100, 0),
56 0x38, 0x3f, TLV_DB_SCALE_ITEM(250, 50, 0)
57);
58
59static const struct snd_kcontrol_new max9850_controls[] = {
60SOC_SINGLE_TLV("Headphone Volume", MAX9850_VOLUME, 0, 0x3f, 1, max9850_tlv),
61SOC_SINGLE("Headphone Switch", MAX9850_VOLUME, 7, 1, 1),
62SOC_SINGLE("Mono Switch", MAX9850_GENERAL_PURPOSE, 2, 1, 0),
63};
64
65static const struct snd_kcontrol_new max9850_mixer_controls[] = {
66 SOC_DAPM_SINGLE("Line In Switch", MAX9850_ENABLE, 1, 1, 0),
67};
68
69static const struct snd_soc_dapm_widget max9850_dapm_widgets[] = {
70SND_SOC_DAPM_SUPPLY("Charge Pump 1", MAX9850_ENABLE, 4, 0, NULL, 0),
71SND_SOC_DAPM_SUPPLY("Charge Pump 2", MAX9850_ENABLE, 5, 0, NULL, 0),
72SND_SOC_DAPM_SUPPLY("MCLK", MAX9850_ENABLE, 6, 0, NULL, 0),
73SND_SOC_DAPM_SUPPLY("SHDN", MAX9850_ENABLE, 7, 0, NULL, 0),
74SND_SOC_DAPM_MIXER_NAMED_CTL("Output Mixer", MAX9850_ENABLE, 2, 0,
75 &max9850_mixer_controls[0],
76 ARRAY_SIZE(max9850_mixer_controls)),
77SND_SOC_DAPM_PGA("Headphone Output", MAX9850_ENABLE, 3, 0, NULL, 0),
78SND_SOC_DAPM_DAC("DAC", "HiFi Playback", MAX9850_ENABLE, 0, 0),
79SND_SOC_DAPM_OUTPUT("OUTL"),
80SND_SOC_DAPM_OUTPUT("HPL"),
81SND_SOC_DAPM_OUTPUT("OUTR"),
82SND_SOC_DAPM_OUTPUT("HPR"),
83SND_SOC_DAPM_MIXER("Line Input", SND_SOC_NOPM, 0, 0, NULL, 0),
84SND_SOC_DAPM_INPUT("INL"),
85SND_SOC_DAPM_INPUT("INR"),
86};
87
88static const struct snd_soc_dapm_route max9850_dapm_routes[] = {
89 /* output mixer */
90 {"Output Mixer", NULL, "DAC"},
91 {"Output Mixer", "Line In Switch", "Line Input"},
92
93 /* outputs */
94 {"Headphone Output", NULL, "Output Mixer"},
95 {"HPL", NULL, "Headphone Output"},
96 {"HPR", NULL, "Headphone Output"},
97 {"OUTL", NULL, "Output Mixer"},
98 {"OUTR", NULL, "Output Mixer"},
99
100 /* inputs */
101 {"Line Input", NULL, "INL"},
102 {"Line Input", NULL, "INR"},
103
104 /* supplies */
105 {"Output Mixer", NULL, "Charge Pump 1"},
106 {"Output Mixer", NULL, "Charge Pump 2"},
107 {"Output Mixer", NULL, "SHDN"},
108 {"DAC", NULL, "MCLK"},
109};
110
111static int max9850_hw_params(struct snd_pcm_substream *substream,
112 struct snd_pcm_hw_params *params,
113 struct snd_soc_dai *dai)
114{
115 struct snd_soc_component *component = dai->component;
116 struct max9850_priv *max9850 = snd_soc_component_get_drvdata(component);
117 u64 lrclk_div;
118 u8 sf, da;
119
120 if (!max9850->sysclk)
121 return -EINVAL;
122
123 /* lrclk_div = 2^22 * rate / iclk with iclk = mclk / sf */
124 sf = (snd_soc_component_read(component, MAX9850_CLOCK) >> 2) + 1;
125 lrclk_div = (1 << 22);
126 lrclk_div *= params_rate(params);
127 lrclk_div *= sf;
128 do_div(lrclk_div, max9850->sysclk);
129
130 snd_soc_component_write(component, MAX9850_LRCLK_MSB, (lrclk_div >> 8) & 0x7f);
131 snd_soc_component_write(component, MAX9850_LRCLK_LSB, lrclk_div & 0xff);
132
133 switch (params_width(params)) {
134 case 16:
135 da = 0;
136 break;
137 case 20:
138 da = 0x2;
139 break;
140 case 24:
141 da = 0x3;
142 break;
143 default:
144 return -EINVAL;
145 }
146 snd_soc_component_update_bits(component, MAX9850_DIGITAL_AUDIO, 0x3, da);
147
148 return 0;
149}
150
151static int max9850_set_dai_sysclk(struct snd_soc_dai *codec_dai,
152 int clk_id, unsigned int freq, int dir)
153{
154 struct snd_soc_component *component = codec_dai->component;
155 struct max9850_priv *max9850 = snd_soc_component_get_drvdata(component);
156
157 /* calculate mclk -> iclk divider */
158 if (freq <= 13000000)
159 snd_soc_component_write(component, MAX9850_CLOCK, 0x0);
160 else if (freq <= 26000000)
161 snd_soc_component_write(component, MAX9850_CLOCK, 0x4);
162 else if (freq <= 40000000)
163 snd_soc_component_write(component, MAX9850_CLOCK, 0x8);
164 else
165 return -EINVAL;
166
167 max9850->sysclk = freq;
168 return 0;
169}
170
171static int max9850_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
172{
173 struct snd_soc_component *component = codec_dai->component;
174 u8 da = 0;
175
176 /* set clock provider for audio interface */
177 switch (fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) {
178 case SND_SOC_DAIFMT_CBP_CFP:
179 da |= MAX9850_MASTER;
180 break;
181 case SND_SOC_DAIFMT_CBC_CFC:
182 break;
183 default:
184 return -EINVAL;
185 }
186
187 /* interface format */
188 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
189 case SND_SOC_DAIFMT_I2S:
190 da |= MAX9850_DLY;
191 break;
192 case SND_SOC_DAIFMT_RIGHT_J:
193 da |= MAX9850_RTJ;
194 break;
195 case SND_SOC_DAIFMT_LEFT_J:
196 break;
197 default:
198 return -EINVAL;
199 }
200
201 /* clock inversion */
202 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
203 case SND_SOC_DAIFMT_NB_NF:
204 break;
205 case SND_SOC_DAIFMT_IB_IF:
206 da |= MAX9850_BCINV | MAX9850_INV;
207 break;
208 case SND_SOC_DAIFMT_IB_NF:
209 da |= MAX9850_BCINV;
210 break;
211 case SND_SOC_DAIFMT_NB_IF:
212 da |= MAX9850_INV;
213 break;
214 default:
215 return -EINVAL;
216 }
217
218 /* set da */
219 snd_soc_component_write(component, MAX9850_DIGITAL_AUDIO, da);
220
221 return 0;
222}
223
224static int max9850_set_bias_level(struct snd_soc_component *component,
225 enum snd_soc_bias_level level)
226{
227 struct max9850_priv *max9850 = snd_soc_component_get_drvdata(component);
228 int ret;
229
230 switch (level) {
231 case SND_SOC_BIAS_ON:
232 break;
233 case SND_SOC_BIAS_PREPARE:
234 break;
235 case SND_SOC_BIAS_STANDBY:
236 if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_OFF) {
237 ret = regcache_sync(max9850->regmap);
238 if (ret) {
239 dev_err(component->dev,
240 "Failed to sync cache: %d\n", ret);
241 return ret;
242 }
243 }
244 break;
245 case SND_SOC_BIAS_OFF:
246 break;
247 }
248 return 0;
249}
250
251#define MAX9850_RATES SNDRV_PCM_RATE_8000_48000
252
253#define MAX9850_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
254 SNDRV_PCM_FMTBIT_S24_LE)
255
256static const struct snd_soc_dai_ops max9850_dai_ops = {
257 .hw_params = max9850_hw_params,
258 .set_sysclk = max9850_set_dai_sysclk,
259 .set_fmt = max9850_set_dai_fmt,
260};
261
262static struct snd_soc_dai_driver max9850_dai = {
263 .name = "max9850-hifi",
264 .playback = {
265 .stream_name = "Playback",
266 .channels_min = 1,
267 .channels_max = 2,
268 .rates = MAX9850_RATES,
269 .formats = MAX9850_FORMATS
270 },
271 .ops = &max9850_dai_ops,
272};
273
274static int max9850_probe(struct snd_soc_component *component)
275{
276 /* enable zero-detect */
277 snd_soc_component_update_bits(component, MAX9850_GENERAL_PURPOSE, 1, 1);
278 /* enable slew-rate control */
279 snd_soc_component_update_bits(component, MAX9850_VOLUME, 0x40, 0x40);
280 /* set slew-rate 125ms */
281 snd_soc_component_update_bits(component, MAX9850_CHARGE_PUMP, 0xff, 0xc0);
282
283 return 0;
284}
285
286static const struct snd_soc_component_driver soc_component_dev_max9850 = {
287 .probe = max9850_probe,
288 .set_bias_level = max9850_set_bias_level,
289 .controls = max9850_controls,
290 .num_controls = ARRAY_SIZE(max9850_controls),
291 .dapm_widgets = max9850_dapm_widgets,
292 .num_dapm_widgets = ARRAY_SIZE(max9850_dapm_widgets),
293 .dapm_routes = max9850_dapm_routes,
294 .num_dapm_routes = ARRAY_SIZE(max9850_dapm_routes),
295 .suspend_bias_off = 1,
296 .idle_bias_on = 1,
297 .use_pmdown_time = 1,
298 .endianness = 1,
299};
300
301static int max9850_i2c_probe(struct i2c_client *i2c)
302{
303 struct max9850_priv *max9850;
304 int ret;
305
306 max9850 = devm_kzalloc(&i2c->dev, sizeof(struct max9850_priv),
307 GFP_KERNEL);
308 if (max9850 == NULL)
309 return -ENOMEM;
310
311 max9850->regmap = devm_regmap_init_i2c(i2c, &max9850_regmap);
312 if (IS_ERR(max9850->regmap))
313 return PTR_ERR(max9850->regmap);
314
315 i2c_set_clientdata(i2c, max9850);
316
317 ret = devm_snd_soc_register_component(&i2c->dev,
318 &soc_component_dev_max9850, &max9850_dai, 1);
319 return ret;
320}
321
322static const struct i2c_device_id max9850_i2c_id[] = {
323 { "max9850" },
324 { }
325};
326MODULE_DEVICE_TABLE(i2c, max9850_i2c_id);
327
328static struct i2c_driver max9850_i2c_driver = {
329 .driver = {
330 .name = "max9850",
331 },
332 .probe = max9850_i2c_probe,
333 .id_table = max9850_i2c_id,
334};
335
336module_i2c_driver(max9850_i2c_driver);
337
338MODULE_AUTHOR("Christian Glindkamp <christian.glindkamp@taskit.de>");
339MODULE_DESCRIPTION("ASoC MAX9850 codec driver");
340MODULE_LICENSE("GPL");
1/*
2 * max9850.c -- codec driver for max9850
3 *
4 * Copyright (C) 2011 taskit GmbH
5 *
6 * Author: Christian Glindkamp <christian.glindkamp@taskit.de>
7 *
8 * Initial development of this code was funded by
9 * MICRONIC Computer Systeme GmbH, http://www.mcsberlin.de/
10 *
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
15 *
16 */
17
18#include <linux/module.h>
19#include <linux/init.h>
20#include <linux/i2c.h>
21#include <linux/slab.h>
22#include <sound/pcm.h>
23#include <sound/pcm_params.h>
24#include <sound/soc.h>
25#include <sound/tlv.h>
26
27#include "max9850.h"
28
29struct max9850_priv {
30 unsigned int sysclk;
31};
32
33/* max9850 register cache */
34static const u8 max9850_reg[MAX9850_CACHEREGNUM] = {
35 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
36};
37
38/* these registers are not used at the moment but provided for the sake of
39 * completeness */
40static int max9850_volatile_register(struct snd_soc_codec *codec,
41 unsigned int reg)
42{
43 switch (reg) {
44 case MAX9850_STATUSA:
45 case MAX9850_STATUSB:
46 return 1;
47 default:
48 return 0;
49 }
50}
51
52static const unsigned int max9850_tlv[] = {
53 TLV_DB_RANGE_HEAD(4),
54 0x18, 0x1f, TLV_DB_SCALE_ITEM(-7450, 400, 0),
55 0x20, 0x33, TLV_DB_SCALE_ITEM(-4150, 200, 0),
56 0x34, 0x37, TLV_DB_SCALE_ITEM(-150, 100, 0),
57 0x38, 0x3f, TLV_DB_SCALE_ITEM(250, 50, 0),
58};
59
60static const struct snd_kcontrol_new max9850_controls[] = {
61SOC_SINGLE_TLV("Headphone Volume", MAX9850_VOLUME, 0, 0x3f, 1, max9850_tlv),
62SOC_SINGLE("Headphone Switch", MAX9850_VOLUME, 7, 1, 1),
63SOC_SINGLE("Mono Switch", MAX9850_GENERAL_PURPOSE, 2, 1, 0),
64};
65
66static const struct snd_kcontrol_new max9850_mixer_controls[] = {
67 SOC_DAPM_SINGLE("Line In Switch", MAX9850_ENABLE, 1, 1, 0),
68};
69
70static const struct snd_soc_dapm_widget max9850_dapm_widgets[] = {
71SND_SOC_DAPM_SUPPLY("Charge Pump 1", MAX9850_ENABLE, 4, 0, NULL, 0),
72SND_SOC_DAPM_SUPPLY("Charge Pump 2", MAX9850_ENABLE, 5, 0, NULL, 0),
73SND_SOC_DAPM_SUPPLY("MCLK", MAX9850_ENABLE, 6, 0, NULL, 0),
74SND_SOC_DAPM_SUPPLY("SHDN", MAX9850_ENABLE, 7, 0, NULL, 0),
75SND_SOC_DAPM_MIXER_NAMED_CTL("Output Mixer", MAX9850_ENABLE, 2, 0,
76 &max9850_mixer_controls[0],
77 ARRAY_SIZE(max9850_mixer_controls)),
78SND_SOC_DAPM_PGA("Headphone Output", MAX9850_ENABLE, 3, 0, NULL, 0),
79SND_SOC_DAPM_DAC("DAC", "HiFi Playback", MAX9850_ENABLE, 0, 0),
80SND_SOC_DAPM_OUTPUT("OUTL"),
81SND_SOC_DAPM_OUTPUT("HPL"),
82SND_SOC_DAPM_OUTPUT("OUTR"),
83SND_SOC_DAPM_OUTPUT("HPR"),
84SND_SOC_DAPM_MIXER("Line Input", SND_SOC_NOPM, 0, 0, NULL, 0),
85SND_SOC_DAPM_INPUT("INL"),
86SND_SOC_DAPM_INPUT("INR"),
87};
88
89static const struct snd_soc_dapm_route max9850_dapm_routes[] = {
90 /* output mixer */
91 {"Output Mixer", NULL, "DAC"},
92 {"Output Mixer", "Line In Switch", "Line Input"},
93
94 /* outputs */
95 {"Headphone Output", NULL, "Output Mixer"},
96 {"HPL", NULL, "Headphone Output"},
97 {"HPR", NULL, "Headphone Output"},
98 {"OUTL", NULL, "Output Mixer"},
99 {"OUTR", NULL, "Output Mixer"},
100
101 /* inputs */
102 {"Line Input", NULL, "INL"},
103 {"Line Input", NULL, "INR"},
104
105 /* supplies */
106 {"Output Mixer", NULL, "Charge Pump 1"},
107 {"Output Mixer", NULL, "Charge Pump 2"},
108 {"Output Mixer", NULL, "SHDN"},
109 {"DAC", NULL, "MCLK"},
110};
111
112static int max9850_hw_params(struct snd_pcm_substream *substream,
113 struct snd_pcm_hw_params *params,
114 struct snd_soc_dai *dai)
115{
116 struct snd_soc_codec *codec = dai->codec;
117 struct max9850_priv *max9850 = snd_soc_codec_get_drvdata(codec);
118 u64 lrclk_div;
119 u8 sf, da;
120
121 if (!max9850->sysclk)
122 return -EINVAL;
123
124 /* lrclk_div = 2^22 * rate / iclk with iclk = mclk / sf */
125 sf = (snd_soc_read(codec, MAX9850_CLOCK) >> 2) + 1;
126 lrclk_div = (1 << 22);
127 lrclk_div *= params_rate(params);
128 lrclk_div *= sf;
129 do_div(lrclk_div, max9850->sysclk);
130
131 snd_soc_write(codec, MAX9850_LRCLK_MSB, (lrclk_div >> 8) & 0x7f);
132 snd_soc_write(codec, MAX9850_LRCLK_LSB, lrclk_div & 0xff);
133
134 switch (params_format(params)) {
135 case SNDRV_PCM_FORMAT_S16_LE:
136 da = 0;
137 break;
138 case SNDRV_PCM_FORMAT_S20_3LE:
139 da = 0x2;
140 break;
141 case SNDRV_PCM_FORMAT_S24_LE:
142 da = 0x3;
143 break;
144 default:
145 return -EINVAL;
146 }
147 snd_soc_update_bits(codec, MAX9850_DIGITAL_AUDIO, 0x3, da);
148
149 return 0;
150}
151
152static int max9850_set_dai_sysclk(struct snd_soc_dai *codec_dai,
153 int clk_id, unsigned int freq, int dir)
154{
155 struct snd_soc_codec *codec = codec_dai->codec;
156 struct max9850_priv *max9850 = snd_soc_codec_get_drvdata(codec);
157
158 /* calculate mclk -> iclk divider */
159 if (freq <= 13000000)
160 snd_soc_write(codec, MAX9850_CLOCK, 0x0);
161 else if (freq <= 26000000)
162 snd_soc_write(codec, MAX9850_CLOCK, 0x4);
163 else if (freq <= 40000000)
164 snd_soc_write(codec, MAX9850_CLOCK, 0x8);
165 else
166 return -EINVAL;
167
168 max9850->sysclk = freq;
169 return 0;
170}
171
172static int max9850_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
173{
174 struct snd_soc_codec *codec = codec_dai->codec;
175 u8 da = 0;
176
177 /* set master/slave audio interface */
178 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
179 case SND_SOC_DAIFMT_CBM_CFM:
180 da |= MAX9850_MASTER;
181 break;
182 case SND_SOC_DAIFMT_CBS_CFS:
183 break;
184 default:
185 return -EINVAL;
186 }
187
188 /* interface format */
189 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
190 case SND_SOC_DAIFMT_I2S:
191 da |= MAX9850_DLY;
192 break;
193 case SND_SOC_DAIFMT_RIGHT_J:
194 da |= MAX9850_RTJ;
195 break;
196 case SND_SOC_DAIFMT_LEFT_J:
197 break;
198 default:
199 return -EINVAL;
200 }
201
202 /* clock inversion */
203 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
204 case SND_SOC_DAIFMT_NB_NF:
205 break;
206 case SND_SOC_DAIFMT_IB_IF:
207 da |= MAX9850_BCINV | MAX9850_INV;
208 break;
209 case SND_SOC_DAIFMT_IB_NF:
210 da |= MAX9850_BCINV;
211 break;
212 case SND_SOC_DAIFMT_NB_IF:
213 da |= MAX9850_INV;
214 break;
215 default:
216 return -EINVAL;
217 }
218
219 /* set da */
220 snd_soc_write(codec, MAX9850_DIGITAL_AUDIO, da);
221
222 return 0;
223}
224
225static int max9850_set_bias_level(struct snd_soc_codec *codec,
226 enum snd_soc_bias_level level)
227{
228 int ret;
229
230 switch (level) {
231 case SND_SOC_BIAS_ON:
232 break;
233 case SND_SOC_BIAS_PREPARE:
234 break;
235 case SND_SOC_BIAS_STANDBY:
236 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
237 ret = snd_soc_cache_sync(codec);
238 if (ret) {
239 dev_err(codec->dev,
240 "Failed to sync cache: %d\n", ret);
241 return ret;
242 }
243 }
244 break;
245 case SND_SOC_BIAS_OFF:
246 break;
247 }
248 codec->dapm.bias_level = level;
249 return 0;
250}
251
252#define MAX9850_RATES SNDRV_PCM_RATE_8000_48000
253
254#define MAX9850_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
255 SNDRV_PCM_FMTBIT_S24_LE)
256
257static const struct snd_soc_dai_ops max9850_dai_ops = {
258 .hw_params = max9850_hw_params,
259 .set_sysclk = max9850_set_dai_sysclk,
260 .set_fmt = max9850_set_dai_fmt,
261};
262
263static struct snd_soc_dai_driver max9850_dai = {
264 .name = "max9850-hifi",
265 .playback = {
266 .stream_name = "Playback",
267 .channels_min = 1,
268 .channels_max = 2,
269 .rates = MAX9850_RATES,
270 .formats = MAX9850_FORMATS
271 },
272 .ops = &max9850_dai_ops,
273};
274
275#ifdef CONFIG_PM
276static int max9850_suspend(struct snd_soc_codec *codec)
277{
278 max9850_set_bias_level(codec, SND_SOC_BIAS_OFF);
279
280 return 0;
281}
282
283static int max9850_resume(struct snd_soc_codec *codec)
284{
285 max9850_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
286
287 return 0;
288}
289#else
290#define max9850_suspend NULL
291#define max9850_resume NULL
292#endif
293
294static int max9850_probe(struct snd_soc_codec *codec)
295{
296 int ret;
297
298 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_I2C);
299 if (ret < 0) {
300 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
301 return ret;
302 }
303
304 /* enable zero-detect */
305 snd_soc_update_bits(codec, MAX9850_GENERAL_PURPOSE, 1, 1);
306 /* enable slew-rate control */
307 snd_soc_update_bits(codec, MAX9850_VOLUME, 0x40, 0x40);
308 /* set slew-rate 125ms */
309 snd_soc_update_bits(codec, MAX9850_CHARGE_PUMP, 0xff, 0xc0);
310
311 return 0;
312}
313
314static struct snd_soc_codec_driver soc_codec_dev_max9850 = {
315 .probe = max9850_probe,
316 .suspend = max9850_suspend,
317 .resume = max9850_resume,
318 .set_bias_level = max9850_set_bias_level,
319 .reg_cache_size = ARRAY_SIZE(max9850_reg),
320 .reg_word_size = sizeof(u8),
321 .reg_cache_default = max9850_reg,
322 .volatile_register = max9850_volatile_register,
323
324 .controls = max9850_controls,
325 .num_controls = ARRAY_SIZE(max9850_controls),
326 .dapm_widgets = max9850_dapm_widgets,
327 .num_dapm_widgets = ARRAY_SIZE(max9850_dapm_widgets),
328 .dapm_routes = max9850_dapm_routes,
329 .num_dapm_routes = ARRAY_SIZE(max9850_dapm_routes),
330};
331
332static int __devinit max9850_i2c_probe(struct i2c_client *i2c,
333 const struct i2c_device_id *id)
334{
335 struct max9850_priv *max9850;
336 int ret;
337
338 max9850 = devm_kzalloc(&i2c->dev, sizeof(struct max9850_priv),
339 GFP_KERNEL);
340 if (max9850 == NULL)
341 return -ENOMEM;
342
343 i2c_set_clientdata(i2c, max9850);
344
345 ret = snd_soc_register_codec(&i2c->dev,
346 &soc_codec_dev_max9850, &max9850_dai, 1);
347 return ret;
348}
349
350static __devexit int max9850_i2c_remove(struct i2c_client *client)
351{
352 snd_soc_unregister_codec(&client->dev);
353 return 0;
354}
355
356static const struct i2c_device_id max9850_i2c_id[] = {
357 { "max9850", 0 },
358 { }
359};
360MODULE_DEVICE_TABLE(i2c, max9850_i2c_id);
361
362static struct i2c_driver max9850_i2c_driver = {
363 .driver = {
364 .name = "max9850",
365 .owner = THIS_MODULE,
366 },
367 .probe = max9850_i2c_probe,
368 .remove = __devexit_p(max9850_i2c_remove),
369 .id_table = max9850_i2c_id,
370};
371
372static int __init max9850_init(void)
373{
374 return i2c_add_driver(&max9850_i2c_driver);
375}
376module_init(max9850_init);
377
378static void __exit max9850_exit(void)
379{
380 i2c_del_driver(&max9850_i2c_driver);
381}
382module_exit(max9850_exit);
383
384MODULE_AUTHOR("Christian Glindkamp <christian.glindkamp@taskit.de>");
385MODULE_DESCRIPTION("ASoC MAX9850 codec driver");
386MODULE_LICENSE("GPL");