CR_3025_Hibernation_TDM_Walker.chen
[platform/kernel/linux-starfive.git] / sound / soc / starfive / starfive_tdm.h
1 /* SPDX-License-Identifier: GPL-2.0
2  *
3  * TDM driver for the StarFive JH7110 SoC
4  *
5  * Copyright (C) 2021 StarFive Technology Co., Ltd.
6  */
7 #ifndef __SND_SOC_STARFIVE_TDM_H
8 #define __SND_SOC_STARFIVE_TDM_H
9
10 #include <linux/clk.h>
11 #include <linux/device.h>
12 #include <linux/types.h>
13 #include <sound/dmaengine_pcm.h>
14 #include <sound/pcm.h>
15 #include <linux/dmaengine.h>
16 #include <linux/types.h>
17
18 #define TDM_PCMGBCR                     0x00
19         #define PCMGBCR_MASK            0x1e
20         #define PCMGBCR_ENABLE          BIT(0)
21         #define PCMGBCR_TRITXEN         BIT(4)
22         #define CLKPOL_BIT              5
23         #define TRITXEN_BIT             4
24         #define ELM_BIT                 3
25         #define SYNCM_BIT               2
26         #define MS_BIT                  1
27 #define TDM_PCMTXCR                     0x04
28         #define PCMTXCR_TXEN            BIT(0)
29         #define IFL_BIT                 11
30         #define WL_BIT                  8
31         #define SSCALE_BIT              4
32         #define SL_BIT                  2
33         #define LRJ_BIT                 1
34 #define TDM_PCMRXCR                     0x08
35         #define PCMRXCR_RXEN            BIT(0)
36         #define PCMRXCR_RXSL_MASK       0xc
37         #define PCMRXCR_RXSL_16BIT      0x4
38         #define PCMRXCR_RXSL_32BIT      0x8
39         #define PCMRXCR_SCALE_MASK      0xf0
40         #define PCMRXCR_SCALE_1CH       0x10
41 #define TDM_PCMDIV                      0x0c
42
43 /*  DMA registers */
44 #define TDM_FIFO                        0x170c0000
45 #define TDM_FIFO_DEPTH                  32
46
47 #define ONE_CHANNEL_SUPPORT             1
48 #define TWO_CHANNEL_SUPPORT             2
49 #define FOUR_CHANNEL_SUPPORT            4
50 #define SIX_CHANNEL_SUPPORT             6
51 #define EIGHT_CHANNEL_SUPPORT           8
52
53 enum TDM_MASTER_SLAVE_MODE {
54         TDM_AS_MASTER = 0,
55         TDM_AS_SLAVE,
56 };
57
58 enum TDM_CLKPOL {
59         /* tx raising and rx falling */
60         TDM_TX_RASING_RX_FALLING = 0,
61         /* tx falling and rx raising */
62         TDM_TX_FALLING_RX_RASING,
63 };
64
65 enum TDM_FRAME_MODE {
66         SHORT_EARLY = 0,
67         SHORT_LATER,
68         LONG,
69 };
70
71 enum TDM_ELM {
72         /* only work while SYNCM=0 */
73         TDM_ELM_LATE = 0,
74         TDM_ELM_EARLY,
75 };
76
77 enum TDM_SYNCM {
78         /* short frame sync */
79         TDM_SYNCM_SHORT = 0,
80         /* long frame sync */
81         TDM_SYNCM_LONG,
82 };
83
84 enum TDM_IFL {
85         /* FIFO to send or received : half-1/2, Quarter-1/4 */
86         TDM_FIFO_HALF = 0,
87         TDM_FIFO_QUARTER,
88 };
89
90 enum TDM_WL {
91         /* send or received word length */
92         TDM_8BIT_WORD_LEN = 0,
93         TDM_16BIT_WORD_LEN,
94         TDM_20BIT_WORD_LEN,
95         TDM_24BIT_WORD_LEN,
96         TDM_32BIT_WORD_LEN,
97 };
98
99 enum TDM_SL {
100         /* send or received slot length */
101         TDM_8BIT_SLOT_LEN = 0,
102         TDM_16BIT_SLOT_LEN,
103         TDM_32BIT_SLOT_LEN,
104 };
105
106 enum TDM_LRJ {
107         /* left-justify or right-justify */
108         TDM_RIGHT_JUSTIFY = 0,
109         TDM_LEFT_JUSTIFT,
110 };
111
112 typedef struct tdm_chan_cfg {
113         enum TDM_IFL ifl;
114         enum TDM_WL  wl;
115         unsigned char sscale;
116         enum TDM_SL  sl;
117         enum TDM_LRJ lrj;
118         unsigned char enable;
119 } tdm_chan_cfg_t;
120
121 struct sf_tdm_dev {
122         void __iomem *tdm_base;
123         struct device *dev;
124         struct clk *clk_ahb0;
125         struct clk *clk_tdm_ahb;
126         struct clk *clk_apb0;
127         struct clk *clk_tdm_apb;
128         struct clk *clk_tdm_internal;
129         struct clk *clk_tdm_ext;
130         struct clk *clk_tdm;
131         struct clk *clk_mclk_inner;
132         struct reset_control *resets;
133         int active;
134         
135         enum TDM_CLKPOL clkpolity;
136         enum TDM_ELM    elm;
137         enum TDM_SYNCM  syncm;
138         enum TDM_MASTER_SLAVE_MODE ms_mode;
139         enum TDM_FRAME_MODE frame_mode;
140         unsigned char   tritxen;
141         
142         tdm_chan_cfg_t tx;
143         tdm_chan_cfg_t rx;
144         
145         u16 syncdiv;
146         u32 samplerate;
147         u32 pcmclk;
148
149         /* data related to DMA transfers b/w tdm and DMAC */
150         struct snd_dmaengine_dai_dma_data play_dma_data;
151         struct snd_dmaengine_dai_dma_data capture_dma_data;
152         u32 saved_reg_value[4];
153 };
154
155 #endif  /* __SND_SOC_STARFIVE_TDM_H */