Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp829309ybh; Wed, 11 Mar 2020 11:40:04 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvM0hKvYl+oedTazVh0D5yZUDI0o7Q6PysQ1eiuDDIhB+ZixoO3t3Tz9OMRq5fC1WRSVL4h X-Received: by 2002:a05:6830:2246:: with SMTP id t6mr3435706otd.46.1583952004534; Wed, 11 Mar 2020 11:40:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583952004; cv=none; d=google.com; s=arc-20160816; b=h37aqoMUUa6VOKDVzTJ0oW4gdd5lXpkM1Waclfn5fUi0yKBEirD6j+opL/inJt88fM ozr2byhX7kh13DUHGlPEH2vHruSFDqzj9tFrjk9Lzm3jbucg1+IWpHFbOkk7z+HEomgw 8nZKdogYETf08CcYSYfM4XM4VWqyVk/i8MMrGhm0MfPRD1MpirTdO6VOXe7wTbM+XJpo 7O4F8mD3SpR3qiBqOeCs7DffwM6pdZJ+4d4Y24ErIJ7fowQOLFQi/KW5KVEpYs7ooX2+ AWJB7a3T5pgE+5b2YxF6UKGRROfIAxFB6vIoS5ALJiPTVdDV1ZxvQOfzXfwXVk7Q+C1I U1Qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:from:references:cc:to:subject:dkim-signature; bh=i3ki1XFvn7TEp/5S0kbEyql6MIJlqruhqzKBemgHTXI=; b=MCbPdDN/HKRzNKatztyb6bUPUvhy3pXFZLy5qRKwmF9zTKFqKdboA7un98iRdsg/dI bO+xWxgJHSg+8DYAL1O3+5D38EtJUffnwy8/aewQ0463d7mja8yWtFJAa8i/taWmAWVU uEr40humaWBXzIafgizWF12UvEwGtzf+U5U8sJAgE/TmkCgT0nERFCnc+OY0Am+xWOE4 MBeYdxdaF+QqJNICuuITBKvQvU0TI6N1RJxjP0yI4UTjgTCDVmH/VnmKxokyWaG1icC/ 6kbeo0+H1qLb5dSCFSXT5FkARFo0etEpYe4H5TIlEeDbAyp+gi4tdT3Y76f6gF6RnOwJ BXHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=hU6s6cMW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r13si1422893otd.167.2020.03.11.11.39.52; Wed, 11 Mar 2020 11:40:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=hU6s6cMW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730888AbgCKSiI (ORCPT + 99 others); Wed, 11 Mar 2020 14:38:08 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:42427 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730734AbgCKSiH (ORCPT ); Wed, 11 Mar 2020 14:38:07 -0400 Received: by mail-wr1-f67.google.com with SMTP id v11so3965808wrm.9; Wed, 11 Mar 2020 11:38:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:autocrypt:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=i3ki1XFvn7TEp/5S0kbEyql6MIJlqruhqzKBemgHTXI=; b=hU6s6cMWtfJinGOlywjEnRZPgbi3fgg/h5p15Sw/ZRdT8ciQdCPu4/TRqj2/0/cKAO tapz0Qb41Ge7EiBZoZRVMcqjRb+R0qFew5S91XbSwzW8ICb5Cn6AOZ5NV73U5uwMPNqv qsVK+VQ+YM6P6Dx71Yk9tgwwLPZCYbrr7O61NoSoWGwrnNYK9sO2SC1IOIT+b6hd1Bz8 SqylbB5wkXHgAyNbZjzRuXxvTgpC5fC8eEeFypY+KfpoktDcbhsq04TdKchOo5RqTJo7 t7x3qqGd+/vq+nqOpqtCCo1p9LhrYUH5BBHrJ1q2R1H49WCFOLuCessJ2DdyjuiafVwT yJWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:autocrypt :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=i3ki1XFvn7TEp/5S0kbEyql6MIJlqruhqzKBemgHTXI=; b=OVX49LpF2AYEEtM/CUJrLWKZA31GXfqqu7mwv4453PD4vHO92jm8UMBAxe/bk43BbP mLJJdiv/A/lLlY1emFmI9gU6IzfuyNsihQ2pNYrq+7VHgo0Mp/EdtkVauQrWYHqG5G3e 1MWS5aq8IDw7S77oOTUpb5drieCoGk+7noKcjcpM/Kh5LQPFuLYLOrPQuxNPjM4A6Wnv Qm7SSoiuIKWfLYuUAnimPbew+X0nyv6Ed8AzFe8me/9hTxT0+mP4FN8AMYBUkyJmvMgS g+GhajFNcdH3iqwj96OIr/c580UqkOXHG/O/73urHXUArN79CXRvwuAlk2iz8wBh+rXp X2Xg== X-Gm-Message-State: ANhLgQ28U9y55R7oakueSW0l93FQsX1e3fGQLE+m7Gb3x9IgLWkUBk/r n+5dQIEYOXQL3VQqMh2BddFGPeD4 X-Received: by 2002:a5d:608e:: with SMTP id w14mr6150991wrt.201.1583951883840; Wed, 11 Mar 2020 11:38:03 -0700 (PDT) Received: from [10.67.49.112] ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id u204sm6644688wmg.40.2020.03.11.11.38.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 11 Mar 2020 11:38:03 -0700 (PDT) Subject: Re: [PATCH V2] gpio: brcmstb: support gpio-line-names property To: Linus Walleij Cc: Gregory Fong , Bartosz Golaszewski , Florian Fainelli , bcm-kernel-feedback-list , "open list:GPIO SUBSYSTEM" , Linux ARM , "linux-kernel@vger.kernel.org" References: <1583780521-45702-1-git-send-email-opendmb@gmail.com> From: Doug Berger Autocrypt: addr=opendmb@gmail.com; prefer-encrypt=mutual; keydata= xsBNBFWUMnYBCADCqDWlxLrPaGxwJpK/JHR+3Lar1S3M3K98bCw5GjIKFmnrdW4pXlm1Hdk5 vspF6aQKcjmgLt3oNtaJ8xTR/q9URQ1DrKX/7CgTwPe2dQdI7gNSAE2bbxo7/2umYBm/B7h2 b0PMWgI0vGybu6UY1e8iGOBWs3haZK2M0eg2rPkdm2d6jkhYjD4w2tsbT08IBX/rA40uoo2B DHijLtRSYuNTY0pwfOrJ7BYeM0U82CRGBpqHFrj/o1ZFMPxLXkUT5V1GyDiY7I3vAuzo/prY m4sfbV6SHxJlreotbFufaWcYmRhY2e/bhIqsGjeHnALpNf1AE2r/KEhx390l2c+PrkrNABEB AAHNJkRvdWcgQmVyZ2VyIDxkb3VnLmJlcmdlckBicm9hZGNvbS5jb20+wsEHBBABAgCxBQJa sDPxFwoAAb9Iy/59LfFRBZrQ2vI+6hEaOwDdIBQAAAAAABYAAWtleS11c2FnZS1tYXNrQHBn cC5jb22OMBSAAAAAACAAB3ByZWZlcnJlZC1lbWFpbC1lbmNvZGluZ0BwZ3AuY29tcGdwbWlt ZQgLCQgHAwIBCgIZAQUXgAAAABkYbGRhcDovL2tleXMuYnJvYWRjb20uY29tBRsDAAAAAxYC AQUeAQAAAAQVCAkKAAoJEEv0cxXPMIiXDXMH/Aj4wrSvJTwDDz/pb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xbpj2IxyJmGyq2J ASkJEEv0cxXPMIiXwF0gBBkBCAAGBQJVlDJ3AAoJEKbLJ7TOGgQNddUIAKMPfjPx9Fqyrf3x 4IfOHVEJEjy9FbWEpj5SvwRPuAOzC2jfr0Dc9hLfyErg1rc9AnSSMHXansRUDWuljP+WkEIM ynoTY/IntnJOCRgYcm8d+uPTqlI9U/kQYMshU5UXlEZR0D+tLVytxOZDmvVFjJ7jBC7rPilz j4hQ00XkrfyJ6kxP9n4X6gNMmLKxZWuGkLZ2KVrpW9MqKkrWTvl29WTJPa7mKMYiqsqzaLBQ mqvxE9RRilmWoos/6SJH6n5gjXrOpvU58F/kjocXbSzqQpKTXjlegMBX36HTlfQ24bRbar94 Fy1r5MKGJXeLz/jgLy+fhgEnFumPYjHImYbKrYlN5gf8CIoI48e2+5V9b6YlvMeOCGMajcvU rHJGgdF+SpHoc95bQLV+cMLFO5/4UdPxP8NFnJWoeoD/6MxKa6Z5SjqUS8k3hk81mc3dFQh3 yWj74xNe+1SCn/7UYGsnPQP9rveri8eubraoRZMgLe1XdzyjG8TsWqemAa7/kcMbu3VdHe7N /jdoA2BGF7+/ZujdO89UCrorkH0TOgmicZzaZwN94GYmm69lsbiWWEBvBOLbLIEWAzS0xG// PxsxZ8Cr0utzY4gvbg+7lrBd9WwZ1HU96vBSAeUKAV5YMxvFlZCTS2O3w0Y/lxNR57iFPTPx rQQYjNSD8+NSdOsIpGNCZ9xhWw== Message-ID: Date: Wed, 11 Mar 2020 11:38:00 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Thanks for taking the time to review this. On 3/11/20 8:32 AM, Linus Walleij wrote: > On Mon, Mar 9, 2020 at 8:02 PM Doug Berger wrote: > >> The default handling of the gpio-line-names property by the >> gpiolib-of implementation does not work with the multiple >> gpiochip banks per device structure used by the gpio-brcmstb >> driver. To expand on this description, the crux of the issue is that the gpio-brcmstb hardware has some nicely banked registers and some not-so-nicely-banked common registers. This lead to the decision to implement the driver to manage multiple banks as a single GPIO device with a single device-tree node rather than separate devices for each bank each with its own device-tree node. In addition, most implementations include a hardware block within an "Always On" power island and a second block that can be powered down. Each of these blocks is represented as a separate device with their own device-tree node and are managed by this driver. The gpio_chip abstraction in the gpiolib provides a lot of useful functionality for managing the banks of GPIO for the gpio-brcmstb driver, but unfortunately it breaks down in a couple of places because of the common device tree node that is shared by each bank. One area is the IRQ chip helpers which were tried but needed to be reverted. Another is labeling, which this commit attempts to address. The device-tree node for each device can optionally contain a single gpio-line-names property with a list of names to be applied to the GPIO managed by the driver. >> >> This commit adds driver level support for the device tree >> property so that GPIO lines can be assigned friendly names. >> > > >> Signed-off-by: Doug Berger >> +static void brcmstb_gpio_set_names(struct device *dev, >> + struct brcmstb_gpio_bank *bank) >> +{ >> + struct device_node *np = dev->of_node; >> + const char **names; >> + int nstrings, base; > > I don't understand why that thing is named "base".Since this function is applied to each bank, it is necessary to know what the device relative index is for the first GPIO contained within this bank. That is the purpose of this base variable. It is used to index the device relative list of gpio labels. GPIO0 of bank 0 would have a base of 0. GPIO0 of bank 1 would have a base of MAX_GPIO_PER_BANK, and so on. >> + unsigned int i; >> + >> + base = bank->id * MAX_GPIO_PER_BANK; > > That would be ngpios or something. > > But you alread have what you need in bank->gc.ngpio, right? > > So why calculate it? Almost. ngpios is the number of gpios in the bank which in this case is always MAX_GPIO_PER_BANK. bank->gc.base is almost the right value, but it is relative to the GPIO subsystem which can include multiple devices rather than the specific device that contains this bank. bank->id is device relative so bank->id * MAX_GPIO_PER_BANK gives us the desired device relative offset. >> + nstrings = of_property_count_strings(np, "gpio-line-names"); >> + if (nstrings <= base) >> + /* Line names not present */ >> + return; >> + >> + names = devm_kcalloc(dev, MAX_GPIO_PER_BANK, sizeof(*names), >> + GFP_KERNEL); >> + if (!names) >> + return; >> + >> + /* >> + * Make sure to not index beyond the end of the number of descriptors >> + * of the GPIO device. >> + */ >> + for (i = 0; i < bank->width; i++) { >> + const char *name; >> + int ret; >> + >> + ret = of_property_read_string_index(np, "gpio-line-names", >> + base + i, &name); >> + if (ret) { >> + if (ret != -ENODATA) >> + dev_err(dev, "unable to name line %d: %d\n", >> + base + i, ret); >> + break; >> + } >> + if (*name) >> + names[i] = name; >> + } >> + >> + bank->gc.names = names; >> +} > > Why can't you just make the function > devprop_gpiochip_set_names() public, (line in ) > and convert your np to a fwnode and call that &bank->gc ? This is basically the current functionality as provided by the call to gpiochip_add_data() in probe that this commit attempts to correct. Since the fwnode is the same for all banks of the same device each bank repeats the first MAX_GPIO_PER_BANK label names in each bank. This commit populates the gc.names member of each bank from the device-tree node within the driver. This overrides the default behavior since devprop_gpiochip_set_names() will only be called if names is NULL. > > Yours, > Linus Walleij > I hope that explanation makes sense. Thanks again, Doug