iosf_mbi.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Intel OnChip System Fabric MailBox access support
  4. */
  5. #ifndef IOSF_MBI_SYMS_H
  6. #define IOSF_MBI_SYMS_H
  7. #include <linux/notifier.h>
  8. #define MBI_MCR_OFFSET 0xD0
  9. #define MBI_MDR_OFFSET 0xD4
  10. #define MBI_MCRX_OFFSET 0xD8
  11. #define MBI_RD_MASK 0xFEFFFFFF
  12. #define MBI_WR_MASK 0X01000000
  13. #define MBI_MASK_HI 0xFFFFFF00
  14. #define MBI_MASK_LO 0x000000FF
  15. #define MBI_ENABLE 0xF0
  16. /* IOSF SB read/write opcodes */
  17. #define MBI_MMIO_READ 0x00
  18. #define MBI_MMIO_WRITE 0x01
  19. #define MBI_CFG_READ 0x04
  20. #define MBI_CFG_WRITE 0x05
  21. #define MBI_CR_READ 0x06
  22. #define MBI_CR_WRITE 0x07
  23. #define MBI_REG_READ 0x10
  24. #define MBI_REG_WRITE 0x11
  25. #define MBI_ESRAM_READ 0x12
  26. #define MBI_ESRAM_WRITE 0x13
  27. /* Baytrail available units */
  28. #define BT_MBI_UNIT_AUNIT 0x00
  29. #define BT_MBI_UNIT_SMC 0x01
  30. #define BT_MBI_UNIT_CPU 0x02
  31. #define BT_MBI_UNIT_BUNIT 0x03
  32. #define BT_MBI_UNIT_PMC 0x04
  33. #define BT_MBI_UNIT_GFX 0x06
  34. #define BT_MBI_UNIT_SMI 0x0C
  35. #define BT_MBI_UNIT_CCK 0x14
  36. #define BT_MBI_UNIT_USB 0x43
  37. #define BT_MBI_UNIT_SATA 0xA3
  38. #define BT_MBI_UNIT_PCIE 0xA6
  39. /* Quark available units */
  40. #define QRK_MBI_UNIT_HBA 0x00
  41. #define QRK_MBI_UNIT_HB 0x03
  42. #define QRK_MBI_UNIT_RMU 0x04
  43. #define QRK_MBI_UNIT_MM 0x05
  44. #define QRK_MBI_UNIT_SOC 0x31
  45. /* Action values for the pmic_bus_access_notifier functions */
  46. #define MBI_PMIC_BUS_ACCESS_BEGIN 1
  47. #define MBI_PMIC_BUS_ACCESS_END 2
  48. #if IS_ENABLED(CONFIG_IOSF_MBI)
  49. bool iosf_mbi_available(void);
  50. /**
  51. * iosf_mbi_read() - MailBox Interface read command
  52. * @port: port indicating subunit being accessed
  53. * @opcode: port specific read or write opcode
  54. * @offset: register address offset
  55. * @mdr: register data to be read
  56. *
  57. * Locking is handled by spinlock - cannot sleep.
  58. * Return: Nonzero on error
  59. */
  60. int iosf_mbi_read(u8 port, u8 opcode, u32 offset, u32 *mdr);
  61. /**
  62. * iosf_mbi_write() - MailBox unmasked write command
  63. * @port: port indicating subunit being accessed
  64. * @opcode: port specific read or write opcode
  65. * @offset: register address offset
  66. * @mdr: register data to be written
  67. *
  68. * Locking is handled by spinlock - cannot sleep.
  69. * Return: Nonzero on error
  70. */
  71. int iosf_mbi_write(u8 port, u8 opcode, u32 offset, u32 mdr);
  72. /**
  73. * iosf_mbi_modify() - MailBox masked write command
  74. * @port: port indicating subunit being accessed
  75. * @opcode: port specific read or write opcode
  76. * @offset: register address offset
  77. * @mdr: register data being modified
  78. * @mask: mask indicating bits in mdr to be modified
  79. *
  80. * Locking is handled by spinlock - cannot sleep.
  81. * Return: Nonzero on error
  82. */
  83. int iosf_mbi_modify(u8 port, u8 opcode, u32 offset, u32 mdr, u32 mask);
  84. /**
  85. * iosf_mbi_punit_acquire() - Acquire access to the P-Unit
  86. *
  87. * One some systems the P-Unit accesses the PMIC to change various voltages
  88. * through the same bus as other kernel drivers use for e.g. battery monitoring.
  89. *
  90. * If a driver sends requests to the P-Unit which require the P-Unit to access
  91. * the PMIC bus while another driver is also accessing the PMIC bus various bad
  92. * things happen.
  93. *
  94. * Call this function before sending requests to the P-Unit which may make it
  95. * access the PMIC, be it through iosf_mbi* functions or through other means.
  96. * This function will block all kernel access to the PMIC I2C bus, so that the
  97. * P-Unit can safely access the PMIC over the shared I2C bus.
  98. *
  99. * Note on these systems the i2c-bus driver will request a sempahore from the
  100. * P-Unit for exclusive access to the PMIC bus when i2c drivers are accessing
  101. * it, but this does not appear to be sufficient, we still need to avoid making
  102. * certain P-Unit requests during the access window to avoid problems.
  103. *
  104. * This function locks a mutex, as such it may sleep.
  105. */
  106. void iosf_mbi_punit_acquire(void);
  107. /**
  108. * iosf_mbi_punit_release() - Release access to the P-Unit
  109. */
  110. void iosf_mbi_punit_release(void);
  111. /**
  112. * iosf_mbi_block_punit_i2c_access() - Block P-Unit accesses to the PMIC bus
  113. *
  114. * Call this function to block P-Unit access to the PMIC I2C bus, so that the
  115. * kernel can safely access the PMIC over the shared I2C bus.
  116. *
  117. * This function acquires the P-Unit bus semaphore and notifies
  118. * pmic_bus_access_notifier listeners that they may no longer access the
  119. * P-Unit in a way which may cause it to access the shared I2C bus.
  120. *
  121. * Note this function may be called multiple times and the bus will not
  122. * be released until iosf_mbi_unblock_punit_i2c_access() has been called the
  123. * same amount of times.
  124. *
  125. * Return: Nonzero on error
  126. */
  127. int iosf_mbi_block_punit_i2c_access(void);
  128. /*
  129. * iosf_mbi_unblock_punit_i2c_access() - Release PMIC I2C bus block
  130. *
  131. * Release i2c access block gotten through iosf_mbi_block_punit_i2c_access().
  132. */
  133. void iosf_mbi_unblock_punit_i2c_access(void);
  134. /**
  135. * iosf_mbi_register_pmic_bus_access_notifier - Register PMIC bus notifier
  136. *
  137. * This function can be used by drivers which may need to acquire P-Unit
  138. * managed resources from interrupt context, where iosf_mbi_punit_acquire()
  139. * can not be used.
  140. *
  141. * This function allows a driver to register a notifier to get notified (in a
  142. * process context) before other drivers start accessing the PMIC bus.
  143. *
  144. * This allows the driver to acquire any resources, which it may need during
  145. * the window the other driver is accessing the PMIC, before hand.
  146. *
  147. * @nb: notifier_block to register
  148. */
  149. int iosf_mbi_register_pmic_bus_access_notifier(struct notifier_block *nb);
  150. /**
  151. * iosf_mbi_register_pmic_bus_access_notifier - Unregister PMIC bus notifier
  152. *
  153. * @nb: notifier_block to unregister
  154. */
  155. int iosf_mbi_unregister_pmic_bus_access_notifier(struct notifier_block *nb);
  156. /**
  157. * iosf_mbi_unregister_pmic_bus_access_notifier_unlocked - Unregister PMIC bus
  158. * notifier, unlocked
  159. *
  160. * Like iosf_mbi_unregister_pmic_bus_access_notifier(), but for use when the
  161. * caller has already called iosf_mbi_punit_acquire() itself.
  162. *
  163. * @nb: notifier_block to unregister
  164. */
  165. int iosf_mbi_unregister_pmic_bus_access_notifier_unlocked(
  166. struct notifier_block *nb);
  167. /**
  168. * iosf_mbi_assert_punit_acquired - Assert that the P-Unit has been acquired.
  169. */
  170. void iosf_mbi_assert_punit_acquired(void);
  171. #else /* CONFIG_IOSF_MBI is not enabled */
  172. static inline
  173. bool iosf_mbi_available(void)
  174. {
  175. return false;
  176. }
  177. static inline
  178. int iosf_mbi_read(u8 port, u8 opcode, u32 offset, u32 *mdr)
  179. {
  180. WARN(1, "IOSF_MBI driver not available");
  181. return -EPERM;
  182. }
  183. static inline
  184. int iosf_mbi_write(u8 port, u8 opcode, u32 offset, u32 mdr)
  185. {
  186. WARN(1, "IOSF_MBI driver not available");
  187. return -EPERM;
  188. }
  189. static inline
  190. int iosf_mbi_modify(u8 port, u8 opcode, u32 offset, u32 mdr, u32 mask)
  191. {
  192. WARN(1, "IOSF_MBI driver not available");
  193. return -EPERM;
  194. }
  195. static inline void iosf_mbi_punit_acquire(void) {}
  196. static inline void iosf_mbi_punit_release(void) {}
  197. static inline
  198. int iosf_mbi_register_pmic_bus_access_notifier(struct notifier_block *nb)
  199. {
  200. return 0;
  201. }
  202. static inline
  203. int iosf_mbi_unregister_pmic_bus_access_notifier(struct notifier_block *nb)
  204. {
  205. return 0;
  206. }
  207. static inline int
  208. iosf_mbi_unregister_pmic_bus_access_notifier_unlocked(struct notifier_block *nb)
  209. {
  210. return 0;
  211. }
  212. static inline
  213. int iosf_mbi_call_pmic_bus_access_notifier_chain(unsigned long val, void *v)
  214. {
  215. return 0;
  216. }
  217. static inline void iosf_mbi_assert_punit_acquired(void) {}
  218. #endif /* CONFIG_IOSF_MBI */
  219. #endif /* IOSF_MBI_SYMS_H */