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