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 10f0163958SBard Liao #define SDW_SHIM_BASE 0x2C000 11f0163958SBard Liao #define SDW_ALH_BASE 0x2C800 12f0163958SBard Liao #define SDW_LINK_BASE 0x30000 13f0163958SBard Liao #define SDW_LINK_SIZE 0x10000 14f0163958SBard Liao 15f0163958SBard Liao /* Intel SHIM Registers Definition */ 16f0163958SBard Liao #define SDW_SHIM_LCAP 0x0 17f0163958SBard Liao #define SDW_SHIM_LCTL 0x4 18f0163958SBard Liao #define SDW_SHIM_IPPTR 0x8 19f0163958SBard Liao #define SDW_SHIM_SYNC 0xC 20f0163958SBard Liao 21f0163958SBard Liao #define SDW_SHIM_CTLSCAP(x) (0x010 + 0x60 * (x)) 22f0163958SBard Liao #define SDW_SHIM_CTLS0CM(x) (0x012 + 0x60 * (x)) 23f0163958SBard Liao #define SDW_SHIM_CTLS1CM(x) (0x014 + 0x60 * (x)) 24f0163958SBard Liao #define SDW_SHIM_CTLS2CM(x) (0x016 + 0x60 * (x)) 25f0163958SBard Liao #define SDW_SHIM_CTLS3CM(x) (0x018 + 0x60 * (x)) 26f0163958SBard Liao #define SDW_SHIM_PCMSCAP(x) (0x020 + 0x60 * (x)) 27f0163958SBard Liao 28f0163958SBard Liao #define SDW_SHIM_PCMSYCHM(x, y) (0x022 + (0x60 * (x)) + (0x2 * (y))) 29f0163958SBard Liao #define SDW_SHIM_PCMSYCHC(x, y) (0x042 + (0x60 * (x)) + (0x2 * (y))) 30f0163958SBard Liao #define SDW_SHIM_PDMSCAP(x) (0x062 + 0x60 * (x)) 31f0163958SBard Liao #define SDW_SHIM_IOCTL(x) (0x06C + 0x60 * (x)) 32f0163958SBard Liao #define SDW_SHIM_CTMCTL(x) (0x06E + 0x60 * (x)) 33f0163958SBard Liao 34f0163958SBard Liao #define SDW_SHIM_WAKEEN 0x190 35f0163958SBard Liao #define SDW_SHIM_WAKESTS 0x192 36f0163958SBard Liao 37f0163958SBard Liao #define SDW_SHIM_LCTL_SPA BIT(0) 38f0163958SBard Liao #define SDW_SHIM_LCTL_SPA_MASK GENMASK(3, 0) 39f0163958SBard Liao #define SDW_SHIM_LCTL_CPA BIT(8) 40f0163958SBard Liao #define SDW_SHIM_LCTL_CPA_MASK GENMASK(11, 8) 41f0163958SBard Liao 42f0163958SBard Liao #define SDW_SHIM_SYNC_SYNCPRD_VAL_24 (24000 / SDW_CADENCE_GSYNC_KHZ - 1) 43f0163958SBard Liao #define SDW_SHIM_SYNC_SYNCPRD_VAL_38_4 (38400 / SDW_CADENCE_GSYNC_KHZ - 1) 44f0163958SBard Liao #define SDW_SHIM_SYNC_SYNCPRD GENMASK(14, 0) 45f0163958SBard Liao #define SDW_SHIM_SYNC_SYNCCPU BIT(15) 46f0163958SBard Liao #define SDW_SHIM_SYNC_CMDSYNC_MASK GENMASK(19, 16) 47f0163958SBard Liao #define SDW_SHIM_SYNC_CMDSYNC BIT(16) 48f0163958SBard Liao #define SDW_SHIM_SYNC_SYNCGO BIT(24) 49f0163958SBard Liao 50f0163958SBard Liao #define SDW_SHIM_PCMSCAP_ISS GENMASK(3, 0) 51f0163958SBard Liao #define SDW_SHIM_PCMSCAP_OSS GENMASK(7, 4) 52f0163958SBard Liao #define SDW_SHIM_PCMSCAP_BSS GENMASK(12, 8) 53f0163958SBard Liao 54f0163958SBard Liao #define SDW_SHIM_PCMSYCM_LCHN GENMASK(3, 0) 55f0163958SBard Liao #define SDW_SHIM_PCMSYCM_HCHN GENMASK(7, 4) 56f0163958SBard Liao #define SDW_SHIM_PCMSYCM_STREAM GENMASK(13, 8) 57f0163958SBard Liao #define SDW_SHIM_PCMSYCM_DIR BIT(15) 58f0163958SBard Liao 59f0163958SBard Liao #define SDW_SHIM_PDMSCAP_ISS GENMASK(3, 0) 60f0163958SBard Liao #define SDW_SHIM_PDMSCAP_OSS GENMASK(7, 4) 61f0163958SBard Liao #define SDW_SHIM_PDMSCAP_BSS GENMASK(12, 8) 62f0163958SBard Liao #define SDW_SHIM_PDMSCAP_CPSS GENMASK(15, 13) 63f0163958SBard Liao 64f0163958SBard Liao #define SDW_SHIM_IOCTL_MIF BIT(0) 65f0163958SBard Liao #define SDW_SHIM_IOCTL_CO BIT(1) 66f0163958SBard Liao #define SDW_SHIM_IOCTL_COE BIT(2) 67f0163958SBard Liao #define SDW_SHIM_IOCTL_DO BIT(3) 68f0163958SBard Liao #define SDW_SHIM_IOCTL_DOE BIT(4) 69f0163958SBard Liao #define SDW_SHIM_IOCTL_BKE BIT(5) 70f0163958SBard Liao #define SDW_SHIM_IOCTL_WPDD BIT(6) 71f0163958SBard Liao #define SDW_SHIM_IOCTL_CIBD BIT(8) 72f0163958SBard Liao #define SDW_SHIM_IOCTL_DIBD BIT(9) 73f0163958SBard Liao 74f0163958SBard Liao #define SDW_SHIM_CTMCTL_DACTQE BIT(0) 75f0163958SBard Liao #define SDW_SHIM_CTMCTL_DODS BIT(1) 76f0163958SBard Liao #define SDW_SHIM_CTMCTL_DOAIS GENMASK(4, 3) 77f0163958SBard Liao 78f0163958SBard Liao #define SDW_SHIM_WAKEEN_ENABLE BIT(0) 79f0163958SBard Liao #define SDW_SHIM_WAKESTS_STATUS BIT(0) 80f0163958SBard Liao 81f0163958SBard Liao /* Intel ALH Register definitions */ 82f0163958SBard Liao #define SDW_ALH_STRMZCFG(x) (0x000 + (0x4 * (x))) 83f0163958SBard Liao #define SDW_ALH_NUM_STREAMS 64 84f0163958SBard Liao 85f0163958SBard Liao #define SDW_ALH_STRMZCFG_DMAT_VAL 0x3 86f0163958SBard Liao #define SDW_ALH_STRMZCFG_DMAT GENMASK(7, 0) 87f0163958SBard Liao #define SDW_ALH_STRMZCFG_CHN GENMASK(19, 16) 88f0163958SBard Liao 8971bb8a1bSVinod Koul /** 904b206d34SRander Wang * struct sdw_intel_stream_params_data: configuration passed during 914b206d34SRander Wang * the @params_stream callback, e.g. for interaction with DSP 924b206d34SRander Wang * firmware. 934b206d34SRander Wang */ 944b206d34SRander Wang struct sdw_intel_stream_params_data { 954b206d34SRander Wang struct snd_pcm_substream *substream; 964b206d34SRander Wang struct snd_soc_dai *dai; 974b206d34SRander Wang struct snd_pcm_hw_params *hw_params; 984b206d34SRander Wang int link_id; 994b206d34SRander Wang int alh_stream_id; 1004b206d34SRander Wang }; 1014b206d34SRander Wang 1024b206d34SRander Wang /** 1034b206d34SRander Wang * struct sdw_intel_stream_free_data: configuration passed during 1044b206d34SRander Wang * the @free_stream callback, e.g. for interaction with DSP 1054b206d34SRander Wang * firmware. 1064b206d34SRander Wang */ 1074b206d34SRander Wang struct sdw_intel_stream_free_data { 1084b206d34SRander Wang struct snd_pcm_substream *substream; 1094b206d34SRander Wang struct snd_soc_dai *dai; 1104b206d34SRander Wang int link_id; 1114b206d34SRander Wang }; 1124b206d34SRander Wang 1134b206d34SRander Wang /** 114c46302ecSVinod Koul * struct sdw_intel_ops: Intel audio driver callback ops 115c46302ecSVinod Koul * 116c46302ecSVinod Koul */ 117c46302ecSVinod Koul struct sdw_intel_ops { 1184b206d34SRander Wang int (*params_stream)(struct device *dev, 1194b206d34SRander Wang struct sdw_intel_stream_params_data *params_data); 1204b206d34SRander Wang int (*free_stream)(struct device *dev, 1214b206d34SRander Wang struct sdw_intel_stream_free_data *free_data); 122c46302ecSVinod Koul }; 123c46302ecSVinod Koul 124c46302ecSVinod Koul /** 125f98f690fSPierre-Louis Bossart * struct sdw_intel_acpi_info - Soundwire Intel information found in ACPI tables 126f98f690fSPierre-Louis Bossart * @handle: ACPI controller handle 127f98f690fSPierre-Louis Bossart * @count: link count found with "sdw-master-count" property 128f98f690fSPierre-Louis Bossart * @link_mask: bit-wise mask listing links enabled by BIOS menu 129f98f690fSPierre-Louis Bossart * 130f98f690fSPierre-Louis Bossart * this structure could be expanded to e.g. provide all the _ADR 131f98f690fSPierre-Louis Bossart * information in case the link_mask is not sufficient to identify 132f98f690fSPierre-Louis Bossart * platform capabilities. 133f98f690fSPierre-Louis Bossart */ 134f98f690fSPierre-Louis Bossart struct sdw_intel_acpi_info { 135f98f690fSPierre-Louis Bossart acpi_handle handle; 136f98f690fSPierre-Louis Bossart int count; 137f98f690fSPierre-Louis Bossart u32 link_mask; 138f98f690fSPierre-Louis Bossart }; 139f98f690fSPierre-Louis Bossart 14029a269c6SPierre-Louis Bossart struct sdw_intel_link_dev; 141f98f690fSPierre-Louis Bossart 14209f6a72dSPierre-Louis Bossart /* Intel clock-stop/pm_runtime quirk definitions */ 14309f6a72dSPierre-Louis Bossart 14409f6a72dSPierre-Louis Bossart /* 14509f6a72dSPierre-Louis Bossart * Force the clock to remain on during pm_runtime suspend. This might 14609f6a72dSPierre-Louis Bossart * be needed if Slave devices do not have an alternate clock source or 14709f6a72dSPierre-Louis Bossart * if the latency requirements are very strict. 14809f6a72dSPierre-Louis Bossart */ 14909f6a72dSPierre-Louis Bossart #define SDW_INTEL_CLK_STOP_NOT_ALLOWED BIT(0) 15009f6a72dSPierre-Louis Bossart 15109f6a72dSPierre-Louis Bossart /* 15209f6a72dSPierre-Louis Bossart * Stop the bus during pm_runtime suspend. If set, a complete bus 15309f6a72dSPierre-Louis Bossart * reset and re-enumeration will be performed when the bus 15409f6a72dSPierre-Louis Bossart * restarts. This mode shall not be used if Slave devices can generate 15509f6a72dSPierre-Louis Bossart * in-band wakes. 15609f6a72dSPierre-Louis Bossart */ 15709f6a72dSPierre-Louis Bossart #define SDW_INTEL_CLK_STOP_TEARDOWN BIT(1) 15809f6a72dSPierre-Louis Bossart 15909f6a72dSPierre-Louis Bossart /* 16009f6a72dSPierre-Louis Bossart * Stop the bus during pm_suspend if Slaves are not wake capable 16109f6a72dSPierre-Louis Bossart * (e.g. speaker amplifiers). The clock-stop mode is typically 16209f6a72dSPierre-Louis Bossart * slightly higher power than when the IP is completely powered-off. 16309f6a72dSPierre-Louis Bossart */ 16409f6a72dSPierre-Louis Bossart #define SDW_INTEL_CLK_STOP_WAKE_CAPABLE_ONLY BIT(2) 16509f6a72dSPierre-Louis Bossart 16609f6a72dSPierre-Louis Bossart /* 16709f6a72dSPierre-Louis Bossart * Require a bus reset (and complete re-enumeration) when exiting 16809f6a72dSPierre-Louis Bossart * clock stop modes. This may be needed if the controller power was 16909f6a72dSPierre-Louis Bossart * turned off and all context lost. This quirk shall not be used if a 17009f6a72dSPierre-Louis Bossart * Slave device needs to remain enumerated and keep its context, 17109f6a72dSPierre-Louis Bossart * e.g. to provide the reasons for the wake, report acoustic events or 17209f6a72dSPierre-Louis Bossart * pass a history buffer. 17309f6a72dSPierre-Louis Bossart */ 17409f6a72dSPierre-Louis Bossart #define SDW_INTEL_CLK_STOP_BUS_RESET BIT(3) 17509f6a72dSPierre-Louis Bossart 17692f622bcSBard Liao struct sdw_intel_slave_id { 17792f622bcSBard Liao int link_id; 17892f622bcSBard Liao struct sdw_slave_id id; 17992f622bcSBard Liao }; 18092f622bcSBard Liao 181f98f690fSPierre-Louis Bossart /** 182f98f690fSPierre-Louis Bossart * struct sdw_intel_ctx - context allocated by the controller 183f98f690fSPierre-Louis Bossart * driver probe 184f98f690fSPierre-Louis Bossart * @count: link count 185f98f690fSPierre-Louis Bossart * @mmio_base: mmio base of SoundWire registers, only used to check 186f98f690fSPierre-Louis Bossart * hardware capabilities after all power dependencies are settled. 187f98f690fSPierre-Louis Bossart * @link_mask: bit-wise mask listing SoundWire links reported by the 188f98f690fSPierre-Louis Bossart * Controller 18992f622bcSBard Liao * @num_slaves: total number of devices exposed across all enabled links 190f98f690fSPierre-Louis Bossart * @handle: ACPI parent handle 19129a269c6SPierre-Louis Bossart * @ldev: information for each link (controller-specific and kept 192f98f690fSPierre-Louis Bossart * opaque here) 19392f622bcSBard Liao * @ids: array of slave_id, representing Slaves exposed across all enabled 19492f622bcSBard Liao * links 195eae0b60dSBard Liao * @link_list: list to handle interrupts across all links 1964da0680fSPierre-Louis Bossart * @shim_lock: mutex to handle concurrent rmw access to shared SHIM registers. 1974a17c441SPierre-Louis Bossart * @shim_mask: flags to track initialization of SHIM shared registers 198*60e9feb7SBard Liao * @shim_base: sdw shim base. 199*60e9feb7SBard Liao * @alh_base: sdw alh base. 200f98f690fSPierre-Louis Bossart */ 201f98f690fSPierre-Louis Bossart struct sdw_intel_ctx { 202f98f690fSPierre-Louis Bossart int count; 203f98f690fSPierre-Louis Bossart void __iomem *mmio_base; 204f98f690fSPierre-Louis Bossart u32 link_mask; 20592f622bcSBard Liao int num_slaves; 206f98f690fSPierre-Louis Bossart acpi_handle handle; 20729a269c6SPierre-Louis Bossart struct sdw_intel_link_dev **ldev; 20892f622bcSBard Liao struct sdw_intel_slave_id *ids; 209eae0b60dSBard Liao struct list_head link_list; 2104da0680fSPierre-Louis Bossart struct mutex shim_lock; /* lock for access to shared SHIM registers */ 2114a17c441SPierre-Louis Bossart u32 shim_mask; 212*60e9feb7SBard Liao u32 shim_base; 213*60e9feb7SBard Liao u32 alh_base; 214f98f690fSPierre-Louis Bossart }; 215f98f690fSPierre-Louis Bossart 216f98f690fSPierre-Louis Bossart /** 217f98f690fSPierre-Louis Bossart * struct sdw_intel_res - Soundwire Intel global resource structure, 218f98f690fSPierre-Louis Bossart * typically populated by the DSP driver 219f98f690fSPierre-Louis Bossart * 220f98f690fSPierre-Louis Bossart * @count: link count 22171bb8a1bSVinod Koul * @mmio_base: mmio base of SoundWire registers 22271bb8a1bSVinod Koul * @irq: interrupt number 22371bb8a1bSVinod Koul * @handle: ACPI parent handle 22471bb8a1bSVinod Koul * @parent: parent device 225c46302ecSVinod Koul * @ops: callback ops 226f98f690fSPierre-Louis Bossart * @dev: device implementing hwparams and free callbacks 227f98f690fSPierre-Louis Bossart * @link_mask: bit-wise mask listing links selected by the DSP driver 228f98f690fSPierre-Louis Bossart * This mask may be a subset of the one reported by the controller since 229f98f690fSPierre-Louis Bossart * machine-specific quirks are handled in the DSP driver. 23009f6a72dSPierre-Louis Bossart * @clock_stop_quirks: mask array of possible behaviors requested by the 23109f6a72dSPierre-Louis Bossart * DSP driver. The quirks are common for all links for now. 232*60e9feb7SBard Liao * @shim_base: sdw shim base. 233*60e9feb7SBard Liao * @alh_base: sdw alh base. 23471bb8a1bSVinod Koul */ 23571bb8a1bSVinod Koul struct sdw_intel_res { 236f98f690fSPierre-Louis Bossart int count; 23771bb8a1bSVinod Koul void __iomem *mmio_base; 23871bb8a1bSVinod Koul int irq; 23971bb8a1bSVinod Koul acpi_handle handle; 24071bb8a1bSVinod Koul struct device *parent; 241c46302ecSVinod Koul const struct sdw_intel_ops *ops; 242f98f690fSPierre-Louis Bossart struct device *dev; 243f98f690fSPierre-Louis Bossart u32 link_mask; 24409f6a72dSPierre-Louis Bossart u32 clock_stop_quirks; 245*60e9feb7SBard Liao u32 shim_base; 246*60e9feb7SBard Liao u32 alh_base; 24771bb8a1bSVinod Koul }; 24871bb8a1bSVinod Koul 249f98f690fSPierre-Louis Bossart /* 250f98f690fSPierre-Louis Bossart * On Intel platforms, the SoundWire IP has dependencies on power 251f98f690fSPierre-Louis Bossart * rails shared with the DSP, and the initialization steps are split 252f98f690fSPierre-Louis Bossart * in three. First an ACPI scan to check what the firmware describes 253f98f690fSPierre-Louis Bossart * in DSDT tables, then an allocation step (with no hardware 254f98f690fSPierre-Louis Bossart * configuration but with all the relevant devices created) and last 255f98f690fSPierre-Louis Bossart * the actual hardware configuration. The final stage is a global 256f98f690fSPierre-Louis Bossart * interrupt enable which is controlled by the DSP driver. Splitting 257f98f690fSPierre-Louis Bossart * these phases helps simplify the boot flow and make early decisions 258f98f690fSPierre-Louis Bossart * on e.g. which machine driver to select (I2S mode, HDaudio or 259f98f690fSPierre-Louis Bossart * SoundWire). 260f98f690fSPierre-Louis Bossart */ 261f98f690fSPierre-Louis Bossart int sdw_intel_acpi_scan(acpi_handle *parent_handle, 262f98f690fSPierre-Louis Bossart struct sdw_intel_acpi_info *info); 263f98f690fSPierre-Louis Bossart 264905b5a81SRander Wang void sdw_intel_process_wakeen_event(struct sdw_intel_ctx *ctx); 265905b5a81SRander Wang 266f98f690fSPierre-Louis Bossart struct sdw_intel_ctx * 267f98f690fSPierre-Louis Bossart sdw_intel_probe(struct sdw_intel_res *res); 268f98f690fSPierre-Louis Bossart 269f98f690fSPierre-Louis Bossart int sdw_intel_startup(struct sdw_intel_ctx *ctx); 270f98f690fSPierre-Louis Bossart 271f98f690fSPierre-Louis Bossart void sdw_intel_exit(struct sdw_intel_ctx *ctx); 272f98f690fSPierre-Louis Bossart 273f98f690fSPierre-Louis Bossart void sdw_intel_enable_irq(void __iomem *mmio_base, bool enable); 274d62a7d41SVinod Koul 2756cd1d670SBard Liao irqreturn_t sdw_intel_thread(int irq, void *dev_id); 2766cd1d670SBard Liao 27708c2a4bcSPierre-Louis Bossart #define SDW_INTEL_QUIRK_MASK_BUS_DISABLE BIT(1) 27808c2a4bcSPierre-Louis Bossart 27971bb8a1bSVinod Koul #endif 280