tools headers UAPI: Sync linux/kvm.h with the kernel sources
[linux-2.6-microblaze.git] / include / linux / pxa2xx_ssp.h
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  *  Copyright (C) 2003 Russell King, All Rights Reserved.
4  *
5  * This driver supports the following PXA CPU/SSP ports:-
6  *
7  *       PXA250     SSP
8  *       PXA255     SSP, NSSP
9  *       PXA26x     SSP, NSSP, ASSP
10  *       PXA27x     SSP1, SSP2, SSP3
11  *       PXA3xx     SSP1, SSP2, SSP3, SSP4
12  */
13
14 #ifndef __LINUX_SSP_H
15 #define __LINUX_SSP_H
16
17 #include <linux/bits.h>
18 #include <linux/compiler_types.h>
19 #include <linux/io.h>
20 #include <linux/kconfig.h>
21 #include <linux/list.h>
22 #include <linux/types.h>
23
24 struct clk;
25 struct device;
26 struct device_node;
27
28 /*
29  * SSP Serial Port Registers
30  * PXA250, PXA255, PXA26x and PXA27x SSP controllers are all slightly different.
31  * PXA255, PXA26x and PXA27x have extra ports, registers and bits.
32  */
33
34 #define SSCR0           (0x00)  /* SSP Control Register 0 */
35 #define SSCR1           (0x04)  /* SSP Control Register 1 */
36 #define SSSR            (0x08)  /* SSP Status Register */
37 #define SSITR           (0x0C)  /* SSP Interrupt Test Register */
38 #define SSDR            (0x10)  /* SSP Data Write/Data Read Register */
39
40 #define SSTO            (0x28)  /* SSP Time Out Register */
41 #define DDS_RATE        (0x28)  /* SSP DDS Clock Rate Register (Intel Quark) */
42 #define SSPSP           (0x2C)  /* SSP Programmable Serial Protocol */
43 #define SSTSA           (0x30)  /* SSP Tx Timeslot Active */
44 #define SSRSA           (0x34)  /* SSP Rx Timeslot Active */
45 #define SSTSS           (0x38)  /* SSP Timeslot Status */
46 #define SSACD           (0x3C)  /* SSP Audio Clock Divider */
47 #define SSACDD          (0x40)  /* SSP Audio Clock Dither Divider */
48
49 /* Common PXA2xx bits first */
50 #define SSCR0_DSS       GENMASK(3, 0)   /* Data Size Select (mask) */
51 #define SSCR0_DataSize(x)  ((x) - 1)    /* Data Size Select [4..16] */
52 #define SSCR0_FRF       GENMASK(5, 4)   /* FRame Format (mask) */
53 #define SSCR0_Motorola  (0x0 << 4)      /* Motorola's Serial Peripheral Interface (SPI) */
54 #define SSCR0_TI        (0x1 << 4)      /* Texas Instruments' Synchronous Serial Protocol (SSP) */
55 #define SSCR0_National  (0x2 << 4)      /* National Microwire */
56 #define SSCR0_ECS       BIT(6)          /* External clock select */
57 #define SSCR0_SSE       BIT(7)          /* Synchronous Serial Port Enable */
58 #define SSCR0_SCR(x)    ((x) << 8)      /* Serial Clock Rate (mask) */
59
60 /* PXA27x, PXA3xx */
61 #define SSCR0_EDSS      BIT(20)         /* Extended data size select */
62 #define SSCR0_NCS       BIT(21)         /* Network clock select */
63 #define SSCR0_RIM       BIT(22)         /* Receive FIFO overrrun interrupt mask */
64 #define SSCR0_TUM       BIT(23)         /* Transmit FIFO underrun interrupt mask */
65 #define SSCR0_FRDC      GENMASK(26, 24) /* Frame rate divider control (mask) */
66 #define SSCR0_SlotsPerFrm(x) (((x) - 1) << 24)  /* Time slots per frame [1..8] */
67 #define SSCR0_FPCKE     BIT(29)         /* FIFO packing enable */
68 #define SSCR0_ACS       BIT(30)         /* Audio clock select */
69 #define SSCR0_MOD       BIT(31)         /* Mode (normal or network) */
70
71 #define SSCR1_RIE       BIT(0)          /* Receive FIFO Interrupt Enable */
72 #define SSCR1_TIE       BIT(1)          /* Transmit FIFO Interrupt Enable */
73 #define SSCR1_LBM       BIT(2)          /* Loop-Back Mode */
74 #define SSCR1_SPO       BIT(3)          /* Motorola SPI SSPSCLK polarity setting */
75 #define SSCR1_SPH       BIT(4)          /* Motorola SPI SSPSCLK phase setting */
76 #define SSCR1_MWDS      BIT(5)          /* Microwire Transmit Data Size */
77
78 #define SSSR_ALT_FRM_MASK       GENMASK(1, 0)   /* Masks the SFRM signal number */
79 #define SSSR_TNF                BIT(2)          /* Transmit FIFO Not Full */
80 #define SSSR_RNE                BIT(3)          /* Receive FIFO Not Empty */
81 #define SSSR_BSY                BIT(4)          /* SSP Busy */
82 #define SSSR_TFS                BIT(5)          /* Transmit FIFO Service Request */
83 #define SSSR_RFS                BIT(6)          /* Receive FIFO Service Request */
84 #define SSSR_ROR                BIT(7)          /* Receive FIFO Overrun */
85
86 #define RX_THRESH_DFLT  8
87 #define TX_THRESH_DFLT  8
88
89 #define SSSR_TFL_MASK   GENMASK(11, 8)  /* Transmit FIFO Level mask */
90 #define SSSR_RFL_MASK   GENMASK(15, 12) /* Receive FIFO Level mask */
91
92 #define SSCR1_TFT       GENMASK(9, 6)   /* Transmit FIFO Threshold (mask) */
93 #define SSCR1_TxTresh(x) (((x) - 1) << 6)       /* level [1..16] */
94 #define SSCR1_RFT       GENMASK(13, 10) /* Receive FIFO Threshold (mask) */
95 #define SSCR1_RxTresh(x) (((x) - 1) << 10)      /* level [1..16] */
96
97 #define RX_THRESH_CE4100_DFLT   2
98 #define TX_THRESH_CE4100_DFLT   2
99
100 #define CE4100_SSSR_TFL_MASK    GENMASK(9, 8)   /* Transmit FIFO Level mask */
101 #define CE4100_SSSR_RFL_MASK    GENMASK(13, 12) /* Receive FIFO Level mask */
102
103 #define CE4100_SSCR1_TFT        GENMASK(7, 6)   /* Transmit FIFO Threshold (mask) */
104 #define CE4100_SSCR1_TxTresh(x) (((x) - 1) << 6)        /* level [1..4] */
105 #define CE4100_SSCR1_RFT        GENMASK(11, 10) /* Receive FIFO Threshold (mask) */
106 #define CE4100_SSCR1_RxTresh(x) (((x) - 1) << 10)       /* level [1..4] */
107
108 /* QUARK_X1000 SSCR0 bit definition */
109 #define QUARK_X1000_SSCR0_DSS           GENMASK(4, 0)   /* Data Size Select (mask) */
110 #define QUARK_X1000_SSCR0_DataSize(x)   ((x) - 1)       /* Data Size Select [4..32] */
111 #define QUARK_X1000_SSCR0_FRF           GENMASK(6, 5)   /* FRame Format (mask) */
112 #define QUARK_X1000_SSCR0_Motorola      (0x0 << 5)      /* Motorola's Serial Peripheral Interface (SPI) */
113
114 #define RX_THRESH_QUARK_X1000_DFLT      1
115 #define TX_THRESH_QUARK_X1000_DFLT      16
116
117 #define QUARK_X1000_SSSR_TFL_MASK       GENMASK(12, 8)  /* Transmit FIFO Level mask */
118 #define QUARK_X1000_SSSR_RFL_MASK       GENMASK(17, 13) /* Receive FIFO Level mask */
119
120 #define QUARK_X1000_SSCR1_TFT   GENMASK(10, 6)  /* Transmit FIFO Threshold (mask) */
121 #define QUARK_X1000_SSCR1_TxTresh(x) (((x) - 1) << 6)   /* level [1..32] */
122 #define QUARK_X1000_SSCR1_RFT   GENMASK(15, 11) /* Receive FIFO Threshold (mask) */
123 #define QUARK_X1000_SSCR1_RxTresh(x) (((x) - 1) << 11)  /* level [1..32] */
124 #define QUARK_X1000_SSCR1_EFWR  BIT(16)         /* Enable FIFO Write/Read */
125 #define QUARK_X1000_SSCR1_STRF  BIT(17)         /* Select FIFO or EFWR */
126
127 /* extra bits in PXA255, PXA26x and PXA27x SSP ports */
128 #define SSCR0_TISSP             (1 << 4)        /* TI Sync Serial Protocol */
129 #define SSCR0_PSP               (3 << 4)        /* PSP - Programmable Serial Protocol */
130
131 #define SSCR1_EFWR              BIT(14)         /* Enable FIFO Write/Read */
132 #define SSCR1_STRF              BIT(15)         /* Select FIFO or EFWR */
133 #define SSCR1_IFS               BIT(16)         /* Invert Frame Signal */
134 #define SSCR1_PINTE             BIT(18)         /* Peripheral Trailing Byte Interrupt Enable */
135 #define SSCR1_TINTE             BIT(19)         /* Receiver Time-out Interrupt enable */
136 #define SSCR1_RSRE              BIT(20)         /* Receive Service Request Enable */
137 #define SSCR1_TSRE              BIT(21)         /* Transmit Service Request Enable */
138 #define SSCR1_TRAIL             BIT(22)         /* Trailing Byte */
139 #define SSCR1_RWOT              BIT(23)         /* Receive Without Transmit */
140 #define SSCR1_SFRMDIR           BIT(24)         /* Frame Direction */
141 #define SSCR1_SCLKDIR           BIT(25)         /* Serial Bit Rate Clock Direction */
142 #define SSCR1_ECRB              BIT(26)         /* Enable Clock request B */
143 #define SSCR1_ECRA              BIT(27)         /* Enable Clock Request A */
144 #define SSCR1_SCFR              BIT(28)         /* Slave Clock free Running */
145 #define SSCR1_EBCEI             BIT(29)         /* Enable Bit Count Error interrupt */
146 #define SSCR1_TTE               BIT(30)         /* TXD Tristate Enable */
147 #define SSCR1_TTELP             BIT(31)         /* TXD Tristate Enable Last Phase */
148
149 #define SSSR_PINT               BIT(18)         /* Peripheral Trailing Byte Interrupt */
150 #define SSSR_TINT               BIT(19)         /* Receiver Time-out Interrupt */
151 #define SSSR_EOC                BIT(20)         /* End Of Chain */
152 #define SSSR_TUR                BIT(21)         /* Transmit FIFO Under Run */
153 #define SSSR_CSS                BIT(22)         /* Clock Synchronisation Status */
154 #define SSSR_BCE                BIT(23)         /* Bit Count Error */
155
156 #define SSPSP_SCMODE(x)         ((x) << 0)      /* Serial Bit Rate Clock Mode */
157 #define SSPSP_SFRMP             BIT(2)          /* Serial Frame Polarity */
158 #define SSPSP_ETDS              BIT(3)          /* End of Transfer data State */
159 #define SSPSP_STRTDLY(x)        ((x) << 4)      /* Start Delay */
160 #define SSPSP_DMYSTRT(x)        ((x) << 7)      /* Dummy Start */
161 #define SSPSP_SFRMDLY(x)        ((x) << 9)      /* Serial Frame Delay */
162 #define SSPSP_SFRMWDTH(x)       ((x) << 16)     /* Serial Frame Width */
163 #define SSPSP_DMYSTOP(x)        ((x) << 23)     /* Dummy Stop */
164 #define SSPSP_FSRT              BIT(25)         /* Frame Sync Relative Timing */
165
166 /* PXA3xx */
167 #define SSPSP_EDMYSTRT(x)       ((x) << 26)     /* Extended Dummy Start */
168 #define SSPSP_EDMYSTOP(x)       ((x) << 28)     /* Extended Dummy Stop */
169 #define SSPSP_TIMING_MASK       (0x7f8001f0)
170
171 #define SSACD_ACDS(x)           ((x) << 0)      /* Audio clock divider select */
172 #define SSACD_ACDS_1            (0)
173 #define SSACD_ACDS_2            (1)
174 #define SSACD_ACDS_4            (2)
175 #define SSACD_ACDS_8            (3)
176 #define SSACD_ACDS_16           (4)
177 #define SSACD_ACDS_32           (5)
178 #define SSACD_SCDB              BIT(3)          /* SSPSYSCLK Divider Bypass */
179 #define SSACD_SCDB_4X           (0)
180 #define SSACD_SCDB_1X           (1)
181 #define SSACD_ACPS(x)           ((x) << 4)      /* Audio clock PLL select */
182 #define SSACD_SCDX8             BIT(7)          /* SYSCLK division ratio select */
183
184 /* LPSS SSP */
185 #define SSITF                   0x44            /* TX FIFO trigger level */
186 #define SSITF_TxHiThresh(x)     (((x) - 1) << 0)
187 #define SSITF_TxLoThresh(x)     (((x) - 1) << 8)
188
189 #define SSIRF                   0x48            /* RX FIFO trigger level */
190 #define SSIRF_RxThresh(x)       ((x) - 1)
191
192 /* LPT/WPT SSP */
193 #define SSCR2           (0x40)  /* SSP Command / Status 2 */
194 #define SSPSP2          (0x44)  /* SSP Programmable Serial Protocol 2 */
195
196 enum pxa_ssp_type {
197         SSP_UNDEFINED = 0,
198         PXA25x_SSP,  /* pxa 210, 250, 255, 26x */
199         PXA25x_NSSP, /* pxa 255, 26x (including ASSP) */
200         PXA27x_SSP,
201         PXA3xx_SSP,
202         PXA168_SSP,
203         MMP2_SSP,
204         PXA910_SSP,
205         CE4100_SSP,
206         QUARK_X1000_SSP,
207         LPSS_LPT_SSP, /* Keep LPSS types sorted with lpss_platforms[] */
208         LPSS_BYT_SSP,
209         LPSS_BSW_SSP,
210         LPSS_SPT_SSP,
211         LPSS_BXT_SSP,
212         LPSS_CNL_SSP,
213 };
214
215 struct ssp_device {
216         struct device   *dev;
217         struct list_head        node;
218
219         struct clk      *clk;
220         void __iomem    *mmio_base;
221         unsigned long   phys_base;
222
223         const char      *label;
224         int             port_id;
225         enum pxa_ssp_type type;
226         int             use_count;
227         int             irq;
228
229         struct device_node      *of_node;
230 };
231
232 /**
233  * pxa_ssp_write_reg - Write to a SSP register
234  *
235  * @dev: SSP device to access
236  * @reg: Register to write to
237  * @val: Value to be written.
238  */
239 static inline void pxa_ssp_write_reg(struct ssp_device *dev, u32 reg, u32 val)
240 {
241         __raw_writel(val, dev->mmio_base + reg);
242 }
243
244 /**
245  * pxa_ssp_read_reg - Read from a SSP register
246  *
247  * @dev: SSP device to access
248  * @reg: Register to read from
249  */
250 static inline u32 pxa_ssp_read_reg(struct ssp_device *dev, u32 reg)
251 {
252         return __raw_readl(dev->mmio_base + reg);
253 }
254
255 #if IS_ENABLED(CONFIG_PXA_SSP)
256 struct ssp_device *pxa_ssp_request(int port, const char *label);
257 void pxa_ssp_free(struct ssp_device *);
258 struct ssp_device *pxa_ssp_request_of(const struct device_node *of_node,
259                                       const char *label);
260 #else
261 static inline struct ssp_device *pxa_ssp_request(int port, const char *label)
262 {
263         return NULL;
264 }
265 static inline struct ssp_device *pxa_ssp_request_of(const struct device_node *n,
266                                                     const char *name)
267 {
268         return NULL;
269 }
270 static inline void pxa_ssp_free(struct ssp_device *ssp) {}
271 #endif
272
273 #endif