iosf_mbi.h 5.7 KB

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