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