coresight-replicator.c 3.9 KB
Newer Older
1 2 3
// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
4 5
 *
 * Description: CoreSight Replicator driver
6 7 8 9 10 11 12 13
 */

#include <linux/kernel.h>
#include <linux/device.h>
#include <linux/platform_device.h>
#include <linux/io.h>
#include <linux/err.h>
#include <linux/slab.h>
14
#include <linux/pm_runtime.h>
15 16 17 18 19 20 21 22 23
#include <linux/clk.h>
#include <linux/of.h>
#include <linux/coresight.h>

#include "coresight-priv.h"

/**
 * struct replicator_drvdata - specifics associated to a replicator component
 * @dev:	the device entity associated with this component
24
 * @atclk:	optional clock for the core parts of the replicator.
25 26 27 28
 * @csdev:	component vitals needed by the framework
 */
struct replicator_drvdata {
	struct device		*dev;
29
	struct clk		*atclk;
30 31 32 33 34 35 36 37
	struct coresight_device	*csdev;
};

static int replicator_enable(struct coresight_device *csdev, int inport,
			     int outport)
{
	struct replicator_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);

38
	dev_dbg(drvdata->dev, "REPLICATOR enabled\n");
39 40 41 42 43 44 45 46
	return 0;
}

static void replicator_disable(struct coresight_device *csdev, int inport,
			       int outport)
{
	struct replicator_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);

47
	dev_dbg(drvdata->dev, "REPLICATOR disabled\n");
48 49 50 51 52 53 54 55 56 57 58
}

static const struct coresight_ops_link replicator_link_ops = {
	.enable		= replicator_enable,
	.disable	= replicator_disable,
};

static const struct coresight_ops replicator_cs_ops = {
	.link_ops	= &replicator_link_ops,
};

59
static int replicator_probe(struct device *dev)
60
{
61
	int ret = 0;
62 63
	struct coresight_platform_data *pdata = NULL;
	struct replicator_drvdata *drvdata;
64
	struct coresight_desc desc = { 0 };
65
	struct device_node *np = dev->of_node;
66 67 68 69 70

	if (np) {
		pdata = of_get_coresight_platform_data(dev, np);
		if (IS_ERR(pdata))
			return PTR_ERR(pdata);
71
		dev->platform_data = pdata;
72 73 74 75 76 77
	}

	drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
	if (!drvdata)
		return -ENOMEM;

78 79
	drvdata->dev = dev;
	drvdata->atclk = devm_clk_get(dev, "atclk"); /* optional */
80 81 82 83 84
	if (!IS_ERR(drvdata->atclk)) {
		ret = clk_prepare_enable(drvdata->atclk);
		if (ret)
			return ret;
	}
85 86

	dev_set_drvdata(dev, drvdata);
87

88 89 90
	desc.type = CORESIGHT_DEV_TYPE_LINK;
	desc.subtype.link_subtype = CORESIGHT_DEV_SUBTYPE_LINK_SPLIT;
	desc.ops = &replicator_cs_ops;
91 92
	desc.pdata = dev->platform_data;
	desc.dev = dev;
93
	drvdata->csdev = coresight_register(&desc);
94 95
	if (IS_ERR(drvdata->csdev)) {
		ret = PTR_ERR(drvdata->csdev);
96
		goto out_disable_clk;
97 98
	}

99
	pm_runtime_put(dev);
100

101 102
out_disable_clk:
	if (ret && !IS_ERR_OR_NULL(drvdata->atclk))
103
		clk_disable_unprepare(drvdata->atclk);
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
	return ret;
}

static int static_replicator_probe(struct platform_device *pdev)
{
	int ret;

	pm_runtime_get_noresume(&pdev->dev);
	pm_runtime_set_active(&pdev->dev);
	pm_runtime_enable(&pdev->dev);

	ret = replicator_probe(&pdev->dev);

	if (ret) {
		pm_runtime_put_noidle(&pdev->dev);
		pm_runtime_disable(&pdev->dev);
	}
121 122

	return ret;
123 124
}

125 126 127 128 129 130 131 132
#ifdef CONFIG_PM
static int replicator_runtime_suspend(struct device *dev)
{
	struct replicator_drvdata *drvdata = dev_get_drvdata(dev);

	if (drvdata && !IS_ERR(drvdata->atclk))
		clk_disable_unprepare(drvdata->atclk);

133 134 135
	return 0;
}

136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
static int replicator_runtime_resume(struct device *dev)
{
	struct replicator_drvdata *drvdata = dev_get_drvdata(dev);

	if (drvdata && !IS_ERR(drvdata->atclk))
		clk_prepare_enable(drvdata->atclk);

	return 0;
}
#endif

static const struct dev_pm_ops replicator_dev_pm_ops = {
	SET_RUNTIME_PM_OPS(replicator_runtime_suspend,
			   replicator_runtime_resume, NULL)
};

152
static const struct of_device_id static_replicator_match[] = {
153 154 155 156
	{.compatible = "arm,coresight-replicator"},
	{}
};

157 158
static struct platform_driver static_replicator_driver = {
	.probe          = static_replicator_probe,
159 160
	.driver         = {
		.name   = "coresight-replicator",
161
		.of_match_table = static_replicator_match,
162
		.pm	= &replicator_dev_pm_ops,
163
		.suppress_bind_attrs = true,
164 165
	},
};
166
builtin_platform_driver(static_replicator_driver);