da7210.c (cf0dbba515415bb19b11f9323d5f7bebd7f24fd6) da7210.c (b2c812e22de88bb79c290c0e718280f10b64a48d)
1/*
2 * DA7210 ALSA Soc codec driver
3 *
4 * Copyright (c) 2009 Dialog Semiconductor
5 * Written by David Chen <Dajun.chen@diasemi.com>
6 *
7 * Copyright (C) 2009 Renesas Solutions Corp.
8 * Cleanups by Kuninori Morimoto <morimoto.kuninori@renesas.com>

--- 9 unchanged lines hidden (view full) ---

18#include <linux/module.h>
19#include <linux/moduleparam.h>
20#include <linux/kernel.h>
21#include <linux/init.h>
22#include <linux/delay.h>
23#include <linux/pm.h>
24#include <linux/i2c.h>
25#include <linux/platform_device.h>
1/*
2 * DA7210 ALSA Soc codec driver
3 *
4 * Copyright (c) 2009 Dialog Semiconductor
5 * Written by David Chen <Dajun.chen@diasemi.com>
6 *
7 * Copyright (C) 2009 Renesas Solutions Corp.
8 * Cleanups by Kuninori Morimoto <morimoto.kuninori@renesas.com>

--- 9 unchanged lines hidden (view full) ---

18#include <linux/module.h>
19#include <linux/moduleparam.h>
20#include <linux/kernel.h>
21#include <linux/init.h>
22#include <linux/delay.h>
23#include <linux/pm.h>
24#include <linux/i2c.h>
25#include <linux/platform_device.h>
26#include <linux/slab.h>
27#include <sound/core.h>
28#include <sound/pcm.h>
29#include <sound/pcm_params.h>
30#include <sound/soc.h>
31#include <sound/soc-dapm.h>
32#include <sound/tlv.h>
33#include <sound/initval.h>
34#include <asm/div64.h>

--- 16 unchanged lines hidden (view full) ---

51#define DA7210_OUTMIX_L 0x1C
52#define DA7210_OUTMIX_R 0x1D
53#define DA7210_HP_L_VOL 0x21
54#define DA7210_HP_R_VOL 0x22
55#define DA7210_HP_CFG 0x23
56#define DA7210_DAI_SRC_SEL 0x25
57#define DA7210_DAI_CFG1 0x26
58#define DA7210_DAI_CFG3 0x28
26#include <sound/core.h>
27#include <sound/pcm.h>
28#include <sound/pcm_params.h>
29#include <sound/soc.h>
30#include <sound/soc-dapm.h>
31#include <sound/tlv.h>
32#include <sound/initval.h>
33#include <asm/div64.h>

--- 16 unchanged lines hidden (view full) ---

50#define DA7210_OUTMIX_L 0x1C
51#define DA7210_OUTMIX_R 0x1D
52#define DA7210_HP_L_VOL 0x21
53#define DA7210_HP_R_VOL 0x22
54#define DA7210_HP_CFG 0x23
55#define DA7210_DAI_SRC_SEL 0x25
56#define DA7210_DAI_CFG1 0x26
57#define DA7210_DAI_CFG3 0x28
58#define DA7210_PLL_DIV1 0x29
59#define DA7210_PLL_DIV2 0x2A
59#define DA7210_PLL_DIV3 0x2B
60#define DA7210_PLL 0x2C
60#define DA7210_PLL_DIV3 0x2B
61#define DA7210_PLL 0x2C
62#define DA7210_A_HID_UNLOCK 0x8A
63#define DA7210_A_TEST_UNLOCK 0x8B
64#define DA7210_A_PLL1 0x90
65#define DA7210_A_CP_MODE 0xA7
61
62/* STARTUP1 bit fields */
63#define DA7210_SC_MST_EN (1 << 0)
64
65/* MIC_L bit fields */
66#define DA7210_MICBIAS_EN (1 << 6)
67#define DA7210_MIC_L_EN (1 << 7)
68
69/* MIC_R bit fields */
70#define DA7210_MIC_R_EN (1 << 7)
71
72/* INMIX_L bit fields */
73#define DA7210_IN_L_EN (1 << 7)
74
75/* INMIX_R bit fields */
76#define DA7210_IN_R_EN (1 << 7)
77
66
67/* STARTUP1 bit fields */
68#define DA7210_SC_MST_EN (1 << 0)
69
70/* MIC_L bit fields */
71#define DA7210_MICBIAS_EN (1 << 6)
72#define DA7210_MIC_L_EN (1 << 7)
73
74/* MIC_R bit fields */
75#define DA7210_MIC_R_EN (1 << 7)
76
77/* INMIX_L bit fields */
78#define DA7210_IN_L_EN (1 << 7)
79
80/* INMIX_R bit fields */
81#define DA7210_IN_R_EN (1 << 7)
82
78/* ADC_HPF bit fields */
79#define DA7210_ADC_VOICE_EN (1 << 7)
80
81/* ADC bit fields */
82#define DA7210_ADC_L_EN (1 << 3)
83#define DA7210_ADC_R_EN (1 << 7)
84
83/* ADC bit fields */
84#define DA7210_ADC_L_EN (1 << 3)
85#define DA7210_ADC_R_EN (1 << 7)
86
85/* DAC_HPF fields */
86#define DA7210_DAC_VOICE_EN (1 << 7)
87/* DAC/ADC HPF fields */
88#define DA7210_VOICE_F0_MASK (0x7 << 4)
89#define DA7210_VOICE_F0_25 (1 << 4)
90#define DA7210_VOICE_EN (1 << 7)
87
88/* DAC_SEL bit fields */
89#define DA7210_DAC_L_SRC_DAI_L (4 << 0)
90#define DA7210_DAC_L_EN (1 << 3)
91#define DA7210_DAC_R_SRC_DAI_R (5 << 4)
92#define DA7210_DAC_R_EN (1 << 7)
93
94/* OUTMIX_L bit fields */

