diff mbox series

[U-Boot,v2,1/2] regmap: add regmap_update_bits() helper

Message ID 1524822975-22120-2-git-send-email-narmstrong@baylibre.com
State Accepted
Commit 285cbcf97f2b1dcadedb6835b3e9662c7fba0fe2
Delegated to: Tom Rini
Headers show
Series regmap: add regmap_update_bits and sandbox R/W test | expand

Commit Message

Neil Armstrong April 27, 2018, 9:56 a.m. UTC
Add the regmap_update_bits() to simply the read/modify/write of registers
in a single command. The function is taken from Linux regmap
implementation.

Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
---
 drivers/core/regmap.c | 14 ++++++++++++++
 include/regmap.h      | 10 ++++++++++
 2 files changed, 24 insertions(+)

Comments

Simon Glass April 30, 2018, 11:12 p.m. UTC | #1
Hi Neil,

On 27 April 2018 at 03:56, Neil Armstrong <narmstrong@baylibre.com> wrote:
>
> Add the regmap_update_bits() to simply the read/modify/write of registers
> in a single command. The function is taken from Linux regmap
> implementation.
>
> Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
> ---
>  drivers/core/regmap.c | 14 ++++++++++++++
>  include/regmap.h      | 10 ++++++++++
>  2 files changed, 24 insertions(+)

Reviewed-by: Simon Glass <sjg@chromium.org>

nit below:

>
> diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c
> index 8a0e00f..9fae252 100644
> --- a/drivers/core/regmap.c
> +++ b/drivers/core/regmap.c
> @@ -147,3 +147,17 @@ int regmap_write(struct regmap *map, uint offset, uint val)
>
>         return 0;
>  }
> +
> +int regmap_update_bits(struct regmap *map, uint offset, uint mask, uint val)
> +{
> +       uint reg;
> +       int ret;
> +
> +       ret = regmap_read(map, offset, &reg);
> +       if (ret)
> +               return ret;
> +
> +       reg &= ~mask;
> +
> +       return regmap_write(map, offset, reg | val);
> +}
> diff --git a/include/regmap.h b/include/regmap.h
> index 493a5d8..1349d40 100644
> --- a/include/regmap.h
> +++ b/include/regmap.h
> @@ -47,6 +47,16 @@ int regmap_read(struct regmap *map, uint offset, uint *valp);
>         regmap_read(map, (uint32_t *)(ptr)->member - (uint32_t *)(ptr), valp)
>
>  /**
> + * regmap_update_bits() - Perform a read/modify/write using a mask
> + *
> + * @map:       The map returned by regmap_init_mem*()
> + * @offset:    Offset of the memory
> + * @mask:      Mask to apply to the read value
> + * @val:       Value to apply to the value to write

How about 'Value to OR to the value to write"

> + */
> +int regmap_update_bits(struct regmap *map, uint offset, uint mask, uint val);
> +
> +/**
>   * regmap_init_mem() - Set up a new register map that uses memory access
>   *
>   * Use regmap_uninit() to free it.
> --
> 2.7.4
>

Regards,
Simon
Tom Rini May 8, 2018, 5:17 p.m. UTC | #2
On Fri, Apr 27, 2018 at 11:56:14AM +0200, Neil Armstrong wrote:

> Add the regmap_update_bits() to simply the read/modify/write of registers
> in a single command. The function is taken from Linux regmap
> implementation.
> 
> Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
> Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c
index 8a0e00f..9fae252 100644
--- a/drivers/core/regmap.c
+++ b/drivers/core/regmap.c
@@ -147,3 +147,17 @@  int regmap_write(struct regmap *map, uint offset, uint val)
 
 	return 0;
 }
+
+int regmap_update_bits(struct regmap *map, uint offset, uint mask, uint val)
+{
+	uint reg;
+	int ret;
+
+	ret = regmap_read(map, offset, &reg);
+	if (ret)
+		return ret;
+
+	reg &= ~mask;
+
+	return regmap_write(map, offset, reg | val);
+}
diff --git a/include/regmap.h b/include/regmap.h
index 493a5d8..1349d40 100644
--- a/include/regmap.h
+++ b/include/regmap.h
@@ -47,6 +47,16 @@  int regmap_read(struct regmap *map, uint offset, uint *valp);
 	regmap_read(map, (uint32_t *)(ptr)->member - (uint32_t *)(ptr), valp)
 
 /**
+ * regmap_update_bits() - Perform a read/modify/write using a mask
+ *
+ * @map:	The map returned by regmap_init_mem*()
+ * @offset:	Offset of the memory
+ * @mask:	Mask to apply to the read value
+ * @val:	Value to apply to the value to write
+ */
+int regmap_update_bits(struct regmap *map, uint offset, uint mask, uint val);
+
+/**
  * regmap_init_mem() - Set up a new register map that uses memory access
  *
  * Use regmap_uninit() to free it.