From patchwork Tue Dec 30 20:11:07 2008 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "jonsmirl@gmail.com" X-Patchwork-Id: 16071 X-Patchwork-Delegate: grant.likely@secretlab.ca Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from ozlabs.org (localhost [127.0.0.1]) by ozlabs.org (Postfix) with ESMTP id 949654755D for ; Wed, 31 Dec 2008 07:17:40 +1100 (EST) X-Original-To: linuxppc-dev@ozlabs.org Delivered-To: linuxppc-dev@ozlabs.org Received: from yx-out-2324.google.com (yx-out-2324.google.com [74.125.44.30]) by ozlabs.org (Postfix) with ESMTP id B871DDDDED for ; Wed, 31 Dec 2008 07:17:23 +1100 (EST) Received: by yx-out-2324.google.com with SMTP id 8so1610220yxg.39 for ; Tue, 30 Dec 2008 12:17:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:received:subject:to:from:date :message-id:user-agent:mime-version:content-type :content-transfer-encoding; bh=dQ2TS4if8OjaxTKHaS0TPgTaE1459wjNYOVoBiUj0CU=; b=Av8vtpDil2Da4rxItFKnGhwkiQn15BSke2kDFvjkEPXhRbgpDfsO5LDILRMwFypluB dJeEQWAyZ5rnwlHPmFUIB5IwHqzwerVxUfjyxFrmw72SHcU5VMS0B/Jw1a3KY8+7j+NE QyLMtvjSVDmOZeBWsxNsPVI5M7hQNQOKVIFNI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=subject:to:from:date:message-id:user-agent:mime-version :content-type:content-transfer-encoding; b=bCmTWpQhzTUQyDxF4ObvrhlbAIAibSFN7sfBsqk2iUYK+hHf5bYKNY/a0SF5TTXioj ql7ErLyBfNX9zvoDY+l4KXdFzAitZbVDERUe09WCn2APXbBFwNK13XTXIDBcJwk+t1/o n0kNTfrfEtpjbWLVDskDwAKWt+McKx0PMZEZg= Received: by 10.150.124.2 with SMTP id w2mr23863583ybc.224.1230667869724; Tue, 30 Dec 2008 12:11:09 -0800 (PST) Received: from terra (c-76-109-159-38.hsd1.fl.comcast.net [76.109.159.38]) by mx.google.com with ESMTPS id k47sm28275177rnd.2.2008.12.30.12.11.08 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 30 Dec 2008 12:11:08 -0800 (PST) Received: from localhost ([127.0.0.1]) by terra with esmtp (Exim 4.69) (envelope-from ) id 1LHkvj-0006z0-Ck for linuxppc-dev@ozlabs.org; Tue, 30 Dec 2008 15:11:07 -0500 Subject: [PATCH] Add the of_find_i2c_device_by_node function. To: linuxppc-dev@ozlabs.org From: Jon Smirl Date: Tue, 30 Dec 2008 15:11:07 -0500 Message-ID: <20081230201107.26810.71390.stgit@localhost> User-Agent: StGit/0.14.3.285.g62874 MIME-Version: 1.0 X-BeenThere: linuxppc-dev@ozlabs.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@ozlabs.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@ozlabs.org Add the of_find_i2c_device_by_node function. This allows you to follow a reference in the device tree to an i2c device node and then locate the linux device instantiated by the device tree. Example use, an i2s codec controlled by i2c. This was waiting for Anton's i2c patches that were just added. Signed-off-by: Jon Smirl --- drivers/of/of_i2c.c | 19 +++++++++++++++++++ include/linux/of_i2c.h | 3 +++ 2 files changed, 22 insertions(+), 0 deletions(-) diff --git a/drivers/of/of_i2c.c b/drivers/of/of_i2c.c index e1b0ad6..fa65a2b 100644 --- a/drivers/of/of_i2c.c +++ b/drivers/of/of_i2c.c @@ -66,4 +66,23 @@ void of_register_i2c_devices(struct i2c_adapter *adap, } EXPORT_SYMBOL(of_register_i2c_devices); +static int of_dev_node_match(struct device *dev, void *data) +{ + return dev_archdata_get_node(&dev->archdata) == data; +} + +/* must call put_device() when done with returned i2c_client device */ +struct i2c_client *of_find_i2c_device_by_node(struct device_node *node) +{ + struct device *dev; + + dev = bus_find_device(&i2c_bus_type, NULL, node, + of_dev_node_match); + if (!dev) + return NULL; + + return to_i2c_client(dev); +} +EXPORT_SYMBOL(of_find_i2c_device_by_node); + MODULE_LICENSE("GPL"); diff --git a/include/linux/of_i2c.h b/include/linux/of_i2c.h index bd2a870..34974b5 100644 --- a/include/linux/of_i2c.h +++ b/include/linux/of_i2c.h @@ -17,4 +17,7 @@ void of_register_i2c_devices(struct i2c_adapter *adap, struct device_node *adap_node); +/* must call put_device() when done with returned i2c_client device */ +struct i2c_client *of_find_i2c_device_by_node(struct device_node *node); + #endif /* __LINUX_OF_I2C_H */