Meng Wang | 43bbb87 | 2018-12-10 12:32:05 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Meng Wang | 61af684 | 2018-09-10 17:47:55 +0800 | [diff] [blame] | 2 | /* |
Aditya Bavanari | 3517b11 | 2018-12-03 13:26:59 +0530 | [diff] [blame] | 3 | * Copyright (c) 2015-2019, The Linux Foundation. All rights reserved. |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <linux/irq.h> |
| 7 | #include <linux/kernel.h> |
| 8 | #include <linux/init.h> |
| 9 | #include <linux/slab.h> |
| 10 | #include <linux/io.h> |
| 11 | #include <linux/interrupt.h> |
| 12 | #include <linux/platform_device.h> |
| 13 | #include <linux/delay.h> |
| 14 | #include <linux/kthread.h> |
Ramprasad Katkam | cab8d72 | 2018-09-28 15:54:06 +0530 | [diff] [blame] | 15 | #include <linux/bitops.h> |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 16 | #include <linux/clk.h> |
Laxminath Kasam | a60239e | 2019-01-10 14:43:03 +0530 | [diff] [blame] | 17 | #include <linux/gpio.h> |
| 18 | #include <linux/of_gpio.h> |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 19 | #include <linux/pm_runtime.h> |
| 20 | #include <linux/of.h> |
| 21 | #include <linux/debugfs.h> |
| 22 | #include <linux/uaccess.h> |
| 23 | #include <soc/soundwire.h> |
Sudheer Papothi | 3d1596e | 2018-10-27 06:19:18 +0530 | [diff] [blame] | 24 | #include <soc/swr-common.h> |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 25 | #include <linux/regmap.h> |
Ramprasad Katkam | 68765ab | 2018-08-30 11:46:32 +0530 | [diff] [blame] | 26 | #include <dsp/msm-audio-event-notify.h> |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 27 | #include "swrm_registers.h" |
| 28 | #include "swr-mstr-ctrl.h" |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 29 | |
Ramprasad Katkam | 5734987 | 2018-11-11 18:34:57 +0530 | [diff] [blame] | 30 | #define SWRM_SYSTEM_RESUME_TIMEOUT_MS 700 |
| 31 | #define SWRM_SYS_SUSPEND_WAIT 1 |
Sudheer Papothi | 3d1596e | 2018-10-27 06:19:18 +0530 | [diff] [blame] | 32 | |
Sudheer Papothi | 4c322b1 | 2018-10-31 06:34:01 +0530 | [diff] [blame] | 33 | #define SWRM_DSD_PARAMS_PORT 4 |
| 34 | |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 35 | #define SWR_BROADCAST_CMD_ID 0x0F |
| 36 | #define SWR_AUTO_SUSPEND_DELAY 3 /* delay in sec */ |
Sudheer Papothi | 7c067e8 | 2018-11-15 06:53:35 +0530 | [diff] [blame] | 37 | #define SWR_DEV_ID_MASK 0xFFFFFFFFFFFF |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 38 | #define SWR_REG_VAL_PACK(data, dev, id, reg) \ |
| 39 | ((reg) | ((id) << 16) | ((dev) << 20) | ((data) << 24)) |
| 40 | |
Ramprasad Katkam | 14f47cc | 2018-07-25 17:20:18 +0530 | [diff] [blame] | 41 | #define SWR_INVALID_PARAM 0xFF |
Laxminath Kasam | 990c70b | 2018-11-09 23:15:09 +0530 | [diff] [blame] | 42 | #define SWR_HSTOP_MAX_VAL 0xF |
| 43 | #define SWR_HSTART_MIN_VAL 0x0 |
Ramprasad Katkam | 14f47cc | 2018-07-25 17:20:18 +0530 | [diff] [blame] | 44 | |
Ramprasad Katkam | 8330351 | 2018-10-11 17:34:22 +0530 | [diff] [blame] | 45 | #define SWRM_INTERRUPT_STATUS_MASK 0x1FDFD |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 46 | /* pm runtime auto suspend timer in msecs */ |
| 47 | static int auto_suspend_timer = SWR_AUTO_SUSPEND_DELAY * 1000; |
| 48 | module_param(auto_suspend_timer, int, 0664); |
| 49 | MODULE_PARM_DESC(auto_suspend_timer, "timer for auto suspend"); |
| 50 | |
| 51 | enum { |
| 52 | SWR_NOT_PRESENT, /* Device is detached/not present on the bus */ |
| 53 | SWR_ATTACHED_OK, /* Device is attached */ |
| 54 | SWR_ALERT, /* Device alters master for any interrupts */ |
| 55 | SWR_RESERVED, /* Reserved */ |
| 56 | }; |
| 57 | |
| 58 | enum { |
| 59 | MASTER_ID_WSA = 1, |
| 60 | MASTER_ID_RX, |
| 61 | MASTER_ID_TX |
| 62 | }; |
Ramprasad Katkam | cab8d72 | 2018-09-28 15:54:06 +0530 | [diff] [blame] | 63 | |
| 64 | enum { |
| 65 | ENABLE_PENDING, |
| 66 | DISABLE_PENDING |
| 67 | }; |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 68 | #define TRUE 1 |
| 69 | #define FALSE 0 |
| 70 | |
Ramprasad Katkam | 1f22126 | 2018-08-23 15:01:22 +0530 | [diff] [blame] | 71 | #define SWRM_MAX_PORT_REG 120 |
Ramprasad Katkam | 8330351 | 2018-10-11 17:34:22 +0530 | [diff] [blame] | 72 | #define SWRM_MAX_INIT_REG 11 |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 73 | |
| 74 | #define SWR_MSTR_MAX_REG_ADDR 0x1740 |
| 75 | #define SWR_MSTR_START_REG_ADDR 0x00 |
| 76 | #define SWR_MSTR_MAX_BUF_LEN 32 |
| 77 | #define BYTES_PER_LINE 12 |
| 78 | #define SWR_MSTR_RD_BUF_LEN 8 |
| 79 | #define SWR_MSTR_WR_BUF_LEN 32 |
| 80 | |
Laxminath Kasam | fbcaf32 | 2018-07-18 00:38:14 +0530 | [diff] [blame] | 81 | #define MAX_FIFO_RD_FAIL_RETRY 3 |
| 82 | |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 83 | static struct swr_mstr_ctrl *dbgswrm; |
| 84 | static struct dentry *debugfs_swrm_dent; |
| 85 | static struct dentry *debugfs_peek; |
| 86 | static struct dentry *debugfs_poke; |
| 87 | static struct dentry *debugfs_reg_dump; |
| 88 | static unsigned int read_data; |
| 89 | |
Ramprasad Katkam | 5734987 | 2018-11-11 18:34:57 +0530 | [diff] [blame] | 90 | static bool swrm_lock_sleep(struct swr_mstr_ctrl *swrm); |
| 91 | static void swrm_unlock_sleep(struct swr_mstr_ctrl *swrm); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 92 | |
| 93 | static bool swrm_is_msm_variant(int val) |
| 94 | { |
| 95 | return (val == SWRM_VERSION_1_3); |
| 96 | } |
| 97 | |
| 98 | static int swrm_debug_open(struct inode *inode, struct file *file) |
| 99 | { |
| 100 | file->private_data = inode->i_private; |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | static int get_parameters(char *buf, u32 *param1, int num_of_par) |
| 105 | { |
| 106 | char *token; |
| 107 | int base, cnt; |
| 108 | |
| 109 | token = strsep(&buf, " "); |
| 110 | for (cnt = 0; cnt < num_of_par; cnt++) { |
| 111 | if (token) { |
| 112 | if ((token[1] == 'x') || (token[1] == 'X')) |
| 113 | base = 16; |
| 114 | else |
| 115 | base = 10; |
| 116 | |
| 117 | if (kstrtou32(token, base, ¶m1[cnt]) != 0) |
| 118 | return -EINVAL; |
| 119 | |
| 120 | token = strsep(&buf, " "); |
| 121 | } else |
| 122 | return -EINVAL; |
| 123 | } |
| 124 | return 0; |
| 125 | } |
| 126 | |
| 127 | static ssize_t swrm_reg_show(char __user *ubuf, size_t count, |
| 128 | loff_t *ppos) |
| 129 | { |
| 130 | int i, reg_val, len; |
| 131 | ssize_t total = 0; |
| 132 | char tmp_buf[SWR_MSTR_MAX_BUF_LEN]; |
| 133 | |
| 134 | if (!ubuf || !ppos) |
| 135 | return 0; |
| 136 | |
| 137 | for (i = (((int) *ppos / BYTES_PER_LINE) + SWR_MSTR_START_REG_ADDR); |
| 138 | i <= SWR_MSTR_MAX_REG_ADDR; i += 4) { |
| 139 | reg_val = dbgswrm->read(dbgswrm->handle, i); |
| 140 | len = snprintf(tmp_buf, 25, "0x%.3x: 0x%.2x\n", i, reg_val); |
| 141 | if ((total + len) >= count - 1) |
| 142 | break; |
| 143 | if (copy_to_user((ubuf + total), tmp_buf, len)) { |
| 144 | pr_err("%s: fail to copy reg dump\n", __func__); |
| 145 | total = -EFAULT; |
| 146 | goto copy_err; |
| 147 | } |
| 148 | *ppos += len; |
| 149 | total += len; |
| 150 | } |
| 151 | |
| 152 | copy_err: |
| 153 | return total; |
| 154 | } |
| 155 | |
| 156 | static ssize_t swrm_debug_read(struct file *file, char __user *ubuf, |
| 157 | size_t count, loff_t *ppos) |
| 158 | { |
| 159 | char lbuf[SWR_MSTR_RD_BUF_LEN]; |
| 160 | char *access_str; |
| 161 | ssize_t ret_cnt; |
| 162 | |
| 163 | if (!count || !file || !ppos || !ubuf) |
| 164 | return -EINVAL; |
| 165 | |
| 166 | access_str = file->private_data; |
| 167 | if (*ppos < 0) |
| 168 | return -EINVAL; |
| 169 | |
| 170 | if (!strcmp(access_str, "swrm_peek")) { |
| 171 | snprintf(lbuf, sizeof(lbuf), "0x%x\n", read_data); |
| 172 | ret_cnt = simple_read_from_buffer(ubuf, count, ppos, lbuf, |
| 173 | strnlen(lbuf, 7)); |
| 174 | } else if (!strcmp(access_str, "swrm_reg_dump")) { |
| 175 | ret_cnt = swrm_reg_show(ubuf, count, ppos); |
| 176 | } else { |
| 177 | pr_err("%s: %s not permitted to read\n", __func__, access_str); |
| 178 | ret_cnt = -EPERM; |
| 179 | } |
| 180 | return ret_cnt; |
| 181 | } |
| 182 | |
| 183 | static ssize_t swrm_debug_write(struct file *filp, |
| 184 | const char __user *ubuf, size_t cnt, loff_t *ppos) |
| 185 | { |
| 186 | char lbuf[SWR_MSTR_WR_BUF_LEN]; |
| 187 | int rc; |
| 188 | u32 param[5]; |
| 189 | char *access_str; |
| 190 | |
| 191 | if (!filp || !ppos || !ubuf) |
| 192 | return -EINVAL; |
| 193 | |
| 194 | access_str = filp->private_data; |
| 195 | if (cnt > sizeof(lbuf) - 1) |
| 196 | return -EINVAL; |
| 197 | |
| 198 | rc = copy_from_user(lbuf, ubuf, cnt); |
| 199 | if (rc) |
| 200 | return -EFAULT; |
| 201 | |
| 202 | lbuf[cnt] = '\0'; |
| 203 | if (!strcmp(access_str, "swrm_poke")) { |
| 204 | /* write */ |
| 205 | rc = get_parameters(lbuf, param, 2); |
| 206 | if ((param[0] <= SWR_MSTR_MAX_REG_ADDR) && |
| 207 | (param[1] <= 0xFFFFFFFF) && |
| 208 | (rc == 0)) |
| 209 | rc = dbgswrm->write(dbgswrm->handle, param[0], |
| 210 | param[1]); |
| 211 | else |
| 212 | rc = -EINVAL; |
| 213 | } else if (!strcmp(access_str, "swrm_peek")) { |
| 214 | /* read */ |
| 215 | rc = get_parameters(lbuf, param, 1); |
| 216 | if ((param[0] <= SWR_MSTR_MAX_REG_ADDR) && (rc == 0)) |
| 217 | read_data = dbgswrm->read(dbgswrm->handle, param[0]); |
| 218 | else |
| 219 | rc = -EINVAL; |
| 220 | } |
| 221 | if (rc == 0) |
| 222 | rc = cnt; |
| 223 | else |
| 224 | pr_err("%s: rc = %d\n", __func__, rc); |
| 225 | |
| 226 | return rc; |
| 227 | } |
| 228 | |
| 229 | static const struct file_operations swrm_debug_ops = { |
| 230 | .open = swrm_debug_open, |
| 231 | .write = swrm_debug_write, |
| 232 | .read = swrm_debug_read, |
| 233 | }; |
| 234 | |
| 235 | static int swrm_clk_request(struct swr_mstr_ctrl *swrm, bool enable) |
| 236 | { |
Ramprasad Katkam | 6bce2e7 | 2018-10-10 19:20:13 +0530 | [diff] [blame] | 237 | int ret = 0; |
| 238 | |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 239 | if (!swrm->clk || !swrm->handle) |
| 240 | return -EINVAL; |
| 241 | |
Ramprasad Katkam | 6bce2e7 | 2018-10-10 19:20:13 +0530 | [diff] [blame] | 242 | mutex_lock(&swrm->clklock); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 243 | if (enable) { |
Aditya Bavanari | f4a471d | 2019-02-19 17:57:12 +0530 | [diff] [blame] | 244 | if (!swrm->dev_up) { |
| 245 | ret = -ENODEV; |
Ramprasad Katkam | 6bce2e7 | 2018-10-10 19:20:13 +0530 | [diff] [blame] | 246 | goto exit; |
Aditya Bavanari | f4a471d | 2019-02-19 17:57:12 +0530 | [diff] [blame] | 247 | } |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 248 | swrm->clk_ref_count++; |
| 249 | if (swrm->clk_ref_count == 1) { |
Ramprasad Katkam | 6bce2e7 | 2018-10-10 19:20:13 +0530 | [diff] [blame] | 250 | ret = swrm->clk(swrm->handle, true); |
| 251 | if (ret) { |
Ramprasad Katkam | 14efed6 | 2019-03-07 13:16:50 +0530 | [diff] [blame] | 252 | dev_err_ratelimited(swrm->dev, |
Ramprasad Katkam | 6bce2e7 | 2018-10-10 19:20:13 +0530 | [diff] [blame] | 253 | "%s: clock enable req failed", |
| 254 | __func__); |
| 255 | --swrm->clk_ref_count; |
| 256 | } |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 257 | } |
| 258 | } else if (--swrm->clk_ref_count == 0) { |
| 259 | swrm->clk(swrm->handle, false); |
Ramprasad Katkam | 6bce2e7 | 2018-10-10 19:20:13 +0530 | [diff] [blame] | 260 | complete(&swrm->clk_off_complete); |
| 261 | } |
| 262 | if (swrm->clk_ref_count < 0) { |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 263 | pr_err("%s: swrm clk count mismatch\n", __func__); |
| 264 | swrm->clk_ref_count = 0; |
| 265 | } |
Ramprasad Katkam | 6bce2e7 | 2018-10-10 19:20:13 +0530 | [diff] [blame] | 266 | |
| 267 | exit: |
| 268 | mutex_unlock(&swrm->clklock); |
| 269 | return ret; |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | static int swrm_ahb_write(struct swr_mstr_ctrl *swrm, |
| 273 | u16 reg, u32 *value) |
| 274 | { |
Laxminath Kasam | fbcaf32 | 2018-07-18 00:38:14 +0530 | [diff] [blame] | 275 | u32 temp = (u32)(*value); |
Laxminath Kasam | 1df09a8 | 2018-09-20 18:57:49 +0530 | [diff] [blame] | 276 | int ret = 0; |
| 277 | |
| 278 | mutex_lock(&swrm->devlock); |
| 279 | if (!swrm->dev_up) |
| 280 | goto err; |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 281 | |
| 282 | ret = swrm_clk_request(swrm, TRUE); |
Laxminath Kasam | 1df09a8 | 2018-09-20 18:57:49 +0530 | [diff] [blame] | 283 | if (ret) { |
| 284 | dev_err_ratelimited(swrm->dev, "%s: clock request failed\n", |
| 285 | __func__); |
| 286 | goto err; |
| 287 | } |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 288 | iowrite32(temp, swrm->swrm_dig_base + reg); |
Laxminath Kasam | fbcaf32 | 2018-07-18 00:38:14 +0530 | [diff] [blame] | 289 | swrm_clk_request(swrm, FALSE); |
Laxminath Kasam | 1df09a8 | 2018-09-20 18:57:49 +0530 | [diff] [blame] | 290 | err: |
| 291 | mutex_unlock(&swrm->devlock); |
| 292 | return ret; |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | static int swrm_ahb_read(struct swr_mstr_ctrl *swrm, |
| 296 | u16 reg, u32 *value) |
| 297 | { |
Laxminath Kasam | fbcaf32 | 2018-07-18 00:38:14 +0530 | [diff] [blame] | 298 | u32 temp = 0; |
Laxminath Kasam | 1df09a8 | 2018-09-20 18:57:49 +0530 | [diff] [blame] | 299 | int ret = 0; |
| 300 | |
| 301 | mutex_lock(&swrm->devlock); |
| 302 | if (!swrm->dev_up) |
| 303 | goto err; |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 304 | |
| 305 | ret = swrm_clk_request(swrm, TRUE); |
Laxminath Kasam | 1df09a8 | 2018-09-20 18:57:49 +0530 | [diff] [blame] | 306 | if (ret) { |
| 307 | dev_err_ratelimited(swrm->dev, "%s: clock request failed\n", |
| 308 | __func__); |
| 309 | goto err; |
| 310 | } |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 311 | temp = ioread32(swrm->swrm_dig_base + reg); |
Laxminath Kasam | fbcaf32 | 2018-07-18 00:38:14 +0530 | [diff] [blame] | 312 | *value = temp; |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 313 | swrm_clk_request(swrm, FALSE); |
Laxminath Kasam | 1df09a8 | 2018-09-20 18:57:49 +0530 | [diff] [blame] | 314 | err: |
| 315 | mutex_unlock(&swrm->devlock); |
| 316 | return ret; |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | static u32 swr_master_read(struct swr_mstr_ctrl *swrm, unsigned int reg_addr) |
| 320 | { |
| 321 | u32 val = 0; |
| 322 | |
| 323 | if (swrm->read) |
| 324 | val = swrm->read(swrm->handle, reg_addr); |
| 325 | else |
| 326 | swrm_ahb_read(swrm, reg_addr, &val); |
| 327 | return val; |
| 328 | } |
| 329 | |
| 330 | static void swr_master_write(struct swr_mstr_ctrl *swrm, u16 reg_addr, u32 val) |
| 331 | { |
| 332 | if (swrm->write) |
| 333 | swrm->write(swrm->handle, reg_addr, val); |
| 334 | else |
| 335 | swrm_ahb_write(swrm, reg_addr, &val); |
| 336 | } |
| 337 | |
| 338 | static int swr_master_bulk_write(struct swr_mstr_ctrl *swrm, u32 *reg_addr, |
| 339 | u32 *val, unsigned int length) |
| 340 | { |
| 341 | int i = 0; |
| 342 | |
| 343 | if (swrm->bulk_write) |
| 344 | swrm->bulk_write(swrm->handle, reg_addr, val, length); |
| 345 | else { |
Ramprasad Katkam | 1f22126 | 2018-08-23 15:01:22 +0530 | [diff] [blame] | 346 | mutex_lock(&swrm->iolock); |
Laxminath Kasam | fbcaf32 | 2018-07-18 00:38:14 +0530 | [diff] [blame] | 347 | for (i = 0; i < length; i++) { |
| 348 | /* wait for FIFO WR command to complete to avoid overflow */ |
| 349 | usleep_range(100, 105); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 350 | swr_master_write(swrm, reg_addr[i], val[i]); |
Laxminath Kasam | fbcaf32 | 2018-07-18 00:38:14 +0530 | [diff] [blame] | 351 | } |
Ramprasad Katkam | 1f22126 | 2018-08-23 15:01:22 +0530 | [diff] [blame] | 352 | mutex_unlock(&swrm->iolock); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 353 | } |
| 354 | return 0; |
| 355 | } |
| 356 | |
| 357 | static bool swrm_is_port_en(struct swr_master *mstr) |
| 358 | { |
| 359 | return !!(mstr->num_port); |
| 360 | } |
| 361 | |
Ramprasad Katkam | 14f47cc | 2018-07-25 17:20:18 +0530 | [diff] [blame] | 362 | static void copy_port_tables(struct swr_mstr_ctrl *swrm, |
| 363 | struct port_params *params) |
| 364 | { |
| 365 | u8 i; |
| 366 | struct port_params *config = params; |
| 367 | |
| 368 | for (i = 0; i < SWR_MSTR_PORT_LEN; i++) { |
| 369 | /* wsa uses single frame structure for all configurations */ |
| 370 | if (!swrm->mport_cfg[i].port_en) |
| 371 | continue; |
| 372 | swrm->mport_cfg[i].sinterval = config[i].si; |
| 373 | swrm->mport_cfg[i].offset1 = config[i].off1; |
| 374 | swrm->mport_cfg[i].offset2 = config[i].off2; |
| 375 | swrm->mport_cfg[i].hstart = config[i].hstart; |
| 376 | swrm->mport_cfg[i].hstop = config[i].hstop; |
| 377 | swrm->mport_cfg[i].blk_pack_mode = config[i].bp_mode; |
| 378 | swrm->mport_cfg[i].blk_grp_count = config[i].bgp_ctrl; |
| 379 | swrm->mport_cfg[i].word_length = config[i].wd_len; |
| 380 | swrm->mport_cfg[i].lane_ctrl = config[i].lane_ctrl; |
| 381 | } |
| 382 | } |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 383 | static int swrm_get_port_config(struct swr_mstr_ctrl *swrm) |
| 384 | { |
Ramprasad Katkam | 14f47cc | 2018-07-25 17:20:18 +0530 | [diff] [blame] | 385 | struct port_params *params; |
Sudheer Papothi | 4c322b1 | 2018-10-31 06:34:01 +0530 | [diff] [blame] | 386 | u32 usecase = 0; |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 387 | |
Sudheer Papothi | 4c322b1 | 2018-10-31 06:34:01 +0530 | [diff] [blame] | 388 | /* TODO - Send usecase information to avoid checking for master_id */ |
| 389 | if (swrm->mport_cfg[SWRM_DSD_PARAMS_PORT].port_en && |
| 390 | (swrm->master_id == MASTER_ID_RX)) |
| 391 | usecase = 1; |
Ramprasad Katkam | 14f47cc | 2018-07-25 17:20:18 +0530 | [diff] [blame] | 392 | |
Sudheer Papothi | 4c322b1 | 2018-10-31 06:34:01 +0530 | [diff] [blame] | 393 | params = swrm->port_param[usecase]; |
Ramprasad Katkam | 14f47cc | 2018-07-25 17:20:18 +0530 | [diff] [blame] | 394 | copy_port_tables(swrm, params); |
Sudheer Papothi | 4c322b1 | 2018-10-31 06:34:01 +0530 | [diff] [blame] | 395 | |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 396 | return 0; |
| 397 | } |
| 398 | |
| 399 | static int swrm_get_master_port(struct swr_mstr_ctrl *swrm, u8 *mstr_port_id, |
| 400 | u8 *mstr_ch_mask, u8 mstr_prt_type, |
| 401 | u8 slv_port_id) |
| 402 | { |
| 403 | int i, j; |
| 404 | *mstr_port_id = 0; |
| 405 | |
| 406 | for (i = 1; i <= swrm->num_ports; i++) { |
| 407 | for (j = 0; j < SWR_MAX_CH_PER_PORT; j++) { |
| 408 | if (swrm->port_mapping[i][j].port_type == mstr_prt_type) |
| 409 | goto found; |
| 410 | } |
| 411 | } |
| 412 | found: |
| 413 | if (i > swrm->num_ports || j == SWR_MAX_CH_PER_PORT) { |
| 414 | dev_err(swrm->dev, "%s: port type not supported by master\n", |
| 415 | __func__); |
| 416 | return -EINVAL; |
| 417 | } |
| 418 | /* id 0 corresponds to master port 1 */ |
| 419 | *mstr_port_id = i - 1; |
| 420 | *mstr_ch_mask = swrm->port_mapping[i][j].ch_mask; |
| 421 | |
| 422 | return 0; |
| 423 | |
| 424 | } |
| 425 | |
| 426 | static u32 swrm_get_packed_reg_val(u8 *cmd_id, u8 cmd_data, |
| 427 | u8 dev_addr, u16 reg_addr) |
| 428 | { |
| 429 | u32 val; |
| 430 | u8 id = *cmd_id; |
| 431 | |
| 432 | if (id != SWR_BROADCAST_CMD_ID) { |
| 433 | if (id < 14) |
| 434 | id += 1; |
| 435 | else |
| 436 | id = 0; |
| 437 | *cmd_id = id; |
| 438 | } |
| 439 | val = SWR_REG_VAL_PACK(cmd_data, dev_addr, id, reg_addr); |
| 440 | |
| 441 | return val; |
| 442 | } |
| 443 | |
| 444 | static int swrm_cmd_fifo_rd_cmd(struct swr_mstr_ctrl *swrm, int *cmd_data, |
| 445 | u8 dev_addr, u8 cmd_id, u16 reg_addr, |
| 446 | u32 len) |
| 447 | { |
| 448 | u32 val; |
Laxminath Kasam | fbcaf32 | 2018-07-18 00:38:14 +0530 | [diff] [blame] | 449 | u32 retry_attempt = 0; |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 450 | |
Ramprasad Katkam | 1f22126 | 2018-08-23 15:01:22 +0530 | [diff] [blame] | 451 | mutex_lock(&swrm->iolock); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 452 | val = swrm_get_packed_reg_val(&swrm->rcmd_id, len, dev_addr, reg_addr); |
Ramprasad Katkam | 1e90620 | 2019-01-30 14:16:34 +0530 | [diff] [blame] | 453 | if (swrm->read) { |
| 454 | /* skip delay if read is handled in platform driver */ |
| 455 | swr_master_write(swrm, SWRM_CMD_FIFO_RD_CMD, val); |
| 456 | } else { |
| 457 | /* wait for FIFO RD to complete to avoid overflow */ |
| 458 | usleep_range(100, 105); |
| 459 | swr_master_write(swrm, SWRM_CMD_FIFO_RD_CMD, val); |
| 460 | /* wait for FIFO RD CMD complete to avoid overflow */ |
| 461 | usleep_range(250, 255); |
| 462 | } |
Laxminath Kasam | fbcaf32 | 2018-07-18 00:38:14 +0530 | [diff] [blame] | 463 | retry_read: |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 464 | *cmd_data = swr_master_read(swrm, SWRM_CMD_FIFO_RD_FIFO_ADDR); |
Ramprasad Katkam | 1f22126 | 2018-08-23 15:01:22 +0530 | [diff] [blame] | 465 | dev_dbg(swrm->dev, "%s: reg: 0x%x, cmd_id: 0x%x, rcmd_id: 0x%x, \ |
| 466 | dev_num: 0x%x, cmd_data: 0x%x\n", __func__, reg_addr, |
| 467 | cmd_id, swrm->rcmd_id, dev_addr, *cmd_data); |
Laxminath Kasam | fbcaf32 | 2018-07-18 00:38:14 +0530 | [diff] [blame] | 468 | if ((((*cmd_data) & 0xF00) >> 8) != swrm->rcmd_id) { |
| 469 | if (retry_attempt < MAX_FIFO_RD_FAIL_RETRY) { |
| 470 | /* wait 500 us before retry on fifo read failure */ |
| 471 | usleep_range(500, 505); |
| 472 | retry_attempt++; |
| 473 | goto retry_read; |
| 474 | } else { |
Ramprasad Katkam | 1f22126 | 2018-08-23 15:01:22 +0530 | [diff] [blame] | 475 | dev_err_ratelimited(swrm->dev, "%s: reg: 0x%x, cmd_id: 0x%x, \ |
| 476 | rcmd_id: 0x%x, dev_num: 0x%x, cmd_data: 0x%x\n", |
| 477 | __func__, reg_addr, cmd_id, swrm->rcmd_id, |
| 478 | dev_addr, *cmd_data); |
| 479 | |
Laxminath Kasam | fbcaf32 | 2018-07-18 00:38:14 +0530 | [diff] [blame] | 480 | dev_err_ratelimited(swrm->dev, |
| 481 | "%s: failed to read fifo\n", __func__); |
| 482 | } |
| 483 | } |
Ramprasad Katkam | 1f22126 | 2018-08-23 15:01:22 +0530 | [diff] [blame] | 484 | mutex_unlock(&swrm->iolock); |
| 485 | |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 486 | return 0; |
| 487 | } |
| 488 | |
| 489 | static int swrm_cmd_fifo_wr_cmd(struct swr_mstr_ctrl *swrm, u8 cmd_data, |
| 490 | u8 dev_addr, u8 cmd_id, u16 reg_addr) |
| 491 | { |
| 492 | u32 val; |
| 493 | int ret = 0; |
| 494 | |
Ramprasad Katkam | 1f22126 | 2018-08-23 15:01:22 +0530 | [diff] [blame] | 495 | mutex_lock(&swrm->iolock); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 496 | if (!cmd_id) |
| 497 | val = swrm_get_packed_reg_val(&swrm->wcmd_id, cmd_data, |
| 498 | dev_addr, reg_addr); |
| 499 | else |
| 500 | val = swrm_get_packed_reg_val(&cmd_id, cmd_data, |
| 501 | dev_addr, reg_addr); |
Ramprasad Katkam | 1f22126 | 2018-08-23 15:01:22 +0530 | [diff] [blame] | 502 | dev_dbg(swrm->dev, "%s: reg: 0x%x, cmd_id: 0x%x,wcmd_id: 0x%x, \ |
| 503 | dev_num: 0x%x, cmd_data: 0x%x\n", __func__, |
| 504 | reg_addr, cmd_id, swrm->wcmd_id,dev_addr, cmd_data); |
Ramprasad Katkam | b4c7c68 | 2018-12-19 18:58:36 +0530 | [diff] [blame] | 505 | swr_master_write(swrm, SWRM_CMD_FIFO_WR_CMD, val); |
Ramprasad Katkam | 1e90620 | 2019-01-30 14:16:34 +0530 | [diff] [blame] | 506 | /* |
| 507 | * wait for FIFO WR command to complete to avoid overflow |
| 508 | * skip delay if write is handled in platform driver. |
| 509 | */ |
| 510 | if(!swrm->write) |
| 511 | usleep_range(250, 255); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 512 | if (cmd_id == 0xF) { |
| 513 | /* |
| 514 | * sleep for 10ms for MSM soundwire variant to allow broadcast |
| 515 | * command to complete. |
| 516 | */ |
| 517 | if (swrm_is_msm_variant(swrm->version)) |
| 518 | usleep_range(10000, 10100); |
| 519 | else |
| 520 | wait_for_completion_timeout(&swrm->broadcast, |
| 521 | (2 * HZ/10)); |
| 522 | } |
Ramprasad Katkam | 1f22126 | 2018-08-23 15:01:22 +0530 | [diff] [blame] | 523 | mutex_unlock(&swrm->iolock); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 524 | return ret; |
| 525 | } |
| 526 | |
| 527 | static int swrm_read(struct swr_master *master, u8 dev_num, u16 reg_addr, |
| 528 | void *buf, u32 len) |
| 529 | { |
| 530 | struct swr_mstr_ctrl *swrm = swr_get_ctrl_data(master); |
| 531 | int ret = 0; |
| 532 | int val; |
| 533 | u8 *reg_val = (u8 *)buf; |
| 534 | |
| 535 | if (!swrm) { |
| 536 | dev_err(&master->dev, "%s: swrm is NULL\n", __func__); |
| 537 | return -EINVAL; |
| 538 | } |
Ramprasad Katkam | 0db4801 | 2018-11-09 11:01:23 +0530 | [diff] [blame] | 539 | if (!dev_num) { |
| 540 | dev_err(&master->dev, "%s: invalid slave dev num\n", __func__); |
| 541 | return -EINVAL; |
| 542 | } |
Laxminath Kasam | 1df09a8 | 2018-09-20 18:57:49 +0530 | [diff] [blame] | 543 | mutex_lock(&swrm->devlock); |
| 544 | if (!swrm->dev_up) { |
| 545 | mutex_unlock(&swrm->devlock); |
| 546 | return 0; |
| 547 | } |
| 548 | mutex_unlock(&swrm->devlock); |
| 549 | |
Ramprasad Katkam | 1f22126 | 2018-08-23 15:01:22 +0530 | [diff] [blame] | 550 | pm_runtime_get_sync(swrm->dev); |
Ramprasad Katkam | 0db4801 | 2018-11-09 11:01:23 +0530 | [diff] [blame] | 551 | ret = swrm_cmd_fifo_rd_cmd(swrm, &val, dev_num, 0, reg_addr, len); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 552 | |
| 553 | if (!ret) |
| 554 | *reg_val = (u8)val; |
| 555 | |
Ramprasad Katkam | 1f22126 | 2018-08-23 15:01:22 +0530 | [diff] [blame] | 556 | pm_runtime_put_autosuspend(swrm->dev); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 557 | pm_runtime_mark_last_busy(swrm->dev); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 558 | return ret; |
| 559 | } |
| 560 | |
| 561 | static int swrm_write(struct swr_master *master, u8 dev_num, u16 reg_addr, |
| 562 | const void *buf) |
| 563 | { |
| 564 | struct swr_mstr_ctrl *swrm = swr_get_ctrl_data(master); |
| 565 | int ret = 0; |
| 566 | u8 reg_val = *(u8 *)buf; |
| 567 | |
| 568 | if (!swrm) { |
| 569 | dev_err(&master->dev, "%s: swrm is NULL\n", __func__); |
| 570 | return -EINVAL; |
| 571 | } |
Ramprasad Katkam | 0db4801 | 2018-11-09 11:01:23 +0530 | [diff] [blame] | 572 | if (!dev_num) { |
| 573 | dev_err(&master->dev, "%s: invalid slave dev num\n", __func__); |
| 574 | return -EINVAL; |
| 575 | } |
Laxminath Kasam | 1df09a8 | 2018-09-20 18:57:49 +0530 | [diff] [blame] | 576 | mutex_lock(&swrm->devlock); |
| 577 | if (!swrm->dev_up) { |
| 578 | mutex_unlock(&swrm->devlock); |
| 579 | return 0; |
| 580 | } |
| 581 | mutex_unlock(&swrm->devlock); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 582 | |
Ramprasad Katkam | 1f22126 | 2018-08-23 15:01:22 +0530 | [diff] [blame] | 583 | pm_runtime_get_sync(swrm->dev); |
Ramprasad Katkam | 0db4801 | 2018-11-09 11:01:23 +0530 | [diff] [blame] | 584 | ret = swrm_cmd_fifo_wr_cmd(swrm, reg_val, dev_num, 0, reg_addr); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 585 | |
Ramprasad Katkam | 1f22126 | 2018-08-23 15:01:22 +0530 | [diff] [blame] | 586 | pm_runtime_put_autosuspend(swrm->dev); |
| 587 | pm_runtime_mark_last_busy(swrm->dev); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 588 | return ret; |
| 589 | } |
| 590 | |
| 591 | static int swrm_bulk_write(struct swr_master *master, u8 dev_num, void *reg, |
| 592 | const void *buf, size_t len) |
| 593 | { |
| 594 | struct swr_mstr_ctrl *swrm = swr_get_ctrl_data(master); |
| 595 | int ret = 0; |
| 596 | int i; |
| 597 | u32 *val; |
| 598 | u32 *swr_fifo_reg; |
| 599 | |
| 600 | if (!swrm || !swrm->handle) { |
| 601 | dev_err(&master->dev, "%s: swrm is NULL\n", __func__); |
| 602 | return -EINVAL; |
| 603 | } |
| 604 | if (len <= 0) |
| 605 | return -EINVAL; |
Laxminath Kasam | 1df09a8 | 2018-09-20 18:57:49 +0530 | [diff] [blame] | 606 | mutex_lock(&swrm->devlock); |
| 607 | if (!swrm->dev_up) { |
| 608 | mutex_unlock(&swrm->devlock); |
| 609 | return 0; |
| 610 | } |
| 611 | mutex_unlock(&swrm->devlock); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 612 | |
Ramprasad Katkam | 1f22126 | 2018-08-23 15:01:22 +0530 | [diff] [blame] | 613 | pm_runtime_get_sync(swrm->dev); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 614 | if (dev_num) { |
| 615 | swr_fifo_reg = kcalloc(len, sizeof(u32), GFP_KERNEL); |
| 616 | if (!swr_fifo_reg) { |
| 617 | ret = -ENOMEM; |
| 618 | goto err; |
| 619 | } |
| 620 | val = kcalloc(len, sizeof(u32), GFP_KERNEL); |
| 621 | if (!val) { |
| 622 | ret = -ENOMEM; |
| 623 | goto mem_fail; |
| 624 | } |
| 625 | |
| 626 | for (i = 0; i < len; i++) { |
| 627 | val[i] = swrm_get_packed_reg_val(&swrm->wcmd_id, |
| 628 | ((u8 *)buf)[i], |
| 629 | dev_num, |
| 630 | ((u16 *)reg)[i]); |
| 631 | swr_fifo_reg[i] = SWRM_CMD_FIFO_WR_CMD; |
| 632 | } |
| 633 | ret = swr_master_bulk_write(swrm, swr_fifo_reg, val, len); |
| 634 | if (ret) { |
| 635 | dev_err(&master->dev, "%s: bulk write failed\n", |
| 636 | __func__); |
| 637 | ret = -EINVAL; |
| 638 | } |
| 639 | } else { |
| 640 | dev_err(&master->dev, |
| 641 | "%s: No support of Bulk write for master regs\n", |
| 642 | __func__); |
| 643 | ret = -EINVAL; |
| 644 | goto err; |
| 645 | } |
| 646 | kfree(val); |
| 647 | mem_fail: |
| 648 | kfree(swr_fifo_reg); |
| 649 | err: |
Ramprasad Katkam | 1f22126 | 2018-08-23 15:01:22 +0530 | [diff] [blame] | 650 | pm_runtime_put_autosuspend(swrm->dev); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 651 | pm_runtime_mark_last_busy(swrm->dev); |
| 652 | return ret; |
| 653 | } |
| 654 | |
| 655 | static u8 get_inactive_bank_num(struct swr_mstr_ctrl *swrm) |
| 656 | { |
| 657 | return (swr_master_read(swrm, SWRM_MCP_STATUS) & |
| 658 | SWRM_MCP_STATUS_BANK_NUM_MASK) ? 0 : 1; |
| 659 | } |
| 660 | |
| 661 | static void enable_bank_switch(struct swr_mstr_ctrl *swrm, u8 bank, |
| 662 | u8 row, u8 col) |
| 663 | { |
| 664 | swrm_cmd_fifo_wr_cmd(swrm, ((row << 3) | col), 0xF, 0xF, |
| 665 | SWRS_SCP_FRAME_CTRL_BANK(bank)); |
| 666 | } |
| 667 | |
| 668 | static struct swr_port_info *swrm_get_port_req(struct swrm_mports *mport, |
| 669 | u8 slv_port, u8 dev_num) |
| 670 | { |
| 671 | struct swr_port_info *port_req = NULL; |
| 672 | |
| 673 | list_for_each_entry(port_req, &mport->port_req_list, list) { |
| 674 | /* Store dev_id instead of dev_num if enumeration is changed run_time */ |
| 675 | if ((port_req->slave_port_id == slv_port) |
| 676 | && (port_req->dev_num == dev_num)) |
| 677 | return port_req; |
| 678 | } |
| 679 | return NULL; |
| 680 | } |
| 681 | |
| 682 | static bool swrm_remove_from_group(struct swr_master *master) |
| 683 | { |
| 684 | struct swr_device *swr_dev; |
| 685 | struct swr_mstr_ctrl *swrm = swr_get_ctrl_data(master); |
| 686 | bool is_removed = false; |
| 687 | |
| 688 | if (!swrm) |
| 689 | goto end; |
| 690 | |
| 691 | mutex_lock(&swrm->mlock); |
| 692 | if ((swrm->num_rx_chs > 1) && |
| 693 | (swrm->num_rx_chs == swrm->num_cfg_devs)) { |
| 694 | list_for_each_entry(swr_dev, &master->devices, |
| 695 | dev_list) { |
| 696 | swr_dev->group_id = SWR_GROUP_NONE; |
| 697 | master->gr_sid = 0; |
| 698 | } |
| 699 | is_removed = true; |
| 700 | } |
| 701 | mutex_unlock(&swrm->mlock); |
| 702 | |
| 703 | end: |
| 704 | return is_removed; |
| 705 | } |
| 706 | |
| 707 | static void swrm_disable_ports(struct swr_master *master, |
| 708 | u8 bank) |
| 709 | { |
| 710 | u32 value; |
| 711 | struct swr_port_info *port_req; |
| 712 | int i; |
| 713 | struct swrm_mports *mport; |
| 714 | struct swr_mstr_ctrl *swrm = swr_get_ctrl_data(master); |
| 715 | |
| 716 | if (!swrm) { |
| 717 | pr_err("%s: swrm is null\n", __func__); |
| 718 | return; |
| 719 | } |
| 720 | |
| 721 | dev_dbg(swrm->dev, "%s: master num_port: %d\n", __func__, |
| 722 | master->num_port); |
| 723 | |
| 724 | |
| 725 | for (i = 0; i < SWR_MSTR_PORT_LEN ; i++) { |
| 726 | |
| 727 | mport = &(swrm->mport_cfg[i]); |
| 728 | if (!mport->port_en) |
| 729 | continue; |
| 730 | |
| 731 | list_for_each_entry(port_req, &mport->port_req_list, list) { |
| 732 | /* skip ports with no change req's*/ |
| 733 | if (port_req->req_ch == port_req->ch_en) |
| 734 | continue; |
| 735 | |
| 736 | swrm_cmd_fifo_wr_cmd(swrm, port_req->req_ch, |
| 737 | port_req->dev_num, 0x00, |
| 738 | SWRS_DP_CHANNEL_ENABLE_BANK(port_req->slave_port_id, |
| 739 | bank)); |
| 740 | dev_dbg(swrm->dev, "%s: mport :%d, reg: 0x%x\n", |
| 741 | __func__, i, |
| 742 | (SWRM_DP_PORT_CTRL_BANK(i + 1, bank))); |
| 743 | } |
| 744 | value = ((mport->req_ch) |
| 745 | << SWRM_DP_PORT_CTRL_EN_CHAN_SHFT); |
| 746 | value |= ((mport->offset2) |
| 747 | << SWRM_DP_PORT_CTRL_OFFSET2_SHFT); |
| 748 | value |= ((mport->offset1) |
| 749 | << SWRM_DP_PORT_CTRL_OFFSET1_SHFT); |
| 750 | value |= mport->sinterval; |
| 751 | |
| 752 | swr_master_write(swrm, |
| 753 | SWRM_DP_PORT_CTRL_BANK(i+1, bank), |
| 754 | value); |
| 755 | dev_dbg(swrm->dev, "%s: mport :%d, reg: 0x%x, val: 0x%x\n", |
| 756 | __func__, i, |
| 757 | (SWRM_DP_PORT_CTRL_BANK(i+1, bank)), value); |
| 758 | } |
| 759 | } |
| 760 | |
| 761 | static void swrm_cleanup_disabled_port_reqs(struct swr_master *master) |
| 762 | { |
| 763 | struct swr_port_info *port_req, *next; |
| 764 | int i; |
| 765 | struct swrm_mports *mport; |
| 766 | struct swr_mstr_ctrl *swrm = swr_get_ctrl_data(master); |
| 767 | |
| 768 | if (!swrm) { |
| 769 | pr_err("%s: swrm is null\n", __func__); |
| 770 | return; |
| 771 | } |
| 772 | dev_dbg(swrm->dev, "%s: master num_port: %d\n", __func__, |
| 773 | master->num_port); |
| 774 | |
| 775 | for (i = 0; i < SWR_MSTR_PORT_LEN; i++) { |
| 776 | mport = &(swrm->mport_cfg[i]); |
| 777 | list_for_each_entry_safe(port_req, next, |
| 778 | &mport->port_req_list, list) { |
| 779 | /* skip ports without new ch req */ |
| 780 | if (port_req->ch_en == port_req->req_ch) |
| 781 | continue; |
| 782 | |
| 783 | /* remove new ch req's*/ |
Ramprasad Katkam | c8d52a1 | 2018-08-31 02:30:00 +0530 | [diff] [blame] | 784 | port_req->ch_en = port_req->req_ch; |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 785 | |
| 786 | /* If no streams enabled on port, remove the port req */ |
| 787 | if (port_req->ch_en == 0) { |
| 788 | list_del(&port_req->list); |
| 789 | kfree(port_req); |
| 790 | } |
| 791 | } |
| 792 | /* remove new ch req's on mport*/ |
Ramprasad Katkam | c8d52a1 | 2018-08-31 02:30:00 +0530 | [diff] [blame] | 793 | mport->ch_en = mport->req_ch; |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 794 | |
| 795 | if (!(mport->ch_en)) { |
| 796 | mport->port_en = false; |
| 797 | master->port_en_mask &= ~i; |
| 798 | } |
| 799 | } |
| 800 | } |
| 801 | static void swrm_copy_data_port_config(struct swr_master *master, u8 bank) |
| 802 | { |
| 803 | u32 value, slv_id; |
| 804 | struct swr_port_info *port_req; |
| 805 | int i; |
| 806 | struct swrm_mports *mport; |
| 807 | u32 reg[SWRM_MAX_PORT_REG]; |
| 808 | u32 val[SWRM_MAX_PORT_REG]; |
| 809 | int len = 0; |
Ramprasad Katkam | 14f47cc | 2018-07-25 17:20:18 +0530 | [diff] [blame] | 810 | u8 hparams; |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 811 | struct swr_mstr_ctrl *swrm = swr_get_ctrl_data(master); |
| 812 | |
| 813 | if (!swrm) { |
| 814 | pr_err("%s: swrm is null\n", __func__); |
| 815 | return; |
| 816 | } |
| 817 | |
| 818 | dev_dbg(swrm->dev, "%s: master num_port: %d\n", __func__, |
| 819 | master->num_port); |
| 820 | |
| 821 | for (i = 0; i < SWR_MSTR_PORT_LEN; i++) { |
| 822 | mport = &(swrm->mport_cfg[i]); |
| 823 | if (!mport->port_en) |
| 824 | continue; |
| 825 | |
| 826 | list_for_each_entry(port_req, &mport->port_req_list, list) { |
| 827 | slv_id = port_req->slave_port_id; |
| 828 | reg[len] = SWRM_CMD_FIFO_WR_CMD; |
| 829 | val[len++] = SWR_REG_VAL_PACK(port_req->req_ch, |
| 830 | port_req->dev_num, 0x00, |
| 831 | SWRS_DP_CHANNEL_ENABLE_BANK(slv_id, |
| 832 | bank)); |
| 833 | |
| 834 | reg[len] = SWRM_CMD_FIFO_WR_CMD; |
| 835 | val[len++] = SWR_REG_VAL_PACK(mport->sinterval, |
| 836 | port_req->dev_num, 0x00, |
| 837 | SWRS_DP_SAMPLE_CONTROL_1_BANK(slv_id, |
| 838 | bank)); |
| 839 | |
| 840 | reg[len] = SWRM_CMD_FIFO_WR_CMD; |
| 841 | val[len++] = SWR_REG_VAL_PACK(mport->offset1, |
| 842 | port_req->dev_num, 0x00, |
| 843 | SWRS_DP_OFFSET_CONTROL_1_BANK(slv_id, |
| 844 | bank)); |
| 845 | |
Ramprasad Katkam | 14f47cc | 2018-07-25 17:20:18 +0530 | [diff] [blame] | 846 | if (mport->offset2 != SWR_INVALID_PARAM) { |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 847 | reg[len] = SWRM_CMD_FIFO_WR_CMD; |
| 848 | val[len++] = SWR_REG_VAL_PACK(mport->offset2, |
| 849 | port_req->dev_num, 0x00, |
| 850 | SWRS_DP_OFFSET_CONTROL_2_BANK( |
| 851 | slv_id, bank)); |
| 852 | } |
Ramprasad Katkam | 14f47cc | 2018-07-25 17:20:18 +0530 | [diff] [blame] | 853 | if (mport->hstart != SWR_INVALID_PARAM |
| 854 | && mport->hstop != SWR_INVALID_PARAM) { |
| 855 | hparams = (mport->hstart << 4) | mport->hstop; |
| 856 | |
| 857 | reg[len] = SWRM_CMD_FIFO_WR_CMD; |
| 858 | val[len++] = SWR_REG_VAL_PACK(hparams, |
| 859 | port_req->dev_num, 0x00, |
| 860 | SWRS_DP_HCONTROL_BANK(slv_id, |
| 861 | bank)); |
| 862 | } |
| 863 | if (mport->word_length != SWR_INVALID_PARAM) { |
| 864 | reg[len] = SWRM_CMD_FIFO_WR_CMD; |
| 865 | val[len++] = |
| 866 | SWR_REG_VAL_PACK(mport->word_length, |
| 867 | port_req->dev_num, 0x00, |
| 868 | SWRS_DP_BLOCK_CONTROL_1(slv_id)); |
| 869 | } |
Ramprasad Katkam | 2a0996b | 2018-09-25 20:13:30 +0530 | [diff] [blame] | 870 | if (mport->blk_pack_mode != SWR_INVALID_PARAM |
| 871 | && swrm->master_id != MASTER_ID_WSA) { |
Ramprasad Katkam | 14f47cc | 2018-07-25 17:20:18 +0530 | [diff] [blame] | 872 | reg[len] = SWRM_CMD_FIFO_WR_CMD; |
| 873 | val[len++] = |
| 874 | SWR_REG_VAL_PACK(mport->blk_pack_mode, |
| 875 | port_req->dev_num, 0x00, |
| 876 | SWRS_DP_BLOCK_CONTROL_3_BANK(slv_id, |
| 877 | bank)); |
| 878 | } |
| 879 | if (mport->blk_grp_count != SWR_INVALID_PARAM) { |
| 880 | reg[len] = SWRM_CMD_FIFO_WR_CMD; |
| 881 | val[len++] = |
| 882 | SWR_REG_VAL_PACK(mport->blk_grp_count, |
| 883 | port_req->dev_num, 0x00, |
| 884 | SWRS_DP_BLOCK_CONTROL_2_BANK(slv_id, |
| 885 | bank)); |
| 886 | } |
| 887 | if (mport->lane_ctrl != SWR_INVALID_PARAM) { |
| 888 | reg[len] = SWRM_CMD_FIFO_WR_CMD; |
| 889 | val[len++] = |
| 890 | SWR_REG_VAL_PACK(mport->lane_ctrl, |
| 891 | port_req->dev_num, 0x00, |
| 892 | SWRS_DP_LANE_CONTROL_BANK(slv_id, |
| 893 | bank)); |
| 894 | } |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 895 | port_req->ch_en = port_req->req_ch; |
| 896 | } |
| 897 | value = ((mport->req_ch) |
| 898 | << SWRM_DP_PORT_CTRL_EN_CHAN_SHFT); |
Ramprasad Katkam | 2a0996b | 2018-09-25 20:13:30 +0530 | [diff] [blame] | 899 | |
| 900 | if (mport->offset2 != SWR_INVALID_PARAM) |
| 901 | value |= ((mport->offset2) |
| 902 | << SWRM_DP_PORT_CTRL_OFFSET2_SHFT); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 903 | value |= ((mport->offset1) |
| 904 | << SWRM_DP_PORT_CTRL_OFFSET1_SHFT); |
| 905 | value |= mport->sinterval; |
| 906 | |
| 907 | |
| 908 | reg[len] = SWRM_DP_PORT_CTRL_BANK(i + 1, bank); |
| 909 | val[len++] = value; |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 910 | dev_dbg(swrm->dev, "%s: mport :%d, reg: 0x%x, val: 0x%x\n", |
| 911 | __func__, i, |
| 912 | (SWRM_DP_PORT_CTRL_BANK(i + 1, bank)), value); |
| 913 | |
Ramprasad Katkam | 14f47cc | 2018-07-25 17:20:18 +0530 | [diff] [blame] | 914 | if (mport->lane_ctrl != SWR_INVALID_PARAM) { |
| 915 | reg[len] = SWRM_DP_PORT_CTRL_2_BANK(i + 1, bank); |
| 916 | val[len++] = mport->lane_ctrl; |
| 917 | } |
| 918 | if (mport->word_length != SWR_INVALID_PARAM) { |
| 919 | reg[len] = SWRM_DP_BLOCK_CTRL_1(i + 1); |
| 920 | val[len++] = mport->word_length; |
| 921 | } |
| 922 | |
| 923 | if (mport->blk_grp_count != SWR_INVALID_PARAM) { |
| 924 | reg[len] = SWRM_DP_BLOCK_CTRL2_BANK(i + 1, bank); |
| 925 | val[len++] = mport->blk_grp_count; |
| 926 | } |
| 927 | if (mport->hstart != SWR_INVALID_PARAM |
| 928 | && mport->hstop != SWR_INVALID_PARAM) { |
| 929 | reg[len] = SWRM_DP_PORT_HCTRL_BANK(i + 1, bank); |
Laxminath Kasam | e30eef7 | 2018-11-05 17:40:09 +0530 | [diff] [blame] | 930 | hparams = (mport->hstop << 4) | mport->hstart; |
Ramprasad Katkam | 14f47cc | 2018-07-25 17:20:18 +0530 | [diff] [blame] | 931 | val[len++] = hparams; |
Laxminath Kasam | 990c70b | 2018-11-09 23:15:09 +0530 | [diff] [blame] | 932 | } else { |
| 933 | reg[len] = SWRM_DP_PORT_HCTRL_BANK(i + 1, bank); |
| 934 | hparams = (SWR_HSTOP_MAX_VAL << 4) | SWR_HSTART_MIN_VAL; |
| 935 | val[len++] = hparams; |
Ramprasad Katkam | 14f47cc | 2018-07-25 17:20:18 +0530 | [diff] [blame] | 936 | } |
| 937 | if (mport->blk_pack_mode != SWR_INVALID_PARAM) { |
| 938 | reg[len] = SWRM_DP_BLOCK_CTRL3_BANK(i + 1, bank); |
| 939 | val[len++] = mport->blk_pack_mode; |
| 940 | } |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 941 | mport->ch_en = mport->req_ch; |
| 942 | |
| 943 | } |
| 944 | swr_master_bulk_write(swrm, reg, val, len); |
| 945 | } |
| 946 | |
| 947 | static void swrm_apply_port_config(struct swr_master *master) |
| 948 | { |
| 949 | u8 bank; |
| 950 | struct swr_mstr_ctrl *swrm = swr_get_ctrl_data(master); |
| 951 | |
| 952 | if (!swrm) { |
| 953 | pr_err("%s: Invalid handle to swr controller\n", |
| 954 | __func__); |
| 955 | return; |
| 956 | } |
| 957 | |
| 958 | bank = get_inactive_bank_num(swrm); |
| 959 | dev_dbg(swrm->dev, "%s: enter bank: %d master_ports: %d\n", |
| 960 | __func__, bank, master->num_port); |
| 961 | |
| 962 | |
| 963 | swrm_cmd_fifo_wr_cmd(swrm, 0x01, 0xF, 0x00, |
| 964 | SWRS_SCP_HOST_CLK_DIV2_CTL_BANK(bank)); |
| 965 | |
| 966 | swrm_copy_data_port_config(master, bank); |
| 967 | } |
| 968 | |
| 969 | static int swrm_slvdev_datapath_control(struct swr_master *master, bool enable) |
| 970 | { |
| 971 | u8 bank; |
Ramprasad Katkam | 14f47cc | 2018-07-25 17:20:18 +0530 | [diff] [blame] | 972 | u32 value, n_row, n_col; |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 973 | int ret; |
| 974 | struct swr_mstr_ctrl *swrm = swr_get_ctrl_data(master); |
| 975 | int mask = (SWRM_MCP_FRAME_CTRL_BANK_ROW_CTRL_BMSK | |
| 976 | SWRM_MCP_FRAME_CTRL_BANK_COL_CTRL_BMSK | |
| 977 | SWRM_MCP_FRAME_CTRL_BANK_SSP_PERIOD_BMSK); |
| 978 | u8 inactive_bank; |
| 979 | |
| 980 | if (!swrm) { |
| 981 | pr_err("%s: swrm is null\n", __func__); |
| 982 | return -EFAULT; |
| 983 | } |
Ramprasad Katkam | 7e35478 | 2018-11-21 15:52:54 +0530 | [diff] [blame] | 984 | |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 985 | mutex_lock(&swrm->mlock); |
| 986 | |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 987 | bank = get_inactive_bank_num(swrm); |
| 988 | |
| 989 | if (enable) { |
Ramprasad Katkam | cab8d72 | 2018-09-28 15:54:06 +0530 | [diff] [blame] | 990 | if (!test_bit(ENABLE_PENDING, &swrm->port_req_pending)) { |
| 991 | dev_dbg(swrm->dev, "%s:No pending connect port req\n", |
| 992 | __func__); |
| 993 | goto exit; |
| 994 | } |
| 995 | clear_bit(ENABLE_PENDING, &swrm->port_req_pending); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 996 | ret = swrm_get_port_config(swrm); |
| 997 | if (ret) { |
| 998 | /* cannot accommodate ports */ |
| 999 | swrm_cleanup_disabled_port_reqs(master); |
| 1000 | mutex_unlock(&swrm->mlock); |
| 1001 | return -EINVAL; |
| 1002 | } |
Ramprasad Katkam | 18bc8e2 | 2018-10-25 15:04:24 +0530 | [diff] [blame] | 1003 | swr_master_write(swrm, SWR_MSTR_RX_SWRM_CPU_INTERRUPT_EN, |
Ramprasad Katkam | 7e35478 | 2018-11-21 15:52:54 +0530 | [diff] [blame] | 1004 | SWRM_INTERRUPT_STATUS_MASK); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 1005 | /* apply the new port config*/ |
| 1006 | swrm_apply_port_config(master); |
| 1007 | } else { |
Ramprasad Katkam | cab8d72 | 2018-09-28 15:54:06 +0530 | [diff] [blame] | 1008 | if (!test_bit(DISABLE_PENDING, &swrm->port_req_pending)) { |
| 1009 | dev_dbg(swrm->dev, "%s:No pending disconn port req\n", |
| 1010 | __func__); |
| 1011 | goto exit; |
| 1012 | } |
| 1013 | clear_bit(DISABLE_PENDING, &swrm->port_req_pending); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 1014 | swrm_disable_ports(master, bank); |
| 1015 | } |
| 1016 | dev_dbg(swrm->dev, "%s: enable: %d, cfg_devs: %d\n", |
| 1017 | __func__, enable, swrm->num_cfg_devs); |
| 1018 | |
| 1019 | if (enable) { |
Ramprasad Katkam | 14f47cc | 2018-07-25 17:20:18 +0530 | [diff] [blame] | 1020 | /* set col = 16 */ |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 1021 | n_col = SWR_MAX_COL; |
| 1022 | } else { |
| 1023 | /* |
Ramprasad Katkam | 14f47cc | 2018-07-25 17:20:18 +0530 | [diff] [blame] | 1024 | * Do not change to col = 2 if there are still active ports |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 1025 | */ |
| 1026 | if (!master->num_port) |
| 1027 | n_col = SWR_MIN_COL; |
| 1028 | else |
| 1029 | n_col = SWR_MAX_COL; |
| 1030 | } |
Ramprasad Katkam | 14f47cc | 2018-07-25 17:20:18 +0530 | [diff] [blame] | 1031 | /* Use default 50 * x, frame shape. Change based on mclk */ |
Laxminath Kasam | b0f27cd | 2018-09-06 12:17:11 +0530 | [diff] [blame] | 1032 | if (swrm->mclk_freq == MCLK_FREQ_NATIVE) { |
| 1033 | dev_dbg(swrm->dev, "setting 64 x %d frameshape\n", |
| 1034 | n_col ? 16 : 2); |
| 1035 | n_row = SWR_ROW_64; |
| 1036 | } else { |
| 1037 | dev_dbg(swrm->dev, "setting 50 x %d frameshape\n", |
| 1038 | n_col ? 16 : 2); |
| 1039 | n_row = SWR_ROW_50; |
| 1040 | } |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 1041 | value = swr_master_read(swrm, SWRM_MCP_FRAME_CTRL_BANK_ADDR(bank)); |
| 1042 | value &= (~mask); |
Ramprasad Katkam | 14f47cc | 2018-07-25 17:20:18 +0530 | [diff] [blame] | 1043 | value |= ((n_row << SWRM_MCP_FRAME_CTRL_BANK_ROW_CTRL_SHFT) | |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 1044 | (n_col << SWRM_MCP_FRAME_CTRL_BANK_COL_CTRL_SHFT) | |
| 1045 | (0 << SWRM_MCP_FRAME_CTRL_BANK_SSP_PERIOD_SHFT)); |
| 1046 | swr_master_write(swrm, SWRM_MCP_FRAME_CTRL_BANK_ADDR(bank), value); |
| 1047 | |
| 1048 | dev_dbg(swrm->dev, "%s: regaddr: 0x%x, value: 0x%x\n", __func__, |
| 1049 | SWRM_MCP_FRAME_CTRL_BANK_ADDR(bank), value); |
| 1050 | |
Ramprasad Katkam | 14f47cc | 2018-07-25 17:20:18 +0530 | [diff] [blame] | 1051 | enable_bank_switch(swrm, bank, n_row, n_col); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 1052 | inactive_bank = bank ? 0 : 1; |
| 1053 | |
| 1054 | if (enable) |
| 1055 | swrm_copy_data_port_config(master, inactive_bank); |
| 1056 | else { |
| 1057 | swrm_disable_ports(master, inactive_bank); |
| 1058 | swrm_cleanup_disabled_port_reqs(master); |
Ramprasad Katkam | 7cb4ff6 | 2018-09-12 04:00:26 +0530 | [diff] [blame] | 1059 | } |
| 1060 | if (!swrm_is_port_en(master)) { |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 1061 | dev_dbg(&master->dev, "%s: pm_runtime auto suspend triggered\n", |
| 1062 | __func__); |
| 1063 | pm_runtime_mark_last_busy(swrm->dev); |
| 1064 | pm_runtime_put_autosuspend(swrm->dev); |
| 1065 | } |
Ramprasad Katkam | cab8d72 | 2018-09-28 15:54:06 +0530 | [diff] [blame] | 1066 | exit: |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 1067 | mutex_unlock(&swrm->mlock); |
| 1068 | return 0; |
| 1069 | } |
| 1070 | |
| 1071 | static int swrm_connect_port(struct swr_master *master, |
| 1072 | struct swr_params *portinfo) |
| 1073 | { |
| 1074 | int i; |
| 1075 | struct swr_port_info *port_req; |
| 1076 | int ret = 0; |
| 1077 | struct swr_mstr_ctrl *swrm = swr_get_ctrl_data(master); |
| 1078 | struct swrm_mports *mport; |
| 1079 | u8 mstr_port_id, mstr_ch_msk; |
| 1080 | |
| 1081 | dev_dbg(&master->dev, "%s: enter\n", __func__); |
| 1082 | if (!portinfo) |
| 1083 | return -EINVAL; |
| 1084 | |
| 1085 | if (!swrm) { |
| 1086 | dev_err(&master->dev, |
| 1087 | "%s: Invalid handle to swr controller\n", |
| 1088 | __func__); |
| 1089 | return -EINVAL; |
| 1090 | } |
| 1091 | |
| 1092 | mutex_lock(&swrm->mlock); |
Ramprasad Katkam | 2a799b4 | 2018-10-04 20:23:28 +0530 | [diff] [blame] | 1093 | mutex_lock(&swrm->devlock); |
| 1094 | if (!swrm->dev_up) { |
| 1095 | mutex_unlock(&swrm->devlock); |
| 1096 | mutex_unlock(&swrm->mlock); |
| 1097 | return -EINVAL; |
| 1098 | } |
| 1099 | mutex_unlock(&swrm->devlock); |
Ramprasad Katkam | 7cb4ff6 | 2018-09-12 04:00:26 +0530 | [diff] [blame] | 1100 | if (!swrm_is_port_en(master)) |
| 1101 | pm_runtime_get_sync(swrm->dev); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 1102 | |
| 1103 | for (i = 0; i < portinfo->num_port; i++) { |
| 1104 | ret = swrm_get_master_port(swrm, &mstr_port_id, &mstr_ch_msk, |
| 1105 | portinfo->port_type[i], |
| 1106 | portinfo->port_id[i]); |
| 1107 | if (ret) { |
| 1108 | dev_err(&master->dev, |
| 1109 | "%s: mstr portid for slv port %d not found\n", |
| 1110 | __func__, portinfo->port_id[i]); |
| 1111 | goto port_fail; |
| 1112 | } |
| 1113 | |
| 1114 | mport = &(swrm->mport_cfg[mstr_port_id]); |
| 1115 | /* get port req */ |
| 1116 | port_req = swrm_get_port_req(mport, portinfo->port_id[i], |
| 1117 | portinfo->dev_num); |
| 1118 | if (!port_req) { |
| 1119 | dev_dbg(&master->dev, "%s: new req:port id %d dev %d\n", |
| 1120 | __func__, portinfo->port_id[i], |
| 1121 | portinfo->dev_num); |
| 1122 | port_req = kzalloc(sizeof(struct swr_port_info), |
| 1123 | GFP_KERNEL); |
| 1124 | if (!port_req) { |
| 1125 | ret = -ENOMEM; |
| 1126 | goto mem_fail; |
| 1127 | } |
| 1128 | port_req->dev_num = portinfo->dev_num; |
| 1129 | port_req->slave_port_id = portinfo->port_id[i]; |
| 1130 | port_req->num_ch = portinfo->num_ch[i]; |
| 1131 | port_req->ch_rate = portinfo->ch_rate[i]; |
| 1132 | port_req->ch_en = 0; |
| 1133 | port_req->master_port_id = mstr_port_id; |
| 1134 | list_add(&port_req->list, &mport->port_req_list); |
| 1135 | } |
| 1136 | port_req->req_ch |= portinfo->ch_en[i]; |
| 1137 | |
| 1138 | dev_dbg(&master->dev, |
| 1139 | "%s: mstr port %d, slv port %d ch_rate %d num_ch %d\n", |
| 1140 | __func__, port_req->master_port_id, |
| 1141 | port_req->slave_port_id, port_req->ch_rate, |
| 1142 | port_req->num_ch); |
| 1143 | /* Put the port req on master port */ |
| 1144 | mport = &(swrm->mport_cfg[mstr_port_id]); |
| 1145 | mport->port_en = true; |
| 1146 | mport->req_ch |= mstr_ch_msk; |
| 1147 | master->port_en_mask |= (1 << mstr_port_id); |
| 1148 | } |
| 1149 | master->num_port += portinfo->num_port; |
Ramprasad Katkam | cab8d72 | 2018-09-28 15:54:06 +0530 | [diff] [blame] | 1150 | set_bit(ENABLE_PENDING, &swrm->port_req_pending); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 1151 | swr_port_response(master, portinfo->tid); |
| 1152 | |
| 1153 | mutex_unlock(&swrm->mlock); |
| 1154 | return 0; |
| 1155 | |
| 1156 | port_fail: |
| 1157 | mem_fail: |
| 1158 | /* cleanup port reqs in error condition */ |
| 1159 | swrm_cleanup_disabled_port_reqs(master); |
| 1160 | mutex_unlock(&swrm->mlock); |
| 1161 | return ret; |
| 1162 | } |
| 1163 | |
| 1164 | static int swrm_disconnect_port(struct swr_master *master, |
| 1165 | struct swr_params *portinfo) |
| 1166 | { |
| 1167 | int i, ret = 0; |
| 1168 | struct swr_port_info *port_req; |
| 1169 | struct swrm_mports *mport; |
| 1170 | struct swr_mstr_ctrl *swrm = swr_get_ctrl_data(master); |
| 1171 | u8 mstr_port_id, mstr_ch_mask; |
| 1172 | |
| 1173 | if (!swrm) { |
| 1174 | dev_err(&master->dev, |
| 1175 | "%s: Invalid handle to swr controller\n", |
| 1176 | __func__); |
| 1177 | return -EINVAL; |
| 1178 | } |
| 1179 | |
| 1180 | if (!portinfo) { |
| 1181 | dev_err(&master->dev, "%s: portinfo is NULL\n", __func__); |
| 1182 | return -EINVAL; |
| 1183 | } |
| 1184 | mutex_lock(&swrm->mlock); |
| 1185 | |
| 1186 | for (i = 0; i < portinfo->num_port; i++) { |
| 1187 | |
| 1188 | ret = swrm_get_master_port(swrm, &mstr_port_id, &mstr_ch_mask, |
| 1189 | portinfo->port_type[i], portinfo->port_id[i]); |
| 1190 | if (ret) { |
| 1191 | dev_err(&master->dev, |
| 1192 | "%s: mstr portid for slv port %d not found\n", |
| 1193 | __func__, portinfo->port_id[i]); |
| 1194 | mutex_unlock(&swrm->mlock); |
| 1195 | return -EINVAL; |
| 1196 | } |
| 1197 | mport = &(swrm->mport_cfg[mstr_port_id]); |
| 1198 | /* get port req */ |
| 1199 | port_req = swrm_get_port_req(mport, portinfo->port_id[i], |
| 1200 | portinfo->dev_num); |
| 1201 | |
| 1202 | if (!port_req) { |
| 1203 | dev_err(&master->dev, "%s:port not enabled : port %d\n", |
| 1204 | __func__, portinfo->port_id[i]); |
Ramprasad Katkam | 86c45e0 | 2018-10-16 19:31:51 +0530 | [diff] [blame] | 1205 | mutex_unlock(&swrm->mlock); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 1206 | return -EINVAL; |
| 1207 | } |
| 1208 | port_req->req_ch &= ~portinfo->ch_en[i]; |
| 1209 | mport->req_ch &= ~mstr_ch_mask; |
| 1210 | } |
| 1211 | master->num_port -= portinfo->num_port; |
Ramprasad Katkam | cab8d72 | 2018-09-28 15:54:06 +0530 | [diff] [blame] | 1212 | set_bit(DISABLE_PENDING, &swrm->port_req_pending); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 1213 | swr_port_response(master, portinfo->tid); |
| 1214 | mutex_unlock(&swrm->mlock); |
| 1215 | |
| 1216 | return 0; |
| 1217 | } |
| 1218 | |
Ramprasad Katkam | 1f22126 | 2018-08-23 15:01:22 +0530 | [diff] [blame] | 1219 | static int swrm_find_alert_slave(struct swr_mstr_ctrl *swrm, |
| 1220 | int status, u8 *devnum) |
| 1221 | { |
| 1222 | int i; |
| 1223 | bool found = false; |
| 1224 | |
| 1225 | for (i = 0; i < (swrm->master.num_dev + 1); i++) { |
| 1226 | if ((status & SWRM_MCP_SLV_STATUS_MASK) == SWR_ALERT) { |
| 1227 | *devnum = i; |
| 1228 | found = true; |
| 1229 | break; |
| 1230 | } |
| 1231 | status >>= 2; |
| 1232 | } |
| 1233 | if (found) |
| 1234 | return 0; |
| 1235 | else |
| 1236 | return -EINVAL; |
| 1237 | } |
| 1238 | |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 1239 | static int swrm_check_slave_change_status(struct swr_mstr_ctrl *swrm, |
| 1240 | int status, u8 *devnum) |
| 1241 | { |
| 1242 | int i; |
| 1243 | int new_sts = status; |
| 1244 | int ret = SWR_NOT_PRESENT; |
| 1245 | |
| 1246 | if (status != swrm->slave_status) { |
| 1247 | for (i = 0; i < (swrm->master.num_dev + 1); i++) { |
| 1248 | if ((status & SWRM_MCP_SLV_STATUS_MASK) != |
| 1249 | (swrm->slave_status & SWRM_MCP_SLV_STATUS_MASK)) { |
| 1250 | ret = (status & SWRM_MCP_SLV_STATUS_MASK); |
| 1251 | *devnum = i; |
| 1252 | break; |
| 1253 | } |
| 1254 | status >>= 2; |
| 1255 | swrm->slave_status >>= 2; |
| 1256 | } |
| 1257 | swrm->slave_status = new_sts; |
| 1258 | } |
| 1259 | return ret; |
| 1260 | } |
| 1261 | |
| 1262 | static irqreturn_t swr_mstr_interrupt(int irq, void *dev) |
| 1263 | { |
| 1264 | struct swr_mstr_ctrl *swrm = dev; |
Ramprasad Katkam | 7e35478 | 2018-11-21 15:52:54 +0530 | [diff] [blame] | 1265 | u32 value, intr_sts, intr_sts_masked; |
Ramprasad Katkam | 1f22126 | 2018-08-23 15:01:22 +0530 | [diff] [blame] | 1266 | u32 temp = 0; |
| 1267 | u32 status, chg_sts, i; |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 1268 | u8 devnum = 0; |
| 1269 | int ret = IRQ_HANDLED; |
| 1270 | struct swr_device *swr_dev; |
| 1271 | struct swr_master *mstr = &swrm->master; |
| 1272 | |
Ramprasad Katkam | 5734987 | 2018-11-11 18:34:57 +0530 | [diff] [blame] | 1273 | if (unlikely(swrm_lock_sleep(swrm) == false)) { |
| 1274 | dev_err(swrm->dev, "%s Failed to hold suspend\n", __func__); |
| 1275 | return IRQ_NONE; |
| 1276 | } |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 1277 | |
| 1278 | mutex_lock(&swrm->reslock); |
Aditya Bavanari | f4a471d | 2019-02-19 17:57:12 +0530 | [diff] [blame] | 1279 | if (swrm_clk_request(swrm, true)) { |
Ramprasad Katkam | 14efed6 | 2019-03-07 13:16:50 +0530 | [diff] [blame] | 1280 | dev_err_ratelimited(swrm->dev, "%s:clk request failed\n", |
| 1281 | __func__); |
Aditya Bavanari | f4a471d | 2019-02-19 17:57:12 +0530 | [diff] [blame] | 1282 | mutex_unlock(&swrm->reslock); |
| 1283 | goto exit; |
| 1284 | } |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 1285 | mutex_unlock(&swrm->reslock); |
| 1286 | |
| 1287 | intr_sts = swr_master_read(swrm, SWRM_INTERRUPT_STATUS); |
Ramprasad Katkam | 7e35478 | 2018-11-21 15:52:54 +0530 | [diff] [blame] | 1288 | intr_sts_masked = intr_sts & swrm->intr_mask; |
Ramprasad Katkam | 8330351 | 2018-10-11 17:34:22 +0530 | [diff] [blame] | 1289 | handle_irq: |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 1290 | for (i = 0; i < SWRM_INTERRUPT_MAX; i++) { |
Ramprasad Katkam | 7e35478 | 2018-11-21 15:52:54 +0530 | [diff] [blame] | 1291 | value = intr_sts_masked & (1 << i); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 1292 | if (!value) |
| 1293 | continue; |
| 1294 | |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 1295 | switch (value) { |
| 1296 | case SWRM_INTERRUPT_STATUS_SLAVE_PEND_IRQ: |
| 1297 | dev_dbg(swrm->dev, "Trigger irq to slave device\n"); |
| 1298 | status = swr_master_read(swrm, SWRM_MCP_SLV_STATUS); |
Ramprasad Katkam | 1f22126 | 2018-08-23 15:01:22 +0530 | [diff] [blame] | 1299 | ret = swrm_find_alert_slave(swrm, status, &devnum); |
| 1300 | if (ret) { |
Ramprasad Katkam | 18bc8e2 | 2018-10-25 15:04:24 +0530 | [diff] [blame] | 1301 | dev_err_ratelimited(swrm->dev, |
| 1302 | "no slave alert found.spurious interrupt\n"); |
Ramprasad Katkam | 48b49b2 | 2018-10-01 20:12:46 +0530 | [diff] [blame] | 1303 | break; |
Ramprasad Katkam | 1f22126 | 2018-08-23 15:01:22 +0530 | [diff] [blame] | 1304 | } |
Ramprasad Katkam | 1f22126 | 2018-08-23 15:01:22 +0530 | [diff] [blame] | 1305 | swrm_cmd_fifo_rd_cmd(swrm, &temp, devnum, 0x0, |
| 1306 | SWRS_SCP_INT_STATUS_CLEAR_1, 1); |
| 1307 | swrm_cmd_fifo_wr_cmd(swrm, 0x4, devnum, 0x0, |
| 1308 | SWRS_SCP_INT_STATUS_CLEAR_1); |
| 1309 | swrm_cmd_fifo_wr_cmd(swrm, 0x0, devnum, 0x0, |
| 1310 | SWRS_SCP_INT_STATUS_CLEAR_1); |
Ramprasad Katkam | 62d6d76 | 2018-09-20 17:50:28 +0530 | [diff] [blame] | 1311 | |
| 1312 | |
| 1313 | list_for_each_entry(swr_dev, &mstr->devices, dev_list) { |
| 1314 | if (swr_dev->dev_num != devnum) |
| 1315 | continue; |
| 1316 | if (swr_dev->slave_irq) { |
| 1317 | do { |
| 1318 | handle_nested_irq( |
| 1319 | irq_find_mapping( |
| 1320 | swr_dev->slave_irq, 0)); |
| 1321 | } while (swr_dev->slave_irq_pending); |
| 1322 | } |
| 1323 | |
| 1324 | } |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 1325 | break; |
| 1326 | case SWRM_INTERRUPT_STATUS_NEW_SLAVE_ATTACHED: |
| 1327 | dev_dbg(swrm->dev, "SWR new slave attached\n"); |
| 1328 | break; |
| 1329 | case SWRM_INTERRUPT_STATUS_CHANGE_ENUM_SLAVE_STATUS: |
| 1330 | status = swr_master_read(swrm, SWRM_MCP_SLV_STATUS); |
| 1331 | if (status == swrm->slave_status) { |
| 1332 | dev_dbg(swrm->dev, |
| 1333 | "%s: No change in slave status: %d\n", |
| 1334 | __func__, status); |
| 1335 | break; |
| 1336 | } |
| 1337 | chg_sts = swrm_check_slave_change_status(swrm, status, |
| 1338 | &devnum); |
| 1339 | switch (chg_sts) { |
| 1340 | case SWR_NOT_PRESENT: |
| 1341 | dev_dbg(swrm->dev, "device %d got detached\n", |
| 1342 | devnum); |
| 1343 | break; |
| 1344 | case SWR_ATTACHED_OK: |
| 1345 | dev_dbg(swrm->dev, "device %d got attached\n", |
| 1346 | devnum); |
Ramprasad Katkam | debe893 | 2018-09-25 18:08:18 +0530 | [diff] [blame] | 1347 | /* enable host irq from slave device*/ |
| 1348 | swrm_cmd_fifo_wr_cmd(swrm, 0xFF, devnum, 0x0, |
| 1349 | SWRS_SCP_INT_STATUS_CLEAR_1); |
| 1350 | swrm_cmd_fifo_wr_cmd(swrm, 0x4, devnum, 0x0, |
| 1351 | SWRS_SCP_INT_STATUS_MASK_1); |
| 1352 | |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 1353 | break; |
| 1354 | case SWR_ALERT: |
| 1355 | dev_dbg(swrm->dev, |
| 1356 | "device %d has pending interrupt\n", |
| 1357 | devnum); |
| 1358 | break; |
| 1359 | } |
| 1360 | break; |
| 1361 | case SWRM_INTERRUPT_STATUS_MASTER_CLASH_DET: |
| 1362 | dev_err_ratelimited(swrm->dev, |
| 1363 | "SWR bus clsh detected\n"); |
| 1364 | break; |
| 1365 | case SWRM_INTERRUPT_STATUS_RD_FIFO_OVERFLOW: |
| 1366 | dev_dbg(swrm->dev, "SWR read FIFO overflow\n"); |
| 1367 | break; |
| 1368 | case SWRM_INTERRUPT_STATUS_RD_FIFO_UNDERFLOW: |
| 1369 | dev_dbg(swrm->dev, "SWR read FIFO underflow\n"); |
| 1370 | break; |
| 1371 | case SWRM_INTERRUPT_STATUS_WR_CMD_FIFO_OVERFLOW: |
| 1372 | dev_dbg(swrm->dev, "SWR write FIFO overflow\n"); |
| 1373 | break; |
| 1374 | case SWRM_INTERRUPT_STATUS_CMD_ERROR: |
| 1375 | value = swr_master_read(swrm, SWRM_CMD_FIFO_STATUS); |
| 1376 | dev_err_ratelimited(swrm->dev, |
| 1377 | "SWR CMD error, fifo status 0x%x, flushing fifo\n", |
| 1378 | value); |
| 1379 | swr_master_write(swrm, SWRM_CMD_FIFO_CMD, 0x1); |
| 1380 | break; |
| 1381 | case SWRM_INTERRUPT_STATUS_DOUT_PORT_COLLISION: |
Ramprasad Katkam | 18bc8e2 | 2018-10-25 15:04:24 +0530 | [diff] [blame] | 1382 | dev_err_ratelimited(swrm->dev, "SWR Port collision detected\n"); |
Ramprasad Katkam | 7e35478 | 2018-11-21 15:52:54 +0530 | [diff] [blame] | 1383 | swrm->intr_mask &= ~SWRM_INTERRUPT_STATUS_DOUT_PORT_COLLISION; |
Ramprasad Katkam | 18bc8e2 | 2018-10-25 15:04:24 +0530 | [diff] [blame] | 1384 | swr_master_write(swrm, |
Ramprasad Katkam | 7e35478 | 2018-11-21 15:52:54 +0530 | [diff] [blame] | 1385 | SWR_MSTR_RX_SWRM_CPU_INTERRUPT_EN, swrm->intr_mask); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 1386 | break; |
| 1387 | case SWRM_INTERRUPT_STATUS_READ_EN_RD_VALID_MISMATCH: |
| 1388 | dev_dbg(swrm->dev, "SWR read enable valid mismatch\n"); |
Ramprasad Katkam | 7e35478 | 2018-11-21 15:52:54 +0530 | [diff] [blame] | 1389 | swrm->intr_mask &= |
Ramprasad Katkam | 18bc8e2 | 2018-10-25 15:04:24 +0530 | [diff] [blame] | 1390 | ~SWRM_INTERRUPT_STATUS_READ_EN_RD_VALID_MISMATCH; |
| 1391 | swr_master_write(swrm, |
Ramprasad Katkam | 7e35478 | 2018-11-21 15:52:54 +0530 | [diff] [blame] | 1392 | SWR_MSTR_RX_SWRM_CPU_INTERRUPT_EN, swrm->intr_mask); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 1393 | break; |
| 1394 | case SWRM_INTERRUPT_STATUS_SPECIAL_CMD_ID_FINISHED: |
| 1395 | complete(&swrm->broadcast); |
| 1396 | dev_dbg(swrm->dev, "SWR cmd id finished\n"); |
| 1397 | break; |
| 1398 | case SWRM_INTERRUPT_STATUS_NEW_SLAVE_AUTO_ENUM_FINISHED: |
| 1399 | break; |
| 1400 | case SWRM_INTERRUPT_STATUS_AUTO_ENUM_FAILED: |
| 1401 | break; |
| 1402 | case SWRM_INTERRUPT_STATUS_AUTO_ENUM_TABLE_IS_FULL: |
| 1403 | break; |
| 1404 | case SWRM_INTERRUPT_STATUS_BUS_RESET_FINISHED: |
| 1405 | complete(&swrm->reset); |
| 1406 | break; |
| 1407 | case SWRM_INTERRUPT_STATUS_CLK_STOP_FINISHED: |
| 1408 | break; |
| 1409 | default: |
| 1410 | dev_err_ratelimited(swrm->dev, |
| 1411 | "SWR unknown interrupt\n"); |
| 1412 | ret = IRQ_NONE; |
| 1413 | break; |
| 1414 | } |
| 1415 | } |
Ramprasad Katkam | 1f22126 | 2018-08-23 15:01:22 +0530 | [diff] [blame] | 1416 | swr_master_write(swrm, SWRM_INTERRUPT_CLEAR, intr_sts); |
| 1417 | swr_master_write(swrm, SWRM_INTERRUPT_CLEAR, 0x0); |
Ramprasad Katkam | 8330351 | 2018-10-11 17:34:22 +0530 | [diff] [blame] | 1418 | |
| 1419 | intr_sts = swr_master_read(swrm, SWRM_INTERRUPT_STATUS); |
Ramprasad Katkam | 7e35478 | 2018-11-21 15:52:54 +0530 | [diff] [blame] | 1420 | intr_sts_masked = intr_sts & swrm->intr_mask; |
Ramprasad Katkam | 8330351 | 2018-10-11 17:34:22 +0530 | [diff] [blame] | 1421 | |
Ramprasad Katkam | 7e35478 | 2018-11-21 15:52:54 +0530 | [diff] [blame] | 1422 | if (intr_sts_masked) { |
Ramprasad Katkam | 8330351 | 2018-10-11 17:34:22 +0530 | [diff] [blame] | 1423 | dev_dbg(swrm->dev, "%s: new interrupt received\n", __func__); |
| 1424 | goto handle_irq; |
| 1425 | } |
| 1426 | |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 1427 | mutex_lock(&swrm->reslock); |
| 1428 | swrm_clk_request(swrm, false); |
| 1429 | mutex_unlock(&swrm->reslock); |
Aditya Bavanari | f4a471d | 2019-02-19 17:57:12 +0530 | [diff] [blame] | 1430 | exit: |
Ramprasad Katkam | 5734987 | 2018-11-11 18:34:57 +0530 | [diff] [blame] | 1431 | swrm_unlock_sleep(swrm); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 1432 | return ret; |
| 1433 | } |
| 1434 | |
Sudheer Papothi | d19d0c5 | 2019-02-23 05:41:39 +0530 | [diff] [blame] | 1435 | static irqreturn_t swr_mstr_interrupt_v2(int irq, void *dev) |
| 1436 | { |
| 1437 | struct swr_mstr_ctrl *swrm = dev; |
| 1438 | u32 value, intr_sts, intr_sts_masked; |
| 1439 | u32 temp = 0; |
| 1440 | u32 status, chg_sts, i; |
| 1441 | u8 devnum = 0; |
| 1442 | int ret = IRQ_HANDLED; |
| 1443 | struct swr_device *swr_dev; |
| 1444 | struct swr_master *mstr = &swrm->master; |
| 1445 | |
| 1446 | if (unlikely(swrm_lock_sleep(swrm) == false)) { |
| 1447 | dev_err(swrm->dev, "%s Failed to hold suspend\n", __func__); |
| 1448 | return IRQ_NONE; |
| 1449 | } |
| 1450 | |
| 1451 | mutex_lock(&swrm->reslock); |
Karthikeyan Mani | 035c50b | 2019-05-02 13:35:01 -0700 | [diff] [blame] | 1452 | if (swrm->lpass_core_hw_vote) { |
| 1453 | ret = clk_prepare_enable(swrm->lpass_core_hw_vote); |
| 1454 | if (ret < 0) { |
| 1455 | dev_err(dev, "%s:lpass core hw enable failed\n", |
| 1456 | __func__); |
| 1457 | ret = IRQ_NONE; |
| 1458 | goto exit; |
| 1459 | } |
| 1460 | } |
Sudheer Papothi | d19d0c5 | 2019-02-23 05:41:39 +0530 | [diff] [blame] | 1461 | swrm_clk_request(swrm, true); |
| 1462 | mutex_unlock(&swrm->reslock); |
| 1463 | |
| 1464 | intr_sts = swr_master_read(swrm, SWRM_INTERRUPT_STATUS); |
| 1465 | intr_sts_masked = intr_sts & swrm->intr_mask; |
| 1466 | handle_irq: |
| 1467 | for (i = 0; i < SWRM_INTERRUPT_MAX; i++) { |
| 1468 | value = intr_sts_masked & (1 << i); |
| 1469 | if (!value) |
| 1470 | continue; |
| 1471 | |
| 1472 | switch (value) { |
| 1473 | case SWRM_INTERRUPT_STATUS_SLAVE_PEND_IRQ: |
| 1474 | dev_dbg(swrm->dev, "%s: Trigger irq to slave device\n", |
| 1475 | __func__); |
| 1476 | status = swr_master_read(swrm, SWRM_MCP_SLV_STATUS); |
| 1477 | ret = swrm_find_alert_slave(swrm, status, &devnum); |
| 1478 | if (ret) { |
| 1479 | dev_err_ratelimited(swrm->dev, |
| 1480 | "%s: no slave alert found.spurious interrupt\n", |
| 1481 | __func__); |
| 1482 | break; |
| 1483 | } |
| 1484 | swrm_cmd_fifo_rd_cmd(swrm, &temp, devnum, 0x0, |
| 1485 | SWRS_SCP_INT_STATUS_CLEAR_1, 1); |
| 1486 | swrm_cmd_fifo_wr_cmd(swrm, 0x4, devnum, 0x0, |
| 1487 | SWRS_SCP_INT_STATUS_CLEAR_1); |
| 1488 | swrm_cmd_fifo_wr_cmd(swrm, 0x0, devnum, 0x0, |
| 1489 | SWRS_SCP_INT_STATUS_CLEAR_1); |
| 1490 | |
| 1491 | |
| 1492 | list_for_each_entry(swr_dev, &mstr->devices, dev_list) { |
| 1493 | if (swr_dev->dev_num != devnum) |
| 1494 | continue; |
| 1495 | if (swr_dev->slave_irq) { |
| 1496 | do { |
| 1497 | handle_nested_irq( |
| 1498 | irq_find_mapping( |
| 1499 | swr_dev->slave_irq, 0)); |
| 1500 | } while (swr_dev->slave_irq_pending); |
| 1501 | } |
| 1502 | |
| 1503 | } |
| 1504 | break; |
| 1505 | case SWRM_INTERRUPT_STATUS_NEW_SLAVE_ATTACHED: |
| 1506 | dev_dbg(swrm->dev, "%s: SWR new slave attached\n", |
| 1507 | __func__); |
| 1508 | break; |
| 1509 | case SWRM_INTERRUPT_STATUS_CHANGE_ENUM_SLAVE_STATUS: |
| 1510 | status = swr_master_read(swrm, SWRM_MCP_SLV_STATUS); |
| 1511 | if (status == swrm->slave_status) { |
| 1512 | dev_dbg(swrm->dev, |
| 1513 | "%s: No change in slave status: %d\n", |
| 1514 | __func__, status); |
| 1515 | break; |
| 1516 | } |
| 1517 | chg_sts = swrm_check_slave_change_status(swrm, status, |
| 1518 | &devnum); |
| 1519 | switch (chg_sts) { |
| 1520 | case SWR_NOT_PRESENT: |
| 1521 | dev_dbg(swrm->dev, |
| 1522 | "%s: device %d got detached\n", |
| 1523 | __func__, devnum); |
| 1524 | break; |
| 1525 | case SWR_ATTACHED_OK: |
| 1526 | dev_dbg(swrm->dev, |
| 1527 | "%s: device %d got attached\n", |
| 1528 | __func__, devnum); |
| 1529 | /* enable host irq from slave device*/ |
| 1530 | swrm_cmd_fifo_wr_cmd(swrm, 0xFF, devnum, 0x0, |
| 1531 | SWRS_SCP_INT_STATUS_CLEAR_1); |
| 1532 | swrm_cmd_fifo_wr_cmd(swrm, 0x4, devnum, 0x0, |
| 1533 | SWRS_SCP_INT_STATUS_MASK_1); |
| 1534 | |
| 1535 | break; |
| 1536 | case SWR_ALERT: |
| 1537 | dev_dbg(swrm->dev, |
| 1538 | "%s: device %d has pending interrupt\n", |
| 1539 | __func__, devnum); |
| 1540 | break; |
| 1541 | } |
| 1542 | break; |
| 1543 | case SWRM_INTERRUPT_STATUS_MASTER_CLASH_DET: |
| 1544 | dev_err_ratelimited(swrm->dev, |
| 1545 | "%s: SWR bus clsh detected\n", |
| 1546 | __func__); |
| 1547 | break; |
| 1548 | case SWRM_INTERRUPT_STATUS_RD_FIFO_OVERFLOW: |
| 1549 | dev_dbg(swrm->dev, "%s: SWR read FIFO overflow\n", |
| 1550 | __func__); |
| 1551 | break; |
| 1552 | case SWRM_INTERRUPT_STATUS_RD_FIFO_UNDERFLOW: |
| 1553 | dev_dbg(swrm->dev, "%s: SWR read FIFO underflow\n", |
| 1554 | __func__); |
| 1555 | break; |
| 1556 | case SWRM_INTERRUPT_STATUS_WR_CMD_FIFO_OVERFLOW: |
| 1557 | dev_dbg(swrm->dev, "%s: SWR write FIFO overflow\n", |
| 1558 | __func__); |
| 1559 | break; |
| 1560 | case SWRM_INTERRUPT_STATUS_CMD_ERROR: |
| 1561 | value = swr_master_read(swrm, SWRM_CMD_FIFO_STATUS); |
| 1562 | dev_err_ratelimited(swrm->dev, |
| 1563 | "%s: SWR CMD error, fifo status 0x%x, flushing fifo\n", |
| 1564 | __func__, value); |
| 1565 | swr_master_write(swrm, SWRM_CMD_FIFO_CMD, 0x1); |
| 1566 | break; |
| 1567 | case SWRM_INTERRUPT_STATUS_DOUT_PORT_COLLISION: |
| 1568 | dev_err_ratelimited(swrm->dev, |
| 1569 | "%s: SWR Port collision detected\n", |
| 1570 | __func__); |
| 1571 | swrm->intr_mask &= ~SWRM_INTERRUPT_STATUS_DOUT_PORT_COLLISION; |
| 1572 | swr_master_write(swrm, |
| 1573 | SWR_MSTR_RX_SWRM_CPU_INTERRUPT_EN, swrm->intr_mask); |
| 1574 | break; |
| 1575 | case SWRM_INTERRUPT_STATUS_READ_EN_RD_VALID_MISMATCH: |
| 1576 | dev_dbg(swrm->dev, |
| 1577 | "%s: SWR read enable valid mismatch\n", |
| 1578 | __func__); |
| 1579 | swrm->intr_mask &= |
| 1580 | ~SWRM_INTERRUPT_STATUS_READ_EN_RD_VALID_MISMATCH; |
| 1581 | swr_master_write(swrm, |
| 1582 | SWR_MSTR_RX_SWRM_CPU_INTERRUPT_EN, swrm->intr_mask); |
| 1583 | break; |
| 1584 | case SWRM_INTERRUPT_STATUS_SPECIAL_CMD_ID_FINISHED: |
| 1585 | complete(&swrm->broadcast); |
| 1586 | dev_dbg(swrm->dev, "%s: SWR cmd id finished\n", |
| 1587 | __func__); |
| 1588 | break; |
| 1589 | case SWRM_INTERRUPT_STATUS_AUTO_ENUM_FAILED_V2: |
| 1590 | break; |
| 1591 | case SWRM_INTERRUPT_STATUS_AUTO_ENUM_TABLE_IS_FULL_V2: |
| 1592 | break; |
| 1593 | case SWRM_INTERRUPT_STATUS_BUS_RESET_FINISHED_V2: |
| 1594 | break; |
| 1595 | case SWRM_INTERRUPT_STATUS_CLK_STOP_FINISHED_V2: |
| 1596 | break; |
| 1597 | case SWRM_INTERRUPT_STATUS_EXT_CLK_STOP_WAKEUP: |
| 1598 | if (swrm->state == SWR_MSTR_UP) |
| 1599 | dev_dbg(swrm->dev, |
| 1600 | "%s:SWR Master is already up\n", |
| 1601 | __func__); |
| 1602 | else |
| 1603 | dev_err_ratelimited(swrm->dev, |
| 1604 | "%s: SWR wokeup during clock stop\n", |
| 1605 | __func__); |
| 1606 | break; |
| 1607 | default: |
| 1608 | dev_err_ratelimited(swrm->dev, |
| 1609 | "%s: SWR unknown interrupt value: %d\n", |
| 1610 | __func__, value); |
| 1611 | ret = IRQ_NONE; |
| 1612 | break; |
| 1613 | } |
| 1614 | } |
| 1615 | swr_master_write(swrm, SWRM_INTERRUPT_CLEAR, intr_sts); |
| 1616 | swr_master_write(swrm, SWRM_INTERRUPT_CLEAR, 0x0); |
| 1617 | |
| 1618 | intr_sts = swr_master_read(swrm, SWRM_INTERRUPT_STATUS); |
| 1619 | intr_sts_masked = intr_sts & swrm->intr_mask; |
| 1620 | |
| 1621 | if (intr_sts_masked) { |
| 1622 | dev_dbg(swrm->dev, "%s: new interrupt received\n", __func__); |
| 1623 | goto handle_irq; |
| 1624 | } |
| 1625 | |
| 1626 | mutex_lock(&swrm->reslock); |
| 1627 | swrm_clk_request(swrm, false); |
Sudheer Papothi | 66d6fd1 | 2019-03-27 17:34:48 +0530 | [diff] [blame] | 1628 | if (swrm->lpass_core_hw_vote) |
| 1629 | clk_disable_unprepare(swrm->lpass_core_hw_vote); |
Karthikeyan Mani | 035c50b | 2019-05-02 13:35:01 -0700 | [diff] [blame] | 1630 | exit: |
Sudheer Papothi | d19d0c5 | 2019-02-23 05:41:39 +0530 | [diff] [blame] | 1631 | mutex_unlock(&swrm->reslock); |
| 1632 | swrm_unlock_sleep(swrm); |
| 1633 | return ret; |
| 1634 | } |
| 1635 | |
Aditya Bavanari | c034fad | 2018-11-12 22:55:11 +0530 | [diff] [blame] | 1636 | static irqreturn_t swrm_wakeup_interrupt(int irq, void *dev) |
| 1637 | { |
| 1638 | struct swr_mstr_ctrl *swrm = dev; |
| 1639 | int ret = IRQ_HANDLED; |
| 1640 | |
| 1641 | if (!swrm || !(swrm->dev)) { |
| 1642 | pr_err("%s: swrm or dev is null\n", __func__); |
| 1643 | return IRQ_NONE; |
| 1644 | } |
| 1645 | mutex_lock(&swrm->devlock); |
| 1646 | if (!swrm->dev_up) { |
| 1647 | if (swrm->wake_irq > 0) |
| 1648 | disable_irq_nosync(swrm->wake_irq); |
| 1649 | mutex_unlock(&swrm->devlock); |
| 1650 | return ret; |
| 1651 | } |
| 1652 | mutex_unlock(&swrm->devlock); |
Ramprasad Katkam | 44b7a96 | 2018-12-20 15:08:44 +0530 | [diff] [blame] | 1653 | if (unlikely(swrm_lock_sleep(swrm) == false)) { |
| 1654 | dev_err(swrm->dev, "%s Failed to hold suspend\n", __func__); |
| 1655 | goto exit; |
| 1656 | } |
Aditya Bavanari | c034fad | 2018-11-12 22:55:11 +0530 | [diff] [blame] | 1657 | if (swrm->wake_irq > 0) |
| 1658 | disable_irq_nosync(swrm->wake_irq); |
| 1659 | pm_runtime_get_sync(swrm->dev); |
| 1660 | pm_runtime_mark_last_busy(swrm->dev); |
| 1661 | pm_runtime_put_autosuspend(swrm->dev); |
Ramprasad Katkam | 44b7a96 | 2018-12-20 15:08:44 +0530 | [diff] [blame] | 1662 | swrm_unlock_sleep(swrm); |
| 1663 | exit: |
Aditya Bavanari | c034fad | 2018-11-12 22:55:11 +0530 | [diff] [blame] | 1664 | return ret; |
| 1665 | } |
| 1666 | |
Laxminath Kasam | f0128ef | 2018-08-31 15:15:09 +0530 | [diff] [blame] | 1667 | static void swrm_wakeup_work(struct work_struct *work) |
| 1668 | { |
| 1669 | struct swr_mstr_ctrl *swrm; |
| 1670 | |
| 1671 | swrm = container_of(work, struct swr_mstr_ctrl, |
| 1672 | wakeup_work); |
| 1673 | if (!swrm || !(swrm->dev)) { |
| 1674 | pr_err("%s: swrm or dev is null\n", __func__); |
| 1675 | return; |
| 1676 | } |
Ramprasad Katkam | 2a799b4 | 2018-10-04 20:23:28 +0530 | [diff] [blame] | 1677 | |
| 1678 | mutex_lock(&swrm->devlock); |
| 1679 | if (!swrm->dev_up) { |
| 1680 | mutex_unlock(&swrm->devlock); |
Ramprasad Katkam | 5734987 | 2018-11-11 18:34:57 +0530 | [diff] [blame] | 1681 | goto exit; |
Ramprasad Katkam | 2a799b4 | 2018-10-04 20:23:28 +0530 | [diff] [blame] | 1682 | } |
| 1683 | mutex_unlock(&swrm->devlock); |
Ramprasad Katkam | 5734987 | 2018-11-11 18:34:57 +0530 | [diff] [blame] | 1684 | if (unlikely(swrm_lock_sleep(swrm) == false)) { |
| 1685 | dev_err(swrm->dev, "%s Failed to hold suspend\n", __func__); |
| 1686 | goto exit; |
| 1687 | } |
Laxminath Kasam | f0128ef | 2018-08-31 15:15:09 +0530 | [diff] [blame] | 1688 | pm_runtime_get_sync(swrm->dev); |
Laxminath Kasam | f0128ef | 2018-08-31 15:15:09 +0530 | [diff] [blame] | 1689 | pm_runtime_mark_last_busy(swrm->dev); |
| 1690 | pm_runtime_put_autosuspend(swrm->dev); |
Ramprasad Katkam | 5734987 | 2018-11-11 18:34:57 +0530 | [diff] [blame] | 1691 | swrm_unlock_sleep(swrm); |
| 1692 | exit: |
| 1693 | pm_relax(swrm->dev); |
Laxminath Kasam | f0128ef | 2018-08-31 15:15:09 +0530 | [diff] [blame] | 1694 | } |
| 1695 | |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 1696 | static int swrm_get_device_status(struct swr_mstr_ctrl *swrm, u8 devnum) |
| 1697 | { |
| 1698 | u32 val; |
| 1699 | |
| 1700 | swrm->slave_status = swr_master_read(swrm, SWRM_MCP_SLV_STATUS); |
| 1701 | val = (swrm->slave_status >> (devnum * 2)); |
| 1702 | val &= SWRM_MCP_SLV_STATUS_MASK; |
| 1703 | return val; |
| 1704 | } |
| 1705 | |
| 1706 | static int swrm_get_logical_dev_num(struct swr_master *mstr, u64 dev_id, |
| 1707 | u8 *dev_num) |
| 1708 | { |
| 1709 | int i; |
| 1710 | u64 id = 0; |
| 1711 | int ret = -EINVAL; |
| 1712 | struct swr_mstr_ctrl *swrm = swr_get_ctrl_data(mstr); |
| 1713 | struct swr_device *swr_dev; |
| 1714 | u32 num_dev = 0; |
| 1715 | |
| 1716 | if (!swrm) { |
| 1717 | pr_err("%s: Invalid handle to swr controller\n", |
| 1718 | __func__); |
| 1719 | return ret; |
| 1720 | } |
| 1721 | if (swrm->num_dev) |
| 1722 | num_dev = swrm->num_dev; |
| 1723 | else |
| 1724 | num_dev = mstr->num_dev; |
Ramprasad Katkam | 2a799b4 | 2018-10-04 20:23:28 +0530 | [diff] [blame] | 1725 | |
| 1726 | mutex_lock(&swrm->devlock); |
| 1727 | if (!swrm->dev_up) { |
| 1728 | mutex_unlock(&swrm->devlock); |
| 1729 | return ret; |
| 1730 | } |
| 1731 | mutex_unlock(&swrm->devlock); |
| 1732 | |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 1733 | pm_runtime_get_sync(swrm->dev); |
| 1734 | for (i = 1; i < (num_dev + 1); i++) { |
| 1735 | id = ((u64)(swr_master_read(swrm, |
| 1736 | SWRM_ENUMERATOR_SLAVE_DEV_ID_2(i))) << 32); |
| 1737 | id |= swr_master_read(swrm, |
| 1738 | SWRM_ENUMERATOR_SLAVE_DEV_ID_1(i)); |
Ramprasad Katkam | 1f22126 | 2018-08-23 15:01:22 +0530 | [diff] [blame] | 1739 | |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 1740 | /* |
| 1741 | * As pm_runtime_get_sync() brings all slaves out of reset |
| 1742 | * update logical device number for all slaves. |
| 1743 | */ |
| 1744 | list_for_each_entry(swr_dev, &mstr->devices, dev_list) { |
| 1745 | if (swr_dev->addr == (id & SWR_DEV_ID_MASK)) { |
| 1746 | u32 status = swrm_get_device_status(swrm, i); |
| 1747 | |
| 1748 | if ((status == 0x01) || (status == 0x02)) { |
| 1749 | swr_dev->dev_num = i; |
| 1750 | if ((id & SWR_DEV_ID_MASK) == dev_id) { |
| 1751 | *dev_num = i; |
| 1752 | ret = 0; |
| 1753 | } |
| 1754 | dev_dbg(swrm->dev, |
| 1755 | "%s: devnum %d is assigned for dev addr %lx\n", |
| 1756 | __func__, i, swr_dev->addr); |
| 1757 | } |
| 1758 | } |
| 1759 | } |
| 1760 | } |
| 1761 | if (ret) |
| 1762 | dev_err(swrm->dev, "%s: device 0x%llx is not ready\n", |
| 1763 | __func__, dev_id); |
| 1764 | |
| 1765 | pm_runtime_mark_last_busy(swrm->dev); |
| 1766 | pm_runtime_put_autosuspend(swrm->dev); |
| 1767 | return ret; |
| 1768 | } |
Sudheer Papothi | 6abd2de | 2018-09-05 05:57:04 +0530 | [diff] [blame] | 1769 | |
| 1770 | static void swrm_device_wakeup_vote(struct swr_master *mstr) |
| 1771 | { |
| 1772 | struct swr_mstr_ctrl *swrm = swr_get_ctrl_data(mstr); |
| 1773 | |
| 1774 | if (!swrm) { |
| 1775 | pr_err("%s: Invalid handle to swr controller\n", |
| 1776 | __func__); |
| 1777 | return; |
| 1778 | } |
Ramprasad Katkam | 5734987 | 2018-11-11 18:34:57 +0530 | [diff] [blame] | 1779 | if (unlikely(swrm_lock_sleep(swrm) == false)) { |
| 1780 | dev_err(swrm->dev, "%s Failed to hold suspend\n", __func__); |
| 1781 | return; |
| 1782 | } |
Sudheer Papothi | 6abd2de | 2018-09-05 05:57:04 +0530 | [diff] [blame] | 1783 | pm_runtime_get_sync(swrm->dev); |
| 1784 | } |
| 1785 | |
| 1786 | static void swrm_device_wakeup_unvote(struct swr_master *mstr) |
| 1787 | { |
| 1788 | struct swr_mstr_ctrl *swrm = swr_get_ctrl_data(mstr); |
| 1789 | |
| 1790 | if (!swrm) { |
| 1791 | pr_err("%s: Invalid handle to swr controller\n", |
| 1792 | __func__); |
| 1793 | return; |
| 1794 | } |
| 1795 | pm_runtime_mark_last_busy(swrm->dev); |
| 1796 | pm_runtime_put_autosuspend(swrm->dev); |
Ramprasad Katkam | 5734987 | 2018-11-11 18:34:57 +0530 | [diff] [blame] | 1797 | swrm_unlock_sleep(swrm); |
Sudheer Papothi | 6abd2de | 2018-09-05 05:57:04 +0530 | [diff] [blame] | 1798 | } |
| 1799 | |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 1800 | static int swrm_master_init(struct swr_mstr_ctrl *swrm) |
| 1801 | { |
| 1802 | int ret = 0; |
| 1803 | u32 val; |
Ramprasad Katkam | 14f47cc | 2018-07-25 17:20:18 +0530 | [diff] [blame] | 1804 | u8 row_ctrl = SWR_ROW_50; |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 1805 | u8 col_ctrl = SWR_MIN_COL; |
| 1806 | u8 ssp_period = 1; |
| 1807 | u8 retry_cmd_num = 3; |
| 1808 | u32 reg[SWRM_MAX_INIT_REG]; |
| 1809 | u32 value[SWRM_MAX_INIT_REG]; |
| 1810 | int len = 0; |
| 1811 | |
| 1812 | /* Clear Rows and Cols */ |
| 1813 | val = ((row_ctrl << SWRM_MCP_FRAME_CTRL_BANK_ROW_CTRL_SHFT) | |
| 1814 | (col_ctrl << SWRM_MCP_FRAME_CTRL_BANK_COL_CTRL_SHFT) | |
| 1815 | (ssp_period << SWRM_MCP_FRAME_CTRL_BANK_SSP_PERIOD_SHFT)); |
| 1816 | |
| 1817 | reg[len] = SWRM_MCP_FRAME_CTRL_BANK_ADDR(0); |
| 1818 | value[len++] = val; |
| 1819 | |
| 1820 | /* Set Auto enumeration flag */ |
| 1821 | reg[len] = SWRM_ENUMERATOR_CFG_ADDR; |
| 1822 | value[len++] = 1; |
| 1823 | |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 1824 | /* Configure No pings */ |
| 1825 | val = swr_master_read(swrm, SWRM_MCP_CFG_ADDR); |
| 1826 | val &= ~SWRM_MCP_CFG_MAX_NUM_OF_CMD_NO_PINGS_BMSK; |
| 1827 | val |= (0x1f << SWRM_MCP_CFG_MAX_NUM_OF_CMD_NO_PINGS_SHFT); |
| 1828 | reg[len] = SWRM_MCP_CFG_ADDR; |
| 1829 | value[len++] = val; |
| 1830 | |
| 1831 | /* Configure number of retries of a read/write cmd */ |
| 1832 | val = (retry_cmd_num << SWRM_CMD_FIFO_CFG_NUM_OF_CMD_RETRY_SHFT); |
| 1833 | reg[len] = SWRM_CMD_FIFO_CFG_ADDR; |
| 1834 | value[len++] = val; |
| 1835 | |
Ramprasad Katkam | 1f22126 | 2018-08-23 15:01:22 +0530 | [diff] [blame] | 1836 | reg[len] = SWRM_MCP_BUS_CTRL_ADDR; |
| 1837 | value[len++] = 0x2; |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 1838 | |
Ramprasad Katkam | 8330351 | 2018-10-11 17:34:22 +0530 | [diff] [blame] | 1839 | /* Set IRQ to PULSE */ |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 1840 | reg[len] = SWRM_COMP_CFG_ADDR; |
Ramprasad Katkam | 8330351 | 2018-10-11 17:34:22 +0530 | [diff] [blame] | 1841 | value[len++] = 0x02; |
| 1842 | |
| 1843 | reg[len] = SWRM_COMP_CFG_ADDR; |
| 1844 | value[len++] = 0x03; |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 1845 | |
| 1846 | reg[len] = SWRM_INTERRUPT_CLEAR; |
Ramprasad Katkam | 1f22126 | 2018-08-23 15:01:22 +0530 | [diff] [blame] | 1847 | value[len++] = 0xFFFFFFFF; |
| 1848 | |
Ramprasad Katkam | 7e35478 | 2018-11-21 15:52:54 +0530 | [diff] [blame] | 1849 | swrm->intr_mask = SWRM_INTERRUPT_STATUS_MASK; |
Ramprasad Katkam | 1f22126 | 2018-08-23 15:01:22 +0530 | [diff] [blame] | 1850 | /* Mask soundwire interrupts */ |
| 1851 | reg[len] = SWRM_INTERRUPT_MASK_ADDR; |
Ramprasad Katkam | 7e35478 | 2018-11-21 15:52:54 +0530 | [diff] [blame] | 1852 | value[len++] = swrm->intr_mask; |
Ramprasad Katkam | 1f22126 | 2018-08-23 15:01:22 +0530 | [diff] [blame] | 1853 | |
| 1854 | reg[len] = SWR_MSTR_RX_SWRM_CPU_INTERRUPT_EN; |
Ramprasad Katkam | 7e35478 | 2018-11-21 15:52:54 +0530 | [diff] [blame] | 1855 | value[len++] = swrm->intr_mask; |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 1856 | |
| 1857 | swr_master_bulk_write(swrm, reg, value, len); |
| 1858 | |
Sudheer Papothi | 63f4815 | 2018-11-15 01:08:03 +0530 | [diff] [blame] | 1859 | /* |
| 1860 | * For SWR master version 1.5.1, continue |
| 1861 | * execute on command ignore. |
| 1862 | */ |
| 1863 | if (swrm->version == SWRM_VERSION_1_5_1) |
| 1864 | swr_master_write(swrm, SWRM_CMD_FIFO_CFG_ADDR, |
| 1865 | (swr_master_read(swrm, |
| 1866 | SWRM_CMD_FIFO_CFG_ADDR) | 0x80000000)); |
| 1867 | |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 1868 | return ret; |
| 1869 | } |
| 1870 | |
Ramprasad Katkam | 68765ab | 2018-08-30 11:46:32 +0530 | [diff] [blame] | 1871 | static int swrm_event_notify(struct notifier_block *self, |
Laxminath Kasam | f0128ef | 2018-08-31 15:15:09 +0530 | [diff] [blame] | 1872 | unsigned long action, void *data) |
Ramprasad Katkam | 68765ab | 2018-08-30 11:46:32 +0530 | [diff] [blame] | 1873 | { |
| 1874 | struct swr_mstr_ctrl *swrm = container_of(self, struct swr_mstr_ctrl, |
Laxminath Kasam | f0128ef | 2018-08-31 15:15:09 +0530 | [diff] [blame] | 1875 | event_notifier); |
| 1876 | |
| 1877 | if (!swrm || !(swrm->dev)) { |
| 1878 | pr_err("%s: swrm or dev is NULL\n", __func__); |
Ramprasad Katkam | 68765ab | 2018-08-30 11:46:32 +0530 | [diff] [blame] | 1879 | return -EINVAL; |
| 1880 | } |
Laxminath Kasam | f0128ef | 2018-08-31 15:15:09 +0530 | [diff] [blame] | 1881 | switch (action) { |
| 1882 | case MSM_AUD_DC_EVENT: |
| 1883 | schedule_work(&(swrm->dc_presence_work)); |
| 1884 | break; |
| 1885 | case SWR_WAKE_IRQ_EVENT: |
Aditya Bavanari | c034fad | 2018-11-12 22:55:11 +0530 | [diff] [blame] | 1886 | if (swrm->ipc_wakeup && !swrm->ipc_wakeup_triggered) { |
| 1887 | swrm->ipc_wakeup_triggered = true; |
Ramprasad Katkam | 5734987 | 2018-11-11 18:34:57 +0530 | [diff] [blame] | 1888 | pm_stay_awake(swrm->dev); |
Laxminath Kasam | f0128ef | 2018-08-31 15:15:09 +0530 | [diff] [blame] | 1889 | schedule_work(&swrm->wakeup_work); |
Ramprasad Katkam | cd61c6e | 2018-09-18 13:22:58 +0530 | [diff] [blame] | 1890 | } |
Laxminath Kasam | f0128ef | 2018-08-31 15:15:09 +0530 | [diff] [blame] | 1891 | break; |
| 1892 | default: |
| 1893 | dev_err(swrm->dev, "%s: invalid event type: %lu\n", |
Ramprasad Katkam | 68765ab | 2018-08-30 11:46:32 +0530 | [diff] [blame] | 1894 | __func__, action); |
| 1895 | return -EINVAL; |
| 1896 | } |
| 1897 | |
Ramprasad Katkam | 68765ab | 2018-08-30 11:46:32 +0530 | [diff] [blame] | 1898 | return 0; |
| 1899 | } |
| 1900 | |
| 1901 | static void swrm_notify_work_fn(struct work_struct *work) |
| 1902 | { |
| 1903 | struct swr_mstr_ctrl *swrm = container_of(work, struct swr_mstr_ctrl, |
Laxminath Kasam | f0128ef | 2018-08-31 15:15:09 +0530 | [diff] [blame] | 1904 | dc_presence_work); |
| 1905 | |
| 1906 | if (!swrm || !swrm->pdev) { |
| 1907 | pr_err("%s: swrm or pdev is NULL\n", __func__); |
| 1908 | return; |
| 1909 | } |
Ramprasad Katkam | 68765ab | 2018-08-30 11:46:32 +0530 | [diff] [blame] | 1910 | swrm_wcd_notify(swrm->pdev, SWR_DEVICE_DOWN, NULL); |
| 1911 | } |
| 1912 | |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 1913 | static int swrm_probe(struct platform_device *pdev) |
| 1914 | { |
| 1915 | struct swr_mstr_ctrl *swrm; |
| 1916 | struct swr_ctrl_platform_data *pdata; |
| 1917 | u32 i, num_ports, port_num, port_type, ch_mask; |
| 1918 | u32 *temp, map_size, map_length, ch_iter = 0, old_port_num = 0; |
| 1919 | int ret = 0; |
Sudheer Papothi | 66d6fd1 | 2019-03-27 17:34:48 +0530 | [diff] [blame] | 1920 | struct clk *lpass_core_hw_vote = NULL; |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 1921 | |
| 1922 | /* Allocate soundwire master driver structure */ |
| 1923 | swrm = devm_kzalloc(&pdev->dev, sizeof(struct swr_mstr_ctrl), |
| 1924 | GFP_KERNEL); |
| 1925 | if (!swrm) { |
| 1926 | ret = -ENOMEM; |
| 1927 | goto err_memory_fail; |
| 1928 | } |
Laxminath Kasam | f0128ef | 2018-08-31 15:15:09 +0530 | [diff] [blame] | 1929 | swrm->pdev = pdev; |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 1930 | swrm->dev = &pdev->dev; |
| 1931 | platform_set_drvdata(pdev, swrm); |
| 1932 | swr_set_ctrl_data(&swrm->master, swrm); |
| 1933 | pdata = dev_get_platdata(&pdev->dev); |
| 1934 | if (!pdata) { |
| 1935 | dev_err(&pdev->dev, "%s: pdata from parent is NULL\n", |
| 1936 | __func__); |
| 1937 | ret = -EINVAL; |
| 1938 | goto err_pdata_fail; |
| 1939 | } |
| 1940 | swrm->handle = (void *)pdata->handle; |
| 1941 | if (!swrm->handle) { |
| 1942 | dev_err(&pdev->dev, "%s: swrm->handle is NULL\n", |
| 1943 | __func__); |
| 1944 | ret = -EINVAL; |
| 1945 | goto err_pdata_fail; |
| 1946 | } |
Ramprasad Katkam | 14f47cc | 2018-07-25 17:20:18 +0530 | [diff] [blame] | 1947 | ret = of_property_read_u32(pdev->dev.of_node, "qcom,swr_master_id", |
| 1948 | &swrm->master_id); |
| 1949 | if (ret) { |
| 1950 | dev_err(&pdev->dev, "%s: failed to get master id\n", __func__); |
| 1951 | goto err_pdata_fail; |
| 1952 | } |
Laxminath Kasam | fbcaf32 | 2018-07-18 00:38:14 +0530 | [diff] [blame] | 1953 | if (!(of_property_read_u32(pdev->dev.of_node, |
| 1954 | "swrm-io-base", &swrm->swrm_base_reg))) |
| 1955 | ret = of_property_read_u32(pdev->dev.of_node, |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 1956 | "swrm-io-base", &swrm->swrm_base_reg); |
| 1957 | if (!swrm->swrm_base_reg) { |
| 1958 | swrm->read = pdata->read; |
| 1959 | if (!swrm->read) { |
| 1960 | dev_err(&pdev->dev, "%s: swrm->read is NULL\n", |
| 1961 | __func__); |
| 1962 | ret = -EINVAL; |
| 1963 | goto err_pdata_fail; |
| 1964 | } |
| 1965 | swrm->write = pdata->write; |
| 1966 | if (!swrm->write) { |
| 1967 | dev_err(&pdev->dev, "%s: swrm->write is NULL\n", |
| 1968 | __func__); |
| 1969 | ret = -EINVAL; |
| 1970 | goto err_pdata_fail; |
| 1971 | } |
| 1972 | swrm->bulk_write = pdata->bulk_write; |
| 1973 | if (!swrm->bulk_write) { |
| 1974 | dev_err(&pdev->dev, "%s: swrm->bulk_write is NULL\n", |
| 1975 | __func__); |
| 1976 | ret = -EINVAL; |
| 1977 | goto err_pdata_fail; |
| 1978 | } |
| 1979 | } else { |
| 1980 | swrm->swrm_dig_base = devm_ioremap(&pdev->dev, |
| 1981 | swrm->swrm_base_reg, SWRM_MAX_REGISTER); |
| 1982 | } |
| 1983 | |
| 1984 | swrm->clk = pdata->clk; |
| 1985 | if (!swrm->clk) { |
| 1986 | dev_err(&pdev->dev, "%s: swrm->clk is NULL\n", |
| 1987 | __func__); |
| 1988 | ret = -EINVAL; |
| 1989 | goto err_pdata_fail; |
| 1990 | } |
Ramprasad Katkam | 14f47cc | 2018-07-25 17:20:18 +0530 | [diff] [blame] | 1991 | if (of_property_read_u32(pdev->dev.of_node, |
| 1992 | "qcom,swr-clock-stop-mode0", |
| 1993 | &swrm->clk_stop_mode0_supp)) { |
| 1994 | swrm->clk_stop_mode0_supp = FALSE; |
| 1995 | } |
Ramprasad Katkam | 5734987 | 2018-11-11 18:34:57 +0530 | [diff] [blame] | 1996 | |
| 1997 | ret = of_property_read_u32(swrm->dev->of_node, "qcom,swr-num-dev", |
| 1998 | &swrm->num_dev); |
| 1999 | if (ret) { |
| 2000 | dev_dbg(&pdev->dev, "%s: Looking up %s property failed\n", |
| 2001 | __func__, "qcom,swr-num-dev"); |
| 2002 | } else { |
| 2003 | if (swrm->num_dev > SWR_MAX_SLAVE_DEVICES) { |
| 2004 | dev_err(&pdev->dev, "%s: num_dev %d > max limit %d\n", |
| 2005 | __func__, swrm->num_dev, SWR_MAX_SLAVE_DEVICES); |
| 2006 | ret = -EINVAL; |
| 2007 | goto err_pdata_fail; |
| 2008 | } |
| 2009 | } |
| 2010 | |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 2011 | /* Parse soundwire port mapping */ |
| 2012 | ret = of_property_read_u32(pdev->dev.of_node, "qcom,swr-num-ports", |
| 2013 | &num_ports); |
| 2014 | if (ret) { |
| 2015 | dev_err(swrm->dev, "%s: Failed to get num_ports\n", __func__); |
| 2016 | goto err_pdata_fail; |
| 2017 | } |
| 2018 | swrm->num_ports = num_ports; |
| 2019 | |
| 2020 | if (!of_find_property(pdev->dev.of_node, "qcom,swr-port-mapping", |
| 2021 | &map_size)) { |
| 2022 | dev_err(swrm->dev, "missing port mapping\n"); |
| 2023 | goto err_pdata_fail; |
| 2024 | } |
| 2025 | |
| 2026 | map_length = map_size / (3 * sizeof(u32)); |
| 2027 | if (num_ports > SWR_MSTR_PORT_LEN) { |
| 2028 | dev_err(&pdev->dev, "%s:invalid number of swr ports\n", |
| 2029 | __func__); |
| 2030 | ret = -EINVAL; |
| 2031 | goto err_pdata_fail; |
| 2032 | } |
| 2033 | temp = devm_kzalloc(&pdev->dev, map_size, GFP_KERNEL); |
| 2034 | |
| 2035 | if (!temp) { |
| 2036 | ret = -ENOMEM; |
| 2037 | goto err_pdata_fail; |
| 2038 | } |
| 2039 | ret = of_property_read_u32_array(pdev->dev.of_node, |
| 2040 | "qcom,swr-port-mapping", temp, 3 * map_length); |
| 2041 | if (ret) { |
| 2042 | dev_err(swrm->dev, "%s: Failed to read port mapping\n", |
| 2043 | __func__); |
| 2044 | goto err_pdata_fail; |
| 2045 | } |
| 2046 | |
| 2047 | for (i = 0; i < map_length; i++) { |
| 2048 | port_num = temp[3 * i]; |
| 2049 | port_type = temp[3 * i + 1]; |
| 2050 | ch_mask = temp[3 * i + 2]; |
| 2051 | |
| 2052 | if (port_num != old_port_num) |
| 2053 | ch_iter = 0; |
| 2054 | swrm->port_mapping[port_num][ch_iter].port_type = port_type; |
| 2055 | swrm->port_mapping[port_num][ch_iter++].ch_mask = ch_mask; |
| 2056 | old_port_num = port_num; |
| 2057 | } |
| 2058 | devm_kfree(&pdev->dev, temp); |
| 2059 | |
| 2060 | swrm->reg_irq = pdata->reg_irq; |
| 2061 | swrm->master.read = swrm_read; |
| 2062 | swrm->master.write = swrm_write; |
| 2063 | swrm->master.bulk_write = swrm_bulk_write; |
| 2064 | swrm->master.get_logical_dev_num = swrm_get_logical_dev_num; |
| 2065 | swrm->master.connect_port = swrm_connect_port; |
| 2066 | swrm->master.disconnect_port = swrm_disconnect_port; |
| 2067 | swrm->master.slvdev_datapath_control = swrm_slvdev_datapath_control; |
| 2068 | swrm->master.remove_from_group = swrm_remove_from_group; |
Sudheer Papothi | 6abd2de | 2018-09-05 05:57:04 +0530 | [diff] [blame] | 2069 | swrm->master.device_wakeup_vote = swrm_device_wakeup_vote; |
| 2070 | swrm->master.device_wakeup_unvote = swrm_device_wakeup_unvote; |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 2071 | swrm->master.dev.parent = &pdev->dev; |
| 2072 | swrm->master.dev.of_node = pdev->dev.of_node; |
| 2073 | swrm->master.num_port = 0; |
| 2074 | swrm->rcmd_id = 0; |
| 2075 | swrm->wcmd_id = 0; |
| 2076 | swrm->slave_status = 0; |
| 2077 | swrm->num_rx_chs = 0; |
| 2078 | swrm->clk_ref_count = 0; |
Vatsal Bucha | df38c3e | 2019-03-11 17:10:23 +0530 | [diff] [blame] | 2079 | swrm->swr_irq_wakeup_capable = 0; |
Laxminath Kasam | b0f27cd | 2018-09-06 12:17:11 +0530 | [diff] [blame] | 2080 | swrm->mclk_freq = MCLK_FREQ; |
Laxminath Kasam | 1df09a8 | 2018-09-20 18:57:49 +0530 | [diff] [blame] | 2081 | swrm->dev_up = true; |
Ramprasad Katkam | 2a799b4 | 2018-10-04 20:23:28 +0530 | [diff] [blame] | 2082 | swrm->state = SWR_MSTR_UP; |
Aditya Bavanari | c034fad | 2018-11-12 22:55:11 +0530 | [diff] [blame] | 2083 | swrm->ipc_wakeup = false; |
| 2084 | swrm->ipc_wakeup_triggered = false; |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 2085 | init_completion(&swrm->reset); |
| 2086 | init_completion(&swrm->broadcast); |
Ramprasad Katkam | 6bce2e7 | 2018-10-10 19:20:13 +0530 | [diff] [blame] | 2087 | init_completion(&swrm->clk_off_complete); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 2088 | mutex_init(&swrm->mlock); |
| 2089 | mutex_init(&swrm->reslock); |
| 2090 | mutex_init(&swrm->force_down_lock); |
Ramprasad Katkam | 1f22126 | 2018-08-23 15:01:22 +0530 | [diff] [blame] | 2091 | mutex_init(&swrm->iolock); |
Ramprasad Katkam | 6bce2e7 | 2018-10-10 19:20:13 +0530 | [diff] [blame] | 2092 | mutex_init(&swrm->clklock); |
Laxminath Kasam | 1df09a8 | 2018-09-20 18:57:49 +0530 | [diff] [blame] | 2093 | mutex_init(&swrm->devlock); |
Ramprasad Katkam | 5734987 | 2018-11-11 18:34:57 +0530 | [diff] [blame] | 2094 | mutex_init(&swrm->pm_lock); |
| 2095 | swrm->wlock_holders = 0; |
| 2096 | swrm->pm_state = SWRM_PM_SLEEPABLE; |
| 2097 | init_waitqueue_head(&swrm->pm_wq); |
| 2098 | pm_qos_add_request(&swrm->pm_qos_req, |
| 2099 | PM_QOS_CPU_DMA_LATENCY, |
| 2100 | PM_QOS_DEFAULT_VALUE); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 2101 | |
| 2102 | for (i = 0 ; i < SWR_MSTR_PORT_LEN; i++) |
| 2103 | INIT_LIST_HEAD(&swrm->mport_cfg[i].port_req_list); |
| 2104 | |
| 2105 | if (swrm->reg_irq) { |
| 2106 | ret = swrm->reg_irq(swrm->handle, swr_mstr_interrupt, swrm, |
| 2107 | SWR_IRQ_REGISTER); |
| 2108 | if (ret) { |
| 2109 | dev_err(&pdev->dev, "%s: IRQ register failed ret %d\n", |
| 2110 | __func__, ret); |
| 2111 | goto err_irq_fail; |
| 2112 | } |
| 2113 | } else { |
| 2114 | swrm->irq = platform_get_irq_byname(pdev, "swr_master_irq"); |
| 2115 | if (swrm->irq < 0) { |
| 2116 | dev_err(swrm->dev, "%s() error getting irq hdle: %d\n", |
| 2117 | __func__, swrm->irq); |
Laxminath Kasam | fbcaf32 | 2018-07-18 00:38:14 +0530 | [diff] [blame] | 2118 | goto err_irq_fail; |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 2119 | } |
| 2120 | |
| 2121 | ret = request_threaded_irq(swrm->irq, NULL, |
Sudheer Papothi | d19d0c5 | 2019-02-23 05:41:39 +0530 | [diff] [blame] | 2122 | swr_mstr_interrupt_v2, |
Ramprasad Katkam | 8330351 | 2018-10-11 17:34:22 +0530 | [diff] [blame] | 2123 | IRQF_TRIGGER_RISING | IRQF_ONESHOT, |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 2124 | "swr_master_irq", swrm); |
| 2125 | if (ret) { |
| 2126 | dev_err(swrm->dev, "%s: Failed to request irq %d\n", |
| 2127 | __func__, ret); |
| 2128 | goto err_irq_fail; |
| 2129 | } |
| 2130 | |
| 2131 | } |
Vatsal Bucha | df38c3e | 2019-03-11 17:10:23 +0530 | [diff] [blame] | 2132 | /* Make inband tx interrupts as wakeup capable for slave irq */ |
| 2133 | ret = of_property_read_u32(pdev->dev.of_node, |
| 2134 | "qcom,swr-mstr-irq-wakeup-capable", |
| 2135 | &swrm->swr_irq_wakeup_capable); |
| 2136 | if (ret) |
| 2137 | dev_dbg(swrm->dev, "%s: swrm irq wakeup capable not defined\n", |
| 2138 | __func__); |
| 2139 | if (swrm->swr_irq_wakeup_capable) |
| 2140 | irq_set_irq_wake(swrm->irq, 1); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 2141 | ret = swr_register_master(&swrm->master); |
| 2142 | if (ret) { |
| 2143 | dev_err(&pdev->dev, "%s: error adding swr master\n", __func__); |
| 2144 | goto err_mstr_fail; |
| 2145 | } |
| 2146 | |
| 2147 | /* Add devices registered with board-info as the |
| 2148 | * controller will be up now |
| 2149 | */ |
| 2150 | swr_master_add_boarddevices(&swrm->master); |
| 2151 | mutex_lock(&swrm->mlock); |
| 2152 | swrm_clk_request(swrm, true); |
| 2153 | ret = swrm_master_init(swrm); |
| 2154 | if (ret < 0) { |
| 2155 | dev_err(&pdev->dev, |
| 2156 | "%s: Error in master Initialization , err %d\n", |
| 2157 | __func__, ret); |
| 2158 | mutex_unlock(&swrm->mlock); |
| 2159 | goto err_mstr_fail; |
| 2160 | } |
| 2161 | swrm->version = swr_master_read(swrm, SWRM_COMP_HW_VERSION); |
| 2162 | |
| 2163 | mutex_unlock(&swrm->mlock); |
Laxminath Kasam | f0128ef | 2018-08-31 15:15:09 +0530 | [diff] [blame] | 2164 | INIT_WORK(&swrm->wakeup_work, swrm_wakeup_work); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 2165 | |
| 2166 | if (pdev->dev.of_node) |
| 2167 | of_register_swr_devices(&swrm->master); |
| 2168 | |
Sudheer Papothi | 66d6fd1 | 2019-03-27 17:34:48 +0530 | [diff] [blame] | 2169 | /* Register LPASS core hw vote */ |
| 2170 | lpass_core_hw_vote = devm_clk_get(&pdev->dev, "lpass_core_hw_vote"); |
| 2171 | if (IS_ERR(lpass_core_hw_vote)) { |
| 2172 | ret = PTR_ERR(lpass_core_hw_vote); |
| 2173 | dev_dbg(&pdev->dev, "%s: clk get %s failed %d\n", |
| 2174 | __func__, "lpass_core_hw_vote", ret); |
| 2175 | lpass_core_hw_vote = NULL; |
| 2176 | ret = 0; |
| 2177 | } |
| 2178 | swrm->lpass_core_hw_vote = lpass_core_hw_vote; |
| 2179 | |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 2180 | dbgswrm = swrm; |
| 2181 | debugfs_swrm_dent = debugfs_create_dir(dev_name(&pdev->dev), 0); |
| 2182 | if (!IS_ERR(debugfs_swrm_dent)) { |
| 2183 | debugfs_peek = debugfs_create_file("swrm_peek", |
| 2184 | S_IFREG | 0444, debugfs_swrm_dent, |
| 2185 | (void *) "swrm_peek", &swrm_debug_ops); |
| 2186 | |
| 2187 | debugfs_poke = debugfs_create_file("swrm_poke", |
| 2188 | S_IFREG | 0444, debugfs_swrm_dent, |
| 2189 | (void *) "swrm_poke", &swrm_debug_ops); |
| 2190 | |
| 2191 | debugfs_reg_dump = debugfs_create_file("swrm_reg_dump", |
| 2192 | S_IFREG | 0444, debugfs_swrm_dent, |
| 2193 | (void *) "swrm_reg_dump", |
| 2194 | &swrm_debug_ops); |
| 2195 | } |
Vatsal Bucha | df38c3e | 2019-03-11 17:10:23 +0530 | [diff] [blame] | 2196 | |
| 2197 | ret = device_init_wakeup(swrm->dev, true); |
| 2198 | if (ret) { |
| 2199 | dev_err(swrm->dev, "Device wakeup init failed: %d\n", ret); |
| 2200 | goto err_irq_wakeup_fail; |
| 2201 | } |
| 2202 | |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 2203 | pm_runtime_set_autosuspend_delay(&pdev->dev, auto_suspend_timer); |
| 2204 | pm_runtime_use_autosuspend(&pdev->dev); |
| 2205 | pm_runtime_set_active(&pdev->dev); |
| 2206 | pm_runtime_enable(&pdev->dev); |
| 2207 | pm_runtime_mark_last_busy(&pdev->dev); |
| 2208 | |
Ramprasad Katkam | 68765ab | 2018-08-30 11:46:32 +0530 | [diff] [blame] | 2209 | INIT_WORK(&swrm->dc_presence_work, swrm_notify_work_fn); |
| 2210 | swrm->event_notifier.notifier_call = swrm_event_notify; |
| 2211 | msm_aud_evt_register_client(&swrm->event_notifier); |
| 2212 | |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 2213 | return 0; |
Vatsal Bucha | df38c3e | 2019-03-11 17:10:23 +0530 | [diff] [blame] | 2214 | err_irq_wakeup_fail: |
| 2215 | device_init_wakeup(swrm->dev, false); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 2216 | err_mstr_fail: |
| 2217 | if (swrm->reg_irq) |
| 2218 | swrm->reg_irq(swrm->handle, swr_mstr_interrupt, |
| 2219 | swrm, SWR_IRQ_FREE); |
| 2220 | else if (swrm->irq) |
| 2221 | free_irq(swrm->irq, swrm); |
| 2222 | err_irq_fail: |
| 2223 | mutex_destroy(&swrm->mlock); |
| 2224 | mutex_destroy(&swrm->reslock); |
| 2225 | mutex_destroy(&swrm->force_down_lock); |
Ramprasad Katkam | 1f22126 | 2018-08-23 15:01:22 +0530 | [diff] [blame] | 2226 | mutex_destroy(&swrm->iolock); |
Ramprasad Katkam | 6bce2e7 | 2018-10-10 19:20:13 +0530 | [diff] [blame] | 2227 | mutex_destroy(&swrm->clklock); |
Ramprasad Katkam | 5734987 | 2018-11-11 18:34:57 +0530 | [diff] [blame] | 2228 | mutex_destroy(&swrm->pm_lock); |
| 2229 | pm_qos_remove_request(&swrm->pm_qos_req); |
| 2230 | |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 2231 | err_pdata_fail: |
| 2232 | err_memory_fail: |
| 2233 | return ret; |
| 2234 | } |
| 2235 | |
| 2236 | static int swrm_remove(struct platform_device *pdev) |
| 2237 | { |
| 2238 | struct swr_mstr_ctrl *swrm = platform_get_drvdata(pdev); |
| 2239 | |
| 2240 | if (swrm->reg_irq) |
| 2241 | swrm->reg_irq(swrm->handle, swr_mstr_interrupt, |
| 2242 | swrm, SWR_IRQ_FREE); |
| 2243 | else if (swrm->irq) |
| 2244 | free_irq(swrm->irq, swrm); |
Aditya Bavanari | c034fad | 2018-11-12 22:55:11 +0530 | [diff] [blame] | 2245 | else if (swrm->wake_irq > 0) |
| 2246 | free_irq(swrm->wake_irq, swrm); |
Vatsal Bucha | df38c3e | 2019-03-11 17:10:23 +0530 | [diff] [blame] | 2247 | if (swrm->swr_irq_wakeup_capable) |
| 2248 | irq_set_irq_wake(swrm->irq, 0); |
Ramprasad Katkam | 5734987 | 2018-11-11 18:34:57 +0530 | [diff] [blame] | 2249 | cancel_work_sync(&swrm->wakeup_work); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 2250 | pm_runtime_disable(&pdev->dev); |
| 2251 | pm_runtime_set_suspended(&pdev->dev); |
| 2252 | swr_unregister_master(&swrm->master); |
Ramprasad Katkam | 68765ab | 2018-08-30 11:46:32 +0530 | [diff] [blame] | 2253 | msm_aud_evt_unregister_client(&swrm->event_notifier); |
Vatsal Bucha | df38c3e | 2019-03-11 17:10:23 +0530 | [diff] [blame] | 2254 | device_init_wakeup(swrm->dev, false); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 2255 | mutex_destroy(&swrm->mlock); |
| 2256 | mutex_destroy(&swrm->reslock); |
Ramprasad Katkam | 6bce2e7 | 2018-10-10 19:20:13 +0530 | [diff] [blame] | 2257 | mutex_destroy(&swrm->iolock); |
| 2258 | mutex_destroy(&swrm->clklock); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 2259 | mutex_destroy(&swrm->force_down_lock); |
Ramprasad Katkam | 5734987 | 2018-11-11 18:34:57 +0530 | [diff] [blame] | 2260 | mutex_destroy(&swrm->pm_lock); |
| 2261 | pm_qos_remove_request(&swrm->pm_qos_req); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 2262 | devm_kfree(&pdev->dev, swrm); |
| 2263 | return 0; |
| 2264 | } |
| 2265 | |
| 2266 | static int swrm_clk_pause(struct swr_mstr_ctrl *swrm) |
| 2267 | { |
| 2268 | u32 val; |
| 2269 | |
| 2270 | dev_dbg(swrm->dev, "%s: state: %d\n", __func__, swrm->state); |
| 2271 | swr_master_write(swrm, SWRM_INTERRUPT_MASK_ADDR, 0x1FDFD); |
| 2272 | val = swr_master_read(swrm, SWRM_MCP_CFG_ADDR); |
| 2273 | val |= SWRM_MCP_CFG_BUS_CLK_PAUSE_BMSK; |
| 2274 | swr_master_write(swrm, SWRM_MCP_CFG_ADDR, val); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 2275 | |
| 2276 | return 0; |
| 2277 | } |
| 2278 | |
| 2279 | #ifdef CONFIG_PM |
| 2280 | static int swrm_runtime_resume(struct device *dev) |
| 2281 | { |
| 2282 | struct platform_device *pdev = to_platform_device(dev); |
| 2283 | struct swr_mstr_ctrl *swrm = platform_get_drvdata(pdev); |
| 2284 | int ret = 0; |
| 2285 | struct swr_master *mstr = &swrm->master; |
| 2286 | struct swr_device *swr_dev; |
| 2287 | |
| 2288 | dev_dbg(dev, "%s: pm_runtime: resume, state:%d\n", |
| 2289 | __func__, swrm->state); |
| 2290 | mutex_lock(&swrm->reslock); |
Ramprasad Katkam | 2a799b4 | 2018-10-04 20:23:28 +0530 | [diff] [blame] | 2291 | |
Karthikeyan Mani | f682190 | 2019-05-21 17:31:24 -0700 | [diff] [blame^] | 2292 | if (swrm->lpass_core_hw_vote) { |
Sudheer Papothi | 66d6fd1 | 2019-03-27 17:34:48 +0530 | [diff] [blame] | 2293 | ret = clk_prepare_enable(swrm->lpass_core_hw_vote); |
Karthikeyan Mani | f682190 | 2019-05-21 17:31:24 -0700 | [diff] [blame^] | 2294 | if (ret < 0) { |
Sudheer Papothi | 66d6fd1 | 2019-03-27 17:34:48 +0530 | [diff] [blame] | 2295 | dev_err(dev, "%s:lpass core hw enable failed\n", |
| 2296 | __func__); |
Karthikeyan Mani | f682190 | 2019-05-21 17:31:24 -0700 | [diff] [blame^] | 2297 | ret = 0; |
| 2298 | } |
| 2299 | } |
Sudheer Papothi | 66d6fd1 | 2019-03-27 17:34:48 +0530 | [diff] [blame] | 2300 | |
Ramprasad Katkam | 2a799b4 | 2018-10-04 20:23:28 +0530 | [diff] [blame] | 2301 | if ((swrm->state == SWR_MSTR_DOWN) || |
| 2302 | (swrm->state == SWR_MSTR_SSR && swrm->dev_up)) { |
Aditya Bavanari | c034fad | 2018-11-12 22:55:11 +0530 | [diff] [blame] | 2303 | if (swrm->clk_stop_mode0_supp) { |
| 2304 | if (swrm->ipc_wakeup) |
| 2305 | msm_aud_evt_blocking_notifier_call_chain( |
| 2306 | SWR_WAKE_IRQ_DEREGISTER, (void *)swrm); |
Laxminath Kasam | f0128ef | 2018-08-31 15:15:09 +0530 | [diff] [blame] | 2307 | } |
| 2308 | |
Ramprasad Katkam | 2a799b4 | 2018-10-04 20:23:28 +0530 | [diff] [blame] | 2309 | if (swrm_clk_request(swrm, true)) |
| 2310 | goto exit; |
| 2311 | if (!swrm->clk_stop_mode0_supp || swrm->state == SWR_MSTR_SSR) { |
Ramprasad Katkam | 14f47cc | 2018-07-25 17:20:18 +0530 | [diff] [blame] | 2312 | list_for_each_entry(swr_dev, &mstr->devices, dev_list) { |
| 2313 | ret = swr_device_up(swr_dev); |
Sudheer Papothi | 79c9075 | 2019-04-23 06:09:52 +0530 | [diff] [blame] | 2314 | if (ret == -ENODEV) { |
| 2315 | dev_dbg(dev, |
| 2316 | "%s slave device up not implemented\n", |
| 2317 | __func__); |
| 2318 | ret = 0; |
| 2319 | } else if (ret) { |
Ramprasad Katkam | 14f47cc | 2018-07-25 17:20:18 +0530 | [diff] [blame] | 2320 | dev_err(dev, |
| 2321 | "%s: failed to wakeup swr dev %d\n", |
| 2322 | __func__, swr_dev->dev_num); |
| 2323 | swrm_clk_request(swrm, false); |
| 2324 | goto exit; |
| 2325 | } |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 2326 | } |
Ramprasad Katkam | 48b49b2 | 2018-10-01 20:12:46 +0530 | [diff] [blame] | 2327 | swr_master_write(swrm, SWRM_COMP_SW_RESET, 0x01); |
| 2328 | swr_master_write(swrm, SWRM_COMP_SW_RESET, 0x01); |
| 2329 | swrm_master_init(swrm); |
Ramprasad Katkam | 2a799b4 | 2018-10-04 20:23:28 +0530 | [diff] [blame] | 2330 | swrm_cmd_fifo_wr_cmd(swrm, 0x4, 0xF, 0x0, |
| 2331 | SWRS_SCP_INT_STATUS_MASK_1); |
Karthikeyan Mani | f682190 | 2019-05-21 17:31:24 -0700 | [diff] [blame^] | 2332 | if (swrm->state == SWR_MSTR_SSR) { |
| 2333 | mutex_unlock(&swrm->reslock); |
| 2334 | enable_bank_switch(swrm, 0, SWR_ROW_50, SWR_MIN_COL); |
| 2335 | mutex_lock(&swrm->reslock); |
| 2336 | } |
Ramprasad Katkam | 14f47cc | 2018-07-25 17:20:18 +0530 | [diff] [blame] | 2337 | } else { |
| 2338 | /*wake up from clock stop*/ |
| 2339 | swr_master_write(swrm, SWRM_MCP_BUS_CTRL_ADDR, 0x2); |
| 2340 | usleep_range(100, 105); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 2341 | } |
Ramprasad Katkam | 2a799b4 | 2018-10-04 20:23:28 +0530 | [diff] [blame] | 2342 | swrm->state = SWR_MSTR_UP; |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 2343 | } |
| 2344 | exit: |
Sudheer Papothi | 66d6fd1 | 2019-03-27 17:34:48 +0530 | [diff] [blame] | 2345 | if (swrm->lpass_core_hw_vote) |
| 2346 | clk_disable_unprepare(swrm->lpass_core_hw_vote); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 2347 | pm_runtime_set_autosuspend_delay(&pdev->dev, auto_suspend_timer); |
| 2348 | mutex_unlock(&swrm->reslock); |
| 2349 | return ret; |
| 2350 | } |
| 2351 | |
| 2352 | static int swrm_runtime_suspend(struct device *dev) |
| 2353 | { |
| 2354 | struct platform_device *pdev = to_platform_device(dev); |
| 2355 | struct swr_mstr_ctrl *swrm = platform_get_drvdata(pdev); |
| 2356 | int ret = 0; |
| 2357 | struct swr_master *mstr = &swrm->master; |
| 2358 | struct swr_device *swr_dev; |
| 2359 | int current_state = 0; |
| 2360 | |
| 2361 | dev_dbg(dev, "%s: pm_runtime: suspend state: %d\n", |
| 2362 | __func__, swrm->state); |
| 2363 | mutex_lock(&swrm->reslock); |
| 2364 | mutex_lock(&swrm->force_down_lock); |
| 2365 | current_state = swrm->state; |
| 2366 | mutex_unlock(&swrm->force_down_lock); |
Karthikeyan Mani | f682190 | 2019-05-21 17:31:24 -0700 | [diff] [blame^] | 2367 | if (swrm->lpass_core_hw_vote) { |
Sudheer Papothi | 66d6fd1 | 2019-03-27 17:34:48 +0530 | [diff] [blame] | 2368 | ret = clk_prepare_enable(swrm->lpass_core_hw_vote); |
Karthikeyan Mani | f682190 | 2019-05-21 17:31:24 -0700 | [diff] [blame^] | 2369 | if (ret < 0) { |
Sudheer Papothi | 66d6fd1 | 2019-03-27 17:34:48 +0530 | [diff] [blame] | 2370 | dev_err(dev, "%s:lpass core hw enable failed\n", |
| 2371 | __func__); |
Karthikeyan Mani | f682190 | 2019-05-21 17:31:24 -0700 | [diff] [blame^] | 2372 | ret = 0; |
| 2373 | } |
| 2374 | } |
Sudheer Papothi | 66d6fd1 | 2019-03-27 17:34:48 +0530 | [diff] [blame] | 2375 | |
Ramprasad Katkam | 2a799b4 | 2018-10-04 20:23:28 +0530 | [diff] [blame] | 2376 | if ((current_state == SWR_MSTR_UP) || |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 2377 | (current_state == SWR_MSTR_SSR)) { |
| 2378 | |
| 2379 | if ((current_state != SWR_MSTR_SSR) && |
| 2380 | swrm_is_port_en(&swrm->master)) { |
| 2381 | dev_dbg(dev, "%s ports are enabled\n", __func__); |
| 2382 | ret = -EBUSY; |
| 2383 | goto exit; |
| 2384 | } |
Ramprasad Katkam | 2a799b4 | 2018-10-04 20:23:28 +0530 | [diff] [blame] | 2385 | if (!swrm->clk_stop_mode0_supp || swrm->state == SWR_MSTR_SSR) { |
Ramprasad Katkam | b4c7c68 | 2018-12-19 18:58:36 +0530 | [diff] [blame] | 2386 | enable_bank_switch(swrm, 0, SWR_ROW_50, SWR_MIN_COL); |
Ramprasad Katkam | 14f47cc | 2018-07-25 17:20:18 +0530 | [diff] [blame] | 2387 | swrm_clk_pause(swrm); |
| 2388 | swr_master_write(swrm, SWRM_COMP_CFG_ADDR, 0x00); |
| 2389 | list_for_each_entry(swr_dev, &mstr->devices, dev_list) { |
| 2390 | ret = swr_device_down(swr_dev); |
Sudheer Papothi | 79c9075 | 2019-04-23 06:09:52 +0530 | [diff] [blame] | 2391 | if (ret == -ENODEV) { |
| 2392 | dev_dbg_ratelimited(dev, |
| 2393 | "%s slave device down not implemented\n", |
| 2394 | __func__); |
| 2395 | ret = 0; |
| 2396 | } else if (ret) { |
Ramprasad Katkam | 14f47cc | 2018-07-25 17:20:18 +0530 | [diff] [blame] | 2397 | dev_err(dev, |
| 2398 | "%s: failed to shutdown swr dev %d\n", |
| 2399 | __func__, swr_dev->dev_num); |
| 2400 | goto exit; |
| 2401 | } |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 2402 | } |
Ramprasad Katkam | 14f47cc | 2018-07-25 17:20:18 +0530 | [diff] [blame] | 2403 | } else { |
| 2404 | /* clock stop sequence */ |
| 2405 | swrm_cmd_fifo_wr_cmd(swrm, 0x2, 0xF, 0xF, |
| 2406 | SWRS_SCP_CONTROL); |
| 2407 | usleep_range(100, 105); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 2408 | } |
| 2409 | swrm_clk_request(swrm, false); |
Ramprasad Katkam | 6a3050d | 2018-10-10 02:08:00 +0530 | [diff] [blame] | 2410 | |
Aditya Bavanari | c034fad | 2018-11-12 22:55:11 +0530 | [diff] [blame] | 2411 | if (swrm->clk_stop_mode0_supp) { |
| 2412 | if (swrm->wake_irq > 0) { |
| 2413 | enable_irq(swrm->wake_irq); |
| 2414 | } else if (swrm->ipc_wakeup) { |
| 2415 | msm_aud_evt_blocking_notifier_call_chain( |
| 2416 | SWR_WAKE_IRQ_REGISTER, (void *)swrm); |
| 2417 | swrm->ipc_wakeup_triggered = false; |
| 2418 | } |
Ramprasad Katkam | 6a3050d | 2018-10-10 02:08:00 +0530 | [diff] [blame] | 2419 | } |
| 2420 | |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 2421 | } |
Ramprasad Katkam | 2a799b4 | 2018-10-04 20:23:28 +0530 | [diff] [blame] | 2422 | /* Retain SSR state until resume */ |
| 2423 | if (current_state != SWR_MSTR_SSR) |
| 2424 | swrm->state = SWR_MSTR_DOWN; |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 2425 | exit: |
Sudheer Papothi | 66d6fd1 | 2019-03-27 17:34:48 +0530 | [diff] [blame] | 2426 | if (swrm->lpass_core_hw_vote) |
| 2427 | clk_disable_unprepare(swrm->lpass_core_hw_vote); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 2428 | mutex_unlock(&swrm->reslock); |
| 2429 | return ret; |
| 2430 | } |
| 2431 | #endif /* CONFIG_PM */ |
| 2432 | |
| 2433 | static int swrm_device_down(struct device *dev) |
| 2434 | { |
| 2435 | struct platform_device *pdev = to_platform_device(dev); |
| 2436 | struct swr_mstr_ctrl *swrm = platform_get_drvdata(pdev); |
| 2437 | int ret = 0; |
| 2438 | |
| 2439 | dev_dbg(dev, "%s: swrm state: %d\n", __func__, swrm->state); |
| 2440 | |
| 2441 | mutex_lock(&swrm->force_down_lock); |
| 2442 | swrm->state = SWR_MSTR_SSR; |
| 2443 | mutex_unlock(&swrm->force_down_lock); |
Laxminath Kasam | 1df09a8 | 2018-09-20 18:57:49 +0530 | [diff] [blame] | 2444 | if (!pm_runtime_enabled(dev) || !pm_runtime_suspended(dev)) { |
| 2445 | ret = swrm_runtime_suspend(dev); |
| 2446 | if (!ret) { |
| 2447 | pm_runtime_disable(dev); |
| 2448 | pm_runtime_set_suspended(dev); |
| 2449 | pm_runtime_enable(dev); |
| 2450 | } |
| 2451 | } |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 2452 | |
Laxminath Kasam | 1df09a8 | 2018-09-20 18:57:49 +0530 | [diff] [blame] | 2453 | return 0; |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 2454 | } |
| 2455 | |
Aditya Bavanari | c034fad | 2018-11-12 22:55:11 +0530 | [diff] [blame] | 2456 | int swrm_register_wake_irq(struct swr_mstr_ctrl *swrm) |
| 2457 | { |
| 2458 | int ret = 0; |
Laxminath Kasam | a60239e | 2019-01-10 14:43:03 +0530 | [diff] [blame] | 2459 | int irq, dir_apps_irq; |
Aditya Bavanari | c034fad | 2018-11-12 22:55:11 +0530 | [diff] [blame] | 2460 | |
| 2461 | if (!swrm->ipc_wakeup) { |
Laxminath Kasam | a60239e | 2019-01-10 14:43:03 +0530 | [diff] [blame] | 2462 | irq = of_get_named_gpio(swrm->dev->of_node, |
| 2463 | "qcom,swr-wakeup-irq", 0); |
| 2464 | if (gpio_is_valid(irq)) { |
| 2465 | swrm->wake_irq = gpio_to_irq(irq); |
| 2466 | if (swrm->wake_irq < 0) { |
| 2467 | dev_err(swrm->dev, |
| 2468 | "Unable to configure irq\n"); |
| 2469 | return swrm->wake_irq; |
| 2470 | } |
| 2471 | } else { |
| 2472 | dir_apps_irq = platform_get_irq_byname(swrm->pdev, |
| 2473 | "swr_wake_irq"); |
| 2474 | if (dir_apps_irq < 0) { |
| 2475 | dev_err(swrm->dev, |
| 2476 | "TLMM connect gpio not found\n"); |
| 2477 | return -EINVAL; |
| 2478 | } |
| 2479 | swrm->wake_irq = dir_apps_irq; |
Aditya Bavanari | c034fad | 2018-11-12 22:55:11 +0530 | [diff] [blame] | 2480 | } |
Aditya Bavanari | c034fad | 2018-11-12 22:55:11 +0530 | [diff] [blame] | 2481 | ret = request_threaded_irq(swrm->wake_irq, NULL, |
| 2482 | swrm_wakeup_interrupt, |
| 2483 | IRQF_TRIGGER_HIGH | IRQF_ONESHOT, |
| 2484 | "swr_wake_irq", swrm); |
| 2485 | if (ret) { |
| 2486 | dev_err(swrm->dev, "%s: Failed to request irq %d\n", |
| 2487 | __func__, ret); |
| 2488 | return -EINVAL; |
| 2489 | } |
Aditya Bavanari | 3517b11 | 2018-12-03 13:26:59 +0530 | [diff] [blame] | 2490 | irq_set_irq_wake(swrm->wake_irq, 1); |
Aditya Bavanari | c034fad | 2018-11-12 22:55:11 +0530 | [diff] [blame] | 2491 | } |
| 2492 | return ret; |
| 2493 | } |
| 2494 | |
Sudheer Papothi | 3d1596e | 2018-10-27 06:19:18 +0530 | [diff] [blame] | 2495 | static int swrm_alloc_port_mem(struct device *dev, struct swr_mstr_ctrl *swrm, |
| 2496 | u32 uc, u32 size) |
| 2497 | { |
| 2498 | if (!swrm->port_param) { |
| 2499 | swrm->port_param = devm_kzalloc(dev, |
| 2500 | sizeof(swrm->port_param) * SWR_UC_MAX, |
| 2501 | GFP_KERNEL); |
| 2502 | if (!swrm->port_param) |
| 2503 | return -ENOMEM; |
| 2504 | } |
| 2505 | if (!swrm->port_param[uc]) { |
| 2506 | swrm->port_param[uc] = devm_kcalloc(dev, size, |
| 2507 | sizeof(struct port_params), |
| 2508 | GFP_KERNEL); |
| 2509 | if (!swrm->port_param[uc]) |
| 2510 | return -ENOMEM; |
| 2511 | } else { |
| 2512 | dev_err_ratelimited(swrm->dev, "%s: called more than once\n", |
| 2513 | __func__); |
| 2514 | } |
| 2515 | |
| 2516 | return 0; |
| 2517 | } |
| 2518 | |
| 2519 | static int swrm_copy_port_config(struct swr_mstr_ctrl *swrm, |
| 2520 | struct swrm_port_config *port_cfg, |
| 2521 | u32 size) |
| 2522 | { |
| 2523 | int idx; |
| 2524 | struct port_params *params; |
| 2525 | int uc = port_cfg->uc; |
| 2526 | int ret = 0; |
| 2527 | |
| 2528 | for (idx = 0; idx < size; idx++) { |
| 2529 | params = &((struct port_params *)port_cfg->params)[idx]; |
| 2530 | if (!params) { |
| 2531 | dev_err(swrm->dev, "%s: Invalid params\n", __func__); |
| 2532 | ret = -EINVAL; |
| 2533 | break; |
| 2534 | } |
| 2535 | memcpy(&swrm->port_param[uc][idx], params, |
| 2536 | sizeof(struct port_params)); |
| 2537 | } |
| 2538 | |
| 2539 | return ret; |
| 2540 | } |
| 2541 | |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 2542 | /** |
| 2543 | * swrm_wcd_notify - parent device can notify to soundwire master through |
| 2544 | * this function |
| 2545 | * @pdev: pointer to platform device structure |
| 2546 | * @id: command id from parent to the soundwire master |
| 2547 | * @data: data from parent device to soundwire master |
| 2548 | */ |
| 2549 | int swrm_wcd_notify(struct platform_device *pdev, u32 id, void *data) |
| 2550 | { |
| 2551 | struct swr_mstr_ctrl *swrm; |
| 2552 | int ret = 0; |
| 2553 | struct swr_master *mstr; |
| 2554 | struct swr_device *swr_dev; |
Sudheer Papothi | 3d1596e | 2018-10-27 06:19:18 +0530 | [diff] [blame] | 2555 | struct swrm_port_config *port_cfg; |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 2556 | |
| 2557 | if (!pdev) { |
| 2558 | pr_err("%s: pdev is NULL\n", __func__); |
| 2559 | return -EINVAL; |
| 2560 | } |
| 2561 | swrm = platform_get_drvdata(pdev); |
| 2562 | if (!swrm) { |
| 2563 | dev_err(&pdev->dev, "%s: swrm is NULL\n", __func__); |
| 2564 | return -EINVAL; |
| 2565 | } |
| 2566 | mstr = &swrm->master; |
| 2567 | |
| 2568 | switch (id) { |
Laxminath Kasam | b0f27cd | 2018-09-06 12:17:11 +0530 | [diff] [blame] | 2569 | case SWR_CLK_FREQ: |
| 2570 | if (!data) { |
| 2571 | dev_err(swrm->dev, "%s: data is NULL\n", __func__); |
| 2572 | ret = -EINVAL; |
| 2573 | } else { |
| 2574 | mutex_lock(&swrm->mlock); |
| 2575 | swrm->mclk_freq = *(int *)data; |
| 2576 | mutex_unlock(&swrm->mlock); |
| 2577 | } |
| 2578 | break; |
Laxminath Kasam | 1df09a8 | 2018-09-20 18:57:49 +0530 | [diff] [blame] | 2579 | case SWR_DEVICE_SSR_DOWN: |
| 2580 | mutex_lock(&swrm->devlock); |
| 2581 | swrm->dev_up = false; |
| 2582 | mutex_unlock(&swrm->devlock); |
Ramprasad Katkam | 2a799b4 | 2018-10-04 20:23:28 +0530 | [diff] [blame] | 2583 | mutex_lock(&swrm->reslock); |
| 2584 | swrm->state = SWR_MSTR_SSR; |
| 2585 | mutex_unlock(&swrm->reslock); |
Laxminath Kasam | 1df09a8 | 2018-09-20 18:57:49 +0530 | [diff] [blame] | 2586 | break; |
| 2587 | case SWR_DEVICE_SSR_UP: |
Ramprasad Katkam | 6bce2e7 | 2018-10-10 19:20:13 +0530 | [diff] [blame] | 2588 | /* wait for clk voting to be zero */ |
Ramprasad Katkam | 7f6462e | 2018-11-06 11:51:22 +0530 | [diff] [blame] | 2589 | reinit_completion(&swrm->clk_off_complete); |
Ramprasad Katkam | 6bce2e7 | 2018-10-10 19:20:13 +0530 | [diff] [blame] | 2590 | if (swrm->clk_ref_count && |
| 2591 | !wait_for_completion_timeout(&swrm->clk_off_complete, |
Ramprasad Katkam | c87efeb | 2018-12-12 19:26:19 +0530 | [diff] [blame] | 2592 | msecs_to_jiffies(500))) |
Ramprasad Katkam | 6bce2e7 | 2018-10-10 19:20:13 +0530 | [diff] [blame] | 2593 | dev_err(swrm->dev, "%s: clock voting not zero\n", |
| 2594 | __func__); |
| 2595 | |
Laxminath Kasam | 1df09a8 | 2018-09-20 18:57:49 +0530 | [diff] [blame] | 2596 | mutex_lock(&swrm->devlock); |
| 2597 | swrm->dev_up = true; |
| 2598 | mutex_unlock(&swrm->devlock); |
| 2599 | break; |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 2600 | case SWR_DEVICE_DOWN: |
| 2601 | dev_dbg(swrm->dev, "%s: swr master down called\n", __func__); |
| 2602 | mutex_lock(&swrm->mlock); |
Ramprasad Katkam | 2a799b4 | 2018-10-04 20:23:28 +0530 | [diff] [blame] | 2603 | if (swrm->state == SWR_MSTR_DOWN) |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 2604 | dev_dbg(swrm->dev, "%s:SWR master is already Down:%d\n", |
| 2605 | __func__, swrm->state); |
| 2606 | else |
| 2607 | swrm_device_down(&pdev->dev); |
| 2608 | mutex_unlock(&swrm->mlock); |
| 2609 | break; |
| 2610 | case SWR_DEVICE_UP: |
| 2611 | dev_dbg(swrm->dev, "%s: swr master up called\n", __func__); |
Ramprasad Katkam | 0fed92f | 2018-11-08 14:22:22 +0530 | [diff] [blame] | 2612 | mutex_lock(&swrm->devlock); |
| 2613 | if (!swrm->dev_up) { |
| 2614 | dev_dbg(swrm->dev, "SSR not complete yet\n"); |
| 2615 | mutex_unlock(&swrm->devlock); |
| 2616 | return -EBUSY; |
| 2617 | } |
| 2618 | mutex_unlock(&swrm->devlock); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 2619 | mutex_lock(&swrm->mlock); |
Ramprasad Katkam | 86c45e0 | 2018-10-16 19:31:51 +0530 | [diff] [blame] | 2620 | pm_runtime_mark_last_busy(&pdev->dev); |
| 2621 | pm_runtime_get_sync(&pdev->dev); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 2622 | mutex_lock(&swrm->reslock); |
Ramprasad Katkam | 86c45e0 | 2018-10-16 19:31:51 +0530 | [diff] [blame] | 2623 | list_for_each_entry(swr_dev, &mstr->devices, dev_list) { |
| 2624 | ret = swr_reset_device(swr_dev); |
| 2625 | if (ret) { |
| 2626 | dev_err(swrm->dev, |
| 2627 | "%s: failed to reset swr device %d\n", |
| 2628 | __func__, swr_dev->dev_num); |
| 2629 | swrm_clk_request(swrm, false); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 2630 | } |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 2631 | } |
Ramprasad Katkam | 86c45e0 | 2018-10-16 19:31:51 +0530 | [diff] [blame] | 2632 | pm_runtime_mark_last_busy(&pdev->dev); |
| 2633 | pm_runtime_put_autosuspend(&pdev->dev); |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 2634 | mutex_unlock(&swrm->reslock); |
| 2635 | mutex_unlock(&swrm->mlock); |
| 2636 | break; |
| 2637 | case SWR_SET_NUM_RX_CH: |
| 2638 | if (!data) { |
| 2639 | dev_err(swrm->dev, "%s: data is NULL\n", __func__); |
| 2640 | ret = -EINVAL; |
| 2641 | } else { |
| 2642 | mutex_lock(&swrm->mlock); |
| 2643 | swrm->num_rx_chs = *(int *)data; |
| 2644 | if ((swrm->num_rx_chs > 1) && !swrm->num_cfg_devs) { |
| 2645 | list_for_each_entry(swr_dev, &mstr->devices, |
| 2646 | dev_list) { |
| 2647 | ret = swr_set_device_group(swr_dev, |
| 2648 | SWR_BROADCAST); |
| 2649 | if (ret) |
| 2650 | dev_err(swrm->dev, |
| 2651 | "%s: set num ch failed\n", |
| 2652 | __func__); |
| 2653 | } |
| 2654 | } else { |
| 2655 | list_for_each_entry(swr_dev, &mstr->devices, |
| 2656 | dev_list) { |
| 2657 | ret = swr_set_device_group(swr_dev, |
| 2658 | SWR_GROUP_NONE); |
| 2659 | if (ret) |
| 2660 | dev_err(swrm->dev, |
| 2661 | "%s: set num ch failed\n", |
| 2662 | __func__); |
| 2663 | } |
| 2664 | } |
| 2665 | mutex_unlock(&swrm->mlock); |
| 2666 | } |
| 2667 | break; |
Aditya Bavanari | c034fad | 2018-11-12 22:55:11 +0530 | [diff] [blame] | 2668 | case SWR_REGISTER_WAKE_IRQ: |
| 2669 | if (!data) { |
| 2670 | dev_err(swrm->dev, "%s: reg wake irq data is NULL\n", |
| 2671 | __func__); |
| 2672 | ret = -EINVAL; |
| 2673 | } else { |
| 2674 | mutex_lock(&swrm->mlock); |
| 2675 | swrm->ipc_wakeup = *(u32 *)data; |
| 2676 | ret = swrm_register_wake_irq(swrm); |
| 2677 | if (ret) |
| 2678 | dev_err(swrm->dev, "%s: register wake_irq failed\n", |
| 2679 | __func__); |
| 2680 | mutex_unlock(&swrm->mlock); |
| 2681 | } |
| 2682 | break; |
Sudheer Papothi | 3d1596e | 2018-10-27 06:19:18 +0530 | [diff] [blame] | 2683 | case SWR_SET_PORT_MAP: |
| 2684 | if (!data) { |
| 2685 | dev_err(swrm->dev, "%s: data is NULL for id=%d\n", |
| 2686 | __func__, id); |
| 2687 | ret = -EINVAL; |
| 2688 | } else { |
| 2689 | mutex_lock(&swrm->mlock); |
| 2690 | port_cfg = (struct swrm_port_config *)data; |
| 2691 | if (!port_cfg->size) { |
| 2692 | ret = -EINVAL; |
| 2693 | goto done; |
| 2694 | } |
| 2695 | ret = swrm_alloc_port_mem(&pdev->dev, swrm, |
| 2696 | port_cfg->uc, port_cfg->size); |
| 2697 | if (!ret) |
| 2698 | swrm_copy_port_config(swrm, port_cfg, |
| 2699 | port_cfg->size); |
| 2700 | done: |
| 2701 | mutex_unlock(&swrm->mlock); |
| 2702 | } |
| 2703 | break; |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 2704 | default: |
| 2705 | dev_err(swrm->dev, "%s: swr master unknown id %d\n", |
| 2706 | __func__, id); |
| 2707 | break; |
| 2708 | } |
| 2709 | return ret; |
| 2710 | } |
| 2711 | EXPORT_SYMBOL(swrm_wcd_notify); |
| 2712 | |
Ramprasad Katkam | 5734987 | 2018-11-11 18:34:57 +0530 | [diff] [blame] | 2713 | /* |
| 2714 | * swrm_pm_cmpxchg: |
| 2715 | * Check old state and exchange with pm new state |
| 2716 | * if old state matches with current state |
| 2717 | * |
| 2718 | * @swrm: pointer to wcd core resource |
| 2719 | * @o: pm old state |
| 2720 | * @n: pm new state |
| 2721 | * |
| 2722 | * Returns old state |
| 2723 | */ |
| 2724 | static enum swrm_pm_state swrm_pm_cmpxchg( |
| 2725 | struct swr_mstr_ctrl *swrm, |
| 2726 | enum swrm_pm_state o, |
| 2727 | enum swrm_pm_state n) |
| 2728 | { |
| 2729 | enum swrm_pm_state old; |
| 2730 | |
| 2731 | if (!swrm) |
| 2732 | return o; |
| 2733 | |
| 2734 | mutex_lock(&swrm->pm_lock); |
| 2735 | old = swrm->pm_state; |
| 2736 | if (old == o) |
| 2737 | swrm->pm_state = n; |
| 2738 | mutex_unlock(&swrm->pm_lock); |
| 2739 | |
| 2740 | return old; |
| 2741 | } |
| 2742 | |
| 2743 | static bool swrm_lock_sleep(struct swr_mstr_ctrl *swrm) |
| 2744 | { |
| 2745 | enum swrm_pm_state os; |
| 2746 | |
| 2747 | /* |
| 2748 | * swrm_{lock/unlock}_sleep will be called by swr irq handler |
| 2749 | * and slave wake up requests.. |
| 2750 | * |
| 2751 | * If system didn't resume, we can simply return false so |
| 2752 | * IRQ handler can return without handling IRQ. |
| 2753 | */ |
| 2754 | mutex_lock(&swrm->pm_lock); |
| 2755 | if (swrm->wlock_holders++ == 0) { |
| 2756 | dev_dbg(swrm->dev, "%s: holding wake lock\n", __func__); |
| 2757 | pm_qos_update_request(&swrm->pm_qos_req, |
| 2758 | msm_cpuidle_get_deep_idle_latency()); |
| 2759 | pm_stay_awake(swrm->dev); |
| 2760 | } |
| 2761 | mutex_unlock(&swrm->pm_lock); |
| 2762 | |
| 2763 | if (!wait_event_timeout(swrm->pm_wq, |
| 2764 | ((os = swrm_pm_cmpxchg(swrm, |
| 2765 | SWRM_PM_SLEEPABLE, |
| 2766 | SWRM_PM_AWAKE)) == |
| 2767 | SWRM_PM_SLEEPABLE || |
| 2768 | (os == SWRM_PM_AWAKE)), |
| 2769 | msecs_to_jiffies( |
| 2770 | SWRM_SYSTEM_RESUME_TIMEOUT_MS))) { |
| 2771 | dev_err(swrm->dev, "%s: system didn't resume within %dms, s %d, w %d\n", |
| 2772 | __func__, SWRM_SYSTEM_RESUME_TIMEOUT_MS, swrm->pm_state, |
| 2773 | swrm->wlock_holders); |
| 2774 | swrm_unlock_sleep(swrm); |
| 2775 | return false; |
| 2776 | } |
| 2777 | wake_up_all(&swrm->pm_wq); |
| 2778 | return true; |
| 2779 | } |
| 2780 | |
| 2781 | static void swrm_unlock_sleep(struct swr_mstr_ctrl *swrm) |
| 2782 | { |
| 2783 | mutex_lock(&swrm->pm_lock); |
| 2784 | if (--swrm->wlock_holders == 0) { |
| 2785 | dev_dbg(swrm->dev, "%s: releasing wake lock pm_state %d -> %d\n", |
| 2786 | __func__, swrm->pm_state, SWRM_PM_SLEEPABLE); |
| 2787 | /* |
| 2788 | * if swrm_lock_sleep failed, pm_state would be still |
| 2789 | * swrm_PM_ASLEEP, don't overwrite |
| 2790 | */ |
| 2791 | if (likely(swrm->pm_state == SWRM_PM_AWAKE)) |
| 2792 | swrm->pm_state = SWRM_PM_SLEEPABLE; |
| 2793 | pm_qos_update_request(&swrm->pm_qos_req, |
| 2794 | PM_QOS_DEFAULT_VALUE); |
| 2795 | pm_relax(swrm->dev); |
| 2796 | } |
| 2797 | mutex_unlock(&swrm->pm_lock); |
| 2798 | wake_up_all(&swrm->pm_wq); |
| 2799 | } |
| 2800 | |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 2801 | #ifdef CONFIG_PM_SLEEP |
| 2802 | static int swrm_suspend(struct device *dev) |
| 2803 | { |
| 2804 | int ret = -EBUSY; |
| 2805 | struct platform_device *pdev = to_platform_device(dev); |
| 2806 | struct swr_mstr_ctrl *swrm = platform_get_drvdata(pdev); |
| 2807 | |
| 2808 | dev_dbg(dev, "%s: system suspend, state: %d\n", __func__, swrm->state); |
Ramprasad Katkam | 5734987 | 2018-11-11 18:34:57 +0530 | [diff] [blame] | 2809 | |
| 2810 | mutex_lock(&swrm->pm_lock); |
| 2811 | |
| 2812 | if (swrm->pm_state == SWRM_PM_SLEEPABLE) { |
| 2813 | dev_dbg(swrm->dev, "%s: suspending system, state %d, wlock %d\n", |
| 2814 | __func__, swrm->pm_state, |
| 2815 | swrm->wlock_holders); |
| 2816 | swrm->pm_state = SWRM_PM_ASLEEP; |
| 2817 | } else if (swrm->pm_state == SWRM_PM_AWAKE) { |
| 2818 | /* |
| 2819 | * unlock to wait for pm_state == SWRM_PM_SLEEPABLE |
| 2820 | * then set to SWRM_PM_ASLEEP |
| 2821 | */ |
| 2822 | dev_dbg(swrm->dev, "%s: waiting to suspend system, state %d, wlock %d\n", |
| 2823 | __func__, swrm->pm_state, |
| 2824 | swrm->wlock_holders); |
| 2825 | mutex_unlock(&swrm->pm_lock); |
| 2826 | if (!(wait_event_timeout(swrm->pm_wq, swrm_pm_cmpxchg( |
| 2827 | swrm, SWRM_PM_SLEEPABLE, |
| 2828 | SWRM_PM_ASLEEP) == |
| 2829 | SWRM_PM_SLEEPABLE, |
| 2830 | msecs_to_jiffies( |
| 2831 | SWRM_SYS_SUSPEND_WAIT)))) { |
| 2832 | dev_dbg(swrm->dev, "%s: suspend failed state %d, wlock %d\n", |
| 2833 | __func__, swrm->pm_state, |
| 2834 | swrm->wlock_holders); |
| 2835 | return -EBUSY; |
| 2836 | } else { |
| 2837 | dev_dbg(swrm->dev, |
| 2838 | "%s: done, state %d, wlock %d\n", |
| 2839 | __func__, swrm->pm_state, |
| 2840 | swrm->wlock_holders); |
| 2841 | } |
| 2842 | mutex_lock(&swrm->pm_lock); |
| 2843 | } else if (swrm->pm_state == SWRM_PM_ASLEEP) { |
| 2844 | dev_dbg(swrm->dev, "%s: system is already suspended, state %d, wlock %d\n", |
| 2845 | __func__, swrm->pm_state, |
| 2846 | swrm->wlock_holders); |
| 2847 | } |
| 2848 | |
| 2849 | mutex_unlock(&swrm->pm_lock); |
| 2850 | |
| 2851 | if ((!pm_runtime_enabled(dev) || !pm_runtime_suspended(dev))) { |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 2852 | ret = swrm_runtime_suspend(dev); |
| 2853 | if (!ret) { |
| 2854 | /* |
| 2855 | * Synchronize runtime-pm and system-pm states: |
| 2856 | * At this point, we are already suspended. If |
| 2857 | * runtime-pm still thinks its active, then |
| 2858 | * make sure its status is in sync with HW |
| 2859 | * status. The three below calls let the |
| 2860 | * runtime-pm know that we are suspended |
| 2861 | * already without re-invoking the suspend |
| 2862 | * callback |
| 2863 | */ |
| 2864 | pm_runtime_disable(dev); |
| 2865 | pm_runtime_set_suspended(dev); |
| 2866 | pm_runtime_enable(dev); |
| 2867 | } |
| 2868 | } |
| 2869 | if (ret == -EBUSY) { |
| 2870 | /* |
| 2871 | * There is a possibility that some audio stream is active |
| 2872 | * during suspend. We dont want to return suspend failure in |
| 2873 | * that case so that display and relevant components can still |
| 2874 | * go to suspend. |
| 2875 | * If there is some other error, then it should be passed-on |
| 2876 | * to system level suspend |
| 2877 | */ |
| 2878 | ret = 0; |
| 2879 | } |
| 2880 | return ret; |
| 2881 | } |
| 2882 | |
| 2883 | static int swrm_resume(struct device *dev) |
| 2884 | { |
| 2885 | int ret = 0; |
| 2886 | struct platform_device *pdev = to_platform_device(dev); |
| 2887 | struct swr_mstr_ctrl *swrm = platform_get_drvdata(pdev); |
| 2888 | |
| 2889 | dev_dbg(dev, "%s: system resume, state: %d\n", __func__, swrm->state); |
| 2890 | if (!pm_runtime_enabled(dev) || !pm_runtime_suspend(dev)) { |
| 2891 | ret = swrm_runtime_resume(dev); |
| 2892 | if (!ret) { |
| 2893 | pm_runtime_mark_last_busy(dev); |
| 2894 | pm_request_autosuspend(dev); |
| 2895 | } |
| 2896 | } |
Ramprasad Katkam | 5734987 | 2018-11-11 18:34:57 +0530 | [diff] [blame] | 2897 | mutex_lock(&swrm->pm_lock); |
| 2898 | if (swrm->pm_state == SWRM_PM_ASLEEP) { |
| 2899 | dev_dbg(swrm->dev, |
| 2900 | "%s: resuming system, state %d, wlock %d\n", |
| 2901 | __func__, swrm->pm_state, |
| 2902 | swrm->wlock_holders); |
| 2903 | swrm->pm_state = SWRM_PM_SLEEPABLE; |
| 2904 | } else { |
| 2905 | dev_dbg(swrm->dev, "%s: system is already awake, state %d wlock %d\n", |
| 2906 | __func__, swrm->pm_state, |
| 2907 | swrm->wlock_holders); |
| 2908 | } |
| 2909 | mutex_unlock(&swrm->pm_lock); |
| 2910 | wake_up_all(&swrm->pm_wq); |
| 2911 | |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 2912 | return ret; |
| 2913 | } |
| 2914 | #endif /* CONFIG_PM_SLEEP */ |
| 2915 | |
| 2916 | static const struct dev_pm_ops swrm_dev_pm_ops = { |
| 2917 | SET_SYSTEM_SLEEP_PM_OPS( |
| 2918 | swrm_suspend, |
| 2919 | swrm_resume |
| 2920 | ) |
| 2921 | SET_RUNTIME_PM_OPS( |
| 2922 | swrm_runtime_suspend, |
| 2923 | swrm_runtime_resume, |
| 2924 | NULL |
| 2925 | ) |
| 2926 | }; |
| 2927 | |
| 2928 | static const struct of_device_id swrm_dt_match[] = { |
| 2929 | { |
| 2930 | .compatible = "qcom,swr-mstr", |
| 2931 | }, |
| 2932 | {} |
| 2933 | }; |
| 2934 | |
| 2935 | static struct platform_driver swr_mstr_driver = { |
| 2936 | .probe = swrm_probe, |
| 2937 | .remove = swrm_remove, |
| 2938 | .driver = { |
| 2939 | .name = SWR_WCD_NAME, |
| 2940 | .owner = THIS_MODULE, |
| 2941 | .pm = &swrm_dev_pm_ops, |
| 2942 | .of_match_table = swrm_dt_match, |
Xiaojun Sang | 53cd13a | 2018-06-29 15:14:37 +0800 | [diff] [blame] | 2943 | .suppress_bind_attrs = true, |
Ramprasad Katkam | 9f040f3 | 2018-05-16 10:19:25 +0530 | [diff] [blame] | 2944 | }, |
| 2945 | }; |
| 2946 | |
| 2947 | static int __init swrm_init(void) |
| 2948 | { |
| 2949 | return platform_driver_register(&swr_mstr_driver); |
| 2950 | } |
| 2951 | module_init(swrm_init); |
| 2952 | |
| 2953 | static void __exit swrm_exit(void) |
| 2954 | { |
| 2955 | platform_driver_unregister(&swr_mstr_driver); |
| 2956 | } |
| 2957 | module_exit(swrm_exit); |
| 2958 | |
| 2959 | MODULE_LICENSE("GPL v2"); |
| 2960 | MODULE_DESCRIPTION("SoundWire Master Controller"); |
| 2961 | MODULE_ALIAS("platform:swr-mstr"); |