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>
21 #include <linux/platform_data/wkup_m3.h>
23 #include "remoteproc_internal.h"
25 #define WKUPM3_MEM_MAX 2
28 * struct wkup_m3_mem - WkupM3 internal memory structure
29 * @cpu_addr: MPU virtual address of the memory region
30 * @bus_addr: Bus address used to access the memory region
31 * @dev_addr: Device address from Wakeup M3 view
32 * @size: Size of the memory region
35 void __iomem
*cpu_addr
;
42 * struct wkup_m3_rproc - WkupM3 remote processor state
43 * @rproc: rproc handle
44 * @pdev: pointer to platform device
45 * @mem: WkupM3 memory information
47 struct wkup_m3_rproc
{
49 struct platform_device
*pdev
;
50 struct wkup_m3_mem mem
[WKUPM3_MEM_MAX
];
53 static int wkup_m3_rproc_start(struct rproc
*rproc
)
55 struct wkup_m3_rproc
*wkupm3
= rproc
->priv
;
56 struct platform_device
*pdev
= wkupm3
->pdev
;
57 struct device
*dev
= &pdev
->dev
;
58 struct wkup_m3_platform_data
*pdata
= dev_get_platdata(dev
);
60 if (pdata
->deassert_reset(pdev
, pdata
->reset_name
)) {
61 dev_err(dev
, "Unable to reset wkup_m3!\n");
68 static int wkup_m3_rproc_stop(struct rproc
*rproc
)
70 struct wkup_m3_rproc
*wkupm3
= rproc
->priv
;
71 struct platform_device
*pdev
= wkupm3
->pdev
;
72 struct device
*dev
= &pdev
->dev
;
73 struct wkup_m3_platform_data
*pdata
= dev_get_platdata(dev
);
75 if (pdata
->assert_reset(pdev
, pdata
->reset_name
)) {
76 dev_err(dev
, "Unable to assert reset of wkup_m3!\n");
83 static void *wkup_m3_rproc_da_to_va(struct rproc
*rproc
, u64 da
, size_t len
)
85 struct wkup_m3_rproc
*wkupm3
= rproc
->priv
;
93 for (i
= 0; i
< WKUPM3_MEM_MAX
; i
++) {
94 if (da
>= wkupm3
->mem
[i
].dev_addr
&& da
+ len
<=
95 wkupm3
->mem
[i
].dev_addr
+ wkupm3
->mem
[i
].size
) {
96 offset
= da
- wkupm3
->mem
[i
].dev_addr
;
97 /* __force to make sparse happy with type conversion */
98 va
= (__force
void *)(wkupm3
->mem
[i
].cpu_addr
+ offset
);
106 static const struct rproc_ops wkup_m3_rproc_ops
= {
107 .start
= wkup_m3_rproc_start
,
108 .stop
= wkup_m3_rproc_stop
,
109 .da_to_va
= wkup_m3_rproc_da_to_va
,
112 static const struct of_device_id wkup_m3_rproc_of_match
[] = {
113 { .compatible
= "ti,am3352-wkup-m3", },
114 { .compatible
= "ti,am4372-wkup-m3", },
117 MODULE_DEVICE_TABLE(of
, wkup_m3_rproc_of_match
);
119 static int wkup_m3_rproc_probe(struct platform_device
*pdev
)
121 struct device
*dev
= &pdev
->dev
;
122 struct wkup_m3_platform_data
*pdata
= dev
->platform_data
;
123 /* umem always needs to be processed first */
124 const char *mem_names
[WKUPM3_MEM_MAX
] = { "umem", "dmem" };
125 struct wkup_m3_rproc
*wkupm3
;
128 struct resource
*res
;
135 if (!(pdata
&& pdata
->deassert_reset
&& pdata
->assert_reset
&&
136 pdata
->reset_name
)) {
137 dev_err(dev
, "Platform data missing!\n");
141 ret
= of_property_read_string(dev
->of_node
, "ti,pm-firmware",
144 dev_err(dev
, "No firmware filename given\n");
148 pm_runtime_enable(&pdev
->dev
);
149 ret
= pm_runtime_get_sync(&pdev
->dev
);
151 dev_err(&pdev
->dev
, "pm_runtime_get_sync() failed\n");
155 rproc
= rproc_alloc(dev
, "wkup_m3", &wkup_m3_rproc_ops
,
156 fw_name
, sizeof(*wkupm3
));
162 rproc
->auto_boot
= false;
164 wkupm3
= rproc
->priv
;
165 wkupm3
->rproc
= rproc
;
168 for (i
= 0; i
< ARRAY_SIZE(mem_names
); i
++) {
169 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
,
171 wkupm3
->mem
[i
].cpu_addr
= devm_ioremap_resource(dev
, res
);
172 if (IS_ERR(wkupm3
->mem
[i
].cpu_addr
)) {
173 dev_err(&pdev
->dev
, "devm_ioremap_resource failed for resource %d\n",
175 ret
= PTR_ERR(wkupm3
->mem
[i
].cpu_addr
);
178 wkupm3
->mem
[i
].bus_addr
= res
->start
;
179 wkupm3
->mem
[i
].size
= resource_size(res
);
180 addrp
= of_get_address(dev
->of_node
, i
, &size
, NULL
);
182 * The wkupm3 has umem at address 0 in its view, so the device
183 * addresses for each memory region is computed as a relative
184 * offset of the bus address for umem, and therefore needs to be
187 if (!strcmp(mem_names
[i
], "umem"))
188 l4_offset
= be32_to_cpu(*addrp
);
189 wkupm3
->mem
[i
].dev_addr
= be32_to_cpu(*addrp
) - l4_offset
;
192 dev_set_drvdata(dev
, rproc
);
194 ret
= rproc_add(rproc
);
196 dev_err(dev
, "rproc_add failed\n");
205 pm_runtime_put_noidle(dev
);
206 pm_runtime_disable(dev
);
210 static int wkup_m3_rproc_remove(struct platform_device
*pdev
)
212 struct rproc
*rproc
= platform_get_drvdata(pdev
);
216 pm_runtime_put_sync(&pdev
->dev
);
217 pm_runtime_disable(&pdev
->dev
);
223 static int wkup_m3_rpm_suspend(struct device
*dev
)
228 static int wkup_m3_rpm_resume(struct device
*dev
)
234 static const struct dev_pm_ops wkup_m3_rproc_pm_ops
= {
235 SET_RUNTIME_PM_OPS(wkup_m3_rpm_suspend
, wkup_m3_rpm_resume
, NULL
)
238 static struct platform_driver wkup_m3_rproc_driver
= {
239 .probe
= wkup_m3_rproc_probe
,
240 .remove
= wkup_m3_rproc_remove
,
242 .name
= "wkup_m3_rproc",
243 .of_match_table
= wkup_m3_rproc_of_match
,
244 .pm
= &wkup_m3_rproc_pm_ops
,
248 module_platform_driver(wkup_m3_rproc_driver
);
250 MODULE_LICENSE("GPL v2");
251 MODULE_DESCRIPTION("TI Wakeup M3 remote processor control driver");
252 MODULE_AUTHOR("Dave Gerlach <d-gerlach@ti.com>");