Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp959698pxb; Wed, 3 Mar 2021 22:34:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJyKfkIPcdUJK24tuOkezEuK6mO2p6f98P0MEX0bO4dZDDz5MtTlSAGBq9eLvAt3UAbyILDD X-Received: by 2002:a05:6402:35d0:: with SMTP id z16mr2665924edc.151.1614839666690; Wed, 03 Mar 2021 22:34:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614839666; cv=none; d=google.com; s=arc-20160816; b=aClc8IbgGcuS3ZOv6wdO/+dWGHjmaJuieFuYOumBMNLO+UPqWylVdf6eJRRv1T91/7 Y04cQ4m2r7bHFEVL8Ekdxx7/KYkLBmFfzL9bBjuVaKEx1kS6+9ZWXGs+KoEvle4/qG30 cxwbjg1W2A2/g0F8NM3WO5EnCMLJzTWpRvkbhGbHvnSjjrIhUHu3934L7RxGO2s0Hxik nL6C2AC6ZBe20SvP8HinCtvo+NdV+m//OVrpf/8M7GoqrP4F1iW5cLgeXn2lTevBrO5m GxzCTNR15qaenDe7rP7LRcMxm1dMnpXVtIcjZ1JfYHnkEOGRFxhZM2kDFAhownVuRhJg A7HQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=cEfoHf83s/nppCpslFBm2JaQs5ooxd+wCNySTYqRLrg=; b=eZe+i9paX/E4SdAiZgu5RH9aE9cZ704+ZOiLQIzAG9ggYEO0yCnV7dxrI7Y4IMjXRO pYXy42cJT8aJeGT6vX74hRwfOz+C9h7tlsuEIEwcRlq7fq3xux2x4fQMTTxNRbiAEbNR D1tI7UM1S+K3sqGHN8Qrc/mWErrygNoCYVNp8pHS+T4Av8TJTJE3ZlzSTc6ls6LGkgId hYThoT6DCx85/Z3uAeQe+CSQJ/P7qh3Ihkz0ABWk3tiA+nl/nHezXoKoFGf3Pizdb8Fj n2ViTyF/D5acsx3ZZrTBQFlDThI9FwcEEh92hSnR3/I+hkyGzUQ6wnj1K9oYmT7Sr7fp rTYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZJvvs7Yp; 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=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f8si15904111ejz.220.2021.03.03.22.34.04; Wed, 03 Mar 2021 22:34:26 -0800 (PST) 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=@linaro.org header.s=google header.b=ZJvvs7Yp; 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=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1580516AbhCBSEA (ORCPT + 99 others); Tue, 2 Mar 2021 13:04:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1578598AbhCBPZZ (ORCPT ); Tue, 2 Mar 2021 10:25:25 -0500 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9E16C0617AB for ; Tue, 2 Mar 2021 07:20:47 -0800 (PST) Received: by mail-lf1-x12d.google.com with SMTP id q25so11613580lfc.8 for ; Tue, 02 Mar 2021 07:20:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=cEfoHf83s/nppCpslFBm2JaQs5ooxd+wCNySTYqRLrg=; b=ZJvvs7YpZ/v82uircBUdvlFwywAJ6JQXf6yaNLeLEx1ezcq4xouLe1KiOdpmq2WO+K yQi5MUw3HpKmdjGCuYgV1N+z8daa6FmEwQiZyZk4fXbq1ygHmp71fIxcN6kPpnydM5PZ 2Y8RQPe6RexZGPlKsqkbrFT+y5Ky68ZqFnnU75jnh8IJyCUtuOuVUhHaFsb3GbjnUHye TAmTMJ3NcUGrf1X359md9oPTRDV24QXbPhYpLP/nx0IoklMtgExYj1Il7aBxS3NQDver 5Fyp0QZijh5mr6qw8zQvVBOpczZzL4ETPy6ZqrGQTNaOUCWX8VnIpI2JrAgnh42rBLxV 0wPQ== 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:content-transfer-encoding; bh=cEfoHf83s/nppCpslFBm2JaQs5ooxd+wCNySTYqRLrg=; b=LpDJBu0GAR61M/JjIJiRZJ8WLPYDdYlhxV46LtZEu4KALCUJcydvkMFvVJftIfZ8P5 XG8Q0AadC2SBujhboVFs20uF2ZhOoL+riaFB1kHzlV7x4XtdHoDZSzCcNcR+sGTCmDEC vo5isz6CXjXPzm+6jfEn2j6DGhZUlnmSXaQLuCrlPcspjmLdxUGHrjTHI9YYVzcrpoaZ 06NV6YAlKbxjEm6WrZIlZ8CJDFagEF3+IlMy9pBNMP0m5jB42JiY95H6S8uNw3ZubrrD 4zJce0GT/e+J3bWqHItjRD65mQgHXIkWuA5P8jJQVbNR7jwclZJvDhy11RhNaCRRVXqM T5Bw== X-Gm-Message-State: AOAM533MVx1vKBvkK2GaqgDgof/sPtw4v6d8X/adJbnNjJvHn9q03FRc JL0YMd8p9LfMcQdHbVvAKMOZ1+94ugv2xoomNvf5YA== X-Received: by 2002:ac2:5d21:: with SMTP id i1mr12066700lfb.649.1614698446288; Tue, 02 Mar 2021 07:20:46 -0800 (PST) MIME-Version: 1.0 References: <20210225164216.21124-1-noltari@gmail.com> <20210225164216.21124-3-noltari@gmail.com> In-Reply-To: <20210225164216.21124-3-noltari@gmail.com> From: Linus Walleij Date: Tue, 2 Mar 2021 16:20:35 +0100 Message-ID: Subject: Re: [PATCH 02/12] pinctrl: add a pincontrol driver for BCM6328 To: =?UTF-8?B?w4FsdmFybyBGZXJuw6FuZGV6IFJvamFz?= Cc: Florian Fainelli , Rob Herring , Jonas Gorski , Necip Fazil Yildiran , "open list:GPIO SUBSYSTEM" , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi =C3=81lvaro, thanks for your patch! On Thu, Feb 25, 2021 at 5:42 PM =C3=81lvaro Fern=C3=A1ndez Rojas wrote: > Add a pincontrol driver for BCM6328. BCM628 supports muxing 32 pins as > GPIOs, as LEDs for the integrated LED controller, or various other > functions. Its pincontrol mux registers also control other aspects, like > switching the second USB port between host and device mode. > > Signed-off-by: =C3=81lvaro Fern=C3=A1ndez Rojas > Signed-off-by: Jonas Gorski Thanks for working on this. This SoC definitely need to come upstream. I think this driver can be simplified a bit and reuse some core infrastruct= ure to make it more maintainable. It might be a bit of challenge but definitely worth it! > +config PINCTRL_BCM6328 > + bool "Broadcom BCM6328 GPIO driver" > + depends on OF_GPIO && (BMIPS_GENERIC || COMPILE_TEST) > + select PINMUX > + select PINCONF > + select GENERIC_PINCONF > + select MFD_SYSCON > + default BMIPS_GENERIC > + help > + Say Y here to enable the Broadcom BCM6328 GPIO driver. I suggest select GPIO_REGMAP select GPIOLIB_IRQCHIP select IRQ_DOMAIN_HIERARCHY see below. (...) > +#include Just maybe, if you only use BIT() and GENMASK(). > +#include > +#include Do not include these, just: #include > +#define BCM6328_DIROUT_REG 0x04 > +#define BCM6328_DATA_REG 0x0c > +#define BCM6328_MODE_REG 0x18 This looks very much like it could use GPIO_REGMAP. Can you look at: drivers/gpio/gpio-regmap.c drivers/gpio/gpio-sl28cpld.c And see if you can do what that driver is doing and reuse this core infrastructure? > +static inline unsigned int bcm6328_bank_pin(unsigned int pin) > +{ > + return pin % PINS_PER_BANK; > +} I am generally reluctant about registering several banks/instances of the GPIO if it is possible to just use more devices in the device tree, like one for each instance. > +static inline unsigned int bcm6328_reg_off(unsigned int reg, unsigned in= t pin) > +{ > + return reg - (pin / PINS_PER_BANK) * BANK_SIZE; > +} Because it leads to this kind of weirdness to split out the devices from the main device in practice. > +static int bcm6328_gpio_direction_input(struct gpio_chip *chip, > + unsigned int pin) > +{ (...) > + /* > + * Check with the pinctrl driver whether this pin is usable as > + * an input GPIO > + */ > + ret =3D pinctrl_gpio_direction_input(chip->base + pin); > + if (ret) > + return ret; This is very nice. > +static int bcm6328_gpio_to_irq(struct gpio_chip *chip, unsigned gpio) > +{ > + char irq_name[7]; > + > + sprintf(irq_name, "gpio%d", gpio); > + > + return of_irq_get_byname(chip->of_node, irq_name); > +} This is a clear indication that we are dealing with a hierarchical irqchip. My assumption is that you have one IRQ per GPIO line, so each GPIO has a dedicated IRQ on the interrupt controller. Correct? This means: - Do not add all the interrupts into the device tree by name. - In Kconfig select GPIOLIB_IRQCHIP, select IRQ_DOMAIN_HIERARCHY - Populate a simple struct gpio_irq_chip, if no local registers need updating on interrupts, just pass interrupts through .irq_mask =3D irq_chip_mask_parent, .irq_unmask =3D irq_chip_unmask_parent, etc. - Implement bcm6328_gpio_child_to_parent_hwirq() for this chip with hardcoded mappings between the hardware GPIO and interrupt lines, using the parent interrupt controller hierarchically. This mapping is determined from the compatible-string, and part of the property of how the GPIO block is integrated with the SoC. If need be to tell different chips apart, more precise compatible strings are needed. - Examples: drivers/gpio/gpio-ixp4xx.c drivers/gpio/gpio-sifive.c If you do this you will notice the core is more helpful to cut down on the code. Yours, Linus Walleij