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 12064520e8SBard Liao #define SDW_SHIM_BASE_ACE 0x38000 13064520e8SBard Liao #define SDW_ALH_BASE_ACE 0x24000 14f0163958SBard Liao #define SDW_LINK_BASE 0x30000 15f0163958SBard Liao #define SDW_LINK_SIZE 0x10000 16f0163958SBard Liao 17f0163958SBard Liao /* Intel SHIM Registers Definition */ 187f817068SPierre-Louis Bossart /* LCAP */ 19f0163958SBard Liao #define SDW_SHIM_LCAP 0x0 207f817068SPierre-Louis Bossart #define SDW_SHIM_LCAP_LCOUNT_MASK GENMASK(2, 0) 217f817068SPierre-Louis Bossart 22feaa24aaSPierre-Louis Bossart /* LCTL */ 23f0163958SBard Liao #define SDW_SHIM_LCTL 0x4 24feaa24aaSPierre-Louis Bossart 25feaa24aaSPierre-Louis Bossart #define SDW_SHIM_LCTL_SPA BIT(0) 26feaa24aaSPierre-Louis Bossart #define SDW_SHIM_LCTL_SPA_MASK GENMASK(3, 0) 27feaa24aaSPierre-Louis Bossart #define SDW_SHIM_LCTL_CPA BIT(8) 28feaa24aaSPierre-Louis Bossart #define SDW_SHIM_LCTL_CPA_MASK GENMASK(11, 8) 29feaa24aaSPierre-Louis Bossart 30ca33a58dSPierre-Louis Bossart /* SYNC */ 31f0163958SBard Liao #define SDW_SHIM_SYNC 0xC 32f0163958SBard Liao 33ca33a58dSPierre-Louis Bossart #define SDW_SHIM_SYNC_SYNCPRD_VAL_24 (24000 / SDW_CADENCE_GSYNC_KHZ - 1) 34ca33a58dSPierre-Louis Bossart #define SDW_SHIM_SYNC_SYNCPRD_VAL_38_4 (38400 / SDW_CADENCE_GSYNC_KHZ - 1) 35ca33a58dSPierre-Louis Bossart #define SDW_SHIM_SYNC_SYNCPRD GENMASK(14, 0) 36ca33a58dSPierre-Louis Bossart #define SDW_SHIM_SYNC_SYNCCPU BIT(15) 37ca33a58dSPierre-Louis Bossart #define SDW_SHIM_SYNC_CMDSYNC_MASK GENMASK(19, 16) 38ca33a58dSPierre-Louis Bossart #define SDW_SHIM_SYNC_CMDSYNC BIT(16) 39ca33a58dSPierre-Louis Bossart #define SDW_SHIM_SYNC_SYNCGO BIT(24) 40ca33a58dSPierre-Louis Bossart 41bd45a65dSPierre-Louis Bossart /* Control stream capabililities and channel mask */ 42f0163958SBard Liao #define SDW_SHIM_CTLSCAP(x) (0x010 + 0x60 * (x)) 43f0163958SBard Liao #define SDW_SHIM_CTLS0CM(x) (0x012 + 0x60 * (x)) 44f0163958SBard Liao #define SDW_SHIM_CTLS1CM(x) (0x014 + 0x60 * (x)) 45f0163958SBard Liao #define SDW_SHIM_CTLS2CM(x) (0x016 + 0x60 * (x)) 46f0163958SBard Liao #define SDW_SHIM_CTLS3CM(x) (0x018 + 0x60 * (x)) 47bd45a65dSPierre-Louis Bossart 4840f7a3ddSPierre-Louis Bossart /* PCM Stream capabilities */ 49f0163958SBard Liao #define SDW_SHIM_PCMSCAP(x) (0x020 + 0x60 * (x)) 50f0163958SBard Liao 5140f7a3ddSPierre-Louis Bossart #define SDW_SHIM_PCMSCAP_ISS GENMASK(3, 0) 5240f7a3ddSPierre-Louis Bossart #define SDW_SHIM_PCMSCAP_OSS GENMASK(7, 4) 5340f7a3ddSPierre-Louis Bossart #define SDW_SHIM_PCMSCAP_BSS GENMASK(12, 8) 5440f7a3ddSPierre-Louis Bossart 555c0d2562SPierre-Louis Bossart /* PCM Stream Channel Map */ 56f0163958SBard Liao #define SDW_SHIM_PCMSYCHM(x, y) (0x022 + (0x60 * (x)) + (0x2 * (y))) 57f0163958SBard Liao 585c0d2562SPierre-Louis Bossart /* PCM Stream Channel Count */ 595c0d2562SPierre-Louis Bossart #define SDW_SHIM_PCMSYCHC(x, y) (0x042 + (0x60 * (x)) + (0x2 * (y))) 60f0163958SBard Liao 61f0163958SBard Liao #define SDW_SHIM_PCMSYCM_LCHN GENMASK(3, 0) 62f0163958SBard Liao #define SDW_SHIM_PCMSYCM_HCHN GENMASK(7, 4) 63f0163958SBard Liao #define SDW_SHIM_PCMSYCM_STREAM GENMASK(13, 8) 64f0163958SBard Liao #define SDW_SHIM_PCMSYCM_DIR BIT(15) 65f0163958SBard Liao 663ea29d33SPierre-Louis Bossart /* IO control */ 675c0d2562SPierre-Louis Bossart #define SDW_SHIM_IOCTL(x) (0x06C + 0x60 * (x)) 685c0d2562SPierre-Louis Bossart 69f0163958SBard Liao #define SDW_SHIM_IOCTL_MIF BIT(0) 70f0163958SBard Liao #define SDW_SHIM_IOCTL_CO BIT(1) 71f0163958SBard Liao #define SDW_SHIM_IOCTL_COE BIT(2) 72f0163958SBard Liao #define SDW_SHIM_IOCTL_DO BIT(3) 73f0163958SBard Liao #define SDW_SHIM_IOCTL_DOE BIT(4) 74f0163958SBard Liao #define SDW_SHIM_IOCTL_BKE BIT(5) 75f0163958SBard Liao #define SDW_SHIM_IOCTL_WPDD BIT(6) 76f0163958SBard Liao #define SDW_SHIM_IOCTL_CIBD BIT(8) 77f0163958SBard Liao #define SDW_SHIM_IOCTL_DIBD BIT(9) 78f0163958SBard Liao 79279e46bcSPierre-Louis Bossart /* Wake Enable*/ 803ea29d33SPierre-Louis Bossart #define SDW_SHIM_WAKEEN 0x190 81279e46bcSPierre-Louis Bossart 82279e46bcSPierre-Louis Bossart #define SDW_SHIM_WAKEEN_ENABLE BIT(0) 83279e46bcSPierre-Louis Bossart 84279e46bcSPierre-Louis Bossart /* Wake Status */ 853ea29d33SPierre-Louis Bossart #define SDW_SHIM_WAKESTS 0x192 863ea29d33SPierre-Louis Bossart 87279e46bcSPierre-Louis Bossart #define SDW_SHIM_WAKESTS_STATUS BIT(0) 88279e46bcSPierre-Louis Bossart 89bc7b9595SPierre-Louis Bossart /* AC Timing control */ 90bc7b9595SPierre-Louis Bossart #define SDW_SHIM_CTMCTL(x) (0x06E + 0x60 * (x)) 91bc7b9595SPierre-Louis Bossart 92f0163958SBard Liao #define SDW_SHIM_CTMCTL_DACTQE BIT(0) 93f0163958SBard Liao #define SDW_SHIM_CTMCTL_DODS BIT(1) 94f0163958SBard Liao #define SDW_SHIM_CTMCTL_DOAIS GENMASK(4, 3) 95f0163958SBard Liao 96f0163958SBard Liao /* Intel ALH Register definitions */ 97f0163958SBard Liao #define SDW_ALH_STRMZCFG(x) (0x000 + (0x4 * (x))) 98f0163958SBard Liao #define SDW_ALH_NUM_STREAMS 64 99f0163958SBard Liao 100f0163958SBard Liao #define SDW_ALH_STRMZCFG_DMAT_VAL 0x3 101f0163958SBard Liao #define SDW_ALH_STRMZCFG_DMAT GENMASK(7, 0) 102f0163958SBard Liao #define SDW_ALH_STRMZCFG_CHN GENMASK(19, 16) 103f0163958SBard Liao 10471bb8a1bSVinod Koul /** 1054b206d34SRander Wang * struct sdw_intel_stream_params_data: configuration passed during 1064b206d34SRander Wang * the @params_stream callback, e.g. for interaction with DSP 1074b206d34SRander Wang * firmware. 1084b206d34SRander Wang */ 1094b206d34SRander Wang struct sdw_intel_stream_params_data { 110b86947b5SPierre-Louis Bossart int stream; 1114b206d34SRander Wang struct snd_soc_dai *dai; 1124b206d34SRander Wang struct snd_pcm_hw_params *hw_params; 1134b206d34SRander Wang int link_id; 1144b206d34SRander Wang int alh_stream_id; 1154b206d34SRander Wang }; 1164b206d34SRander Wang 1174b206d34SRander Wang /** 1184b206d34SRander Wang * struct sdw_intel_stream_free_data: configuration passed during 1194b206d34SRander Wang * the @free_stream callback, e.g. for interaction with DSP 1204b206d34SRander Wang * firmware. 1214b206d34SRander Wang */ 1224b206d34SRander Wang struct sdw_intel_stream_free_data { 123b86947b5SPierre-Louis Bossart int stream; 1244b206d34SRander Wang struct snd_soc_dai *dai; 1254b206d34SRander Wang int link_id; 1264b206d34SRander Wang }; 1274b206d34SRander Wang 1284b206d34SRander Wang /** 129c46302ecSVinod Koul * struct sdw_intel_ops: Intel audio driver callback ops 130c46302ecSVinod Koul * 131c46302ecSVinod Koul */ 132c46302ecSVinod Koul struct sdw_intel_ops { 1334b206d34SRander Wang int (*params_stream)(struct device *dev, 1344b206d34SRander Wang struct sdw_intel_stream_params_data *params_data); 1354b206d34SRander Wang int (*free_stream)(struct device *dev, 1364b206d34SRander Wang struct sdw_intel_stream_free_data *free_data); 1376d1c1a73SBard Liao int (*trigger)(struct snd_soc_dai *dai, int cmd, int stream); 138c46302ecSVinod Koul }; 139c46302ecSVinod Koul 140c46302ecSVinod Koul /** 141f98f690fSPierre-Louis Bossart * struct sdw_intel_acpi_info - Soundwire Intel information found in ACPI tables 142f98f690fSPierre-Louis Bossart * @handle: ACPI controller handle 143f98f690fSPierre-Louis Bossart * @count: link count found with "sdw-master-count" property 144f98f690fSPierre-Louis Bossart * @link_mask: bit-wise mask listing links enabled by BIOS menu 145f98f690fSPierre-Louis Bossart * 146f98f690fSPierre-Louis Bossart * this structure could be expanded to e.g. provide all the _ADR 147f98f690fSPierre-Louis Bossart * information in case the link_mask is not sufficient to identify 148f98f690fSPierre-Louis Bossart * platform capabilities. 149f98f690fSPierre-Louis Bossart */ 150f98f690fSPierre-Louis Bossart struct sdw_intel_acpi_info { 151f98f690fSPierre-Louis Bossart acpi_handle handle; 152f98f690fSPierre-Louis Bossart int count; 153f98f690fSPierre-Louis Bossart u32 link_mask; 154f98f690fSPierre-Louis Bossart }; 155f98f690fSPierre-Louis Bossart 15629a269c6SPierre-Louis Bossart struct sdw_intel_link_dev; 157f98f690fSPierre-Louis Bossart 15809f6a72dSPierre-Louis Bossart /* Intel clock-stop/pm_runtime quirk definitions */ 15909f6a72dSPierre-Louis Bossart 16009f6a72dSPierre-Louis Bossart /* 16109f6a72dSPierre-Louis Bossart * Force the clock to remain on during pm_runtime suspend. This might 16209f6a72dSPierre-Louis Bossart * be needed if Slave devices do not have an alternate clock source or 16309f6a72dSPierre-Louis Bossart * if the latency requirements are very strict. 16409f6a72dSPierre-Louis Bossart */ 16509f6a72dSPierre-Louis Bossart #define SDW_INTEL_CLK_STOP_NOT_ALLOWED BIT(0) 16609f6a72dSPierre-Louis Bossart 16709f6a72dSPierre-Louis Bossart /* 16809f6a72dSPierre-Louis Bossart * Stop the bus during pm_runtime suspend. If set, a complete bus 16909f6a72dSPierre-Louis Bossart * reset and re-enumeration will be performed when the bus 17009f6a72dSPierre-Louis Bossart * restarts. This mode shall not be used if Slave devices can generate 17109f6a72dSPierre-Louis Bossart * in-band wakes. 17209f6a72dSPierre-Louis Bossart */ 17309f6a72dSPierre-Louis Bossart #define SDW_INTEL_CLK_STOP_TEARDOWN BIT(1) 17409f6a72dSPierre-Louis Bossart 17509f6a72dSPierre-Louis Bossart /* 17609f6a72dSPierre-Louis Bossart * Stop the bus during pm_suspend if Slaves are not wake capable 17709f6a72dSPierre-Louis Bossart * (e.g. speaker amplifiers). The clock-stop mode is typically 17809f6a72dSPierre-Louis Bossart * slightly higher power than when the IP is completely powered-off. 17909f6a72dSPierre-Louis Bossart */ 18009f6a72dSPierre-Louis Bossart #define SDW_INTEL_CLK_STOP_WAKE_CAPABLE_ONLY BIT(2) 18109f6a72dSPierre-Louis Bossart 18209f6a72dSPierre-Louis Bossart /* 18309f6a72dSPierre-Louis Bossart * Require a bus reset (and complete re-enumeration) when exiting 18409f6a72dSPierre-Louis Bossart * clock stop modes. This may be needed if the controller power was 18509f6a72dSPierre-Louis Bossart * turned off and all context lost. This quirk shall not be used if a 18609f6a72dSPierre-Louis Bossart * Slave device needs to remain enumerated and keep its context, 18709f6a72dSPierre-Louis Bossart * e.g. to provide the reasons for the wake, report acoustic events or 18809f6a72dSPierre-Louis Bossart * pass a history buffer. 18909f6a72dSPierre-Louis Bossart */ 19009f6a72dSPierre-Louis Bossart #define SDW_INTEL_CLK_STOP_BUS_RESET BIT(3) 19109f6a72dSPierre-Louis Bossart 19292f622bcSBard Liao struct sdw_intel_slave_id { 19392f622bcSBard Liao int link_id; 19492f622bcSBard Liao struct sdw_slave_id id; 19592f622bcSBard Liao }; 19692f622bcSBard Liao 197f98f690fSPierre-Louis Bossart /** 198f98f690fSPierre-Louis Bossart * struct sdw_intel_ctx - context allocated by the controller 199f98f690fSPierre-Louis Bossart * driver probe 200f98f690fSPierre-Louis Bossart * @count: link count 201f98f690fSPierre-Louis Bossart * @mmio_base: mmio base of SoundWire registers, only used to check 202f98f690fSPierre-Louis Bossart * hardware capabilities after all power dependencies are settled. 203f98f690fSPierre-Louis Bossart * @link_mask: bit-wise mask listing SoundWire links reported by the 204f98f690fSPierre-Louis Bossart * Controller 20592f622bcSBard Liao * @num_slaves: total number of devices exposed across all enabled links 206f98f690fSPierre-Louis Bossart * @handle: ACPI parent handle 20729a269c6SPierre-Louis Bossart * @ldev: information for each link (controller-specific and kept 208f98f690fSPierre-Louis Bossart * opaque here) 20992f622bcSBard Liao * @ids: array of slave_id, representing Slaves exposed across all enabled 21092f622bcSBard Liao * links 211eae0b60dSBard Liao * @link_list: list to handle interrupts across all links 2124da0680fSPierre-Louis Bossart * @shim_lock: mutex to handle concurrent rmw access to shared SHIM registers. 2134a17c441SPierre-Louis Bossart * @shim_mask: flags to track initialization of SHIM shared registers 21460e9feb7SBard Liao * @shim_base: sdw shim base. 21560e9feb7SBard Liao * @alh_base: sdw alh base. 216f98f690fSPierre-Louis Bossart */ 217f98f690fSPierre-Louis Bossart struct sdw_intel_ctx { 218f98f690fSPierre-Louis Bossart int count; 219f98f690fSPierre-Louis Bossart void __iomem *mmio_base; 220f98f690fSPierre-Louis Bossart u32 link_mask; 22192f622bcSBard Liao int num_slaves; 222f98f690fSPierre-Louis Bossart acpi_handle handle; 22329a269c6SPierre-Louis Bossart struct sdw_intel_link_dev **ldev; 22492f622bcSBard Liao struct sdw_intel_slave_id *ids; 225eae0b60dSBard Liao struct list_head link_list; 2264da0680fSPierre-Louis Bossart struct mutex shim_lock; /* lock for access to shared SHIM registers */ 2274a17c441SPierre-Louis Bossart u32 shim_mask; 22860e9feb7SBard Liao u32 shim_base; 22960e9feb7SBard Liao u32 alh_base; 230f98f690fSPierre-Louis Bossart }; 231f98f690fSPierre-Louis Bossart 232f98f690fSPierre-Louis Bossart /** 233f98f690fSPierre-Louis Bossart * struct sdw_intel_res - Soundwire Intel global resource structure, 234f98f690fSPierre-Louis Bossart * typically populated by the DSP driver 235f98f690fSPierre-Louis Bossart * 236b3ad31f3SPierre-Louis Bossart * @hw_ops: abstraction for platform ops 237f98f690fSPierre-Louis Bossart * @count: link count 23871bb8a1bSVinod Koul * @mmio_base: mmio base of SoundWire registers 23971bb8a1bSVinod Koul * @irq: interrupt number 24071bb8a1bSVinod Koul * @handle: ACPI parent handle 24171bb8a1bSVinod Koul * @parent: parent device 242c46302ecSVinod Koul * @ops: callback ops 243f98f690fSPierre-Louis Bossart * @dev: device implementing hwparams and free callbacks 244f98f690fSPierre-Louis Bossart * @link_mask: bit-wise mask listing links selected by the DSP driver 245f98f690fSPierre-Louis Bossart * This mask may be a subset of the one reported by the controller since 246f98f690fSPierre-Louis Bossart * machine-specific quirks are handled in the DSP driver. 24709f6a72dSPierre-Louis Bossart * @clock_stop_quirks: mask array of possible behaviors requested by the 24809f6a72dSPierre-Louis Bossart * DSP driver. The quirks are common for all links for now. 24960e9feb7SBard Liao * @shim_base: sdw shim base. 25060e9feb7SBard Liao * @alh_base: sdw alh base. 25171bb8a1bSVinod Koul */ 25271bb8a1bSVinod Koul struct sdw_intel_res { 253b3ad31f3SPierre-Louis Bossart const struct sdw_intel_hw_ops *hw_ops; 254f98f690fSPierre-Louis Bossart int count; 25571bb8a1bSVinod Koul void __iomem *mmio_base; 25671bb8a1bSVinod Koul int irq; 25771bb8a1bSVinod Koul acpi_handle handle; 25871bb8a1bSVinod Koul struct device *parent; 259c46302ecSVinod Koul const struct sdw_intel_ops *ops; 260f98f690fSPierre-Louis Bossart struct device *dev; 261f98f690fSPierre-Louis Bossart u32 link_mask; 26209f6a72dSPierre-Louis Bossart u32 clock_stop_quirks; 26360e9feb7SBard Liao u32 shim_base; 26460e9feb7SBard Liao u32 alh_base; 26571bb8a1bSVinod Koul }; 26671bb8a1bSVinod Koul 267f98f690fSPierre-Louis Bossart /* 268f98f690fSPierre-Louis Bossart * On Intel platforms, the SoundWire IP has dependencies on power 269f98f690fSPierre-Louis Bossart * rails shared with the DSP, and the initialization steps are split 270f98f690fSPierre-Louis Bossart * in three. First an ACPI scan to check what the firmware describes 271f98f690fSPierre-Louis Bossart * in DSDT tables, then an allocation step (with no hardware 272f98f690fSPierre-Louis Bossart * configuration but with all the relevant devices created) and last 273f98f690fSPierre-Louis Bossart * the actual hardware configuration. The final stage is a global 274f98f690fSPierre-Louis Bossart * interrupt enable which is controlled by the DSP driver. Splitting 275f98f690fSPierre-Louis Bossart * these phases helps simplify the boot flow and make early decisions 276f98f690fSPierre-Louis Bossart * on e.g. which machine driver to select (I2S mode, HDaudio or 277f98f690fSPierre-Louis Bossart * SoundWire). 278f98f690fSPierre-Louis Bossart */ 279f98f690fSPierre-Louis Bossart int sdw_intel_acpi_scan(acpi_handle *parent_handle, 280f98f690fSPierre-Louis Bossart struct sdw_intel_acpi_info *info); 281f98f690fSPierre-Louis Bossart 282905b5a81SRander Wang void sdw_intel_process_wakeen_event(struct sdw_intel_ctx *ctx); 283905b5a81SRander Wang 284f98f690fSPierre-Louis Bossart struct sdw_intel_ctx * 285f98f690fSPierre-Louis Bossart sdw_intel_probe(struct sdw_intel_res *res); 286f98f690fSPierre-Louis Bossart 287f98f690fSPierre-Louis Bossart int sdw_intel_startup(struct sdw_intel_ctx *ctx); 288f98f690fSPierre-Louis Bossart 289f98f690fSPierre-Louis Bossart void sdw_intel_exit(struct sdw_intel_ctx *ctx); 290f98f690fSPierre-Louis Bossart 291f98f690fSPierre-Louis Bossart void sdw_intel_enable_irq(void __iomem *mmio_base, bool enable); 292d62a7d41SVinod Koul 2936cd1d670SBard Liao irqreturn_t sdw_intel_thread(int irq, void *dev_id); 2946cd1d670SBard Liao 29508c2a4bcSPierre-Louis Bossart #define SDW_INTEL_QUIRK_MASK_BUS_DISABLE BIT(1) 29608c2a4bcSPierre-Louis Bossart 297b3ad31f3SPierre-Louis Bossart struct sdw_intel; 298b3ad31f3SPierre-Louis Bossart 299b3ad31f3SPierre-Louis Bossart /* struct intel_sdw_hw_ops - SoundWire ops for Intel platforms. 300fb2dc6a0SPierre-Louis Bossart * @debugfs_init: initialize all debugfs capabilities 301fb2dc6a0SPierre-Louis Bossart * @debugfs_exit: close and cleanup debugfs capabilities 302*b6234bccSPierre-Louis Bossart * @register_dai: read all PDI information and register DAIs 303b3ad31f3SPierre-Louis Bossart * @pre_bank_switch: helper for bus management 304b3ad31f3SPierre-Louis Bossart * @post_bank_switch: helper for bus management 305b3ad31f3SPierre-Louis Bossart */ 306b3ad31f3SPierre-Louis Bossart struct sdw_intel_hw_ops { 307fb2dc6a0SPierre-Louis Bossart void (*debugfs_init)(struct sdw_intel *sdw); 308fb2dc6a0SPierre-Louis Bossart void (*debugfs_exit)(struct sdw_intel *sdw); 309fb2dc6a0SPierre-Louis Bossart 310*b6234bccSPierre-Louis Bossart int (*register_dai)(struct sdw_intel *sdw); 311*b6234bccSPierre-Louis Bossart 312b3ad31f3SPierre-Louis Bossart int (*pre_bank_switch)(struct sdw_intel *sdw); 313b3ad31f3SPierre-Louis Bossart int (*post_bank_switch)(struct sdw_intel *sdw); 314b3ad31f3SPierre-Louis Bossart }; 315b3ad31f3SPierre-Louis Bossart 316b3ad31f3SPierre-Louis Bossart extern const struct sdw_intel_hw_ops sdw_intel_cnl_hw_ops; 317b3ad31f3SPierre-Louis Bossart 31871bb8a1bSVinod Koul #endif 319