Guest User

ip804ar

a guest
Oct 2nd, 2025
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.28 KB | None | 0 0
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2.  
  3. #pragma once
  4.  
  5. #include <stdint.h>
  6.  
  7. #include "common.h"
  8. #include "poemgr.h"
  9.  
  10. /*
  11. * Calculate available power conservatively,
  12. * Conservative approach uses class defined power
  13. * Uncomment following line to output available power based on class defined power.
  14. *
  15. */
  16. // #define IP804AR_CONSERVATIVE_AVAILABLE_POWER
  17.  
  18. #define IP804AR_COMBINE_BYTES(msb, lsb) ((msb << 8) | lsb)
  19. #define IP804AR_POLL_IN_PROGRESS_RETRY (20)
  20.  
  21. #define IP804AR_REG_SETPAGE (0x00)
  22. #define IP804AR_OFFSET_SETPAGE (6)
  23. #define IP804AR_MASK_SETPAGE GENMASK(7, IP804AR_OFFSET_SETPAGE)
  24.  
  25. #define IP804AR_PAGE_RESET 1
  26. #define IP804AR_REG_RESET 0x02
  27.  
  28. #define IP804AR_PAGE_HW_REVISION 1
  29. #define IP804AR_REG_HW_REVISION_MSB 0x04 //0x03
  30. #define IP804AR_REG_HW_REVISION_LSB 0xA2 //0x04
  31.  
  32. #define IP804AR_PAGE_FORCE_POLL (0)
  33. #define IP804AR_REG_FORCE_POLL (0xE2) //3:0 IP804 1:0 IP802
  34. /************************* */
  35. //page 29 IVT Poll Register
  36. /* Poll period is in units of 8ms, default value as per datasheet is 2 (16ms period)*/
  37. #define IP804AR_PAGE_IVT_POLL (0)
  38. #define IP804AR_REG_IVT_POLL (0xE3)
  39. #define IP804AR_MASK_IVT_POLL_PERIOD GENMASK(3, 0)
  40. // 12 * 0.25 ms = 3 ms
  41. #define IP804AR_IVT_POLL_PERIOD (12)
  42. #define IP804AR_BIT_AUTO_POLL BIT(5)
  43. #define IP804AR_BIT_POLL_IN_PROGRESS BIT(7)
  44. /*************************** */
  45.  
  46. /* Opmode */
  47. #define IP804AR_PAGE_SYS_CONF 1
  48. #define IP804AR_REG_SYS_CONF 0x01
  49. #define IP804AR_MASK_OPMODE (GENMASK(7, 6))
  50.  
  51. /* Supply voltage */
  52. #define IP804AR_PAGE_SUPPLY_VOLTAGE 0
  53. #define IP804AR_REG_SUPPLY_VOLTAGE 0xe0
  54. // 4 bits fraction
  55. #define IP804AR_FBITS_SUPPLY_VOLTAGE (4)
  56.  
  57. /* port voltage */
  58. #define IP804AR_PAGE_PORT_VOLTAGE 0
  59. // 2 registers per port
  60. #define IP804AR_REG_PORT_VOLTAGE(port) (0xb0 + (port * 2))
  61. #define IP804AR_FBITS_PORT_VOLTAGE (4)
  62.  
  63. /* port temperature */
  64. #define IP804AR_PAGE_PORT_TEMP 0
  65. /**************** */
  66. /*Since the current register have 2 bytes, the I2C read CMD must Burst read 2
  67. bytes (hi byte First ) to avoid the deviation in reading the register value*/
  68. /**************** */
  69. // 2 registers per port
  70. #define IP804AR_REG_PORT_TEMP(port) (0xc0 + (port * 2))
  71. #define IP804AR_FBITS_PORT_TEMP (4)
  72.  
  73. /* port current */
  74. #define IP804AR_PAGE_PORT_CURR 0
  75. /**************** */
  76. /*Since the current register have 2 bytes, the I2C read CMD must Burst read 2
  77. bytes (hi byte First ) to avoid the deviation in reading the register value*/
  78. /**************** */
  79. // 2 registers per port
  80. #define IP804AR_REG_PORT_CURR(port) (0xa0 + (port * 2))
  81. #define IP804AR_FBITS_PORT_CURR (2)
  82.  
  83. /* port power */
  84. #define IP804AR_PAGE_REQUESTED_POWER (0)
  85. #define IP804AR_REG_REQUESTED_POWER(port) (0x90 + port)
  86.  
  87. /* port detection */
  88. #define IP804AR_PAGE_PORT_DET 0
  89. #define IP804AR_REG_PORT_DET(port) (0x68 + port)
  90. #define IP804AR_MASK_PORT_DET GENMASK(2, 0)
  91. #define IP804AR_PORT_DET_RBAD (0b000)
  92. #define IP804AR_PORT_DET_RGOOD (0b001)
  93. #define IP804AR_PORT_DET_ROPEN (0b010)
  94. #define IP804AR_PORT_DET_CLARGE (0b100)
  95. #define IP804AR_PORT_DET_RLOW (0b101)
  96. #define IP804AR_PORT_DET_RHIGH (0b110)
  97.  
  98. /* Power Limit */
  99. #define IP804AR_PWR_TRUNK_NUM 2
  100. #define IP804AR_PAGE_TRUNK_LIMIT 1
  101. #define IP804AR_REG_TRUNK_LIMIT(trunk) (0x40 + (trunk * 2))
  102. #define IP804AR_MASK_TRUNK_LIMIT_MSB GENMASK(2, 0)
  103. #define IP804AR_MASK_TRUNK_LIMIT_LSB GENMASK(7, 0)
  104.  
  105. #define IP804AR_MASK_TRUNK_LIMIT \
  106. IP804AR_COMBINE_BYTES(IP804AR_MASK_TRUNK_LIMIT_MSB, \
  107. IP804AR_MASK_TRUNK_LIMIT_LSB)
  108.  
  109. /* Port power control */
  110. #define IP804AR_PORT_DISABLED 0b00
  111. #define IP804AR_PORT_ENABLED 0b01
  112. #define IP804AR_PORT_FORCE 0b10
  113. /* Test only mode, not for production */
  114. // #define PORT_ENABLED_SKIP_DETECTION 0b11
  115. #define IP804AR_PAGE_PORT_POWER_CTRL 1
  116. #define IP804AR_REG_PORT_POWER_CTRL(port) (0x98 + port)
  117. #define IP804AR_MASK_PORT_POWER_CTRL GENMASK(1, 0)
  118.  
  119. /* state machine control */
  120. #define IP804AR_PAGE_SM_CTL (1)
  121. #define IP804AR_REG_SM_CTL(port) (0x90 + port)
  122. // #define IP804AR_BIT_START_PWR BIT(5)
  123. #define IP804AR_MASK_SM_STATE GENMASK(4, 0)
  124.  
  125. /* Power configuration mode */
  126. #define IP804AR_PAGE_POWER_CONFIG_MODE 1
  127. #define IP804AR_REG_POWER_CONFIG_MODE 0x10
  128. #define IP804AR_MASK_POWER_CONFIG_MODE GENMASK(4, 3)
  129. #define IP804AR_HOST_DEFINED_POWER_LIMIT (0 << 3)
  130. #define IP804AR_CLASS_DEFINED_POWER_LIMIT (1 << 3)
  131. #define IP804AR_MAX_AFAT_POWER_LIMIT (2 << 3)
  132. #define IP804AR_MASK_POWER_ESTIMATE_MODE GENMASK(1, 0)
  133. #define IP804AR_ESTIMATE_CLASS_POWER (0)
  134. #define IP804AR_ESTIMATE_CURRENT_POWER (1)
  135. #define IP804AR_ESTIMATE_MAX_POWER (2)
  136.  
  137. /* Port AFAT mode */
  138.  
  139. /******************** */
  140. /*AF/AT Mode. IP802AR
  141. The 2 bits represent the AF/AT mode of the 2 ports, where bit 0
  142. corresponds to port 0, and bit 1 corresponds to port 1, etc.
  143. 0 = AF mode.
  144. 1 = AT mode.*/
  145.  
  146. /*AF/AT Mode. IP804AR
  147. The 4 bits represent the af/at mode of the 4 ports, where bit 0
  148. corresponds to port 0, and bit 1 corresponds to port 1, etc.
  149. 0 = AF mode.
  150. 1 = AT mode.*/
  151.  
  152. #define IP804AR_PAGE_PORT_AFAT_MODE 0
  153. #define IP804AR_REG_PORT_AFAT_MODE 0x25
  154. #define IP804AR_MASK_PORT_AFAT_MODE(port) BIT(port) //for IP802AR
  155. /*#define IP804AR_MASK_PORT_AFAT_MODE(port) GENMASK(3, 0) ???? */
  156. #define IP804AR_AF_MODE(port) 0
  157. #define IP804AR_AT_MODE(port) BIT(port) //for IP802AR
  158.  
  159.  
  160. /* Port Detected PD Class */
  161.  
  162. /*
  163. #define IP802AR_PAGE_PORT_PD_CLASS 0
  164. #define IP802AR_REG_PORT_PD_CLASS(port) (0x88 + (port / 2))
  165.  
  166. #define IP802AR_SHIFT_PORT_PD_CLASS(port) (4 * (port % 2))
  167. #define IP802AR_MASK_PORT_PD_CLASS(port) \
  168. (GENMASK(2, 0) << IP804AR_SHIFT_PORT_PD_CLASS(port))
  169.  
  170. /*For PORT 3 & 4 IP804AR ?? */
  171. /*
  172. #define IP802AR_REG_PORT_PD_CLASS(port) (0x89 + (port / 2))
  173.  
  174. #define IP802AR_SHIFT_PORT_PD_CLASS(port) (4 * (port % 2))
  175. #define IP802AR_MASK_PORT_PD_CLASS(port) \
  176. (GENMASK(2, 0) << IP804AR_SHIFT_PORT_PD_CLASS(port))
  177. */
  178. /* PORT 0 PORT 1 */
  179. #define IP804AR_REG_PORT_PD_CLASS(0) (0x88, GENMASK_OL(2, 0)) /* PORT 0 2:0 */
  180. #define IP804AR_REG_PORT_PD_CLASS(1) (0x88, GENMASK_OL(6, 4)) /* PORT 1 6:4 */
  181. /* PORT 2 PORT3 */
  182. #define IP804AR_REG_PORT_PD_CLASS(2) (0x89, GENMASK_OL(2, 0)) /* PORT 2 2:0 */
  183. #define IP804AR_REG_PORT_PD_CLASS(3) (0x89, GENMASK_OL(6, 4)) /*PORT 3 6:4 */
  184.  
  185. #define IP804AR_PD_CLASS_0 0
  186. #define IP804AR_PD_CLASS_1 1
  187. #define IP804AR_PD_CLASS_2 2
  188. #define IP804AR_PD_CLASS_3 3
  189. #define IP804AR_PD_CLASS_4 4
  190. #define IP804AR_PD_CLASS_UNKNOWN 5
  191.  
  192. #define IP804AR_PAGE_PORT_PWR_EVT_HDL (1)
  193. #define IP804AR_REG_PORT_PWR_EVT_HDL (0x81)
  194. #define IP804AR_BIT_PORT_TEMP_LMT_EVT BIT(7)
  195. #define IP804AR_BIT_TRK_VOLT_LMT_EVT BIT(6)
  196. #define IP804AR_BIT_PORT_CUR_LMT_EVT BIT(5)
  197. #define IP804AR_BIT_PORT_VOLT_LMT_EVT BIT(3)
  198.  
  199. #define IP804AR_PAGE_PWR_EVT (1)
  200. #define IP804AR_REG_PWR_EVT (0x78)
  201. #define IP804AR_PAGE_HIPWR_CTRL (1)
  202. #define IP804AR_REG_HIPWR_CTRL (0xF3)
  203. #define IP804AR_BIT_HIPWR_DISCON_MODE BIT(4)
  204.  
  205. #define IP804AR_PAGE_PORT_PWR_STS (1)
  206. #define IP804AR_REG_PORT_PWR_STS (0x82)
  207.  
  208. /* Fault events */
  209. #define IP804AR_PAGE_PORT_EVENT (1)
  210. #define IP804AR_REG_PORT_EVENT(port) (0x70 + port)
  211.  
  212. /* current_overload_event */
  213. #define IP804AR_PAGE_FAULTS (1)
  214. // TODO:what is 0x85
  215. #define IP804AR_REG_CUR_OVERLOAD_EVT (0x84)
  216. #define IP804AR_BIT_CUR_OVERLOAD_EVT BIT(5)
  217. #define IP804AR_REG_BAD_VOLT_EVT (0x86)
  218. #define IP804AR_BIT_BAD_VOLT_EVT BIT(4)
  219. #define IP804AR_REG_SHORT_EVT (0x87)
  220. #define IP804AR_REG_CURR_LIM_PWR_OFF_EVT (0x60)
  221. #define IP804AR_REG_INVALID_SIG_EVT (0xDC)
  222. #define IP804AR_REG_POWER_DENIED (0xDA)
  223.  
  224. /* Metrics */
  225.  
  226. /* Trunk selection and limits */
  227. #define IP804AR_PAGE_TRUNK (1)
  228.  
  229. #define IP804AR_REG_TRUNK_SELECT (0x69)
  230. #define IP804AR_TRUNKX_MSB_BITS (0b111)
  231. #define IP804AR_REG_TRUNK0_POWER_LIMIT (0x40)
  232. #define IP804AR_REG_TRUNK1_POWER_LIMIT (0x42)
  233.  
  234. /* Current/Power limit type */
  235. #define IP804AR_PAGE_LIMIT_CTRL (1)
  236. #define IP804AR_REG_LIMIT_CTRL (0xc0)
  237. #define IP804AR_MASK_CURRENT_LIMIT (BIT(7))
  238. #define IP804AR_MASK_POWER_LIMIT (BIT(6))
  239. #define IP804AR_MASK_VICTIM_STRATEGY (GENMASK(2, 0))
  240.  
  241. /* Available current */
  242. #define IP804AR_PAGE_CURRENT (1)
  243. #define IP804AR_REG_AVAILABLE_CURRENT (0x54)
  244. #define IP804AR_MASK_AVAILABLE_CURRENT_MSB (GENMASK(6, 0))
  245. #define IP804AR_MASK_AVAILABLE_CURRENT_LSB (GENMASK(7, 0))
  246. #define IP804AR_REG_CONSUMED_CURRENT (0x56)
  247. #define IP804AR_PAGE_POWER (1)
  248. #define IP804AR_REG_AVAILABLE_POWER (0x6c)
  249. #define IP804AR_REG_CONSUMED_POWER (0x6a)
  250. /* Datasheet has this in two places with two different registers */
  251. #define _IP804AR_PAGE_AVAILABLE_POWER (2)
  252. #define _IP804AR_REG_AVAILABLE_POWER (0x2e)
  253.  
  254. /* PSE Allocated Power */
  255. #define IP804AR_PAGE_PSE_ALLOCATED_POWER (1)
  256. #define IP804AR_REG_PSE_ALLOCATED_POWER (0x6e)
  257.  
  258. struct IP804AR_priv {
  259. int i2c_fd;
  260.  
  261. int i2c_addr;
  262. };
  263.  
  264. enum operation_mode {
  265. AUTO_MODE = 0x00,
  266. MANUAL_MODE = BIT(6),
  267. DIAGNOSTIC_MODE = BIT(7),
  268. SCAN_MODE = GENMASK(7, 6),
  269. };
  270.  
  271. int IP804AR_init(struct poemgr_pse_chip *pse_chip, int i2c_bus, int i2c_addr,
  272. uint32_t port_mask);
  273. int IP804AR_device_online(struct poemgr_pse_chip *pse_chip);
  274. int IP804AR_device_enable_set(struct poemgr_pse_chip *pse_chip,
  275. int enable_disable);
  276. int IP804AR_port_enable_set(struct poemgr_pse_chip *pse_chip, int port,
  277. int enable_disable);
  278. int IP804AR_port_enable_get(struct poemgr_pse_chip *pse_chip, int port);
  279. int IP804AR_port_power_consumption_get(struct poemgr_pse_chip *pse_chip,
  280. int port);
  281. int IP804AR_port_afat_mode_set(struct poemgr_pse_chip *pse_chip, int port,
  282. int mode);
  283. int IP804AR_port_detection_classification_set(struct poemgr_pse_chip *pse_chip,
  284. int port, int enable);
  285. int IP804AR_port_poe_class_get(struct poemgr_pse_chip *pse_chip, int port);
  286. int IP804AR_port_good_get(struct poemgr_pse_chip *pse_chip, int port);
  287. int IP804AR_port_power_limit_get(struct poemgr_pse_chip *pse_chip, int port);
  288. int IP804AR_system_power_budget_set(struct poemgr_pse_chip *pse_chip, int bank,
  289. int val);
  290. int IP804AR_system_current_budget_set(struct poemgr_pse_chip *pse_chip,
  291. int milliamps);
  292. int IP804AR_port_faults_get(struct poemgr_pse_chip *pse_chip, int port);
  293. int IP804AR_clear_faults(struct poemgr_pse_chip *pse_chip, int num_ports);
  294. int IP804AR_export_port_metric(struct poemgr_pse_chip *pse_chip, int port,
  295. const struct poemgr_port_status *p_status,
  296. struct poemgr_metric *output, int metric);
  297. int IP804AR_export_metric(struct poemgr_pse_chip *pse_chip,
  298. struct poemgr_metric *output, int metric);
  299.  
Advertisement
Add Comment
Please, Sign In to add comment