Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 1 | /* |
| 2 | * wm8741.c -- WM8741 ALSA SoC Audio driver |
| 3 | * |
Mark Brown | 656baae | 2012-05-23 12:39:07 +0100 | [diff] [blame] | 4 | * Copyright 2010-1 Wolfson Microelectronics plc |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 5 | * |
| 6 | * Author: Ian Lartey <ian@opensource.wolfsonmicro.com> |
| 7 | * |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 as |
| 11 | * published by the Free Software Foundation. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/moduleparam.h> |
| 16 | #include <linux/init.h> |
| 17 | #include <linux/delay.h> |
| 18 | #include <linux/pm.h> |
| 19 | #include <linux/i2c.h> |
Mark Brown | 39e9b8d | 2011-08-03 17:30:57 +0900 | [diff] [blame] | 20 | #include <linux/spi/spi.h> |
Mark Brown | fe98c0c | 2012-09-10 18:00:21 +0800 | [diff] [blame] | 21 | #include <linux/regmap.h> |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 22 | #include <linux/regulator/consumer.h> |
| 23 | #include <linux/slab.h> |
Mark Brown | 80080ec | 2011-08-03 17:31:26 +0900 | [diff] [blame] | 24 | #include <linux/of_device.h> |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 25 | #include <sound/core.h> |
| 26 | #include <sound/pcm.h> |
| 27 | #include <sound/pcm_params.h> |
| 28 | #include <sound/soc.h> |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 29 | #include <sound/initval.h> |
| 30 | #include <sound/tlv.h> |
| 31 | |
| 32 | #include "wm8741.h" |
| 33 | |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 34 | #define WM8741_NUM_SUPPLIES 2 |
| 35 | static const char *wm8741_supply_names[WM8741_NUM_SUPPLIES] = { |
| 36 | "AVDD", |
| 37 | "DVDD", |
| 38 | }; |
| 39 | |
Ian Lartey | 3fe4a5e | 2010-08-27 15:26:27 +0100 | [diff] [blame] | 40 | #define WM8741_NUM_RATES 6 |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 41 | |
| 42 | /* codec private data */ |
| 43 | struct wm8741_priv { |
Sergej Sawazki | c354b54 | 2015-05-13 11:39:01 +0200 | [diff] [blame] | 44 | struct wm8741_platform_data pdata; |
Mark Brown | fe98c0c | 2012-09-10 18:00:21 +0800 | [diff] [blame] | 45 | struct regmap *regmap; |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 46 | struct regulator_bulk_data supplies[WM8741_NUM_SUPPLIES]; |
| 47 | unsigned int sysclk; |
Lars-Peter Clausen | 70bad2c | 2014-02-05 21:54:35 +0100 | [diff] [blame] | 48 | const struct snd_pcm_hw_constraint_list *sysclk_constraints; |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 49 | }; |
| 50 | |
Mark Brown | fe98c0c | 2012-09-10 18:00:21 +0800 | [diff] [blame] | 51 | static const struct reg_default wm8741_reg_defaults[] = { |
| 52 | { 0, 0x0000 }, /* R0 - DACLLSB Attenuation */ |
| 53 | { 1, 0x0000 }, /* R1 - DACLMSB Attenuation */ |
| 54 | { 2, 0x0000 }, /* R2 - DACRLSB Attenuation */ |
| 55 | { 3, 0x0000 }, /* R3 - DACRMSB Attenuation */ |
| 56 | { 4, 0x0000 }, /* R4 - Volume Control */ |
| 57 | { 5, 0x000A }, /* R5 - Format Control */ |
| 58 | { 6, 0x0000 }, /* R6 - Filter Control */ |
| 59 | { 7, 0x0000 }, /* R7 - Mode Control 1 */ |
| 60 | { 8, 0x0002 }, /* R8 - Mode Control 2 */ |
| 61 | { 32, 0x0002 }, /* R32 - ADDITONAL_CONTROL_1 */ |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 62 | }; |
| 63 | |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 64 | static int wm8741_reset(struct snd_soc_codec *codec) |
| 65 | { |
| 66 | return snd_soc_write(codec, WM8741_RESET, 0); |
| 67 | } |
| 68 | |
| 69 | static const DECLARE_TLV_DB_SCALE(dac_tlv_fine, -12700, 13, 0); |
| 70 | static const DECLARE_TLV_DB_SCALE(dac_tlv, -12700, 400, 0); |
| 71 | |
Sergej Sawazki | c354b54 | 2015-05-13 11:39:01 +0200 | [diff] [blame] | 72 | static const struct snd_kcontrol_new wm8741_snd_controls_stereo[] = { |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 73 | SOC_DOUBLE_R_TLV("Fine Playback Volume", WM8741_DACLLSB_ATTENUATION, |
| 74 | WM8741_DACRLSB_ATTENUATION, 1, 255, 1, dac_tlv_fine), |
| 75 | SOC_DOUBLE_R_TLV("Playback Volume", WM8741_DACLMSB_ATTENUATION, |
| 76 | WM8741_DACRMSB_ATTENUATION, 0, 511, 1, dac_tlv), |
| 77 | }; |
| 78 | |
Sergej Sawazki | c354b54 | 2015-05-13 11:39:01 +0200 | [diff] [blame] | 79 | static const struct snd_kcontrol_new wm8741_snd_controls_mono_left[] = { |
| 80 | SOC_SINGLE_TLV("Fine Playback Volume", WM8741_DACLLSB_ATTENUATION, |
| 81 | 1, 255, 1, dac_tlv_fine), |
| 82 | SOC_SINGLE_TLV("Playback Volume", WM8741_DACLMSB_ATTENUATION, |
| 83 | 0, 511, 1, dac_tlv), |
| 84 | }; |
| 85 | |
| 86 | static const struct snd_kcontrol_new wm8741_snd_controls_mono_right[] = { |
| 87 | SOC_SINGLE_TLV("Fine Playback Volume", WM8741_DACRLSB_ATTENUATION, |
| 88 | 1, 255, 1, dac_tlv_fine), |
| 89 | SOC_SINGLE_TLV("Playback Volume", WM8741_DACRMSB_ATTENUATION, |
| 90 | 0, 511, 1, dac_tlv), |
| 91 | }; |
| 92 | |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 93 | static const struct snd_soc_dapm_widget wm8741_dapm_widgets[] = { |
| 94 | SND_SOC_DAPM_DAC("DACL", "Playback", SND_SOC_NOPM, 0, 0), |
| 95 | SND_SOC_DAPM_DAC("DACR", "Playback", SND_SOC_NOPM, 0, 0), |
| 96 | SND_SOC_DAPM_OUTPUT("VOUTLP"), |
| 97 | SND_SOC_DAPM_OUTPUT("VOUTLN"), |
| 98 | SND_SOC_DAPM_OUTPUT("VOUTRP"), |
| 99 | SND_SOC_DAPM_OUTPUT("VOUTRN"), |
| 100 | }; |
| 101 | |
Mark Brown | 0e62780 | 2011-12-03 17:15:06 +0000 | [diff] [blame] | 102 | static const struct snd_soc_dapm_route wm8741_dapm_routes[] = { |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 103 | { "VOUTLP", NULL, "DACL" }, |
| 104 | { "VOUTLN", NULL, "DACL" }, |
| 105 | { "VOUTRP", NULL, "DACR" }, |
| 106 | { "VOUTRN", NULL, "DACR" }, |
| 107 | }; |
| 108 | |
Lars-Peter Clausen | 70bad2c | 2014-02-05 21:54:35 +0100 | [diff] [blame] | 109 | static const unsigned int rates_11289[] = { |
Sergej Sawazki | 8787041 | 2015-03-24 21:13:22 +0100 | [diff] [blame] | 110 | 44100, 88200, |
Ian Lartey | 3fe4a5e | 2010-08-27 15:26:27 +0100 | [diff] [blame] | 111 | }; |
| 112 | |
Lars-Peter Clausen | 70bad2c | 2014-02-05 21:54:35 +0100 | [diff] [blame] | 113 | static const struct snd_pcm_hw_constraint_list constraints_11289 = { |
Ian Lartey | 3fe4a5e | 2010-08-27 15:26:27 +0100 | [diff] [blame] | 114 | .count = ARRAY_SIZE(rates_11289), |
| 115 | .list = rates_11289, |
| 116 | }; |
| 117 | |
Lars-Peter Clausen | 70bad2c | 2014-02-05 21:54:35 +0100 | [diff] [blame] | 118 | static const unsigned int rates_12288[] = { |
Ian Lartey | 3fe4a5e | 2010-08-27 15:26:27 +0100 | [diff] [blame] | 119 | 32000, 48000, 96000, |
| 120 | }; |
| 121 | |
Lars-Peter Clausen | 70bad2c | 2014-02-05 21:54:35 +0100 | [diff] [blame] | 122 | static const struct snd_pcm_hw_constraint_list constraints_12288 = { |
Ian Lartey | 3fe4a5e | 2010-08-27 15:26:27 +0100 | [diff] [blame] | 123 | .count = ARRAY_SIZE(rates_12288), |
| 124 | .list = rates_12288, |
| 125 | }; |
| 126 | |
Lars-Peter Clausen | 70bad2c | 2014-02-05 21:54:35 +0100 | [diff] [blame] | 127 | static const unsigned int rates_16384[] = { |
Ian Lartey | 3fe4a5e | 2010-08-27 15:26:27 +0100 | [diff] [blame] | 128 | 32000, |
| 129 | }; |
| 130 | |
Lars-Peter Clausen | 70bad2c | 2014-02-05 21:54:35 +0100 | [diff] [blame] | 131 | static const struct snd_pcm_hw_constraint_list constraints_16384 = { |
Ian Lartey | 3fe4a5e | 2010-08-27 15:26:27 +0100 | [diff] [blame] | 132 | .count = ARRAY_SIZE(rates_16384), |
| 133 | .list = rates_16384, |
| 134 | }; |
| 135 | |
Lars-Peter Clausen | 70bad2c | 2014-02-05 21:54:35 +0100 | [diff] [blame] | 136 | static const unsigned int rates_16934[] = { |
Sergej Sawazki | 8787041 | 2015-03-24 21:13:22 +0100 | [diff] [blame] | 137 | 44100, 88200, |
Ian Lartey | 3fe4a5e | 2010-08-27 15:26:27 +0100 | [diff] [blame] | 138 | }; |
| 139 | |
Lars-Peter Clausen | 70bad2c | 2014-02-05 21:54:35 +0100 | [diff] [blame] | 140 | static const struct snd_pcm_hw_constraint_list constraints_16934 = { |
Ian Lartey | 3fe4a5e | 2010-08-27 15:26:27 +0100 | [diff] [blame] | 141 | .count = ARRAY_SIZE(rates_16934), |
| 142 | .list = rates_16934, |
| 143 | }; |
| 144 | |
Lars-Peter Clausen | 70bad2c | 2014-02-05 21:54:35 +0100 | [diff] [blame] | 145 | static const unsigned int rates_18432[] = { |
Ian Lartey | 3fe4a5e | 2010-08-27 15:26:27 +0100 | [diff] [blame] | 146 | 48000, 96000, |
| 147 | }; |
| 148 | |
Lars-Peter Clausen | 70bad2c | 2014-02-05 21:54:35 +0100 | [diff] [blame] | 149 | static const struct snd_pcm_hw_constraint_list constraints_18432 = { |
Ian Lartey | 3fe4a5e | 2010-08-27 15:26:27 +0100 | [diff] [blame] | 150 | .count = ARRAY_SIZE(rates_18432), |
| 151 | .list = rates_18432, |
| 152 | }; |
| 153 | |
Lars-Peter Clausen | 70bad2c | 2014-02-05 21:54:35 +0100 | [diff] [blame] | 154 | static const unsigned int rates_22579[] = { |
Sergej Sawazki | 8787041 | 2015-03-24 21:13:22 +0100 | [diff] [blame] | 155 | 44100, 88200, 176400 |
Ian Lartey | 3fe4a5e | 2010-08-27 15:26:27 +0100 | [diff] [blame] | 156 | }; |
| 157 | |
Lars-Peter Clausen | 70bad2c | 2014-02-05 21:54:35 +0100 | [diff] [blame] | 158 | static const struct snd_pcm_hw_constraint_list constraints_22579 = { |
Ian Lartey | 3fe4a5e | 2010-08-27 15:26:27 +0100 | [diff] [blame] | 159 | .count = ARRAY_SIZE(rates_22579), |
| 160 | .list = rates_22579, |
| 161 | }; |
| 162 | |
Lars-Peter Clausen | 70bad2c | 2014-02-05 21:54:35 +0100 | [diff] [blame] | 163 | static const unsigned int rates_24576[] = { |
Ian Lartey | 3fe4a5e | 2010-08-27 15:26:27 +0100 | [diff] [blame] | 164 | 32000, 48000, 96000, 192000 |
| 165 | }; |
| 166 | |
Lars-Peter Clausen | 70bad2c | 2014-02-05 21:54:35 +0100 | [diff] [blame] | 167 | static const struct snd_pcm_hw_constraint_list constraints_24576 = { |
Ian Lartey | 3fe4a5e | 2010-08-27 15:26:27 +0100 | [diff] [blame] | 168 | .count = ARRAY_SIZE(rates_24576), |
| 169 | .list = rates_24576, |
| 170 | }; |
| 171 | |
Lars-Peter Clausen | 70bad2c | 2014-02-05 21:54:35 +0100 | [diff] [blame] | 172 | static const unsigned int rates_36864[] = { |
Sergej Sawazki | 8787041 | 2015-03-24 21:13:22 +0100 | [diff] [blame] | 173 | 48000, 96000, 192000 |
Ian Lartey | 3fe4a5e | 2010-08-27 15:26:27 +0100 | [diff] [blame] | 174 | }; |
| 175 | |
Lars-Peter Clausen | 70bad2c | 2014-02-05 21:54:35 +0100 | [diff] [blame] | 176 | static const struct snd_pcm_hw_constraint_list constraints_36864 = { |
Ian Lartey | 3fe4a5e | 2010-08-27 15:26:27 +0100 | [diff] [blame] | 177 | .count = ARRAY_SIZE(rates_36864), |
| 178 | .list = rates_36864, |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 179 | }; |
| 180 | |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 181 | static int wm8741_startup(struct snd_pcm_substream *substream, |
| 182 | struct snd_soc_dai *dai) |
| 183 | { |
| 184 | struct snd_soc_codec *codec = dai->codec; |
| 185 | struct wm8741_priv *wm8741 = snd_soc_codec_get_drvdata(codec); |
| 186 | |
Sergej Sawazki | e369bd0 | 2015-06-06 11:25:48 +0200 | [diff] [blame] | 187 | if (wm8741->sysclk) |
| 188 | snd_pcm_hw_constraint_list(substream->runtime, 0, |
| 189 | SNDRV_PCM_HW_PARAM_RATE, |
| 190 | wm8741->sysclk_constraints); |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 191 | |
| 192 | return 0; |
| 193 | } |
| 194 | |
| 195 | static int wm8741_hw_params(struct snd_pcm_substream *substream, |
| 196 | struct snd_pcm_hw_params *params, |
| 197 | struct snd_soc_dai *dai) |
| 198 | { |
Mark Brown | e6968a1 | 2012-04-04 15:58:16 +0100 | [diff] [blame] | 199 | struct snd_soc_codec *codec = dai->codec; |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 200 | struct wm8741_priv *wm8741 = snd_soc_codec_get_drvdata(codec); |
| 201 | u16 iface = snd_soc_read(codec, WM8741_FORMAT_CONTROL) & 0x1FC; |
| 202 | int i; |
| 203 | |
Sergej Sawazki | e369bd0 | 2015-06-06 11:25:48 +0200 | [diff] [blame] | 204 | /* The set of sample rates that can be supported depends on the |
| 205 | * MCLK supplied to the CODEC - enforce this. |
| 206 | */ |
| 207 | if (!wm8741->sysclk) { |
| 208 | dev_err(codec->dev, |
| 209 | "No MCLK configured, call set_sysclk() on init or in hw_params\n"); |
| 210 | return -EINVAL; |
| 211 | } |
| 212 | |
| 213 | /* Find a supported LRCLK rate */ |
| 214 | for (i = 0; i < wm8741->sysclk_constraints->count; i++) { |
| 215 | if (wm8741->sysclk_constraints->list[i] == params_rate(params)) |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 216 | break; |
| 217 | } |
| 218 | |
Sergej Sawazki | e369bd0 | 2015-06-06 11:25:48 +0200 | [diff] [blame] | 219 | if (i == wm8741->sysclk_constraints->count) { |
| 220 | dev_err(codec->dev, "LRCLK %d unsupported with MCLK %d\n", |
| 221 | params_rate(params), wm8741->sysclk); |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 222 | return -EINVAL; |
| 223 | } |
| 224 | |
| 225 | /* bit size */ |
Mark Brown | 34967ad | 2014-07-31 12:51:45 +0100 | [diff] [blame] | 226 | switch (params_width(params)) { |
| 227 | case 16: |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 228 | break; |
Mark Brown | 34967ad | 2014-07-31 12:51:45 +0100 | [diff] [blame] | 229 | case 20: |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 230 | iface |= 0x0001; |
| 231 | break; |
Mark Brown | 34967ad | 2014-07-31 12:51:45 +0100 | [diff] [blame] | 232 | case 24: |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 233 | iface |= 0x0002; |
| 234 | break; |
Mark Brown | 34967ad | 2014-07-31 12:51:45 +0100 | [diff] [blame] | 235 | case 32: |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 236 | iface |= 0x0003; |
| 237 | break; |
| 238 | default: |
| 239 | dev_dbg(codec->dev, "wm8741_hw_params: Unsupported bit size param = %d", |
Mark Brown | 34967ad | 2014-07-31 12:51:45 +0100 | [diff] [blame] | 240 | params_width(params)); |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 241 | return -EINVAL; |
| 242 | } |
| 243 | |
Sergej Sawazki | e369bd0 | 2015-06-06 11:25:48 +0200 | [diff] [blame] | 244 | dev_dbg(codec->dev, "wm8741_hw_params: bit size param = %d, rate param = %d", |
| 245 | params_width(params), params_rate(params)); |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 246 | |
| 247 | snd_soc_write(codec, WM8741_FORMAT_CONTROL, iface); |
| 248 | return 0; |
| 249 | } |
| 250 | |
| 251 | static int wm8741_set_dai_sysclk(struct snd_soc_dai *codec_dai, |
| 252 | int clk_id, unsigned int freq, int dir) |
| 253 | { |
| 254 | struct snd_soc_codec *codec = codec_dai->codec; |
| 255 | struct wm8741_priv *wm8741 = snd_soc_codec_get_drvdata(codec); |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 256 | |
| 257 | dev_dbg(codec->dev, "wm8741_set_dai_sysclk info: freq=%dHz\n", freq); |
| 258 | |
Ian Lartey | 3fe4a5e | 2010-08-27 15:26:27 +0100 | [diff] [blame] | 259 | switch (freq) { |
Sergej Sawazki | e369bd0 | 2015-06-06 11:25:48 +0200 | [diff] [blame] | 260 | case 0: |
| 261 | wm8741->sysclk_constraints = NULL; |
Axel Lin | 6f55a04 | 2015-07-30 10:24:03 +0800 | [diff] [blame] | 262 | break; |
Ian Lartey | 3fe4a5e | 2010-08-27 15:26:27 +0100 | [diff] [blame] | 263 | case 11289600: |
| 264 | wm8741->sysclk_constraints = &constraints_11289; |
Axel Lin | 6f55a04 | 2015-07-30 10:24:03 +0800 | [diff] [blame] | 265 | break; |
Ian Lartey | 3fe4a5e | 2010-08-27 15:26:27 +0100 | [diff] [blame] | 266 | case 12288000: |
| 267 | wm8741->sysclk_constraints = &constraints_12288; |
Axel Lin | 6f55a04 | 2015-07-30 10:24:03 +0800 | [diff] [blame] | 268 | break; |
Ian Lartey | 3fe4a5e | 2010-08-27 15:26:27 +0100 | [diff] [blame] | 269 | case 16384000: |
| 270 | wm8741->sysclk_constraints = &constraints_16384; |
Axel Lin | 6f55a04 | 2015-07-30 10:24:03 +0800 | [diff] [blame] | 271 | break; |
Ian Lartey | 3fe4a5e | 2010-08-27 15:26:27 +0100 | [diff] [blame] | 272 | case 16934400: |
| 273 | wm8741->sysclk_constraints = &constraints_16934; |
Axel Lin | 6f55a04 | 2015-07-30 10:24:03 +0800 | [diff] [blame] | 274 | break; |
Ian Lartey | 3fe4a5e | 2010-08-27 15:26:27 +0100 | [diff] [blame] | 275 | case 18432000: |
| 276 | wm8741->sysclk_constraints = &constraints_18432; |
Axel Lin | 6f55a04 | 2015-07-30 10:24:03 +0800 | [diff] [blame] | 277 | break; |
Ian Lartey | 3fe4a5e | 2010-08-27 15:26:27 +0100 | [diff] [blame] | 278 | case 22579200: |
| 279 | case 33868800: |
| 280 | wm8741->sysclk_constraints = &constraints_22579; |
Axel Lin | 6f55a04 | 2015-07-30 10:24:03 +0800 | [diff] [blame] | 281 | break; |
Ian Lartey | 3fe4a5e | 2010-08-27 15:26:27 +0100 | [diff] [blame] | 282 | case 24576000: |
| 283 | wm8741->sysclk_constraints = &constraints_24576; |
Axel Lin | 6f55a04 | 2015-07-30 10:24:03 +0800 | [diff] [blame] | 284 | break; |
Ian Lartey | 3fe4a5e | 2010-08-27 15:26:27 +0100 | [diff] [blame] | 285 | case 36864000: |
| 286 | wm8741->sysclk_constraints = &constraints_36864; |
Axel Lin | 6f55a04 | 2015-07-30 10:24:03 +0800 | [diff] [blame] | 287 | break; |
| 288 | default: |
| 289 | return -EINVAL; |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 290 | } |
Axel Lin | 6f55a04 | 2015-07-30 10:24:03 +0800 | [diff] [blame] | 291 | |
| 292 | wm8741->sysclk = freq; |
| 293 | return 0; |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | static int wm8741_set_dai_fmt(struct snd_soc_dai *codec_dai, |
| 297 | unsigned int fmt) |
| 298 | { |
| 299 | struct snd_soc_codec *codec = codec_dai->codec; |
| 300 | u16 iface = snd_soc_read(codec, WM8741_FORMAT_CONTROL) & 0x1C3; |
| 301 | |
| 302 | /* check master/slave audio interface */ |
| 303 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 304 | case SND_SOC_DAIFMT_CBS_CFS: |
| 305 | break; |
| 306 | default: |
| 307 | return -EINVAL; |
| 308 | } |
| 309 | |
| 310 | /* interface format */ |
| 311 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 312 | case SND_SOC_DAIFMT_I2S: |
| 313 | iface |= 0x0008; |
| 314 | break; |
| 315 | case SND_SOC_DAIFMT_RIGHT_J: |
| 316 | break; |
| 317 | case SND_SOC_DAIFMT_LEFT_J: |
| 318 | iface |= 0x0004; |
| 319 | break; |
| 320 | case SND_SOC_DAIFMT_DSP_A: |
Axel Lin | 3a34010 | 2011-10-17 20:14:56 +0800 | [diff] [blame] | 321 | iface |= 0x000C; |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 322 | break; |
| 323 | case SND_SOC_DAIFMT_DSP_B: |
Axel Lin | 3a34010 | 2011-10-17 20:14:56 +0800 | [diff] [blame] | 324 | iface |= 0x001C; |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 325 | break; |
| 326 | default: |
| 327 | return -EINVAL; |
| 328 | } |
| 329 | |
| 330 | /* clock inversion */ |
| 331 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { |
| 332 | case SND_SOC_DAIFMT_NB_NF: |
| 333 | break; |
| 334 | case SND_SOC_DAIFMT_IB_IF: |
| 335 | iface |= 0x0010; |
| 336 | break; |
| 337 | case SND_SOC_DAIFMT_IB_NF: |
| 338 | iface |= 0x0020; |
| 339 | break; |
| 340 | case SND_SOC_DAIFMT_NB_IF: |
| 341 | iface |= 0x0030; |
| 342 | break; |
| 343 | default: |
| 344 | return -EINVAL; |
| 345 | } |
| 346 | |
| 347 | |
| 348 | dev_dbg(codec->dev, "wm8741_set_dai_fmt: Format=%x, Clock Inv=%x\n", |
| 349 | fmt & SND_SOC_DAIFMT_FORMAT_MASK, |
| 350 | ((fmt & SND_SOC_DAIFMT_INV_MASK))); |
| 351 | |
| 352 | snd_soc_write(codec, WM8741_FORMAT_CONTROL, iface); |
| 353 | return 0; |
| 354 | } |
| 355 | |
| 356 | #define WM8741_RATES (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \ |
| 357 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | \ |
| 358 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_176400 | \ |
| 359 | SNDRV_PCM_RATE_192000) |
| 360 | |
| 361 | #define WM8741_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ |
| 362 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE) |
| 363 | |
Lars-Peter Clausen | 85e7652 | 2011-11-23 11:40:40 +0100 | [diff] [blame] | 364 | static const struct snd_soc_dai_ops wm8741_dai_ops = { |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 365 | .startup = wm8741_startup, |
| 366 | .hw_params = wm8741_hw_params, |
| 367 | .set_sysclk = wm8741_set_dai_sysclk, |
| 368 | .set_fmt = wm8741_set_dai_fmt, |
| 369 | }; |
| 370 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 371 | static struct snd_soc_dai_driver wm8741_dai = { |
Ian Lartey | 30e2d36 | 2010-08-20 17:18:44 +0100 | [diff] [blame] | 372 | .name = "wm8741", |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 373 | .playback = { |
| 374 | .stream_name = "Playback", |
Sergej Sawazki | c354b54 | 2015-05-13 11:39:01 +0200 | [diff] [blame] | 375 | .channels_min = 2, |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 376 | .channels_max = 2, |
| 377 | .rates = WM8741_RATES, |
| 378 | .formats = WM8741_FORMATS, |
| 379 | }, |
| 380 | .ops = &wm8741_dai_ops, |
| 381 | }; |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 382 | |
| 383 | #ifdef CONFIG_PM |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 384 | static int wm8741_resume(struct snd_soc_codec *codec) |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 385 | { |
Axel Lin | df3431b | 2011-10-17 20:16:37 +0800 | [diff] [blame] | 386 | snd_soc_cache_sync(codec); |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 387 | return 0; |
| 388 | } |
| 389 | #else |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 390 | #define wm8741_resume NULL |
| 391 | #endif |
| 392 | |
Sergej Sawazki | c354b54 | 2015-05-13 11:39:01 +0200 | [diff] [blame] | 393 | static int wm8741_configure(struct snd_soc_codec *codec) |
| 394 | { |
| 395 | struct wm8741_priv *wm8741 = snd_soc_codec_get_drvdata(codec); |
| 396 | |
| 397 | /* Configure differential mode */ |
| 398 | switch (wm8741->pdata.diff_mode) { |
| 399 | case WM8741_DIFF_MODE_STEREO: |
| 400 | case WM8741_DIFF_MODE_STEREO_REVERSED: |
| 401 | case WM8741_DIFF_MODE_MONO_LEFT: |
| 402 | case WM8741_DIFF_MODE_MONO_RIGHT: |
| 403 | snd_soc_update_bits(codec, WM8741_MODE_CONTROL_2, |
| 404 | WM8741_DIFF_MASK, |
| 405 | wm8741->pdata.diff_mode << WM8741_DIFF_SHIFT); |
| 406 | break; |
| 407 | default: |
| 408 | return -EINVAL; |
| 409 | } |
| 410 | |
| 411 | /* Change some default settings - latch VU */ |
| 412 | snd_soc_update_bits(codec, WM8741_DACLLSB_ATTENUATION, |
| 413 | WM8741_UPDATELL, WM8741_UPDATELL); |
| 414 | snd_soc_update_bits(codec, WM8741_DACLMSB_ATTENUATION, |
| 415 | WM8741_UPDATELM, WM8741_UPDATELM); |
| 416 | snd_soc_update_bits(codec, WM8741_DACRLSB_ATTENUATION, |
| 417 | WM8741_UPDATERL, WM8741_UPDATERL); |
| 418 | snd_soc_update_bits(codec, WM8741_DACRMSB_ATTENUATION, |
| 419 | WM8741_UPDATERM, WM8741_UPDATERM); |
| 420 | |
| 421 | return 0; |
| 422 | } |
| 423 | |
| 424 | static int wm8741_add_controls(struct snd_soc_codec *codec) |
| 425 | { |
| 426 | struct wm8741_priv *wm8741 = snd_soc_codec_get_drvdata(codec); |
| 427 | |
| 428 | switch (wm8741->pdata.diff_mode) { |
| 429 | case WM8741_DIFF_MODE_STEREO: |
| 430 | case WM8741_DIFF_MODE_STEREO_REVERSED: |
| 431 | snd_soc_add_codec_controls(codec, |
| 432 | wm8741_snd_controls_stereo, |
| 433 | ARRAY_SIZE(wm8741_snd_controls_stereo)); |
| 434 | break; |
| 435 | case WM8741_DIFF_MODE_MONO_LEFT: |
| 436 | snd_soc_add_codec_controls(codec, |
| 437 | wm8741_snd_controls_mono_left, |
| 438 | ARRAY_SIZE(wm8741_snd_controls_mono_left)); |
| 439 | break; |
| 440 | case WM8741_DIFF_MODE_MONO_RIGHT: |
| 441 | snd_soc_add_codec_controls(codec, |
| 442 | wm8741_snd_controls_mono_right, |
| 443 | ARRAY_SIZE(wm8741_snd_controls_mono_right)); |
| 444 | break; |
| 445 | default: |
| 446 | return -EINVAL; |
| 447 | } |
| 448 | |
| 449 | return 0; |
| 450 | } |
| 451 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 452 | static int wm8741_probe(struct snd_soc_codec *codec) |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 453 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 454 | struct wm8741_priv *wm8741 = snd_soc_codec_get_drvdata(codec); |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 455 | int ret = 0; |
Mark Brown | 398575d | 2011-08-03 17:16:11 +0900 | [diff] [blame] | 456 | |
| 457 | ret = regulator_bulk_enable(ARRAY_SIZE(wm8741->supplies), |
| 458 | wm8741->supplies); |
| 459 | if (ret != 0) { |
| 460 | dev_err(codec->dev, "Failed to enable supplies: %d\n", ret); |
| 461 | goto err_get; |
| 462 | } |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 463 | |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 464 | ret = wm8741_reset(codec); |
| 465 | if (ret < 0) { |
| 466 | dev_err(codec->dev, "Failed to issue reset\n"); |
Mark Brown | 398575d | 2011-08-03 17:16:11 +0900 | [diff] [blame] | 467 | goto err_enable; |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 468 | } |
| 469 | |
Sergej Sawazki | c354b54 | 2015-05-13 11:39:01 +0200 | [diff] [blame] | 470 | ret = wm8741_configure(codec); |
| 471 | if (ret < 0) { |
| 472 | dev_err(codec->dev, "Failed to change default settings\n"); |
| 473 | goto err_enable; |
| 474 | } |
| 475 | |
| 476 | ret = wm8741_add_controls(codec); |
| 477 | if (ret < 0) { |
| 478 | dev_err(codec->dev, "Failed to add controls\n"); |
| 479 | goto err_enable; |
| 480 | } |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 481 | |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 482 | dev_dbg(codec->dev, "Successful registration\n"); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 483 | return ret; |
Mark Brown | 398575d | 2011-08-03 17:16:11 +0900 | [diff] [blame] | 484 | |
| 485 | err_enable: |
| 486 | regulator_bulk_disable(ARRAY_SIZE(wm8741->supplies), wm8741->supplies); |
| 487 | err_get: |
Mark Brown | 398575d | 2011-08-03 17:16:11 +0900 | [diff] [blame] | 488 | return ret; |
| 489 | } |
| 490 | |
| 491 | static int wm8741_remove(struct snd_soc_codec *codec) |
| 492 | { |
| 493 | struct wm8741_priv *wm8741 = snd_soc_codec_get_drvdata(codec); |
| 494 | |
| 495 | regulator_bulk_disable(ARRAY_SIZE(wm8741->supplies), wm8741->supplies); |
Mark Brown | 398575d | 2011-08-03 17:16:11 +0900 | [diff] [blame] | 496 | |
| 497 | return 0; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | static struct snd_soc_codec_driver soc_codec_dev_wm8741 = { |
| 501 | .probe = wm8741_probe, |
Mark Brown | 398575d | 2011-08-03 17:16:11 +0900 | [diff] [blame] | 502 | .remove = wm8741_remove, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 503 | .resume = wm8741_resume, |
Mark Brown | 0e62780 | 2011-12-03 17:15:06 +0000 | [diff] [blame] | 504 | |
Mark Brown | 0e62780 | 2011-12-03 17:15:06 +0000 | [diff] [blame] | 505 | .dapm_widgets = wm8741_dapm_widgets, |
| 506 | .num_dapm_widgets = ARRAY_SIZE(wm8741_dapm_widgets), |
| 507 | .dapm_routes = wm8741_dapm_routes, |
| 508 | .num_dapm_routes = ARRAY_SIZE(wm8741_dapm_routes), |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 509 | }; |
| 510 | |
Mark Brown | 80080ec | 2011-08-03 17:31:26 +0900 | [diff] [blame] | 511 | static const struct of_device_id wm8741_of_match[] = { |
| 512 | { .compatible = "wlf,wm8741", }, |
| 513 | { } |
| 514 | }; |
| 515 | MODULE_DEVICE_TABLE(of, wm8741_of_match); |
| 516 | |
Mark Brown | fe98c0c | 2012-09-10 18:00:21 +0800 | [diff] [blame] | 517 | static const struct regmap_config wm8741_regmap = { |
| 518 | .reg_bits = 7, |
| 519 | .val_bits = 9, |
| 520 | .max_register = WM8741_MAX_REGISTER, |
| 521 | |
| 522 | .reg_defaults = wm8741_reg_defaults, |
| 523 | .num_reg_defaults = ARRAY_SIZE(wm8741_reg_defaults), |
| 524 | .cache_type = REGCACHE_RBTREE, |
Mark Brown | fe98c0c | 2012-09-10 18:00:21 +0800 | [diff] [blame] | 525 | }; |
| 526 | |
Sergej Sawazki | c354b54 | 2015-05-13 11:39:01 +0200 | [diff] [blame] | 527 | static int wm8741_set_pdata(struct device *dev, struct wm8741_priv *wm8741) |
| 528 | { |
| 529 | const struct wm8741_platform_data *pdata = dev_get_platdata(dev); |
| 530 | u32 diff_mode; |
| 531 | |
| 532 | if (dev->of_node) { |
| 533 | if (of_property_read_u32(dev->of_node, "diff-mode", &diff_mode) |
| 534 | >= 0) |
| 535 | wm8741->pdata.diff_mode = diff_mode; |
| 536 | } else { |
| 537 | if (pdata != NULL) |
| 538 | memcpy(&wm8741->pdata, pdata, sizeof(wm8741->pdata)); |
| 539 | } |
| 540 | |
| 541 | return 0; |
| 542 | } |
| 543 | |
Fabio Estevam | 26090a8 | 2013-11-21 12:38:45 -0200 | [diff] [blame] | 544 | #if IS_ENABLED(CONFIG_I2C) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 545 | static int wm8741_i2c_probe(struct i2c_client *i2c, |
| 546 | const struct i2c_device_id *id) |
| 547 | { |
| 548 | struct wm8741_priv *wm8741; |
Mark Brown | d978055 | 2012-09-10 17:52:59 +0800 | [diff] [blame] | 549 | int ret, i; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 550 | |
Mark Brown | 5aefb30 | 2011-12-03 17:17:05 +0000 | [diff] [blame] | 551 | wm8741 = devm_kzalloc(&i2c->dev, sizeof(struct wm8741_priv), |
| 552 | GFP_KERNEL); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 553 | if (wm8741 == NULL) |
| 554 | return -ENOMEM; |
| 555 | |
Mark Brown | d978055 | 2012-09-10 17:52:59 +0800 | [diff] [blame] | 556 | for (i = 0; i < ARRAY_SIZE(wm8741->supplies); i++) |
| 557 | wm8741->supplies[i].supply = wm8741_supply_names[i]; |
| 558 | |
| 559 | ret = devm_regulator_bulk_get(&i2c->dev, ARRAY_SIZE(wm8741->supplies), |
| 560 | wm8741->supplies); |
| 561 | if (ret != 0) { |
Mark Brown | fe98c0c | 2012-09-10 18:00:21 +0800 | [diff] [blame] | 562 | dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret); |
| 563 | return ret; |
| 564 | } |
| 565 | |
Tushar Behera | fd64c45 | 2012-11-22 09:38:37 +0530 | [diff] [blame] | 566 | wm8741->regmap = devm_regmap_init_i2c(i2c, &wm8741_regmap); |
Mark Brown | fe98c0c | 2012-09-10 18:00:21 +0800 | [diff] [blame] | 567 | if (IS_ERR(wm8741->regmap)) { |
| 568 | ret = PTR_ERR(wm8741->regmap); |
| 569 | dev_err(&i2c->dev, "Failed to init regmap: %d\n", ret); |
| 570 | return ret; |
Mark Brown | d978055 | 2012-09-10 17:52:59 +0800 | [diff] [blame] | 571 | } |
| 572 | |
Dan Carpenter | 2d52d17 | 2015-05-20 10:40:35 +0300 | [diff] [blame] | 573 | ret = wm8741_set_pdata(&i2c->dev, wm8741); |
Sergej Sawazki | c354b54 | 2015-05-13 11:39:01 +0200 | [diff] [blame] | 574 | if (ret != 0) { |
| 575 | dev_err(&i2c->dev, "Failed to set pdata: %d\n", ret); |
| 576 | return ret; |
| 577 | } |
| 578 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 579 | i2c_set_clientdata(i2c, wm8741); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 580 | |
Mark Brown | 398575d | 2011-08-03 17:16:11 +0900 | [diff] [blame] | 581 | ret = snd_soc_register_codec(&i2c->dev, |
| 582 | &soc_codec_dev_wm8741, &wm8741_dai, 1); |
Mark Brown | 398575d | 2011-08-03 17:16:11 +0900 | [diff] [blame] | 583 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 584 | return ret; |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 585 | } |
| 586 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 587 | static int wm8741_i2c_remove(struct i2c_client *client) |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 588 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 589 | snd_soc_unregister_codec(&client->dev); |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 590 | return 0; |
| 591 | } |
| 592 | |
| 593 | static const struct i2c_device_id wm8741_i2c_id[] = { |
| 594 | { "wm8741", 0 }, |
| 595 | { } |
| 596 | }; |
| 597 | MODULE_DEVICE_TABLE(i2c, wm8741_i2c_id); |
| 598 | |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 599 | static struct i2c_driver wm8741_i2c_driver = { |
| 600 | .driver = { |
Mark Brown | 0473e61 | 2011-08-03 16:52:10 +0900 | [diff] [blame] | 601 | .name = "wm8741", |
Mark Brown | 80080ec | 2011-08-03 17:31:26 +0900 | [diff] [blame] | 602 | .of_match_table = wm8741_of_match, |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 603 | }, |
| 604 | .probe = wm8741_i2c_probe, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 605 | .remove = wm8741_i2c_remove, |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 606 | .id_table = wm8741_i2c_id, |
| 607 | }; |
| 608 | #endif |
| 609 | |
Mark Brown | 39e9b8d | 2011-08-03 17:30:57 +0900 | [diff] [blame] | 610 | #if defined(CONFIG_SPI_MASTER) |
Bill Pemberton | 7a79e94 | 2012-12-07 09:26:37 -0500 | [diff] [blame] | 611 | static int wm8741_spi_probe(struct spi_device *spi) |
Mark Brown | 39e9b8d | 2011-08-03 17:30:57 +0900 | [diff] [blame] | 612 | { |
| 613 | struct wm8741_priv *wm8741; |
Mark Brown | d978055 | 2012-09-10 17:52:59 +0800 | [diff] [blame] | 614 | int ret, i; |
Mark Brown | 39e9b8d | 2011-08-03 17:30:57 +0900 | [diff] [blame] | 615 | |
Mark Brown | 5aefb30 | 2011-12-03 17:17:05 +0000 | [diff] [blame] | 616 | wm8741 = devm_kzalloc(&spi->dev, sizeof(struct wm8741_priv), |
| 617 | GFP_KERNEL); |
Mark Brown | 39e9b8d | 2011-08-03 17:30:57 +0900 | [diff] [blame] | 618 | if (wm8741 == NULL) |
| 619 | return -ENOMEM; |
| 620 | |
Mark Brown | d978055 | 2012-09-10 17:52:59 +0800 | [diff] [blame] | 621 | for (i = 0; i < ARRAY_SIZE(wm8741->supplies); i++) |
| 622 | wm8741->supplies[i].supply = wm8741_supply_names[i]; |
| 623 | |
Mark Brown | fe98c0c | 2012-09-10 18:00:21 +0800 | [diff] [blame] | 624 | ret = devm_regulator_bulk_get(&spi->dev, ARRAY_SIZE(wm8741->supplies), |
Mark Brown | d978055 | 2012-09-10 17:52:59 +0800 | [diff] [blame] | 625 | wm8741->supplies); |
| 626 | if (ret != 0) { |
| 627 | dev_err(&spi->dev, "Failed to request supplies: %d\n", ret); |
Mark Brown | fe98c0c | 2012-09-10 18:00:21 +0800 | [diff] [blame] | 628 | return ret; |
Mark Brown | d978055 | 2012-09-10 17:52:59 +0800 | [diff] [blame] | 629 | } |
| 630 | |
Tushar Behera | fd64c45 | 2012-11-22 09:38:37 +0530 | [diff] [blame] | 631 | wm8741->regmap = devm_regmap_init_spi(spi, &wm8741_regmap); |
Mark Brown | fe98c0c | 2012-09-10 18:00:21 +0800 | [diff] [blame] | 632 | if (IS_ERR(wm8741->regmap)) { |
| 633 | ret = PTR_ERR(wm8741->regmap); |
| 634 | dev_err(&spi->dev, "Failed to init regmap: %d\n", ret); |
| 635 | return ret; |
| 636 | } |
| 637 | |
Dan Carpenter | 2d52d17 | 2015-05-20 10:40:35 +0300 | [diff] [blame] | 638 | ret = wm8741_set_pdata(&spi->dev, wm8741); |
Sergej Sawazki | c354b54 | 2015-05-13 11:39:01 +0200 | [diff] [blame] | 639 | if (ret != 0) { |
| 640 | dev_err(&spi->dev, "Failed to set pdata: %d\n", ret); |
| 641 | return ret; |
| 642 | } |
| 643 | |
Mark Brown | 39e9b8d | 2011-08-03 17:30:57 +0900 | [diff] [blame] | 644 | spi_set_drvdata(spi, wm8741); |
| 645 | |
| 646 | ret = snd_soc_register_codec(&spi->dev, |
| 647 | &soc_codec_dev_wm8741, &wm8741_dai, 1); |
Mark Brown | 39e9b8d | 2011-08-03 17:30:57 +0900 | [diff] [blame] | 648 | return ret; |
| 649 | } |
| 650 | |
Bill Pemberton | 7a79e94 | 2012-12-07 09:26:37 -0500 | [diff] [blame] | 651 | static int wm8741_spi_remove(struct spi_device *spi) |
Mark Brown | 39e9b8d | 2011-08-03 17:30:57 +0900 | [diff] [blame] | 652 | { |
| 653 | snd_soc_unregister_codec(&spi->dev); |
Mark Brown | 39e9b8d | 2011-08-03 17:30:57 +0900 | [diff] [blame] | 654 | return 0; |
| 655 | } |
| 656 | |
| 657 | static struct spi_driver wm8741_spi_driver = { |
| 658 | .driver = { |
| 659 | .name = "wm8741", |
| 660 | .owner = THIS_MODULE, |
Mark Brown | 80080ec | 2011-08-03 17:31:26 +0900 | [diff] [blame] | 661 | .of_match_table = wm8741_of_match, |
Mark Brown | 39e9b8d | 2011-08-03 17:30:57 +0900 | [diff] [blame] | 662 | }, |
| 663 | .probe = wm8741_spi_probe, |
Bill Pemberton | 7a79e94 | 2012-12-07 09:26:37 -0500 | [diff] [blame] | 664 | .remove = wm8741_spi_remove, |
Mark Brown | 39e9b8d | 2011-08-03 17:30:57 +0900 | [diff] [blame] | 665 | }; |
| 666 | #endif /* CONFIG_SPI_MASTER */ |
| 667 | |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 668 | static int __init wm8741_modinit(void) |
| 669 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 670 | int ret = 0; |
| 671 | |
Fabio Estevam | 26090a8 | 2013-11-21 12:38:45 -0200 | [diff] [blame] | 672 | #if IS_ENABLED(CONFIG_I2C) |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 673 | ret = i2c_add_driver(&wm8741_i2c_driver); |
Ian Lartey | 3fe4a5e | 2010-08-27 15:26:27 +0100 | [diff] [blame] | 674 | if (ret != 0) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 675 | pr_err("Failed to register WM8741 I2C driver: %d\n", ret); |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 676 | #endif |
Mark Brown | 39e9b8d | 2011-08-03 17:30:57 +0900 | [diff] [blame] | 677 | #if defined(CONFIG_SPI_MASTER) |
| 678 | ret = spi_register_driver(&wm8741_spi_driver); |
| 679 | if (ret != 0) { |
| 680 | printk(KERN_ERR "Failed to register wm8741 SPI driver: %d\n", |
| 681 | ret); |
| 682 | } |
| 683 | #endif |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 684 | |
| 685 | return ret; |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 686 | } |
| 687 | module_init(wm8741_modinit); |
| 688 | |
| 689 | static void __exit wm8741_exit(void) |
| 690 | { |
Mark Brown | 39e9b8d | 2011-08-03 17:30:57 +0900 | [diff] [blame] | 691 | #if defined(CONFIG_SPI_MASTER) |
| 692 | spi_unregister_driver(&wm8741_spi_driver); |
| 693 | #endif |
Fabio Estevam | 26090a8 | 2013-11-21 12:38:45 -0200 | [diff] [blame] | 694 | #if IS_ENABLED(CONFIG_I2C) |
Ian Lartey | 992bee4 | 2010-07-31 00:32:11 +0100 | [diff] [blame] | 695 | i2c_del_driver(&wm8741_i2c_driver); |
| 696 | #endif |
| 697 | } |
| 698 | module_exit(wm8741_exit); |
| 699 | |
| 700 | MODULE_DESCRIPTION("ASoC WM8741 driver"); |
| 701 | MODULE_AUTHOR("Ian Lartey <ian@opensource.wolfsonmicro.com>"); |
| 702 | MODULE_LICENSE("GPL"); |