1 // SPDX-License-Identifier: GPL-2.0
3 * ARM System Control and Management Interface (ARM SCMI) reset driver
5 * Copyright (C) 2019-2021 ARM Ltd.
8 #include <linux/module.h>
10 #include <linux/device.h>
11 #include <linux/reset-controller.h>
12 #include <linux/scmi_protocol.h>
14 static const struct scmi_reset_proto_ops
*reset_ops
;
17 * struct scmi_reset_data - reset controller information structure
18 * @rcdev: reset controller entity
19 * @ph: ARM SCMI protocol handle used for communication with system controller
21 struct scmi_reset_data
{
22 struct reset_controller_dev rcdev
;
23 const struct scmi_protocol_handle
*ph
;
26 #define to_scmi_reset_data(p) container_of((p), struct scmi_reset_data, rcdev)
27 #define to_scmi_handle(p) (to_scmi_reset_data(p)->ph)
30 * scmi_reset_assert() - assert device reset
31 * @rcdev: reset controller entity
32 * @id: ID of the reset to be asserted
34 * This function implements the reset driver op to assert a device's reset
35 * using the ARM SCMI protocol.
37 * Return: 0 for successful request, else a corresponding error value
40 scmi_reset_assert(struct reset_controller_dev
*rcdev
, unsigned long id
)
42 const struct scmi_protocol_handle
*ph
= to_scmi_handle(rcdev
);
44 return reset_ops
->assert(ph
, id
);
48 * scmi_reset_deassert() - deassert device reset
49 * @rcdev: reset controller entity
50 * @id: ID of the reset to be deasserted
52 * This function implements the reset driver op to deassert a device's reset
53 * using the ARM SCMI protocol.
55 * Return: 0 for successful request, else a corresponding error value
58 scmi_reset_deassert(struct reset_controller_dev
*rcdev
, unsigned long id
)
60 const struct scmi_protocol_handle
*ph
= to_scmi_handle(rcdev
);
62 return reset_ops
->deassert(ph
, id
);
66 * scmi_reset_reset() - reset the device
67 * @rcdev: reset controller entity
68 * @id: ID of the reset signal to be reset(assert + deassert)
70 * This function implements the reset driver op to trigger a device's
71 * reset signal using the ARM SCMI protocol.
73 * Return: 0 for successful request, else a corresponding error value
76 scmi_reset_reset(struct reset_controller_dev
*rcdev
, unsigned long id
)
78 const struct scmi_protocol_handle
*ph
= to_scmi_handle(rcdev
);
80 return reset_ops
->reset(ph
, id
);
83 static const struct reset_control_ops scmi_reset_ops
= {
84 .assert = scmi_reset_assert
,
85 .deassert
= scmi_reset_deassert
,
86 .reset
= scmi_reset_reset
,
89 static int scmi_reset_probe(struct scmi_device
*sdev
)
91 struct scmi_reset_data
*data
;
92 struct device
*dev
= &sdev
->dev
;
93 struct device_node
*np
= dev
->of_node
;
94 const struct scmi_handle
*handle
= sdev
->handle
;
95 struct scmi_protocol_handle
*ph
;
100 reset_ops
= handle
->devm_protocol_get(sdev
, SCMI_PROTOCOL_RESET
, &ph
);
101 if (IS_ERR(reset_ops
))
102 return PTR_ERR(reset_ops
);
104 data
= devm_kzalloc(dev
, sizeof(*data
), GFP_KERNEL
);
108 data
->rcdev
.ops
= &scmi_reset_ops
;
109 data
->rcdev
.owner
= THIS_MODULE
;
110 data
->rcdev
.of_node
= np
;
111 data
->rcdev
.nr_resets
= reset_ops
->num_domains_get(ph
);
114 return devm_reset_controller_register(dev
, &data
->rcdev
);
117 static const struct scmi_device_id scmi_id_table
[] = {
118 { SCMI_PROTOCOL_RESET
, "reset" },
121 MODULE_DEVICE_TABLE(scmi
, scmi_id_table
);
123 static struct scmi_driver scmi_reset_driver
= {
124 .name
= "scmi-reset",
125 .probe
= scmi_reset_probe
,
126 .id_table
= scmi_id_table
,
128 module_scmi_driver(scmi_reset_driver
);
130 MODULE_AUTHOR("Sudeep Holla <sudeep.holla@arm.com>");
131 MODULE_DESCRIPTION("ARM SCMI reset controller driver");
132 MODULE_LICENSE("GPL v2");