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: 31352 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f200.google.com (mail-ve0-f200.google.com [209.85.128.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 9F93E203AC for ; Wed, 4 Jun 2014 12:10:40 +0000 (UTC) Received: by mail-ve0-f200.google.com with SMTP id pa12sf37053386veb.11 for ; Wed, 04 Jun 2014 05:10:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=MsUFY7xHBMIxBHzvvEcAhH8Yx1fikcP9C76NsHxU3I8=; b=lJi8LJEx6zf4x34B4VMy8wzk0y/terl1unP4mZsD4BhxaPRudd/g9GyL2IgIqLQJxV DbRlMrFKfiaUc0B9vpAUhZL8ywbTzEdEGAZHilI+qvVw6UmoaA6m57rj7drzqiI6HrxI kE8mX4Zx/k/FAsJybvAd+e4qgDH/qeQ57arY0zrF+S9SAyaPUKtdXIZFHTali3o0TjKg Hd1rbhNDMvMZRo1TyK/fWgAJtwsLfjoc7tvfBaerN1H0Mmy0KrA45PMLxU0MkWPeeayx mE2YwrTg9aV7HENne8fIkMuzWEre8z56jeh1XjuyIBRxGYnjDbJAKnOuVkIAwAp8cPet ML2g== X-Gm-Message-State: ALoCoQkXE6VGsw9bvAROXuMEQNejLO3DMWmfqcwPbssz7eFntnpAsZepTULiCEMJ7limChE8S5M9 X-Received: by 10.224.26.76 with SMTP id d12mr12194444qac.3.1401883840226; Wed, 04 Jun 2014 05:10:40 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.50.16 with SMTP id r16ls3181742qga.71.gmail; Wed, 04 Jun 2014 05:10:40 -0700 (PDT) X-Received: by 10.52.190.138 with SMTP id gq10mr11874720vdc.47.1401883840128; Wed, 04 Jun 2014 05:10:40 -0700 (PDT) Received: from mail-ve0-f179.google.com (mail-ve0-f179.google.com [209.85.128.179]) by mx.google.com with ESMTPS id g6si1365168vez.71.2014.06.04.05.10.40 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 04 Jun 2014 05:10:40 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.179 as permitted sender) client-ip=209.85.128.179; Received: by mail-ve0-f179.google.com with SMTP id oy12so8538701veb.24 for ; Wed, 04 Jun 2014 05:10:40 -0700 (PDT) X-Received: by 10.220.15.8 with SMTP id i8mr1261652vca.45.1401883840066; Wed, 04 Jun 2014 05:10:40 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.221.54.6 with SMTP id vs6csp39902vcb; Wed, 4 Jun 2014 05:10:39 -0700 (PDT) X-Received: by 10.14.53.66 with SMTP id f42mr689714eec.70.1401883838932; Wed, 04 Jun 2014 05:10:38 -0700 (PDT) Received: from mail-ig0-f171.google.com (mail-ig0-f171.google.com [209.85.213.171]) by mx.google.com with ESMTPS id cz7si4716044icc.103.2014.06.04.05.10.28 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 04 Jun 2014 05:10:28 -0700 (PDT) Received-SPF: pass (google.com: domain of lee.jones@linaro.org designates 209.85.213.171 as permitted sender) client-ip=209.85.213.171; Received: by mail-ig0-f171.google.com with SMTP id c1so6163263igq.16 for ; Wed, 04 Jun 2014 05:10:28 -0700 (PDT) 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> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: lee.jones@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.179 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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; +}