Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 1 | /* |
| 2 | * wm8996.c - WM8996 audio codec interface |
| 3 | * |
| 4 | * Copyright 2011 Wolfson Microelectronics PLC. |
| 5 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> |
| 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 | |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/moduleparam.h> |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/completion.h> |
| 17 | #include <linux/delay.h> |
| 18 | #include <linux/pm.h> |
| 19 | #include <linux/gcd.h> |
| 20 | #include <linux/gpio.h> |
| 21 | #include <linux/i2c.h> |
Mark Brown | 7917274 | 2011-09-19 16:15:58 +0100 | [diff] [blame] | 22 | #include <linux/regmap.h> |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 23 | #include <linux/regulator/consumer.h> |
| 24 | #include <linux/slab.h> |
| 25 | #include <linux/workqueue.h> |
| 26 | #include <sound/core.h> |
| 27 | #include <sound/jack.h> |
| 28 | #include <sound/pcm.h> |
| 29 | #include <sound/pcm_params.h> |
| 30 | #include <sound/soc.h> |
| 31 | #include <sound/initval.h> |
| 32 | #include <sound/tlv.h> |
| 33 | #include <trace/events/asoc.h> |
| 34 | |
| 35 | #include <sound/wm8996.h> |
| 36 | #include "wm8996.h" |
| 37 | |
| 38 | #define WM8996_AIFS 2 |
| 39 | |
| 40 | #define HPOUT1L 1 |
| 41 | #define HPOUT1R 2 |
| 42 | #define HPOUT2L 4 |
| 43 | #define HPOUT2R 8 |
| 44 | |
Mark Brown | c83495a | 2011-09-11 10:05:18 +0100 | [diff] [blame] | 45 | #define WM8996_NUM_SUPPLIES 3 |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 46 | static const char *wm8996_supply_names[WM8996_NUM_SUPPLIES] = { |
| 47 | "DBVDD", |
| 48 | "AVDD1", |
| 49 | "AVDD2", |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | struct wm8996_priv { |
Mark Brown | b2d1e23 | 2011-09-19 23:04:06 +0100 | [diff] [blame] | 53 | struct device *dev; |
Mark Brown | ee5f387 | 2011-09-19 19:51:07 +0100 | [diff] [blame] | 54 | struct regmap *regmap; |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 55 | struct snd_soc_codec *codec; |
| 56 | |
| 57 | int ldo1ena; |
| 58 | |
| 59 | int sysclk; |
| 60 | int sysclk_src; |
| 61 | |
| 62 | int fll_src; |
| 63 | int fll_fref; |
| 64 | int fll_fout; |
| 65 | |
| 66 | struct completion fll_lock; |
| 67 | |
| 68 | u16 dcs_pending; |
| 69 | struct completion dcs_done; |
| 70 | |
| 71 | u16 hpout_ena; |
| 72 | u16 hpout_pending; |
| 73 | |
| 74 | struct regulator_bulk_data supplies[WM8996_NUM_SUPPLIES]; |
| 75 | struct notifier_block disable_nb[WM8996_NUM_SUPPLIES]; |
Mark Brown | c83495a | 2011-09-11 10:05:18 +0100 | [diff] [blame] | 76 | struct regulator *cpvdd; |
Mark Brown | ded71dc | 2011-09-19 18:50:05 +0100 | [diff] [blame] | 77 | int bg_ena; |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 78 | |
| 79 | struct wm8996_pdata pdata; |
| 80 | |
| 81 | int rx_rate[WM8996_AIFS]; |
| 82 | int bclk_rate[WM8996_AIFS]; |
| 83 | |
| 84 | /* Platform dependant ReTune mobile configuration */ |
| 85 | int num_retune_mobile_texts; |
| 86 | const char **retune_mobile_texts; |
| 87 | int retune_mobile_cfg[2]; |
| 88 | struct soc_enum retune_mobile_enum; |
| 89 | |
| 90 | struct snd_soc_jack *jack; |
| 91 | bool detecting; |
| 92 | bool jack_mic; |
Mark Brown | d7b3557 | 2012-01-26 18:00:42 +0000 | [diff] [blame] | 93 | int jack_flips; |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 94 | wm8996_polarity_fn polarity_cb; |
| 95 | |
| 96 | #ifdef CONFIG_GPIOLIB |
| 97 | struct gpio_chip gpio_chip; |
| 98 | #endif |
| 99 | }; |
| 100 | |
| 101 | /* We can't use the same notifier block for more than one supply and |
| 102 | * there's no way I can see to get from a callback to the caller |
| 103 | * except container_of(). |
| 104 | */ |
| 105 | #define WM8996_REGULATOR_EVENT(n) \ |
| 106 | static int wm8996_regulator_event_##n(struct notifier_block *nb, \ |
| 107 | unsigned long event, void *data) \ |
| 108 | { \ |
| 109 | struct wm8996_priv *wm8996 = container_of(nb, struct wm8996_priv, \ |
| 110 | disable_nb[n]); \ |
| 111 | if (event & REGULATOR_EVENT_DISABLE) { \ |
Mark Brown | ee5f387 | 2011-09-19 19:51:07 +0100 | [diff] [blame] | 112 | regcache_cache_only(wm8996->regmap, true); \ |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 113 | } \ |
| 114 | return 0; \ |
| 115 | } |
| 116 | |
| 117 | WM8996_REGULATOR_EVENT(0) |
| 118 | WM8996_REGULATOR_EVENT(1) |
| 119 | WM8996_REGULATOR_EVENT(2) |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 120 | |
Mark Brown | 7917274 | 2011-09-19 16:15:58 +0100 | [diff] [blame] | 121 | static struct reg_default wm8996_reg[] = { |
| 122 | { WM8996_SOFTWARE_RESET, 0x8996 }, |
| 123 | { WM8996_POWER_MANAGEMENT_1, 0x0 }, |
| 124 | { WM8996_POWER_MANAGEMENT_2, 0x0 }, |
| 125 | { WM8996_POWER_MANAGEMENT_3, 0x0 }, |
| 126 | { WM8996_POWER_MANAGEMENT_4, 0x0 }, |
| 127 | { WM8996_POWER_MANAGEMENT_5, 0x0 }, |
| 128 | { WM8996_POWER_MANAGEMENT_6, 0x0 }, |
| 129 | { WM8996_POWER_MANAGEMENT_7, 0x10 }, |
| 130 | { WM8996_POWER_MANAGEMENT_8, 0x0 }, |
| 131 | { WM8996_LEFT_LINE_INPUT_VOLUME, 0x0 }, |
| 132 | { WM8996_RIGHT_LINE_INPUT_VOLUME, 0x0 }, |
| 133 | { WM8996_LINE_INPUT_CONTROL, 0x0 }, |
| 134 | { WM8996_DAC1_HPOUT1_VOLUME, 0x88 }, |
| 135 | { WM8996_DAC2_HPOUT2_VOLUME, 0x88 }, |
| 136 | { WM8996_DAC1_LEFT_VOLUME, 0x2c0 }, |
| 137 | { WM8996_DAC1_RIGHT_VOLUME, 0x2c0 }, |
| 138 | { WM8996_DAC2_LEFT_VOLUME, 0x2c0 }, |
| 139 | { WM8996_DAC2_RIGHT_VOLUME, 0x2c0 }, |
| 140 | { WM8996_OUTPUT1_LEFT_VOLUME, 0x80 }, |
| 141 | { WM8996_OUTPUT1_RIGHT_VOLUME, 0x80 }, |
| 142 | { WM8996_OUTPUT2_LEFT_VOLUME, 0x80 }, |
| 143 | { WM8996_OUTPUT2_RIGHT_VOLUME, 0x80 }, |
| 144 | { WM8996_MICBIAS_1, 0x39 }, |
| 145 | { WM8996_MICBIAS_2, 0x39 }, |
| 146 | { WM8996_LDO_1, 0x3 }, |
| 147 | { WM8996_LDO_2, 0x13 }, |
| 148 | { WM8996_ACCESSORY_DETECT_MODE_1, 0x4 }, |
| 149 | { WM8996_ACCESSORY_DETECT_MODE_2, 0x0 }, |
| 150 | { WM8996_HEADPHONE_DETECT_1, 0x20 }, |
| 151 | { WM8996_HEADPHONE_DETECT_2, 0x0 }, |
| 152 | { WM8996_MIC_DETECT_1, 0x7600 }, |
| 153 | { WM8996_MIC_DETECT_2, 0xbf }, |
| 154 | { WM8996_CHARGE_PUMP_1, 0x1f25 }, |
| 155 | { WM8996_CHARGE_PUMP_2, 0xab19 }, |
| 156 | { WM8996_DC_SERVO_1, 0x0 }, |
| 157 | { WM8996_DC_SERVO_2, 0x0 }, |
| 158 | { WM8996_DC_SERVO_3, 0x0 }, |
| 159 | { WM8996_DC_SERVO_5, 0x2a2a }, |
| 160 | { WM8996_DC_SERVO_6, 0x0 }, |
| 161 | { WM8996_DC_SERVO_7, 0x0 }, |
| 162 | { WM8996_ANALOGUE_HP_1, 0x0 }, |
| 163 | { WM8996_ANALOGUE_HP_2, 0x0 }, |
| 164 | { WM8996_CONTROL_INTERFACE_1, 0x8004 }, |
| 165 | { WM8996_WRITE_SEQUENCER_CTRL_1, 0x0 }, |
| 166 | { WM8996_WRITE_SEQUENCER_CTRL_2, 0x0 }, |
| 167 | { WM8996_AIF_CLOCKING_1, 0x0 }, |
| 168 | { WM8996_AIF_CLOCKING_2, 0x0 }, |
| 169 | { WM8996_CLOCKING_1, 0x10 }, |
| 170 | { WM8996_CLOCKING_2, 0x0 }, |
| 171 | { WM8996_AIF_RATE, 0x83 }, |
| 172 | { WM8996_FLL_CONTROL_1, 0x0 }, |
| 173 | { WM8996_FLL_CONTROL_2, 0x0 }, |
| 174 | { WM8996_FLL_CONTROL_3, 0x0 }, |
| 175 | { WM8996_FLL_CONTROL_4, 0x5dc0 }, |
| 176 | { WM8996_FLL_CONTROL_5, 0xc84 }, |
| 177 | { WM8996_FLL_EFS_1, 0x0 }, |
| 178 | { WM8996_FLL_EFS_2, 0x2 }, |
| 179 | { WM8996_AIF1_CONTROL, 0x0 }, |
| 180 | { WM8996_AIF1_BCLK, 0x0 }, |
| 181 | { WM8996_AIF1_TX_LRCLK_1, 0x80 }, |
| 182 | { WM8996_AIF1_TX_LRCLK_2, 0x8 }, |
| 183 | { WM8996_AIF1_RX_LRCLK_1, 0x80 }, |
| 184 | { WM8996_AIF1_RX_LRCLK_2, 0x0 }, |
| 185 | { WM8996_AIF1TX_DATA_CONFIGURATION_1, 0x1818 }, |
| 186 | { WM8996_AIF1TX_DATA_CONFIGURATION_2, 0 }, |
| 187 | { WM8996_AIF1RX_DATA_CONFIGURATION, 0x1818 }, |
| 188 | { WM8996_AIF1TX_CHANNEL_0_CONFIGURATION, 0x0 }, |
| 189 | { WM8996_AIF1TX_CHANNEL_1_CONFIGURATION, 0x0 }, |
| 190 | { WM8996_AIF1TX_CHANNEL_2_CONFIGURATION, 0x0 }, |
| 191 | { WM8996_AIF1TX_CHANNEL_3_CONFIGURATION, 0x0 }, |
| 192 | { WM8996_AIF1TX_CHANNEL_4_CONFIGURATION, 0x0 }, |
| 193 | { WM8996_AIF1TX_CHANNEL_5_CONFIGURATION, 0x0 }, |
| 194 | { WM8996_AIF1RX_CHANNEL_0_CONFIGURATION, 0x0 }, |
| 195 | { WM8996_AIF1RX_CHANNEL_1_CONFIGURATION, 0x0 }, |
| 196 | { WM8996_AIF1RX_CHANNEL_2_CONFIGURATION, 0x0 }, |
| 197 | { WM8996_AIF1RX_CHANNEL_3_CONFIGURATION, 0x0 }, |
| 198 | { WM8996_AIF1RX_CHANNEL_4_CONFIGURATION, 0x0 }, |
| 199 | { WM8996_AIF1RX_CHANNEL_5_CONFIGURATION, 0x0 }, |
| 200 | { WM8996_AIF1RX_MONO_CONFIGURATION, 0x0 }, |
| 201 | { WM8996_AIF1TX_TEST, 0x7 }, |
| 202 | { WM8996_AIF2_CONTROL, 0x0 }, |
| 203 | { WM8996_AIF2_BCLK, 0x0 }, |
| 204 | { WM8996_AIF2_TX_LRCLK_1, 0x80 }, |
| 205 | { WM8996_AIF2_TX_LRCLK_2, 0x8 }, |
| 206 | { WM8996_AIF2_RX_LRCLK_1, 0x80 }, |
| 207 | { WM8996_AIF2_RX_LRCLK_2, 0x0 }, |
| 208 | { WM8996_AIF2TX_DATA_CONFIGURATION_1, 0x1818 }, |
| 209 | { WM8996_AIF2RX_DATA_CONFIGURATION, 0x1818 }, |
| 210 | { WM8996_AIF2RX_DATA_CONFIGURATION, 0x0 }, |
| 211 | { WM8996_AIF2TX_CHANNEL_0_CONFIGURATION, 0x0 }, |
| 212 | { WM8996_AIF2TX_CHANNEL_1_CONFIGURATION, 0x0 }, |
| 213 | { WM8996_AIF2RX_CHANNEL_0_CONFIGURATION, 0x0 }, |
| 214 | { WM8996_AIF2RX_CHANNEL_1_CONFIGURATION, 0x0 }, |
| 215 | { WM8996_AIF2RX_MONO_CONFIGURATION, 0x0 }, |
| 216 | { WM8996_AIF2TX_TEST, 0x1 }, |
| 217 | { WM8996_DSP1_TX_LEFT_VOLUME, 0xc0 }, |
| 218 | { WM8996_DSP1_TX_RIGHT_VOLUME, 0xc0 }, |
| 219 | { WM8996_DSP1_RX_LEFT_VOLUME, 0xc0 }, |
| 220 | { WM8996_DSP1_RX_RIGHT_VOLUME, 0xc0 }, |
| 221 | { WM8996_DSP1_TX_FILTERS, 0x2000 }, |
| 222 | { WM8996_DSP1_RX_FILTERS_1, 0x200 }, |
| 223 | { WM8996_DSP1_RX_FILTERS_2, 0x10 }, |
| 224 | { WM8996_DSP1_DRC_1, 0x98 }, |
| 225 | { WM8996_DSP1_DRC_2, 0x845 }, |
| 226 | { WM8996_DSP1_RX_EQ_GAINS_1, 0x6318 }, |
| 227 | { WM8996_DSP1_RX_EQ_GAINS_2, 0x6300 }, |
| 228 | { WM8996_DSP1_RX_EQ_BAND_1_A, 0xfca }, |
| 229 | { WM8996_DSP1_RX_EQ_BAND_1_B, 0x400 }, |
| 230 | { WM8996_DSP1_RX_EQ_BAND_1_PG, 0xd8 }, |
| 231 | { WM8996_DSP1_RX_EQ_BAND_2_A, 0x1eb5 }, |
| 232 | { WM8996_DSP1_RX_EQ_BAND_2_B, 0xf145 }, |
| 233 | { WM8996_DSP1_RX_EQ_BAND_2_C, 0xb75 }, |
| 234 | { WM8996_DSP1_RX_EQ_BAND_2_PG, 0x1c5 }, |
| 235 | { WM8996_DSP1_RX_EQ_BAND_3_A, 0x1c58 }, |
| 236 | { WM8996_DSP1_RX_EQ_BAND_3_B, 0xf373 }, |
| 237 | { WM8996_DSP1_RX_EQ_BAND_3_C, 0xa54 }, |
| 238 | { WM8996_DSP1_RX_EQ_BAND_3_PG, 0x558 }, |
| 239 | { WM8996_DSP1_RX_EQ_BAND_4_A, 0x168e }, |
| 240 | { WM8996_DSP1_RX_EQ_BAND_4_B, 0xf829 }, |
| 241 | { WM8996_DSP1_RX_EQ_BAND_4_C, 0x7ad }, |
| 242 | { WM8996_DSP1_RX_EQ_BAND_4_PG, 0x1103 }, |
| 243 | { WM8996_DSP1_RX_EQ_BAND_5_A, 0x564 }, |
| 244 | { WM8996_DSP1_RX_EQ_BAND_5_B, 0x559 }, |
| 245 | { WM8996_DSP1_RX_EQ_BAND_5_PG, 0x4000 }, |
| 246 | { WM8996_DSP2_TX_LEFT_VOLUME, 0xc0 }, |
| 247 | { WM8996_DSP2_TX_RIGHT_VOLUME, 0xc0 }, |
| 248 | { WM8996_DSP2_RX_LEFT_VOLUME, 0xc0 }, |
| 249 | { WM8996_DSP2_RX_RIGHT_VOLUME, 0xc0 }, |
| 250 | { WM8996_DSP2_TX_FILTERS, 0x2000 }, |
| 251 | { WM8996_DSP2_RX_FILTERS_1, 0x200 }, |
| 252 | { WM8996_DSP2_RX_FILTERS_2, 0x10 }, |
| 253 | { WM8996_DSP2_DRC_1, 0x98 }, |
| 254 | { WM8996_DSP2_DRC_2, 0x845 }, |
| 255 | { WM8996_DSP2_RX_EQ_GAINS_1, 0x6318 }, |
| 256 | { WM8996_DSP2_RX_EQ_GAINS_2, 0x6300 }, |
| 257 | { WM8996_DSP2_RX_EQ_BAND_1_A, 0xfca }, |
| 258 | { WM8996_DSP2_RX_EQ_BAND_1_B, 0x400 }, |
| 259 | { WM8996_DSP2_RX_EQ_BAND_1_PG, 0xd8 }, |
| 260 | { WM8996_DSP2_RX_EQ_BAND_2_A, 0x1eb5 }, |
| 261 | { WM8996_DSP2_RX_EQ_BAND_2_B, 0xf145 }, |
| 262 | { WM8996_DSP2_RX_EQ_BAND_2_C, 0xb75 }, |
| 263 | { WM8996_DSP2_RX_EQ_BAND_2_PG, 0x1c5 }, |
| 264 | { WM8996_DSP2_RX_EQ_BAND_3_A, 0x1c58 }, |
| 265 | { WM8996_DSP2_RX_EQ_BAND_3_B, 0xf373 }, |
| 266 | { WM8996_DSP2_RX_EQ_BAND_3_C, 0xa54 }, |
| 267 | { WM8996_DSP2_RX_EQ_BAND_3_PG, 0x558 }, |
| 268 | { WM8996_DSP2_RX_EQ_BAND_4_A, 0x168e }, |
| 269 | { WM8996_DSP2_RX_EQ_BAND_4_B, 0xf829 }, |
| 270 | { WM8996_DSP2_RX_EQ_BAND_4_C, 0x7ad }, |
| 271 | { WM8996_DSP2_RX_EQ_BAND_4_PG, 0x1103 }, |
| 272 | { WM8996_DSP2_RX_EQ_BAND_5_A, 0x564 }, |
| 273 | { WM8996_DSP2_RX_EQ_BAND_5_B, 0x559 }, |
| 274 | { WM8996_DSP2_RX_EQ_BAND_5_PG, 0x4000 }, |
| 275 | { WM8996_DAC1_MIXER_VOLUMES, 0x0 }, |
| 276 | { WM8996_DAC1_LEFT_MIXER_ROUTING, 0x0 }, |
| 277 | { WM8996_DAC1_RIGHT_MIXER_ROUTING, 0x0 }, |
| 278 | { WM8996_DAC2_MIXER_VOLUMES, 0x0 }, |
| 279 | { WM8996_DAC2_LEFT_MIXER_ROUTING, 0x0 }, |
| 280 | { WM8996_DAC2_RIGHT_MIXER_ROUTING, 0x0 }, |
| 281 | { WM8996_DSP1_TX_LEFT_MIXER_ROUTING, 0x0 }, |
| 282 | { WM8996_DSP1_TX_RIGHT_MIXER_ROUTING, 0x0 }, |
| 283 | { WM8996_DSP2_TX_LEFT_MIXER_ROUTING, 0x0 }, |
| 284 | { WM8996_DSP2_TX_RIGHT_MIXER_ROUTING, 0x0 }, |
| 285 | { WM8996_DSP_TX_MIXER_SELECT, 0x0 }, |
| 286 | { WM8996_DAC_SOFTMUTE, 0x0 }, |
| 287 | { WM8996_OVERSAMPLING, 0xd }, |
| 288 | { WM8996_SIDETONE, 0x1040 }, |
| 289 | { WM8996_GPIO_1, 0xa101 }, |
| 290 | { WM8996_GPIO_2, 0xa101 }, |
| 291 | { WM8996_GPIO_3, 0xa101 }, |
| 292 | { WM8996_GPIO_4, 0xa101 }, |
| 293 | { WM8996_GPIO_5, 0xa101 }, |
| 294 | { WM8996_PULL_CONTROL_1, 0x0 }, |
| 295 | { WM8996_PULL_CONTROL_2, 0x140 }, |
| 296 | { WM8996_INTERRUPT_STATUS_1_MASK, 0x1f }, |
| 297 | { WM8996_INTERRUPT_STATUS_2_MASK, 0x1ecf }, |
| 298 | { WM8996_LEFT_PDM_SPEAKER, 0x0 }, |
| 299 | { WM8996_RIGHT_PDM_SPEAKER, 0x1 }, |
| 300 | { WM8996_PDM_SPEAKER_MUTE_SEQUENCE, 0x69 }, |
| 301 | { WM8996_PDM_SPEAKER_VOLUME, 0x66 }, |
| 302 | { WM8996_WRITE_SEQUENCER_0, 0x1 }, |
| 303 | { WM8996_WRITE_SEQUENCER_1, 0x1 }, |
| 304 | { WM8996_WRITE_SEQUENCER_3, 0x6 }, |
| 305 | { WM8996_WRITE_SEQUENCER_4, 0x40 }, |
| 306 | { WM8996_WRITE_SEQUENCER_5, 0x1 }, |
| 307 | { WM8996_WRITE_SEQUENCER_6, 0xf }, |
| 308 | { WM8996_WRITE_SEQUENCER_7, 0x6 }, |
| 309 | { WM8996_WRITE_SEQUENCER_8, 0x1 }, |
| 310 | { WM8996_WRITE_SEQUENCER_9, 0x3 }, |
| 311 | { WM8996_WRITE_SEQUENCER_10, 0x104 }, |
| 312 | { WM8996_WRITE_SEQUENCER_12, 0x60 }, |
| 313 | { WM8996_WRITE_SEQUENCER_13, 0x11 }, |
| 314 | { WM8996_WRITE_SEQUENCER_14, 0x401 }, |
| 315 | { WM8996_WRITE_SEQUENCER_16, 0x50 }, |
| 316 | { WM8996_WRITE_SEQUENCER_17, 0x3 }, |
| 317 | { WM8996_WRITE_SEQUENCER_18, 0x100 }, |
| 318 | { WM8996_WRITE_SEQUENCER_20, 0x51 }, |
| 319 | { WM8996_WRITE_SEQUENCER_21, 0x3 }, |
| 320 | { WM8996_WRITE_SEQUENCER_22, 0x104 }, |
| 321 | { WM8996_WRITE_SEQUENCER_23, 0xa }, |
| 322 | { WM8996_WRITE_SEQUENCER_24, 0x60 }, |
| 323 | { WM8996_WRITE_SEQUENCER_25, 0x3b }, |
| 324 | { WM8996_WRITE_SEQUENCER_26, 0x502 }, |
| 325 | { WM8996_WRITE_SEQUENCER_27, 0x100 }, |
| 326 | { WM8996_WRITE_SEQUENCER_28, 0x2fff }, |
| 327 | { WM8996_WRITE_SEQUENCER_32, 0x2fff }, |
| 328 | { WM8996_WRITE_SEQUENCER_36, 0x2fff }, |
| 329 | { WM8996_WRITE_SEQUENCER_40, 0x2fff }, |
| 330 | { WM8996_WRITE_SEQUENCER_44, 0x2fff }, |
| 331 | { WM8996_WRITE_SEQUENCER_48, 0x2fff }, |
| 332 | { WM8996_WRITE_SEQUENCER_52, 0x2fff }, |
| 333 | { WM8996_WRITE_SEQUENCER_56, 0x2fff }, |
| 334 | { WM8996_WRITE_SEQUENCER_60, 0x2fff }, |
| 335 | { WM8996_WRITE_SEQUENCER_64, 0x1 }, |
| 336 | { WM8996_WRITE_SEQUENCER_65, 0x1 }, |
| 337 | { WM8996_WRITE_SEQUENCER_67, 0x6 }, |
| 338 | { WM8996_WRITE_SEQUENCER_68, 0x40 }, |
| 339 | { WM8996_WRITE_SEQUENCER_69, 0x1 }, |
| 340 | { WM8996_WRITE_SEQUENCER_70, 0xf }, |
| 341 | { WM8996_WRITE_SEQUENCER_71, 0x6 }, |
| 342 | { WM8996_WRITE_SEQUENCER_72, 0x1 }, |
| 343 | { WM8996_WRITE_SEQUENCER_73, 0x3 }, |
| 344 | { WM8996_WRITE_SEQUENCER_74, 0x104 }, |
| 345 | { WM8996_WRITE_SEQUENCER_76, 0x60 }, |
| 346 | { WM8996_WRITE_SEQUENCER_77, 0x11 }, |
| 347 | { WM8996_WRITE_SEQUENCER_78, 0x401 }, |
| 348 | { WM8996_WRITE_SEQUENCER_80, 0x50 }, |
| 349 | { WM8996_WRITE_SEQUENCER_81, 0x3 }, |
| 350 | { WM8996_WRITE_SEQUENCER_82, 0x100 }, |
| 351 | { WM8996_WRITE_SEQUENCER_84, 0x60 }, |
| 352 | { WM8996_WRITE_SEQUENCER_85, 0x3b }, |
| 353 | { WM8996_WRITE_SEQUENCER_86, 0x502 }, |
| 354 | { WM8996_WRITE_SEQUENCER_87, 0x100 }, |
| 355 | { WM8996_WRITE_SEQUENCER_88, 0x2fff }, |
| 356 | { WM8996_WRITE_SEQUENCER_92, 0x2fff }, |
| 357 | { WM8996_WRITE_SEQUENCER_96, 0x2fff }, |
| 358 | { WM8996_WRITE_SEQUENCER_100, 0x2fff }, |
| 359 | { WM8996_WRITE_SEQUENCER_104, 0x2fff }, |
| 360 | { WM8996_WRITE_SEQUENCER_108, 0x2fff }, |
| 361 | { WM8996_WRITE_SEQUENCER_112, 0x2fff }, |
| 362 | { WM8996_WRITE_SEQUENCER_116, 0x2fff }, |
| 363 | { WM8996_WRITE_SEQUENCER_120, 0x2fff }, |
| 364 | { WM8996_WRITE_SEQUENCER_124, 0x2fff }, |
| 365 | { WM8996_WRITE_SEQUENCER_128, 0x1 }, |
| 366 | { WM8996_WRITE_SEQUENCER_129, 0x1 }, |
| 367 | { WM8996_WRITE_SEQUENCER_131, 0x6 }, |
| 368 | { WM8996_WRITE_SEQUENCER_132, 0x40 }, |
| 369 | { WM8996_WRITE_SEQUENCER_133, 0x1 }, |
| 370 | { WM8996_WRITE_SEQUENCER_134, 0xf }, |
| 371 | { WM8996_WRITE_SEQUENCER_135, 0x6 }, |
| 372 | { WM8996_WRITE_SEQUENCER_136, 0x1 }, |
| 373 | { WM8996_WRITE_SEQUENCER_137, 0x3 }, |
| 374 | { WM8996_WRITE_SEQUENCER_138, 0x106 }, |
| 375 | { WM8996_WRITE_SEQUENCER_140, 0x61 }, |
| 376 | { WM8996_WRITE_SEQUENCER_141, 0x11 }, |
| 377 | { WM8996_WRITE_SEQUENCER_142, 0x401 }, |
| 378 | { WM8996_WRITE_SEQUENCER_144, 0x50 }, |
| 379 | { WM8996_WRITE_SEQUENCER_145, 0x3 }, |
| 380 | { WM8996_WRITE_SEQUENCER_146, 0x102 }, |
| 381 | { WM8996_WRITE_SEQUENCER_148, 0x51 }, |
| 382 | { WM8996_WRITE_SEQUENCER_149, 0x3 }, |
| 383 | { WM8996_WRITE_SEQUENCER_150, 0x106 }, |
| 384 | { WM8996_WRITE_SEQUENCER_151, 0xa }, |
| 385 | { WM8996_WRITE_SEQUENCER_152, 0x61 }, |
| 386 | { WM8996_WRITE_SEQUENCER_153, 0x3b }, |
| 387 | { WM8996_WRITE_SEQUENCER_154, 0x502 }, |
| 388 | { WM8996_WRITE_SEQUENCER_155, 0x100 }, |
| 389 | { WM8996_WRITE_SEQUENCER_156, 0x2fff }, |
| 390 | { WM8996_WRITE_SEQUENCER_160, 0x2fff }, |
| 391 | { WM8996_WRITE_SEQUENCER_164, 0x2fff }, |
| 392 | { WM8996_WRITE_SEQUENCER_168, 0x2fff }, |
| 393 | { WM8996_WRITE_SEQUENCER_172, 0x2fff }, |
| 394 | { WM8996_WRITE_SEQUENCER_176, 0x2fff }, |
| 395 | { WM8996_WRITE_SEQUENCER_180, 0x2fff }, |
| 396 | { WM8996_WRITE_SEQUENCER_184, 0x2fff }, |
| 397 | { WM8996_WRITE_SEQUENCER_188, 0x2fff }, |
| 398 | { WM8996_WRITE_SEQUENCER_192, 0x1 }, |
| 399 | { WM8996_WRITE_SEQUENCER_193, 0x1 }, |
| 400 | { WM8996_WRITE_SEQUENCER_195, 0x6 }, |
| 401 | { WM8996_WRITE_SEQUENCER_196, 0x40 }, |
| 402 | { WM8996_WRITE_SEQUENCER_197, 0x1 }, |
| 403 | { WM8996_WRITE_SEQUENCER_198, 0xf }, |
| 404 | { WM8996_WRITE_SEQUENCER_199, 0x6 }, |
| 405 | { WM8996_WRITE_SEQUENCER_200, 0x1 }, |
| 406 | { WM8996_WRITE_SEQUENCER_201, 0x3 }, |
| 407 | { WM8996_WRITE_SEQUENCER_202, 0x106 }, |
| 408 | { WM8996_WRITE_SEQUENCER_204, 0x61 }, |
| 409 | { WM8996_WRITE_SEQUENCER_205, 0x11 }, |
| 410 | { WM8996_WRITE_SEQUENCER_206, 0x401 }, |
| 411 | { WM8996_WRITE_SEQUENCER_208, 0x50 }, |
| 412 | { WM8996_WRITE_SEQUENCER_209, 0x3 }, |
| 413 | { WM8996_WRITE_SEQUENCER_210, 0x102 }, |
| 414 | { WM8996_WRITE_SEQUENCER_212, 0x61 }, |
| 415 | { WM8996_WRITE_SEQUENCER_213, 0x3b }, |
| 416 | { WM8996_WRITE_SEQUENCER_214, 0x502 }, |
| 417 | { WM8996_WRITE_SEQUENCER_215, 0x100 }, |
| 418 | { WM8996_WRITE_SEQUENCER_216, 0x2fff }, |
| 419 | { WM8996_WRITE_SEQUENCER_220, 0x2fff }, |
| 420 | { WM8996_WRITE_SEQUENCER_224, 0x2fff }, |
| 421 | { WM8996_WRITE_SEQUENCER_228, 0x2fff }, |
| 422 | { WM8996_WRITE_SEQUENCER_232, 0x2fff }, |
| 423 | { WM8996_WRITE_SEQUENCER_236, 0x2fff }, |
| 424 | { WM8996_WRITE_SEQUENCER_240, 0x2fff }, |
| 425 | { WM8996_WRITE_SEQUENCER_244, 0x2fff }, |
| 426 | { WM8996_WRITE_SEQUENCER_248, 0x2fff }, |
| 427 | { WM8996_WRITE_SEQUENCER_252, 0x2fff }, |
| 428 | { WM8996_WRITE_SEQUENCER_256, 0x60 }, |
| 429 | { WM8996_WRITE_SEQUENCER_258, 0x601 }, |
| 430 | { WM8996_WRITE_SEQUENCER_260, 0x50 }, |
| 431 | { WM8996_WRITE_SEQUENCER_262, 0x100 }, |
| 432 | { WM8996_WRITE_SEQUENCER_264, 0x1 }, |
| 433 | { WM8996_WRITE_SEQUENCER_266, 0x104 }, |
| 434 | { WM8996_WRITE_SEQUENCER_267, 0x100 }, |
| 435 | { WM8996_WRITE_SEQUENCER_268, 0x2fff }, |
| 436 | { WM8996_WRITE_SEQUENCER_272, 0x2fff }, |
| 437 | { WM8996_WRITE_SEQUENCER_276, 0x2fff }, |
| 438 | { WM8996_WRITE_SEQUENCER_280, 0x2fff }, |
| 439 | { WM8996_WRITE_SEQUENCER_284, 0x2fff }, |
| 440 | { WM8996_WRITE_SEQUENCER_288, 0x2fff }, |
| 441 | { WM8996_WRITE_SEQUENCER_292, 0x2fff }, |
| 442 | { WM8996_WRITE_SEQUENCER_296, 0x2fff }, |
| 443 | { WM8996_WRITE_SEQUENCER_300, 0x2fff }, |
| 444 | { WM8996_WRITE_SEQUENCER_304, 0x2fff }, |
| 445 | { WM8996_WRITE_SEQUENCER_308, 0x2fff }, |
| 446 | { WM8996_WRITE_SEQUENCER_312, 0x2fff }, |
| 447 | { WM8996_WRITE_SEQUENCER_316, 0x2fff }, |
| 448 | { WM8996_WRITE_SEQUENCER_320, 0x61 }, |
| 449 | { WM8996_WRITE_SEQUENCER_322, 0x601 }, |
| 450 | { WM8996_WRITE_SEQUENCER_324, 0x50 }, |
| 451 | { WM8996_WRITE_SEQUENCER_326, 0x102 }, |
| 452 | { WM8996_WRITE_SEQUENCER_328, 0x1 }, |
| 453 | { WM8996_WRITE_SEQUENCER_330, 0x106 }, |
| 454 | { WM8996_WRITE_SEQUENCER_331, 0x100 }, |
| 455 | { WM8996_WRITE_SEQUENCER_332, 0x2fff }, |
| 456 | { WM8996_WRITE_SEQUENCER_336, 0x2fff }, |
| 457 | { WM8996_WRITE_SEQUENCER_340, 0x2fff }, |
| 458 | { WM8996_WRITE_SEQUENCER_344, 0x2fff }, |
| 459 | { WM8996_WRITE_SEQUENCER_348, 0x2fff }, |
| 460 | { WM8996_WRITE_SEQUENCER_352, 0x2fff }, |
| 461 | { WM8996_WRITE_SEQUENCER_356, 0x2fff }, |
| 462 | { WM8996_WRITE_SEQUENCER_360, 0x2fff }, |
| 463 | { WM8996_WRITE_SEQUENCER_364, 0x2fff }, |
| 464 | { WM8996_WRITE_SEQUENCER_368, 0x2fff }, |
| 465 | { WM8996_WRITE_SEQUENCER_372, 0x2fff }, |
| 466 | { WM8996_WRITE_SEQUENCER_376, 0x2fff }, |
| 467 | { WM8996_WRITE_SEQUENCER_380, 0x2fff }, |
| 468 | { WM8996_WRITE_SEQUENCER_384, 0x60 }, |
| 469 | { WM8996_WRITE_SEQUENCER_386, 0x601 }, |
| 470 | { WM8996_WRITE_SEQUENCER_388, 0x61 }, |
| 471 | { WM8996_WRITE_SEQUENCER_390, 0x601 }, |
| 472 | { WM8996_WRITE_SEQUENCER_392, 0x50 }, |
| 473 | { WM8996_WRITE_SEQUENCER_394, 0x300 }, |
| 474 | { WM8996_WRITE_SEQUENCER_396, 0x1 }, |
| 475 | { WM8996_WRITE_SEQUENCER_398, 0x304 }, |
| 476 | { WM8996_WRITE_SEQUENCER_400, 0x40 }, |
| 477 | { WM8996_WRITE_SEQUENCER_402, 0xf }, |
| 478 | { WM8996_WRITE_SEQUENCER_404, 0x1 }, |
| 479 | { WM8996_WRITE_SEQUENCER_407, 0x100 }, |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 480 | }; |
| 481 | |
| 482 | static const DECLARE_TLV_DB_SCALE(inpga_tlv, 0, 100, 0); |
| 483 | static const DECLARE_TLV_DB_SCALE(sidetone_tlv, -3600, 150, 0); |
| 484 | static const DECLARE_TLV_DB_SCALE(digital_tlv, -7200, 75, 1); |
| 485 | static const DECLARE_TLV_DB_SCALE(out_digital_tlv, -1200, 150, 0); |
| 486 | static const DECLARE_TLV_DB_SCALE(out_tlv, -900, 75, 0); |
| 487 | static const DECLARE_TLV_DB_SCALE(spk_tlv, -900, 150, 0); |
| 488 | static const DECLARE_TLV_DB_SCALE(eq_tlv, -1200, 100, 0); |
susan gao | 18a4eef | 2011-08-26 12:14:14 -0700 | [diff] [blame] | 489 | static const DECLARE_TLV_DB_SCALE(threedstereo_tlv, -1600, 183, 1); |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 490 | |
| 491 | static const char *sidetone_hpf_text[] = { |
| 492 | "2.9kHz", "1.5kHz", "735Hz", "403Hz", "196Hz", "98Hz", "49Hz" |
| 493 | }; |
| 494 | |
| 495 | static const struct soc_enum sidetone_hpf = |
Mark Brown | 18036b5 | 2011-08-24 16:35:32 +0100 | [diff] [blame] | 496 | SOC_ENUM_SINGLE(WM8996_SIDETONE, 7, 7, sidetone_hpf_text); |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 497 | |
| 498 | static const char *hpf_mode_text[] = { |
| 499 | "HiFi", "Custom", "Voice" |
| 500 | }; |
| 501 | |
| 502 | static const struct soc_enum dsp1tx_hpf_mode = |
| 503 | SOC_ENUM_SINGLE(WM8996_DSP1_TX_FILTERS, 3, 3, hpf_mode_text); |
| 504 | |
| 505 | static const struct soc_enum dsp2tx_hpf_mode = |
| 506 | SOC_ENUM_SINGLE(WM8996_DSP2_TX_FILTERS, 3, 3, hpf_mode_text); |
| 507 | |
| 508 | static const char *hpf_cutoff_text[] = { |
| 509 | "50Hz", "75Hz", "100Hz", "150Hz", "200Hz", "300Hz", "400Hz" |
| 510 | }; |
| 511 | |
| 512 | static const struct soc_enum dsp1tx_hpf_cutoff = |
| 513 | SOC_ENUM_SINGLE(WM8996_DSP1_TX_FILTERS, 0, 7, hpf_cutoff_text); |
| 514 | |
| 515 | static const struct soc_enum dsp2tx_hpf_cutoff = |
| 516 | SOC_ENUM_SINGLE(WM8996_DSP2_TX_FILTERS, 0, 7, hpf_cutoff_text); |
| 517 | |
| 518 | static void wm8996_set_retune_mobile(struct snd_soc_codec *codec, int block) |
| 519 | { |
| 520 | struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec); |
| 521 | struct wm8996_pdata *pdata = &wm8996->pdata; |
| 522 | int base, best, best_val, save, i, cfg, iface; |
| 523 | |
| 524 | if (!wm8996->num_retune_mobile_texts) |
| 525 | return; |
| 526 | |
| 527 | switch (block) { |
| 528 | case 0: |
| 529 | base = WM8996_DSP1_RX_EQ_GAINS_1; |
| 530 | if (snd_soc_read(codec, WM8996_POWER_MANAGEMENT_8) & |
| 531 | WM8996_DSP1RX_SRC) |
| 532 | iface = 1; |
| 533 | else |
| 534 | iface = 0; |
| 535 | break; |
| 536 | case 1: |
| 537 | base = WM8996_DSP1_RX_EQ_GAINS_2; |
| 538 | if (snd_soc_read(codec, WM8996_POWER_MANAGEMENT_8) & |
| 539 | WM8996_DSP2RX_SRC) |
| 540 | iface = 1; |
| 541 | else |
| 542 | iface = 0; |
| 543 | break; |
| 544 | default: |
| 545 | return; |
| 546 | } |
| 547 | |
| 548 | /* Find the version of the currently selected configuration |
| 549 | * with the nearest sample rate. */ |
| 550 | cfg = wm8996->retune_mobile_cfg[block]; |
| 551 | best = 0; |
| 552 | best_val = INT_MAX; |
| 553 | for (i = 0; i < pdata->num_retune_mobile_cfgs; i++) { |
| 554 | if (strcmp(pdata->retune_mobile_cfgs[i].name, |
| 555 | wm8996->retune_mobile_texts[cfg]) == 0 && |
| 556 | abs(pdata->retune_mobile_cfgs[i].rate |
| 557 | - wm8996->rx_rate[iface]) < best_val) { |
| 558 | best = i; |
| 559 | best_val = abs(pdata->retune_mobile_cfgs[i].rate |
| 560 | - wm8996->rx_rate[iface]); |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | dev_dbg(codec->dev, "ReTune Mobile %d %s/%dHz for %dHz sample rate\n", |
| 565 | block, |
| 566 | pdata->retune_mobile_cfgs[best].name, |
| 567 | pdata->retune_mobile_cfgs[best].rate, |
| 568 | wm8996->rx_rate[iface]); |
| 569 | |
| 570 | /* The EQ will be disabled while reconfiguring it, remember the |
| 571 | * current configuration. |
| 572 | */ |
| 573 | save = snd_soc_read(codec, base); |
| 574 | save &= WM8996_DSP1RX_EQ_ENA; |
| 575 | |
| 576 | for (i = 0; i < ARRAY_SIZE(pdata->retune_mobile_cfgs[best].regs); i++) |
| 577 | snd_soc_update_bits(codec, base + i, 0xffff, |
| 578 | pdata->retune_mobile_cfgs[best].regs[i]); |
| 579 | |
| 580 | snd_soc_update_bits(codec, base, WM8996_DSP1RX_EQ_ENA, save); |
| 581 | } |
| 582 | |
| 583 | /* Icky as hell but saves code duplication */ |
| 584 | static int wm8996_get_retune_mobile_block(const char *name) |
| 585 | { |
| 586 | if (strcmp(name, "DSP1 EQ Mode") == 0) |
| 587 | return 0; |
| 588 | if (strcmp(name, "DSP2 EQ Mode") == 0) |
| 589 | return 1; |
| 590 | return -EINVAL; |
| 591 | } |
| 592 | |
| 593 | static int wm8996_put_retune_mobile_enum(struct snd_kcontrol *kcontrol, |
| 594 | struct snd_ctl_elem_value *ucontrol) |
| 595 | { |
| 596 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 597 | struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec); |
| 598 | struct wm8996_pdata *pdata = &wm8996->pdata; |
| 599 | int block = wm8996_get_retune_mobile_block(kcontrol->id.name); |
| 600 | int value = ucontrol->value.integer.value[0]; |
| 601 | |
| 602 | if (block < 0) |
| 603 | return block; |
| 604 | |
| 605 | if (value >= pdata->num_retune_mobile_cfgs) |
| 606 | return -EINVAL; |
| 607 | |
| 608 | wm8996->retune_mobile_cfg[block] = value; |
| 609 | |
| 610 | wm8996_set_retune_mobile(codec, block); |
| 611 | |
| 612 | return 0; |
| 613 | } |
| 614 | |
| 615 | static int wm8996_get_retune_mobile_enum(struct snd_kcontrol *kcontrol, |
| 616 | struct snd_ctl_elem_value *ucontrol) |
| 617 | { |
| 618 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 619 | struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec); |
| 620 | int block = wm8996_get_retune_mobile_block(kcontrol->id.name); |
| 621 | |
| 622 | ucontrol->value.enumerated.item[0] = wm8996->retune_mobile_cfg[block]; |
| 623 | |
| 624 | return 0; |
| 625 | } |
| 626 | |
| 627 | static const struct snd_kcontrol_new wm8996_snd_controls[] = { |
| 628 | SOC_DOUBLE_R_TLV("Capture Volume", WM8996_LEFT_LINE_INPUT_VOLUME, |
| 629 | WM8996_RIGHT_LINE_INPUT_VOLUME, 0, 31, 0, inpga_tlv), |
| 630 | SOC_DOUBLE_R("Capture ZC Switch", WM8996_LEFT_LINE_INPUT_VOLUME, |
| 631 | WM8996_RIGHT_LINE_INPUT_VOLUME, 5, 1, 0), |
| 632 | |
| 633 | SOC_DOUBLE_TLV("DAC1 Sidetone Volume", WM8996_DAC1_MIXER_VOLUMES, |
| 634 | 0, 5, 24, 0, sidetone_tlv), |
| 635 | SOC_DOUBLE_TLV("DAC2 Sidetone Volume", WM8996_DAC2_MIXER_VOLUMES, |
| 636 | 0, 5, 24, 0, sidetone_tlv), |
| 637 | SOC_SINGLE("Sidetone LPF Switch", WM8996_SIDETONE, 12, 1, 0), |
| 638 | SOC_ENUM("Sidetone HPF Cut-off", sidetone_hpf), |
| 639 | SOC_SINGLE("Sidetone HPF Switch", WM8996_SIDETONE, 6, 1, 0), |
| 640 | |
| 641 | SOC_DOUBLE_R_TLV("DSP1 Capture Volume", WM8996_DSP1_TX_LEFT_VOLUME, |
| 642 | WM8996_DSP1_TX_RIGHT_VOLUME, 1, 96, 0, digital_tlv), |
| 643 | SOC_DOUBLE_R_TLV("DSP2 Capture Volume", WM8996_DSP2_TX_LEFT_VOLUME, |
| 644 | WM8996_DSP2_TX_RIGHT_VOLUME, 1, 96, 0, digital_tlv), |
| 645 | |
| 646 | SOC_SINGLE("DSP1 Capture Notch Filter Switch", WM8996_DSP1_TX_FILTERS, |
| 647 | 13, 1, 0), |
| 648 | SOC_DOUBLE("DSP1 Capture HPF Switch", WM8996_DSP1_TX_FILTERS, 12, 11, 1, 0), |
| 649 | SOC_ENUM("DSP1 Capture HPF Mode", dsp1tx_hpf_mode), |
| 650 | SOC_ENUM("DSP1 Capture HPF Cutoff", dsp1tx_hpf_cutoff), |
| 651 | |
| 652 | SOC_SINGLE("DSP2 Capture Notch Filter Switch", WM8996_DSP2_TX_FILTERS, |
| 653 | 13, 1, 0), |
| 654 | SOC_DOUBLE("DSP2 Capture HPF Switch", WM8996_DSP2_TX_FILTERS, 12, 11, 1, 0), |
| 655 | SOC_ENUM("DSP2 Capture HPF Mode", dsp2tx_hpf_mode), |
| 656 | SOC_ENUM("DSP2 Capture HPF Cutoff", dsp2tx_hpf_cutoff), |
| 657 | |
| 658 | SOC_DOUBLE_R_TLV("DSP1 Playback Volume", WM8996_DSP1_RX_LEFT_VOLUME, |
| 659 | WM8996_DSP1_RX_RIGHT_VOLUME, 1, 112, 0, digital_tlv), |
| 660 | SOC_SINGLE("DSP1 Playback Switch", WM8996_DSP1_RX_FILTERS_1, 9, 1, 1), |
| 661 | |
| 662 | SOC_DOUBLE_R_TLV("DSP2 Playback Volume", WM8996_DSP2_RX_LEFT_VOLUME, |
| 663 | WM8996_DSP2_RX_RIGHT_VOLUME, 1, 112, 0, digital_tlv), |
| 664 | SOC_SINGLE("DSP2 Playback Switch", WM8996_DSP2_RX_FILTERS_1, 9, 1, 1), |
| 665 | |
| 666 | SOC_DOUBLE_R_TLV("DAC1 Volume", WM8996_DAC1_LEFT_VOLUME, |
| 667 | WM8996_DAC1_RIGHT_VOLUME, 1, 112, 0, digital_tlv), |
| 668 | SOC_DOUBLE_R("DAC1 Switch", WM8996_DAC1_LEFT_VOLUME, |
| 669 | WM8996_DAC1_RIGHT_VOLUME, 9, 1, 1), |
| 670 | |
| 671 | SOC_DOUBLE_R_TLV("DAC2 Volume", WM8996_DAC2_LEFT_VOLUME, |
| 672 | WM8996_DAC2_RIGHT_VOLUME, 1, 112, 0, digital_tlv), |
| 673 | SOC_DOUBLE_R("DAC2 Switch", WM8996_DAC2_LEFT_VOLUME, |
| 674 | WM8996_DAC2_RIGHT_VOLUME, 9, 1, 1), |
| 675 | |
| 676 | SOC_SINGLE("Speaker High Performance Switch", WM8996_OVERSAMPLING, 3, 1, 0), |
| 677 | SOC_SINGLE("DMIC High Performance Switch", WM8996_OVERSAMPLING, 2, 1, 0), |
| 678 | SOC_SINGLE("ADC High Performance Switch", WM8996_OVERSAMPLING, 1, 1, 0), |
| 679 | SOC_SINGLE("DAC High Performance Switch", WM8996_OVERSAMPLING, 0, 1, 0), |
| 680 | |
| 681 | SOC_SINGLE("DAC Soft Mute Switch", WM8996_DAC_SOFTMUTE, 1, 1, 0), |
| 682 | SOC_SINGLE("DAC Slow Soft Mute Switch", WM8996_DAC_SOFTMUTE, 0, 1, 0), |
| 683 | |
susan gao | 18a4eef | 2011-08-26 12:14:14 -0700 | [diff] [blame] | 684 | SOC_SINGLE("DSP1 3D Stereo Switch", WM8996_DSP1_RX_FILTERS_2, 8, 1, 0), |
| 685 | SOC_SINGLE("DSP2 3D Stereo Switch", WM8996_DSP2_RX_FILTERS_2, 8, 1, 0), |
| 686 | |
| 687 | SOC_SINGLE_TLV("DSP1 3D Stereo Volume", WM8996_DSP1_RX_FILTERS_2, 10, 15, |
| 688 | 0, threedstereo_tlv), |
| 689 | SOC_SINGLE_TLV("DSP2 3D Stereo Volume", WM8996_DSP2_RX_FILTERS_2, 10, 15, |
| 690 | 0, threedstereo_tlv), |
| 691 | |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 692 | SOC_DOUBLE_TLV("Digital Output 1 Volume", WM8996_DAC1_HPOUT1_VOLUME, 0, 4, |
| 693 | 8, 0, out_digital_tlv), |
| 694 | SOC_DOUBLE_TLV("Digital Output 2 Volume", WM8996_DAC2_HPOUT2_VOLUME, 0, 4, |
| 695 | 8, 0, out_digital_tlv), |
| 696 | |
| 697 | SOC_DOUBLE_R_TLV("Output 1 Volume", WM8996_OUTPUT1_LEFT_VOLUME, |
| 698 | WM8996_OUTPUT1_RIGHT_VOLUME, 0, 12, 0, out_tlv), |
| 699 | SOC_DOUBLE_R("Output 1 ZC Switch", WM8996_OUTPUT1_LEFT_VOLUME, |
| 700 | WM8996_OUTPUT1_RIGHT_VOLUME, 7, 1, 0), |
| 701 | |
| 702 | SOC_DOUBLE_R_TLV("Output 2 Volume", WM8996_OUTPUT2_LEFT_VOLUME, |
| 703 | WM8996_OUTPUT2_RIGHT_VOLUME, 0, 12, 0, out_tlv), |
| 704 | SOC_DOUBLE_R("Output 2 ZC Switch", WM8996_OUTPUT2_LEFT_VOLUME, |
| 705 | WM8996_OUTPUT2_RIGHT_VOLUME, 7, 1, 0), |
| 706 | |
| 707 | SOC_DOUBLE_TLV("Speaker Volume", WM8996_PDM_SPEAKER_VOLUME, 0, 4, 8, 0, |
| 708 | spk_tlv), |
| 709 | SOC_DOUBLE_R("Speaker Switch", WM8996_LEFT_PDM_SPEAKER, |
| 710 | WM8996_RIGHT_PDM_SPEAKER, 3, 1, 1), |
| 711 | SOC_DOUBLE_R("Speaker ZC Switch", WM8996_LEFT_PDM_SPEAKER, |
| 712 | WM8996_RIGHT_PDM_SPEAKER, 2, 1, 0), |
| 713 | |
| 714 | SOC_SINGLE("DSP1 EQ Switch", WM8996_DSP1_RX_EQ_GAINS_1, 0, 1, 0), |
| 715 | SOC_SINGLE("DSP2 EQ Switch", WM8996_DSP2_RX_EQ_GAINS_1, 0, 1, 0), |
Karl Tsou | bcec267 | 2011-09-28 01:47:18 +0800 | [diff] [blame] | 716 | |
| 717 | SOC_SINGLE("DSP1 DRC TXL Switch", WM8996_DSP1_DRC_1, 0, 1, 0), |
| 718 | SOC_SINGLE("DSP1 DRC TXR Switch", WM8996_DSP1_DRC_1, 1, 1, 0), |
| 719 | SOC_SINGLE("DSP1 DRC RX Switch", WM8996_DSP1_DRC_1, 2, 1, 0), |
| 720 | |
| 721 | SOC_SINGLE("DSP2 DRC TXL Switch", WM8996_DSP2_DRC_1, 0, 1, 0), |
| 722 | SOC_SINGLE("DSP2 DRC TXR Switch", WM8996_DSP2_DRC_1, 1, 1, 0), |
| 723 | SOC_SINGLE("DSP2 DRC RX Switch", WM8996_DSP2_DRC_1, 2, 1, 0), |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 724 | }; |
| 725 | |
| 726 | static const struct snd_kcontrol_new wm8996_eq_controls[] = { |
| 727 | SOC_SINGLE_TLV("DSP1 EQ B1 Volume", WM8996_DSP1_RX_EQ_GAINS_1, 11, 31, 0, |
| 728 | eq_tlv), |
| 729 | SOC_SINGLE_TLV("DSP1 EQ B2 Volume", WM8996_DSP1_RX_EQ_GAINS_1, 6, 31, 0, |
| 730 | eq_tlv), |
| 731 | SOC_SINGLE_TLV("DSP1 EQ B3 Volume", WM8996_DSP1_RX_EQ_GAINS_1, 1, 31, 0, |
| 732 | eq_tlv), |
| 733 | SOC_SINGLE_TLV("DSP1 EQ B4 Volume", WM8996_DSP1_RX_EQ_GAINS_2, 11, 31, 0, |
| 734 | eq_tlv), |
| 735 | SOC_SINGLE_TLV("DSP1 EQ B5 Volume", WM8996_DSP1_RX_EQ_GAINS_2, 6, 31, 0, |
| 736 | eq_tlv), |
| 737 | |
| 738 | SOC_SINGLE_TLV("DSP2 EQ B1 Volume", WM8996_DSP2_RX_EQ_GAINS_1, 11, 31, 0, |
| 739 | eq_tlv), |
| 740 | SOC_SINGLE_TLV("DSP2 EQ B2 Volume", WM8996_DSP2_RX_EQ_GAINS_1, 6, 31, 0, |
| 741 | eq_tlv), |
| 742 | SOC_SINGLE_TLV("DSP2 EQ B3 Volume", WM8996_DSP2_RX_EQ_GAINS_1, 1, 31, 0, |
| 743 | eq_tlv), |
| 744 | SOC_SINGLE_TLV("DSP2 EQ B4 Volume", WM8996_DSP2_RX_EQ_GAINS_2, 11, 31, 0, |
| 745 | eq_tlv), |
| 746 | SOC_SINGLE_TLV("DSP2 EQ B5 Volume", WM8996_DSP2_RX_EQ_GAINS_2, 6, 31, 0, |
| 747 | eq_tlv), |
| 748 | }; |
| 749 | |
Mark Brown | ded71dc | 2011-09-19 18:50:05 +0100 | [diff] [blame] | 750 | static void wm8996_bg_enable(struct snd_soc_codec *codec) |
| 751 | { |
| 752 | struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec); |
| 753 | |
| 754 | wm8996->bg_ena++; |
| 755 | if (wm8996->bg_ena == 1) { |
| 756 | snd_soc_update_bits(codec, WM8996_POWER_MANAGEMENT_1, |
| 757 | WM8996_BG_ENA, WM8996_BG_ENA); |
| 758 | msleep(2); |
| 759 | } |
| 760 | } |
| 761 | |
| 762 | static void wm8996_bg_disable(struct snd_soc_codec *codec) |
| 763 | { |
| 764 | struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec); |
| 765 | |
| 766 | wm8996->bg_ena--; |
| 767 | if (!wm8996->bg_ena) |
| 768 | snd_soc_update_bits(codec, WM8996_POWER_MANAGEMENT_1, |
| 769 | WM8996_BG_ENA, 0); |
| 770 | } |
| 771 | |
Mark Brown | 8259df1 | 2011-09-16 17:55:06 +0100 | [diff] [blame] | 772 | static int bg_event(struct snd_soc_dapm_widget *w, |
| 773 | struct snd_kcontrol *kcontrol, int event) |
| 774 | { |
Mark Brown | ded71dc | 2011-09-19 18:50:05 +0100 | [diff] [blame] | 775 | struct snd_soc_codec *codec = w->codec; |
Mark Brown | 8259df1 | 2011-09-16 17:55:06 +0100 | [diff] [blame] | 776 | int ret = 0; |
| 777 | |
| 778 | switch (event) { |
Mark Brown | ded71dc | 2011-09-19 18:50:05 +0100 | [diff] [blame] | 779 | case SND_SOC_DAPM_PRE_PMU: |
| 780 | wm8996_bg_enable(codec); |
| 781 | break; |
| 782 | case SND_SOC_DAPM_POST_PMD: |
| 783 | wm8996_bg_disable(codec); |
Mark Brown | 8259df1 | 2011-09-16 17:55:06 +0100 | [diff] [blame] | 784 | break; |
| 785 | default: |
| 786 | BUG(); |
| 787 | ret = -EINVAL; |
| 788 | } |
| 789 | |
| 790 | return ret; |
| 791 | } |
| 792 | |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 793 | static int cp_event(struct snd_soc_dapm_widget *w, |
| 794 | struct snd_kcontrol *kcontrol, int event) |
| 795 | { |
Mark Brown | c83495a | 2011-09-11 10:05:18 +0100 | [diff] [blame] | 796 | struct snd_soc_codec *codec = w->codec; |
| 797 | struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec); |
| 798 | int ret = 0; |
| 799 | |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 800 | switch (event) { |
Mark Brown | c83495a | 2011-09-11 10:05:18 +0100 | [diff] [blame] | 801 | case SND_SOC_DAPM_PRE_PMU: |
| 802 | ret = regulator_enable(wm8996->cpvdd); |
| 803 | if (ret != 0) |
| 804 | dev_err(codec->dev, "Failed to enable CPVDD: %d\n", |
| 805 | ret); |
| 806 | break; |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 807 | case SND_SOC_DAPM_POST_PMU: |
| 808 | msleep(5); |
| 809 | break; |
Mark Brown | c83495a | 2011-09-11 10:05:18 +0100 | [diff] [blame] | 810 | case SND_SOC_DAPM_POST_PMD: |
| 811 | regulator_disable_deferred(wm8996->cpvdd, 20); |
| 812 | break; |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 813 | default: |
| 814 | BUG(); |
Mark Brown | c83495a | 2011-09-11 10:05:18 +0100 | [diff] [blame] | 815 | ret = -EINVAL; |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 816 | } |
| 817 | |
Mark Brown | c83495a | 2011-09-11 10:05:18 +0100 | [diff] [blame] | 818 | return ret; |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | static int rmv_short_event(struct snd_soc_dapm_widget *w, |
| 822 | struct snd_kcontrol *kcontrol, int event) |
| 823 | { |
| 824 | struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(w->codec); |
| 825 | |
| 826 | /* Record which outputs we enabled */ |
| 827 | switch (event) { |
| 828 | case SND_SOC_DAPM_PRE_PMD: |
| 829 | wm8996->hpout_pending &= ~w->shift; |
| 830 | break; |
| 831 | case SND_SOC_DAPM_PRE_PMU: |
| 832 | wm8996->hpout_pending |= w->shift; |
| 833 | break; |
| 834 | default: |
| 835 | BUG(); |
| 836 | return -EINVAL; |
| 837 | } |
| 838 | |
| 839 | return 0; |
| 840 | } |
| 841 | |
| 842 | static void wait_for_dc_servo(struct snd_soc_codec *codec, u16 mask) |
| 843 | { |
| 844 | struct i2c_client *i2c = to_i2c_client(codec->dev); |
| 845 | struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec); |
Mark Brown | f998f25 | 2011-09-15 10:52:11 +0100 | [diff] [blame] | 846 | int ret; |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 847 | unsigned long timeout = 200; |
| 848 | |
| 849 | snd_soc_write(codec, WM8996_DC_SERVO_2, mask); |
| 850 | |
| 851 | /* Use the interrupt if possible */ |
| 852 | do { |
| 853 | if (i2c->irq) { |
| 854 | timeout = wait_for_completion_timeout(&wm8996->dcs_done, |
| 855 | msecs_to_jiffies(200)); |
| 856 | if (timeout == 0) |
| 857 | dev_err(codec->dev, "DC servo timed out\n"); |
| 858 | |
| 859 | } else { |
| 860 | msleep(1); |
Mark Brown | f998f25 | 2011-09-15 10:52:11 +0100 | [diff] [blame] | 861 | timeout--; |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 862 | } |
| 863 | |
| 864 | ret = snd_soc_read(codec, WM8996_DC_SERVO_2); |
| 865 | dev_dbg(codec->dev, "DC servo state: %x\n", ret); |
Mark Brown | f998f25 | 2011-09-15 10:52:11 +0100 | [diff] [blame] | 866 | } while (timeout && ret & mask); |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 867 | |
| 868 | if (timeout == 0) |
| 869 | dev_err(codec->dev, "DC servo timed out for %x\n", mask); |
| 870 | else |
| 871 | dev_dbg(codec->dev, "DC servo complete for %x\n", mask); |
| 872 | } |
| 873 | |
| 874 | static void wm8996_seq_notifier(struct snd_soc_dapm_context *dapm, |
| 875 | enum snd_soc_dapm_type event, int subseq) |
| 876 | { |
| 877 | struct snd_soc_codec *codec = container_of(dapm, |
| 878 | struct snd_soc_codec, dapm); |
| 879 | struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec); |
| 880 | u16 val, mask; |
| 881 | |
| 882 | /* Complete any pending DC servo starts */ |
| 883 | if (wm8996->dcs_pending) { |
| 884 | dev_dbg(codec->dev, "Starting DC servo for %x\n", |
| 885 | wm8996->dcs_pending); |
| 886 | |
| 887 | /* Trigger a startup sequence */ |
| 888 | wait_for_dc_servo(codec, wm8996->dcs_pending |
| 889 | << WM8996_DCS_TRIG_STARTUP_0_SHIFT); |
| 890 | |
| 891 | wm8996->dcs_pending = 0; |
| 892 | } |
| 893 | |
| 894 | if (wm8996->hpout_pending != wm8996->hpout_ena) { |
| 895 | dev_dbg(codec->dev, "Applying RMV_SHORTs %x->%x\n", |
| 896 | wm8996->hpout_ena, wm8996->hpout_pending); |
| 897 | |
| 898 | val = 0; |
| 899 | mask = 0; |
| 900 | if (wm8996->hpout_pending & HPOUT1L) { |
| 901 | val |= WM8996_HPOUT1L_RMV_SHORT; |
| 902 | mask |= WM8996_HPOUT1L_RMV_SHORT; |
| 903 | } else { |
| 904 | mask |= WM8996_HPOUT1L_RMV_SHORT | |
| 905 | WM8996_HPOUT1L_OUTP | |
| 906 | WM8996_HPOUT1L_DLY; |
| 907 | } |
| 908 | |
| 909 | if (wm8996->hpout_pending & HPOUT1R) { |
| 910 | val |= WM8996_HPOUT1R_RMV_SHORT; |
| 911 | mask |= WM8996_HPOUT1R_RMV_SHORT; |
| 912 | } else { |
| 913 | mask |= WM8996_HPOUT1R_RMV_SHORT | |
| 914 | WM8996_HPOUT1R_OUTP | |
| 915 | WM8996_HPOUT1R_DLY; |
| 916 | } |
| 917 | |
| 918 | snd_soc_update_bits(codec, WM8996_ANALOGUE_HP_1, mask, val); |
| 919 | |
| 920 | val = 0; |
| 921 | mask = 0; |
| 922 | if (wm8996->hpout_pending & HPOUT2L) { |
| 923 | val |= WM8996_HPOUT2L_RMV_SHORT; |
| 924 | mask |= WM8996_HPOUT2L_RMV_SHORT; |
| 925 | } else { |
| 926 | mask |= WM8996_HPOUT2L_RMV_SHORT | |
| 927 | WM8996_HPOUT2L_OUTP | |
| 928 | WM8996_HPOUT2L_DLY; |
| 929 | } |
| 930 | |
| 931 | if (wm8996->hpout_pending & HPOUT2R) { |
| 932 | val |= WM8996_HPOUT2R_RMV_SHORT; |
| 933 | mask |= WM8996_HPOUT2R_RMV_SHORT; |
| 934 | } else { |
| 935 | mask |= WM8996_HPOUT2R_RMV_SHORT | |
| 936 | WM8996_HPOUT2R_OUTP | |
| 937 | WM8996_HPOUT2R_DLY; |
| 938 | } |
| 939 | |
| 940 | snd_soc_update_bits(codec, WM8996_ANALOGUE_HP_2, mask, val); |
| 941 | |
| 942 | wm8996->hpout_ena = wm8996->hpout_pending; |
| 943 | } |
| 944 | } |
| 945 | |
| 946 | static int dcs_start(struct snd_soc_dapm_widget *w, |
| 947 | struct snd_kcontrol *kcontrol, int event) |
| 948 | { |
| 949 | struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(w->codec); |
| 950 | |
| 951 | switch (event) { |
| 952 | case SND_SOC_DAPM_POST_PMU: |
| 953 | wm8996->dcs_pending |= 1 << w->shift; |
| 954 | break; |
| 955 | default: |
| 956 | BUG(); |
| 957 | return -EINVAL; |
| 958 | } |
| 959 | |
| 960 | return 0; |
| 961 | } |
| 962 | |
| 963 | static const char *sidetone_text[] = { |
| 964 | "IN1", "IN2", |
| 965 | }; |
| 966 | |
| 967 | static const struct soc_enum left_sidetone_enum = |
| 968 | SOC_ENUM_SINGLE(WM8996_SIDETONE, 0, 2, sidetone_text); |
| 969 | |
| 970 | static const struct snd_kcontrol_new left_sidetone = |
| 971 | SOC_DAPM_ENUM("Left Sidetone", left_sidetone_enum); |
| 972 | |
| 973 | static const struct soc_enum right_sidetone_enum = |
| 974 | SOC_ENUM_SINGLE(WM8996_SIDETONE, 1, 2, sidetone_text); |
| 975 | |
| 976 | static const struct snd_kcontrol_new right_sidetone = |
| 977 | SOC_DAPM_ENUM("Right Sidetone", right_sidetone_enum); |
| 978 | |
| 979 | static const char *spk_text[] = { |
| 980 | "DAC1L", "DAC1R", "DAC2L", "DAC2R" |
| 981 | }; |
| 982 | |
| 983 | static const struct soc_enum spkl_enum = |
| 984 | SOC_ENUM_SINGLE(WM8996_LEFT_PDM_SPEAKER, 0, 4, spk_text); |
| 985 | |
| 986 | static const struct snd_kcontrol_new spkl_mux = |
| 987 | SOC_DAPM_ENUM("SPKL", spkl_enum); |
| 988 | |
| 989 | static const struct soc_enum spkr_enum = |
| 990 | SOC_ENUM_SINGLE(WM8996_RIGHT_PDM_SPEAKER, 0, 4, spk_text); |
| 991 | |
| 992 | static const struct snd_kcontrol_new spkr_mux = |
| 993 | SOC_DAPM_ENUM("SPKR", spkr_enum); |
| 994 | |
| 995 | static const char *dsp1rx_text[] = { |
| 996 | "AIF1", "AIF2" |
| 997 | }; |
| 998 | |
| 999 | static const struct soc_enum dsp1rx_enum = |
| 1000 | SOC_ENUM_SINGLE(WM8996_POWER_MANAGEMENT_8, 0, 2, dsp1rx_text); |
| 1001 | |
| 1002 | static const struct snd_kcontrol_new dsp1rx = |
| 1003 | SOC_DAPM_ENUM("DSP1RX", dsp1rx_enum); |
| 1004 | |
| 1005 | static const char *dsp2rx_text[] = { |
| 1006 | "AIF2", "AIF1" |
| 1007 | }; |
| 1008 | |
| 1009 | static const struct soc_enum dsp2rx_enum = |
| 1010 | SOC_ENUM_SINGLE(WM8996_POWER_MANAGEMENT_8, 4, 2, dsp2rx_text); |
| 1011 | |
| 1012 | static const struct snd_kcontrol_new dsp2rx = |
| 1013 | SOC_DAPM_ENUM("DSP2RX", dsp2rx_enum); |
| 1014 | |
| 1015 | static const char *aif2tx_text[] = { |
| 1016 | "DSP2", "DSP1", "AIF1" |
| 1017 | }; |
| 1018 | |
| 1019 | static const struct soc_enum aif2tx_enum = |
| 1020 | SOC_ENUM_SINGLE(WM8996_POWER_MANAGEMENT_8, 6, 3, aif2tx_text); |
| 1021 | |
| 1022 | static const struct snd_kcontrol_new aif2tx = |
| 1023 | SOC_DAPM_ENUM("AIF2TX", aif2tx_enum); |
| 1024 | |
| 1025 | static const char *inmux_text[] = { |
| 1026 | "ADC", "DMIC1", "DMIC2" |
| 1027 | }; |
| 1028 | |
| 1029 | static const struct soc_enum in1_enum = |
| 1030 | SOC_ENUM_SINGLE(WM8996_POWER_MANAGEMENT_7, 0, 3, inmux_text); |
| 1031 | |
| 1032 | static const struct snd_kcontrol_new in1_mux = |
| 1033 | SOC_DAPM_ENUM("IN1 Mux", in1_enum); |
| 1034 | |
| 1035 | static const struct soc_enum in2_enum = |
| 1036 | SOC_ENUM_SINGLE(WM8996_POWER_MANAGEMENT_7, 4, 3, inmux_text); |
| 1037 | |
| 1038 | static const struct snd_kcontrol_new in2_mux = |
| 1039 | SOC_DAPM_ENUM("IN2 Mux", in2_enum); |
| 1040 | |
| 1041 | static const struct snd_kcontrol_new dac2r_mix[] = { |
| 1042 | SOC_DAPM_SINGLE("Right Sidetone Switch", WM8996_DAC2_RIGHT_MIXER_ROUTING, |
| 1043 | 5, 1, 0), |
| 1044 | SOC_DAPM_SINGLE("Left Sidetone Switch", WM8996_DAC2_RIGHT_MIXER_ROUTING, |
| 1045 | 4, 1, 0), |
| 1046 | SOC_DAPM_SINGLE("DSP2 Switch", WM8996_DAC2_RIGHT_MIXER_ROUTING, 1, 1, 0), |
| 1047 | SOC_DAPM_SINGLE("DSP1 Switch", WM8996_DAC2_RIGHT_MIXER_ROUTING, 0, 1, 0), |
| 1048 | }; |
| 1049 | |
| 1050 | static const struct snd_kcontrol_new dac2l_mix[] = { |
| 1051 | SOC_DAPM_SINGLE("Right Sidetone Switch", WM8996_DAC2_LEFT_MIXER_ROUTING, |
| 1052 | 5, 1, 0), |
| 1053 | SOC_DAPM_SINGLE("Left Sidetone Switch", WM8996_DAC2_LEFT_MIXER_ROUTING, |
| 1054 | 4, 1, 0), |
| 1055 | SOC_DAPM_SINGLE("DSP2 Switch", WM8996_DAC2_LEFT_MIXER_ROUTING, 1, 1, 0), |
| 1056 | SOC_DAPM_SINGLE("DSP1 Switch", WM8996_DAC2_LEFT_MIXER_ROUTING, 0, 1, 0), |
| 1057 | }; |
| 1058 | |
| 1059 | static const struct snd_kcontrol_new dac1r_mix[] = { |
| 1060 | SOC_DAPM_SINGLE("Right Sidetone Switch", WM8996_DAC1_RIGHT_MIXER_ROUTING, |
| 1061 | 5, 1, 0), |
| 1062 | SOC_DAPM_SINGLE("Left Sidetone Switch", WM8996_DAC1_RIGHT_MIXER_ROUTING, |
| 1063 | 4, 1, 0), |
| 1064 | SOC_DAPM_SINGLE("DSP2 Switch", WM8996_DAC1_RIGHT_MIXER_ROUTING, 1, 1, 0), |
| 1065 | SOC_DAPM_SINGLE("DSP1 Switch", WM8996_DAC1_RIGHT_MIXER_ROUTING, 0, 1, 0), |
| 1066 | }; |
| 1067 | |
| 1068 | static const struct snd_kcontrol_new dac1l_mix[] = { |
| 1069 | SOC_DAPM_SINGLE("Right Sidetone Switch", WM8996_DAC1_LEFT_MIXER_ROUTING, |
| 1070 | 5, 1, 0), |
| 1071 | SOC_DAPM_SINGLE("Left Sidetone Switch", WM8996_DAC1_LEFT_MIXER_ROUTING, |
| 1072 | 4, 1, 0), |
| 1073 | SOC_DAPM_SINGLE("DSP2 Switch", WM8996_DAC1_LEFT_MIXER_ROUTING, 1, 1, 0), |
| 1074 | SOC_DAPM_SINGLE("DSP1 Switch", WM8996_DAC1_LEFT_MIXER_ROUTING, 0, 1, 0), |
| 1075 | }; |
| 1076 | |
| 1077 | static const struct snd_kcontrol_new dsp1txl[] = { |
| 1078 | SOC_DAPM_SINGLE("IN1 Switch", WM8996_DSP1_TX_LEFT_MIXER_ROUTING, |
| 1079 | 1, 1, 0), |
| 1080 | SOC_DAPM_SINGLE("DAC Switch", WM8996_DSP1_TX_LEFT_MIXER_ROUTING, |
| 1081 | 0, 1, 0), |
| 1082 | }; |
| 1083 | |
| 1084 | static const struct snd_kcontrol_new dsp1txr[] = { |
| 1085 | SOC_DAPM_SINGLE("IN1 Switch", WM8996_DSP1_TX_RIGHT_MIXER_ROUTING, |
| 1086 | 1, 1, 0), |
| 1087 | SOC_DAPM_SINGLE("DAC Switch", WM8996_DSP1_TX_RIGHT_MIXER_ROUTING, |
| 1088 | 0, 1, 0), |
| 1089 | }; |
| 1090 | |
| 1091 | static const struct snd_kcontrol_new dsp2txl[] = { |
| 1092 | SOC_DAPM_SINGLE("IN1 Switch", WM8996_DSP2_TX_LEFT_MIXER_ROUTING, |
| 1093 | 1, 1, 0), |
| 1094 | SOC_DAPM_SINGLE("DAC Switch", WM8996_DSP2_TX_LEFT_MIXER_ROUTING, |
| 1095 | 0, 1, 0), |
| 1096 | }; |
| 1097 | |
| 1098 | static const struct snd_kcontrol_new dsp2txr[] = { |
| 1099 | SOC_DAPM_SINGLE("IN1 Switch", WM8996_DSP2_TX_RIGHT_MIXER_ROUTING, |
| 1100 | 1, 1, 0), |
| 1101 | SOC_DAPM_SINGLE("DAC Switch", WM8996_DSP2_TX_RIGHT_MIXER_ROUTING, |
| 1102 | 0, 1, 0), |
| 1103 | }; |
| 1104 | |
| 1105 | |
| 1106 | static const struct snd_soc_dapm_widget wm8996_dapm_widgets[] = { |
| 1107 | SND_SOC_DAPM_INPUT("IN1LN"), |
| 1108 | SND_SOC_DAPM_INPUT("IN1LP"), |
| 1109 | SND_SOC_DAPM_INPUT("IN1RN"), |
| 1110 | SND_SOC_DAPM_INPUT("IN1RP"), |
| 1111 | |
| 1112 | SND_SOC_DAPM_INPUT("IN2LN"), |
| 1113 | SND_SOC_DAPM_INPUT("IN2LP"), |
| 1114 | SND_SOC_DAPM_INPUT("IN2RN"), |
| 1115 | SND_SOC_DAPM_INPUT("IN2RP"), |
| 1116 | |
| 1117 | SND_SOC_DAPM_INPUT("DMIC1DAT"), |
| 1118 | SND_SOC_DAPM_INPUT("DMIC2DAT"), |
| 1119 | |
| 1120 | SND_SOC_DAPM_SUPPLY_S("SYSCLK", 1, WM8996_AIF_CLOCKING_1, 0, 0, NULL, 0), |
| 1121 | SND_SOC_DAPM_SUPPLY_S("SYSDSPCLK", 2, WM8996_CLOCKING_1, 1, 0, NULL, 0), |
| 1122 | SND_SOC_DAPM_SUPPLY_S("AIFCLK", 2, WM8996_CLOCKING_1, 2, 0, NULL, 0), |
| 1123 | SND_SOC_DAPM_SUPPLY_S("Charge Pump", 2, WM8996_CHARGE_PUMP_1, 15, 0, cp_event, |
Mark Brown | ded71dc | 2011-09-19 18:50:05 +0100 | [diff] [blame] | 1124 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 1125 | SND_SOC_DAPM_SUPPLY("Bandgap", SND_SOC_NOPM, 0, 0, bg_event, |
| 1126 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 1127 | SND_SOC_DAPM_SUPPLY("LDO2", WM8996_POWER_MANAGEMENT_2, 1, 0, NULL, 0), |
Mark Brown | 889c85c | 2011-08-20 19:00:50 +0100 | [diff] [blame] | 1128 | SND_SOC_DAPM_SUPPLY("MICB1 Audio", WM8996_MICBIAS_1, 4, 1, NULL, 0), |
| 1129 | SND_SOC_DAPM_SUPPLY("MICB2 Audio", WM8996_MICBIAS_2, 4, 1, NULL, 0), |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 1130 | SND_SOC_DAPM_MICBIAS("MICB2", WM8996_POWER_MANAGEMENT_1, 9, 0), |
| 1131 | SND_SOC_DAPM_MICBIAS("MICB1", WM8996_POWER_MANAGEMENT_1, 8, 0), |
| 1132 | |
| 1133 | SND_SOC_DAPM_PGA("IN1L PGA", WM8996_POWER_MANAGEMENT_2, 5, 0, NULL, 0), |
| 1134 | SND_SOC_DAPM_PGA("IN1R PGA", WM8996_POWER_MANAGEMENT_2, 4, 0, NULL, 0), |
| 1135 | |
Mark Brown | 7691cd74 | 2011-08-20 16:59:27 +0100 | [diff] [blame] | 1136 | SND_SOC_DAPM_MUX("IN1L Mux", WM8996_POWER_MANAGEMENT_7, 2, 0, &in1_mux), |
| 1137 | SND_SOC_DAPM_MUX("IN1R Mux", WM8996_POWER_MANAGEMENT_7, 3, 0, &in1_mux), |
| 1138 | SND_SOC_DAPM_MUX("IN2L Mux", WM8996_POWER_MANAGEMENT_7, 6, 0, &in2_mux), |
| 1139 | SND_SOC_DAPM_MUX("IN2R Mux", WM8996_POWER_MANAGEMENT_7, 7, 0, &in2_mux), |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 1140 | |
| 1141 | SND_SOC_DAPM_SUPPLY("DMIC2", WM8996_POWER_MANAGEMENT_7, 9, 0, NULL, 0), |
| 1142 | SND_SOC_DAPM_SUPPLY("DMIC1", WM8996_POWER_MANAGEMENT_7, 8, 0, NULL, 0), |
| 1143 | |
| 1144 | SND_SOC_DAPM_ADC("DMIC2L", NULL, WM8996_POWER_MANAGEMENT_3, 5, 0), |
| 1145 | SND_SOC_DAPM_ADC("DMIC2R", NULL, WM8996_POWER_MANAGEMENT_3, 4, 0), |
| 1146 | SND_SOC_DAPM_ADC("DMIC1L", NULL, WM8996_POWER_MANAGEMENT_3, 3, 0), |
| 1147 | SND_SOC_DAPM_ADC("DMIC1R", NULL, WM8996_POWER_MANAGEMENT_3, 2, 0), |
| 1148 | |
| 1149 | SND_SOC_DAPM_ADC("ADCL", NULL, WM8996_POWER_MANAGEMENT_3, 1, 0), |
| 1150 | SND_SOC_DAPM_ADC("ADCR", NULL, WM8996_POWER_MANAGEMENT_3, 0, 0), |
| 1151 | |
| 1152 | SND_SOC_DAPM_MUX("Left Sidetone", SND_SOC_NOPM, 0, 0, &left_sidetone), |
| 1153 | SND_SOC_DAPM_MUX("Right Sidetone", SND_SOC_NOPM, 0, 0, &right_sidetone), |
| 1154 | |
| 1155 | SND_SOC_DAPM_AIF_IN("DSP2RXL", NULL, 0, WM8996_POWER_MANAGEMENT_3, 11, 0), |
| 1156 | SND_SOC_DAPM_AIF_IN("DSP2RXR", NULL, 1, WM8996_POWER_MANAGEMENT_3, 10, 0), |
| 1157 | SND_SOC_DAPM_AIF_IN("DSP1RXL", NULL, 0, WM8996_POWER_MANAGEMENT_3, 9, 0), |
| 1158 | SND_SOC_DAPM_AIF_IN("DSP1RXR", NULL, 1, WM8996_POWER_MANAGEMENT_3, 8, 0), |
| 1159 | |
| 1160 | SND_SOC_DAPM_MIXER("DSP2TXL", WM8996_POWER_MANAGEMENT_5, 11, 0, |
| 1161 | dsp2txl, ARRAY_SIZE(dsp2txl)), |
| 1162 | SND_SOC_DAPM_MIXER("DSP2TXR", WM8996_POWER_MANAGEMENT_5, 10, 0, |
| 1163 | dsp2txr, ARRAY_SIZE(dsp2txr)), |
| 1164 | SND_SOC_DAPM_MIXER("DSP1TXL", WM8996_POWER_MANAGEMENT_5, 9, 0, |
| 1165 | dsp1txl, ARRAY_SIZE(dsp1txl)), |
| 1166 | SND_SOC_DAPM_MIXER("DSP1TXR", WM8996_POWER_MANAGEMENT_5, 8, 0, |
| 1167 | dsp1txr, ARRAY_SIZE(dsp1txr)), |
| 1168 | |
| 1169 | SND_SOC_DAPM_MIXER("DAC2L Mixer", SND_SOC_NOPM, 0, 0, |
| 1170 | dac2l_mix, ARRAY_SIZE(dac2l_mix)), |
| 1171 | SND_SOC_DAPM_MIXER("DAC2R Mixer", SND_SOC_NOPM, 0, 0, |
| 1172 | dac2r_mix, ARRAY_SIZE(dac2r_mix)), |
| 1173 | SND_SOC_DAPM_MIXER("DAC1L Mixer", SND_SOC_NOPM, 0, 0, |
| 1174 | dac1l_mix, ARRAY_SIZE(dac1l_mix)), |
| 1175 | SND_SOC_DAPM_MIXER("DAC1R Mixer", SND_SOC_NOPM, 0, 0, |
| 1176 | dac1r_mix, ARRAY_SIZE(dac1r_mix)), |
| 1177 | |
| 1178 | SND_SOC_DAPM_DAC("DAC2L", NULL, WM8996_POWER_MANAGEMENT_5, 3, 0), |
| 1179 | SND_SOC_DAPM_DAC("DAC2R", NULL, WM8996_POWER_MANAGEMENT_5, 2, 0), |
| 1180 | SND_SOC_DAPM_DAC("DAC1L", NULL, WM8996_POWER_MANAGEMENT_5, 1, 0), |
| 1181 | SND_SOC_DAPM_DAC("DAC1R", NULL, WM8996_POWER_MANAGEMENT_5, 0, 0), |
| 1182 | |
Mark Brown | 32d2a0c | 2011-09-10 22:36:17 -0700 | [diff] [blame] | 1183 | SND_SOC_DAPM_AIF_IN("AIF2RX1", "AIF2 Playback", 0, |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 1184 | WM8996_POWER_MANAGEMENT_4, 9, 0), |
Mark Brown | 32d2a0c | 2011-09-10 22:36:17 -0700 | [diff] [blame] | 1185 | SND_SOC_DAPM_AIF_IN("AIF2RX0", "AIF2 Playback", 1, |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 1186 | WM8996_POWER_MANAGEMENT_4, 8, 0), |
| 1187 | |
Axel Lin | ff39dbe | 2011-10-20 12:16:31 +0800 | [diff] [blame] | 1188 | SND_SOC_DAPM_AIF_OUT("AIF2TX1", "AIF2 Capture", 0, |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 1189 | WM8996_POWER_MANAGEMENT_6, 9, 0), |
Axel Lin | ff39dbe | 2011-10-20 12:16:31 +0800 | [diff] [blame] | 1190 | SND_SOC_DAPM_AIF_OUT("AIF2TX0", "AIF2 Capture", 1, |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 1191 | WM8996_POWER_MANAGEMENT_6, 8, 0), |
| 1192 | |
| 1193 | SND_SOC_DAPM_AIF_IN("AIF1RX5", "AIF1 Playback", 5, |
| 1194 | WM8996_POWER_MANAGEMENT_4, 5, 0), |
| 1195 | SND_SOC_DAPM_AIF_IN("AIF1RX4", "AIF1 Playback", 4, |
| 1196 | WM8996_POWER_MANAGEMENT_4, 4, 0), |
| 1197 | SND_SOC_DAPM_AIF_IN("AIF1RX3", "AIF1 Playback", 3, |
| 1198 | WM8996_POWER_MANAGEMENT_4, 3, 0), |
| 1199 | SND_SOC_DAPM_AIF_IN("AIF1RX2", "AIF1 Playback", 2, |
| 1200 | WM8996_POWER_MANAGEMENT_4, 2, 0), |
| 1201 | SND_SOC_DAPM_AIF_IN("AIF1RX1", "AIF1 Playback", 1, |
| 1202 | WM8996_POWER_MANAGEMENT_4, 1, 0), |
| 1203 | SND_SOC_DAPM_AIF_IN("AIF1RX0", "AIF1 Playback", 0, |
| 1204 | WM8996_POWER_MANAGEMENT_4, 0, 0), |
| 1205 | |
| 1206 | SND_SOC_DAPM_AIF_OUT("AIF1TX5", "AIF1 Capture", 5, |
| 1207 | WM8996_POWER_MANAGEMENT_6, 5, 0), |
| 1208 | SND_SOC_DAPM_AIF_OUT("AIF1TX4", "AIF1 Capture", 4, |
| 1209 | WM8996_POWER_MANAGEMENT_6, 4, 0), |
| 1210 | SND_SOC_DAPM_AIF_OUT("AIF1TX3", "AIF1 Capture", 3, |
| 1211 | WM8996_POWER_MANAGEMENT_6, 3, 0), |
| 1212 | SND_SOC_DAPM_AIF_OUT("AIF1TX2", "AIF1 Capture", 2, |
| 1213 | WM8996_POWER_MANAGEMENT_6, 2, 0), |
| 1214 | SND_SOC_DAPM_AIF_OUT("AIF1TX1", "AIF1 Capture", 1, |
| 1215 | WM8996_POWER_MANAGEMENT_6, 1, 0), |
| 1216 | SND_SOC_DAPM_AIF_OUT("AIF1TX0", "AIF1 Capture", 0, |
| 1217 | WM8996_POWER_MANAGEMENT_6, 0, 0), |
| 1218 | |
| 1219 | /* We route as stereo pairs so define some dummy widgets to squash |
| 1220 | * things down for now. RXA = 0,1, RXB = 2,3 and so on */ |
| 1221 | SND_SOC_DAPM_PGA("AIF1RXA", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 1222 | SND_SOC_DAPM_PGA("AIF1RXB", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 1223 | SND_SOC_DAPM_PGA("AIF1RXC", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 1224 | SND_SOC_DAPM_PGA("AIF2RX", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 1225 | SND_SOC_DAPM_PGA("DSP2TX", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 1226 | |
| 1227 | SND_SOC_DAPM_MUX("DSP1RX", SND_SOC_NOPM, 0, 0, &dsp1rx), |
| 1228 | SND_SOC_DAPM_MUX("DSP2RX", SND_SOC_NOPM, 0, 0, &dsp2rx), |
| 1229 | SND_SOC_DAPM_MUX("AIF2TX", SND_SOC_NOPM, 0, 0, &aif2tx), |
| 1230 | |
| 1231 | SND_SOC_DAPM_MUX("SPKL", SND_SOC_NOPM, 0, 0, &spkl_mux), |
| 1232 | SND_SOC_DAPM_MUX("SPKR", SND_SOC_NOPM, 0, 0, &spkr_mux), |
| 1233 | SND_SOC_DAPM_PGA("SPKL PGA", WM8996_LEFT_PDM_SPEAKER, 4, 0, NULL, 0), |
| 1234 | SND_SOC_DAPM_PGA("SPKR PGA", WM8996_RIGHT_PDM_SPEAKER, 4, 0, NULL, 0), |
| 1235 | |
| 1236 | SND_SOC_DAPM_PGA_S("HPOUT2L PGA", 0, WM8996_POWER_MANAGEMENT_1, 7, 0, NULL, 0), |
| 1237 | SND_SOC_DAPM_PGA_S("HPOUT2L_DLY", 1, WM8996_ANALOGUE_HP_2, 5, 0, NULL, 0), |
| 1238 | SND_SOC_DAPM_PGA_S("HPOUT2L_DCS", 2, WM8996_DC_SERVO_1, 2, 0, dcs_start, |
| 1239 | SND_SOC_DAPM_POST_PMU), |
| 1240 | SND_SOC_DAPM_PGA_S("HPOUT2L_OUTP", 3, WM8996_ANALOGUE_HP_2, 6, 0, NULL, 0), |
| 1241 | SND_SOC_DAPM_PGA_S("HPOUT2L_RMV_SHORT", 3, SND_SOC_NOPM, HPOUT2L, 0, |
| 1242 | rmv_short_event, |
| 1243 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD), |
| 1244 | |
| 1245 | SND_SOC_DAPM_PGA_S("HPOUT2R PGA", 0, WM8996_POWER_MANAGEMENT_1, 6, 0,NULL, 0), |
| 1246 | SND_SOC_DAPM_PGA_S("HPOUT2R_DLY", 1, WM8996_ANALOGUE_HP_2, 1, 0, NULL, 0), |
| 1247 | SND_SOC_DAPM_PGA_S("HPOUT2R_DCS", 2, WM8996_DC_SERVO_1, 3, 0, dcs_start, |
| 1248 | SND_SOC_DAPM_POST_PMU), |
| 1249 | SND_SOC_DAPM_PGA_S("HPOUT2R_OUTP", 3, WM8996_ANALOGUE_HP_2, 2, 0, NULL, 0), |
| 1250 | SND_SOC_DAPM_PGA_S("HPOUT2R_RMV_SHORT", 3, SND_SOC_NOPM, HPOUT2R, 0, |
| 1251 | rmv_short_event, |
| 1252 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD), |
| 1253 | |
| 1254 | SND_SOC_DAPM_PGA_S("HPOUT1L PGA", 0, WM8996_POWER_MANAGEMENT_1, 5, 0, NULL, 0), |
| 1255 | SND_SOC_DAPM_PGA_S("HPOUT1L_DLY", 1, WM8996_ANALOGUE_HP_1, 5, 0, NULL, 0), |
| 1256 | SND_SOC_DAPM_PGA_S("HPOUT1L_DCS", 2, WM8996_DC_SERVO_1, 0, 0, dcs_start, |
| 1257 | SND_SOC_DAPM_POST_PMU), |
| 1258 | SND_SOC_DAPM_PGA_S("HPOUT1L_OUTP", 3, WM8996_ANALOGUE_HP_1, 6, 0, NULL, 0), |
| 1259 | SND_SOC_DAPM_PGA_S("HPOUT1L_RMV_SHORT", 3, SND_SOC_NOPM, HPOUT1L, 0, |
| 1260 | rmv_short_event, |
| 1261 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD), |
| 1262 | |
| 1263 | SND_SOC_DAPM_PGA_S("HPOUT1R PGA", 0, WM8996_POWER_MANAGEMENT_1, 4, 0, NULL, 0), |
| 1264 | SND_SOC_DAPM_PGA_S("HPOUT1R_DLY", 1, WM8996_ANALOGUE_HP_1, 1, 0, NULL, 0), |
| 1265 | SND_SOC_DAPM_PGA_S("HPOUT1R_DCS", 2, WM8996_DC_SERVO_1, 1, 0, dcs_start, |
| 1266 | SND_SOC_DAPM_POST_PMU), |
| 1267 | SND_SOC_DAPM_PGA_S("HPOUT1R_OUTP", 3, WM8996_ANALOGUE_HP_1, 2, 0, NULL, 0), |
| 1268 | SND_SOC_DAPM_PGA_S("HPOUT1R_RMV_SHORT", 3, SND_SOC_NOPM, HPOUT1R, 0, |
| 1269 | rmv_short_event, |
| 1270 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD), |
| 1271 | |
| 1272 | SND_SOC_DAPM_OUTPUT("HPOUT1L"), |
| 1273 | SND_SOC_DAPM_OUTPUT("HPOUT1R"), |
| 1274 | SND_SOC_DAPM_OUTPUT("HPOUT2L"), |
| 1275 | SND_SOC_DAPM_OUTPUT("HPOUT2R"), |
| 1276 | SND_SOC_DAPM_OUTPUT("SPKDAT"), |
| 1277 | }; |
| 1278 | |
| 1279 | static const struct snd_soc_dapm_route wm8996_dapm_routes[] = { |
| 1280 | { "AIFCLK", NULL, "SYSCLK" }, |
| 1281 | { "SYSDSPCLK", NULL, "SYSCLK" }, |
| 1282 | { "Charge Pump", NULL, "SYSCLK" }, |
| 1283 | |
| 1284 | { "MICB1", NULL, "LDO2" }, |
Mark Brown | 889c85c | 2011-08-20 19:00:50 +0100 | [diff] [blame] | 1285 | { "MICB1", NULL, "MICB1 Audio" }, |
Mark Brown | 8259df1 | 2011-09-16 17:55:06 +0100 | [diff] [blame] | 1286 | { "MICB1", NULL, "Bandgap" }, |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 1287 | { "MICB2", NULL, "LDO2" }, |
Mark Brown | 889c85c | 2011-08-20 19:00:50 +0100 | [diff] [blame] | 1288 | { "MICB2", NULL, "MICB2 Audio" }, |
Mark Brown | 8259df1 | 2011-09-16 17:55:06 +0100 | [diff] [blame] | 1289 | { "MICB2", NULL, "Bandgap" }, |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 1290 | |
| 1291 | { "IN1L PGA", NULL, "IN2LN" }, |
| 1292 | { "IN1L PGA", NULL, "IN2LP" }, |
| 1293 | { "IN1L PGA", NULL, "IN1LN" }, |
| 1294 | { "IN1L PGA", NULL, "IN1LP" }, |
Mark Brown | 8259df1 | 2011-09-16 17:55:06 +0100 | [diff] [blame] | 1295 | { "IN1L PGA", NULL, "Bandgap" }, |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 1296 | |
| 1297 | { "IN1R PGA", NULL, "IN2RN" }, |
| 1298 | { "IN1R PGA", NULL, "IN2RP" }, |
| 1299 | { "IN1R PGA", NULL, "IN1RN" }, |
| 1300 | { "IN1R PGA", NULL, "IN1RP" }, |
Mark Brown | 8259df1 | 2011-09-16 17:55:06 +0100 | [diff] [blame] | 1301 | { "IN1R PGA", NULL, "Bandgap" }, |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 1302 | |
| 1303 | { "ADCL", NULL, "IN1L PGA" }, |
| 1304 | |
| 1305 | { "ADCR", NULL, "IN1R PGA" }, |
| 1306 | |
| 1307 | { "DMIC1L", NULL, "DMIC1DAT" }, |
| 1308 | { "DMIC1R", NULL, "DMIC1DAT" }, |
| 1309 | { "DMIC2L", NULL, "DMIC2DAT" }, |
| 1310 | { "DMIC2R", NULL, "DMIC2DAT" }, |
| 1311 | |
| 1312 | { "DMIC2L", NULL, "DMIC2" }, |
| 1313 | { "DMIC2R", NULL, "DMIC2" }, |
| 1314 | { "DMIC1L", NULL, "DMIC1" }, |
| 1315 | { "DMIC1R", NULL, "DMIC1" }, |
| 1316 | |
| 1317 | { "IN1L Mux", "ADC", "ADCL" }, |
| 1318 | { "IN1L Mux", "DMIC1", "DMIC1L" }, |
| 1319 | { "IN1L Mux", "DMIC2", "DMIC2L" }, |
| 1320 | |
| 1321 | { "IN1R Mux", "ADC", "ADCR" }, |
| 1322 | { "IN1R Mux", "DMIC1", "DMIC1R" }, |
| 1323 | { "IN1R Mux", "DMIC2", "DMIC2R" }, |
| 1324 | |
| 1325 | { "IN2L Mux", "ADC", "ADCL" }, |
| 1326 | { "IN2L Mux", "DMIC1", "DMIC1L" }, |
| 1327 | { "IN2L Mux", "DMIC2", "DMIC2L" }, |
| 1328 | |
| 1329 | { "IN2R Mux", "ADC", "ADCR" }, |
| 1330 | { "IN2R Mux", "DMIC1", "DMIC1R" }, |
| 1331 | { "IN2R Mux", "DMIC2", "DMIC2R" }, |
| 1332 | |
| 1333 | { "Left Sidetone", "IN1", "IN1L Mux" }, |
| 1334 | { "Left Sidetone", "IN2", "IN2L Mux" }, |
| 1335 | |
| 1336 | { "Right Sidetone", "IN1", "IN1R Mux" }, |
| 1337 | { "Right Sidetone", "IN2", "IN2R Mux" }, |
| 1338 | |
| 1339 | { "DSP1TXL", "IN1 Switch", "IN1L Mux" }, |
| 1340 | { "DSP1TXR", "IN1 Switch", "IN1R Mux" }, |
| 1341 | |
| 1342 | { "DSP2TXL", "IN1 Switch", "IN2L Mux" }, |
| 1343 | { "DSP2TXR", "IN1 Switch", "IN2R Mux" }, |
| 1344 | |
| 1345 | { "AIF1TX0", NULL, "DSP1TXL" }, |
| 1346 | { "AIF1TX1", NULL, "DSP1TXR" }, |
| 1347 | { "AIF1TX2", NULL, "DSP2TXL" }, |
| 1348 | { "AIF1TX3", NULL, "DSP2TXR" }, |
| 1349 | { "AIF1TX4", NULL, "AIF2RX0" }, |
| 1350 | { "AIF1TX5", NULL, "AIF2RX1" }, |
| 1351 | |
| 1352 | { "AIF1RX0", NULL, "AIFCLK" }, |
| 1353 | { "AIF1RX1", NULL, "AIFCLK" }, |
| 1354 | { "AIF1RX2", NULL, "AIFCLK" }, |
| 1355 | { "AIF1RX3", NULL, "AIFCLK" }, |
| 1356 | { "AIF1RX4", NULL, "AIFCLK" }, |
| 1357 | { "AIF1RX5", NULL, "AIFCLK" }, |
| 1358 | |
| 1359 | { "AIF2RX0", NULL, "AIFCLK" }, |
| 1360 | { "AIF2RX1", NULL, "AIFCLK" }, |
| 1361 | |
Mark Brown | 4f41adf | 2011-08-20 10:23:38 +0100 | [diff] [blame] | 1362 | { "AIF1TX0", NULL, "AIFCLK" }, |
| 1363 | { "AIF1TX1", NULL, "AIFCLK" }, |
| 1364 | { "AIF1TX2", NULL, "AIFCLK" }, |
| 1365 | { "AIF1TX3", NULL, "AIFCLK" }, |
| 1366 | { "AIF1TX4", NULL, "AIFCLK" }, |
| 1367 | { "AIF1TX5", NULL, "AIFCLK" }, |
| 1368 | |
| 1369 | { "AIF2TX0", NULL, "AIFCLK" }, |
| 1370 | { "AIF2TX1", NULL, "AIFCLK" }, |
| 1371 | |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 1372 | { "DSP1RXL", NULL, "SYSDSPCLK" }, |
| 1373 | { "DSP1RXR", NULL, "SYSDSPCLK" }, |
| 1374 | { "DSP2RXL", NULL, "SYSDSPCLK" }, |
| 1375 | { "DSP2RXR", NULL, "SYSDSPCLK" }, |
| 1376 | { "DSP1TXL", NULL, "SYSDSPCLK" }, |
| 1377 | { "DSP1TXR", NULL, "SYSDSPCLK" }, |
| 1378 | { "DSP2TXL", NULL, "SYSDSPCLK" }, |
| 1379 | { "DSP2TXR", NULL, "SYSDSPCLK" }, |
| 1380 | |
| 1381 | { "AIF1RXA", NULL, "AIF1RX0" }, |
| 1382 | { "AIF1RXA", NULL, "AIF1RX1" }, |
| 1383 | { "AIF1RXB", NULL, "AIF1RX2" }, |
| 1384 | { "AIF1RXB", NULL, "AIF1RX3" }, |
| 1385 | { "AIF1RXC", NULL, "AIF1RX4" }, |
| 1386 | { "AIF1RXC", NULL, "AIF1RX5" }, |
| 1387 | |
| 1388 | { "AIF2RX", NULL, "AIF2RX0" }, |
| 1389 | { "AIF2RX", NULL, "AIF2RX1" }, |
| 1390 | |
| 1391 | { "AIF2TX", "DSP2", "DSP2TX" }, |
| 1392 | { "AIF2TX", "DSP1", "DSP1RX" }, |
| 1393 | { "AIF2TX", "AIF1", "AIF1RXC" }, |
| 1394 | |
| 1395 | { "DSP1RXL", NULL, "DSP1RX" }, |
| 1396 | { "DSP1RXR", NULL, "DSP1RX" }, |
| 1397 | { "DSP2RXL", NULL, "DSP2RX" }, |
| 1398 | { "DSP2RXR", NULL, "DSP2RX" }, |
| 1399 | |
| 1400 | { "DSP2TX", NULL, "DSP2TXL" }, |
| 1401 | { "DSP2TX", NULL, "DSP2TXR" }, |
| 1402 | |
| 1403 | { "DSP1RX", "AIF1", "AIF1RXA" }, |
| 1404 | { "DSP1RX", "AIF2", "AIF2RX" }, |
| 1405 | |
| 1406 | { "DSP2RX", "AIF1", "AIF1RXB" }, |
| 1407 | { "DSP2RX", "AIF2", "AIF2RX" }, |
| 1408 | |
| 1409 | { "DAC2L Mixer", "DSP2 Switch", "DSP2RXL" }, |
| 1410 | { "DAC2L Mixer", "DSP1 Switch", "DSP1RXL" }, |
| 1411 | { "DAC2L Mixer", "Right Sidetone Switch", "Right Sidetone" }, |
| 1412 | { "DAC2L Mixer", "Left Sidetone Switch", "Left Sidetone" }, |
| 1413 | |
| 1414 | { "DAC2R Mixer", "DSP2 Switch", "DSP2RXR" }, |
| 1415 | { "DAC2R Mixer", "DSP1 Switch", "DSP1RXR" }, |
| 1416 | { "DAC2R Mixer", "Right Sidetone Switch", "Right Sidetone" }, |
| 1417 | { "DAC2R Mixer", "Left Sidetone Switch", "Left Sidetone" }, |
| 1418 | |
| 1419 | { "DAC1L Mixer", "DSP2 Switch", "DSP2RXL" }, |
| 1420 | { "DAC1L Mixer", "DSP1 Switch", "DSP1RXL" }, |
| 1421 | { "DAC1L Mixer", "Right Sidetone Switch", "Right Sidetone" }, |
| 1422 | { "DAC1L Mixer", "Left Sidetone Switch", "Left Sidetone" }, |
| 1423 | |
| 1424 | { "DAC1R Mixer", "DSP2 Switch", "DSP2RXR" }, |
| 1425 | { "DAC1R Mixer", "DSP1 Switch", "DSP1RXR" }, |
| 1426 | { "DAC1R Mixer", "Right Sidetone Switch", "Right Sidetone" }, |
| 1427 | { "DAC1R Mixer", "Left Sidetone Switch", "Left Sidetone" }, |
| 1428 | |
| 1429 | { "DAC1L", NULL, "DAC1L Mixer" }, |
| 1430 | { "DAC1R", NULL, "DAC1R Mixer" }, |
| 1431 | { "DAC2L", NULL, "DAC2L Mixer" }, |
| 1432 | { "DAC2R", NULL, "DAC2R Mixer" }, |
| 1433 | |
| 1434 | { "HPOUT2L PGA", NULL, "Charge Pump" }, |
Mark Brown | 8259df1 | 2011-09-16 17:55:06 +0100 | [diff] [blame] | 1435 | { "HPOUT2L PGA", NULL, "Bandgap" }, |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 1436 | { "HPOUT2L PGA", NULL, "DAC2L" }, |
| 1437 | { "HPOUT2L_DLY", NULL, "HPOUT2L PGA" }, |
| 1438 | { "HPOUT2L_DCS", NULL, "HPOUT2L_DLY" }, |
| 1439 | { "HPOUT2L_OUTP", NULL, "HPOUT2L_DCS" }, |
| 1440 | { "HPOUT2L_RMV_SHORT", NULL, "HPOUT2L_OUTP" }, |
| 1441 | |
| 1442 | { "HPOUT2R PGA", NULL, "Charge Pump" }, |
Mark Brown | 8259df1 | 2011-09-16 17:55:06 +0100 | [diff] [blame] | 1443 | { "HPOUT2R PGA", NULL, "Bandgap" }, |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 1444 | { "HPOUT2R PGA", NULL, "DAC2R" }, |
| 1445 | { "HPOUT2R_DLY", NULL, "HPOUT2R PGA" }, |
| 1446 | { "HPOUT2R_DCS", NULL, "HPOUT2R_DLY" }, |
| 1447 | { "HPOUT2R_OUTP", NULL, "HPOUT2R_DCS" }, |
| 1448 | { "HPOUT2R_RMV_SHORT", NULL, "HPOUT2R_OUTP" }, |
| 1449 | |
| 1450 | { "HPOUT1L PGA", NULL, "Charge Pump" }, |
Mark Brown | 8259df1 | 2011-09-16 17:55:06 +0100 | [diff] [blame] | 1451 | { "HPOUT1L PGA", NULL, "Bandgap" }, |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 1452 | { "HPOUT1L PGA", NULL, "DAC1L" }, |
| 1453 | { "HPOUT1L_DLY", NULL, "HPOUT1L PGA" }, |
| 1454 | { "HPOUT1L_DCS", NULL, "HPOUT1L_DLY" }, |
| 1455 | { "HPOUT1L_OUTP", NULL, "HPOUT1L_DCS" }, |
| 1456 | { "HPOUT1L_RMV_SHORT", NULL, "HPOUT1L_OUTP" }, |
| 1457 | |
| 1458 | { "HPOUT1R PGA", NULL, "Charge Pump" }, |
Mark Brown | 8259df1 | 2011-09-16 17:55:06 +0100 | [diff] [blame] | 1459 | { "HPOUT1R PGA", NULL, "Bandgap" }, |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 1460 | { "HPOUT1R PGA", NULL, "DAC1R" }, |
| 1461 | { "HPOUT1R_DLY", NULL, "HPOUT1R PGA" }, |
| 1462 | { "HPOUT1R_DCS", NULL, "HPOUT1R_DLY" }, |
| 1463 | { "HPOUT1R_OUTP", NULL, "HPOUT1R_DCS" }, |
| 1464 | { "HPOUT1R_RMV_SHORT", NULL, "HPOUT1R_OUTP" }, |
| 1465 | |
| 1466 | { "HPOUT2L", NULL, "HPOUT2L_RMV_SHORT" }, |
| 1467 | { "HPOUT2R", NULL, "HPOUT2R_RMV_SHORT" }, |
| 1468 | { "HPOUT1L", NULL, "HPOUT1L_RMV_SHORT" }, |
| 1469 | { "HPOUT1R", NULL, "HPOUT1R_RMV_SHORT" }, |
| 1470 | |
| 1471 | { "SPKL", "DAC1L", "DAC1L" }, |
| 1472 | { "SPKL", "DAC1R", "DAC1R" }, |
| 1473 | { "SPKL", "DAC2L", "DAC2L" }, |
| 1474 | { "SPKL", "DAC2R", "DAC2R" }, |
| 1475 | |
| 1476 | { "SPKR", "DAC1L", "DAC1L" }, |
| 1477 | { "SPKR", "DAC1R", "DAC1R" }, |
| 1478 | { "SPKR", "DAC2L", "DAC2L" }, |
| 1479 | { "SPKR", "DAC2R", "DAC2R" }, |
| 1480 | |
| 1481 | { "SPKL PGA", NULL, "SPKL" }, |
| 1482 | { "SPKR PGA", NULL, "SPKR" }, |
| 1483 | |
| 1484 | { "SPKDAT", NULL, "SPKL PGA" }, |
| 1485 | { "SPKDAT", NULL, "SPKR PGA" }, |
| 1486 | }; |
| 1487 | |
Mark Brown | 7917274 | 2011-09-19 16:15:58 +0100 | [diff] [blame] | 1488 | static bool wm8996_readable_register(struct device *dev, unsigned int reg) |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 1489 | { |
| 1490 | /* Due to the sparseness of the register map the compiler |
| 1491 | * output from an explicit switch statement ends up being much |
| 1492 | * more efficient than a table. |
| 1493 | */ |
| 1494 | switch (reg) { |
| 1495 | case WM8996_SOFTWARE_RESET: |
| 1496 | case WM8996_POWER_MANAGEMENT_1: |
| 1497 | case WM8996_POWER_MANAGEMENT_2: |
| 1498 | case WM8996_POWER_MANAGEMENT_3: |
| 1499 | case WM8996_POWER_MANAGEMENT_4: |
| 1500 | case WM8996_POWER_MANAGEMENT_5: |
| 1501 | case WM8996_POWER_MANAGEMENT_6: |
| 1502 | case WM8996_POWER_MANAGEMENT_7: |
| 1503 | case WM8996_POWER_MANAGEMENT_8: |
| 1504 | case WM8996_LEFT_LINE_INPUT_VOLUME: |
| 1505 | case WM8996_RIGHT_LINE_INPUT_VOLUME: |
| 1506 | case WM8996_LINE_INPUT_CONTROL: |
| 1507 | case WM8996_DAC1_HPOUT1_VOLUME: |
| 1508 | case WM8996_DAC2_HPOUT2_VOLUME: |
| 1509 | case WM8996_DAC1_LEFT_VOLUME: |
| 1510 | case WM8996_DAC1_RIGHT_VOLUME: |
| 1511 | case WM8996_DAC2_LEFT_VOLUME: |
| 1512 | case WM8996_DAC2_RIGHT_VOLUME: |
| 1513 | case WM8996_OUTPUT1_LEFT_VOLUME: |
| 1514 | case WM8996_OUTPUT1_RIGHT_VOLUME: |
| 1515 | case WM8996_OUTPUT2_LEFT_VOLUME: |
| 1516 | case WM8996_OUTPUT2_RIGHT_VOLUME: |
| 1517 | case WM8996_MICBIAS_1: |
| 1518 | case WM8996_MICBIAS_2: |
| 1519 | case WM8996_LDO_1: |
| 1520 | case WM8996_LDO_2: |
| 1521 | case WM8996_ACCESSORY_DETECT_MODE_1: |
| 1522 | case WM8996_ACCESSORY_DETECT_MODE_2: |
| 1523 | case WM8996_HEADPHONE_DETECT_1: |
| 1524 | case WM8996_HEADPHONE_DETECT_2: |
| 1525 | case WM8996_MIC_DETECT_1: |
| 1526 | case WM8996_MIC_DETECT_2: |
| 1527 | case WM8996_MIC_DETECT_3: |
| 1528 | case WM8996_CHARGE_PUMP_1: |
| 1529 | case WM8996_CHARGE_PUMP_2: |
| 1530 | case WM8996_DC_SERVO_1: |
| 1531 | case WM8996_DC_SERVO_2: |
| 1532 | case WM8996_DC_SERVO_3: |
| 1533 | case WM8996_DC_SERVO_5: |
| 1534 | case WM8996_DC_SERVO_6: |
| 1535 | case WM8996_DC_SERVO_7: |
| 1536 | case WM8996_DC_SERVO_READBACK_0: |
| 1537 | case WM8996_ANALOGUE_HP_1: |
| 1538 | case WM8996_ANALOGUE_HP_2: |
| 1539 | case WM8996_CHIP_REVISION: |
| 1540 | case WM8996_CONTROL_INTERFACE_1: |
| 1541 | case WM8996_WRITE_SEQUENCER_CTRL_1: |
| 1542 | case WM8996_WRITE_SEQUENCER_CTRL_2: |
| 1543 | case WM8996_AIF_CLOCKING_1: |
| 1544 | case WM8996_AIF_CLOCKING_2: |
| 1545 | case WM8996_CLOCKING_1: |
| 1546 | case WM8996_CLOCKING_2: |
| 1547 | case WM8996_AIF_RATE: |
| 1548 | case WM8996_FLL_CONTROL_1: |
| 1549 | case WM8996_FLL_CONTROL_2: |
| 1550 | case WM8996_FLL_CONTROL_3: |
| 1551 | case WM8996_FLL_CONTROL_4: |
| 1552 | case WM8996_FLL_CONTROL_5: |
| 1553 | case WM8996_FLL_CONTROL_6: |
| 1554 | case WM8996_FLL_EFS_1: |
| 1555 | case WM8996_FLL_EFS_2: |
| 1556 | case WM8996_AIF1_CONTROL: |
| 1557 | case WM8996_AIF1_BCLK: |
| 1558 | case WM8996_AIF1_TX_LRCLK_1: |
| 1559 | case WM8996_AIF1_TX_LRCLK_2: |
| 1560 | case WM8996_AIF1_RX_LRCLK_1: |
| 1561 | case WM8996_AIF1_RX_LRCLK_2: |
| 1562 | case WM8996_AIF1TX_DATA_CONFIGURATION_1: |
| 1563 | case WM8996_AIF1TX_DATA_CONFIGURATION_2: |
| 1564 | case WM8996_AIF1RX_DATA_CONFIGURATION: |
| 1565 | case WM8996_AIF1TX_CHANNEL_0_CONFIGURATION: |
| 1566 | case WM8996_AIF1TX_CHANNEL_1_CONFIGURATION: |
| 1567 | case WM8996_AIF1TX_CHANNEL_2_CONFIGURATION: |
| 1568 | case WM8996_AIF1TX_CHANNEL_3_CONFIGURATION: |
| 1569 | case WM8996_AIF1TX_CHANNEL_4_CONFIGURATION: |
| 1570 | case WM8996_AIF1TX_CHANNEL_5_CONFIGURATION: |
| 1571 | case WM8996_AIF1RX_CHANNEL_0_CONFIGURATION: |
| 1572 | case WM8996_AIF1RX_CHANNEL_1_CONFIGURATION: |
| 1573 | case WM8996_AIF1RX_CHANNEL_2_CONFIGURATION: |
| 1574 | case WM8996_AIF1RX_CHANNEL_3_CONFIGURATION: |
| 1575 | case WM8996_AIF1RX_CHANNEL_4_CONFIGURATION: |
| 1576 | case WM8996_AIF1RX_CHANNEL_5_CONFIGURATION: |
| 1577 | case WM8996_AIF1RX_MONO_CONFIGURATION: |
| 1578 | case WM8996_AIF1TX_TEST: |
| 1579 | case WM8996_AIF2_CONTROL: |
| 1580 | case WM8996_AIF2_BCLK: |
| 1581 | case WM8996_AIF2_TX_LRCLK_1: |
| 1582 | case WM8996_AIF2_TX_LRCLK_2: |
| 1583 | case WM8996_AIF2_RX_LRCLK_1: |
| 1584 | case WM8996_AIF2_RX_LRCLK_2: |
| 1585 | case WM8996_AIF2TX_DATA_CONFIGURATION_1: |
| 1586 | case WM8996_AIF2TX_DATA_CONFIGURATION_2: |
| 1587 | case WM8996_AIF2RX_DATA_CONFIGURATION: |
| 1588 | case WM8996_AIF2TX_CHANNEL_0_CONFIGURATION: |
| 1589 | case WM8996_AIF2TX_CHANNEL_1_CONFIGURATION: |
| 1590 | case WM8996_AIF2RX_CHANNEL_0_CONFIGURATION: |
| 1591 | case WM8996_AIF2RX_CHANNEL_1_CONFIGURATION: |
| 1592 | case WM8996_AIF2RX_MONO_CONFIGURATION: |
| 1593 | case WM8996_AIF2TX_TEST: |
| 1594 | case WM8996_DSP1_TX_LEFT_VOLUME: |
| 1595 | case WM8996_DSP1_TX_RIGHT_VOLUME: |
| 1596 | case WM8996_DSP1_RX_LEFT_VOLUME: |
| 1597 | case WM8996_DSP1_RX_RIGHT_VOLUME: |
| 1598 | case WM8996_DSP1_TX_FILTERS: |
| 1599 | case WM8996_DSP1_RX_FILTERS_1: |
| 1600 | case WM8996_DSP1_RX_FILTERS_2: |
| 1601 | case WM8996_DSP1_DRC_1: |
| 1602 | case WM8996_DSP1_DRC_2: |
| 1603 | case WM8996_DSP1_DRC_3: |
| 1604 | case WM8996_DSP1_DRC_4: |
| 1605 | case WM8996_DSP1_DRC_5: |
| 1606 | case WM8996_DSP1_RX_EQ_GAINS_1: |
| 1607 | case WM8996_DSP1_RX_EQ_GAINS_2: |
| 1608 | case WM8996_DSP1_RX_EQ_BAND_1_A: |
| 1609 | case WM8996_DSP1_RX_EQ_BAND_1_B: |
| 1610 | case WM8996_DSP1_RX_EQ_BAND_1_PG: |
| 1611 | case WM8996_DSP1_RX_EQ_BAND_2_A: |
| 1612 | case WM8996_DSP1_RX_EQ_BAND_2_B: |
| 1613 | case WM8996_DSP1_RX_EQ_BAND_2_C: |
| 1614 | case WM8996_DSP1_RX_EQ_BAND_2_PG: |
| 1615 | case WM8996_DSP1_RX_EQ_BAND_3_A: |
| 1616 | case WM8996_DSP1_RX_EQ_BAND_3_B: |
| 1617 | case WM8996_DSP1_RX_EQ_BAND_3_C: |
| 1618 | case WM8996_DSP1_RX_EQ_BAND_3_PG: |
| 1619 | case WM8996_DSP1_RX_EQ_BAND_4_A: |
| 1620 | case WM8996_DSP1_RX_EQ_BAND_4_B: |
| 1621 | case WM8996_DSP1_RX_EQ_BAND_4_C: |
| 1622 | case WM8996_DSP1_RX_EQ_BAND_4_PG: |
| 1623 | case WM8996_DSP1_RX_EQ_BAND_5_A: |
| 1624 | case WM8996_DSP1_RX_EQ_BAND_5_B: |
| 1625 | case WM8996_DSP1_RX_EQ_BAND_5_PG: |
| 1626 | case WM8996_DSP2_TX_LEFT_VOLUME: |
| 1627 | case WM8996_DSP2_TX_RIGHT_VOLUME: |
| 1628 | case WM8996_DSP2_RX_LEFT_VOLUME: |
| 1629 | case WM8996_DSP2_RX_RIGHT_VOLUME: |
| 1630 | case WM8996_DSP2_TX_FILTERS: |
| 1631 | case WM8996_DSP2_RX_FILTERS_1: |
| 1632 | case WM8996_DSP2_RX_FILTERS_2: |
| 1633 | case WM8996_DSP2_DRC_1: |
| 1634 | case WM8996_DSP2_DRC_2: |
| 1635 | case WM8996_DSP2_DRC_3: |
| 1636 | case WM8996_DSP2_DRC_4: |
| 1637 | case WM8996_DSP2_DRC_5: |
| 1638 | case WM8996_DSP2_RX_EQ_GAINS_1: |
| 1639 | case WM8996_DSP2_RX_EQ_GAINS_2: |
| 1640 | case WM8996_DSP2_RX_EQ_BAND_1_A: |
| 1641 | case WM8996_DSP2_RX_EQ_BAND_1_B: |
| 1642 | case WM8996_DSP2_RX_EQ_BAND_1_PG: |
| 1643 | case WM8996_DSP2_RX_EQ_BAND_2_A: |
| 1644 | case WM8996_DSP2_RX_EQ_BAND_2_B: |
| 1645 | case WM8996_DSP2_RX_EQ_BAND_2_C: |
| 1646 | case WM8996_DSP2_RX_EQ_BAND_2_PG: |
| 1647 | case WM8996_DSP2_RX_EQ_BAND_3_A: |
| 1648 | case WM8996_DSP2_RX_EQ_BAND_3_B: |
| 1649 | case WM8996_DSP2_RX_EQ_BAND_3_C: |
| 1650 | case WM8996_DSP2_RX_EQ_BAND_3_PG: |
| 1651 | case WM8996_DSP2_RX_EQ_BAND_4_A: |
| 1652 | case WM8996_DSP2_RX_EQ_BAND_4_B: |
| 1653 | case WM8996_DSP2_RX_EQ_BAND_4_C: |
| 1654 | case WM8996_DSP2_RX_EQ_BAND_4_PG: |
| 1655 | case WM8996_DSP2_RX_EQ_BAND_5_A: |
| 1656 | case WM8996_DSP2_RX_EQ_BAND_5_B: |
| 1657 | case WM8996_DSP2_RX_EQ_BAND_5_PG: |
| 1658 | case WM8996_DAC1_MIXER_VOLUMES: |
| 1659 | case WM8996_DAC1_LEFT_MIXER_ROUTING: |
| 1660 | case WM8996_DAC1_RIGHT_MIXER_ROUTING: |
| 1661 | case WM8996_DAC2_MIXER_VOLUMES: |
| 1662 | case WM8996_DAC2_LEFT_MIXER_ROUTING: |
| 1663 | case WM8996_DAC2_RIGHT_MIXER_ROUTING: |
| 1664 | case WM8996_DSP1_TX_LEFT_MIXER_ROUTING: |
| 1665 | case WM8996_DSP1_TX_RIGHT_MIXER_ROUTING: |
| 1666 | case WM8996_DSP2_TX_LEFT_MIXER_ROUTING: |
| 1667 | case WM8996_DSP2_TX_RIGHT_MIXER_ROUTING: |
| 1668 | case WM8996_DSP_TX_MIXER_SELECT: |
| 1669 | case WM8996_DAC_SOFTMUTE: |
| 1670 | case WM8996_OVERSAMPLING: |
| 1671 | case WM8996_SIDETONE: |
| 1672 | case WM8996_GPIO_1: |
| 1673 | case WM8996_GPIO_2: |
| 1674 | case WM8996_GPIO_3: |
| 1675 | case WM8996_GPIO_4: |
| 1676 | case WM8996_GPIO_5: |
| 1677 | case WM8996_PULL_CONTROL_1: |
| 1678 | case WM8996_PULL_CONTROL_2: |
| 1679 | case WM8996_INTERRUPT_STATUS_1: |
| 1680 | case WM8996_INTERRUPT_STATUS_2: |
| 1681 | case WM8996_INTERRUPT_RAW_STATUS_2: |
| 1682 | case WM8996_INTERRUPT_STATUS_1_MASK: |
| 1683 | case WM8996_INTERRUPT_STATUS_2_MASK: |
| 1684 | case WM8996_INTERRUPT_CONTROL: |
| 1685 | case WM8996_LEFT_PDM_SPEAKER: |
| 1686 | case WM8996_RIGHT_PDM_SPEAKER: |
| 1687 | case WM8996_PDM_SPEAKER_MUTE_SEQUENCE: |
| 1688 | case WM8996_PDM_SPEAKER_VOLUME: |
| 1689 | return 1; |
| 1690 | default: |
| 1691 | return 0; |
| 1692 | } |
| 1693 | } |
| 1694 | |
Mark Brown | 7917274 | 2011-09-19 16:15:58 +0100 | [diff] [blame] | 1695 | static bool wm8996_volatile_register(struct device *dev, unsigned int reg) |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 1696 | { |
| 1697 | switch (reg) { |
| 1698 | case WM8996_SOFTWARE_RESET: |
| 1699 | case WM8996_CHIP_REVISION: |
| 1700 | case WM8996_LDO_1: |
| 1701 | case WM8996_LDO_2: |
| 1702 | case WM8996_INTERRUPT_STATUS_1: |
| 1703 | case WM8996_INTERRUPT_STATUS_2: |
| 1704 | case WM8996_INTERRUPT_RAW_STATUS_2: |
| 1705 | case WM8996_DC_SERVO_READBACK_0: |
| 1706 | case WM8996_DC_SERVO_2: |
| 1707 | case WM8996_DC_SERVO_6: |
| 1708 | case WM8996_DC_SERVO_7: |
| 1709 | case WM8996_FLL_CONTROL_6: |
| 1710 | case WM8996_MIC_DETECT_3: |
| 1711 | case WM8996_HEADPHONE_DETECT_1: |
| 1712 | case WM8996_HEADPHONE_DETECT_2: |
| 1713 | return 1; |
| 1714 | default: |
| 1715 | return 0; |
| 1716 | } |
| 1717 | } |
| 1718 | |
Mark Brown | ee5f387 | 2011-09-19 19:51:07 +0100 | [diff] [blame] | 1719 | static int wm8996_reset(struct wm8996_priv *wm8996) |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 1720 | { |
Mark Brown | ee5f387 | 2011-09-19 19:51:07 +0100 | [diff] [blame] | 1721 | if (wm8996->pdata.ldo_ena > 0) { |
| 1722 | gpio_set_value_cansleep(wm8996->pdata.ldo_ena, 0); |
| 1723 | return 0; |
| 1724 | } else { |
| 1725 | return regmap_write(wm8996->regmap, WM8996_SOFTWARE_RESET, |
| 1726 | 0x8915); |
| 1727 | } |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 1728 | } |
| 1729 | |
| 1730 | static const int bclk_divs[] = { |
| 1731 | 1, 2, 3, 4, 6, 8, 12, 16, 24, 32, 48, 64, 96 |
| 1732 | }; |
| 1733 | |
| 1734 | static void wm8996_update_bclk(struct snd_soc_codec *codec) |
| 1735 | { |
| 1736 | struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec); |
| 1737 | int aif, best, cur_val, bclk_rate, bclk_reg, i; |
| 1738 | |
| 1739 | /* Don't bother if we're in a low frequency idle mode that |
| 1740 | * can't support audio. |
| 1741 | */ |
| 1742 | if (wm8996->sysclk < 64000) |
| 1743 | return; |
| 1744 | |
| 1745 | for (aif = 0; aif < WM8996_AIFS; aif++) { |
| 1746 | switch (aif) { |
| 1747 | case 0: |
| 1748 | bclk_reg = WM8996_AIF1_BCLK; |
| 1749 | break; |
| 1750 | case 1: |
| 1751 | bclk_reg = WM8996_AIF2_BCLK; |
| 1752 | break; |
| 1753 | } |
| 1754 | |
| 1755 | bclk_rate = wm8996->bclk_rate[aif]; |
| 1756 | |
| 1757 | /* Pick a divisor for BCLK as close as we can get to ideal */ |
| 1758 | best = 0; |
| 1759 | for (i = 0; i < ARRAY_SIZE(bclk_divs); i++) { |
| 1760 | cur_val = (wm8996->sysclk / bclk_divs[i]) - bclk_rate; |
| 1761 | if (cur_val < 0) /* BCLK table is sorted */ |
| 1762 | break; |
| 1763 | best = i; |
| 1764 | } |
| 1765 | bclk_rate = wm8996->sysclk / bclk_divs[best]; |
| 1766 | dev_dbg(codec->dev, "Using BCLK_DIV %d for actual BCLK %dHz\n", |
| 1767 | bclk_divs[best], bclk_rate); |
| 1768 | |
| 1769 | snd_soc_update_bits(codec, bclk_reg, |
| 1770 | WM8996_AIF1_BCLK_DIV_MASK, best); |
| 1771 | } |
| 1772 | } |
| 1773 | |
| 1774 | static int wm8996_set_bias_level(struct snd_soc_codec *codec, |
| 1775 | enum snd_soc_bias_level level) |
| 1776 | { |
| 1777 | struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec); |
| 1778 | int ret; |
| 1779 | |
| 1780 | switch (level) { |
| 1781 | case SND_SOC_BIAS_ON: |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 1782 | case SND_SOC_BIAS_PREPARE: |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 1783 | break; |
| 1784 | |
| 1785 | case SND_SOC_BIAS_STANDBY: |
| 1786 | if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { |
| 1787 | ret = regulator_bulk_enable(ARRAY_SIZE(wm8996->supplies), |
| 1788 | wm8996->supplies); |
| 1789 | if (ret != 0) { |
| 1790 | dev_err(codec->dev, |
| 1791 | "Failed to enable supplies: %d\n", |
| 1792 | ret); |
| 1793 | return ret; |
| 1794 | } |
| 1795 | |
| 1796 | if (wm8996->pdata.ldo_ena >= 0) { |
| 1797 | gpio_set_value_cansleep(wm8996->pdata.ldo_ena, |
| 1798 | 1); |
| 1799 | msleep(5); |
| 1800 | } |
| 1801 | |
Mark Brown | 7917274 | 2011-09-19 16:15:58 +0100 | [diff] [blame] | 1802 | regcache_cache_only(codec->control_data, false); |
| 1803 | regcache_sync(codec->control_data); |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 1804 | } |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 1805 | break; |
| 1806 | |
| 1807 | case SND_SOC_BIAS_OFF: |
Mark Brown | 7917274 | 2011-09-19 16:15:58 +0100 | [diff] [blame] | 1808 | regcache_cache_only(codec->control_data, true); |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 1809 | if (wm8996->pdata.ldo_ena >= 0) |
| 1810 | gpio_set_value_cansleep(wm8996->pdata.ldo_ena, 0); |
| 1811 | regulator_bulk_disable(ARRAY_SIZE(wm8996->supplies), |
| 1812 | wm8996->supplies); |
| 1813 | break; |
| 1814 | } |
| 1815 | |
| 1816 | codec->dapm.bias_level = level; |
| 1817 | |
| 1818 | return 0; |
| 1819 | } |
| 1820 | |
| 1821 | static int wm8996_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) |
| 1822 | { |
| 1823 | struct snd_soc_codec *codec = dai->codec; |
| 1824 | int aifctrl = 0; |
| 1825 | int bclk = 0; |
| 1826 | int lrclk_tx = 0; |
| 1827 | int lrclk_rx = 0; |
| 1828 | int aifctrl_reg, bclk_reg, lrclk_tx_reg, lrclk_rx_reg; |
| 1829 | |
| 1830 | switch (dai->id) { |
| 1831 | case 0: |
| 1832 | aifctrl_reg = WM8996_AIF1_CONTROL; |
| 1833 | bclk_reg = WM8996_AIF1_BCLK; |
| 1834 | lrclk_tx_reg = WM8996_AIF1_TX_LRCLK_2; |
| 1835 | lrclk_rx_reg = WM8996_AIF1_RX_LRCLK_2; |
| 1836 | break; |
| 1837 | case 1: |
| 1838 | aifctrl_reg = WM8996_AIF2_CONTROL; |
| 1839 | bclk_reg = WM8996_AIF2_BCLK; |
| 1840 | lrclk_tx_reg = WM8996_AIF2_TX_LRCLK_2; |
| 1841 | lrclk_rx_reg = WM8996_AIF2_RX_LRCLK_2; |
| 1842 | break; |
| 1843 | default: |
| 1844 | BUG(); |
| 1845 | return -EINVAL; |
| 1846 | } |
| 1847 | |
| 1848 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { |
| 1849 | case SND_SOC_DAIFMT_NB_NF: |
| 1850 | break; |
| 1851 | case SND_SOC_DAIFMT_IB_NF: |
| 1852 | bclk |= WM8996_AIF1_BCLK_INV; |
| 1853 | break; |
| 1854 | case SND_SOC_DAIFMT_NB_IF: |
| 1855 | lrclk_tx |= WM8996_AIF1TX_LRCLK_INV; |
| 1856 | lrclk_rx |= WM8996_AIF1RX_LRCLK_INV; |
| 1857 | break; |
| 1858 | case SND_SOC_DAIFMT_IB_IF: |
| 1859 | bclk |= WM8996_AIF1_BCLK_INV; |
| 1860 | lrclk_tx |= WM8996_AIF1TX_LRCLK_INV; |
| 1861 | lrclk_rx |= WM8996_AIF1RX_LRCLK_INV; |
| 1862 | break; |
| 1863 | } |
| 1864 | |
| 1865 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 1866 | case SND_SOC_DAIFMT_CBS_CFS: |
| 1867 | break; |
| 1868 | case SND_SOC_DAIFMT_CBS_CFM: |
| 1869 | lrclk_tx |= WM8996_AIF1TX_LRCLK_MSTR; |
| 1870 | lrclk_rx |= WM8996_AIF1RX_LRCLK_MSTR; |
| 1871 | break; |
| 1872 | case SND_SOC_DAIFMT_CBM_CFS: |
| 1873 | bclk |= WM8996_AIF1_BCLK_MSTR; |
| 1874 | break; |
| 1875 | case SND_SOC_DAIFMT_CBM_CFM: |
| 1876 | bclk |= WM8996_AIF1_BCLK_MSTR; |
| 1877 | lrclk_tx |= WM8996_AIF1TX_LRCLK_MSTR; |
| 1878 | lrclk_rx |= WM8996_AIF1RX_LRCLK_MSTR; |
| 1879 | break; |
| 1880 | default: |
| 1881 | return -EINVAL; |
| 1882 | } |
| 1883 | |
| 1884 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 1885 | case SND_SOC_DAIFMT_DSP_A: |
| 1886 | break; |
| 1887 | case SND_SOC_DAIFMT_DSP_B: |
| 1888 | aifctrl |= 1; |
| 1889 | break; |
| 1890 | case SND_SOC_DAIFMT_I2S: |
| 1891 | aifctrl |= 2; |
| 1892 | break; |
| 1893 | case SND_SOC_DAIFMT_LEFT_J: |
| 1894 | aifctrl |= 3; |
| 1895 | break; |
| 1896 | default: |
| 1897 | return -EINVAL; |
| 1898 | } |
| 1899 | |
| 1900 | snd_soc_update_bits(codec, aifctrl_reg, WM8996_AIF1_FMT_MASK, aifctrl); |
| 1901 | snd_soc_update_bits(codec, bclk_reg, |
| 1902 | WM8996_AIF1_BCLK_INV | WM8996_AIF1_BCLK_MSTR, |
| 1903 | bclk); |
| 1904 | snd_soc_update_bits(codec, lrclk_tx_reg, |
| 1905 | WM8996_AIF1TX_LRCLK_INV | |
| 1906 | WM8996_AIF1TX_LRCLK_MSTR, |
| 1907 | lrclk_tx); |
| 1908 | snd_soc_update_bits(codec, lrclk_rx_reg, |
| 1909 | WM8996_AIF1RX_LRCLK_INV | |
| 1910 | WM8996_AIF1RX_LRCLK_MSTR, |
| 1911 | lrclk_rx); |
| 1912 | |
| 1913 | return 0; |
| 1914 | } |
| 1915 | |
| 1916 | static const int dsp_divs[] = { |
| 1917 | 48000, 32000, 16000, 8000 |
| 1918 | }; |
| 1919 | |
| 1920 | static int wm8996_hw_params(struct snd_pcm_substream *substream, |
| 1921 | struct snd_pcm_hw_params *params, |
| 1922 | struct snd_soc_dai *dai) |
| 1923 | { |
| 1924 | struct snd_soc_codec *codec = dai->codec; |
| 1925 | struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec); |
| 1926 | int bits, i, bclk_rate; |
| 1927 | int aifdata = 0; |
| 1928 | int lrclk = 0; |
| 1929 | int dsp = 0; |
| 1930 | int aifdata_reg, lrclk_reg, dsp_shift; |
| 1931 | |
| 1932 | switch (dai->id) { |
| 1933 | case 0: |
| 1934 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK || |
| 1935 | (snd_soc_read(codec, WM8996_GPIO_1)) & WM8996_GP1_FN_MASK) { |
| 1936 | aifdata_reg = WM8996_AIF1RX_DATA_CONFIGURATION; |
| 1937 | lrclk_reg = WM8996_AIF1_RX_LRCLK_1; |
| 1938 | } else { |
| 1939 | aifdata_reg = WM8996_AIF1TX_DATA_CONFIGURATION_1; |
| 1940 | lrclk_reg = WM8996_AIF1_TX_LRCLK_1; |
| 1941 | } |
| 1942 | dsp_shift = 0; |
| 1943 | break; |
| 1944 | case 1: |
| 1945 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK || |
| 1946 | (snd_soc_read(codec, WM8996_GPIO_2)) & WM8996_GP2_FN_MASK) { |
| 1947 | aifdata_reg = WM8996_AIF2RX_DATA_CONFIGURATION; |
| 1948 | lrclk_reg = WM8996_AIF2_RX_LRCLK_1; |
| 1949 | } else { |
| 1950 | aifdata_reg = WM8996_AIF2TX_DATA_CONFIGURATION_1; |
| 1951 | lrclk_reg = WM8996_AIF2_TX_LRCLK_1; |
| 1952 | } |
| 1953 | dsp_shift = WM8996_DSP2_DIV_SHIFT; |
| 1954 | break; |
| 1955 | default: |
| 1956 | BUG(); |
| 1957 | return -EINVAL; |
| 1958 | } |
| 1959 | |
| 1960 | bclk_rate = snd_soc_params_to_bclk(params); |
| 1961 | if (bclk_rate < 0) { |
| 1962 | dev_err(codec->dev, "Unsupported BCLK rate: %d\n", bclk_rate); |
| 1963 | return bclk_rate; |
| 1964 | } |
| 1965 | |
| 1966 | wm8996->bclk_rate[dai->id] = bclk_rate; |
| 1967 | wm8996->rx_rate[dai->id] = params_rate(params); |
| 1968 | |
| 1969 | /* Needs looking at for TDM */ |
| 1970 | bits = snd_pcm_format_width(params_format(params)); |
| 1971 | if (bits < 0) |
| 1972 | return bits; |
| 1973 | aifdata |= (bits << WM8996_AIF1TX_WL_SHIFT) | bits; |
| 1974 | |
| 1975 | for (i = 0; i < ARRAY_SIZE(dsp_divs); i++) { |
| 1976 | if (dsp_divs[i] == params_rate(params)) |
| 1977 | break; |
| 1978 | } |
| 1979 | if (i == ARRAY_SIZE(dsp_divs)) { |
| 1980 | dev_err(codec->dev, "Unsupported sample rate %dHz\n", |
| 1981 | params_rate(params)); |
| 1982 | return -EINVAL; |
| 1983 | } |
| 1984 | dsp |= i << dsp_shift; |
| 1985 | |
| 1986 | wm8996_update_bclk(codec); |
| 1987 | |
| 1988 | lrclk = bclk_rate / params_rate(params); |
| 1989 | dev_dbg(dai->dev, "Using LRCLK rate %d for actual LRCLK %dHz\n", |
| 1990 | lrclk, bclk_rate / lrclk); |
| 1991 | |
| 1992 | snd_soc_update_bits(codec, aifdata_reg, |
| 1993 | WM8996_AIF1TX_WL_MASK | |
| 1994 | WM8996_AIF1TX_SLOT_LEN_MASK, |
| 1995 | aifdata); |
| 1996 | snd_soc_update_bits(codec, lrclk_reg, WM8996_AIF1RX_RATE_MASK, |
| 1997 | lrclk); |
| 1998 | snd_soc_update_bits(codec, WM8996_AIF_CLOCKING_2, |
Axel Lin | 3205e66 | 2011-10-21 10:44:07 +0800 | [diff] [blame] | 1999 | WM8996_DSP1_DIV_MASK << dsp_shift, dsp); |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2000 | |
| 2001 | return 0; |
| 2002 | } |
| 2003 | |
| 2004 | static int wm8996_set_sysclk(struct snd_soc_dai *dai, |
| 2005 | int clk_id, unsigned int freq, int dir) |
| 2006 | { |
| 2007 | struct snd_soc_codec *codec = dai->codec; |
| 2008 | struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec); |
| 2009 | int lfclk = 0; |
| 2010 | int ratediv = 0; |
Mark Brown | fed2200 | 2012-01-18 19:17:06 +0000 | [diff] [blame] | 2011 | int sync = WM8996_REG_SYNC; |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2012 | int src; |
| 2013 | int old; |
| 2014 | |
| 2015 | if (freq == wm8996->sysclk && clk_id == wm8996->sysclk_src) |
| 2016 | return 0; |
| 2017 | |
| 2018 | /* Disable SYSCLK while we reconfigure */ |
| 2019 | old = snd_soc_read(codec, WM8996_AIF_CLOCKING_1) & WM8996_SYSCLK_ENA; |
| 2020 | snd_soc_update_bits(codec, WM8996_AIF_CLOCKING_1, |
| 2021 | WM8996_SYSCLK_ENA, 0); |
| 2022 | |
| 2023 | switch (clk_id) { |
| 2024 | case WM8996_SYSCLK_MCLK1: |
| 2025 | wm8996->sysclk = freq; |
| 2026 | src = 0; |
| 2027 | break; |
| 2028 | case WM8996_SYSCLK_MCLK2: |
| 2029 | wm8996->sysclk = freq; |
| 2030 | src = 1; |
| 2031 | break; |
| 2032 | case WM8996_SYSCLK_FLL: |
| 2033 | wm8996->sysclk = freq; |
| 2034 | src = 2; |
| 2035 | break; |
| 2036 | default: |
| 2037 | dev_err(codec->dev, "Unsupported clock source %d\n", clk_id); |
| 2038 | return -EINVAL; |
| 2039 | } |
| 2040 | |
| 2041 | switch (wm8996->sysclk) { |
| 2042 | case 6144000: |
| 2043 | snd_soc_update_bits(codec, WM8996_AIF_RATE, |
| 2044 | WM8996_SYSCLK_RATE, 0); |
| 2045 | break; |
| 2046 | case 24576000: |
| 2047 | ratediv = WM8996_SYSCLK_DIV; |
Mark Brown | 37d5993 | 2011-12-10 20:38:32 +0800 | [diff] [blame] | 2048 | wm8996->sysclk /= 2; |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2049 | case 12288000: |
| 2050 | snd_soc_update_bits(codec, WM8996_AIF_RATE, |
| 2051 | WM8996_SYSCLK_RATE, WM8996_SYSCLK_RATE); |
| 2052 | break; |
| 2053 | case 32000: |
| 2054 | case 32768: |
| 2055 | lfclk = WM8996_LFCLK_ENA; |
Mark Brown | fed2200 | 2012-01-18 19:17:06 +0000 | [diff] [blame] | 2056 | sync = 0; |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2057 | break; |
| 2058 | default: |
| 2059 | dev_warn(codec->dev, "Unsupported clock rate %dHz\n", |
| 2060 | wm8996->sysclk); |
| 2061 | return -EINVAL; |
| 2062 | } |
| 2063 | |
| 2064 | wm8996_update_bclk(codec); |
| 2065 | |
| 2066 | snd_soc_update_bits(codec, WM8996_AIF_CLOCKING_1, |
| 2067 | WM8996_SYSCLK_SRC_MASK | WM8996_SYSCLK_DIV_MASK, |
| 2068 | src << WM8996_SYSCLK_SRC_SHIFT | ratediv); |
| 2069 | snd_soc_update_bits(codec, WM8996_CLOCKING_1, WM8996_LFCLK_ENA, lfclk); |
Mark Brown | fed2200 | 2012-01-18 19:17:06 +0000 | [diff] [blame] | 2070 | snd_soc_update_bits(codec, WM8996_CONTROL_INTERFACE_1, |
| 2071 | WM8996_REG_SYNC, sync); |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2072 | snd_soc_update_bits(codec, WM8996_AIF_CLOCKING_1, |
| 2073 | WM8996_SYSCLK_ENA, old); |
| 2074 | |
| 2075 | wm8996->sysclk_src = clk_id; |
| 2076 | |
| 2077 | return 0; |
| 2078 | } |
| 2079 | |
| 2080 | struct _fll_div { |
| 2081 | u16 fll_fratio; |
| 2082 | u16 fll_outdiv; |
| 2083 | u16 fll_refclk_div; |
| 2084 | u16 fll_loop_gain; |
| 2085 | u16 fll_ref_freq; |
| 2086 | u16 n; |
| 2087 | u16 theta; |
| 2088 | u16 lambda; |
| 2089 | }; |
| 2090 | |
| 2091 | static struct { |
| 2092 | unsigned int min; |
| 2093 | unsigned int max; |
| 2094 | u16 fll_fratio; |
| 2095 | int ratio; |
| 2096 | } fll_fratios[] = { |
| 2097 | { 0, 64000, 4, 16 }, |
| 2098 | { 64000, 128000, 3, 8 }, |
| 2099 | { 128000, 256000, 2, 4 }, |
| 2100 | { 256000, 1000000, 1, 2 }, |
| 2101 | { 1000000, 13500000, 0, 1 }, |
| 2102 | }; |
| 2103 | |
| 2104 | static int fll_factors(struct _fll_div *fll_div, unsigned int Fref, |
| 2105 | unsigned int Fout) |
| 2106 | { |
| 2107 | unsigned int target; |
| 2108 | unsigned int div; |
| 2109 | unsigned int fratio, gcd_fll; |
| 2110 | int i; |
| 2111 | |
| 2112 | /* Fref must be <=13.5MHz */ |
| 2113 | div = 1; |
| 2114 | fll_div->fll_refclk_div = 0; |
| 2115 | while ((Fref / div) > 13500000) { |
| 2116 | div *= 2; |
| 2117 | fll_div->fll_refclk_div++; |
| 2118 | |
| 2119 | if (div > 8) { |
| 2120 | pr_err("Can't scale %dMHz input down to <=13.5MHz\n", |
| 2121 | Fref); |
| 2122 | return -EINVAL; |
| 2123 | } |
| 2124 | } |
| 2125 | |
| 2126 | pr_debug("FLL Fref=%u Fout=%u\n", Fref, Fout); |
| 2127 | |
| 2128 | /* Apply the division for our remaining calculations */ |
| 2129 | Fref /= div; |
| 2130 | |
| 2131 | if (Fref >= 3000000) |
| 2132 | fll_div->fll_loop_gain = 5; |
| 2133 | else |
| 2134 | fll_div->fll_loop_gain = 0; |
| 2135 | |
| 2136 | if (Fref >= 48000) |
| 2137 | fll_div->fll_ref_freq = 0; |
| 2138 | else |
| 2139 | fll_div->fll_ref_freq = 1; |
| 2140 | |
| 2141 | /* Fvco should be 90-100MHz; don't check the upper bound */ |
| 2142 | div = 2; |
| 2143 | while (Fout * div < 90000000) { |
| 2144 | div++; |
| 2145 | if (div > 64) { |
| 2146 | pr_err("Unable to find FLL_OUTDIV for Fout=%uHz\n", |
| 2147 | Fout); |
| 2148 | return -EINVAL; |
| 2149 | } |
| 2150 | } |
| 2151 | target = Fout * div; |
| 2152 | fll_div->fll_outdiv = div - 1; |
| 2153 | |
| 2154 | pr_debug("FLL Fvco=%dHz\n", target); |
| 2155 | |
| 2156 | /* Find an appropraite FLL_FRATIO and factor it out of the target */ |
| 2157 | for (i = 0; i < ARRAY_SIZE(fll_fratios); i++) { |
| 2158 | if (fll_fratios[i].min <= Fref && Fref <= fll_fratios[i].max) { |
| 2159 | fll_div->fll_fratio = fll_fratios[i].fll_fratio; |
| 2160 | fratio = fll_fratios[i].ratio; |
| 2161 | break; |
| 2162 | } |
| 2163 | } |
| 2164 | if (i == ARRAY_SIZE(fll_fratios)) { |
| 2165 | pr_err("Unable to find FLL_FRATIO for Fref=%uHz\n", Fref); |
| 2166 | return -EINVAL; |
| 2167 | } |
| 2168 | |
| 2169 | fll_div->n = target / (fratio * Fref); |
| 2170 | |
| 2171 | if (target % Fref == 0) { |
| 2172 | fll_div->theta = 0; |
| 2173 | fll_div->lambda = 0; |
| 2174 | } else { |
| 2175 | gcd_fll = gcd(target, fratio * Fref); |
| 2176 | |
| 2177 | fll_div->theta = (target - (fll_div->n * fratio * Fref)) |
| 2178 | / gcd_fll; |
| 2179 | fll_div->lambda = (fratio * Fref) / gcd_fll; |
| 2180 | } |
| 2181 | |
| 2182 | pr_debug("FLL N=%x THETA=%x LAMBDA=%x\n", |
| 2183 | fll_div->n, fll_div->theta, fll_div->lambda); |
| 2184 | pr_debug("FLL_FRATIO=%x FLL_OUTDIV=%x FLL_REFCLK_DIV=%x\n", |
| 2185 | fll_div->fll_fratio, fll_div->fll_outdiv, |
| 2186 | fll_div->fll_refclk_div); |
| 2187 | |
| 2188 | return 0; |
| 2189 | } |
| 2190 | |
| 2191 | static int wm8996_set_fll(struct snd_soc_codec *codec, int fll_id, int source, |
| 2192 | unsigned int Fref, unsigned int Fout) |
| 2193 | { |
| 2194 | struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec); |
| 2195 | struct i2c_client *i2c = to_i2c_client(codec->dev); |
| 2196 | struct _fll_div fll_div; |
| 2197 | unsigned long timeout; |
Mark Brown | 27b6d92 | 2011-09-04 09:35:47 -0700 | [diff] [blame] | 2198 | int ret, reg, retry; |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2199 | |
| 2200 | /* Any change? */ |
| 2201 | if (source == wm8996->fll_src && Fref == wm8996->fll_fref && |
| 2202 | Fout == wm8996->fll_fout) |
| 2203 | return 0; |
| 2204 | |
| 2205 | if (Fout == 0) { |
| 2206 | dev_dbg(codec->dev, "FLL disabled\n"); |
| 2207 | |
| 2208 | wm8996->fll_fref = 0; |
| 2209 | wm8996->fll_fout = 0; |
| 2210 | |
| 2211 | snd_soc_update_bits(codec, WM8996_FLL_CONTROL_1, |
| 2212 | WM8996_FLL_ENA, 0); |
| 2213 | |
Mark Brown | ded71dc | 2011-09-19 18:50:05 +0100 | [diff] [blame] | 2214 | wm8996_bg_disable(codec); |
| 2215 | |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2216 | return 0; |
| 2217 | } |
| 2218 | |
| 2219 | ret = fll_factors(&fll_div, Fref, Fout); |
| 2220 | if (ret != 0) |
| 2221 | return ret; |
| 2222 | |
| 2223 | switch (source) { |
| 2224 | case WM8996_FLL_MCLK1: |
| 2225 | reg = 0; |
| 2226 | break; |
| 2227 | case WM8996_FLL_MCLK2: |
| 2228 | reg = 1; |
| 2229 | break; |
| 2230 | case WM8996_FLL_DACLRCLK1: |
| 2231 | reg = 2; |
| 2232 | break; |
| 2233 | case WM8996_FLL_BCLK1: |
| 2234 | reg = 3; |
| 2235 | break; |
| 2236 | default: |
| 2237 | dev_err(codec->dev, "Unknown FLL source %d\n", ret); |
| 2238 | return -EINVAL; |
| 2239 | } |
| 2240 | |
| 2241 | reg |= fll_div.fll_refclk_div << WM8996_FLL_REFCLK_DIV_SHIFT; |
| 2242 | reg |= fll_div.fll_ref_freq << WM8996_FLL_REF_FREQ_SHIFT; |
| 2243 | |
| 2244 | snd_soc_update_bits(codec, WM8996_FLL_CONTROL_5, |
| 2245 | WM8996_FLL_REFCLK_DIV_MASK | WM8996_FLL_REF_FREQ | |
| 2246 | WM8996_FLL_REFCLK_SRC_MASK, reg); |
| 2247 | |
| 2248 | reg = 0; |
| 2249 | if (fll_div.theta || fll_div.lambda) |
| 2250 | reg |= WM8996_FLL_EFS_ENA | (3 << WM8996_FLL_LFSR_SEL_SHIFT); |
| 2251 | else |
| 2252 | reg |= 1 << WM8996_FLL_LFSR_SEL_SHIFT; |
| 2253 | snd_soc_write(codec, WM8996_FLL_EFS_2, reg); |
| 2254 | |
| 2255 | snd_soc_update_bits(codec, WM8996_FLL_CONTROL_2, |
| 2256 | WM8996_FLL_OUTDIV_MASK | |
| 2257 | WM8996_FLL_FRATIO_MASK, |
| 2258 | (fll_div.fll_outdiv << WM8996_FLL_OUTDIV_SHIFT) | |
| 2259 | (fll_div.fll_fratio)); |
| 2260 | |
| 2261 | snd_soc_write(codec, WM8996_FLL_CONTROL_3, fll_div.theta); |
| 2262 | |
| 2263 | snd_soc_update_bits(codec, WM8996_FLL_CONTROL_4, |
| 2264 | WM8996_FLL_N_MASK | WM8996_FLL_LOOP_GAIN_MASK, |
| 2265 | (fll_div.n << WM8996_FLL_N_SHIFT) | |
| 2266 | fll_div.fll_loop_gain); |
| 2267 | |
| 2268 | snd_soc_write(codec, WM8996_FLL_EFS_1, fll_div.lambda); |
| 2269 | |
Mark Brown | ded71dc | 2011-09-19 18:50:05 +0100 | [diff] [blame] | 2270 | /* Enable the bandgap if it's not already enabled */ |
| 2271 | ret = snd_soc_read(codec, WM8996_FLL_CONTROL_1); |
| 2272 | if (!(ret & WM8996_FLL_ENA)) |
| 2273 | wm8996_bg_enable(codec); |
| 2274 | |
Mark Brown | a416194 | 2011-08-16 16:57:58 +0900 | [diff] [blame] | 2275 | /* Clear any pending completions (eg, from failed startups) */ |
| 2276 | try_wait_for_completion(&wm8996->fll_lock); |
| 2277 | |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2278 | snd_soc_update_bits(codec, WM8996_FLL_CONTROL_1, |
| 2279 | WM8996_FLL_ENA, WM8996_FLL_ENA); |
| 2280 | |
| 2281 | /* The FLL supports live reconfiguration - kick that in case we were |
| 2282 | * already enabled. |
| 2283 | */ |
| 2284 | snd_soc_write(codec, WM8996_FLL_CONTROL_6, WM8996_FLL_SWITCH_CLK); |
| 2285 | |
| 2286 | /* Wait for the FLL to lock, using the interrupt if possible */ |
| 2287 | if (Fref > 1000000) |
| 2288 | timeout = usecs_to_jiffies(300); |
| 2289 | else |
| 2290 | timeout = msecs_to_jiffies(2); |
| 2291 | |
Mark Brown | 27b6d92 | 2011-09-04 09:35:47 -0700 | [diff] [blame] | 2292 | /* Allow substantially longer if we've actually got the IRQ, poll |
| 2293 | * at a slightly higher rate if we don't. |
| 2294 | */ |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2295 | if (i2c->irq) |
Mark Brown | 27b6d92 | 2011-09-04 09:35:47 -0700 | [diff] [blame] | 2296 | timeout *= 10; |
| 2297 | else |
| 2298 | timeout /= 2; |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2299 | |
Mark Brown | 27b6d92 | 2011-09-04 09:35:47 -0700 | [diff] [blame] | 2300 | for (retry = 0; retry < 10; retry++) { |
| 2301 | ret = wait_for_completion_timeout(&wm8996->fll_lock, |
| 2302 | timeout); |
| 2303 | if (ret != 0) { |
| 2304 | WARN_ON(!i2c->irq); |
| 2305 | break; |
| 2306 | } |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2307 | |
Mark Brown | 27b6d92 | 2011-09-04 09:35:47 -0700 | [diff] [blame] | 2308 | ret = snd_soc_read(codec, WM8996_INTERRUPT_RAW_STATUS_2); |
| 2309 | if (ret & WM8996_FLL_LOCK_STS) |
| 2310 | break; |
| 2311 | } |
| 2312 | if (retry == 10) { |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2313 | dev_err(codec->dev, "Timed out waiting for FLL\n"); |
| 2314 | ret = -ETIMEDOUT; |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2315 | } |
| 2316 | |
| 2317 | dev_dbg(codec->dev, "FLL configured for %dHz->%dHz\n", Fref, Fout); |
| 2318 | |
| 2319 | wm8996->fll_fref = Fref; |
| 2320 | wm8996->fll_fout = Fout; |
| 2321 | wm8996->fll_src = source; |
| 2322 | |
| 2323 | return ret; |
| 2324 | } |
| 2325 | |
| 2326 | #ifdef CONFIG_GPIOLIB |
| 2327 | static inline struct wm8996_priv *gpio_to_wm8996(struct gpio_chip *chip) |
| 2328 | { |
| 2329 | return container_of(chip, struct wm8996_priv, gpio_chip); |
| 2330 | } |
| 2331 | |
| 2332 | static void wm8996_gpio_set(struct gpio_chip *chip, unsigned offset, int value) |
| 2333 | { |
| 2334 | struct wm8996_priv *wm8996 = gpio_to_wm8996(chip); |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2335 | |
Mark Brown | b2d1e23 | 2011-09-19 23:04:06 +0100 | [diff] [blame] | 2336 | regmap_update_bits(wm8996->regmap, WM8996_GPIO_1 + offset, |
| 2337 | WM8996_GP1_LVL, !!value << WM8996_GP1_LVL_SHIFT); |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2338 | } |
| 2339 | |
| 2340 | static int wm8996_gpio_direction_out(struct gpio_chip *chip, |
| 2341 | unsigned offset, int value) |
| 2342 | { |
| 2343 | struct wm8996_priv *wm8996 = gpio_to_wm8996(chip); |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2344 | int val; |
| 2345 | |
| 2346 | val = (1 << WM8996_GP1_FN_SHIFT) | (!!value << WM8996_GP1_LVL_SHIFT); |
| 2347 | |
Mark Brown | b2d1e23 | 2011-09-19 23:04:06 +0100 | [diff] [blame] | 2348 | return regmap_update_bits(wm8996->regmap, WM8996_GPIO_1 + offset, |
| 2349 | WM8996_GP1_FN_MASK | WM8996_GP1_DIR | |
| 2350 | WM8996_GP1_LVL, val); |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2351 | } |
| 2352 | |
| 2353 | static int wm8996_gpio_get(struct gpio_chip *chip, unsigned offset) |
| 2354 | { |
| 2355 | struct wm8996_priv *wm8996 = gpio_to_wm8996(chip); |
Mark Brown | b2d1e23 | 2011-09-19 23:04:06 +0100 | [diff] [blame] | 2356 | unsigned int reg; |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2357 | int ret; |
| 2358 | |
Mark Brown | b2d1e23 | 2011-09-19 23:04:06 +0100 | [diff] [blame] | 2359 | ret = regmap_read(wm8996->regmap, WM8996_GPIO_1 + offset, ®); |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2360 | if (ret < 0) |
| 2361 | return ret; |
| 2362 | |
Mark Brown | b2d1e23 | 2011-09-19 23:04:06 +0100 | [diff] [blame] | 2363 | return (reg & WM8996_GP1_LVL) != 0; |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2364 | } |
| 2365 | |
| 2366 | static int wm8996_gpio_direction_in(struct gpio_chip *chip, unsigned offset) |
| 2367 | { |
| 2368 | struct wm8996_priv *wm8996 = gpio_to_wm8996(chip); |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2369 | |
Mark Brown | b2d1e23 | 2011-09-19 23:04:06 +0100 | [diff] [blame] | 2370 | return regmap_update_bits(wm8996->regmap, WM8996_GPIO_1 + offset, |
| 2371 | WM8996_GP1_FN_MASK | WM8996_GP1_DIR, |
| 2372 | (1 << WM8996_GP1_FN_SHIFT) | |
| 2373 | (1 << WM8996_GP1_DIR_SHIFT)); |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2374 | } |
| 2375 | |
| 2376 | static struct gpio_chip wm8996_template_chip = { |
| 2377 | .label = "wm8996", |
| 2378 | .owner = THIS_MODULE, |
| 2379 | .direction_output = wm8996_gpio_direction_out, |
| 2380 | .set = wm8996_gpio_set, |
| 2381 | .direction_input = wm8996_gpio_direction_in, |
| 2382 | .get = wm8996_gpio_get, |
| 2383 | .can_sleep = 1, |
| 2384 | }; |
| 2385 | |
Mark Brown | b2d1e23 | 2011-09-19 23:04:06 +0100 | [diff] [blame] | 2386 | static void wm8996_init_gpio(struct wm8996_priv *wm8996) |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2387 | { |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2388 | int ret; |
| 2389 | |
| 2390 | wm8996->gpio_chip = wm8996_template_chip; |
| 2391 | wm8996->gpio_chip.ngpio = 5; |
Mark Brown | b2d1e23 | 2011-09-19 23:04:06 +0100 | [diff] [blame] | 2392 | wm8996->gpio_chip.dev = wm8996->dev; |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2393 | |
| 2394 | if (wm8996->pdata.gpio_base) |
| 2395 | wm8996->gpio_chip.base = wm8996->pdata.gpio_base; |
| 2396 | else |
| 2397 | wm8996->gpio_chip.base = -1; |
| 2398 | |
| 2399 | ret = gpiochip_add(&wm8996->gpio_chip); |
| 2400 | if (ret != 0) |
Mark Brown | b2d1e23 | 2011-09-19 23:04:06 +0100 | [diff] [blame] | 2401 | dev_err(wm8996->dev, "Failed to add GPIOs: %d\n", ret); |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2402 | } |
| 2403 | |
Mark Brown | b2d1e23 | 2011-09-19 23:04:06 +0100 | [diff] [blame] | 2404 | static void wm8996_free_gpio(struct wm8996_priv *wm8996) |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2405 | { |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2406 | int ret; |
| 2407 | |
| 2408 | ret = gpiochip_remove(&wm8996->gpio_chip); |
| 2409 | if (ret != 0) |
Mark Brown | b2d1e23 | 2011-09-19 23:04:06 +0100 | [diff] [blame] | 2410 | dev_err(wm8996->dev, "Failed to remove GPIOs: %d\n", ret); |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2411 | } |
| 2412 | #else |
Mark Brown | b2d1e23 | 2011-09-19 23:04:06 +0100 | [diff] [blame] | 2413 | static void wm8996_init_gpio(struct wm8996_priv *wm8996) |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2414 | { |
| 2415 | } |
| 2416 | |
Mark Brown | b2d1e23 | 2011-09-19 23:04:06 +0100 | [diff] [blame] | 2417 | static void wm8996_free_gpio(struct wm8996_priv *wm8996) |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2418 | { |
| 2419 | } |
| 2420 | #endif |
| 2421 | |
| 2422 | /** |
| 2423 | * wm8996_detect - Enable default WM8996 jack detection |
| 2424 | * |
| 2425 | * The WM8996 has advanced accessory detection support for headsets. |
| 2426 | * This function provides a default implementation which integrates |
| 2427 | * the majority of this functionality with minimal user configuration. |
| 2428 | * |
| 2429 | * This will detect headset, headphone and short circuit button and |
| 2430 | * will also detect inverted microphone ground connections and update |
| 2431 | * the polarity of the connections. |
| 2432 | */ |
| 2433 | int wm8996_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack, |
| 2434 | wm8996_polarity_fn polarity_cb) |
| 2435 | { |
| 2436 | struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec); |
| 2437 | |
| 2438 | wm8996->jack = jack; |
| 2439 | wm8996->detecting = true; |
| 2440 | wm8996->polarity_cb = polarity_cb; |
Mark Brown | d7b3557 | 2012-01-26 18:00:42 +0000 | [diff] [blame] | 2441 | wm8996->jack_flips = 0; |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2442 | |
| 2443 | if (wm8996->polarity_cb) |
| 2444 | wm8996->polarity_cb(codec, 0); |
| 2445 | |
| 2446 | /* Clear discarge to avoid noise during detection */ |
| 2447 | snd_soc_update_bits(codec, WM8996_MICBIAS_1, |
| 2448 | WM8996_MICB1_DISCH, 0); |
| 2449 | snd_soc_update_bits(codec, WM8996_MICBIAS_2, |
| 2450 | WM8996_MICB2_DISCH, 0); |
| 2451 | |
| 2452 | /* LDO2 powers the microphones, SYSCLK clocks detection */ |
| 2453 | snd_soc_dapm_force_enable_pin(&codec->dapm, "LDO2"); |
| 2454 | snd_soc_dapm_force_enable_pin(&codec->dapm, "SYSCLK"); |
| 2455 | |
| 2456 | /* We start off just enabling microphone detection - even a |
| 2457 | * plain headphone will trigger detection. |
| 2458 | */ |
| 2459 | snd_soc_update_bits(codec, WM8996_MIC_DETECT_1, |
| 2460 | WM8996_MICD_ENA, WM8996_MICD_ENA); |
| 2461 | |
| 2462 | /* Slowest detection rate, gives debounce for initial detection */ |
| 2463 | snd_soc_update_bits(codec, WM8996_MIC_DETECT_1, |
| 2464 | WM8996_MICD_RATE_MASK, |
| 2465 | WM8996_MICD_RATE_MASK); |
| 2466 | |
| 2467 | /* Enable interrupts and we're off */ |
| 2468 | snd_soc_update_bits(codec, WM8996_INTERRUPT_STATUS_2_MASK, |
Mark Brown | 0b684cc | 2011-09-04 07:50:31 -0700 | [diff] [blame] | 2469 | WM8996_IM_MICD_EINT | WM8996_HP_DONE_EINT, 0); |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2470 | |
| 2471 | return 0; |
| 2472 | } |
| 2473 | EXPORT_SYMBOL_GPL(wm8996_detect); |
| 2474 | |
Mark Brown | 0b684cc | 2011-09-04 07:50:31 -0700 | [diff] [blame] | 2475 | static void wm8996_hpdet_irq(struct snd_soc_codec *codec) |
| 2476 | { |
| 2477 | struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec); |
| 2478 | int val, reg, report; |
| 2479 | |
| 2480 | /* Assume headphone in error conditions; we need to report |
| 2481 | * something or we stall our state machine. |
| 2482 | */ |
| 2483 | report = SND_JACK_HEADPHONE; |
| 2484 | |
| 2485 | reg = snd_soc_read(codec, WM8996_HEADPHONE_DETECT_2); |
| 2486 | if (reg < 0) { |
| 2487 | dev_err(codec->dev, "Failed to read HPDET status\n"); |
| 2488 | goto out; |
| 2489 | } |
| 2490 | |
| 2491 | if (!(reg & WM8996_HP_DONE)) { |
| 2492 | dev_err(codec->dev, "Got HPDET IRQ but HPDET is busy\n"); |
| 2493 | goto out; |
| 2494 | } |
| 2495 | |
| 2496 | val = reg & WM8996_HP_LVL_MASK; |
| 2497 | |
| 2498 | dev_dbg(codec->dev, "HPDET measured %d ohms\n", val); |
| 2499 | |
| 2500 | /* If we've got high enough impedence then report as line, |
| 2501 | * otherwise assume headphone. |
| 2502 | */ |
| 2503 | if (val >= 126) |
| 2504 | report = SND_JACK_LINEOUT; |
| 2505 | else |
| 2506 | report = SND_JACK_HEADPHONE; |
| 2507 | |
| 2508 | out: |
| 2509 | if (wm8996->jack_mic) |
| 2510 | report |= SND_JACK_MICROPHONE; |
| 2511 | |
| 2512 | snd_soc_jack_report(wm8996->jack, report, |
| 2513 | SND_JACK_LINEOUT | SND_JACK_HEADSET); |
| 2514 | |
| 2515 | wm8996->detecting = false; |
| 2516 | |
| 2517 | /* If the output isn't running re-clamp it */ |
| 2518 | if (!(snd_soc_read(codec, WM8996_POWER_MANAGEMENT_1) & |
| 2519 | (WM8996_HPOUT1L_ENA | WM8996_HPOUT1R_RMV_SHORT))) |
| 2520 | snd_soc_update_bits(codec, WM8996_ANALOGUE_HP_1, |
| 2521 | WM8996_HPOUT1L_RMV_SHORT | |
| 2522 | WM8996_HPOUT1R_RMV_SHORT, 0); |
| 2523 | |
| 2524 | /* Go back to looking at the microphone */ |
| 2525 | snd_soc_update_bits(codec, WM8996_ACCESSORY_DETECT_MODE_1, |
| 2526 | WM8996_JD_MODE_MASK, 0); |
| 2527 | snd_soc_update_bits(codec, WM8996_MIC_DETECT_1, WM8996_MICD_ENA, |
| 2528 | WM8996_MICD_ENA); |
| 2529 | |
| 2530 | snd_soc_dapm_disable_pin(&codec->dapm, "Bandgap"); |
| 2531 | snd_soc_dapm_sync(&codec->dapm); |
| 2532 | } |
| 2533 | |
| 2534 | static void wm8996_hpdet_start(struct snd_soc_codec *codec) |
| 2535 | { |
| 2536 | /* Unclamp the output, we can't measure while we're shorting it */ |
| 2537 | snd_soc_update_bits(codec, WM8996_ANALOGUE_HP_1, |
| 2538 | WM8996_HPOUT1L_RMV_SHORT | |
| 2539 | WM8996_HPOUT1R_RMV_SHORT, |
| 2540 | WM8996_HPOUT1L_RMV_SHORT | |
| 2541 | WM8996_HPOUT1R_RMV_SHORT); |
| 2542 | |
| 2543 | /* We need bandgap for HPDET */ |
| 2544 | snd_soc_dapm_force_enable_pin(&codec->dapm, "Bandgap"); |
| 2545 | snd_soc_dapm_sync(&codec->dapm); |
| 2546 | |
| 2547 | /* Go into headphone detect left mode */ |
| 2548 | snd_soc_update_bits(codec, WM8996_MIC_DETECT_1, WM8996_MICD_ENA, 0); |
| 2549 | snd_soc_update_bits(codec, WM8996_ACCESSORY_DETECT_MODE_1, |
| 2550 | WM8996_JD_MODE_MASK, 1); |
| 2551 | |
| 2552 | /* Trigger a measurement */ |
| 2553 | snd_soc_update_bits(codec, WM8996_HEADPHONE_DETECT_1, |
| 2554 | WM8996_HP_POLL, WM8996_HP_POLL); |
| 2555 | } |
| 2556 | |
Mark Brown | d7b3557 | 2012-01-26 18:00:42 +0000 | [diff] [blame] | 2557 | static void wm8996_report_headphone(struct snd_soc_codec *codec) |
| 2558 | { |
| 2559 | dev_dbg(codec->dev, "Headphone detected\n"); |
| 2560 | wm8996_hpdet_start(codec); |
| 2561 | |
| 2562 | /* Increase the detection rate a bit for responsiveness. */ |
| 2563 | snd_soc_update_bits(codec, WM8996_MIC_DETECT_1, |
| 2564 | WM8996_MICD_RATE_MASK | |
| 2565 | WM8996_MICD_BIAS_STARTTIME_MASK, |
| 2566 | 7 << WM8996_MICD_RATE_SHIFT | |
| 2567 | 7 << WM8996_MICD_BIAS_STARTTIME_SHIFT); |
| 2568 | } |
| 2569 | |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2570 | static void wm8996_micd(struct snd_soc_codec *codec) |
| 2571 | { |
| 2572 | struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec); |
| 2573 | int val, reg; |
| 2574 | |
| 2575 | val = snd_soc_read(codec, WM8996_MIC_DETECT_3); |
| 2576 | |
| 2577 | dev_dbg(codec->dev, "Microphone event: %x\n", val); |
| 2578 | |
| 2579 | if (!(val & WM8996_MICD_VALID)) { |
| 2580 | dev_warn(codec->dev, "Microphone detection state invalid\n"); |
| 2581 | return; |
| 2582 | } |
| 2583 | |
| 2584 | /* No accessory, reset everything and report removal */ |
| 2585 | if (!(val & WM8996_MICD_STS)) { |
| 2586 | dev_dbg(codec->dev, "Jack removal detected\n"); |
| 2587 | wm8996->jack_mic = false; |
| 2588 | wm8996->detecting = true; |
Mark Brown | d7b3557 | 2012-01-26 18:00:42 +0000 | [diff] [blame] | 2589 | wm8996->jack_flips = 0; |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2590 | snd_soc_jack_report(wm8996->jack, 0, |
Mark Brown | 0b684cc | 2011-09-04 07:50:31 -0700 | [diff] [blame] | 2591 | SND_JACK_LINEOUT | SND_JACK_HEADSET | |
| 2592 | SND_JACK_BTN_0); |
| 2593 | |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2594 | snd_soc_update_bits(codec, WM8996_MIC_DETECT_1, |
Mark Brown | 45ba82d | 2011-12-14 19:23:37 +0800 | [diff] [blame] | 2595 | WM8996_MICD_RATE_MASK | |
| 2596 | WM8996_MICD_BIAS_STARTTIME_MASK, |
| 2597 | WM8996_MICD_RATE_MASK | |
| 2598 | 9 << WM8996_MICD_BIAS_STARTTIME_SHIFT); |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2599 | return; |
| 2600 | } |
| 2601 | |
Mark Brown | 0b684cc | 2011-09-04 07:50:31 -0700 | [diff] [blame] | 2602 | /* If the measurement is very high we've got a microphone, |
| 2603 | * either we just detected one or if we already reported then |
| 2604 | * we've got a button release event. |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2605 | */ |
| 2606 | if (val & 0x400) { |
Mark Brown | 0b684cc | 2011-09-04 07:50:31 -0700 | [diff] [blame] | 2607 | if (wm8996->detecting) { |
| 2608 | dev_dbg(codec->dev, "Microphone detected\n"); |
| 2609 | wm8996->jack_mic = true; |
| 2610 | wm8996_hpdet_start(codec); |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2611 | |
Mark Brown | 0b684cc | 2011-09-04 07:50:31 -0700 | [diff] [blame] | 2612 | /* Increase poll rate to give better responsiveness |
| 2613 | * for buttons */ |
| 2614 | snd_soc_update_bits(codec, WM8996_MIC_DETECT_1, |
Mark Brown | 45ba82d | 2011-12-14 19:23:37 +0800 | [diff] [blame] | 2615 | WM8996_MICD_RATE_MASK | |
| 2616 | WM8996_MICD_BIAS_STARTTIME_MASK, |
| 2617 | 5 << WM8996_MICD_RATE_SHIFT | |
| 2618 | 7 << WM8996_MICD_BIAS_STARTTIME_SHIFT); |
Mark Brown | 0b684cc | 2011-09-04 07:50:31 -0700 | [diff] [blame] | 2619 | } else { |
| 2620 | dev_dbg(codec->dev, "Mic button up\n"); |
| 2621 | snd_soc_jack_report(wm8996->jack, 0, SND_JACK_BTN_0); |
| 2622 | } |
| 2623 | |
| 2624 | return; |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2625 | } |
| 2626 | |
| 2627 | /* If we detected a lower impedence during initial startup |
| 2628 | * then we probably have the wrong polarity, flip it. Don't |
| 2629 | * do this for the lowest impedences to speed up detection of |
Mark Brown | d7b3557 | 2012-01-26 18:00:42 +0000 | [diff] [blame] | 2630 | * plain headphones. If both polarities report a low |
| 2631 | * impedence then give up and report headphones. |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2632 | */ |
| 2633 | if (wm8996->detecting && (val & 0x3f0)) { |
Mark Brown | d7b3557 | 2012-01-26 18:00:42 +0000 | [diff] [blame] | 2634 | wm8996->jack_flips++; |
| 2635 | |
| 2636 | if (wm8996->jack_flips > 1) { |
| 2637 | wm8996_report_headphone(codec); |
| 2638 | return; |
| 2639 | } |
| 2640 | |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2641 | reg = snd_soc_read(codec, WM8996_ACCESSORY_DETECT_MODE_2); |
| 2642 | reg ^= WM8996_HPOUT1FB_SRC | WM8996_MICD_SRC | |
| 2643 | WM8996_MICD_BIAS_SRC; |
| 2644 | snd_soc_update_bits(codec, WM8996_ACCESSORY_DETECT_MODE_2, |
| 2645 | WM8996_HPOUT1FB_SRC | WM8996_MICD_SRC | |
| 2646 | WM8996_MICD_BIAS_SRC, reg); |
| 2647 | |
| 2648 | if (wm8996->polarity_cb) |
| 2649 | wm8996->polarity_cb(codec, |
| 2650 | (reg & WM8996_MICD_SRC) != 0); |
| 2651 | |
| 2652 | dev_dbg(codec->dev, "Set microphone polarity to %d\n", |
| 2653 | (reg & WM8996_MICD_SRC) != 0); |
| 2654 | |
| 2655 | return; |
| 2656 | } |
| 2657 | |
| 2658 | /* Don't distinguish between buttons, just report any low |
| 2659 | * impedence as BTN_0. |
| 2660 | */ |
| 2661 | if (val & 0x3fc) { |
| 2662 | if (wm8996->jack_mic) { |
| 2663 | dev_dbg(codec->dev, "Mic button detected\n"); |
Mark Brown | 0b684cc | 2011-09-04 07:50:31 -0700 | [diff] [blame] | 2664 | snd_soc_jack_report(wm8996->jack, SND_JACK_BTN_0, |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2665 | SND_JACK_BTN_0); |
Mark Brown | 0b684cc | 2011-09-04 07:50:31 -0700 | [diff] [blame] | 2666 | } else if (wm8996->detecting) { |
Mark Brown | d7b3557 | 2012-01-26 18:00:42 +0000 | [diff] [blame] | 2667 | wm8996_report_headphone(codec); |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2668 | } |
| 2669 | } |
| 2670 | } |
| 2671 | |
| 2672 | static irqreturn_t wm8996_irq(int irq, void *data) |
| 2673 | { |
| 2674 | struct snd_soc_codec *codec = data; |
| 2675 | struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec); |
| 2676 | int irq_val; |
| 2677 | |
| 2678 | irq_val = snd_soc_read(codec, WM8996_INTERRUPT_STATUS_2); |
| 2679 | if (irq_val < 0) { |
| 2680 | dev_err(codec->dev, "Failed to read IRQ status: %d\n", |
| 2681 | irq_val); |
| 2682 | return IRQ_NONE; |
| 2683 | } |
| 2684 | irq_val &= ~snd_soc_read(codec, WM8996_INTERRUPT_STATUS_2_MASK); |
| 2685 | |
Mark Brown | 2fde6e8 | 2011-08-20 19:28:59 +0100 | [diff] [blame] | 2686 | if (!irq_val) |
| 2687 | return IRQ_NONE; |
| 2688 | |
Mark Brown | 8449709 | 2011-07-20 13:49:58 +0100 | [diff] [blame] | 2689 | snd_soc_write(codec, WM8996_INTERRUPT_STATUS_2, irq_val); |
| 2690 | |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2691 | if (irq_val & (WM8996_DCS_DONE_01_EINT | WM8996_DCS_DONE_23_EINT)) { |
| 2692 | dev_dbg(codec->dev, "DC servo IRQ\n"); |
| 2693 | complete(&wm8996->dcs_done); |
| 2694 | } |
| 2695 | |
| 2696 | if (irq_val & WM8996_FIFOS_ERR_EINT) |
| 2697 | dev_err(codec->dev, "Digital core FIFO error\n"); |
| 2698 | |
| 2699 | if (irq_val & WM8996_FLL_LOCK_EINT) { |
| 2700 | dev_dbg(codec->dev, "FLL locked\n"); |
| 2701 | complete(&wm8996->fll_lock); |
| 2702 | } |
| 2703 | |
| 2704 | if (irq_val & WM8996_MICD_EINT) |
| 2705 | wm8996_micd(codec); |
| 2706 | |
Mark Brown | 0b684cc | 2011-09-04 07:50:31 -0700 | [diff] [blame] | 2707 | if (irq_val & WM8996_HP_DONE_EINT) |
| 2708 | wm8996_hpdet_irq(codec); |
| 2709 | |
Mark Brown | 2fde6e8 | 2011-08-20 19:28:59 +0100 | [diff] [blame] | 2710 | return IRQ_HANDLED; |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2711 | } |
| 2712 | |
| 2713 | static irqreturn_t wm8996_edge_irq(int irq, void *data) |
| 2714 | { |
| 2715 | irqreturn_t ret = IRQ_NONE; |
| 2716 | irqreturn_t val; |
| 2717 | |
| 2718 | do { |
| 2719 | val = wm8996_irq(irq, data); |
| 2720 | if (val != IRQ_NONE) |
| 2721 | ret = val; |
| 2722 | } while (val != IRQ_NONE); |
| 2723 | |
| 2724 | return ret; |
| 2725 | } |
| 2726 | |
| 2727 | static void wm8996_retune_mobile_pdata(struct snd_soc_codec *codec) |
| 2728 | { |
| 2729 | struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec); |
| 2730 | struct wm8996_pdata *pdata = &wm8996->pdata; |
| 2731 | |
| 2732 | struct snd_kcontrol_new controls[] = { |
| 2733 | SOC_ENUM_EXT("DSP1 EQ Mode", |
| 2734 | wm8996->retune_mobile_enum, |
| 2735 | wm8996_get_retune_mobile_enum, |
| 2736 | wm8996_put_retune_mobile_enum), |
| 2737 | SOC_ENUM_EXT("DSP2 EQ Mode", |
| 2738 | wm8996->retune_mobile_enum, |
| 2739 | wm8996_get_retune_mobile_enum, |
| 2740 | wm8996_put_retune_mobile_enum), |
| 2741 | }; |
| 2742 | int ret, i, j; |
| 2743 | const char **t; |
| 2744 | |
| 2745 | /* We need an array of texts for the enum API but the number |
| 2746 | * of texts is likely to be less than the number of |
| 2747 | * configurations due to the sample rate dependency of the |
| 2748 | * configurations. */ |
| 2749 | wm8996->num_retune_mobile_texts = 0; |
| 2750 | wm8996->retune_mobile_texts = NULL; |
| 2751 | for (i = 0; i < pdata->num_retune_mobile_cfgs; i++) { |
| 2752 | for (j = 0; j < wm8996->num_retune_mobile_texts; j++) { |
| 2753 | if (strcmp(pdata->retune_mobile_cfgs[i].name, |
| 2754 | wm8996->retune_mobile_texts[j]) == 0) |
| 2755 | break; |
| 2756 | } |
| 2757 | |
| 2758 | if (j != wm8996->num_retune_mobile_texts) |
| 2759 | continue; |
| 2760 | |
| 2761 | /* Expand the array... */ |
| 2762 | t = krealloc(wm8996->retune_mobile_texts, |
| 2763 | sizeof(char *) * |
| 2764 | (wm8996->num_retune_mobile_texts + 1), |
| 2765 | GFP_KERNEL); |
| 2766 | if (t == NULL) |
| 2767 | continue; |
| 2768 | |
| 2769 | /* ...store the new entry... */ |
| 2770 | t[wm8996->num_retune_mobile_texts] = |
| 2771 | pdata->retune_mobile_cfgs[i].name; |
| 2772 | |
| 2773 | /* ...and remember the new version. */ |
| 2774 | wm8996->num_retune_mobile_texts++; |
| 2775 | wm8996->retune_mobile_texts = t; |
| 2776 | } |
| 2777 | |
| 2778 | dev_dbg(codec->dev, "Allocated %d unique ReTune Mobile names\n", |
| 2779 | wm8996->num_retune_mobile_texts); |
| 2780 | |
| 2781 | wm8996->retune_mobile_enum.max = wm8996->num_retune_mobile_texts; |
| 2782 | wm8996->retune_mobile_enum.texts = wm8996->retune_mobile_texts; |
| 2783 | |
| 2784 | ret = snd_soc_add_controls(codec, controls, ARRAY_SIZE(controls)); |
| 2785 | if (ret != 0) |
| 2786 | dev_err(codec->dev, |
| 2787 | "Failed to add ReTune Mobile controls: %d\n", ret); |
| 2788 | } |
| 2789 | |
Mark Brown | 7917274 | 2011-09-19 16:15:58 +0100 | [diff] [blame] | 2790 | static const struct regmap_config wm8996_regmap = { |
| 2791 | .reg_bits = 16, |
| 2792 | .val_bits = 16, |
| 2793 | |
| 2794 | .max_register = WM8996_MAX_REGISTER, |
| 2795 | .reg_defaults = wm8996_reg, |
| 2796 | .num_reg_defaults = ARRAY_SIZE(wm8996_reg), |
| 2797 | .volatile_reg = wm8996_volatile_register, |
| 2798 | .readable_reg = wm8996_readable_register, |
| 2799 | .cache_type = REGCACHE_RBTREE, |
| 2800 | }; |
| 2801 | |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2802 | static int wm8996_probe(struct snd_soc_codec *codec) |
| 2803 | { |
| 2804 | int ret; |
| 2805 | struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec); |
| 2806 | struct i2c_client *i2c = to_i2c_client(codec->dev); |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2807 | int i, irq_flags; |
| 2808 | |
| 2809 | wm8996->codec = codec; |
| 2810 | |
| 2811 | init_completion(&wm8996->dcs_done); |
| 2812 | init_completion(&wm8996->fll_lock); |
| 2813 | |
Mark Brown | ee5f387 | 2011-09-19 19:51:07 +0100 | [diff] [blame] | 2814 | codec->control_data = wm8996->regmap; |
Mark Brown | 7917274 | 2011-09-19 16:15:58 +0100 | [diff] [blame] | 2815 | |
| 2816 | ret = snd_soc_codec_set_cache_io(codec, 16, 16, SND_SOC_REGMAP); |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2817 | if (ret != 0) { |
| 2818 | dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); |
Mark Brown | ee5f387 | 2011-09-19 19:51:07 +0100 | [diff] [blame] | 2819 | goto err; |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2820 | } |
| 2821 | |
| 2822 | wm8996->disable_nb[0].notifier_call = wm8996_regulator_event_0; |
| 2823 | wm8996->disable_nb[1].notifier_call = wm8996_regulator_event_1; |
| 2824 | wm8996->disable_nb[2].notifier_call = wm8996_regulator_event_2; |
Mark Brown | c83495a | 2011-09-11 10:05:18 +0100 | [diff] [blame] | 2825 | |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2826 | /* This should really be moved into the regulator core */ |
| 2827 | for (i = 0; i < ARRAY_SIZE(wm8996->supplies); i++) { |
| 2828 | ret = regulator_register_notifier(wm8996->supplies[i].consumer, |
| 2829 | &wm8996->disable_nb[i]); |
| 2830 | if (ret != 0) { |
| 2831 | dev_err(codec->dev, |
| 2832 | "Failed to register regulator notifier: %d\n", |
| 2833 | ret); |
| 2834 | } |
| 2835 | } |
| 2836 | |
Mark Brown | 7917274 | 2011-09-19 16:15:58 +0100 | [diff] [blame] | 2837 | regcache_cache_only(codec->control_data, true); |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2838 | |
| 2839 | /* Apply platform data settings */ |
| 2840 | snd_soc_update_bits(codec, WM8996_LINE_INPUT_CONTROL, |
| 2841 | WM8996_INL_MODE_MASK | WM8996_INR_MODE_MASK, |
| 2842 | wm8996->pdata.inl_mode << WM8996_INL_MODE_SHIFT | |
| 2843 | wm8996->pdata.inr_mode); |
| 2844 | |
| 2845 | for (i = 0; i < ARRAY_SIZE(wm8996->pdata.gpio_default); i++) { |
| 2846 | if (!wm8996->pdata.gpio_default[i]) |
| 2847 | continue; |
| 2848 | |
| 2849 | snd_soc_write(codec, WM8996_GPIO_1 + i, |
| 2850 | wm8996->pdata.gpio_default[i] & 0xffff); |
| 2851 | } |
| 2852 | |
| 2853 | if (wm8996->pdata.spkmute_seq) |
| 2854 | snd_soc_update_bits(codec, WM8996_PDM_SPEAKER_MUTE_SEQUENCE, |
| 2855 | WM8996_SPK_MUTE_ENDIAN | |
| 2856 | WM8996_SPK_MUTE_SEQ1_MASK, |
| 2857 | wm8996->pdata.spkmute_seq); |
| 2858 | |
| 2859 | snd_soc_update_bits(codec, WM8996_ACCESSORY_DETECT_MODE_2, |
| 2860 | WM8996_MICD_BIAS_SRC | WM8996_HPOUT1FB_SRC | |
| 2861 | WM8996_MICD_SRC, wm8996->pdata.micdet_def); |
| 2862 | |
| 2863 | /* Latch volume update bits */ |
| 2864 | snd_soc_update_bits(codec, WM8996_LEFT_LINE_INPUT_VOLUME, |
| 2865 | WM8996_IN1_VU, WM8996_IN1_VU); |
| 2866 | snd_soc_update_bits(codec, WM8996_RIGHT_LINE_INPUT_VOLUME, |
| 2867 | WM8996_IN1_VU, WM8996_IN1_VU); |
| 2868 | |
| 2869 | snd_soc_update_bits(codec, WM8996_DAC1_LEFT_VOLUME, |
| 2870 | WM8996_DAC1_VU, WM8996_DAC1_VU); |
| 2871 | snd_soc_update_bits(codec, WM8996_DAC1_RIGHT_VOLUME, |
| 2872 | WM8996_DAC1_VU, WM8996_DAC1_VU); |
| 2873 | snd_soc_update_bits(codec, WM8996_DAC2_LEFT_VOLUME, |
| 2874 | WM8996_DAC2_VU, WM8996_DAC2_VU); |
| 2875 | snd_soc_update_bits(codec, WM8996_DAC2_RIGHT_VOLUME, |
| 2876 | WM8996_DAC2_VU, WM8996_DAC2_VU); |
| 2877 | |
| 2878 | snd_soc_update_bits(codec, WM8996_OUTPUT1_LEFT_VOLUME, |
| 2879 | WM8996_DAC1_VU, WM8996_DAC1_VU); |
| 2880 | snd_soc_update_bits(codec, WM8996_OUTPUT1_RIGHT_VOLUME, |
| 2881 | WM8996_DAC1_VU, WM8996_DAC1_VU); |
| 2882 | snd_soc_update_bits(codec, WM8996_OUTPUT2_LEFT_VOLUME, |
| 2883 | WM8996_DAC2_VU, WM8996_DAC2_VU); |
| 2884 | snd_soc_update_bits(codec, WM8996_OUTPUT2_RIGHT_VOLUME, |
| 2885 | WM8996_DAC2_VU, WM8996_DAC2_VU); |
| 2886 | |
| 2887 | snd_soc_update_bits(codec, WM8996_DSP1_TX_LEFT_VOLUME, |
| 2888 | WM8996_DSP1TX_VU, WM8996_DSP1TX_VU); |
| 2889 | snd_soc_update_bits(codec, WM8996_DSP1_TX_RIGHT_VOLUME, |
| 2890 | WM8996_DSP1TX_VU, WM8996_DSP1TX_VU); |
| 2891 | snd_soc_update_bits(codec, WM8996_DSP2_TX_LEFT_VOLUME, |
| 2892 | WM8996_DSP2TX_VU, WM8996_DSP2TX_VU); |
| 2893 | snd_soc_update_bits(codec, WM8996_DSP2_TX_RIGHT_VOLUME, |
| 2894 | WM8996_DSP2TX_VU, WM8996_DSP2TX_VU); |
| 2895 | |
| 2896 | snd_soc_update_bits(codec, WM8996_DSP1_RX_LEFT_VOLUME, |
| 2897 | WM8996_DSP1RX_VU, WM8996_DSP1RX_VU); |
| 2898 | snd_soc_update_bits(codec, WM8996_DSP1_RX_RIGHT_VOLUME, |
| 2899 | WM8996_DSP1RX_VU, WM8996_DSP1RX_VU); |
| 2900 | snd_soc_update_bits(codec, WM8996_DSP2_RX_LEFT_VOLUME, |
| 2901 | WM8996_DSP2RX_VU, WM8996_DSP2RX_VU); |
| 2902 | snd_soc_update_bits(codec, WM8996_DSP2_RX_RIGHT_VOLUME, |
| 2903 | WM8996_DSP2RX_VU, WM8996_DSP2RX_VU); |
| 2904 | |
| 2905 | /* No support currently for the underclocked TDM modes and |
| 2906 | * pick a default TDM layout with each channel pair working with |
| 2907 | * slots 0 and 1. */ |
| 2908 | snd_soc_update_bits(codec, WM8996_AIF1RX_CHANNEL_0_CONFIGURATION, |
| 2909 | WM8996_AIF1RX_CHAN0_SLOTS_MASK | |
| 2910 | WM8996_AIF1RX_CHAN0_START_SLOT_MASK, |
| 2911 | 1 << WM8996_AIF1RX_CHAN0_SLOTS_SHIFT | 0); |
| 2912 | snd_soc_update_bits(codec, WM8996_AIF1RX_CHANNEL_1_CONFIGURATION, |
| 2913 | WM8996_AIF1RX_CHAN1_SLOTS_MASK | |
| 2914 | WM8996_AIF1RX_CHAN1_START_SLOT_MASK, |
| 2915 | 1 << WM8996_AIF1RX_CHAN1_SLOTS_SHIFT | 1); |
| 2916 | snd_soc_update_bits(codec, WM8996_AIF1RX_CHANNEL_2_CONFIGURATION, |
| 2917 | WM8996_AIF1RX_CHAN2_SLOTS_MASK | |
| 2918 | WM8996_AIF1RX_CHAN2_START_SLOT_MASK, |
| 2919 | 1 << WM8996_AIF1RX_CHAN2_SLOTS_SHIFT | 0); |
| 2920 | snd_soc_update_bits(codec, WM8996_AIF1RX_CHANNEL_3_CONFIGURATION, |
| 2921 | WM8996_AIF1RX_CHAN3_SLOTS_MASK | |
| 2922 | WM8996_AIF1RX_CHAN0_START_SLOT_MASK, |
| 2923 | 1 << WM8996_AIF1RX_CHAN3_SLOTS_SHIFT | 1); |
| 2924 | snd_soc_update_bits(codec, WM8996_AIF1RX_CHANNEL_4_CONFIGURATION, |
| 2925 | WM8996_AIF1RX_CHAN4_SLOTS_MASK | |
| 2926 | WM8996_AIF1RX_CHAN0_START_SLOT_MASK, |
| 2927 | 1 << WM8996_AIF1RX_CHAN4_SLOTS_SHIFT | 0); |
| 2928 | snd_soc_update_bits(codec, WM8996_AIF1RX_CHANNEL_5_CONFIGURATION, |
| 2929 | WM8996_AIF1RX_CHAN5_SLOTS_MASK | |
| 2930 | WM8996_AIF1RX_CHAN0_START_SLOT_MASK, |
| 2931 | 1 << WM8996_AIF1RX_CHAN5_SLOTS_SHIFT | 1); |
| 2932 | |
| 2933 | snd_soc_update_bits(codec, WM8996_AIF2RX_CHANNEL_0_CONFIGURATION, |
| 2934 | WM8996_AIF2RX_CHAN0_SLOTS_MASK | |
| 2935 | WM8996_AIF2RX_CHAN0_START_SLOT_MASK, |
| 2936 | 1 << WM8996_AIF2RX_CHAN0_SLOTS_SHIFT | 0); |
| 2937 | snd_soc_update_bits(codec, WM8996_AIF2RX_CHANNEL_1_CONFIGURATION, |
| 2938 | WM8996_AIF2RX_CHAN1_SLOTS_MASK | |
| 2939 | WM8996_AIF2RX_CHAN1_START_SLOT_MASK, |
| 2940 | 1 << WM8996_AIF2RX_CHAN1_SLOTS_SHIFT | 1); |
| 2941 | |
| 2942 | snd_soc_update_bits(codec, WM8996_AIF1TX_CHANNEL_0_CONFIGURATION, |
| 2943 | WM8996_AIF1TX_CHAN0_SLOTS_MASK | |
| 2944 | WM8996_AIF1TX_CHAN0_START_SLOT_MASK, |
| 2945 | 1 << WM8996_AIF1TX_CHAN0_SLOTS_SHIFT | 0); |
| 2946 | snd_soc_update_bits(codec, WM8996_AIF1TX_CHANNEL_1_CONFIGURATION, |
| 2947 | WM8996_AIF1TX_CHAN1_SLOTS_MASK | |
| 2948 | WM8996_AIF1TX_CHAN0_START_SLOT_MASK, |
| 2949 | 1 << WM8996_AIF1TX_CHAN1_SLOTS_SHIFT | 1); |
| 2950 | snd_soc_update_bits(codec, WM8996_AIF1TX_CHANNEL_2_CONFIGURATION, |
| 2951 | WM8996_AIF1TX_CHAN2_SLOTS_MASK | |
| 2952 | WM8996_AIF1TX_CHAN0_START_SLOT_MASK, |
| 2953 | 1 << WM8996_AIF1TX_CHAN2_SLOTS_SHIFT | 0); |
| 2954 | snd_soc_update_bits(codec, WM8996_AIF1TX_CHANNEL_3_CONFIGURATION, |
| 2955 | WM8996_AIF1TX_CHAN3_SLOTS_MASK | |
| 2956 | WM8996_AIF1TX_CHAN0_START_SLOT_MASK, |
| 2957 | 1 << WM8996_AIF1TX_CHAN3_SLOTS_SHIFT | 1); |
| 2958 | snd_soc_update_bits(codec, WM8996_AIF1TX_CHANNEL_4_CONFIGURATION, |
| 2959 | WM8996_AIF1TX_CHAN4_SLOTS_MASK | |
| 2960 | WM8996_AIF1TX_CHAN0_START_SLOT_MASK, |
| 2961 | 1 << WM8996_AIF1TX_CHAN4_SLOTS_SHIFT | 0); |
| 2962 | snd_soc_update_bits(codec, WM8996_AIF1TX_CHANNEL_5_CONFIGURATION, |
| 2963 | WM8996_AIF1TX_CHAN5_SLOTS_MASK | |
| 2964 | WM8996_AIF1TX_CHAN0_START_SLOT_MASK, |
| 2965 | 1 << WM8996_AIF1TX_CHAN5_SLOTS_SHIFT | 1); |
| 2966 | |
| 2967 | snd_soc_update_bits(codec, WM8996_AIF2TX_CHANNEL_0_CONFIGURATION, |
| 2968 | WM8996_AIF2TX_CHAN0_SLOTS_MASK | |
| 2969 | WM8996_AIF2TX_CHAN0_START_SLOT_MASK, |
| 2970 | 1 << WM8996_AIF2TX_CHAN0_SLOTS_SHIFT | 0); |
| 2971 | snd_soc_update_bits(codec, WM8996_AIF1TX_CHANNEL_1_CONFIGURATION, |
| 2972 | WM8996_AIF2TX_CHAN1_SLOTS_MASK | |
| 2973 | WM8996_AIF2TX_CHAN1_START_SLOT_MASK, |
| 2974 | 1 << WM8996_AIF1TX_CHAN1_SLOTS_SHIFT | 1); |
| 2975 | |
| 2976 | if (wm8996->pdata.num_retune_mobile_cfgs) |
| 2977 | wm8996_retune_mobile_pdata(codec); |
| 2978 | else |
| 2979 | snd_soc_add_controls(codec, wm8996_eq_controls, |
| 2980 | ARRAY_SIZE(wm8996_eq_controls)); |
| 2981 | |
| 2982 | /* If the TX LRCLK pins are not in LRCLK mode configure the |
| 2983 | * AIFs to source their clocks from the RX LRCLKs. |
| 2984 | */ |
| 2985 | if ((snd_soc_read(codec, WM8996_GPIO_1))) |
| 2986 | snd_soc_update_bits(codec, WM8996_AIF1_TX_LRCLK_2, |
| 2987 | WM8996_AIF1TX_LRCLK_MODE, |
| 2988 | WM8996_AIF1TX_LRCLK_MODE); |
| 2989 | |
| 2990 | if ((snd_soc_read(codec, WM8996_GPIO_2))) |
| 2991 | snd_soc_update_bits(codec, WM8996_AIF2_TX_LRCLK_2, |
| 2992 | WM8996_AIF2TX_LRCLK_MODE, |
| 2993 | WM8996_AIF2TX_LRCLK_MODE); |
| 2994 | |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 2995 | if (i2c->irq) { |
| 2996 | if (wm8996->pdata.irq_flags) |
| 2997 | irq_flags = wm8996->pdata.irq_flags; |
| 2998 | else |
| 2999 | irq_flags = IRQF_TRIGGER_LOW; |
| 3000 | |
| 3001 | irq_flags |= IRQF_ONESHOT; |
| 3002 | |
| 3003 | if (irq_flags & (IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING)) |
| 3004 | ret = request_threaded_irq(i2c->irq, NULL, |
| 3005 | wm8996_edge_irq, |
| 3006 | irq_flags, "wm8996", codec); |
| 3007 | else |
| 3008 | ret = request_threaded_irq(i2c->irq, NULL, wm8996_irq, |
| 3009 | irq_flags, "wm8996", codec); |
| 3010 | |
| 3011 | if (ret == 0) { |
| 3012 | /* Unmask the interrupt */ |
| 3013 | snd_soc_update_bits(codec, WM8996_INTERRUPT_CONTROL, |
| 3014 | WM8996_IM_IRQ, 0); |
| 3015 | |
| 3016 | /* Enable error reporting and DC servo status */ |
| 3017 | snd_soc_update_bits(codec, |
| 3018 | WM8996_INTERRUPT_STATUS_2_MASK, |
| 3019 | WM8996_IM_DCS_DONE_23_EINT | |
| 3020 | WM8996_IM_DCS_DONE_01_EINT | |
| 3021 | WM8996_IM_FLL_LOCK_EINT | |
| 3022 | WM8996_IM_FIFOS_ERR_EINT, |
| 3023 | 0); |
| 3024 | } else { |
| 3025 | dev_err(codec->dev, "Failed to request IRQ: %d\n", |
| 3026 | ret); |
| 3027 | } |
| 3028 | } |
| 3029 | |
| 3030 | return 0; |
| 3031 | |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 3032 | err: |
| 3033 | return ret; |
| 3034 | } |
| 3035 | |
| 3036 | static int wm8996_remove(struct snd_soc_codec *codec) |
| 3037 | { |
| 3038 | struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec); |
| 3039 | struct i2c_client *i2c = to_i2c_client(codec->dev); |
| 3040 | int i; |
| 3041 | |
| 3042 | snd_soc_update_bits(codec, WM8996_INTERRUPT_CONTROL, |
| 3043 | WM8996_IM_IRQ, WM8996_IM_IRQ); |
| 3044 | |
| 3045 | if (i2c->irq) |
| 3046 | free_irq(i2c->irq, codec); |
| 3047 | |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 3048 | for (i = 0; i < ARRAY_SIZE(wm8996->supplies); i++) |
| 3049 | regulator_unregister_notifier(wm8996->supplies[i].consumer, |
| 3050 | &wm8996->disable_nb[i]); |
Mark Brown | c83495a | 2011-09-11 10:05:18 +0100 | [diff] [blame] | 3051 | regulator_put(wm8996->cpvdd); |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 3052 | regulator_bulk_free(ARRAY_SIZE(wm8996->supplies), wm8996->supplies); |
| 3053 | |
| 3054 | return 0; |
| 3055 | } |
| 3056 | |
Mark Brown | 1b39bf34 | 2011-12-29 12:18:53 +0000 | [diff] [blame] | 3057 | static int wm8996_soc_volatile_register(struct snd_soc_codec *codec, |
| 3058 | unsigned int reg) |
| 3059 | { |
| 3060 | return true; |
| 3061 | } |
| 3062 | |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 3063 | static struct snd_soc_codec_driver soc_codec_dev_wm8996 = { |
| 3064 | .probe = wm8996_probe, |
| 3065 | .remove = wm8996_remove, |
| 3066 | .set_bias_level = wm8996_set_bias_level, |
Axel Lin | eb3032f | 2012-01-27 18:02:09 +0800 | [diff] [blame^] | 3067 | .idle_bias_off = true, |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 3068 | .seq_notifier = wm8996_seq_notifier, |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 3069 | .controls = wm8996_snd_controls, |
| 3070 | .num_controls = ARRAY_SIZE(wm8996_snd_controls), |
| 3071 | .dapm_widgets = wm8996_dapm_widgets, |
| 3072 | .num_dapm_widgets = ARRAY_SIZE(wm8996_dapm_widgets), |
| 3073 | .dapm_routes = wm8996_dapm_routes, |
| 3074 | .num_dapm_routes = ARRAY_SIZE(wm8996_dapm_routes), |
| 3075 | .set_pll = wm8996_set_fll, |
Mark Brown | 1b39bf34 | 2011-12-29 12:18:53 +0000 | [diff] [blame] | 3076 | .reg_cache_size = WM8996_MAX_REGISTER, |
| 3077 | .volatile_register = wm8996_soc_volatile_register, |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 3078 | }; |
| 3079 | |
| 3080 | #define WM8996_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\ |
| 3081 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000) |
| 3082 | #define WM8996_FORMATS (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE |\ |
| 3083 | SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S24_LE |\ |
| 3084 | SNDRV_PCM_FMTBIT_S32_LE) |
| 3085 | |
Lars-Peter Clausen | 85e7652 | 2011-11-23 11:40:40 +0100 | [diff] [blame] | 3086 | static const struct snd_soc_dai_ops wm8996_dai_ops = { |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 3087 | .set_fmt = wm8996_set_fmt, |
| 3088 | .hw_params = wm8996_hw_params, |
| 3089 | .set_sysclk = wm8996_set_sysclk, |
| 3090 | }; |
| 3091 | |
| 3092 | static struct snd_soc_dai_driver wm8996_dai[] = { |
| 3093 | { |
| 3094 | .name = "wm8996-aif1", |
| 3095 | .playback = { |
| 3096 | .stream_name = "AIF1 Playback", |
| 3097 | .channels_min = 1, |
| 3098 | .channels_max = 6, |
| 3099 | .rates = WM8996_RATES, |
| 3100 | .formats = WM8996_FORMATS, |
Mark Brown | a4b5233 | 2012-01-16 18:39:21 +0000 | [diff] [blame] | 3101 | .sig_bits = 24, |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 3102 | }, |
| 3103 | .capture = { |
| 3104 | .stream_name = "AIF1 Capture", |
| 3105 | .channels_min = 1, |
| 3106 | .channels_max = 6, |
| 3107 | .rates = WM8996_RATES, |
| 3108 | .formats = WM8996_FORMATS, |
Mark Brown | a4b5233 | 2012-01-16 18:39:21 +0000 | [diff] [blame] | 3109 | .sig_bits = 24, |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 3110 | }, |
| 3111 | .ops = &wm8996_dai_ops, |
| 3112 | }, |
| 3113 | { |
| 3114 | .name = "wm8996-aif2", |
| 3115 | .playback = { |
| 3116 | .stream_name = "AIF2 Playback", |
| 3117 | .channels_min = 1, |
| 3118 | .channels_max = 2, |
| 3119 | .rates = WM8996_RATES, |
| 3120 | .formats = WM8996_FORMATS, |
Mark Brown | a4b5233 | 2012-01-16 18:39:21 +0000 | [diff] [blame] | 3121 | .sig_bits = 24, |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 3122 | }, |
| 3123 | .capture = { |
| 3124 | .stream_name = "AIF2 Capture", |
| 3125 | .channels_min = 1, |
| 3126 | .channels_max = 2, |
| 3127 | .rates = WM8996_RATES, |
| 3128 | .formats = WM8996_FORMATS, |
Mark Brown | a4b5233 | 2012-01-16 18:39:21 +0000 | [diff] [blame] | 3129 | .sig_bits = 24, |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 3130 | }, |
| 3131 | .ops = &wm8996_dai_ops, |
| 3132 | }, |
| 3133 | }; |
| 3134 | |
| 3135 | static __devinit int wm8996_i2c_probe(struct i2c_client *i2c, |
| 3136 | const struct i2c_device_id *id) |
| 3137 | { |
| 3138 | struct wm8996_priv *wm8996; |
Mark Brown | ee5f387 | 2011-09-19 19:51:07 +0100 | [diff] [blame] | 3139 | int ret, i; |
| 3140 | unsigned int reg; |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 3141 | |
Mark Brown | a290986 | 2011-11-27 15:59:23 +0000 | [diff] [blame] | 3142 | wm8996 = devm_kzalloc(&i2c->dev, sizeof(struct wm8996_priv), |
| 3143 | GFP_KERNEL); |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 3144 | if (wm8996 == NULL) |
| 3145 | return -ENOMEM; |
| 3146 | |
| 3147 | i2c_set_clientdata(i2c, wm8996); |
Mark Brown | b2d1e23 | 2011-09-19 23:04:06 +0100 | [diff] [blame] | 3148 | wm8996->dev = &i2c->dev; |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 3149 | |
| 3150 | if (dev_get_platdata(&i2c->dev)) |
| 3151 | memcpy(&wm8996->pdata, dev_get_platdata(&i2c->dev), |
| 3152 | sizeof(wm8996->pdata)); |
| 3153 | |
| 3154 | if (wm8996->pdata.ldo_ena > 0) { |
| 3155 | ret = gpio_request_one(wm8996->pdata.ldo_ena, |
| 3156 | GPIOF_OUT_INIT_LOW, "WM8996 ENA"); |
| 3157 | if (ret < 0) { |
| 3158 | dev_err(&i2c->dev, "Failed to request GPIO %d: %d\n", |
| 3159 | wm8996->pdata.ldo_ena, ret); |
| 3160 | goto err; |
| 3161 | } |
| 3162 | } |
| 3163 | |
Mark Brown | ee5f387 | 2011-09-19 19:51:07 +0100 | [diff] [blame] | 3164 | for (i = 0; i < ARRAY_SIZE(wm8996->supplies); i++) |
| 3165 | wm8996->supplies[i].supply = wm8996_supply_names[i]; |
| 3166 | |
| 3167 | ret = regulator_bulk_get(&i2c->dev, ARRAY_SIZE(wm8996->supplies), |
| 3168 | wm8996->supplies); |
| 3169 | if (ret != 0) { |
| 3170 | dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret); |
| 3171 | goto err_gpio; |
| 3172 | } |
| 3173 | |
| 3174 | wm8996->cpvdd = regulator_get(&i2c->dev, "CPVDD"); |
| 3175 | if (IS_ERR(wm8996->cpvdd)) { |
| 3176 | ret = PTR_ERR(wm8996->cpvdd); |
| 3177 | dev_err(&i2c->dev, "Failed to get CPVDD: %d\n", ret); |
| 3178 | goto err_get; |
| 3179 | } |
| 3180 | |
| 3181 | ret = regulator_bulk_enable(ARRAY_SIZE(wm8996->supplies), |
| 3182 | wm8996->supplies); |
| 3183 | if (ret != 0) { |
| 3184 | dev_err(&i2c->dev, "Failed to enable supplies: %d\n", ret); |
| 3185 | goto err_cpvdd; |
| 3186 | } |
| 3187 | |
| 3188 | if (wm8996->pdata.ldo_ena > 0) { |
| 3189 | gpio_set_value_cansleep(wm8996->pdata.ldo_ena, 1); |
| 3190 | msleep(5); |
| 3191 | } |
| 3192 | |
| 3193 | wm8996->regmap = regmap_init_i2c(i2c, &wm8996_regmap); |
| 3194 | if (IS_ERR(wm8996->regmap)) { |
| 3195 | ret = PTR_ERR(wm8996->regmap); |
| 3196 | dev_err(&i2c->dev, "regmap_init() failed: %d\n", ret); |
| 3197 | goto err_enable; |
| 3198 | } |
| 3199 | |
| 3200 | ret = regmap_read(wm8996->regmap, WM8996_SOFTWARE_RESET, ®); |
| 3201 | if (ret < 0) { |
| 3202 | dev_err(&i2c->dev, "Failed to read ID register: %d\n", ret); |
| 3203 | goto err_regmap; |
| 3204 | } |
| 3205 | if (reg != 0x8915) { |
| 3206 | dev_err(&i2c->dev, "Device is not a WM8996, ID %x\n", ret); |
| 3207 | ret = -EINVAL; |
| 3208 | goto err_regmap; |
| 3209 | } |
| 3210 | |
| 3211 | ret = regmap_read(wm8996->regmap, WM8996_CHIP_REVISION, ®); |
| 3212 | if (ret < 0) { |
| 3213 | dev_err(&i2c->dev, "Failed to read device revision: %d\n", |
| 3214 | ret); |
| 3215 | goto err_regmap; |
| 3216 | } |
| 3217 | |
| 3218 | dev_info(&i2c->dev, "revision %c\n", |
| 3219 | (reg & WM8996_CHIP_REV_MASK) + 'A'); |
| 3220 | |
| 3221 | regulator_bulk_disable(ARRAY_SIZE(wm8996->supplies), wm8996->supplies); |
| 3222 | |
| 3223 | ret = wm8996_reset(wm8996); |
| 3224 | if (ret < 0) { |
| 3225 | dev_err(&i2c->dev, "Failed to issue reset\n"); |
| 3226 | goto err_regmap; |
| 3227 | } |
| 3228 | |
Mark Brown | b2d1e23 | 2011-09-19 23:04:06 +0100 | [diff] [blame] | 3229 | wm8996_init_gpio(wm8996); |
| 3230 | |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 3231 | ret = snd_soc_register_codec(&i2c->dev, |
| 3232 | &soc_codec_dev_wm8996, wm8996_dai, |
| 3233 | ARRAY_SIZE(wm8996_dai)); |
| 3234 | if (ret < 0) |
Mark Brown | b2d1e23 | 2011-09-19 23:04:06 +0100 | [diff] [blame] | 3235 | goto err_gpiolib; |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 3236 | |
| 3237 | return ret; |
| 3238 | |
Mark Brown | b2d1e23 | 2011-09-19 23:04:06 +0100 | [diff] [blame] | 3239 | err_gpiolib: |
| 3240 | wm8996_free_gpio(wm8996); |
Mark Brown | ee5f387 | 2011-09-19 19:51:07 +0100 | [diff] [blame] | 3241 | err_regmap: |
| 3242 | regmap_exit(wm8996->regmap); |
| 3243 | err_enable: |
| 3244 | if (wm8996->pdata.ldo_ena > 0) |
| 3245 | gpio_set_value_cansleep(wm8996->pdata.ldo_ena, 0); |
| 3246 | regulator_bulk_disable(ARRAY_SIZE(wm8996->supplies), wm8996->supplies); |
| 3247 | err_cpvdd: |
| 3248 | regulator_put(wm8996->cpvdd); |
| 3249 | err_get: |
| 3250 | regulator_bulk_free(ARRAY_SIZE(wm8996->supplies), wm8996->supplies); |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 3251 | err_gpio: |
| 3252 | if (wm8996->pdata.ldo_ena > 0) |
| 3253 | gpio_free(wm8996->pdata.ldo_ena); |
| 3254 | err: |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 3255 | |
| 3256 | return ret; |
| 3257 | } |
| 3258 | |
| 3259 | static __devexit int wm8996_i2c_remove(struct i2c_client *client) |
| 3260 | { |
| 3261 | struct wm8996_priv *wm8996 = i2c_get_clientdata(client); |
| 3262 | |
| 3263 | snd_soc_unregister_codec(&client->dev); |
Mark Brown | b2d1e23 | 2011-09-19 23:04:06 +0100 | [diff] [blame] | 3264 | wm8996_free_gpio(wm8996); |
Mark Brown | ee5f387 | 2011-09-19 19:51:07 +0100 | [diff] [blame] | 3265 | regulator_put(wm8996->cpvdd); |
| 3266 | regulator_bulk_free(ARRAY_SIZE(wm8996->supplies), wm8996->supplies); |
| 3267 | regmap_exit(wm8996->regmap); |
| 3268 | if (wm8996->pdata.ldo_ena > 0) { |
| 3269 | gpio_set_value_cansleep(wm8996->pdata.ldo_ena, 0); |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 3270 | gpio_free(wm8996->pdata.ldo_ena); |
Mark Brown | ee5f387 | 2011-09-19 19:51:07 +0100 | [diff] [blame] | 3271 | } |
Mark Brown | a9ba615 | 2011-06-24 12:10:44 +0100 | [diff] [blame] | 3272 | return 0; |
| 3273 | } |
| 3274 | |
| 3275 | static const struct i2c_device_id wm8996_i2c_id[] = { |
| 3276 | { "wm8996", 0 }, |
| 3277 | { } |
| 3278 | }; |
| 3279 | MODULE_DEVICE_TABLE(i2c, wm8996_i2c_id); |
| 3280 | |
| 3281 | static struct i2c_driver wm8996_i2c_driver = { |
| 3282 | .driver = { |
| 3283 | .name = "wm8996", |
| 3284 | .owner = THIS_MODULE, |
| 3285 | }, |
| 3286 | .probe = wm8996_i2c_probe, |
| 3287 | .remove = __devexit_p(wm8996_i2c_remove), |
| 3288 | .id_table = wm8996_i2c_id, |
| 3289 | }; |
| 3290 | |
| 3291 | static int __init wm8996_modinit(void) |
| 3292 | { |
| 3293 | int ret; |
| 3294 | |
| 3295 | ret = i2c_add_driver(&wm8996_i2c_driver); |
| 3296 | if (ret != 0) { |
| 3297 | printk(KERN_ERR "Failed to register WM8996 I2C driver: %d\n", |
| 3298 | ret); |
| 3299 | } |
| 3300 | |
| 3301 | return ret; |
| 3302 | } |
| 3303 | module_init(wm8996_modinit); |
| 3304 | |
| 3305 | static void __exit wm8996_exit(void) |
| 3306 | { |
| 3307 | i2c_del_driver(&wm8996_i2c_driver); |
| 3308 | } |
| 3309 | module_exit(wm8996_exit); |
| 3310 | |
| 3311 | MODULE_DESCRIPTION("ASoC WM8996 driver"); |
| 3312 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); |
| 3313 | MODULE_LICENSE("GPL"); |