Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1 | // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) |
| 2 | // Copyright(c) 2015-17 Intel Corporation. |
| 3 | |
| 4 | /* |
| 5 | * Soundwire Intel Master Driver |
| 6 | */ |
| 7 | |
| 8 | #include <linux/acpi.h> |
Pierre-Louis Bossart | 79ee663 | 2019-08-21 13:58:20 -0500 | [diff] [blame] | 9 | #include <linux/debugfs.h> |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 10 | #include <linux/delay.h> |
Paul Gortmaker | 4abbd78 | 2019-04-13 11:12:52 -0400 | [diff] [blame] | 11 | #include <linux/module.h> |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 12 | #include <linux/interrupt.h> |
Pierre-Louis Bossart | df72b71 | 2019-09-16 13:57:38 -0500 | [diff] [blame] | 13 | #include <linux/io.h> |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 14 | #include <linux/platform_device.h> |
Vinod Koul | 37a2d22 | 2018-04-26 18:38:58 +0530 | [diff] [blame] | 15 | #include <sound/pcm_params.h> |
Rander Wang | ab2c913 | 2020-07-16 23:09:46 +0800 | [diff] [blame] | 16 | #include <linux/pm_runtime.h> |
Vinod Koul | 37a2d22 | 2018-04-26 18:38:58 +0530 | [diff] [blame] | 17 | #include <sound/soc.h> |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 18 | #include <linux/soundwire/sdw_registers.h> |
| 19 | #include <linux/soundwire/sdw.h> |
| 20 | #include <linux/soundwire/sdw_intel.h> |
| 21 | #include "cadence_master.h" |
Pierre-Louis Bossart | 79ee663 | 2019-08-21 13:58:20 -0500 | [diff] [blame] | 22 | #include "bus.h" |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 23 | #include "intel.h" |
| 24 | |
Pierre-Louis Bossart | ebf878e | 2020-08-17 23:29:12 +0800 | [diff] [blame] | 25 | #define INTEL_MASTER_SUSPEND_DELAY_MS 3000 |
| 26 | |
| 27 | /* |
| 28 | * debug/config flags for the Intel SoundWire Master. |
| 29 | * |
| 30 | * Since we may have multiple masters active, we can have up to 8 |
| 31 | * flags reused in each byte, with master0 using the ls-byte, etc. |
| 32 | */ |
| 33 | |
Pierre-Louis Bossart | a2d9c16 | 2020-08-17 23:29:17 +0800 | [diff] [blame] | 34 | #define SDW_INTEL_MASTER_DISABLE_PM_RUNTIME BIT(0) |
| 35 | #define SDW_INTEL_MASTER_DISABLE_CLOCK_STOP BIT(1) |
| 36 | #define SDW_INTEL_MASTER_DISABLE_PM_RUNTIME_IDLE BIT(2) |
Pierre-Louis Bossart | ebf878e | 2020-08-17 23:29:12 +0800 | [diff] [blame] | 37 | |
| 38 | static int md_flags; |
| 39 | module_param_named(sdw_md_flags, md_flags, int, 0444); |
| 40 | MODULE_PARM_DESC(sdw_md_flags, "SoundWire Intel Master device flags (0x0 all off)"); |
| 41 | |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 42 | /* Intel SHIM Registers Definition */ |
| 43 | #define SDW_SHIM_LCAP 0x0 |
| 44 | #define SDW_SHIM_LCTL 0x4 |
| 45 | #define SDW_SHIM_IPPTR 0x8 |
| 46 | #define SDW_SHIM_SYNC 0xC |
| 47 | |
Pierre-Louis Bossart | 7cc6e31 | 2019-05-01 10:57:39 -0500 | [diff] [blame] | 48 | #define SDW_SHIM_CTLSCAP(x) (0x010 + 0x60 * (x)) |
| 49 | #define SDW_SHIM_CTLS0CM(x) (0x012 + 0x60 * (x)) |
| 50 | #define SDW_SHIM_CTLS1CM(x) (0x014 + 0x60 * (x)) |
| 51 | #define SDW_SHIM_CTLS2CM(x) (0x016 + 0x60 * (x)) |
| 52 | #define SDW_SHIM_CTLS3CM(x) (0x018 + 0x60 * (x)) |
| 53 | #define SDW_SHIM_PCMSCAP(x) (0x020 + 0x60 * (x)) |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 54 | |
Pierre-Louis Bossart | 7cc6e31 | 2019-05-01 10:57:39 -0500 | [diff] [blame] | 55 | #define SDW_SHIM_PCMSYCHM(x, y) (0x022 + (0x60 * (x)) + (0x2 * (y))) |
| 56 | #define SDW_SHIM_PCMSYCHC(x, y) (0x042 + (0x60 * (x)) + (0x2 * (y))) |
| 57 | #define SDW_SHIM_PDMSCAP(x) (0x062 + 0x60 * (x)) |
| 58 | #define SDW_SHIM_IOCTL(x) (0x06C + 0x60 * (x)) |
| 59 | #define SDW_SHIM_CTMCTL(x) (0x06E + 0x60 * (x)) |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 60 | |
| 61 | #define SDW_SHIM_WAKEEN 0x190 |
| 62 | #define SDW_SHIM_WAKESTS 0x192 |
| 63 | |
| 64 | #define SDW_SHIM_LCTL_SPA BIT(0) |
| 65 | #define SDW_SHIM_LCTL_CPA BIT(8) |
| 66 | |
Pierre-Louis Bossart | 4a17c44 | 2020-07-16 23:09:40 +0800 | [diff] [blame] | 67 | #define SDW_SHIM_SYNC_SYNCPRD_VAL_24 (24000 / SDW_CADENCE_GSYNC_KHZ - 1) |
| 68 | #define SDW_SHIM_SYNC_SYNCPRD_VAL_38_4 (38400 / SDW_CADENCE_GSYNC_KHZ - 1) |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 69 | #define SDW_SHIM_SYNC_SYNCPRD GENMASK(14, 0) |
| 70 | #define SDW_SHIM_SYNC_SYNCCPU BIT(15) |
| 71 | #define SDW_SHIM_SYNC_CMDSYNC_MASK GENMASK(19, 16) |
| 72 | #define SDW_SHIM_SYNC_CMDSYNC BIT(16) |
| 73 | #define SDW_SHIM_SYNC_SYNCGO BIT(24) |
| 74 | |
| 75 | #define SDW_SHIM_PCMSCAP_ISS GENMASK(3, 0) |
| 76 | #define SDW_SHIM_PCMSCAP_OSS GENMASK(7, 4) |
| 77 | #define SDW_SHIM_PCMSCAP_BSS GENMASK(12, 8) |
| 78 | |
| 79 | #define SDW_SHIM_PCMSYCM_LCHN GENMASK(3, 0) |
| 80 | #define SDW_SHIM_PCMSYCM_HCHN GENMASK(7, 4) |
| 81 | #define SDW_SHIM_PCMSYCM_STREAM GENMASK(13, 8) |
| 82 | #define SDW_SHIM_PCMSYCM_DIR BIT(15) |
| 83 | |
| 84 | #define SDW_SHIM_PDMSCAP_ISS GENMASK(3, 0) |
| 85 | #define SDW_SHIM_PDMSCAP_OSS GENMASK(7, 4) |
| 86 | #define SDW_SHIM_PDMSCAP_BSS GENMASK(12, 8) |
| 87 | #define SDW_SHIM_PDMSCAP_CPSS GENMASK(15, 13) |
| 88 | |
| 89 | #define SDW_SHIM_IOCTL_MIF BIT(0) |
| 90 | #define SDW_SHIM_IOCTL_CO BIT(1) |
| 91 | #define SDW_SHIM_IOCTL_COE BIT(2) |
| 92 | #define SDW_SHIM_IOCTL_DO BIT(3) |
| 93 | #define SDW_SHIM_IOCTL_DOE BIT(4) |
| 94 | #define SDW_SHIM_IOCTL_BKE BIT(5) |
| 95 | #define SDW_SHIM_IOCTL_WPDD BIT(6) |
| 96 | #define SDW_SHIM_IOCTL_CIBD BIT(8) |
| 97 | #define SDW_SHIM_IOCTL_DIBD BIT(9) |
| 98 | |
| 99 | #define SDW_SHIM_CTMCTL_DACTQE BIT(0) |
| 100 | #define SDW_SHIM_CTMCTL_DODS BIT(1) |
| 101 | #define SDW_SHIM_CTMCTL_DOAIS GENMASK(4, 3) |
| 102 | |
| 103 | #define SDW_SHIM_WAKEEN_ENABLE BIT(0) |
| 104 | #define SDW_SHIM_WAKESTS_STATUS BIT(0) |
| 105 | |
| 106 | /* Intel ALH Register definitions */ |
Pierre-Louis Bossart | 7cc6e31 | 2019-05-01 10:57:39 -0500 | [diff] [blame] | 107 | #define SDW_ALH_STRMZCFG(x) (0x000 + (0x4 * (x))) |
Pierre-Louis Bossart | 79ee663 | 2019-08-21 13:58:20 -0500 | [diff] [blame] | 108 | #define SDW_ALH_NUM_STREAMS 64 |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 109 | |
| 110 | #define SDW_ALH_STRMZCFG_DMAT_VAL 0x3 |
| 111 | #define SDW_ALH_STRMZCFG_DMAT GENMASK(7, 0) |
| 112 | #define SDW_ALH_STRMZCFG_CHN GENMASK(19, 16) |
| 113 | |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 114 | enum intel_pdi_type { |
| 115 | INTEL_PDI_IN = 0, |
| 116 | INTEL_PDI_OUT = 1, |
| 117 | INTEL_PDI_BD = 2, |
| 118 | }; |
| 119 | |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 120 | #define cdns_to_intel(_cdns) container_of(_cdns, struct sdw_intel, cdns) |
| 121 | |
| 122 | /* |
| 123 | * Read, write helpers for HW registers |
| 124 | */ |
| 125 | static inline int intel_readl(void __iomem *base, int offset) |
| 126 | { |
| 127 | return readl(base + offset); |
| 128 | } |
| 129 | |
| 130 | static inline void intel_writel(void __iomem *base, int offset, int value) |
| 131 | { |
| 132 | writel(value, base + offset); |
| 133 | } |
| 134 | |
| 135 | static inline u16 intel_readw(void __iomem *base, int offset) |
| 136 | { |
| 137 | return readw(base + offset); |
| 138 | } |
| 139 | |
| 140 | static inline void intel_writew(void __iomem *base, int offset, u16 value) |
| 141 | { |
| 142 | writew(value, base + offset); |
| 143 | } |
| 144 | |
Pierre-Louis Bossart | 7d2845d | 2020-07-16 23:09:39 +0800 | [diff] [blame] | 145 | static int intel_wait_bit(void __iomem *base, int offset, u32 mask, u32 target) |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 146 | { |
| 147 | int timeout = 10; |
| 148 | u32 reg_read; |
| 149 | |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 150 | do { |
| 151 | reg_read = readl(base + offset); |
Pierre-Louis Bossart | 7d2845d | 2020-07-16 23:09:39 +0800 | [diff] [blame] | 152 | if ((reg_read & mask) == target) |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 153 | return 0; |
| 154 | |
| 155 | timeout--; |
Pierre-Louis Bossart | 7d2845d | 2020-07-16 23:09:39 +0800 | [diff] [blame] | 156 | usleep_range(50, 100); |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 157 | } while (timeout != 0); |
| 158 | |
| 159 | return -EAGAIN; |
| 160 | } |
| 161 | |
Pierre-Louis Bossart | 7d2845d | 2020-07-16 23:09:39 +0800 | [diff] [blame] | 162 | static int intel_clear_bit(void __iomem *base, int offset, u32 value, u32 mask) |
| 163 | { |
| 164 | writel(value, base + offset); |
| 165 | return intel_wait_bit(base, offset, mask, 0); |
| 166 | } |
| 167 | |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 168 | static int intel_set_bit(void __iomem *base, int offset, u32 value, u32 mask) |
| 169 | { |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 170 | writel(value, base + offset); |
Pierre-Louis Bossart | 7d2845d | 2020-07-16 23:09:39 +0800 | [diff] [blame] | 171 | return intel_wait_bit(base, offset, mask, mask); |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | /* |
Pierre-Louis Bossart | 79ee663 | 2019-08-21 13:58:20 -0500 | [diff] [blame] | 175 | * debugfs |
| 176 | */ |
| 177 | #ifdef CONFIG_DEBUG_FS |
| 178 | |
| 179 | #define RD_BUF (2 * PAGE_SIZE) |
| 180 | |
| 181 | static ssize_t intel_sprintf(void __iomem *mem, bool l, |
| 182 | char *buf, size_t pos, unsigned int reg) |
| 183 | { |
| 184 | int value; |
| 185 | |
| 186 | if (l) |
| 187 | value = intel_readl(mem, reg); |
| 188 | else |
| 189 | value = intel_readw(mem, reg); |
| 190 | |
| 191 | return scnprintf(buf + pos, RD_BUF - pos, "%4x\t%4x\n", reg, value); |
| 192 | } |
| 193 | |
| 194 | static int intel_reg_show(struct seq_file *s_file, void *data) |
| 195 | { |
| 196 | struct sdw_intel *sdw = s_file->private; |
Pierre-Louis Bossart | 2523486 | 2020-02-14 19:47:36 -0600 | [diff] [blame] | 197 | void __iomem *s = sdw->link_res->shim; |
| 198 | void __iomem *a = sdw->link_res->alh; |
Pierre-Louis Bossart | 79ee663 | 2019-08-21 13:58:20 -0500 | [diff] [blame] | 199 | char *buf; |
| 200 | ssize_t ret; |
| 201 | int i, j; |
| 202 | unsigned int links, reg; |
| 203 | |
| 204 | buf = kzalloc(RD_BUF, GFP_KERNEL); |
| 205 | if (!buf) |
| 206 | return -ENOMEM; |
| 207 | |
| 208 | links = intel_readl(s, SDW_SHIM_LCAP) & GENMASK(2, 0); |
| 209 | |
| 210 | ret = scnprintf(buf, RD_BUF, "Register Value\n"); |
| 211 | ret += scnprintf(buf + ret, RD_BUF - ret, "\nShim\n"); |
| 212 | |
| 213 | for (i = 0; i < links; i++) { |
| 214 | reg = SDW_SHIM_LCAP + i * 4; |
| 215 | ret += intel_sprintf(s, true, buf, ret, reg); |
| 216 | } |
| 217 | |
| 218 | for (i = 0; i < links; i++) { |
| 219 | ret += scnprintf(buf + ret, RD_BUF - ret, "\nLink%d\n", i); |
| 220 | ret += intel_sprintf(s, false, buf, ret, SDW_SHIM_CTLSCAP(i)); |
| 221 | ret += intel_sprintf(s, false, buf, ret, SDW_SHIM_CTLS0CM(i)); |
| 222 | ret += intel_sprintf(s, false, buf, ret, SDW_SHIM_CTLS1CM(i)); |
| 223 | ret += intel_sprintf(s, false, buf, ret, SDW_SHIM_CTLS2CM(i)); |
| 224 | ret += intel_sprintf(s, false, buf, ret, SDW_SHIM_CTLS3CM(i)); |
| 225 | ret += intel_sprintf(s, false, buf, ret, SDW_SHIM_PCMSCAP(i)); |
| 226 | |
| 227 | ret += scnprintf(buf + ret, RD_BUF - ret, "\n PCMSyCH registers\n"); |
| 228 | |
| 229 | /* |
| 230 | * the value 10 is the number of PDIs. We will need a |
| 231 | * cleanup to remove hard-coded Intel configurations |
| 232 | * from cadence_master.c |
| 233 | */ |
| 234 | for (j = 0; j < 10; j++) { |
| 235 | ret += intel_sprintf(s, false, buf, ret, |
| 236 | SDW_SHIM_PCMSYCHM(i, j)); |
| 237 | ret += intel_sprintf(s, false, buf, ret, |
| 238 | SDW_SHIM_PCMSYCHC(i, j)); |
| 239 | } |
| 240 | ret += scnprintf(buf + ret, RD_BUF - ret, "\n PDMSCAP, IOCTL, CTMCTL\n"); |
| 241 | |
| 242 | ret += intel_sprintf(s, false, buf, ret, SDW_SHIM_PDMSCAP(i)); |
| 243 | ret += intel_sprintf(s, false, buf, ret, SDW_SHIM_IOCTL(i)); |
| 244 | ret += intel_sprintf(s, false, buf, ret, SDW_SHIM_CTMCTL(i)); |
| 245 | } |
| 246 | |
| 247 | ret += scnprintf(buf + ret, RD_BUF - ret, "\nWake registers\n"); |
| 248 | ret += intel_sprintf(s, false, buf, ret, SDW_SHIM_WAKEEN); |
| 249 | ret += intel_sprintf(s, false, buf, ret, SDW_SHIM_WAKESTS); |
| 250 | |
| 251 | ret += scnprintf(buf + ret, RD_BUF - ret, "\nALH STRMzCFG\n"); |
| 252 | for (i = 0; i < SDW_ALH_NUM_STREAMS; i++) |
| 253 | ret += intel_sprintf(a, true, buf, ret, SDW_ALH_STRMZCFG(i)); |
| 254 | |
| 255 | seq_printf(s_file, "%s", buf); |
| 256 | kfree(buf); |
| 257 | |
| 258 | return 0; |
| 259 | } |
| 260 | DEFINE_SHOW_ATTRIBUTE(intel_reg); |
| 261 | |
| 262 | static void intel_debugfs_init(struct sdw_intel *sdw) |
| 263 | { |
| 264 | struct dentry *root = sdw->cdns.bus.debugfs; |
| 265 | |
| 266 | if (!root) |
| 267 | return; |
| 268 | |
| 269 | sdw->debugfs = debugfs_create_dir("intel-sdw", root); |
| 270 | |
| 271 | debugfs_create_file("intel-registers", 0400, sdw->debugfs, sdw, |
| 272 | &intel_reg_fops); |
| 273 | |
| 274 | sdw_cdns_debugfs_init(&sdw->cdns, sdw->debugfs); |
| 275 | } |
| 276 | |
| 277 | static void intel_debugfs_exit(struct sdw_intel *sdw) |
| 278 | { |
| 279 | debugfs_remove_recursive(sdw->debugfs); |
| 280 | } |
| 281 | #else |
| 282 | static void intel_debugfs_init(struct sdw_intel *sdw) {} |
| 283 | static void intel_debugfs_exit(struct sdw_intel *sdw) {} |
| 284 | #endif /* CONFIG_DEBUG_FS */ |
| 285 | |
| 286 | /* |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 287 | * shim ops |
| 288 | */ |
| 289 | |
| 290 | static int intel_link_power_up(struct sdw_intel *sdw) |
| 291 | { |
| 292 | unsigned int link_id = sdw->instance; |
Pierre-Louis Bossart | 2523486 | 2020-02-14 19:47:36 -0600 | [diff] [blame] | 293 | void __iomem *shim = sdw->link_res->shim; |
Pierre-Louis Bossart | 4a17c44 | 2020-07-16 23:09:40 +0800 | [diff] [blame] | 294 | u32 *shim_mask = sdw->link_res->shim_mask; |
| 295 | struct sdw_bus *bus = &sdw->cdns.bus; |
| 296 | struct sdw_master_prop *prop = &bus->prop; |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 297 | int spa_mask, cpa_mask; |
Pierre-Louis Bossart | 4a17c44 | 2020-07-16 23:09:40 +0800 | [diff] [blame] | 298 | int link_control; |
| 299 | int ret = 0; |
| 300 | u32 syncprd; |
| 301 | u32 sync_reg; |
| 302 | |
| 303 | mutex_lock(sdw->link_res->shim_lock); |
| 304 | |
| 305 | /* |
| 306 | * The hardware relies on an internal counter, typically 4kHz, |
| 307 | * to generate the SoundWire SSP - which defines a 'safe' |
| 308 | * synchronization point between commands and audio transport |
| 309 | * and allows for multi link synchronization. The SYNCPRD value |
| 310 | * is only dependent on the oscillator clock provided to |
| 311 | * the IP, so adjust based on _DSD properties reported in DSDT |
| 312 | * tables. The values reported are based on either 24MHz |
| 313 | * (CNL/CML) or 38.4 MHz (ICL/TGL+). |
| 314 | */ |
| 315 | if (prop->mclk_freq % 6000000) |
| 316 | syncprd = SDW_SHIM_SYNC_SYNCPRD_VAL_38_4; |
| 317 | else |
| 318 | syncprd = SDW_SHIM_SYNC_SYNCPRD_VAL_24; |
| 319 | |
| 320 | if (!*shim_mask) { |
| 321 | /* we first need to program the SyncPRD/CPU registers */ |
| 322 | dev_dbg(sdw->cdns.dev, |
| 323 | "%s: first link up, programming SYNCPRD\n", __func__); |
| 324 | |
| 325 | /* set SyncPRD period */ |
| 326 | sync_reg = intel_readl(shim, SDW_SHIM_SYNC); |
| 327 | sync_reg |= (syncprd << |
| 328 | SDW_REG_SHIFT(SDW_SHIM_SYNC_SYNCPRD)); |
| 329 | |
| 330 | /* Set SyncCPU bit */ |
| 331 | sync_reg |= SDW_SHIM_SYNC_SYNCCPU; |
| 332 | intel_writel(shim, SDW_SHIM_SYNC, sync_reg); |
| 333 | } |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 334 | |
| 335 | /* Link power up sequence */ |
| 336 | link_control = intel_readl(shim, SDW_SHIM_LCTL); |
| 337 | spa_mask = (SDW_SHIM_LCTL_SPA << link_id); |
| 338 | cpa_mask = (SDW_SHIM_LCTL_CPA << link_id); |
| 339 | link_control |= spa_mask; |
| 340 | |
| 341 | ret = intel_set_bit(shim, SDW_SHIM_LCTL, link_control, cpa_mask); |
Pierre-Louis Bossart | 4a17c44 | 2020-07-16 23:09:40 +0800 | [diff] [blame] | 342 | if (ret < 0) { |
| 343 | dev_err(sdw->cdns.dev, "Failed to power up link: %d\n", ret); |
| 344 | goto out; |
| 345 | } |
| 346 | |
| 347 | if (!*shim_mask) { |
| 348 | /* SyncCPU will change once link is active */ |
| 349 | ret = intel_wait_bit(shim, SDW_SHIM_SYNC, |
| 350 | SDW_SHIM_SYNC_SYNCCPU, 0); |
| 351 | if (ret < 0) { |
| 352 | dev_err(sdw->cdns.dev, |
| 353 | "Failed to set SHIM_SYNC: %d\n", ret); |
| 354 | goto out; |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | *shim_mask |= BIT(link_id); |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 359 | |
| 360 | sdw->cdns.link_up = true; |
Pierre-Louis Bossart | 4a17c44 | 2020-07-16 23:09:40 +0800 | [diff] [blame] | 361 | out: |
| 362 | mutex_unlock(sdw->link_res->shim_lock); |
| 363 | |
| 364 | return ret; |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 365 | } |
| 366 | |
Pierre-Louis Bossart | 4a17c44 | 2020-07-16 23:09:40 +0800 | [diff] [blame] | 367 | /* this needs to be called with shim_lock */ |
| 368 | static void intel_shim_glue_to_master_ip(struct sdw_intel *sdw) |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 369 | { |
Pierre-Louis Bossart | 2523486 | 2020-02-14 19:47:36 -0600 | [diff] [blame] | 370 | void __iomem *shim = sdw->link_res->shim; |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 371 | unsigned int link_id = sdw->instance; |
Pierre-Louis Bossart | 4a17c44 | 2020-07-16 23:09:40 +0800 | [diff] [blame] | 372 | u16 ioctl; |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 373 | |
| 374 | /* Switch to MIP from Glue logic */ |
| 375 | ioctl = intel_readw(shim, SDW_SHIM_IOCTL(link_id)); |
| 376 | |
| 377 | ioctl &= ~(SDW_SHIM_IOCTL_DOE); |
| 378 | intel_writew(shim, SDW_SHIM_IOCTL(link_id), ioctl); |
Pierre-Louis Bossart | 4a17c44 | 2020-07-16 23:09:40 +0800 | [diff] [blame] | 379 | usleep_range(10, 15); |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 380 | |
| 381 | ioctl &= ~(SDW_SHIM_IOCTL_DO); |
| 382 | intel_writew(shim, SDW_SHIM_IOCTL(link_id), ioctl); |
Pierre-Louis Bossart | 4a17c44 | 2020-07-16 23:09:40 +0800 | [diff] [blame] | 383 | usleep_range(10, 15); |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 384 | |
| 385 | ioctl |= (SDW_SHIM_IOCTL_MIF); |
| 386 | intel_writew(shim, SDW_SHIM_IOCTL(link_id), ioctl); |
Pierre-Louis Bossart | 4a17c44 | 2020-07-16 23:09:40 +0800 | [diff] [blame] | 387 | usleep_range(10, 15); |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 388 | |
| 389 | ioctl &= ~(SDW_SHIM_IOCTL_BKE); |
| 390 | ioctl &= ~(SDW_SHIM_IOCTL_COE); |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 391 | intel_writew(shim, SDW_SHIM_IOCTL(link_id), ioctl); |
Pierre-Louis Bossart | 4a17c44 | 2020-07-16 23:09:40 +0800 | [diff] [blame] | 392 | usleep_range(10, 15); |
| 393 | |
| 394 | /* at this point Master IP has full control of the I/Os */ |
| 395 | } |
| 396 | |
| 397 | /* this needs to be called with shim_lock */ |
| 398 | static void intel_shim_master_ip_to_glue(struct sdw_intel *sdw) |
| 399 | { |
| 400 | unsigned int link_id = sdw->instance; |
| 401 | void __iomem *shim = sdw->link_res->shim; |
| 402 | u16 ioctl; |
| 403 | |
| 404 | /* Glue logic */ |
| 405 | ioctl = intel_readw(shim, SDW_SHIM_IOCTL(link_id)); |
| 406 | ioctl |= SDW_SHIM_IOCTL_BKE; |
| 407 | ioctl |= SDW_SHIM_IOCTL_COE; |
| 408 | intel_writew(shim, SDW_SHIM_IOCTL(link_id), ioctl); |
| 409 | usleep_range(10, 15); |
| 410 | |
| 411 | ioctl &= ~(SDW_SHIM_IOCTL_MIF); |
| 412 | intel_writew(shim, SDW_SHIM_IOCTL(link_id), ioctl); |
| 413 | usleep_range(10, 15); |
| 414 | |
| 415 | /* at this point Integration Glue has full control of the I/Os */ |
| 416 | } |
| 417 | |
| 418 | static int intel_shim_init(struct sdw_intel *sdw, bool clock_stop) |
| 419 | { |
| 420 | void __iomem *shim = sdw->link_res->shim; |
| 421 | unsigned int link_id = sdw->instance; |
| 422 | int ret = 0; |
| 423 | u16 ioctl = 0, act = 0; |
| 424 | |
| 425 | mutex_lock(sdw->link_res->shim_lock); |
| 426 | |
| 427 | /* Initialize Shim */ |
| 428 | ioctl |= SDW_SHIM_IOCTL_BKE; |
| 429 | intel_writew(shim, SDW_SHIM_IOCTL(link_id), ioctl); |
| 430 | usleep_range(10, 15); |
| 431 | |
| 432 | ioctl |= SDW_SHIM_IOCTL_WPDD; |
| 433 | intel_writew(shim, SDW_SHIM_IOCTL(link_id), ioctl); |
| 434 | usleep_range(10, 15); |
| 435 | |
| 436 | ioctl |= SDW_SHIM_IOCTL_DO; |
| 437 | intel_writew(shim, SDW_SHIM_IOCTL(link_id), ioctl); |
| 438 | usleep_range(10, 15); |
| 439 | |
| 440 | ioctl |= SDW_SHIM_IOCTL_DOE; |
| 441 | intel_writew(shim, SDW_SHIM_IOCTL(link_id), ioctl); |
| 442 | usleep_range(10, 15); |
| 443 | |
| 444 | intel_shim_glue_to_master_ip(sdw); |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 445 | |
| 446 | act |= 0x1 << SDW_REG_SHIFT(SDW_SHIM_CTMCTL_DOAIS); |
| 447 | act |= SDW_SHIM_CTMCTL_DACTQE; |
| 448 | act |= SDW_SHIM_CTMCTL_DODS; |
| 449 | intel_writew(shim, SDW_SHIM_CTMCTL(link_id), act); |
Pierre-Louis Bossart | 4a17c44 | 2020-07-16 23:09:40 +0800 | [diff] [blame] | 450 | usleep_range(10, 15); |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 451 | |
Pierre-Louis Bossart | 4a17c44 | 2020-07-16 23:09:40 +0800 | [diff] [blame] | 452 | mutex_unlock(sdw->link_res->shim_lock); |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 453 | |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 454 | return ret; |
| 455 | } |
| 456 | |
Rander Wang | ab2c913 | 2020-07-16 23:09:46 +0800 | [diff] [blame] | 457 | static void intel_shim_wake(struct sdw_intel *sdw, bool wake_enable) |
Pierre-Louis Bossart | 4a17c44 | 2020-07-16 23:09:40 +0800 | [diff] [blame] | 458 | { |
| 459 | void __iomem *shim = sdw->link_res->shim; |
| 460 | unsigned int link_id = sdw->instance; |
| 461 | u16 wake_en, wake_sts; |
| 462 | |
| 463 | mutex_lock(sdw->link_res->shim_lock); |
| 464 | wake_en = intel_readw(shim, SDW_SHIM_WAKEEN); |
| 465 | |
| 466 | if (wake_enable) { |
| 467 | /* Enable the wakeup */ |
| 468 | wake_en |= (SDW_SHIM_WAKEEN_ENABLE << link_id); |
| 469 | intel_writew(shim, SDW_SHIM_WAKEEN, wake_en); |
| 470 | } else { |
| 471 | /* Disable the wake up interrupt */ |
| 472 | wake_en &= ~(SDW_SHIM_WAKEEN_ENABLE << link_id); |
| 473 | intel_writew(shim, SDW_SHIM_WAKEEN, wake_en); |
| 474 | |
| 475 | /* Clear wake status */ |
| 476 | wake_sts = intel_readw(shim, SDW_SHIM_WAKESTS); |
| 477 | wake_sts |= (SDW_SHIM_WAKEEN_ENABLE << link_id); |
| 478 | intel_writew(shim, SDW_SHIM_WAKESTS_STATUS, wake_sts); |
| 479 | } |
| 480 | mutex_unlock(sdw->link_res->shim_lock); |
| 481 | } |
| 482 | |
Pierre-Louis Bossart | 9b3b4b3 | 2020-07-22 04:37:11 +0800 | [diff] [blame] | 483 | static int intel_link_power_down(struct sdw_intel *sdw) |
Pierre-Louis Bossart | 4a17c44 | 2020-07-16 23:09:40 +0800 | [diff] [blame] | 484 | { |
| 485 | int link_control, spa_mask, cpa_mask; |
| 486 | unsigned int link_id = sdw->instance; |
| 487 | void __iomem *shim = sdw->link_res->shim; |
| 488 | u32 *shim_mask = sdw->link_res->shim_mask; |
| 489 | int ret = 0; |
| 490 | |
| 491 | mutex_lock(sdw->link_res->shim_lock); |
| 492 | |
| 493 | intel_shim_master_ip_to_glue(sdw); |
| 494 | |
| 495 | /* Link power down sequence */ |
| 496 | link_control = intel_readl(shim, SDW_SHIM_LCTL); |
| 497 | spa_mask = ~(SDW_SHIM_LCTL_SPA << link_id); |
| 498 | cpa_mask = (SDW_SHIM_LCTL_CPA << link_id); |
| 499 | link_control &= spa_mask; |
| 500 | |
| 501 | ret = intel_clear_bit(shim, SDW_SHIM_LCTL, link_control, cpa_mask); |
| 502 | |
| 503 | if (!(*shim_mask & BIT(link_id))) |
| 504 | dev_err(sdw->cdns.dev, |
| 505 | "%s: Unbalanced power-up/down calls\n", __func__); |
| 506 | |
| 507 | *shim_mask &= ~BIT(link_id); |
| 508 | |
| 509 | mutex_unlock(sdw->link_res->shim_lock); |
| 510 | |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 511 | if (ret < 0) |
Pierre-Louis Bossart | 4a17c44 | 2020-07-16 23:09:40 +0800 | [diff] [blame] | 512 | return ret; |
| 513 | |
| 514 | sdw->cdns.link_up = false; |
| 515 | return 0; |
| 516 | } |
| 517 | |
Pierre-Louis Bossart | 02629e45 | 2020-07-16 23:09:41 +0800 | [diff] [blame] | 518 | static void intel_shim_sync_arm(struct sdw_intel *sdw) |
| 519 | { |
| 520 | void __iomem *shim = sdw->link_res->shim; |
| 521 | u32 sync_reg; |
| 522 | |
| 523 | mutex_lock(sdw->link_res->shim_lock); |
| 524 | |
| 525 | /* update SYNC register */ |
| 526 | sync_reg = intel_readl(shim, SDW_SHIM_SYNC); |
| 527 | sync_reg |= (SDW_SHIM_SYNC_CMDSYNC << sdw->instance); |
| 528 | intel_writel(shim, SDW_SHIM_SYNC, sync_reg); |
| 529 | |
| 530 | mutex_unlock(sdw->link_res->shim_lock); |
| 531 | } |
| 532 | |
Pierre-Louis Bossart | 437e328 | 2020-07-16 23:09:42 +0800 | [diff] [blame] | 533 | static int intel_shim_sync_go_unlocked(struct sdw_intel *sdw) |
| 534 | { |
| 535 | void __iomem *shim = sdw->link_res->shim; |
| 536 | u32 sync_reg; |
| 537 | int ret; |
| 538 | |
| 539 | /* Read SYNC register */ |
| 540 | sync_reg = intel_readl(shim, SDW_SHIM_SYNC); |
| 541 | |
| 542 | /* |
| 543 | * Set SyncGO bit to synchronously trigger a bank switch for |
| 544 | * all the masters. A write to SYNCGO bit clears CMDSYNC bit for all |
| 545 | * the Masters. |
| 546 | */ |
| 547 | sync_reg |= SDW_SHIM_SYNC_SYNCGO; |
| 548 | |
| 549 | ret = intel_clear_bit(shim, SDW_SHIM_SYNC, sync_reg, |
| 550 | SDW_SHIM_SYNC_SYNCGO); |
| 551 | |
| 552 | if (ret < 0) |
| 553 | dev_err(sdw->cdns.dev, "SyncGO clear failed: %d\n", ret); |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 554 | |
| 555 | return ret; |
| 556 | } |
| 557 | |
Vinod Koul | 37a2d22 | 2018-04-26 18:38:58 +0530 | [diff] [blame] | 558 | /* |
| 559 | * PDI routines |
| 560 | */ |
| 561 | static void intel_pdi_init(struct sdw_intel *sdw, |
Pierre-Louis Bossart | d542bc9 | 2019-05-01 10:57:38 -0500 | [diff] [blame] | 562 | struct sdw_cdns_stream_config *config) |
Vinod Koul | 37a2d22 | 2018-04-26 18:38:58 +0530 | [diff] [blame] | 563 | { |
Pierre-Louis Bossart | 2523486 | 2020-02-14 19:47:36 -0600 | [diff] [blame] | 564 | void __iomem *shim = sdw->link_res->shim; |
Vinod Koul | 37a2d22 | 2018-04-26 18:38:58 +0530 | [diff] [blame] | 565 | unsigned int link_id = sdw->instance; |
| 566 | int pcm_cap, pdm_cap; |
| 567 | |
| 568 | /* PCM Stream Capability */ |
| 569 | pcm_cap = intel_readw(shim, SDW_SHIM_PCMSCAP(link_id)); |
| 570 | |
| 571 | config->pcm_bd = (pcm_cap & SDW_SHIM_PCMSCAP_BSS) >> |
| 572 | SDW_REG_SHIFT(SDW_SHIM_PCMSCAP_BSS); |
| 573 | config->pcm_in = (pcm_cap & SDW_SHIM_PCMSCAP_ISS) >> |
| 574 | SDW_REG_SHIFT(SDW_SHIM_PCMSCAP_ISS); |
| 575 | config->pcm_out = (pcm_cap & SDW_SHIM_PCMSCAP_OSS) >> |
| 576 | SDW_REG_SHIFT(SDW_SHIM_PCMSCAP_OSS); |
| 577 | |
Pierre-Louis Bossart | 121f436 | 2019-05-22 14:47:29 -0500 | [diff] [blame] | 578 | dev_dbg(sdw->cdns.dev, "PCM cap bd:%d in:%d out:%d\n", |
| 579 | config->pcm_bd, config->pcm_in, config->pcm_out); |
| 580 | |
Vinod Koul | 37a2d22 | 2018-04-26 18:38:58 +0530 | [diff] [blame] | 581 | /* PDM Stream Capability */ |
| 582 | pdm_cap = intel_readw(shim, SDW_SHIM_PDMSCAP(link_id)); |
| 583 | |
| 584 | config->pdm_bd = (pdm_cap & SDW_SHIM_PDMSCAP_BSS) >> |
| 585 | SDW_REG_SHIFT(SDW_SHIM_PDMSCAP_BSS); |
| 586 | config->pdm_in = (pdm_cap & SDW_SHIM_PDMSCAP_ISS) >> |
| 587 | SDW_REG_SHIFT(SDW_SHIM_PDMSCAP_ISS); |
| 588 | config->pdm_out = (pdm_cap & SDW_SHIM_PDMSCAP_OSS) >> |
| 589 | SDW_REG_SHIFT(SDW_SHIM_PDMSCAP_OSS); |
Pierre-Louis Bossart | 121f436 | 2019-05-22 14:47:29 -0500 | [diff] [blame] | 590 | |
| 591 | dev_dbg(sdw->cdns.dev, "PDM cap bd:%d in:%d out:%d\n", |
| 592 | config->pdm_bd, config->pdm_in, config->pdm_out); |
Vinod Koul | 37a2d22 | 2018-04-26 18:38:58 +0530 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | static int |
| 596 | intel_pdi_get_ch_cap(struct sdw_intel *sdw, unsigned int pdi_num, bool pcm) |
| 597 | { |
Pierre-Louis Bossart | 2523486 | 2020-02-14 19:47:36 -0600 | [diff] [blame] | 598 | void __iomem *shim = sdw->link_res->shim; |
Vinod Koul | 37a2d22 | 2018-04-26 18:38:58 +0530 | [diff] [blame] | 599 | unsigned int link_id = sdw->instance; |
| 600 | int count; |
| 601 | |
| 602 | if (pcm) { |
| 603 | count = intel_readw(shim, SDW_SHIM_PCMSYCHC(link_id, pdi_num)); |
Pierre-Louis Bossart | 1804633 | 2019-08-05 19:55:07 -0500 | [diff] [blame] | 604 | |
| 605 | /* |
| 606 | * WORKAROUND: on all existing Intel controllers, pdi |
| 607 | * number 2 reports channel count as 1 even though it |
| 608 | * supports 8 channels. Performing hardcoding for pdi |
| 609 | * number 2. |
| 610 | */ |
| 611 | if (pdi_num == 2) |
| 612 | count = 7; |
| 613 | |
Vinod Koul | 37a2d22 | 2018-04-26 18:38:58 +0530 | [diff] [blame] | 614 | } else { |
| 615 | count = intel_readw(shim, SDW_SHIM_PDMSCAP(link_id)); |
| 616 | count = ((count & SDW_SHIM_PDMSCAP_CPSS) >> |
| 617 | SDW_REG_SHIFT(SDW_SHIM_PDMSCAP_CPSS)); |
| 618 | } |
| 619 | |
| 620 | /* zero based values for channel count in register */ |
| 621 | count++; |
| 622 | |
| 623 | return count; |
| 624 | } |
| 625 | |
| 626 | static int intel_pdi_get_ch_update(struct sdw_intel *sdw, |
Pierre-Louis Bossart | d542bc9 | 2019-05-01 10:57:38 -0500 | [diff] [blame] | 627 | struct sdw_cdns_pdi *pdi, |
| 628 | unsigned int num_pdi, |
| 629 | unsigned int *num_ch, bool pcm) |
Vinod Koul | 37a2d22 | 2018-04-26 18:38:58 +0530 | [diff] [blame] | 630 | { |
| 631 | int i, ch_count = 0; |
| 632 | |
| 633 | for (i = 0; i < num_pdi; i++) { |
| 634 | pdi->ch_count = intel_pdi_get_ch_cap(sdw, pdi->num, pcm); |
| 635 | ch_count += pdi->ch_count; |
| 636 | pdi++; |
| 637 | } |
| 638 | |
| 639 | *num_ch = ch_count; |
| 640 | return 0; |
| 641 | } |
| 642 | |
| 643 | static int intel_pdi_stream_ch_update(struct sdw_intel *sdw, |
Pierre-Louis Bossart | d542bc9 | 2019-05-01 10:57:38 -0500 | [diff] [blame] | 644 | struct sdw_cdns_streams *stream, bool pcm) |
Vinod Koul | 37a2d22 | 2018-04-26 18:38:58 +0530 | [diff] [blame] | 645 | { |
| 646 | intel_pdi_get_ch_update(sdw, stream->bd, stream->num_bd, |
Pierre-Louis Bossart | d542bc9 | 2019-05-01 10:57:38 -0500 | [diff] [blame] | 647 | &stream->num_ch_bd, pcm); |
Vinod Koul | 37a2d22 | 2018-04-26 18:38:58 +0530 | [diff] [blame] | 648 | |
| 649 | intel_pdi_get_ch_update(sdw, stream->in, stream->num_in, |
Pierre-Louis Bossart | d542bc9 | 2019-05-01 10:57:38 -0500 | [diff] [blame] | 650 | &stream->num_ch_in, pcm); |
Vinod Koul | 37a2d22 | 2018-04-26 18:38:58 +0530 | [diff] [blame] | 651 | |
| 652 | intel_pdi_get_ch_update(sdw, stream->out, stream->num_out, |
Pierre-Louis Bossart | d542bc9 | 2019-05-01 10:57:38 -0500 | [diff] [blame] | 653 | &stream->num_ch_out, pcm); |
Vinod Koul | 37a2d22 | 2018-04-26 18:38:58 +0530 | [diff] [blame] | 654 | |
| 655 | return 0; |
| 656 | } |
| 657 | |
| 658 | static int intel_pdi_ch_update(struct sdw_intel *sdw) |
| 659 | { |
| 660 | /* First update PCM streams followed by PDM streams */ |
| 661 | intel_pdi_stream_ch_update(sdw, &sdw->cdns.pcm, true); |
| 662 | intel_pdi_stream_ch_update(sdw, &sdw->cdns.pdm, false); |
| 663 | |
| 664 | return 0; |
| 665 | } |
| 666 | |
| 667 | static void |
| 668 | intel_pdi_shim_configure(struct sdw_intel *sdw, struct sdw_cdns_pdi *pdi) |
| 669 | { |
Pierre-Louis Bossart | 2523486 | 2020-02-14 19:47:36 -0600 | [diff] [blame] | 670 | void __iomem *shim = sdw->link_res->shim; |
Vinod Koul | 37a2d22 | 2018-04-26 18:38:58 +0530 | [diff] [blame] | 671 | unsigned int link_id = sdw->instance; |
| 672 | int pdi_conf = 0; |
| 673 | |
Pierre-Louis Bossart | c134f91 | 2019-10-22 18:29:48 -0500 | [diff] [blame] | 674 | /* the Bulk and PCM streams are not contiguous */ |
| 675 | pdi->intel_alh_id = (link_id * 16) + pdi->num + 3; |
| 676 | if (pdi->num >= 2) |
| 677 | pdi->intel_alh_id += 2; |
Vinod Koul | 37a2d22 | 2018-04-26 18:38:58 +0530 | [diff] [blame] | 678 | |
| 679 | /* |
| 680 | * Program stream parameters to stream SHIM register |
| 681 | * This is applicable for PCM stream only. |
| 682 | */ |
| 683 | if (pdi->type != SDW_STREAM_PCM) |
| 684 | return; |
| 685 | |
| 686 | if (pdi->dir == SDW_DATA_DIR_RX) |
| 687 | pdi_conf |= SDW_SHIM_PCMSYCM_DIR; |
| 688 | else |
| 689 | pdi_conf &= ~(SDW_SHIM_PCMSYCM_DIR); |
| 690 | |
| 691 | pdi_conf |= (pdi->intel_alh_id << |
| 692 | SDW_REG_SHIFT(SDW_SHIM_PCMSYCM_STREAM)); |
| 693 | pdi_conf |= (pdi->l_ch_num << SDW_REG_SHIFT(SDW_SHIM_PCMSYCM_LCHN)); |
| 694 | pdi_conf |= (pdi->h_ch_num << SDW_REG_SHIFT(SDW_SHIM_PCMSYCM_HCHN)); |
| 695 | |
| 696 | intel_writew(shim, SDW_SHIM_PCMSYCHM(link_id, pdi->num), pdi_conf); |
| 697 | } |
| 698 | |
| 699 | static void |
| 700 | intel_pdi_alh_configure(struct sdw_intel *sdw, struct sdw_cdns_pdi *pdi) |
| 701 | { |
Pierre-Louis Bossart | 2523486 | 2020-02-14 19:47:36 -0600 | [diff] [blame] | 702 | void __iomem *alh = sdw->link_res->alh; |
Vinod Koul | 37a2d22 | 2018-04-26 18:38:58 +0530 | [diff] [blame] | 703 | unsigned int link_id = sdw->instance; |
| 704 | unsigned int conf; |
| 705 | |
Pierre-Louis Bossart | c134f91 | 2019-10-22 18:29:48 -0500 | [diff] [blame] | 706 | /* the Bulk and PCM streams are not contiguous */ |
| 707 | pdi->intel_alh_id = (link_id * 16) + pdi->num + 3; |
| 708 | if (pdi->num >= 2) |
| 709 | pdi->intel_alh_id += 2; |
Vinod Koul | 37a2d22 | 2018-04-26 18:38:58 +0530 | [diff] [blame] | 710 | |
| 711 | /* Program Stream config ALH register */ |
| 712 | conf = intel_readl(alh, SDW_ALH_STRMZCFG(pdi->intel_alh_id)); |
| 713 | |
| 714 | conf |= (SDW_ALH_STRMZCFG_DMAT_VAL << |
| 715 | SDW_REG_SHIFT(SDW_ALH_STRMZCFG_DMAT)); |
| 716 | |
| 717 | conf |= ((pdi->ch_count - 1) << |
| 718 | SDW_REG_SHIFT(SDW_ALH_STRMZCFG_CHN)); |
| 719 | |
| 720 | intel_writel(alh, SDW_ALH_STRMZCFG(pdi->intel_alh_id), conf); |
| 721 | } |
| 722 | |
Rander Wang | 4b206d3 | 2019-12-11 19:45:02 -0600 | [diff] [blame] | 723 | static int intel_params_stream(struct sdw_intel *sdw, |
Pierre-Louis Bossart | d542bc9 | 2019-05-01 10:57:38 -0500 | [diff] [blame] | 724 | struct snd_pcm_substream *substream, |
| 725 | struct snd_soc_dai *dai, |
Rander Wang | 4b206d3 | 2019-12-11 19:45:02 -0600 | [diff] [blame] | 726 | struct snd_pcm_hw_params *hw_params, |
| 727 | int link_id, int alh_stream_id) |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 728 | { |
Pierre-Louis Bossart | 2523486 | 2020-02-14 19:47:36 -0600 | [diff] [blame] | 729 | struct sdw_intel_link_res *res = sdw->link_res; |
Rander Wang | 4b206d3 | 2019-12-11 19:45:02 -0600 | [diff] [blame] | 730 | struct sdw_intel_stream_params_data params_data; |
Pierre-Louis Bossart | 05c8afe4 | 2019-08-05 19:55:06 -0500 | [diff] [blame] | 731 | |
Rander Wang | 4b206d3 | 2019-12-11 19:45:02 -0600 | [diff] [blame] | 732 | params_data.substream = substream; |
| 733 | params_data.dai = dai; |
| 734 | params_data.hw_params = hw_params; |
| 735 | params_data.link_id = link_id; |
| 736 | params_data.alh_stream_id = alh_stream_id; |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 737 | |
Rander Wang | 4b206d3 | 2019-12-11 19:45:02 -0600 | [diff] [blame] | 738 | if (res->ops && res->ops->params_stream && res->dev) |
| 739 | return res->ops->params_stream(res->dev, |
| 740 | ¶ms_data); |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 741 | return -EIO; |
| 742 | } |
| 743 | |
Pierre-Louis Bossart | eff346f | 2020-02-14 19:47:40 -0600 | [diff] [blame] | 744 | static int intel_free_stream(struct sdw_intel *sdw, |
| 745 | struct snd_pcm_substream *substream, |
| 746 | struct snd_soc_dai *dai, |
| 747 | int link_id) |
| 748 | { |
| 749 | struct sdw_intel_link_res *res = sdw->link_res; |
| 750 | struct sdw_intel_stream_free_data free_data; |
| 751 | |
| 752 | free_data.substream = substream; |
| 753 | free_data.dai = dai; |
| 754 | free_data.link_id = link_id; |
| 755 | |
| 756 | if (res->ops && res->ops->free_stream && res->dev) |
| 757 | return res->ops->free_stream(res->dev, |
| 758 | &free_data); |
| 759 | |
| 760 | return 0; |
| 761 | } |
| 762 | |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 763 | /* |
Shreyas NC | 30246e2 | 2018-07-27 14:44:17 +0530 | [diff] [blame] | 764 | * bank switch routines |
| 765 | */ |
| 766 | |
| 767 | static int intel_pre_bank_switch(struct sdw_bus *bus) |
| 768 | { |
| 769 | struct sdw_cdns *cdns = bus_to_cdns(bus); |
| 770 | struct sdw_intel *sdw = cdns_to_intel(cdns); |
Shreyas NC | 30246e2 | 2018-07-27 14:44:17 +0530 | [diff] [blame] | 771 | |
| 772 | /* Write to register only for multi-link */ |
| 773 | if (!bus->multi_link) |
| 774 | return 0; |
| 775 | |
Pierre-Louis Bossart | 02629e45 | 2020-07-16 23:09:41 +0800 | [diff] [blame] | 776 | intel_shim_sync_arm(sdw); |
Shreyas NC | 30246e2 | 2018-07-27 14:44:17 +0530 | [diff] [blame] | 777 | |
| 778 | return 0; |
| 779 | } |
| 780 | |
| 781 | static int intel_post_bank_switch(struct sdw_bus *bus) |
| 782 | { |
| 783 | struct sdw_cdns *cdns = bus_to_cdns(bus); |
| 784 | struct sdw_intel *sdw = cdns_to_intel(cdns); |
Pierre-Louis Bossart | 2523486 | 2020-02-14 19:47:36 -0600 | [diff] [blame] | 785 | void __iomem *shim = sdw->link_res->shim; |
Shreyas NC | 30246e2 | 2018-07-27 14:44:17 +0530 | [diff] [blame] | 786 | int sync_reg, ret; |
| 787 | |
| 788 | /* Write to register only for multi-link */ |
| 789 | if (!bus->multi_link) |
| 790 | return 0; |
| 791 | |
Pierre-Louis Bossart | 4a17c44 | 2020-07-16 23:09:40 +0800 | [diff] [blame] | 792 | mutex_lock(sdw->link_res->shim_lock); |
| 793 | |
Shreyas NC | 30246e2 | 2018-07-27 14:44:17 +0530 | [diff] [blame] | 794 | /* Read SYNC register */ |
| 795 | sync_reg = intel_readl(shim, SDW_SHIM_SYNC); |
| 796 | |
| 797 | /* |
| 798 | * post_bank_switch() ops is called from the bus in loop for |
| 799 | * all the Masters in the steam with the expectation that |
| 800 | * we trigger the bankswitch for the only first Master in the list |
| 801 | * and do nothing for the other Masters |
| 802 | * |
| 803 | * So, set the SYNCGO bit only if CMDSYNC bit is set for any Master. |
| 804 | */ |
Pierre-Louis Bossart | 4a17c44 | 2020-07-16 23:09:40 +0800 | [diff] [blame] | 805 | if (!(sync_reg & SDW_SHIM_SYNC_CMDSYNC_MASK)) { |
| 806 | ret = 0; |
| 807 | goto unlock; |
| 808 | } |
Shreyas NC | 30246e2 | 2018-07-27 14:44:17 +0530 | [diff] [blame] | 809 | |
Pierre-Louis Bossart | 437e328 | 2020-07-16 23:09:42 +0800 | [diff] [blame] | 810 | ret = intel_shim_sync_go_unlocked(sdw); |
Pierre-Louis Bossart | 4a17c44 | 2020-07-16 23:09:40 +0800 | [diff] [blame] | 811 | unlock: |
| 812 | mutex_unlock(sdw->link_res->shim_lock); |
Shreyas NC | 30246e2 | 2018-07-27 14:44:17 +0530 | [diff] [blame] | 813 | |
Shreyas NC | 30246e2 | 2018-07-27 14:44:17 +0530 | [diff] [blame] | 814 | if (ret < 0) |
Pierre-Louis Bossart | 17ed5be | 2019-05-01 10:57:45 -0500 | [diff] [blame] | 815 | dev_err(sdw->cdns.dev, "Post bank switch failed: %d\n", ret); |
Shreyas NC | 30246e2 | 2018-07-27 14:44:17 +0530 | [diff] [blame] | 816 | |
| 817 | return ret; |
| 818 | } |
| 819 | |
| 820 | /* |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 821 | * DAI routines |
| 822 | */ |
| 823 | |
Rander Wang | 5e7484d | 2020-02-14 19:47:39 -0600 | [diff] [blame] | 824 | static int intel_startup(struct snd_pcm_substream *substream, |
| 825 | struct snd_soc_dai *dai) |
| 826 | { |
Pierre-Louis Bossart | ebf878e | 2020-08-17 23:29:12 +0800 | [diff] [blame] | 827 | struct sdw_cdns *cdns = snd_soc_dai_get_drvdata(dai); |
| 828 | int ret; |
| 829 | |
| 830 | ret = pm_runtime_get_sync(cdns->dev); |
| 831 | if (ret < 0 && ret != -EACCES) { |
| 832 | dev_err_ratelimited(cdns->dev, |
| 833 | "pm_runtime_get_sync failed in %s, ret %d\n", |
| 834 | __func__, ret); |
| 835 | pm_runtime_put_noidle(cdns->dev); |
| 836 | return ret; |
| 837 | } |
Pierre-Louis Bossart | ff16d1e | 2020-07-01 02:43:54 +0800 | [diff] [blame] | 838 | return 0; |
Rander Wang | 5e7484d | 2020-02-14 19:47:39 -0600 | [diff] [blame] | 839 | } |
| 840 | |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 841 | static int intel_hw_params(struct snd_pcm_substream *substream, |
Pierre-Louis Bossart | d542bc9 | 2019-05-01 10:57:38 -0500 | [diff] [blame] | 842 | struct snd_pcm_hw_params *params, |
| 843 | struct snd_soc_dai *dai) |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 844 | { |
| 845 | struct sdw_cdns *cdns = snd_soc_dai_get_drvdata(dai); |
| 846 | struct sdw_intel *sdw = cdns_to_intel(cdns); |
| 847 | struct sdw_cdns_dma_data *dma; |
Pierre-Louis Bossart | 57a3479 | 2019-09-16 14:23:46 -0500 | [diff] [blame] | 848 | struct sdw_cdns_pdi *pdi; |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 849 | struct sdw_stream_config sconfig; |
| 850 | struct sdw_port_config *pconfig; |
Pierre-Louis Bossart | 57a3479 | 2019-09-16 14:23:46 -0500 | [diff] [blame] | 851 | int ch, dir; |
| 852 | int ret; |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 853 | bool pcm = true; |
| 854 | |
| 855 | dma = snd_soc_dai_get_dma_data(dai, substream); |
| 856 | if (!dma) |
| 857 | return -EIO; |
| 858 | |
| 859 | ch = params_channels(params); |
| 860 | if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) |
| 861 | dir = SDW_DATA_DIR_RX; |
| 862 | else |
| 863 | dir = SDW_DATA_DIR_TX; |
| 864 | |
Pierre-Louis Bossart | 57a3479 | 2019-09-16 14:23:46 -0500 | [diff] [blame] | 865 | if (dma->stream_type == SDW_STREAM_PDM) |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 866 | pcm = false; |
Pierre-Louis Bossart | 57a3479 | 2019-09-16 14:23:46 -0500 | [diff] [blame] | 867 | |
Pierre-Louis Bossart | 57a3479 | 2019-09-16 14:23:46 -0500 | [diff] [blame] | 868 | if (pcm) |
Bard Liao | 1b53385e | 2019-09-16 14:23:48 -0500 | [diff] [blame] | 869 | pdi = sdw_cdns_alloc_pdi(cdns, &cdns->pcm, ch, dir, dai->id); |
Pierre-Louis Bossart | 57a3479 | 2019-09-16 14:23:46 -0500 | [diff] [blame] | 870 | else |
Bard Liao | 1b53385e | 2019-09-16 14:23:48 -0500 | [diff] [blame] | 871 | pdi = sdw_cdns_alloc_pdi(cdns, &cdns->pdm, ch, dir, dai->id); |
Pierre-Louis Bossart | 57a3479 | 2019-09-16 14:23:46 -0500 | [diff] [blame] | 872 | |
| 873 | if (!pdi) { |
| 874 | ret = -EINVAL; |
| 875 | goto error; |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 876 | } |
| 877 | |
Pierre-Louis Bossart | 57a3479 | 2019-09-16 14:23:46 -0500 | [diff] [blame] | 878 | /* do run-time configurations for SHIM, ALH and PDI/PORT */ |
| 879 | intel_pdi_shim_configure(sdw, pdi); |
| 880 | intel_pdi_alh_configure(sdw, pdi); |
| 881 | sdw_cdns_config_stream(cdns, ch, dir, pdi); |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 882 | |
Bard Liao | a5a0239 | 2020-08-17 23:29:16 +0800 | [diff] [blame] | 883 | /* store pdi and hw_params, may be needed in prepare step */ |
| 884 | dma->suspended = false; |
| 885 | dma->pdi = pdi; |
| 886 | dma->hw_params = params; |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 887 | |
| 888 | /* Inform DSP about PDI stream number */ |
Rander Wang | 4b206d3 | 2019-12-11 19:45:02 -0600 | [diff] [blame] | 889 | ret = intel_params_stream(sdw, substream, dai, params, |
| 890 | sdw->instance, |
Pierre-Louis Bossart | 57a3479 | 2019-09-16 14:23:46 -0500 | [diff] [blame] | 891 | pdi->intel_alh_id); |
| 892 | if (ret) |
| 893 | goto error; |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 894 | |
| 895 | sconfig.direction = dir; |
| 896 | sconfig.ch_count = ch; |
| 897 | sconfig.frame_rate = params_rate(params); |
| 898 | sconfig.type = dma->stream_type; |
| 899 | |
| 900 | if (dma->stream_type == SDW_STREAM_PDM) { |
| 901 | sconfig.frame_rate *= 50; |
| 902 | sconfig.bps = 1; |
| 903 | } else { |
| 904 | sconfig.bps = snd_pcm_format_width(params_format(params)); |
| 905 | } |
| 906 | |
| 907 | /* Port configuration */ |
Pierre-Louis Bossart | 57a3479 | 2019-09-16 14:23:46 -0500 | [diff] [blame] | 908 | pconfig = kcalloc(1, sizeof(*pconfig), GFP_KERNEL); |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 909 | if (!pconfig) { |
| 910 | ret = -ENOMEM; |
Pierre-Louis Bossart | 57a3479 | 2019-09-16 14:23:46 -0500 | [diff] [blame] | 911 | goto error; |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 912 | } |
| 913 | |
Pierre-Louis Bossart | 57a3479 | 2019-09-16 14:23:46 -0500 | [diff] [blame] | 914 | pconfig->num = pdi->num; |
| 915 | pconfig->ch_mask = (1 << ch) - 1; |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 916 | |
| 917 | ret = sdw_stream_add_master(&cdns->bus, &sconfig, |
Pierre-Louis Bossart | 57a3479 | 2019-09-16 14:23:46 -0500 | [diff] [blame] | 918 | pconfig, 1, dma->stream); |
| 919 | if (ret) |
Pierre-Louis Bossart | 17ed5be | 2019-05-01 10:57:45 -0500 | [diff] [blame] | 920 | dev_err(cdns->dev, "add master to stream failed:%d\n", ret); |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 921 | |
| 922 | kfree(pconfig); |
Pierre-Louis Bossart | 57a3479 | 2019-09-16 14:23:46 -0500 | [diff] [blame] | 923 | error: |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 924 | return ret; |
| 925 | } |
| 926 | |
Rander Wang | 27b198f | 2020-02-14 19:47:37 -0600 | [diff] [blame] | 927 | static int intel_prepare(struct snd_pcm_substream *substream, |
| 928 | struct snd_soc_dai *dai) |
| 929 | { |
Bard Liao | a5a0239 | 2020-08-17 23:29:16 +0800 | [diff] [blame] | 930 | struct sdw_cdns *cdns = snd_soc_dai_get_drvdata(dai); |
| 931 | struct sdw_intel *sdw = cdns_to_intel(cdns); |
Rander Wang | 27b198f | 2020-02-14 19:47:37 -0600 | [diff] [blame] | 932 | struct sdw_cdns_dma_data *dma; |
Bard Liao | a5a0239 | 2020-08-17 23:29:16 +0800 | [diff] [blame] | 933 | int ch, dir; |
| 934 | int ret; |
Rander Wang | 27b198f | 2020-02-14 19:47:37 -0600 | [diff] [blame] | 935 | |
| 936 | dma = snd_soc_dai_get_dma_data(dai, substream); |
| 937 | if (!dma) { |
| 938 | dev_err(dai->dev, "failed to get dma data in %s", |
| 939 | __func__); |
| 940 | return -EIO; |
| 941 | } |
| 942 | |
Bard Liao | a5a0239 | 2020-08-17 23:29:16 +0800 | [diff] [blame] | 943 | if (dma->suspended) { |
| 944 | dma->suspended = false; |
| 945 | |
| 946 | /* |
| 947 | * .prepare() is called after system resume, where we |
| 948 | * need to reinitialize the SHIM/ALH/Cadence IP. |
| 949 | * .prepare() is also called to deal with underflows, |
| 950 | * but in those cases we cannot touch ALH/SHIM |
| 951 | * registers |
| 952 | */ |
| 953 | |
| 954 | /* configure stream */ |
| 955 | ch = params_channels(dma->hw_params); |
| 956 | if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) |
| 957 | dir = SDW_DATA_DIR_RX; |
| 958 | else |
| 959 | dir = SDW_DATA_DIR_TX; |
| 960 | |
| 961 | intel_pdi_shim_configure(sdw, dma->pdi); |
| 962 | intel_pdi_alh_configure(sdw, dma->pdi); |
| 963 | sdw_cdns_config_stream(cdns, ch, dir, dma->pdi); |
| 964 | |
| 965 | /* Inform DSP about PDI stream number */ |
| 966 | ret = intel_params_stream(sdw, substream, dai, |
| 967 | dma->hw_params, |
| 968 | sdw->instance, |
| 969 | dma->pdi->intel_alh_id); |
| 970 | if (ret) |
| 971 | goto err; |
| 972 | } |
| 973 | |
| 974 | ret = sdw_prepare_stream(dma->stream); |
| 975 | |
| 976 | err: |
| 977 | return ret; |
Rander Wang | 27b198f | 2020-02-14 19:47:37 -0600 | [diff] [blame] | 978 | } |
| 979 | |
Rander Wang | 973a842 | 2020-02-14 19:47:38 -0600 | [diff] [blame] | 980 | static int intel_trigger(struct snd_pcm_substream *substream, int cmd, |
| 981 | struct snd_soc_dai *dai) |
| 982 | { |
| 983 | struct sdw_cdns_dma_data *dma; |
| 984 | int ret; |
| 985 | |
| 986 | dma = snd_soc_dai_get_dma_data(dai, substream); |
| 987 | if (!dma) { |
| 988 | dev_err(dai->dev, "failed to get dma data in %s", __func__); |
| 989 | return -EIO; |
| 990 | } |
| 991 | |
| 992 | switch (cmd) { |
| 993 | case SNDRV_PCM_TRIGGER_START: |
| 994 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 995 | case SNDRV_PCM_TRIGGER_RESUME: |
| 996 | ret = sdw_enable_stream(dma->stream); |
| 997 | break; |
| 998 | |
| 999 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 1000 | case SNDRV_PCM_TRIGGER_SUSPEND: |
| 1001 | case SNDRV_PCM_TRIGGER_STOP: |
| 1002 | ret = sdw_disable_stream(dma->stream); |
| 1003 | break; |
| 1004 | |
| 1005 | default: |
| 1006 | ret = -EINVAL; |
| 1007 | break; |
| 1008 | } |
| 1009 | |
| 1010 | if (ret) |
| 1011 | dev_err(dai->dev, |
| 1012 | "%s trigger %d failed: %d", |
| 1013 | __func__, cmd, ret); |
| 1014 | return ret; |
| 1015 | } |
| 1016 | |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1017 | static int |
| 1018 | intel_hw_free(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) |
| 1019 | { |
| 1020 | struct sdw_cdns *cdns = snd_soc_dai_get_drvdata(dai); |
Pierre-Louis Bossart | eff346f | 2020-02-14 19:47:40 -0600 | [diff] [blame] | 1021 | struct sdw_intel *sdw = cdns_to_intel(cdns); |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1022 | struct sdw_cdns_dma_data *dma; |
| 1023 | int ret; |
| 1024 | |
| 1025 | dma = snd_soc_dai_get_dma_data(dai, substream); |
| 1026 | if (!dma) |
| 1027 | return -EIO; |
| 1028 | |
Pierre-Louis Bossart | eff346f | 2020-02-14 19:47:40 -0600 | [diff] [blame] | 1029 | ret = sdw_deprepare_stream(dma->stream); |
| 1030 | if (ret) { |
| 1031 | dev_err(dai->dev, "sdw_deprepare_stream: failed %d", ret); |
| 1032 | return ret; |
| 1033 | } |
| 1034 | |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1035 | ret = sdw_stream_remove_master(&cdns->bus, dma->stream); |
Pierre-Louis Bossart | eff346f | 2020-02-14 19:47:40 -0600 | [diff] [blame] | 1036 | if (ret < 0) { |
Pierre-Louis Bossart | 17ed5be | 2019-05-01 10:57:45 -0500 | [diff] [blame] | 1037 | dev_err(dai->dev, "remove master from stream %s failed: %d\n", |
Pierre-Louis Bossart | d542bc9 | 2019-05-01 10:57:38 -0500 | [diff] [blame] | 1038 | dma->stream->name, ret); |
Pierre-Louis Bossart | eff346f | 2020-02-14 19:47:40 -0600 | [diff] [blame] | 1039 | return ret; |
| 1040 | } |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1041 | |
Pierre-Louis Bossart | eff346f | 2020-02-14 19:47:40 -0600 | [diff] [blame] | 1042 | ret = intel_free_stream(sdw, substream, dai, sdw->instance); |
| 1043 | if (ret < 0) { |
| 1044 | dev_err(dai->dev, "intel_free_stream: failed %d", ret); |
| 1045 | return ret; |
| 1046 | } |
| 1047 | |
Bard Liao | a5a0239 | 2020-08-17 23:29:16 +0800 | [diff] [blame] | 1048 | dma->hw_params = NULL; |
| 1049 | dma->pdi = NULL; |
| 1050 | |
Pierre-Louis Bossart | eff346f | 2020-02-14 19:47:40 -0600 | [diff] [blame] | 1051 | return 0; |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1052 | } |
| 1053 | |
Pierre-Louis Bossart | 183c768 | 2019-08-05 19:55:22 -0500 | [diff] [blame] | 1054 | static void intel_shutdown(struct snd_pcm_substream *substream, |
| 1055 | struct snd_soc_dai *dai) |
| 1056 | { |
Pierre-Louis Bossart | ebf878e | 2020-08-17 23:29:12 +0800 | [diff] [blame] | 1057 | struct sdw_cdns *cdns = snd_soc_dai_get_drvdata(dai); |
Pierre-Louis Bossart | 183c768 | 2019-08-05 19:55:22 -0500 | [diff] [blame] | 1058 | |
Pierre-Louis Bossart | ebf878e | 2020-08-17 23:29:12 +0800 | [diff] [blame] | 1059 | pm_runtime_mark_last_busy(cdns->dev); |
| 1060 | pm_runtime_put_autosuspend(cdns->dev); |
Pierre-Louis Bossart | 183c768 | 2019-08-05 19:55:22 -0500 | [diff] [blame] | 1061 | } |
| 1062 | |
Bard Liao | a5a0239 | 2020-08-17 23:29:16 +0800 | [diff] [blame] | 1063 | static int intel_component_dais_suspend(struct snd_soc_component *component) |
| 1064 | { |
| 1065 | struct sdw_cdns_dma_data *dma; |
| 1066 | struct snd_soc_dai *dai; |
| 1067 | |
| 1068 | for_each_component_dais(component, dai) { |
| 1069 | /* |
| 1070 | * we don't have a .suspend dai_ops, and we don't have access |
| 1071 | * to the substream, so let's mark both capture and playback |
| 1072 | * DMA contexts as suspended |
| 1073 | */ |
| 1074 | dma = dai->playback_dma_data; |
| 1075 | if (dma) |
| 1076 | dma->suspended = true; |
| 1077 | |
| 1078 | dma = dai->capture_dma_data; |
| 1079 | if (dma) |
| 1080 | dma->suspended = true; |
| 1081 | } |
| 1082 | |
| 1083 | return 0; |
| 1084 | } |
| 1085 | |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1086 | static int intel_pcm_set_sdw_stream(struct snd_soc_dai *dai, |
Pierre-Louis Bossart | d542bc9 | 2019-05-01 10:57:38 -0500 | [diff] [blame] | 1087 | void *stream, int direction) |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1088 | { |
| 1089 | return cdns_set_sdw_stream(dai, stream, true, direction); |
| 1090 | } |
| 1091 | |
| 1092 | static int intel_pdm_set_sdw_stream(struct snd_soc_dai *dai, |
Pierre-Louis Bossart | d542bc9 | 2019-05-01 10:57:38 -0500 | [diff] [blame] | 1093 | void *stream, int direction) |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1094 | { |
| 1095 | return cdns_set_sdw_stream(dai, stream, false, direction); |
| 1096 | } |
| 1097 | |
Pierre-Louis Bossart | 0955314 | 2020-07-01 02:43:52 +0800 | [diff] [blame] | 1098 | static void *intel_get_sdw_stream(struct snd_soc_dai *dai, |
| 1099 | int direction) |
| 1100 | { |
| 1101 | struct sdw_cdns_dma_data *dma; |
| 1102 | |
| 1103 | if (direction == SNDRV_PCM_STREAM_PLAYBACK) |
| 1104 | dma = dai->playback_dma_data; |
| 1105 | else |
| 1106 | dma = dai->capture_dma_data; |
| 1107 | |
| 1108 | if (!dma) |
| 1109 | return NULL; |
| 1110 | |
| 1111 | return dma->stream; |
| 1112 | } |
| 1113 | |
Julia Lawall | b163559 | 2018-10-27 15:34:42 +0200 | [diff] [blame] | 1114 | static const struct snd_soc_dai_ops intel_pcm_dai_ops = { |
Rander Wang | 5e7484d | 2020-02-14 19:47:39 -0600 | [diff] [blame] | 1115 | .startup = intel_startup, |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1116 | .hw_params = intel_hw_params, |
Rander Wang | 27b198f | 2020-02-14 19:47:37 -0600 | [diff] [blame] | 1117 | .prepare = intel_prepare, |
Rander Wang | 973a842 | 2020-02-14 19:47:38 -0600 | [diff] [blame] | 1118 | .trigger = intel_trigger, |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1119 | .hw_free = intel_hw_free, |
Pierre-Louis Bossart | 183c768 | 2019-08-05 19:55:22 -0500 | [diff] [blame] | 1120 | .shutdown = intel_shutdown, |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1121 | .set_sdw_stream = intel_pcm_set_sdw_stream, |
Pierre-Louis Bossart | 0955314 | 2020-07-01 02:43:52 +0800 | [diff] [blame] | 1122 | .get_sdw_stream = intel_get_sdw_stream, |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1123 | }; |
| 1124 | |
Julia Lawall | b163559 | 2018-10-27 15:34:42 +0200 | [diff] [blame] | 1125 | static const struct snd_soc_dai_ops intel_pdm_dai_ops = { |
Rander Wang | 5e7484d | 2020-02-14 19:47:39 -0600 | [diff] [blame] | 1126 | .startup = intel_startup, |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1127 | .hw_params = intel_hw_params, |
Rander Wang | 27b198f | 2020-02-14 19:47:37 -0600 | [diff] [blame] | 1128 | .prepare = intel_prepare, |
Rander Wang | 973a842 | 2020-02-14 19:47:38 -0600 | [diff] [blame] | 1129 | .trigger = intel_trigger, |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1130 | .hw_free = intel_hw_free, |
Pierre-Louis Bossart | 183c768 | 2019-08-05 19:55:22 -0500 | [diff] [blame] | 1131 | .shutdown = intel_shutdown, |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1132 | .set_sdw_stream = intel_pdm_set_sdw_stream, |
Pierre-Louis Bossart | 0955314 | 2020-07-01 02:43:52 +0800 | [diff] [blame] | 1133 | .get_sdw_stream = intel_get_sdw_stream, |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1134 | }; |
| 1135 | |
| 1136 | static const struct snd_soc_component_driver dai_component = { |
| 1137 | .name = "soundwire", |
Bard Liao | a5a0239 | 2020-08-17 23:29:16 +0800 | [diff] [blame] | 1138 | .suspend = intel_component_dais_suspend |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1139 | }; |
| 1140 | |
| 1141 | static int intel_create_dai(struct sdw_cdns *cdns, |
Pierre-Louis Bossart | d542bc9 | 2019-05-01 10:57:38 -0500 | [diff] [blame] | 1142 | struct snd_soc_dai_driver *dais, |
| 1143 | enum intel_pdi_type type, |
| 1144 | u32 num, u32 off, u32 max_ch, bool pcm) |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1145 | { |
| 1146 | int i; |
| 1147 | |
| 1148 | if (num == 0) |
| 1149 | return 0; |
| 1150 | |
| 1151 | /* TODO: Read supported rates/formats from hardware */ |
| 1152 | for (i = off; i < (off + num); i++) { |
Pierre-Louis Bossart | bf6d6e6 | 2020-06-17 11:35:36 -0500 | [diff] [blame] | 1153 | dais[i].name = devm_kasprintf(cdns->dev, GFP_KERNEL, |
| 1154 | "SDW%d Pin%d", |
| 1155 | cdns->instance, i); |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1156 | if (!dais[i].name) |
| 1157 | return -ENOMEM; |
| 1158 | |
| 1159 | if (type == INTEL_PDI_BD || type == INTEL_PDI_OUT) { |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1160 | dais[i].playback.channels_min = 1; |
| 1161 | dais[i].playback.channels_max = max_ch; |
| 1162 | dais[i].playback.rates = SNDRV_PCM_RATE_48000; |
| 1163 | dais[i].playback.formats = SNDRV_PCM_FMTBIT_S16_LE; |
| 1164 | } |
| 1165 | |
| 1166 | if (type == INTEL_PDI_BD || type == INTEL_PDI_IN) { |
Srinivas Kandagatla | 3919412 | 2019-06-06 12:23:04 +0100 | [diff] [blame] | 1167 | dais[i].capture.channels_min = 1; |
| 1168 | dais[i].capture.channels_max = max_ch; |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1169 | dais[i].capture.rates = SNDRV_PCM_RATE_48000; |
| 1170 | dais[i].capture.formats = SNDRV_PCM_FMTBIT_S16_LE; |
| 1171 | } |
| 1172 | |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1173 | if (pcm) |
| 1174 | dais[i].ops = &intel_pcm_dai_ops; |
| 1175 | else |
| 1176 | dais[i].ops = &intel_pdm_dai_ops; |
| 1177 | } |
| 1178 | |
| 1179 | return 0; |
| 1180 | } |
| 1181 | |
| 1182 | static int intel_register_dai(struct sdw_intel *sdw) |
| 1183 | { |
| 1184 | struct sdw_cdns *cdns = &sdw->cdns; |
| 1185 | struct sdw_cdns_streams *stream; |
| 1186 | struct snd_soc_dai_driver *dais; |
| 1187 | int num_dai, ret, off = 0; |
| 1188 | |
| 1189 | /* DAIs are created based on total number of PDIs supported */ |
| 1190 | num_dai = cdns->pcm.num_pdi + cdns->pdm.num_pdi; |
| 1191 | |
| 1192 | dais = devm_kcalloc(cdns->dev, num_dai, sizeof(*dais), GFP_KERNEL); |
| 1193 | if (!dais) |
| 1194 | return -ENOMEM; |
| 1195 | |
| 1196 | /* Create PCM DAIs */ |
| 1197 | stream = &cdns->pcm; |
| 1198 | |
Bard Liao | cf92496 | 2019-09-16 14:23:43 -0500 | [diff] [blame] | 1199 | ret = intel_create_dai(cdns, dais, INTEL_PDI_IN, cdns->pcm.num_in, |
Vinod Koul | 1215dae | 2019-05-02 16:29:25 +0530 | [diff] [blame] | 1200 | off, stream->num_ch_in, true); |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1201 | if (ret) |
| 1202 | return ret; |
| 1203 | |
| 1204 | off += cdns->pcm.num_in; |
Vinod Koul | 1215dae | 2019-05-02 16:29:25 +0530 | [diff] [blame] | 1205 | ret = intel_create_dai(cdns, dais, INTEL_PDI_OUT, cdns->pcm.num_out, |
| 1206 | off, stream->num_ch_out, true); |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1207 | if (ret) |
| 1208 | return ret; |
| 1209 | |
| 1210 | off += cdns->pcm.num_out; |
Vinod Koul | 1215dae | 2019-05-02 16:29:25 +0530 | [diff] [blame] | 1211 | ret = intel_create_dai(cdns, dais, INTEL_PDI_BD, cdns->pcm.num_bd, |
| 1212 | off, stream->num_ch_bd, true); |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1213 | if (ret) |
| 1214 | return ret; |
| 1215 | |
| 1216 | /* Create PDM DAIs */ |
| 1217 | stream = &cdns->pdm; |
| 1218 | off += cdns->pcm.num_bd; |
Vinod Koul | 1215dae | 2019-05-02 16:29:25 +0530 | [diff] [blame] | 1219 | ret = intel_create_dai(cdns, dais, INTEL_PDI_IN, cdns->pdm.num_in, |
| 1220 | off, stream->num_ch_in, false); |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1221 | if (ret) |
| 1222 | return ret; |
| 1223 | |
| 1224 | off += cdns->pdm.num_in; |
Vinod Koul | 1215dae | 2019-05-02 16:29:25 +0530 | [diff] [blame] | 1225 | ret = intel_create_dai(cdns, dais, INTEL_PDI_OUT, cdns->pdm.num_out, |
| 1226 | off, stream->num_ch_out, false); |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1227 | if (ret) |
| 1228 | return ret; |
| 1229 | |
Bard Liao | cf92496 | 2019-09-16 14:23:43 -0500 | [diff] [blame] | 1230 | off += cdns->pdm.num_out; |
Vinod Koul | 1215dae | 2019-05-02 16:29:25 +0530 | [diff] [blame] | 1231 | ret = intel_create_dai(cdns, dais, INTEL_PDI_BD, cdns->pdm.num_bd, |
| 1232 | off, stream->num_ch_bd, false); |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1233 | if (ret) |
| 1234 | return ret; |
| 1235 | |
| 1236 | return snd_soc_register_component(cdns->dev, &dai_component, |
Pierre-Louis Bossart | d542bc9 | 2019-05-01 10:57:38 -0500 | [diff] [blame] | 1237 | dais, num_dai); |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1238 | } |
| 1239 | |
Pierre-Louis Bossart | 085f4ac | 2019-08-05 19:55:16 -0500 | [diff] [blame] | 1240 | static int sdw_master_read_intel_prop(struct sdw_bus *bus) |
| 1241 | { |
| 1242 | struct sdw_master_prop *prop = &bus->prop; |
| 1243 | struct fwnode_handle *link; |
| 1244 | char name[32]; |
Pierre-Louis Bossart | 395713d | 2019-08-21 13:58:21 -0500 | [diff] [blame] | 1245 | u32 quirk_mask; |
Pierre-Louis Bossart | 085f4ac | 2019-08-05 19:55:16 -0500 | [diff] [blame] | 1246 | |
| 1247 | /* Find master handle */ |
| 1248 | snprintf(name, sizeof(name), |
| 1249 | "mipi-sdw-link-%d-subproperties", bus->link_id); |
| 1250 | |
| 1251 | link = device_get_named_child_node(bus->dev, name); |
| 1252 | if (!link) { |
| 1253 | dev_err(bus->dev, "Master node %s not found\n", name); |
| 1254 | return -EIO; |
| 1255 | } |
| 1256 | |
| 1257 | fwnode_property_read_u32(link, |
| 1258 | "intel-sdw-ip-clock", |
| 1259 | &prop->mclk_freq); |
Pierre-Louis Bossart | 395713d | 2019-08-21 13:58:21 -0500 | [diff] [blame] | 1260 | |
Bard Liao | a19efb5 | 2020-01-13 17:11:29 -0600 | [diff] [blame] | 1261 | /* the values reported by BIOS are the 2x clock, not the bus clock */ |
| 1262 | prop->mclk_freq /= 2; |
| 1263 | |
Pierre-Louis Bossart | 395713d | 2019-08-21 13:58:21 -0500 | [diff] [blame] | 1264 | fwnode_property_read_u32(link, |
| 1265 | "intel-quirk-mask", |
| 1266 | &quirk_mask); |
| 1267 | |
| 1268 | if (quirk_mask & SDW_INTEL_QUIRK_MASK_BUS_DISABLE) |
| 1269 | prop->hw_disabled = true; |
| 1270 | |
Pierre-Louis Bossart | 085f4ac | 2019-08-05 19:55:16 -0500 | [diff] [blame] | 1271 | return 0; |
| 1272 | } |
| 1273 | |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1274 | static int intel_prop_read(struct sdw_bus *bus) |
| 1275 | { |
| 1276 | /* Initialize with default handler to read all DisCo properties */ |
| 1277 | sdw_master_read_prop(bus); |
| 1278 | |
Pierre-Louis Bossart | 085f4ac | 2019-08-05 19:55:16 -0500 | [diff] [blame] | 1279 | /* read Intel-specific properties */ |
| 1280 | sdw_master_read_intel_prop(bus); |
| 1281 | |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1282 | return 0; |
| 1283 | } |
| 1284 | |
Shreyas NC | c91605f | 2018-04-26 18:38:43 +0530 | [diff] [blame] | 1285 | static struct sdw_master_ops sdw_intel_ops = { |
| 1286 | .read_prop = sdw_master_read_prop, |
| 1287 | .xfer_msg = cdns_xfer_msg, |
| 1288 | .xfer_msg_defer = cdns_xfer_msg_defer, |
| 1289 | .reset_page_addr = cdns_reset_page_addr, |
Vinod Koul | 07abeff | 2018-04-26 18:38:48 +0530 | [diff] [blame] | 1290 | .set_bus_conf = cdns_bus_conf, |
Shreyas NC | 30246e2 | 2018-07-27 14:44:17 +0530 | [diff] [blame] | 1291 | .pre_bank_switch = intel_pre_bank_switch, |
| 1292 | .post_bank_switch = intel_post_bank_switch, |
Shreyas NC | c91605f | 2018-04-26 18:38:43 +0530 | [diff] [blame] | 1293 | }; |
| 1294 | |
Pierre-Louis Bossart | dfbe642 | 2019-10-22 18:54:46 -0500 | [diff] [blame] | 1295 | static int intel_init(struct sdw_intel *sdw) |
| 1296 | { |
Pierre-Louis Bossart | 4a17c44 | 2020-07-16 23:09:40 +0800 | [diff] [blame] | 1297 | bool clock_stop; |
| 1298 | |
Pierre-Louis Bossart | dfbe642 | 2019-10-22 18:54:46 -0500 | [diff] [blame] | 1299 | /* Initialize shim and controller */ |
| 1300 | intel_link_power_up(sdw); |
Pierre-Louis Bossart | 4a17c44 | 2020-07-16 23:09:40 +0800 | [diff] [blame] | 1301 | |
| 1302 | clock_stop = sdw_cdns_is_clock_stop(&sdw->cdns); |
| 1303 | |
| 1304 | intel_shim_init(sdw, clock_stop); |
| 1305 | |
| 1306 | if (clock_stop) |
| 1307 | return 0; |
Pierre-Louis Bossart | dfbe642 | 2019-10-22 18:54:46 -0500 | [diff] [blame] | 1308 | |
Rander Wang | 7b174f2 | 2020-03-17 11:33:14 -0500 | [diff] [blame] | 1309 | return sdw_cdns_init(&sdw->cdns); |
Pierre-Louis Bossart | dfbe642 | 2019-10-22 18:54:46 -0500 | [diff] [blame] | 1310 | } |
| 1311 | |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1312 | /* |
| 1313 | * probe and init |
| 1314 | */ |
Pierre-Louis Bossart | b6109dd | 2020-06-01 02:20:57 +0800 | [diff] [blame] | 1315 | static int intel_master_probe(struct platform_device *pdev) |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1316 | { |
Pierre-Louis Bossart | b6109dd | 2020-06-01 02:20:57 +0800 | [diff] [blame] | 1317 | struct device *dev = &pdev->dev; |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1318 | struct sdw_intel *sdw; |
Pierre-Louis Bossart | 83e129af | 2020-06-01 02:20:58 +0800 | [diff] [blame] | 1319 | struct sdw_cdns *cdns; |
Pierre-Louis Bossart | b6109dd | 2020-06-01 02:20:57 +0800 | [diff] [blame] | 1320 | struct sdw_bus *bus; |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1321 | int ret; |
| 1322 | |
Pierre-Louis Bossart | b6109dd | 2020-06-01 02:20:57 +0800 | [diff] [blame] | 1323 | sdw = devm_kzalloc(dev, sizeof(*sdw), GFP_KERNEL); |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1324 | if (!sdw) |
| 1325 | return -ENOMEM; |
| 1326 | |
Pierre-Louis Bossart | 83e129af | 2020-06-01 02:20:58 +0800 | [diff] [blame] | 1327 | cdns = &sdw->cdns; |
| 1328 | bus = &cdns->bus; |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1329 | |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1330 | sdw->instance = pdev->id; |
Pierre-Louis Bossart | b6109dd | 2020-06-01 02:20:57 +0800 | [diff] [blame] | 1331 | sdw->link_res = dev_get_platdata(dev); |
Pierre-Louis Bossart | 83e129af | 2020-06-01 02:20:58 +0800 | [diff] [blame] | 1332 | cdns->dev = dev; |
| 1333 | cdns->registers = sdw->link_res->registers; |
| 1334 | cdns->instance = sdw->instance; |
| 1335 | cdns->msg_count = 0; |
| 1336 | |
Pierre-Louis Bossart | b6109dd | 2020-06-01 02:20:57 +0800 | [diff] [blame] | 1337 | bus->link_id = pdev->id; |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1338 | |
Pierre-Louis Bossart | 83e129af | 2020-06-01 02:20:58 +0800 | [diff] [blame] | 1339 | sdw_cdns_probe(cdns); |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1340 | |
| 1341 | /* Set property read ops */ |
Shreyas NC | c91605f | 2018-04-26 18:38:43 +0530 | [diff] [blame] | 1342 | sdw_intel_ops.read_prop = intel_prop_read; |
Pierre-Louis Bossart | b6109dd | 2020-06-01 02:20:57 +0800 | [diff] [blame] | 1343 | bus->ops = &sdw_intel_ops; |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1344 | |
Pierre-Louis Bossart | b6109dd | 2020-06-01 02:20:57 +0800 | [diff] [blame] | 1345 | /* set driver data, accessed by snd_soc_dai_get_drvdata() */ |
Pierre-Louis Bossart | 83e129af | 2020-06-01 02:20:58 +0800 | [diff] [blame] | 1346 | dev_set_drvdata(dev, cdns); |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1347 | |
Pierre-Louis Bossart | b6109dd | 2020-06-01 02:20:57 +0800 | [diff] [blame] | 1348 | ret = sdw_bus_master_add(bus, dev, dev->fwnode); |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1349 | if (ret) { |
Pierre-Louis Bossart | b6109dd | 2020-06-01 02:20:57 +0800 | [diff] [blame] | 1350 | dev_err(dev, "sdw_bus_master_add fail: %d\n", ret); |
Pierre-Louis Bossart | 9e3d47f | 2019-10-22 18:54:47 -0500 | [diff] [blame] | 1351 | return ret; |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1352 | } |
| 1353 | |
Pierre-Louis Bossart | 6d2c666 | 2020-06-01 02:21:02 +0800 | [diff] [blame] | 1354 | if (bus->prop.hw_disabled) |
Pierre-Louis Bossart | b6109dd | 2020-06-01 02:20:57 +0800 | [diff] [blame] | 1355 | dev_info(dev, |
| 1356 | "SoundWire master %d is disabled, will be ignored\n", |
| 1357 | bus->link_id); |
Pierre-Louis Bossart | 6d2c666 | 2020-06-01 02:21:02 +0800 | [diff] [blame] | 1358 | |
Pierre-Louis Bossart | 6d2c666 | 2020-06-01 02:21:02 +0800 | [diff] [blame] | 1359 | return 0; |
Pierre-Louis Bossart | 6d2c666 | 2020-06-01 02:21:02 +0800 | [diff] [blame] | 1360 | } |
| 1361 | |
| 1362 | int intel_master_startup(struct platform_device *pdev) |
| 1363 | { |
| 1364 | struct sdw_cdns_stream_config config; |
| 1365 | struct device *dev = &pdev->dev; |
| 1366 | struct sdw_cdns *cdns = dev_get_drvdata(dev); |
| 1367 | struct sdw_intel *sdw = cdns_to_intel(cdns); |
| 1368 | struct sdw_bus *bus = &cdns->bus; |
Pierre-Louis Bossart | ebf878e | 2020-08-17 23:29:12 +0800 | [diff] [blame] | 1369 | int link_flags; |
Pierre-Louis Bossart | 6d2c666 | 2020-06-01 02:21:02 +0800 | [diff] [blame] | 1370 | int ret; |
| 1371 | |
| 1372 | if (bus->prop.hw_disabled) { |
| 1373 | dev_info(dev, |
| 1374 | "SoundWire master %d is disabled, ignoring\n", |
| 1375 | sdw->instance); |
Pierre-Louis Bossart | 395713d | 2019-08-21 13:58:21 -0500 | [diff] [blame] | 1376 | return 0; |
| 1377 | } |
| 1378 | |
Pierre-Louis Bossart | dfbe642 | 2019-10-22 18:54:46 -0500 | [diff] [blame] | 1379 | /* Initialize shim, controller and Cadence IP */ |
| 1380 | ret = intel_init(sdw); |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1381 | if (ret) |
| 1382 | goto err_init; |
| 1383 | |
Vinod Koul | 37a2d22 | 2018-04-26 18:38:58 +0530 | [diff] [blame] | 1384 | /* Read the PDI config and initialize cadence PDI */ |
| 1385 | intel_pdi_init(sdw, &config); |
Pierre-Louis Bossart | 83e129af | 2020-06-01 02:20:58 +0800 | [diff] [blame] | 1386 | ret = sdw_cdns_pdi_init(cdns, config); |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1387 | if (ret) |
| 1388 | goto err_init; |
| 1389 | |
Vinod Koul | 37a2d22 | 2018-04-26 18:38:58 +0530 | [diff] [blame] | 1390 | intel_pdi_ch_update(sdw); |
| 1391 | |
Pierre-Louis Bossart | 83e129af | 2020-06-01 02:20:58 +0800 | [diff] [blame] | 1392 | ret = sdw_cdns_enable_interrupt(cdns, true); |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1393 | if (ret < 0) { |
Pierre-Louis Bossart | b6109dd | 2020-06-01 02:20:57 +0800 | [diff] [blame] | 1394 | dev_err(dev, "cannot enable interrupts\n"); |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1395 | goto err_init; |
| 1396 | } |
| 1397 | |
Pierre-Louis Bossart | 83e129af | 2020-06-01 02:20:58 +0800 | [diff] [blame] | 1398 | ret = sdw_cdns_exit_reset(cdns); |
Pierre-Louis Bossart | 49ea07d | 2019-10-22 18:54:44 -0500 | [diff] [blame] | 1399 | if (ret < 0) { |
Pierre-Louis Bossart | b6109dd | 2020-06-01 02:20:57 +0800 | [diff] [blame] | 1400 | dev_err(dev, "unable to exit bus reset sequence\n"); |
Pierre-Louis Bossart | 9e3d47f | 2019-10-22 18:54:47 -0500 | [diff] [blame] | 1401 | goto err_interrupt; |
Pierre-Louis Bossart | 49ea07d | 2019-10-22 18:54:44 -0500 | [diff] [blame] | 1402 | } |
| 1403 | |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1404 | /* Register DAIs */ |
| 1405 | ret = intel_register_dai(sdw); |
| 1406 | if (ret) { |
Pierre-Louis Bossart | b6109dd | 2020-06-01 02:20:57 +0800 | [diff] [blame] | 1407 | dev_err(dev, "DAI registration failed: %d\n", ret); |
| 1408 | snd_soc_unregister_component(dev); |
Pierre-Louis Bossart | 9e3d47f | 2019-10-22 18:54:47 -0500 | [diff] [blame] | 1409 | goto err_interrupt; |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1410 | } |
| 1411 | |
Pierre-Louis Bossart | 79ee663 | 2019-08-21 13:58:20 -0500 | [diff] [blame] | 1412 | intel_debugfs_init(sdw); |
| 1413 | |
Pierre-Louis Bossart | ebf878e | 2020-08-17 23:29:12 +0800 | [diff] [blame] | 1414 | /* Enable runtime PM */ |
| 1415 | link_flags = md_flags >> (bus->link_id * 8); |
| 1416 | if (!(link_flags & SDW_INTEL_MASTER_DISABLE_PM_RUNTIME)) { |
| 1417 | pm_runtime_set_autosuspend_delay(dev, |
| 1418 | INTEL_MASTER_SUSPEND_DELAY_MS); |
| 1419 | pm_runtime_use_autosuspend(dev); |
| 1420 | pm_runtime_mark_last_busy(dev); |
| 1421 | |
| 1422 | pm_runtime_set_active(dev); |
| 1423 | pm_runtime_enable(dev); |
| 1424 | } |
| 1425 | |
Pierre-Louis Bossart | a2d9c16 | 2020-08-17 23:29:17 +0800 | [diff] [blame] | 1426 | /* |
| 1427 | * The runtime PM status of Slave devices is "Unsupported" |
| 1428 | * until they report as ATTACHED. If they don't, e.g. because |
| 1429 | * there are no Slave devices populated or if the power-on is |
| 1430 | * delayed or dependent on a power switch, the Master will |
| 1431 | * remain active and prevent its parent from suspending. |
| 1432 | * |
| 1433 | * Conditionally force the pm_runtime core to re-evaluate the |
| 1434 | * Master status in the absence of any Slave activity. A quirk |
| 1435 | * is provided to e.g. deal with Slaves that may be powered on |
| 1436 | * with a delay. A more complete solution would require the |
| 1437 | * definition of Master properties. |
| 1438 | */ |
| 1439 | if (!(link_flags & SDW_INTEL_MASTER_DISABLE_PM_RUNTIME_IDLE)) |
| 1440 | pm_runtime_idle(dev); |
| 1441 | |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1442 | return 0; |
| 1443 | |
Pierre-Louis Bossart | 9e3d47f | 2019-10-22 18:54:47 -0500 | [diff] [blame] | 1444 | err_interrupt: |
Pierre-Louis Bossart | 83e129af | 2020-06-01 02:20:58 +0800 | [diff] [blame] | 1445 | sdw_cdns_enable_interrupt(cdns, false); |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1446 | err_init: |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1447 | return ret; |
| 1448 | } |
| 1449 | |
Pierre-Louis Bossart | b6109dd | 2020-06-01 02:20:57 +0800 | [diff] [blame] | 1450 | static int intel_master_remove(struct platform_device *pdev) |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1451 | { |
Pierre-Louis Bossart | b6109dd | 2020-06-01 02:20:57 +0800 | [diff] [blame] | 1452 | struct device *dev = &pdev->dev; |
Pierre-Louis Bossart | 83e129af | 2020-06-01 02:20:58 +0800 | [diff] [blame] | 1453 | struct sdw_cdns *cdns = dev_get_drvdata(dev); |
| 1454 | struct sdw_intel *sdw = cdns_to_intel(cdns); |
| 1455 | struct sdw_bus *bus = &cdns->bus; |
Pierre-Louis Bossart | b6109dd | 2020-06-01 02:20:57 +0800 | [diff] [blame] | 1456 | |
| 1457 | if (!bus->prop.hw_disabled) { |
Pierre-Louis Bossart | 395713d | 2019-08-21 13:58:21 -0500 | [diff] [blame] | 1458 | intel_debugfs_exit(sdw); |
Pierre-Louis Bossart | 83e129af | 2020-06-01 02:20:58 +0800 | [diff] [blame] | 1459 | sdw_cdns_enable_interrupt(cdns, false); |
Pierre-Louis Bossart | b6109dd | 2020-06-01 02:20:57 +0800 | [diff] [blame] | 1460 | snd_soc_unregister_component(dev); |
Pierre-Louis Bossart | 395713d | 2019-08-21 13:58:21 -0500 | [diff] [blame] | 1461 | } |
Pierre-Louis Bossart | b6109dd | 2020-06-01 02:20:57 +0800 | [diff] [blame] | 1462 | sdw_bus_master_delete(bus); |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1463 | |
| 1464 | return 0; |
| 1465 | } |
| 1466 | |
Rander Wang | ab2c913 | 2020-07-16 23:09:46 +0800 | [diff] [blame] | 1467 | int intel_master_process_wakeen_event(struct platform_device *pdev) |
| 1468 | { |
| 1469 | struct device *dev = &pdev->dev; |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1470 | struct sdw_intel *sdw; |
Rander Wang | ab2c913 | 2020-07-16 23:09:46 +0800 | [diff] [blame] | 1471 | struct sdw_bus *bus; |
| 1472 | void __iomem *shim; |
| 1473 | u16 wake_sts; |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1474 | |
| 1475 | sdw = platform_get_drvdata(pdev); |
Rander Wang | ab2c913 | 2020-07-16 23:09:46 +0800 | [diff] [blame] | 1476 | bus = &sdw->cdns.bus; |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1477 | |
Rander Wang | ab2c913 | 2020-07-16 23:09:46 +0800 | [diff] [blame] | 1478 | if (bus->prop.hw_disabled) { |
| 1479 | dev_dbg(dev, "SoundWire master %d is disabled, ignoring\n", bus->link_id); |
| 1480 | return 0; |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1481 | } |
Rander Wang | ab2c913 | 2020-07-16 23:09:46 +0800 | [diff] [blame] | 1482 | |
| 1483 | shim = sdw->link_res->shim; |
| 1484 | wake_sts = intel_readw(shim, SDW_SHIM_WAKESTS); |
| 1485 | |
| 1486 | if (!(wake_sts & BIT(sdw->instance))) |
| 1487 | return 0; |
| 1488 | |
| 1489 | /* disable WAKEEN interrupt ASAP to prevent interrupt flood */ |
| 1490 | intel_shim_wake(sdw, false); |
| 1491 | |
| 1492 | /* |
| 1493 | * resume the Master, which will generate a bus reset and result in |
| 1494 | * Slaves re-attaching and be re-enumerated. The SoundWire physical |
| 1495 | * device which generated the wake will trigger an interrupt, which |
| 1496 | * will in turn cause the corresponding Linux Slave device to be |
| 1497 | * resumed and the Slave codec driver to check the status. |
| 1498 | */ |
| 1499 | pm_request_resume(dev); |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1500 | |
| 1501 | return 0; |
| 1502 | } |
| 1503 | |
Pierre-Louis Bossart | 9b3b4b3 | 2020-07-22 04:37:11 +0800 | [diff] [blame] | 1504 | /* |
| 1505 | * PM calls |
| 1506 | */ |
| 1507 | |
| 1508 | #ifdef CONFIG_PM |
| 1509 | |
| 1510 | static int intel_suspend(struct device *dev) |
| 1511 | { |
| 1512 | struct sdw_cdns *cdns = dev_get_drvdata(dev); |
| 1513 | struct sdw_intel *sdw = cdns_to_intel(cdns); |
| 1514 | struct sdw_bus *bus = &cdns->bus; |
| 1515 | int ret; |
| 1516 | |
| 1517 | if (bus->prop.hw_disabled) { |
| 1518 | dev_dbg(dev, "SoundWire master %d is disabled, ignoring\n", |
| 1519 | bus->link_id); |
| 1520 | return 0; |
| 1521 | } |
| 1522 | |
Pierre-Louis Bossart | b61b8b3 | 2020-08-17 23:29:13 +0800 | [diff] [blame] | 1523 | if (pm_runtime_suspended(dev)) { |
| 1524 | dev_dbg(dev, "%s: pm_runtime status: suspended\n", __func__); |
| 1525 | |
| 1526 | return 0; |
| 1527 | } |
| 1528 | |
Pierre-Louis Bossart | 9b3b4b3 | 2020-07-22 04:37:11 +0800 | [diff] [blame] | 1529 | ret = sdw_cdns_enable_interrupt(cdns, false); |
| 1530 | if (ret < 0) { |
| 1531 | dev_err(dev, "cannot disable interrupts on suspend\n"); |
| 1532 | return ret; |
| 1533 | } |
| 1534 | |
| 1535 | ret = intel_link_power_down(sdw); |
| 1536 | if (ret) { |
| 1537 | dev_err(dev, "Link power down failed: %d", ret); |
| 1538 | return ret; |
| 1539 | } |
| 1540 | |
| 1541 | intel_shim_wake(sdw, false); |
| 1542 | |
| 1543 | return 0; |
| 1544 | } |
| 1545 | |
Pierre-Louis Bossart | ebf878e | 2020-08-17 23:29:12 +0800 | [diff] [blame] | 1546 | static int intel_suspend_runtime(struct device *dev) |
| 1547 | { |
| 1548 | struct sdw_cdns *cdns = dev_get_drvdata(dev); |
| 1549 | struct sdw_intel *sdw = cdns_to_intel(cdns); |
| 1550 | struct sdw_bus *bus = &cdns->bus; |
Pierre-Louis Bossart | a320f41 | 2020-08-17 23:29:18 +0800 | [diff] [blame] | 1551 | u32 clock_stop_quirks; |
Pierre-Louis Bossart | ebf878e | 2020-08-17 23:29:12 +0800 | [diff] [blame] | 1552 | int ret; |
| 1553 | |
| 1554 | if (bus->prop.hw_disabled) { |
| 1555 | dev_dbg(dev, "SoundWire master %d is disabled, ignoring\n", |
| 1556 | bus->link_id); |
| 1557 | return 0; |
| 1558 | } |
| 1559 | |
Pierre-Louis Bossart | a320f41 | 2020-08-17 23:29:18 +0800 | [diff] [blame] | 1560 | clock_stop_quirks = sdw->link_res->clock_stop_quirks; |
| 1561 | |
| 1562 | if (clock_stop_quirks & SDW_INTEL_CLK_STOP_TEARDOWN) { |
| 1563 | |
| 1564 | ret = sdw_cdns_enable_interrupt(cdns, false); |
| 1565 | if (ret < 0) { |
| 1566 | dev_err(dev, "cannot disable interrupts on suspend\n"); |
| 1567 | return ret; |
| 1568 | } |
| 1569 | |
| 1570 | ret = intel_link_power_down(sdw); |
| 1571 | if (ret) { |
| 1572 | dev_err(dev, "Link power down failed: %d", ret); |
| 1573 | return ret; |
| 1574 | } |
| 1575 | |
| 1576 | intel_shim_wake(sdw, false); |
| 1577 | |
Rander Wang | 6626a61 | 2020-08-17 23:29:19 +0800 | [diff] [blame^] | 1578 | } else if (clock_stop_quirks & SDW_INTEL_CLK_STOP_BUS_RESET) { |
| 1579 | ret = sdw_cdns_clock_stop(cdns, true); |
| 1580 | if (ret < 0) { |
| 1581 | dev_err(dev, "cannot enable clock stop on suspend\n"); |
| 1582 | return ret; |
| 1583 | } |
| 1584 | |
| 1585 | ret = sdw_cdns_enable_interrupt(cdns, false); |
| 1586 | if (ret < 0) { |
| 1587 | dev_err(dev, "cannot disable interrupts on suspend\n"); |
| 1588 | return ret; |
| 1589 | } |
| 1590 | |
| 1591 | ret = intel_link_power_down(sdw); |
| 1592 | if (ret) { |
| 1593 | dev_err(dev, "Link power down failed: %d", ret); |
| 1594 | return ret; |
| 1595 | } |
| 1596 | |
| 1597 | intel_shim_wake(sdw, true); |
Pierre-Louis Bossart | a320f41 | 2020-08-17 23:29:18 +0800 | [diff] [blame] | 1598 | } else { |
| 1599 | dev_err(dev, "%s clock_stop_quirks %x unsupported\n", |
| 1600 | __func__, clock_stop_quirks); |
| 1601 | ret = -EINVAL; |
Pierre-Louis Bossart | ebf878e | 2020-08-17 23:29:12 +0800 | [diff] [blame] | 1602 | } |
| 1603 | |
Pierre-Louis Bossart | a320f41 | 2020-08-17 23:29:18 +0800 | [diff] [blame] | 1604 | return ret; |
Pierre-Louis Bossart | ebf878e | 2020-08-17 23:29:12 +0800 | [diff] [blame] | 1605 | } |
| 1606 | |
Pierre-Louis Bossart | 9b3b4b3 | 2020-07-22 04:37:11 +0800 | [diff] [blame] | 1607 | static int intel_resume(struct device *dev) |
| 1608 | { |
| 1609 | struct sdw_cdns *cdns = dev_get_drvdata(dev); |
| 1610 | struct sdw_intel *sdw = cdns_to_intel(cdns); |
| 1611 | struct sdw_bus *bus = &cdns->bus; |
Pierre-Louis Bossart | a2d9c16 | 2020-08-17 23:29:17 +0800 | [diff] [blame] | 1612 | int link_flags; |
Pierre-Louis Bossart | 9b3b4b3 | 2020-07-22 04:37:11 +0800 | [diff] [blame] | 1613 | int ret; |
| 1614 | |
| 1615 | if (bus->prop.hw_disabled) { |
| 1616 | dev_dbg(dev, "SoundWire master %d is disabled, ignoring\n", |
| 1617 | bus->link_id); |
| 1618 | return 0; |
| 1619 | } |
| 1620 | |
Pierre-Louis Bossart | b61b8b3 | 2020-08-17 23:29:13 +0800 | [diff] [blame] | 1621 | if (pm_runtime_suspended(dev)) { |
| 1622 | dev_dbg(dev, "%s: pm_runtime status was suspended, forcing active\n", __func__); |
| 1623 | |
| 1624 | /* follow required sequence from runtime_pm.rst */ |
| 1625 | pm_runtime_disable(dev); |
| 1626 | pm_runtime_set_active(dev); |
| 1627 | pm_runtime_mark_last_busy(dev); |
| 1628 | pm_runtime_enable(dev); |
Pierre-Louis Bossart | a2d9c16 | 2020-08-17 23:29:17 +0800 | [diff] [blame] | 1629 | |
| 1630 | link_flags = md_flags >> (bus->link_id * 8); |
| 1631 | if (!(link_flags & SDW_INTEL_MASTER_DISABLE_PM_RUNTIME_IDLE)) |
| 1632 | pm_runtime_idle(dev); |
Pierre-Louis Bossart | b61b8b3 | 2020-08-17 23:29:13 +0800 | [diff] [blame] | 1633 | } |
| 1634 | |
Pierre-Louis Bossart | 9b3b4b3 | 2020-07-22 04:37:11 +0800 | [diff] [blame] | 1635 | ret = intel_init(sdw); |
| 1636 | if (ret) { |
| 1637 | dev_err(dev, "%s failed: %d", __func__, ret); |
| 1638 | return ret; |
| 1639 | } |
| 1640 | |
Pierre-Louis Bossart | 99b6a30 | 2020-08-17 23:29:15 +0800 | [diff] [blame] | 1641 | /* |
| 1642 | * make sure all Slaves are tagged as UNATTACHED and provide |
| 1643 | * reason for reinitialization |
| 1644 | */ |
| 1645 | sdw_clear_slave_status(bus, SDW_UNATTACH_REQUEST_MASTER_RESET); |
| 1646 | |
Pierre-Louis Bossart | 9b3b4b3 | 2020-07-22 04:37:11 +0800 | [diff] [blame] | 1647 | ret = sdw_cdns_enable_interrupt(cdns, true); |
| 1648 | if (ret < 0) { |
| 1649 | dev_err(dev, "cannot enable interrupts during resume\n"); |
| 1650 | return ret; |
| 1651 | } |
| 1652 | |
| 1653 | ret = sdw_cdns_exit_reset(cdns); |
| 1654 | if (ret < 0) { |
| 1655 | dev_err(dev, "unable to exit bus reset sequence during resume\n"); |
| 1656 | return ret; |
| 1657 | } |
| 1658 | |
Pierre-Louis Bossart | cb1e6d5 | 2020-08-17 23:29:14 +0800 | [diff] [blame] | 1659 | /* |
| 1660 | * after system resume, the pm_runtime suspend() may kick in |
| 1661 | * during the enumeration, before any children device force the |
| 1662 | * master device to remain active. Using pm_runtime_get() |
| 1663 | * routines is not really possible, since it'd prevent the |
| 1664 | * master from suspending. |
| 1665 | * A reasonable compromise is to update the pm_runtime |
| 1666 | * counters and delay the pm_runtime suspend by several |
| 1667 | * seconds, by when all enumeration should be complete. |
| 1668 | */ |
| 1669 | pm_runtime_mark_last_busy(dev); |
| 1670 | |
Pierre-Louis Bossart | 9b3b4b3 | 2020-07-22 04:37:11 +0800 | [diff] [blame] | 1671 | return ret; |
| 1672 | } |
| 1673 | |
Pierre-Louis Bossart | ebf878e | 2020-08-17 23:29:12 +0800 | [diff] [blame] | 1674 | static int intel_resume_runtime(struct device *dev) |
| 1675 | { |
| 1676 | struct sdw_cdns *cdns = dev_get_drvdata(dev); |
| 1677 | struct sdw_intel *sdw = cdns_to_intel(cdns); |
| 1678 | struct sdw_bus *bus = &cdns->bus; |
Pierre-Louis Bossart | a320f41 | 2020-08-17 23:29:18 +0800 | [diff] [blame] | 1679 | u32 clock_stop_quirks; |
Pierre-Louis Bossart | ebf878e | 2020-08-17 23:29:12 +0800 | [diff] [blame] | 1680 | int ret; |
| 1681 | |
| 1682 | if (bus->prop.hw_disabled) { |
| 1683 | dev_dbg(dev, "SoundWire master %d is disabled, ignoring\n", |
| 1684 | bus->link_id); |
| 1685 | return 0; |
| 1686 | } |
| 1687 | |
Pierre-Louis Bossart | a320f41 | 2020-08-17 23:29:18 +0800 | [diff] [blame] | 1688 | clock_stop_quirks = sdw->link_res->clock_stop_quirks; |
Pierre-Louis Bossart | ebf878e | 2020-08-17 23:29:12 +0800 | [diff] [blame] | 1689 | |
Pierre-Louis Bossart | a320f41 | 2020-08-17 23:29:18 +0800 | [diff] [blame] | 1690 | if (clock_stop_quirks & SDW_INTEL_CLK_STOP_TEARDOWN) { |
| 1691 | ret = intel_init(sdw); |
| 1692 | if (ret) { |
| 1693 | dev_err(dev, "%s failed: %d", __func__, ret); |
| 1694 | return ret; |
| 1695 | } |
Pierre-Louis Bossart | 99b6a30 | 2020-08-17 23:29:15 +0800 | [diff] [blame] | 1696 | |
Pierre-Louis Bossart | a320f41 | 2020-08-17 23:29:18 +0800 | [diff] [blame] | 1697 | /* |
| 1698 | * make sure all Slaves are tagged as UNATTACHED and provide |
| 1699 | * reason for reinitialization |
| 1700 | */ |
| 1701 | sdw_clear_slave_status(bus, SDW_UNATTACH_REQUEST_MASTER_RESET); |
Pierre-Louis Bossart | ebf878e | 2020-08-17 23:29:12 +0800 | [diff] [blame] | 1702 | |
Pierre-Louis Bossart | a320f41 | 2020-08-17 23:29:18 +0800 | [diff] [blame] | 1703 | ret = sdw_cdns_enable_interrupt(cdns, true); |
| 1704 | if (ret < 0) { |
| 1705 | dev_err(dev, "cannot enable interrupts during resume\n"); |
| 1706 | return ret; |
| 1707 | } |
| 1708 | |
| 1709 | ret = sdw_cdns_exit_reset(cdns); |
| 1710 | if (ret < 0) { |
| 1711 | dev_err(dev, "unable to exit bus reset sequence during resume\n"); |
| 1712 | return ret; |
| 1713 | } |
Rander Wang | 6626a61 | 2020-08-17 23:29:19 +0800 | [diff] [blame^] | 1714 | } else if (clock_stop_quirks & SDW_INTEL_CLK_STOP_BUS_RESET) { |
| 1715 | ret = intel_init(sdw); |
| 1716 | if (ret) { |
| 1717 | dev_err(dev, "%s failed: %d", __func__, ret); |
| 1718 | return ret; |
| 1719 | } |
| 1720 | |
| 1721 | /* |
| 1722 | * make sure all Slaves are tagged as UNATTACHED and |
| 1723 | * provide reason for reinitialization |
| 1724 | */ |
| 1725 | sdw_clear_slave_status(bus, SDW_UNATTACH_REQUEST_MASTER_RESET); |
| 1726 | |
| 1727 | ret = sdw_cdns_enable_interrupt(cdns, true); |
| 1728 | if (ret < 0) { |
| 1729 | dev_err(dev, "cannot enable interrupts during resume\n"); |
| 1730 | return ret; |
| 1731 | } |
| 1732 | |
| 1733 | ret = sdw_cdns_clock_restart(cdns, true); |
| 1734 | if (ret < 0) { |
| 1735 | dev_err(dev, "unable to restart clock during resume\n"); |
| 1736 | return ret; |
| 1737 | } |
Pierre-Louis Bossart | a320f41 | 2020-08-17 23:29:18 +0800 | [diff] [blame] | 1738 | } else { |
| 1739 | dev_err(dev, "%s clock_stop_quirks %x unsupported\n", |
| 1740 | __func__, clock_stop_quirks); |
| 1741 | ret = -EINVAL; |
Pierre-Louis Bossart | ebf878e | 2020-08-17 23:29:12 +0800 | [diff] [blame] | 1742 | } |
| 1743 | |
| 1744 | return ret; |
| 1745 | } |
| 1746 | |
Pierre-Louis Bossart | 9b3b4b3 | 2020-07-22 04:37:11 +0800 | [diff] [blame] | 1747 | #endif |
| 1748 | |
| 1749 | static const struct dev_pm_ops intel_pm = { |
| 1750 | SET_SYSTEM_SLEEP_PM_OPS(intel_suspend, intel_resume) |
Pierre-Louis Bossart | ebf878e | 2020-08-17 23:29:12 +0800 | [diff] [blame] | 1751 | SET_RUNTIME_PM_OPS(intel_suspend_runtime, intel_resume_runtime, NULL) |
Pierre-Louis Bossart | 9b3b4b3 | 2020-07-22 04:37:11 +0800 | [diff] [blame] | 1752 | }; |
| 1753 | |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1754 | static struct platform_driver sdw_intel_drv = { |
Pierre-Louis Bossart | b6109dd | 2020-06-01 02:20:57 +0800 | [diff] [blame] | 1755 | .probe = intel_master_probe, |
| 1756 | .remove = intel_master_remove, |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1757 | .driver = { |
Pierre-Louis Bossart | 6d2c666 | 2020-06-01 02:21:02 +0800 | [diff] [blame] | 1758 | .name = "intel-sdw", |
Pierre-Louis Bossart | 9b3b4b3 | 2020-07-22 04:37:11 +0800 | [diff] [blame] | 1759 | .pm = &intel_pm, |
| 1760 | } |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1761 | }; |
| 1762 | |
| 1763 | module_platform_driver(sdw_intel_drv); |
| 1764 | |
| 1765 | MODULE_LICENSE("Dual BSD/GPL"); |
Pierre-Louis Bossart | 6d2c666 | 2020-06-01 02:21:02 +0800 | [diff] [blame] | 1766 | MODULE_ALIAS("platform:intel-sdw"); |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1767 | MODULE_DESCRIPTION("Intel Soundwire Master Driver"); |