Lines Matching +full:i2c +full:- +full:slave +full:- +full:addr

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
36 * copyright (C) 2005-2006 Texas Instruments, Inc.
78 /* Each TWL device typically has more than one I2C address */
84 /* The TWL devices typically use 4 I2C address for the different internal
85 * register sets, plus one SmartReflex I2C address.
112 #define TWL_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx)
113 #define TWL_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx)
115 mtx_init(&_sc->sc_mtx, device_get_nameunit(_sc->sc_dev), \
117 #define TWL_LOCK_DESTROY(_sc) mtx_destroy(&_sc->sc_mtx);
118 #define TWL_ASSERT_LOCKED(_sc) mtx_assert(&_sc->sc_mtx, MA_OWNED);
119 #define TWL_ASSERT_UNLOCKED(_sc) mtx_assert(&_sc->sc_mtx, MA_NOTOWNED);
122 * twl_is_4030 - returns true if the device is TWL4030
123 * twl_is_6025 - returns true if the device is TWL6025
124 * twl_is_6030 - returns true if the device is TWL6030
127 * Returns a non-zero value if the device matches.
130 * Returns a non-zero value if the device matches, otherwise zero.
136 return (sc->sc_type == TWL_DEVICE_4030); in twl_is_4030()
143 return (sc->sc_type == TWL_DEVICE_6025); in twl_is_6025()
150 return (sc->sc_type == TWL_DEVICE_6030); in twl_is_6030()
154 * twl_read - read one or more registers from the TWL device
156 * @nsub: the sub-module to read from
171 uint8_t addr; in twl_read() local
177 addr = sc->sc_subaddr_map[nsub]; in twl_read()
180 if (addr == TWL_INVALID_CHIP_ID) in twl_read()
184 msg[0].slave = addr; in twl_read()
189 msg[1].slave = addr; in twl_read()
197 addr, reg); in twl_read()
205 * twl_write - writes one or more registers to the TWL device
207 * @nsub: the sub-module to read from
222 uint8_t addr; in twl_write() local
236 addr = sc->sc_subaddr_map[nsub]; in twl_write()
239 if (addr == TWL_INVALID_CHIP_ID) in twl_write()
243 msg.slave = addr; in twl_write()
250 device_printf(sc->sc_dev, "iicbus write failed (adr:0x%02x, reg:0x%02x)\n", in twl_write()
251 addr, reg); in twl_write()
259 * twl_test_present - checks if a device with given address is present
261 * @addr: the address of the device to scan for
270 twl_test_present(struct twl_softc *sc, uint8_t addr) in twl_test_present() argument
276 msg.slave = addr; in twl_test_present()
281 if (iicbus_transfer(sc->sc_dev, &msg, 1) != 0) in twl_test_present()
288 * twl_scan - scans the i2c bus for sub modules
291 * TWL devices don't just have one i2c slave address, rather they have up to
293 * function scans the bus for 4 possible sub-devices and stores the info
315 device_printf(sc->sc_dev, "Found (sub)device at 0x%02x\n", (base + i)); in twl_scan()
320 memcpy(sc->sc_subaddr_map, devs, TWL_MAX_SUBADDRS); in twl_scan()
324 config_intrhook_disestablish(&sc->sc_scan_hook); in twl_scan()
328 * twl_probe -
357 sc->sc_dev = dev; in twl_probe()
358 sc->sc_type = TWL_DEVICE_UNKNOWN; in twl_probe()
362 sc->sc_type = TWL_DEVICE_6030; in twl_probe()
364 sc->sc_type = TWL_DEVICE_6025; in twl_probe()
366 sc->sc_type = TWL_DEVICE_4030; in twl_probe()
368 if (sc->sc_type != TWL_DEVICE_UNKNOWN) in twl_probe()
371 /* Slide to the next sub-string. */ in twl_probe()
374 len -= l; in twl_probe()
377 switch (sc->sc_type) { in twl_probe()
401 sc->sc_dev = dev; in twl_attach()
405 /* We have to wait until interrupts are enabled. I2C read and write in twl_attach()
408 sc->sc_scan_hook.ich_func = twl_scan; in twl_attach()
409 sc->sc_scan_hook.ich_arg = dev; in twl_attach()
411 if (config_intrhook_establish(&sc->sc_scan_hook) != 0) in twl_attach()
415 if ((sc->sc_vreg = device_add_child(dev, "twl_vreg", -1)) == NULL) in twl_attach()
417 if ((sc->sc_clks = device_add_child(dev, "twl_clks", -1)) == NULL) in twl_attach()