From patchwork Sun May 12 22:26:23 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 16873 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qe0-f70.google.com (mail-qe0-f70.google.com [209.85.128.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 587DE20DF3 for ; Sun, 12 May 2013 22:27:08 +0000 (UTC) Received: by mail-qe0-f70.google.com with SMTP id b10sf7703284qen.9 for ; Sun, 12 May 2013 15:26:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:mime-version:x-beenthere:x-received:received-spf :x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:x-received:from:to:cc:subject:date:message-id:x-mailer :x-gm-message-state:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:list-unsubscribe; bh=ySGeYzQaodYe3vNnKAezzh/De5p5ZKfzpFTnej3s4WY=; b=U2zPzT0B8KSthLVcA0NzfYBcYmkvK1qMbWzrup21Ls/FABkR1qocw6sNXGPL4L1MQH LIxCxM4+xaf5svP6OED5L2MnMPE8pvsfi8kEV6/WeMmTrczBKcNKyZYcqUjKSpkXKVDC J0ubi+VIyowjvGX6Ac31kBZYECAkME59U6iMw7GdceT9Em3jUWXYnXnZjsm+OP3SPEdB MPJA2BtCJHLWsYPg+EKA+C6mg32wo70ah7FbZpJMOtCcwEvb0RpsAzDyaIxVEgsCDpZi l33fS92J94oh20Y6sM63VbC5pnK8PyNCUAfcLbI+5pN4++9kqsveetEWG4fY9v3nyWKU 2ulg== X-Received: by 10.224.215.194 with SMTP id hf2mr17529396qab.0.1368397597181; Sun, 12 May 2013 15:26:37 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.41.7 with SMTP id b7ls2619281qel.12.gmail; Sun, 12 May 2013 15:26:36 -0700 (PDT) X-Received: by 10.220.112.198 with SMTP id x6mr8910618vcp.38.1368397596876; Sun, 12 May 2013 15:26:36 -0700 (PDT) Received: from mail-vb0-x22b.google.com (mail-vb0-x22b.google.com [2607:f8b0:400c:c02::22b]) by mx.google.com with ESMTPS id zp6si6949367vdb.80.2013.05.12.15.26.36 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 12 May 2013 15:26:36 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c02::22b is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=2607:f8b0:400c:c02::22b; Received: by mail-vb0-f43.google.com with SMTP id p14so4825413vbm.30 for ; Sun, 12 May 2013 15:26:36 -0700 (PDT) X-Received: by 10.58.144.170 with SMTP id sn10mr16661560veb.7.1368397596633; Sun, 12 May 2013 15:26:36 -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.220.217.15 with SMTP id hk15csp134902vcb; Sun, 12 May 2013 15:26:35 -0700 (PDT) X-Received: by 10.112.144.165 with SMTP id sn5mr11683487lbb.48.1368397595007; Sun, 12 May 2013 15:26:35 -0700 (PDT) Received: from mail-lb0-f180.google.com (mail-lb0-f180.google.com [209.85.217.180]) by mx.google.com with ESMTPS id s8si3769586lae.203.2013.05.12.15.26.33 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 12 May 2013 15:26:34 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.217.180 is neither permitted nor denied by best guess record for domain of linus.walleij@linaro.org) client-ip=209.85.217.180; Received: by mail-lb0-f180.google.com with SMTP id o10so220420lbi.25 for ; Sun, 12 May 2013 15:26:33 -0700 (PDT) X-Received: by 10.112.190.6 with SMTP id gm6mr11646849lbc.41.1368397593614; Sun, 12 May 2013 15:26:33 -0700 (PDT) Received: from localhost.localdomain (c83-249-208-225.bredband.comhem.se. [83.249.208.225]) by mx.google.com with ESMTPSA id jr19sm4685363lab.0.2013.05.12.15.26.31 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sun, 12 May 2013 15:26:32 -0700 (PDT) From: Linus Walleij To: Wolfram Sang , linux-i2c@vger.kernel.org, devicetree-discuss@lists.ozlabs.org Cc: Linus Walleij , Rob Herring , Grant Likely Subject: [PATCH] i2c: core: make it possible to match a pure device tree driver Date: Mon, 13 May 2013 00:26:23 +0200 Message-Id: <1368397583-22769-1-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 1.8.1.4 X-Gm-Message-State: ALoCoQmXxrMtu/GLjcJ7SS5v/5TGQ720J1dctfXqyLN/AmPIO00wHFuqQ9Pu7rhBo1SPqO22E7lg X-Original-Sender: linus.walleij@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 2607:f8b0:400c:c02::22b is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) 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: , This tries to address an issue found when writing an MFD driver for the Nomadik STw481x PMICs: as the platform is using device tree exclusively I want to specify the driver matching like this: static const struct of_device_id stw481x_match[] = { { .compatible = "st,stw4810", }, { .compatible = "st,stw4811", }, {}, }; static struct i2c_driver stw481x_driver = { .driver = { .name = "stw481x", .of_match_table = stw481x_match, }, .probe = stw481x_probe, .remove = stw481x_remove, }; However that turns out not to be possible: the I2C probe code is written so that the probe() call is always passed a match from i2c_match_id() using non-devicetree matches. This is probably why most devices using device tree for I2C clients currently will pass no .of_match_table *at all* but instead just use .id_table from struct i2c_driver to match the device. As you realize that means that the whole idea with compatible strings is discarded, and that is why we find strange device tree I2C device compatible strings like "product" instead of "vendor,product" as you could expect. Let's figure out how to fix this before the mess spreads. This patch will allow probeing devices with only an of_match_table as per above, and will pass NULL as the second argument to the probe() function. If the driver wants to deduce secondary info from the struct of_device_id .data field, it has to call of_match_device() on its own match table in the probe function device tree probe path. If drivers define both an .of_match_table *AND* a i2c_driver .id_table, the .of_match_table will take precedence, just as is done in the i2c_device_match() function in i2c-core.c. I2C devices probed from device tree should subsequently be fixed to handle the case where of_match_table() is used (I think none of them do that today), and platforms should fix their device trees to use compatible strings for I2C devices instead of setting the name to Linux device driver names as is done in multiple cases today. Cc: Rob Herring Cc: Grant Likely Signed-off-by: Linus Walleij --- I would need some device tree core people to confirm that I am on the right track with this. I was soooo confused when I found that .of_match_table could not be used with I2C devices... --- drivers/i2c/i2c-core.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 6b63cc7..30b5bb2 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c @@ -240,7 +240,7 @@ static int i2c_device_probe(struct device *dev) return 0; driver = to_i2c_driver(dev->driver); - if (!driver->probe || !driver->id_table) + if (!driver->probe || (!driver->id_table && !dev->driver->of_match_table)) return -ENODEV; client->driver = driver; if (!device_can_wakeup(&client->dev)) @@ -248,7 +248,12 @@ static int i2c_device_probe(struct device *dev) client->flags & I2C_CLIENT_WAKE); dev_dbg(dev, "probe\n"); - status = driver->probe(client, i2c_match_id(driver->id_table, client)); + if (dev->driver->of_match_table) + /* Device tree matching */ + status = driver->probe(client, NULL); + else + /* Fall back to matching the id_table */ + status = driver->probe(client, i2c_match_id(driver->id_table, client)); if (status) { client->driver = NULL; i2c_set_clientdata(client, NULL);