Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * ARM System Control and Management Interface (ARM SCMI) reset driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2019-2020 ARM Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/reset-controller.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/scmi_protocol.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) static const struct scmi_reset_proto_ops *reset_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  * struct scmi_reset_data - reset controller information structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * @rcdev: reset controller entity
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * @ph: ARM SCMI protocol handle used for communication with system controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) struct scmi_reset_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	struct reset_controller_dev rcdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	const struct scmi_protocol_handle *ph;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define to_scmi_reset_data(p)	container_of((p), struct scmi_reset_data, rcdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define to_scmi_handle(p)	(to_scmi_reset_data(p)->ph)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  * scmi_reset_assert() - assert device reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  * @rcdev: reset controller entity
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  * @id: ID of the reset to be asserted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  * This function implements the reset driver op to assert a device's reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  * using the ARM SCMI protocol.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  * Return: 0 for successful request, else a corresponding error value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) scmi_reset_assert(struct reset_controller_dev *rcdev, unsigned long id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	const struct scmi_protocol_handle *ph = to_scmi_handle(rcdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	return reset_ops->assert(ph, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  * scmi_reset_deassert() - deassert device reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  * @rcdev: reset controller entity
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  * @id: ID of the reset to be deasserted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  * This function implements the reset driver op to deassert a device's reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  * using the ARM SCMI protocol.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)  * Return: 0 for successful request, else a corresponding error value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) scmi_reset_deassert(struct reset_controller_dev *rcdev, unsigned long id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	const struct scmi_protocol_handle *ph = to_scmi_handle(rcdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	return reset_ops->deassert(ph, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  * scmi_reset_reset() - reset the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  * @rcdev: reset controller entity
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  * @id: ID of the reset signal to be reset(assert + deassert)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  * This function implements the reset driver op to trigger a device's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)  * reset signal using the ARM SCMI protocol.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73)  * Return: 0 for successful request, else a corresponding error value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) scmi_reset_reset(struct reset_controller_dev *rcdev, unsigned long id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	const struct scmi_protocol_handle *ph = to_scmi_handle(rcdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	return reset_ops->reset(ph, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) static const struct reset_control_ops scmi_reset_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	.assert		= scmi_reset_assert,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	.deassert	= scmi_reset_deassert,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	.reset		= scmi_reset_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) static int scmi_reset_probe(struct scmi_device *sdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	struct scmi_reset_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	struct device *dev = &sdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	struct device_node *np = dev->of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	const struct scmi_handle *handle = sdev->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	struct scmi_protocol_handle *ph;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	if (!handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	reset_ops = handle->devm_get_protocol(sdev, SCMI_PROTOCOL_RESET, &ph);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	if (IS_ERR(reset_ops))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		return PTR_ERR(reset_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	data->rcdev.ops = &scmi_reset_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	data->rcdev.owner = THIS_MODULE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	data->rcdev.of_node = np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	data->rcdev.nr_resets = reset_ops->num_domains_get(ph);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	data->ph = ph;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	return devm_reset_controller_register(dev, &data->rcdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) static const struct scmi_device_id scmi_id_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	{ SCMI_PROTOCOL_RESET, "reset" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	{ },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) MODULE_DEVICE_TABLE(scmi, scmi_id_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static struct scmi_driver scmi_reset_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	.name = "scmi-reset",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	.probe = scmi_reset_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	.id_table = scmi_id_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) module_scmi_driver(scmi_reset_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) MODULE_AUTHOR("Sudeep Holla <sudeep.holla@arm.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) MODULE_DESCRIPTION("ARM SCMI reset controller driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) MODULE_LICENSE("GPL v2");