1 // SPDX-License-Identifier: GPL-2.0-only << 2 /* 1 /* 3 * wm8731.c -- WM8731 ALSA SoC Audio driver 2 * wm8731.c -- WM8731 ALSA SoC Audio driver 4 * 3 * 5 * Copyright 2005 Openedhand Ltd. 4 * Copyright 2005 Openedhand Ltd. 6 * Copyright 2006-12 Wolfson Microelectronics, 5 * Copyright 2006-12 Wolfson Microelectronics, plc 7 * 6 * 8 * Author: Richard Purdie <richard@openedhand. 7 * Author: Richard Purdie <richard@openedhand.com> 9 * 8 * 10 * Based on wm8753.c by Liam Girdwood 9 * Based on wm8753.c by Liam Girdwood >> 10 * >> 11 * This program is free software; you can redistribute it and/or modify >> 12 * it under the terms of the GNU General Public License version 2 as >> 13 * published by the Free Software Foundation. 11 */ 14 */ 12 15 13 #include <linux/module.h> 16 #include <linux/module.h> 14 #include <linux/moduleparam.h> 17 #include <linux/moduleparam.h> 15 #include <linux/init.h> 18 #include <linux/init.h> 16 #include <linux/delay.h> 19 #include <linux/delay.h> 17 #include <linux/pm.h> 20 #include <linux/pm.h> >> 21 #include <linux/i2c.h> 18 #include <linux/slab.h> 22 #include <linux/slab.h> 19 #include <linux/regmap.h> 23 #include <linux/regmap.h> 20 #include <linux/regulator/consumer.h> 24 #include <linux/regulator/consumer.h> >> 25 #include <linux/spi/spi.h> >> 26 #include <linux/of_device.h> >> 27 #include <linux/mutex.h> 21 #include <linux/clk.h> 28 #include <linux/clk.h> 22 #include <sound/core.h> 29 #include <sound/core.h> 23 #include <sound/pcm.h> 30 #include <sound/pcm.h> 24 #include <sound/pcm_params.h> 31 #include <sound/pcm_params.h> 25 #include <sound/soc.h> 32 #include <sound/soc.h> 26 #include <sound/initval.h> 33 #include <sound/initval.h> 27 #include <sound/tlv.h> 34 #include <sound/tlv.h> 28 35 29 #include "wm8731.h" 36 #include "wm8731.h" 30 37 >> 38 #define WM8731_NUM_SUPPLIES 4 31 static const char *wm8731_supply_names[WM8731_ 39 static const char *wm8731_supply_names[WM8731_NUM_SUPPLIES] = { 32 "AVDD", 40 "AVDD", 33 "HPVDD", 41 "HPVDD", 34 "DCVDD", 42 "DCVDD", 35 "DBVDD", 43 "DBVDD", 36 }; 44 }; 37 45 >> 46 /* codec private data */ >> 47 struct wm8731_priv { >> 48 struct regmap *regmap; >> 49 struct clk *mclk; >> 50 struct regulator_bulk_data supplies[WM8731_NUM_SUPPLIES]; >> 51 const struct snd_pcm_hw_constraint_list *constraints; >> 52 unsigned int sysclk; >> 53 int sysclk_type; >> 54 int playback_fs; >> 55 bool deemph; >> 56 >> 57 struct mutex lock; >> 58 }; >> 59 >> 60 38 /* 61 /* 39 * wm8731 register cache 62 * wm8731 register cache 40 */ 63 */ 41 static const struct reg_default wm8731_reg_def 64 static const struct reg_default wm8731_reg_defaults[] = { 42 { 0, 0x0097 }, 65 { 0, 0x0097 }, 43 { 1, 0x0097 }, 66 { 1, 0x0097 }, 44 { 2, 0x0079 }, 67 { 2, 0x0079 }, 45 { 3, 0x0079 }, 68 { 3, 0x0079 }, 46 { 4, 0x000a }, 69 { 4, 0x000a }, 47 { 5, 0x0008 }, 70 { 5, 0x0008 }, 48 { 6, 0x009f }, 71 { 6, 0x009f }, 49 { 7, 0x000a }, 72 { 7, 0x000a }, 50 { 8, 0x0000 }, 73 { 8, 0x0000 }, 51 { 9, 0x0000 }, 74 { 9, 0x0000 }, 52 }; 75 }; 53 76 54 static bool wm8731_volatile(struct device *dev 77 static bool wm8731_volatile(struct device *dev, unsigned int reg) 55 { 78 { 56 return reg == WM8731_RESET; 79 return reg == WM8731_RESET; 57 } 80 } 58 81 59 #define wm8731_reset(m) regmap_write(m, WM8731 82 #define wm8731_reset(m) regmap_write(m, WM8731_RESET, 0) 60 83 61 static const char *wm8731_input_select[] = {"L 84 static const char *wm8731_input_select[] = {"Line In", "Mic"}; 62 85 63 static SOC_ENUM_SINGLE_DECL(wm8731_insel_enum, 86 static SOC_ENUM_SINGLE_DECL(wm8731_insel_enum, 64 WM8731_APANA, 2, w 87 WM8731_APANA, 2, wm8731_input_select); 65 88 66 static int wm8731_deemph[] = { 0, 32000, 44100 89 static int wm8731_deemph[] = { 0, 32000, 44100, 48000 }; 67 90 68 static int wm8731_set_deemph(struct snd_soc_co 91 static int wm8731_set_deemph(struct snd_soc_component *component) 69 { 92 { 70 struct wm8731_priv *wm8731 = snd_soc_c 93 struct wm8731_priv *wm8731 = snd_soc_component_get_drvdata(component); 71 int val, i, best; 94 int val, i, best; 72 95 73 /* If we're using deemphasis select th 96 /* If we're using deemphasis select the nearest available sample 74 * rate. 97 * rate. 75 */ 98 */ 76 if (wm8731->deemph) { 99 if (wm8731->deemph) { 77 best = 1; 100 best = 1; 78 for (i = 2; i < ARRAY_SIZE(wm8 101 for (i = 2; i < ARRAY_SIZE(wm8731_deemph); i++) { 79 if (abs(wm8731_deemph[ 102 if (abs(wm8731_deemph[i] - wm8731->playback_fs) < 80 abs(wm8731_deemph[ 103 abs(wm8731_deemph[best] - wm8731->playback_fs)) 81 best = i; 104 best = i; 82 } 105 } 83 106 84 val = best << 1; 107 val = best << 1; 85 } else { 108 } else { 86 best = 0; 109 best = 0; 87 val = 0; 110 val = 0; 88 } 111 } 89 112 90 dev_dbg(component->dev, "Set deemphasi 113 dev_dbg(component->dev, "Set deemphasis %d (%dHz)\n", 91 best, wm8731_deemph[best]); 114 best, wm8731_deemph[best]); 92 115 93 return snd_soc_component_update_bits(c 116 return snd_soc_component_update_bits(component, WM8731_APDIGI, 0x6, val); 94 } 117 } 95 118 96 static int wm8731_get_deemph(struct snd_kcontr 119 static int wm8731_get_deemph(struct snd_kcontrol *kcontrol, 97 struct snd_ctl_el 120 struct snd_ctl_elem_value *ucontrol) 98 { 121 { 99 struct snd_soc_component *component = 122 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); 100 struct wm8731_priv *wm8731 = snd_soc_c 123 struct wm8731_priv *wm8731 = snd_soc_component_get_drvdata(component); 101 124 102 ucontrol->value.integer.value[0] = wm8 125 ucontrol->value.integer.value[0] = wm8731->deemph; 103 126 104 return 0; 127 return 0; 105 } 128 } 106 129 107 static int wm8731_put_deemph(struct snd_kcontr 130 static int wm8731_put_deemph(struct snd_kcontrol *kcontrol, 108 struct snd_ctl_el 131 struct snd_ctl_elem_value *ucontrol) 109 { 132 { 110 struct snd_soc_component *component = 133 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); 111 struct wm8731_priv *wm8731 = snd_soc_c 134 struct wm8731_priv *wm8731 = snd_soc_component_get_drvdata(component); 112 unsigned int deemph = ucontrol->value. 135 unsigned int deemph = ucontrol->value.integer.value[0]; 113 int ret = 0; 136 int ret = 0; 114 137 115 if (deemph > 1) 138 if (deemph > 1) 116 return -EINVAL; 139 return -EINVAL; 117 140 118 mutex_lock(&wm8731->lock); 141 mutex_lock(&wm8731->lock); 119 if (wm8731->deemph != deemph) { 142 if (wm8731->deemph != deemph) { 120 wm8731->deemph = deemph; 143 wm8731->deemph = deemph; 121 144 122 wm8731_set_deemph(component); 145 wm8731_set_deemph(component); 123 146 124 ret = 1; 147 ret = 1; 125 } 148 } 126 mutex_unlock(&wm8731->lock); 149 mutex_unlock(&wm8731->lock); 127 150 128 return ret; 151 return ret; 129 } 152 } 130 153 131 static const DECLARE_TLV_DB_SCALE(in_tlv, -345 154 static const DECLARE_TLV_DB_SCALE(in_tlv, -3450, 150, 0); 132 static const DECLARE_TLV_DB_SCALE(sidetone_tlv 155 static const DECLARE_TLV_DB_SCALE(sidetone_tlv, -1500, 300, 0); 133 static const DECLARE_TLV_DB_SCALE(out_tlv, -12 156 static const DECLARE_TLV_DB_SCALE(out_tlv, -12100, 100, 1); 134 static const DECLARE_TLV_DB_SCALE(mic_tlv, 0, 157 static const DECLARE_TLV_DB_SCALE(mic_tlv, 0, 2000, 0); 135 158 136 static const struct snd_kcontrol_new wm8731_sn 159 static const struct snd_kcontrol_new wm8731_snd_controls[] = { 137 160 138 SOC_DOUBLE_R_TLV("Master Playback Volume", WM8 161 SOC_DOUBLE_R_TLV("Master Playback Volume", WM8731_LOUT1V, WM8731_ROUT1V, 139 0, 127, 0, out_tlv), 162 0, 127, 0, out_tlv), 140 SOC_DOUBLE_R("Master Playback ZC Switch", WM87 163 SOC_DOUBLE_R("Master Playback ZC Switch", WM8731_LOUT1V, WM8731_ROUT1V, 141 7, 1, 0), 164 7, 1, 0), 142 165 143 SOC_DOUBLE_R_TLV("Capture Volume", WM8731_LINV 166 SOC_DOUBLE_R_TLV("Capture Volume", WM8731_LINVOL, WM8731_RINVOL, 0, 31, 0, 144 in_tlv), 167 in_tlv), 145 SOC_DOUBLE_R("Line Capture Switch", WM8731_LIN 168 SOC_DOUBLE_R("Line Capture Switch", WM8731_LINVOL, WM8731_RINVOL, 7, 1, 1), 146 169 147 SOC_SINGLE_TLV("Mic Boost Volume", WM8731_APAN 170 SOC_SINGLE_TLV("Mic Boost Volume", WM8731_APANA, 0, 1, 0, mic_tlv), 148 SOC_SINGLE("Mic Capture Switch", WM8731_APANA, 171 SOC_SINGLE("Mic Capture Switch", WM8731_APANA, 1, 1, 1), 149 172 150 SOC_SINGLE_TLV("Sidetone Playback Volume", WM8 173 SOC_SINGLE_TLV("Sidetone Playback Volume", WM8731_APANA, 6, 3, 1, 151 sidetone_tlv), 174 sidetone_tlv), 152 175 153 SOC_SINGLE("ADC High Pass Filter Switch", WM87 176 SOC_SINGLE("ADC High Pass Filter Switch", WM8731_APDIGI, 0, 1, 1), 154 SOC_SINGLE("Store DC Offset Switch", WM8731_AP 177 SOC_SINGLE("Store DC Offset Switch", WM8731_APDIGI, 4, 1, 0), 155 178 156 SOC_SINGLE_BOOL_EXT("Playback Deemphasis Switc 179 SOC_SINGLE_BOOL_EXT("Playback Deemphasis Switch", 0, 157 wm8731_get_deemph, wm8731_ 180 wm8731_get_deemph, wm8731_put_deemph), 158 }; 181 }; 159 182 160 /* Output Mixer */ 183 /* Output Mixer */ 161 static const struct snd_kcontrol_new wm8731_ou 184 static const struct snd_kcontrol_new wm8731_output_mixer_controls[] = { 162 SOC_DAPM_SINGLE("Line Bypass Switch", WM8731_A 185 SOC_DAPM_SINGLE("Line Bypass Switch", WM8731_APANA, 3, 1, 0), 163 SOC_DAPM_SINGLE("Mic Sidetone Switch", WM8731_ 186 SOC_DAPM_SINGLE("Mic Sidetone Switch", WM8731_APANA, 5, 1, 0), 164 SOC_DAPM_SINGLE("HiFi Playback Switch", WM8731 187 SOC_DAPM_SINGLE("HiFi Playback Switch", WM8731_APANA, 4, 1, 0), 165 }; 188 }; 166 189 167 /* Input mux */ 190 /* Input mux */ 168 static const struct snd_kcontrol_new wm8731_in 191 static const struct snd_kcontrol_new wm8731_input_mux_controls = 169 SOC_DAPM_ENUM("Input Select", wm8731_insel_enu 192 SOC_DAPM_ENUM("Input Select", wm8731_insel_enum); 170 193 171 static const struct snd_soc_dapm_widget wm8731 194 static const struct snd_soc_dapm_widget wm8731_dapm_widgets[] = { 172 SND_SOC_DAPM_SUPPLY("ACTIVE",WM8731_ACTIVE, 0, 195 SND_SOC_DAPM_SUPPLY("ACTIVE",WM8731_ACTIVE, 0, 0, NULL, 0), 173 SND_SOC_DAPM_SUPPLY("OSC", WM8731_PWR, 5, 1, N 196 SND_SOC_DAPM_SUPPLY("OSC", WM8731_PWR, 5, 1, NULL, 0), 174 SND_SOC_DAPM_MIXER("Output Mixer", WM8731_PWR, 197 SND_SOC_DAPM_MIXER("Output Mixer", WM8731_PWR, 4, 1, 175 &wm8731_output_mixer_controls[0], 198 &wm8731_output_mixer_controls[0], 176 ARRAY_SIZE(wm8731_output_mixer_control 199 ARRAY_SIZE(wm8731_output_mixer_controls)), 177 SND_SOC_DAPM_DAC("DAC", "HiFi Playback", WM873 200 SND_SOC_DAPM_DAC("DAC", "HiFi Playback", WM8731_PWR, 3, 1), 178 SND_SOC_DAPM_OUTPUT("LOUT"), 201 SND_SOC_DAPM_OUTPUT("LOUT"), 179 SND_SOC_DAPM_OUTPUT("LHPOUT"), 202 SND_SOC_DAPM_OUTPUT("LHPOUT"), 180 SND_SOC_DAPM_OUTPUT("ROUT"), 203 SND_SOC_DAPM_OUTPUT("ROUT"), 181 SND_SOC_DAPM_OUTPUT("RHPOUT"), 204 SND_SOC_DAPM_OUTPUT("RHPOUT"), 182 SND_SOC_DAPM_ADC("ADC", "HiFi Capture", WM8731 205 SND_SOC_DAPM_ADC("ADC", "HiFi Capture", WM8731_PWR, 2, 1), 183 SND_SOC_DAPM_MUX("Input Mux", SND_SOC_NOPM, 0, 206 SND_SOC_DAPM_MUX("Input Mux", SND_SOC_NOPM, 0, 0, &wm8731_input_mux_controls), 184 SND_SOC_DAPM_PGA("Line Input", WM8731_PWR, 0, 207 SND_SOC_DAPM_PGA("Line Input", WM8731_PWR, 0, 1, NULL, 0), 185 SND_SOC_DAPM_MICBIAS("Mic Bias", WM8731_PWR, 1 208 SND_SOC_DAPM_MICBIAS("Mic Bias", WM8731_PWR, 1, 1), 186 SND_SOC_DAPM_INPUT("MICIN"), 209 SND_SOC_DAPM_INPUT("MICIN"), 187 SND_SOC_DAPM_INPUT("RLINEIN"), 210 SND_SOC_DAPM_INPUT("RLINEIN"), 188 SND_SOC_DAPM_INPUT("LLINEIN"), 211 SND_SOC_DAPM_INPUT("LLINEIN"), 189 }; 212 }; 190 213 191 static int wm8731_check_osc(struct snd_soc_dap 214 static int wm8731_check_osc(struct snd_soc_dapm_widget *source, 192 struct snd_soc_dap 215 struct snd_soc_dapm_widget *sink) 193 { 216 { 194 struct snd_soc_component *component = 217 struct snd_soc_component *component = snd_soc_dapm_to_component(source->dapm); 195 struct wm8731_priv *wm8731 = snd_soc_c 218 struct wm8731_priv *wm8731 = snd_soc_component_get_drvdata(component); 196 219 197 return wm8731->sysclk_type == WM8731_S 220 return wm8731->sysclk_type == WM8731_SYSCLK_XTAL; 198 } 221 } 199 222 200 static const struct snd_soc_dapm_route wm8731_ 223 static const struct snd_soc_dapm_route wm8731_intercon[] = { 201 {"DAC", NULL, "OSC", wm8731_check_osc} 224 {"DAC", NULL, "OSC", wm8731_check_osc}, 202 {"ADC", NULL, "OSC", wm8731_check_osc} 225 {"ADC", NULL, "OSC", wm8731_check_osc}, 203 {"DAC", NULL, "ACTIVE"}, 226 {"DAC", NULL, "ACTIVE"}, 204 {"ADC", NULL, "ACTIVE"}, 227 {"ADC", NULL, "ACTIVE"}, 205 228 206 /* output mixer */ 229 /* output mixer */ 207 {"Output Mixer", "Line Bypass Switch", 230 {"Output Mixer", "Line Bypass Switch", "Line Input"}, 208 {"Output Mixer", "HiFi Playback Switch 231 {"Output Mixer", "HiFi Playback Switch", "DAC"}, 209 {"Output Mixer", "Mic Sidetone Switch" 232 {"Output Mixer", "Mic Sidetone Switch", "Mic Bias"}, 210 233 211 /* outputs */ 234 /* outputs */ 212 {"RHPOUT", NULL, "Output Mixer"}, 235 {"RHPOUT", NULL, "Output Mixer"}, 213 {"ROUT", NULL, "Output Mixer"}, 236 {"ROUT", NULL, "Output Mixer"}, 214 {"LHPOUT", NULL, "Output Mixer"}, 237 {"LHPOUT", NULL, "Output Mixer"}, 215 {"LOUT", NULL, "Output Mixer"}, 238 {"LOUT", NULL, "Output Mixer"}, 216 239 217 /* input mux */ 240 /* input mux */ 218 {"Input Mux", "Line In", "Line Input"} 241 {"Input Mux", "Line In", "Line Input"}, 219 {"Input Mux", "Mic", "Mic Bias"}, 242 {"Input Mux", "Mic", "Mic Bias"}, 220 {"ADC", NULL, "Input Mux"}, 243 {"ADC", NULL, "Input Mux"}, 221 244 222 /* inputs */ 245 /* inputs */ 223 {"Line Input", NULL, "LLINEIN"}, 246 {"Line Input", NULL, "LLINEIN"}, 224 {"Line Input", NULL, "RLINEIN"}, 247 {"Line Input", NULL, "RLINEIN"}, 225 {"Mic Bias", NULL, "MICIN"}, 248 {"Mic Bias", NULL, "MICIN"}, 226 }; 249 }; 227 250 228 struct _coeff_div { 251 struct _coeff_div { 229 u32 mclk; 252 u32 mclk; 230 u32 rate; 253 u32 rate; 231 u16 fs; 254 u16 fs; 232 u8 sr:4; 255 u8 sr:4; 233 u8 bosr:1; 256 u8 bosr:1; 234 u8 usb:1; 257 u8 usb:1; 235 }; 258 }; 236 259 237 /* codec mclk clock divider coefficients */ 260 /* codec mclk clock divider coefficients */ 238 static const struct _coeff_div coeff_div[] = { 261 static const struct _coeff_div coeff_div[] = { 239 /* 48k */ 262 /* 48k */ 240 {12288000, 48000, 256, 0x0, 0x0, 0x0}, 263 {12288000, 48000, 256, 0x0, 0x0, 0x0}, 241 {18432000, 48000, 384, 0x0, 0x1, 0x0}, 264 {18432000, 48000, 384, 0x0, 0x1, 0x0}, 242 {12000000, 48000, 250, 0x0, 0x0, 0x1}, 265 {12000000, 48000, 250, 0x0, 0x0, 0x1}, 243 266 244 /* 32k */ 267 /* 32k */ 245 {12288000, 32000, 384, 0x6, 0x0, 0x0}, 268 {12288000, 32000, 384, 0x6, 0x0, 0x0}, 246 {18432000, 32000, 576, 0x6, 0x1, 0x0}, 269 {18432000, 32000, 576, 0x6, 0x1, 0x0}, 247 {12000000, 32000, 375, 0x6, 0x0, 0x1}, 270 {12000000, 32000, 375, 0x6, 0x0, 0x1}, 248 271 249 /* 8k */ 272 /* 8k */ 250 {12288000, 8000, 1536, 0x3, 0x0, 0x0}, 273 {12288000, 8000, 1536, 0x3, 0x0, 0x0}, 251 {18432000, 8000, 2304, 0x3, 0x1, 0x0}, 274 {18432000, 8000, 2304, 0x3, 0x1, 0x0}, 252 {11289600, 8000, 1408, 0xb, 0x0, 0x0}, 275 {11289600, 8000, 1408, 0xb, 0x0, 0x0}, 253 {16934400, 8000, 2112, 0xb, 0x1, 0x0}, 276 {16934400, 8000, 2112, 0xb, 0x1, 0x0}, 254 {12000000, 8000, 1500, 0x3, 0x0, 0x1}, 277 {12000000, 8000, 1500, 0x3, 0x0, 0x1}, 255 278 256 /* 96k */ 279 /* 96k */ 257 {12288000, 96000, 128, 0x7, 0x0, 0x0}, 280 {12288000, 96000, 128, 0x7, 0x0, 0x0}, 258 {18432000, 96000, 192, 0x7, 0x1, 0x0}, 281 {18432000, 96000, 192, 0x7, 0x1, 0x0}, 259 {12000000, 96000, 125, 0x7, 0x0, 0x1}, 282 {12000000, 96000, 125, 0x7, 0x0, 0x1}, 260 283 261 /* 44.1k */ 284 /* 44.1k */ 262 {11289600, 44100, 256, 0x8, 0x0, 0x0}, 285 {11289600, 44100, 256, 0x8, 0x0, 0x0}, 263 {16934400, 44100, 384, 0x8, 0x1, 0x0}, 286 {16934400, 44100, 384, 0x8, 0x1, 0x0}, 264 {12000000, 44100, 272, 0x8, 0x1, 0x1}, 287 {12000000, 44100, 272, 0x8, 0x1, 0x1}, 265 288 266 /* 88.2k */ 289 /* 88.2k */ 267 {11289600, 88200, 128, 0xf, 0x0, 0x0}, 290 {11289600, 88200, 128, 0xf, 0x0, 0x0}, 268 {16934400, 88200, 192, 0xf, 0x1, 0x0}, 291 {16934400, 88200, 192, 0xf, 0x1, 0x0}, 269 {12000000, 88200, 136, 0xf, 0x1, 0x1}, 292 {12000000, 88200, 136, 0xf, 0x1, 0x1}, 270 }; 293 }; 271 294 272 /* rates constraints */ 295 /* rates constraints */ 273 static const unsigned int wm8731_rates_1200000 296 static const unsigned int wm8731_rates_12000000[] = { 274 8000, 32000, 44100, 48000, 96000, 8820 297 8000, 32000, 44100, 48000, 96000, 88200, 275 }; 298 }; 276 299 277 static const unsigned int wm8731_rates_1228800 300 static const unsigned int wm8731_rates_12288000_18432000[] = { 278 8000, 32000, 48000, 96000, 301 8000, 32000, 48000, 96000, 279 }; 302 }; 280 303 281 static const unsigned int wm8731_rates_1128960 304 static const unsigned int wm8731_rates_11289600_16934400[] = { 282 8000, 44100, 88200, 305 8000, 44100, 88200, 283 }; 306 }; 284 307 285 static const struct snd_pcm_hw_constraint_list 308 static const struct snd_pcm_hw_constraint_list wm8731_constraints_12000000 = { 286 .list = wm8731_rates_12000000, 309 .list = wm8731_rates_12000000, 287 .count = ARRAY_SIZE(wm8731_rates_12000 310 .count = ARRAY_SIZE(wm8731_rates_12000000), 288 }; 311 }; 289 312 290 static const 313 static const 291 struct snd_pcm_hw_constraint_list wm8731_const 314 struct snd_pcm_hw_constraint_list wm8731_constraints_12288000_18432000 = { 292 .list = wm8731_rates_12288000_18432000 315 .list = wm8731_rates_12288000_18432000, 293 .count = ARRAY_SIZE(wm8731_rates_12288 316 .count = ARRAY_SIZE(wm8731_rates_12288000_18432000), 294 }; 317 }; 295 318 296 static const 319 static const 297 struct snd_pcm_hw_constraint_list wm8731_const 320 struct snd_pcm_hw_constraint_list wm8731_constraints_11289600_16934400 = { 298 .list = wm8731_rates_11289600_16934400 321 .list = wm8731_rates_11289600_16934400, 299 .count = ARRAY_SIZE(wm8731_rates_11289 322 .count = ARRAY_SIZE(wm8731_rates_11289600_16934400), 300 }; 323 }; 301 324 302 static inline int get_coeff(int mclk, int rate 325 static inline int get_coeff(int mclk, int rate) 303 { 326 { 304 int i; 327 int i; 305 328 306 for (i = 0; i < ARRAY_SIZE(coeff_div); 329 for (i = 0; i < ARRAY_SIZE(coeff_div); i++) { 307 if (coeff_div[i].rate == rate 330 if (coeff_div[i].rate == rate && coeff_div[i].mclk == mclk) 308 return i; 331 return i; 309 } 332 } 310 return 0; 333 return 0; 311 } 334 } 312 335 313 static int wm8731_hw_params(struct snd_pcm_sub 336 static int wm8731_hw_params(struct snd_pcm_substream *substream, 314 struct snd_pcm_hw_ 337 struct snd_pcm_hw_params *params, 315 struct snd_soc_dai 338 struct snd_soc_dai *dai) 316 { 339 { 317 struct snd_soc_component *component = 340 struct snd_soc_component *component = dai->component; 318 struct wm8731_priv *wm8731 = snd_soc_c 341 struct wm8731_priv *wm8731 = snd_soc_component_get_drvdata(component); 319 u16 iface = snd_soc_component_read(com !! 342 u16 iface = snd_soc_component_read32(component, WM8731_IFACE) & 0xfff3; 320 int i = get_coeff(wm8731->sysclk, para 343 int i = get_coeff(wm8731->sysclk, params_rate(params)); 321 u16 srate = (coeff_div[i].sr << 2) | 344 u16 srate = (coeff_div[i].sr << 2) | 322 (coeff_div[i].bosr << 1) | coe 345 (coeff_div[i].bosr << 1) | coeff_div[i].usb; 323 346 324 wm8731->playback_fs = params_rate(para 347 wm8731->playback_fs = params_rate(params); 325 348 326 snd_soc_component_write(component, WM8 349 snd_soc_component_write(component, WM8731_SRATE, srate); 327 350 328 /* bit size */ 351 /* bit size */ 329 switch (params_width(params)) { 352 switch (params_width(params)) { 330 case 16: 353 case 16: 331 break; 354 break; 332 case 20: 355 case 20: 333 iface |= 0x0004; 356 iface |= 0x0004; 334 break; 357 break; 335 case 24: 358 case 24: 336 iface |= 0x0008; 359 iface |= 0x0008; 337 break; 360 break; 338 case 32: 361 case 32: 339 iface |= 0x000c; 362 iface |= 0x000c; 340 break; 363 break; 341 } 364 } 342 365 343 wm8731_set_deemph(component); 366 wm8731_set_deemph(component); 344 367 345 snd_soc_component_write(component, WM8 368 snd_soc_component_write(component, WM8731_IFACE, iface); 346 return 0; 369 return 0; 347 } 370 } 348 371 349 static int wm8731_mute(struct snd_soc_dai *dai !! 372 static int wm8731_mute(struct snd_soc_dai *dai, int mute) 350 { 373 { 351 struct snd_soc_component *component = 374 struct snd_soc_component *component = dai->component; 352 u16 mute_reg = snd_soc_component_read( !! 375 u16 mute_reg = snd_soc_component_read32(component, WM8731_APDIGI) & 0xfff7; 353 376 354 if (mute) 377 if (mute) 355 snd_soc_component_write(compon 378 snd_soc_component_write(component, WM8731_APDIGI, mute_reg | 0x8); 356 else 379 else 357 snd_soc_component_write(compon 380 snd_soc_component_write(component, WM8731_APDIGI, mute_reg); 358 return 0; 381 return 0; 359 } 382 } 360 383 361 static int wm8731_set_dai_sysclk(struct snd_so 384 static int wm8731_set_dai_sysclk(struct snd_soc_dai *codec_dai, 362 int clk_id, unsigned int freq, 385 int clk_id, unsigned int freq, int dir) 363 { 386 { 364 struct snd_soc_component *component = 387 struct snd_soc_component *component = codec_dai->component; 365 struct snd_soc_dapm_context *dapm = sn 388 struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); 366 struct wm8731_priv *wm8731 = snd_soc_c 389 struct wm8731_priv *wm8731 = snd_soc_component_get_drvdata(component); 367 390 368 switch (clk_id) { 391 switch (clk_id) { 369 case WM8731_SYSCLK_XTAL: 392 case WM8731_SYSCLK_XTAL: 370 case WM8731_SYSCLK_MCLK: 393 case WM8731_SYSCLK_MCLK: 371 if (wm8731->mclk && clk_set_ra 394 if (wm8731->mclk && clk_set_rate(wm8731->mclk, freq)) 372 return -EINVAL; 395 return -EINVAL; 373 wm8731->sysclk_type = clk_id; 396 wm8731->sysclk_type = clk_id; 374 break; 397 break; 375 default: 398 default: 376 return -EINVAL; 399 return -EINVAL; 377 } 400 } 378 401 379 switch (freq) { 402 switch (freq) { 380 case 0: 403 case 0: 381 wm8731->constraints = NULL; 404 wm8731->constraints = NULL; 382 break; 405 break; 383 case 12000000: 406 case 12000000: 384 wm8731->constraints = &wm8731_ 407 wm8731->constraints = &wm8731_constraints_12000000; 385 break; 408 break; 386 case 12288000: 409 case 12288000: 387 case 18432000: 410 case 18432000: 388 wm8731->constraints = &wm8731_ 411 wm8731->constraints = &wm8731_constraints_12288000_18432000; 389 break; 412 break; 390 case 16934400: 413 case 16934400: 391 case 11289600: 414 case 11289600: 392 wm8731->constraints = &wm8731_ 415 wm8731->constraints = &wm8731_constraints_11289600_16934400; 393 break; 416 break; 394 default: 417 default: 395 return -EINVAL; 418 return -EINVAL; 396 } 419 } 397 420 398 wm8731->sysclk = freq; 421 wm8731->sysclk = freq; 399 422 400 snd_soc_dapm_sync(dapm); 423 snd_soc_dapm_sync(dapm); 401 424 402 return 0; 425 return 0; 403 } 426 } 404 427 405 428 406 static int wm8731_set_dai_fmt(struct snd_soc_d 429 static int wm8731_set_dai_fmt(struct snd_soc_dai *codec_dai, 407 unsigned int fmt) 430 unsigned int fmt) 408 { 431 { 409 struct snd_soc_component *component = 432 struct snd_soc_component *component = codec_dai->component; 410 u16 iface = 0; 433 u16 iface = 0; 411 434 412 switch (fmt & SND_SOC_DAIFMT_CLOCK_PRO !! 435 /* set master/slave audio interface */ 413 case SND_SOC_DAIFMT_CBP_CFP: !! 436 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { >> 437 case SND_SOC_DAIFMT_CBM_CFM: 414 iface |= 0x0040; 438 iface |= 0x0040; 415 break; 439 break; 416 case SND_SOC_DAIFMT_CBC_CFC: !! 440 case SND_SOC_DAIFMT_CBS_CFS: 417 break; 441 break; 418 default: 442 default: 419 return -EINVAL; 443 return -EINVAL; 420 } 444 } 421 445 422 /* interface format */ 446 /* interface format */ 423 switch (fmt & SND_SOC_DAIFMT_FORMAT_MA 447 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { 424 case SND_SOC_DAIFMT_I2S: 448 case SND_SOC_DAIFMT_I2S: 425 iface |= 0x0002; 449 iface |= 0x0002; 426 break; 450 break; 427 case SND_SOC_DAIFMT_RIGHT_J: 451 case SND_SOC_DAIFMT_RIGHT_J: 428 break; 452 break; 429 case SND_SOC_DAIFMT_LEFT_J: 453 case SND_SOC_DAIFMT_LEFT_J: 430 iface |= 0x0001; 454 iface |= 0x0001; 431 break; 455 break; 432 case SND_SOC_DAIFMT_DSP_A: 456 case SND_SOC_DAIFMT_DSP_A: 433 iface |= 0x0013; 457 iface |= 0x0013; 434 break; 458 break; 435 case SND_SOC_DAIFMT_DSP_B: 459 case SND_SOC_DAIFMT_DSP_B: 436 iface |= 0x0003; 460 iface |= 0x0003; 437 break; 461 break; 438 default: 462 default: 439 return -EINVAL; 463 return -EINVAL; 440 } 464 } 441 465 442 /* clock inversion */ 466 /* clock inversion */ 443 switch (fmt & SND_SOC_DAIFMT_INV_MASK) 467 switch (fmt & SND_SOC_DAIFMT_INV_MASK) { 444 case SND_SOC_DAIFMT_NB_NF: 468 case SND_SOC_DAIFMT_NB_NF: 445 break; 469 break; 446 case SND_SOC_DAIFMT_IB_IF: 470 case SND_SOC_DAIFMT_IB_IF: 447 iface |= 0x0090; 471 iface |= 0x0090; 448 break; 472 break; 449 case SND_SOC_DAIFMT_IB_NF: 473 case SND_SOC_DAIFMT_IB_NF: 450 iface |= 0x0080; 474 iface |= 0x0080; 451 break; 475 break; 452 case SND_SOC_DAIFMT_NB_IF: 476 case SND_SOC_DAIFMT_NB_IF: 453 iface |= 0x0010; 477 iface |= 0x0010; 454 break; 478 break; 455 default: 479 default: 456 return -EINVAL; 480 return -EINVAL; 457 } 481 } 458 482 459 /* set iface */ 483 /* set iface */ 460 snd_soc_component_write(component, WM8 484 snd_soc_component_write(component, WM8731_IFACE, iface); 461 return 0; 485 return 0; 462 } 486 } 463 487 464 static int wm8731_set_bias_level(struct snd_so 488 static int wm8731_set_bias_level(struct snd_soc_component *component, 465 enum snd_soc_ 489 enum snd_soc_bias_level level) 466 { 490 { 467 struct wm8731_priv *wm8731 = snd_soc_c 491 struct wm8731_priv *wm8731 = snd_soc_component_get_drvdata(component); 468 int ret; 492 int ret; 469 u16 reg; 493 u16 reg; 470 494 471 switch (level) { 495 switch (level) { 472 case SND_SOC_BIAS_ON: 496 case SND_SOC_BIAS_ON: 473 if (wm8731->mclk) { 497 if (wm8731->mclk) { 474 ret = clk_prepare_enab 498 ret = clk_prepare_enable(wm8731->mclk); 475 if (ret) 499 if (ret) 476 return ret; 500 return ret; 477 } 501 } 478 break; 502 break; 479 case SND_SOC_BIAS_PREPARE: 503 case SND_SOC_BIAS_PREPARE: 480 break; 504 break; 481 case SND_SOC_BIAS_STANDBY: 505 case SND_SOC_BIAS_STANDBY: 482 if (snd_soc_component_get_bias 506 if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_OFF) { 483 ret = regulator_bulk_e 507 ret = regulator_bulk_enable(ARRAY_SIZE(wm8731->supplies), 484 508 wm8731->supplies); 485 if (ret != 0) 509 if (ret != 0) 486 return ret; 510 return ret; 487 511 488 regcache_sync(wm8731-> 512 regcache_sync(wm8731->regmap); 489 } 513 } 490 514 491 /* Clear PWROFF, gate CLKOUT, 515 /* Clear PWROFF, gate CLKOUT, everything else as-is */ 492 reg = snd_soc_component_read(c !! 516 reg = snd_soc_component_read32(component, WM8731_PWR) & 0xff7f; 493 snd_soc_component_write(compon 517 snd_soc_component_write(component, WM8731_PWR, reg | 0x0040); 494 break; 518 break; 495 case SND_SOC_BIAS_OFF: 519 case SND_SOC_BIAS_OFF: 496 if (wm8731->mclk) 520 if (wm8731->mclk) 497 clk_disable_unprepare( 521 clk_disable_unprepare(wm8731->mclk); 498 snd_soc_component_write(compon 522 snd_soc_component_write(component, WM8731_PWR, 0xffff); 499 regulator_bulk_disable(ARRAY_S 523 regulator_bulk_disable(ARRAY_SIZE(wm8731->supplies), 500 wm8731- 524 wm8731->supplies); 501 regcache_mark_dirty(wm8731->re 525 regcache_mark_dirty(wm8731->regmap); 502 break; 526 break; 503 } 527 } 504 return 0; 528 return 0; 505 } 529 } 506 530 507 static int wm8731_startup(struct snd_pcm_subst 531 static int wm8731_startup(struct snd_pcm_substream *substream, 508 struct snd_soc_dai *dai) 532 struct snd_soc_dai *dai) 509 { 533 { 510 struct wm8731_priv *wm8731 = snd_soc_c 534 struct wm8731_priv *wm8731 = snd_soc_component_get_drvdata(dai->component); 511 535 512 if (wm8731->constraints) 536 if (wm8731->constraints) 513 snd_pcm_hw_constraint_list(sub 537 snd_pcm_hw_constraint_list(substream->runtime, 0, 514 SND 538 SNDRV_PCM_HW_PARAM_RATE, 515 wm8 539 wm8731->constraints); 516 540 517 return 0; 541 return 0; 518 } 542 } 519 543 520 #define WM8731_RATES SNDRV_PCM_RATE_8000_96000 544 #define WM8731_RATES SNDRV_PCM_RATE_8000_96000 521 545 522 #define WM8731_FORMATS (SNDRV_PCM_FMTBIT_S16_L 546 #define WM8731_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ 523 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FM 547 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE) 524 548 525 static const struct snd_soc_dai_ops wm8731_dai 549 static const struct snd_soc_dai_ops wm8731_dai_ops = { 526 .startup = wm8731_startup, 550 .startup = wm8731_startup, 527 .hw_params = wm8731_hw_params, 551 .hw_params = wm8731_hw_params, 528 .mute_stream = wm8731_mute, !! 552 .digital_mute = wm8731_mute, 529 .set_sysclk = wm8731_set_dai_syscl 553 .set_sysclk = wm8731_set_dai_sysclk, 530 .set_fmt = wm8731_set_dai_fmt, 554 .set_fmt = wm8731_set_dai_fmt, 531 .no_capture_mute = 1, << 532 }; 555 }; 533 556 534 static struct snd_soc_dai_driver wm8731_dai = 557 static struct snd_soc_dai_driver wm8731_dai = { 535 .name = "wm8731-hifi", 558 .name = "wm8731-hifi", 536 .playback = { 559 .playback = { 537 .stream_name = "Playback", 560 .stream_name = "Playback", 538 .channels_min = 1, 561 .channels_min = 1, 539 .channels_max = 2, 562 .channels_max = 2, 540 .rates = WM8731_RATES, 563 .rates = WM8731_RATES, 541 .formats = WM8731_FORMATS,}, 564 .formats = WM8731_FORMATS,}, 542 .capture = { 565 .capture = { 543 .stream_name = "Capture", 566 .stream_name = "Capture", 544 .channels_min = 1, 567 .channels_min = 1, 545 .channels_max = 2, 568 .channels_max = 2, 546 .rates = WM8731_RATES, 569 .rates = WM8731_RATES, 547 .formats = WM8731_FORMATS,}, 570 .formats = WM8731_FORMATS,}, 548 .ops = &wm8731_dai_ops, 571 .ops = &wm8731_dai_ops, 549 .symmetric_rate = 1, !! 572 .symmetric_rates = 1, 550 }; << 551 << 552 static const struct snd_soc_component_driver s << 553 .set_bias_level = wm8731_set_b << 554 .controls = wm8731_snd_c << 555 .num_controls = ARRAY_SIZE(w << 556 .dapm_widgets = wm8731_dapm_ << 557 .num_dapm_widgets = ARRAY_SIZE(w << 558 .dapm_routes = wm8731_inter << 559 .num_dapm_routes = ARRAY_SIZE(w << 560 .suspend_bias_off = 1, << 561 .idle_bias_on = 1, << 562 .use_pmdown_time = 1, << 563 .endianness = 1, << 564 }; 573 }; 565 574 566 int wm8731_init(struct device *dev, struct wm8 !! 575 static int wm8731_request_supplies(struct device *dev, >> 576 struct wm8731_priv *wm8731) 567 { 577 { 568 int ret = 0, i; 578 int ret = 0, i; 569 579 570 wm8731->mclk = devm_clk_get(dev, "mclk << 571 if (IS_ERR(wm8731->mclk)) { << 572 ret = PTR_ERR(wm8731->mclk); << 573 if (ret == -ENOENT) { << 574 wm8731->mclk = NULL; << 575 dev_warn(dev, "Assumin << 576 } else { << 577 dev_err(dev, "Failed t << 578 return ret; << 579 } << 580 } << 581 << 582 mutex_init(&wm8731->lock); << 583 << 584 for (i = 0; i < ARRAY_SIZE(wm8731->sup 580 for (i = 0; i < ARRAY_SIZE(wm8731->supplies); i++) 585 wm8731->supplies[i].supply = w 581 wm8731->supplies[i].supply = wm8731_supply_names[i]; 586 582 587 ret = devm_regulator_bulk_get(dev, ARR 583 ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(wm8731->supplies), 588 wm8731->suppl 584 wm8731->supplies); 589 if (ret != 0) { 585 if (ret != 0) { 590 dev_err(dev, "Failed to reques 586 dev_err(dev, "Failed to request supplies: %d\n", ret); 591 return ret; 587 return ret; 592 } 588 } 593 589 594 ret = regulator_bulk_enable(ARRAY_SIZE 590 ret = regulator_bulk_enable(ARRAY_SIZE(wm8731->supplies), 595 wm8731->su 591 wm8731->supplies); 596 if (ret != 0) { 592 if (ret != 0) { 597 dev_err(dev, "Failed to enable 593 dev_err(dev, "Failed to enable supplies: %d\n", ret); 598 return ret; 594 return ret; 599 } 595 } 600 596 >> 597 return 0; >> 598 } >> 599 >> 600 static int wm8731_hw_init(struct device *dev, struct wm8731_priv *wm8731) >> 601 { >> 602 int ret = 0; >> 603 601 ret = wm8731_reset(wm8731->regmap); 604 ret = wm8731_reset(wm8731->regmap); 602 if (ret < 0) { 605 if (ret < 0) { 603 dev_err(dev, "Failed to issue 606 dev_err(dev, "Failed to issue reset: %d\n", ret); 604 goto err_regulator_enable; 607 goto err_regulator_enable; 605 } 608 } 606 609 607 /* Clear POWEROFF, keep everything els 610 /* Clear POWEROFF, keep everything else disabled */ 608 regmap_write(wm8731->regmap, WM8731_PW 611 regmap_write(wm8731->regmap, WM8731_PWR, 0x7f); 609 612 610 /* Latch the update bits */ 613 /* Latch the update bits */ 611 regmap_update_bits(wm8731->regmap, WM8 614 regmap_update_bits(wm8731->regmap, WM8731_LOUT1V, 0x100, 0); 612 regmap_update_bits(wm8731->regmap, WM8 615 regmap_update_bits(wm8731->regmap, WM8731_ROUT1V, 0x100, 0); 613 regmap_update_bits(wm8731->regmap, WM8 616 regmap_update_bits(wm8731->regmap, WM8731_LINVOL, 0x100, 0); 614 regmap_update_bits(wm8731->regmap, WM8 617 regmap_update_bits(wm8731->regmap, WM8731_RINVOL, 0x100, 0); 615 618 616 /* Disable bypass path by default */ 619 /* Disable bypass path by default */ 617 regmap_update_bits(wm8731->regmap, WM8 620 regmap_update_bits(wm8731->regmap, WM8731_APANA, 0x8, 0); 618 621 619 regcache_mark_dirty(wm8731->regmap); 622 regcache_mark_dirty(wm8731->regmap); 620 623 621 ret = devm_snd_soc_register_component( << 622 &soc_component_dev_wm8 << 623 if (ret != 0) { << 624 dev_err(dev, "Failed to regist << 625 goto err_regulator_enable; << 626 } << 627 << 628 return 0; << 629 << 630 err_regulator_enable: 624 err_regulator_enable: 631 /* Regulators will be enabled by bias 625 /* Regulators will be enabled by bias management */ 632 regulator_bulk_disable(ARRAY_SIZE(wm87 626 regulator_bulk_disable(ARRAY_SIZE(wm8731->supplies), wm8731->supplies); 633 627 634 return ret; 628 return ret; 635 } 629 } 636 EXPORT_SYMBOL_GPL(wm8731_init); << 637 630 638 const struct regmap_config wm8731_regmap = { !! 631 static const struct snd_soc_component_driver soc_component_dev_wm8731 = { >> 632 .set_bias_level = wm8731_set_bias_level, >> 633 .controls = wm8731_snd_controls, >> 634 .num_controls = ARRAY_SIZE(wm8731_snd_controls), >> 635 .dapm_widgets = wm8731_dapm_widgets, >> 636 .num_dapm_widgets = ARRAY_SIZE(wm8731_dapm_widgets), >> 637 .dapm_routes = wm8731_intercon, >> 638 .num_dapm_routes = ARRAY_SIZE(wm8731_intercon), >> 639 .suspend_bias_off = 1, >> 640 .idle_bias_on = 1, >> 641 .use_pmdown_time = 1, >> 642 .endianness = 1, >> 643 .non_legacy_dai_naming = 1, >> 644 }; >> 645 >> 646 static const struct of_device_id wm8731_of_match[] = { >> 647 { .compatible = "wlf,wm8731", }, >> 648 { } >> 649 }; >> 650 >> 651 MODULE_DEVICE_TABLE(of, wm8731_of_match); >> 652 >> 653 static const struct regmap_config wm8731_regmap = { 639 .reg_bits = 7, 654 .reg_bits = 7, 640 .val_bits = 9, 655 .val_bits = 9, 641 656 642 .max_register = WM8731_RESET, 657 .max_register = WM8731_RESET, 643 .volatile_reg = wm8731_volatile, 658 .volatile_reg = wm8731_volatile, 644 659 645 .cache_type = REGCACHE_MAPLE, !! 660 .cache_type = REGCACHE_RBTREE, 646 .reg_defaults = wm8731_reg_defaults, 661 .reg_defaults = wm8731_reg_defaults, 647 .num_reg_defaults = ARRAY_SIZE(wm8731_ 662 .num_reg_defaults = ARRAY_SIZE(wm8731_reg_defaults), 648 }; 663 }; 649 EXPORT_SYMBOL_GPL(wm8731_regmap); !! 664 >> 665 #if defined(CONFIG_SPI_MASTER) >> 666 static int wm8731_spi_probe(struct spi_device *spi) >> 667 { >> 668 struct wm8731_priv *wm8731; >> 669 int ret; >> 670 >> 671 wm8731 = devm_kzalloc(&spi->dev, sizeof(*wm8731), GFP_KERNEL); >> 672 if (wm8731 == NULL) >> 673 return -ENOMEM; >> 674 >> 675 wm8731->mclk = devm_clk_get(&spi->dev, "mclk"); >> 676 if (IS_ERR(wm8731->mclk)) { >> 677 ret = PTR_ERR(wm8731->mclk); >> 678 if (ret == -ENOENT) { >> 679 wm8731->mclk = NULL; >> 680 dev_warn(&spi->dev, "Assuming static MCLK\n"); >> 681 } else { >> 682 dev_err(&spi->dev, "Failed to get MCLK: %d\n", >> 683 ret); >> 684 return ret; >> 685 } >> 686 } >> 687 >> 688 mutex_init(&wm8731->lock); >> 689 >> 690 spi_set_drvdata(spi, wm8731); >> 691 >> 692 ret = wm8731_request_supplies(&spi->dev, wm8731); >> 693 if (ret != 0) >> 694 return ret; >> 695 >> 696 wm8731->regmap = devm_regmap_init_spi(spi, &wm8731_regmap); >> 697 if (IS_ERR(wm8731->regmap)) { >> 698 ret = PTR_ERR(wm8731->regmap); >> 699 dev_err(&spi->dev, "Failed to allocate register map: %d\n", >> 700 ret); >> 701 return ret; >> 702 } >> 703 >> 704 ret = wm8731_hw_init(&spi->dev, wm8731); >> 705 if (ret != 0) >> 706 return ret; >> 707 >> 708 ret = devm_snd_soc_register_component(&spi->dev, >> 709 &soc_component_dev_wm8731, &wm8731_dai, 1); >> 710 if (ret != 0) { >> 711 dev_err(&spi->dev, "Failed to register CODEC: %d\n", ret); >> 712 return ret; >> 713 } >> 714 >> 715 return 0; >> 716 } >> 717 >> 718 static int wm8731_spi_remove(struct spi_device *spi) >> 719 { >> 720 return 0; >> 721 } >> 722 >> 723 static struct spi_driver wm8731_spi_driver = { >> 724 .driver = { >> 725 .name = "wm8731", >> 726 .of_match_table = wm8731_of_match, >> 727 }, >> 728 .probe = wm8731_spi_probe, >> 729 .remove = wm8731_spi_remove, >> 730 }; >> 731 #endif /* CONFIG_SPI_MASTER */ >> 732 >> 733 #if IS_ENABLED(CONFIG_I2C) >> 734 static int wm8731_i2c_probe(struct i2c_client *i2c, >> 735 const struct i2c_device_id *id) >> 736 { >> 737 struct wm8731_priv *wm8731; >> 738 int ret; >> 739 >> 740 wm8731 = devm_kzalloc(&i2c->dev, sizeof(struct wm8731_priv), >> 741 GFP_KERNEL); >> 742 if (wm8731 == NULL) >> 743 return -ENOMEM; >> 744 >> 745 wm8731->mclk = devm_clk_get(&i2c->dev, "mclk"); >> 746 if (IS_ERR(wm8731->mclk)) { >> 747 ret = PTR_ERR(wm8731->mclk); >> 748 if (ret == -ENOENT) { >> 749 wm8731->mclk = NULL; >> 750 dev_warn(&i2c->dev, "Assuming static MCLK\n"); >> 751 } else { >> 752 dev_err(&i2c->dev, "Failed to get MCLK: %d\n", >> 753 ret); >> 754 return ret; >> 755 } >> 756 } >> 757 >> 758 mutex_init(&wm8731->lock); >> 759 >> 760 i2c_set_clientdata(i2c, wm8731); >> 761 >> 762 ret = wm8731_request_supplies(&i2c->dev, wm8731); >> 763 if (ret != 0) >> 764 return ret; >> 765 >> 766 wm8731->regmap = devm_regmap_init_i2c(i2c, &wm8731_regmap); >> 767 if (IS_ERR(wm8731->regmap)) { >> 768 ret = PTR_ERR(wm8731->regmap); >> 769 dev_err(&i2c->dev, "Failed to allocate register map: %d\n", >> 770 ret); >> 771 return ret; >> 772 } >> 773 >> 774 ret = wm8731_hw_init(&i2c->dev, wm8731); >> 775 if (ret != 0) >> 776 return ret; >> 777 >> 778 ret = devm_snd_soc_register_component(&i2c->dev, >> 779 &soc_component_dev_wm8731, &wm8731_dai, 1); >> 780 if (ret != 0) { >> 781 dev_err(&i2c->dev, "Failed to register CODEC: %d\n", ret); >> 782 return ret; >> 783 } >> 784 >> 785 return 0; >> 786 } >> 787 >> 788 static int wm8731_i2c_remove(struct i2c_client *client) >> 789 { >> 790 return 0; >> 791 } >> 792 >> 793 static const struct i2c_device_id wm8731_i2c_id[] = { >> 794 { "wm8731", 0 }, >> 795 { } >> 796 }; >> 797 MODULE_DEVICE_TABLE(i2c, wm8731_i2c_id); >> 798 >> 799 static struct i2c_driver wm8731_i2c_driver = { >> 800 .driver = { >> 801 .name = "wm8731", >> 802 .of_match_table = wm8731_of_match, >> 803 }, >> 804 .probe = wm8731_i2c_probe, >> 805 .remove = wm8731_i2c_remove, >> 806 .id_table = wm8731_i2c_id, >> 807 }; >> 808 #endif >> 809 >> 810 static int __init wm8731_modinit(void) >> 811 { >> 812 int ret = 0; >> 813 #if IS_ENABLED(CONFIG_I2C) >> 814 ret = i2c_add_driver(&wm8731_i2c_driver); >> 815 if (ret != 0) { >> 816 printk(KERN_ERR "Failed to register WM8731 I2C driver: %d\n", >> 817 ret); >> 818 } >> 819 #endif >> 820 #if defined(CONFIG_SPI_MASTER) >> 821 ret = spi_register_driver(&wm8731_spi_driver); >> 822 if (ret != 0) { >> 823 printk(KERN_ERR "Failed to register WM8731 SPI driver: %d\n", >> 824 ret); >> 825 } >> 826 #endif >> 827 return ret; >> 828 } >> 829 module_init(wm8731_modinit); >> 830 >> 831 static void __exit wm8731_exit(void) >> 832 { >> 833 #if IS_ENABLED(CONFIG_I2C) >> 834 i2c_del_driver(&wm8731_i2c_driver); >> 835 #endif >> 836 #if defined(CONFIG_SPI_MASTER) >> 837 spi_unregister_driver(&wm8731_spi_driver); >> 838 #endif >> 839 } >> 840 module_exit(wm8731_exit); 650 841 651 MODULE_DESCRIPTION("ASoC WM8731 driver"); 842 MODULE_DESCRIPTION("ASoC WM8731 driver"); 652 MODULE_AUTHOR("Richard Purdie"); 843 MODULE_AUTHOR("Richard Purdie"); 653 MODULE_LICENSE("GPL"); 844 MODULE_LICENSE("GPL"); 654 845
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.