]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - k3conf/k3conf.git/blob - common/tisci/tisci_device.c
tisci: Add support for handling clocks
[k3conf/k3conf.git] / common / tisci / tisci_device.c
1 /*
2  * TISCI device ops library
3  *
4  * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/
5  *      Lokesh Vutla <lokeshvutla@ti.com>
6  *
7  *  Redistribution and use in source and binary forms, with or without
8  *  modification, are permitted provided that the following conditions
9  *  are met:
10  *
11  *    Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  *
14  *    Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the
17  *    distribution.
18  *
19  *    Neither the name of Texas Instruments Incorporated nor the names of
20  *    its contributors may be used to endorse or promote products derived
21  *    from this software without specific prior written permission.
22  *
23  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
36 #include <string.h>
37 #include <tisci_protocol.h>
38 #include <tisci.h>
40 static const char device_state[MAX_DEVICE_HW_STATES + 1][MAX_DEVICE_STATE_LENGTH] = {
41         [MSG_DEVICE_HW_STATE_OFF] = "DEVICE_STATE_OFF",
42         [MSG_DEVICE_HW_STATE_ON] = "DEVICE_STATE_ON",
43         [MSG_DEVICE_HW_STATE_TRANS] = "DEVICE_STATE_TRANS",
44         [MAX_DEVICE_HW_STATES] = "DEVICE_STATE_UNKNOWN"
45 };
47 static int ti_sci_set_device_state(uint32_t id, uint32_t flags, uint8_t state)
48 {
49         struct ti_sci_msg_req_set_device_state *req;
50         uint8_t buf[SEC_PROXY_MAX_MSG_SIZE];
51         struct k3_sec_proxy_msg msg;
53         memset(buf, 0, sizeof(buf));
54         ti_sci_setup_header((struct ti_sci_msg_hdr *)buf,
55                             TI_SCI_MSG_SET_DEVICE_STATE, flags);
56         req = (struct ti_sci_msg_req_set_device_state *)buf;
57         req->id = id;
58         req->state = state;
60         msg.len = sizeof(*req);
61         msg.buf = buf;
62         return ti_sci_xfer_msg(&msg);
63 }
65 int ti_sci_cmd_enable_device(uint32_t dev_id)
66 {
67         return ti_sci_set_device_state(dev_id, 0, MSG_DEVICE_SW_STATE_ON);
68 }
70 int ti_sci_cmd_disable_device(uint32_t dev_id)
71 {
72         return ti_sci_set_device_state(dev_id, 0, MSG_DEVICE_SW_STATE_AUTO_OFF);
73 }
75 const char *ti_sci_cmd_get_device_status(uint32_t dev_id)
76 {
77         struct ti_sci_msg_resp_get_device_state *resp;
78         struct ti_sci_msg_req_get_device_state *req;
79         uint8_t buf[SEC_PROXY_MAX_MSG_SIZE];
80         struct k3_sec_proxy_msg msg;
81         int ret = 0;
83         memset(buf, 0, sizeof(buf));
84         ti_sci_setup_header((struct ti_sci_msg_hdr *)buf,
85                             TI_SCI_MSG_GET_DEVICE_STATE, 0);
86         req = (struct ti_sci_msg_req_get_device_state *)buf;
87         req->id = dev_id;
89         msg.len = sizeof(*req);
90         msg.buf = buf;
91         ret = ti_sci_xfer_msg(&msg);
92         if (ret)
93                 return NULL;
95         resp = (struct ti_sci_msg_resp_get_device_state *)buf;
97         return device_state[resp->current_state];
98 }