Linux Audio

Check our new training course

Loading...
v6.8
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  3 * Copyright (c) 2011-2015, The Linux Foundation. All rights reserved.
  4 *
  5 * Description: CoreSight Replicator driver
  6 */
  7
  8#include <linux/acpi.h>
  9#include <linux/amba/bus.h>
 10#include <linux/kernel.h>
 11#include <linux/device.h>
 12#include <linux/platform_device.h>
 13#include <linux/io.h>
 14#include <linux/err.h>
 15#include <linux/slab.h>
 16#include <linux/pm_runtime.h>
 17#include <linux/property.h>
 18#include <linux/clk.h>
 19#include <linux/of.h>
 20#include <linux/coresight.h>
 21
 22#include "coresight-priv.h"
 23
 24#define REPLICATOR_IDFILTER0		0x000
 25#define REPLICATOR_IDFILTER1		0x004
 26
 27DEFINE_CORESIGHT_DEVLIST(replicator_devs, "replicator");
 28
 29/**
 30 * struct replicator_drvdata - specifics associated to a replicator component
 31 * @base:	memory mapped base address for this component. Also indicates
 32 *		whether this one is programmable or not.
 33 * @atclk:	optional clock for the core parts of the replicator.
 34 * @csdev:	component vitals needed by the framework
 35 * @spinlock:	serialize enable/disable operations.
 36 * @check_idfilter_val: check if the context is lost upon clock removal.
 37 */
 38struct replicator_drvdata {
 39	void __iomem		*base;
 40	struct clk		*atclk;
 41	struct coresight_device	*csdev;
 42	spinlock_t		spinlock;
 43	bool			check_idfilter_val;
 44};
 45
 46static void dynamic_replicator_reset(struct replicator_drvdata *drvdata)
 47{
 48	struct coresight_device *csdev = drvdata->csdev;
 49
 50	CS_UNLOCK(drvdata->base);
 51
 52	if (!coresight_claim_device_unlocked(csdev)) {
 53		writel_relaxed(0xff, drvdata->base + REPLICATOR_IDFILTER0);
 54		writel_relaxed(0xff, drvdata->base + REPLICATOR_IDFILTER1);
 55		coresight_disclaim_device_unlocked(csdev);
 56	}
 57
 58	CS_LOCK(drvdata->base);
 59}
 60
 61/*
 62 * replicator_reset : Reset the replicator configuration to sane values.
 63 */
 64static inline void replicator_reset(struct replicator_drvdata *drvdata)
 65{
 66	if (drvdata->base)
 67		dynamic_replicator_reset(drvdata);
 68}
 69
 70static int dynamic_replicator_enable(struct replicator_drvdata *drvdata,
 71				     int inport, int outport)
 72{
 73	int rc = 0;
 74	u32 id0val, id1val;
 75	struct coresight_device *csdev = drvdata->csdev;
 76
 77	CS_UNLOCK(drvdata->base);
 78
 79	id0val = readl_relaxed(drvdata->base + REPLICATOR_IDFILTER0);
 80	id1val = readl_relaxed(drvdata->base + REPLICATOR_IDFILTER1);
 81
 82	/*
 83	 * Some replicator designs lose context when AMBA clocks are removed,
 84	 * so have a check for this.
 85	 */
 86	if (drvdata->check_idfilter_val && id0val == 0x0 && id1val == 0x0)
 87		id0val = id1val = 0xff;
 88
 89	if (id0val == 0xff && id1val == 0xff)
 90		rc = coresight_claim_device_unlocked(csdev);
 91
 92	if (!rc) {
 93		switch (outport) {
 94		case 0:
 95			id0val = 0x0;
 96			break;
 97		case 1:
 98			id1val = 0x0;
 99			break;
100		default:
101			WARN_ON(1);
102			rc = -EINVAL;
103		}
104	}
105
106	/* Ensure that the outport is enabled. */
107	if (!rc) {
108		writel_relaxed(id0val, drvdata->base + REPLICATOR_IDFILTER0);
109		writel_relaxed(id1val, drvdata->base + REPLICATOR_IDFILTER1);
110	}
111
112	CS_LOCK(drvdata->base);
113
114	return rc;
115}
116
117static int replicator_enable(struct coresight_device *csdev,
118			     struct coresight_connection *in,
119			     struct coresight_connection *out)
120{
121	int rc = 0;
122	struct replicator_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
123	unsigned long flags;
124	bool first_enable = false;
125
126	spin_lock_irqsave(&drvdata->spinlock, flags);
127	if (atomic_read(&out->src_refcnt) == 0) {
128		if (drvdata->base)
129			rc = dynamic_replicator_enable(drvdata, in->dest_port,
130						       out->src_port);
131		if (!rc)
132			first_enable = true;
133	}
134	if (!rc)
135		atomic_inc(&out->src_refcnt);
136	spin_unlock_irqrestore(&drvdata->spinlock, flags);
137
138	if (first_enable)
139		dev_dbg(&csdev->dev, "REPLICATOR enabled\n");
140	return rc;
141}
142
143static void dynamic_replicator_disable(struct replicator_drvdata *drvdata,
144				       int inport, int outport)
145{
146	u32 reg;
147	struct coresight_device *csdev = drvdata->csdev;
148
149	switch (outport) {
150	case 0:
151		reg = REPLICATOR_IDFILTER0;
152		break;
153	case 1:
154		reg = REPLICATOR_IDFILTER1;
155		break;
156	default:
157		WARN_ON(1);
158		return;
159	}
160
161	CS_UNLOCK(drvdata->base);
162
163	/* disable the flow of ATB data through port */
164	writel_relaxed(0xff, drvdata->base + reg);
165
166	if ((readl_relaxed(drvdata->base + REPLICATOR_IDFILTER0) == 0xff) &&
167	    (readl_relaxed(drvdata->base + REPLICATOR_IDFILTER1) == 0xff))
168		coresight_disclaim_device_unlocked(csdev);
169	CS_LOCK(drvdata->base);
170}
171
172static void replicator_disable(struct coresight_device *csdev,
173			       struct coresight_connection *in,
174			       struct coresight_connection *out)
175{
176	struct replicator_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
177	unsigned long flags;
178	bool last_disable = false;
179
180	spin_lock_irqsave(&drvdata->spinlock, flags);
181	if (atomic_dec_return(&out->src_refcnt) == 0) {
182		if (drvdata->base)
183			dynamic_replicator_disable(drvdata, in->dest_port,
184						   out->src_port);
185		last_disable = true;
186	}
187	spin_unlock_irqrestore(&drvdata->spinlock, flags);
188
189	if (last_disable)
190		dev_dbg(&csdev->dev, "REPLICATOR disabled\n");
191}
192
193static const struct coresight_ops_link replicator_link_ops = {
194	.enable		= replicator_enable,
195	.disable	= replicator_disable,
196};
197
198static const struct coresight_ops replicator_cs_ops = {
199	.link_ops	= &replicator_link_ops,
200};
201
 
 
 
 
 
 
202static struct attribute *replicator_mgmt_attrs[] = {
203	coresight_simple_reg32(idfilter0, REPLICATOR_IDFILTER0),
204	coresight_simple_reg32(idfilter1, REPLICATOR_IDFILTER1),
205	NULL,
206};
207
208static const struct attribute_group replicator_mgmt_group = {
209	.attrs = replicator_mgmt_attrs,
210	.name = "mgmt",
211};
212
213static const struct attribute_group *replicator_groups[] = {
214	&replicator_mgmt_group,
215	NULL,
216};
217
218static int replicator_probe(struct device *dev, struct resource *res)
219{
220	int ret = 0;
221	struct coresight_platform_data *pdata = NULL;
222	struct replicator_drvdata *drvdata;
223	struct coresight_desc desc = { 0 };
224	void __iomem *base;
225
226	if (is_of_node(dev_fwnode(dev)) &&
227	    of_device_is_compatible(dev->of_node, "arm,coresight-replicator"))
228		dev_warn_once(dev,
229			      "Uses OBSOLETE CoreSight replicator binding\n");
230
231	desc.name = coresight_alloc_device_name(&replicator_devs, dev);
232	if (!desc.name)
233		return -ENOMEM;
234
235	drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
236	if (!drvdata)
237		return -ENOMEM;
238
239	drvdata->atclk = devm_clk_get(dev, "atclk"); /* optional */
240	if (!IS_ERR(drvdata->atclk)) {
241		ret = clk_prepare_enable(drvdata->atclk);
242		if (ret)
243			return ret;
244	}
245
246	/*
247	 * Map the device base for dynamic-replicator, which has been
248	 * validated by AMBA core
249	 */
250	if (res) {
251		base = devm_ioremap_resource(dev, res);
252		if (IS_ERR(base)) {
253			ret = PTR_ERR(base);
254			goto out_disable_clk;
255		}
256		drvdata->base = base;
257		desc.groups = replicator_groups;
258		desc.access = CSDEV_ACCESS_IOMEM(base);
259	}
260
261	if (fwnode_property_present(dev_fwnode(dev),
262				    "qcom,replicator-loses-context"))
263		drvdata->check_idfilter_val = true;
264
265	dev_set_drvdata(dev, drvdata);
266
267	pdata = coresight_get_platform_data(dev);
268	if (IS_ERR(pdata)) {
269		ret = PTR_ERR(pdata);
270		goto out_disable_clk;
271	}
272	dev->platform_data = pdata;
273
274	spin_lock_init(&drvdata->spinlock);
275	desc.type = CORESIGHT_DEV_TYPE_LINK;
276	desc.subtype.link_subtype = CORESIGHT_DEV_SUBTYPE_LINK_SPLIT;
277	desc.ops = &replicator_cs_ops;
278	desc.pdata = dev->platform_data;
279	desc.dev = dev;
280
281	drvdata->csdev = coresight_register(&desc);
282	if (IS_ERR(drvdata->csdev)) {
283		ret = PTR_ERR(drvdata->csdev);
284		goto out_disable_clk;
285	}
286
287	replicator_reset(drvdata);
288	pm_runtime_put(dev);
289
290out_disable_clk:
291	if (ret && !IS_ERR_OR_NULL(drvdata->atclk))
292		clk_disable_unprepare(drvdata->atclk);
293	return ret;
294}
295
296static int replicator_remove(struct device *dev)
297{
298	struct replicator_drvdata *drvdata = dev_get_drvdata(dev);
299
300	coresight_unregister(drvdata->csdev);
301	return 0;
302}
303
304static int static_replicator_probe(struct platform_device *pdev)
305{
306	int ret;
307
308	pm_runtime_get_noresume(&pdev->dev);
309	pm_runtime_set_active(&pdev->dev);
310	pm_runtime_enable(&pdev->dev);
311
312	/* Static replicators do not have programming base */
313	ret = replicator_probe(&pdev->dev, NULL);
314
315	if (ret) {
316		pm_runtime_put_noidle(&pdev->dev);
317		pm_runtime_disable(&pdev->dev);
318	}
319
320	return ret;
321}
322
323static void static_replicator_remove(struct platform_device *pdev)
324{
325	replicator_remove(&pdev->dev);
326	pm_runtime_disable(&pdev->dev);
327}
328
329#ifdef CONFIG_PM
330static int replicator_runtime_suspend(struct device *dev)
331{
332	struct replicator_drvdata *drvdata = dev_get_drvdata(dev);
333
334	if (drvdata && !IS_ERR(drvdata->atclk))
335		clk_disable_unprepare(drvdata->atclk);
336
337	return 0;
338}
339
340static int replicator_runtime_resume(struct device *dev)
341{
342	struct replicator_drvdata *drvdata = dev_get_drvdata(dev);
343
344	if (drvdata && !IS_ERR(drvdata->atclk))
345		clk_prepare_enable(drvdata->atclk);
346
347	return 0;
348}
349#endif
350
351static const struct dev_pm_ops replicator_dev_pm_ops = {
352	SET_RUNTIME_PM_OPS(replicator_runtime_suspend,
353			   replicator_runtime_resume, NULL)
354};
355
356static const struct of_device_id static_replicator_match[] = {
357	{.compatible = "arm,coresight-replicator"},
358	{.compatible = "arm,coresight-static-replicator"},
359	{}
360};
361
362MODULE_DEVICE_TABLE(of, static_replicator_match);
363
364#ifdef CONFIG_ACPI
365static const struct acpi_device_id static_replicator_acpi_ids[] = {
366	{"ARMHC985", 0}, /* ARM CoreSight Static Replicator */
367	{}
368};
369
370MODULE_DEVICE_TABLE(acpi, static_replicator_acpi_ids);
371#endif
372
373static struct platform_driver static_replicator_driver = {
374	.probe          = static_replicator_probe,
375	.remove_new     = static_replicator_remove,
376	.driver         = {
377		.name   = "coresight-static-replicator",
378		/* THIS_MODULE is taken care of by platform_driver_register() */
379		.of_match_table = of_match_ptr(static_replicator_match),
380		.acpi_match_table = ACPI_PTR(static_replicator_acpi_ids),
381		.pm	= &replicator_dev_pm_ops,
382		.suppress_bind_attrs = true,
383	},
384};
 
