aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/xilinx
diff options
context:
space:
mode:
Diffstat (limited to 'sound/soc/xilinx')
-rw-r--r--sound/soc/xilinx/xlnx_formatter_pcm.c68
-rw-r--r--sound/soc/xilinx/xlnx_i2s.c148
-rw-r--r--sound/soc/xilinx/xlnx_spdif.c11
3 files changed, 173 insertions, 54 deletions
diff --git a/sound/soc/xilinx/xlnx_formatter_pcm.c b/sound/soc/xilinx/xlnx_formatter_pcm.c
index 91afea9d5de6..ff1fe62fea70 100644
--- a/sound/soc/xilinx/xlnx_formatter_pcm.c
+++ b/sound/soc/xilinx/xlnx_formatter_pcm.c
@@ -37,6 +37,7 @@
#define XLNX_AUD_XFER_COUNT 0x28
#define XLNX_AUD_CH_STS_START 0x2C
#define XLNX_BYTES_PER_CH 0x44
+#define XLNX_AUD_ALIGN_BYTES 64
#define AUD_STS_IOC_IRQ_MASK BIT(31)
#define AUD_STS_CH_STS_MASK BIT(29)
@@ -83,6 +84,7 @@ struct xlnx_pcm_drv_data {
struct snd_pcm_substream *play_stream;
struct snd_pcm_substream *capture_stream;
struct clk *axi_clk;
+ unsigned int sysclk;
};
/*
@@ -313,6 +315,15 @@ static irqreturn_t xlnx_s2mm_irq_handler(int irq, void *arg)
return IRQ_NONE;
}
+static int xlnx_formatter_set_sysclk(struct snd_soc_component *component,
+ int clk_id, int source, unsigned int freq, int dir)
+{
+ struct xlnx_pcm_drv_data *adata = dev_get_drvdata(component->dev);
+
+ adata->sysclk = freq;
+ return 0;
+}
+
static int xlnx_formatter_pcm_open(struct snd_soc_component *component,
struct snd_pcm_substream *substream)
{
@@ -368,12 +379,32 @@ static int xlnx_formatter_pcm_open(struct snd_soc_component *component,
snd_soc_set_runtime_hwparams(substream, &xlnx_pcm_hardware);
runtime->private_data = stream_data;
- /* Resize the period size divisible by 64 */
+ /* Resize the period bytes as divisible by 64 */
err = snd_pcm_hw_constraint_step(runtime, 0,
- SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 64);
+ SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
+ XLNX_AUD_ALIGN_BYTES);
if (err) {
dev_err(component->dev,
- "unable to set constraint on period bytes\n");
+ "Unable to set constraint on period bytes\n");
+ return err;
+ }
+
+ /* Resize the buffer bytes as divisible by 64 */
+ err = snd_pcm_hw_constraint_step(runtime, 0,
+ SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
+ XLNX_AUD_ALIGN_BYTES);
+ if (err) {
+ dev_err(component->dev,
+ "Unable to set constraint on buffer bytes\n");
+ return err;
+ }
+
+ /* Set periods as integer multiple */
+ err = snd_pcm_hw_constraint_integer(runtime,
+ SNDRV_PCM_HW_PARAM_PERIODS);
+ if (err < 0) {
+ dev_err(component->dev,
+ "Unable to set constraint on periods to be integer\n");
return err;
}
@@ -429,11 +460,25 @@ static int xlnx_formatter_pcm_hw_params(struct snd_soc_component *component,
u64 size;
struct snd_pcm_runtime *runtime = substream->runtime;
struct xlnx_pcm_stream_param *stream_data = runtime->private_data;
+ struct xlnx_pcm_drv_data *adata = dev_get_drvdata(component->dev);
active_ch = params_channels(params);
if (active_ch > stream_data->ch_limit)
return -EINVAL;
+ if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
+ adata->sysclk) {
+ unsigned int mclk_fs = adata->sysclk / params_rate(params);
+
+ if (adata->sysclk % params_rate(params) != 0) {
+ dev_warn(component->dev, "sysclk %u not divisible by rate %u\n",
+ adata->sysclk, params_rate(params));
+ return -EINVAL;
+ }
+
+ writel(mclk_fs, stream_data->mmio + XLNX_AUD_FS_MULTIPLIER);
+ }
+
if (substream->stream == SNDRV_PCM_STREAM_CAPTURE &&
stream_data->xfer_mode == AES_TO_PCM) {
val = readl(stream_data->mmio + XLNX_AUD_STS);
@@ -530,13 +575,14 @@ static int xlnx_formatter_pcm_new(struct snd_soc_component *component,
}
static const struct snd_soc_component_driver xlnx_asoc_component = {
- .name = DRV_NAME,
- .open = xlnx_formatter_pcm_open,
- .close = xlnx_formatter_pcm_close,
- .hw_params = xlnx_formatter_pcm_hw_params,
- .trigger = xlnx_formatter_pcm_trigger,
- .pointer = xlnx_formatter_pcm_pointer,
- .pcm_construct = xlnx_formatter_pcm_new,
+ .name = DRV_NAME,
+ .set_sysclk = xlnx_formatter_set_sysclk,
+ .open = xlnx_formatter_pcm_open,
+ .close = xlnx_formatter_pcm_close,
+ .hw_params = xlnx_formatter_pcm_hw_params,
+ .trigger = xlnx_formatter_pcm_trigger,
+ .pointer = xlnx_formatter_pcm_pointer,
+ .pcm_construct = xlnx_formatter_pcm_new,
};
static int xlnx_formatter_pcm_probe(struct platform_device *pdev)
@@ -657,7 +703,7 @@ static int xlnx_formatter_pcm_remove(struct platform_device *pdev)
dev_err(&pdev->dev, "audio formatter reset failed\n");
clk_disable_unprepare(adata->axi_clk);
- return ret;
+ return 0;
}
static const struct of_device_id xlnx_formatter_pcm_of_match[] = {
diff --git a/sound/soc/xilinx/xlnx_i2s.c b/sound/soc/xilinx/xlnx_i2s.c
index cc641e582c82..9de92d35e30e 100644
--- a/sound/soc/xilinx/xlnx_i2s.c
+++ b/sound/soc/xilinx/xlnx_i2s.c
@@ -18,19 +18,71 @@
#define DRV_NAME "xlnx_i2s"
#define I2S_CORE_CTRL_OFFSET 0x08
+#define I2S_CORE_CTRL_32BIT_LRCLK BIT(3)
+#define I2S_CORE_CTRL_ENABLE BIT(0)
#define I2S_I2STIM_OFFSET 0x20
#define I2S_CH0_OFFSET 0x30
#define I2S_I2STIM_VALID_MASK GENMASK(7, 0)
+struct xlnx_i2s_drv_data {
+ struct snd_soc_dai_driver dai_drv;
+ void __iomem *base;
+ unsigned int sysclk;
+ u32 data_width;
+ u32 channels;
+ bool is_32bit_lrclk;
+ struct snd_ratnum ratnum;
+ struct snd_pcm_hw_constraint_ratnums rate_constraints;
+};
+
static int xlnx_i2s_set_sclkout_div(struct snd_soc_dai *cpu_dai,
int div_id, int div)
{
- void __iomem *base = snd_soc_dai_get_drvdata(cpu_dai);
+ struct xlnx_i2s_drv_data *drv_data = snd_soc_dai_get_drvdata(cpu_dai);
if (!div || (div & ~I2S_I2STIM_VALID_MASK))
return -EINVAL;
- writel(div, base + I2S_I2STIM_OFFSET);
+ drv_data->sysclk = 0;
+
+ writel(div, drv_data->base + I2S_I2STIM_OFFSET);
+
+ return 0;
+}
+
+static int xlnx_i2s_set_sysclk(struct snd_soc_dai *dai,
+ int clk_id, unsigned int freq, int dir)
+{
+ struct xlnx_i2s_drv_data *drv_data = snd_soc_dai_get_drvdata(dai);
+
+ drv_data->sysclk = freq;
+ if (freq) {
+ unsigned int bits_per_sample;
+
+ if (drv_data->is_32bit_lrclk)
+ bits_per_sample = 32;
+ else
+ bits_per_sample = drv_data->data_width;
+
+ drv_data->ratnum.num = freq / (bits_per_sample * drv_data->channels) / 2;
+ drv_data->ratnum.den_step = 1;
+ drv_data->ratnum.den_min = 1;
+ drv_data->ratnum.den_max = 255;
+ drv_data->rate_constraints.rats = &drv_data->ratnum;
+ drv_data->rate_constraints.nrats = 1;
+ }
+ return 0;
+}
+
+static int xlnx_i2s_startup(struct snd_pcm_substream *substream,
+ struct snd_soc_dai *dai)
+{
+ struct xlnx_i2s_drv_data *drv_data = snd_soc_dai_get_drvdata(dai);
+
+ if (drv_data->sysclk)
+ return snd_pcm_hw_constraint_ratnums(substream->runtime, 0,
+ SNDRV_PCM_HW_PARAM_RATE,
+ &drv_data->rate_constraints);
return 0;
}
@@ -40,13 +92,33 @@ static int xlnx_i2s_hw_params(struct snd_pcm_substream *substream,
struct snd_soc_dai *i2s_dai)
{
u32 reg_off, chan_id;
- void __iomem *base = snd_soc_dai_get_drvdata(i2s_dai);
+ struct xlnx_i2s_drv_data *drv_data = snd_soc_dai_get_drvdata(i2s_dai);
+
+ if (drv_data->sysclk) {
+ unsigned int bits_per_sample, sclk, sclk_div;
+
+ if (drv_data->is_32bit_lrclk)
+ bits_per_sample = 32;
+ else
+ bits_per_sample = drv_data->data_width;
+
+ sclk = params_rate(params) * bits_per_sample * params_channels(params);
+ sclk_div = drv_data->sysclk / sclk / 2;
+
+ if ((drv_data->sysclk % sclk != 0) ||
+ !sclk_div || (sclk_div & ~I2S_I2STIM_VALID_MASK)) {
+ dev_warn(i2s_dai->dev, "invalid SCLK divisor for sysclk %u and sclk %u\n",
+ drv_data->sysclk, sclk);
+ return -EINVAL;
+ }
+ writel(sclk_div, drv_data->base + I2S_I2STIM_OFFSET);
+ }
chan_id = params_channels(params) / 2;
while (chan_id > 0) {
reg_off = I2S_CH0_OFFSET + ((chan_id - 1) * 4);
- writel(chan_id, base + reg_off);
+ writel(chan_id, drv_data->base + reg_off);
chan_id--;
}
@@ -56,18 +128,18 @@ static int xlnx_i2s_hw_params(struct snd_pcm_substream *substream,
static int xlnx_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
struct snd_soc_dai *i2s_dai)
{
- void __iomem *base = snd_soc_dai_get_drvdata(i2s_dai);
+ struct xlnx_i2s_drv_data *drv_data = snd_soc_dai_get_drvdata(i2s_dai);
switch (cmd) {
case SNDRV_PCM_TRIGGER_START:
case SNDRV_PCM_TRIGGER_RESUME:
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
- writel(1, base + I2S_CORE_CTRL_OFFSET);
+ writel(I2S_CORE_CTRL_ENABLE, drv_data->base + I2S_CORE_CTRL_OFFSET);
break;
case SNDRV_PCM_TRIGGER_STOP:
case SNDRV_PCM_TRIGGER_SUSPEND:
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
- writel(0, base + I2S_CORE_CTRL_OFFSET);
+ writel(0, drv_data->base + I2S_CORE_CTRL_OFFSET);
break;
default:
return -EINVAL;
@@ -78,12 +150,15 @@ static int xlnx_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
static const struct snd_soc_dai_ops xlnx_i2s_dai_ops = {
.trigger = xlnx_i2s_trigger,
+ .set_sysclk = xlnx_i2s_set_sysclk,
.set_clkdiv = xlnx_i2s_set_sclkout_div,
+ .startup = xlnx_i2s_startup,
.hw_params = xlnx_i2s_hw_params
};
static const struct snd_soc_component_driver xlnx_i2s_component = {
.name = DRV_NAME,
+ .legacy_dai_naming = 1,
};
static const struct of_device_id xlnx_i2s_of_match[] = {
@@ -95,34 +170,33 @@ MODULE_DEVICE_TABLE(of, xlnx_i2s_of_match);
static int xlnx_i2s_probe(struct platform_device *pdev)
{
- void __iomem *base;
- struct snd_soc_dai_driver *dai_drv;
+ struct xlnx_i2s_drv_data *drv_data;
int ret;
- u32 ch, format, data_width;
+ u32 format;
struct device *dev = &pdev->dev;
struct device_node *node = dev->of_node;
- dai_drv = devm_kzalloc(&pdev->dev, sizeof(*dai_drv), GFP_KERNEL);
- if (!dai_drv)
+ drv_data = devm_kzalloc(&pdev->dev, sizeof(*drv_data), GFP_KERNEL);
+ if (!drv_data)
return -ENOMEM;
- base = devm_platform_ioremap_resource(pdev, 0);
- if (IS_ERR(base))
- return PTR_ERR(base);
+ drv_data->base = devm_platform_ioremap_resource(pdev, 0);
+ if (IS_ERR(drv_data->base))
+ return PTR_ERR(drv_data->base);
- ret = of_property_read_u32(node, "xlnx,num-channels", &ch);
+ ret = of_property_read_u32(node, "xlnx,num-channels", &drv_data->channels);
if (ret < 0) {
dev_err(dev, "cannot get supported channels\n");
return ret;
}
- ch = ch * 2;
+ drv_data->channels *= 2;
- ret = of_property_read_u32(node, "xlnx,dwidth", &data_width);
+ ret = of_property_read_u32(node, "xlnx,dwidth", &drv_data->data_width);
if (ret < 0) {
dev_err(dev, "cannot get data width\n");
return ret;
}
- switch (data_width) {
+ switch (drv_data->data_width) {
case 16:
format = SNDRV_PCM_FMTBIT_S16_LE;
break;
@@ -134,35 +208,37 @@ static int xlnx_i2s_probe(struct platform_device *pdev)
}
if (of_device_is_compatible(node, "xlnx,i2s-transmitter-1.0")) {
- dai_drv->name = "xlnx_i2s_playback";
- dai_drv->playback.stream_name = "Playback";
- dai_drv->playback.formats = format;
- dai_drv->playback.channels_min = ch;
- dai_drv->playback.channels_max = ch;
- dai_drv->playback.rates = SNDRV_PCM_RATE_8000_192000;
- dai_drv->ops = &xlnx_i2s_dai_ops;
+ drv_data->dai_drv.name = "xlnx_i2s_playback";
+ drv_data->dai_drv.playback.stream_name = "Playback";
+ drv_data->dai_drv.playback.formats = format;
+ drv_data->dai_drv.playback.channels_min = drv_data->channels;
+ drv_data->dai_drv.playback.channels_max = drv_data->channels;
+ drv_data->dai_drv.playback.rates = SNDRV_PCM_RATE_8000_192000;
+ drv_data->dai_drv.ops = &xlnx_i2s_dai_ops;
} else if (of_device_is_compatible(node, "xlnx,i2s-receiver-1.0")) {
- dai_drv->name = "xlnx_i2s_capture";
- dai_drv->capture.stream_name = "Capture";
- dai_drv->capture.formats = format;
- dai_drv->capture.channels_min = ch;
- dai_drv->capture.channels_max = ch;
- dai_drv->capture.rates = SNDRV_PCM_RATE_8000_192000;
- dai_drv->ops = &xlnx_i2s_dai_ops;
+ drv_data->dai_drv.name = "xlnx_i2s_capture";
+ drv_data->dai_drv.capture.stream_name = "Capture";
+ drv_data->dai_drv.capture.formats = format;
+ drv_data->dai_drv.capture.channels_min = drv_data->channels;
+ drv_data->dai_drv.capture.channels_max = drv_data->channels;
+ drv_data->dai_drv.capture.rates = SNDRV_PCM_RATE_8000_192000;
+ drv_data->dai_drv.ops = &xlnx_i2s_dai_ops;
} else {
return -ENODEV;
}
+ drv_data->is_32bit_lrclk = readl(drv_data->base + I2S_CORE_CTRL_OFFSET) &
+ I2S_CORE_CTRL_32BIT_LRCLK;
- dev_set_drvdata(&pdev->dev, base);
+ dev_set_drvdata(&pdev->dev, drv_data);
ret = devm_snd_soc_register_component(&pdev->dev, &xlnx_i2s_component,
- dai_drv, 1);
+ &drv_data->dai_drv, 1);
if (ret) {
dev_err(&pdev->dev, "i2s component registration failed\n");
return ret;
}
- dev_info(&pdev->dev, "%s DAI registered\n", dai_drv->name);
+ dev_info(&pdev->dev, "%s DAI registered\n", drv_data->dai_drv.name);
return ret;
}
diff --git a/sound/soc/xilinx/xlnx_spdif.c b/sound/soc/xilinx/xlnx_spdif.c
index e2ca087adee6..7342048e9875 100644
--- a/sound/soc/xilinx/xlnx_spdif.c
+++ b/sound/soc/xilinx/xlnx_spdif.c
@@ -226,6 +226,7 @@ static struct snd_soc_dai_driver xlnx_spdif_rx_dai = {
static const struct snd_soc_component_driver xlnx_spdif_component = {
.name = "xlnx-spdif",
+ .legacy_dai_naming = 1,
};
static const struct of_device_id xlnx_spdif_of_match[] = {
@@ -237,7 +238,6 @@ MODULE_DEVICE_TABLE(of, xlnx_spdif_of_match);
static int xlnx_spdif_probe(struct platform_device *pdev)
{
int ret;
- struct resource *res;
struct snd_soc_dai_driver *dai_drv;
struct spdif_dev_data *ctx;
@@ -273,13 +273,10 @@ static int xlnx_spdif_probe(struct platform_device *pdev)
if (ctx->mode) {
dai_drv = &xlnx_spdif_tx_dai;
} else {
- res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
- if (!res) {
- dev_err(dev, "No IRQ resource found\n");
- ret = -ENODEV;
+ ret = platform_get_irq(pdev, 0);
+ if (ret < 0)
goto clk_err;
- }
- ret = devm_request_irq(dev, res->start,
+ ret = devm_request_irq(dev, ret,
xlnx_spdifrx_irq_handler,
0, "XLNX_SPDIF_RX", ctx);
if (ret) {