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>
This commit is contained in:
parent
717071dc27
commit
81e8e49261
@ -13,6 +13,8 @@
|
|||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
#include <linux/of.h>
|
#include <linux/of.h>
|
||||||
#include <linux/of_platform.h>
|
#include <linux/of_platform.h>
|
||||||
|
#include <linux/of_i2c.h>
|
||||||
|
#include <linux/clk.h>
|
||||||
#include <sound/soc.h>
|
#include <sound/soc.h>
|
||||||
|
|
||||||
#include "../codecs/sgtl5000.h"
|
#include "../codecs/sgtl5000.h"
|
||||||
@ -25,6 +27,7 @@ struct imx_sgtl5000_data {
|
|||||||
struct snd_soc_card card;
|
struct snd_soc_card card;
|
||||||
char codec_dai_name[DAI_NAME_SIZE];
|
char codec_dai_name[DAI_NAME_SIZE];
|
||||||
char platform_name[DAI_NAME_SIZE];
|
char platform_name[DAI_NAME_SIZE];
|
||||||
|
struct clk *codec_clk;
|
||||||
unsigned int clk_frequency;
|
unsigned int clk_frequency;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -58,6 +61,7 @@ static int __devinit imx_sgtl5000_probe(struct platform_device *pdev)
|
|||||||
struct device_node *np = pdev->dev.of_node;
|
struct device_node *np = pdev->dev.of_node;
|
||||||
struct device_node *ssi_np, *codec_np;
|
struct device_node *ssi_np, *codec_np;
|
||||||
struct platform_device *ssi_pdev;
|
struct platform_device *ssi_pdev;
|
||||||
|
struct i2c_client *codec_dev;
|
||||||
struct imx_sgtl5000_data *data;
|
struct imx_sgtl5000_data *data;
|
||||||
int int_port, ext_port;
|
int int_port, ext_port;
|
||||||
int ret;
|
int ret;
|
||||||
@ -113,6 +117,11 @@ static int __devinit imx_sgtl5000_probe(struct platform_device *pdev)
|
|||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
codec_dev = of_find_i2c_device_by_node(codec_np);
|
||||||
|
if (!codec_dev) {
|
||||||
|
dev_err(&pdev->dev, "failed to find codec platform device\n");
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
|
data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
|
||||||
if (!data) {
|
if (!data) {
|
||||||
@ -120,12 +129,21 @@ static int __devinit imx_sgtl5000_probe(struct platform_device *pdev)
|
|||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data->codec_clk = clk_get(&codec_dev->dev, NULL);
|
||||||
|
if (IS_ERR(data->codec_clk)) {
|
||||||
|
/* assuming clock enabled by default */
|
||||||
|
data->codec_clk = NULL;
|
||||||
ret = of_property_read_u32(codec_np, "clock-frequency",
|
ret = of_property_read_u32(codec_np, "clock-frequency",
|
||||||
&data->clk_frequency);
|
&data->clk_frequency);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
dev_err(&pdev->dev, "clock-frequency missing or invalid\n");
|
dev_err(&codec_dev->dev,
|
||||||
|
"clock-frequency missing or invalid\n");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
data->clk_frequency = clk_get_rate(data->codec_clk);
|
||||||
|
clk_prepare_enable(data->codec_clk);
|
||||||
|
}
|
||||||
|
|
||||||
data->dai.name = "HiFi";
|
data->dai.name = "HiFi";
|
||||||
data->dai.stream_name = "HiFi";
|
data->dai.stream_name = "HiFi";
|
||||||
@ -140,10 +158,10 @@ static int __devinit imx_sgtl5000_probe(struct platform_device *pdev)
|
|||||||
data->card.dev = &pdev->dev;
|
data->card.dev = &pdev->dev;
|
||||||
ret = snd_soc_of_parse_card_name(&data->card, "model");
|
ret = snd_soc_of_parse_card_name(&data->card, "model");
|
||||||
if (ret)
|
if (ret)
|
||||||
goto fail;
|
goto clk_fail;
|
||||||
ret = snd_soc_of_parse_audio_routing(&data->card, "audio-routing");
|
ret = snd_soc_of_parse_audio_routing(&data->card, "audio-routing");
|
||||||
if (ret)
|
if (ret)
|
||||||
goto fail;
|
goto clk_fail;
|
||||||
data->card.num_links = 1;
|
data->card.num_links = 1;
|
||||||
data->card.dai_link = &data->dai;
|
data->card.dai_link = &data->dai;
|
||||||
data->card.dapm_widgets = imx_sgtl5000_dapm_widgets;
|
data->card.dapm_widgets = imx_sgtl5000_dapm_widgets;
|
||||||
@ -152,10 +170,12 @@ static int __devinit imx_sgtl5000_probe(struct platform_device *pdev)
|
|||||||
ret = snd_soc_register_card(&data->card);
|
ret = snd_soc_register_card(&data->card);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
|
dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
|
||||||
goto fail;
|
goto clk_fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
platform_set_drvdata(pdev, data);
|
platform_set_drvdata(pdev, data);
|
||||||
|
clk_fail:
|
||||||
|
clk_put(data->codec_clk);
|
||||||
fail:
|
fail:
|
||||||
if (ssi_np)
|
if (ssi_np)
|
||||||
of_node_put(ssi_np);
|
of_node_put(ssi_np);
|
||||||
@ -169,6 +189,10 @@ static int __devexit imx_sgtl5000_remove(struct platform_device *pdev)
|
|||||||
{
|
{
|
||||||
struct imx_sgtl5000_data *data = platform_get_drvdata(pdev);
|
struct imx_sgtl5000_data *data = platform_get_drvdata(pdev);
|
||||||
|
|
||||||
|
if (data->codec_clk) {
|
||||||
|
clk_disable_unprepare(data->codec_clk);
|
||||||
|
clk_put(data->codec_clk);
|
||||||
|
}
|
||||||
snd_soc_unregister_card(&data->card);
|
snd_soc_unregister_card(&data->card);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user