xref: /OK3568_Linux_fs/kernel/include/linux/soundwire/sdw_intel.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
2*4882a593Smuzhiyun /* Copyright(c) 2015-17 Intel Corporation. */
3*4882a593Smuzhiyun 
4*4882a593Smuzhiyun #ifndef __SDW_INTEL_H
5*4882a593Smuzhiyun #define __SDW_INTEL_H
6*4882a593Smuzhiyun 
7*4882a593Smuzhiyun #include <linux/irqreturn.h>
8*4882a593Smuzhiyun #include <linux/soundwire/sdw.h>
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun /**
11*4882a593Smuzhiyun  * struct sdw_intel_stream_params_data: configuration passed during
12*4882a593Smuzhiyun  * the @params_stream callback, e.g. for interaction with DSP
13*4882a593Smuzhiyun  * firmware.
14*4882a593Smuzhiyun  */
15*4882a593Smuzhiyun struct sdw_intel_stream_params_data {
16*4882a593Smuzhiyun 	struct snd_pcm_substream *substream;
17*4882a593Smuzhiyun 	struct snd_soc_dai *dai;
18*4882a593Smuzhiyun 	struct snd_pcm_hw_params *hw_params;
19*4882a593Smuzhiyun 	int link_id;
20*4882a593Smuzhiyun 	int alh_stream_id;
21*4882a593Smuzhiyun };
22*4882a593Smuzhiyun 
23*4882a593Smuzhiyun /**
24*4882a593Smuzhiyun  * struct sdw_intel_stream_free_data: configuration passed during
25*4882a593Smuzhiyun  * the @free_stream callback, e.g. for interaction with DSP
26*4882a593Smuzhiyun  * firmware.
27*4882a593Smuzhiyun  */
28*4882a593Smuzhiyun struct sdw_intel_stream_free_data {
29*4882a593Smuzhiyun 	struct snd_pcm_substream *substream;
30*4882a593Smuzhiyun 	struct snd_soc_dai *dai;
31*4882a593Smuzhiyun 	int link_id;
32*4882a593Smuzhiyun };
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun /**
35*4882a593Smuzhiyun  * struct sdw_intel_ops: Intel audio driver callback ops
36*4882a593Smuzhiyun  *
37*4882a593Smuzhiyun  */
38*4882a593Smuzhiyun struct sdw_intel_ops {
39*4882a593Smuzhiyun 	int (*params_stream)(struct device *dev,
40*4882a593Smuzhiyun 			     struct sdw_intel_stream_params_data *params_data);
41*4882a593Smuzhiyun 	int (*free_stream)(struct device *dev,
42*4882a593Smuzhiyun 			   struct sdw_intel_stream_free_data *free_data);
43*4882a593Smuzhiyun };
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun /**
46*4882a593Smuzhiyun  * struct sdw_intel_acpi_info - Soundwire Intel information found in ACPI tables
47*4882a593Smuzhiyun  * @handle: ACPI controller handle
48*4882a593Smuzhiyun  * @count: link count found with "sdw-master-count" property
49*4882a593Smuzhiyun  * @link_mask: bit-wise mask listing links enabled by BIOS menu
50*4882a593Smuzhiyun  *
51*4882a593Smuzhiyun  * this structure could be expanded to e.g. provide all the _ADR
52*4882a593Smuzhiyun  * information in case the link_mask is not sufficient to identify
53*4882a593Smuzhiyun  * platform capabilities.
54*4882a593Smuzhiyun  */
55*4882a593Smuzhiyun struct sdw_intel_acpi_info {
56*4882a593Smuzhiyun 	acpi_handle handle;
57*4882a593Smuzhiyun 	int count;
58*4882a593Smuzhiyun 	u32 link_mask;
59*4882a593Smuzhiyun };
60*4882a593Smuzhiyun 
61*4882a593Smuzhiyun struct sdw_intel_link_res;
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun /* Intel clock-stop/pm_runtime quirk definitions */
64*4882a593Smuzhiyun 
65*4882a593Smuzhiyun /*
66*4882a593Smuzhiyun  * Force the clock to remain on during pm_runtime suspend. This might
67*4882a593Smuzhiyun  * be needed if Slave devices do not have an alternate clock source or
68*4882a593Smuzhiyun  * if the latency requirements are very strict.
69*4882a593Smuzhiyun  */
70*4882a593Smuzhiyun #define SDW_INTEL_CLK_STOP_NOT_ALLOWED		BIT(0)
71*4882a593Smuzhiyun 
72*4882a593Smuzhiyun /*
73*4882a593Smuzhiyun  * Stop the bus during pm_runtime suspend. If set, a complete bus
74*4882a593Smuzhiyun  * reset and re-enumeration will be performed when the bus
75*4882a593Smuzhiyun  * restarts. This mode shall not be used if Slave devices can generate
76*4882a593Smuzhiyun  * in-band wakes.
77*4882a593Smuzhiyun  */
78*4882a593Smuzhiyun #define SDW_INTEL_CLK_STOP_TEARDOWN		BIT(1)
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun /*
81*4882a593Smuzhiyun  * Stop the bus during pm_suspend if Slaves are not wake capable
82*4882a593Smuzhiyun  * (e.g. speaker amplifiers). The clock-stop mode is typically
83*4882a593Smuzhiyun  * slightly higher power than when the IP is completely powered-off.
84*4882a593Smuzhiyun  */
85*4882a593Smuzhiyun #define SDW_INTEL_CLK_STOP_WAKE_CAPABLE_ONLY	BIT(2)
86*4882a593Smuzhiyun 
87*4882a593Smuzhiyun /*
88*4882a593Smuzhiyun  * Require a bus reset (and complete re-enumeration) when exiting
89*4882a593Smuzhiyun  * clock stop modes. This may be needed if the controller power was
90*4882a593Smuzhiyun  * turned off and all context lost. This quirk shall not be used if a
91*4882a593Smuzhiyun  * Slave device needs to remain enumerated and keep its context,
92*4882a593Smuzhiyun  * e.g. to provide the reasons for the wake, report acoustic events or
93*4882a593Smuzhiyun  * pass a history buffer.
94*4882a593Smuzhiyun  */
95*4882a593Smuzhiyun #define SDW_INTEL_CLK_STOP_BUS_RESET		BIT(3)
96*4882a593Smuzhiyun 
97*4882a593Smuzhiyun struct sdw_intel_slave_id {
98*4882a593Smuzhiyun 	int link_id;
99*4882a593Smuzhiyun 	struct sdw_slave_id id;
100*4882a593Smuzhiyun };
101*4882a593Smuzhiyun 
102*4882a593Smuzhiyun /**
103*4882a593Smuzhiyun  * struct sdw_intel_ctx - context allocated by the controller
104*4882a593Smuzhiyun  * driver probe
105*4882a593Smuzhiyun  * @count: link count
106*4882a593Smuzhiyun  * @mmio_base: mmio base of SoundWire registers, only used to check
107*4882a593Smuzhiyun  * hardware capabilities after all power dependencies are settled.
108*4882a593Smuzhiyun  * @link_mask: bit-wise mask listing SoundWire links reported by the
109*4882a593Smuzhiyun  * Controller
110*4882a593Smuzhiyun  * @num_slaves: total number of devices exposed across all enabled links
111*4882a593Smuzhiyun  * @handle: ACPI parent handle
112*4882a593Smuzhiyun  * @links: information for each link (controller-specific and kept
113*4882a593Smuzhiyun  * opaque here)
114*4882a593Smuzhiyun  * @ids: array of slave_id, representing Slaves exposed across all enabled
115*4882a593Smuzhiyun  * links
116*4882a593Smuzhiyun  * @link_list: list to handle interrupts across all links
117*4882a593Smuzhiyun  * @shim_lock: mutex to handle concurrent rmw access to shared SHIM registers.
118*4882a593Smuzhiyun  * @shim_mask: flags to track initialization of SHIM shared registers
119*4882a593Smuzhiyun  */
120*4882a593Smuzhiyun struct sdw_intel_ctx {
121*4882a593Smuzhiyun 	int count;
122*4882a593Smuzhiyun 	void __iomem *mmio_base;
123*4882a593Smuzhiyun 	u32 link_mask;
124*4882a593Smuzhiyun 	int num_slaves;
125*4882a593Smuzhiyun 	acpi_handle handle;
126*4882a593Smuzhiyun 	struct sdw_intel_link_res *links;
127*4882a593Smuzhiyun 	struct sdw_intel_slave_id *ids;
128*4882a593Smuzhiyun 	struct list_head link_list;
129*4882a593Smuzhiyun 	struct mutex shim_lock; /* lock for access to shared SHIM registers */
130*4882a593Smuzhiyun 	u32 shim_mask;
131*4882a593Smuzhiyun };
132*4882a593Smuzhiyun 
133*4882a593Smuzhiyun /**
134*4882a593Smuzhiyun  * struct sdw_intel_res - Soundwire Intel global resource structure,
135*4882a593Smuzhiyun  * typically populated by the DSP driver
136*4882a593Smuzhiyun  *
137*4882a593Smuzhiyun  * @count: link count
138*4882a593Smuzhiyun  * @mmio_base: mmio base of SoundWire registers
139*4882a593Smuzhiyun  * @irq: interrupt number
140*4882a593Smuzhiyun  * @handle: ACPI parent handle
141*4882a593Smuzhiyun  * @parent: parent device
142*4882a593Smuzhiyun  * @ops: callback ops
143*4882a593Smuzhiyun  * @dev: device implementing hwparams and free callbacks
144*4882a593Smuzhiyun  * @link_mask: bit-wise mask listing links selected by the DSP driver
145*4882a593Smuzhiyun  * This mask may be a subset of the one reported by the controller since
146*4882a593Smuzhiyun  * machine-specific quirks are handled in the DSP driver.
147*4882a593Smuzhiyun  * @clock_stop_quirks: mask array of possible behaviors requested by the
148*4882a593Smuzhiyun  * DSP driver. The quirks are common for all links for now.
149*4882a593Smuzhiyun  */
150*4882a593Smuzhiyun struct sdw_intel_res {
151*4882a593Smuzhiyun 	int count;
152*4882a593Smuzhiyun 	void __iomem *mmio_base;
153*4882a593Smuzhiyun 	int irq;
154*4882a593Smuzhiyun 	acpi_handle handle;
155*4882a593Smuzhiyun 	struct device *parent;
156*4882a593Smuzhiyun 	const struct sdw_intel_ops *ops;
157*4882a593Smuzhiyun 	struct device *dev;
158*4882a593Smuzhiyun 	u32 link_mask;
159*4882a593Smuzhiyun 	u32 clock_stop_quirks;
160*4882a593Smuzhiyun };
161*4882a593Smuzhiyun 
162*4882a593Smuzhiyun /*
163*4882a593Smuzhiyun  * On Intel platforms, the SoundWire IP has dependencies on power
164*4882a593Smuzhiyun  * rails shared with the DSP, and the initialization steps are split
165*4882a593Smuzhiyun  * in three. First an ACPI scan to check what the firmware describes
166*4882a593Smuzhiyun  * in DSDT tables, then an allocation step (with no hardware
167*4882a593Smuzhiyun  * configuration but with all the relevant devices created) and last
168*4882a593Smuzhiyun  * the actual hardware configuration. The final stage is a global
169*4882a593Smuzhiyun  * interrupt enable which is controlled by the DSP driver. Splitting
170*4882a593Smuzhiyun  * these phases helps simplify the boot flow and make early decisions
171*4882a593Smuzhiyun  * on e.g. which machine driver to select (I2S mode, HDaudio or
172*4882a593Smuzhiyun  * SoundWire).
173*4882a593Smuzhiyun  */
174*4882a593Smuzhiyun int sdw_intel_acpi_scan(acpi_handle *parent_handle,
175*4882a593Smuzhiyun 			struct sdw_intel_acpi_info *info);
176*4882a593Smuzhiyun 
177*4882a593Smuzhiyun void sdw_intel_process_wakeen_event(struct sdw_intel_ctx *ctx);
178*4882a593Smuzhiyun 
179*4882a593Smuzhiyun struct sdw_intel_ctx *
180*4882a593Smuzhiyun sdw_intel_probe(struct sdw_intel_res *res);
181*4882a593Smuzhiyun 
182*4882a593Smuzhiyun int sdw_intel_startup(struct sdw_intel_ctx *ctx);
183*4882a593Smuzhiyun 
184*4882a593Smuzhiyun void sdw_intel_exit(struct sdw_intel_ctx *ctx);
185*4882a593Smuzhiyun 
186*4882a593Smuzhiyun void sdw_intel_enable_irq(void __iomem *mmio_base, bool enable);
187*4882a593Smuzhiyun 
188*4882a593Smuzhiyun irqreturn_t sdw_intel_thread(int irq, void *dev_id);
189*4882a593Smuzhiyun 
190*4882a593Smuzhiyun #endif
191