From patchwork Thu Jul 30 17:55:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Griffin X-Patchwork-Id: 51715 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f70.google.com (mail-la0-f70.google.com [209.85.215.70]) by patches.linaro.org (Postfix) with ESMTPS id 4CAD322DB5 for ; Thu, 30 Jul 2015 17:55:35 +0000 (UTC) Received: by lahh5 with SMTP id h5sf14778543lah.0 for ; Thu, 30 Jul 2015 10:55:34 -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=cOvsO6feFsPn6O4F4RH0wgj9ucuTmLvljVLeIL2rh0xkwYiLxs4oC9JEnf2GyFlAc7 dTgSntsoWZkfaTn4NiyO95EqSOpOuozw3pszzXk+JXjBpY7pEIodIKrRMHCw+gb1k/qv CYqCFo0WaxPYY0ww87Yx3G9zFlVGnjUnWGMo5wMOaRbWOz6a9dxEGDkk7kFTvpEnaoCe /csqGIBSN4XTlfDMDhT3/C62bc+m+XJd0tSP9CwwMc8MpyL4v5NOdJqvB1FZzNm+o1xk O4y2g/nfLc/6ssup+Uzh367Jy9kr/4pVeHkU8AiLBIGCcYEHZ6cVJIHebdxUcIQTz2mE XvGA== X-Gm-Message-State: ALoCoQlq+2MoGC2j5BMOE7r+WgIXBdkwLKIA9Zl3qcxeMhSgPN8zyHO8zOwFQuo9T/JmRU0OomRX X-Received: by 10.112.189.131 with SMTP id gi3mr18258575lbc.6.1438278934342; Thu, 30 Jul 2015 10:55:34 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.1.233 with SMTP id 9ls217741lap.39.gmail; Thu, 30 Jul 2015 10:55:34 -0700 (PDT) X-Received: by 10.152.1.4 with SMTP id 4mr46143281lai.25.1438278934191; Thu, 30 Jul 2015 10:55:34 -0700 (PDT) Received: from mail-la0-f46.google.com (mail-la0-f46.google.com. [209.85.215.46]) by mx.google.com with ESMTPS id pc7si1380656lbb.120.2015.07.30.10.55.34 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Jul 2015 10:55:34 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) client-ip=209.85.215.46; Received: by lafd3 with SMTP id d3so29792527laf.1 for ; Thu, 30 Jul 2015 10:55:34 -0700 (PDT) X-Received: by 10.152.6.69 with SMTP id y5mr45003439lay.72.1438278934095; Thu, 30 Jul 2015 10:55:34 -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 l6csp764863lba; Thu, 30 Jul 2015 10:55:33 -0700 (PDT) X-Received: by 10.180.87.230 with SMTP id bb6mr8284700wib.36.1438278933091; Thu, 30 Jul 2015 10:55:33 -0700 (PDT) Received: from mail-wi0-f179.google.com (mail-wi0-f179.google.com. [209.85.212.179]) by mx.google.com with ESMTPS id wu10si3162390wjb.190.2015.07.30.10.55.32 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Jul 2015 10:55:33 -0700 (PDT) Received-SPF: pass (google.com: domain of peter.griffin@linaro.org designates 209.85.212.179 as permitted sender) client-ip=209.85.212.179; Received: by wibud3 with SMTP id ud3so30443649wib.1 for ; Thu, 30 Jul 2015 10:55:32 -0700 (PDT) X-Received: by 10.180.20.15 with SMTP id j15mr8723533wie.76.1438278932682; Thu, 30 Jul 2015 10:55:32 -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 lm5sm257774wic.22.2015.07.30.10.55.31 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 30 Jul 2015 10:55:32 -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 v4 2/9] dm: gpio: hi6220: Add a hi6220 GPIO driver model driver. Date: Thu, 30 Jul 2015 18:55:18 +0100 Message-Id: <1438278925-3038-3-git-send-email-peter.griffin@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1438278925-3038-1-git-send-email-peter.griffin@linaro.org> References: <1438278925-3038-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.46 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), +}; + +