1#ifndef __SOUND_I2C_H
2#define __SOUND_I2C_H
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#define SND_I2C_DEVICE_ADDRTEN (1<<0)
25
26struct snd_i2c_device {
27 struct list_head list;
28 struct snd_i2c_bus *bus;
29 char name[32];
30 unsigned short flags;
31 unsigned short addr;
32 unsigned long private_value;
33 void *private_data;
34 void (*private_free)(struct snd_i2c_device *device);
35};
36
37#define snd_i2c_device(n) list_entry(n, struct snd_i2c_device, list)
38
39struct snd_i2c_bit_ops {
40 void (*start)(struct snd_i2c_bus *bus);
41 void (*stop)(struct snd_i2c_bus *bus);
42 void (*direction)(struct snd_i2c_bus *bus, int clock, int data);
43 void (*setlines)(struct snd_i2c_bus *bus, int clock, int data);
44 int (*getclock)(struct snd_i2c_bus *bus);
45 int (*getdata)(struct snd_i2c_bus *bus, int ack);
46};
47
48struct snd_i2c_ops {
49 int (*sendbytes)(struct snd_i2c_device *device, unsigned char *bytes, int count);
50 int (*readbytes)(struct snd_i2c_device *device, unsigned char *bytes, int count);
51 int (*probeaddr)(struct snd_i2c_bus *bus, unsigned short addr);
52};
53
54struct snd_i2c_bus {
55 struct snd_card *card;
56 char name[32];
57
58 struct mutex lock_mutex;
59
60 struct snd_i2c_bus *master;
61 struct list_head buses;
62
63 struct list_head devices;
64
65 union {
66 struct snd_i2c_bit_ops *bit;
67 void *ops;
68 } hw_ops;
69 const struct snd_i2c_ops *ops;
70
71 unsigned long private_value;
72 void *private_data;
73 void (*private_free)(struct snd_i2c_bus *bus);
74};
75
76#define snd_i2c_slave_bus(n) list_entry(n, struct snd_i2c_bus, buses)
77
78int snd_i2c_bus_create(struct snd_card *card, const char *name,
79 struct snd_i2c_bus *master, struct snd_i2c_bus **ri2c);
80int snd_i2c_device_create(struct snd_i2c_bus *bus, const char *name,
81 unsigned char addr, struct snd_i2c_device **rdevice);
82int snd_i2c_device_free(struct snd_i2c_device *device);
83
84static inline void snd_i2c_lock(struct snd_i2c_bus *bus)
85{
86 if (bus->master)
87 mutex_lock(&bus->master->lock_mutex);
88 else
89 mutex_lock(&bus->lock_mutex);
90}
91
92static inline void snd_i2c_unlock(struct snd_i2c_bus *bus)
93{
94 if (bus->master)
95 mutex_unlock(&bus->master->lock_mutex);
96 else
97 mutex_unlock(&bus->lock_mutex);
98}
99
100int snd_i2c_sendbytes(struct snd_i2c_device *device, unsigned char *bytes, int count);
101int snd_i2c_readbytes(struct snd_i2c_device *device, unsigned char *bytes, int count);
102int snd_i2c_probeaddr(struct snd_i2c_bus *bus, unsigned short addr);
103
104#endif
105