linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: andy.shevchenko@gmail.com
To: Jerome Neanne <jneanne@baylibre.com>
Cc: linus.walleij@linaro.org, brgl@bgdev.pl, tony@atomide.com,
	lee@kernel.org, linux-kernel@vger.kernel.org,
	linux-gpio@vger.kernel.org, linux-omap@vger.kernel.org,
	Jonathan Cormier <jcormier@criticallink.com>
Subject: Re: [PATCH 1/2] gpio: tps65219: add GPIO support for TPS65219 PMIC
Date: Fri, 24 Feb 2023 14:16:06 +0200	[thread overview]
Message-ID: <Y/iqhsEIvHgnZ+5l@surfacebook> (raw)
In-Reply-To: <20230224113837.874264-2-jneanne@baylibre.com>

Fri, Feb 24, 2023 at 12:38:36PM +0100, Jerome Neanne kirjoitti:
> Add support for TPS65219 PMICs GPIO interface.
> 
> 3 GPIO pins:
> - GPIO0 only is IO but input mode reserved for MULTI_DEVICE_ENABLE usage
> - GPIO1 and GPIO2 are Output only and referred as GPO1 and GPO2 in spec
> 
> GPIO0 is statically configured as input or output prior to linux boot.

Linux

> it is used for MULTI_DEVICE_ENABLE function.
> This setting is statically configured by NVM.
> GPIO0 can't be used as a generic GPIO (specification Table 8-34).
> It's either a GPO when MULTI_DEVICE_EN=0
> or a GPI when MULTI_DEVICE_EN=1.

Something wrong with the indentation.

> Link: https://www.ti.com/lit/ds/symlink/tps65219.pdf

Can it be Datasheet tag?

> Signed-off-by: Jonathan Cormier <jcormier@criticallink.com>
> Signed-off-by: Jerome Neanne <jneanne@baylibre.com>

Not sure how to interpet this along with the From line.

...

> +config GPIO_TPS65219
> +	tristate "TPS65219 GPIO"
> +	depends on MFD_TPS65219
> +	help
> +	  Select this option to enable GPIO driver for the TPS65219
> +	  chip family.
> +	  GPIO0 is statically configured as input or output prior to linux boot.
> +	  it is used for MULTI_DEVICE_ENABLE function.
> +	  This setting is statically configured by NVM.
> +	  GPIO0 can't be used as a generic GPIO.
> +	  It's either a GPO when MULTI_DEVICE_EN=0
> +	  or a GPI when MULTI_DEVICE_EN=1.

Similar issues as with commit message. Also if chosen as M, how will it be
called?

> +#include <linux/module.h>
> +#include <linux/of.h>
> +#include <linux/platform_device.h>
> +#include <linux/regmap.h>
> +
> +#include <linux/gpio/driver.h>
> +#include <linux/mfd/tps65219.h>
> +
> +#define TPS65219_GPIO0_DIR_MASK		BIT(3)
> +#define TPS65219_GPIO0_OFFSET		2
> +#define TPS65219_GPIO0_IDX		0
> +#define TPS65219_GPIO_DIR_IN		1
> +#define TPS65219_GPIO_DIR_OUT		0
> +
> +struct tps65219_gpio {
> +	struct gpio_chip gpio_chip;
> +	struct tps65219 *tps;
> +};

...

> +static void tps65219_gpio_set(struct gpio_chip *gc, unsigned int offset,
> +			      int value)
> +{
> +	struct tps65219_gpio *gpio = gpiochip_get_data(gc);
> +
> +	if (offset != TPS65219_GPIO0_IDX)
> +		regmap_update_bits(gpio->tps->regmap,
> +				   TPS65219_REG_GENERAL_CONFIG,
> +				   BIT(offset - 1), value ? BIT(offset - 1) : 0);
> +	else
> +		regmap_update_bits(gpio->tps->regmap,
> +				   TPS65219_REG_GENERAL_CONFIG,
> +				   BIT(TPS65219_GPIO0_OFFSET),
> +				   value ? BIT(TPS65219_GPIO0_OFFSET) : 0);

With tenporary variables for value and mask this can be simplified.

	bit = (offset == _IDX) ? GPIO0_OFFSET : offset - 1;

	mask = BIT(bit);
	v = value ? mask : 0;

	regmap_update_bits(..., mask, v);

> +}

...

> +static int tps65219_gpio_change_direction(struct gpio_chip *gc, unsigned int offset,
> +					  unsigned int direction)
> +{
> +	struct tps65219_gpio *gpio = gpiochip_get_data(gc);
> +
> +	/* Documentation is stating that GPIO0 direction must not be changed in Linux:
> +	 * Table 8-34. MFP_1_CONFIG(3): MULTI_DEVICE_ENABLE,
> +	 * Should only be changed in INITIALIZE state (prior to ON Request).
> +	 * Set statically by NVM, changing direction in application can cause a hang.
> +	 * Below can be used for test purpose only:

You may rather put code into #if 0 ... #endif, so it will be easier to get the
test. Also, probably you would need to take care about error handling properly.

> +	 * ret = regmap_update_bits(gpio->tps->regmap, TPS65219_REG_MFP_1_CONFIG,
> +	 *			 TPS65219_GPIO0_DIR_MASK, direction);
> +	 */
> +	dev_err(gpio->tps->dev,
> +		"GPIO%d direction set by NVM, change to %u failed, not allowed by specification\n",
> +		 offset, direction);
> +	return -EOPNOTSUPP;
> +}

...

> +static struct platform_driver tps65219_gpio_driver = {
> +	.driver = {.name = "tps65219-gpio",},

Can you write it as

	.driver = {
		...
	},
?

> +	.probe = tps65219_gpio_probe,
> +};

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2023-02-24 12:16 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-24 11:38 [PATCH 0/2] Add support for TI TPS65219 PMIC GPIO interface Jerome Neanne
2023-02-24 11:38 ` [PATCH 1/2] gpio: tps65219: add GPIO support for TPS65219 PMIC Jerome Neanne
2023-02-24 12:16   ` andy.shevchenko [this message]
2023-02-24 12:18     ` andy.shevchenko
2023-02-27 19:20     ` Jon Cormier
2023-02-27 19:51       ` Andy Shevchenko
2023-02-28 11:18         ` jerome Neanne
2023-02-24 11:38 ` [PATCH 2/2] mfd: tps65219: Add gpio cell instance Jerome Neanne
2023-02-24 12:17   ` andy.shevchenko

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=Y/iqhsEIvHgnZ+5l@surfacebook \
    --to=andy.shevchenko@gmail.com \
    --cc=brgl@bgdev.pl \
    --cc=jcormier@criticallink.com \
    --cc=jneanne@baylibre.com \
    --cc=lee@kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=tony@atomide.com \
    /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).