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>
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, bool *is_iomem)
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;
166 rproc->sysfs_read_only = true;
168 wkupm3 = rproc->priv;
169 wkupm3->rproc = rproc;
172 wkupm3->rsts = devm_reset_control_get_optional_shared(dev, "rstctrl");
173 if (IS_ERR(wkupm3->rsts))
174 return PTR_ERR(wkupm3->rsts);
176 if (!(pdata && pdata->deassert_reset && pdata->assert_reset &&
177 pdata->reset_name)) {
178 dev_err(dev, "Platform data missing!\n");
184 for (i = 0; i < ARRAY_SIZE(mem_names); i++) {
185 res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
187 wkupm3->mem[i].cpu_addr = devm_ioremap_resource(dev, res);
188 if (IS_ERR(wkupm3->mem[i].cpu_addr)) {
189 dev_err(&pdev->dev, "devm_ioremap_resource failed for resource %d\n",
191 ret = PTR_ERR(wkupm3->mem[i].cpu_addr);
194 wkupm3->mem[i].bus_addr = res->start;
195 wkupm3->mem[i].size = resource_size(res);
196 addrp = of_get_address(dev->of_node, i, &size, NULL);
198 * The wkupm3 has umem at address 0 in its view, so the device
199 * addresses for each memory region is computed as a relative
200 * offset of the bus address for umem, and therefore needs to be
203 if (!strcmp(mem_names[i], "umem"))
204 l4_offset = be32_to_cpu(*addrp);
205 wkupm3->mem[i].dev_addr = be32_to_cpu(*addrp) - l4_offset;
208 dev_set_drvdata(dev, rproc);
210 ret = rproc_add(rproc);
212 dev_err(dev, "rproc_add failed\n");
221 pm_runtime_put_noidle(dev);
222 pm_runtime_disable(dev);
226 static void wkup_m3_rproc_remove(struct platform_device *pdev)
228 struct rproc *rproc = platform_get_drvdata(pdev);
232 pm_runtime_put_sync(&pdev->dev);
233 pm_runtime_disable(&pdev->dev);
237 static int wkup_m3_rpm_suspend(struct device *dev)
242 static int wkup_m3_rpm_resume(struct device *dev)
248 static const struct dev_pm_ops wkup_m3_rproc_pm_ops = {
249 SET_RUNTIME_PM_OPS(wkup_m3_rpm_suspend, wkup_m3_rpm_resume, NULL)
252 static struct platform_driver wkup_m3_rproc_driver = {
253 .probe = wkup_m3_rproc_probe,
254 .remove_new = wkup_m3_rproc_remove,
256 .name = "wkup_m3_rproc",
257 .of_match_table = wkup_m3_rproc_of_match,
258 .pm = &wkup_m3_rproc_pm_ops,
262 module_platform_driver(wkup_m3_rproc_driver);
264 MODULE_LICENSE("GPL v2");
265 MODULE_DESCRIPTION("TI Wakeup M3 remote processor control driver");
266 MODULE_AUTHOR("Dave Gerlach <d-gerlach@ti.com>");