1 // SPDX-License-Identifier: GPL-2.0
3 * ARM System Control and Management Interface (ARM SCMI) reset driver
5 * Copyright (C) 2019 ARM Ltd.
8 #include <linux/module.h>
10 #include <linux/device.h>
11 #include <linux/reset-controller.h>
12 #include <linux/scmi_protocol.h>
15 * struct scmi_reset_data - reset controller information structure
16 * @rcdev: reset controller entity
17 * @handle: ARM SCMI handle used for communication with system controller
19 struct scmi_reset_data
{
20 struct reset_controller_dev rcdev
;
21 const struct scmi_handle
*handle
;
24 #define to_scmi_reset_data(p) container_of((p), struct scmi_reset_data, rcdev)
25 #define to_scmi_handle(p) (to_scmi_reset_data(p)->handle)
28 * scmi_reset_assert() - assert device reset
29 * @rcdev: reset controller entity
30 * @id: ID of the reset to be asserted
32 * This function implements the reset driver op to assert a device's reset
33 * using the ARM SCMI protocol.
35 * Return: 0 for successful request, else a corresponding error value
38 scmi_reset_assert(struct reset_controller_dev
*rcdev
, unsigned long id
)
40 const struct scmi_handle
*handle
= to_scmi_handle(rcdev
);
42 return handle
->reset_ops
->assert(handle
, id
);
46 * scmi_reset_deassert() - deassert device reset
47 * @rcdev: reset controller entity
48 * @id: ID of the reset to be deasserted
50 * This function implements the reset driver op to deassert a device's reset
51 * using the ARM SCMI protocol.
53 * Return: 0 for successful request, else a corresponding error value
56 scmi_reset_deassert(struct reset_controller_dev
*rcdev
, unsigned long id
)
58 const struct scmi_handle
*handle
= to_scmi_handle(rcdev
);
60 return handle
->reset_ops
->deassert(handle
, id
);
64 * scmi_reset_reset() - reset the device
65 * @rcdev: reset controller entity
66 * @id: ID of the reset signal to be reset(assert + deassert)
68 * This function implements the reset driver op to trigger a device's
69 * reset signal using the ARM SCMI protocol.
71 * Return: 0 for successful request, else a corresponding error value
74 scmi_reset_reset(struct reset_controller_dev
*rcdev
, unsigned long id
)
76 const struct scmi_handle
*handle
= to_scmi_handle(rcdev
);
78 return handle
->reset_ops
->reset(handle
, id
);
81 static const struct reset_control_ops scmi_reset_ops
= {
82 .assert = scmi_reset_assert
,
83 .deassert
= scmi_reset_deassert
,
84 .reset
= scmi_reset_reset
,
87 static int scmi_reset_probe(struct scmi_device
*sdev
)
89 struct scmi_reset_data
*data
;
90 struct device
*dev
= &sdev
->dev
;
91 struct device_node
*np
= dev
->of_node
;
92 const struct scmi_handle
*handle
= sdev
->handle
;
94 if (!handle
|| !handle
->reset_ops
)
97 data
= devm_kzalloc(dev
, sizeof(*data
), GFP_KERNEL
);
101 data
->rcdev
.ops
= &scmi_reset_ops
;
102 data
->rcdev
.owner
= THIS_MODULE
;
103 data
->rcdev
.of_node
= np
;
104 data
->rcdev
.nr_resets
= handle
->reset_ops
->num_domains_get(handle
);
105 data
->handle
= handle
;
107 return devm_reset_controller_register(dev
, &data
->rcdev
);
110 static const struct scmi_device_id scmi_id_table
[] = {
111 { SCMI_PROTOCOL_RESET
, "reset" },
114 MODULE_DEVICE_TABLE(scmi
, scmi_id_table
);
116 static struct scmi_driver scmi_reset_driver
= {
117 .name
= "scmi-reset",
118 .probe
= scmi_reset_probe
,
119 .id_table
= scmi_id_table
,
121 module_scmi_driver(scmi_reset_driver
);
123 MODULE_AUTHOR("Sudeep Holla <sudeep.holla@arm.com>");
124 MODULE_DESCRIPTION("ARM SCMI reset controller driver");
125 MODULE_LICENSE("GPL v2");