mirror of
https://github.com/AetherDroid/android_kernel_samsung_on5xelte.git
synced 2025-10-29 23:28:52 +01:00
Fixed MTP to work with TWRP
This commit is contained in:
commit
f6dfaef42e
50820 changed files with 20846062 additions and 0 deletions
2
sound/soc/sh/rcar/Makefile
Normal file
2
sound/soc/sh/rcar/Makefile
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
snd-soc-rcar-objs := core.o gen.o src.o adg.o ssi.o dvc.o
|
||||
obj-$(CONFIG_SND_SOC_RCAR) += snd-soc-rcar.o
|
||||
442
sound/soc/sh/rcar/adg.c
Normal file
442
sound/soc/sh/rcar/adg.c
Normal file
|
|
@ -0,0 +1,442 @@
|
|||
/*
|
||||
* 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 "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 rbga_rate_for_441khz_div_6; /* RBGA */
|
||||
int rbgb_rate_for_48khz_div_6; /* RBGB */
|
||||
u32 ckr;
|
||||
};
|
||||
|
||||
#define for_each_rsnd_clk(pos, adg, i) \
|
||||
for (i = 0; \
|
||||
(i < CLKMAX) && \
|
||||
((pos) = adg->clk[i]); \
|
||||
i++)
|
||||
#define rsnd_priv_to_adg(priv) ((struct rsnd_adg *)(priv)->adg)
|
||||
|
||||
|
||||
static u32 rsnd_adg_ssi_ws_timing_gen2(struct rsnd_dai_stream *io)
|
||||
{
|
||||
struct rsnd_mod *mod = rsnd_io_to_mod_ssi(io);
|
||||
struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
|
||||
int id = rsnd_mod_id(mod);
|
||||
int ws = id;
|
||||
|
||||
if (rsnd_ssi_is_pin_sharing(rsnd_ssi_mod_get(priv, id))) {
|
||||
switch (id) {
|
||||
case 1:
|
||||
case 2:
|
||||
ws = 0;
|
||||
break;
|
||||
case 4:
|
||||
ws = 3;
|
||||
break;
|
||||
case 8:
|
||||
ws = 7;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return (0x6 + ws) << 8;
|
||||
}
|
||||
|
||||
int rsnd_adg_set_cmd_timsel_gen2(struct rsnd_dai *rdai,
|
||||
struct rsnd_mod *mod,
|
||||
struct rsnd_dai_stream *io)
|
||||
{
|
||||
int id = rsnd_mod_id(mod);
|
||||
int shift = (id % 2) ? 16 : 0;
|
||||
u32 mask, val;
|
||||
|
||||
val = rsnd_adg_ssi_ws_timing_gen2(io);
|
||||
|
||||
val = val << shift;
|
||||
mask = 0xffff << shift;
|
||||
|
||||
rsnd_mod_bset(mod, CMDOUT_TIMSEL, mask, val);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rsnd_adg_set_src_timsel_gen2(struct rsnd_dai *rdai,
|
||||
struct rsnd_mod *mod,
|
||||
struct rsnd_dai_stream *io,
|
||||
u32 timsel)
|
||||
{
|
||||
int is_play = rsnd_dai_is_play(rdai, io);
|
||||
int id = rsnd_mod_id(mod);
|
||||
int shift = (id % 2) ? 16 : 0;
|
||||
u32 mask, ws;
|
||||
u32 in, out;
|
||||
|
||||
ws = rsnd_adg_ssi_ws_timing_gen2(io);
|
||||
|
||||
in = (is_play) ? timsel : ws;
|
||||
out = (is_play) ? ws : timsel;
|
||||
|
||||
in = in << shift;
|
||||
out = out << shift;
|
||||
mask = 0xffff << shift;
|
||||
|
||||
switch (id / 2) {
|
||||
case 0:
|
||||
rsnd_mod_bset(mod, SRCIN_TIMSEL0, mask, in);
|
||||
rsnd_mod_bset(mod, SRCOUT_TIMSEL0, mask, out);
|
||||
break;
|
||||
case 1:
|
||||
rsnd_mod_bset(mod, SRCIN_TIMSEL1, mask, in);
|
||||
rsnd_mod_bset(mod, SRCOUT_TIMSEL1, mask, out);
|
||||
break;
|
||||
case 2:
|
||||
rsnd_mod_bset(mod, SRCIN_TIMSEL2, mask, in);
|
||||
rsnd_mod_bset(mod, SRCOUT_TIMSEL2, mask, out);
|
||||
break;
|
||||
case 3:
|
||||
rsnd_mod_bset(mod, SRCIN_TIMSEL3, mask, in);
|
||||
rsnd_mod_bset(mod, SRCOUT_TIMSEL3, mask, out);
|
||||
break;
|
||||
case 4:
|
||||
rsnd_mod_bset(mod, SRCIN_TIMSEL4, mask, in);
|
||||
rsnd_mod_bset(mod, SRCOUT_TIMSEL4, mask, out);
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rsnd_adg_set_convert_clk_gen2(struct rsnd_mod *mod,
|
||||
struct rsnd_dai *rdai,
|
||||
struct rsnd_dai_stream *io,
|
||||
unsigned int src_rate,
|
||||
unsigned int dst_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);
|
||||
int idx, sel, div, step, ret;
|
||||
u32 val, en;
|
||||
unsigned int min, diff;
|
||||
unsigned int sel_rate [] = {
|
||||
clk_get_rate(adg->clk[CLKA]), /* 0000: CLKA */
|
||||
clk_get_rate(adg->clk[CLKB]), /* 0001: CLKB */
|
||||
clk_get_rate(adg->clk[CLKC]), /* 0010: CLKC */
|
||||
adg->rbga_rate_for_441khz_div_6,/* 0011: RBGA */
|
||||
adg->rbgb_rate_for_48khz_div_6, /* 0100: RBGB */
|
||||
};
|
||||
|
||||
min = ~0;
|
||||
val = 0;
|
||||
en = 0;
|
||||
for (sel = 0; sel < ARRAY_SIZE(sel_rate); sel++) {
|
||||
idx = 0;
|
||||
step = 2;
|
||||
|
||||
if (!sel_rate[sel])
|
||||
continue;
|
||||
|
||||
for (div = 2; div <= 98304; div += step) {
|
||||
diff = abs(src_rate - sel_rate[sel] / div);
|
||||
if (min > diff) {
|
||||
val = (sel << 8) | idx;
|
||||
min = diff;
|
||||
en = 1 << (sel + 1); /* fixme */
|
||||
}
|
||||
|
||||
/*
|
||||
* step of 0_0000 / 0_0001 / 0_1101
|
||||
* are out of order
|
||||
*/
|
||||
if ((idx > 2) && (idx % 2))
|
||||
step *= 2;
|
||||
if (idx == 0x1c) {
|
||||
div += step;
|
||||
step *= 2;
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
|
||||
if (min == ~0) {
|
||||
dev_err(dev, "no Input clock\n");
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
ret = rsnd_adg_set_src_timsel_gen2(rdai, mod, io, val);
|
||||
if (ret < 0) {
|
||||
dev_err(dev, "timsel error\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
rsnd_mod_bset(mod, DIV_EN, en, en);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rsnd_adg_set_convert_timing_gen2(struct rsnd_mod *mod,
|
||||
struct rsnd_dai *rdai,
|
||||
struct rsnd_dai_stream *io)
|
||||
{
|
||||
u32 val = rsnd_adg_ssi_ws_timing_gen2(io);
|
||||
|
||||
return rsnd_adg_set_src_timsel_gen2(rdai, mod, io, val);
|
||||
}
|
||||
|
||||
int rsnd_adg_set_convert_clk_gen1(struct rsnd_priv *priv,
|
||||
struct rsnd_mod *mod,
|
||||
unsigned int src_rate,
|
||||
unsigned int dst_rate)
|
||||
{
|
||||
struct rsnd_adg *adg = rsnd_priv_to_adg(priv);
|
||||
struct device *dev = rsnd_priv_to_dev(priv);
|
||||
int idx, sel, div, shift;
|
||||
u32 mask, val;
|
||||
int id = rsnd_mod_id(mod);
|
||||
unsigned int sel_rate [] = {
|
||||
clk_get_rate(adg->clk[CLKA]), /* 000: CLKA */
|
||||
clk_get_rate(adg->clk[CLKB]), /* 001: CLKB */
|
||||
clk_get_rate(adg->clk[CLKC]), /* 010: CLKC */
|
||||
0, /* 011: MLBCLK (not used) */
|
||||
adg->rbga_rate_for_441khz_div_6,/* 100: RBGA */
|
||||
adg->rbgb_rate_for_48khz_div_6, /* 101: RBGB */
|
||||
};
|
||||
|
||||
/* find div (= 1/128, 1/256, 1/512, 1/1024, 1/2048 */
|
||||
for (sel = 0; sel < ARRAY_SIZE(sel_rate); sel++) {
|
||||
for (div = 128, idx = 0;
|
||||
div <= 2048;
|
||||
div *= 2, idx++) {
|
||||
if (src_rate == sel_rate[sel] / div) {
|
||||
val = (idx << 4) | sel;
|
||||
goto find_rate;
|
||||
}
|
||||
}
|
||||
}
|
||||
dev_err(dev, "can't find convert src clk\n");
|
||||
return -EINVAL;
|
||||
|
||||
find_rate:
|
||||
shift = (id % 4) * 8;
|
||||
mask = 0xFF << shift;
|
||||
val = val << shift;
|
||||
|
||||
dev_dbg(dev, "adg convert src clk = %02x\n", val);
|
||||
|
||||
switch (id / 4) {
|
||||
case 0:
|
||||
rsnd_mod_bset(mod, AUDIO_CLK_SEL3, mask, val);
|
||||
break;
|
||||
case 1:
|
||||
rsnd_mod_bset(mod, AUDIO_CLK_SEL4, mask, val);
|
||||
break;
|
||||
case 2:
|
||||
rsnd_mod_bset(mod, AUDIO_CLK_SEL5, mask, val);
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* Gen1 doesn't need dst_rate settings,
|
||||
* since it uses SSI WS pin.
|
||||
* see also rsnd_src_set_route_if_gen1()
|
||||
*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void rsnd_adg_set_ssi_clk(struct rsnd_mod *mod, u32 val)
|
||||
{
|
||||
int id = rsnd_mod_id(mod);
|
||||
int shift = (id % 4) * 8;
|
||||
u32 mask = 0xFF << shift;
|
||||
|
||||
val = val << shift;
|
||||
|
||||
/*
|
||||
* SSI 8 is not connected to ADG.
|
||||
* it works with SSI 7
|
||||
*/
|
||||
if (id == 8)
|
||||
return;
|
||||
|
||||
switch (id / 4) {
|
||||
case 0:
|
||||
rsnd_mod_bset(mod, AUDIO_CLK_SEL0, mask, val);
|
||||
break;
|
||||
case 1:
|
||||
rsnd_mod_bset(mod, AUDIO_CLK_SEL1, mask, val);
|
||||
break;
|
||||
case 2:
|
||||
rsnd_mod_bset(mod, AUDIO_CLK_SEL2, mask, val);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int rsnd_adg_ssi_clk_stop(struct rsnd_mod *mod)
|
||||
{
|
||||
/*
|
||||
* "mod" = "ssi" here.
|
||||
* we can get "ssi id" from mod
|
||||
*/
|
||||
rsnd_adg_set_ssi_clk(mod, 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;
|
||||
int 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->rbga_rate_for_441khz_div_6) {
|
||||
data = 0x10;
|
||||
goto found_clock;
|
||||
}
|
||||
|
||||
if (rate == adg->rbgb_rate_for_48khz_div_6) {
|
||||
data = 0x20;
|
||||
goto found_clock;
|
||||
}
|
||||
|
||||
return -EIO;
|
||||
|
||||
found_clock:
|
||||
|
||||
/* see rsnd_adg_ssi_clk_init() */
|
||||
rsnd_mod_bset(mod, SSICKR, 0x00FF0000, adg->ckr);
|
||||
rsnd_mod_write(mod, BRRA, 0x00000002); /* 1/6 */
|
||||
rsnd_mod_write(mod, BRRB, 0x00000002); /* 1/6 */
|
||||
|
||||
/*
|
||||
* This "mod" = "ssi" here.
|
||||
* we can get "ssi id" from mod
|
||||
*/
|
||||
rsnd_adg_set_ssi_clk(mod, data);
|
||||
|
||||
dev_dbg(dev, "ADG: ssi%d selects clk%d = %d",
|
||||
rsnd_mod_id(mod), i, rate);
|
||||
|
||||
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->rbga_rate_for_441khz_div_6 = 0;
|
||||
adg->rbgb_rate_for_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->rbga_rate_for_441khz_div_6 && (0 == rate % 44100)) {
|
||||
adg->rbga_rate_for_441khz_div_6 = rate / 6;
|
||||
ckr |= brg_table[i] << 20;
|
||||
}
|
||||
|
||||
/* RBGB */
|
||||
if (!adg->rbgb_rate_for_48khz_div_6 && (0 == rate % 48000)) {
|
||||
adg->rbgb_rate_for_48khz_div_6 = rate / 6;
|
||||
ckr |= brg_table[i] << 16;
|
||||
}
|
||||
}
|
||||
|
||||
adg->ckr = ckr;
|
||||
}
|
||||
|
||||
int rsnd_adg_probe(struct platform_device *pdev,
|
||||
const struct rsnd_of_data *of_data,
|
||||
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] = devm_clk_get(dev, "clk_a");
|
||||
adg->clk[CLKB] = devm_clk_get(dev, "clk_b");
|
||||
adg->clk[CLKC] = devm_clk_get(dev, "clk_c");
|
||||
adg->clk[CLKI] = devm_clk_get(dev, "clk_i");
|
||||
|
||||
for_each_rsnd_clk(clk, adg, i)
|
||||
dev_dbg(dev, "clk %d : %p\n", i, clk);
|
||||
|
||||
rsnd_adg_ssi_clk_init(priv, adg);
|
||||
|
||||
priv->adg = adg;
|
||||
|
||||
dev_dbg(dev, "adg probed\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
1112
sound/soc/sh/rcar/core.c
Normal file
1112
sound/soc/sh/rcar/core.c
Normal file
File diff suppressed because it is too large
Load diff
356
sound/soc/sh/rcar/dvc.c
Normal file
356
sound/soc/sh/rcar/dvc.c
Normal file
|
|
@ -0,0 +1,356 @@
|
|||
/*
|
||||
* Renesas R-Car DVC support
|
||||
*
|
||||
* Copyright (C) 2014 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"
|
||||
|
||||
#define RSND_DVC_NAME_SIZE 16
|
||||
#define RSND_DVC_VOLUME_MAX 100
|
||||
#define RSND_DVC_VOLUME_NUM 2
|
||||
|
||||
#define DVC_NAME "dvc"
|
||||
|
||||
struct rsnd_dvc {
|
||||
struct rsnd_dvc_platform_info *info; /* rcar_snd.h */
|
||||
struct rsnd_mod mod;
|
||||
struct clk *clk;
|
||||
u8 volume[RSND_DVC_VOLUME_NUM];
|
||||
u8 mute[RSND_DVC_VOLUME_NUM];
|
||||
};
|
||||
|
||||
#define rsnd_mod_to_dvc(_mod) \
|
||||
container_of((_mod), struct rsnd_dvc, mod)
|
||||
|
||||
#define for_each_rsnd_dvc(pos, priv, i) \
|
||||
for ((i) = 0; \
|
||||
((i) < rsnd_dvc_nr(priv)) && \
|
||||
((pos) = (struct rsnd_dvc *)(priv)->dvc + i); \
|
||||
i++)
|
||||
|
||||
static void rsnd_dvc_volume_update(struct rsnd_mod *mod)
|
||||
{
|
||||
struct rsnd_dvc *dvc = rsnd_mod_to_dvc(mod);
|
||||
u32 max = (0x00800000 - 1);
|
||||
u32 vol[RSND_DVC_VOLUME_NUM];
|
||||
u32 mute = 0;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < RSND_DVC_VOLUME_NUM; i++) {
|
||||
vol[i] = max / RSND_DVC_VOLUME_MAX * dvc->volume[i];
|
||||
mute |= (!!dvc->mute[i]) << i;
|
||||
}
|
||||
|
||||
rsnd_mod_write(mod, DVC_VOL0R, vol[0]);
|
||||
rsnd_mod_write(mod, DVC_VOL1R, vol[1]);
|
||||
|
||||
rsnd_mod_write(mod, DVC_ZCMCR, mute);
|
||||
}
|
||||
|
||||
static int rsnd_dvc_probe_gen2(struct rsnd_mod *mod,
|
||||
struct rsnd_dai *rdai)
|
||||
{
|
||||
struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
|
||||
struct device *dev = rsnd_priv_to_dev(priv);
|
||||
|
||||
dev_dbg(dev, "%s (Gen2) is probed\n", rsnd_mod_name(mod));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rsnd_dvc_init(struct rsnd_mod *dvc_mod,
|
||||
struct rsnd_dai *rdai)
|
||||
{
|
||||
struct rsnd_dvc *dvc = rsnd_mod_to_dvc(dvc_mod);
|
||||
struct rsnd_dai_stream *io = rsnd_mod_to_io(dvc_mod);
|
||||
struct rsnd_priv *priv = rsnd_mod_to_priv(dvc_mod);
|
||||
struct rsnd_mod *src_mod = rsnd_io_to_mod_src(io);
|
||||
struct device *dev = rsnd_priv_to_dev(priv);
|
||||
int dvc_id = rsnd_mod_id(dvc_mod);
|
||||
int src_id = rsnd_mod_id(src_mod);
|
||||
u32 route[] = {
|
||||
[0] = 0x30000,
|
||||
[1] = 0x30001,
|
||||
[2] = 0x40000,
|
||||
[3] = 0x10000,
|
||||
[4] = 0x20000,
|
||||
[5] = 0x40100
|
||||
};
|
||||
|
||||
if (src_id >= ARRAY_SIZE(route)) {
|
||||
dev_err(dev, "DVC%d isn't connected to SRC%d\n", dvc_id, src_id);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
clk_prepare_enable(dvc->clk);
|
||||
|
||||
/*
|
||||
* fixme
|
||||
* it doesn't support CTU/MIX
|
||||
*/
|
||||
rsnd_mod_write(dvc_mod, CMD_ROUTE_SLCT, route[src_id]);
|
||||
|
||||
rsnd_mod_write(dvc_mod, DVC_SWRSR, 0);
|
||||
rsnd_mod_write(dvc_mod, DVC_SWRSR, 1);
|
||||
|
||||
rsnd_mod_write(dvc_mod, DVC_DVUIR, 1);
|
||||
|
||||
rsnd_mod_write(dvc_mod, DVC_ADINR, rsnd_get_adinr(dvc_mod));
|
||||
|
||||
/* enable Volume / Mute */
|
||||
rsnd_mod_write(dvc_mod, DVC_DVUCR, 0x101);
|
||||
|
||||
/* ch0/ch1 Volume */
|
||||
rsnd_dvc_volume_update(dvc_mod);
|
||||
|
||||
rsnd_mod_write(dvc_mod, DVC_DVUIR, 0);
|
||||
|
||||
rsnd_mod_write(dvc_mod, DVC_DVUER, 1);
|
||||
|
||||
rsnd_adg_set_cmd_timsel_gen2(rdai, dvc_mod, io);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rsnd_dvc_quit(struct rsnd_mod *mod,
|
||||
struct rsnd_dai *rdai)
|
||||
{
|
||||
struct rsnd_dvc *dvc = rsnd_mod_to_dvc(mod);
|
||||
|
||||
clk_disable_unprepare(dvc->clk);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rsnd_dvc_start(struct rsnd_mod *mod,
|
||||
struct rsnd_dai *rdai)
|
||||
{
|
||||
rsnd_mod_write(mod, CMD_CTRL, 0x10);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rsnd_dvc_stop(struct rsnd_mod *mod,
|
||||
struct rsnd_dai *rdai)
|
||||
{
|
||||
rsnd_mod_write(mod, CMD_CTRL, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rsnd_dvc_volume_info(struct snd_kcontrol *kctrl,
|
||||
struct snd_ctl_elem_info *uinfo)
|
||||
{
|
||||
struct rsnd_mod *mod = snd_kcontrol_chip(kctrl);
|
||||
struct rsnd_dvc *dvc = rsnd_mod_to_dvc(mod);
|
||||
u8 *val = (u8 *)kctrl->private_value;
|
||||
|
||||
uinfo->count = RSND_DVC_VOLUME_NUM;
|
||||
uinfo->value.integer.min = 0;
|
||||
|
||||
if (val == dvc->volume) {
|
||||
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
|
||||
uinfo->value.integer.max = RSND_DVC_VOLUME_MAX;
|
||||
} else {
|
||||
uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
|
||||
uinfo->value.integer.max = 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rsnd_dvc_volume_get(struct snd_kcontrol *kctrl,
|
||||
struct snd_ctl_elem_value *ucontrol)
|
||||
{
|
||||
u8 *val = (u8 *)kctrl->private_value;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < RSND_DVC_VOLUME_NUM; i++)
|
||||
ucontrol->value.integer.value[i] = val[i];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rsnd_dvc_volume_put(struct snd_kcontrol *kctrl,
|
||||
struct snd_ctl_elem_value *ucontrol)
|
||||
{
|
||||
struct rsnd_mod *mod = snd_kcontrol_chip(kctrl);
|
||||
u8 *val = (u8 *)kctrl->private_value;
|
||||
int i, change = 0;
|
||||
|
||||
for (i = 0; i < RSND_DVC_VOLUME_NUM; i++) {
|
||||
change |= (ucontrol->value.integer.value[i] != val[i]);
|
||||
val[i] = ucontrol->value.integer.value[i];
|
||||
}
|
||||
|
||||
if (change)
|
||||
rsnd_dvc_volume_update(mod);
|
||||
|
||||
return change;
|
||||
}
|
||||
|
||||
static int __rsnd_dvc_pcm_new(struct rsnd_mod *mod,
|
||||
struct rsnd_dai *rdai,
|
||||
struct snd_soc_pcm_runtime *rtd,
|
||||
const unsigned char *name,
|
||||
u8 *private)
|
||||
{
|
||||
struct snd_card *card = rtd->card->snd_card;
|
||||
struct snd_kcontrol *kctrl;
|
||||
struct snd_kcontrol_new knew = {
|
||||
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
|
||||
.name = name,
|
||||
.info = rsnd_dvc_volume_info,
|
||||
.get = rsnd_dvc_volume_get,
|
||||
.put = rsnd_dvc_volume_put,
|
||||
.private_value = (unsigned long)private,
|
||||
};
|
||||
int ret;
|
||||
|
||||
kctrl = snd_ctl_new1(&knew, mod);
|
||||
if (!kctrl)
|
||||
return -ENOMEM;
|
||||
|
||||
ret = snd_ctl_add(card, kctrl);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rsnd_dvc_pcm_new(struct rsnd_mod *mod,
|
||||
struct rsnd_dai *rdai,
|
||||
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);
|
||||
int ret;
|
||||
|
||||
/* Volume */
|
||||
ret = __rsnd_dvc_pcm_new(mod, rdai, rtd,
|
||||
rsnd_dai_is_play(rdai, io) ?
|
||||
"DVC Out Playback Volume" : "DVC In Capture Volume",
|
||||
dvc->volume);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
/* Mute */
|
||||
ret = __rsnd_dvc_pcm_new(mod, rdai, rtd,
|
||||
rsnd_dai_is_play(rdai, io) ?
|
||||
"DVC Out Mute Switch" : "DVC In Mute Switch",
|
||||
dvc->mute);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct rsnd_mod_ops rsnd_dvc_ops = {
|
||||
.name = DVC_NAME,
|
||||
.probe = rsnd_dvc_probe_gen2,
|
||||
.init = rsnd_dvc_init,
|
||||
.quit = rsnd_dvc_quit,
|
||||
.start = rsnd_dvc_start,
|
||||
.stop = rsnd_dvc_stop,
|
||||
.pcm_new = rsnd_dvc_pcm_new,
|
||||
};
|
||||
|
||||
struct rsnd_mod *rsnd_dvc_mod_get(struct rsnd_priv *priv, int id)
|
||||
{
|
||||
if (WARN_ON(id < 0 || id >= rsnd_dvc_nr(priv)))
|
||||
id = 0;
|
||||
|
||||
return &((struct rsnd_dvc *)(priv->dvc) + id)->mod;
|
||||
}
|
||||
|
||||
static void rsnd_of_parse_dvc(struct platform_device *pdev,
|
||||
const struct rsnd_of_data *of_data,
|
||||
struct rsnd_priv *priv)
|
||||
{
|
||||
struct device_node *node;
|
||||
struct rsnd_dvc_platform_info *dvc_info;
|
||||
struct rcar_snd_info *info = rsnd_priv_to_info(priv);
|
||||
struct device *dev = &pdev->dev;
|
||||
int nr;
|
||||
|
||||
if (!of_data)
|
||||
return;
|
||||
|
||||
node = of_get_child_by_name(dev->of_node, "rcar_sound,dvc");
|
||||
if (!node)
|
||||
return;
|
||||
|
||||
nr = of_get_child_count(node);
|
||||
if (!nr)
|
||||
goto rsnd_of_parse_dvc_end;
|
||||
|
||||
dvc_info = devm_kzalloc(dev,
|
||||
sizeof(struct rsnd_dvc_platform_info) * nr,
|
||||
GFP_KERNEL);
|
||||
if (!dvc_info) {
|
||||
dev_err(dev, "dvc info allocation error\n");
|
||||
goto rsnd_of_parse_dvc_end;
|
||||
}
|
||||
|
||||
info->dvc_info = dvc_info;
|
||||
info->dvc_info_nr = nr;
|
||||
|
||||
rsnd_of_parse_dvc_end:
|
||||
of_node_put(node);
|
||||
}
|
||||
|
||||
int rsnd_dvc_probe(struct platform_device *pdev,
|
||||
const struct rsnd_of_data *of_data,
|
||||
struct rsnd_priv *priv)
|
||||
{
|
||||
struct rcar_snd_info *info = rsnd_priv_to_info(priv);
|
||||
struct device *dev = rsnd_priv_to_dev(priv);
|
||||
struct rsnd_dvc *dvc;
|
||||
struct clk *clk;
|
||||
char name[RSND_DVC_NAME_SIZE];
|
||||
int i, nr;
|
||||
|
||||
rsnd_of_parse_dvc(pdev, of_data, priv);
|
||||
|
||||
nr = info->dvc_info_nr;
|
||||
if (!nr)
|
||||
return 0;
|
||||
|
||||
/* This driver doesn't support Gen1 at this point */
|
||||
if (rsnd_is_gen1(priv)) {
|
||||
dev_warn(dev, "CMD is not supported on Gen1\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
dvc = devm_kzalloc(dev, sizeof(*dvc) * nr, GFP_KERNEL);
|
||||
if (!dvc) {
|
||||
dev_err(dev, "CMD allocate failed\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
priv->dvc_nr = nr;
|
||||
priv->dvc = dvc;
|
||||
|
||||
for_each_rsnd_dvc(dvc, priv, i) {
|
||||
snprintf(name, RSND_DVC_NAME_SIZE, "%s.%d",
|
||||
DVC_NAME, i);
|
||||
|
||||
clk = devm_clk_get(dev, name);
|
||||
if (IS_ERR(clk))
|
||||
return PTR_ERR(clk);
|
||||
|
||||
dvc->info = &info->dvc_info[i];
|
||||
dvc->clk = clk;
|
||||
|
||||
rsnd_mod_init(priv, &dvc->mod, &rsnd_dvc_ops, RSND_MOD_DVC, i);
|
||||
|
||||
dev_dbg(dev, "CMD%d probed\n", i);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
468
sound/soc/sh/rcar/gen.c
Normal file
468
sound/soc/sh/rcar/gen.c
Normal file
|
|
@ -0,0 +1,468 @@
|
|||
/*
|
||||
* 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 {
|
||||
void __iomem *base[RSND_BASE_MAX];
|
||||
|
||||
struct rsnd_gen_ops *ops;
|
||||
|
||||
struct regmap *regmap[RSND_BASE_MAX];
|
||||
struct regmap_field *regs[RSND_REG_MAX];
|
||||
};
|
||||
|
||||
#define rsnd_priv_to_gen(p) ((struct rsnd_gen *)(p)->gen)
|
||||
|
||||
struct rsnd_regmap_field_conf {
|
||||
int idx;
|
||||
unsigned int reg_offset;
|
||||
unsigned int id_offset;
|
||||
};
|
||||
|
||||
#define RSND_REG_SET(id, offset, _id_offset) \
|
||||
{ \
|
||||
.idx = id, \
|
||||
.reg_offset = offset, \
|
||||
.id_offset = _id_offset, \
|
||||
}
|
||||
/* single address mapping */
|
||||
#define RSND_GEN_S_REG(id, offset) \
|
||||
RSND_REG_SET(RSND_REG_##id, offset, 0)
|
||||
|
||||
/* multi address mapping */
|
||||
#define RSND_GEN_M_REG(id, offset, _id_offset) \
|
||||
RSND_REG_SET(RSND_REG_##id, offset, _id_offset)
|
||||
|
||||
/*
|
||||
* basic function
|
||||
*/
|
||||
static int rsnd_is_accessible_reg(struct rsnd_priv *priv,
|
||||
struct rsnd_gen *gen, enum rsnd_reg reg)
|
||||
{
|
||||
if (!gen->regs[reg]) {
|
||||
struct device *dev = rsnd_priv_to_dev(priv);
|
||||
|
||||
dev_err(dev, "unsupported register access %x\n", reg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
u32 rsnd_read(struct rsnd_priv *priv,
|
||||
struct rsnd_mod *mod, enum rsnd_reg reg)
|
||||
{
|
||||
struct device *dev = rsnd_priv_to_dev(priv);
|
||||
struct rsnd_gen *gen = rsnd_priv_to_gen(priv);
|
||||
u32 val;
|
||||
|
||||
if (!rsnd_is_accessible_reg(priv, gen, reg))
|
||||
return 0;
|
||||
|
||||
regmap_fields_read(gen->regs[reg], rsnd_mod_id(mod), &val);
|
||||
|
||||
dev_dbg(dev, "r %s - 0x%04d : %08x\n", rsnd_mod_name(mod), reg, val);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
void rsnd_write(struct rsnd_priv *priv,
|
||||
struct rsnd_mod *mod,
|
||||
enum rsnd_reg reg, u32 data)
|
||||
{
|
||||
struct device *dev = rsnd_priv_to_dev(priv);
|
||||
struct rsnd_gen *gen = rsnd_priv_to_gen(priv);
|
||||
|
||||
if (!rsnd_is_accessible_reg(priv, gen, reg))
|
||||
return;
|
||||
|
||||
regmap_fields_write(gen->regs[reg], rsnd_mod_id(mod), data);
|
||||
|
||||
dev_dbg(dev, "w %s - 0x%04d : %08x\n", rsnd_mod_name(mod), reg, data);
|
||||
}
|
||||
|
||||
void rsnd_bset(struct rsnd_priv *priv, struct rsnd_mod *mod,
|
||||
enum rsnd_reg reg, u32 mask, u32 data)
|
||||
{
|
||||
struct device *dev = rsnd_priv_to_dev(priv);
|
||||
struct rsnd_gen *gen = rsnd_priv_to_gen(priv);
|
||||
|
||||
if (!rsnd_is_accessible_reg(priv, gen, reg))
|
||||
return;
|
||||
|
||||
regmap_fields_update_bits(gen->regs[reg], rsnd_mod_id(mod),
|
||||
mask, data);
|
||||
|
||||
dev_dbg(dev, "b %s - 0x%04d : %08x/%08x\n",
|
||||
rsnd_mod_name(mod), reg, data, mask);
|
||||
}
|
||||
|
||||
#define rsnd_gen_regmap_init(priv, id_size, reg_id, conf) \
|
||||
_rsnd_gen_regmap_init(priv, id_size, reg_id, conf, ARRAY_SIZE(conf))
|
||||
static int _rsnd_gen_regmap_init(struct rsnd_priv *priv,
|
||||
int id_size,
|
||||
int reg_id,
|
||||
struct rsnd_regmap_field_conf *conf,
|
||||
int conf_size)
|
||||
{
|
||||
struct platform_device *pdev = rsnd_priv_to_pdev(priv);
|
||||
struct rsnd_gen *gen = rsnd_priv_to_gen(priv);
|
||||
struct device *dev = rsnd_priv_to_dev(priv);
|
||||
struct resource *res;
|
||||
struct regmap_config regc;
|
||||
struct regmap_field *regs;
|
||||
struct regmap *regmap;
|
||||
struct reg_field regf;
|
||||
void __iomem *base;
|
||||
int i;
|
||||
|
||||
memset(®c, 0, sizeof(regc));
|
||||
regc.reg_bits = 32;
|
||||
regc.val_bits = 32;
|
||||
regc.reg_stride = 4;
|
||||
|
||||
res = platform_get_resource(pdev, IORESOURCE_MEM, reg_id);
|
||||
if (!res)
|
||||
return -ENODEV;
|
||||
|
||||
base = devm_ioremap_resource(dev, res);
|
||||
if (IS_ERR(base))
|
||||
return PTR_ERR(base);
|
||||
|
||||
regmap = devm_regmap_init_mmio(dev, base, ®c);
|
||||
if (IS_ERR(regmap))
|
||||
return PTR_ERR(regmap);
|
||||
|
||||
gen->base[reg_id] = base;
|
||||
gen->regmap[reg_id] = regmap;
|
||||
|
||||
for (i = 0; i < conf_size; i++) {
|
||||
|
||||
regf.reg = conf[i].reg_offset;
|
||||
regf.id_offset = conf[i].id_offset;
|
||||
regf.lsb = 0;
|
||||
regf.msb = 31;
|
||||
regf.id_size = id_size;
|
||||
|
||||
regs = devm_regmap_field_alloc(dev, regmap, regf);
|
||||
if (IS_ERR(regs))
|
||||
return PTR_ERR(regs);
|
||||
|
||||
gen->regs[conf[i].idx] = regs;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* DMA read/write register offset
|
||||
*
|
||||
* RSND_xxx_I_N for Audio DMAC input
|
||||
* RSND_xxx_O_N for Audio DMAC output
|
||||
* RSND_xxx_I_P for Audio DMAC peri peri input
|
||||
* RSND_xxx_O_P for Audio DMAC peri peri output
|
||||
*
|
||||
* ex) R-Car H2 case
|
||||
* mod / DMAC in / DMAC out / DMAC PP in / DMAC pp out
|
||||
* SSI : 0xec541000 / 0xec241008 / 0xec24100c
|
||||
* SSIU: 0xec541000 / 0xec100000 / 0xec100000 / 0xec400000 / 0xec400000
|
||||
* SCU : 0xec500000 / 0xec000000 / 0xec004000 / 0xec300000 / 0xec304000
|
||||
* CMD : 0xec500000 / / 0xec008000 0xec308000
|
||||
*/
|
||||
#define RDMA_SSI_I_N(addr, i) (addr ##_reg - 0x00300000 + (0x40 * i) + 0x8)
|
||||
#define RDMA_SSI_O_N(addr, i) (addr ##_reg - 0x00300000 + (0x40 * i) + 0xc)
|
||||
|
||||
#define RDMA_SSIU_I_N(addr, i) (addr ##_reg - 0x00441000 + (0x1000 * i))
|
||||
#define RDMA_SSIU_O_N(addr, i) (addr ##_reg - 0x00441000 + (0x1000 * i))
|
||||
|
||||
#define RDMA_SSIU_I_P(addr, i) (addr ##_reg - 0x00141000 + (0x1000 * i))
|
||||
#define RDMA_SSIU_O_P(addr, i) (addr ##_reg - 0x00141000 + (0x1000 * i))
|
||||
|
||||
#define RDMA_SRC_I_N(addr, i) (addr ##_reg - 0x00500000 + (0x400 * i))
|
||||
#define RDMA_SRC_O_N(addr, i) (addr ##_reg - 0x004fc000 + (0x400 * i))
|
||||
|
||||
#define RDMA_SRC_I_P(addr, i) (addr ##_reg - 0x00200000 + (0x400 * i))
|
||||
#define RDMA_SRC_O_P(addr, i) (addr ##_reg - 0x001fc000 + (0x400 * i))
|
||||
|
||||
#define RDMA_CMD_O_N(addr, i) (addr ##_reg - 0x004f8000 + (0x400 * i))
|
||||
#define RDMA_CMD_O_P(addr, i) (addr ##_reg - 0x001f8000 + (0x400 * i))
|
||||
|
||||
static dma_addr_t
|
||||
rsnd_gen2_dma_addr(struct rsnd_priv *priv,
|
||||
struct rsnd_mod *mod,
|
||||
int is_play, int is_from)
|
||||
{
|
||||
struct platform_device *pdev = rsnd_priv_to_pdev(priv);
|
||||
struct device *dev = rsnd_priv_to_dev(priv);
|
||||
struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
|
||||
dma_addr_t ssi_reg = platform_get_resource(pdev,
|
||||
IORESOURCE_MEM, RSND_GEN2_SSI)->start;
|
||||
dma_addr_t src_reg = platform_get_resource(pdev,
|
||||
IORESOURCE_MEM, RSND_GEN2_SCU)->start;
|
||||
int is_ssi = !!(rsnd_io_to_mod_ssi(io) == mod);
|
||||
int use_src = !!rsnd_io_to_mod_src(io);
|
||||
int use_dvc = !!rsnd_io_to_mod_dvc(io);
|
||||
int id = rsnd_mod_id(mod);
|
||||
struct dma_addr {
|
||||
dma_addr_t out_addr;
|
||||
dma_addr_t in_addr;
|
||||
} dma_addrs[3][2][3] = {
|
||||
/* SRC */
|
||||
{{{ 0, 0 },
|
||||
/* Capture */
|
||||
{ RDMA_SRC_O_N(src, id), RDMA_SRC_I_P(src, id) },
|
||||
{ RDMA_CMD_O_N(src, id), RDMA_SRC_I_P(src, id) } },
|
||||
/* Playback */
|
||||
{{ 0, 0, },
|
||||
{ RDMA_SRC_O_P(src, id), RDMA_SRC_I_N(src, id) },
|
||||
{ RDMA_CMD_O_P(src, id), RDMA_SRC_I_N(src, id) } }
|
||||
},
|
||||
/* SSI */
|
||||
/* Capture */
|
||||
{{{ RDMA_SSI_O_N(ssi, id), 0 },
|
||||
{ RDMA_SSIU_O_P(ssi, id), 0 },
|
||||
{ RDMA_SSIU_O_P(ssi, id), 0 } },
|
||||
/* Playback */
|
||||
{{ 0, RDMA_SSI_I_N(ssi, id) },
|
||||
{ 0, RDMA_SSIU_I_P(ssi, id) },
|
||||
{ 0, RDMA_SSIU_I_P(ssi, id) } }
|
||||
},
|
||||
/* SSIU */
|
||||
/* Capture */
|
||||
{{{ RDMA_SSIU_O_N(ssi, id), 0 },
|
||||
{ RDMA_SSIU_O_P(ssi, id), 0 },
|
||||
{ RDMA_SSIU_O_P(ssi, id), 0 } },
|
||||
/* Playback */
|
||||
{{ 0, RDMA_SSIU_I_N(ssi, id) },
|
||||
{ 0, RDMA_SSIU_I_P(ssi, id) },
|
||||
{ 0, RDMA_SSIU_I_P(ssi, id) } } },
|
||||
};
|
||||
|
||||
/* it shouldn't happen */
|
||||
if (use_dvc && !use_src)
|
||||
dev_err(dev, "DVC is selected without SRC\n");
|
||||
|
||||
/* use SSIU or SSI ? */
|
||||
if (is_ssi && (0 == strcmp(rsnd_mod_dma_name(mod), "ssiu")))
|
||||
is_ssi++;
|
||||
|
||||
return (is_from) ?
|
||||
dma_addrs[is_ssi][is_play][use_src + use_dvc].out_addr :
|
||||
dma_addrs[is_ssi][is_play][use_src + use_dvc].in_addr;
|
||||
}
|
||||
|
||||
dma_addr_t rsnd_gen_dma_addr(struct rsnd_priv *priv,
|
||||
struct rsnd_mod *mod,
|
||||
int is_play, int is_from)
|
||||
{
|
||||
/*
|
||||
* gen1 uses default DMA addr
|
||||
*/
|
||||
if (rsnd_is_gen1(priv))
|
||||
return 0;
|
||||
|
||||
if (!mod)
|
||||
return 0;
|
||||
|
||||
return rsnd_gen2_dma_addr(priv, mod, is_play, is_from);
|
||||
}
|
||||
|
||||
/*
|
||||
* Gen2
|
||||
*/
|
||||
static int rsnd_gen2_probe(struct platform_device *pdev,
|
||||
struct rsnd_priv *priv)
|
||||
{
|
||||
struct device *dev = rsnd_priv_to_dev(priv);
|
||||
struct rsnd_regmap_field_conf conf_ssiu[] = {
|
||||
RSND_GEN_S_REG(SSI_MODE0, 0x800),
|
||||
RSND_GEN_S_REG(SSI_MODE1, 0x804),
|
||||
/* FIXME: it needs SSI_MODE2/3 in the future */
|
||||
RSND_GEN_M_REG(SSI_BUSIF_MODE, 0x0, 0x80),
|
||||
RSND_GEN_M_REG(SSI_BUSIF_ADINR, 0x4, 0x80),
|
||||
RSND_GEN_M_REG(BUSIF_DALIGN, 0x8, 0x80),
|
||||
RSND_GEN_M_REG(SSI_CTRL, 0x10, 0x80),
|
||||
RSND_GEN_M_REG(INT_ENABLE, 0x18, 0x80),
|
||||
};
|
||||
struct rsnd_regmap_field_conf conf_scu[] = {
|
||||
RSND_GEN_M_REG(SRC_BUSIF_MODE, 0x0, 0x20),
|
||||
RSND_GEN_M_REG(SRC_ROUTE_MODE0, 0xc, 0x20),
|
||||
RSND_GEN_M_REG(SRC_CTRL, 0x10, 0x20),
|
||||
RSND_GEN_M_REG(CMD_ROUTE_SLCT, 0x18c, 0x20),
|
||||
RSND_GEN_M_REG(CMD_CTRL, 0x190, 0x20),
|
||||
RSND_GEN_M_REG(SRC_SWRSR, 0x200, 0x40),
|
||||
RSND_GEN_M_REG(SRC_SRCIR, 0x204, 0x40),
|
||||
RSND_GEN_M_REG(SRC_ADINR, 0x214, 0x40),
|
||||
RSND_GEN_M_REG(SRC_IFSCR, 0x21c, 0x40),
|
||||
RSND_GEN_M_REG(SRC_IFSVR, 0x220, 0x40),
|
||||
RSND_GEN_M_REG(SRC_SRCCR, 0x224, 0x40),
|
||||
RSND_GEN_M_REG(SRC_BSDSR, 0x22c, 0x40),
|
||||
RSND_GEN_M_REG(SRC_BSISR, 0x238, 0x40),
|
||||
RSND_GEN_M_REG(DVC_SWRSR, 0xe00, 0x100),
|
||||
RSND_GEN_M_REG(DVC_DVUIR, 0xe04, 0x100),
|
||||
RSND_GEN_M_REG(DVC_ADINR, 0xe08, 0x100),
|
||||
RSND_GEN_M_REG(DVC_DVUCR, 0xe10, 0x100),
|
||||
RSND_GEN_M_REG(DVC_ZCMCR, 0xe14, 0x100),
|
||||
RSND_GEN_M_REG(DVC_VOL0R, 0xe28, 0x100),
|
||||
RSND_GEN_M_REG(DVC_VOL1R, 0xe2c, 0x100),
|
||||
RSND_GEN_M_REG(DVC_DVUER, 0xe48, 0x100),
|
||||
};
|
||||
struct rsnd_regmap_field_conf conf_adg[] = {
|
||||
RSND_GEN_S_REG(BRRA, 0x00),
|
||||
RSND_GEN_S_REG(BRRB, 0x04),
|
||||
RSND_GEN_S_REG(SSICKR, 0x08),
|
||||
RSND_GEN_S_REG(AUDIO_CLK_SEL0, 0x0c),
|
||||
RSND_GEN_S_REG(AUDIO_CLK_SEL1, 0x10),
|
||||
RSND_GEN_S_REG(AUDIO_CLK_SEL2, 0x14),
|
||||
RSND_GEN_S_REG(DIV_EN, 0x30),
|
||||
RSND_GEN_S_REG(SRCIN_TIMSEL0, 0x34),
|
||||
RSND_GEN_S_REG(SRCIN_TIMSEL1, 0x38),
|
||||
RSND_GEN_S_REG(SRCIN_TIMSEL2, 0x3c),
|
||||
RSND_GEN_S_REG(SRCIN_TIMSEL3, 0x40),
|
||||
RSND_GEN_S_REG(SRCIN_TIMSEL4, 0x44),
|
||||
RSND_GEN_S_REG(SRCOUT_TIMSEL0, 0x48),
|
||||
RSND_GEN_S_REG(SRCOUT_TIMSEL1, 0x4c),
|
||||
RSND_GEN_S_REG(SRCOUT_TIMSEL2, 0x50),
|
||||
RSND_GEN_S_REG(SRCOUT_TIMSEL3, 0x54),
|
||||
RSND_GEN_S_REG(SRCOUT_TIMSEL4, 0x58),
|
||||
RSND_GEN_S_REG(CMDOUT_TIMSEL, 0x5c),
|
||||
};
|
||||
struct rsnd_regmap_field_conf conf_ssi[] = {
|
||||
RSND_GEN_M_REG(SSICR, 0x00, 0x40),
|
||||
RSND_GEN_M_REG(SSISR, 0x04, 0x40),
|
||||
RSND_GEN_M_REG(SSITDR, 0x08, 0x40),
|
||||
RSND_GEN_M_REG(SSIRDR, 0x0c, 0x40),
|
||||
RSND_GEN_M_REG(SSIWSR, 0x20, 0x40),
|
||||
};
|
||||
int ret_ssiu;
|
||||
int ret_scu;
|
||||
int ret_adg;
|
||||
int ret_ssi;
|
||||
|
||||
ret_ssiu = rsnd_gen_regmap_init(priv, 10, RSND_GEN2_SSIU, conf_ssiu);
|
||||
ret_scu = rsnd_gen_regmap_init(priv, 10, RSND_GEN2_SCU, conf_scu);
|
||||
ret_adg = rsnd_gen_regmap_init(priv, 10, RSND_GEN2_ADG, conf_adg);
|
||||
ret_ssi = rsnd_gen_regmap_init(priv, 10, RSND_GEN2_SSI, conf_ssi);
|
||||
if (ret_ssiu < 0 ||
|
||||
ret_scu < 0 ||
|
||||
ret_adg < 0 ||
|
||||
ret_ssi < 0)
|
||||
return ret_ssiu | ret_scu | ret_adg | ret_ssi;
|
||||
|
||||
dev_dbg(dev, "Gen2 is probed\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Gen1
|
||||
*/
|
||||
|
||||
static int rsnd_gen1_probe(struct platform_device *pdev,
|
||||
struct rsnd_priv *priv)
|
||||
{
|
||||
struct device *dev = rsnd_priv_to_dev(priv);
|
||||
struct rsnd_regmap_field_conf conf_sru[] = {
|
||||
RSND_GEN_S_REG(SRC_ROUTE_SEL, 0x00),
|
||||
RSND_GEN_S_REG(SRC_TMG_SEL0, 0x08),
|
||||
RSND_GEN_S_REG(SRC_TMG_SEL1, 0x0c),
|
||||
RSND_GEN_S_REG(SRC_TMG_SEL2, 0x10),
|
||||
RSND_GEN_S_REG(SRC_ROUTE_CTRL, 0xc0),
|
||||
RSND_GEN_S_REG(SSI_MODE0, 0xD0),
|
||||
RSND_GEN_S_REG(SSI_MODE1, 0xD4),
|
||||
RSND_GEN_M_REG(SRC_BUSIF_MODE, 0x20, 0x4),
|
||||
RSND_GEN_M_REG(SRC_ROUTE_MODE0, 0x50, 0x8),
|
||||
RSND_GEN_M_REG(SRC_SWRSR, 0x200, 0x40),
|
||||
RSND_GEN_M_REG(SRC_SRCIR, 0x204, 0x40),
|
||||
RSND_GEN_M_REG(SRC_ADINR, 0x214, 0x40),
|
||||
RSND_GEN_M_REG(SRC_IFSCR, 0x21c, 0x40),
|
||||
RSND_GEN_M_REG(SRC_IFSVR, 0x220, 0x40),
|
||||
RSND_GEN_M_REG(SRC_SRCCR, 0x224, 0x40),
|
||||
RSND_GEN_M_REG(SRC_MNFSR, 0x228, 0x40),
|
||||
};
|
||||
struct rsnd_regmap_field_conf conf_adg[] = {
|
||||
RSND_GEN_S_REG(BRRA, 0x00),
|
||||
RSND_GEN_S_REG(BRRB, 0x04),
|
||||
RSND_GEN_S_REG(SSICKR, 0x08),
|
||||
RSND_GEN_S_REG(AUDIO_CLK_SEL0, 0x0c),
|
||||
RSND_GEN_S_REG(AUDIO_CLK_SEL1, 0x10),
|
||||
RSND_GEN_S_REG(AUDIO_CLK_SEL3, 0x18),
|
||||
RSND_GEN_S_REG(AUDIO_CLK_SEL4, 0x1c),
|
||||
RSND_GEN_S_REG(AUDIO_CLK_SEL5, 0x20),
|
||||
};
|
||||
struct rsnd_regmap_field_conf conf_ssi[] = {
|
||||
RSND_GEN_M_REG(SSICR, 0x00, 0x40),
|
||||
RSND_GEN_M_REG(SSISR, 0x04, 0x40),
|
||||
RSND_GEN_M_REG(SSITDR, 0x08, 0x40),
|
||||
RSND_GEN_M_REG(SSIRDR, 0x0c, 0x40),
|
||||
RSND_GEN_M_REG(SSIWSR, 0x20, 0x40),
|
||||
};
|
||||
int ret_sru;
|
||||
int ret_adg;
|
||||
int ret_ssi;
|
||||
|
||||
ret_sru = rsnd_gen_regmap_init(priv, 9, RSND_GEN1_SRU, conf_sru);
|
||||
ret_adg = rsnd_gen_regmap_init(priv, 9, RSND_GEN1_ADG, conf_adg);
|
||||
ret_ssi = rsnd_gen_regmap_init(priv, 9, RSND_GEN1_SSI, conf_ssi);
|
||||
if (ret_sru < 0 ||
|
||||
ret_adg < 0 ||
|
||||
ret_ssi < 0)
|
||||
return ret_sru | ret_adg | ret_ssi;
|
||||
|
||||
dev_dbg(dev, "Gen1 is probed\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Gen
|
||||
*/
|
||||
static void rsnd_of_parse_gen(struct platform_device *pdev,
|
||||
const struct rsnd_of_data *of_data,
|
||||
struct rsnd_priv *priv)
|
||||
{
|
||||
struct rcar_snd_info *info = priv->info;
|
||||
|
||||
if (!of_data)
|
||||
return;
|
||||
|
||||
info->flags = of_data->flags;
|
||||
}
|
||||
|
||||
int rsnd_gen_probe(struct platform_device *pdev,
|
||||
const struct rsnd_of_data *of_data,
|
||||
struct rsnd_priv *priv)
|
||||
{
|
||||
struct device *dev = rsnd_priv_to_dev(priv);
|
||||
struct rsnd_gen *gen;
|
||||
int ret;
|
||||
|
||||
rsnd_of_parse_gen(pdev, of_data, priv);
|
||||
|
||||
gen = devm_kzalloc(dev, sizeof(*gen), GFP_KERNEL);
|
||||
if (!gen) {
|
||||
dev_err(dev, "GEN allocate failed\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
priv->gen = gen;
|
||||
|
||||
ret = -ENODEV;
|
||||
if (rsnd_is_gen1(priv))
|
||||
ret = rsnd_gen1_probe(pdev, priv);
|
||||
else if (rsnd_is_gen2(priv))
|
||||
ret = rsnd_gen2_probe(pdev, priv);
|
||||
|
||||
if (ret < 0)
|
||||
dev_err(dev, "unknown generation R-Car sound device\n");
|
||||
|
||||
return ret;
|
||||
}
|
||||
427
sound/soc/sh/rcar/rsnd.h
Normal file
427
sound/soc/sh/rcar/rsnd.h
Normal file
|
|
@ -0,0 +1,427 @@
|
|||
/*
|
||||
* 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/of_device.h>
|
||||
#include <linux/of_irq.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/SSIU */
|
||||
RSND_REG_SSI_MODE0,
|
||||
RSND_REG_SSI_MODE1,
|
||||
RSND_REG_SRC_BUSIF_MODE,
|
||||
RSND_REG_SRC_ROUTE_MODE0,
|
||||
RSND_REG_SRC_SWRSR,
|
||||
RSND_REG_SRC_SRCIR,
|
||||
RSND_REG_SRC_ADINR,
|
||||
RSND_REG_SRC_IFSCR,
|
||||
RSND_REG_SRC_IFSVR,
|
||||
RSND_REG_SRC_SRCCR,
|
||||
RSND_REG_CMD_ROUTE_SLCT,
|
||||
RSND_REG_DVC_SWRSR,
|
||||
RSND_REG_DVC_DVUIR,
|
||||
RSND_REG_DVC_ADINR,
|
||||
RSND_REG_DVC_DVUCR,
|
||||
RSND_REG_DVC_ZCMCR,
|
||||
RSND_REG_DVC_VOL0R,
|
||||
RSND_REG_DVC_VOL1R,
|
||||
RSND_REG_DVC_DVUER,
|
||||
|
||||
/* ADG */
|
||||
RSND_REG_BRRA,
|
||||
RSND_REG_BRRB,
|
||||
RSND_REG_SSICKR,
|
||||
RSND_REG_AUDIO_CLK_SEL0,
|
||||
RSND_REG_AUDIO_CLK_SEL1,
|
||||
|
||||
/* SSI */
|
||||
RSND_REG_SSICR,
|
||||
RSND_REG_SSISR,
|
||||
RSND_REG_SSITDR,
|
||||
RSND_REG_SSIRDR,
|
||||
RSND_REG_SSIWSR,
|
||||
|
||||
/* SHARE see below */
|
||||
RSND_REG_SHARE01,
|
||||
RSND_REG_SHARE02,
|
||||
RSND_REG_SHARE03,
|
||||
RSND_REG_SHARE04,
|
||||
RSND_REG_SHARE05,
|
||||
RSND_REG_SHARE06,
|
||||
RSND_REG_SHARE07,
|
||||
RSND_REG_SHARE08,
|
||||
RSND_REG_SHARE09,
|
||||
RSND_REG_SHARE10,
|
||||
RSND_REG_SHARE11,
|
||||
RSND_REG_SHARE12,
|
||||
RSND_REG_SHARE13,
|
||||
RSND_REG_SHARE14,
|
||||
RSND_REG_SHARE15,
|
||||
RSND_REG_SHARE16,
|
||||
RSND_REG_SHARE17,
|
||||
RSND_REG_SHARE18,
|
||||
RSND_REG_SHARE19,
|
||||
RSND_REG_SHARE20,
|
||||
RSND_REG_SHARE21,
|
||||
RSND_REG_SHARE22,
|
||||
|
||||
RSND_REG_MAX,
|
||||
};
|
||||
|
||||
/* Gen1 only */
|
||||
#define RSND_REG_SRC_ROUTE_SEL RSND_REG_SHARE01
|
||||
#define RSND_REG_SRC_TMG_SEL0 RSND_REG_SHARE02
|
||||
#define RSND_REG_SRC_TMG_SEL1 RSND_REG_SHARE03
|
||||
#define RSND_REG_SRC_TMG_SEL2 RSND_REG_SHARE04
|
||||
#define RSND_REG_SRC_ROUTE_CTRL RSND_REG_SHARE05
|
||||
#define RSND_REG_SRC_MNFSR RSND_REG_SHARE06
|
||||
#define RSND_REG_AUDIO_CLK_SEL3 RSND_REG_SHARE07
|
||||
#define RSND_REG_AUDIO_CLK_SEL4 RSND_REG_SHARE08
|
||||
#define RSND_REG_AUDIO_CLK_SEL5 RSND_REG_SHARE09
|
||||
|
||||
/* Gen2 only */
|
||||
#define RSND_REG_SRC_CTRL RSND_REG_SHARE01
|
||||
#define RSND_REG_SSI_CTRL RSND_REG_SHARE02
|
||||
#define RSND_REG_SSI_BUSIF_MODE RSND_REG_SHARE03
|
||||
#define RSND_REG_SSI_BUSIF_ADINR RSND_REG_SHARE04
|
||||
#define RSND_REG_INT_ENABLE RSND_REG_SHARE05
|
||||
#define RSND_REG_SRC_BSDSR RSND_REG_SHARE06
|
||||
#define RSND_REG_SRC_BSISR RSND_REG_SHARE07
|
||||
#define RSND_REG_DIV_EN RSND_REG_SHARE08
|
||||
#define RSND_REG_SRCIN_TIMSEL0 RSND_REG_SHARE09
|
||||
#define RSND_REG_SRCIN_TIMSEL1 RSND_REG_SHARE10
|
||||
#define RSND_REG_SRCIN_TIMSEL2 RSND_REG_SHARE11
|
||||
#define RSND_REG_SRCIN_TIMSEL3 RSND_REG_SHARE12
|
||||
#define RSND_REG_SRCIN_TIMSEL4 RSND_REG_SHARE13
|
||||
#define RSND_REG_SRCOUT_TIMSEL0 RSND_REG_SHARE14
|
||||
#define RSND_REG_SRCOUT_TIMSEL1 RSND_REG_SHARE15
|
||||
#define RSND_REG_SRCOUT_TIMSEL2 RSND_REG_SHARE16
|
||||
#define RSND_REG_SRCOUT_TIMSEL3 RSND_REG_SHARE17
|
||||
#define RSND_REG_SRCOUT_TIMSEL4 RSND_REG_SHARE18
|
||||
#define RSND_REG_AUDIO_CLK_SEL2 RSND_REG_SHARE19
|
||||
#define RSND_REG_CMD_CTRL RSND_REG_SHARE20
|
||||
#define RSND_REG_CMDOUT_TIMSEL RSND_REG_SHARE21
|
||||
#define RSND_REG_BUSIF_DALIGN RSND_REG_SHARE22
|
||||
|
||||
struct rsnd_of_data;
|
||||
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)
|
||||
|
||||
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);
|
||||
u32 rsnd_get_adinr(struct rsnd_mod *mod);
|
||||
|
||||
/*
|
||||
* R-Car DMA
|
||||
*/
|
||||
struct rsnd_dma {
|
||||
struct sh_dmae_slave slave;
|
||||
struct dma_chan *chan;
|
||||
enum dma_transfer_direction dir;
|
||||
dma_addr_t addr;
|
||||
};
|
||||
|
||||
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);
|
||||
void rsnd_dma_quit(struct rsnd_priv *priv,
|
||||
struct rsnd_dma *dma);
|
||||
|
||||
|
||||
/*
|
||||
* R-Car sound mod
|
||||
*/
|
||||
enum rsnd_mod_type {
|
||||
RSND_MOD_SRC = 0,
|
||||
RSND_MOD_SSI,
|
||||
RSND_MOD_DVC,
|
||||
RSND_MOD_MAX,
|
||||
};
|
||||
|
||||
struct rsnd_mod_ops {
|
||||
char *name;
|
||||
char* (*dma_name)(struct rsnd_mod *mod);
|
||||
int (*probe)(struct rsnd_mod *mod,
|
||||
struct rsnd_dai *rdai);
|
||||
int (*remove)(struct rsnd_mod *mod,
|
||||
struct rsnd_dai *rdai);
|
||||
int (*init)(struct rsnd_mod *mod,
|
||||
struct rsnd_dai *rdai);
|
||||
int (*quit)(struct rsnd_mod *mod,
|
||||
struct rsnd_dai *rdai);
|
||||
int (*start)(struct rsnd_mod *mod,
|
||||
struct rsnd_dai *rdai);
|
||||
int (*stop)(struct rsnd_mod *mod,
|
||||
struct rsnd_dai *rdai);
|
||||
int (*pcm_new)(struct rsnd_mod *mod,
|
||||
struct rsnd_dai *rdai,
|
||||
struct snd_soc_pcm_runtime *rtd);
|
||||
};
|
||||
|
||||
struct rsnd_dai_stream;
|
||||
struct rsnd_mod {
|
||||
int id;
|
||||
enum rsnd_mod_type type;
|
||||
struct rsnd_priv *priv;
|
||||
struct rsnd_mod_ops *ops;
|
||||
struct rsnd_dma dma;
|
||||
struct rsnd_dai_stream *io;
|
||||
};
|
||||
|
||||
#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_to_io(mod) ((mod)->io)
|
||||
#define rsnd_mod_id(mod) ((mod)->id)
|
||||
|
||||
void rsnd_mod_init(struct rsnd_priv *priv,
|
||||
struct rsnd_mod *mod,
|
||||
struct rsnd_mod_ops *ops,
|
||||
enum rsnd_mod_type type,
|
||||
int id);
|
||||
char *rsnd_mod_name(struct rsnd_mod *mod);
|
||||
char *rsnd_mod_dma_name(struct rsnd_mod *mod);
|
||||
|
||||
/*
|
||||
* R-Car sound DAI
|
||||
*/
|
||||
#define RSND_DAI_NAME_SIZE 16
|
||||
struct rsnd_dai_stream {
|
||||
struct snd_pcm_substream *substream;
|
||||
struct rsnd_mod *mod[RSND_MOD_MAX];
|
||||
struct rsnd_dai_path_info *info; /* rcar_snd.h */
|
||||
int byte_pos;
|
||||
int period_pos;
|
||||
int byte_per_period;
|
||||
int next_period_byte;
|
||||
};
|
||||
#define rsnd_io_to_mod_ssi(io) ((io)->mod[RSND_MOD_SSI])
|
||||
#define rsnd_io_to_mod_src(io) ((io)->mod[RSND_MOD_SRC])
|
||||
#define rsnd_io_to_mod_dvc(io) ((io)->mod[RSND_MOD_DVC])
|
||||
|
||||
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;
|
||||
|
||||
unsigned int clk_master:1;
|
||||
unsigned int bit_clk_inv:1;
|
||||
unsigned int frm_clk_inv:1;
|
||||
unsigned int sys_delay:1;
|
||||
unsigned int data_alignment:1;
|
||||
};
|
||||
|
||||
#define rsnd_rdai_nr(priv) ((priv)->rdai_nr)
|
||||
#define for_each_rsnd_dai(rdai, priv, i) \
|
||||
for (i = 0; \
|
||||
(i < rsnd_rdai_nr(priv)) && \
|
||||
((rdai) = rsnd_dai_get(priv, i)); \
|
||||
i++)
|
||||
|
||||
struct rsnd_dai *rsnd_dai_get(struct rsnd_priv *priv, int id);
|
||||
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);
|
||||
#define rsnd_dai_is_clk_master(rdai) ((rdai)->clk_master)
|
||||
|
||||
/*
|
||||
* R-Car Gen1/Gen2
|
||||
*/
|
||||
int rsnd_gen_probe(struct platform_device *pdev,
|
||||
const struct rsnd_of_data *of_data,
|
||||
struct rsnd_priv *priv);
|
||||
void __iomem *rsnd_gen_reg_get(struct rsnd_priv *priv,
|
||||
struct rsnd_mod *mod,
|
||||
enum rsnd_reg reg);
|
||||
dma_addr_t rsnd_gen_dma_addr(struct rsnd_priv *priv,
|
||||
struct rsnd_mod *mod,
|
||||
int is_play, int is_from);
|
||||
|
||||
#define rsnd_is_gen1(s) (((s)->info->flags & RSND_GEN_MASK) == RSND_GEN1)
|
||||
#define rsnd_is_gen2(s) (((s)->info->flags & RSND_GEN_MASK) == 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,
|
||||
const struct rsnd_of_data *of_data,
|
||||
struct rsnd_priv *priv);
|
||||
int rsnd_adg_set_convert_clk_gen1(struct rsnd_priv *priv,
|
||||
struct rsnd_mod *mod,
|
||||
unsigned int src_rate,
|
||||
unsigned int dst_rate);
|
||||
int rsnd_adg_set_convert_clk_gen2(struct rsnd_mod *mod,
|
||||
struct rsnd_dai *rdai,
|
||||
struct rsnd_dai_stream *io,
|
||||
unsigned int src_rate,
|
||||
unsigned int dst_rate);
|
||||
int rsnd_adg_set_convert_timing_gen2(struct rsnd_mod *mod,
|
||||
struct rsnd_dai *rdai,
|
||||
struct rsnd_dai_stream *io);
|
||||
int rsnd_adg_set_cmd_timsel_gen2(struct rsnd_dai *rdai,
|
||||
struct rsnd_mod *mod,
|
||||
struct rsnd_dai_stream *io);
|
||||
|
||||
/*
|
||||
* R-Car sound priv
|
||||
*/
|
||||
struct rsnd_of_data {
|
||||
u32 flags;
|
||||
};
|
||||
|
||||
struct rsnd_priv {
|
||||
|
||||
struct platform_device *pdev;
|
||||
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_src_probe()
|
||||
*/
|
||||
void *src;
|
||||
int src_nr;
|
||||
|
||||
/*
|
||||
* below value will be filled on rsnd_adg_probe()
|
||||
*/
|
||||
void *adg;
|
||||
|
||||
/*
|
||||
* below value will be filled on rsnd_ssi_probe()
|
||||
*/
|
||||
void *ssi;
|
||||
int ssi_nr;
|
||||
|
||||
/*
|
||||
* below value will be filled on rsnd_dvc_probe()
|
||||
*/
|
||||
void *dvc;
|
||||
int dvc_nr;
|
||||
|
||||
/*
|
||||
* below value will be filled on rsnd_dai_probe()
|
||||
*/
|
||||
struct snd_soc_dai_driver *daidrv;
|
||||
struct rsnd_dai *rdai;
|
||||
int rdai_nr;
|
||||
};
|
||||
|
||||
#define rsnd_priv_to_pdev(priv) ((priv)->pdev)
|
||||
#define rsnd_priv_to_dev(priv) (&(rsnd_priv_to_pdev(priv)->dev))
|
||||
#define rsnd_priv_to_info(priv) ((priv)->info)
|
||||
#define rsnd_lock(priv, flags) spin_lock_irqsave(&priv->lock, flags)
|
||||
#define rsnd_unlock(priv, flags) spin_unlock_irqrestore(&priv->lock, flags)
|
||||
|
||||
#define rsnd_info_is_playback(priv, type) \
|
||||
({ \
|
||||
struct rcar_snd_info *info = rsnd_priv_to_info(priv); \
|
||||
int i, is_play = 0; \
|
||||
for (i = 0; i < info->dai_info_nr; i++) { \
|
||||
if (info->dai_info[i].playback.type == (type)->info) { \
|
||||
is_play = 1; \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
is_play; \
|
||||
})
|
||||
|
||||
/*
|
||||
* R-Car SRC
|
||||
*/
|
||||
int rsnd_src_probe(struct platform_device *pdev,
|
||||
const struct rsnd_of_data *of_data,
|
||||
struct rsnd_priv *priv);
|
||||
struct rsnd_mod *rsnd_src_mod_get(struct rsnd_priv *priv, int id);
|
||||
unsigned int rsnd_src_get_ssi_rate(struct rsnd_priv *priv,
|
||||
struct rsnd_dai_stream *io,
|
||||
struct snd_pcm_runtime *runtime);
|
||||
int rsnd_src_ssiu_start(struct rsnd_mod *ssi_mod,
|
||||
struct rsnd_dai *rdai,
|
||||
int use_busif);
|
||||
int rsnd_src_ssiu_stop(struct rsnd_mod *ssi_mod,
|
||||
struct rsnd_dai *rdai,
|
||||
int use_busif);
|
||||
int rsnd_src_enable_ssi_irq(struct rsnd_mod *ssi_mod,
|
||||
struct rsnd_dai *rdai);
|
||||
|
||||
#define rsnd_src_nr(priv) ((priv)->src_nr)
|
||||
|
||||
/*
|
||||
* R-Car SSI
|
||||
*/
|
||||
int rsnd_ssi_probe(struct platform_device *pdev,
|
||||
const struct rsnd_of_data *of_data,
|
||||
struct rsnd_priv *priv);
|
||||
struct rsnd_mod *rsnd_ssi_mod_get(struct rsnd_priv *priv, int id);
|
||||
int rsnd_ssi_is_pin_sharing(struct rsnd_mod *mod);
|
||||
|
||||
/*
|
||||
* R-Car DVC
|
||||
*/
|
||||
int rsnd_dvc_probe(struct platform_device *pdev,
|
||||
const struct rsnd_of_data *of_data,
|
||||
struct rsnd_priv *priv);
|
||||
void rsnd_dvc_remove(struct platform_device *pdev,
|
||||
struct rsnd_priv *priv);
|
||||
struct rsnd_mod *rsnd_dvc_mod_get(struct rsnd_priv *priv, int id);
|
||||
|
||||
#define rsnd_dvc_nr(priv) ((priv)->dvc_nr)
|
||||
|
||||
|
||||
#endif
|
||||
753
sound/soc/sh/rcar/src.c
Normal file
753
sound/soc/sh/rcar/src.c
Normal file
|
|
@ -0,0 +1,753 @@
|
|||
/*
|
||||
* Renesas R-Car SRC 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"
|
||||
|
||||
#define SRC_NAME "src"
|
||||
|
||||
struct rsnd_src {
|
||||
struct rsnd_src_platform_info *info; /* rcar_snd.h */
|
||||
struct rsnd_mod mod;
|
||||
struct clk *clk;
|
||||
};
|
||||
|
||||
#define RSND_SRC_NAME_SIZE 16
|
||||
|
||||
#define rsnd_src_convert_rate(p) ((p)->info->convert_rate)
|
||||
#define rsnd_mod_to_src(_mod) \
|
||||
container_of((_mod), struct rsnd_src, mod)
|
||||
#define rsnd_src_dma_available(src) \
|
||||
rsnd_dma_available(rsnd_mod_to_dma(&(src)->mod))
|
||||
|
||||
#define for_each_rsnd_src(pos, priv, i) \
|
||||
for ((i) = 0; \
|
||||
((i) < rsnd_src_nr(priv)) && \
|
||||
((pos) = (struct rsnd_src *)(priv)->src + i); \
|
||||
i++)
|
||||
|
||||
|
||||
/*
|
||||
* image of SRC (Sampling Rate Converter)
|
||||
*
|
||||
* 96kHz <-> +-----+ 48kHz +-----+ 48kHz +-------+
|
||||
* 48kHz <-> | SRC | <------> | SSI | <-----> | codec |
|
||||
* 44.1kHz <-> +-----+ +-----+ +-------+
|
||||
* ...
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* src.c is caring...
|
||||
*
|
||||
* Gen1
|
||||
*
|
||||
* [mem] -> [SRU] -> [SSI]
|
||||
* |--------|
|
||||
*
|
||||
* Gen2
|
||||
*
|
||||
* [mem] -> [SRC] -> [SSIU] -> [SSI]
|
||||
* |-----------------|
|
||||
*/
|
||||
|
||||
/*
|
||||
* How to use SRC bypass mode for debugging
|
||||
*
|
||||
* SRC has bypass mode, and it is useful for debugging.
|
||||
* In Gen2 case,
|
||||
* SRCm_MODE controls whether SRC is used or not
|
||||
* SSI_MODE0 controls whether SSIU which receives SRC data
|
||||
* is used or not.
|
||||
* Both SRCm_MODE/SSI_MODE0 settings are needed if you use SRC,
|
||||
* but SRC bypass mode needs SSI_MODE0 only.
|
||||
*
|
||||
* This driver request
|
||||
* struct rsnd_src_platform_info {
|
||||
* u32 convert_rate;
|
||||
* int dma_id;
|
||||
* }
|
||||
*
|
||||
* rsnd_src_convert_rate() indicates
|
||||
* above convert_rate, and it controls
|
||||
* whether SRC is used or not.
|
||||
*
|
||||
* ex) doesn't use SRC
|
||||
* static struct rsnd_dai_platform_info rsnd_dai = {
|
||||
* .playback = { .ssi = &rsnd_ssi[0], },
|
||||
* };
|
||||
*
|
||||
* ex) uses SRC
|
||||
* static struct rsnd_src_platform_info rsnd_src[] = {
|
||||
* RSND_SCU(48000, 0),
|
||||
* ...
|
||||
* };
|
||||
* static struct rsnd_dai_platform_info rsnd_dai = {
|
||||
* .playback = { .ssi = &rsnd_ssi[0], .src = &rsnd_src[0] },
|
||||
* };
|
||||
*
|
||||
* ex) uses SRC bypass mode
|
||||
* static struct rsnd_src_platform_info rsnd_src[] = {
|
||||
* RSND_SCU(0, 0),
|
||||
* ...
|
||||
* };
|
||||
* static struct rsnd_dai_platform_info rsnd_dai = {
|
||||
* .playback = { .ssi = &rsnd_ssi[0], .src = &rsnd_src[0] },
|
||||
* };
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Gen1/Gen2 common functions
|
||||
*/
|
||||
int rsnd_src_ssiu_start(struct rsnd_mod *ssi_mod,
|
||||
struct rsnd_dai *rdai,
|
||||
int use_busif)
|
||||
{
|
||||
struct rsnd_dai_stream *io = rsnd_mod_to_io(ssi_mod);
|
||||
struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
|
||||
int ssi_id = rsnd_mod_id(ssi_mod);
|
||||
|
||||
/*
|
||||
* SSI_MODE0
|
||||
*/
|
||||
rsnd_mod_bset(ssi_mod, SSI_MODE0, (1 << ssi_id),
|
||||
!use_busif << ssi_id);
|
||||
|
||||
/*
|
||||
* SSI_MODE1
|
||||
*/
|
||||
if (rsnd_ssi_is_pin_sharing(ssi_mod)) {
|
||||
int shift = -1;
|
||||
switch (ssi_id) {
|
||||
case 1:
|
||||
shift = 0;
|
||||
break;
|
||||
case 2:
|
||||
shift = 2;
|
||||
break;
|
||||
case 4:
|
||||
shift = 16;
|
||||
break;
|
||||
}
|
||||
|
||||
if (shift >= 0)
|
||||
rsnd_mod_bset(ssi_mod, SSI_MODE1,
|
||||
0x3 << shift,
|
||||
rsnd_dai_is_clk_master(rdai) ?
|
||||
0x2 << shift : 0x1 << shift);
|
||||
}
|
||||
|
||||
/*
|
||||
* DMA settings for SSIU
|
||||
*/
|
||||
if (use_busif) {
|
||||
u32 val = 0x76543210;
|
||||
u32 mask = ~0;
|
||||
|
||||
rsnd_mod_write(ssi_mod, SSI_BUSIF_ADINR,
|
||||
rsnd_get_adinr(ssi_mod));
|
||||
rsnd_mod_write(ssi_mod, SSI_BUSIF_MODE, 1);
|
||||
rsnd_mod_write(ssi_mod, SSI_CTRL, 0x1);
|
||||
|
||||
mask <<= runtime->channels * 4;
|
||||
val = val & mask;
|
||||
|
||||
switch (runtime->sample_bits) {
|
||||
case 16:
|
||||
val |= 0x67452301 & ~mask;
|
||||
break;
|
||||
case 32:
|
||||
val |= 0x76543210 & ~mask;
|
||||
break;
|
||||
}
|
||||
rsnd_mod_write(ssi_mod, BUSIF_DALIGN, val);
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rsnd_src_ssiu_stop(struct rsnd_mod *ssi_mod,
|
||||
struct rsnd_dai *rdai,
|
||||
int use_busif)
|
||||
{
|
||||
/*
|
||||
* DMA settings for SSIU
|
||||
*/
|
||||
if (use_busif)
|
||||
rsnd_mod_write(ssi_mod, SSI_CTRL, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rsnd_src_enable_ssi_irq(struct rsnd_mod *ssi_mod,
|
||||
struct rsnd_dai *rdai)
|
||||
{
|
||||
struct rsnd_priv *priv = rsnd_mod_to_priv(ssi_mod);
|
||||
|
||||
/* enable PIO interrupt if Gen2 */
|
||||
if (rsnd_is_gen2(priv))
|
||||
rsnd_mod_write(ssi_mod, INT_ENABLE, 0x0f000000);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int rsnd_src_get_ssi_rate(struct rsnd_priv *priv,
|
||||
struct rsnd_dai_stream *io,
|
||||
struct snd_pcm_runtime *runtime)
|
||||
{
|
||||
struct rsnd_mod *src_mod = rsnd_io_to_mod_src(io);
|
||||
struct rsnd_src *src;
|
||||
unsigned int rate = 0;
|
||||
|
||||
if (src_mod) {
|
||||
src = rsnd_mod_to_src(src_mod);
|
||||
|
||||
/*
|
||||
* return convert rate if SRC is used,
|
||||
* otherwise, return runtime->rate as usual
|
||||
*/
|
||||
rate = rsnd_src_convert_rate(src);
|
||||
}
|
||||
|
||||
if (!rate)
|
||||
rate = runtime->rate;
|
||||
|
||||
return rate;
|
||||
}
|
||||
|
||||
static int rsnd_src_set_convert_rate(struct rsnd_mod *mod,
|
||||
struct rsnd_dai *rdai)
|
||||
{
|
||||
struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
|
||||
struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
|
||||
struct rsnd_src *src = rsnd_mod_to_src(mod);
|
||||
u32 convert_rate = rsnd_src_convert_rate(src);
|
||||
u32 fsrate = 0;
|
||||
|
||||
if (convert_rate)
|
||||
fsrate = 0x0400000 / convert_rate * runtime->rate;
|
||||
|
||||
/* set/clear soft reset */
|
||||
rsnd_mod_write(mod, SRC_SWRSR, 0);
|
||||
rsnd_mod_write(mod, SRC_SWRSR, 1);
|
||||
|
||||
/*
|
||||
* Initialize the operation of the SRC internal circuits
|
||||
* see rsnd_src_start()
|
||||
*/
|
||||
rsnd_mod_write(mod, SRC_SRCIR, 1);
|
||||
|
||||
/* Set channel number and output bit length */
|
||||
rsnd_mod_write(mod, SRC_ADINR, rsnd_get_adinr(mod));
|
||||
|
||||
/* Enable the initial value of IFS */
|
||||
if (fsrate) {
|
||||
rsnd_mod_write(mod, SRC_IFSCR, 1);
|
||||
|
||||
/* Set initial value of IFS */
|
||||
rsnd_mod_write(mod, SRC_IFSVR, fsrate);
|
||||
}
|
||||
|
||||
/* use DMA transfer */
|
||||
rsnd_mod_write(mod, SRC_BUSIF_MODE, 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rsnd_src_init(struct rsnd_mod *mod,
|
||||
struct rsnd_dai *rdai)
|
||||
{
|
||||
struct rsnd_src *src = rsnd_mod_to_src(mod);
|
||||
|
||||
clk_prepare_enable(src->clk);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rsnd_src_quit(struct rsnd_mod *mod,
|
||||
struct rsnd_dai *rdai)
|
||||
{
|
||||
struct rsnd_src *src = rsnd_mod_to_src(mod);
|
||||
|
||||
clk_disable_unprepare(src->clk);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rsnd_src_start(struct rsnd_mod *mod,
|
||||
struct rsnd_dai *rdai)
|
||||
{
|
||||
struct rsnd_src *src = rsnd_mod_to_src(mod);
|
||||
|
||||
/*
|
||||
* Cancel the initialization and operate the SRC function
|
||||
* see rsnd_src_set_convert_rate()
|
||||
*/
|
||||
rsnd_mod_write(mod, SRC_SRCIR, 0);
|
||||
|
||||
if (rsnd_src_convert_rate(src))
|
||||
rsnd_mod_write(mod, SRC_ROUTE_MODE0, 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int rsnd_src_stop(struct rsnd_mod *mod,
|
||||
struct rsnd_dai *rdai)
|
||||
{
|
||||
struct rsnd_src *src = rsnd_mod_to_src(mod);
|
||||
|
||||
if (rsnd_src_convert_rate(src))
|
||||
rsnd_mod_write(mod, SRC_ROUTE_MODE0, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Gen1 functions
|
||||
*/
|
||||
static int rsnd_src_set_route_gen1(struct rsnd_mod *mod,
|
||||
struct rsnd_dai *rdai)
|
||||
{
|
||||
struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
|
||||
struct src_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 id;
|
||||
|
||||
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);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rsnd_src_set_convert_timing_gen1(struct rsnd_mod *mod,
|
||||
struct rsnd_dai *rdai)
|
||||
{
|
||||
struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
|
||||
struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
|
||||
struct rsnd_src *src = rsnd_mod_to_src(mod);
|
||||
struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
|
||||
u32 convert_rate = rsnd_src_convert_rate(src);
|
||||
u32 mask;
|
||||
u32 val;
|
||||
int shift;
|
||||
int id = rsnd_mod_id(mod);
|
||||
int ret;
|
||||
|
||||
/*
|
||||
* SRC_TIMING_SELECT
|
||||
*/
|
||||
shift = (id % 4) * 8;
|
||||
mask = 0x1F << shift;
|
||||
|
||||
/*
|
||||
* ADG is used as source clock if SRC was used,
|
||||
* then, SSI WS is used as destination clock.
|
||||
* SSI WS is used as source clock if SRC is not used
|
||||
* (when playback, source/destination become reverse when capture)
|
||||
*/
|
||||
ret = 0;
|
||||
if (convert_rate) {
|
||||
/* use ADG */
|
||||
val = 0;
|
||||
ret = rsnd_adg_set_convert_clk_gen1(priv, mod,
|
||||
runtime->rate,
|
||||
convert_rate);
|
||||
} else if (8 == id) {
|
||||
/* use SSI WS, but SRU8 is special */
|
||||
val = id << shift;
|
||||
} else {
|
||||
/* use SSI WS */
|
||||
val = (id + 1) << shift;
|
||||
}
|
||||
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
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_src_set_convert_rate_gen1(struct rsnd_mod *mod,
|
||||
struct rsnd_dai *rdai)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = rsnd_src_set_convert_rate(mod, rdai);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
/* Select SRC mode (fixed value) */
|
||||
rsnd_mod_write(mod, SRC_SRCCR, 0x00010110);
|
||||
|
||||
/* Set the restriction value of the FS ratio (98%) */
|
||||
rsnd_mod_write(mod, SRC_MNFSR,
|
||||
rsnd_mod_read(mod, SRC_IFSVR) / 100 * 98);
|
||||
|
||||
/* no SRC_BFSSR settings, since SRC_SRCCR::BUFMD is 0 */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rsnd_src_probe_gen1(struct rsnd_mod *mod,
|
||||
struct rsnd_dai *rdai)
|
||||
{
|
||||
struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
|
||||
struct device *dev = rsnd_priv_to_dev(priv);
|
||||
|
||||
dev_dbg(dev, "%s (Gen1) is probed\n", rsnd_mod_name(mod));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rsnd_src_init_gen1(struct rsnd_mod *mod,
|
||||
struct rsnd_dai *rdai)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = rsnd_src_init(mod, rdai);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
ret = rsnd_src_set_route_gen1(mod, rdai);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
ret = rsnd_src_set_convert_rate_gen1(mod, rdai);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
ret = rsnd_src_set_convert_timing_gen1(mod, rdai);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rsnd_src_start_gen1(struct rsnd_mod *mod,
|
||||
struct rsnd_dai *rdai)
|
||||
{
|
||||
int id = rsnd_mod_id(mod);
|
||||
|
||||
rsnd_mod_bset(mod, SRC_ROUTE_CTRL, (1 << id), (1 << id));
|
||||
|
||||
return rsnd_src_start(mod, rdai);
|
||||
}
|
||||
|
||||
static int rsnd_src_stop_gen1(struct rsnd_mod *mod,
|
||||
struct rsnd_dai *rdai)
|
||||
{
|
||||
int id = rsnd_mod_id(mod);
|
||||
|
||||
rsnd_mod_bset(mod, SRC_ROUTE_CTRL, (1 << id), 0);
|
||||
|
||||
return rsnd_src_stop(mod, rdai);
|
||||
}
|
||||
|
||||
static struct rsnd_mod_ops rsnd_src_gen1_ops = {
|
||||
.name = SRC_NAME,
|
||||
.probe = rsnd_src_probe_gen1,
|
||||
.init = rsnd_src_init_gen1,
|
||||
.quit = rsnd_src_quit,
|
||||
.start = rsnd_src_start_gen1,
|
||||
.stop = rsnd_src_stop_gen1,
|
||||
};
|
||||
|
||||
/*
|
||||
* Gen2 functions
|
||||
*/
|
||||
static int rsnd_src_set_convert_rate_gen2(struct rsnd_mod *mod,
|
||||
struct rsnd_dai *rdai)
|
||||
{
|
||||
struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
|
||||
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 rsnd_src *src = rsnd_mod_to_src(mod);
|
||||
uint ratio;
|
||||
int ret;
|
||||
|
||||
/* 6 - 1/6 are very enough ratio for SRC_BSDSR */
|
||||
if (!rsnd_src_convert_rate(src))
|
||||
ratio = 0;
|
||||
else if (rsnd_src_convert_rate(src) > runtime->rate)
|
||||
ratio = 100 * rsnd_src_convert_rate(src) / runtime->rate;
|
||||
else
|
||||
ratio = 100 * runtime->rate / rsnd_src_convert_rate(src);
|
||||
|
||||
if (ratio > 600) {
|
||||
dev_err(dev, "FSO/FSI ratio error\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = rsnd_src_set_convert_rate(mod, rdai);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
rsnd_mod_write(mod, SRC_SRCCR, 0x00011110);
|
||||
|
||||
switch (rsnd_mod_id(mod)) {
|
||||
case 5:
|
||||
case 6:
|
||||
case 7:
|
||||
case 8:
|
||||
rsnd_mod_write(mod, SRC_BSDSR, 0x02400000);
|
||||
break;
|
||||
default:
|
||||
rsnd_mod_write(mod, SRC_BSDSR, 0x01800000);
|
||||
break;
|
||||
}
|
||||
|
||||
rsnd_mod_write(mod, SRC_BSISR, 0x00100060);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rsnd_src_set_convert_timing_gen2(struct rsnd_mod *mod,
|
||||
struct rsnd_dai *rdai)
|
||||
{
|
||||
struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
|
||||
struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
|
||||
struct rsnd_src *src = rsnd_mod_to_src(mod);
|
||||
u32 convert_rate = rsnd_src_convert_rate(src);
|
||||
int ret;
|
||||
|
||||
if (convert_rate)
|
||||
ret = rsnd_adg_set_convert_clk_gen2(mod, rdai, io,
|
||||
runtime->rate,
|
||||
convert_rate);
|
||||
else
|
||||
ret = rsnd_adg_set_convert_timing_gen2(mod, rdai, io);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int rsnd_src_probe_gen2(struct rsnd_mod *mod,
|
||||
struct rsnd_dai *rdai)
|
||||
{
|
||||
struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
|
||||
struct rsnd_src *src = rsnd_mod_to_src(mod);
|
||||
struct device *dev = rsnd_priv_to_dev(priv);
|
||||
int ret;
|
||||
|
||||
ret = rsnd_dma_init(priv,
|
||||
rsnd_mod_to_dma(mod),
|
||||
rsnd_info_is_playback(priv, src),
|
||||
src->info->dma_id);
|
||||
if (ret < 0)
|
||||
dev_err(dev, "SRC DMA failed\n");
|
||||
|
||||
dev_dbg(dev, "%s (Gen2) is probed\n", rsnd_mod_name(mod));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int rsnd_src_remove_gen2(struct rsnd_mod *mod,
|
||||
struct rsnd_dai *rdai)
|
||||
{
|
||||
rsnd_dma_quit(rsnd_mod_to_priv(mod), rsnd_mod_to_dma(mod));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rsnd_src_init_gen2(struct rsnd_mod *mod,
|
||||
struct rsnd_dai *rdai)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = rsnd_src_init(mod, rdai);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
ret = rsnd_src_set_convert_rate_gen2(mod, rdai);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
ret = rsnd_src_set_convert_timing_gen2(mod, rdai);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rsnd_src_start_gen2(struct rsnd_mod *mod,
|
||||
struct rsnd_dai *rdai)
|
||||
{
|
||||
struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
|
||||
struct rsnd_src *src = rsnd_mod_to_src(mod);
|
||||
u32 val = rsnd_io_to_mod_dvc(io) ? 0x01 : 0x11;
|
||||
|
||||
rsnd_dma_start(rsnd_mod_to_dma(&src->mod));
|
||||
|
||||
rsnd_mod_write(mod, SRC_CTRL, val);
|
||||
|
||||
return rsnd_src_start(mod, rdai);
|
||||
}
|
||||
|
||||
static int rsnd_src_stop_gen2(struct rsnd_mod *mod,
|
||||
struct rsnd_dai *rdai)
|
||||
{
|
||||
struct rsnd_src *src = rsnd_mod_to_src(mod);
|
||||
|
||||
rsnd_mod_write(mod, SRC_CTRL, 0);
|
||||
|
||||
rsnd_dma_stop(rsnd_mod_to_dma(&src->mod));
|
||||
|
||||
return rsnd_src_stop(mod, rdai);
|
||||
}
|
||||
|
||||
static struct rsnd_mod_ops rsnd_src_gen2_ops = {
|
||||
.name = SRC_NAME,
|
||||
.probe = rsnd_src_probe_gen2,
|
||||
.remove = rsnd_src_remove_gen2,
|
||||
.init = rsnd_src_init_gen2,
|
||||
.quit = rsnd_src_quit,
|
||||
.start = rsnd_src_start_gen2,
|
||||
.stop = rsnd_src_stop_gen2,
|
||||
};
|
||||
|
||||
struct rsnd_mod *rsnd_src_mod_get(struct rsnd_priv *priv, int id)
|
||||
{
|
||||
if (WARN_ON(id < 0 || id >= rsnd_src_nr(priv)))
|
||||
id = 0;
|
||||
|
||||
return &((struct rsnd_src *)(priv->src) + id)->mod;
|
||||
}
|
||||
|
||||
static void rsnd_of_parse_src(struct platform_device *pdev,
|
||||
const struct rsnd_of_data *of_data,
|
||||
struct rsnd_priv *priv)
|
||||
{
|
||||
struct device_node *src_node;
|
||||
struct rcar_snd_info *info = rsnd_priv_to_info(priv);
|
||||
struct rsnd_src_platform_info *src_info;
|
||||
struct device *dev = &pdev->dev;
|
||||
int nr;
|
||||
|
||||
if (!of_data)
|
||||
return;
|
||||
|
||||
src_node = of_get_child_by_name(dev->of_node, "rcar_sound,src");
|
||||
if (!src_node)
|
||||
return;
|
||||
|
||||
nr = of_get_child_count(src_node);
|
||||
if (!nr)
|
||||
goto rsnd_of_parse_src_end;
|
||||
|
||||
src_info = devm_kzalloc(dev,
|
||||
sizeof(struct rsnd_src_platform_info) * nr,
|
||||
GFP_KERNEL);
|
||||
if (!src_info) {
|
||||
dev_err(dev, "src info allocation error\n");
|
||||
goto rsnd_of_parse_src_end;
|
||||
}
|
||||
|
||||
info->src_info = src_info;
|
||||
info->src_info_nr = nr;
|
||||
|
||||
rsnd_of_parse_src_end:
|
||||
of_node_put(src_node);
|
||||
}
|
||||
|
||||
int rsnd_src_probe(struct platform_device *pdev,
|
||||
const struct rsnd_of_data *of_data,
|
||||
struct rsnd_priv *priv)
|
||||
{
|
||||
struct rcar_snd_info *info = rsnd_priv_to_info(priv);
|
||||
struct device *dev = rsnd_priv_to_dev(priv);
|
||||
struct rsnd_src *src;
|
||||
struct rsnd_mod_ops *ops;
|
||||
struct clk *clk;
|
||||
char name[RSND_SRC_NAME_SIZE];
|
||||
int i, nr;
|
||||
|
||||
ops = NULL;
|
||||
if (rsnd_is_gen1(priv))
|
||||
ops = &rsnd_src_gen1_ops;
|
||||
if (rsnd_is_gen2(priv))
|
||||
ops = &rsnd_src_gen2_ops;
|
||||
if (!ops) {
|
||||
dev_err(dev, "unknown Generation\n");
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
rsnd_of_parse_src(pdev, of_data, priv);
|
||||
|
||||
/*
|
||||
* init SRC
|
||||
*/
|
||||
nr = info->src_info_nr;
|
||||
if (!nr)
|
||||
return 0;
|
||||
|
||||
src = devm_kzalloc(dev, sizeof(*src) * nr, GFP_KERNEL);
|
||||
if (!src) {
|
||||
dev_err(dev, "SRC allocate failed\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
priv->src_nr = nr;
|
||||
priv->src = src;
|
||||
|
||||
for_each_rsnd_src(src, priv, i) {
|
||||
snprintf(name, RSND_SRC_NAME_SIZE, "%s.%d",
|
||||
SRC_NAME, i);
|
||||
|
||||
clk = devm_clk_get(dev, name);
|
||||
if (IS_ERR(clk))
|
||||
return PTR_ERR(clk);
|
||||
|
||||
src->info = &info->src_info[i];
|
||||
src->clk = clk;
|
||||
|
||||
rsnd_mod_init(priv, &src->mod, ops, RSND_MOD_SRC, i);
|
||||
|
||||
dev_dbg(dev, "SRC%d probed\n", i);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
686
sound/soc/sh/rcar/ssi.c
Normal file
686
sound/soc/sh/rcar/ssi.c
Normal file
|
|
@ -0,0 +1,686 @@
|
|||
/*
|
||||
* Renesas R-Car SSIU/SSI support
|
||||
*
|
||||
* Copyright (C) 2013 Renesas Solutions Corp.
|
||||
* Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
|
||||
*
|
||||
* Based on fsi.c
|
||||
* Kuninori Morimoto <morimoto.kuninori@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 <linux/delay.h>
|
||||
#include "rsnd.h"
|
||||
#define RSND_SSI_NAME_SIZE 16
|
||||
|
||||
/*
|
||||
* SSICR
|
||||
*/
|
||||
#define FORCE (1 << 31) /* Fixed */
|
||||
#define DMEN (1 << 28) /* DMA Enable */
|
||||
#define UIEN (1 << 27) /* Underflow Interrupt Enable */
|
||||
#define OIEN (1 << 26) /* Overflow Interrupt Enable */
|
||||
#define IIEN (1 << 25) /* Idle Mode Interrupt Enable */
|
||||
#define DIEN (1 << 24) /* Data Interrupt Enable */
|
||||
|
||||
#define DWL_8 (0 << 19) /* Data Word Length */
|
||||
#define DWL_16 (1 << 19) /* Data Word Length */
|
||||
#define DWL_18 (2 << 19) /* Data Word Length */
|
||||
#define DWL_20 (3 << 19) /* Data Word Length */
|
||||
#define DWL_22 (4 << 19) /* Data Word Length */
|
||||
#define DWL_24 (5 << 19) /* Data Word Length */
|
||||
#define DWL_32 (6 << 19) /* Data Word Length */
|
||||
|
||||
#define SWL_32 (3 << 16) /* R/W System Word Length */
|
||||
#define SCKD (1 << 15) /* Serial Bit Clock Direction */
|
||||
#define SWSD (1 << 14) /* Serial WS Direction */
|
||||
#define SCKP (1 << 13) /* Serial Bit Clock Polarity */
|
||||
#define SWSP (1 << 12) /* Serial WS Polarity */
|
||||
#define SDTA (1 << 10) /* Serial Data Alignment */
|
||||
#define DEL (1 << 8) /* Serial Data Delay */
|
||||
#define CKDV(v) (v << 4) /* Serial Clock Division Ratio */
|
||||
#define TRMD (1 << 1) /* Transmit/Receive Mode Select */
|
||||
#define EN (1 << 0) /* SSI Module Enable */
|
||||
|
||||
/*
|
||||
* SSISR
|
||||
*/
|
||||
#define UIRQ (1 << 27) /* Underflow Error Interrupt Status */
|
||||
#define OIRQ (1 << 26) /* Overflow Error Interrupt Status */
|
||||
#define IIRQ (1 << 25) /* Idle Mode Interrupt Status */
|
||||
#define DIRQ (1 << 24) /* Data Interrupt Status Flag */
|
||||
|
||||
/*
|
||||
* SSIWSR
|
||||
*/
|
||||
#define CONT (1 << 8) /* WS Continue Function */
|
||||
|
||||
#define SSI_NAME "ssi"
|
||||
|
||||
struct rsnd_ssi {
|
||||
struct clk *clk;
|
||||
struct rsnd_ssi_platform_info *info; /* rcar_snd.h */
|
||||
struct rsnd_ssi *parent;
|
||||
struct rsnd_mod mod;
|
||||
|
||||
struct rsnd_dai *rdai;
|
||||
u32 cr_own;
|
||||
u32 cr_clk;
|
||||
u32 cr_etc;
|
||||
int err;
|
||||
unsigned int usrcnt;
|
||||
unsigned int rate;
|
||||
};
|
||||
|
||||
#define for_each_rsnd_ssi(pos, priv, i) \
|
||||
for (i = 0; \
|
||||
(i < rsnd_ssi_nr(priv)) && \
|
||||
((pos) = ((struct rsnd_ssi *)(priv)->ssi + i)); \
|
||||
i++)
|
||||
|
||||
#define rsnd_ssi_nr(priv) ((priv)->ssi_nr)
|
||||
#define rsnd_mod_to_ssi(_mod) container_of((_mod), struct rsnd_ssi, mod)
|
||||
#define rsnd_dma_to_ssi(dma) rsnd_mod_to_ssi(rsnd_dma_to_mod(dma))
|
||||
#define rsnd_ssi_pio_available(ssi) ((ssi)->info->pio_irq > 0)
|
||||
#define rsnd_ssi_dma_available(ssi) \
|
||||
rsnd_dma_available(rsnd_mod_to_dma(&(ssi)->mod))
|
||||
#define rsnd_ssi_clk_from_parent(ssi) ((ssi)->parent)
|
||||
#define rsnd_ssi_mode_flags(p) ((p)->info->flags)
|
||||
#define rsnd_ssi_dai_id(ssi) ((ssi)->info->dai_id)
|
||||
|
||||
static int rsnd_ssi_use_busif(struct rsnd_mod *mod)
|
||||
{
|
||||
struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
|
||||
struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
|
||||
int use_busif = 0;
|
||||
|
||||
if (!(rsnd_ssi_mode_flags(ssi) & RSND_SSI_NO_BUSIF))
|
||||
use_busif = 1;
|
||||
if (rsnd_io_to_mod_src(io))
|
||||
use_busif = 1;
|
||||
|
||||
return use_busif;
|
||||
}
|
||||
|
||||
static void rsnd_ssi_status_check(struct rsnd_mod *mod,
|
||||
u32 bit)
|
||||
{
|
||||
struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
|
||||
struct device *dev = rsnd_priv_to_dev(priv);
|
||||
u32 status;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 1024; i++) {
|
||||
status = rsnd_mod_read(mod, SSISR);
|
||||
if (status & bit)
|
||||
return;
|
||||
|
||||
udelay(50);
|
||||
}
|
||||
|
||||
dev_warn(dev, "status check failed\n");
|
||||
}
|
||||
|
||||
static int rsnd_ssi_master_clk_start(struct rsnd_ssi *ssi,
|
||||
struct rsnd_dai_stream *io)
|
||||
{
|
||||
struct rsnd_priv *priv = rsnd_mod_to_priv(&ssi->mod);
|
||||
struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
|
||||
struct device *dev = rsnd_priv_to_dev(priv);
|
||||
int i, j, ret;
|
||||
int adg_clk_div_table[] = {
|
||||
1, 6, /* see adg.c */
|
||||
};
|
||||
int ssi_clk_mul_table[] = {
|
||||
1, 2, 4, 8, 16, 6, 12,
|
||||
};
|
||||
unsigned int main_rate;
|
||||
unsigned int rate = rsnd_src_get_ssi_rate(priv, io, runtime);
|
||||
|
||||
/*
|
||||
* Find best clock, and try to start ADG
|
||||
*/
|
||||
for (i = 0; i < ARRAY_SIZE(adg_clk_div_table); i++) {
|
||||
for (j = 0; j < ARRAY_SIZE(ssi_clk_mul_table); j++) {
|
||||
|
||||
/*
|
||||
* this driver is assuming that
|
||||
* system word is 64fs (= 2 x 32bit)
|
||||
* see rsnd_ssi_init()
|
||||
*/
|
||||
main_rate = rate / adg_clk_div_table[i]
|
||||
* 32 * 2 * ssi_clk_mul_table[j];
|
||||
|
||||
ret = rsnd_adg_ssi_clk_try_start(&ssi->mod, main_rate);
|
||||
if (0 == ret) {
|
||||
ssi->rate = rate;
|
||||
ssi->cr_clk = FORCE | SWL_32 |
|
||||
SCKD | SWSD | CKDV(j);
|
||||
|
||||
dev_dbg(dev, "ssi%d outputs %u Hz\n",
|
||||
rsnd_mod_id(&ssi->mod), rate);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dev_err(dev, "unsupported clock rate\n");
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
static void rsnd_ssi_master_clk_stop(struct rsnd_ssi *ssi)
|
||||
{
|
||||
ssi->rate = 0;
|
||||
ssi->cr_clk = 0;
|
||||
rsnd_adg_ssi_clk_stop(&ssi->mod);
|
||||
}
|
||||
|
||||
static void rsnd_ssi_hw_start(struct rsnd_ssi *ssi,
|
||||
struct rsnd_dai *rdai,
|
||||
struct rsnd_dai_stream *io)
|
||||
{
|
||||
struct rsnd_priv *priv = rsnd_mod_to_priv(&ssi->mod);
|
||||
struct device *dev = rsnd_priv_to_dev(priv);
|
||||
u32 cr;
|
||||
|
||||
if (0 == ssi->usrcnt) {
|
||||
clk_prepare_enable(ssi->clk);
|
||||
|
||||
if (rsnd_dai_is_clk_master(rdai)) {
|
||||
if (rsnd_ssi_clk_from_parent(ssi))
|
||||
rsnd_ssi_hw_start(ssi->parent, rdai, io);
|
||||
else
|
||||
rsnd_ssi_master_clk_start(ssi, io);
|
||||
}
|
||||
}
|
||||
|
||||
cr = ssi->cr_own |
|
||||
ssi->cr_clk |
|
||||
ssi->cr_etc |
|
||||
EN;
|
||||
|
||||
rsnd_mod_write(&ssi->mod, SSICR, cr);
|
||||
|
||||
ssi->usrcnt++;
|
||||
|
||||
dev_dbg(dev, "ssi%d hw started\n", rsnd_mod_id(&ssi->mod));
|
||||
}
|
||||
|
||||
static void rsnd_ssi_hw_stop(struct rsnd_ssi *ssi,
|
||||
struct rsnd_dai *rdai)
|
||||
{
|
||||
struct rsnd_priv *priv = rsnd_mod_to_priv(&ssi->mod);
|
||||
struct device *dev = rsnd_priv_to_dev(priv);
|
||||
u32 cr;
|
||||
|
||||
if (0 == ssi->usrcnt) /* stop might be called without start */
|
||||
return;
|
||||
|
||||
ssi->usrcnt--;
|
||||
|
||||
if (0 == ssi->usrcnt) {
|
||||
/*
|
||||
* disable all IRQ,
|
||||
* and, wait all data was sent
|
||||
*/
|
||||
cr = ssi->cr_own |
|
||||
ssi->cr_clk;
|
||||
|
||||
rsnd_mod_write(&ssi->mod, SSICR, cr | EN);
|
||||
rsnd_ssi_status_check(&ssi->mod, DIRQ);
|
||||
|
||||
/*
|
||||
* disable SSI,
|
||||
* and, wait idle state
|
||||
*/
|
||||
rsnd_mod_write(&ssi->mod, SSICR, cr); /* disabled all */
|
||||
rsnd_ssi_status_check(&ssi->mod, IIRQ);
|
||||
|
||||
if (rsnd_dai_is_clk_master(rdai)) {
|
||||
if (rsnd_ssi_clk_from_parent(ssi))
|
||||
rsnd_ssi_hw_stop(ssi->parent, rdai);
|
||||
else
|
||||
rsnd_ssi_master_clk_stop(ssi);
|
||||
}
|
||||
|
||||
clk_disable_unprepare(ssi->clk);
|
||||
}
|
||||
|
||||
dev_dbg(dev, "ssi%d hw stopped\n", rsnd_mod_id(&ssi->mod));
|
||||
}
|
||||
|
||||
/*
|
||||
* SSI mod common functions
|
||||
*/
|
||||
static int rsnd_ssi_init(struct rsnd_mod *mod,
|
||||
struct rsnd_dai *rdai)
|
||||
{
|
||||
struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
|
||||
struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
|
||||
struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
|
||||
u32 cr;
|
||||
|
||||
cr = FORCE;
|
||||
|
||||
/*
|
||||
* always use 32bit system word for easy clock calculation.
|
||||
* see also rsnd_ssi_master_clk_enable()
|
||||
*/
|
||||
cr |= SWL_32;
|
||||
|
||||
/*
|
||||
* init clock settings for SSICR
|
||||
*/
|
||||
switch (runtime->sample_bits) {
|
||||
case 16:
|
||||
cr |= DWL_16;
|
||||
break;
|
||||
case 32:
|
||||
cr |= DWL_24;
|
||||
break;
|
||||
default:
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
if (rdai->bit_clk_inv)
|
||||
cr |= SCKP;
|
||||
if (rdai->frm_clk_inv)
|
||||
cr |= SWSP;
|
||||
if (rdai->data_alignment)
|
||||
cr |= SDTA;
|
||||
if (rdai->sys_delay)
|
||||
cr |= DEL;
|
||||
if (rsnd_dai_is_play(rdai, io))
|
||||
cr |= TRMD;
|
||||
|
||||
/*
|
||||
* set ssi parameter
|
||||
*/
|
||||
ssi->rdai = rdai;
|
||||
ssi->cr_own = cr;
|
||||
ssi->err = -1; /* ignore 1st error */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rsnd_ssi_quit(struct rsnd_mod *mod,
|
||||
struct rsnd_dai *rdai)
|
||||
{
|
||||
struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
|
||||
struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
|
||||
struct device *dev = rsnd_priv_to_dev(priv);
|
||||
|
||||
if (ssi->err > 0)
|
||||
dev_warn(dev, "ssi under/over flow err = %d\n", ssi->err);
|
||||
|
||||
ssi->rdai = NULL;
|
||||
ssi->cr_own = 0;
|
||||
ssi->err = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void rsnd_ssi_record_error(struct rsnd_ssi *ssi, u32 status)
|
||||
{
|
||||
/* under/over flow error */
|
||||
if (status & (UIRQ | OIRQ)) {
|
||||
ssi->err++;
|
||||
|
||||
/* clear error status */
|
||||
rsnd_mod_write(&ssi->mod, SSISR, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* SSI PIO
|
||||
*/
|
||||
static irqreturn_t rsnd_ssi_pio_interrupt(int irq, void *data)
|
||||
{
|
||||
struct rsnd_ssi *ssi = data;
|
||||
struct rsnd_mod *mod = &ssi->mod;
|
||||
struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
|
||||
u32 status = rsnd_mod_read(mod, SSISR);
|
||||
irqreturn_t ret = IRQ_NONE;
|
||||
|
||||
if (io && (status & DIRQ)) {
|
||||
struct rsnd_dai *rdai = ssi->rdai;
|
||||
struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
|
||||
u32 *buf = (u32 *)(runtime->dma_area +
|
||||
rsnd_dai_pointer_offset(io, 0));
|
||||
|
||||
rsnd_ssi_record_error(ssi, status);
|
||||
|
||||
/*
|
||||
* 8/16/32 data can be assesse to TDR/RDR register
|
||||
* directly as 32bit data
|
||||
* see rsnd_ssi_init()
|
||||
*/
|
||||
if (rsnd_dai_is_play(rdai, io))
|
||||
rsnd_mod_write(mod, SSITDR, *buf);
|
||||
else
|
||||
*buf = rsnd_mod_read(mod, SSIRDR);
|
||||
|
||||
rsnd_dai_pointer_update(io, sizeof(*buf));
|
||||
|
||||
ret = IRQ_HANDLED;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int rsnd_ssi_pio_probe(struct rsnd_mod *mod,
|
||||
struct rsnd_dai *rdai)
|
||||
{
|
||||
struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
|
||||
struct device *dev = rsnd_priv_to_dev(priv);
|
||||
struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
|
||||
int irq = ssi->info->pio_irq;
|
||||
int ret;
|
||||
|
||||
ret = devm_request_irq(dev, irq,
|
||||
rsnd_ssi_pio_interrupt,
|
||||
IRQF_SHARED,
|
||||
dev_name(dev), ssi);
|
||||
if (ret)
|
||||
dev_err(dev, "SSI request interrupt failed\n");
|
||||
|
||||
dev_dbg(dev, "%s (PIO) is probed\n", rsnd_mod_name(mod));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int rsnd_ssi_pio_start(struct rsnd_mod *mod,
|
||||
struct rsnd_dai *rdai)
|
||||
{
|
||||
struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
|
||||
struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
|
||||
|
||||
/* enable PIO IRQ */
|
||||
ssi->cr_etc = UIEN | OIEN | DIEN;
|
||||
|
||||
rsnd_src_ssiu_start(mod, rdai, 0);
|
||||
|
||||
rsnd_src_enable_ssi_irq(mod, rdai);
|
||||
|
||||
rsnd_ssi_hw_start(ssi, rdai, io);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rsnd_ssi_pio_stop(struct rsnd_mod *mod,
|
||||
struct rsnd_dai *rdai)
|
||||
{
|
||||
struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
|
||||
|
||||
ssi->cr_etc = 0;
|
||||
|
||||
rsnd_ssi_hw_stop(ssi, rdai);
|
||||
|
||||
rsnd_src_ssiu_stop(mod, rdai, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct rsnd_mod_ops rsnd_ssi_pio_ops = {
|
||||
.name = SSI_NAME,
|
||||
.probe = rsnd_ssi_pio_probe,
|
||||
.init = rsnd_ssi_init,
|
||||
.quit = rsnd_ssi_quit,
|
||||
.start = rsnd_ssi_pio_start,
|
||||
.stop = rsnd_ssi_pio_stop,
|
||||
};
|
||||
|
||||
static int rsnd_ssi_dma_probe(struct rsnd_mod *mod,
|
||||
struct rsnd_dai *rdai)
|
||||
{
|
||||
struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
|
||||
struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
|
||||
struct device *dev = rsnd_priv_to_dev(priv);
|
||||
int dma_id = ssi->info->dma_id;
|
||||
int ret;
|
||||
|
||||
ret = rsnd_dma_init(
|
||||
priv, rsnd_mod_to_dma(mod),
|
||||
rsnd_info_is_playback(priv, ssi),
|
||||
dma_id);
|
||||
|
||||
if (ret < 0)
|
||||
dev_err(dev, "SSI DMA failed\n");
|
||||
|
||||
dev_dbg(dev, "%s (DMA) is probed\n", rsnd_mod_name(mod));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int rsnd_ssi_dma_remove(struct rsnd_mod *mod,
|
||||
struct rsnd_dai *rdai)
|
||||
{
|
||||
rsnd_dma_quit(rsnd_mod_to_priv(mod), rsnd_mod_to_dma(mod));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rsnd_ssi_dma_start(struct rsnd_mod *mod,
|
||||
struct rsnd_dai *rdai)
|
||||
{
|
||||
struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
|
||||
struct rsnd_dma *dma = rsnd_mod_to_dma(&ssi->mod);
|
||||
struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
|
||||
|
||||
/* enable DMA transfer */
|
||||
ssi->cr_etc = DMEN;
|
||||
|
||||
rsnd_src_ssiu_start(mod, rdai, rsnd_ssi_use_busif(mod));
|
||||
|
||||
rsnd_dma_start(dma);
|
||||
|
||||
rsnd_ssi_hw_start(ssi, ssi->rdai, io);
|
||||
|
||||
/* enable WS continue */
|
||||
if (rsnd_dai_is_clk_master(rdai))
|
||||
rsnd_mod_write(&ssi->mod, SSIWSR, CONT);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rsnd_ssi_dma_stop(struct rsnd_mod *mod,
|
||||
struct rsnd_dai *rdai)
|
||||
{
|
||||
struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
|
||||
struct rsnd_dma *dma = rsnd_mod_to_dma(&ssi->mod);
|
||||
|
||||
ssi->cr_etc = 0;
|
||||
|
||||
rsnd_ssi_record_error(ssi, rsnd_mod_read(mod, SSISR));
|
||||
|
||||
rsnd_ssi_hw_stop(ssi, rdai);
|
||||
|
||||
rsnd_dma_stop(dma);
|
||||
|
||||
rsnd_src_ssiu_stop(mod, rdai, 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char *rsnd_ssi_dma_name(struct rsnd_mod *mod)
|
||||
{
|
||||
return rsnd_ssi_use_busif(mod) ? "ssiu" : SSI_NAME;
|
||||
}
|
||||
|
||||
static struct rsnd_mod_ops rsnd_ssi_dma_ops = {
|
||||
.name = SSI_NAME,
|
||||
.dma_name = rsnd_ssi_dma_name,
|
||||
.probe = rsnd_ssi_dma_probe,
|
||||
.remove = rsnd_ssi_dma_remove,
|
||||
.init = rsnd_ssi_init,
|
||||
.quit = rsnd_ssi_quit,
|
||||
.start = rsnd_ssi_dma_start,
|
||||
.stop = rsnd_ssi_dma_stop,
|
||||
};
|
||||
|
||||
/*
|
||||
* Non SSI
|
||||
*/
|
||||
static struct rsnd_mod_ops rsnd_ssi_non_ops = {
|
||||
.name = SSI_NAME,
|
||||
};
|
||||
|
||||
/*
|
||||
* ssi mod function
|
||||
*/
|
||||
struct rsnd_mod *rsnd_ssi_mod_get(struct rsnd_priv *priv, int id)
|
||||
{
|
||||
if (WARN_ON(id < 0 || id >= rsnd_ssi_nr(priv)))
|
||||
id = 0;
|
||||
|
||||
return &((struct rsnd_ssi *)(priv->ssi) + id)->mod;
|
||||
}
|
||||
|
||||
int rsnd_ssi_is_pin_sharing(struct rsnd_mod *mod)
|
||||
{
|
||||
struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
|
||||
|
||||
return !!(rsnd_ssi_mode_flags(ssi) & RSND_SSI_CLK_PIN_SHARE);
|
||||
}
|
||||
|
||||
static void rsnd_ssi_parent_clk_setup(struct rsnd_priv *priv, struct rsnd_ssi *ssi)
|
||||
{
|
||||
if (!rsnd_ssi_is_pin_sharing(&ssi->mod))
|
||||
return;
|
||||
|
||||
switch (rsnd_mod_id(&ssi->mod)) {
|
||||
case 1:
|
||||
case 2:
|
||||
ssi->parent = rsnd_mod_to_ssi(rsnd_ssi_mod_get(priv, 0));
|
||||
break;
|
||||
case 4:
|
||||
ssi->parent = rsnd_mod_to_ssi(rsnd_ssi_mod_get(priv, 3));
|
||||
break;
|
||||
case 8:
|
||||
ssi->parent = rsnd_mod_to_ssi(rsnd_ssi_mod_get(priv, 7));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void rsnd_of_parse_ssi(struct platform_device *pdev,
|
||||
const struct rsnd_of_data *of_data,
|
||||
struct rsnd_priv *priv)
|
||||
{
|
||||
struct device_node *node;
|
||||
struct device_node *np;
|
||||
struct rsnd_ssi_platform_info *ssi_info;
|
||||
struct rcar_snd_info *info = rsnd_priv_to_info(priv);
|
||||
struct device *dev = &pdev->dev;
|
||||
int nr, i;
|
||||
|
||||
if (!of_data)
|
||||
return;
|
||||
|
||||
node = of_get_child_by_name(dev->of_node, "rcar_sound,ssi");
|
||||
if (!node)
|
||||
return;
|
||||
|
||||
nr = of_get_child_count(node);
|
||||
if (!nr)
|
||||
goto rsnd_of_parse_ssi_end;
|
||||
|
||||
ssi_info = devm_kzalloc(dev,
|
||||
sizeof(struct rsnd_ssi_platform_info) * nr,
|
||||
GFP_KERNEL);
|
||||
if (!ssi_info) {
|
||||
dev_err(dev, "ssi info allocation error\n");
|
||||
goto rsnd_of_parse_ssi_end;
|
||||
}
|
||||
|
||||
info->ssi_info = ssi_info;
|
||||
info->ssi_info_nr = nr;
|
||||
|
||||
i = -1;
|
||||
for_each_child_of_node(node, np) {
|
||||
i++;
|
||||
|
||||
ssi_info = info->ssi_info + i;
|
||||
|
||||
/*
|
||||
* pin settings
|
||||
*/
|
||||
if (of_get_property(np, "shared-pin", NULL))
|
||||
ssi_info->flags |= RSND_SSI_CLK_PIN_SHARE;
|
||||
|
||||
/*
|
||||
* irq
|
||||
*/
|
||||
ssi_info->pio_irq = irq_of_parse_and_map(np, 0);
|
||||
|
||||
/*
|
||||
* DMA
|
||||
*/
|
||||
ssi_info->dma_id = of_get_property(np, "pio-transfer", NULL) ?
|
||||
0 : 1;
|
||||
|
||||
if (of_get_property(np, "no-busif", NULL))
|
||||
ssi_info->flags |= RSND_SSI_NO_BUSIF;
|
||||
}
|
||||
|
||||
rsnd_of_parse_ssi_end:
|
||||
of_node_put(node);
|
||||
}
|
||||
|
||||
int rsnd_ssi_probe(struct platform_device *pdev,
|
||||
const struct rsnd_of_data *of_data,
|
||||
struct rsnd_priv *priv)
|
||||
{
|
||||
struct rcar_snd_info *info = rsnd_priv_to_info(priv);
|
||||
struct rsnd_ssi_platform_info *pinfo;
|
||||
struct device *dev = rsnd_priv_to_dev(priv);
|
||||
struct rsnd_mod_ops *ops;
|
||||
struct clk *clk;
|
||||
struct rsnd_ssi *ssi;
|
||||
char name[RSND_SSI_NAME_SIZE];
|
||||
int i, nr;
|
||||
|
||||
rsnd_of_parse_ssi(pdev, of_data, priv);
|
||||
|
||||
/*
|
||||
* init SSI
|
||||
*/
|
||||
nr = info->ssi_info_nr;
|
||||
ssi = devm_kzalloc(dev, sizeof(*ssi) * nr, GFP_KERNEL);
|
||||
if (!ssi) {
|
||||
dev_err(dev, "SSI allocate failed\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
priv->ssi = ssi;
|
||||
priv->ssi_nr = nr;
|
||||
|
||||
for_each_rsnd_ssi(ssi, priv, i) {
|
||||
pinfo = &info->ssi_info[i];
|
||||
|
||||
snprintf(name, RSND_SSI_NAME_SIZE, "%s.%d",
|
||||
SSI_NAME, i);
|
||||
|
||||
clk = devm_clk_get(dev, name);
|
||||
if (IS_ERR(clk))
|
||||
return PTR_ERR(clk);
|
||||
|
||||
ssi->info = pinfo;
|
||||
ssi->clk = clk;
|
||||
|
||||
ops = &rsnd_ssi_non_ops;
|
||||
if (pinfo->dma_id > 0)
|
||||
ops = &rsnd_ssi_dma_ops;
|
||||
else if (rsnd_ssi_pio_available(ssi))
|
||||
ops = &rsnd_ssi_pio_ops;
|
||||
|
||||
rsnd_mod_init(priv, &ssi->mod, ops, RSND_MOD_SSI, i);
|
||||
|
||||
rsnd_ssi_parent_clk_setup(priv, ssi);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue