Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2272859pxv; Sat, 3 Jul 2021 04:10:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4X5JaQG276xhnzI/V/nIMliBYjzEfc53HShbjE0ctpt3b/O54wNSapaorCPrVF7WoWtXN X-Received: by 2002:a02:c615:: with SMTP id i21mr3414051jan.4.1625310617812; Sat, 03 Jul 2021 04:10:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625310617; cv=none; d=google.com; s=arc-20160816; b=qcWUlNTd0yc502xaPd0LcMAw9RHC+Ogtr5I6CyfFwtWRywpW9rJI4DfUPkucwOLglf gpHDORI6aoEogjrgbKiKmlIkbDy7O3VUmGMCobSwL2TYUq+yrryNUonTUuH2VbZ8/Weg 6S/0PdyebMhIivs/0Bis95QX8iZ5aYti+1OlO0k1uvicbPuVl//EbnLBybVmAJbCsjYQ Z+8jqDv4MGyzmULGkd4jTGhavxnMC1Gu9x3st5T3Tj95yFMLb7zjMhGahGkMuxhKSLE9 Qugy9Qw0l+MPGDWn1C973qfRKLc27gxm4zTD97N9ED722aPc5dzvO9cSuD/dw/+UTD3Y /VmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=KZ4HsDs6b9mvzeZXoceC90pUFVVJiY28SrKqwA4xe4Y=; b=KYKC5cb1tQE2pr8CenHlwDdiZvD/YywNGDJrH7HOv84X48T/dLR1GiwYEDmojkMKWc kd083eFBjJ/V9bfnfQAvoXwAHRUd+qKTOsB5sSQVcRq8ilNsSXgGHlfHG9GRaAGWN07j rYavTn4RKLvIZp5yJnSqFy+MJpOm9NybYsvf6LpCqErurllfJY0QgGgMCiOADzEx6agb YPGAs7chzQ8E/qWHMWFIdHIOJDshdlL8AchbGd3kh1y/T+6NWKqdkHDr6i0KIIuop2UN 5HRzL8SjQxk0x1eopzLJpjVEL72oi+HS7r5DCzRsuwFauoPLzc0sey3g1AaCcbeGPVvp /hbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=tILncNLN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id f17si6505984jaj.104.2021.07.03.04.09.47; Sat, 03 Jul 2021 04:10:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=tILncNLN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S230148AbhGCLJa (ORCPT + 99 others); Sat, 3 Jul 2021 07:09:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229829AbhGCLJ3 (ORCPT ); Sat, 3 Jul 2021 07:09:29 -0400 Received: from mail-vk1-xa35.google.com (mail-vk1-xa35.google.com [IPv6:2607:f8b0:4864:20::a35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E3F7C061762; Sat, 3 Jul 2021 04:06:55 -0700 (PDT) Received: by mail-vk1-xa35.google.com with SMTP id j23so291235vki.4; Sat, 03 Jul 2021 04:06:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=KZ4HsDs6b9mvzeZXoceC90pUFVVJiY28SrKqwA4xe4Y=; b=tILncNLNWsI2BEyuUUkoFyxW5upoSeuYnCMTnHdQUYPMob1IDTB+txpGexY5r1LExI gXy5Axp6GAvdQ24NlJa1cSrJqz506sUxYeOL5ZW8pO/1j0FYKAjVlD+oeTd4wwKiNt35 p8cWeeWBhpBAFBA1++TGUVITinY0UdrQhccyZuQRD1MvBmGpRmXkw6evDpRjDtaBqVUG wbYeQZqCkU+JxNkqjF01vm60sL8MLv7xCbCutVLlYzOio6DLxqWY/ranpu/uEgmrsk4Z euWQdC37mfyXTs2jr/dcdLiMdPvdIjLga2dkN36KaFBS+F3XxT1yzxATWyrbB2in6Z/c n0qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=KZ4HsDs6b9mvzeZXoceC90pUFVVJiY28SrKqwA4xe4Y=; b=pZ3jefS8/E//e9LZKZwk3RNShZy2k4IzcJfi/aILgS6F3hKVpRMy68hr5q99HI6s9G ESfu6NEN+jNBU3kdTjgh2vzcvItBhro0jLWs4HpkwgwBMOTRUC9OOMkqZFygacLIRnNo WALuST4JlIUzUj5clT64vBqEe6TJzOS3807+KpztJ2YtIRDOpDsRri3fFf+HjZs7JRgu MXwtIQoqJXdZI9/AKEsJqkMbEC6NJUEhWV7FrqFQL8giIS9LNCuHIckUYkWKRfTUEdKD R0MesZglknkeWT+yoC1VNwp4ovwETfrlmSMEKtIuBkt0LgUnYvDXJC2qt3+GvF0n2q79 CYTw== X-Gm-Message-State: AOAM533Ympr19wrePHZZ4VZMzwArCT1VZAswb/RoY8FKwkawh+hcC6lc OhIrCC0+GuFMSeUqUCwli/zWDIyPx3OlJYY5gmo= X-Received: by 2002:a05:6122:2090:: with SMTP id i16mr3315243vkd.5.1625310413980; Sat, 03 Jul 2021 04:06:53 -0700 (PDT) MIME-Version: 1.0 References: <20210626161819.30508-1-sergio.paracuellos@gmail.com> In-Reply-To: From: Sergio Paracuellos Date: Sat, 3 Jul 2021 13:06:42 +0200 Message-ID: Subject: Re: [PATCH v2] gpio: mt7621: support gpio-line-names property To: Linus Walleij Cc: Andy Shevchenko , "open list:GPIO SUBSYSTEM" , Bartosz Golaszewski , Matthias Brugger , John Thomson , Linux Kernel Mailing List , NeilBrown , =?UTF-8?Q?Ren=C3=A9_van_Dorst?= , Nicholas Mc Guire Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Linus, On Fri, Jul 2, 2021 at 1:30 PM Sergio Paracuellos wrote: > > Hi Linus, > > On Fri, Jul 2, 2021 at 12:18 PM Linus Walleij wrote: > > > > On Fri, Jul 2, 2021 at 11:40 AM Sergio Paracuellos > > wrote: > > > On Fri, Jul 2, 2021 at 11:27 AM Andy Shevchenko > > > wrote: > > > > > > > There are no child nodes, all the stuff is in the same parent node > > > > > and, as I said, belongs to the same device but internally uses three > > > > > gpiochips. > > > > > > > > And it can't be split into three children in the overlay? > > > > > > Original code before this being mainlined was using three children and > > > I was told in the review that three children were not allowed: > > > > > > See https://patchwork.ozlabs.org/project/linux-gpio/patch/1527924610-13135-3-git-send-email-sergio.paracuellos@gmail.com/#1932827 > > > > Yeah this is one of those unfortunate cases where the DT representation > > (or ACPI for that matter) of the device and the Linux internal representation > > differs. > > > > > > Let's assume it can't, then the GPIO library function should be > > > > refactored in a way that it takes parameters like base index for the > > > > names and tries to satisfy the caller. > > > > > > Bartosz, Linus, any thoughts on this? > > > > This would be ideal, is there a reasonably simple way to get to this helper? > > > > In gpiolib.c devprop_gpiochip_set_names() need to be refactored to > > take a base number, devprop_gpiochip_set_names_base() that > > function exposed in and then the old function > > devprop_gpiochip_set_names() wrapped in the new > > one so all old users continue to work without modification. > > Sprinkle some kerneldoc on top so we do not make mistakes > > in the future. > > > > This should work I think. If I am understanding correctly what you mean is something like follows: diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 6e3c4d7a7d14..5a88a305bc59 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -361,13 +361,14 @@ static int gpiochip_set_desc_names(struct gpio_chip *gc) /* * devprop_gpiochip_set_names - Set GPIO line names using device properties * @chip: GPIO chip whose lines should be named, if possible + * @base: starting index in names array to start copying from * * Looks for device property "gpio-line-names" and if it exists assigns * GPIO line names for the chip. The memory allocated for the assigned * names belong to the underlying software node and should not be released * by the caller. */ -static int devprop_gpiochip_set_names(struct gpio_chip *chip) +static int devprop_gpiochip_set_names(struct gpio_chip *chip, int base) { // WHATEVER CHANGES TO TAKE base into account +int devprop_gpiochip_set_names_base(struct gpio_chip *gc, int base) +{ + return devprop_gpiochip_set_names(gc, base); +} +EXPORT_SYMBOL_GPL(devprop_gpiochip_set_names_base); + static unsigned long *gpiochip_allocate_mask(struct gpio_chip *gc) { unsigned long *p; @@ -684,7 +706,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data, if (gc->names) ret = gpiochip_set_desc_names(gc); else - ret = devprop_gpiochip_set_names(gc); + ret = devprop_gpiochip_set_names(gc, 0); if (ret) goto err_remove_from_list; diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index 4a7e295c3640..ad145ab0794c 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -537,6 +537,8 @@ extern int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data, devm_gpiochip_add_data_with_key(dev, gc, data, NULL, NULL) #endif /* CONFIG_LOCKDEP */ +extern int devprop_gpiochip_set_names_base(struct gpio_chip *gc, int base); + The problem I see with this approach is that 'devprop_gpiochip_set_names' already trusts in gpio_device already created and this happens in 'gpiochip_add_data_with_key'. So doing in this way force "broken drivers" to call this new 'devprop_gpiochip_set_names_base' function after 'devm_gpiochip_add_data' is called so the core code has already set up the friendly names repeated for all gpio chip banks and the approach would be to "overwrite" those in a second pass which sounds more like a hack than a solution. But maybe I am missing something in what you were pointing out here. Best regards, Sergio Paracuellos > > > > Any similar drivers (several gpio_chip per FW node) that want to > > set line names need to do the same thing. > > Thanks for the advices. I'll try to make a bit of time to try to > handle this in the way you are pointing out here. > > Best regards, > Sergio Paracuellos > > > > > Sorry that you ran into this, I hate it when I'm first at hairy stuff > > like this. > > > > Yours, > > Linus Walleij