--- 24 unchanged lines hidden (view full) ---

119#define DA7210_DAI_OE (1 << 3)
120#define DA7210_DAI_EN (1 << 7)
121
122/*PLL_DIV3 bit fields */
123#define DA7210_MCLK_RANGE_10_20_MHZ (1 << 4)
124#define DA7210_PLL_BYP (1 << 6)
125
126/* PLL bit fields */
91
92/* DAC_SEL bit fields */
93#define DA7210_DAC_L_SRC_DAI_L (4 << 0)
94#define DA7210_DAC_L_EN (1 << 3)
95#define DA7210_DAC_R_SRC_DAI_R (5 << 4)
96#define DA7210_DAC_R_EN (1 << 7)
97
98/* OUTMIX_L bit fields */

--- 24 unchanged lines hidden (view full) ---

123#define DA7210_DAI_OE (1 << 3)
124#define DA7210_DAI_EN (1 << 7)
125
126/*PLL_DIV3 bit fields */
127#define DA7210_MCLK_RANGE_10_20_MHZ (1 << 4)
128#define DA7210_PLL_BYP (1 << 6)
129
130/* PLL bit fields */
127#define DA7210_PLL_FS_48000 (11 << 0)
131#define DA7210_PLL_FS_MASK (0xF << 0)
132#define DA7210_PLL_FS_8000 (0x1 << 0)
133#define DA7210_PLL_FS_11025 (0x2 << 0)
134#define DA7210_PLL_FS_12000 (0x3 << 0)
135#define DA7210_PLL_FS_16000 (0x5 << 0)
136#define DA7210_PLL_FS_22050 (0x6 << 0)
137#define DA7210_PLL_FS_24000 (0x7 << 0)
138#define DA7210_PLL_FS_32000 (0x9 << 0)
139#define DA7210_PLL_FS_44100 (0xA << 0)
140#define DA7210_PLL_FS_48000 (0xB << 0)
141#define DA7210_PLL_FS_88200 (0xE << 0)
142#define DA7210_PLL_FS_96000 (0xF << 0)
143#define DA7210_PLL_EN (0x1 << 7)
128
129#define DA7210_VERSION "0.0.1"
130
131/* Codec private data */
132struct da7210_priv {
133 struct snd_soc_codec codec;
134};
135

--- 101 unchanged lines hidden (view full) ---

