Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0+
0002 //
0003 // siu.h - ALSA SoC driver for Renesas SH7343, SH7722 SIU peripheral.
0004 //
0005 // Copyright (C) 2009-2010 Guennadi Liakhovetski <g.liakhovetski@gmx.de>
0006 // Copyright (C) 2006 Carlos Munoz <carlos@kenati.com>
0007 
0008 #ifndef SIU_H
0009 #define SIU_H
0010 
0011 /* Common kernel and user-space firmware-building defines and types */
0012 
0013 #define YRAM0_SIZE      (0x0040 / 4)        /* 16 */
0014 #define YRAM1_SIZE      (0x0080 / 4)        /* 32 */
0015 #define YRAM2_SIZE      (0x0040 / 4)        /* 16 */
0016 #define YRAM3_SIZE      (0x0080 / 4)        /* 32 */
0017 #define YRAM4_SIZE      (0x0080 / 4)        /* 32 */
0018 #define YRAM_DEF_SIZE       (YRAM0_SIZE + YRAM1_SIZE + YRAM2_SIZE + \
0019                  YRAM3_SIZE + YRAM4_SIZE)
0020 #define YRAM_FIR_SIZE       (0x0400 / 4)        /* 256 */
0021 #define YRAM_IIR_SIZE       (0x0200 / 4)        /* 128 */
0022 
0023 #define XRAM0_SIZE      (0x0400 / 4)        /* 256 */
0024 #define XRAM1_SIZE      (0x0200 / 4)        /* 128 */
0025 #define XRAM2_SIZE      (0x0200 / 4)        /* 128 */
0026 
0027 /* PRAM program array size */
0028 #define PRAM0_SIZE      (0x0100 / 4)        /* 64 */
0029 #define PRAM1_SIZE      ((0x2000 - 0x0100) / 4) /* 1984 */
0030 
0031 #include <linux/types.h>
0032 
0033 struct siu_spb_param {
0034     __u32   ab1a;   /* input FIFO address */
0035     __u32   ab0a;   /* output FIFO address */
0036     __u32   dir;    /* 0=the ather except CPUOUTPUT, 1=CPUINPUT */
0037     __u32   event;  /* SPB program starting conditions */
0038     __u32   stfifo; /* STFIFO register setting value */
0039     __u32   trdat;  /* TRDAT register setting value */
0040 };
0041 
0042 struct siu_firmware {
0043     __u32           yram_fir_coeff[YRAM_FIR_SIZE];
0044     __u32           pram0[PRAM0_SIZE];
0045     __u32           pram1[PRAM1_SIZE];
0046     __u32           yram0[YRAM0_SIZE];
0047     __u32           yram1[YRAM1_SIZE];
0048     __u32           yram2[YRAM2_SIZE];
0049     __u32           yram3[YRAM3_SIZE];
0050     __u32           yram4[YRAM4_SIZE];
0051     __u32           spbpar_num;
0052     struct siu_spb_param    spbpar[32];
0053 };
0054 
0055 #ifdef __KERNEL__
0056 
0057 #include <linux/dmaengine.h>
0058 #include <linux/interrupt.h>
0059 #include <linux/io.h>
0060 #include <linux/sh_dma.h>
0061 
0062 #include <sound/core.h>
0063 #include <sound/pcm.h>
0064 #include <sound/soc.h>
0065 
0066 #define SIU_PERIOD_BYTES_MAX    8192        /* DMA transfer/period size */
0067 #define SIU_PERIOD_BYTES_MIN    256     /* DMA transfer/period size */
0068 #define SIU_PERIODS_MAX     64      /* Max periods in buffer */
0069 #define SIU_PERIODS_MIN     4       /* Min periods in buffer */
0070 #define SIU_BUFFER_BYTES_MAX    (SIU_PERIOD_BYTES_MAX * SIU_PERIODS_MAX)
0071 
0072 /* SIU ports: only one can be used at a time */
0073 enum {
0074     SIU_PORT_A,
0075     SIU_PORT_B,
0076     SIU_PORT_NUM,
0077 };
0078 
0079 /* SIU clock configuration */
0080 enum {
0081     SIU_CLKA_PLL,
0082     SIU_CLKA_EXT,
0083     SIU_CLKB_PLL,
0084     SIU_CLKB_EXT
0085 };
0086 
0087 struct device;
0088 struct siu_info {
0089     struct device       *dev;
0090     int         port_id;
0091     u32 __iomem     *pram;
0092     u32 __iomem     *xram;
0093     u32 __iomem     *yram;
0094     u32 __iomem     *reg;
0095     struct siu_firmware fw;
0096 };
0097 
0098 struct siu_stream {
0099     struct work_struct      work;
0100     struct snd_pcm_substream    *substream;
0101     snd_pcm_format_t        format;
0102     size_t              buf_bytes;
0103     size_t              period_bytes;
0104     int             cur_period; /* Period currently in dma */
0105     u32             volume;
0106     snd_pcm_sframes_t       xfer_cnt;   /* Number of frames */
0107     u8              rw_flg;     /* transfer status */
0108     /* DMA status */
0109     struct dma_chan         *chan;      /* DMA channel */
0110     struct dma_async_tx_descriptor  *tx_desc;
0111     dma_cookie_t            cookie;
0112     struct sh_dmae_slave        param;
0113 };
0114 
0115 struct siu_port {
0116     unsigned long       play_cap;   /* Used to track full duplex */
0117     struct snd_pcm      *pcm;
0118     struct siu_stream   playback;
0119     struct siu_stream   capture;
0120     u32         stfifo;     /* STFIFO value from firmware */
0121     u32         trdat;      /* TRDAT value from firmware */
0122 };
0123 
0124 extern struct siu_port *siu_ports[SIU_PORT_NUM];
0125 
0126 static inline struct siu_port *siu_port_info(struct snd_pcm_substream *substream)
0127 {
0128     struct platform_device *pdev =
0129         to_platform_device(substream->pcm->card->dev);
0130     return siu_ports[pdev->id];
0131 }
0132 
0133 /* Register access */
0134 static inline void siu_write32(u32 __iomem *addr, u32 val)
0135 {
0136     __raw_writel(val, addr);
0137 }
0138 
0139 static inline u32 siu_read32(u32 __iomem *addr)
0140 {
0141     return __raw_readl(addr);
0142 }
0143 
0144 /* SIU registers */
0145 #define SIU_IFCTL   (0x000 / sizeof(u32))
0146 #define SIU_SRCTL   (0x004 / sizeof(u32))
0147 #define SIU_SFORM   (0x008 / sizeof(u32))
0148 #define SIU_CKCTL   (0x00c / sizeof(u32))
0149 #define SIU_TRDAT   (0x010 / sizeof(u32))
0150 #define SIU_STFIFO  (0x014 / sizeof(u32))
0151 #define SIU_DPAK    (0x01c / sizeof(u32))
0152 #define SIU_CKREV   (0x020 / sizeof(u32))
0153 #define SIU_EVNTC   (0x028 / sizeof(u32))
0154 #define SIU_SBCTL   (0x040 / sizeof(u32))
0155 #define SIU_SBPSET  (0x044 / sizeof(u32))
0156 #define SIU_SBFSTS  (0x068 / sizeof(u32))
0157 #define SIU_SBDVCA  (0x06c / sizeof(u32))
0158 #define SIU_SBDVCB  (0x070 / sizeof(u32))
0159 #define SIU_SBACTIV (0x074 / sizeof(u32))
0160 #define SIU_DMAIA   (0x090 / sizeof(u32))
0161 #define SIU_DMAIB   (0x094 / sizeof(u32))
0162 #define SIU_DMAOA   (0x098 / sizeof(u32))
0163 #define SIU_DMAOB   (0x09c / sizeof(u32))
0164 #define SIU_DMAML   (0x0a0 / sizeof(u32))
0165 #define SIU_SPSTS   (0x0cc / sizeof(u32))
0166 #define SIU_SPCTL   (0x0d0 / sizeof(u32))
0167 #define SIU_BRGASEL (0x100 / sizeof(u32))
0168 #define SIU_BRRA    (0x104 / sizeof(u32))
0169 #define SIU_BRGBSEL (0x108 / sizeof(u32))
0170 #define SIU_BRRB    (0x10c / sizeof(u32))
0171 
0172 extern const struct snd_soc_component_driver siu_component;
0173 extern struct siu_info *siu_i2s_data;
0174 
0175 int siu_init_port(int port, struct siu_port **port_info, struct snd_card *card);
0176 void siu_free_port(struct siu_port *port_info);
0177 
0178 #endif
0179 
0180 #endif /* SIU_H */