164dbbd40SGerald Van Baren /* 264dbbd40SGerald Van Baren * (C) Copyright 2007 364dbbd40SGerald Van Baren * Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com 464dbbd40SGerald Van Baren * 51a459660SWolfgang Denk * SPDX-License-Identifier: GPL-2.0+ 664dbbd40SGerald Van Baren */ 764dbbd40SGerald Van Baren 864dbbd40SGerald Van Baren #ifndef __FDT_SUPPORT_H 964dbbd40SGerald Van Baren #define __FDT_SUPPORT_H 1064dbbd40SGerald Van Baren 1164dbbd40SGerald Van Baren #ifdef CONFIG_OF_LIBFDT 1264dbbd40SGerald Van Baren 1358864ddcSGerald Van Baren #include <libfdt.h> 1464dbbd40SGerald Van Baren 1594fb182cSAlexander Graf u32 fdt_getprop_u32_default_node(const void *fdt, int off, int cell, 1694fb182cSAlexander Graf const char *prop, const u32 dflt); 1707e12784SGabe Black u32 fdt_getprop_u32_default(const void *fdt, const char *path, 1807e12784SGabe Black const char *prop, const u32 dflt); 19bc6ed0f9SMasahiro Yamada int fdt_chosen(void *fdt); 20dbe963aeSMasahiro Yamada int fdt_initrd(void *fdt, ulong initrd_start, ulong initrd_end); 21e93becf8SKumar Gala void do_fixup_by_path(void *fdt, const char *path, const char *prop, 22e93becf8SKumar Gala const void *val, int len, int create); 23e93becf8SKumar Gala void do_fixup_by_path_u32(void *fdt, const char *path, const char *prop, 24e93becf8SKumar Gala u32 val, int create); 258ddb10eaSChunhe Lan 268ddb10eaSChunhe Lan static inline void do_fixup_by_path_string(void *fdt, const char *path, 278ddb10eaSChunhe Lan const char *prop, const char *status) 288ddb10eaSChunhe Lan { 298ddb10eaSChunhe Lan do_fixup_by_path(fdt, path, prop, status, strlen(status) + 1, 1); 308ddb10eaSChunhe Lan } 318ddb10eaSChunhe Lan 329eb77ceaSKumar Gala void do_fixup_by_prop(void *fdt, 339eb77ceaSKumar Gala const char *pname, const void *pval, int plen, 349eb77ceaSKumar Gala const char *prop, const void *val, int len, 359eb77ceaSKumar Gala int create); 369eb77ceaSKumar Gala void do_fixup_by_prop_u32(void *fdt, 379eb77ceaSKumar Gala const char *pname, const void *pval, int plen, 389eb77ceaSKumar Gala const char *prop, u32 val, int create); 399eb77ceaSKumar Gala void do_fixup_by_compat(void *fdt, const char *compat, 409eb77ceaSKumar Gala const char *prop, const void *val, int len, int create); 419eb77ceaSKumar Gala void do_fixup_by_compat_u32(void *fdt, const char *compat, 429eb77ceaSKumar Gala const char *prop, u32 val, int create); 433c927281SKumar Gala int fdt_fixup_memory(void *blob, u64 start, u64 size); 44a6bd9e83SJohn Rigby int fdt_fixup_memory_banks(void *blob, u64 start[], u64 size[], int banks); 45ba37aa03SKumar Gala void fdt_fixup_ethernet(void *fdt); 4622fb2246SMatthias Fuchs int fdt_find_and_setprop(void *fdt, const char *node, const char *prop, 4722fb2246SMatthias Fuchs const void *val, int len, int create); 48b8ec2385STimur Tabi void fdt_fixup_qe_firmware(void *fdt); 4964dbbd40SGerald Van Baren 5079f49120Sramneek mehresh #if defined(CONFIG_HAS_FSL_DR_USB) || defined(CONFIG_HAS_FSL_MPH_USB) 5118e69a35SAnton Vorontsov void fdt_fixup_dr_usb(void *blob, bd_t *bd); 5218e69a35SAnton Vorontsov #else 5318e69a35SAnton Vorontsov static inline void fdt_fixup_dr_usb(void *blob, bd_t *bd) {} 5479f49120Sramneek mehresh #endif /* defined(CONFIG_HAS_FSL_DR_USB) || defined(CONFIG_HAS_FSL_MPH_USB) */ 5518e69a35SAnton Vorontsov 56929a2138SKim Phillips #if defined(CONFIG_SYS_FSL_SEC_COMPAT) 576b70ffb9SKim Phillips void fdt_fixup_crypto_node(void *blob, int sec_rev); 586b70ffb9SKim Phillips #else 596b70ffb9SKim Phillips static inline void fdt_fixup_crypto_node(void *blob, int sec_rev) {} 606b70ffb9SKim Phillips #endif 616b70ffb9SKim Phillips 628ab451c4SKumar Gala #ifdef CONFIG_PCI 638ab451c4SKumar Gala #include <pci.h> 648ab451c4SKumar Gala int fdt_pci_dma_ranges(void *blob, int phb_off, struct pci_controller *hose); 658ab451c4SKumar Gala #endif 668ab451c4SKumar Gala 67e125a2ffSGerald Van Baren void ft_board_setup(void *blob, bd_t *bd); 6800c200f1SVitaly Andrianov /* 6900c200f1SVitaly Andrianov * The keystone2 SOC requires all 32 bit aliased addresses to be converted 7000c200f1SVitaly Andrianov * to their 36 physical format. This has to happen after all fdt nodes 7100c200f1SVitaly Andrianov * are added or modified by the image_setup_libfdt(). The ft_board_setup_ex() 7200c200f1SVitaly Andrianov * called at the end of the image_setup_libfdt() is to do that convertion. 7300c200f1SVitaly Andrianov */ 7400c200f1SVitaly Andrianov void ft_board_setup_ex(void *blob, bd_t *bd); 75e125a2ffSGerald Van Baren void ft_cpu_setup(void *blob, bd_t *bd); 76e125a2ffSGerald Van Baren void ft_pci_setup(void *blob, bd_t *bd); 77e125a2ffSGerald Van Baren 7854f9c866SKumar Gala void set_working_fdt_addr(void *addr); 79*5bf58cccSSimon Glass int fdt_shrink_to_minimum(void *blob); 80b3606f14STimur Tabi int fdt_increase_size(void *fdt, int add_len); 8154f9c866SKumar Gala 828a805df1SStefan Roese int fdt_fixup_nor_flash_size(void *blob); 8330d45c0dSStefan Roese 843c950e2eSAnatolij Gustschin void fdt_fixup_mtdparts(void *fdt, void *node_info, int node_info_size); 8549b97d9cSKumar Gala void fdt_del_node_and_alias(void *blob, const char *alias); 868aa5ec6eSKim Phillips u64 fdt_translate_address(void *blob, int node_offset, const __be32 *in_addr); 8775e73afdSKumar Gala int fdt_node_offset_by_compat_reg(void *blob, const char *compat, 8875e73afdSKumar Gala phys_addr_t compat_off); 89b4b847e9SKumar Gala int fdt_alloc_phandle(void *blob); 90f117c0f0SKumar Gala int fdt_set_phandle(void *fdt, int nodeoffset, uint32_t phandle); 913c927cccSTimur Tabi unsigned int fdt_create_phandle(void *fdt, int nodeoffset); 92beca5a5fSAnatolij Gustschin int fdt_add_edid(void *blob, const char *compat, unsigned char *buf); 933c950e2eSAnatolij Gustschin 94bb682001STimur Tabi int fdt_verify_alias_address(void *fdt, int anode, const char *alias, 95bb682001STimur Tabi u64 addr); 96bb682001STimur Tabi u64 fdt_get_base_address(void *fdt, int node); 97c48e6868SAlexander Graf int fdt_read_range(void *fdt, int node, int n, uint64_t *child_addr, 98c48e6868SAlexander Graf uint64_t *addr, uint64_t *len); 99bb682001STimur Tabi 1002a523f52SShengzhou Liu enum fdt_status { 1012a523f52SShengzhou Liu FDT_STATUS_OKAY, 1022a523f52SShengzhou Liu FDT_STATUS_DISABLED, 1032a523f52SShengzhou Liu FDT_STATUS_FAIL, 1042a523f52SShengzhou Liu FDT_STATUS_FAIL_ERROR_CODE, 1052a523f52SShengzhou Liu }; 1062a523f52SShengzhou Liu int fdt_set_node_status(void *fdt, int nodeoffset, 1072a523f52SShengzhou Liu enum fdt_status status, unsigned int error_code); 1082a523f52SShengzhou Liu static inline int fdt_status_okay(void *fdt, int nodeoffset) 1092a523f52SShengzhou Liu { 1102a523f52SShengzhou Liu return fdt_set_node_status(fdt, nodeoffset, FDT_STATUS_OKAY, 0); 1112a523f52SShengzhou Liu } 1122a523f52SShengzhou Liu static inline int fdt_status_disabled(void *fdt, int nodeoffset) 1132a523f52SShengzhou Liu { 1142a523f52SShengzhou Liu return fdt_set_node_status(fdt, nodeoffset, FDT_STATUS_DISABLED, 0); 1152a523f52SShengzhou Liu } 116b940ca64SJ. German Rivera static inline int fdt_status_fail(void *fdt, int nodeoffset) 117b940ca64SJ. German Rivera { 118b940ca64SJ. German Rivera return fdt_set_node_status(fdt, nodeoffset, FDT_STATUS_FAIL, 0); 119b940ca64SJ. German Rivera } 1202a523f52SShengzhou Liu 1212a523f52SShengzhou Liu int fdt_set_status_by_alias(void *fdt, const char *alias, 1222a523f52SShengzhou Liu enum fdt_status status, unsigned int error_code); 1232a523f52SShengzhou Liu static inline int fdt_status_okay_by_alias(void *fdt, const char *alias) 1242a523f52SShengzhou Liu { 1252a523f52SShengzhou Liu return fdt_set_status_by_alias(fdt, alias, FDT_STATUS_OKAY, 0); 1262a523f52SShengzhou Liu } 1272a523f52SShengzhou Liu static inline int fdt_status_disabled_by_alias(void *fdt, const char *alias) 1282a523f52SShengzhou Liu { 1292a523f52SShengzhou Liu return fdt_set_status_by_alias(fdt, alias, FDT_STATUS_DISABLED, 0); 1302a523f52SShengzhou Liu } 131b940ca64SJ. German Rivera static inline int fdt_status_fail_by_alias(void *fdt, const char *alias) 132b940ca64SJ. German Rivera { 133b940ca64SJ. German Rivera return fdt_set_status_by_alias(fdt, alias, FDT_STATUS_FAIL, 0); 134b940ca64SJ. German Rivera } 1352a523f52SShengzhou Liu 13664dbbd40SGerald Van Baren #endif /* ifdef CONFIG_OF_LIBFDT */ 13729a23f9dSHeiko Schocher 13829a23f9dSHeiko Schocher #ifdef USE_HOSTCC 13929a23f9dSHeiko Schocher int fdtdec_get_int(const void *blob, int node, const char *prop_name, 14029a23f9dSHeiko Schocher int default_val); 14129a23f9dSHeiko Schocher #endif 14264dbbd40SGerald Van Baren #endif /* ifndef __FDT_SUPPORT_H */ 143