Lines Matching +full:slave +full:- +full:dev
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
57 #include <dev/iicbus/iiconf.h>
58 #include <dev/iicbus/iicbus.h>
60 #include <dev/smbus/smb.h>
61 #include <dev/smbus/smbconf.h>
74 u_char devaddr; /* slave device address */
88 static int iicsmb_intr(device_t dev, int event, char *buf);
89 static int iicsmb_callback(device_t dev, int index, void *data);
90 static int iicsmb_quick(device_t dev, u_char slave, int how);
91 static int iicsmb_sendb(device_t dev, u_char slave, char byte);
92 static int iicsmb_recvb(device_t dev, u_char slave, char *byte);
93 static int iicsmb_writeb(device_t dev, u_char slave, char cmd, char byte);
94 static int iicsmb_writew(device_t dev, u_char slave, char cmd, short word);
95 static int iicsmb_readb(device_t dev, u_char slave, char cmd, char *byte);
96 static int iicsmb_readw(device_t dev, u_char slave, char cmd, short *word);
97 static int iicsmb_pcall(device_t dev, u_char slave, char cmd, short sdata, short *rdata);
98 static int iicsmb_bwrite(device_t dev, u_char slave, char cmd, u_char count, char *buf);
99 static int iicsmb_bread(device_t dev, u_char slave, char cmd, u_char *count, char *buf);
137 if (device_find_child(parent, "iicsmb", -1) == NULL)
142 iicsmb_probe(device_t dev)
144 device_set_desc(dev, "SMBus over I2C bridge");
149 iicsmb_attach(device_t dev)
151 struct iicsmb_softc *sc = (struct iicsmb_softc *)device_get_softc(dev);
153 mtx_init(&sc->lock, "iicsmb", NULL, MTX_DEF);
155 sc->smbus = device_add_child(dev, "smbus", DEVICE_UNIT_ANY);
158 bus_generic_attach(dev);
164 iicsmb_detach(device_t dev)
166 struct iicsmb_softc *sc = (struct iicsmb_softc *)device_get_softc(dev);
168 bus_generic_detach(dev);
169 device_delete_children(dev);
170 mtx_destroy(&sc->lock);
181 iicsmb_intr(device_t dev, int event, char *buf)
183 struct iicsmb_softc *sc = (struct iicsmb_softc *)device_get_softc(dev);
185 mtx_lock(&sc->lock);
189 sc->state = SMB_WAITING_ADDR;
194 smbus_intr(sc->smbus, sc->devaddr,
195 sc->low, sc->high, SMB_ENOERR);
199 switch (sc->state) {
203 sc->devaddr & 0xff);
207 sc->devaddr = (u_char)*buf;
208 sc->state = SMB_WAITING_LOW;
212 sc->low = *buf;
213 sc->state = SMB_WAITING_HIGH;
217 sc->high = *buf;
218 sc->state = SMB_DONE;
231 smbus_intr(sc->smbus, sc->devaddr, 0, 0, SMB_EBUSERR);
244 mtx_unlock(&sc->lock);
250 iicsmb_callback(device_t dev, int index, void *data)
252 device_t parent = device_get_parent(dev);
260 error = iicbus_request_bus(parent, dev, how);
265 error = iicbus_release_bus(parent, dev);
306 #define TRANSFER_MSGS(dev, msgs) iicbus_transfer(dev, msgs, nitems(msgs))
309 iicsmb_quick(device_t dev, u_char slave, int how)
312 { slave, how == SMB_QWRITE ? IIC_M_WR : IIC_M_RD, 0, NULL },
324 error = TRANSFER_MSGS(dev, msgs);
329 iicsmb_sendb(device_t dev, u_char slave, char byte)
332 { slave, IIC_M_WR, 1, &byte },
336 error = TRANSFER_MSGS(dev, msgs);
341 iicsmb_recvb(device_t dev, u_char slave, char *byte)
344 { slave, IIC_M_RD, 1, byte },
348 error = TRANSFER_MSGS(dev, msgs);
353 iicsmb_writeb(device_t dev, u_char slave, char cmd, char byte)
357 { slave, IIC_M_WR, nitems(bytes), bytes },
361 error = TRANSFER_MSGS(dev, msgs);
366 iicsmb_writew(device_t dev, u_char slave, char cmd, short word)
370 { slave, IIC_M_WR, nitems(bytes), bytes },
374 error = TRANSFER_MSGS(dev, msgs);
379 iicsmb_readb(device_t dev, u_char slave, char cmd, char *byte)
382 { slave, IIC_M_WR | IIC_M_NOSTOP, 1, &cmd },
383 { slave, IIC_M_RD, 1, byte },
387 error = TRANSFER_MSGS(dev, msgs);
392 iicsmb_readw(device_t dev, u_char slave, char cmd, short *word)
396 { slave, IIC_M_WR | IIC_M_NOSTOP, 1, &cmd },
397 { slave, IIC_M_RD, nitems(buf), buf },
401 error = TRANSFER_MSGS(dev, msgs);
408 iicsmb_pcall(device_t dev, u_char slave, char cmd, short sdata, short *rdata)
413 { slave, IIC_M_WR | IIC_M_NOSTOP, nitems(in), in },
414 { slave, IIC_M_RD, nitems(out), out },
418 error = TRANSFER_MSGS(dev, msgs);
425 iicsmb_bwrite(device_t dev, u_char slave, char cmd, u_char count, char *buf)
429 { slave, IIC_M_WR | IIC_M_NOSTOP, nitems(bytes), bytes },
430 { slave, IIC_M_WR | IIC_M_NOSTART, count, buf },
436 error = TRANSFER_MSGS(dev, msgs);
441 iicsmb_bread(device_t dev, u_char slave, char cmd, u_char *count, char *buf)
444 { slave, IIC_M_WR | IIC_M_NOSTOP, 1, &cmd },
445 { slave, IIC_M_RD | IIC_M_NOSTOP, 1, count },
448 { slave, IIC_M_RD | IIC_M_NOSTART, 0, buf },
450 device_t parent = device_get_parent(dev);
454 error = iicbus_request_bus(parent, dev, IIC_WAIT | IIC_RECURSIVE);
456 error = TRANSFER_MSGS(dev, msgs);
459 * If the slave offers an empty or a too long reply,
466 error = TRANSFER_MSGS(dev, block_msg);
470 (void)iicbus_release_bus(parent, dev);