Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 1 | /* |
Avaneesh Kumar Dwivedi | 90a068e | 2017-01-30 20:33:08 +0530 | [diff] [blame] | 2 | * Qualcomm ADSP/SLPI Peripheral Image Loader for MSM8974 and MSM8996 |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2016 Linaro Ltd |
| 5 | * Copyright (C) 2014 Sony Mobile Communications AB |
| 6 | * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License |
| 10 | * version 2 as published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | */ |
| 17 | |
Sarangdhar Joshi | f33a735 | 2016-10-25 13:57:26 -0700 | [diff] [blame] | 18 | #include <linux/clk.h> |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 19 | #include <linux/firmware.h> |
| 20 | #include <linux/interrupt.h> |
| 21 | #include <linux/kernel.h> |
| 22 | #include <linux/module.h> |
| 23 | #include <linux/of_address.h> |
| 24 | #include <linux/of_device.h> |
| 25 | #include <linux/platform_device.h> |
| 26 | #include <linux/qcom_scm.h> |
| 27 | #include <linux/regulator/consumer.h> |
| 28 | #include <linux/remoteproc.h> |
Bjorn Andersson | 2aad40d | 2017-01-27 03:12:57 -0800 | [diff] [blame] | 29 | #include <linux/soc/qcom/mdt_loader.h> |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 30 | #include <linux/soc/qcom/smem.h> |
| 31 | #include <linux/soc/qcom/smem_state.h> |
| 32 | |
Bjorn Andersson | bde440e | 2017-01-27 02:28:32 -0800 | [diff] [blame] | 33 | #include "qcom_common.h" |
Bjorn Andersson | 6103b1a | 2018-06-04 13:30:37 -0700 | [diff] [blame] | 34 | #include "qcom_q6v5.h" |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 35 | #include "remoteproc_internal.h" |
| 36 | |
Avaneesh Kumar Dwivedi | c7715e4 | 2017-01-30 20:33:06 +0530 | [diff] [blame] | 37 | struct adsp_data { |
| 38 | int crash_reason_smem; |
| 39 | const char *firmware_name; |
| 40 | int pas_id; |
Avaneesh Kumar Dwivedi | e323fc0 | 2017-01-30 20:33:07 +0530 | [diff] [blame] | 41 | bool has_aggre2_clk; |
Bjorn Andersson | 1fb82ee | 2017-08-27 21:51:38 -0700 | [diff] [blame] | 42 | |
Bjorn Andersson | 1e140df | 2017-07-24 22:56:43 -0700 | [diff] [blame] | 43 | const char *ssr_name; |
Bjorn Andersson | 1fb82ee | 2017-08-27 21:51:38 -0700 | [diff] [blame] | 44 | const char *sysmon_name; |
| 45 | int ssctl_id; |
Avaneesh Kumar Dwivedi | c7715e4 | 2017-01-30 20:33:06 +0530 | [diff] [blame] | 46 | }; |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 47 | |
| 48 | struct qcom_adsp { |
| 49 | struct device *dev; |
| 50 | struct rproc *rproc; |
| 51 | |
Bjorn Andersson | 6103b1a | 2018-06-04 13:30:37 -0700 | [diff] [blame] | 52 | struct qcom_q6v5 q6v5; |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 53 | |
Sarangdhar Joshi | f33a735 | 2016-10-25 13:57:26 -0700 | [diff] [blame] | 54 | struct clk *xo; |
Avaneesh Kumar Dwivedi | e323fc0 | 2017-01-30 20:33:07 +0530 | [diff] [blame] | 55 | struct clk *aggre2_clk; |
Sarangdhar Joshi | f33a735 | 2016-10-25 13:57:26 -0700 | [diff] [blame] | 56 | |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 57 | struct regulator *cx_supply; |
Avaneesh Kumar Dwivedi | e323fc0 | 2017-01-30 20:33:07 +0530 | [diff] [blame] | 58 | struct regulator *px_supply; |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 59 | |
Avaneesh Kumar Dwivedi | c7715e4 | 2017-01-30 20:33:06 +0530 | [diff] [blame] | 60 | int pas_id; |
| 61 | int crash_reason_smem; |
Avaneesh Kumar Dwivedi | e323fc0 | 2017-01-30 20:33:07 +0530 | [diff] [blame] | 62 | bool has_aggre2_clk; |
Avaneesh Kumar Dwivedi | c7715e4 | 2017-01-30 20:33:06 +0530 | [diff] [blame] | 63 | |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 64 | struct completion start_done; |
| 65 | struct completion stop_done; |
| 66 | |
| 67 | phys_addr_t mem_phys; |
| 68 | phys_addr_t mem_reloc; |
| 69 | void *mem_region; |
| 70 | size_t mem_size; |
Bjorn Andersson | 4b48921 | 2017-01-29 14:05:50 -0800 | [diff] [blame] | 71 | |
Bjorn Andersson | eea0702 | 2017-08-29 16:13:35 -0700 | [diff] [blame] | 72 | struct qcom_rproc_glink glink_subdev; |
Bjorn Andersson | 4b48921 | 2017-01-29 14:05:50 -0800 | [diff] [blame] | 73 | struct qcom_rproc_subdev smd_subdev; |
Bjorn Andersson | 1e140df | 2017-07-24 22:56:43 -0700 | [diff] [blame] | 74 | struct qcom_rproc_ssr ssr_subdev; |
Bjorn Andersson | 1fb82ee | 2017-08-27 21:51:38 -0700 | [diff] [blame] | 75 | struct qcom_sysmon *sysmon; |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | static int adsp_load(struct rproc *rproc, const struct firmware *fw) |
| 79 | { |
| 80 | struct qcom_adsp *adsp = (struct qcom_adsp *)rproc->priv; |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 81 | |
Bjorn Andersson | 7f0dd07 | 2017-01-27 02:17:23 -0800 | [diff] [blame] | 82 | return qcom_mdt_load(adsp->dev, fw, rproc->firmware, adsp->pas_id, |
Bjorn Andersson | 4dd27f5 | 2018-01-05 16:04:19 -0800 | [diff] [blame] | 83 | adsp->mem_region, adsp->mem_phys, adsp->mem_size, |
| 84 | &adsp->mem_reloc); |
| 85 | |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 88 | static int adsp_start(struct rproc *rproc) |
| 89 | { |
| 90 | struct qcom_adsp *adsp = (struct qcom_adsp *)rproc->priv; |
| 91 | int ret; |
| 92 | |
Bjorn Andersson | 6103b1a | 2018-06-04 13:30:37 -0700 | [diff] [blame] | 93 | qcom_q6v5_prepare(&adsp->q6v5); |
| 94 | |
Sarangdhar Joshi | f33a735 | 2016-10-25 13:57:26 -0700 | [diff] [blame] | 95 | ret = clk_prepare_enable(adsp->xo); |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 96 | if (ret) |
| 97 | return ret; |
| 98 | |
Avaneesh Kumar Dwivedi | e323fc0 | 2017-01-30 20:33:07 +0530 | [diff] [blame] | 99 | ret = clk_prepare_enable(adsp->aggre2_clk); |
| 100 | if (ret) |
| 101 | goto disable_xo_clk; |
| 102 | |
Sarangdhar Joshi | f33a735 | 2016-10-25 13:57:26 -0700 | [diff] [blame] | 103 | ret = regulator_enable(adsp->cx_supply); |
| 104 | if (ret) |
Avaneesh Kumar Dwivedi | e323fc0 | 2017-01-30 20:33:07 +0530 | [diff] [blame] | 105 | goto disable_aggre2_clk; |
| 106 | |
| 107 | ret = regulator_enable(adsp->px_supply); |
| 108 | if (ret) |
| 109 | goto disable_cx_supply; |
Sarangdhar Joshi | f33a735 | 2016-10-25 13:57:26 -0700 | [diff] [blame] | 110 | |
Avaneesh Kumar Dwivedi | c7715e4 | 2017-01-30 20:33:06 +0530 | [diff] [blame] | 111 | ret = qcom_scm_pas_auth_and_reset(adsp->pas_id); |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 112 | if (ret) { |
| 113 | dev_err(adsp->dev, |
| 114 | "failed to authenticate image and release reset\n"); |
Avaneesh Kumar Dwivedi | e323fc0 | 2017-01-30 20:33:07 +0530 | [diff] [blame] | 115 | goto disable_px_supply; |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Bjorn Andersson | 6103b1a | 2018-06-04 13:30:37 -0700 | [diff] [blame] | 118 | ret = qcom_q6v5_wait_for_start(&adsp->q6v5, msecs_to_jiffies(5000)); |
| 119 | if (ret == -ETIMEDOUT) { |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 120 | dev_err(adsp->dev, "start timed out\n"); |
Avaneesh Kumar Dwivedi | c7715e4 | 2017-01-30 20:33:06 +0530 | [diff] [blame] | 121 | qcom_scm_pas_shutdown(adsp->pas_id); |
Avaneesh Kumar Dwivedi | e323fc0 | 2017-01-30 20:33:07 +0530 | [diff] [blame] | 122 | goto disable_px_supply; |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Bjorn Andersson | 6103b1a | 2018-06-04 13:30:37 -0700 | [diff] [blame] | 125 | return 0; |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 126 | |
Avaneesh Kumar Dwivedi | e323fc0 | 2017-01-30 20:33:07 +0530 | [diff] [blame] | 127 | disable_px_supply: |
| 128 | regulator_disable(adsp->px_supply); |
| 129 | disable_cx_supply: |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 130 | regulator_disable(adsp->cx_supply); |
Avaneesh Kumar Dwivedi | e323fc0 | 2017-01-30 20:33:07 +0530 | [diff] [blame] | 131 | disable_aggre2_clk: |
| 132 | clk_disable_unprepare(adsp->aggre2_clk); |
| 133 | disable_xo_clk: |
Sarangdhar Joshi | f33a735 | 2016-10-25 13:57:26 -0700 | [diff] [blame] | 134 | clk_disable_unprepare(adsp->xo); |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 135 | |
| 136 | return ret; |
| 137 | } |
| 138 | |
Bjorn Andersson | 6103b1a | 2018-06-04 13:30:37 -0700 | [diff] [blame] | 139 | static void qcom_pas_handover(struct qcom_q6v5 *q6v5) |
| 140 | { |
| 141 | struct qcom_adsp *adsp = container_of(q6v5, struct qcom_adsp, q6v5); |
| 142 | |
| 143 | regulator_disable(adsp->px_supply); |
| 144 | regulator_disable(adsp->cx_supply); |
| 145 | clk_disable_unprepare(adsp->aggre2_clk); |
| 146 | clk_disable_unprepare(adsp->xo); |
| 147 | } |
| 148 | |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 149 | static int adsp_stop(struct rproc *rproc) |
| 150 | { |
| 151 | struct qcom_adsp *adsp = (struct qcom_adsp *)rproc->priv; |
Bjorn Andersson | 6103b1a | 2018-06-04 13:30:37 -0700 | [diff] [blame] | 152 | int handover; |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 153 | int ret; |
| 154 | |
Bjorn Andersson | 6103b1a | 2018-06-04 13:30:37 -0700 | [diff] [blame] | 155 | ret = qcom_q6v5_request_stop(&adsp->q6v5); |
| 156 | if (ret == -ETIMEDOUT) |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 157 | dev_err(adsp->dev, "timed out on wait\n"); |
| 158 | |
Avaneesh Kumar Dwivedi | c7715e4 | 2017-01-30 20:33:06 +0530 | [diff] [blame] | 159 | ret = qcom_scm_pas_shutdown(adsp->pas_id); |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 160 | if (ret) |
| 161 | dev_err(adsp->dev, "failed to shutdown: %d\n", ret); |
| 162 | |
Bjorn Andersson | 6103b1a | 2018-06-04 13:30:37 -0700 | [diff] [blame] | 163 | handover = qcom_q6v5_unprepare(&adsp->q6v5); |
| 164 | if (handover) |
| 165 | qcom_pas_handover(&adsp->q6v5); |
| 166 | |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 167 | return ret; |
| 168 | } |
| 169 | |
| 170 | static void *adsp_da_to_va(struct rproc *rproc, u64 da, int len) |
| 171 | { |
| 172 | struct qcom_adsp *adsp = (struct qcom_adsp *)rproc->priv; |
| 173 | int offset; |
| 174 | |
| 175 | offset = da - adsp->mem_reloc; |
| 176 | if (offset < 0 || offset + len > adsp->mem_size) |
| 177 | return NULL; |
| 178 | |
| 179 | return adsp->mem_region + offset; |
| 180 | } |
| 181 | |
| 182 | static const struct rproc_ops adsp_ops = { |
| 183 | .start = adsp_start, |
| 184 | .stop = adsp_stop, |
| 185 | .da_to_va = adsp_da_to_va, |
Sarangdhar Joshi | dcb57ed | 2018-01-05 16:04:20 -0800 | [diff] [blame] | 186 | .parse_fw = qcom_register_dump_segments, |
Bjorn Andersson | 0f21f9c | 2018-01-05 15:58:01 -0800 | [diff] [blame] | 187 | .load = adsp_load, |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 188 | }; |
| 189 | |
Sarangdhar Joshi | f33a735 | 2016-10-25 13:57:26 -0700 | [diff] [blame] | 190 | static int adsp_init_clock(struct qcom_adsp *adsp) |
| 191 | { |
| 192 | int ret; |
| 193 | |
| 194 | adsp->xo = devm_clk_get(adsp->dev, "xo"); |
| 195 | if (IS_ERR(adsp->xo)) { |
| 196 | ret = PTR_ERR(adsp->xo); |
| 197 | if (ret != -EPROBE_DEFER) |
| 198 | dev_err(adsp->dev, "failed to get xo clock"); |
| 199 | return ret; |
| 200 | } |
| 201 | |
Avaneesh Kumar Dwivedi | e323fc0 | 2017-01-30 20:33:07 +0530 | [diff] [blame] | 202 | if (adsp->has_aggre2_clk) { |
| 203 | adsp->aggre2_clk = devm_clk_get(adsp->dev, "aggre2"); |
| 204 | if (IS_ERR(adsp->aggre2_clk)) { |
| 205 | ret = PTR_ERR(adsp->aggre2_clk); |
| 206 | if (ret != -EPROBE_DEFER) |
| 207 | dev_err(adsp->dev, |
| 208 | "failed to get aggre2 clock"); |
| 209 | return ret; |
| 210 | } |
| 211 | } |
| 212 | |
Sarangdhar Joshi | f33a735 | 2016-10-25 13:57:26 -0700 | [diff] [blame] | 213 | return 0; |
| 214 | } |
| 215 | |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 216 | static int adsp_init_regulator(struct qcom_adsp *adsp) |
| 217 | { |
| 218 | adsp->cx_supply = devm_regulator_get(adsp->dev, "cx"); |
| 219 | if (IS_ERR(adsp->cx_supply)) |
| 220 | return PTR_ERR(adsp->cx_supply); |
| 221 | |
| 222 | regulator_set_load(adsp->cx_supply, 100000); |
| 223 | |
Avaneesh Kumar Dwivedi | e323fc0 | 2017-01-30 20:33:07 +0530 | [diff] [blame] | 224 | adsp->px_supply = devm_regulator_get(adsp->dev, "px"); |
Himanshu Jha | c76929b | 2017-08-29 19:13:18 +0530 | [diff] [blame] | 225 | return PTR_ERR_OR_ZERO(adsp->px_supply); |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 226 | } |
| 227 | |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 228 | static int adsp_alloc_memory_region(struct qcom_adsp *adsp) |
| 229 | { |
| 230 | struct device_node *node; |
| 231 | struct resource r; |
| 232 | int ret; |
| 233 | |
| 234 | node = of_parse_phandle(adsp->dev->of_node, "memory-region", 0); |
| 235 | if (!node) { |
| 236 | dev_err(adsp->dev, "no memory-region specified\n"); |
| 237 | return -EINVAL; |
| 238 | } |
| 239 | |
| 240 | ret = of_address_to_resource(node, 0, &r); |
| 241 | if (ret) |
| 242 | return ret; |
| 243 | |
| 244 | adsp->mem_phys = adsp->mem_reloc = r.start; |
| 245 | adsp->mem_size = resource_size(&r); |
| 246 | adsp->mem_region = devm_ioremap_wc(adsp->dev, adsp->mem_phys, adsp->mem_size); |
| 247 | if (!adsp->mem_region) { |
| 248 | dev_err(adsp->dev, "unable to map memory region: %pa+%zx\n", |
| 249 | &r.start, adsp->mem_size); |
| 250 | return -EBUSY; |
| 251 | } |
| 252 | |
| 253 | return 0; |
| 254 | } |
| 255 | |
| 256 | static int adsp_probe(struct platform_device *pdev) |
| 257 | { |
Avaneesh Kumar Dwivedi | c7715e4 | 2017-01-30 20:33:06 +0530 | [diff] [blame] | 258 | const struct adsp_data *desc; |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 259 | struct qcom_adsp *adsp; |
| 260 | struct rproc *rproc; |
| 261 | int ret; |
| 262 | |
Avaneesh Kumar Dwivedi | c7715e4 | 2017-01-30 20:33:06 +0530 | [diff] [blame] | 263 | desc = of_device_get_match_data(&pdev->dev); |
| 264 | if (!desc) |
| 265 | return -EINVAL; |
| 266 | |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 267 | if (!qcom_scm_is_available()) |
| 268 | return -EPROBE_DEFER; |
| 269 | |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 270 | rproc = rproc_alloc(&pdev->dev, pdev->name, &adsp_ops, |
Avaneesh Kumar Dwivedi | c7715e4 | 2017-01-30 20:33:06 +0530 | [diff] [blame] | 271 | desc->firmware_name, sizeof(*adsp)); |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 272 | if (!rproc) { |
| 273 | dev_err(&pdev->dev, "unable to allocate remoteproc\n"); |
| 274 | return -ENOMEM; |
| 275 | } |
| 276 | |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 277 | adsp = (struct qcom_adsp *)rproc->priv; |
| 278 | adsp->dev = &pdev->dev; |
| 279 | adsp->rproc = rproc; |
Avaneesh Kumar Dwivedi | c7715e4 | 2017-01-30 20:33:06 +0530 | [diff] [blame] | 280 | adsp->pas_id = desc->pas_id; |
Avaneesh Kumar Dwivedi | e323fc0 | 2017-01-30 20:33:07 +0530 | [diff] [blame] | 281 | adsp->has_aggre2_clk = desc->has_aggre2_clk; |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 282 | platform_set_drvdata(pdev, adsp); |
| 283 | |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 284 | ret = adsp_alloc_memory_region(adsp); |
| 285 | if (ret) |
| 286 | goto free_rproc; |
| 287 | |
Sarangdhar Joshi | f33a735 | 2016-10-25 13:57:26 -0700 | [diff] [blame] | 288 | ret = adsp_init_clock(adsp); |
| 289 | if (ret) |
| 290 | goto free_rproc; |
| 291 | |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 292 | ret = adsp_init_regulator(adsp); |
| 293 | if (ret) |
| 294 | goto free_rproc; |
| 295 | |
Bjorn Andersson | 6103b1a | 2018-06-04 13:30:37 -0700 | [diff] [blame] | 296 | ret = qcom_q6v5_init(&adsp->q6v5, pdev, rproc, desc->crash_reason_smem, |
| 297 | qcom_pas_handover); |
| 298 | if (ret) |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 299 | goto free_rproc; |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 300 | |
Bjorn Andersson | eea0702 | 2017-08-29 16:13:35 -0700 | [diff] [blame] | 301 | qcom_add_glink_subdev(rproc, &adsp->glink_subdev); |
Bjorn Andersson | 4b48921 | 2017-01-29 14:05:50 -0800 | [diff] [blame] | 302 | qcom_add_smd_subdev(rproc, &adsp->smd_subdev); |
Bjorn Andersson | 1e140df | 2017-07-24 22:56:43 -0700 | [diff] [blame] | 303 | qcom_add_ssr_subdev(rproc, &adsp->ssr_subdev, desc->ssr_name); |
Bjorn Andersson | 1fb82ee | 2017-08-27 21:51:38 -0700 | [diff] [blame] | 304 | adsp->sysmon = qcom_add_sysmon_subdev(rproc, |
| 305 | desc->sysmon_name, |
| 306 | desc->ssctl_id); |
Sibi Sankar | 027045a | 2019-01-08 15:53:43 +0530 | [diff] [blame^] | 307 | if (IS_ERR(adsp->sysmon)) { |
| 308 | ret = PTR_ERR(adsp->sysmon); |
| 309 | goto free_rproc; |
| 310 | } |
Bjorn Andersson | 4b48921 | 2017-01-29 14:05:50 -0800 | [diff] [blame] | 311 | |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 312 | ret = rproc_add(rproc); |
| 313 | if (ret) |
| 314 | goto free_rproc; |
| 315 | |
| 316 | return 0; |
| 317 | |
| 318 | free_rproc: |
Bjorn Andersson | 90a80d8 | 2016-11-19 22:42:55 -0800 | [diff] [blame] | 319 | rproc_free(rproc); |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 320 | |
| 321 | return ret; |
| 322 | } |
| 323 | |
| 324 | static int adsp_remove(struct platform_device *pdev) |
| 325 | { |
| 326 | struct qcom_adsp *adsp = platform_get_drvdata(pdev); |
| 327 | |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 328 | rproc_del(adsp->rproc); |
Bjorn Andersson | 4b48921 | 2017-01-29 14:05:50 -0800 | [diff] [blame] | 329 | |
Bjorn Andersson | eea0702 | 2017-08-29 16:13:35 -0700 | [diff] [blame] | 330 | qcom_remove_glink_subdev(adsp->rproc, &adsp->glink_subdev); |
Bjorn Andersson | 1fb82ee | 2017-08-27 21:51:38 -0700 | [diff] [blame] | 331 | qcom_remove_sysmon_subdev(adsp->sysmon); |
Bjorn Andersson | 4b48921 | 2017-01-29 14:05:50 -0800 | [diff] [blame] | 332 | qcom_remove_smd_subdev(adsp->rproc, &adsp->smd_subdev); |
Bjorn Andersson | 1e140df | 2017-07-24 22:56:43 -0700 | [diff] [blame] | 333 | qcom_remove_ssr_subdev(adsp->rproc, &adsp->ssr_subdev); |
Bjorn Andersson | 90a80d8 | 2016-11-19 22:42:55 -0800 | [diff] [blame] | 334 | rproc_free(adsp->rproc); |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 335 | |
| 336 | return 0; |
| 337 | } |
| 338 | |
Avaneesh Kumar Dwivedi | c7715e4 | 2017-01-30 20:33:06 +0530 | [diff] [blame] | 339 | static const struct adsp_data adsp_resource_init = { |
| 340 | .crash_reason_smem = 423, |
| 341 | .firmware_name = "adsp.mdt", |
| 342 | .pas_id = 1, |
Avaneesh Kumar Dwivedi | e323fc0 | 2017-01-30 20:33:07 +0530 | [diff] [blame] | 343 | .has_aggre2_clk = false, |
Bjorn Andersson | 1e140df | 2017-07-24 22:56:43 -0700 | [diff] [blame] | 344 | .ssr_name = "lpass", |
Bjorn Andersson | 1fb82ee | 2017-08-27 21:51:38 -0700 | [diff] [blame] | 345 | .sysmon_name = "adsp", |
| 346 | .ssctl_id = 0x14, |
Avaneesh Kumar Dwivedi | c7715e4 | 2017-01-30 20:33:06 +0530 | [diff] [blame] | 347 | }; |
| 348 | |
Bjorn Andersson | 3b0d1b6 | 2018-08-28 00:14:58 -0700 | [diff] [blame] | 349 | static const struct adsp_data cdsp_resource_init = { |
| 350 | .crash_reason_smem = 601, |
| 351 | .firmware_name = "cdsp.mdt", |
| 352 | .pas_id = 18, |
| 353 | .has_aggre2_clk = false, |
| 354 | .ssr_name = "cdsp", |
| 355 | .sysmon_name = "cdsp", |
| 356 | .ssctl_id = 0x17, |
| 357 | }; |
| 358 | |
Avaneesh Kumar Dwivedi | 90a068e | 2017-01-30 20:33:08 +0530 | [diff] [blame] | 359 | static const struct adsp_data slpi_resource_init = { |
| 360 | .crash_reason_smem = 424, |
| 361 | .firmware_name = "slpi.mdt", |
| 362 | .pas_id = 12, |
| 363 | .has_aggre2_clk = true, |
Bjorn Andersson | 1e140df | 2017-07-24 22:56:43 -0700 | [diff] [blame] | 364 | .ssr_name = "dsps", |
Bjorn Andersson | 1fb82ee | 2017-08-27 21:51:38 -0700 | [diff] [blame] | 365 | .sysmon_name = "slpi", |
| 366 | .ssctl_id = 0x16, |
Avaneesh Kumar Dwivedi | 90a068e | 2017-01-30 20:33:08 +0530 | [diff] [blame] | 367 | }; |
| 368 | |
Bjorn Andersson | 0af9368 | 2018-09-27 12:03:46 -0700 | [diff] [blame] | 369 | static const struct adsp_data wcss_resource_init = { |
| 370 | .crash_reason_smem = 421, |
| 371 | .firmware_name = "wcnss.mdt", |
| 372 | .pas_id = 6, |
| 373 | .ssr_name = "mpss", |
| 374 | .sysmon_name = "wcnss", |
| 375 | .ssctl_id = 0x12, |
| 376 | }; |
| 377 | |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 378 | static const struct of_device_id adsp_of_match[] = { |
Avaneesh Kumar Dwivedi | c7715e4 | 2017-01-30 20:33:06 +0530 | [diff] [blame] | 379 | { .compatible = "qcom,msm8974-adsp-pil", .data = &adsp_resource_init}, |
| 380 | { .compatible = "qcom,msm8996-adsp-pil", .data = &adsp_resource_init}, |
Avaneesh Kumar Dwivedi | 90a068e | 2017-01-30 20:33:08 +0530 | [diff] [blame] | 381 | { .compatible = "qcom,msm8996-slpi-pil", .data = &slpi_resource_init}, |
Bjorn Andersson | 0af9368 | 2018-09-27 12:03:46 -0700 | [diff] [blame] | 382 | { .compatible = "qcom,qcs404-adsp-pas", .data = &adsp_resource_init }, |
| 383 | { .compatible = "qcom,qcs404-cdsp-pas", .data = &cdsp_resource_init }, |
| 384 | { .compatible = "qcom,qcs404-wcss-pas", .data = &wcss_resource_init }, |
Bjorn Andersson | 3b0d1b6 | 2018-08-28 00:14:58 -0700 | [diff] [blame] | 385 | { .compatible = "qcom,sdm845-adsp-pas", .data = &adsp_resource_init}, |
| 386 | { .compatible = "qcom,sdm845-cdsp-pas", .data = &cdsp_resource_init}, |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 387 | { }, |
| 388 | }; |
Bjorn Andersson | 6242347 | 2016-11-19 22:41:56 -0800 | [diff] [blame] | 389 | MODULE_DEVICE_TABLE(of, adsp_of_match); |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 390 | |
| 391 | static struct platform_driver adsp_driver = { |
| 392 | .probe = adsp_probe, |
| 393 | .remove = adsp_remove, |
| 394 | .driver = { |
Bjorn Andersson | 9e004f9 | 2018-09-24 16:45:25 -0700 | [diff] [blame] | 395 | .name = "qcom_q6v5_pas", |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 396 | .of_match_table = adsp_of_match, |
| 397 | }, |
| 398 | }; |
| 399 | |
| 400 | module_platform_driver(adsp_driver); |
Bjorn Andersson | 9e004f9 | 2018-09-24 16:45:25 -0700 | [diff] [blame] | 401 | MODULE_DESCRIPTION("Qualcomm Hexagon v5 Peripheral Authentication Service driver"); |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 402 | MODULE_LICENSE("GPL v2"); |