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 | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 34 | #include "remoteproc_internal.h" |
| 35 | |
Avaneesh Kumar Dwivedi | c7715e4 | 2017-01-30 20:33:06 +0530 | [diff] [blame] | 36 | struct adsp_data { |
| 37 | int crash_reason_smem; |
| 38 | const char *firmware_name; |
| 39 | int pas_id; |
Avaneesh Kumar Dwivedi | e323fc0 | 2017-01-30 20:33:07 +0530 | [diff] [blame] | 40 | bool has_aggre2_clk; |
Bjorn Andersson | 1e140df | 2017-07-24 22:56:43 -0700 | [diff] [blame] | 41 | const char *ssr_name; |
Avaneesh Kumar Dwivedi | c7715e4 | 2017-01-30 20:33:06 +0530 | [diff] [blame] | 42 | }; |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 43 | |
| 44 | struct qcom_adsp { |
| 45 | struct device *dev; |
| 46 | struct rproc *rproc; |
| 47 | |
| 48 | int wdog_irq; |
| 49 | int fatal_irq; |
| 50 | int ready_irq; |
| 51 | int handover_irq; |
| 52 | int stop_ack_irq; |
| 53 | |
| 54 | struct qcom_smem_state *state; |
| 55 | unsigned stop_bit; |
| 56 | |
Sarangdhar Joshi | f33a735 | 2016-10-25 13:57:26 -0700 | [diff] [blame] | 57 | struct clk *xo; |
Avaneesh Kumar Dwivedi | e323fc0 | 2017-01-30 20:33:07 +0530 | [diff] [blame] | 58 | struct clk *aggre2_clk; |
Sarangdhar Joshi | f33a735 | 2016-10-25 13:57:26 -0700 | [diff] [blame] | 59 | |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 60 | struct regulator *cx_supply; |
Avaneesh Kumar Dwivedi | e323fc0 | 2017-01-30 20:33:07 +0530 | [diff] [blame] | 61 | struct regulator *px_supply; |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 62 | |
Avaneesh Kumar Dwivedi | c7715e4 | 2017-01-30 20:33:06 +0530 | [diff] [blame] | 63 | int pas_id; |
| 64 | int crash_reason_smem; |
Avaneesh Kumar Dwivedi | e323fc0 | 2017-01-30 20:33:07 +0530 | [diff] [blame] | 65 | bool has_aggre2_clk; |
Avaneesh Kumar Dwivedi | c7715e4 | 2017-01-30 20:33:06 +0530 | [diff] [blame] | 66 | |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 67 | struct completion start_done; |
| 68 | struct completion stop_done; |
| 69 | |
| 70 | phys_addr_t mem_phys; |
| 71 | phys_addr_t mem_reloc; |
| 72 | void *mem_region; |
| 73 | size_t mem_size; |
Bjorn Andersson | 4b48921 | 2017-01-29 14:05:50 -0800 | [diff] [blame] | 74 | |
| 75 | struct qcom_rproc_subdev smd_subdev; |
Bjorn Andersson | 1e140df | 2017-07-24 22:56:43 -0700 | [diff] [blame] | 76 | struct qcom_rproc_ssr ssr_subdev; |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | static int adsp_load(struct rproc *rproc, const struct firmware *fw) |
| 80 | { |
| 81 | struct qcom_adsp *adsp = (struct qcom_adsp *)rproc->priv; |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 82 | |
Bjorn Andersson | 7f0dd07 | 2017-01-27 02:17:23 -0800 | [diff] [blame] | 83 | return qcom_mdt_load(adsp->dev, fw, rproc->firmware, adsp->pas_id, |
| 84 | adsp->mem_region, adsp->mem_phys, adsp->mem_size); |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | static const struct rproc_fw_ops adsp_fw_ops = { |
| 88 | .find_rsc_table = qcom_mdt_find_rsc_table, |
| 89 | .load = adsp_load, |
| 90 | }; |
| 91 | |
| 92 | static int adsp_start(struct rproc *rproc) |
| 93 | { |
| 94 | struct qcom_adsp *adsp = (struct qcom_adsp *)rproc->priv; |
| 95 | int ret; |
| 96 | |
Sarangdhar Joshi | f33a735 | 2016-10-25 13:57:26 -0700 | [diff] [blame] | 97 | ret = clk_prepare_enable(adsp->xo); |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 98 | if (ret) |
| 99 | return ret; |
| 100 | |
Avaneesh Kumar Dwivedi | e323fc0 | 2017-01-30 20:33:07 +0530 | [diff] [blame] | 101 | ret = clk_prepare_enable(adsp->aggre2_clk); |
| 102 | if (ret) |
| 103 | goto disable_xo_clk; |
| 104 | |
Sarangdhar Joshi | f33a735 | 2016-10-25 13:57:26 -0700 | [diff] [blame] | 105 | ret = regulator_enable(adsp->cx_supply); |
| 106 | if (ret) |
Avaneesh Kumar Dwivedi | e323fc0 | 2017-01-30 20:33:07 +0530 | [diff] [blame] | 107 | goto disable_aggre2_clk; |
| 108 | |
| 109 | ret = regulator_enable(adsp->px_supply); |
| 110 | if (ret) |
| 111 | goto disable_cx_supply; |
Sarangdhar Joshi | f33a735 | 2016-10-25 13:57:26 -0700 | [diff] [blame] | 112 | |
Avaneesh Kumar Dwivedi | c7715e4 | 2017-01-30 20:33:06 +0530 | [diff] [blame] | 113 | ret = qcom_scm_pas_auth_and_reset(adsp->pas_id); |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 114 | if (ret) { |
| 115 | dev_err(adsp->dev, |
| 116 | "failed to authenticate image and release reset\n"); |
Avaneesh Kumar Dwivedi | e323fc0 | 2017-01-30 20:33:07 +0530 | [diff] [blame] | 117 | goto disable_px_supply; |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | ret = wait_for_completion_timeout(&adsp->start_done, |
| 121 | msecs_to_jiffies(5000)); |
| 122 | if (!ret) { |
| 123 | dev_err(adsp->dev, "start timed out\n"); |
Avaneesh Kumar Dwivedi | c7715e4 | 2017-01-30 20:33:06 +0530 | [diff] [blame] | 124 | qcom_scm_pas_shutdown(adsp->pas_id); |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 125 | ret = -ETIMEDOUT; |
Avaneesh Kumar Dwivedi | e323fc0 | 2017-01-30 20:33:07 +0530 | [diff] [blame] | 126 | goto disable_px_supply; |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | ret = 0; |
| 130 | |
Avaneesh Kumar Dwivedi | e323fc0 | 2017-01-30 20:33:07 +0530 | [diff] [blame] | 131 | disable_px_supply: |
| 132 | regulator_disable(adsp->px_supply); |
| 133 | disable_cx_supply: |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 134 | regulator_disable(adsp->cx_supply); |
Avaneesh Kumar Dwivedi | e323fc0 | 2017-01-30 20:33:07 +0530 | [diff] [blame] | 135 | disable_aggre2_clk: |
| 136 | clk_disable_unprepare(adsp->aggre2_clk); |
| 137 | disable_xo_clk: |
Sarangdhar Joshi | f33a735 | 2016-10-25 13:57:26 -0700 | [diff] [blame] | 138 | clk_disable_unprepare(adsp->xo); |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 139 | |
| 140 | return ret; |
| 141 | } |
| 142 | |
| 143 | static int adsp_stop(struct rproc *rproc) |
| 144 | { |
| 145 | struct qcom_adsp *adsp = (struct qcom_adsp *)rproc->priv; |
| 146 | int ret; |
| 147 | |
| 148 | qcom_smem_state_update_bits(adsp->state, |
| 149 | BIT(adsp->stop_bit), |
| 150 | BIT(adsp->stop_bit)); |
| 151 | |
| 152 | ret = wait_for_completion_timeout(&adsp->stop_done, |
| 153 | msecs_to_jiffies(5000)); |
| 154 | if (ret == 0) |
| 155 | dev_err(adsp->dev, "timed out on wait\n"); |
| 156 | |
| 157 | qcom_smem_state_update_bits(adsp->state, |
| 158 | BIT(adsp->stop_bit), |
| 159 | 0); |
| 160 | |
Avaneesh Kumar Dwivedi | c7715e4 | 2017-01-30 20:33:06 +0530 | [diff] [blame] | 161 | ret = qcom_scm_pas_shutdown(adsp->pas_id); |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 162 | if (ret) |
| 163 | dev_err(adsp->dev, "failed to shutdown: %d\n", ret); |
| 164 | |
| 165 | return ret; |
| 166 | } |
| 167 | |
| 168 | static void *adsp_da_to_va(struct rproc *rproc, u64 da, int len) |
| 169 | { |
| 170 | struct qcom_adsp *adsp = (struct qcom_adsp *)rproc->priv; |
| 171 | int offset; |
| 172 | |
| 173 | offset = da - adsp->mem_reloc; |
| 174 | if (offset < 0 || offset + len > adsp->mem_size) |
| 175 | return NULL; |
| 176 | |
| 177 | return adsp->mem_region + offset; |
| 178 | } |
| 179 | |
| 180 | static const struct rproc_ops adsp_ops = { |
| 181 | .start = adsp_start, |
| 182 | .stop = adsp_stop, |
| 183 | .da_to_va = adsp_da_to_va, |
| 184 | }; |
| 185 | |
| 186 | static irqreturn_t adsp_wdog_interrupt(int irq, void *dev) |
| 187 | { |
| 188 | struct qcom_adsp *adsp = dev; |
| 189 | |
| 190 | rproc_report_crash(adsp->rproc, RPROC_WATCHDOG); |
| 191 | |
| 192 | return IRQ_HANDLED; |
| 193 | } |
| 194 | |
| 195 | static irqreturn_t adsp_fatal_interrupt(int irq, void *dev) |
| 196 | { |
| 197 | struct qcom_adsp *adsp = dev; |
| 198 | size_t len; |
| 199 | char *msg; |
| 200 | |
Avaneesh Kumar Dwivedi | c7715e4 | 2017-01-30 20:33:06 +0530 | [diff] [blame] | 201 | msg = qcom_smem_get(QCOM_SMEM_HOST_ANY, adsp->crash_reason_smem, &len); |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 202 | if (!IS_ERR(msg) && len > 0 && msg[0]) |
| 203 | dev_err(adsp->dev, "fatal error received: %s\n", msg); |
| 204 | |
| 205 | rproc_report_crash(adsp->rproc, RPROC_FATAL_ERROR); |
| 206 | |
| 207 | if (!IS_ERR(msg)) |
| 208 | msg[0] = '\0'; |
| 209 | |
| 210 | return IRQ_HANDLED; |
| 211 | } |
| 212 | |
| 213 | static irqreturn_t adsp_ready_interrupt(int irq, void *dev) |
| 214 | { |
| 215 | return IRQ_HANDLED; |
| 216 | } |
| 217 | |
| 218 | static irqreturn_t adsp_handover_interrupt(int irq, void *dev) |
| 219 | { |
| 220 | struct qcom_adsp *adsp = dev; |
| 221 | |
| 222 | complete(&adsp->start_done); |
| 223 | |
| 224 | return IRQ_HANDLED; |
| 225 | } |
| 226 | |
| 227 | static irqreturn_t adsp_stop_ack_interrupt(int irq, void *dev) |
| 228 | { |
| 229 | struct qcom_adsp *adsp = dev; |
| 230 | |
| 231 | complete(&adsp->stop_done); |
| 232 | |
| 233 | return IRQ_HANDLED; |
| 234 | } |
| 235 | |
Sarangdhar Joshi | f33a735 | 2016-10-25 13:57:26 -0700 | [diff] [blame] | 236 | static int adsp_init_clock(struct qcom_adsp *adsp) |
| 237 | { |
| 238 | int ret; |
| 239 | |
| 240 | adsp->xo = devm_clk_get(adsp->dev, "xo"); |
| 241 | if (IS_ERR(adsp->xo)) { |
| 242 | ret = PTR_ERR(adsp->xo); |
| 243 | if (ret != -EPROBE_DEFER) |
| 244 | dev_err(adsp->dev, "failed to get xo clock"); |
| 245 | return ret; |
| 246 | } |
| 247 | |
Avaneesh Kumar Dwivedi | e323fc0 | 2017-01-30 20:33:07 +0530 | [diff] [blame] | 248 | if (adsp->has_aggre2_clk) { |
| 249 | adsp->aggre2_clk = devm_clk_get(adsp->dev, "aggre2"); |
| 250 | if (IS_ERR(adsp->aggre2_clk)) { |
| 251 | ret = PTR_ERR(adsp->aggre2_clk); |
| 252 | if (ret != -EPROBE_DEFER) |
| 253 | dev_err(adsp->dev, |
| 254 | "failed to get aggre2 clock"); |
| 255 | return ret; |
| 256 | } |
| 257 | } |
| 258 | |
Sarangdhar Joshi | f33a735 | 2016-10-25 13:57:26 -0700 | [diff] [blame] | 259 | return 0; |
| 260 | } |
| 261 | |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 262 | static int adsp_init_regulator(struct qcom_adsp *adsp) |
| 263 | { |
| 264 | adsp->cx_supply = devm_regulator_get(adsp->dev, "cx"); |
| 265 | if (IS_ERR(adsp->cx_supply)) |
| 266 | return PTR_ERR(adsp->cx_supply); |
| 267 | |
| 268 | regulator_set_load(adsp->cx_supply, 100000); |
| 269 | |
Avaneesh Kumar Dwivedi | e323fc0 | 2017-01-30 20:33:07 +0530 | [diff] [blame] | 270 | adsp->px_supply = devm_regulator_get(adsp->dev, "px"); |
Himanshu Jha | c76929b | 2017-08-29 19:13:18 +0530 | [diff] [blame^] | 271 | return PTR_ERR_OR_ZERO(adsp->px_supply); |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | static int adsp_request_irq(struct qcom_adsp *adsp, |
| 275 | struct platform_device *pdev, |
| 276 | const char *name, |
| 277 | irq_handler_t thread_fn) |
| 278 | { |
| 279 | int ret; |
| 280 | |
| 281 | ret = platform_get_irq_byname(pdev, name); |
| 282 | if (ret < 0) { |
| 283 | dev_err(&pdev->dev, "no %s IRQ defined\n", name); |
| 284 | return ret; |
| 285 | } |
| 286 | |
| 287 | ret = devm_request_threaded_irq(&pdev->dev, ret, |
| 288 | NULL, thread_fn, |
| 289 | IRQF_ONESHOT, |
| 290 | "adsp", adsp); |
| 291 | if (ret) |
| 292 | dev_err(&pdev->dev, "request %s IRQ failed\n", name); |
| 293 | |
| 294 | return ret; |
| 295 | } |
| 296 | |
| 297 | static int adsp_alloc_memory_region(struct qcom_adsp *adsp) |
| 298 | { |
| 299 | struct device_node *node; |
| 300 | struct resource r; |
| 301 | int ret; |
| 302 | |
| 303 | node = of_parse_phandle(adsp->dev->of_node, "memory-region", 0); |
| 304 | if (!node) { |
| 305 | dev_err(adsp->dev, "no memory-region specified\n"); |
| 306 | return -EINVAL; |
| 307 | } |
| 308 | |
| 309 | ret = of_address_to_resource(node, 0, &r); |
| 310 | if (ret) |
| 311 | return ret; |
| 312 | |
| 313 | adsp->mem_phys = adsp->mem_reloc = r.start; |
| 314 | adsp->mem_size = resource_size(&r); |
| 315 | adsp->mem_region = devm_ioremap_wc(adsp->dev, adsp->mem_phys, adsp->mem_size); |
| 316 | if (!adsp->mem_region) { |
| 317 | dev_err(adsp->dev, "unable to map memory region: %pa+%zx\n", |
| 318 | &r.start, adsp->mem_size); |
| 319 | return -EBUSY; |
| 320 | } |
| 321 | |
| 322 | return 0; |
| 323 | } |
| 324 | |
| 325 | static int adsp_probe(struct platform_device *pdev) |
| 326 | { |
Avaneesh Kumar Dwivedi | c7715e4 | 2017-01-30 20:33:06 +0530 | [diff] [blame] | 327 | const struct adsp_data *desc; |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 328 | struct qcom_adsp *adsp; |
| 329 | struct rproc *rproc; |
| 330 | int ret; |
| 331 | |
Avaneesh Kumar Dwivedi | c7715e4 | 2017-01-30 20:33:06 +0530 | [diff] [blame] | 332 | desc = of_device_get_match_data(&pdev->dev); |
| 333 | if (!desc) |
| 334 | return -EINVAL; |
| 335 | |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 336 | if (!qcom_scm_is_available()) |
| 337 | return -EPROBE_DEFER; |
| 338 | |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 339 | rproc = rproc_alloc(&pdev->dev, pdev->name, &adsp_ops, |
Avaneesh Kumar Dwivedi | c7715e4 | 2017-01-30 20:33:06 +0530 | [diff] [blame] | 340 | desc->firmware_name, sizeof(*adsp)); |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 341 | if (!rproc) { |
| 342 | dev_err(&pdev->dev, "unable to allocate remoteproc\n"); |
| 343 | return -ENOMEM; |
| 344 | } |
| 345 | |
| 346 | rproc->fw_ops = &adsp_fw_ops; |
| 347 | |
| 348 | adsp = (struct qcom_adsp *)rproc->priv; |
| 349 | adsp->dev = &pdev->dev; |
| 350 | adsp->rproc = rproc; |
Avaneesh Kumar Dwivedi | c7715e4 | 2017-01-30 20:33:06 +0530 | [diff] [blame] | 351 | adsp->pas_id = desc->pas_id; |
| 352 | adsp->crash_reason_smem = desc->crash_reason_smem; |
Avaneesh Kumar Dwivedi | e323fc0 | 2017-01-30 20:33:07 +0530 | [diff] [blame] | 353 | adsp->has_aggre2_clk = desc->has_aggre2_clk; |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 354 | platform_set_drvdata(pdev, adsp); |
| 355 | |
| 356 | init_completion(&adsp->start_done); |
| 357 | init_completion(&adsp->stop_done); |
| 358 | |
| 359 | ret = adsp_alloc_memory_region(adsp); |
| 360 | if (ret) |
| 361 | goto free_rproc; |
| 362 | |
Sarangdhar Joshi | f33a735 | 2016-10-25 13:57:26 -0700 | [diff] [blame] | 363 | ret = adsp_init_clock(adsp); |
| 364 | if (ret) |
| 365 | goto free_rproc; |
| 366 | |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 367 | ret = adsp_init_regulator(adsp); |
| 368 | if (ret) |
| 369 | goto free_rproc; |
| 370 | |
| 371 | ret = adsp_request_irq(adsp, pdev, "wdog", adsp_wdog_interrupt); |
| 372 | if (ret < 0) |
| 373 | goto free_rproc; |
| 374 | adsp->wdog_irq = ret; |
| 375 | |
| 376 | ret = adsp_request_irq(adsp, pdev, "fatal", adsp_fatal_interrupt); |
| 377 | if (ret < 0) |
| 378 | goto free_rproc; |
| 379 | adsp->fatal_irq = ret; |
| 380 | |
| 381 | ret = adsp_request_irq(adsp, pdev, "ready", adsp_ready_interrupt); |
| 382 | if (ret < 0) |
| 383 | goto free_rproc; |
| 384 | adsp->ready_irq = ret; |
| 385 | |
| 386 | ret = adsp_request_irq(adsp, pdev, "handover", adsp_handover_interrupt); |
| 387 | if (ret < 0) |
| 388 | goto free_rproc; |
| 389 | adsp->handover_irq = ret; |
| 390 | |
| 391 | ret = adsp_request_irq(adsp, pdev, "stop-ack", adsp_stop_ack_interrupt); |
| 392 | if (ret < 0) |
| 393 | goto free_rproc; |
| 394 | adsp->stop_ack_irq = ret; |
| 395 | |
| 396 | adsp->state = qcom_smem_state_get(&pdev->dev, "stop", |
| 397 | &adsp->stop_bit); |
| 398 | if (IS_ERR(adsp->state)) { |
| 399 | ret = PTR_ERR(adsp->state); |
| 400 | goto free_rproc; |
| 401 | } |
| 402 | |
Bjorn Andersson | 4b48921 | 2017-01-29 14:05:50 -0800 | [diff] [blame] | 403 | qcom_add_smd_subdev(rproc, &adsp->smd_subdev); |
Bjorn Andersson | 1e140df | 2017-07-24 22:56:43 -0700 | [diff] [blame] | 404 | qcom_add_ssr_subdev(rproc, &adsp->ssr_subdev, desc->ssr_name); |
Bjorn Andersson | 4b48921 | 2017-01-29 14:05:50 -0800 | [diff] [blame] | 405 | |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 406 | ret = rproc_add(rproc); |
| 407 | if (ret) |
| 408 | goto free_rproc; |
| 409 | |
| 410 | return 0; |
| 411 | |
| 412 | free_rproc: |
Bjorn Andersson | 90a80d8 | 2016-11-19 22:42:55 -0800 | [diff] [blame] | 413 | rproc_free(rproc); |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 414 | |
| 415 | return ret; |
| 416 | } |
| 417 | |
| 418 | static int adsp_remove(struct platform_device *pdev) |
| 419 | { |
| 420 | struct qcom_adsp *adsp = platform_get_drvdata(pdev); |
| 421 | |
| 422 | qcom_smem_state_put(adsp->state); |
| 423 | rproc_del(adsp->rproc); |
Bjorn Andersson | 4b48921 | 2017-01-29 14:05:50 -0800 | [diff] [blame] | 424 | |
| 425 | qcom_remove_smd_subdev(adsp->rproc, &adsp->smd_subdev); |
Bjorn Andersson | 1e140df | 2017-07-24 22:56:43 -0700 | [diff] [blame] | 426 | qcom_remove_ssr_subdev(adsp->rproc, &adsp->ssr_subdev); |
Bjorn Andersson | 90a80d8 | 2016-11-19 22:42:55 -0800 | [diff] [blame] | 427 | rproc_free(adsp->rproc); |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 428 | |
| 429 | return 0; |
| 430 | } |
| 431 | |
Avaneesh Kumar Dwivedi | c7715e4 | 2017-01-30 20:33:06 +0530 | [diff] [blame] | 432 | static const struct adsp_data adsp_resource_init = { |
| 433 | .crash_reason_smem = 423, |
| 434 | .firmware_name = "adsp.mdt", |
| 435 | .pas_id = 1, |
Avaneesh Kumar Dwivedi | e323fc0 | 2017-01-30 20:33:07 +0530 | [diff] [blame] | 436 | .has_aggre2_clk = false, |
Bjorn Andersson | 1e140df | 2017-07-24 22:56:43 -0700 | [diff] [blame] | 437 | .ssr_name = "lpass", |
Avaneesh Kumar Dwivedi | c7715e4 | 2017-01-30 20:33:06 +0530 | [diff] [blame] | 438 | }; |
| 439 | |
Avaneesh Kumar Dwivedi | 90a068e | 2017-01-30 20:33:08 +0530 | [diff] [blame] | 440 | static const struct adsp_data slpi_resource_init = { |
| 441 | .crash_reason_smem = 424, |
| 442 | .firmware_name = "slpi.mdt", |
| 443 | .pas_id = 12, |
| 444 | .has_aggre2_clk = true, |
Bjorn Andersson | 1e140df | 2017-07-24 22:56:43 -0700 | [diff] [blame] | 445 | .ssr_name = "dsps", |
Avaneesh Kumar Dwivedi | 90a068e | 2017-01-30 20:33:08 +0530 | [diff] [blame] | 446 | }; |
| 447 | |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 448 | static const struct of_device_id adsp_of_match[] = { |
Avaneesh Kumar Dwivedi | c7715e4 | 2017-01-30 20:33:06 +0530 | [diff] [blame] | 449 | { .compatible = "qcom,msm8974-adsp-pil", .data = &adsp_resource_init}, |
| 450 | { .compatible = "qcom,msm8996-adsp-pil", .data = &adsp_resource_init}, |
Avaneesh Kumar Dwivedi | 90a068e | 2017-01-30 20:33:08 +0530 | [diff] [blame] | 451 | { .compatible = "qcom,msm8996-slpi-pil", .data = &slpi_resource_init}, |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 452 | { }, |
| 453 | }; |
Bjorn Andersson | 6242347 | 2016-11-19 22:41:56 -0800 | [diff] [blame] | 454 | MODULE_DEVICE_TABLE(of, adsp_of_match); |
Bjorn Andersson | b9e718e | 2016-08-22 22:57:44 -0700 | [diff] [blame] | 455 | |
| 456 | static struct platform_driver adsp_driver = { |
| 457 | .probe = adsp_probe, |
| 458 | .remove = adsp_remove, |
| 459 | .driver = { |
| 460 | .name = "qcom_adsp_pil", |
| 461 | .of_match_table = adsp_of_match, |
| 462 | }, |
| 463 | }; |
| 464 | |
| 465 | module_platform_driver(adsp_driver); |
| 466 | MODULE_DESCRIPTION("Qualcomm MSM8974/MSM8996 ADSP Peripherial Image Loader"); |
| 467 | MODULE_LICENSE("GPL v2"); |