octeon_fdt.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2020 Marvell International Ltd.
  4. */
  5. #ifndef __OCTEON_FDT_H__
  6. #define __OCTEON_FDT_H__
  7. struct phy_device;
  8. /** Type of GPIO pin */
  9. enum octeon_gpio_type {
  10. GPIO_TYPE_OCTEON, /** Native Octeon */
  11. GPIO_TYPE_PCA953X, /** PCA953X i2c GPIO expander */
  12. GPIO_TYPE_PCA9554, /** PCA9554 i2c GPIO expander */
  13. GPIO_TYPE_PCA9555, /** PCA9555 i2c GPIO expander */
  14. GPIO_TYPE_PCA9698, /** PCA9698 i2c GPIO expander */
  15. #ifdef CONFIG_PHY_VITESSE
  16. GPIO_TYPE_VSC8488, /** Vitesse VSC8488 or related PHY GPIO */
  17. #endif
  18. GPIO_TYPE_UNKNOWN /** Unknown GPIO type */
  19. };
  20. /**
  21. * Trims nodes from the flat device tree.
  22. *
  23. * @param fdt - pointer to working FDT, usually in gd->fdt_blob
  24. * @param fdt_key - key to preserve. All non-matching keys are removed
  25. * @param trim_name - name of property to look for. If NULL use
  26. * 'cavium,qlm-trim'
  27. * @param rename - set to TRUE to rename interfaces.
  28. * @param callback - function to call on matched nodes.
  29. * @param cbarg - passed to callback.
  30. *
  31. * The key should look something like device #, type where device # is a
  32. * number from 0-9 and type is a string describing the type. For QLM
  33. * operations this would typically contain the QLM number followed by
  34. * the type in the device tree, like "0,xaui", "0,sgmii", etc. This function
  35. * will trim all items in the device tree which match the device number but
  36. * have a type which does not match. For example, if a QLM has a xaui module
  37. * installed on QLM 0 and "0,xaui" is passed as a key, then all FDT nodes that
  38. * have "0,xaui" will be preserved but all others, i.e. "0,sgmii" will be
  39. * removed.
  40. *
  41. * Note that the trim_name must also match. If trim_name is NULL then it
  42. * looks for the property "cavium,qlm-trim".
  43. *
  44. * Also, when the trim_name is "cavium,qlm-trim" or NULL that the interfaces
  45. * will also be renamed based on their register values.
  46. *
  47. * For example, if a PIP interface is named "interface@W" and has the property
  48. * reg = <0> then the interface will be renamed after this function to
  49. * interface@0.
  50. *
  51. * Return: 0 for success.
  52. */
  53. int octeon_fdt_patch_rename(void *fdt, const char *fdt_key, const char *trim_name, bool rename,
  54. void (*callback)(void *fdt, int offset, void *arg), void *cbarg);
  55. /**
  56. * Trims nodes from the flat device tree.
  57. *
  58. * @param fdt - pointer to working FDT, usually in gd->fdt_blob
  59. * @param fdt_key - key to preserve. All non-matching keys are removed
  60. * @param trim_name - name of property to look for. If NULL use
  61. * 'cavium,qlm-trim'
  62. *
  63. * The key should look something like device #, type where device # is a
  64. * number from 0-9 and type is a string describing the type. For QLM
  65. * operations this would typically contain the QLM number followed by
  66. * the type in the device tree, like "0,xaui", "0,sgmii", etc. This function
  67. * will trim all items in the device tree which match the device number but
  68. * have a type which does not match. For example, if a QLM has a xaui module
  69. * installed on QLM 0 and "0,xaui" is passed as a key, then all FDT nodes that
  70. * have "0,xaui" will be preserved but all others, i.e. "0,sgmii" will be
  71. * removed.
  72. *
  73. * Note that the trim_name must also match. If trim_name is NULL then it
  74. * looks for the property "cavium,qlm-trim".
  75. *
  76. * Also, when the trim_name is "cavium,qlm-trim" or NULL that the interfaces
  77. * will also be renamed based on their register values.
  78. *
  79. * For example, if a PIP interface is named "interface@W" and has the property
  80. * reg = <0> then the interface will be renamed after this function to
  81. * interface@0.
  82. *
  83. * Return: 0 for success.
  84. */
  85. int octeon_fdt_patch(void *fdt, const char *fdt_key, const char *trim_name);
  86. /**
  87. * Fix up the MAC address in the flat device tree based on the MAC address
  88. * stored in ethaddr or in the board descriptor.
  89. *
  90. * NOTE: This function is weak and an alias for __octeon_fixup_fdt_mac_addr.
  91. */
  92. void octeon_fixup_fdt_mac_addr(void);
  93. /**
  94. * This function fixes the clock-frequency in the flat device tree for the UART.
  95. *
  96. * NOTE: This function is weak and an alias for __octeon_fixup_fdt_uart.
  97. */
  98. void octeon_fixup_fdt_uart(void);
  99. /**
  100. * This function fills in the /memory portion of the flat device tree.
  101. *
  102. * NOTE: This function is weak and aliased to __octeon_fixup_fdt_memory.
  103. */
  104. void octeon_fixup_fdt_memory(void);
  105. int board_fixup_fdt(void);
  106. void octeon_fixup_fdt(void);
  107. /**
  108. * This is a helper function to find the offset of a PHY device given
  109. * an Ethernet device.
  110. *
  111. * @param[in] eth - Ethernet device to search for PHY offset
  112. *
  113. * @returns offset of phy info in device tree or -1 if not found
  114. */
  115. int octeon_fdt_find_phy(const struct udevice *eth);
  116. /**
  117. * This helper function returns if a node contains the specified vendor name.
  118. *
  119. * @param[in] fdt pointer to device tree blob
  120. * @param nodeoffset offset of the tree node
  121. * @param[in] vendor name of vendor to check
  122. *
  123. * returns:
  124. * 0, if the node has a compatible vendor string property
  125. * 1, if the node does not contain the vendor string property
  126. * -FDT_ERR_NOTFOUND, if the given node has no 'compatible' property
  127. * -FDT_ERR_BADOFFSET, if nodeoffset does not refer to a BEGIN_NODE tag
  128. * -FDT_ERR_BADMAGIC,
  129. * -FDT_ERR_BADVERSION,
  130. * -FDT_BADSTATE,
  131. * -FDT_ERR_BADSTRUCTURE, standard meanings
  132. */
  133. int octeon_fdt_compat_vendor(const void *fdt, int nodeoffset, const char *vendor);
  134. /**
  135. * Given a node in the device tree get the OCTEON OCX node number
  136. *
  137. * @param fdt pointer to flat device tree
  138. * @param nodeoffset node offset to get OCX node for
  139. *
  140. * Return: the Octeon OCX node number
  141. */
  142. int octeon_fdt_get_soc_node(const void *fdt, int nodeoffset);
  143. /**
  144. * Given a FDT node, check if it is compatible with a list of devices
  145. *
  146. * @param[in] fdt Flat device tree pointer
  147. * @param node_offset Node offset in device tree
  148. * @param[in] strlist Array of FDT devices to check, end must be NULL
  149. *
  150. * Return: 0 if at least one device is compatible, 1 if not compatible.
  151. */
  152. int octeon_fdt_node_check_compatible(const void *fdt, int node_offset, const char *const *strlist);
  153. /**
  154. * Given a node offset, find the i2c bus number for that node
  155. *
  156. * @param[in] fdt Pointer to flat device tree
  157. * @param node_offset Node offset in device tree
  158. *
  159. * Return: i2c bus number or -1 if error
  160. */
  161. int octeon_fdt_i2c_get_bus(const void *fdt, int node_offset);
  162. /**
  163. * Given an offset into the fdt, output the i2c bus and address of the device
  164. *
  165. * @param[in] fdt fdt blob pointer
  166. * @param node offset in FDT of device
  167. * @param[out] bus i2c bus number of device
  168. * @param[out] addr address of device on i2c bus
  169. *
  170. * Return: 0 for success, -1 on error
  171. */
  172. int octeon_fdt_get_i2c_bus_addr(const void *fdt, int node, int *bus, int *addr);
  173. /**
  174. * Reads a GPIO pin given the node of the GPIO device in the device tree and
  175. * the pin number.
  176. *
  177. * @param[in] fdt fdt blob pointer
  178. * @param phandle phandle of GPIO node
  179. * @param pin pin number to read
  180. *
  181. * Return: 0 = pin is low, 1 = pin is high, -1 = error
  182. */
  183. int octeon_fdt_read_gpio(const void *fdt, int phandle, int pin);
  184. /**
  185. * Reads a GPIO pin given the node of the GPIO device in the device tree and
  186. * the pin number.
  187. *
  188. * @param[in] fdt fdt blob pointer
  189. * @param phandle phandle of GPIO node
  190. * @param pin pin number to read
  191. * @param val value to write (1 = high, 0 = low)
  192. *
  193. * Return: 0 = success, -1 = error
  194. */
  195. int octeon_fdt_set_gpio(const void *fdt, int phandle, int pin, int val);
  196. /**
  197. * Given the node to a MAC entry in the device tree, output the i2c bus, address
  198. * and if the module is absent.
  199. *
  200. * @param[in] fdt flat device tree pointer
  201. * @param mac_node node of Ethernet port in the FDT
  202. * @param[out] bus i2c bus address of SFP EEPROM
  203. * @param[out] addr i2c address of SFP EEPROM
  204. * @param[out] mod_abs Set true if module is absent, false if present
  205. *
  206. * Return: 0 for success, -1 if there are problems with the device tree
  207. */
  208. int octeon_fdt_get_sfp_eeprom(const void *fdt, int mac_node, int *bus, int *addr, bool *mod_abs);
  209. /**
  210. * Given a node to a MAC entry in the device tree, output the i2c bus, address
  211. * and if the module is absent
  212. *
  213. * @param[in] fdt flat device tree pointer
  214. * @param mac_node node of QSFP Ethernet port in FDT
  215. * @param[out] bus i2c bus address of SFP EEPROM
  216. * @param[out] addr i2c address of SFP eeprom
  217. * @param[out] mod_abs Set true if module is absent, false if present
  218. *
  219. * Return: 0 for success, -1 if there are problems with the device tree
  220. */
  221. int octeon_fdt_get_qsfp_eeprom(const void *fdt, int mac_node, int *bus, int *addr, bool *mod_abs);
  222. /**
  223. * Given the node of a GPIO entry output the GPIO type, i2c bus and i2c
  224. * address.
  225. *
  226. * @param fdt_node node of GPIO in device tree, generally
  227. * derived from a phandle.
  228. * @param[out] type Type of GPIO detected
  229. * @param[out] i2c_bus For i2c GPIO expanders, the i2c bus number
  230. * @param[out] i2c_addr For i2c GPIO expanders, the i2c address
  231. *
  232. * Return: 0 for success, -1 for errors
  233. *
  234. * NOTE: It is up to the caller to determine the pin number.
  235. */
  236. int octeon_fdt_get_gpio_info(int fdt_node, enum octeon_gpio_type *type, int *i2c_bus,
  237. int *i2c_addr);
  238. /**
  239. * Get the PHY data structure for the specified FDT node and output the type
  240. *
  241. * @param fdt_node FDT node of phy
  242. * @param[out] type Type of GPIO
  243. *
  244. * Return: pointer to phy device or NULL if no match found.
  245. */
  246. struct phy_device *octeon_fdt_get_phy_gpio_info(int fdt_node, enum octeon_gpio_type *type);
  247. #endif /* __OCTEON_FDT_H__ */