24 #include <linux/slab.h>
25 #include <linux/module.h>
26 #include <linux/string.h>
27 #include <linux/errno.h>
43 .sendbytes = snd_i2c_bit_sendbytes,
44 .readbytes = snd_i2c_bit_readbytes,
45 .probeaddr = snd_i2c_bit_probeaddr,
55 while (!list_empty(&bus->
devices)) {
62 while (!list_empty(&bus->
buses)) {
73 static int snd_i2c_bus_dev_free(
struct snd_device *device)
76 return snd_i2c_bus_free(bus);
94 INIT_LIST_HEAD(&bus->
buses);
96 bus->
ops = &snd_i2c_bit_ops;
104 snd_i2c_bus_free(bus);
121 device = kzalloc(
sizeof(*device),
GFP_KERNEL);
148 return device->
bus->ops->sendbytes(device, bytes, count);
155 return device->
bus->ops->readbytes(device, bytes, count);
162 return bus->
ops->probeaddr(bus, addr);
171 static inline void snd_i2c_bit_hw_start(
struct snd_i2c_bus *bus)
177 static inline void snd_i2c_bit_hw_stop(
struct snd_i2c_bus *bus)
186 bus->
hw_ops.
bit->direction(bus, clock, data);
189 static void snd_i2c_bit_set(
struct snd_i2c_bus *bus,
int clock,
int data)
191 bus->
hw_ops.
bit->setlines(bus, clock, data);
195 static int snd_i2c_bit_clock(
struct snd_i2c_bus *bus)
205 return bus->
hw_ops.
bit->getdata(bus, ack);
208 static void snd_i2c_bit_start(
struct snd_i2c_bus *bus)
210 snd_i2c_bit_hw_start(bus);
211 snd_i2c_bit_direction(bus, 1, 1);
212 snd_i2c_bit_set(bus, 1, 1);
213 snd_i2c_bit_set(bus, 1, 0);
214 snd_i2c_bit_set(bus, 0, 0);
217 static void snd_i2c_bit_stop(
struct snd_i2c_bus *bus)
219 snd_i2c_bit_set(bus, 0, 0);
220 snd_i2c_bit_set(bus, 1, 0);
221 snd_i2c_bit_set(bus, 1, 1);
222 snd_i2c_bit_hw_stop(bus);
225 static void snd_i2c_bit_send(
struct snd_i2c_bus *bus,
int data)
227 snd_i2c_bit_set(bus, 0, data);
228 snd_i2c_bit_set(bus, 1, data);
229 snd_i2c_bit_set(bus, 0, data);
232 static int snd_i2c_bit_ack(
struct snd_i2c_bus *bus)
236 snd_i2c_bit_set(bus, 0, 1);
237 snd_i2c_bit_set(bus, 1, 1);
238 snd_i2c_bit_direction(bus, 1, 0);
239 ack = snd_i2c_bit_data(bus, 1);
240 snd_i2c_bit_direction(bus, 1, 1);
241 snd_i2c_bit_set(bus, 0, 1);
242 return ack ? -
EIO : 0;
245 static int snd_i2c_bit_sendbyte(
struct snd_i2c_bus *bus,
unsigned char data)
249 for (i = 7; i >= 0; i--)
250 snd_i2c_bit_send(bus, !!(data & (1 << i)));
251 err = snd_i2c_bit_ack(bus);
257 static int snd_i2c_bit_readbyte(
struct snd_i2c_bus *bus,
int last)
260 unsigned char data = 0;
262 snd_i2c_bit_set(bus, 0, 1);
263 snd_i2c_bit_direction(bus, 1, 0);
264 for (i = 7; i >= 0; i--) {
265 snd_i2c_bit_set(bus, 1, 1);
266 if (snd_i2c_bit_data(bus, 0))
268 snd_i2c_bit_set(bus, 0, 1);
270 snd_i2c_bit_direction(bus, 1, 1);
271 snd_i2c_bit_send(bus, !!last);
283 snd_i2c_bit_start(bus);
284 err = snd_i2c_bit_sendbyte(bus, device->
addr << 1);
286 snd_i2c_bit_hw_stop(bus);
289 while (count-- > 0) {
290 err = snd_i2c_bit_sendbyte(bus, *bytes++);
292 snd_i2c_bit_hw_stop(bus);
297 snd_i2c_bit_stop(bus);
302 unsigned char *bytes,
int count)
309 snd_i2c_bit_start(bus);
310 err = snd_i2c_bit_sendbyte(bus, (device->
addr << 1) | 1);
312 snd_i2c_bit_hw_stop(bus);
315 while (count-- > 0) {
316 err = snd_i2c_bit_readbyte(bus, count == 0);
318 snd_i2c_bit_hw_stop(bus);
321 *bytes++ = (
unsigned char)err;
324 snd_i2c_bit_stop(bus);
328 static int snd_i2c_bit_probeaddr(
struct snd_i2c_bus *bus,
unsigned short addr)
336 snd_i2c_bit_start(bus);
337 err = snd_i2c_bit_sendbyte(bus, addr << 1);
338 snd_i2c_bit_stop(bus);
343 static int __init alsa_i2c_init(
void)
348 static void __exit alsa_i2c_exit(
void)