From: Bill Gatliff <bgat@billgatliff.com>
To: linuxppc-dev@ozlabs.org
Cc: Bill Gatliff <bgat@billgatliff.com>
Subject: [PATCH 2/2] Create an of_i2c_gpiochip_add()
Date: Tue, 5 Jan 2010 21:51:38 -0600 [thread overview]
Message-ID: <1262749898-19197-3-git-send-email-bgat@billgatliff.com> (raw)
In-Reply-To: <1262749898-19197-2-git-send-email-bgat@billgatliff.com>
Signed-off-by: Bill Gatliff <bgat@billgatliff.com>
---
drivers/of/gpio.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 55 insertions(+), 0 deletions(-)
diff --git a/drivers/of/gpio.c b/drivers/of/gpio.c
index 6eea601..56b438a 100644
--- a/drivers/of/gpio.c
+++ b/drivers/of/gpio.c
@@ -217,3 +217,58 @@ err0:
return ret;
}
EXPORT_SYMBOL(of_mm_gpiochip_add);
+
+/**
+ * of_i2c_gpiochip_add - Add memory I2C-based GPIO chip
+ * @np: device node of the GPIO chip
+ * @gc: pointer to the of_i2c_gpio_chip allocated structure
+ *
+ * To use this function you should allocate and fill gc with:
+ *
+ * 1) In the gpio_chip structure:
+ * - all the callbacks
+ *
+ * 2) In the of_gpio_chip structure:
+ * - gpio_cells
+ * - xlate callback (optional)
+ *
+ * If succeeded, this function will do something useful...
+ */
+int of_i2c_gpiochip_add(struct device_node *np,
+ struct of_i2c_gpio_chip *i2c_gc)
+{
+ int ret = -ENOMEM;
+ struct of_gpio_chip *of_gc = &i2c_gc->of_gc;
+ struct gpio_chip *gc = &of_gc->gc;
+
+ gc->label = kstrdup(np->full_name, GFP_KERNEL);
+ if (!gc->label)
+ goto err0;
+
+ gc->base = -1;
+
+ if (!of_gc->xlate)
+ of_gc->xlate = of_gpio_simple_xlate;
+
+ np->data = of_gc;
+
+ ret = gpiochip_add(gc);
+ if (ret)
+ goto err2;
+
+ /* We don't want to lose the node and its ->data */
+ of_node_get(np);
+
+ pr_debug("%s: registered as generic GPIO chip, base is %d\n",
+ np->full_name, gc->base);
+ return 0;
+err2:
+ np->data = NULL;
+err1:
+ kfree(gc->label);
+err0:
+ pr_err("%s: GPIO chip registration failed with status %d\n",
+ np->full_name, ret);
+ return ret;
+}
+EXPORT_SYMBOL(of_i2c_gpiochip_add);
--
1.6.5
next prev parent reply other threads:[~2010-01-06 3:51 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-06 3:51 [PATCH 0/2] Create an of_i2c_gpiochip_add() Bill Gatliff
2010-01-06 3:51 ` [PATCH 1/2] Create a struct of_i2c_gpio_chip, for i2c-based GPIO devices Bill Gatliff
2010-01-06 3:51 ` Bill Gatliff [this message]
2010-01-06 20:07 ` [PATCH 0/2] Create an of_i2c_gpiochip_add() Bill Gatliff
2010-01-06 20:17 ` Wolfram Sang
2010-01-06 20:31 ` Bill Gatliff
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1262749898-19197-3-git-send-email-bgat@billgatliff.com \
--to=bgat@billgatliff.com \
--cc=linuxppc-dev@ozlabs.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox