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 * The Cadence IP supports up to 32 entries in the FIFO, though implementations
13 * can configure the IP to have a smaller FIFO.
15 #define CDNS_MCP_IP_MAX_CMD_LEN 32
18 * struct sdw_cdns_pdi: PDI (Physical Data Interface) instance
21 * @intel_alh_id: link identifier
22 * @l_ch_num: low channel for PDI
23 * @h_ch_num: high channel for PDI
24 * @ch_count: total channel count for PDI
25 * @dir: data direction
26 * @type: stream type, PDM or PCM
34 enum sdw_data_direction dir;
35 enum sdw_stream_type type;
39 * struct sdw_cdns_streams: Cadence stream data structure
41 * @num_bd: number of bidirectional streams
42 * @num_in: number of input streams
43 * @num_out: number of output streams
44 * @num_ch_bd: number of bidirectional stream channels
45 * @num_ch_bd: number of input stream channels
46 * @num_ch_bd: number of output stream channels
47 * @num_pdi: total number of PDIs
48 * @bd: bidirectional streams
50 * @out: output streams
52 struct sdw_cdns_streams {
56 unsigned int num_ch_bd;
57 unsigned int num_ch_in;
58 unsigned int num_ch_out;
60 struct sdw_cdns_pdi *bd;
61 struct sdw_cdns_pdi *in;
62 struct sdw_cdns_pdi *out;
66 * struct sdw_cdns_stream_config: stream configuration
68 * @pcm_bd: number of bidirectional PCM streams supported
69 * @pcm_in: number of input PCM streams supported
70 * @pcm_out: number of output PCM streams supported
71 * @pdm_bd: number of bidirectional PDM streams supported
72 * @pdm_in: number of input PDM streams supported
73 * @pdm_out: number of output PDM streams supported
75 struct sdw_cdns_stream_config {
85 * struct sdw_cdns_dma_data: Cadence DMA data
87 * @name: SoundWire stream name
88 * @stream: stream runtime
89 * @pdi: PDI used for this dai
91 * @stream_type: Stream type
92 * @link_id: Master link id
93 * @hw_params: hw_params to be applied in .prepare step
94 * @suspended: status set when suspended, to be used in .prepare
96 struct sdw_cdns_dma_data {
98 struct sdw_stream_runtime *stream;
99 struct sdw_cdns_pdi *pdi;
101 enum sdw_stream_type stream_type;
103 struct snd_pcm_hw_params *hw_params;
108 * struct sdw_cdns - Cadence driver context
111 * @instance: instance number
112 * @response_buf: SoundWire response buffer
113 * @tx_complete: Tx completion
114 * @defer: Defer pointer
116 * @num_ports: Total number of data ports
119 * @registers: Cadence registers
120 * @link_up: Link status
121 * @msg_count: Messages sent on bus
126 unsigned int instance;
129 * The datasheet says the RX FIFO AVAIL can be 2 entries more
130 * than the FIFO capacity, so allow for this.
132 u32 response_buf[CDNS_MCP_IP_MAX_CMD_LEN + 2];
134 struct completion tx_complete;
135 struct sdw_defer *defer;
137 struct sdw_cdns_port *ports;
140 struct sdw_cdns_streams pcm;
141 struct sdw_cdns_streams pdm;
143 void __iomem *registers;
146 unsigned int msg_count;
147 bool interrupt_enabled;
149 struct work_struct work;
151 struct list_head list;
154 #define bus_to_cdns(_bus) container_of(_bus, struct sdw_cdns, bus)
156 /* Exported symbols */
158 int sdw_cdns_probe(struct sdw_cdns *cdns);
159 extern struct sdw_master_ops sdw_cdns_master_ops;
161 irqreturn_t sdw_cdns_irq(int irq, void *dev_id);
162 irqreturn_t sdw_cdns_thread(int irq, void *dev_id);
164 int sdw_cdns_init(struct sdw_cdns *cdns);
165 int sdw_cdns_pdi_init(struct sdw_cdns *cdns,
166 struct sdw_cdns_stream_config config);
167 int sdw_cdns_exit_reset(struct sdw_cdns *cdns);
168 int sdw_cdns_enable_interrupt(struct sdw_cdns *cdns, bool state);
170 bool sdw_cdns_is_clock_stop(struct sdw_cdns *cdns);
171 int sdw_cdns_clock_stop(struct sdw_cdns *cdns, bool block_wake);
172 int sdw_cdns_clock_restart(struct sdw_cdns *cdns, bool bus_reset);
174 #ifdef CONFIG_DEBUG_FS
175 void sdw_cdns_debugfs_init(struct sdw_cdns *cdns, struct dentry *root);
178 struct sdw_cdns_pdi *sdw_cdns_alloc_pdi(struct sdw_cdns *cdns,
179 struct sdw_cdns_streams *stream,
180 u32 ch, u32 dir, int dai_id);
181 void sdw_cdns_config_stream(struct sdw_cdns *cdns,
182 u32 ch, u32 dir, struct sdw_cdns_pdi *pdi);
184 enum sdw_command_response
185 cdns_reset_page_addr(struct sdw_bus *bus, unsigned int dev_num);
187 enum sdw_command_response
188 cdns_xfer_msg(struct sdw_bus *bus, struct sdw_msg *msg);
190 enum sdw_command_response
191 cdns_xfer_msg_defer(struct sdw_bus *bus,
192 struct sdw_msg *msg, struct sdw_defer *defer);
194 enum sdw_command_response
195 cdns_reset_page_addr(struct sdw_bus *bus, unsigned int dev_num);
197 int cdns_bus_conf(struct sdw_bus *bus, struct sdw_bus_params *params);
199 int cdns_set_sdw_stream(struct snd_soc_dai *dai,
200 void *stream, bool pcm, int direction);
201 #endif /* __SDW_CADENCE_H */