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