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