1 // SPDX-License-Identifier: GPL-2.0-only
3 * TI AMx3 Wakeup M3 Remote Processor driver
5 * Copyright (C) 2014-2015 Texas Instruments, Inc.
7 * Dave Gerlach <d-gerlach@ti.com>
8 * Suman Anna <s-anna@ti.com>
11 #include <linux/err.h>
12 #include <linux/interrupt.h>
13 #include <linux/kernel.h>
14 #include <linux/module.h>
15 #include <linux/of_device.h>
16 #include <linux/of_address.h>
17 #include <linux/platform_device.h>
18 #include <linux/pm_runtime.h>
19 #include <linux/remoteproc.h>
20 #include <linux/reset.h>
22 #include <linux/platform_data/wkup_m3.h>
24 #include "remoteproc_internal.h"
26 #define WKUPM3_MEM_MAX 2
29 * struct wkup_m3_mem - WkupM3 internal memory structure
30 * @cpu_addr: MPU virtual address of the memory region
31 * @bus_addr: Bus address used to access the memory region
32 * @dev_addr: Device address from Wakeup M3 view
33 * @size: Size of the memory region
36 void __iomem
*cpu_addr
;
43 * struct wkup_m3_rproc - WkupM3 remote processor state
44 * @rproc: rproc handle
45 * @pdev: pointer to platform device
46 * @mem: WkupM3 memory information
47 * @rsts: reset control
49 struct wkup_m3_rproc
{
51 struct platform_device
*pdev
;
52 struct wkup_m3_mem mem
[WKUPM3_MEM_MAX
];
53 struct reset_control
*rsts
;
56 static int wkup_m3_rproc_start(struct rproc
*rproc
)
58 struct wkup_m3_rproc
*wkupm3
= rproc
->priv
;
59 struct platform_device
*pdev
= wkupm3
->pdev
;
60 struct device
*dev
= &pdev
->dev
;
61 struct wkup_m3_platform_data
*pdata
= dev_get_platdata(dev
);
64 error
= reset_control_deassert(wkupm3
->rsts
);
66 if (!wkupm3
->rsts
&& pdata
->deassert_reset(pdev
, pdata
->reset_name
)) {
67 dev_err(dev
, "Unable to reset wkup_m3!\n");
74 static int wkup_m3_rproc_stop(struct rproc
*rproc
)
76 struct wkup_m3_rproc
*wkupm3
= rproc
->priv
;
77 struct platform_device
*pdev
= wkupm3
->pdev
;
78 struct device
*dev
= &pdev
->dev
;
79 struct wkup_m3_platform_data
*pdata
= dev_get_platdata(dev
);
82 error
= reset_control_assert(wkupm3
->rsts
);
84 if (!wkupm3
->rsts
&& pdata
->assert_reset(pdev
, pdata
->reset_name
)) {
85 dev_err(dev
, "Unable to assert reset of wkup_m3!\n");
92 static void *wkup_m3_rproc_da_to_va(struct rproc
*rproc
, u64 da
, size_t len
)
94 struct wkup_m3_rproc
*wkupm3
= rproc
->priv
;
102 for (i
= 0; i
< WKUPM3_MEM_MAX
; i
++) {
103 if (da
>= wkupm3
->mem
[i
].dev_addr
&& da
+ len
<=
104 wkupm3
->mem
[i
].dev_addr
+ wkupm3
->mem
[i
].size
) {
105 offset
= da
- wkupm3
->mem
[i
].dev_addr
;
106 /* __force to make sparse happy with type conversion */
107 va
= (__force
void *)(wkupm3
->mem
[i
].cpu_addr
+ offset
);
115 static const struct rproc_ops wkup_m3_rproc_ops
= {
116 .start
= wkup_m3_rproc_start
,
117 .stop
= wkup_m3_rproc_stop
,
118 .da_to_va
= wkup_m3_rproc_da_to_va
,
121 static const struct of_device_id wkup_m3_rproc_of_match
[] = {
122 { .compatible
= "ti,am3352-wkup-m3", },
123 { .compatible
= "ti,am4372-wkup-m3", },
126 MODULE_DEVICE_TABLE(of
, wkup_m3_rproc_of_match
);
128 static int wkup_m3_rproc_probe(struct platform_device
*pdev
)
130 struct device
*dev
= &pdev
->dev
;
131 struct wkup_m3_platform_data
*pdata
= dev
->platform_data
;
132 /* umem always needs to be processed first */
133 const char *mem_names
[WKUPM3_MEM_MAX
] = { "umem", "dmem" };
134 struct wkup_m3_rproc
*wkupm3
;
137 struct resource
*res
;
144 ret
= of_property_read_string(dev
->of_node
, "ti,pm-firmware",
147 dev_err(dev
, "No firmware filename given\n");
151 pm_runtime_enable(&pdev
->dev
);
152 ret
= pm_runtime_get_sync(&pdev
->dev
);
154 dev_err(&pdev
->dev
, "pm_runtime_get_sync() failed\n");
158 rproc
= rproc_alloc(dev
, "wkup_m3", &wkup_m3_rproc_ops
,
159 fw_name
, sizeof(*wkupm3
));
165 rproc
->auto_boot
= false;
167 wkupm3
= rproc
->priv
;
168 wkupm3
->rproc
= rproc
;
171 wkupm3
->rsts
= devm_reset_control_get_optional_shared(dev
, "rstctrl");
172 if (IS_ERR(wkupm3
->rsts
))
173 return PTR_ERR(wkupm3
->rsts
);
175 if (!(pdata
&& pdata
->deassert_reset
&& pdata
->assert_reset
&&
176 pdata
->reset_name
)) {
177 dev_err(dev
, "Platform data missing!\n");
183 for (i
= 0; i
< ARRAY_SIZE(mem_names
); i
++) {
184 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
,
186 wkupm3
->mem
[i
].cpu_addr
= devm_ioremap_resource(dev
, res
);
187 if (IS_ERR(wkupm3
->mem
[i
].cpu_addr
)) {
188 dev_err(&pdev
->dev
, "devm_ioremap_resource failed for resource %d\n",
190 ret
= PTR_ERR(wkupm3
->mem
[i
].cpu_addr
);
193 wkupm3
->mem
[i
].bus_addr
= res
->start
;
194 wkupm3
->mem
[i
].size
= resource_size(res
);
195 addrp
= of_get_address(dev
->of_node
, i
, &size
, NULL
);
197 * The wkupm3 has umem at address 0 in its view, so the device
198 * addresses for each memory region is computed as a relative
199 * offset of the bus address for umem, and therefore needs to be
202 if (!strcmp(mem_names
[i
], "umem"))
203 l4_offset
= be32_to_cpu(*addrp
);
204 wkupm3
->mem
[i
].dev_addr
= be32_to_cpu(*addrp
) - l4_offset
;
207 dev_set_drvdata(dev
, rproc
);
209 ret
= rproc_add(rproc
);
211 dev_err(dev
, "rproc_add failed\n");
220 pm_runtime_put_noidle(dev
);
221 pm_runtime_disable(dev
);
225 static int wkup_m3_rproc_remove(struct platform_device
*pdev
)
227 struct rproc
*rproc
= platform_get_drvdata(pdev
);
231 pm_runtime_put_sync(&pdev
->dev
);
232 pm_runtime_disable(&pdev
->dev
);
238 static int wkup_m3_rpm_suspend(struct device
*dev
)
243 static int wkup_m3_rpm_resume(struct device
*dev
)
249 static const struct dev_pm_ops wkup_m3_rproc_pm_ops
= {
250 SET_RUNTIME_PM_OPS(wkup_m3_rpm_suspend
, wkup_m3_rpm_resume
, NULL
)
253 static struct platform_driver wkup_m3_rproc_driver
= {
254 .probe
= wkup_m3_rproc_probe
,
255 .remove
= wkup_m3_rproc_remove
,
257 .name
= "wkup_m3_rproc",
258 .of_match_table
= wkup_m3_rproc_of_match
,
259 .pm
= &wkup_m3_rproc_pm_ops
,
263 module_platform_driver(wkup_m3_rproc_driver
);
265 MODULE_LICENSE("GPL v2");
266 MODULE_DESCRIPTION("TI Wakeup M3 remote processor control driver");
267 MODULE_AUTHOR("Dave Gerlach <d-gerlach@ti.com>");