/* * SSI PIO */ static irqreturn_t rsnd_ssi_pio_interrupt(int irq, void *data) { struct rsnd_ssi *ssi = data; struct rsnd_dai_stream *io = ssi->io; u32 status = rsnd_mod_read(&ssi->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(&ssi->mod, SSITDR, *buf); else *buf = rsnd_mod_read(&ssi->mod, SSIRDR); rsnd_dai_pointer_update(io, sizeof(*buf)); ret = IRQ_HANDLED; } return ret; }
/* * SSI mod common functions */ static int rsnd_ssi_init(struct rsnd_mod *mod, struct rsnd_dai *rdai, struct rsnd_dai_stream *io) { 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); 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->io = io; ssi->cr_own = cr; ssi->err = -1; /* ignore 1st error */ rsnd_ssi_mode_set(priv, rdai, ssi); dev_dbg(dev, "%s.%d init\n", rsnd_mod_name(mod), rsnd_mod_id(mod)); return 0; }
/* * Gen1 */ static int rsnd_gen1_path_init(struct rsnd_priv *priv, struct rsnd_dai *rdai, struct rsnd_dai_stream *io) { struct rsnd_mod *mod; int ret; int id; /* * Gen1 is created by SRU/SSI, and this SRU is base module of * Gen2's SCU/SSIU/SSI. (Gen2 SCU/SSIU came from SRU) * * Easy image is.. * Gen1 SRU = Gen2 SCU + SSIU + etc * * Gen2 SCU path is very flexible, but, Gen1 SRU (SCU parts) is * using fixed path. * * Then, SSI id = SCU id here */ /* get SSI's ID */ mod = rsnd_ssi_mod_get_frm_dai(priv, rsnd_dai_id(priv, rdai), rsnd_dai_is_play(rdai, io)); id = rsnd_mod_id(mod); /* SSI */ mod = rsnd_ssi_mod_get(priv, id); ret = rsnd_dai_connect(rdai, mod, io); if (ret < 0) return ret; /* SCU */ mod = rsnd_scu_mod_get(priv, id); ret = rsnd_dai_connect(rdai, mod, io); return ret; }
/* * Gen1 functions */ static int rsnd_src_set_route_gen1(struct rsnd_mod *mod, struct rsnd_dai *rdai, struct rsnd_dai_stream *io) { 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_soc_dai_trigger(struct snd_pcm_substream *substream, int cmd, struct snd_soc_dai *dai) { struct rsnd_priv *priv = snd_soc_dai_get_drvdata(dai); struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai); struct rsnd_dai_stream *io = rsnd_rdai_to_io(rdai, substream); struct rsnd_mod *mod = rsnd_ssi_mod_get_frm_dai(priv, rsnd_dai_id(priv, rdai), rsnd_dai_is_play(rdai, io)); int ssi_id = rsnd_mod_id(mod); int ret; unsigned long flags; rsnd_lock(priv, flags); switch (cmd) { case SNDRV_PCM_TRIGGER_START: ret = rsnd_dai_stream_init(io, substream); if (ret < 0) goto dai_trigger_end; ret = rsnd_platform_call(priv, dai, start, ssi_id); if (ret < 0) goto dai_trigger_end; ret = rsnd_gen_path_init(priv, rdai, io); if (ret < 0) goto dai_trigger_end; ret = rsnd_dai_call(rdai, io, init); if (ret < 0) goto dai_trigger_end; ret = rsnd_dai_call(rdai, io, start); if (ret < 0) goto dai_trigger_end; break; case SNDRV_PCM_TRIGGER_STOP: ret = rsnd_dai_call(rdai, io, stop); if (ret < 0) goto dai_trigger_end; ret = rsnd_dai_call(rdai, io, quit); if (ret < 0) goto dai_trigger_end; ret = rsnd_gen_path_exit(priv, rdai, io); if (ret < 0) goto dai_trigger_end; ret = rsnd_platform_call(priv, dai, stop, ssi_id); if (ret < 0) goto dai_trigger_end; break; default: ret = -EINVAL; } dai_trigger_end: rsnd_unlock(priv, flags); return ret; }
static int rsnd_scu_set_route(struct rsnd_priv *priv, struct rsnd_mod *mod, struct rsnd_dai *rdai, struct rsnd_dai_stream *io) { struct scu_route_config { u32 mask; int shift; } routes[] = { { 0xF, 0, }, /* 0 */ { 0xF, 4, }, /* 1 */ { 0xF, 8, }, /* 2 */ { 0x7, 12, }, /* 3 */ { 0x7, 16, }, /* 4 */ { 0x7, 20, }, /* 5 */ { 0x7, 24, }, /* 6 */ { 0x3, 28, }, /* 7 */ { 0x3, 30, }, /* 8 */ }; u32 mask; u32 val; int shift; int id; /* * Gen1 only */ if (!rsnd_is_gen1(priv)) return 0; id = rsnd_mod_id(mod); if (id < 0 || id > ARRAY_SIZE(routes)) return -EIO; /* * SRC_ROUTE_SELECT */ val = rsnd_dai_is_play(rdai, io) ? 0x1 : 0x2; val = val << routes[id].shift; mask = routes[id].mask << routes[id].shift; rsnd_mod_bset(mod, SRC_ROUTE_SEL, mask, val); /* * SRC_TIMING_SELECT */ shift = (id % 4) * 8; mask = 0x1F << shift; if (8 == id) /* SRU8 is very special */ val = id << shift; else val = (id + 1) << shift; switch (id / 4) { case 0: rsnd_mod_bset(mod, SRC_TMG_SEL0, mask, val); break; case 1: rsnd_mod_bset(mod, SRC_TMG_SEL1, mask, val); break; case 2: rsnd_mod_bset(mod, SRC_TMG_SEL2, mask, val); break; } return 0; }