Pierre-Louis Bossart | 2385946 | 2019-05-01 10:57:25 -0500 | [diff] [blame] | 1 | /* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */ |
| 2 | /* Copyright(c) 2015-17 Intel Corporation. */ |
Vinod Koul | 7c3cd18 | 2017-12-14 11:19:34 +0530 | [diff] [blame] | 3 | |
| 4 | #ifndef __SDW_BUS_H |
| 5 | #define __SDW_BUS_H |
| 6 | |
Shreyas NC | ce6e74d | 2018-07-27 14:44:16 +0530 | [diff] [blame] | 7 | #define DEFAULT_BANK_SWITCH_TIMEOUT 3000 |
Pierre-Louis Bossart | 2140b66 | 2020-01-14 18:08:35 -0600 | [diff] [blame] | 8 | #define DEFAULT_PROBE_TIMEOUT 2000 |
Shreyas NC | ce6e74d | 2018-07-27 14:44:16 +0530 | [diff] [blame] | 9 | |
Pierre-Louis Bossart | f6594cd | 2021-03-02 15:51:04 +0800 | [diff] [blame] | 10 | u64 sdw_dmi_override_adr(struct sdw_bus *bus, u64 addr); |
| 11 | |
Vinod Koul | 7c3cd18 | 2017-12-14 11:19:34 +0530 | [diff] [blame] | 12 | #if IS_ENABLED(CONFIG_ACPI) |
| 13 | int sdw_acpi_find_slaves(struct sdw_bus *bus); |
| 14 | #else |
| 15 | static inline int sdw_acpi_find_slaves(struct sdw_bus *bus) |
| 16 | { |
| 17 | return -ENOTSUPP; |
| 18 | } |
| 19 | #endif |
| 20 | |
Srinivas Kandagatla | a2e4845 | 2019-08-29 17:35:12 +0100 | [diff] [blame] | 21 | int sdw_of_find_slaves(struct sdw_bus *bus); |
Vinod Koul | 7c3cd18 | 2017-12-14 11:19:34 +0530 | [diff] [blame] | 22 | void sdw_extract_slave_id(struct sdw_bus *bus, |
Pierre-Louis Bossart | 806a11f | 2019-05-01 10:57:26 -0500 | [diff] [blame] | 23 | u64 addr, struct sdw_slave_id *id); |
Srinivas Kandagatla | fcb9d73 | 2020-09-24 14:44:29 -0500 | [diff] [blame] | 24 | int sdw_slave_add(struct sdw_bus *bus, struct sdw_slave_id *id, |
| 25 | struct fwnode_handle *fwnode); |
Pierre-Louis Bossart | 7ceaa40 | 2020-05-19 01:43:21 +0800 | [diff] [blame] | 26 | int sdw_master_device_add(struct sdw_bus *bus, struct device *parent, |
| 27 | struct fwnode_handle *fwnode); |
| 28 | int sdw_master_device_del(struct sdw_bus *bus); |
Vinod Koul | 7c3cd18 | 2017-12-14 11:19:34 +0530 | [diff] [blame] | 29 | |
Pierre-Louis Bossart | bf03473 | 2019-08-21 13:58:18 -0500 | [diff] [blame] | 30 | #ifdef CONFIG_DEBUG_FS |
| 31 | void sdw_bus_debugfs_init(struct sdw_bus *bus); |
| 32 | void sdw_bus_debugfs_exit(struct sdw_bus *bus); |
| 33 | void sdw_slave_debugfs_init(struct sdw_slave *slave); |
| 34 | void sdw_slave_debugfs_exit(struct sdw_slave *slave); |
| 35 | void sdw_debugfs_init(void); |
| 36 | void sdw_debugfs_exit(void); |
| 37 | #else |
| 38 | static inline void sdw_bus_debugfs_init(struct sdw_bus *bus) {} |
| 39 | static inline void sdw_bus_debugfs_exit(struct sdw_bus *bus) {} |
| 40 | static inline void sdw_slave_debugfs_init(struct sdw_slave *slave) {} |
| 41 | static inline void sdw_slave_debugfs_exit(struct sdw_slave *slave) {} |
| 42 | static inline void sdw_debugfs_init(void) {} |
| 43 | static inline void sdw_debugfs_exit(void) {} |
| 44 | #endif |
| 45 | |
Vinod Koul | 9d715fa | 2017-12-14 11:19:37 +0530 | [diff] [blame] | 46 | enum { |
| 47 | SDW_MSG_FLAG_READ = 0, |
| 48 | SDW_MSG_FLAG_WRITE, |
| 49 | }; |
| 50 | |
| 51 | /** |
| 52 | * struct sdw_msg - Message structure |
| 53 | * @addr: Register address accessed in the Slave |
| 54 | * @len: number of messages |
| 55 | * @dev_num: Slave device number |
| 56 | * @addr_page1: SCP address page 1 Slave register |
| 57 | * @addr_page2: SCP address page 2 Slave register |
| 58 | * @flags: transfer flags, indicate if xfer is read or write |
| 59 | * @buf: message data buffer |
| 60 | * @ssp_sync: Send message at SSP (Stream Synchronization Point) |
| 61 | * @page: address requires paging |
| 62 | */ |
| 63 | struct sdw_msg { |
| 64 | u16 addr; |
| 65 | u16 len; |
| 66 | u8 dev_num; |
| 67 | u8 addr_page1; |
| 68 | u8 addr_page2; |
| 69 | u8 flags; |
| 70 | u8 *buf; |
| 71 | bool ssp_sync; |
| 72 | bool page; |
| 73 | }; |
| 74 | |
Sanyog Kale | 99b8a5d | 2018-04-26 18:38:28 +0530 | [diff] [blame] | 75 | #define SDW_DOUBLE_RATE_FACTOR 2 |
Bard Liao | 9026118 | 2020-09-08 21:15:20 +0800 | [diff] [blame] | 76 | #define SDW_STRM_RATE_GROUPING 1 |
Sanyog Kale | 99b8a5d | 2018-04-26 18:38:28 +0530 | [diff] [blame] | 77 | |
Pierre-Louis Bossart | fe4b70f | 2019-08-05 19:55:10 -0500 | [diff] [blame] | 78 | extern int sdw_rows[SDW_FRAME_ROWS]; |
| 79 | extern int sdw_cols[SDW_FRAME_COLS]; |
| 80 | |
| 81 | int sdw_find_row_index(int row); |
| 82 | int sdw_find_col_index(int col); |
Sanyog Kale | 99b8a5d | 2018-04-26 18:38:28 +0530 | [diff] [blame] | 83 | |
Sanyog Kale | 89e5905 | 2018-04-26 18:38:08 +0530 | [diff] [blame] | 84 | /** |
Sanyog Kale | bbe7379 | 2018-04-26 18:38:13 +0530 | [diff] [blame] | 85 | * sdw_port_runtime: Runtime port parameters for Master or Slave |
| 86 | * |
| 87 | * @num: Port number. For audio streams, valid port number ranges from |
| 88 | * [1,14] |
| 89 | * @ch_mask: Channel mask |
| 90 | * @transport_params: Transport parameters |
| 91 | * @port_params: Port parameters |
| 92 | * @port_node: List node for Master or Slave port_list |
| 93 | * |
| 94 | * SoundWire spec has no mention of ports for Master interface but the |
| 95 | * concept is logically extended. |
| 96 | */ |
| 97 | struct sdw_port_runtime { |
| 98 | int num; |
| 99 | int ch_mask; |
| 100 | struct sdw_transport_params transport_params; |
| 101 | struct sdw_port_params port_params; |
| 102 | struct list_head port_node; |
| 103 | }; |
| 104 | |
| 105 | /** |
Sanyog Kale | 89e5905 | 2018-04-26 18:38:08 +0530 | [diff] [blame] | 106 | * sdw_slave_runtime: Runtime Stream parameters for Slave |
| 107 | * |
| 108 | * @slave: Slave handle |
| 109 | * @direction: Data direction for Slave |
| 110 | * @ch_count: Number of channels handled by the Slave for |
| 111 | * this stream |
| 112 | * @m_rt_node: sdw_master_runtime list node |
Sanyog Kale | bbe7379 | 2018-04-26 18:38:13 +0530 | [diff] [blame] | 113 | * @port_list: List of Slave Ports configured for this stream |
Sanyog Kale | 89e5905 | 2018-04-26 18:38:08 +0530 | [diff] [blame] | 114 | */ |
| 115 | struct sdw_slave_runtime { |
| 116 | struct sdw_slave *slave; |
| 117 | enum sdw_data_direction direction; |
| 118 | unsigned int ch_count; |
| 119 | struct list_head m_rt_node; |
Sanyog Kale | bbe7379 | 2018-04-26 18:38:13 +0530 | [diff] [blame] | 120 | struct list_head port_list; |
Sanyog Kale | 89e5905 | 2018-04-26 18:38:08 +0530 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | /** |
| 124 | * sdw_master_runtime: Runtime stream parameters for Master |
| 125 | * |
| 126 | * @bus: Bus handle |
| 127 | * @stream: Stream runtime handle |
| 128 | * @direction: Data direction for Master |
| 129 | * @ch_count: Number of channels handled by the Master for |
| 130 | * this stream, can be zero. |
| 131 | * @slave_rt_list: Slave runtime list |
Sanyog Kale | bbe7379 | 2018-04-26 18:38:13 +0530 | [diff] [blame] | 132 | * @port_list: List of Master Ports configured for this stream, can be zero. |
Sanyog Kale | 0c4a104 | 2018-07-27 14:44:13 +0530 | [diff] [blame] | 133 | * @stream_node: sdw_stream_runtime master_list node |
Sanyog Kale | 89e5905 | 2018-04-26 18:38:08 +0530 | [diff] [blame] | 134 | * @bus_node: sdw_bus m_rt_list node |
| 135 | */ |
| 136 | struct sdw_master_runtime { |
| 137 | struct sdw_bus *bus; |
| 138 | struct sdw_stream_runtime *stream; |
| 139 | enum sdw_data_direction direction; |
| 140 | unsigned int ch_count; |
| 141 | struct list_head slave_rt_list; |
Sanyog Kale | bbe7379 | 2018-04-26 18:38:13 +0530 | [diff] [blame] | 142 | struct list_head port_list; |
Sanyog Kale | 0c4a104 | 2018-07-27 14:44:13 +0530 | [diff] [blame] | 143 | struct list_head stream_node; |
Sanyog Kale | 89e5905 | 2018-04-26 18:38:08 +0530 | [diff] [blame] | 144 | struct list_head bus_node; |
| 145 | }; |
| 146 | |
Sanyog Kale | f8101c7 | 2018-04-26 18:38:17 +0530 | [diff] [blame] | 147 | struct sdw_dpn_prop *sdw_get_slave_dpn_prop(struct sdw_slave *slave, |
Pierre-Louis Bossart | 806a11f | 2019-05-01 10:57:26 -0500 | [diff] [blame] | 148 | enum sdw_data_direction direction, |
| 149 | unsigned int port_num); |
Sanyog Kale | 79df15b | 2018-04-26 18:38:23 +0530 | [diff] [blame] | 150 | int sdw_configure_dpn_intr(struct sdw_slave *slave, int port, |
Pierre-Louis Bossart | 806a11f | 2019-05-01 10:57:26 -0500 | [diff] [blame] | 151 | bool enable, int mask); |
Sanyog Kale | f8101c7 | 2018-04-26 18:38:17 +0530 | [diff] [blame] | 152 | |
Vinod Koul | 9d715fa | 2017-12-14 11:19:37 +0530 | [diff] [blame] | 153 | int sdw_transfer(struct sdw_bus *bus, struct sdw_msg *msg); |
| 154 | int sdw_transfer_defer(struct sdw_bus *bus, struct sdw_msg *msg, |
Pierre-Louis Bossart | 806a11f | 2019-05-01 10:57:26 -0500 | [diff] [blame] | 155 | struct sdw_defer *defer); |
Vinod Koul | 9d715fa | 2017-12-14 11:19:37 +0530 | [diff] [blame] | 156 | |
Vinod Koul | b0a9c37 | 2017-12-14 11:19:40 +0530 | [diff] [blame] | 157 | #define SDW_READ_INTR_CLEAR_RETRY 10 |
| 158 | |
Vinod Koul | 9d715fa | 2017-12-14 11:19:37 +0530 | [diff] [blame] | 159 | int sdw_fill_msg(struct sdw_msg *msg, struct sdw_slave *slave, |
Pierre-Louis Bossart | 806a11f | 2019-05-01 10:57:26 -0500 | [diff] [blame] | 160 | u32 addr, size_t count, u16 dev_num, u8 flags, u8 *buf); |
Vinod Koul | 9d715fa | 2017-12-14 11:19:37 +0530 | [diff] [blame] | 161 | |
Bard Liao | 9026118 | 2020-09-08 21:15:20 +0800 | [diff] [blame] | 162 | /* Retrieve and return channel count from channel mask */ |
| 163 | static inline int sdw_ch_mask_to_ch(int ch_mask) |
| 164 | { |
| 165 | int c = 0; |
| 166 | |
| 167 | for (c = 0; ch_mask; ch_mask >>= 1) |
| 168 | c += ch_mask & 1; |
| 169 | |
| 170 | return c; |
| 171 | } |
| 172 | |
| 173 | /* Fill transport parameter data structure */ |
| 174 | static inline void sdw_fill_xport_params(struct sdw_transport_params *params, |
| 175 | int port_num, bool grp_ctrl_valid, |
| 176 | int grp_ctrl, int sample_int, |
| 177 | int off1, int off2, |
| 178 | int hstart, int hstop, |
| 179 | int pack_mode, int lane_ctrl) |
| 180 | { |
| 181 | params->port_num = port_num; |
| 182 | params->blk_grp_ctrl_valid = grp_ctrl_valid; |
| 183 | params->blk_grp_ctrl = grp_ctrl; |
| 184 | params->sample_interval = sample_int; |
| 185 | params->offset1 = off1; |
| 186 | params->offset2 = off2; |
| 187 | params->hstart = hstart; |
| 188 | params->hstop = hstop; |
| 189 | params->blk_pkg_mode = pack_mode; |
| 190 | params->lane_ctrl = lane_ctrl; |
| 191 | } |
| 192 | |
| 193 | /* Fill port parameter data structure */ |
| 194 | static inline void sdw_fill_port_params(struct sdw_port_params *params, |
| 195 | int port_num, int bps, |
| 196 | int flow_mode, int data_mode) |
| 197 | { |
| 198 | params->num = port_num; |
| 199 | params->bps = bps; |
| 200 | params->flow_mode = flow_mode; |
| 201 | params->data_mode = data_mode; |
| 202 | } |
| 203 | |
Pierre-Louis Bossart | a350aff | 2020-09-08 21:45:20 +0800 | [diff] [blame] | 204 | /* broadcast read/write for tests */ |
| 205 | int sdw_bread_no_pm_unlocked(struct sdw_bus *bus, u16 dev_num, u32 addr); |
| 206 | int sdw_bwrite_no_pm_unlocked(struct sdw_bus *bus, u16 dev_num, u32 addr, u8 value); |
| 207 | |
Pierre-Louis Bossart | 3ab2ca4 | 2020-01-14 18:08:40 -0600 | [diff] [blame] | 208 | /* |
| 209 | * At the moment we only track Master-initiated hw_reset. |
| 210 | * Additional fields can be added as needed |
| 211 | */ |
| 212 | #define SDW_UNATTACH_REQUEST_MASTER_RESET BIT(0) |
| 213 | |
| 214 | void sdw_clear_slave_status(struct sdw_bus *bus, u32 request); |
Pierre-Louis Bossart | bcac590 | 2020-05-19 04:35:51 +0800 | [diff] [blame] | 215 | int sdw_slave_modalias(const struct sdw_slave *slave, char *buf, size_t size); |
Pierre-Louis Bossart | 3ab2ca4 | 2020-01-14 18:08:40 -0600 | [diff] [blame] | 216 | |
Vinod Koul | 7c3cd18 | 2017-12-14 11:19:34 +0530 | [diff] [blame] | 217 | #endif /* __SDW_BUS_H */ |