Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ASoC: wm8960: Add device tree support

Document the device tree binding for the WM8960 codec, and modify the
driver to extract the platform data from device tree, if present.

Signed-off-by: Zidan Wang <b50113@freescale.com>
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Zidan Wang and committed by
Mark Brown
e2280c90 f114040e

+62 -10
+31
Documentation/devicetree/bindings/sound/wm8960.txt
··· 1 + WM8960 audio CODEC 2 + 3 + This device supports I2C only. 4 + 5 + Required properties: 6 + 7 + - compatible : "wlf,wm8960" 8 + 9 + - reg : the I2C address of the device. 10 + 11 + Optional properties: 12 + - wlf,shared-lrclk: This is a boolean property. If present, the LRCM bit of 13 + R24 (Additional control 2) gets set, indicating that ADCLRC and DACLRC pins 14 + will be disabled only when ADC (Left and Right) and DAC (Left and Right) 15 + are disabled. 16 + When wm8960 works on synchronize mode and DACLRC pin is used to supply 17 + frame clock, it will no frame clock for captrue unless enable DAC to enable 18 + DACLRC pin. If shared-lrclk is present, no need to enable DAC for captrue. 19 + 20 + - wlf,capless: This is a boolean property. If present, OUT3 pin will be 21 + enabled and disabled together with HP_L and HP_R pins in response to jack 22 + detect events. 23 + 24 + Example: 25 + 26 + codec: wm8960@1a { 27 + compatible = "wlf,wm8960"; 28 + reg = <0x1a>; 29 + 30 + wlf,shared-lrclk; 31 + };
+31 -10
sound/soc/codecs/wm8960.c
··· 125 125 struct snd_soc_dapm_widget *out3; 126 126 bool deemph; 127 127 int playback_fs; 128 + struct wm8960_data pdata; 128 129 }; 129 130 130 131 #define wm8960_reset(c) snd_soc_write(c, WM8960_RESET, 0) ··· 441 440 442 441 static int wm8960_add_widgets(struct snd_soc_codec *codec) 443 442 { 444 - struct wm8960_data *pdata = codec->dev->platform_data; 445 443 struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); 444 + struct wm8960_data *pdata = &wm8960->pdata; 446 445 struct snd_soc_dapm_context *dapm = &codec->dapm; 447 446 struct snd_soc_dapm_widget *w; 448 447 ··· 962 961 static int wm8960_probe(struct snd_soc_codec *codec) 963 962 { 964 963 struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); 965 - struct wm8960_data *pdata = dev_get_platdata(codec->dev); 964 + struct wm8960_data *pdata = &wm8960->pdata; 966 965 int ret; 967 966 968 - wm8960->set_bias_level = wm8960_set_bias_level_out3; 969 - 970 - if (!pdata) { 971 - dev_warn(codec->dev, "No platform data supplied\n"); 972 - } else { 973 - if (pdata->capless) 974 - wm8960->set_bias_level = wm8960_set_bias_level_capless; 975 - } 967 + if (pdata->capless) 968 + wm8960->set_bias_level = wm8960_set_bias_level_capless; 969 + else 970 + wm8960->set_bias_level = wm8960_set_bias_level_out3; 976 971 977 972 ret = wm8960_reset(codec); 978 973 if (ret < 0) { ··· 1026 1029 .volatile_reg = wm8960_volatile, 1027 1030 }; 1028 1031 1032 + static void wm8960_set_pdata_from_of(struct i2c_client *i2c, 1033 + struct wm8960_data *pdata) 1034 + { 1035 + const struct device_node *np = i2c->dev.of_node; 1036 + 1037 + if (of_property_read_bool(np, "wlf,capless")) 1038 + pdata->capless = true; 1039 + 1040 + if (of_property_read_bool(np, "wlf,shared-lrclk")) 1041 + pdata->shared_lrclk = true; 1042 + } 1043 + 1029 1044 static int wm8960_i2c_probe(struct i2c_client *i2c, 1030 1045 const struct i2c_device_id *id) 1031 1046 { ··· 1053 1044 wm8960->regmap = devm_regmap_init_i2c(i2c, &wm8960_regmap); 1054 1045 if (IS_ERR(wm8960->regmap)) 1055 1046 return PTR_ERR(wm8960->regmap); 1047 + 1048 + if (pdata) 1049 + memcpy(&wm8960->pdata, pdata, sizeof(struct wm8960_data)); 1050 + else if (i2c->dev.of_node) 1051 + wm8960_set_pdata_from_of(i2c, &wm8960->pdata); 1056 1052 1057 1053 if (pdata && pdata->shared_lrclk) { 1058 1054 ret = regmap_update_bits(wm8960->regmap, WM8960_ADDCTL2, ··· 1089 1075 }; 1090 1076 MODULE_DEVICE_TABLE(i2c, wm8960_i2c_id); 1091 1077 1078 + static const struct of_device_id wm8960_of_match[] = { 1079 + { .compatible = "wlf,wm8960", }, 1080 + { } 1081 + }; 1082 + MODULE_DEVICE_TABLE(of, wm8960_of_match); 1083 + 1092 1084 static struct i2c_driver wm8960_i2c_driver = { 1093 1085 .driver = { 1094 1086 .name = "wm8960", 1095 1087 .owner = THIS_MODULE, 1088 + .of_match_table = wm8960_of_match, 1096 1089 }, 1097 1090 .probe = wm8960_i2c_probe, 1098 1091 .remove = wm8960_i2c_remove,