1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#include <linux/io.h>
20#include <linux/module.h>
21#include <linux/platform_device.h>
22#include <linux/err.h>
23#include <linux/pm_runtime.h>
24#include <linux/of.h>
25#include <linux/of_platform.h>
26
27#define OCP2SCP_TIMING 0x18
28#define SYNC2_MASK 0xf
29
30static int ocp2scp_remove_devices(struct device *dev, void *c)
31{
32 struct platform_device *pdev = to_platform_device(dev);
33
34 platform_device_unregister(pdev);
35
36 return 0;
37}
38
39static int omap_ocp2scp_probe(struct platform_device *pdev)
40{
41 int ret;
42 u32 reg;
43 void __iomem *regs;
44 struct resource *res;
45 struct device_node *np = pdev->dev.of_node;
46
47 if (np) {
48 ret = of_platform_populate(np, NULL, NULL, &pdev->dev);
49 if (ret) {
50 dev_err(&pdev->dev,
51 "failed to add resources for ocp2scp child\n");
52 goto err0;
53 }
54 }
55
56 pm_runtime_enable(&pdev->dev);
57
58
59
60
61
62
63
64
65
66
67
68
69
70 if (!of_device_is_compatible(np, "ti,am437x-ocp2scp")) {
71 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
72 regs = devm_ioremap_resource(&pdev->dev, res);
73 if (IS_ERR(regs))
74 goto err0;
75
76 pm_runtime_get_sync(&pdev->dev);
77 reg = readl_relaxed(regs + OCP2SCP_TIMING);
78 reg &= ~(SYNC2_MASK);
79 reg |= 0x6;
80 writel_relaxed(reg, regs + OCP2SCP_TIMING);
81 pm_runtime_put_sync(&pdev->dev);
82 }
83
84 return 0;
85
86err0:
87 device_for_each_child(&pdev->dev, NULL, ocp2scp_remove_devices);
88
89 return ret;
90}
91
92static int omap_ocp2scp_remove(struct platform_device *pdev)
93{
94 pm_runtime_disable(&pdev->dev);
95 device_for_each_child(&pdev->dev, NULL, ocp2scp_remove_devices);
96
97 return 0;
98}
99
100#ifdef CONFIG_OF
101static const struct of_device_id omap_ocp2scp_id_table[] = {
102 { .compatible = "ti,omap-ocp2scp" },
103 { .compatible = "ti,am437x-ocp2scp" },
104 {}
105};
106MODULE_DEVICE_TABLE(of, omap_ocp2scp_id_table);
107#endif
108
109static struct platform_driver omap_ocp2scp_driver = {
110 .probe = omap_ocp2scp_probe,
111 .remove = omap_ocp2scp_remove,
112 .driver = {
113 .name = "omap-ocp2scp",
114 .of_match_table = of_match_ptr(omap_ocp2scp_id_table),
115 },
116};
117
118module_platform_driver(omap_ocp2scp_driver);
119
120MODULE_ALIAS("platform:omap-ocp2scp");
121MODULE_AUTHOR("Texas Instruments Inc.");
122MODULE_DESCRIPTION("OMAP OCP2SCP driver");
123MODULE_LICENSE("GPL v2");
124