blob: 6199e71edeab7eabeb2bf12921086b86d10fcc89 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001/* 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/**
9 * struct sdw_cdns_pdi: PDI (Physical Data Interface) instance
10 *
11 * @num: pdi number
12 * @intel_alh_id: link identifier
13 * @l_ch_num: low channel for PDI
14 * @h_ch_num: high channel for PDI
15 * @ch_count: total channel count for PDI
16 * @dir: data direction
17 * @type: stream type, PDM or PCM
18 */
19struct sdw_cdns_pdi {
20 int num;
21 int intel_alh_id;
22 int l_ch_num;
23 int h_ch_num;
24 int ch_count;
25 enum sdw_data_direction dir;
26 enum sdw_stream_type type;
27};
28
29/**
30 * struct sdw_cdns_streams: Cadence stream data structure
31 *
32 * @num_bd: number of bidirectional streams
33 * @num_in: number of input streams
34 * @num_out: number of output streams
35 * @num_ch_bd: number of bidirectional stream channels
36 * @num_ch_bd: number of input stream channels
37 * @num_ch_bd: number of output stream channels
38 * @num_pdi: total number of PDIs
39 * @bd: bidirectional streams
40 * @in: input streams
41 * @out: output streams
42 */
43struct sdw_cdns_streams {
44 unsigned int num_bd;
45 unsigned int num_in;
46 unsigned int num_out;
47 unsigned int num_ch_bd;
48 unsigned int num_ch_in;
49 unsigned int num_ch_out;
50 unsigned int num_pdi;
51 struct sdw_cdns_pdi *bd;
52 struct sdw_cdns_pdi *in;
53 struct sdw_cdns_pdi *out;
54};
55
56/**
57 * struct sdw_cdns_stream_config: stream configuration
58 *
59 * @pcm_bd: number of bidirectional PCM streams supported
60 * @pcm_in: number of input PCM streams supported
61 * @pcm_out: number of output PCM streams supported
62 * @pdm_bd: number of bidirectional PDM streams supported
63 * @pdm_in: number of input PDM streams supported
64 * @pdm_out: number of output PDM streams supported
65 */
66struct sdw_cdns_stream_config {
67 unsigned int pcm_bd;
68 unsigned int pcm_in;
69 unsigned int pcm_out;
70 unsigned int pdm_bd;
71 unsigned int pdm_in;
72 unsigned int pdm_out;
73};
74
75/**
76 * struct sdw_cdns_dma_data: Cadence DMA data
77 *
78 * @name: SoundWire stream name
79 * @stream: stream runtime
80 * @pdi: PDI used for this dai
81 * @bus: Bus handle
82 * @stream_type: Stream type
83 * @link_id: Master link id
84 */
85struct sdw_cdns_dma_data {
86 char *name;
87 struct sdw_stream_runtime *stream;
88 struct sdw_cdns_pdi *pdi;
89 struct sdw_bus *bus;
90 enum sdw_stream_type stream_type;
91 int link_id;
92};
93
94/**
95 * struct sdw_cdns - Cadence driver context
96 * @dev: Linux device
97 * @bus: Bus handle
98 * @instance: instance number
99 * @response_buf: SoundWire response buffer
100 * @tx_complete: Tx completion
101 * @defer: Defer pointer
102 * @ports: Data ports
103 * @num_ports: Total number of data ports
104 * @pcm: PCM streams
105 * @pdm: PDM streams
106 * @registers: Cadence registers
107 * @link_up: Link status
108 * @msg_count: Messages sent on bus
109 */
110struct sdw_cdns {
111 struct device *dev;
112 struct sdw_bus bus;
113 unsigned int instance;
114
115 u32 response_buf[0x80];
116 struct completion tx_complete;
117 struct sdw_defer *defer;
118
119 struct sdw_cdns_port *ports;
120 int num_ports;
121
122 struct sdw_cdns_streams pcm;
123 struct sdw_cdns_streams pdm;
124
125 void __iomem *registers;
126
127 bool link_up;
128 unsigned int msg_count;
129};
130
131#define bus_to_cdns(_bus) container_of(_bus, struct sdw_cdns, bus)
132
133/* Exported symbols */
134
135int sdw_cdns_probe(struct sdw_cdns *cdns);
136extern struct sdw_master_ops sdw_cdns_master_ops;
137
138irqreturn_t sdw_cdns_irq(int irq, void *dev_id);
139irqreturn_t sdw_cdns_thread(int irq, void *dev_id);
140
141int sdw_cdns_init(struct sdw_cdns *cdns);
142int sdw_cdns_pdi_init(struct sdw_cdns *cdns,
143 struct sdw_cdns_stream_config config);
144int sdw_cdns_exit_reset(struct sdw_cdns *cdns);
145int sdw_cdns_enable_interrupt(struct sdw_cdns *cdns);
146
147#ifdef CONFIG_DEBUG_FS
148void sdw_cdns_debugfs_init(struct sdw_cdns *cdns, struct dentry *root);
149#endif
150
151int sdw_cdns_get_stream(struct sdw_cdns *cdns,
152 struct sdw_cdns_streams *stream,
153 u32 ch, u32 dir);
154struct sdw_cdns_pdi *sdw_cdns_alloc_pdi(struct sdw_cdns *cdns,
155 struct sdw_cdns_streams *stream,
156 u32 ch, u32 dir, int dai_id);
157void sdw_cdns_config_stream(struct sdw_cdns *cdns,
158 u32 ch, u32 dir, struct sdw_cdns_pdi *pdi);
159
160int sdw_cdns_pcm_set_stream(struct snd_soc_dai *dai,
161 void *stream, int direction);
162int sdw_cdns_pdm_set_stream(struct snd_soc_dai *dai,
163 void *stream, int direction);
164
165enum sdw_command_response
166cdns_reset_page_addr(struct sdw_bus *bus, unsigned int dev_num);
167
168enum sdw_command_response
169cdns_xfer_msg(struct sdw_bus *bus, struct sdw_msg *msg);
170
171enum sdw_command_response
172cdns_xfer_msg_defer(struct sdw_bus *bus,
173 struct sdw_msg *msg, struct sdw_defer *defer);
174
175enum sdw_command_response
176cdns_reset_page_addr(struct sdw_bus *bus, unsigned int dev_num);
177
178int cdns_bus_conf(struct sdw_bus *bus, struct sdw_bus_params *params);
179
180int cdns_set_sdw_stream(struct snd_soc_dai *dai,
181 void *stream, bool pcm, int direction);
182#endif /* __SDW_CADENCE_H */