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 | |
Pierre-Louis Bossart | 1dd6a17 | 2020-03-17 11:33:22 -0500 | [diff] [blame] | 8 | #define SDW_CADENCE_GSYNC_KHZ 4 /* 4 kHz */ |
| 9 | #define SDW_CADENCE_GSYNC_HZ (SDW_CADENCE_GSYNC_KHZ * 1000) |
| 10 | |
Vinod Koul | 2f52a51 | 2017-12-14 11:19:41 +0530 | [diff] [blame] | 11 | /** |
Vinod Koul | 07abeff | 2018-04-26 18:38:48 +0530 | [diff] [blame] | 12 | * struct sdw_cdns_pdi: PDI (Physical Data Interface) instance |
| 13 | * |
Vinod Koul | 07abeff | 2018-04-26 18:38:48 +0530 | [diff] [blame] | 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 |
Pierre-Louis Bossart | 63a6aa9 | 2021-12-24 10:10:34 +0800 | [diff] [blame] | 20 | * @type: stream type, (only PCM supported) |
Vinod Koul | 07abeff | 2018-04-26 18:38:48 +0530 | [diff] [blame] | 21 | */ |
| 22 | struct sdw_cdns_pdi { |
Vinod Koul | 07abeff | 2018-04-26 18:38:48 +0530 | [diff] [blame] | 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 | /** |
Vinod Koul | 07abeff | 2018-04-26 18:38:48 +0530 | [diff] [blame] | 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 | */ |
| 46 | struct 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 |
Vinod Koul | 07abeff | 2018-04-26 18:38:48 +0530 | [diff] [blame] | 65 | */ |
| 66 | struct sdw_cdns_stream_config { |
| 67 | unsigned int pcm_bd; |
| 68 | unsigned int pcm_in; |
| 69 | unsigned int pcm_out; |
Vinod Koul | 07abeff | 2018-04-26 18:38:48 +0530 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | /** |
Vinod Koul | 5d6b3c8 | 2018-04-26 18:38:53 +0530 | [diff] [blame] | 73 | * struct sdw_cdns_dma_data: Cadence DMA data |
| 74 | * |
| 75 | * @name: SoundWire stream name |
Pierre-Louis Bossart | 57a3479 | 2019-09-16 14:23:46 -0500 | [diff] [blame] | 76 | * @stream: stream runtime |
| 77 | * @pdi: PDI used for this dai |
Vinod Koul | 5d6b3c8 | 2018-04-26 18:38:53 +0530 | [diff] [blame] | 78 | * @bus: Bus handle |
| 79 | * @stream_type: Stream type |
| 80 | * @link_id: Master link id |
Bard Liao | a5a0239 | 2020-08-17 23:29:16 +0800 | [diff] [blame] | 81 | * @hw_params: hw_params to be applied in .prepare step |
| 82 | * @suspended: status set when suspended, to be used in .prepare |
Ranjani Sridharan | 8ddeafb | 2021-12-24 10:10:30 +0800 | [diff] [blame] | 83 | * @paused: status set in .trigger, to be used in suspend |
Vinod Koul | 5d6b3c8 | 2018-04-26 18:38:53 +0530 | [diff] [blame] | 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; |
Bard Liao | a5a0239 | 2020-08-17 23:29:16 +0800 | [diff] [blame] | 92 | struct snd_pcm_hw_params *hw_params; |
| 93 | bool suspended; |
Ranjani Sridharan | 8ddeafb | 2021-12-24 10:10:30 +0800 | [diff] [blame] | 94 | bool paused; |
Vinod Koul | 5d6b3c8 | 2018-04-26 18:38:53 +0530 | [diff] [blame] | 95 | }; |
| 96 | |
| 97 | /** |
Vinod Koul | 2f52a51 | 2017-12-14 11:19:41 +0530 | [diff] [blame] | 98 | * struct sdw_cdns - Cadence driver context |
| 99 | * @dev: Linux device |
| 100 | * @bus: Bus handle |
| 101 | * @instance: instance number |
Sanyog Kale | 956baa1 | 2017-12-14 11:19:42 +0530 | [diff] [blame] | 102 | * @response_buf: SoundWire response buffer |
| 103 | * @tx_complete: Tx completion |
| 104 | * @defer: Defer pointer |
Vinod Koul | 07abeff | 2018-04-26 18:38:48 +0530 | [diff] [blame] | 105 | * @ports: Data ports |
| 106 | * @num_ports: Total number of data ports |
| 107 | * @pcm: PCM streams |
Vinod Koul | 2f52a51 | 2017-12-14 11:19:41 +0530 | [diff] [blame] | 108 | * @registers: Cadence registers |
| 109 | * @link_up: Link status |
Sanyog Kale | 956baa1 | 2017-12-14 11:19:42 +0530 | [diff] [blame] | 110 | * @msg_count: Messages sent on bus |
Vinod Koul | 2f52a51 | 2017-12-14 11:19:41 +0530 | [diff] [blame] | 111 | */ |
| 112 | struct sdw_cdns { |
| 113 | struct device *dev; |
| 114 | struct sdw_bus bus; |
| 115 | unsigned int instance; |
| 116 | |
Sanyog Kale | 956baa1 | 2017-12-14 11:19:42 +0530 | [diff] [blame] | 117 | u32 response_buf[0x80]; |
| 118 | struct completion tx_complete; |
| 119 | struct sdw_defer *defer; |
| 120 | |
Vinod Koul | 07abeff | 2018-04-26 18:38:48 +0530 | [diff] [blame] | 121 | struct sdw_cdns_port *ports; |
| 122 | int num_ports; |
| 123 | |
| 124 | struct sdw_cdns_streams pcm; |
Vinod Koul | 07abeff | 2018-04-26 18:38:48 +0530 | [diff] [blame] | 125 | |
Pierre-Louis Bossart | 8fba8ac | 2021-07-14 11:22:08 +0800 | [diff] [blame] | 126 | int pdi_loopback_source; |
| 127 | int pdi_loopback_target; |
| 128 | |
Vinod Koul | 2f52a51 | 2017-12-14 11:19:41 +0530 | [diff] [blame] | 129 | void __iomem *registers; |
| 130 | |
| 131 | bool link_up; |
Sanyog Kale | 956baa1 | 2017-12-14 11:19:42 +0530 | [diff] [blame] | 132 | unsigned int msg_count; |
Pierre-Louis Bossart | d2068da | 2020-08-18 06:23:40 +0800 | [diff] [blame] | 133 | bool interrupt_enabled; |
Bard Liao | 4a98a6b | 2020-07-16 23:09:45 +0800 | [diff] [blame] | 134 | |
| 135 | struct work_struct work; |
| 136 | |
| 137 | struct list_head list; |
Vinod Koul | 2f52a51 | 2017-12-14 11:19:41 +0530 | [diff] [blame] | 138 | }; |
| 139 | |
| 140 | #define bus_to_cdns(_bus) container_of(_bus, struct sdw_cdns, bus) |
| 141 | |
| 142 | /* Exported symbols */ |
| 143 | |
Sanyog Kale | 956baa1 | 2017-12-14 11:19:42 +0530 | [diff] [blame] | 144 | int sdw_cdns_probe(struct sdw_cdns *cdns); |
| 145 | extern struct sdw_master_ops sdw_cdns_master_ops; |
| 146 | |
Vinod Koul | 2f52a51 | 2017-12-14 11:19:41 +0530 | [diff] [blame] | 147 | irqreturn_t sdw_cdns_irq(int irq, void *dev_id); |
| 148 | irqreturn_t sdw_cdns_thread(int irq, void *dev_id); |
| 149 | |
Rander Wang | 7b174f2 | 2020-03-17 11:33:14 -0500 | [diff] [blame] | 150 | int sdw_cdns_init(struct sdw_cdns *cdns); |
Vinod Koul | 07abeff | 2018-04-26 18:38:48 +0530 | [diff] [blame] | 151 | int sdw_cdns_pdi_init(struct sdw_cdns *cdns, |
Pierre-Louis Bossart | 806a11f | 2019-05-01 10:57:26 -0500 | [diff] [blame] | 152 | struct sdw_cdns_stream_config config); |
Pierre-Louis Bossart | 49ea07d | 2019-10-22 18:54:44 -0500 | [diff] [blame] | 153 | int sdw_cdns_exit_reset(struct sdw_cdns *cdns); |
Pierre-Louis Bossart | 9e3d47f | 2019-10-22 18:54:47 -0500 | [diff] [blame] | 154 | int sdw_cdns_enable_interrupt(struct sdw_cdns *cdns, bool state); |
Sanyog Kale | 956baa1 | 2017-12-14 11:19:42 +0530 | [diff] [blame] | 155 | |
Rander Wang | 5a885c5 | 2020-03-17 11:33:15 -0500 | [diff] [blame] | 156 | bool sdw_cdns_is_clock_stop(struct sdw_cdns *cdns); |
Rander Wang | 1032504 | 2020-03-17 11:33:17 -0500 | [diff] [blame] | 157 | int sdw_cdns_clock_stop(struct sdw_cdns *cdns, bool block_wake); |
| 158 | int sdw_cdns_clock_restart(struct sdw_cdns *cdns, bool bus_reset); |
Rander Wang | 5a885c5 | 2020-03-17 11:33:15 -0500 | [diff] [blame] | 159 | |
Pierre-Louis Bossart | aa85066 | 2019-08-21 13:58:19 -0500 | [diff] [blame] | 160 | #ifdef CONFIG_DEBUG_FS |
| 161 | void sdw_cdns_debugfs_init(struct sdw_cdns *cdns, struct dentry *root); |
| 162 | #endif |
| 163 | |
Pierre-Louis Bossart | 57a3479 | 2019-09-16 14:23:46 -0500 | [diff] [blame] | 164 | struct sdw_cdns_pdi *sdw_cdns_alloc_pdi(struct sdw_cdns *cdns, |
| 165 | struct sdw_cdns_streams *stream, |
Bard Liao | 1b53385e | 2019-09-16 14:23:48 -0500 | [diff] [blame] | 166 | u32 ch, u32 dir, int dai_id); |
Pierre-Louis Bossart | 57a3479 | 2019-09-16 14:23:46 -0500 | [diff] [blame] | 167 | void sdw_cdns_config_stream(struct sdw_cdns *cdns, |
Pierre-Louis Bossart | 806a11f | 2019-05-01 10:57:26 -0500 | [diff] [blame] | 168 | u32 ch, u32 dir, struct sdw_cdns_pdi *pdi); |
Vinod Koul | 5d6b3c8 | 2018-04-26 18:38:53 +0530 | [diff] [blame] | 169 | |
Vinod Koul | 5d6b3c8 | 2018-04-26 18:38:53 +0530 | [diff] [blame] | 170 | enum sdw_command_response |
| 171 | cdns_reset_page_addr(struct sdw_bus *bus, unsigned int dev_num); |
| 172 | |
Shreyas NC | c91605f | 2018-04-26 18:38:43 +0530 | [diff] [blame] | 173 | enum sdw_command_response |
| 174 | cdns_xfer_msg(struct sdw_bus *bus, struct sdw_msg *msg); |
Vinod Koul | 2f52a51 | 2017-12-14 11:19:41 +0530 | [diff] [blame] | 175 | |
Shreyas NC | c91605f | 2018-04-26 18:38:43 +0530 | [diff] [blame] | 176 | enum sdw_command_response |
| 177 | cdns_xfer_msg_defer(struct sdw_bus *bus, |
Pierre-Louis Bossart | 806a11f | 2019-05-01 10:57:26 -0500 | [diff] [blame] | 178 | struct sdw_msg *msg, struct sdw_defer *defer); |
Shreyas NC | c91605f | 2018-04-26 18:38:43 +0530 | [diff] [blame] | 179 | |
Vinod Koul | 07abeff | 2018-04-26 18:38:48 +0530 | [diff] [blame] | 180 | 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] | 181 | |
| 182 | int cdns_set_sdw_stream(struct snd_soc_dai *dai, |
Pierre-Louis Bossart | 63a6aa9 | 2021-12-24 10:10:34 +0800 | [diff] [blame] | 183 | void *stream, int direction); |
Pierre-Louis Bossart | ff56094 | 2021-07-14 13:13:49 +0800 | [diff] [blame] | 184 | |
| 185 | void sdw_cdns_check_self_clearing_bits(struct sdw_cdns *cdns, const char *string, |
| 186 | bool initial_delay, int reset_iterations); |
| 187 | |
Vinod Koul | 2f52a51 | 2017-12-14 11:19:41 +0530 | [diff] [blame] | 188 | #endif /* __SDW_CADENCE_H */ |