]> git.ipfire.org Git - thirdparty/u-boot.git/blame - drivers/misc/imx8ulp/s400_api.c
drivers: misc: imx8ulp: Update S400 API for release RDC
[thirdparty/u-boot.git] / drivers / misc / imx8ulp / s400_api.c
CommitLineData
0c00d03a
YL
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright 2020 NXP
4 *
5 */
6
7#include <common.h>
8#include <hang.h>
9#include <malloc.h>
10#include <asm/io.h>
11#include <dm.h>
12#include <asm/arch/s400_api.h>
13#include <misc.h>
14
15DECLARE_GLOBAL_DATA_PTR;
16
7aeaf4d9 17int ahab_release_rdc(u8 core_id, bool xrdc, u32 *response)
0c00d03a
YL
18{
19 struct udevice *dev = gd->arch.s400_dev;
20 int size = sizeof(struct imx8ulp_s400_msg);
21 struct imx8ulp_s400_msg msg;
22 int ret;
23
24 if (!dev) {
25 printf("s400 dev is not initialized\n");
26 return -ENODEV;
27 }
28
29 msg.version = AHAB_VERSION;
30 msg.tag = AHAB_CMD_TAG;
31 msg.size = 2;
32 msg.command = AHAB_RELEASE_RDC_REQ_CID;
7aeaf4d9
YL
33 if (xrdc)
34 msg.data[0] = (0x78 << 8) | core_id;
35 else
36 msg.data[0] = (0x74 << 8) | core_id;
0c00d03a
YL
37
38 ret = misc_call(dev, false, &msg, size, &msg, size);
39 if (ret)
40 printf("Error: %s: ret %d, core id %u, response 0x%x\n",
41 __func__, ret, core_id, msg.data[0]);
42
6306f75d
YL
43 if (response)
44 *response = msg.data[0];
45
46 return ret;
47}
48
49int ahab_auth_oem_ctnr(ulong ctnr_addr, u32 *response)
50{
51 struct udevice *dev = gd->arch.s400_dev;
52 int size = sizeof(struct imx8ulp_s400_msg);
53 struct imx8ulp_s400_msg msg;
54 int ret;
55
56 if (!dev) {
57 printf("s400 dev is not initialized\n");
58 return -ENODEV;
59 }
60
61 msg.version = AHAB_VERSION;
62 msg.tag = AHAB_CMD_TAG;
63 msg.size = 3;
64 msg.command = AHAB_AUTH_OEM_CTNR_CID;
65 msg.data[0] = upper_32_bits(ctnr_addr);
66 msg.data[1] = lower_32_bits(ctnr_addr);
67
68 ret = misc_call(dev, false, &msg, size, &msg, size);
69 if (ret)
70 printf("Error: %s: ret %d, cntr_addr 0x%lx, response 0x%x\n",
71 __func__, ret, ctnr_addr, msg.data[0]);
72
73 if (response)
74 *response = msg.data[0];
75
76 return ret;
77}
78
79int ahab_release_container(u32 *response)
80{
81 struct udevice *dev = gd->arch.s400_dev;
82 int size = sizeof(struct imx8ulp_s400_msg);
83 struct imx8ulp_s400_msg msg;
84 int ret;
85
86 if (!dev) {
87 printf("s400 dev is not initialized\n");
88 return -ENODEV;
89 }
90
91 msg.version = AHAB_VERSION;
92 msg.tag = AHAB_CMD_TAG;
93 msg.size = 1;
94 msg.command = AHAB_RELEASE_CTNR_CID;
95
96 ret = misc_call(dev, false, &msg, size, &msg, size);
97 if (ret)
98 printf("Error: %s: ret %d, response 0x%x\n",
99 __func__, ret, msg.data[0]);
100
101 if (response)
102 *response = msg.data[0];
103
104 return ret;
105}
106
107int ahab_verify_image(u32 img_id, u32 *response)
108{
109 struct udevice *dev = gd->arch.s400_dev;
110 int size = sizeof(struct imx8ulp_s400_msg);
111 struct imx8ulp_s400_msg msg;
112 int ret;
113
114 if (!dev) {
115 printf("s400 dev is not initialized\n");
116 return -ENODEV;
117 }
118
119 msg.version = AHAB_VERSION;
120 msg.tag = AHAB_CMD_TAG;
121 msg.size = 2;
122 msg.command = AHAB_VERIFY_IMG_CID;
123 msg.data[0] = 1 << img_id;
124
125 ret = misc_call(dev, false, &msg, size, &msg, size);
126 if (ret)
127 printf("Error: %s: ret %d, img_id %u, response 0x%x\n",
128 __func__, ret, img_id, msg.data[0]);
129
130 if (response)
131 *response = msg.data[0];
132
133 return ret;
134}
135
136int ahab_forward_lifecycle(u16 life_cycle, u32 *response)
137{
138 struct udevice *dev = gd->arch.s400_dev;
139 int size = sizeof(struct imx8ulp_s400_msg);
140 struct imx8ulp_s400_msg msg;
141 int ret;
142
143 if (!dev) {
144 printf("s400 dev is not initialized\n");
145 return -ENODEV;
146 }
147
148 msg.version = AHAB_VERSION;
149 msg.tag = AHAB_CMD_TAG;
150 msg.size = 2;
151 msg.command = AHAB_FWD_LIFECYCLE_UP_REQ_CID;
152 msg.data[0] = life_cycle;
153
154 ret = misc_call(dev, false, &msg, size, &msg, size);
155 if (ret)
156 printf("Error: %s: ret %d, life_cycle 0x%x, response 0x%x\n",
157 __func__, ret, life_cycle, msg.data[0]);
158
159 if (response)
160 *response = msg.data[0];
161
0c00d03a
YL
162 return ret;
163}