237static int da7210_hw_params(struct snd_pcm_substream *substream,
238 struct snd_pcm_hw_params *params,
239 struct snd_soc_dai *dai)
240{
241 struct snd_soc_pcm_runtime *rtd = substream->private_data;
242 struct snd_soc_device *socdev = rtd->socdev;
243 struct snd_soc_codec *codec = socdev->card->codec;
244 u32 dai_cfg1;
144
145#define DA7210_VERSION "0.0.1"
146
147/* Codec private data */
148struct da7210_priv {
149 struct snd_soc_codec codec;
150};
151

--- 101 unchanged lines hidden (view full) ---

253static int da7210_hw_params(struct snd_pcm_substream *substream,
254 struct snd_pcm_hw_params *params,
255 struct snd_soc_dai *dai)
256{
257 struct snd_soc_pcm_runtime *rtd = substream->private_data;
258 struct snd_soc_device *socdev = rtd->socdev;
259 struct snd_soc_codec *codec = socdev->card->codec;
260 u32 dai_cfg1;
245 u32 reg, mask;
261 u32 hpf_reg, hpf_mask, hpf_value;
262 u32 fs, bypass;
246
247 /* set DAI source to Left and Right ADC */
248 da7210_write(codec, DA7210_DAI_SRC_SEL,
249 DA7210_DAI_OUT_R_SRC | DA7210_DAI_OUT_L_SRC);
250
251 /* Enable DAI */
252 da7210_write(codec, DA7210_DAI_CFG3, DA7210_DAI_OE | DA7210_DAI_EN);
253

--- 7 unchanged lines hidden (view full) ---

261 dai_cfg1 |= DA7210_DAI_WORD_S24_LE;
262 break;
263 default:
264 return -EINVAL;
265 }
266
267 da7210_write(codec, DA7210_DAI_CFG1, dai_cfg1);
268
263
264 /* set DAI source to Left and Right ADC */
265 da7210_write(codec, DA7210_DAI_SRC_SEL,
266 DA7210_DAI_OUT_R_SRC | DA7210_DAI_OUT_L_SRC);
267
268 /* Enable DAI */
269 da7210_write(codec, DA7210_DAI_CFG3, DA7210_DAI_OE | DA7210_DAI_EN);
270

--- 7 unchanged lines hidden (view full) ---

278 dai_cfg1 |= DA7210_DAI_WORD_S24_LE;
279 break;
280 default:
281 return -EINVAL;
282 }
283
284 da7210_write(codec, DA7210_DAI_CFG1, dai_cfg1);
285
269 /* FIXME
270 *
271 * It support 48K only now
272 */
286 hpf_reg = (SNDRV_PCM_STREAM_PLAYBACK == substream->stream) ?
287 DA7210_DAC_HPF : DA7210_ADC_HPF;
288
273 switch (params_rate(params)) {
289 switch (params_rate(params)) {
290 case 8000:
291 fs = DA7210_PLL_FS_8000;
292 hpf_mask = DA7210_VOICE_F0_MASK | DA7210_VOICE_EN;
293 hpf_value = DA7210_VOICE_F0_25 | DA7210_VOICE_EN;
294 bypass = DA7210_PLL_BYP;
295 break;
296 case 11025:
297 fs = DA7210_PLL_FS_11025;
298 hpf_mask = DA7210_VOICE_F0_MASK | DA7210_VOICE_EN;
299 hpf_value = DA7210_VOICE_F0_25 | DA7210_VOICE_EN;
300 bypass = 0;
301 break;
302 case 12000:
303 fs = DA7210_PLL_FS_12000;
304 hpf_mask = DA7210_VOICE_F0_MASK | DA7210_VOICE_EN;
305 hpf_value = DA7210_VOICE_F0_25 | DA7210_VOICE_EN;
306 bypass = DA7210_PLL_BYP;
307 break;
308 case 16000:
309 fs = DA7210_PLL_FS_16000;
310 hpf_mask = DA7210_VOICE_F0_MASK | DA7210_VOICE_EN;
311 hpf_value = DA7210_VOICE_F0_25 | DA7210_VOICE_EN;
312 bypass = DA7210_PLL_BYP;
313 break;
314 case 22050:
315 fs = DA7210_PLL_FS_22050;
316 hpf_mask = DA7210_VOICE_EN;
317 hpf_value = 0;
318 bypass = 0;
319 break;
320 case 32000:
321 fs = DA7210_PLL_FS_32000;
322 hpf_mask = DA7210_VOICE_EN;
323 hpf_value = 0;
324 bypass = DA7210_PLL_BYP;
325 break;
326 case 44100:
327 fs = DA7210_PLL_FS_44100;
328 hpf_mask = DA7210_VOICE_EN;
329 hpf_value = 0;
330 bypass = 0;
331 break;
274 case 48000:
332 case 48000:
275 if (SNDRV_PCM_STREAM_PLAYBACK == substream->stream) {
276 reg = DA7210_DAC_HPF;
277 mask = DA7210_DAC_VOICE_EN;
278 } else {
279 reg = DA7210_ADC_HPF;
280 mask = DA7210_ADC_VOICE_EN;
281 }
333 fs = DA7210_PLL_FS_48000;
334 hpf_mask = DA7210_VOICE_EN;
335 hpf_value = 0;
336 bypass = DA7210_PLL_BYP;
282 break;
337 break;
338 case 88200:
339 fs = DA7210_PLL_FS_88200;
340 hpf_mask = DA7210_VOICE_EN;
341 hpf_value = 0;
342 bypass = 0;
343 break;
344 case 96000:
345 fs = DA7210_PLL_FS_96000;
346 hpf_mask = DA7210_VOICE_EN;
347 hpf_value = 0;
348 bypass = DA7210_PLL_BYP;
349 break;
283 default:
284 return -EINVAL;
285 }
286
350 default:
351 return -EINVAL;
352 }
353
287 snd_soc_update_bits(codec, reg, mask, 0);
354 /* Disable active mode */
355 snd_soc_update_bits(codec, DA7210_STARTUP1, DA7210_SC_MST_EN, 0);
288
356
357 snd_soc_update_bits(codec, hpf_reg, hpf_mask, hpf_value);
358 snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_FS_MASK, fs);
359 snd_soc_update_bits(codec, DA7210_PLL_DIV3, DA7210_PLL_BYP, bypass);
360
361 /* Enable active mode */
362 snd_soc_update_bits(codec, DA7210_STARTUP1,
363 DA7210_SC_MST_EN, DA7210_SC_MST_EN);
364
289 return 0;
290}
291
292/*
293 * Set DAI mode and Format
294 */
295static int da7210_set_dai_fmt(struct snd_soc_dai *codec_dai, u32 fmt)
296{

--- 60 unchanged lines hidden (view full) ---

357 .capture = {
358 .stream_name = "Capture",
359 .channels_min = 1,
360 .channels_max = 2,
361 .rates = SNDRV_PCM_RATE_8000_96000,
362 .formats = DA7210_FORMATS,
363 },
364 .ops = &da7210_dai_ops,
365 return 0;
366}
367
368/*
369 * Set DAI mode and Format
370 */
371static int da7210_set_dai_fmt(struct snd_soc_dai *codec_dai, u32 fmt)
372{

--- 60 unchanged lines hidden (view full) ---

433 .capture = {
434 .stream_name = "Capture",
435 .channels_min = 1,
436 .channels_max = 2,
437 .rates = SNDRV_PCM_RATE_8000_96000,
438 .formats = DA7210_FORMATS,
439 },
440 .ops = &da7210_dai_ops,
441 .symmetric_rates = 1,
365};
366EXPORT_SYMBOL_GPL(da7210_dai);
367
368/*
369 * Initialize the DA7210 driver
370 * register the mixer and dsp interfaces with the kernel
371 */
372static int da7210_init(struct da7210_priv *da7210)

