fdtdec.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. /*
  2. * Copyright (c) 2011 The Chromium OS Authors.
  3. * SPDX-License-Identifier: GPL-2.0+
  4. */
  5. #ifndef USE_HOSTCC
  6. #include <common.h>
  7. #include <serial.h>
  8. #include <libfdt.h>
  9. #include <fdtdec.h>
  10. #include <asm/gpio.h>
  11. DECLARE_GLOBAL_DATA_PTR;
  12. /*
  13. * Here are the type we know about. One day we might allow drivers to
  14. * register. For now we just put them here. The COMPAT macro allows us to
  15. * turn this into a sparse list later, and keeps the ID with the name.
  16. */
  17. #define COMPAT(id, name) name
  18. static const char * const compat_names[COMPAT_COUNT] = {
  19. COMPAT(UNKNOWN, "<none>"),
  20. COMPAT(NVIDIA_TEGRA20_USB, "nvidia,tegra20-ehci"),
  21. COMPAT(NVIDIA_TEGRA30_USB, "nvidia,tegra30-ehci"),
  22. COMPAT(NVIDIA_TEGRA114_USB, "nvidia,tegra114-ehci"),
  23. COMPAT(NVIDIA_TEGRA114_I2C, "nvidia,tegra114-i2c"),
  24. COMPAT(NVIDIA_TEGRA20_I2C, "nvidia,tegra20-i2c"),
  25. COMPAT(NVIDIA_TEGRA20_DVC, "nvidia,tegra20-i2c-dvc"),
  26. COMPAT(NVIDIA_TEGRA20_EMC, "nvidia,tegra20-emc"),
  27. COMPAT(NVIDIA_TEGRA20_EMC_TABLE, "nvidia,tegra20-emc-table"),
  28. COMPAT(NVIDIA_TEGRA20_KBC, "nvidia,tegra20-kbc"),
  29. COMPAT(NVIDIA_TEGRA20_NAND, "nvidia,tegra20-nand"),
  30. COMPAT(NVIDIA_TEGRA20_PWM, "nvidia,tegra20-pwm"),
  31. COMPAT(NVIDIA_TEGRA20_DC, "nvidia,tegra20-dc"),
  32. COMPAT(NVIDIA_TEGRA124_SDMMC, "nvidia,tegra124-sdhci"),
  33. COMPAT(NVIDIA_TEGRA30_SDMMC, "nvidia,tegra30-sdhci"),
  34. COMPAT(NVIDIA_TEGRA20_SDMMC, "nvidia,tegra20-sdhci"),
  35. COMPAT(NVIDIA_TEGRA20_SFLASH, "nvidia,tegra20-sflash"),
  36. COMPAT(NVIDIA_TEGRA20_SLINK, "nvidia,tegra20-slink"),
  37. COMPAT(NVIDIA_TEGRA114_SPI, "nvidia,tegra114-spi"),
  38. COMPAT(SMSC_LAN9215, "smsc,lan9215"),
  39. COMPAT(SAMSUNG_EXYNOS5_SROMC, "samsung,exynos-sromc"),
  40. COMPAT(SAMSUNG_S3C2440_I2C, "samsung,s3c2440-i2c"),
  41. COMPAT(SAMSUNG_EXYNOS5_SOUND, "samsung,exynos-sound"),
  42. COMPAT(WOLFSON_WM8994_CODEC, "wolfson,wm8994-codec"),
  43. COMPAT(SAMSUNG_EXYNOS_SPI, "samsung,exynos-spi"),
  44. COMPAT(GOOGLE_CROS_EC, "google,cros-ec"),
  45. COMPAT(GOOGLE_CROS_EC_KEYB, "google,cros-ec-keyb"),
  46. COMPAT(SAMSUNG_EXYNOS_EHCI, "samsung,exynos-ehci"),
  47. COMPAT(SAMSUNG_EXYNOS5_XHCI, "samsung,exynos5250-xhci"),
  48. COMPAT(SAMSUNG_EXYNOS_USB_PHY, "samsung,exynos-usb-phy"),
  49. COMPAT(SAMSUNG_EXYNOS5_USB3_PHY, "samsung,exynos5250-usb3-phy"),
  50. COMPAT(SAMSUNG_EXYNOS_TMU, "samsung,exynos-tmu"),
  51. COMPAT(SAMSUNG_EXYNOS_FIMD, "samsung,exynos-fimd"),
  52. COMPAT(SAMSUNG_EXYNOS_MIPI_DSI, "samsung,exynos-mipi-dsi"),
  53. COMPAT(SAMSUNG_EXYNOS5_DP, "samsung,exynos5-dp"),
  54. COMPAT(SAMSUNG_EXYNOS_DWMMC, "samsung,exynos-dwmmc"),
  55. COMPAT(SAMSUNG_EXYNOS_MMC, "samsung,exynos-mmc"),
  56. COMPAT(SAMSUNG_EXYNOS_SERIAL, "samsung,exynos4210-uart"),
  57. COMPAT(MAXIM_MAX77686_PMIC, "maxim,max77686_pmic"),
  58. COMPAT(GENERIC_SPI_FLASH, "spi-flash"),
  59. COMPAT(MAXIM_98095_CODEC, "maxim,max98095-codec"),
  60. COMPAT(INFINEON_SLB9635_TPM, "infineon,slb9635-tpm"),
  61. COMPAT(INFINEON_SLB9645_TPM, "infineon,slb9645-tpm"),
  62. COMPAT(SAMSUNG_EXYNOS5_I2C, "samsung,exynos5-hsi2c"),
  63. COMPAT(SANDBOX_HOST_EMULATION, "sandbox,host-emulation"),
  64. COMPAT(SANDBOX_LCD_SDL, "sandbox,lcd-sdl"),
  65. COMPAT(TI_TPS65090, "ti,tps65090"),
  66. COMPAT(COMPAT_NXP_PTN3460, "nxp,ptn3460"),
  67. };
  68. const char *fdtdec_get_compatible(enum fdt_compat_id id)
  69. {
  70. /* We allow reading of the 'unknown' ID for testing purposes */
  71. assert(id >= 0 && id < COMPAT_COUNT);
  72. return compat_names[id];
  73. }
  74. fdt_addr_t fdtdec_get_addr_size(const void *blob, int node,
  75. const char *prop_name, fdt_size_t *sizep)
  76. {
  77. const fdt_addr_t *cell;
  78. int len;
  79. debug("%s: %s: ", __func__, prop_name);
  80. cell = fdt_getprop(blob, node, prop_name, &len);
  81. if (cell && ((!sizep && len == sizeof(fdt_addr_t)) ||
  82. len == sizeof(fdt_addr_t) * 2)) {
  83. fdt_addr_t addr = fdt_addr_to_cpu(*cell);
  84. if (sizep) {
  85. const fdt_size_t *size;
  86. size = (fdt_size_t *)((char *)cell +
  87. sizeof(fdt_addr_t));
  88. *sizep = fdt_size_to_cpu(*size);
  89. debug("addr=%08lx, size=%08x\n",
  90. (ulong)addr, *sizep);
  91. } else {
  92. debug("%08lx\n", (ulong)addr);
  93. }
  94. return addr;
  95. }
  96. debug("(not found)\n");
  97. return FDT_ADDR_T_NONE;
  98. }
  99. fdt_addr_t fdtdec_get_addr(const void *blob, int node,
  100. const char *prop_name)
  101. {
  102. return fdtdec_get_addr_size(blob, node, prop_name, NULL);
  103. }
  104. uint64_t fdtdec_get_uint64(const void *blob, int node, const char *prop_name,
  105. uint64_t default_val)
  106. {
  107. const uint64_t *cell64;
  108. int length;
  109. cell64 = fdt_getprop(blob, node, prop_name, &length);
  110. if (!cell64 || length < sizeof(*cell64))
  111. return default_val;
  112. return fdt64_to_cpu(*cell64);
  113. }
  114. int fdtdec_get_is_enabled(const void *blob, int node)
  115. {
  116. const char *cell;
  117. /*
  118. * It should say "okay", so only allow that. Some fdts use "ok" but
  119. * this is a bug. Please fix your device tree source file. See here
  120. * for discussion:
  121. *
  122. * http://www.mail-archive.com/u-boot@lists.denx.de/msg71598.html
  123. */
  124. cell = fdt_getprop(blob, node, "status", NULL);
  125. if (cell)
  126. return 0 == strcmp(cell, "okay");
  127. return 1;
  128. }
  129. enum fdt_compat_id fdtdec_lookup(const void *blob, int node)
  130. {
  131. enum fdt_compat_id id;
  132. /* Search our drivers */
  133. for (id = COMPAT_UNKNOWN; id < COMPAT_COUNT; id++)
  134. if (0 == fdt_node_check_compatible(blob, node,
  135. compat_names[id]))
  136. return id;
  137. return COMPAT_UNKNOWN;
  138. }
  139. int fdtdec_next_compatible(const void *blob, int node,
  140. enum fdt_compat_id id)
  141. {
  142. return fdt_node_offset_by_compatible(blob, node, compat_names[id]);
  143. }
  144. int fdtdec_next_compatible_subnode(const void *blob, int node,
  145. enum fdt_compat_id id, int *depthp)
  146. {
  147. do {
  148. node = fdt_next_node(blob, node, depthp);
  149. } while (*depthp > 1);
  150. /* If this is a direct subnode, and compatible, return it */
  151. if (*depthp == 1 && 0 == fdt_node_check_compatible(
  152. blob, node, compat_names[id]))
  153. return node;
  154. return -FDT_ERR_NOTFOUND;
  155. }
  156. int fdtdec_next_alias(const void *blob, const char *name,
  157. enum fdt_compat_id id, int *upto)
  158. {
  159. #define MAX_STR_LEN 20
  160. char str[MAX_STR_LEN + 20];
  161. int node, err;
  162. /* snprintf() is not available */
  163. assert(strlen(name) < MAX_STR_LEN);
  164. sprintf(str, "%.*s%d", MAX_STR_LEN, name, *upto);
  165. node = fdt_path_offset(blob, str);
  166. if (node < 0)
  167. return node;
  168. err = fdt_node_check_compatible(blob, node, compat_names[id]);
  169. if (err < 0)
  170. return err;
  171. if (err)
  172. return -FDT_ERR_NOTFOUND;
  173. (*upto)++;
  174. return node;
  175. }
  176. int fdtdec_find_aliases_for_id(const void *blob, const char *name,
  177. enum fdt_compat_id id, int *node_list, int maxcount)
  178. {
  179. memset(node_list, '\0', sizeof(*node_list) * maxcount);
  180. return fdtdec_add_aliases_for_id(blob, name, id, node_list, maxcount);
  181. }
  182. /* TODO: Can we tighten this code up a little? */
  183. int fdtdec_add_aliases_for_id(const void *blob, const char *name,
  184. enum fdt_compat_id id, int *node_list, int maxcount)
  185. {
  186. int name_len = strlen(name);
  187. int nodes[maxcount];
  188. int num_found = 0;
  189. int offset, node;
  190. int alias_node;
  191. int count;
  192. int i, j;
  193. /* find the alias node if present */
  194. alias_node = fdt_path_offset(blob, "/aliases");
  195. /*
  196. * start with nothing, and we can assume that the root node can't
  197. * match
  198. */
  199. memset(nodes, '\0', sizeof(nodes));
  200. /* First find all the compatible nodes */
  201. for (node = count = 0; node >= 0 && count < maxcount;) {
  202. node = fdtdec_next_compatible(blob, node, id);
  203. if (node >= 0)
  204. nodes[count++] = node;
  205. }
  206. if (node >= 0)
  207. debug("%s: warning: maxcount exceeded with alias '%s'\n",
  208. __func__, name);
  209. /* Now find all the aliases */
  210. for (offset = fdt_first_property_offset(blob, alias_node);
  211. offset > 0;
  212. offset = fdt_next_property_offset(blob, offset)) {
  213. const struct fdt_property *prop;
  214. const char *path;
  215. int number;
  216. int found;
  217. node = 0;
  218. prop = fdt_get_property_by_offset(blob, offset, NULL);
  219. path = fdt_string(blob, fdt32_to_cpu(prop->nameoff));
  220. if (prop->len && 0 == strncmp(path, name, name_len))
  221. node = fdt_path_offset(blob, prop->data);
  222. if (node <= 0)
  223. continue;
  224. /* Get the alias number */
  225. number = simple_strtoul(path + name_len, NULL, 10);
  226. if (number < 0 || number >= maxcount) {
  227. debug("%s: warning: alias '%s' is out of range\n",
  228. __func__, path);
  229. continue;
  230. }
  231. /* Make sure the node we found is actually in our list! */
  232. found = -1;
  233. for (j = 0; j < count; j++)
  234. if (nodes[j] == node) {
  235. found = j;
  236. break;
  237. }
  238. if (found == -1) {
  239. debug("%s: warning: alias '%s' points to a node "
  240. "'%s' that is missing or is not compatible "
  241. " with '%s'\n", __func__, path,
  242. fdt_get_name(blob, node, NULL),
  243. compat_names[id]);
  244. continue;
  245. }
  246. /*
  247. * Add this node to our list in the right place, and mark
  248. * it as done.
  249. */
  250. if (fdtdec_get_is_enabled(blob, node)) {
  251. if (node_list[number]) {
  252. debug("%s: warning: alias '%s' requires that "
  253. "a node be placed in the list in a "
  254. "position which is already filled by "
  255. "node '%s'\n", __func__, path,
  256. fdt_get_name(blob, node, NULL));
  257. continue;
  258. }
  259. node_list[number] = node;
  260. if (number >= num_found)
  261. num_found = number + 1;
  262. }
  263. nodes[found] = 0;
  264. }
  265. /* Add any nodes not mentioned by an alias */
  266. for (i = j = 0; i < maxcount; i++) {
  267. if (!node_list[i]) {
  268. for (; j < maxcount; j++)
  269. if (nodes[j] &&
  270. fdtdec_get_is_enabled(blob, nodes[j]))
  271. break;
  272. /* Have we run out of nodes to add? */
  273. if (j == maxcount)
  274. break;
  275. assert(!node_list[i]);
  276. node_list[i] = nodes[j++];
  277. if (i >= num_found)
  278. num_found = i + 1;
  279. }
  280. }
  281. return num_found;
  282. }
  283. int fdtdec_check_fdt(void)
  284. {
  285. /*
  286. * We must have an FDT, but we cannot panic() yet since the console
  287. * is not ready. So for now, just assert(). Boards which need an early
  288. * FDT (prior to console ready) will need to make their own
  289. * arrangements and do their own checks.
  290. */
  291. assert(!fdtdec_prepare_fdt());
  292. return 0;
  293. }
  294. /*
  295. * This function is a little odd in that it accesses global data. At some
  296. * point if the architecture board.c files merge this will make more sense.
  297. * Even now, it is common code.
  298. */
  299. int fdtdec_prepare_fdt(void)
  300. {
  301. if (!gd->fdt_blob || ((uintptr_t)gd->fdt_blob & 3) ||
  302. fdt_check_header(gd->fdt_blob)) {
  303. printf("No valid FDT found - please append one to U-Boot "
  304. "binary, use u-boot-dtb.bin or define "
  305. "CONFIG_OF_EMBED. For sandbox, use -d <file.dtb>\n");
  306. return -1;
  307. }
  308. return 0;
  309. }
  310. int fdtdec_lookup_phandle(const void *blob, int node, const char *prop_name)
  311. {
  312. const u32 *phandle;
  313. int lookup;
  314. debug("%s: %s\n", __func__, prop_name);
  315. phandle = fdt_getprop(blob, node, prop_name, NULL);
  316. if (!phandle)
  317. return -FDT_ERR_NOTFOUND;
  318. lookup = fdt_node_offset_by_phandle(blob, fdt32_to_cpu(*phandle));
  319. return lookup;
  320. }
  321. /**
  322. * Look up a property in a node and check that it has a minimum length.
  323. *
  324. * @param blob FDT blob
  325. * @param node node to examine
  326. * @param prop_name name of property to find
  327. * @param min_len minimum property length in bytes
  328. * @param err 0 if ok, or -FDT_ERR_NOTFOUND if the property is not
  329. found, or -FDT_ERR_BADLAYOUT if not enough data
  330. * @return pointer to cell, which is only valid if err == 0
  331. */
  332. static const void *get_prop_check_min_len(const void *blob, int node,
  333. const char *prop_name, int min_len, int *err)
  334. {
  335. const void *cell;
  336. int len;
  337. debug("%s: %s\n", __func__, prop_name);
  338. cell = fdt_getprop(blob, node, prop_name, &len);
  339. if (!cell)
  340. *err = -FDT_ERR_NOTFOUND;
  341. else if (len < min_len)
  342. *err = -FDT_ERR_BADLAYOUT;
  343. else
  344. *err = 0;
  345. return cell;
  346. }
  347. int fdtdec_get_int_array(const void *blob, int node, const char *prop_name,
  348. u32 *array, int count)
  349. {
  350. const u32 *cell;
  351. int i, err = 0;
  352. debug("%s: %s\n", __func__, prop_name);
  353. cell = get_prop_check_min_len(blob, node, prop_name,
  354. sizeof(u32) * count, &err);
  355. if (!err) {
  356. for (i = 0; i < count; i++)
  357. array[i] = fdt32_to_cpu(cell[i]);
  358. }
  359. return err;
  360. }
  361. const u32 *fdtdec_locate_array(const void *blob, int node,
  362. const char *prop_name, int count)
  363. {
  364. const u32 *cell;
  365. int err;
  366. cell = get_prop_check_min_len(blob, node, prop_name,
  367. sizeof(u32) * count, &err);
  368. return err ? NULL : cell;
  369. }
  370. int fdtdec_get_bool(const void *blob, int node, const char *prop_name)
  371. {
  372. const s32 *cell;
  373. int len;
  374. debug("%s: %s\n", __func__, prop_name);
  375. cell = fdt_getprop(blob, node, prop_name, &len);
  376. return cell != NULL;
  377. }
  378. /**
  379. * Decode a list of GPIOs from an FDT. This creates a list of GPIOs with no
  380. * terminating item.
  381. *
  382. * @param blob FDT blob to use
  383. * @param node Node to look at
  384. * @param prop_name Node property name
  385. * @param gpio Array of gpio elements to fill from FDT. This will be
  386. * untouched if either 0 or an error is returned
  387. * @param max_count Maximum number of elements allowed
  388. * @return number of GPIOs read if ok, -FDT_ERR_BADLAYOUT if max_count would
  389. * be exceeded, or -FDT_ERR_NOTFOUND if the property is missing.
  390. */
  391. int fdtdec_decode_gpios(const void *blob, int node, const char *prop_name,
  392. struct fdt_gpio_state *gpio, int max_count)
  393. {
  394. const struct fdt_property *prop;
  395. const u32 *cell;
  396. const char *name;
  397. int len, i;
  398. debug("%s: %s\n", __func__, prop_name);
  399. assert(max_count > 0);
  400. prop = fdt_get_property(blob, node, prop_name, &len);
  401. if (!prop) {
  402. debug("%s: property '%s' missing\n", __func__, prop_name);
  403. return -FDT_ERR_NOTFOUND;
  404. }
  405. /* We will use the name to tag the GPIO */
  406. name = fdt_string(blob, fdt32_to_cpu(prop->nameoff));
  407. cell = (u32 *)prop->data;
  408. len /= sizeof(u32) * 3; /* 3 cells per GPIO record */
  409. if (len > max_count) {
  410. debug(" %s: too many GPIOs / cells for "
  411. "property '%s'\n", __func__, prop_name);
  412. return -FDT_ERR_BADLAYOUT;
  413. }
  414. /* Read out the GPIO data from the cells */
  415. for (i = 0; i < len; i++, cell += 3) {
  416. gpio[i].gpio = fdt32_to_cpu(cell[1]);
  417. gpio[i].flags = fdt32_to_cpu(cell[2]);
  418. gpio[i].name = name;
  419. }
  420. return len;
  421. }
  422. int fdtdec_decode_gpio(const void *blob, int node, const char *prop_name,
  423. struct fdt_gpio_state *gpio)
  424. {
  425. int err;
  426. debug("%s: %s\n", __func__, prop_name);
  427. gpio->gpio = FDT_GPIO_NONE;
  428. gpio->name = NULL;
  429. err = fdtdec_decode_gpios(blob, node, prop_name, gpio, 1);
  430. return err == 1 ? 0 : err;
  431. }
  432. int fdtdec_get_gpio(struct fdt_gpio_state *gpio)
  433. {
  434. int val;
  435. if (!fdt_gpio_isvalid(gpio))
  436. return -1;
  437. val = gpio_get_value(gpio->gpio);
  438. return gpio->flags & FDT_GPIO_ACTIVE_LOW ? val ^ 1 : val;
  439. }
  440. int fdtdec_set_gpio(struct fdt_gpio_state *gpio, int val)
  441. {
  442. if (!fdt_gpio_isvalid(gpio))
  443. return -1;
  444. val = gpio->flags & FDT_GPIO_ACTIVE_LOW ? val ^ 1 : val;
  445. return gpio_set_value(gpio->gpio, val);
  446. }
  447. int fdtdec_setup_gpio(struct fdt_gpio_state *gpio)
  448. {
  449. /*
  450. * Return success if there is no GPIO defined. This is used for
  451. * optional GPIOs)
  452. */
  453. if (!fdt_gpio_isvalid(gpio))
  454. return 0;
  455. if (gpio_request(gpio->gpio, gpio->name))
  456. return -1;
  457. return 0;
  458. }
  459. int fdtdec_get_byte_array(const void *blob, int node, const char *prop_name,
  460. u8 *array, int count)
  461. {
  462. const u8 *cell;
  463. int err;
  464. cell = get_prop_check_min_len(blob, node, prop_name, count, &err);
  465. if (!err)
  466. memcpy(array, cell, count);
  467. return err;
  468. }
  469. const u8 *fdtdec_locate_byte_array(const void *blob, int node,
  470. const char *prop_name, int count)
  471. {
  472. const u8 *cell;
  473. int err;
  474. cell = get_prop_check_min_len(blob, node, prop_name, count, &err);
  475. if (err)
  476. return NULL;
  477. return cell;
  478. }
  479. int fdtdec_get_config_int(const void *blob, const char *prop_name,
  480. int default_val)
  481. {
  482. int config_node;
  483. debug("%s: %s\n", __func__, prop_name);
  484. config_node = fdt_path_offset(blob, "/config");
  485. if (config_node < 0)
  486. return default_val;
  487. return fdtdec_get_int(blob, config_node, prop_name, default_val);
  488. }
  489. int fdtdec_get_config_bool(const void *blob, const char *prop_name)
  490. {
  491. int config_node;
  492. const void *prop;
  493. debug("%s: %s\n", __func__, prop_name);
  494. config_node = fdt_path_offset(blob, "/config");
  495. if (config_node < 0)
  496. return 0;
  497. prop = fdt_get_property(blob, config_node, prop_name, NULL);
  498. return prop != NULL;
  499. }
  500. char *fdtdec_get_config_string(const void *blob, const char *prop_name)
  501. {
  502. const char *nodep;
  503. int nodeoffset;
  504. int len;
  505. debug("%s: %s\n", __func__, prop_name);
  506. nodeoffset = fdt_path_offset(blob, "/config");
  507. if (nodeoffset < 0)
  508. return NULL;
  509. nodep = fdt_getprop(blob, nodeoffset, prop_name, &len);
  510. if (!nodep)
  511. return NULL;
  512. return (char *)nodep;
  513. }
  514. int fdtdec_decode_region(const void *blob, int node,
  515. const char *prop_name, void **ptrp, size_t *size)
  516. {
  517. const fdt_addr_t *cell;
  518. int len;
  519. debug("%s: %s\n", __func__, prop_name);
  520. cell = fdt_getprop(blob, node, prop_name, &len);
  521. if (!cell || (len != sizeof(fdt_addr_t) * 2))
  522. return -1;
  523. *ptrp = map_sysmem(fdt_addr_to_cpu(*cell), *size);
  524. *size = fdt_size_to_cpu(cell[1]);
  525. debug("%s: size=%zx\n", __func__, *size);
  526. return 0;
  527. }
  528. /**
  529. * Read a flash entry from the fdt
  530. *
  531. * @param blob FDT blob
  532. * @param node Offset of node to read
  533. * @param name Name of node being read
  534. * @param entry Place to put offset and size of this node
  535. * @return 0 if ok, -ve on error
  536. */
  537. int fdtdec_read_fmap_entry(const void *blob, int node, const char *name,
  538. struct fmap_entry *entry)
  539. {
  540. u32 reg[2];
  541. if (fdtdec_get_int_array(blob, node, "reg", reg, 2)) {
  542. debug("Node '%s' has bad/missing 'reg' property\n", name);
  543. return -FDT_ERR_NOTFOUND;
  544. }
  545. entry->offset = reg[0];
  546. entry->length = reg[1];
  547. return 0;
  548. }
  549. #endif