mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Samuel Holland <samuel@sholland.org>
To: Aidan MacDonald <aidanmacdonald.0x0@gmail.com>, wens@csie.org
Cc: linus.walleij@linaro.org, brgl@bgdev.pl, robh+dt@kernel.org,
	krzysztof.kozlowski+dt@linaro.org, jic23@kernel.org,
	sre@kernel.org, lee.jones@linaro.org, lgirdwood@gmail.com,
	broonie@kernel.org, lars@metafoo.de, quic_gurus@quicinc.com,
	sebastian.reichel@collabora.com, andy.shevchenko@gmail.com,
	michael@walle.cc, rdunlap@infradead.org,
	linux-gpio@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org,
	linux-pm@vger.kernel.org
Subject: Re: [PATCH v4 12/15] pinctrl: Add AXP192 pin control driver
Date: Sat, 2 Jul 2022 10:11:43 -0500	[thread overview]
Message-ID: <37d40cf2-4512-754f-2e44-ee1449bc2e9f@sholland.org> (raw)
In-Reply-To: <20220629143046.213584-13-aidanmacdonald.0x0@gmail.com>

On 6/29/22 9:30 AM, Aidan MacDonald wrote:
> The AXP192 PMIC's GPIO registers are much different from the GPIO
> registers of the AXP20x and AXP813 PMICs supported by the existing
> pinctrl-axp209 driver. It makes more sense to add a new driver for
> the AXP192, rather than add support in the existing axp20x driver.
> 
> The pinctrl-axp192 driver is considerably more flexible in terms of
> register layout and should be able to support other X-Powers PMICs.
> Interrupts and pull down resistor configuration are supported too.

I am planning to implement gpio/pinctrl support for AXP152[1], which is
somewhere between AXP20x and AXP192 in terms of GPIO capability.

Which driver should I add it to? How much work would it be to convert AXP20x
variants to the new driver? And if supporting other X-Powers PMICs is the plan,
would it make sense to convert the existing driver in-place to avoid dealing
with Kconfig migrations?

[1]: https://linux-sunxi.org/AXP152

