From patchwork Tue Oct 21 00:23:15 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: 5164 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 27300DDF6D for ; Tue, 21 Oct 2008 11:23:34 +1100 (EST) X-Original-To: linuxppc-dev@ozlabs.org Delivered-To: linuxppc-dev@ozlabs.org Received: from yw-out-2324.google.com (yw-out-2324.google.com [74.125.46.28]) by ozlabs.org (Postfix) with ESMTP id 78066DDDED for ; Tue, 21 Oct 2008 11:23:19 +1100 (EST) Received: by yw-out-2324.google.com with SMTP id 5so342827ywh.39 for ; Mon, 20 Oct 2008 17:23:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:received:from:subject:to:date :message-id:user-agent:mime-version:content-type :content-transfer-encoding; bh=DGd2L0Q4O7Vt7ZcJWMWYHeFW2ccnDzaHLmGNAAgMNVw=; b=xZQm74Xzg6lDygwuVoqaoTQgLahTDJjLFAZcrCIzSemxC5/pO0oFVnJzp7RUN3mx1M uxIkZOXKOOrEajzhqXB36R3OW1fcxewOv4yaUW40WLkYyhkVBrXi71V8e7rJesMIMvOh R6rP14zxAxh5pyh5Fm3pe58lr5+gbhcBUIeGU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:subject:to:date:message-id:user-agent:mime-version :content-type:content-transfer-encoding; b=xU5fM18SqpQ/ozxMZ23CFrepwOFEDUtsUkQUE8plwKzuMHhW7ISZOoc6Y1DN4Op4HY ob2eCk6GQFx2mZKArVy49E1Wmi6ZV3LoqgDcpVE9BrBNpuPRh8xDhRVNI32mknN5okik cPdpDGw9fcwMOSNKrMcg4ajIUizV+jYO2Bcy8= Received: by 10.70.57.5 with SMTP id f5mr9390747wxa.42.1224548597483; Mon, 20 Oct 2008 17:23:17 -0700 (PDT) Received: from terra (c-76-109-159-38.hsd1.fl.comcast.net [76.109.159.38]) by mx.google.com with ESMTPS id e76sm7171284hse.18.2008.10.20.17.23.16 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 20 Oct 2008 17:23:16 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=[127.0.1.1]) by terra with esmtp (Exim 4.69) (envelope-from ) id 1Ks51n-0008Hf-Iv; Mon, 20 Oct 2008 20:23:15 -0400 From: Jon Smirl Subject: [PATCH] Add the of_find_i2c_device_by_node function. To: linuxppc-dev@ozlabs.org, avorontsov@ru.mvista.com Date: Mon, 20 Oct 2008 20:23:15 -0400 Message-ID: <20081021002315.31817.7497.stgit@terra> User-Agent: StGIT/0.14.3.224.g199b 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. Anton - this version is based off from your patches 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 */