devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Linus Walleij <linus.walleij@linaro.org>
To: Matheus Castello <matheus@castello.eng.br>,
	"open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS"
	<devicetree@vger.kernel.org>, Rob Herring <robh+dt@kernel.org>
Cc: Stefan Wahren <stefan.wahren@i2se.com>,
	Eric Anholt <eric@anholt.net>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] pinctrl: bc2835: Add brcm,level property
Date: Fri, 2 Mar 2018 11:14:05 +0100	[thread overview]
Message-ID: <CACRpkdZc0ataQGWQ-81v1+_wCRpv=VVk195rafJcEQUFM5xfOg@mail.gmail.com> (raw)
In-Reply-To: <1519321475-973-1-git-send-email-matheus@castello.eng.br>

Hi Matheus,

sorry for top-posting, but new DT properties have to be ACKed
by the device tree maintainers, so quoting it all.

I understand why you use the legacy bcm-specific bindings for this,
but in theory nothing really stops you from just using
"output-high" and "output-low" from the generic properties,
even if you are not using the generic code to handle them but
instead parse them just like in this driver.

The only reason I could think of not to use them would be consistency,
like it would look not so elegant.

But if we look at the pin control bindings from a birds eye view
the big problem with consistency is the proliferation of custom
vendor bindings like this.

So there is a bit of conflict of interest here.

Yours,
Linus Walleij


