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