13 #include <linux/module.h>
18 #include <linux/i2c.h>
21 #include <linux/slab.h>
32 #define WM8955_NUM_SUPPLIES 4
52 static const struct reg_default wm8955_reg_defaults[] = {
83 static bool wm8955_writeable(
struct device *
dev,
unsigned int reg)
121 static bool wm8955_volatile(
struct device *dev,
unsigned int reg)
144 #define FIXED_FLL_SIZE ((1 << 22) * 10)
146 static int wm8995_pll_factors(
struct device *dev,
150 unsigned int K, Ndiv, Nmod,
target;
152 dev_dbg(dev,
"Fref=%u Fout=%u\n", Fref, Fout);
159 if (target < 90000000) {
166 WARN_ON(target < 90000000 || target > 100000000);
168 dev_dbg(dev,
"Fvco=%dHz\n", target);
171 Ndiv = target / Fref;
174 Nmod = target % Fref;
175 dev_dbg(dev,
"Nmod=%d\n", Nmod);
182 K = Kpart & 0xFFFFFFFF;
204 { 18432000, 8000, 0, 3, },
205 { 18432000, 12000, 0, 9, },
206 { 18432000, 16000, 0, 11, },
207 { 18432000, 24000, 0, 29, },
208 { 18432000, 32000, 0, 13, },
209 { 18432000, 48000, 0, 1, },
210 { 18432000, 96000, 0, 15, },
212 { 16934400, 8018, 0, 19, },
213 { 16934400, 11025, 0, 25, },
214 { 16934400, 22050, 0, 27, },
215 { 16934400, 44100, 0, 17, },
216 { 16934400, 88200, 0, 31, },
218 { 12000000, 8000, 1, 2, },
219 { 12000000, 11025, 1, 25, },
220 { 12000000, 12000, 1, 8, },
221 { 12000000, 16000, 1, 10, },
222 { 12000000, 22050, 1, 27, },
223 { 12000000, 24000, 1, 28, },
224 { 12000000, 32000, 1, 12, },
225 { 12000000, 44100, 1, 17, },
226 { 12000000, 48000, 1, 0, },
227 { 12000000, 88200, 1, 31, },
228 { 12000000, 96000, 1, 14, },
230 { 12288000, 8000, 0, 2, },
231 { 12288000, 12000, 0, 8, },
232 { 12288000, 16000, 0, 10, },
233 { 12288000, 24000, 0, 28, },
234 { 12288000, 32000, 0, 12, },
235 { 12288000, 48000, 0, 0, },
236 { 12288000, 96000, 0, 14, },
238 { 12289600, 8018, 0, 18, },
239 { 12289600, 11025, 0, 24, },
240 { 12289600, 22050, 0, 26, },
241 { 11289600, 44100, 0, 16, },
242 { 11289600, 88200, 0, 31, },
247 struct wm8955_priv *wm8955 = snd_soc_codec_get_drvdata(codec);
259 for (i = 0; i <
ARRAY_SIZE(clock_cfgs); i++) {
260 if (wm8955->
fs != clock_cfgs[i].fs)
264 if (wm8955->
mclk_rate == clock_cfgs[i].mclk)
270 dev_err(codec->
dev,
"Sample rate %dHz unsupported\n",
286 clock_cfgs[sr].mclk, &
pll);
289 "Unable to generate %dHz from %dHz MCLK\n",
351 ret = wm8955_configure_clocking(codec);
361 static int deemph_settings[] = { 0, 32000, 44100, 48000 };
365 struct wm8955_priv *wm8955 = snd_soc_codec_get_drvdata(codec);
373 for (i = 2; i <
ARRAY_SIZE(deemph_settings); i++) {
374 if (
abs(deemph_settings[i] - wm8955->
fs) <
375 abs(deemph_settings[best] - wm8955->
fs))
384 dev_dbg(codec->
dev,
"Set deemphasis %d\n", val);
390 static int wm8955_get_deemph(
struct snd_kcontrol *kcontrol,
394 struct wm8955_priv *wm8955 = snd_soc_codec_get_drvdata(codec);
396 ucontrol->
value.enumerated.item[0] = wm8955->
deemph;
400 static int wm8955_put_deemph(
struct snd_kcontrol *kcontrol,
404 struct wm8955_priv *wm8955 = snd_soc_codec_get_drvdata(codec);
412 return wm8955_set_deemph(codec);
415 static const char *bass_mode_text[] = {
416 "Linear",
"Adaptive",
419 static const struct soc_enum bass_mode =
422 static const char *bass_cutoff_text[] = {
426 static const struct soc_enum bass_cutoff =
429 static const char *treble_cutoff_text[] = {
433 static const struct soc_enum treble_cutoff =
449 wm8955_get_deemph, wm8955_put_deemph),
452 SOC_ENUM(
"Bass Cutoff", bass_cutoff),
455 SOC_ENUM(
"Treble Cutoff", treble_cutoff),
548 {
"DACL",
NULL,
"SYSCLK" },
549 {
"DACR",
NULL,
"SYSCLK" },
551 {
"Mono Input",
NULL,
"MONOIN-" },
552 {
"Mono Input",
NULL,
"MONOIN+" },
554 {
"Left",
"Playback Switch",
"DACL" },
555 {
"Left",
"Right Playback Switch",
"DACR" },
556 {
"Left",
"Bypass Switch",
"LINEINL" },
557 {
"Left",
"Mono Switch",
"Mono Input" },
559 {
"Right",
"Playback Switch",
"DACR" },
560 {
"Right",
"Left Playback Switch",
"DACL" },
561 {
"Right",
"Bypass Switch",
"LINEINR" },
562 {
"Right",
"Mono Switch",
"Mono Input" },
564 {
"Mono",
"Left Playback Switch",
"DACL" },
565 {
"Mono",
"Right Playback Switch",
"DACR" },
566 {
"Mono",
"Left Bypass Switch",
"LINEINL" },
567 {
"Mono",
"Right Bypass Switch",
"LINEINR" },
569 {
"LOUT1 PGA",
NULL,
"Left" },
570 {
"LOUT1",
NULL,
"TSDEN" },
571 {
"LOUT1",
NULL,
"LOUT1 PGA" },
573 {
"ROUT1 PGA",
NULL,
"Right" },
574 {
"ROUT1",
NULL,
"TSDEN" },
575 {
"ROUT1",
NULL,
"ROUT1 PGA" },
577 {
"LOUT2 PGA",
NULL,
"Left" },
578 {
"LOUT2",
NULL,
"TSDEN" },
579 {
"LOUT2",
NULL,
"LOUT2 PGA" },
581 {
"ROUT2 PGA",
NULL,
"Right" },
582 {
"ROUT2",
NULL,
"TSDEN" },
583 {
"ROUT2",
NULL,
"ROUT2 PGA" },
585 {
"MOUT PGA",
NULL,
"Mono" },
586 {
"MONOOUT",
NULL,
"MOUT PGA" },
589 {
"OUT3",
NULL,
"OUT3 PGA" },
597 struct wm8955_priv *wm8955 = snd_soc_codec_get_drvdata(codec);
621 wm8955_set_deemph(codec);
635 wm8955_configure_clocking(codec);
642 static int wm8955_set_sysclk(
struct snd_soc_dai *dai,
int clk_id,
643 unsigned int freq,
int dir)
651 if (freq > 15000000) {
667 dev_dbg(dai->
dev,
"Clock source is %d at %uHz\n", clk_id, freq);
672 static int wm8955_set_fmt(
struct snd_soc_dai *dai,
unsigned int fmt)
705 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
723 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
751 static int wm8955_digital_mute(
struct snd_soc_dai *codec_dai,
int mute)
766 static int wm8955_set_bias_level(
struct snd_soc_codec *codec,
769 struct wm8955_priv *wm8955 = snd_soc_codec_get_drvdata(codec);
794 "Failed to enable supplies: %d\n",
846 #define WM8955_RATES SNDRV_PCM_RATE_8000_96000
848 #define WM8955_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
849 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
852 .set_sysclk = wm8955_set_sysclk,
853 .set_fmt = wm8955_set_fmt,
854 .hw_params = wm8955_hw_params,
855 .digital_mute = wm8955_digital_mute,
859 .name =
"wm8955-hifi",
861 .stream_name =
"Playback",
867 .ops = &wm8955_dai_ops,
873 struct wm8955_priv *wm8955 = snd_soc_codec_get_drvdata(codec);
889 #define wm8955_suspend NULL
890 #define wm8955_resume NULL
895 struct wm8955_priv *wm8955 = snd_soc_codec_get_drvdata(codec);
903 dev_err(codec->
dev,
"Failed to set cache I/O: %d\n", ret);
908 wm8955->
supplies[i].supply = wm8955_supply_names[i];
913 dev_err(codec->
dev,
"Failed to request supplies: %d\n", ret);
920 dev_err(codec->
dev,
"Failed to enable supplies: %d\n", ret);
924 ret = wm8955_reset(codec);
926 dev_err(codec->
dev,
"Failed to issue reset: %d\n", ret);
980 struct wm8955_priv *wm8955 = snd_soc_codec_get_drvdata(codec);
988 .probe = wm8955_probe,
989 .remove = wm8955_remove,
992 .set_bias_level = wm8955_set_bias_level,
994 .controls = wm8955_snd_controls,
995 .num_controls =
ARRAY_SIZE(wm8955_snd_controls),
996 .dapm_widgets = wm8955_dapm_widgets,
997 .num_dapm_widgets =
ARRAY_SIZE(wm8955_dapm_widgets),
998 .dapm_routes = wm8955_dapm_routes,
999 .num_dapm_routes =
ARRAY_SIZE(wm8955_dapm_routes),
1002 static const struct regmap_config wm8955_regmap = {
1007 .volatile_reg = wm8955_volatile,
1008 .writeable_reg = wm8955_writeable,
1011 .reg_defaults = wm8955_reg_defaults,
1012 .num_reg_defaults =
ARRAY_SIZE(wm8955_reg_defaults),
1027 if (IS_ERR(wm8955->
regmap)) {
1028 ret = PTR_ERR(wm8955->
regmap);
1029 dev_err(&i2c->
dev,
"Failed to allocate register map: %d\n",
1034 i2c_set_clientdata(i2c, wm8955);
1037 &soc_codec_dev_wm8955, &wm8955_dai, 1);
1050 struct wm8955_priv *wm8955 = i2c_get_clientdata(client);
1064 static struct i2c_driver wm8955_i2c_driver = {
1069 .probe = wm8955_i2c_probe,
1071 .id_table = wm8955_i2c_id,