1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
5 * Description: CoreSight Replicator driver
8 #include <linux/kernel.h>
9 #include <linux/device.h>
10 #include <linux/platform_device.h>
12 #include <linux/err.h>
13 #include <linux/slab.h>
14 #include <linux/pm_runtime.h>
15 #include <linux/clk.h>
17 #include <linux/coresight.h>
19 #include "coresight-priv.h"
22 * struct replicator_drvdata - specifics associated to a replicator component
23 * @dev: the device entity associated with this component
24 * @atclk: optional clock for the core parts of the replicator.
25 * @csdev: component vitals needed by the framework
27 struct replicator_drvdata {
30 struct coresight_device *csdev;
33 static int replicator_enable(struct coresight_device *csdev, int inport,
36 struct replicator_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
38 dev_info(drvdata->dev, "REPLICATOR enabled\n");
42 static void replicator_disable(struct coresight_device *csdev, int inport,
45 struct replicator_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
47 dev_info(drvdata->dev, "REPLICATOR disabled\n");
50 static const struct coresight_ops_link replicator_link_ops = {
51 .enable = replicator_enable,
52 .disable = replicator_disable,
55 static const struct coresight_ops replicator_cs_ops = {
56 .link_ops = &replicator_link_ops,
59 static int replicator_probe(struct platform_device *pdev)
62 struct device *dev = &pdev->dev;
63 struct coresight_platform_data *pdata = NULL;
64 struct replicator_drvdata *drvdata;
65 struct coresight_desc desc = { 0 };
66 struct device_node *np = pdev->dev.of_node;
69 pdata = of_get_coresight_platform_data(dev, np);
71 return PTR_ERR(pdata);
72 pdev->dev.platform_data = pdata;
75 drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
79 drvdata->dev = &pdev->dev;
80 drvdata->atclk = devm_clk_get(&pdev->dev, "atclk"); /* optional */
81 if (!IS_ERR(drvdata->atclk)) {
82 ret = clk_prepare_enable(drvdata->atclk);
86 pm_runtime_get_noresume(&pdev->dev);
87 pm_runtime_set_active(&pdev->dev);
88 pm_runtime_enable(&pdev->dev);
89 platform_set_drvdata(pdev, drvdata);
91 desc.type = CORESIGHT_DEV_TYPE_LINK;
92 desc.subtype.link_subtype = CORESIGHT_DEV_SUBTYPE_LINK_SPLIT;
93 desc.ops = &replicator_cs_ops;
94 desc.pdata = pdev->dev.platform_data;
95 desc.dev = &pdev->dev;
96 drvdata->csdev = coresight_register(&desc);
97 if (IS_ERR(drvdata->csdev)) {
98 ret = PTR_ERR(drvdata->csdev);
102 pm_runtime_put(&pdev->dev);
107 if (!IS_ERR(drvdata->atclk))
108 clk_disable_unprepare(drvdata->atclk);
109 pm_runtime_put_noidle(&pdev->dev);
110 pm_runtime_disable(&pdev->dev);
116 static int replicator_runtime_suspend(struct device *dev)
118 struct replicator_drvdata *drvdata = dev_get_drvdata(dev);
120 if (drvdata && !IS_ERR(drvdata->atclk))
121 clk_disable_unprepare(drvdata->atclk);
126 static int replicator_runtime_resume(struct device *dev)
128 struct replicator_drvdata *drvdata = dev_get_drvdata(dev);
130 if (drvdata && !IS_ERR(drvdata->atclk))
131 clk_prepare_enable(drvdata->atclk);
137 static const struct dev_pm_ops replicator_dev_pm_ops = {
138 SET_RUNTIME_PM_OPS(replicator_runtime_suspend,
139 replicator_runtime_resume, NULL)
142 static const struct of_device_id replicator_match[] = {
143 {.compatible = "arm,coresight-replicator"},
147 static struct platform_driver replicator_driver = {
148 .probe = replicator_probe,
150 .name = "coresight-replicator",
151 .of_match_table = replicator_match,
152 .pm = &replicator_dev_pm_ops,
153 .suppress_bind_attrs = true,
156 builtin_platform_driver(replicator_driver);