Lines Matching refs:bus

25 static int snd_i2c_bit_probeaddr(struct snd_i2c_bus *bus,
34 static int snd_i2c_bus_free(struct snd_i2c_bus *bus)
39 if (snd_BUG_ON(!bus))
41 while (!list_empty(&bus->devices)) {
42 device = snd_i2c_device(bus->devices.next);
45 if (bus->master)
46 list_del(&bus->buses);
48 while (!list_empty(&bus->buses)) {
49 slave = snd_i2c_slave_bus(bus->buses.next);
50 snd_device_free(bus->card, slave);
53 if (bus->private_free)
54 bus->private_free(bus);
55 kfree(bus);
61 struct snd_i2c_bus *bus = device->device_data;
62 return snd_i2c_bus_free(bus);
68 struct snd_i2c_bus *bus;
75 bus = kzalloc(sizeof(*bus), GFP_KERNEL);
76 if (bus == NULL)
78 mutex_init(&bus->lock_mutex);
79 INIT_LIST_HEAD(&bus->devices);
80 INIT_LIST_HEAD(&bus->buses);
81 bus->card = card;
82 bus->ops = &snd_i2c_bit_ops;
84 list_add_tail(&bus->buses, &master->buses);
85 bus->master = master;
87 strscpy(bus->name, name, sizeof(bus->name));
88 err = snd_device_new(card, SNDRV_DEV_BUS, bus, &ops);
90 snd_i2c_bus_free(bus);
93 *ri2c = bus;
99 int snd_i2c_device_create(struct snd_i2c_bus *bus, const char *name,
105 if (snd_BUG_ON(!bus))
112 list_add_tail(&device->list, &bus->devices);
113 device->bus = bus;
122 if (device->bus)
134 return device->bus->ops->sendbytes(device, bytes, count);
141 return device->bus->ops->readbytes(device, bytes, count);
146 int snd_i2c_probeaddr(struct snd_i2c_bus *bus, unsigned short addr)
148 return bus->ops->probeaddr(bus, addr);
157 static inline void snd_i2c_bit_hw_start(struct snd_i2c_bus *bus)
159 if (bus->hw_ops.bit->start)
160 bus->hw_ops.bit->start(bus);
163 static inline void snd_i2c_bit_hw_stop(struct snd_i2c_bus *bus)
165 if (bus->hw_ops.bit->stop)
166 bus->hw_ops.bit->stop(bus);
169 static void snd_i2c_bit_direction(struct snd_i2c_bus *bus, int clock, int data)
171 if (bus->hw_ops.bit->direction)
172 bus->hw_ops.bit->direction(bus, clock, data);
175 static void snd_i2c_bit_set(struct snd_i2c_bus *bus, int clock, int data)
177 bus->hw_ops.bit->setlines(bus, clock, data);
181 static int snd_i2c_bit_clock(struct snd_i2c_bus *bus)
183 if (bus->hw_ops.bit->getclock)
184 return bus->hw_ops.bit->getclock(bus);
189 static int snd_i2c_bit_data(struct snd_i2c_bus *bus, int ack)
191 return bus->hw_ops.bit->getdata(bus, ack);
194 static void snd_i2c_bit_start(struct snd_i2c_bus *bus)
196 snd_i2c_bit_hw_start(bus);
197 snd_i2c_bit_direction(bus, 1, 1); /* SCL - wr, SDA - wr */
198 snd_i2c_bit_set(bus, 1, 1);
199 snd_i2c_bit_set(bus, 1, 0);
200 snd_i2c_bit_set(bus, 0, 0);
203 static void snd_i2c_bit_stop(struct snd_i2c_bus *bus)
205 snd_i2c_bit_set(bus, 0, 0);
206 snd_i2c_bit_set(bus, 1, 0);
207 snd_i2c_bit_set(bus, 1, 1);
208 snd_i2c_bit_hw_stop(bus);
211 static void snd_i2c_bit_send(struct snd_i2c_bus *bus, int data)
213 snd_i2c_bit_set(bus, 0, data);
214 snd_i2c_bit_set(bus, 1, data);
215 snd_i2c_bit_set(bus, 0, data);
218 static int snd_i2c_bit_ack(struct snd_i2c_bus *bus)
222 snd_i2c_bit_set(bus, 0, 1);
223 snd_i2c_bit_set(bus, 1, 1);
224 snd_i2c_bit_direction(bus, 1, 0); /* SCL - wr, SDA - rd */
225 ack = snd_i2c_bit_data(bus, 1);
226 snd_i2c_bit_direction(bus, 1, 1); /* SCL - wr, SDA - wr */
227 snd_i2c_bit_set(bus, 0, 1);
231 static int snd_i2c_bit_sendbyte(struct snd_i2c_bus *bus, unsigned char data)
236 snd_i2c_bit_send(bus, !!(data & (1 << i)));
237 err = snd_i2c_bit_ack(bus);
243 static int snd_i2c_bit_readbyte(struct snd_i2c_bus *bus, int last)
248 snd_i2c_bit_set(bus, 0, 1);
249 snd_i2c_bit_direction(bus, 1, 0); /* SCL - wr, SDA - rd */
251 snd_i2c_bit_set(bus, 1, 1);
252 if (snd_i2c_bit_data(bus, 0))
254 snd_i2c_bit_set(bus, 0, 1);
256 snd_i2c_bit_direction(bus, 1, 1); /* SCL - wr, SDA - wr */
257 snd_i2c_bit_send(bus, !!last);
264 struct snd_i2c_bus *bus = device->bus;
269 snd_i2c_bit_start(bus);
270 err = snd_i2c_bit_sendbyte(bus, device->addr << 1);
272 snd_i2c_bit_hw_stop(bus);
276 err = snd_i2c_bit_sendbyte(bus, *bytes++);
278 snd_i2c_bit_hw_stop(bus);
283 snd_i2c_bit_stop(bus);
290 struct snd_i2c_bus *bus = device->bus;
295 snd_i2c_bit_start(bus);
296 err = snd_i2c_bit_sendbyte(bus, (device->addr << 1) | 1);
298 snd_i2c_bit_hw_stop(bus);
302 err = snd_i2c_bit_readbyte(bus, count == 0);
304 snd_i2c_bit_hw_stop(bus);
310 snd_i2c_bit_stop(bus);
314 static int snd_i2c_bit_probeaddr(struct snd_i2c_bus *bus, unsigned short addr)
322 snd_i2c_bit_start(bus);
323 err = snd_i2c_bit_sendbyte(bus, addr << 1);
324 snd_i2c_bit_stop(bus);