blob: b54c161a837fa8527b74c54e07e5fc4872223762 [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
Pierre-Louis Bossart1dd6a172020-03-17 11:33:22 -05008#define SDW_CADENCE_GSYNC_KHZ 4 /* 4 kHz */
9#define SDW_CADENCE_GSYNC_HZ (SDW_CADENCE_GSYNC_KHZ * 1000)
10
Vinod Koul2f52a512017-12-14 11:19:41 +053011/**
Vinod Koul07abeff2018-04-26 18:38:48 +053012 * struct sdw_cdns_pdi: PDI (Physical Data Interface) instance
13 *
Vinod Koul07abeff2018-04-26 18:38:48 +053014 * @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
20 * @type: stream type, PDM or PCM
21 */
22struct sdw_cdns_pdi {
Vinod Koul07abeff2018-04-26 18:38:48 +053023 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 Koul07abeff2018-04-26 18:38:48 +053033 * 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 */
46struct 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
65 * @pdm_bd: number of bidirectional PDM streams supported
66 * @pdm_in: number of input PDM streams supported
67 * @pdm_out: number of output PDM streams supported
68 */
69struct sdw_cdns_stream_config {
70 unsigned int pcm_bd;
71 unsigned int pcm_in;
72 unsigned int pcm_out;
73 unsigned int pdm_bd;
74 unsigned int pdm_in;
75 unsigned int pdm_out;
76};
77
78/**
Vinod Koul5d6b3c82018-04-26 18:38:53 +053079 * struct sdw_cdns_dma_data: Cadence DMA data
80 *
81 * @name: SoundWire stream name
Pierre-Louis Bossart57a34792019-09-16 14:23:46 -050082 * @stream: stream runtime
83 * @pdi: PDI used for this dai
Vinod Koul5d6b3c82018-04-26 18:38:53 +053084 * @bus: Bus handle
85 * @stream_type: Stream type
86 * @link_id: Master link id
Bard Liaoa5a02392020-08-17 23:29:16 +080087 * @hw_params: hw_params to be applied in .prepare step
88 * @suspended: status set when suspended, to be used in .prepare
Vinod Koul5d6b3c82018-04-26 18:38:53 +053089 */
90struct sdw_cdns_dma_data {
91 char *name;
92 struct sdw_stream_runtime *stream;
Pierre-Louis Bossart57a34792019-09-16 14:23:46 -050093 struct sdw_cdns_pdi *pdi;
Vinod Koul5d6b3c82018-04-26 18:38:53 +053094 struct sdw_bus *bus;
95 enum sdw_stream_type stream_type;
96 int link_id;
Bard Liaoa5a02392020-08-17 23:29:16 +080097 struct snd_pcm_hw_params *hw_params;
98 bool suspended;
Vinod Koul5d6b3c82018-04-26 18:38:53 +053099};
100
101/**
Vinod Koul2f52a512017-12-14 11:19:41 +0530102 * struct sdw_cdns - Cadence driver context
103 * @dev: Linux device
104 * @bus: Bus handle
105 * @instance: instance number
Sanyog Kale956baa12017-12-14 11:19:42 +0530106 * @response_buf: SoundWire response buffer
107 * @tx_complete: Tx completion
108 * @defer: Defer pointer
Vinod Koul07abeff2018-04-26 18:38:48 +0530109 * @ports: Data ports
110 * @num_ports: Total number of data ports
111 * @pcm: PCM streams
112 * @pdm: PDM streams
Vinod Koul2f52a512017-12-14 11:19:41 +0530113 * @registers: Cadence registers
114 * @link_up: Link status
Sanyog Kale956baa12017-12-14 11:19:42 +0530115 * @msg_count: Messages sent on bus
Vinod Koul2f52a512017-12-14 11:19:41 +0530116 */
117struct sdw_cdns {
118 struct device *dev;
119 struct sdw_bus bus;
120 unsigned int instance;
121
Sanyog Kale956baa12017-12-14 11:19:42 +0530122 u32 response_buf[0x80];
123 struct completion tx_complete;
124 struct sdw_defer *defer;
125
Vinod Koul07abeff2018-04-26 18:38:48 +0530126 struct sdw_cdns_port *ports;
127 int num_ports;
128
129 struct sdw_cdns_streams pcm;
130 struct sdw_cdns_streams pdm;
131
Vinod Koul2f52a512017-12-14 11:19:41 +0530132 void __iomem *registers;
133
134 bool link_up;
Sanyog Kale956baa12017-12-14 11:19:42 +0530135 unsigned int msg_count;
Pierre-Louis Bossartd2068da2020-08-18 06:23:40 +0800136 bool interrupt_enabled;
Bard Liao4a98a6b2020-07-16 23:09:45 +0800137
138 struct work_struct work;
139
140 struct list_head list;
Vinod Koul2f52a512017-12-14 11:19:41 +0530141};
142
143#define bus_to_cdns(_bus) container_of(_bus, struct sdw_cdns, bus)
144
145/* Exported symbols */
146
Sanyog Kale956baa12017-12-14 11:19:42 +0530147int sdw_cdns_probe(struct sdw_cdns *cdns);
148extern struct sdw_master_ops sdw_cdns_master_ops;
149
Vinod Koul2f52a512017-12-14 11:19:41 +0530150irqreturn_t sdw_cdns_irq(int irq, void *dev_id);
151irqreturn_t sdw_cdns_thread(int irq, void *dev_id);
152
Rander Wang7b174f22020-03-17 11:33:14 -0500153int sdw_cdns_init(struct sdw_cdns *cdns);
Vinod Koul07abeff2018-04-26 18:38:48 +0530154int sdw_cdns_pdi_init(struct sdw_cdns *cdns,
Pierre-Louis Bossart806a11f2019-05-01 10:57:26 -0500155 struct sdw_cdns_stream_config config);
Pierre-Louis Bossart49ea07d2019-10-22 18:54:44 -0500156int sdw_cdns_exit_reset(struct sdw_cdns *cdns);
Pierre-Louis Bossart9e3d47f2019-10-22 18:54:47 -0500157int sdw_cdns_enable_interrupt(struct sdw_cdns *cdns, bool state);
Sanyog Kale956baa12017-12-14 11:19:42 +0530158
Rander Wang5a885c52020-03-17 11:33:15 -0500159bool sdw_cdns_is_clock_stop(struct sdw_cdns *cdns);
Rander Wang10325042020-03-17 11:33:17 -0500160int sdw_cdns_clock_stop(struct sdw_cdns *cdns, bool block_wake);
161int sdw_cdns_clock_restart(struct sdw_cdns *cdns, bool bus_reset);
Rander Wang5a885c52020-03-17 11:33:15 -0500162
Pierre-Louis Bossartaa850662019-08-21 13:58:19 -0500163#ifdef CONFIG_DEBUG_FS
164void sdw_cdns_debugfs_init(struct sdw_cdns *cdns, struct dentry *root);
165#endif
166
Pierre-Louis Bossart57a34792019-09-16 14:23:46 -0500167struct sdw_cdns_pdi *sdw_cdns_alloc_pdi(struct sdw_cdns *cdns,
168 struct sdw_cdns_streams *stream,
Bard Liao1b53385e2019-09-16 14:23:48 -0500169 u32 ch, u32 dir, int dai_id);
Pierre-Louis Bossart57a34792019-09-16 14:23:46 -0500170void sdw_cdns_config_stream(struct sdw_cdns *cdns,
Pierre-Louis Bossart806a11f2019-05-01 10:57:26 -0500171 u32 ch, u32 dir, struct sdw_cdns_pdi *pdi);
Vinod Koul5d6b3c82018-04-26 18:38:53 +0530172
Vinod Koul5d6b3c82018-04-26 18:38:53 +0530173enum sdw_command_response
174cdns_reset_page_addr(struct sdw_bus *bus, unsigned int dev_num);
175
Shreyas NCc91605f2018-04-26 18:38:43 +0530176enum sdw_command_response
177cdns_xfer_msg(struct sdw_bus *bus, struct sdw_msg *msg);
Vinod Koul2f52a512017-12-14 11:19:41 +0530178
Shreyas NCc91605f2018-04-26 18:38:43 +0530179enum sdw_command_response
180cdns_xfer_msg_defer(struct sdw_bus *bus,
Pierre-Louis Bossart806a11f2019-05-01 10:57:26 -0500181 struct sdw_msg *msg, struct sdw_defer *defer);
Shreyas NCc91605f2018-04-26 18:38:43 +0530182
Vinod Koul07abeff2018-04-26 18:38:48 +0530183int cdns_bus_conf(struct sdw_bus *bus, struct sdw_bus_params *params);
Vinod Koul5d6b3c82018-04-26 18:38:53 +0530184
185int cdns_set_sdw_stream(struct snd_soc_dai *dai,
Pierre-Louis Bossart806a11f2019-05-01 10:57:26 -0500186 void *stream, bool pcm, int direction);
Pierre-Louis Bossartff560942021-07-14 13:13:49 +0800187
188void sdw_cdns_check_self_clearing_bits(struct sdw_cdns *cdns, const char *string,
189 bool initial_delay, int reset_iterations);
190
Vinod Koul2f52a512017-12-14 11:19:41 +0530191#endif /* __SDW_CADENCE_H */