public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Vipin Kumar <vipin.kumar@st.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] gpio: spear_gpio: Fix gpio_set_value() implementation
Date: Mon, 1 Jul 2013 11:51:46 +0530	[thread overview]
Message-ID: <51D11FFA.6000203@st.com> (raw)
In-Reply-To: <CAFRkauARGW4voJYYHy8MvQNqyKPFY_Od-PCB11X9=o3Tk6hQNg@mail.gmail.com>

On 7/1/2013 11:02 AM, Axel Lin wrote:
>>
>> The questions raised here are valid and it forced me to re-read the
>> datasheet. For your convenience, I must tell you that the device is actually
>> pl061 from ARM, so the driver can also be named so.
>>
>> The datasheet is here
>> http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0190b/I1002697.html
>>
>> Quoting from the datasheet
>> "The GPIODATA register is the data register. In software control mode,
>> values written in the GPIODATA register are transferred onto the GPOUT pins
>> if the respective pins have been configured as outputs through the GPIODIR
>> register.
>>
>> In order to write to GPIODATA, the corresponding bits in the mask, resulting
>> from the address bus, PADDR[9:2], must be HIGH. Otherwise the bit values
>> remain unchanged by the write.
>>
>> Similarly, the values read from this register are determined for each bit,
>> by the mask bit derived from the address used to access the data register,
>> PADDR[9:2]. Bits that are 1 in the address mask cause the corresponding bits
>> in GPIODATA to be read, and bits that are 0 in the address mask cause the
>> corresponding bits in GPIODATA to be read as 0, regardless of their value.
>>
>> A read from GPIODATA returns the last bit value written if the respective
>> pins are configured as output, or it returns the value on the corresponding
>> input GPIN bit when these are configured as inputs. All bits are cleared by
>> a reset."
>>
>> After reading all this I am confused about numbering of the gpio's. I think
>> the numbering should be from 1 to 8 for a device. And this would mean that
>> we should write to *&regs->datareg[1<<  (gpio - 1)]* instead of the present
>> code which is _&regs->datareg[1<<  (gpio + 2)]_
>
> Hi Vipin,

Hello Alex,

> Thanks for the review and providing the datasheet information.
> You mentioned that this is PL061.
> So... I just checked the gpio-pl061 driver in linux kernel.
> It's writing to _&regs->datareg[1<<  (gpio + 2)]. and seems no bug
> report for this.
>

Yes, I see it now. The difference is that we are using a writel and the 
datareg is a u32 array.

> And the gpio_get/set implementation in linux kernel has the same behavior as
> this patch does:
>
> ( below is from linux/drivers/gpio/gpio-pl061.c )
>
> static int pl061_get_value(struct gpio_chip *gc, unsigned offset)
> {
>          struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc);
>
>          return !!readb(chip->base + (1<<  (offset + 2)));
> }
>
> static void pl061_set_value(struct gpio_chip *gc, unsigned offset, int value)
> {
>          struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc);
>
>          writeb(!!value<<  offset, chip->base + (1<<  (offset + 2)));
> }
>
> BTW, it would be great if you have the hardware to test.
>

I am sorry about this. I have now moved to a different group and I have 
no access to the hardware

Regards
Vipin

> Regards,
> Axel
> .
>

  reply	other threads:[~2013-07-01  6:21 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-20  7:13 [U-Boot] [PATCH] gpio: spear_gpio: Fix gpio_set_value() implementation Axel Lin
2013-06-20  7:22 ` Stefan Roese
2013-06-20 13:09 ` Michael Trimarchi
2013-06-20 13:57   ` Marek Vasut
2013-06-20 15:04     ` Michael Trimarchi
2013-06-20 15:11       ` Marek Vasut
2013-06-20 13:44 ` Marek Vasut
2013-06-20 13:56   ` Axel Lin
2013-06-20 20:02     ` Michael Trimarchi
2013-06-20 20:16       ` Marek Vasut
2013-06-21  4:40     ` Vipin Kumar
2013-06-21  6:42       ` Michael Trimarchi
2013-06-30  4:18         ` Axel Lin
2013-06-30  8:10           ` Michael Trimarchi
2013-06-30  8:57             ` Axel Lin
2013-07-01  4:27               ` Vipin Kumar
2013-07-01  5:32                 ` Axel Lin
2013-07-01  6:21                   ` Vipin Kumar [this message]
2013-08-12 16:57                     ` Axel Lin
2013-08-12 17:00                       ` Michael Trimarchi

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=51D11FFA.6000203@st.com \
    --to=vipin.kumar@st.com \
    --cc=u-boot@lists.denx.de \
    /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