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