diff options
author | Richard Zhao <richard.zhao@linaro.org> | 2012-04-27 03:02:57 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-04-27 13:44:08 -0400 |
commit | 81e8e4926167ab32593bbb915b45a42024ca1020 (patch) | |
tree | d663a8d1e6161371dfb5c17ec65f5785a8db7a8d /sound/soc/fsl | |
parent | 717071dc273bb0acff3b95d39764d4f20adc6e1d (diff) |
ASoC: fsl: add sgtl5000 clock support for imx-sgtl5000
It tries to clk_get the clock. And if it failed, it assumes the clock
by default enabled.
Signed-off-by: Richard Zhao <richard.zhao@freescale.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/fsl')
-rw-r--r-- | sound/soc/fsl/imx-sgtl5000.c | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/sound/soc/fsl/imx-sgtl5000.c b/sound/soc/fsl/imx-sgtl5000.c index 73b935e25f9b..3a729caeb8c8 100644 --- a/sound/soc/fsl/imx-sgtl5000.c +++ b/sound/soc/fsl/imx-sgtl5000.c | |||
@@ -13,6 +13,8 @@ | |||
13 | #include <linux/module.h> | 13 | #include <linux/module.h> |
14 | #include <linux/of.h> | 14 | #include <linux/of.h> |
15 | #include <linux/of_platform.h> | 15 | #include <linux/of_platform.h> |
16 | #include <linux/of_i2c.h> | ||
17 | #include <linux/clk.h> | ||
16 | #include <sound/soc.h> | 18 | #include <sound/soc.h> |
17 | 19 | ||
18 | #include "../codecs/sgtl5000.h" | 20 | #include "../codecs/sgtl5000.h" |
@@ -25,6 +27,7 @@ struct imx_sgtl5000_data { | |||
25 | struct snd_soc_card card; | 27 | struct snd_soc_card card; |
26 | char codec_dai_name[DAI_NAME_SIZE]; | 28 | char codec_dai_name[DAI_NAME_SIZE]; |
27 | char platform_name[DAI_NAME_SIZE]; | 29 | char platform_name[DAI_NAME_SIZE]; |
30 | struct clk *codec_clk; | ||
28 | unsigned int clk_frequency; | 31 | unsigned int clk_frequency; |
29 | }; | 32 | }; |
30 | 33 | ||
@@ -58,6 +61,7 @@ static int __devinit imx_sgtl5000_probe(struct platform_device *pdev) | |||
58 | struct device_node *np = pdev->dev.of_node; | 61 | struct device_node *np = pdev->dev.of_node; |
59 | struct device_node *ssi_np, *codec_np; | 62 | struct device_node *ssi_np, *codec_np; |
60 | struct platform_device *ssi_pdev; | 63 | struct platform_device *ssi_pdev; |
64 | struct i2c_client *codec_dev; | ||
61 | struct imx_sgtl5000_data *data; | 65 | struct imx_sgtl5000_data *data; |
62 | int int_port, ext_port; | 66 | int int_port, ext_port; |
63 | int ret; | 67 | int ret; |
@@ -113,6 +117,11 @@ static int __devinit imx_sgtl5000_probe(struct platform_device *pdev) | |||
113 | ret = -EINVAL; | 117 | ret = -EINVAL; |
114 | goto fail; | 118 | goto fail; |
115 | } | 119 | } |
120 | codec_dev = of_find_i2c_device_by_node(codec_np); | ||
121 | if (!codec_dev) { | ||
122 | dev_err(&pdev->dev, "failed to find codec platform device\n"); | ||
123 | return -EINVAL; | ||
124 | } | ||
116 | 125 | ||
117 | data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); | 126 | data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); |
118 | if (!data) { | 127 | if (!data) { |
@@ -120,11 +129,20 @@ static int __devinit imx_sgtl5000_probe(struct platform_device *pdev) | |||
120 | goto fail; | 129 | goto fail; |
121 | } | 130 | } |
122 | 131 | ||
123 | ret = of_property_read_u32(codec_np, "clock-frequency", | 132 | data->codec_clk = clk_get(&codec_dev->dev, NULL); |
124 | &data->clk_frequency); | 133 | if (IS_ERR(data->codec_clk)) { |
125 | if (ret) { | 134 | /* assuming clock enabled by default */ |
126 | dev_err(&pdev->dev, "clock-frequency missing or invalid\n"); | 135 | data->codec_clk = NULL; |
127 | goto fail; | 136 | ret = of_property_read_u32(codec_np, "clock-frequency", |
137 | &data->clk_frequency); | ||
138 | if (ret) { | ||
139 | dev_err(&codec_dev->dev, | ||
140 | "clock-frequency missing or invalid\n"); | ||
141 | goto fail; | ||
142 | } | ||
143 | } else { | ||
144 | data->clk_frequency = clk_get_rate(data->codec_clk); | ||
145 | clk_prepare_enable(data->codec_clk); | ||
128 | } | 146 | } |
129 | 147 | ||
130 | data->dai.name = "HiFi"; | 148 | data->dai.name = "HiFi"; |
@@ -140,10 +158,10 @@ static int __devinit imx_sgtl5000_probe(struct platform_device *pdev) | |||
140 | data->card.dev = &pdev->dev; | 158 | data->card.dev = &pdev->dev; |
141 | ret = snd_soc_of_parse_card_name(&data->card, "model"); | 159 | ret = snd_soc_of_parse_card_name(&data->card, "model"); |
142 | if (ret) | 160 | if (ret) |
143 | goto fail; | 161 | goto clk_fail; |
144 | ret = snd_soc_of_parse_audio_routing(&data->card, "audio-routing"); | 162 | ret = snd_soc_of_parse_audio_routing(&data->card, "audio-routing"); |
145 | if (ret) | 163 | if (ret) |
146 | goto fail; | 164 | goto clk_fail; |
147 | data->card.num_links = 1; | 165 | data->card.num_links = 1; |
148 | data->card.dai_link = &data->dai; | 166 | data->card.dai_link = &data->dai; |
149 | data->card.dapm_widgets = imx_sgtl5000_dapm_widgets; | 167 | data->card.dapm_widgets = imx_sgtl5000_dapm_widgets; |
@@ -152,10 +170,12 @@ static int __devinit imx_sgtl5000_probe(struct platform_device *pdev) | |||
152 | ret = snd_soc_register_card(&data->card); | 170 | ret = snd_soc_register_card(&data->card); |
153 | if (ret) { | 171 | if (ret) { |
154 | dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret); | 172 | dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret); |
155 | goto fail; | 173 | goto clk_fail; |
156 | } | 174 | } |
157 | 175 | ||
158 | platform_set_drvdata(pdev, data); | 176 | platform_set_drvdata(pdev, data); |
177 | clk_fail: | ||
178 | clk_put(data->codec_clk); | ||
159 | fail: | 179 | fail: |
160 | if (ssi_np) | 180 | if (ssi_np) |
161 | of_node_put(ssi_np); | 181 | of_node_put(ssi_np); |
@@ -169,6 +189,10 @@ static int __devexit imx_sgtl5000_remove(struct platform_device *pdev) | |||
169 | { | 189 | { |
170 | struct imx_sgtl5000_data *data = platform_get_drvdata(pdev); | 190 | struct imx_sgtl5000_data *data = platform_get_drvdata(pdev); |
171 | 191 | ||
192 | if (data->codec_clk) { | ||
193 | clk_disable_unprepare(data->codec_clk); | ||
194 | clk_put(data->codec_clk); | ||
195 | } | ||
172 | snd_soc_unregister_card(&data->card); | 196 | snd_soc_unregister_card(&data->card); |
173 | 197 | ||
174 | return 0; | 198 | return 0; |