Commit | Line | Data |
---|---|---|
ceacc1d9 PP |
1 | /* Copyright (c) 2011-2012, The Linux Foundation. All rights reserved. |
2 | * | |
3 | * This program is free software; you can redistribute it and/or modify | |
4 | * it under the terms of the GNU General Public License version 2 and | |
5 | * only version 2 as published by the Free Software Foundation. | |
6 | * | |
7 | * This program is distributed in the hope that it will be useful, | |
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
10 | * GNU General Public License for more details. | |
11 | */ | |
12 | ||
13 | #include <linux/kernel.h> | |
14 | #include <linux/module.h> | |
ceacc1d9 PP |
15 | #include <linux/device.h> |
16 | #include <linux/platform_device.h> | |
17 | #include <linux/io.h> | |
18 | #include <linux/err.h> | |
19 | #include <linux/slab.h> | |
9875cd9c | 20 | #include <linux/pm_runtime.h> |
ceacc1d9 PP |
21 | #include <linux/clk.h> |
22 | #include <linux/of.h> | |
23 | #include <linux/coresight.h> | |
24 | ||
25 | #include "coresight-priv.h" | |
26 | ||
27 | /** | |
28 | * struct replicator_drvdata - specifics associated to a replicator component | |
29 | * @dev: the device entity associated with this component | |
9875cd9c | 30 | * @atclk: optional clock for the core parts of the replicator. |
ceacc1d9 PP |
31 | * @csdev: component vitals needed by the framework |
32 | */ | |
33 | struct replicator_drvdata { | |
34 | struct device *dev; | |
9875cd9c | 35 | struct clk *atclk; |
ceacc1d9 PP |
36 | struct coresight_device *csdev; |
37 | }; | |
38 | ||
39 | static int replicator_enable(struct coresight_device *csdev, int inport, | |
40 | int outport) | |
41 | { | |
42 | struct replicator_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); | |
43 | ||
9875cd9c | 44 | pm_runtime_get_sync(drvdata->dev); |
ceacc1d9 PP |
45 | dev_info(drvdata->dev, "REPLICATOR enabled\n"); |
46 | return 0; | |
47 | } | |
48 | ||
49 | static void replicator_disable(struct coresight_device *csdev, int inport, | |
50 | int outport) | |
51 | { | |
52 | struct replicator_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); | |
53 | ||
9875cd9c | 54 | pm_runtime_put(drvdata->dev); |
ceacc1d9 PP |
55 | dev_info(drvdata->dev, "REPLICATOR disabled\n"); |
56 | } | |
57 | ||
58 | static const struct coresight_ops_link replicator_link_ops = { | |
59 | .enable = replicator_enable, | |
60 | .disable = replicator_disable, | |
61 | }; | |
62 | ||
63 | static const struct coresight_ops replicator_cs_ops = { | |
64 | .link_ops = &replicator_link_ops, | |
65 | }; | |
66 | ||
67 | static int replicator_probe(struct platform_device *pdev) | |
68 | { | |
9875cd9c | 69 | int ret; |
ceacc1d9 PP |
70 | struct device *dev = &pdev->dev; |
71 | struct coresight_platform_data *pdata = NULL; | |
72 | struct replicator_drvdata *drvdata; | |
73 | struct coresight_desc *desc; | |
74 | struct device_node *np = pdev->dev.of_node; | |
75 | ||
76 | if (np) { | |
77 | pdata = of_get_coresight_platform_data(dev, np); | |
78 | if (IS_ERR(pdata)) | |
79 | return PTR_ERR(pdata); | |
80 | pdev->dev.platform_data = pdata; | |
81 | } | |
82 | ||
83 | drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); | |
84 | if (!drvdata) | |
85 | return -ENOMEM; | |
86 | ||
87 | drvdata->dev = &pdev->dev; | |
9875cd9c LW |
88 | drvdata->atclk = devm_clk_get(&pdev->dev, "atclk"); /* optional */ |
89 | if (!IS_ERR(drvdata->atclk)) { | |
90 | ret = clk_prepare_enable(drvdata->atclk); | |
91 | if (ret) | |
92 | return ret; | |
93 | } | |
94 | pm_runtime_get_noresume(&pdev->dev); | |
95 | pm_runtime_set_active(&pdev->dev); | |
96 | pm_runtime_enable(&pdev->dev); | |
ceacc1d9 PP |
97 | platform_set_drvdata(pdev, drvdata); |
98 | ||
99 | desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL); | |
9875cd9c LW |
100 | if (!desc) { |
101 | ret = -ENOMEM; | |
102 | goto out_disable_pm; | |
103 | } | |
ceacc1d9 PP |
104 | |
105 | desc->type = CORESIGHT_DEV_TYPE_LINK; | |
410d841a | 106 | desc->subtype.link_subtype = CORESIGHT_DEV_SUBTYPE_LINK_SPLIT; |
ceacc1d9 PP |
107 | desc->ops = &replicator_cs_ops; |
108 | desc->pdata = pdev->dev.platform_data; | |
109 | desc->dev = &pdev->dev; | |
110 | drvdata->csdev = coresight_register(desc); | |
9875cd9c LW |
111 | if (IS_ERR(drvdata->csdev)) { |
112 | ret = PTR_ERR(drvdata->csdev); | |
113 | goto out_disable_pm; | |
114 | } | |
115 | ||
116 | pm_runtime_put(&pdev->dev); | |
ceacc1d9 PP |
117 | |
118 | dev_info(dev, "REPLICATOR initialized\n"); | |
119 | return 0; | |
9875cd9c LW |
120 | |
121 | out_disable_pm: | |
122 | if (!IS_ERR(drvdata->atclk)) | |
123 | clk_disable_unprepare(drvdata->atclk); | |
124 | pm_runtime_put_noidle(&pdev->dev); | |
125 | pm_runtime_disable(&pdev->dev); | |
126 | ||
127 | return ret; | |
ceacc1d9 PP |
128 | } |
129 | ||
130 | static int replicator_remove(struct platform_device *pdev) | |
131 | { | |
132 | struct replicator_drvdata *drvdata = platform_get_drvdata(pdev); | |
133 | ||
134 | coresight_unregister(drvdata->csdev); | |
9875cd9c LW |
135 | pm_runtime_get_sync(&pdev->dev); |
136 | if (!IS_ERR(drvdata->atclk)) | |
137 | clk_disable_unprepare(drvdata->atclk); | |
138 | pm_runtime_put_noidle(&pdev->dev); | |
139 | pm_runtime_disable(&pdev->dev); | |
140 | ||
141 | return 0; | |
142 | } | |
143 | ||
144 | #ifdef CONFIG_PM | |
145 | static int replicator_runtime_suspend(struct device *dev) | |
146 | { | |
147 | struct replicator_drvdata *drvdata = dev_get_drvdata(dev); | |
148 | ||
149 | if (drvdata && !IS_ERR(drvdata->atclk)) | |
150 | clk_disable_unprepare(drvdata->atclk); | |
151 | ||
ceacc1d9 PP |
152 | return 0; |
153 | } | |
154 | ||
9875cd9c LW |
155 | static int replicator_runtime_resume(struct device *dev) |
156 | { | |
157 | struct replicator_drvdata *drvdata = dev_get_drvdata(dev); | |
158 | ||
159 | if (drvdata && !IS_ERR(drvdata->atclk)) | |
160 | clk_prepare_enable(drvdata->atclk); | |
161 | ||
162 | return 0; | |
163 | } | |
164 | #endif | |
165 | ||
166 | static const struct dev_pm_ops replicator_dev_pm_ops = { | |
167 | SET_RUNTIME_PM_OPS(replicator_runtime_suspend, | |
168 | replicator_runtime_resume, NULL) | |
169 | }; | |
170 | ||
160b7daa | 171 | static const struct of_device_id replicator_match[] = { |
ceacc1d9 PP |
172 | {.compatible = "arm,coresight-replicator"}, |
173 | {} | |
174 | }; | |
175 | ||
176 | static struct platform_driver replicator_driver = { | |
177 | .probe = replicator_probe, | |
178 | .remove = replicator_remove, | |
179 | .driver = { | |
180 | .name = "coresight-replicator", | |
ceacc1d9 | 181 | .of_match_table = replicator_match, |
9875cd9c | 182 | .pm = &replicator_dev_pm_ops, |
ceacc1d9 PP |
183 | }, |
184 | }; | |
185 | ||
c35aaa13 | 186 | builtin_platform_driver(replicator_driver); |
ceacc1d9 PP |
187 | |
188 | MODULE_LICENSE("GPL v2"); | |
189 | MODULE_DESCRIPTION("CoreSight Replicator driver"); |