From patchwork Wed Apr 29 08:06:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 1279088 X-Patchwork-Delegate: sjg@chromium.org 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=vouARiS7; 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 49BrhH04Tnz9sSM for ; Wed, 29 Apr 2020 18:06:54 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C4C3482060; Wed, 29 Apr 2020 10:06:48 +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="vouARiS7"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9303682063; Wed, 29 Apr 2020 10:06:46 +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-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) (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 648F28205B for ; Wed, 29 Apr 2020 10:06:43 +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-x443.google.com with SMTP id s10so1362298wrr.0 for ; Wed, 29 Apr 2020 01:06:43 -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:mime-version :content-transfer-encoding; bh=ycP8DMFeRohxih1xBQHFPuhM6lz5P7eCVYkycIYce0U=; b=vouARiS7pJdBUStI07D0hqZUmCUy1F9dxvMp5AwJZxzZuMMN54UNlcQb9a2ORM4pWY 1YzVuoR9g48JXuFckww4ucm1qDVYoTJk7ZB4u269VOE3x0j1HVg0vp95dnrDVw4AF3Wu abSYEnePQ0LZ0v/ZKYTMBNOcJEYVGNpLXhMy1A4SiSfKWIbr8jjGLITuTJW3ixEALRcO LfqZ8fTXTXokvtQdRRNGTioh5PXAwZemWGCXDkvQi6GTKkJd7Ghg8KnX30DQ6oEIslSs PBJK4wJIgkzvSM++XI63LZw5EpbJV2xWy28vT9G83lzrCZFCByf5pAec/jWf1+5nZ25P oWXw== 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:mime-version :content-transfer-encoding; bh=ycP8DMFeRohxih1xBQHFPuhM6lz5P7eCVYkycIYce0U=; b=Ii4NZRSM7gXM8+mEH7pnhN5530f8uFvgpzFV2KyAWfZXzP62Zujk/oTQJxUM1sG7Nj AgUmjo+dWjCYHlHHqwStaKvyHKXOJxD1Dgv7ABa5vJJmRjVUoqsmtob32wNkJGKZr2GJ H46gezemeveq1WiHOfZODw/zbkyngUVuvfO6lHzcg7r+jCmzsXcRx9f1RZVUS8gh+E6Q sibiQIpiueIYQI0MmgNZp0euVpZC23t73+gQkxDKPjMyG2Ptbry351mHDEVEdCTvHgZw o/FR7MZgMt/DBnjcPXCRtHOIonLi7lghGLRjHw6s8/W1qCb2qdrikJCkjGMxgKk+oqId +MMg== X-Gm-Message-State: AGi0PuY3bZOuqZY46cLteooY6r7wB6txaFJQjIX3eEtt25ZGaXrKsWz6 BXnf2ItA4yaPnlMiZvLQVv8Zfg== X-Google-Smtp-Source: APiQypL3CJ14PFGo3fzYYfHvfsMHx3skBh835hucS5HlE9l1oV714Tprm0EDptEwHAGgqIEiv4+PJw== X-Received: by 2002:a5d:6647:: with SMTP id f7mr39965749wrw.41.1588147602489; Wed, 29 Apr 2020 01:06:42 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:2ec0:82b0:4460:3fd3:382:4a71]) by smtp.gmail.com with ESMTPSA id r2sm6759514wmg.2.2020.04.29.01.06.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Apr 2020 01:06:41 -0700 (PDT) From: Neil Armstrong To: sjg@chromium.org, patrick.delaunay@st.com Cc: Neil Armstrong , u-boot@lists.denx.de, u-boot-amlogic@groups.io Subject: [PATCH] gpio: emulate open drain & open source in dm_gpio_set_value() Date: Wed, 29 Apr 2020 10:06:34 +0200 Message-Id: <20200429080634.355-1-narmstrong@baylibre.com> X-Mailer: git-send-email 2.22.0 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. It notably permits enabling a GPIO regulator used as Open Drain on the Amlogic G12A/g12B/SM1 platforms for HDMI output feature. Signed-off-by: Neil Armstrong --- drivers/gpio/gpio-uclass.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c index 757ab7106e..6b82d02a4d 100644 --- a/drivers/gpio/gpio-uclass.c +++ b/drivers/gpio/gpio-uclass.c @@ -524,8 +524,21 @@ int dm_gpio_set_value(const struct gpio_desc *desc, int value) if (ret) return ret; + /* + * 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 | GPIOD_OPEN_SOURCE)) + goto set_output_value; + if (desc->flags & GPIOD_ACTIVE_LOW) value = !value; + +set_output_value: gpio_get_ops(desc->dev)->set_value(desc->dev, desc->offset, value); return 0; }