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: 243219 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 44E8B2C009F for ; Mon, 13 May 2013 08:26:37 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751491Ab3ELW0g (ORCPT ); Sun, 12 May 2013 18:26:36 -0400 Received: from mail-lb0-f174.google.com ([209.85.217.174]:39179 "EHLO mail-lb0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751297Ab3ELW0f (ORCPT ); Sun, 12 May 2013 18:26:35 -0400 Received: by mail-lb0-f174.google.com with SMTP id r10so5778997lbi.19 for ; Sun, 12 May 2013 15:26:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer :x-gm-message-state; bh=ySGeYzQaodYe3vNnKAezzh/De5p5ZKfzpFTnej3s4WY=; b=AmpM7GJ52qqrKBMMk5AcbYjcO+2Y6Rx8jWt6InH7n2vyhDpPb+ZqwdL4NQkdWDZI8w tvEJeV3hxB/vz8gVCaSTTf7R3Neogzfr8+HBXbvddV3nA+OTlreOkMsOf4MwImNzLLwO GVzM9gLG9umFTk7KBnacl48aAk1SI1l7RrLqiuQNzB6HaWAdp3zjNjrcELKzZ/pOhkOV 56LAY93j5NXDpoU5YHSXdIx52GGfHcprQ1uVj+Ezfm3gbDAaq3VeIv/WGLMp1BTEWhdi 6kqQZgQmJ9X5AzpisiuaYJwkJ7BrOfoRRRgdjhCaJwYCTjICYrG6K5tUmYLYDYmduRYo C9Ig== 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: ALoCoQmA8emKlGZ30jyJvfhboKqp7wEyBmeQ2wHMwpBmudU7+2BzeKfXhNS8T0HUZ96/ylzk4vXT Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org 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);