385
386static int dynamic_replicator_probe(struct amba_device *adev,
387				    const struct amba_id *id)
388{
389	return replicator_probe(&adev->dev, &adev->res);
390}
391
392static void dynamic_replicator_remove(struct amba_device *adev)
393{
394	replicator_remove(&adev->dev);
395}
396
397static const struct amba_id dynamic_replicator_ids[] = {
398	CS_AMBA_ID(0x000bb909),
399	CS_AMBA_ID(0x000bb9ec),		/* Coresight SoC-600 */
400	{},
401};
402
403MODULE_DEVICE_TABLE(amba, dynamic_replicator_ids);
404
405static struct amba_driver dynamic_replicator_driver = {
406	.drv = {
407		.name	= "coresight-dynamic-replicator",
408		.pm	= &replicator_dev_pm_ops,
409		.owner	= THIS_MODULE,
410		.suppress_bind_attrs = true,
411	},
412	.probe		= dynamic_replicator_probe,
413	.remove         = dynamic_replicator_remove,
414	.id_table	= dynamic_replicator_ids,
415};
416
417static int __init replicator_init(void)
418{
419	int ret;
420
421	ret = platform_driver_register(&static_replicator_driver);
422	if (ret) {
423		pr_info("Error registering platform driver\n");
424		return ret;
425	}
426
427	ret = amba_driver_register(&dynamic_replicator_driver);
428	if (ret) {
429		pr_info("Error registering amba driver\n");
430		platform_driver_unregister(&static_replicator_driver);
431	}
432
433	return ret;
434}
435
436static void __exit replicator_exit(void)
437{
438	platform_driver_unregister(&static_replicator_driver);
439	amba_driver_unregister(&dynamic_replicator_driver);
440}
441
442module_init(replicator_init);
443module_exit(replicator_exit);
444
445MODULE_AUTHOR("Pratik Patel <pratikp@codeaurora.org>");
446MODULE_AUTHOR("Mathieu Poirier <mathieu.poirier@linaro.org>");
447MODULE_DESCRIPTION("Arm CoreSight Replicator Driver");
448MODULE_LICENSE("GPL v2");
v5.9
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  3 * Copyright (c) 2011-2015, The Linux Foundation. All rights reserved.
  4 *
  5 * Description: CoreSight Replicator driver
  6 */
  7
  8#include <linux/acpi.h>
  9#include <linux/amba/bus.h>
 10#include <linux/kernel.h>
 11#include <linux/device.h>
 12#include <linux/platform_device.h>
 13#include <linux/io.h>
 14#include <linux/err.h>
 15#include <linux/slab.h>
 16#include <linux/pm_runtime.h>
 17#include <linux/property.h>
 18#include <linux/clk.h>
 19#include <linux/of.h>
 20#include <linux/coresight.h>
 21
 22#include "coresight-priv.h"
 23
 24#define REPLICATOR_IDFILTER0		0x000
 25#define REPLICATOR_IDFILTER1		0x004
 26
 27DEFINE_CORESIGHT_DEVLIST(replicator_devs, "replicator");
 28
 29/**
 30 * struct replicator_drvdata - specifics associated to a replicator component
 31 * @base:	memory mapped base address for this component. Also indicates
 32 *		whether this one is programmable or not.
 33 * @atclk:	optional clock for the core parts of the replicator.
 34 * @csdev:	component vitals needed by the framework
 35 * @spinlock:	serialize enable/disable operations.
 36 * @check_idfilter_val: check if the context is lost upon clock removal.
 37 */
 38struct replicator_drvdata {
 39	void __iomem		*base;
 40	struct clk		*atclk;
 41	struct coresight_device	*csdev;
 42	spinlock_t		spinlock;
 43	bool			check_idfilter_val;
 44};
 45
 46static void dynamic_replicator_reset(struct replicator_drvdata *drvdata)
 47{
 
 
 48	CS_UNLOCK(drvdata->base);
 49
 50	if (!coresight_claim_device_unlocked(drvdata->base)) {
 51		writel_relaxed(0xff, drvdata->base + REPLICATOR_IDFILTER0);
 52		writel_relaxed(0xff, drvdata->base + REPLICATOR_IDFILTER1);
 53		coresight_disclaim_device_unlocked(drvdata->base);
 54	}
 55
 56	CS_LOCK(drvdata->base);
 57}
 58
 59/*
 60 * replicator_reset : Reset the replicator configuration to sane values.
 61 */
 62static inline void replicator_reset(struct replicator_drvdata *drvdata)
 63{
 64	if (drvdata->base)
 65		dynamic_replicator_reset(drvdata);
 66}
 67
 68static int dynamic_replicator_enable(struct replicator_drvdata *drvdata,
 69				     int inport, int outport)
 70{
 71	int rc = 0;
 72	u32 id0val, id1val;
 
 73
 74	CS_UNLOCK(drvdata->base);
 75
 76	id0val = readl_relaxed(drvdata->base + REPLICATOR_IDFILTER0);
 77	id1val = readl_relaxed(drvdata->base + REPLICATOR_IDFILTER1);
 78
 79	/*
 80	 * Some replicator designs lose context when AMBA clocks are removed,
 81	 * so have a check for this.
 82	 */
 83	if (drvdata->check_idfilter_val && id0val == 0x0 && id1val == 0x0)
 84		id0val = id1val = 0xff;
 85
 86	if (id0val == 0xff && id1val == 0xff)
 87		rc = coresight_claim_device_unlocked(drvdata->base);
 88
 89	if (!rc) {
 90		switch (outport) {
 91		case 0:
 92			id0val = 0x0;
 93			break;
 94		case 1:
 95			id1val = 0x0;
 96			break;
 97		default:
 98			WARN_ON(1);
 99			rc = -EINVAL;
100		}
101	}
102
103	/* Ensure that the outport is enabled. */
104	if (!rc) {
105		writel_relaxed(id0val, drvdata->base + REPLICATOR_IDFILTER0);
106		writel_relaxed(id1val, drvdata->base + REPLICATOR_IDFILTER1);
107	}
108
109	CS_LOCK(drvdata->base);
110
111	return rc;
112}
113
114static int replicator_enable(struct coresight_device *csdev, int inport,
115			     int outport)
 
