fdtdec.c 17 KB

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