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