Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1 | /* |
| 2 | * wm8753.c -- WM8753 ALSA Soc Audio driver |
| 3 | * |
| 4 | * Copyright 2003 Wolfson Microelectronics PLC. |
Liam Girdwood | d331124 | 2008-10-12 13:17:36 +0100 | [diff] [blame] | 5 | * Author: Liam Girdwood <lrg@slimlogic.co.uk> |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License as published by the |
| 9 | * Free Software Foundation; either version 2 of the License, or (at your |
| 10 | * option) any later version. |
| 11 | * |
| 12 | * Notes: |
| 13 | * The WM8753 is a low power, high quality stereo codec with integrated PCM |
| 14 | * codec designed for portable digital telephony applications. |
| 15 | * |
| 16 | * Dual DAI:- |
| 17 | * |
| 18 | * This driver support 2 DAI PCM's. This makes the default PCM available for |
| 19 | * HiFi audio (e.g. MP3, ogg) playback/capture and the other PCM available for |
| 20 | * voice. |
| 21 | * |
| 22 | * Please note that the voice PCM can be connected directly to a Bluetooth |
| 23 | * codec or GSM modem and thus cannot be read or written to, although it is |
| 24 | * available to be configured with snd_hw_params(), etc and kcontrols in the |
| 25 | * normal alsa manner. |
| 26 | * |
| 27 | * Fast DAI switching:- |
| 28 | * |
| 29 | * The driver can now fast switch between the DAI configurations via a |
| 30 | * an alsa kcontrol. This allows the PCM to remain open. |
| 31 | * |
| 32 | */ |
| 33 | |
| 34 | #include <linux/module.h> |
| 35 | #include <linux/moduleparam.h> |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 36 | #include <linux/kernel.h> |
| 37 | #include <linux/init.h> |
| 38 | #include <linux/delay.h> |
| 39 | #include <linux/pm.h> |
| 40 | #include <linux/i2c.h> |
| 41 | #include <linux/platform_device.h> |
Mark Brown | dd0c0c8 | 2008-10-06 16:54:34 +0100 | [diff] [blame] | 42 | #include <linux/spi/spi.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 43 | #include <linux/slab.h> |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 44 | #include <sound/core.h> |
| 45 | #include <sound/pcm.h> |
| 46 | #include <sound/pcm_params.h> |
| 47 | #include <sound/soc.h> |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 48 | #include <sound/initval.h> |
Liam Girdwood | 2d6a4ac | 2008-01-10 14:43:48 +0100 | [diff] [blame] | 49 | #include <sound/tlv.h> |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 50 | #include <asm/div64.h> |
| 51 | |
| 52 | #include "wm8753.h" |
| 53 | |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 54 | static int caps_charge = 2000; |
| 55 | module_param(caps_charge, int, 0); |
| 56 | MODULE_PARM_DESC(caps_charge, "WM8753 cap charge time (msecs)"); |
| 57 | |
| 58 | static void wm8753_set_dai_mode(struct snd_soc_codec *codec, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 59 | struct snd_soc_dai *dai, unsigned int hifi); |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 60 | |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 61 | /* |
| 62 | * wm8753 register cache |
| 63 | * We can't read the WM8753 register space when we |
| 64 | * are using 2 wire for device control, so we cache them instead. |
| 65 | */ |
| 66 | static const u16 wm8753_reg[] = { |
| 67 | 0x0008, 0x0000, 0x000a, 0x000a, |
| 68 | 0x0033, 0x0000, 0x0007, 0x00ff, |
| 69 | 0x00ff, 0x000f, 0x000f, 0x007b, |
| 70 | 0x0000, 0x0032, 0x0000, 0x00c3, |
| 71 | 0x00c3, 0x00c0, 0x0000, 0x0000, |
| 72 | 0x0000, 0x0000, 0x0000, 0x0000, |
| 73 | 0x0000, 0x0000, 0x0000, 0x0000, |
| 74 | 0x0000, 0x0000, 0x0000, 0x0055, |
| 75 | 0x0005, 0x0050, 0x0055, 0x0050, |
| 76 | 0x0055, 0x0050, 0x0055, 0x0079, |
| 77 | 0x0079, 0x0079, 0x0079, 0x0079, |
| 78 | 0x0000, 0x0000, 0x0000, 0x0000, |
| 79 | 0x0097, 0x0097, 0x0000, 0x0004, |
| 80 | 0x0000, 0x0083, 0x0024, 0x01ba, |
| 81 | 0x0000, 0x0083, 0x0024, 0x01ba, |
Lars-Peter Clausen | 637a935 | 2009-07-03 01:04:16 +0200 | [diff] [blame] | 82 | 0x0000, 0x0000, 0x0000 |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 83 | }; |
| 84 | |
Mark Brown | c2bac16 | 2009-02-24 23:33:12 +0000 | [diff] [blame] | 85 | /* codec private data */ |
| 86 | struct wm8753_priv { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 87 | enum snd_soc_control_type control_type; |
Mark Brown | c2bac16 | 2009-02-24 23:33:12 +0000 | [diff] [blame] | 88 | unsigned int sysclk; |
| 89 | unsigned int pcmclk; |
Mark Brown | c2bac16 | 2009-02-24 23:33:12 +0000 | [diff] [blame] | 90 | u16 reg_cache[ARRAY_SIZE(wm8753_reg)]; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 91 | int dai_func; |
Mark Brown | c2bac16 | 2009-02-24 23:33:12 +0000 | [diff] [blame] | 92 | }; |
| 93 | |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 94 | /* |
| 95 | * read wm8753 register cache |
| 96 | */ |
| 97 | static inline unsigned int wm8753_read_reg_cache(struct snd_soc_codec *codec, |
| 98 | unsigned int reg) |
| 99 | { |
| 100 | u16 *cache = codec->reg_cache; |
Ian Molton | 91432e9 | 2009-01-17 17:44:23 +0000 | [diff] [blame] | 101 | if (reg < 1 || reg >= (ARRAY_SIZE(wm8753_reg) + 1)) |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 102 | return -1; |
| 103 | return cache[reg - 1]; |
| 104 | } |
| 105 | |
| 106 | /* |
| 107 | * write wm8753 register cache |
| 108 | */ |
| 109 | static inline void wm8753_write_reg_cache(struct snd_soc_codec *codec, |
| 110 | unsigned int reg, unsigned int value) |
| 111 | { |
| 112 | u16 *cache = codec->reg_cache; |
Ian Molton | 91432e9 | 2009-01-17 17:44:23 +0000 | [diff] [blame] | 113 | if (reg < 1 || reg >= (ARRAY_SIZE(wm8753_reg) + 1)) |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 114 | return; |
| 115 | cache[reg - 1] = value; |
| 116 | } |
| 117 | |
| 118 | /* |
| 119 | * write to the WM8753 register space |
| 120 | */ |
| 121 | static int wm8753_write(struct snd_soc_codec *codec, unsigned int reg, |
| 122 | unsigned int value) |
| 123 | { |
| 124 | u8 data[2]; |
| 125 | |
| 126 | /* data is |
| 127 | * D15..D9 WM8753 register offset |
| 128 | * D8...D0 register data |
| 129 | */ |
| 130 | data[0] = (reg << 1) | ((value >> 8) & 0x0001); |
| 131 | data[1] = value & 0x00ff; |
| 132 | |
Mark Brown | 60fc684 | 2008-04-30 17:18:43 +0200 | [diff] [blame] | 133 | wm8753_write_reg_cache(codec, reg, value); |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 134 | if (codec->hw_write(codec->control_data, data, 2) == 2) |
| 135 | return 0; |
| 136 | else |
| 137 | return -EIO; |
| 138 | } |
| 139 | |
| 140 | #define wm8753_reset(c) wm8753_write(c, WM8753_RESET, 0) |
| 141 | |
| 142 | /* |
| 143 | * WM8753 Controls |
| 144 | */ |
| 145 | static const char *wm8753_base[] = {"Linear Control", "Adaptive Boost"}; |
| 146 | static const char *wm8753_base_filter[] = |
| 147 | {"130Hz @ 48kHz", "200Hz @ 48kHz", "100Hz @ 16kHz", "400Hz @ 48kHz", |
| 148 | "100Hz @ 8kHz", "200Hz @ 8kHz"}; |
| 149 | static const char *wm8753_treble[] = {"8kHz", "4kHz"}; |
| 150 | static const char *wm8753_alc_func[] = {"Off", "Right", "Left", "Stereo"}; |
| 151 | static const char *wm8753_ng_type[] = {"Constant PGA Gain", "Mute ADC Output"}; |
| 152 | static const char *wm8753_3d_func[] = {"Capture", "Playback"}; |
| 153 | static const char *wm8753_3d_uc[] = {"2.2kHz", "1.5kHz"}; |
| 154 | static const char *wm8753_3d_lc[] = {"200Hz", "500Hz"}; |
| 155 | static const char *wm8753_deemp[] = {"None", "32kHz", "44.1kHz", "48kHz"}; |
| 156 | static const char *wm8753_mono_mix[] = {"Stereo", "Left", "Right", "Mono"}; |
| 157 | static const char *wm8753_dac_phase[] = {"Non Inverted", "Inverted"}; |
| 158 | static const char *wm8753_line_mix[] = {"Line 1 + 2", "Line 1 - 2", |
| 159 | "Line 1", "Line 2"}; |
| 160 | static const char *wm8753_mono_mux[] = {"Line Mix", "Rx Mix"}; |
| 161 | static const char *wm8753_right_mux[] = {"Line 2", "Rx Mix"}; |
| 162 | static const char *wm8753_left_mux[] = {"Line 1", "Rx Mix"}; |
| 163 | static const char *wm8753_rxmsel[] = {"RXP - RXN", "RXP + RXN", "RXP", "RXN"}; |
| 164 | static const char *wm8753_sidetone_mux[] = {"Left PGA", "Mic 1", "Mic 2", |
| 165 | "Right PGA"}; |
| 166 | static const char *wm8753_mono2_src[] = {"Inverted Mono 1", "Left", "Right", |
| 167 | "Left + Right"}; |
| 168 | static const char *wm8753_out3[] = {"VREF", "ROUT2", "Left + Right"}; |
| 169 | static const char *wm8753_out4[] = {"VREF", "Capture ST", "LOUT2"}; |
| 170 | static const char *wm8753_radcsel[] = {"PGA", "Line or RXP-RXN", "Sidetone"}; |
| 171 | static const char *wm8753_ladcsel[] = {"PGA", "Line or RXP-RXN", "Line"}; |
| 172 | static const char *wm8753_mono_adc[] = {"Stereo", "Analogue Mix Left", |
| 173 | "Analogue Mix Right", "Digital Mono Mix"}; |
| 174 | static const char *wm8753_adc_hp[] = {"3.4Hz @ 48kHz", "82Hz @ 16k", |
| 175 | "82Hz @ 8kHz", "170Hz @ 8kHz"}; |
| 176 | static const char *wm8753_adc_filter[] = {"HiFi", "Voice"}; |
| 177 | static const char *wm8753_mic_sel[] = {"Mic 1", "Mic 2", "Mic 3"}; |
| 178 | static const char *wm8753_dai_mode[] = {"DAI 0", "DAI 1", "DAI 2", "DAI 3"}; |
| 179 | static const char *wm8753_dat_sel[] = {"Stereo", "Left ADC", "Right ADC", |
| 180 | "Channel Swap"}; |
Graeme Gregory | ae092c9 | 2008-03-03 17:19:45 +0100 | [diff] [blame] | 181 | static const char *wm8753_rout2_phase[] = {"Non Inverted", "Inverted"}; |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 182 | |
| 183 | static const struct soc_enum wm8753_enum[] = { |
| 184 | SOC_ENUM_SINGLE(WM8753_BASS, 7, 2, wm8753_base), |
| 185 | SOC_ENUM_SINGLE(WM8753_BASS, 4, 6, wm8753_base_filter), |
| 186 | SOC_ENUM_SINGLE(WM8753_TREBLE, 6, 2, wm8753_treble), |
| 187 | SOC_ENUM_SINGLE(WM8753_ALC1, 7, 4, wm8753_alc_func), |
| 188 | SOC_ENUM_SINGLE(WM8753_NGATE, 1, 2, wm8753_ng_type), |
| 189 | SOC_ENUM_SINGLE(WM8753_3D, 7, 2, wm8753_3d_func), |
| 190 | SOC_ENUM_SINGLE(WM8753_3D, 6, 2, wm8753_3d_uc), |
| 191 | SOC_ENUM_SINGLE(WM8753_3D, 5, 2, wm8753_3d_lc), |
| 192 | SOC_ENUM_SINGLE(WM8753_DAC, 1, 4, wm8753_deemp), |
| 193 | SOC_ENUM_SINGLE(WM8753_DAC, 4, 4, wm8753_mono_mix), |
| 194 | SOC_ENUM_SINGLE(WM8753_DAC, 6, 2, wm8753_dac_phase), |
| 195 | SOC_ENUM_SINGLE(WM8753_INCTL1, 3, 4, wm8753_line_mix), |
| 196 | SOC_ENUM_SINGLE(WM8753_INCTL1, 2, 2, wm8753_mono_mux), |
| 197 | SOC_ENUM_SINGLE(WM8753_INCTL1, 1, 2, wm8753_right_mux), |
| 198 | SOC_ENUM_SINGLE(WM8753_INCTL1, 0, 2, wm8753_left_mux), |
| 199 | SOC_ENUM_SINGLE(WM8753_INCTL2, 6, 4, wm8753_rxmsel), |
| 200 | SOC_ENUM_SINGLE(WM8753_INCTL2, 4, 4, wm8753_sidetone_mux), |
| 201 | SOC_ENUM_SINGLE(WM8753_OUTCTL, 7, 4, wm8753_mono2_src), |
| 202 | SOC_ENUM_SINGLE(WM8753_OUTCTL, 0, 3, wm8753_out3), |
| 203 | SOC_ENUM_SINGLE(WM8753_ADCTL2, 7, 3, wm8753_out4), |
| 204 | SOC_ENUM_SINGLE(WM8753_ADCIN, 2, 3, wm8753_radcsel), |
| 205 | SOC_ENUM_SINGLE(WM8753_ADCIN, 0, 3, wm8753_ladcsel), |
| 206 | SOC_ENUM_SINGLE(WM8753_ADCIN, 4, 4, wm8753_mono_adc), |
| 207 | SOC_ENUM_SINGLE(WM8753_ADC, 2, 4, wm8753_adc_hp), |
| 208 | SOC_ENUM_SINGLE(WM8753_ADC, 4, 2, wm8753_adc_filter), |
| 209 | SOC_ENUM_SINGLE(WM8753_MICBIAS, 6, 3, wm8753_mic_sel), |
| 210 | SOC_ENUM_SINGLE(WM8753_IOCTL, 2, 4, wm8753_dai_mode), |
| 211 | SOC_ENUM_SINGLE(WM8753_ADC, 7, 4, wm8753_dat_sel), |
Graeme Gregory | ae092c9 | 2008-03-03 17:19:45 +0100 | [diff] [blame] | 212 | SOC_ENUM_SINGLE(WM8753_OUTCTL, 2, 2, wm8753_rout2_phase), |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 213 | }; |
| 214 | |
| 215 | |
| 216 | static int wm8753_get_dai(struct snd_kcontrol *kcontrol, |
| 217 | struct snd_ctl_elem_value *ucontrol) |
| 218 | { |
| 219 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 220 | int mode = wm8753_read_reg_cache(codec, WM8753_IOCTL); |
| 221 | |
| 222 | ucontrol->value.integer.value[0] = (mode & 0xc) >> 2; |
| 223 | return 0; |
| 224 | } |
| 225 | |
| 226 | static int wm8753_set_dai(struct snd_kcontrol *kcontrol, |
| 227 | struct snd_ctl_elem_value *ucontrol) |
| 228 | { |
| 229 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 230 | int mode = wm8753_read_reg_cache(codec, WM8753_IOCTL); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 231 | struct wm8753_priv *wm8753 = snd_soc_codec_get_drvdata(codec); |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 232 | |
Mark Brown | 60fc684 | 2008-04-30 17:18:43 +0200 | [diff] [blame] | 233 | if (((mode & 0xc) >> 2) == ucontrol->value.integer.value[0]) |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 234 | return 0; |
| 235 | |
| 236 | mode &= 0xfff3; |
| 237 | mode |= (ucontrol->value.integer.value[0] << 2); |
| 238 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 239 | wm8753->dai_func = ucontrol->value.integer.value[0]; |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 240 | return 1; |
| 241 | } |
| 242 | |
Mike Montour | 2cc8c60 | 2008-06-11 13:47:12 +0100 | [diff] [blame] | 243 | static const DECLARE_TLV_DB_SCALE(rec_mix_tlv, -1500, 300, 0); |
| 244 | static const DECLARE_TLV_DB_SCALE(mic_preamp_tlv, 1200, 600, 0); |
| 245 | static const DECLARE_TLV_DB_SCALE(adc_tlv, -9750, 50, 1); |
| 246 | static const DECLARE_TLV_DB_SCALE(dac_tlv, -12750, 50, 1); |
| 247 | static const unsigned int out_tlv[] = { |
| 248 | TLV_DB_RANGE_HEAD(2), |
| 249 | /* 0000000 - 0101111 = "Analogue mute" */ |
| 250 | 0, 48, TLV_DB_SCALE_ITEM(-25500, 0, 0), |
| 251 | 48, 127, TLV_DB_SCALE_ITEM(-7300, 100, 0), |
| 252 | }; |
| 253 | static const DECLARE_TLV_DB_SCALE(mix_tlv, -1500, 300, 0); |
| 254 | static const DECLARE_TLV_DB_SCALE(voice_mix_tlv, -1200, 300, 0); |
| 255 | static const DECLARE_TLV_DB_SCALE(pga_tlv, -1725, 75, 0); |
Liam Girdwood | 2d6a4ac | 2008-01-10 14:43:48 +0100 | [diff] [blame] | 256 | |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 257 | static const struct snd_kcontrol_new wm8753_snd_controls[] = { |
Mike Montour | 2cc8c60 | 2008-06-11 13:47:12 +0100 | [diff] [blame] | 258 | SOC_DOUBLE_R_TLV("PCM Volume", WM8753_LDAC, WM8753_RDAC, 0, 255, 0, dac_tlv), |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 259 | |
Mike Montour | 2cc8c60 | 2008-06-11 13:47:12 +0100 | [diff] [blame] | 260 | SOC_DOUBLE_R_TLV("ADC Capture Volume", WM8753_LADC, WM8753_RADC, 0, 255, 0, |
| 261 | adc_tlv), |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 262 | |
Mike Montour | 2cc8c60 | 2008-06-11 13:47:12 +0100 | [diff] [blame] | 263 | SOC_DOUBLE_R_TLV("Headphone Playback Volume", WM8753_LOUT1V, WM8753_ROUT1V, |
| 264 | 0, 127, 0, out_tlv), |
| 265 | SOC_DOUBLE_R_TLV("Speaker Playback Volume", WM8753_LOUT2V, WM8753_ROUT2V, 0, |
| 266 | 127, 0, out_tlv), |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 267 | |
Mike Montour | 2cc8c60 | 2008-06-11 13:47:12 +0100 | [diff] [blame] | 268 | SOC_SINGLE_TLV("Mono Playback Volume", WM8753_MOUTV, 0, 127, 0, out_tlv), |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 269 | |
Mike Montour | 2cc8c60 | 2008-06-11 13:47:12 +0100 | [diff] [blame] | 270 | SOC_DOUBLE_R_TLV("Bypass Playback Volume", WM8753_LOUTM1, WM8753_ROUTM1, 4, 7, |
| 271 | 1, mix_tlv), |
| 272 | SOC_DOUBLE_R_TLV("Sidetone Playback Volume", WM8753_LOUTM2, WM8753_ROUTM2, 4, |
| 273 | 7, 1, mix_tlv), |
| 274 | SOC_DOUBLE_R_TLV("Voice Playback Volume", WM8753_LOUTM2, WM8753_ROUTM2, 0, 7, |
| 275 | 1, voice_mix_tlv), |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 276 | |
Mike Montour | 2cc8c60 | 2008-06-11 13:47:12 +0100 | [diff] [blame] | 277 | SOC_DOUBLE_R("Headphone Playback ZC Switch", WM8753_LOUT1V, WM8753_ROUT1V, 7, |
| 278 | 1, 0), |
| 279 | SOC_DOUBLE_R("Speaker Playback ZC Switch", WM8753_LOUT2V, WM8753_ROUT2V, 7, |
| 280 | 1, 0), |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 281 | |
Mike Montour | 2cc8c60 | 2008-06-11 13:47:12 +0100 | [diff] [blame] | 282 | SOC_SINGLE_TLV("Mono Bypass Playback Volume", WM8753_MOUTM1, 4, 7, 1, mix_tlv), |
| 283 | SOC_SINGLE_TLV("Mono Sidetone Playback Volume", WM8753_MOUTM2, 4, 7, 1, |
| 284 | mix_tlv), |
| 285 | SOC_SINGLE_TLV("Mono Voice Playback Volume", WM8753_MOUTM2, 0, 7, 1, |
| 286 | voice_mix_tlv), |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 287 | SOC_SINGLE("Mono Playback ZC Switch", WM8753_MOUTV, 7, 1, 0), |
| 288 | |
| 289 | SOC_ENUM("Bass Boost", wm8753_enum[0]), |
| 290 | SOC_ENUM("Bass Filter", wm8753_enum[1]), |
| 291 | SOC_SINGLE("Bass Volume", WM8753_BASS, 0, 15, 1), |
| 292 | |
| 293 | SOC_SINGLE("Treble Volume", WM8753_TREBLE, 0, 15, 1), |
| 294 | SOC_ENUM("Treble Cut-off", wm8753_enum[2]), |
| 295 | |
Mike Montour | 2cc8c60 | 2008-06-11 13:47:12 +0100 | [diff] [blame] | 296 | SOC_DOUBLE_TLV("Sidetone Capture Volume", WM8753_RECMIX1, 0, 4, 7, 1, |
| 297 | rec_mix_tlv), |
| 298 | SOC_SINGLE_TLV("Voice Sidetone Capture Volume", WM8753_RECMIX2, 0, 7, 1, |
| 299 | rec_mix_tlv), |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 300 | |
Mike Montour | 2cc8c60 | 2008-06-11 13:47:12 +0100 | [diff] [blame] | 301 | SOC_DOUBLE_R_TLV("Capture Volume", WM8753_LINVOL, WM8753_RINVOL, 0, 63, 0, |
| 302 | pga_tlv), |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 303 | SOC_DOUBLE_R("Capture ZC Switch", WM8753_LINVOL, WM8753_RINVOL, 6, 1, 0), |
| 304 | SOC_DOUBLE_R("Capture Switch", WM8753_LINVOL, WM8753_RINVOL, 7, 1, 1), |
| 305 | |
| 306 | SOC_ENUM("Capture Filter Select", wm8753_enum[23]), |
| 307 | SOC_ENUM("Capture Filter Cut-off", wm8753_enum[24]), |
| 308 | SOC_SINGLE("Capture Filter Switch", WM8753_ADC, 0, 1, 1), |
| 309 | |
| 310 | SOC_SINGLE("ALC Capture Target Volume", WM8753_ALC1, 0, 7, 0), |
| 311 | SOC_SINGLE("ALC Capture Max Volume", WM8753_ALC1, 4, 7, 0), |
| 312 | SOC_ENUM("ALC Capture Function", wm8753_enum[3]), |
| 313 | SOC_SINGLE("ALC Capture ZC Switch", WM8753_ALC2, 8, 1, 0), |
| 314 | SOC_SINGLE("ALC Capture Hold Time", WM8753_ALC2, 0, 15, 1), |
| 315 | SOC_SINGLE("ALC Capture Decay Time", WM8753_ALC3, 4, 15, 1), |
| 316 | SOC_SINGLE("ALC Capture Attack Time", WM8753_ALC3, 0, 15, 0), |
| 317 | SOC_SINGLE("ALC Capture NG Threshold", WM8753_NGATE, 3, 31, 0), |
| 318 | SOC_ENUM("ALC Capture NG Type", wm8753_enum[4]), |
| 319 | SOC_SINGLE("ALC Capture NG Switch", WM8753_NGATE, 0, 1, 0), |
| 320 | |
| 321 | SOC_ENUM("3D Function", wm8753_enum[5]), |
| 322 | SOC_ENUM("3D Upper Cut-off", wm8753_enum[6]), |
| 323 | SOC_ENUM("3D Lower Cut-off", wm8753_enum[7]), |
| 324 | SOC_SINGLE("3D Volume", WM8753_3D, 1, 15, 0), |
| 325 | SOC_SINGLE("3D Switch", WM8753_3D, 0, 1, 0), |
| 326 | |
| 327 | SOC_SINGLE("Capture 6dB Attenuate", WM8753_ADCTL1, 2, 1, 0), |
| 328 | SOC_SINGLE("Playback 6dB Attenuate", WM8753_ADCTL1, 1, 1, 0), |
| 329 | |
| 330 | SOC_ENUM("De-emphasis", wm8753_enum[8]), |
| 331 | SOC_ENUM("Playback Mono Mix", wm8753_enum[9]), |
| 332 | SOC_ENUM("Playback Phase", wm8753_enum[10]), |
| 333 | |
Mike Montour | 2cc8c60 | 2008-06-11 13:47:12 +0100 | [diff] [blame] | 334 | SOC_SINGLE_TLV("Mic2 Capture Volume", WM8753_INCTL1, 7, 3, 0, mic_preamp_tlv), |
| 335 | SOC_SINGLE_TLV("Mic1 Capture Volume", WM8753_INCTL1, 5, 3, 0, mic_preamp_tlv), |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 336 | |
| 337 | SOC_ENUM_EXT("DAI Mode", wm8753_enum[26], wm8753_get_dai, wm8753_set_dai), |
| 338 | |
| 339 | SOC_ENUM("ADC Data Select", wm8753_enum[27]), |
Graeme Gregory | ae092c9 | 2008-03-03 17:19:45 +0100 | [diff] [blame] | 340 | SOC_ENUM("ROUT2 Phase", wm8753_enum[28]), |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 341 | }; |
| 342 | |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 343 | /* |
| 344 | * _DAPM_ Controls |
| 345 | */ |
| 346 | |
| 347 | /* Left Mixer */ |
| 348 | static const struct snd_kcontrol_new wm8753_left_mixer_controls[] = { |
| 349 | SOC_DAPM_SINGLE("Voice Playback Switch", WM8753_LOUTM2, 8, 1, 0), |
| 350 | SOC_DAPM_SINGLE("Sidetone Playback Switch", WM8753_LOUTM2, 7, 1, 0), |
| 351 | SOC_DAPM_SINGLE("Left Playback Switch", WM8753_LOUTM1, 8, 1, 0), |
| 352 | SOC_DAPM_SINGLE("Bypass Playback Switch", WM8753_LOUTM1, 7, 1, 0), |
| 353 | }; |
| 354 | |
| 355 | /* Right mixer */ |
| 356 | static const struct snd_kcontrol_new wm8753_right_mixer_controls[] = { |
| 357 | SOC_DAPM_SINGLE("Voice Playback Switch", WM8753_ROUTM2, 8, 1, 0), |
| 358 | SOC_DAPM_SINGLE("Sidetone Playback Switch", WM8753_ROUTM2, 7, 1, 0), |
| 359 | SOC_DAPM_SINGLE("Right Playback Switch", WM8753_ROUTM1, 8, 1, 0), |
| 360 | SOC_DAPM_SINGLE("Bypass Playback Switch", WM8753_ROUTM1, 7, 1, 0), |
| 361 | }; |
| 362 | |
| 363 | /* Mono mixer */ |
| 364 | static const struct snd_kcontrol_new wm8753_mono_mixer_controls[] = { |
| 365 | SOC_DAPM_SINGLE("Left Playback Switch", WM8753_MOUTM1, 8, 1, 0), |
| 366 | SOC_DAPM_SINGLE("Right Playback Switch", WM8753_MOUTM2, 8, 1, 0), |
| 367 | SOC_DAPM_SINGLE("Voice Playback Switch", WM8753_MOUTM2, 3, 1, 0), |
| 368 | SOC_DAPM_SINGLE("Sidetone Playback Switch", WM8753_MOUTM2, 7, 1, 0), |
| 369 | SOC_DAPM_SINGLE("Bypass Playback Switch", WM8753_MOUTM1, 7, 1, 0), |
| 370 | }; |
| 371 | |
| 372 | /* Mono 2 Mux */ |
| 373 | static const struct snd_kcontrol_new wm8753_mono2_controls = |
| 374 | SOC_DAPM_ENUM("Route", wm8753_enum[17]); |
| 375 | |
| 376 | /* Out 3 Mux */ |
| 377 | static const struct snd_kcontrol_new wm8753_out3_controls = |
| 378 | SOC_DAPM_ENUM("Route", wm8753_enum[18]); |
| 379 | |
| 380 | /* Out 4 Mux */ |
| 381 | static const struct snd_kcontrol_new wm8753_out4_controls = |
| 382 | SOC_DAPM_ENUM("Route", wm8753_enum[19]); |
| 383 | |
| 384 | /* ADC Mono Mix */ |
| 385 | static const struct snd_kcontrol_new wm8753_adc_mono_controls = |
| 386 | SOC_DAPM_ENUM("Route", wm8753_enum[22]); |
| 387 | |
| 388 | /* Record mixer */ |
| 389 | static const struct snd_kcontrol_new wm8753_record_mixer_controls[] = { |
| 390 | SOC_DAPM_SINGLE("Voice Capture Switch", WM8753_RECMIX2, 3, 1, 0), |
| 391 | SOC_DAPM_SINGLE("Left Capture Switch", WM8753_RECMIX1, 3, 1, 0), |
| 392 | SOC_DAPM_SINGLE("Right Capture Switch", WM8753_RECMIX1, 7, 1, 0), |
| 393 | }; |
| 394 | |
| 395 | /* Left ADC mux */ |
| 396 | static const struct snd_kcontrol_new wm8753_adc_left_controls = |
| 397 | SOC_DAPM_ENUM("Route", wm8753_enum[21]); |
| 398 | |
| 399 | /* Right ADC mux */ |
| 400 | static const struct snd_kcontrol_new wm8753_adc_right_controls = |
| 401 | SOC_DAPM_ENUM("Route", wm8753_enum[20]); |
| 402 | |
| 403 | /* MIC mux */ |
| 404 | static const struct snd_kcontrol_new wm8753_mic_mux_controls = |
| 405 | SOC_DAPM_ENUM("Route", wm8753_enum[16]); |
| 406 | |
| 407 | /* ALC mixer */ |
| 408 | static const struct snd_kcontrol_new wm8753_alc_mixer_controls[] = { |
| 409 | SOC_DAPM_SINGLE("Line Capture Switch", WM8753_INCTL2, 3, 1, 0), |
| 410 | SOC_DAPM_SINGLE("Mic2 Capture Switch", WM8753_INCTL2, 2, 1, 0), |
| 411 | SOC_DAPM_SINGLE("Mic1 Capture Switch", WM8753_INCTL2, 1, 1, 0), |
| 412 | SOC_DAPM_SINGLE("Rx Capture Switch", WM8753_INCTL2, 0, 1, 0), |
| 413 | }; |
| 414 | |
| 415 | /* Left Line mux */ |
| 416 | static const struct snd_kcontrol_new wm8753_line_left_controls = |
| 417 | SOC_DAPM_ENUM("Route", wm8753_enum[14]); |
| 418 | |
| 419 | /* Right Line mux */ |
| 420 | static const struct snd_kcontrol_new wm8753_line_right_controls = |
| 421 | SOC_DAPM_ENUM("Route", wm8753_enum[13]); |
| 422 | |
| 423 | /* Mono Line mux */ |
| 424 | static const struct snd_kcontrol_new wm8753_line_mono_controls = |
| 425 | SOC_DAPM_ENUM("Route", wm8753_enum[12]); |
| 426 | |
| 427 | /* Line mux and mixer */ |
| 428 | static const struct snd_kcontrol_new wm8753_line_mux_mix_controls = |
| 429 | SOC_DAPM_ENUM("Route", wm8753_enum[11]); |
| 430 | |
| 431 | /* Rx mux and mixer */ |
| 432 | static const struct snd_kcontrol_new wm8753_rx_mux_mix_controls = |
| 433 | SOC_DAPM_ENUM("Route", wm8753_enum[15]); |
| 434 | |
| 435 | /* Mic Selector Mux */ |
| 436 | static const struct snd_kcontrol_new wm8753_mic_sel_mux_controls = |
| 437 | SOC_DAPM_ENUM("Route", wm8753_enum[25]); |
| 438 | |
| 439 | static const struct snd_soc_dapm_widget wm8753_dapm_widgets[] = { |
| 440 | SND_SOC_DAPM_MICBIAS("Mic Bias", WM8753_PWR1, 5, 0), |
| 441 | SND_SOC_DAPM_MIXER("Left Mixer", WM8753_PWR4, 0, 0, |
| 442 | &wm8753_left_mixer_controls[0], ARRAY_SIZE(wm8753_left_mixer_controls)), |
| 443 | SND_SOC_DAPM_PGA("Left Out 1", WM8753_PWR3, 8, 0, NULL, 0), |
| 444 | SND_SOC_DAPM_PGA("Left Out 2", WM8753_PWR3, 6, 0, NULL, 0), |
| 445 | SND_SOC_DAPM_DAC("Left DAC", "Left HiFi Playback", WM8753_PWR1, 3, 0), |
| 446 | SND_SOC_DAPM_OUTPUT("LOUT1"), |
| 447 | SND_SOC_DAPM_OUTPUT("LOUT2"), |
| 448 | SND_SOC_DAPM_MIXER("Right Mixer", WM8753_PWR4, 1, 0, |
| 449 | &wm8753_right_mixer_controls[0], ARRAY_SIZE(wm8753_right_mixer_controls)), |
| 450 | SND_SOC_DAPM_PGA("Right Out 1", WM8753_PWR3, 7, 0, NULL, 0), |
| 451 | SND_SOC_DAPM_PGA("Right Out 2", WM8753_PWR3, 5, 0, NULL, 0), |
| 452 | SND_SOC_DAPM_DAC("Right DAC", "Right HiFi Playback", WM8753_PWR1, 2, 0), |
| 453 | SND_SOC_DAPM_OUTPUT("ROUT1"), |
| 454 | SND_SOC_DAPM_OUTPUT("ROUT2"), |
| 455 | SND_SOC_DAPM_MIXER("Mono Mixer", WM8753_PWR4, 2, 0, |
| 456 | &wm8753_mono_mixer_controls[0], ARRAY_SIZE(wm8753_mono_mixer_controls)), |
| 457 | SND_SOC_DAPM_PGA("Mono Out 1", WM8753_PWR3, 2, 0, NULL, 0), |
| 458 | SND_SOC_DAPM_PGA("Mono Out 2", WM8753_PWR3, 1, 0, NULL, 0), |
| 459 | SND_SOC_DAPM_DAC("Voice DAC", "Voice Playback", WM8753_PWR1, 4, 0), |
| 460 | SND_SOC_DAPM_OUTPUT("MONO1"), |
| 461 | SND_SOC_DAPM_MUX("Mono 2 Mux", SND_SOC_NOPM, 0, 0, &wm8753_mono2_controls), |
| 462 | SND_SOC_DAPM_OUTPUT("MONO2"), |
| 463 | SND_SOC_DAPM_MIXER("Out3 Left + Right", -1, 0, 0, NULL, 0), |
| 464 | SND_SOC_DAPM_MUX("Out3 Mux", SND_SOC_NOPM, 0, 0, &wm8753_out3_controls), |
| 465 | SND_SOC_DAPM_PGA("Out 3", WM8753_PWR3, 4, 0, NULL, 0), |
| 466 | SND_SOC_DAPM_OUTPUT("OUT3"), |
| 467 | SND_SOC_DAPM_MUX("Out4 Mux", SND_SOC_NOPM, 0, 0, &wm8753_out4_controls), |
| 468 | SND_SOC_DAPM_PGA("Out 4", WM8753_PWR3, 3, 0, NULL, 0), |
| 469 | SND_SOC_DAPM_OUTPUT("OUT4"), |
| 470 | SND_SOC_DAPM_MIXER("Playback Mixer", WM8753_PWR4, 3, 0, |
| 471 | &wm8753_record_mixer_controls[0], |
| 472 | ARRAY_SIZE(wm8753_record_mixer_controls)), |
| 473 | SND_SOC_DAPM_ADC("Left ADC", "Left Capture", WM8753_PWR2, 3, 0), |
| 474 | SND_SOC_DAPM_ADC("Right ADC", "Right Capture", WM8753_PWR2, 2, 0), |
| 475 | SND_SOC_DAPM_MUX("Capture Left Mixer", SND_SOC_NOPM, 0, 0, |
| 476 | &wm8753_adc_mono_controls), |
| 477 | SND_SOC_DAPM_MUX("Capture Right Mixer", SND_SOC_NOPM, 0, 0, |
| 478 | &wm8753_adc_mono_controls), |
| 479 | SND_SOC_DAPM_MUX("Capture Left Mux", SND_SOC_NOPM, 0, 0, |
| 480 | &wm8753_adc_left_controls), |
| 481 | SND_SOC_DAPM_MUX("Capture Right Mux", SND_SOC_NOPM, 0, 0, |
| 482 | &wm8753_adc_right_controls), |
| 483 | SND_SOC_DAPM_MUX("Mic Sidetone Mux", SND_SOC_NOPM, 0, 0, |
| 484 | &wm8753_mic_mux_controls), |
| 485 | SND_SOC_DAPM_PGA("Left Capture Volume", WM8753_PWR2, 5, 0, NULL, 0), |
| 486 | SND_SOC_DAPM_PGA("Right Capture Volume", WM8753_PWR2, 4, 0, NULL, 0), |
| 487 | SND_SOC_DAPM_MIXER("ALC Mixer", WM8753_PWR2, 6, 0, |
| 488 | &wm8753_alc_mixer_controls[0], ARRAY_SIZE(wm8753_alc_mixer_controls)), |
| 489 | SND_SOC_DAPM_MUX("Line Left Mux", SND_SOC_NOPM, 0, 0, |
| 490 | &wm8753_line_left_controls), |
| 491 | SND_SOC_DAPM_MUX("Line Right Mux", SND_SOC_NOPM, 0, 0, |
| 492 | &wm8753_line_right_controls), |
| 493 | SND_SOC_DAPM_MUX("Line Mono Mux", SND_SOC_NOPM, 0, 0, |
| 494 | &wm8753_line_mono_controls), |
| 495 | SND_SOC_DAPM_MUX("Line Mixer", WM8753_PWR2, 0, 0, |
| 496 | &wm8753_line_mux_mix_controls), |
| 497 | SND_SOC_DAPM_MUX("Rx Mixer", WM8753_PWR2, 1, 0, |
| 498 | &wm8753_rx_mux_mix_controls), |
| 499 | SND_SOC_DAPM_PGA("Mic 1 Volume", WM8753_PWR2, 8, 0, NULL, 0), |
| 500 | SND_SOC_DAPM_PGA("Mic 2 Volume", WM8753_PWR2, 7, 0, NULL, 0), |
| 501 | SND_SOC_DAPM_MUX("Mic Selection Mux", SND_SOC_NOPM, 0, 0, |
| 502 | &wm8753_mic_sel_mux_controls), |
| 503 | SND_SOC_DAPM_INPUT("LINE1"), |
| 504 | SND_SOC_DAPM_INPUT("LINE2"), |
| 505 | SND_SOC_DAPM_INPUT("RXP"), |
| 506 | SND_SOC_DAPM_INPUT("RXN"), |
| 507 | SND_SOC_DAPM_INPUT("ACIN"), |
| 508 | SND_SOC_DAPM_OUTPUT("ACOP"), |
| 509 | SND_SOC_DAPM_INPUT("MIC1N"), |
| 510 | SND_SOC_DAPM_INPUT("MIC1"), |
| 511 | SND_SOC_DAPM_INPUT("MIC2N"), |
| 512 | SND_SOC_DAPM_INPUT("MIC2"), |
| 513 | SND_SOC_DAPM_VMID("VREF"), |
| 514 | }; |
| 515 | |
Mark Brown | a65f056 | 2008-05-13 14:54:43 +0200 | [diff] [blame] | 516 | static const struct snd_soc_dapm_route audio_map[] = { |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 517 | /* left mixer */ |
| 518 | {"Left Mixer", "Left Playback Switch", "Left DAC"}, |
| 519 | {"Left Mixer", "Voice Playback Switch", "Voice DAC"}, |
| 520 | {"Left Mixer", "Sidetone Playback Switch", "Mic Sidetone Mux"}, |
| 521 | {"Left Mixer", "Bypass Playback Switch", "Line Left Mux"}, |
| 522 | |
| 523 | /* right mixer */ |
| 524 | {"Right Mixer", "Right Playback Switch", "Right DAC"}, |
| 525 | {"Right Mixer", "Voice Playback Switch", "Voice DAC"}, |
| 526 | {"Right Mixer", "Sidetone Playback Switch", "Mic Sidetone Mux"}, |
| 527 | {"Right Mixer", "Bypass Playback Switch", "Line Right Mux"}, |
| 528 | |
| 529 | /* mono mixer */ |
| 530 | {"Mono Mixer", "Voice Playback Switch", "Voice DAC"}, |
| 531 | {"Mono Mixer", "Left Playback Switch", "Left DAC"}, |
| 532 | {"Mono Mixer", "Right Playback Switch", "Right DAC"}, |
| 533 | {"Mono Mixer", "Sidetone Playback Switch", "Mic Sidetone Mux"}, |
| 534 | {"Mono Mixer", "Bypass Playback Switch", "Line Mono Mux"}, |
| 535 | |
| 536 | /* left out */ |
| 537 | {"Left Out 1", NULL, "Left Mixer"}, |
| 538 | {"Left Out 2", NULL, "Left Mixer"}, |
| 539 | {"LOUT1", NULL, "Left Out 1"}, |
| 540 | {"LOUT2", NULL, "Left Out 2"}, |
| 541 | |
| 542 | /* right out */ |
| 543 | {"Right Out 1", NULL, "Right Mixer"}, |
| 544 | {"Right Out 2", NULL, "Right Mixer"}, |
| 545 | {"ROUT1", NULL, "Right Out 1"}, |
| 546 | {"ROUT2", NULL, "Right Out 2"}, |
| 547 | |
| 548 | /* mono 1 out */ |
| 549 | {"Mono Out 1", NULL, "Mono Mixer"}, |
| 550 | {"MONO1", NULL, "Mono Out 1"}, |
| 551 | |
| 552 | /* mono 2 out */ |
| 553 | {"Mono 2 Mux", "Left + Right", "Out3 Left + Right"}, |
| 554 | {"Mono 2 Mux", "Inverted Mono 1", "MONO1"}, |
| 555 | {"Mono 2 Mux", "Left", "Left Mixer"}, |
| 556 | {"Mono 2 Mux", "Right", "Right Mixer"}, |
| 557 | {"Mono Out 2", NULL, "Mono 2 Mux"}, |
| 558 | {"MONO2", NULL, "Mono Out 2"}, |
| 559 | |
| 560 | /* out 3 */ |
| 561 | {"Out3 Left + Right", NULL, "Left Mixer"}, |
| 562 | {"Out3 Left + Right", NULL, "Right Mixer"}, |
| 563 | {"Out3 Mux", "VREF", "VREF"}, |
| 564 | {"Out3 Mux", "Left + Right", "Out3 Left + Right"}, |
| 565 | {"Out3 Mux", "ROUT2", "ROUT2"}, |
| 566 | {"Out 3", NULL, "Out3 Mux"}, |
| 567 | {"OUT3", NULL, "Out 3"}, |
| 568 | |
| 569 | /* out 4 */ |
| 570 | {"Out4 Mux", "VREF", "VREF"}, |
Rob Sims | 4037314 | 2008-10-01 21:47:31 +0200 | [diff] [blame] | 571 | {"Out4 Mux", "Capture ST", "Playback Mixer"}, |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 572 | {"Out4 Mux", "LOUT2", "LOUT2"}, |
| 573 | {"Out 4", NULL, "Out4 Mux"}, |
| 574 | {"OUT4", NULL, "Out 4"}, |
| 575 | |
| 576 | /* record mixer */ |
| 577 | {"Playback Mixer", "Left Capture Switch", "Left Mixer"}, |
| 578 | {"Playback Mixer", "Voice Capture Switch", "Mono Mixer"}, |
| 579 | {"Playback Mixer", "Right Capture Switch", "Right Mixer"}, |
| 580 | |
| 581 | /* Mic/SideTone Mux */ |
| 582 | {"Mic Sidetone Mux", "Left PGA", "Left Capture Volume"}, |
| 583 | {"Mic Sidetone Mux", "Right PGA", "Right Capture Volume"}, |
| 584 | {"Mic Sidetone Mux", "Mic 1", "Mic 1 Volume"}, |
| 585 | {"Mic Sidetone Mux", "Mic 2", "Mic 2 Volume"}, |
| 586 | |
| 587 | /* Capture Left Mux */ |
| 588 | {"Capture Left Mux", "PGA", "Left Capture Volume"}, |
| 589 | {"Capture Left Mux", "Line or RXP-RXN", "Line Left Mux"}, |
| 590 | {"Capture Left Mux", "Line", "LINE1"}, |
| 591 | |
| 592 | /* Capture Right Mux */ |
| 593 | {"Capture Right Mux", "PGA", "Right Capture Volume"}, |
| 594 | {"Capture Right Mux", "Line or RXP-RXN", "Line Right Mux"}, |
Rob Sims | 4037314 | 2008-10-01 21:47:31 +0200 | [diff] [blame] | 595 | {"Capture Right Mux", "Sidetone", "Playback Mixer"}, |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 596 | |
| 597 | /* Mono Capture mixer-mux */ |
| 598 | {"Capture Right Mixer", "Stereo", "Capture Right Mux"}, |
Phil Vandry | 877ae70 | 2009-09-21 11:36:08 -0400 | [diff] [blame] | 599 | {"Capture Left Mixer", "Stereo", "Capture Left Mux"}, |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 600 | {"Capture Left Mixer", "Analogue Mix Left", "Capture Left Mux"}, |
| 601 | {"Capture Left Mixer", "Analogue Mix Left", "Capture Right Mux"}, |
| 602 | {"Capture Right Mixer", "Analogue Mix Right", "Capture Left Mux"}, |
| 603 | {"Capture Right Mixer", "Analogue Mix Right", "Capture Right Mux"}, |
| 604 | {"Capture Left Mixer", "Digital Mono Mix", "Capture Left Mux"}, |
| 605 | {"Capture Left Mixer", "Digital Mono Mix", "Capture Right Mux"}, |
| 606 | {"Capture Right Mixer", "Digital Mono Mix", "Capture Left Mux"}, |
| 607 | {"Capture Right Mixer", "Digital Mono Mix", "Capture Right Mux"}, |
| 608 | |
| 609 | /* ADC */ |
| 610 | {"Left ADC", NULL, "Capture Left Mixer"}, |
| 611 | {"Right ADC", NULL, "Capture Right Mixer"}, |
| 612 | |
| 613 | /* Left Capture Volume */ |
| 614 | {"Left Capture Volume", NULL, "ACIN"}, |
| 615 | |
| 616 | /* Right Capture Volume */ |
| 617 | {"Right Capture Volume", NULL, "Mic 2 Volume"}, |
| 618 | |
| 619 | /* ALC Mixer */ |
| 620 | {"ALC Mixer", "Line Capture Switch", "Line Mixer"}, |
| 621 | {"ALC Mixer", "Mic2 Capture Switch", "Mic 2 Volume"}, |
| 622 | {"ALC Mixer", "Mic1 Capture Switch", "Mic 1 Volume"}, |
| 623 | {"ALC Mixer", "Rx Capture Switch", "Rx Mixer"}, |
| 624 | |
| 625 | /* Line Left Mux */ |
| 626 | {"Line Left Mux", "Line 1", "LINE1"}, |
| 627 | {"Line Left Mux", "Rx Mix", "Rx Mixer"}, |
| 628 | |
| 629 | /* Line Right Mux */ |
| 630 | {"Line Right Mux", "Line 2", "LINE2"}, |
| 631 | {"Line Right Mux", "Rx Mix", "Rx Mixer"}, |
| 632 | |
| 633 | /* Line Mono Mux */ |
| 634 | {"Line Mono Mux", "Line Mix", "Line Mixer"}, |
| 635 | {"Line Mono Mux", "Rx Mix", "Rx Mixer"}, |
| 636 | |
| 637 | /* Line Mixer/Mux */ |
| 638 | {"Line Mixer", "Line 1 + 2", "LINE1"}, |
| 639 | {"Line Mixer", "Line 1 - 2", "LINE1"}, |
| 640 | {"Line Mixer", "Line 1 + 2", "LINE2"}, |
| 641 | {"Line Mixer", "Line 1 - 2", "LINE2"}, |
| 642 | {"Line Mixer", "Line 1", "LINE1"}, |
| 643 | {"Line Mixer", "Line 2", "LINE2"}, |
| 644 | |
| 645 | /* Rx Mixer/Mux */ |
| 646 | {"Rx Mixer", "RXP - RXN", "RXP"}, |
| 647 | {"Rx Mixer", "RXP + RXN", "RXP"}, |
| 648 | {"Rx Mixer", "RXP - RXN", "RXN"}, |
| 649 | {"Rx Mixer", "RXP + RXN", "RXN"}, |
| 650 | {"Rx Mixer", "RXP", "RXP"}, |
| 651 | {"Rx Mixer", "RXN", "RXN"}, |
| 652 | |
| 653 | /* Mic 1 Volume */ |
| 654 | {"Mic 1 Volume", NULL, "MIC1N"}, |
| 655 | {"Mic 1 Volume", NULL, "Mic Selection Mux"}, |
| 656 | |
| 657 | /* Mic 2 Volume */ |
| 658 | {"Mic 2 Volume", NULL, "MIC2N"}, |
| 659 | {"Mic 2 Volume", NULL, "MIC2"}, |
| 660 | |
| 661 | /* Mic Selector Mux */ |
| 662 | {"Mic Selection Mux", "Mic 1", "MIC1"}, |
| 663 | {"Mic Selection Mux", "Mic 2", "MIC2N"}, |
| 664 | {"Mic Selection Mux", "Mic 3", "MIC2"}, |
| 665 | |
| 666 | /* ACOP */ |
| 667 | {"ACOP", NULL, "ALC Mixer"}, |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 668 | }; |
| 669 | |
| 670 | static int wm8753_add_widgets(struct snd_soc_codec *codec) |
| 671 | { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 672 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 673 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 674 | snd_soc_dapm_new_controls(dapm, wm8753_dapm_widgets, |
| 675 | ARRAY_SIZE(wm8753_dapm_widgets)); |
| 676 | snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map)); |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 677 | |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 678 | return 0; |
| 679 | } |
| 680 | |
| 681 | /* PLL divisors */ |
| 682 | struct _pll_div { |
| 683 | u32 div2:1; |
| 684 | u32 n:4; |
| 685 | u32 k:24; |
| 686 | }; |
| 687 | |
| 688 | /* The size in bits of the pll divide multiplied by 10 |
| 689 | * to allow rounding later */ |
| 690 | #define FIXED_PLL_SIZE ((1 << 22) * 10) |
| 691 | |
| 692 | static void pll_factors(struct _pll_div *pll_div, unsigned int target, |
| 693 | unsigned int source) |
| 694 | { |
| 695 | u64 Kpart; |
| 696 | unsigned int K, Ndiv, Nmod; |
| 697 | |
| 698 | Ndiv = target / source; |
| 699 | if (Ndiv < 6) { |
| 700 | source >>= 1; |
| 701 | pll_div->div2 = 1; |
| 702 | Ndiv = target / source; |
| 703 | } else |
| 704 | pll_div->div2 = 0; |
| 705 | |
| 706 | if ((Ndiv < 6) || (Ndiv > 12)) |
| 707 | printk(KERN_WARNING |
Roel Kluin | 449bd54 | 2009-05-27 17:08:39 -0700 | [diff] [blame] | 708 | "wm8753: unsupported N = %u\n", Ndiv); |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 709 | |
| 710 | pll_div->n = Ndiv; |
| 711 | Nmod = target % source; |
| 712 | Kpart = FIXED_PLL_SIZE * (long long)Nmod; |
| 713 | |
| 714 | do_div(Kpart, source); |
| 715 | |
| 716 | K = Kpart & 0xFFFFFFFF; |
| 717 | |
| 718 | /* Check if we need to round */ |
| 719 | if ((K % 10) >= 5) |
| 720 | K += 5; |
| 721 | |
| 722 | /* Move down to proper range now rounding is done */ |
| 723 | K /= 10; |
| 724 | |
| 725 | pll_div->k = K; |
| 726 | } |
| 727 | |
Mark Brown | 8548803 | 2009-09-05 18:52:16 +0100 | [diff] [blame] | 728 | static int wm8753_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id, |
| 729 | int source, unsigned int freq_in, unsigned int freq_out) |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 730 | { |
| 731 | u16 reg, enable; |
| 732 | int offset; |
| 733 | struct snd_soc_codec *codec = codec_dai->codec; |
| 734 | |
| 735 | if (pll_id < WM8753_PLL1 || pll_id > WM8753_PLL2) |
| 736 | return -ENODEV; |
| 737 | |
| 738 | if (pll_id == WM8753_PLL1) { |
| 739 | offset = 0; |
| 740 | enable = 0x10; |
| 741 | reg = wm8753_read_reg_cache(codec, WM8753_CLOCK) & 0xffef; |
| 742 | } else { |
| 743 | offset = 4; |
| 744 | enable = 0x8; |
| 745 | reg = wm8753_read_reg_cache(codec, WM8753_CLOCK) & 0xfff7; |
| 746 | } |
| 747 | |
| 748 | if (!freq_in || !freq_out) { |
| 749 | /* disable PLL */ |
| 750 | wm8753_write(codec, WM8753_PLL1CTL1 + offset, 0x0026); |
| 751 | wm8753_write(codec, WM8753_CLOCK, reg); |
| 752 | return 0; |
| 753 | } else { |
| 754 | u16 value = 0; |
| 755 | struct _pll_div pll_div; |
| 756 | |
| 757 | pll_factors(&pll_div, freq_out * 8, freq_in); |
| 758 | |
| 759 | /* set up N and K PLL divisor ratios */ |
| 760 | /* bits 8:5 = PLL_N, bits 3:0 = PLL_K[21:18] */ |
| 761 | value = (pll_div.n << 5) + ((pll_div.k & 0x3c0000) >> 18); |
| 762 | wm8753_write(codec, WM8753_PLL1CTL2 + offset, value); |
| 763 | |
| 764 | /* bits 8:0 = PLL_K[17:9] */ |
| 765 | value = (pll_div.k & 0x03fe00) >> 9; |
| 766 | wm8753_write(codec, WM8753_PLL1CTL3 + offset, value); |
| 767 | |
| 768 | /* bits 8:0 = PLL_K[8:0] */ |
| 769 | value = pll_div.k & 0x0001ff; |
| 770 | wm8753_write(codec, WM8753_PLL1CTL4 + offset, value); |
| 771 | |
| 772 | /* set PLL as input and enable */ |
| 773 | wm8753_write(codec, WM8753_PLL1CTL1 + offset, 0x0027 | |
| 774 | (pll_div.div2 << 3)); |
| 775 | wm8753_write(codec, WM8753_CLOCK, reg | enable); |
| 776 | } |
| 777 | return 0; |
| 778 | } |
| 779 | |
| 780 | struct _coeff_div { |
| 781 | u32 mclk; |
| 782 | u32 rate; |
| 783 | u8 sr:5; |
| 784 | u8 usb:1; |
| 785 | }; |
| 786 | |
| 787 | /* codec hifi mclk (after PLL) clock divider coefficients */ |
| 788 | static const struct _coeff_div coeff_div[] = { |
| 789 | /* 8k */ |
| 790 | {12288000, 8000, 0x6, 0x0}, |
| 791 | {11289600, 8000, 0x16, 0x0}, |
| 792 | {18432000, 8000, 0x7, 0x0}, |
| 793 | {16934400, 8000, 0x17, 0x0}, |
| 794 | {12000000, 8000, 0x6, 0x1}, |
| 795 | |
| 796 | /* 11.025k */ |
| 797 | {11289600, 11025, 0x18, 0x0}, |
| 798 | {16934400, 11025, 0x19, 0x0}, |
| 799 | {12000000, 11025, 0x19, 0x1}, |
| 800 | |
| 801 | /* 16k */ |
| 802 | {12288000, 16000, 0xa, 0x0}, |
| 803 | {18432000, 16000, 0xb, 0x0}, |
| 804 | {12000000, 16000, 0xa, 0x1}, |
| 805 | |
| 806 | /* 22.05k */ |
| 807 | {11289600, 22050, 0x1a, 0x0}, |
| 808 | {16934400, 22050, 0x1b, 0x0}, |
| 809 | {12000000, 22050, 0x1b, 0x1}, |
| 810 | |
| 811 | /* 32k */ |
| 812 | {12288000, 32000, 0xc, 0x0}, |
| 813 | {18432000, 32000, 0xd, 0x0}, |
| 814 | {12000000, 32000, 0xa, 0x1}, |
| 815 | |
| 816 | /* 44.1k */ |
| 817 | {11289600, 44100, 0x10, 0x0}, |
| 818 | {16934400, 44100, 0x11, 0x0}, |
| 819 | {12000000, 44100, 0x11, 0x1}, |
| 820 | |
| 821 | /* 48k */ |
| 822 | {12288000, 48000, 0x0, 0x0}, |
| 823 | {18432000, 48000, 0x1, 0x0}, |
| 824 | {12000000, 48000, 0x0, 0x1}, |
| 825 | |
| 826 | /* 88.2k */ |
| 827 | {11289600, 88200, 0x1e, 0x0}, |
| 828 | {16934400, 88200, 0x1f, 0x0}, |
| 829 | {12000000, 88200, 0x1f, 0x1}, |
| 830 | |
| 831 | /* 96k */ |
| 832 | {12288000, 96000, 0xe, 0x0}, |
| 833 | {18432000, 96000, 0xf, 0x0}, |
| 834 | {12000000, 96000, 0xe, 0x1}, |
| 835 | }; |
| 836 | |
| 837 | static int get_coeff(int mclk, int rate) |
| 838 | { |
| 839 | int i; |
| 840 | |
| 841 | for (i = 0; i < ARRAY_SIZE(coeff_div); i++) { |
| 842 | if (coeff_div[i].rate == rate && coeff_div[i].mclk == mclk) |
| 843 | return i; |
| 844 | } |
| 845 | return -EINVAL; |
| 846 | } |
| 847 | |
| 848 | /* |
| 849 | * Clock after PLL and dividers |
| 850 | */ |
Liam Girdwood | e550e17 | 2008-07-07 16:07:52 +0100 | [diff] [blame] | 851 | static int wm8753_set_dai_sysclk(struct snd_soc_dai *codec_dai, |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 852 | int clk_id, unsigned int freq, int dir) |
| 853 | { |
| 854 | struct snd_soc_codec *codec = codec_dai->codec; |
Mark Brown | b2c812e | 2010-04-14 15:35:19 +0900 | [diff] [blame] | 855 | struct wm8753_priv *wm8753 = snd_soc_codec_get_drvdata(codec); |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 856 | |
| 857 | switch (freq) { |
| 858 | case 11289600: |
| 859 | case 12000000: |
| 860 | case 12288000: |
| 861 | case 16934400: |
| 862 | case 18432000: |
| 863 | if (clk_id == WM8753_MCLK) { |
| 864 | wm8753->sysclk = freq; |
| 865 | return 0; |
| 866 | } else if (clk_id == WM8753_PCMCLK) { |
| 867 | wm8753->pcmclk = freq; |
| 868 | return 0; |
| 869 | } |
| 870 | break; |
| 871 | } |
| 872 | return -EINVAL; |
| 873 | } |
| 874 | |
| 875 | /* |
| 876 | * Set's ADC and Voice DAC format. |
| 877 | */ |
Liam Girdwood | e550e17 | 2008-07-07 16:07:52 +0100 | [diff] [blame] | 878 | static int wm8753_vdac_adc_set_dai_fmt(struct snd_soc_dai *codec_dai, |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 879 | unsigned int fmt) |
| 880 | { |
| 881 | struct snd_soc_codec *codec = codec_dai->codec; |
| 882 | u16 voice = wm8753_read_reg_cache(codec, WM8753_PCM) & 0x01ec; |
| 883 | |
| 884 | /* interface format */ |
| 885 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 886 | case SND_SOC_DAIFMT_I2S: |
| 887 | voice |= 0x0002; |
| 888 | break; |
| 889 | case SND_SOC_DAIFMT_RIGHT_J: |
| 890 | break; |
| 891 | case SND_SOC_DAIFMT_LEFT_J: |
| 892 | voice |= 0x0001; |
| 893 | break; |
| 894 | case SND_SOC_DAIFMT_DSP_A: |
| 895 | voice |= 0x0003; |
| 896 | break; |
| 897 | case SND_SOC_DAIFMT_DSP_B: |
| 898 | voice |= 0x0013; |
| 899 | break; |
| 900 | default: |
| 901 | return -EINVAL; |
| 902 | } |
| 903 | |
| 904 | wm8753_write(codec, WM8753_PCM, voice); |
| 905 | return 0; |
| 906 | } |
| 907 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 908 | static int wm8753_pcm_startup(struct snd_pcm_substream *substream, |
| 909 | struct snd_soc_dai *dai) |
| 910 | { |
| 911 | wm8753_set_dai_mode(dai->codec, dai, 0); |
| 912 | return 0; |
| 913 | } |
| 914 | |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 915 | /* |
| 916 | * Set PCM DAI bit size and sample rate. |
| 917 | */ |
| 918 | static int wm8753_pcm_hw_params(struct snd_pcm_substream *substream, |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 919 | struct snd_pcm_hw_params *params, |
| 920 | struct snd_soc_dai *dai) |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 921 | { |
| 922 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 923 | struct snd_soc_codec *codec = rtd->codec; |
Mark Brown | b2c812e | 2010-04-14 15:35:19 +0900 | [diff] [blame] | 924 | struct wm8753_priv *wm8753 = snd_soc_codec_get_drvdata(codec); |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 925 | u16 voice = wm8753_read_reg_cache(codec, WM8753_PCM) & 0x01f3; |
| 926 | u16 srate = wm8753_read_reg_cache(codec, WM8753_SRATE1) & 0x017f; |
| 927 | |
| 928 | /* bit size */ |
| 929 | switch (params_format(params)) { |
| 930 | case SNDRV_PCM_FORMAT_S16_LE: |
| 931 | break; |
| 932 | case SNDRV_PCM_FORMAT_S20_3LE: |
| 933 | voice |= 0x0004; |
| 934 | break; |
| 935 | case SNDRV_PCM_FORMAT_S24_LE: |
| 936 | voice |= 0x0008; |
| 937 | break; |
| 938 | case SNDRV_PCM_FORMAT_S32_LE: |
| 939 | voice |= 0x000c; |
| 940 | break; |
| 941 | } |
| 942 | |
| 943 | /* sample rate */ |
| 944 | if (params_rate(params) * 384 == wm8753->pcmclk) |
| 945 | srate |= 0x80; |
| 946 | wm8753_write(codec, WM8753_SRATE1, srate); |
| 947 | |
| 948 | wm8753_write(codec, WM8753_PCM, voice); |
| 949 | return 0; |
| 950 | } |
| 951 | |
| 952 | /* |
| 953 | * Set's PCM dai fmt and BCLK. |
| 954 | */ |
Liam Girdwood | e550e17 | 2008-07-07 16:07:52 +0100 | [diff] [blame] | 955 | static int wm8753_pcm_set_dai_fmt(struct snd_soc_dai *codec_dai, |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 956 | unsigned int fmt) |
| 957 | { |
| 958 | struct snd_soc_codec *codec = codec_dai->codec; |
| 959 | u16 voice, ioctl; |
| 960 | |
| 961 | voice = wm8753_read_reg_cache(codec, WM8753_PCM) & 0x011f; |
| 962 | ioctl = wm8753_read_reg_cache(codec, WM8753_IOCTL) & 0x015d; |
| 963 | |
| 964 | /* set master/slave audio interface */ |
| 965 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 966 | case SND_SOC_DAIFMT_CBS_CFS: |
| 967 | break; |
| 968 | case SND_SOC_DAIFMT_CBM_CFM: |
| 969 | ioctl |= 0x2; |
| 970 | case SND_SOC_DAIFMT_CBM_CFS: |
| 971 | voice |= 0x0040; |
| 972 | break; |
| 973 | default: |
| 974 | return -EINVAL; |
| 975 | } |
| 976 | |
| 977 | /* clock inversion */ |
| 978 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 979 | case SND_SOC_DAIFMT_DSP_A: |
| 980 | case SND_SOC_DAIFMT_DSP_B: |
| 981 | /* frame inversion not valid for DSP modes */ |
| 982 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { |
| 983 | case SND_SOC_DAIFMT_NB_NF: |
| 984 | break; |
| 985 | case SND_SOC_DAIFMT_IB_NF: |
| 986 | voice |= 0x0080; |
| 987 | break; |
| 988 | default: |
| 989 | return -EINVAL; |
| 990 | } |
| 991 | break; |
| 992 | case SND_SOC_DAIFMT_I2S: |
| 993 | case SND_SOC_DAIFMT_RIGHT_J: |
| 994 | case SND_SOC_DAIFMT_LEFT_J: |
| 995 | voice &= ~0x0010; |
| 996 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { |
| 997 | case SND_SOC_DAIFMT_NB_NF: |
| 998 | break; |
| 999 | case SND_SOC_DAIFMT_IB_IF: |
| 1000 | voice |= 0x0090; |
| 1001 | break; |
| 1002 | case SND_SOC_DAIFMT_IB_NF: |
| 1003 | voice |= 0x0080; |
| 1004 | break; |
| 1005 | case SND_SOC_DAIFMT_NB_IF: |
| 1006 | voice |= 0x0010; |
| 1007 | break; |
| 1008 | default: |
| 1009 | return -EINVAL; |
| 1010 | } |
| 1011 | break; |
| 1012 | default: |
| 1013 | return -EINVAL; |
| 1014 | } |
| 1015 | |
| 1016 | wm8753_write(codec, WM8753_PCM, voice); |
| 1017 | wm8753_write(codec, WM8753_IOCTL, ioctl); |
| 1018 | return 0; |
| 1019 | } |
| 1020 | |
Liam Girdwood | e550e17 | 2008-07-07 16:07:52 +0100 | [diff] [blame] | 1021 | static int wm8753_set_dai_clkdiv(struct snd_soc_dai *codec_dai, |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1022 | int div_id, int div) |
| 1023 | { |
| 1024 | struct snd_soc_codec *codec = codec_dai->codec; |
| 1025 | u16 reg; |
| 1026 | |
| 1027 | switch (div_id) { |
| 1028 | case WM8753_PCMDIV: |
| 1029 | reg = wm8753_read_reg_cache(codec, WM8753_CLOCK) & 0x003f; |
| 1030 | wm8753_write(codec, WM8753_CLOCK, reg | div); |
| 1031 | break; |
| 1032 | case WM8753_BCLKDIV: |
| 1033 | reg = wm8753_read_reg_cache(codec, WM8753_SRATE2) & 0x01c7; |
| 1034 | wm8753_write(codec, WM8753_SRATE2, reg | div); |
| 1035 | break; |
| 1036 | case WM8753_VXCLKDIV: |
| 1037 | reg = wm8753_read_reg_cache(codec, WM8753_SRATE2) & 0x003f; |
| 1038 | wm8753_write(codec, WM8753_SRATE2, reg | div); |
| 1039 | break; |
| 1040 | default: |
| 1041 | return -EINVAL; |
| 1042 | } |
| 1043 | return 0; |
| 1044 | } |
| 1045 | |
| 1046 | /* |
| 1047 | * Set's HiFi DAC format. |
| 1048 | */ |
Liam Girdwood | e550e17 | 2008-07-07 16:07:52 +0100 | [diff] [blame] | 1049 | static int wm8753_hdac_set_dai_fmt(struct snd_soc_dai *codec_dai, |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1050 | unsigned int fmt) |
| 1051 | { |
| 1052 | struct snd_soc_codec *codec = codec_dai->codec; |
| 1053 | u16 hifi = wm8753_read_reg_cache(codec, WM8753_HIFI) & 0x01e0; |
| 1054 | |
| 1055 | /* interface format */ |
| 1056 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 1057 | case SND_SOC_DAIFMT_I2S: |
| 1058 | hifi |= 0x0002; |
| 1059 | break; |
| 1060 | case SND_SOC_DAIFMT_RIGHT_J: |
| 1061 | break; |
| 1062 | case SND_SOC_DAIFMT_LEFT_J: |
| 1063 | hifi |= 0x0001; |
| 1064 | break; |
| 1065 | case SND_SOC_DAIFMT_DSP_A: |
| 1066 | hifi |= 0x0003; |
| 1067 | break; |
| 1068 | case SND_SOC_DAIFMT_DSP_B: |
| 1069 | hifi |= 0x0013; |
| 1070 | break; |
| 1071 | default: |
| 1072 | return -EINVAL; |
| 1073 | } |
| 1074 | |
| 1075 | wm8753_write(codec, WM8753_HIFI, hifi); |
| 1076 | return 0; |
| 1077 | } |
| 1078 | |
| 1079 | /* |
| 1080 | * Set's I2S DAI format. |
| 1081 | */ |
Liam Girdwood | e550e17 | 2008-07-07 16:07:52 +0100 | [diff] [blame] | 1082 | static int wm8753_i2s_set_dai_fmt(struct snd_soc_dai *codec_dai, |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1083 | unsigned int fmt) |
| 1084 | { |
| 1085 | struct snd_soc_codec *codec = codec_dai->codec; |
| 1086 | u16 ioctl, hifi; |
| 1087 | |
| 1088 | hifi = wm8753_read_reg_cache(codec, WM8753_HIFI) & 0x011f; |
| 1089 | ioctl = wm8753_read_reg_cache(codec, WM8753_IOCTL) & 0x00ae; |
| 1090 | |
| 1091 | /* set master/slave audio interface */ |
| 1092 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 1093 | case SND_SOC_DAIFMT_CBS_CFS: |
| 1094 | break; |
| 1095 | case SND_SOC_DAIFMT_CBM_CFM: |
| 1096 | ioctl |= 0x1; |
| 1097 | case SND_SOC_DAIFMT_CBM_CFS: |
| 1098 | hifi |= 0x0040; |
| 1099 | break; |
| 1100 | default: |
| 1101 | return -EINVAL; |
| 1102 | } |
| 1103 | |
| 1104 | /* clock inversion */ |
| 1105 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 1106 | case SND_SOC_DAIFMT_DSP_A: |
| 1107 | case SND_SOC_DAIFMT_DSP_B: |
| 1108 | /* frame inversion not valid for DSP modes */ |
| 1109 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { |
| 1110 | case SND_SOC_DAIFMT_NB_NF: |
| 1111 | break; |
| 1112 | case SND_SOC_DAIFMT_IB_NF: |
| 1113 | hifi |= 0x0080; |
| 1114 | break; |
| 1115 | default: |
| 1116 | return -EINVAL; |
| 1117 | } |
| 1118 | break; |
| 1119 | case SND_SOC_DAIFMT_I2S: |
| 1120 | case SND_SOC_DAIFMT_RIGHT_J: |
| 1121 | case SND_SOC_DAIFMT_LEFT_J: |
| 1122 | hifi &= ~0x0010; |
| 1123 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { |
| 1124 | case SND_SOC_DAIFMT_NB_NF: |
| 1125 | break; |
| 1126 | case SND_SOC_DAIFMT_IB_IF: |
| 1127 | hifi |= 0x0090; |
| 1128 | break; |
| 1129 | case SND_SOC_DAIFMT_IB_NF: |
| 1130 | hifi |= 0x0080; |
| 1131 | break; |
| 1132 | case SND_SOC_DAIFMT_NB_IF: |
| 1133 | hifi |= 0x0010; |
| 1134 | break; |
| 1135 | default: |
| 1136 | return -EINVAL; |
| 1137 | } |
| 1138 | break; |
| 1139 | default: |
| 1140 | return -EINVAL; |
| 1141 | } |
| 1142 | |
| 1143 | wm8753_write(codec, WM8753_HIFI, hifi); |
| 1144 | wm8753_write(codec, WM8753_IOCTL, ioctl); |
| 1145 | return 0; |
| 1146 | } |
| 1147 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1148 | static int wm8753_i2s_startup(struct snd_pcm_substream *substream, |
| 1149 | struct snd_soc_dai *dai) |
| 1150 | { |
| 1151 | wm8753_set_dai_mode(dai->codec, dai, 1); |
| 1152 | return 0; |
| 1153 | } |
| 1154 | |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1155 | /* |
| 1156 | * Set PCM DAI bit size and sample rate. |
| 1157 | */ |
| 1158 | static int wm8753_i2s_hw_params(struct snd_pcm_substream *substream, |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 1159 | struct snd_pcm_hw_params *params, |
| 1160 | struct snd_soc_dai *dai) |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1161 | { |
| 1162 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1163 | struct snd_soc_codec *codec = rtd->codec; |
Mark Brown | b2c812e | 2010-04-14 15:35:19 +0900 | [diff] [blame] | 1164 | struct wm8753_priv *wm8753 = snd_soc_codec_get_drvdata(codec); |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1165 | u16 srate = wm8753_read_reg_cache(codec, WM8753_SRATE1) & 0x01c0; |
| 1166 | u16 hifi = wm8753_read_reg_cache(codec, WM8753_HIFI) & 0x01f3; |
| 1167 | int coeff; |
| 1168 | |
| 1169 | /* is digital filter coefficient valid ? */ |
| 1170 | coeff = get_coeff(wm8753->sysclk, params_rate(params)); |
| 1171 | if (coeff < 0) { |
| 1172 | printk(KERN_ERR "wm8753 invalid MCLK or rate\n"); |
| 1173 | return coeff; |
| 1174 | } |
| 1175 | wm8753_write(codec, WM8753_SRATE1, srate | (coeff_div[coeff].sr << 1) | |
| 1176 | coeff_div[coeff].usb); |
| 1177 | |
| 1178 | /* bit size */ |
| 1179 | switch (params_format(params)) { |
| 1180 | case SNDRV_PCM_FORMAT_S16_LE: |
| 1181 | break; |
| 1182 | case SNDRV_PCM_FORMAT_S20_3LE: |
| 1183 | hifi |= 0x0004; |
| 1184 | break; |
| 1185 | case SNDRV_PCM_FORMAT_S24_LE: |
| 1186 | hifi |= 0x0008; |
| 1187 | break; |
| 1188 | case SNDRV_PCM_FORMAT_S32_LE: |
| 1189 | hifi |= 0x000c; |
| 1190 | break; |
| 1191 | } |
| 1192 | |
| 1193 | wm8753_write(codec, WM8753_HIFI, hifi); |
| 1194 | return 0; |
| 1195 | } |
| 1196 | |
Liam Girdwood | e550e17 | 2008-07-07 16:07:52 +0100 | [diff] [blame] | 1197 | static int wm8753_mode1v_set_dai_fmt(struct snd_soc_dai *codec_dai, |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1198 | unsigned int fmt) |
| 1199 | { |
| 1200 | struct snd_soc_codec *codec = codec_dai->codec; |
| 1201 | u16 clock; |
| 1202 | |
| 1203 | /* set clk source as pcmclk */ |
| 1204 | clock = wm8753_read_reg_cache(codec, WM8753_CLOCK) & 0xfffb; |
| 1205 | wm8753_write(codec, WM8753_CLOCK, clock); |
| 1206 | |
| 1207 | if (wm8753_vdac_adc_set_dai_fmt(codec_dai, fmt) < 0) |
| 1208 | return -EINVAL; |
| 1209 | return wm8753_pcm_set_dai_fmt(codec_dai, fmt); |
| 1210 | } |
| 1211 | |
Liam Girdwood | e550e17 | 2008-07-07 16:07:52 +0100 | [diff] [blame] | 1212 | static int wm8753_mode1h_set_dai_fmt(struct snd_soc_dai *codec_dai, |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1213 | unsigned int fmt) |
| 1214 | { |
| 1215 | if (wm8753_hdac_set_dai_fmt(codec_dai, fmt) < 0) |
| 1216 | return -EINVAL; |
| 1217 | return wm8753_i2s_set_dai_fmt(codec_dai, fmt); |
| 1218 | } |
| 1219 | |
Liam Girdwood | e550e17 | 2008-07-07 16:07:52 +0100 | [diff] [blame] | 1220 | static int wm8753_mode2_set_dai_fmt(struct snd_soc_dai *codec_dai, |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1221 | unsigned int fmt) |
| 1222 | { |
| 1223 | struct snd_soc_codec *codec = codec_dai->codec; |
| 1224 | u16 clock; |
| 1225 | |
| 1226 | /* set clk source as pcmclk */ |
| 1227 | clock = wm8753_read_reg_cache(codec, WM8753_CLOCK) & 0xfffb; |
| 1228 | wm8753_write(codec, WM8753_CLOCK, clock); |
| 1229 | |
| 1230 | if (wm8753_vdac_adc_set_dai_fmt(codec_dai, fmt) < 0) |
| 1231 | return -EINVAL; |
| 1232 | return wm8753_i2s_set_dai_fmt(codec_dai, fmt); |
| 1233 | } |
| 1234 | |
Liam Girdwood | e550e17 | 2008-07-07 16:07:52 +0100 | [diff] [blame] | 1235 | static int wm8753_mode3_4_set_dai_fmt(struct snd_soc_dai *codec_dai, |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1236 | unsigned int fmt) |
| 1237 | { |
| 1238 | struct snd_soc_codec *codec = codec_dai->codec; |
| 1239 | u16 clock; |
| 1240 | |
| 1241 | /* set clk source as mclk */ |
| 1242 | clock = wm8753_read_reg_cache(codec, WM8753_CLOCK) & 0xfffb; |
| 1243 | wm8753_write(codec, WM8753_CLOCK, clock | 0x4); |
| 1244 | |
| 1245 | if (wm8753_hdac_set_dai_fmt(codec_dai, fmt) < 0) |
| 1246 | return -EINVAL; |
| 1247 | if (wm8753_vdac_adc_set_dai_fmt(codec_dai, fmt) < 0) |
| 1248 | return -EINVAL; |
| 1249 | return wm8753_i2s_set_dai_fmt(codec_dai, fmt); |
| 1250 | } |
| 1251 | |
Liam Girdwood | e550e17 | 2008-07-07 16:07:52 +0100 | [diff] [blame] | 1252 | static int wm8753_mute(struct snd_soc_dai *dai, int mute) |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1253 | { |
| 1254 | struct snd_soc_codec *codec = dai->codec; |
| 1255 | u16 mute_reg = wm8753_read_reg_cache(codec, WM8753_DAC) & 0xfff7; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1256 | struct wm8753_priv *wm8753 = snd_soc_codec_get_drvdata(codec); |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1257 | |
| 1258 | /* the digital mute covers the HiFi and Voice DAC's on the WM8753. |
| 1259 | * make sure we check if they are not both active when we mute */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1260 | if (mute && wm8753->dai_func == 1) { |
| 1261 | if (!codec->active) |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1262 | wm8753_write(codec, WM8753_DAC, mute_reg | 0x8); |
| 1263 | } else { |
| 1264 | if (mute) |
| 1265 | wm8753_write(codec, WM8753_DAC, mute_reg | 0x8); |
| 1266 | else |
| 1267 | wm8753_write(codec, WM8753_DAC, mute_reg); |
| 1268 | } |
| 1269 | |
| 1270 | return 0; |
| 1271 | } |
| 1272 | |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1273 | static int wm8753_set_bias_level(struct snd_soc_codec *codec, |
| 1274 | enum snd_soc_bias_level level) |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1275 | { |
| 1276 | u16 pwr_reg = wm8753_read_reg_cache(codec, WM8753_PWR1) & 0xfe3e; |
| 1277 | |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1278 | switch (level) { |
| 1279 | case SND_SOC_BIAS_ON: |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1280 | /* set vmid to 50k and unmute dac */ |
| 1281 | wm8753_write(codec, WM8753_PWR1, pwr_reg | 0x00c0); |
| 1282 | break; |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1283 | case SND_SOC_BIAS_PREPARE: |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1284 | /* set vmid to 5k for quick power up */ |
| 1285 | wm8753_write(codec, WM8753_PWR1, pwr_reg | 0x01c1); |
| 1286 | break; |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1287 | case SND_SOC_BIAS_STANDBY: |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1288 | /* mute dac and set vmid to 500k, enable VREF */ |
| 1289 | wm8753_write(codec, WM8753_PWR1, pwr_reg | 0x0141); |
| 1290 | break; |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1291 | case SND_SOC_BIAS_OFF: |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1292 | wm8753_write(codec, WM8753_PWR1, 0x0001); |
| 1293 | break; |
| 1294 | } |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1295 | codec->dapm.bias_level = level; |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1296 | return 0; |
| 1297 | } |
| 1298 | |
| 1299 | #define WM8753_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\ |
Mark Brown | 60fc684 | 2008-04-30 17:18:43 +0200 | [diff] [blame] | 1300 | SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 |\ |
| 1301 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |\ |
| 1302 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000) |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1303 | |
| 1304 | #define WM8753_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ |
| 1305 | SNDRV_PCM_FMTBIT_S24_LE) |
| 1306 | |
| 1307 | /* |
| 1308 | * The WM8753 supports upto 4 different and mutually exclusive DAI |
| 1309 | * configurations. This gives 2 PCM's available for use, hifi and voice. |
| 1310 | * NOTE: The Voice PCM cannot play or capture audio to the CPU as it's DAI |
| 1311 | * is connected between the wm8753 and a BT codec or GSM modem. |
| 1312 | * |
| 1313 | * 1. Voice over PCM DAI - HIFI DAC over HIFI DAI |
| 1314 | * 2. Voice over HIFI DAI - HIFI disabled |
| 1315 | * 3. Voice disabled - HIFI over HIFI |
| 1316 | * 4. Voice disabled - HIFI over HIFI, uses voice DAI LRC for capture |
| 1317 | */ |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 1318 | static struct snd_soc_dai_ops wm8753_dai_ops_hifi_mode1 = { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1319 | .startup = wm8753_i2s_startup, |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 1320 | .hw_params = wm8753_i2s_hw_params, |
| 1321 | .digital_mute = wm8753_mute, |
| 1322 | .set_fmt = wm8753_mode1h_set_dai_fmt, |
| 1323 | .set_clkdiv = wm8753_set_dai_clkdiv, |
| 1324 | .set_pll = wm8753_set_dai_pll, |
| 1325 | .set_sysclk = wm8753_set_dai_sysclk, |
| 1326 | }; |
| 1327 | |
| 1328 | static struct snd_soc_dai_ops wm8753_dai_ops_voice_mode1 = { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1329 | .startup = wm8753_pcm_startup, |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 1330 | .hw_params = wm8753_pcm_hw_params, |
| 1331 | .digital_mute = wm8753_mute, |
| 1332 | .set_fmt = wm8753_mode1v_set_dai_fmt, |
| 1333 | .set_clkdiv = wm8753_set_dai_clkdiv, |
| 1334 | .set_pll = wm8753_set_dai_pll, |
| 1335 | .set_sysclk = wm8753_set_dai_sysclk, |
| 1336 | }; |
| 1337 | |
| 1338 | static struct snd_soc_dai_ops wm8753_dai_ops_voice_mode2 = { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1339 | .startup = wm8753_pcm_startup, |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 1340 | .hw_params = wm8753_pcm_hw_params, |
| 1341 | .digital_mute = wm8753_mute, |
| 1342 | .set_fmt = wm8753_mode2_set_dai_fmt, |
| 1343 | .set_clkdiv = wm8753_set_dai_clkdiv, |
| 1344 | .set_pll = wm8753_set_dai_pll, |
| 1345 | .set_sysclk = wm8753_set_dai_sysclk, |
| 1346 | }; |
| 1347 | |
| 1348 | static struct snd_soc_dai_ops wm8753_dai_ops_hifi_mode3 = { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1349 | .startup = wm8753_i2s_startup, |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 1350 | .hw_params = wm8753_i2s_hw_params, |
| 1351 | .digital_mute = wm8753_mute, |
| 1352 | .set_fmt = wm8753_mode3_4_set_dai_fmt, |
| 1353 | .set_clkdiv = wm8753_set_dai_clkdiv, |
| 1354 | .set_pll = wm8753_set_dai_pll, |
| 1355 | .set_sysclk = wm8753_set_dai_sysclk, |
| 1356 | }; |
| 1357 | |
| 1358 | static struct snd_soc_dai_ops wm8753_dai_ops_hifi_mode4 = { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1359 | .startup = wm8753_i2s_startup, |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 1360 | .hw_params = wm8753_i2s_hw_params, |
| 1361 | .digital_mute = wm8753_mute, |
| 1362 | .set_fmt = wm8753_mode3_4_set_dai_fmt, |
| 1363 | .set_clkdiv = wm8753_set_dai_clkdiv, |
| 1364 | .set_pll = wm8753_set_dai_pll, |
| 1365 | .set_sysclk = wm8753_set_dai_sysclk, |
| 1366 | }; |
| 1367 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1368 | static struct snd_soc_dai_driver wm8753_all_dai[] = { |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1369 | /* DAI HiFi mode 1 */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1370 | { .name = "wm8753-hifi", |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1371 | .playback = { |
| 1372 | .stream_name = "HiFi Playback", |
| 1373 | .channels_min = 1, |
| 1374 | .channels_max = 2, |
| 1375 | .rates = WM8753_RATES, |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 1376 | .formats = WM8753_FORMATS}, |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1377 | .capture = { /* dummy for fast DAI switching */ |
| 1378 | .stream_name = "Capture", |
| 1379 | .channels_min = 1, |
| 1380 | .channels_max = 2, |
| 1381 | .rates = WM8753_RATES, |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 1382 | .formats = WM8753_FORMATS}, |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 1383 | .ops = &wm8753_dai_ops_hifi_mode1, |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1384 | }, |
| 1385 | /* DAI Voice mode 1 */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1386 | { .name = "wm8753-voice", |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1387 | .playback = { |
| 1388 | .stream_name = "Voice Playback", |
| 1389 | .channels_min = 1, |
| 1390 | .channels_max = 1, |
| 1391 | .rates = WM8753_RATES, |
| 1392 | .formats = WM8753_FORMATS,}, |
| 1393 | .capture = { |
| 1394 | .stream_name = "Capture", |
| 1395 | .channels_min = 1, |
| 1396 | .channels_max = 2, |
| 1397 | .rates = WM8753_RATES, |
| 1398 | .formats = WM8753_FORMATS,}, |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 1399 | .ops = &wm8753_dai_ops_voice_mode1, |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1400 | }, |
| 1401 | /* DAI HiFi mode 2 - dummy */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1402 | { .name = "wm8753-hifi", |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1403 | }, |
| 1404 | /* DAI Voice mode 2 */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1405 | { .name = "wm8753-voice", |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1406 | .playback = { |
| 1407 | .stream_name = "Voice Playback", |
| 1408 | .channels_min = 1, |
| 1409 | .channels_max = 1, |
| 1410 | .rates = WM8753_RATES, |
| 1411 | .formats = WM8753_FORMATS,}, |
| 1412 | .capture = { |
| 1413 | .stream_name = "Capture", |
| 1414 | .channels_min = 1, |
| 1415 | .channels_max = 2, |
| 1416 | .rates = WM8753_RATES, |
| 1417 | .formats = WM8753_FORMATS,}, |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 1418 | .ops = &wm8753_dai_ops_voice_mode2, |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1419 | }, |
| 1420 | /* DAI HiFi mode 3 */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1421 | { .name = "wm8753-hifi", |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1422 | .playback = { |
| 1423 | .stream_name = "HiFi Playback", |
| 1424 | .channels_min = 1, |
| 1425 | .channels_max = 2, |
| 1426 | .rates = WM8753_RATES, |
| 1427 | .formats = WM8753_FORMATS,}, |
| 1428 | .capture = { |
| 1429 | .stream_name = "Capture", |
| 1430 | .channels_min = 1, |
| 1431 | .channels_max = 2, |
| 1432 | .rates = WM8753_RATES, |
| 1433 | .formats = WM8753_FORMATS,}, |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 1434 | .ops = &wm8753_dai_ops_hifi_mode3, |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1435 | }, |
| 1436 | /* DAI Voice mode 3 - dummy */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1437 | { .name = "wm8753-voice", |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1438 | }, |
| 1439 | /* DAI HiFi mode 4 */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1440 | { .name = "wm8753-hifi", |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1441 | .playback = { |
| 1442 | .stream_name = "HiFi Playback", |
| 1443 | .channels_min = 1, |
| 1444 | .channels_max = 2, |
| 1445 | .rates = WM8753_RATES, |
| 1446 | .formats = WM8753_FORMATS,}, |
| 1447 | .capture = { |
| 1448 | .stream_name = "Capture", |
| 1449 | .channels_min = 1, |
| 1450 | .channels_max = 2, |
| 1451 | .rates = WM8753_RATES, |
| 1452 | .formats = WM8753_FORMATS,}, |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 1453 | .ops = &wm8753_dai_ops_hifi_mode4, |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1454 | }, |
| 1455 | /* DAI Voice mode 4 - dummy */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1456 | { .name = "wm8753-voice", |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1457 | }, |
| 1458 | }; |
| 1459 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1460 | static struct snd_soc_dai_driver wm8753_dai[] = { |
Mark Brown | 9e70c1f | 2009-01-29 13:08:20 +0000 | [diff] [blame] | 1461 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1462 | .name = "wm8753-aif0", |
Mark Brown | 9e70c1f | 2009-01-29 13:08:20 +0000 | [diff] [blame] | 1463 | }, |
| 1464 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1465 | .name = "wm8753-aif1", |
Mark Brown | 9e70c1f | 2009-01-29 13:08:20 +0000 | [diff] [blame] | 1466 | }, |
| 1467 | }; |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1468 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1469 | static void wm8753_set_dai_mode(struct snd_soc_codec *codec, |
| 1470 | struct snd_soc_dai *dai, unsigned int hifi) |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1471 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1472 | struct wm8753_priv *wm8753 = snd_soc_codec_get_drvdata(codec); |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1473 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1474 | if (wm8753->dai_func < 4) { |
| 1475 | if (hifi) |
| 1476 | dai->driver = &wm8753_all_dai[wm8753->dai_func << 1]; |
| 1477 | else |
| 1478 | dai->driver = &wm8753_all_dai[(wm8753->dai_func << 1) + 1]; |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1479 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1480 | wm8753_write(codec, WM8753_IOCTL, wm8753->dai_func); |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1481 | } |
| 1482 | |
| 1483 | static void wm8753_work(struct work_struct *work) |
| 1484 | { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1485 | struct snd_soc_dapm_context *dapm = |
| 1486 | container_of(work, struct snd_soc_dapm_context, |
| 1487 | delayed_work.work); |
| 1488 | struct snd_soc_codec *codec = dapm->codec; |
| 1489 | wm8753_set_bias_level(codec, dapm->bias_level); |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1490 | } |
| 1491 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1492 | static int wm8753_suspend(struct snd_soc_codec *codec, pm_message_t state) |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1493 | { |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1494 | wm8753_set_bias_level(codec, SND_SOC_BIAS_OFF); |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1495 | return 0; |
| 1496 | } |
| 1497 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1498 | static int wm8753_resume(struct snd_soc_codec *codec) |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1499 | { |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1500 | int i; |
| 1501 | u8 data[2]; |
| 1502 | u16 *cache = codec->reg_cache; |
| 1503 | |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1504 | /* Sync reg_cache with the hardware */ |
| 1505 | for (i = 0; i < ARRAY_SIZE(wm8753_reg); i++) { |
| 1506 | if (i + 1 == WM8753_RESET) |
| 1507 | continue; |
Mark Brown | e611bd8 | 2009-02-22 20:04:41 +0000 | [diff] [blame] | 1508 | |
| 1509 | /* No point in writing hardware default values back */ |
| 1510 | if (cache[i] == wm8753_reg[i]) |
| 1511 | continue; |
| 1512 | |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1513 | data[0] = ((i + 1) << 1) | ((cache[i] >> 8) & 0x0001); |
| 1514 | data[1] = cache[i] & 0x00ff; |
| 1515 | codec->hw_write(codec->control_data, data, 2); |
| 1516 | } |
| 1517 | |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1518 | wm8753_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1519 | |
| 1520 | /* charge wm8753 caps */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1521 | if (codec->dapm.suspend_bias_level == SND_SOC_BIAS_ON) { |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1522 | wm8753_set_bias_level(codec, SND_SOC_BIAS_PREPARE); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1523 | codec->dapm.bias_level = SND_SOC_BIAS_ON; |
| 1524 | schedule_delayed_work(&codec->dapm.delayed_work, |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1525 | msecs_to_jiffies(caps_charge)); |
| 1526 | } |
| 1527 | |
| 1528 | return 0; |
| 1529 | } |
| 1530 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1531 | static int wm8753_probe(struct snd_soc_codec *codec) |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1532 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1533 | struct wm8753_priv *wm8753 = snd_soc_codec_get_drvdata(codec); |
| 1534 | int ret = 0, reg; |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1535 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1536 | INIT_DELAYED_WORK(&codec->dapm.delayed_work, wm8753_work); |
Mark Brown | c2bac16 | 2009-02-24 23:33:12 +0000 | [diff] [blame] | 1537 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1538 | ret = snd_soc_codec_set_cache_io(codec, 7, 9, wm8753->control_type); |
| 1539 | if (ret < 0) { |
| 1540 | dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); |
| 1541 | return ret; |
| 1542 | } |
| 1543 | |
Mark Brown | c2bac16 | 2009-02-24 23:33:12 +0000 | [diff] [blame] | 1544 | ret = wm8753_reset(codec); |
| 1545 | if (ret < 0) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1546 | dev_err(codec->dev, "Failed to issue reset: %d\n", ret); |
| 1547 | return ret; |
Mark Brown | c2bac16 | 2009-02-24 23:33:12 +0000 | [diff] [blame] | 1548 | } |
| 1549 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1550 | wm8753_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
| 1551 | wm8753->dai_func = 0; |
| 1552 | |
Mark Brown | c2bac16 | 2009-02-24 23:33:12 +0000 | [diff] [blame] | 1553 | /* charge output caps */ |
| 1554 | wm8753_set_bias_level(codec, SND_SOC_BIAS_PREPARE); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1555 | schedule_delayed_work(&codec->dapm.delayed_work, |
Mark Brown | c2bac16 | 2009-02-24 23:33:12 +0000 | [diff] [blame] | 1556 | msecs_to_jiffies(caps_charge)); |
| 1557 | |
| 1558 | /* set the update bits */ |
| 1559 | reg = wm8753_read_reg_cache(codec, WM8753_LDAC); |
| 1560 | wm8753_write(codec, WM8753_LDAC, reg | 0x0100); |
| 1561 | reg = wm8753_read_reg_cache(codec, WM8753_RDAC); |
| 1562 | wm8753_write(codec, WM8753_RDAC, reg | 0x0100); |
| 1563 | reg = wm8753_read_reg_cache(codec, WM8753_LADC); |
| 1564 | wm8753_write(codec, WM8753_LADC, reg | 0x0100); |
| 1565 | reg = wm8753_read_reg_cache(codec, WM8753_RADC); |
| 1566 | wm8753_write(codec, WM8753_RADC, reg | 0x0100); |
| 1567 | reg = wm8753_read_reg_cache(codec, WM8753_LOUT1V); |
| 1568 | wm8753_write(codec, WM8753_LOUT1V, reg | 0x0100); |
| 1569 | reg = wm8753_read_reg_cache(codec, WM8753_ROUT1V); |
| 1570 | wm8753_write(codec, WM8753_ROUT1V, reg | 0x0100); |
| 1571 | reg = wm8753_read_reg_cache(codec, WM8753_LOUT2V); |
| 1572 | wm8753_write(codec, WM8753_LOUT2V, reg | 0x0100); |
| 1573 | reg = wm8753_read_reg_cache(codec, WM8753_ROUT2V); |
| 1574 | wm8753_write(codec, WM8753_ROUT2V, reg | 0x0100); |
| 1575 | reg = wm8753_read_reg_cache(codec, WM8753_LINVOL); |
| 1576 | wm8753_write(codec, WM8753_LINVOL, reg | 0x0100); |
| 1577 | reg = wm8753_read_reg_cache(codec, WM8753_RINVOL); |
| 1578 | wm8753_write(codec, WM8753_RINVOL, reg | 0x0100); |
| 1579 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1580 | snd_soc_add_controls(codec, wm8753_snd_controls, |
| 1581 | ARRAY_SIZE(wm8753_snd_controls)); |
| 1582 | wm8753_add_widgets(codec); |
Mark Brown | c2bac16 | 2009-02-24 23:33:12 +0000 | [diff] [blame] | 1583 | |
| 1584 | return 0; |
Mark Brown | c2bac16 | 2009-02-24 23:33:12 +0000 | [diff] [blame] | 1585 | } |
| 1586 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1587 | /* power down chip */ |
| 1588 | static int wm8753_remove(struct snd_soc_codec *codec) |
Mark Brown | c2bac16 | 2009-02-24 23:33:12 +0000 | [diff] [blame] | 1589 | { |
Takashi Iwai | fdea057 | 2010-12-13 12:55:39 +0100 | [diff] [blame^] | 1590 | flush_delayed_work_sync(&codec->dapm.delayed_work); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1591 | wm8753_set_bias_level(codec, SND_SOC_BIAS_OFF); |
| 1592 | |
| 1593 | return 0; |
Mark Brown | c2bac16 | 2009-02-24 23:33:12 +0000 | [diff] [blame] | 1594 | } |
| 1595 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1596 | static struct snd_soc_codec_driver soc_codec_dev_wm8753 = { |
| 1597 | .probe = wm8753_probe, |
| 1598 | .remove = wm8753_remove, |
| 1599 | .suspend = wm8753_suspend, |
| 1600 | .resume = wm8753_resume, |
| 1601 | .set_bias_level = wm8753_set_bias_level, |
Dimitris Papastamos | e5eec34 | 2010-09-10 18:14:56 +0100 | [diff] [blame] | 1602 | .reg_cache_size = ARRAY_SIZE(wm8753_reg), |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1603 | .reg_word_size = sizeof(u16), |
| 1604 | .reg_cache_default = wm8753_reg, |
| 1605 | }; |
Mark Brown | 69e169d | 2009-02-22 14:39:03 +0000 | [diff] [blame] | 1606 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1607 | #if defined(CONFIG_SPI_MASTER) |
| 1608 | static int __devinit wm8753_spi_probe(struct spi_device *spi) |
Mark Brown | 69e169d | 2009-02-22 14:39:03 +0000 | [diff] [blame] | 1609 | { |
Mark Brown | c2bac16 | 2009-02-24 23:33:12 +0000 | [diff] [blame] | 1610 | struct wm8753_priv *wm8753; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1611 | int ret; |
Mark Brown | 69e169d | 2009-02-22 14:39:03 +0000 | [diff] [blame] | 1612 | |
Mark Brown | c2bac16 | 2009-02-24 23:33:12 +0000 | [diff] [blame] | 1613 | wm8753 = kzalloc(sizeof(struct wm8753_priv), GFP_KERNEL); |
| 1614 | if (wm8753 == NULL) |
| 1615 | return -ENOMEM; |
Mark Brown | 69e169d | 2009-02-22 14:39:03 +0000 | [diff] [blame] | 1616 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1617 | wm8753->control_type = SND_SOC_SPI; |
| 1618 | spi_set_drvdata(spi, wm8753); |
Mark Brown | 69e169d | 2009-02-22 14:39:03 +0000 | [diff] [blame] | 1619 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1620 | ret = snd_soc_register_codec(&spi->dev, |
| 1621 | &soc_codec_dev_wm8753, wm8753_dai, ARRAY_SIZE(wm8753_dai)); |
| 1622 | if (ret < 0) |
| 1623 | kfree(wm8753); |
| 1624 | return ret; |
Mark Brown | 69e169d | 2009-02-22 14:39:03 +0000 | [diff] [blame] | 1625 | } |
| 1626 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1627 | static int __devexit wm8753_spi_remove(struct spi_device *spi) |
Mark Brown | 69e169d | 2009-02-22 14:39:03 +0000 | [diff] [blame] | 1628 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1629 | snd_soc_unregister_codec(&spi->dev); |
| 1630 | kfree(spi_get_drvdata(spi)); |
| 1631 | return 0; |
| 1632 | } |
| 1633 | |
| 1634 | static struct spi_driver wm8753_spi_driver = { |
| 1635 | .driver = { |
| 1636 | .name = "wm8753-codec", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1637 | .owner = THIS_MODULE, |
| 1638 | }, |
| 1639 | .probe = wm8753_spi_probe, |
| 1640 | .remove = __devexit_p(wm8753_spi_remove), |
| 1641 | }; |
| 1642 | #endif /* CONFIG_SPI_MASTER */ |
| 1643 | |
| 1644 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
| 1645 | static __devinit int wm8753_i2c_probe(struct i2c_client *i2c, |
| 1646 | const struct i2c_device_id *id) |
| 1647 | { |
| 1648 | struct wm8753_priv *wm8753; |
| 1649 | int ret; |
| 1650 | |
| 1651 | wm8753 = kzalloc(sizeof(struct wm8753_priv), GFP_KERNEL); |
| 1652 | if (wm8753 == NULL) |
| 1653 | return -ENOMEM; |
| 1654 | |
| 1655 | i2c_set_clientdata(i2c, wm8753); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1656 | wm8753->control_type = SND_SOC_I2C; |
| 1657 | |
| 1658 | ret = snd_soc_register_codec(&i2c->dev, |
| 1659 | &soc_codec_dev_wm8753, wm8753_dai, ARRAY_SIZE(wm8753_dai)); |
| 1660 | if (ret < 0) |
| 1661 | kfree(wm8753); |
| 1662 | return ret; |
| 1663 | } |
| 1664 | |
| 1665 | static __devexit int wm8753_i2c_remove(struct i2c_client *client) |
| 1666 | { |
| 1667 | snd_soc_unregister_codec(&client->dev); |
| 1668 | kfree(i2c_get_clientdata(client)); |
| 1669 | return 0; |
Mark Brown | 69e169d | 2009-02-22 14:39:03 +0000 | [diff] [blame] | 1670 | } |
| 1671 | |
| 1672 | static const struct i2c_device_id wm8753_i2c_id[] = { |
| 1673 | { "wm8753", 0 }, |
| 1674 | { } |
| 1675 | }; |
| 1676 | MODULE_DEVICE_TABLE(i2c, wm8753_i2c_id); |
| 1677 | |
| 1678 | static struct i2c_driver wm8753_i2c_driver = { |
| 1679 | .driver = { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1680 | .name = "wm8753-codec", |
Mark Brown | 69e169d | 2009-02-22 14:39:03 +0000 | [diff] [blame] | 1681 | .owner = THIS_MODULE, |
| 1682 | }, |
| 1683 | .probe = wm8753_i2c_probe, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1684 | .remove = __devexit_p(wm8753_i2c_remove), |
Mark Brown | 69e169d | 2009-02-22 14:39:03 +0000 | [diff] [blame] | 1685 | .id_table = wm8753_i2c_id, |
| 1686 | }; |
| 1687 | #endif |
| 1688 | |
Takashi Iwai | c9b3a40 | 2008-12-10 07:47:22 +0100 | [diff] [blame] | 1689 | static int __init wm8753_modinit(void) |
Mark Brown | 64089b8 | 2008-12-08 19:17:58 +0000 | [diff] [blame] | 1690 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1691 | int ret = 0; |
Mark Brown | c2bac16 | 2009-02-24 23:33:12 +0000 | [diff] [blame] | 1692 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
| 1693 | ret = i2c_add_driver(&wm8753_i2c_driver); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1694 | if (ret != 0) { |
| 1695 | printk(KERN_ERR "Failed to register wm8753 I2C driver: %d\n", |
| 1696 | ret); |
| 1697 | } |
Mark Brown | c2bac16 | 2009-02-24 23:33:12 +0000 | [diff] [blame] | 1698 | #endif |
| 1699 | #if defined(CONFIG_SPI_MASTER) |
| 1700 | ret = spi_register_driver(&wm8753_spi_driver); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1701 | if (ret != 0) { |
| 1702 | printk(KERN_ERR "Failed to register wm8753 SPI driver: %d\n", |
| 1703 | ret); |
| 1704 | } |
Mark Brown | c2bac16 | 2009-02-24 23:33:12 +0000 | [diff] [blame] | 1705 | #endif |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1706 | return ret; |
Mark Brown | 64089b8 | 2008-12-08 19:17:58 +0000 | [diff] [blame] | 1707 | } |
| 1708 | module_init(wm8753_modinit); |
| 1709 | |
| 1710 | static void __exit wm8753_exit(void) |
| 1711 | { |
Mark Brown | c2bac16 | 2009-02-24 23:33:12 +0000 | [diff] [blame] | 1712 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
| 1713 | i2c_del_driver(&wm8753_i2c_driver); |
| 1714 | #endif |
| 1715 | #if defined(CONFIG_SPI_MASTER) |
| 1716 | spi_unregister_driver(&wm8753_spi_driver); |
| 1717 | #endif |
Mark Brown | 64089b8 | 2008-12-08 19:17:58 +0000 | [diff] [blame] | 1718 | } |
| 1719 | module_exit(wm8753_exit); |
| 1720 | |
Liam Girdwood | 1f53aee | 2007-04-16 19:17:44 +0200 | [diff] [blame] | 1721 | MODULE_DESCRIPTION("ASoC WM8753 driver"); |
| 1722 | MODULE_AUTHOR("Liam Girdwood"); |
| 1723 | MODULE_LICENSE("GPL"); |