Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
2/* Copyright(c) 2015-17 Intel Corporation. */
3#include <sound/soc.h>
4
5#ifndef __SDW_CADENCE_H
6#define __SDW_CADENCE_H
7
8#define SDW_CADENCE_GSYNC_KHZ 4 /* 4 kHz */
9#define SDW_CADENCE_GSYNC_HZ (SDW_CADENCE_GSYNC_KHZ * 1000)
10
11/*
12 * The Cadence IP supports up to 32 entries in the FIFO, though implementations
13 * can configure the IP to have a smaller FIFO.
14 */
15#define CDNS_MCP_IP_MAX_CMD_LEN 32
16
17#define SDW_CADENCE_MCP_IP_OFFSET 0x4000
18
19/**
20 * struct sdw_cdns_pdi: PDI (Physical Data Interface) instance
21 *
22 * @num: pdi number
23 * @intel_alh_id: link identifier
24 * @l_ch_num: low channel for PDI
25 * @h_ch_num: high channel for PDI
26 * @ch_count: total channel count for PDI
27 * @dir: data direction
28 * @type: stream type, (only PCM supported)
29 */
30struct sdw_cdns_pdi {
31 int num;
32 int intel_alh_id;
33 int l_ch_num;
34 int h_ch_num;
35 int ch_count;
36 enum sdw_data_direction dir;
37 enum sdw_stream_type type;
38};
39
40/**
41 * struct sdw_cdns_streams: Cadence stream data structure
42 *
43 * @num_bd: number of bidirectional streams
44 * @num_in: number of input streams
45 * @num_out: number of output streams
46 * @num_ch_bd: number of bidirectional stream channels
47 * @num_ch_bd: number of input stream channels
48 * @num_ch_bd: number of output stream channels
49 * @num_pdi: total number of PDIs
50 * @bd: bidirectional streams
51 * @in: input streams
52 * @out: output streams
53 */
54struct sdw_cdns_streams {
55 unsigned int num_bd;
56 unsigned int num_in;
57 unsigned int num_out;
58 unsigned int num_ch_bd;
59 unsigned int num_ch_in;
60 unsigned int num_ch_out;
61 unsigned int num_pdi;
62 struct sdw_cdns_pdi *bd;
63 struct sdw_cdns_pdi *in;
64 struct sdw_cdns_pdi *out;
65};
66
67/**
68 * struct sdw_cdns_stream_config: stream configuration
69 *
70 * @pcm_bd: number of bidirectional PCM streams supported
71 * @pcm_in: number of input PCM streams supported
72 * @pcm_out: number of output PCM streams supported
73 */
74struct sdw_cdns_stream_config {
75 unsigned int pcm_bd;
76 unsigned int pcm_in;
77 unsigned int pcm_out;
78};
79
80/**
81 * struct sdw_cdns_dai_runtime: Cadence DAI runtime data
82 *
83 * @name: SoundWire stream name
84 * @stream: stream runtime
85 * @pdi: PDI used for this dai
86 * @bus: Bus handle
87 * @stream_type: Stream type
88 * @link_id: Master link id
89 * @suspended: status set when suspended, to be used in .prepare
90 * @paused: status set in .trigger, to be used in suspend
91 * @direction: stream direction
92 */
93struct sdw_cdns_dai_runtime {
94 char *name;
95 struct sdw_stream_runtime *stream;
96 struct sdw_cdns_pdi *pdi;
97 struct sdw_bus *bus;
98 enum sdw_stream_type stream_type;
99 int link_id;
100 bool suspended;
101 bool paused;
102 int direction;
103};
104
105/**
106 * struct sdw_cdns - Cadence driver context
107 * @dev: Linux device
108 * @bus: Bus handle
109 * @instance: instance number
110 * @ip_offset: version-dependent offset to access IP_MCP registers and fields
111 * @response_buf: SoundWire response buffer
112 * @tx_complete: Tx completion
113 * @ports: Data ports
114 * @num_ports: Total number of data ports
115 * @pcm: PCM streams
116 * @registers: Cadence registers
117 * @link_up: Link status
118 * @msg_count: Messages sent on bus
119 * @dai_runtime_array: runtime context for each allocated DAI.
120 * @status_update_lock: protect concurrency between interrupt-based and delayed work
121 * status update
122 */
123struct sdw_cdns {
124 struct device *dev;
125 struct sdw_bus bus;
126 unsigned int instance;
127
128 u32 ip_offset;
129
130 /*
131 * The datasheet says the RX FIFO AVAIL can be 2 entries more
132 * than the FIFO capacity, so allow for this.
133 */
134 u32 response_buf[CDNS_MCP_IP_MAX_CMD_LEN + 2];
135
136 struct completion tx_complete;
137
138 struct sdw_cdns_port *ports;
139 int num_ports;
140
141 struct sdw_cdns_streams pcm;
142
143 int pdi_loopback_source;
144 int pdi_loopback_target;
145
146 void __iomem *registers;
147
148 bool link_up;
149 unsigned int msg_count;
150 bool interrupt_enabled;
151
152 struct work_struct work;
153 struct delayed_work attach_dwork;
154
155 struct list_head list;
156
157 struct sdw_cdns_dai_runtime **dai_runtime_array;
158
159 struct mutex status_update_lock; /* add mutual exclusion to sdw_handle_slave_status() */
160};
161
162#define bus_to_cdns(_bus) container_of(_bus, struct sdw_cdns, bus)
163
164/* Exported symbols */
165
166int sdw_cdns_probe(struct sdw_cdns *cdns);
167
168irqreturn_t sdw_cdns_irq(int irq, void *dev_id);
169irqreturn_t sdw_cdns_thread(int irq, void *dev_id);
170
171int sdw_cdns_soft_reset(struct sdw_cdns *cdns);
172int sdw_cdns_init(struct sdw_cdns *cdns);
173int sdw_cdns_pdi_init(struct sdw_cdns *cdns,
174 struct sdw_cdns_stream_config config);
175int sdw_cdns_exit_reset(struct sdw_cdns *cdns);
176int sdw_cdns_enable_interrupt(struct sdw_cdns *cdns, bool state);
177
178bool sdw_cdns_is_clock_stop(struct sdw_cdns *cdns);
179int sdw_cdns_clock_stop(struct sdw_cdns *cdns, bool block_wake);
180int sdw_cdns_clock_restart(struct sdw_cdns *cdns, bool bus_reset);
181
182#ifdef CONFIG_DEBUG_FS
183void sdw_cdns_debugfs_init(struct sdw_cdns *cdns, struct dentry *root);
184#endif
185
186struct sdw_cdns_pdi *sdw_cdns_alloc_pdi(struct sdw_cdns *cdns,
187 struct sdw_cdns_streams *stream,
188 u32 ch, u32 dir, int dai_id);
189void sdw_cdns_config_stream(struct sdw_cdns *cdns,
190 u32 ch, u32 dir, struct sdw_cdns_pdi *pdi);
191
192enum sdw_command_response
193cdns_xfer_msg(struct sdw_bus *bus, struct sdw_msg *msg);
194
195enum sdw_command_response
196cdns_xfer_msg_defer(struct sdw_bus *bus);
197
198u32 cdns_read_ping_status(struct sdw_bus *bus);
199
200int cdns_bus_conf(struct sdw_bus *bus, struct sdw_bus_params *params);
201
202int cdns_set_sdw_stream(struct snd_soc_dai *dai,
203 void *stream, int direction);
204
205void sdw_cdns_check_self_clearing_bits(struct sdw_cdns *cdns, const char *string,
206 bool initial_delay, int reset_iterations);
207
208void sdw_cdns_config_update(struct sdw_cdns *cdns);
209int sdw_cdns_config_update_set_wait(struct sdw_cdns *cdns);
210
211/* SoundWire BPT/BRA helpers to format data */
212int sdw_cdns_bpt_find_buffer_sizes(int command, /* 0: write, 1: read */
213 int row, int col, unsigned int data_bytes,
214 unsigned int requested_bytes_per_frame,
215 unsigned int *data_per_frame, unsigned int *pdi0_buffer_size,
216 unsigned int *pdi1_buffer_size, unsigned int *num_frames);
217
218int sdw_cdns_prepare_write_dma_buffer(u8 dev_num, u32 start_register, u8 *data, int data_size,
219 int data_per_frame, u8 *dma_buffer, int dma_buffer_size,
220 int *dma_buffer_total_bytes);
221
222int sdw_cdns_prepare_read_dma_buffer(u8 dev_num, u32 start_register, int data_size,
223 int data_per_frame, u8 *dma_buffer, int dma_buffer_size,
224 int *dma_buffer_total_bytes);
225
226int sdw_cdns_check_write_response(struct device *dev, u8 *dma_buffer,
227 int dma_buffer_size, int num_frames);
228
229int sdw_cdns_check_read_response(struct device *dev, u8 *dma_buffer, int dma_buffer_size,
230 u8 *buffer, int buffer_size, int num_frames, int data_per_frame);
231#endif /* __SDW_CADENCE_H */