blob: 8ecdb93c7a2ac42bf84335aa95ed3db296422a33 [file] [log] [blame]
Channagoud Kadabi9f7641b2015-01-08 19:17:06 -08001/* Copyright (c) 2014-2015, The Linux Foundation. All rights reserved.
Channagoud Kadabiffaea422014-12-05 15:45:41 -08002
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
12 * * Neither the name of The Linux Foundation. nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <platform/partial_goods.h>
30#include <libfdt.h>
31#include <reg.h>
32#include <debug.h>
33
34void update_partial_goods_dtb_nodes(void *fdt)
35{
36 int i;
37 int tbl_sz = sizeof(table) / sizeof(struct partial_goods);
38 int parent_offset = 0;
39 int subnode_offset = 0;
40 int ret = 0;
41 int prop_len = 0;
42 uint32_t reg = readl(QFPROM_PTE_PART_ADDR);
Channagoud Kadabi9f7641b2015-01-08 19:17:06 -080043 uint32_t prop_type = 0;
Channagoud Kadabiffaea422014-12-05 15:45:41 -080044 struct subnode_list *subnode_lst = NULL;
45 const struct fdt_property *prop = NULL;
Channagoud Kadabi9f7641b2015-01-08 19:17:06 -080046 const char *replace_str = NULL;
Channagoud Kadabiffaea422014-12-05 15:45:41 -080047
48 /* If none of the DTB needs update */
49 if (!reg)
50 return;
51
52 ret = fdt_open_into(fdt, fdt, fdt_totalsize(fdt));
53 if (ret != 0)
54 {
55 dprintf(CRITICAL, "Failed to move/resize dtb buffer: %d\n", ret);
56 ASSERT(0);
57 }
58
59 for (i = 0; i < tbl_sz; i++)
60 {
61 if (reg == table[i].val)
62 {
63 /* Find the Parent node */
64 ret = fdt_path_offset(fdt, table[i].parent_node);
65 if (ret < 0)
66 {
67 dprintf(CRITICAL, "Failed to get parent node: %s\terrno:%d\n", table[i].parent_node, ret);
68 ASSERT(0);
69 }
70 parent_offset = ret;
71
72 /* Find the subnode */
73 subnode_lst = table[i].subnode;
74
75 while (subnode_lst->subnode)
76 {
77 ret = fdt_subnode_offset(fdt, parent_offset, subnode_lst->subnode);
78 if (ret < 0)
79 {
80 dprintf(CRITICAL, "Failed to get subnode: %s\terrno:%d\n", subnode_lst->subnode, ret);
81 ASSERT(0);
82 }
83 subnode_offset = ret;
84
85 /* Find the property node and its length */
86 prop = fdt_get_property(fdt, subnode_offset, subnode_lst->property, &prop_len);
87 if (!prop)
88 {
89 dprintf(CRITICAL, "Failed to get property: %s\terrno: %d\n", subnode_lst->property, prop_len);
90 ASSERT(0);
91 }
92
93 /*
94 * Replace the property value based on the property
95 * length and type
96 */
97 if (!(strncmp(subnode_lst->property, "device_type", sizeof(subnode_lst->property))))
98 prop_type = DEVICE_TYPE;
99 else if ((!strncmp(subnode_lst->property, "status", sizeof(subnode_lst->property))))
100 prop_type = STATUS_TYPE;
101 else
102 {
103 dprintf(CRITICAL, "%s: Property type is not supported\n", subnode_lst->property);
104 ASSERT(0);
105 }
106
107 switch (prop_type)
108 {
109 case DEVICE_TYPE:
110 replace_str = "nak";
111 break;
112 case STATUS_TYPE:
113 if (prop_len == sizeof("ok"))
114 replace_str = "no";
Channagoud Kadabi9f7641b2015-01-08 19:17:06 -0800115 else if (prop_len == sizeof("okay"))
Channagoud Kadabiffaea422014-12-05 15:45:41 -0800116 replace_str = "dsbl";
117 else
118 {
119 dprintf(CRITICAL, "Property value length: %u is invalid for property: %s\n", prop_len, subnode_lst->property);
120 ASSERT(0);
121 }
122 break;
123 default:
124 /* Control would not come here, as this gets taken care while setting property type */
125 break;
126 };
127
128 /* Replace the property with new value */
129 ret = fdt_setprop_inplace(fdt, subnode_offset, subnode_lst->property, (const void *)replace_str, prop_len);
130 if (!ret)
131 dprintf(INFO, "Updated device tree property: %s @ %s node\n", subnode_lst->property, subnode_lst->subnode);
132 else
133 {
134 dprintf(CRITICAL, "Failed to update property: %s: error no: %d\n", subnode_lst->property, ret);
135 ASSERT(0);
136 }
137
138 subnode_lst++;
139 }
140 }
141 }
142
143 fdt_pack(fdt);
144}