Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752337AbdI1SBQ (ORCPT ); Thu, 28 Sep 2017 14:01:16 -0400 Received: from vps0.lunn.ch ([185.16.172.187]:60274 "EHLO vps0.lunn.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752042AbdI1SBO (ORCPT ); Thu, 28 Sep 2017 14:01:14 -0400 Date: Thu, 28 Sep 2017 20:01:11 +0200 From: Andrew Lunn To: Florian Fainelli Cc: Brandon Streiff , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "David S. Miller" , Vivien Didelot , Richard Cochran , Erik Hons Subject: Re: [PATCH net-next RFC 3/9] net: dsa: mv88e6xxx: add support for GPIO configuration Message-ID: <20170928180111.GF14940@lunn.ch> References: <1506612341-18061-1-git-send-email-brandon.streiff@ni.com> <1506612341-18061-4-git-send-email-brandon.streiff@ni.com> <659c4254-d0b7-52dc-dd9b-3921cd2f20c0@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <659c4254-d0b7-52dc-dd9b-3921cd2f20c0@gmail.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1795 Lines: 51 On Thu, Sep 28, 2017 at 10:45:03AM -0700, Florian Fainelli wrote: > On 09/28/2017 08:25 AM, Brandon Streiff wrote: > > The Scratch/Misc register is a windowed interface that provides access > > to the GPIO configuration. Provide a new method for configuration of > > GPIO functions. > > > > Signed-off-by: Brandon Streiff > > --- > > > +/* Offset 0x1A: Scratch and Misc. Register */ > > +static int mv88e6xxx_g2_scratch_reg_read(struct mv88e6xxx_chip *chip, > > + int reg, u8 *data) > > +{ > > + int err; > > + u16 value; > > + > > + err = mv88e6xxx_g2_write(chip, MV88E6XXX_G2_SCRATCH_MISC_MISC, > > + reg << 8); > > + if (err) > > + return err; > > + > > + err = mv88e6xxx_g2_read(chip, MV88E6XXX_G2_SCRATCH_MISC_MISC, &value); > > + if (err) > > + return err; > > + > > + *data = (value & MV88E6XXX_G2_SCRATCH_MISC_DATA_MASK); > > + > > + return 0; > > +} > > With the write and read acquiring and then releasing the lock > immediately, is no there room for this sequence to be interrupted in the > middle and end-up returning inconsistent reads? Hi Florian The general pattern in this code is that the lock chip->reg_lock is taken at a higher level. That protects against other threads. The driver tends to do that at the highest levels, at the entry points into the driver. I've not yet checked this code follows the pattern yet. However, we have a check in the low level to ensure the lock has been taken. So it seems likely the lock is held. > Would there be any value in implementing a proper gpiochip structure > here such that other pieces of SW can see this GPIO controller as a > provider and you can reference it from e.g: Device Tree using GPIO > descriptors? That would be my preference as well, or maybe a pinctrl driver. Andrew