i3c: master: cdns: Use for_each_set_bit()

This simplifies and standardizes slot manipulation code
by using for_each_set_bit() library function.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
This commit is contained in:
Andy Shevchenko 2019-07-25 23:51:45 +03:00 committed by Boris Brezillon
parent 91227632fc
commit fd3f8f3118
1 changed files with 10 additions and 16 deletions

View File

@ -903,7 +903,8 @@ static void cdns_i3c_master_upd_i3c_addr(struct i3c_dev_desc *dev)
static int cdns_i3c_master_get_rr_slot(struct cdns_i3c_master *master, static int cdns_i3c_master_get_rr_slot(struct cdns_i3c_master *master,
u8 dyn_addr) u8 dyn_addr)
{ {
u32 activedevs, rr; unsigned long activedevs;
u32 rr;
int i; int i;
if (!dyn_addr) { if (!dyn_addr) {
@ -913,13 +914,10 @@ static int cdns_i3c_master_get_rr_slot(struct cdns_i3c_master *master,
return ffs(master->free_rr_slots) - 1; return ffs(master->free_rr_slots) - 1;
} }
activedevs = readl(master->regs + DEVS_CTRL) & activedevs = readl(master->regs + DEVS_CTRL) & DEVS_CTRL_DEVS_ACTIVE_MASK;
DEVS_CTRL_DEVS_ACTIVE_MASK; activedevs &= ~BIT(0);
for (i = 1; i <= master->maxdevs; i++) {
if (!(BIT(i) & activedevs))
continue;
for_each_set_bit(i, &activedevs, master->maxdevs + 1) {
rr = readl(master->regs + DEV_ID_RR0(i)); rr = readl(master->regs + DEV_ID_RR0(i));
if (!(rr & DEV_ID_RR0_IS_I3C) || if (!(rr & DEV_ID_RR0_IS_I3C) ||
DEV_ID_RR0_GET_DEV_ADDR(rr) != dyn_addr) DEV_ID_RR0_GET_DEV_ADDR(rr) != dyn_addr)
@ -1126,18 +1124,16 @@ static void cdns_i3c_master_upd_i3c_scl_lim(struct cdns_i3c_master *master)
static int cdns_i3c_master_do_daa(struct i3c_master_controller *m) static int cdns_i3c_master_do_daa(struct i3c_master_controller *m)
{ {
struct cdns_i3c_master *master = to_cdns_i3c_master(m); struct cdns_i3c_master *master = to_cdns_i3c_master(m);
u32 olddevs, newdevs; unsigned long olddevs, newdevs;
int ret, slot; int ret, slot;
u8 addrs[MAX_DEVS] = { }; u8 addrs[MAX_DEVS] = { };
u8 last_addr = 0; u8 last_addr = 0;
olddevs = readl(master->regs + DEVS_CTRL) & DEVS_CTRL_DEVS_ACTIVE_MASK; olddevs = readl(master->regs + DEVS_CTRL) & DEVS_CTRL_DEVS_ACTIVE_MASK;
olddevs |= BIT(0);
/* Prepare RR slots before launching DAA. */ /* Prepare RR slots before launching DAA. */
for (slot = 1; slot <= master->maxdevs; slot++) { for_each_clear_bit(slot, &olddevs, master->maxdevs + 1) {
if (olddevs & BIT(slot))
continue;
ret = i3c_master_get_free_addr(m, last_addr + 1); ret = i3c_master_get_free_addr(m, last_addr + 1);
if (ret < 0) if (ret < 0)
return -ENOSPC; return -ENOSPC;
@ -1161,10 +1157,8 @@ static int cdns_i3c_master_do_daa(struct i3c_master_controller *m)
* Clear all retaining registers filled during DAA. We already * Clear all retaining registers filled during DAA. We already
* have the addressed assigned to them in the addrs array. * have the addressed assigned to them in the addrs array.
*/ */
for (slot = 1; slot <= master->maxdevs; slot++) { for_each_set_bit(slot, &newdevs, master->maxdevs + 1)
if (newdevs & BIT(slot))
i3c_master_add_i3c_dev_locked(m, addrs[slot]); i3c_master_add_i3c_dev_locked(m, addrs[slot]);
}
/* /*
* Clear slots that ended up not being used. Can be caused by I3C * Clear slots that ended up not being used. Can be caused by I3C