blob: 4c8075c29963d97a6cbcd95de64c5cb50bd20ae1 [file] [log] [blame]
Aparna Dasb84b3112013-07-06 09:40:33 -07001/* Copyright (c) 2013, 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>
15#include <linux/init.h>
16#include <linux/types.h>
17#include <linux/device.h>
18#include <linux/platform_device.h>
19#include <linux/io.h>
20#include <linux/err.h>
21#include <linux/sysfs.h>
22#include <linux/of_coresight.h>
23#include <linux/coresight.h>
24
25struct modem_etm_drvdata {
26 struct device *dev;
27 struct coresight_device *csdev;
28};
29
30static int modem_etm_enable(struct coresight_device *csdev)
31{
32 struct modem_etm_drvdata *drvdata =
33 dev_get_drvdata(csdev->dev.parent);
34
35 dev_info(drvdata->dev, "Modem ETM tracing enabled\n");
36 return 0;
37}
38
39
40static void modem_etm_disable(struct coresight_device *csdev)
41{
42 struct modem_etm_drvdata *drvdata =
43 dev_get_drvdata(csdev->dev.parent);
44
45 dev_info(drvdata->dev, "Modem ETM tracing disabled\n");
46}
47
48static const struct coresight_ops_source modem_etm_source_ops = {
49 .enable = modem_etm_enable,
50 .disable = modem_etm_disable,
51};
52
53static const struct coresight_ops modem_cs_ops = {
54 .source_ops = &modem_etm_source_ops,
55};
56
57static int modem_etm_probe(struct platform_device *pdev)
58{
59 struct device *dev = &pdev->dev;
60 struct coresight_platform_data *pdata;
61 struct modem_etm_drvdata *drvdata;
62 struct coresight_desc *desc;
63
64 if (pdev->dev.of_node) {
65 pdata = of_get_coresight_platform_data(dev, pdev->dev.of_node);
66 if (IS_ERR(pdata))
67 return PTR_ERR(pdata);
68 pdev->dev.platform_data = pdata;
69 }
70
71 drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
72 if (!drvdata)
73 return -ENOMEM;
74
75 drvdata->dev = &pdev->dev;
76 platform_set_drvdata(pdev, drvdata);
77
78 desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL);
79 if (!desc)
80 return -ENOMEM;
81
82 desc->type = CORESIGHT_DEV_TYPE_SOURCE;
83 desc->subtype.source_subtype = CORESIGHT_DEV_SUBTYPE_SOURCE_PROC;
84 desc->ops = &modem_cs_ops;
85 desc->pdata = pdev->dev.platform_data;
86 desc->dev = &pdev->dev;
87 desc->owner = THIS_MODULE;
88 drvdata->csdev = coresight_register(desc);
89 if (IS_ERR(drvdata->csdev))
90 return PTR_ERR(drvdata->csdev);
91
92 dev_info(dev, "Modem ETM initialized\n");
93 return 0;
94}
95
96static int modem_etm_remove(struct platform_device *pdev)
97{
98 struct modem_etm_drvdata *drvdata = platform_get_drvdata(pdev);
99
100 coresight_unregister(drvdata->csdev);
101 return 0;
102}
103
104static struct of_device_id modem_etm_match[] = {
105 {.compatible = "qcom,coresight-modem-etm"},
106 {}
107};
108
109static struct platform_driver modem_etm_driver = {
110 .probe = modem_etm_probe,
111 .remove = modem_etm_remove,
112 .driver = {
113 .name = "coresight-modem-etm",
114 .owner = THIS_MODULE,
115 .of_match_table = modem_etm_match,
116 },
117};
118
119int __init modem_etm_init(void)
120{
121 return platform_driver_register(&modem_etm_driver);
122}
123module_init(modem_etm_init);
124
125void __exit modem_etm_exit(void)
126{
127 platform_driver_unregister(&modem_etm_driver);
128}
129module_exit(modem_etm_exit);
130
131MODULE_LICENSE("GPL v2");
132MODULE_DESCRIPTION("CoreSight Modem ETM driver");