// SPDX-License-Identifier: GPL-2.0 // // Serial Sound Interface (I2S) support for SH7760/SH7780 // // Copyright (c) 2007 Manuel Lauss <mano@roarinelk.homelinux.net> // // dont forget to set IPSEL/OMSEL register bits (in your board code) to // enable SSI output pins!
/* * LIMITATIONS: * The SSI unit has only one physical data line, so full duplex is * impossible. This can be remedied on the SH7760 by using the * other SSI unit for recording; however the SH7780 has only 1 SSI * unit, and its pins are shared with the AC97 unit, among others. * * FEATURES: * The SSI features "compressed mode": in this mode it continuously * streams PCM data over the I2S lines and uses LRCK as a handshake * signal. Can be used to send compressed data (AC3/DTS) to a DSP. * The number of bits sent over the wire in a frame can be adjusted * and can be independent from the actual sample bit depth. This is * useful to support TDM mode codecs like the AD1939 which have a * fixed TDM slot size, regardless of sample resolution.
*/
/* DATA WORD LENGTH (DWL): databits in audio sample */
i = 0; switch (bits) { case 32: ++i; case 24: ++i; case 22: ++i; case 20: ++i; case 18: ++i; case 16: ++i;
ssicr |= i << CR_DWL_SHIFT; case 8: break; default:
pr_debug("ssi: invalid sample width\n"); return -EINVAL;
}
/* * SYSTEM WORD LENGTH: size in bits of half a frame over the I2S * wires. This is usually bits_per_sample x channels/2; i.e. in * Stereo mode the SWL equals DWL. SWL can be bigger than the * product of (channels_per_slot x samplebits), e.g. for codecs * like the AD1939 which only accept 32bit wide TDM slots. For * "standard" I2S operation we set SWL = chans / 2 * DWL here. * Waiting for ASoC to get TDM support ;-)
*/ if ((bits > 16) && (bits <= 24)) {
bits = 24; /* these are padded by the SSI */ /*ssicr |= CR_PDTA;*/ /* cpu/data endianness ? */
}
i = 0;
swl = (bits * channels) / 2; switch (swl) { case 256: ++i; case 128: ++i; case 64: ++i; case 48: ++i; case 32: ++i; case 16: ++i;
ssicr |= i << CR_SWL_SHIFT; case 8: break; default:
pr_debug("ssi: invalid system word length computed\n"); return -EINVAL;
}
SSIREG(SSICR) = ssicr;
pr_debug("ssi_hw_params() leave\nssicr is now %08lx\n", ssicr); return 0;
}
staticint ssi_set_sysclk(struct snd_soc_dai *cpu_dai, int clk_id, unsignedint freq, int dir)
{ struct ssi_priv *ssi = &ssi_cpu_data[cpu_dai->id];
ssi->sysclk = freq;
return 0;
}
/* * This divider is used to generate the SSI_SCK (I2S bitclock) from the * clock at the HAC_BIT_CLK ("oversampling clock") pin.
*/ staticint ssi_set_clkdiv(struct snd_soc_dai *dai, int did, int div)
{ struct ssi_priv *ssi = &ssi_cpu_data[dai->id]; unsignedlong ssicr; int i;
i = 0;
ssicr = SSIREG(SSICR) & ~CR_CKDIV_MASK; switch (div) { case 16: ++i; case 8: ++i; case 4: ++i; case 2: ++i;
SSIREG(SSICR) = ssicr | (i << CR_CKDIV_SHIFT); case 1: break; default:
pr_debug("ssi: invalid sck divider %d\n", div); return -EINVAL;
}
switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { case SND_SOC_DAIFMT_I2S: break; case SND_SOC_DAIFMT_RIGHT_J:
ssicr |= CR_DEL | CR_PDTA; break; case SND_SOC_DAIFMT_LEFT_J:
ssicr |= CR_DEL; break; default:
pr_debug("ssi: unsupported format\n"); return -EINVAL;
}
switch (fmt & SND_SOC_DAIFMT_CLOCK_MASK) { case SND_SOC_DAIFMT_CONT: break; case SND_SOC_DAIFMT_GATED:
ssicr |= CR_BREN; break;
}
switch (fmt & SND_SOC_DAIFMT_INV_MASK) { case SND_SOC_DAIFMT_NB_NF:
ssicr |= CR_SCKP; /* sample data at low clkedge */ break; case SND_SOC_DAIFMT_NB_IF:
ssicr |= CR_SCKP | CR_SWSP; break; case SND_SOC_DAIFMT_IB_NF: break; case SND_SOC_DAIFMT_IB_IF:
ssicr |= CR_SWSP; /* word select starts low */ break; default:
pr_debug("ssi: invalid inversion\n"); return -EINVAL;
}
switch (fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) { case SND_SOC_DAIFMT_BC_FC: break; case SND_SOC_DAIFMT_BP_FC:
ssicr |= CR_SCK_MASTER; break; case SND_SOC_DAIFMT_BC_FP:
ssicr |= CR_SWS_MASTER; break; case SND_SOC_DAIFMT_BP_FP:
ssicr |= CR_SWS_MASTER | CR_SCK_MASTER; break; default:
pr_debug("ssi: invalid master/secondary configuration\n"); return -EINVAL;
}
SSIREG(SSICR) = ssicr;
pr_debug("ssi_set_fmt() leave\nssicr is now 0x%08lx\n", ssicr);
return 0;
}
/* the SSI depends on an external clocksource (at HAC_BIT_CLK) even in * Master mode, so really this is board specific; the SSI can do any * rate with the right bitclk and divider settings.
*/ #define SSI_RATES \
SNDRV_PCM_RATE_8000_192000
/* the SSI can do 8-32 bit samples, with 8 possible channels */ #define SSI_FMTS \
(SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U8 | \
SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U16_LE | \
SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_U20_3LE | \
SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_U24_3LE | \
SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_U32_LE)
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.