Commit 71d8c2d7 authored by Mark Brown's avatar Mark Brown

Merge remote-tracking branches 'asoc/topic/qcom', 'asoc/topic/rcar',...

Merge remote-tracking branches 'asoc/topic/qcom', 'asoc/topic/rcar', 'asoc/topic/rt286' and 'asoc/topic/rt5640' into asoc-next
* Qualcomm Technologies APQ8016 SBC ASoC machine driver
This node models the Qualcomm Technologies APQ8016 SBC ASoC machine driver
Required properties:
- compatible : "qcom,apq8016-sbc-sndcard"
- pinctrl-N : One property must exist for each entry in
pinctrl-names. See ../pinctrl/pinctrl-bindings.txt
for details of the property values.
- pinctrl-names : Must contain a "default" entry.
- reg : Must contain an address for each entry in reg-names.
- reg-names : A list which must include the following entries:
* "mic-iomux"
* "spkr-iomux"
- qcom,model : Name of the sound card.
Dai-link subnode properties and subnodes:
Required dai-link subnodes:
- cpu : CPU sub-node
- codec : CODEC sub-node
Required CPU/CODEC subnodes properties:
-link-name : Name of the dai link.
-sound-dai : phandle and port of CPU/CODEC
-capture-dai : phandle and port of CPU/CODEC
Example:
sound: sound {
compatible = "qcom,apq8016-sbc-sndcard";
reg = <0x07702000 0x4>, <0x07702004 0x4>;
reg-names = "mic-iomux", "spkr-iomux";
qcom,model = "DB410c";
/* I2S - Internal codec */
internal-dai-link@0 {
cpu { /* PRIMARY */
sound-dai = <&lpass MI2S_PRIMARY>;
};
codec {
sound-dai = <&wcd_codec 0>;
};
};
/* External Primary or External Secondary -ADV7533 HDMI */
external-dai-link@0 {
link-name = "ADV7533";
cpu { /* QUAT */
sound-dai = <&lpass MI2S_QUATERNARY>;
};
codec {
sound-dai = <&adv_bridge 0>;
};
};
};
...@@ -509,6 +509,11 @@ config SND_SOC_RL6231 ...@@ -509,6 +509,11 @@ config SND_SOC_RL6231
default m if SND_SOC_RT5670=m default m if SND_SOC_RT5670=m
default m if SND_SOC_RT5677=m default m if SND_SOC_RT5677=m
config SND_SOC_RL6347A
tristate
default y if SND_SOC_RT286=y
default m if SND_SOC_RT286=m
config SND_SOC_RT286 config SND_SOC_RT286
tristate tristate
depends on I2C depends on I2C
......
...@@ -77,6 +77,7 @@ snd-soc-pcm512x-objs := pcm512x.o ...@@ -77,6 +77,7 @@ snd-soc-pcm512x-objs := pcm512x.o
snd-soc-pcm512x-i2c-objs := pcm512x-i2c.o snd-soc-pcm512x-i2c-objs := pcm512x-i2c.o
snd-soc-pcm512x-spi-objs := pcm512x-spi.o snd-soc-pcm512x-spi-objs := pcm512x-spi.o
snd-soc-rl6231-objs := rl6231.o snd-soc-rl6231-objs := rl6231.o
snd-soc-rl6347a-objs := rl6347a.o
snd-soc-rt286-objs := rt286.o snd-soc-rt286-objs := rt286.o
snd-soc-rt5631-objs := rt5631.o snd-soc-rt5631-objs := rt5631.o
snd-soc-rt5640-objs := rt5640.o snd-soc-rt5640-objs := rt5640.o
...@@ -263,6 +264,7 @@ obj-$(CONFIG_SND_SOC_PCM512x) += snd-soc-pcm512x.o ...@@ -263,6 +264,7 @@ obj-$(CONFIG_SND_SOC_PCM512x) += snd-soc-pcm512x.o
obj-$(CONFIG_SND_SOC_PCM512x_I2C) += snd-soc-pcm512x-i2c.o obj-$(CONFIG_SND_SOC_PCM512x_I2C) += snd-soc-pcm512x-i2c.o
obj-$(CONFIG_SND_SOC_PCM512x_SPI) += snd-soc-pcm512x-spi.o obj-$(CONFIG_SND_SOC_PCM512x_SPI) += snd-soc-pcm512x-spi.o
obj-$(CONFIG_SND_SOC_RL6231) += snd-soc-rl6231.o obj-$(CONFIG_SND_SOC_RL6231) += snd-soc-rl6231.o
obj-$(CONFIG_SND_SOC_RL6347A) += snd-soc-rl6347a.o
obj-$(CONFIG_SND_SOC_RT286) += snd-soc-rt286.o obj-$(CONFIG_SND_SOC_RT286) += snd-soc-rt286.o
obj-$(CONFIG_SND_SOC_RT5631) += snd-soc-rt5631.o obj-$(CONFIG_SND_SOC_RT5631) += snd-soc-rt5631.o
obj-$(CONFIG_SND_SOC_RT5640) += snd-soc-rt5640.o obj-$(CONFIG_SND_SOC_RT5640) += snd-soc-rt5640.o
......
/*
* rl6347a.c - RL6347A class device shared support
*
* Copyright 2015 Realtek Semiconductor Corp.
*
* Author: Oder Chiou <oder_chiou@realtek.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/pm.h>
#include <linux/i2c.h>
#include <linux/platform_device.h>
#include <linux/spi/spi.h>
#include <linux/dmi.h>
#include <linux/acpi.h>
#include <sound/core.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
#include <sound/soc.h>
#include <sound/soc-dapm.h>
#include <sound/initval.h>
#include <sound/tlv.h>
#include <sound/jack.h>
#include <linux/workqueue.h>
#include <sound/hda_verbs.h>
#include "rl6347a.h"
int rl6347a_hw_write(void *context, unsigned int reg, unsigned int value)
{
struct i2c_client *client = context;
struct rl6347a_priv *rl6347a = i2c_get_clientdata(client);
u8 data[4];
int ret, i;
/* handle index registers */
if (reg <= 0xff) {
rl6347a_hw_write(client, RL6347A_COEF_INDEX, reg);
for (i = 0; i < rl6347a->index_cache_size; i++) {
if (reg == rl6347a->index_cache[i].reg) {
rl6347a->index_cache[i].def = value;
break;
}
}
reg = RL6347A_PROC_COEF;
}
data[0] = (reg >> 24) & 0xff;
data[1] = (reg >> 16) & 0xff;
/*
* 4 bit VID: reg should be 0
* 12 bit VID: value should be 0
* So we use an OR operator to handle it rather than use if condition.
*/
data[2] = ((reg >> 8) & 0xff) | ((value >> 8) & 0xff);
data[3] = value & 0xff;
ret = i2c_master_send(client, data, 4);
if (ret == 4)
return 0;
else
pr_err("ret=%d\n", ret);
if (ret < 0)
return ret;
else
return -EIO;
}
EXPORT_SYMBOL_GPL(rl6347a_hw_write);
int rl6347a_hw_read(void *context, unsigned int reg, unsigned int *value)
{
struct i2c_client *client = context;
struct i2c_msg xfer[2];
int ret;
__be32 be_reg;
unsigned int index, vid, buf = 0x0;
/* handle index registers */
if (reg <= 0xff) {
rl6347a_hw_write(client, RL6347A_COEF_INDEX, reg);
reg = RL6347A_PROC_COEF;
}
reg = reg | 0x80000;
vid = (reg >> 8) & 0xfff;
if (AC_VERB_GET_AMP_GAIN_MUTE == (vid & 0xf00)) {
index = (reg >> 8) & 0xf;
reg = (reg & ~0xf0f) | index;
}
be_reg = cpu_to_be32(reg);
/* Write register */
xfer[0].addr = client->addr;
xfer[0].flags = 0;
xfer[0].len = 4;
xfer[0].buf = (u8 *)&be_reg;
/* Read data */
xfer[1].addr = client->addr;
xfer[1].flags = I2C_M_RD;
xfer[1].len = 4;
xfer[1].buf = (u8 *)&buf;
ret = i2c_transfer(client->adapter, xfer, 2);
if (ret < 0)
return ret;
else if (ret != 2)
return -EIO;
*value = be32_to_cpu(buf);
return 0;
}
EXPORT_SYMBOL_GPL(rl6347a_hw_read);
MODULE_DESCRIPTION("RL6347A class device shared support");
MODULE_AUTHOR("Oder Chiou <oder_chiou@realtek.com>");
MODULE_LICENSE("GPL v2");
/*
* rl6347a.h - RL6347A class device shared support
*
* Copyright 2015 Realtek Semiconductor Corp.
*
* Author: Oder Chiou <oder_chiou@realtek.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#ifndef __RL6347A_H__
#define __RL6347A_H__
#define VERB_CMD(V, N, D) ((N << 20) | (V << 8) | D)
#define RL6347A_VENDOR_REGISTERS 0x20
#define RL6347A_COEF_INDEX\
VERB_CMD(AC_VERB_SET_COEF_INDEX, RL6347A_VENDOR_REGISTERS, 0)
#define RL6347A_PROC_COEF\
VERB_CMD(AC_VERB_SET_PROC_COEF, RL6347A_VENDOR_REGISTERS, 0)
struct rl6347a_priv {
struct reg_default *index_cache;
int index_cache_size;
};
int rl6347a_hw_write(void *context, unsigned int reg, unsigned int value);
int rl6347a_hw_read(void *context, unsigned int reg, unsigned int *value);
#endif /* __RL6347A_H__ */
...@@ -31,12 +31,15 @@ ...@@ -31,12 +31,15 @@
#include <sound/rt286.h> #include <sound/rt286.h>
#include <sound/hda_verbs.h> #include <sound/hda_verbs.h>
#include "rl6347a.h"
#include "rt286.h" #include "rt286.h"
#define RT286_VENDOR_ID 0x10ec0286 #define RT286_VENDOR_ID 0x10ec0286
#define RT288_VENDOR_ID 0x10ec0288 #define RT288_VENDOR_ID 0x10ec0288
struct rt286_priv { struct rt286_priv {
struct reg_default *index_cache;
int index_cache_size;
struct regmap *regmap; struct regmap *regmap;
struct snd_soc_codec *codec; struct snd_soc_codec *codec;
struct rt286_platform_data pdata; struct rt286_platform_data pdata;
...@@ -45,7 +48,6 @@ struct rt286_priv { ...@@ -45,7 +48,6 @@ struct rt286_priv {
struct delayed_work jack_detect_work; struct delayed_work jack_detect_work;
int sys_clk; int sys_clk;
int clk_id; int clk_id;
struct reg_default *index_cache;
}; };
static struct reg_default rt286_index_def[] = { static struct reg_default rt286_index_def[] = {
...@@ -185,94 +187,6 @@ static bool rt286_readable_register(struct device *dev, unsigned int reg) ...@@ -185,94 +187,6 @@ static bool rt286_readable_register(struct device *dev, unsigned int reg)
} }
} }
static int rt286_hw_write(void *context, unsigned int reg, unsigned int value)
{
struct i2c_client *client = context;
struct rt286_priv *rt286 = i2c_get_clientdata(client);
u8 data[4];
int ret, i;
/* handle index registers */
if (reg <= 0xff) {
rt286_hw_write(client, RT286_COEF_INDEX, reg);
for (i = 0; i < INDEX_CACHE_SIZE; i++) {
if (reg == rt286->index_cache[i].reg) {
rt286->index_cache[i].def = value;
break;
}
}
reg = RT286_PROC_COEF;
}
data[0] = (reg >> 24) & 0xff;
data[1] = (reg >> 16) & 0xff;
/*
* 4 bit VID: reg should be 0
* 12 bit VID: value should be 0
* So we use an OR operator to handle it rather than use if condition.
*/
data[2] = ((reg >> 8) & 0xff) | ((value >> 8) & 0xff);
data[3] = value & 0xff;
ret = i2c_master_send(client, data, 4);
if (ret == 4)
return 0;
else
pr_err("ret=%d\n", ret);
if (ret < 0)
return ret;
else
return -EIO;
}
static int rt286_hw_read(void *context, unsigned int reg, unsigned int *value)
{
struct i2c_client *client = context;
struct i2c_msg xfer[2];
int ret;
__be32 be_reg;
unsigned int index, vid, buf = 0x0;
/* handle index registers */
if (reg <= 0xff) {
rt286_hw_write(client, RT286_COEF_INDEX, reg);
reg = RT286_PROC_COEF;
}
reg = reg | 0x80000;
vid = (reg >> 8) & 0xfff;
if (AC_VERB_GET_AMP_GAIN_MUTE == (vid & 0xf00)) {
index = (reg >> 8) & 0xf;
reg = (reg & ~0xf0f) | index;
}
be_reg = cpu_to_be32(reg);
/* Write register */
xfer[0].addr = client->addr;
xfer[0].flags = 0;
xfer[0].len = 4;
xfer[0].buf = (u8 *)&be_reg;
/* Read data */
xfer[1].addr = client->addr;
xfer[1].flags = I2C_M_RD;
xfer[1].len = 4;
xfer[1].buf = (u8 *)&buf;
ret = i2c_transfer(client->adapter, xfer, 2);
if (ret < 0)
return ret;
else if (ret != 2)
return -EIO;
*value = be32_to_cpu(buf);
return 0;
}
#ifdef CONFIG_PM #ifdef CONFIG_PM
static void rt286_index_sync(struct snd_soc_codec *codec) static void rt286_index_sync(struct snd_soc_codec *codec)
{ {
...@@ -1174,8 +1088,8 @@ static const struct regmap_config rt286_regmap = { ...@@ -1174,8 +1088,8 @@ static const struct regmap_config rt286_regmap = {
.max_register = 0x02370100, .max_register = 0x02370100,
.volatile_reg = rt286_volatile_register, .volatile_reg = rt286_volatile_register,
.readable_reg = rt286_readable_register, .readable_reg = rt286_readable_register,
.reg_write = rt286_hw_write, .reg_write = rl6347a_hw_write,
.reg_read = rt286_hw_read, .reg_read = rl6347a_hw_read,
.cache_type = REGCACHE_RBTREE, .cache_type = REGCACHE_RBTREE,
.reg_defaults = rt286_reg, .reg_defaults = rt286_reg,
.num_reg_defaults = ARRAY_SIZE(rt286_reg), .num_reg_defaults = ARRAY_SIZE(rt286_reg),
...@@ -1248,6 +1162,7 @@ static int rt286_i2c_probe(struct i2c_client *i2c, ...@@ -1248,6 +1162,7 @@ static int rt286_i2c_probe(struct i2c_client *i2c,
} }
rt286->index_cache = rt286_index_def; rt286->index_cache = rt286_index_def;
rt286->index_cache_size = INDEX_CACHE_SIZE;
rt286->i2c = i2c; rt286->i2c = i2c;
i2c_set_clientdata(i2c, rt286); i2c_set_clientdata(i2c, rt286);
......
...@@ -51,7 +51,7 @@ static const struct regmap_range_cfg rt5640_ranges[] = { ...@@ -51,7 +51,7 @@ static const struct regmap_range_cfg rt5640_ranges[] = {
.window_len = 0x1, }, .window_len = 0x1, },
}; };
static struct reg_default init_list[] = { static const struct reg_default init_list[] = {
{RT5640_PR_BASE + 0x3d, 0x3600}, {RT5640_PR_BASE + 0x3d, 0x3600},
{RT5640_PR_BASE + 0x12, 0x0aa8}, {RT5640_PR_BASE + 0x12, 0x0aa8},
{RT5640_PR_BASE + 0x14, 0x0aaa}, {RT5640_PR_BASE + 0x14, 0x0aaa},
...@@ -59,7 +59,6 @@ static struct reg_default init_list[] = { ...@@ -59,7 +59,6 @@ static struct reg_default init_list[] = {
{RT5640_PR_BASE + 0x21, 0xe0e0}, {RT5640_PR_BASE + 0x21, 0xe0e0},
{RT5640_PR_BASE + 0x23, 0x1804}, {RT5640_PR_BASE + 0x23, 0x1804},
}; };
#define RT5640_INIT_REG_LEN ARRAY_SIZE(init_list)
static const struct reg_default rt5640_reg[] = { static const struct reg_default rt5640_reg[] = {
{ 0x00, 0x000e }, { 0x00, 0x000e },
...@@ -2122,7 +2121,7 @@ MODULE_DEVICE_TABLE(of, rt5640_of_match); ...@@ -2122,7 +2121,7 @@ MODULE_DEVICE_TABLE(of, rt5640_of_match);
#endif #endif
#ifdef CONFIG_ACPI #ifdef CONFIG_ACPI
static struct acpi_device_id rt5640_acpi_match[] = { static const struct acpi_device_id rt5640_acpi_match[] = {
{ "INT33CA", 0 }, { "INT33CA", 0 },
{ "10EC5640", 0 }, { "10EC5640", 0 },
{ "10EC5642", 0 }, { "10EC5642", 0 },
......
...@@ -32,3 +32,12 @@ config SND_SOC_STORM ...@@ -32,3 +32,12 @@ config SND_SOC_STORM
help help
Say Y or M if you want add support for SoC audio on the Say Y or M if you want add support for SoC audio on the
Qualcomm Technologies IPQ806X-based Storm board. Qualcomm Technologies IPQ806X-based Storm board.
config SND_SOC_APQ8016_SBC
tristate "SoC Audio support for APQ8016 SBC platforms"
depends on SND_SOC_QCOM && (ARCH_QCOM || COMPILE_TEST)
select SND_SOC_LPASS_APQ8016
help
Support for Qualcomm Technologies LPASS audio block in
APQ8016 SOC-based systems.
Say Y if you want to use audio devices on MI2S.
...@@ -11,5 +11,7 @@ obj-$(CONFIG_SND_SOC_LPASS_APQ8016) += snd-soc-lpass-apq8016.o ...@@ -11,5 +11,7 @@ obj-$(CONFIG_SND_SOC_LPASS_APQ8016) += snd-soc-lpass-apq8016.o
# Machine # Machine
snd-soc-storm-objs := storm.o snd-soc-storm-objs := storm.o
snd-soc-apq8016-sbc-objs := apq8016_sbc.o
obj-$(CONFIG_SND_SOC_STORM) += snd-soc-storm.o obj-$(CONFIG_SND_SOC_STORM) += snd-soc-storm.o
obj-$(CONFIG_SND_SOC_APQ8016_SBC) += snd-soc-apq8016-sbc.o
/*
* Copyright (c) 2015 The Linux Foundation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
* only version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include <linux/device.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/io.h>
#include <linux/of.h>
#include <linux/clk.h>
#include <linux/platform_device.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
#include <sound/soc.h>
#include <dt-bindings/sound/apq8016-lpass.h>
struct apq8016_sbc_data {
void __iomem *mic_iomux;
void __iomem *spkr_iomux;
struct snd_soc_dai_link dai_link[]; /* dynamically allocated */
};
#define MIC_CTRL_QUA_WS_SLAVE_SEL_10 BIT(17)
#define MIC_CTRL_TLMM_SCLK_EN BIT(1)
#define SPKR_CTL_PRI_WS_SLAVE_SEL_11 (BIT(17) | BIT(16))
static int apq8016_sbc_dai_init(struct snd_soc_pcm_runtime *rtd)
{
struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
struct snd_soc_card *card = rtd->card;
struct apq8016_sbc_data *pdata = snd_soc_card_get_drvdata(card);
int rval = 0;
switch (cpu_dai->id) {
case MI2S_PRIMARY:
writel(readl(pdata->spkr_iomux) | SPKR_CTL_PRI_WS_SLAVE_SEL_11,
pdata->spkr_iomux);
break;
case MI2S_QUATERNARY:
/* Configure the Quat MI2S to TLMM */
writel(readl(pdata->mic_iomux) | MIC_CTRL_QUA_WS_SLAVE_SEL_10 |
MIC_CTRL_TLMM_SCLK_EN,
pdata->mic_iomux);
break;
default:
dev_err(card->dev, "unsupported cpu dai configuration\n");
rval = -EINVAL;
break;
}
return rval;
}
static struct apq8016_sbc_data *apq8016_sbc_parse_of(struct snd_soc_card *card)
{
struct device *dev = card->dev;
struct snd_soc_dai_link *link;
struct device_node *np, *codec, *cpu, *node = dev->of_node;
struct apq8016_sbc_data *data;
int ret, num_links;
ret = snd_soc_of_parse_card_name(card, "qcom,model");
if (ret) {
dev_err(dev, "Error parsing card name: %d\n", ret);
return ERR_PTR(ret);
}
/* Populate links */
num_links = of_get_child_count(node);
/* Allocate the private data and the DAI link array */
data = devm_kzalloc(dev, sizeof(*data) + sizeof(*link) * num_links,
GFP_KERNEL);
if (!data)
return ERR_PTR(-ENOMEM);
card->dai_link = &data->dai_link[0];
card->num_links = num_links;
link = data->dai_link;
for_each_child_of_node(node, np) {
cpu = of_get_child_by_name(np, "cpu");
codec = of_get_child_by_name(np, "codec");
if (!cpu || !codec) {
dev_err(dev, "Can't find cpu/codec DT node\n");
return ERR_PTR(-EINVAL);
}
link->cpu_of_node = of_parse_phandle(cpu, "sound-dai", 0);
if (!link->cpu_of_node) {
dev_err(card->dev, "error getting cpu phandle\n");
return ERR_PTR(-EINVAL);
}
link->codec_of_node = of_parse_phandle(codec, "sound-dai", 0);
if (!link->codec_of_node) {
dev_err(card->dev, "error getting codec phandle\n");
return ERR_PTR(-EINVAL);
}
ret = snd_soc_of_get_dai_name(cpu, &link->cpu_dai_name);
if (ret) {
dev_err(card->dev, "error getting cpu dai name\n");
return ERR_PTR(ret);
}
ret = snd_soc_of_get_dai_name(codec, &link->codec_dai_name);
if (ret) {
dev_err(card->dev, "error getting codec dai name\n");
return ERR_PTR(ret);
}
link->platform_of_node = link->cpu_of_node;
/* For now we only support playback */
link->playback_only = true;
ret = of_property_read_string(np, "link-name", &link->name);
if (ret) {
dev_err(card->dev, "error getting codec dai_link name\n");
return ERR_PTR(ret);
}
link->stream_name = link->name;
link->init = apq8016_sbc_dai_init;
link++;
}
return data;
}
static int apq8016_sbc_platform_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct snd_soc_card *card;
struct apq8016_sbc_data *data;
struct resource *res;
card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
if (!card)
return -ENOMEM;
card->dev = dev;
data = apq8016_sbc_parse_of(card);
if (IS_ERR(data)) {
dev_err(&pdev->dev, "Error resolving dai links: %ld\n",
PTR_ERR(data));
return PTR_ERR(data);
}
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mic-iomux");
data->mic_iomux = devm_ioremap_resource(dev, res);
if (IS_ERR(data->mic_iomux))
return PTR_ERR(data->mic_iomux);
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "spkr-iomux");
data->spkr_iomux = devm_ioremap_resource(dev, res);
if (IS_ERR(data->spkr_iomux))
return PTR_ERR(data->spkr_iomux);
platform_set_drvdata(pdev, data);
snd_soc_card_set_drvdata(card, data);
return devm_snd_soc_register_card(&pdev->dev, card);
}
static const struct of_device_id apq8016_sbc_device_id[] = {
{ .compatible = "qcom,apq8016-sbc-sndcard" },
{},
};
MODULE_DEVICE_TABLE(of, apq8016_sbc_device_id);
static struct platform_driver apq8016_sbc_platform_driver = {
.driver = {
.name = "qcom-apq8016-sbc",
.of_match_table = of_match_ptr(apq8016_sbc_device_id),
},
.probe = apq8016_sbc_platform_probe,
};
module_platform_driver(apq8016_sbc_platform_driver);
MODULE_AUTHOR("Srinivas Kandagatla <srinivas.kandagatla@linaro.org");
MODULE_DESCRIPTION("APQ8016 ASoC Machine Driver");
MODULE_LICENSE("GPL v2");
...@@ -69,11 +69,6 @@ static struct snd_soc_dai_link storm_dai_link = { ...@@ -69,11 +69,6 @@ static struct snd_soc_dai_link storm_dai_link = {
.ops = &storm_soc_ops, .ops = &storm_soc_ops,
}; };
static struct snd_soc_card storm_soc_card = {
.name = "ipq806x-storm",
.dev = NULL,
};
static int storm_parse_of(struct snd_soc_card *card) static int storm_parse_of(struct snd_soc_card *card)
{ {
struct snd_soc_dai_link *dai_link = card->dai_link; struct snd_soc_dai_link *dai_link = card->dai_link;
...@@ -99,14 +94,13 @@ static int storm_parse_of(struct snd_soc_card *card) ...@@ -99,14 +94,13 @@ static int storm_parse_of(struct snd_soc_card *card)
static int storm_platform_probe(struct platform_device *pdev) static int storm_platform_probe(struct platform_device *pdev)
{ {
struct snd_soc_card *card = &storm_soc_card; struct snd_soc_card *card;
int ret; int ret;
if (card->dev) { card = devm_kzalloc(&pdev->dev, sizeof(*card), GFP_KERNEL);
dev_err(&pdev->dev, "%s() error, existing soundcard\n", if (!card)
__func__); return -ENOMEM;
return -ENODEV;
}
card->dev = &pdev->dev; card->dev = &pdev->dev;
platform_set_drvdata(pdev, card); platform_set_drvdata(pdev, card);
...@@ -128,16 +122,12 @@ static int storm_platform_probe(struct platform_device *pdev) ...@@ -128,16 +122,12 @@ static int storm_platform_probe(struct platform_device *pdev)
} }
ret = devm_snd_soc_register_card(&pdev->dev, card); ret = devm_snd_soc_register_card(&pdev->dev, card);
if (ret == -EPROBE_DEFER) { if (ret)
card->dev = NULL;
return ret;
} else if (ret) {
dev_err(&pdev->dev, "%s() error registering soundcard: %d\n", dev_err(&pdev->dev, "%s() error registering soundcard: %d\n",
__func__, ret); __func__, ret);
return ret; return ret;
}
return 0;
} }
#ifdef CONFIG_OF #ifdef CONFIG_OF
......
...@@ -137,15 +137,17 @@ char *rsnd_mod_name(struct rsnd_mod *mod) ...@@ -137,15 +137,17 @@ char *rsnd_mod_name(struct rsnd_mod *mod)
return mod->ops->name; return mod->ops->name;
} }
struct dma_chan *rsnd_mod_dma_req(struct rsnd_mod *mod) struct dma_chan *rsnd_mod_dma_req(struct rsnd_dai_stream *io,
struct rsnd_mod *mod)
{ {
if (!mod || !mod->ops || !mod->ops->dma_req) if (!mod || !mod->ops || !mod->ops->dma_req)
return NULL; return NULL;
return mod->ops->dma_req(mod); return mod->ops->dma_req(io, mod);
} }
int rsnd_mod_init(struct rsnd_mod *mod, int rsnd_mod_init(struct rsnd_priv *priv,
struct rsnd_mod *mod,
struct rsnd_mod_ops *ops, struct rsnd_mod_ops *ops,
struct clk *clk, struct clk *clk,
enum rsnd_mod_type type, enum rsnd_mod_type type,
...@@ -160,6 +162,7 @@ int rsnd_mod_init(struct rsnd_mod *mod, ...@@ -160,6 +162,7 @@ int rsnd_mod_init(struct rsnd_mod *mod,
mod->ops = ops; mod->ops = ops;
mod->type = type; mod->type = type;
mod->clk = clk; mod->clk = clk;
mod->priv = priv;
return ret; return ret;
} }
...@@ -170,10 +173,31 @@ void rsnd_mod_quit(struct rsnd_mod *mod) ...@@ -170,10 +173,31 @@ void rsnd_mod_quit(struct rsnd_mod *mod)
clk_unprepare(mod->clk); clk_unprepare(mod->clk);
} }
int rsnd_mod_is_working(struct rsnd_mod *mod) void rsnd_mod_interrupt(struct rsnd_mod *mod,
void (*callback)(struct rsnd_mod *mod,
struct rsnd_dai_stream *io))
{ {
struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
struct rsnd_dai_stream *io;
struct rsnd_dai *rdai;
int i, j;
for_each_rsnd_dai(rdai, priv, j) {
for (i = 0; i < RSND_MOD_MAX; i++) {
io = &rdai->playback;
if (mod == io->mod[i])
callback(mod, io);
io = &rdai->capture;
if (mod == io->mod[i])
callback(mod, io);
}
}
}
int rsnd_io_is_working(struct rsnd_dai_stream *io)
{
/* see rsnd_dai_stream_init/quit() */ /* see rsnd_dai_stream_init/quit() */
return !!io->substream; return !!io->substream;
} }
...@@ -181,10 +205,9 @@ int rsnd_mod_is_working(struct rsnd_mod *mod) ...@@ -181,10 +205,9 @@ int rsnd_mod_is_working(struct rsnd_mod *mod)
/* /*
* settting function * settting function
*/ */
u32 rsnd_get_adinr(struct rsnd_mod *mod) u32 rsnd_get_adinr(struct rsnd_mod *mod, struct rsnd_dai_stream *io)
{ {
struct rsnd_priv *priv = rsnd_mod_to_priv(mod); struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
struct device *dev = rsnd_priv_to_dev(priv); struct device *dev = rsnd_priv_to_dev(priv);
u32 adinr = runtime->channels; u32 adinr = runtime->channels;
...@@ -207,26 +230,31 @@ u32 rsnd_get_adinr(struct rsnd_mod *mod) ...@@ -207,26 +230,31 @@ u32 rsnd_get_adinr(struct rsnd_mod *mod)
/* /*
* rsnd_dai functions * rsnd_dai functions
*/ */
#define __rsnd_mod_call(mod, func, param...) \ #define __rsnd_mod_call(mod, io, func, param...) \
({ \ ({ \
struct rsnd_priv *priv = rsnd_mod_to_priv(mod); \ struct rsnd_priv *priv = rsnd_mod_to_priv(mod); \
struct device *dev = rsnd_priv_to_dev(priv); \ struct device *dev = rsnd_priv_to_dev(priv); \
u32 mask = (1 << __rsnd_mod_shift_##func) & ~(1 << 31); \ u32 mask = 0xF << __rsnd_mod_shift_##func; \
u32 call = __rsnd_mod_call_##func << __rsnd_mod_shift_##func; \ u8 val = (mod->status >> __rsnd_mod_shift_##func) & 0xF; \
u8 add = ((val + __rsnd_mod_add_##func) & 0xF); \
int ret = 0; \ int ret = 0; \
if ((mod->status & mask) == call) { \ int called = 0; \
dev_dbg(dev, "%s[%d] %s\n", \ if (val == __rsnd_mod_call_##func) { \
rsnd_mod_name(mod), rsnd_mod_id(mod), #func); \ called = 1; \
ret = (mod)->ops->func(mod, param); \ ret = (mod)->ops->func(mod, io, param); \
mod->status = (mod->status & ~mask) | (~call & mask); \ mod->status = (mod->status & ~mask) + \
(add << __rsnd_mod_shift_##func); \
} \ } \
dev_dbg(dev, "%s[%d] 0x%08x %s\n", \
rsnd_mod_name(mod), rsnd_mod_id(mod), mod->status, \
called ? #func : ""); \
ret; \ ret; \
}) })
#define rsnd_mod_call(mod, func, param...) \ #define rsnd_mod_call(mod, io, func, param...) \
(!(mod) ? -ENODEV : \ (!(mod) ? -ENODEV : \
!((mod)->ops->func) ? 0 : \ !((mod)->ops->func) ? 0 : \
__rsnd_mod_call(mod, func, param)) __rsnd_mod_call(mod, io, func, param))
#define rsnd_dai_call(fn, io, param...) \ #define rsnd_dai_call(fn, io, param...) \
({ \ ({ \
...@@ -236,7 +264,7 @@ u32 rsnd_get_adinr(struct rsnd_mod *mod) ...@@ -236,7 +264,7 @@ u32 rsnd_get_adinr(struct rsnd_mod *mod)
mod = (io)->mod[i]; \ mod = (io)->mod[i]; \
if (!mod) \ if (!mod) \
continue; \ continue; \
ret = rsnd_mod_call(mod, fn, param); \ ret = rsnd_mod_call(mod, io, fn, param); \
if (ret < 0) \ if (ret < 0) \
break; \ break; \
} \ } \
...@@ -260,7 +288,6 @@ static int rsnd_dai_connect(struct rsnd_mod *mod, ...@@ -260,7 +288,6 @@ static int rsnd_dai_connect(struct rsnd_mod *mod,
} }
io->mod[mod->type] = mod; io->mod[mod->type] = mod;
mod->io = io;
return 0; return 0;
} }
...@@ -268,7 +295,6 @@ static int rsnd_dai_connect(struct rsnd_mod *mod, ...@@ -268,7 +295,6 @@ static int rsnd_dai_connect(struct rsnd_mod *mod,
static void rsnd_dai_disconnect(struct rsnd_mod *mod, static void rsnd_dai_disconnect(struct rsnd_mod *mod,
struct rsnd_dai_stream *io) struct rsnd_dai_stream *io)
{ {
mod->io = NULL;
io->mod[mod->type] = NULL; io->mod[mod->type] = NULL;
} }
...@@ -302,7 +328,7 @@ int rsnd_dai_pointer_offset(struct rsnd_dai_stream *io, int additional) ...@@ -302,7 +328,7 @@ int rsnd_dai_pointer_offset(struct rsnd_dai_stream *io, int additional)
return pos; return pos;
} }
void rsnd_dai_pointer_update(struct rsnd_dai_stream *io, int byte) bool rsnd_dai_pointer_update(struct rsnd_dai_stream *io, int byte)
{ {
io->byte_pos += byte; io->byte_pos += byte;
...@@ -319,8 +345,24 @@ void rsnd_dai_pointer_update(struct rsnd_dai_stream *io, int byte) ...@@ -319,8 +345,24 @@ void rsnd_dai_pointer_update(struct rsnd_dai_stream *io, int byte)
io->next_period_byte = io->byte_per_period; io->next_period_byte = io->byte_per_period;
} }
snd_pcm_period_elapsed(substream); return true;
} }
return false;
}
void rsnd_dai_period_elapsed(struct rsnd_dai_stream *io)
{
struct snd_pcm_substream *substream = io->substream;
/*
* this function should be called...
*
* - if rsnd_dai_pointer_update() returns true
* - without spin lock
*/
snd_pcm_period_elapsed(substream);
} }
static void rsnd_dai_stream_init(struct rsnd_dai_stream *io, static void rsnd_dai_stream_init(struct rsnd_dai_stream *io,
...@@ -834,16 +876,18 @@ static int rsnd_kctrl_put(struct snd_kcontrol *kctrl, ...@@ -834,16 +876,18 @@ static int rsnd_kctrl_put(struct snd_kcontrol *kctrl,
} }
if (change) if (change)
cfg->update(mod); cfg->update(cfg->io, mod);
return change; return change;
} }
static int __rsnd_kctrl_new(struct rsnd_mod *mod, static int __rsnd_kctrl_new(struct rsnd_mod *mod,
struct rsnd_dai_stream *io,
struct snd_soc_pcm_runtime *rtd, struct snd_soc_pcm_runtime *rtd,
const unsigned char *name, const unsigned char *name,
struct rsnd_kctrl_cfg *cfg, struct rsnd_kctrl_cfg *cfg,
void (*update)(struct rsnd_mod *mod)) void (*update)(struct rsnd_dai_stream *io,
struct rsnd_mod *mod))
{ {
struct snd_soc_card *soc_card = rtd->card; struct snd_soc_card *soc_card = rtd->card;
struct snd_card *card = rtd->card->snd_card; struct snd_card *card = rtd->card->snd_card;
...@@ -872,6 +916,7 @@ static int __rsnd_kctrl_new(struct rsnd_mod *mod, ...@@ -872,6 +916,7 @@ static int __rsnd_kctrl_new(struct rsnd_mod *mod,
cfg->update = update; cfg->update = update;
cfg->card = card; cfg->card = card;
cfg->kctrl = kctrl; cfg->kctrl = kctrl;
cfg->io = io;
return 0; return 0;
} }
...@@ -882,36 +927,42 @@ void _rsnd_kctrl_remove(struct rsnd_kctrl_cfg *cfg) ...@@ -882,36 +927,42 @@ void _rsnd_kctrl_remove(struct rsnd_kctrl_cfg *cfg)
} }
int rsnd_kctrl_new_m(struct rsnd_mod *mod, int rsnd_kctrl_new_m(struct rsnd_mod *mod,
struct rsnd_dai_stream *io,
struct snd_soc_pcm_runtime *rtd, struct snd_soc_pcm_runtime *rtd,
const unsigned char *name, const unsigned char *name,
void (*update)(struct rsnd_mod *mod), void (*update)(struct rsnd_dai_stream *io,
struct rsnd_mod *mod),
struct rsnd_kctrl_cfg_m *_cfg, struct rsnd_kctrl_cfg_m *_cfg,
u32 max) u32 max)
{ {
_cfg->cfg.max = max; _cfg->cfg.max = max;
_cfg->cfg.size = RSND_DVC_CHANNELS; _cfg->cfg.size = RSND_DVC_CHANNELS;
_cfg->cfg.val = _cfg->val; _cfg->cfg.val = _cfg->val;
return __rsnd_kctrl_new(mod, rtd, name, &_cfg->cfg, update); return __rsnd_kctrl_new(mod, io, rtd, name, &_cfg->cfg, update);
} }
int rsnd_kctrl_new_s(struct rsnd_mod *mod, int rsnd_kctrl_new_s(struct rsnd_mod *mod,
struct rsnd_dai_stream *io,
struct snd_soc_pcm_runtime *rtd, struct snd_soc_pcm_runtime *rtd,
const unsigned char *name, const unsigned char *name,
void (*update)(struct rsnd_mod *mod), void (*update)(struct rsnd_dai_stream *io,
struct rsnd_mod *mod),
struct rsnd_kctrl_cfg_s *_cfg, struct rsnd_kctrl_cfg_s *_cfg,
u32 max) u32 max)
{ {
_cfg->cfg.max = max; _cfg->cfg.max = max;
_cfg->cfg.size = 1; _cfg->cfg.size = 1;
_cfg->cfg.val = &_cfg->val; _cfg->cfg.val = &_cfg->val;
return __rsnd_kctrl_new(mod, rtd, name, &_cfg->cfg, update); return __rsnd_kctrl_new(mod, io, rtd, name, &_cfg->cfg, update);
} }
int rsnd_kctrl_new_e(struct rsnd_mod *mod, int rsnd_kctrl_new_e(struct rsnd_mod *mod,
struct rsnd_dai_stream *io,
struct snd_soc_pcm_runtime *rtd, struct snd_soc_pcm_runtime *rtd,
const unsigned char *name, const unsigned char *name,
struct rsnd_kctrl_cfg_s *_cfg, struct rsnd_kctrl_cfg_s *_cfg,
void (*update)(struct rsnd_mod *mod), void (*update)(struct rsnd_dai_stream *io,
struct rsnd_mod *mod),
const char * const *texts, const char * const *texts,
u32 max) u32 max)
{ {
...@@ -919,7 +970,7 @@ int rsnd_kctrl_new_e(struct rsnd_mod *mod, ...@@ -919,7 +970,7 @@ int rsnd_kctrl_new_e(struct rsnd_mod *mod,
_cfg->cfg.size = 1; _cfg->cfg.size = 1;
_cfg->cfg.val = &_cfg->val; _cfg->cfg.val = &_cfg->val;
_cfg->cfg.texts = texts; _cfg->cfg.texts = texts;
return __rsnd_kctrl_new(mod, rtd, name, &_cfg->cfg, update); return __rsnd_kctrl_new(mod, io, rtd, name, &_cfg->cfg, update);
} }
/* /*
......
...@@ -32,11 +32,12 @@ struct rsnd_dma_ctrl { ...@@ -32,11 +32,12 @@ struct rsnd_dma_ctrl {
/* /*
* Audio DMAC * Audio DMAC
*/ */
static void rsnd_dmaen_complete(void *data) static void __rsnd_dmaen_complete(struct rsnd_mod *mod,
struct rsnd_dai_stream *io)
{ {
struct rsnd_dma *dma = (struct rsnd_dma *)data; struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
struct rsnd_mod *mod = rsnd_dma_to_mod(dma); bool elapsed = false;
struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); unsigned long flags;
/* /*
* Renesas sound Gen1 needs 1 DMAC, * Renesas sound Gen1 needs 1 DMAC,
...@@ -49,23 +50,36 @@ static void rsnd_dmaen_complete(void *data) ...@@ -49,23 +50,36 @@ static void rsnd_dmaen_complete(void *data)
* rsnd_dai_pointer_update() will be called twice, * rsnd_dai_pointer_update() will be called twice,
* ant it will breaks io->byte_pos * ant it will breaks io->byte_pos
*/ */
spin_lock_irqsave(&priv->lock, flags);
if (rsnd_io_is_working(io))
elapsed = rsnd_dai_pointer_update(io, io->byte_per_period);
rsnd_dai_pointer_update(io, io->byte_per_period); spin_unlock_irqrestore(&priv->lock, flags);
if (elapsed)
rsnd_dai_period_elapsed(io);
} }
static void rsnd_dmaen_stop(struct rsnd_dma *dma) static void rsnd_dmaen_complete(void *data)
{
struct rsnd_mod *mod = data;
rsnd_mod_interrupt(mod, __rsnd_dmaen_complete);
}
static void rsnd_dmaen_stop(struct rsnd_dai_stream *io, struct rsnd_dma *dma)
{ {
struct rsnd_dmaen *dmaen = rsnd_dma_to_dmaen(dma); struct rsnd_dmaen *dmaen = rsnd_dma_to_dmaen(dma);
dmaengine_terminate_all(dmaen->chan); dmaengine_terminate_all(dmaen->chan);
} }
static void rsnd_dmaen_start(struct rsnd_dma *dma) static void rsnd_dmaen_start(struct rsnd_dai_stream *io, struct rsnd_dma *dma)
{ {
struct rsnd_dmaen *dmaen = rsnd_dma_to_dmaen(dma); struct rsnd_dmaen *dmaen = rsnd_dma_to_dmaen(dma);
struct rsnd_mod *mod = rsnd_dma_to_mod(dma); struct rsnd_mod *mod = rsnd_dma_to_mod(dma);
struct rsnd_priv *priv = rsnd_mod_to_priv(mod); struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
struct snd_pcm_substream *substream = io->substream; struct snd_pcm_substream *substream = io->substream;
struct device *dev = rsnd_priv_to_dev(priv); struct device *dev = rsnd_priv_to_dev(priv);
struct dma_async_tx_descriptor *desc; struct dma_async_tx_descriptor *desc;
...@@ -84,7 +98,7 @@ static void rsnd_dmaen_start(struct rsnd_dma *dma) ...@@ -84,7 +98,7 @@ static void rsnd_dmaen_start(struct rsnd_dma *dma)
} }
desc->callback = rsnd_dmaen_complete; desc->callback = rsnd_dmaen_complete;
desc->callback_param = dma; desc->callback_param = mod;
if (dmaengine_submit(desc) < 0) { if (dmaengine_submit(desc) < 0) {
dev_err(dev, "dmaengine_submit() fail\n"); dev_err(dev, "dmaengine_submit() fail\n");
...@@ -115,7 +129,8 @@ struct dma_chan *rsnd_dma_request_channel(struct device_node *of_node, ...@@ -115,7 +129,8 @@ struct dma_chan *rsnd_dma_request_channel(struct device_node *of_node,
return chan; return chan;
} }
static struct dma_chan *rsnd_dmaen_request_channel(struct rsnd_mod *mod_from, static struct dma_chan *rsnd_dmaen_request_channel(struct rsnd_dai_stream *io,
struct rsnd_mod *mod_from,
struct rsnd_mod *mod_to) struct rsnd_mod *mod_to)
{ {
if ((!mod_from && !mod_to) || if ((!mod_from && !mod_to) ||
...@@ -123,19 +138,19 @@ static struct dma_chan *rsnd_dmaen_request_channel(struct rsnd_mod *mod_from, ...@@ -123,19 +138,19 @@ static struct dma_chan *rsnd_dmaen_request_channel(struct rsnd_mod *mod_from,
return NULL; return NULL;
if (mod_from) if (mod_from)
return rsnd_mod_dma_req(mod_from); return rsnd_mod_dma_req(io, mod_from);
else else
return rsnd_mod_dma_req(mod_to); return rsnd_mod_dma_req(io, mod_to);
} }
static int rsnd_dmaen_init(struct rsnd_priv *priv, struct rsnd_dma *dma, int id, static int rsnd_dmaen_init(struct rsnd_dai_stream *io,
struct rsnd_dma *dma, int id,
struct rsnd_mod *mod_from, struct rsnd_mod *mod_to) struct rsnd_mod *mod_from, struct rsnd_mod *mod_to)
{ {
struct rsnd_dmaen *dmaen = rsnd_dma_to_dmaen(dma); struct rsnd_dmaen *dmaen = rsnd_dma_to_dmaen(dma);
struct rsnd_priv *priv = rsnd_io_to_priv(io);
struct device *dev = rsnd_priv_to_dev(priv); struct device *dev = rsnd_priv_to_dev(priv);
struct dma_slave_config cfg = {}; struct dma_slave_config cfg = {};
struct rsnd_mod *mod = rsnd_dma_to_mod(dma);
struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
int is_play = rsnd_io_is_play(io); int is_play = rsnd_io_is_play(io);
int ret; int ret;
...@@ -145,7 +160,7 @@ static int rsnd_dmaen_init(struct rsnd_priv *priv, struct rsnd_dma *dma, int id, ...@@ -145,7 +160,7 @@ static int rsnd_dmaen_init(struct rsnd_priv *priv, struct rsnd_dma *dma, int id,
} }
if (dev->of_node) { if (dev->of_node) {
dmaen->chan = rsnd_dmaen_request_channel(mod_from, mod_to); dmaen->chan = rsnd_dmaen_request_channel(io, mod_from, mod_to);
} else { } else {
dma_cap_mask_t mask; dma_cap_mask_t mask;
...@@ -177,7 +192,7 @@ static int rsnd_dmaen_init(struct rsnd_priv *priv, struct rsnd_dma *dma, int id, ...@@ -177,7 +192,7 @@ static int rsnd_dmaen_init(struct rsnd_priv *priv, struct rsnd_dma *dma, int id,
return 0; return 0;
rsnd_dma_init_err: rsnd_dma_init_err:
rsnd_dma_quit(dma); rsnd_dma_quit(io, dma);
rsnd_dma_channel_err: rsnd_dma_channel_err:
/* /*
...@@ -189,7 +204,7 @@ static int rsnd_dmaen_init(struct rsnd_priv *priv, struct rsnd_dma *dma, int id, ...@@ -189,7 +204,7 @@ static int rsnd_dmaen_init(struct rsnd_priv *priv, struct rsnd_dma *dma, int id,
return -EAGAIN; return -EAGAIN;
} }
static void rsnd_dmaen_quit(struct rsnd_dma *dma) static void rsnd_dmaen_quit(struct rsnd_dai_stream *io, struct rsnd_dma *dma)
{ {
struct rsnd_dmaen *dmaen = rsnd_dma_to_dmaen(dma); struct rsnd_dmaen *dmaen = rsnd_dma_to_dmaen(dma);
...@@ -238,9 +253,9 @@ static const u8 gen2_id_table_cmd[] = { ...@@ -238,9 +253,9 @@ static const u8 gen2_id_table_cmd[] = {
0x38, /* SCU_CMD1 */ 0x38, /* SCU_CMD1 */
}; };
static u32 rsnd_dmapp_get_id(struct rsnd_mod *mod) static u32 rsnd_dmapp_get_id(struct rsnd_dai_stream *io,
struct rsnd_mod *mod)
{ {
struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
struct rsnd_mod *ssi = rsnd_io_to_mod_ssi(io); struct rsnd_mod *ssi = rsnd_io_to_mod_ssi(io);
struct rsnd_mod *src = rsnd_io_to_mod_src(io); struct rsnd_mod *src = rsnd_io_to_mod_src(io);
struct rsnd_mod *dvc = rsnd_io_to_mod_dvc(io); struct rsnd_mod *dvc = rsnd_io_to_mod_dvc(io);
...@@ -268,11 +283,12 @@ static u32 rsnd_dmapp_get_id(struct rsnd_mod *mod) ...@@ -268,11 +283,12 @@ static u32 rsnd_dmapp_get_id(struct rsnd_mod *mod)
return entry[id]; return entry[id];
} }
static u32 rsnd_dmapp_get_chcr(struct rsnd_mod *mod_from, static u32 rsnd_dmapp_get_chcr(struct rsnd_dai_stream *io,
struct rsnd_mod *mod_from,
struct rsnd_mod *mod_to) struct rsnd_mod *mod_to)
{ {
return (rsnd_dmapp_get_id(mod_from) << 24) + return (rsnd_dmapp_get_id(io, mod_from) << 24) +
(rsnd_dmapp_get_id(mod_to) << 16); (rsnd_dmapp_get_id(io, mod_to) << 16);
} }
#define rsnd_dmapp_addr(dmac, dma, reg) \ #define rsnd_dmapp_addr(dmac, dma, reg) \
...@@ -299,7 +315,7 @@ static u32 rsnd_dmapp_read(struct rsnd_dma *dma, u32 reg) ...@@ -299,7 +315,7 @@ static u32 rsnd_dmapp_read(struct rsnd_dma *dma, u32 reg)
return ioread32(rsnd_dmapp_addr(dmac, dma, reg)); return ioread32(rsnd_dmapp_addr(dmac, dma, reg));
} }
static void rsnd_dmapp_stop(struct rsnd_dma *dma) static void rsnd_dmapp_stop(struct rsnd_dai_stream *io, struct rsnd_dma *dma)
{ {
int i; int i;
...@@ -312,7 +328,7 @@ static void rsnd_dmapp_stop(struct rsnd_dma *dma) ...@@ -312,7 +328,7 @@ static void rsnd_dmapp_stop(struct rsnd_dma *dma)
} }
} }
static void rsnd_dmapp_start(struct rsnd_dma *dma) static void rsnd_dmapp_start(struct rsnd_dai_stream *io, struct rsnd_dma *dma)
{ {
struct rsnd_dmapp *dmapp = rsnd_dma_to_dmapp(dma); struct rsnd_dmapp *dmapp = rsnd_dma_to_dmapp(dma);
...@@ -321,19 +337,21 @@ static void rsnd_dmapp_start(struct rsnd_dma *dma) ...@@ -321,19 +337,21 @@ static void rsnd_dmapp_start(struct rsnd_dma *dma)
rsnd_dmapp_write(dma, dmapp->chcr, PDMACHCR); rsnd_dmapp_write(dma, dmapp->chcr, PDMACHCR);
} }
static int rsnd_dmapp_init(struct rsnd_priv *priv, struct rsnd_dma *dma, int id, static int rsnd_dmapp_init(struct rsnd_dai_stream *io,
struct rsnd_dma *dma, int id,
struct rsnd_mod *mod_from, struct rsnd_mod *mod_to) struct rsnd_mod *mod_from, struct rsnd_mod *mod_to)
{ {
struct rsnd_dmapp *dmapp = rsnd_dma_to_dmapp(dma); struct rsnd_dmapp *dmapp = rsnd_dma_to_dmapp(dma);
struct rsnd_priv *priv = rsnd_io_to_priv(io);
struct rsnd_dma_ctrl *dmac = rsnd_priv_to_dmac(priv); struct rsnd_dma_ctrl *dmac = rsnd_priv_to_dmac(priv);
struct device *dev = rsnd_priv_to_dev(priv); struct device *dev = rsnd_priv_to_dev(priv);
dmapp->dmapp_id = dmac->dmapp_num; dmapp->dmapp_id = dmac->dmapp_num;
dmapp->chcr = rsnd_dmapp_get_chcr(mod_from, mod_to) | PDMACHCR_DE; dmapp->chcr = rsnd_dmapp_get_chcr(io, mod_from, mod_to) | PDMACHCR_DE;
dmac->dmapp_num++; dmac->dmapp_num++;
rsnd_dmapp_stop(dma); rsnd_dmapp_stop(io, dma);
dev_dbg(dev, "id/src/dst/chcr = %d/%pad/%pad/%08x\n", dev_dbg(dev, "id/src/dst/chcr = %d/%pad/%pad/%08x\n",
dmapp->dmapp_id, &dma->src_addr, &dma->dst_addr, dmapp->chcr); dmapp->dmapp_id, &dma->src_addr, &dma->dst_addr, dmapp->chcr);
...@@ -386,12 +404,12 @@ static struct rsnd_dma_ops rsnd_dmapp_ops = { ...@@ -386,12 +404,12 @@ static struct rsnd_dma_ops rsnd_dmapp_ops = {
#define RDMA_CMD_O_P(addr, i) (addr ##_reg - 0x001f8000 + (0x400 * i)) #define RDMA_CMD_O_P(addr, i) (addr ##_reg - 0x001f8000 + (0x400 * i))
static dma_addr_t static dma_addr_t
rsnd_gen2_dma_addr(struct rsnd_priv *priv, rsnd_gen2_dma_addr(struct rsnd_dai_stream *io,
struct rsnd_mod *mod, struct rsnd_mod *mod,
int is_play, int is_from) int is_play, int is_from)
{ {
struct rsnd_priv *priv = rsnd_io_to_priv(io);
struct device *dev = rsnd_priv_to_dev(priv); struct device *dev = rsnd_priv_to_dev(priv);
struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
phys_addr_t ssi_reg = rsnd_gen_get_phy_addr(priv, RSND_GEN2_SSI); phys_addr_t ssi_reg = rsnd_gen_get_phy_addr(priv, RSND_GEN2_SSI);
phys_addr_t src_reg = rsnd_gen_get_phy_addr(priv, RSND_GEN2_SCU); phys_addr_t src_reg = rsnd_gen_get_phy_addr(priv, RSND_GEN2_SCU);
int is_ssi = !!(rsnd_io_to_mod_ssi(io) == mod); int is_ssi = !!(rsnd_io_to_mod_ssi(io) == mod);
...@@ -438,7 +456,7 @@ rsnd_gen2_dma_addr(struct rsnd_priv *priv, ...@@ -438,7 +456,7 @@ rsnd_gen2_dma_addr(struct rsnd_priv *priv,
dev_err(dev, "DVC is selected without SRC\n"); dev_err(dev, "DVC is selected without SRC\n");
/* use SSIU or SSI ? */ /* use SSIU or SSI ? */
if (is_ssi && rsnd_ssi_use_busif(mod)) if (is_ssi && rsnd_ssi_use_busif(io, mod))
is_ssi++; is_ssi++;
return (is_from) ? return (is_from) ?
...@@ -446,10 +464,12 @@ rsnd_gen2_dma_addr(struct rsnd_priv *priv, ...@@ -446,10 +464,12 @@ rsnd_gen2_dma_addr(struct rsnd_priv *priv,
dma_addrs[is_ssi][is_play][use_src + use_dvc].in_addr; dma_addrs[is_ssi][is_play][use_src + use_dvc].in_addr;
} }
static dma_addr_t rsnd_dma_addr(struct rsnd_priv *priv, static dma_addr_t rsnd_dma_addr(struct rsnd_dai_stream *io,
struct rsnd_mod *mod, struct rsnd_mod *mod,
int is_play, int is_from) int is_play, int is_from)
{ {
struct rsnd_priv *priv = rsnd_io_to_priv(io);
/* /*
* gen1 uses default DMA addr * gen1 uses default DMA addr
*/ */
...@@ -459,17 +479,17 @@ static dma_addr_t rsnd_dma_addr(struct rsnd_priv *priv, ...@@ -459,17 +479,17 @@ static dma_addr_t rsnd_dma_addr(struct rsnd_priv *priv,
if (!mod) if (!mod)
return 0; return 0;
return rsnd_gen2_dma_addr(priv, mod, is_play, is_from); return rsnd_gen2_dma_addr(io, mod, is_play, is_from);
} }
#define MOD_MAX 4 /* MEM/SSI/SRC/DVC */ #define MOD_MAX 4 /* MEM/SSI/SRC/DVC */
static void rsnd_dma_of_path(struct rsnd_dma *dma, static void rsnd_dma_of_path(struct rsnd_dma *dma,
struct rsnd_dai_stream *io,
int is_play, int is_play,
struct rsnd_mod **mod_from, struct rsnd_mod **mod_from,
struct rsnd_mod **mod_to) struct rsnd_mod **mod_to)
{ {
struct rsnd_mod *this = rsnd_dma_to_mod(dma); struct rsnd_mod *this = rsnd_dma_to_mod(dma);
struct rsnd_dai_stream *io = rsnd_mod_to_io(this);
struct rsnd_mod *ssi = rsnd_io_to_mod_ssi(io); struct rsnd_mod *ssi = rsnd_io_to_mod_ssi(io);
struct rsnd_mod *src = rsnd_io_to_mod_src(io); struct rsnd_mod *src = rsnd_io_to_mod_src(io);
struct rsnd_mod *dvc = rsnd_io_to_mod_dvc(io); struct rsnd_mod *dvc = rsnd_io_to_mod_dvc(io);
...@@ -524,17 +544,17 @@ static void rsnd_dma_of_path(struct rsnd_dma *dma, ...@@ -524,17 +544,17 @@ static void rsnd_dma_of_path(struct rsnd_dma *dma,
} }
} }
void rsnd_dma_stop(struct rsnd_dma *dma) void rsnd_dma_stop(struct rsnd_dai_stream *io, struct rsnd_dma *dma)
{ {
dma->ops->stop(dma); dma->ops->stop(io, dma);
} }
void rsnd_dma_start(struct rsnd_dma *dma) void rsnd_dma_start(struct rsnd_dai_stream *io, struct rsnd_dma *dma)
{ {
dma->ops->start(dma); dma->ops->start(io, dma);
} }
void rsnd_dma_quit(struct rsnd_dma *dma) void rsnd_dma_quit(struct rsnd_dai_stream *io, struct rsnd_dma *dma)
{ {
struct rsnd_mod *mod = rsnd_dma_to_mod(dma); struct rsnd_mod *mod = rsnd_dma_to_mod(dma);
struct rsnd_priv *priv = rsnd_mod_to_priv(mod); struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
...@@ -543,15 +563,14 @@ void rsnd_dma_quit(struct rsnd_dma *dma) ...@@ -543,15 +563,14 @@ void rsnd_dma_quit(struct rsnd_dma *dma)
if (!dmac) if (!dmac)
return; return;
dma->ops->quit(dma); dma->ops->quit(io, dma);
} }
int rsnd_dma_init(struct rsnd_priv *priv, struct rsnd_dma *dma, int id) int rsnd_dma_init(struct rsnd_dai_stream *io, struct rsnd_dma *dma, int id)
{ {
struct rsnd_mod *mod = rsnd_dma_to_mod(dma);
struct rsnd_mod *mod_from; struct rsnd_mod *mod_from;
struct rsnd_mod *mod_to; struct rsnd_mod *mod_to;
struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); struct rsnd_priv *priv = rsnd_io_to_priv(io);
struct rsnd_dma_ctrl *dmac = rsnd_priv_to_dmac(priv); struct rsnd_dma_ctrl *dmac = rsnd_priv_to_dmac(priv);
int is_play = rsnd_io_is_play(io); int is_play = rsnd_io_is_play(io);
...@@ -564,10 +583,10 @@ int rsnd_dma_init(struct rsnd_priv *priv, struct rsnd_dma *dma, int id) ...@@ -564,10 +583,10 @@ int rsnd_dma_init(struct rsnd_priv *priv, struct rsnd_dma *dma, int id)
if (!dmac) if (!dmac)
return -EAGAIN; return -EAGAIN;
rsnd_dma_of_path(dma, is_play, &mod_from, &mod_to); rsnd_dma_of_path(dma, io, is_play, &mod_from, &mod_to);
dma->src_addr = rsnd_dma_addr(priv, mod_from, is_play, 1); dma->src_addr = rsnd_dma_addr(io, mod_from, is_play, 1);
dma->dst_addr = rsnd_dma_addr(priv, mod_to, is_play, 0); dma->dst_addr = rsnd_dma_addr(io, mod_to, is_play, 0);
/* for Gen2 */ /* for Gen2 */
if (mod_from && mod_to) if (mod_from && mod_to)
...@@ -579,7 +598,7 @@ int rsnd_dma_init(struct rsnd_priv *priv, struct rsnd_dma *dma, int id) ...@@ -579,7 +598,7 @@ int rsnd_dma_init(struct rsnd_priv *priv, struct rsnd_dma *dma, int id)
if (rsnd_is_gen1(priv)) if (rsnd_is_gen1(priv))
dma->ops = &rsnd_dmaen_ops; dma->ops = &rsnd_dmaen_ops;
return dma->ops->init(priv, dma, id, mod_from, mod_to); return dma->ops->init(io, dma, id, mod_from, mod_to);
} }
int rsnd_dma_probe(struct platform_device *pdev, int rsnd_dma_probe(struct platform_device *pdev,
......
...@@ -63,7 +63,8 @@ static const char * const dvc_ramp_rate[] = { ...@@ -63,7 +63,8 @@ static const char * const dvc_ramp_rate[] = {
"0.125 dB/8192 steps", /* 10111 */ "0.125 dB/8192 steps", /* 10111 */
}; };
static void rsnd_dvc_volume_update(struct rsnd_mod *mod) static void rsnd_dvc_volume_update(struct rsnd_dai_stream *io,
struct rsnd_mod *mod)
{ {
struct rsnd_dvc *dvc = rsnd_mod_to_dvc(mod); struct rsnd_dvc *dvc = rsnd_mod_to_dvc(mod);
u32 val[RSND_DVC_CHANNELS]; u32 val[RSND_DVC_CHANNELS];
...@@ -120,6 +121,7 @@ static void rsnd_dvc_volume_update(struct rsnd_mod *mod) ...@@ -120,6 +121,7 @@ static void rsnd_dvc_volume_update(struct rsnd_mod *mod)
} }
static int rsnd_dvc_remove_gen2(struct rsnd_mod *mod, static int rsnd_dvc_remove_gen2(struct rsnd_mod *mod,
struct rsnd_dai_stream *io,
struct rsnd_priv *priv) struct rsnd_priv *priv)
{ {
struct rsnd_dvc *dvc = rsnd_mod_to_dvc(mod); struct rsnd_dvc *dvc = rsnd_mod_to_dvc(mod);
...@@ -134,9 +136,9 @@ static int rsnd_dvc_remove_gen2(struct rsnd_mod *mod, ...@@ -134,9 +136,9 @@ static int rsnd_dvc_remove_gen2(struct rsnd_mod *mod,
} }
static int rsnd_dvc_init(struct rsnd_mod *dvc_mod, static int rsnd_dvc_init(struct rsnd_mod *dvc_mod,
struct rsnd_dai_stream *io,
struct rsnd_priv *priv) struct rsnd_priv *priv)
{ {
struct rsnd_dai_stream *io = rsnd_mod_to_io(dvc_mod);
struct rsnd_mod *src_mod = rsnd_io_to_mod_src(io); struct rsnd_mod *src_mod = rsnd_io_to_mod_src(io);
struct device *dev = rsnd_priv_to_dev(priv); struct device *dev = rsnd_priv_to_dev(priv);
int dvc_id = rsnd_mod_id(dvc_mod); int dvc_id = rsnd_mod_id(dvc_mod);
...@@ -168,10 +170,10 @@ static int rsnd_dvc_init(struct rsnd_mod *dvc_mod, ...@@ -168,10 +170,10 @@ static int rsnd_dvc_init(struct rsnd_mod *dvc_mod,
rsnd_mod_write(dvc_mod, DVC_DVUIR, 1); rsnd_mod_write(dvc_mod, DVC_DVUIR, 1);
rsnd_mod_write(dvc_mod, DVC_ADINR, rsnd_get_adinr(dvc_mod)); rsnd_mod_write(dvc_mod, DVC_ADINR, rsnd_get_adinr(dvc_mod, io));
/* ch0/ch1 Volume */ /* ch0/ch1 Volume */
rsnd_dvc_volume_update(dvc_mod); rsnd_dvc_volume_update(io, dvc_mod);
rsnd_mod_write(dvc_mod, DVC_DVUIR, 0); rsnd_mod_write(dvc_mod, DVC_DVUIR, 0);
...@@ -181,6 +183,7 @@ static int rsnd_dvc_init(struct rsnd_mod *dvc_mod, ...@@ -181,6 +183,7 @@ static int rsnd_dvc_init(struct rsnd_mod *dvc_mod,
} }
static int rsnd_dvc_quit(struct rsnd_mod *mod, static int rsnd_dvc_quit(struct rsnd_mod *mod,
struct rsnd_dai_stream *io,
struct rsnd_priv *priv) struct rsnd_priv *priv)
{ {
rsnd_mod_hw_stop(mod); rsnd_mod_hw_stop(mod);
...@@ -189,6 +192,7 @@ static int rsnd_dvc_quit(struct rsnd_mod *mod, ...@@ -189,6 +192,7 @@ static int rsnd_dvc_quit(struct rsnd_mod *mod,
} }
static int rsnd_dvc_start(struct rsnd_mod *mod, static int rsnd_dvc_start(struct rsnd_mod *mod,
struct rsnd_dai_stream *io,
struct rsnd_priv *priv) struct rsnd_priv *priv)
{ {
rsnd_mod_write(mod, CMD_CTRL, 0x10); rsnd_mod_write(mod, CMD_CTRL, 0x10);
...@@ -197,6 +201,7 @@ static int rsnd_dvc_start(struct rsnd_mod *mod, ...@@ -197,6 +201,7 @@ static int rsnd_dvc_start(struct rsnd_mod *mod,
} }
static int rsnd_dvc_stop(struct rsnd_mod *mod, static int rsnd_dvc_stop(struct rsnd_mod *mod,
struct rsnd_dai_stream *io,
struct rsnd_priv *priv) struct rsnd_priv *priv)
{ {
rsnd_mod_write(mod, CMD_CTRL, 0); rsnd_mod_write(mod, CMD_CTRL, 0);
...@@ -205,15 +210,15 @@ static int rsnd_dvc_stop(struct rsnd_mod *mod, ...@@ -205,15 +210,15 @@ static int rsnd_dvc_stop(struct rsnd_mod *mod,
} }
static int rsnd_dvc_pcm_new(struct rsnd_mod *mod, static int rsnd_dvc_pcm_new(struct rsnd_mod *mod,
struct rsnd_dai_stream *io,
struct snd_soc_pcm_runtime *rtd) struct snd_soc_pcm_runtime *rtd)
{ {
struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
struct rsnd_dvc *dvc = rsnd_mod_to_dvc(mod); struct rsnd_dvc *dvc = rsnd_mod_to_dvc(mod);
int is_play = rsnd_io_is_play(io); int is_play = rsnd_io_is_play(io);
int ret; int ret;
/* Volume */ /* Volume */
ret = rsnd_kctrl_new_m(mod, rtd, ret = rsnd_kctrl_new_m(mod, io, rtd,
is_play ? is_play ?
"DVC Out Playback Volume" : "DVC In Capture Volume", "DVC Out Playback Volume" : "DVC In Capture Volume",
rsnd_dvc_volume_update, rsnd_dvc_volume_update,
...@@ -222,7 +227,7 @@ static int rsnd_dvc_pcm_new(struct rsnd_mod *mod, ...@@ -222,7 +227,7 @@ static int rsnd_dvc_pcm_new(struct rsnd_mod *mod,
return ret; return ret;
/* Mute */ /* Mute */
ret = rsnd_kctrl_new_m(mod, rtd, ret = rsnd_kctrl_new_m(mod, io, rtd,
is_play ? is_play ?
"DVC Out Mute Switch" : "DVC In Mute Switch", "DVC Out Mute Switch" : "DVC In Mute Switch",
rsnd_dvc_volume_update, rsnd_dvc_volume_update,
...@@ -231,7 +236,7 @@ static int rsnd_dvc_pcm_new(struct rsnd_mod *mod, ...@@ -231,7 +236,7 @@ static int rsnd_dvc_pcm_new(struct rsnd_mod *mod,
return ret; return ret;
/* Ramp */ /* Ramp */
ret = rsnd_kctrl_new_s(mod, rtd, ret = rsnd_kctrl_new_s(mod, io, rtd,
is_play ? is_play ?
"DVC Out Ramp Switch" : "DVC In Ramp Switch", "DVC Out Ramp Switch" : "DVC In Ramp Switch",
rsnd_dvc_volume_update, rsnd_dvc_volume_update,
...@@ -239,7 +244,7 @@ static int rsnd_dvc_pcm_new(struct rsnd_mod *mod, ...@@ -239,7 +244,7 @@ static int rsnd_dvc_pcm_new(struct rsnd_mod *mod,
if (ret < 0) if (ret < 0)
return ret; return ret;
ret = rsnd_kctrl_new_e(mod, rtd, ret = rsnd_kctrl_new_e(mod, io, rtd,
is_play ? is_play ?
"DVC Out Ramp Up Rate" : "DVC In Ramp Up Rate", "DVC Out Ramp Up Rate" : "DVC In Ramp Up Rate",
&dvc->rup, &dvc->rup,
...@@ -248,7 +253,7 @@ static int rsnd_dvc_pcm_new(struct rsnd_mod *mod, ...@@ -248,7 +253,7 @@ static int rsnd_dvc_pcm_new(struct rsnd_mod *mod,
if (ret < 0) if (ret < 0)
return ret; return ret;
ret = rsnd_kctrl_new_e(mod, rtd, ret = rsnd_kctrl_new_e(mod, io, rtd,
is_play ? is_play ?
"DVC Out Ramp Down Rate" : "DVC In Ramp Down Rate", "DVC Out Ramp Down Rate" : "DVC In Ramp Down Rate",
&dvc->rdown, &dvc->rdown,
...@@ -261,7 +266,8 @@ static int rsnd_dvc_pcm_new(struct rsnd_mod *mod, ...@@ -261,7 +266,8 @@ static int rsnd_dvc_pcm_new(struct rsnd_mod *mod,
return 0; return 0;
} }
static struct dma_chan *rsnd_dvc_dma_req(struct rsnd_mod *mod) static struct dma_chan *rsnd_dvc_dma_req(struct rsnd_dai_stream *io,
struct rsnd_mod *mod)
{ {
struct rsnd_priv *priv = rsnd_mod_to_priv(mod); struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
...@@ -366,7 +372,7 @@ int rsnd_dvc_probe(struct platform_device *pdev, ...@@ -366,7 +372,7 @@ int rsnd_dvc_probe(struct platform_device *pdev,
dvc->info = &info->dvc_info[i]; dvc->info = &info->dvc_info[i];
ret = rsnd_mod_init(&dvc->mod, &rsnd_dvc_ops, ret = rsnd_mod_init(priv, &dvc->mod, &rsnd_dvc_ops,
clk, RSND_MOD_DVC, i); clk, RSND_MOD_DVC, i);
if (ret) if (ret)
return ret; return ret;
......
...@@ -165,18 +165,18 @@ void rsnd_write(struct rsnd_priv *priv, struct rsnd_mod *mod, ...@@ -165,18 +165,18 @@ void rsnd_write(struct rsnd_priv *priv, struct rsnd_mod *mod,
enum rsnd_reg reg, u32 data); enum rsnd_reg reg, u32 data);
void rsnd_bset(struct rsnd_priv *priv, struct rsnd_mod *mod, enum rsnd_reg reg, void rsnd_bset(struct rsnd_priv *priv, struct rsnd_mod *mod, enum rsnd_reg reg,
u32 mask, u32 data); u32 mask, u32 data);
u32 rsnd_get_adinr(struct rsnd_mod *mod); u32 rsnd_get_adinr(struct rsnd_mod *mod, struct rsnd_dai_stream *io);
/* /*
* R-Car DMA * R-Car DMA
*/ */
struct rsnd_dma; struct rsnd_dma;
struct rsnd_dma_ops { struct rsnd_dma_ops {
void (*start)(struct rsnd_dma *dma); void (*start)(struct rsnd_dai_stream *io, struct rsnd_dma *dma);
void (*stop)(struct rsnd_dma *dma); void (*stop)(struct rsnd_dai_stream *io, struct rsnd_dma *dma);
int (*init)(struct rsnd_priv *priv, struct rsnd_dma *dma, int id, int (*init)(struct rsnd_dai_stream *io, struct rsnd_dma *dma, int id,
struct rsnd_mod *mod_from, struct rsnd_mod *mod_to); struct rsnd_mod *mod_from, struct rsnd_mod *mod_to);
void (*quit)(struct rsnd_dma *dma); void (*quit)(struct rsnd_dai_stream *io, struct rsnd_dma *dma);
}; };
struct rsnd_dmaen { struct rsnd_dmaen {
...@@ -200,10 +200,10 @@ struct rsnd_dma { ...@@ -200,10 +200,10 @@ struct rsnd_dma {
#define rsnd_dma_to_dmaen(dma) (&(dma)->dma.en) #define rsnd_dma_to_dmaen(dma) (&(dma)->dma.en)
#define rsnd_dma_to_dmapp(dma) (&(dma)->dma.pp) #define rsnd_dma_to_dmapp(dma) (&(dma)->dma.pp)
void rsnd_dma_start(struct rsnd_dma *dma); void rsnd_dma_start(struct rsnd_dai_stream *io, struct rsnd_dma *dma);
void rsnd_dma_stop(struct rsnd_dma *dma); void rsnd_dma_stop(struct rsnd_dai_stream *io, struct rsnd_dma *dma);
int rsnd_dma_init(struct rsnd_priv *priv, struct rsnd_dma *dma, int id); int rsnd_dma_init(struct rsnd_dai_stream *io, struct rsnd_dma *dma, int id);
void rsnd_dma_quit(struct rsnd_dma *dma); void rsnd_dma_quit(struct rsnd_dai_stream *io, struct rsnd_dma *dma);
int rsnd_dma_probe(struct platform_device *pdev, int rsnd_dma_probe(struct platform_device *pdev,
const struct rsnd_of_data *of_data, const struct rsnd_of_data *of_data,
struct rsnd_priv *priv); struct rsnd_priv *priv);
...@@ -224,25 +224,35 @@ enum rsnd_mod_type { ...@@ -224,25 +224,35 @@ enum rsnd_mod_type {
struct rsnd_mod_ops { struct rsnd_mod_ops {
char *name; char *name;
struct dma_chan* (*dma_req)(struct rsnd_mod *mod); struct dma_chan* (*dma_req)(struct rsnd_dai_stream *io,
struct rsnd_mod *mod);
int (*probe)(struct rsnd_mod *mod, int (*probe)(struct rsnd_mod *mod,
struct rsnd_dai_stream *io,
struct rsnd_priv *priv); struct rsnd_priv *priv);
int (*remove)(struct rsnd_mod *mod, int (*remove)(struct rsnd_mod *mod,
struct rsnd_dai_stream *io,
struct rsnd_priv *priv); struct rsnd_priv *priv);
int (*init)(struct rsnd_mod *mod, int (*init)(struct rsnd_mod *mod,
struct rsnd_dai_stream *io,
struct rsnd_priv *priv); struct rsnd_priv *priv);
int (*quit)(struct rsnd_mod *mod, int (*quit)(struct rsnd_mod *mod,
struct rsnd_dai_stream *io,
struct rsnd_priv *priv); struct rsnd_priv *priv);
int (*start)(struct rsnd_mod *mod, int (*start)(struct rsnd_mod *mod,
struct rsnd_dai_stream *io,
struct rsnd_priv *priv); struct rsnd_priv *priv);
int (*stop)(struct rsnd_mod *mod, int (*stop)(struct rsnd_mod *mod,
struct rsnd_dai_stream *io,
struct rsnd_priv *priv); struct rsnd_priv *priv);
int (*pcm_new)(struct rsnd_mod *mod, int (*pcm_new)(struct rsnd_mod *mod,
struct rsnd_dai_stream *io,
struct snd_soc_pcm_runtime *rtd); struct snd_soc_pcm_runtime *rtd);
int (*hw_params)(struct rsnd_mod *mod, int (*hw_params)(struct rsnd_mod *mod,
struct rsnd_dai_stream *io,
struct snd_pcm_substream *substream, struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *hw_params); struct snd_pcm_hw_params *hw_params);
int (*fallback)(struct rsnd_mod *mod, int (*fallback)(struct rsnd_mod *mod,
struct rsnd_dai_stream *io,
struct rsnd_priv *priv); struct rsnd_priv *priv);
}; };
...@@ -252,32 +262,43 @@ struct rsnd_mod { ...@@ -252,32 +262,43 @@ struct rsnd_mod {
enum rsnd_mod_type type; enum rsnd_mod_type type;
struct rsnd_mod_ops *ops; struct rsnd_mod_ops *ops;
struct rsnd_dma dma; struct rsnd_dma dma;
struct rsnd_dai_stream *io; struct rsnd_priv *priv;
struct clk *clk; struct clk *clk;
u32 status; u32 status;
}; };
/* /*
* status * status
* *
* bit * 0xH0000CBA
* 0 0: probe 1: remove *
* 1 0: init 1: quit * A 0: probe 1: remove
* 2 0: start 1: stop * B 0: init 1: quit
* 3 0: pcm_new * C 0: start 1: stop
* 4 0: fallback
* *
* 31 bit is always called (see __rsnd_mod_call) * H is always called (see __rsnd_mod_call)
* 31 0: hw_params * H 0: pcm_new
* H 0: fallback
* H 0: hw_params
*/ */
#define __rsnd_mod_shift_probe 0 #define __rsnd_mod_shift_probe 0
#define __rsnd_mod_shift_remove 0 #define __rsnd_mod_shift_remove 0
#define __rsnd_mod_shift_init 1 #define __rsnd_mod_shift_init 4
#define __rsnd_mod_shift_quit 1 #define __rsnd_mod_shift_quit 4
#define __rsnd_mod_shift_start 2 #define __rsnd_mod_shift_start 8
#define __rsnd_mod_shift_stop 2 #define __rsnd_mod_shift_stop 8
#define __rsnd_mod_shift_pcm_new 3 #define __rsnd_mod_shift_pcm_new 28 /* always called */
#define __rsnd_mod_shift_fallback 4 #define __rsnd_mod_shift_fallback 28 /* always called */
#define __rsnd_mod_shift_hw_params 31 /* always called */ #define __rsnd_mod_shift_hw_params 28 /* always called */
#define __rsnd_mod_add_probe 1
#define __rsnd_mod_add_remove -1
#define __rsnd_mod_add_init 1
#define __rsnd_mod_add_quit -1
#define __rsnd_mod_add_start 1
#define __rsnd_mod_add_stop -1
#define __rsnd_mod_add_pcm_new 0
#define __rsnd_mod_add_fallback 0
#define __rsnd_mod_add_hw_params 0
#define __rsnd_mod_call_probe 0 #define __rsnd_mod_call_probe 0
#define __rsnd_mod_call_remove 1 #define __rsnd_mod_call_remove 1
...@@ -289,22 +310,25 @@ struct rsnd_mod { ...@@ -289,22 +310,25 @@ struct rsnd_mod {
#define __rsnd_mod_call_fallback 0 #define __rsnd_mod_call_fallback 0
#define __rsnd_mod_call_hw_params 0 #define __rsnd_mod_call_hw_params 0
#define rsnd_mod_to_priv(mod) (rsnd_io_to_priv(rsnd_mod_to_io(mod))) #define rsnd_mod_to_priv(mod) ((mod)->priv)
#define rsnd_mod_to_dma(mod) (&(mod)->dma) #define rsnd_mod_to_dma(mod) (&(mod)->dma)
#define rsnd_mod_to_io(mod) ((mod)->io)
#define rsnd_mod_id(mod) ((mod)->id) #define rsnd_mod_id(mod) ((mod)->id)
#define rsnd_mod_hw_start(mod) clk_enable((mod)->clk) #define rsnd_mod_hw_start(mod) clk_enable((mod)->clk)
#define rsnd_mod_hw_stop(mod) clk_disable((mod)->clk) #define rsnd_mod_hw_stop(mod) clk_disable((mod)->clk)
int rsnd_mod_init(struct rsnd_mod *mod, int rsnd_mod_init(struct rsnd_priv *priv,
struct rsnd_mod *mod,
struct rsnd_mod_ops *ops, struct rsnd_mod_ops *ops,
struct clk *clk, struct clk *clk,
enum rsnd_mod_type type, enum rsnd_mod_type type,
int id); int id);
void rsnd_mod_quit(struct rsnd_mod *mod); void rsnd_mod_quit(struct rsnd_mod *mod);
char *rsnd_mod_name(struct rsnd_mod *mod); char *rsnd_mod_name(struct rsnd_mod *mod);
int rsnd_mod_is_working(struct rsnd_mod *mod); struct dma_chan *rsnd_mod_dma_req(struct rsnd_dai_stream *io,
struct dma_chan *rsnd_mod_dma_req(struct rsnd_mod *mod); struct rsnd_mod *mod);
void rsnd_mod_interrupt(struct rsnd_mod *mod,
void (*callback)(struct rsnd_mod *mod,
struct rsnd_dai_stream *io));
/* /*
* R-Car sound DAI * R-Car sound DAI
...@@ -329,7 +353,7 @@ struct rsnd_dai_stream { ...@@ -329,7 +353,7 @@ struct rsnd_dai_stream {
#define rsnd_io_is_play(io) (&rsnd_io_to_rdai(io)->playback == io) #define rsnd_io_is_play(io) (&rsnd_io_to_rdai(io)->playback == io)
#define rsnd_io_to_runtime(io) ((io)->substream ? \ #define rsnd_io_to_runtime(io) ((io)->substream ? \
(io)->substream->runtime : NULL) (io)->substream->runtime : NULL)
int rsnd_io_is_working(struct rsnd_dai_stream *io);
struct rsnd_dai { struct rsnd_dai {
char name[RSND_DAI_NAME_SIZE]; char name[RSND_DAI_NAME_SIZE];
...@@ -355,7 +379,8 @@ struct rsnd_dai { ...@@ -355,7 +379,8 @@ struct rsnd_dai {
struct rsnd_dai *rsnd_rdai_get(struct rsnd_priv *priv, int id); struct rsnd_dai *rsnd_rdai_get(struct rsnd_priv *priv, int id);
void rsnd_dai_pointer_update(struct rsnd_dai_stream *io, int cnt); bool rsnd_dai_pointer_update(struct rsnd_dai_stream *io, int cnt);
void rsnd_dai_period_elapsed(struct rsnd_dai_stream *io);
int rsnd_dai_pointer_offset(struct rsnd_dai_stream *io, int additional); int rsnd_dai_pointer_offset(struct rsnd_dai_stream *io, int additional);
/* /*
...@@ -459,7 +484,8 @@ struct rsnd_kctrl_cfg { ...@@ -459,7 +484,8 @@ struct rsnd_kctrl_cfg {
unsigned int size; unsigned int size;
u32 *val; u32 *val;
const char * const *texts; const char * const *texts;
void (*update)(struct rsnd_mod *mod); void (*update)(struct rsnd_dai_stream *io, struct rsnd_mod *mod);
struct rsnd_dai_stream *io;
struct snd_card *card; struct snd_card *card;
struct snd_kcontrol *kctrl; struct snd_kcontrol *kctrl;
}; };
...@@ -479,22 +505,28 @@ void _rsnd_kctrl_remove(struct rsnd_kctrl_cfg *cfg); ...@@ -479,22 +505,28 @@ void _rsnd_kctrl_remove(struct rsnd_kctrl_cfg *cfg);
#define rsnd_kctrl_remove(_cfg) _rsnd_kctrl_remove(&((_cfg).cfg)) #define rsnd_kctrl_remove(_cfg) _rsnd_kctrl_remove(&((_cfg).cfg))
int rsnd_kctrl_new_m(struct rsnd_mod *mod, int rsnd_kctrl_new_m(struct rsnd_mod *mod,
struct rsnd_dai_stream *io,
struct snd_soc_pcm_runtime *rtd, struct snd_soc_pcm_runtime *rtd,
const unsigned char *name, const unsigned char *name,
void (*update)(struct rsnd_mod *mod), void (*update)(struct rsnd_dai_stream *io,
struct rsnd_mod *mod),
struct rsnd_kctrl_cfg_m *_cfg, struct rsnd_kctrl_cfg_m *_cfg,
u32 max); u32 max);
int rsnd_kctrl_new_s(struct rsnd_mod *mod, int rsnd_kctrl_new_s(struct rsnd_mod *mod,
struct rsnd_dai_stream *io,
struct snd_soc_pcm_runtime *rtd, struct snd_soc_pcm_runtime *rtd,
const unsigned char *name, const unsigned char *name,
void (*update)(struct rsnd_mod *mod), void (*update)(struct rsnd_dai_stream *io,
struct rsnd_mod *mod),
struct rsnd_kctrl_cfg_s *_cfg, struct rsnd_kctrl_cfg_s *_cfg,
u32 max); u32 max);
int rsnd_kctrl_new_e(struct rsnd_mod *mod, int rsnd_kctrl_new_e(struct rsnd_mod *mod,
struct rsnd_dai_stream *io,
struct snd_soc_pcm_runtime *rtd, struct snd_soc_pcm_runtime *rtd,
const unsigned char *name, const unsigned char *name,
struct rsnd_kctrl_cfg_s *_cfg, struct rsnd_kctrl_cfg_s *_cfg,
void (*update)(struct rsnd_mod *mod), void (*update)(struct rsnd_dai_stream *io,
struct rsnd_mod *mod),
const char * const *texts, const char * const *texts,
u32 max); u32 max);
...@@ -511,8 +543,10 @@ unsigned int rsnd_src_get_ssi_rate(struct rsnd_priv *priv, ...@@ -511,8 +543,10 @@ unsigned int rsnd_src_get_ssi_rate(struct rsnd_priv *priv,
struct rsnd_dai_stream *io, struct rsnd_dai_stream *io,
struct snd_pcm_runtime *runtime); struct snd_pcm_runtime *runtime);
int rsnd_src_ssiu_start(struct rsnd_mod *ssi_mod, int rsnd_src_ssiu_start(struct rsnd_mod *ssi_mod,
struct rsnd_dai_stream *io,
int use_busif); int use_busif);
int rsnd_src_ssiu_stop(struct rsnd_mod *ssi_mod); int rsnd_src_ssiu_stop(struct rsnd_mod *ssi_mod,
struct rsnd_dai_stream *io);
int rsnd_src_ssi_irq_enable(struct rsnd_mod *ssi_mod); int rsnd_src_ssi_irq_enable(struct rsnd_mod *ssi_mod);
int rsnd_src_ssi_irq_disable(struct rsnd_mod *ssi_mod); int rsnd_src_ssi_irq_disable(struct rsnd_mod *ssi_mod);
...@@ -529,7 +563,7 @@ void rsnd_ssi_remove(struct platform_device *pdev, ...@@ -529,7 +563,7 @@ void rsnd_ssi_remove(struct platform_device *pdev,
struct rsnd_mod *rsnd_ssi_mod_get(struct rsnd_priv *priv, int id); struct rsnd_mod *rsnd_ssi_mod_get(struct rsnd_priv *priv, int id);
int rsnd_ssi_is_pin_sharing(struct rsnd_mod *mod); int rsnd_ssi_is_pin_sharing(struct rsnd_mod *mod);
int rsnd_ssi_is_dma_mode(struct rsnd_mod *mod); int rsnd_ssi_is_dma_mode(struct rsnd_mod *mod);
int rsnd_ssi_use_busif(struct rsnd_mod *mod); int rsnd_ssi_use_busif(struct rsnd_dai_stream *io, struct rsnd_mod *mod);
/* /*
* R-Car DVC * R-Car DVC
......
...@@ -45,61 +45,50 @@ static const struct of_device_id rsrc_card_of_match[] = { ...@@ -45,61 +45,50 @@ static const struct of_device_id rsrc_card_of_match[] = {
}; };
MODULE_DEVICE_TABLE(of, rsrc_card_of_match); MODULE_DEVICE_TABLE(of, rsrc_card_of_match);
#define DAI_NAME_NUM 32
struct rsrc_card_dai { struct rsrc_card_dai {
const char *name;
unsigned int fmt; unsigned int fmt;
unsigned int sysclk; unsigned int sysclk;
struct clk *clk; struct clk *clk;
char dai_name[DAI_NAME_NUM];
}; };
#define RSRC_FB_NUM 2 /* FE/BE */
#define IDX_CPU 0 #define IDX_CPU 0
#define IDX_CODEC 1 #define IDX_CODEC 1
struct rsrc_card_priv { struct rsrc_card_priv {
struct snd_soc_card snd_card; struct snd_soc_card snd_card;
struct rsrc_card_dai_props {
struct rsrc_card_dai cpu_dai;
struct rsrc_card_dai codec_dai;
} dai_props[RSRC_FB_NUM];
struct snd_soc_codec_conf codec_conf; struct snd_soc_codec_conf codec_conf;
struct snd_soc_dai_link dai_link[RSRC_FB_NUM]; struct rsrc_card_dai *dai_props;
struct snd_soc_dai_link *dai_link;
int dai_num;
u32 convert_rate; u32 convert_rate;
}; };
#define rsrc_priv_to_dev(priv) ((priv)->snd_card.dev) #define rsrc_priv_to_dev(priv) ((priv)->snd_card.dev)
#define rsrc_priv_to_link(priv, i) ((priv)->snd_card.dai_link + i) #define rsrc_priv_to_link(priv, i) ((priv)->snd_card.dai_link + (i))
#define rsrc_priv_to_props(priv, i) ((priv)->dai_props + i) #define rsrc_priv_to_props(priv, i) ((priv)->dai_props + (i))
#define rsrc_dev_to_of_data(dev) (of_match_device(rsrc_card_of_match, (dev))->data) #define rsrc_dev_to_of_data(dev) (of_match_device(rsrc_card_of_match, (dev))->data)
static int rsrc_card_startup(struct snd_pcm_substream *substream) static int rsrc_card_startup(struct snd_pcm_substream *substream)
{ {
struct snd_soc_pcm_runtime *rtd = substream->private_data; struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct rsrc_card_priv *priv = snd_soc_card_get_drvdata(rtd->card); struct rsrc_card_priv *priv = snd_soc_card_get_drvdata(rtd->card);
struct rsrc_card_dai_props *dai_props = struct rsrc_card_dai *dai_props =
&priv->dai_props[rtd - rtd->card->rtd]; rsrc_priv_to_props(priv, rtd - rtd->card->rtd);
int ret; int ret;
ret = clk_prepare_enable(dai_props->cpu_dai.clk);
if (ret)
return ret;
ret = clk_prepare_enable(dai_props->codec_dai.clk);
if (ret)
clk_disable_unprepare(dai_props->cpu_dai.clk);
return ret; return clk_prepare_enable(dai_props->clk);
} }
static void rsrc_card_shutdown(struct snd_pcm_substream *substream) static void rsrc_card_shutdown(struct snd_pcm_substream *substream)
{ {
struct snd_soc_pcm_runtime *rtd = substream->private_data; struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct rsrc_card_priv *priv = snd_soc_card_get_drvdata(rtd->card); struct rsrc_card_priv *priv = snd_soc_card_get_drvdata(rtd->card);
struct rsrc_card_dai_props *dai_props = struct rsrc_card_dai *dai_props =
&priv->dai_props[rtd - rtd->card->rtd]; rsrc_priv_to_props(priv, rtd - rtd->card->rtd);
clk_disable_unprepare(dai_props->cpu_dai.clk); clk_disable_unprepare(dai_props->clk);
clk_disable_unprepare(dai_props->codec_dai.clk);
} }
static struct snd_soc_ops rsrc_card_ops = { static struct snd_soc_ops rsrc_card_ops = {
...@@ -107,21 +96,31 @@ static struct snd_soc_ops rsrc_card_ops = { ...@@ -107,21 +96,31 @@ static struct snd_soc_ops rsrc_card_ops = {
.shutdown = rsrc_card_shutdown, .shutdown = rsrc_card_shutdown,
}; };
static int __rsrc_card_dai_init(struct snd_soc_dai *dai, static int rsrc_card_dai_init(struct snd_soc_pcm_runtime *rtd)
struct rsrc_card_dai *set)
{ {
struct rsrc_card_priv *priv = snd_soc_card_get_drvdata(rtd->card);
struct snd_soc_dai *dai;
struct snd_soc_dai_link *dai_link;
struct rsrc_card_dai *dai_props;
int num = rtd - rtd->card->rtd;
int ret; int ret;
if (set->fmt) { dai_link = rsrc_priv_to_link(priv, num);
ret = snd_soc_dai_set_fmt(dai, set->fmt); dai_props = rsrc_priv_to_props(priv, num);
dai = dai_link->dynamic ?
rtd->cpu_dai :
rtd->codec_dai;
if (dai_props->fmt) {
ret = snd_soc_dai_set_fmt(dai, dai_props->fmt);
if (ret && ret != -ENOTSUPP) { if (ret && ret != -ENOTSUPP) {
dev_err(dai->dev, "set_fmt error\n"); dev_err(dai->dev, "set_fmt error\n");
goto err; goto err;
} }
} }
if (set->sysclk) { if (dai_props->sysclk) {
ret = snd_soc_dai_set_sysclk(dai, 0, set->sysclk, 0); ret = snd_soc_dai_set_sysclk(dai, 0, dai_props->sysclk, 0);
if (ret && ret != -ENOTSUPP) { if (ret && ret != -ENOTSUPP) {
dev_err(dai->dev, "set_sysclk error\n"); dev_err(dai->dev, "set_sysclk error\n");
goto err; goto err;
...@@ -134,27 +133,6 @@ static int __rsrc_card_dai_init(struct snd_soc_dai *dai, ...@@ -134,27 +133,6 @@ static int __rsrc_card_dai_init(struct snd_soc_dai *dai,
return ret; return ret;
} }
static int rsrc_card_dai_init(struct snd_soc_pcm_runtime *rtd)
{
struct rsrc_card_priv *priv = snd_soc_card_get_drvdata(rtd->card);
struct snd_soc_dai *codec = rtd->codec_dai;
struct snd_soc_dai *cpu = rtd->cpu_dai;
struct rsrc_card_dai_props *dai_props;
int num, ret;
num = rtd - rtd->card->rtd;
dai_props = &priv->dai_props[num];
ret = __rsrc_card_dai_init(codec, &dai_props->codec_dai);
if (ret < 0)
return ret;
ret = __rsrc_card_dai_init(cpu, &dai_props->cpu_dai);
if (ret < 0)
return ret;
return 0;
}
static int rsrc_card_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, static int rsrc_card_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
struct snd_pcm_hw_params *params) struct snd_pcm_hw_params *params)
{ {
...@@ -170,40 +148,47 @@ static int rsrc_card_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, ...@@ -170,40 +148,47 @@ static int rsrc_card_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
return 0; return 0;
} }
static int static int rsrc_card_parse_daifmt(struct device_node *node,
rsrc_card_sub_parse_of(struct rsrc_card_priv *priv,
struct device_node *np, struct device_node *np,
struct rsrc_card_dai *dai, struct rsrc_card_priv *priv,
struct snd_soc_dai_link *dai_link, int idx, bool is_fe)
int *args_count)
{ {
struct device *dev = rsrc_priv_to_dev(priv); struct rsrc_card_dai *dai_props = rsrc_priv_to_props(priv, idx);
const struct rsrc_card_of_data *of_data = rsrc_dev_to_of_data(dev); struct device_node *bitclkmaster = NULL;
struct of_phandle_args args; struct device_node *framemaster = NULL;
struct device_node **p_node; struct device_node *codec = is_fe ? NULL : np;
struct clk *clk; unsigned int daifmt;
const char **dai_name;
const char **name;
u32 val;
int ret;
if (args_count) { daifmt = snd_soc_of_parse_daifmt(node, NULL,
p_node = &dai_link->cpu_of_node; &bitclkmaster, &framemaster);
dai_name = &dai_link->cpu_dai_name; daifmt &= ~SND_SOC_DAIFMT_MASTER_MASK;
name = &dai_link->cpu_name;
} else { if (!bitclkmaster && !framemaster)
p_node = &dai_link->codec_of_node; return -EINVAL;
dai_name = &dai_link->codec_dai_name;
name = &dai_link->codec_name; if (codec == bitclkmaster)
} daifmt |= (codec == framemaster) ?
SND_SOC_DAIFMT_CBM_CFM : SND_SOC_DAIFMT_CBM_CFS;
else
daifmt |= (codec == framemaster) ?
SND_SOC_DAIFMT_CBS_CFM : SND_SOC_DAIFMT_CBS_CFS;
dai_props->fmt = daifmt;
of_node_put(bitclkmaster);
of_node_put(framemaster);
if (!np) {
/* use snd-soc-dummy */
*p_node = NULL;
*dai_name = "snd-soc-dummy-dai";
*name = "snd-soc-dummy";
return 0; return 0;
} }
static int rsrc_card_parse_links(struct device_node *np,
struct rsrc_card_priv *priv,
int idx, bool is_fe)
{
struct snd_soc_dai_link *dai_link = rsrc_priv_to_link(priv, idx);
struct rsrc_card_dai *dai_props = rsrc_priv_to_props(priv, idx);
struct of_phandle_args args;
int ret;
/* /*
* Get node via "sound-dai = <&phandle port>" * Get node via "sound-dai = <&phandle port>"
...@@ -214,31 +199,82 @@ rsrc_card_sub_parse_of(struct rsrc_card_priv *priv, ...@@ -214,31 +199,82 @@ rsrc_card_sub_parse_of(struct rsrc_card_priv *priv,
if (ret) if (ret)
return ret; return ret;
*p_node = args.np; if (is_fe) {
/* BE is dummy */
dai_link->codec_of_node = NULL;
dai_link->codec_dai_name = "snd-soc-dummy-dai";
dai_link->codec_name = "snd-soc-dummy";
/* Get dai->name */ /* FE settings */
ret = snd_soc_of_get_dai_name(np, dai_name); dai_link->dynamic = 1;
if (ret < 0) dai_link->dpcm_merged_format = 1;
return ret; dai_link->cpu_of_node = args.np;
snd_soc_of_get_dai_name(np, &dai_link->cpu_dai_name);
/* set dai_name */
snprintf(dai_props->dai_name, DAI_NAME_NUM, "fe.%s",
dai_link->cpu_dai_name);
/* /*
* FIXME * In soc_bind_dai_link() will check cpu name after
* * of_node matching if dai_link has cpu_dai_name.
* rsrc assumes DPCM playback/capture * but, it will never match if name was created by
* fmt_single_name() remove cpu_dai_name if cpu_args
* was 0. See:
* fmt_single_name()
* fmt_multiple_name()
*/ */
dai_link->dpcm_playback = 1; if (!args.args_count)
dai_link->dpcm_capture = 1; dai_link->cpu_dai_name = NULL;
if (args_count) {
*args_count = args.args_count;
dai_link->dynamic = 1;
dai_link->dpcm_merged_format = 1;
} else { } else {
struct device *dev = rsrc_priv_to_dev(priv);
const struct rsrc_card_of_data *of_data;
of_data = rsrc_dev_to_of_data(dev);
/* FE is dummy */
dai_link->cpu_of_node = NULL;
dai_link->cpu_dai_name = "snd-soc-dummy-dai";
dai_link->cpu_name = "snd-soc-dummy";
/* BE settings */
dai_link->no_pcm = 1; dai_link->no_pcm = 1;
priv->codec_conf.of_node = (*p_node); dai_link->be_hw_params_fixup = rsrc_card_be_hw_params_fixup;
dai_link->codec_of_node = args.np;
snd_soc_of_get_dai_name(np, &dai_link->codec_dai_name);
/* additional name prefix */
priv->codec_conf.of_node = dai_link->codec_of_node;
priv->codec_conf.name_prefix = of_data->prefix; priv->codec_conf.name_prefix = of_data->prefix;
/* set dai_name */
snprintf(dai_props->dai_name, DAI_NAME_NUM, "be.%s",
dai_link->codec_dai_name);
} }
/* Simple Card assumes platform == cpu */
dai_link->platform_of_node = dai_link->cpu_of_node;
dai_link->dpcm_playback = 1;
dai_link->dpcm_capture = 1;
dai_link->name = dai_props->dai_name;
dai_link->stream_name = dai_props->dai_name;
dai_link->ops = &rsrc_card_ops;
dai_link->init = rsrc_card_dai_init;
return 0;
}
static int rsrc_card_parse_clk(struct device_node *np,
struct rsrc_card_priv *priv,
int idx, bool is_fe)
{
struct snd_soc_dai_link *dai_link = rsrc_priv_to_link(priv, idx);
struct rsrc_card_dai *dai_props = rsrc_priv_to_props(priv, idx);
struct clk *clk;
struct device_node *of_np = is_fe ? dai_link->cpu_of_node :
dai_link->codec_of_node;
u32 val;
/* /*
* Parse dai->sysclk come from "clocks = <&xxx>" * Parse dai->sysclk come from "clocks = <&xxx>"
* (if system has common clock) * (if system has common clock)
...@@ -247,173 +283,92 @@ rsrc_card_sub_parse_of(struct rsrc_card_priv *priv, ...@@ -247,173 +283,92 @@ rsrc_card_sub_parse_of(struct rsrc_card_priv *priv,
*/ */
if (of_property_read_bool(np, "clocks")) { if (of_property_read_bool(np, "clocks")) {
clk = of_clk_get(np, 0); clk = of_clk_get(np, 0);
if (IS_ERR(clk)) { if (IS_ERR(clk))
ret = PTR_ERR(clk); return PTR_ERR(clk);
return ret;
}
dai->sysclk = clk_get_rate(clk); dai_props->sysclk = clk_get_rate(clk);
dai->clk = clk; dai_props->clk = clk;
} else if (!of_property_read_u32(np, "system-clock-frequency", &val)) { } else if (!of_property_read_u32(np, "system-clock-frequency", &val)) {
dai->sysclk = val; dai_props->sysclk = val;
} else { } else {
clk = of_clk_get(args.np, 0); clk = of_clk_get(of_np, 0);
if (!IS_ERR(clk)) if (!IS_ERR(clk))
dai->sysclk = clk_get_rate(clk); dai_props->sysclk = clk_get_rate(clk);
} }
return 0; return 0;
} }
static int rsrc_card_parse_daifmt(struct device_node *node,
struct rsrc_card_priv *priv,
struct device_node *codec,
int idx)
{
struct device_node *bitclkmaster = NULL;
struct device_node *framemaster = NULL;
struct rsrc_card_dai_props *dai_props = rsrc_priv_to_props(priv, idx);
struct rsrc_card_dai *cpu_dai = &dai_props->cpu_dai;
struct rsrc_card_dai *codec_dai = &dai_props->codec_dai;
unsigned int daifmt;
daifmt = snd_soc_of_parse_daifmt(node, NULL,
&bitclkmaster, &framemaster);
daifmt &= ~SND_SOC_DAIFMT_MASTER_MASK;
if (!bitclkmaster && !framemaster)
return -EINVAL;
if (codec == bitclkmaster)
daifmt |= (codec == framemaster) ?
SND_SOC_DAIFMT_CBM_CFM : SND_SOC_DAIFMT_CBM_CFS;
else
daifmt |= (codec == framemaster) ?
SND_SOC_DAIFMT_CBS_CFM : SND_SOC_DAIFMT_CBS_CFS;
cpu_dai->fmt = daifmt;
codec_dai->fmt = daifmt;
of_node_put(bitclkmaster);
of_node_put(framemaster);
return 0;
}
static int rsrc_card_dai_link_of(struct device_node *node, static int rsrc_card_dai_link_of(struct device_node *node,
struct device_node *np,
struct rsrc_card_priv *priv, struct rsrc_card_priv *priv,
int idx) int idx)
{ {
struct device *dev = rsrc_priv_to_dev(priv); struct device *dev = rsrc_priv_to_dev(priv);
struct snd_soc_dai_link *dai_link = rsrc_priv_to_link(priv, idx); struct rsrc_card_dai *dai_props = rsrc_priv_to_props(priv, idx);
struct rsrc_card_dai_props *dai_props = rsrc_priv_to_props(priv, idx); bool is_fe = false;
struct device_node *cpu = NULL; int ret;
struct device_node *codec = NULL;
char *name;
char prop[128];
int ret, cpu_args;
cpu = of_get_child_by_name(node, "cpu");
codec = of_get_child_by_name(node, "codec");
if (!cpu || !codec) {
ret = -EINVAL;
dev_err(dev, "%s: Can't find %s DT node\n", __func__, prop);
goto dai_link_of_err;
}
ret = rsrc_card_parse_daifmt(node, priv, codec, idx); if (0 == strcmp(np->name, "cpu"))
if (ret < 0) is_fe = true;
goto dai_link_of_err;
ret = rsrc_card_sub_parse_of(priv, (idx == IDX_CPU) ? cpu : NULL, ret = rsrc_card_parse_daifmt(node, np, priv, idx, is_fe);
&dai_props->cpu_dai,
dai_link,
&cpu_args);
if (ret < 0) if (ret < 0)
goto dai_link_of_err; return ret;
ret = rsrc_card_sub_parse_of(priv, (idx == IDX_CODEC) ? codec : NULL, ret = rsrc_card_parse_links(np, priv, idx, is_fe);
&dai_props->codec_dai,
dai_link,
NULL);
if (ret < 0) if (ret < 0)
goto dai_link_of_err; return ret;
if (!dai_link->cpu_dai_name || !dai_link->codec_dai_name) {
ret = -EINVAL;
goto dai_link_of_err;
}
/* Simple Card assumes platform == cpu */
dai_link->platform_of_node = dai_link->cpu_of_node;
/* DAI link name is created from CPU/CODEC dai name */
name = devm_kzalloc(dev,
strlen(dai_link->cpu_dai_name) +
strlen(dai_link->codec_dai_name) + 2,
GFP_KERNEL);
if (!name) {
ret = -ENOMEM;
goto dai_link_of_err;
}
sprintf(name, "%s-%s", dai_link->cpu_dai_name,
dai_link->codec_dai_name);
dai_link->name = dai_link->stream_name = name;
dai_link->ops = &rsrc_card_ops;
dai_link->init = rsrc_card_dai_init;
if (idx == IDX_CODEC)
dai_link->be_hw_params_fixup = rsrc_card_be_hw_params_fixup;
dev_dbg(dev, "\tname : %s\n", dai_link->stream_name);
dev_dbg(dev, "\tcpu : %s / %04x / %d\n",
dai_link->cpu_dai_name,
dai_props->cpu_dai.fmt,
dai_props->cpu_dai.sysclk);
dev_dbg(dev, "\tcodec : %s / %04x / %d\n",
dai_link->codec_dai_name,
dai_props->codec_dai.fmt,
dai_props->codec_dai.sysclk);
/* ret = rsrc_card_parse_clk(np, priv, idx, is_fe);
* In soc_bind_dai_link() will check cpu name after if (ret < 0)
* of_node matching if dai_link has cpu_dai_name. return ret;
* but, it will never match if name was created by
* fmt_single_name() remove cpu_dai_name if cpu_args
* was 0. See:
* fmt_single_name()
* fmt_multiple_name()
*/
if (!cpu_args)
dai_link->cpu_dai_name = NULL;
dai_link_of_err: dev_dbg(dev, "\t%s / %04x / %d\n",
of_node_put(cpu); dai_props->dai_name,
of_node_put(codec); dai_props->fmt,
dai_props->sysclk);
return ret; return ret;
} }
static int rsrc_card_parse_of(struct device_node *node, static int rsrc_card_parse_of(struct device_node *node,
struct rsrc_card_priv *priv) struct rsrc_card_priv *priv,
struct device *dev)
{ {
struct device *dev = rsrc_priv_to_dev(priv);
const struct rsrc_card_of_data *of_data = rsrc_dev_to_of_data(dev); const struct rsrc_card_of_data *of_data = rsrc_dev_to_of_data(dev);
struct rsrc_card_dai *props;
struct snd_soc_dai_link *links;
struct device_node *np;
int ret; int ret;
int i; int i, num;
if (!node) if (!node)
return -EINVAL; return -EINVAL;
/* Parse the card name from DT */ num = of_get_child_count(node);
snd_soc_of_parse_card_name(&priv->snd_card, "card-name"); props = devm_kzalloc(dev, sizeof(*props) * num, GFP_KERNEL);
links = devm_kzalloc(dev, sizeof(*links) * num, GFP_KERNEL);
if (!props || !links)
return -ENOMEM;
priv->dai_props = props;
priv->dai_link = links;
priv->dai_num = num;
/* DAPM routes */ /* Init snd_soc_card */
priv->snd_card.owner = THIS_MODULE;
priv->snd_card.dev = dev;
priv->snd_card.dai_link = priv->dai_link;
priv->snd_card.num_links = num;
priv->snd_card.codec_conf = &priv->codec_conf;
priv->snd_card.num_configs = 1;
priv->snd_card.of_dapm_routes = of_data->routes; priv->snd_card.of_dapm_routes = of_data->routes;
priv->snd_card.num_of_dapm_routes = of_data->num_routes; priv->snd_card.num_of_dapm_routes = of_data->num_routes;
/* Parse the card name from DT */
snd_soc_of_parse_card_name(&priv->snd_card, "card-name");
/* sampling rate convert */ /* sampling rate convert */
of_property_read_u32(node, "convert-rate", &priv->convert_rate); of_property_read_u32(node, "convert-rate", &priv->convert_rate);
...@@ -421,11 +376,12 @@ static int rsrc_card_parse_of(struct device_node *node, ...@@ -421,11 +376,12 @@ static int rsrc_card_parse_of(struct device_node *node,
priv->snd_card.name ? priv->snd_card.name : "", priv->snd_card.name ? priv->snd_card.name : "",
priv->convert_rate); priv->convert_rate);
/* FE/BE */ i = 0;
for (i = 0; i < RSRC_FB_NUM; i++) { for_each_child_of_node(node, np) {
ret = rsrc_card_dai_link_of(node, priv, i); ret = rsrc_card_dai_link_of(node, np, priv, i);
if (ret < 0) if (ret < 0)
return ret; return ret;
i++;
} }
if (!priv->snd_card.name) if (!priv->snd_card.name)
...@@ -452,7 +408,6 @@ static int rsrc_card_unref(struct snd_soc_card *card) ...@@ -452,7 +408,6 @@ static int rsrc_card_unref(struct snd_soc_card *card)
static int rsrc_card_probe(struct platform_device *pdev) static int rsrc_card_probe(struct platform_device *pdev)
{ {
struct rsrc_card_priv *priv; struct rsrc_card_priv *priv;
struct snd_soc_dai_link *dai_link;
struct device_node *np = pdev->dev.of_node; struct device_node *np = pdev->dev.of_node;
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
int ret; int ret;
...@@ -462,16 +417,7 @@ static int rsrc_card_probe(struct platform_device *pdev) ...@@ -462,16 +417,7 @@ static int rsrc_card_probe(struct platform_device *pdev)
if (!priv) if (!priv)
return -ENOMEM; return -ENOMEM;
/* Init snd_soc_card */ ret = rsrc_card_parse_of(np, priv, dev);
priv->snd_card.owner = THIS_MODULE;
priv->snd_card.dev = dev;
dai_link = priv->dai_link;
priv->snd_card.dai_link = dai_link;
priv->snd_card.num_links = RSRC_FB_NUM;
priv->snd_card.codec_conf = &priv->codec_conf;
priv->snd_card.num_configs = 1;
ret = rsrc_card_parse_of(np, priv);
if (ret < 0) { if (ret < 0) {
if (ret != -EPROBE_DEFER) if (ret != -EPROBE_DEFER)
dev_err(dev, "parse error %d\n", ret); dev_err(dev, "parse error %d\n", ret);
......
...@@ -117,10 +117,10 @@ struct rsnd_src { ...@@ -117,10 +117,10 @@ struct rsnd_src {
/* /*
* Gen1/Gen2 common functions * Gen1/Gen2 common functions
*/ */
static struct dma_chan *rsnd_src_dma_req(struct rsnd_mod *mod) static struct dma_chan *rsnd_src_dma_req(struct rsnd_dai_stream *io,
struct rsnd_mod *mod)
{ {
struct rsnd_priv *priv = rsnd_mod_to_priv(mod); struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
int is_play = rsnd_io_is_play(io); int is_play = rsnd_io_is_play(io);
return rsnd_dma_request_channel(rsnd_src_of_node(priv), return rsnd_dma_request_channel(rsnd_src_of_node(priv),
...@@ -129,9 +129,9 @@ static struct dma_chan *rsnd_src_dma_req(struct rsnd_mod *mod) ...@@ -129,9 +129,9 @@ static struct dma_chan *rsnd_src_dma_req(struct rsnd_mod *mod)
} }
int rsnd_src_ssiu_start(struct rsnd_mod *ssi_mod, int rsnd_src_ssiu_start(struct rsnd_mod *ssi_mod,
struct rsnd_dai_stream *io,
int use_busif) int use_busif)
{ {
struct rsnd_dai_stream *io = rsnd_mod_to_io(ssi_mod);
struct rsnd_dai *rdai = rsnd_io_to_rdai(io); struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
int ssi_id = rsnd_mod_id(ssi_mod); int ssi_id = rsnd_mod_id(ssi_mod);
...@@ -174,7 +174,7 @@ int rsnd_src_ssiu_start(struct rsnd_mod *ssi_mod, ...@@ -174,7 +174,7 @@ int rsnd_src_ssiu_start(struct rsnd_mod *ssi_mod,
u32 mask = ~0; u32 mask = ~0;
rsnd_mod_write(ssi_mod, SSI_BUSIF_ADINR, rsnd_mod_write(ssi_mod, SSI_BUSIF_ADINR,
rsnd_get_adinr(ssi_mod)); rsnd_get_adinr(ssi_mod, io));
rsnd_mod_write(ssi_mod, SSI_BUSIF_MODE, 1); rsnd_mod_write(ssi_mod, SSI_BUSIF_MODE, 1);
rsnd_mod_write(ssi_mod, SSI_CTRL, 0x1); rsnd_mod_write(ssi_mod, SSI_CTRL, 0x1);
...@@ -196,7 +196,8 @@ int rsnd_src_ssiu_start(struct rsnd_mod *ssi_mod, ...@@ -196,7 +196,8 @@ int rsnd_src_ssiu_start(struct rsnd_mod *ssi_mod,
return 0; return 0;
} }
int rsnd_src_ssiu_stop(struct rsnd_mod *ssi_mod) int rsnd_src_ssiu_stop(struct rsnd_mod *ssi_mod,
struct rsnd_dai_stream *io)
{ {
/* /*
* DMA settings for SSIU * DMA settings for SSIU
...@@ -235,10 +236,9 @@ int rsnd_src_ssi_irq_disable(struct rsnd_mod *ssi_mod) ...@@ -235,10 +236,9 @@ int rsnd_src_ssi_irq_disable(struct rsnd_mod *ssi_mod)
return 0; return 0;
} }
static u32 rsnd_src_convert_rate(struct rsnd_src *src) static u32 rsnd_src_convert_rate(struct rsnd_dai_stream *io,
struct rsnd_src *src)
{ {
struct rsnd_mod *mod = &src->mod;
struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
u32 convert_rate; u32 convert_rate;
...@@ -274,7 +274,7 @@ unsigned int rsnd_src_get_ssi_rate(struct rsnd_priv *priv, ...@@ -274,7 +274,7 @@ unsigned int rsnd_src_get_ssi_rate(struct rsnd_priv *priv,
* return convert rate if SRC is used, * return convert rate if SRC is used,
* otherwise, return runtime->rate as usual * otherwise, return runtime->rate as usual
*/ */
rate = rsnd_src_convert_rate(src); rate = rsnd_src_convert_rate(io, src);
} }
if (!rate) if (!rate)
...@@ -283,12 +283,12 @@ unsigned int rsnd_src_get_ssi_rate(struct rsnd_priv *priv, ...@@ -283,12 +283,12 @@ unsigned int rsnd_src_get_ssi_rate(struct rsnd_priv *priv,
return rate; return rate;
} }
static int rsnd_src_set_convert_rate(struct rsnd_mod *mod) static int rsnd_src_set_convert_rate(struct rsnd_mod *mod,
struct rsnd_dai_stream *io)
{ {
struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
struct rsnd_src *src = rsnd_mod_to_src(mod); struct rsnd_src *src = rsnd_mod_to_src(mod);
u32 convert_rate = rsnd_src_convert_rate(src); u32 convert_rate = rsnd_src_convert_rate(io, src);
u32 fsrate = 0; u32 fsrate = 0;
if (convert_rate) if (convert_rate)
...@@ -299,7 +299,7 @@ static int rsnd_src_set_convert_rate(struct rsnd_mod *mod) ...@@ -299,7 +299,7 @@ static int rsnd_src_set_convert_rate(struct rsnd_mod *mod)
rsnd_mod_write(mod, SRC_SWRSR, 1); rsnd_mod_write(mod, SRC_SWRSR, 1);
/* Set channel number and output bit length */ /* Set channel number and output bit length */
rsnd_mod_write(mod, SRC_ADINR, rsnd_get_adinr(mod)); rsnd_mod_write(mod, SRC_ADINR, rsnd_get_adinr(mod, io));
/* Enable the initial value of IFS */ /* Enable the initial value of IFS */
if (fsrate) { if (fsrate) {
...@@ -316,6 +316,7 @@ static int rsnd_src_set_convert_rate(struct rsnd_mod *mod) ...@@ -316,6 +316,7 @@ static int rsnd_src_set_convert_rate(struct rsnd_mod *mod)
} }
static int rsnd_src_hw_params(struct rsnd_mod *mod, static int rsnd_src_hw_params(struct rsnd_mod *mod,
struct rsnd_dai_stream *io,
struct snd_pcm_substream *substream, struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *fe_params) struct snd_pcm_hw_params *fe_params)
{ {
...@@ -372,6 +373,7 @@ static int rsnd_src_init(struct rsnd_mod *mod, ...@@ -372,6 +373,7 @@ static int rsnd_src_init(struct rsnd_mod *mod,
} }
static int rsnd_src_quit(struct rsnd_mod *mod, static int rsnd_src_quit(struct rsnd_mod *mod,
struct rsnd_dai_stream *io,
struct rsnd_priv *priv) struct rsnd_priv *priv)
{ {
struct rsnd_src *src = rsnd_mod_to_src(mod); struct rsnd_src *src = rsnd_mod_to_src(mod);
...@@ -411,9 +413,9 @@ static int rsnd_src_stop(struct rsnd_mod *mod) ...@@ -411,9 +413,9 @@ static int rsnd_src_stop(struct rsnd_mod *mod)
/* /*
* Gen1 functions * Gen1 functions
*/ */
static int rsnd_src_set_route_gen1(struct rsnd_mod *mod) static int rsnd_src_set_route_gen1(struct rsnd_dai_stream *io,
struct rsnd_mod *mod)
{ {
struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
struct src_route_config { struct src_route_config {
u32 mask; u32 mask;
int shift; int shift;
...@@ -448,13 +450,13 @@ static int rsnd_src_set_route_gen1(struct rsnd_mod *mod) ...@@ -448,13 +450,13 @@ static int rsnd_src_set_route_gen1(struct rsnd_mod *mod)
return 0; return 0;
} }
static int rsnd_src_set_convert_timing_gen1(struct rsnd_mod *mod) static int rsnd_src_set_convert_timing_gen1(struct rsnd_dai_stream *io,
struct rsnd_mod *mod)
{ {
struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
struct rsnd_priv *priv = rsnd_mod_to_priv(mod); struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
struct rsnd_src *src = rsnd_mod_to_src(mod); struct rsnd_src *src = rsnd_mod_to_src(mod);
struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
u32 convert_rate = rsnd_src_convert_rate(src); u32 convert_rate = rsnd_src_convert_rate(io, src);
u32 mask; u32 mask;
u32 val; u32 val;
int shift; int shift;
...@@ -506,12 +508,13 @@ static int rsnd_src_set_convert_timing_gen1(struct rsnd_mod *mod) ...@@ -506,12 +508,13 @@ static int rsnd_src_set_convert_timing_gen1(struct rsnd_mod *mod)
return 0; return 0;
} }
static int rsnd_src_set_convert_rate_gen1(struct rsnd_mod *mod) static int rsnd_src_set_convert_rate_gen1(struct rsnd_mod *mod,
struct rsnd_dai_stream *io)
{ {
struct rsnd_src *src = rsnd_mod_to_src(mod); struct rsnd_src *src = rsnd_mod_to_src(mod);
int ret; int ret;
ret = rsnd_src_set_convert_rate(mod); ret = rsnd_src_set_convert_rate(mod, io);
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -523,7 +526,7 @@ static int rsnd_src_set_convert_rate_gen1(struct rsnd_mod *mod) ...@@ -523,7 +526,7 @@ static int rsnd_src_set_convert_rate_gen1(struct rsnd_mod *mod)
rsnd_mod_read(mod, SRC_IFSVR) / 100 * 98); rsnd_mod_read(mod, SRC_IFSVR) / 100 * 98);
/* Gen1/Gen2 are not compatible */ /* Gen1/Gen2 are not compatible */
if (rsnd_src_convert_rate(src)) if (rsnd_src_convert_rate(io, src))
rsnd_mod_write(mod, SRC_ROUTE_MODE0, 1); rsnd_mod_write(mod, SRC_ROUTE_MODE0, 1);
/* no SRC_BFSSR settings, since SRC_SRCCR::BUFMD is 0 */ /* no SRC_BFSSR settings, since SRC_SRCCR::BUFMD is 0 */
...@@ -532,6 +535,7 @@ static int rsnd_src_set_convert_rate_gen1(struct rsnd_mod *mod) ...@@ -532,6 +535,7 @@ static int rsnd_src_set_convert_rate_gen1(struct rsnd_mod *mod)
} }
static int rsnd_src_init_gen1(struct rsnd_mod *mod, static int rsnd_src_init_gen1(struct rsnd_mod *mod,
struct rsnd_dai_stream *io,
struct rsnd_priv *priv) struct rsnd_priv *priv)
{ {
int ret; int ret;
...@@ -540,15 +544,15 @@ static int rsnd_src_init_gen1(struct rsnd_mod *mod, ...@@ -540,15 +544,15 @@ static int rsnd_src_init_gen1(struct rsnd_mod *mod,
if (ret < 0) if (ret < 0)
return ret; return ret;
ret = rsnd_src_set_route_gen1(mod); ret = rsnd_src_set_route_gen1(io, mod);
if (ret < 0) if (ret < 0)
return ret; return ret;
ret = rsnd_src_set_convert_rate_gen1(mod); ret = rsnd_src_set_convert_rate_gen1(mod, io);
if (ret < 0) if (ret < 0)
return ret; return ret;
ret = rsnd_src_set_convert_timing_gen1(mod); ret = rsnd_src_set_convert_timing_gen1(io, mod);
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -556,6 +560,7 @@ static int rsnd_src_init_gen1(struct rsnd_mod *mod, ...@@ -556,6 +560,7 @@ static int rsnd_src_init_gen1(struct rsnd_mod *mod,
} }
static int rsnd_src_start_gen1(struct rsnd_mod *mod, static int rsnd_src_start_gen1(struct rsnd_mod *mod,
struct rsnd_dai_stream *io,
struct rsnd_priv *priv) struct rsnd_priv *priv)
{ {
int id = rsnd_mod_id(mod); int id = rsnd_mod_id(mod);
...@@ -566,6 +571,7 @@ static int rsnd_src_start_gen1(struct rsnd_mod *mod, ...@@ -566,6 +571,7 @@ static int rsnd_src_start_gen1(struct rsnd_mod *mod,
} }
static int rsnd_src_stop_gen1(struct rsnd_mod *mod, static int rsnd_src_stop_gen1(struct rsnd_mod *mod,
struct rsnd_dai_stream *io,
struct rsnd_priv *priv) struct rsnd_priv *priv)
{ {
int id = rsnd_mod_id(mod); int id = rsnd_mod_id(mod);
...@@ -643,9 +649,9 @@ static bool rsnd_src_error_record_gen2(struct rsnd_mod *mod) ...@@ -643,9 +649,9 @@ static bool rsnd_src_error_record_gen2(struct rsnd_mod *mod)
return ret; return ret;
} }
static int _rsnd_src_start_gen2(struct rsnd_mod *mod) static int _rsnd_src_start_gen2(struct rsnd_mod *mod,
struct rsnd_dai_stream *io)
{ {
struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
u32 val = rsnd_io_to_mod_dvc(io) ? 0x01 : 0x11; u32 val = rsnd_io_to_mod_dvc(io) ? 0x01 : 0x11;
rsnd_mod_write(mod, SRC_CTRL, val); rsnd_mod_write(mod, SRC_CTRL, val);
...@@ -670,15 +676,15 @@ static int _rsnd_src_stop_gen2(struct rsnd_mod *mod) ...@@ -670,15 +676,15 @@ static int _rsnd_src_stop_gen2(struct rsnd_mod *mod)
return rsnd_src_stop(mod); return rsnd_src_stop(mod);
} }
static irqreturn_t rsnd_src_interrupt_gen2(int irq, void *data) static void __rsnd_src_interrupt_gen2(struct rsnd_mod *mod,
struct rsnd_dai_stream *io)
{ {
struct rsnd_mod *mod = data;
struct rsnd_priv *priv = rsnd_mod_to_priv(mod); struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
spin_lock(&priv->lock); spin_lock(&priv->lock);
/* ignore all cases if not working */ /* ignore all cases if not working */
if (!rsnd_mod_is_working(mod)) if (!rsnd_io_is_working(io))
goto rsnd_src_interrupt_gen2_out; goto rsnd_src_interrupt_gen2_out;
if (rsnd_src_error_record_gen2(mod)) { if (rsnd_src_error_record_gen2(mod)) {
...@@ -691,24 +697,32 @@ static irqreturn_t rsnd_src_interrupt_gen2(int irq, void *data) ...@@ -691,24 +697,32 @@ static irqreturn_t rsnd_src_interrupt_gen2(int irq, void *data)
_rsnd_src_stop_gen2(mod); _rsnd_src_stop_gen2(mod);
if (src->err < 1024) if (src->err < 1024)
_rsnd_src_start_gen2(mod); _rsnd_src_start_gen2(mod, io);
else else
dev_warn(dev, "no more SRC restart\n"); dev_warn(dev, "no more SRC restart\n");
} }
rsnd_src_interrupt_gen2_out: rsnd_src_interrupt_gen2_out:
spin_unlock(&priv->lock); spin_unlock(&priv->lock);
}
static irqreturn_t rsnd_src_interrupt_gen2(int irq, void *data)
{
struct rsnd_mod *mod = data;
rsnd_mod_interrupt(mod, __rsnd_src_interrupt_gen2);
return IRQ_HANDLED; return IRQ_HANDLED;
} }
static int rsnd_src_set_convert_rate_gen2(struct rsnd_mod *mod) static int rsnd_src_set_convert_rate_gen2(struct rsnd_mod *mod,
struct rsnd_dai_stream *io)
{ {
struct rsnd_priv *priv = rsnd_mod_to_priv(mod); struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
struct device *dev = rsnd_priv_to_dev(priv); struct device *dev = rsnd_priv_to_dev(priv);
struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
struct rsnd_src *src = rsnd_mod_to_src(mod); struct rsnd_src *src = rsnd_mod_to_src(mod);
u32 convert_rate = rsnd_src_convert_rate(src); u32 convert_rate = rsnd_src_convert_rate(io, src);
u32 cr, route; u32 cr, route;
uint ratio; uint ratio;
int ret; int ret;
...@@ -726,7 +740,7 @@ static int rsnd_src_set_convert_rate_gen2(struct rsnd_mod *mod) ...@@ -726,7 +740,7 @@ static int rsnd_src_set_convert_rate_gen2(struct rsnd_mod *mod)
return -EINVAL; return -EINVAL;
} }
ret = rsnd_src_set_convert_rate(mod); ret = rsnd_src_set_convert_rate(mod, io);
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -762,12 +776,12 @@ static int rsnd_src_set_convert_rate_gen2(struct rsnd_mod *mod) ...@@ -762,12 +776,12 @@ static int rsnd_src_set_convert_rate_gen2(struct rsnd_mod *mod)
return 0; return 0;
} }
static int rsnd_src_set_convert_timing_gen2(struct rsnd_mod *mod) static int rsnd_src_set_convert_timing_gen2(struct rsnd_dai_stream *io,
struct rsnd_mod *mod)
{ {
struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
struct rsnd_src *src = rsnd_mod_to_src(mod); struct rsnd_src *src = rsnd_mod_to_src(mod);
u32 convert_rate = rsnd_src_convert_rate(src); u32 convert_rate = rsnd_src_convert_rate(io, src);
int ret; int ret;
if (convert_rate) if (convert_rate)
...@@ -781,6 +795,7 @@ static int rsnd_src_set_convert_timing_gen2(struct rsnd_mod *mod) ...@@ -781,6 +795,7 @@ static int rsnd_src_set_convert_timing_gen2(struct rsnd_mod *mod)
} }
static int rsnd_src_probe_gen2(struct rsnd_mod *mod, static int rsnd_src_probe_gen2(struct rsnd_mod *mod,
struct rsnd_dai_stream *io,
struct rsnd_priv *priv) struct rsnd_priv *priv)
{ {
struct rsnd_src *src = rsnd_mod_to_src(mod); struct rsnd_src *src = rsnd_mod_to_src(mod);
...@@ -802,7 +817,7 @@ static int rsnd_src_probe_gen2(struct rsnd_mod *mod, ...@@ -802,7 +817,7 @@ static int rsnd_src_probe_gen2(struct rsnd_mod *mod,
return ret; return ret;
} }
ret = rsnd_dma_init(priv, ret = rsnd_dma_init(io,
rsnd_mod_to_dma(mod), rsnd_mod_to_dma(mod),
src->info->dma_id); src->info->dma_id);
...@@ -810,14 +825,16 @@ static int rsnd_src_probe_gen2(struct rsnd_mod *mod, ...@@ -810,14 +825,16 @@ static int rsnd_src_probe_gen2(struct rsnd_mod *mod,
} }
static int rsnd_src_remove_gen2(struct rsnd_mod *mod, static int rsnd_src_remove_gen2(struct rsnd_mod *mod,
struct rsnd_dai_stream *io,
struct rsnd_priv *priv) struct rsnd_priv *priv)
{ {
rsnd_dma_quit(rsnd_mod_to_dma(mod)); rsnd_dma_quit(io, rsnd_mod_to_dma(mod));
return 0; return 0;
} }
static int rsnd_src_init_gen2(struct rsnd_mod *mod, static int rsnd_src_init_gen2(struct rsnd_mod *mod,
struct rsnd_dai_stream *io,
struct rsnd_priv *priv) struct rsnd_priv *priv)
{ {
int ret; int ret;
...@@ -826,11 +843,11 @@ static int rsnd_src_init_gen2(struct rsnd_mod *mod, ...@@ -826,11 +843,11 @@ static int rsnd_src_init_gen2(struct rsnd_mod *mod,
if (ret < 0) if (ret < 0)
return ret; return ret;
ret = rsnd_src_set_convert_rate_gen2(mod); ret = rsnd_src_set_convert_rate_gen2(mod, io);
if (ret < 0) if (ret < 0)
return ret; return ret;
ret = rsnd_src_set_convert_timing_gen2(mod); ret = rsnd_src_set_convert_timing_gen2(io, mod);
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -838,31 +855,33 @@ static int rsnd_src_init_gen2(struct rsnd_mod *mod, ...@@ -838,31 +855,33 @@ static int rsnd_src_init_gen2(struct rsnd_mod *mod,
} }
static int rsnd_src_start_gen2(struct rsnd_mod *mod, static int rsnd_src_start_gen2(struct rsnd_mod *mod,
struct rsnd_dai_stream *io,
struct rsnd_priv *priv) struct rsnd_priv *priv)
{ {
rsnd_dma_start(rsnd_mod_to_dma(mod)); rsnd_dma_start(io, rsnd_mod_to_dma(mod));
return _rsnd_src_start_gen2(mod); return _rsnd_src_start_gen2(mod, io);
} }
static int rsnd_src_stop_gen2(struct rsnd_mod *mod, static int rsnd_src_stop_gen2(struct rsnd_mod *mod,
struct rsnd_dai_stream *io,
struct rsnd_priv *priv) struct rsnd_priv *priv)
{ {
int ret; int ret;
ret = _rsnd_src_stop_gen2(mod); ret = _rsnd_src_stop_gen2(mod);
rsnd_dma_stop(rsnd_mod_to_dma(mod)); rsnd_dma_stop(io, rsnd_mod_to_dma(mod));
return ret; return ret;
} }
static void rsnd_src_reconvert_update(struct rsnd_mod *mod) static void rsnd_src_reconvert_update(struct rsnd_dai_stream *io,
struct rsnd_mod *mod)
{ {
struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
struct rsnd_src *src = rsnd_mod_to_src(mod); struct rsnd_src *src = rsnd_mod_to_src(mod);
u32 convert_rate = rsnd_src_convert_rate(src); u32 convert_rate = rsnd_src_convert_rate(io, src);
u32 fsrate; u32 fsrate;
if (!runtime) if (!runtime)
...@@ -878,10 +897,10 @@ static void rsnd_src_reconvert_update(struct rsnd_mod *mod) ...@@ -878,10 +897,10 @@ static void rsnd_src_reconvert_update(struct rsnd_mod *mod)
} }
static int rsnd_src_pcm_new(struct rsnd_mod *mod, static int rsnd_src_pcm_new(struct rsnd_mod *mod,
struct rsnd_dai_stream *io,
struct snd_soc_pcm_runtime *rtd) struct snd_soc_pcm_runtime *rtd)
{ {
struct rsnd_priv *priv = rsnd_mod_to_priv(mod); struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
struct rsnd_dai *rdai = rsnd_io_to_rdai(io); struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
struct rsnd_src *src = rsnd_mod_to_src(mod); struct rsnd_src *src = rsnd_mod_to_src(mod);
int ret; int ret;
...@@ -912,7 +931,7 @@ static int rsnd_src_pcm_new(struct rsnd_mod *mod, ...@@ -912,7 +931,7 @@ static int rsnd_src_pcm_new(struct rsnd_mod *mod,
/* /*
* enable sync convert * enable sync convert
*/ */
ret = rsnd_kctrl_new_s(mod, rtd, ret = rsnd_kctrl_new_s(mod, io, rtd,
rsnd_io_is_play(io) ? rsnd_io_is_play(io) ?
"SRC Out Rate Switch" : "SRC Out Rate Switch" :
"SRC In Rate Switch", "SRC In Rate Switch",
...@@ -921,7 +940,7 @@ static int rsnd_src_pcm_new(struct rsnd_mod *mod, ...@@ -921,7 +940,7 @@ static int rsnd_src_pcm_new(struct rsnd_mod *mod,
if (ret < 0) if (ret < 0)
return ret; return ret;
ret = rsnd_kctrl_new_s(mod, rtd, ret = rsnd_kctrl_new_s(mod, io, rtd,
rsnd_io_is_play(io) ? rsnd_io_is_play(io) ?
"SRC Out Rate" : "SRC Out Rate" :
"SRC In Rate", "SRC In Rate",
...@@ -1046,7 +1065,7 @@ int rsnd_src_probe(struct platform_device *pdev, ...@@ -1046,7 +1065,7 @@ int rsnd_src_probe(struct platform_device *pdev,
src->info = &info->src_info[i]; src->info = &info->src_info[i];
ret = rsnd_mod_init(&src->mod, ops, clk, RSND_MOD_SRC, i); ret = rsnd_mod_init(priv, &src->mod, ops, clk, RSND_MOD_SRC, i);
if (ret) if (ret)
return ret; return ret;
} }
......
...@@ -87,10 +87,9 @@ struct rsnd_ssi { ...@@ -87,10 +87,9 @@ struct rsnd_ssi {
#define rsnd_ssi_of_node(priv) \ #define rsnd_ssi_of_node(priv) \
of_get_child_by_name(rsnd_priv_to_dev(priv)->of_node, "rcar_sound,ssi") of_get_child_by_name(rsnd_priv_to_dev(priv)->of_node, "rcar_sound,ssi")
int rsnd_ssi_use_busif(struct rsnd_mod *mod) int rsnd_ssi_use_busif(struct rsnd_dai_stream *io, struct rsnd_mod *mod)
{ {
struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
int use_busif = 0; int use_busif = 0;
if (!rsnd_ssi_is_dma_mode(mod)) if (!rsnd_ssi_is_dma_mode(mod))
...@@ -199,15 +198,17 @@ static void rsnd_ssi_hw_start(struct rsnd_ssi *ssi, ...@@ -199,15 +198,17 @@ static void rsnd_ssi_hw_start(struct rsnd_ssi *ssi,
} }
} }
cr_mode = rsnd_ssi_is_dma_mode(&ssi->mod) ? if (rsnd_ssi_is_dma_mode(&ssi->mod)) {
DMEN : /* DMA : enable DMA */ cr_mode = UIEN | OIEN | /* over/under run */
DIEN; /* PIO : enable Data interrupt */ DMEN; /* DMA : enable DMA */
} else {
cr_mode = DIEN; /* PIO : enable Data interrupt */
}
cr = ssi->cr_own | cr = ssi->cr_own |
ssi->cr_clk | ssi->cr_clk |
cr_mode | cr_mode |
UIEN | OIEN | EN; EN;
rsnd_mod_write(&ssi->mod, SSICR, cr); rsnd_mod_write(&ssi->mod, SSICR, cr);
...@@ -224,10 +225,9 @@ static void rsnd_ssi_hw_start(struct rsnd_ssi *ssi, ...@@ -224,10 +225,9 @@ static void rsnd_ssi_hw_start(struct rsnd_ssi *ssi,
rsnd_mod_name(&ssi->mod), rsnd_mod_id(&ssi->mod)); rsnd_mod_name(&ssi->mod), rsnd_mod_id(&ssi->mod));
} }
static void rsnd_ssi_hw_stop(struct rsnd_ssi *ssi) static void rsnd_ssi_hw_stop(struct rsnd_dai_stream *io, struct rsnd_ssi *ssi)
{ {
struct rsnd_priv *priv = rsnd_mod_to_priv(&ssi->mod); struct rsnd_priv *priv = rsnd_mod_to_priv(&ssi->mod);
struct rsnd_dai_stream *io = rsnd_mod_to_io(&ssi->mod);
struct rsnd_dai *rdai = rsnd_io_to_rdai(io); struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
struct device *dev = rsnd_priv_to_dev(priv); struct device *dev = rsnd_priv_to_dev(priv);
u32 cr; u32 cr;
...@@ -261,7 +261,7 @@ static void rsnd_ssi_hw_stop(struct rsnd_ssi *ssi) ...@@ -261,7 +261,7 @@ static void rsnd_ssi_hw_stop(struct rsnd_ssi *ssi)
struct rsnd_ssi *ssi_parent = rsnd_ssi_parent(ssi); struct rsnd_ssi *ssi_parent = rsnd_ssi_parent(ssi);
if (ssi_parent) if (ssi_parent)
rsnd_ssi_hw_stop(ssi_parent); rsnd_ssi_hw_stop(io, ssi_parent);
else else
rsnd_ssi_master_clk_stop(ssi); rsnd_ssi_master_clk_stop(ssi);
} }
...@@ -279,10 +279,10 @@ static void rsnd_ssi_hw_stop(struct rsnd_ssi *ssi) ...@@ -279,10 +279,10 @@ static void rsnd_ssi_hw_stop(struct rsnd_ssi *ssi)
* SSI mod common functions * SSI mod common functions
*/ */
static int rsnd_ssi_init(struct rsnd_mod *mod, static int rsnd_ssi_init(struct rsnd_mod *mod,
struct rsnd_dai_stream *io,
struct rsnd_priv *priv) struct rsnd_priv *priv)
{ {
struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
struct rsnd_dai *rdai = rsnd_io_to_rdai(io); struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
u32 cr; u32 cr;
...@@ -330,6 +330,7 @@ static int rsnd_ssi_init(struct rsnd_mod *mod, ...@@ -330,6 +330,7 @@ static int rsnd_ssi_init(struct rsnd_mod *mod,
} }
static int rsnd_ssi_quit(struct rsnd_mod *mod, static int rsnd_ssi_quit(struct rsnd_mod *mod,
struct rsnd_dai_stream *io,
struct rsnd_priv *priv) struct rsnd_priv *priv)
{ {
struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
...@@ -346,6 +347,7 @@ static int rsnd_ssi_quit(struct rsnd_mod *mod, ...@@ -346,6 +347,7 @@ static int rsnd_ssi_quit(struct rsnd_mod *mod,
} }
static int rsnd_ssi_hw_params(struct rsnd_mod *mod, static int rsnd_ssi_hw_params(struct rsnd_mod *mod,
struct rsnd_dai_stream *io,
struct snd_pcm_substream *substream, struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params) struct snd_pcm_hw_params *params)
{ {
...@@ -369,7 +371,8 @@ static int rsnd_ssi_hw_params(struct rsnd_mod *mod, ...@@ -369,7 +371,8 @@ static int rsnd_ssi_hw_params(struct rsnd_mod *mod,
/* It will be removed on rsnd_ssi_hw_stop */ /* It will be removed on rsnd_ssi_hw_stop */
ssi->chan = chan; ssi->chan = chan;
if (ssi_parent) if (ssi_parent)
return rsnd_ssi_hw_params(&ssi_parent->mod, substream, params); return rsnd_ssi_hw_params(&ssi_parent->mod, io,
substream, params);
return 0; return 0;
} }
...@@ -386,12 +389,12 @@ static void rsnd_ssi_record_error(struct rsnd_ssi *ssi, u32 status) ...@@ -386,12 +389,12 @@ static void rsnd_ssi_record_error(struct rsnd_ssi *ssi, u32 status)
} }
static int rsnd_ssi_start(struct rsnd_mod *mod, static int rsnd_ssi_start(struct rsnd_mod *mod,
struct rsnd_dai_stream *io,
struct rsnd_priv *priv) struct rsnd_priv *priv)
{ {
struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
rsnd_src_ssiu_start(mod, rsnd_ssi_use_busif(mod)); rsnd_src_ssiu_start(mod, io, rsnd_ssi_use_busif(io, mod));
rsnd_ssi_hw_start(ssi, io); rsnd_ssi_hw_start(ssi, io);
...@@ -401,6 +404,7 @@ static int rsnd_ssi_start(struct rsnd_mod *mod, ...@@ -401,6 +404,7 @@ static int rsnd_ssi_start(struct rsnd_mod *mod,
} }
static int rsnd_ssi_stop(struct rsnd_mod *mod, static int rsnd_ssi_stop(struct rsnd_mod *mod,
struct rsnd_dai_stream *io,
struct rsnd_priv *priv) struct rsnd_priv *priv)
{ {
struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
...@@ -409,26 +413,26 @@ static int rsnd_ssi_stop(struct rsnd_mod *mod, ...@@ -409,26 +413,26 @@ static int rsnd_ssi_stop(struct rsnd_mod *mod,
rsnd_ssi_record_error(ssi, rsnd_mod_read(mod, SSISR)); rsnd_ssi_record_error(ssi, rsnd_mod_read(mod, SSISR));
rsnd_ssi_hw_stop(ssi); rsnd_ssi_hw_stop(io, ssi);
rsnd_src_ssiu_stop(mod); rsnd_src_ssiu_stop(mod, io);
return 0; return 0;
} }
static irqreturn_t rsnd_ssi_interrupt(int irq, void *data) static void __rsnd_ssi_interrupt(struct rsnd_mod *mod,
struct rsnd_dai_stream *io)
{ {
struct rsnd_ssi *ssi = data; struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
struct rsnd_mod *mod = &ssi->mod;
struct rsnd_priv *priv = rsnd_mod_to_priv(mod); struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
int is_dma = rsnd_ssi_is_dma_mode(mod); int is_dma = rsnd_ssi_is_dma_mode(mod);
u32 status; u32 status;
bool elapsed = false;
spin_lock(&priv->lock); spin_lock(&priv->lock);
/* ignore all cases if not working */ /* ignore all cases if not working */
if (!rsnd_mod_is_working(mod)) if (!rsnd_io_is_working(io))
goto rsnd_ssi_interrupt_out; goto rsnd_ssi_interrupt_out;
status = rsnd_mod_read(mod, SSISR); status = rsnd_mod_read(mod, SSISR);
...@@ -449,11 +453,11 @@ static irqreturn_t rsnd_ssi_interrupt(int irq, void *data) ...@@ -449,11 +453,11 @@ static irqreturn_t rsnd_ssi_interrupt(int irq, void *data)
else else
*buf = rsnd_mod_read(mod, SSIRDR); *buf = rsnd_mod_read(mod, SSIRDR);
rsnd_dai_pointer_update(io, sizeof(*buf)); elapsed = rsnd_dai_pointer_update(io, sizeof(*buf));
} }
/* PIO / DMA */ /* DMA only */
if (status & (UIRQ | OIRQ)) { if (is_dma && (status & (UIRQ | OIRQ))) {
struct device *dev = rsnd_priv_to_dev(priv); struct device *dev = rsnd_priv_to_dev(priv);
/* /*
...@@ -462,9 +466,9 @@ static irqreturn_t rsnd_ssi_interrupt(int irq, void *data) ...@@ -462,9 +466,9 @@ static irqreturn_t rsnd_ssi_interrupt(int irq, void *data)
dev_dbg(dev, "%s[%d] restart\n", dev_dbg(dev, "%s[%d] restart\n",
rsnd_mod_name(mod), rsnd_mod_id(mod)); rsnd_mod_name(mod), rsnd_mod_id(mod));
rsnd_ssi_stop(mod, priv); rsnd_ssi_stop(mod, io, priv);
if (ssi->err < 1024) if (ssi->err < 1024)
rsnd_ssi_start(mod, priv); rsnd_ssi_start(mod, io, priv);
else else
dev_warn(dev, "no more SSI restart\n"); dev_warn(dev, "no more SSI restart\n");
} }
...@@ -474,6 +478,16 @@ static irqreturn_t rsnd_ssi_interrupt(int irq, void *data) ...@@ -474,6 +478,16 @@ static irqreturn_t rsnd_ssi_interrupt(int irq, void *data)
rsnd_ssi_interrupt_out: rsnd_ssi_interrupt_out:
spin_unlock(&priv->lock); spin_unlock(&priv->lock);
if (elapsed)
rsnd_dai_period_elapsed(io);
}
static irqreturn_t rsnd_ssi_interrupt(int irq, void *data)
{
struct rsnd_mod *mod = data;
rsnd_mod_interrupt(mod, __rsnd_ssi_interrupt);
return IRQ_HANDLED; return IRQ_HANDLED;
} }
...@@ -481,6 +495,7 @@ static irqreturn_t rsnd_ssi_interrupt(int irq, void *data) ...@@ -481,6 +495,7 @@ static irqreturn_t rsnd_ssi_interrupt(int irq, void *data)
* SSI PIO * SSI PIO
*/ */
static int rsnd_ssi_pio_probe(struct rsnd_mod *mod, static int rsnd_ssi_pio_probe(struct rsnd_mod *mod,
struct rsnd_dai_stream *io,
struct rsnd_priv *priv) struct rsnd_priv *priv)
{ {
struct device *dev = rsnd_priv_to_dev(priv); struct device *dev = rsnd_priv_to_dev(priv);
...@@ -490,7 +505,7 @@ static int rsnd_ssi_pio_probe(struct rsnd_mod *mod, ...@@ -490,7 +505,7 @@ static int rsnd_ssi_pio_probe(struct rsnd_mod *mod,
ret = devm_request_irq(dev, ssi->info->irq, ret = devm_request_irq(dev, ssi->info->irq,
rsnd_ssi_interrupt, rsnd_ssi_interrupt,
IRQF_SHARED, IRQF_SHARED,
dev_name(dev), ssi); dev_name(dev), mod);
return ret; return ret;
} }
...@@ -506,6 +521,7 @@ static struct rsnd_mod_ops rsnd_ssi_pio_ops = { ...@@ -506,6 +521,7 @@ static struct rsnd_mod_ops rsnd_ssi_pio_ops = {
}; };
static int rsnd_ssi_dma_probe(struct rsnd_mod *mod, static int rsnd_ssi_dma_probe(struct rsnd_mod *mod,
struct rsnd_dai_stream *io,
struct rsnd_priv *priv) struct rsnd_priv *priv)
{ {
struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
...@@ -516,25 +532,26 @@ static int rsnd_ssi_dma_probe(struct rsnd_mod *mod, ...@@ -516,25 +532,26 @@ static int rsnd_ssi_dma_probe(struct rsnd_mod *mod,
ret = devm_request_irq(dev, ssi->info->irq, ret = devm_request_irq(dev, ssi->info->irq,
rsnd_ssi_interrupt, rsnd_ssi_interrupt,
IRQF_SHARED, IRQF_SHARED,
dev_name(dev), ssi); dev_name(dev), mod);
if (ret) if (ret)
return ret; return ret;
ret = rsnd_dma_init( ret = rsnd_dma_init(
priv, rsnd_mod_to_dma(mod), io, rsnd_mod_to_dma(mod),
dma_id); dma_id);
return ret; return ret;
} }
static int rsnd_ssi_dma_remove(struct rsnd_mod *mod, static int rsnd_ssi_dma_remove(struct rsnd_mod *mod,
struct rsnd_dai_stream *io,
struct rsnd_priv *priv) struct rsnd_priv *priv)
{ {
struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
struct device *dev = rsnd_priv_to_dev(priv); struct device *dev = rsnd_priv_to_dev(priv);
int irq = ssi->info->irq; int irq = ssi->info->irq;
rsnd_dma_quit(rsnd_mod_to_dma(mod)); rsnd_dma_quit(io, rsnd_mod_to_dma(mod));
/* PIO will request IRQ again */ /* PIO will request IRQ again */
devm_free_irq(dev, irq, ssi); devm_free_irq(dev, irq, ssi);
...@@ -543,6 +560,7 @@ static int rsnd_ssi_dma_remove(struct rsnd_mod *mod, ...@@ -543,6 +560,7 @@ static int rsnd_ssi_dma_remove(struct rsnd_mod *mod,
} }
static int rsnd_ssi_fallback(struct rsnd_mod *mod, static int rsnd_ssi_fallback(struct rsnd_mod *mod,
struct rsnd_dai_stream *io,
struct rsnd_priv *priv) struct rsnd_priv *priv)
{ {
struct device *dev = rsnd_priv_to_dev(priv); struct device *dev = rsnd_priv_to_dev(priv);
...@@ -563,37 +581,39 @@ static int rsnd_ssi_fallback(struct rsnd_mod *mod, ...@@ -563,37 +581,39 @@ static int rsnd_ssi_fallback(struct rsnd_mod *mod,
} }
static int rsnd_ssi_dma_start(struct rsnd_mod *mod, static int rsnd_ssi_dma_start(struct rsnd_mod *mod,
struct rsnd_dai_stream *io,
struct rsnd_priv *priv) struct rsnd_priv *priv)
{ {
struct rsnd_dma *dma = rsnd_mod_to_dma(mod); struct rsnd_dma *dma = rsnd_mod_to_dma(mod);
rsnd_dma_start(dma); rsnd_dma_start(io, dma);
rsnd_ssi_start(mod, priv); rsnd_ssi_start(mod, io, priv);
return 0; return 0;
} }
static int rsnd_ssi_dma_stop(struct rsnd_mod *mod, static int rsnd_ssi_dma_stop(struct rsnd_mod *mod,
struct rsnd_dai_stream *io,
struct rsnd_priv *priv) struct rsnd_priv *priv)
{ {
struct rsnd_dma *dma = rsnd_mod_to_dma(mod); struct rsnd_dma *dma = rsnd_mod_to_dma(mod);
rsnd_ssi_stop(mod, priv); rsnd_ssi_stop(mod, io, priv);
rsnd_dma_stop(dma); rsnd_dma_stop(io, dma);
return 0; return 0;
} }
static struct dma_chan *rsnd_ssi_dma_req(struct rsnd_mod *mod) static struct dma_chan *rsnd_ssi_dma_req(struct rsnd_dai_stream *io,
struct rsnd_mod *mod)
{ {
struct rsnd_priv *priv = rsnd_mod_to_priv(mod); struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
int is_play = rsnd_io_is_play(io); int is_play = rsnd_io_is_play(io);
char *name; char *name;
if (rsnd_ssi_use_busif(mod)) if (rsnd_ssi_use_busif(io, mod))
name = is_play ? "rxu" : "txu"; name = is_play ? "rxu" : "txu";
else else
name = is_play ? "rx" : "tx"; name = is_play ? "rx" : "tx";
...@@ -776,7 +796,7 @@ int rsnd_ssi_probe(struct platform_device *pdev, ...@@ -776,7 +796,7 @@ int rsnd_ssi_probe(struct platform_device *pdev,
else if (rsnd_ssi_pio_available(ssi)) else if (rsnd_ssi_pio_available(ssi))
ops = &rsnd_ssi_pio_ops; ops = &rsnd_ssi_pio_ops;
ret = rsnd_mod_init(&ssi->mod, ops, clk, RSND_MOD_SSI, i); ret = rsnd_mod_init(priv, &ssi->mod, ops, clk, RSND_MOD_SSI, i);
if (ret) if (ret)
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment