All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lee Jones <lee@kernel.org>
To: Matthias Schiffer <matthias.schiffer@ew.tq-group.com>
Cc: linux@ew.tq-group.com, linux-kernel@vger.kernel.org,
	Gregor Herburger <gregor.herburger@tq-group.com>
Subject: Re: [PATCH v3 3/5] mfd: tqmx86: refactor GPIO IRQ setup
Date: Thu, 3 Oct 2024 08:36:42 +0100	[thread overview]
Message-ID: <20241003073642.GH7504@google.com> (raw)
In-Reply-To: <00708dee4281943a8da8dc2fee63388c9f923048.1726148801.git.matthias.schiffer@ew.tq-group.com>

On Thu, 12 Sep 2024, Matthias Schiffer wrote:

> Move IRQ setup into a helper function. The string "GPIO" for error
> messages is replaced with a label argument to prepare for reusing the
> function for the I2C IRQ.
> 
> No functional change intended.
> 
> Co-developed-by: Gregor Herburger <gregor.herburger@tq-group.com>
> Signed-off-by: Gregor Herburger <gregor.herburger@tq-group.com>
> Signed-off-by: Matthias Schiffer <matthias.schiffer@ew.tq-group.com>
> ---
> 
> v2: no changes (was patch 2/4)
> v3: no changes
> 
>  drivers/mfd/tqmx86.c | 72 +++++++++++++++++++++++++++-----------------
>  1 file changed, 45 insertions(+), 27 deletions(-)
> 
> diff --git a/drivers/mfd/tqmx86.c b/drivers/mfd/tqmx86.c
> index 7b2f9490a9af5..5aa51ead00a28 100644
> --- a/drivers/mfd/tqmx86.c
> +++ b/drivers/mfd/tqmx86.c
> @@ -186,32 +186,54 @@ static int tqmx86_board_id_to_clk_rate(struct device *dev, u8 board_id)
>  	}
>  }
>  
> -static int tqmx86_probe(struct platform_device *pdev)
> +static int tqmx86_irq_to_irq_cfg(struct device *dev, const char *label, u8 irq)

Not sure single case statement that only gets called once warrants its
own function (with a weird name).  I'd put it in tqmx86_setup_irq() and
have done.

>  {
> -	u8 board_id, sauc, rev, i2c_det, io_ext_int_val;
> -	struct device *dev = &pdev->dev;
> -	u8 gpio_irq_cfg, readback;
> -	const char *board_name;
> -	void __iomem *io_base;
> -	int err;
> -
> -	switch (gpio_irq) {
> +	switch (irq) {
>  	case 0:
> -		gpio_irq_cfg = TQMX86_REG_IO_EXT_INT_NONE;
> -		break;
> +		return TQMX86_REG_IO_EXT_INT_NONE;
>  	case 7:
> -		gpio_irq_cfg = TQMX86_REG_IO_EXT_INT_7;
> -		break;
> +		return TQMX86_REG_IO_EXT_INT_7;
>  	case 9:
> -		gpio_irq_cfg = TQMX86_REG_IO_EXT_INT_9;
> -		break;
> +		return TQMX86_REG_IO_EXT_INT_9;
>  	case 12:
> -		gpio_irq_cfg = TQMX86_REG_IO_EXT_INT_12;
> -		break;
> +		return TQMX86_REG_IO_EXT_INT_12;
>  	default:
> -		pr_err("tqmx86: Invalid GPIO IRQ (%d)\n", gpio_irq);
> +		dev_err(dev, "invalid %s IRQ (%d)\n", label, irq);
>  		return -EINVAL;
>  	}
> +}
> +
> +static int tqmx86_setup_irq(struct device *dev, const char *label, u8 irq,
> +			    void __iomem *io_base, u8 reg_shift)
> +{
> +	u8 val, readback;
> +	int irq_cfg;
> +
> +	irq_cfg = tqmx86_irq_to_irq_cfg(dev, label, irq);
> +	if (irq_cfg < 0)
> +		return irq_cfg;
> +
> +	val = ioread8(io_base + TQMX86_REG_IO_EXT_INT);
> +	val &= ~(TQMX86_REG_IO_EXT_INT_MASK << reg_shift);
> +	val |= (irq_cfg & TQMX86_REG_IO_EXT_INT_MASK) << reg_shift;
> +
> +	iowrite8(val, io_base + TQMX86_REG_IO_EXT_INT);
> +	readback = ioread8(io_base + TQMX86_REG_IO_EXT_INT);
> +	if (readback != val) {
> +		dev_warn(dev, "%s interrupts not supported\n", label);
> +		return -EINVAL;
> +	}
> +
> +	return 0;
> +}
> +
> +static int tqmx86_probe(struct platform_device *pdev)
> +{
> +	u8 board_id, sauc, rev, i2c_det;
> +	struct device *dev = &pdev->dev;
> +	const char *board_name;
> +	void __iomem *io_base;
> +	int err;
>  
>  	io_base = devm_ioport_map(dev, TQMX86_IOBASE, TQMX86_IOSIZE);
>  	if (!io_base)
> @@ -233,15 +255,11 @@ static int tqmx86_probe(struct platform_device *pdev)
>  	 */
>  	i2c_det = inb(TQMX86_REG_I2C_DETECT);
>  
> -	if (gpio_irq_cfg) {
> -		io_ext_int_val =
> -			gpio_irq_cfg << TQMX86_REG_IO_EXT_INT_GPIO_SHIFT;
> -		iowrite8(io_ext_int_val, io_base + TQMX86_REG_IO_EXT_INT);
> -		readback = ioread8(io_base + TQMX86_REG_IO_EXT_INT);
> -		if (readback != io_ext_int_val) {
> -			dev_warn(dev, "GPIO interrupts not supported.\n");
> -			return -EINVAL;
> -		}
> +	if (gpio_irq) {
> +		err = tqmx86_setup_irq(dev, "GPIO", gpio_irq, io_base,
> +				       TQMX86_REG_IO_EXT_INT_GPIO_SHIFT);
> +		if (err)
> +			return err;
>  
>  		/* Assumes the IRQ resource is first. */
>  		tqmx_gpio_resources[0].start = gpio_irq;
> -- 
> TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
> Amtsgericht München, HRB 105018
> Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
> https://www.tq-group.com/

-- 
Lee Jones [李琼斯]

  reply	other threads:[~2024-10-03  7:36 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-12 14:04 [PATCH v3 0/5] mfd: tqmx86: new hardware and GPIO/I2C IRQ improvements/additions Matthias Schiffer
2024-09-12 14:04 ` [PATCH v3 1/5] mfd: tqmx86: add board definitions for TQMx120UC, TQMx130UC and TQMxE41S Matthias Schiffer
2024-09-12 14:04 ` [PATCH v3 2/5] mfd: tqmx86: improve gpio_irq module parameter description Matthias Schiffer
2024-09-12 14:04 ` [PATCH v3 3/5] mfd: tqmx86: refactor GPIO IRQ setup Matthias Schiffer
2024-10-03  7:36   ` Lee Jones [this message]
2024-09-12 14:04 ` [PATCH v3 4/5] mfd: tqmx86: make IRQ setup errors non-fatal Matthias Schiffer
2024-09-12 14:04 ` [PATCH v3 5/5] mfd: tqmx86: add I2C IRQ support Matthias Schiffer

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=20241003073642.GH7504@google.com \
    --to=lee@kernel.org \
    --cc=gregor.herburger@tq-group.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@ew.tq-group.com \
    --cc=matthias.schiffer@ew.tq-group.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.