From patchwork Wed Jul 29 21:39:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Griffin X-Patchwork-Id: 51669 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by patches.linaro.org (Postfix) with ESMTPS id CA0EB22DB5 for ; Wed, 29 Jul 2015 21:39:46 +0000 (UTC) Received: by wixh2 with SMTP id h2sf11509759wix.0 for ; Wed, 29 Jul 2015 14:39:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=Xgjqo8PMZPXTncBJ3NQXG9MFj0o9qEA/IvBx/lqRM2Y=; b=XwcjNYzT2PdfSX9JzkPqhkI5nKFMI+oZHESdYQRuWN2JhRtegQWG+LIUlt9Qf3WkUc /82q31Xx+OhNZ7Q9RyogQz+WmfGHCc7bnLWXC2o0QyPYhIimhwluoQ7TGROfONJbL6+m 5unRdWPbCz+0pxvIZbqF4O8H2o96/LafP9X5CWe500QHXS7RbaAPf8KN7RXBarECkzr1 tE/vB7+R+/3zLutOwqd6tgDf4FoxzZpbw1n8KO+/rvL5McSjgOyymZgDLLVRNdHyi2nH r52vKEUEC/Gd3hPtnZ3DuZela8tAXA1d0RcQctkGeX3XsO0ySEsubdNnBC22rVbuB9NO yPow== X-Gm-Message-State: ALoCoQlhoeFLzDEUsHUqXU5TJvyiegflHI+cGpzrTCPXrZqUAPCkt3iRRNwbL+i+OlPANhwuYEJB X-Received: by 10.112.51.177 with SMTP id l17mr16758491lbo.1.1438205986151; Wed, 29 Jul 2015 14:39:46 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.44.169 with SMTP id f9ls104187lam.93.gmail; Wed, 29 Jul 2015 14:39:46 -0700 (PDT) X-Received: by 10.152.36.41 with SMTP id n9mr41370521laj.79.1438205986004; Wed, 29 Jul 2015 14:39:46 -0700 (PDT) Received: from mail-la0-f51.google.com (mail-la0-f51.google.com. [209.85.215.51]) by mx.google.com with ESMTPS id l7si22603605lbb.19.2015.07.29.14.39.45 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Jul 2015 14:39:45 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) client-ip=209.85.215.51; Received: by laah7 with SMTP id h7so14199241laa.0 for ; Wed, 29 Jul 2015 14:39:45 -0700 (PDT) X-Received: by 10.152.25.228 with SMTP id f4mr40282959lag.112.1438205985910; Wed, 29 Jul 2015 14:39:45 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.7.198 with SMTP id l6csp119961lba; Wed, 29 Jul 2015 14:39:45 -0700 (PDT) X-Received: by 10.194.78.230 with SMTP id e6mr78514508wjx.43.1438205984896; Wed, 29 Jul 2015 14:39:44 -0700 (PDT) Received: from mail-wi0-f182.google.com (mail-wi0-f182.google.com. [209.85.212.182]) by mx.google.com with ESMTPS id hf10si29499279wib.2.2015.07.29.14.39.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Jul 2015 14:39:44 -0700 (PDT) Received-SPF: pass (google.com: domain of peter.griffin@linaro.org designates 209.85.212.182 as permitted sender) client-ip=209.85.212.182; Received: by wibxm9 with SMTP id xm9so44014900wib.1 for ; Wed, 29 Jul 2015 14:39:44 -0700 (PDT) X-Received: by 10.180.206.176 with SMTP id lp16mr20967326wic.85.1438205984635; Wed, 29 Jul 2015 14:39:44 -0700 (PDT) Received: from localhost.localdomain (cpc14-aztw22-2-0-cust189.18-1.cable.virginm.net. [82.45.1.190]) by smtp.gmail.com with ESMTPSA id h9sm40559615wjx.20.2015.07.29.14.39.43 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 29 Jul 2015 14:39:43 -0700 (PDT) From: Peter Griffin To: u-boot@lists.denx.de, albert.u.boot@aribaud.net, trini@konsulko.com, panto@antoniou-consulting.com, marex@denx.de, sjg@chromium.org, robherring2@gmail.com Cc: Peter Griffin Subject: [PATCH v3 2/8] dm: gpio: hi6220: Add a hi6220 GPIO driver model driver. Date: Wed, 29 Jul 2015 22:39:30 +0100 Message-Id: <1438205976-11105-3-git-send-email-peter.griffin@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1438205976-11105-1-git-send-email-peter.griffin@linaro.org> References: <1438205976-11105-1-git-send-email-peter.griffin@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.griffin@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , This patch adds support for the GPIO perif found on hi6220 SoC. Signed-off-by: Peter Griffin --- 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 + * + * 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)) + +#define HI6220_GPIO_PER_BANK 8 +#define HI6220_GPIO_DIR 0x400 + +struct gpio_bank { + u8 *base; /* address of registers in physical memory */ +}; + +/* 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 + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include +#include +#include +#include + +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); + + 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))); + 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); + + 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), +}; + +