Commit b008387a authored by Mark Brown's avatar Mark Brown

Merge remote-tracking branch 'asoc/topic/rcar' into asoc-next

parents 5388d480 2460719c
/*
* Renesas R-Car SRU/SCU/SSIU/SSI support
*
* Copyright (C) 2013 Renesas Solutions Corp.
* Kuninori Morimoto <kuninori.morimoto.gx@renesas.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 RCAR_SND_H
#define RCAR_SND_H
#include <linux/sh_clk.h>
#define RSND_GEN1_SRU 0
#define RSND_GEN1_ADG 1
#define RSND_GEN1_SSI 2
#define RSND_GEN2_SRU 0
#define RSND_GEN2_ADG 1
#define RSND_GEN2_SSIU 2
#define RSND_GEN2_SSI 3
#define RSND_BASE_MAX 4
/*
* flags
*
* 0xAB000000
*
* A : clock sharing settings
* B : SSI direction
*/
#define RSND_SSI_CLK_PIN_SHARE (1 << 31)
#define RSND_SSI_CLK_FROM_ADG (1 << 30) /* clock parent is master */
#define RSND_SSI_SYNC (1 << 29) /* SSI34_sync etc */
#define RSND_SSI_DEPENDENT (1 << 28) /* SSI needs SRU/SCU */
#define RSND_SSI_PLAY (1 << 24)
#define RSND_SSI_SET(_dai_id, _dma_id, _pio_irq, _flags) \
{ .dai_id = _dai_id, .dma_id = _dma_id, .pio_irq = _pio_irq, .flags = _flags }
#define RSND_SSI_UNUSED \
{ .dai_id = -1, .dma_id = -1, .pio_irq = -1, .flags = 0 }
struct rsnd_ssi_platform_info {
int dai_id;
int dma_id;
int pio_irq;
u32 flags;
};
/*
* flags
*/
#define RSND_SCU_USB_HPBIF (1 << 31) /* it needs RSND_SSI_DEPENDENT */
struct rsnd_scu_platform_info {
u32 flags;
};
/*
* flags
*
* 0x0000000A
*
* A : generation
*/
#define RSND_GEN1 (1 << 0) /* fixme */
#define RSND_GEN2 (2 << 0) /* fixme */
struct rcar_snd_info {
u32 flags;
struct rsnd_ssi_platform_info *ssi_info;
int ssi_info_nr;
struct rsnd_scu_platform_info *scu_info;
int scu_info_nr;
int (*start)(int id);
int (*stop)(int id);
};
#endif
......@@ -34,6 +34,13 @@ config SND_SOC_SH4_SIU
select SH_DMAE
select FW_LOADER
config SND_SOC_RCAR
tristate "R-Car series SRU/SCU/SSIU/SSI support"
select SND_SIMPLE_CARD
select RCAR_CLK_ADG
help
This option enables R-Car SUR/SCU/SSIU/SSI sound support
##
## Boards
##
......
......@@ -12,6 +12,9 @@ obj-$(CONFIG_SND_SOC_SH4_SSI) += snd-soc-ssi.o
obj-$(CONFIG_SND_SOC_SH4_FSI) += snd-soc-fsi.o
obj-$(CONFIG_SND_SOC_SH4_SIU) += snd-soc-siu.o
## audio units for R-Car
obj-$(CONFIG_SND_SOC_RCAR) += rcar/
## boards
snd-soc-sh7760-ac97-objs := sh7760-ac97.o
snd-soc-migor-objs := migor.o
......
snd-soc-rcar-objs := core.o gen.o scu.o adg.o ssi.o
obj-$(CONFIG_SND_SOC_RCAR) += snd-soc-rcar.o
\ No newline at end of file
/*
* Helper routines for R-Car sound ADG.
*
* Copyright (C) 2013 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file "COPYING" in the main directory of this archive
* for more details.
*/
#include <linux/sh_clk.h>
#include <mach/clock.h>
#include "rsnd.h"
#define CLKA 0
#define CLKB 1
#define CLKC 2
#define CLKI 3
#define CLKMAX 4
struct rsnd_adg {
struct clk *clk[CLKMAX];
int rate_of_441khz_div_6;
int rate_of_48khz_div_6;
};
#define for_each_rsnd_clk(pos, adg, i) \
for (i = 0, (pos) = adg->clk[i]; \
i < CLKMAX; \
i++, (pos) = adg->clk[i])
#define rsnd_priv_to_adg(priv) ((struct rsnd_adg *)(priv)->adg)
static enum rsnd_reg rsnd_adg_ssi_reg_get(int id)
{
enum rsnd_reg reg;
/*
* SSI 8 is not connected to ADG.
* it works with SSI 7
*/
if (id == 8)
return RSND_REG_MAX;
if (0 <= id && id <= 3)
reg = RSND_REG_AUDIO_CLK_SEL0;
else if (4 <= id && id <= 7)
reg = RSND_REG_AUDIO_CLK_SEL1;
else
reg = RSND_REG_AUDIO_CLK_SEL2;
return reg;
}
int rsnd_adg_ssi_clk_stop(struct rsnd_mod *mod)
{
struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
enum rsnd_reg reg;
int id;
/*
* "mod" = "ssi" here.
* we can get "ssi id" from mod
*/
id = rsnd_mod_id(mod);
reg = rsnd_adg_ssi_reg_get(id);
rsnd_write(priv, mod, reg, 0);
return 0;
}
int rsnd_adg_ssi_clk_try_start(struct rsnd_mod *mod, unsigned int rate)
{
struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
struct rsnd_adg *adg = rsnd_priv_to_adg(priv);
struct device *dev = rsnd_priv_to_dev(priv);
struct clk *clk;
enum rsnd_reg reg;
int id, shift, i;
u32 data;
int sel_table[] = {
[CLKA] = 0x1,
[CLKB] = 0x2,
[CLKC] = 0x3,
[CLKI] = 0x0,
};
dev_dbg(dev, "request clock = %d\n", rate);
/*
* find suitable clock from
* AUDIO_CLKA/AUDIO_CLKB/AUDIO_CLKC/AUDIO_CLKI.
*/
data = 0;
for_each_rsnd_clk(clk, adg, i) {
if (rate == clk_get_rate(clk)) {
data = sel_table[i];
goto found_clock;
}
}
/*
* find 1/6 clock from BRGA/BRGB
*/
if (rate == adg->rate_of_441khz_div_6) {
data = 0x10;
goto found_clock;
}
if (rate == adg->rate_of_48khz_div_6) {
data = 0x20;
goto found_clock;
}
return -EIO;
found_clock:
/*
* This "mod" = "ssi" here.
* we can get "ssi id" from mod
*/
id = rsnd_mod_id(mod);
reg = rsnd_adg_ssi_reg_get(id);
dev_dbg(dev, "ADG: ssi%d selects clk%d = %d", id, i, rate);
/*
* Enable SSIx clock
*/
shift = (id % 4) * 8;
rsnd_bset(priv, mod, reg,
0xFF << shift,
data << shift);
return 0;
}
static void rsnd_adg_ssi_clk_init(struct rsnd_priv *priv, struct rsnd_adg *adg)
{
struct clk *clk;
unsigned long rate;
u32 ckr;
int i;
int brg_table[] = {
[CLKA] = 0x0,
[CLKB] = 0x1,
[CLKC] = 0x4,
[CLKI] = 0x2,
};
/*
* This driver is assuming that AUDIO_CLKA/AUDIO_CLKB/AUDIO_CLKC
* have 44.1kHz or 48kHz base clocks for now.
*
* SSI itself can divide parent clock by 1/1 - 1/16
* So, BRGA outputs 44.1kHz base parent clock 1/32,
* and, BRGB outputs 48.0kHz base parent clock 1/32 here.
* see
* rsnd_adg_ssi_clk_try_start()
*/
ckr = 0;
adg->rate_of_441khz_div_6 = 0;
adg->rate_of_48khz_div_6 = 0;
for_each_rsnd_clk(clk, adg, i) {
rate = clk_get_rate(clk);
if (0 == rate) /* not used */
continue;
/* RBGA */
if (!adg->rate_of_441khz_div_6 && (0 == rate % 44100)) {
adg->rate_of_441khz_div_6 = rate / 6;
ckr |= brg_table[i] << 20;
}
/* RBGB */
if (!adg->rate_of_48khz_div_6 && (0 == rate % 48000)) {
adg->rate_of_48khz_div_6 = rate / 6;
ckr |= brg_table[i] << 16;
}
}
rsnd_priv_bset(priv, SSICKR, 0x00FF0000, ckr);
rsnd_priv_write(priv, BRRA, 0x00000002); /* 1/6 */
rsnd_priv_write(priv, BRRB, 0x00000002); /* 1/6 */
}
int rsnd_adg_probe(struct platform_device *pdev,
struct rcar_snd_info *info,
struct rsnd_priv *priv)
{
struct rsnd_adg *adg;
struct device *dev = rsnd_priv_to_dev(priv);
struct clk *clk;
int i;
adg = devm_kzalloc(dev, sizeof(*adg), GFP_KERNEL);
if (!adg) {
dev_err(dev, "ADG allocate failed\n");
return -ENOMEM;
}
adg->clk[CLKA] = clk_get(NULL, "audio_clk_a");
adg->clk[CLKB] = clk_get(NULL, "audio_clk_b");
adg->clk[CLKC] = clk_get(NULL, "audio_clk_c");
adg->clk[CLKI] = clk_get(NULL, "audio_clk_internal");
for_each_rsnd_clk(clk, adg, i) {
if (IS_ERR(clk)) {
dev_err(dev, "Audio clock failed\n");
return -EIO;
}
}
rsnd_adg_ssi_clk_init(priv, adg);
priv->adg = adg;
dev_dbg(dev, "adg probed\n");
return 0;
}
void rsnd_adg_remove(struct platform_device *pdev,
struct rsnd_priv *priv)
{
struct rsnd_adg *adg = priv->adg;
struct clk *clk;
int i;
for_each_rsnd_clk(clk, adg, i)
clk_put(clk);
}
This diff is collapsed.
/*
* Renesas R-Car Gen1 SRU/SSI support
*
* Copyright (C) 2013 Renesas Solutions Corp.
* Kuninori Morimoto <kuninori.morimoto.gx@renesas.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 "rsnd.h"
struct rsnd_gen_ops {
int (*path_init)(struct rsnd_priv *priv,
struct rsnd_dai *rdai,
struct rsnd_dai_stream *io);
int (*path_exit)(struct rsnd_priv *priv,
struct rsnd_dai *rdai,
struct rsnd_dai_stream *io);
};
struct rsnd_gen_reg_map {
int index; /* -1 : not supported */
u32 offset_id; /* offset of ssi0, ssi1, ssi2... */
u32 offset_adr; /* offset of SSICR, SSISR, ... */
};
struct rsnd_gen {
void __iomem *base[RSND_BASE_MAX];
struct rsnd_gen_reg_map reg_map[RSND_REG_MAX];
struct rsnd_gen_ops *ops;
};
#define rsnd_priv_to_gen(p) ((struct rsnd_gen *)(p)->gen)
/*
* Gen2
* will be filled in the future
*/
/*
* Gen1
*/
static int rsnd_gen1_path_init(struct rsnd_priv *priv,
struct rsnd_dai *rdai,
struct rsnd_dai_stream *io)
{
struct rsnd_mod *mod;
int ret;
int id;
/*
* Gen1 is created by SRU/SSI, and this SRU is base module of
* Gen2's SCU/SSIU/SSI. (Gen2 SCU/SSIU came from SRU)
*
* Easy image is..
* Gen1 SRU = Gen2 SCU + SSIU + etc
*
* Gen2 SCU path is very flexible, but, Gen1 SRU (SCU parts) is
* using fixed path.
*
* Then, SSI id = SCU id here
*/
/* get SSI's ID */
mod = rsnd_ssi_mod_get_frm_dai(priv,
rsnd_dai_id(priv, rdai),
rsnd_dai_is_play(rdai, io));
id = rsnd_mod_id(mod);
/* SSI */
mod = rsnd_ssi_mod_get(priv, id);
ret = rsnd_dai_connect(rdai, mod, io);
if (ret < 0)
return ret;
/* SCU */
mod = rsnd_scu_mod_get(priv, id);
ret = rsnd_dai_connect(rdai, mod, io);
return ret;
}
static int rsnd_gen1_path_exit(struct rsnd_priv *priv,
struct rsnd_dai *rdai,
struct rsnd_dai_stream *io)
{
struct rsnd_mod *mod, *n;
int ret = 0;
/*
* remove all mod from rdai
*/
for_each_rsnd_mod(mod, n, io)
ret |= rsnd_dai_disconnect(mod);
return ret;
}
static struct rsnd_gen_ops rsnd_gen1_ops = {
.path_init = rsnd_gen1_path_init,
.path_exit = rsnd_gen1_path_exit,
};
#define RSND_GEN1_REG_MAP(g, s, i, oi, oa) \
do { \
(g)->reg_map[RSND_REG_##i].index = RSND_GEN1_##s; \
(g)->reg_map[RSND_REG_##i].offset_id = oi; \
(g)->reg_map[RSND_REG_##i].offset_adr = oa; \
} while (0)
static void rsnd_gen1_reg_map_init(struct rsnd_gen *gen)
{
RSND_GEN1_REG_MAP(gen, SRU, SRC_ROUTE_SEL, 0x0, 0x00);
RSND_GEN1_REG_MAP(gen, SRU, SRC_TMG_SEL0, 0x0, 0x08);
RSND_GEN1_REG_MAP(gen, SRU, SRC_TMG_SEL1, 0x0, 0x0c);
RSND_GEN1_REG_MAP(gen, SRU, SRC_TMG_SEL2, 0x0, 0x10);
RSND_GEN1_REG_MAP(gen, SRU, SRC_CTRL, 0x0, 0xc0);
RSND_GEN1_REG_MAP(gen, SRU, SSI_MODE0, 0x0, 0xD0);
RSND_GEN1_REG_MAP(gen, SRU, SSI_MODE1, 0x0, 0xD4);
RSND_GEN1_REG_MAP(gen, SRU, BUSIF_MODE, 0x4, 0x20);
RSND_GEN1_REG_MAP(gen, SRU, BUSIF_ADINR, 0x40, 0x214);
RSND_GEN1_REG_MAP(gen, ADG, BRRA, 0x0, 0x00);
RSND_GEN1_REG_MAP(gen, ADG, BRRB, 0x0, 0x04);
RSND_GEN1_REG_MAP(gen, ADG, SSICKR, 0x0, 0x08);
RSND_GEN1_REG_MAP(gen, ADG, AUDIO_CLK_SEL0, 0x0, 0x0c);
RSND_GEN1_REG_MAP(gen, ADG, AUDIO_CLK_SEL1, 0x0, 0x10);
RSND_GEN1_REG_MAP(gen, ADG, AUDIO_CLK_SEL3, 0x0, 0x18);
RSND_GEN1_REG_MAP(gen, ADG, AUDIO_CLK_SEL4, 0x0, 0x1c);
RSND_GEN1_REG_MAP(gen, ADG, AUDIO_CLK_SEL5, 0x0, 0x20);
RSND_GEN1_REG_MAP(gen, SSI, SSICR, 0x40, 0x00);
RSND_GEN1_REG_MAP(gen, SSI, SSISR, 0x40, 0x04);
RSND_GEN1_REG_MAP(gen, SSI, SSITDR, 0x40, 0x08);
RSND_GEN1_REG_MAP(gen, SSI, SSIRDR, 0x40, 0x0c);
RSND_GEN1_REG_MAP(gen, SSI, SSIWSR, 0x40, 0x20);
}
static int rsnd_gen1_probe(struct platform_device *pdev,
struct rcar_snd_info *info,
struct rsnd_priv *priv)
{
struct device *dev = rsnd_priv_to_dev(priv);
struct rsnd_gen *gen = rsnd_priv_to_gen(priv);
struct resource *sru_res;
struct resource *adg_res;
struct resource *ssi_res;
/*
* map address
*/
sru_res = platform_get_resource(pdev, IORESOURCE_MEM, RSND_GEN1_SRU);
adg_res = platform_get_resource(pdev, IORESOURCE_MEM, RSND_GEN1_ADG);
ssi_res = platform_get_resource(pdev, IORESOURCE_MEM, RSND_GEN1_SSI);
gen->base[RSND_GEN1_SRU] = devm_ioremap_resource(dev, sru_res);
gen->base[RSND_GEN1_ADG] = devm_ioremap_resource(dev, adg_res);
gen->base[RSND_GEN1_SSI] = devm_ioremap_resource(dev, ssi_res);
if (IS_ERR(gen->base[RSND_GEN1_SRU]) ||
IS_ERR(gen->base[RSND_GEN1_ADG]) ||
IS_ERR(gen->base[RSND_GEN1_SSI]))
return -ENODEV;
gen->ops = &rsnd_gen1_ops;
rsnd_gen1_reg_map_init(gen);
dev_dbg(dev, "Gen1 device probed\n");
dev_dbg(dev, "SRU : %08x => %p\n", sru_res->start,
gen->base[RSND_GEN1_SRU]);
dev_dbg(dev, "ADG : %08x => %p\n", adg_res->start,
gen->base[RSND_GEN1_ADG]);
dev_dbg(dev, "SSI : %08x => %p\n", ssi_res->start,
gen->base[RSND_GEN1_SSI]);
return 0;
}
static void rsnd_gen1_remove(struct platform_device *pdev,
struct rsnd_priv *priv)
{
}
/*
* Gen
*/
int rsnd_gen_path_init(struct rsnd_priv *priv,
struct rsnd_dai *rdai,
struct rsnd_dai_stream *io)
{
struct rsnd_gen *gen = rsnd_priv_to_gen(priv);
return gen->ops->path_init(priv, rdai, io);
}
int rsnd_gen_path_exit(struct rsnd_priv *priv,
struct rsnd_dai *rdai,
struct rsnd_dai_stream *io)
{
struct rsnd_gen *gen = rsnd_priv_to_gen(priv);
return gen->ops->path_exit(priv, rdai, io);
}
void __iomem *rsnd_gen_reg_get(struct rsnd_priv *priv,
struct rsnd_mod *mod,
enum rsnd_reg reg)
{
struct rsnd_gen *gen = rsnd_priv_to_gen(priv);
struct device *dev = rsnd_priv_to_dev(priv);
int index;
u32 offset_id, offset_adr;
if (reg >= RSND_REG_MAX) {
dev_err(dev, "rsnd_reg reg error\n");
return NULL;
}
index = gen->reg_map[reg].index;
offset_id = gen->reg_map[reg].offset_id;
offset_adr = gen->reg_map[reg].offset_adr;
if (index < 0) {
dev_err(dev, "unsupported reg access %d\n", reg);
return NULL;
}
if (offset_id && mod)
offset_id *= rsnd_mod_id(mod);
/*
* index/offset were set on gen1/gen2
*/
return gen->base[index] + offset_id + offset_adr;
}
int rsnd_gen_probe(struct platform_device *pdev,
struct rcar_snd_info *info,
struct rsnd_priv *priv)
{
struct device *dev = rsnd_priv_to_dev(priv);
struct rsnd_gen *gen;
int i;
gen = devm_kzalloc(dev, sizeof(*gen), GFP_KERNEL);
if (!gen) {
dev_err(dev, "GEN allocate failed\n");
return -ENOMEM;
}
priv->gen = gen;
/*
* see
* rsnd_reg_get()
* rsnd_gen_probe()
*/
for (i = 0; i < RSND_REG_MAX; i++)
gen->reg_map[i].index = -1;
/*
* init each module
*/
if (rsnd_is_gen1(priv))
return rsnd_gen1_probe(pdev, info, priv);
dev_err(dev, "unknown generation R-Car sound device\n");
return -ENODEV;
}
void rsnd_gen_remove(struct platform_device *pdev,
struct rsnd_priv *priv)
{
if (rsnd_is_gen1(priv))
rsnd_gen1_remove(pdev, priv);
}
/*
* Renesas R-Car
*
* Copyright (C) 2013 Renesas Solutions Corp.
* Kuninori Morimoto <kuninori.morimoto.gx@renesas.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 RSND_H
#define RSND_H
#include <linux/clk.h>
#include <linux/device.h>
#include <linux/dma-mapping.h>
#include <linux/io.h>
#include <linux/list.h>
#include <linux/module.h>
#include <linux/sh_dma.h>
#include <linux/workqueue.h>
#include <sound/rcar_snd.h>
#include <sound/soc.h>
#include <sound/pcm_params.h>
/*
* pseudo register
*
* The register address offsets SRU/SCU/SSIU on Gen1/Gen2 are very different.
* This driver uses pseudo register in order to hide it.
* see gen1/gen2 for detail
*/
enum rsnd_reg {
/* SRU/SCU */
RSND_REG_SRC_ROUTE_SEL,
RSND_REG_SRC_TMG_SEL0,
RSND_REG_SRC_TMG_SEL1,
RSND_REG_SRC_TMG_SEL2,
RSND_REG_SRC_CTRL,
RSND_REG_SSI_MODE0,
RSND_REG_SSI_MODE1,
RSND_REG_BUSIF_MODE,
RSND_REG_BUSIF_ADINR,
/* ADG */
RSND_REG_BRRA,
RSND_REG_BRRB,
RSND_REG_SSICKR,
RSND_REG_AUDIO_CLK_SEL0,
RSND_REG_AUDIO_CLK_SEL1,
RSND_REG_AUDIO_CLK_SEL2,
RSND_REG_AUDIO_CLK_SEL3,
RSND_REG_AUDIO_CLK_SEL4,
RSND_REG_AUDIO_CLK_SEL5,
/* SSI */
RSND_REG_SSICR,
RSND_REG_SSISR,
RSND_REG_SSITDR,
RSND_REG_SSIRDR,
RSND_REG_SSIWSR,
RSND_REG_MAX,
};
struct rsnd_priv;
struct rsnd_mod;
struct rsnd_dai;
struct rsnd_dai_stream;
/*
* R-Car basic functions
*/
#define rsnd_mod_read(m, r) \
rsnd_read(rsnd_mod_to_priv(m), m, RSND_REG_##r)
#define rsnd_mod_write(m, r, d) \
rsnd_write(rsnd_mod_to_priv(m), m, RSND_REG_##r, d)
#define rsnd_mod_bset(m, r, s, d) \
rsnd_bset(rsnd_mod_to_priv(m), m, RSND_REG_##r, s, d)
#define rsnd_priv_read(p, r) rsnd_read(p, NULL, RSND_REG_##r)
#define rsnd_priv_write(p, r, d) rsnd_write(p, NULL, RSND_REG_##r, d)
#define rsnd_priv_bset(p, r, s, d) rsnd_bset(p, NULL, RSND_REG_##r, s, d)
u32 rsnd_read(struct rsnd_priv *priv, struct rsnd_mod *mod, enum rsnd_reg reg);
void rsnd_write(struct rsnd_priv *priv, struct rsnd_mod *mod,
enum rsnd_reg reg, u32 data);
void rsnd_bset(struct rsnd_priv *priv, struct rsnd_mod *mod, enum rsnd_reg reg,
u32 mask, u32 data);
/*
* R-Car DMA
*/
struct rsnd_dma {
struct rsnd_priv *priv;
struct sh_dmae_slave slave;
struct work_struct work;
struct dma_chan *chan;
enum dma_data_direction dir;
int (*inquiry)(struct rsnd_dma *dma, dma_addr_t *buf, int *len);
int (*complete)(struct rsnd_dma *dma);
int submit_loop;
};
void rsnd_dma_start(struct rsnd_dma *dma);
void rsnd_dma_stop(struct rsnd_dma *dma);
int rsnd_dma_available(struct rsnd_dma *dma);
int rsnd_dma_init(struct rsnd_priv *priv, struct rsnd_dma *dma,
int is_play, int id,
int (*inquiry)(struct rsnd_dma *dma, dma_addr_t *buf, int *len),
int (*complete)(struct rsnd_dma *dma));
void rsnd_dma_quit(struct rsnd_priv *priv,
struct rsnd_dma *dma);
/*
* R-Car sound mod
*/
struct rsnd_mod_ops {
char *name;
int (*init)(struct rsnd_mod *mod,
struct rsnd_dai *rdai,
struct rsnd_dai_stream *io);
int (*quit)(struct rsnd_mod *mod,
struct rsnd_dai *rdai,
struct rsnd_dai_stream *io);
int (*start)(struct rsnd_mod *mod,
struct rsnd_dai *rdai,
struct rsnd_dai_stream *io);
int (*stop)(struct rsnd_mod *mod,
struct rsnd_dai *rdai,
struct rsnd_dai_stream *io);
};
struct rsnd_mod {
int id;
struct rsnd_priv *priv;
struct rsnd_mod_ops *ops;
struct list_head list; /* connect to rsnd_dai playback/capture */
struct rsnd_dma dma;
};
#define rsnd_mod_to_priv(mod) ((mod)->priv)
#define rsnd_mod_to_dma(mod) (&(mod)->dma)
#define rsnd_dma_to_mod(_dma) container_of((_dma), struct rsnd_mod, dma)
#define rsnd_mod_id(mod) ((mod)->id)
#define for_each_rsnd_mod(pos, n, io) \
list_for_each_entry_safe(pos, n, &(io)->head, list)
#define rsnd_mod_call(mod, func, rdai, io) \
(!(mod) ? -ENODEV : \
!((mod)->ops->func) ? 0 : \
(mod)->ops->func(mod, rdai, io))
void rsnd_mod_init(struct rsnd_priv *priv,
struct rsnd_mod *mod,
struct rsnd_mod_ops *ops,
int id);
char *rsnd_mod_name(struct rsnd_mod *mod);
/*
* R-Car sound DAI
*/
#define RSND_DAI_NAME_SIZE 16
struct rsnd_dai_stream {
struct list_head head; /* head of rsnd_mod list */
struct snd_pcm_substream *substream;
int byte_pos;
int period_pos;
int byte_per_period;
int next_period_byte;
};
struct rsnd_dai {
char name[RSND_DAI_NAME_SIZE];
struct rsnd_dai_platform_info *info; /* rcar_snd.h */
struct rsnd_dai_stream playback;
struct rsnd_dai_stream capture;
int clk_master:1;
int bit_clk_inv:1;
int frm_clk_inv:1;
int sys_delay:1;
int data_alignment:1;
};
#define rsnd_dai_nr(priv) ((priv)->dai_nr)
#define for_each_rsnd_dai(rdai, priv, i) \
for (i = 0, (rdai) = rsnd_dai_get(priv, i); \
i < rsnd_dai_nr(priv); \
i++, (rdai) = rsnd_dai_get(priv, i))
struct rsnd_dai *rsnd_dai_get(struct rsnd_priv *priv, int id);
int rsnd_dai_disconnect(struct rsnd_mod *mod);
int rsnd_dai_connect(struct rsnd_dai *rdai, struct rsnd_mod *mod,
struct rsnd_dai_stream *io);
int rsnd_dai_is_play(struct rsnd_dai *rdai, struct rsnd_dai_stream *io);
int rsnd_dai_id(struct rsnd_priv *priv, struct rsnd_dai *rdai);
#define rsnd_dai_get_platform_info(rdai) ((rdai)->info)
#define rsnd_io_to_runtime(io) ((io)->substream->runtime)
void rsnd_dai_pointer_update(struct rsnd_dai_stream *io, int cnt);
int rsnd_dai_pointer_offset(struct rsnd_dai_stream *io, int additional);
/*
* R-Car Gen1/Gen2
*/
int rsnd_gen_probe(struct platform_device *pdev,
struct rcar_snd_info *info,
struct rsnd_priv *priv);
void rsnd_gen_remove(struct platform_device *pdev,
struct rsnd_priv *priv);
int rsnd_gen_path_init(struct rsnd_priv *priv,
struct rsnd_dai *rdai,
struct rsnd_dai_stream *io);
int rsnd_gen_path_exit(struct rsnd_priv *priv,
struct rsnd_dai *rdai,
struct rsnd_dai_stream *io);
void __iomem *rsnd_gen_reg_get(struct rsnd_priv *priv,
struct rsnd_mod *mod,
enum rsnd_reg reg);
#define rsnd_is_gen1(s) ((s)->info->flags & RSND_GEN1)
#define rsnd_is_gen2(s) ((s)->info->flags & RSND_GEN2)
/*
* R-Car ADG
*/
int rsnd_adg_ssi_clk_stop(struct rsnd_mod *mod);
int rsnd_adg_ssi_clk_try_start(struct rsnd_mod *mod, unsigned int rate);
int rsnd_adg_probe(struct platform_device *pdev,
struct rcar_snd_info *info,
struct rsnd_priv *priv);
void rsnd_adg_remove(struct platform_device *pdev,
struct rsnd_priv *priv);
/*
* R-Car sound priv
*/
struct rsnd_priv {
struct device *dev;
struct rcar_snd_info *info;
spinlock_t lock;
/*
* below value will be filled on rsnd_gen_probe()
*/
void *gen;
/*
* below value will be filled on rsnd_scu_probe()
*/
void *scu;
int scu_nr;
/*
* below value will be filled on rsnd_adg_probe()
*/
void *adg;
/*
* below value will be filled on rsnd_ssi_probe()
*/
void *ssiu;
/*
* below value will be filled on rsnd_dai_probe()
*/
struct snd_soc_dai_driver *daidrv;
struct rsnd_dai *rdai;
int dai_nr;
};
#define rsnd_priv_to_dev(priv) ((priv)->dev)
#define rsnd_lock(priv, flags) spin_lock_irqsave(&priv->lock, flags)
#define rsnd_unlock(priv, flags) spin_unlock_irqrestore(&priv->lock, flags)
/*
* R-Car SCU
*/
int rsnd_scu_probe(struct platform_device *pdev,
struct rcar_snd_info *info,
struct rsnd_priv *priv);
void rsnd_scu_remove(struct platform_device *pdev,
struct rsnd_priv *priv);
struct rsnd_mod *rsnd_scu_mod_get(struct rsnd_priv *priv, int id);
#define rsnd_scu_nr(priv) ((priv)->scu_nr)
/*
* R-Car SSI
*/
int rsnd_ssi_probe(struct platform_device *pdev,
struct rcar_snd_info *info,
struct rsnd_priv *priv);
void rsnd_ssi_remove(struct platform_device *pdev,
struct rsnd_priv *priv);
struct rsnd_mod *rsnd_ssi_mod_get(struct rsnd_priv *priv, int id);
struct rsnd_mod *rsnd_ssi_mod_get_frm_dai(struct rsnd_priv *priv,
int dai_id, int is_play);
#endif
/*
* Renesas R-Car SCU support
*
* Copyright (C) 2013 Renesas Solutions Corp.
* Kuninori Morimoto <kuninori.morimoto.gx@renesas.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 "rsnd.h"
struct rsnd_scu {
struct rsnd_scu_platform_info *info; /* rcar_snd.h */
struct rsnd_mod mod;
};
#define rsnd_scu_mode_flags(p) ((p)->info->flags)
/*
* ADINR
*/
#define OTBL_24 (0 << 16)
#define OTBL_22 (2 << 16)
#define OTBL_20 (4 << 16)
#define OTBL_18 (6 << 16)
#define OTBL_16 (8 << 16)
#define rsnd_mod_to_scu(_mod) \
container_of((_mod), struct rsnd_scu, mod)
#define for_each_rsnd_scu(pos, priv, i) \
for ((i) = 0; \
((i) < rsnd_scu_nr(priv)) && \
((pos) = (struct rsnd_scu *)(priv)->scu + i); \
i++)
static int rsnd_scu_set_route(struct rsnd_priv *priv,
struct rsnd_mod *mod,
struct rsnd_dai *rdai,
struct rsnd_dai_stream *io)
{
struct scu_route_config {
u32 mask;
int shift;
} routes[] = {
{ 0xF, 0, }, /* 0 */
{ 0xF, 4, }, /* 1 */
{ 0xF, 8, }, /* 2 */
{ 0x7, 12, }, /* 3 */
{ 0x7, 16, }, /* 4 */
{ 0x7, 20, }, /* 5 */
{ 0x7, 24, }, /* 6 */
{ 0x3, 28, }, /* 7 */
{ 0x3, 30, }, /* 8 */
};
u32 mask;
u32 val;
int shift;
int id;
/*
* Gen1 only
*/
if (!rsnd_is_gen1(priv))
return 0;
id = rsnd_mod_id(mod);
if (id < 0 || id > ARRAY_SIZE(routes))
return -EIO;
/*
* SRC_ROUTE_SELECT
*/
val = rsnd_dai_is_play(rdai, io) ? 0x1 : 0x2;
val = val << routes[id].shift;
mask = routes[id].mask << routes[id].shift;
rsnd_mod_bset(mod, SRC_ROUTE_SEL, mask, val);
/*
* SRC_TIMING_SELECT
*/
shift = (id % 4) * 8;
mask = 0x1F << shift;
if (8 == id) /* SRU8 is very special */
val = id << shift;
else
val = (id + 1) << shift;
switch (id / 4) {
case 0:
rsnd_mod_bset(mod, SRC_TMG_SEL0, mask, val);
break;
case 1:
rsnd_mod_bset(mod, SRC_TMG_SEL1, mask, val);
break;
case 2:
rsnd_mod_bset(mod, SRC_TMG_SEL2, mask, val);
break;
}
return 0;
}
static int rsnd_scu_set_mode(struct rsnd_priv *priv,
struct rsnd_mod *mod,
struct rsnd_dai *rdai,
struct rsnd_dai_stream *io)
{
int id = rsnd_mod_id(mod);
u32 val;
if (rsnd_is_gen1(priv)) {
val = (1 << id);
rsnd_mod_bset(mod, SRC_CTRL, val, val);
}
return 0;
}
static int rsnd_scu_set_hpbif(struct rsnd_priv *priv,
struct rsnd_mod *mod,
struct rsnd_dai *rdai,
struct rsnd_dai_stream *io)
{
struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
u32 adinr = runtime->channels;
switch (runtime->sample_bits) {
case 16:
adinr |= OTBL_16;
break;
case 32:
adinr |= OTBL_24;
break;
default:
return -EIO;
}
rsnd_mod_write(mod, BUSIF_MODE, 1);
rsnd_mod_write(mod, BUSIF_ADINR, adinr);
return 0;
}
static int rsnd_scu_start(struct rsnd_mod *mod,
struct rsnd_dai *rdai,
struct rsnd_dai_stream *io)
{
struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
struct rsnd_scu *scu = rsnd_mod_to_scu(mod);
struct device *dev = rsnd_priv_to_dev(priv);
u32 flags = rsnd_scu_mode_flags(scu);
int ret;
/*
* SCU will be used if it has RSND_SCU_USB_HPBIF flags
*/
if (!(flags & RSND_SCU_USB_HPBIF)) {
/* it use PIO transter */
dev_dbg(dev, "%s%d is not used\n",
rsnd_mod_name(mod), rsnd_mod_id(mod));
return 0;
}
/* it use DMA transter */
ret = rsnd_scu_set_route(priv, mod, rdai, io);
if (ret < 0)
return ret;
ret = rsnd_scu_set_mode(priv, mod, rdai, io);
if (ret < 0)
return ret;
ret = rsnd_scu_set_hpbif(priv, mod, rdai, io);
if (ret < 0)
return ret;
dev_dbg(dev, "%s%d start\n", rsnd_mod_name(mod), rsnd_mod_id(mod));
return 0;
}
static struct rsnd_mod_ops rsnd_scu_ops = {
.name = "scu",
.start = rsnd_scu_start,
};
struct rsnd_mod *rsnd_scu_mod_get(struct rsnd_priv *priv, int id)
{
BUG_ON(id < 0 || id >= rsnd_scu_nr(priv));
return &((struct rsnd_scu *)(priv->scu) + id)->mod;
}
int rsnd_scu_probe(struct platform_device *pdev,
struct rcar_snd_info *info,
struct rsnd_priv *priv)
{
struct device *dev = rsnd_priv_to_dev(priv);
struct rsnd_scu *scu;
int i, nr;
/*
* init SCU
*/
nr = info->scu_info_nr;
scu = devm_kzalloc(dev, sizeof(*scu) * nr, GFP_KERNEL);
if (!scu) {
dev_err(dev, "SCU allocate failed\n");
return -ENOMEM;
}
priv->scu_nr = nr;
priv->scu = scu;
for_each_rsnd_scu(scu, priv, i) {
rsnd_mod_init(priv, &scu->mod,
&rsnd_scu_ops, i);
scu->info = &info->scu_info[i];
dev_dbg(dev, "SCU%d probed\n", i);
}
dev_dbg(dev, "scu probed\n");
return 0;
}
void rsnd_scu_remove(struct platform_device *pdev,
struct rsnd_priv *priv)
{
}
This diff is collapsed.
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