From patchwork Fri May 30 12:26:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 354124 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id EA3651400D8 for ; Fri, 30 May 2014 22:27:29 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754565AbaE3M0x (ORCPT ); Fri, 30 May 2014 08:26:53 -0400 Received: from mail-ig0-f181.google.com ([209.85.213.181]:64389 "EHLO mail-ig0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754283AbaE3M0t (ORCPT ); Fri, 30 May 2014 08:26:49 -0400 Received: by mail-ig0-f181.google.com with SMTP id h3so732791igd.2 for ; Fri, 30 May 2014 05:26:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=zZG/CeMm18Vl7iBHWp25LT0ds3QYltl3cUhiB9uppX0=; b=kOPG9palF1pFQPJPviGP19h1cH52NVcUps5uTdkrSDlKbzQq/EIkschc3+rbyXB5uN bLOn91nFxNyv12WHp01wSU5/pPfEn/+tZIckwUJc++O+fyqZTcJvWiA9L0qZeg+i/o8X 2TXNA+17C7lMopPMGyu3kvTpc2Q5H8VkY2Ys+2oY+64shU0CFtFw0oT0HHlFNQBegEAl MAbeyE3chrJS1ljsvm6/ZSwMeoAbnL9O78QNs2GK1cOLMNJhDXQj6Wc8v6lAVkKxsZQt ksI7vy4cGed/pqHxMrOjSLJbaG6w/P9FknsmUVCFC1r7EzAfgwlSJvaXMtMG8ZD0hmZL PDWg== X-Gm-Message-State: ALoCoQn+MSiLEdMMt4jlvBQ+XvcYsWv1Yq6D7XvOJRlyxdmHsm7xVpSFTKBxrDkEz+vPxnWx6oQA X-Received: by 10.50.30.6 with SMTP id o6mr5047166igh.43.1401452809248; Fri, 30 May 2014 05:26:49 -0700 (PDT) Received: from localhost.localdomain (host109-148-113-200.range109-148.btcentralplus.com. [109.148.113.200]) by mx.google.com with ESMTPSA id g2sm5152788igc.12.2014.05.30.05.26.47 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 30 May 2014 05:26:48 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, wsa@the-dreams.de Cc: grant.likely@linaro.org, linus.walleij@linaro.org, linux-i2c@vger.kernel.org, Lee Jones Subject: [PATCH] i2c: Make I2C ID tables non-mandatory for DT'ed and/or ACPI'ed devices Date: Fri, 30 May 2014 13:26:36 +0100 Message-Id: <1401452797-29521-2-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1401452797-29521-1-git-send-email-lee.jones@linaro.org> References: <1401452797-29521-1-git-send-email-lee.jones@linaro.org> Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Currently the I2C framework insists on devices supplying an I2C ID table. Many of the devices which do so unnecessarily adding quite a few wasted lines to kernel code. This patch allows drivers a means to 'not' supply the aforementioned table and match on either DT and/or ACPI match tables instead. Signed-off-by: Lee Jones --- drivers/i2c/i2c-core.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 7c7f4b8..703da9e 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c @@ -260,13 +260,25 @@ static int i2c_device_probe(struct device *dev) { struct i2c_client *client = i2c_verify_client(dev); struct i2c_driver *driver; + const struct of_device_id *of_match = dev->driver->of_match_table; + const struct acpi_device_id *acpi_match = dev->driver->acpi_match_table; int status; if (!client) return 0; driver = to_i2c_driver(dev->driver); - if (!driver->probe || !driver->id_table) + if (!driver->probe) + return -EINVAL; + + /* + * An I2C ID table is not madatory, if and only if, a suitable Device + * Tree and/or ACPI match table entry is supplied for the probing + * device. + */ + if (!driver->id_table && + !of_match_device(of_match, dev) && + !acpi_match_device(acpi_match, dev)) return -ENODEV; if (!device_can_wakeup(&client->dev)) @@ -275,7 +287,12 @@ static int i2c_device_probe(struct device *dev) dev_dbg(dev, "probe\n"); acpi_dev_pm_attach(&client->dev, true); - status = driver->probe(client, i2c_match_id(driver->id_table, client)); + + if (!driver->id_table) + status = driver->probe(client, NULL); + else + status = driver->probe(client, + i2c_match_id(driver->id_table, client)); if (status) acpi_dev_pm_detach(&client->dev, true);