Skip to content

Commit 2a934b3

Browse files
committed
Merge tag 'i3c/for-5.10' of git://git.kernel.org/pub/scm/linux/kernel/git/i3c/linux
Pull i3c updates from Boris Brezillon: - Fix DAA for the pre-reserved address case - Fix an error path in the cadence driver * tag 'i3c/for-5.10' of git://git.kernel.org/pub/scm/linux/kernel/git/i3c/linux: i3c: master: Fix error return in cdns_i3c_master_probe() i3c: master: fix for SETDASA and DAA process i3c: master add i3c_master_attach_boardinfo to preserve boardinfo
2 parents 6f78b9a + abea14b commit 2a934b3

File tree

2 files changed

+94
-54
lines changed

2 files changed

+94
-54
lines changed

drivers/i3c/master.c

Lines changed: 91 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,7 +1373,9 @@ static int i3c_master_reattach_i3c_dev(struct i3c_dev_desc *dev,
13731373
enum i3c_addr_slot_status status;
13741374
int ret;
13751375

1376-
if (dev->info.dyn_addr != old_dyn_addr) {
1376+
if (dev->info.dyn_addr != old_dyn_addr &&
1377+
(!dev->boardinfo ||
1378+
dev->info.dyn_addr != dev->boardinfo->init_dyn_addr)) {
13771379
status = i3c_bus_get_addr_slot_status(&master->bus,
13781380
dev->info.dyn_addr);
13791381
if (status != I3C_ADDR_SLOT_FREE)
@@ -1432,33 +1434,49 @@ static void i3c_master_detach_i2c_dev(struct i2c_dev_desc *dev)
14321434
master->ops->detach_i2c_dev(dev);
14331435
}
14341436

1435-
static void i3c_master_pre_assign_dyn_addr(struct i3c_dev_desc *dev)
1437+
static int i3c_master_early_i3c_dev_add(struct i3c_master_controller *master,
1438+
struct i3c_dev_boardinfo *boardinfo)
14361439
{
1437-
struct i3c_master_controller *master = i3c_dev_get_master(dev);
1440+
struct i3c_device_info info = {
1441+
.static_addr = boardinfo->static_addr,
1442+
};
1443+
struct i3c_dev_desc *i3cdev;
14381444
int ret;
14391445

1440-
if (!dev->boardinfo || !dev->boardinfo->init_dyn_addr ||
1441-
!dev->boardinfo->static_addr)
1442-
return;
1446+
i3cdev = i3c_master_alloc_i3c_dev(master, &info);
1447+
if (IS_ERR(i3cdev))
1448+
return -ENOMEM;
1449+
1450+
i3cdev->boardinfo = boardinfo;
1451+
1452+
ret = i3c_master_attach_i3c_dev(master, i3cdev);
1453+
if (ret)
1454+
goto err_free_dev;
14431455

1444-
ret = i3c_master_setdasa_locked(master, dev->info.static_addr,
1445-
dev->boardinfo->init_dyn_addr);
1456+
ret = i3c_master_setdasa_locked(master, i3cdev->info.static_addr,
1457+
i3cdev->boardinfo->init_dyn_addr);
14461458
if (ret)
1447-
return;
1459+
goto err_detach_dev;
14481460

1449-
dev->info.dyn_addr = dev->boardinfo->init_dyn_addr;
1450-
ret = i3c_master_reattach_i3c_dev(dev, 0);
1461+
i3cdev->info.dyn_addr = i3cdev->boardinfo->init_dyn_addr;
1462+
ret = i3c_master_reattach_i3c_dev(i3cdev, 0);
14511463
if (ret)
14521464
goto err_rstdaa;
14531465

1454-
ret = i3c_master_retrieve_dev_info(dev);
1466+
ret = i3c_master_retrieve_dev_info(i3cdev);
14551467
if (ret)
14561468
goto err_rstdaa;
14571469

1458-
return;
1470+
return 0;
14591471

14601472
err_rstdaa:
1461-
i3c_master_rstdaa_locked(master, dev->boardinfo->init_dyn_addr);
1473+
i3c_master_rstdaa_locked(master, i3cdev->boardinfo->init_dyn_addr);
1474+
err_detach_dev:
1475+
i3c_master_detach_i3c_dev(i3cdev);
1476+
err_free_dev:
1477+
i3c_master_free_i3c_dev(i3cdev);
1478+
1479+
return ret;
14621480
}
14631481

14641482
static void
@@ -1625,8 +1643,8 @@ static void i3c_master_detach_free_devs(struct i3c_master_controller *master)
16251643
* This function is following all initialisation steps described in the I3C
16261644
* specification:
16271645
*
1628-
* 1. Attach I2C and statically defined I3C devs to the master so that the
1629-
* master can fill its internal device table appropriately
1646+
* 1. Attach I2C devs to the master so that the master can fill its internal
1647+
* device table appropriately
16301648
*
16311649
* 2. Call &i3c_master_controller_ops->bus_init() method to initialize
16321650
* the master controller. That's usually where the bus mode is selected
@@ -1638,8 +1656,10 @@ static void i3c_master_detach_free_devs(struct i3c_master_controller *master)
16381656
*
16391657
* 4. Disable all slave events.
16401658
*
1641-
* 5. Pre-assign dynamic addresses requested by the FW with SETDASA for I3C
1642-
* devices that have a static address
1659+
* 5. Reserve address slots for I3C devices with init_dyn_addr. And if devices
1660+
* also have static_addr, try to pre-assign dynamic addresses requested by
1661+
* the FW with SETDASA and attach corresponding statically defined I3C
1662+
* devices to the master.
16431663
*
16441664
* 6. Do a DAA (Dynamic Address Assignment) to assign dynamic addresses to all
16451665
* remaining I3C devices
@@ -1653,7 +1673,6 @@ static int i3c_master_bus_init(struct i3c_master_controller *master)
16531673
enum i3c_addr_slot_status status;
16541674
struct i2c_dev_boardinfo *i2cboardinfo;
16551675
struct i3c_dev_boardinfo *i3cboardinfo;
1656-
struct i3c_dev_desc *i3cdev;
16571676
struct i2c_dev_desc *i2cdev;
16581677
int ret;
16591678

@@ -1685,34 +1704,6 @@ static int i3c_master_bus_init(struct i3c_master_controller *master)
16851704
goto err_detach_devs;
16861705
}
16871706
}
1688-
list_for_each_entry(i3cboardinfo, &master->boardinfo.i3c, node) {
1689-
struct i3c_device_info info = {
1690-
.static_addr = i3cboardinfo->static_addr,
1691-
};
1692-
1693-
if (i3cboardinfo->init_dyn_addr) {
1694-
status = i3c_bus_get_addr_slot_status(&master->bus,
1695-
i3cboardinfo->init_dyn_addr);
1696-
if (status != I3C_ADDR_SLOT_FREE) {
1697-
ret = -EBUSY;
1698-
goto err_detach_devs;
1699-
}
1700-
}
1701-
1702-
i3cdev = i3c_master_alloc_i3c_dev(master, &info);
1703-
if (IS_ERR(i3cdev)) {
1704-
ret = PTR_ERR(i3cdev);
1705-
goto err_detach_devs;
1706-
}
1707-
1708-
i3cdev->boardinfo = i3cboardinfo;
1709-
1710-
ret = i3c_master_attach_i3c_dev(master, i3cdev);
1711-
if (ret) {
1712-
i3c_master_free_i3c_dev(i3cdev);
1713-
goto err_detach_devs;
1714-
}
1715-
}
17161707

