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> 892f622bcSBard Liao #include <linux/soundwire/sdw.h> 96cd1d670SBard Liao 1071bb8a1bSVinod Koul /** 114b206d34SRander Wang * struct sdw_intel_stream_params_data: configuration passed during 124b206d34SRander Wang * the @params_stream callback, e.g. for interaction with DSP 134b206d34SRander Wang * firmware. 144b206d34SRander Wang */ 154b206d34SRander Wang struct sdw_intel_stream_params_data { 164b206d34SRander Wang struct snd_pcm_substream *substream; 174b206d34SRander Wang struct snd_soc_dai *dai; 184b206d34SRander Wang struct snd_pcm_hw_params *hw_params; 194b206d34SRander Wang int link_id; 204b206d34SRander Wang int alh_stream_id; 214b206d34SRander Wang }; 224b206d34SRander Wang 234b206d34SRander Wang /** 244b206d34SRander Wang * struct sdw_intel_stream_free_data: configuration passed during 254b206d34SRander Wang * the @free_stream callback, e.g. for interaction with DSP 264b206d34SRander Wang * firmware. 274b206d34SRander Wang */ 284b206d34SRander Wang struct sdw_intel_stream_free_data { 294b206d34SRander Wang struct snd_pcm_substream *substream; 304b206d34SRander Wang struct snd_soc_dai *dai; 314b206d34SRander Wang int link_id; 324b206d34SRander Wang }; 334b206d34SRander Wang 344b206d34SRander Wang /** 35c46302ecSVinod Koul * struct sdw_intel_ops: Intel audio driver callback ops 36c46302ecSVinod Koul * 37c46302ecSVinod Koul */ 38c46302ecSVinod Koul struct sdw_intel_ops { 394b206d34SRander Wang int (*params_stream)(struct device *dev, 404b206d34SRander Wang struct sdw_intel_stream_params_data *params_data); 414b206d34SRander Wang int (*free_stream)(struct device *dev, 424b206d34SRander Wang struct sdw_intel_stream_free_data *free_data); 43c46302ecSVinod Koul }; 44c46302ecSVinod Koul 45c46302ecSVinod Koul /** 46f98f690fSPierre-Louis Bossart * struct sdw_intel_acpi_info - Soundwire Intel information found in ACPI tables 47f98f690fSPierre-Louis Bossart * @handle: ACPI controller handle 48f98f690fSPierre-Louis Bossart * @count: link count found with "sdw-master-count" property 49f98f690fSPierre-Louis Bossart * @link_mask: bit-wise mask listing links enabled by BIOS menu 50f98f690fSPierre-Louis Bossart * 51f98f690fSPierre-Louis Bossart * this structure could be expanded to e.g. provide all the _ADR 52f98f690fSPierre-Louis Bossart * information in case the link_mask is not sufficient to identify 53f98f690fSPierre-Louis Bossart * platform capabilities. 54f98f690fSPierre-Louis Bossart */ 55f98f690fSPierre-Louis Bossart struct sdw_intel_acpi_info { 56f98f690fSPierre-Louis Bossart acpi_handle handle; 57f98f690fSPierre-Louis Bossart int count; 58f98f690fSPierre-Louis Bossart u32 link_mask; 59f98f690fSPierre-Louis Bossart }; 60f98f690fSPierre-Louis Bossart 61*29a269c6SPierre-Louis Bossart struct sdw_intel_link_dev; 62f98f690fSPierre-Louis Bossart 6309f6a72dSPierre-Louis Bossart /* Intel clock-stop/pm_runtime quirk definitions */ 6409f6a72dSPierre-Louis Bossart 6509f6a72dSPierre-Louis Bossart /* 6609f6a72dSPierre-Louis Bossart * Force the clock to remain on during pm_runtime suspend. This might 6709f6a72dSPierre-Louis Bossart * be needed if Slave devices do not have an alternate clock source or 6809f6a72dSPierre-Louis Bossart * if the latency requirements are very strict. 6909f6a72dSPierre-Louis Bossart */ 7009f6a72dSPierre-Louis Bossart #define SDW_INTEL_CLK_STOP_NOT_ALLOWED BIT(0) 7109f6a72dSPierre-Louis Bossart 7209f6a72dSPierre-Louis Bossart /* 7309f6a72dSPierre-Louis Bossart * Stop the bus during pm_runtime suspend. If set, a complete bus 7409f6a72dSPierre-Louis Bossart * reset and re-enumeration will be performed when the bus 7509f6a72dSPierre-Louis Bossart * restarts. This mode shall not be used if Slave devices can generate 7609f6a72dSPierre-Louis Bossart * in-band wakes. 7709f6a72dSPierre-Louis Bossart */ 7809f6a72dSPierre-Louis Bossart #define SDW_INTEL_CLK_STOP_TEARDOWN BIT(1) 7909f6a72dSPierre-Louis Bossart 8009f6a72dSPierre-Louis Bossart /* 8109f6a72dSPierre-Louis Bossart * Stop the bus during pm_suspend if Slaves are not wake capable 8209f6a72dSPierre-Louis Bossart * (e.g. speaker amplifiers). The clock-stop mode is typically 8309f6a72dSPierre-Louis Bossart * slightly higher power than when the IP is completely powered-off. 8409f6a72dSPierre-Louis Bossart */ 8509f6a72dSPierre-Louis Bossart #define SDW_INTEL_CLK_STOP_WAKE_CAPABLE_ONLY BIT(2) 8609f6a72dSPierre-Louis Bossart 8709f6a72dSPierre-Louis Bossart /* 8809f6a72dSPierre-Louis Bossart * Require a bus reset (and complete re-enumeration) when exiting 8909f6a72dSPierre-Louis Bossart * clock stop modes. This may be needed if the controller power was 9009f6a72dSPierre-Louis Bossart * turned off and all context lost. This quirk shall not be used if a 9109f6a72dSPierre-Louis Bossart * Slave device needs to remain enumerated and keep its context, 9209f6a72dSPierre-Louis Bossart * e.g. to provide the reasons for the wake, report acoustic events or 9309f6a72dSPierre-Louis Bossart * pass a history buffer. 9409f6a72dSPierre-Louis Bossart */ 9509f6a72dSPierre-Louis Bossart #define SDW_INTEL_CLK_STOP_BUS_RESET BIT(3) 9609f6a72dSPierre-Louis Bossart 9792f622bcSBard Liao struct sdw_intel_slave_id { 9892f622bcSBard Liao int link_id; 9992f622bcSBard Liao struct sdw_slave_id id; 10092f622bcSBard Liao }; 10192f622bcSBard Liao 102f98f690fSPierre-Louis Bossart /** 103f98f690fSPierre-Louis Bossart * struct sdw_intel_ctx - context allocated by the controller 104f98f690fSPierre-Louis Bossart * driver probe 105f98f690fSPierre-Louis Bossart * @count: link count 106f98f690fSPierre-Louis Bossart * @mmio_base: mmio base of SoundWire registers, only used to check 107f98f690fSPierre-Louis Bossart * hardware capabilities after all power dependencies are settled. 108f98f690fSPierre-Louis Bossart * @link_mask: bit-wise mask listing SoundWire links reported by the 109f98f690fSPierre-Louis Bossart * Controller 11092f622bcSBard Liao * @num_slaves: total number of devices exposed across all enabled links 111f98f690fSPierre-Louis Bossart * @handle: ACPI parent handle 112*29a269c6SPierre-Louis Bossart * @ldev: information for each link (controller-specific and kept 113f98f690fSPierre-Louis Bossart * opaque here) 11492f622bcSBard Liao * @ids: array of slave_id, representing Slaves exposed across all enabled 11592f622bcSBard Liao * links 116eae0b60dSBard Liao * @link_list: list to handle interrupts across all links 1174da0680fSPierre-Louis Bossart * @shim_lock: mutex to handle concurrent rmw access to shared SHIM registers. 1184a17c441SPierre-Louis Bossart * @shim_mask: flags to track initialization of SHIM shared registers 119f98f690fSPierre-Louis Bossart */ 120f98f690fSPierre-Louis Bossart struct sdw_intel_ctx { 121f98f690fSPierre-Louis Bossart int count; 122f98f690fSPierre-Louis Bossart void __iomem *mmio_base; 123f98f690fSPierre-Louis Bossart u32 link_mask; 12492f622bcSBard Liao int num_slaves; 125f98f690fSPierre-Louis Bossart acpi_handle handle; 126*29a269c6SPierre-Louis Bossart struct sdw_intel_link_dev **ldev; 12792f622bcSBard Liao struct sdw_intel_slave_id *ids; 128eae0b60dSBard Liao struct list_head link_list; 1294da0680fSPierre-Louis Bossart struct mutex shim_lock; /* lock for access to shared SHIM registers */ 1304a17c441SPierre-Louis Bossart u32 shim_mask; 131f98f690fSPierre-Louis Bossart }; 132f98f690fSPierre-Louis Bossart 133f98f690fSPierre-Louis Bossart /** 134f98f690fSPierre-Louis Bossart * struct sdw_intel_res - Soundwire Intel global resource structure, 135f98f690fSPierre-Louis Bossart * typically populated by the DSP driver 136f98f690fSPierre-Louis Bossart * 137f98f690fSPierre-Louis Bossart * @count: link count 13871bb8a1bSVinod Koul * @mmio_base: mmio base of SoundWire registers 13971bb8a1bSVinod Koul * @irq: interrupt number 14071bb8a1bSVinod Koul * @handle: ACPI parent handle 14171bb8a1bSVinod Koul * @parent: parent device 142c46302ecSVinod Koul * @ops: callback ops 143f98f690fSPierre-Louis Bossart * @dev: device implementing hwparams and free callbacks 144f98f690fSPierre-Louis Bossart * @link_mask: bit-wise mask listing links selected by the DSP driver 145f98f690fSPierre-Louis Bossart * This mask may be a subset of the one reported by the controller since 146f98f690fSPierre-Louis Bossart * machine-specific quirks are handled in the DSP driver. 14709f6a72dSPierre-Louis Bossart * @clock_stop_quirks: mask array of possible behaviors requested by the 14809f6a72dSPierre-Louis Bossart * DSP driver. The quirks are common for all links for now. 14971bb8a1bSVinod Koul */ 15071bb8a1bSVinod Koul struct sdw_intel_res { 151f98f690fSPierre-Louis Bossart int count; 15271bb8a1bSVinod Koul void __iomem *mmio_base; 15371bb8a1bSVinod Koul int irq; 15471bb8a1bSVinod Koul acpi_handle handle; 15571bb8a1bSVinod Koul struct device *parent; 156c46302ecSVinod Koul const struct sdw_intel_ops *ops; 157f98f690fSPierre-Louis Bossart struct device *dev; 158f98f690fSPierre-Louis Bossart u32 link_mask; 15909f6a72dSPierre-Louis Bossart u32 clock_stop_quirks; 16071bb8a1bSVinod Koul }; 16171bb8a1bSVinod Koul 162f98f690fSPierre-Louis Bossart /* 163f98f690fSPierre-Louis Bossart * On Intel platforms, the SoundWire IP has dependencies on power 164f98f690fSPierre-Louis Bossart * rails shared with the DSP, and the initialization steps are split 165f98f690fSPierre-Louis Bossart * in three. First an ACPI scan to check what the firmware describes 166f98f690fSPierre-Louis Bossart * in DSDT tables, then an allocation step (with no hardware 167f98f690fSPierre-Louis Bossart * configuration but with all the relevant devices created) and last 168f98f690fSPierre-Louis Bossart * the actual hardware configuration. The final stage is a global 169f98f690fSPierre-Louis Bossart * interrupt enable which is controlled by the DSP driver. Splitting 170f98f690fSPierre-Louis Bossart * these phases helps simplify the boot flow and make early decisions 171f98f690fSPierre-Louis Bossart * on e.g. which machine driver to select (I2S mode, HDaudio or 172f98f690fSPierre-Louis Bossart * SoundWire). 173f98f690fSPierre-Louis Bossart */ 174f98f690fSPierre-Louis Bossart int sdw_intel_acpi_scan(acpi_handle *parent_handle, 175f98f690fSPierre-Louis Bossart struct sdw_intel_acpi_info *info); 176f98f690fSPierre-Louis Bossart 177905b5a81SRander Wang void sdw_intel_process_wakeen_event(struct sdw_intel_ctx *ctx); 178905b5a81SRander Wang 179f98f690fSPierre-Louis Bossart struct sdw_intel_ctx * 180f98f690fSPierre-Louis Bossart sdw_intel_probe(struct sdw_intel_res *res); 181f98f690fSPierre-Louis Bossart 182f98f690fSPierre-Louis Bossart int sdw_intel_startup(struct sdw_intel_ctx *ctx); 183f98f690fSPierre-Louis Bossart 184f98f690fSPierre-Louis Bossart void sdw_intel_exit(struct sdw_intel_ctx *ctx); 185f98f690fSPierre-Louis Bossart 186f98f690fSPierre-Louis Bossart void sdw_intel_enable_irq(void __iomem *mmio_base, bool enable); 187d62a7d41SVinod Koul 1886cd1d670SBard Liao irqreturn_t sdw_intel_thread(int irq, void *dev_id); 1896cd1d670SBard Liao 19008c2a4bcSPierre-Louis Bossart #define SDW_INTEL_QUIRK_MASK_BUS_DISABLE BIT(1) 19108c2a4bcSPierre-Louis Bossart 19271bb8a1bSVinod Koul #endif 193