1 /* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
2 /* Copyright(c) 2015-17 Intel Corporation. */
5 #ifndef __SDW_CADENCE_H
6 #define __SDW_CADENCE_H
8 #define SDW_CADENCE_GSYNC_KHZ 4 /* 4 kHz */
9 #define SDW_CADENCE_GSYNC_HZ (SDW_CADENCE_GSYNC_KHZ * 1000)
12 * struct sdw_cdns_pdi: PDI (Physical Data Interface) instance
15 * @intel_alh_id: link identifier
16 * @l_ch_num: low channel for PDI
17 * @h_ch_num: high channel for PDI
18 * @ch_count: total channel count for PDI
19 * @dir: data direction
20 * @type: stream type, (only PCM supported)
28 enum sdw_data_direction dir;
29 enum sdw_stream_type type;
33 * struct sdw_cdns_streams: Cadence stream data structure
35 * @num_bd: number of bidirectional streams
36 * @num_in: number of input streams
37 * @num_out: number of output streams
38 * @num_ch_bd: number of bidirectional stream channels
39 * @num_ch_bd: number of input stream channels
40 * @num_ch_bd: number of output stream channels
41 * @num_pdi: total number of PDIs
42 * @bd: bidirectional streams
44 * @out: output streams
46 struct sdw_cdns_streams {
50 unsigned int num_ch_bd;
51 unsigned int num_ch_in;
52 unsigned int num_ch_out;
54 struct sdw_cdns_pdi *bd;
55 struct sdw_cdns_pdi *in;
56 struct sdw_cdns_pdi *out;
60 * struct sdw_cdns_stream_config: stream configuration
62 * @pcm_bd: number of bidirectional PCM streams supported
63 * @pcm_in: number of input PCM streams supported
64 * @pcm_out: number of output PCM streams supported
66 struct sdw_cdns_stream_config {
73 * struct sdw_cdns_dai_runtime: Cadence DAI runtime data
75 * @name: SoundWire stream name
76 * @stream: stream runtime
77 * @pdi: PDI used for this dai
79 * @stream_type: Stream type
80 * @link_id: Master link id
81 * @hw_params: hw_params to be applied in .prepare step
82 * @suspended: status set when suspended, to be used in .prepare
83 * @paused: status set in .trigger, to be used in suspend
84 * @direction: stream direction
86 struct sdw_cdns_dai_runtime {
88 struct sdw_stream_runtime *stream;
89 struct sdw_cdns_pdi *pdi;
91 enum sdw_stream_type stream_type;
93 struct snd_pcm_hw_params *hw_params;
100 * struct sdw_cdns - Cadence driver context
103 * @instance: instance number
104 * @response_buf: SoundWire response buffer
105 * @tx_complete: Tx completion
106 * @defer: Defer pointer
108 * @num_ports: Total number of data ports
110 * @registers: Cadence registers
111 * @link_up: Link status
112 * @msg_count: Messages sent on bus
113 * @dai_runtime_array: runtime context for each allocated DAI.
118 unsigned int instance;
120 u32 response_buf[0x80];
121 struct completion tx_complete;
122 struct sdw_defer *defer;
124 struct sdw_cdns_port *ports;
127 struct sdw_cdns_streams pcm;
129 int pdi_loopback_source;
130 int pdi_loopback_target;
132 void __iomem *registers;
135 unsigned int msg_count;
136 bool interrupt_enabled;
138 struct work_struct work;
140 struct list_head list;
142 struct sdw_cdns_dai_runtime **dai_runtime_array;
145 #define bus_to_cdns(_bus) container_of(_bus, struct sdw_cdns, bus)
147 /* Exported symbols */
149 int sdw_cdns_probe(struct sdw_cdns *cdns);
150 extern struct sdw_master_ops sdw_cdns_master_ops;
152 irqreturn_t sdw_cdns_irq(int irq, void *dev_id);
153 irqreturn_t sdw_cdns_thread(int irq, void *dev_id);
155 int sdw_cdns_init(struct sdw_cdns *cdns);
156 int sdw_cdns_pdi_init(struct sdw_cdns *cdns,
157 struct sdw_cdns_stream_config config);
158 int sdw_cdns_exit_reset(struct sdw_cdns *cdns);
159 int sdw_cdns_enable_interrupt(struct sdw_cdns *cdns, bool state);
161 bool sdw_cdns_is_clock_stop(struct sdw_cdns *cdns);
162 int sdw_cdns_clock_stop(struct sdw_cdns *cdns, bool block_wake);
163 int sdw_cdns_clock_restart(struct sdw_cdns *cdns, bool bus_reset);
165 #ifdef CONFIG_DEBUG_FS
166 void sdw_cdns_debugfs_init(struct sdw_cdns *cdns, struct dentry *root);
169 struct sdw_cdns_pdi *sdw_cdns_alloc_pdi(struct sdw_cdns *cdns,
170 struct sdw_cdns_streams *stream,
171 u32 ch, u32 dir, int dai_id);
172 void sdw_cdns_config_stream(struct sdw_cdns *cdns,
173 u32 ch, u32 dir, struct sdw_cdns_pdi *pdi);
175 enum sdw_command_response
176 cdns_reset_page_addr(struct sdw_bus *bus, unsigned int dev_num);
178 enum sdw_command_response
179 cdns_xfer_msg(struct sdw_bus *bus, struct sdw_msg *msg);
181 enum sdw_command_response
182 cdns_xfer_msg_defer(struct sdw_bus *bus,
183 struct sdw_msg *msg, struct sdw_defer *defer);
185 u32 cdns_read_ping_status(struct sdw_bus *bus);
187 int cdns_bus_conf(struct sdw_bus *bus, struct sdw_bus_params *params);
189 int cdns_set_sdw_stream(struct snd_soc_dai *dai,
190 void *stream, int direction);
192 void sdw_cdns_check_self_clearing_bits(struct sdw_cdns *cdns, const char *string,
193 bool initial_delay, int reset_iterations);
195 #endif /* __SDW_CADENCE_H */