All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 1/6] dm: gpio: hi6220: Add a hi6220 GPIO driver model driver.
Date: Sat, 18 Jul 2015 08:37:51 -0600	[thread overview]
Message-ID: <CAPnjgZ2b=mZMv8SigMZXg5j-Wz+VvzXPLTO-ZXB-i76kRQrSgw@mail.gmail.com> (raw)
In-Reply-To: <1436371040-26620-2-git-send-email-peter.griffin@linaro.org>

Hi Peter,

On 8 July 2015 at 09:57, Peter Griffin <peter.griffin@linaro.org> wrote:
> This patch adds support for the GPIO perif found on hi6220
> SoC.
>
> Signed-off-by: Peter Griffin <peter.griffin@linaro.org>
> ---
>  arch/arm/include/asm/arch-hi6220/gpio.h | 29 ++++++++++
>  drivers/gpio/Makefile                   |  2 +
>  drivers/gpio/hi6220_gpio.c              | 95 +++++++++++++++++++++++++++++++++
>  3 files changed, 126 insertions(+)
>  create mode 100644 arch/arm/include/asm/arch-hi6220/gpio.h
>  create mode 100644 drivers/gpio/hi6220_gpio.c
>
> diff --git a/arch/arm/include/asm/arch-hi6220/gpio.h b/arch/arm/include/asm/arch-hi6220/gpio.h
> new file mode 100644
> index 0000000..98122a2
> --- /dev/null
> +++ b/arch/arm/include/asm/arch-hi6220/gpio.h
> @@ -0,0 +1,29 @@
> +/*
> + * Copyright (C) 2015 Linaro
> + * Peter Griffin <peter.griffin@linaro.org>
> + *
> + * SPDX-License-Identifier:    GPL-2.0+
> + */
> +
> +#ifndef _HI6220_GPIO_H_
> +#define _HI6220_GPIO_H_
> +
> +#define HI6220_GPIO_BASE(bank) (((bank < 4) ? 0xf8011000 : \
> +                               0xf7020000 - 0x4000) + (0x1000 * bank))
> +
> +#define BIT(x)                 (1 << (x))

I thought we had this in U-Boot now but cannot find it.

> +
> +#define HI6220_GPIO_PER_BANK   8
> +#define HI6220_GPIO_DIR                0x400
> +
> +struct gpio_bank {
> +       u8 *base;       /* address of registers in physical memory */
> +};

We should use a C struct to access registers. See here:

http://www.denx.de/wiki/U-Boot/CodingStyle

