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