blob: 82484f7411687d401655e583c075c5d8388b9894 [file] [log] [blame]
Pierre-Louis Bossart23859462019-05-01 10:57:25 -05001/* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
2/* Copyright(c) 2015-17 Intel Corporation. */
Vinod Koul7c3cd182017-12-14 11:19:34 +05303
4#ifndef __SDW_BUS_H
5#define __SDW_BUS_H
6
Shreyas NCce6e74d2018-07-27 14:44:16 +05307#define DEFAULT_BANK_SWITCH_TIMEOUT 3000
Pierre-Louis Bossart2140b662020-01-14 18:08:35 -06008#define DEFAULT_PROBE_TIMEOUT 2000
Shreyas NCce6e74d2018-07-27 14:44:16 +05309
Vinod Koul7c3cd182017-12-14 11:19:34 +053010#if IS_ENABLED(CONFIG_ACPI)
11int sdw_acpi_find_slaves(struct sdw_bus *bus);
12#else
13static inline int sdw_acpi_find_slaves(struct sdw_bus *bus)
14{
15 return -ENOTSUPP;
16}
17#endif
18
Srinivas Kandagatlaa2e48452019-08-29 17:35:12 +010019int sdw_of_find_slaves(struct sdw_bus *bus);
Vinod Koul7c3cd182017-12-14 11:19:34 +053020void sdw_extract_slave_id(struct sdw_bus *bus,
Pierre-Louis Bossart806a11f2019-05-01 10:57:26 -050021 u64 addr, struct sdw_slave_id *id);
Pierre-Louis Bossart7ceaa402020-05-19 01:43:21 +080022int sdw_master_device_add(struct sdw_bus *bus, struct device *parent,
23 struct fwnode_handle *fwnode);
24int sdw_master_device_del(struct sdw_bus *bus);
Vinod Koul7c3cd182017-12-14 11:19:34 +053025
Pierre-Louis Bossartbf034732019-08-21 13:58:18 -050026#ifdef CONFIG_DEBUG_FS
27void sdw_bus_debugfs_init(struct sdw_bus *bus);
28void sdw_bus_debugfs_exit(struct sdw_bus *bus);
29void sdw_slave_debugfs_init(struct sdw_slave *slave);
30void sdw_slave_debugfs_exit(struct sdw_slave *slave);
31void sdw_debugfs_init(void);
32void sdw_debugfs_exit(void);
33#else
34static inline void sdw_bus_debugfs_init(struct sdw_bus *bus) {}
35static inline void sdw_bus_debugfs_exit(struct sdw_bus *bus) {}
36static inline void sdw_slave_debugfs_init(struct sdw_slave *slave) {}
37static inline void sdw_slave_debugfs_exit(struct sdw_slave *slave) {}
38static inline void sdw_debugfs_init(void) {}
39static inline void sdw_debugfs_exit(void) {}
40#endif
41
Vinod Koul9d715fa2017-12-14 11:19:37 +053042enum {
43 SDW_MSG_FLAG_READ = 0,
44 SDW_MSG_FLAG_WRITE,
45};
46
47/**
48 * struct sdw_msg - Message structure
49 * @addr: Register address accessed in the Slave
50 * @len: number of messages
51 * @dev_num: Slave device number
52 * @addr_page1: SCP address page 1 Slave register
53 * @addr_page2: SCP address page 2 Slave register
54 * @flags: transfer flags, indicate if xfer is read or write
55 * @buf: message data buffer
56 * @ssp_sync: Send message at SSP (Stream Synchronization Point)
57 * @page: address requires paging
58 */
59struct sdw_msg {
60 u16 addr;
61 u16 len;
62 u8 dev_num;
63 u8 addr_page1;
64 u8 addr_page2;
65 u8 flags;
66 u8 *buf;
67 bool ssp_sync;
68 bool page;
69};
70
Sanyog Kale99b8a5d2018-04-26 18:38:28 +053071#define SDW_DOUBLE_RATE_FACTOR 2
72
Pierre-Louis Bossartfe4b70f2019-08-05 19:55:10 -050073extern int sdw_rows[SDW_FRAME_ROWS];
74extern int sdw_cols[SDW_FRAME_COLS];
75
76int sdw_find_row_index(int row);
77int sdw_find_col_index(int col);
Sanyog Kale99b8a5d2018-04-26 18:38:28 +053078
Sanyog Kale89e59052018-04-26 18:38:08 +053079/**
Sanyog Kalebbe73792018-04-26 18:38:13 +053080 * sdw_port_runtime: Runtime port parameters for Master or Slave
81 *
82 * @num: Port number. For audio streams, valid port number ranges from
83 * [1,14]
84 * @ch_mask: Channel mask
85 * @transport_params: Transport parameters
86 * @port_params: Port parameters
87 * @port_node: List node for Master or Slave port_list
88 *
89 * SoundWire spec has no mention of ports for Master interface but the
90 * concept is logically extended.
91 */
92struct sdw_port_runtime {
93 int num;
94 int ch_mask;
95 struct sdw_transport_params transport_params;
96 struct sdw_port_params port_params;
97 struct list_head port_node;
98};
99
100/**
Sanyog Kale89e59052018-04-26 18:38:08 +0530101 * sdw_slave_runtime: Runtime Stream parameters for Slave
102 *
103 * @slave: Slave handle
104 * @direction: Data direction for Slave
105 * @ch_count: Number of channels handled by the Slave for
106 * this stream
107 * @m_rt_node: sdw_master_runtime list node
Sanyog Kalebbe73792018-04-26 18:38:13 +0530108 * @port_list: List of Slave Ports configured for this stream
Sanyog Kale89e59052018-04-26 18:38:08 +0530109 */
110struct sdw_slave_runtime {
111 struct sdw_slave *slave;
112 enum sdw_data_direction direction;
113 unsigned int ch_count;
114 struct list_head m_rt_node;
Sanyog Kalebbe73792018-04-26 18:38:13 +0530115 struct list_head port_list;
Sanyog Kale89e59052018-04-26 18:38:08 +0530116};
117
118/**
119 * sdw_master_runtime: Runtime stream parameters for Master
120 *
121 * @bus: Bus handle
122 * @stream: Stream runtime handle
123 * @direction: Data direction for Master
124 * @ch_count: Number of channels handled by the Master for
125 * this stream, can be zero.
126 * @slave_rt_list: Slave runtime list
Sanyog Kalebbe73792018-04-26 18:38:13 +0530127 * @port_list: List of Master Ports configured for this stream, can be zero.
Sanyog Kale0c4a1042018-07-27 14:44:13 +0530128 * @stream_node: sdw_stream_runtime master_list node
Sanyog Kale89e59052018-04-26 18:38:08 +0530129 * @bus_node: sdw_bus m_rt_list node
130 */
131struct sdw_master_runtime {
132 struct sdw_bus *bus;
133 struct sdw_stream_runtime *stream;
134 enum sdw_data_direction direction;
135 unsigned int ch_count;
136 struct list_head slave_rt_list;
Sanyog Kalebbe73792018-04-26 18:38:13 +0530137 struct list_head port_list;
Sanyog Kale0c4a1042018-07-27 14:44:13 +0530138 struct list_head stream_node;
Sanyog Kale89e59052018-04-26 18:38:08 +0530139 struct list_head bus_node;
140};
141
Sanyog Kalef8101c72018-04-26 18:38:17 +0530142struct sdw_dpn_prop *sdw_get_slave_dpn_prop(struct sdw_slave *slave,
Pierre-Louis Bossart806a11f2019-05-01 10:57:26 -0500143 enum sdw_data_direction direction,
144 unsigned int port_num);
Sanyog Kale79df15b2018-04-26 18:38:23 +0530145int sdw_configure_dpn_intr(struct sdw_slave *slave, int port,
Pierre-Louis Bossart806a11f2019-05-01 10:57:26 -0500146 bool enable, int mask);
Sanyog Kalef8101c72018-04-26 18:38:17 +0530147
Vinod Koul9d715fa2017-12-14 11:19:37 +0530148int sdw_transfer(struct sdw_bus *bus, struct sdw_msg *msg);
149int sdw_transfer_defer(struct sdw_bus *bus, struct sdw_msg *msg,
Pierre-Louis Bossart806a11f2019-05-01 10:57:26 -0500150 struct sdw_defer *defer);
Vinod Koul9d715fa2017-12-14 11:19:37 +0530151
Vinod Koulb0a9c372017-12-14 11:19:40 +0530152#define SDW_READ_INTR_CLEAR_RETRY 10
153
Vinod Koul9d715fa2017-12-14 11:19:37 +0530154int sdw_fill_msg(struct sdw_msg *msg, struct sdw_slave *slave,
Pierre-Louis Bossart806a11f2019-05-01 10:57:26 -0500155 u32 addr, size_t count, u16 dev_num, u8 flags, u8 *buf);
Vinod Koul9d715fa2017-12-14 11:19:37 +0530156
Sanyog Kaled52d7a12017-12-14 11:19:39 +0530157/* Read-Modify-Write Slave register */
158static inline int
159sdw_update(struct sdw_slave *slave, u32 addr, u8 mask, u8 val)
160{
161 int tmp;
162
163 tmp = sdw_read(slave, addr);
164 if (tmp < 0)
165 return tmp;
166
167 tmp = (tmp & ~mask) | val;
168 return sdw_write(slave, addr, tmp);
169}
170
Pierre-Louis Bossart3ab2ca42020-01-14 18:08:40 -0600171/*
172 * At the moment we only track Master-initiated hw_reset.
173 * Additional fields can be added as needed
174 */
175#define SDW_UNATTACH_REQUEST_MASTER_RESET BIT(0)
176
177void sdw_clear_slave_status(struct sdw_bus *bus, u32 request);
Pierre-Louis Bossartbcac5902020-05-19 04:35:51 +0800178int sdw_slave_modalias(const struct sdw_slave *slave, char *buf, size_t size);
Pierre-Louis Bossart3ab2ca42020-01-14 18:08:40 -0600179
Vinod Koul7c3cd182017-12-14 11:19:34 +0530180#endif /* __SDW_BUS_H */