Commit 1d957d86 authored by Maruthi Srinivas Bayyavarapu's avatar Maruthi Srinivas Bayyavarapu Committed by Mark Brown
Browse files

ASoC: dwc: support dw i2s in slave mode



dw i2s controller can work in slave mode, codec being master.
dw i2s is made to support master/slave operation, by reading dwc
register.

Signed-off-by: default avatarMaruthi Bayyavarapu <maruthi.bayyavarapu@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent 6ff33f39
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -38,6 +38,8 @@ struct i2s_clk_config_data {
struct i2s_platform_data {
	#define DWC_I2S_PLAY	(1 << 0)
	#define DWC_I2S_RECORD	(1 << 1)
	#define DW_I2S_SLAVE	(1 << 2)
	#define DW_I2S_MASTER	(1 << 3)
	unsigned int cap;
	int channel;
	u32 snd_fmts;
+55 −37
Original line number Diff line number Diff line
@@ -273,6 +273,7 @@ static int dw_i2s_hw_params(struct snd_pcm_substream *substream,

	config->sample_rate = params_rate(params);

	if (dev->capability & DW_I2S_MASTER) {
		if (dev->i2s_clk_cfg) {
			ret = dev->i2s_clk_cfg(config);
			if (ret < 0) {
@@ -280,7 +281,8 @@ static int dw_i2s_hw_params(struct snd_pcm_substream *substream,
				return ret;
			}
		} else {
		u32 bitclk = config->sample_rate * config->data_width * 2;
			u32 bitclk = config->sample_rate *
					config->data_width * 2;

			ret = clk_set_rate(dev->clk, bitclk);
			if (ret) {
@@ -289,7 +291,7 @@ static int dw_i2s_hw_params(struct snd_pcm_substream *substream,
				return ret;
			}
		}

	}
	return 0;
}

@@ -357,6 +359,7 @@ static int dw_i2s_suspend(struct snd_soc_dai *dai)
{
	struct dw_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);

	if (dev->capability & DW_I2S_MASTER)
		clk_disable(dev->clk);
	return 0;
}
@@ -365,6 +368,7 @@ static int dw_i2s_resume(struct snd_soc_dai *dai)
{
	struct dw_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);

	if (dev->capability & DW_I2S_MASTER)
		clk_enable(dev->clk);
	return 0;
}
@@ -443,6 +447,14 @@ static int dw_configure_dai(struct dw_i2s_dev *dev,
		dw_i2s_dai->capture.rates = rates;
	}

	if (COMP1_MODE_EN(comp1)) {
		dev_dbg(dev->dev, "designware: i2s master mode supported\n");
		dev->capability |= DW_I2S_MASTER;
	} else {
		dev_dbg(dev->dev, "designware: i2s slave mode supported\n");
		dev->capability |= DW_I2S_SLAVE;
	}

	return 0;
}

@@ -529,6 +541,7 @@ static int dw_i2s_probe(struct platform_device *pdev)
	struct resource *res;
	int ret;
	struct snd_soc_dai_driver *dw_i2s_dai;
	const char *clk_id;

	dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
	if (!dev) {
@@ -550,32 +563,35 @@ static int dw_i2s_probe(struct platform_device *pdev)
		return PTR_ERR(dev->i2s_base);

	dev->dev = &pdev->dev;

	if (pdata) {
		dev->capability = pdata->cap;
		clk_id = NULL;
		ret = dw_configure_dai_by_pd(dev, dw_i2s_dai, res, pdata);
	} else {
		clk_id = "i2sclk";
		ret = dw_configure_dai_by_dt(dev, dw_i2s_dai, res);
	}
	if (ret < 0)
		return ret;

		dev->capability = pdata->cap;
	if (dev->capability & DW_I2S_MASTER) {
		if (pdata) {
			dev->i2s_clk_cfg = pdata->i2s_clk_cfg;
			if (!dev->i2s_clk_cfg) {
				dev_err(&pdev->dev, "no clock configure method\n");
				return -ENODEV;
			}

		dev->clk = devm_clk_get(&pdev->dev, NULL);
	} else {
		ret = dw_configure_dai_by_dt(dev, dw_i2s_dai, res);
		if (ret < 0)
			return ret;

		dev->clk = devm_clk_get(&pdev->dev, "i2sclk");
		}
		dev->clk = devm_clk_get(&pdev->dev, clk_id);

		if (IS_ERR(dev->clk))
			return PTR_ERR(dev->clk);

		ret = clk_prepare_enable(dev->clk);
		if (ret < 0)
			return ret;
	}

	dev_set_drvdata(&pdev->dev, dev);
	ret = devm_snd_soc_register_component(&pdev->dev, &dw_i2s_component,
@@ -597,6 +613,7 @@ static int dw_i2s_probe(struct platform_device *pdev)
	return 0;

err_clk_disable:
	if (dev->capability & DW_I2S_MASTER)
		clk_disable_unprepare(dev->clk);
	return ret;
}
@@ -605,6 +622,7 @@ static int dw_i2s_remove(struct platform_device *pdev)
{
	struct dw_i2s_dev *dev = dev_get_drvdata(&pdev->dev);

	if (dev->capability & DW_I2S_MASTER)
		clk_disable_unprepare(dev->clk);

	return 0;