--- 5 unchanged lines hidden (view full) ---

378 dev_err(codec->dev, "Another da7210 is registered\n");
379 return -EINVAL;
380 }
381
382 mutex_init(&codec->mutex);
383 INIT_LIST_HEAD(&codec->dapm_widgets);
384 INIT_LIST_HEAD(&codec->dapm_paths);
385
442};
443EXPORT_SYMBOL_GPL(da7210_dai);
444
445/*
446 * Initialize the DA7210 driver
447 * register the mixer and dsp interfaces with the kernel
448 */
449static int da7210_init(struct da7210_priv *da7210)

--- 5 unchanged lines hidden (view full) ---

455 dev_err(codec->dev, "Another da7210 is registered\n");
456 return -EINVAL;
457 }
458
459 mutex_init(&codec->mutex);
460 INIT_LIST_HEAD(&codec->dapm_widgets);
461 INIT_LIST_HEAD(&codec->dapm_paths);
462
386 codec->private_data = da7210;
463 snd_soc_codec_set_drvdata(codec, da7210);
387 codec->name = "DA7210";
388 codec->owner = THIS_MODULE;
389 codec->read = da7210_read;
390 codec->write = da7210_write;
391 codec->dai = &da7210_dai;
392 codec->num_dai = 1;
393 codec->hw_write = (hw_write_t)i2c_master_send;
394 codec->reg_cache_size = ARRAY_SIZE(da7210_reg);

--- 16 unchanged lines hidden (view full) ---

