From patchwork Fri Oct 18 20:27:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zixun LI X-Patchwork-Id: 1999367 X-Patchwork-Delegate: eugen.hristev@microchip.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=hifiphile-com.20230601.gappssmtp.com header.i=@hifiphile-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=NLOYkJ4F; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XVcDn6m0Lz1xw2 for ; Sat, 19 Oct 2024 07:46:17 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2935A88D5B; Fri, 18 Oct 2024 22:46:13 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=hifiphile.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=hifiphile-com.20230601.gappssmtp.com header.i=@hifiphile-com.20230601.gappssmtp.com header.b="NLOYkJ4F"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 86F6388DA0; Fri, 18 Oct 2024 22:27:24 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 8390A88B23 for ; Fri, 18 Oct 2024 22:27:22 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=hifiphile.com Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=admin@hifiphile.com Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-43155abaf0bso23897665e9.0 for ; Fri, 18 Oct 2024 13:27:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hifiphile-com.20230601.gappssmtp.com; s=20230601; t=1729283242; x=1729888042; darn=lists.denx.de; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=WluH7AQOLiL0GTH5xHlsLlNpMla8/qfLrtkMEUXGkcQ=; b=NLOYkJ4Fn5q8m0AqpoPZaNmTNxVSlSmeIEcqvUqHgXLs9Pe1B0snqP9mckZa0dsizP X9Xp70aUpzX0Qs3OGvlZE9QiGwlcTBy4JETg9C+vk7NgMmftLZAQWeLBV3L7PXhs375A vNlfv8mJJjJxzbz/G6L00TMTuOMrWW7z7m8A8NUhB9Et+ZXlfFlZbwSHa2jXnxTW2iWx 3IQI6HQ560wFrdoXKta/wEBrtYPdt6sk43iPeJm4/pQ9eVJDqscyU0h1FxzXW7dbf+RU IuIok6PvnijC+sree1DQXgEhIBxcbiyis9NCA1+7eRyUYmKZ930mgAOu9Pep5bQgAf6Q 6DAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729283242; x=1729888042; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=WluH7AQOLiL0GTH5xHlsLlNpMla8/qfLrtkMEUXGkcQ=; b=T2DOeHFzmqwsPmnRMk+Si5BnuDIny3pKD809hMFMNryz7KWyQhLC831M/xZZP++A9M 21Le31nrAS2s7rluoIGPoeg1eIUZ/5sU6//PPo65+VYCf+e9Wt0k1QrXQ6gtNcraIxcH 2piALnz2SuvkOwnZYegq3t/ZmGWduBIQx50ijFZClvN5v/85RSPcKLAg0UjvSkllPkaU LcPHCQbGTUvp9FyLba+Y3Ptpai00Qrz/xcCV6ZnSH5+wP8/Yf6UdURvuVC6NBax+DYjs kgDd3DSBmrnLj+uerUwv+tfMUv8zJzzHq68ZcmuyI4ExRjyoncvSET+ETZhMRg0uicuj uxqA== X-Gm-Message-State: AOJu0YzK0bKSSoKKL/Iry1lF+20wDBxb+J25dlFWnJjU3drH+uU9MIzA 1CHsj+7ErAR29nSmifE7N1bUZqY78esMe6PbIvFrDh/iPCfWkDNApDBisBLkIMg= X-Google-Smtp-Source: AGHT+IGvq+n7Z7qISUnOkllfD+7UpfdyWtTcc9x97wlNX5/5QMHr034eQTsK4jpBcVFm5RuTJNCWkA== X-Received: by 2002:a05:600c:3d9b:b0:431:54d9:da57 with SMTP id 5b1f17b1804b1-431616ad787mr28883095e9.30.1729283241740; Fri, 18 Oct 2024 13:27:21 -0700 (PDT) Received: from localhost.localdomain ([78.199.60.143]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-4316067dc70sm35810395e9.10.2024.10.18.13.27.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 13:27:21 -0700 (PDT) From: Zixun LI To: Simon Glass Cc: u-boot@lists.denx.de, Zixun LI Subject: [PATCH 1/3] gpio: at91: Implement GPIOF_FUNC in get_function() Date: Fri, 18 Oct 2024 22:27:13 +0200 Message-ID: <20241018202715.283011-1-admin@hifiphile.com> X-Mailer: git-send-email 2.46.2 MIME-Version: 1.0 X-Mailman-Approved-At: Fri, 18 Oct 2024 22:46:12 +0200 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean This patch adds support for determining whether a gpio pin is mapped as peripheral function. Signed-off-by: Zixun LI --- drivers/gpio/at91_gpio.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/at91_gpio.c b/drivers/gpio/at91_gpio.c index 1409db5dc1..64a6e8a4a5 100644 --- a/drivers/gpio/at91_gpio.c +++ b/drivers/gpio/at91_gpio.c @@ -220,6 +220,15 @@ static bool at91_get_port_output(struct at91_port *at91_port, int offset) val = readl(&at91_port->osr); return val & mask; } + +static bool at91_get_port_pio(struct at91_port *at91_port, int offset) +{ + u32 mask, val; + + mask = 1 << offset; + val = readl(&at91_port->psr); + return val & mask; +} #endif static void at91_set_port_input(struct at91_port *at91_port, int offset, @@ -550,7 +559,9 @@ static int at91_gpio_get_function(struct udevice *dev, unsigned offset) { struct at91_port_priv *port = dev_get_priv(dev); - /* GPIOF_FUNC is not implemented yet */ + if (!at91_get_port_pio(port->regs, offset)) + return GPIOF_FUNC; + if (at91_get_port_output(port->regs, offset)) return GPIOF_OUTPUT; else From patchwork Fri Oct 18 20:27:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zixun LI X-Patchwork-Id: 1999368 X-Patchwork-Delegate: eugen.hristev@microchip.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=hifiphile-com.20230601.gappssmtp.com header.i=@hifiphile-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=JVY0oFZL; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XVcDz6K4Cz1xw2 for ; Sat, 19 Oct 2024 07:46:27 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 840A188DFF; Fri, 18 Oct 2024 22:46:13 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=hifiphile.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=hifiphile-com.20230601.gappssmtp.com header.i=@hifiphile-com.20230601.gappssmtp.com header.b="JVY0oFZL"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 20E3888DA0; Fri, 18 Oct 2024 22:27:26 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3D84E88D5B for ; Fri, 18 Oct 2024 22:27:24 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=hifiphile.com Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=admin@hifiphile.com Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-4314f38d274so32298895e9.1 for ; Fri, 18 Oct 2024 13:27:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hifiphile-com.20230601.gappssmtp.com; s=20230601; t=1729283244; x=1729888044; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0cU8ffk7avq6dqi+FK+yp8rCXvS00d7UDYCrxvClces=; b=JVY0oFZL0wXNz38BYV2q0rfHL7H/GiTzfa7W/hbHCcU2jtZwp83I5u/sRa1Qf5sVji uyH8wpuh5htZKASkswolXD5xsuTZTmIIq55vKZK4ZskYmt2ujNCIri9UMVwkg6DM9361 /EiYYHJ/PXNy5G/K957I88GQn9SrUPS7SB7wsilb+U+SQELgWn+QklBl8P3vbz+fN0U3 XQUTgvYTKaCTWGOfoZ2GuycHtzjqzrNqGu9WSWv2ld6ksjM04Kzc5TCKak2f6D0DAAx1 LDaFbTRQ3lPBGBET7WJu6oYcWxyXtDyhj5IX2pxDnwI/HBSGlhdORUisFptBlOolgVB5 8dBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729283244; x=1729888044; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0cU8ffk7avq6dqi+FK+yp8rCXvS00d7UDYCrxvClces=; b=pAKvYBtyosczXI8xntJvCeYmsrFpqXX8ODm+1NFmyBp5E0e41NAKUspq2bKknTRQMR pq2lXjACwgbr8j/gWIaL7Vn8wNfFlvyknSOJdDpT7ZXkH8zXL+gG1+z+jie62r59xQJ0 zDgsDMZfW7diOvYxivpUiIUhMDp3308plOWgeUtTVlGLzPtbOnjbEmSxmD8pveMv3lty 0BaLWYRFg/gvRaApIlqLqBoitr2dmERxXHwNzoL0sxFSGv65nZmYcyexpey/1UAYPSN8 wCpWmeoaTweH2w7NcZDS8D9f92AJnoraIaN8c8Z22KtwPZHLhrIKKN4mgIVMMz7/1PRN mAnA== X-Gm-Message-State: AOJu0YyI94M3O9XQhZlY27JbR1dLaB34N4CSvBBck+Kp7+oKoUjT/lyR w4VC9SE2cJSIOGOBH8jY2haHmfqohdrGVdpfTqY83u38JYkMoipKNZtGSa346lRsW75Lc4uI1Z2 P X-Google-Smtp-Source: AGHT+IFPssC9dXTGivPgVfTmeSxZ/4z8E40V5JCpbvExUk+5Q71JyQUAdYSqE56rWVL5vn+4oTOqgg== X-Received: by 2002:a05:600c:5489:b0:431:24c3:dbaa with SMTP id 5b1f17b1804b1-4316161eeaamr34227795e9.2.1729283243509; Fri, 18 Oct 2024 13:27:23 -0700 (PDT) Received: from localhost.localdomain ([78.199.60.143]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-4316067dc70sm35810395e9.10.2024.10.18.13.27.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 13:27:22 -0700 (PDT) From: Zixun LI To: Simon Glass Cc: u-boot@lists.denx.de, Zixun LI Subject: [PATCH 2/3] gpio: at91: Implement ops set_flags Date: Fri, 18 Oct 2024 22:27:14 +0200 Message-ID: <20241018202715.283011-2-admin@hifiphile.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241018202715.283011-1-admin@hifiphile.com> References: <20241018202715.283011-1-admin@hifiphile.com> MIME-Version: 1.0 X-Mailman-Approved-At: Fri, 18 Oct 2024 22:46:12 +0200 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Support GPIO configuration with following flags: - in, out, out_active - open_drain, pull_up Signed-off-by: Zixun LI --- drivers/gpio/at91_gpio.c | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/drivers/gpio/at91_gpio.c b/drivers/gpio/at91_gpio.c index 64a6e8a4a5..7828f9b447 100644 --- a/drivers/gpio/at91_gpio.c +++ b/drivers/gpio/at91_gpio.c @@ -229,6 +229,17 @@ static bool at91_get_port_pio(struct at91_port *at91_port, int offset) val = readl(&at91_port->psr); return val & mask; } + +static void at91_set_port_multi_drive(struct at91_port *at91_port, int offset, int is_on) +{ + u32 mask; + + mask = 1 << offset; + if (is_on) + writel(mask, &at91_port->mder); + else + writel(mask, &at91_port->mddr); +} #endif static void at91_set_port_input(struct at91_port *at91_port, int offset, @@ -568,6 +579,35 @@ static int at91_gpio_get_function(struct udevice *dev, unsigned offset) return GPIOF_INPUT; } +static int at91_gpio_set_flags(struct udevice *dev, unsigned int offset, + ulong flags) +{ + struct at91_port_priv *port = dev_get_priv(dev); + ulong supported_mask; + + supported_mask = GPIOD_OPEN_DRAIN | GPIOD_MASK_DIR | GPIOD_PULL_UP; + if (flags & ~supported_mask) + return -EINVAL; + + if (flags & GPIOD_IS_OUT) { + bool value = flags & GPIOD_IS_OUT_ACTIVE; + + if (flags & GPIOD_OPEN_DRAIN) + at91_set_port_multi_drive(port->regs, offset, true); + else + at91_set_port_multi_drive(port->regs, offset, false); + + at91_set_port_output(port->regs, offset, value); + + } else if (flags & GPIOD_IS_IN) { + at91_set_port_input(port->regs, offset, false); + } + if (flags & GPIOD_PULL_UP) + at91_set_port_pullup(port->regs, offset, true); + + return 0; +} + static const char *at91_get_bank_name(uint32_t base_addr) { switch (base_addr) { @@ -596,6 +636,7 @@ static const struct dm_gpio_ops gpio_at91_ops = { .get_value = at91_gpio_get_value, .set_value = at91_gpio_set_value, .get_function = at91_gpio_get_function, + .set_flags = at91_gpio_set_flags, }; static int at91_gpio_probe(struct udevice *dev) From patchwork Fri Oct 18 20:27:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zixun LI X-Patchwork-Id: 1999369 X-Patchwork-Delegate: eugen.hristev@microchip.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=hifiphile-com.20230601.gappssmtp.com header.i=@hifiphile-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=axQyPOwx; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XVcF64yCtz1xw2 for ; Sat, 19 Oct 2024 07:46:34 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id ECCF988E2B; Fri, 18 Oct 2024 22:46:13 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=hifiphile.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=hifiphile-com.20230601.gappssmtp.com header.i=@hifiphile-com.20230601.gappssmtp.com header.b="axQyPOwx"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3889E88D72; Fri, 18 Oct 2024 22:27:27 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 55F7E88B23 for ; Fri, 18 Oct 2024 22:27:25 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=hifiphile.com Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=admin@hifiphile.com Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-431616c23b5so7431885e9.0 for ; Fri, 18 Oct 2024 13:27:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hifiphile-com.20230601.gappssmtp.com; s=20230601; t=1729283245; x=1729888045; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GoCJD5Zngd/58b2dw/ExiyOu/rcLIvwRGXdTekrnXME=; b=axQyPOwxvnn1acE3PR+qAUEV1WGbPDQJX8hjFd8/0PK/JMhU5De4AwSL2ldqAxIWiV G9LQTM/h+ZGjK82EjwagZAniImWT6MhD0H8jJbJRGXGNcyG97du6o7eCy8QtxHwC7N3/ 18PfXCtlG/62yGONI3h7w2seGEEb36irxRJ0LGdXHn2vUtyXiF8wn4PwApvv3Ts81JE/ 8SjRF70oPp/FvyGkMJ2kwPikZQ6xwtj2c5y/NJ5j1q6rTouAABwIO/YbQgi7SEOp/yQP O4a9kqruo/gaS2gIsVFID+Wesz/LvlpHH0lz9+mbBoX0X/jwyhFBKozmma2LbT/Nnblw Vcag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729283245; x=1729888045; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GoCJD5Zngd/58b2dw/ExiyOu/rcLIvwRGXdTekrnXME=; b=RX5Zy95w7VMOir+GkTadUS6cVJM7Wek1b5Nxg2vyEHYLu8njX80EBNi9tGTPWLuPE3 JbK7Eqq3+8jPFwk+6AjeSlV/h7v5Bfa6SFnDqdilSwX+zPXU5gMvsApxsOv21vYiFKMy Q5ty97sD/R8n535l4bBpYFIYAN0a8InSkDk/PLkHZRcEGwAzGySwAmonGJ5txJIkxov6 ISAIiQgVPvz57Rf6XzLx0Zkkvgqg6GooLypDl9so69/uhnMe80sdz5lwsJnDxGW0CTU0 2si5ebCyjD87JsmMCST4yZ/KnMixyBgoPSty34t6Ituy2AtZyTQxddXOfwCCSO4WZkpi WnKA== X-Gm-Message-State: AOJu0YxdVKPu2sW3JapjiUfWZB6qU6OmWS/GlByK/nBQGj7ha2ZNK262 JhlBUCgQX6VKRsIwC9ezcPIruQA4Zr/iD/zmnij3cz3IpPYLpFQiwqRGQ2SUUI5o/Z2AUNeeWC0 f X-Google-Smtp-Source: AGHT+IFk4/Yy3K06l3JL0KglpA7Gs4L4mv+xyjVHjlf2Yayu5IbFme5mxDF/+KccCRf02FEqT4PrSw== X-Received: by 2002:a05:600c:3151:b0:431:4fbd:f571 with SMTP id 5b1f17b1804b1-43161685008mr24424795e9.13.1729283244743; Fri, 18 Oct 2024 13:27:24 -0700 (PDT) Received: from localhost.localdomain ([78.199.60.143]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-4316067dc70sm35810395e9.10.2024.10.18.13.27.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 13:27:23 -0700 (PDT) From: Zixun LI To: Simon Glass Cc: u-boot@lists.denx.de, Zixun LI Subject: [PATCH 3/3] gpio: at91: Implement ops get_flags Date: Fri, 18 Oct 2024 22:27:15 +0200 Message-ID: <20241018202715.283011-3-admin@hifiphile.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241018202715.283011-1-admin@hifiphile.com> References: <20241018202715.283011-1-admin@hifiphile.com> MIME-Version: 1.0 X-Mailman-Approved-At: Fri, 18 Oct 2024 22:46:12 +0200 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Add ops get_dir_flags() to read status from GPIO registers. Signed-off-by: Zixun LI --- drivers/gpio/at91_gpio.c | 45 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/drivers/gpio/at91_gpio.c b/drivers/gpio/at91_gpio.c index 7828f9b447..c986007716 100644 --- a/drivers/gpio/at91_gpio.c +++ b/drivers/gpio/at91_gpio.c @@ -240,6 +240,24 @@ static void at91_set_port_multi_drive(struct at91_port *at91_port, int offset, i else writel(mask, &at91_port->mddr); } + +static bool at91_get_port_multi_drive(struct at91_port *at91_port, int offset) +{ + u32 mask, val; + + mask = 1 << offset; + val = readl(&at91_port->mdsr); + return val & mask; +} + +static bool at91_get_port_pullup(struct at91_port *at91_port, int offset) +{ + u32 mask, val; + + mask = 1 << offset; + val = readl(&at91_port->pusr); + return val & mask; +} #endif static void at91_set_port_input(struct at91_port *at91_port, int offset, @@ -608,6 +626,32 @@ static int at91_gpio_set_flags(struct udevice *dev, unsigned int offset, return 0; } +static int at91_gpio_get_flags(struct udevice *dev, unsigned int offset, + ulong *flagsp) +{ + struct at91_port_priv *port = dev_get_priv(dev); + ulong dir_flags = 0; + + if (at91_get_port_output(port->regs, offset)) { + dir_flags |= GPIOD_IS_OUT; + + if (at91_get_port_multi_drive(port->regs, offset)) + dir_flags |= GPIOD_OPEN_DRAIN; + + if (at91_get_port_value(port->regs, offset)) + dir_flags |= GPIOD_IS_OUT_ACTIVE; + } else { + dir_flags |= GPIOD_IS_IN; + } + + if (at91_get_port_pullup(port->regs, offset)) + dir_flags |= GPIOD_PULL_UP; + + *flagsp = dir_flags; + + return 0; +} + static const char *at91_get_bank_name(uint32_t base_addr) { switch (base_addr) { @@ -637,6 +681,7 @@ static const struct dm_gpio_ops gpio_at91_ops = { .set_value = at91_gpio_set_value, .get_function = at91_gpio_get_function, .set_flags = at91_gpio_set_flags, + .get_flags = at91_gpio_get_flags, }; static int at91_gpio_probe(struct udevice *dev)