forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/sound/soc/stm/stm32_sai.h
....@@ -1,19 +1,9 @@
1
+/* SPDX-License-Identifier: GPL-2.0-only */
12 /*
23 * STM32 ALSA SoC Digital Audio Interface (SAI) driver.
34 *
45 * Copyright (C) 2016, STMicroelectronics - All Rights Reserved
56 * Author(s): Olivier Moysan <olivier.moysan@st.com> for STMicroelectronics.
6
- *
7
- * License terms: GPL V2.0.
8
- *
9
- * This program is free software; you can redistribute it and/or modify it
10
- * under the terms of the GNU General Public License version 2 as published by
11
- * the Free Software Foundation.
12
- *
13
- * This program is distributed in the hope that it will be useful, but
14
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16
- * details.
177 */
188
199 #include <linux/bitfield.h>
....@@ -36,6 +26,12 @@
3626 /* Sub-block A registers, relative to sub-block A address */
3727 #define STM_SAI_PDMCR_REGX 0x40
3828 #define STM_SAI_PDMLY_REGX 0x44
29
+
30
+/* Hardware configuration registers */
31
+#define STM_SAI_HWCFGR 0x3F0
32
+#define STM_SAI_VERR 0x3F4
33
+#define STM_SAI_IDR 0x3F8
34
+#define STM_SAI_SIDR 0x3FC
3935
4036 /******************** Bit definition for SAI_GCR register *******************/
4137 #define SAI_GCR_SYNCIN_SHIFT 0
....@@ -82,7 +78,7 @@
8278 #define SAI_XCR1_NODIV BIT(SAI_XCR1_NODIV_SHIFT)
8379
8480 #define SAI_XCR1_MCKDIV_SHIFT 20
85
-#define SAI_XCR1_MCKDIV_WIDTH(x) (((x) == SAI_STM32F4) ? 4 : 6)
81
+#define SAI_XCR1_MCKDIV_WIDTH(x) (((x) == STM_SAI_STM32F4) ? 4 : 6)
8682 #define SAI_XCR1_MCKDIV_MASK(x) GENMASK((SAI_XCR1_MCKDIV_SHIFT + (x) - 1),\
8783 SAI_XCR1_MCKDIV_SHIFT)
8884 #define SAI_XCR1_MCKDIV_SET(x) ((x) << SAI_XCR1_MCKDIV_SHIFT)
....@@ -90,6 +86,9 @@
9086
9187 #define SAI_XCR1_OSR_SHIFT 26
9288 #define SAI_XCR1_OSR BIT(SAI_XCR1_OSR_SHIFT)
89
+
90
+#define SAI_XCR1_MCKEN_SHIFT 27
91
+#define SAI_XCR1_MCKEN BIT(SAI_XCR1_MCKEN_SHIFT)
9392
9493 /******************* Bit definition for SAI_XCR2 register *******************/
9594 #define SAI_XCR2_FTH_SHIFT 0
....@@ -231,8 +230,33 @@
231230 #define SAI_PDMDLY_4R_MASK GENMASK(30, SAI_PDMDLY_4R_SHIFT)
232231 #define SAI_PDMDLY_4R_WIDTH 3
233232
234
-#define STM_SAI_IS_F4(ip) ((ip)->conf->version == SAI_STM32F4)
235
-#define STM_SAI_IS_H7(ip) ((ip)->conf->version == SAI_STM32H7)
233
+/* Registers below apply to SAI version 2.1 and more */
234
+
235
+/* Bit definition for SAI_HWCFGR register */
236
+#define SAI_HWCFGR_FIFO_SIZE GENMASK(7, 0)
237
+#define SAI_HWCFGR_SPDIF_PDM GENMASK(11, 8)
238
+#define SAI_HWCFGR_REGOUT GENMASK(19, 12)
239
+
240
+/* Bit definition for SAI_VERR register */
241
+#define SAI_VERR_MIN_MASK GENMASK(3, 0)
242
+#define SAI_VERR_MAJ_MASK GENMASK(7, 4)
243
+
244
+/* Bit definition for SAI_IDR register */
245
+#define SAI_IDR_ID_MASK GENMASK(31, 0)
246
+
247
+/* Bit definition for SAI_SIDR register */
248
+#define SAI_SIDR_ID_MASK GENMASK(31, 0)
249
+
250
+#define SAI_IPIDR_NUMBER 0x00130031
251
+
252
+/* SAI version numbers are 1.x for F4. Major version number set to 1 for F4 */
253
+#define STM_SAI_STM32F4 BIT(4)
254
+/* Dummy version number for H7 socs and next */
255
+#define STM_SAI_STM32H7 0x0
256
+
257
+#define STM_SAI_IS_F4(ip) ((ip)->conf.version == STM_SAI_STM32F4)
258
+#define STM_SAI_HAS_SPDIF_PDM(ip)\
259
+ ((ip)->pdata->conf.has_spdif_pdm)
236260
237261 enum stm32_sai_syncout {
238262 STM_SAI_SYNC_OUT_NONE,
....@@ -240,19 +264,16 @@
240264 STM_SAI_SYNC_OUT_B,
241265 };
242266
243
-enum stm32_sai_version {
244
- SAI_STM32F4,
245
- SAI_STM32H7
246
-};
247
-
248267 /**
249268 * struct stm32_sai_conf - SAI configuration
250269 * @version: SAI version
251
- * @has_spdif: SAI S/PDIF support flag
270
+ * @fifo_size: SAI fifo size as words number
271
+ * @has_spdif_pdm: SAI S/PDIF and PDM features support flag
252272 */
253273 struct stm32_sai_conf {
254
- int version;
255
- bool has_spdif;
274
+ u32 version;
275
+ u32 fifo_size;
276
+ bool has_spdif_pdm;
256277 };
257278
258279 /**
....@@ -262,9 +283,10 @@
262283 * @pclk: SAI bus clock
263284 * @clk_x8k: SAI parent clock for sampling frequencies multiple of 8kHz
264285 * @clk_x11k: SAI parent clock for sampling frequencies multiple of 11kHz
265
- * @version: SOC version
286
+ * @conf: SAI hardware capabitilites
266287 * @irq: SAI interrupt line
267288 * @set_sync: pointer to synchro mode configuration callback
289
+ * @gcr: SAI Global Configuration Register
268290 */
269291 struct stm32_sai_data {
270292 struct platform_device *pdev;
....@@ -272,8 +294,9 @@
272294 struct clk *pclk;
273295 struct clk *clk_x8k;
274296 struct clk *clk_x11k;
275
- struct stm32_sai_conf *conf;
297
+ struct stm32_sai_conf conf;
276298 int irq;
277299 int (*set_sync)(struct stm32_sai_data *sai,
278300 struct device_node *np_provider, int synco, int synci);
301
+ u32 gcr;
279302 };