116{
117	int rc = 0;
118	struct replicator_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
119	unsigned long flags;
120	bool first_enable = false;
121
122	spin_lock_irqsave(&drvdata->spinlock, flags);
123	if (atomic_read(&csdev->refcnt[outport]) == 0) {
124		if (drvdata->base)
125			rc = dynamic_replicator_enable(drvdata, inport,
126						       outport);
127		if (!rc)
128			first_enable = true;
129	}
130	if (!rc)
131		atomic_inc(&csdev->refcnt[outport]);
132	spin_unlock_irqrestore(&drvdata->spinlock, flags);
133
134	if (first_enable)
135		dev_dbg(&csdev->dev, "REPLICATOR enabled\n");
136	return rc;
137}
138
139static void dynamic_replicator_disable(struct replicator_drvdata *drvdata,
140				       int inport, int outport)
141{
142	u32 reg;
 
143
144	switch (outport) {
145	case 0:
146		reg = REPLICATOR_IDFILTER0;
147		break;
148	case 1:
149		reg = REPLICATOR_IDFILTER1;
150		break;
151	default:
152		WARN_ON(1);
153		return;
154	}
155
156	CS_UNLOCK(drvdata->base);
157
158	/* disable the flow of ATB data through port */
159	writel_relaxed(0xff, drvdata->base + reg);
160
161	if ((readl_relaxed(drvdata->base + REPLICATOR_IDFILTER0) == 0xff) &&
162	    (readl_relaxed(drvdata->base + REPLICATOR_IDFILTER1) == 0xff))
163		coresight_disclaim_device_unlocked(drvdata->base);
164	CS_LOCK(drvdata->base);
165}
166
167static void replicator_disable(struct coresight_device *csdev, int inport,
168			       int outport)
 
