Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
0002 /* Copyright(c) 2015-17 Intel Corporation. */
0003 #include <sound/soc.h>
0004 
0005 #ifndef __SDW_CADENCE_H
0006 #define __SDW_CADENCE_H
0007 
0008 #define SDW_CADENCE_GSYNC_KHZ       4 /* 4 kHz */
0009 #define SDW_CADENCE_GSYNC_HZ        (SDW_CADENCE_GSYNC_KHZ * 1000)
0010 
0011 /**
0012  * struct sdw_cdns_pdi: PDI (Physical Data Interface) instance
0013  *
0014  * @num: pdi number
0015  * @intel_alh_id: link identifier
0016  * @l_ch_num: low channel for PDI
0017  * @h_ch_num: high channel for PDI
0018  * @ch_count: total channel count for PDI
0019  * @dir: data direction
0020  * @type: stream type, (only PCM supported)
0021  */
0022 struct sdw_cdns_pdi {
0023     int num;
0024     int intel_alh_id;
0025     int l_ch_num;
0026     int h_ch_num;
0027     int ch_count;
0028     enum sdw_data_direction dir;
0029     enum sdw_stream_type type;
0030 };
0031 
0032 /**
0033  * struct sdw_cdns_streams: Cadence stream data structure
0034  *
0035  * @num_bd: number of bidirectional streams
0036  * @num_in: number of input streams
0037  * @num_out: number of output streams
0038  * @num_ch_bd: number of bidirectional stream channels
0039  * @num_ch_bd: number of input stream channels
0040  * @num_ch_bd: number of output stream channels
0041  * @num_pdi: total number of PDIs
0042  * @bd: bidirectional streams
0043  * @in: input streams
0044  * @out: output streams
0045  */
0046 struct sdw_cdns_streams {
0047     unsigned int num_bd;
0048     unsigned int num_in;
0049     unsigned int num_out;
0050     unsigned int num_ch_bd;
0051     unsigned int num_ch_in;
0052     unsigned int num_ch_out;
0053     unsigned int num_pdi;
0054     struct sdw_cdns_pdi *bd;
0055     struct sdw_cdns_pdi *in;
0056     struct sdw_cdns_pdi *out;
0057 };
0058 
0059 /**
0060  * struct sdw_cdns_stream_config: stream configuration
0061  *
0062  * @pcm_bd: number of bidirectional PCM streams supported
0063  * @pcm_in: number of input PCM streams supported
0064  * @pcm_out: number of output PCM streams supported
0065  */
0066 struct sdw_cdns_stream_config {
0067     unsigned int pcm_bd;
0068     unsigned int pcm_in;
0069     unsigned int pcm_out;
0070 };
0071 
0072 /**
0073  * struct sdw_cdns_dma_data: Cadence DMA data
0074  *
0075  * @name: SoundWire stream name
0076  * @stream: stream runtime
0077  * @pdi: PDI used for this dai
0078  * @bus: Bus handle
0079  * @stream_type: Stream type
0080  * @link_id: Master link id
0081  * @hw_params: hw_params to be applied in .prepare step
0082  * @suspended: status set when suspended, to be used in .prepare
0083  * @paused: status set in .trigger, to be used in suspend
0084  */
0085 struct sdw_cdns_dma_data {
0086     char *name;
0087     struct sdw_stream_runtime *stream;
0088     struct sdw_cdns_pdi *pdi;
0089     struct sdw_bus *bus;
0090     enum sdw_stream_type stream_type;
0091     int link_id;
0092     struct snd_pcm_hw_params *hw_params;
0093     bool suspended;
0094     bool paused;
0095 };
0096 
0097 /**
0098  * struct sdw_cdns - Cadence driver context
0099  * @dev: Linux device
0100  * @bus: Bus handle
0101  * @instance: instance number
0102  * @response_buf: SoundWire response buffer
0103  * @tx_complete: Tx completion
0104  * @defer: Defer pointer
0105  * @ports: Data ports
0106  * @num_ports: Total number of data ports
0107  * @pcm: PCM streams
0108  * @registers: Cadence registers
0109  * @link_up: Link status
0110  * @msg_count: Messages sent on bus
0111  */
0112 struct sdw_cdns {
0113     struct device *dev;
0114     struct sdw_bus bus;
0115     unsigned int instance;
0116 
0117     u32 response_buf[0x80];
0118     struct completion tx_complete;
0119     struct sdw_defer *defer;
0120 
0121     struct sdw_cdns_port *ports;
0122     int num_ports;
0123 
0124     struct sdw_cdns_streams pcm;
0125 
0126     int pdi_loopback_source;
0127     int pdi_loopback_target;
0128 
0129     void __iomem *registers;
0130 
0131     bool link_up;
0132     unsigned int msg_count;
0133     bool interrupt_enabled;
0134 
0135     struct work_struct work;
0136 
0137     struct list_head list;
0138 };
0139 
0140 #define bus_to_cdns(_bus) container_of(_bus, struct sdw_cdns, bus)
0141 
0142 /* Exported symbols */
0143 
0144 int sdw_cdns_probe(struct sdw_cdns *cdns);
0145 extern struct sdw_master_ops sdw_cdns_master_ops;
0146 
0147 irqreturn_t sdw_cdns_irq(int irq, void *dev_id);
0148 irqreturn_t sdw_cdns_thread(int irq, void *dev_id);
0149 
0150 int sdw_cdns_init(struct sdw_cdns *cdns);
0151 int sdw_cdns_pdi_init(struct sdw_cdns *cdns,
0152               struct sdw_cdns_stream_config config);
0153 int sdw_cdns_exit_reset(struct sdw_cdns *cdns);
0154 int sdw_cdns_enable_interrupt(struct sdw_cdns *cdns, bool state);
0155 
0156 bool sdw_cdns_is_clock_stop(struct sdw_cdns *cdns);
0157 int sdw_cdns_clock_stop(struct sdw_cdns *cdns, bool block_wake);
0158 int sdw_cdns_clock_restart(struct sdw_cdns *cdns, bool bus_reset);
0159 
0160 #ifdef CONFIG_DEBUG_FS
0161 void sdw_cdns_debugfs_init(struct sdw_cdns *cdns, struct dentry *root);
0162 #endif
0163 
0164 struct sdw_cdns_pdi *sdw_cdns_alloc_pdi(struct sdw_cdns *cdns,
0165                     struct sdw_cdns_streams *stream,
0166                     u32 ch, u32 dir, int dai_id);
0167 void sdw_cdns_config_stream(struct sdw_cdns *cdns,
0168                 u32 ch, u32 dir, struct sdw_cdns_pdi *pdi);
0169 
0170 enum sdw_command_response
0171 cdns_reset_page_addr(struct sdw_bus *bus, unsigned int dev_num);
0172 
0173 enum sdw_command_response
0174 cdns_xfer_msg(struct sdw_bus *bus, struct sdw_msg *msg);
0175 
0176 enum sdw_command_response
0177 cdns_xfer_msg_defer(struct sdw_bus *bus,
0178             struct sdw_msg *msg, struct sdw_defer *defer);
0179 
0180 int cdns_bus_conf(struct sdw_bus *bus, struct sdw_bus_params *params);
0181 
0182 int cdns_set_sdw_stream(struct snd_soc_dai *dai,
0183             void *stream, int direction);
0184 
0185 void sdw_cdns_check_self_clearing_bits(struct sdw_cdns *cdns, const char *string,
0186                        bool initial_delay, int reset_iterations);
0187 
0188 #endif /* __SDW_CADENCE_H */