From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e40sR-0006VC-Fh for barebox@lists.infradead.org; Mon, 16 Oct 2017 08:36:01 +0000 Date: Mon, 16 Oct 2017 10:35:37 +0200 From: Sascha Hauer Message-ID: <20171016083537.bykiglghw73ds3fx@pengutronix.de> References: <20171006095302.9602-1-s.trumtrar@pengutronix.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20171006095302.9602-1-s.trumtrar@pengutronix.de> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "barebox" Errors-To: barebox-bounces+u.kleine-koenig=pengutronix.de@lists.infradead.org Subject: Re: [PATCH] regmap: port regmap_update_bits from linux To: Steffen Trumtrar Cc: barebox@lists.infradead.org On Fri, Oct 06, 2017 at 11:53:02AM +0200, Steffen Trumtrar wrote: > Port the regmap_update_bits function from linux v4.14-rc1 to barebox. > > Signed-off-by: Steffen Trumtrar > --- > drivers/base/regmap/regmap.c | 29 +++++++++++++++++++++++++++++ > include/regmap.h | 3 ++- > 2 files changed, 31 insertions(+), 1 deletion(-) Applied, thanks Sascha > > diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c > index 52b7d88c74ed..67d95fe30a0b 100644 > --- a/drivers/base/regmap/regmap.c > +++ b/drivers/base/regmap/regmap.c > @@ -137,6 +137,35 @@ int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val) > } > > /** > + * regmap_update_bits() - Perform a read/modify/write cycle on a register > + * > + * @map: Register map to update > + * @reg: Register to update > + * @mask: Bitmask to change > + * @val: New value for bitmask > + * > + * Returns zero for success, a negative number on error. > + */ > +int regmap_update_bits(struct regmap *map, unsigned int reg, > + unsigned int mask, unsigned int val) > +{ > + int ret; > + unsigned int tmp, orig; > + > + ret = regmap_read(map, reg, &orig); > + if (ret != 0) > + return ret; > + > + tmp = orig & ~mask; > + tmp |= val & mask; > + > + if (tmp != orig) > + ret = regmap_write(map, reg, tmp); > + > + return ret; > +} > + > +/** > * regmap_write_bits - write bits of a register in a map > * > * @map: The map > diff --git a/include/regmap.h b/include/regmap.h > index 9675a17b9641..09b7b57d52f3 100644 > --- a/include/regmap.h > +++ b/include/regmap.h > @@ -62,6 +62,7 @@ int regmap_get_reg_stride(struct regmap *map); > > int regmap_write_bits(struct regmap *map, unsigned int reg, > unsigned int mask, unsigned int val); > - > +int regmap_update_bits(struct regmap *map, unsigned int reg, > + unsigned int mask, unsigned int val); > > #endif /* __REGMAP_H */ > -- > 2.11.0 > > > _______________________________________________ > barebox mailing list > barebox@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/barebox > -- Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox