All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tony Lindgren <tony@atomide.com>
To: Jun Nie <jun.nie@linaro.org>
Cc: haojian.zhuang@linaro.org, linus.walleij@linaro.org,
	linux-gpio@vger.kernel.org, shawn.guo@linaro.org,
	wan.zhijun@zte.com.cn, jason.liu@linaro.org
Subject: Re: [PATCH v2] pinctrl: single: support GPIO for bits pinctrl
Date: Mon, 6 Jul 2015 08:42:05 -0700	[thread overview]
Message-ID: <20150706154205.GE10644@atomide.com> (raw)
In-Reply-To: <1436191025-9024-1-git-send-email-jun.nie@linaro.org>

* Jun Nie <jun.nie@linaro.org> [150706 06:59]:
> Support GPIO for one register control multiple pins case
> with calculating register offset first, then bit offset.
> 
> Signed-off-by: Jun Nie <jun.nie@linaro.org>
> ---
>  drivers/pinctrl/pinctrl-single.c | 22 ++++++++++++++++++----
>  1 file changed, 18 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c
> index 13b45f2..4f23ef0 100644
> --- a/drivers/pinctrl/pinctrl-single.c
> +++ b/drivers/pinctrl/pinctrl-single.c
> @@ -494,7 +494,7 @@ static int pcs_request_gpio(struct pinctrl_dev *pctldev,
>  	struct pcs_device *pcs = pinctrl_dev_get_drvdata(pctldev);
>  	struct pcs_gpiofunc_range *frange = NULL;
>  	struct list_head *pos, *tmp;
> -	int mux_bytes = 0;
> +	int offset, mux_bytes = 0;
>  	unsigned data;
>  
>  	/* If function mask is null, return directly. */
> @@ -507,9 +507,23 @@ static int pcs_request_gpio(struct pinctrl_dev *pctldev,
>  			|| pin < frange->offset)
>  			continue;
>  		mux_bytes = pcs->width / BITS_PER_BYTE;
> -		data = pcs->read(pcs->base + pin * mux_bytes) & ~pcs->fmask;
> -		data |= frange->gpiofunc;
> -		pcs->write(data, pcs->base + pin * mux_bytes);
> +		if (pcs->bits_per_mux) {
> +			int pin_pos, byte_num, num_pins_in_register;
> +
> +			num_pins_in_register = pcs->width / pcs->bits_per_pin;
> +			byte_num = (pcs->bits_per_pin * pin) / BITS_PER_BYTE;
> +			offset = (byte_num / mux_bytes) * mux_bytes;
> +			pin_pos = pin % num_pins_in_register;
> +			pin_pos *= pcs->bits_per_pin;
> +			data = pcs->read(pcs->base + offset) &
> +				~(pcs->fmask << pin_pos);
> +			data |= (frange->gpiofunc & pcs->fmask) << pin_pos;

I don't quite follow you here.. The pcs->fmask is for the whole register,
so I think the fmask should be checked the same way in this case also:
		
			data = pcs->read(pcs->base + offset) & ~pcs->fmask;
			...

I don't think we can safely assume the fmask would behave differently
in this case.

Regards,

Tony

  reply	other threads:[~2015-07-06 15:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-06 13:57 [PATCH v2] pinctrl: single: support GPIO for bits pinctrl Jun Nie
2015-07-06 15:42 ` Tony Lindgren [this message]
2015-07-07  1:57   ` Jun Nie
2015-07-07  7:42     ` Tony Lindgren

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=20150706154205.GE10644@atomide.com \
    --to=tony@atomide.com \
    --cc=haojian.zhuang@linaro.org \
    --cc=jason.liu@linaro.org \
    --cc=jun.nie@linaro.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=shawn.guo@linaro.org \
    --cc=wan.zhijun@zte.com.cn \
    /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.