Lines Matching +full:primary +full:- +full:pmic
1 /*-
27 * Allwinner RSB (Reduced Serial Bus) and P2WI (Push-Pull Two Wire Interface)
103 { "allwinner,sun6i-a31-p2wi", A31_P2WI },
104 { "allwinner,sun8i-a23-rsb", A23_RSB },
110 { -1, 0 }
114 * Device address to Run-time address mappings.
116 * Run-time address (RTA) is an 8-bit value used to address the device during
120 * Allwinner uses RTA 0x2d for the primary PMIC, 0x3a for the secondary PMIC,
147 #define RSB_LOCK(sc) mtx_lock(&(sc)->mtx)
148 #define RSB_UNLOCK(sc) mtx_unlock(&(sc)->mtx)
149 #define RSB_ASSERT_LOCKED(sc) mtx_assert(&(sc)->mtx, MA_OWNED)
150 #define RSB_READ(sc, reg) bus_read_4((sc)->res, (reg))
151 #define RSB_WRITE(sc, reg, val) bus_write_4((sc)->res, (reg), (val))
169 /* Write soft-reset bit and wait for it to self-clear. */ in rsb_reset()
171 for (retry = RSB_RESET_RETRY; retry > 0; retry--) in rsb_reset()
193 val |= ((uint32_t)buf[n] << ((n - off) * NBBY)); in rsb_encode()
204 buf[n] = (val >> ((n - off) * NBBY)) & 0xff; in rsb_decode()
222 for (retry = RSB_I2C_TIMEOUT; retry > 0; retry--) { in rsb_start()
223 sc->status |= RSB_READ(sc, RSB_INTS); in rsb_start()
224 if ((sc->status & INT_TRANS_OVER) != 0) { in rsb_start()
230 if (error == 0 && (sc->status & INT_TRANS_OVER) == 0) { in rsb_start()
232 sc->status); in rsb_start()
251 /* Lookup run-time address for given device address */ in rsb_set_rta()
262 /* Set run-time address */ in rsb_set_rta()
297 if (sc->type == A23_RSB) { in rsb_transfer()
330 while (sc->busy) in rsb_transfer()
331 mtx_sleep(sc, &sc->mtx, 0, "i2cbuswait", 0); in rsb_transfer()
332 sc->busy = 1; in rsb_transfer()
333 sc->status = 0; in rsb_transfer()
335 /* Select current run-time address if necessary */ in rsb_transfer()
336 if (sc->type == A23_RSB) { in rsb_transfer()
338 if (sc->cur_addr != device_addr) { in rsb_transfer()
342 sc->cur_addr = device_addr; in rsb_transfer()
343 sc->status = 0; in rsb_transfer()
361 if (sc->type == A23_RSB) in rsb_transfer()
365 dlen = msgs[0].len - 1; in rsb_transfer()
382 sc->msg = NULL; in rsb_transfer()
383 sc->busy = 0; in rsb_transfer()
396 switch (ofw_bus_search_compatible(dev, compat_data)->ocd_data) { in rsb_probe()
417 mtx_init(&sc->mtx, device_get_nameunit(dev), "rsb", MTX_DEF); in rsb_attach()
419 sc->type = ofw_bus_search_compatible(dev, compat_data)->ocd_data; in rsb_attach()
421 if (clk_get_by_ofw_index(dev, 0, 0, &sc->clk) == 0) { in rsb_attach()
422 error = clk_enable(sc->clk); in rsb_attach()
428 if (hwreset_get_by_ofw_idx(dev, 0, 0, &sc->rst) == 0) { in rsb_attach()
429 error = hwreset_deassert(sc->rst); in rsb_attach()
431 device_printf(dev, "cannot de-assert reset\n"); in rsb_attach()
436 if (bus_alloc_resources(dev, rsb_spec, &sc->res) != 0) { in rsb_attach()
442 /* Set the PMIC into RSB mode as ATF might have leave it in I2C mode */ in rsb_attach()
445 sc->iicbus = device_add_child(dev, "iicbus", DEVICE_UNIT_ANY); in rsb_attach()
446 if (sc->iicbus == NULL) { in rsb_attach()
457 bus_release_resources(dev, rsb_spec, &sc->res); in rsb_attach()
458 if (sc->rst != NULL) in rsb_attach()
459 hwreset_release(sc->rst); in rsb_attach()
460 if (sc->clk != NULL) in rsb_attach()
461 clk_release(sc->clk); in rsb_attach()
462 mtx_destroy(&sc->mtx); in rsb_attach()