iosf_mbi.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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_USB 0x43
  36. #define BT_MBI_UNIT_SATA 0xA3
  37. #define BT_MBI_UNIT_PCIE 0xA6
  38. /* Quark available units */
  39. #define QRK_MBI_UNIT_HBA 0x00
  40. #define QRK_MBI_UNIT_HB 0x03
  41. #define QRK_MBI_UNIT_RMU 0x04
  42. #define QRK_MBI_UNIT_MM 0x05
  43. #define QRK_MBI_UNIT_SOC 0x31
  44. /* Action values for the pmic_bus_access_notifier functions */
  45. #define MBI_PMIC_BUS_ACCESS_BEGIN 1
  46. #define MBI_PMIC_BUS_ACCESS_END 2
  47. #if IS_ENABLED(CONFIG_IOSF_MBI)
  48. bool iosf_mbi_available(void);
  49. /**
  50. * iosf_mbi_read() - MailBox Interface read command
  51. * @port: port indicating subunit being accessed
  52. * @opcode: port specific read or write opcode
  53. * @offset: register address offset
  54. * @mdr: register data to be read
  55. *
  56. * Locking is handled by spinlock - cannot sleep.
  57. * Return: Nonzero on error
  58. */
  59. int iosf_mbi_read(u8 port, u8 opcode, u32 offset, u32 *mdr);
  60. /**
  61. * iosf_mbi_write() - MailBox unmasked write command
  62. * @port: port indicating subunit being accessed
  63. * @opcode: port specific read or write opcode
  64. * @offset: register address offset
  65. * @mdr: register data to be written
  66. *
  67. * Locking is handled by spinlock - cannot sleep.
  68. * Return: Nonzero on error
  69. */
  70. int iosf_mbi_write(u8 port, u8 opcode, u32 offset, u32 mdr);
  71. /**
  72. * iosf_mbi_modify() - MailBox masked write command
  73. * @port: port indicating subunit being accessed
  74. * @opcode: port specific read or write opcode
  75. * @offset: register address offset
  76. * @mdr: register data being modified
  77. * @mask: mask indicating bits in mdr to be modified
  78. *
  79. * Locking is handled by spinlock - cannot sleep.
  80. * Return: Nonzero on error
  81. */
  82. int iosf_mbi_modify(u8 port, u8 opcode, u32 offset, u32 mdr, u32 mask);
  83. /**
  84. * iosf_mbi_punit_acquire() - Acquire access to the P-Unit
  85. *
  86. * One some systems the P-Unit accesses the PMIC to change various voltages
  87. * through the same bus as other kernel drivers use for e.g. battery monitoring.
  88. *
  89. * If a driver sends requests to the P-Unit which require the P-Unit to access
  90. * the PMIC bus while another driver is also accessing the PMIC bus various bad
  91. * things happen.
  92. *
  93. * To avoid these problems this function must be called before accessing the
  94. * P-Unit or the PMIC, be it through iosf_mbi* functions or through other means.
  95. *
  96. * Note on these systems the i2c-bus driver will request a sempahore from the
  97. * P-Unit for exclusive access to the PMIC bus when i2c drivers are accessing
  98. * it, but this does not appear to be sufficient, we still need to avoid making
  99. * certain P-Unit requests during the access window to avoid problems.
  100. *
  101. * This function locks a mutex, as such it may sleep.
  102. */
  103. void iosf_mbi_punit_acquire(void);
  104. /**
  105. * iosf_mbi_punit_release() - Release access to the P-Unit
  106. */
  107. void iosf_mbi_punit_release(void);
  108. /**
  109. * iosf_mbi_register_pmic_bus_access_notifier - Register PMIC bus notifier
  110. *
  111. * This function can be used by drivers which may need to acquire P-Unit
  112. * managed resources from interrupt context, where iosf_mbi_punit_acquire()
  113. * can not be used.
  114. *
  115. * This function allows a driver to register a notifier to get notified (in a
  116. * process context) before other drivers start accessing the PMIC bus.
  117. *
  118. * This allows the driver to acquire any resources, which it may need during
  119. * the window the other driver is accessing the PMIC, before hand.
  120. *
  121. * @nb: notifier_block to register
  122. */
  123. int iosf_mbi_register_pmic_bus_access_notifier(struct notifier_block *nb);
  124. /**
  125. * iosf_mbi_register_pmic_bus_access_notifier - Unregister PMIC bus notifier
  126. *
  127. * @nb: notifier_block to unregister
  128. */
  129. int iosf_mbi_unregister_pmic_bus_access_notifier(struct notifier_block *nb);
  130. /**
  131. * iosf_mbi_call_pmic_bus_access_notifier_chain - Call PMIC bus notifier chain
  132. *
  133. * @val: action to pass into listener's notifier_call function
  134. * @v: data pointer to pass into listener's notifier_call function
  135. */
  136. int iosf_mbi_call_pmic_bus_access_notifier_chain(unsigned long val, void *v);
  137. #else /* CONFIG_IOSF_MBI is not enabled */
  138. static inline
  139. bool iosf_mbi_available(void)
  140. {
  141. return false;
  142. }
  143. static inline
  144. int iosf_mbi_read(u8 port, u8 opcode, u32 offset, u32 *mdr)
  145. {
  146. WARN(1, "IOSF_MBI driver not available");
  147. return -EPERM;
  148. }
  149. static inline
  150. int iosf_mbi_write(u8 port, u8 opcode, u32 offset, u32 mdr)
  151. {
  152. WARN(1, "IOSF_MBI driver not available");
  153. return -EPERM;
  154. }
  155. static inline
  156. int iosf_mbi_modify(u8 port, u8 opcode, u32 offset, u32 mdr, u32 mask)
  157. {
  158. WARN(1, "IOSF_MBI driver not available");
  159. return -EPERM;
  160. }
  161. static inline void iosf_mbi_punit_acquire(void) {}
  162. static inline void iosf_mbi_punit_release(void) {}
  163. static inline
  164. int iosf_mbi_register_pmic_bus_access_notifier(struct notifier_block *nb)
  165. {
  166. return 0;
  167. }
  168. static inline
  169. int iosf_mbi_unregister_pmic_bus_access_notifier(struct notifier_block *nb)
  170. {
  171. return 0;
  172. }
  173. static inline
  174. int iosf_mbi_call_pmic_bus_access_notifier_chain(unsigned long val, void *v)
  175. {
  176. return 0;
  177. }
  178. #endif /* CONFIG_IOSF_MBI */
  179. #endif /* IOSF_MBI_SYMS_H */