diff mbox series

[1/5] i2c: core: Pick i2c bus number from ACPI if present

Message ID be5cd69c7c58d44ca119d4ca692d95a2ae924533.1663835855.git.zhoubinbin@loongson.cn
State New
Headers show
Series i2c: ls2x: Add support for the Loongson-2K/LS7A I2C | expand

Commit Message

Binbin Zhou Sept. 22, 2022, 11:39 a.m. UTC
Under LoongARCH based on ACPI(such as Loongson-3A + LS7A), the ls2x i2c
driver obtains the i2c bus number from ACPI table.

Similar to the DT-base system, this is also a static bus number.

Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
---
 drivers/i2c/i2c-core-base.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

Comments

kernel test robot Sept. 26, 2022, 6:02 a.m. UTC | #1
Hi Binbin,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on wsa/i2c/for-next]
[also build test WARNING on linus/master v6.0-rc7 next-20220923]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Binbin-Zhou/i2c-ls2x-Add-support-for-the-Loongson-2K-LS7A-I2C/20220922-194252
base:   https://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git i2c/for-next
config: x86_64-randconfig-m001
compiler: gcc-11 (Debian 11.3.0-5) 11.3.0

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>

New smatch warnings:
drivers/i2c/i2c-core-base.c:1563 i2c_add_adapter() warn: always true condition '(id >= 0) => (0-u64max >= 0)'

Old smatch warnings:
drivers/i2c/i2c-core-base.c:1570 i2c_add_adapter() warn: always true condition '(id >= 0) => (0-u64max >= 0)'

vim +1563 drivers/i2c/i2c-core-base.c

