From nobody Thu Aug 10 07:22:12 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4RLyzm6KVNz4TjVy; Thu, 10 Aug 2023 07:22:12 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4RLyzm5qVDz4M4k; Thu, 10 Aug 2023 07:22:12 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1691652132; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Zf9OZtm5iM4Qej/8QpeT9Zf7/vKhzk4owK5nwBi5SSM=; b=ktmqXdU//tWxei+6HqQ+BE/Q2dWVtl50RrOrcomgDD9xLYCxrJ5RsYAWAgYf2pY6oksww5 C3i0i5/T1M6Juu3IRqj1Z0XPbQxtJ+oKJqUngvn+rEHVrn5af+te1g8OqOsu4mK4CrTA2X fTUA+YYCCYd2dyZYeEUB/NHwWgQQV/Vuzh8dxvZxlWViJclkTj36avcvs4iv90+7pvZQP5 HLTJfIBKSkDCsjiF5h6sNBDgn97NUbdvT6RcCM+PRGMmJavY6zC4WdlWxwsIrgrVU9IMbG uJ8bRIAebLmiph3J7IdUlIYYQHX7mVIdApipMPEQ87EL01at0HWLqKanSyg2Mg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1691652132; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Zf9OZtm5iM4Qej/8QpeT9Zf7/vKhzk4owK5nwBi5SSM=; b=vvL5LGyLAeGc5vnnQNpRGpnIHKfydxFiG21ksNORlHFj/lRyLt74JuZvMHG8OSa4ynms10 sC7/UU6SQm8KdCKZsugjYPoCvyRSPPrifnAD05UQDB08Nff1F7LsvmASZXpMppZ/LrLufD Q0XigSjCuTPU4J9A8a1QsbakHAJk7oli/19PJl77tEgvL7wFw07G5WJicgqVZbbBuOjUPZ vW4ESoyU9kBsufcOhrwN5UV8Uhw7eHHRuwZlqJvsI/2Iyrj0+3ythHUh3JSoM59CuDl8UA b2Rvoe0Dx3CNZK2DyUx9v96U8Kz1ONF/LNUjN8rfeAXJy7FKlrPBjdlgQ5Ea5A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1691652132; a=rsa-sha256; cv=none; b=QyzKaMc/W/uLT2+2yzQMp5F7aKu15hwm/ckpx2JoOm+GohMA1NV/jCPK/u3UYVrxfccX+b 9due2MxsHDpc2wE5aAIgpjdpAYtFEbV+JbIWIBEFvE14kaVhNsN/UoDwpmFpxNxmjD/X7z y/Ls9x5xBBmzIRSeVAvLghDGUr1vDU6WRY5bjMTwPs0g9yD183TDMwUbapdpQIovCJeyya uOt2h+AOsGSzSlp8UI58q4yGsGmIZDDU6gZqvgWGzXLeZ7axNrvcjwKmGRgFb+44Bf2OJB S7qjcE8Zh4nU/AJqZL60LP5MdGr45gK/kYyf7rFmfa07G5Ad51mTy3MZBHHylQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4RLyzm4nTpznhq; Thu, 10 Aug 2023 07:22:12 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 37A7MCUm023555; Thu, 10 Aug 2023 07:22:12 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 37A7MCLY023540; Thu, 10 Aug 2023 07:22:12 GMT (envelope-from git) Date: Thu, 10 Aug 2023 07:22:12 GMT Message-Id: <202308100722.37A7MCLY023540@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Emmanuel Vadot Subject: git: c15106da820b - main - arm64: xilinx: gpio: Add support for ZynqMP SoC List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: manu X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: c15106da820bd2e042fa8bc7cfba56ae69b371d6 Auto-Submitted: auto-generated The branch main has been updated by manu: URL: https://cgit.FreeBSD.org/src/commit/?id=c15106da820bd2e042fa8bc7cfba56ae69b371d6 commit c15106da820bd2e042fa8bc7cfba56ae69b371d6 Author: Emmanuel Vadot AuthorDate: 2022-09-29 08:41:24 +0000 Commit: Emmanuel Vadot CommitDate: 2023-08-10 07:21:55 +0000 arm64: xilinx: gpio: Add support for ZynqMP SoC Add support for the gpio controller found in the ZynqMP SoC. The registers are the same as the Zynq 7000, just the number of banks/pins per banks differs. Sponsored by: Beckhoff Automation GmbH & Co. KG MFC after: 2 weeks --- sys/arm/xilinx/zy7_gpio.c | 140 +++++++++++++++++++++++++++++++++------------- sys/conf/files.arm64 | 1 + 2 files changed, 102 insertions(+), 39 deletions(-) diff --git a/sys/arm/xilinx/zy7_gpio.c b/sys/arm/xilinx/zy7_gpio.c index d487fc8e79d1..3dea34dc47fd 100644 --- a/sys/arm/xilinx/zy7_gpio.c +++ b/sys/arm/xilinx/zy7_gpio.c @@ -70,30 +70,49 @@ __FBSDID("$FreeBSD$"); #include "gpio_if.h" -#define ZYNQ_MAX_BANK 4 +#define ZYNQ7_MAX_BANK 4 +#define ZYNQMP_MAX_BANK 6 /* Zynq 7000 */ -#define ZYNQ_BANK0_PIN_MIN 0 -#define ZYNQ_BANK0_NPIN 32 -#define ZYNQ_BANK1_PIN_MIN 32 -#define ZYNQ_BANK1_NPIN 22 -#define ZYNQ_BANK2_PIN_MIN 64 -#define ZYNQ_BANK2_NPIN 32 -#define ZYNQ_BANK3_PIN_MIN 96 -#define ZYNQ_BANK3_NPIN 32 -#define ZYNQ_PIN_MIO_MIN 0 -#define ZYNQ_PIN_MIO_MAX 54 -#define ZYNQ_PIN_EMIO_MIN 64 -#define ZYNQ_PIN_EMIO_MAX 118 - -#define ZYNQ_BANK_NPIN(bank) (ZYNQ_BANK##bank##_NPIN) -#define ZYNQ_BANK_PIN_MIN(bank) (ZYNQ_BANK##bank##_PIN_MIN) -#define ZYNQ_BANK_PIN_MAX(bank) (ZYNQ_BANK##bank##_PIN_MIN + ZYNQ_BANK##bank##_NPIN - 1) - -#define ZYNQ_PIN_IS_MIO(pin) (pin >= ZYNQ_PIN_MIO_MIN && \ - pin <= ZYNQ_PIN_MIO_MAX) -#define ZYNQ_PIN_IS_EMIO(pin) (pin >= ZYNQ_PIN_EMIO_MIN && \ - pin <= ZYNQ_PIN_EMIO_MAX) +#define ZYNQ7_BANK0_PIN_MIN 0 +#define ZYNQ7_BANK0_NPIN 32 +#define ZYNQ7_BANK1_PIN_MIN 32 +#define ZYNQ7_BANK1_NPIN 22 +#define ZYNQ7_BANK2_PIN_MIN 64 +#define ZYNQ7_BANK2_NPIN 32 +#define ZYNQ7_BANK3_PIN_MIN 96 +#define ZYNQ7_BANK3_NPIN 32 +#define ZYNQ7_PIN_MIO_MIN 0 +#define ZYNQ7_PIN_MIO_MAX 54 +#define ZYNQ7_PIN_EMIO_MIN 64 +#define ZYNQ7_PIN_EMIO_MAX 118 + +/* ZynqMP */ +#define ZYNQMP_BANK0_PIN_MIN 0 +#define ZYNQMP_BANK0_NPIN 26 +#define ZYNQMP_BANK1_PIN_MIN 26 +#define ZYNQMP_BANK1_NPIN 26 +#define ZYNQMP_BANK2_PIN_MIN 52 +#define ZYNQMP_BANK2_NPIN 26 +#define ZYNQMP_BANK3_PIN_MIN 78 +#define ZYNQMP_BANK3_NPIN 32 +#define ZYNQMP_BANK4_PIN_MIN 110 +#define ZYNQMP_BANK4_NPIN 32 +#define ZYNQMP_BANK5_PIN_MIN 142 +#define ZYNQMP_BANK5_NPIN 32 +#define ZYNQMP_PIN_MIO_MIN 0 +#define ZYNQMP_PIN_MIO_MAX 77 +#define ZYNQMP_PIN_EMIO_MIN 78 +#define ZYNQMP_PIN_EMIO_MAX 174 + +#define ZYNQ_BANK_NPIN(type, bank) (ZYNQ##type##_BANK##bank##_NPIN) +#define ZYNQ_BANK_PIN_MIN(type, bank) (ZYNQ##type##_BANK##bank##_PIN_MIN) +#define ZYNQ_BANK_PIN_MAX(type, bank) (ZYNQ##type##_BANK##bank##_PIN_MIN + ZYNQ##type##_BANK##bank##_NPIN - 1) + +#define ZYNQ_PIN_IS_MIO(type, pin) (pin >= ZYNQ##type##_PIN_MIO_MIN && \ + pin <= ZYNQ##type##_PIN_MIO_MAX) +#define ZYNQ_PIN_IS_EMIO(type, pin) (pin >= ZYNQ##type##_PIN_EMIO_MIN && \ + pin <= ZYNQ##type##_PIN_EMIO_MAX) #define ZGPIO_LOCK(sc) mtx_lock(&(sc)->sc_mtx) #define ZGPIO_UNLOCK(sc) mtx_unlock(&(sc)->sc_mtx) @@ -102,12 +121,18 @@ __FBSDID("$FreeBSD$"); "gpio", MTX_DEF) #define ZGPIO_LOCK_DESTROY(_sc) mtx_destroy(&_sc->sc_mtx); +enum zynq_gpio_type { + ZYNQ_7000 = 0, + ZYNQMP, +}; + struct zynq_gpio_conf { - char *name; - uint32_t nbanks; - uint32_t maxpin; - uint32_t bank_min[ZYNQ_MAX_BANK]; - uint32_t bank_max[ZYNQ_MAX_BANK]; + char *name; + enum zynq_gpio_type type; + uint32_t nbanks; + uint32_t maxpin; + uint32_t bank_min[ZYNQMP_MAX_BANK]; + uint32_t bank_max[ZYNQMP_MAX_BANK]; }; struct zy7_gpio_softc { @@ -120,20 +145,41 @@ struct zy7_gpio_softc { static struct zynq_gpio_conf z7_gpio_conf = { .name = "Zynq-7000 GPIO Controller", - .nbanks = ZYNQ_MAX_BANK, - .maxpin = ZYNQ_PIN_EMIO_MAX, - .bank_min[0] = ZYNQ_BANK_PIN_MIN(0), - .bank_max[0] = ZYNQ_BANK_PIN_MAX(0), - .bank_min[1] = ZYNQ_BANK_PIN_MIN(1), - .bank_max[1] = ZYNQ_BANK_PIN_MAX(1), - .bank_min[2] = ZYNQ_BANK_PIN_MIN(2), - .bank_max[2] = ZYNQ_BANK_PIN_MAX(2), - .bank_min[3] = ZYNQ_BANK_PIN_MIN(3), - .bank_max[3] = ZYNQ_BANK_PIN_MAX(3), + .type = ZYNQ_7000, + .nbanks = ZYNQ7_MAX_BANK, + .maxpin = ZYNQ7_PIN_EMIO_MAX, + .bank_min[0] = ZYNQ_BANK_PIN_MIN(7, 0), + .bank_max[0] = ZYNQ_BANK_PIN_MAX(7, 0), + .bank_min[1] = ZYNQ_BANK_PIN_MIN(7, 1), + .bank_max[1] = ZYNQ_BANK_PIN_MAX(7, 1), + .bank_min[2] = ZYNQ_BANK_PIN_MIN(7, 2), + .bank_max[2] = ZYNQ_BANK_PIN_MAX(7, 2), + .bank_min[3] = ZYNQ_BANK_PIN_MIN(7, 3), + .bank_max[3] = ZYNQ_BANK_PIN_MAX(7, 3), +}; + +static struct zynq_gpio_conf zynqmp_gpio_conf = { + .name = "ZynqMP GPIO Controller", + .type = ZYNQMP, + .nbanks = ZYNQMP_MAX_BANK, + .maxpin = ZYNQMP_PIN_EMIO_MAX, + .bank_min[0] = ZYNQ_BANK_PIN_MIN(MP, 0), + .bank_max[0] = ZYNQ_BANK_PIN_MAX(MP, 0), + .bank_min[1] = ZYNQ_BANK_PIN_MIN(MP, 1), + .bank_max[1] = ZYNQ_BANK_PIN_MAX(MP, 1), + .bank_min[2] = ZYNQ_BANK_PIN_MIN(MP, 2), + .bank_max[2] = ZYNQ_BANK_PIN_MAX(MP, 2), + .bank_min[3] = ZYNQ_BANK_PIN_MIN(MP, 3), + .bank_max[3] = ZYNQ_BANK_PIN_MAX(MP, 3), + .bank_min[4] = ZYNQ_BANK_PIN_MIN(MP, 4), + .bank_max[4] = ZYNQ_BANK_PIN_MAX(MP, 4), + .bank_min[5] = ZYNQ_BANK_PIN_MIN(MP, 5), + .bank_max[5] = ZYNQ_BANK_PIN_MAX(MP, 5), }; static struct ofw_compat_data compat_data[] = { {"xlnx,zy7_gpio", (uintptr_t)&z7_gpio_conf}, + {"xlnx,zynqmp-gpio-1.0", (uintptr_t)&zynqmp_gpio_conf}, {NULL, 0}, }; @@ -212,15 +258,31 @@ zy7_gpio_pin_getcaps(device_t dev, uint32_t pin, uint32_t *caps) static int zy7_gpio_pin_getname(device_t dev, uint32_t pin, char *name) { + struct zy7_gpio_softc *sc; + uint32_t emio_min; + bool is_mio; + sc = device_get_softc(dev); if (!zy7_pin_valid(dev, pin)) return (EINVAL); - if (ZYNQ_PIN_IS_MIO(pin)) { + switch (sc->conf->type) { + case ZYNQ_7000: + is_mio = ZYNQ_PIN_IS_MIO(7, pin); + emio_min = ZYNQ7_PIN_EMIO_MIN; + break; + case ZYNQMP: + is_mio = ZYNQ_PIN_IS_MIO(MP, pin); + emio_min = ZYNQMP_PIN_EMIO_MIN; + break; + default: + return (EINVAL); + } + if (is_mio) { snprintf(name, GPIOMAXNAME, "MIO_%d", pin); name[GPIOMAXNAME - 1] = '\0'; } else { - snprintf(name, GPIOMAXNAME, "EMIO_%d", pin - ZYNQ_PIN_EMIO_MIN); + snprintf(name, GPIOMAXNAME, "EMIO_%d", pin - emio_min); name[GPIOMAXNAME - 1] = '\0'; } diff --git a/sys/conf/files.arm64 b/sys/conf/files.arm64 index 7eb0c0d04367..31c296d49d86 100644 --- a/sys/conf/files.arm64 +++ b/sys/conf/files.arm64 @@ -692,3 +692,4 @@ arm64/rockchip/clk/rk3568_pmucru.c optional fdt soc_rockchip_rk3568 # Xilinx arm/xilinx/uart_dev_cdnc.c optional uart soc_xilinx_zynq fdt +arm/xilinx/zy7_gpio.c optional gpio soc_xilinx_zynq fdt