Linux Audio

Check our new training course

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.8
  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 */
121struct sdw_cdns {
122	struct device *dev;
123	struct sdw_bus bus;
124	unsigned int instance;
125
126	u32 ip_offset;
127
128	/*
129	 * The datasheet says the RX FIFO AVAIL can be 2 entries more
130	 * than the FIFO capacity, so allow for this.
131	 */
132	u32 response_buf[CDNS_MCP_IP_MAX_CMD_LEN + 2];
133
134	struct completion tx_complete;
 
135
136	struct sdw_cdns_port *ports;
137	int num_ports;
138
139	struct sdw_cdns_streams pcm;
140
141	int pdi_loopback_source;
142	int pdi_loopback_target;
143
144	void __iomem *registers;
145
146	bool link_up;
147	unsigned int msg_count;
148	bool interrupt_enabled;
149
150	struct work_struct work;
151
152	struct list_head list;
153
154	struct sdw_cdns_dai_runtime **dai_runtime_array;
155};
156
157#define bus_to_cdns(_bus) container_of(_bus, struct sdw_cdns, bus)
158
159/* Exported symbols */
160
161int sdw_cdns_probe(struct sdw_cdns *cdns);
 
162
163irqreturn_t sdw_cdns_irq(int irq, void *dev_id);
164irqreturn_t sdw_cdns_thread(int irq, void *dev_id);
165
166int sdw_cdns_init(struct sdw_cdns *cdns);
167int sdw_cdns_pdi_init(struct sdw_cdns *cdns,
168		      struct sdw_cdns_stream_config config);
169int sdw_cdns_exit_reset(struct sdw_cdns *cdns);
170int sdw_cdns_enable_interrupt(struct sdw_cdns *cdns, bool state);
171
172bool sdw_cdns_is_clock_stop(struct sdw_cdns *cdns);
173int sdw_cdns_clock_stop(struct sdw_cdns *cdns, bool block_wake);
174int sdw_cdns_clock_restart(struct sdw_cdns *cdns, bool bus_reset);
175
176#ifdef CONFIG_DEBUG_FS
177void sdw_cdns_debugfs_init(struct sdw_cdns *cdns, struct dentry *root);
178#endif
179
180struct sdw_cdns_pdi *sdw_cdns_alloc_pdi(struct sdw_cdns *cdns,
181					struct sdw_cdns_streams *stream,
182					u32 ch, u32 dir, int dai_id);
183void sdw_cdns_config_stream(struct sdw_cdns *cdns,
184			    u32 ch, u32 dir, struct sdw_cdns_pdi *pdi);
185
186enum sdw_command_response
 
 
 
187cdns_xfer_msg(struct sdw_bus *bus, struct sdw_msg *msg);
188
189enum sdw_command_response
190cdns_xfer_msg_defer(struct sdw_bus *bus);
 
191
192u32 cdns_read_ping_status(struct sdw_bus *bus);
 
193
194int cdns_bus_conf(struct sdw_bus *bus, struct sdw_bus_params *params);
195
196int cdns_set_sdw_stream(struct snd_soc_dai *dai,
197			void *stream, int direction);
198
199void sdw_cdns_check_self_clearing_bits(struct sdw_cdns *cdns, const char *string,
200				       bool initial_delay, int reset_iterations);
201
202void sdw_cdns_config_update(struct sdw_cdns *cdns);
203int sdw_cdns_config_update_set_wait(struct sdw_cdns *cdns);
204
205#endif /* __SDW_CADENCE_H */