Lines Matching +full:i2c +full:- +full:slave +full:- +full:addr
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
57 * AT24 parts have a "write page size" that differs per-device, and a "read page
68 int addr; /* Slave address on the bus */ member
112 #define CDEV2SOFTC(dev) ((dev)->si_drv1)
135 ofw_bus_search_compatible(dev, compat_data)->ocd_data; in icee_probe()
137 device_set_desc(dev, d->name); in icee_probe()
141 device_set_desc(dev, "I2C EEPROM"); in icee_probe()
154 ofw_bus_search_compatible(sc->dev, compat_data)->ocd_data; in icee_init()
156 sc->size = d->size; in icee_init()
157 sc->type = d->type; in icee_init()
158 sc->wr_sz = d->wr_sz; in icee_init()
162 dname = device_get_name(sc->dev); in icee_init()
163 dunit = device_get_unit(sc->dev); in icee_init()
164 if (resource_int_value(dname, dunit, "type", &sc->type) != 0) in icee_init()
166 if (resource_int_value(dname, dunit, "size", &sc->size) != 0) in icee_init()
168 if (resource_int_value(dname, dunit, "wr_sz", &sc->wr_sz) != 0) in icee_init()
180 sc->dev = dev; in icee_attach()
181 sc->addr = iicbus_get_addr(dev); in icee_attach()
185 device_printf(dev, "size: %d bytes, addressing: %d-bits\n", in icee_attach()
186 sc->size, sc->type); in icee_attach()
187 sc->cdev = make_dev(&icee_cdevsw, device_get_unit(dev), UID_ROOT, in icee_attach()
189 if (sc->cdev == NULL) { in icee_attach()
192 sc->cdev->si_drv1 = sc; in icee_attach()
197 &sc->type, 0, "Memory array address size in bits"); in icee_attach()
199 &sc->size, 0, "Memory array capacity in bytes"); in icee_attach()
201 &sc->wr_sz, 0, "Memory array page write size in bytes"); in icee_attach()
211 destroy_dev(sc->cdev); in icee_detach()
219 uint8_t addr[2]; in icee_read() local
221 int error, i, len, slave; in icee_read() local
223 { 0, IIC_M_WR, 1, addr }, in icee_read()
228 if (uio->uio_offset == sc->size) in icee_read()
230 if (uio->uio_offset > sc->size) in icee_read()
232 if (sc->type != 8 && sc->type != 16) in icee_read()
234 slave = error = 0; in icee_read()
235 while (uio->uio_resid > 0) { in icee_read()
236 if (uio->uio_offset >= sc->size) in icee_read()
238 len = MIN(MAX_RD_SZ - (uio->uio_offset & (MAX_RD_SZ - 1)), in icee_read()
239 uio->uio_resid); in icee_read()
240 switch (sc->type) { in icee_read()
242 slave = (uio->uio_offset >> 7) | sc->addr; in icee_read()
245 addr[0] = uio->uio_offset & 0xff; in icee_read()
248 slave = sc->addr | (uio->uio_offset >> 15); in icee_read()
251 addr[0] = (uio->uio_offset >> 8) & 0xff; in icee_read()
252 addr[1] = uio->uio_offset & 0xff; in icee_read()
256 msgs[i].slave = slave; in icee_read()
257 error = iicbus_transfer_excl(sc->dev, msgs, 2, IIC_INTRWAIT); in icee_read()
279 int error, len, slave, waitlimit; in icee_write() local
289 if (uio->uio_offset >= sc->size) in icee_write()
291 if (sc->type != 8 && sc->type != 16) in icee_write()
294 slave = error = 0; in icee_write()
295 while (uio->uio_resid > 0) { in icee_write()
296 if (uio->uio_offset >= sc->size) in icee_write()
298 len = MIN(sc->wr_sz - (uio->uio_offset & (sc->wr_sz - 1)), in icee_write()
299 uio->uio_resid); in icee_write()
300 switch (sc->type) { in icee_write()
302 slave = (uio->uio_offset >> 7) | sc->addr; in icee_write()
304 data[0] = uio->uio_offset & 0xff; in icee_write()
307 slave = sc->addr | (uio->uio_offset >> 15); in icee_write()
309 data[0] = (uio->uio_offset >> 8) & 0xff; in icee_write()
310 data[1] = uio->uio_offset & 0xff; in icee_write()
313 wr[0].slave = slave; in icee_write()
314 error = uiomove(data + sc->type / 8, len, uio); in icee_write()
317 error = iicbus_transfer_excl(sc->dev, wr, 1, IIC_INTRWAIT); in icee_write()
322 /* Read after write to wait for write-done. */ in icee_write()
324 rd[0].slave = slave; in icee_write()
326 error = iicbus_transfer_excl(sc->dev, rd, 1, in icee_write()
328 } while (waitlimit-- > 0 && error != 0); in icee_write()