> Signed-off-by: Aidan MacDonald <aidanmacdonald.0x0@gmail.com>
> ---
>  drivers/pinctrl/Kconfig          |  13 +
>  drivers/pinctrl/Makefile         |   1 +
>  drivers/pinctrl/pinctrl-axp192.c | 598 +++++++++++++++++++++++++++++++
>  3 files changed, 612 insertions(+)
>  create mode 100644 drivers/pinctrl/pinctrl-axp192.c
> [...]
> +static int axp192_pinconf_get(struct pinctrl_dev *pctldev, unsigned int pin, unsigned long *config)
> +{
> +	enum pin_config_param param = pinconf_to_config_param(*config);
> +	unsigned int arg = 1;
> +	bool pull_down;
> +	int ret;
> +
> +	switch (param) {
> +	case PIN_CONFIG_BIAS_DISABLE:
> +		ret = axp192_pinconf_get_pull_down(pctldev, pin, &pull_down);
> +		if (ret)
> +			return ret;
> +		if (pull_down)
> +			return -EINVAL;
> +		break;
> +
> +	case PIN_CONFIG_BIAS_PULL_DOWN:
> +		ret = axp192_pinconf_get_pull_down(pctldev, pin, &pull_down);
> +		if (ret)
> +			return ret;
> +		if (!pull_down)
> +			return -EINVAL;
> +		break;
> +
> +	default:
> +		return -ENOTSUPP;
> +	}
> +
> +	*config = pinconf_to_config_packed(param, arg);
> +	return 0;
> +}
> +
> +static int axp192_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
> +			      unsigned long *configs, unsigned int num_configs)
> +{
> +	int ret;
> +	unsigned int cfg;
> +
> +	for (cfg = 0; cfg < num_configs; cfg++) {
> +		switch (pinconf_to_config_param(configs[cfg])) {
> +		case PIN_CONFIG_BIAS_DISABLE:
> +			ret = axp192_pinconf_set_pull_down(pctldev, pin, 0);
> +			if (ret)
> +				return ret;
> +			break;
> +
> +		case PIN_CONFIG_BIAS_PULL_DOWN:
> +			ret = axp192_pinconf_set_pull_down(pctldev, pin, 1);
> +			if (ret)
> +				return ret;
> +			break;
> +
> +		default:
> +			return -ENOTSUPP;

The GPIO outputs are always open-drain. It looks like this needs to handle
PIN_CONFIG_DRIVE_OPEN_DRAIN, or gpiolib will try to emulate it.

And I would suggest returning -EINVAL for PIN_CONFIG_DRIVE_PUSH_PULL, but
gpiolib does not check the return value when setting that.

> +		}
> +	}
> +
> +	return 0;
> +}
> +
> [...]
> +
> +static int axp192_pctl_probe(struct platform_device *pdev)
> +{
> +	struct device *dev = &pdev->dev;
> +	struct axp20x_dev *axp20x = dev_get_drvdata(dev->parent);
> +	struct axp192_pctl *pctl;
> +	struct pinctrl_desc *pctrl_desc;
> +	int ret, i;
> +
> +	pctl = devm_kzalloc(dev, sizeof(*pctl), GFP_KERNEL);
> +	if (!pctl)
> +		return -ENOMEM;
> +
> +	pctl->desc = device_get_match_data(dev);
> +	pctl->regmap = axp20x->regmap;
> +	pctl->regmap_irqc = axp20x->regmap_irqc;
> +	pctl->dev = dev;
> +
> +	pctl->chip.base			= -1;
> +	pctl->chip.can_sleep		= true;
> +	pctl->chip.request		= gpiochip_generic_request;
> +	pctl->chip.free			= gpiochip_generic_free;
> +	pctl->chip.parent		= dev;
> +	pctl->chip.label		= dev_name(dev);
> +	pctl->chip.owner		= THIS_MODULE;
> +	pctl->chip.get			= axp192_gpio_get;
> +	pctl->chip.get_direction	= axp192_gpio_get_direction;
> +	pctl->chip.set			= axp192_gpio_set;
> +	pctl->chip.direction_input	= axp192_gpio_direction_input;
> +	pctl->chip.direction_output	= axp192_gpio_direction_output;
> +	pctl->chip.to_irq		= axp192_gpio_to_irq;
> +	pctl->chip.ngpio		= pctl->desc->npins;
> +
> +	pctl->irqs = devm_kcalloc(dev, pctl->desc->npins, sizeof(int), GFP_KERNEL);
> +	if (!pctl->irqs)
> +		return -ENOMEM;
> +
> +	for (i = 0; i < pctl->desc->npins; i++) {
> +		ret = platform_get_irq_byname_optional(pdev, pctl->desc->pins[i].name);
> +		if (ret > 0)
> +			pctl->irqs[i] = ret;
> +	}
> +
> +	platform_set_drvdata(pdev, pctl);
> +
> +	pctrl_desc = devm_kzalloc(dev, sizeof(*pctrl_desc), GFP_KERNEL);
> +	if (!pctrl_desc)
> +		return -ENOMEM;

This can go inside struct axp192_pctl. It does not need a separate allocation.

Regards,
Samuel

  parent reply	other threads:[~2022-07-02 15:11 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-29 14:30 [PATCH v4 00/15] Add support for AXP192 PMIC Aidan MacDonald
2022-06-29 14:30 ` [PATCH v4 01/15] dt-bindings: mfd: add bindings for AXP192 MFD device Aidan MacDonald
2022-06-29 14:30 ` [PATCH v4 02/15] dt-bindings: iio: adc: axp209: Add AXP192 compatible Aidan MacDonald
2022-06-29 14:30 ` [PATCH v4 03/15] dt-bindings: power: supply: axp20x: " Aidan MacDonald
2022-06-29 14:30 ` [PATCH v4 04/15] dt-bindings: gpio: Add AXP192 GPIO bindings Aidan MacDonald
2022-06-29 18:17   ` Krzysztof Kozlowski
2022-07-02 15:16   ` Samuel Holland
2022-07-03 11:31     ` Aidan MacDonald
2022-06-29 14:30 ` [PATCH v4 05/15] dt-bindings: power: axp20x-battery: Add AXP192 compatible Aidan MacDonald
2022-06-29 14:30 ` [PATCH v4 06/15] mfd: axp20x: Add support for AXP192 Aidan MacDonald
2022-06-30  7:57   ` Andy Shevchenko
2022-07-05 12:35   ` Lee Jones
2022-07-05 14:26     ` Aidan MacDonald
2022-07-05 14:38       ` Lee Jones
2022-07-05 19:42         ` Aidan MacDonald
2022-06-29 14:30 ` [PATCH v4 07/15] regulator: " Aidan MacDonald
2022-06-30  7:58   ` Andy Shevchenko
2022-06-29 14:30 ` [PATCH v4 08/15] iio: adc: axp20x_adc: Minor code cleanups Aidan MacDonald
2022-06-30  7:58   ` Andy Shevchenko
2022-06-29 14:30 ` [PATCH v4 09/15] iio: adc: axp20x_adc: Replace adc_en2 flag with adc_en2_mask field Aidan MacDonald
2022-06-30  7:58   ` Andy Shevchenko
2022-07-01 16:56   ` Jonathan Cameron
2022-06-29 14:30 ` [PATCH v4 10/15] iio: adc: axp20x_adc: Add support for AXP192 Aidan MacDonald
2022-06-30  7:58   ` Andy Shevchenko
2022-06-29 14:30 ` [PATCH v4 11/15] power: supply: axp20x_usb_power: " Aidan MacDonald
2022-06-30  7:59   ` Andy Shevchenko
2022-06-29 14:30 ` [PATCH v4 12/15] pinctrl: Add AXP192 pin control driver Aidan MacDonald
2022-06-29 21:13   ` Andy Shevchenko
2022-07-01 15:37     ` Aidan MacDonald
2022-07-01 20:06       ` Andy Shevchenko
2022-07-02 19:22         ` Aidan MacDonald
2022-07-02 15:11   ` Samuel Holland [this message]
2022-07-03 11:27     ` Aidan MacDonald
2022-06-29 14:30 ` [PATCH v4 13/15] power: axp20x_battery: Add constant charge current table Aidan MacDonald
2022-06-30  7:59   ` Andy Shevchenko
2022-06-29 14:30 ` [PATCH v4 14/15] power: axp20x_battery: Support battery status without fuel gauge Aidan MacDonald
2022-06-30  8:00   ` Andy Shevchenko
2022-06-29 14:30 ` [PATCH v4 15/15] power: axp20x_battery: Add support for AXP192 Aidan MacDonald
2022-06-30  8:00   ` Andy Shevchenko
2022-06-29 21:14 ` [PATCH v4 00/15] Add support for AXP192 PMIC Andy Shevchenko
2022-06-29 21:16   ` Andy Shevchenko
2022-06-30  7:55     ` Lee Jones
2022-06-30  8:02       ` Andy Shevchenko
2022-06-30  8:46         ` Lee Jones

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=37d40cf2-4512-754f-2e44-ee1449bc2e9f@sholland.org \
    --to=samuel@sholland.org \
    --cc=aidanmacdonald.0x0@gmail.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=brgl@bgdev.pl \
    --cc=broonie@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=jic23@kernel.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=lars@metafoo.de \
    --cc=lee.jones@linaro.org \
    --cc=lgirdwood@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=michael@walle.cc \
    --cc=quic_gurus@quicinc.com \
    --cc=rdunlap@infradead.org \
    --cc=robh+dt@kernel.org \
    --cc=sebastian.reichel@collabora.com \
    --cc=sre@kernel.org \
    --cc=wens@csie.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

all inboxes | Powered by JetHome®