aboutsummaryrefslogtreecommitdiff
path: root/drivers/reset/reset-scmi.c
blob: 8d3a858e3b19702b86b223b5650a97b18fb6cf7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// SPDX-License-Identifier: GPL-2.0
/*
 * ARM System Control and Management Interface (ARM SCMI) reset driver
 *
 * Copyright (C) 2019 ARM Ltd.
 */

#include <linux/module.h>
#include <linux/of.h>
#include <linux/device.h>
#include <linux/reset-controller.h>
#include <linux/scmi_protocol.h>

/**
 * struct scmi_reset_data - reset controller information structure
 * @rcdev: reset controller entity
 * @handle: ARM SCMI handle used for communication with system controller
 */
struct scmi_reset_data {
	struct reset_controller_dev rcdev;
	const struct scmi_handle *handle;
};

#define to_scmi_reset_data(p)	container_of((p), struct scmi_reset_data, rcdev)
#define to_scmi_handle(p)	(to_scmi_reset_data(p)->handle)

/**
 * scmi_reset_assert() - assert device reset
 * @rcdev: reset controller entity
 * @id: ID of the reset to be asserted
 *
 * This function implements the reset driver op to assert a device's reset
 * using the ARM SCMI protocol.
 *
 * Return: 0 for successful request, else a corresponding error value
 */
static int
scmi_reset_assert(struct reset_controller_dev *rcdev, unsigned long id)
{
	const struct scmi_handle *handle = to_scmi_handle(rcdev);

	return handle->reset_ops->assert(handle, id);
}

/**
 * scmi_reset_deassert() - deassert device reset
 * @rcdev: reset controller entity
 * @id: ID of the reset to be deasserted
 *
 * This function implements the reset driver op to deassert a device's reset
 * using the ARM SCMI protocol.
 *
 * Return: 0 for successful request, else a corresponding error value
 */
static int
scmi_reset_deassert(struct reset_controller_dev *rcdev, unsigned long id)
{
	const struct scmi_handle *handle = to_scmi_handle(rcdev);

	return handle->reset_ops->deassert(handle, id);
}

/**
 * scmi_reset_reset() - reset the device
 * @rcdev: reset controller entity
 * @id: ID of the reset signal to be reset(assert + deassert)
 *
 * This function implements the reset driver op to trigger a device's
 * reset signal using the ARM SCMI protocol.
 *
 * Return: 0 for successful request, else a corresponding error value
 */
static int
scmi_reset_reset(struct reset_controller_dev *rcdev, unsigned long id)
{
	const struct scmi_handle *handle = to_scmi_handle(rcdev);

	return handle->reset_ops->reset(handle, id);
}

static const struct reset_control_ops scmi_reset_ops = {
	.assert		= scmi_reset_assert,
	.deassert	= scmi_reset_deassert,
	.reset		= scmi_reset_reset,
};

static int scmi_reset_probe(struct scmi_device *sdev)
{
	struct scmi_reset_data *data;
	struct device *dev = &sdev->dev;
	struct device_node *np = dev->of_node;
	const struct scmi_handle *handle = sdev->handle;

	if (!handle || !handle->reset_ops)
		return -ENODEV;

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

	data->rcdev.ops = &scmi_reset_ops;
	data->rcdev.owner = THIS_MODULE;
	data->rcdev.of_node = np;
	data->rcdev.nr_resets = handle->reset_ops->num_domains_get(handle);
	data->handle = handle;

	return devm_reset_controller_register(dev, &data->rcdev);
}

static const struct scmi_device_id scmi_id_table[] = {
	{ SCMI_PROTOCOL_RESET, "reset" },
	{ },
};
MODULE_DEVICE_TABLE(scmi, scmi_id_table);

static struct scmi_driver scmi_reset_driver = {
	.name = "scmi-reset",
	.probe = scmi_reset_probe,
	.id_table = scmi_id_table,
};
module_scmi_driver(scmi_reset_driver);

MODULE_AUTHOR("Sudeep Holla <sudeep.holla@arm.com>");
MODULE_DESCRIPTION("ARM SCMI reset controller driver");
MODULE_LICENSE("GPL v2");