i2c-mux.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. *
  4. * i2c-mux.h - functions for the i2c-bus mux support
  5. *
  6. * Copyright (c) 2008-2009 Rodolfo Giometti <[email protected]>
  7. * Copyright (c) 2008-2009 Eurotech S.p.A. <[email protected]>
  8. * Michael Lawnick <[email protected]>
  9. */
  10. #ifndef _LINUX_I2C_MUX_H
  11. #define _LINUX_I2C_MUX_H
  12. #ifdef __KERNEL__
  13. #include <linux/bitops.h>
  14. struct i2c_mux_core {
  15. struct i2c_adapter *parent;
  16. struct device *dev;
  17. unsigned int mux_locked:1;
  18. unsigned int arbitrator:1;
  19. unsigned int gate:1;
  20. void *priv;
  21. int (*select)(struct i2c_mux_core *, u32 chan_id);
  22. int (*deselect)(struct i2c_mux_core *, u32 chan_id);
  23. int num_adapters;
  24. int max_adapters;
  25. struct i2c_adapter *adapter[];
  26. };
  27. struct i2c_mux_core *i2c_mux_alloc(struct i2c_adapter *parent,
  28. struct device *dev, int max_adapters,
  29. int sizeof_priv, u32 flags,
  30. int (*select)(struct i2c_mux_core *, u32),
  31. int (*deselect)(struct i2c_mux_core *, u32));
  32. /* flags for i2c_mux_alloc */
  33. #define I2C_MUX_LOCKED BIT(0)
  34. #define I2C_MUX_ARBITRATOR BIT(1)
  35. #define I2C_MUX_GATE BIT(2)
  36. static inline void *i2c_mux_priv(struct i2c_mux_core *muxc)
  37. {
  38. return muxc->priv;
  39. }
  40. struct i2c_adapter *i2c_root_adapter(struct device *dev);
  41. /*
  42. * Called to create an i2c bus on a multiplexed bus segment.
  43. * The chan_id parameter is passed to the select and deselect
  44. * callback functions to perform hardware-specific mux control.
  45. */
  46. int i2c_mux_add_adapter(struct i2c_mux_core *muxc,
  47. u32 force_nr, u32 chan_id,
  48. unsigned int class);
  49. void i2c_mux_del_adapters(struct i2c_mux_core *muxc);
  50. #endif /* __KERNEL__ */
  51. #endif /* _LINUX_I2C_MUX_H */