From patchwork Sat Dec 19 17:40:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1418749 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=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=YiHMhB38; 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 4CytQN4nFYz9sVm for ; Sun, 20 Dec 2020 04:44:12 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9F91E82E19; Sat, 19 Dec 2020 18:41:33 +0100 (CET) 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="YiHMhB38"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C93C782878; Sat, 19 Dec 2020 18:40:57 +0100 (CET) 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,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd32.google.com (mail-io1-xd32.google.com [IPv6:2607:f8b0:4864:20::d32]) (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 CC7BA82869 for ; Sat, 19 Dec 2020 18:40:52 +0100 (CET) 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-io1-xd32.google.com with SMTP id p187so5147796iod.4 for ; Sat, 19 Dec 2020 09:40:52 -0800 (PST) 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=uTnVaIAm73fSJAz/a1TgTgaItyLIKB4lCnhd9CCYnZo=; b=YiHMhB38X3UGp+sIcef9T173dG47VbkzTsuAjvBdnPuDwyzuBc6sHCiVt6zMr17VrD F256oheC5qPR7/+K/Yyy22US26t8dJ6yDA70WbveXQQDFsH51ib8Wb01rDuhlENZ7h8R JUZO8imcU6kjCr1Fz9B6qU+NQWNfl02kPvb5M= 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=uTnVaIAm73fSJAz/a1TgTgaItyLIKB4lCnhd9CCYnZo=; b=SS7gt5nJRXjKNtRtZZNTYNBkU5MvqmfSALEAfvrYQJjQRVuy8zyp83B0HSzWhBNP0J CNdfiAOWORmYV+OpMizmf4H1U0GM9gsLtO2rN3sx4gJpjC55A+Uv87SOy4GqCAh/iJx4 4czGggPwoUS6OjXEZrm2j4u3iYNYtBp3OAmdL+fKgh6SVDgJ8DEFWJiaYdH3GdPEv4L3 WsQN90ZT1nd2mq6x44zpUEn0YjYmDea1C+mIh3KcNVp+IY3R/ex8sAqdg3P+1kmE+E80 BDCFJb8ejMEnCk3ZMTJseYlf5q0wBK+vdhOC/tDGSuP2b9Gi37G1rlPk0TtmlGgdqoc/ 620g== X-Gm-Message-State: AOAM530TE0I/luKzgHcdMXceqkw8t2zXeX1yaw226UgLAgrRVP8B8B2P 9GDwY6GMa5e23JvYDRPzYeJxPBTU9BGL6kv2 X-Google-Smtp-Source: ABdhPJw6CGgpMq/b6yRq1OEyJoIXUKnKZ77pYkxhY9DobGVGehRAVN+2HCGn66PtCK9g/U7fLH2Vcw== X-Received: by 2002:a6b:f714:: with SMTP id k20mr9014732iog.70.1608399651116; Sat, 19 Dec 2020 09:40:51 -0800 (PST) Received: from localhost.localdomain (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id n10sm9781962ila.69.2020.12.19.09.40.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Dec 2020 09:40:50 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Simon Glass , Anatolij Gustschin , Andy Shevchenko , Bin Meng , Heiko Schocher , Heinrich Schuchardt , Jagan Teki , Lukasz Majewski , Marek Vasut , Michael Walle , Patrick Delaunay , Pavel Herrmann , Peng Fan , Philippe Reynes , Rayagonda Kokatanur , Rick Chen , Sean Anderson , Stefan Roese , Suneel Garapati , Walter Lozano , Ye Li Subject: [PATCH 21/26] dm: core: Use dev_has_ofnode() instead of dev_of_valid() Date: Sat, 19 Dec 2020 10:40:13 -0700 Message-Id: <20201219174018.1114146-20-sjg@chromium.org> X-Mailer: git-send-email 2.29.2.684.gfbc64c5ab5-goog In-Reply-To: <20201219174018.1114146-1-sjg@chromium.org> References: <20201219174018.1114146-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.3 at phobos.denx.de X-Virus-Status: Clean We have two functions which do the same thing. Standardise on dev_has_ofnode() since there is no such thing as an 'invalid' ofnode in normal operation: it is either null or missing. Also move the functions into one place. Signed-off-by: Simon Glass Reviewed-by: Andy Shevchenko Reviewed-by: Andy Shevchenko Reviewed-by: Patrick Delaunay --- drivers/clk/clk-uclass.c | 2 +- drivers/core/device.c | 2 +- drivers/gpio/sandbox.c | 2 +- drivers/i2c/designware_i2c_pci.c | 4 ++-- drivers/i2c/i2c-uclass.c | 2 +- drivers/mmc/pci_mmc.c | 2 +- drivers/pci/pci-uclass.c | 6 +++--- drivers/pinctrl/pinctrl-uclass.c | 2 +- drivers/spi/spi-uclass.c | 2 +- drivers/sysreset/sysreset_sandbox.c | 2 +- drivers/timer/timer-uclass.c | 2 +- drivers/usb/host/usb-uclass.c | 2 +- include/dm/device.h | 13 ++++++++++++- include/dm/read.h | 16 ---------------- test/dm/pci.c | 6 +++--- 15 files changed, 30 insertions(+), 35 deletions(-) diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c index ac954a34d27..5cfd00ce771 100644 --- a/drivers/clk/clk-uclass.c +++ b/drivers/clk/clk-uclass.c @@ -345,7 +345,7 @@ int clk_set_defaults(struct udevice *dev, int stage) { int ret; - if (!dev_of_valid(dev)) + if (!dev_has_ofnode(dev)) return 0; /* If this not in SPL and pre-reloc state, don't take any action. */ diff --git a/drivers/core/device.c b/drivers/core/device.c index 8c7ce220f84..bd4ecc9e24d 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -485,7 +485,7 @@ int device_probe(struct udevice *dev) } /* Only handle devices that have a valid ofnode */ - if (dev_of_valid(dev)) { + if (dev_has_ofnode(dev)) { /* * Process 'assigned-{clocks/clock-parents/clock-rates}' * properties diff --git a/drivers/gpio/sandbox.c b/drivers/gpio/sandbox.c index 489271b560e..f8fa4baa2c3 100644 --- a/drivers/gpio/sandbox.c +++ b/drivers/gpio/sandbox.c @@ -294,7 +294,7 @@ static int gpio_sandbox_probe(struct udevice *dev) { struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev); - if (!dev_of_valid(dev)) + if (!dev_has_ofnode(dev)) /* Tell the uclass how many GPIOs we have */ uc_priv->gpio_count = CONFIG_SANDBOX_GPIO_COUNT; diff --git a/drivers/i2c/designware_i2c_pci.c b/drivers/i2c/designware_i2c_pci.c index 18eef625f0f..ec0cdf62207 100644 --- a/drivers/i2c/designware_i2c_pci.c +++ b/drivers/i2c/designware_i2c_pci.c @@ -92,7 +92,7 @@ static int designware_i2c_pci_bind(struct udevice *dev) { char name[20]; - if (dev_of_valid(dev)) + if (dev_has_ofnode(dev)) return 0; sprintf(name, "i2c_designware#%u", dev_seq(dev)); @@ -152,7 +152,7 @@ static int dw_i2c_acpi_fill_ssdt(const struct udevice *dev, int ret; /* If no device-tree node, ignore this since we assume it isn't used */ - if (!dev_of_valid(dev)) + if (!dev_has_ofnode(dev)) return 0; ret = acpi_device_path(dev, path, sizeof(path)); diff --git a/drivers/i2c/i2c-uclass.c b/drivers/i2c/i2c-uclass.c index 456cf3b85fb..be56785217c 100644 --- a/drivers/i2c/i2c-uclass.c +++ b/drivers/i2c/i2c-uclass.c @@ -678,7 +678,7 @@ static int i2c_child_post_bind(struct udevice *dev) #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) struct dm_i2c_chip *plat = dev_get_parent_plat(dev); - if (!dev_of_valid(dev)) + if (!dev_has_ofnode(dev)) return 0; return i2c_chip_of_to_plat(dev, plat); #else diff --git a/drivers/mmc/pci_mmc.c b/drivers/mmc/pci_mmc.c index fc09ad99e5e..c71c495d581 100644 --- a/drivers/mmc/pci_mmc.c +++ b/drivers/mmc/pci_mmc.c @@ -75,7 +75,7 @@ static int pci_mmc_acpi_fill_ssdt(const struct udevice *dev, struct acpi_dp *dp; int ret; - if (!dev_of_valid(dev)) + if (!dev_has_ofnode(dev)) return 0; ret = gpio_get_acpi(&priv->cd_gpio, &gpio); diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c index 1f6c51f1e8d..4cdd06b1257 100644 --- a/drivers/pci/pci-uclass.c +++ b/drivers/pci/pci-uclass.c @@ -540,7 +540,7 @@ int pci_auto_config_devices(struct udevice *bus) int ret; debug("%s: device %s\n", __func__, dev->name); - if (dev_of_valid(dev) && + if (dev_has_ofnode(dev) && dev_read_bool(dev, "pci,no-autoconfig")) continue; ret = dm_pciauto_config_device(dev); @@ -1036,7 +1036,7 @@ static int pci_uclass_pre_probe(struct udevice *bus) hose->bus = bus; hose->first_busno = dev_seq(bus); hose->last_busno = dev_seq(bus); - if (dev_of_valid(bus)) { + if (dev_has_ofnode(bus)) { hose->skip_auto_config_until_reloc = dev_read_bool(bus, "u-boot,skip-auto-config-until-reloc"); @@ -1091,7 +1091,7 @@ static int pci_uclass_child_post_bind(struct udevice *dev) { struct pci_child_plat *pplat; - if (!dev_of_valid(dev)) + if (!dev_has_ofnode(dev)) return 0; pplat = dev_get_parent_plat(dev); diff --git a/drivers/pinctrl/pinctrl-uclass.c b/drivers/pinctrl/pinctrl-uclass.c index 4653e86ba46..7919e54e8de 100644 --- a/drivers/pinctrl/pinctrl-uclass.c +++ b/drivers/pinctrl/pinctrl-uclass.c @@ -112,7 +112,7 @@ static int pinconfig_post_bind(struct udevice *dev) ofnode node; int ret; - if (!dev_of_valid(dev)) + if (!dev_has_ofnode(dev)) return 0; dev_for_each_subnode(node, dev) { diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c index f3b8ffad425..8bd35a551b8 100644 --- a/drivers/spi/spi-uclass.c +++ b/drivers/spi/spi-uclass.c @@ -155,7 +155,7 @@ static int spi_child_post_bind(struct udevice *dev) { struct dm_spi_slave_plat *plat = dev_get_parent_plat(dev); - if (!dev_of_valid(dev)) + if (!dev_has_ofnode(dev)) return 0; return spi_slave_of_to_plat(dev, plat); diff --git a/drivers/sysreset/sysreset_sandbox.c b/drivers/sysreset/sysreset_sandbox.c index 7026a48c4b2..8eca7d8bfda 100644 --- a/drivers/sysreset/sysreset_sandbox.c +++ b/drivers/sysreset/sysreset_sandbox.c @@ -50,7 +50,7 @@ static int sandbox_sysreset_request(struct udevice *dev, enum sysreset_t type) * (see the U_BOOT_DEVICE() declaration below) should not do anything. * If we are that device, return an error. */ - if (state->fdt_fname && !dev_of_valid(dev)) + if (state->fdt_fname && !dev_has_ofnode(dev)) return -ENODEV; switch (type) { diff --git a/drivers/timer/timer-uclass.c b/drivers/timer/timer-uclass.c index 8e63c17e9f3..da1a72f0252 100644 --- a/drivers/timer/timer-uclass.c +++ b/drivers/timer/timer-uclass.c @@ -54,7 +54,7 @@ static int timer_pre_probe(struct udevice *dev) ulong ret; /* It is possible that a timer device has a null ofnode */ - if (!dev_of_valid(dev)) + if (!dev_has_ofnode(dev)) return 0; err = clk_get_by_index(dev, 0, &timer_clk); diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c index ae6b1450d3a..e3b616c3266 100644 --- a/drivers/usb/host/usb-uclass.c +++ b/drivers/usb/host/usb-uclass.c @@ -773,7 +773,7 @@ static int usb_child_post_bind(struct udevice *dev) struct usb_dev_plat *plat = dev_get_parent_plat(dev); int val; - if (!dev_of_valid(dev)) + if (!dev_has_ofnode(dev)) return 0; /* We only support matching a few things */ diff --git a/include/dm/device.h b/include/dm/device.h index b15a14ec330..4a1224bcc26 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -192,6 +192,17 @@ static inline void dev_bic_flags(struct udevice *dev, u32 bic) dev->flags_ &= ~bic; } +/** + * dev_ofnode() - get the DT node reference associated with a udevice + * + * @dev: device to check + * @return reference of the the device's DT node + */ +static inline ofnode dev_ofnode(const struct udevice *dev) +{ + return dev->node; +} + /* Returns non-zero if the device is active (probed and not removed) */ #define device_active(dev) (dev_get_flags(dev) & DM_FLAG_ACTIVATED) @@ -200,7 +211,7 @@ static inline int dev_of_offset(const struct udevice *dev) return ofnode_to_offset(dev->node); } -static inline bool dev_has_ofnode(struct udevice *dev) +static inline bool dev_has_ofnode(const struct udevice *dev) { return ofnode_valid(dev->node); } diff --git a/include/dm/read.h b/include/dm/read.h index 0585eb12281..d5cdd87911d 100644 --- a/include/dm/read.h +++ b/include/dm/read.h @@ -30,22 +30,6 @@ static inline const struct device_node *dev_np(const struct udevice *dev) } #endif -/** - * dev_ofnode() - get the DT node reference associated with a udevice - * - * @dev: device to check - * @return reference of the the device's DT node - */ -static inline ofnode dev_ofnode(const struct udevice *dev) -{ - return dev->node; -} - -static inline bool dev_of_valid(const struct udevice *dev) -{ - return ofnode_valid(dev_ofnode(dev)); -} - #ifndef CONFIG_DM_DEV_READ_INLINE /** diff --git a/test/dm/pci.c b/test/dm/pci.c index 76490befdf5..fa2e4a85596 100644 --- a/test/dm/pci.c +++ b/test/dm/pci.c @@ -120,13 +120,13 @@ static int dm_test_pci_drvdata(struct unit_test_state *uts) ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(1, 0x08, 0), &swap)); ut_asserteq(SWAP_CASE_DRV_DATA, swap->driver_data); - ut_assertok(dev_of_valid(swap)); + ut_assertok(dev_has_ofnode(swap)); ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(1, 0x0c, 0), &swap)); ut_asserteq(SWAP_CASE_DRV_DATA, swap->driver_data); - ut_assertok(dev_of_valid(swap)); + ut_assertok(dev_has_ofnode(swap)); ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(1, 0x10, 0), &swap)); ut_asserteq(SWAP_CASE_DRV_DATA, swap->driver_data); - ut_assertok(!dev_of_valid(swap)); + ut_assertok(!dev_has_ofnode(swap)); return 0; }