Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1609029pxj; Sat, 12 Jun 2021 14:15:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyeDYhHEkAD5cTQ27H8yw4ofGPHxBRG9v1Kz7njFU+4KNzdBIb8MbTRtnD8zYipry055vbJ X-Received: by 2002:a05:6402:2790:: with SMTP id b16mr10030014ede.115.1623532521587; Sat, 12 Jun 2021 14:15:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623532521; cv=none; d=google.com; s=arc-20160816; b=LkssfKHXdpjFDPcXhZZgF2sSLVa1YpTNoFUGz5aiHaUgF6bBbn2NhDSnHAGBH433vz faPltM0K8qaiq28qxBYCjm5GsmGgnpgKKQbo0FtYGpGOVY12kpzIzz3IMy2cKQD4IurC A1LZg+kkMbeHqeR5mPCnWFhOIyB/w9Pfe875VBpI359cZfzeRxBl8CxhCJELO+DtfUOx q70Nw7C0ZekX+ZQLxS3XmJNmp0qLECip9rie2Lm1R17WtHO1/4Hybk9VqcbLlrQzV66y YPUjT4I48B30Vvq7qIfFiPuny7JgGrChJTm44aNurEjMC0hpqwTDH9xNImlqPapnENeK J5KQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=wGMyTGqExOUC7fcBNcFG8EWKgKVZcX6itOO0TIv9aY0=; b=A1+qmLXfOhhZMoSrA2bbv0ZOeKAvQkgzumhTb/g9EJEmylCcQ4CKKsYhelLBiaAE9L GWA9UH08QwO7Fjho2O+6TY+iwCt05LRJFXX+698sGBjC2Sw9qpN3Oj+/GXl4+JoyujC3 xokzd9qugHg15ZIueJt2XBs+9sFVMJQBmp8iDLv1OZ2MN9Vr4QWx+hY++AtZvZ6fYsti LkGdVgTRRO8zBYWGurYzNahe1KI4WKC/pvHGA3b8LHFZZOMiy6Z+/eIYEAmhDuMygT9B 6qmIeWmCfJQi/HqAvJCU9Qw95TVuQXar/tizG7nmkWIgTmdRhgHUPGS88/+3txbL1uNS pSvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@svanheule.net header.s=mail1707 header.b="Hki/FRU/"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=svanheule.net Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cq27si7306693edb.222.2021.06.12.14.14.59; Sat, 12 Jun 2021 14:15:21 -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=@svanheule.net header.s=mail1707 header.b="Hki/FRU/"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=svanheule.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231531AbhFLVPh (ORCPT + 99 others); Sat, 12 Jun 2021 17:15:37 -0400 Received: from polaris.svanheule.net ([84.16.241.116]:48018 "EHLO polaris.svanheule.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231509AbhFLVPh (ORCPT ); Sat, 12 Jun 2021 17:15:37 -0400 Received: from terra.local.svanheule.net (unknown [IPv6:2a02:a03f:eafb:ee01:a4dd:c59:8cbd:ee0d]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: sander@svanheule.net) by polaris.svanheule.net (Postfix) with ESMTPSA id 24FE020C9CD; Sat, 12 Jun 2021 23:13:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=svanheule.net; s=mail1707; t=1623532414; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wGMyTGqExOUC7fcBNcFG8EWKgKVZcX6itOO0TIv9aY0=; b=Hki/FRU/5sgbOdptnEi7Qtz+P4sxe3DEbzVZ32Bzhc53QEgi+BdnfCuFz8iNRB4LPlrFf8 osQxi5/4+ckM7XBSs+Eg1lYdqujBfy5OWDl8qwF7BtwEEXVaz7IjmUDxzF1zLDg7TT13qy Tvp4GBsKcpNlnbeY0quKIOHkG7urXL0P8eYRzWht0yqM3wnFti/mtvoqbX/vgvRtU39X3p l4txFpk3hOD/xxpr9gwx7Lw5Lw8aLpJ0hxdVAUPdM2p8xzmZnsRP1Tob3+k2yXzBEgE6KV ZY2jsMKhzSCA3Ly8ocxYbPOgd93b0jVDHxIkoIcD6zwP1xwzx3k7smZBDBTh9w== From: Sander Vanheule To: Pavel Machek , Rob Herring , Lee Jones , Mark Brown , Greg Kroah-Hartman , "Rafael J . Wysocki" , Michael Walle , Linus Walleij , Bartosz Golaszewski , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-gpio@vger.kernel.org Cc: Andrew Lunn , Andy Shevchenko , linux-kernel@vger.kernel.org, Sander Vanheule Subject: [PATCH v5 1/8] regmap: Support atomic forced uncached reads Date: Sat, 12 Jun 2021 23:12:31 +0200 Message-Id: X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When a user wants to read a single uncached register, cache bypassing can be enabled. However, this is not atomic unless an external lock is used for the regmap. When using regcache_cache_bypass, the original bypass state also cannot be restored. Add support to atomically read a single uncached value, bypassing any regmap cache. Signed-off-by: Sander Vanheule --- drivers/base/regmap/regmap.c | 33 +++++++++++++++++++++++++++++++++ include/linux/regmap.h | 8 ++++++++ 2 files changed, 41 insertions(+) diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index fe3e38dd5324..a828f05535b7 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -2745,6 +2745,39 @@ int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val) } EXPORT_SYMBOL_GPL(regmap_read); +/** + * regmap_read_bypassed() - Read a value from a single register, bypassing the cache + * + * @map: Register map to read from + * @reg: Register to be read from + * @val: Pointer to store read value + * + * A value of zero will be returned on success, a negative errno will + * be returned in error cases. + */ +int regmap_read_bypassed(struct regmap *map, unsigned int reg, unsigned int *val) +{ + bool bypass; + int ret; + + if (!IS_ALIGNED(reg, map->reg_stride)) + return -EINVAL; + + map->lock(map->lock_arg); + + bypass = map->cache_bypass; + map->cache_bypass = true; + + ret = _regmap_read(map, reg, val); + + map->cache_bypass = bypass; + + map->unlock(map->lock_arg); + + return ret; +} +EXPORT_SYMBOL_GPL(regmap_read_bypassed); + /** * regmap_raw_read() - Read raw data from the device * diff --git a/include/linux/regmap.h b/include/linux/regmap.h index f5f08dd0a116..a54dc00326ba 100644 --- a/include/linux/regmap.h +++ b/include/linux/regmap.h @@ -1133,6 +1133,7 @@ int regmap_multi_reg_write_bypassed(struct regmap *map, int regmap_raw_write_async(struct regmap *map, unsigned int reg, const void *val, size_t val_len); int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val); +int regmap_read_bypassed(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, @@ -1607,6 +1608,13 @@ static inline int regmap_read(struct regmap *map, unsigned int reg, return -EINVAL; } +static inline int regmap_read_bypassed(struct regmap *map, unsigned int reg, + unsigned int *val) +{ + WARN_ONCE(1, "regmap API is disabled"); + return -EINVAL; +} + static inline int regmap_raw_read(struct regmap *map, unsigned int reg, void *val, size_t val_len) { -- 2.31.1