Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2558087pxv; Sat, 3 Jul 2021 12:40:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwLoeg87TM8uFpiiv9bY6wYm7cZwzyu6kgXYN+6cNDTxHpf5TyQRQr+jHtwKNn1ur5pYuhK X-Received: by 2002:a92:364f:: with SMTP id d15mr4548003ilf.26.1625341222666; Sat, 03 Jul 2021 12:40:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625341222; cv=none; d=google.com; s=arc-20160816; b=X3dnScL0muAHqtOp3zd7umfcIA8Btt3N6usjNxmNVHdwCiLhVH0k89Hr71rLOd6S2l vVXhxhbY/rOOObm9Shq+KjL2LDHSyhB4Ta4VsND2HqsQziBjwbqBN5NnSsGXPqTZMUfd VeSM0ZnTjh/+1eScHSi0hww8d2rjWW3USPtDya+2NtgJywui3TNSJqKNjSYGGjPhyCYu 4O9RZn7O6e6ZVgufhZh6glnhWkvYZ8TiMY5O37qOEIubZ3gFUShOukNbgBhwrZHUeX5l D1ajKF9PnuB7UyyDvDsjsVPCxEzex0AW7JcPg4o57Lm/YyJZBV+4/9xg9ap5+OWEvg5/ HY1A== 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=QJwXPHklFmm/M0F7FosREaVzctnCkZAKK3BhxKroh4E=; b=TdLvXP3mOFQV8lBRR9c4N4Ds2pj8Oaya5Z3DwkKphe4JM3vXTCYjrIqGtOpRUVfRen d6Dx2GcKJWVmDZqpjvgMqiVy6MA3gaMAL6/ohNhuSgNhjQDwPRIBaFhM+9kee0e4OhHz YSg0TOUFHD/MXSsmwS0azyAC9ZHSPfS0gk06O+KknM+fokA+6aVHKFu9bukEPHVn+dBu WGdmLogr9+R6iGPkMdgAiJSw4ZP8OPx22KYrlZRmDwC84eb4dWbnvUOTIHMv8W7MBwQn U+U/6NVv1tAgqyDu048Xf+1+822GSVzOwaXKLjKEkDU61YZO5C3VxwNXG8VtL+MJ7NFV aX8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Ik4SjVjT; 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 f16si4656912iol.39.2021.07.03.12.40.10; Sat, 03 Jul 2021 12:40:22 -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=Ik4SjVjT; 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 S229787AbhGCTjX (ORCPT + 99 others); Sat, 3 Jul 2021 15:39:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229473AbhGCTjX (ORCPT ); Sat, 3 Jul 2021 15:39:23 -0400 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A625BC061762; Sat, 3 Jul 2021 12:36:49 -0700 (PDT) Received: by mail-pf1-x432.google.com with SMTP id j24so12614516pfi.12; Sat, 03 Jul 2021 12:36:49 -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=QJwXPHklFmm/M0F7FosREaVzctnCkZAKK3BhxKroh4E=; b=Ik4SjVjT394OT4b0ZiXqiYoiV8wAadFNh1nKnvy0xsoD/nUbvh1gfg9zSVqvngKlji tly/OjFIDTuBNEH8U3Nxdi2WP6YTQ9IKYuiaYy7dMDArXavN/dkrHoKvQ3rM6XhDM9DF HfviLJAvZI8CuMVDdzIOubf+UZ5BYR+eGJLs0e1esPKtLAon98tvQSW9Vgffo1lZsVX3 Q2XUAqhhiE0w0ruTwF6CI2nZhACj3LbcO/ExZH1a56JD1Bz+SL+Y/81gNx5LFoCSQ5/n ipEmiBSWDXfPKkc5yunEEWhPo/Kk46q+x975bY1L9EckFeYJeVk4OD7Xy9vHZZiQJcBl Ia8g== 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=QJwXPHklFmm/M0F7FosREaVzctnCkZAKK3BhxKroh4E=; b=Sh1EVy42tSS+AfydzlTimCGIi0Czvj3tn0nU+umxI0JlrQ1mwXHB8zI2hsK0b4IEDX KbFel4P8i1UeOvh7HQ/J53mLELfjgQxnbezEZUPeDGPcZMtQ7RuR2tyEy3SI8FK5np27 6mHX4wiLhLihKg/+Wf4+vIqaF9wlmEC4IlNaP9ZGRR0lMp8b1LOLiDQ6sJd6HttHGi6l PPBKoQWAG8aoZiOgM6gWRreVWBdJzJ5APih9dFHh0m0+BDwN7BDSN0/Wn3oOKdLJZDer 8uKura4myu//ll30dncTfb5Of7GDKqUFRrq6UgXDZkks6rrm3corm96Yrc15s+6WS5ke a9Rw== X-Gm-Message-State: AOAM533iJuomXYTDkiL1FlKuUX99GeMycIWLxgAucFsRpNYNkPju8EOE MVZAjlhupF1ShAa3jQ2MIY/+Dm1YfSmKNyedBo8= X-Received: by 2002:a63:d014:: with SMTP id z20mr6708365pgf.203.1625341009085; Sat, 03 Jul 2021 12:36:49 -0700 (PDT) MIME-Version: 1.0 References: <20210626161819.30508-1-sergio.paracuellos@gmail.com> In-Reply-To: From: Andy Shevchenko Date: Sat, 3 Jul 2021 22:36:12 +0300 Message-ID: Subject: Re: [PATCH v2] gpio: mt7621: support gpio-line-names property To: Sergio Paracuellos Cc: Linus Walleij , "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 On Sat, Jul 3, 2021 at 3:51 PM Sergio Paracuellos wrote: > On Sat, Jul 3, 2021 at 2:05 PM Sergio Paracuellos > wrote: > > On Sat, Jul 3, 2021 at 1:32 PM Andy Shevchenko > > wrote: > > > On Sat, Jul 3, 2021 at 2:06 PM Sergio Paracuellos > > > wrote: > > > > On Fri, Jul 2, 2021 at 1:30 PM Sergio Paracuellos > > > > wrote: > > > > > > ... > > > > > > > - ret = devprop_gpiochip_set_names(gc); > > > > + ret = devprop_gpiochip_set_names(gc, 0); > > > > > > I had been expecting that this parameter would be in the field of the gpiochip. > > > > > > ... > > > > If doing it in that way is preferred, I have no problem at all. But in > > that case I think there is no need for a new > > 'devprop_gpiochip_set_names_base' and we can assume for all drivers to > > be zero and if is set taking it into account directly in > > devprop_gpiochip_set_names function? Is this what you mean by having > > this field added there?? The below is closer to what I meant, yes. I have not much time to look into the details, but I don't have objections about what you suggested below. Additional comments there as well. > How about something like this? > > diff --git a/drivers/gpio/gpio-mt7621.c b/drivers/gpio/gpio-mt7621.c > index 82fb20dca53a..5854a9343491 100644 > --- a/drivers/gpio/gpio-mt7621.c > +++ b/drivers/gpio/gpio-mt7621.c > @@ -241,6 +241,7 @@ mediatek_gpio_bank_probe(struct device *dev, > if (!rg->chip.label) > return -ENOMEM; > > + rg->chip.offset = bank * MTK_BANK_WIDTH; > rg->irq_chip.name = dev_name(dev); > rg->irq_chip.parent_device = dev; > rg->irq_chip.irq_unmask = mediatek_gpio_irq_unmask; Obviously it should be a separate patch :-) > diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c > index 6e3c4d7a7d14..0587f46b7c22 100644 > --- a/drivers/gpio/gpiolib.c > +++ b/drivers/gpio/gpiolib.c > @@ -380,10 +380,10 @@ static int devprop_gpiochip_set_names(struct > gpio_chip *chip) > return 0; > > count = device_property_string_array_count(dev, "gpio-line-names"); > - if (count < 0) > + if (count < 0 || count <= chip->offset) Please, split it into two conditionals and add a comment to the second one. > return 0; > > - if (count > gdev->ngpio) { > + if (count > gdev->ngpio && chip->offset == 0) { > dev_warn(&gdev->dev, "gpio-line-names is length %d but > should be at most length %d", > count, gdev->ngpio); > count = gdev->ngpio; > @@ -401,8 +401,9 @@ static int devprop_gpiochip_set_names(struct > gpio_chip *chip) > return ret; > } > > + count = (chip->offset >= count) ? (chip->offset - count) : count; Too many parentheses. > for (i = 0; i < count; i++) > - gdev->descs[i].name = names[i]; > + gdev->descs[i].name = names[chip->offset + i]; > > kfree(names); > > diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h > index 4a7e295c3640..39e0786586f6 100644 > --- a/include/linux/gpio/driver.h > +++ b/include/linux/gpio/driver.h > @@ -312,6 +312,9 @@ struct gpio_irq_chip { > * get rid of the static GPIO number space in the long run. > * @ngpio: the number of GPIOs handled by this controller; the last GPIO > * handled is (base + ngpio - 1). > + * @offset: when multiple gpio chips belong to the same device this > + * can be used as offset within the device so friendly names can > + * be properly assigned. > * @names: if set, must be an array of strings to use as alternative > * names for the GPIOs in this chip. Any entry in the array > * may be NULL if there is no alias for the GPIO, however the > @@ -398,6 +401,7 @@ struct gpio_chip { > > int base; > u16 ngpio; > + int offset; u16 (as ngpio has that type) > const char *const *names; > bool can_sleep; > > > Does this sound reasonable? > > > > 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. > > > > > > Would the above work? -- With Best Regards, Andy Shevchenko