17171708
/*
17181709
* Now execute the controller specific ->bus_init() routine, which
@@ -1749,11 +1740,43 @@ static int i3c_master_bus_init(struct i3c_master_controller *master)
17491740
goto err_bus_cleanup;
17501741

17511742
/*
1752-
* Pre-assign dynamic address and retrieve device information if
1753-
* needed.
1743+
* Reserve init_dyn_addr first, and then try to pre-assign dynamic
1744+
* address and retrieve device information if needed.
1745+
* In case pre-assign dynamic address fails, setting dynamic address to
1746+
* the requested init_dyn_addr is retried after DAA is done in
1747+
* i3c_master_add_i3c_dev_locked().
17541748
*/
1755-
i3c_bus_for_each_i3cdev(&master->bus, i3cdev)
1756-
i3c_master_pre_assign_dyn_addr(i3cdev);
1749+
list_for_each_entry(i3cboardinfo, &master->boardinfo.i3c, node) {
1750+
1751+
/*
1752+
* We don't reserve a dynamic address for devices that
1753+
* don't explicitly request one.
1754+
*/
1755+
if (!i3cboardinfo->init_dyn_addr)
1756+
continue;
1757+
1758+
ret = i3c_bus_get_addr_slot_status(&master->bus,
1759+
i3cboardinfo->init_dyn_addr);
1760+
if (ret != I3C_ADDR_SLOT_FREE) {
1761+
ret = -EBUSY;
1762+
goto err_rstdaa;
1763+
}
1764+
1765+
i3c_bus_set_addr_slot_status(&master->bus,
1766+
i3cboardinfo->init_dyn_addr,
1767+
I3C_ADDR_SLOT_I3C_DEV);
1768+
1769+
/*
1770+
* Only try to create/attach devices that have a static
1771+
* address. Other devices will be created/attached when
1772+
* DAA happens, and the requested dynamic address will
1773+
* be set using SETNEWDA once those devices become
1774+
* addressable.
1775+
*/
1776+
1777+
if (i3cboardinfo->static_addr)
1778+
i3c_master_early_i3c_dev_add(master, i3cboardinfo);
1779+
}
17571780

