i2c.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. typedef struct _snd_i2c_device snd_i2c_device_t;
  23. typedef struct _snd_i2c_bus snd_i2c_bus_t;
  24. #define SND_I2C_DEVICE_ADDRTEN (1<<0) /* 10-bit I2C address */
  25. struct _snd_i2c_device {
  26. struct list_head list;
  27. snd_i2c_bus_t *bus; /* I2C bus */
  28. char name[32]; /* some useful device name */
  29. unsigned short flags; /* device flags */
  30. unsigned short addr; /* device address (might be 10-bit) */
  31. unsigned long private_value;
  32. void *private_data;
  33. void (*private_free)(snd_i2c_device_t *device);
  34. };
  35. #define snd_i2c_device(n) list_entry(n, snd_i2c_device_t, list)
  36. typedef struct _snd_i2c_bit_ops {
  37. void (*start)(snd_i2c_bus_t *bus); /* transfer start */
  38. void (*stop)(snd_i2c_bus_t *bus); /* transfer stop */
  39. void (*direction)(snd_i2c_bus_t *bus, int clock, int data); /* set line direction (0 = write, 1 = read) */
  40. void (*setlines)(snd_i2c_bus_t *bus, int clock, int data);
  41. int (*getclock)(snd_i2c_bus_t *bus);
  42. int (*getdata)(snd_i2c_bus_t *bus, int ack);
  43. } snd_i2c_bit_ops_t;
  44. typedef struct _snd_i2c_ops {
  45. int (*sendbytes)(snd_i2c_device_t *device, unsigned char *bytes, int count);
  46. int (*readbytes)(snd_i2c_device_t *device, unsigned char *bytes, int count);
  47. int (*probeaddr)(snd_i2c_bus_t *bus, unsigned short addr);
  48. } snd_i2c_ops_t;
  49. struct _snd_i2c_bus {
  50. snd_card_t *card; /* card which I2C belongs to */
  51. char name[32]; /* some useful label */
  52. struct semaphore lock_mutex;
  53. snd_i2c_bus_t *master; /* master bus when SCK/SCL is shared */
  54. struct list_head buses; /* master: slave buses sharing SCK/SCL, slave: link list */
  55. struct list_head devices; /* attached devices to this bus */
  56. union {
  57. snd_i2c_bit_ops_t *bit;
  58. void *ops;
  59. } hw_ops; /* lowlevel operations */
  60. snd_i2c_ops_t *ops; /* midlevel operations */
  61. unsigned long private_value;
  62. void *private_data;
  63. void (*private_free)(snd_i2c_bus_t *bus);
  64. };
  65. #define snd_i2c_slave_bus(n) list_entry(n, snd_i2c_bus_t, buses)
  66. int snd_i2c_bus_create(snd_card_t *card, const char *name, snd_i2c_bus_t *master, snd_i2c_bus_t **ri2c);
  67. int snd_i2c_device_create(snd_i2c_bus_t *bus, const char *name, unsigned char addr, snd_i2c_device_t **rdevice);
  68. int snd_i2c_device_free(snd_i2c_device_t *device);
  69. static inline void snd_i2c_lock(snd_i2c_bus_t *bus) {
  70. if (bus->master)
  71. down(&bus->master->lock_mutex);
  72. else
  73. down(&bus->lock_mutex);
  74. }
  75. static inline void snd_i2c_unlock(snd_i2c_bus_t *bus) {
  76. if (bus->master)
  77. up(&bus->master->lock_mutex);
  78. else
  79. up(&bus->lock_mutex);
  80. }
  81. int snd_i2c_sendbytes(snd_i2c_device_t *device, unsigned char *bytes, int count);
  82. int snd_i2c_readbytes(snd_i2c_device_t *device, unsigned char *bytes, int count);
  83. int snd_i2c_probeaddr(snd_i2c_bus_t *bus, unsigned short addr);
  84. #endif /* __SOUND_I2C_H */