ee5c27440cc24d drivers/i2c/i2c-core.c      Doug Anderson  2013-03-01  1540  
6e13e641841833 drivers/i2c/i2c-core.c      David Brownell 2007-05-01  1541  /**
6e13e641841833 drivers/i2c/i2c-core.c      David Brownell 2007-05-01  1542   * i2c_add_adapter - declare i2c adapter, use dynamic bus number
6e13e641841833 drivers/i2c/i2c-core.c      David Brownell 2007-05-01  1543   * @adapter: the adapter to add
d64f73be1b59b9 drivers/i2c/i2c-core.c      David Brownell 2007-07-12  1544   * Context: can sleep
6e13e641841833 drivers/i2c/i2c-core.c      David Brownell 2007-05-01  1545   *
6e13e641841833 drivers/i2c/i2c-core.c      David Brownell 2007-05-01  1546   * This routine is used to declare an I2C adapter when its bus number
ee5c27440cc24d drivers/i2c/i2c-core.c      Doug Anderson  2013-03-01  1547   * doesn't matter or when its bus number is specified by an dt alias.
ee5c27440cc24d drivers/i2c/i2c-core.c      Doug Anderson  2013-03-01  1548   * Examples of bases when the bus number doesn't matter: I2C adapters
ee5c27440cc24d drivers/i2c/i2c-core.c      Doug Anderson  2013-03-01  1549   * dynamically added by USB links or PCI plugin cards.
6e13e641841833 drivers/i2c/i2c-core.c      David Brownell 2007-05-01  1550   *
6e13e641841833 drivers/i2c/i2c-core.c      David Brownell 2007-05-01  1551   * When this returns zero, a new bus number was allocated and stored
6e13e641841833 drivers/i2c/i2c-core.c      David Brownell 2007-05-01  1552   * in adap->nr, and the specified adapter became available for clients.
6e13e641841833 drivers/i2c/i2c-core.c      David Brownell 2007-05-01  1553   * Otherwise, a negative errno value is returned.
6e13e641841833 drivers/i2c/i2c-core.c      David Brownell 2007-05-01  1554   */
6e13e641841833 drivers/i2c/i2c-core.c      David Brownell 2007-05-01  1555  int i2c_add_adapter(struct i2c_adapter *adapter)
6e13e641841833 drivers/i2c/i2c-core.c      David Brownell 2007-05-01  1556  {
ee5c27440cc24d drivers/i2c/i2c-core.c      Doug Anderson  2013-03-01  1557  	struct device *dev = &adapter->dev;
749fc796eb66dc drivers/i2c/i2c-core-base.c Binbin Zhou    2022-09-22  1558  	acpi_status status;
749fc796eb66dc drivers/i2c/i2c-core-base.c Binbin Zhou    2022-09-22  1559  	unsigned long long id;
6e13e641841833 drivers/i2c/i2c-core.c      David Brownell 2007-05-01  1560  
ee5c27440cc24d drivers/i2c/i2c-core.c      Doug Anderson  2013-03-01  1561  	if (dev->of_node) {
ee5c27440cc24d drivers/i2c/i2c-core.c      Doug Anderson  2013-03-01  1562  		id = of_alias_get_id(dev->of_node, "i2c");
ee5c27440cc24d drivers/i2c/i2c-core.c      Doug Anderson  2013-03-01 @1563  		if (id >= 0) {
ee5c27440cc24d drivers/i2c/i2c-core.c      Doug Anderson  2013-03-01  1564  			adapter->nr = id;
ee5c27440cc24d drivers/i2c/i2c-core.c      Doug Anderson  2013-03-01  1565  			return __i2c_add_numbered_adapter(adapter);
ee5c27440cc24d drivers/i2c/i2c-core.c      Doug Anderson  2013-03-01  1566  		}
749fc796eb66dc drivers/i2c/i2c-core-base.c Binbin Zhou    2022-09-22  1567  	} else if (dev->parent->fwnode) {
749fc796eb66dc drivers/i2c/i2c-core-base.c Binbin Zhou    2022-09-22  1568  		status = acpi_evaluate_integer(ACPI_HANDLE(dev->parent),
749fc796eb66dc drivers/i2c/i2c-core-base.c Binbin Zhou    2022-09-22  1569  						"_UID", NULL, &id);
749fc796eb66dc drivers/i2c/i2c-core-base.c Binbin Zhou    2022-09-22  1570  		if (ACPI_SUCCESS(status) && (id >= 0)) {
749fc796eb66dc drivers/i2c/i2c-core-base.c Binbin Zhou    2022-09-22  1571  			adapter->nr = id;
749fc796eb66dc drivers/i2c/i2c-core-base.c Binbin Zhou    2022-09-22  1572  			return __i2c_add_numbered_adapter(adapter);
749fc796eb66dc drivers/i2c/i2c-core-base.c Binbin Zhou    2022-09-22  1573  		}
ee5c27440cc24d drivers/i2c/i2c-core.c      Doug Anderson  2013-03-01  1574  	}
ee5c27440cc24d drivers/i2c/i2c-core.c      Doug Anderson  2013-03-01  1575  
caada32afe0d18 drivers/i2c/i2c-core.c      Jean Delvare   2008-01-27  1576  	mutex_lock(&core_lock);
4ae42b0ff0f999 drivers/i2c/i2c-core.c      Tejun Heo      2013-02-27  1577  	id = idr_alloc(&i2c_adapter_idr, adapter,
4ae42b0ff0f999 drivers/i2c/i2c-core.c      Tejun Heo      2013-02-27  1578  		       __i2c_first_dynamic_bus_num, 0, GFP_KERNEL);
caada32afe0d18 drivers/i2c/i2c-core.c      Jean Delvare   2008-01-27  1579  	mutex_unlock(&core_lock);
84d0b61773c7af drivers/i2c/i2c-core.c      Wolfram Sang   2016-07-09  1580  	if (WARN(id < 0, "couldn't get idr"))
4ae42b0ff0f999 drivers/i2c/i2c-core.c      Tejun Heo      2013-02-27  1581  		return id;
6e13e641841833 drivers/i2c/i2c-core.c      David Brownell 2007-05-01  1582  
6e13e641841833 drivers/i2c/i2c-core.c      David Brownell 2007-05-01  1583  	adapter->nr = id;
4ae42b0ff0f999 drivers/i2c/i2c-core.c      Tejun Heo      2013-02-27  1584  
6e13e641841833 drivers/i2c/i2c-core.c      David Brownell 2007-05-01  1585  	return i2c_register_adapter(adapter);
6e13e641841833 drivers/i2c/i2c-core.c      David Brownell 2007-05-01  1586  }
6e13e641841833 drivers/i2c/i2c-core.c      David Brownell 2007-05-01  1587  EXPORT_SYMBOL(i2c_add_adapter);
6e13e641841833 drivers/i2c/i2c-core.c      David Brownell 2007-05-01  1588
diff mbox series

Patch

diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index 91007558bcb2..ffab4cc2c6ba 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -1559,7 +1559,8 @@  static int __i2c_add_numbered_adapter(struct i2c_adapter *adap)
 int i2c_add_adapter(struct i2c_adapter *adapter)
 {
 	struct device *dev = &adapter->dev;
-	int id;
+	acpi_status status;
+	unsigned long long id;
 
 	if (dev->of_node) {
 		id = of_alias_get_id(dev->of_node, "i2c");
@@ -1567,6 +1568,13 @@  int i2c_add_adapter(struct i2c_adapter *adapter)
 			adapter->nr = id;
 			return __i2c_add_numbered_adapter(adapter);
 		}
+	} else if (dev->parent->fwnode) {
+		status = acpi_evaluate_integer(ACPI_HANDLE(dev->parent),
+						"_UID", NULL, &id);
+		if (ACPI_SUCCESS(status) && (id >= 0)) {
+			adapter->nr = id;
+			return __i2c_add_numbered_adapter(adapter);
+		}
 	}
 
 	mutex_lock(&core_lock);