17581781
ret = i3c_master_do_daa(master);
17591782
if (ret)
@@ -1782,6 +1805,21 @@ static void i3c_master_bus_cleanup(struct i3c_master_controller *master)
17821805
i3c_master_detach_free_devs(master);
17831806
}
17841807

1808+
static void i3c_master_attach_boardinfo(struct i3c_dev_desc *i3cdev)
1809+
{
1810+
struct i3c_master_controller *master = i3cdev->common.master;
1811+
struct i3c_dev_boardinfo *i3cboardinfo;
1812+
1813+
list_for_each_entry(i3cboardinfo, &master->boardinfo.i3c, node) {
1814+
if (i3cdev->info.pid != i3cboardinfo->pid)
1815+
continue;
1816+
1817+
i3cdev->boardinfo = i3cboardinfo;
1818+
i3cdev->info.static_addr = i3cboardinfo->static_addr;
1819+
return;
1820+
}
1821+
}
1822+
17851823
static struct i3c_dev_desc *
17861824
i3c_master_search_i3c_dev_duplicate(struct i3c_dev_desc *refdev)
17871825
{
@@ -1837,10 +1875,10 @@ int i3c_master_add_i3c_dev_locked(struct i3c_master_controller *master,
18371875
if (ret)
18381876
goto err_detach_dev;
18391877

1878+
i3c_master_attach_boardinfo(newdev);
1879+
18401880
olddev = i3c_master_search_i3c_dev_duplicate(newdev);
18411881
if (olddev) {
1842-
newdev->boardinfo = olddev->boardinfo;
1843-
newdev->info.static_addr = olddev->info.static_addr;
18441882
newdev->dev = olddev->dev;
18451883
if (newdev->dev)
18461884
newdev->dev->desc = newdev;

drivers/i3c/master/i3c-master-cdns.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1635,8 +1635,10 @@ static int cdns_i3c_master_probe(struct platform_device *pdev)
16351635
master->ibi.slots = devm_kcalloc(&pdev->dev, master->ibi.num_slots,
16361636
sizeof(*master->ibi.slots),
16371637
GFP_KERNEL);
1638-
if (!master->ibi.slots)
1638+
if (!master->ibi.slots) {
1639+
ret = -ENOMEM;
16391640
goto err_disable_sysclk;
1641+
}
16401642

16411643
writel(IBIR_THR(1), master->regs + CMD_IBI_THR_CTRL);
16421644
writel(MST_INT_IBIR_THR, master->regs + MST_IER);

0 commit comments

Comments
 (0)