All of lore.kernel.org
 help / color / mirror / Atom feed
From: NeilBrown <neil@brown.name>
To: Sergio Paracuellos <sergio.paracuellos@gmail.com>,
	gregkh@linuxfoundation.org
Cc: driverdev-devel@linuxdriverproject.org
Subject: Re: [PATCH v3 05/11] staging: mt7621-gpio: avoid use of globals and use platform_data instead
Date: Sat, 19 May 2018 20:51:43 +1000	[thread overview]
Message-ID: <87wovz2a0w.fsf@notabene.neil.brown.name> (raw)
In-Reply-To: <1526461910-20650-6-git-send-email-sergio.paracuellos@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 4377 bytes --]

On Wed, May 16 2018, Sergio Paracuellos wrote:

> Gpio driver have a some globals which can be avoided just
> using platform_data in a proper form. This commit adds a new
> struct mtk_data which includes all of those globals setting them
> using platform_set_drvdata and devm_gpiochip_add_data functions.
> With this properly set we are able to retrieve driver data along
> the code using kernel api's so globals are not needed anymore.
>
> Signed-off-by: Sergio Paracuellos <sergio.paracuellos@gmail.com>
> ---
>  drivers/staging/mt7621-gpio/gpio-mt7621.c | 85 +++++++++++++++++++++----------
>  1 file changed, 59 insertions(+), 26 deletions(-)
>
> diff --git a/drivers/staging/mt7621-gpio/gpio-mt7621.c b/drivers/staging/mt7621-gpio/gpio-mt7621.c
> index 7d17949..c701259 100644
> --- a/drivers/staging/mt7621-gpio/gpio-mt7621.c
> +++ b/drivers/staging/mt7621-gpio/gpio-mt7621.c
> @@ -31,17 +31,20 @@ enum mediatek_gpio_reg {
>  	GPIO_REG_EDGE,
>  };
>  
> -static void __iomem *mediatek_gpio_membase;
> -static int mediatek_gpio_irq;
> -static struct irq_domain *mediatek_gpio_irq_domain;
> -
> -static struct mtk_gc {
> +struct mtk_gc {
>  	struct gpio_chip chip;
>  	spinlock_t lock;
>  	int bank;
>  	u32 rising;
>  	u32 falling;
> -} *gc_map[MTK_MAX_BANK];
> +};
> +
> +struct mtk_data {
> +	void __iomem *gpio_membase;
> +	int gpio_irq;
> +	struct irq_domain *gpio_irq_domain;
> +	struct mtk_gc *gc_map[MTK_MAX_BANK];
> +};
>  
>  static inline struct mtk_gc
>  *to_mediatek_gpio(struct gpio_chip *chip)
> @@ -56,15 +59,19 @@ static inline struct mtk_gc
>  static inline void
>  mtk_gpio_w32(struct mtk_gc *rg, u8 reg, u32 val)
>  {
> -	iowrite32(val, mediatek_gpio_membase + (reg * 0x10) + (rg->bank * 0x4));
> +	struct mtk_data *gpio_data = gpiochip_get_data(&rg->chip);
> +	u32 offset = (reg * 0x10) + (rg->bank * 0x4);
> +
> +	iowrite32(val, gpio_data->gpio_membase + offset);
>  }
>  
>  static inline u32
>  mtk_gpio_r32(struct mtk_gc *rg, u8 reg)
>  {
> +	struct mtk_data *gpio_data = gpiochip_get_data(&rg->chip);
>  	u32 offset = (reg * 0x10) + (rg->bank * 0x4);
>  
> -	return ioread32(mediatek_gpio_membase + offset);
> +	return ioread32(gpio_data->gpio_membase + offset);
>  }
>  
>  static void
> @@ -137,23 +144,26 @@ mediatek_gpio_get_direction(struct gpio_chip *chip, unsigned int offset)
>  static int
>  mediatek_gpio_to_irq(struct gpio_chip *chip, unsigned int pin)
>  {
> +	struct mtk_data *gpio_data = gpiochip_get_data(chip);
>  	struct mtk_gc *rg = to_mediatek_gpio(chip);
>  
> -	return irq_create_mapping(mediatek_gpio_irq_domain,
> +	return irq_create_mapping(gpio_data->gpio_irq_domain,
>  				  pin + (rg->bank * MTK_BANK_WIDTH));
>  }
>  
>  static int
>  mediatek_gpio_bank_probe(struct platform_device *pdev, struct device_node *bank)
>  {
> +	struct mtk_data *gpio_data = dev_get_drvdata(&pdev->dev);
>  	const __be32 *id = of_get_property(bank, "reg", NULL);
>  	struct mtk_gc *rg = devm_kzalloc(&pdev->dev,
>  				sizeof(struct mtk_gc), GFP_KERNEL);
> +	int ret;
>  
>  	if (!rg || !id || be32_to_cpu(*id) > MTK_MAX_BANK)
>  		return -ENOMEM;
>  
> -	gc_map[be32_to_cpu(*id)] = rg;
> +	gpio_data->gc_map[be32_to_cpu(*id)] = rg;
>  
>  	memset(rg, 0, sizeof(struct mtk_gc));
>  
> @@ -169,10 +179,17 @@ mediatek_gpio_bank_probe(struct platform_device *pdev, struct device_node *bank)
>  	rg->chip.get_direction = mediatek_gpio_get_direction;
>  	rg->chip.get = mediatek_gpio_get;
>  	rg->chip.set = mediatek_gpio_set;
> -	if (mediatek_gpio_irq_domain)
> +	if (gpio_data->gpio_irq_domain)
>  		rg->chip.to_irq = mediatek_gpio_to_irq;
>  	rg->bank = be32_to_cpu(*id);
>  
> +	ret = devm_gpiochip_add_data(&pdev->dev, &rg->chip, gpio_data);
> +	if (ret < 0) {
> +		dev_err(&pdev->dev, "Could not register gpio %d, ret=%d\n",
> +			rg->chip.ngpio, ret);
> +		return ret;
> +	}
> +

Calling devm_gpiochip_add_data() here looks good.
Not removing
	return gpiochip_add(&rg->chip);
from the end of the function isn't so good :-(

BTW interrupt definitely don't work yet.  The calls
	struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
get NULL.  I think some sort of irq_set_chip_data(irq,...) is needed
in mediatek_gpio_gpio_map(), but it is too late at night for it to
all make sense to me :-)

Thanks,
NeilBrown

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

  reply	other threads:[~2018-05-19 10:51 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-16  9:11 [PATCH v3 00/11] staging: mt7621-gpio: use mediatek as binding instead of custom mtk Sergio Paracuellos
2018-05-16  9:11 ` [PATCH v3 01/11] staging: mt7621-gpio: dt-bindings: add documentation for mt7621-gpio Sergio Paracuellos
2018-05-16  9:11 ` [PATCH v3 02/11] staging: mt7621-gpio: update TODO file Sergio Paracuellos
2018-05-16  9:11 ` [PATCH v3 03/11] staging: mt7621-dts: update gpios related entries to use 'mediatek' Sergio Paracuellos
2018-05-16  9:11 ` [PATCH v3 04/11] staging: mt7621-gpio: replace 'mtk' to use correct one 'mediatek' Sergio Paracuellos
2018-05-16  9:11 ` [PATCH v3 05/11] staging: mt7621-gpio: avoid use of globals and use platform_data instead Sergio Paracuellos
2018-05-19 10:51   ` NeilBrown [this message]
2018-05-19 11:18     ` Sergio Paracuellos
2018-05-19 22:44       ` NeilBrown
2018-05-20  8:02         ` Sergio Paracuellos
2018-05-20  8:06         ` [PATCH] staging: mt7621-gpio: retrieve correct pointers in interrupt related functions Sergio Paracuellos
2018-05-20  9:53           ` NeilBrown
2018-05-20 10:18             ` Sergio Paracuellos
2018-05-20 11:21               ` NeilBrown
2018-05-20 14:20                 ` Sergio Paracuellos
2018-05-20 12:38               ` Greg KH
2018-05-20 12:39                 ` Greg KH
2018-05-20 13:01                   ` Sergio Paracuellos
2018-05-20 11:02             ` [PATCH v5 00/10] staging: mt7621-gpio: use mediatek as binding instead of custom mtk Sergio Paracuellos
2018-05-20 11:02               ` [PATCH v5 01/10] staging: mt7621-gpio: dt-bindings: add documentation for mt7621-gpio Sergio Paracuellos
2018-05-20 11:02               ` [PATCH v5 02/10] staging: mt7621-dts: update gpios related entries to use 'mediatek' Sergio Paracuellos
2018-05-20 11:02               ` [PATCH v5 03/10] staging: mt7621-gpio: replace 'mtk' to use correct one 'mediatek' Sergio Paracuellos
2018-05-20 11:02               ` [PATCH v5 04/10] staging: mt7621-gpio: avoid use of globals and use platform_data instead Sergio Paracuellos
2018-05-20 11:02               ` [PATCH v5 05/10] staging: mt7621-dts: add interrupt device tree nodes for the gpio controller Sergio Paracuellos
2018-05-20 11:02               ` [PATCH v5 06/10] staging: mt7621-gpio: dt-bindings: add interrupt nodes to bindings doc Sergio Paracuellos
2018-05-20 11:02               ` [PATCH v5 07/10] staging: mt7621-gpio: avoid devm_kzalloc() hidden inside declarations and refactor function a bit Sergio Paracuellos
2018-05-20 11:02               ` [PATCH v5 08/10] staging: mt7621-gpio: use ternary operator in return in mediatek_gpio_get_direction Sergio Paracuellos
2018-05-20 11:02               ` [PATCH v5 09/10] staging: mt7621-gpio: use MTK_BANK_WIDTH instead of magic number Sergio Paracuellos
2018-05-20 11:03               ` [PATCH v5 10/10] staging: mt7621-gpio: update TODO file Sergio Paracuellos
2018-05-16  9:11 ` [PATCH v3 06/11] staging: mt7621-dts: add interrupt device tree nodes for the gpio controller Sergio Paracuellos
2018-05-16  9:11 ` [PATCH v3 07/11] staging: mt7621-gpio: dt-bindings: add interrupt nodes to bindings doc Sergio Paracuellos
2018-05-16  9:11 ` [PATCH v3 08/11] staging: mt7621-gpio: avoid devm_kzalloc() hidden inside declarations and refactor function a bit Sergio Paracuellos
2018-05-16  9:11 ` [PATCH v3 09/11] staging: mt7621-gpio: use ternary operator in return in mediatek_gpio_get_direction Sergio Paracuellos
2018-05-16  9:11 ` [PATCH v3 10/11] staging: mt7621-gpio: use MTK_BANK_WIDTH instead of magic number Sergio Paracuellos
2018-05-16  9:11 ` [PATCH v3 11/11] staging: mt7621-gpio: update TODO list Sergio Paracuellos

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=87wovz2a0w.fsf@notabene.neil.brown.name \
    --to=neil@brown.name \
    --cc=driverdev-devel@linuxdriverproject.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=sergio.paracuellos@gmail.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.