1 /*
2 * omap-ocp2scp.c - transform ocp interface protocol to scp protocol
3 *
4 * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * Author: Kishon Vijay Abraham I <kishon@ti.com>
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
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
ocp2scp_remove_devices(struct device * dev,void * c)30 static 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
omap_ocp2scp_probe(struct platform_device * pdev)39 static 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 * As per AM572x TRM: http://www.ti.com/lit/ug/spruhz6/spruhz6.pdf
59 * under section 26.3.2.2, table 26-26 OCP2SCP TIMING Caution;
60 * As per OMAP4430 TRM: http://www.ti.com/lit/ug/swpu231ap/swpu231ap.pdf
61 * under section 23.12.6.2.2 , Table 23-1213 OCP2SCP TIMING Caution;
62 * As per OMAP4460 TRM: http://www.ti.com/lit/ug/swpu235ab/swpu235ab.pdf
63 * under section 23.12.6.2.2, Table 23-1213 OCP2SCP TIMING Caution;
64 * As per OMAP543x TRM http://www.ti.com/lit/pdf/swpu249
65 * under section 27.3.2.2, Table 27-27 OCP2SCP TIMING Caution;
66 *
67 * Read path of OCP2SCP is not working properly due to low reset value
68 * of SYNC2 parameter in OCP2SCP. Suggested reset value is 0x6 or more.
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 ret = PTR_ERR(regs);
75 goto err1;
76 }
77
78 pm_runtime_get_sync(&pdev->dev);
79 reg = readl_relaxed(regs + OCP2SCP_TIMING);
80 reg &= ~(SYNC2_MASK);
81 reg |= 0x6;
82 writel_relaxed(reg, regs + OCP2SCP_TIMING);
83 pm_runtime_put_sync(&pdev->dev);
84 }
85
86 return 0;
87
88 err1:
89 pm_runtime_disable(&pdev->dev);
90
91 err0:
92 device_for_each_child(&pdev->dev, NULL, ocp2scp_remove_devices);
93
94 return ret;
95 }
96
omap_ocp2scp_remove(struct platform_device * pdev)97 static int omap_ocp2scp_remove(struct platform_device *pdev)
98 {
99 pm_runtime_disable(&pdev->dev);
100 device_for_each_child(&pdev->dev, NULL, ocp2scp_remove_devices);
101
102 return 0;
103 }
104
105 #ifdef CONFIG_OF
106 static const struct of_device_id omap_ocp2scp_id_table[] = {
107 { .compatible = "ti,omap-ocp2scp" },
108 { .compatible = "ti,am437x-ocp2scp" },
109 {}
110 };
111 MODULE_DEVICE_TABLE(of, omap_ocp2scp_id_table);
112 #endif
113
114 static struct platform_driver omap_ocp2scp_driver = {
115 .probe = omap_ocp2scp_probe,
116 .remove = omap_ocp2scp_remove,
117 .driver = {
118 .name = "omap-ocp2scp",
119 .of_match_table = of_match_ptr(omap_ocp2scp_id_table),
120 },
121 };
122
123 module_platform_driver(omap_ocp2scp_driver);
124
125 MODULE_ALIAS("platform:omap-ocp2scp");
126 MODULE_AUTHOR("Texas Instruments Inc.");
127 MODULE_DESCRIPTION("OMAP OCP2SCP driver");
128 MODULE_LICENSE("GPL v2");
129