18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Intel OnChip System Fabric MailBox access support 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#ifndef IOSF_MBI_SYMS_H 78c2ecf20Sopenharmony_ci#define IOSF_MBI_SYMS_H 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include <linux/notifier.h> 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#define MBI_MCR_OFFSET 0xD0 128c2ecf20Sopenharmony_ci#define MBI_MDR_OFFSET 0xD4 138c2ecf20Sopenharmony_ci#define MBI_MCRX_OFFSET 0xD8 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#define MBI_RD_MASK 0xFEFFFFFF 168c2ecf20Sopenharmony_ci#define MBI_WR_MASK 0X01000000 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci#define MBI_MASK_HI 0xFFFFFF00 198c2ecf20Sopenharmony_ci#define MBI_MASK_LO 0x000000FF 208c2ecf20Sopenharmony_ci#define MBI_ENABLE 0xF0 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci/* IOSF SB read/write opcodes */ 238c2ecf20Sopenharmony_ci#define MBI_MMIO_READ 0x00 248c2ecf20Sopenharmony_ci#define MBI_MMIO_WRITE 0x01 258c2ecf20Sopenharmony_ci#define MBI_CFG_READ 0x04 268c2ecf20Sopenharmony_ci#define MBI_CFG_WRITE 0x05 278c2ecf20Sopenharmony_ci#define MBI_CR_READ 0x06 288c2ecf20Sopenharmony_ci#define MBI_CR_WRITE 0x07 298c2ecf20Sopenharmony_ci#define MBI_REG_READ 0x10 308c2ecf20Sopenharmony_ci#define MBI_REG_WRITE 0x11 318c2ecf20Sopenharmony_ci#define MBI_ESRAM_READ 0x12 328c2ecf20Sopenharmony_ci#define MBI_ESRAM_WRITE 0x13 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci/* Baytrail available units */ 358c2ecf20Sopenharmony_ci#define BT_MBI_UNIT_AUNIT 0x00 368c2ecf20Sopenharmony_ci#define BT_MBI_UNIT_SMC 0x01 378c2ecf20Sopenharmony_ci#define BT_MBI_UNIT_CPU 0x02 388c2ecf20Sopenharmony_ci#define BT_MBI_UNIT_BUNIT 0x03 398c2ecf20Sopenharmony_ci#define BT_MBI_UNIT_PMC 0x04 408c2ecf20Sopenharmony_ci#define BT_MBI_UNIT_GFX 0x06 418c2ecf20Sopenharmony_ci#define BT_MBI_UNIT_SMI 0x0C 428c2ecf20Sopenharmony_ci#define BT_MBI_UNIT_CCK 0x14 438c2ecf20Sopenharmony_ci#define BT_MBI_UNIT_USB 0x43 448c2ecf20Sopenharmony_ci#define BT_MBI_UNIT_SATA 0xA3 458c2ecf20Sopenharmony_ci#define BT_MBI_UNIT_PCIE 0xA6 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci/* Quark available units */ 488c2ecf20Sopenharmony_ci#define QRK_MBI_UNIT_HBA 0x00 498c2ecf20Sopenharmony_ci#define QRK_MBI_UNIT_HB 0x03 508c2ecf20Sopenharmony_ci#define QRK_MBI_UNIT_RMU 0x04 518c2ecf20Sopenharmony_ci#define QRK_MBI_UNIT_MM 0x05 528c2ecf20Sopenharmony_ci#define QRK_MBI_UNIT_SOC 0x31 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci/* Action values for the pmic_bus_access_notifier functions */ 558c2ecf20Sopenharmony_ci#define MBI_PMIC_BUS_ACCESS_BEGIN 1 568c2ecf20Sopenharmony_ci#define MBI_PMIC_BUS_ACCESS_END 2 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_IOSF_MBI) 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_cibool iosf_mbi_available(void); 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci/** 638c2ecf20Sopenharmony_ci * iosf_mbi_read() - MailBox Interface read command 648c2ecf20Sopenharmony_ci * @port: port indicating subunit being accessed 658c2ecf20Sopenharmony_ci * @opcode: port specific read or write opcode 668c2ecf20Sopenharmony_ci * @offset: register address offset 678c2ecf20Sopenharmony_ci * @mdr: register data to be read 688c2ecf20Sopenharmony_ci * 698c2ecf20Sopenharmony_ci * Locking is handled by spinlock - cannot sleep. 708c2ecf20Sopenharmony_ci * Return: Nonzero on error 718c2ecf20Sopenharmony_ci */ 728c2ecf20Sopenharmony_ciint iosf_mbi_read(u8 port, u8 opcode, u32 offset, u32 *mdr); 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci/** 758c2ecf20Sopenharmony_ci * iosf_mbi_write() - MailBox unmasked write command 768c2ecf20Sopenharmony_ci * @port: port indicating subunit being accessed 778c2ecf20Sopenharmony_ci * @opcode: port specific read or write opcode 788c2ecf20Sopenharmony_ci * @offset: register address offset 798c2ecf20Sopenharmony_ci * @mdr: register data to be written 808c2ecf20Sopenharmony_ci * 818c2ecf20Sopenharmony_ci * Locking is handled by spinlock - cannot sleep. 828c2ecf20Sopenharmony_ci * Return: Nonzero on error 838c2ecf20Sopenharmony_ci */ 848c2ecf20Sopenharmony_ciint iosf_mbi_write(u8 port, u8 opcode, u32 offset, u32 mdr); 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci/** 878c2ecf20Sopenharmony_ci * iosf_mbi_modify() - MailBox masked write command 888c2ecf20Sopenharmony_ci * @port: port indicating subunit being accessed 898c2ecf20Sopenharmony_ci * @opcode: port specific read or write opcode 908c2ecf20Sopenharmony_ci * @offset: register address offset 918c2ecf20Sopenharmony_ci * @mdr: register data being modified 928c2ecf20Sopenharmony_ci * @mask: mask indicating bits in mdr to be modified 938c2ecf20Sopenharmony_ci * 948c2ecf20Sopenharmony_ci * Locking is handled by spinlock - cannot sleep. 958c2ecf20Sopenharmony_ci * Return: Nonzero on error 968c2ecf20Sopenharmony_ci */ 978c2ecf20Sopenharmony_ciint iosf_mbi_modify(u8 port, u8 opcode, u32 offset, u32 mdr, u32 mask); 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci/** 1008c2ecf20Sopenharmony_ci * iosf_mbi_punit_acquire() - Acquire access to the P-Unit 1018c2ecf20Sopenharmony_ci * 1028c2ecf20Sopenharmony_ci * One some systems the P-Unit accesses the PMIC to change various voltages 1038c2ecf20Sopenharmony_ci * through the same bus as other kernel drivers use for e.g. battery monitoring. 1048c2ecf20Sopenharmony_ci * 1058c2ecf20Sopenharmony_ci * If a driver sends requests to the P-Unit which require the P-Unit to access 1068c2ecf20Sopenharmony_ci * the PMIC bus while another driver is also accessing the PMIC bus various bad 1078c2ecf20Sopenharmony_ci * things happen. 1088c2ecf20Sopenharmony_ci * 1098c2ecf20Sopenharmony_ci * Call this function before sending requests to the P-Unit which may make it 1108c2ecf20Sopenharmony_ci * access the PMIC, be it through iosf_mbi* functions or through other means. 1118c2ecf20Sopenharmony_ci * This function will block all kernel access to the PMIC I2C bus, so that the 1128c2ecf20Sopenharmony_ci * P-Unit can safely access the PMIC over the shared I2C bus. 1138c2ecf20Sopenharmony_ci * 1148c2ecf20Sopenharmony_ci * Note on these systems the i2c-bus driver will request a sempahore from the 1158c2ecf20Sopenharmony_ci * P-Unit for exclusive access to the PMIC bus when i2c drivers are accessing 1168c2ecf20Sopenharmony_ci * it, but this does not appear to be sufficient, we still need to avoid making 1178c2ecf20Sopenharmony_ci * certain P-Unit requests during the access window to avoid problems. 1188c2ecf20Sopenharmony_ci * 1198c2ecf20Sopenharmony_ci * This function locks a mutex, as such it may sleep. 1208c2ecf20Sopenharmony_ci */ 1218c2ecf20Sopenharmony_civoid iosf_mbi_punit_acquire(void); 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci/** 1248c2ecf20Sopenharmony_ci * iosf_mbi_punit_release() - Release access to the P-Unit 1258c2ecf20Sopenharmony_ci */ 1268c2ecf20Sopenharmony_civoid iosf_mbi_punit_release(void); 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci/** 1298c2ecf20Sopenharmony_ci * iosf_mbi_block_punit_i2c_access() - Block P-Unit accesses to the PMIC bus 1308c2ecf20Sopenharmony_ci * 1318c2ecf20Sopenharmony_ci * Call this function to block P-Unit access to the PMIC I2C bus, so that the 1328c2ecf20Sopenharmony_ci * kernel can safely access the PMIC over the shared I2C bus. 1338c2ecf20Sopenharmony_ci * 1348c2ecf20Sopenharmony_ci * This function acquires the P-Unit bus semaphore and notifies 1358c2ecf20Sopenharmony_ci * pmic_bus_access_notifier listeners that they may no longer access the 1368c2ecf20Sopenharmony_ci * P-Unit in a way which may cause it to access the shared I2C bus. 1378c2ecf20Sopenharmony_ci * 1388c2ecf20Sopenharmony_ci * Note this function may be called multiple times and the bus will not 1398c2ecf20Sopenharmony_ci * be released until iosf_mbi_unblock_punit_i2c_access() has been called the 1408c2ecf20Sopenharmony_ci * same amount of times. 1418c2ecf20Sopenharmony_ci * 1428c2ecf20Sopenharmony_ci * Return: Nonzero on error 1438c2ecf20Sopenharmony_ci */ 1448c2ecf20Sopenharmony_ciint iosf_mbi_block_punit_i2c_access(void); 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_ci/* 1478c2ecf20Sopenharmony_ci * iosf_mbi_unblock_punit_i2c_access() - Release PMIC I2C bus block 1488c2ecf20Sopenharmony_ci * 1498c2ecf20Sopenharmony_ci * Release i2c access block gotten through iosf_mbi_block_punit_i2c_access(). 1508c2ecf20Sopenharmony_ci */ 1518c2ecf20Sopenharmony_civoid iosf_mbi_unblock_punit_i2c_access(void); 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_ci/** 1548c2ecf20Sopenharmony_ci * iosf_mbi_register_pmic_bus_access_notifier - Register PMIC bus notifier 1558c2ecf20Sopenharmony_ci * 1568c2ecf20Sopenharmony_ci * This function can be used by drivers which may need to acquire P-Unit 1578c2ecf20Sopenharmony_ci * managed resources from interrupt context, where iosf_mbi_punit_acquire() 1588c2ecf20Sopenharmony_ci * can not be used. 1598c2ecf20Sopenharmony_ci * 1608c2ecf20Sopenharmony_ci * This function allows a driver to register a notifier to get notified (in a 1618c2ecf20Sopenharmony_ci * process context) before other drivers start accessing the PMIC bus. 1628c2ecf20Sopenharmony_ci * 1638c2ecf20Sopenharmony_ci * This allows the driver to acquire any resources, which it may need during 1648c2ecf20Sopenharmony_ci * the window the other driver is accessing the PMIC, before hand. 1658c2ecf20Sopenharmony_ci * 1668c2ecf20Sopenharmony_ci * @nb: notifier_block to register 1678c2ecf20Sopenharmony_ci */ 1688c2ecf20Sopenharmony_ciint iosf_mbi_register_pmic_bus_access_notifier(struct notifier_block *nb); 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_ci/** 1718c2ecf20Sopenharmony_ci * iosf_mbi_register_pmic_bus_access_notifier - Unregister PMIC bus notifier 1728c2ecf20Sopenharmony_ci * 1738c2ecf20Sopenharmony_ci * @nb: notifier_block to unregister 1748c2ecf20Sopenharmony_ci */ 1758c2ecf20Sopenharmony_ciint iosf_mbi_unregister_pmic_bus_access_notifier(struct notifier_block *nb); 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_ci/** 1788c2ecf20Sopenharmony_ci * iosf_mbi_unregister_pmic_bus_access_notifier_unlocked - Unregister PMIC bus 1798c2ecf20Sopenharmony_ci * notifier, unlocked 1808c2ecf20Sopenharmony_ci * 1818c2ecf20Sopenharmony_ci * Like iosf_mbi_unregister_pmic_bus_access_notifier(), but for use when the 1828c2ecf20Sopenharmony_ci * caller has already called iosf_mbi_punit_acquire() itself. 1838c2ecf20Sopenharmony_ci * 1848c2ecf20Sopenharmony_ci * @nb: notifier_block to unregister 1858c2ecf20Sopenharmony_ci */ 1868c2ecf20Sopenharmony_ciint iosf_mbi_unregister_pmic_bus_access_notifier_unlocked( 1878c2ecf20Sopenharmony_ci struct notifier_block *nb); 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_ci/** 1908c2ecf20Sopenharmony_ci * iosf_mbi_assert_punit_acquired - Assert that the P-Unit has been acquired. 1918c2ecf20Sopenharmony_ci */ 1928c2ecf20Sopenharmony_civoid iosf_mbi_assert_punit_acquired(void); 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_ci#else /* CONFIG_IOSF_MBI is not enabled */ 1958c2ecf20Sopenharmony_cistatic inline 1968c2ecf20Sopenharmony_cibool iosf_mbi_available(void) 1978c2ecf20Sopenharmony_ci{ 1988c2ecf20Sopenharmony_ci return false; 1998c2ecf20Sopenharmony_ci} 2008c2ecf20Sopenharmony_ci 2018c2ecf20Sopenharmony_cistatic inline 2028c2ecf20Sopenharmony_ciint iosf_mbi_read(u8 port, u8 opcode, u32 offset, u32 *mdr) 2038c2ecf20Sopenharmony_ci{ 2048c2ecf20Sopenharmony_ci WARN(1, "IOSF_MBI driver not available"); 2058c2ecf20Sopenharmony_ci return -EPERM; 2068c2ecf20Sopenharmony_ci} 2078c2ecf20Sopenharmony_ci 2088c2ecf20Sopenharmony_cistatic inline 2098c2ecf20Sopenharmony_ciint iosf_mbi_write(u8 port, u8 opcode, u32 offset, u32 mdr) 2108c2ecf20Sopenharmony_ci{ 2118c2ecf20Sopenharmony_ci WARN(1, "IOSF_MBI driver not available"); 2128c2ecf20Sopenharmony_ci return -EPERM; 2138c2ecf20Sopenharmony_ci} 2148c2ecf20Sopenharmony_ci 2158c2ecf20Sopenharmony_cistatic inline 2168c2ecf20Sopenharmony_ciint iosf_mbi_modify(u8 port, u8 opcode, u32 offset, u32 mdr, u32 mask) 2178c2ecf20Sopenharmony_ci{ 2188c2ecf20Sopenharmony_ci WARN(1, "IOSF_MBI driver not available"); 2198c2ecf20Sopenharmony_ci return -EPERM; 2208c2ecf20Sopenharmony_ci} 2218c2ecf20Sopenharmony_ci 2228c2ecf20Sopenharmony_cistatic inline void iosf_mbi_punit_acquire(void) {} 2238c2ecf20Sopenharmony_cistatic inline void iosf_mbi_punit_release(void) {} 2248c2ecf20Sopenharmony_ci 2258c2ecf20Sopenharmony_cistatic inline 2268c2ecf20Sopenharmony_ciint iosf_mbi_register_pmic_bus_access_notifier(struct notifier_block *nb) 2278c2ecf20Sopenharmony_ci{ 2288c2ecf20Sopenharmony_ci return 0; 2298c2ecf20Sopenharmony_ci} 2308c2ecf20Sopenharmony_ci 2318c2ecf20Sopenharmony_cistatic inline 2328c2ecf20Sopenharmony_ciint iosf_mbi_unregister_pmic_bus_access_notifier(struct notifier_block *nb) 2338c2ecf20Sopenharmony_ci{ 2348c2ecf20Sopenharmony_ci return 0; 2358c2ecf20Sopenharmony_ci} 2368c2ecf20Sopenharmony_ci 2378c2ecf20Sopenharmony_cistatic inline int 2388c2ecf20Sopenharmony_ciiosf_mbi_unregister_pmic_bus_access_notifier_unlocked(struct notifier_block *nb) 2398c2ecf20Sopenharmony_ci{ 2408c2ecf20Sopenharmony_ci return 0; 2418c2ecf20Sopenharmony_ci} 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_cistatic inline 2448c2ecf20Sopenharmony_ciint iosf_mbi_call_pmic_bus_access_notifier_chain(unsigned long val, void *v) 2458c2ecf20Sopenharmony_ci{ 2468c2ecf20Sopenharmony_ci return 0; 2478c2ecf20Sopenharmony_ci} 2488c2ecf20Sopenharmony_ci 2498c2ecf20Sopenharmony_cistatic inline void iosf_mbi_assert_punit_acquired(void) {} 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_ci#endif /* CONFIG_IOSF_MBI */ 2528c2ecf20Sopenharmony_ci 2538c2ecf20Sopenharmony_ci#endif /* IOSF_MBI_SYMS_H */ 254