xref: /openbmc/linux/drivers/soundwire/bus.h (revision e72e8bf1)
1 /* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
2 /* Copyright(c) 2015-17 Intel Corporation. */
3 
4 #ifndef __SDW_BUS_H
5 #define __SDW_BUS_H
6 
7 #define DEFAULT_BANK_SWITCH_TIMEOUT 3000
8 #define DEFAULT_PROBE_TIMEOUT       2000
9 
10 #if IS_ENABLED(CONFIG_ACPI)
11 int sdw_acpi_find_slaves(struct sdw_bus *bus);
12 #else
13 static inline int sdw_acpi_find_slaves(struct sdw_bus *bus)
14 {
15 	return -ENOTSUPP;
16 }
17 #endif
18 
19 int sdw_of_find_slaves(struct sdw_bus *bus);
20 void sdw_extract_slave_id(struct sdw_bus *bus,
21 			  u64 addr, struct sdw_slave_id *id);
22 
23 #ifdef CONFIG_DEBUG_FS
24 void sdw_bus_debugfs_init(struct sdw_bus *bus);
25 void sdw_bus_debugfs_exit(struct sdw_bus *bus);
26 void sdw_slave_debugfs_init(struct sdw_slave *slave);
27 void sdw_slave_debugfs_exit(struct sdw_slave *slave);
28 void sdw_debugfs_init(void);
29 void sdw_debugfs_exit(void);
30 #else
31 static inline void sdw_bus_debugfs_init(struct sdw_bus *bus) {}
32 static inline void sdw_bus_debugfs_exit(struct sdw_bus *bus) {}
33 static inline void sdw_slave_debugfs_init(struct sdw_slave *slave) {}
34 static inline void sdw_slave_debugfs_exit(struct sdw_slave *slave) {}
35 static inline void sdw_debugfs_init(void) {}
36 static inline void sdw_debugfs_exit(void) {}
37 #endif
38 
39 enum {
40 	SDW_MSG_FLAG_READ = 0,
41 	SDW_MSG_FLAG_WRITE,
42 };
43 
44 /**
45  * struct sdw_msg - Message structure
46  * @addr: Register address accessed in the Slave
47  * @len: number of messages
48  * @dev_num: Slave device number
49  * @addr_page1: SCP address page 1 Slave register
50  * @addr_page2: SCP address page 2 Slave register
51  * @flags: transfer flags, indicate if xfer is read or write
52  * @buf: message data buffer
53  * @ssp_sync: Send message at SSP (Stream Synchronization Point)
54  * @page: address requires paging
55  */
56 struct sdw_msg {
57 	u16 addr;
58 	u16 len;
59 	u8 dev_num;
60 	u8 addr_page1;
61 	u8 addr_page2;
62 	u8 flags;
63 	u8 *buf;
64 	bool ssp_sync;
65 	bool page;
66 };
67 
68 #define SDW_DOUBLE_RATE_FACTOR		2
69 
70 extern int sdw_rows[SDW_FRAME_ROWS];
71 extern int sdw_cols[SDW_FRAME_COLS];
72 
73 int sdw_find_row_index(int row);
74 int sdw_find_col_index(int col);
75 
76 /**
77  * sdw_port_runtime: Runtime port parameters for Master or Slave
78  *
79  * @num: Port number. For audio streams, valid port number ranges from
80  * [1,14]
81  * @ch_mask: Channel mask
82  * @transport_params: Transport parameters
83  * @port_params: Port parameters
84  * @port_node: List node for Master or Slave port_list
85  *
86  * SoundWire spec has no mention of ports for Master interface but the
87  * concept is logically extended.
88  */
89 struct sdw_port_runtime {
90 	int num;
91 	int ch_mask;
92 	struct sdw_transport_params transport_params;
93 	struct sdw_port_params port_params;
94 	struct list_head port_node;
95 };
96 
97 /**
98  * sdw_slave_runtime: Runtime Stream parameters for Slave
99  *
100  * @slave: Slave handle
101  * @direction: Data direction for Slave
102  * @ch_count: Number of channels handled by the Slave for
103  * this stream
104  * @m_rt_node: sdw_master_runtime list node
105  * @port_list: List of Slave Ports configured for this stream
106  */
107 struct sdw_slave_runtime {
108 	struct sdw_slave *slave;
109 	enum sdw_data_direction direction;
110 	unsigned int ch_count;
111 	struct list_head m_rt_node;
112 	struct list_head port_list;
113 };
114 
115 /**
116  * sdw_master_runtime: Runtime stream parameters for Master
117  *
118  * @bus: Bus handle
119  * @stream: Stream runtime handle
120  * @direction: Data direction for Master
121  * @ch_count: Number of channels handled by the Master for
122  * this stream, can be zero.
123  * @slave_rt_list: Slave runtime list
124  * @port_list: List of Master Ports configured for this stream, can be zero.
125  * @stream_node: sdw_stream_runtime master_list node
126  * @bus_node: sdw_bus m_rt_list node
127  */
128 struct sdw_master_runtime {
129 	struct sdw_bus *bus;
130 	struct sdw_stream_runtime *stream;
131 	enum sdw_data_direction direction;
132 	unsigned int ch_count;
133 	struct list_head slave_rt_list;
134 	struct list_head port_list;
135 	struct list_head stream_node;
136 	struct list_head bus_node;
137 };
138 
139 struct sdw_dpn_prop *sdw_get_slave_dpn_prop(struct sdw_slave *slave,
140 					    enum sdw_data_direction direction,
141 					    unsigned int port_num);
142 int sdw_configure_dpn_intr(struct sdw_slave *slave, int port,
143 			   bool enable, int mask);
144 
145 int sdw_transfer(struct sdw_bus *bus, struct sdw_msg *msg);
146 int sdw_transfer_defer(struct sdw_bus *bus, struct sdw_msg *msg,
147 		       struct sdw_defer *defer);
148 
149 #define SDW_READ_INTR_CLEAR_RETRY	10
150 
151 int sdw_fill_msg(struct sdw_msg *msg, struct sdw_slave *slave,
152 		 u32 addr, size_t count, u16 dev_num, u8 flags, u8 *buf);
153 
154 /* Read-Modify-Write Slave register */
155 static inline int
156 sdw_update(struct sdw_slave *slave, u32 addr, u8 mask, u8 val)
157 {
158 	int tmp;
159 
160 	tmp = sdw_read(slave, addr);
161 	if (tmp < 0)
162 		return tmp;
163 
164 	tmp = (tmp & ~mask) | val;
165 	return sdw_write(slave, addr, tmp);
166 }
167 
168 /*
169  * At the moment we only track Master-initiated hw_reset.
170  * Additional fields can be added as needed
171  */
172 #define SDW_UNATTACH_REQUEST_MASTER_RESET	BIT(0)
173 
174 void sdw_clear_slave_status(struct sdw_bus *bus, u32 request);
175 
176 #endif /* __SDW_BUS_H */
177