Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 11610C43334 for ; Wed, 20 Jul 2022 17:02:56 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 920F084129; Wed, 20 Jul 2022 19:00:58 +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="Cq8AkVN6"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2286D840D9; Wed, 20 Jul 2022 19:00:37 +0200 (CEST) Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) (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 D63B2840F1 for ; Wed, 20 Jul 2022 19:00:25 +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-wr1-x42c.google.com with SMTP id z13so7429556wro.13 for ; Wed, 20 Jul 2022 10:00:25 -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=JeMCjnJ+3+VQtz244n9yLw8FiSMgWv4dNzDaWxO5kpQ=; b=Cq8AkVN6tdMB60zwfm/b3ipgpApAUrB+VS5GrhdX737QbCBs/tPJzj5dSd77pJbXaP B/HzTZ2kw7pHebHk0GUJaWPQ6VUTkn1QtqFO/bgUWmSAJonH7hsGE4HOZEKT59e0TZ3l +MfTgFTErgW6khgYa2dH9hmEEsMdylucRXsYo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JeMCjnJ+3+VQtz244n9yLw8FiSMgWv4dNzDaWxO5kpQ=; b=1SuanhZCn6LTcq5TqY09gutYTI6p1Ta/bWcnmWmMWfI4NFVuO3bW2mpsQhvDowe523 OFlYRhNbEv1jzo0bAI2ow4cmW9Kn6Z9L4yxjYnVyovND0dso9/FJpKTrTnrwTeCkdvKz 7MZL4AH17KX4s42CkOvVxnU0/KlG0BuH98Z7Jx1YXByvU90qbh0O2uVxpiZY3mhwflag U4qGlcvtIHaG0WpXw0pL+0KjFj7OrfXkKl3pz6Lyhe3ZFnez6XYXeaERVyaMqpYiKr4q CfNRQcUUjccI5AFND9e9lKt7yKlGcl5811KFPnb/CTSazl2aGB5Ts8pvh1ofOX4lnbjX ntNA== X-Gm-Message-State: AJIora8b8stP5EWX4AoGfD8xFcZUU8k8WRkZuAmweEtLyJva8EHDJepf acU81D8Yx8xAtvIu0ICFOnyKHwOId61OYT7z X-Google-Smtp-Source: AGRyM1u9pDn4HR00588OxCSvXqB0sva1GGjetediultyLsW1i9GOz2zBd5WortOWFwBRcLPJ8vaWaQ== X-Received: by 2002:adf:f28b:0:b0:21e:3161:7129 with SMTP id k11-20020adff28b000000b0021e31617129mr7643070wro.438.1658336425344; Wed, 20 Jul 2022 10:00:25 -0700 (PDT) Received: from sjg1.roam.corp.google.com ([62.48.169.138]) by smtp.gmail.com with ESMTPSA id u16-20020a05600c00d000b003a31c4f6f74sm3690906wmm.32.2022.07.20.10.00.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 10:00:24 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Simon Glass , Marek Vasut , Pavel Herrmann Subject: [PATCH 11/19] dm: core: Add support for writing u32 with ofnode Date: Wed, 20 Jul 2022 10:59:39 -0600 Message-Id: <20220720165947.12728-10-sjg@chromium.org> X-Mailer: git-send-email 2.37.0.170.g444d1eabd0-goog In-Reply-To: <20220720165947.12728-1-sjg@chromium.org> References: <20220720165947.12728-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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.6 at phobos.denx.de X-Virus-Status: Clean Add a new function to write an integer to an ofnode (live tree or flat tree). Signed-off-by: Simon Glass --- drivers/core/ofnode.c | 15 +++++++++++++++ include/dm/ofnode.h | 10 ++++++++++ test/dm/ofnode.c | 16 ++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index b7a55589a1c..45ea84e9fb8 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -1126,6 +1126,21 @@ int ofnode_write_string(ofnode node, const char *propname, const char *value) return ofnode_write_prop(node, propname, value, strlen(value) + 1); } +int ofnode_write_u32(ofnode node, const char *propname, u32 value) +{ + fdt32_t *val; + + assert(ofnode_valid(node)); + + log_debug("%s = %x", propname, value); + val = malloc(sizeof(*val)); + if (!val) + return -ENOMEM; + *val = cpu_to_fdt32(value); + + return ofnode_write_prop(node, propname, val, sizeof(value)); +} + int ofnode_set_enabled(ofnode node, bool value) { assert(ofnode_valid(node)); diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index 16c8890b097..7ce1e4c6d91 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -1154,6 +1154,16 @@ int ofnode_write_prop(ofnode node, const char *propname, const void *value, */ int ofnode_write_string(ofnode node, const char *propname, const char *value); +/** + * ofnode_write_u32() - Set an integer property of an ofnode + * + * @node: The node for whose string property should be set + * @propname: The name of the string property to set + * @value: The new value of the 32-bit integer property + * Return: 0 if successful, -ve on error + */ +int ofnode_write_u32(ofnode node, const char *propname, u32 value); + /** * ofnode_set_enabled() - Enable or disable a device tree node given by its * ofnode diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c index bd598d23e44..f80993f8927 100644 --- a/test/dm/ofnode.c +++ b/test/dm/ofnode.c @@ -585,3 +585,19 @@ static int dm_test_ofnode_livetree_writing(struct unit_test_state *uts) } DM_TEST(dm_test_ofnode_livetree_writing, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT | UT_TESTF_LIVE_OR_FLAT); + +static int dm_test_ofnode_u32(struct unit_test_state *uts) +{ + ofnode node; + + node = ofnode_path("/lcd"); + ut_assert(ofnode_valid(node)); + ut_asserteq(1366, ofnode_read_u32_default(node, "xres", 123)); + ut_assertok(ofnode_write_u32(node, "xres", 1367)); + ut_asserteq(1367, ofnode_read_u32_default(node, "xres", 123)); + ut_assertok(ofnode_write_u32(node, "xres", 1366)); + + return 0; +} +DM_TEST(dm_test_ofnode_u32, + UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT | UT_TESTF_LIVE_OR_FLAT); -- 2.37.0.170.g444d1eabd0-goog