Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 #ifndef __SOUND_I2C_H
0003 #define __SOUND_I2C_H
0004 
0005 /*
0006  */
0007 
0008 #define SND_I2C_DEVICE_ADDRTEN  (1<<0)  /* 10-bit I2C address */
0009 
0010 struct snd_i2c_device {
0011     struct list_head list;
0012     struct snd_i2c_bus *bus;    /* I2C bus */
0013     char name[32];      /* some useful device name */
0014     unsigned short flags;   /* device flags */
0015     unsigned short addr;    /* device address (might be 10-bit) */
0016     unsigned long private_value;
0017     void *private_data;
0018     void (*private_free)(struct snd_i2c_device *device);
0019 };
0020 
0021 #define snd_i2c_device(n) list_entry(n, struct snd_i2c_device, list)
0022 
0023 struct snd_i2c_bit_ops {
0024     void (*start)(struct snd_i2c_bus *bus); /* transfer start */
0025     void (*stop)(struct snd_i2c_bus *bus);  /* transfer stop */
0026     void (*direction)(struct snd_i2c_bus *bus, int clock, int data);  /* set line direction (0 = write, 1 = read) */
0027     void (*setlines)(struct snd_i2c_bus *bus, int clock, int data);
0028     int (*getclock)(struct snd_i2c_bus *bus);
0029     int (*getdata)(struct snd_i2c_bus *bus, int ack);
0030 };
0031 
0032 struct snd_i2c_ops {
0033     int (*sendbytes)(struct snd_i2c_device *device, unsigned char *bytes, int count);
0034     int (*readbytes)(struct snd_i2c_device *device, unsigned char *bytes, int count);
0035     int (*probeaddr)(struct snd_i2c_bus *bus, unsigned short addr);
0036 };
0037 
0038 struct snd_i2c_bus {
0039     struct snd_card *card;  /* card which I2C belongs to */
0040     char name[32];      /* some useful label */
0041 
0042     struct mutex lock_mutex;
0043 
0044     struct snd_i2c_bus *master; /* master bus when SCK/SCL is shared */
0045     struct list_head buses; /* master: slave buses sharing SCK/SCL, slave: link list */
0046 
0047     struct list_head devices; /* attached devices to this bus */
0048 
0049     union {
0050         struct snd_i2c_bit_ops *bit;
0051         void *ops;
0052     } hw_ops;       /* lowlevel operations */
0053     const struct snd_i2c_ops *ops;  /* midlevel operations */
0054 
0055     unsigned long private_value;
0056     void *private_data;
0057     void (*private_free)(struct snd_i2c_bus *bus);
0058 };
0059 
0060 #define snd_i2c_slave_bus(n) list_entry(n, struct snd_i2c_bus, buses)
0061 
0062 int snd_i2c_bus_create(struct snd_card *card, const char *name,
0063                struct snd_i2c_bus *master, struct snd_i2c_bus **ri2c);
0064 int snd_i2c_device_create(struct snd_i2c_bus *bus, const char *name,
0065               unsigned char addr, struct snd_i2c_device **rdevice);
0066 int snd_i2c_device_free(struct snd_i2c_device *device);
0067 
0068 static inline void snd_i2c_lock(struct snd_i2c_bus *bus)
0069 {
0070     if (bus->master)
0071         mutex_lock(&bus->master->lock_mutex);
0072     else
0073         mutex_lock(&bus->lock_mutex);
0074 }
0075 
0076 static inline void snd_i2c_unlock(struct snd_i2c_bus *bus)
0077 {
0078     if (bus->master)
0079         mutex_unlock(&bus->master->lock_mutex);
0080     else
0081         mutex_unlock(&bus->lock_mutex);
0082 }
0083 
0084 int snd_i2c_sendbytes(struct snd_i2c_device *device, unsigned char *bytes, int count);
0085 int snd_i2c_readbytes(struct snd_i2c_device *device, unsigned char *bytes, int count);
0086 int snd_i2c_probeaddr(struct snd_i2c_bus *bus, unsigned short addr);
0087 
0088 #endif /* __SOUND_I2C_H */