18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0+ 28c2ecf20Sopenharmony_ci// 38c2ecf20Sopenharmony_ci// siu.h - ALSA SoC driver for Renesas SH7343, SH7722 SIU peripheral. 48c2ecf20Sopenharmony_ci// 58c2ecf20Sopenharmony_ci// Copyright (C) 2009-2010 Guennadi Liakhovetski <g.liakhovetski@gmx.de> 68c2ecf20Sopenharmony_ci// Copyright (C) 2006 Carlos Munoz <carlos@kenati.com> 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#ifndef SIU_H 98c2ecf20Sopenharmony_ci#define SIU_H 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci/* Common kernel and user-space firmware-building defines and types */ 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#define YRAM0_SIZE (0x0040 / 4) /* 16 */ 148c2ecf20Sopenharmony_ci#define YRAM1_SIZE (0x0080 / 4) /* 32 */ 158c2ecf20Sopenharmony_ci#define YRAM2_SIZE (0x0040 / 4) /* 16 */ 168c2ecf20Sopenharmony_ci#define YRAM3_SIZE (0x0080 / 4) /* 32 */ 178c2ecf20Sopenharmony_ci#define YRAM4_SIZE (0x0080 / 4) /* 32 */ 188c2ecf20Sopenharmony_ci#define YRAM_DEF_SIZE (YRAM0_SIZE + YRAM1_SIZE + YRAM2_SIZE + \ 198c2ecf20Sopenharmony_ci YRAM3_SIZE + YRAM4_SIZE) 208c2ecf20Sopenharmony_ci#define YRAM_FIR_SIZE (0x0400 / 4) /* 256 */ 218c2ecf20Sopenharmony_ci#define YRAM_IIR_SIZE (0x0200 / 4) /* 128 */ 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#define XRAM0_SIZE (0x0400 / 4) /* 256 */ 248c2ecf20Sopenharmony_ci#define XRAM1_SIZE (0x0200 / 4) /* 128 */ 258c2ecf20Sopenharmony_ci#define XRAM2_SIZE (0x0200 / 4) /* 128 */ 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci/* PRAM program array size */ 288c2ecf20Sopenharmony_ci#define PRAM0_SIZE (0x0100 / 4) /* 64 */ 298c2ecf20Sopenharmony_ci#define PRAM1_SIZE ((0x2000 - 0x0100) / 4) /* 1984 */ 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci#include <linux/types.h> 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_cistruct siu_spb_param { 348c2ecf20Sopenharmony_ci __u32 ab1a; /* input FIFO address */ 358c2ecf20Sopenharmony_ci __u32 ab0a; /* output FIFO address */ 368c2ecf20Sopenharmony_ci __u32 dir; /* 0=the ather except CPUOUTPUT, 1=CPUINPUT */ 378c2ecf20Sopenharmony_ci __u32 event; /* SPB program starting conditions */ 388c2ecf20Sopenharmony_ci __u32 stfifo; /* STFIFO register setting value */ 398c2ecf20Sopenharmony_ci __u32 trdat; /* TRDAT register setting value */ 408c2ecf20Sopenharmony_ci}; 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_cistruct siu_firmware { 438c2ecf20Sopenharmony_ci __u32 yram_fir_coeff[YRAM_FIR_SIZE]; 448c2ecf20Sopenharmony_ci __u32 pram0[PRAM0_SIZE]; 458c2ecf20Sopenharmony_ci __u32 pram1[PRAM1_SIZE]; 468c2ecf20Sopenharmony_ci __u32 yram0[YRAM0_SIZE]; 478c2ecf20Sopenharmony_ci __u32 yram1[YRAM1_SIZE]; 488c2ecf20Sopenharmony_ci __u32 yram2[YRAM2_SIZE]; 498c2ecf20Sopenharmony_ci __u32 yram3[YRAM3_SIZE]; 508c2ecf20Sopenharmony_ci __u32 yram4[YRAM4_SIZE]; 518c2ecf20Sopenharmony_ci __u32 spbpar_num; 528c2ecf20Sopenharmony_ci struct siu_spb_param spbpar[32]; 538c2ecf20Sopenharmony_ci}; 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci#ifdef __KERNEL__ 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci#include <linux/dmaengine.h> 588c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 598c2ecf20Sopenharmony_ci#include <linux/io.h> 608c2ecf20Sopenharmony_ci#include <linux/sh_dma.h> 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci#include <sound/core.h> 638c2ecf20Sopenharmony_ci#include <sound/pcm.h> 648c2ecf20Sopenharmony_ci#include <sound/soc.h> 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci#define SIU_PERIOD_BYTES_MAX 8192 /* DMA transfer/period size */ 678c2ecf20Sopenharmony_ci#define SIU_PERIOD_BYTES_MIN 256 /* DMA transfer/period size */ 688c2ecf20Sopenharmony_ci#define SIU_PERIODS_MAX 64 /* Max periods in buffer */ 698c2ecf20Sopenharmony_ci#define SIU_PERIODS_MIN 4 /* Min periods in buffer */ 708c2ecf20Sopenharmony_ci#define SIU_BUFFER_BYTES_MAX (SIU_PERIOD_BYTES_MAX * SIU_PERIODS_MAX) 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci/* SIU ports: only one can be used at a time */ 738c2ecf20Sopenharmony_cienum { 748c2ecf20Sopenharmony_ci SIU_PORT_A, 758c2ecf20Sopenharmony_ci SIU_PORT_B, 768c2ecf20Sopenharmony_ci SIU_PORT_NUM, 778c2ecf20Sopenharmony_ci}; 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci/* SIU clock configuration */ 808c2ecf20Sopenharmony_cienum { 818c2ecf20Sopenharmony_ci SIU_CLKA_PLL, 828c2ecf20Sopenharmony_ci SIU_CLKA_EXT, 838c2ecf20Sopenharmony_ci SIU_CLKB_PLL, 848c2ecf20Sopenharmony_ci SIU_CLKB_EXT 858c2ecf20Sopenharmony_ci}; 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_cistruct device; 888c2ecf20Sopenharmony_cistruct siu_info { 898c2ecf20Sopenharmony_ci struct device *dev; 908c2ecf20Sopenharmony_ci int port_id; 918c2ecf20Sopenharmony_ci u32 __iomem *pram; 928c2ecf20Sopenharmony_ci u32 __iomem *xram; 938c2ecf20Sopenharmony_ci u32 __iomem *yram; 948c2ecf20Sopenharmony_ci u32 __iomem *reg; 958c2ecf20Sopenharmony_ci struct siu_firmware fw; 968c2ecf20Sopenharmony_ci}; 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_cistruct siu_stream { 998c2ecf20Sopenharmony_ci struct work_struct work; 1008c2ecf20Sopenharmony_ci struct snd_pcm_substream *substream; 1018c2ecf20Sopenharmony_ci snd_pcm_format_t format; 1028c2ecf20Sopenharmony_ci size_t buf_bytes; 1038c2ecf20Sopenharmony_ci size_t period_bytes; 1048c2ecf20Sopenharmony_ci int cur_period; /* Period currently in dma */ 1058c2ecf20Sopenharmony_ci u32 volume; 1068c2ecf20Sopenharmony_ci snd_pcm_sframes_t xfer_cnt; /* Number of frames */ 1078c2ecf20Sopenharmony_ci u8 rw_flg; /* transfer status */ 1088c2ecf20Sopenharmony_ci /* DMA status */ 1098c2ecf20Sopenharmony_ci struct dma_chan *chan; /* DMA channel */ 1108c2ecf20Sopenharmony_ci struct dma_async_tx_descriptor *tx_desc; 1118c2ecf20Sopenharmony_ci dma_cookie_t cookie; 1128c2ecf20Sopenharmony_ci struct sh_dmae_slave param; 1138c2ecf20Sopenharmony_ci}; 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_cistruct siu_port { 1168c2ecf20Sopenharmony_ci unsigned long play_cap; /* Used to track full duplex */ 1178c2ecf20Sopenharmony_ci struct snd_pcm *pcm; 1188c2ecf20Sopenharmony_ci struct siu_stream playback; 1198c2ecf20Sopenharmony_ci struct siu_stream capture; 1208c2ecf20Sopenharmony_ci u32 stfifo; /* STFIFO value from firmware */ 1218c2ecf20Sopenharmony_ci u32 trdat; /* TRDAT value from firmware */ 1228c2ecf20Sopenharmony_ci}; 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ciextern struct siu_port *siu_ports[SIU_PORT_NUM]; 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_cistatic inline struct siu_port *siu_port_info(struct snd_pcm_substream *substream) 1278c2ecf20Sopenharmony_ci{ 1288c2ecf20Sopenharmony_ci struct platform_device *pdev = 1298c2ecf20Sopenharmony_ci to_platform_device(substream->pcm->card->dev); 1308c2ecf20Sopenharmony_ci return siu_ports[pdev->id]; 1318c2ecf20Sopenharmony_ci} 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci/* Register access */ 1348c2ecf20Sopenharmony_cistatic inline void siu_write32(u32 __iomem *addr, u32 val) 1358c2ecf20Sopenharmony_ci{ 1368c2ecf20Sopenharmony_ci __raw_writel(val, addr); 1378c2ecf20Sopenharmony_ci} 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_cistatic inline u32 siu_read32(u32 __iomem *addr) 1408c2ecf20Sopenharmony_ci{ 1418c2ecf20Sopenharmony_ci return __raw_readl(addr); 1428c2ecf20Sopenharmony_ci} 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ci/* SIU registers */ 1458c2ecf20Sopenharmony_ci#define SIU_IFCTL (0x000 / sizeof(u32)) 1468c2ecf20Sopenharmony_ci#define SIU_SRCTL (0x004 / sizeof(u32)) 1478c2ecf20Sopenharmony_ci#define SIU_SFORM (0x008 / sizeof(u32)) 1488c2ecf20Sopenharmony_ci#define SIU_CKCTL (0x00c / sizeof(u32)) 1498c2ecf20Sopenharmony_ci#define SIU_TRDAT (0x010 / sizeof(u32)) 1508c2ecf20Sopenharmony_ci#define SIU_STFIFO (0x014 / sizeof(u32)) 1518c2ecf20Sopenharmony_ci#define SIU_DPAK (0x01c / sizeof(u32)) 1528c2ecf20Sopenharmony_ci#define SIU_CKREV (0x020 / sizeof(u32)) 1538c2ecf20Sopenharmony_ci#define SIU_EVNTC (0x028 / sizeof(u32)) 1548c2ecf20Sopenharmony_ci#define SIU_SBCTL (0x040 / sizeof(u32)) 1558c2ecf20Sopenharmony_ci#define SIU_SBPSET (0x044 / sizeof(u32)) 1568c2ecf20Sopenharmony_ci#define SIU_SBFSTS (0x068 / sizeof(u32)) 1578c2ecf20Sopenharmony_ci#define SIU_SBDVCA (0x06c / sizeof(u32)) 1588c2ecf20Sopenharmony_ci#define SIU_SBDVCB (0x070 / sizeof(u32)) 1598c2ecf20Sopenharmony_ci#define SIU_SBACTIV (0x074 / sizeof(u32)) 1608c2ecf20Sopenharmony_ci#define SIU_DMAIA (0x090 / sizeof(u32)) 1618c2ecf20Sopenharmony_ci#define SIU_DMAIB (0x094 / sizeof(u32)) 1628c2ecf20Sopenharmony_ci#define SIU_DMAOA (0x098 / sizeof(u32)) 1638c2ecf20Sopenharmony_ci#define SIU_DMAOB (0x09c / sizeof(u32)) 1648c2ecf20Sopenharmony_ci#define SIU_DMAML (0x0a0 / sizeof(u32)) 1658c2ecf20Sopenharmony_ci#define SIU_SPSTS (0x0cc / sizeof(u32)) 1668c2ecf20Sopenharmony_ci#define SIU_SPCTL (0x0d0 / sizeof(u32)) 1678c2ecf20Sopenharmony_ci#define SIU_BRGASEL (0x100 / sizeof(u32)) 1688c2ecf20Sopenharmony_ci#define SIU_BRRA (0x104 / sizeof(u32)) 1698c2ecf20Sopenharmony_ci#define SIU_BRGBSEL (0x108 / sizeof(u32)) 1708c2ecf20Sopenharmony_ci#define SIU_BRRB (0x10c / sizeof(u32)) 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_ciextern const struct snd_soc_component_driver siu_component; 1738c2ecf20Sopenharmony_ciextern struct siu_info *siu_i2s_data; 1748c2ecf20Sopenharmony_ci 1758c2ecf20Sopenharmony_ciint siu_init_port(int port, struct siu_port **port_info, struct snd_card *card); 1768c2ecf20Sopenharmony_civoid siu_free_port(struct siu_port *port_info); 1778c2ecf20Sopenharmony_ci 1788c2ecf20Sopenharmony_ci#endif 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_ci#endif /* SIU_H */ 181