Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp1737675pxu; Fri, 16 Oct 2020 22:43:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx+FPYKNkqlAiJ/D8UQqde0Yy+ARf7NpV+38OqId1KZyyZPVLRDZlkn2rcNwAUxmdYUKUXJ X-Received: by 2002:a17:906:2b5b:: with SMTP id b27mr7337646ejg.400.1602913397935; Fri, 16 Oct 2020 22:43:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602913397; cv=none; d=google.com; s=arc-20160816; b=lzFUm6WtziBae0Pt3YuAwgKzYv3RfHkk9xj/m8iY+xJB2jOVZU3mQ1p4//Jh8rfC9h qrPwJWGzcd9IPwhVE/NXQHc0FQE0aqZkPHYCgdAy/2xm5LR9lkzyH/HnWUD187kumlQR u2WCmKbBJVlbxSxOG+Sjx5jDe3IVZ4WY9u5+NWyr/SEuxC+Ia6UdnupBTjXS1La1wlnW 7uQBsGo4Y9JGQa4HC8UfI5SFexRIg2kDwo1NxKnLKBC1nHO0PuSD35qyPhWKi+20DPZL YwaAqQu/1XzflDJAZ2qMP97QYckXFXNeSOeU9TTWzRd5WoXARAOTFKTsNFHAEhu4o0IU hiYQ== 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=nuh/bmn3RkFq4gADcA0ZAUJL6az2qyr09AghLknddnE=; b=OwmeF6FZ05BwONiY/UvEY6p8L0k3YuG6c7dqVtVwAZZtkaluUfE/HKvvfGO61d3aEY a9K6sxnTUv7sZkeOByY9bxOXwaIxLrPxZqd1O6mUjZQ+KIKKvi6EGa8UHl7Btwv/D1BS 21rRImnYO9/b8vwoeZZEuTACEvPmAnz9YSncNEY1uW+xpbscUje4daSH6om0b4ylFT7S tLV8EsbWIoYAUsdkIQPETQKei9dO7vmms8WojwJ0ItmtMCX4TqzSY2ttL0hgCdMcd4Nn CYIEsj10bPyhG2X5QEjoSebNdjozKDQudgP5V1Zy8XCjQgUNEBJ8VFLiaUTvufnjVu6i b/9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@0x0f.com header.s=google header.b=Hc8aQmwn; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v20si3159388eja.42.2020.10.16.22.42.55; Fri, 16 Oct 2020 22:43:17 -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=@0x0f.com header.s=google header.b=Hc8aQmwn; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2411745AbgJQFe7 (ORCPT + 99 others); Sat, 17 Oct 2020 01:34:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2411755AbgJQFen (ORCPT ); Sat, 17 Oct 2020 01:34:43 -0400 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8166FC0610E0 for ; Fri, 16 Oct 2020 18:57:47 -0700 (PDT) Received: by mail-wm1-x343.google.com with SMTP id z22so2528863wmi.0 for ; Fri, 16 Oct 2020 18:57:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=0x0f.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=nuh/bmn3RkFq4gADcA0ZAUJL6az2qyr09AghLknddnE=; b=Hc8aQmwnLL+wERyyQ7CpO51Fsn3derfmkT8umMZkwXPkhXFcXuK1+srj5bzWdyGS8X w44FRI2rzKxxk+WBy/GE7xvWOVWLkwNIvcfxSm9c9uuhAX+67wPWEgXL3kgROKrUsuvf zsmczeVNeaUiEkBC4f+DsFxJ2lpdyqlb7kjm8= 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=nuh/bmn3RkFq4gADcA0ZAUJL6az2qyr09AghLknddnE=; b=eCWRsgWwZ+D8nE3mpiD0AETAgmF+3uBSzAFIJnqRt+mMgRFJTX18g+N5FKW3MCWNCM xrs+BUf1MXUv5uZ375Iij7KI/BX1pTsp9lRONmPBcTR5+N9SO5H1wbtTRJywWv6h83xj Fl6q31DLudqhmq7kQ+0vJTKEG1EXp5AMO6oBLqe0GF1WRBapjpawAGBUaK73mxeIyXP6 7t0kETym/vdHsu2eT04aSZ7wUmsAolqPotITGqHLr3mc956eqabf3jpJxcHkeLrHX4pM dxasFb98GlLzJbBwHXBlbBxWr8jKxSvbUkHsUwTUkR3Nzt/LKD17WGsyJCb4c/ulBOKB JOpQ== X-Gm-Message-State: AOAM531sKnimtkmjmSOKSeAvh+Cpjve+xIErJ2YPODCakyUmvAaa6gq0 IhuPpslyHyLq++zDatviHRD/krTarpsbKTIQdhNASw== X-Received: by 2002:a7b:c935:: with SMTP id h21mr6120268wml.99.1602899865888; Fri, 16 Oct 2020 18:57:45 -0700 (PDT) MIME-Version: 1.0 References: <20201011024831.3868571-1-daniel@0x0f.com> <20201011024831.3868571-4-daniel@0x0f.com> In-Reply-To: From: Daniel Palmer Date: Sat, 17 Oct 2020 10:57:35 +0900 Message-ID: Subject: Re: [PATCH 3/5] gpio: msc313: MStar MSC313 GPIO driver To: Linus Walleij 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 Linus On Sat, 17 Oct 2020 at 01:56, Linus Walleij wrote: > (...) > > > +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. Well spotted. Copy/paste fail on my side :). > > +#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. There is a comment near to the save function that explains it I think. When the hardware goes into low power mode with the CPU turned off the register contents are lost and those two bits are the only ones that are writable from what I can tell. I'll add an extra comment above that line. > > +#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. > > > Same with all these. I suppose it is the offsets of stuff > that would be there unless we were using it for GPIO. The pad FUART_RX can't move but the function FUART_RX can. If the function FUART_RX (or another function) isn't on the pad/pin FUART_RX it's connected to the GPIO block. Even more confusingly some of the other chips (SSD201/SSD202) have pads called GPIO1, GPIO2 etc that only have GPIO functionality but the offsets of the registers to control the GPIO on those pads might not have a relation to the name. GPIO1 isn't gpio_base + (1 * 4) and instead some random address. Basically using the pad name as the name of the GPIO made sense because it's fixed and the pad name and offset are the same with all of the chips I've seen so far. > > +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. > 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. I'll look into this. I don't have datasheets so I'm working from some crusty header files from the vendor kernel but there isn't one irq per line from what I can tell. There seems to have been 4 spare lines on an interrupt controller so they wired GPIOs to them. Thank you for the comments. I'll send a v2 in a few days. Thanks, Daniel