0001
0002
0003
0004 #ifndef __SDW_BUS_H
0005 #define __SDW_BUS_H
0006
0007 #define DEFAULT_BANK_SWITCH_TIMEOUT 3000
0008 #define DEFAULT_PROBE_TIMEOUT 2000
0009
0010 u64 sdw_dmi_override_adr(struct sdw_bus *bus, u64 addr);
0011
0012 #if IS_ENABLED(CONFIG_ACPI)
0013 int sdw_acpi_find_slaves(struct sdw_bus *bus);
0014 #else
0015 static inline int sdw_acpi_find_slaves(struct sdw_bus *bus)
0016 {
0017 return -ENOTSUPP;
0018 }
0019 #endif
0020
0021 int sdw_of_find_slaves(struct sdw_bus *bus);
0022 void sdw_extract_slave_id(struct sdw_bus *bus,
0023 u64 addr, struct sdw_slave_id *id);
0024 int sdw_slave_add(struct sdw_bus *bus, struct sdw_slave_id *id,
0025 struct fwnode_handle *fwnode);
0026 int sdw_master_device_add(struct sdw_bus *bus, struct device *parent,
0027 struct fwnode_handle *fwnode);
0028 int sdw_master_device_del(struct sdw_bus *bus);
0029
0030 #ifdef CONFIG_DEBUG_FS
0031 void sdw_bus_debugfs_init(struct sdw_bus *bus);
0032 void sdw_bus_debugfs_exit(struct sdw_bus *bus);
0033 void sdw_slave_debugfs_init(struct sdw_slave *slave);
0034 void sdw_slave_debugfs_exit(struct sdw_slave *slave);
0035 void sdw_debugfs_init(void);
0036 void sdw_debugfs_exit(void);
0037 #else
0038 static inline void sdw_bus_debugfs_init(struct sdw_bus *bus) {}
0039 static inline void sdw_bus_debugfs_exit(struct sdw_bus *bus) {}
0040 static inline void sdw_slave_debugfs_init(struct sdw_slave *slave) {}
0041 static inline void sdw_slave_debugfs_exit(struct sdw_slave *slave) {}
0042 static inline void sdw_debugfs_init(void) {}
0043 static inline void sdw_debugfs_exit(void) {}
0044 #endif
0045
0046 enum {
0047 SDW_MSG_FLAG_READ = 0,
0048 SDW_MSG_FLAG_WRITE,
0049 };
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063 struct sdw_msg {
0064 u16 addr;
0065 u16 len;
0066 u8 dev_num;
0067 u8 addr_page1;
0068 u8 addr_page2;
0069 u8 flags;
0070 u8 *buf;
0071 bool ssp_sync;
0072 bool page;
0073 };
0074
0075 #define SDW_DOUBLE_RATE_FACTOR 2
0076 #define SDW_STRM_RATE_GROUPING 1
0077
0078 extern int sdw_rows[SDW_FRAME_ROWS];
0079 extern int sdw_cols[SDW_FRAME_COLS];
0080
0081 int sdw_find_row_index(int row);
0082 int sdw_find_col_index(int col);
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097 struct sdw_port_runtime {
0098 int num;
0099 int ch_mask;
0100 struct sdw_transport_params transport_params;
0101 struct sdw_port_params port_params;
0102 struct list_head port_node;
0103 };
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115 struct sdw_slave_runtime {
0116 struct sdw_slave *slave;
0117 enum sdw_data_direction direction;
0118 unsigned int ch_count;
0119 struct list_head m_rt_node;
0120 struct list_head port_list;
0121 };
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136 struct sdw_master_runtime {
0137 struct sdw_bus *bus;
0138 struct sdw_stream_runtime *stream;
0139 enum sdw_data_direction direction;
0140 unsigned int ch_count;
0141 struct list_head slave_rt_list;
0142 struct list_head port_list;
0143 struct list_head stream_node;
0144 struct list_head bus_node;
0145 };
0146
0147 struct sdw_dpn_prop *sdw_get_slave_dpn_prop(struct sdw_slave *slave,
0148 enum sdw_data_direction direction,
0149 unsigned int port_num);
0150 int sdw_configure_dpn_intr(struct sdw_slave *slave, int port,
0151 bool enable, int mask);
0152
0153 int sdw_transfer(struct sdw_bus *bus, struct sdw_msg *msg);
0154 int sdw_transfer_defer(struct sdw_bus *bus, struct sdw_msg *msg,
0155 struct sdw_defer *defer);
0156
0157 #define SDW_READ_INTR_CLEAR_RETRY 10
0158
0159 int sdw_fill_msg(struct sdw_msg *msg, struct sdw_slave *slave,
0160 u32 addr, size_t count, u16 dev_num, u8 flags, u8 *buf);
0161
0162
0163 static inline int sdw_ch_mask_to_ch(int ch_mask)
0164 {
0165 int c = 0;
0166
0167 for (c = 0; ch_mask; ch_mask >>= 1)
0168 c += ch_mask & 1;
0169
0170 return c;
0171 }
0172
0173
0174 static inline void sdw_fill_xport_params(struct sdw_transport_params *params,
0175 int port_num, bool grp_ctrl_valid,
0176 int grp_ctrl, int sample_int,
0177 int off1, int off2,
0178 int hstart, int hstop,
0179 int pack_mode, int lane_ctrl)
0180 {
0181 params->port_num = port_num;
0182 params->blk_grp_ctrl_valid = grp_ctrl_valid;
0183 params->blk_grp_ctrl = grp_ctrl;
0184 params->sample_interval = sample_int;
0185 params->offset1 = off1;
0186 params->offset2 = off2;
0187 params->hstart = hstart;
0188 params->hstop = hstop;
0189 params->blk_pkg_mode = pack_mode;
0190 params->lane_ctrl = lane_ctrl;
0191 }
0192
0193
0194 static inline void sdw_fill_port_params(struct sdw_port_params *params,
0195 int port_num, int bps,
0196 int flow_mode, int data_mode)
0197 {
0198 params->num = port_num;
0199 params->bps = bps;
0200 params->flow_mode = flow_mode;
0201 params->data_mode = data_mode;
0202 }
0203
0204
0205 int sdw_bread_no_pm_unlocked(struct sdw_bus *bus, u16 dev_num, u32 addr);
0206 int sdw_bwrite_no_pm_unlocked(struct sdw_bus *bus, u16 dev_num, u32 addr, u8 value);
0207
0208
0209
0210
0211
0212 #define SDW_UNATTACH_REQUEST_MASTER_RESET BIT(0)
0213
0214 void sdw_clear_slave_status(struct sdw_bus *bus, u32 request);
0215 int sdw_slave_modalias(const struct sdw_slave *slave, char *buf, size_t size);
0216
0217 #endif