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> |
| 16 | #include <sound/soc.h> |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 17 | #include <linux/soundwire/sdw_registers.h> |
| 18 | #include <linux/soundwire/sdw.h> |
| 19 | #include <linux/soundwire/sdw_intel.h> |
| 20 | #include "cadence_master.h" |
Pierre-Louis Bossart | 79ee663 | 2019-08-21 13:58:20 -0500 | [diff] [blame] | 21 | #include "bus.h" |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 22 | #include "intel.h" |
| 23 | |
| 24 | /* Intel SHIM Registers Definition */ |
| 25 | #define SDW_SHIM_LCAP 0x0 |
| 26 | #define SDW_SHIM_LCTL 0x4 |
| 27 | #define SDW_SHIM_IPPTR 0x8 |
| 28 | #define SDW_SHIM_SYNC 0xC |
| 29 | |
Pierre-Louis Bossart | 7cc6e31 | 2019-05-01 10:57:39 -0500 | [diff] [blame] | 30 | #define SDW_SHIM_CTLSCAP(x) (0x010 + 0x60 * (x)) |
| 31 | #define SDW_SHIM_CTLS0CM(x) (0x012 + 0x60 * (x)) |
| 32 | #define SDW_SHIM_CTLS1CM(x) (0x014 + 0x60 * (x)) |
| 33 | #define SDW_SHIM_CTLS2CM(x) (0x016 + 0x60 * (x)) |
| 34 | #define SDW_SHIM_CTLS3CM(x) (0x018 + 0x60 * (x)) |
| 35 | #define SDW_SHIM_PCMSCAP(x) (0x020 + 0x60 * (x)) |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 36 | |
Pierre-Louis Bossart | 7cc6e31 | 2019-05-01 10:57:39 -0500 | [diff] [blame] | 37 | #define SDW_SHIM_PCMSYCHM(x, y) (0x022 + (0x60 * (x)) + (0x2 * (y))) |
| 38 | #define SDW_SHIM_PCMSYCHC(x, y) (0x042 + (0x60 * (x)) + (0x2 * (y))) |
| 39 | #define SDW_SHIM_PDMSCAP(x) (0x062 + 0x60 * (x)) |
| 40 | #define SDW_SHIM_IOCTL(x) (0x06C + 0x60 * (x)) |
| 41 | #define SDW_SHIM_CTMCTL(x) (0x06E + 0x60 * (x)) |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 42 | |
| 43 | #define SDW_SHIM_WAKEEN 0x190 |
| 44 | #define SDW_SHIM_WAKESTS 0x192 |
| 45 | |
| 46 | #define SDW_SHIM_LCTL_SPA BIT(0) |
| 47 | #define SDW_SHIM_LCTL_CPA BIT(8) |
| 48 | |
Pierre-Louis Bossart | 4a17c44 | 2020-07-16 23:09:40 +0800 | [diff] [blame] | 49 | #define SDW_SHIM_SYNC_SYNCPRD_VAL_24 (24000 / SDW_CADENCE_GSYNC_KHZ - 1) |
| 50 | #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] | 51 | #define SDW_SHIM_SYNC_SYNCPRD GENMASK(14, 0) |
| 52 | #define SDW_SHIM_SYNC_SYNCCPU BIT(15) |
| 53 | #define SDW_SHIM_SYNC_CMDSYNC_MASK GENMASK(19, 16) |
| 54 | #define SDW_SHIM_SYNC_CMDSYNC BIT(16) |
| 55 | #define SDW_SHIM_SYNC_SYNCGO BIT(24) |
| 56 | |
| 57 | #define SDW_SHIM_PCMSCAP_ISS GENMASK(3, 0) |
| 58 | #define SDW_SHIM_PCMSCAP_OSS GENMASK(7, 4) |
| 59 | #define SDW_SHIM_PCMSCAP_BSS GENMASK(12, 8) |
| 60 | |
| 61 | #define SDW_SHIM_PCMSYCM_LCHN GENMASK(3, 0) |
| 62 | #define SDW_SHIM_PCMSYCM_HCHN GENMASK(7, 4) |
| 63 | #define SDW_SHIM_PCMSYCM_STREAM GENMASK(13, 8) |
| 64 | #define SDW_SHIM_PCMSYCM_DIR BIT(15) |
| 65 | |
| 66 | #define SDW_SHIM_PDMSCAP_ISS GENMASK(3, 0) |
| 67 | #define SDW_SHIM_PDMSCAP_OSS GENMASK(7, 4) |
| 68 | #define SDW_SHIM_PDMSCAP_BSS GENMASK(12, 8) |
| 69 | #define SDW_SHIM_PDMSCAP_CPSS GENMASK(15, 13) |
| 70 | |
| 71 | #define SDW_SHIM_IOCTL_MIF BIT(0) |
| 72 | #define SDW_SHIM_IOCTL_CO BIT(1) |
| 73 | #define SDW_SHIM_IOCTL_COE BIT(2) |
| 74 | #define SDW_SHIM_IOCTL_DO BIT(3) |
| 75 | #define SDW_SHIM_IOCTL_DOE BIT(4) |
| 76 | #define SDW_SHIM_IOCTL_BKE BIT(5) |
| 77 | #define SDW_SHIM_IOCTL_WPDD BIT(6) |
| 78 | #define SDW_SHIM_IOCTL_CIBD BIT(8) |
| 79 | #define SDW_SHIM_IOCTL_DIBD BIT(9) |
| 80 | |
| 81 | #define SDW_SHIM_CTMCTL_DACTQE BIT(0) |
| 82 | #define SDW_SHIM_CTMCTL_DODS BIT(1) |
| 83 | #define SDW_SHIM_CTMCTL_DOAIS GENMASK(4, 3) |
| 84 | |
| 85 | #define SDW_SHIM_WAKEEN_ENABLE BIT(0) |
| 86 | #define SDW_SHIM_WAKESTS_STATUS BIT(0) |
| 87 | |
| 88 | /* Intel ALH Register definitions */ |
Pierre-Louis Bossart | 7cc6e31 | 2019-05-01 10:57:39 -0500 | [diff] [blame] | 89 | #define SDW_ALH_STRMZCFG(x) (0x000 + (0x4 * (x))) |
Pierre-Louis Bossart | 79ee663 | 2019-08-21 13:58:20 -0500 | [diff] [blame] | 90 | #define SDW_ALH_NUM_STREAMS 64 |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 91 | |
| 92 | #define SDW_ALH_STRMZCFG_DMAT_VAL 0x3 |
| 93 | #define SDW_ALH_STRMZCFG_DMAT GENMASK(7, 0) |
| 94 | #define SDW_ALH_STRMZCFG_CHN GENMASK(19, 16) |
| 95 | |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 96 | enum intel_pdi_type { |
| 97 | INTEL_PDI_IN = 0, |
| 98 | INTEL_PDI_OUT = 1, |
| 99 | INTEL_PDI_BD = 2, |
| 100 | }; |
| 101 | |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 102 | #define cdns_to_intel(_cdns) container_of(_cdns, struct sdw_intel, cdns) |
| 103 | |
| 104 | /* |
| 105 | * Read, write helpers for HW registers |
| 106 | */ |
| 107 | static inline int intel_readl(void __iomem *base, int offset) |
| 108 | { |
| 109 | return readl(base + offset); |
| 110 | } |
| 111 | |
| 112 | static inline void intel_writel(void __iomem *base, int offset, int value) |
| 113 | { |
| 114 | writel(value, base + offset); |
| 115 | } |
| 116 | |
| 117 | static inline u16 intel_readw(void __iomem *base, int offset) |
| 118 | { |
| 119 | return readw(base + offset); |
| 120 | } |
| 121 | |
| 122 | static inline void intel_writew(void __iomem *base, int offset, u16 value) |
| 123 | { |
| 124 | writew(value, base + offset); |
| 125 | } |
| 126 | |
Pierre-Louis Bossart | 7d2845d | 2020-07-16 23:09:39 +0800 | [diff] [blame] | 127 | 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] | 128 | { |
| 129 | int timeout = 10; |
| 130 | u32 reg_read; |
| 131 | |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 132 | do { |
| 133 | reg_read = readl(base + offset); |
Pierre-Louis Bossart | 7d2845d | 2020-07-16 23:09:39 +0800 | [diff] [blame] | 134 | if ((reg_read & mask) == target) |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 135 | return 0; |
| 136 | |
| 137 | timeout--; |
Pierre-Louis Bossart | 7d2845d | 2020-07-16 23:09:39 +0800 | [diff] [blame] | 138 | usleep_range(50, 100); |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 139 | } while (timeout != 0); |
| 140 | |
| 141 | return -EAGAIN; |
| 142 | } |
| 143 | |
Pierre-Louis Bossart | 7d2845d | 2020-07-16 23:09:39 +0800 | [diff] [blame] | 144 | static int intel_clear_bit(void __iomem *base, int offset, u32 value, u32 mask) |
| 145 | { |
| 146 | writel(value, base + offset); |
| 147 | return intel_wait_bit(base, offset, mask, 0); |
| 148 | } |
| 149 | |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 150 | static int intel_set_bit(void __iomem *base, int offset, u32 value, u32 mask) |
| 151 | { |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 152 | writel(value, base + offset); |
Pierre-Louis Bossart | 7d2845d | 2020-07-16 23:09:39 +0800 | [diff] [blame] | 153 | return intel_wait_bit(base, offset, mask, mask); |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | /* |
Pierre-Louis Bossart | 79ee663 | 2019-08-21 13:58:20 -0500 | [diff] [blame] | 157 | * debugfs |
| 158 | */ |
| 159 | #ifdef CONFIG_DEBUG_FS |
| 160 | |
| 161 | #define RD_BUF (2 * PAGE_SIZE) |
| 162 | |
| 163 | static ssize_t intel_sprintf(void __iomem *mem, bool l, |
| 164 | char *buf, size_t pos, unsigned int reg) |
| 165 | { |
| 166 | int value; |
| 167 | |
| 168 | if (l) |
| 169 | value = intel_readl(mem, reg); |
| 170 | else |
| 171 | value = intel_readw(mem, reg); |
| 172 | |
| 173 | return scnprintf(buf + pos, RD_BUF - pos, "%4x\t%4x\n", reg, value); |
| 174 | } |
| 175 | |
| 176 | static int intel_reg_show(struct seq_file *s_file, void *data) |
| 177 | { |
| 178 | struct sdw_intel *sdw = s_file->private; |
Pierre-Louis Bossart | 2523486 | 2020-02-14 19:47:36 -0600 | [diff] [blame] | 179 | void __iomem *s = sdw->link_res->shim; |
| 180 | void __iomem *a = sdw->link_res->alh; |
Pierre-Louis Bossart | 79ee663 | 2019-08-21 13:58:20 -0500 | [diff] [blame] | 181 | char *buf; |
| 182 | ssize_t ret; |
| 183 | int i, j; |
| 184 | unsigned int links, reg; |
| 185 | |
| 186 | buf = kzalloc(RD_BUF, GFP_KERNEL); |
| 187 | if (!buf) |
| 188 | return -ENOMEM; |
| 189 | |
| 190 | links = intel_readl(s, SDW_SHIM_LCAP) & GENMASK(2, 0); |
| 191 | |
| 192 | ret = scnprintf(buf, RD_BUF, "Register Value\n"); |
| 193 | ret += scnprintf(buf + ret, RD_BUF - ret, "\nShim\n"); |
| 194 | |
| 195 | for (i = 0; i < links; i++) { |
| 196 | reg = SDW_SHIM_LCAP + i * 4; |
| 197 | ret += intel_sprintf(s, true, buf, ret, reg); |
| 198 | } |
| 199 | |
| 200 | for (i = 0; i < links; i++) { |
| 201 | ret += scnprintf(buf + ret, RD_BUF - ret, "\nLink%d\n", i); |
| 202 | ret += intel_sprintf(s, false, buf, ret, SDW_SHIM_CTLSCAP(i)); |
| 203 | ret += intel_sprintf(s, false, buf, ret, SDW_SHIM_CTLS0CM(i)); |
| 204 | ret += intel_sprintf(s, false, buf, ret, SDW_SHIM_CTLS1CM(i)); |
| 205 | ret += intel_sprintf(s, false, buf, ret, SDW_SHIM_CTLS2CM(i)); |
| 206 | ret += intel_sprintf(s, false, buf, ret, SDW_SHIM_CTLS3CM(i)); |
| 207 | ret += intel_sprintf(s, false, buf, ret, SDW_SHIM_PCMSCAP(i)); |
| 208 | |
| 209 | ret += scnprintf(buf + ret, RD_BUF - ret, "\n PCMSyCH registers\n"); |
| 210 | |
| 211 | /* |
| 212 | * the value 10 is the number of PDIs. We will need a |
| 213 | * cleanup to remove hard-coded Intel configurations |
| 214 | * from cadence_master.c |
| 215 | */ |
| 216 | for (j = 0; j < 10; j++) { |
| 217 | ret += intel_sprintf(s, false, buf, ret, |
| 218 | SDW_SHIM_PCMSYCHM(i, j)); |
| 219 | ret += intel_sprintf(s, false, buf, ret, |
| 220 | SDW_SHIM_PCMSYCHC(i, j)); |
| 221 | } |
| 222 | ret += scnprintf(buf + ret, RD_BUF - ret, "\n PDMSCAP, IOCTL, CTMCTL\n"); |
| 223 | |
| 224 | ret += intel_sprintf(s, false, buf, ret, SDW_SHIM_PDMSCAP(i)); |
| 225 | ret += intel_sprintf(s, false, buf, ret, SDW_SHIM_IOCTL(i)); |
| 226 | ret += intel_sprintf(s, false, buf, ret, SDW_SHIM_CTMCTL(i)); |
| 227 | } |
| 228 | |
| 229 | ret += scnprintf(buf + ret, RD_BUF - ret, "\nWake registers\n"); |
| 230 | ret += intel_sprintf(s, false, buf, ret, SDW_SHIM_WAKEEN); |
| 231 | ret += intel_sprintf(s, false, buf, ret, SDW_SHIM_WAKESTS); |
| 232 | |
| 233 | ret += scnprintf(buf + ret, RD_BUF - ret, "\nALH STRMzCFG\n"); |
| 234 | for (i = 0; i < SDW_ALH_NUM_STREAMS; i++) |
| 235 | ret += intel_sprintf(a, true, buf, ret, SDW_ALH_STRMZCFG(i)); |
| 236 | |
| 237 | seq_printf(s_file, "%s", buf); |
| 238 | kfree(buf); |
| 239 | |
| 240 | return 0; |
| 241 | } |
| 242 | DEFINE_SHOW_ATTRIBUTE(intel_reg); |
| 243 | |
| 244 | static void intel_debugfs_init(struct sdw_intel *sdw) |
| 245 | { |
| 246 | struct dentry *root = sdw->cdns.bus.debugfs; |
| 247 | |
| 248 | if (!root) |
| 249 | return; |
| 250 | |
| 251 | sdw->debugfs = debugfs_create_dir("intel-sdw", root); |
| 252 | |
| 253 | debugfs_create_file("intel-registers", 0400, sdw->debugfs, sdw, |
| 254 | &intel_reg_fops); |
| 255 | |
| 256 | sdw_cdns_debugfs_init(&sdw->cdns, sdw->debugfs); |
| 257 | } |
| 258 | |
| 259 | static void intel_debugfs_exit(struct sdw_intel *sdw) |
| 260 | { |
| 261 | debugfs_remove_recursive(sdw->debugfs); |
| 262 | } |
| 263 | #else |
| 264 | static void intel_debugfs_init(struct sdw_intel *sdw) {} |
| 265 | static void intel_debugfs_exit(struct sdw_intel *sdw) {} |
| 266 | #endif /* CONFIG_DEBUG_FS */ |
| 267 | |
| 268 | /* |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 269 | * shim ops |
| 270 | */ |
| 271 | |
| 272 | static int intel_link_power_up(struct sdw_intel *sdw) |
| 273 | { |
| 274 | unsigned int link_id = sdw->instance; |
Pierre-Louis Bossart | 2523486 | 2020-02-14 19:47:36 -0600 | [diff] [blame] | 275 | void __iomem *shim = sdw->link_res->shim; |
Pierre-Louis Bossart | 4a17c44 | 2020-07-16 23:09:40 +0800 | [diff] [blame] | 276 | u32 *shim_mask = sdw->link_res->shim_mask; |
| 277 | struct sdw_bus *bus = &sdw->cdns.bus; |
| 278 | struct sdw_master_prop *prop = &bus->prop; |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 279 | int spa_mask, cpa_mask; |
Pierre-Louis Bossart | 4a17c44 | 2020-07-16 23:09:40 +0800 | [diff] [blame] | 280 | int link_control; |
| 281 | int ret = 0; |
| 282 | u32 syncprd; |
| 283 | u32 sync_reg; |
| 284 | |
| 285 | mutex_lock(sdw->link_res->shim_lock); |
| 286 | |
| 287 | /* |
| 288 | * The hardware relies on an internal counter, typically 4kHz, |
| 289 | * to generate the SoundWire SSP - which defines a 'safe' |
| 290 | * synchronization point between commands and audio transport |
| 291 | * and allows for multi link synchronization. The SYNCPRD value |
| 292 | * is only dependent on the oscillator clock provided to |
| 293 | * the IP, so adjust based on _DSD properties reported in DSDT |
| 294 | * tables. The values reported are based on either 24MHz |
| 295 | * (CNL/CML) or 38.4 MHz (ICL/TGL+). |
| 296 | */ |
| 297 | if (prop->mclk_freq % 6000000) |
| 298 | syncprd = SDW_SHIM_SYNC_SYNCPRD_VAL_38_4; |
| 299 | else |
| 300 | syncprd = SDW_SHIM_SYNC_SYNCPRD_VAL_24; |
| 301 | |
| 302 | if (!*shim_mask) { |
| 303 | /* we first need to program the SyncPRD/CPU registers */ |
| 304 | dev_dbg(sdw->cdns.dev, |
| 305 | "%s: first link up, programming SYNCPRD\n", __func__); |
| 306 | |
| 307 | /* set SyncPRD period */ |
| 308 | sync_reg = intel_readl(shim, SDW_SHIM_SYNC); |
| 309 | sync_reg |= (syncprd << |
| 310 | SDW_REG_SHIFT(SDW_SHIM_SYNC_SYNCPRD)); |
| 311 | |
| 312 | /* Set SyncCPU bit */ |
| 313 | sync_reg |= SDW_SHIM_SYNC_SYNCCPU; |
| 314 | intel_writel(shim, SDW_SHIM_SYNC, sync_reg); |
| 315 | } |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 316 | |
| 317 | /* Link power up sequence */ |
| 318 | link_control = intel_readl(shim, SDW_SHIM_LCTL); |
| 319 | spa_mask = (SDW_SHIM_LCTL_SPA << link_id); |
| 320 | cpa_mask = (SDW_SHIM_LCTL_CPA << link_id); |
| 321 | link_control |= spa_mask; |
| 322 | |
| 323 | 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] | 324 | if (ret < 0) { |
| 325 | dev_err(sdw->cdns.dev, "Failed to power up link: %d\n", ret); |
| 326 | goto out; |
| 327 | } |
| 328 | |
| 329 | if (!*shim_mask) { |
| 330 | /* SyncCPU will change once link is active */ |
| 331 | ret = intel_wait_bit(shim, SDW_SHIM_SYNC, |
| 332 | SDW_SHIM_SYNC_SYNCCPU, 0); |
| 333 | if (ret < 0) { |
| 334 | dev_err(sdw->cdns.dev, |
| 335 | "Failed to set SHIM_SYNC: %d\n", ret); |
| 336 | goto out; |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | *shim_mask |= BIT(link_id); |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 341 | |
| 342 | sdw->cdns.link_up = true; |
Pierre-Louis Bossart | 4a17c44 | 2020-07-16 23:09:40 +0800 | [diff] [blame] | 343 | out: |
| 344 | mutex_unlock(sdw->link_res->shim_lock); |
| 345 | |
| 346 | return ret; |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 347 | } |
| 348 | |
Pierre-Louis Bossart | 4a17c44 | 2020-07-16 23:09:40 +0800 | [diff] [blame] | 349 | /* this needs to be called with shim_lock */ |
| 350 | static void intel_shim_glue_to_master_ip(struct sdw_intel *sdw) |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 351 | { |
Pierre-Louis Bossart | 2523486 | 2020-02-14 19:47:36 -0600 | [diff] [blame] | 352 | void __iomem *shim = sdw->link_res->shim; |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 353 | unsigned int link_id = sdw->instance; |
Pierre-Louis Bossart | 4a17c44 | 2020-07-16 23:09:40 +0800 | [diff] [blame] | 354 | u16 ioctl; |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 355 | |
| 356 | /* Switch to MIP from Glue logic */ |
| 357 | ioctl = intel_readw(shim, SDW_SHIM_IOCTL(link_id)); |
| 358 | |
| 359 | ioctl &= ~(SDW_SHIM_IOCTL_DOE); |
| 360 | intel_writew(shim, SDW_SHIM_IOCTL(link_id), ioctl); |
Pierre-Louis Bossart | 4a17c44 | 2020-07-16 23:09:40 +0800 | [diff] [blame] | 361 | usleep_range(10, 15); |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 362 | |
| 363 | ioctl &= ~(SDW_SHIM_IOCTL_DO); |
| 364 | intel_writew(shim, SDW_SHIM_IOCTL(link_id), ioctl); |
Pierre-Louis Bossart | 4a17c44 | 2020-07-16 23:09:40 +0800 | [diff] [blame] | 365 | usleep_range(10, 15); |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 366 | |
| 367 | ioctl |= (SDW_SHIM_IOCTL_MIF); |
| 368 | intel_writew(shim, SDW_SHIM_IOCTL(link_id), ioctl); |
Pierre-Louis Bossart | 4a17c44 | 2020-07-16 23:09:40 +0800 | [diff] [blame] | 369 | usleep_range(10, 15); |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 370 | |
| 371 | ioctl &= ~(SDW_SHIM_IOCTL_BKE); |
| 372 | ioctl &= ~(SDW_SHIM_IOCTL_COE); |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 373 | intel_writew(shim, SDW_SHIM_IOCTL(link_id), ioctl); |
Pierre-Louis Bossart | 4a17c44 | 2020-07-16 23:09:40 +0800 | [diff] [blame] | 374 | usleep_range(10, 15); |
| 375 | |
| 376 | /* at this point Master IP has full control of the I/Os */ |
| 377 | } |
| 378 | |
| 379 | /* this needs to be called with shim_lock */ |
| 380 | static void intel_shim_master_ip_to_glue(struct sdw_intel *sdw) |
| 381 | { |
| 382 | unsigned int link_id = sdw->instance; |
| 383 | void __iomem *shim = sdw->link_res->shim; |
| 384 | u16 ioctl; |
| 385 | |
| 386 | /* Glue logic */ |
| 387 | ioctl = intel_readw(shim, SDW_SHIM_IOCTL(link_id)); |
| 388 | ioctl |= SDW_SHIM_IOCTL_BKE; |
| 389 | ioctl |= SDW_SHIM_IOCTL_COE; |
| 390 | intel_writew(shim, SDW_SHIM_IOCTL(link_id), ioctl); |
| 391 | usleep_range(10, 15); |
| 392 | |
| 393 | ioctl &= ~(SDW_SHIM_IOCTL_MIF); |
| 394 | intel_writew(shim, SDW_SHIM_IOCTL(link_id), ioctl); |
| 395 | usleep_range(10, 15); |
| 396 | |
| 397 | /* at this point Integration Glue has full control of the I/Os */ |
| 398 | } |
| 399 | |
| 400 | static int intel_shim_init(struct sdw_intel *sdw, bool clock_stop) |
| 401 | { |
| 402 | void __iomem *shim = sdw->link_res->shim; |
| 403 | unsigned int link_id = sdw->instance; |
| 404 | int ret = 0; |
| 405 | u16 ioctl = 0, act = 0; |
| 406 | |
| 407 | mutex_lock(sdw->link_res->shim_lock); |
| 408 | |
| 409 | /* Initialize Shim */ |
| 410 | ioctl |= SDW_SHIM_IOCTL_BKE; |
| 411 | intel_writew(shim, SDW_SHIM_IOCTL(link_id), ioctl); |
| 412 | usleep_range(10, 15); |
| 413 | |
| 414 | ioctl |= SDW_SHIM_IOCTL_WPDD; |
| 415 | intel_writew(shim, SDW_SHIM_IOCTL(link_id), ioctl); |
| 416 | usleep_range(10, 15); |
| 417 | |
| 418 | ioctl |= SDW_SHIM_IOCTL_DO; |
| 419 | intel_writew(shim, SDW_SHIM_IOCTL(link_id), ioctl); |
| 420 | usleep_range(10, 15); |
| 421 | |
| 422 | ioctl |= SDW_SHIM_IOCTL_DOE; |
| 423 | intel_writew(shim, SDW_SHIM_IOCTL(link_id), ioctl); |
| 424 | usleep_range(10, 15); |
| 425 | |
| 426 | intel_shim_glue_to_master_ip(sdw); |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 427 | |
| 428 | act |= 0x1 << SDW_REG_SHIFT(SDW_SHIM_CTMCTL_DOAIS); |
| 429 | act |= SDW_SHIM_CTMCTL_DACTQE; |
| 430 | act |= SDW_SHIM_CTMCTL_DODS; |
| 431 | intel_writew(shim, SDW_SHIM_CTMCTL(link_id), act); |
Pierre-Louis Bossart | 4a17c44 | 2020-07-16 23:09:40 +0800 | [diff] [blame] | 432 | usleep_range(10, 15); |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 433 | |
Pierre-Louis Bossart | 4a17c44 | 2020-07-16 23:09:40 +0800 | [diff] [blame] | 434 | mutex_unlock(sdw->link_res->shim_lock); |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 435 | |
| 436 | return ret; |
| 437 | } |
| 438 | |
Pierre-Louis Bossart | 4a17c44 | 2020-07-16 23:09:40 +0800 | [diff] [blame] | 439 | static void __maybe_unused intel_shim_wake(struct sdw_intel *sdw, bool wake_enable) |
| 440 | { |
| 441 | void __iomem *shim = sdw->link_res->shim; |
| 442 | unsigned int link_id = sdw->instance; |
| 443 | u16 wake_en, wake_sts; |
| 444 | |
| 445 | mutex_lock(sdw->link_res->shim_lock); |
| 446 | wake_en = intel_readw(shim, SDW_SHIM_WAKEEN); |
| 447 | |
| 448 | if (wake_enable) { |
| 449 | /* Enable the wakeup */ |
| 450 | wake_en |= (SDW_SHIM_WAKEEN_ENABLE << link_id); |
| 451 | intel_writew(shim, SDW_SHIM_WAKEEN, wake_en); |
| 452 | } else { |
| 453 | /* Disable the wake up interrupt */ |
| 454 | wake_en &= ~(SDW_SHIM_WAKEEN_ENABLE << link_id); |
| 455 | intel_writew(shim, SDW_SHIM_WAKEEN, wake_en); |
| 456 | |
| 457 | /* Clear wake status */ |
| 458 | wake_sts = intel_readw(shim, SDW_SHIM_WAKESTS); |
| 459 | wake_sts |= (SDW_SHIM_WAKEEN_ENABLE << link_id); |
| 460 | intel_writew(shim, SDW_SHIM_WAKESTS_STATUS, wake_sts); |
| 461 | } |
| 462 | mutex_unlock(sdw->link_res->shim_lock); |
| 463 | } |
| 464 | |
| 465 | static int __maybe_unused intel_link_power_down(struct sdw_intel *sdw) |
| 466 | { |
| 467 | int link_control, spa_mask, cpa_mask; |
| 468 | unsigned int link_id = sdw->instance; |
| 469 | void __iomem *shim = sdw->link_res->shim; |
| 470 | u32 *shim_mask = sdw->link_res->shim_mask; |
| 471 | int ret = 0; |
| 472 | |
| 473 | mutex_lock(sdw->link_res->shim_lock); |
| 474 | |
| 475 | intel_shim_master_ip_to_glue(sdw); |
| 476 | |
| 477 | /* Link power down sequence */ |
| 478 | link_control = intel_readl(shim, SDW_SHIM_LCTL); |
| 479 | spa_mask = ~(SDW_SHIM_LCTL_SPA << link_id); |
| 480 | cpa_mask = (SDW_SHIM_LCTL_CPA << link_id); |
| 481 | link_control &= spa_mask; |
| 482 | |
| 483 | ret = intel_clear_bit(shim, SDW_SHIM_LCTL, link_control, cpa_mask); |
| 484 | |
| 485 | if (!(*shim_mask & BIT(link_id))) |
| 486 | dev_err(sdw->cdns.dev, |
| 487 | "%s: Unbalanced power-up/down calls\n", __func__); |
| 488 | |
| 489 | *shim_mask &= ~BIT(link_id); |
| 490 | |
| 491 | mutex_unlock(sdw->link_res->shim_lock); |
| 492 | |
| 493 | if (ret < 0) |
| 494 | return ret; |
| 495 | |
| 496 | sdw->cdns.link_up = false; |
| 497 | return 0; |
| 498 | } |
| 499 | |
Pierre-Louis Bossart | 02629e45 | 2020-07-16 23:09:41 +0800 | [diff] [blame] | 500 | static void intel_shim_sync_arm(struct sdw_intel *sdw) |
| 501 | { |
| 502 | void __iomem *shim = sdw->link_res->shim; |
| 503 | u32 sync_reg; |
| 504 | |
| 505 | mutex_lock(sdw->link_res->shim_lock); |
| 506 | |
| 507 | /* update SYNC register */ |
| 508 | sync_reg = intel_readl(shim, SDW_SHIM_SYNC); |
| 509 | sync_reg |= (SDW_SHIM_SYNC_CMDSYNC << sdw->instance); |
| 510 | intel_writel(shim, SDW_SHIM_SYNC, sync_reg); |
| 511 | |
| 512 | mutex_unlock(sdw->link_res->shim_lock); |
| 513 | } |
| 514 | |
Pierre-Louis Bossart | 437e328 | 2020-07-16 23:09:42 +0800 | [diff] [blame^] | 515 | static int intel_shim_sync_go_unlocked(struct sdw_intel *sdw) |
| 516 | { |
| 517 | void __iomem *shim = sdw->link_res->shim; |
| 518 | u32 sync_reg; |
| 519 | int ret; |
| 520 | |
| 521 | /* Read SYNC register */ |
| 522 | sync_reg = intel_readl(shim, SDW_SHIM_SYNC); |
| 523 | |
| 524 | /* |
| 525 | * Set SyncGO bit to synchronously trigger a bank switch for |
| 526 | * all the masters. A write to SYNCGO bit clears CMDSYNC bit for all |
| 527 | * the Masters. |
| 528 | */ |
| 529 | sync_reg |= SDW_SHIM_SYNC_SYNCGO; |
| 530 | |
| 531 | ret = intel_clear_bit(shim, SDW_SHIM_SYNC, sync_reg, |
| 532 | SDW_SHIM_SYNC_SYNCGO); |
| 533 | |
| 534 | if (ret < 0) |
| 535 | dev_err(sdw->cdns.dev, "SyncGO clear failed: %d\n", ret); |
| 536 | |
| 537 | return ret; |
| 538 | } |
| 539 | |
Vinod Koul | 37a2d22 | 2018-04-26 18:38:58 +0530 | [diff] [blame] | 540 | /* |
| 541 | * PDI routines |
| 542 | */ |
| 543 | static void intel_pdi_init(struct sdw_intel *sdw, |
Pierre-Louis Bossart | d542bc9 | 2019-05-01 10:57:38 -0500 | [diff] [blame] | 544 | struct sdw_cdns_stream_config *config) |
Vinod Koul | 37a2d22 | 2018-04-26 18:38:58 +0530 | [diff] [blame] | 545 | { |
Pierre-Louis Bossart | 2523486 | 2020-02-14 19:47:36 -0600 | [diff] [blame] | 546 | void __iomem *shim = sdw->link_res->shim; |
Vinod Koul | 37a2d22 | 2018-04-26 18:38:58 +0530 | [diff] [blame] | 547 | unsigned int link_id = sdw->instance; |
| 548 | int pcm_cap, pdm_cap; |
| 549 | |
| 550 | /* PCM Stream Capability */ |
| 551 | pcm_cap = intel_readw(shim, SDW_SHIM_PCMSCAP(link_id)); |
| 552 | |
| 553 | config->pcm_bd = (pcm_cap & SDW_SHIM_PCMSCAP_BSS) >> |
| 554 | SDW_REG_SHIFT(SDW_SHIM_PCMSCAP_BSS); |
| 555 | config->pcm_in = (pcm_cap & SDW_SHIM_PCMSCAP_ISS) >> |
| 556 | SDW_REG_SHIFT(SDW_SHIM_PCMSCAP_ISS); |
| 557 | config->pcm_out = (pcm_cap & SDW_SHIM_PCMSCAP_OSS) >> |
| 558 | SDW_REG_SHIFT(SDW_SHIM_PCMSCAP_OSS); |
| 559 | |
Pierre-Louis Bossart | 121f436 | 2019-05-22 14:47:29 -0500 | [diff] [blame] | 560 | dev_dbg(sdw->cdns.dev, "PCM cap bd:%d in:%d out:%d\n", |
| 561 | config->pcm_bd, config->pcm_in, config->pcm_out); |
| 562 | |
Vinod Koul | 37a2d22 | 2018-04-26 18:38:58 +0530 | [diff] [blame] | 563 | /* PDM Stream Capability */ |
| 564 | pdm_cap = intel_readw(shim, SDW_SHIM_PDMSCAP(link_id)); |
| 565 | |
| 566 | config->pdm_bd = (pdm_cap & SDW_SHIM_PDMSCAP_BSS) >> |
| 567 | SDW_REG_SHIFT(SDW_SHIM_PDMSCAP_BSS); |
| 568 | config->pdm_in = (pdm_cap & SDW_SHIM_PDMSCAP_ISS) >> |
| 569 | SDW_REG_SHIFT(SDW_SHIM_PDMSCAP_ISS); |
| 570 | config->pdm_out = (pdm_cap & SDW_SHIM_PDMSCAP_OSS) >> |
| 571 | SDW_REG_SHIFT(SDW_SHIM_PDMSCAP_OSS); |
Pierre-Louis Bossart | 121f436 | 2019-05-22 14:47:29 -0500 | [diff] [blame] | 572 | |
| 573 | dev_dbg(sdw->cdns.dev, "PDM cap bd:%d in:%d out:%d\n", |
| 574 | config->pdm_bd, config->pdm_in, config->pdm_out); |
Vinod Koul | 37a2d22 | 2018-04-26 18:38:58 +0530 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | static int |
| 578 | intel_pdi_get_ch_cap(struct sdw_intel *sdw, unsigned int pdi_num, bool pcm) |
| 579 | { |
Pierre-Louis Bossart | 2523486 | 2020-02-14 19:47:36 -0600 | [diff] [blame] | 580 | void __iomem *shim = sdw->link_res->shim; |
Vinod Koul | 37a2d22 | 2018-04-26 18:38:58 +0530 | [diff] [blame] | 581 | unsigned int link_id = sdw->instance; |
| 582 | int count; |
| 583 | |
| 584 | if (pcm) { |
| 585 | count = intel_readw(shim, SDW_SHIM_PCMSYCHC(link_id, pdi_num)); |
Pierre-Louis Bossart | 1804633 | 2019-08-05 19:55:07 -0500 | [diff] [blame] | 586 | |
| 587 | /* |
| 588 | * WORKAROUND: on all existing Intel controllers, pdi |
| 589 | * number 2 reports channel count as 1 even though it |
| 590 | * supports 8 channels. Performing hardcoding for pdi |
| 591 | * number 2. |
| 592 | */ |
| 593 | if (pdi_num == 2) |
| 594 | count = 7; |
| 595 | |
Vinod Koul | 37a2d22 | 2018-04-26 18:38:58 +0530 | [diff] [blame] | 596 | } else { |
| 597 | count = intel_readw(shim, SDW_SHIM_PDMSCAP(link_id)); |
| 598 | count = ((count & SDW_SHIM_PDMSCAP_CPSS) >> |
| 599 | SDW_REG_SHIFT(SDW_SHIM_PDMSCAP_CPSS)); |
| 600 | } |
| 601 | |
| 602 | /* zero based values for channel count in register */ |
| 603 | count++; |
| 604 | |
| 605 | return count; |
| 606 | } |
| 607 | |
| 608 | static int intel_pdi_get_ch_update(struct sdw_intel *sdw, |
Pierre-Louis Bossart | d542bc9 | 2019-05-01 10:57:38 -0500 | [diff] [blame] | 609 | struct sdw_cdns_pdi *pdi, |
| 610 | unsigned int num_pdi, |
| 611 | unsigned int *num_ch, bool pcm) |
Vinod Koul | 37a2d22 | 2018-04-26 18:38:58 +0530 | [diff] [blame] | 612 | { |
| 613 | int i, ch_count = 0; |
| 614 | |
| 615 | for (i = 0; i < num_pdi; i++) { |
| 616 | pdi->ch_count = intel_pdi_get_ch_cap(sdw, pdi->num, pcm); |
| 617 | ch_count += pdi->ch_count; |
| 618 | pdi++; |
| 619 | } |
| 620 | |
| 621 | *num_ch = ch_count; |
| 622 | return 0; |
| 623 | } |
| 624 | |
| 625 | static int intel_pdi_stream_ch_update(struct sdw_intel *sdw, |
Pierre-Louis Bossart | d542bc9 | 2019-05-01 10:57:38 -0500 | [diff] [blame] | 626 | struct sdw_cdns_streams *stream, bool pcm) |
Vinod Koul | 37a2d22 | 2018-04-26 18:38:58 +0530 | [diff] [blame] | 627 | { |
| 628 | intel_pdi_get_ch_update(sdw, stream->bd, stream->num_bd, |
Pierre-Louis Bossart | d542bc9 | 2019-05-01 10:57:38 -0500 | [diff] [blame] | 629 | &stream->num_ch_bd, pcm); |
Vinod Koul | 37a2d22 | 2018-04-26 18:38:58 +0530 | [diff] [blame] | 630 | |
| 631 | intel_pdi_get_ch_update(sdw, stream->in, stream->num_in, |
Pierre-Louis Bossart | d542bc9 | 2019-05-01 10:57:38 -0500 | [diff] [blame] | 632 | &stream->num_ch_in, pcm); |
Vinod Koul | 37a2d22 | 2018-04-26 18:38:58 +0530 | [diff] [blame] | 633 | |
| 634 | intel_pdi_get_ch_update(sdw, stream->out, stream->num_out, |
Pierre-Louis Bossart | d542bc9 | 2019-05-01 10:57:38 -0500 | [diff] [blame] | 635 | &stream->num_ch_out, pcm); |
Vinod Koul | 37a2d22 | 2018-04-26 18:38:58 +0530 | [diff] [blame] | 636 | |
| 637 | return 0; |
| 638 | } |
| 639 | |
| 640 | static int intel_pdi_ch_update(struct sdw_intel *sdw) |
| 641 | { |
| 642 | /* First update PCM streams followed by PDM streams */ |
| 643 | intel_pdi_stream_ch_update(sdw, &sdw->cdns.pcm, true); |
| 644 | intel_pdi_stream_ch_update(sdw, &sdw->cdns.pdm, false); |
| 645 | |
| 646 | return 0; |
| 647 | } |
| 648 | |
| 649 | static void |
| 650 | intel_pdi_shim_configure(struct sdw_intel *sdw, struct sdw_cdns_pdi *pdi) |
| 651 | { |
Pierre-Louis Bossart | 2523486 | 2020-02-14 19:47:36 -0600 | [diff] [blame] | 652 | void __iomem *shim = sdw->link_res->shim; |
Vinod Koul | 37a2d22 | 2018-04-26 18:38:58 +0530 | [diff] [blame] | 653 | unsigned int link_id = sdw->instance; |
| 654 | int pdi_conf = 0; |
| 655 | |
Pierre-Louis Bossart | c134f91 | 2019-10-22 18:29:48 -0500 | [diff] [blame] | 656 | /* the Bulk and PCM streams are not contiguous */ |
| 657 | pdi->intel_alh_id = (link_id * 16) + pdi->num + 3; |
| 658 | if (pdi->num >= 2) |
| 659 | pdi->intel_alh_id += 2; |
Vinod Koul | 37a2d22 | 2018-04-26 18:38:58 +0530 | [diff] [blame] | 660 | |
| 661 | /* |
| 662 | * Program stream parameters to stream SHIM register |
| 663 | * This is applicable for PCM stream only. |
| 664 | */ |
| 665 | if (pdi->type != SDW_STREAM_PCM) |
| 666 | return; |
| 667 | |
| 668 | if (pdi->dir == SDW_DATA_DIR_RX) |
| 669 | pdi_conf |= SDW_SHIM_PCMSYCM_DIR; |
| 670 | else |
| 671 | pdi_conf &= ~(SDW_SHIM_PCMSYCM_DIR); |
| 672 | |
| 673 | pdi_conf |= (pdi->intel_alh_id << |
| 674 | SDW_REG_SHIFT(SDW_SHIM_PCMSYCM_STREAM)); |
| 675 | pdi_conf |= (pdi->l_ch_num << SDW_REG_SHIFT(SDW_SHIM_PCMSYCM_LCHN)); |
| 676 | pdi_conf |= (pdi->h_ch_num << SDW_REG_SHIFT(SDW_SHIM_PCMSYCM_HCHN)); |
| 677 | |
| 678 | intel_writew(shim, SDW_SHIM_PCMSYCHM(link_id, pdi->num), pdi_conf); |
| 679 | } |
| 680 | |
| 681 | static void |
| 682 | intel_pdi_alh_configure(struct sdw_intel *sdw, struct sdw_cdns_pdi *pdi) |
| 683 | { |
Pierre-Louis Bossart | 2523486 | 2020-02-14 19:47:36 -0600 | [diff] [blame] | 684 | void __iomem *alh = sdw->link_res->alh; |
Vinod Koul | 37a2d22 | 2018-04-26 18:38:58 +0530 | [diff] [blame] | 685 | unsigned int link_id = sdw->instance; |
| 686 | unsigned int conf; |
| 687 | |
Pierre-Louis Bossart | c134f91 | 2019-10-22 18:29:48 -0500 | [diff] [blame] | 688 | /* the Bulk and PCM streams are not contiguous */ |
| 689 | pdi->intel_alh_id = (link_id * 16) + pdi->num + 3; |
| 690 | if (pdi->num >= 2) |
| 691 | pdi->intel_alh_id += 2; |
Vinod Koul | 37a2d22 | 2018-04-26 18:38:58 +0530 | [diff] [blame] | 692 | |
| 693 | /* Program Stream config ALH register */ |
| 694 | conf = intel_readl(alh, SDW_ALH_STRMZCFG(pdi->intel_alh_id)); |
| 695 | |
| 696 | conf |= (SDW_ALH_STRMZCFG_DMAT_VAL << |
| 697 | SDW_REG_SHIFT(SDW_ALH_STRMZCFG_DMAT)); |
| 698 | |
| 699 | conf |= ((pdi->ch_count - 1) << |
| 700 | SDW_REG_SHIFT(SDW_ALH_STRMZCFG_CHN)); |
| 701 | |
| 702 | intel_writel(alh, SDW_ALH_STRMZCFG(pdi->intel_alh_id), conf); |
| 703 | } |
| 704 | |
Rander Wang | 4b206d3 | 2019-12-11 19:45:02 -0600 | [diff] [blame] | 705 | static int intel_params_stream(struct sdw_intel *sdw, |
Pierre-Louis Bossart | d542bc9 | 2019-05-01 10:57:38 -0500 | [diff] [blame] | 706 | struct snd_pcm_substream *substream, |
| 707 | struct snd_soc_dai *dai, |
Rander Wang | 4b206d3 | 2019-12-11 19:45:02 -0600 | [diff] [blame] | 708 | struct snd_pcm_hw_params *hw_params, |
| 709 | int link_id, int alh_stream_id) |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 710 | { |
Pierre-Louis Bossart | 2523486 | 2020-02-14 19:47:36 -0600 | [diff] [blame] | 711 | struct sdw_intel_link_res *res = sdw->link_res; |
Rander Wang | 4b206d3 | 2019-12-11 19:45:02 -0600 | [diff] [blame] | 712 | struct sdw_intel_stream_params_data params_data; |
Pierre-Louis Bossart | 05c8afe4 | 2019-08-05 19:55:06 -0500 | [diff] [blame] | 713 | |
Rander Wang | 4b206d3 | 2019-12-11 19:45:02 -0600 | [diff] [blame] | 714 | params_data.substream = substream; |
| 715 | params_data.dai = dai; |
| 716 | params_data.hw_params = hw_params; |
| 717 | params_data.link_id = link_id; |
| 718 | params_data.alh_stream_id = alh_stream_id; |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 719 | |
Rander Wang | 4b206d3 | 2019-12-11 19:45:02 -0600 | [diff] [blame] | 720 | if (res->ops && res->ops->params_stream && res->dev) |
| 721 | return res->ops->params_stream(res->dev, |
| 722 | ¶ms_data); |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 723 | return -EIO; |
| 724 | } |
| 725 | |
Pierre-Louis Bossart | eff346f | 2020-02-14 19:47:40 -0600 | [diff] [blame] | 726 | static int intel_free_stream(struct sdw_intel *sdw, |
| 727 | struct snd_pcm_substream *substream, |
| 728 | struct snd_soc_dai *dai, |
| 729 | int link_id) |
| 730 | { |
| 731 | struct sdw_intel_link_res *res = sdw->link_res; |
| 732 | struct sdw_intel_stream_free_data free_data; |
| 733 | |
| 734 | free_data.substream = substream; |
| 735 | free_data.dai = dai; |
| 736 | free_data.link_id = link_id; |
| 737 | |
| 738 | if (res->ops && res->ops->free_stream && res->dev) |
| 739 | return res->ops->free_stream(res->dev, |
| 740 | &free_data); |
| 741 | |
| 742 | return 0; |
| 743 | } |
| 744 | |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 745 | /* |
Shreyas NC | 30246e2 | 2018-07-27 14:44:17 +0530 | [diff] [blame] | 746 | * bank switch routines |
| 747 | */ |
| 748 | |
| 749 | static int intel_pre_bank_switch(struct sdw_bus *bus) |
| 750 | { |
| 751 | struct sdw_cdns *cdns = bus_to_cdns(bus); |
| 752 | struct sdw_intel *sdw = cdns_to_intel(cdns); |
Shreyas NC | 30246e2 | 2018-07-27 14:44:17 +0530 | [diff] [blame] | 753 | |
| 754 | /* Write to register only for multi-link */ |
| 755 | if (!bus->multi_link) |
| 756 | return 0; |
| 757 | |
Pierre-Louis Bossart | 02629e45 | 2020-07-16 23:09:41 +0800 | [diff] [blame] | 758 | intel_shim_sync_arm(sdw); |
Pierre-Louis Bossart | 4a17c44 | 2020-07-16 23:09:40 +0800 | [diff] [blame] | 759 | |
Shreyas NC | 30246e2 | 2018-07-27 14:44:17 +0530 | [diff] [blame] | 760 | return 0; |
| 761 | } |
| 762 | |
| 763 | static int intel_post_bank_switch(struct sdw_bus *bus) |
| 764 | { |
| 765 | struct sdw_cdns *cdns = bus_to_cdns(bus); |
| 766 | struct sdw_intel *sdw = cdns_to_intel(cdns); |
Pierre-Louis Bossart | 2523486 | 2020-02-14 19:47:36 -0600 | [diff] [blame] | 767 | void __iomem *shim = sdw->link_res->shim; |
Shreyas NC | 30246e2 | 2018-07-27 14:44:17 +0530 | [diff] [blame] | 768 | int sync_reg, ret; |
| 769 | |
| 770 | /* Write to register only for multi-link */ |
| 771 | if (!bus->multi_link) |
| 772 | return 0; |
| 773 | |
Pierre-Louis Bossart | 4a17c44 | 2020-07-16 23:09:40 +0800 | [diff] [blame] | 774 | mutex_lock(sdw->link_res->shim_lock); |
| 775 | |
Shreyas NC | 30246e2 | 2018-07-27 14:44:17 +0530 | [diff] [blame] | 776 | /* Read SYNC register */ |
| 777 | sync_reg = intel_readl(shim, SDW_SHIM_SYNC); |
| 778 | |
| 779 | /* |
| 780 | * post_bank_switch() ops is called from the bus in loop for |
| 781 | * all the Masters in the steam with the expectation that |
| 782 | * we trigger the bankswitch for the only first Master in the list |
| 783 | * and do nothing for the other Masters |
| 784 | * |
| 785 | * So, set the SYNCGO bit only if CMDSYNC bit is set for any Master. |
| 786 | */ |
Pierre-Louis Bossart | 4a17c44 | 2020-07-16 23:09:40 +0800 | [diff] [blame] | 787 | if (!(sync_reg & SDW_SHIM_SYNC_CMDSYNC_MASK)) { |
| 788 | ret = 0; |
| 789 | goto unlock; |
| 790 | } |
Shreyas NC | 30246e2 | 2018-07-27 14:44:17 +0530 | [diff] [blame] | 791 | |
Pierre-Louis Bossart | 437e328 | 2020-07-16 23:09:42 +0800 | [diff] [blame^] | 792 | ret = intel_shim_sync_go_unlocked(sdw); |
Pierre-Louis Bossart | 4a17c44 | 2020-07-16 23:09:40 +0800 | [diff] [blame] | 793 | unlock: |
| 794 | mutex_unlock(sdw->link_res->shim_lock); |
| 795 | |
Shreyas NC | 30246e2 | 2018-07-27 14:44:17 +0530 | [diff] [blame] | 796 | if (ret < 0) |
Pierre-Louis Bossart | 17ed5be | 2019-05-01 10:57:45 -0500 | [diff] [blame] | 797 | dev_err(sdw->cdns.dev, "Post bank switch failed: %d\n", ret); |
Shreyas NC | 30246e2 | 2018-07-27 14:44:17 +0530 | [diff] [blame] | 798 | |
| 799 | return ret; |
| 800 | } |
| 801 | |
| 802 | /* |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 803 | * DAI routines |
| 804 | */ |
| 805 | |
Rander Wang | 5e7484d | 2020-02-14 19:47:39 -0600 | [diff] [blame] | 806 | static int intel_startup(struct snd_pcm_substream *substream, |
| 807 | struct snd_soc_dai *dai) |
| 808 | { |
| 809 | /* |
| 810 | * TODO: add pm_runtime support here, the startup callback |
| 811 | * will make sure the IP is 'active' |
| 812 | */ |
Pierre-Louis Bossart | ff16d1e | 2020-07-01 02:43:54 +0800 | [diff] [blame] | 813 | return 0; |
Rander Wang | 5e7484d | 2020-02-14 19:47:39 -0600 | [diff] [blame] | 814 | } |
| 815 | |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 816 | static int intel_hw_params(struct snd_pcm_substream *substream, |
Pierre-Louis Bossart | d542bc9 | 2019-05-01 10:57:38 -0500 | [diff] [blame] | 817 | struct snd_pcm_hw_params *params, |
| 818 | struct snd_soc_dai *dai) |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 819 | { |
| 820 | struct sdw_cdns *cdns = snd_soc_dai_get_drvdata(dai); |
| 821 | struct sdw_intel *sdw = cdns_to_intel(cdns); |
| 822 | struct sdw_cdns_dma_data *dma; |
Pierre-Louis Bossart | 57a3479 | 2019-09-16 14:23:46 -0500 | [diff] [blame] | 823 | struct sdw_cdns_pdi *pdi; |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 824 | struct sdw_stream_config sconfig; |
| 825 | struct sdw_port_config *pconfig; |
Pierre-Louis Bossart | 57a3479 | 2019-09-16 14:23:46 -0500 | [diff] [blame] | 826 | int ch, dir; |
| 827 | int ret; |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 828 | bool pcm = true; |
| 829 | |
| 830 | dma = snd_soc_dai_get_dma_data(dai, substream); |
| 831 | if (!dma) |
| 832 | return -EIO; |
| 833 | |
| 834 | ch = params_channels(params); |
| 835 | if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) |
| 836 | dir = SDW_DATA_DIR_RX; |
| 837 | else |
| 838 | dir = SDW_DATA_DIR_TX; |
| 839 | |
Pierre-Louis Bossart | 57a3479 | 2019-09-16 14:23:46 -0500 | [diff] [blame] | 840 | if (dma->stream_type == SDW_STREAM_PDM) |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 841 | pcm = false; |
Pierre-Louis Bossart | 57a3479 | 2019-09-16 14:23:46 -0500 | [diff] [blame] | 842 | |
Pierre-Louis Bossart | 57a3479 | 2019-09-16 14:23:46 -0500 | [diff] [blame] | 843 | if (pcm) |
Bard Liao | 1b53385e | 2019-09-16 14:23:48 -0500 | [diff] [blame] | 844 | 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] | 845 | else |
Bard Liao | 1b53385e | 2019-09-16 14:23:48 -0500 | [diff] [blame] | 846 | 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] | 847 | |
| 848 | if (!pdi) { |
| 849 | ret = -EINVAL; |
| 850 | goto error; |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 851 | } |
| 852 | |
Pierre-Louis Bossart | 57a3479 | 2019-09-16 14:23:46 -0500 | [diff] [blame] | 853 | /* do run-time configurations for SHIM, ALH and PDI/PORT */ |
| 854 | intel_pdi_shim_configure(sdw, pdi); |
| 855 | intel_pdi_alh_configure(sdw, pdi); |
| 856 | sdw_cdns_config_stream(cdns, ch, dir, pdi); |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 857 | |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 858 | |
| 859 | /* Inform DSP about PDI stream number */ |
Rander Wang | 4b206d3 | 2019-12-11 19:45:02 -0600 | [diff] [blame] | 860 | ret = intel_params_stream(sdw, substream, dai, params, |
| 861 | sdw->instance, |
Pierre-Louis Bossart | 57a3479 | 2019-09-16 14:23:46 -0500 | [diff] [blame] | 862 | pdi->intel_alh_id); |
| 863 | if (ret) |
| 864 | goto error; |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 865 | |
| 866 | sconfig.direction = dir; |
| 867 | sconfig.ch_count = ch; |
| 868 | sconfig.frame_rate = params_rate(params); |
| 869 | sconfig.type = dma->stream_type; |
| 870 | |
| 871 | if (dma->stream_type == SDW_STREAM_PDM) { |
| 872 | sconfig.frame_rate *= 50; |
| 873 | sconfig.bps = 1; |
| 874 | } else { |
| 875 | sconfig.bps = snd_pcm_format_width(params_format(params)); |
| 876 | } |
| 877 | |
| 878 | /* Port configuration */ |
Pierre-Louis Bossart | 57a3479 | 2019-09-16 14:23:46 -0500 | [diff] [blame] | 879 | pconfig = kcalloc(1, sizeof(*pconfig), GFP_KERNEL); |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 880 | if (!pconfig) { |
| 881 | ret = -ENOMEM; |
Pierre-Louis Bossart | 57a3479 | 2019-09-16 14:23:46 -0500 | [diff] [blame] | 882 | goto error; |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 883 | } |
| 884 | |
Pierre-Louis Bossart | 57a3479 | 2019-09-16 14:23:46 -0500 | [diff] [blame] | 885 | pconfig->num = pdi->num; |
| 886 | pconfig->ch_mask = (1 << ch) - 1; |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 887 | |
| 888 | ret = sdw_stream_add_master(&cdns->bus, &sconfig, |
Pierre-Louis Bossart | 57a3479 | 2019-09-16 14:23:46 -0500 | [diff] [blame] | 889 | pconfig, 1, dma->stream); |
| 890 | if (ret) |
Pierre-Louis Bossart | 17ed5be | 2019-05-01 10:57:45 -0500 | [diff] [blame] | 891 | dev_err(cdns->dev, "add master to stream failed:%d\n", ret); |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 892 | |
| 893 | kfree(pconfig); |
Pierre-Louis Bossart | 57a3479 | 2019-09-16 14:23:46 -0500 | [diff] [blame] | 894 | error: |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 895 | return ret; |
| 896 | } |
| 897 | |
Rander Wang | 27b198f | 2020-02-14 19:47:37 -0600 | [diff] [blame] | 898 | static int intel_prepare(struct snd_pcm_substream *substream, |
| 899 | struct snd_soc_dai *dai) |
| 900 | { |
| 901 | struct sdw_cdns_dma_data *dma; |
| 902 | |
| 903 | dma = snd_soc_dai_get_dma_data(dai, substream); |
| 904 | if (!dma) { |
| 905 | dev_err(dai->dev, "failed to get dma data in %s", |
| 906 | __func__); |
| 907 | return -EIO; |
| 908 | } |
| 909 | |
| 910 | return sdw_prepare_stream(dma->stream); |
| 911 | } |
| 912 | |
Rander Wang | 973a842 | 2020-02-14 19:47:38 -0600 | [diff] [blame] | 913 | static int intel_trigger(struct snd_pcm_substream *substream, int cmd, |
| 914 | struct snd_soc_dai *dai) |
| 915 | { |
| 916 | struct sdw_cdns_dma_data *dma; |
| 917 | int ret; |
| 918 | |
| 919 | dma = snd_soc_dai_get_dma_data(dai, substream); |
| 920 | if (!dma) { |
| 921 | dev_err(dai->dev, "failed to get dma data in %s", __func__); |
| 922 | return -EIO; |
| 923 | } |
| 924 | |
| 925 | switch (cmd) { |
| 926 | case SNDRV_PCM_TRIGGER_START: |
| 927 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 928 | case SNDRV_PCM_TRIGGER_RESUME: |
| 929 | ret = sdw_enable_stream(dma->stream); |
| 930 | break; |
| 931 | |
| 932 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 933 | case SNDRV_PCM_TRIGGER_SUSPEND: |
| 934 | case SNDRV_PCM_TRIGGER_STOP: |
| 935 | ret = sdw_disable_stream(dma->stream); |
| 936 | break; |
| 937 | |
| 938 | default: |
| 939 | ret = -EINVAL; |
| 940 | break; |
| 941 | } |
| 942 | |
| 943 | if (ret) |
| 944 | dev_err(dai->dev, |
| 945 | "%s trigger %d failed: %d", |
| 946 | __func__, cmd, ret); |
| 947 | return ret; |
| 948 | } |
| 949 | |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 950 | static int |
| 951 | intel_hw_free(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) |
| 952 | { |
| 953 | struct sdw_cdns *cdns = snd_soc_dai_get_drvdata(dai); |
Pierre-Louis Bossart | eff346f | 2020-02-14 19:47:40 -0600 | [diff] [blame] | 954 | struct sdw_intel *sdw = cdns_to_intel(cdns); |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 955 | struct sdw_cdns_dma_data *dma; |
| 956 | int ret; |
| 957 | |
| 958 | dma = snd_soc_dai_get_dma_data(dai, substream); |
| 959 | if (!dma) |
| 960 | return -EIO; |
| 961 | |
Pierre-Louis Bossart | eff346f | 2020-02-14 19:47:40 -0600 | [diff] [blame] | 962 | ret = sdw_deprepare_stream(dma->stream); |
| 963 | if (ret) { |
| 964 | dev_err(dai->dev, "sdw_deprepare_stream: failed %d", ret); |
| 965 | return ret; |
| 966 | } |
| 967 | |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 968 | ret = sdw_stream_remove_master(&cdns->bus, dma->stream); |
Pierre-Louis Bossart | eff346f | 2020-02-14 19:47:40 -0600 | [diff] [blame] | 969 | if (ret < 0) { |
Pierre-Louis Bossart | 17ed5be | 2019-05-01 10:57:45 -0500 | [diff] [blame] | 970 | 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] | 971 | dma->stream->name, ret); |
Pierre-Louis Bossart | eff346f | 2020-02-14 19:47:40 -0600 | [diff] [blame] | 972 | return ret; |
| 973 | } |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 974 | |
Pierre-Louis Bossart | eff346f | 2020-02-14 19:47:40 -0600 | [diff] [blame] | 975 | ret = intel_free_stream(sdw, substream, dai, sdw->instance); |
| 976 | if (ret < 0) { |
| 977 | dev_err(dai->dev, "intel_free_stream: failed %d", ret); |
| 978 | return ret; |
| 979 | } |
| 980 | |
Pierre-Louis Bossart | eff346f | 2020-02-14 19:47:40 -0600 | [diff] [blame] | 981 | return 0; |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 982 | } |
| 983 | |
Pierre-Louis Bossart | 183c768 | 2019-08-05 19:55:22 -0500 | [diff] [blame] | 984 | static void intel_shutdown(struct snd_pcm_substream *substream, |
| 985 | struct snd_soc_dai *dai) |
| 986 | { |
Pierre-Louis Bossart | 183c768 | 2019-08-05 19:55:22 -0500 | [diff] [blame] | 987 | |
Pierre-Louis Bossart | 183c768 | 2019-08-05 19:55:22 -0500 | [diff] [blame] | 988 | } |
| 989 | |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 990 | 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] | 991 | void *stream, int direction) |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 992 | { |
| 993 | return cdns_set_sdw_stream(dai, stream, true, direction); |
| 994 | } |
| 995 | |
| 996 | 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] | 997 | void *stream, int direction) |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 998 | { |
| 999 | return cdns_set_sdw_stream(dai, stream, false, direction); |
| 1000 | } |
| 1001 | |
Pierre-Louis Bossart | 0955314 | 2020-07-01 02:43:52 +0800 | [diff] [blame] | 1002 | static void *intel_get_sdw_stream(struct snd_soc_dai *dai, |
| 1003 | int direction) |
| 1004 | { |
| 1005 | struct sdw_cdns_dma_data *dma; |
| 1006 | |
| 1007 | if (direction == SNDRV_PCM_STREAM_PLAYBACK) |
| 1008 | dma = dai->playback_dma_data; |
| 1009 | else |
| 1010 | dma = dai->capture_dma_data; |
| 1011 | |
| 1012 | if (!dma) |
| 1013 | return NULL; |
| 1014 | |
| 1015 | return dma->stream; |
| 1016 | } |
| 1017 | |
Julia Lawall | b163559 | 2018-10-27 15:34:42 +0200 | [diff] [blame] | 1018 | static const struct snd_soc_dai_ops intel_pcm_dai_ops = { |
Rander Wang | 5e7484d | 2020-02-14 19:47:39 -0600 | [diff] [blame] | 1019 | .startup = intel_startup, |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1020 | .hw_params = intel_hw_params, |
Rander Wang | 27b198f | 2020-02-14 19:47:37 -0600 | [diff] [blame] | 1021 | .prepare = intel_prepare, |
Rander Wang | 973a842 | 2020-02-14 19:47:38 -0600 | [diff] [blame] | 1022 | .trigger = intel_trigger, |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1023 | .hw_free = intel_hw_free, |
Pierre-Louis Bossart | 183c768 | 2019-08-05 19:55:22 -0500 | [diff] [blame] | 1024 | .shutdown = intel_shutdown, |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1025 | .set_sdw_stream = intel_pcm_set_sdw_stream, |
Pierre-Louis Bossart | 0955314 | 2020-07-01 02:43:52 +0800 | [diff] [blame] | 1026 | .get_sdw_stream = intel_get_sdw_stream, |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1027 | }; |
| 1028 | |
Julia Lawall | b163559 | 2018-10-27 15:34:42 +0200 | [diff] [blame] | 1029 | static const struct snd_soc_dai_ops intel_pdm_dai_ops = { |
Rander Wang | 5e7484d | 2020-02-14 19:47:39 -0600 | [diff] [blame] | 1030 | .startup = intel_startup, |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1031 | .hw_params = intel_hw_params, |
Rander Wang | 27b198f | 2020-02-14 19:47:37 -0600 | [diff] [blame] | 1032 | .prepare = intel_prepare, |
Rander Wang | 973a842 | 2020-02-14 19:47:38 -0600 | [diff] [blame] | 1033 | .trigger = intel_trigger, |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1034 | .hw_free = intel_hw_free, |
Pierre-Louis Bossart | 183c768 | 2019-08-05 19:55:22 -0500 | [diff] [blame] | 1035 | .shutdown = intel_shutdown, |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1036 | .set_sdw_stream = intel_pdm_set_sdw_stream, |
Pierre-Louis Bossart | 0955314 | 2020-07-01 02:43:52 +0800 | [diff] [blame] | 1037 | .get_sdw_stream = intel_get_sdw_stream, |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1038 | }; |
| 1039 | |
| 1040 | static const struct snd_soc_component_driver dai_component = { |
| 1041 | .name = "soundwire", |
| 1042 | }; |
| 1043 | |
| 1044 | static int intel_create_dai(struct sdw_cdns *cdns, |
Pierre-Louis Bossart | d542bc9 | 2019-05-01 10:57:38 -0500 | [diff] [blame] | 1045 | struct snd_soc_dai_driver *dais, |
| 1046 | enum intel_pdi_type type, |
| 1047 | u32 num, u32 off, u32 max_ch, bool pcm) |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1048 | { |
| 1049 | int i; |
| 1050 | |
| 1051 | if (num == 0) |
| 1052 | return 0; |
| 1053 | |
| 1054 | /* TODO: Read supported rates/formats from hardware */ |
| 1055 | for (i = off; i < (off + num); i++) { |
| 1056 | dais[i].name = kasprintf(GFP_KERNEL, "SDW%d Pin%d", |
Pierre-Louis Bossart | d542bc9 | 2019-05-01 10:57:38 -0500 | [diff] [blame] | 1057 | cdns->instance, i); |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1058 | if (!dais[i].name) |
| 1059 | return -ENOMEM; |
| 1060 | |
| 1061 | if (type == INTEL_PDI_BD || type == INTEL_PDI_OUT) { |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1062 | dais[i].playback.channels_min = 1; |
| 1063 | dais[i].playback.channels_max = max_ch; |
| 1064 | dais[i].playback.rates = SNDRV_PCM_RATE_48000; |
| 1065 | dais[i].playback.formats = SNDRV_PCM_FMTBIT_S16_LE; |
| 1066 | } |
| 1067 | |
| 1068 | if (type == INTEL_PDI_BD || type == INTEL_PDI_IN) { |
Srinivas Kandagatla | 3919412 | 2019-06-06 12:23:04 +0100 | [diff] [blame] | 1069 | dais[i].capture.channels_min = 1; |
| 1070 | dais[i].capture.channels_max = max_ch; |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1071 | dais[i].capture.rates = SNDRV_PCM_RATE_48000; |
| 1072 | dais[i].capture.formats = SNDRV_PCM_FMTBIT_S16_LE; |
| 1073 | } |
| 1074 | |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1075 | if (pcm) |
| 1076 | dais[i].ops = &intel_pcm_dai_ops; |
| 1077 | else |
| 1078 | dais[i].ops = &intel_pdm_dai_ops; |
| 1079 | } |
| 1080 | |
| 1081 | return 0; |
| 1082 | } |
| 1083 | |
| 1084 | static int intel_register_dai(struct sdw_intel *sdw) |
| 1085 | { |
| 1086 | struct sdw_cdns *cdns = &sdw->cdns; |
| 1087 | struct sdw_cdns_streams *stream; |
| 1088 | struct snd_soc_dai_driver *dais; |
| 1089 | int num_dai, ret, off = 0; |
| 1090 | |
| 1091 | /* DAIs are created based on total number of PDIs supported */ |
| 1092 | num_dai = cdns->pcm.num_pdi + cdns->pdm.num_pdi; |
| 1093 | |
| 1094 | dais = devm_kcalloc(cdns->dev, num_dai, sizeof(*dais), GFP_KERNEL); |
| 1095 | if (!dais) |
| 1096 | return -ENOMEM; |
| 1097 | |
| 1098 | /* Create PCM DAIs */ |
| 1099 | stream = &cdns->pcm; |
| 1100 | |
Bard Liao | cf92496 | 2019-09-16 14:23:43 -0500 | [diff] [blame] | 1101 | 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] | 1102 | off, stream->num_ch_in, true); |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1103 | if (ret) |
| 1104 | return ret; |
| 1105 | |
| 1106 | off += cdns->pcm.num_in; |
Vinod Koul | 1215dae | 2019-05-02 16:29:25 +0530 | [diff] [blame] | 1107 | ret = intel_create_dai(cdns, dais, INTEL_PDI_OUT, cdns->pcm.num_out, |
| 1108 | off, stream->num_ch_out, true); |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1109 | if (ret) |
| 1110 | return ret; |
| 1111 | |
| 1112 | off += cdns->pcm.num_out; |
Vinod Koul | 1215dae | 2019-05-02 16:29:25 +0530 | [diff] [blame] | 1113 | ret = intel_create_dai(cdns, dais, INTEL_PDI_BD, cdns->pcm.num_bd, |
| 1114 | off, stream->num_ch_bd, true); |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1115 | if (ret) |
| 1116 | return ret; |
| 1117 | |
| 1118 | /* Create PDM DAIs */ |
| 1119 | stream = &cdns->pdm; |
| 1120 | off += cdns->pcm.num_bd; |
Vinod Koul | 1215dae | 2019-05-02 16:29:25 +0530 | [diff] [blame] | 1121 | ret = intel_create_dai(cdns, dais, INTEL_PDI_IN, cdns->pdm.num_in, |
| 1122 | off, stream->num_ch_in, false); |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1123 | if (ret) |
| 1124 | return ret; |
| 1125 | |
| 1126 | off += cdns->pdm.num_in; |
Vinod Koul | 1215dae | 2019-05-02 16:29:25 +0530 | [diff] [blame] | 1127 | ret = intel_create_dai(cdns, dais, INTEL_PDI_OUT, cdns->pdm.num_out, |
| 1128 | off, stream->num_ch_out, false); |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1129 | if (ret) |
| 1130 | return ret; |
| 1131 | |
Bard Liao | cf92496 | 2019-09-16 14:23:43 -0500 | [diff] [blame] | 1132 | off += cdns->pdm.num_out; |
Vinod Koul | 1215dae | 2019-05-02 16:29:25 +0530 | [diff] [blame] | 1133 | ret = intel_create_dai(cdns, dais, INTEL_PDI_BD, cdns->pdm.num_bd, |
| 1134 | off, stream->num_ch_bd, false); |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1135 | if (ret) |
| 1136 | return ret; |
| 1137 | |
| 1138 | return snd_soc_register_component(cdns->dev, &dai_component, |
Pierre-Louis Bossart | d542bc9 | 2019-05-01 10:57:38 -0500 | [diff] [blame] | 1139 | dais, num_dai); |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1140 | } |
| 1141 | |
Pierre-Louis Bossart | 085f4ac | 2019-08-05 19:55:16 -0500 | [diff] [blame] | 1142 | static int sdw_master_read_intel_prop(struct sdw_bus *bus) |
| 1143 | { |
| 1144 | struct sdw_master_prop *prop = &bus->prop; |
| 1145 | struct fwnode_handle *link; |
| 1146 | char name[32]; |
Pierre-Louis Bossart | 395713d | 2019-08-21 13:58:21 -0500 | [diff] [blame] | 1147 | u32 quirk_mask; |
Pierre-Louis Bossart | 085f4ac | 2019-08-05 19:55:16 -0500 | [diff] [blame] | 1148 | |
| 1149 | /* Find master handle */ |
| 1150 | snprintf(name, sizeof(name), |
| 1151 | "mipi-sdw-link-%d-subproperties", bus->link_id); |
| 1152 | |
| 1153 | link = device_get_named_child_node(bus->dev, name); |
| 1154 | if (!link) { |
| 1155 | dev_err(bus->dev, "Master node %s not found\n", name); |
| 1156 | return -EIO; |
| 1157 | } |
| 1158 | |
| 1159 | fwnode_property_read_u32(link, |
| 1160 | "intel-sdw-ip-clock", |
| 1161 | &prop->mclk_freq); |
Pierre-Louis Bossart | 395713d | 2019-08-21 13:58:21 -0500 | [diff] [blame] | 1162 | |
Bard Liao | a19efb5 | 2020-01-13 17:11:29 -0600 | [diff] [blame] | 1163 | /* the values reported by BIOS are the 2x clock, not the bus clock */ |
| 1164 | prop->mclk_freq /= 2; |
| 1165 | |
Pierre-Louis Bossart | 395713d | 2019-08-21 13:58:21 -0500 | [diff] [blame] | 1166 | fwnode_property_read_u32(link, |
| 1167 | "intel-quirk-mask", |
| 1168 | &quirk_mask); |
| 1169 | |
| 1170 | if (quirk_mask & SDW_INTEL_QUIRK_MASK_BUS_DISABLE) |
| 1171 | prop->hw_disabled = true; |
| 1172 | |
Pierre-Louis Bossart | 085f4ac | 2019-08-05 19:55:16 -0500 | [diff] [blame] | 1173 | return 0; |
| 1174 | } |
| 1175 | |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1176 | static int intel_prop_read(struct sdw_bus *bus) |
| 1177 | { |
| 1178 | /* Initialize with default handler to read all DisCo properties */ |
| 1179 | sdw_master_read_prop(bus); |
| 1180 | |
Pierre-Louis Bossart | 085f4ac | 2019-08-05 19:55:16 -0500 | [diff] [blame] | 1181 | /* read Intel-specific properties */ |
| 1182 | sdw_master_read_intel_prop(bus); |
| 1183 | |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1184 | return 0; |
| 1185 | } |
| 1186 | |
Shreyas NC | c91605f | 2018-04-26 18:38:43 +0530 | [diff] [blame] | 1187 | static struct sdw_master_ops sdw_intel_ops = { |
| 1188 | .read_prop = sdw_master_read_prop, |
| 1189 | .xfer_msg = cdns_xfer_msg, |
| 1190 | .xfer_msg_defer = cdns_xfer_msg_defer, |
| 1191 | .reset_page_addr = cdns_reset_page_addr, |
Vinod Koul | 07abeff | 2018-04-26 18:38:48 +0530 | [diff] [blame] | 1192 | .set_bus_conf = cdns_bus_conf, |
Shreyas NC | 30246e2 | 2018-07-27 14:44:17 +0530 | [diff] [blame] | 1193 | .pre_bank_switch = intel_pre_bank_switch, |
| 1194 | .post_bank_switch = intel_post_bank_switch, |
Shreyas NC | c91605f | 2018-04-26 18:38:43 +0530 | [diff] [blame] | 1195 | }; |
| 1196 | |
Pierre-Louis Bossart | dfbe642 | 2019-10-22 18:54:46 -0500 | [diff] [blame] | 1197 | static int intel_init(struct sdw_intel *sdw) |
| 1198 | { |
Pierre-Louis Bossart | 4a17c44 | 2020-07-16 23:09:40 +0800 | [diff] [blame] | 1199 | bool clock_stop; |
| 1200 | |
Pierre-Louis Bossart | dfbe642 | 2019-10-22 18:54:46 -0500 | [diff] [blame] | 1201 | /* Initialize shim and controller */ |
| 1202 | intel_link_power_up(sdw); |
Pierre-Louis Bossart | 4a17c44 | 2020-07-16 23:09:40 +0800 | [diff] [blame] | 1203 | |
| 1204 | clock_stop = sdw_cdns_is_clock_stop(&sdw->cdns); |
| 1205 | |
| 1206 | intel_shim_init(sdw, clock_stop); |
| 1207 | |
| 1208 | if (clock_stop) |
| 1209 | return 0; |
Pierre-Louis Bossart | dfbe642 | 2019-10-22 18:54:46 -0500 | [diff] [blame] | 1210 | |
Rander Wang | 7b174f2 | 2020-03-17 11:33:14 -0500 | [diff] [blame] | 1211 | return sdw_cdns_init(&sdw->cdns); |
Pierre-Louis Bossart | dfbe642 | 2019-10-22 18:54:46 -0500 | [diff] [blame] | 1212 | } |
| 1213 | |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1214 | /* |
| 1215 | * probe and init |
| 1216 | */ |
Pierre-Louis Bossart | b6109dd | 2020-06-01 02:20:57 +0800 | [diff] [blame] | 1217 | static int intel_master_probe(struct platform_device *pdev) |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1218 | { |
Pierre-Louis Bossart | b6109dd | 2020-06-01 02:20:57 +0800 | [diff] [blame] | 1219 | struct device *dev = &pdev->dev; |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1220 | struct sdw_intel *sdw; |
Pierre-Louis Bossart | 83e129af | 2020-06-01 02:20:58 +0800 | [diff] [blame] | 1221 | struct sdw_cdns *cdns; |
Pierre-Louis Bossart | b6109dd | 2020-06-01 02:20:57 +0800 | [diff] [blame] | 1222 | struct sdw_bus *bus; |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1223 | int ret; |
| 1224 | |
Pierre-Louis Bossart | b6109dd | 2020-06-01 02:20:57 +0800 | [diff] [blame] | 1225 | sdw = devm_kzalloc(dev, sizeof(*sdw), GFP_KERNEL); |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1226 | if (!sdw) |
| 1227 | return -ENOMEM; |
| 1228 | |
Pierre-Louis Bossart | 83e129af | 2020-06-01 02:20:58 +0800 | [diff] [blame] | 1229 | cdns = &sdw->cdns; |
| 1230 | bus = &cdns->bus; |
Pierre-Louis Bossart | b6109dd | 2020-06-01 02:20:57 +0800 | [diff] [blame] | 1231 | |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1232 | sdw->instance = pdev->id; |
Pierre-Louis Bossart | b6109dd | 2020-06-01 02:20:57 +0800 | [diff] [blame] | 1233 | sdw->link_res = dev_get_platdata(dev); |
Pierre-Louis Bossart | 83e129af | 2020-06-01 02:20:58 +0800 | [diff] [blame] | 1234 | cdns->dev = dev; |
| 1235 | cdns->registers = sdw->link_res->registers; |
| 1236 | cdns->instance = sdw->instance; |
| 1237 | cdns->msg_count = 0; |
| 1238 | |
Pierre-Louis Bossart | b6109dd | 2020-06-01 02:20:57 +0800 | [diff] [blame] | 1239 | bus->link_id = pdev->id; |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1240 | |
Pierre-Louis Bossart | 83e129af | 2020-06-01 02:20:58 +0800 | [diff] [blame] | 1241 | sdw_cdns_probe(cdns); |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1242 | |
| 1243 | /* Set property read ops */ |
Shreyas NC | c91605f | 2018-04-26 18:38:43 +0530 | [diff] [blame] | 1244 | sdw_intel_ops.read_prop = intel_prop_read; |
Pierre-Louis Bossart | b6109dd | 2020-06-01 02:20:57 +0800 | [diff] [blame] | 1245 | bus->ops = &sdw_intel_ops; |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1246 | |
Pierre-Louis Bossart | b6109dd | 2020-06-01 02:20:57 +0800 | [diff] [blame] | 1247 | /* set driver data, accessed by snd_soc_dai_get_drvdata() */ |
Pierre-Louis Bossart | 83e129af | 2020-06-01 02:20:58 +0800 | [diff] [blame] | 1248 | dev_set_drvdata(dev, cdns); |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1249 | |
Pierre-Louis Bossart | b6109dd | 2020-06-01 02:20:57 +0800 | [diff] [blame] | 1250 | ret = sdw_bus_master_add(bus, dev, dev->fwnode); |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1251 | if (ret) { |
Pierre-Louis Bossart | b6109dd | 2020-06-01 02:20:57 +0800 | [diff] [blame] | 1252 | dev_err(dev, "sdw_bus_master_add fail: %d\n", ret); |
Pierre-Louis Bossart | 9e3d47f | 2019-10-22 18:54:47 -0500 | [diff] [blame] | 1253 | return ret; |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1254 | } |
| 1255 | |
Pierre-Louis Bossart | 6d2c666 | 2020-06-01 02:21:02 +0800 | [diff] [blame] | 1256 | if (bus->prop.hw_disabled) |
Pierre-Louis Bossart | b6109dd | 2020-06-01 02:20:57 +0800 | [diff] [blame] | 1257 | dev_info(dev, |
| 1258 | "SoundWire master %d is disabled, will be ignored\n", |
| 1259 | bus->link_id); |
Pierre-Louis Bossart | 6d2c666 | 2020-06-01 02:21:02 +0800 | [diff] [blame] | 1260 | |
| 1261 | /* Acquire IRQ */ |
| 1262 | ret = request_threaded_irq(sdw->link_res->irq, |
| 1263 | sdw_cdns_irq, sdw_cdns_thread, |
| 1264 | IRQF_SHARED, KBUILD_MODNAME, cdns); |
| 1265 | if (ret < 0) { |
| 1266 | dev_err(dev, "unable to grab IRQ %d, disabling device\n", |
| 1267 | sdw->link_res->irq); |
| 1268 | goto err_init; |
| 1269 | } |
| 1270 | |
| 1271 | return 0; |
| 1272 | |
| 1273 | err_init: |
| 1274 | sdw_bus_master_delete(bus); |
| 1275 | return ret; |
| 1276 | } |
| 1277 | |
| 1278 | int intel_master_startup(struct platform_device *pdev) |
| 1279 | { |
| 1280 | struct sdw_cdns_stream_config config; |
| 1281 | struct device *dev = &pdev->dev; |
| 1282 | struct sdw_cdns *cdns = dev_get_drvdata(dev); |
| 1283 | struct sdw_intel *sdw = cdns_to_intel(cdns); |
| 1284 | struct sdw_bus *bus = &cdns->bus; |
| 1285 | int ret; |
| 1286 | |
| 1287 | if (bus->prop.hw_disabled) { |
| 1288 | dev_info(dev, |
| 1289 | "SoundWire master %d is disabled, ignoring\n", |
| 1290 | sdw->instance); |
Pierre-Louis Bossart | 395713d | 2019-08-21 13:58:21 -0500 | [diff] [blame] | 1291 | return 0; |
| 1292 | } |
| 1293 | |
Pierre-Louis Bossart | dfbe642 | 2019-10-22 18:54:46 -0500 | [diff] [blame] | 1294 | /* Initialize shim, controller and Cadence IP */ |
| 1295 | ret = intel_init(sdw); |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1296 | if (ret) |
| 1297 | goto err_init; |
| 1298 | |
Vinod Koul | 37a2d22 | 2018-04-26 18:38:58 +0530 | [diff] [blame] | 1299 | /* Read the PDI config and initialize cadence PDI */ |
| 1300 | intel_pdi_init(sdw, &config); |
Pierre-Louis Bossart | 83e129af | 2020-06-01 02:20:58 +0800 | [diff] [blame] | 1301 | ret = sdw_cdns_pdi_init(cdns, config); |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1302 | if (ret) |
| 1303 | goto err_init; |
| 1304 | |
Vinod Koul | 37a2d22 | 2018-04-26 18:38:58 +0530 | [diff] [blame] | 1305 | intel_pdi_ch_update(sdw); |
| 1306 | |
Pierre-Louis Bossart | 83e129af | 2020-06-01 02:20:58 +0800 | [diff] [blame] | 1307 | ret = sdw_cdns_enable_interrupt(cdns, true); |
Pierre-Louis Bossart | 49ea07d | 2019-10-22 18:54:44 -0500 | [diff] [blame] | 1308 | if (ret < 0) { |
Pierre-Louis Bossart | b6109dd | 2020-06-01 02:20:57 +0800 | [diff] [blame] | 1309 | dev_err(dev, "cannot enable interrupts\n"); |
Pierre-Louis Bossart | 49ea07d | 2019-10-22 18:54:44 -0500 | [diff] [blame] | 1310 | goto err_init; |
| 1311 | } |
| 1312 | |
Pierre-Louis Bossart | 83e129af | 2020-06-01 02:20:58 +0800 | [diff] [blame] | 1313 | ret = sdw_cdns_exit_reset(cdns); |
Pierre-Louis Bossart | 49ea07d | 2019-10-22 18:54:44 -0500 | [diff] [blame] | 1314 | if (ret < 0) { |
Pierre-Louis Bossart | b6109dd | 2020-06-01 02:20:57 +0800 | [diff] [blame] | 1315 | dev_err(dev, "unable to exit bus reset sequence\n"); |
Pierre-Louis Bossart | 9e3d47f | 2019-10-22 18:54:47 -0500 | [diff] [blame] | 1316 | goto err_interrupt; |
Pierre-Louis Bossart | 49ea07d | 2019-10-22 18:54:44 -0500 | [diff] [blame] | 1317 | } |
| 1318 | |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1319 | /* Register DAIs */ |
| 1320 | ret = intel_register_dai(sdw); |
| 1321 | if (ret) { |
Pierre-Louis Bossart | b6109dd | 2020-06-01 02:20:57 +0800 | [diff] [blame] | 1322 | dev_err(dev, "DAI registration failed: %d\n", ret); |
| 1323 | snd_soc_unregister_component(dev); |
Pierre-Louis Bossart | 9e3d47f | 2019-10-22 18:54:47 -0500 | [diff] [blame] | 1324 | goto err_interrupt; |
Vinod Koul | c46302e | 2018-04-26 18:39:05 +0530 | [diff] [blame] | 1325 | } |
| 1326 | |
Pierre-Louis Bossart | 79ee663 | 2019-08-21 13:58:20 -0500 | [diff] [blame] | 1327 | intel_debugfs_init(sdw); |
| 1328 | |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1329 | return 0; |
| 1330 | |
Pierre-Louis Bossart | 9e3d47f | 2019-10-22 18:54:47 -0500 | [diff] [blame] | 1331 | err_interrupt: |
Pierre-Louis Bossart | 83e129af | 2020-06-01 02:20:58 +0800 | [diff] [blame] | 1332 | sdw_cdns_enable_interrupt(cdns, false); |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1333 | err_init: |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1334 | return ret; |
| 1335 | } |
| 1336 | |
Pierre-Louis Bossart | b6109dd | 2020-06-01 02:20:57 +0800 | [diff] [blame] | 1337 | static int intel_master_remove(struct platform_device *pdev) |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1338 | { |
Pierre-Louis Bossart | b6109dd | 2020-06-01 02:20:57 +0800 | [diff] [blame] | 1339 | struct device *dev = &pdev->dev; |
Pierre-Louis Bossart | 83e129af | 2020-06-01 02:20:58 +0800 | [diff] [blame] | 1340 | struct sdw_cdns *cdns = dev_get_drvdata(dev); |
| 1341 | struct sdw_intel *sdw = cdns_to_intel(cdns); |
| 1342 | struct sdw_bus *bus = &cdns->bus; |
Pierre-Louis Bossart | b6109dd | 2020-06-01 02:20:57 +0800 | [diff] [blame] | 1343 | |
| 1344 | if (!bus->prop.hw_disabled) { |
Pierre-Louis Bossart | 395713d | 2019-08-21 13:58:21 -0500 | [diff] [blame] | 1345 | intel_debugfs_exit(sdw); |
Pierre-Louis Bossart | 83e129af | 2020-06-01 02:20:58 +0800 | [diff] [blame] | 1346 | sdw_cdns_enable_interrupt(cdns, false); |
Pierre-Louis Bossart | 2523486 | 2020-02-14 19:47:36 -0600 | [diff] [blame] | 1347 | free_irq(sdw->link_res->irq, sdw); |
Pierre-Louis Bossart | b6109dd | 2020-06-01 02:20:57 +0800 | [diff] [blame] | 1348 | snd_soc_unregister_component(dev); |
Pierre-Louis Bossart | 395713d | 2019-08-21 13:58:21 -0500 | [diff] [blame] | 1349 | } |
Pierre-Louis Bossart | b6109dd | 2020-06-01 02:20:57 +0800 | [diff] [blame] | 1350 | sdw_bus_master_delete(bus); |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1351 | |
| 1352 | return 0; |
| 1353 | } |
| 1354 | |
| 1355 | static struct platform_driver sdw_intel_drv = { |
Pierre-Louis Bossart | b6109dd | 2020-06-01 02:20:57 +0800 | [diff] [blame] | 1356 | .probe = intel_master_probe, |
| 1357 | .remove = intel_master_remove, |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1358 | .driver = { |
Pierre-Louis Bossart | 6d2c666 | 2020-06-01 02:21:02 +0800 | [diff] [blame] | 1359 | .name = "intel-sdw", |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1360 | }, |
| 1361 | }; |
| 1362 | |
| 1363 | module_platform_driver(sdw_intel_drv); |
| 1364 | |
| 1365 | MODULE_LICENSE("Dual BSD/GPL"); |
Pierre-Louis Bossart | 6d2c666 | 2020-06-01 02:21:02 +0800 | [diff] [blame] | 1366 | MODULE_ALIAS("platform:intel-sdw"); |
Vinod Koul | 71bb8a1 | 2017-12-14 11:19:43 +0530 | [diff] [blame] | 1367 | MODULE_DESCRIPTION("Intel Soundwire Master Driver"); |