169{
170	struct replicator_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
171	unsigned long flags;
172	bool last_disable = false;
173
174	spin_lock_irqsave(&drvdata->spinlock, flags);
175	if (atomic_dec_return(&csdev->refcnt[outport]) == 0) {
176		if (drvdata->base)
177			dynamic_replicator_disable(drvdata, inport, outport);
 
178		last_disable = true;
179	}
180	spin_unlock_irqrestore(&drvdata->spinlock, flags);
181
182	if (last_disable)
183		dev_dbg(&csdev->dev, "REPLICATOR disabled\n");
184}
185
186static const struct coresight_ops_link replicator_link_ops = {
187	.enable		= replicator_enable,
188	.disable	= replicator_disable,
189};
190
191static const struct coresight_ops replicator_cs_ops = {
192	.link_ops	= &replicator_link_ops,
193};
194
195#define coresight_replicator_reg(name, offset) \
196	coresight_simple_reg32(struct replicator_drvdata, name, offset)
197
198coresight_replicator_reg(idfilter0, REPLICATOR_IDFILTER0);
199coresight_replicator_reg(idfilter1, REPLICATOR_IDFILTER1);
200
201static struct attribute *replicator_mgmt_attrs[] = {
202	&dev_attr_idfilter0.attr,
203	&dev_attr_idfilter1.attr,
204	NULL,
205};
206
207static const struct attribute_group replicator_mgmt_group = {
208	.attrs = replicator_mgmt_attrs,
209	.name = "mgmt",
210};
211
212static const struct attribute_group *replicator_groups[] = {
213	&replicator_mgmt_group,
214	NULL,
215};
216
217static int replicator_probe(struct device *dev, struct resource *res)
218{
219	int ret = 0;
220	struct coresight_platform_data *pdata = NULL;
221	struct replicator_drvdata *drvdata;
222	struct coresight_desc desc = { 0 };
223	void __iomem *base;
224
225	if (is_of_node(dev_fwnode(dev)) &&
226	    of_device_is_compatible(dev->of_node, "arm,coresight-replicator"))
227		dev_warn_once(dev,
228			      "Uses OBSOLETE CoreSight replicator binding\n");
229
230	desc.name = coresight_alloc_device_name(&replicator_devs, dev);
231	if (!desc.name)
232		return -ENOMEM;
233
234	drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
235	if (!drvdata)
236		return -ENOMEM;
237
238	drvdata->atclk = devm_clk_get(dev, "atclk"); /* optional */
239	if (!IS_ERR(drvdata->atclk)) {
240		ret = clk_prepare_enable(drvdata->atclk);
241		if (ret)
242			return ret;
243	}
244
245	/*
246	 * Map the device base for dynamic-replicator, which has been
247	 * validated by AMBA core
248	 */
249	if (res) {
250		base = devm_ioremap_resource(dev, res);
251		if (IS_ERR(base)) {
252			ret = PTR_ERR(base);
253			goto out_disable_clk;
254		}
255		drvdata->base = base;
256		desc.groups = replicator_groups;
 
257	}
258
259	if (fwnode_property_present(dev_fwnode(dev),
260				    "qcom,replicator-loses-context"))
261		drvdata->check_idfilter_val = true;
262
263	dev_set_drvdata(dev, drvdata);
264
265	pdata = coresight_get_platform_data(dev);
266	if (IS_ERR(pdata)) {
267		ret = PTR_ERR(pdata);
268		goto out_disable_clk;
269	}
270	dev->platform_data = pdata;
271
272	spin_lock_init(&drvdata->spinlock);
273	desc.type = CORESIGHT_DEV_TYPE_LINK;
274	desc.subtype.link_subtype = CORESIGHT_DEV_SUBTYPE_LINK_SPLIT;
275	desc.ops = &replicator_cs_ops;
276	desc.pdata = dev->platform_data;
277	desc.dev = dev;
278
279	drvdata->csdev = coresight_register(&desc);
280	if (IS_ERR(drvdata->csdev)) {
281		ret = PTR_ERR(drvdata->csdev);
282		goto out_disable_clk;
283	}
284
285	replicator_reset(drvdata);
286	pm_runtime_put(dev);
287
288out_disable_clk:
289	if (ret && !IS_ERR_OR_NULL(drvdata->atclk))
290		clk_disable_unprepare(drvdata->atclk);
291	return ret;
292}
293
 
 
 
 
 
 
 
 
294static int static_replicator_probe(struct platform_device *pdev)
295{
296	int ret;
297
298	pm_runtime_get_noresume(&pdev->dev);
299	pm_runtime_set_active(&pdev->dev);
300	pm_runtime_enable(&pdev->dev);
301
302	/* Static replicators do not have programming base */
303	ret = replicator_probe(&pdev->dev, NULL);
304
305	if (ret) {
306		pm_runtime_put_noidle(&pdev->dev);
307		pm_runtime_disable(&pdev->dev);
308	}
309
310	return ret;
311}
312
 
 
 
 
 
 
313#ifdef CONFIG_PM
314static int replicator_runtime_suspend(struct device *dev)
315{
316	struct replicator_drvdata *drvdata = dev_get_drvdata(dev);
317
318	if (drvdata && !IS_ERR(drvdata->atclk))
319		clk_disable_unprepare(drvdata->atclk);
320
321	return 0;
322}
323
324static int replicator_runtime_resume(struct device *dev)
325{
326	struct replicator_drvdata *drvdata = dev_get_drvdata(dev);
327
328	if (drvdata && !IS_ERR(drvdata->atclk))
329		clk_prepare_enable(drvdata->atclk);
330
331	return 0;
332}
333#endif
334
335static const struct dev_pm_ops replicator_dev_pm_ops = {
336	SET_RUNTIME_PM_OPS(replicator_runtime_suspend,
337			   replicator_runtime_resume, NULL)
338};
339
340static const struct of_device_id static_replicator_match[] = {
341	{.compatible = "arm,coresight-replicator"},
342	{.compatible = "arm,coresight-static-replicator"},
343	{}
344};
345
 
 
346#ifdef CONFIG_ACPI
347static const struct acpi_device_id static_replicator_acpi_ids[] = {
348	{"ARMHC985", 0}, /* ARM CoreSight Static Replicator */
349	{}
350};
 
 
351#endif
352
353static struct platform_driver static_replicator_driver = {
354	.probe          = static_replicator_probe,
 
355	.driver         = {
356		.name   = "coresight-static-replicator",
 
357		.of_match_table = of_match_ptr(static_replicator_match),
358		.acpi_match_table = ACPI_PTR(static_replicator_acpi_ids),
359		.pm	= &replicator_dev_pm_ops,
360		.suppress_bind_attrs = true,
361	},
362};
363builtin_platform_driver(static_replicator_driver);
364
365static int dynamic_replicator_probe(struct amba_device *adev,
366				    const struct amba_id *id)
367{
368	return replicator_probe(&adev->dev, &adev->res);
369}
370
 
 
 
 
 
371static const struct amba_id dynamic_replicator_ids[] = {
372	CS_AMBA_ID(0x000bb909),
373	CS_AMBA_ID(0x000bb9ec),		/* Coresight SoC-600 */
374	{},
375};
376
 
 
377static struct amba_driver dynamic_replicator_driver = {
378	.drv = {
379		.name	= "coresight-dynamic-replicator",
380		.pm	= &replicator_dev_pm_ops,
 
381		.suppress_bind_attrs = true,
382	},
383	.probe		= dynamic_replicator_probe,
 
384	.id_table	= dynamic_replicator_ids,
385};
386builtin_amba_driver(dynamic_replicator_driver);