From: David Jander <david.jander@protonic.nl>
To: Grant Likely <grant.likely@secretlab.ca>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>, linux-input@vger.kernel.org
Subject: Re: [PATCH] INPUT: gpio_keys.c: Added OF support and enabled use with I2C GPIO expanders
Date: Mon, 6 Jun 2011 15:39:10 +0200 [thread overview]
Message-ID: <20110606153910.14865cc9@archvile> (raw)
In-Reply-To: <BANLkTikt2iLXqOeO0ba0jK1+WiNRVBAESw@mail.gmail.com>
Hi Grant,
Thanks for reacting.
On Thu, 2 Jun 2011 07:30:21 -0600
Grant Likely <grant.likely@secretlab.ca> wrote:
> There are a lot of unrelated changes being made in this patch. Can
> you split it up please into logical changes. For example, adding
> device tree support is one discrete change, reworking the handling of
> struct device pointers is another, changing the initcall is another,
> etc.
Ok, will do.
>[...]
> >
> > struct gpio_button_data {
> > struct gpio_keys_button *button;
> > @@ -42,6 +49,7 @@ struct gpio_keys_drvdata {
> > int (*enable)(struct device *dev);
> > void (*disable)(struct device *dev);
> > struct gpio_button_data data[0];
> > + struct gpio_keys_platform_data *dyn_pdata;
>
> If you make this a copy of the gpio_keys_platform_data instead of a
> pointer, then you can avoid kzallocing a pdata structure, and avoid
> the messy question about when to free it.
Someone needs to kzalloc it somewhere. Originally it is supposed to be done in
platform setup code somewhere in the BSP. Now I am parsing OF Device-Tree
data, so I will need to provide this, since pdata is NULL.
I don't know how to deal with it in a simpler way than using an extra member
in struct gpio_keys_drvdata to save the allocated pointer and free it if
needed....
> > };
> >
> > /*
> > @@ -251,8 +259,7 @@ static ssize_t gpio_keys_show_##name(struct device
> > *dev, \ struct device_attribute *attr, \
> > char *buf) \
> > { \
> > - struct platform_device *pdev = to_platform_device(dev); \
> > - struct gpio_keys_drvdata *ddata = platform_get_drvdata(pdev); \
> > + struct gpio_keys_drvdata *ddata = dev_get_drvdata(dev); \
> > \
> > return gpio_keys_attr_show_helper(ddata, buf, \
> > type, only_disabled); \
> > @@ -278,8 +285,7 @@ static ssize_t gpio_keys_store_##name(struct device
> > *dev, \ const char *buf, \
> > size_t count) \
> > { \
> > - struct platform_device *pdev = to_platform_device(dev); \
> > - struct gpio_keys_drvdata *ddata = platform_get_drvdata(pdev); \
> > + struct gpio_keys_drvdata *ddata = dev_get_drvdata(dev); \
> > ssize_t error; \
> > \
> > error = gpio_keys_attr_store_helper(ddata, buf, type); \
> > @@ -359,12 +365,11 @@ static irqreturn_t gpio_keys_isr(int irq, void
> > *dev_id) return IRQ_HANDLED;
> > }
> >
> > -static int __devinit gpio_keys_setup_key(struct platform_device *pdev,
> > +static int __devinit gpio_keys_setup_key(struct device *dev,
> > struct gpio_button_data *bdata,
> > struct gpio_keys_button *button)
> > {
> > char *desc = button->desc ? button->desc : "gpio_keys";
> > - struct device *dev = &pdev->dev;
> > unsigned long irqflags;
> > int irq, error;
> >
> > @@ -410,8 +415,8 @@ static int __devinit gpio_keys_setup_key(struct
> > platform_device *pdev, if (!button->can_disable)
> > irqflags |= IRQF_SHARED;
> >
> > - error = request_any_context_irq(irq, gpio_keys_isr, irqflags,
> > desc, bdata);
> > - if (error < 0) {
> > + error = request_threaded_irq(irq, NULL, gpio_keys_isr, irqflags,
> > desc, bdata);
> > + if (error) {
>
> You need to explain why you are making this change.
Will do in next patch version... it amounts to this:
request_threaded_irq() permits to execute the IRQ code in a thread, which is
better suited if the handler wants to do things like I2C transfers to figure
out the cause of the interrupt (like in a PCA953x).
The second line was not intended to be changed... will revert that, sorry.
> > dev_err(dev, "Unable to claim irq %d; error %d\n",
> > irq, error);
> > goto fail3;
> > @@ -440,18 +445,133 @@ static void gpio_keys_close(struct input_dev *input)
> > ddata->disable(input->dev.parent);
> > }
> >
> > +/*
> > + * Handlers for alternative sources of platform_data
> > + */
> > +#ifdef CONFIG_OF
> > +/*
> > + * Translate OpenFirmware node properties into platform_data
> > + */
> > +static struct gpio_keys_platform_data *
> > +gpio_keys_get_alt_pdata(struct device *dev)
>
> Function name should reflect what it does. In this case, something
> like gpio_keys_get_devtree_pdata() would be more appropriate.
Agreed!
> > +{
> > + struct gpio_keys_platform_data *pdata;
> > + struct device_node *node, *pp;
> > + int i;
> > + struct gpio_keys_button *buttons;
> > + const u32 *reg;
> > + int len;
> > +
> > + node = dev->of_node;
> > + if (node == NULL)
> > + return NULL;
> > +
> > + pdata = kzalloc(sizeof(struct gpio_keys_platform_data),
> > GFP_KERNEL);
> > + if (pdata == NULL) {
> > + dev_err(dev, "Unable to allocate platform_data\n");
> > + return NULL;
> > + }
> > +
> > + reg = of_get_property(node, "linux,autorepeat", &len);
>
> You're creating a new binding. You must also document it in
> Documentation/devicetree/bindings.
Ok, will do, thanks for pointing out.
Best regards,
--
David Jander
Protonic Holland.
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2011-06-06 13:39 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <-3144470533789149426@unknownmsgid>
2011-06-02 13:30 ` [PATCH] INPUT: gpio_keys.c: Added OF support and enabled use with I2C GPIO expanders Grant Likely
2011-06-06 13:39 ` David Jander [this message]
[not found] <6613128190865466111@unknownmsgid>
[not found] ` <BANLkTinNMeiimJqzFsWSS2zDggZ-o5k=fA@mail.gmail.com>
2011-06-06 9:12 ` David Jander
[not found] <1306919273-26815-1-git-send-email-y>
2011-06-01 9:16 ` David Jander
2011-06-01 9:07 y
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=20110606153910.14865cc9@archvile \
--to=david.jander@protonic.nl \
--cc=dmitry.torokhov@gmail.com \
--cc=grant.likely@secretlab.ca \
--cc=linux-input@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).