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 #if IS_ENABLED(CONFIG_ACPI) 8 int sdw_acpi_find_slaves(struct sdw_bus *bus); 9 #else 10 static inline int sdw_acpi_find_slaves(struct sdw_bus *bus) 11 { 12 return -ENOTSUPP; 13 } 14 #endif 15 16 void sdw_extract_slave_id(struct sdw_bus *bus, 17 u64 addr, struct sdw_slave_id *id); 18 19 enum { 20 SDW_MSG_FLAG_READ = 0, 21 SDW_MSG_FLAG_WRITE, 22 }; 23 24 /** 25 * struct sdw_msg - Message structure 26 * @addr: Register address accessed in the Slave 27 * @len: number of messages 28 * @dev_num: Slave device number 29 * @addr_page1: SCP address page 1 Slave register 30 * @addr_page2: SCP address page 2 Slave register 31 * @flags: transfer flags, indicate if xfer is read or write 32 * @buf: message data buffer 33 * @ssp_sync: Send message at SSP (Stream Synchronization Point) 34 * @page: address requires paging 35 */ 36 struct sdw_msg { 37 u16 addr; 38 u16 len; 39 u8 dev_num; 40 u8 addr_page1; 41 u8 addr_page2; 42 u8 flags; 43 u8 *buf; 44 bool ssp_sync; 45 bool page; 46 }; 47 48 #define SDW_DOUBLE_RATE_FACTOR 2 49 50 extern int rows[SDW_FRAME_ROWS]; 51 extern int cols[SDW_FRAME_COLS]; 52 53 /** 54 * sdw_port_runtime: Runtime port parameters for Master or Slave 55 * 56 * @num: Port number. For audio streams, valid port number ranges from 57 * [1,14] 58 * @ch_mask: Channel mask 59 * @transport_params: Transport parameters 60 * @port_params: Port parameters 61 * @port_node: List node for Master or Slave port_list 62 * 63 * SoundWire spec has no mention of ports for Master interface but the 64 * concept is logically extended. 65 */ 66 struct sdw_port_runtime { 67 int num; 68 int ch_mask; 69 struct sdw_transport_params transport_params; 70 struct sdw_port_params port_params; 71 struct list_head port_node; 72 }; 73 74 /** 75 * sdw_slave_runtime: Runtime Stream parameters for Slave 76 * 77 * @slave: Slave handle 78 * @direction: Data direction for Slave 79 * @ch_count: Number of channels handled by the Slave for 80 * this stream 81 * @m_rt_node: sdw_master_runtime list node 82 * @port_list: List of Slave Ports configured for this stream 83 */ 84 struct sdw_slave_runtime { 85 struct sdw_slave *slave; 86 enum sdw_data_direction direction; 87 unsigned int ch_count; 88 struct list_head m_rt_node; 89 struct list_head port_list; 90 }; 91 92 /** 93 * sdw_master_runtime: Runtime stream parameters for Master 94 * 95 * @bus: Bus handle 96 * @stream: Stream runtime handle 97 * @direction: Data direction for Master 98 * @ch_count: Number of channels handled by the Master for 99 * this stream, can be zero. 100 * @slave_rt_list: Slave runtime list 101 * @port_list: List of Master Ports configured for this stream, can be zero. 102 * @bus_node: sdw_bus m_rt_list node 103 */ 104 struct sdw_master_runtime { 105 struct sdw_bus *bus; 106 struct sdw_stream_runtime *stream; 107 enum sdw_data_direction direction; 108 unsigned int ch_count; 109 struct list_head slave_rt_list; 110 struct list_head port_list; 111 struct list_head bus_node; 112 }; 113 114 struct sdw_dpn_prop *sdw_get_slave_dpn_prop(struct sdw_slave *slave, 115 enum sdw_data_direction direction, 116 unsigned int port_num); 117 int sdw_configure_dpn_intr(struct sdw_slave *slave, int port, 118 bool enable, int mask); 119 120 int sdw_transfer(struct sdw_bus *bus, struct sdw_msg *msg); 121 int sdw_transfer_defer(struct sdw_bus *bus, struct sdw_msg *msg, 122 struct sdw_defer *defer); 123 124 #define SDW_READ_INTR_CLEAR_RETRY 10 125 126 int sdw_fill_msg(struct sdw_msg *msg, struct sdw_slave *slave, 127 u32 addr, size_t count, u16 dev_num, u8 flags, u8 *buf); 128 129 /* Read-Modify-Write Slave register */ 130 static inline int 131 sdw_update(struct sdw_slave *slave, u32 addr, u8 mask, u8 val) 132 { 133 int tmp; 134 135 tmp = sdw_read(slave, addr); 136 if (tmp < 0) 137 return tmp; 138 139 tmp = (tmp & ~mask) | val; 140 return sdw_write(slave, addr, tmp); 141 } 142 143 #endif /* __SDW_BUS_H */ 144