1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
5 * Description: CoreSight Funnel driver
8 #include <linux/kernel.h>
9 #include <linux/init.h>
10 #include <linux/types.h>
11 #include <linux/device.h>
12 #include <linux/err.h>
14 #include <linux/slab.h>
15 #include <linux/pm_runtime.h>
16 #include <linux/coresight.h>
17 #include <linux/amba/bus.h>
18 #include <linux/clk.h>
20 #include "coresight-priv.h"
22 #define FUNNEL_FUNCTL 0x000
23 #define FUNNEL_PRICTL 0x004
25 #define FUNNEL_HOLDTIME_MASK 0xf00
26 #define FUNNEL_HOLDTIME_SHFT 0x8
27 #define FUNNEL_HOLDTIME (0x7 << FUNNEL_HOLDTIME_SHFT)
30 * struct funnel_drvdata - specifics associated to a funnel component
31 * @base: memory mapped base address for this component.
32 * @dev: the device entity associated to this component.
33 * @atclk: optional clock for the core parts of the funnel.
34 * @csdev: component vitals needed by the framework.
35 * @priority: port selection order.
37 struct funnel_drvdata
{
41 struct coresight_device
*csdev
;
42 unsigned long priority
;
45 static void funnel_enable_hw(struct funnel_drvdata
*drvdata
, int port
)
49 CS_UNLOCK(drvdata
->base
);
51 functl
= readl_relaxed(drvdata
->base
+ FUNNEL_FUNCTL
);
52 functl
&= ~FUNNEL_HOLDTIME_MASK
;
53 functl
|= FUNNEL_HOLDTIME
;
54 functl
|= (1 << port
);
55 writel_relaxed(functl
, drvdata
->base
+ FUNNEL_FUNCTL
);
56 writel_relaxed(drvdata
->priority
, drvdata
->base
+ FUNNEL_PRICTL
);
58 CS_LOCK(drvdata
->base
);
61 static int funnel_enable(struct coresight_device
*csdev
, int inport
,
64 struct funnel_drvdata
*drvdata
= dev_get_drvdata(csdev
->dev
.parent
);
66 funnel_enable_hw(drvdata
, inport
);
68 dev_info(drvdata
->dev
, "FUNNEL inport %d enabled\n", inport
);
72 static void funnel_disable_hw(struct funnel_drvdata
*drvdata
, int inport
)
76 CS_UNLOCK(drvdata
->base
);
78 functl
= readl_relaxed(drvdata
->base
+ FUNNEL_FUNCTL
);
79 functl
&= ~(1 << inport
);
80 writel_relaxed(functl
, drvdata
->base
+ FUNNEL_FUNCTL
);
82 CS_LOCK(drvdata
->base
);
85 static void funnel_disable(struct coresight_device
*csdev
, int inport
,
88 struct funnel_drvdata
*drvdata
= dev_get_drvdata(csdev
->dev
.parent
);
90 funnel_disable_hw(drvdata
, inport
);
92 dev_info(drvdata
->dev
, "FUNNEL inport %d disabled\n", inport
);
95 static const struct coresight_ops_link funnel_link_ops
= {
96 .enable
= funnel_enable
,
97 .disable
= funnel_disable
,
100 static const struct coresight_ops funnel_cs_ops
= {
101 .link_ops
= &funnel_link_ops
,
104 static ssize_t
priority_show(struct device
*dev
,
105 struct device_attribute
*attr
, char *buf
)
107 struct funnel_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
108 unsigned long val
= drvdata
->priority
;
110 return sprintf(buf
, "%#lx\n", val
);
113 static ssize_t
priority_store(struct device
*dev
,
114 struct device_attribute
*attr
,
115 const char *buf
, size_t size
)
119 struct funnel_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
121 ret
= kstrtoul(buf
, 16, &val
);
125 drvdata
->priority
= val
;
128 static DEVICE_ATTR_RW(priority
);
130 static u32
get_funnel_ctrl_hw(struct funnel_drvdata
*drvdata
)
134 CS_UNLOCK(drvdata
->base
);
135 functl
= readl_relaxed(drvdata
->base
+ FUNNEL_FUNCTL
);
136 CS_LOCK(drvdata
->base
);
141 static ssize_t
funnel_ctrl_show(struct device
*dev
,
142 struct device_attribute
*attr
, char *buf
)
145 struct funnel_drvdata
*drvdata
= dev_get_drvdata(dev
->parent
);
147 pm_runtime_get_sync(drvdata
->dev
);
149 val
= get_funnel_ctrl_hw(drvdata
);
151 pm_runtime_put(drvdata
->dev
);
153 return sprintf(buf
, "%#x\n", val
);
155 static DEVICE_ATTR_RO(funnel_ctrl
);
157 static struct attribute
*coresight_funnel_attrs
[] = {
158 &dev_attr_funnel_ctrl
.attr
,
159 &dev_attr_priority
.attr
,
162 ATTRIBUTE_GROUPS(coresight_funnel
);
164 static int funnel_probe(struct amba_device
*adev
, const struct amba_id
*id
)
168 struct device
*dev
= &adev
->dev
;
169 struct coresight_platform_data
*pdata
= NULL
;
170 struct funnel_drvdata
*drvdata
;
171 struct resource
*res
= &adev
->res
;
172 struct coresight_desc desc
= { 0 };
173 struct device_node
*np
= adev
->dev
.of_node
;
176 pdata
= of_get_coresight_platform_data(dev
, np
);
178 return PTR_ERR(pdata
);
179 adev
->dev
.platform_data
= pdata
;
182 drvdata
= devm_kzalloc(dev
, sizeof(*drvdata
), GFP_KERNEL
);
186 drvdata
->dev
= &adev
->dev
;
187 drvdata
->atclk
= devm_clk_get(&adev
->dev
, "atclk"); /* optional */
188 if (!IS_ERR(drvdata
->atclk
)) {
189 ret
= clk_prepare_enable(drvdata
->atclk
);
193 dev_set_drvdata(dev
, drvdata
);
195 /* Validity for the resource is already checked by the AMBA core */
196 base
= devm_ioremap_resource(dev
, res
);
198 return PTR_ERR(base
);
200 drvdata
->base
= base
;
201 pm_runtime_put(&adev
->dev
);
203 desc
.type
= CORESIGHT_DEV_TYPE_LINK
;
204 desc
.subtype
.link_subtype
= CORESIGHT_DEV_SUBTYPE_LINK_MERG
;
205 desc
.ops
= &funnel_cs_ops
;
208 desc
.groups
= coresight_funnel_groups
;
209 drvdata
->csdev
= coresight_register(&desc
);
211 return PTR_ERR_OR_ZERO(drvdata
->csdev
);
215 static int funnel_runtime_suspend(struct device
*dev
)
217 struct funnel_drvdata
*drvdata
= dev_get_drvdata(dev
);
219 if (drvdata
&& !IS_ERR(drvdata
->atclk
))
220 clk_disable_unprepare(drvdata
->atclk
);
225 static int funnel_runtime_resume(struct device
*dev
)
227 struct funnel_drvdata
*drvdata
= dev_get_drvdata(dev
);
229 if (drvdata
&& !IS_ERR(drvdata
->atclk
))
230 clk_prepare_enable(drvdata
->atclk
);
236 static const struct dev_pm_ops funnel_dev_pm_ops
= {
237 SET_RUNTIME_PM_OPS(funnel_runtime_suspend
, funnel_runtime_resume
, NULL
)
240 static const struct amba_id funnel_ids
[] = {
246 /* Coresight SoC-600 */
253 static struct amba_driver funnel_driver
= {
255 .name
= "coresight-funnel",
256 .owner
= THIS_MODULE
,
257 .pm
= &funnel_dev_pm_ops
,
258 .suppress_bind_attrs
= true,
260 .probe
= funnel_probe
,
261 .id_table
= funnel_ids
,
263 builtin_amba_driver(funnel_driver
);