From patchwork Wed Jun 4 12:09:56 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 355877 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 6CC6A14009E for ; Wed, 4 Jun 2014 22:11:00 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752960AbaFDMKb (ORCPT ); Wed, 4 Jun 2014 08:10:31 -0400 Received: from mail-ie0-f171.google.com ([209.85.223.171]:39010 "EHLO mail-ie0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752938AbaFDMK3 (ORCPT ); Wed, 4 Jun 2014 08:10:29 -0400 Received: by mail-ie0-f171.google.com with SMTP id to1so7176569ieb.30 for ; Wed, 04 Jun 2014 05:10:28 -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=MsUFY7xHBMIxBHzvvEcAhH8Yx1fikcP9C76NsHxU3I8=; b=b5xH9qwLjG9zJMvFWC7rAon5gyzNQuAMnxlyHyiPlqAWCY6pb7sBNfaQwsaEzmb/e2 ZhZn2pME/Dd4fYJiKtpZnY8/+Ol5ICrH3z0wlWunphXNlXKXPDt7xWlOfo6fCEuZ3+KN lNqLi0qmnYqTWYeup9ug1GrvhpjnEAzhJOct3gZ6PomiFkeptQdVcRI4P0/PsWBbSXr5 AwGVk85xMM+V6biB9eM3BVFQHvqjDTQe8LUZYZZHRC/Amj+M/ZnqRPEaVvG1c37RI636 RtmUIHR+OeUs+bkbBeVnCC0AtrhDDpzL9YB6qZkOwfOyAxZG4Zx0IBpWn3BF6wYLmRjR NOSw== X-Gm-Message-State: ALoCoQlzqQQCbSAsFzKxraTFybH76ka5pZdzxmBO9zA9tmrZXLpTpijk0VAg4UM1aEB7orT+yOGU X-Received: by 10.50.254.132 with SMTP id ai4mr6588677igd.30.1401883828606; Wed, 04 Jun 2014 05:10:28 -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 on9sm10028136igb.11.2014.06.04.05.10.26 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 04 Jun 2014 05:10:28 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: wsa@the-dreams.de, grant.likely@linaro.org, linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, linus.walleij@linaro.org, Lee Jones Subject: [PATCH 7/7] OF/ACPI/I2C: Add generic match function for the aforementioned systems Date: Wed, 4 Jun 2014 13:09:56 +0100 Message-Id: <1401883796-17841-8-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1401883796-17841-1-git-send-email-lee.jones@linaro.org> References: <1401883796-17841-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 this is a helper function for the I2C subsystem to aid the matching of non-standard compatible strings and devices which use DT and/or ACPI, but do not supply any nodes (see: [1] Method 4). However, it has been made more generic as it can be used to only make one call for drivers which support any mixture of OF, ACPI and/or I2C matching. The initial aim is for of_match_device() to be replaced by this call in all I2C device drivers. [1] Documentation/i2c/instantiating-devices Signed-off-by: Lee Jones --- include/linux/match.h | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 include/linux/match.h diff --git a/include/linux/match.h b/include/linux/match.h new file mode 100644 index 0000000..20a08e2 --- /dev/null +++ b/include/linux/match.h @@ -0,0 +1,40 @@ +#include +#include +#include + +static void *device_match(struct device *dev) +{ + struct device_driver *driver = dev->driver; + + if (!driver) + return NULL; + + /* Attempt an OF style match */ + if (IS_ENABLED(CONFIG_OF)) { + const struct of_device_id *of_match = + i2c_of_match_device(driver->of_match_table, dev); + if (of_match) + return (void *)of_match; + } + + /* Then ACPI style match */ + if (IS_ENABLED(CONFIG_ACPI)) { + const struct acpi_device_id *acpi_match = + acpi_match_device(driver->acpi_match_table, dev); + if (acpi_match) + return (void *)acpi_match; + } + + /* Finally an I2C match */ + if (IS_ENABLED(CONFIG_I2C)) { + struct i2c_client *client = i2c_verify_client(dev); + struct i2c_driver *i2c_drv = to_i2c_driver(driver); + struct i2c_device_id *i2c_match; + + i2c_match = i2c_match_id(i2c_drv->id_table, client); + if (i2c_match) + return (void *)i2c_match; + } + + return NULL; +}