Linux Audio

Check our new training course

Open-source upstreaming

Need help get the support for your hardware in upstream Linux?
Loading...
v5.9
  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 * struct sdw_cdns_pdi: PDI (Physical Data Interface) instance
 13 *
 14 * @num: pdi number
 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, PDM or PCM
 21 */
 22struct sdw_cdns_pdi {
 23	int num;
 24	int intel_alh_id;
 25	int l_ch_num;
 26	int h_ch_num;
 27	int ch_count;
 28	enum sdw_data_direction dir;
 29	enum sdw_stream_type type;
 30};
 31
 32/**
 33 * struct sdw_cdns_streams: Cadence stream data structure
 34 *
 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
 43 * @in: input streams
 44 * @out: output streams
 45 */
 46struct sdw_cdns_streams {
 47	unsigned int num_bd;
 48	unsigned int num_in;
 49	unsigned int num_out;
 50	unsigned int num_ch_bd;
 51	unsigned int num_ch_in;
 52	unsigned int num_ch_out;
 53	unsigned int num_pdi;
 54	struct sdw_cdns_pdi *bd;
 55	struct sdw_cdns_pdi *in;
 56	struct sdw_cdns_pdi *out;
 57};
 58
 59/**
 60 * struct sdw_cdns_stream_config: stream configuration
 61 *
 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
 65 * @pdm_bd: number of bidirectional PDM streams supported
 66 * @pdm_in: number of input PDM streams supported
 67 * @pdm_out: number of output PDM streams supported
 68 */
 69struct sdw_cdns_stream_config {
 70	unsigned int pcm_bd;
 71	unsigned int pcm_in;
 72	unsigned int pcm_out;
 73	unsigned int pdm_bd;
 74	unsigned int pdm_in;
 75	unsigned int pdm_out;
 76};
 77
 78/**
 79 * struct sdw_cdns_dma_data: Cadence DMA data
 80 *
 81 * @name: SoundWire stream name
 82 * @stream: stream runtime
 83 * @pdi: PDI used for this dai
 84 * @bus: Bus handle
 85 * @stream_type: Stream type
 86 * @link_id: Master link id
 
 
 
 
 87 */
 88struct sdw_cdns_dma_data {
 89	char *name;
 90	struct sdw_stream_runtime *stream;
 91	struct sdw_cdns_pdi *pdi;
 92	struct sdw_bus *bus;
 93	enum sdw_stream_type stream_type;
 94	int link_id;
 
 
 
 
 95};
 96
 97/**
 98 * struct sdw_cdns - Cadence driver context
 99 * @dev: Linux device
100 * @bus: Bus handle
101 * @instance: instance number
102 * @response_buf: SoundWire response buffer
103 * @tx_complete: Tx completion
104 * @defer: Defer pointer
105 * @ports: Data ports
106 * @num_ports: Total number of data ports
107 * @pcm: PCM streams
108 * @pdm: PDM streams
109 * @registers: Cadence registers
110 * @link_up: Link status
111 * @msg_count: Messages sent on bus
 
112 */
113struct sdw_cdns {
114	struct device *dev;
115	struct sdw_bus bus;
116	unsigned int instance;
117
118	u32 response_buf[0x80];
119	struct completion tx_complete;
120	struct sdw_defer *defer;
121
122	struct sdw_cdns_port *ports;
123	int num_ports;
124
125	struct sdw_cdns_streams pcm;
126	struct sdw_cdns_streams pdm;
 
 
127
128	void __iomem *registers;
129
130	bool link_up;
131	unsigned int msg_count;
 
132
133	struct work_struct work;
134
135	struct list_head list;
 
 
136};
137
138#define bus_to_cdns(_bus) container_of(_bus, struct sdw_cdns, bus)
139
140/* Exported symbols */
141
142int sdw_cdns_probe(struct sdw_cdns *cdns);
143extern struct sdw_master_ops sdw_cdns_master_ops;
144
145irqreturn_t sdw_cdns_irq(int irq, void *dev_id);
146irqreturn_t sdw_cdns_thread(int irq, void *dev_id);
147
148int sdw_cdns_init(struct sdw_cdns *cdns);
149int sdw_cdns_pdi_init(struct sdw_cdns *cdns,
150		      struct sdw_cdns_stream_config config);
151int sdw_cdns_exit_reset(struct sdw_cdns *cdns);
152int sdw_cdns_enable_interrupt(struct sdw_cdns *cdns, bool state);
153
154bool sdw_cdns_is_clock_stop(struct sdw_cdns *cdns);
155int sdw_cdns_clock_stop(struct sdw_cdns *cdns, bool block_wake);
156int sdw_cdns_clock_restart(struct sdw_cdns *cdns, bool bus_reset);
157
158#ifdef CONFIG_DEBUG_FS
159void sdw_cdns_debugfs_init(struct sdw_cdns *cdns, struct dentry *root);
160#endif
161
162struct sdw_cdns_pdi *sdw_cdns_alloc_pdi(struct sdw_cdns *cdns,
163					struct sdw_cdns_streams *stream,
164					u32 ch, u32 dir, int dai_id);
165void sdw_cdns_config_stream(struct sdw_cdns *cdns,
166			    u32 ch, u32 dir, struct sdw_cdns_pdi *pdi);
167
168enum sdw_command_response
169cdns_reset_page_addr(struct sdw_bus *bus, unsigned int dev_num);
170
171enum sdw_command_response
172cdns_xfer_msg(struct sdw_bus *bus, struct sdw_msg *msg);
173
174enum sdw_command_response
175cdns_xfer_msg_defer(struct sdw_bus *bus,
176		    struct sdw_msg *msg, struct sdw_defer *defer);
177
178enum sdw_command_response
179cdns_reset_page_addr(struct sdw_bus *bus, unsigned int dev_num);
180
181int cdns_bus_conf(struct sdw_bus *bus, struct sdw_bus_params *params);
182
183int cdns_set_sdw_stream(struct snd_soc_dai *dai,
184			void *stream, bool pcm, int direction);
 
 
 
 
185#endif /* __SDW_CADENCE_H */
v6.2
  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 * struct sdw_cdns_pdi: PDI (Physical Data Interface) instance
 13 *
 14 * @num: pdi number
 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)
 21 */
 22struct sdw_cdns_pdi {
 23	int num;
 24	int intel_alh_id;
 25	int l_ch_num;
 26	int h_ch_num;
 27	int ch_count;
 28	enum sdw_data_direction dir;
 29	enum sdw_stream_type type;
 30};
 31
 32/**
 33 * struct sdw_cdns_streams: Cadence stream data structure
 34 *
 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
 43 * @in: input streams
 44 * @out: output streams
 45 */
 46struct sdw_cdns_streams {
 47	unsigned int num_bd;
 48	unsigned int num_in;
 49	unsigned int num_out;
 50	unsigned int num_ch_bd;
 51	unsigned int num_ch_in;
 52	unsigned int num_ch_out;
 53	unsigned int num_pdi;
 54	struct sdw_cdns_pdi *bd;
 55	struct sdw_cdns_pdi *in;
 56	struct sdw_cdns_pdi *out;
 57};
 58
 59/**
 60 * struct sdw_cdns_stream_config: stream configuration
 61 *
 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
 
 
 
 65 */
 66struct sdw_cdns_stream_config {
 67	unsigned int pcm_bd;
 68	unsigned int pcm_in;
 69	unsigned int pcm_out;
 
 
 
 70};
 71
 72/**
 73 * struct sdw_cdns_dai_runtime: Cadence DAI runtime data
 74 *
 75 * @name: SoundWire stream name
 76 * @stream: stream runtime
 77 * @pdi: PDI used for this dai
 78 * @bus: Bus handle
 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
 85 */
 86struct sdw_cdns_dai_runtime {
 87	char *name;
 88	struct sdw_stream_runtime *stream;
 89	struct sdw_cdns_pdi *pdi;
 90	struct sdw_bus *bus;
 91	enum sdw_stream_type stream_type;
 92	int link_id;
 93	struct snd_pcm_hw_params *hw_params;
 94	bool suspended;
 95	bool paused;
 96	int direction;
 97};
 98
 99/**
100 * struct sdw_cdns - Cadence driver context
101 * @dev: Linux device
102 * @bus: Bus handle
103 * @instance: instance number
104 * @response_buf: SoundWire response buffer
105 * @tx_complete: Tx completion
106 * @defer: Defer pointer
107 * @ports: Data ports
108 * @num_ports: Total number of data ports
109 * @pcm: PCM streams
 
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.
114 */
115struct sdw_cdns {
116	struct device *dev;
117	struct sdw_bus bus;
118	unsigned int instance;
119
120	u32 response_buf[0x80];
121	struct completion tx_complete;
122	struct sdw_defer *defer;
123
124	struct sdw_cdns_port *ports;
125	int num_ports;
126
127	struct sdw_cdns_streams pcm;
128
129	int pdi_loopback_source;
130	int pdi_loopback_target;
131
132	void __iomem *registers;
133
134	bool link_up;
135	unsigned int msg_count;
136	bool interrupt_enabled;
137
138	struct work_struct work;
139
140	struct list_head list;
141
142	struct sdw_cdns_dai_runtime **dai_runtime_array;
143};
144
145#define bus_to_cdns(_bus) container_of(_bus, struct sdw_cdns, bus)
146
147/* Exported symbols */
148
149int sdw_cdns_probe(struct sdw_cdns *cdns);
150extern struct sdw_master_ops sdw_cdns_master_ops;
151
152irqreturn_t sdw_cdns_irq(int irq, void *dev_id);
153irqreturn_t sdw_cdns_thread(int irq, void *dev_id);
154
155int sdw_cdns_init(struct sdw_cdns *cdns);
156int sdw_cdns_pdi_init(struct sdw_cdns *cdns,
157		      struct sdw_cdns_stream_config config);
158int sdw_cdns_exit_reset(struct sdw_cdns *cdns);
159int sdw_cdns_enable_interrupt(struct sdw_cdns *cdns, bool state);
160
161bool sdw_cdns_is_clock_stop(struct sdw_cdns *cdns);
162int sdw_cdns_clock_stop(struct sdw_cdns *cdns, bool block_wake);
163int sdw_cdns_clock_restart(struct sdw_cdns *cdns, bool bus_reset);
164
165#ifdef CONFIG_DEBUG_FS
166void sdw_cdns_debugfs_init(struct sdw_cdns *cdns, struct dentry *root);
167#endif
168
169struct 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);
172void sdw_cdns_config_stream(struct sdw_cdns *cdns,
173			    u32 ch, u32 dir, struct sdw_cdns_pdi *pdi);
174
175enum sdw_command_response
176cdns_reset_page_addr(struct sdw_bus *bus, unsigned int dev_num);
177
178enum sdw_command_response
179cdns_xfer_msg(struct sdw_bus *bus, struct sdw_msg *msg);
180
181enum sdw_command_response
182cdns_xfer_msg_defer(struct sdw_bus *bus,
183		    struct sdw_msg *msg, struct sdw_defer *defer);
184
185u32 cdns_read_ping_status(struct sdw_bus *bus);
 
186
187int cdns_bus_conf(struct sdw_bus *bus, struct sdw_bus_params *params);
188
189int cdns_set_sdw_stream(struct snd_soc_dai *dai,
190			void *stream, int direction);
191
192void sdw_cdns_check_self_clearing_bits(struct sdw_cdns *cdns, const char *string,
193				       bool initial_delay, int reset_iterations);
194
195#endif /* __SDW_CADENCE_H */