Pierre-Louis Bossart | 2385946 | 2019-05-01 10:57:25 -0500 | [diff] [blame] | 1 | /* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */ |
| 2 | /* Copyright(c) 2015-17 Intel Corporation. */ |
Vinod Koul | 5d6b3c8 | 2018-04-26 18:38:53 +0530 | [diff] [blame] | 3 | #include <sound/soc.h> |
Vinod Koul | 2f52a51 | 2017-12-14 11:19:41 +0530 | [diff] [blame] | 4 | |
| 5 | #ifndef __SDW_CADENCE_H |
| 6 | #define __SDW_CADENCE_H |
| 7 | |
| 8 | /** |
Vinod Koul | 07abeff | 2018-04-26 18:38:48 +0530 | [diff] [blame] | 9 | * struct sdw_cdns_pdi: PDI (Physical Data Interface) instance |
| 10 | * |
Vinod Koul | 07abeff | 2018-04-26 18:38:48 +0530 | [diff] [blame] | 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 | */ |
| 19 | struct sdw_cdns_pdi { |
Vinod Koul | 07abeff | 2018-04-26 18:38:48 +0530 | [diff] [blame] | 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 | /** |
Vinod Koul | 07abeff | 2018-04-26 18:38:48 +0530 | [diff] [blame] | 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 | */ |
| 43 | struct 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 | */ |
| 66 | struct 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 | /** |
Vinod Koul | 5d6b3c8 | 2018-04-26 18:38:53 +0530 | [diff] [blame] | 76 | * struct sdw_cdns_dma_data: Cadence DMA data |
| 77 | * |
| 78 | * @name: SoundWire stream name |
Pierre-Louis Bossart | 57a3479 | 2019-09-16 14:23:46 -0500 | [diff] [blame] | 79 | * @stream: stream runtime |
| 80 | * @pdi: PDI used for this dai |
Vinod Koul | 5d6b3c8 | 2018-04-26 18:38:53 +0530 | [diff] [blame] | 81 | * @bus: Bus handle |
| 82 | * @stream_type: Stream type |
| 83 | * @link_id: Master link id |
| 84 | */ |
| 85 | struct sdw_cdns_dma_data { |
| 86 | char *name; |
| 87 | struct sdw_stream_runtime *stream; |
Pierre-Louis Bossart | 57a3479 | 2019-09-16 14:23:46 -0500 | [diff] [blame] | 88 | struct sdw_cdns_pdi *pdi; |
Vinod Koul | 5d6b3c8 | 2018-04-26 18:38:53 +0530 | [diff] [blame] | 89 | struct sdw_bus *bus; |
| 90 | enum sdw_stream_type stream_type; |
| 91 | int link_id; |
| 92 | }; |
| 93 | |
| 94 | /** |
Vinod Koul | 2f52a51 | 2017-12-14 11:19:41 +0530 | [diff] [blame] | 95 | * struct sdw_cdns - Cadence driver context |
| 96 | * @dev: Linux device |
| 97 | * @bus: Bus handle |
| 98 | * @instance: instance number |
Sanyog Kale | 956baa1 | 2017-12-14 11:19:42 +0530 | [diff] [blame] | 99 | * @response_buf: SoundWire response buffer |
| 100 | * @tx_complete: Tx completion |
| 101 | * @defer: Defer pointer |
Vinod Koul | 07abeff | 2018-04-26 18:38:48 +0530 | [diff] [blame] | 102 | * @ports: Data ports |
| 103 | * @num_ports: Total number of data ports |
| 104 | * @pcm: PCM streams |
| 105 | * @pdm: PDM streams |
Vinod Koul | 2f52a51 | 2017-12-14 11:19:41 +0530 | [diff] [blame] | 106 | * @registers: Cadence registers |
| 107 | * @link_up: Link status |
Sanyog Kale | 956baa1 | 2017-12-14 11:19:42 +0530 | [diff] [blame] | 108 | * @msg_count: Messages sent on bus |
Vinod Koul | 2f52a51 | 2017-12-14 11:19:41 +0530 | [diff] [blame] | 109 | */ |
| 110 | struct sdw_cdns { |
| 111 | struct device *dev; |
| 112 | struct sdw_bus bus; |
| 113 | unsigned int instance; |
| 114 | |
Sanyog Kale | 956baa1 | 2017-12-14 11:19:42 +0530 | [diff] [blame] | 115 | u32 response_buf[0x80]; |
| 116 | struct completion tx_complete; |
| 117 | struct sdw_defer *defer; |
| 118 | |
Vinod Koul | 07abeff | 2018-04-26 18:38:48 +0530 | [diff] [blame] | 119 | struct sdw_cdns_port *ports; |
| 120 | int num_ports; |
| 121 | |
| 122 | struct sdw_cdns_streams pcm; |
| 123 | struct sdw_cdns_streams pdm; |
| 124 | |
Vinod Koul | 2f52a51 | 2017-12-14 11:19:41 +0530 | [diff] [blame] | 125 | void __iomem *registers; |
| 126 | |
| 127 | bool link_up; |
Sanyog Kale | 956baa1 | 2017-12-14 11:19:42 +0530 | [diff] [blame] | 128 | unsigned int msg_count; |
Vinod Koul | 2f52a51 | 2017-12-14 11:19:41 +0530 | [diff] [blame] | 129 | }; |
| 130 | |
| 131 | #define bus_to_cdns(_bus) container_of(_bus, struct sdw_cdns, bus) |
| 132 | |
| 133 | /* Exported symbols */ |
| 134 | |
Sanyog Kale | 956baa1 | 2017-12-14 11:19:42 +0530 | [diff] [blame] | 135 | int sdw_cdns_probe(struct sdw_cdns *cdns); |
| 136 | extern struct sdw_master_ops sdw_cdns_master_ops; |
| 137 | |
Vinod Koul | 2f52a51 | 2017-12-14 11:19:41 +0530 | [diff] [blame] | 138 | irqreturn_t sdw_cdns_irq(int irq, void *dev_id); |
| 139 | irqreturn_t sdw_cdns_thread(int irq, void *dev_id); |
| 140 | |
| 141 | int sdw_cdns_init(struct sdw_cdns *cdns); |
Vinod Koul | 07abeff | 2018-04-26 18:38:48 +0530 | [diff] [blame] | 142 | int sdw_cdns_pdi_init(struct sdw_cdns *cdns, |
Pierre-Louis Bossart | 806a11f | 2019-05-01 10:57:26 -0500 | [diff] [blame] | 143 | struct sdw_cdns_stream_config config); |
Pierre-Louis Bossart | 49ea07d | 2019-10-22 18:54:44 -0500 | [diff] [blame^] | 144 | int sdw_cdns_exit_reset(struct sdw_cdns *cdns); |
Sanyog Kale | 956baa1 | 2017-12-14 11:19:42 +0530 | [diff] [blame] | 145 | int sdw_cdns_enable_interrupt(struct sdw_cdns *cdns); |
| 146 | |
Pierre-Louis Bossart | aa85066 | 2019-08-21 13:58:19 -0500 | [diff] [blame] | 147 | #ifdef CONFIG_DEBUG_FS |
| 148 | void sdw_cdns_debugfs_init(struct sdw_cdns *cdns, struct dentry *root); |
| 149 | #endif |
| 150 | |
Vinod Koul | 5d6b3c8 | 2018-04-26 18:38:53 +0530 | [diff] [blame] | 151 | int sdw_cdns_get_stream(struct sdw_cdns *cdns, |
| 152 | struct sdw_cdns_streams *stream, |
| 153 | u32 ch, u32 dir); |
Pierre-Louis Bossart | 57a3479 | 2019-09-16 14:23:46 -0500 | [diff] [blame] | 154 | struct sdw_cdns_pdi *sdw_cdns_alloc_pdi(struct sdw_cdns *cdns, |
| 155 | struct sdw_cdns_streams *stream, |
Bard Liao | 1b53385e | 2019-09-16 14:23:48 -0500 | [diff] [blame] | 156 | u32 ch, u32 dir, int dai_id); |
Pierre-Louis Bossart | 57a3479 | 2019-09-16 14:23:46 -0500 | [diff] [blame] | 157 | void sdw_cdns_config_stream(struct sdw_cdns *cdns, |
Pierre-Louis Bossart | 806a11f | 2019-05-01 10:57:26 -0500 | [diff] [blame] | 158 | u32 ch, u32 dir, struct sdw_cdns_pdi *pdi); |
Vinod Koul | 5d6b3c8 | 2018-04-26 18:38:53 +0530 | [diff] [blame] | 159 | |
Vinod Koul | 5d6b3c8 | 2018-04-26 18:38:53 +0530 | [diff] [blame] | 160 | int sdw_cdns_pcm_set_stream(struct snd_soc_dai *dai, |
Pierre-Louis Bossart | 806a11f | 2019-05-01 10:57:26 -0500 | [diff] [blame] | 161 | void *stream, int direction); |
Vinod Koul | 5d6b3c8 | 2018-04-26 18:38:53 +0530 | [diff] [blame] | 162 | int sdw_cdns_pdm_set_stream(struct snd_soc_dai *dai, |
Pierre-Louis Bossart | 806a11f | 2019-05-01 10:57:26 -0500 | [diff] [blame] | 163 | void *stream, int direction); |
Vinod Koul | 5d6b3c8 | 2018-04-26 18:38:53 +0530 | [diff] [blame] | 164 | |
| 165 | enum sdw_command_response |
| 166 | cdns_reset_page_addr(struct sdw_bus *bus, unsigned int dev_num); |
| 167 | |
Shreyas NC | c91605f | 2018-04-26 18:38:43 +0530 | [diff] [blame] | 168 | enum sdw_command_response |
| 169 | cdns_xfer_msg(struct sdw_bus *bus, struct sdw_msg *msg); |
Vinod Koul | 2f52a51 | 2017-12-14 11:19:41 +0530 | [diff] [blame] | 170 | |
Shreyas NC | c91605f | 2018-04-26 18:38:43 +0530 | [diff] [blame] | 171 | enum sdw_command_response |
| 172 | cdns_xfer_msg_defer(struct sdw_bus *bus, |
Pierre-Louis Bossart | 806a11f | 2019-05-01 10:57:26 -0500 | [diff] [blame] | 173 | struct sdw_msg *msg, struct sdw_defer *defer); |
Shreyas NC | c91605f | 2018-04-26 18:38:43 +0530 | [diff] [blame] | 174 | |
| 175 | enum sdw_command_response |
| 176 | cdns_reset_page_addr(struct sdw_bus *bus, unsigned int dev_num); |
Vinod Koul | 07abeff | 2018-04-26 18:38:48 +0530 | [diff] [blame] | 177 | |
| 178 | int cdns_bus_conf(struct sdw_bus *bus, struct sdw_bus_params *params); |
Vinod Koul | 5d6b3c8 | 2018-04-26 18:38:53 +0530 | [diff] [blame] | 179 | |
| 180 | int cdns_set_sdw_stream(struct snd_soc_dai *dai, |
Pierre-Louis Bossart | 806a11f | 2019-05-01 10:57:26 -0500 | [diff] [blame] | 181 | void *stream, bool pcm, int direction); |
Vinod Koul | 2f52a51 | 2017-12-14 11:19:41 +0530 | [diff] [blame] | 182 | #endif /* __SDW_CADENCE_H */ |