| 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 | u64 sdw_dmi_override_adr(struct sdw_bus *bus, u64 addr); |
| 11 | |
| 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 | |
| 21 | int sdw_of_find_slaves(struct sdw_bus *bus); |
| 22 | void (struct sdw_bus *bus, |
| 23 | u64 addr, struct sdw_slave_id *id); |
| 24 | int sdw_slave_add(struct sdw_bus *bus, struct sdw_slave_id *id, |
| 25 | struct fwnode_handle *fwnode); |
| 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); |
| 29 | |
| 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 | |
| 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 | |
| 75 | /** |
| 76 | * struct sdw_btp_msg - Message structure |
| 77 | * @addr: Start Register address accessed in the Slave |
| 78 | * @len: number of bytes to transfer. More than 64Kb can be transferred |
| 79 | * but a practical limit of SDW_BPT_MSG_MAX_BYTES is enforced. |
| 80 | * @dev_num: Slave device number |
| 81 | * @flags: transfer flags, indicate if xfer is read or write |
| 82 | * @buf: message data buffer (filled by host for write, filled |
| 83 | * by Peripheral hardware for reads) |
| 84 | */ |
| 85 | struct sdw_bpt_msg { |
| 86 | u32 addr; |
| 87 | u32 len; |
| 88 | u8 dev_num; |
| 89 | u8 flags; |
| 90 | u8 *buf; |
| 91 | }; |
| 92 | |
| 93 | #define SDW_DOUBLE_RATE_FACTOR 2 |
| 94 | #define SDW_STRM_RATE_GROUPING 1 |
| 95 | |
| 96 | extern int sdw_rows[SDW_FRAME_ROWS]; |
| 97 | extern int sdw_cols[SDW_FRAME_COLS]; |
| 98 | |
| 99 | int sdw_find_row_index(int row); |
| 100 | int sdw_find_col_index(int col); |
| 101 | |
| 102 | /** |
| 103 | * sdw_port_runtime: Runtime port parameters for Master or Slave |
| 104 | * |
| 105 | * @num: Port number. For audio streams, valid port number ranges from |
| 106 | * [1,14] |
| 107 | * @ch_mask: Channel mask |
| 108 | * @transport_params: Transport parameters |
| 109 | * @port_params: Port parameters |
| 110 | * @port_node: List node for Master or Slave port_list |
| 111 | * @lane: Which lane is used |
| 112 | * |
| 113 | * SoundWire spec has no mention of ports for Master interface but the |
| 114 | * concept is logically extended. |
| 115 | */ |
| 116 | struct sdw_port_runtime { |
| 117 | int num; |
| 118 | int ch_mask; |
| 119 | struct sdw_transport_params transport_params; |
| 120 | struct sdw_port_params port_params; |
| 121 | struct list_head port_node; |
| 122 | unsigned int lane; |
| 123 | }; |
| 124 | |
| 125 | /** |
| 126 | * sdw_slave_runtime: Runtime Stream parameters for Slave |
| 127 | * |
| 128 | * @slave: Slave handle |
| 129 | * @direction: Data direction for Slave |
| 130 | * @ch_count: Number of channels handled by the Slave for |
| 131 | * this stream |
| 132 | * @m_rt_node: sdw_master_runtime list node |
| 133 | * @port_list: List of Slave Ports configured for this stream |
| 134 | */ |
| 135 | struct sdw_slave_runtime { |
| 136 | struct sdw_slave *slave; |
| 137 | enum sdw_data_direction direction; |
| 138 | unsigned int ch_count; |
| 139 | struct list_head m_rt_node; |
| 140 | struct list_head port_list; |
| 141 | }; |
| 142 | |
| 143 | /** |
| 144 | * sdw_master_runtime: Runtime stream parameters for Master |
| 145 | * |
| 146 | * @bus: Bus handle |
| 147 | * @stream: Stream runtime handle |
| 148 | * @direction: Data direction for Master |
| 149 | * @ch_count: Number of channels handled by the Master for |
| 150 | * this stream, can be zero. |
| 151 | * @slave_rt_list: Slave runtime list |
| 152 | * @port_list: List of Master Ports configured for this stream, can be zero. |
| 153 | * @stream_node: sdw_stream_runtime master_list node |
| 154 | * @bus_node: sdw_bus m_rt_list node |
| 155 | */ |
| 156 | struct sdw_master_runtime { |
| 157 | struct sdw_bus *bus; |
| 158 | struct sdw_stream_runtime *stream; |
| 159 | enum sdw_data_direction direction; |
| 160 | unsigned int ch_count; |
| 161 | struct list_head slave_rt_list; |
| 162 | struct list_head port_list; |
| 163 | struct list_head stream_node; |
| 164 | struct list_head bus_node; |
| 165 | }; |
| 166 | |
| 167 | struct sdw_transport_data { |
| 168 | int hstart; |
| 169 | int hstop; |
| 170 | int block_offset; |
| 171 | int sub_block_offset; |
| 172 | unsigned int lane; |
| 173 | }; |
| 174 | |
| 175 | struct sdw_dpn_prop *sdw_get_slave_dpn_prop(struct sdw_slave *slave, |
| 176 | enum sdw_data_direction direction, |
| 177 | unsigned int port_num); |
| 178 | int sdw_configure_dpn_intr(struct sdw_slave *slave, int port, |
| 179 | bool enable, int mask); |
| 180 | |
| 181 | int sdw_transfer(struct sdw_bus *bus, struct sdw_msg *msg); |
| 182 | int sdw_transfer_defer(struct sdw_bus *bus, struct sdw_msg *msg); |
| 183 | |
| 184 | #define SDW_READ_INTR_CLEAR_RETRY 10 |
| 185 | |
| 186 | int sdw_fill_msg(struct sdw_msg *msg, struct sdw_slave *slave, |
| 187 | u32 addr, size_t count, u16 dev_num, u8 flags, u8 *buf); |
| 188 | |
| 189 | /* Fill transport parameter data structure */ |
| 190 | static inline void sdw_fill_xport_params(struct sdw_transport_params *params, |
| 191 | int port_num, bool grp_ctrl_valid, |
| 192 | int grp_ctrl, int sample_int, |
| 193 | int off1, int off2, |
| 194 | int hstart, int hstop, |
| 195 | int pack_mode, int lane_ctrl) |
| 196 | { |
| 197 | params->port_num = port_num; |
| 198 | params->blk_grp_ctrl_valid = grp_ctrl_valid; |
| 199 | params->blk_grp_ctrl = grp_ctrl; |
| 200 | params->sample_interval = sample_int; |
| 201 | params->offset1 = off1; |
| 202 | params->offset2 = off2; |
| 203 | params->hstart = hstart; |
| 204 | params->hstop = hstop; |
| 205 | params->blk_pkg_mode = pack_mode; |
| 206 | params->lane_ctrl = lane_ctrl; |
| 207 | } |
| 208 | |
| 209 | /* Fill port parameter data structure */ |
| 210 | static inline void sdw_fill_port_params(struct sdw_port_params *params, |
| 211 | int port_num, int bps, |
| 212 | int flow_mode, int data_mode) |
| 213 | { |
| 214 | params->num = port_num; |
| 215 | params->bps = bps; |
| 216 | params->flow_mode = flow_mode; |
| 217 | params->data_mode = data_mode; |
| 218 | } |
| 219 | |
| 220 | /* broadcast read/write for tests */ |
| 221 | int sdw_bread_no_pm_unlocked(struct sdw_bus *bus, u16 dev_num, u32 addr); |
| 222 | int sdw_bwrite_no_pm_unlocked(struct sdw_bus *bus, u16 dev_num, u32 addr, u8 value); |
| 223 | |
| 224 | /* |
| 225 | * At the moment we only track Master-initiated hw_reset. |
| 226 | * Additional fields can be added as needed |
| 227 | */ |
| 228 | #define SDW_UNATTACH_REQUEST_MASTER_RESET BIT(0) |
| 229 | |
| 230 | void sdw_clear_slave_status(struct sdw_bus *bus, u32 request); |
| 231 | int sdw_slave_modalias(const struct sdw_slave *slave, char *buf, size_t size); |
| 232 | void sdw_compute_slave_ports(struct sdw_master_runtime *m_rt, |
| 233 | struct sdw_transport_data *t_data); |
| 234 | |
| 235 | #endif /* __SDW_BUS_H */ |
| 236 | |