x86/speculation/mds: Fix documentation typo
[linux/fpc-iii.git] / drivers / hwtracing / coresight / coresight-replicator.c
blob3756e71cb8f56d604097d6ddfdfac9e9bbf3aebf
1 /* Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
3 * Description: CoreSight Replicator driver
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 and
7 * only version 2 as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
15 #include <linux/kernel.h>
16 #include <linux/device.h>
17 #include <linux/platform_device.h>
18 #include <linux/io.h>
19 #include <linux/err.h>
20 #include <linux/slab.h>
21 #include <linux/pm_runtime.h>
22 #include <linux/clk.h>
23 #include <linux/of.h>
24 #include <linux/coresight.h>
26 #include "coresight-priv.h"
28 /**
29 * struct replicator_drvdata - specifics associated to a replicator component
30 * @dev: the device entity associated with this component
31 * @atclk: optional clock for the core parts of the replicator.
32 * @csdev: component vitals needed by the framework
34 struct replicator_drvdata {
35 struct device *dev;
36 struct clk *atclk;
37 struct coresight_device *csdev;
40 static int replicator_enable(struct coresight_device *csdev, int inport,
41 int outport)
43 struct replicator_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
45 dev_info(drvdata->dev, "REPLICATOR enabled\n");
46 return 0;
49 static void replicator_disable(struct coresight_device *csdev, int inport,
50 int outport)
52 struct replicator_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
54 dev_info(drvdata->dev, "REPLICATOR disabled\n");
57 static const struct coresight_ops_link replicator_link_ops = {
58 .enable = replicator_enable,
59 .disable = replicator_disable,
62 static const struct coresight_ops replicator_cs_ops = {
63 .link_ops = &replicator_link_ops,
66 static int replicator_probe(struct platform_device *pdev)
68 int ret;
69 struct device *dev = &pdev->dev;
70 struct coresight_platform_data *pdata = NULL;
71 struct replicator_drvdata *drvdata;
72 struct coresight_desc desc = { 0 };
73 struct device_node *np = pdev->dev.of_node;
75 if (np) {
76 pdata = of_get_coresight_platform_data(dev, np);
77 if (IS_ERR(pdata))
78 return PTR_ERR(pdata);
79 pdev->dev.platform_data = pdata;
82 drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
83 if (!drvdata)
84 return -ENOMEM;
86 drvdata->dev = &pdev->dev;
87 drvdata->atclk = devm_clk_get(&pdev->dev, "atclk"); /* optional */
88 if (!IS_ERR(drvdata->atclk)) {
89 ret = clk_prepare_enable(drvdata->atclk);
90 if (ret)
91 return ret;
93 pm_runtime_get_noresume(&pdev->dev);
94 pm_runtime_set_active(&pdev->dev);
95 pm_runtime_enable(&pdev->dev);
96 platform_set_drvdata(pdev, drvdata);
98 desc.type = CORESIGHT_DEV_TYPE_LINK;
99 desc.subtype.link_subtype = CORESIGHT_DEV_SUBTYPE_LINK_SPLIT;
100 desc.ops = &replicator_cs_ops;
101 desc.pdata = pdev->dev.platform_data;
102 desc.dev = &pdev->dev;
103 drvdata->csdev = coresight_register(&desc);
104 if (IS_ERR(drvdata->csdev)) {
105 ret = PTR_ERR(drvdata->csdev);
106 goto out_disable_pm;
109 pm_runtime_put(&pdev->dev);
111 return 0;
113 out_disable_pm:
114 if (!IS_ERR(drvdata->atclk))
115 clk_disable_unprepare(drvdata->atclk);
116 pm_runtime_put_noidle(&pdev->dev);
117 pm_runtime_disable(&pdev->dev);
119 return ret;
122 #ifdef CONFIG_PM
123 static int replicator_runtime_suspend(struct device *dev)
125 struct replicator_drvdata *drvdata = dev_get_drvdata(dev);
127 if (drvdata && !IS_ERR(drvdata->atclk))
128 clk_disable_unprepare(drvdata->atclk);
130 return 0;
133 static int replicator_runtime_resume(struct device *dev)
135 struct replicator_drvdata *drvdata = dev_get_drvdata(dev);
137 if (drvdata && !IS_ERR(drvdata->atclk))
138 clk_prepare_enable(drvdata->atclk);
140 return 0;
142 #endif
144 static const struct dev_pm_ops replicator_dev_pm_ops = {
145 SET_RUNTIME_PM_OPS(replicator_runtime_suspend,
146 replicator_runtime_resume, NULL)
149 static const struct of_device_id replicator_match[] = {
150 {.compatible = "arm,coresight-replicator"},
154 static struct platform_driver replicator_driver = {
155 .probe = replicator_probe,
156 .driver = {
157 .name = "coresight-replicator",
158 .of_match_table = replicator_match,
159 .pm = &replicator_dev_pm_ops,
160 .suppress_bind_attrs = true,
163 builtin_platform_driver(replicator_driver);