i2c-core.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * i2c-core.h - interfaces internal to the I2C framework
  4. */
  5. #include <linux/rwsem.h>
  6. struct i2c_devinfo {
  7. struct list_head list;
  8. int busnum;
  9. struct i2c_board_info board_info;
  10. };
  11. /* board_lock protects board_list and first_dynamic_bus_num.
  12. * only i2c core components are allowed to use these symbols.
  13. */
  14. extern struct rw_semaphore __i2c_board_lock;
  15. extern struct list_head __i2c_board_list;
  16. extern int __i2c_first_dynamic_bus_num;
  17. int i2c_check_7bit_addr_validity_strict(unsigned short addr);
  18. int i2c_dev_irq_from_resources(const struct resource *resources,
  19. unsigned int num_resources);
  20. /*
  21. * We only allow atomic transfers for very late communication, e.g. to access a
  22. * PMIC when powering down. Atomic transfers are a corner case and not for
  23. * generic use!
  24. */
  25. static inline bool i2c_in_atomic_xfer_mode(void)
  26. {
  27. return system_state > SYSTEM_RUNNING && !preemptible();
  28. }
  29. static inline int __i2c_lock_bus_helper(struct i2c_adapter *adap)
  30. {
  31. int ret = 0;
  32. if (i2c_in_atomic_xfer_mode()) {
  33. WARN(!adap->algo->master_xfer_atomic && !adap->algo->smbus_xfer_atomic,
  34. "No atomic I2C transfer handler for '%s'\n", dev_name(&adap->dev));
  35. ret = i2c_trylock_bus(adap, I2C_LOCK_SEGMENT) ? 0 : -EAGAIN;
  36. } else {
  37. i2c_lock_bus(adap, I2C_LOCK_SEGMENT);
  38. }
  39. return ret;
  40. }
  41. static inline int __i2c_check_suspended(struct i2c_adapter *adap)
  42. {
  43. if (test_bit(I2C_ALF_IS_SUSPENDED, &adap->locked_flags)) {
  44. if (!test_and_set_bit(I2C_ALF_SUSPEND_REPORTED, &adap->locked_flags))
  45. dev_WARN(&adap->dev, "Transfer while suspended\n");
  46. return -ESHUTDOWN;
  47. }
  48. return 0;
  49. }
  50. #ifdef CONFIG_ACPI
  51. void i2c_acpi_register_devices(struct i2c_adapter *adap);
  52. int i2c_acpi_get_irq(struct i2c_client *client, bool *wake_capable);
  53. #else /* CONFIG_ACPI */
  54. static inline void i2c_acpi_register_devices(struct i2c_adapter *adap) { }
  55. static inline int i2c_acpi_get_irq(struct i2c_client *client, bool *wake_capable)
  56. {
  57. return 0;
  58. }
  59. #endif /* CONFIG_ACPI */
  60. extern struct notifier_block i2c_acpi_notifier;
  61. #ifdef CONFIG_ACPI_I2C_OPREGION
  62. int i2c_acpi_install_space_handler(struct i2c_adapter *adapter);
  63. void i2c_acpi_remove_space_handler(struct i2c_adapter *adapter);
  64. #else /* CONFIG_ACPI_I2C_OPREGION */
  65. static inline int i2c_acpi_install_space_handler(struct i2c_adapter *adapter) { return 0; }
  66. static inline void i2c_acpi_remove_space_handler(struct i2c_adapter *adapter) { }
  67. #endif /* CONFIG_ACPI_I2C_OPREGION */
  68. #ifdef CONFIG_OF
  69. void of_i2c_register_devices(struct i2c_adapter *adap);
  70. #else
  71. static inline void of_i2c_register_devices(struct i2c_adapter *adap) { }
  72. #endif
  73. extern struct notifier_block i2c_of_notifier;
  74. #if IS_ENABLED(CONFIG_I2C_SMBUS)
  75. int i2c_setup_smbus_alert(struct i2c_adapter *adap);
  76. #else
  77. static inline int i2c_setup_smbus_alert(struct i2c_adapter *adap)
  78. {
  79. return 0;
  80. }
  81. #endif