Thomas Gleixner | 1802d0b | 2019-05-27 08:55:21 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 2 | /* |
Bjorn Andersson | ef73c22 | 2018-09-24 16:45:26 -0700 | [diff] [blame] | 3 | * Qualcomm self-authenticating modem subsystem remoteproc driver |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 4 | * |
| 5 | * Copyright (C) 2016 Linaro Ltd. |
| 6 | * Copyright (C) 2014 Sony Mobile Communications AB |
| 7 | * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <linux/clk.h> |
| 11 | #include <linux/delay.h> |
| 12 | #include <linux/dma-mapping.h> |
| 13 | #include <linux/interrupt.h> |
| 14 | #include <linux/kernel.h> |
| 15 | #include <linux/mfd/syscon.h> |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/of_address.h> |
Avaneesh Kumar Dwivedi | 7a8ffe1 | 2016-12-30 19:24:00 +0530 | [diff] [blame] | 18 | #include <linux/of_device.h> |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 19 | #include <linux/platform_device.h> |
Rajendra Nayak | 4760a89 | 2019-01-30 16:39:30 -0800 | [diff] [blame] | 20 | #include <linux/pm_domain.h> |
| 21 | #include <linux/pm_runtime.h> |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 22 | #include <linux/regmap.h> |
| 23 | #include <linux/regulator/consumer.h> |
| 24 | #include <linux/remoteproc.h> |
| 25 | #include <linux/reset.h> |
Bjorn Andersson | 2aad40d | 2017-01-27 03:12:57 -0800 | [diff] [blame] | 26 | #include <linux/soc/qcom/mdt_loader.h> |
Avaneesh Kumar Dwivedi | 9f058fa | 2017-10-24 21:22:27 +0530 | [diff] [blame] | 27 | #include <linux/iopoll.h> |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 28 | |
| 29 | #include "remoteproc_internal.h" |
Bjorn Andersson | bde440e | 2017-01-27 02:28:32 -0800 | [diff] [blame] | 30 | #include "qcom_common.h" |
Bjorn Andersson | 7d67473 | 2018-06-04 13:30:38 -0700 | [diff] [blame] | 31 | #include "qcom_q6v5.h" |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 32 | |
| 33 | #include <linux/qcom_scm.h> |
| 34 | |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 35 | #define MPSS_CRASH_REASON_SMEM 421 |
| 36 | |
| 37 | /* RMB Status Register Values */ |
| 38 | #define RMB_PBL_SUCCESS 0x1 |
| 39 | |
| 40 | #define RMB_MBA_XPU_UNLOCKED 0x1 |
| 41 | #define RMB_MBA_XPU_UNLOCKED_SCRIBBLED 0x2 |
| 42 | #define RMB_MBA_META_DATA_AUTH_SUCCESS 0x3 |
| 43 | #define RMB_MBA_AUTH_COMPLETE 0x4 |
| 44 | |
| 45 | /* PBL/MBA interface registers */ |
| 46 | #define RMB_MBA_IMAGE_REG 0x00 |
| 47 | #define RMB_PBL_STATUS_REG 0x04 |
| 48 | #define RMB_MBA_COMMAND_REG 0x08 |
| 49 | #define RMB_MBA_STATUS_REG 0x0C |
| 50 | #define RMB_PMI_META_DATA_REG 0x10 |
| 51 | #define RMB_PMI_CODE_START_REG 0x14 |
| 52 | #define RMB_PMI_CODE_LENGTH_REG 0x18 |
Sibi Sankar | 231f67d | 2018-05-21 22:57:13 +0530 | [diff] [blame] | 53 | #define RMB_MBA_MSS_STATUS 0x40 |
| 54 | #define RMB_MBA_ALT_RESET 0x44 |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 55 | |
| 56 | #define RMB_CMD_META_DATA_READY 0x1 |
| 57 | #define RMB_CMD_LOAD_READY 0x2 |
| 58 | |
| 59 | /* QDSP6SS Register Offsets */ |
| 60 | #define QDSP6SS_RESET_REG 0x014 |
| 61 | #define QDSP6SS_GFMUX_CTL_REG 0x020 |
| 62 | #define QDSP6SS_PWR_CTL_REG 0x030 |
Avaneesh Kumar Dwivedi | 9f058fa | 2017-10-24 21:22:27 +0530 | [diff] [blame] | 63 | #define QDSP6SS_MEM_PWR_CTL 0x0B0 |
| 64 | #define QDSP6SS_STRAP_ACC 0x110 |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 65 | |
| 66 | /* AXI Halt Register Offsets */ |
| 67 | #define AXI_HALTREQ_REG 0x0 |
| 68 | #define AXI_HALTACK_REG 0x4 |
| 69 | #define AXI_IDLE_REG 0x8 |
| 70 | |
| 71 | #define HALT_ACK_TIMEOUT_MS 100 |
| 72 | |
| 73 | /* QDSP6SS_RESET */ |
| 74 | #define Q6SS_STOP_CORE BIT(0) |
| 75 | #define Q6SS_CORE_ARES BIT(1) |
| 76 | #define Q6SS_BUS_ARES_ENABLE BIT(2) |
| 77 | |
| 78 | /* QDSP6SS_GFMUX_CTL */ |
| 79 | #define Q6SS_CLK_ENABLE BIT(1) |
| 80 | |
| 81 | /* QDSP6SS_PWR_CTL */ |
| 82 | #define Q6SS_L2DATA_SLP_NRET_N_0 BIT(0) |
| 83 | #define Q6SS_L2DATA_SLP_NRET_N_1 BIT(1) |
| 84 | #define Q6SS_L2DATA_SLP_NRET_N_2 BIT(2) |
| 85 | #define Q6SS_L2TAG_SLP_NRET_N BIT(16) |
| 86 | #define Q6SS_ETB_SLP_NRET_N BIT(17) |
| 87 | #define Q6SS_L2DATA_STBY_N BIT(18) |
| 88 | #define Q6SS_SLP_RET_N BIT(19) |
| 89 | #define Q6SS_CLAMP_IO BIT(20) |
| 90 | #define QDSS_BHS_ON BIT(21) |
| 91 | #define QDSS_LDO_BYP BIT(22) |
| 92 | |
Avaneesh Kumar Dwivedi | 9f058fa | 2017-10-24 21:22:27 +0530 | [diff] [blame] | 93 | /* QDSP6v56 parameters */ |
| 94 | #define QDSP6v56_LDO_BYP BIT(25) |
| 95 | #define QDSP6v56_BHS_ON BIT(24) |
| 96 | #define QDSP6v56_CLAMP_WL BIT(21) |
| 97 | #define QDSP6v56_CLAMP_QMC_MEM BIT(22) |
| 98 | #define HALT_CHECK_MAX_LOOPS 200 |
| 99 | #define QDSP6SS_XO_CBCR 0x0038 |
| 100 | #define QDSP6SS_ACC_OVERRIDE_VAL 0x20 |
| 101 | |
Sibi Sankar | 231f67d | 2018-05-21 22:57:13 +0530 | [diff] [blame] | 102 | /* QDSP6v65 parameters */ |
| 103 | #define QDSP6SS_SLEEP 0x3C |
| 104 | #define QDSP6SS_BOOT_CORE_START 0x400 |
| 105 | #define QDSP6SS_BOOT_CMD 0x404 |
| 106 | #define SLEEP_CHECK_MAX_LOOPS 200 |
| 107 | #define BOOT_FSM_TIMEOUT 10000 |
| 108 | |
Avaneesh Kumar Dwivedi | 19f902b | 2016-12-30 19:24:02 +0530 | [diff] [blame] | 109 | struct reg_info { |
| 110 | struct regulator *reg; |
| 111 | int uV; |
| 112 | int uA; |
| 113 | }; |
| 114 | |
| 115 | struct qcom_mss_reg_res { |
| 116 | const char *supply; |
| 117 | int uV; |
| 118 | int uA; |
| 119 | }; |
| 120 | |
Avaneesh Kumar Dwivedi | 7a8ffe1 | 2016-12-30 19:24:00 +0530 | [diff] [blame] | 121 | struct rproc_hexagon_res { |
| 122 | const char *hexagon_mba_image; |
Arnd Bergmann | ec671b5 | 2017-02-01 17:56:28 +0100 | [diff] [blame] | 123 | struct qcom_mss_reg_res *proxy_supply; |
| 124 | struct qcom_mss_reg_res *active_supply; |
Avaneesh Kumar Dwivedi | 39b2410 | 2016-12-30 19:24:01 +0530 | [diff] [blame] | 125 | char **proxy_clk_names; |
Sibi Sankar | 231f67d | 2018-05-21 22:57:13 +0530 | [diff] [blame] | 126 | char **reset_clk_names; |
Avaneesh Kumar Dwivedi | 39b2410 | 2016-12-30 19:24:01 +0530 | [diff] [blame] | 127 | char **active_clk_names; |
Bjorn Andersson | deb9bb8 | 2019-01-30 16:39:31 -0800 | [diff] [blame] | 128 | char **active_pd_names; |
Rajendra Nayak | 4760a89 | 2019-01-30 16:39:30 -0800 | [diff] [blame] | 129 | char **proxy_pd_names; |
Avaneesh Kumar Dwivedi | 9f058fa | 2017-10-24 21:22:27 +0530 | [diff] [blame] | 130 | int version; |
Avaneesh Kumar Dwivedi | 6c5a9dc | 2017-10-24 21:22:26 +0530 | [diff] [blame] | 131 | bool need_mem_protection; |
Sibi Sankar | 231f67d | 2018-05-21 22:57:13 +0530 | [diff] [blame] | 132 | bool has_alt_reset; |
Avaneesh Kumar Dwivedi | 7a8ffe1 | 2016-12-30 19:24:00 +0530 | [diff] [blame] | 133 | }; |
| 134 | |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 135 | struct q6v5 { |
| 136 | struct device *dev; |
| 137 | struct rproc *rproc; |
| 138 | |
| 139 | void __iomem *reg_base; |
| 140 | void __iomem *rmb_base; |
| 141 | |
| 142 | struct regmap *halt_map; |
| 143 | u32 halt_q6; |
| 144 | u32 halt_modem; |
| 145 | u32 halt_nc; |
| 146 | |
| 147 | struct reset_control *mss_restart; |
Sibi Sankar | 29a5f9a | 2018-08-30 00:42:15 +0530 | [diff] [blame] | 148 | struct reset_control *pdc_reset; |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 149 | |
Bjorn Andersson | 7d67473 | 2018-06-04 13:30:38 -0700 | [diff] [blame] | 150 | struct qcom_q6v5 q6v5; |
Sibi Sankar | 663e984 | 2018-05-21 22:57:09 +0530 | [diff] [blame] | 151 | |
Avaneesh Kumar Dwivedi | 39b2410 | 2016-12-30 19:24:01 +0530 | [diff] [blame] | 152 | struct clk *active_clks[8]; |
Sibi Sankar | 231f67d | 2018-05-21 22:57:13 +0530 | [diff] [blame] | 153 | struct clk *reset_clks[4]; |
Avaneesh Kumar Dwivedi | 39b2410 | 2016-12-30 19:24:01 +0530 | [diff] [blame] | 154 | struct clk *proxy_clks[4]; |
Bjorn Andersson | deb9bb8 | 2019-01-30 16:39:31 -0800 | [diff] [blame] | 155 | struct device *active_pds[1]; |
Rajendra Nayak | 4760a89 | 2019-01-30 16:39:30 -0800 | [diff] [blame] | 156 | struct device *proxy_pds[3]; |
Avaneesh Kumar Dwivedi | 39b2410 | 2016-12-30 19:24:01 +0530 | [diff] [blame] | 157 | int active_clk_count; |
Sibi Sankar | 231f67d | 2018-05-21 22:57:13 +0530 | [diff] [blame] | 158 | int reset_clk_count; |
Avaneesh Kumar Dwivedi | 39b2410 | 2016-12-30 19:24:01 +0530 | [diff] [blame] | 159 | int proxy_clk_count; |
Bjorn Andersson | deb9bb8 | 2019-01-30 16:39:31 -0800 | [diff] [blame] | 160 | int active_pd_count; |
Rajendra Nayak | 4760a89 | 2019-01-30 16:39:30 -0800 | [diff] [blame] | 161 | int proxy_pd_count; |
Avaneesh Kumar Dwivedi | 39b2410 | 2016-12-30 19:24:01 +0530 | [diff] [blame] | 162 | |
Avaneesh Kumar Dwivedi | 19f902b | 2016-12-30 19:24:02 +0530 | [diff] [blame] | 163 | struct reg_info active_regs[1]; |
| 164 | struct reg_info proxy_regs[3]; |
| 165 | int active_reg_count; |
| 166 | int proxy_reg_count; |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 167 | |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 168 | bool running; |
| 169 | |
Sibi Sankar | 0304530 | 2018-10-17 19:25:25 +0530 | [diff] [blame] | 170 | bool dump_mba_loaded; |
Sibi Sankar | 7dd8ade2 | 2018-10-17 19:25:26 +0530 | [diff] [blame] | 171 | unsigned long dump_segment_mask; |
| 172 | unsigned long dump_complete_mask; |
| 173 | |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 174 | phys_addr_t mba_phys; |
| 175 | void *mba_region; |
| 176 | size_t mba_size; |
| 177 | |
| 178 | phys_addr_t mpss_phys; |
| 179 | phys_addr_t mpss_reloc; |
| 180 | void *mpss_region; |
| 181 | size_t mpss_size; |
Bjorn Andersson | 4b48921 | 2017-01-29 14:05:50 -0800 | [diff] [blame] | 182 | |
Sibi Sankar | 4725496 | 2018-05-21 22:57:14 +0530 | [diff] [blame] | 183 | struct qcom_rproc_glink glink_subdev; |
Bjorn Andersson | 4b48921 | 2017-01-29 14:05:50 -0800 | [diff] [blame] | 184 | struct qcom_rproc_subdev smd_subdev; |
Bjorn Andersson | 1e140df | 2017-07-24 22:56:43 -0700 | [diff] [blame] | 185 | struct qcom_rproc_ssr ssr_subdev; |
Bjorn Andersson | 1fb82ee | 2017-08-27 21:51:38 -0700 | [diff] [blame] | 186 | struct qcom_sysmon *sysmon; |
Avaneesh Kumar Dwivedi | 6c5a9dc | 2017-10-24 21:22:26 +0530 | [diff] [blame] | 187 | bool need_mem_protection; |
Sibi Sankar | 231f67d | 2018-05-21 22:57:13 +0530 | [diff] [blame] | 188 | bool has_alt_reset; |
Avaneesh Kumar Dwivedi | 6c5a9dc | 2017-10-24 21:22:26 +0530 | [diff] [blame] | 189 | int mpss_perm; |
| 190 | int mba_perm; |
Sibi Sankar | a5a4e02 | 2019-01-15 01:20:01 +0530 | [diff] [blame] | 191 | const char *hexagon_mdt_image; |
Avaneesh Kumar Dwivedi | 9f058fa | 2017-10-24 21:22:27 +0530 | [diff] [blame] | 192 | int version; |
| 193 | }; |
Avaneesh Kumar Dwivedi | 6c5a9dc | 2017-10-24 21:22:26 +0530 | [diff] [blame] | 194 | |
Avaneesh Kumar Dwivedi | 9f058fa | 2017-10-24 21:22:27 +0530 | [diff] [blame] | 195 | enum { |
| 196 | MSS_MSM8916, |
| 197 | MSS_MSM8974, |
| 198 | MSS_MSM8996, |
Sibi Sankar | 231f67d | 2018-05-21 22:57:13 +0530 | [diff] [blame] | 199 | MSS_SDM845, |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 200 | }; |
| 201 | |
Avaneesh Kumar Dwivedi | 19f902b | 2016-12-30 19:24:02 +0530 | [diff] [blame] | 202 | static int q6v5_regulator_init(struct device *dev, struct reg_info *regs, |
| 203 | const struct qcom_mss_reg_res *reg_res) |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 204 | { |
Avaneesh Kumar Dwivedi | 19f902b | 2016-12-30 19:24:02 +0530 | [diff] [blame] | 205 | int rc; |
| 206 | int i; |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 207 | |
Bjorn Andersson | 2bb5d90 | 2017-01-30 03:20:27 -0800 | [diff] [blame] | 208 | if (!reg_res) |
| 209 | return 0; |
| 210 | |
Avaneesh Kumar Dwivedi | 19f902b | 2016-12-30 19:24:02 +0530 | [diff] [blame] | 211 | for (i = 0; reg_res[i].supply; i++) { |
| 212 | regs[i].reg = devm_regulator_get(dev, reg_res[i].supply); |
| 213 | if (IS_ERR(regs[i].reg)) { |
| 214 | rc = PTR_ERR(regs[i].reg); |
| 215 | if (rc != -EPROBE_DEFER) |
| 216 | dev_err(dev, "Failed to get %s\n regulator", |
| 217 | reg_res[i].supply); |
| 218 | return rc; |
| 219 | } |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 220 | |
Avaneesh Kumar Dwivedi | 19f902b | 2016-12-30 19:24:02 +0530 | [diff] [blame] | 221 | regs[i].uV = reg_res[i].uV; |
| 222 | regs[i].uA = reg_res[i].uA; |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 223 | } |
| 224 | |
Avaneesh Kumar Dwivedi | 19f902b | 2016-12-30 19:24:02 +0530 | [diff] [blame] | 225 | return i; |
| 226 | } |
| 227 | |
| 228 | static int q6v5_regulator_enable(struct q6v5 *qproc, |
| 229 | struct reg_info *regs, int count) |
| 230 | { |
| 231 | int ret; |
| 232 | int i; |
| 233 | |
| 234 | for (i = 0; i < count; i++) { |
| 235 | if (regs[i].uV > 0) { |
| 236 | ret = regulator_set_voltage(regs[i].reg, |
| 237 | regs[i].uV, INT_MAX); |
| 238 | if (ret) { |
| 239 | dev_err(qproc->dev, |
| 240 | "Failed to request voltage for %d.\n", |
| 241 | i); |
| 242 | goto err; |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | if (regs[i].uA > 0) { |
| 247 | ret = regulator_set_load(regs[i].reg, |
| 248 | regs[i].uA); |
| 249 | if (ret < 0) { |
| 250 | dev_err(qproc->dev, |
| 251 | "Failed to set regulator mode\n"); |
| 252 | goto err; |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | ret = regulator_enable(regs[i].reg); |
| 257 | if (ret) { |
| 258 | dev_err(qproc->dev, "Regulator enable failed\n"); |
| 259 | goto err; |
| 260 | } |
| 261 | } |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 262 | |
| 263 | return 0; |
Avaneesh Kumar Dwivedi | 19f902b | 2016-12-30 19:24:02 +0530 | [diff] [blame] | 264 | err: |
| 265 | for (; i >= 0; i--) { |
| 266 | if (regs[i].uV > 0) |
| 267 | regulator_set_voltage(regs[i].reg, 0, INT_MAX); |
| 268 | |
| 269 | if (regs[i].uA > 0) |
| 270 | regulator_set_load(regs[i].reg, 0); |
| 271 | |
| 272 | regulator_disable(regs[i].reg); |
| 273 | } |
| 274 | |
| 275 | return ret; |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 276 | } |
| 277 | |
Avaneesh Kumar Dwivedi | 19f902b | 2016-12-30 19:24:02 +0530 | [diff] [blame] | 278 | static void q6v5_regulator_disable(struct q6v5 *qproc, |
| 279 | struct reg_info *regs, int count) |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 280 | { |
Avaneesh Kumar Dwivedi | 19f902b | 2016-12-30 19:24:02 +0530 | [diff] [blame] | 281 | int i; |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 282 | |
Avaneesh Kumar Dwivedi | 19f902b | 2016-12-30 19:24:02 +0530 | [diff] [blame] | 283 | for (i = 0; i < count; i++) { |
| 284 | if (regs[i].uV > 0) |
| 285 | regulator_set_voltage(regs[i].reg, 0, INT_MAX); |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 286 | |
Avaneesh Kumar Dwivedi | 19f902b | 2016-12-30 19:24:02 +0530 | [diff] [blame] | 287 | if (regs[i].uA > 0) |
| 288 | regulator_set_load(regs[i].reg, 0); |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 289 | |
Avaneesh Kumar Dwivedi | 19f902b | 2016-12-30 19:24:02 +0530 | [diff] [blame] | 290 | regulator_disable(regs[i].reg); |
| 291 | } |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 292 | } |
| 293 | |
Avaneesh Kumar Dwivedi | 39b2410 | 2016-12-30 19:24:01 +0530 | [diff] [blame] | 294 | static int q6v5_clk_enable(struct device *dev, |
| 295 | struct clk **clks, int count) |
| 296 | { |
| 297 | int rc; |
| 298 | int i; |
| 299 | |
| 300 | for (i = 0; i < count; i++) { |
| 301 | rc = clk_prepare_enable(clks[i]); |
| 302 | if (rc) { |
| 303 | dev_err(dev, "Clock enable failed\n"); |
| 304 | goto err; |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | return 0; |
| 309 | err: |
| 310 | for (i--; i >= 0; i--) |
| 311 | clk_disable_unprepare(clks[i]); |
| 312 | |
| 313 | return rc; |
| 314 | } |
| 315 | |
| 316 | static void q6v5_clk_disable(struct device *dev, |
| 317 | struct clk **clks, int count) |
| 318 | { |
| 319 | int i; |
| 320 | |
| 321 | for (i = 0; i < count; i++) |
| 322 | clk_disable_unprepare(clks[i]); |
| 323 | } |
| 324 | |
Rajendra Nayak | 4760a89 | 2019-01-30 16:39:30 -0800 | [diff] [blame] | 325 | static int q6v5_pds_enable(struct q6v5 *qproc, struct device **pds, |
| 326 | size_t pd_count) |
| 327 | { |
| 328 | int ret; |
| 329 | int i; |
| 330 | |
| 331 | for (i = 0; i < pd_count; i++) { |
| 332 | dev_pm_genpd_set_performance_state(pds[i], INT_MAX); |
| 333 | ret = pm_runtime_get_sync(pds[i]); |
| 334 | if (ret < 0) |
| 335 | goto unroll_pd_votes; |
| 336 | } |
| 337 | |
| 338 | return 0; |
| 339 | |
| 340 | unroll_pd_votes: |
| 341 | for (i--; i >= 0; i--) { |
| 342 | dev_pm_genpd_set_performance_state(pds[i], 0); |
| 343 | pm_runtime_put(pds[i]); |
| 344 | } |
| 345 | |
| 346 | return ret; |
| 347 | }; |
| 348 | |
| 349 | static void q6v5_pds_disable(struct q6v5 *qproc, struct device **pds, |
| 350 | size_t pd_count) |
| 351 | { |
| 352 | int i; |
| 353 | |
| 354 | for (i = 0; i < pd_count; i++) { |
| 355 | dev_pm_genpd_set_performance_state(pds[i], 0); |
| 356 | pm_runtime_put(pds[i]); |
| 357 | } |
| 358 | } |
| 359 | |
Avaneesh Kumar Dwivedi | 6c5a9dc | 2017-10-24 21:22:26 +0530 | [diff] [blame] | 360 | static int q6v5_xfer_mem_ownership(struct q6v5 *qproc, int *current_perm, |
| 361 | bool remote_owner, phys_addr_t addr, |
| 362 | size_t size) |
| 363 | { |
| 364 | struct qcom_scm_vmperm next; |
Avaneesh Kumar Dwivedi | 6c5a9dc | 2017-10-24 21:22:26 +0530 | [diff] [blame] | 365 | |
| 366 | if (!qproc->need_mem_protection) |
| 367 | return 0; |
| 368 | if (remote_owner && *current_perm == BIT(QCOM_SCM_VMID_MSS_MSA)) |
| 369 | return 0; |
| 370 | if (!remote_owner && *current_perm == BIT(QCOM_SCM_VMID_HLOS)) |
| 371 | return 0; |
| 372 | |
| 373 | next.vmid = remote_owner ? QCOM_SCM_VMID_MSS_MSA : QCOM_SCM_VMID_HLOS; |
| 374 | next.perm = remote_owner ? QCOM_SCM_PERM_RW : QCOM_SCM_PERM_RWX; |
| 375 | |
Bjorn Andersson | 9f2a434 | 2017-11-06 22:26:41 -0800 | [diff] [blame] | 376 | return qcom_scm_assign_mem(addr, ALIGN(size, SZ_4K), |
| 377 | current_perm, &next, 1); |
Avaneesh Kumar Dwivedi | 6c5a9dc | 2017-10-24 21:22:26 +0530 | [diff] [blame] | 378 | } |
| 379 | |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 380 | static int q6v5_load(struct rproc *rproc, const struct firmware *fw) |
| 381 | { |
| 382 | struct q6v5 *qproc = rproc->priv; |
| 383 | |
| 384 | memcpy(qproc->mba_region, fw->data, fw->size); |
| 385 | |
| 386 | return 0; |
| 387 | } |
| 388 | |
Sibi Sankar | 9f135fa | 2018-05-21 22:57:12 +0530 | [diff] [blame] | 389 | static int q6v5_reset_assert(struct q6v5 *qproc) |
| 390 | { |
Sibi Sankar | 29a5f9a | 2018-08-30 00:42:15 +0530 | [diff] [blame] | 391 | int ret; |
| 392 | |
| 393 | if (qproc->has_alt_reset) { |
| 394 | reset_control_assert(qproc->pdc_reset); |
| 395 | ret = reset_control_reset(qproc->mss_restart); |
| 396 | reset_control_deassert(qproc->pdc_reset); |
| 397 | } else { |
| 398 | ret = reset_control_assert(qproc->mss_restart); |
| 399 | } |
| 400 | |
| 401 | return ret; |
Sibi Sankar | 9f135fa | 2018-05-21 22:57:12 +0530 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | static int q6v5_reset_deassert(struct q6v5 *qproc) |
| 405 | { |
Sibi Sankar | 231f67d | 2018-05-21 22:57:13 +0530 | [diff] [blame] | 406 | int ret; |
| 407 | |
| 408 | if (qproc->has_alt_reset) { |
Sibi Sankar | 29a5f9a | 2018-08-30 00:42:15 +0530 | [diff] [blame] | 409 | reset_control_assert(qproc->pdc_reset); |
Sibi Sankar | 231f67d | 2018-05-21 22:57:13 +0530 | [diff] [blame] | 410 | writel(1, qproc->rmb_base + RMB_MBA_ALT_RESET); |
| 411 | ret = reset_control_reset(qproc->mss_restart); |
| 412 | writel(0, qproc->rmb_base + RMB_MBA_ALT_RESET); |
Sibi Sankar | 29a5f9a | 2018-08-30 00:42:15 +0530 | [diff] [blame] | 413 | reset_control_deassert(qproc->pdc_reset); |
Sibi Sankar | 231f67d | 2018-05-21 22:57:13 +0530 | [diff] [blame] | 414 | } else { |
| 415 | ret = reset_control_deassert(qproc->mss_restart); |
| 416 | } |
| 417 | |
| 418 | return ret; |
Sibi Sankar | 9f135fa | 2018-05-21 22:57:12 +0530 | [diff] [blame] | 419 | } |
| 420 | |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 421 | static int q6v5_rmb_pbl_wait(struct q6v5 *qproc, int ms) |
| 422 | { |
| 423 | unsigned long timeout; |
| 424 | s32 val; |
| 425 | |
| 426 | timeout = jiffies + msecs_to_jiffies(ms); |
| 427 | for (;;) { |
| 428 | val = readl(qproc->rmb_base + RMB_PBL_STATUS_REG); |
| 429 | if (val) |
| 430 | break; |
| 431 | |
| 432 | if (time_after(jiffies, timeout)) |
| 433 | return -ETIMEDOUT; |
| 434 | |
| 435 | msleep(1); |
| 436 | } |
| 437 | |
| 438 | return val; |
| 439 | } |
| 440 | |
| 441 | static int q6v5_rmb_mba_wait(struct q6v5 *qproc, u32 status, int ms) |
| 442 | { |
| 443 | |
| 444 | unsigned long timeout; |
| 445 | s32 val; |
| 446 | |
| 447 | timeout = jiffies + msecs_to_jiffies(ms); |
| 448 | for (;;) { |
| 449 | val = readl(qproc->rmb_base + RMB_MBA_STATUS_REG); |
| 450 | if (val < 0) |
| 451 | break; |
| 452 | |
| 453 | if (!status && val) |
| 454 | break; |
| 455 | else if (status && val == status) |
| 456 | break; |
| 457 | |
| 458 | if (time_after(jiffies, timeout)) |
| 459 | return -ETIMEDOUT; |
| 460 | |
| 461 | msleep(1); |
| 462 | } |
| 463 | |
| 464 | return val; |
| 465 | } |
| 466 | |
| 467 | static int q6v5proc_reset(struct q6v5 *qproc) |
| 468 | { |
| 469 | u32 val; |
| 470 | int ret; |
Avaneesh Kumar Dwivedi | 9f058fa | 2017-10-24 21:22:27 +0530 | [diff] [blame] | 471 | int i; |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 472 | |
Sibi Sankar | 231f67d | 2018-05-21 22:57:13 +0530 | [diff] [blame] | 473 | if (qproc->version == MSS_SDM845) { |
| 474 | val = readl(qproc->reg_base + QDSP6SS_SLEEP); |
| 475 | val |= 0x1; |
| 476 | writel(val, qproc->reg_base + QDSP6SS_SLEEP); |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 477 | |
Sibi Sankar | 231f67d | 2018-05-21 22:57:13 +0530 | [diff] [blame] | 478 | ret = readl_poll_timeout(qproc->reg_base + QDSP6SS_SLEEP, |
| 479 | val, !(val & BIT(31)), 1, |
| 480 | SLEEP_CHECK_MAX_LOOPS); |
| 481 | if (ret) { |
| 482 | dev_err(qproc->dev, "QDSP6SS Sleep clock timed out\n"); |
| 483 | return -ETIMEDOUT; |
| 484 | } |
| 485 | |
| 486 | /* De-assert QDSP6 stop core */ |
| 487 | writel(1, qproc->reg_base + QDSP6SS_BOOT_CORE_START); |
| 488 | /* Trigger boot FSM */ |
| 489 | writel(1, qproc->reg_base + QDSP6SS_BOOT_CMD); |
| 490 | |
| 491 | ret = readl_poll_timeout(qproc->rmb_base + RMB_MBA_MSS_STATUS, |
| 492 | val, (val & BIT(0)) != 0, 10, BOOT_FSM_TIMEOUT); |
| 493 | if (ret) { |
| 494 | dev_err(qproc->dev, "Boot FSM failed to complete.\n"); |
| 495 | /* Reset the modem so that boot FSM is in reset state */ |
| 496 | q6v5_reset_deassert(qproc); |
| 497 | return ret; |
| 498 | } |
| 499 | |
| 500 | goto pbl_wait; |
| 501 | } else if (qproc->version == MSS_MSM8996) { |
Avaneesh Kumar Dwivedi | 9f058fa | 2017-10-24 21:22:27 +0530 | [diff] [blame] | 502 | /* Override the ACC value if required */ |
| 503 | writel(QDSP6SS_ACC_OVERRIDE_VAL, |
| 504 | qproc->reg_base + QDSP6SS_STRAP_ACC); |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 505 | |
Avaneesh Kumar Dwivedi | 9f058fa | 2017-10-24 21:22:27 +0530 | [diff] [blame] | 506 | /* Assert resets, stop core */ |
| 507 | val = readl(qproc->reg_base + QDSP6SS_RESET_REG); |
| 508 | val |= Q6SS_CORE_ARES | Q6SS_BUS_ARES_ENABLE | Q6SS_STOP_CORE; |
| 509 | writel(val, qproc->reg_base + QDSP6SS_RESET_REG); |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 510 | |
Avaneesh Kumar Dwivedi | 9f058fa | 2017-10-24 21:22:27 +0530 | [diff] [blame] | 511 | /* BHS require xo cbcr to be enabled */ |
| 512 | val = readl(qproc->reg_base + QDSP6SS_XO_CBCR); |
| 513 | val |= 0x1; |
| 514 | writel(val, qproc->reg_base + QDSP6SS_XO_CBCR); |
| 515 | |
| 516 | /* Read CLKOFF bit to go low indicating CLK is enabled */ |
| 517 | ret = readl_poll_timeout(qproc->reg_base + QDSP6SS_XO_CBCR, |
| 518 | val, !(val & BIT(31)), 1, |
| 519 | HALT_CHECK_MAX_LOOPS); |
| 520 | if (ret) { |
| 521 | dev_err(qproc->dev, |
| 522 | "xo cbcr enabling timed out (rc:%d)\n", ret); |
| 523 | return ret; |
| 524 | } |
| 525 | /* Enable power block headswitch and wait for it to stabilize */ |
| 526 | val = readl(qproc->reg_base + QDSP6SS_PWR_CTL_REG); |
| 527 | val |= QDSP6v56_BHS_ON; |
| 528 | writel(val, qproc->reg_base + QDSP6SS_PWR_CTL_REG); |
| 529 | val |= readl(qproc->reg_base + QDSP6SS_PWR_CTL_REG); |
| 530 | udelay(1); |
| 531 | |
| 532 | /* Put LDO in bypass mode */ |
| 533 | val |= QDSP6v56_LDO_BYP; |
| 534 | writel(val, qproc->reg_base + QDSP6SS_PWR_CTL_REG); |
| 535 | |
| 536 | /* Deassert QDSP6 compiler memory clamp */ |
| 537 | val = readl(qproc->reg_base + QDSP6SS_PWR_CTL_REG); |
| 538 | val &= ~QDSP6v56_CLAMP_QMC_MEM; |
| 539 | writel(val, qproc->reg_base + QDSP6SS_PWR_CTL_REG); |
| 540 | |
| 541 | /* Deassert memory peripheral sleep and L2 memory standby */ |
| 542 | val |= Q6SS_L2DATA_STBY_N | Q6SS_SLP_RET_N; |
| 543 | writel(val, qproc->reg_base + QDSP6SS_PWR_CTL_REG); |
| 544 | |
| 545 | /* Turn on L1, L2, ETB and JU memories 1 at a time */ |
| 546 | val = readl(qproc->reg_base + QDSP6SS_MEM_PWR_CTL); |
| 547 | for (i = 19; i >= 0; i--) { |
| 548 | val |= BIT(i); |
| 549 | writel(val, qproc->reg_base + |
| 550 | QDSP6SS_MEM_PWR_CTL); |
| 551 | /* |
| 552 | * Read back value to ensure the write is done then |
| 553 | * wait for 1us for both memory peripheral and data |
| 554 | * array to turn on. |
| 555 | */ |
| 556 | val |= readl(qproc->reg_base + QDSP6SS_MEM_PWR_CTL); |
| 557 | udelay(1); |
| 558 | } |
| 559 | /* Remove word line clamp */ |
| 560 | val = readl(qproc->reg_base + QDSP6SS_PWR_CTL_REG); |
| 561 | val &= ~QDSP6v56_CLAMP_WL; |
| 562 | writel(val, qproc->reg_base + QDSP6SS_PWR_CTL_REG); |
| 563 | } else { |
| 564 | /* Assert resets, stop core */ |
| 565 | val = readl(qproc->reg_base + QDSP6SS_RESET_REG); |
| 566 | val |= Q6SS_CORE_ARES | Q6SS_BUS_ARES_ENABLE | Q6SS_STOP_CORE; |
| 567 | writel(val, qproc->reg_base + QDSP6SS_RESET_REG); |
| 568 | |
| 569 | /* Enable power block headswitch and wait for it to stabilize */ |
| 570 | val = readl(qproc->reg_base + QDSP6SS_PWR_CTL_REG); |
| 571 | val |= QDSS_BHS_ON | QDSS_LDO_BYP; |
| 572 | writel(val, qproc->reg_base + QDSP6SS_PWR_CTL_REG); |
| 573 | val |= readl(qproc->reg_base + QDSP6SS_PWR_CTL_REG); |
| 574 | udelay(1); |
| 575 | /* |
| 576 | * Turn on memories. L2 banks should be done individually |
| 577 | * to minimize inrush current. |
| 578 | */ |
| 579 | val = readl(qproc->reg_base + QDSP6SS_PWR_CTL_REG); |
| 580 | val |= Q6SS_SLP_RET_N | Q6SS_L2TAG_SLP_NRET_N | |
| 581 | Q6SS_ETB_SLP_NRET_N | Q6SS_L2DATA_STBY_N; |
| 582 | writel(val, qproc->reg_base + QDSP6SS_PWR_CTL_REG); |
| 583 | val |= Q6SS_L2DATA_SLP_NRET_N_2; |
| 584 | writel(val, qproc->reg_base + QDSP6SS_PWR_CTL_REG); |
| 585 | val |= Q6SS_L2DATA_SLP_NRET_N_1; |
| 586 | writel(val, qproc->reg_base + QDSP6SS_PWR_CTL_REG); |
| 587 | val |= Q6SS_L2DATA_SLP_NRET_N_0; |
| 588 | writel(val, qproc->reg_base + QDSP6SS_PWR_CTL_REG); |
| 589 | } |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 590 | /* Remove IO clamp */ |
| 591 | val &= ~Q6SS_CLAMP_IO; |
| 592 | writel(val, qproc->reg_base + QDSP6SS_PWR_CTL_REG); |
| 593 | |
| 594 | /* Bring core out of reset */ |
| 595 | val = readl(qproc->reg_base + QDSP6SS_RESET_REG); |
| 596 | val &= ~Q6SS_CORE_ARES; |
| 597 | writel(val, qproc->reg_base + QDSP6SS_RESET_REG); |
| 598 | |
| 599 | /* Turn on core clock */ |
| 600 | val = readl(qproc->reg_base + QDSP6SS_GFMUX_CTL_REG); |
| 601 | val |= Q6SS_CLK_ENABLE; |
| 602 | writel(val, qproc->reg_base + QDSP6SS_GFMUX_CTL_REG); |
| 603 | |
| 604 | /* Start core execution */ |
| 605 | val = readl(qproc->reg_base + QDSP6SS_RESET_REG); |
| 606 | val &= ~Q6SS_STOP_CORE; |
| 607 | writel(val, qproc->reg_base + QDSP6SS_RESET_REG); |
| 608 | |
Sibi Sankar | 231f67d | 2018-05-21 22:57:13 +0530 | [diff] [blame] | 609 | pbl_wait: |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 610 | /* Wait for PBL status */ |
| 611 | ret = q6v5_rmb_pbl_wait(qproc, 1000); |
| 612 | if (ret == -ETIMEDOUT) { |
| 613 | dev_err(qproc->dev, "PBL boot timed out\n"); |
| 614 | } else if (ret != RMB_PBL_SUCCESS) { |
| 615 | dev_err(qproc->dev, "PBL returned unexpected status %d\n", ret); |
| 616 | ret = -EINVAL; |
| 617 | } else { |
| 618 | ret = 0; |
| 619 | } |
| 620 | |
| 621 | return ret; |
| 622 | } |
| 623 | |
| 624 | static void q6v5proc_halt_axi_port(struct q6v5 *qproc, |
| 625 | struct regmap *halt_map, |
| 626 | u32 offset) |
| 627 | { |
| 628 | unsigned long timeout; |
| 629 | unsigned int val; |
| 630 | int ret; |
| 631 | |
| 632 | /* Check if we're already idle */ |
| 633 | ret = regmap_read(halt_map, offset + AXI_IDLE_REG, &val); |
| 634 | if (!ret && val) |
| 635 | return; |
| 636 | |
| 637 | /* Assert halt request */ |
| 638 | regmap_write(halt_map, offset + AXI_HALTREQ_REG, 1); |
| 639 | |
| 640 | /* Wait for halt */ |
| 641 | timeout = jiffies + msecs_to_jiffies(HALT_ACK_TIMEOUT_MS); |
| 642 | for (;;) { |
| 643 | ret = regmap_read(halt_map, offset + AXI_HALTACK_REG, &val); |
| 644 | if (ret || val || time_after(jiffies, timeout)) |
| 645 | break; |
| 646 | |
| 647 | msleep(1); |
| 648 | } |
| 649 | |
| 650 | ret = regmap_read(halt_map, offset + AXI_IDLE_REG, &val); |
| 651 | if (ret || !val) |
| 652 | dev_err(qproc->dev, "port failed halt\n"); |
| 653 | |
| 654 | /* Clear halt request (port will remain halted until reset) */ |
| 655 | regmap_write(halt_map, offset + AXI_HALTREQ_REG, 0); |
| 656 | } |
| 657 | |
| 658 | static int q6v5_mpss_init_image(struct q6v5 *qproc, const struct firmware *fw) |
| 659 | { |
Krzysztof Kozlowski | 00085f1 | 2016-08-03 13:46:00 -0700 | [diff] [blame] | 660 | unsigned long dma_attrs = DMA_ATTR_FORCE_CONTIGUOUS; |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 661 | dma_addr_t phys; |
Bjorn Andersson | f04b913 | 2019-06-21 18:21:46 -0700 | [diff] [blame] | 662 | void *metadata; |
Avaneesh Kumar Dwivedi | 6c5a9dc | 2017-10-24 21:22:26 +0530 | [diff] [blame] | 663 | int mdata_perm; |
| 664 | int xferop_ret; |
Bjorn Andersson | f04b913 | 2019-06-21 18:21:46 -0700 | [diff] [blame] | 665 | size_t size; |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 666 | void *ptr; |
| 667 | int ret; |
| 668 | |
Bjorn Andersson | f04b913 | 2019-06-21 18:21:46 -0700 | [diff] [blame] | 669 | metadata = qcom_mdt_read_metadata(fw, &size); |
| 670 | if (IS_ERR(metadata)) |
| 671 | return PTR_ERR(metadata); |
| 672 | |
| 673 | ptr = dma_alloc_attrs(qproc->dev, size, &phys, GFP_KERNEL, dma_attrs); |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 674 | if (!ptr) { |
Bjorn Andersson | f04b913 | 2019-06-21 18:21:46 -0700 | [diff] [blame] | 675 | kfree(metadata); |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 676 | dev_err(qproc->dev, "failed to allocate mdt buffer\n"); |
| 677 | return -ENOMEM; |
| 678 | } |
| 679 | |
Bjorn Andersson | f04b913 | 2019-06-21 18:21:46 -0700 | [diff] [blame] | 680 | memcpy(ptr, metadata, size); |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 681 | |
Avaneesh Kumar Dwivedi | 6c5a9dc | 2017-10-24 21:22:26 +0530 | [diff] [blame] | 682 | /* Hypervisor mapping to access metadata by modem */ |
| 683 | mdata_perm = BIT(QCOM_SCM_VMID_HLOS); |
Bjorn Andersson | f04b913 | 2019-06-21 18:21:46 -0700 | [diff] [blame] | 684 | ret = q6v5_xfer_mem_ownership(qproc, &mdata_perm, true, phys, size); |
Bjorn Andersson | 9f2a434 | 2017-11-06 22:26:41 -0800 | [diff] [blame] | 685 | if (ret) { |
| 686 | dev_err(qproc->dev, |
| 687 | "assigning Q6 access to metadata failed: %d\n", ret); |
Christophe JAILLET | 1a5d5c5 | 2017-11-15 07:58:35 +0100 | [diff] [blame] | 688 | ret = -EAGAIN; |
| 689 | goto free_dma_attrs; |
Bjorn Andersson | 9f2a434 | 2017-11-06 22:26:41 -0800 | [diff] [blame] | 690 | } |
Avaneesh Kumar Dwivedi | 6c5a9dc | 2017-10-24 21:22:26 +0530 | [diff] [blame] | 691 | |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 692 | writel(phys, qproc->rmb_base + RMB_PMI_META_DATA_REG); |
| 693 | writel(RMB_CMD_META_DATA_READY, qproc->rmb_base + RMB_MBA_COMMAND_REG); |
| 694 | |
| 695 | ret = q6v5_rmb_mba_wait(qproc, RMB_MBA_META_DATA_AUTH_SUCCESS, 1000); |
| 696 | if (ret == -ETIMEDOUT) |
| 697 | dev_err(qproc->dev, "MPSS header authentication timed out\n"); |
| 698 | else if (ret < 0) |
| 699 | dev_err(qproc->dev, "MPSS header authentication failed: %d\n", ret); |
| 700 | |
Avaneesh Kumar Dwivedi | 6c5a9dc | 2017-10-24 21:22:26 +0530 | [diff] [blame] | 701 | /* Metadata authentication done, remove modem access */ |
Bjorn Andersson | f04b913 | 2019-06-21 18:21:46 -0700 | [diff] [blame] | 702 | xferop_ret = q6v5_xfer_mem_ownership(qproc, &mdata_perm, false, phys, size); |
Avaneesh Kumar Dwivedi | 6c5a9dc | 2017-10-24 21:22:26 +0530 | [diff] [blame] | 703 | if (xferop_ret) |
| 704 | dev_warn(qproc->dev, |
| 705 | "mdt buffer not reclaimed system may become unstable\n"); |
| 706 | |
Christophe JAILLET | 1a5d5c5 | 2017-11-15 07:58:35 +0100 | [diff] [blame] | 707 | free_dma_attrs: |
Bjorn Andersson | f04b913 | 2019-06-21 18:21:46 -0700 | [diff] [blame] | 708 | dma_free_attrs(qproc->dev, size, ptr, phys, dma_attrs); |
| 709 | kfree(metadata); |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 710 | |
| 711 | return ret < 0 ? ret : 0; |
| 712 | } |
| 713 | |
Bjorn Andersson | e7fd252 | 2017-01-26 13:58:35 -0800 | [diff] [blame] | 714 | static bool q6v5_phdr_valid(const struct elf32_phdr *phdr) |
| 715 | { |
| 716 | if (phdr->p_type != PT_LOAD) |
| 717 | return false; |
| 718 | |
| 719 | if ((phdr->p_flags & QCOM_MDT_TYPE_MASK) == QCOM_MDT_TYPE_HASH) |
| 720 | return false; |
| 721 | |
| 722 | if (!phdr->p_memsz) |
| 723 | return false; |
| 724 | |
| 725 | return true; |
| 726 | } |
| 727 | |
Sibi Sankar | 0304530 | 2018-10-17 19:25:25 +0530 | [diff] [blame] | 728 | static int q6v5_mba_load(struct q6v5 *qproc) |
| 729 | { |
| 730 | int ret; |
| 731 | int xfermemop_ret; |
| 732 | |
| 733 | qcom_q6v5_prepare(&qproc->q6v5); |
| 734 | |
Bjorn Andersson | deb9bb8 | 2019-01-30 16:39:31 -0800 | [diff] [blame] | 735 | ret = q6v5_pds_enable(qproc, qproc->active_pds, qproc->active_pd_count); |
| 736 | if (ret < 0) { |
| 737 | dev_err(qproc->dev, "failed to enable active power domains\n"); |
| 738 | goto disable_irqs; |
| 739 | } |
| 740 | |
Rajendra Nayak | 4760a89 | 2019-01-30 16:39:30 -0800 | [diff] [blame] | 741 | ret = q6v5_pds_enable(qproc, qproc->proxy_pds, qproc->proxy_pd_count); |
| 742 | if (ret < 0) { |
| 743 | dev_err(qproc->dev, "failed to enable proxy power domains\n"); |
Bjorn Andersson | deb9bb8 | 2019-01-30 16:39:31 -0800 | [diff] [blame] | 744 | goto disable_active_pds; |
Rajendra Nayak | 4760a89 | 2019-01-30 16:39:30 -0800 | [diff] [blame] | 745 | } |
| 746 | |
Sibi Sankar | 0304530 | 2018-10-17 19:25:25 +0530 | [diff] [blame] | 747 | ret = q6v5_regulator_enable(qproc, qproc->proxy_regs, |
| 748 | qproc->proxy_reg_count); |
| 749 | if (ret) { |
| 750 | dev_err(qproc->dev, "failed to enable proxy supplies\n"); |
Rajendra Nayak | 4760a89 | 2019-01-30 16:39:30 -0800 | [diff] [blame] | 751 | goto disable_proxy_pds; |
Sibi Sankar | 0304530 | 2018-10-17 19:25:25 +0530 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | ret = q6v5_clk_enable(qproc->dev, qproc->proxy_clks, |
| 755 | qproc->proxy_clk_count); |
| 756 | if (ret) { |
| 757 | dev_err(qproc->dev, "failed to enable proxy clocks\n"); |
| 758 | goto disable_proxy_reg; |
| 759 | } |
| 760 | |
| 761 | ret = q6v5_regulator_enable(qproc, qproc->active_regs, |
| 762 | qproc->active_reg_count); |
| 763 | if (ret) { |
| 764 | dev_err(qproc->dev, "failed to enable supplies\n"); |
| 765 | goto disable_proxy_clk; |
| 766 | } |
| 767 | |
| 768 | ret = q6v5_clk_enable(qproc->dev, qproc->reset_clks, |
| 769 | qproc->reset_clk_count); |
| 770 | if (ret) { |
| 771 | dev_err(qproc->dev, "failed to enable reset clocks\n"); |
| 772 | goto disable_vdd; |
| 773 | } |
| 774 | |
| 775 | ret = q6v5_reset_deassert(qproc); |
| 776 | if (ret) { |
| 777 | dev_err(qproc->dev, "failed to deassert mss restart\n"); |
| 778 | goto disable_reset_clks; |
| 779 | } |
| 780 | |
| 781 | ret = q6v5_clk_enable(qproc->dev, qproc->active_clks, |
| 782 | qproc->active_clk_count); |
| 783 | if (ret) { |
| 784 | dev_err(qproc->dev, "failed to enable clocks\n"); |
| 785 | goto assert_reset; |
| 786 | } |
| 787 | |
| 788 | /* Assign MBA image access in DDR to q6 */ |
| 789 | ret = q6v5_xfer_mem_ownership(qproc, &qproc->mba_perm, true, |
| 790 | qproc->mba_phys, qproc->mba_size); |
| 791 | if (ret) { |
| 792 | dev_err(qproc->dev, |
| 793 | "assigning Q6 access to mba memory failed: %d\n", ret); |
| 794 | goto disable_active_clks; |
| 795 | } |
| 796 | |
| 797 | writel(qproc->mba_phys, qproc->rmb_base + RMB_MBA_IMAGE_REG); |
| 798 | |
| 799 | ret = q6v5proc_reset(qproc); |
| 800 | if (ret) |
| 801 | goto reclaim_mba; |
| 802 | |
| 803 | ret = q6v5_rmb_mba_wait(qproc, 0, 5000); |
| 804 | if (ret == -ETIMEDOUT) { |
| 805 | dev_err(qproc->dev, "MBA boot timed out\n"); |
| 806 | goto halt_axi_ports; |
| 807 | } else if (ret != RMB_MBA_XPU_UNLOCKED && |
| 808 | ret != RMB_MBA_XPU_UNLOCKED_SCRIBBLED) { |
| 809 | dev_err(qproc->dev, "MBA returned unexpected status %d\n", ret); |
| 810 | ret = -EINVAL; |
| 811 | goto halt_axi_ports; |
| 812 | } |
| 813 | |
| 814 | qproc->dump_mba_loaded = true; |
| 815 | return 0; |
| 816 | |
| 817 | halt_axi_ports: |
| 818 | q6v5proc_halt_axi_port(qproc, qproc->halt_map, qproc->halt_q6); |
| 819 | q6v5proc_halt_axi_port(qproc, qproc->halt_map, qproc->halt_modem); |
| 820 | q6v5proc_halt_axi_port(qproc, qproc->halt_map, qproc->halt_nc); |
| 821 | |
| 822 | reclaim_mba: |
| 823 | xfermemop_ret = q6v5_xfer_mem_ownership(qproc, &qproc->mba_perm, false, |
| 824 | qproc->mba_phys, |
| 825 | qproc->mba_size); |
| 826 | if (xfermemop_ret) { |
| 827 | dev_err(qproc->dev, |
| 828 | "Failed to reclaim mba buffer, system may become unstable\n"); |
| 829 | } |
| 830 | |
| 831 | disable_active_clks: |
| 832 | q6v5_clk_disable(qproc->dev, qproc->active_clks, |
| 833 | qproc->active_clk_count); |
| 834 | assert_reset: |
| 835 | q6v5_reset_assert(qproc); |
| 836 | disable_reset_clks: |
| 837 | q6v5_clk_disable(qproc->dev, qproc->reset_clks, |
| 838 | qproc->reset_clk_count); |
| 839 | disable_vdd: |
| 840 | q6v5_regulator_disable(qproc, qproc->active_regs, |
| 841 | qproc->active_reg_count); |
| 842 | disable_proxy_clk: |
| 843 | q6v5_clk_disable(qproc->dev, qproc->proxy_clks, |
| 844 | qproc->proxy_clk_count); |
| 845 | disable_proxy_reg: |
| 846 | q6v5_regulator_disable(qproc, qproc->proxy_regs, |
| 847 | qproc->proxy_reg_count); |
Rajendra Nayak | 4760a89 | 2019-01-30 16:39:30 -0800 | [diff] [blame] | 848 | disable_proxy_pds: |
| 849 | q6v5_pds_disable(qproc, qproc->proxy_pds, qproc->proxy_pd_count); |
Bjorn Andersson | deb9bb8 | 2019-01-30 16:39:31 -0800 | [diff] [blame] | 850 | disable_active_pds: |
| 851 | q6v5_pds_disable(qproc, qproc->active_pds, qproc->active_pd_count); |
Sibi Sankar | 0304530 | 2018-10-17 19:25:25 +0530 | [diff] [blame] | 852 | disable_irqs: |
| 853 | qcom_q6v5_unprepare(&qproc->q6v5); |
| 854 | |
| 855 | return ret; |
| 856 | } |
| 857 | |
| 858 | static void q6v5_mba_reclaim(struct q6v5 *qproc) |
| 859 | { |
| 860 | int ret; |
| 861 | u32 val; |
| 862 | |
| 863 | qproc->dump_mba_loaded = false; |
| 864 | |
| 865 | q6v5proc_halt_axi_port(qproc, qproc->halt_map, qproc->halt_q6); |
| 866 | q6v5proc_halt_axi_port(qproc, qproc->halt_map, qproc->halt_modem); |
| 867 | q6v5proc_halt_axi_port(qproc, qproc->halt_map, qproc->halt_nc); |
| 868 | if (qproc->version == MSS_MSM8996) { |
| 869 | /* |
| 870 | * To avoid high MX current during LPASS/MSS restart. |
| 871 | */ |
| 872 | val = readl(qproc->reg_base + QDSP6SS_PWR_CTL_REG); |
| 873 | val |= Q6SS_CLAMP_IO | QDSP6v56_CLAMP_WL | |
| 874 | QDSP6v56_CLAMP_QMC_MEM; |
| 875 | writel(val, qproc->reg_base + QDSP6SS_PWR_CTL_REG); |
| 876 | } |
| 877 | |
| 878 | ret = q6v5_xfer_mem_ownership(qproc, &qproc->mpss_perm, |
| 879 | false, qproc->mpss_phys, |
| 880 | qproc->mpss_size); |
| 881 | WARN_ON(ret); |
| 882 | |
| 883 | q6v5_reset_assert(qproc); |
| 884 | |
| 885 | q6v5_clk_disable(qproc->dev, qproc->reset_clks, |
| 886 | qproc->reset_clk_count); |
| 887 | q6v5_clk_disable(qproc->dev, qproc->active_clks, |
| 888 | qproc->active_clk_count); |
| 889 | q6v5_regulator_disable(qproc, qproc->active_regs, |
| 890 | qproc->active_reg_count); |
Bjorn Andersson | deb9bb8 | 2019-01-30 16:39:31 -0800 | [diff] [blame] | 891 | q6v5_pds_disable(qproc, qproc->active_pds, qproc->active_pd_count); |
Sibi Sankar | 0304530 | 2018-10-17 19:25:25 +0530 | [diff] [blame] | 892 | |
| 893 | /* In case of failure or coredump scenario where reclaiming MBA memory |
| 894 | * could not happen reclaim it here. |
| 895 | */ |
| 896 | ret = q6v5_xfer_mem_ownership(qproc, &qproc->mba_perm, false, |
| 897 | qproc->mba_phys, |
| 898 | qproc->mba_size); |
| 899 | WARN_ON(ret); |
| 900 | |
| 901 | ret = qcom_q6v5_unprepare(&qproc->q6v5); |
| 902 | if (ret) { |
Rajendra Nayak | 4760a89 | 2019-01-30 16:39:30 -0800 | [diff] [blame] | 903 | q6v5_pds_disable(qproc, qproc->proxy_pds, |
| 904 | qproc->proxy_pd_count); |
Sibi Sankar | 0304530 | 2018-10-17 19:25:25 +0530 | [diff] [blame] | 905 | q6v5_clk_disable(qproc->dev, qproc->proxy_clks, |
| 906 | qproc->proxy_clk_count); |
| 907 | q6v5_regulator_disable(qproc, qproc->proxy_regs, |
| 908 | qproc->proxy_reg_count); |
| 909 | } |
| 910 | } |
| 911 | |
Bjorn Andersson | e7fd252 | 2017-01-26 13:58:35 -0800 | [diff] [blame] | 912 | static int q6v5_mpss_load(struct q6v5 *qproc) |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 913 | { |
| 914 | const struct elf32_phdr *phdrs; |
| 915 | const struct elf32_phdr *phdr; |
Bjorn Andersson | e7fd252 | 2017-01-26 13:58:35 -0800 | [diff] [blame] | 916 | const struct firmware *seg_fw; |
| 917 | const struct firmware *fw; |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 918 | struct elf32_hdr *ehdr; |
Bjorn Andersson | e7fd252 | 2017-01-26 13:58:35 -0800 | [diff] [blame] | 919 | phys_addr_t mpss_reloc; |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 920 | phys_addr_t boot_addr; |
Stefan Agner | d7dc899 | 2018-06-14 15:28:02 -0700 | [diff] [blame] | 921 | phys_addr_t min_addr = PHYS_ADDR_MAX; |
Bjorn Andersson | e7fd252 | 2017-01-26 13:58:35 -0800 | [diff] [blame] | 922 | phys_addr_t max_addr = 0; |
| 923 | bool relocate = false; |
Sibi Sankar | a5a4e02 | 2019-01-15 01:20:01 +0530 | [diff] [blame] | 924 | char *fw_name; |
| 925 | size_t fw_name_len; |
Bjorn Andersson | 01625cc5 | 2017-02-15 14:00:41 -0800 | [diff] [blame] | 926 | ssize_t offset; |
Avaneesh Kumar Dwivedi | 94c9078 | 2017-10-24 21:22:25 +0530 | [diff] [blame] | 927 | size_t size = 0; |
Bjorn Andersson | e7fd252 | 2017-01-26 13:58:35 -0800 | [diff] [blame] | 928 | void *ptr; |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 929 | int ret; |
| 930 | int i; |
| 931 | |
Sibi Sankar | a5a4e02 | 2019-01-15 01:20:01 +0530 | [diff] [blame] | 932 | fw_name_len = strlen(qproc->hexagon_mdt_image); |
| 933 | if (fw_name_len <= 4) |
| 934 | return -EINVAL; |
| 935 | |
| 936 | fw_name = kstrdup(qproc->hexagon_mdt_image, GFP_KERNEL); |
| 937 | if (!fw_name) |
| 938 | return -ENOMEM; |
| 939 | |
| 940 | ret = request_firmware(&fw, fw_name, qproc->dev); |
Bjorn Andersson | e7fd252 | 2017-01-26 13:58:35 -0800 | [diff] [blame] | 941 | if (ret < 0) { |
Sibi Sankar | a5a4e02 | 2019-01-15 01:20:01 +0530 | [diff] [blame] | 942 | dev_err(qproc->dev, "unable to load %s\n", fw_name); |
| 943 | goto out; |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 944 | } |
| 945 | |
Bjorn Andersson | e7fd252 | 2017-01-26 13:58:35 -0800 | [diff] [blame] | 946 | /* Initialize the RMB validator */ |
| 947 | writel(0, qproc->rmb_base + RMB_PMI_CODE_LENGTH_REG); |
| 948 | |
| 949 | ret = q6v5_mpss_init_image(qproc, fw); |
| 950 | if (ret) |
| 951 | goto release_firmware; |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 952 | |
| 953 | ehdr = (struct elf32_hdr *)fw->data; |
| 954 | phdrs = (struct elf32_phdr *)(ehdr + 1); |
Bjorn Andersson | e7fd252 | 2017-01-26 13:58:35 -0800 | [diff] [blame] | 955 | |
| 956 | for (i = 0; i < ehdr->e_phnum; i++) { |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 957 | phdr = &phdrs[i]; |
| 958 | |
Bjorn Andersson | e7fd252 | 2017-01-26 13:58:35 -0800 | [diff] [blame] | 959 | if (!q6v5_phdr_valid(phdr)) |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 960 | continue; |
| 961 | |
Bjorn Andersson | e7fd252 | 2017-01-26 13:58:35 -0800 | [diff] [blame] | 962 | if (phdr->p_flags & QCOM_MDT_RELOCATABLE) |
| 963 | relocate = true; |
| 964 | |
| 965 | if (phdr->p_paddr < min_addr) |
| 966 | min_addr = phdr->p_paddr; |
| 967 | |
| 968 | if (phdr->p_paddr + phdr->p_memsz > max_addr) |
| 969 | max_addr = ALIGN(phdr->p_paddr + phdr->p_memsz, SZ_4K); |
| 970 | } |
| 971 | |
| 972 | mpss_reloc = relocate ? min_addr : qproc->mpss_phys; |
Sibi Sankar | 3bf62eb | 2018-07-27 20:50:03 +0530 | [diff] [blame] | 973 | qproc->mpss_reloc = mpss_reloc; |
Avaneesh Kumar Dwivedi | 94c9078 | 2017-10-24 21:22:25 +0530 | [diff] [blame] | 974 | /* Load firmware segments */ |
Bjorn Andersson | e7fd252 | 2017-01-26 13:58:35 -0800 | [diff] [blame] | 975 | for (i = 0; i < ehdr->e_phnum; i++) { |
| 976 | phdr = &phdrs[i]; |
| 977 | |
| 978 | if (!q6v5_phdr_valid(phdr)) |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 979 | continue; |
| 980 | |
Bjorn Andersson | e7fd252 | 2017-01-26 13:58:35 -0800 | [diff] [blame] | 981 | offset = phdr->p_paddr - mpss_reloc; |
| 982 | if (offset < 0 || offset + phdr->p_memsz > qproc->mpss_size) { |
| 983 | dev_err(qproc->dev, "segment outside memory range\n"); |
| 984 | ret = -EINVAL; |
| 985 | goto release_firmware; |
| 986 | } |
| 987 | |
| 988 | ptr = qproc->mpss_region + offset; |
| 989 | |
Bjorn Andersson | f04b913 | 2019-06-21 18:21:46 -0700 | [diff] [blame] | 990 | if (phdr->p_filesz && phdr->p_offset < fw->size) { |
| 991 | /* Firmware is large enough to be non-split */ |
| 992 | if (phdr->p_offset + phdr->p_filesz > fw->size) { |
| 993 | dev_err(qproc->dev, |
| 994 | "failed to load segment %d from truncated file %s\n", |
| 995 | i, fw_name); |
| 996 | ret = -EINVAL; |
| 997 | goto release_firmware; |
| 998 | } |
| 999 | |
| 1000 | memcpy(ptr, fw->data + phdr->p_offset, phdr->p_filesz); |
| 1001 | } else if (phdr->p_filesz) { |
Sibi Sankar | a5a4e02 | 2019-01-15 01:20:01 +0530 | [diff] [blame] | 1002 | /* Replace "xxx.xxx" with "xxx.bxx" */ |
| 1003 | sprintf(fw_name + fw_name_len - 3, "b%02d", i); |
| 1004 | ret = request_firmware(&seg_fw, fw_name, qproc->dev); |
Bjorn Andersson | e7fd252 | 2017-01-26 13:58:35 -0800 | [diff] [blame] | 1005 | if (ret) { |
Sibi Sankar | a5a4e02 | 2019-01-15 01:20:01 +0530 | [diff] [blame] | 1006 | dev_err(qproc->dev, "failed to load %s\n", fw_name); |
Bjorn Andersson | e7fd252 | 2017-01-26 13:58:35 -0800 | [diff] [blame] | 1007 | goto release_firmware; |
| 1008 | } |
| 1009 | |
| 1010 | memcpy(ptr, seg_fw->data, seg_fw->size); |
| 1011 | |
| 1012 | release_firmware(seg_fw); |
| 1013 | } |
| 1014 | |
| 1015 | if (phdr->p_memsz > phdr->p_filesz) { |
| 1016 | memset(ptr + phdr->p_filesz, 0, |
| 1017 | phdr->p_memsz - phdr->p_filesz); |
| 1018 | } |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1019 | size += phdr->p_memsz; |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1020 | } |
| 1021 | |
Avaneesh Kumar Dwivedi | 6c5a9dc | 2017-10-24 21:22:26 +0530 | [diff] [blame] | 1022 | /* Transfer ownership of modem ddr region to q6 */ |
| 1023 | ret = q6v5_xfer_mem_ownership(qproc, &qproc->mpss_perm, true, |
| 1024 | qproc->mpss_phys, qproc->mpss_size); |
Bjorn Andersson | 9f2a434 | 2017-11-06 22:26:41 -0800 | [diff] [blame] | 1025 | if (ret) { |
| 1026 | dev_err(qproc->dev, |
| 1027 | "assigning Q6 access to mpss memory failed: %d\n", ret); |
Christophe JAILLET | 1a5d5c5 | 2017-11-15 07:58:35 +0100 | [diff] [blame] | 1028 | ret = -EAGAIN; |
| 1029 | goto release_firmware; |
Bjorn Andersson | 9f2a434 | 2017-11-06 22:26:41 -0800 | [diff] [blame] | 1030 | } |
Avaneesh Kumar Dwivedi | 6c5a9dc | 2017-10-24 21:22:26 +0530 | [diff] [blame] | 1031 | |
Avaneesh Kumar Dwivedi | 94c9078 | 2017-10-24 21:22:25 +0530 | [diff] [blame] | 1032 | boot_addr = relocate ? qproc->mpss_phys : min_addr; |
| 1033 | writel(boot_addr, qproc->rmb_base + RMB_PMI_CODE_START_REG); |
| 1034 | writel(RMB_CMD_LOAD_READY, qproc->rmb_base + RMB_MBA_COMMAND_REG); |
| 1035 | writel(size, qproc->rmb_base + RMB_PMI_CODE_LENGTH_REG); |
| 1036 | |
Bjorn Andersson | 72beb49 | 2016-07-12 17:15:45 -0700 | [diff] [blame] | 1037 | ret = q6v5_rmb_mba_wait(qproc, RMB_MBA_AUTH_COMPLETE, 10000); |
| 1038 | if (ret == -ETIMEDOUT) |
| 1039 | dev_err(qproc->dev, "MPSS authentication timed out\n"); |
| 1040 | else if (ret < 0) |
| 1041 | dev_err(qproc->dev, "MPSS authentication failed: %d\n", ret); |
| 1042 | |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1043 | release_firmware: |
| 1044 | release_firmware(fw); |
Sibi Sankar | a5a4e02 | 2019-01-15 01:20:01 +0530 | [diff] [blame] | 1045 | out: |
| 1046 | kfree(fw_name); |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1047 | |
| 1048 | return ret < 0 ? ret : 0; |
| 1049 | } |
| 1050 | |
Sibi Sankar | 7dd8ade2 | 2018-10-17 19:25:26 +0530 | [diff] [blame] | 1051 | static void qcom_q6v5_dump_segment(struct rproc *rproc, |
| 1052 | struct rproc_dump_segment *segment, |
| 1053 | void *dest) |
| 1054 | { |
| 1055 | int ret = 0; |
| 1056 | struct q6v5 *qproc = rproc->priv; |
| 1057 | unsigned long mask = BIT((unsigned long)segment->priv); |
| 1058 | void *ptr = rproc_da_to_va(rproc, segment->da, segment->size); |
| 1059 | |
| 1060 | /* Unlock mba before copying segments */ |
| 1061 | if (!qproc->dump_mba_loaded) |
| 1062 | ret = q6v5_mba_load(qproc); |
| 1063 | |
| 1064 | if (!ptr || ret) |
| 1065 | memset(dest, 0xff, segment->size); |
| 1066 | else |
| 1067 | memcpy(dest, ptr, segment->size); |
| 1068 | |
| 1069 | qproc->dump_segment_mask |= mask; |
| 1070 | |
| 1071 | /* Reclaim mba after copying segments */ |
| 1072 | if (qproc->dump_segment_mask == qproc->dump_complete_mask) { |
| 1073 | if (qproc->dump_mba_loaded) |
| 1074 | q6v5_mba_reclaim(qproc); |
| 1075 | } |
| 1076 | } |
| 1077 | |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1078 | static int q6v5_start(struct rproc *rproc) |
| 1079 | { |
| 1080 | struct q6v5 *qproc = (struct q6v5 *)rproc->priv; |
Avaneesh Kumar Dwivedi | 6c5a9dc | 2017-10-24 21:22:26 +0530 | [diff] [blame] | 1081 | int xfermemop_ret; |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1082 | int ret; |
| 1083 | |
Sibi Sankar | 0304530 | 2018-10-17 19:25:25 +0530 | [diff] [blame] | 1084 | ret = q6v5_mba_load(qproc); |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1085 | if (ret) |
Sibi Sankar | 0304530 | 2018-10-17 19:25:25 +0530 | [diff] [blame] | 1086 | return ret; |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1087 | |
| 1088 | dev_info(qproc->dev, "MBA booted, loading mpss\n"); |
| 1089 | |
| 1090 | ret = q6v5_mpss_load(qproc); |
| 1091 | if (ret) |
Avaneesh Kumar Dwivedi | 6c5a9dc | 2017-10-24 21:22:26 +0530 | [diff] [blame] | 1092 | goto reclaim_mpss; |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1093 | |
Bjorn Andersson | 7d67473 | 2018-06-04 13:30:38 -0700 | [diff] [blame] | 1094 | ret = qcom_q6v5_wait_for_start(&qproc->q6v5, msecs_to_jiffies(5000)); |
| 1095 | if (ret == -ETIMEDOUT) { |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1096 | dev_err(qproc->dev, "start timed out\n"); |
Avaneesh Kumar Dwivedi | 6c5a9dc | 2017-10-24 21:22:26 +0530 | [diff] [blame] | 1097 | goto reclaim_mpss; |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1098 | } |
| 1099 | |
Avaneesh Kumar Dwivedi | 6c5a9dc | 2017-10-24 21:22:26 +0530 | [diff] [blame] | 1100 | xfermemop_ret = q6v5_xfer_mem_ownership(qproc, &qproc->mba_perm, false, |
| 1101 | qproc->mba_phys, |
| 1102 | qproc->mba_size); |
| 1103 | if (xfermemop_ret) |
| 1104 | dev_err(qproc->dev, |
| 1105 | "Failed to reclaim mba buffer system may become unstable\n"); |
Sibi Sankar | 7dd8ade2 | 2018-10-17 19:25:26 +0530 | [diff] [blame] | 1106 | |
| 1107 | /* Reset Dump Segment Mask */ |
| 1108 | qproc->dump_segment_mask = 0; |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1109 | qproc->running = true; |
| 1110 | |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1111 | return 0; |
| 1112 | |
Avaneesh Kumar Dwivedi | 6c5a9dc | 2017-10-24 21:22:26 +0530 | [diff] [blame] | 1113 | reclaim_mpss: |
| 1114 | xfermemop_ret = q6v5_xfer_mem_ownership(qproc, &qproc->mpss_perm, |
| 1115 | false, qproc->mpss_phys, |
| 1116 | qproc->mpss_size); |
| 1117 | WARN_ON(xfermemop_ret); |
Sibi Sankar | 0304530 | 2018-10-17 19:25:25 +0530 | [diff] [blame] | 1118 | q6v5_mba_reclaim(qproc); |
Sibi Sankar | 663e984 | 2018-05-21 22:57:09 +0530 | [diff] [blame] | 1119 | |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1120 | return ret; |
| 1121 | } |
| 1122 | |
| 1123 | static int q6v5_stop(struct rproc *rproc) |
| 1124 | { |
| 1125 | struct q6v5 *qproc = (struct q6v5 *)rproc->priv; |
| 1126 | int ret; |
| 1127 | |
| 1128 | qproc->running = false; |
| 1129 | |
Bjorn Andersson | 7d67473 | 2018-06-04 13:30:38 -0700 | [diff] [blame] | 1130 | ret = qcom_q6v5_request_stop(&qproc->q6v5); |
| 1131 | if (ret == -ETIMEDOUT) |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1132 | dev_err(qproc->dev, "timed out on wait\n"); |
| 1133 | |
Sibi Sankar | 0304530 | 2018-10-17 19:25:25 +0530 | [diff] [blame] | 1134 | q6v5_mba_reclaim(qproc); |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1135 | |
| 1136 | return 0; |
| 1137 | } |
| 1138 | |
| 1139 | static void *q6v5_da_to_va(struct rproc *rproc, u64 da, int len) |
| 1140 | { |
| 1141 | struct q6v5 *qproc = rproc->priv; |
| 1142 | int offset; |
| 1143 | |
| 1144 | offset = da - qproc->mpss_reloc; |
| 1145 | if (offset < 0 || offset + len > qproc->mpss_size) |
| 1146 | return NULL; |
| 1147 | |
| 1148 | return qproc->mpss_region + offset; |
| 1149 | } |
| 1150 | |
Sibi Sankar | f18b7e9 | 2018-10-17 19:25:27 +0530 | [diff] [blame] | 1151 | static int qcom_q6v5_register_dump_segments(struct rproc *rproc, |
| 1152 | const struct firmware *mba_fw) |
| 1153 | { |
| 1154 | const struct firmware *fw; |
| 1155 | const struct elf32_phdr *phdrs; |
| 1156 | const struct elf32_phdr *phdr; |
| 1157 | const struct elf32_hdr *ehdr; |
| 1158 | struct q6v5 *qproc = rproc->priv; |
| 1159 | unsigned long i; |
| 1160 | int ret; |
| 1161 | |
Sibi Sankar | a5a4e02 | 2019-01-15 01:20:01 +0530 | [diff] [blame] | 1162 | ret = request_firmware(&fw, qproc->hexagon_mdt_image, qproc->dev); |
Sibi Sankar | f18b7e9 | 2018-10-17 19:25:27 +0530 | [diff] [blame] | 1163 | if (ret < 0) { |
Sibi Sankar | a5a4e02 | 2019-01-15 01:20:01 +0530 | [diff] [blame] | 1164 | dev_err(qproc->dev, "unable to load %s\n", |
| 1165 | qproc->hexagon_mdt_image); |
Sibi Sankar | f18b7e9 | 2018-10-17 19:25:27 +0530 | [diff] [blame] | 1166 | return ret; |
| 1167 | } |
| 1168 | |
| 1169 | ehdr = (struct elf32_hdr *)fw->data; |
| 1170 | phdrs = (struct elf32_phdr *)(ehdr + 1); |
| 1171 | qproc->dump_complete_mask = 0; |
| 1172 | |
| 1173 | for (i = 0; i < ehdr->e_phnum; i++) { |
| 1174 | phdr = &phdrs[i]; |
| 1175 | |
| 1176 | if (!q6v5_phdr_valid(phdr)) |
| 1177 | continue; |
| 1178 | |
| 1179 | ret = rproc_coredump_add_custom_segment(rproc, phdr->p_paddr, |
| 1180 | phdr->p_memsz, |
| 1181 | qcom_q6v5_dump_segment, |
| 1182 | (void *)i); |
| 1183 | if (ret) |
| 1184 | break; |
| 1185 | |
| 1186 | qproc->dump_complete_mask |= BIT(i); |
| 1187 | } |
| 1188 | |
| 1189 | release_firmware(fw); |
| 1190 | return ret; |
| 1191 | } |
| 1192 | |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1193 | static const struct rproc_ops q6v5_ops = { |
| 1194 | .start = q6v5_start, |
| 1195 | .stop = q6v5_stop, |
| 1196 | .da_to_va = q6v5_da_to_va, |
Sibi Sankar | f18b7e9 | 2018-10-17 19:25:27 +0530 | [diff] [blame] | 1197 | .parse_fw = qcom_q6v5_register_dump_segments, |
Bjorn Andersson | 0f21f9c | 2018-01-05 15:58:01 -0800 | [diff] [blame] | 1198 | .load = q6v5_load, |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1199 | }; |
| 1200 | |
Bjorn Andersson | 7d67473 | 2018-06-04 13:30:38 -0700 | [diff] [blame] | 1201 | static void qcom_msa_handover(struct qcom_q6v5 *q6v5) |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1202 | { |
Bjorn Andersson | 7d67473 | 2018-06-04 13:30:38 -0700 | [diff] [blame] | 1203 | struct q6v5 *qproc = container_of(q6v5, struct q6v5, q6v5); |
Sibi Sankar | 663e984 | 2018-05-21 22:57:09 +0530 | [diff] [blame] | 1204 | |
| 1205 | q6v5_clk_disable(qproc->dev, qproc->proxy_clks, |
| 1206 | qproc->proxy_clk_count); |
| 1207 | q6v5_regulator_disable(qproc, qproc->proxy_regs, |
| 1208 | qproc->proxy_reg_count); |
Rajendra Nayak | 4760a89 | 2019-01-30 16:39:30 -0800 | [diff] [blame] | 1209 | q6v5_pds_disable(qproc, qproc->proxy_pds, qproc->proxy_pd_count); |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1210 | } |
| 1211 | |
| 1212 | static int q6v5_init_mem(struct q6v5 *qproc, struct platform_device *pdev) |
| 1213 | { |
| 1214 | struct of_phandle_args args; |
| 1215 | struct resource *res; |
| 1216 | int ret; |
| 1217 | |
| 1218 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "qdsp6"); |
| 1219 | qproc->reg_base = devm_ioremap_resource(&pdev->dev, res); |
Wei Yongjun | b1653f2 | 2016-07-14 12:57:44 +0000 | [diff] [blame] | 1220 | if (IS_ERR(qproc->reg_base)) |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1221 | return PTR_ERR(qproc->reg_base); |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1222 | |
| 1223 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "rmb"); |
| 1224 | qproc->rmb_base = devm_ioremap_resource(&pdev->dev, res); |
Wei Yongjun | b1653f2 | 2016-07-14 12:57:44 +0000 | [diff] [blame] | 1225 | if (IS_ERR(qproc->rmb_base)) |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1226 | return PTR_ERR(qproc->rmb_base); |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1227 | |
| 1228 | ret = of_parse_phandle_with_fixed_args(pdev->dev.of_node, |
| 1229 | "qcom,halt-regs", 3, 0, &args); |
| 1230 | if (ret < 0) { |
| 1231 | dev_err(&pdev->dev, "failed to parse qcom,halt-regs\n"); |
| 1232 | return -EINVAL; |
| 1233 | } |
| 1234 | |
| 1235 | qproc->halt_map = syscon_node_to_regmap(args.np); |
| 1236 | of_node_put(args.np); |
| 1237 | if (IS_ERR(qproc->halt_map)) |
| 1238 | return PTR_ERR(qproc->halt_map); |
| 1239 | |
| 1240 | qproc->halt_q6 = args.args[0]; |
| 1241 | qproc->halt_modem = args.args[1]; |
| 1242 | qproc->halt_nc = args.args[2]; |
| 1243 | |
| 1244 | return 0; |
| 1245 | } |
| 1246 | |
Avaneesh Kumar Dwivedi | 39b2410 | 2016-12-30 19:24:01 +0530 | [diff] [blame] | 1247 | static int q6v5_init_clocks(struct device *dev, struct clk **clks, |
| 1248 | char **clk_names) |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1249 | { |
Avaneesh Kumar Dwivedi | 39b2410 | 2016-12-30 19:24:01 +0530 | [diff] [blame] | 1250 | int i; |
| 1251 | |
| 1252 | if (!clk_names) |
| 1253 | return 0; |
| 1254 | |
| 1255 | for (i = 0; clk_names[i]; i++) { |
| 1256 | clks[i] = devm_clk_get(dev, clk_names[i]); |
| 1257 | if (IS_ERR(clks[i])) { |
| 1258 | int rc = PTR_ERR(clks[i]); |
| 1259 | |
| 1260 | if (rc != -EPROBE_DEFER) |
| 1261 | dev_err(dev, "Failed to get %s clock\n", |
| 1262 | clk_names[i]); |
| 1263 | return rc; |
| 1264 | } |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1265 | } |
| 1266 | |
Avaneesh Kumar Dwivedi | 39b2410 | 2016-12-30 19:24:01 +0530 | [diff] [blame] | 1267 | return i; |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1268 | } |
| 1269 | |
Rajendra Nayak | 4760a89 | 2019-01-30 16:39:30 -0800 | [diff] [blame] | 1270 | static int q6v5_pds_attach(struct device *dev, struct device **devs, |
| 1271 | char **pd_names) |
| 1272 | { |
| 1273 | size_t num_pds = 0; |
| 1274 | int ret; |
| 1275 | int i; |
| 1276 | |
| 1277 | if (!pd_names) |
| 1278 | return 0; |
| 1279 | |
| 1280 | while (pd_names[num_pds]) |
| 1281 | num_pds++; |
| 1282 | |
| 1283 | for (i = 0; i < num_pds; i++) { |
| 1284 | devs[i] = dev_pm_domain_attach_by_name(dev, pd_names[i]); |
Sibi Sankar | f2583fd | 2019-08-21 23:35:48 +0530 | [diff] [blame^] | 1285 | if (IS_ERR_OR_NULL(devs[i])) { |
| 1286 | ret = PTR_ERR(devs[i]) ? : -ENODATA; |
Rajendra Nayak | 4760a89 | 2019-01-30 16:39:30 -0800 | [diff] [blame] | 1287 | goto unroll_attach; |
| 1288 | } |
| 1289 | } |
| 1290 | |
| 1291 | return num_pds; |
| 1292 | |
| 1293 | unroll_attach: |
| 1294 | for (i--; i >= 0; i--) |
| 1295 | dev_pm_domain_detach(devs[i], false); |
| 1296 | |
| 1297 | return ret; |
| 1298 | }; |
| 1299 | |
| 1300 | static void q6v5_pds_detach(struct q6v5 *qproc, struct device **pds, |
| 1301 | size_t pd_count) |
| 1302 | { |
| 1303 | int i; |
| 1304 | |
| 1305 | for (i = 0; i < pd_count; i++) |
| 1306 | dev_pm_domain_detach(pds[i], false); |
| 1307 | } |
| 1308 | |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1309 | static int q6v5_init_reset(struct q6v5 *qproc) |
| 1310 | { |
Philipp Zabel | 5acbf7e | 2017-07-19 17:26:16 +0200 | [diff] [blame] | 1311 | qproc->mss_restart = devm_reset_control_get_exclusive(qproc->dev, |
Sibi Sankar | 9e483ef | 2018-08-30 00:42:14 +0530 | [diff] [blame] | 1312 | "mss_restart"); |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1313 | if (IS_ERR(qproc->mss_restart)) { |
| 1314 | dev_err(qproc->dev, "failed to acquire mss restart\n"); |
| 1315 | return PTR_ERR(qproc->mss_restart); |
| 1316 | } |
| 1317 | |
Sibi Sankar | 29a5f9a | 2018-08-30 00:42:15 +0530 | [diff] [blame] | 1318 | if (qproc->has_alt_reset) { |
| 1319 | qproc->pdc_reset = devm_reset_control_get_exclusive(qproc->dev, |
| 1320 | "pdc_reset"); |
| 1321 | if (IS_ERR(qproc->pdc_reset)) { |
| 1322 | dev_err(qproc->dev, "failed to acquire pdc reset\n"); |
| 1323 | return PTR_ERR(qproc->pdc_reset); |
| 1324 | } |
| 1325 | } |
| 1326 | |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1327 | return 0; |
| 1328 | } |
| 1329 | |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1330 | static int q6v5_alloc_memory_region(struct q6v5 *qproc) |
| 1331 | { |
| 1332 | struct device_node *child; |
| 1333 | struct device_node *node; |
| 1334 | struct resource r; |
| 1335 | int ret; |
| 1336 | |
| 1337 | child = of_get_child_by_name(qproc->dev->of_node, "mba"); |
| 1338 | node = of_parse_phandle(child, "memory-region", 0); |
| 1339 | ret = of_address_to_resource(node, 0, &r); |
| 1340 | if (ret) { |
| 1341 | dev_err(qproc->dev, "unable to resolve mba region\n"); |
| 1342 | return ret; |
| 1343 | } |
Tobias Jordan | 278d744 | 2018-02-15 16:12:55 +0100 | [diff] [blame] | 1344 | of_node_put(node); |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1345 | |
| 1346 | qproc->mba_phys = r.start; |
| 1347 | qproc->mba_size = resource_size(&r); |
| 1348 | qproc->mba_region = devm_ioremap_wc(qproc->dev, qproc->mba_phys, qproc->mba_size); |
| 1349 | if (!qproc->mba_region) { |
| 1350 | dev_err(qproc->dev, "unable to map memory region: %pa+%zx\n", |
| 1351 | &r.start, qproc->mba_size); |
| 1352 | return -EBUSY; |
| 1353 | } |
| 1354 | |
| 1355 | child = of_get_child_by_name(qproc->dev->of_node, "mpss"); |
| 1356 | node = of_parse_phandle(child, "memory-region", 0); |
| 1357 | ret = of_address_to_resource(node, 0, &r); |
| 1358 | if (ret) { |
| 1359 | dev_err(qproc->dev, "unable to resolve mpss region\n"); |
| 1360 | return ret; |
| 1361 | } |
Tobias Jordan | 278d744 | 2018-02-15 16:12:55 +0100 | [diff] [blame] | 1362 | of_node_put(node); |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1363 | |
| 1364 | qproc->mpss_phys = qproc->mpss_reloc = r.start; |
| 1365 | qproc->mpss_size = resource_size(&r); |
| 1366 | qproc->mpss_region = devm_ioremap_wc(qproc->dev, qproc->mpss_phys, qproc->mpss_size); |
| 1367 | if (!qproc->mpss_region) { |
| 1368 | dev_err(qproc->dev, "unable to map memory region: %pa+%zx\n", |
| 1369 | &r.start, qproc->mpss_size); |
| 1370 | return -EBUSY; |
| 1371 | } |
| 1372 | |
| 1373 | return 0; |
| 1374 | } |
| 1375 | |
| 1376 | static int q6v5_probe(struct platform_device *pdev) |
| 1377 | { |
Avaneesh Kumar Dwivedi | 7a8ffe1 | 2016-12-30 19:24:00 +0530 | [diff] [blame] | 1378 | const struct rproc_hexagon_res *desc; |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1379 | struct q6v5 *qproc; |
| 1380 | struct rproc *rproc; |
Sibi Sankar | a5a4e02 | 2019-01-15 01:20:01 +0530 | [diff] [blame] | 1381 | const char *mba_image; |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1382 | int ret; |
| 1383 | |
Avaneesh Kumar Dwivedi | 7a8ffe1 | 2016-12-30 19:24:00 +0530 | [diff] [blame] | 1384 | desc = of_device_get_match_data(&pdev->dev); |
| 1385 | if (!desc) |
| 1386 | return -EINVAL; |
| 1387 | |
Brian Norris | bbcda30 | 2018-10-08 19:08:05 -0700 | [diff] [blame] | 1388 | if (desc->need_mem_protection && !qcom_scm_is_available()) |
| 1389 | return -EPROBE_DEFER; |
| 1390 | |
Sibi Sankar | a5a4e02 | 2019-01-15 01:20:01 +0530 | [diff] [blame] | 1391 | mba_image = desc->hexagon_mba_image; |
| 1392 | ret = of_property_read_string_index(pdev->dev.of_node, "firmware-name", |
| 1393 | 0, &mba_image); |
| 1394 | if (ret < 0 && ret != -EINVAL) |
| 1395 | return ret; |
| 1396 | |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1397 | rproc = rproc_alloc(&pdev->dev, pdev->name, &q6v5_ops, |
Sibi Sankar | a5a4e02 | 2019-01-15 01:20:01 +0530 | [diff] [blame] | 1398 | mba_image, sizeof(*qproc)); |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1399 | if (!rproc) { |
| 1400 | dev_err(&pdev->dev, "failed to allocate rproc\n"); |
| 1401 | return -ENOMEM; |
| 1402 | } |
| 1403 | |
Ramon Fried | 4107102 | 2018-05-24 22:21:41 +0300 | [diff] [blame] | 1404 | rproc->auto_boot = false; |
| 1405 | |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1406 | qproc = (struct q6v5 *)rproc->priv; |
| 1407 | qproc->dev = &pdev->dev; |
| 1408 | qproc->rproc = rproc; |
Sibi Sankar | a5a4e02 | 2019-01-15 01:20:01 +0530 | [diff] [blame] | 1409 | qproc->hexagon_mdt_image = "modem.mdt"; |
| 1410 | ret = of_property_read_string_index(pdev->dev.of_node, "firmware-name", |
| 1411 | 1, &qproc->hexagon_mdt_image); |
| 1412 | if (ret < 0 && ret != -EINVAL) |
| 1413 | return ret; |
| 1414 | |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1415 | platform_set_drvdata(pdev, qproc); |
| 1416 | |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1417 | ret = q6v5_init_mem(qproc, pdev); |
| 1418 | if (ret) |
| 1419 | goto free_rproc; |
| 1420 | |
| 1421 | ret = q6v5_alloc_memory_region(qproc); |
| 1422 | if (ret) |
| 1423 | goto free_rproc; |
| 1424 | |
Avaneesh Kumar Dwivedi | 39b2410 | 2016-12-30 19:24:01 +0530 | [diff] [blame] | 1425 | ret = q6v5_init_clocks(&pdev->dev, qproc->proxy_clks, |
| 1426 | desc->proxy_clk_names); |
| 1427 | if (ret < 0) { |
| 1428 | dev_err(&pdev->dev, "Failed to get proxy clocks.\n"); |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1429 | goto free_rproc; |
Avaneesh Kumar Dwivedi | 39b2410 | 2016-12-30 19:24:01 +0530 | [diff] [blame] | 1430 | } |
| 1431 | qproc->proxy_clk_count = ret; |
| 1432 | |
Sibi Sankar | 231f67d | 2018-05-21 22:57:13 +0530 | [diff] [blame] | 1433 | ret = q6v5_init_clocks(&pdev->dev, qproc->reset_clks, |
| 1434 | desc->reset_clk_names); |
| 1435 | if (ret < 0) { |
| 1436 | dev_err(&pdev->dev, "Failed to get reset clocks.\n"); |
| 1437 | goto free_rproc; |
| 1438 | } |
| 1439 | qproc->reset_clk_count = ret; |
| 1440 | |
Avaneesh Kumar Dwivedi | 39b2410 | 2016-12-30 19:24:01 +0530 | [diff] [blame] | 1441 | ret = q6v5_init_clocks(&pdev->dev, qproc->active_clks, |
| 1442 | desc->active_clk_names); |
| 1443 | if (ret < 0) { |
| 1444 | dev_err(&pdev->dev, "Failed to get active clocks.\n"); |
| 1445 | goto free_rproc; |
| 1446 | } |
| 1447 | qproc->active_clk_count = ret; |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1448 | |
Avaneesh Kumar Dwivedi | 19f902b | 2016-12-30 19:24:02 +0530 | [diff] [blame] | 1449 | ret = q6v5_regulator_init(&pdev->dev, qproc->proxy_regs, |
| 1450 | desc->proxy_supply); |
| 1451 | if (ret < 0) { |
| 1452 | dev_err(&pdev->dev, "Failed to get proxy regulators.\n"); |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1453 | goto free_rproc; |
Avaneesh Kumar Dwivedi | 19f902b | 2016-12-30 19:24:02 +0530 | [diff] [blame] | 1454 | } |
| 1455 | qproc->proxy_reg_count = ret; |
| 1456 | |
| 1457 | ret = q6v5_regulator_init(&pdev->dev, qproc->active_regs, |
| 1458 | desc->active_supply); |
| 1459 | if (ret < 0) { |
| 1460 | dev_err(&pdev->dev, "Failed to get active regulators.\n"); |
| 1461 | goto free_rproc; |
| 1462 | } |
| 1463 | qproc->active_reg_count = ret; |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1464 | |
Bjorn Andersson | deb9bb8 | 2019-01-30 16:39:31 -0800 | [diff] [blame] | 1465 | ret = q6v5_pds_attach(&pdev->dev, qproc->active_pds, |
| 1466 | desc->active_pd_names); |
| 1467 | if (ret < 0) { |
| 1468 | dev_err(&pdev->dev, "Failed to attach active power domains\n"); |
| 1469 | goto free_rproc; |
| 1470 | } |
| 1471 | qproc->active_pd_count = ret; |
| 1472 | |
Rajendra Nayak | 4760a89 | 2019-01-30 16:39:30 -0800 | [diff] [blame] | 1473 | ret = q6v5_pds_attach(&pdev->dev, qproc->proxy_pds, |
| 1474 | desc->proxy_pd_names); |
| 1475 | if (ret < 0) { |
| 1476 | dev_err(&pdev->dev, "Failed to init power domains\n"); |
Bjorn Andersson | deb9bb8 | 2019-01-30 16:39:31 -0800 | [diff] [blame] | 1477 | goto detach_active_pds; |
Rajendra Nayak | 4760a89 | 2019-01-30 16:39:30 -0800 | [diff] [blame] | 1478 | } |
| 1479 | qproc->proxy_pd_count = ret; |
| 1480 | |
Sibi Sankar | 29a5f9a | 2018-08-30 00:42:15 +0530 | [diff] [blame] | 1481 | qproc->has_alt_reset = desc->has_alt_reset; |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1482 | ret = q6v5_init_reset(qproc); |
| 1483 | if (ret) |
Rajendra Nayak | 4760a89 | 2019-01-30 16:39:30 -0800 | [diff] [blame] | 1484 | goto detach_proxy_pds; |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1485 | |
Avaneesh Kumar Dwivedi | 9f058fa | 2017-10-24 21:22:27 +0530 | [diff] [blame] | 1486 | qproc->version = desc->version; |
Avaneesh Kumar Dwivedi | 6c5a9dc | 2017-10-24 21:22:26 +0530 | [diff] [blame] | 1487 | qproc->need_mem_protection = desc->need_mem_protection; |
Bjorn Andersson | 7d67473 | 2018-06-04 13:30:38 -0700 | [diff] [blame] | 1488 | |
| 1489 | ret = qcom_q6v5_init(&qproc->q6v5, pdev, rproc, MPSS_CRASH_REASON_SMEM, |
| 1490 | qcom_msa_handover); |
| 1491 | if (ret) |
Rajendra Nayak | 4760a89 | 2019-01-30 16:39:30 -0800 | [diff] [blame] | 1492 | goto detach_proxy_pds; |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1493 | |
Avaneesh Kumar Dwivedi | 6c5a9dc | 2017-10-24 21:22:26 +0530 | [diff] [blame] | 1494 | qproc->mpss_perm = BIT(QCOM_SCM_VMID_HLOS); |
| 1495 | qproc->mba_perm = BIT(QCOM_SCM_VMID_HLOS); |
Sibi Sankar | 4725496 | 2018-05-21 22:57:14 +0530 | [diff] [blame] | 1496 | qcom_add_glink_subdev(rproc, &qproc->glink_subdev); |
Bjorn Andersson | 4b48921 | 2017-01-29 14:05:50 -0800 | [diff] [blame] | 1497 | qcom_add_smd_subdev(rproc, &qproc->smd_subdev); |
Bjorn Andersson | 1e140df | 2017-07-24 22:56:43 -0700 | [diff] [blame] | 1498 | qcom_add_ssr_subdev(rproc, &qproc->ssr_subdev, "mpss"); |
Bjorn Andersson | 1fb82ee | 2017-08-27 21:51:38 -0700 | [diff] [blame] | 1499 | qproc->sysmon = qcom_add_sysmon_subdev(rproc, "modem", 0x12); |
Sibi Sankar | 027045a | 2019-01-08 15:53:43 +0530 | [diff] [blame] | 1500 | if (IS_ERR(qproc->sysmon)) { |
| 1501 | ret = PTR_ERR(qproc->sysmon); |
Rajendra Nayak | 4760a89 | 2019-01-30 16:39:30 -0800 | [diff] [blame] | 1502 | goto detach_proxy_pds; |
Sibi Sankar | 027045a | 2019-01-08 15:53:43 +0530 | [diff] [blame] | 1503 | } |
Bjorn Andersson | 4b48921 | 2017-01-29 14:05:50 -0800 | [diff] [blame] | 1504 | |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1505 | ret = rproc_add(rproc); |
| 1506 | if (ret) |
Rajendra Nayak | 4760a89 | 2019-01-30 16:39:30 -0800 | [diff] [blame] | 1507 | goto detach_proxy_pds; |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1508 | |
| 1509 | return 0; |
| 1510 | |
Rajendra Nayak | 4760a89 | 2019-01-30 16:39:30 -0800 | [diff] [blame] | 1511 | detach_proxy_pds: |
| 1512 | q6v5_pds_detach(qproc, qproc->proxy_pds, qproc->proxy_pd_count); |
Bjorn Andersson | deb9bb8 | 2019-01-30 16:39:31 -0800 | [diff] [blame] | 1513 | detach_active_pds: |
| 1514 | q6v5_pds_detach(qproc, qproc->active_pds, qproc->active_pd_count); |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1515 | free_rproc: |
Bjorn Andersson | 433c0e0 | 2016-10-02 17:46:38 -0700 | [diff] [blame] | 1516 | rproc_free(rproc); |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1517 | |
| 1518 | return ret; |
| 1519 | } |
| 1520 | |
| 1521 | static int q6v5_remove(struct platform_device *pdev) |
| 1522 | { |
| 1523 | struct q6v5 *qproc = platform_get_drvdata(pdev); |
| 1524 | |
| 1525 | rproc_del(qproc->rproc); |
Bjorn Andersson | 4b48921 | 2017-01-29 14:05:50 -0800 | [diff] [blame] | 1526 | |
Bjorn Andersson | 1fb82ee | 2017-08-27 21:51:38 -0700 | [diff] [blame] | 1527 | qcom_remove_sysmon_subdev(qproc->sysmon); |
Sibi Sankar | 4725496 | 2018-05-21 22:57:14 +0530 | [diff] [blame] | 1528 | qcom_remove_glink_subdev(qproc->rproc, &qproc->glink_subdev); |
Bjorn Andersson | 4b48921 | 2017-01-29 14:05:50 -0800 | [diff] [blame] | 1529 | qcom_remove_smd_subdev(qproc->rproc, &qproc->smd_subdev); |
Bjorn Andersson | 1e140df | 2017-07-24 22:56:43 -0700 | [diff] [blame] | 1530 | qcom_remove_ssr_subdev(qproc->rproc, &qproc->ssr_subdev); |
Rajendra Nayak | 4760a89 | 2019-01-30 16:39:30 -0800 | [diff] [blame] | 1531 | |
Bjorn Andersson | deb9bb8 | 2019-01-30 16:39:31 -0800 | [diff] [blame] | 1532 | q6v5_pds_detach(qproc, qproc->active_pds, qproc->active_pd_count); |
Rajendra Nayak | 4760a89 | 2019-01-30 16:39:30 -0800 | [diff] [blame] | 1533 | q6v5_pds_detach(qproc, qproc->proxy_pds, qproc->proxy_pd_count); |
| 1534 | |
Bjorn Andersson | 433c0e0 | 2016-10-02 17:46:38 -0700 | [diff] [blame] | 1535 | rproc_free(qproc->rproc); |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1536 | |
| 1537 | return 0; |
| 1538 | } |
| 1539 | |
Sibi Sankar | 231f67d | 2018-05-21 22:57:13 +0530 | [diff] [blame] | 1540 | static const struct rproc_hexagon_res sdm845_mss = { |
| 1541 | .hexagon_mba_image = "mba.mbn", |
| 1542 | .proxy_clk_names = (char*[]){ |
| 1543 | "xo", |
Sibi Sankar | 231f67d | 2018-05-21 22:57:13 +0530 | [diff] [blame] | 1544 | "prng", |
| 1545 | NULL |
| 1546 | }, |
| 1547 | .reset_clk_names = (char*[]){ |
| 1548 | "iface", |
| 1549 | "snoc_axi", |
| 1550 | NULL |
| 1551 | }, |
| 1552 | .active_clk_names = (char*[]){ |
| 1553 | "bus", |
| 1554 | "mem", |
| 1555 | "gpll0_mss", |
| 1556 | "mnoc_axi", |
| 1557 | NULL |
| 1558 | }, |
Bjorn Andersson | deb9bb8 | 2019-01-30 16:39:31 -0800 | [diff] [blame] | 1559 | .active_pd_names = (char*[]){ |
| 1560 | "load_state", |
| 1561 | NULL |
| 1562 | }, |
Rajendra Nayak | 4760a89 | 2019-01-30 16:39:30 -0800 | [diff] [blame] | 1563 | .proxy_pd_names = (char*[]){ |
| 1564 | "cx", |
| 1565 | "mx", |
| 1566 | "mss", |
| 1567 | NULL |
| 1568 | }, |
Sibi Sankar | 231f67d | 2018-05-21 22:57:13 +0530 | [diff] [blame] | 1569 | .need_mem_protection = true, |
| 1570 | .has_alt_reset = true, |
| 1571 | .version = MSS_SDM845, |
| 1572 | }; |
| 1573 | |
Avaneesh Kumar Dwivedi | 9f058fa | 2017-10-24 21:22:27 +0530 | [diff] [blame] | 1574 | static const struct rproc_hexagon_res msm8996_mss = { |
| 1575 | .hexagon_mba_image = "mba.mbn", |
Sibi Sankar | 47b8747 | 2018-12-29 00:23:05 +0530 | [diff] [blame] | 1576 | .proxy_supply = (struct qcom_mss_reg_res[]) { |
| 1577 | { |
| 1578 | .supply = "pll", |
| 1579 | .uA = 100000, |
| 1580 | }, |
| 1581 | {} |
| 1582 | }, |
Avaneesh Kumar Dwivedi | 9f058fa | 2017-10-24 21:22:27 +0530 | [diff] [blame] | 1583 | .proxy_clk_names = (char*[]){ |
| 1584 | "xo", |
| 1585 | "pnoc", |
Sibi Sankar | 80ec419 | 2018-12-29 00:23:03 +0530 | [diff] [blame] | 1586 | "qdss", |
Avaneesh Kumar Dwivedi | 9f058fa | 2017-10-24 21:22:27 +0530 | [diff] [blame] | 1587 | NULL |
| 1588 | }, |
| 1589 | .active_clk_names = (char*[]){ |
| 1590 | "iface", |
| 1591 | "bus", |
| 1592 | "mem", |
Sibi Sankar | 80ec419 | 2018-12-29 00:23:03 +0530 | [diff] [blame] | 1593 | "gpll0_mss", |
| 1594 | "snoc_axi", |
| 1595 | "mnoc_axi", |
Avaneesh Kumar Dwivedi | 9f058fa | 2017-10-24 21:22:27 +0530 | [diff] [blame] | 1596 | NULL |
| 1597 | }, |
| 1598 | .need_mem_protection = true, |
Sibi Sankar | 231f67d | 2018-05-21 22:57:13 +0530 | [diff] [blame] | 1599 | .has_alt_reset = false, |
Avaneesh Kumar Dwivedi | 9f058fa | 2017-10-24 21:22:27 +0530 | [diff] [blame] | 1600 | .version = MSS_MSM8996, |
| 1601 | }; |
| 1602 | |
Avaneesh Kumar Dwivedi | 7a8ffe1 | 2016-12-30 19:24:00 +0530 | [diff] [blame] | 1603 | static const struct rproc_hexagon_res msm8916_mss = { |
| 1604 | .hexagon_mba_image = "mba.mbn", |
Avaneesh Kumar Dwivedi | 19f902b | 2016-12-30 19:24:02 +0530 | [diff] [blame] | 1605 | .proxy_supply = (struct qcom_mss_reg_res[]) { |
| 1606 | { |
| 1607 | .supply = "mx", |
| 1608 | .uV = 1050000, |
| 1609 | }, |
| 1610 | { |
| 1611 | .supply = "cx", |
| 1612 | .uA = 100000, |
| 1613 | }, |
| 1614 | { |
| 1615 | .supply = "pll", |
| 1616 | .uA = 100000, |
| 1617 | }, |
| 1618 | {} |
| 1619 | }, |
Avaneesh Kumar Dwivedi | 39b2410 | 2016-12-30 19:24:01 +0530 | [diff] [blame] | 1620 | .proxy_clk_names = (char*[]){ |
| 1621 | "xo", |
| 1622 | NULL |
| 1623 | }, |
| 1624 | .active_clk_names = (char*[]){ |
| 1625 | "iface", |
| 1626 | "bus", |
| 1627 | "mem", |
| 1628 | NULL |
| 1629 | }, |
Avaneesh Kumar Dwivedi | 6c5a9dc | 2017-10-24 21:22:26 +0530 | [diff] [blame] | 1630 | .need_mem_protection = false, |
Sibi Sankar | 231f67d | 2018-05-21 22:57:13 +0530 | [diff] [blame] | 1631 | .has_alt_reset = false, |
Avaneesh Kumar Dwivedi | 9f058fa | 2017-10-24 21:22:27 +0530 | [diff] [blame] | 1632 | .version = MSS_MSM8916, |
Avaneesh Kumar Dwivedi | 7a8ffe1 | 2016-12-30 19:24:00 +0530 | [diff] [blame] | 1633 | }; |
| 1634 | |
| 1635 | static const struct rproc_hexagon_res msm8974_mss = { |
| 1636 | .hexagon_mba_image = "mba.b00", |
Avaneesh Kumar Dwivedi | 19f902b | 2016-12-30 19:24:02 +0530 | [diff] [blame] | 1637 | .proxy_supply = (struct qcom_mss_reg_res[]) { |
| 1638 | { |
| 1639 | .supply = "mx", |
| 1640 | .uV = 1050000, |
| 1641 | }, |
| 1642 | { |
| 1643 | .supply = "cx", |
| 1644 | .uA = 100000, |
| 1645 | }, |
| 1646 | { |
| 1647 | .supply = "pll", |
| 1648 | .uA = 100000, |
| 1649 | }, |
| 1650 | {} |
| 1651 | }, |
| 1652 | .active_supply = (struct qcom_mss_reg_res[]) { |
| 1653 | { |
| 1654 | .supply = "mss", |
| 1655 | .uV = 1050000, |
| 1656 | .uA = 100000, |
| 1657 | }, |
| 1658 | {} |
| 1659 | }, |
Avaneesh Kumar Dwivedi | 39b2410 | 2016-12-30 19:24:01 +0530 | [diff] [blame] | 1660 | .proxy_clk_names = (char*[]){ |
| 1661 | "xo", |
| 1662 | NULL |
| 1663 | }, |
| 1664 | .active_clk_names = (char*[]){ |
| 1665 | "iface", |
| 1666 | "bus", |
| 1667 | "mem", |
| 1668 | NULL |
| 1669 | }, |
Avaneesh Kumar Dwivedi | 6c5a9dc | 2017-10-24 21:22:26 +0530 | [diff] [blame] | 1670 | .need_mem_protection = false, |
Sibi Sankar | 231f67d | 2018-05-21 22:57:13 +0530 | [diff] [blame] | 1671 | .has_alt_reset = false, |
Avaneesh Kumar Dwivedi | 9f058fa | 2017-10-24 21:22:27 +0530 | [diff] [blame] | 1672 | .version = MSS_MSM8974, |
Avaneesh Kumar Dwivedi | 7a8ffe1 | 2016-12-30 19:24:00 +0530 | [diff] [blame] | 1673 | }; |
| 1674 | |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1675 | static const struct of_device_id q6v5_of_match[] = { |
Avaneesh Kumar Dwivedi | 7a8ffe1 | 2016-12-30 19:24:00 +0530 | [diff] [blame] | 1676 | { .compatible = "qcom,q6v5-pil", .data = &msm8916_mss}, |
| 1677 | { .compatible = "qcom,msm8916-mss-pil", .data = &msm8916_mss}, |
| 1678 | { .compatible = "qcom,msm8974-mss-pil", .data = &msm8974_mss}, |
Avaneesh Kumar Dwivedi | 9f058fa | 2017-10-24 21:22:27 +0530 | [diff] [blame] | 1679 | { .compatible = "qcom,msm8996-mss-pil", .data = &msm8996_mss}, |
Sibi Sankar | 231f67d | 2018-05-21 22:57:13 +0530 | [diff] [blame] | 1680 | { .compatible = "qcom,sdm845-mss-pil", .data = &sdm845_mss}, |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1681 | { }, |
| 1682 | }; |
Javier Martinez Canillas | 3227c87 | 2016-10-18 18:24:19 -0300 | [diff] [blame] | 1683 | MODULE_DEVICE_TABLE(of, q6v5_of_match); |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1684 | |
| 1685 | static struct platform_driver q6v5_driver = { |
| 1686 | .probe = q6v5_probe, |
| 1687 | .remove = q6v5_remove, |
| 1688 | .driver = { |
Bjorn Andersson | ef73c22 | 2018-09-24 16:45:26 -0700 | [diff] [blame] | 1689 | .name = "qcom-q6v5-mss", |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1690 | .of_match_table = q6v5_of_match, |
| 1691 | }, |
| 1692 | }; |
| 1693 | module_platform_driver(q6v5_driver); |
| 1694 | |
Bjorn Andersson | ef73c22 | 2018-09-24 16:45:26 -0700 | [diff] [blame] | 1695 | MODULE_DESCRIPTION("Qualcomm Self-authenticating modem remoteproc driver"); |
Bjorn Andersson | 051fb70 | 2016-06-20 14:28:41 -0700 | [diff] [blame] | 1696 | MODULE_LICENSE("GPL v2"); |