diff options
author | Zidan Wang <b50113@freescale.com> | 2014-11-20 06:07:48 -0500 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2014-11-21 13:19:35 -0500 |
commit | e2280c9040d8bc5039617af35ccf7b8ac4abb428 (patch) | |
tree | 6991e31dad342f53f6dc7d417991f4d7925eb194 /sound | |
parent | f114040e3ea6e07372334ade75d1ee0775c355e1 (diff) |
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>
Diffstat (limited to 'sound')
-rw-r--r-- | sound/soc/codecs/wm8960.c | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/sound/soc/codecs/wm8960.c b/sound/soc/codecs/wm8960.c index 4dc4e85116cd..99d6457c87ba 100644 --- a/sound/soc/codecs/wm8960.c +++ b/sound/soc/codecs/wm8960.c | |||
@@ -125,6 +125,7 @@ struct wm8960_priv { | |||
125 | struct snd_soc_dapm_widget *out3; | 125 | struct snd_soc_dapm_widget *out3; |
126 | bool deemph; | 126 | bool deemph; |
127 | int playback_fs; | 127 | int playback_fs; |
128 | struct wm8960_data pdata; | ||
128 | }; | 129 | }; |
129 | 130 | ||
130 | #define wm8960_reset(c) snd_soc_write(c, WM8960_RESET, 0) | 131 | #define wm8960_reset(c) snd_soc_write(c, WM8960_RESET, 0) |
@@ -440,8 +441,8 @@ static const struct snd_soc_dapm_route audio_paths_capless[] = { | |||
440 | 441 | ||
441 | static int wm8960_add_widgets(struct snd_soc_codec *codec) | 442 | static int wm8960_add_widgets(struct snd_soc_codec *codec) |
442 | { | 443 | { |
443 | struct wm8960_data *pdata = codec->dev->platform_data; | ||
444 | struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); | 444 | struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); |
445 | struct wm8960_data *pdata = &wm8960->pdata; | ||
445 | struct snd_soc_dapm_context *dapm = &codec->dapm; | 446 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
446 | struct snd_soc_dapm_widget *w; | 447 | struct snd_soc_dapm_widget *w; |
447 | 448 | ||
@@ -961,17 +962,13 @@ static int wm8960_resume(struct snd_soc_codec *codec) | |||
961 | static int wm8960_probe(struct snd_soc_codec *codec) | 962 | static int wm8960_probe(struct snd_soc_codec *codec) |
962 | { | 963 | { |
963 | struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); | 964 | struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); |
964 | struct wm8960_data *pdata = dev_get_platdata(codec->dev); | 965 | struct wm8960_data *pdata = &wm8960->pdata; |
965 | int ret; | 966 | int ret; |
966 | 967 | ||
967 | wm8960->set_bias_level = wm8960_set_bias_level_out3; | 968 | if (pdata->capless) |
968 | 969 | wm8960->set_bias_level = wm8960_set_bias_level_capless; | |
969 | if (!pdata) { | 970 | else |
970 | dev_warn(codec->dev, "No platform data supplied\n"); | 971 | wm8960->set_bias_level = wm8960_set_bias_level_out3; |
971 | } else { | ||
972 | if (pdata->capless) | ||
973 | wm8960->set_bias_level = wm8960_set_bias_level_capless; | ||
974 | } | ||
975 | 972 | ||
976 | ret = wm8960_reset(codec); | 973 | ret = wm8960_reset(codec); |
977 | if (ret < 0) { | 974 | if (ret < 0) { |
@@ -1029,6 +1026,18 @@ static const struct regmap_config wm8960_regmap = { | |||
1029 | .volatile_reg = wm8960_volatile, | 1026 | .volatile_reg = wm8960_volatile, |
1030 | }; | 1027 | }; |
1031 | 1028 | ||
1029 | static void wm8960_set_pdata_from_of(struct i2c_client *i2c, | ||
1030 | struct wm8960_data *pdata) | ||
1031 | { | ||
1032 | const struct device_node *np = i2c->dev.of_node; | ||
1033 | |||
1034 | if (of_property_read_bool(np, "wlf,capless")) | ||
1035 | pdata->capless = true; | ||
1036 | |||
1037 | if (of_property_read_bool(np, "wlf,shared-lrclk")) | ||
1038 | pdata->shared_lrclk = true; | ||
1039 | } | ||
1040 | |||
1032 | static int wm8960_i2c_probe(struct i2c_client *i2c, | 1041 | static int wm8960_i2c_probe(struct i2c_client *i2c, |
1033 | const struct i2c_device_id *id) | 1042 | const struct i2c_device_id *id) |
1034 | { | 1043 | { |
@@ -1045,6 +1054,11 @@ static int wm8960_i2c_probe(struct i2c_client *i2c, | |||
1045 | if (IS_ERR(wm8960->regmap)) | 1054 | if (IS_ERR(wm8960->regmap)) |
1046 | return PTR_ERR(wm8960->regmap); | 1055 | return PTR_ERR(wm8960->regmap); |
1047 | 1056 | ||
1057 | if (pdata) | ||
1058 | memcpy(&wm8960->pdata, pdata, sizeof(struct wm8960_data)); | ||
1059 | else if (i2c->dev.of_node) | ||
1060 | wm8960_set_pdata_from_of(i2c, &wm8960->pdata); | ||
1061 | |||
1048 | if (pdata && pdata->shared_lrclk) { | 1062 | if (pdata && pdata->shared_lrclk) { |
1049 | ret = regmap_update_bits(wm8960->regmap, WM8960_ADDCTL2, | 1063 | ret = regmap_update_bits(wm8960->regmap, WM8960_ADDCTL2, |
1050 | 0x4, 0x4); | 1064 | 0x4, 0x4); |
@@ -1075,10 +1089,17 @@ static const struct i2c_device_id wm8960_i2c_id[] = { | |||
1075 | }; | 1089 | }; |
1076 | MODULE_DEVICE_TABLE(i2c, wm8960_i2c_id); | 1090 | MODULE_DEVICE_TABLE(i2c, wm8960_i2c_id); |
1077 | 1091 | ||
1092 | static const struct of_device_id wm8960_of_match[] = { | ||
1093 | { .compatible = "wlf,wm8960", }, | ||
1094 | { } | ||
1095 | }; | ||
1096 | MODULE_DEVICE_TABLE(of, wm8960_of_match); | ||
1097 | |||
1078 | static struct i2c_driver wm8960_i2c_driver = { | 1098 | static struct i2c_driver wm8960_i2c_driver = { |
1079 | .driver = { | 1099 | .driver = { |
1080 | .name = "wm8960", | 1100 | .name = "wm8960", |
1081 | .owner = THIS_MODULE, | 1101 | .owner = THIS_MODULE, |
1102 | .of_match_table = wm8960_of_match, | ||
1082 | }, | 1103 | }, |
1083 | .probe = wm8960_i2c_probe, | 1104 | .probe = wm8960_i2c_probe, |
1084 | .remove = wm8960_i2c_remove, | 1105 | .remove = wm8960_i2c_remove, |