Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp670573rwe; Thu, 25 Aug 2022 07:18:11 -0700 (PDT) X-Google-Smtp-Source: AA6agR7srv1t6bkq4qHK9uLxzlMRXJYZVeP0HRs9k0mzdTYEPsC6rp7NhgQKfEjts44MlJ+j7QAb X-Received: by 2002:a17:907:97cb:b0:731:6d1:13fa with SMTP id js11-20020a17090797cb00b0073106d113famr2558817ejc.375.1661437091386; Thu, 25 Aug 2022 07:18:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661437091; cv=none; d=google.com; s=arc-20160816; b=celeXfch5F8FwpZmHTkMQlXSDufJIMlDWy8ZEj7gP7CdGbb9GsUZlXQmTY+Q0K/jQP 5FeO1OTMb5a4VHWivP8eLCobpekkrm/xRB797WP08GkhKM7+RnYqq/3ItuBzRP8ZQ79e SxLAJv7fdhec7XKNNq/fmvmpOVwMFN6HS19xas74pjTRQVHOzhKq2rUc/rZuh1OWfRHy /SNmJUAlHeLnvGv3I6Nk8cvriuraHW/ERAi5lXBd1xI67vhwomyM2fzjAiB4WBjHesVp VAjk2SVTtJMCT4Fo9JgY1s8akv2CMSBu+qfKk6DHG9/lxvG4UI0zpxJn++TmYdy7tndM o6sQ== 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=dlm2famS8O5FqtaX9yCeRxscNO/EP4O+QRIK7hJkB2s=; b=AA3rlzgdq0jF9P3MV1F+Fp2aQ8Ua59jxaDy/xa2Sswz80w+kUG66sIVS+Jjr6WO3ra AbV5OEaMs1vZ1NS/9iotTHbwGUgcwtASTDdV/pMl3h1xB3qfXRXPMHDrDhFEoWrg8n7/ hdzpHV7AE8HejSNdhwLTkMsXixzeq8BFTlpzxQhk1fh1jvCHMVeucj6QV5mZ180Sriq3 lNEox9QcTHa2olCK5BF7Gi9yTRSSxjhOGLKUdAcexHPE8/X+MEGNvWnM3T/q3Dz6u0jK Etfavmq+ya0PyqCher7vOZWcxcoEEkkZ9bFmSMxiu6AgW816t5lP6ZAomB+1xYvQ5Ncd Gulg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hTFwrfce; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id di16-20020a170906731000b00732f74ed931si4581740ejc.793.2022.08.25.07.17.44; Thu, 25 Aug 2022 07:18:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hTFwrfce; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241661AbiHYNhR (ORCPT + 99 others); Thu, 25 Aug 2022 09:37:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241823AbiHYNhN (ORCPT ); Thu, 25 Aug 2022 09:37:13 -0400 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85E3DB275C for ; Thu, 25 Aug 2022 06:37:11 -0700 (PDT) Received: by mail-ej1-x62b.google.com with SMTP id u15so30922824ejt.6 for ; Thu, 25 Aug 2022 06:37:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=dlm2famS8O5FqtaX9yCeRxscNO/EP4O+QRIK7hJkB2s=; b=hTFwrfcekpPlwsKPKUDudDRoTVjcNhRXmh1WtgUK60PKUyBomYKetqdJodmXMyLiB0 dkyuV7K5eZsOuK963+nUWPUe7KCyXkJZONDwPCrivKsZT9PJDubk1TQqXKdDF6asiLn/ tKuc0x8bOBlRQRLCT3cu6Yw1wdke2dVeoukHTnpDK1KgGBp18+wj0ZvHkmzlWDm5xfBe 7fzo7likfMjdV90vpKunxdhJef3uuXRWyf+Ve8lXxcg9SOUlYCESKPN/0H+qXAmkBCTn HkRXi4lc+hQbTfmsIQLyBi6byW3t6UFkkCoPxj3LYOq5bF2Nj0Yq+8g0crj8aP/TqJK5 Uo7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=dlm2famS8O5FqtaX9yCeRxscNO/EP4O+QRIK7hJkB2s=; b=z/iwng9LAcNs31fMMvIPyE5GYenZoMGnA2zY0dbOJfrPdRqWy7Ys1uUheUTR4Lp0K4 S6R7G6OsaYuGdP7I2sIPv/1Cn3thqhvhCt5vbugkrFGYH8JTvT00gvieFBudwqISjpPs bMelFQIMEHSgQeC0ivvVtlmEwJdAUWXweb493lNphvQ4Qvi2dkmXJrsLX1I7k0NMs1+Y Z5krQ4wZ9SMoNmlaLqyfi2NAnhjIh//PXuI3FL8OiI+azhubI3ztAj82uxvu6m1olpbZ 5HHuWdJB0Jq7MlVTASzhJM3yXMqV2opN5JWhVtFRffufIg76GPczyIHd4CYzM+ih5TOh nYCA== X-Gm-Message-State: ACgBeo00XlYznbOIZlFH3ZfNzZkEOJ3NwCut2Gj/ye0yW3Ji3Qv+IrtK mVnijBWB33smXQrFvdqr02V59BBeso3fmY0+LngzNg== X-Received: by 2002:a17:906:9b86:b0:73d:72cf:72af with SMTP id dd6-20020a1709069b8600b0073d72cf72afmr2609925ejc.440.1661434630115; Thu, 25 Aug 2022 06:37:10 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Linus Walleij Date: Thu, 25 Aug 2022 15:36:58 +0200 Message-ID: Subject: Re: [PATCH] gpio: Allow user to customise maximum number of GPIOs To: Arnd Bergmann Cc: Alexandre Courbot , Alexandre Courbot , Bartosz Golaszewski , Christophe Leroy , Jonathan Corbet , Russell King , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , "H. Peter Anvin" , "open list:GPIO SUBSYSTEM" , "open list:DOCUMENTATION" , open list , "moderated list:ARM PORT" , "open list:GENERIC INCLUDE/ASM HEADER FILES" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 18, 2022 at 2:46 PM Arnd Bergmann wrote: > On Thu, Aug 18, 2022 at 2:25 PM Linus Walleij wrote: > > git grep 'base = -1' yields these suspects: > > > > arch/arm/common/sa1111.c: sachip->gc.base = -1; > > arch/arm/common/scoop.c: devptr->gpio.base = -1; > > arch/powerpc/platforms/52xx/mpc52xx_gpt.c: gpt->gc.base = -1; > > arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c: gc->base = -1; > > > > That's all! We could just calculate these to 512-ngpios and > > hardcode that instead. > > How do the consumers find the numbers for these four? For SA1111 the chip gets named "sa1111" and some consumers actually use proper machine descriptions, maybe all? arch/arm/mach-sa1100/jornada720.c: GPIO_LOOKUP("sa1111", 0, "s0-power", GPIO_ACTIVE_HIGH), arch/arm/mach-sa1100/jornada720.c: GPIO_LOOKUP("sa1111", 1, "s1-power", GPIO_ACTIVE_HIGH), (...) For Scoop it is conditionally overridden in the code. I guess always overridden. For powerpc these seem to be using (old but working) device tree lookups, so should not be an issue. Sadly I'm not 100% sure that there are no random hard-coded GPIO numbers referring to whatever the framework gave them at the time the code was written :( Another reason the base is assigned from above (usually from 512 and downward) is that the primary SoC GPIO usually want to be at base 0 and there is no guarantee that it will get probed first. So hard-coded GPIO bases go from 0 -> n and dynamically allocateed GPIO bases from n <- 512. Then we hope they don't meet and overlap in the middle... > > and in that case it is better to delete the use of this function > > altogether since it can not fail. > > S32_MAX might be a better upper bound. That allows to > just have no number assigned to a gpio chip. Any driver > code calling desc_to_gpio() could then get back -1 > or a negative error code. > > Making the ones that are invalid today valid sounds like > a step backwards to me if the goal is to stop using > gpio numbers and most consumers no longer need them. OK I get it... Now: who wants to write this patch? :) Christophe? Will you take a stab at it? Yours, Linus Walleij