Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756200AbbESOE1 (ORCPT ); Tue, 19 May 2015 10:04:27 -0400 Received: from mga01.intel.com ([192.55.52.88]:56956 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755925AbbESOEZ (ORCPT ); Tue, 19 May 2015 10:04:25 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,458,1427785200"; d="scan'208";a="573656282" From: Robert Dolca To: linux-i2c@vger.kernel.org, linux-acpi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Wolfram Sang , "Rafael J. Wysocki" , Len Brown , Daniel Baluta , Robert Dolca Subject: [PATCH RFC] i2c: Use ID table to detect ACPI I2C devices Date: Tue, 19 May 2015 17:03:29 +0300 Message-Id: <1432044209-27858-1-git-send-email-robert.dolca@intel.com> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2048 Lines: 57 For i2c devices enumerated with ACPI you need to declare both acpi_match_table and id_table. When using ACPI, the i2c_device_id structure supplied to the probe function is null and you have to handle this case in the driver. The current name for the i2c client when using ACPI is "HID:UID" where the UID has 7 or 8 characters and the UID has 2 characters. The UID is not relevant for identifying the chip so it does not have any practical purpose. Modifying i2c_match_id we make the comparison by ignoring the UID from the client name when the device was discovered using ACPI. The comparison is case insensitive because the ACPI names are uppercase and the DT and ID table names are lowercase. It would not make sense to have two different chips with the same name and the only diference being the capitalized letters. With these changes the probe function gets a valid i2c_device_id and the driver doesn't have to declare acpi_match_table. Signed-off-by: Robert Dolca --- drivers/i2c/i2c-core.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index fec0e0d..c9b30b7 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c @@ -447,8 +447,18 @@ static inline int acpi_i2c_install_space_handler(struct i2c_adapter *adapter) static const struct i2c_device_id *i2c_match_id(const struct i2c_device_id *id, const struct i2c_client *client) { + char name[I2C_NAME_SIZE], *c; + + strlcpy(name, client->name, sizeof(name)); + + if (ACPI_HANDLE(&client->dev)) { + c = strchr(name, ':'); + if (c) + *c = 0; + } + while (id->name[0]) { - if (strcmp(client->name, id->name) == 0) + if (strncasecmp(name, id->name, sizeof(id->name)) == 0) return id; id++; } -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/