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); 193c4c142eSPaul Kocialkowski 203c4c142eSPaul Kocialkowski /** 213c4c142eSPaul Kocialkowski * Add data to the root of the FDT before booting the OS. 223c4c142eSPaul Kocialkowski * 233c4c142eSPaul Kocialkowski * See doc/device-tree-bindings/root.txt 243c4c142eSPaul Kocialkowski * 253c4c142eSPaul Kocialkowski * @param fdt FDT address in memory 263c4c142eSPaul Kocialkowski * @return 0 if ok, or -FDT_ERR_... on error 273c4c142eSPaul Kocialkowski */ 2810be5b5dSPaul Kocialkowski int fdt_root(void *fdt); 293c4c142eSPaul Kocialkowski 303c4c142eSPaul Kocialkowski /** 313c4c142eSPaul Kocialkowski * Add chosen data the FDT before booting the OS. 323c4c142eSPaul Kocialkowski * 333c4c142eSPaul Kocialkowski * In particular, this adds the kernel command line (bootargs) to the FDT. 343c4c142eSPaul Kocialkowski * 353c4c142eSPaul Kocialkowski * @param fdt FDT address in memory 363c4c142eSPaul Kocialkowski * @return 0 if ok, or -FDT_ERR_... on error 373c4c142eSPaul Kocialkowski */ 38bc6ed0f9SMasahiro Yamada int fdt_chosen(void *fdt); 393c4c142eSPaul Kocialkowski 403c4c142eSPaul Kocialkowski /** 413c4c142eSPaul Kocialkowski * Add initrd information to the FDT before booting the OS. 423c4c142eSPaul Kocialkowski * 433c4c142eSPaul Kocialkowski * @param fdt FDT address in memory 443c4c142eSPaul Kocialkowski * @return 0 if ok, or -FDT_ERR_... on error 453c4c142eSPaul Kocialkowski */ 46dbe963aeSMasahiro Yamada int fdt_initrd(void *fdt, ulong initrd_start, ulong initrd_end); 473c4c142eSPaul Kocialkowski 48e93becf8SKumar Gala void do_fixup_by_path(void *fdt, const char *path, const char *prop, 49e93becf8SKumar Gala const void *val, int len, int create); 50e93becf8SKumar Gala void do_fixup_by_path_u32(void *fdt, const char *path, const char *prop, 51e93becf8SKumar Gala u32 val, int create); 528ddb10eaSChunhe Lan 538ddb10eaSChunhe Lan static inline void do_fixup_by_path_string(void *fdt, const char *path, 548ddb10eaSChunhe Lan const char *prop, const char *status) 558ddb10eaSChunhe Lan { 568ddb10eaSChunhe Lan do_fixup_by_path(fdt, path, prop, status, strlen(status) + 1, 1); 578ddb10eaSChunhe Lan } 588ddb10eaSChunhe Lan 599eb77ceaSKumar Gala void do_fixup_by_prop(void *fdt, 609eb77ceaSKumar Gala const char *pname, const void *pval, int plen, 619eb77ceaSKumar Gala const char *prop, const void *val, int len, 629eb77ceaSKumar Gala int create); 639eb77ceaSKumar Gala void do_fixup_by_prop_u32(void *fdt, 649eb77ceaSKumar Gala const char *pname, const void *pval, int plen, 659eb77ceaSKumar Gala const char *prop, u32 val, int create); 669eb77ceaSKumar Gala void do_fixup_by_compat(void *fdt, const char *compat, 679eb77ceaSKumar Gala const char *prop, const void *val, int len, int create); 689eb77ceaSKumar Gala void do_fixup_by_compat_u32(void *fdt, const char *compat, 699eb77ceaSKumar Gala const char *prop, u32 val, int create); 705c1cf89fSAndre Przywara /** 715c1cf89fSAndre Przywara * Setup the memory node in the DT. Creates one if none was existing before. 725c1cf89fSAndre Przywara * Calls fdt_fixup_memory_banks() to populate a single reg pair covering the 735c1cf89fSAndre Przywara * whole memory. 745c1cf89fSAndre Przywara * 755c1cf89fSAndre Przywara * @param blob FDT blob to update 765c1cf89fSAndre Przywara * @param start Begin of DRAM mapping in physical memory 775c1cf89fSAndre Przywara * @param size Size of the single memory bank 785c1cf89fSAndre Przywara * @return 0 if ok, or -1 or -FDT_ERR_... on error 795c1cf89fSAndre Przywara */ 803c927281SKumar Gala int fdt_fixup_memory(void *blob, u64 start, u64 size); 815c1cf89fSAndre Przywara 825c1cf89fSAndre Przywara /** 835c1cf89fSAndre Przywara * Fill the DT memory node with multiple memory banks. 845c1cf89fSAndre Przywara * Creates the node if none was existing before. 855c1cf89fSAndre Przywara * If banks is 0, it will not touch the existing reg property. This allows 865c1cf89fSAndre Przywara * boards to not mess with the existing DT setup, which may have been 875c1cf89fSAndre Przywara * filled in properly before. 885c1cf89fSAndre Przywara * 895c1cf89fSAndre Przywara * @param blob FDT blob to update 905c1cf89fSAndre Przywara * @param start Array of size <banks> to hold the start addresses. 915c1cf89fSAndre Przywara * @param size Array of size <banks> to hold the size of each region. 925c1cf89fSAndre Przywara * @param banks Number of memory banks to create. If 0, the reg 935c1cf89fSAndre Przywara * property will be left untouched. 945c1cf89fSAndre Przywara * @return 0 if ok, or -1 or -FDT_ERR_... on error 955c1cf89fSAndre Przywara */ 96a6bd9e83SJohn Rigby int fdt_fixup_memory_banks(void *blob, u64 start[], u64 size[], int banks); 975c1cf89fSAndre Przywara 98ba37aa03SKumar Gala void fdt_fixup_ethernet(void *fdt); 9922fb2246SMatthias Fuchs int fdt_find_and_setprop(void *fdt, const char *node, const char *prop, 10022fb2246SMatthias Fuchs const void *val, int len, int create); 101b8ec2385STimur Tabi void fdt_fixup_qe_firmware(void *fdt); 10264dbbd40SGerald Van Baren 10308daa258STim Harvey /** 10408daa258STim Harvey * Update native-mode property of display-timings node to the phandle 10508daa258STim Harvey * of the timings matching a display by name (case insensitive). 10608daa258STim Harvey * 10708daa258STim Harvey * see kernel Documentation/devicetree/bindings/video/display-timing.txt 10808daa258STim Harvey * 10908daa258STim Harvey * @param blob FDT blob to update 11008daa258STim Harvey * @param path path within dt 11108daa258STim Harvey * @param display name of display timing to match 11208daa258STim Harvey * @return 0 if ok, or -FDT_ERR_... on error 11308daa258STim Harvey */ 11408daa258STim Harvey int fdt_fixup_display(void *blob, const char *path, const char *display); 11508daa258STim Harvey 116b9f6786aSSriram Dash #if defined(CONFIG_USB_EHCI_FSL) || defined(CONFIG_USB_XHCI_FSL) 11718e69a35SAnton Vorontsov void fdt_fixup_dr_usb(void *blob, bd_t *bd); 11818e69a35SAnton Vorontsov #else 11918e69a35SAnton Vorontsov static inline void fdt_fixup_dr_usb(void *blob, bd_t *bd) {} 120b9f6786aSSriram Dash #endif /* defined(CONFIG_USB_EHCI_FSL) || defined(CONFIG_USB_XHCI_FSL) */ 12118e69a35SAnton Vorontsov 122929a2138SKim Phillips #if defined(CONFIG_SYS_FSL_SEC_COMPAT) 1236b70ffb9SKim Phillips void fdt_fixup_crypto_node(void *blob, int sec_rev); 1246b70ffb9SKim Phillips #else 1256b70ffb9SKim Phillips static inline void fdt_fixup_crypto_node(void *blob, int sec_rev) {} 1266b70ffb9SKim Phillips #endif 1276b70ffb9SKim Phillips 1288ab451c4SKumar Gala #ifdef CONFIG_PCI 1298ab451c4SKumar Gala #include <pci.h> 1308ab451c4SKumar Gala int fdt_pci_dma_ranges(void *blob, int phb_off, struct pci_controller *hose); 1318ab451c4SKumar Gala #endif 1328ab451c4SKumar Gala 133a9e8e291SSimon Glass int fdt_find_or_add_subnode(void *fdt, int parentoffset, const char *name); 134a9e8e291SSimon Glass 135e895a4b0SSimon Glass /** 136e895a4b0SSimon Glass * Add board-specific data to the FDT before booting the OS. 137e895a4b0SSimon Glass * 138e895a4b0SSimon Glass * Use CONFIG_SYS_FDT_PAD to ensure there is sufficient space. 1396f4dbc21SSimon Glass * This function is called if CONFIG_OF_BOARD_SETUP is defined 140e895a4b0SSimon Glass * 141e895a4b0SSimon Glass * @param blob FDT blob to update 142e895a4b0SSimon Glass * @param bd_t Pointer to board data 143e895a4b0SSimon Glass * @return 0 if ok, or -FDT_ERR_... on error 144e895a4b0SSimon Glass */ 145e895a4b0SSimon Glass int ft_board_setup(void *blob, bd_t *bd); 146e895a4b0SSimon Glass 14700c200f1SVitaly Andrianov /* 14800c200f1SVitaly Andrianov * The keystone2 SOC requires all 32 bit aliased addresses to be converted 14900c200f1SVitaly Andrianov * to their 36 physical format. This has to happen after all fdt nodes 15000c200f1SVitaly Andrianov * are added or modified by the image_setup_libfdt(). The ft_board_setup_ex() 15100c200f1SVitaly Andrianov * called at the end of the image_setup_libfdt() is to do that convertion. 15200c200f1SVitaly Andrianov */ 15300c200f1SVitaly Andrianov void ft_board_setup_ex(void *blob, bd_t *bd); 154e125a2ffSGerald Van Baren void ft_cpu_setup(void *blob, bd_t *bd); 155e125a2ffSGerald Van Baren void ft_pci_setup(void *blob, bd_t *bd); 156e125a2ffSGerald Van Baren 157c654b517SSimon Glass /** 158c654b517SSimon Glass * Add system-specific data to the FDT before booting the OS. 159c654b517SSimon Glass * 160c654b517SSimon Glass * Use CONFIG_SYS_FDT_PAD to ensure there is sufficient space. 161c654b517SSimon Glass * This function is called if CONFIG_OF_SYSTEM_SETUP is defined 162c654b517SSimon Glass * 163c654b517SSimon Glass * @param blob FDT blob to update 164c654b517SSimon Glass * @param bd_t Pointer to board data 165c654b517SSimon Glass * @return 0 if ok, or -FDT_ERR_... on error 166c654b517SSimon Glass */ 167c654b517SSimon Glass int ft_system_setup(void *blob, bd_t *bd); 168c654b517SSimon Glass 16990fbee3eSJoe Hershberger void set_working_fdt_addr(ulong addr); 1705bf58cccSSimon Glass int fdt_shrink_to_minimum(void *blob); 171b3606f14STimur Tabi int fdt_increase_size(void *fdt, int add_len); 17254f9c866SKumar Gala 1738a805df1SStefan Roese int fdt_fixup_nor_flash_size(void *blob); 17430d45c0dSStefan Roese 175*f4ae23a7SChristopher Spinrath #if defined(CONFIG_FDT_FIXUP_PARTITIONS) 1763c950e2eSAnatolij Gustschin void fdt_fixup_mtdparts(void *fdt, void *node_info, int node_info_size); 177*f4ae23a7SChristopher Spinrath #else 178*f4ae23a7SChristopher Spinrath static inline void fdt_fixup_mtdparts(void *fdt, void *node_info, 179*f4ae23a7SChristopher Spinrath int node_info_size) {} 180*f4ae23a7SChristopher Spinrath #endif 181*f4ae23a7SChristopher Spinrath 18249b97d9cSKumar Gala void fdt_del_node_and_alias(void *blob, const char *alias); 1838aa5ec6eSKim Phillips u64 fdt_translate_address(void *blob, int node_offset, const __be32 *in_addr); 18475e73afdSKumar Gala int fdt_node_offset_by_compat_reg(void *blob, const char *compat, 18575e73afdSKumar Gala phys_addr_t compat_off); 186b4b847e9SKumar Gala int fdt_alloc_phandle(void *blob); 187f117c0f0SKumar Gala int fdt_set_phandle(void *fdt, int nodeoffset, uint32_t phandle); 1883c927cccSTimur Tabi unsigned int fdt_create_phandle(void *fdt, int nodeoffset); 189beca5a5fSAnatolij Gustschin int fdt_add_edid(void *blob, const char *compat, unsigned char *buf); 1903c950e2eSAnatolij Gustschin 191bb682001STimur Tabi int fdt_verify_alias_address(void *fdt, int anode, const char *alias, 192bb682001STimur Tabi u64 addr); 193bb682001STimur Tabi u64 fdt_get_base_address(void *fdt, int node); 194c48e6868SAlexander Graf int fdt_read_range(void *fdt, int node, int n, uint64_t *child_addr, 195c48e6868SAlexander Graf uint64_t *addr, uint64_t *len); 196bb682001STimur Tabi 1972a523f52SShengzhou Liu enum fdt_status { 1982a523f52SShengzhou Liu FDT_STATUS_OKAY, 1992a523f52SShengzhou Liu FDT_STATUS_DISABLED, 2002a523f52SShengzhou Liu FDT_STATUS_FAIL, 2012a523f52SShengzhou Liu FDT_STATUS_FAIL_ERROR_CODE, 2022a523f52SShengzhou Liu }; 2032a523f52SShengzhou Liu int fdt_set_node_status(void *fdt, int nodeoffset, 2042a523f52SShengzhou Liu enum fdt_status status, unsigned int error_code); 2052a523f52SShengzhou Liu static inline int fdt_status_okay(void *fdt, int nodeoffset) 2062a523f52SShengzhou Liu { 2072a523f52SShengzhou Liu return fdt_set_node_status(fdt, nodeoffset, FDT_STATUS_OKAY, 0); 2082a523f52SShengzhou Liu } 2092a523f52SShengzhou Liu static inline int fdt_status_disabled(void *fdt, int nodeoffset) 2102a523f52SShengzhou Liu { 2112a523f52SShengzhou Liu return fdt_set_node_status(fdt, nodeoffset, FDT_STATUS_DISABLED, 0); 2122a523f52SShengzhou Liu } 213b940ca64SJ. German Rivera static inline int fdt_status_fail(void *fdt, int nodeoffset) 214b940ca64SJ. German Rivera { 215b940ca64SJ. German Rivera return fdt_set_node_status(fdt, nodeoffset, FDT_STATUS_FAIL, 0); 216b940ca64SJ. German Rivera } 2172a523f52SShengzhou Liu 2182a523f52SShengzhou Liu int fdt_set_status_by_alias(void *fdt, const char *alias, 2192a523f52SShengzhou Liu enum fdt_status status, unsigned int error_code); 2202a523f52SShengzhou Liu static inline int fdt_status_okay_by_alias(void *fdt, const char *alias) 2212a523f52SShengzhou Liu { 2222a523f52SShengzhou Liu return fdt_set_status_by_alias(fdt, alias, FDT_STATUS_OKAY, 0); 2232a523f52SShengzhou Liu } 2242a523f52SShengzhou Liu static inline int fdt_status_disabled_by_alias(void *fdt, const char *alias) 2252a523f52SShengzhou Liu { 2262a523f52SShengzhou Liu return fdt_set_status_by_alias(fdt, alias, FDT_STATUS_DISABLED, 0); 2272a523f52SShengzhou Liu } 228b940ca64SJ. German Rivera static inline int fdt_status_fail_by_alias(void *fdt, const char *alias) 229b940ca64SJ. German Rivera { 230b940ca64SJ. German Rivera return fdt_set_status_by_alias(fdt, alias, FDT_STATUS_FAIL, 0); 231b940ca64SJ. German Rivera } 2322a523f52SShengzhou Liu 23308df4a21SArnab Basu /* Helper to read a big number; size is in cells (not bytes) */ 23408df4a21SArnab Basu static inline u64 of_read_number(const fdt32_t *cell, int size) 23508df4a21SArnab Basu { 23608df4a21SArnab Basu u64 r = 0; 23708df4a21SArnab Basu while (size--) 23808df4a21SArnab Basu r = (r << 32) | fdt32_to_cpu(*(cell++)); 23908df4a21SArnab Basu return r; 24008df4a21SArnab Basu } 24108df4a21SArnab Basu 242f43b4356SArnab Basu void of_bus_default_count_cells(void *blob, int parentoffset, 243f43b4356SArnab Basu int *addrc, int *sizec); 244d50b07dfSJeroen Hofstee int ft_verify_fdt(void *fdt); 245d50b07dfSJeroen Hofstee int arch_fixup_memory_node(void *blob); 246f43b4356SArnab Basu 247d4f495a8SHans de Goede int fdt_setup_simplefb_node(void *fdt, int node, u64 base_address, u32 width, 248d4f495a8SHans de Goede u32 height, u32 stride, const char *format); 249d4f495a8SHans de Goede 25064dbbd40SGerald Van Baren #endif /* ifdef CONFIG_OF_LIBFDT */ 25129a23f9dSHeiko Schocher 25229a23f9dSHeiko Schocher #ifdef USE_HOSTCC 25329a23f9dSHeiko Schocher int fdtdec_get_int(const void *blob, int node, const char *prop_name, 25429a23f9dSHeiko Schocher int default_val); 25529a23f9dSHeiko Schocher #endif 25664dbbd40SGerald Van Baren #endif /* ifndef __FDT_SUPPORT_H */ 257