Hello,
On Mon, Jan 26, 2015 at 01:13:37PM +0200, Robert Dolca wrote:
> + /* Get EN GPIO from ACPI */
> + gpiod_en = devm_gpiod_get_index(dev, PN544_GPIO_NAME_EN, 1);
Actually devm_gpiod_get_index takes 4 arguments. In your case you should
also pass GPIOD_OUT_LOW, then you can skip the gpiod_direction_output
part below.
> + if (IS_ERR(gpiod_en)) {
> + nfc_err(dev,
> + "Unable to get EN GPIO\n");
> + return -ENODEV;
> + }
> +
> + phy->gpio_en = desc_to_gpio(gpiod_en);
Why don't you save a reference to the gpiod instead? Mixing usage of raw
and gpiod might result in surprising results. For example
gpiod_direction_output(gpiod_en, 0);
might actually have the same result as
gpio_direction_output(gpio_en, 1);
if the matching gpio is marked as active low.
> +
> + /* Configuration EN GPIO */
> + ret = gpiod_direction_output(gpiod_en, 0);
> + if (ret) {
> + nfc_err(dev, "Fail EN pin direction\n");
> + return ret;
> + }
> +
> + /* Get FW GPIO from ACPI */
> + gpiod_fw = devm_gpiod_get_index(dev, PN544_GPIO_NAME_FW, 2);
> + if (IS_ERR(gpiod_fw)) {
> + nfc_err(dev,
> + "Unable to get FW GPIO\n");
> + return -ENODEV;
> + }
> +
> + phy->gpio_fw = desc_to_gpio(gpiod_fw);
> +
> + /* Configuration FW GPIO */
> + ret = gpiod_direction_output(gpiod_fw, 0);
> + if (ret) {
> + nfc_err(dev, "Fail FW pin direction\n");
> + return ret;
> + }
The same comments apply here.
> +
> + /* Get IRQ GPIO */
> + gpiod_irq = devm_gpiod_get_index(dev, PN544_GPIO_NAME_IRQ, 0);
> + if (IS_ERR(gpiod_irq)) {
> + nfc_err(dev,
> + "Unable to get IRQ GPIO\n");
> + return -ENODEV;
> + }
> +
> + phy->gpio_irq = desc_to_gpio(gpiod_irq);
> +
> + /* Configure IRQ GPIO */
> + ret = gpiod_direction_input(gpiod_irq);
> + if (ret) {
> + nfc_err(dev, "Fail IRQ pin direction\n");
> + return ret;
> + }
> +
> + /* Map the pin to an IRQ */
> + ret = gpiod_to_irq(gpiod_irq);
> + if (ret < 0) {
> + nfc_err(dev, "Fail pin IRQ mapping\n");
> + return ret;
> + }
and here.
Best regards
Uwe
--
Pengutronix e.K. | Uwe Kleine-K?nig |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Hi Uwe,
On Thu, Feb 12, 2015 at 09:14:59AM +0100, Uwe Kleine-K?nig wrote:
> On Mon, Jan 26, 2015 at 01:13:37PM +0200, Robert Dolca wrote:
> > + /* Get EN GPIO from ACPI */
> > + gpiod_en = devm_gpiod_get_index(dev, PN544_GPIO_NAME_EN, 1);
> Actually devm_gpiod_get_index takes 4 arguments. In your case you should
> also pass GPIOD_OUT_LOW, then you can skip the gpiod_direction_output
> part below.
>
> > + if (IS_ERR(gpiod_en)) {
> > + nfc_err(dev,
> > + "Unable to get EN GPIO\n");
> > + return -ENODEV;
> > + }
> > +
> > + phy->gpio_en = desc_to_gpio(gpiod_en);
> Why don't you save a reference to the gpiod instead? Mixing usage of raw
> and gpiod might result in surprising results. For example
>
> gpiod_direction_output(gpiod_en, 0);
>
> might actually have the same result as
>
> gpio_direction_output(gpio_en, 1);
>
> if the matching gpio is marked as active low.
>
> > +
> > + /* Configuration EN GPIO */
> > + ret = gpiod_direction_output(gpiod_en, 0);
> > + if (ret) {
> > + nfc_err(dev, "Fail EN pin direction\n");
> > + return ret;
> > + }
> > +
> > + /* Get FW GPIO from ACPI */
> > + gpiod_fw = devm_gpiod_get_index(dev, PN544_GPIO_NAME_FW, 2);
> > + if (IS_ERR(gpiod_fw)) {
> > + nfc_err(dev,
> > + "Unable to get FW GPIO\n");
> > + return -ENODEV;
> > + }
> > +
> > + phy->gpio_fw = desc_to_gpio(gpiod_fw);
> > +
> > + /* Configuration FW GPIO */
> > + ret = gpiod_direction_output(gpiod_fw, 0);
> > + if (ret) {
> > + nfc_err(dev, "Fail FW pin direction\n");
> > + return ret;
> > + }
> The same comments apply here.
>
> > +
> > + /* Get IRQ GPIO */
> > + gpiod_irq = devm_gpiod_get_index(dev, PN544_GPIO_NAME_IRQ, 0);
> > + if (IS_ERR(gpiod_irq)) {
> > + nfc_err(dev,
> > + "Unable to get IRQ GPIO\n");
> > + return -ENODEV;
> > + }
> > +
> > + phy->gpio_irq = desc_to_gpio(gpiod_irq);
> > +
> > + /* Configure IRQ GPIO */
> > + ret = gpiod_direction_input(gpiod_irq);
> > + if (ret) {
> > + nfc_err(dev, "Fail IRQ pin direction\n");
> > + return ret;
> > + }
> > +
> > + /* Map the pin to an IRQ */
> > + ret = gpiod_to_irq(gpiod_irq);
> > + if (ret < 0) {
> > + nfc_err(dev, "Fail pin IRQ mapping\n");
> > + return ret;
> > + }
> and here.
I didn't use gpiod_* functions because the existing enumeration method for
platform init and device tree was using gpio_* functions.
Also as far as I know the device tree implementation will not give you the
gpiod data structure. It gives you only the gpio index.
Keeping both gpiod and gpio depending on the enumeration method is unscallable
so I didn't choose that.
Regards,
Robert
Hello Robert,
On Thu, Feb 12, 2015 at 07:48:43PM +0200, Robert Dolca wrote:
> On Thu, Feb 12, 2015 at 09:14:59AM +0100, Uwe Kleine-K?nig wrote:
> > On Mon, Jan 26, 2015 at 01:13:37PM +0200, Robert Dolca wrote:
> > > + /* Get EN GPIO from ACPI */
> > > + gpiod_en = devm_gpiod_get_index(dev, PN544_GPIO_NAME_EN, 1);
> > Actually devm_gpiod_get_index takes 4 arguments. In your case you should
> > also pass GPIOD_OUT_LOW, then you can skip the gpiod_direction_output
> > part below.
> >
> > > + if (IS_ERR(gpiod_en)) {
> > > + nfc_err(dev,
> > > + "Unable to get EN GPIO\n");
> > > + return -ENODEV;
> > > + }
> > > +
> > > + phy->gpio_en = desc_to_gpio(gpiod_en);
> > Why don't you save a reference to the gpiod instead? Mixing usage of raw
> > and gpiod might result in surprising results. For example
> >
> > gpiod_direction_output(gpiod_en, 0);
> >
> > might actually have the same result as
> >
> > gpio_direction_output(gpio_en, 1);
> >
> > if the matching gpio is marked as active low.
> >
> > > +
> > > + /* Configuration EN GPIO */
> > > + ret = gpiod_direction_output(gpiod_en, 0);
> > > + if (ret) {
> > > + nfc_err(dev, "Fail EN pin direction\n");
> > > + return ret;
> > > + }
> > > +
> > > + /* Get FW GPIO from ACPI */
> > > + gpiod_fw = devm_gpiod_get_index(dev, PN544_GPIO_NAME_FW, 2);
> > > + if (IS_ERR(gpiod_fw)) {
> > > + nfc_err(dev,
> > > + "Unable to get FW GPIO\n");
> > > + return -ENODEV;
> > > + }
> > > +
> > > + phy->gpio_fw = desc_to_gpio(gpiod_fw);
> > > +
> > > + /* Configuration FW GPIO */
> > > + ret = gpiod_direction_output(gpiod_fw, 0);
> > > + if (ret) {
> > > + nfc_err(dev, "Fail FW pin direction\n");
> > > + return ret;
> > > + }
> > The same comments apply here.
> >
> > > +
> > > + /* Get IRQ GPIO */
> > > + gpiod_irq = devm_gpiod_get_index(dev, PN544_GPIO_NAME_IRQ, 0);
> > > + if (IS_ERR(gpiod_irq)) {
> > > + nfc_err(dev,
> > > + "Unable to get IRQ GPIO\n");
> > > + return -ENODEV;
> > > + }
> > > +
> > > + phy->gpio_irq = desc_to_gpio(gpiod_irq);
> > > +
> > > + /* Configure IRQ GPIO */
> > > + ret = gpiod_direction_input(gpiod_irq);
> > > + if (ret) {
> > > + nfc_err(dev, "Fail IRQ pin direction\n");
> > > + return ret;
> > > + }
> > > +
> > > + /* Map the pin to an IRQ */
> > > + ret = gpiod_to_irq(gpiod_irq);
> > > + if (ret < 0) {
> > > + nfc_err(dev, "Fail pin IRQ mapping\n");
> > > + return ret;
> > > + }
> > and here.
> Also as far as I know the device tree implementation will not give you the
> gpiod data structure. It gives you only the gpio index.
What is "the device tree implementation"? If devm_gpiod_get_index gets
the information which gpio to use from a device tree that doesn't change
the return type, you still get a struct gpio_desc pointer. And it can
very well return a descriptor with GPIO_ACTIVE_LOW set, see the
implementation of of_find_gpio.
> Keeping both gpiod and gpio depending on the enumeration method is unscallable
> so I didn't choose that.
And if the descriptor has GPIO_ACTIVE_LOW set, you should better not
ignore it. The best thing to do here AFAIUI is to first convert the
driver to gpiod and then add your ACPI support in an additional patch.
And then please (this was the main motivation for my reply) your the
4-parameter version of devm_gpiod_get_index.
Best regards
Uwe
--
Pengutronix e.K. | Uwe Kleine-K?nig |
Industrial Linux Solutions | http://www.pengutronix.de/ |