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