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