From patchwork Tue May 5 08:43:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 1283364 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: 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=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=xOtfbKW0; dkim-atps=neutral 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 RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49GYCx68F1z9sRf for ; Tue, 5 May 2020 18:43:41 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E6DC68205B; Tue, 5 May 2020 10:43:30 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=baylibre.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=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.b="xOtfbKW0"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3B07881F6F; Tue, 5 May 2020 10:43:29 +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,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) (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 BA4AF81F6F for ; Tue, 5 May 2020 10:43:26 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=narmstrong@baylibre.com Received: by mail-wr1-x441.google.com with SMTP id g13so1659894wrb.8 for ; Tue, 05 May 2020 01:43:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=w1ainhA5kBRYbUW+5Sf76wIUmxG2kIm+RsEaOCbiRgE=; b=xOtfbKW0WbxaiOjGqN0juNHfEtofs11Is9h2WR73gvL0dPH9vnMPh3eToHu0O/cSw+ 8UcEmTGlSjjlTpbnx9nMaIfkJUWIopL7NmLos8N84AHW/AI/B0M84qDVihqXyMRVY+Pd CiifwpFm/Vwsd1tlgmmNXVekg/Hd5wx+JlZLTONvRxAjYEU2fcuKhdVVau2BUQesG75W IY1tTwrXpk1ENydMzb38GtkdW4VT1Kr3sUOEdwyvVceQIE8QeZQmfo12OGVTGCNZLwFx pzbQxfCeBpZNVrWN2CyhRwxXyS/9Zvrc/RyA73RsARM2a16pMLzSqqI1FWHeO/1wpbf0 01KQ== 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:mime-version:content-transfer-encoding; bh=w1ainhA5kBRYbUW+5Sf76wIUmxG2kIm+RsEaOCbiRgE=; b=I9TrQ/3XO/nqWmoRpxoJ4WwwHAq9M3/RiR7HE5iV1EKQRUdSUwk1tCG3k6Vz6K8W8t 6tVGfmiV95tdnv6mWbKu5cNrJT4+3f2ZcBPwP7sDsjB/GN2qyErC5xDhdOUF56a5VuV5 QRTafAWa0EsfAsBGU5pRefFowfsJ5Je6jUscun5KZKmLFSvhEkDGHH1I0K+fjaZQTn0c iq4Ru9crTS8NcuwLp9F93LjXn2+RIgD0cNTq9v367jG4GUNjq/1Zo5ePlK5MWVw/c772 L1ISzfsFBMBprUBSKWt/N5MwlveY647dQHrucqJ0ORNmQ4HZQWmKIAQ/geaKjdRQgE7u 6SGg== X-Gm-Message-State: AGi0PuaGpGxz50IwuoyD02J3TnkcUEKuK8Ba50FxeepJBe+PbTVW26rZ ns+fFKsyRsbL13lwQaJ2CG8WutdISF4x6Q== X-Google-Smtp-Source: APiQypKFSFmR6ad/HIPH76unxGhkjTYSuzD14LS+KZjTYeZYyS347aMIRK/luUJaTm+BgthhyApuag== X-Received: by 2002:a5d:4d50:: with SMTP id a16mr2635340wru.219.1588668206336; Tue, 05 May 2020 01:43:26 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:2ec0:82b0:4460:3fd3:382:4a71]) by smtp.gmail.com with ESMTPSA id n2sm1959654wrt.33.2020.05.05.01.43.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2020 01:43:25 -0700 (PDT) From: Neil Armstrong To: sjg@chromium.org Cc: patrick.delaunay@st.com, u-boot@lists.denx.de, Neil Armstrong Subject: [PATCH v2 1/2] gpio: emulate open drain & open source in dm_gpio_set_value() Date: Tue, 5 May 2020 10:43:17 +0200 Message-Id: <20200505084318.15307-2-narmstrong@baylibre.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20200505084318.15307-1-narmstrong@baylibre.com> References: <20200505084318.15307-1-narmstrong@baylibre.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 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.102.2 at phobos.denx.de X-Virus-Status: Clean Handle the GPIOD_OPEN_DRAIN & GPIOD_OPEN_SOURCE flags to emulate open drain and open source by setting the GPIO line as input depending on the requested value. The behaviour is taken from the Linux gpiolib. Signed-off-by: Neil Armstrong Reviewed-by: Simon Glass --- drivers/gpio/gpio-uclass.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c index 757ab7106e..d3cea11f76 100644 --- a/drivers/gpio/gpio-uclass.c +++ b/drivers/gpio/gpio-uclass.c @@ -526,6 +526,21 @@ int dm_gpio_set_value(const struct gpio_desc *desc, int value) if (desc->flags & GPIOD_ACTIVE_LOW) value = !value; + + /* + * Emulate open drain by not actively driving the line high or + * Emulate open source by not actively driving the line low + */ + if ((desc->flags & GPIOD_OPEN_DRAIN && value) || + (desc->flags & GPIOD_OPEN_SOURCE && !value)) + return gpio_get_ops(desc->dev)->direction_input(desc->dev, + desc->offset); + else if (desc->flags & GPIOD_OPEN_DRAIN || + desc->flags & GPIOD_OPEN_SOURCE) + return gpio_get_ops(desc->dev)->direction_output(desc->dev, + desc->offset, + value); + gpio_get_ops(desc->dev)->set_value(desc->dev, desc->offset, value); return 0; }