Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp936438imm; Fri, 3 Aug 2018 14:27:34 -0700 (PDT) X-Google-Smtp-Source: AAOMgpc72G2guna2iTNKEtEE3TCwzmDffjBF0dxttl6LDakfNwKf3mxPKps7zNCW6qnIWOrwhw2M X-Received: by 2002:a63:d20e:: with SMTP id a14-v6mr5381288pgg.226.1533331654426; Fri, 03 Aug 2018 14:27:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533331654; cv=none; d=google.com; s=arc-20160816; b=MTuF55M4cmSZmkksOaDmb3oSyGXge0xpN4a173kAWQIA/TAcdLDWC9J520u1mp6baL aJ4wgxoiRJ8H0lBKmPgnwJPNQ+DoVuFFfoQdYzPuLwjSaApq5JPLJ5G7PuHvpqQQ/+wr /UexAaTZO9SPrzEtfem+lqi/bMWsaBmJoQ86PQ9b0mxTeEX6IHiAtktjRKme1DDx95lt lKyVY/5NfQKVcLxJbEZLjmXDaU1OKLJYdFGQ5Pu86JxHwH7ugp32ReZJYtHewx9oSRzB acpBj4WnQJkbR7yyU33ZLtkl2B3+ukAJLb9zan/M1DfPO/ydbxNZ5JiK1xFxJeqHuGST 5xNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature:arc-authentication-results; bh=ScjaT+Ls+HC2vGog0zjFxk9iqQO7/mYVcOB+f6zNSnA=; b=LwB1j1+gf3aPMugJyw0K+IO49MuHJB/4AkE4MpQIpbHbZOwR5Ionsdtmnt28nBE3+6 hkVUqKe4CpEcmNHJs7fXUOv2IL4B3HwzLmRLbv8oW2260K4UVHpl/i+UcYEbTm/JnTmV sYKsJYmZGJAWTIr7EFZYwySANt1Jeb0HJDbj3GsZKsBKYJtWblBJ4koVCMtxrT1SsJrH zWZluzE7/jLNVEtV5r53YKu2O8+Shmg9gGD28DHMr7LEuWkprDlIYk0yEK1Hbhsb47rz OkQHNwVjFahDKdBVs788+Nbn1dIGx0ICXaPftq3Ru4mKgCTGteDKjzvdDjAob0tA5jlP UiRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=m5BmFUZQ; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u134-v6si5728496pfc.244.2018.08.03.14.27.19; Fri, 03 Aug 2018 14:27:34 -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=@kernel.org header.s=default header.b=m5BmFUZQ; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731999AbeHCXYc (ORCPT + 99 others); Fri, 3 Aug 2018 19:24:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:33480 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729660AbeHCXYc (ORCPT ); Fri, 3 Aug 2018 19:24:32 -0400 Received: from archlinux (cpc91196-cmbg18-2-0-cust659.5-4.cable.virginm.net [81.96.234.148]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AE2CF2178D; Fri, 3 Aug 2018 21:26:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1533331590; bh=oFEq5z4HBQOsdY30N/e0TW8ntjyvbSbPm82mHXnQbCk=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=m5BmFUZQ0Jigzb8vKvnArfNwpeAyBnlE8bthk1Lf7sfuyiVoV/4DoDbKW7lfHEsap iIwInnn0lTVqhWwCRf7QET0BhX400Am4VO/EwgpVJEqUkkA+T+TRsFccuPLkzqxW6s 5z9fD2fp12VAZKJQzQeRJEutW6MPri3BpQCE8bAw= Date: Fri, 3 Aug 2018 22:26:24 +0100 From: Jonathan Cameron To: Stefan Popa Cc: , , , , , , , , , , , , , , "Crestez Dan Leonard" Subject: Re: [PATCH v3 3/6] regmap: Add regmap_noinc_read API Message-ID: <20180803222624.68572840@archlinux> In-Reply-To: <1533301341-26560-4-git-send-email-stefan.popa@analog.com> References: <1533301341-26560-1-git-send-email-stefan.popa@analog.com> <1533301341-26560-4-git-send-email-stefan.popa@analog.com> X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 3 Aug 2018 16:02:18 +0300 Stefan Popa wrote: > From: Crestez Dan Leonard > > The regmap API usually assumes that bulk read operations will read a > range of registers but some I2C/SPI devices have certain registers for > which a such a read operation will return data from an internal FIFO > instead. Add an explicit API to support bulk read without range semantics. > > Some linux drivers use regmap_bulk_read or regmap_raw_read for such > registers, for example mpu6050 or bmi150 from IIO. This only happens to > work because when caching is disabled a single regmap read op will map > to a single bus read op (as desired). This breaks if caching is enabled and > reg+1 happens to be a cacheable register. > > Without regmap support refactoring a driver to enable regmap caching > requires separate I2C and SPI paths. This is exactly what regmap is > supposed to help avoid. > > Suggested-by: Jonathan Cameron > Signed-off-by: Crestez Dan Leonard > Signed-off-by: Stefan Popa I always liked this so am very pleased you have picked it up - so if Mark want's to squeeze it in directly then I'm happy for him to do so. If not, hopefully he's happy for this got via IIO next cycle? Reviewed-by: Jonathan Cameron When this is applied we'll have to remember to clear up the odd cases you hightlight above as well. > --- > drivers/base/regmap/regmap.c | 65 +++++++++++++++++++++++++++++++++++++++++++- > include/linux/regmap.h | 9 ++++++ > 2 files changed, 73 insertions(+), 1 deletion(-) > > diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c > index 3bc8488..e632503 100644 > --- a/drivers/base/regmap/regmap.c > +++ b/drivers/base/regmap/regmap.c > @@ -2564,7 +2564,70 @@ int regmap_raw_read(struct regmap *map, unsigned int reg, void *val, > EXPORT_SYMBOL_GPL(regmap_raw_read); > > /** > - * regmap_field_read() - Read a value to a single register field > + * regmap_noinc_read(): Read data from a register without incrementing the > + * register number > + * > + * @map: Register map to read from > + * @reg: Register to read from > + * @val: Pointer to data buffer > + * @val_len: Length of output buffer in bytes. > + * > + * The regmap API usually assumes that bulk bus read operations will read a > + * range of registers. Some devices have certain registers for which a read > + * operation read will read from an internal FIFO. > + * > + * The target register must be volatile but registers after it can be > + * completely unrelated cacheable registers. > + * > + * This will attempt multiple reads as required to read val_len bytes. > + * > + * A value of zero will be returned on success, a negative errno will be > + * returned in error cases. > + */ > +int regmap_noinc_read(struct regmap *map, unsigned int reg, > + void *val, size_t val_len) > +{ > + size_t read_len; > + int ret; > + > + if (!map->bus) > + return -EINVAL; > + if (!map->bus->read) > + return -ENOTSUPP; > + if (val_len % map->format.val_bytes) > + return -EINVAL; > + if (!IS_ALIGNED(reg, map->reg_stride)) > + return -EINVAL; > + if (val_len == 0) > + return -EINVAL; > + > + map->lock(map->lock_arg); > + > + if (!regmap_volatile(map, reg) || !regmap_readable(map, reg)) { > + ret = -EINVAL; > + goto out_unlock; > + } > + > + while (val_len) { > + if (map->max_raw_read && map->max_raw_read < val_len) > + read_len = map->max_raw_read; > + else > + read_len = val_len; > + ret = _regmap_raw_read(map, reg, val, read_len); > + if (ret) > + goto out_unlock; > + val = ((u8 *)val) + read_len; > + val_len -= read_len; > + } > + > +out_unlock: > + map->unlock(map->lock_arg); > + return ret; > +} > +EXPORT_SYMBOL_GPL(regmap_noinc_read); > + > +/** > + * regmap_field_read(): Read a value to a single register field > * > * @field: Register field to read from > * @val: Pointer to store read value > diff --git a/include/linux/regmap.h b/include/linux/regmap.h > index 4f38068..b6e6040 100644 > --- a/include/linux/regmap.h > +++ b/include/linux/regmap.h > @@ -946,6 +946,8 @@ int regmap_raw_write_async(struct regmap *map, unsigned int reg, > int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val); > int regmap_raw_read(struct regmap *map, unsigned int reg, > void *val, size_t val_len); > +int regmap_noinc_read(struct regmap *map, unsigned int reg, > + void *val, size_t val_len); > int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val, > size_t val_count); > int regmap_update_bits_base(struct regmap *map, unsigned int reg, > @@ -1196,6 +1198,13 @@ static inline int regmap_raw_read(struct regmap *map, unsigned int reg, > return -EINVAL; > } > > +static inline int regmap_pipe_read(struct regmap *map, unsigned int reg, > + void *val, size_t val_len) > +{ > + WARN_ONCE(1, "regmap API is disabled"); > + return -EINVAL; > +} > + > static inline int regmap_bulk_read(struct regmap *map, unsigned int reg, > void *val, size_t val_count) > {