> +
> +/* Information about a GPIO bank */
> +struct hikey_gpio_platdata {
> +       int bank_index;
> +       unsigned int base;     /* address of registers in physical memory */
> +};
> +
> +#endif /* _HI6220_GPIO_H_ */
> diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
> index 5864850..b470bab 100644
> --- a/drivers/gpio/Makefile
> +++ b/drivers/gpio/Makefile
> @@ -46,3 +46,5 @@ obj-$(CONFIG_LPC32XX_GPIO)    += lpc32xx_gpio.o
>  obj-$(CONFIG_STM32_GPIO)       += stm32_gpio.o
>  obj-$(CONFIG_ZYNQ_GPIO)                += zynq_gpio.o
>  obj-$(CONFIG_VYBRID_GPIO)      += vybrid_gpio.o
> +obj-$(CONFIG_HIKEY_GPIO)       += hi6220_gpio.o
> +
> diff --git a/drivers/gpio/hi6220_gpio.c b/drivers/gpio/hi6220_gpio.c
> new file mode 100644
> index 0000000..3f41bff
> --- /dev/null
> +++ b/drivers/gpio/hi6220_gpio.c
> @@ -0,0 +1,95 @@
> +/*
> + * Copyright (C) 2015 Linaro
> + * Peter Griffin <peter.griffin@linaro.org>
> + *
> + * SPDX-License-Identifier:    GPL-2.0+
> + */
> +
> +#include <common.h>
> +#include <dm.h>
> +#include <asm/gpio.h>
> +#include <asm/io.h>
> +#include <errno.h>
> +
> +static int hi6220_gpio_direction_input(struct udevice *dev, unsigned int gpio)
> +{
> +       struct gpio_bank *bank = dev_get_priv(dev);
> +       u8 data;
> +
> +       data = readb(bank->base + HI6220_GPIO_DIR);
> +       data &= ~(1 << gpio);
> +       writeb(data, bank->base + HI6220_GPIO_DIR);

Something like this:

clrbits_8(&regs->gpio_dir, 1 << gpio)

> +
> +       return 0;
> +}
> +
> +static int hi6220_gpio_set_value(struct udevice *dev, unsigned gpio,
> +                                 int value)
> +{
> +       struct gpio_bank *bank = dev_get_priv(dev);
> +
> +       writeb(!!value << gpio, bank->base + (BIT(gpio + 2)));

Ick, use struct access.

> +       return 0;
> +}
> +
> +static int hi6220_gpio_direction_output(struct udevice *dev, unsigned gpio,
> +                                       int value)
> +{
> +       struct gpio_bank *bank = dev_get_priv(dev);
> +       u8 data;
> +
> +       data = readb(bank->base + HI6220_GPIO_DIR);
> +       data |= 1 << gpio;
> +       writeb(data, bank->base + HI6220_GPIO_DIR);
> +
> +       hi6220_gpio_set_value(dev, gpio, value);
> +
> +       return 0;
> +}
> +
> +static int hi6220_gpio_get_value(struct udevice *dev, unsigned gpio)
> +{
> +       struct gpio_bank *bank = dev_get_priv(dev);
> +
> +       return !!readb(bank->base + (BIT(gpio + 2)));
> +}
> +
> +
> +
> +static const struct dm_gpio_ops gpio_hi6220_ops = {
> +       .direction_input        = hi6220_gpio_direction_input,
> +       .direction_output       = hi6220_gpio_direction_output,
> +       .get_value              = hi6220_gpio_get_value,
> +       .set_value              = hi6220_gpio_set_value,
> +};
> +
> +static int hi6220_gpio_probe(struct udevice *dev)
> +{
> +       struct gpio_bank *bank = dev_get_priv(dev);
> +       struct hikey_gpio_platdata *plat = dev_get_platdata(dev);
> +       struct gpio_dev_priv *uc_priv = dev->uclass_priv;
> +       char name[18], *str;
> +
> +       sprintf(name, "GPIO%d_", plat->bank_index);

Could use just use 'GP' or 'P'? This seems quite long as a name. Also
I don't think you want the %d.
> +
> +       str = strdup(name);
> +       if (!str)
> +               return -ENOMEM;
> +
> +       uc_priv->bank_name = str;
> +       uc_priv->gpio_count = HI6220_GPIO_PER_BANK;
> +
> +       bank->base = (u8 *)plat->base;
> +
> +       return 0;
> +}
> +
> +U_BOOT_DRIVER(gpio_hi6220) = {
> +       .name   = "gpio_hi6220",
> +       .id     = UCLASS_GPIO,
> +       .ops    = &gpio_hi6220_ops,
> +       .probe  = hi6220_gpio_probe,
> +       .priv_auto_alloc_size = sizeof(struct gpio_bank),
> +};
> +
> +
> --
> 1.9.1
>

Regards,
Simon

  reply	other threads:[~2015-07-18 14:37 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-08 15:57 [U-Boot] [PATCH v2 0/6] Add support for hi6220 SoC and HiKey 96boards CE board Peter Griffin
2015-07-08 15:57 ` [U-Boot] [PATCH v2 1/6] dm: gpio: hi6220: Add a hi6220 GPIO driver model driver Peter Griffin
2015-07-18 14:37   ` Simon Glass [this message]
2015-07-08 15:57 ` [U-Boot] [PATCH v2 2/6] ARM: hi6220: Add register and bitfield definition header files Peter Griffin
2015-07-18 14:37   ` Simon Glass
2015-07-29 21:07     ` Peter Griffin
2015-07-08 15:57 ` [U-Boot] [PATCH v2 3/6] hi6553: Add register definition and bitfield header for 6553 pmic Peter Griffin
2015-07-18 14:37   ` Simon Glass
2015-07-29 21:04     ` Peter Griffin
2015-07-08 15:57 ` [U-Boot] [PATCH v2 4/6] mmc: hi6220_dw_mmc: Add hi6220 glue code for dw_mmc controller Peter Griffin
2015-07-09  4:30   ` Jaehoon Chung
2015-07-18 14:38   ` Simon Glass
2015-07-19  9:39     ` Peter Griffin
2015-07-20  2:17       ` Simon Glass
2015-07-08 15:57 ` [U-Boot] [PATCH v2 5/6] ARM64: hikey: hi6220: Add u-boot support for the 96boards CE HiKey board Peter Griffin
2015-07-10 18:36   ` Rob Herring
2015-07-16  0:41     ` Peter Griffin
2015-07-16 13:28       ` Rob Herring
2015-07-16 13:39         ` Tom Rini
2015-07-29 20:59         ` Peter Griffin
2015-07-18 14:38   ` Simon Glass
2015-07-28 17:37     ` Peter Griffin
2015-07-08 15:57 ` [U-Boot] [PATCH v2 6/6] ARM64: hikey: Add a README for this board Peter Griffin

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='CAPnjgZ2b=mZMv8SigMZXg5j-Wz+VvzXPLTO-ZXB-i76kRQrSgw@mail.gmail.com' \
    --to=sjg@chromium.org \
    --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.