Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp1474136pxu; Fri, 16 Oct 2020 12:57:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyGakpjdraeKeseA0/FdrxfjvOTRx6W7xq14EjySINLZcHyBbc6QkrJttVzMyByrzEld8iU X-Received: by 2002:a50:fe98:: with SMTP id d24mr5817679edt.223.1602878236697; Fri, 16 Oct 2020 12:57:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602878236; cv=none; d=google.com; s=arc-20160816; b=nx/a4ZQP86A531VBBLcN8pHOzyzXj9OwtUd4QpsgR/HbP/2yn6IEexVEezN5I2mxak TBurmEQCpBMYSCfkZXd/8SEcwwmPCOGYKtU5ojMi0QgHznkfL/w6zF0Tf9OZKB2cRQDn 8r+0ilHl1x0fwQdLicxTy98Gqg8Qe//P4Zomx4eILtvmHIBjUu1d7hDs+Zl+T0mrMOnb xwBP8bQsmPirLGEeHnuGr2P6wOXsFyBvZCxKaaZzrLz05XCJV9GNuPL1MOJcr1HHIv3u gZFS0k/Ikb8BBYDQkW8YdKRm8SPstsIybUtWzjl51yLXYFmWQD7+JupNwm/x3jq/q5co MZ0g== 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=UCDm/leIjbm6cLrDBLzkAxcbDZIxq5LPj31J47YI3rA=; b=kJAzdcB4/It6FVLQMYgHgMd23gnvyUMp+7y5j6g1QfwHkdmsvsn69XFKRZKqtCGgDD LLLtKQmANW8Tat9efjJ5IiX0EzH2VXrJ7D/RqUacyEIozZoRUYBEVkNkrUBtkFfktYLs EO5tZdMn0zhYb5moI6JHuyYv5e3v52Ggu8boU4I66wpuDON030vDopqYM+SoAhSIvPyZ cOekr8PHXIlHf4IWs2zHXapvDzsIIsTwWO2P0XSxX26wne1fd09uypAW2GXe6xuGyyjy lSibHA7cMkKDgCzAzQZ9R4SR7TbzcmREURfrwvByZXdNB8Afzrd9TO6z7/uPT/HsXD9G grtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=O6LseaGX; 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 p15si2363907ejm.293.2020.10.16.12.56.53; Fri, 16 Oct 2020 12:57:16 -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=O6LseaGX; 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 S2410942AbgJPQ4h (ORCPT + 99 others); Fri, 16 Oct 2020 12:56:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2410935AbgJPQ4h (ORCPT ); Fri, 16 Oct 2020 12:56:37 -0400 Received: from mail-lf1-x144.google.com (mail-lf1-x144.google.com [IPv6:2a00:1450:4864:20::144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD5E7C0613D3 for ; Fri, 16 Oct 2020 09:56:35 -0700 (PDT) Received: by mail-lf1-x144.google.com with SMTP id z2so3832933lfr.1 for ; Fri, 16 Oct 2020 09:56:35 -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=UCDm/leIjbm6cLrDBLzkAxcbDZIxq5LPj31J47YI3rA=; b=O6LseaGXZ01uMmh85FJbb8S6TDmvdQR1JiVmqSS2EeQkzJD00jfbHtD2//OXppDt6g blta4vTt9oEaP8e5p8zLjFuNp/LK/1yVu96vmTIhtP2npu3I7Ubxtdi08mXBNxUA2tJG gwguMYAuaTp+W8YQicdembgZ+5TCQBWd0TYcJzcBaippWvzZ5JCOomp+18GRd5jWQ24g Oi/26AeDGsOHA4+Ml/dFpG1xo+QITxDwNBmDBvGJgB06s5wLBQncR0N8VP5t7PKQke/7 wwSguDm4IKVYt22wyUibb+bQSwjt/F+a1oa7y092pDDmwjt66IssANTGI+6w9CtWkR0I +w7A== 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=UCDm/leIjbm6cLrDBLzkAxcbDZIxq5LPj31J47YI3rA=; b=FLMlrVm4hW4JGgjmxR6JsnuFh6NryaA12mhEEGkF7OXQp0LpcId4S06/GlmJLkVlL/ GqeDatllSlqxH2gDku5wbI4mmX1OCrkBUgnQvosLEoklg9ihwEzIHJdJNwdhkH3Rn9s/ EKeouY1qLDT8EWBYX3RhlrM7WMANg5vfkxZsCLReq7KF0wpsVEh1qTdJPKpQEA+4/DM8 ytaSDZ0QjR3Ley7PQQVJM92JjA8Py8oz096vfHWU9e+706AKglDBnNLmAxVJwOC/eWTm Tf7zZNf19Np8d30avEzfTkjnj9YEWpXpKuxCD+YVpl29k0sMNnXscuBe2RvjtMly+3NO 9wJQ== X-Gm-Message-State: AOAM5305eEM9LROlHPiqNo2u7NSr4AyNsNYIRdOv0TGl6nYoH0Se/tSD aYX+uHKUNDoMErt6UrkBk+zEHoTu0PPqbo5YsZb+zA== X-Received: by 2002:a19:824f:: with SMTP id e76mr1615966lfd.572.1602867394059; Fri, 16 Oct 2020 09:56:34 -0700 (PDT) MIME-Version: 1.0 References: <20201011024831.3868571-1-daniel@0x0f.com> <20201011024831.3868571-4-daniel@0x0f.com> In-Reply-To: <20201011024831.3868571-4-daniel@0x0f.com> From: Linus Walleij Date: Fri, 16 Oct 2020 18:56:23 +0200 Message-ID: Subject: Re: [PATCH 3/5] gpio: msc313: MStar MSC313 GPIO driver To: Daniel Palmer Cc: "open list:GPIO SUBSYSTEM" , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" , Linux ARM , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Daniel, thanks for your patch! Some comments below, we need some work but keep at it. On Sun, Oct 11, 2020 at 4:48 AM Daniel Palmer wrote: > This adds a driver that supports the GPIO block found in > MStar/SigmaStar ARMv7 SoCs. > > The controller seems to support 128 lines but where they > are wired up differs between chips and no currently known > chip uses anywhere near 128 lines so there needs to be some > per-chip data to collect together what lines actually have > physical pins attached and map the right names to them. > > The core peripherals seem to use the same lines on the > currently known chips but the lines used for the sensor > interface, lcd controller etc pins seem to be totally > different between the infinity and mercury chips > > The code tries to collect all of the re-usable names, > offsets etc together so that it's easy to build the extra > per-chip data for other chips in the future. > > So far this only supports the MSC313 and MSC313E chips. > > Support for the SSC8336N (mercury5) is trivial to add once > all of the lines have been mapped out. > > Signed-off-by: Daniel Palmer (...) > +config GPIO_MSC313 > + bool "MStar MSC313 GPIO support" > + default y if ARCH_MSTARV7 > + depends on ARCH_MSTARV7 > + select GPIO_GENERIC Selecting GPIO_GENERIC, that is good. But you're not using it, because you can't. This chip does not have the bits lined up nicely in one register, instead there seems to be something like one register per line, right? So skip GPIO_GENERIC. > +#define MSC313_GPIO_IN BIT(0) > +#define MSC313_GPIO_OUT BIT(4) > +#define MSC313_GPIO_OEN BIT(5) > + > +#define MSC313_GPIO_BITSTOSAVE (MSC313_GPIO_OUT | MSC313_GPIO_OEN) Some comment here telling us why these need saving and not others. > +#define FUART_NAMES \ > + MSC313_PINNAME_FUART_RX, \ > + MSC313_PINNAME_FUART_TX, \ > + MSC313_PINNAME_FUART_CTS, \ > + MSC313_PINNAME_FUART_RTS > + > +#define OFF_FUART_RX 0x50 > +#define OFF_FUART_TX 0x54 > +#define OFF_FUART_CTS 0x58 > +#define OFF_FUART_RTS 0x5c > + > +#define FUART_OFFSETS \ > + OFF_FUART_RX, \ > + OFF_FUART_TX, \ > + OFF_FUART_CTS, \ > + OFF_FUART_RTS This looks a bit strange. The GPIO driver should not really have to know about any other use cases for pins than GPIO. But I guess it is intuitive for the driver. > +#define SD_NAMES \ > + MSC313_PINNAME_SD_CLK, \ > + MSC313_PINNAME_SD_CMD, \ > + MSC313_PINNAME_SD_D0, \ > + MSC313_PINNAME_SD_D1, \ > + MSC313_PINNAME_SD_D2, \ > + MSC313_PINNAME_SD_D3 > + > +#define OFF_SD_CLK 0x140 > +#define OFF_SD_CMD 0x144 > +#define OFF_SD_D0 0x148 > +#define OFF_SD_D1 0x14cchild_to_parent_hwirq > +#define OFF_SD_D2 0x150 > +#define OFF_SD_D3 0x154 > + > +#define SD_OFFSETS \ > + OFF_SD_CLK, \ > + OFF_SD_CMD, \ > + OFF_SD_D0, \ > + OFF_SD_D1, \ > + OFF_SD_D2, \ > + OFF_SD_D3 > + > +#define I2C1_NAMES \ > + MSC313_PINNAME_I2C1_SCL, \ > + MSC313_PINNAME_I2C1_SCA > + > +#define OFF_I2C1_SCL 0x188 > +#define OFF_I2C1_SCA 0x18c > + > +#define I2C1_OFFSETS \ > + OFF_I2C1_SCL, \ > + OFF_I2C1_SCA > + > +#define SPI0_NAMES \ > + MSC313_PINNAME_SPI0_CZ, \ > + MSC313_PINNAME_SPI0_CK, \ > + MSC313_PINNAME_SPI0_DI, \ > + MSC313_PINNAME_SPI0_DO > + > +#define OFF_SPI0_CZ 0x1c0 > +#define OFF_SPI0_CK 0x1c4 > +#define OFF_SPI0_DI 0x1c8 > +#define OFF_SPI0_DO 0x1cc > + > +#define SPI0_OFFSETS \ > + OFF_SPI0_CZ, \ > + OFF_SPI0_CK, \ > + OFF_SPI0_DI, \ > + OFF_SPI0_DO Same with all these. I suppose it is the offsets of stuff that would be there unless we were using it for GPIO. > +static int msc313_gpio_to_irq(struct gpio_chip *chip, unsigned int offset) > +{ > + struct msc313_gpio *gpio = gpiochip_get_data(chip); > +> + > + return gpio->irqs[offset]; > +} Please do not use custom IRQ handling like this. As there seems to be one IRQ per line, look into using select GPIOLIB_IRQCHIP select IRQ_DOMAIN_HIERARCHY See for example in gpio-ixp4xx.c how we deal with hiearchical GPIO IRQs. > + gpiochip->to_irq = msc313_gpio_to_irq; > + gpiochip->base = -1; > + gpiochip->ngpio = gpio->gpio_data->num; > + gpiochip->names = gpio->gpio_data->names; > + > + for (i = 0; i < gpiochip->ngpio; i++) > + gpio->irqs[i] = of_irq_get_byname(pdev->dev.of_node, gpio->gpio_data->names[i]); Use hierarchical generic GPIO IRQs for these. Assign ->fwnode, ->parent_domain, ->child_to_parent_hwirq, and probably also ->handler on the struct gpio_irq_chip *. Skip assigning gpiochip->to_irq, the generic code will handle that. Again see gpio-ixp4xx.c for an example. Yours, Linus Walleij