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 B5BA0C6379F for ; Wed, 22 Feb 2023 11:00:01 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5E33585A8C; Wed, 22 Feb 2023 11:59:59 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.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=gmail.com header.i=@gmail.com header.b="jjbX9g6N"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3275785A93; Wed, 22 Feb 2023 11:59:57 +0100 (CET) Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) (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 772E5804E7 for ; Wed, 22 Feb 2023 11:59:54 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jbx6244@gmail.com Received: by mail-ed1-x533.google.com with SMTP id x10so27893784edd.13 for ; Wed, 22 Feb 2023 02:59:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=90ukbTGPEEuZC4HZ8yplUK1xH28himD62680O825DiM=; b=jjbX9g6NXJNFUnUE8Ix/XhDVPKp2vi4pP4Dyxr38VN6TuumU0wzCwiO+8X32gpB6ib BpiqCeEsqcSJ0ttBeQxfDSBnkwgKQY4cMiaSwotXuneubxaat7NONcd+PPXHreP8jApj IuRe5fq+iGh1cJvXlNgGRWGqgkgXhAYBqqEKqwZlH4oU2mFySBy9DJOXf4oQFDeG0yN2 HXn9tlZZcVRezlXGPjNL9b+mh71x8DV/6rJuA2inJX8kRU4aF148TFrWzMNpwREljwsX 8x/nUYnBEkZllShKu6nwlgv/qxf6NTCjb8WDNp0dGn3WNmcMNxItX4bFpyq9Tdu9CgIl dcyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=90ukbTGPEEuZC4HZ8yplUK1xH28himD62680O825DiM=; b=7yTw8GjAYHNavvX2GGrg9jP7GBnTA4bvJh/kSl3W/HdZ+g865IN7UWsG/Z5iZGP64l YOtGP715j7C5NsfkjRD6bGsErfrGJypn3c6D5DlSX6LSsL3Ce5XxJCN7pnWzkXEI0Z4A /LQHLagYtriO1eAK+xmszhQkO26s3jU8xYfxw4M6bm3O7TLTVS0toYZT9gfbiKth6VnX yvgWFNPHlf8YN02GgQZSro4Dwk0drh7onIC5PmqbTg6bFswDRKUI00ZddtGMnHJI6+So fzV9KGKkYBZeLdrzohEo9rD20faXHmtdCBgXl/C4S5WwQlHj6ZD77j1uFvffd7QEHJM6 oyIA== X-Gm-Message-State: AO0yUKXcvcIxT+UqDJIGZJ5OOQtVh8lMN8DTL35uSzN01xEXRa3QPWsG 3s7TLSdhiXRoNJtRqOFFeV4= X-Google-Smtp-Source: AK7set+5jgbzfEs0VpsmcovqLWwYTnytLQom1KaFW2WvYd2kE+d3smTzv5ElWauozbLoQ3uoJsuitA== X-Received: by 2002:a17:907:62a6:b0:8e0:e89b:3711 with SMTP id nd38-20020a17090762a600b008e0e89b3711mr5000069ejc.16.1677063593949; Wed, 22 Feb 2023 02:59:53 -0800 (PST) Received: from [192.168.2.1] (81-204-249-205.fixed.kpn.net. [81.204.249.205]) by smtp.gmail.com with ESMTPSA id ch26-20020a170906c2da00b008cce6c5da29sm4393601ejb.70.2023.02.22.02.59.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 22 Feb 2023 02:59:53 -0800 (PST) Message-ID: Date: Wed, 22 Feb 2023 11:59:52 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: Re: [PATCH V2 1/9] gpio: gpio-rockchip: parse gpio-ranges for bank id To: kever.yang@rock-chips.com, Linus Walleij , heiko@sntech.de Cc: sjg@chromium.org, philipp.tomsich@vrull.eu, chenjh@rock-chips.com, pgwipeout@gmail.com, heiko.stuebner@theobroma-systems.com, Chris Morgan , Chris Morgan , u-boot@lists.denx.de, Heiko Stuebner , Bartosz Golaszewski References: <20230213222742.135093-1-macroalpha82@gmail.com> <20230213222742.135093-2-macroalpha82@gmail.com> Content-Language: en-US From: Johan Jonker In-Reply-To: <20230213222742.135093-2-macroalpha82@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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 Hi Kever, Linus Walleij, Heiko, My Linux proposal has a little different logic (see below) and was "Acked-by", but the merge status is unknown. https://lore.kernel.org/linux-rockchip/890be9a0-8e82-a8f4-bc15-d5d1597343c2@gmail.com/ Could Linus/Heiko indicate if U-boot already can use this or are there other ideas? Johan On 2/13/23 23:27, Chris Morgan wrote: > From: Chris Morgan > > Use the new devicetree property of gpio-ranges to determine the GPIO > bank ID. Preserve the "old" way of doing things too, so that boards > can be migrated and tested gradually (I only have a 3566 and 3326 to > test). > > Signed-off-by: Chris Morgan > Reviewed-by: Kever Yang > --- > drivers/gpio/rk_gpio.c | 20 +++++++++++++++++--- > 1 file changed, 17 insertions(+), 3 deletions(-) > > diff --git a/drivers/gpio/rk_gpio.c b/drivers/gpio/rk_gpio.c > index 68f30157a9..98a79b5f4d 100644 > --- a/drivers/gpio/rk_gpio.c > +++ b/drivers/gpio/rk_gpio.c > @@ -142,6 +142,7 @@ static int rockchip_gpio_probe(struct udevice *dev) > { > struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev); > struct rockchip_gpio_priv *priv = dev_get_priv(dev); > + struct ofnode_phandle_args args; > char *end; > int ret; > > @@ -150,9 +151,22 @@ static int rockchip_gpio_probe(struct udevice *dev) > if (ret) > return ret; > > - uc_priv->gpio_count = ROCKCHIP_GPIOS_PER_BANK; > - end = strrchr(dev->name, '@'); > - priv->bank = trailing_strtoln(dev->name, end); > + /* > + * If "gpio-ranges" is present in the devicetree use it to parse > + * the GPIO bank ID, otherwise use the legacy method. > + */ > + ret = ofnode_parse_phandle_with_args(dev_ofnode(dev), > + "gpio-ranges", NULL, 3, > + 0, &args); > + if (!ret || ret != -ENOENT) { > + uc_priv->gpio_count = args.args[2]; > + priv->bank = args.args[1] / args.args[2]; priv->bank = args.args[1] / 32; args.args[2] The number of pins is not is not constant for every gpio node (see data sheets). Therefore can't be used as divider to get the bank number. I used 32 as simple offset method, because of register size. > + } else { > + uc_priv->gpio_count = ROCKCHIP_GPIOS_PER_BANK; > + end = strrchr(dev->name, '@'); > + priv->bank = trailing_strtoln(dev->name, end); > + } > + > priv->name[0] = 'A' + priv->bank; > uc_priv->bank_name = priv->name; >