164dbbd40SGerald Van Baren /* 264dbbd40SGerald Van Baren * (C) Copyright 2007 364dbbd40SGerald Van Baren * Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com 464dbbd40SGerald Van Baren * 5*1a459660SWolfgang 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 1507e12784SGabe Black u32 fdt_getprop_u32_default(const void *fdt, const char *path, 1607e12784SGabe Black const char *prop, const u32 dflt); 1756844a22SHeiko Schocher int fdt_chosen(void *fdt, int force); 182a1a2cb6SKumar Gala int fdt_initrd(void *fdt, ulong initrd_start, ulong initrd_end, int force); 19e93becf8SKumar Gala void do_fixup_by_path(void *fdt, const char *path, const char *prop, 20e93becf8SKumar Gala const void *val, int len, int create); 21e93becf8SKumar Gala void do_fixup_by_path_u32(void *fdt, const char *path, const char *prop, 22e93becf8SKumar Gala u32 val, int create); 238ddb10eaSChunhe Lan 248ddb10eaSChunhe Lan static inline void do_fixup_by_path_string(void *fdt, const char *path, 258ddb10eaSChunhe Lan const char *prop, const char *status) 268ddb10eaSChunhe Lan { 278ddb10eaSChunhe Lan do_fixup_by_path(fdt, path, prop, status, strlen(status) + 1, 1); 288ddb10eaSChunhe Lan } 298ddb10eaSChunhe Lan 309eb77ceaSKumar Gala void do_fixup_by_prop(void *fdt, 319eb77ceaSKumar Gala const char *pname, const void *pval, int plen, 329eb77ceaSKumar Gala const char *prop, const void *val, int len, 339eb77ceaSKumar Gala int create); 349eb77ceaSKumar Gala void do_fixup_by_prop_u32(void *fdt, 359eb77ceaSKumar Gala const char *pname, const void *pval, int plen, 369eb77ceaSKumar Gala const char *prop, u32 val, int create); 379eb77ceaSKumar Gala void do_fixup_by_compat(void *fdt, const char *compat, 389eb77ceaSKumar Gala const char *prop, const void *val, int len, int create); 399eb77ceaSKumar Gala void do_fixup_by_compat_u32(void *fdt, const char *compat, 409eb77ceaSKumar Gala const char *prop, u32 val, int create); 413c927281SKumar Gala int fdt_fixup_memory(void *blob, u64 start, u64 size); 42a6bd9e83SJohn Rigby int fdt_fixup_memory_banks(void *blob, u64 start[], u64 size[], int banks); 43ba37aa03SKumar Gala void fdt_fixup_ethernet(void *fdt); 4422fb2246SMatthias Fuchs int fdt_find_and_setprop(void *fdt, const char *node, const char *prop, 4522fb2246SMatthias Fuchs const void *val, int len, int create); 46b8ec2385STimur Tabi void fdt_fixup_qe_firmware(void *fdt); 4764dbbd40SGerald Van Baren 4879f49120Sramneek mehresh #if defined(CONFIG_HAS_FSL_DR_USB) || defined(CONFIG_HAS_FSL_MPH_USB) 4918e69a35SAnton Vorontsov void fdt_fixup_dr_usb(void *blob, bd_t *bd); 5018e69a35SAnton Vorontsov #else 5118e69a35SAnton Vorontsov static inline void fdt_fixup_dr_usb(void *blob, bd_t *bd) {} 5279f49120Sramneek mehresh #endif /* defined(CONFIG_HAS_FSL_DR_USB) || defined(CONFIG_HAS_FSL_MPH_USB) */ 5318e69a35SAnton Vorontsov 54929a2138SKim Phillips #if defined(CONFIG_SYS_FSL_SEC_COMPAT) 556b70ffb9SKim Phillips void fdt_fixup_crypto_node(void *blob, int sec_rev); 566b70ffb9SKim Phillips #else 576b70ffb9SKim Phillips static inline void fdt_fixup_crypto_node(void *blob, int sec_rev) {} 586b70ffb9SKim Phillips #endif 596b70ffb9SKim Phillips 608ab451c4SKumar Gala #ifdef CONFIG_PCI 618ab451c4SKumar Gala #include <pci.h> 628ab451c4SKumar Gala int fdt_pci_dma_ranges(void *blob, int phb_off, struct pci_controller *hose); 638ab451c4SKumar Gala #endif 648ab451c4SKumar Gala 65e125a2ffSGerald Van Baren void ft_board_setup(void *blob, bd_t *bd); 66e125a2ffSGerald Van Baren void ft_cpu_setup(void *blob, bd_t *bd); 67e125a2ffSGerald Van Baren void ft_pci_setup(void *blob, bd_t *bd); 68e125a2ffSGerald Van Baren 6954f9c866SKumar Gala void set_working_fdt_addr(void *addr); 703082d234SKumar Gala int fdt_resize(void *blob); 71b3606f14STimur Tabi int fdt_increase_size(void *fdt, int add_len); 7254f9c866SKumar Gala 738a805df1SStefan Roese int fdt_fixup_nor_flash_size(void *blob); 7430d45c0dSStefan Roese 753c950e2eSAnatolij Gustschin void fdt_fixup_mtdparts(void *fdt, void *node_info, int node_info_size); 7649b97d9cSKumar Gala void fdt_del_node_and_alias(void *blob, const char *alias); 778aa5ec6eSKim Phillips u64 fdt_translate_address(void *blob, int node_offset, const __be32 *in_addr); 7875e73afdSKumar Gala int fdt_node_offset_by_compat_reg(void *blob, const char *compat, 7975e73afdSKumar Gala phys_addr_t compat_off); 80b4b847e9SKumar Gala int fdt_alloc_phandle(void *blob); 81f117c0f0SKumar Gala int fdt_set_phandle(void *fdt, int nodeoffset, uint32_t phandle); 823c927cccSTimur Tabi unsigned int fdt_create_phandle(void *fdt, int nodeoffset); 83beca5a5fSAnatolij Gustschin int fdt_add_edid(void *blob, const char *compat, unsigned char *buf); 843c950e2eSAnatolij Gustschin 85bb682001STimur Tabi int fdt_verify_alias_address(void *fdt, int anode, const char *alias, 86bb682001STimur Tabi u64 addr); 87bb682001STimur Tabi u64 fdt_get_base_address(void *fdt, int node); 88bb682001STimur Tabi 892a523f52SShengzhou Liu enum fdt_status { 902a523f52SShengzhou Liu FDT_STATUS_OKAY, 912a523f52SShengzhou Liu FDT_STATUS_DISABLED, 922a523f52SShengzhou Liu FDT_STATUS_FAIL, 932a523f52SShengzhou Liu FDT_STATUS_FAIL_ERROR_CODE, 942a523f52SShengzhou Liu }; 952a523f52SShengzhou Liu int fdt_set_node_status(void *fdt, int nodeoffset, 962a523f52SShengzhou Liu enum fdt_status status, unsigned int error_code); 972a523f52SShengzhou Liu static inline int fdt_status_okay(void *fdt, int nodeoffset) 982a523f52SShengzhou Liu { 992a523f52SShengzhou Liu return fdt_set_node_status(fdt, nodeoffset, FDT_STATUS_OKAY, 0); 1002a523f52SShengzhou Liu } 1012a523f52SShengzhou Liu static inline int fdt_status_disabled(void *fdt, int nodeoffset) 1022a523f52SShengzhou Liu { 1032a523f52SShengzhou Liu return fdt_set_node_status(fdt, nodeoffset, FDT_STATUS_DISABLED, 0); 1042a523f52SShengzhou Liu } 1052a523f52SShengzhou Liu 1062a523f52SShengzhou Liu int fdt_set_status_by_alias(void *fdt, const char* alias, 1072a523f52SShengzhou Liu enum fdt_status status, unsigned int error_code); 1082a523f52SShengzhou Liu static inline int fdt_status_okay_by_alias(void *fdt, const char* alias) 1092a523f52SShengzhou Liu { 1102a523f52SShengzhou Liu return fdt_set_status_by_alias(fdt, alias, FDT_STATUS_OKAY, 0); 1112a523f52SShengzhou Liu } 1122a523f52SShengzhou Liu static inline int fdt_status_disabled_by_alias(void *fdt, const char* alias) 1132a523f52SShengzhou Liu { 1142a523f52SShengzhou Liu return fdt_set_status_by_alias(fdt, alias, FDT_STATUS_DISABLED, 0); 1152a523f52SShengzhou Liu } 1162a523f52SShengzhou Liu 11764dbbd40SGerald Van Baren #endif /* ifdef CONFIG_OF_LIBFDT */ 11864dbbd40SGerald Van Baren #endif /* ifndef __FDT_SUPPORT_H */ 119