blob: 6199e71edeab7eabeb2bf12921086b86d10fcc89 [file] [log] [blame]
Pierre-Louis Bossart23859462019-05-01 10:57:25 -05001/* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
2/* Copyright(c) 2015-17 Intel Corporation. */
Vinod Koul5d6b3c82018-04-26 18:38:53 +05303#include <sound/soc.h>
Vinod Koul2f52a512017-12-14 11:19:41 +05304
5#ifndef __SDW_CADENCE_H
6#define __SDW_CADENCE_H
7
8/**
Vinod Koul07abeff2018-04-26 18:38:48 +05309 * struct sdw_cdns_pdi: PDI (Physical Data Interface) instance
10 *
Vinod Koul07abeff2018-04-26 18:38:48 +053011 * @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 */
19struct sdw_cdns_pdi {
Vinod Koul07abeff2018-04-26 18:38:48 +053020 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 Koul07abeff2018-04-26 18:38:48 +053030 * 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 */
43struct 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 */
66struct 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 Koul5d6b3c82018-04-26 18:38:53 +053076 * struct sdw_cdns_dma_data: Cadence DMA data
77 *
78 * @name: SoundWire stream name
Pierre-Louis Bossart57a34792019-09-16 14:23:46 -050079 * @stream: stream runtime
80 * @pdi: PDI used for this dai
Vinod Koul5d6b3c82018-04-26 18:38:53 +053081 * @bus: Bus handle
82 * @stream_type: Stream type
83 * @link_id: Master link id
84 */
85struct sdw_cdns_dma_data {
86 char *name;
87 struct sdw_stream_runtime *stream;
Pierre-Louis Bossart57a34792019-09-16 14:23:46 -050088 struct sdw_cdns_pdi *pdi;
Vinod Koul5d6b3c82018-04-26 18:38:53 +053089 struct sdw_bus *bus;
90 enum sdw_stream_type stream_type;
91 int link_id;
92};
93
94/**
Vinod Koul2f52a512017-12-14 11:19:41 +053095 * struct sdw_cdns - Cadence driver context
96 * @dev: Linux device
97 * @bus: Bus handle
98 * @instance: instance number
Sanyog Kale956baa12017-12-14 11:19:42 +053099 * @response_buf: SoundWire response buffer
100 * @tx_complete: Tx completion
101 * @defer: Defer pointer
Vinod Koul07abeff2018-04-26 18:38:48 +0530102 * @ports: Data ports
103 * @num_ports: Total number of data ports
104 * @pcm: PCM streams
105 * @pdm: PDM streams
Vinod Koul2f52a512017-12-14 11:19:41 +0530106 * @registers: Cadence registers
107 * @link_up: Link status
Sanyog Kale956baa12017-12-14 11:19:42 +0530108 * @msg_count: Messages sent on bus
Vinod Koul2f52a512017-12-14 11:19:41 +0530109 */
110struct sdw_cdns {
111 struct device *dev;
112 struct sdw_bus bus;
113 unsigned int instance;
114
Sanyog Kale956baa12017-12-14 11:19:42 +0530115 u32 response_buf[0x80];
116 struct completion tx_complete;
117 struct sdw_defer *defer;
118
Vinod Koul07abeff2018-04-26 18:38:48 +0530119 struct sdw_cdns_port *ports;
120 int num_ports;
121
122 struct sdw_cdns_streams pcm;
123 struct sdw_cdns_streams pdm;
124
Vinod Koul2f52a512017-12-14 11:19:41 +0530125 void __iomem *registers;
126
127 bool link_up;
Sanyog Kale956baa12017-12-14 11:19:42 +0530128 unsigned int msg_count;
Vinod Koul2f52a512017-12-14 11:19:41 +0530129};
130
131#define bus_to_cdns(_bus) container_of(_bus, struct sdw_cdns, bus)
132
133/* Exported symbols */
134
Sanyog Kale956baa12017-12-14 11:19:42 +0530135int sdw_cdns_probe(struct sdw_cdns *cdns);
136extern struct sdw_master_ops sdw_cdns_master_ops;
137
Vinod Koul2f52a512017-12-14 11:19:41 +0530138irqreturn_t sdw_cdns_irq(int irq, void *dev_id);
139irqreturn_t sdw_cdns_thread(int irq, void *dev_id);
140
141int sdw_cdns_init(struct sdw_cdns *cdns);
Vinod Koul07abeff2018-04-26 18:38:48 +0530142int sdw_cdns_pdi_init(struct sdw_cdns *cdns,
Pierre-Louis Bossart806a11f2019-05-01 10:57:26 -0500143 struct sdw_cdns_stream_config config);
Pierre-Louis Bossart49ea07d2019-10-22 18:54:44 -0500144int sdw_cdns_exit_reset(struct sdw_cdns *cdns);
Sanyog Kale956baa12017-12-14 11:19:42 +0530145int sdw_cdns_enable_interrupt(struct sdw_cdns *cdns);
146
Pierre-Louis Bossartaa850662019-08-21 13:58:19 -0500147#ifdef CONFIG_DEBUG_FS
148void sdw_cdns_debugfs_init(struct sdw_cdns *cdns, struct dentry *root);
149#endif
150
Vinod Koul5d6b3c82018-04-26 18:38:53 +0530151int sdw_cdns_get_stream(struct sdw_cdns *cdns,
152 struct sdw_cdns_streams *stream,
153 u32 ch, u32 dir);
Pierre-Louis Bossart57a34792019-09-16 14:23:46 -0500154struct sdw_cdns_pdi *sdw_cdns_alloc_pdi(struct sdw_cdns *cdns,
155 struct sdw_cdns_streams *stream,
Bard Liao1b53385e2019-09-16 14:23:48 -0500156 u32 ch, u32 dir, int dai_id);
Pierre-Louis Bossart57a34792019-09-16 14:23:46 -0500157void sdw_cdns_config_stream(struct sdw_cdns *cdns,
Pierre-Louis Bossart806a11f2019-05-01 10:57:26 -0500158 u32 ch, u32 dir, struct sdw_cdns_pdi *pdi);
Vinod Koul5d6b3c82018-04-26 18:38:53 +0530159
Vinod Koul5d6b3c82018-04-26 18:38:53 +0530160int sdw_cdns_pcm_set_stream(struct snd_soc_dai *dai,
Pierre-Louis Bossart806a11f2019-05-01 10:57:26 -0500161 void *stream, int direction);
Vinod Koul5d6b3c82018-04-26 18:38:53 +0530162int sdw_cdns_pdm_set_stream(struct snd_soc_dai *dai,
Pierre-Louis Bossart806a11f2019-05-01 10:57:26 -0500163 void *stream, int direction);
Vinod Koul5d6b3c82018-04-26 18:38:53 +0530164
165enum sdw_command_response
166cdns_reset_page_addr(struct sdw_bus *bus, unsigned int dev_num);
167
Shreyas NCc91605f2018-04-26 18:38:43 +0530168enum sdw_command_response
169cdns_xfer_msg(struct sdw_bus *bus, struct sdw_msg *msg);
Vinod Koul2f52a512017-12-14 11:19:41 +0530170
Shreyas NCc91605f2018-04-26 18:38:43 +0530171enum sdw_command_response
172cdns_xfer_msg_defer(struct sdw_bus *bus,
Pierre-Louis Bossart806a11f2019-05-01 10:57:26 -0500173 struct sdw_msg *msg, struct sdw_defer *defer);
Shreyas NCc91605f2018-04-26 18:38:43 +0530174
175enum sdw_command_response
176cdns_reset_page_addr(struct sdw_bus *bus, unsigned int dev_num);
Vinod Koul07abeff2018-04-26 18:38:48 +0530177
178int cdns_bus_conf(struct sdw_bus *bus, struct sdw_bus_params *params);
Vinod Koul5d6b3c82018-04-26 18:38:53 +0530179
180int cdns_set_sdw_stream(struct snd_soc_dai *dai,
Pierre-Louis Bossart806a11f2019-05-01 10:57:26 -0500181 void *stream, bool pcm, int direction);
Vinod Koul2f52a512017-12-14 11:19:41 +0530182#endif /* __SDW_CADENCE_H */