Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * i2c-core.h - interfaces internal to the I2C framework
0004  */
0005 
0006 #include <linux/rwsem.h>
0007 
0008 struct i2c_devinfo {
0009     struct list_head    list;
0010     int         busnum;
0011     struct i2c_board_info   board_info;
0012 };
0013 
0014 /* board_lock protects board_list and first_dynamic_bus_num.
0015  * only i2c core components are allowed to use these symbols.
0016  */
0017 extern struct rw_semaphore  __i2c_board_lock;
0018 extern struct list_head __i2c_board_list;
0019 extern int      __i2c_first_dynamic_bus_num;
0020 
0021 int i2c_check_7bit_addr_validity_strict(unsigned short addr);
0022 int i2c_dev_irq_from_resources(const struct resource *resources,
0023                    unsigned int num_resources);
0024 
0025 /*
0026  * We only allow atomic transfers for very late communication, e.g. to access a
0027  * PMIC when powering down. Atomic transfers are a corner case and not for
0028  * generic use!
0029  */
0030 static inline bool i2c_in_atomic_xfer_mode(void)
0031 {
0032     return system_state > SYSTEM_RUNNING && irqs_disabled();
0033 }
0034 
0035 static inline int __i2c_lock_bus_helper(struct i2c_adapter *adap)
0036 {
0037     int ret = 0;
0038 
0039     if (i2c_in_atomic_xfer_mode()) {
0040         WARN(!adap->algo->master_xfer_atomic && !adap->algo->smbus_xfer_atomic,
0041              "No atomic I2C transfer handler for '%s'\n", dev_name(&adap->dev));
0042         ret = i2c_trylock_bus(adap, I2C_LOCK_SEGMENT) ? 0 : -EAGAIN;
0043     } else {
0044         i2c_lock_bus(adap, I2C_LOCK_SEGMENT);
0045     }
0046 
0047     return ret;
0048 }
0049 
0050 static inline int __i2c_check_suspended(struct i2c_adapter *adap)
0051 {
0052     if (test_bit(I2C_ALF_IS_SUSPENDED, &adap->locked_flags)) {
0053         if (!test_and_set_bit(I2C_ALF_SUSPEND_REPORTED, &adap->locked_flags))
0054             dev_WARN(&adap->dev, "Transfer while suspended\n");
0055         return -ESHUTDOWN;
0056     }
0057 
0058     return 0;
0059 }
0060 
0061 #ifdef CONFIG_ACPI
0062 void i2c_acpi_register_devices(struct i2c_adapter *adap);
0063 
0064 int i2c_acpi_get_irq(struct i2c_client *client);
0065 #else /* CONFIG_ACPI */
0066 static inline void i2c_acpi_register_devices(struct i2c_adapter *adap) { }
0067 
0068 static inline int i2c_acpi_get_irq(struct i2c_client *client)
0069 {
0070     return 0;
0071 }
0072 #endif /* CONFIG_ACPI */
0073 extern struct notifier_block i2c_acpi_notifier;
0074 
0075 #ifdef CONFIG_ACPI_I2C_OPREGION
0076 int i2c_acpi_install_space_handler(struct i2c_adapter *adapter);
0077 void i2c_acpi_remove_space_handler(struct i2c_adapter *adapter);
0078 #else /* CONFIG_ACPI_I2C_OPREGION */
0079 static inline int i2c_acpi_install_space_handler(struct i2c_adapter *adapter) { return 0; }
0080 static inline void i2c_acpi_remove_space_handler(struct i2c_adapter *adapter) { }
0081 #endif /* CONFIG_ACPI_I2C_OPREGION */
0082 
0083 #ifdef CONFIG_OF
0084 void of_i2c_register_devices(struct i2c_adapter *adap);
0085 #else
0086 static inline void of_i2c_register_devices(struct i2c_adapter *adap) { }
0087 #endif
0088 extern struct notifier_block i2c_of_notifier;
0089 
0090 #if IS_ENABLED(CONFIG_I2C_SMBUS)
0091 int i2c_setup_smbus_alert(struct i2c_adapter *adap);
0092 #else
0093 static inline int i2c_setup_smbus_alert(struct i2c_adapter *adap)
0094 {
0095     return 0;
0096 }
0097 #endif