xref: /linux/include/sound/sdca_fdl.h (revision 59e6295fac26b8e85c1ea859cdd89fa1e47519d7)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * The MIPI SDCA specification is available for public downloads at
4  * https://www.mipi.org/mipi-sdca-v1-0-download
5  *
6  * Copyright (C) 2025 Cirrus Logic, Inc. and
7  *                    Cirrus Logic International Semiconductor Ltd.
8  */
9 
10 #ifndef __SDCA_FDL_H__
11 #define __SDCA_FDL_H__
12 
13 #include <linux/completion.h>
14 #include <linux/workqueue.h>
15 
16 struct device;
17 struct regmap;
18 struct sdca_fdl_set;
19 struct sdca_function_data;
20 struct sdca_interrupt;
21 struct sdca_interrupt_info;
22 
23 /**
24  * struct fdl_state - FDL state structure to keep data between interrupts
25  * @begin: Completion indicating the start of an FDL download cycle.
26  * @done: Completion indicating the end of an FDL download cycle.
27  * @timeout: Delayed work used for timing out UMP transactions.
28  * @lock: Mutex to protect between the timeout work and IRQ handlers.
29  * @interrupt: Pointer to the interrupt struct to which this FDL is attached.
30  * @set: Pointer to the FDL set currently being downloaded.
31  * @file_index: Index of the current file being processed.
32  */
33 struct fdl_state {
34 	struct completion begin;
35 	struct completion done;
36 	struct delayed_work timeout;
37 	struct mutex lock;
38 
39 	struct sdca_interrupt *interrupt;
40 	struct sdca_fdl_set *set;
41 	int file_index;
42 };
43 
44 #define SDCA_CTL_XU_FDLH_COMPLETE	0
45 #define SDCA_CTL_XU_FDLH_MORE_FILES	SDCA_CTL_XU_FDLH_SET_IN_PROGRESS
46 #define SDCA_CTL_XU_FDLH_FILE_AVAILABLE	(SDCA_CTL_XU_FDLH_TRANSFERRED_FILE | \
47 					 SDCA_CTL_XU_FDLH_SET_IN_PROGRESS)
48 #define SDCA_CTL_XU_FDLH_MASK		(SDCA_CTL_XU_FDLH_TRANSFERRED_CHUNK | \
49 					 SDCA_CTL_XU_FDLH_TRANSFERRED_FILE | \
50 					 SDCA_CTL_XU_FDLH_SET_IN_PROGRESS | \
51 					 SDCA_CTL_XU_FDLH_RESET_ACK | \
52 					 SDCA_CTL_XU_FDLH_REQ_ABORT)
53 
54 #define SDCA_CTL_XU_FDLD_COMPLETE	0
55 #define SDCA_CTL_XU_FDLD_FILE_OK	(SDCA_CTL_XU_FDLH_TRANSFERRED_FILE | \
56 					 SDCA_CTL_XU_FDLH_SET_IN_PROGRESS | \
57 					 SDCA_CTL_XU_FDLD_ACK_TRANSFER | \
58 					 SDCA_CTL_XU_FDLD_NEEDS_SET)
59 #define SDCA_CTL_XU_FDLD_MORE_FILES_OK	(SDCA_CTL_XU_FDLH_SET_IN_PROGRESS | \
60 					 SDCA_CTL_XU_FDLD_ACK_TRANSFER | \
61 					 SDCA_CTL_XU_FDLD_NEEDS_SET)
62 #define SDCA_CTL_XU_FDLD_MASK		(SDCA_CTL_XU_FDLD_REQ_RESET | \
63 					 SDCA_CTL_XU_FDLD_REQ_ABORT | \
64 					 SDCA_CTL_XU_FDLD_ACK_TRANSFER | \
65 					 SDCA_CTL_XU_FDLD_NEEDS_SET)
66 
67 #if IS_ENABLED(CONFIG_SND_SOC_SDCA_FDL)
68 
69 int sdca_fdl_alloc_state(struct sdca_interrupt *interrupt);
70 void sdca_fdl_free_state(struct sdca_interrupt *interrupt);
71 
72 int sdca_fdl_process(struct sdca_interrupt *interrupt);
73 int sdca_fdl_sync(struct device *dev, struct sdca_function_data *function,
74 		  struct sdca_interrupt_info *info);
75 
76 int sdca_reset_function(struct device *dev, struct sdca_function_data *function,
77 			struct regmap *regmap);
78 
79 #else
80 
81 static inline int sdca_fdl_alloc_state(struct sdca_interrupt *interrupt)
82 {
83 	return 0;
84 }
85 
86 static inline void sdca_fdl_free_state(struct sdca_interrupt *interrupt)
87 {
88 }
89 
90 static inline int sdca_fdl_process(struct sdca_interrupt *interrupt)
91 {
92 	return 0;
93 }
94 
95 static inline int sdca_fdl_sync(struct device *dev,
96 				struct sdca_function_data *function,
97 				struct sdca_interrupt_info *info)
98 {
99 	return 0;
100 }
101 
102 static inline int sdca_reset_function(struct device *dev,
103 				      struct sdca_function_data *function,
104 				      struct regmap *regmap)
105 {
106 	return 0;
107 }
108 
109 #endif // CONFIG_SND_SOC_SDCA_FDL
110 
111 #endif // __SDCA_FDL_H__
112