pmbus.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. /*
  2. * pmbus.h - Common defines and structures for PMBus devices
  3. *
  4. * Copyright (c) 2010, 2011 Ericsson AB.
  5. * Copyright (c) 2012 Guenter Roeck
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. #ifndef PMBUS_H
  22. #define PMBUS_H
  23. #include <linux/bitops.h>
  24. #include <linux/regulator/driver.h>
  25. /*
  26. * Registers
  27. */
  28. enum pmbus_regs {
  29. PMBUS_PAGE = 0x00,
  30. PMBUS_OPERATION = 0x01,
  31. PMBUS_ON_OFF_CONFIG = 0x02,
  32. PMBUS_CLEAR_FAULTS = 0x03,
  33. PMBUS_PHASE = 0x04,
  34. PMBUS_CAPABILITY = 0x19,
  35. PMBUS_QUERY = 0x1A,
  36. PMBUS_VOUT_MODE = 0x20,
  37. PMBUS_VOUT_COMMAND = 0x21,
  38. PMBUS_VOUT_TRIM = 0x22,
  39. PMBUS_VOUT_CAL_OFFSET = 0x23,
  40. PMBUS_VOUT_MAX = 0x24,
  41. PMBUS_VOUT_MARGIN_HIGH = 0x25,
  42. PMBUS_VOUT_MARGIN_LOW = 0x26,
  43. PMBUS_VOUT_TRANSITION_RATE = 0x27,
  44. PMBUS_VOUT_DROOP = 0x28,
  45. PMBUS_VOUT_SCALE_LOOP = 0x29,
  46. PMBUS_VOUT_SCALE_MONITOR = 0x2A,
  47. PMBUS_COEFFICIENTS = 0x30,
  48. PMBUS_POUT_MAX = 0x31,
  49. PMBUS_FAN_CONFIG_12 = 0x3A,
  50. PMBUS_FAN_COMMAND_1 = 0x3B,
  51. PMBUS_FAN_COMMAND_2 = 0x3C,
  52. PMBUS_FAN_CONFIG_34 = 0x3D,
  53. PMBUS_FAN_COMMAND_3 = 0x3E,
  54. PMBUS_FAN_COMMAND_4 = 0x3F,
  55. PMBUS_VOUT_OV_FAULT_LIMIT = 0x40,
  56. PMBUS_VOUT_OV_FAULT_RESPONSE = 0x41,
  57. PMBUS_VOUT_OV_WARN_LIMIT = 0x42,
  58. PMBUS_VOUT_UV_WARN_LIMIT = 0x43,
  59. PMBUS_VOUT_UV_FAULT_LIMIT = 0x44,
  60. PMBUS_VOUT_UV_FAULT_RESPONSE = 0x45,
  61. PMBUS_IOUT_OC_FAULT_LIMIT = 0x46,
  62. PMBUS_IOUT_OC_FAULT_RESPONSE = 0x47,
  63. PMBUS_IOUT_OC_LV_FAULT_LIMIT = 0x48,
  64. PMBUS_IOUT_OC_LV_FAULT_RESPONSE = 0x49,
  65. PMBUS_IOUT_OC_WARN_LIMIT = 0x4A,
  66. PMBUS_IOUT_UC_FAULT_LIMIT = 0x4B,
  67. PMBUS_IOUT_UC_FAULT_RESPONSE = 0x4C,
  68. PMBUS_OT_FAULT_LIMIT = 0x4F,
  69. PMBUS_OT_FAULT_RESPONSE = 0x50,
  70. PMBUS_OT_WARN_LIMIT = 0x51,
  71. PMBUS_UT_WARN_LIMIT = 0x52,
  72. PMBUS_UT_FAULT_LIMIT = 0x53,
  73. PMBUS_UT_FAULT_RESPONSE = 0x54,
  74. PMBUS_VIN_OV_FAULT_LIMIT = 0x55,
  75. PMBUS_VIN_OV_FAULT_RESPONSE = 0x56,
  76. PMBUS_VIN_OV_WARN_LIMIT = 0x57,
  77. PMBUS_VIN_UV_WARN_LIMIT = 0x58,
  78. PMBUS_VIN_UV_FAULT_LIMIT = 0x59,
  79. PMBUS_IIN_OC_FAULT_LIMIT = 0x5B,
  80. PMBUS_IIN_OC_WARN_LIMIT = 0x5D,
  81. PMBUS_POUT_OP_FAULT_LIMIT = 0x68,
  82. PMBUS_POUT_OP_WARN_LIMIT = 0x6A,
  83. PMBUS_PIN_OP_WARN_LIMIT = 0x6B,
  84. PMBUS_STATUS_BYTE = 0x78,
  85. PMBUS_STATUS_WORD = 0x79,
  86. PMBUS_STATUS_VOUT = 0x7A,
  87. PMBUS_STATUS_IOUT = 0x7B,
  88. PMBUS_STATUS_INPUT = 0x7C,
  89. PMBUS_STATUS_TEMPERATURE = 0x7D,
  90. PMBUS_STATUS_CML = 0x7E,
  91. PMBUS_STATUS_OTHER = 0x7F,
  92. PMBUS_STATUS_MFR_SPECIFIC = 0x80,
  93. PMBUS_STATUS_FAN_12 = 0x81,
  94. PMBUS_STATUS_FAN_34 = 0x82,
  95. PMBUS_READ_VIN = 0x88,
  96. PMBUS_READ_IIN = 0x89,
  97. PMBUS_READ_VCAP = 0x8A,
  98. PMBUS_READ_VOUT = 0x8B,
  99. PMBUS_READ_IOUT = 0x8C,
  100. PMBUS_READ_TEMPERATURE_1 = 0x8D,
  101. PMBUS_READ_TEMPERATURE_2 = 0x8E,
  102. PMBUS_READ_TEMPERATURE_3 = 0x8F,
  103. PMBUS_READ_FAN_SPEED_1 = 0x90,
  104. PMBUS_READ_FAN_SPEED_2 = 0x91,
  105. PMBUS_READ_FAN_SPEED_3 = 0x92,
  106. PMBUS_READ_FAN_SPEED_4 = 0x93,
  107. PMBUS_READ_DUTY_CYCLE = 0x94,
  108. PMBUS_READ_FREQUENCY = 0x95,
  109. PMBUS_READ_POUT = 0x96,
  110. PMBUS_READ_PIN = 0x97,
  111. PMBUS_REVISION = 0x98,
  112. PMBUS_MFR_ID = 0x99,
  113. PMBUS_MFR_MODEL = 0x9A,
  114. PMBUS_MFR_REVISION = 0x9B,
  115. PMBUS_MFR_LOCATION = 0x9C,
  116. PMBUS_MFR_DATE = 0x9D,
  117. PMBUS_MFR_SERIAL = 0x9E,
  118. /*
  119. * Virtual registers.
  120. * Useful to support attributes which are not supported by standard PMBus
  121. * registers but exist as manufacturer specific registers on individual chips.
  122. * Must be mapped to real registers in device specific code.
  123. *
  124. * Semantics:
  125. * Virtual registers are all word size.
  126. * READ registers are read-only; writes are either ignored or return an error.
  127. * RESET registers are read/write. Reading reset registers returns zero
  128. * (used for detection), writing any value causes the associated history to be
  129. * reset.
  130. * Virtual registers have to be handled in device specific driver code. Chip
  131. * driver code returns non-negative register values if a virtual register is
  132. * supported, or a negative error code if not. The chip driver may return
  133. * -ENODATA or any other error code in this case, though an error code other
  134. * than -ENODATA is handled more efficiently and thus preferred. Either case,
  135. * the calling PMBus core code will abort if the chip driver returns an error
  136. * code when reading or writing virtual registers.
  137. */
  138. PMBUS_VIRT_BASE = 0x100,
  139. PMBUS_VIRT_READ_TEMP_AVG,
  140. PMBUS_VIRT_READ_TEMP_MIN,
  141. PMBUS_VIRT_READ_TEMP_MAX,
  142. PMBUS_VIRT_RESET_TEMP_HISTORY,
  143. PMBUS_VIRT_READ_VIN_AVG,
  144. PMBUS_VIRT_READ_VIN_MIN,
  145. PMBUS_VIRT_READ_VIN_MAX,
  146. PMBUS_VIRT_RESET_VIN_HISTORY,
  147. PMBUS_VIRT_READ_IIN_AVG,
  148. PMBUS_VIRT_READ_IIN_MIN,
  149. PMBUS_VIRT_READ_IIN_MAX,
  150. PMBUS_VIRT_RESET_IIN_HISTORY,
  151. PMBUS_VIRT_READ_PIN_AVG,
  152. PMBUS_VIRT_READ_PIN_MIN,
  153. PMBUS_VIRT_READ_PIN_MAX,
  154. PMBUS_VIRT_RESET_PIN_HISTORY,
  155. PMBUS_VIRT_READ_POUT_AVG,
  156. PMBUS_VIRT_READ_POUT_MIN,
  157. PMBUS_VIRT_READ_POUT_MAX,
  158. PMBUS_VIRT_RESET_POUT_HISTORY,
  159. PMBUS_VIRT_READ_VOUT_AVG,
  160. PMBUS_VIRT_READ_VOUT_MIN,
  161. PMBUS_VIRT_READ_VOUT_MAX,
  162. PMBUS_VIRT_RESET_VOUT_HISTORY,
  163. PMBUS_VIRT_READ_IOUT_AVG,
  164. PMBUS_VIRT_READ_IOUT_MIN,
  165. PMBUS_VIRT_READ_IOUT_MAX,
  166. PMBUS_VIRT_RESET_IOUT_HISTORY,
  167. PMBUS_VIRT_READ_TEMP2_AVG,
  168. PMBUS_VIRT_READ_TEMP2_MIN,
  169. PMBUS_VIRT_READ_TEMP2_MAX,
  170. PMBUS_VIRT_RESET_TEMP2_HISTORY,
  171. PMBUS_VIRT_READ_VMON,
  172. PMBUS_VIRT_VMON_UV_WARN_LIMIT,
  173. PMBUS_VIRT_VMON_OV_WARN_LIMIT,
  174. PMBUS_VIRT_VMON_UV_FAULT_LIMIT,
  175. PMBUS_VIRT_VMON_OV_FAULT_LIMIT,
  176. PMBUS_VIRT_STATUS_VMON,
  177. };
  178. /*
  179. * OPERATION
  180. */
  181. #define PB_OPERATION_CONTROL_ON BIT(7)
  182. /*
  183. * CAPABILITY
  184. */
  185. #define PB_CAPABILITY_SMBALERT BIT(4)
  186. #define PB_CAPABILITY_ERROR_CHECK BIT(7)
  187. /*
  188. * VOUT_MODE
  189. */
  190. #define PB_VOUT_MODE_MODE_MASK 0xe0
  191. #define PB_VOUT_MODE_PARAM_MASK 0x1f
  192. #define PB_VOUT_MODE_LINEAR 0x00
  193. #define PB_VOUT_MODE_VID 0x20
  194. #define PB_VOUT_MODE_DIRECT 0x40
  195. /*
  196. * Fan configuration
  197. */
  198. #define PB_FAN_2_PULSE_MASK (BIT(0) | BIT(1))
  199. #define PB_FAN_2_RPM BIT(2)
  200. #define PB_FAN_2_INSTALLED BIT(3)
  201. #define PB_FAN_1_PULSE_MASK (BIT(4) | BIT(5))
  202. #define PB_FAN_1_RPM BIT(6)
  203. #define PB_FAN_1_INSTALLED BIT(7)
  204. /*
  205. * STATUS_BYTE, STATUS_WORD (lower)
  206. */
  207. #define PB_STATUS_NONE_ABOVE BIT(0)
  208. #define PB_STATUS_CML BIT(1)
  209. #define PB_STATUS_TEMPERATURE BIT(2)
  210. #define PB_STATUS_VIN_UV BIT(3)
  211. #define PB_STATUS_IOUT_OC BIT(4)
  212. #define PB_STATUS_VOUT_OV BIT(5)
  213. #define PB_STATUS_OFF BIT(6)
  214. #define PB_STATUS_BUSY BIT(7)
  215. /*
  216. * STATUS_WORD (upper)
  217. */
  218. #define PB_STATUS_UNKNOWN BIT(8)
  219. #define PB_STATUS_OTHER BIT(9)
  220. #define PB_STATUS_FANS BIT(10)
  221. #define PB_STATUS_POWER_GOOD_N BIT(11)
  222. #define PB_STATUS_WORD_MFR BIT(12)
  223. #define PB_STATUS_INPUT BIT(13)
  224. #define PB_STATUS_IOUT_POUT BIT(14)
  225. #define PB_STATUS_VOUT BIT(15)
  226. /*
  227. * STATUS_IOUT
  228. */
  229. #define PB_POUT_OP_WARNING BIT(0)
  230. #define PB_POUT_OP_FAULT BIT(1)
  231. #define PB_POWER_LIMITING BIT(2)
  232. #define PB_CURRENT_SHARE_FAULT BIT(3)
  233. #define PB_IOUT_UC_FAULT BIT(4)
  234. #define PB_IOUT_OC_WARNING BIT(5)
  235. #define PB_IOUT_OC_LV_FAULT BIT(6)
  236. #define PB_IOUT_OC_FAULT BIT(7)
  237. /*
  238. * STATUS_VOUT, STATUS_INPUT
  239. */
  240. #define PB_VOLTAGE_UV_FAULT BIT(4)
  241. #define PB_VOLTAGE_UV_WARNING BIT(5)
  242. #define PB_VOLTAGE_OV_WARNING BIT(6)
  243. #define PB_VOLTAGE_OV_FAULT BIT(7)
  244. /*
  245. * STATUS_INPUT
  246. */
  247. #define PB_PIN_OP_WARNING BIT(0)
  248. #define PB_IIN_OC_WARNING BIT(1)
  249. #define PB_IIN_OC_FAULT BIT(2)
  250. /*
  251. * STATUS_TEMPERATURE
  252. */
  253. #define PB_TEMP_UT_FAULT BIT(4)
  254. #define PB_TEMP_UT_WARNING BIT(5)
  255. #define PB_TEMP_OT_WARNING BIT(6)
  256. #define PB_TEMP_OT_FAULT BIT(7)
  257. /*
  258. * STATUS_FAN
  259. */
  260. #define PB_FAN_AIRFLOW_WARNING BIT(0)
  261. #define PB_FAN_AIRFLOW_FAULT BIT(1)
  262. #define PB_FAN_FAN2_SPEED_OVERRIDE BIT(2)
  263. #define PB_FAN_FAN1_SPEED_OVERRIDE BIT(3)
  264. #define PB_FAN_FAN2_WARNING BIT(4)
  265. #define PB_FAN_FAN1_WARNING BIT(5)
  266. #define PB_FAN_FAN2_FAULT BIT(6)
  267. #define PB_FAN_FAN1_FAULT BIT(7)
  268. /*
  269. * CML_FAULT_STATUS
  270. */
  271. #define PB_CML_FAULT_OTHER_MEM_LOGIC BIT(0)
  272. #define PB_CML_FAULT_OTHER_COMM BIT(1)
  273. #define PB_CML_FAULT_PROCESSOR BIT(3)
  274. #define PB_CML_FAULT_MEMORY BIT(4)
  275. #define PB_CML_FAULT_PACKET_ERROR BIT(5)
  276. #define PB_CML_FAULT_INVALID_DATA BIT(6)
  277. #define PB_CML_FAULT_INVALID_COMMAND BIT(7)
  278. enum pmbus_sensor_classes {
  279. PSC_VOLTAGE_IN = 0,
  280. PSC_VOLTAGE_OUT,
  281. PSC_CURRENT_IN,
  282. PSC_CURRENT_OUT,
  283. PSC_POWER,
  284. PSC_TEMPERATURE,
  285. PSC_FAN,
  286. PSC_NUM_CLASSES /* Number of power sensor classes */
  287. };
  288. #define PMBUS_PAGES 32 /* Per PMBus specification */
  289. /* Functionality bit mask */
  290. #define PMBUS_HAVE_VIN BIT(0)
  291. #define PMBUS_HAVE_VCAP BIT(1)
  292. #define PMBUS_HAVE_VOUT BIT(2)
  293. #define PMBUS_HAVE_IIN BIT(3)
  294. #define PMBUS_HAVE_IOUT BIT(4)
  295. #define PMBUS_HAVE_PIN BIT(5)
  296. #define PMBUS_HAVE_POUT BIT(6)
  297. #define PMBUS_HAVE_FAN12 BIT(7)
  298. #define PMBUS_HAVE_FAN34 BIT(8)
  299. #define PMBUS_HAVE_TEMP BIT(9)
  300. #define PMBUS_HAVE_TEMP2 BIT(10)
  301. #define PMBUS_HAVE_TEMP3 BIT(11)
  302. #define PMBUS_HAVE_STATUS_VOUT BIT(12)
  303. #define PMBUS_HAVE_STATUS_IOUT BIT(13)
  304. #define PMBUS_HAVE_STATUS_INPUT BIT(14)
  305. #define PMBUS_HAVE_STATUS_TEMP BIT(15)
  306. #define PMBUS_HAVE_STATUS_FAN12 BIT(16)
  307. #define PMBUS_HAVE_STATUS_FAN34 BIT(17)
  308. #define PMBUS_HAVE_VMON BIT(18)
  309. #define PMBUS_HAVE_STATUS_VMON BIT(19)
  310. enum pmbus_data_format { linear = 0, direct, vid };
  311. enum vrm_version { vr11 = 0, vr12 };
  312. struct pmbus_driver_info {
  313. int pages; /* Total number of pages */
  314. enum pmbus_data_format format[PSC_NUM_CLASSES];
  315. enum vrm_version vrm_version;
  316. /*
  317. * Support one set of coefficients for each sensor type
  318. * Used for chips providing data in direct mode.
  319. */
  320. int m[PSC_NUM_CLASSES]; /* mantissa for direct data format */
  321. int b[PSC_NUM_CLASSES]; /* offset */
  322. int R[PSC_NUM_CLASSES]; /* exponent */
  323. u32 func[PMBUS_PAGES]; /* Functionality, per page */
  324. /*
  325. * The following functions map manufacturing specific register values
  326. * to PMBus standard register values. Specify only if mapping is
  327. * necessary.
  328. * Functions return the register value (read) or zero (write) if
  329. * successful. A return value of -ENODATA indicates that there is no
  330. * manufacturer specific register, but that a standard PMBus register
  331. * may exist. Any other negative return value indicates that the
  332. * register does not exist, and that no attempt should be made to read
  333. * the standard register.
  334. */
  335. int (*read_byte_data)(struct i2c_client *client, int page, int reg);
  336. int (*read_word_data)(struct i2c_client *client, int page, int reg);
  337. int (*write_word_data)(struct i2c_client *client, int page, int reg,
  338. u16 word);
  339. int (*write_byte)(struct i2c_client *client, int page, u8 value);
  340. /*
  341. * The identify function determines supported PMBus functionality.
  342. * This function is only necessary if a chip driver supports multiple
  343. * chips, and the chip functionality is not pre-determined.
  344. */
  345. int (*identify)(struct i2c_client *client,
  346. struct pmbus_driver_info *info);
  347. /* Regulator functionality, if supported by this chip driver. */
  348. int num_regulators;
  349. const struct regulator_desc *reg_desc;
  350. };
  351. /* Regulator ops */
  352. extern const struct regulator_ops pmbus_regulator_ops;
  353. /* Macro for filling in array of struct regulator_desc */
  354. #define PMBUS_REGULATOR(_name, _id) \
  355. [_id] = { \
  356. .name = (_name # _id), \
  357. .id = (_id), \
  358. .of_match = of_match_ptr(_name # _id), \
  359. .regulators_node = of_match_ptr("regulators"), \
  360. .ops = &pmbus_regulator_ops, \
  361. .type = REGULATOR_VOLTAGE, \
  362. .owner = THIS_MODULE, \
  363. }
  364. /* Function declarations */
  365. void pmbus_clear_cache(struct i2c_client *client);
  366. int pmbus_set_page(struct i2c_client *client, u8 page);
  367. int pmbus_read_word_data(struct i2c_client *client, u8 page, u8 reg);
  368. int pmbus_write_word_data(struct i2c_client *client, u8 page, u8 reg, u16 word);
  369. int pmbus_read_byte_data(struct i2c_client *client, int page, u8 reg);
  370. int pmbus_write_byte(struct i2c_client *client, int page, u8 value);
  371. int pmbus_write_byte_data(struct i2c_client *client, int page, u8 reg,
  372. u8 value);
  373. int pmbus_update_byte_data(struct i2c_client *client, int page, u8 reg,
  374. u8 mask, u8 value);
  375. void pmbus_clear_faults(struct i2c_client *client);
  376. bool pmbus_check_byte_register(struct i2c_client *client, int page, int reg);
  377. bool pmbus_check_word_register(struct i2c_client *client, int page, int reg);
  378. int pmbus_do_probe(struct i2c_client *client, const struct i2c_device_id *id,
  379. struct pmbus_driver_info *info);
  380. int pmbus_do_remove(struct i2c_client *client);
  381. const struct pmbus_driver_info *pmbus_get_driver_info(struct i2c_client
  382. *client);
  383. #endif /* PMBUS_H */