/drivers/i2c/i2c-core.h

http://github.com/mirrors/linux · C Header · 97 lines · 70 code · 15 blank · 12 comment · 6 complexity · 5f67962fd00f183aeae412703d8af78b MD5 · raw file

  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 send
  22. * the powerdown command to a PMIC. Atomic transfers are a corner case and not
  23. * for generic use!
  24. */
  25. static inline bool i2c_in_atomic_xfer_mode(void)
  26. {
  27. return system_state > SYSTEM_RUNNING && irqs_disabled();
  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. const struct acpi_device_id *
  52. i2c_acpi_match_device(const struct acpi_device_id *matches,
  53. struct i2c_client *client);
  54. void i2c_acpi_register_devices(struct i2c_adapter *adap);
  55. int i2c_acpi_get_irq(struct i2c_client *client);
  56. #else /* CONFIG_ACPI */
  57. static inline void i2c_acpi_register_devices(struct i2c_adapter *adap) { }
  58. static inline const struct acpi_device_id *
  59. i2c_acpi_match_device(const struct acpi_device_id *matches,
  60. struct i2c_client *client)
  61. {
  62. return NULL;
  63. }
  64. static inline int i2c_acpi_get_irq(struct i2c_client *client)
  65. {
  66. return 0;
  67. }
  68. #endif /* CONFIG_ACPI */
  69. extern struct notifier_block i2c_acpi_notifier;
  70. #ifdef CONFIG_ACPI_I2C_OPREGION
  71. int i2c_acpi_install_space_handler(struct i2c_adapter *adapter);
  72. void i2c_acpi_remove_space_handler(struct i2c_adapter *adapter);
  73. #else /* CONFIG_ACPI_I2C_OPREGION */
  74. static inline int i2c_acpi_install_space_handler(struct i2c_adapter *adapter) { return 0; }
  75. static inline void i2c_acpi_remove_space_handler(struct i2c_adapter *adapter) { }
  76. #endif /* CONFIG_ACPI_I2C_OPREGION */
  77. #ifdef CONFIG_OF
  78. void of_i2c_register_devices(struct i2c_adapter *adap);
  79. #else
  80. static inline void of_i2c_register_devices(struct i2c_adapter *adap) { }
  81. #endif
  82. extern struct notifier_block i2c_of_notifier;