All of lore.kernel.org
 help / color / mirror / Atom feed
From: Patrick DELAUNAY <patrick.delaunay@foss.st.com>
To: u-boot@lists.denx.de
Subject: [PATCH v4 10/16] dm: gpio: Add a way to update flags
Date: Wed, 10 Feb 2021 09:38:49 +0100	[thread overview]
Message-ID: <9eb742a5-37b3-82d6-f472-c2861083b66d@foss.st.com> (raw)
In-Reply-To: <CAPnjgZ3+rV-hZxEUs_6V7nX4UQf5r6iqS3iOhBFtuBjGBMkA-w@mail.gmail.com>


On 2/9/21 5:28 AM, Simon Glass wrote:
> Hi Patrick,
>
> On Mon, 8 Feb 2021 at 10:33, Patrick DELAUNAY
> <patrick.delaunay@foss.st.com> wrote:
>> Hi Simon,
>>
>> 2 minor remarks,
>>
>> On 2/5/21 5:22 AM, Simon Glass wrote:
>>> It is convenient to be able to adjust some of the flags for a GPIO while
>>> leaving others alone. Add a function for this.
>>>
>>> Update dm_gpio_set_dir_flags() to make use of this.
>>>
>>> Also update dm_gpio_set_value() to use this also, since this allows the
>>> open-drain / open-source features to be implemented directly in the
>>> driver, rather than using the uclass workaround.
>>>
>>> Update the sandbox tests accordingly. This involves a lot of changes to
>>> dm_test_gpio_opendrain_opensource() since we no-longer have the direciion
>>> being reported differently depending on the open drain/open source flags.
>>>
>>> Also update the STM32 drivers to let the uclass handle the active low/high
>>> logic.
>>>
>>> Drop the GPIOD_FLAGS_OUTPUT() macro which is no-longer used.
>>>
>>> Signed-off-by: Simon Glass <sjg@chromium.org>
>>> ---
>>>
>>> Changes in v4:
>>> - Update dm_gpio_set_dir_flags() to clear direction flags first
>>>
>>> Changes in v3:
>>> - Incorporate GPIOD_FLAGS_OUTPUT() changes from Patrick Delaunay
>>>
>>>    drivers/gpio/gpio-uclass.c      |  75 ++++++++++++++----
>>>    drivers/gpio/stm32_gpio.c       |   3 +-
>>>    drivers/pinctrl/pinctrl-stmfx.c |   5 +-
>>>    include/asm-generic/gpio.h      |  31 ++++++--
>>>    test/dm/gpio.c                  | 132 ++++++++++++++++++++++++++++----
>>>    5 files changed, 203 insertions(+), 43 deletions(-)
>> (...)
>>
>>> diff --git a/drivers/gpio/stm32_gpio.c b/drivers/gpio/stm32_gpio.c
>>> index c2d7046c0dd..125c237551c 100644
>>> --- a/drivers/gpio/stm32_gpio.c
>>> +++ b/drivers/gpio/stm32_gpio.c
>>> @@ -203,12 +203,13 @@ static int stm32_gpio_set_flags(struct udevice *dev, unsigned int offset,
>>>                return idx;
>>>
>>>        if (flags & GPIOD_IS_OUT) {
>>> -             int value = GPIOD_FLAGS_OUTPUT(flags);
>>> +             bool value = flags & GPIOD_IS_OUT_ACTIVE;
>> here the bool variable valeu can be 0 or GPIOD_IS_OUT_ACTIVE = BIT(4),
>> so it should have
>>
>> + bool value = !!(flags & GPIOD_IS_OUT_ACTIVE);
>>
>> or
>>
>> + int value = flags & GPIOD_IS_OUT_ACTIVE;
>>
>> PS: not functional impact as
>>
>> #define BSRR_BIT(gpio_pin, value)    BIT((gpio_pin) + (value ? 0 : 16))
>>
>>>                if (flags & GPIOD_OPEN_DRAIN)
>>>                        stm32_gpio_set_otype(regs, idx, STM32_GPIO_OTYPE_OD);
>>>                else
>>>                        stm32_gpio_set_otype(regs, idx, STM32_GPIO_OTYPE_PP);
>>> +
>>>                stm32_gpio_set_moder(regs, idx, STM32_GPIO_MODE_OUT);
>>>                writel(BSRR_BIT(idx, value), &regs->bsrr);
>>>
>>> diff --git a/drivers/pinctrl/pinctrl-stmfx.c b/drivers/pinctrl/pinctrl-stmfx.c
>>> index 8ddbc3dc281..711b1a5d8c4 100644
>>> --- a/drivers/pinctrl/pinctrl-stmfx.c
>>> +++ b/drivers/pinctrl/pinctrl-stmfx.c
>>> @@ -169,6 +169,8 @@ static int stmfx_gpio_set_flags(struct udevice *dev, unsigned int offset,
>>>        int ret = -ENOTSUPP;
>>>
>>>        if (flags & GPIOD_IS_OUT) {
>>> +             bool value = flags & GPIOD_IS_OUT_ACTIVE;
>>> +
>>
>> same here
>>
>> +               int value = flags & GPIOD_IS_OUT_ACTIVE;
>> or
>> +               bool value = !!(flags & GPIOD_IS_OUT_ACTIVE);
> The bool type should do this automatically. I tested this and it seems
> to do the right thing.
>
I confirmed that it is working, forget my remarks.

for information: I tested it in stm32MP157C-DK2 board (with gcc 9.2)....


After check, it is my old habit / coding rule, when the bool type

don't exist in C (it was a typedef to int)

but, since C++ introducing a proper bool type,

the cast to 'bool' is enough with current compilers .

>
> Regards,
> SImon


Reviewed-by: Patrick Delaunay <patrick.delaunay@foss.st.com>

Tested-by: Patrick Delaunay <patrick.delaunay@foss.st.com>


Regards

  reply	other threads:[~2021-02-10  8:38 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-05  4:21 [PATCH v4 00/16] gpio: Update and simplify the uclass API Simon Glass
2021-02-05  4:21 ` [PATCH v4 01/16] gpio: Disable functions not used with of-platdata Simon Glass
2021-03-04 18:13   ` Tom Rini
2021-02-05  4:21 ` [PATCH v4 02/16] dm: gpio: Rename set_dir_flags() method to update_flags() Simon Glass
2021-03-04 18:14   ` Tom Rini
2021-02-05  4:21 ` [PATCH v4 03/16] dm: gpio: Rename get_dir_flags() method to get_flags() Simon Glass
2021-03-04 18:14   ` Tom Rini
2021-02-05  4:21 ` [PATCH v4 04/16] gpio: Rename dm_gpio_get_dir_flags() to dm_gpio_get_flags() Simon Glass
2021-03-04 18:14   ` Tom Rini
2021-02-05  4:21 ` [PATCH v4 05/16] gpio: Drop dm_gpio_set_dir() Simon Glass
2021-03-03 20:39   ` Tom Rini
2021-03-04 14:22     ` Simon Glass
2021-03-04 15:09       ` Tom Rini
2021-02-05  4:21 ` [PATCH v4 06/16] gpio: sandbox: Rename GPIO dir_flags to flags Simon Glass
2021-03-04 18:14   ` Tom Rini
2021-02-05  4:22 ` [PATCH v4 07/16] gpio: sandbox: Use a separate flag for the value Simon Glass
2021-03-04 18:14   ` Tom Rini
2021-02-05  4:22 ` [PATCH v4 08/16] gpio: sandbox: Fully separate pin value from output value Simon Glass
2021-03-04 18:14   ` Tom Rini
2021-02-05  4:22 ` [PATCH v4 09/16] gpio: sandbox: Make sandbox_gpio_set_flags() set all flags Simon Glass
2021-03-04 18:14   ` Tom Rini
2021-02-05  4:22 ` [PATCH v4 10/16] dm: gpio: Add a way to update flags Simon Glass
2021-02-08  9:00   ` Köry Maincent
2021-02-08 17:33   ` Patrick DELAUNAY
2021-02-09  4:28     ` Simon Glass
2021-02-10  8:38       ` Patrick DELAUNAY [this message]
2021-02-13  4:17         ` Simon Glass
2021-03-04 18:14   ` Tom Rini
2021-02-05  4:22 ` [PATCH v4 11/16] gpio: Replace direction_input() and direction_output() Simon Glass
2021-03-04 18:14   ` Tom Rini
2021-02-05  4:22 ` [PATCH v4 12/16] gpio: Use an 'ops' variable everywhere Simon Glass
2021-03-04 18:14   ` Tom Rini
2021-02-05  4:22 ` [PATCH v4 13/16] gpio: x86: Drop the deprecated methods in intel_gpio Simon Glass
2021-03-04 18:15   ` Tom Rini
2021-02-05  4:22 ` [PATCH v4 14/16] gpio: sandbox: Track whether a GPIO is driven Simon Glass
2021-03-04 18:15   ` Tom Rini
2021-02-05  4:22 ` [PATCH v4 15/16] gpio: Define the log category in the uclass Simon Glass
2021-03-04 18:15   ` Tom Rini
2021-02-05  4:22 ` [PATCH v4 16/16] gpio: Add a way to read 3-way strapping pins Simon Glass
2021-02-08 18:13   ` Patrick DELAUNAY
2021-02-08 23:41     ` Simon Glass
2021-03-04 18:15   ` Tom Rini

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=9eb742a5-37b3-82d6-f472-c2861083b66d@foss.st.com \
    --to=patrick.delaunay@foss.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 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.