mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Beleswar Padhi <b-padhi@ti.com>
To: <nm@ti.com>, <kristo@kernel.org>, <ssantosh@kernel.org>,
	<afd@ti.com>, <vigneshr@ti.com>, <u-kumar1@ti.com>
Cc: <linux-kernel@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>, <b-padhi@ti.com>
Subject: [PATCH v3 18/22] firmware: ti: ti_sci_device: Move device ops into its own file
Date: Thu, 29 Oct 2026 23:41:43 +0530	[thread overview]
Message-ID: <20261029181147.266771-19-b-padhi@ti.com> (raw)
In-Reply-To: <20261029181147.266771-1-b-padhi@ti.com>

From: Andrew Davis <afd@ti.com>

Extract the device operations related functions and services from
ti_sci_core.c into its own file. This breaks down the single large file
into smaller logical files for better readability and maintenance.

Signed-off-by: Andrew Davis <afd@ti.com>
Signed-off-by: Beleswar Padhi <b-padhi@ti.com>
---
v3: Changelog:
1. Update commit message to remove ti_sci_core.c file renaming as that
is already done in [PATCH v3 16/22] now.

Link to v2:
https://lore.kernel.org/all/20260930160607.2674980-19-b-padhi@ti.com/

v2: Changelog:
1. None to this patch.

Link to v1:
https://lore.kernel.org/all/20260929201746.4078803-19-b-padhi@ti.com/

 drivers/firmware/ti/Makefile        |   1 +
 drivers/firmware/ti/ti_sci.h        |   7 +
 drivers/firmware/ti/ti_sci_core.c   | 378 +--------------------------
 drivers/firmware/ti/ti_sci_device.c | 388 ++++++++++++++++++++++++++++
 4 files changed, 401 insertions(+), 373 deletions(-)
 create mode 100644 drivers/firmware/ti/ti_sci_device.c

diff --git a/drivers/firmware/ti/Makefile b/drivers/firmware/ti/Makefile
index ca54cd35eaef2..a3a056eedd9a5 100644
--- a/drivers/firmware/ti/Makefile
+++ b/drivers/firmware/ti/Makefile
@@ -1,4 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0-only
 
 ti_sci-y			:= ti_sci_core.o
+ti_sci-y			+= ti_sci_device.o
 obj-$(CONFIG_TI_SCI_PROTOCOL)	+= ti_sci.o
diff --git a/drivers/firmware/ti/ti_sci.h b/drivers/firmware/ti/ti_sci.h
index f2f17bcac39e4..79f56699faf29 100644
--- a/drivers/firmware/ti/ti_sci.h
+++ b/drivers/firmware/ti/ti_sci.h
@@ -1560,4 +1560,11 @@ struct ti_sci_msg_resp_get_status {
 	u32 status_flags;
 } __packed;
 
+int ti_sci_do_xfer(const struct ti_sci_handle *handle,
+		   u16 msg_type, u32 msg_flags,
+		   void *tx_message, size_t tx_message_size,
+		   void *rx_message, size_t rx_message_size);
+
+void ti_sci_setup_device_ops(struct ti_sci_dev_ops *dops);
+
 #endif /* __TI_SCI_H */
diff --git a/drivers/firmware/ti/ti_sci_core.c b/drivers/firmware/ti/ti_sci_core.c
index 5d3151571ac33..e98bf3c5f9dc1 100644
--- a/drivers/firmware/ti/ti_sci_core.c
+++ b/drivers/firmware/ti/ti_sci_core.c
@@ -444,10 +444,10 @@ static inline bool ti_sci_is_response_ack(void *r)
  *         corresponding error if transmit fails, or
  *         return 0, if all goes well.
  */
-static inline int ti_sci_do_xfer(const struct ti_sci_handle *handle,
-				 u16 msg_type, u32 msg_flags,
-				 void *tx_message, size_t tx_message_size,
-				 void *rx_message, size_t rx_message_size)
+int ti_sci_do_xfer(const struct ti_sci_handle *handle,
+		   u16 msg_type, u32 msg_flags,
+		   void *tx_message, size_t tx_message_size,
+		   void *rx_message, size_t rx_message_size)
 {
 	struct ti_sci_info *info;
 	struct ti_sci_xfer *xfer;
@@ -565,361 +565,6 @@ static int ti_sci_cmd_get_revision(struct ti_sci_info *info)
 	return 0;
 }
 
