Channagoud Kadabi | 9f7641b | 2015-01-08 19:17:06 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2014-2015, The Linux Foundation. All rights reserved. |
Channagoud Kadabi | ffaea42 | 2014-12-05 15:45:41 -0800 | [diff] [blame] | 2 | |
| 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 | |
| 34 | void 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 Kadabi | 9f7641b | 2015-01-08 19:17:06 -0800 | [diff] [blame] | 43 | uint32_t prop_type = 0; |
Channagoud Kadabi | ffaea42 | 2014-12-05 15:45:41 -0800 | [diff] [blame] | 44 | struct subnode_list *subnode_lst = NULL; |
| 45 | const struct fdt_property *prop = NULL; |
Channagoud Kadabi | 9f7641b | 2015-01-08 19:17:06 -0800 | [diff] [blame] | 46 | const char *replace_str = NULL; |
Channagoud Kadabi | ffaea42 | 2014-12-05 15:45:41 -0800 | [diff] [blame] | 47 | |
Channagoud Kadabi | 0d206ba | 2015-01-15 15:30:51 -0800 | [diff] [blame] | 48 | /* |
| 49 | * The PTE register bits 23 to 27 have the partial goods |
| 50 | * info, extract the partial goods value before using |
| 51 | */ |
| 52 | reg = (reg & 0x0f800000) >> 23; |
| 53 | |
Channagoud Kadabi | ffaea42 | 2014-12-05 15:45:41 -0800 | [diff] [blame] | 54 | /* If none of the DTB needs update */ |
| 55 | if (!reg) |
| 56 | return; |
| 57 | |
| 58 | ret = fdt_open_into(fdt, fdt, fdt_totalsize(fdt)); |
| 59 | if (ret != 0) |
| 60 | { |
| 61 | dprintf(CRITICAL, "Failed to move/resize dtb buffer: %d\n", ret); |
| 62 | ASSERT(0); |
| 63 | } |
| 64 | |
| 65 | for (i = 0; i < tbl_sz; i++) |
| 66 | { |
| 67 | if (reg == table[i].val) |
| 68 | { |
| 69 | /* Find the Parent node */ |
| 70 | ret = fdt_path_offset(fdt, table[i].parent_node); |
| 71 | if (ret < 0) |
| 72 | { |
| 73 | dprintf(CRITICAL, "Failed to get parent node: %s\terrno:%d\n", table[i].parent_node, ret); |
| 74 | ASSERT(0); |
| 75 | } |
| 76 | parent_offset = ret; |
| 77 | |
| 78 | /* Find the subnode */ |
| 79 | subnode_lst = table[i].subnode; |
| 80 | |
| 81 | while (subnode_lst->subnode) |
| 82 | { |
| 83 | ret = fdt_subnode_offset(fdt, parent_offset, subnode_lst->subnode); |
| 84 | if (ret < 0) |
| 85 | { |
| 86 | dprintf(CRITICAL, "Failed to get subnode: %s\terrno:%d\n", subnode_lst->subnode, ret); |
| 87 | ASSERT(0); |
| 88 | } |
| 89 | subnode_offset = ret; |
| 90 | |
| 91 | /* Find the property node and its length */ |
| 92 | prop = fdt_get_property(fdt, subnode_offset, subnode_lst->property, &prop_len); |
| 93 | if (!prop) |
| 94 | { |
| 95 | dprintf(CRITICAL, "Failed to get property: %s\terrno: %d\n", subnode_lst->property, prop_len); |
| 96 | ASSERT(0); |
| 97 | } |
| 98 | |
| 99 | /* |
| 100 | * Replace the property value based on the property |
| 101 | * length and type |
| 102 | */ |
| 103 | if (!(strncmp(subnode_lst->property, "device_type", sizeof(subnode_lst->property)))) |
| 104 | prop_type = DEVICE_TYPE; |
| 105 | else if ((!strncmp(subnode_lst->property, "status", sizeof(subnode_lst->property)))) |
| 106 | prop_type = STATUS_TYPE; |
| 107 | else |
| 108 | { |
| 109 | dprintf(CRITICAL, "%s: Property type is not supported\n", subnode_lst->property); |
| 110 | ASSERT(0); |
| 111 | } |
| 112 | |
| 113 | switch (prop_type) |
| 114 | { |
| 115 | case DEVICE_TYPE: |
| 116 | replace_str = "nak"; |
| 117 | break; |
| 118 | case STATUS_TYPE: |
| 119 | if (prop_len == sizeof("ok")) |
| 120 | replace_str = "no"; |
Channagoud Kadabi | 9f7641b | 2015-01-08 19:17:06 -0800 | [diff] [blame] | 121 | else if (prop_len == sizeof("okay")) |
Channagoud Kadabi | ffaea42 | 2014-12-05 15:45:41 -0800 | [diff] [blame] | 122 | replace_str = "dsbl"; |
| 123 | else |
| 124 | { |
| 125 | dprintf(CRITICAL, "Property value length: %u is invalid for property: %s\n", prop_len, subnode_lst->property); |
| 126 | ASSERT(0); |
| 127 | } |
| 128 | break; |
| 129 | default: |
| 130 | /* Control would not come here, as this gets taken care while setting property type */ |
| 131 | break; |
| 132 | }; |
| 133 | |
| 134 | /* Replace the property with new value */ |
| 135 | ret = fdt_setprop_inplace(fdt, subnode_offset, subnode_lst->property, (const void *)replace_str, prop_len); |
| 136 | if (!ret) |
| 137 | dprintf(INFO, "Updated device tree property: %s @ %s node\n", subnode_lst->property, subnode_lst->subnode); |
| 138 | else |
| 139 | { |
| 140 | dprintf(CRITICAL, "Failed to update property: %s: error no: %d\n", subnode_lst->property, ret); |
| 141 | ASSERT(0); |
| 142 | } |
| 143 | |
| 144 | subnode_lst++; |
| 145 | } |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | fdt_pack(fdt); |
| 150 | } |