From patchwork Wed May 27 12:52:03 2020
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Patchwork-Submitter: Pratyush Yadav
X-Patchwork-Id: 1298879
X-Patchwork-Delegate: sjg@chromium.org
Return-Path:
X-Original-To: incoming@patchwork.ozlabs.org
Delivered-To: patchwork-incoming@bilbo.ozlabs.org
Authentication-Results: ozlabs.org;
spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de
(client-ip=85.214.62.61; helo=phobos.denx.de;
envelope-from=u-boot-bounces@lists.denx.de; receiver=)
Authentication-Results: ozlabs.org;
dmarc=pass (p=quarantine dis=none) header.from=ti.com
Authentication-Results: ozlabs.org;
dkim=pass (1024-bit key;
unprotected) header.d=ti.com header.i=@ti.com header.a=rsa-sha256
header.s=ti-com-17Q1 header.b=GVfHg0cq;
dkim-atps=neutral
Received: from phobos.denx.de (phobos.denx.de [85.214.62.61])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
key-exchange X25519 server-signature RSA-PSS (4096 bits))
(No client certificate requested)
by ozlabs.org (Postfix) with ESMTPS id 49X9jg65Bmz9sRK
for ; Wed, 27 May 2020 22:53:11 +1000 (AEST)
Received: from h2850616.stratoserver.net (localhost [IPv6:::1])
by phobos.denx.de (Postfix) with ESMTP id 87CD781CA8;
Wed, 27 May 2020 14:52:36 +0200 (CEST)
Authentication-Results: phobos.denx.de;
dmarc=pass (p=quarantine dis=none) header.from=ti.com
Authentication-Results: phobos.denx.de;
spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de
Authentication-Results: phobos.denx.de;
dkim=pass (1024-bit key;
unprotected) header.d=ti.com header.i=@ti.com header.b="GVfHg0cq";
dkim-atps=neutral
Received: by phobos.denx.de (Postfix, from userid 109)
id 4DC9B819F4; Wed, 27 May 2020 14:52:25 +0200 (CEST)
X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de
X-Spam-Level:
X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,
DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED
autolearn=ham autolearn_force=no version=3.4.2
Received: from fllv0016.ext.ti.com (fllv0016.ext.ti.com [198.47.19.142])
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
(No client certificate requested)
by phobos.denx.de (Postfix) with ESMTPS id 883D8815F2
for ; Wed, 27 May 2020 14:52:19 +0200 (CEST)
Authentication-Results: phobos.denx.de;
dmarc=pass (p=quarantine dis=none) header.from=ti.com
Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=p.yadav@ti.com
Received: from fllv0035.itg.ti.com ([10.64.41.0])
by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 04RCqHea033880;
Wed, 27 May 2020 07:52:17 -0500
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com;
s=ti-com-17Q1; t=1590583937;
bh=G7KETig5C2v94C2IW1erpNnPxaXeAb/ZsmRn/TgXAc8=;
h=From:To:CC:Subject:Date:In-Reply-To:References;
b=GVfHg0cqjfrtCewGjC5fGAR3BVlc9hoi+sZWZJQeNVDg2Y6s1I/XOe4u5y9MV6fN7
AZzrzKuwAvCk6rQVVX1CJGTndlnuryNV/EDrvXAz2sAJYyDTztI4DDDW7+yQz/nooe
Hqn1rHg7FoVPuuWeYcwk+H+MEnFHFUmkW5SBOUy8=
Received: from DFLE102.ent.ti.com (dfle102.ent.ti.com [10.64.6.23])
by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTP id 04RCqHQc105395;
Wed, 27 May 2020 07:52:17 -0500
Received: from DFLE111.ent.ti.com (10.64.6.32) by DFLE102.ent.ti.com
(10.64.6.23) with Microsoft SMTP Server (version=TLS1_2,
cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3; Wed, 27
May 2020 07:52:17 -0500
Received: from fllv0040.itg.ti.com (10.64.41.20) by DFLE111.ent.ti.com
(10.64.6.32) with Microsoft SMTP Server (version=TLS1_2,
cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3 via
Frontend Transport; Wed, 27 May 2020 07:52:17 -0500
Received: from pratyush-OptiPlex-790.dhcp.ti.com (ileax41-snat.itg.ti.com
[10.172.224.153])
by fllv0040.itg.ti.com (8.15.2/8.15.2) with ESMTP id 04RCq9HC022313;
Wed, 27 May 2020 07:52:15 -0500
From: Pratyush Yadav
To: Simon Glass ,
CC: Pratyush Yadav , Vignesh Raghavendra ,
Sekhar Nori
Subject: [PATCH 3/8] regmap: Allow specifying read/write width
Date: Wed, 27 May 2020 18:22:03 +0530
Message-ID: <20200527125208.24881-4-p.yadav@ti.com>
X-Mailer: git-send-email 2.25.0
In-Reply-To: <20200527125208.24881-1-p.yadav@ti.com>
References: <20200527125208.24881-1-p.yadav@ti.com>
MIME-Version: 1.0
X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180
X-BeenThere: u-boot@lists.denx.de
X-Mailman-Version: 2.1.30rc1
Precedence: list
List-Id: U-Boot discussion
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
Errors-To: u-boot-bounces@lists.denx.de
Sender: "U-Boot"
X-Virus-Scanned: clamav-milter 0.102.2 at phobos.denx.de
X-Virus-Status: Clean
Right now, regmap_read() and regmap_write() read/write a 32-bit value
only. To write other lengths, regmap_raw_read() and regmap_raw_write()
need to be used.
This means that any driver ported from Linux that relies on
regmap_{read,write}() to know the size already has to be updated at each
callsite. This makes the port harder to maintain.
So, allow specifying the read/write width to make it easier to port the
drivers, since now the only change needed is when initializing the
regmap.
Signed-off-by: Pratyush Yadav
Reviewed-by: Simon Glass
---
drivers/core/regmap.c | 12 +++++++++---
include/regmap.h | 28 ++++++++++++++++++----------
2 files changed, 27 insertions(+), 13 deletions(-)
diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c
index 24651fb3ec..0180246095 100644
--- a/drivers/core/regmap.c
+++ b/drivers/core/regmap.c
@@ -245,7 +245,7 @@ struct regmap *devm_regmap_init(struct udevice *dev,
const struct regmap_config *config)
{
int rc;
- struct regmap **mapp;
+ struct regmap **mapp, *map;
mapp = devres_alloc(devm_regmap_release, sizeof(struct regmap *),
__GFP_ZERO);
@@ -256,6 +256,10 @@ struct regmap *devm_regmap_init(struct udevice *dev,
if (rc)
return ERR_PTR(rc);
+ map = *mapp;
+ if (config)
+ map->width = config->width;
+
devres_add(dev, mapp);
return *mapp;
}
@@ -378,7 +382,8 @@ int regmap_raw_read(struct regmap *map, uint offset, void *valp, size_t val_len)
int regmap_read(struct regmap *map, uint offset, uint *valp)
{
- return regmap_raw_read(map, offset, valp, REGMAP_SIZE_32);
+ return regmap_raw_read(map, offset, valp,
+ map->width ? map->width : REGMAP_SIZE_32);
}
static inline void __write_8(u8 *addr, const u8 *val,
@@ -488,7 +493,8 @@ int regmap_raw_write(struct regmap *map, uint offset, const void *val,
int regmap_write(struct regmap *map, uint offset, uint val)
{
- return regmap_raw_write(map, offset, &val, REGMAP_SIZE_32);
+ return regmap_raw_write(map, offset, &val,
+ map->width ? map->width : REGMAP_SIZE_32);
}
int regmap_update_bits(struct regmap *map, uint offset, uint mask, uint val)
diff --git a/include/regmap.h b/include/regmap.h
index c7dd240a74..9362d864c0 100644
--- a/include/regmap.h
+++ b/include/regmap.h
@@ -76,16 +76,28 @@ struct regmap_range {
};
struct regmap_bus;
-struct regmap_config;
+
+/**
+ * struct regmap_config - Configure the behaviour of a regmap
+ *
+ * @width: Width of the read/write operations. Defaults to
+ * REGMAP_SIZE_32 if set to 0.
+ */
+struct regmap_config {
+ enum regmap_size_t width;
+};
/**
* struct regmap - a way of accessing hardware/bus registers
*
+ * @width: Width of the read/write operations. Defaults to
+ * REGMAP_SIZE_32 if set to 0.
* @range_count: Number of ranges available within the map
* @ranges: Array of ranges
*/
struct regmap {
enum regmap_endianness_t endianness;
+ enum regmap_size_t width;
int range_count;
struct regmap_range ranges[0];
};
@@ -96,31 +108,27 @@ struct regmap {
*/
/**
- * regmap_write() - Write a 32-bit value to a regmap
+ * regmap_write() - Write a value to a regmap
*
* @map: Regmap to write to
* @offset: Offset in the regmap to write to
* @val: Data to write to the regmap at the specified offset
*
- * Note that this function will only write values of 32 bit width to the
- * regmap; if the size of data to be read is different, the regmap_raw_write
- * function can be used.
+ * If the map's width is not set, this function will write a 32-bit value.
*
* Return: 0 if OK, -ve on error
*/
int regmap_write(struct regmap *map, uint offset, uint val);
/**
- * regmap_read() - Read a 32-bit value from a regmap
+ * regmap_read() - Read a value from a regmap
*
* @map: Regmap to read from
* @offset: Offset in the regmap to read from
* @valp: Pointer to the buffer to receive the data read from the regmap
* at the specified offset
*
- * Note that this function will only read values of 32 bit width from the
- * regmap; if the size of data to be read is different, the regmap_raw_read
- * function can be used.
+ * If the map's width is not set, this function will read a 32-bit value.
*
* Return: 0 if OK, -ve on error
*/
@@ -344,7 +352,7 @@ int regmap_init_mem_index(ofnode node, struct regmap **mapp, int index);
* @dev: Device that will be interacted with
* @bus: Bus-specific callbacks to use with device (IGNORED)
* @bus_context: Data passed to bus-specific callbacks (IGNORED)
- * @config: Configuration for register map (IGNORED)
+ * @config: Configuration for register map
*
* @Return a valid pointer to a struct regmap or a ERR_PTR() on error.
* The structure is automatically freed when the device is unbound