/*
* Renesas R-Car SRU/SCU/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.
*/
/*
* Renesas R-Car sound device structure
*
* Gen1
*
* SRU : Sound Routing Unit
* - SRC : Sampling Rate Converter
* - CMD
* - CTU : Channel Count Conversion Unit
* - MIX : Mixer
* - DVC : Digital Volume and Mute Function
* - SSI : Serial Sound Interface
*
* Gen2
*
* SCU : Sampling Rate Converter Unit
* - SRC : Sampling Rate Converter
* - CMD
* - CTU : Channel Count Conversion Unit
* - MIX : Mixer
* - DVC : Digital Volume and Mute Function
* SSIU : Serial Sound Interface Unit
* - SSI : Serial Sound Interface
*/
/*
* driver data Image
*
* rsnd_priv
* |
* | ** this depends on Gen1/Gen2
* |
* +- gen
* |
* | ** these depend on data path
* | ** gen and platform data control it
* |
* +- rdai[0]
* | | sru ssiu ssi
* | +- playback -> [mod] -> [mod] -> [mod] -> ...
* | |
* | | sru ssiu ssi
* | +- capture -> [mod] -> [mod] -> [mod] -> ...
* |
* +- rdai[1]
* | | sru ssiu ssi
* | +- playback -> [mod] -> [mod] -> [mod] -> ...
* | |
* | | sru ssiu ssi
* | +- capture -> [mod] -> [mod] -> [mod] -> ...
* ...
* |
* | ** these control ssi
* |
* +- ssi
* | |
* | +- ssi[0]
* | +- ssi[1]
* | +- ssi[2]
* | ...
* |
* | ** these control src
* |
* +- src
* |
* +- src[0]
* +- src[1]
* +- src[2]
* ...
*
*
* for_each_rsnd_dai(xx, priv, xx)
* rdai[0] => rdai[1] => rdai[2] => ...
*
* for_each_rsnd_mod(xx, rdai, xx)
* [mod] => [mod] => [mod] => ...
*
* rsnd_dai_call(xxx, fn )
* [mod]->fn() -> [mod]->fn() -> [mod]->fn()...
*
*/
#include <linux/pm_runtime.h>
#include <linux/shdma-base.h>
#include "rsnd.h"
#define RSND_RATES SNDRV_PCM_RATE_8000_96000
#define RSND_FMTS (SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE)
static struct rsnd_of_data rsnd_of_data_gen1 = {
.flags = RSND_GEN1,
};
static struct rsnd_of_data rsnd_of_data_gen2 = {
.flags = RSND_GEN2,
};
static struct of_device_id rsnd_of_match[] = {
{ .compatible = "renesas,rcar_sound-gen1", .data = &rsnd_of_data_gen1 },
{ .compatible = "renesas,rcar_sound-gen2", .data = &rsnd_of_data_gen2 },
{},
};
MODULE_DEVICE_TABLE(of, rsnd_of_match);
/*
* rsnd_platform functions
*/
#define rsnd_platform_call(priv, dai, func, param...) \
(!(priv->info->func) ? 0 : \
priv->info->func(param))
#define rsnd_is_enable_path(io, name) \
((io)->info ? (io)->info->name : NULL)
#define rsnd_info_id(priv, io, name) \
((io)->info->name - priv->info->name##_info)
/*
* rsnd_mod functions
*/
char *rsnd_mod_name(struct rsnd_mod *mod)
{
if (!mod || !mod->ops)
return "unknown";
return mod->ops->name;
}
void rsnd_mod_init(struct rsnd_priv *priv,
struct rsnd_mod *mod,
struct rsnd_mod_ops *ops,
enum rsnd_mod_type type,
int id)
{
mod->priv = priv;
mod->id = id;
mod->ops = ops;
mod->type = type;
}
/*
* rsnd_dma functions
*/
static void __rsnd_dma_start(struct rsnd_dma *dma);
static void rsnd_dma_continue(struct rsnd_dma *dma)
{
/* push next A or B plane */
dma->submit_loop = 1;
schedule_work(&dma->work);
}
void rsnd_dma_start(struct rsnd_dma *dma)
{
/* push both A and B plane*/
dma->offset = 0;
dma->submit_loop = 2;
__rsnd_dma_start(dma);
}
void rsnd_dma_stop(struct rsnd_dma *dma)
{
dma->submit_loop = 0;
cancel_work_sync(&dma->work);
dmaengine_terminate_all(dma->chan);
}
static void rsnd_dma_complete(void *data)
{
struct rsnd_dma *dma = (struct rsnd_dma *)data;
struct rsnd_mod *mod = rsnd_dma_to_mod(dma);
struct rsnd_priv *priv = rsnd_mod_to_priv(rsnd_dma_to_mod(dma));
struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
unsigned long flags;
rsnd_lock(priv, flags);
/*
* Renesas sound Gen1 needs 1 DMAC,
* Gen2 needs 2 DMAC.
* In Gen2 case, it are Audio-DMAC, and Audio-DMAC-peri-peri.
* But, Audio-DMAC-peri-peri doesn't have interrupt,
* and this driver is assuming that here.
*
* If Audio-DMAC-peri-peri has interrpt,
* rsnd_dai_pointer_update() will be called twice,
* ant it will breaks io->byte_pos
*/
if (dma->submit_loop)
rsnd_dma_continue(dma);
rsnd_unlock