From: Lukasz Majewski <lukma@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 19/26] power: Add a GPIO driver for the as3722 PMIC
Date: Sun, 21 May 2017 01:40:49 +0200 [thread overview]
Message-ID: <20170521014049.724b0f9e@jawa> (raw)
In-Reply-To: <20170519143109.21683-20-sjg@chromium.org>
On Fri, 19 May 2017 08:31:02 -0600
Simon Glass <sjg@chromium.org> wrote:
> This pmic includes GPIOs which should have their own driver. Add
> a driver to support these.
Reviewed-by: Lukasz Majewski <lukma@denx.de>
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
> drivers/power/pmic/as3722_gpio.c | 120
> +++++++++++++++++++++++++++++++++++++++
> include/power/as3722.h | 5 ++ 2 files changed, 125
> insertions(+) create mode 100644 drivers/power/pmic/as3722_gpio.c
>
> diff --git a/drivers/power/pmic/as3722_gpio.c
> b/drivers/power/pmic/as3722_gpio.c new file mode 100644
> index 0000000000..d0b681ca4a
> --- /dev/null
> +++ b/drivers/power/pmic/as3722_gpio.c
> @@ -0,0 +1,120 @@
> +/*
> + * Copyright (C) 2014 NVIDIA Corporation
> + *
> + * SPDX-License-Identifier: GPL-2.0+
> + */
> +
> +#include <common.h>
> +#include <dm.h>
> +#include <asm/gpio.h>
> +#include <power/as3722.h>
> +#include <power/pmic.h>
> +
> +#define NUM_GPIOS 8
> +
> +int as3722_gpio_configure(struct udevice *pmic, unsigned int gpio,
> + unsigned long flags)
> +{
> + u8 value = 0;
> + int err;
> +
> + if (flags & AS3722_GPIO_OUTPUT_VDDH)
> + value |= AS3722_GPIO_CONTROL_MODE_OUTPUT_VDDH;
> +
> + if (flags & AS3722_GPIO_INVERT)
> + value |= AS3722_GPIO_CONTROL_INVERT;
> +
> + err = pmic_reg_write(pmic, AS3722_GPIO_CONTROL(gpio), value);
> + if (err) {
> + error("failed to configure GPIO#%u: %d", gpio, err);
> + return err;
> + }
> +
> + return 0;
> +}
> +
> +static int as3722_gpio_set_value(struct udevice *dev, unsigned int
> gpio,
> + int level)
> +{
> + struct udevice *pmic = dev_get_parent(dev);
> + const char *l;
> + u8 value;
> + int err;
> +
> + if (gpio >= NUM_GPIOS)
> + return -EINVAL;
> +
> + err = pmic_reg_read(pmic, AS3722_GPIO_SIGNAL_OUT);
> + if (err < 0) {
> + error("failed to read GPIO signal out register: %d",
> err);
> + return err;
> + }
> + value = err;
> +
> + if (level == 0) {
> + value &= ~(1 << gpio);
> + l = "low";
> + } else {
> + value |= 1 << gpio;
> + l = "high";
> + }
> +
> + err = pmic_reg_write(pmic, AS3722_GPIO_SIGNAL_OUT, value);
> + if (err) {
> + error("failed to set GPIO#%u %s: %d", gpio, l, err);
> + return err;
> + }
> +
> + return 0;
> +}
> +
> +int as3722_gpio_direction_output(struct udevice *dev, unsigned int
> gpio,
> + int value)
> +{
> + struct udevice *pmic = dev_get_parent(dev);
> + int err;
> +
> + if (gpio > 7)
> + return -EINVAL;
> +
> + if (value == 0)
> + value = AS3722_GPIO_CONTROL_MODE_OUTPUT_VDDL;
> + else
> + value = AS3722_GPIO_CONTROL_MODE_OUTPUT_VDDH;
> +
> + err = pmic_reg_write(pmic, AS3722_GPIO_CONTROL(gpio), value);
> + if (err) {
> + error("failed to configure GPIO#%u as output: %d",
> gpio, err);
> + return err;
> + }
> +
> + err = as3722_gpio_set_value(pmic, gpio, value);
> + if (err < 0) {
> + error("failed to set GPIO#%u high: %d", gpio, err);
> + return err;
> + }
> +
> + return 0;
> +}
> +
> +static int as3722_gpio_probe(struct udevice *dev)
> +{
> + struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
> +
> + uc_priv->gpio_count = NUM_GPIOS;
> + uc_priv->bank_name = "as3722_";
> +
> + return 0;
> +}
> +
> +static const struct dm_gpio_ops gpio_as3722_ops = {
> + .direction_output = as3722_gpio_direction_output,
> + .set_value = as3722_gpio_set_value,
> +};
> +
> +U_BOOT_DRIVER(gpio_as3722) = {
> + .name = "gpio_as3722",
> + .id = UCLASS_GPIO,
> + .ops = &gpio_as3722_ops,
> + .probe = as3722_gpio_probe,
> +};
> diff --git a/include/power/as3722.h b/include/power/as3722.h
> index 14afa0c81a..713e79840f 100644
> --- a/include/power/as3722.h
> +++ b/include/power/as3722.h
> @@ -20,6 +20,11 @@
> #define AS3722_ASIC_ID1 0x90
> #define AS3722_ASIC_ID2 0x91
>
> +#define AS3722_GPIO_CONTROL(n) (0x08 + (n))
> +#define AS3722_GPIO_CONTROL_MODE_OUTPUT_VDDH (1 << 0)
> +#define AS3722_GPIO_CONTROL_MODE_OUTPUT_VDDL (7 << 0)
> +#define AS3722_GPIO_CONTROL_INVERT (1 << 7)
> +
> struct udevice;
>
> int as3722_init(struct udevice **devp);
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
next prev parent reply other threads:[~2017-05-20 23:40 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-19 14:30 [U-Boot] [PATCH 00/26] dm: tegra: Move nyan-big to livetree Simon Glass
2017-05-19 14:30 ` [U-Boot] [PATCH 01/26] dm: video: Sync display on backspace Simon Glass
2017-05-19 14:53 ` Anatolij Gustschin
2017-05-19 14:30 ` [U-Boot] [PATCH 02/26] dm: video: Update pwm_backlight to support livetree Simon Glass
2017-05-19 14:55 ` Anatolij Gustschin
2017-05-19 14:30 ` [U-Boot] [PATCH 03/26] video: simple-panel: Add a little more debugging Simon Glass
2017-05-19 14:56 ` Anatolij Gustschin
2017-05-19 14:30 ` [U-Boot] [PATCH 04/26] tegra: Fix up include file ordering Simon Glass
2017-05-19 14:30 ` [U-Boot] [PATCH 05/26] tegra: spl: Enable debug UART Simon Glass
2017-05-19 14:30 ` [U-Boot] [PATCH 06/26] tegra: nyan: Add a PMC syscon driver Simon Glass
2017-05-19 14:30 ` [U-Boot] [PATCH 07/26] dm: tegra: Convert USB setup to livetree Simon Glass
2017-05-19 14:30 ` [U-Boot] [PATCH 08/26] dm: tegra: Convert clock_decode_periph_id() to support livetree Simon Glass
2017-05-19 14:30 ` [U-Boot] [PATCH 09/26] dm: video: tegra124: Convert to livetree Simon Glass
2017-05-19 15:02 ` Anatolij Gustschin
2017-05-19 14:30 ` [U-Boot] [PATCH 10/26] tegra: dts: Move stdout-path to /chosen Simon Glass
2017-05-19 14:30 ` [U-Boot] [PATCH 11/26] tegra: Don't set up the UART clocks again in U-Boot Simon Glass
2017-05-19 14:30 ` [U-Boot] [PATCH 12/26] dm: tegra: gpio: Convert to support livetree Simon Glass
2017-05-19 14:30 ` [U-Boot] [PATCH 13/26] dm: tegra: usb: Convert to livetree Simon Glass
2017-05-19 14:30 ` [U-Boot] [PATCH 14/26] dm: tegra: spi: " Simon Glass
2017-05-19 14:30 ` [U-Boot] [PATCH 15/26] dm: tegra: i2c: " Simon Glass
2017-05-19 14:30 ` [U-Boot] [PATCH 16/26] dm: tegra: pwm: " Simon Glass
2017-05-19 14:31 ` [U-Boot] [PATCH 17/26] dm: tegra: mmc: " Simon Glass
2017-05-19 14:31 ` [U-Boot] [PATCH 18/26] power: Add a regulator driver for the as3722 PMIC Simon Glass
2017-05-20 23:40 ` Lukasz Majewski
2017-05-19 14:31 ` [U-Boot] [PATCH 19/26] power: Add a GPIO " Simon Glass
2017-05-20 23:40 ` Lukasz Majewski [this message]
2017-05-19 14:31 ` [U-Boot] [PATCH 20/26] dm: power: Convert as3722 to driver model Simon Glass
2017-05-20 23:41 ` Lukasz Majewski
2017-05-19 14:31 ` [U-Boot] [PATCH 21/26] dm: serial: ns16550: Convert to livetree Simon Glass
2017-05-19 14:31 ` [U-Boot] [PATCH 22/26] dm: serial: Separate out the core serial-device finding code Simon Glass
2017-05-19 14:31 ` [U-Boot] [PATCH 23/26] dm: serial: Add livetree support Simon Glass
2017-05-19 14:31 ` [U-Boot] [PATCH 24/26] tegra: Show a debug message if the LCD PMIC fails to start Simon Glass
2017-05-19 14:31 ` [U-Boot] [PATCH 25/26] fdtdec: Drop old compatible values Simon Glass
2017-05-19 14:31 ` [U-Boot] [PATCH 26/26] dm: tegra: nyan-big: Move to livetree Simon Glass
2017-05-29 15:08 ` Marcel Ziswiler
2017-06-01 3:11 ` Simon Glass
2017-05-22 22:15 ` [U-Boot] [PATCH 00/26] dm: tegra: Move nyan-big " Tom Rini
2017-05-24 0:44 ` Simon Glass
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=20170521014049.724b0f9e@jawa \
--to=lukma@denx.de \
--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