411 if (ret) {
412 dev_err(codec->dev, "Failed to register DAI: %d\n", ret);
413 goto init_err;
414 }
415
416 /* FIXME
417 *
418 * This driver use fixed value here
464 codec->name = "DA7210";
465 codec->owner = THIS_MODULE;
466 codec->read = da7210_read;
467 codec->write = da7210_write;
468 codec->dai = &da7210_dai;
469 codec->num_dai = 1;
470 codec->hw_write = (hw_write_t)i2c_master_send;
471 codec->reg_cache_size = ARRAY_SIZE(da7210_reg);

--- 16 unchanged lines hidden (view full) ---

488 if (ret) {
489 dev_err(codec->dev, "Failed to register DAI: %d\n", ret);
490 goto init_err;
491 }
492
493 /* FIXME
494 *
495 * This driver use fixed value here
496 * And below settings expects MCLK = 12.288MHz
497 *
498 * When you select different MCLK, please check...
499 * DA7210_PLL_DIV1 val
500 * DA7210_PLL_DIV2 val
501 * DA7210_PLL_DIV3 val
502 * DA7210_PLL_DIV3 :: DA7210_MCLK_RANGExxx
419 */
420
421 /*
503 */
504
505 /*
506 * make sure that DA7210 use bypass mode before start up
507 */
508 da7210_write(codec, DA7210_STARTUP1, 0);
509 da7210_write(codec, DA7210_PLL_DIV3,
510 DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP);
511
512 /*
422 * ADC settings
423 */
424
425 /* Enable Left & Right MIC PGA and Mic Bias */
426 da7210_write(codec, DA7210_MIC_L, DA7210_MIC_L_EN | DA7210_MICBIAS_EN);
427 da7210_write(codec, DA7210_MIC_R, DA7210_MIC_R_EN);
428
429 /* Enable Left and Right input PGA */

--- 19 unchanged lines hidden (view full) ---

449 /* Enable Left and Right HeadPhone PGA */
450 da7210_write(codec, DA7210_HP_CFG,
451 DA7210_HP_2CAP_MODE | DA7210_HP_SENSE_EN |
452 DA7210_HP_L_EN | DA7210_HP_MODE | DA7210_HP_R_EN);
453
454 /* Diable PLL and bypass it */
455 da7210_write(codec, DA7210_PLL, DA7210_PLL_FS_48000);
456
513 * ADC settings
514 */
515
516 /* Enable Left & Right MIC PGA and Mic Bias */
517 da7210_write(codec, DA7210_MIC_L, DA7210_MIC_L_EN | DA7210_MICBIAS_EN);
518 da7210_write(codec, DA7210_MIC_R, DA7210_MIC_R_EN);
519
520 /* Enable Left and Right input PGA */

--- 19 unchanged lines hidden (view full) ---

540 /* Enable Left and Right HeadPhone PGA */
541 da7210_write(codec, DA7210_HP_CFG,
542 DA7210_HP_2CAP_MODE | DA7210_HP_SENSE_EN |
543 DA7210_HP_L_EN | DA7210_HP_MODE | DA7210_HP_R_EN);
544
545 /* Diable PLL and bypass it */
546 da7210_write(codec, DA7210_PLL, DA7210_PLL_FS_48000);
547
457 /* Bypass PLL and set MCLK freq rang to 10-20MHz */
458 da7210_write(codec, DA7210_PLL_DIV3,
548 /*
549 * If 48kHz sound came, it use bypass mode,
550 * and when it is 44.1kHz, it use PLL.
551 *
552 * This time, this driver sets PLL always ON
553 * and controls bypass/PLL mode by switching
554 * DA7210_PLL_DIV3 :: DA7210_PLL_BYP bit.
555 * see da7210_hw_params
556 */
557 da7210_write(codec, DA7210_PLL_DIV1, 0xE5); /* MCLK = 12.288MHz */
558 da7210_write(codec, DA7210_PLL_DIV2, 0x99);
559 da7210_write(codec, DA7210_PLL_DIV3, 0x0A |
459 DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP);
560 DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP);
561 snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_EN, DA7210_PLL_EN);
460
562
563 /* As suggested by Dialog */
564 da7210_write(codec, DA7210_A_HID_UNLOCK, 0x8B); /* unlock */
565 da7210_write(codec, DA7210_A_TEST_UNLOCK, 0xB4);
566 da7210_write(codec, DA7210_A_PLL1, 0x01);
567 da7210_write(codec, DA7210_A_CP_MODE, 0x7C);
568 da7210_write(codec, DA7210_A_HID_UNLOCK, 0x00); /* re-lock */
569 da7210_write(codec, DA7210_A_TEST_UNLOCK, 0x00);
570
461 /* Activate all enabled subsystem */
462 da7210_write(codec, DA7210_STARTUP1, DA7210_SC_MST_EN);
463
464 return ret;
465
466init_err:
467 kfree(codec->reg_cache);
468 codec->reg_cache = NULL;

--- 122 unchanged lines hidden ---
571 /* Activate all enabled subsystem */
572 da7210_write(codec, DA7210_STARTUP1, DA7210_SC_MST_EN);
573
574 return ret;
575
576init_err:
577 kfree(codec->reg_cache);
578 codec->reg_cache = NULL;

--- 122 unchanged lines hidden ---