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