Lines Matching refs:dev
28 __FBSDID("$FreeBSD: releng/11.0/sys/dev/iicbus/iicbb.c 289657 2015-10-20 19:52:59Z dumbbell $");
56 #include <dev/ofw/ofw_bus.h>
57 #include <dev/ofw/ofw_bus_subr.h>
58 #include <dev/fdt/fdt_common.h>
61 #include <dev/iicbus/iiconf.h>
62 #include <dev/iicbus/iicbus.h>
64 #include <dev/smbus/smbconf.h>
86 static int iicbb_transfer(device_t dev, struct iic_msg *msgs, uint32_t nmsgs);
128 iicbb_probe(device_t dev)
130 device_set_desc(dev, "I2C bit-banging driver");
136 iicbb_attach(device_t dev)
138 struct iicbb_softc *sc = (struct iicbb_softc *)device_get_softc(dev);
140 sc->iicbus = device_add_child(dev, "iicbus", -1);
144 bus_generic_attach(dev);
150 iicbb_detach(device_t dev)
153 bus_generic_detach(dev);
154 device_delete_children(dev);
161 iicbb_get_node(device_t bus, device_t dev)
170 iicbb_child_detached( device_t dev, device_t child )
172 struct iicbb_softc *sc = (struct iicbb_softc *)device_get_softc(dev);
179 iicbb_print_child(device_t bus, device_t dev)
185 retval += bus_print_child_header(bus, dev);
202 #define I2C_SETSDA(sc,dev,val) do { \
203 IICBB_SETSDA(device_get_parent(dev), val); \
207 #define I2C_SETSCL(dev,val) do { \
208 iicbb_setscl(dev, val, 100); \
211 #define I2C_SET(sc,dev,ctrl,data) do { \
212 I2C_SETSCL(dev, ctrl); \
213 I2C_SETSDA(sc, dev, data); \
216 #define I2C_GETSDA(dev) (IICBB_GETSDA(device_get_parent(dev)))
218 #define I2C_GETSCL(dev) (IICBB_GETSCL(device_get_parent(dev)))
230 iicbb_setscl(device_t dev, int val, int timeout)
232 struct iicbb_softc *sc = device_get_softc(dev);
235 IICBB_SETSCL(device_get_parent(dev), val);
238 while (val && !I2C_GETSCL(dev) && k++ < timeout) {
239 IICBB_SETSCL(device_get_parent(dev), val);
247 iicbb_one(device_t dev, int timeout)
249 struct iicbb_softc *sc = device_get_softc(dev);
251 I2C_SET(sc,dev,0,1);
252 I2C_SET(sc,dev,1,1);
253 I2C_SET(sc,dev,0,1);
258 iicbb_zero(device_t dev, int timeout)
260 struct iicbb_softc *sc = device_get_softc(dev);
262 I2C_SET(sc,dev,0,0);
263 I2C_SET(sc,dev,1,0);
264 I2C_SET(sc,dev,0,0);
283 iicbb_ack(device_t dev, int timeout)
285 struct iicbb_softc *sc = device_get_softc(dev);
289 I2C_SET(sc,dev,0,1);
290 I2C_SET(sc,dev,1,1);
292 noack = I2C_GETSDA(dev);
299 I2C_SET(sc,dev,0,1);
306 iicbb_sendbyte(device_t dev, u_char data, int timeout)
312 iicbb_one(dev, timeout);
314 iicbb_zero(dev, timeout);
322 iicbb_readbyte(device_t dev, int last, int timeout)
324 struct iicbb_softc *sc = device_get_softc(dev);
328 I2C_SET(sc,dev,0,1);
331 I2C_SET(sc,dev,1,1);
332 if (I2C_GETSDA(dev))
334 I2C_SET(sc,dev,0,1);
337 iicbb_one(dev, timeout);
339 iicbb_zero(dev, timeout);
346 iicbb_callback(device_t dev, int index, caddr_t data)
348 return (IICBB_CALLBACK(device_get_parent(dev), index, data));
352 iicbb_reset(device_t dev, u_char speed, u_char addr, u_char *oldaddr)
354 return (IICBB_RESET(device_get_parent(dev), speed, addr, oldaddr));
358 iicbb_start(device_t dev, u_char slave, int timeout)
360 struct iicbb_softc *sc = device_get_softc(dev);
365 I2C_SET(sc,dev,1,1);
366 I2C_SET(sc,dev,1,0);
367 I2C_SET(sc,dev,0,0);
370 iicbb_sendbyte(dev, slave, timeout);
373 if (iicbb_ack(dev, timeout)) {
381 iicbb_stop(dev);
386 iicbb_stop(device_t dev)
388 struct iicbb_softc *sc = device_get_softc(dev);
390 I2C_SET(sc,dev,0,0);
391 I2C_SET(sc,dev,1,0);
392 I2C_SET(sc,dev,1,1);
399 iicbb_write(device_t dev, const char *buf, int len, int *sent, int timeout)
406 iicbb_sendbyte(dev,(u_char)*buf++, timeout);
409 if (iicbb_ack(dev, timeout)) {
423 iicbb_read(device_t dev, char * buf, int len, int *read, int last, int delay)
430 *buf++ = (char)iicbb_readbyte(dev, (len == 1) ? last : 0, delay);
441 iicbb_transfer(device_t dev, struct iic_msg *msgs, uint32_t nmsgs)
445 error = IICBB_PRE_XFER(device_get_parent(dev));
449 error = iicbus_transfer_gen(dev, msgs, nmsgs);
451 IICBB_POST_XFER(device_get_parent(dev));