aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMario Six2018-10-15 02:24:07 -0500
committerSimon Glass2018-11-14 11:16:27 -0600
commit7f0e36699952adee90dc29b5a9db1378f3a7ae06 (patch)
tree0ad682ea4ea76be8edd1adf8209db1e1d97cc87e /drivers
parent0689036a35296a3d51685a0b671f805818f94af7 (diff)
downloadu-boot-7f0e36699952adee90dc29b5a9db1378f3a7ae06.tar.gz
u-boot-7f0e36699952adee90dc29b5a9db1378f3a7ae06.tar.xz
u-boot-7f0e36699952adee90dc29b5a9db1378f3a7ae06.zip
regmap: Introduce init_range
Both fdtdec_get_addr_size_fixed and of_address_to_resource can fail with an error, which is not currently checked during regmap initialization. Since the indentation depth is already quite deep, extract a new 'init_range' method to do the initialization. Reviewed-by: Anatolij Gustschin <agust@denx.de> Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Mario Six <mario.six@gdsys.cc>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/core/regmap.c68
1 files changed, 56 insertions, 12 deletions
diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c
index 4ebab23349..25c1ae5d7d 100644
--- a/drivers/core/regmap.c
+++ b/drivers/core/regmap.c
@@ -56,6 +56,58 @@ int regmap_init_mem_platdata(struct udevice *dev, fdt_val_t *reg, int count,
56 return 0; 56 return 0;
57} 57}
58#else 58#else
59/**
60 * init_range() - Initialize a single range of a regmap
61 * @node: Device node that will use the map in question
62 * @range: Pointer to a regmap_range structure that will be initialized
63 * @addr_len: The length of the addr parts of the reg property
64 * @size_len: The length of the size parts of the reg property
65 * @index: The index of the range to initialize
66 *
67 * This function will read the necessary 'reg' information from the device tree
68 * (the 'addr' part, and the 'length' part), and initialize the range in
69 * quesion.
70 *
71 * Return: 0 if OK, -ve on error
72 */
73static int init_range(ofnode node, struct regmap_range *range, int addr_len,
74 int size_len, int index)
75{
76 fdt_size_t sz;
77 struct resource r;
78
79 if (of_live_active()) {
80 int ret;
81
82 ret = of_address_to_resource(ofnode_to_np(node),
83 index, &r);
84 if (ret) {
85 debug("%s: Could not read resource of range %d (ret = %d)\n",
86 ofnode_get_name(node), index, ret);
87 return ret;
88 }
89
90 range->start = r.start;
91 range->size = r.end - r.start + 1;
92 } else {
93 int offset = ofnode_to_offset(node);
94
95 range->start = fdtdec_get_addr_size_fixed(gd->fdt_blob, offset,
96 "reg", index,
97 addr_len, size_len,
98 &sz, true);
99 if (range->start == FDT_ADDR_T_NONE) {
100 debug("%s: Could not read start of range %d\n",
101 ofnode_get_name(node), index);
102 return -EINVAL;
103 }
104
105 range->size = sz;
106 }
107
108 return 0;
109}
110
59int regmap_init_mem(ofnode node, struct regmap **mapp) 111int regmap_init_mem(ofnode node, struct regmap **mapp)
60{ 112{
61 struct regmap_range *range; 113 struct regmap_range *range;
@@ -64,7 +116,6 @@ int regmap_init_mem(ofnode node, struct regmap **mapp)
64 int addr_len, size_len, both_len; 116 int addr_len, size_len, both_len;
65 int len; 117 int len;
66 int index; 118 int index;
67 struct resource r;
68 119
69 addr_len = ofnode_read_simple_addr_cells(ofnode_get_parent(node)); 120 addr_len = ofnode_read_simple_addr_cells(ofnode_get_parent(node));
70 if (addr_len < 0) { 121 if (addr_len < 0) {
@@ -101,17 +152,10 @@ int regmap_init_mem(ofnode node, struct regmap **mapp)
101 152
102 for (range = map->ranges, index = 0; count > 0; 153 for (range = map->ranges, index = 0; count > 0;
103 count--, range++, index++) { 154 count--, range++, index++) {
104 fdt_size_t sz; 155 int ret = init_range(node, range, addr_len, size_len, index);
105 if (of_live_active()) { 156
106 of_address_to_resource(ofnode_to_np(node), index, &r); 157 if (ret)
107 range->start = r.start; 158 return ret;
108 range->size = r.end - r.start + 1;
109 } else {
110 range->start = fdtdec_get_addr_size_fixed(gd->fdt_blob,
111 ofnode_to_offset(node), "reg", index,
112 addr_len, size_len, &sz, true);
113 range->size = sz;
114 }
115 } 159 }
116 160
117 *mapp = map; 161 *mapp = map;