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