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/types.h>
17 #include <linux/device.h>
18 #include <linux/err.h>
20 #include <linux/slab.h>
21 #include <linux/clk.h>
22 #include <linux/coresight.h>
23 #include <linux/amba/bus.h>
25 #include "coresight-priv.h"
27 #define FUNNEL_FUNCTL 0x000
28 #define FUNNEL_PRICTL 0x004
30 #define FUNNEL_HOLDTIME_MASK 0xf00
31 #define FUNNEL_HOLDTIME_SHFT 0x8
32 #define FUNNEL_HOLDTIME (0x7 << FUNNEL_HOLDTIME_SHFT)
35 * struct funnel_drvdata - specifics associated to a funnel component
36 * @base: memory mapped base address for this component.
37 * @dev: the device entity associated to this component.
38 * @csdev: component vitals needed by the framework.
39 * @clk: the clock this component is associated to.
40 * @priority: port selection order.
42 struct funnel_drvdata
{
45 struct coresight_device
*csdev
;
47 unsigned long priority
;
50 static void funnel_enable_hw(struct funnel_drvdata
*drvdata
, int port
)
54 CS_UNLOCK(drvdata
->base
);
56 functl
= readl_relaxed(drvdata
->base
+ FUNNEL_FUNCTL
);
57 functl
&= ~FUNNEL_HOLDTIME_MASK
;
58 functl
|= FUNNEL_HOLDTIME
;
59 functl
|= (1 << port
);
60 writel_relaxed(functl
, drvdata
->base
+ FUNNEL_FUNCTL
);
61 writel_relaxed(drvdata
->priority
, drvdata
->base
+ FUNNEL_PRICTL
);
63 CS_LOCK(drvdata
->base
);
66 static int funnel_enable(struct coresight_device
*csdev
, int inport
,
69 struct funnel_drvdata
*drvdata
= dev_get_drvdata(csdev
->dev
.parent
);
72 ret
= clk_prepare_enable(drvdata
->clk
);
76 funnel_enable_hw(drvdata
, inport
);
78 dev_info(drvdata
->dev
, "FUNNEL inport %d enabled\n", inport
);
82 static void funnel_disable_hw(struct funnel_drvdata
*drvdata
, int inport
)
86 CS_UNLOCK(drvdata
->base
);
88 functl
= readl_relaxed(drvdata
->base
+ FUNNEL_FUNCTL
);
89 functl
&= ~(1 << inport
);
90 writel_relaxed(functl
, drvdata
->base
+ FUNNEL_FUNCTL
);
92 CS_LOCK(drvdata
->base
);
95 static void funnel_disable(struct coresight_device
*csdev
, int inport
,
98 struct funnel_drvdata
*drvdata
= dev_get_drvdata(csdev
->dev
.parent
);
100 funnel_disable_hw(drvdata
, inport
);
102 clk_disable_unprepare(drvdata
->clk
);
104 dev_info(drvdata
->dev
, "FUNNEL inport %d disabled\n", inport
);
107 static const struct coresight_ops_link funnel_link_ops
= {
108 .enable
= funnel_enable
,
109 .disable
= funnel_disable
,
112 static const struct coresight_ops funnel_cs_ops
= {
113 .link_ops
= &funnel_link_ops
,
116 static ssize_t
priority_show(struct device
*dev
,
117 struct device_attribute
*attr
, char *buf
)
119 struct funnel_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
120 unsigned long val
= drvdata
->priority
;
122 return sprintf(buf
, "%#lx\n", val
);
125 static ssize_t
priority_store(struct device
*dev
,
126 struct device_attribute
*attr
,
127 const char *buf
, size_t size
)
131 struct funnel_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
133 ret
= kstrtoul(buf
, 16, &val
);
137 drvdata
->priority
= val
;
140 static DEVICE_ATTR_RW(priority
);
142 static u32
get_funnel_ctrl_hw(struct funnel_drvdata
*drvdata
)
146 CS_UNLOCK(drvdata
->base
);
147 functl
= readl_relaxed(drvdata
->base
+ FUNNEL_FUNCTL
);
148 CS_LOCK(drvdata
->base
);
153 static ssize_t
funnel_ctrl_show(struct device
*dev
,
154 struct device_attribute
*attr
, char *buf
)
158 struct funnel_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
160 ret
= clk_prepare_enable(drvdata
->clk
);
164 val
= get_funnel_ctrl_hw(drvdata
);
165 clk_disable_unprepare(drvdata
->clk
);
167 return sprintf(buf
, "%#x\n", val
);
169 static DEVICE_ATTR_RO(funnel_ctrl
);
171 static struct attribute
*coresight_funnel_attrs
[] = {
172 &dev_attr_funnel_ctrl
.attr
,
173 &dev_attr_priority
.attr
,
176 ATTRIBUTE_GROUPS(coresight_funnel
);
178 static int funnel_probe(struct amba_device
*adev
, const struct amba_id
*id
)
181 struct device
*dev
= &adev
->dev
;
182 struct coresight_platform_data
*pdata
= NULL
;
183 struct funnel_drvdata
*drvdata
;
184 struct resource
*res
= &adev
->res
;
185 struct coresight_desc
*desc
;
186 struct device_node
*np
= adev
->dev
.of_node
;
189 pdata
= of_get_coresight_platform_data(dev
, np
);
191 return PTR_ERR(pdata
);
192 adev
->dev
.platform_data
= pdata
;
195 drvdata
= devm_kzalloc(dev
, sizeof(*drvdata
), GFP_KERNEL
);
199 drvdata
->dev
= &adev
->dev
;
200 dev_set_drvdata(dev
, drvdata
);
202 /* Validity for the resource is already checked by the AMBA core */
203 base
= devm_ioremap_resource(dev
, res
);
205 return PTR_ERR(base
);
207 drvdata
->base
= base
;
209 drvdata
->clk
= adev
->pclk
;
211 desc
= devm_kzalloc(dev
, sizeof(*desc
), GFP_KERNEL
);
215 desc
->type
= CORESIGHT_DEV_TYPE_LINK
;
216 desc
->subtype
.link_subtype
= CORESIGHT_DEV_SUBTYPE_LINK_MERG
;
217 desc
->ops
= &funnel_cs_ops
;
220 desc
->groups
= coresight_funnel_groups
;
221 drvdata
->csdev
= coresight_register(desc
);
222 if (IS_ERR(drvdata
->csdev
))
223 return PTR_ERR(drvdata
->csdev
);
225 dev_info(dev
, "FUNNEL initialized\n");
229 static int funnel_remove(struct amba_device
*adev
)
231 struct funnel_drvdata
*drvdata
= amba_get_drvdata(adev
);
233 coresight_unregister(drvdata
->csdev
);
237 static struct amba_id funnel_ids
[] = {
245 static struct amba_driver funnel_driver
= {
247 .name
= "coresight-funnel",
248 .owner
= THIS_MODULE
,
250 .probe
= funnel_probe
,
251 .remove
= funnel_remove
,
252 .id_table
= funnel_ids
,
255 static int __init
funnel_init(void)
257 return amba_driver_register(&funnel_driver
);
259 module_init(funnel_init
);
261 static void __exit
funnel_exit(void)
263 amba_driver_unregister(&funnel_driver
);
265 module_exit(funnel_exit
);
267 MODULE_LICENSE("GPL v2");
268 MODULE_DESCRIPTION("CoreSight Funnel driver");