1392f1045SVinod Koul /* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
2392f1045SVinod Koul /* Copyright(c) 2015-17 Intel Corporation. */
371bb8a1bSVinod Koul 
471bb8a1bSVinod Koul #ifndef __SDW_INTEL_H
571bb8a1bSVinod Koul #define __SDW_INTEL_H
671bb8a1bSVinod Koul 
76cd1d670SBard Liao #include <linux/irqreturn.h>
86cd1d670SBard Liao 
971bb8a1bSVinod Koul /**
104b206d34SRander Wang  * struct sdw_intel_stream_params_data: configuration passed during
114b206d34SRander Wang  * the @params_stream callback, e.g. for interaction with DSP
124b206d34SRander Wang  * firmware.
134b206d34SRander Wang  */
144b206d34SRander Wang struct sdw_intel_stream_params_data {
154b206d34SRander Wang 	struct snd_pcm_substream *substream;
164b206d34SRander Wang 	struct snd_soc_dai *dai;
174b206d34SRander Wang 	struct snd_pcm_hw_params *hw_params;
184b206d34SRander Wang 	int link_id;
194b206d34SRander Wang 	int alh_stream_id;
204b206d34SRander Wang };
214b206d34SRander Wang 
224b206d34SRander Wang /**
234b206d34SRander Wang  * struct sdw_intel_stream_free_data: configuration passed during
244b206d34SRander Wang  * the @free_stream callback, e.g. for interaction with DSP
254b206d34SRander Wang  * firmware.
264b206d34SRander Wang  */
274b206d34SRander Wang struct sdw_intel_stream_free_data {
284b206d34SRander Wang 	struct snd_pcm_substream *substream;
294b206d34SRander Wang 	struct snd_soc_dai *dai;
304b206d34SRander Wang 	int link_id;
314b206d34SRander Wang };
324b206d34SRander Wang 
334b206d34SRander Wang /**
34c46302ecSVinod Koul  * struct sdw_intel_ops: Intel audio driver callback ops
35c46302ecSVinod Koul  *
36c46302ecSVinod Koul  */
37c46302ecSVinod Koul struct sdw_intel_ops {
384b206d34SRander Wang 	int (*params_stream)(struct device *dev,
394b206d34SRander Wang 			     struct sdw_intel_stream_params_data *params_data);
404b206d34SRander Wang 	int (*free_stream)(struct device *dev,
414b206d34SRander Wang 			   struct sdw_intel_stream_free_data *free_data);
42c46302ecSVinod Koul };
43c46302ecSVinod Koul 
44c46302ecSVinod Koul /**
45f98f690fSPierre-Louis Bossart  * struct sdw_intel_acpi_info - Soundwire Intel information found in ACPI tables
46f98f690fSPierre-Louis Bossart  * @handle: ACPI controller handle
47f98f690fSPierre-Louis Bossart  * @count: link count found with "sdw-master-count" property
48f98f690fSPierre-Louis Bossart  * @link_mask: bit-wise mask listing links enabled by BIOS menu
49f98f690fSPierre-Louis Bossart  *
50f98f690fSPierre-Louis Bossart  * this structure could be expanded to e.g. provide all the _ADR
51f98f690fSPierre-Louis Bossart  * information in case the link_mask is not sufficient to identify
52f98f690fSPierre-Louis Bossart  * platform capabilities.
53f98f690fSPierre-Louis Bossart  */
54f98f690fSPierre-Louis Bossart struct sdw_intel_acpi_info {
55f98f690fSPierre-Louis Bossart 	acpi_handle handle;
56f98f690fSPierre-Louis Bossart 	int count;
57f98f690fSPierre-Louis Bossart 	u32 link_mask;
58f98f690fSPierre-Louis Bossart };
59f98f690fSPierre-Louis Bossart 
60f98f690fSPierre-Louis Bossart struct sdw_intel_link_res;
61f98f690fSPierre-Louis Bossart 
62f98f690fSPierre-Louis Bossart /**
63f98f690fSPierre-Louis Bossart  * struct sdw_intel_ctx - context allocated by the controller
64f98f690fSPierre-Louis Bossart  * driver probe
65f98f690fSPierre-Louis Bossart  * @count: link count
66f98f690fSPierre-Louis Bossart  * @mmio_base: mmio base of SoundWire registers, only used to check
67f98f690fSPierre-Louis Bossart  * hardware capabilities after all power dependencies are settled.
68f98f690fSPierre-Louis Bossart  * @link_mask: bit-wise mask listing SoundWire links reported by the
69f98f690fSPierre-Louis Bossart  * Controller
70f98f690fSPierre-Louis Bossart  * @handle: ACPI parent handle
71f98f690fSPierre-Louis Bossart  * @links: information for each link (controller-specific and kept
72f98f690fSPierre-Louis Bossart  * opaque here)
73eae0b60dSBard Liao  * @link_list: list to handle interrupts across all links
744da0680fSPierre-Louis Bossart  * @shim_lock: mutex to handle concurrent rmw access to shared SHIM registers.
75f98f690fSPierre-Louis Bossart  */
76f98f690fSPierre-Louis Bossart struct sdw_intel_ctx {
77f98f690fSPierre-Louis Bossart 	int count;
78f98f690fSPierre-Louis Bossart 	void __iomem *mmio_base;
79f98f690fSPierre-Louis Bossart 	u32 link_mask;
80f98f690fSPierre-Louis Bossart 	acpi_handle handle;
81f98f690fSPierre-Louis Bossart 	struct sdw_intel_link_res *links;
82eae0b60dSBard Liao 	struct list_head link_list;
834da0680fSPierre-Louis Bossart 	struct mutex shim_lock; /* lock for access to shared SHIM registers */
84f98f690fSPierre-Louis Bossart };
85f98f690fSPierre-Louis Bossart 
86f98f690fSPierre-Louis Bossart /**
87f98f690fSPierre-Louis Bossart  * struct sdw_intel_res - Soundwire Intel global resource structure,
88f98f690fSPierre-Louis Bossart  * typically populated by the DSP driver
89f98f690fSPierre-Louis Bossart  *
90f98f690fSPierre-Louis Bossart  * @count: link count
9171bb8a1bSVinod Koul  * @mmio_base: mmio base of SoundWire registers
9271bb8a1bSVinod Koul  * @irq: interrupt number
9371bb8a1bSVinod Koul  * @handle: ACPI parent handle
9471bb8a1bSVinod Koul  * @parent: parent device
95c46302ecSVinod Koul  * @ops: callback ops
96f98f690fSPierre-Louis Bossart  * @dev: device implementing hwparams and free callbacks
97f98f690fSPierre-Louis Bossart  * @link_mask: bit-wise mask listing links selected by the DSP driver
98f98f690fSPierre-Louis Bossart  * This mask may be a subset of the one reported by the controller since
99f98f690fSPierre-Louis Bossart  * machine-specific quirks are handled in the DSP driver.
10071bb8a1bSVinod Koul  */
10171bb8a1bSVinod Koul struct sdw_intel_res {
102f98f690fSPierre-Louis Bossart 	int count;
10371bb8a1bSVinod Koul 	void __iomem *mmio_base;
10471bb8a1bSVinod Koul 	int irq;
10571bb8a1bSVinod Koul 	acpi_handle handle;
10671bb8a1bSVinod Koul 	struct device *parent;
107c46302ecSVinod Koul 	const struct sdw_intel_ops *ops;
108f98f690fSPierre-Louis Bossart 	struct device *dev;
109f98f690fSPierre-Louis Bossart 	u32 link_mask;
11071bb8a1bSVinod Koul };
11171bb8a1bSVinod Koul 
112f98f690fSPierre-Louis Bossart /*
113f98f690fSPierre-Louis Bossart  * On Intel platforms, the SoundWire IP has dependencies on power
114f98f690fSPierre-Louis Bossart  * rails shared with the DSP, and the initialization steps are split
115f98f690fSPierre-Louis Bossart  * in three. First an ACPI scan to check what the firmware describes
116f98f690fSPierre-Louis Bossart  * in DSDT tables, then an allocation step (with no hardware
117f98f690fSPierre-Louis Bossart  * configuration but with all the relevant devices created) and last
118f98f690fSPierre-Louis Bossart  * the actual hardware configuration. The final stage is a global
119f98f690fSPierre-Louis Bossart  * interrupt enable which is controlled by the DSP driver. Splitting
120f98f690fSPierre-Louis Bossart  * these phases helps simplify the boot flow and make early decisions
121f98f690fSPierre-Louis Bossart  * on e.g. which machine driver to select (I2S mode, HDaudio or
122f98f690fSPierre-Louis Bossart  * SoundWire).
123f98f690fSPierre-Louis Bossart  */
124f98f690fSPierre-Louis Bossart int sdw_intel_acpi_scan(acpi_handle *parent_handle,
125f98f690fSPierre-Louis Bossart 			struct sdw_intel_acpi_info *info);
126f98f690fSPierre-Louis Bossart 
127905b5a81SRander Wang void sdw_intel_process_wakeen_event(struct sdw_intel_ctx *ctx);
128905b5a81SRander Wang 
129f98f690fSPierre-Louis Bossart struct sdw_intel_ctx *
130f98f690fSPierre-Louis Bossart sdw_intel_probe(struct sdw_intel_res *res);
131f98f690fSPierre-Louis Bossart 
132f98f690fSPierre-Louis Bossart int sdw_intel_startup(struct sdw_intel_ctx *ctx);
133f98f690fSPierre-Louis Bossart 
134f98f690fSPierre-Louis Bossart void sdw_intel_exit(struct sdw_intel_ctx *ctx);
135f98f690fSPierre-Louis Bossart 
136f98f690fSPierre-Louis Bossart void sdw_intel_enable_irq(void __iomem *mmio_base, bool enable);
137d62a7d41SVinod Koul 
1386cd1d670SBard Liao irqreturn_t sdw_intel_thread(int irq, void *dev_id);
1396cd1d670SBard Liao 
14071bb8a1bSVinod Koul #endif
141