i2c.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #ifndef __SOUND_I2C_H
  2. #define __SOUND_I2C_H
  3. /*
  4. *
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. *
  21. */
  22. #define SND_I2C_DEVICE_ADDRTEN (1<<0) /* 10-bit I2C address */
  23. struct snd_i2c_device {
  24. struct list_head list;
  25. struct snd_i2c_bus *bus; /* I2C bus */
  26. char name[32]; /* some useful device name */
  27. unsigned short flags; /* device flags */
  28. unsigned short addr; /* device address (might be 10-bit) */
  29. unsigned long private_value;
  30. void *private_data;
  31. void (*private_free)(struct snd_i2c_device *device);
  32. };
  33. #define snd_i2c_device(n) list_entry(n, struct snd_i2c_device, list)
  34. struct snd_i2c_bit_ops {
  35. void (*start)(struct snd_i2c_bus *bus); /* transfer start */
  36. void (*stop)(struct snd_i2c_bus *bus); /* transfer stop */
  37. void (*direction)(struct snd_i2c_bus *bus, int clock, int data); /* set line direction (0 = write, 1 = read) */
  38. void (*setlines)(struct snd_i2c_bus *bus, int clock, int data);
  39. int (*getclock)(struct snd_i2c_bus *bus);
  40. int (*getdata)(struct snd_i2c_bus *bus, int ack);
  41. };
  42. struct snd_i2c_ops {
  43. int (*sendbytes)(struct snd_i2c_device *device, unsigned char *bytes, int count);
  44. int (*readbytes)(struct snd_i2c_device *device, unsigned char *bytes, int count);
  45. int (*probeaddr)(struct snd_i2c_bus *bus, unsigned short addr);
  46. };
  47. struct snd_i2c_bus {
  48. struct snd_card *card; /* card which I2C belongs to */
  49. char name[32]; /* some useful label */
  50. struct mutex lock_mutex;
  51. struct snd_i2c_bus *master; /* master bus when SCK/SCL is shared */
  52. struct list_head buses; /* master: slave buses sharing SCK/SCL, slave: link list */
  53. struct list_head devices; /* attached devices to this bus */
  54. union {
  55. struct snd_i2c_bit_ops *bit;
  56. void *ops;
  57. } hw_ops; /* lowlevel operations */
  58. struct snd_i2c_ops *ops; /* midlevel operations */
  59. unsigned long private_value;
  60. void *private_data;
  61. void (*private_free)(struct snd_i2c_bus *bus);
  62. };
  63. #define snd_i2c_slave_bus(n) list_entry(n, struct snd_i2c_bus, buses)
  64. int snd_i2c_bus_create(struct snd_card *card, const char *name,
  65. struct snd_i2c_bus *master, struct snd_i2c_bus **ri2c);
  66. int snd_i2c_device_create(struct snd_i2c_bus *bus, const char *name,
  67. unsigned char addr, struct snd_i2c_device **rdevice);
  68. int snd_i2c_device_free(struct snd_i2c_device *device);
  69. static inline void snd_i2c_lock(struct snd_i2c_bus *bus)
  70. {
  71. if (bus->master)
  72. mutex_lock(&bus->master->lock_mutex);
  73. else
  74. mutex_lock(&bus->lock_mutex);
  75. }
  76. static inline void snd_i2c_unlock(struct snd_i2c_bus *bus)
  77. {
  78. if (bus->master)
  79. mutex_unlock(&bus->master->lock_mutex);
  80. else
  81. mutex_unlock(&bus->lock_mutex);
  82. }
  83. int snd_i2c_sendbytes(struct snd_i2c_device *device, unsigned char *bytes, int count);
  84. int snd_i2c_readbytes(struct snd_i2c_device *device, unsigned char *bytes, int count);
  85. int snd_i2c_probeaddr(struct snd_i2c_bus *bus, unsigned short addr);
  86. #endif /* __SOUND_I2C_H */