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 |
| 8 | |
Vinod Koul | 7c3cd18 | 2017-12-14 11:19:34 +0530 | [diff] [blame] | 9 | #if IS_ENABLED(CONFIG_ACPI) |
| 10 | int sdw_acpi_find_slaves(struct sdw_bus *bus); |
| 11 | #else |
| 12 | static inline int sdw_acpi_find_slaves(struct sdw_bus *bus) |
| 13 | { |
| 14 | return -ENOTSUPP; |
| 15 | } |
| 16 | #endif |
| 17 | |
Srinivas Kandagatla | a2e4845 | 2019-08-29 17:35:12 +0100 | [diff] [blame] | 18 | int sdw_of_find_slaves(struct sdw_bus *bus); |
Vinod Koul | 7c3cd18 | 2017-12-14 11:19:34 +0530 | [diff] [blame] | 19 | void sdw_extract_slave_id(struct sdw_bus *bus, |
Pierre-Louis Bossart | 806a11f | 2019-05-01 10:57:26 -0500 | [diff] [blame] | 20 | u64 addr, struct sdw_slave_id *id); |
Vinod Koul | 7c3cd18 | 2017-12-14 11:19:34 +0530 | [diff] [blame] | 21 | |
Pierre-Louis Bossart | bf03473 | 2019-08-21 13:58:18 -0500 | [diff] [blame] | 22 | #ifdef CONFIG_DEBUG_FS |
| 23 | void sdw_bus_debugfs_init(struct sdw_bus *bus); |
| 24 | void sdw_bus_debugfs_exit(struct sdw_bus *bus); |
| 25 | void sdw_slave_debugfs_init(struct sdw_slave *slave); |
| 26 | void sdw_slave_debugfs_exit(struct sdw_slave *slave); |
| 27 | void sdw_debugfs_init(void); |
| 28 | void sdw_debugfs_exit(void); |
| 29 | #else |
| 30 | static inline void sdw_bus_debugfs_init(struct sdw_bus *bus) {} |
| 31 | static inline void sdw_bus_debugfs_exit(struct sdw_bus *bus) {} |
| 32 | static inline void sdw_slave_debugfs_init(struct sdw_slave *slave) {} |
| 33 | static inline void sdw_slave_debugfs_exit(struct sdw_slave *slave) {} |
| 34 | static inline void sdw_debugfs_init(void) {} |
| 35 | static inline void sdw_debugfs_exit(void) {} |
| 36 | #endif |
| 37 | |
Vinod Koul | 9d715fa | 2017-12-14 11:19:37 +0530 | [diff] [blame] | 38 | enum { |
| 39 | SDW_MSG_FLAG_READ = 0, |
| 40 | SDW_MSG_FLAG_WRITE, |
| 41 | }; |
| 42 | |
| 43 | /** |
| 44 | * struct sdw_msg - Message structure |
| 45 | * @addr: Register address accessed in the Slave |
| 46 | * @len: number of messages |
| 47 | * @dev_num: Slave device number |
| 48 | * @addr_page1: SCP address page 1 Slave register |
| 49 | * @addr_page2: SCP address page 2 Slave register |
| 50 | * @flags: transfer flags, indicate if xfer is read or write |
| 51 | * @buf: message data buffer |
| 52 | * @ssp_sync: Send message at SSP (Stream Synchronization Point) |
| 53 | * @page: address requires paging |
| 54 | */ |
| 55 | struct sdw_msg { |
| 56 | u16 addr; |
| 57 | u16 len; |
| 58 | u8 dev_num; |
| 59 | u8 addr_page1; |
| 60 | u8 addr_page2; |
| 61 | u8 flags; |
| 62 | u8 *buf; |
| 63 | bool ssp_sync; |
| 64 | bool page; |
| 65 | }; |
| 66 | |
Sanyog Kale | 99b8a5d | 2018-04-26 18:38:28 +0530 | [diff] [blame] | 67 | #define SDW_DOUBLE_RATE_FACTOR 2 |
| 68 | |
Pierre-Louis Bossart | fe4b70f | 2019-08-05 19:55:10 -0500 | [diff] [blame] | 69 | extern int sdw_rows[SDW_FRAME_ROWS]; |
| 70 | extern int sdw_cols[SDW_FRAME_COLS]; |
| 71 | |
| 72 | int sdw_find_row_index(int row); |
| 73 | int sdw_find_col_index(int col); |
Sanyog Kale | 99b8a5d | 2018-04-26 18:38:28 +0530 | [diff] [blame] | 74 | |
Sanyog Kale | 89e5905 | 2018-04-26 18:38:08 +0530 | [diff] [blame] | 75 | /** |
Sanyog Kale | bbe7379 | 2018-04-26 18:38:13 +0530 | [diff] [blame] | 76 | * sdw_port_runtime: Runtime port parameters for Master or Slave |
| 77 | * |
| 78 | * @num: Port number. For audio streams, valid port number ranges from |
| 79 | * [1,14] |
| 80 | * @ch_mask: Channel mask |
| 81 | * @transport_params: Transport parameters |
| 82 | * @port_params: Port parameters |
| 83 | * @port_node: List node for Master or Slave port_list |
| 84 | * |
| 85 | * SoundWire spec has no mention of ports for Master interface but the |
| 86 | * concept is logically extended. |
| 87 | */ |
| 88 | struct sdw_port_runtime { |
| 89 | int num; |
| 90 | int ch_mask; |
| 91 | struct sdw_transport_params transport_params; |
| 92 | struct sdw_port_params port_params; |
| 93 | struct list_head port_node; |
| 94 | }; |
| 95 | |
| 96 | /** |
Sanyog Kale | 89e5905 | 2018-04-26 18:38:08 +0530 | [diff] [blame] | 97 | * sdw_slave_runtime: Runtime Stream parameters for Slave |
| 98 | * |
| 99 | * @slave: Slave handle |
| 100 | * @direction: Data direction for Slave |
| 101 | * @ch_count: Number of channels handled by the Slave for |
| 102 | * this stream |
| 103 | * @m_rt_node: sdw_master_runtime list node |
Sanyog Kale | bbe7379 | 2018-04-26 18:38:13 +0530 | [diff] [blame] | 104 | * @port_list: List of Slave Ports configured for this stream |
Sanyog Kale | 89e5905 | 2018-04-26 18:38:08 +0530 | [diff] [blame] | 105 | */ |
| 106 | struct sdw_slave_runtime { |
| 107 | struct sdw_slave *slave; |
| 108 | enum sdw_data_direction direction; |
| 109 | unsigned int ch_count; |
| 110 | struct list_head m_rt_node; |
Sanyog Kale | bbe7379 | 2018-04-26 18:38:13 +0530 | [diff] [blame] | 111 | struct list_head port_list; |
Sanyog Kale | 89e5905 | 2018-04-26 18:38:08 +0530 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | /** |
| 115 | * sdw_master_runtime: Runtime stream parameters for Master |
| 116 | * |
| 117 | * @bus: Bus handle |
| 118 | * @stream: Stream runtime handle |
| 119 | * @direction: Data direction for Master |
| 120 | * @ch_count: Number of channels handled by the Master for |
| 121 | * this stream, can be zero. |
| 122 | * @slave_rt_list: Slave runtime list |
Sanyog Kale | bbe7379 | 2018-04-26 18:38:13 +0530 | [diff] [blame] | 123 | * @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] | 124 | * @stream_node: sdw_stream_runtime master_list node |
Sanyog Kale | 89e5905 | 2018-04-26 18:38:08 +0530 | [diff] [blame] | 125 | * @bus_node: sdw_bus m_rt_list node |
| 126 | */ |
| 127 | struct sdw_master_runtime { |
| 128 | struct sdw_bus *bus; |
| 129 | struct sdw_stream_runtime *stream; |
| 130 | enum sdw_data_direction direction; |
| 131 | unsigned int ch_count; |
| 132 | struct list_head slave_rt_list; |
Sanyog Kale | bbe7379 | 2018-04-26 18:38:13 +0530 | [diff] [blame] | 133 | struct list_head port_list; |
Sanyog Kale | 0c4a104 | 2018-07-27 14:44:13 +0530 | [diff] [blame] | 134 | struct list_head stream_node; |
Sanyog Kale | 89e5905 | 2018-04-26 18:38:08 +0530 | [diff] [blame] | 135 | struct list_head bus_node; |
| 136 | }; |
| 137 | |
Sanyog Kale | f8101c7 | 2018-04-26 18:38:17 +0530 | [diff] [blame] | 138 | 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] | 139 | enum sdw_data_direction direction, |
| 140 | unsigned int port_num); |
Sanyog Kale | 79df15b | 2018-04-26 18:38:23 +0530 | [diff] [blame] | 141 | int sdw_configure_dpn_intr(struct sdw_slave *slave, int port, |
Pierre-Louis Bossart | 806a11f | 2019-05-01 10:57:26 -0500 | [diff] [blame] | 142 | bool enable, int mask); |
Sanyog Kale | f8101c7 | 2018-04-26 18:38:17 +0530 | [diff] [blame] | 143 | |
Vinod Koul | 9d715fa | 2017-12-14 11:19:37 +0530 | [diff] [blame] | 144 | int sdw_transfer(struct sdw_bus *bus, struct sdw_msg *msg); |
| 145 | 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] | 146 | struct sdw_defer *defer); |
Vinod Koul | 9d715fa | 2017-12-14 11:19:37 +0530 | [diff] [blame] | 147 | |
Vinod Koul | b0a9c37 | 2017-12-14 11:19:40 +0530 | [diff] [blame] | 148 | #define SDW_READ_INTR_CLEAR_RETRY 10 |
| 149 | |
Vinod Koul | 9d715fa | 2017-12-14 11:19:37 +0530 | [diff] [blame] | 150 | 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] | 151 | u32 addr, size_t count, u16 dev_num, u8 flags, u8 *buf); |
Vinod Koul | 9d715fa | 2017-12-14 11:19:37 +0530 | [diff] [blame] | 152 | |
Sanyog Kale | d52d7a1 | 2017-12-14 11:19:39 +0530 | [diff] [blame] | 153 | /* Read-Modify-Write Slave register */ |
| 154 | static inline int |
| 155 | sdw_update(struct sdw_slave *slave, u32 addr, u8 mask, u8 val) |
| 156 | { |
| 157 | int tmp; |
| 158 | |
| 159 | tmp = sdw_read(slave, addr); |
| 160 | if (tmp < 0) |
| 161 | return tmp; |
| 162 | |
| 163 | tmp = (tmp & ~mask) | val; |
| 164 | return sdw_write(slave, addr, tmp); |
| 165 | } |
| 166 | |
Vinod Koul | 7c3cd18 | 2017-12-14 11:19:34 +0530 | [diff] [blame] | 167 | #endif /* __SDW_BUS_H */ |