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); 70*5c1cf89fSAndre Przywara /** 71*5c1cf89fSAndre Przywara * Setup the memory node in the DT. Creates one if none was existing before. 72*5c1cf89fSAndre Przywara * Calls fdt_fixup_memory_banks() to populate a single reg pair covering the 73*5c1cf89fSAndre Przywara * whole memory. 74*5c1cf89fSAndre Przywara * 75*5c1cf89fSAndre Przywara * @param blob FDT blob to update 76*5c1cf89fSAndre Przywara * @param start Begin of DRAM mapping in physical memory 77*5c1cf89fSAndre Przywara * @param size Size of the single memory bank 78*5c1cf89fSAndre Przywara * @return 0 if ok, or -1 or -FDT_ERR_... on error 79*5c1cf89fSAndre Przywara */ 803c927281SKumar Gala int fdt_fixup_memory(void *blob, u64 start, u64 size); 81*5c1cf89fSAndre Przywara 82*5c1cf89fSAndre Przywara /** 83*5c1cf89fSAndre Przywara * Fill the DT memory node with multiple memory banks. 84*5c1cf89fSAndre Przywara * Creates the node if none was existing before. 85*5c1cf89fSAndre Przywara * If banks is 0, it will not touch the existing reg property. This allows 86*5c1cf89fSAndre Przywara * boards to not mess with the existing DT setup, which may have been 87*5c1cf89fSAndre Przywara * filled in properly before. 88*5c1cf89fSAndre Przywara * 89*5c1cf89fSAndre Przywara * @param blob FDT blob to update 90*5c1cf89fSAndre Przywara * @param start Array of size <banks> to hold the start addresses. 91*5c1cf89fSAndre Przywara * @param size Array of size <banks> to hold the size of each region. 92*5c1cf89fSAndre Przywara * @param banks Number of memory banks to create. If 0, the reg 93*5c1cf89fSAndre Przywara * property will be left untouched. 94*5c1cf89fSAndre Przywara * @return 0 if ok, or -1 or -FDT_ERR_... on error 95*5c1cf89fSAndre Przywara */ 96a6bd9e83SJohn Rigby int fdt_fixup_memory_banks(void *blob, u64 start[], u64 size[], int banks); 97*5c1cf89fSAndre 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 11679f49120Sramneek mehresh #if defined(CONFIG_HAS_FSL_DR_USB) || defined(CONFIG_HAS_FSL_MPH_USB) 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) {} 12079f49120Sramneek mehresh #endif /* defined(CONFIG_HAS_FSL_DR_USB) || defined(CONFIG_HAS_FSL_MPH_USB) */ 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 1753c950e2eSAnatolij Gustschin void fdt_fixup_mtdparts(void *fdt, void *node_info, int node_info_size); 17649b97d9cSKumar Gala void fdt_del_node_and_alias(void *blob, const char *alias); 1778aa5ec6eSKim Phillips u64 fdt_translate_address(void *blob, int node_offset, const __be32 *in_addr); 17875e73afdSKumar Gala int fdt_node_offset_by_compat_reg(void *blob, const char *compat, 17975e73afdSKumar Gala phys_addr_t compat_off); 180b4b847e9SKumar Gala int fdt_alloc_phandle(void *blob); 181f117c0f0SKumar Gala int fdt_set_phandle(void *fdt, int nodeoffset, uint32_t phandle); 1823c927cccSTimur Tabi unsigned int fdt_create_phandle(void *fdt, int nodeoffset); 183beca5a5fSAnatolij Gustschin int fdt_add_edid(void *blob, const char *compat, unsigned char *buf); 1843c950e2eSAnatolij Gustschin 185bb682001STimur Tabi int fdt_verify_alias_address(void *fdt, int anode, const char *alias, 186bb682001STimur Tabi u64 addr); 187bb682001STimur Tabi u64 fdt_get_base_address(void *fdt, int node); 188c48e6868SAlexander Graf int fdt_read_range(void *fdt, int node, int n, uint64_t *child_addr, 189c48e6868SAlexander Graf uint64_t *addr, uint64_t *len); 190bb682001STimur Tabi 1912a523f52SShengzhou Liu enum fdt_status { 1922a523f52SShengzhou Liu FDT_STATUS_OKAY, 1932a523f52SShengzhou Liu FDT_STATUS_DISABLED, 1942a523f52SShengzhou Liu FDT_STATUS_FAIL, 1952a523f52SShengzhou Liu FDT_STATUS_FAIL_ERROR_CODE, 1962a523f52SShengzhou Liu }; 1972a523f52SShengzhou Liu int fdt_set_node_status(void *fdt, int nodeoffset, 1982a523f52SShengzhou Liu enum fdt_status status, unsigned int error_code); 1992a523f52SShengzhou Liu static inline int fdt_status_okay(void *fdt, int nodeoffset) 2002a523f52SShengzhou Liu { 2012a523f52SShengzhou Liu return fdt_set_node_status(fdt, nodeoffset, FDT_STATUS_OKAY, 0); 2022a523f52SShengzhou Liu } 2032a523f52SShengzhou Liu static inline int fdt_status_disabled(void *fdt, int nodeoffset) 2042a523f52SShengzhou Liu { 2052a523f52SShengzhou Liu return fdt_set_node_status(fdt, nodeoffset, FDT_STATUS_DISABLED, 0); 2062a523f52SShengzhou Liu } 207b940ca64SJ. German Rivera static inline int fdt_status_fail(void *fdt, int nodeoffset) 208b940ca64SJ. German Rivera { 209b940ca64SJ. German Rivera return fdt_set_node_status(fdt, nodeoffset, FDT_STATUS_FAIL, 0); 210b940ca64SJ. German Rivera } 2112a523f52SShengzhou Liu 2122a523f52SShengzhou Liu int fdt_set_status_by_alias(void *fdt, const char *alias, 2132a523f52SShengzhou Liu enum fdt_status status, unsigned int error_code); 2142a523f52SShengzhou Liu static inline int fdt_status_okay_by_alias(void *fdt, const char *alias) 2152a523f52SShengzhou Liu { 2162a523f52SShengzhou Liu return fdt_set_status_by_alias(fdt, alias, FDT_STATUS_OKAY, 0); 2172a523f52SShengzhou Liu } 2182a523f52SShengzhou Liu static inline int fdt_status_disabled_by_alias(void *fdt, const char *alias) 2192a523f52SShengzhou Liu { 2202a523f52SShengzhou Liu return fdt_set_status_by_alias(fdt, alias, FDT_STATUS_DISABLED, 0); 2212a523f52SShengzhou Liu } 222b940ca64SJ. German Rivera static inline int fdt_status_fail_by_alias(void *fdt, const char *alias) 223b940ca64SJ. German Rivera { 224b940ca64SJ. German Rivera return fdt_set_status_by_alias(fdt, alias, FDT_STATUS_FAIL, 0); 225b940ca64SJ. German Rivera } 2262a523f52SShengzhou Liu 22708df4a21SArnab Basu /* Helper to read a big number; size is in cells (not bytes) */ 22808df4a21SArnab Basu static inline u64 of_read_number(const fdt32_t *cell, int size) 22908df4a21SArnab Basu { 23008df4a21SArnab Basu u64 r = 0; 23108df4a21SArnab Basu while (size--) 23208df4a21SArnab Basu r = (r << 32) | fdt32_to_cpu(*(cell++)); 23308df4a21SArnab Basu return r; 23408df4a21SArnab Basu } 23508df4a21SArnab Basu 236f43b4356SArnab Basu void of_bus_default_count_cells(void *blob, int parentoffset, 237f43b4356SArnab Basu int *addrc, int *sizec); 238d50b07dfSJeroen Hofstee int ft_verify_fdt(void *fdt); 239d50b07dfSJeroen Hofstee int arch_fixup_memory_node(void *blob); 240f43b4356SArnab Basu 241d4f495a8SHans de Goede int fdt_setup_simplefb_node(void *fdt, int node, u64 base_address, u32 width, 242d4f495a8SHans de Goede u32 height, u32 stride, const char *format); 243d4f495a8SHans de Goede 24464dbbd40SGerald Van Baren #endif /* ifdef CONFIG_OF_LIBFDT */ 24529a23f9dSHeiko Schocher 24629a23f9dSHeiko Schocher #ifdef USE_HOSTCC 24729a23f9dSHeiko Schocher int fdtdec_get_int(const void *blob, int node, const char *prop_name, 24829a23f9dSHeiko Schocher int default_val); 24929a23f9dSHeiko Schocher #endif 25064dbbd40SGerald Van Baren #endif /* ifndef __FDT_SUPPORT_H */ 251