From patchwork Tue Oct 1 17:00:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sagar Shrikant Kadam X-Patchwork-Id: 1170077 X-Patchwork-Delegate: uboot@andestech.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.b="YGB4RDGV"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 46jQXz38Nhz9sCJ for ; Wed, 2 Oct 2019 03:01:54 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id A09A6C21DD7; Tue, 1 Oct 2019 17:01:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id BE655C21D8E; Tue, 1 Oct 2019 17:01:17 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 619E2C21CB6; Tue, 1 Oct 2019 17:01:10 +0000 (UTC) Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) by lists.denx.de (Postfix) with ESMTPS id 5C12BC21C3F for ; Tue, 1 Oct 2019 17:01:06 +0000 (UTC) Received: by mail-pf1-f195.google.com with SMTP id q21so8424165pfn.11 for ; Tue, 01 Oct 2019 10:01:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=p0EUZo6NeH++WB5Rt6MUBUk7Gc0amGexCsr4QT3JR5w=; b=YGB4RDGVeg2xdHM9WknVlG8cBd4S0JSYpTn/qX6CxzBWma4AmKEElC/RdjK/SZqC8W 0j89G/GSRy1cCNwZtU+/FmvbokYsjAsqD6+QiFtrwB9Sth35rqk13xUnUpJ8tnWdUdhM qq7C3TJTDhYqBo3xNea23fszrBfYXlZfwDN9GemB474IZSs8X2wJLQiSCnEW0Cv9STKX W0tV1V5CQPOJUsAejnH1AyigQ7hNWePMfDIIa1jROMSPN/J0/vkojUsvhtAW0pf5RdUi rjUIMgb4AX6ssk8IW74VR1T68Q/gWMoyaWcHE9SRCxWJchiKQRqCQiYbXyRRngvamTkx Kphg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=p0EUZo6NeH++WB5Rt6MUBUk7Gc0amGexCsr4QT3JR5w=; b=BZ1BlZGAOQ3bLJNPDHTLae2AJXBbbDaQQM4wTowqHQPQ0D9ywBhYe7HxohDVn3EpoD nk9H0qsmEN5gdbrWytfkIAAXIRbW/BCWylDTnjUj3yDLLgZpnFlcZfQsPxAJ5UVPMyWE 3r5CX9u35RWRuxPq1VVbZvBbMV0vJS0k/cdQYeUmRO+Y9A8GGyOHJUFLgwKaf0pg0ElS vev/8lciHuajZme6ZKkGD1Rjx1oD5l8h9yfENXajTSBgeq7mXhNS0G1kIJJP4a+WltN/ 8SVFMgP9cKtevyS/NMDtiVCkBQiZL+ijDMs8uFKG8mJtHeIuZaEfedpKmfVH0cqhNqZD MX/A== X-Gm-Message-State: APjAAAVaQFw6o6HABfHIaMArCxg/GV5yvpVs5RISKw2qwrW4M8VUxguH hlKt+r5yJwFln+uND/Otu7zvhb6Hw/4= X-Google-Smtp-Source: APXvYqz01uNAZ5Qt9udnko+hcR/pq6yq0VVE7gJhtvigj+01yKR2ng0KJhK+b3jSeFdDd2UrN7PXOw== X-Received: by 2002:a63:ba47:: with SMTP id l7mr30793001pgu.201.1569949264304; Tue, 01 Oct 2019 10:01:04 -0700 (PDT) Received: from gamma07.internal.sifive.com ([64.62.193.194]) by smtp.googlemail.com with ESMTPSA id k5sm26096667pfp.109.2019.10.01.10.01.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 01 Oct 2019 10:01:03 -0700 (PDT) From: Sagar Shrikant Kadam To: u-boot@lists.denx.de, rick@andestech.com, paul.walmsley@sifive.com, palmer@sifive.com, anup.patel@wdc.com, atish.patra@wdc.com Date: Tue, 1 Oct 2019 10:00:46 -0700 Message-Id: <1569949247-17895-2-git-send-email-sagar.kadam@sifive.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1569949247-17895-1-git-send-email-sagar.kadam@sifive.com> References: <1569949247-17895-1-git-send-email-sagar.kadam@sifive.com> Cc: wesley@sifive.com Subject: [U-Boot] [U-BOOT PATCH v2 1/2] gpio: sifive: add support for DM based gpio driver for FU540-SoC X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" This patch adds a DM based driver model for gpio controller present in FU540-C000 SoC on HiFive Unleashed A00 board. This SoC has one GPIO bank and 16 GPIO lines in total, out of which GPIO0 to GPIO9 and GPIO15 are routed to the J1 header on the board. This implementation is ported from linux based gpio driver submitted for review by Wesley W. Terpstra and/or Atish Patra (many thanks !!). The linux driver can be referred here [1] [1]: https://lkml.org/lkml/2018/10/9/1103 Signed-off-by: Sagar Shrikant Kadam Reviewed-by: Bin Meng --- arch/riscv/include/asm/arch-generic/gpio.h | 35 ++++++ arch/riscv/include/asm/gpio.h | 6 + drivers/gpio/Kconfig | 7 ++ drivers/gpio/Makefile | 1 + drivers/gpio/sifive-gpio.c | 177 +++++++++++++++++++++++++++++ 5 files changed, 226 insertions(+) create mode 100644 arch/riscv/include/asm/arch-generic/gpio.h create mode 100644 arch/riscv/include/asm/gpio.h create mode 100644 drivers/gpio/sifive-gpio.c diff --git a/arch/riscv/include/asm/arch-generic/gpio.h b/arch/riscv/include/asm/arch-generic/gpio.h new file mode 100644 index 0000000..dfcb753 --- /dev/null +++ b/arch/riscv/include/asm/arch-generic/gpio.h @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (C) 2019 SiFive, Inc. + */ + +#ifndef _GPIO_SIFIVE_H +#define _GPIO_SIFIVE_H + +#define GPIO_INPUT_VAL 0x00 +#define GPIO_INPUT_EN 0x04 +#define GPIO_OUTPUT_EN 0x08 +#define GPIO_OUTPUT_VAL 0x0C +#define GPIO_RISE_IE 0x18 +#define GPIO_RISE_IP 0x1C +#define GPIO_FALL_IE 0x20 +#define GPIO_FALL_IP 0x24 +#define GPIO_HIGH_IE 0x28 +#define GPIO_HIGH_IP 0x2C +#define GPIO_LOW_IE 0x30 +#define GPIO_LOW_IP 0x34 +#define GPIO_OUTPUT_XOR 0x40 + +#define NR_GPIOS 16 + +enum gpio_state { + LOW, + HIGH +}; + +/* Details about a GPIO bank */ +struct sifive_gpio_platdata { + void *base; /* address of registers in physical memory */ +}; + +#endif /* _GPIO_SIFIVE_H */ diff --git a/arch/riscv/include/asm/gpio.h b/arch/riscv/include/asm/gpio.h new file mode 100644 index 0000000..008d756 --- /dev/null +++ b/arch/riscv/include/asm/gpio.h @@ -0,0 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright 2018 SiFive, Inc. + */ + +#include diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index f2dabb5..39f2c7e 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -285,6 +285,13 @@ config STM32_GPIO usable on many stm32 families like stm32f4/f7/h7 and stm32mp1. Tested on STM32F7. +config SIFIVE_GPIO + bool "SiFive GPIO driver" + depends on DM_GPIO + help + Device model driver for GPIO controller present in SiFive FU540 SoC. This + driver enables GPIO interface on HiFive Unleashed A00 board. + config MVEBU_GPIO bool "Marvell MVEBU GPIO driver" depends on DM_GPIO && ARCH_MVEBU diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile index 4a8aa0f..ccc49e2 100644 --- a/drivers/gpio/Makefile +++ b/drivers/gpio/Makefile @@ -61,3 +61,4 @@ obj-$(CONFIG_$(SPL_)PCF8575_GPIO) += pcf8575_gpio.o obj-$(CONFIG_PM8916_GPIO) += pm8916_gpio.o obj-$(CONFIG_MT7621_GPIO) += mt7621_gpio.o obj-$(CONFIG_MSCC_SGPIO) += mscc_sgpio.o +obj-$(CONFIG_SIFIVE_GPIO) += sifive-gpio.o diff --git a/drivers/gpio/sifive-gpio.c b/drivers/gpio/sifive-gpio.c new file mode 100644 index 0000000..76d5a1d3 --- /dev/null +++ b/drivers/gpio/sifive-gpio.c @@ -0,0 +1,177 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * SiFive GPIO driver + * + * Copyright (C) 2019 SiFive, Inc. + */ + +#include +#include +#include +#include +#include +#include + +static int sifive_gpio_probe(struct udevice *dev) +{ + struct sifive_gpio_platdata *plat = dev_get_platdata(dev); + struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev); + char name[18], *str; + + sprintf(name, "gpio@%4lx_", (uintptr_t)plat->base); + str = strdup(name); + if (!str) + return -ENOMEM; + uc_priv->bank_name = str; + + /* + * Use the gpio count mentioned in device tree, + * if not specified in dt, set NR_GPIOS as default + */ + uc_priv->gpio_count = dev_read_u32_default(dev, "ngpios", NR_GPIOS); + + return 0; +} + +static void sifive_update_gpio_reg(void *bptr, u32 offset, bool value) +{ + void __iomem *ptr = (void __iomem *)bptr; + + u32 bit = BIT(offset); + u32 old = readl(ptr); + + if (value) + writel(old | bit, ptr); + else + writel(old & ~bit, ptr); +} + +static int sifive_gpio_direction_input(struct udevice *dev, u32 offset) +{ + struct sifive_gpio_platdata *plat = dev_get_platdata(dev); + struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev); + + if (offset > uc_priv->gpio_count) + return -EINVAL; + + /* Configure gpio direction as input */ + sifive_update_gpio_reg(plat->base + GPIO_INPUT_EN, offset, true); + sifive_update_gpio_reg(plat->base + GPIO_OUTPUT_EN, offset, false); + + return 0; +} + +static int sifive_gpio_direction_output(struct udevice *dev, u32 offset, + int value) +{ + struct sifive_gpio_platdata *plat = dev_get_platdata(dev); + struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev); + + if (offset > uc_priv->gpio_count) + return -EINVAL; + + /* Configure gpio direction as output */ + sifive_update_gpio_reg(plat->base + GPIO_OUTPUT_EN, offset, true); + sifive_update_gpio_reg(plat->base + GPIO_INPUT_EN, offset, false); + + /* Set the output state of the pin */ + sifive_update_gpio_reg(plat->base + GPIO_OUTPUT_VAL, offset, value); + + return 0; +} + +static int sifive_gpio_get_value(struct udevice *dev, u32 offset) +{ + struct sifive_gpio_platdata *plat = dev_get_platdata(dev); + struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev); + int val; + int dir; + + if (offset > uc_priv->gpio_count) + return -EINVAL; + + /* Get direction of the pin */ + dir = !(readl(plat->base + GPIO_OUTPUT_EN) & BIT(offset)); + + if (dir) + val = readl(plat->base + GPIO_INPUT_VAL) & BIT(offset); + else + val = readl(plat->base + GPIO_OUTPUT_VAL) & BIT(offset); + + return val ? HIGH : LOW; +} + +static int sifive_gpio_set_value(struct udevice *dev, u32 offset, int value) +{ + struct sifive_gpio_platdata *plat = dev_get_platdata(dev); + struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev); + + if (offset > uc_priv->gpio_count) + return -EINVAL; + + sifive_update_gpio_reg(plat->base + GPIO_OUTPUT_VAL, offset, value); + + return 0; +} + +static int sifive_gpio_get_function(struct udevice *dev, unsigned int offset) +{ + struct sifive_gpio_platdata *plat = dev_get_platdata(dev); + u32 outdir, indir, val; + struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev); + + if (offset > uc_priv->gpio_count) + return -1; + + /* Get direction of the pin */ + outdir = readl(plat->base + GPIO_OUTPUT_EN) & BIT(offset); + indir = readl(plat->base + GPIO_INPUT_EN) & BIT(offset); + + if (outdir) + /* Pin at specified offset is configured as output */ + val = GPIOF_OUTPUT; + else if (indir) + /* Pin at specified offset is configured as input */ + val = GPIOF_INPUT; + else + /*The requested GPIO is not set as input or output */ + val = GPIOF_UNUSED; + + return val; +} + +static const struct udevice_id sifive_gpio_match[] = { + { .compatible = "sifive,gpio0" }, + { } +}; + +static const struct dm_gpio_ops sifive_gpio_ops = { + .direction_input = sifive_gpio_direction_input, + .direction_output = sifive_gpio_direction_output, + .get_value = sifive_gpio_get_value, + .set_value = sifive_gpio_set_value, + .get_function = sifive_gpio_get_function, +}; + +static int sifive_gpio_ofdata_to_platdata(struct udevice *dev) +{ + struct sifive_gpio_platdata *plat = dev_get_platdata(dev); + fdt_addr_t addr; + + addr = devfdt_get_addr(dev); + if (addr == FDT_ADDR_T_NONE) + return -EINVAL; + + plat->base = (void *)addr; + return 0; +} + +U_BOOT_DRIVER(gpio_sifive) = { + .name = "gpio_sifive", + .id = UCLASS_GPIO, + .of_match = sifive_gpio_match, + .ofdata_to_platdata = of_match_ptr(sifive_gpio_ofdata_to_platdata), + .platdata_auto_alloc_size = sizeof(struct sifive_gpio_platdata), + .ops = &sifive_gpio_ops, + .probe = sifive_gpio_probe, +}; From patchwork Tue Oct 1 17:00:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sagar Shrikant Kadam X-Patchwork-Id: 1170078 X-Patchwork-Delegate: uboot@andestech.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.b="B79A0mzi"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 46jQYR1sCbz9sQq for ; Wed, 2 Oct 2019 03:02:19 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id DA8A1C21C6A; Tue, 1 Oct 2019 17:01:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 654CBC21D72; Tue, 1 Oct 2019 17:01:25 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id DA9FDC21DB3; Tue, 1 Oct 2019 17:01:14 +0000 (UTC) Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) by lists.denx.de (Postfix) with ESMTPS id A65AAC21DB5 for ; Tue, 1 Oct 2019 17:01:09 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id e1so4547993pgj.6 for ; Tue, 01 Oct 2019 10:01:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=CYxjqry5Tz9EH/QFHk/1dnPIJujE6i2+OGSthBVpdbY=; b=B79A0mziH8yiemByZQzVMDKEYXYXr0sXjUozQLQXoLFQGhrd0IeO/qUZhH74Lo1LdU ISy7UoxXoP71TZU/ZFm1vip+3rC2uCNdzEJkKV65PbvLQytkvPk9Cm+qYzr2fkVrGNrr pueDNtCjsBl8dSqtYYj42M4Ldh2wQ9F6+XEwOBKZF4ZGQ3S/gT+odhPOKSaJGydtlMlO 4PW2XRvZyVRddi+2aGQ9gm9v0keaYbNzpqTSUP0SB0wYtuauSRxQsdatlsoUP0910Aa8 omIh54v0CQjoxBj4aEHEjAbGr/Ru42tCsvAXS5W/m10XmKjp2o/VBkwb7okFoGc6Ji+K Lkow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=CYxjqry5Tz9EH/QFHk/1dnPIJujE6i2+OGSthBVpdbY=; b=SAkG6Z0QhDbn2/J9Muc0bKmXOA0dUwYMbqyhBpQ5o2L9rRAOwL4qFrEQrCP5ujIC2q TjgfGuFIm5GJ3vhVwxAqzQ3idYoOjKbwvVQSgCIFAOmsDHDOiwOUGSzvSryl/7NWSSTu c+3psF1XqReRURKQmkTx0DBnJ/VDd8modIPUGgx+gPKvBFp2KVR44ZQFVXZ369s/Nwus X4/C261nRShq6Uiu5tUSxZ2Rvw0srVtWEGmu+/gU6ly0OwUPaznLJ7VxrLtlugTWHsk+ zNerDOoica6Pvf0BHzuVng67c1NgPDtmT3T27Oki/PqX0obbVZRd0LxK8LHupDXj0aAW aedA== X-Gm-Message-State: APjAAAVptt55iCgF9/ozAcB020G9UU+w/0m5Gtk+hOsD8wqFxAVqKzGY D86OshCk7BYJ8Hjr6tjHUu8DD1CW4DE= X-Google-Smtp-Source: APXvYqzsi1szbYzfWdv+1aCU750ha0LkM97DBfkxfBpksGqScqb4TISeMMOonC9zFZwnUHIez4/G6g== X-Received: by 2002:a17:90a:2464:: with SMTP id h91mr6982998pje.9.1569949267947; Tue, 01 Oct 2019 10:01:07 -0700 (PDT) Received: from gamma07.internal.sifive.com ([64.62.193.194]) by smtp.googlemail.com with ESMTPSA id k5sm26096667pfp.109.2019.10.01.10.01.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 01 Oct 2019 10:01:07 -0700 (PDT) From: Sagar Shrikant Kadam To: u-boot@lists.denx.de, rick@andestech.com, paul.walmsley@sifive.com, palmer@sifive.com, anup.patel@wdc.com, atish.patra@wdc.com Date: Tue, 1 Oct 2019 10:00:47 -0700 Message-Id: <1569949247-17895-3-git-send-email-sagar.kadam@sifive.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1569949247-17895-1-git-send-email-sagar.kadam@sifive.com> References: <1569949247-17895-1-git-send-email-sagar.kadam@sifive.com> Cc: wesley@sifive.com Subject: [U-Boot] [U-BOOT PATCH v2 2/2] configs: fu540: enable gpio driver X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Enable the DM based GPIO driver for FU540-C000 SoC. Signed-off-by: Sagar Shrikant Kadam Reviewed-by: Bin Meng Tested-by: Bin Meng --- board/sifive/fu540/Kconfig | 3 +++ 1 file changed, 3 insertions(+) diff --git a/board/sifive/fu540/Kconfig b/board/sifive/fu540/Kconfig index 5d65080..5ca2147 100644 --- a/board/sifive/fu540/Kconfig +++ b/board/sifive/fu540/Kconfig @@ -44,6 +44,9 @@ config BOARD_SPECIFIC_OPTIONS # dummy imply MMC_SPI imply MMC_BROKEN_CD imply CMD_MMC + imply DM_GPIO + imply SIFIVE_GPIO + imply CMD_GPIO imply SMP endif