Lines Matching full:bus
2 * QEMU I2C bus interface.
34 I2CBus *bus = opaque; in i2c_bus_pre_save() local
36 bus->saved_address = -1; in i2c_bus_pre_save()
37 if (!QLIST_EMPTY(&bus->current_devs)) { in i2c_bus_pre_save()
38 if (!bus->broadcast) { in i2c_bus_pre_save()
39 bus->saved_address = QLIST_FIRST(&bus->current_devs)->elt->address; in i2c_bus_pre_save()
41 bus->saved_address = I2C_BROADCAST; in i2c_bus_pre_save()
59 /* Create a new I2C bus. */
62 I2CBus *bus; in i2c_init_bus() local
64 bus = I2C_BUS(qbus_new(TYPE_I2C_BUS, parent, name)); in i2c_init_bus()
65 QLIST_INIT(&bus->current_devs); in i2c_init_bus()
66 QSIMPLEQ_INIT(&bus->pending_masters); in i2c_init_bus()
67 vmstate_register_any(NULL, &vmstate_i2c_bus, bus); in i2c_init_bus()
68 return bus; in i2c_init_bus()
76 /* Return nonzero if bus is busy. */
77 int i2c_bus_busy(I2CBus *bus) in i2c_bus_busy() argument
79 return !QLIST_EMPTY(&bus->current_devs) || bus->bh; in i2c_bus_busy()
82 bool i2c_scan_bus(I2CBus *bus, uint8_t address, bool broadcast, in i2c_scan_bus() argument
87 QTAILQ_FOREACH(kid, &bus->qbus.children, sibling) { in i2c_scan_bus()
110 * the bus transaction is terminated (or really never started). If
117 * without releasing the bus. If that fails, the bus is still
122 static int i2c_do_start_transfer(I2CBus *bus, uint8_t address, in i2c_do_start_transfer() argument
132 * bus. in i2c_do_start_transfer()
134 bus->broadcast = true; in i2c_do_start_transfer()
139 * the middle of a transaction and we shouldn't rescan the bus. in i2c_do_start_transfer()
145 if (QLIST_EMPTY(&bus->current_devs)) { in i2c_do_start_transfer()
147 (void)i2c_scan_bus(bus, address, bus->broadcast, &bus->current_devs); in i2c_do_start_transfer()
151 if (QLIST_EMPTY(&bus->current_devs)) { in i2c_do_start_transfer()
155 QLIST_FOREACH(node, &bus->current_devs, next) { in i2c_do_start_transfer()
160 /* If the bus is already busy, assume this is a repeated in i2c_do_start_transfer()
167 if (rv && !bus->broadcast) { in i2c_do_start_transfer()
170 i2c_end_transfer(bus); in i2c_do_start_transfer()
179 int i2c_start_transfer(I2CBus *bus, uint8_t address, bool is_recv) in i2c_start_transfer() argument
181 return i2c_do_start_transfer(bus, address, is_recv in i2c_start_transfer()
186 void i2c_bus_master(I2CBus *bus, QEMUBH *bh) in i2c_bus_master() argument
191 QSIMPLEQ_INSERT_TAIL(&bus->pending_masters, node, entry); in i2c_bus_master()
194 void i2c_schedule_pending_master(I2CBus *bus) in i2c_schedule_pending_master() argument
198 if (i2c_bus_busy(bus)) { in i2c_schedule_pending_master()
199 /* someone is already controlling the bus; wait for it to release it */ in i2c_schedule_pending_master()
203 if (QSIMPLEQ_EMPTY(&bus->pending_masters)) { in i2c_schedule_pending_master()
207 node = QSIMPLEQ_FIRST(&bus->pending_masters); in i2c_schedule_pending_master()
208 bus->bh = node->bh; in i2c_schedule_pending_master()
210 QSIMPLEQ_REMOVE_HEAD(&bus->pending_masters, entry); in i2c_schedule_pending_master()
213 qemu_bh_schedule(bus->bh); in i2c_schedule_pending_master()
216 void i2c_bus_release(I2CBus *bus) in i2c_bus_release() argument
218 bus->bh = NULL; in i2c_bus_release()
220 i2c_schedule_pending_master(bus); in i2c_bus_release()
223 int i2c_start_recv(I2CBus *bus, uint8_t address) in i2c_start_recv() argument
225 return i2c_do_start_transfer(bus, address, I2C_START_RECV); in i2c_start_recv()
228 int i2c_start_send(I2CBus *bus, uint8_t address) in i2c_start_send() argument
230 return i2c_do_start_transfer(bus, address, I2C_START_SEND); in i2c_start_send()
233 int i2c_start_send_async(I2CBus *bus, uint8_t address) in i2c_start_send_async() argument
235 return i2c_do_start_transfer(bus, address, I2C_START_SEND_ASYNC); in i2c_start_send_async()
238 void i2c_end_transfer(I2CBus *bus) in i2c_end_transfer() argument
243 QLIST_FOREACH_SAFE(node, &bus->current_devs, next, next) { in i2c_end_transfer()
253 bus->broadcast = false; in i2c_end_transfer()
256 int i2c_send(I2CBus *bus, uint8_t data) in i2c_send() argument
263 QLIST_FOREACH(node, &bus->current_devs, next) { in i2c_send()
277 int i2c_send_async(I2CBus *bus, uint8_t data) in i2c_send_async() argument
279 I2CNode *node = QLIST_FIRST(&bus->current_devs); in i2c_send_async()
294 uint8_t i2c_recv(I2CBus *bus) in i2c_recv() argument
300 if (!QLIST_EMPTY(&bus->current_devs) && !bus->broadcast) { in i2c_recv()
301 sc = I2C_SLAVE_GET_CLASS(QLIST_FIRST(&bus->current_devs)->elt); in i2c_recv()
303 s = QLIST_FIRST(&bus->current_devs)->elt; in i2c_recv()
312 void i2c_nack(I2CBus *bus) in i2c_nack() argument
317 if (QLIST_EMPTY(&bus->current_devs)) { in i2c_nack()
321 QLIST_FOREACH(node, &bus->current_devs, next) { in i2c_nack()
330 void i2c_ack(I2CBus *bus) in i2c_ack() argument
332 if (!bus->bh) { in i2c_ack()
338 qemu_bh_schedule(bus->bh); in i2c_ack()
344 I2CBus *bus; in i2c_slave_post_load() local
347 bus = I2C_BUS(qdev_get_parent_bus(DEVICE(dev))); in i2c_slave_post_load()
348 if ((bus->saved_address == dev->address) || in i2c_slave_post_load()
349 (bus->saved_address == I2C_BROADCAST)) { in i2c_slave_post_load()
352 QLIST_INSERT_HEAD(&bus->current_devs, node, next); in i2c_slave_post_load()
377 bool i2c_slave_realize_and_unref(I2CSlave *dev, I2CBus *bus, Error **errp) in i2c_slave_realize_and_unref() argument
379 return qdev_realize_and_unref(&dev->qdev, &bus->qbus, errp); in i2c_slave_realize_and_unref()
382 I2CSlave *i2c_slave_create_simple(I2CBus *bus, const char *name, uint8_t addr) in i2c_slave_create_simple() argument
386 i2c_slave_realize_and_unref(dev, bus, &error_abort); in i2c_slave_create_simple()