Commit 2a523f524090d7fc5600ece9f12d7c955db567d7
Committed by
Kumar Gala
1 parent
4d28db8a1e
Exists in
master
and in
54 other branches
fdt: Add new fdt_set_node_status & fdt_set_status_by_alias helpers
Add common function fdt_set_node_status() to assist in various locations that we set a nodes status. This function utilizes the status values that are part of the EPAPR spec (on power.org). fdt_set_status_by_alias() is based on fdt_set_node_status() but uses an alias string to identify the node to update. We also add some shortcut functions to help the common cases of setting "okay" and "disabled": fdt_status_okay() fdt_status_disabled() fdt_status_okay_by_alias() fdt_status_disabled_by_alias() Finally, we fixup the corenet_ds ethernet code which previously had a function by the same name that can be replaced with the new helpers. Signed-off-by: Shengzhou Liu <Shengzhou.Liu@freescale.com> Signed-off-by: Kumar Gala <galak@kernel.crashing.org> Acked-by: Gerald Van Baren <vanbaren@cideas.com>
Showing 4 changed files with 101 additions and 49 deletions Side-by-side Diff
board/freescale/corenet_ds/eth_hydra.c
... | ... | @@ -70,6 +70,7 @@ |
70 | 70 | #include <fm_eth.h> |
71 | 71 | #include <fsl_mdio.h> |
72 | 72 | #include <malloc.h> |
73 | +#include <fdt_support.h> | |
73 | 74 | #include <asm/fsl_dtsec.h> |
74 | 75 | |
75 | 76 | #include "../common/ngpixis.h" |
... | ... | @@ -200,25 +201,6 @@ |
200 | 201 | } |
201 | 202 | |
202 | 203 | /* |
203 | - * Given an alias or a path for a node, set the status of that node. | |
204 | - * | |
205 | - * If 'alias' is not a valid alias, then it is treated as a full path to the | |
206 | - * node. No error checking is performed. | |
207 | - * | |
208 | - * This function is normally called to set the status for a virtual MDIO node. | |
209 | - */ | |
210 | -static void fdt_set_node_status(void *fdt, const char *alias, | |
211 | - const char *status) | |
212 | -{ | |
213 | - const char *path = fdt_get_alias(fdt, alias); | |
214 | - | |
215 | - if (!path) | |
216 | - path = alias; | |
217 | - | |
218 | - do_fixup_by_path(fdt, path, "status", status, strlen(status) + 1, 1); | |
219 | -} | |
220 | - | |
221 | -/* | |
222 | 204 | * Given an alias or a path for a node, set the mux value of that node. |
223 | 205 | * |
224 | 206 | * If 'alias' is not a valid alias, then it is treated as a full path to the |
225 | 207 | |
... | ... | @@ -372,14 +354,14 @@ |
372 | 354 | case PHY_INTERFACE_MODE_SGMII: |
373 | 355 | lane = serdes_get_first_lane(SGMII_FM1_DTSEC1 + idx); |
374 | 356 | if (lane >= 0) { |
375 | - fdt_set_node_status(fdt, "emi1_sgmii", "okay"); | |
357 | + fdt_status_okay_by_alias(fdt, "emi1_sgmii"); | |
376 | 358 | /* Also set the MUX value */ |
377 | 359 | fdt_set_mdio_mux(fdt, "emi1_sgmii", |
378 | 360 | mdio_mux[i].val); |
379 | 361 | } |
380 | 362 | break; |
381 | 363 | case PHY_INTERFACE_MODE_RGMII: |
382 | - fdt_set_node_status(fdt, "emi1_rgmii", "okay"); | |
364 | + fdt_status_okay_by_alias(fdt, "emi1_rgmii"); | |
383 | 365 | break; |
384 | 366 | default: |
385 | 367 | break; |
... | ... | @@ -388,7 +370,7 @@ |
388 | 370 | |
389 | 371 | lane = serdes_get_first_lane(XAUI_FM1); |
390 | 372 | if (lane >= 0) |
391 | - fdt_set_node_status(fdt, "emi2_xgmii", "okay"); | |
373 | + fdt_status_okay_by_alias(fdt, "emi2_xgmii"); | |
392 | 374 | #endif |
393 | 375 | } |
394 | 376 |
board/freescale/corenet_ds/eth_p4080.c
... | ... | @@ -199,22 +199,6 @@ |
199 | 199 | return mdio_register(bus); |
200 | 200 | } |
201 | 201 | |
202 | -/* | |
203 | - * Sets the specified node's status to the value contained in "status" | |
204 | - * If the first character of the specified path is "/" then we use | |
205 | - * alias as a path. Otherwise, we look for an alias of that name | |
206 | - */ | |
207 | -static void fdt_set_node_status(void *fdt, const char *alias, | |
208 | - const char *status) | |
209 | -{ | |
210 | - const char *path = fdt_get_alias(fdt, alias); | |
211 | - | |
212 | - if (!path) | |
213 | - path = alias; | |
214 | - | |
215 | - do_fixup_by_path(fdt, path, "status", status, strlen(status) + 1, 1); | |
216 | -} | |
217 | - | |
218 | 202 | void board_ft_fman_fixup_port(void *blob, char * prop, phys_addr_t pa, |
219 | 203 | enum fm_port port, int offset) |
220 | 204 | { |
221 | 205 | |
222 | 206 | |
223 | 207 | |
224 | 208 | |
225 | 209 | |
... | ... | @@ -255,28 +239,28 @@ |
255 | 239 | */ |
256 | 240 | |
257 | 241 | /* We've got six MDIO nodes that may or may not need to exist */ |
258 | - fdt_set_node_status(fdt, "emi1_slot3", "disabled"); | |
259 | - fdt_set_node_status(fdt, "emi1_slot4", "disabled"); | |
260 | - fdt_set_node_status(fdt, "emi1_slot5", "disabled"); | |
261 | - fdt_set_node_status(fdt, "emi2_slot4", "disabled"); | |
262 | - fdt_set_node_status(fdt, "emi2_slot5", "disabled"); | |
242 | + fdt_status_disabled_by_alias(fdt, "emi1_slot3"); | |
243 | + fdt_status_disabled_by_alias(fdt, "emi1_slot4"); | |
244 | + fdt_status_disabled_by_alias(fdt, "emi1_slot5"); | |
245 | + fdt_status_disabled_by_alias(fdt, "emi2_slot4"); | |
246 | + fdt_status_disabled_by_alias(fdt, "emi2_slot5"); | |
263 | 247 | |
264 | 248 | for (i = 0; i < NUM_FM_PORTS; i++) { |
265 | 249 | switch (mdio_mux[i]) { |
266 | 250 | case EMI1_SLOT3: |
267 | - fdt_set_node_status(fdt, "emi1_slot3", "okay"); | |
251 | + fdt_status_okay_by_alias(fdt, "emi1_slot3"); | |
268 | 252 | break; |
269 | 253 | case EMI1_SLOT4: |
270 | - fdt_set_node_status(fdt, "emi1_slot4", "okay"); | |
254 | + fdt_status_okay_by_alias(fdt, "emi1_slot4"); | |
271 | 255 | break; |
272 | 256 | case EMI1_SLOT5: |
273 | - fdt_set_node_status(fdt, "emi1_slot5", "okay"); | |
257 | + fdt_status_okay_by_alias(fdt, "emi1_slot5"); | |
274 | 258 | break; |
275 | 259 | case EMI2_SLOT4: |
276 | - fdt_set_node_status(fdt, "emi2_slot4", "okay"); | |
260 | + fdt_status_okay_by_alias(fdt, "emi2_slot4"); | |
277 | 261 | break; |
278 | 262 | case EMI2_SLOT5: |
279 | - fdt_set_node_status(fdt, "emi2_slot5", "okay"); | |
263 | + fdt_status_okay_by_alias(fdt, "emi2_slot5"); | |
280 | 264 | break; |
281 | 265 | } |
282 | 266 | } |
common/fdt_support.c
... | ... | @@ -2,7 +2,7 @@ |
2 | 2 | * (C) Copyright 2007 |
3 | 3 | * Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com |
4 | 4 | * |
5 | - * Copyright 2010 Freescale Semiconductor, Inc. | |
5 | + * Copyright 2010-2011 Freescale Semiconductor, Inc. | |
6 | 6 | * |
7 | 7 | * See file CREDITS for list of people who contributed to this |
8 | 8 | * project. |
... | ... | @@ -1257,6 +1257,64 @@ |
1257 | 1257 | } |
1258 | 1258 | |
1259 | 1259 | return phandle; |
1260 | +} | |
1261 | + | |
1262 | +/* | |
1263 | + * fdt_set_node_status: Set status for the given node | |
1264 | + * | |
1265 | + * @fdt: ptr to device tree | |
1266 | + * @nodeoffset: node to update | |
1267 | + * @status: FDT_STATUS_OKAY, FDT_STATUS_DISABLED, | |
1268 | + * FDT_STATUS_FAIL, FDT_STATUS_FAIL_ERROR_CODE | |
1269 | + * @error_code: optional, only used if status is FDT_STATUS_FAIL_ERROR_CODE | |
1270 | + */ | |
1271 | +int fdt_set_node_status(void *fdt, int nodeoffset, | |
1272 | + enum fdt_status status, unsigned int error_code) | |
1273 | +{ | |
1274 | + char buf[16]; | |
1275 | + int ret = 0; | |
1276 | + | |
1277 | + if (nodeoffset < 0) | |
1278 | + return nodeoffset; | |
1279 | + | |
1280 | + switch (status) { | |
1281 | + case FDT_STATUS_OKAY: | |
1282 | + ret = fdt_setprop_string(fdt, nodeoffset, "status", "okay"); | |
1283 | + break; | |
1284 | + case FDT_STATUS_DISABLED: | |
1285 | + ret = fdt_setprop_string(fdt, nodeoffset, "status", "disabled"); | |
1286 | + break; | |
1287 | + case FDT_STATUS_FAIL: | |
1288 | + ret = fdt_setprop_string(fdt, nodeoffset, "status", "fail"); | |
1289 | + break; | |
1290 | + case FDT_STATUS_FAIL_ERROR_CODE: | |
1291 | + sprintf(buf, "fail-%d", error_code); | |
1292 | + ret = fdt_setprop_string(fdt, nodeoffset, "status", buf); | |
1293 | + break; | |
1294 | + default: | |
1295 | + printf("Invalid fdt status: %x\n", status); | |
1296 | + ret = -1; | |
1297 | + break; | |
1298 | + } | |
1299 | + | |
1300 | + return ret; | |
1301 | +} | |
1302 | + | |
1303 | +/* | |
1304 | + * fdt_set_status_by_alias: Set status for the given node given an alias | |
1305 | + * | |
1306 | + * @fdt: ptr to device tree | |
1307 | + * @alias: alias of node to update | |
1308 | + * @status: FDT_STATUS_OKAY, FDT_STATUS_DISABLED, | |
1309 | + * FDT_STATUS_FAIL, FDT_STATUS_FAIL_ERROR_CODE | |
1310 | + * @error_code: optional, only used if status is FDT_STATUS_FAIL_ERROR_CODE | |
1311 | + */ | |
1312 | +int fdt_set_status_by_alias(void *fdt, const char* alias, | |
1313 | + enum fdt_status status, unsigned int error_code) | |
1314 | +{ | |
1315 | + int offset = fdt_path_offset(fdt, alias); | |
1316 | + | |
1317 | + return fdt_set_node_status(fdt, offset, status, error_code); | |
1260 | 1318 | } |
1261 | 1319 | |
1262 | 1320 | #if defined(CONFIG_VIDEO) |
include/fdt_support.h
... | ... | @@ -104,6 +104,34 @@ |
104 | 104 | u64 addr); |
105 | 105 | u64 fdt_get_base_address(void *fdt, int node); |
106 | 106 | |
107 | +enum fdt_status { | |
108 | + FDT_STATUS_OKAY, | |
109 | + FDT_STATUS_DISABLED, | |
110 | + FDT_STATUS_FAIL, | |
111 | + FDT_STATUS_FAIL_ERROR_CODE, | |
112 | +}; | |
113 | +int fdt_set_node_status(void *fdt, int nodeoffset, | |
114 | + enum fdt_status status, unsigned int error_code); | |
115 | +static inline int fdt_status_okay(void *fdt, int nodeoffset) | |
116 | +{ | |
117 | + return fdt_set_node_status(fdt, nodeoffset, FDT_STATUS_OKAY, 0); | |
118 | +} | |
119 | +static inline int fdt_status_disabled(void *fdt, int nodeoffset) | |
120 | +{ | |
121 | + return fdt_set_node_status(fdt, nodeoffset, FDT_STATUS_DISABLED, 0); | |
122 | +} | |
123 | + | |
124 | +int fdt_set_status_by_alias(void *fdt, const char* alias, | |
125 | + enum fdt_status status, unsigned int error_code); | |
126 | +static inline int fdt_status_okay_by_alias(void *fdt, const char* alias) | |
127 | +{ | |
128 | + return fdt_set_status_by_alias(fdt, alias, FDT_STATUS_OKAY, 0); | |
129 | +} | |
130 | +static inline int fdt_status_disabled_by_alias(void *fdt, const char* alias) | |
131 | +{ | |
132 | + return fdt_set_status_by_alias(fdt, alias, FDT_STATUS_DISABLED, 0); | |
133 | +} | |
134 | + | |
107 | 135 | #endif /* ifdef CONFIG_OF_LIBFDT */ |
108 | 136 | #endif /* ifndef __FDT_SUPPORT_H */ |