Merge remote-tracking branches 'asoc/topic/ssm2518', 'asoc/topic/sta529', 'asoc/topic/sti' and 'asoc/topic/sti-sas' into asoc-next
This commit is contained in:
Коммит
0a5ff07757
|
@ -0,0 +1,155 @@
|
|||
STMicroelectronics sti ASoC cards
|
||||
|
||||
The sti ASoC Sound Card can be used, for all sti SoCs using internal sti-sas
|
||||
codec or external codecs.
|
||||
|
||||
sti sound drivers allows to expose sti SoC audio interface through the
|
||||
generic ASoC simple card. For details about sound card declaration please refer to
|
||||
Documentation/devicetree/bindings/sound/simple-card.txt.
|
||||
|
||||
1) sti-uniperiph-dai: audio dai device.
|
||||
---------------------------------------
|
||||
|
||||
Required properties:
|
||||
- compatible: "st,sti-uni-player" or "st,sti-uni-reader"
|
||||
|
||||
- st,syscfg: phandle to boot-device system configuration registers
|
||||
|
||||
- clock-names: name of the clocks listed in clocks property in the same order
|
||||
|
||||
- reg: CPU DAI IP Base address and size entries, listed in same
|
||||
order than the CPU_DAI properties.
|
||||
|
||||
- reg-names: names of the mapped memory regions listed in regs property in
|
||||
the same order.
|
||||
|
||||
- interrupts: CPU_DAI interrupt line, listed in the same order than the
|
||||
CPU_DAI properties.
|
||||
|
||||
- dma: CPU_DAI DMA controller phandle and DMA request line, listed in the same
|
||||
order than the CPU_DAI properties.
|
||||
|
||||
- dma-names: identifier string for each DMA request line in the dmas property.
|
||||
"tx" for "st,sti-uni-player" compatibility
|
||||
"rx" for "st,sti-uni-reader" compatibility
|
||||
|
||||
- version: IP version integrated in SOC.
|
||||
|
||||
- dai-name: DAI name that describes the IP.
|
||||
|
||||
Required properties ("st,sti-uni-player" compatibility only):
|
||||
- clocks: CPU_DAI IP clock source, listed in the same order than the
|
||||
CPU_DAI properties.
|
||||
|
||||
- uniperiph-id: internal SOC IP instance ID.
|
||||
|
||||
- IP mode: IP working mode depending on associated codec.
|
||||
"HDMI" connected to HDMI codec IP and IEC HDMI formats.
|
||||
"SPDIF"connected to SPDIF codec and support SPDIF formats.
|
||||
"PCM" PCM standard mode for I2S or TDM bus.
|
||||
|
||||
Optional properties:
|
||||
- pinctrl-0: defined for CPU_DAI@1 and CPU_DAI@4 to describe I2S PIOs for
|
||||
external codecs connection.
|
||||
|
||||
- pinctrl-names: should contain only one value - "default".
|
||||
|
||||
Example:
|
||||
|
||||
sti_uni_player2: sti-uni-player@2 {
|
||||
compatible = "st,sti-uni-player";
|
||||
status = "okay";
|
||||
#sound-dai-cells = <0>;
|
||||
st,syscfg = <&syscfg_core>;
|
||||
clocks = <&clk_s_d0_flexgen CLK_PCM_2>;
|
||||
reg = <0x8D82000 0x158>;
|
||||
interrupts = <GIC_SPI 86 IRQ_TYPE_NONE>;
|
||||
dmas = <&fdma0 4 0 1>;
|
||||
dai-name = "Uni Player #1 (DAC)";
|
||||
dma-names = "tx";
|
||||
uniperiph-id = <2>;
|
||||
version = <5>;
|
||||
mode = "PCM";
|
||||
};
|
||||
|
||||
sti_uni_player3: sti-uni-player@3 {
|
||||
compatible = "st,sti-uni-player";
|
||||
status = "okay";
|
||||
#sound-dai-cells = <0>;
|
||||
st,syscfg = <&syscfg_core>;
|
||||
clocks = <&clk_s_d0_flexgen CLK_SPDIFF>;
|
||||
reg = <0x8D85000 0x158>;
|
||||
interrupts = <GIC_SPI 89 IRQ_TYPE_NONE>;
|
||||
dmas = <&fdma0 7 0 1>;
|
||||
dma-names = "tx";
|
||||
dai-name = "Uni Player #1 (PIO)";
|
||||
uniperiph-id = <3>;
|
||||
version = <5>;
|
||||
mode = "SPDIF";
|
||||
};
|
||||
|
||||
sti_uni_reader1: sti-uni-reader@1 {
|
||||
compatible = "st,sti-uni-reader";
|
||||
status = "disabled";
|
||||
#sound-dai-cells = <0>;
|
||||
st,syscfg = <&syscfg_core>;
|
||||
reg = <0x8D84000 0x158>;
|
||||
interrupts = <GIC_SPI 88 IRQ_TYPE_NONE>;
|
||||
dmas = <&fdma0 6 0 1>;
|
||||
dma-names = "rx";
|
||||
dai-name = "Uni Reader #1 (HDMI RX)";
|
||||
version = <3>;
|
||||
};
|
||||
|
||||
2) sti-sas-codec: internal audio codec IPs driver
|
||||
-------------------------------------------------
|
||||
|
||||
Required properties:
|
||||
- compatible: "st,sti<chip>-sas-codec" .
|
||||
Should be chip "st,stih416-sas-codec" or "st,stih407-sas-codec"
|
||||
|
||||
- st,syscfg: phandle to boot-device system configuration registers.
|
||||
|
||||
- pinctrl-0: SPDIF PIO description.
|
||||
|
||||
- pinctrl-names: should contain only one value - "default".
|
||||
|
||||
Example:
|
||||
sti_sas_codec: sti-sas-codec {
|
||||
compatible = "st,stih407-sas-codec";
|
||||
#sound-dai-cells = <1>;
|
||||
st,reg_audio = <&syscfg_core>;
|
||||
pinctrl-names = "default";
|
||||
pinctrl-0 = <&pinctrl_spdif_out >;
|
||||
};
|
||||
|
||||
Example of audio card declaration:
|
||||
sound {
|
||||
compatible = "simple-audio-card";
|
||||
simple-audio-card,name = "sti audio card";
|
||||
status = "okay";
|
||||
|
||||
simple-audio-card,dai-link@0 {
|
||||
/* DAC */
|
||||
format = "i2s";
|
||||
dai-tdm-slot-width = <32>;
|
||||
cpu {
|
||||
sound-dai = <&sti_uni_player2>;
|
||||
};
|
||||
|
||||
codec {
|
||||
sound-dai = <&sti_sasg_codec 1>;
|
||||
};
|
||||
};
|
||||
simple-audio-card,dai-link@1 {
|
||||
/* SPDIF */
|
||||
format = "left_j";
|
||||
cpu {
|
||||
sound-dai = <&sti_uni_player3>;
|
||||
};
|
||||
|
||||
codec {
|
||||
sound-dai = <&sti_sasg_codec 0>;
|
||||
};
|
||||
};
|
||||
};
|
|
@ -57,6 +57,7 @@ source "sound/soc/samsung/Kconfig"
|
|||
source "sound/soc/sh/Kconfig"
|
||||
source "sound/soc/sirf/Kconfig"
|
||||
source "sound/soc/spear/Kconfig"
|
||||
source "sound/soc/sti/Kconfig"
|
||||
source "sound/soc/tegra/Kconfig"
|
||||
source "sound/soc/txx9/Kconfig"
|
||||
source "sound/soc/ux500/Kconfig"
|
||||
|
|
|
@ -39,6 +39,7 @@ obj-$(CONFIG_SND_SOC) += samsung/
|
|||
obj-$(CONFIG_SND_SOC) += sh/
|
||||
obj-$(CONFIG_SND_SOC) += sirf/
|
||||
obj-$(CONFIG_SND_SOC) += spear/
|
||||
obj-$(CONFIG_SND_SOC) += sti/
|
||||
obj-$(CONFIG_SND_SOC) += tegra/
|
||||
obj-$(CONFIG_SND_SOC) += txx9/
|
||||
obj-$(CONFIG_SND_SOC) += ux500/
|
||||
|
|
|
@ -106,6 +106,7 @@ config SND_SOC_ALL_CODECS
|
|||
select SND_SOC_STA350 if I2C
|
||||
select SND_SOC_STA529 if I2C
|
||||
select SND_SOC_STAC9766 if SND_SOC_AC97_BUS
|
||||
select SND_SOC_STI_SAS
|
||||
select SND_SOC_TAS2552 if I2C
|
||||
select SND_SOC_TAS5086 if I2C
|
||||
select SND_SOC_TAS571X if I2C
|
||||
|
@ -631,6 +632,9 @@ config SND_SOC_STA529
|
|||
config SND_SOC_STAC9766
|
||||
tristate
|
||||
|
||||
config SND_SOC_STI_SAS
|
||||
tristate "codec Audio support for STI SAS codec"
|
||||
|
||||
config SND_SOC_TAS2552
|
||||
tristate "Texas Instruments TAS2552 Mono Audio amplifier"
|
||||
depends on I2C
|
||||
|
|
|
@ -110,6 +110,7 @@ snd-soc-sta32x-objs := sta32x.o
|
|||
snd-soc-sta350-objs := sta350.o
|
||||
snd-soc-sta529-objs := sta529.o
|
||||
snd-soc-stac9766-objs := stac9766.o
|
||||
snd-soc-sti-sas-objs := sti-sas.o
|
||||
snd-soc-tas5086-objs := tas5086.o
|
||||
snd-soc-tas571x-objs := tas571x.o
|
||||
snd-soc-tfa9879-objs := tfa9879.o
|
||||
|
@ -297,6 +298,7 @@ obj-$(CONFIG_SND_SOC_STA32X) += snd-soc-sta32x.o
|
|||
obj-$(CONFIG_SND_SOC_STA350) += snd-soc-sta350.o
|
||||
obj-$(CONFIG_SND_SOC_STA529) += snd-soc-sta529.o
|
||||
obj-$(CONFIG_SND_SOC_STAC9766) += snd-soc-stac9766.o
|
||||
obj-$(CONFIG_SND_SOC_STI_SAS) += snd-soc-sti-sas.o
|
||||
obj-$(CONFIG_SND_SOC_TAS2552) += snd-soc-tas2552.o
|
||||
obj-$(CONFIG_SND_SOC_TAS5086) += snd-soc-tas5086.o
|
||||
obj-$(CONFIG_SND_SOC_TAS571X) += snd-soc-tas571x.o
|
||||
|
|
|
@ -806,6 +806,14 @@ static int ssm2518_i2c_remove(struct i2c_client *client)
|
|||
return 0;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_OF
|
||||
static const struct of_device_id ssm2518_dt_ids[] = {
|
||||
{ .compatible = "adi,ssm2518", },
|
||||
{ }
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, ssm2518_dt_ids);
|
||||
#endif
|
||||
|
||||
static const struct i2c_device_id ssm2518_i2c_ids[] = {
|
||||
{ "ssm2518", 0 },
|
||||
{ }
|
||||
|
@ -815,6 +823,7 @@ MODULE_DEVICE_TABLE(i2c, ssm2518_i2c_ids);
|
|||
static struct i2c_driver ssm2518_driver = {
|
||||
.driver = {
|
||||
.name = "ssm2518",
|
||||
.of_match_table = of_match_ptr(ssm2518_dt_ids),
|
||||
},
|
||||
.probe = ssm2518_i2c_probe,
|
||||
.remove = ssm2518_i2c_remove,
|
||||
|
|
|
@ -339,9 +339,6 @@ static int sta529_i2c_probe(struct i2c_client *i2c,
|
|||
struct sta529 *sta529;
|
||||
int ret;
|
||||
|
||||
if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
|
||||
return -EINVAL;
|
||||
|
||||
sta529 = devm_kzalloc(&i2c->dev, sizeof(struct sta529), GFP_KERNEL);
|
||||
if (!sta529)
|
||||
return -ENOMEM;
|
||||
|
|
|
@ -0,0 +1,628 @@
|
|||
/*
|
||||
* Copyright (C) STMicroelectronics SA 2015
|
||||
* Authors: Arnaud Pouliquen <arnaud.pouliquen@st.com>
|
||||
* for STMicroelectronics.
|
||||
* License terms: GNU General Public License (GPL), version 2
|
||||
*/
|
||||
|
||||
#include <linux/io.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/regmap.h>
|
||||
#include <linux/reset.h>
|
||||
#include <linux/mfd/syscon.h>
|
||||
|
||||
#include <sound/soc.h>
|
||||
#include <sound/soc-dapm.h>
|
||||
|
||||
/* chipID supported */
|
||||
#define CHIPID_STIH416 0
|
||||
#define CHIPID_STIH407 1
|
||||
|
||||
/* DAC definitions */
|
||||
|
||||
/* stih416 DAC registers */
|
||||
/* sysconf 2517: Audio-DAC-Control */
|
||||
#define STIH416_AUDIO_DAC_CTRL 0x00000814
|
||||
/* sysconf 2519: Audio-Gue-Control */
|
||||
#define STIH416_AUDIO_GLUE_CTRL 0x0000081C
|
||||
|
||||
#define STIH416_DAC_NOT_STANDBY 0x3
|
||||
#define STIH416_DAC_SOFTMUTE 0x4
|
||||
#define STIH416_DAC_ANA_NOT_PWR 0x5
|
||||
#define STIH416_DAC_NOT_PNDBG 0x6
|
||||
|
||||
#define STIH416_DAC_NOT_STANDBY_MASK BIT(STIH416_DAC_NOT_STANDBY)
|
||||
#define STIH416_DAC_SOFTMUTE_MASK BIT(STIH416_DAC_SOFTMUTE)
|
||||
#define STIH416_DAC_ANA_NOT_PWR_MASK BIT(STIH416_DAC_ANA_NOT_PWR)
|
||||
#define STIH416_DAC_NOT_PNDBG_MASK BIT(STIH416_DAC_NOT_PNDBG)
|
||||
|
||||
/* stih407 DAC registers */
|
||||
/* sysconf 5041: Audio-Gue-Control */
|
||||
#define STIH407_AUDIO_GLUE_CTRL 0x000000A4
|
||||
/* sysconf 5042: Audio-DAC-Control */
|
||||
#define STIH407_AUDIO_DAC_CTRL 0x000000A8
|
||||
|
||||
/* DAC definitions */
|
||||
#define STIH407_DAC_SOFTMUTE 0x0
|
||||
#define STIH407_DAC_STANDBY_ANA 0x1
|
||||
#define STIH407_DAC_STANDBY 0x2
|
||||
|
||||
#define STIH407_DAC_SOFTMUTE_MASK BIT(STIH407_DAC_SOFTMUTE)
|
||||
#define STIH407_DAC_STANDBY_ANA_MASK BIT(STIH407_DAC_STANDBY_ANA)
|
||||
#define STIH407_DAC_STANDBY_MASK BIT(STIH407_DAC_STANDBY)
|
||||
|
||||
/* SPDIF definitions */
|
||||
#define SPDIF_BIPHASE_ENABLE 0x6
|
||||
#define SPDIF_BIPHASE_IDLE 0x7
|
||||
|
||||
#define SPDIF_BIPHASE_ENABLE_MASK BIT(SPDIF_BIPHASE_ENABLE)
|
||||
#define SPDIF_BIPHASE_IDLE_MASK BIT(SPDIF_BIPHASE_IDLE)
|
||||
|
||||
enum {
|
||||
STI_SAS_DAI_SPDIF_OUT,
|
||||
STI_SAS_DAI_ANALOG_OUT,
|
||||
};
|
||||
|
||||
static const struct reg_default stih416_sas_reg_defaults[] = {
|
||||
{ STIH407_AUDIO_GLUE_CTRL, 0x00000040 },
|
||||
{ STIH407_AUDIO_DAC_CTRL, 0x000000000 },
|
||||
};
|
||||
|
||||
static const struct reg_default stih407_sas_reg_defaults[] = {
|
||||
{ STIH416_AUDIO_DAC_CTRL, 0x000000000 },
|
||||
{ STIH416_AUDIO_GLUE_CTRL, 0x00000040 },
|
||||
};
|
||||
|
||||
struct sti_dac_audio {
|
||||
struct regmap *regmap;
|
||||
struct regmap *virt_regmap;
|
||||
struct regmap_field **field;
|
||||
struct reset_control *rst;
|
||||
int mclk;
|
||||
};
|
||||
|
||||
struct sti_spdif_audio {
|
||||
struct regmap *regmap;
|
||||
struct regmap_field **field;
|
||||
int mclk;
|
||||
};
|
||||
|
||||
/* device data structure */
|
||||
struct sti_sas_dev_data {
|
||||
const int chipid; /* IC version */
|
||||
const struct regmap_config *regmap;
|
||||
const struct snd_soc_dai_ops *dac_ops; /* DAC function callbacks */
|
||||
const struct snd_soc_dapm_widget *dapm_widgets; /* dapms declaration */
|
||||
const int num_dapm_widgets; /* dapms declaration */
|
||||
const struct snd_soc_dapm_route *dapm_routes; /* route declaration */
|
||||
const int num_dapm_routes; /* route declaration */
|
||||
};
|
||||
|
||||
/* driver data structure */
|
||||
struct sti_sas_data {
|
||||
struct device *dev;
|
||||
const struct sti_sas_dev_data *dev_data;
|
||||
struct sti_dac_audio dac;
|
||||
struct sti_spdif_audio spdif;
|
||||
};
|
||||
|
||||
/* Read a register from the sysconf reg bank */
|
||||
static int sti_sas_read_reg(void *context, unsigned int reg,
|
||||
unsigned int *value)
|
||||
{
|
||||
struct sti_sas_data *drvdata = context;
|
||||
int status;
|
||||
u32 val;
|
||||
|
||||
status = regmap_read(drvdata->dac.regmap, reg, &val);
|
||||
*value = (unsigned int)val;
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/* Read a register from the sysconf reg bank */
|
||||
static int sti_sas_write_reg(void *context, unsigned int reg,
|
||||
unsigned int value)
|
||||
{
|
||||
struct sti_sas_data *drvdata = context;
|
||||
int status;
|
||||
|
||||
status = regmap_write(drvdata->dac.regmap, reg, value);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
static int sti_sas_init_sas_registers(struct snd_soc_codec *codec,
|
||||
struct sti_sas_data *data)
|
||||
{
|
||||
int ret;
|
||||
/*
|
||||
* DAC and SPDIF are activated by default
|
||||
* put them in IDLE to save power
|
||||
*/
|
||||
|
||||
/* Initialise bi-phase formatter to disabled */
|
||||
ret = snd_soc_update_bits(codec, STIH407_AUDIO_GLUE_CTRL,
|
||||
SPDIF_BIPHASE_ENABLE_MASK, 0);
|
||||
|
||||
if (!ret)
|
||||
/* Initialise bi-phase formatter idle value to 0 */
|
||||
ret = snd_soc_update_bits(codec, STIH407_AUDIO_GLUE_CTRL,
|
||||
SPDIF_BIPHASE_IDLE_MASK, 0);
|
||||
if (ret < 0) {
|
||||
dev_err(codec->dev, "Failed to update SPDIF registers");
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Init DAC configuration */
|
||||
switch (data->dev_data->chipid) {
|
||||
case CHIPID_STIH407:
|
||||
/* init configuration */
|
||||
ret = snd_soc_update_bits(codec, STIH407_AUDIO_DAC_CTRL,
|
||||
STIH407_DAC_STANDBY_MASK,
|
||||
STIH407_DAC_STANDBY_MASK);
|
||||
|
||||
if (!ret)
|
||||
ret = snd_soc_update_bits(codec, STIH407_AUDIO_DAC_CTRL,
|
||||
STIH407_DAC_STANDBY_ANA_MASK,
|
||||
STIH407_DAC_STANDBY_ANA_MASK);
|
||||
if (!ret)
|
||||
ret = snd_soc_update_bits(codec, STIH407_AUDIO_DAC_CTRL,
|
||||
STIH407_DAC_SOFTMUTE_MASK,
|
||||
STIH407_DAC_SOFTMUTE_MASK);
|
||||
break;
|
||||
case CHIPID_STIH416:
|
||||
ret = snd_soc_update_bits(codec, STIH416_AUDIO_DAC_CTRL,
|
||||
STIH416_DAC_NOT_STANDBY_MASK, 0);
|
||||
if (!ret)
|
||||
ret = snd_soc_update_bits(codec,
|
||||
STIH416_AUDIO_DAC_CTRL,
|
||||
STIH416_DAC_ANA_NOT_PWR, 0);
|
||||
if (!ret)
|
||||
ret = snd_soc_update_bits(codec,
|
||||
STIH416_AUDIO_DAC_CTRL,
|
||||
STIH416_DAC_NOT_PNDBG_MASK,
|
||||
0);
|
||||
if (!ret)
|
||||
ret = snd_soc_update_bits(codec,
|
||||
STIH416_AUDIO_DAC_CTRL,
|
||||
STIH416_DAC_SOFTMUTE_MASK,
|
||||
STIH416_DAC_SOFTMUTE_MASK);
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (ret < 0) {
|
||||
dev_err(codec->dev, "Failed to update DAC registers");
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* DAC
|
||||
*/
|
||||
static int sti_sas_dac_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
|
||||
{
|
||||
/* Sanity check only */
|
||||
if ((fmt & SND_SOC_DAIFMT_MASTER_MASK) != SND_SOC_DAIFMT_CBS_CFS) {
|
||||
dev_err(dai->codec->dev,
|
||||
"%s: ERROR: Unsupporter master mask 0x%x\n",
|
||||
__func__, fmt & SND_SOC_DAIFMT_MASTER_MASK);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int stih416_dac_probe(struct snd_soc_dai *dai)
|
||||
{
|
||||
struct snd_soc_codec *codec = dai->codec;
|
||||
struct sti_sas_data *drvdata = dev_get_drvdata(codec->dev);
|
||||
struct sti_dac_audio *dac = &drvdata->dac;
|
||||
|
||||
/* Get reset control */
|
||||
dac->rst = devm_reset_control_get(codec->dev, "dac_rst");
|
||||
if (IS_ERR(dac->rst)) {
|
||||
dev_err(dai->codec->dev,
|
||||
"%s: ERROR: DAC reset control not defined !\n",
|
||||
__func__);
|
||||
dac->rst = NULL;
|
||||
return -EFAULT;
|
||||
}
|
||||
/* Put the DAC into reset */
|
||||
reset_control_assert(dac->rst);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct snd_soc_dapm_widget stih416_sas_dapm_widgets[] = {
|
||||
SND_SOC_DAPM_PGA("DAC bandgap", STIH416_AUDIO_DAC_CTRL,
|
||||
STIH416_DAC_NOT_PNDBG_MASK, 0, NULL, 0),
|
||||
SND_SOC_DAPM_OUT_DRV("DAC standby ana", STIH416_AUDIO_DAC_CTRL,
|
||||
STIH416_DAC_ANA_NOT_PWR, 0, NULL, 0),
|
||||
SND_SOC_DAPM_DAC("DAC standby", "dac_p", STIH416_AUDIO_DAC_CTRL,
|
||||
STIH416_DAC_NOT_STANDBY, 0),
|
||||
SND_SOC_DAPM_OUTPUT("DAC Output"),
|
||||
};
|
||||
|
||||
static const struct snd_soc_dapm_widget stih407_sas_dapm_widgets[] = {
|
||||
SND_SOC_DAPM_OUT_DRV("DAC standby ana", STIH407_AUDIO_DAC_CTRL,
|
||||
STIH407_DAC_STANDBY_ANA, 1, NULL, 0),
|
||||
SND_SOC_DAPM_DAC("DAC standby", "dac_p", STIH407_AUDIO_DAC_CTRL,
|
||||
STIH407_DAC_STANDBY, 1),
|
||||
SND_SOC_DAPM_OUTPUT("DAC Output"),
|
||||
};
|
||||
|
||||
static const struct snd_soc_dapm_route stih416_sas_route[] = {
|
||||
{"DAC Output", NULL, "DAC bandgap"},
|
||||
{"DAC Output", NULL, "DAC standby ana"},
|
||||
{"DAC standby ana", NULL, "DAC standby"},
|
||||
};
|
||||
|
||||
static const struct snd_soc_dapm_route stih407_sas_route[] = {
|
||||
{"DAC Output", NULL, "DAC standby ana"},
|
||||
{"DAC standby ana", NULL, "DAC standby"},
|
||||
};
|
||||
|
||||
static int stih416_sas_dac_mute(struct snd_soc_dai *dai, int mute, int stream)
|
||||
{
|
||||
struct snd_soc_codec *codec = dai->codec;
|
||||
|
||||
if (mute) {
|
||||
return snd_soc_update_bits(codec, STIH416_AUDIO_DAC_CTRL,
|
||||
STIH416_DAC_SOFTMUTE_MASK,
|
||||
STIH416_DAC_SOFTMUTE_MASK);
|
||||
} else {
|
||||
return snd_soc_update_bits(codec, STIH416_AUDIO_DAC_CTRL,
|
||||
STIH416_DAC_SOFTMUTE_MASK, 0);
|
||||
}
|
||||
}
|
||||
|
||||
static int stih407_sas_dac_mute(struct snd_soc_dai *dai, int mute, int stream)
|
||||
{
|
||||
struct snd_soc_codec *codec = dai->codec;
|
||||
|
||||
if (mute) {
|
||||
return snd_soc_update_bits(codec, STIH407_AUDIO_DAC_CTRL,
|
||||
STIH407_DAC_SOFTMUTE_MASK,
|
||||
STIH407_DAC_SOFTMUTE_MASK);
|
||||
} else {
|
||||
return snd_soc_update_bits(codec, STIH407_AUDIO_DAC_CTRL,
|
||||
STIH407_DAC_SOFTMUTE_MASK,
|
||||
0);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* SPDIF
|
||||
*/
|
||||
static int sti_sas_spdif_set_fmt(struct snd_soc_dai *dai,
|
||||
unsigned int fmt)
|
||||
{
|
||||
if ((fmt & SND_SOC_DAIFMT_MASTER_MASK) != SND_SOC_DAIFMT_CBS_CFS) {
|
||||
dev_err(dai->codec->dev,
|
||||
"%s: ERROR: Unsupporter master mask 0x%x\n",
|
||||
__func__, fmt & SND_SOC_DAIFMT_MASTER_MASK);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* sti_sas_spdif_trigger:
|
||||
* Trigger function is used to ensure that BiPhase Formater is disabled
|
||||
* before CPU dai is stopped.
|
||||
* This is mandatory to avoid that BPF is stalled
|
||||
*/
|
||||
static int sti_sas_spdif_trigger(struct snd_pcm_substream *substream, int cmd,
|
||||
struct snd_soc_dai *dai)
|
||||
{
|
||||
struct snd_soc_codec *codec = dai->codec;
|
||||
|
||||
switch (cmd) {
|
||||
case SNDRV_PCM_TRIGGER_START:
|
||||
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
|
||||
return snd_soc_update_bits(codec, STIH407_AUDIO_GLUE_CTRL,
|
||||
SPDIF_BIPHASE_ENABLE_MASK,
|
||||
SPDIF_BIPHASE_ENABLE_MASK);
|
||||
case SNDRV_PCM_TRIGGER_RESUME:
|
||||
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
|
||||
case SNDRV_PCM_TRIGGER_STOP:
|
||||
case SNDRV_PCM_TRIGGER_SUSPEND:
|
||||
return snd_soc_update_bits(codec, STIH407_AUDIO_GLUE_CTRL,
|
||||
SPDIF_BIPHASE_ENABLE_MASK,
|
||||
0);
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
static bool sti_sas_volatile_register(struct device *dev, unsigned int reg)
|
||||
{
|
||||
if (reg == STIH407_AUDIO_GLUE_CTRL)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* CODEC DAIS
|
||||
*/
|
||||
|
||||
/*
|
||||
* sti_sas_set_sysclk:
|
||||
* get MCLK input frequency to check that MCLK-FS ratio is coherent
|
||||
*/
|
||||
static int sti_sas_set_sysclk(struct snd_soc_dai *dai, int clk_id,
|
||||
unsigned int freq, int dir)
|
||||
{
|
||||
struct snd_soc_codec *codec = dai->codec;
|
||||
struct sti_sas_data *drvdata = dev_get_drvdata(codec->dev);
|
||||
|
||||
if (dir == SND_SOC_CLOCK_OUT)
|
||||
return 0;
|
||||
|
||||
if (clk_id != 0)
|
||||
return -EINVAL;
|
||||
|
||||
switch (dai->id) {
|
||||
case STI_SAS_DAI_SPDIF_OUT:
|
||||
drvdata->spdif.mclk = freq;
|
||||
break;
|
||||
|
||||
case STI_SAS_DAI_ANALOG_OUT:
|
||||
drvdata->dac.mclk = freq;
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int sti_sas_prepare(struct snd_pcm_substream *substream,
|
||||
struct snd_soc_dai *dai)
|
||||
{
|
||||
struct snd_soc_codec *codec = dai->codec;
|
||||
struct sti_sas_data *drvdata = dev_get_drvdata(codec->dev);
|
||||
struct snd_pcm_runtime *runtime = substream->runtime;
|
||||
|
||||
switch (dai->id) {
|
||||
case STI_SAS_DAI_SPDIF_OUT:
|
||||
if ((drvdata->spdif.mclk / runtime->rate) != 128) {
|
||||
dev_err(codec->dev, "unexpected mclk-fs ratio");
|
||||
return -EINVAL;
|
||||
}
|
||||
break;
|
||||
case STI_SAS_DAI_ANALOG_OUT:
|
||||
if ((drvdata->dac.mclk / runtime->rate) != 256) {
|
||||
dev_err(codec->dev, "unexpected mclk-fs ratio");
|
||||
return -EINVAL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct snd_soc_dai_ops stih416_dac_ops = {
|
||||
.set_fmt = sti_sas_dac_set_fmt,
|
||||
.mute_stream = stih416_sas_dac_mute,
|
||||
.prepare = sti_sas_prepare,
|
||||
.set_sysclk = sti_sas_set_sysclk,
|
||||
};
|
||||
|
||||
static const struct snd_soc_dai_ops stih407_dac_ops = {
|
||||
.set_fmt = sti_sas_dac_set_fmt,
|
||||
.mute_stream = stih407_sas_dac_mute,
|
||||
.prepare = sti_sas_prepare,
|
||||
.set_sysclk = sti_sas_set_sysclk,
|
||||
};
|
||||
|
||||
static const struct regmap_config stih407_sas_regmap = {
|
||||
.reg_bits = 32,
|
||||
.val_bits = 32,
|
||||
|
||||
.max_register = STIH407_AUDIO_DAC_CTRL,
|
||||
.reg_defaults = stih407_sas_reg_defaults,
|
||||
.num_reg_defaults = ARRAY_SIZE(stih407_sas_reg_defaults),
|
||||
.volatile_reg = sti_sas_volatile_register,
|
||||
.cache_type = REGCACHE_RBTREE,
|
||||
.reg_read = sti_sas_read_reg,
|
||||
.reg_write = sti_sas_write_reg,
|
||||
};
|
||||
|
||||
static const struct regmap_config stih416_sas_regmap = {
|
||||
.reg_bits = 32,
|
||||
.val_bits = 32,
|
||||
|
||||
.max_register = STIH416_AUDIO_DAC_CTRL,
|
||||
.reg_defaults = stih416_sas_reg_defaults,
|
||||
.num_reg_defaults = ARRAY_SIZE(stih416_sas_reg_defaults),
|
||||
.volatile_reg = sti_sas_volatile_register,
|
||||
.cache_type = REGCACHE_RBTREE,
|
||||
.reg_read = sti_sas_read_reg,
|
||||
.reg_write = sti_sas_write_reg,
|
||||
};
|
||||
|
||||
static const struct sti_sas_dev_data stih416_data = {
|
||||
.chipid = CHIPID_STIH416,
|
||||
.regmap = &stih416_sas_regmap,
|
||||
.dac_ops = &stih416_dac_ops,
|
||||
.dapm_widgets = stih416_sas_dapm_widgets,
|
||||
.num_dapm_widgets = ARRAY_SIZE(stih416_sas_dapm_widgets),
|
||||
.dapm_routes = stih416_sas_route,
|
||||
.num_dapm_routes = ARRAY_SIZE(stih416_sas_route),
|
||||
};
|
||||
|
||||
static const struct sti_sas_dev_data stih407_data = {
|
||||
.chipid = CHIPID_STIH407,
|
||||
.regmap = &stih407_sas_regmap,
|
||||
.dac_ops = &stih407_dac_ops,
|
||||
.dapm_widgets = stih407_sas_dapm_widgets,
|
||||
.num_dapm_widgets = ARRAY_SIZE(stih407_sas_dapm_widgets),
|
||||
.dapm_routes = stih407_sas_route,
|
||||
.num_dapm_routes = ARRAY_SIZE(stih407_sas_route),
|
||||
};
|
||||
|
||||
static struct snd_soc_dai_driver sti_sas_dai[] = {
|
||||
{
|
||||
.name = "sas-dai-spdif-out",
|
||||
.id = STI_SAS_DAI_SPDIF_OUT,
|
||||
.playback = {
|
||||
.stream_name = "spdif_p",
|
||||
.channels_min = 2,
|
||||
.channels_max = 2,
|
||||
.rates = SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |
|
||||
SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_64000 |
|
||||
SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 |
|
||||
SNDRV_PCM_RATE_192000,
|
||||
.formats = SNDRV_PCM_FMTBIT_S16_LE |
|
||||
SNDRV_PCM_FMTBIT_S32_LE,
|
||||
},
|
||||
.ops = (struct snd_soc_dai_ops[]) {
|
||||
{
|
||||
.set_fmt = sti_sas_spdif_set_fmt,
|
||||
.trigger = sti_sas_spdif_trigger,
|
||||
.set_sysclk = sti_sas_set_sysclk,
|
||||
.prepare = sti_sas_prepare,
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
.name = "sas-dai-dac",
|
||||
.id = STI_SAS_DAI_ANALOG_OUT,
|
||||
.playback = {
|
||||
.stream_name = "dac_p",
|
||||
.channels_min = 2,
|
||||
.channels_max = 2,
|
||||
.rates = SNDRV_PCM_RATE_8000_48000,
|
||||
.formats = SNDRV_PCM_FMTBIT_S16_LE |
|
||||
SNDRV_PCM_FMTBIT_S32_LE,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
#ifdef CONFIG_PM_SLEEP
|
||||
static int sti_sas_resume(struct snd_soc_codec *codec)
|
||||
{
|
||||
struct sti_sas_data *drvdata = dev_get_drvdata(codec->dev);
|
||||
|
||||
return sti_sas_init_sas_registers(codec, drvdata);
|
||||
}
|
||||
#else
|
||||
#define sti_sas_resume NULL
|
||||
#endif
|
||||
|
||||
static int sti_sas_codec_probe(struct snd_soc_codec *codec)
|
||||
{
|
||||
struct sti_sas_data *drvdata = dev_get_drvdata(codec->dev);
|
||||
int ret;
|
||||
|
||||
ret = sti_sas_init_sas_registers(codec, drvdata);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static struct snd_soc_codec_driver sti_sas_driver = {
|
||||
.probe = sti_sas_codec_probe,
|
||||
.resume = sti_sas_resume,
|
||||
};
|
||||
|
||||
static const struct of_device_id sti_sas_dev_match[] = {
|
||||
{
|
||||
.compatible = "st,stih416-sas-codec",
|
||||
.data = &stih416_data,
|
||||
},
|
||||
{
|
||||
.compatible = "st,stih407-sas-codec",
|
||||
.data = &stih407_data,
|
||||
},
|
||||
{},
|
||||
};
|
||||
|
||||
static int sti_sas_driver_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct device_node *pnode = pdev->dev.of_node;
|
||||
struct sti_sas_data *drvdata;
|
||||
const struct of_device_id *of_id;
|
||||
|
||||
/* Allocate device structure */
|
||||
drvdata = devm_kzalloc(&pdev->dev, sizeof(struct sti_sas_data),
|
||||
GFP_KERNEL);
|
||||
if (!drvdata)
|
||||
return -ENOMEM;
|
||||
|
||||
/* Populate data structure depending on compatibility */
|
||||
of_id = of_match_node(sti_sas_dev_match, pnode);
|
||||
if (!of_id->data) {
|
||||
dev_err(&pdev->dev, "data associated to device is missing");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
drvdata->dev_data = (struct sti_sas_dev_data *)of_id->data;
|
||||
|
||||
/* Initialise device structure */
|
||||
drvdata->dev = &pdev->dev;
|
||||
|
||||
/* Request the DAC & SPDIF registers memory region */
|
||||
drvdata->dac.virt_regmap = devm_regmap_init(&pdev->dev, NULL, drvdata,
|
||||
drvdata->dev_data->regmap);
|
||||
if (IS_ERR(drvdata->dac.virt_regmap)) {
|
||||
dev_err(&pdev->dev, "audio registers not enabled\n");
|
||||
return PTR_ERR(drvdata->dac.virt_regmap);
|
||||
}
|
||||
|
||||
/* Request the syscon region */
|
||||
drvdata->dac.regmap =
|
||||
syscon_regmap_lookup_by_phandle(pnode, "st,syscfg");
|
||||
if (IS_ERR(drvdata->dac.regmap)) {
|
||||
dev_err(&pdev->dev, "syscon registers not available\n");
|
||||
return PTR_ERR(drvdata->dac.regmap);
|
||||
}
|
||||
drvdata->spdif.regmap = drvdata->dac.regmap;
|
||||
|
||||
/* Set DAC dai probe */
|
||||
if (drvdata->dev_data->chipid == CHIPID_STIH416)
|
||||
sti_sas_dai[STI_SAS_DAI_ANALOG_OUT].probe = stih416_dac_probe;
|
||||
|
||||
sti_sas_dai[STI_SAS_DAI_ANALOG_OUT].ops = drvdata->dev_data->dac_ops;
|
||||
|
||||
/* Set dapms*/
|
||||
sti_sas_driver.dapm_widgets = drvdata->dev_data->dapm_widgets;
|
||||
sti_sas_driver.num_dapm_widgets = drvdata->dev_data->num_dapm_widgets;
|
||||
|
||||
sti_sas_driver.dapm_routes = drvdata->dev_data->dapm_routes;
|
||||
sti_sas_driver.num_dapm_routes = drvdata->dev_data->num_dapm_routes;
|
||||
|
||||
/* Store context */
|
||||
dev_set_drvdata(&pdev->dev, drvdata);
|
||||
|
||||
return snd_soc_register_codec(&pdev->dev, &sti_sas_driver,
|
||||
sti_sas_dai,
|
||||
ARRAY_SIZE(sti_sas_dai));
|
||||
}
|
||||
|
||||
static int sti_sas_driver_remove(struct platform_device *pdev)
|
||||
{
|
||||
snd_soc_unregister_codec(&pdev->dev);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct platform_driver sti_sas_platform_driver = {
|
||||
.driver = {
|
||||
.name = "sti-sas-codec",
|
||||
.of_match_table = sti_sas_dev_match,
|
||||
},
|
||||
.probe = sti_sas_driver_probe,
|
||||
.remove = sti_sas_driver_remove,
|
||||
};
|
||||
|
||||
module_platform_driver(sti_sas_platform_driver);
|
||||
|
||||
MODULE_DESCRIPTION("audio codec for STMicroelectronics sti platforms");
|
||||
MODULE_AUTHOR("Arnaud.pouliquen@st.com");
|
||||
MODULE_LICENSE("GPL v2");
|
|
@ -0,0 +1,11 @@
|
|||
#
|
||||
# STM SoC audio configuration
|
||||
#
|
||||
menuconfig SND_SOC_STI
|
||||
tristate "SoC Audio support for STI System-On-Chip"
|
||||
depends on SND_SOC
|
||||
depends on ARCH_STI || COMPILE_TEST
|
||||
select SND_SOC_GENERIC_DMAENGINE_PCM
|
||||
help
|
||||
Say Y if you want to enable ASoC-support for
|
||||
any of the STI platforms (e.g. STIH416).
|
|
@ -0,0 +1,4 @@
|
|||
# STI platform support
|
||||
snd-soc-sti-objs := sti_uniperif.o uniperif_player.o uniperif_reader.o
|
||||
|
||||
obj-$(CONFIG_SND_SOC_STI) += snd-soc-sti.o
|
|
@ -0,0 +1,254 @@
|
|||
/*
|
||||
* Copyright (C) STMicroelectronics SA 2015
|
||||
* Authors: Arnaud Pouliquen <arnaud.pouliquen@st.com>
|
||||
* for STMicroelectronics.
|
||||
* License terms: GNU General Public License (GPL), version 2
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/pinctrl/consumer.h>
|
||||
|
||||
#include "uniperif.h"
|
||||
|
||||
/*
|
||||
* sti_uniperiph_dai_create_ctrl
|
||||
* This function is used to create Ctrl associated to DAI but also pcm device.
|
||||
* Request is done by front end to associate ctrl with pcm device id
|
||||
*/
|
||||
static int sti_uniperiph_dai_create_ctrl(struct snd_soc_dai *dai)
|
||||
{
|
||||
struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai);
|
||||
struct uniperif *uni = priv->dai_data.uni;
|
||||
struct snd_kcontrol_new *ctrl;
|
||||
int i;
|
||||
|
||||
if (!uni->num_ctrls)
|
||||
return 0;
|
||||
|
||||
for (i = 0; i < uni->num_ctrls; i++) {
|
||||
/*
|
||||
* Several Control can have same name. Controls are indexed on
|
||||
* Uniperipheral instance ID
|
||||
*/
|
||||
ctrl = &uni->snd_ctrls[i];
|
||||
ctrl->index = uni->info->id;
|
||||
ctrl->device = uni->info->id;
|
||||
}
|
||||
|
||||
return snd_soc_add_dai_controls(dai, uni->snd_ctrls, uni->num_ctrls);
|
||||
}
|
||||
|
||||
/*
|
||||
* DAI
|
||||
*/
|
||||
int sti_uniperiph_dai_hw_params(struct snd_pcm_substream *substream,
|
||||
struct snd_pcm_hw_params *params,
|
||||
struct snd_soc_dai *dai)
|
||||
{
|
||||
struct snd_dmaengine_dai_dma_data *dma_data;
|
||||
int transfer_size;
|
||||
|
||||
transfer_size = params_channels(params) * UNIPERIF_FIFO_FRAMES;
|
||||
|
||||
dma_data = snd_soc_dai_get_dma_data(dai, substream);
|
||||
dma_data->maxburst = transfer_size;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sti_uniperiph_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
|
||||
{
|
||||
struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai);
|
||||
|
||||
priv->dai_data.uni->daifmt = fmt;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int sti_uniperiph_dai_suspend(struct snd_soc_dai *dai)
|
||||
{
|
||||
struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai);
|
||||
struct uniperif *uni = priv->dai_data.uni;
|
||||
int ret;
|
||||
|
||||
/* The uniperipheral should be in stopped state */
|
||||
if (uni->state != UNIPERIF_STATE_STOPPED) {
|
||||
dev_err(uni->dev, "%s: invalid uni state( %d)",
|
||||
__func__, (int)uni->state);
|
||||
return -EBUSY;
|
||||
}
|
||||
|
||||
/* Pinctrl: switch pinstate to sleep */
|
||||
ret = pinctrl_pm_select_sleep_state(uni->dev);
|
||||
if (ret)
|
||||
dev_err(uni->dev, "%s: failed to select pinctrl state",
|
||||
__func__);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int sti_uniperiph_dai_resume(struct snd_soc_dai *dai)
|
||||
{
|
||||
struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai);
|
||||
struct uniperif *uni = priv->dai_data.uni;
|
||||
int ret;
|
||||
|
||||
if (of_device_is_compatible(dai->dev->of_node, "st,sti-uni-player")) {
|
||||
ret = uni_player_resume(uni);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* pinctrl: switch pinstate to default */
|
||||
ret = pinctrl_pm_select_default_state(uni->dev);
|
||||
if (ret)
|
||||
dev_err(uni->dev, "%s: failed to select pinctrl state",
|
||||
__func__);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int sti_uniperiph_dai_probe(struct snd_soc_dai *dai)
|
||||
{
|
||||
struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai);
|
||||
struct sti_uniperiph_dai *dai_data = &priv->dai_data;
|
||||
|
||||
/* DMA settings*/
|
||||
if (of_device_is_compatible(dai->dev->of_node, "st,sti-uni-player"))
|
||||
snd_soc_dai_init_dma_data(dai, &dai_data->dma_data, NULL);
|
||||
else
|
||||
snd_soc_dai_init_dma_data(dai, NULL, &dai_data->dma_data);
|
||||
|
||||
dai_data->dma_data.addr = dai_data->uni->fifo_phys_address;
|
||||
dai_data->dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
|
||||
|
||||
return sti_uniperiph_dai_create_ctrl(dai);
|
||||
}
|
||||
|
||||
static const struct snd_soc_dai_driver sti_uniperiph_dai_template = {
|
||||
.probe = sti_uniperiph_dai_probe,
|
||||
.suspend = sti_uniperiph_dai_suspend,
|
||||
.resume = sti_uniperiph_dai_resume
|
||||
};
|
||||
|
||||
static const struct snd_soc_component_driver sti_uniperiph_dai_component = {
|
||||
.name = "sti_cpu_dai",
|
||||
};
|
||||
|
||||
static int sti_uniperiph_cpu_dai_of(struct device_node *node,
|
||||
struct sti_uniperiph_data *priv)
|
||||
{
|
||||
const char *str;
|
||||
int ret;
|
||||
struct device *dev = &priv->pdev->dev;
|
||||
struct sti_uniperiph_dai *dai_data = &priv->dai_data;
|
||||
struct snd_soc_dai_driver *dai = priv->dai;
|
||||
struct snd_soc_pcm_stream *stream;
|
||||
struct uniperif *uni;
|
||||
|
||||
uni = devm_kzalloc(dev, sizeof(*uni), GFP_KERNEL);
|
||||
if (!uni)
|
||||
return -ENOMEM;
|
||||
|
||||
*dai = sti_uniperiph_dai_template;
|
||||
ret = of_property_read_string(node, "dai-name", &str);
|
||||
if (ret < 0) {
|
||||
dev_err(dev, "%s: dai name missing.\n", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
dai->name = str;
|
||||
|
||||
/* Get resources */
|
||||
uni->mem_region = platform_get_resource(priv->pdev, IORESOURCE_MEM, 0);
|
||||
|
||||
if (!uni->mem_region) {
|
||||
dev_err(dev, "Failed to get memory resource");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
uni->base = devm_ioremap_resource(dev, uni->mem_region);
|
||||
|
||||
if (IS_ERR(uni->base))
|
||||
return PTR_ERR(uni->base);
|
||||
|
||||
uni->fifo_phys_address = uni->mem_region->start +
|
||||
UNIPERIF_FIFO_DATA_OFFSET(uni);
|
||||
|
||||
uni->irq = platform_get_irq(priv->pdev, 0);
|
||||
if (uni->irq < 0) {
|
||||
dev_err(dev, "Failed to get IRQ resource");
|
||||
return -ENXIO;
|
||||
}
|
||||
|
||||
dai_data->uni = uni;
|
||||
|
||||
if (of_device_is_compatible(node, "st,sti-uni-player")) {
|
||||
uni_player_init(priv->pdev, uni);
|
||||
stream = &dai->playback;
|
||||
} else {
|
||||
uni_reader_init(priv->pdev, uni);
|
||||
stream = &dai->capture;
|
||||
}
|
||||
dai->ops = uni->dai_ops;
|
||||
|
||||
stream->stream_name = dai->name;
|
||||
stream->channels_min = uni->hw->channels_min;
|
||||
stream->channels_max = uni->hw->channels_max;
|
||||
stream->rates = uni->hw->rates;
|
||||
stream->formats = uni->hw->formats;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct snd_dmaengine_pcm_config dmaengine_pcm_config = {
|
||||
.prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config,
|
||||
};
|
||||
|
||||
static int sti_uniperiph_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct sti_uniperiph_data *priv;
|
||||
struct device_node *node = pdev->dev.of_node;
|
||||
int ret;
|
||||
|
||||
/* Allocate the private data and the CPU_DAI array */
|
||||
priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
|
||||
if (!priv)
|
||||
return -ENOMEM;
|
||||
priv->dai = devm_kzalloc(&pdev->dev, sizeof(*priv->dai), GFP_KERNEL);
|
||||
if (!priv->dai)
|
||||
return -ENOMEM;
|
||||
|
||||
priv->pdev = pdev;
|
||||
|
||||
ret = sti_uniperiph_cpu_dai_of(node, priv);
|
||||
|
||||
dev_set_drvdata(&pdev->dev, priv);
|
||||
|
||||
ret = devm_snd_soc_register_component(&pdev->dev,
|
||||
&sti_uniperiph_dai_component,
|
||||
priv->dai, 1);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
return devm_snd_dmaengine_pcm_register(&pdev->dev,
|
||||
&dmaengine_pcm_config, 0);
|
||||
}
|
||||
|
||||
static const struct of_device_id snd_soc_sti_match[] = {
|
||||
{ .compatible = "st,sti-uni-player", },
|
||||
{ .compatible = "st,sti-uni-reader", },
|
||||
{},
|
||||
};
|
||||
|
||||
static struct platform_driver sti_uniperiph_driver = {
|
||||
.driver = {
|
||||
.name = "sti-uniperiph-dai",
|
||||
.of_match_table = snd_soc_sti_match,
|
||||
},
|
||||
.probe = sti_uniperiph_probe,
|
||||
};
|
||||
module_platform_driver(sti_uniperiph_driver);
|
||||
|
||||
MODULE_DESCRIPTION("uniperipheral DAI driver");
|
||||
MODULE_AUTHOR("Arnaud Pouliquen <arnaud.pouliquen@st.com>");
|
||||
MODULE_LICENSE("GPL v2");
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,362 @@
|
|||
/*
|
||||
* Copyright (C) STMicroelectronics SA 2015
|
||||
* Authors: Arnaud Pouliquen <arnaud.pouliquen@st.com>
|
||||
* for STMicroelectronics.
|
||||
* License terms: GNU General Public License (GPL), version 2
|
||||
*/
|
||||
|
||||
#include <linux/clk.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/io.h>
|
||||
|
||||
#include <sound/soc.h>
|
||||
|
||||
#include "uniperif.h"
|
||||
|
||||
/*
|
||||
* Note: snd_pcm_hardware is linked to DMA controller but is declared here to
|
||||
* integrate unireader capability in term of rate and supported channels
|
||||
*/
|
||||
static const struct snd_pcm_hardware uni_reader_pcm_hw = {
|
||||
.info = SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
|
||||
SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_MMAP |
|
||||
SNDRV_PCM_INFO_MMAP_VALID,
|
||||
.formats = SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S16_LE,
|
||||
|
||||
.rates = SNDRV_PCM_RATE_CONTINUOUS,
|
||||
.rate_min = 8000,
|
||||
.rate_max = 96000,
|
||||
|
||||
.channels_min = 2,
|
||||
.channels_max = 8,
|
||||
|
||||
.periods_min = 2,
|
||||
.periods_max = 48,
|
||||
|
||||
.period_bytes_min = 128,
|
||||
.period_bytes_max = 64 * PAGE_SIZE,
|
||||
.buffer_bytes_max = 256 * PAGE_SIZE
|
||||
};
|
||||
|
||||
/*
|
||||
* uni_reader_irq_handler
|
||||
* In case of error audio stream is stopped; stop action is protected via PCM
|
||||
* stream lock to avoid race condition with trigger callback.
|
||||
*/
|
||||
static irqreturn_t uni_reader_irq_handler(int irq, void *dev_id)
|
||||
{
|
||||
irqreturn_t ret = IRQ_NONE;
|
||||
struct uniperif *reader = dev_id;
|
||||
unsigned int status;
|
||||
|
||||
if (reader->state == UNIPERIF_STATE_STOPPED) {
|
||||
/* Unexpected IRQ: do nothing */
|
||||
dev_warn(reader->dev, "unexpected IRQ ");
|
||||
return IRQ_HANDLED;
|
||||
}
|
||||
|
||||
/* Get interrupt status & clear them immediately */
|
||||
status = GET_UNIPERIF_ITS(reader);
|
||||
SET_UNIPERIF_ITS_BCLR(reader, status);
|
||||
|
||||
/* Check for fifo overflow error */
|
||||
if (unlikely(status & UNIPERIF_ITS_FIFO_ERROR_MASK(reader))) {
|
||||
dev_err(reader->dev, "FIFO error detected");
|
||||
|
||||
snd_pcm_stream_lock(reader->substream);
|
||||
snd_pcm_stop(reader->substream, SNDRV_PCM_STATE_XRUN);
|
||||
snd_pcm_stream_unlock(reader->substream);
|
||||
|
||||
return IRQ_HANDLED;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int uni_reader_prepare(struct snd_pcm_substream *substream,
|
||||
struct snd_soc_dai *dai)
|
||||
{
|
||||
struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai);
|
||||
struct uniperif *reader = priv->dai_data.uni;
|
||||
struct snd_pcm_runtime *runtime = substream->runtime;
|
||||
int transfer_size, trigger_limit;
|
||||
int slot_width;
|
||||
int count = 10;
|
||||
|
||||
/* The reader should be stopped */
|
||||
if (reader->state != UNIPERIF_STATE_STOPPED) {
|
||||
dev_err(reader->dev, "%s: invalid reader state %d", __func__,
|
||||
reader->state);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Calculate transfer size (in fifo cells and bytes) for frame count */
|
||||
transfer_size = runtime->channels * UNIPERIF_FIFO_FRAMES;
|
||||
|
||||
/* Calculate number of empty cells available before asserting DREQ */
|
||||
if (reader->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0)
|
||||
trigger_limit = UNIPERIF_FIFO_SIZE - transfer_size;
|
||||
else
|
||||
/*
|
||||
* Since SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0
|
||||
* FDMA_TRIGGER_LIMIT also controls when the state switches
|
||||
* from OFF or STANDBY to AUDIO DATA.
|
||||
*/
|
||||
trigger_limit = transfer_size;
|
||||
|
||||
/* Trigger limit must be an even number */
|
||||
if ((!trigger_limit % 2) ||
|
||||
(trigger_limit != 1 && transfer_size % 2) ||
|
||||
(trigger_limit > UNIPERIF_CONFIG_DMA_TRIG_LIMIT_MASK(reader))) {
|
||||
dev_err(reader->dev, "invalid trigger limit %d", trigger_limit);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
SET_UNIPERIF_CONFIG_DMA_TRIG_LIMIT(reader, trigger_limit);
|
||||
|
||||
switch (reader->daifmt & SND_SOC_DAIFMT_INV_MASK) {
|
||||
case SND_SOC_DAIFMT_IB_IF:
|
||||
case SND_SOC_DAIFMT_NB_IF:
|
||||
SET_UNIPERIF_I2S_FMT_LR_POL_HIG(reader);
|
||||
break;
|
||||
default:
|
||||
SET_UNIPERIF_I2S_FMT_LR_POL_LOW(reader);
|
||||
}
|
||||
|
||||
/* Force slot width to 32 in I2S mode */
|
||||
if ((reader->daifmt & SND_SOC_DAIFMT_FORMAT_MASK)
|
||||
== SND_SOC_DAIFMT_I2S) {
|
||||
slot_width = 32;
|
||||
} else {
|
||||
switch (runtime->format) {
|
||||
case SNDRV_PCM_FORMAT_S16_LE:
|
||||
slot_width = 16;
|
||||
break;
|
||||
default:
|
||||
slot_width = 32;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Number of bits per subframe (i.e one channel sample) on input. */
|
||||
switch (slot_width) {
|
||||
case 32:
|
||||
SET_UNIPERIF_I2S_FMT_NBIT_32(reader);
|
||||
SET_UNIPERIF_I2S_FMT_DATA_SIZE_32(reader);
|
||||
break;
|
||||
case 16:
|
||||
SET_UNIPERIF_I2S_FMT_NBIT_16(reader);
|
||||
SET_UNIPERIF_I2S_FMT_DATA_SIZE_16(reader);
|
||||
break;
|
||||
default:
|
||||
dev_err(reader->dev, "subframe format not supported");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Configure data memory format */
|
||||
switch (runtime->format) {
|
||||
case SNDRV_PCM_FORMAT_S16_LE:
|
||||
/* One data word contains two samples */
|
||||
SET_UNIPERIF_CONFIG_MEM_FMT_16_16(reader);
|
||||
break;
|
||||
|
||||
case SNDRV_PCM_FORMAT_S32_LE:
|
||||
/*
|
||||
* Actually "16 bits/0 bits" means "32/28/24/20/18/16 bits
|
||||
* on the MSB then zeros (if less than 32 bytes)"...
|
||||
*/
|
||||
SET_UNIPERIF_CONFIG_MEM_FMT_16_0(reader);
|
||||
break;
|
||||
|
||||
default:
|
||||
dev_err(reader->dev, "format not supported");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
switch (reader->daifmt & SND_SOC_DAIFMT_FORMAT_MASK) {
|
||||
case SND_SOC_DAIFMT_I2S:
|
||||
SET_UNIPERIF_I2S_FMT_ALIGN_LEFT(reader);
|
||||
SET_UNIPERIF_I2S_FMT_PADDING_I2S_MODE(reader);
|
||||
break;
|
||||
case SND_SOC_DAIFMT_LEFT_J:
|
||||
SET_UNIPERIF_I2S_FMT_ALIGN_LEFT(reader);
|
||||
SET_UNIPERIF_I2S_FMT_PADDING_SONY_MODE(reader);
|
||||
break;
|
||||
case SND_SOC_DAIFMT_RIGHT_J:
|
||||
SET_UNIPERIF_I2S_FMT_ALIGN_RIGHT(reader);
|
||||
SET_UNIPERIF_I2S_FMT_PADDING_SONY_MODE(reader);
|
||||
break;
|
||||
default:
|
||||
dev_err(reader->dev, "format not supported");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
SET_UNIPERIF_I2S_FMT_ORDER_MSB(reader);
|
||||
|
||||
/* Data clocking (changing) on the rising edge */
|
||||
SET_UNIPERIF_I2S_FMT_SCLK_EDGE_RISING(reader);
|
||||
|
||||
/* Number of channels must be even */
|
||||
|
||||
if ((runtime->channels % 2) || (runtime->channels < 2) ||
|
||||
(runtime->channels > 10)) {
|
||||
dev_err(reader->dev, "%s: invalid nb of channels", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
SET_UNIPERIF_I2S_FMT_NUM_CH(reader, runtime->channels / 2);
|
||||
|
||||
/* Clear any pending interrupts */
|
||||
SET_UNIPERIF_ITS_BCLR(reader, GET_UNIPERIF_ITS(reader));
|
||||
|
||||
SET_UNIPERIF_I2S_FMT_NO_OF_SAMPLES_TO_READ(reader, 0);
|
||||
|
||||
/* Set the interrupt mask */
|
||||
SET_UNIPERIF_ITM_BSET_DMA_ERROR(reader);
|
||||
SET_UNIPERIF_ITM_BSET_FIFO_ERROR(reader);
|
||||
SET_UNIPERIF_ITM_BSET_MEM_BLK_READ(reader);
|
||||
|
||||
/* Enable underflow recovery interrupts */
|
||||
if (reader->info->underflow_enabled) {
|
||||
SET_UNIPERIF_ITM_BSET_UNDERFLOW_REC_DONE(reader);
|
||||
SET_UNIPERIF_ITM_BSET_UNDERFLOW_REC_FAILED(reader);
|
||||
}
|
||||
|
||||
/* Reset uniperipheral reader */
|
||||
SET_UNIPERIF_SOFT_RST_SOFT_RST(reader);
|
||||
|
||||
while (GET_UNIPERIF_SOFT_RST_SOFT_RST(reader)) {
|
||||
udelay(5);
|
||||
count--;
|
||||
}
|
||||
if (!count) {
|
||||
dev_err(reader->dev, "Failed to reset uniperif");
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int uni_reader_start(struct uniperif *reader)
|
||||
{
|
||||
/* The reader should be stopped */
|
||||
if (reader->state != UNIPERIF_STATE_STOPPED) {
|
||||
dev_err(reader->dev, "%s: invalid reader state", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Enable reader interrupts (and clear possible stalled ones) */
|
||||
SET_UNIPERIF_ITS_BCLR_FIFO_ERROR(reader);
|
||||
SET_UNIPERIF_ITM_BSET_FIFO_ERROR(reader);
|
||||
|
||||
/* Launch the reader */
|
||||
SET_UNIPERIF_CTRL_OPERATION_PCM_DATA(reader);
|
||||
|
||||
/* Update state to started */
|
||||
reader->state = UNIPERIF_STATE_STARTED;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int uni_reader_stop(struct uniperif *reader)
|
||||
{
|
||||
/* The reader should not be in stopped state */
|
||||
if (reader->state == UNIPERIF_STATE_STOPPED) {
|
||||
dev_err(reader->dev, "%s: invalid reader state", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Turn the reader off */
|
||||
SET_UNIPERIF_CTRL_OPERATION_OFF(reader);
|
||||
|
||||
/* Disable interrupts */
|
||||
SET_UNIPERIF_ITM_BCLR(reader, GET_UNIPERIF_ITM(reader));
|
||||
|
||||
/* Update state to stopped and return */
|
||||
reader->state = UNIPERIF_STATE_STOPPED;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int uni_reader_trigger(struct snd_pcm_substream *substream,
|
||||
int cmd, struct snd_soc_dai *dai)
|
||||
{
|
||||
struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai);
|
||||
struct uniperif *reader = priv->dai_data.uni;
|
||||
|
||||
switch (cmd) {
|
||||
case SNDRV_PCM_TRIGGER_START:
|
||||
return uni_reader_start(reader);
|
||||
case SNDRV_PCM_TRIGGER_STOP:
|
||||
return uni_reader_stop(reader);
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
static void uni_reader_shutdown(struct snd_pcm_substream *substream,
|
||||
struct snd_soc_dai *dai)
|
||||
{
|
||||
struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai);
|
||||
struct uniperif *reader = priv->dai_data.uni;
|
||||
|
||||
if (reader->state != UNIPERIF_STATE_STOPPED) {
|
||||
/* Stop the reader */
|
||||
uni_reader_stop(reader);
|
||||
}
|
||||
}
|
||||
|
||||
static int uni_reader_parse_dt(struct platform_device *pdev,
|
||||
struct uniperif *reader)
|
||||
{
|
||||
struct uniperif_info *info;
|
||||
struct device_node *node = pdev->dev.of_node;
|
||||
|
||||
/* Allocate memory for the info structure */
|
||||
info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
|
||||
if (!info)
|
||||
return -ENOMEM;
|
||||
|
||||
of_property_read_u32(node, "version", &reader->ver);
|
||||
|
||||
/* Save the info structure */
|
||||
reader->info = info;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct snd_soc_dai_ops uni_reader_dai_ops = {
|
||||
.shutdown = uni_reader_shutdown,
|
||||
.prepare = uni_reader_prepare,
|
||||
.trigger = uni_reader_trigger,
|
||||
.hw_params = sti_uniperiph_dai_hw_params,
|
||||
.set_fmt = sti_uniperiph_dai_set_fmt,
|
||||
};
|
||||
|
||||
int uni_reader_init(struct platform_device *pdev,
|
||||
struct uniperif *reader)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
reader->dev = &pdev->dev;
|
||||
reader->state = UNIPERIF_STATE_STOPPED;
|
||||
reader->hw = &uni_reader_pcm_hw;
|
||||
reader->dai_ops = &uni_reader_dai_ops;
|
||||
|
||||
dev_err(reader->dev, "%s: enter\n", __func__);
|
||||
ret = uni_reader_parse_dt(pdev, reader);
|
||||
if (ret < 0) {
|
||||
dev_err(reader->dev, "Failed to parse DeviceTree");
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = devm_request_irq(&pdev->dev, reader->irq,
|
||||
uni_reader_irq_handler, IRQF_SHARED,
|
||||
dev_name(&pdev->dev), reader);
|
||||
if (ret < 0) {
|
||||
dev_err(&pdev->dev, "Failed to request IRQ");
|
||||
return -EBUSY;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(uni_reader_init);
|
Загрузка…
Ссылка в новой задаче