From patchwork Sun May 10 20:33:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1287392 X-Patchwork-Delegate: bmeng.cn@gmail.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=pass (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=C90wHG7H; 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 49Kwrk1CBHz9sNH for ; Mon, 11 May 2020 06:38:45 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C55408195D; Sun, 10 May 2020 22:35:35 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="C90wHG7H"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BA77C81673; Sun, 10 May 2020 22:35:02 +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=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x143.google.com (mail-il1-x143.google.com [IPv6:2607:f8b0:4864:20::143]) (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 C5C26813B8 for ; Sun, 10 May 2020 22:34:57 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-il1-x143.google.com with SMTP id c18so6518796ile.5 for ; Sun, 10 May 2020 13:34:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=N3Mo2wyxhNCb+3YLfuKPs8uN9E4ltQaTkAZtSp+zPCA=; b=C90wHG7H8bD++xsN4fW+oBjvAhiFmcCnRv481PK5IVEOV0Ulv/LXiE8kCs64iIFSVP uYEGP69hDZnzP7I58l7ECp2pOrMChoTtgGJnKWfL9glDg89HFreFAfewikuwTqjeoYgO rrEE5HBtXx3vMJUzs7G5C7Ww/SivPkvFQ+USU= 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=N3Mo2wyxhNCb+3YLfuKPs8uN9E4ltQaTkAZtSp+zPCA=; b=nbjW3g/y4/4fpuBt6DR991dP1I6KkcvFN9Hi2EWw1WGM7vU5WJnXzU8QiqDTdyl5OO UHh3VbKTPeNUOXRJr+4dRRUNTl9eD9O+BSDyqiIcaDvm0itHm5I5iotQNTVgwfyIScBq 5CwDjEiy8GCnIF34vED2xhzEteJ/7yplut4oQXH1YdM0P5v+v2uyWaMtWjUH2DEz2J/C TccR9yElPgycWcohikGoJv3BUys4bUZt22Oy29d2opC9hXpvxlgOhajQStI5CF+Kf8R1 EvIYZIHka9J4qnrN0GIEWWDK5fwc6RuVb4givKbOcm6ykSRDZx3/3m3aspUVVpRM41nk CE0A== X-Gm-Message-State: AGi0PuasZ3cnIUdCkDEZ+Io5Qq0N3hRDhlzO0q1aLO0D4DhAlAfg8xCV v45EceKQ4bAYyOaba4PnWuSlVwmrlqM= X-Google-Smtp-Source: APiQypLd2Nyaqz4d2T9MV/6FsKKhPSQs7Togdswb+8Os+rC9vgWjyXuCRb29k5G6Ihc6XgmywH9TwQ== X-Received: by 2002:a05:6e02:4ad:: with SMTP id e13mr2715637ils.253.1589142896524; Sun, 10 May 2020 13:34:56 -0700 (PDT) Received: from localhost.localdomain (c-73-14-175-90.hsd1.co.comcast.net. [73.14.175.90]) by smtp.gmail.com with ESMTPSA id k2sm3607191ioq.20.2020.05.10.13.34.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 May 2020 13:34:56 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Wolfgang Wallner , Bin Meng , Andy Shevchenko , Simon Glass Subject: [PATCH v2 20/35] acpi: Support writing a GPIO Date: Sun, 10 May 2020 14:33:54 -0600 Message-Id: <20200510203409.203520-18-sjg@chromium.org> X-Mailer: git-send-email 2.26.2.645.ge9eca65c58-goog In-Reply-To: <20200510203409.203520-1-sjg@chromium.org> References: <20200510203409.203520-1-sjg@chromium.org> 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 Allowing writing out a reference to a GPIO within the ACPI output. This can be used by ACPI code to access a GPIO at runtime. Signed-off-by: Simon Glass --- Changes in v2: None Changes in v1: None include/acpi/acpi_dp.h | 18 ++++++++++++++++++ lib/acpi/acpi_dp.c | 21 +++++++++++++++++++++ test/dm/acpi_dp.c | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+) diff --git a/include/acpi/acpi_dp.h b/include/acpi/acpi_dp.h index 840be855c5..f42602405a 100644 --- a/include/acpi/acpi_dp.h +++ b/include/acpi/acpi_dp.h @@ -202,6 +202,24 @@ struct acpi_dp *acpi_dp_add_integer_array(struct acpi_dp *dp, const char *name, struct acpi_dp *acpi_dp_add_child(struct acpi_dp *dp, const char *name, struct acpi_dp *child); +/** + * acpi_dp_add_gpio() - Add a GPIO to a list of Device Properties + * + * A new node is added to the end of the property list of @dp, with the + * GPIO properties added to the the new node + * + * @dp: Table to add this property to + * @name: Name of property + * @ref: Reference to device with a _CRS containing GpioIO or GpioInt + * @index: Index of the GPIO resource in _CRS starting from zero + * @pin: Pin in the GPIO resource, typically zero + * @active_low: true if pin is active low + * @return pointer to new node, or NULL if out of memory + */ +struct acpi_dp *acpi_dp_add_gpio(struct acpi_dp *dp, const char *name, + const char *ref, int index, int pin, + bool active_low); + /** * acpi_dp_write() - Write Device Property hierarchy and clean up resources * diff --git a/lib/acpi/acpi_dp.c b/lib/acpi/acpi_dp.c index 479cb6743c..4ba5d555a0 100644 --- a/lib/acpi/acpi_dp.c +++ b/lib/acpi/acpi_dp.c @@ -322,3 +322,24 @@ struct acpi_dp *acpi_dp_add_integer_array(struct acpi_dp *dp, const char *name, return dp_array; } + +struct acpi_dp *acpi_dp_add_gpio(struct acpi_dp *dp, const char *name, + const char *ref, int index, int pin, + bool active_low) +{ + struct acpi_dp *gpio; + + assert(dp); + gpio = acpi_dp_new_table(name); + if (!gpio) + return NULL; + + acpi_dp_add_reference(gpio, NULL, ref); + acpi_dp_add_integer(gpio, NULL, index); + acpi_dp_add_integer(gpio, NULL, pin); + acpi_dp_add_integer(gpio, NULL, active_low); + + acpi_dp_add_array(dp, gpio); + + return gpio; +} diff --git a/test/dm/acpi_dp.c b/test/dm/acpi_dp.c index c11394786f..d6a054a98b 100644 --- a/test/dm/acpi_dp.c +++ b/test/dm/acpi_dp.c @@ -403,3 +403,42 @@ static int dm_test_acpi_dp_child(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_acpi_dp_child, 0); + +/* Test emitting a GPIO */ +static int dm_test_acpi_dp_gpio(struct unit_test_state *uts) +{ + struct acpi_ctx *ctx; + struct acpi_dp *dp; + u8 *ptr, *pptr; + + ut_assertok(alloc_context(&ctx)); + + dp = acpi_dp_new_table("FRED"); + ut_assertnonnull(dp); + + /* Try a few different parameters */ + ut_assertnonnull(acpi_dp_add_gpio(dp, "reset", TEST_REF, 0x23, 0x24, + false)); + ut_assertnonnull(acpi_dp_add_gpio(dp, "allow", TEST_REF, 0, 0, true)); + + ptr = acpigen_get_current(ctx); + ut_assertok(acpi_dp_write(ctx, dp)); + ut_asserteq(0x6e, acpigen_get_current(ctx) - ptr); + + pptr = ptr + 0x2c; //0x3a; + ut_asserteq_str("reset", (char *)pptr); + ut_asserteq_strn(EXPECT_REF, (char *)pptr + 0xe); + ut_asserteq(0x23, pptr[0x1b]); + ut_asserteq(0x24, pptr[0x1d]); + ut_asserteq(ZERO_OP, pptr[0x1e]); + + pptr = ptr + 0x51; + ut_asserteq_str("allow", (char *)pptr); + ut_asserteq_strn(EXPECT_REF, (char *)pptr + 0xe); + ut_asserteq(ZERO_OP, pptr[0x1a]); + ut_asserteq(ZERO_OP, pptr[0x1b]); + ut_asserteq(ONE_OP, pptr[0x1c]); + + return 0; +} +DM_TEST(dm_test_acpi_dp_gpio, 0);