]> git.karo-electronics.de Git - karo-tx-uboot.git/blob - include/power/pmic-qcom-smd-rpm.h
misc: add support for Qualcomm SMD protocol
[karo-tx-uboot.git] / include / power / pmic-qcom-smd-rpm.h
1 /*
2  * Copyright (C) 2017, Lothar Waßmann <LW@KARO-electronics.de>
3  *
4  * SPDX-License-Identifier:     GPL-2.0+
5  *
6  * based on: platform/msm_shared/include/rpm-smd.h
7  * from Android Little Kernel: https://github.com/littlekernel/lk
8  *
9  * Copyright (c) 2014, The Linux Foundation. All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions are
13  * met:
14  *     * Redistributions of source code must retain the above copyright
15  *       notice, this list of conditions and the following disclaimer.
16  *     * Redistributions in binary form must reproduce the above
17  *       copyright notice, this list of conditions and the following
18  *       disclaimer in the documentation and/or other materials provided
19  *       with the distribution.
20  *     * Neither the name of The Linux Fundation, Inc. nor the names of its
21  *       contributors may be used to endorse or promote products derived
22  *       from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
25  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
28  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
31  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
33  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
34  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35  *
36  */
37
38 #ifndef __PMIC_QCOM_SMD_RPM_H
39 #define __PMIC_QCOM_SMD_RPM_H
40
41 #define KEY_SOFTWARE_ENABLE             0x6E657773 // swen - software enable
42 #define KEY_LDO_SOFTWARE_MODE           0X646D736C // lsmd - LDO software mode
43 #define KEY_SMPS_SOFTWARE_MODE          0X646D7373 // ssmd - SMPS software mode
44 #define KEY_PIN_CTRL_ENABLE             0x6E656370 //pcen - pin control enable
45 #define KEY_PIN_CTRL_POWER_MODE         0x646d6370 // pcmd - pin control mode
46 #define KEY_CURRENT                     0x616D //ma
47 #define KEY_MICRO_VOLT                  0x7675 //uv
48 #define KEY_FREQUENCY                   0x71657266 //freq
49 #define KEY_FREQUENCY_REASON            0x6E736572 //resn
50 #define KEY_FOLLOW_QUIET_MODE           0x6D71 //qm
51 #define KEY_HEAD_ROOM                   0x7268 // hr
52 #define KEY_PIN_CTRL_CLK_BUFFER_ENABLE_KEY 0x62636370 // pccb - clk buffer pin control
53 #define KEY_BYPASS_ALLOWED_KEY          0x61707962 //bypa - bypass allowed
54 #define KEY_CORNER_LEVEL_KEY            0x6E726F63 // corn - coner voltage
55 #define KEY_ACTIVE_FLOOR                0x636676
56 #define GENERIC_DISABLE                 0
57 #define GENERIC_ENABLE                  1
58 #define SW_MODE_LDO_IPEAK               1
59 #define LDOA_RES_TYPE                   0x616F646C //aodl
60 #define SMPS_RES_TYPE                   0x61706D73 //apms
61
62 #ifdef CONFIG_QCOM_SMD_RPM
63 typedef enum {
64         RPM_REQUEST_TYPE,
65         RPM_CMD_TYPE,
66         RPM_SUCCESS_REQ_ACK,
67         RPM_SUCCESS_CMD_ACK,
68         RPM_ERROR_ACK,
69 } msg_type;
70
71 enum {
72         RESOURCETYPE,
73         RESOURCEID,
74         KVP_KEY,
75         KVP_LENGTH,
76         KVP_VALUE,
77 };
78
79 typedef struct {
80         uint32_t type;
81         uint32_t len;
82 } rpm_gen_hdr;
83
84 typedef struct {
85         uint32_t key;
86         uint32_t len;
87         uint32_t val;
88 } kvp_data;
89
90 typedef struct {
91         uint32_t id;
92         uint32_t set;
93         uint32_t resourceType;
94         uint32_t resourceId;
95         uint32_t dataLength;
96 } rpm_req_hdr;
97
98 typedef struct {
99         rpm_gen_hdr hdr;
100         rpm_req_hdr req_hdr;
101         uint32_t payload[];
102 } rpm_req;
103
104 typedef struct {
105         rpm_gen_hdr hdr;
106         kvp_data *data;
107 } rpm_cmd;
108
109 typedef struct {
110         rpm_gen_hdr hdr;
111         uint32_t id;
112         uint32_t len;
113         uint32_t seq;
114 } rpm_ack_msg;
115
116 int rpm_send_data(uint32_t *data, uint32_t len, msg_type type);
117 uint32_t rpm_recv_data(uint32_t *data, uint32_t *len);
118 void rpm_clk_enable(uint32_t *data, uint32_t len);
119 void rpm_clk_disable(uint32_t *data, uint32_t len);
120 void smd_rpm_init(void);
121 void smd_rpm_uninit(void);
122 #else /* !CONFIG_QCOM_SMD_RPM */
123 static inline void smd_rpm_init(void)
124 {
125 }
126
127 static inline void smd_rpm_uninit(void)
128 {
129 }
130 #endif /* !CONFIG_QCOM_SMD_RPM */
131
132 #endif /* __PMIC_QCOM_SMD_RPM_H */