1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) STMicroelectronics 2018 - All Rights Reserved
4 * Authors: Ludovic Barre <ludovic.barre@st.com> for STMicroelectronics.
5 * Fabien Dessenne <fabien.dessenne@st.com> for STMicroelectronics.
8 #include <linux/arm-smccc.h>
9 #include <linux/dma-mapping.h>
10 #include <linux/interrupt.h>
12 #include <linux/mailbox_client.h>
13 #include <linux/mfd/syscon.h>
14 #include <linux/module.h>
16 #include <linux/of_reserved_mem.h>
17 #include <linux/platform_device.h>
18 #include <linux/pm_wakeirq.h>
19 #include <linux/regmap.h>
20 #include <linux/remoteproc.h>
21 #include <linux/reset.h>
22 #include <linux/slab.h>
23 #include <linux/workqueue.h>
25 #include "remoteproc_internal.h"
28 #define RELEASE_BOOT 1
33 #define STM32_SMC_RCC 0x82001000
34 #define STM32_SMC_REG_WRITE 0x1
36 #define STM32_MBX_VQ0 "vq0"
37 #define STM32_MBX_VQ0_ID 0
38 #define STM32_MBX_VQ1 "vq1"
39 #define STM32_MBX_VQ1_ID 1
40 #define STM32_MBX_SHUTDOWN "shutdown"
41 #define STM32_MBX_DETACH "detach"
43 #define RSC_TBL_SIZE 1024
45 #define M4_STATE_OFF 0
46 #define M4_STATE_INI 1
47 #define M4_STATE_CRUN 2
48 #define M4_STATE_CSTOP 3
49 #define M4_STATE_STANDBY 4
50 #define M4_STATE_CRASH 5
58 struct stm32_rproc_mem {
60 void __iomem *cpu_addr;
66 struct stm32_rproc_mem_ranges {
73 const unsigned char name[10];
74 struct mbox_chan *chan;
75 struct mbox_client client;
76 struct work_struct vq_work;
81 struct reset_control *rst;
82 struct reset_control *hold_boot_rst;
83 struct stm32_syscon hold_boot;
84 struct stm32_syscon pdds;
85 struct stm32_syscon m4_state;
86 struct stm32_syscon rsctbl;
89 struct stm32_rproc_mem *rmems;
90 struct stm32_mbox mb[MBOX_NB_MBX];
91 struct workqueue_struct *workqueue;
96 static int stm32_rproc_pa_to_da(struct rproc *rproc, phys_addr_t pa, u64 *da)
99 struct stm32_rproc *ddata = rproc->priv;
100 struct stm32_rproc_mem *p_mem;
102 for (i = 0; i < ddata->nb_rmems; i++) {
103 p_mem = &ddata->rmems[i];
105 if (pa < p_mem->bus_addr ||
106 pa >= p_mem->bus_addr + p_mem->size)
108 *da = pa - p_mem->bus_addr + p_mem->dev_addr;
109 dev_dbg(rproc->dev.parent, "pa %pa to da %llx\n", &pa, *da);
116 static int stm32_rproc_mem_alloc(struct rproc *rproc,
117 struct rproc_mem_entry *mem)
119 struct device *dev = rproc->dev.parent;
122 dev_dbg(dev, "map memory: %pad+%zx\n", &mem->dma, mem->len);
123 va = ioremap_wc(mem->dma, mem->len);
124 if (IS_ERR_OR_NULL(va)) {
125 dev_err(dev, "Unable to map memory region: %pad+0x%zx\n",
126 &mem->dma, mem->len);
130 /* Update memory entry va */
136 static int stm32_rproc_mem_release(struct rproc *rproc,
137 struct rproc_mem_entry *mem)
139 dev_dbg(rproc->dev.parent, "unmap memory: %pa\n", &mem->dma);
145 static int stm32_rproc_of_memory_translations(struct platform_device *pdev,
146 struct stm32_rproc *ddata)
148 struct device *parent, *dev = &pdev->dev;
149 struct device_node *np;
150 struct stm32_rproc_mem *p_mems;
151 struct stm32_rproc_mem_ranges *mem_range;
152 int cnt, array_size, i, ret = 0;
154 parent = dev->parent;
155 np = parent->of_node;
157 cnt = of_property_count_elems_of_size(np, "dma-ranges",
160 dev_err(dev, "%s: dma-ranges property not defined\n", __func__);
164 p_mems = devm_kcalloc(dev, cnt, sizeof(*p_mems), GFP_KERNEL);
167 mem_range = kcalloc(cnt, sizeof(*mem_range), GFP_KERNEL);
171 array_size = cnt * sizeof(struct stm32_rproc_mem_ranges) / sizeof(u32);
173 ret = of_property_read_u32_array(np, "dma-ranges",
174 (u32 *)mem_range, array_size);
176 dev_err(dev, "error while get dma-ranges property: %x\n", ret);
180 for (i = 0; i < cnt; i++) {
181 p_mems[i].bus_addr = mem_range[i].bus_addr;
182 p_mems[i].dev_addr = mem_range[i].dev_addr;
183 p_mems[i].size = mem_range[i].size;
185 dev_dbg(dev, "memory range[%i]: da %#x, pa %pa, size %#zx:\n",
186 i, p_mems[i].dev_addr, &p_mems[i].bus_addr,
190 ddata->rmems = p_mems;
191 ddata->nb_rmems = cnt;
198 static int stm32_rproc_mbox_idx(struct rproc *rproc, const unsigned char *name)
200 struct stm32_rproc *ddata = rproc->priv;
203 for (i = 0; i < ARRAY_SIZE(ddata->mb); i++) {
204 if (!strncmp(ddata->mb[i].name, name, strlen(name)))
207 dev_err(&rproc->dev, "mailbox %s not found\n", name);
212 static int stm32_rproc_prepare(struct rproc *rproc)
214 struct device *dev = rproc->dev.parent;
215 struct device_node *np = dev->of_node;
216 struct of_phandle_iterator it;
217 struct rproc_mem_entry *mem;
218 struct reserved_mem *rmem;
222 /* Register associated reserved memory regions */
223 of_phandle_iterator_init(&it, np, "memory-region", NULL, 0);
224 while (of_phandle_iterator_next(&it) == 0) {
225 rmem = of_reserved_mem_lookup(it.node);
227 of_node_put(it.node);
228 dev_err(dev, "unable to acquire memory-region\n");
232 if (stm32_rproc_pa_to_da(rproc, rmem->base, &da) < 0) {
233 of_node_put(it.node);
234 dev_err(dev, "memory region not valid %pa\n",
239 /* No need to map vdev buffer */
240 if (strcmp(it.node->name, "vdev0buffer")) {
241 /* Register memory region */
242 mem = rproc_mem_entry_init(dev, NULL,
243 (dma_addr_t)rmem->base,
245 stm32_rproc_mem_alloc,
246 stm32_rproc_mem_release,
250 rproc_coredump_add_segment(rproc, da,
253 /* Register reserved memory for vdev buffer alloc */
254 mem = rproc_of_resm_mem_entry_init(dev, index,
261 of_node_put(it.node);
265 rproc_add_carveout(rproc, mem);
272 static int stm32_rproc_parse_fw(struct rproc *rproc, const struct firmware *fw)
274 if (rproc_elf_load_rsc_table(rproc, fw))
275 dev_warn(&rproc->dev, "no resource table found for this firmware\n");
280 static irqreturn_t stm32_rproc_wdg(int irq, void *data)
282 struct platform_device *pdev = data;
283 struct rproc *rproc = platform_get_drvdata(pdev);
285 rproc_report_crash(rproc, RPROC_WATCHDOG);
290 static void stm32_rproc_mb_vq_work(struct work_struct *work)
292 struct stm32_mbox *mb = container_of(work, struct stm32_mbox, vq_work);
293 struct rproc *rproc = dev_get_drvdata(mb->client.dev);
295 mutex_lock(&rproc->lock);
297 if (rproc->state != RPROC_RUNNING)
300 if (rproc_vq_interrupt(rproc, mb->vq_id) == IRQ_NONE)
301 dev_dbg(&rproc->dev, "no message found in vq%d\n", mb->vq_id);
304 mutex_unlock(&rproc->lock);
307 static void stm32_rproc_mb_callback(struct mbox_client *cl, void *data)
309 struct rproc *rproc = dev_get_drvdata(cl->dev);
310 struct stm32_mbox *mb = container_of(cl, struct stm32_mbox, client);
311 struct stm32_rproc *ddata = rproc->priv;
313 queue_work(ddata->workqueue, &mb->vq_work);
316 static void stm32_rproc_free_mbox(struct rproc *rproc)
318 struct stm32_rproc *ddata = rproc->priv;
321 for (i = 0; i < ARRAY_SIZE(ddata->mb); i++) {
322 if (ddata->mb[i].chan)
323 mbox_free_channel(ddata->mb[i].chan);
324 ddata->mb[i].chan = NULL;
328 static const struct stm32_mbox stm32_rproc_mbox[MBOX_NB_MBX] = {
330 .name = STM32_MBX_VQ0,
331 .vq_id = STM32_MBX_VQ0_ID,
333 .rx_callback = stm32_rproc_mb_callback,
338 .name = STM32_MBX_VQ1,
339 .vq_id = STM32_MBX_VQ1_ID,
341 .rx_callback = stm32_rproc_mb_callback,
346 .name = STM32_MBX_SHUTDOWN,
351 .tx_tout = 500, /* 500 ms time out */
355 .name = STM32_MBX_DETACH,
360 .tx_tout = 200, /* 200 ms time out to detach should be fair enough */
365 static int stm32_rproc_request_mbox(struct rproc *rproc)
367 struct stm32_rproc *ddata = rproc->priv;
368 struct device *dev = &rproc->dev;
371 const unsigned char *name;
372 struct mbox_client *cl;
374 /* Initialise mailbox structure table */
375 memcpy(ddata->mb, stm32_rproc_mbox, sizeof(stm32_rproc_mbox));
377 for (i = 0; i < MBOX_NB_MBX; i++) {
378 name = ddata->mb[i].name;
380 cl = &ddata->mb[i].client;
381 cl->dev = dev->parent;
383 ddata->mb[i].chan = mbox_request_channel_byname(cl, name);
384 if (IS_ERR(ddata->mb[i].chan)) {
385 if (PTR_ERR(ddata->mb[i].chan) == -EPROBE_DEFER) {
386 dev_err_probe(dev->parent,
387 PTR_ERR(ddata->mb[i].chan),
388 "failed to request mailbox %s\n",
392 dev_warn(dev, "cannot get %s mbox\n", name);
393 ddata->mb[i].chan = NULL;
395 if (ddata->mb[i].vq_id >= 0) {
396 INIT_WORK(&ddata->mb[i].vq_work,
397 stm32_rproc_mb_vq_work);
404 for (j = i - 1; j >= 0; j--)
405 if (ddata->mb[j].chan)
406 mbox_free_channel(ddata->mb[j].chan);
407 return -EPROBE_DEFER;
410 static int stm32_rproc_set_hold_boot(struct rproc *rproc, bool hold)
412 struct stm32_rproc *ddata = rproc->priv;
413 struct stm32_syscon hold_boot = ddata->hold_boot;
414 struct arm_smccc_res smc_res;
418 * Three ways to manage the hold boot
419 * - using SCMI: the hold boot is managed as a reset,
420 * - using Linux(no SCMI): the hold boot is managed as a syscon register
421 * - using SMC call (deprecated): use SMC reset interface
424 val = hold ? HOLD_BOOT : RELEASE_BOOT;
426 if (ddata->hold_boot_rst) {
427 /* Use the SCMI reset controller */
429 err = reset_control_deassert(ddata->hold_boot_rst);
431 err = reset_control_assert(ddata->hold_boot_rst);
432 } else if (IS_ENABLED(CONFIG_HAVE_ARM_SMCCC) && ddata->hold_boot_smc) {
433 /* Use the SMC call */
434 arm_smccc_smc(STM32_SMC_RCC, STM32_SMC_REG_WRITE,
435 hold_boot.reg, val, 0, 0, 0, 0, &smc_res);
439 err = regmap_update_bits(hold_boot.map, hold_boot.reg,
440 hold_boot.mask, val);
444 dev_err(&rproc->dev, "failed to set hold boot\n");
449 static void stm32_rproc_add_coredump_trace(struct rproc *rproc)
451 struct rproc_debug_trace *trace;
452 struct rproc_dump_segment *segment;
455 list_for_each_entry(trace, &rproc->traces, node) {
456 already_added = false;
458 list_for_each_entry(segment, &rproc->dump_segments, node) {
459 if (segment->da == trace->trace_mem.da) {
460 already_added = true;
466 rproc_coredump_add_segment(rproc, trace->trace_mem.da,
467 trace->trace_mem.len);
471 static int stm32_rproc_start(struct rproc *rproc)
473 struct stm32_rproc *ddata = rproc->priv;
476 stm32_rproc_add_coredump_trace(rproc);
478 /* clear remote proc Deep Sleep */
479 if (ddata->pdds.map) {
480 err = regmap_update_bits(ddata->pdds.map, ddata->pdds.reg,
481 ddata->pdds.mask, 0);
483 dev_err(&rproc->dev, "failed to clear pdds\n");
488 err = stm32_rproc_set_hold_boot(rproc, false);
492 return stm32_rproc_set_hold_boot(rproc, true);
495 static int stm32_rproc_attach(struct rproc *rproc)
497 stm32_rproc_add_coredump_trace(rproc);
499 return stm32_rproc_set_hold_boot(rproc, true);
502 static int stm32_rproc_detach(struct rproc *rproc)
504 struct stm32_rproc *ddata = rproc->priv;
507 /* Inform the remote processor of the detach */
508 idx = stm32_rproc_mbox_idx(rproc, STM32_MBX_DETACH);
509 if (idx >= 0 && ddata->mb[idx].chan) {
510 err = mbox_send_message(ddata->mb[idx].chan, "stop");
512 dev_warn(&rproc->dev, "warning: remote FW detach without ack\n");
515 /* Allow remote processor to auto-reboot */
516 return stm32_rproc_set_hold_boot(rproc, false);
519 static int stm32_rproc_stop(struct rproc *rproc)
521 struct stm32_rproc *ddata = rproc->priv;
524 /* request shutdown of the remote processor */
525 if (rproc->state != RPROC_OFFLINE && rproc->state != RPROC_CRASHED) {
526 idx = stm32_rproc_mbox_idx(rproc, STM32_MBX_SHUTDOWN);
527 if (idx >= 0 && ddata->mb[idx].chan) {
528 err = mbox_send_message(ddata->mb[idx].chan, "detach");
530 dev_warn(&rproc->dev, "warning: remote FW shutdown without ack\n");
534 err = stm32_rproc_set_hold_boot(rproc, true);
538 err = reset_control_assert(ddata->rst);
540 dev_err(&rproc->dev, "failed to assert the reset\n");
544 /* to allow platform Standby power mode, set remote proc Deep Sleep */
545 if (ddata->pdds.map) {
546 err = regmap_update_bits(ddata->pdds.map, ddata->pdds.reg,
547 ddata->pdds.mask, 1);
549 dev_err(&rproc->dev, "failed to set pdds\n");
554 /* update coprocessor state to OFF if available */
555 if (ddata->m4_state.map) {
556 err = regmap_update_bits(ddata->m4_state.map,
558 ddata->m4_state.mask,
561 dev_err(&rproc->dev, "failed to set copro state\n");
569 static void stm32_rproc_kick(struct rproc *rproc, int vqid)
571 struct stm32_rproc *ddata = rproc->priv;
575 if (WARN_ON(vqid >= MBOX_NB_VQ))
578 for (i = 0; i < MBOX_NB_MBX; i++) {
579 if (vqid != ddata->mb[i].vq_id)
581 if (!ddata->mb[i].chan)
583 err = mbox_send_message(ddata->mb[i].chan, "kick");
585 dev_err(&rproc->dev, "%s: failed (%s, err:%d)\n",
586 __func__, ddata->mb[i].name, err);
591 static int stm32_rproc_da_to_pa(struct rproc *rproc,
592 u64 da, phys_addr_t *pa)
594 struct stm32_rproc *ddata = rproc->priv;
595 struct device *dev = rproc->dev.parent;
596 struct stm32_rproc_mem *p_mem;
599 for (i = 0; i < ddata->nb_rmems; i++) {
600 p_mem = &ddata->rmems[i];
602 if (da < p_mem->dev_addr ||
603 da >= p_mem->dev_addr + p_mem->size)
606 *pa = da - p_mem->dev_addr + p_mem->bus_addr;
607 dev_dbg(dev, "da %llx to pa %pap\n", da, pa);
612 dev_err(dev, "can't translate da %llx\n", da);
617 static struct resource_table *
618 stm32_rproc_get_loaded_rsc_table(struct rproc *rproc, size_t *table_sz)
620 struct stm32_rproc *ddata = rproc->priv;
621 struct device *dev = rproc->dev.parent;
626 /* The resource table has already been mapped, nothing to do */
630 err = regmap_read(ddata->rsctbl.map, ddata->rsctbl.reg, &rsc_da);
632 dev_err(dev, "failed to read rsc tbl addr\n");
633 return ERR_PTR(-EINVAL);
638 return ERR_PTR(-ENOENT);
640 err = stm32_rproc_da_to_pa(rproc, rsc_da, &rsc_pa);
644 ddata->rsc_va = devm_ioremap_wc(dev, rsc_pa, RSC_TBL_SIZE);
645 if (IS_ERR_OR_NULL(ddata->rsc_va)) {
646 dev_err(dev, "Unable to map memory region: %pa+%x\n",
647 &rsc_pa, RSC_TBL_SIZE);
648 ddata->rsc_va = NULL;
649 return ERR_PTR(-ENOMEM);
654 * Assuming the resource table fits in 1kB is fair.
655 * Notice for the detach, that this 1 kB memory area has to be reserved in the coprocessor
656 * firmware for the resource table. On detach, the remoteproc core re-initializes this
657 * entire area by overwriting it with the initial values stored in rproc->clean_table.
659 *table_sz = RSC_TBL_SIZE;
660 return (struct resource_table *)ddata->rsc_va;
663 static const struct rproc_ops st_rproc_ops = {
664 .prepare = stm32_rproc_prepare,
665 .start = stm32_rproc_start,
666 .stop = stm32_rproc_stop,
667 .attach = stm32_rproc_attach,
668 .detach = stm32_rproc_detach,
669 .kick = stm32_rproc_kick,
670 .load = rproc_elf_load_segments,
671 .parse_fw = stm32_rproc_parse_fw,
672 .find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table,
673 .get_loaded_rsc_table = stm32_rproc_get_loaded_rsc_table,
674 .sanity_check = rproc_elf_sanity_check,
675 .get_boot_addr = rproc_elf_get_boot_addr,
678 static const struct of_device_id stm32_rproc_match[] = {
679 { .compatible = "st,stm32mp1-m4" },
682 MODULE_DEVICE_TABLE(of, stm32_rproc_match);
684 static int stm32_rproc_get_syscon(struct device_node *np, const char *prop,
685 struct stm32_syscon *syscon)
689 syscon->map = syscon_regmap_lookup_by_phandle(np, prop);
690 if (IS_ERR(syscon->map)) {
691 err = PTR_ERR(syscon->map);
696 err = of_property_read_u32_index(np, prop, 1, &syscon->reg);
700 err = of_property_read_u32_index(np, prop, 2, &syscon->mask);
706 static int stm32_rproc_parse_dt(struct platform_device *pdev,
707 struct stm32_rproc *ddata, bool *auto_boot)
709 struct device *dev = &pdev->dev;
710 struct device_node *np = dev->of_node;
711 struct stm32_syscon tz;
715 irq = platform_get_irq(pdev, 0);
716 if (irq == -EPROBE_DEFER)
717 return dev_err_probe(dev, irq, "failed to get interrupt\n");
720 err = devm_request_irq(dev, irq, stm32_rproc_wdg, 0,
721 dev_name(dev), pdev);
723 return dev_err_probe(dev, err,
724 "failed to request wdg irq\n");
726 ddata->wdg_irq = irq;
728 if (of_property_read_bool(np, "wakeup-source")) {
729 device_init_wakeup(dev, true);
730 dev_pm_set_wake_irq(dev, irq);
733 dev_info(dev, "wdg irq registered\n");
736 ddata->rst = devm_reset_control_get_optional(dev, "mcu_rst");
738 /* Try legacy fallback method: get it by index */
739 ddata->rst = devm_reset_control_get_by_index(dev, 0);
741 if (IS_ERR(ddata->rst))
742 return dev_err_probe(dev, PTR_ERR(ddata->rst),
743 "failed to get mcu_reset\n");
746 * Three ways to manage the hold boot
747 * - using SCMI: the hold boot is managed as a reset
748 * The DT "reset-mames" property should be defined with 2 items:
749 * reset-names = "mcu_rst", "hold_boot";
750 * - using SMC call (deprecated): use SMC reset interface
751 * The DT "reset-mames" property is optional, "st,syscfg-tz" is required
752 * - default(no SCMI, no SMC): the hold boot is managed as a syscon register
753 * The DT "reset-mames" property is optional, "st,syscfg-holdboot" is required
756 ddata->hold_boot_rst = devm_reset_control_get_optional(dev, "hold_boot");
757 if (IS_ERR(ddata->hold_boot_rst))
758 return dev_err_probe(dev, PTR_ERR(ddata->hold_boot_rst),
759 "failed to get hold_boot reset\n");
761 if (!ddata->hold_boot_rst && IS_ENABLED(CONFIG_HAVE_ARM_SMCCC)) {
762 /* Manage the MCU_BOOT using SMC call */
763 err = stm32_rproc_get_syscon(np, "st,syscfg-tz", &tz);
765 err = regmap_read(tz.map, tz.reg, &tzen);
767 dev_err(dev, "failed to read tzen\n");
770 ddata->hold_boot_smc = tzen & tz.mask;
774 if (!ddata->hold_boot_rst && !ddata->hold_boot_smc) {
775 /* Default: hold boot manage it through the syscon controller */
776 err = stm32_rproc_get_syscon(np, "st,syscfg-holdboot",
779 dev_err(dev, "failed to get hold boot\n");
784 err = stm32_rproc_get_syscon(np, "st,syscfg-pdds", &ddata->pdds);
786 dev_info(dev, "failed to get pdds\n");
788 *auto_boot = of_property_read_bool(np, "st,auto-boot");
791 * See if we can check the M4 status, i.e if it was started
792 * from the boot loader or not.
794 err = stm32_rproc_get_syscon(np, "st,syscfg-m4-state",
798 ddata->m4_state.map = NULL;
799 /* no coprocessor state syscon (optional) */
800 dev_warn(dev, "m4 state not supported\n");
802 /* no need to go further */
806 /* See if we can get the resource table */
807 err = stm32_rproc_get_syscon(np, "st,syscfg-rsc-tbl",
810 /* no rsc table syscon (optional) */
811 dev_warn(dev, "rsc tbl syscon not supported\n");
817 static int stm32_rproc_get_m4_status(struct stm32_rproc *ddata,
820 /* See stm32_rproc_parse_dt() */
821 if (!ddata->m4_state.map) {
823 * We couldn't get the coprocessor's state, assume
826 *state = M4_STATE_OFF;
830 return regmap_read(ddata->m4_state.map, ddata->m4_state.reg, state);
833 static int stm32_rproc_probe(struct platform_device *pdev)
835 struct device *dev = &pdev->dev;
836 struct stm32_rproc *ddata;
837 struct device_node *np = dev->of_node;
842 ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32));
846 rproc = rproc_alloc(dev, np->name, &st_rproc_ops, NULL, sizeof(*ddata));
852 rproc_coredump_set_elf_info(rproc, ELFCLASS32, EM_NONE);
854 ret = stm32_rproc_parse_dt(pdev, ddata, &rproc->auto_boot);
858 ret = stm32_rproc_of_memory_translations(pdev, ddata);
862 ret = stm32_rproc_get_m4_status(ddata, &state);
866 if (state == M4_STATE_CRUN)
867 rproc->state = RPROC_DETACHED;
869 rproc->has_iommu = false;
870 ddata->workqueue = create_workqueue(dev_name(dev));
871 if (!ddata->workqueue) {
872 dev_err(dev, "cannot create workqueue\n");
877 platform_set_drvdata(pdev, rproc);
879 ret = stm32_rproc_request_mbox(rproc);
883 ret = rproc_add(rproc);
890 stm32_rproc_free_mbox(rproc);
892 destroy_workqueue(ddata->workqueue);
894 rproc_resource_cleanup(rproc);
896 if (device_may_wakeup(dev)) {
897 dev_pm_clear_wake_irq(dev);
898 device_init_wakeup(dev, false);
904 static void stm32_rproc_remove(struct platform_device *pdev)
906 struct rproc *rproc = platform_get_drvdata(pdev);
907 struct stm32_rproc *ddata = rproc->priv;
908 struct device *dev = &pdev->dev;
910 if (atomic_read(&rproc->power) > 0)
911 rproc_shutdown(rproc);
914 stm32_rproc_free_mbox(rproc);
915 destroy_workqueue(ddata->workqueue);
917 if (device_may_wakeup(dev)) {
918 dev_pm_clear_wake_irq(dev);
919 device_init_wakeup(dev, false);
924 static int stm32_rproc_suspend(struct device *dev)
926 struct rproc *rproc = dev_get_drvdata(dev);
927 struct stm32_rproc *ddata = rproc->priv;
929 if (device_may_wakeup(dev))
930 return enable_irq_wake(ddata->wdg_irq);
935 static int stm32_rproc_resume(struct device *dev)
937 struct rproc *rproc = dev_get_drvdata(dev);
938 struct stm32_rproc *ddata = rproc->priv;
940 if (device_may_wakeup(dev))
941 return disable_irq_wake(ddata->wdg_irq);
946 static DEFINE_SIMPLE_DEV_PM_OPS(stm32_rproc_pm_ops,
947 stm32_rproc_suspend, stm32_rproc_resume);
949 static struct platform_driver stm32_rproc_driver = {
950 .probe = stm32_rproc_probe,
951 .remove_new = stm32_rproc_remove,
953 .name = "stm32-rproc",
954 .pm = pm_ptr(&stm32_rproc_pm_ops),
955 .of_match_table = stm32_rproc_match,
958 module_platform_driver(stm32_rproc_driver);
960 MODULE_DESCRIPTION("STM32 Remote Processor Control Driver");
961 MODULE_AUTHOR("Ludovic Barre <ludovic.barre@st.com>");
962 MODULE_AUTHOR("Fabien Dessenne <fabien.dessenne@st.com>");
963 MODULE_LICENSE("GPL v2");