tisci: Add support for handling devices
authorLokesh Vutla <lokeshvutla@ti.com>
Tue, 20 Aug 2019 15:07:32 +0000 (20:37 +0530)
committerLokesh Vutla <lokeshvutla@ti.com>
Sun, 25 Aug 2019 03:14:04 +0000 (08:44 +0530)
Add support for the following tisci commands for handling devices:
- ti_sci_cmd_enable_device
- ti_sci_cmd_disable_device
- ti_sci_get_device_status

Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
Makefile
common/tisci/tisci_device.c [new file with mode: 0644]
include/tisci.h
include/tisci_protocol.h

index 3f51dece55c6e66c393710c705d3a9c2ae1fff06..b06a8296479b92df3b4913e4f24975c00d182ffc 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -62,7 +62,8 @@ COMMONSOURCES=\
                common/mmio.c \
                common/socinfo.c \
                common/sec_proxy.c \
-               common/tisci/tisci_core.c
+               common/tisci/tisci_core.c \
+               common/tisci/tisci_device.c
 
 COMMONOBJECTS= $(COMMONSOURCES:.c=.o)
 
diff --git a/common/tisci/tisci_device.c b/common/tisci/tisci_device.c
new file mode 100644 (file)
index 0000000..cc0fd1e
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ * TISCI device ops library
+ *
+ * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/
+ *     Lokesh Vutla <lokeshvutla@ti.com>
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions
+ *  are met:
+ *
+ *    Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ *    Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the
+ *    distribution.
+ *
+ *    Neither the name of Texas Instruments Incorporated nor the names of
+ *    its contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <string.h>
+#include <tisci_protocol.h>
+#include <tisci.h>
+
+static const char device_state[MAX_DEVICE_HW_STATES + 1][MAX_DEVICE_STATE_LENGTH] = {
+       [MSG_DEVICE_HW_STATE_OFF] = "DEVICE_STATE_OFF",
+       [MSG_DEVICE_HW_STATE_ON] = "DEVICE_STATE_ON",
+       [MSG_DEVICE_HW_STATE_TRANS] = "DEVICE_STATE_TRANS",
+       [MAX_DEVICE_HW_STATES] = "DEVICE_STATE_UNKNOWN"
+};
+
+static int ti_sci_set_device_state(uint32_t id, uint32_t flags, uint8_t state)
+{
+       struct ti_sci_msg_req_set_device_state *req;
+       uint8_t buf[SEC_PROXY_MAX_MSG_SIZE];
+       struct k3_sec_proxy_msg msg;
+
+       memset(buf, 0, sizeof(buf));
+       ti_sci_setup_header((struct ti_sci_msg_hdr *)buf,
+                           TI_SCI_MSG_SET_DEVICE_STATE, flags);
+       req = (struct ti_sci_msg_req_set_device_state *)buf;
+       req->id = id;
+       req->state = state;
+
+       msg.len = sizeof(*req);
+       msg.buf = buf;
+       return ti_sci_xfer_msg(&msg);
+}
+
+int ti_sci_cmd_enable_device(uint32_t dev_id)
+{
+       return ti_sci_set_device_state(dev_id, 0, MSG_DEVICE_SW_STATE_ON);
+}
+
+int ti_sci_cmd_disable_device(uint32_t dev_id)
+{
+       return ti_sci_set_device_state(dev_id, 0, MSG_DEVICE_SW_STATE_AUTO_OFF);
+}
+
+const char *ti_sci_cmd_get_device_status(uint32_t dev_id)
+{
+       struct ti_sci_msg_resp_get_device_state *resp;
+       struct ti_sci_msg_req_get_device_state *req;
+       uint8_t buf[SEC_PROXY_MAX_MSG_SIZE];
+       struct k3_sec_proxy_msg msg;
+       int ret = 0;
+
+       memset(buf, 0, sizeof(buf));
+       ti_sci_setup_header((struct ti_sci_msg_hdr *)buf,
+                           TI_SCI_MSG_GET_DEVICE_STATE, 0);
+       req = (struct ti_sci_msg_req_get_device_state *)buf;
+       req->id = dev_id;
+
+       msg.len = sizeof(*req);
+       msg.buf = buf;
+       ret = ti_sci_xfer_msg(&msg);
+       if (ret)
+               return NULL;
+
+       resp = (struct ti_sci_msg_resp_get_device_state *)buf;
+
+       return device_state[resp->current_state];
+}
index 43faefe40992b57bbb79b022c2e6d46ce6bc607c..c339de7b2c6dd0ec704e02ad69300f51352e5ea7 100644 (file)
@@ -50,5 +50,11 @@ struct ti_sci_info {
        struct ti_sci_version_info version;
 };
 
+#define MAX_DEVICE_STATE_LENGTH                25
+
 int ti_sci_init(void);
+const char *ti_sci_cmd_get_device_status(uint32_t dev_id);
+int ti_sci_cmd_disable_device(uint32_t dev_id);
+int ti_sci_cmd_enable_device(uint32_t dev_id);
+
 #endif
index b40baec1adbde785b7f22100e716fb22ed7da221..78dec078b3b7ce8823eac00662a7e603a6c1795f 100644 (file)
@@ -40,6 +40,9 @@
 #include <sec_proxy.h>
 
 #define TI_SCI_MSG_VERSION             0x0002
+/* Device requests */
+#define TI_SCI_MSG_SET_DEVICE_STATE    0x0200
+#define TI_SCI_MSG_GET_DEVICE_STATE    0x0201
 
 #define TI_SCI_MSG_FLAG(val)                   (1 << (val))
 #define TI_SCI_FLAG_REQ_GENERIC_NORESPONSE     0x0
@@ -68,6 +71,39 @@ struct ti_sci_secure_msg_hdr {
        uint16_t reserved;
 } __attribute__ ((__packed__));
 
+struct ti_sci_msg_req_set_device_state {
+       /* Additional hdr->flags options */
+#define MSG_FLAG_DEVICE_WAKE_ENABLED   TI_SCI_MSG_FLAG(8)
+#define MSG_FLAG_DEVICE_RESET_ISO      TI_SCI_MSG_FLAG(9)
+#define MSG_FLAG_DEVICE_EXCLUSIVE      TI_SCI_MSG_FLAG(10)
+       struct ti_sci_msg_hdr hdr;
+       uint32_t id;
+       uint32_t reserved;
+#define MSG_DEVICE_SW_STATE_AUTO_OFF   0
+#define MSG_DEVICE_SW_STATE_RETENTION  1
+#define MSG_DEVICE_SW_STATE_ON         2
+       uint8_t state;
+} __attribute__ ((__packed__));
+
+struct ti_sci_msg_req_get_device_state {
+       struct ti_sci_msg_hdr hdr;
+       uint32_t id;
+} __attribute__ ((__packed__));
+
+struct ti_sci_msg_resp_get_device_state {
+       struct ti_sci_msg_hdr hdr;
+       uint32_t context_loss_count;
+       uint32_t resets;
+       uint8_t programmed_state;
+#define MSG_DEVICE_HW_STATE_OFF                0
+#define MSG_DEVICE_HW_STATE_ON         1
+#define MSG_DEVICE_HW_STATE_TRANS      2
+#define MAX_DEVICE_HW_STATES           3
+       uint8_t current_state;
+} __attribute__ ((__packed__));
+
+void ti_sci_setup_header(struct ti_sci_msg_hdr *hdr, uint16_t type,
+                        uint32_t flags);
 int ti_sci_xfer_msg(struct k3_sec_proxy_msg *msg);
 
 static inline uint8_t ti_sci_is_response_ack(uint8_t *resp)