Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 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 | * |
| 10 | * Tested on SuperH Ecovec24 board with S16/S24 LE in 48KHz using I2S |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify it |
| 13 | * under the terms of the GNU General Public License as published by the |
| 14 | * Free Software Foundation; either version 2 of the License, or (at your |
| 15 | * option) any later version. |
| 16 | */ |
| 17 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 18 | #include <linux/delay.h> |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 19 | #include <linux/i2c.h> |
| 20 | #include <linux/platform_device.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 21 | #include <linux/slab.h> |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 22 | #include <sound/pcm.h> |
| 23 | #include <sound/pcm_params.h> |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 24 | #include <sound/soc.h> |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 25 | #include <sound/initval.h> |
Kuninori Morimoto | a7e7cd5 | 2010-07-21 14:12:16 +0900 | [diff] [blame] | 26 | #include <sound/tlv.h> |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 27 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 28 | /* DA7210 register space */ |
| 29 | #define DA7210_STATUS 0x02 |
| 30 | #define DA7210_STARTUP1 0x03 |
| 31 | #define DA7210_MIC_L 0x07 |
| 32 | #define DA7210_MIC_R 0x08 |
| 33 | #define DA7210_INMIX_L 0x0D |
| 34 | #define DA7210_INMIX_R 0x0E |
| 35 | #define DA7210_ADC_HPF 0x0F |
| 36 | #define DA7210_ADC 0x10 |
Ashish Chavan | 0ee6e9e | 2011-10-15 14:47:56 +0530 | [diff] [blame^] | 37 | #define DA7210_ADC_EQ1_2 0X11 |
| 38 | #define DA7210_ADC_EQ3_4 0x12 |
| 39 | #define DA7210_ADC_EQ5 0x13 |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 40 | #define DA7210_DAC_HPF 0x14 |
| 41 | #define DA7210_DAC_L 0x15 |
| 42 | #define DA7210_DAC_R 0x16 |
| 43 | #define DA7210_DAC_SEL 0x17 |
Ashish Chavan | 0ee6e9e | 2011-10-15 14:47:56 +0530 | [diff] [blame^] | 44 | #define DA7210_DAC_EQ1_2 0x19 |
| 45 | #define DA7210_DAC_EQ3_4 0x1A |
| 46 | #define DA7210_DAC_EQ5 0x1B |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 47 | #define DA7210_OUTMIX_L 0x1C |
| 48 | #define DA7210_OUTMIX_R 0x1D |
| 49 | #define DA7210_HP_L_VOL 0x21 |
| 50 | #define DA7210_HP_R_VOL 0x22 |
| 51 | #define DA7210_HP_CFG 0x23 |
| 52 | #define DA7210_DAI_SRC_SEL 0x25 |
| 53 | #define DA7210_DAI_CFG1 0x26 |
| 54 | #define DA7210_DAI_CFG3 0x28 |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 55 | #define DA7210_PLL_DIV1 0x29 |
| 56 | #define DA7210_PLL_DIV2 0x2A |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 57 | #define DA7210_PLL_DIV3 0x2B |
| 58 | #define DA7210_PLL 0x2C |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 59 | #define DA7210_A_HID_UNLOCK 0x8A |
| 60 | #define DA7210_A_TEST_UNLOCK 0x8B |
| 61 | #define DA7210_A_PLL1 0x90 |
| 62 | #define DA7210_A_CP_MODE 0xA7 |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 63 | |
| 64 | /* STARTUP1 bit fields */ |
| 65 | #define DA7210_SC_MST_EN (1 << 0) |
| 66 | |
| 67 | /* MIC_L bit fields */ |
| 68 | #define DA7210_MICBIAS_EN (1 << 6) |
| 69 | #define DA7210_MIC_L_EN (1 << 7) |
| 70 | |
| 71 | /* MIC_R bit fields */ |
| 72 | #define DA7210_MIC_R_EN (1 << 7) |
| 73 | |
| 74 | /* INMIX_L bit fields */ |
| 75 | #define DA7210_IN_L_EN (1 << 7) |
| 76 | |
| 77 | /* INMIX_R bit fields */ |
| 78 | #define DA7210_IN_R_EN (1 << 7) |
| 79 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 80 | /* ADC bit fields */ |
| 81 | #define DA7210_ADC_L_EN (1 << 3) |
| 82 | #define DA7210_ADC_R_EN (1 << 7) |
| 83 | |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 84 | /* DAC/ADC HPF fields */ |
| 85 | #define DA7210_VOICE_F0_MASK (0x7 << 4) |
| 86 | #define DA7210_VOICE_F0_25 (1 << 4) |
| 87 | #define DA7210_VOICE_EN (1 << 7) |
Mark Brown | c215143 | 2009-12-16 20:36:37 +0000 | [diff] [blame] | 88 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 89 | /* DAC_SEL bit fields */ |
| 90 | #define DA7210_DAC_L_SRC_DAI_L (4 << 0) |
| 91 | #define DA7210_DAC_L_EN (1 << 3) |
| 92 | #define DA7210_DAC_R_SRC_DAI_R (5 << 4) |
| 93 | #define DA7210_DAC_R_EN (1 << 7) |
| 94 | |
| 95 | /* OUTMIX_L bit fields */ |
| 96 | #define DA7210_OUT_L_EN (1 << 7) |
| 97 | |
| 98 | /* OUTMIX_R bit fields */ |
| 99 | #define DA7210_OUT_R_EN (1 << 7) |
| 100 | |
| 101 | /* HP_CFG bit fields */ |
| 102 | #define DA7210_HP_2CAP_MODE (1 << 1) |
| 103 | #define DA7210_HP_SENSE_EN (1 << 2) |
| 104 | #define DA7210_HP_L_EN (1 << 3) |
| 105 | #define DA7210_HP_MODE (1 << 6) |
| 106 | #define DA7210_HP_R_EN (1 << 7) |
| 107 | |
| 108 | /* DAI_SRC_SEL bit fields */ |
| 109 | #define DA7210_DAI_OUT_L_SRC (6 << 0) |
| 110 | #define DA7210_DAI_OUT_R_SRC (7 << 4) |
| 111 | |
| 112 | /* DAI_CFG1 bit fields */ |
| 113 | #define DA7210_DAI_WORD_S16_LE (0 << 0) |
Ashish Chavan | 0f8ea58 | 2011-10-12 20:33:21 +0530 | [diff] [blame] | 114 | #define DA7210_DAI_WORD_S20_3LE (1 << 0) |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 115 | #define DA7210_DAI_WORD_S24_LE (2 << 0) |
Ashish Chavan | 0f8ea58 | 2011-10-12 20:33:21 +0530 | [diff] [blame] | 116 | #define DA7210_DAI_WORD_S32_LE (3 << 0) |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 117 | #define DA7210_DAI_FLEN_64BIT (1 << 2) |
Ashish Chavan | 0f8ea58 | 2011-10-12 20:33:21 +0530 | [diff] [blame] | 118 | #define DA7210_DAI_MODE_SLAVE (0 << 7) |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 119 | #define DA7210_DAI_MODE_MASTER (1 << 7) |
| 120 | |
| 121 | /* DAI_CFG3 bit fields */ |
| 122 | #define DA7210_DAI_FORMAT_I2SMODE (0 << 0) |
Ashish Chavan | 0f8ea58 | 2011-10-12 20:33:21 +0530 | [diff] [blame] | 123 | #define DA7210_DAI_FORMAT_LEFT_J (1 << 0) |
| 124 | #define DA7210_DAI_FORMAT_RIGHT_J (2 << 0) |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 125 | #define DA7210_DAI_OE (1 << 3) |
| 126 | #define DA7210_DAI_EN (1 << 7) |
| 127 | |
| 128 | /*PLL_DIV3 bit fields */ |
| 129 | #define DA7210_MCLK_RANGE_10_20_MHZ (1 << 4) |
| 130 | #define DA7210_PLL_BYP (1 << 6) |
| 131 | |
| 132 | /* PLL bit fields */ |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 133 | #define DA7210_PLL_FS_MASK (0xF << 0) |
| 134 | #define DA7210_PLL_FS_8000 (0x1 << 0) |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 135 | #define DA7210_PLL_FS_11025 (0x2 << 0) |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 136 | #define DA7210_PLL_FS_12000 (0x3 << 0) |
| 137 | #define DA7210_PLL_FS_16000 (0x5 << 0) |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 138 | #define DA7210_PLL_FS_22050 (0x6 << 0) |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 139 | #define DA7210_PLL_FS_24000 (0x7 << 0) |
| 140 | #define DA7210_PLL_FS_32000 (0x9 << 0) |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 141 | #define DA7210_PLL_FS_44100 (0xA << 0) |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 142 | #define DA7210_PLL_FS_48000 (0xB << 0) |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 143 | #define DA7210_PLL_FS_88200 (0xE << 0) |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 144 | #define DA7210_PLL_FS_96000 (0xF << 0) |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 145 | #define DA7210_PLL_EN (0x1 << 7) |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 146 | |
| 147 | #define DA7210_VERSION "0.0.1" |
| 148 | |
Kuninori Morimoto | a7e7cd5 | 2010-07-21 14:12:16 +0900 | [diff] [blame] | 149 | /* |
| 150 | * Playback Volume |
| 151 | * |
| 152 | * max : 0x3F (+15.0 dB) |
| 153 | * (1.5 dB step) |
| 154 | * min : 0x11 (-54.0 dB) |
| 155 | * mute : 0x10 |
| 156 | * reserved : 0x00 - 0x0F |
| 157 | * |
Kuninori Morimoto | a7e7cd5 | 2010-07-21 14:12:16 +0900 | [diff] [blame] | 158 | * Reserved area are considered as "mute". |
Kuninori Morimoto | a7e7cd5 | 2010-07-21 14:12:16 +0900 | [diff] [blame] | 159 | */ |
Ashish Chavan | 7a0e67b | 2011-10-14 16:25:25 +0530 | [diff] [blame] | 160 | static const unsigned int hp_out_tlv[] = { |
| 161 | TLV_DB_RANGE_HEAD(2), |
| 162 | 0x0, 0x10, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 1), |
| 163 | /* -54 dB to +15 dB */ |
| 164 | 0x11, 0x3f, TLV_DB_SCALE_ITEM(-5400, 150, 0), |
| 165 | }; |
Kuninori Morimoto | a7e7cd5 | 2010-07-21 14:12:16 +0900 | [diff] [blame] | 166 | |
Ashish Chavan | 0ee6e9e | 2011-10-15 14:47:56 +0530 | [diff] [blame^] | 167 | static const DECLARE_TLV_DB_SCALE(eq_gain_tlv, -1050, 150, 0); |
| 168 | static const DECLARE_TLV_DB_SCALE(adc_eq_master_gain_tlv, -1800, 600, 1); |
| 169 | |
Kuninori Morimoto | a7e7cd5 | 2010-07-21 14:12:16 +0900 | [diff] [blame] | 170 | static const struct snd_kcontrol_new da7210_snd_controls[] = { |
| 171 | |
| 172 | SOC_DOUBLE_R_TLV("HeadPhone Playback Volume", |
| 173 | DA7210_HP_L_VOL, DA7210_HP_R_VOL, |
| 174 | 0, 0x3F, 0, hp_out_tlv), |
Ashish Chavan | 0ee6e9e | 2011-10-15 14:47:56 +0530 | [diff] [blame^] | 175 | |
| 176 | /* DAC Equalizer controls */ |
| 177 | SOC_SINGLE("DAC EQ Switch", DA7210_DAC_EQ5, 7, 1, 0), |
| 178 | SOC_SINGLE_TLV("DAC EQ1 Volume", DA7210_DAC_EQ1_2, 0, 0xf, 1, |
| 179 | eq_gain_tlv), |
| 180 | SOC_SINGLE_TLV("DAC EQ2 Volume", DA7210_DAC_EQ1_2, 4, 0xf, 1, |
| 181 | eq_gain_tlv), |
| 182 | SOC_SINGLE_TLV("DAC EQ3 Volume", DA7210_DAC_EQ3_4, 0, 0xf, 1, |
| 183 | eq_gain_tlv), |
| 184 | SOC_SINGLE_TLV("DAC EQ4 Volume", DA7210_DAC_EQ3_4, 4, 0xf, 1, |
| 185 | eq_gain_tlv), |
| 186 | SOC_SINGLE_TLV("DAC EQ5 Volume", DA7210_DAC_EQ5, 0, 0xf, 1, |
| 187 | eq_gain_tlv), |
| 188 | |
| 189 | /* ADC Equalizer controls */ |
| 190 | SOC_SINGLE("ADC EQ Switch", DA7210_ADC_EQ5, 7, 1, 0), |
| 191 | SOC_SINGLE_TLV("ADC EQ Master Volume", DA7210_ADC_EQ5, 4, 0x3, |
| 192 | 1, adc_eq_master_gain_tlv), |
| 193 | SOC_SINGLE_TLV("ADC EQ1 Volume", DA7210_ADC_EQ1_2, 0, 0xf, 1, |
| 194 | eq_gain_tlv), |
| 195 | SOC_SINGLE_TLV("ADC EQ2 Volume", DA7210_ADC_EQ1_2, 4, 0xf, 1, |
| 196 | eq_gain_tlv), |
| 197 | SOC_SINGLE_TLV("ADC EQ3 Volume", DA7210_ADC_EQ3_4, 0, 0xf, 1, |
| 198 | eq_gain_tlv), |
| 199 | SOC_SINGLE_TLV("ADC EQ4 Volume", DA7210_ADC_EQ3_4, 4, 0xf, 1, |
| 200 | eq_gain_tlv), |
| 201 | SOC_SINGLE_TLV("ADC EQ5 Volume", DA7210_ADC_EQ5, 0, 0xf, 1, |
| 202 | eq_gain_tlv), |
Kuninori Morimoto | a7e7cd5 | 2010-07-21 14:12:16 +0900 | [diff] [blame] | 203 | }; |
| 204 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 205 | /* Codec private data */ |
| 206 | struct da7210_priv { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 207 | enum snd_soc_control_type control_type; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 208 | }; |
| 209 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 210 | /* |
| 211 | * Register cache |
| 212 | */ |
| 213 | static const u8 da7210_reg[] = { |
| 214 | 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R0 - R7 */ |
| 215 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, /* R8 - RF */ |
| 216 | 0x00, 0x00, 0x00, 0x00, 0x08, 0x10, 0x10, 0x54, /* R10 - R17 */ |
| 217 | 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R18 - R1F */ |
| 218 | 0x00, 0x00, 0x00, 0x02, 0x00, 0x76, 0x00, 0x00, /* R20 - R27 */ |
| 219 | 0x04, 0x00, 0x00, 0x30, 0x2A, 0x00, 0x40, 0x00, /* R28 - R2F */ |
| 220 | 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, /* R30 - R37 */ |
| 221 | 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x00, 0x00, /* R38 - R3F */ |
| 222 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R40 - R4F */ |
| 223 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R48 - R4F */ |
| 224 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R50 - R57 */ |
| 225 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R58 - R5F */ |
| 226 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R60 - R67 */ |
| 227 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R68 - R6F */ |
| 228 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R70 - R77 */ |
| 229 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0x54, 0x00, /* R78 - R7F */ |
| 230 | 0x00, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x00, /* R80 - R87 */ |
| 231 | 0x00, /* R88 */ |
| 232 | }; |
| 233 | |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 234 | static int da7210_volatile_register(struct snd_soc_codec *codec, |
| 235 | unsigned int reg) |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 236 | { |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 237 | switch (reg) { |
| 238 | case DA7210_STATUS: |
| 239 | return 1; |
| 240 | default: |
| 241 | return 0; |
| 242 | } |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 243 | } |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 244 | static int da7210_startup(struct snd_pcm_substream *substream, |
| 245 | struct snd_soc_dai *dai) |
| 246 | { |
| 247 | int is_play = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; |
| 248 | struct snd_soc_codec *codec = dai->codec; |
| 249 | |
| 250 | if (is_play) { |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 251 | /* Enable Out */ |
| 252 | snd_soc_update_bits(codec, DA7210_OUTMIX_L, 0x1F, 0x10); |
| 253 | snd_soc_update_bits(codec, DA7210_OUTMIX_R, 0x1F, 0x10); |
| 254 | |
| 255 | } else { |
| 256 | /* Volume 7 */ |
| 257 | snd_soc_update_bits(codec, DA7210_MIC_L, 0x7, 0x7); |
| 258 | snd_soc_update_bits(codec, DA7210_MIC_R, 0x7, 0x7); |
| 259 | |
| 260 | /* Enable Mic */ |
| 261 | snd_soc_update_bits(codec, DA7210_INMIX_L, 0x1F, 0x1); |
| 262 | snd_soc_update_bits(codec, DA7210_INMIX_R, 0x1F, 0x1); |
| 263 | } |
| 264 | |
| 265 | return 0; |
| 266 | } |
| 267 | |
| 268 | /* |
| 269 | * Set PCM DAI word length. |
| 270 | */ |
| 271 | static int da7210_hw_params(struct snd_pcm_substream *substream, |
| 272 | struct snd_pcm_hw_params *params, |
| 273 | struct snd_soc_dai *dai) |
| 274 | { |
| 275 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 276 | struct snd_soc_codec *codec = rtd->codec; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 277 | u32 dai_cfg1; |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 278 | u32 hpf_reg, hpf_mask, hpf_value; |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 279 | u32 fs, bypass; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 280 | |
| 281 | /* set DAI source to Left and Right ADC */ |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 282 | snd_soc_write(codec, DA7210_DAI_SRC_SEL, |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 283 | DA7210_DAI_OUT_R_SRC | DA7210_DAI_OUT_L_SRC); |
| 284 | |
| 285 | /* Enable DAI */ |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 286 | snd_soc_write(codec, DA7210_DAI_CFG3, DA7210_DAI_OE | DA7210_DAI_EN); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 287 | |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 288 | dai_cfg1 = 0xFC & snd_soc_read(codec, DA7210_DAI_CFG1); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 289 | |
| 290 | switch (params_format(params)) { |
| 291 | case SNDRV_PCM_FORMAT_S16_LE: |
| 292 | dai_cfg1 |= DA7210_DAI_WORD_S16_LE; |
| 293 | break; |
Ashish Chavan | 0f8ea58 | 2011-10-12 20:33:21 +0530 | [diff] [blame] | 294 | case SNDRV_PCM_FORMAT_S20_3LE: |
| 295 | dai_cfg1 |= DA7210_DAI_WORD_S20_3LE; |
| 296 | break; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 297 | case SNDRV_PCM_FORMAT_S24_LE: |
| 298 | dai_cfg1 |= DA7210_DAI_WORD_S24_LE; |
| 299 | break; |
Ashish Chavan | 0f8ea58 | 2011-10-12 20:33:21 +0530 | [diff] [blame] | 300 | case SNDRV_PCM_FORMAT_S32_LE: |
| 301 | dai_cfg1 |= DA7210_DAI_WORD_S32_LE; |
| 302 | break; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 303 | default: |
| 304 | return -EINVAL; |
| 305 | } |
| 306 | |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 307 | snd_soc_write(codec, DA7210_DAI_CFG1, dai_cfg1); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 308 | |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 309 | hpf_reg = (SNDRV_PCM_STREAM_PLAYBACK == substream->stream) ? |
| 310 | DA7210_DAC_HPF : DA7210_ADC_HPF; |
| 311 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 312 | switch (params_rate(params)) { |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 313 | case 8000: |
| 314 | fs = DA7210_PLL_FS_8000; |
| 315 | hpf_mask = DA7210_VOICE_F0_MASK | DA7210_VOICE_EN; |
| 316 | hpf_value = DA7210_VOICE_F0_25 | DA7210_VOICE_EN; |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 317 | bypass = DA7210_PLL_BYP; |
| 318 | break; |
| 319 | case 11025: |
| 320 | fs = DA7210_PLL_FS_11025; |
| 321 | hpf_mask = DA7210_VOICE_F0_MASK | DA7210_VOICE_EN; |
| 322 | hpf_value = DA7210_VOICE_F0_25 | DA7210_VOICE_EN; |
| 323 | bypass = 0; |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 324 | break; |
| 325 | case 12000: |
| 326 | fs = DA7210_PLL_FS_12000; |
| 327 | hpf_mask = DA7210_VOICE_F0_MASK | DA7210_VOICE_EN; |
| 328 | hpf_value = DA7210_VOICE_F0_25 | DA7210_VOICE_EN; |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 329 | bypass = DA7210_PLL_BYP; |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 330 | break; |
| 331 | case 16000: |
| 332 | fs = DA7210_PLL_FS_16000; |
| 333 | hpf_mask = DA7210_VOICE_F0_MASK | DA7210_VOICE_EN; |
| 334 | hpf_value = DA7210_VOICE_F0_25 | DA7210_VOICE_EN; |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 335 | bypass = DA7210_PLL_BYP; |
| 336 | break; |
| 337 | case 22050: |
| 338 | fs = DA7210_PLL_FS_22050; |
| 339 | hpf_mask = DA7210_VOICE_EN; |
| 340 | hpf_value = 0; |
| 341 | bypass = 0; |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 342 | break; |
| 343 | case 32000: |
| 344 | fs = DA7210_PLL_FS_32000; |
| 345 | hpf_mask = DA7210_VOICE_EN; |
| 346 | hpf_value = 0; |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 347 | bypass = DA7210_PLL_BYP; |
| 348 | break; |
| 349 | case 44100: |
| 350 | fs = DA7210_PLL_FS_44100; |
| 351 | hpf_mask = DA7210_VOICE_EN; |
| 352 | hpf_value = 0; |
| 353 | bypass = 0; |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 354 | break; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 355 | case 48000: |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 356 | fs = DA7210_PLL_FS_48000; |
| 357 | hpf_mask = DA7210_VOICE_EN; |
| 358 | hpf_value = 0; |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 359 | bypass = DA7210_PLL_BYP; |
| 360 | break; |
| 361 | case 88200: |
| 362 | fs = DA7210_PLL_FS_88200; |
| 363 | hpf_mask = DA7210_VOICE_EN; |
| 364 | hpf_value = 0; |
| 365 | bypass = 0; |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 366 | break; |
| 367 | case 96000: |
| 368 | fs = DA7210_PLL_FS_96000; |
| 369 | hpf_mask = DA7210_VOICE_EN; |
| 370 | hpf_value = 0; |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 371 | bypass = DA7210_PLL_BYP; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 372 | break; |
| 373 | default: |
| 374 | return -EINVAL; |
| 375 | } |
| 376 | |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 377 | /* Disable active mode */ |
| 378 | snd_soc_update_bits(codec, DA7210_STARTUP1, DA7210_SC_MST_EN, 0); |
| 379 | |
Kuninori Morimoto | 3a9d620 | 2010-03-01 10:10:43 +0900 | [diff] [blame] | 380 | snd_soc_update_bits(codec, hpf_reg, hpf_mask, hpf_value); |
| 381 | snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_FS_MASK, fs); |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 382 | snd_soc_update_bits(codec, DA7210_PLL_DIV3, DA7210_PLL_BYP, bypass); |
| 383 | |
| 384 | /* Enable active mode */ |
| 385 | snd_soc_update_bits(codec, DA7210_STARTUP1, |
| 386 | DA7210_SC_MST_EN, DA7210_SC_MST_EN); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 387 | |
| 388 | return 0; |
| 389 | } |
| 390 | |
| 391 | /* |
| 392 | * Set DAI mode and Format |
| 393 | */ |
| 394 | static int da7210_set_dai_fmt(struct snd_soc_dai *codec_dai, u32 fmt) |
| 395 | { |
| 396 | struct snd_soc_codec *codec = codec_dai->codec; |
| 397 | u32 dai_cfg1; |
| 398 | u32 dai_cfg3; |
| 399 | |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 400 | dai_cfg1 = 0x7f & snd_soc_read(codec, DA7210_DAI_CFG1); |
| 401 | dai_cfg3 = 0xfc & snd_soc_read(codec, DA7210_DAI_CFG3); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 402 | |
| 403 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 404 | case SND_SOC_DAIFMT_CBM_CFM: |
| 405 | dai_cfg1 |= DA7210_DAI_MODE_MASTER; |
| 406 | break; |
Ashish Chavan | 0f8ea58 | 2011-10-12 20:33:21 +0530 | [diff] [blame] | 407 | case SND_SOC_DAIFMT_CBS_CFS: |
| 408 | dai_cfg1 |= DA7210_DAI_MODE_SLAVE; |
| 409 | break; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 410 | default: |
| 411 | return -EINVAL; |
| 412 | } |
| 413 | |
| 414 | /* FIXME |
| 415 | * |
| 416 | * It support I2S only now |
| 417 | */ |
| 418 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 419 | case SND_SOC_DAIFMT_I2S: |
| 420 | dai_cfg3 |= DA7210_DAI_FORMAT_I2SMODE; |
| 421 | break; |
Ashish Chavan | 0f8ea58 | 2011-10-12 20:33:21 +0530 | [diff] [blame] | 422 | case SND_SOC_DAIFMT_LEFT_J: |
| 423 | dai_cfg3 |= DA7210_DAI_FORMAT_LEFT_J; |
| 424 | break; |
| 425 | case SND_SOC_DAIFMT_RIGHT_J: |
| 426 | dai_cfg3 |= DA7210_DAI_FORMAT_RIGHT_J; |
| 427 | break; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 428 | default: |
| 429 | return -EINVAL; |
| 430 | } |
| 431 | |
| 432 | /* FIXME |
| 433 | * |
| 434 | * It support 64bit data transmission only now |
| 435 | */ |
| 436 | dai_cfg1 |= DA7210_DAI_FLEN_64BIT; |
| 437 | |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 438 | snd_soc_write(codec, DA7210_DAI_CFG1, dai_cfg1); |
| 439 | snd_soc_write(codec, DA7210_DAI_CFG3, dai_cfg3); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 440 | |
| 441 | return 0; |
| 442 | } |
| 443 | |
Ashish Chavan | 0f8ea58 | 2011-10-12 20:33:21 +0530 | [diff] [blame] | 444 | #define DA7210_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ |
| 445 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE) |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 446 | |
| 447 | /* DAI operations */ |
| 448 | static struct snd_soc_dai_ops da7210_dai_ops = { |
| 449 | .startup = da7210_startup, |
| 450 | .hw_params = da7210_hw_params, |
| 451 | .set_fmt = da7210_set_dai_fmt, |
| 452 | }; |
| 453 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 454 | static struct snd_soc_dai_driver da7210_dai = { |
| 455 | .name = "da7210-hifi", |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 456 | /* playback capabilities */ |
| 457 | .playback = { |
| 458 | .stream_name = "Playback", |
| 459 | .channels_min = 1, |
| 460 | .channels_max = 2, |
| 461 | .rates = SNDRV_PCM_RATE_8000_96000, |
| 462 | .formats = DA7210_FORMATS, |
| 463 | }, |
| 464 | /* capture capabilities */ |
| 465 | .capture = { |
| 466 | .stream_name = "Capture", |
| 467 | .channels_min = 1, |
| 468 | .channels_max = 2, |
| 469 | .rates = SNDRV_PCM_RATE_8000_96000, |
| 470 | .formats = DA7210_FORMATS, |
| 471 | }, |
| 472 | .ops = &da7210_dai_ops, |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 473 | .symmetric_rates = 1, |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 474 | }; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 475 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 476 | static int da7210_probe(struct snd_soc_codec *codec) |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 477 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 478 | struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec); |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 479 | int ret; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 480 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 481 | dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 482 | |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 483 | ret = snd_soc_codec_set_cache_io(codec, 8, 8, da7210->control_type); |
| 484 | if (ret < 0) { |
| 485 | dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); |
| 486 | return ret; |
| 487 | } |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 488 | |
| 489 | /* FIXME |
| 490 | * |
| 491 | * This driver use fixed value here |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 492 | * And below settings expects MCLK = 12.288MHz |
| 493 | * |
| 494 | * When you select different MCLK, please check... |
| 495 | * DA7210_PLL_DIV1 val |
| 496 | * DA7210_PLL_DIV2 val |
| 497 | * DA7210_PLL_DIV3 val |
| 498 | * DA7210_PLL_DIV3 :: DA7210_MCLK_RANGExxx |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 499 | */ |
| 500 | |
| 501 | /* |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 502 | * make sure that DA7210 use bypass mode before start up |
| 503 | */ |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 504 | snd_soc_write(codec, DA7210_STARTUP1, 0); |
| 505 | snd_soc_write(codec, DA7210_PLL_DIV3, |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 506 | DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP); |
| 507 | |
| 508 | /* |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 509 | * ADC settings |
| 510 | */ |
| 511 | |
| 512 | /* Enable Left & Right MIC PGA and Mic Bias */ |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 513 | snd_soc_write(codec, DA7210_MIC_L, DA7210_MIC_L_EN | DA7210_MICBIAS_EN); |
| 514 | snd_soc_write(codec, DA7210_MIC_R, DA7210_MIC_R_EN); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 515 | |
| 516 | /* Enable Left and Right input PGA */ |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 517 | snd_soc_write(codec, DA7210_INMIX_L, DA7210_IN_L_EN); |
| 518 | snd_soc_write(codec, DA7210_INMIX_R, DA7210_IN_R_EN); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 519 | |
| 520 | /* Enable Left and Right ADC */ |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 521 | snd_soc_write(codec, DA7210_ADC, DA7210_ADC_L_EN | DA7210_ADC_R_EN); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 522 | |
| 523 | /* |
| 524 | * DAC settings |
| 525 | */ |
| 526 | |
| 527 | /* Enable Left and Right DAC */ |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 528 | snd_soc_write(codec, DA7210_DAC_SEL, |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 529 | DA7210_DAC_L_SRC_DAI_L | DA7210_DAC_L_EN | |
| 530 | DA7210_DAC_R_SRC_DAI_R | DA7210_DAC_R_EN); |
| 531 | |
| 532 | /* Enable Left and Right out PGA */ |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 533 | snd_soc_write(codec, DA7210_OUTMIX_L, DA7210_OUT_L_EN); |
| 534 | snd_soc_write(codec, DA7210_OUTMIX_R, DA7210_OUT_R_EN); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 535 | |
| 536 | /* Enable Left and Right HeadPhone PGA */ |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 537 | snd_soc_write(codec, DA7210_HP_CFG, |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 538 | DA7210_HP_2CAP_MODE | DA7210_HP_SENSE_EN | |
| 539 | DA7210_HP_L_EN | DA7210_HP_MODE | DA7210_HP_R_EN); |
| 540 | |
| 541 | /* Diable PLL and bypass it */ |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 542 | snd_soc_write(codec, DA7210_PLL, DA7210_PLL_FS_48000); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 543 | |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 544 | /* |
| 545 | * If 48kHz sound came, it use bypass mode, |
| 546 | * and when it is 44.1kHz, it use PLL. |
| 547 | * |
| 548 | * This time, this driver sets PLL always ON |
| 549 | * and controls bypass/PLL mode by switching |
| 550 | * DA7210_PLL_DIV3 :: DA7210_PLL_BYP bit. |
| 551 | * see da7210_hw_params |
| 552 | */ |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 553 | snd_soc_write(codec, DA7210_PLL_DIV1, 0xE5); /* MCLK = 12.288MHz */ |
| 554 | snd_soc_write(codec, DA7210_PLL_DIV2, 0x99); |
| 555 | snd_soc_write(codec, DA7210_PLL_DIV3, 0x0A | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 556 | DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP); |
Kuninori Morimoto | 960b3b4 | 2010-03-11 11:37:44 +0900 | [diff] [blame] | 557 | snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_EN, DA7210_PLL_EN); |
| 558 | |
| 559 | /* As suggested by Dialog */ |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 560 | snd_soc_write(codec, DA7210_A_HID_UNLOCK, 0x8B); /* unlock */ |
| 561 | snd_soc_write(codec, DA7210_A_TEST_UNLOCK, 0xB4); |
| 562 | snd_soc_write(codec, DA7210_A_PLL1, 0x01); |
| 563 | snd_soc_write(codec, DA7210_A_CP_MODE, 0x7C); |
| 564 | snd_soc_write(codec, DA7210_A_HID_UNLOCK, 0x00); /* re-lock */ |
| 565 | snd_soc_write(codec, DA7210_A_TEST_UNLOCK, 0x00); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 566 | |
| 567 | /* Activate all enabled subsystem */ |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 568 | snd_soc_write(codec, DA7210_STARTUP1, DA7210_SC_MST_EN); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 569 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 570 | dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 571 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 572 | return 0; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 573 | } |
| 574 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 575 | static struct snd_soc_codec_driver soc_codec_dev_da7210 = { |
Kuninori Morimoto | 4c62ed9 | 2010-09-16 13:07:06 +0900 | [diff] [blame] | 576 | .probe = da7210_probe, |
Kuninori Morimoto | 4c62ed9 | 2010-09-16 13:07:06 +0900 | [diff] [blame] | 577 | .reg_cache_size = ARRAY_SIZE(da7210_reg), |
| 578 | .reg_word_size = sizeof(u8), |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 579 | .reg_cache_default = da7210_reg, |
Axel Lin | 40a4971 | 2011-10-12 07:16:25 +0800 | [diff] [blame] | 580 | .volatile_register = da7210_volatile_register, |
Mark Brown | a6f096f | 2011-10-14 20:18:49 +0100 | [diff] [blame] | 581 | |
| 582 | .controls = da7210_snd_controls, |
| 583 | .num_controls = ARRAY_SIZE(da7210_snd_controls), |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 584 | }; |
| 585 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 586 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
Mark Brown | 735fe4c | 2010-01-12 14:13:00 +0000 | [diff] [blame] | 587 | static int __devinit da7210_i2c_probe(struct i2c_client *i2c, |
| 588 | const struct i2c_device_id *id) |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 589 | { |
| 590 | struct da7210_priv *da7210; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 591 | int ret; |
| 592 | |
| 593 | da7210 = kzalloc(sizeof(struct da7210_priv), GFP_KERNEL); |
| 594 | if (!da7210) |
| 595 | return -ENOMEM; |
| 596 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 597 | i2c_set_clientdata(i2c, da7210); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 598 | da7210->control_type = SND_SOC_I2C; |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 599 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 600 | ret = snd_soc_register_codec(&i2c->dev, |
| 601 | &soc_codec_dev_da7210, &da7210_dai, 1); |
| 602 | if (ret < 0) |
Axel Lin | 085efd2 | 2010-07-23 05:53:45 +0000 | [diff] [blame] | 603 | kfree(da7210); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 604 | |
| 605 | return ret; |
| 606 | } |
| 607 | |
Mark Brown | 735fe4c | 2010-01-12 14:13:00 +0000 | [diff] [blame] | 608 | static int __devexit da7210_i2c_remove(struct i2c_client *client) |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 609 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 610 | snd_soc_unregister_codec(&client->dev); |
| 611 | kfree(i2c_get_clientdata(client)); |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 612 | return 0; |
| 613 | } |
| 614 | |
| 615 | static const struct i2c_device_id da7210_i2c_id[] = { |
| 616 | { "da7210", 0 }, |
| 617 | { } |
| 618 | }; |
| 619 | MODULE_DEVICE_TABLE(i2c, da7210_i2c_id); |
| 620 | |
| 621 | /* I2C codec control layer */ |
| 622 | static struct i2c_driver da7210_i2c_driver = { |
| 623 | .driver = { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 624 | .name = "da7210-codec", |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 625 | .owner = THIS_MODULE, |
| 626 | }, |
Kuninori Morimoto | 4c62ed9 | 2010-09-16 13:07:06 +0900 | [diff] [blame] | 627 | .probe = da7210_i2c_probe, |
| 628 | .remove = __devexit_p(da7210_i2c_remove), |
| 629 | .id_table = da7210_i2c_id, |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 630 | }; |
| 631 | #endif |
| 632 | |
Kuninori Morimoto | 9861545 | 2009-12-14 13:21:56 +0900 | [diff] [blame] | 633 | static int __init da7210_modinit(void) |
| 634 | { |
| 635 | int ret = 0; |
| 636 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
| 637 | ret = i2c_add_driver(&da7210_i2c_driver); |
| 638 | #endif |
| 639 | return ret; |
| 640 | } |
| 641 | module_init(da7210_modinit); |
| 642 | |
| 643 | static void __exit da7210_exit(void) |
| 644 | { |
| 645 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
| 646 | i2c_del_driver(&da7210_i2c_driver); |
| 647 | #endif |
| 648 | } |
| 649 | module_exit(da7210_exit); |
| 650 | |
| 651 | MODULE_DESCRIPTION("ASoC DA7210 driver"); |
| 652 | MODULE_AUTHOR("David Chen, Kuninori Morimoto"); |
| 653 | MODULE_LICENSE("GPL"); |