Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp207511imm; Thu, 2 Aug 2018 17:10:26 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcUK2ZrN6opzLPUvKw2CaFlK0O3mlaagFY3p/pSaTNOPv9yzVOdccWb1ZVm2KMHM1PGWV+V X-Received: by 2002:a17:902:14cb:: with SMTP id y11-v6mr1342451plg.317.1533255025985; Thu, 02 Aug 2018 17:10:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533255025; cv=none; d=google.com; s=arc-20160816; b=daZYBrTOO6sOe6Rr+tCEQp0yIeB5KsQ7ZpEJurQqjmmztLFtq62vXmsmo60BvBUcTt A7eDHOno+n+DPGINUWt4A/bPHAeLfeVAm6J6FswRaf5wApoKoxdVwILVxwItsWbZtVaQ NCYTFY6xVZQ1f43Ev6s4OEVR5GAvpro0kYc+fLSp/ajXjeTW3Cd5nQSSM1Ux36Ulfq0m BdST25nsc2cAo0xjD9hfkhGIgfK2jdjL+osN4KciwKPgnssDyd+nDgq962bOawDX571P wdDNcDupKQ+FflJgHnYGjl2b0UxRR73Dw3JyemlU9RiKp4vCuDMHURfy1srRbgCw7V0u eGbQ== 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 :arc-authentication-results; bh=whepv9ceqpKeQSobXWBzs/Amu/cZ+5W6duyabfxJS5I=; b=Kpe0xMXU4zoCMDpdqljraduCzqU8mLgOinCAPqI+rRUz2dgIvuIDAhLZ2sPQjXmjPZ JdQq1usQSMy6HGProvIxv54HgigWJyyEvC5ImlszJtjsYXXj0yH0wDw/VAOR4Z8a4DV3 0kRuafxkiILUJPVcKlmI8M7AQ1RFpl5F2V0r3efLawPuFZpaWxKFntNunZmzoEPGdmBF 2TpDOU/BHf7NR0ZgbxOxJZRwEgwQUkCA+K77+5llK8RktrrAUtOQEzcIXdqnB76HzJYU 9hsUusFR7lmZmITn9NGx/Xc0yPXNFvBaqibSjMMYKbvKzgaAvX5K0sXwHEc4R3V66wVO bW9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aLXVahqn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id u21-v6si3398732pgn.86.2018.08.02.17.10.11; Thu, 02 Aug 2018 17:10:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aLXVahqn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1732001AbeHCCCt (ORCPT + 99 others); Thu, 2 Aug 2018 22:02:49 -0400 Received: from mail-it0-f65.google.com ([209.85.214.65]:54594 "EHLO mail-it0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730951AbeHCCCt (ORCPT ); Thu, 2 Aug 2018 22:02:49 -0400 Received: by mail-it0-f65.google.com with SMTP id s7-v6so6118079itb.4 for ; Thu, 02 Aug 2018 17:09:16 -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=whepv9ceqpKeQSobXWBzs/Amu/cZ+5W6duyabfxJS5I=; b=aLXVahqnkz9QDpDLJ8AQLKE2W7L1TLpvjIga7fwNbe7sUXz9FIkH0gKb5hYCpk8WM+ 3c11zespD0cGxbg8/BfoWhGUtL7CjiHHVqu0DTMofkUG2k1v0bFYB0bQypfoZn2LvBw4 wjtf1tZViA86DQAUim6matsVQ85/IpJ0j8LFY= 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=whepv9ceqpKeQSobXWBzs/Amu/cZ+5W6duyabfxJS5I=; b=GStEv5LT4hxLMXS8aEZf+lHDBdQhTLLL0rrIj3th2++O/rxaogSrSwQjw0k9wnZ7WZ 1y3GYhe+agK+82jC/Pt48tjUqQVdfm9yUssTpHQrzR1qyEXikVYQtbkJSCgUryI5qTms sTr1SYrnHlbxXXOX+mSq1+B8J0IFz9EhQ7Pb6bcwrtXzb9mfKj4+fCGEDZjrMT90a9Ce WRI1kJlBwIVS2i172UyEyvQc/GyMckiu3vYk4X8fPw09tkyrE/b+LBNwnMTQSDN7o0zK JUdqVMwmxaBPs12ik1PJTEeeTGhwwB3MwVjsuFUuwgMV3fsT4xVhAPRZX241JmVxR756 FzBw== X-Gm-Message-State: AOUpUlGKuei5OmXKW0uUPZSMYyY6ANQ/Qf89uiWrsG429lnd99pHv0v/ utrVafquCh0mR8BiRwFNPQBEJpV7qK9E7IWqZNCYqg== X-Received: by 2002:a24:5004:: with SMTP id m4-v6mr4457189itb.38.1533254956321; Thu, 02 Aug 2018 17:09:16 -0700 (PDT) MIME-Version: 1.0 References: <20180730110406.132729-1-tmaimon77@gmail.com> <20180730110406.132729-3-tmaimon77@gmail.com> In-Reply-To: <20180730110406.132729-3-tmaimon77@gmail.com> From: Linus Walleij Date: Fri, 3 Aug 2018 02:09:04 +0200 Message-ID: Subject: Re: [PATCH v4 2/2] pinctrl: nuvoton: add NPCM7xx pinctrl and GPIO driver To: Tomer Maimon Cc: Rob Herring , Mark Rutland , Nancy Yuen , Patrick Venture , Brendan Higgins , avifishman70@gmail.com, Joel Stanley , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" , OpenBMC Maillist , "linux-kernel@vger.kernel.org" , "open list:GPIO SUBSYSTEM" 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 Hi Tomer, this is starting to look really good! Please try this with my patch and drop the new DIR_INV flag that I think we do not need anymore after that. Other small bits: On Mon, Jul 30, 2018 at 1:04 PM Tomer Maimon wrote: > +/* Structure for register banks */ > +struct npcm7xx_gpio { > + void __iomem *base; > + struct gpio_chip gc; > + int irqbase; > + int irq; > + void *priv; > + struct irq_chip irq_chip; > + u32 pinctrl_id; > + int (*direction_input)(struct gpio_chip *chip, unsigned offset); > + int (*direction_output)(struct gpio_chip *chip, unsigned offset, > + int value); > + int (*request)(struct gpio_chip *chip, unsigned offset); > + void (*free)(struct gpio_chip *chip, unsigned offset); Very nice! You sorted it out perfectly. > +/* GPIO handling in the pinctrl driver */ > +static void npcm_gpio_set(struct gpio_chip *gc, void __iomem *reg, > + unsigned int pinmask) > +{ > + unsigned long flags; > + unsigned long val; > + > + spin_lock_irqsave(&gc->bgpio_lock, flags); > + > + val = gc->read_reg(reg) | pinmask; > + gc->write_reg(reg, val); I see some GPIO drivers do this but I don't think you need to use these indirect ->read_reg() and ->write_reg() accessors, it just obscures things. If you need to access these registers I think it's fine to just use the base and read/write them. But it's your pick, I will not insist. Maybe it's a matter of taste. > +static int npcmgpio_direction_input(struct gpio_chip *chip, unsigned int offset) > +{ > + struct npcm7xx_gpio *bank = gpiochip_get_data(chip); > + int ret; > + > + ret = pinctrl_gpio_direction_input(offset + chip->base); > + if (ret) > + return ret; > + > + return bank->direction_input(chip, offset); > +} Exactly as I think it should work, sweet! This: > + pctrl->gpio_bank[id].pinctrl_id = pinspec.args[0]; > + pctrl->gpio_bank[id].gc.base = pinspec.args[1]; > + pctrl->gpio_bank[id].gc.ngpio = pinspec.args[2]; > + pctrl->gpio_bank[id].gc.owner = THIS_MODULE; > + pctrl->gpio_bank[id].gc.label = > + devm_kasprintf(pctrl->dev, GFP_KERNEL, "%pOF", And this: > + for (i = 0 ; i < pctrl->bank_num ; i++) { > + ret = gpiochip_add_pin_range(&pctrl->gpio_bank[i].gc, > + dev_name(pctrl->dev), > + pctrl->gpio_bank[i].pinctrl_id, > + pctrl->gpio_bank[i].gc.base, > + pctrl->gpio_bank[i].gc.ngpio); > + if (ret < 0) { > + dev_err(pctrl->dev, "Failed to add GPIO bank %u\n", i); > + gpiochip_remove(&pctrl->gpio_bank[i].gc); > + goto err_range; > + } > + } Worries me a bit. This seems to be like this because you register the GPIO before the pin controller. Normally we would register in the other order, and the code inside of_gpiochio_add() as part of [devm_]gpiochip_add() will parse the phandle and add the ranges when you add the GPIO chip. Is this impossible to solve this cleanly? Yours, Linus Walleij