aboutsummaryrefslogtreecommitdiffstats
path: root/sound/i2c/i2c.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/i2c/i2c.c')
-rw-r--r--sound/i2c/i2c.c79
1 files changed, 43 insertions, 36 deletions
diff --git a/sound/i2c/i2c.c b/sound/i2c/i2c.c
index e4e505b9d88b..c4e1f2c23ced 100644
--- a/sound/i2c/i2c.c
+++ b/sound/i2c/i2c.c
@@ -32,20 +32,23 @@ MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
32MODULE_DESCRIPTION("Generic i2c interface for ALSA"); 32MODULE_DESCRIPTION("Generic i2c interface for ALSA");
33MODULE_LICENSE("GPL"); 33MODULE_LICENSE("GPL");
34 34
35static int snd_i2c_bit_sendbytes(snd_i2c_device_t *device, unsigned char *bytes, int count); 35static int snd_i2c_bit_sendbytes(struct snd_i2c_device *device,
36static int snd_i2c_bit_readbytes(snd_i2c_device_t *device, unsigned char *bytes, int count); 36 unsigned char *bytes, int count);
37static int snd_i2c_bit_probeaddr(snd_i2c_bus_t *bus, unsigned short addr); 37static int snd_i2c_bit_readbytes(struct snd_i2c_device *device,
38 38 unsigned char *bytes, int count);
39static snd_i2c_ops_t snd_i2c_bit_ops = { 39static int snd_i2c_bit_probeaddr(struct snd_i2c_bus *bus,
40 unsigned short addr);
41
42static struct snd_i2c_ops snd_i2c_bit_ops = {
40 .sendbytes = snd_i2c_bit_sendbytes, 43 .sendbytes = snd_i2c_bit_sendbytes,
41 .readbytes = snd_i2c_bit_readbytes, 44 .readbytes = snd_i2c_bit_readbytes,
42 .probeaddr = snd_i2c_bit_probeaddr, 45 .probeaddr = snd_i2c_bit_probeaddr,
43}; 46};
44 47
45static int snd_i2c_bus_free(snd_i2c_bus_t *bus) 48static int snd_i2c_bus_free(struct snd_i2c_bus *bus)
46{ 49{
47 snd_i2c_bus_t *slave; 50 struct snd_i2c_bus *slave;
48 snd_i2c_device_t *device; 51 struct snd_i2c_device *device;
49 52
50 snd_assert(bus != NULL, return -EINVAL); 53 snd_assert(bus != NULL, return -EINVAL);
51 while (!list_empty(&bus->devices)) { 54 while (!list_empty(&bus->devices)) {
@@ -66,17 +69,18 @@ static int snd_i2c_bus_free(snd_i2c_bus_t *bus)
66 return 0; 69 return 0;
67} 70}
68 71
69static int snd_i2c_bus_dev_free(snd_device_t *device) 72static int snd_i2c_bus_dev_free(struct snd_device *device)
70{ 73{
71 snd_i2c_bus_t *bus = device->device_data; 74 struct snd_i2c_bus *bus = device->device_data;
72 return snd_i2c_bus_free(bus); 75 return snd_i2c_bus_free(bus);
73} 76}
74 77
75int snd_i2c_bus_create(snd_card_t *card, const char *name, snd_i2c_bus_t *master, snd_i2c_bus_t **ri2c) 78int snd_i2c_bus_create(struct snd_card *card, const char *name,
79 struct snd_i2c_bus *master, struct snd_i2c_bus **ri2c)
76{ 80{
77 snd_i2c_bus_t *bus; 81 struct snd_i2c_bus *bus;
78 int err; 82 int err;
79 static snd_device_ops_t ops = { 83 static struct snd_device_ops ops = {
80 .dev_free = snd_i2c_bus_dev_free, 84 .dev_free = snd_i2c_bus_dev_free,
81 }; 85 };
82 86
@@ -102,9 +106,10 @@ int snd_i2c_bus_create(snd_card_t *card, const char *name, snd_i2c_bus_t *master
102 return 0; 106 return 0;
103} 107}
104 108
105int snd_i2c_device_create(snd_i2c_bus_t *bus, const char *name, unsigned char addr, snd_i2c_device_t **rdevice) 109int snd_i2c_device_create(struct snd_i2c_bus *bus, const char *name,
110 unsigned char addr, struct snd_i2c_device **rdevice)
106{ 111{
107 snd_i2c_device_t *device; 112 struct snd_i2c_device *device;
108 113
109 *rdevice = NULL; 114 *rdevice = NULL;
110 snd_assert(bus != NULL, return -EINVAL); 115 snd_assert(bus != NULL, return -EINVAL);
@@ -119,7 +124,7 @@ int snd_i2c_device_create(snd_i2c_bus_t *bus, const char *name, unsigned char ad
119 return 0; 124 return 0;
120} 125}
121 126
122int snd_i2c_device_free(snd_i2c_device_t *device) 127int snd_i2c_device_free(struct snd_i2c_device *device)
123{ 128{
124 if (device->bus) 129 if (device->bus)
125 list_del(&device->list); 130 list_del(&device->list);
@@ -129,18 +134,18 @@ int snd_i2c_device_free(snd_i2c_device_t *device)
129 return 0; 134 return 0;
130} 135}
131 136
132int snd_i2c_sendbytes(snd_i2c_device_t *device, unsigned char *bytes, int count) 137int snd_i2c_sendbytes(struct snd_i2c_device *device, unsigned char *bytes, int count)
133{ 138{
134 return device->bus->ops->sendbytes(device, bytes, count); 139 return device->bus->ops->sendbytes(device, bytes, count);
135} 140}
136 141
137 142
138int snd_i2c_readbytes(snd_i2c_device_t *device, unsigned char *bytes, int count) 143int snd_i2c_readbytes(struct snd_i2c_device *device, unsigned char *bytes, int count)
139{ 144{
140 return device->bus->ops->readbytes(device, bytes, count); 145 return device->bus->ops->readbytes(device, bytes, count);
141} 146}
142 147
143int snd_i2c_probeaddr(snd_i2c_bus_t *bus, unsigned short addr) 148int snd_i2c_probeaddr(struct snd_i2c_bus *bus, unsigned short addr)
144{ 149{
145 return bus->ops->probeaddr(bus, addr); 150 return bus->ops->probeaddr(bus, addr);
146} 151}
@@ -149,31 +154,31 @@ int snd_i2c_probeaddr(snd_i2c_bus_t *bus, unsigned short addr)
149 * bit-operations 154 * bit-operations
150 */ 155 */
151 156
152static inline void snd_i2c_bit_hw_start(snd_i2c_bus_t *bus) 157static inline void snd_i2c_bit_hw_start(struct snd_i2c_bus *bus)
153{ 158{
154 if (bus->hw_ops.bit->start) 159 if (bus->hw_ops.bit->start)
155 bus->hw_ops.bit->start(bus); 160 bus->hw_ops.bit->start(bus);
156} 161}
157 162
158static inline void snd_i2c_bit_hw_stop(snd_i2c_bus_t *bus) 163static inline void snd_i2c_bit_hw_stop(struct snd_i2c_bus *bus)
159{ 164{
160 if (bus->hw_ops.bit->stop) 165 if (bus->hw_ops.bit->stop)
161 bus->hw_ops.bit->stop(bus); 166 bus->hw_ops.bit->stop(bus);
162} 167}
163 168
164static void snd_i2c_bit_direction(snd_i2c_bus_t *bus, int clock, int data) 169static void snd_i2c_bit_direction(struct snd_i2c_bus *bus, int clock, int data)
165{ 170{
166 if (bus->hw_ops.bit->direction) 171 if (bus->hw_ops.bit->direction)
167 bus->hw_ops.bit->direction(bus, clock, data); 172 bus->hw_ops.bit->direction(bus, clock, data);
168} 173}
169 174
170static void snd_i2c_bit_set(snd_i2c_bus_t *bus, int clock, int data) 175static void snd_i2c_bit_set(struct snd_i2c_bus *bus, int clock, int data)
171{ 176{
172 bus->hw_ops.bit->setlines(bus, clock, data); 177 bus->hw_ops.bit->setlines(bus, clock, data);
173} 178}
174 179
175#if 0 180#if 0
176static int snd_i2c_bit_clock(snd_i2c_bus_t *bus) 181static int snd_i2c_bit_clock(struct snd_i2c_bus *bus)
177{ 182{
178 if (bus->hw_ops.bit->getclock) 183 if (bus->hw_ops.bit->getclock)
179 return bus->hw_ops.bit->getclock(bus); 184 return bus->hw_ops.bit->getclock(bus);
@@ -181,12 +186,12 @@ static int snd_i2c_bit_clock(snd_i2c_bus_t *bus)
181} 186}
182#endif 187#endif
183 188
184static int snd_i2c_bit_data(snd_i2c_bus_t *bus, int ack) 189static int snd_i2c_bit_data(struct snd_i2c_bus *bus, int ack)
185{ 190{
186 return bus->hw_ops.bit->getdata(bus, ack); 191 return bus->hw_ops.bit->getdata(bus, ack);
187} 192}
188 193
189static void snd_i2c_bit_start(snd_i2c_bus_t *bus) 194static void snd_i2c_bit_start(struct snd_i2c_bus *bus)
190{ 195{
191 snd_i2c_bit_hw_start(bus); 196 snd_i2c_bit_hw_start(bus);
192 snd_i2c_bit_direction(bus, 1, 1); /* SCL - wr, SDA - wr */ 197 snd_i2c_bit_direction(bus, 1, 1); /* SCL - wr, SDA - wr */
@@ -195,7 +200,7 @@ static void snd_i2c_bit_start(snd_i2c_bus_t *bus)
195 snd_i2c_bit_set(bus, 0, 0); 200 snd_i2c_bit_set(bus, 0, 0);
196} 201}
197 202
198static void snd_i2c_bit_stop(snd_i2c_bus_t *bus) 203static void snd_i2c_bit_stop(struct snd_i2c_bus *bus)
199{ 204{
200 snd_i2c_bit_set(bus, 0, 0); 205 snd_i2c_bit_set(bus, 0, 0);
201 snd_i2c_bit_set(bus, 1, 0); 206 snd_i2c_bit_set(bus, 1, 0);
@@ -203,14 +208,14 @@ static void snd_i2c_bit_stop(snd_i2c_bus_t *bus)
203 snd_i2c_bit_hw_stop(bus); 208 snd_i2c_bit_hw_stop(bus);
204} 209}
205 210
206static void snd_i2c_bit_send(snd_i2c_bus_t *bus, int data) 211static void snd_i2c_bit_send(struct snd_i2c_bus *bus, int data)
207{ 212{
208 snd_i2c_bit_set(bus, 0, data); 213 snd_i2c_bit_set(bus, 0, data);
209 snd_i2c_bit_set(bus, 1, data); 214 snd_i2c_bit_set(bus, 1, data);
210 snd_i2c_bit_set(bus, 0, data); 215 snd_i2c_bit_set(bus, 0, data);
211} 216}
212 217
213static int snd_i2c_bit_ack(snd_i2c_bus_t *bus) 218static int snd_i2c_bit_ack(struct snd_i2c_bus *bus)
214{ 219{
215 int ack; 220 int ack;
216 221
@@ -223,7 +228,7 @@ static int snd_i2c_bit_ack(snd_i2c_bus_t *bus)
223 return ack ? -EIO : 0; 228 return ack ? -EIO : 0;
224} 229}
225 230
226static int snd_i2c_bit_sendbyte(snd_i2c_bus_t *bus, unsigned char data) 231static int snd_i2c_bit_sendbyte(struct snd_i2c_bus *bus, unsigned char data)
227{ 232{
228 int i, err; 233 int i, err;
229 234
@@ -234,7 +239,7 @@ static int snd_i2c_bit_sendbyte(snd_i2c_bus_t *bus, unsigned char data)
234 return 0; 239 return 0;
235} 240}
236 241
237static int snd_i2c_bit_readbyte(snd_i2c_bus_t *bus, int last) 242static int snd_i2c_bit_readbyte(struct snd_i2c_bus *bus, int last)
238{ 243{
239 int i; 244 int i;
240 unsigned char data = 0; 245 unsigned char data = 0;
@@ -252,9 +257,10 @@ static int snd_i2c_bit_readbyte(snd_i2c_bus_t *bus, int last)
252 return data; 257 return data;
253} 258}
254 259
255static int snd_i2c_bit_sendbytes(snd_i2c_device_t *device, unsigned char *bytes, int count) 260static int snd_i2c_bit_sendbytes(struct snd_i2c_device *device,
261 unsigned char *bytes, int count)
256{ 262{
257 snd_i2c_bus_t *bus = device->bus; 263 struct snd_i2c_bus *bus = device->bus;
258 int err, res = 0; 264 int err, res = 0;
259 265
260 if (device->flags & SND_I2C_DEVICE_ADDRTEN) 266 if (device->flags & SND_I2C_DEVICE_ADDRTEN)
@@ -275,9 +281,10 @@ static int snd_i2c_bit_sendbytes(snd_i2c_device_t *device, unsigned char *bytes,
275 return res; 281 return res;
276} 282}
277 283
278static int snd_i2c_bit_readbytes(snd_i2c_device_t *device, unsigned char *bytes, int count) 284static int snd_i2c_bit_readbytes(struct snd_i2c_device *device,
285 unsigned char *bytes, int count)
279{ 286{
280 snd_i2c_bus_t *bus = device->bus; 287 struct snd_i2c_bus *bus = device->bus;
281 int err, res = 0; 288 int err, res = 0;
282 289
283 if (device->flags & SND_I2C_DEVICE_ADDRTEN) 290 if (device->flags & SND_I2C_DEVICE_ADDRTEN)
@@ -299,7 +306,7 @@ static int snd_i2c_bit_readbytes(snd_i2c_device_t *device, unsigned char *bytes,
299 return res; 306 return res;
300} 307}
301 308
302static int snd_i2c_bit_probeaddr(snd_i2c_bus_t *bus, unsigned short addr) 309static int snd_i2c_bit_probeaddr(struct snd_i2c_bus *bus, unsigned short addr)
303{ 310{
304 int err; 311 int err;
305 312