Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1434020ybb; Thu, 9 Apr 2020 01:59:32 -0700 (PDT) X-Google-Smtp-Source: APiQypIr30rJ29XOwRpptL13bGGV9tCcr2rxN5ZBZR3VEbtRH9RnscBNmgD9fGscwetjPEfB8BBD X-Received: by 2002:a9d:441:: with SMTP id 59mr547127otc.236.1586422771862; Thu, 09 Apr 2020 01:59:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586422771; cv=none; d=google.com; s=arc-20160816; b=MBU5XQ009mx1p/evXZxc/HD2AU/26vpW1b96p6h/qg8Pqah3HJa5EUWNuIXFBwFhQ2 j+SRxC1tdrnXdxXS7rE+kL7j5lcDeNGhnurfFixjlUyzX8nUnvfBDhM1kXQlmW27YJm1 6b0vuYO83Y7qJIVzmvVeOo/GkDdqAeiKFt9zQPrGFXF9y5jpUjpMWhFKjecIsFqUuv09 saXZilGdQwVSSL/4gfuNOS9R20/ZjzRwIFSfY3Vwkz0FrvGB+eW0rIIv1NuWM4WCFxPJ iOoFAV70I40MA6oU9iS3sOvvCuScmwhKns6ADEj71LGKdxEbZOYWnO1UDZgbMfXO4AY5 YTRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=oU1SD0/H2uFcMVlkfJZK0TPjnOK4yvBSFYiaVddiQBs=; b=C1pMD6jshpZVLIx+EJUBmVEBnkYF7EPiSSTTtzruuJiIa8Oo7xSnxr6ZZEHbqiBBQ0 HFfycFU7HzG0bsB9TEgM0iuSKUM5BNdMPOkHFxQ6vYeT72UwAKpJGwr3LAJwzzU303Fi 9R657kdFgrEdVKCt53FB46lzx1R2RsAyx5iuspq6SUvra9F3p9CAJurfDP3QNfI07KGw nwnjG2+JxP4jDNyKcr7TsuDBQTKDbhCCa2y57idjUY+fnhzbpxinrWmUmAdh0tIFFlEn WeIHnhJlnLX/PyGmQIO+iZNYYgck5d73deD3J8anYFR3yhHR9nTp4sYdqIYDmAr0uy6R si9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=eQB1quuu; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l13si3715194otl.78.2020.04.09.01.59.17; Thu, 09 Apr 2020 01:59:31 -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=@gmail.com header.s=20161025 header.b=eQB1quuu; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726718AbgDII6U (ORCPT + 99 others); Thu, 9 Apr 2020 04:58:20 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:45066 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725972AbgDII6U (ORCPT ); Thu, 9 Apr 2020 04:58:20 -0400 Received: by mail-pg1-f194.google.com with SMTP id w11so516306pga.12 for ; Thu, 09 Apr 2020 01:58:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=oU1SD0/H2uFcMVlkfJZK0TPjnOK4yvBSFYiaVddiQBs=; b=eQB1quuuNCnbuszNLZq5C4v9ObB3vpVxfyBN7YbqpY/tdFfJM0ZH+Z6kGaCU1KyCwA oQL5ILPSOB8OLPRrcnzMepJq//HqoJj0BsKCZNoBphaIxrjWrjZOemIRzQs4AR8B8Y4n xCTC0+VRhGafFP47eDaza5ZdZMKRU1A6pPswGprcH+9CjE94KA41CNnnDkx5/cYTaPBO 1s/ddv70jXS7M4oOKJ7sI+NEUhr7dP+aDrwaHip7Wcv1V0+aLuT5wUiRNOIJpSr5QeIJ HRf6OdsuFaaycPp+oFN5iIE7SdShy4iyS5/y8vHsRnpa22DXMA/IC16N0/4kboa+x5dV icMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=oU1SD0/H2uFcMVlkfJZK0TPjnOK4yvBSFYiaVddiQBs=; b=Iq0bVSYHPYub1zmpNWGA+VLC+lg78gIY1JjdPf1STpy4OlEFsLxk2GeRMYQinr1d3w 2zHqBcsCbQueOJXS//AdcHfsEi0h6muvgMLsdL74fjcTJVUSdIZkxzaHgW9qFJjd2hYC 2np353P7nlw9hh/l5JfukZtDRDIbOYJbxdkbyQU/8n5j/9bZ7zys21TvG0LkXyseKySe WDhxB6Z7uEuKyjYNqod/r4KATOzZZkxtuesFoELyWuvuJMImqPkBkA9WhIHjmCzoDKG/ KQJYt+aS/nRcLLVyoRy4n8nXxBcsDb9QLnCIiHCb0DwN8THu2LLvUEuaDv4Pk14K8eaB 0yEQ== X-Gm-Message-State: AGi0Pub9+n8BMxyoFiZy6kGsVAjmEKw/KhUhvMtyqOxHX30s35TV9L9m WmCburoPy2V+VQ5Fz8wCDywOIGqv X-Received: by 2002:a63:e708:: with SMTP id b8mr2703800pgi.128.1586422700609; Thu, 09 Apr 2020 01:58:20 -0700 (PDT) Received: from sh03840pcu.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id s9sm1561712pjr.5.2020.04.09.01.58.17 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Apr 2020 01:58:20 -0700 (PDT) From: Baolin Wang To: lee.jones@linaro.org, arnd@arndb.de, broonie@kernel.org Cc: orsonzhai@gmail.com, zhang.lyra@gmail.com, baolin.wang7@gmail.com, linux-kernel@vger.kernel.org Subject: [RFC PATCH 2/3] regmap: Add reg_update_bits() support Date: Thu, 9 Apr 2020 16:57:58 +0800 Message-Id: X-Mailer: git-send-email 1.9.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add reg_update_bits() support in case some platforms use a special method to update bits of registers. Signed-off-by: Baolin Wang --- drivers/base/regmap/regmap-mmio.c | 29 ++++++++++++++++++++++++++++- drivers/base/regmap/regmap.c | 1 + 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/drivers/base/regmap/regmap-mmio.c b/drivers/base/regmap/regmap-mmio.c index af967d8..dae0d28 100644 --- a/drivers/base/regmap/regmap-mmio.c +++ b/drivers/base/regmap/regmap-mmio.c @@ -24,6 +24,8 @@ struct regmap_mmio_context { unsigned int reg, unsigned int val); unsigned int (*reg_read)(struct regmap_mmio_context *ctx, unsigned int reg); + int (*reg_update_bits)(void *ctx, unsigned int reg, + unsigned int mask, unsigned int val); }; static int regmap_mmio_regbits_check(size_t reg_bits) @@ -188,6 +190,26 @@ static int regmap_mmio_read(void *context, unsigned int reg, unsigned int *val) return 0; } +static int regmap_mmio_update_bits(void *context, unsigned int reg, + unsigned int mask, unsigned int val) +{ + struct regmap_mmio_context *ctx = context; + int ret; + + if (!IS_ERR(ctx->clk)) { + ret = clk_enable(ctx->clk); + if (ret < 0) + return ret; + } + + ctx->reg_update_bits(ctx->regs, reg, mask, val); + + if (!IS_ERR(ctx->clk)) + clk_disable(ctx->clk); + + return 0; +} + static void regmap_mmio_free_context(void *context) { struct regmap_mmio_context *ctx = context; @@ -200,7 +222,7 @@ static void regmap_mmio_free_context(void *context) kfree(context); } -static const struct regmap_bus regmap_mmio = { +static struct regmap_bus regmap_mmio = { .fast_io = true, .reg_write = regmap_mmio_write, .reg_read = regmap_mmio_read, @@ -239,6 +261,11 @@ static struct regmap_mmio_context *regmap_mmio_gen_context(struct device *dev, ctx->val_bytes = config->val_bits / 8; ctx->clk = ERR_PTR(-ENODEV); + if (config->reg_update_bits) { + ctx->reg_update_bits = config->reg_update_bits; + regmap_mmio.reg_update_bits = regmap_mmio_update_bits; + } + switch (regmap_get_val_endian(dev, ®map_mmio, config)) { case REGMAP_ENDIAN_DEFAULT: case REGMAP_ENDIAN_LITTLE: diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index 59f911e..553d92a 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -827,6 +827,7 @@ struct regmap *__regmap_init(struct device *dev, } else if (!bus->read || !bus->write) { map->reg_read = _regmap_bus_reg_read; map->reg_write = _regmap_bus_reg_write; + map->reg_update_bits = bus->reg_update_bits; map->defer_caching = false; goto skip_format_initialization; -- 1.9.1