From patchwork Fri Sep 27 13:22:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Jacques Hiblot X-Patchwork-Id: 1168505 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=quarantine dis=none) header.from=ti.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ti.com header.i=@ti.com header.b="TRnGla7A"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 46fswV3X65z9sDB for ; Fri, 27 Sep 2019 23:24:58 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 139B8C21F9E; Fri, 27 Sep 2019 13:23:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 36927C21F90; Fri, 27 Sep 2019 13:23:18 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 6FDF6C21F9E; Fri, 27 Sep 2019 13:22:39 +0000 (UTC) Received: from fllv0016.ext.ti.com (fllv0016.ext.ti.com [198.47.19.142]) by lists.denx.de (Postfix) with ESMTPS id 0E404C21F6A for ; Fri, 27 Sep 2019 13:22:36 +0000 (UTC) Received: from fllv0035.itg.ti.com ([10.64.41.0]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id x8RDMSkN122783; Fri, 27 Sep 2019 08:22:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1569590548; bh=WBasmWIW+t24wLxZB/jODEm4hZSB8Llv3iF4N4vj0Ak=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=TRnGla7AK2JyLY+4S4N5HV6uaOjz73H89Ug16nMrYfDQewWLhq4RAoB6wJx6RJTs2 M3YqWf+67VJuaOC3L6pdPqVkn5Jgi6TldAf0sM+HvJytTS1NdrVP7RU/Mwd72w5NqU K9sVQYdtxEhSY376zOKmn4TCfD5iiEaN0YnSt1a8= Received: from DFLE101.ent.ti.com (dfle101.ent.ti.com [10.64.6.22]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTP id x8RDMSqC104239; Fri, 27 Sep 2019 08:22:28 -0500 Received: from DFLE111.ent.ti.com (10.64.6.32) by DFLE101.ent.ti.com (10.64.6.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Fri, 27 Sep 2019 08:22:27 -0500 Received: from lelv0327.itg.ti.com (10.180.67.183) 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.1713.5 via Frontend Transport; Fri, 27 Sep 2019 08:22:27 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by lelv0327.itg.ti.com (8.15.2/8.15.2) with ESMTP id x8RDMR1Z087199; Fri, 27 Sep 2019 08:22:27 -0500 From: Jean-Jacques Hiblot To: , Date: Fri, 27 Sep 2019 15:22:19 +0200 Message-ID: <20190927132221.17892-4-jjhiblot@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190927132221.17892-1-jjhiblot@ti.com> References: <20190927132221.17892-1-jjhiblot@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH v1 3/5] regmap: Allow providing read/write callbacks through struct regmap_config X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" Some linux drivers provide their own read/write functions to access data from/of the regmap. Adding support for it. Signed-off-by: Jean-Jacques Hiblot --- drivers/core/regmap.c | 12 ++++++++++++ include/regmap.h | 26 +++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c index f69ff6d12f..486eea7bd4 100644 --- a/drivers/core/regmap.c +++ b/drivers/core/regmap.c @@ -31,6 +31,9 @@ static struct regmap *regmap_alloc(int count) if (!map) return NULL; map->range_count = count; + map->bus_context = NULL; + map->reg_read = NULL; + map->reg_write = NULL; return map; } @@ -241,6 +244,9 @@ struct regmap *devm_regmap_init(struct udevice *dev, rc = regmap_init_mem(dev_ofnode(dev), mapp); if (rc) return ERR_PTR(rc); + (*mapp)->reg_read = config->reg_read; + (*mapp)->reg_write = config->reg_write; + (*mapp)->bus_context = bus_context; devres_add(dev, mapp); return *mapp; @@ -320,6 +326,9 @@ int regmap_raw_read_range(struct regmap *map, uint range_num, uint offset, struct regmap_range *range; void *ptr; + if (map->reg_read) + return map->reg_read(map->bus_context, offset, valp); + if (range_num >= map->range_count) { debug("%s: range index %d larger than range count\n", __func__, range_num); @@ -429,6 +438,9 @@ int regmap_raw_write_range(struct regmap *map, uint range_num, uint offset, struct regmap_range *range; void *ptr; + if (map->reg_write) + return map->reg_write(map->bus_context, offset, + *(unsigned int *)val); if (range_num >= map->range_count) { debug("%s: range index %d larger than range count\n", __func__, range_num); diff --git a/include/regmap.h b/include/regmap.h index 63a362d86d..cc0adf568b 100644 --- a/include/regmap.h +++ b/include/regmap.h @@ -74,16 +74,36 @@ struct regmap_range { }; struct regmap_bus; -struct regmap_config; +/** + * struct regmap_config - a way of accessing hardware/bus registers + * + * @reg_read: Optional callback that if filled will be used to perform + * all the reads from the registers. Should only be provided for + * devices whose read operation cannot be represented as a simple + * read operation on a bus such as SPI, I2C, etc. Most of the + * devices do not need this. + * @reg_write: Same as above for writing. + */ +struct regmap_config { + int (*reg_read)(void *context, unsigned int reg, unsigned int *val); + int (*reg_write)(void *context, unsigned int reg, unsigned int val); +}; /** * struct regmap - a way of accessing hardware/bus registers * * @range_count: Number of ranges available within the map * @ranges: Array of ranges + * @bus_context: Data passed to bus-specific callbacks + * @reg_read: Optional callback that if filled will be used to perform + * all the reads from the registers. + * @reg_write: Same as above for writing. */ struct regmap { enum regmap_endianness_t endianness; + void *bus_context; + int (*reg_read)(void *context, unsigned int reg, unsigned int *val); + int (*reg_write)(void *context, unsigned int reg, unsigned int val); int range_count; struct regmap_range ranges[0]; }; @@ -340,8 +360,8 @@ 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) + * @bus_context: Data passed to bus-specific callbacks + * @config: Configuration for register map * * The return value will be an ERR_PTR() on error or a valid pointer to * a struct regmap.