Lines Matching +full:slave +full:- +full:dev
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
37 #include <dev/iicbus/iiconf.h>
38 #include <dev/iicbus/iicbus.h>
44 * system errno value later. This lets controller- and bus-layer code get
54 * Translate IIC_Exxxxx status values to vaguely-equivelent errno values.
75 * IIC_ERRNO marker bit. If lots of high-order bits are set, in iic2errno()
76 * then it's one of the negative pseudo-errors such as ERESTART in iic2errno()
77 * and we return it as-is. Otherwise it's a plain "small in iic2errno()
99 if (sc->owner) in iicbus_intr()
100 IICBUS_INTR(sc->owner, event, buf); in iicbus_intr()
113 error = mtx_sleep(sc, &sc->lock, IICPRI|PCATCH, "iicreq", 0); in iicbus_poll()
117 error = mtx_sleep(sc, &sc->lock, IICPRI, "iicreq", 0); in iicbus_poll()
135 iicbus_request_bus(device_t bus, device_t dev, int how) in iicbus_request_bus() argument
144 if (sc->owner == NULL) in iicbus_request_bus()
146 if ((how & IIC_RECURSIVE) && sc->owner == dev) in iicbus_request_bus()
153 ++sc->owncount; in iicbus_request_bus()
154 if (sc->owner == NULL) { in iicbus_request_bus()
155 sc->owner = dev; in iicbus_request_bus()
163 if (device_get_state(dev) < DS_ATTACHING) in iicbus_request_bus()
164 sc->busydev = bus; in iicbus_request_bus()
166 sc->busydev = dev; in iicbus_request_bus()
167 device_busy(sc->busydev); in iicbus_request_bus()
176 reqdata.dev = dev; in iicbus_request_bus()
184 sc->owner = NULL; in iicbus_request_bus()
185 sc->owncount = 0; in iicbus_request_bus()
187 device_unbusy(sc->busydev); in iicbus_request_bus()
203 iicbus_release_bus(device_t bus, device_t dev) in iicbus_release_bus() argument
210 if (sc->owner != dev) { in iicbus_release_bus()
215 if (--sc->owncount == 0) { in iicbus_release_bus()
216 /* Drop the lock while informing the low-level driver. */ in iicbus_release_bus()
218 reqdata.dev = dev; in iicbus_release_bus()
224 sc->owner = NULL; in iicbus_release_bus()
226 device_unbusy(sc->busydev); in iicbus_release_bus()
242 return (sc->started); in iicbus_started()
248 * Send start condition to the slave addressed by 'slave'
251 iicbus_start(device_t bus, u_char slave, int timeout) in iicbus_start() argument
256 if (sc->started) in iicbus_start()
259 if (!(error = IICBUS_START(device_get_parent(bus), slave, timeout))) in iicbus_start()
260 sc->started = slave; in iicbus_start()
262 sc->started = 0; in iicbus_start()
270 * Send start condition to the slave addressed by 'slave'
273 iicbus_repeated_start(device_t bus, u_char slave, int timeout) in iicbus_repeated_start() argument
278 if (!sc->started) in iicbus_repeated_start()
281 if (!(error = IICBUS_REPEATED_START(device_get_parent(bus), slave, timeout))) in iicbus_repeated_start()
282 sc->started = slave; in iicbus_repeated_start()
284 sc->started = 0; in iicbus_repeated_start()
300 if (!sc->started) in iicbus_stop()
306 sc->started = 0; in iicbus_stop()
314 * Write a block of data to the slave previously started by
322 /* a slave must have been started for writing */ in iicbus_write()
323 if (sc->started == 0 || (sc->strict != 0 && (sc->started & LSB) != 0)) in iicbus_write()
332 * Read a block of data from the slave previously started by
340 /* a slave must have been started for reading */ in iicbus_read()
341 if (sc->started == 0 || (sc->strict != 0 && (sc->started & LSB) == 0)) in iicbus_read()
350 * Write a byte to the slave previously started by iicbus_start() call
359 /* a slave must have been started for writing */ in iicbus_write_byte()
360 if (sc->started == 0 || (sc->strict != 0 && (sc->started & LSB) != 0)) in iicbus_write_byte()
369 * Read a byte from the slave previously started by iicbus_start() call
377 /* a slave must have been started for reading */ in iicbus_read_byte()
378 if (sc->started == 0 || (sc->strict != 0 && (sc->started & LSB) == 0)) in iicbus_read_byte()
387 * Write a block of data to slave ; start/stop protocol managed
390 iicbus_block_write(device_t bus, u_char slave, char *buf, int len, int *sent) in iicbus_block_write() argument
392 u_char addr = slave & ~LSB; in iicbus_block_write()
408 * Read a block of data from slave ; start/stop protocol managed
411 iicbus_block_read(device_t bus, u_char slave, char *buf, int len, int *read) in iicbus_block_read() argument
413 u_char addr = slave | LSB; in iicbus_block_read()
446 iicbus_transfer_excl(device_t dev, struct iic_msg *msgs, uint32_t nmsgs, in iicbus_transfer_excl() argument
452 bus = device_get_parent(dev); in iicbus_transfer_excl()
453 error = iicbus_request_bus(bus, dev, how); in iicbus_transfer_excl()
456 iicbus_release_bus(bus, dev); in iicbus_transfer_excl()
466 iicbus_transfer_gen(device_t dev, struct iic_msg *msgs, uint32_t nmsgs) in iicbus_transfer_gen() argument
472 if ((error = device_get_children(dev, &children, &nkid)) != 0) in iicbus_transfer_gen()
483 addr = msgs[i].slave; in iicbus_transfer_gen()
528 * Two transfers back to back with a repeat-start between them; first we in iicdev_readfrom()
529 * write the address-within-device, then we read from the device. in iicdev_readfrom()
533 msgs[0].slave = slaveaddr; in iicdev_readfrom()
538 msgs[1].slave = slaveaddr; in iicdev_readfrom()
581 msg.slave = iicbus_get_addr(slavedev); in iicdev_writeto()