xref: /openbmc/linux/sound/soc/codecs/da7210.c (revision 960b3b4b)
198615454SKuninori Morimoto /*
298615454SKuninori Morimoto  * DA7210 ALSA Soc codec driver
398615454SKuninori Morimoto  *
498615454SKuninori Morimoto  * Copyright (c) 2009 Dialog Semiconductor
598615454SKuninori Morimoto  * Written by David Chen <Dajun.chen@diasemi.com>
698615454SKuninori Morimoto  *
798615454SKuninori Morimoto  * Copyright (C) 2009 Renesas Solutions Corp.
898615454SKuninori Morimoto  * Cleanups by Kuninori Morimoto <morimoto.kuninori@renesas.com>
998615454SKuninori Morimoto  *
1098615454SKuninori Morimoto  * Tested on SuperH Ecovec24 board with S16/S24 LE in 48KHz using I2S
1198615454SKuninori Morimoto  *
1298615454SKuninori Morimoto  * This program is free software; you can redistribute  it and/or modify it
1398615454SKuninori Morimoto  * under  the terms of  the GNU General  Public License as published by the
1498615454SKuninori Morimoto  * Free Software Foundation;  either version 2 of the  License, or (at your
1598615454SKuninori Morimoto  * option) any later version.
1698615454SKuninori Morimoto  */
1798615454SKuninori Morimoto 
1898615454SKuninori Morimoto #include <linux/module.h>
1998615454SKuninori Morimoto #include <linux/moduleparam.h>
2098615454SKuninori Morimoto #include <linux/kernel.h>
2198615454SKuninori Morimoto #include <linux/init.h>
2298615454SKuninori Morimoto #include <linux/delay.h>
2398615454SKuninori Morimoto #include <linux/pm.h>
2498615454SKuninori Morimoto #include <linux/i2c.h>
2598615454SKuninori Morimoto #include <linux/platform_device.h>
2698615454SKuninori Morimoto #include <sound/core.h>
2798615454SKuninori Morimoto #include <sound/pcm.h>
2898615454SKuninori Morimoto #include <sound/pcm_params.h>
2998615454SKuninori Morimoto #include <sound/soc.h>
3098615454SKuninori Morimoto #include <sound/soc-dapm.h>
3198615454SKuninori Morimoto #include <sound/tlv.h>
3298615454SKuninori Morimoto #include <sound/initval.h>
3398615454SKuninori Morimoto #include <asm/div64.h>
3498615454SKuninori Morimoto 
3598615454SKuninori Morimoto #include "da7210.h"
3698615454SKuninori Morimoto 
3798615454SKuninori Morimoto /* DA7210 register space */
3898615454SKuninori Morimoto #define DA7210_STATUS			0x02
3998615454SKuninori Morimoto #define DA7210_STARTUP1			0x03
4098615454SKuninori Morimoto #define DA7210_MIC_L			0x07
4198615454SKuninori Morimoto #define DA7210_MIC_R			0x08
4298615454SKuninori Morimoto #define DA7210_INMIX_L			0x0D
4398615454SKuninori Morimoto #define DA7210_INMIX_R			0x0E
4498615454SKuninori Morimoto #define DA7210_ADC_HPF			0x0F
4598615454SKuninori Morimoto #define DA7210_ADC			0x10
4698615454SKuninori Morimoto #define DA7210_DAC_HPF			0x14
4798615454SKuninori Morimoto #define DA7210_DAC_L			0x15
4898615454SKuninori Morimoto #define DA7210_DAC_R			0x16
4998615454SKuninori Morimoto #define DA7210_DAC_SEL			0x17
5098615454SKuninori Morimoto #define DA7210_OUTMIX_L			0x1C
5198615454SKuninori Morimoto #define DA7210_OUTMIX_R			0x1D
5298615454SKuninori Morimoto #define DA7210_HP_L_VOL			0x21
5398615454SKuninori Morimoto #define DA7210_HP_R_VOL			0x22
5498615454SKuninori Morimoto #define DA7210_HP_CFG			0x23
5598615454SKuninori Morimoto #define DA7210_DAI_SRC_SEL		0x25
5698615454SKuninori Morimoto #define DA7210_DAI_CFG1			0x26
5798615454SKuninori Morimoto #define DA7210_DAI_CFG3			0x28
58960b3b4bSKuninori Morimoto #define DA7210_PLL_DIV1			0x29
59960b3b4bSKuninori Morimoto #define DA7210_PLL_DIV2			0x2A
6098615454SKuninori Morimoto #define DA7210_PLL_DIV3			0x2B
6198615454SKuninori Morimoto #define DA7210_PLL			0x2C
62960b3b4bSKuninori Morimoto #define DA7210_A_HID_UNLOCK		0x8A
63960b3b4bSKuninori Morimoto #define DA7210_A_TEST_UNLOCK		0x8B
64960b3b4bSKuninori Morimoto #define DA7210_A_PLL1			0x90
65960b3b4bSKuninori Morimoto #define DA7210_A_CP_MODE		0xA7
6698615454SKuninori Morimoto 
6798615454SKuninori Morimoto /* STARTUP1 bit fields */
6898615454SKuninori Morimoto #define DA7210_SC_MST_EN		(1 << 0)
6998615454SKuninori Morimoto 
7098615454SKuninori Morimoto /* MIC_L bit fields */
7198615454SKuninori Morimoto #define DA7210_MICBIAS_EN		(1 << 6)
7298615454SKuninori Morimoto #define DA7210_MIC_L_EN			(1 << 7)
7398615454SKuninori Morimoto 
7498615454SKuninori Morimoto /* MIC_R bit fields */
7598615454SKuninori Morimoto #define DA7210_MIC_R_EN			(1 << 7)
7698615454SKuninori Morimoto 
7798615454SKuninori Morimoto /* INMIX_L bit fields */
7898615454SKuninori Morimoto #define DA7210_IN_L_EN			(1 << 7)
7998615454SKuninori Morimoto 
8098615454SKuninori Morimoto /* INMIX_R bit fields */
8198615454SKuninori Morimoto #define DA7210_IN_R_EN			(1 << 7)
8298615454SKuninori Morimoto 
8398615454SKuninori Morimoto /* ADC bit fields */
8498615454SKuninori Morimoto #define DA7210_ADC_L_EN			(1 << 3)
8598615454SKuninori Morimoto #define DA7210_ADC_R_EN			(1 << 7)
8698615454SKuninori Morimoto 
873a9d6202SKuninori Morimoto /* DAC/ADC HPF fields */
883a9d6202SKuninori Morimoto #define DA7210_VOICE_F0_MASK		(0x7 << 4)
893a9d6202SKuninori Morimoto #define DA7210_VOICE_F0_25		(1 << 4)
903a9d6202SKuninori Morimoto #define DA7210_VOICE_EN			(1 << 7)
91c2151433SMark Brown 
9298615454SKuninori Morimoto /* DAC_SEL bit fields */
9398615454SKuninori Morimoto #define DA7210_DAC_L_SRC_DAI_L		(4 << 0)
9498615454SKuninori Morimoto #define DA7210_DAC_L_EN			(1 << 3)
9598615454SKuninori Morimoto #define DA7210_DAC_R_SRC_DAI_R		(5 << 4)
9698615454SKuninori Morimoto #define DA7210_DAC_R_EN			(1 << 7)
9798615454SKuninori Morimoto 
9898615454SKuninori Morimoto /* OUTMIX_L bit fields */
9998615454SKuninori Morimoto #define DA7210_OUT_L_EN			(1 << 7)
10098615454SKuninori Morimoto 
10198615454SKuninori Morimoto /* OUTMIX_R bit fields */
10298615454SKuninori Morimoto #define DA7210_OUT_R_EN			(1 << 7)
10398615454SKuninori Morimoto 
10498615454SKuninori Morimoto /* HP_CFG bit fields */
10598615454SKuninori Morimoto #define DA7210_HP_2CAP_MODE		(1 << 1)
10698615454SKuninori Morimoto #define DA7210_HP_SENSE_EN		(1 << 2)
10798615454SKuninori Morimoto #define DA7210_HP_L_EN			(1 << 3)
10898615454SKuninori Morimoto #define DA7210_HP_MODE			(1 << 6)
10998615454SKuninori Morimoto #define DA7210_HP_R_EN			(1 << 7)
11098615454SKuninori Morimoto 
11198615454SKuninori Morimoto /* DAI_SRC_SEL bit fields */
11298615454SKuninori Morimoto #define DA7210_DAI_OUT_L_SRC		(6 << 0)
11398615454SKuninori Morimoto #define DA7210_DAI_OUT_R_SRC		(7 << 4)
11498615454SKuninori Morimoto 
11598615454SKuninori Morimoto /* DAI_CFG1 bit fields */
11698615454SKuninori Morimoto #define DA7210_DAI_WORD_S16_LE		(0 << 0)
11798615454SKuninori Morimoto #define DA7210_DAI_WORD_S24_LE		(2 << 0)
11898615454SKuninori Morimoto #define DA7210_DAI_FLEN_64BIT		(1 << 2)
11998615454SKuninori Morimoto #define DA7210_DAI_MODE_MASTER		(1 << 7)
12098615454SKuninori Morimoto 
12198615454SKuninori Morimoto /* DAI_CFG3 bit fields */
12298615454SKuninori Morimoto #define DA7210_DAI_FORMAT_I2SMODE	(0 << 0)
12398615454SKuninori Morimoto #define DA7210_DAI_OE			(1 << 3)
12498615454SKuninori Morimoto #define DA7210_DAI_EN			(1 << 7)
12598615454SKuninori Morimoto 
12698615454SKuninori Morimoto /*PLL_DIV3 bit fields */
12798615454SKuninori Morimoto #define DA7210_MCLK_RANGE_10_20_MHZ	(1 << 4)
12898615454SKuninori Morimoto #define DA7210_PLL_BYP			(1 << 6)
12998615454SKuninori Morimoto 
13098615454SKuninori Morimoto /* PLL bit fields */
1313a9d6202SKuninori Morimoto #define DA7210_PLL_FS_MASK		(0xF << 0)
1323a9d6202SKuninori Morimoto #define DA7210_PLL_FS_8000		(0x1 << 0)
133960b3b4bSKuninori Morimoto #define DA7210_PLL_FS_11025		(0x2 << 0)
1343a9d6202SKuninori Morimoto #define DA7210_PLL_FS_12000		(0x3 << 0)
1353a9d6202SKuninori Morimoto #define DA7210_PLL_FS_16000		(0x5 << 0)
136960b3b4bSKuninori Morimoto #define DA7210_PLL_FS_22050		(0x6 << 0)
1373a9d6202SKuninori Morimoto #define DA7210_PLL_FS_24000		(0x7 << 0)
1383a9d6202SKuninori Morimoto #define DA7210_PLL_FS_32000		(0x9 << 0)
139960b3b4bSKuninori Morimoto #define DA7210_PLL_FS_44100		(0xA << 0)
1403a9d6202SKuninori Morimoto #define DA7210_PLL_FS_48000		(0xB << 0)
141960b3b4bSKuninori Morimoto #define DA7210_PLL_FS_88200		(0xE << 0)
1423a9d6202SKuninori Morimoto #define DA7210_PLL_FS_96000		(0xF << 0)
143960b3b4bSKuninori Morimoto #define DA7210_PLL_EN			(0x1 << 7)
14498615454SKuninori Morimoto 
14598615454SKuninori Morimoto #define DA7210_VERSION "0.0.1"
14698615454SKuninori Morimoto 
14798615454SKuninori Morimoto /* Codec private data */
14898615454SKuninori Morimoto struct da7210_priv {
14998615454SKuninori Morimoto 	struct snd_soc_codec codec;
15098615454SKuninori Morimoto };
15198615454SKuninori Morimoto 
15298615454SKuninori Morimoto static struct snd_soc_codec *da7210_codec;
15398615454SKuninori Morimoto 
15498615454SKuninori Morimoto /*
15598615454SKuninori Morimoto  * Register cache
15698615454SKuninori Morimoto  */
15798615454SKuninori Morimoto static const u8 da7210_reg[] = {
15898615454SKuninori Morimoto 	0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	/* R0  - R7  */
15998615454SKuninori Morimoto 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,	/* R8  - RF  */
16098615454SKuninori Morimoto 	0x00, 0x00, 0x00, 0x00, 0x08, 0x10, 0x10, 0x54,	/* R10 - R17 */
16198615454SKuninori Morimoto 	0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	/* R18 - R1F */
16298615454SKuninori Morimoto 	0x00, 0x00, 0x00, 0x02, 0x00, 0x76, 0x00, 0x00,	/* R20 - R27 */
16398615454SKuninori Morimoto 	0x04, 0x00, 0x00, 0x30, 0x2A, 0x00, 0x40, 0x00,	/* R28 - R2F */
16498615454SKuninori Morimoto 	0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00,	/* R30 - R37 */
16598615454SKuninori Morimoto 	0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x00, 0x00,	/* R38 - R3F */
16698615454SKuninori Morimoto 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	/* R40 - R4F */
16798615454SKuninori Morimoto 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	/* R48 - R4F */
16898615454SKuninori Morimoto 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	/* R50 - R57 */
16998615454SKuninori Morimoto 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	/* R58 - R5F */
17098615454SKuninori Morimoto 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	/* R60 - R67 */
17198615454SKuninori Morimoto 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	/* R68 - R6F */
17298615454SKuninori Morimoto 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	/* R70 - R77 */
17398615454SKuninori Morimoto 	0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0x54, 0x00,	/* R78 - R7F */
17498615454SKuninori Morimoto 	0x00, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x00,	/* R80 - R87 */
17598615454SKuninori Morimoto 	0x00,						/* R88       */
17698615454SKuninori Morimoto };
17798615454SKuninori Morimoto 
17898615454SKuninori Morimoto /*
17998615454SKuninori Morimoto  * Read da7210 register cache
18098615454SKuninori Morimoto  */
18198615454SKuninori Morimoto static inline u32 da7210_read_reg_cache(struct snd_soc_codec *codec, u32 reg)
18298615454SKuninori Morimoto {
18398615454SKuninori Morimoto 	u8 *cache = codec->reg_cache;
18498615454SKuninori Morimoto 	BUG_ON(reg > ARRAY_SIZE(da7210_reg));
18598615454SKuninori Morimoto 	return cache[reg];
18698615454SKuninori Morimoto }
18798615454SKuninori Morimoto 
18898615454SKuninori Morimoto /*
18998615454SKuninori Morimoto  * Write to the da7210 register space
19098615454SKuninori Morimoto  */
19198615454SKuninori Morimoto static int da7210_write(struct snd_soc_codec *codec, u32 reg, u32 value)
19298615454SKuninori Morimoto {
19398615454SKuninori Morimoto 	u8 *cache = codec->reg_cache;
19498615454SKuninori Morimoto 	u8 data[2];
19598615454SKuninori Morimoto 
19698615454SKuninori Morimoto 	BUG_ON(codec->volatile_register);
19798615454SKuninori Morimoto 
19898615454SKuninori Morimoto 	data[0] = reg & 0xff;
19998615454SKuninori Morimoto 	data[1] = value & 0xff;
20098615454SKuninori Morimoto 
20198615454SKuninori Morimoto 	if (reg >= codec->reg_cache_size)
20298615454SKuninori Morimoto 		return -EIO;
20398615454SKuninori Morimoto 
20498615454SKuninori Morimoto 	if (2 != codec->hw_write(codec->control_data, data, 2))
20598615454SKuninori Morimoto 		return -EIO;
20698615454SKuninori Morimoto 
20798615454SKuninori Morimoto 	cache[reg] = value;
20898615454SKuninori Morimoto 	return 0;
20998615454SKuninori Morimoto }
21098615454SKuninori Morimoto 
21198615454SKuninori Morimoto /*
21298615454SKuninori Morimoto  * Read from the da7210 register space.
21398615454SKuninori Morimoto  */
21498615454SKuninori Morimoto static inline u32 da7210_read(struct snd_soc_codec *codec, u32 reg)
21598615454SKuninori Morimoto {
21698615454SKuninori Morimoto 	if (DA7210_STATUS == reg)
21798615454SKuninori Morimoto 		return i2c_smbus_read_byte_data(codec->control_data, reg);
21898615454SKuninori Morimoto 
21998615454SKuninori Morimoto 	return da7210_read_reg_cache(codec, reg);
22098615454SKuninori Morimoto }
22198615454SKuninori Morimoto 
22298615454SKuninori Morimoto static int da7210_startup(struct snd_pcm_substream *substream,
22398615454SKuninori Morimoto 			  struct snd_soc_dai *dai)
22498615454SKuninori Morimoto {
22598615454SKuninori Morimoto 	int is_play = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
22698615454SKuninori Morimoto 	struct snd_soc_codec *codec = dai->codec;
22798615454SKuninori Morimoto 
22898615454SKuninori Morimoto 	if (is_play) {
22998615454SKuninori Morimoto 		/* PlayBack Volume 40 */
23098615454SKuninori Morimoto 		snd_soc_update_bits(codec, DA7210_HP_L_VOL, 0x3F, 40);
23198615454SKuninori Morimoto 		snd_soc_update_bits(codec, DA7210_HP_R_VOL, 0x3F, 40);
23298615454SKuninori Morimoto 
23398615454SKuninori Morimoto 		/* Enable Out */
23498615454SKuninori Morimoto 		snd_soc_update_bits(codec, DA7210_OUTMIX_L, 0x1F, 0x10);
23598615454SKuninori Morimoto 		snd_soc_update_bits(codec, DA7210_OUTMIX_R, 0x1F, 0x10);
23698615454SKuninori Morimoto 
23798615454SKuninori Morimoto 	} else {
23898615454SKuninori Morimoto 		/* Volume 7 */
23998615454SKuninori Morimoto 		snd_soc_update_bits(codec, DA7210_MIC_L, 0x7, 0x7);
24098615454SKuninori Morimoto 		snd_soc_update_bits(codec, DA7210_MIC_R, 0x7, 0x7);
24198615454SKuninori Morimoto 
24298615454SKuninori Morimoto 		/* Enable Mic */
24398615454SKuninori Morimoto 		snd_soc_update_bits(codec, DA7210_INMIX_L, 0x1F, 0x1);
24498615454SKuninori Morimoto 		snd_soc_update_bits(codec, DA7210_INMIX_R, 0x1F, 0x1);
24598615454SKuninori Morimoto 	}
24698615454SKuninori Morimoto 
24798615454SKuninori Morimoto 	return 0;
24898615454SKuninori Morimoto }
24998615454SKuninori Morimoto 
25098615454SKuninori Morimoto /*
25198615454SKuninori Morimoto  * Set PCM DAI word length.
25298615454SKuninori Morimoto  */
25398615454SKuninori Morimoto static int da7210_hw_params(struct snd_pcm_substream *substream,
25498615454SKuninori Morimoto 			    struct snd_pcm_hw_params *params,
25598615454SKuninori Morimoto 			    struct snd_soc_dai *dai)
25698615454SKuninori Morimoto {
25798615454SKuninori Morimoto 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
25898615454SKuninori Morimoto 	struct snd_soc_device *socdev = rtd->socdev;
25998615454SKuninori Morimoto 	struct snd_soc_codec *codec = socdev->card->codec;
26098615454SKuninori Morimoto 	u32 dai_cfg1;
2613a9d6202SKuninori Morimoto 	u32 hpf_reg, hpf_mask, hpf_value;
262960b3b4bSKuninori Morimoto 	u32 fs, bypass;
26398615454SKuninori Morimoto 
26498615454SKuninori Morimoto 	/* set DAI source to Left and Right ADC */
26598615454SKuninori Morimoto 	da7210_write(codec, DA7210_DAI_SRC_SEL,
26698615454SKuninori Morimoto 		     DA7210_DAI_OUT_R_SRC | DA7210_DAI_OUT_L_SRC);
26798615454SKuninori Morimoto 
26898615454SKuninori Morimoto 	/* Enable DAI */
26998615454SKuninori Morimoto 	da7210_write(codec, DA7210_DAI_CFG3, DA7210_DAI_OE | DA7210_DAI_EN);
27098615454SKuninori Morimoto 
27198615454SKuninori Morimoto 	dai_cfg1 = 0xFC & da7210_read(codec, DA7210_DAI_CFG1);
27298615454SKuninori Morimoto 
27398615454SKuninori Morimoto 	switch (params_format(params)) {
27498615454SKuninori Morimoto 	case SNDRV_PCM_FORMAT_S16_LE:
27598615454SKuninori Morimoto 		dai_cfg1 |= DA7210_DAI_WORD_S16_LE;
27698615454SKuninori Morimoto 		break;
27798615454SKuninori Morimoto 	case SNDRV_PCM_FORMAT_S24_LE:
27898615454SKuninori Morimoto 		dai_cfg1 |= DA7210_DAI_WORD_S24_LE;
27998615454SKuninori Morimoto 		break;
28098615454SKuninori Morimoto 	default:
28198615454SKuninori Morimoto 		return -EINVAL;
28298615454SKuninori Morimoto 	}
28398615454SKuninori Morimoto 
28498615454SKuninori Morimoto 	da7210_write(codec, DA7210_DAI_CFG1, dai_cfg1);
28598615454SKuninori Morimoto 
2863a9d6202SKuninori Morimoto 	hpf_reg = (SNDRV_PCM_STREAM_PLAYBACK == substream->stream) ?
2873a9d6202SKuninori Morimoto 		DA7210_DAC_HPF : DA7210_ADC_HPF;
2883a9d6202SKuninori Morimoto 
28998615454SKuninori Morimoto 	switch (params_rate(params)) {
2903a9d6202SKuninori Morimoto 	case 8000:
2913a9d6202SKuninori Morimoto 		fs		= DA7210_PLL_FS_8000;
2923a9d6202SKuninori Morimoto 		hpf_mask	= DA7210_VOICE_F0_MASK	| DA7210_VOICE_EN;
2933a9d6202SKuninori Morimoto 		hpf_value	= DA7210_VOICE_F0_25	| DA7210_VOICE_EN;
294960b3b4bSKuninori Morimoto 		bypass		= DA7210_PLL_BYP;
295960b3b4bSKuninori Morimoto 		break;
296960b3b4bSKuninori Morimoto 	case 11025:
297960b3b4bSKuninori Morimoto 		fs		= DA7210_PLL_FS_11025;
298960b3b4bSKuninori Morimoto 		hpf_mask	= DA7210_VOICE_F0_MASK	| DA7210_VOICE_EN;
299960b3b4bSKuninori Morimoto 		hpf_value	= DA7210_VOICE_F0_25	| DA7210_VOICE_EN;
300960b3b4bSKuninori Morimoto 		bypass		= 0;
3013a9d6202SKuninori Morimoto 		break;
3023a9d6202SKuninori Morimoto 	case 12000:
3033a9d6202SKuninori Morimoto 		fs		= DA7210_PLL_FS_12000;
3043a9d6202SKuninori Morimoto 		hpf_mask	= DA7210_VOICE_F0_MASK	| DA7210_VOICE_EN;
3053a9d6202SKuninori Morimoto 		hpf_value	= DA7210_VOICE_F0_25	| DA7210_VOICE_EN;
306960b3b4bSKuninori Morimoto 		bypass		= DA7210_PLL_BYP;
3073a9d6202SKuninori Morimoto 		break;
3083a9d6202SKuninori Morimoto 	case 16000:
3093a9d6202SKuninori Morimoto 		fs		= DA7210_PLL_FS_16000;
3103a9d6202SKuninori Morimoto 		hpf_mask	= DA7210_VOICE_F0_MASK	| DA7210_VOICE_EN;
3113a9d6202SKuninori Morimoto 		hpf_value	= DA7210_VOICE_F0_25	| DA7210_VOICE_EN;
312960b3b4bSKuninori Morimoto 		bypass		= DA7210_PLL_BYP;
313960b3b4bSKuninori Morimoto 		break;
314960b3b4bSKuninori Morimoto 	case 22050:
315960b3b4bSKuninori Morimoto 		fs		= DA7210_PLL_FS_22050;
316960b3b4bSKuninori Morimoto 		hpf_mask	= DA7210_VOICE_EN;
317960b3b4bSKuninori Morimoto 		hpf_value	= 0;
318960b3b4bSKuninori Morimoto 		bypass		= 0;
3193a9d6202SKuninori Morimoto 		break;
3203a9d6202SKuninori Morimoto 	case 32000:
3213a9d6202SKuninori Morimoto 		fs		= DA7210_PLL_FS_32000;
3223a9d6202SKuninori Morimoto 		hpf_mask	= DA7210_VOICE_EN;
3233a9d6202SKuninori Morimoto 		hpf_value	= 0;
324960b3b4bSKuninori Morimoto 		bypass		= DA7210_PLL_BYP;
325960b3b4bSKuninori Morimoto 		break;
326960b3b4bSKuninori Morimoto 	case 44100:
327960b3b4bSKuninori Morimoto 		fs		= DA7210_PLL_FS_44100;
328960b3b4bSKuninori Morimoto 		hpf_mask	= DA7210_VOICE_EN;
329960b3b4bSKuninori Morimoto 		hpf_value	= 0;
330960b3b4bSKuninori Morimoto 		bypass		= 0;
3313a9d6202SKuninori Morimoto 		break;
33298615454SKuninori Morimoto 	case 48000:
3333a9d6202SKuninori Morimoto 		fs		= DA7210_PLL_FS_48000;
3343a9d6202SKuninori Morimoto 		hpf_mask	= DA7210_VOICE_EN;
3353a9d6202SKuninori Morimoto 		hpf_value	= 0;
336960b3b4bSKuninori Morimoto 		bypass		= DA7210_PLL_BYP;
337960b3b4bSKuninori Morimoto 		break;
338960b3b4bSKuninori Morimoto 	case 88200:
339960b3b4bSKuninori Morimoto 		fs		= DA7210_PLL_FS_88200;
340960b3b4bSKuninori Morimoto 		hpf_mask	= DA7210_VOICE_EN;
341960b3b4bSKuninori Morimoto 		hpf_value	= 0;
342960b3b4bSKuninori Morimoto 		bypass		= 0;
3433a9d6202SKuninori Morimoto 		break;
3443a9d6202SKuninori Morimoto 	case 96000:
3453a9d6202SKuninori Morimoto 		fs		= DA7210_PLL_FS_96000;
3463a9d6202SKuninori Morimoto 		hpf_mask	= DA7210_VOICE_EN;
3473a9d6202SKuninori Morimoto 		hpf_value	= 0;
348960b3b4bSKuninori Morimoto 		bypass		= DA7210_PLL_BYP;
34998615454SKuninori Morimoto 		break;
35098615454SKuninori Morimoto 	default:
35198615454SKuninori Morimoto 		return -EINVAL;
35298615454SKuninori Morimoto 	}
35398615454SKuninori Morimoto 
354960b3b4bSKuninori Morimoto 	/* Disable active mode */
355960b3b4bSKuninori Morimoto 	snd_soc_update_bits(codec, DA7210_STARTUP1, DA7210_SC_MST_EN, 0);
356960b3b4bSKuninori Morimoto 
3573a9d6202SKuninori Morimoto 	snd_soc_update_bits(codec, hpf_reg, hpf_mask, hpf_value);
3583a9d6202SKuninori Morimoto 	snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_FS_MASK, fs);
359960b3b4bSKuninori Morimoto 	snd_soc_update_bits(codec, DA7210_PLL_DIV3, DA7210_PLL_BYP, bypass);
360960b3b4bSKuninori Morimoto 
361960b3b4bSKuninori Morimoto 	/* Enable active mode */
362960b3b4bSKuninori Morimoto 	snd_soc_update_bits(codec, DA7210_STARTUP1,
363960b3b4bSKuninori Morimoto 			    DA7210_SC_MST_EN, DA7210_SC_MST_EN);
36498615454SKuninori Morimoto 
36598615454SKuninori Morimoto 	return 0;
36698615454SKuninori Morimoto }
36798615454SKuninori Morimoto 
36898615454SKuninori Morimoto /*
36998615454SKuninori Morimoto  * Set DAI mode and Format
37098615454SKuninori Morimoto  */
37198615454SKuninori Morimoto static int da7210_set_dai_fmt(struct snd_soc_dai *codec_dai, u32 fmt)
37298615454SKuninori Morimoto {
37398615454SKuninori Morimoto 	struct snd_soc_codec *codec = codec_dai->codec;
37498615454SKuninori Morimoto 	u32 dai_cfg1;
37598615454SKuninori Morimoto 	u32 dai_cfg3;
37698615454SKuninori Morimoto 
37798615454SKuninori Morimoto 	dai_cfg1 = 0x7f & da7210_read(codec, DA7210_DAI_CFG1);
37898615454SKuninori Morimoto 	dai_cfg3 = 0xfc & da7210_read(codec, DA7210_DAI_CFG3);
37998615454SKuninori Morimoto 
38098615454SKuninori Morimoto 	switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
38198615454SKuninori Morimoto 	case SND_SOC_DAIFMT_CBM_CFM:
38298615454SKuninori Morimoto 		dai_cfg1 |= DA7210_DAI_MODE_MASTER;
38398615454SKuninori Morimoto 		break;
38498615454SKuninori Morimoto 	default:
38598615454SKuninori Morimoto 		return -EINVAL;
38698615454SKuninori Morimoto 	}
38798615454SKuninori Morimoto 
38898615454SKuninori Morimoto 	/* FIXME
38998615454SKuninori Morimoto 	 *
39098615454SKuninori Morimoto 	 * It support I2S only now
39198615454SKuninori Morimoto 	 */
39298615454SKuninori Morimoto 	switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
39398615454SKuninori Morimoto 	case SND_SOC_DAIFMT_I2S:
39498615454SKuninori Morimoto 		dai_cfg3 |= DA7210_DAI_FORMAT_I2SMODE;
39598615454SKuninori Morimoto 		break;
39698615454SKuninori Morimoto 	default:
39798615454SKuninori Morimoto 		return -EINVAL;
39898615454SKuninori Morimoto 	}
39998615454SKuninori Morimoto 
40098615454SKuninori Morimoto 	/* FIXME
40198615454SKuninori Morimoto 	 *
40298615454SKuninori Morimoto 	 * It support 64bit data transmission only now
40398615454SKuninori Morimoto 	 */
40498615454SKuninori Morimoto 	dai_cfg1 |= DA7210_DAI_FLEN_64BIT;
40598615454SKuninori Morimoto 
40698615454SKuninori Morimoto 	da7210_write(codec, DA7210_DAI_CFG1, dai_cfg1);
40798615454SKuninori Morimoto 	da7210_write(codec, DA7210_DAI_CFG3, dai_cfg3);
40898615454SKuninori Morimoto 
40998615454SKuninori Morimoto 	return 0;
41098615454SKuninori Morimoto }
41198615454SKuninori Morimoto 
41298615454SKuninori Morimoto #define DA7210_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE)
41398615454SKuninori Morimoto 
41498615454SKuninori Morimoto /* DAI operations */
41598615454SKuninori Morimoto static struct snd_soc_dai_ops da7210_dai_ops = {
41698615454SKuninori Morimoto 	.startup	= da7210_startup,
41798615454SKuninori Morimoto 	.hw_params	= da7210_hw_params,
41898615454SKuninori Morimoto 	.set_fmt	= da7210_set_dai_fmt,
41998615454SKuninori Morimoto };
42098615454SKuninori Morimoto 
42198615454SKuninori Morimoto struct snd_soc_dai da7210_dai = {
42298615454SKuninori Morimoto 	.name = "DA7210 IIS",
42398615454SKuninori Morimoto 	.id = 0,
42498615454SKuninori Morimoto 	/* playback capabilities */
42598615454SKuninori Morimoto 	.playback = {
42698615454SKuninori Morimoto 		.stream_name = "Playback",
42798615454SKuninori Morimoto 		.channels_min = 1,
42898615454SKuninori Morimoto 		.channels_max = 2,
42998615454SKuninori Morimoto 		.rates = SNDRV_PCM_RATE_8000_96000,
43098615454SKuninori Morimoto 		.formats = DA7210_FORMATS,
43198615454SKuninori Morimoto 	},
43298615454SKuninori Morimoto 	/* capture capabilities */
43398615454SKuninori Morimoto 	.capture = {
43498615454SKuninori Morimoto 		.stream_name = "Capture",
43598615454SKuninori Morimoto 		.channels_min = 1,
43698615454SKuninori Morimoto 		.channels_max = 2,
43798615454SKuninori Morimoto 		.rates = SNDRV_PCM_RATE_8000_96000,
43898615454SKuninori Morimoto 		.formats = DA7210_FORMATS,
43998615454SKuninori Morimoto 	},
44098615454SKuninori Morimoto 	.ops = &da7210_dai_ops,
441960b3b4bSKuninori Morimoto 	.symmetric_rates = 1,
44298615454SKuninori Morimoto };
44398615454SKuninori Morimoto EXPORT_SYMBOL_GPL(da7210_dai);
44498615454SKuninori Morimoto 
44598615454SKuninori Morimoto /*
44698615454SKuninori Morimoto  * Initialize the DA7210 driver
44798615454SKuninori Morimoto  * register the mixer and dsp interfaces with the kernel
44898615454SKuninori Morimoto  */
44998615454SKuninori Morimoto static int da7210_init(struct da7210_priv *da7210)
45098615454SKuninori Morimoto {
45198615454SKuninori Morimoto 	struct snd_soc_codec *codec = &da7210->codec;
45298615454SKuninori Morimoto 	int ret = 0;
45398615454SKuninori Morimoto 
45498615454SKuninori Morimoto 	if (da7210_codec) {
45598615454SKuninori Morimoto 		dev_err(codec->dev, "Another da7210 is registered\n");
45698615454SKuninori Morimoto 		return -EINVAL;
45798615454SKuninori Morimoto 	}
45898615454SKuninori Morimoto 
45998615454SKuninori Morimoto 	mutex_init(&codec->mutex);
46098615454SKuninori Morimoto 	INIT_LIST_HEAD(&codec->dapm_widgets);
46198615454SKuninori Morimoto 	INIT_LIST_HEAD(&codec->dapm_paths);
46298615454SKuninori Morimoto 
46398615454SKuninori Morimoto 	codec->private_data	= da7210;
46498615454SKuninori Morimoto 	codec->name		= "DA7210";
46598615454SKuninori Morimoto 	codec->owner		= THIS_MODULE;
46698615454SKuninori Morimoto 	codec->read		= da7210_read;
46798615454SKuninori Morimoto 	codec->write		= da7210_write;
46898615454SKuninori Morimoto 	codec->dai		= &da7210_dai;
46998615454SKuninori Morimoto 	codec->num_dai		= 1;
47098615454SKuninori Morimoto 	codec->hw_write		= (hw_write_t)i2c_master_send;
47198615454SKuninori Morimoto 	codec->reg_cache_size	= ARRAY_SIZE(da7210_reg);
47298615454SKuninori Morimoto 	codec->reg_cache	= kmemdup(da7210_reg,
47398615454SKuninori Morimoto 					  sizeof(da7210_reg), GFP_KERNEL);
47498615454SKuninori Morimoto 
47598615454SKuninori Morimoto 	if (!codec->reg_cache)
47698615454SKuninori Morimoto 		return -ENOMEM;
47798615454SKuninori Morimoto 
47898615454SKuninori Morimoto 	da7210_dai.dev = codec->dev;
47998615454SKuninori Morimoto 	da7210_codec = codec;
48098615454SKuninori Morimoto 
48198615454SKuninori Morimoto 	ret = snd_soc_register_codec(codec);
48298615454SKuninori Morimoto 	if (ret) {
48398615454SKuninori Morimoto 		dev_err(codec->dev, "Failed to register CODEC: %d\n", ret);
48498615454SKuninori Morimoto 		goto init_err;
48598615454SKuninori Morimoto 	}
48698615454SKuninori Morimoto 
48798615454SKuninori Morimoto 	ret = snd_soc_register_dai(&da7210_dai);
48898615454SKuninori Morimoto 	if (ret) {
48998615454SKuninori Morimoto 		dev_err(codec->dev, "Failed to register DAI: %d\n", ret);
49098615454SKuninori Morimoto 		goto init_err;
49198615454SKuninori Morimoto 	}
49298615454SKuninori Morimoto 
49398615454SKuninori Morimoto 	/* FIXME
49498615454SKuninori Morimoto 	 *
49598615454SKuninori Morimoto 	 * This driver use fixed value here
496960b3b4bSKuninori Morimoto 	 * And below settings expects MCLK = 12.288MHz
497960b3b4bSKuninori Morimoto 	 *
498960b3b4bSKuninori Morimoto 	 * When you select different MCLK, please check...
499960b3b4bSKuninori Morimoto 	 *      DA7210_PLL_DIV1 val
500960b3b4bSKuninori Morimoto 	 *      DA7210_PLL_DIV2 val
501960b3b4bSKuninori Morimoto 	 *      DA7210_PLL_DIV3 val
502960b3b4bSKuninori Morimoto 	 *      DA7210_PLL_DIV3 :: DA7210_MCLK_RANGExxx
50398615454SKuninori Morimoto 	 */
50498615454SKuninori Morimoto 
50598615454SKuninori Morimoto 	/*
506960b3b4bSKuninori Morimoto 	 * make sure that DA7210 use bypass mode before start up
507960b3b4bSKuninori Morimoto 	 */
508960b3b4bSKuninori Morimoto 	da7210_write(codec, DA7210_STARTUP1, 0);
509960b3b4bSKuninori Morimoto 	da7210_write(codec, DA7210_PLL_DIV3,
510960b3b4bSKuninori Morimoto 		     DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP);
511960b3b4bSKuninori Morimoto 
512960b3b4bSKuninori Morimoto 	/*
51398615454SKuninori Morimoto 	 * ADC settings
51498615454SKuninori Morimoto 	 */
51598615454SKuninori Morimoto 
51698615454SKuninori Morimoto 	/* Enable Left & Right MIC PGA and Mic Bias */
51798615454SKuninori Morimoto 	da7210_write(codec, DA7210_MIC_L, DA7210_MIC_L_EN | DA7210_MICBIAS_EN);
51898615454SKuninori Morimoto 	da7210_write(codec, DA7210_MIC_R, DA7210_MIC_R_EN);
51998615454SKuninori Morimoto 
52098615454SKuninori Morimoto 	/* Enable Left and Right input PGA */
52198615454SKuninori Morimoto 	da7210_write(codec, DA7210_INMIX_L, DA7210_IN_L_EN);
52298615454SKuninori Morimoto 	da7210_write(codec, DA7210_INMIX_R, DA7210_IN_R_EN);
52398615454SKuninori Morimoto 
52498615454SKuninori Morimoto 	/* Enable Left and Right ADC */
52598615454SKuninori Morimoto 	da7210_write(codec, DA7210_ADC, DA7210_ADC_L_EN | DA7210_ADC_R_EN);
52698615454SKuninori Morimoto 
52798615454SKuninori Morimoto 	/*
52898615454SKuninori Morimoto 	 * DAC settings
52998615454SKuninori Morimoto 	 */
53098615454SKuninori Morimoto 
53198615454SKuninori Morimoto 	/* Enable Left and Right DAC */
53298615454SKuninori Morimoto 	da7210_write(codec, DA7210_DAC_SEL,
53398615454SKuninori Morimoto 		     DA7210_DAC_L_SRC_DAI_L | DA7210_DAC_L_EN |
53498615454SKuninori Morimoto 		     DA7210_DAC_R_SRC_DAI_R | DA7210_DAC_R_EN);
53598615454SKuninori Morimoto 
53698615454SKuninori Morimoto 	/* Enable Left and Right out PGA */
53798615454SKuninori Morimoto 	da7210_write(codec, DA7210_OUTMIX_L, DA7210_OUT_L_EN);
53898615454SKuninori Morimoto 	da7210_write(codec, DA7210_OUTMIX_R, DA7210_OUT_R_EN);
53998615454SKuninori Morimoto 
54098615454SKuninori Morimoto 	/* Enable Left and Right HeadPhone PGA */
54198615454SKuninori Morimoto 	da7210_write(codec, DA7210_HP_CFG,
54298615454SKuninori Morimoto 		     DA7210_HP_2CAP_MODE | DA7210_HP_SENSE_EN |
54398615454SKuninori Morimoto 		     DA7210_HP_L_EN | DA7210_HP_MODE | DA7210_HP_R_EN);
54498615454SKuninori Morimoto 
54598615454SKuninori Morimoto 	/* Diable PLL and bypass it */
54698615454SKuninori Morimoto 	da7210_write(codec, DA7210_PLL, DA7210_PLL_FS_48000);
54798615454SKuninori Morimoto 
548960b3b4bSKuninori Morimoto 	/*
549960b3b4bSKuninori Morimoto 	 * If 48kHz sound came, it use bypass mode,
550960b3b4bSKuninori Morimoto 	 * and when it is 44.1kHz, it use PLL.
551960b3b4bSKuninori Morimoto 	 *
552960b3b4bSKuninori Morimoto 	 * This time, this driver sets PLL always ON
553960b3b4bSKuninori Morimoto 	 * and controls bypass/PLL mode by switching
554960b3b4bSKuninori Morimoto 	 * DA7210_PLL_DIV3 :: DA7210_PLL_BYP bit.
555960b3b4bSKuninori Morimoto 	 *   see da7210_hw_params
556960b3b4bSKuninori Morimoto 	 */
557960b3b4bSKuninori Morimoto 	da7210_write(codec, DA7210_PLL_DIV1, 0xE5); /* MCLK = 12.288MHz */
558960b3b4bSKuninori Morimoto 	da7210_write(codec, DA7210_PLL_DIV2, 0x99);
559960b3b4bSKuninori Morimoto 	da7210_write(codec, DA7210_PLL_DIV3, 0x0A |
56098615454SKuninori Morimoto 		     DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP);
561960b3b4bSKuninori Morimoto 	snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_EN, DA7210_PLL_EN);
562960b3b4bSKuninori Morimoto 
563960b3b4bSKuninori Morimoto 	/* As suggested by Dialog */
564960b3b4bSKuninori Morimoto 	da7210_write(codec, DA7210_A_HID_UNLOCK,	0x8B); /* unlock */
565960b3b4bSKuninori Morimoto 	da7210_write(codec, DA7210_A_TEST_UNLOCK,	0xB4);
566960b3b4bSKuninori Morimoto 	da7210_write(codec, DA7210_A_PLL1,		0x01);
567960b3b4bSKuninori Morimoto 	da7210_write(codec, DA7210_A_CP_MODE,		0x7C);
568960b3b4bSKuninori Morimoto 	da7210_write(codec, DA7210_A_HID_UNLOCK,	0x00); /* re-lock */
569960b3b4bSKuninori Morimoto 	da7210_write(codec, DA7210_A_TEST_UNLOCK,	0x00);
57098615454SKuninori Morimoto 
57198615454SKuninori Morimoto 	/* Activate all enabled subsystem */
57298615454SKuninori Morimoto 	da7210_write(codec, DA7210_STARTUP1, DA7210_SC_MST_EN);
57398615454SKuninori Morimoto 
57498615454SKuninori Morimoto 	return ret;
57598615454SKuninori Morimoto 
57698615454SKuninori Morimoto init_err:
57798615454SKuninori Morimoto 	kfree(codec->reg_cache);
57898615454SKuninori Morimoto 	codec->reg_cache = NULL;
57998615454SKuninori Morimoto 
58098615454SKuninori Morimoto 	return ret;
58198615454SKuninori Morimoto 
58298615454SKuninori Morimoto }
58398615454SKuninori Morimoto 
58498615454SKuninori Morimoto #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
585735fe4cfSMark Brown static int __devinit da7210_i2c_probe(struct i2c_client *i2c,
58698615454SKuninori Morimoto 			   	      const struct i2c_device_id *id)
58798615454SKuninori Morimoto {
58898615454SKuninori Morimoto 	struct da7210_priv *da7210;
58998615454SKuninori Morimoto 	struct snd_soc_codec *codec;
59098615454SKuninori Morimoto 	int ret;
59198615454SKuninori Morimoto 
59298615454SKuninori Morimoto 	da7210 = kzalloc(sizeof(struct da7210_priv), GFP_KERNEL);
59398615454SKuninori Morimoto 	if (!da7210)
59498615454SKuninori Morimoto 		return -ENOMEM;
59598615454SKuninori Morimoto 
59698615454SKuninori Morimoto 	codec = &da7210->codec;
59798615454SKuninori Morimoto 	codec->dev = &i2c->dev;
59898615454SKuninori Morimoto 
59998615454SKuninori Morimoto 	i2c_set_clientdata(i2c, da7210);
60098615454SKuninori Morimoto 	codec->control_data = i2c;
60198615454SKuninori Morimoto 
60298615454SKuninori Morimoto 	ret = da7210_init(da7210);
60398615454SKuninori Morimoto 	if (ret < 0)
60498615454SKuninori Morimoto 		pr_err("Failed to initialise da7210 audio codec\n");
60598615454SKuninori Morimoto 
60698615454SKuninori Morimoto 	return ret;
60798615454SKuninori Morimoto }
60898615454SKuninori Morimoto 
609735fe4cfSMark Brown static int __devexit da7210_i2c_remove(struct i2c_client *client)
61098615454SKuninori Morimoto {
61198615454SKuninori Morimoto 	struct da7210_priv *da7210 = i2c_get_clientdata(client);
61298615454SKuninori Morimoto 
61398615454SKuninori Morimoto 	snd_soc_unregister_dai(&da7210_dai);
61498615454SKuninori Morimoto 	kfree(da7210->codec.reg_cache);
61598615454SKuninori Morimoto 	kfree(da7210);
61698615454SKuninori Morimoto 	da7210_codec = NULL;
61798615454SKuninori Morimoto 
61898615454SKuninori Morimoto 	return 0;
61998615454SKuninori Morimoto }
62098615454SKuninori Morimoto 
62198615454SKuninori Morimoto static const struct i2c_device_id da7210_i2c_id[] = {
62298615454SKuninori Morimoto 	{ "da7210", 0 },
62398615454SKuninori Morimoto 	{ }
62498615454SKuninori Morimoto };
62598615454SKuninori Morimoto MODULE_DEVICE_TABLE(i2c, da7210_i2c_id);
62698615454SKuninori Morimoto 
62798615454SKuninori Morimoto /* I2C codec control layer */
62898615454SKuninori Morimoto static struct i2c_driver da7210_i2c_driver = {
62998615454SKuninori Morimoto 	.driver = {
63098615454SKuninori Morimoto 		.name = "DA7210 I2C Codec",
63198615454SKuninori Morimoto 		.owner = THIS_MODULE,
63298615454SKuninori Morimoto 	},
63398615454SKuninori Morimoto 	.probe = da7210_i2c_probe,
63498615454SKuninori Morimoto 	.remove =  __devexit_p(da7210_i2c_remove),
63598615454SKuninori Morimoto 	.id_table = da7210_i2c_id,
63698615454SKuninori Morimoto };
63798615454SKuninori Morimoto #endif
63898615454SKuninori Morimoto 
63998615454SKuninori Morimoto static int da7210_probe(struct platform_device *pdev)
64098615454SKuninori Morimoto {
64198615454SKuninori Morimoto 	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
64298615454SKuninori Morimoto 	struct snd_soc_codec *codec;
64398615454SKuninori Morimoto 	int ret;
64498615454SKuninori Morimoto 
64598615454SKuninori Morimoto 	if (!da7210_codec) {
64698615454SKuninori Morimoto 		dev_err(&pdev->dev, "Codec device not registered\n");
64798615454SKuninori Morimoto 		return -ENODEV;
64898615454SKuninori Morimoto 	}
64998615454SKuninori Morimoto 
65098615454SKuninori Morimoto 	socdev->card->codec = da7210_codec;
65198615454SKuninori Morimoto 	codec = da7210_codec;
65298615454SKuninori Morimoto 
65398615454SKuninori Morimoto 	/* Register pcms */
65498615454SKuninori Morimoto 	ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
65598615454SKuninori Morimoto 	if (ret < 0)
65698615454SKuninori Morimoto 		goto pcm_err;
65798615454SKuninori Morimoto 
65898615454SKuninori Morimoto 	dev_info(&pdev->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION);
65998615454SKuninori Morimoto 
66098615454SKuninori Morimoto pcm_err:
66198615454SKuninori Morimoto 	return ret;
66298615454SKuninori Morimoto }
66398615454SKuninori Morimoto 
66498615454SKuninori Morimoto static int da7210_remove(struct platform_device *pdev)
66598615454SKuninori Morimoto {
66698615454SKuninori Morimoto 	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
66798615454SKuninori Morimoto 
66898615454SKuninori Morimoto 	snd_soc_free_pcms(socdev);
66998615454SKuninori Morimoto 	snd_soc_dapm_free(socdev);
67098615454SKuninori Morimoto 
67198615454SKuninori Morimoto 	return 0;
67298615454SKuninori Morimoto }
67398615454SKuninori Morimoto 
67498615454SKuninori Morimoto struct snd_soc_codec_device soc_codec_dev_da7210 = {
67598615454SKuninori Morimoto 	.probe =	da7210_probe,
67698615454SKuninori Morimoto 	.remove =	da7210_remove,
67798615454SKuninori Morimoto };
67898615454SKuninori Morimoto EXPORT_SYMBOL_GPL(soc_codec_dev_da7210);
67998615454SKuninori Morimoto 
68098615454SKuninori Morimoto static int __init da7210_modinit(void)
68198615454SKuninori Morimoto {
68298615454SKuninori Morimoto 	int ret = 0;
68398615454SKuninori Morimoto #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
68498615454SKuninori Morimoto 	ret = i2c_add_driver(&da7210_i2c_driver);
68598615454SKuninori Morimoto #endif
68698615454SKuninori Morimoto 	return ret;
68798615454SKuninori Morimoto }
68898615454SKuninori Morimoto module_init(da7210_modinit);
68998615454SKuninori Morimoto 
69098615454SKuninori Morimoto static void __exit da7210_exit(void)
69198615454SKuninori Morimoto {
69298615454SKuninori Morimoto #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
69398615454SKuninori Morimoto 	i2c_del_driver(&da7210_i2c_driver);
69498615454SKuninori Morimoto #endif
69598615454SKuninori Morimoto }
69698615454SKuninori Morimoto module_exit(da7210_exit);
69798615454SKuninori Morimoto 
69898615454SKuninori Morimoto MODULE_DESCRIPTION("ASoC DA7210 driver");
69998615454SKuninori Morimoto MODULE_AUTHOR("David Chen, Kuninori Morimoto");
70098615454SKuninori Morimoto MODULE_LICENSE("GPL");
701