Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp5211728pxu; Thu, 10 Dec 2020 16:16:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJzJkYZrMDzPx1VTclaW6WRrqjKgX73t+eTkqhC6WRc4t5iJtAgqqJTpq3pjuhwc9UsPe18V X-Received: by 2002:a17:907:3f9e:: with SMTP id hr30mr8797283ejc.258.1607645791000; Thu, 10 Dec 2020 16:16:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607645790; cv=none; d=google.com; s=arc-20160816; b=q9MWI0Zukv9G1X/tfI4p4kRtXHll1IERX8KrtzFgLiZ0Ita7H07ALEmQbsW98wGFzY ItTHhkbhmQZM97IysFb1M8T1FCNnF+5JXAVorvk8CKqTz93rgG+iKwGDq/mqv21zb5CM 5S4lxk6Xr6Q5xsBQBqOIjTjal60L7KHTghp4XHDx7JFy0vnrwjzWZKL9jBImwR3IUIK1 Pwd1d6OtXIlEfkOyZIWlr5/9gGUY3UtdrOLeNW42KdfYMBn29bpwuX6LIkSumL+We2Q3 MrIg60pVNX07R4nrUah/5fKdUV9WrYnCnF4phNUY8BrTeVQ3YKUdWuQfH40Nuteri/2V KV1w== 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=b0knabE4pLiyMjkoiksYG/IB8kMycYTPeC8EyBeBTFk=; b=VeFR7DGVwccwVMUqOAWw/sB88CuDyeBELNhTo/LtnGCyxb5fEGj+wwgTzuwleeFTSz EWP7JMUP5yUePe8hZOwRmf1R2jeEIEKWOeh9/68vXSdW19Rt7SD7DdOT2Ym9C70RC0Zn KYWKiwgzPh6+AfhipDZgfZTqSMIHoHrdF8QezQ1ODbhljV6flNuuH/S8kKk4X8o+z9HL bS2TWuXeWeLGT9HWONrseUFfbq/UQvnRF54wfSeETXS5o17xYPc2XYufGTJAKrZE+PMa YHfpDmLXqJPkW3WBH/gyHnSRoqkXUk/XI6PaE6CoQLwJbH0H9AeEPi6WuGTMGcN7LCyl b6yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@0x0f.com header.s=google header.b=miRhMRcV; 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 w16si3662654edu.211.2020.12.10.16.16.07; Thu, 10 Dec 2020 16:16:30 -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=@0x0f.com header.s=google header.b=miRhMRcV; 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 S1731900AbgLJKa1 (ORCPT + 99 others); Thu, 10 Dec 2020 05:30:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731908AbgLJKaC (ORCPT ); Thu, 10 Dec 2020 05:30:02 -0500 Received: from mail-qk1-x742.google.com (mail-qk1-x742.google.com [IPv6:2607:f8b0:4864:20::742]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C154FC0613D6 for ; Thu, 10 Dec 2020 02:29:20 -0800 (PST) Received: by mail-qk1-x742.google.com with SMTP id w79so4244976qkb.5 for ; Thu, 10 Dec 2020 02:29:20 -0800 (PST) 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=b0knabE4pLiyMjkoiksYG/IB8kMycYTPeC8EyBeBTFk=; b=miRhMRcVYRU8W2s9H83rcF+aFhaacPuIK1msFRh8h6eJwvU0WCRwa9ZzdaBW9vYaSM 5XrEfOOQ5WKR+Vi4i3eQCuBJOhhTI4d+IymcP5l/zOl4TfKm6+/MK8E1yiXqqFv+VhNz gc7Zw1UEvharuOq3E/DRhmUxt30EVJiLe85UY= 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=b0knabE4pLiyMjkoiksYG/IB8kMycYTPeC8EyBeBTFk=; b=epq6uXJb+BA6WIfQGkH70WFP7D27xopt50ueZ0BtlaghTjV9pFOySouxNRnnexAu9K +BvYRqhkEO+GAeZfagGdByEEeZPIkYULo6wqG+Jn8h+XeVmhsm5cr5k6z9atM8xs3Je4 WDsuxC13uyjDgta0bHZ/uNO7Rvmj54BlNghTMovBQdu0+2g1Eid0w8tdln37Ihqesb4x dpAbKMrdjHLmMA5AtQjNJzaxZxx3rxhTv8iApo/I2mDAGcVI/FVXd0leWNFa6V48weSy wvIa2ufvxWU6scY/IkflSHiIggWbzyh8CYBTWjy4fLOLDmnu9o2X9I6TYJlfSqx2gTTe 9ARA== X-Gm-Message-State: AOAM5320hH5m0L4ub0whFXSXafsYwA83X9F190QZtR3WeWVwRnNAq1DW /Fc6Et/UoUOxYnHHYxfUjbB8xs5hMiUUT+SjRkee9Q== X-Received: by 2002:a37:8681:: with SMTP id i123mr7867752qkd.54.1607596159936; Thu, 10 Dec 2020 02:29:19 -0800 (PST) MIME-Version: 1.0 References: <20201129110803.2461700-1-daniel@0x0f.com> <20201129110803.2461700-4-daniel@0x0f.com> In-Reply-To: From: Daniel Palmer Date: Thu, 10 Dec 2020 19:29:09 +0900 Message-ID: Subject: Re: [PATCH v4 3/5] gpio: msc313: MStar MSC313 GPIO driver To: Arnd Bergmann Cc: SoC Team , "open list:GPIO SUBSYSTEM" , DTML , Linux ARM , "linux-kernel@vger.kernel.org" , Linus Walleij , Rob Herring , Willy Tarreau Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Arnd, On Thu, 10 Dec 2020 at 06:58, Arnd Bergmann wrote: > These seem to just be contiguous ranges, so I probably would have > suggested describing them as separate gpio controllers to avoid > all the complexity with the names. As Linus already merged the > driver into the gpio tree, I won't complain too much about it. > > Maybe you can do that for the other chips though and have one > implementation that works for all others, leaving only the msc313 > as the one with the extra complexity. I'll have a think about that. The other chips I'm aiming to support (the mercury5 ssc8336 and infinity2m ssd202) currently reuse most of the msc313 bits with a few extras for the differences. i.e. the ssc8336 reuses most of the tables for the msc313 with some additions. Adding new chips hasn't been too bad so far. > > +#define MSC313_GPIO_CHIPDATA(_chip) \ > > static const struct msc313_gpio_data _chip##_data = { \ > > + .names = _chip##_names, \ > > + .offsets = _chip##_offsets, \ > > + .num = ARRAY_SIZE(_chip##_offsets), \ > > +} > > > +#ifdef CONFIG_MACH_INFINITY > > +static const char * const msc313_names[] = { > > + FUART_NAMES, > > + SR_NAMES, > > I would try to avoid the #ifdefs and the macros here, don't overthink > it. The macro really hurts readability with the ## concatenation > making it impossible to grep for where things are defined, and > the #ifdef means you get worse compile test coverage compared > to an if(IS_ENABLED()) check in the place where the identifiers > are actually used. Ok. I was really just trying to enforce some sort of pattern there so that each chip that gets added follows the same convention. > Even better would be to completely avoid the lookup tables here, > and have one driver that is instantiated based on settings from > the DT. I did think about this and I did this with the clk mux driver I haven't pushed yet. In that case there is a random lump of registers with some muxes mixed into it so I decided to make the lump a syscon and then have a node for each clk mux in the lump and some properties for the muxes within. The driver is certainly less complex but the device tree is pretty unmanageable as there are probably 30 or more muxes. > > +static void msc313_gpio_set(struct gpio_chip *chip, unsigned int offset, int value) > > +{ > > + struct msc313_gpio *gpio = gpiochip_get_data(chip); > > + u8 gpioreg = readb_relaxed(gpio->base + gpio->gpio_data->offsets[offset]); > > + > > + if (value) > > + gpioreg |= MSC313_GPIO_OUT; > > + else > > + gpioreg &= ~MSC313_GPIO_OUT; > > + > > + writeb_relaxed(gpioreg, gpio->base + gpio->gpio_data->offsets[offset]); > > +} > > It would be helpful here to replace all the readb_relaxed/writeb_relaxed() > with normal readb()/writeb(). Don't use _relaxed() unless there is a strong > reason why you have to do it, and if you do, explain it in a comment what > the reason is. The reason is that readb()/writeb() will invoke the heavy memory barrier even though it's not needed for peripheral registers. I guess it doesn't actually make all that much difference in reality. > > +static int msc313_gpio_direction_output(struct gpio_chip *chip, unsigned int offset, int value) > > +{ > > + struct msc313_gpio *gpio = gpiochip_get_data(chip); > > + u8 gpioreg = readb_relaxed(gpio->base + gpio->gpio_data->offsets[offset]); > > + > > + gpioreg &= ~MSC313_GPIO_OEN; > > + if (value) > > + gpioreg |= MSC313_GPIO_OUT; > > + else > > + gpioreg &= ~MSC313_GPIO_OUT; > > + writeb_relaxed(gpioreg, gpio->base + gpio->gpio_data->offsets[offset]); > > These look like they also need a spinlock to avoid races between concurrent > read-modify-write cycles on the same register. Noted. I'll fix this and the readb and send a patch at some point. > > +builtin_platform_driver(msc313_gpio_driver); > > There is a trend to make all drivers optionally loadable modules these days. > Is there a reason this has to be built-in? This was discussed and I think Linus said it was ok. Thanks, Daniel