i2c.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. #ifndef __SOUND_I2C_H
  3. #define __SOUND_I2C_H
  4. /*
  5. */
  6. #define SND_I2C_DEVICE_ADDRTEN (1<<0) /* 10-bit I2C address */
  7. struct snd_i2c_device {
  8. struct list_head list;
  9. struct snd_i2c_bus *bus; /* I2C bus */
  10. char name[32]; /* some useful device name */
  11. unsigned short flags; /* device flags */
  12. unsigned short addr; /* device address (might be 10-bit) */
  13. unsigned long private_value;
  14. void *private_data;
  15. void (*private_free)(struct snd_i2c_device *device);
  16. };
  17. #define snd_i2c_device(n) list_entry(n, struct snd_i2c_device, list)
  18. struct snd_i2c_bit_ops {
  19. void (*start)(struct snd_i2c_bus *bus); /* transfer start */
  20. void (*stop)(struct snd_i2c_bus *bus); /* transfer stop */
  21. void (*direction)(struct snd_i2c_bus *bus, int clock, int data); /* set line direction (0 = write, 1 = read) */
  22. void (*setlines)(struct snd_i2c_bus *bus, int clock, int data);
  23. int (*getclock)(struct snd_i2c_bus *bus);
  24. int (*getdata)(struct snd_i2c_bus *bus, int ack);
  25. };
  26. struct snd_i2c_ops {
  27. int (*sendbytes)(struct snd_i2c_device *device, unsigned char *bytes, int count);
  28. int (*readbytes)(struct snd_i2c_device *device, unsigned char *bytes, int count);
  29. int (*probeaddr)(struct snd_i2c_bus *bus, unsigned short addr);
  30. };
  31. struct snd_i2c_bus {
  32. struct snd_card *card; /* card which I2C belongs to */
  33. char name[32]; /* some useful label */
  34. struct mutex lock_mutex;
  35. struct snd_i2c_bus *master; /* master bus when SCK/SCL is shared */
  36. struct list_head buses; /* master: slave buses sharing SCK/SCL, slave: link list */
  37. struct list_head devices; /* attached devices to this bus */
  38. union {
  39. struct snd_i2c_bit_ops *bit;
  40. void *ops;
  41. } hw_ops; /* lowlevel operations */
  42. const struct snd_i2c_ops *ops; /* midlevel operations */
  43. unsigned long private_value;
  44. void *private_data;
  45. void (*private_free)(struct snd_i2c_bus *bus);
  46. };
  47. #define snd_i2c_slave_bus(n) list_entry(n, struct snd_i2c_bus, buses)
  48. int snd_i2c_bus_create(struct snd_card *card, const char *name,
  49. struct snd_i2c_bus *master, struct snd_i2c_bus **ri2c);
  50. int snd_i2c_device_create(struct snd_i2c_bus *bus, const char *name,
  51. unsigned char addr, struct snd_i2c_device **rdevice);
  52. int snd_i2c_device_free(struct snd_i2c_device *device);
  53. static inline void snd_i2c_lock(struct snd_i2c_bus *bus)
  54. {
  55. if (bus->master)
  56. mutex_lock(&bus->master->lock_mutex);
  57. else
  58. mutex_lock(&bus->lock_mutex);
  59. }
  60. static inline void snd_i2c_unlock(struct snd_i2c_bus *bus)
  61. {
  62. if (bus->master)
  63. mutex_unlock(&bus->master->lock_mutex);
  64. else
  65. mutex_unlock(&bus->lock_mutex);
  66. }
  67. int snd_i2c_sendbytes(struct snd_i2c_device *device, unsigned char *bytes, int count);
  68. int snd_i2c_readbytes(struct snd_i2c_device *device, unsigned char *bytes, int count);
  69. int snd_i2c_probeaddr(struct snd_i2c_bus *bus, unsigned short addr);
  70. #endif /* __SOUND_I2C_H */