Linux 4.1.16
[linux/fpc-iii.git] / drivers / hwtracing / coresight / coresight-replicator.c
blob75b9abd804e6bdf4d22d35943da29b7ecffbae91
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/init.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/clk.h>
22 #include <linux/of.h>
23 #include <linux/coresight.h>
25 #include "coresight-priv.h"
27 /**
28 * struct replicator_drvdata - specifics associated to a replicator component
29 * @dev: the device entity associated with this component
30 * @csdev: component vitals needed by the framework
32 struct replicator_drvdata {
33 struct device *dev;
34 struct coresight_device *csdev;
37 static int replicator_enable(struct coresight_device *csdev, int inport,
38 int outport)
40 struct replicator_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
42 dev_info(drvdata->dev, "REPLICATOR enabled\n");
43 return 0;
46 static void replicator_disable(struct coresight_device *csdev, int inport,
47 int outport)
49 struct replicator_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
51 dev_info(drvdata->dev, "REPLICATOR disabled\n");
54 static const struct coresight_ops_link replicator_link_ops = {
55 .enable = replicator_enable,
56 .disable = replicator_disable,
59 static const struct coresight_ops replicator_cs_ops = {
60 .link_ops = &replicator_link_ops,
63 static int replicator_probe(struct platform_device *pdev)
65 struct device *dev = &pdev->dev;
66 struct coresight_platform_data *pdata = NULL;
67 struct replicator_drvdata *drvdata;
68 struct coresight_desc *desc;
69 struct device_node *np = pdev->dev.of_node;
71 if (np) {
72 pdata = of_get_coresight_platform_data(dev, np);
73 if (IS_ERR(pdata))
74 return PTR_ERR(pdata);
75 pdev->dev.platform_data = pdata;
78 drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
79 if (!drvdata)
80 return -ENOMEM;
82 drvdata->dev = &pdev->dev;
83 platform_set_drvdata(pdev, drvdata);
85 desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL);
86 if (!desc)
87 return -ENOMEM;
89 desc->type = CORESIGHT_DEV_TYPE_LINK;
90 desc->subtype.link_subtype = CORESIGHT_DEV_SUBTYPE_LINK_SPLIT;
91 desc->ops = &replicator_cs_ops;
92 desc->pdata = pdev->dev.platform_data;
93 desc->dev = &pdev->dev;
94 drvdata->csdev = coresight_register(desc);
95 if (IS_ERR(drvdata->csdev))
96 return PTR_ERR(drvdata->csdev);
98 dev_info(dev, "REPLICATOR initialized\n");
99 return 0;
102 static int replicator_remove(struct platform_device *pdev)
104 struct replicator_drvdata *drvdata = platform_get_drvdata(pdev);
106 coresight_unregister(drvdata->csdev);
107 return 0;
110 static const struct of_device_id replicator_match[] = {
111 {.compatible = "arm,coresight-replicator"},
115 static struct platform_driver replicator_driver = {
116 .probe = replicator_probe,
117 .remove = replicator_remove,
118 .driver = {
119 .name = "coresight-replicator",
120 .of_match_table = replicator_match,
124 static int __init replicator_init(void)
126 return platform_driver_register(&replicator_driver);
128 module_init(replicator_init);
130 static void __exit replicator_exit(void)
132 platform_driver_unregister(&replicator_driver);
134 module_exit(replicator_exit);
136 MODULE_LICENSE("GPL v2");
137 MODULE_DESCRIPTION("CoreSight Replicator driver");