Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp899211pxk; Sat, 12 Sep 2020 04:14:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxVhW6yo3za5xeW8SJ1V+eRMW2SxRBm/2EEoYl6jwxyPCj/Gw7s6INfS+FxCocHolOJZb9T X-Received: by 2002:aa7:c3d4:: with SMTP id l20mr7826201edr.263.1599909287184; Sat, 12 Sep 2020 04:14:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599909287; cv=none; d=google.com; s=arc-20160816; b=rgHJt7MtZN7y6DIMjPczkBCRIDY97nAHsh/FGCalAClQrUxl441l1a0aR9t2CwkPdp xZDtgIaKOgOf3X7QSdeZKc0yC9HZ/A72a9ruyDaNF3TXkQHjrDkxagLg3erGNtJcinup ACYYz0wLVTPa0ACVCAUehYIYv+fFiTu3aZBOan3ndj9CQlolvUqjh68U/JRvK0LwbG9v VnGIYUGFSFatN1nV8L66QVTheDJ8GlfvO/HtEc+ZfC6IwH3OjZhwWYcX4/0+BiCRMsak ENG10j4BaOg5TgaP2m46FW/oSEAR97Wc+JncPywsBgcqPLUsjHHAY3cdvQf2ok6sdAi1 I6wA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=difJeTP+wV7JyemjeWX3GldS9tsqpKh0tmwoGysikgA=; b=kqHoXO8E1BPm+A5j8buoPFKWcduwH1XBGPztHxfZM7Dfr7qjM8u1AVOmEFrT88avQH KULme0aemK9ANb2ipB984w5mFenryUaGENAhqBSVFQr6XJ2v0tXuD8f9bQILuLEUmDx7 I0vlZ1YVxsUC9bwS9wV2lgZqlVgir4Mi0UWRjuFGHFVS1bx0lSbWu5bW1I9JVs3qbgYo Yg2Ds9yf0EwlSyRjEkkWba2wjijrsgmyb6wJRSZ2OJUWnOY5C7qtpfua70qTAz+KQak8 O08hllSSxNLLmW3tPhPOz6+XqCJfaXL7t2g7SfRyJxYdLa1PzNJQchVSGEC8e97P5gld TgNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PHEEwmZH; 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 u18si3233591edy.380.2020.09.12.04.14.25; Sat, 12 Sep 2020 04:14:47 -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=@linaro.org header.s=google header.b=PHEEwmZH; 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 S1725942AbgILLLX (ORCPT + 99 others); Sat, 12 Sep 2020 07:11:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725994AbgILLLP (ORCPT ); Sat, 12 Sep 2020 07:11:15 -0400 Received: from mail-lj1-x241.google.com (mail-lj1-x241.google.com [IPv6:2a00:1450:4864:20::241]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7A7BC061757 for ; Sat, 12 Sep 2020 04:11:14 -0700 (PDT) Received: by mail-lj1-x241.google.com with SMTP id w3so14601974ljo.5 for ; Sat, 12 Sep 2020 04:11:14 -0700 (PDT) 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; bh=difJeTP+wV7JyemjeWX3GldS9tsqpKh0tmwoGysikgA=; b=PHEEwmZH0GmE/ddgwQsvtRHwatJShCMl8y2YHwI7N4grJggqzM1xLhzEsjLeosNc9t nnouvutJlZBAv+T3DkIn8zydOcB6d4qKPGPX3XgzaQSl8rEckvpDZkgXBUDmqZnYHkrE n7tdrjSjl12tQhG2/cWnj+zy9zSL0o4NoCsJXtQQkakVGRfEBqGMWHRQBiCIWST5c76i E2Bpq8CjKtVcVE+y7QWsVJM7w4toH+r7cbhss3XIeEz0hu2N29G6Lk/+eVDj8YNOZ4+H U2WoMdzqMLsZXwe5XaJat9yNYPEVRKt0sAbhYVGTTC8Z8FjPIcie8ywoxH3t9httEGMA d+/Q== 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=difJeTP+wV7JyemjeWX3GldS9tsqpKh0tmwoGysikgA=; b=j3y4Rpy8hdvYhzwTOlhK94sv8QUfYUamxNPDSRTc5XCF2fOjoBdOkxGOrNfAEhSvlM xn6ysoMxTAi8h5uF40OPzb1KT1/sB5kA9KgeE/46LiTtzQb9xo5QHmz+iUC05RGIKFh/ VdMOW+zKQptIWhyMWM0C+kXVj46ojOmGfsTDUP6DpRt7L7ZF/LvF+VLJOqTmay3MlpWL dey1XP1zfYW2d1Bz/VkeKBJ2qhZXeye91G9P55eoQ8J+hD4zCLZ1PiNMywKj3RQzvYcw 45oD/HtlOWk3uPIAmB+yY3ZkaYaB0vsgj+u4LvDXytm++OKcAZyW/NXQZEhpwt38F1It Oo0w== X-Gm-Message-State: AOAM531awAT9v2WDfEohmhgckyRxr9aKqttw0L9YpXdz8QHzwcKvYVto iVesuYeCOYbzSJq1o9K+5s2QCOdpwyEa2WVNBilwCg== X-Received: by 2002:a05:651c:107b:: with SMTP id y27mr2047736ljm.338.1599909072951; Sat, 12 Sep 2020 04:11:12 -0700 (PDT) MIME-Version: 1.0 References: <20200903133528.8595-1-lars.povlsen@microchip.com> <20200903133528.8595-3-lars.povlsen@microchip.com> In-Reply-To: <20200903133528.8595-3-lars.povlsen@microchip.com> From: Linus Walleij Date: Sat, 12 Sep 2020 13:11:02 +0200 Message-ID: Subject: Re: [PATCH v2 2/3] pinctrl: pinctrl-mchp-sgpio: Add pinctrl driver for Microsemi Serial GPIO To: Lars Povlsen , Kate Stewart Cc: Microchip Linux Driver Support , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" , "open list:GPIO SUBSYSTEM" , Linux ARM , "linux-kernel@vger.kernel.org" , Alexandre Belloni Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 3, 2020 at 3:35 PM Lars Povlsen wrote: > This adds a pinctrl driver for the Microsemi/Microchip Serial GPIO > (SGPIO) device used in various SoC's. > > Signed-off-by: Lars Povlsen (...) > diff --git a/drivers/pinctrl/pinctrl-mchp-sgpio.c b/drivers/pinctrl/pinctrl-mchp-sgpio.c Can we just spell it out pinctrl-microchip-sgpio.c ? The abbreviation seems arbitrary and unnecessary. I do see that this chip is using the pinctrl abstractions (very nicely) and should be under drivers/pinctrl/*. Sadly it doesn't mean the bindings need to be in pinctrl ... unless you plan to add pinctrl bindings later. > +config PINCTRL_MCHP_SGPIO > + bool "Pinctrl driver for Microsemi/Microchip Serial GPIO" > + depends on OF > + depends on HAS_IOMEM > + select GPIOLIB > + select GENERIC_PINCONF > + select GENERIC_PINCTRL_GROUPS > + select GENERIC_PINMUX_FUNCTIONS Nice use of these abstractions! > +// SPDX-License-Identifier: (GPL-2.0 OR MIT) What's up with this OR MIT? I'd like Kate to OK this. > +#define MCHP_SGPIOS_PER_BANK 32 > +#define MCHP_SGPIO_BANK_DEPTH 4 > + > +#define PIN_NAM_SZ (sizeof("SGPIO_D_pXXbY")+1) > + > +enum { > + REG_INPUT_DATA, > + REG_PORT_CONFIG, > + REG_PORT_ENABLE, > + REG_SIO_CONFIG, > + REG_SIO_CLOCK, > + MAXREG > +}; > + > +struct mchp_sgpio_props { Just call it struct microchip_gpio_variant it is easier to read and does not abbreviate randomly, also it is a per-variant set of properties so calling it variant is more to the point. > +struct mchp_sgpio_priv { I would just spell it out struct microchip_sgpio, it is implicit that the struct is private since it is defined in a c file. > +struct mchp_sgpio_port_addr { struct microchip_sgpio_port_addr (Admittedly this is a bit about taste.) > +static inline void sgpio_writel(struct mchp_sgpio_priv *priv, > + u32 val, u32 rno, u32 off) > +{ > + u32 __iomem *reg = &priv->regs[priv->props->regoff[rno] + off]; > + > + writel(val, reg); > +} > + > +static inline void sgpio_clrsetbits(struct mchp_sgpio_priv *priv, > + u32 rno, u32 off, u32 clear, u32 set) > +{ > + u32 __iomem *reg = &priv->regs[priv->props->regoff[rno] + off]; > + u32 val = readl(reg); > + > + val &= ~clear; > + val |= set; > + > + writel(val, reg); > +} This looks like a reimplementation of regmap_update_bits for a bit, have you considered just using regmap? It's pretty simple. > +static int mchp_sgpio_direction_input(struct gpio_chip *gc, unsigned int gpio) > +{ > + struct mchp_sgpio_priv *priv = gpiochip_get_data(gc); > + > + /* Fixed-position function */ > + return sgpio_is_input(priv, gpio) ? 0 : -EINVAL; > +} > + > +static int mchp_sgpio_direction_output(struct gpio_chip *gc, > + unsigned int gpio, int value) > +{ > + struct mchp_sgpio_priv *priv = gpiochip_get_data(gc); > + struct mchp_sgpio_port_addr addr; > + > + sgpio_pin_to_addr(priv, gpio, &addr); > + > + /* Fixed-position function */ > + if (addr.input) > + return -EINVAL; > + > + sgpio_output_set(priv, &addr, value); > + > + return 0; > +} This looks like the right way to handle this! > +static int mchp_sgpio_of_xlate(struct gpio_chip *gc, > + const struct of_phandle_args *gpiospec, > + u32 *flags) > +{ > + struct mchp_sgpio_priv *priv = gpiochip_get_data(gc); > + int pin, base; > + > + if (gpiospec->args[0] > MCHP_SGPIOS_PER_BANK || > + gpiospec->args[1] > priv->bitcount) > + return -EINVAL; > + base = priv->bitcount * gpiospec->args[0]; > + pin = base + gpiospec->args[1]; > + /* Add to 2nd half of output range if output */ > + if (gpiospec->args[2] == PIN_OUTPUT) > + pin += (priv->ngpios / 2); > + > + if (pin > gc->ngpio) > + return -EINVAL; > + > + if (flags) > + *flags = gpiospec->args[3]; > + > + return pin; > +} I don't like this. I would certainly prefer the driver to just use standard GPIO bindings. I do not understand why this is necessary. If for nothing else, there should be a big comment explaining this. The only real problem I have with the driver is this extra flag tagged onto all the GPIOs, this seems unnecessary, and something the hardware driver should already know from the compatible string. Yours, Linus Walleij