Hi Mario,

On 31 July 2018 at 04:01, Mario Six <mario....@gdsys.cc> wrote:
> The regmap functions currently assume that all register map accesses
> have a data width of 32 bits, but there are maps that have different
> widths.
>
> To rectify this, implement the regmap_raw_read and regmap_raw_write
> functions from the Linux kernel API that specify the width of a desired
> read or write operation on a regmap.
>
> Implement the regmap_read and regmap_write functions using these raw
> functions in a backwards-compatible manner.
>
> Signed-off-by: Mario Six <mario....@gdsys.cc>
> ---
>
> v2 -> v3:
> * Implement the "raw" functions from Linux instead of adding a size
>   parameter to the regmap_{read,write} functions
> * Fixed style violation
> * Improved error handling
>
> v1 -> v2:
> New in v2
>
> ---
>  drivers/core/regmap.c | 54 
> ++++++++++++++++++++++++++++++++++++++++++++-------
>  include/regmap.h      | 40 ++++++++++++++++++++++++++++++++++++++
>  2 files changed, 87 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c
> index 3488361ee14..83ca19a08a4 100644
> --- a/drivers/core/regmap.c
> +++ b/drivers/core/regmap.c
> @@ -188,22 +188,62 @@ int regmap_uninit(struct regmap *map)
>         return 0;
>  }
>
> +int regmap_raw_read(struct regmap *map, uint offset, void *valp, size_t 
> val_len)
> +{
> +       void *ptr;
> +
> +       ptr = map_physmem(map->ranges[0] + offset, val_len, MAP_NOCACHE);
> +
> +       switch (val_len) {
> +       case REGMAP_SIZE_8:
> +               *((u8 *)valp) = in_8((u8 *)ptr);
> +               break;
> +       case REGMAP_SIZE_16:
> +               *((u16 *)valp) = in_le16((u16 *)ptr);
> +               break;
> +       case REGMAP_SIZE_32:
> +               *((u32 *)valp) = in_le32((u32 *)ptr);
> +               break;
> +       default:
> +               debug("%s: regmap size %u unknown\n", __func__, val_len);
> +               return -EINVAL;
> +       }
> +       return 0;
> +}
> +
>  int regmap_read(struct regmap *map, uint offset, uint *valp)
>  {
> -       u32 *ptr = map_physmem(map->ranges[0].start + offset, 4, MAP_NOCACHE);
> +       return regmap_raw_read(map, offset, valp, REGMAP_SIZE_32);
> +}
>
> -       *valp = le32_to_cpu(readl(ptr));
> +int regmap_raw_write(struct regmap *map, uint offset, const void *val,
> +                    size_t val_len)
> +{
> +       void *ptr;
> +
> +       ptr = map_physmem(map->ranges[0] + offset, val_len, MAP_NOCACHE);
> +
> +       switch (val_len) {
> +       case REGMAP_SIZE_8:
> +               out_8((u8 *)ptr, *((u8 *)val));
> +               break;
> +       case REGMAP_SIZE_16:
> +               out_le16((u16 *)ptr, *((u16 *)val));
> +               break;
> +       case REGMAP_SIZE_32:
> +               out_le32((u32 *)ptr, *((u32 *)val));
> +               break;
> +       default:
> +               debug("%s: regmap size %u unknown\n", __func__, val_len);
> +               return -EINVAL;
> +       }
>
>         return 0;
>  }
>
>  int regmap_write(struct regmap *map, uint offset, uint val)
>  {
> -       u32 *ptr = map_physmem(map->ranges[0].start + offset, 4, MAP_NOCACHE);
> -
> -       writel(cpu_to_le32(val), ptr);
> -
> -       return 0;
> +       return regmap_raw_write(map, offset, &val, 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 32f75e06f59..352851c715b 100644
> --- a/include/regmap.h
> +++ b/include/regmap.h
> @@ -8,6 +8,19 @@
>  #define __REGMAP_H
>
>  /**
> + * enum regmap_size_t - Access sizes for fpgamap reads and writes
> + *
> + * @REGMAP_SIZE_8: 8-bit read/write access size
> + * @REGMAP_SIZE_16: 16-bit read/write access size
> + * @REGMAP_SIZE_32: 32-bit read/write access size
> + */
> +enum regmap_size_t {
> +       REGMAP_SIZE_8 = 1,
> +       REGMAP_SIZE_16 = 2,
> +       REGMAP_SIZE_32 = 4,
> +};
> +
> +/**
>   * struct regmap_range - a register map range
>   *
>   * @start:     Start address
> @@ -57,6 +70,33 @@ int regmap_write(struct regmap *map, uint offset, uint 
> val);
>   */
>  int regmap_read(struct regmap *map, uint offset, uint *valp);
>
> +/**
> + * regmap_raw_write() - Write a value of specified length to a regmap
> + *

Please explain the meaning of 'raw' here. Also please update the
non-raw ones to explain that meaning.

> + * @map:       Regmap to write to
> + * @offset:    Offset in the regmap to write to
> + * @val:       Value to write to the regmap at the specified offset
> + * @val_len:   Length of the data to be written to the regmap
> + *
> + * Return: 0 if OK, -ve on error
> + */
> +int regmap_raw_write(struct regmap *map, uint offset, const void *val,
> +                    size_t val_len);
> +
> +/**
> + * regmap_raw_read() - Read a value of specified length from a regmap
> + *

Same here

> + * @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
> + * @val_len:   Length of the data to be read from the regmap
> + *
> + * Return: 0 if OK, -ve on error
> + */
> +int regmap_raw_read(struct regmap *map, uint offset, void *valp,
> +                   size_t val_len);
> +
>  #define regmap_write32(map, ptr, member, val) \
>         regmap_write(map, (uint32_t *)(ptr)->member - (uint32_t *)(ptr), val)
>
> --
> 2.11.0
>
_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot

Reply via email to