1 /* Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
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.
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.
13 #include <linux/kernel.h>
14 #include <linux/module.h>
15 #include <linux/device.h>
16 #include <linux/platform_device.h>
18 #include <linux/err.h>
19 #include <linux/slab.h>
20 #include <linux/pm_runtime.h>
21 #include <linux/clk.h>
23 #include <linux/coresight.h>
25 #include "coresight-priv.h"
28 * struct replicator_drvdata - specifics associated to a replicator component
29 * @dev: the device entity associated with this component
30 * @atclk: optional clock for the core parts of the replicator.
31 * @csdev: component vitals needed by the framework
33 struct replicator_drvdata {
36 struct coresight_device *csdev;
39 static int replicator_enable(struct coresight_device *csdev, int inport,
42 struct replicator_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
44 pm_runtime_get_sync(drvdata->dev);
45 dev_info(drvdata->dev, "REPLICATOR enabled\n");
49 static void replicator_disable(struct coresight_device *csdev, int inport,
52 struct replicator_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
54 pm_runtime_put(drvdata->dev);
55 dev_info(drvdata->dev, "REPLICATOR disabled\n");
58 static const struct coresight_ops_link replicator_link_ops = {
59 .enable = replicator_enable,
60 .disable = replicator_disable,
63 static const struct coresight_ops replicator_cs_ops = {
64 .link_ops = &replicator_link_ops,
67 static int replicator_probe(struct platform_device *pdev)
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;
77 pdata = of_get_coresight_platform_data(dev, np);
79 return PTR_ERR(pdata);
80 pdev->dev.platform_data = pdata;
83 drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
87 drvdata->dev = &pdev->dev;
88 drvdata->atclk = devm_clk_get(&pdev->dev, "atclk"); /* optional */
89 if (!IS_ERR(drvdata->atclk)) {
90 ret = clk_prepare_enable(drvdata->atclk);
94 pm_runtime_get_noresume(&pdev->dev);
95 pm_runtime_set_active(&pdev->dev);
96 pm_runtime_enable(&pdev->dev);
97 platform_set_drvdata(pdev, drvdata);
99 desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL);
105 desc->type = CORESIGHT_DEV_TYPE_LINK;
106 desc->subtype.link_subtype = CORESIGHT_DEV_SUBTYPE_LINK_SPLIT;
107 desc->ops = &replicator_cs_ops;
108 desc->pdata = pdev->dev.platform_data;
109 desc->dev = &pdev->dev;
110 drvdata->csdev = coresight_register(desc);
111 if (IS_ERR(drvdata->csdev)) {
112 ret = PTR_ERR(drvdata->csdev);
116 pm_runtime_put(&pdev->dev);
118 dev_info(dev, "REPLICATOR initialized\n");
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);
131 static int replicator_runtime_suspend(struct device *dev)
133 struct replicator_drvdata *drvdata = dev_get_drvdata(dev);
135 if (drvdata && !IS_ERR(drvdata->atclk))
136 clk_disable_unprepare(drvdata->atclk);
141 static int replicator_runtime_resume(struct device *dev)
143 struct replicator_drvdata *drvdata = dev_get_drvdata(dev);
145 if (drvdata && !IS_ERR(drvdata->atclk))
146 clk_prepare_enable(drvdata->atclk);
152 static const struct dev_pm_ops replicator_dev_pm_ops = {
153 SET_RUNTIME_PM_OPS(replicator_runtime_suspend,
154 replicator_runtime_resume, NULL)
157 static const struct of_device_id replicator_match[] = {
158 {.compatible = "arm,coresight-replicator"},
162 static struct platform_driver replicator_driver = {
163 .probe = replicator_probe,
165 .name = "coresight-replicator",
166 .of_match_table = replicator_match,
167 .pm = &replicator_dev_pm_ops,
168 .suppress_bind_attrs = true,
172 builtin_platform_driver(replicator_driver);
174 MODULE_LICENSE("GPL v2");
175 MODULE_DESCRIPTION("CoreSight Replicator driver");