On Thu, Feb 22, 2018 at 6:44 PM, Matheus Castello
<matheus@castello.eng.br> wrote:
> Property to set initial value of pin output buffer.
>
> Signed-off-by: Matheus Castello <matheus@castello.eng.br>
> ---
>  .../bindings/pinctrl/brcm,bcm2835-gpio.txt         |  5 +-
>  drivers/pinctrl/bcm/pinctrl-bcm2835.c              | 90 +++++++++++++++++-----
>  2 files changed, 75 insertions(+), 20 deletions(-)
>
> diff --git a/Documentation/devicetree/bindings/pinctrl/brcm,bcm2835-gpio.txt b/Documentation/devicetree/bindings/pinctrl/brcm,bcm2835-gpio.txt
> index 2569866..6834f1d 100644
> --- a/Documentation/devicetree/bindings/pinctrl/brcm,bcm2835-gpio.txt
> +++ b/Documentation/devicetree/bindings/pinctrl/brcm,bcm2835-gpio.txt
> @@ -54,8 +54,11 @@ Optional subnode-properties:
>    0: none
>    1: down
>    2: up
> +- brcm,level: Integer, representing the value of output buffer to apply to the pin(s):
> +  0: low
> +  1: high
>
> -Each of brcm,function and brcm,pull may contain either a single value which
> +Each of brcm,function, brcm,pull and brcm,level may contain either a single value which
>  will be applied to all pins in brcm,pins, or 1 value for each entry in
>  brcm,pins.
>
> diff --git a/drivers/pinctrl/bcm/pinctrl-bcm2835.c b/drivers/pinctrl/bcm/pinctrl-bcm2835.c
> index 785c366..0ace548 100644
> --- a/drivers/pinctrl/bcm/pinctrl-bcm2835.c
> +++ b/drivers/pinctrl/bcm/pinctrl-bcm2835.c
> @@ -73,6 +73,8 @@
>  enum bcm2835_pinconf_param {
>         /* argument: bcm2835_pinconf_pull */
>         BCM2835_PINCONF_PARAM_PULL,
> +       /* argument: bcm2835_pinconf_level */
> +       BCM2835_PINCONF_PARAM_LEVEL,
>  };
>
>  #define BCM2835_PINCONF_PACK(_param_, _arg_) ((_param_) << 16 | (_arg_))
> @@ -725,16 +727,42 @@ static int bcm2835_pctl_dt_node_to_map_pull(struct bcm2835_pinctrl *pc,
>         return 0;
>  }
>
> +static int bcm2835_pctl_dt_node_to_map_level(struct bcm2835_pinctrl *pc,
> +               struct device_node *np, u32 pin, u32 level,
> +               struct pinctrl_map **maps)
> +{
> +       struct pinctrl_map *map = *maps;
> +       unsigned long *configs;
> +
> +       if (level > 2) {
> +               dev_err(pc->dev, "%pOF: invalid brcm,level %d\n", np, level);
> +               return -EINVAL;
> +       }
> +
> +       configs = kzalloc(sizeof(*configs), GFP_KERNEL);
> +       if (!configs)
> +               return -ENOMEM;
> +       configs[0] = BCM2835_PINCONF_PACK(BCM2835_PINCONF_PARAM_LEVEL, level);
> +
> +       map->type = PIN_MAP_TYPE_CONFIGS_PIN;
> +       map->data.configs.group_or_pin = bcm2835_gpio_pins[pin].name;
> +       map->data.configs.configs = configs;
> +       map->data.configs.num_configs = 1;
> +       (*maps)++;
> +
> +       return 0;
> +}
> +
>  static int bcm2835_pctl_dt_node_to_map(struct pinctrl_dev *pctldev,
>                 struct device_node *np,
>                 struct pinctrl_map **map, unsigned *num_maps)
>  {
>         struct bcm2835_pinctrl *pc = pinctrl_dev_get_drvdata(pctldev);
> -       struct property *pins, *funcs, *pulls;
> -       int num_pins, num_funcs, num_pulls, maps_per_pin;
> +       struct property *pins, *funcs, *pulls, *levels;
> +       int num_pins, num_funcs, num_pulls, num_levels, maps_per_pin;
>         struct pinctrl_map *maps, *cur_map;
>         int i, err;
> -       u32 pin, func, pull;
> +       u32 pin, func, pull, level;
>
>         pins = of_find_property(np, "brcm,pins", NULL);
>         if (!pins) {
> @@ -744,6 +772,7 @@ static int bcm2835_pctl_dt_node_to_map(struct pinctrl_dev *pctldev,
>
>         funcs = of_find_property(np, "brcm,function", NULL);
>         pulls = of_find_property(np, "brcm,pull", NULL);
> +       levels = of_find_property(np, "brcm,level", NULL);
>
>         if (!funcs && !pulls) {
>                 dev_err(pc->dev,
> @@ -755,6 +784,7 @@ static int bcm2835_pctl_dt_node_to_map(struct pinctrl_dev *pctldev,
>         num_pins = pins->length / 4;
>         num_funcs = funcs ? (funcs->length / 4) : 0;
>         num_pulls = pulls ? (pulls->length / 4) : 0;
> +       num_levels = levels ? (levels->length / 4) : 0;
>
>         if (num_funcs > 1 && num_funcs != num_pins) {
>                 dev_err(pc->dev,
> @@ -770,11 +800,20 @@ static int bcm2835_pctl_dt_node_to_map(struct pinctrl_dev *pctldev,
>                 return -EINVAL;
>         }
>
> +       if (num_levels > 1 && num_levels != num_pins) {
> +               dev_err(pc->dev,
> +                       "%pOF: brcm,level must have 1 or %d entries\n",
> +                       np, num_pins);
> +               return -EINVAL;
> +       }
> +
>         maps_per_pin = 0;
>         if (num_funcs)
>                 maps_per_pin++;
>         if (num_pulls)
>                 maps_per_pin++;
> +       if (num_levels)
> +               maps_per_pin++;
>         cur_map = maps = kzalloc(num_pins * maps_per_pin * sizeof(*maps),
>                                 GFP_KERNEL);
>         if (!maps)
> @@ -811,6 +850,17 @@ static int bcm2835_pctl_dt_node_to_map(struct pinctrl_dev *pctldev,
>                         if (err)
>                                 goto out;
>                 }
> +               if (num_levels) {
> +                       err = of_property_read_u32_index(np, "brcm,level",
> +                                       (num_levels > 1) ? i : 0, &level);
> +                       if (err)
> +                               goto out;
> +
> +                       err = bcm2835_pctl_dt_node_to_map_level(pc, np, pin,
> +                                                       level, &cur_map);
> +                       if (err)
> +                               goto out;
> +               }
>         }
>
>         *map = maps;
> @@ -931,23 +981,25 @@ static int bcm2835_pinconf_set(struct pinctrl_dev *pctldev,
>                 param = BCM2835_PINCONF_UNPACK_PARAM(configs[i]);
>                 arg = BCM2835_PINCONF_UNPACK_ARG(configs[i]);
>
> -               if (param != BCM2835_PINCONF_PARAM_PULL)
> +               if (param == BCM2835_PINCONF_PARAM_PULL) {
> +                       off = GPIO_REG_OFFSET(pin);
> +                       bit = GPIO_REG_SHIFT(pin);
> +
> +                       bcm2835_gpio_wr(pc, GPPUD, arg & 3);
> +                       /*
> +                       * Docs say to wait 150 cycles, but not of what. We assume a
> +                       * 1 MHz clock here, which is pretty slow...
> +                       */
> +                       udelay(150);
> +                       bcm2835_gpio_wr(pc, GPPUDCLK0 + (off * 4), BIT(bit));
> +                       udelay(150);
> +                       bcm2835_gpio_wr(pc, GPPUDCLK0 + (off * 4), 0);
> +               } else if (param == BCM2835_PINCONF_PARAM_LEVEL) {
> +                       /* write in register */
> +                       bcm2835_gpio_set_bit(pc, arg ? GPSET0 : GPCLR0, pin);
> +               } else {
>                         return -EINVAL;
> -
> -               off = GPIO_REG_OFFSET(pin);
> -               bit = GPIO_REG_SHIFT(pin);
> -
> -               bcm2835_gpio_wr(pc, GPPUD, arg & 3);
> -               /*
> -                * BCM2835 datasheet say to wait 150 cycles, but not of what.
> -                * But the VideoCore firmware delay for this operation
> -                * based nearly on the same amount of VPU cycles and this clock
> -                * runs at 250 MHz.
> -                */
> -               udelay(1);
> -               bcm2835_gpio_wr(pc, GPPUDCLK0 + (off * 4), BIT(bit));
> -               udelay(1);
> -               bcm2835_gpio_wr(pc, GPPUDCLK0 + (off * 4), 0);
> +               }
>         } /* for each config */
>
>         return 0;
> --
> 2.7.4
>

       reply	other threads:[~2018-03-02 10:14 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1519321475-973-1-git-send-email-matheus@castello.eng.br>
2018-03-02 10:14 ` Linus Walleij [this message]
2018-03-03 14:21 ` [PATCH] pinctrl: bc2835: Add brcm,level property Stefan Wahren
2018-03-05  2:29   ` [PATCH v2 0/3] pinctrl: bcm2835: " Matheus Castello
2018-03-05  2:29     ` [PATCH v2 1/3] pinctrl: bcm2835: switch to GENERIC_PINCONF Matheus Castello
2018-03-07 11:51       ` Stefan Wahren
2018-03-05  2:29     ` [PATCH v2 2/3] pinctrl: bcm2835: Add support for generic pinctrl binding Matheus Castello
2018-03-05 23:21       ` Eric Anholt
2018-03-07  3:28         ` Matheus Castello
2018-03-05  2:29     ` [PATCH v2 3/3] pinctrl: bcm2835: Add support for output-low output-high properties Matheus Castello
2018-03-07 11:58     ` [PATCH v2 0/3] pinctrl: bcm2835: Add brcm,level property Stefan Wahren
2018-03-08  0:12       ` Matheus Castello
2018-03-08  8:00         ` Stefan Wahren
2018-03-08 19:47           ` Matheus Castello
2018-03-09  4:16             ` [PATCH v3 " Matheus Castello
2018-03-09  4:16               ` [PATCH v3 1/3] pinctrl: bcm2835: Add support for generic pinctrl binding Matheus Castello
2018-03-09  4:16               ` [PATCH v3 2/3] pinctrl: bcm2835: Add support for output-low output-high properties Matheus Castello
2018-03-09  4:16               ` [PATCH v3 3/3] pinctrl: bcm2835: Update docs about generic pinctrl bindings support Matheus Castello
2018-03-09 11:46                 ` Stefan Wahren
2018-03-09 17:13                   ` [PATCH v4 0/3] pinctrl: bcm2835: Add generic pinctrl support Matheus Castello
2018-03-09 17:13                     ` [PATCH v4 1/3] dt-bindings: pinctrl: bcm2835-gpio: " Matheus Castello
2018-03-18 12:48                       ` Rob Herring
2018-03-18 15:23                         ` Matheus Castello
2018-04-11  4:58                           ` [PATCH v5 0/3] pinctrl: bcm2835: " Matheus Castello
2018-04-11  4:58                             ` [PATCH v5 1/3] dt-bindings: pinctrl: bcm2835-gpio: " Matheus Castello
2018-04-11 16:02                               ` Eric Anholt
2018-04-16 15:06                               ` Rob Herring
2018-04-26 12:21                               ` Linus Walleij
2018-04-11  4:58                             ` [PATCH v5 2/3] pinctrl: bcm2835: Add support for generic pinctrl binding Matheus Castello
2018-04-21 10:30                               ` Stefan Wahren
2018-04-22 12:44                               ` Stefan Wahren
2018-04-26 12:24                               ` Linus Walleij
2018-04-11  4:58                             ` [PATCH v5 3/3] pinctrl: bcm2835: Add support for output-low output-high properties Matheus Castello
2018-04-26 12:25                               ` Linus Walleij
2018-04-29 19:28                                 ` [PATCH v6 0/3] bcm2835: Add generic pinctrl support Matheus Castello
2018-04-29 19:28                                   ` [PATCH v6 2/3] pinctrl: bcm2835: Add support for generic pinctrl binding Matheus Castello
2018-04-29 19:28                                   ` [PATCH v6 3/3] pinctrl: bcm2835: Add support for output-low output-high properties Matheus Castello
2018-05-01  0:42                                     ` [PATCH v7 0/3] bcm2835: Add generic pinctrl support Matheus Castello
2018-05-01  0:42                                       ` [PATCH v7 2/3] pinctrl: bcm2835: Add support for generic pinctrl binding Matheus Castello
2018-05-03 17:38                                         ` Stefan Wahren
2018-05-12  9:08                                           ` Stefan Wahren
2018-05-16 12:00                                         ` Linus Walleij
2018-05-01  0:42                                       ` [PATCH v7 3/3] pinctrl: bcm2835: Add support for output-low output-high properties Matheus Castello
2018-05-16 12:02                                         ` Linus Walleij
2018-03-09 17:13                     ` [PATCH v4 2/3] pinctrl: bcm2835: Add support for generic pinctrl binding Matheus Castello
2018-03-12 18:03                       ` Eric Anholt
2018-03-09 17:14                     ` [PATCH v4 3/3] pinctrl: bcm2835: Add support for output-low output-high properties Matheus Castello

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='CACRpkdZc0ataQGWQ-81v1+_wCRpv=VVk195rafJcEQUFM5xfOg@mail.gmail.com' \
    --to=linus.walleij@linaro.org \
    --cc=devicetree@vger.kernel.org \
    --cc=eric@anholt.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matheus@castello.eng.br \
    --cc=robh+dt@kernel.org \
    --cc=stefan.wahren@i2se.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).