-/**
- * ti_sci_set_device_state() - Set device state helper
- * @handle:	pointer to TI SCI handle
- * @id:		Device identifier
- * @flags:	flags to setup for the device
- * @state:	State to move the device to
- *
- * Return: 0 if all went well, else returns appropriate error value.
- */
-static int ti_sci_set_device_state(const struct ti_sci_handle *handle,
-				   u32 id, u32 flags, u8 state)
-{
-	struct ti_sci_msg_req_set_device_state req;
-	struct ti_sci_msg_hdr resp;
-	int ret = 0;
-
-	req.id = id;
-	req.state = state;
-
-	ret = ti_sci_do_xfer(handle, TI_SCI_MSG_SET_DEVICE_STATE,
-			     flags | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
-			     &req, sizeof(req),
-			     &resp, sizeof(resp));
-	if (ret)
-		return ret;
-
-	return 0;
-}
-
-/**
- * ti_sci_get_device_state() - Get device state helper
- * @handle:	Handle to the device
- * @id:		Device Identifier
- * @clcnt:	Pointer to Context Loss Count
- * @resets:	pointer to resets
- * @p_state:	pointer to p_state
- * @c_state:	pointer to c_state
- *
- * Return: 0 if all went fine, else return appropriate error.
- */
-static int ti_sci_get_device_state(const struct ti_sci_handle *handle,
-				   u32 id,  u32 *clcnt,  u32 *resets,
-				    u8 *p_state,  u8 *c_state)
-{
-	struct ti_sci_msg_req_get_device_state req;
-	struct ti_sci_msg_resp_get_device_state resp;
-	int ret = 0;
-
-	if (!clcnt && !resets && !p_state && !c_state)
-		return -EINVAL;
-
-	req.id = id;
-
-	ret = ti_sci_do_xfer(handle, TI_SCI_MSG_GET_DEVICE_STATE,
-			     TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
-			     &req, sizeof(req),
-			     &resp, sizeof(resp));
-	if (ret)
-		return ret;
-
-	if (clcnt)
-		*clcnt = resp.context_loss_count;
-	if (resets)
-		*resets = resp.resets;
-	if (p_state)
-		*p_state = resp.programmed_state;
-	if (c_state)
-		*c_state = resp.current_state;
-
-	return 0;
-}
-
-/**
- * ti_sci_cmd_get_device() - command to request for device managed by TISCI
- *			     that can be shared with other hosts.
- * @handle:	Pointer to TISCI handle as retrieved by *ti_sci_get_handle
- * @id:		Device Identifier
- *
- * Request for the device - NOTE: the client MUST maintain integrity of
- * usage count by balancing get_device with put_device. No refcounting is
- * managed by driver for that purpose.
- *
- * Return: 0 if all went fine, else return appropriate error.
- */
-static int ti_sci_cmd_get_device(const struct ti_sci_handle *handle, u32 id)
-{
-	return ti_sci_set_device_state(handle, id, 0,
-				       MSG_DEVICE_SW_STATE_ON);
-}
-
-/**
- * ti_sci_cmd_get_device_exclusive() - command to request for device managed by
- *				       TISCI that is exclusively owned by the
- *				       requesting host.
- * @handle:	Pointer to TISCI handle as retrieved by *ti_sci_get_handle
- * @id:		Device Identifier
- *
- * Request for the device - NOTE: the client MUST maintain integrity of
- * usage count by balancing get_device with put_device. No refcounting is
- * managed by driver for that purpose.
- *
- * Return: 0 if all went fine, else return appropriate error.
- */
-static int ti_sci_cmd_get_device_exclusive(const struct ti_sci_handle *handle,
-					   u32 id)
-{
-	return ti_sci_set_device_state(handle, id,
-				       MSG_FLAG_DEVICE_EXCLUSIVE,
-				       MSG_DEVICE_SW_STATE_ON);
-}
-
-/**
- * ti_sci_cmd_idle_device() - Command to idle a device managed by TISCI
- * @handle:	Pointer to TISCI handle as retrieved by *ti_sci_get_handle
- * @id:		Device Identifier
- *
- * Request for the device - NOTE: the client MUST maintain integrity of
- * usage count by balancing get_device with put_device. No refcounting is
- * managed by driver for that purpose.
- *
- * Return: 0 if all went fine, else return appropriate error.
- */
-static int ti_sci_cmd_idle_device(const struct ti_sci_handle *handle, u32 id)
-{
-	return ti_sci_set_device_state(handle, id, 0,
-				       MSG_DEVICE_SW_STATE_RETENTION);
-}
-
-/**
- * ti_sci_cmd_idle_device_exclusive() - Command to idle a device managed by
- *					TISCI that is exclusively owned by
- *					requesting host.
- * @handle:	Pointer to TISCI handle as retrieved by *ti_sci_get_handle
- * @id:		Device Identifier
- *
- * Request for the device - NOTE: the client MUST maintain integrity of
- * usage count by balancing get_device with put_device. No refcounting is
- * managed by driver for that purpose.
- *
- * Return: 0 if all went fine, else return appropriate error.
- */
-static int ti_sci_cmd_idle_device_exclusive(const struct ti_sci_handle *handle,
-					    u32 id)
-{
-	return ti_sci_set_device_state(handle, id,
-				       MSG_FLAG_DEVICE_EXCLUSIVE,
-				       MSG_DEVICE_SW_STATE_RETENTION);
-}
-
-/**
- * ti_sci_cmd_put_device() - command to release a device managed by TISCI
- * @handle:	Pointer to TISCI handle as retrieved by *ti_sci_get_handle
- * @id:		Device Identifier
- *
- * Request for the device - NOTE: the client MUST maintain integrity of
- * usage count by balancing get_device with put_device. No refcounting is
- * managed by driver for that purpose.
- *
- * Return: 0 if all went fine, else return appropriate error.
- */
-static int ti_sci_cmd_put_device(const struct ti_sci_handle *handle, u32 id)
-{
-	return ti_sci_set_device_state(handle, id,
-				       0, MSG_DEVICE_SW_STATE_AUTO_OFF);
-}
-
-/**
- * ti_sci_cmd_dev_is_valid() - Is the device valid
- * @handle:	Pointer to TISCI handle as retrieved by *ti_sci_get_handle
- * @id:		Device Identifier
- *
- * Return: 0 if all went fine and the device ID is valid, else return
- * appropriate error.
- */
-static int ti_sci_cmd_dev_is_valid(const struct ti_sci_handle *handle, u32 id)
-{
-	u8 unused;
-
-	/* check the device state which will also tell us if the ID is valid */
-	return ti_sci_get_device_state(handle, id, NULL, NULL, NULL, &unused);
-}
-
-/**
- * ti_sci_cmd_dev_get_clcnt() - Get context loss counter
- * @handle:	Pointer to TISCI handle
- * @id:		Device Identifier
- * @count:	Pointer to Context Loss counter to populate
- *
- * Return: 0 if all went fine, else return appropriate error.
- */
-static int ti_sci_cmd_dev_get_clcnt(const struct ti_sci_handle *handle, u32 id,
-				    u32 *count)
-{
-	return ti_sci_get_device_state(handle, id, count, NULL, NULL, NULL);
-}
-
-/**
- * ti_sci_cmd_dev_is_idle() - Check if the device is requested to be idle
- * @handle:	Pointer to TISCI handle
- * @id:		Device Identifier
- * @r_state:	true if requested to be idle
- *
- * Return: 0 if all went fine, else return appropriate error.
- */
-static int ti_sci_cmd_dev_is_idle(const struct ti_sci_handle *handle, u32 id,
-				  bool *r_state)
-{
-	int ret;
-	u8 state;
-
-	if (!r_state)
-		return -EINVAL;
-
-	ret = ti_sci_get_device_state(handle, id, NULL, NULL, &state, NULL);
-	if (ret)
-		return ret;
-
-	*r_state = (state == MSG_DEVICE_SW_STATE_RETENTION);
-
-	return 0;
-}
-
-/**
- * ti_sci_cmd_dev_is_stop() - Check if the device is requested to be stopped
- * @handle:	Pointer to TISCI handle
- * @id:		Device Identifier
- * @r_state:	true if requested to be stopped
- * @curr_state:	true if currently stopped.
- *
- * Return: 0 if all went fine, else return appropriate error.
- */
-static int ti_sci_cmd_dev_is_stop(const struct ti_sci_handle *handle, u32 id,
-				  bool *r_state,  bool *curr_state)
-{
-	int ret;
-	u8 p_state, c_state;
-
-	if (!r_state && !curr_state)
-		return -EINVAL;
-
-	ret =
-	    ti_sci_get_device_state(handle, id, NULL, NULL, &p_state, &c_state);
-	if (ret)
-		return ret;
-
-	if (r_state)
-		*r_state = (p_state == MSG_DEVICE_SW_STATE_AUTO_OFF);
-	if (curr_state)
-		*curr_state = (c_state == MSG_DEVICE_HW_STATE_OFF);
-
-	return 0;
-}
-
-/**
- * ti_sci_cmd_dev_is_on() - Check if the device is requested to be ON
- * @handle:	Pointer to TISCI handle
- * @id:		Device Identifier
- * @r_state:	true if requested to be ON
- * @curr_state:	true if currently ON and active
- *
- * Return: 0 if all went fine, else return appropriate error.
- */
-static int ti_sci_cmd_dev_is_on(const struct ti_sci_handle *handle, u32 id,
-				bool *r_state,  bool *curr_state)
-{
-	int ret;
-	u8 p_state, c_state;
-
-	if (!r_state && !curr_state)
-		return -EINVAL;
-
-	ret =
-	    ti_sci_get_device_state(handle, id, NULL, NULL, &p_state, &c_state);
-	if (ret)
-		return ret;
-
-	if (r_state)
-		*r_state = (p_state == MSG_DEVICE_SW_STATE_ON);
-	if (curr_state)
-		*curr_state = (c_state == MSG_DEVICE_HW_STATE_ON);
-
-	return 0;
-}
-
-/**
- * ti_sci_cmd_dev_is_trans() - Check if the device is currently transitioning
- * @handle:	Pointer to TISCI handle
- * @id:		Device Identifier
- * @curr_state:	true if currently transitioning.
- *
- * Return: 0 if all went fine, else return appropriate error.
- */
-static int ti_sci_cmd_dev_is_trans(const struct ti_sci_handle *handle, u32 id,
-				   bool *curr_state)
-{
-	int ret;
-	u8 state;
-
-	if (!curr_state)
-		return -EINVAL;
-
-	ret = ti_sci_get_device_state(handle, id, NULL, NULL, NULL, &state);
-	if (ret)
-		return ret;
-
-	*curr_state = (state == MSG_DEVICE_HW_STATE_TRANS);
-
-	return 0;
-}
-
-/**
- * ti_sci_cmd_set_device_resets() - command to set resets for device managed
- *				    by TISCI
- * @handle:	Pointer to TISCI handle as retrieved by *ti_sci_get_handle
- * @id:		Device Identifier
- * @reset_state: Device specific reset bit field
- *
- * Return: 0 if all went fine, else return appropriate error.
- */
-static int ti_sci_cmd_set_device_resets(const struct ti_sci_handle *handle,
-					u32 id, u32 reset_state)
-{
-	struct ti_sci_msg_req_set_device_resets req;
-	struct ti_sci_msg_hdr resp;
-	int ret = 0;
-
-	req.id = id;
-	req.resets = reset_state;
-
-	ret = ti_sci_do_xfer(handle, TI_SCI_MSG_SET_DEVICE_RESETS,
-			     TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
-			     &req, sizeof(req),
-			     &resp, sizeof(resp));
-	if (ret)
-		return ret;
-
-	return 0;
-}
-
-/**
- * ti_sci_cmd_get_device_resets() - Get reset state for device managed
- *				    by TISCI
- * @handle:		Pointer to TISCI handle
- * @id:			Device Identifier
- * @reset_state:	Pointer to reset state to populate
- *
- * Return: 0 if all went fine, else return appropriate error.
- */
-static int ti_sci_cmd_get_device_resets(const struct ti_sci_handle *handle,
-					u32 id, u32 *reset_state)
-{
-	return ti_sci_get_device_state(handle, id, NULL, reset_state, NULL,
-				       NULL);
-}
-
 /**
  * ti_sci_set_clock_state() - Set clock state helper
  * @handle:	pointer to TI SCI handle
@@ -2577,20 +2222,7 @@ static void ti_sci_setup_ops(struct ti_sci_info *info)
 	struct ti_sci_rm_udmap_ops *udmap_ops = &ops->rm_udmap_ops;
 	struct ti_sci_proc_ops *pops = &ops->proc_ops;
 
-	dops->get_device = ti_sci_cmd_get_device;
-	dops->get_device_exclusive = ti_sci_cmd_get_device_exclusive;
-	dops->idle_device = ti_sci_cmd_idle_device;
-	dops->idle_device_exclusive = ti_sci_cmd_idle_device_exclusive;
-	dops->put_device = ti_sci_cmd_put_device;
-
-	dops->is_valid = ti_sci_cmd_dev_is_valid;
-	dops->get_context_loss_count = ti_sci_cmd_dev_get_clcnt;
-	dops->is_idle = ti_sci_cmd_dev_is_idle;
-	dops->is_stop = ti_sci_cmd_dev_is_stop;
-	dops->is_on = ti_sci_cmd_dev_is_on;
-	dops->is_transitioning = ti_sci_cmd_dev_is_trans;
-	dops->set_device_resets = ti_sci_cmd_set_device_resets;
-	dops->get_device_resets = ti_sci_cmd_get_device_resets;
+	ti_sci_setup_device_ops(dops);
 
 	cops->get_clock = ti_sci_cmd_get_clock;
 	cops->idle_clock = ti_sci_cmd_idle_clock;
diff --git a/drivers/firmware/ti/ti_sci_device.c b/drivers/firmware/ti/ti_sci_device.c
new file mode 100644
index 0000000000000..cb9888ca54a35
--- /dev/null
+++ b/drivers/firmware/ti/ti_sci_device.c
@@ -0,0 +1,388 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Texas Instruments System Control Interface Protocol Driver
+ *
+ * Copyright (C) 2015-2026 Texas Instruments Incorporated - https://www.ti.com/
+ *	Nishanth Menon
+ */
+
+#include <linux/soc/ti/ti_sci_protocol.h>
+
+#include "ti_sci.h"
+
+/**
+ * ti_sci_set_device_state() - Set device state helper
+ * @handle:	pointer to TI SCI handle
+ * @id:		Device identifier
+ * @flags:	flags to setup for the device
+ * @state:	State to move the device to
+ *
+ * Return: 0 if all went well, else returns appropriate error value.
+ */
+static int ti_sci_set_device_state(const struct ti_sci_handle *handle,
+				   u32 id, u32 flags, u8 state)
+{
+	struct ti_sci_msg_req_set_device_state req;
+	struct ti_sci_msg_hdr resp;
+	int ret = 0;
+
+	req.id = id;
+	req.state = state;
+
+	ret = ti_sci_do_xfer(handle, TI_SCI_MSG_SET_DEVICE_STATE,
+			     flags | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
+			     &req, sizeof(req),
+			     &resp, sizeof(resp));
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
+/**
+ * ti_sci_get_device_state() - Get device state helper
+ * @handle:	Handle to the device
+ * @id:		Device Identifier
+ * @clcnt:	Pointer to Context Loss Count
+ * @resets:	pointer to resets
+ * @p_state:	pointer to p_state
+ * @c_state:	pointer to c_state
+ *
+ * Return: 0 if all went fine, else return appropriate error.
+ */
+static int ti_sci_get_device_state(const struct ti_sci_handle *handle,
+				   u32 id,  u32 *clcnt,  u32 *resets,
+				    u8 *p_state,  u8 *c_state)
+{
+	struct ti_sci_msg_req_get_device_state req;
+	struct ti_sci_msg_resp_get_device_state resp;
+	int ret = 0;
+
+	if (!clcnt && !resets && !p_state && !c_state)
+		return -EINVAL;
+
+	req.id = id;
+
+	ret = ti_sci_do_xfer(handle, TI_SCI_MSG_GET_DEVICE_STATE,
+			     TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
+			     &req, sizeof(req),
+			     &resp, sizeof(resp));
+	if (ret)
+		return ret;
+
+	if (clcnt)
+		*clcnt = resp.context_loss_count;
+	if (resets)
+		*resets = resp.resets;
+	if (p_state)
+		*p_state = resp.programmed_state;
+	if (c_state)
+		*c_state = resp.current_state;
+
+	return 0;
+}
+
+/**
+ * ti_sci_cmd_get_device() - command to request for device managed by TISCI
+ *			     that can be shared with other hosts.
+ * @handle:	Pointer to TISCI handle as retrieved by *ti_sci_get_handle
+ * @id:		Device Identifier
+ *
+ * Request for the device - NOTE: the client MUST maintain integrity of
+ * usage count by balancing get_device with put_device. No refcounting is
+ * managed by driver for that purpose.
+ *
+ * Return: 0 if all went fine, else return appropriate error.
+ */
+static int ti_sci_cmd_get_device(const struct ti_sci_handle *handle, u32 id)
+{
+	return ti_sci_set_device_state(handle, id, 0,
+				       MSG_DEVICE_SW_STATE_ON);
+}
+
+/**
+ * ti_sci_cmd_get_device_exclusive() - command to request for device managed by
+ *				       TISCI that is exclusively owned by the
+ *				       requesting host.
+ * @handle:	Pointer to TISCI handle as retrieved by *ti_sci_get_handle
+ * @id:		Device Identifier
+ *
+ * Request for the device - NOTE: the client MUST maintain integrity of
+ * usage count by balancing get_device with put_device. No refcounting is
+ * managed by driver for that purpose.
+ *
+ * Return: 0 if all went fine, else return appropriate error.
+ */
+static int ti_sci_cmd_get_device_exclusive(const struct ti_sci_handle *handle,
+					   u32 id)
+{
+	return ti_sci_set_device_state(handle, id,
+				       MSG_FLAG_DEVICE_EXCLUSIVE,
+				       MSG_DEVICE_SW_STATE_ON);
+}
+
+/**
+ * ti_sci_cmd_idle_device() - Command to idle a device managed by TISCI
+ * @handle:	Pointer to TISCI handle as retrieved by *ti_sci_get_handle
+ * @id:		Device Identifier
+ *
+ * Request for the device - NOTE: the client MUST maintain integrity of
+ * usage count by balancing get_device with put_device. No refcounting is
+ * managed by driver for that purpose.
+ *
+ * Return: 0 if all went fine, else return appropriate error.
+ */
+static int ti_sci_cmd_idle_device(const struct ti_sci_handle *handle, u32 id)
+{
+	return ti_sci_set_device_state(handle, id, 0,
+				       MSG_DEVICE_SW_STATE_RETENTION);
+}
+
+/**
+ * ti_sci_cmd_idle_device_exclusive() - Command to idle a device managed by
+ *					TISCI that is exclusively owned by
+ *					requesting host.
+ * @handle:	Pointer to TISCI handle as retrieved by *ti_sci_get_handle
+ * @id:		Device Identifier
+ *
+ * Request for the device - NOTE: the client MUST maintain integrity of
+ * usage count by balancing get_device with put_device. No refcounting is
+ * managed by driver for that purpose.
+ *
+ * Return: 0 if all went fine, else return appropriate error.
+ */
+static int ti_sci_cmd_idle_device_exclusive(const struct ti_sci_handle *handle,
+					    u32 id)
+{
+	return ti_sci_set_device_state(handle, id,
+				       MSG_FLAG_DEVICE_EXCLUSIVE,
+				       MSG_DEVICE_SW_STATE_RETENTION);
+}
+
+/**
+ * ti_sci_cmd_put_device() - command to release a device managed by TISCI
+ * @handle:	Pointer to TISCI handle as retrieved by *ti_sci_get_handle
+ * @id:		Device Identifier
+ *
+ * Request for the device - NOTE: the client MUST maintain integrity of
+ * usage count by balancing get_device with put_device. No refcounting is
+ * managed by driver for that purpose.
+ *
+ * Return: 0 if all went fine, else return appropriate error.
+ */
+static int ti_sci_cmd_put_device(const struct ti_sci_handle *handle, u32 id)
+{
+	return ti_sci_set_device_state(handle, id,
+				       0, MSG_DEVICE_SW_STATE_AUTO_OFF);
+}
+
+/**
+ * ti_sci_cmd_dev_is_valid() - Is the device valid
+ * @handle:	Pointer to TISCI handle as retrieved by *ti_sci_get_handle
+ * @id:		Device Identifier
+ *
+ * Return: 0 if all went fine and the device ID is valid, else return
+ * appropriate error.
+ */
+static int ti_sci_cmd_dev_is_valid(const struct ti_sci_handle *handle, u32 id)
+{
+	u8 unused;
+
+	/* check the device state which will also tell us if the ID is valid */
+	return ti_sci_get_device_state(handle, id, NULL, NULL, NULL, &unused);
+}
+
+/**
+ * ti_sci_cmd_dev_get_clcnt() - Get context loss counter
+ * @handle:	Pointer to TISCI handle
+ * @id:		Device Identifier
+ * @count:	Pointer to Context Loss counter to populate
+ *
+ * Return: 0 if all went fine, else return appropriate error.
+ */
+static int ti_sci_cmd_dev_get_clcnt(const struct ti_sci_handle *handle, u32 id,
+				    u32 *count)
+{
+	return ti_sci_get_device_state(handle, id, count, NULL, NULL, NULL);
+}
+
+/**
+ * ti_sci_cmd_dev_is_idle() - Check if the device is requested to be idle
+ * @handle:	Pointer to TISCI handle
+ * @id:		Device Identifier
+ * @r_state:	true if requested to be idle
+ *
+ * Return: 0 if all went fine, else return appropriate error.
+ */
+static int ti_sci_cmd_dev_is_idle(const struct ti_sci_handle *handle, u32 id,
+				  bool *r_state)
+{
+	int ret;
+	u8 state;
+
+	if (!r_state)
+		return -EINVAL;
+
+	ret = ti_sci_get_device_state(handle, id, NULL, NULL, &state, NULL);
+	if (ret)
+		return ret;
+
+	*r_state = (state == MSG_DEVICE_SW_STATE_RETENTION);
+
+	return 0;
+}
+
+/**
+ * ti_sci_cmd_dev_is_stop() - Check if the device is requested to be stopped
+ * @handle:	Pointer to TISCI handle
+ * @id:		Device Identifier
+ * @r_state:	true if requested to be stopped
+ * @curr_state:	true if currently stopped.
+ *
+ * Return: 0 if all went fine, else return appropriate error.
+ */
+static int ti_sci_cmd_dev_is_stop(const struct ti_sci_handle *handle, u32 id,
+				  bool *r_state,  bool *curr_state)
+{
+	int ret;
+	u8 p_state, c_state;
+
+	if (!r_state && !curr_state)
+		return -EINVAL;
+
+	ret =
+	    ti_sci_get_device_state(handle, id, NULL, NULL, &p_state, &c_state);
+	if (ret)
+		return ret;
+
+	if (r_state)
+		*r_state = (p_state == MSG_DEVICE_SW_STATE_AUTO_OFF);
+	if (curr_state)
+		*curr_state = (c_state == MSG_DEVICE_HW_STATE_OFF);
+
+	return 0;
+}
+
+/**
+ * ti_sci_cmd_dev_is_on() - Check if the device is requested to be ON
+ * @handle:	Pointer to TISCI handle
+ * @id:		Device Identifier
+ * @r_state:	true if requested to be ON
+ * @curr_state:	true if currently ON and active
+ *
+ * Return: 0 if all went fine, else return appropriate error.
+ */
+static int ti_sci_cmd_dev_is_on(const struct ti_sci_handle *handle, u32 id,
+				bool *r_state,  bool *curr_state)
+{
+	int ret;
+	u8 p_state, c_state;
+
+	if (!r_state && !curr_state)
+		return -EINVAL;
+
+	ret =
+	    ti_sci_get_device_state(handle, id, NULL, NULL, &p_state, &c_state);
+	if (ret)
+		return ret;
+
+	if (r_state)
+		*r_state = (p_state == MSG_DEVICE_SW_STATE_ON);
+	if (curr_state)
+		*curr_state = (c_state == MSG_DEVICE_HW_STATE_ON);
+
+	return 0;
+}
+
+/**
+ * ti_sci_cmd_dev_is_trans() - Check if the device is currently transitioning
+ * @handle:	Pointer to TISCI handle
+ * @id:		Device Identifier
+ * @curr_state:	true if currently transitioning.
+ *
+ * Return: 0 if all went fine, else return appropriate error.
+ */
+static int ti_sci_cmd_dev_is_trans(const struct ti_sci_handle *handle, u32 id,
+				   bool *curr_state)
+{
+	int ret;
+	u8 state;
+
+	if (!curr_state)
+		return -EINVAL;
+
+	ret = ti_sci_get_device_state(handle, id, NULL, NULL, NULL, &state);
+	if (ret)
+		return ret;
+
+	*curr_state = (state == MSG_DEVICE_HW_STATE_TRANS);
+
+	return 0;
+}
+
+/**
+ * ti_sci_cmd_set_device_resets() - command to set resets for device managed
+ *				    by TISCI
+ * @handle:	Pointer to TISCI handle as retrieved by *ti_sci_get_handle
+ * @id:		Device Identifier
+ * @reset_state: Device specific reset bit field
+ *
+ * Return: 0 if all went fine, else return appropriate error.
+ */
+static int ti_sci_cmd_set_device_resets(const struct ti_sci_handle *handle,
+					u32 id, u32 reset_state)
+{
+	struct ti_sci_msg_req_set_device_resets req;
+	struct ti_sci_msg_hdr resp;
+	int ret = 0;
+
+	req.id = id;
+	req.resets = reset_state;
+
+	ret = ti_sci_do_xfer(handle, TI_SCI_MSG_SET_DEVICE_RESETS,
+			     TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
+			     &req, sizeof(req),
+			     &resp, sizeof(resp));
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
+/**
+ * ti_sci_cmd_get_device_resets() - Get reset state for device managed
+ *				    by TISCI
+ * @handle:		Pointer to TISCI handle
+ * @id:			Device Identifier
+ * @reset_state:	Pointer to reset state to populate
+ *
+ * Return: 0 if all went fine, else return appropriate error.
+ */
+static int ti_sci_cmd_get_device_resets(const struct ti_sci_handle *handle,
+					u32 id, u32 *reset_state)
+{
+	return ti_sci_get_device_state(handle, id, NULL, reset_state, NULL,
+				       NULL);
+}
+
+/*
+ * ti_sci_setup_device_ops() - Setup the device operations structures
+ * @dops:	pointer to TISCI device ops structure
+ */
+void ti_sci_setup_device_ops(struct ti_sci_dev_ops *dops)
+{
+	dops->get_device = ti_sci_cmd_get_device;
+	dops->get_device_exclusive = ti_sci_cmd_get_device_exclusive;
+	dops->idle_device = ti_sci_cmd_idle_device;
+	dops->idle_device_exclusive = ti_sci_cmd_idle_device_exclusive;
+	dops->put_device = ti_sci_cmd_put_device;
+
+	dops->is_valid = ti_sci_cmd_dev_is_valid;
+	dops->get_context_loss_count = ti_sci_cmd_dev_get_clcnt;
+	dops->is_idle = ti_sci_cmd_dev_is_idle;
+	dops->is_stop = ti_sci_cmd_dev_is_stop;
+	dops->is_on = ti_sci_cmd_dev_is_on;
+	dops->is_transitioning = ti_sci_cmd_dev_is_trans;
+	dops->set_device_resets = ti_sci_cmd_set_device_resets;
+	dops->get_device_resets = ti_sci_cmd_get_device_resets;
+}
-- 
2.34.1


  parent reply	other threads:[~2026-10-29 18:13 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-29 18:11 [PATCH v3 00/22] Cleanup and Refactor TI-SCI driver Beleswar Padhi
2026-10-29 18:11 ` [PATCH v3 01/22] firmware: ti_sci: Move error message handling into ti_sci_get_one_xfer() Beleswar Padhi
2026-10-29 18:11 ` [PATCH v3 02/22] firmware: ti_sci: Move error message handling into ti_sci_do_xfer() Beleswar Padhi
2026-10-29 18:11 ` [PATCH v3 03/22] firmware: ti_sci: Move check for ACK " Beleswar Padhi
2026-10-29 18:11 ` [PATCH v3 04/22] firmware: ti_sci: Remove out of place RM debug messages Beleswar Padhi
2026-10-29 18:11 ` [PATCH v3 05/22] firmware: ti_sci: Name response variable resp for consistency Beleswar Padhi
2026-10-29 18:11 ` [PATCH v3 06/22] firmware: ti_sci: Handle xfer cleanup inside ti_sci_do_xfer() Beleswar Padhi
2026-10-29 18:11 ` [PATCH v3 07/22] firmware: ti_sci: Pass request struct into ti_sci_do_xfer() Beleswar Padhi
2026-10-29 18:11 ` [PATCH v3 08/22] firmware: ti_sci: Combine xfer allocation and transfer functions Beleswar Padhi
2026-10-29 18:11 ` [PATCH v3 09/22] firmware: ti_sci: Fetch info struct from handle inside ti_sci_do_xfer() Beleswar Padhi
2026-10-29 18:11 ` [PATCH v3 10/22] firmware: ti_sci: Use tx_message as message buffer directly Beleswar Padhi
2026-10-29 18:11 ` [PATCH v3 11/22] firmware: ti_sci: Use rx_message as message receive buffer Beleswar Padhi
2026-10-29 18:11 ` [PATCH v3 12/22] firmware: ti_sci: Fix some kernel-doc references in structs Beleswar Padhi
2026-10-29 18:11 ` [PATCH v3 13/22] soc: ti: ti_sci_protocol.h: Add missing documentation for structs Beleswar Padhi
2026-10-29 18:11 ` [PATCH v3 14/22] firmware: ti_sci: Do not export reboot control Beleswar Padhi
2026-10-29 18:11 ` [PATCH v3 15/22] firmware: ti_sci: Use pmops fxn pointers in suspend/resume hooks Beleswar Padhi
2026-10-29 18:11 ` [PATCH v3 16/22] firmware: ti_sci: Move the huge ti_sci file into its own directory Beleswar Padhi
2026-10-29 18:11 ` [PATCH v3 17/22] firmware: ti: ti_sci: Add missing includes for self-contained headers Beleswar Padhi
2026-10-29 18:11 ` Beleswar Padhi [this message]
2026-10-29 18:11 ` [PATCH v3 19/22] firmware: ti: ti_sci_clock: Move clock ops into its own file Beleswar Padhi
2026-10-29 18:11 ` [PATCH v3 20/22] firmware: ti: ti_sci_pm: Move pm " Beleswar Padhi
2026-10-29 18:11 ` [PATCH v3 21/22] firmware: ti: ti_sci_rm: Move rm " Beleswar Padhi
2026-10-29 18:11 ` [PATCH v3 22/22] firmware: ti: ti_sci_proc: Move processor " Beleswar Padhi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261029181147.266771-19-b-padhi@ti.com \
    --to=b-padhi@ti.com \
    --cc=afd@ti.com \
    --cc=kristo@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nm@ti.com \
    --cc=ssantosh@kernel.org \
    --cc=u-kumar1@ti.com \
    --cc=vigneshr@ti.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®