test: regmap: Increase size of syscon0 memory
Subsystems (3)
PATCH v6 1/14 test: regmap: Increase size of syscon0 memory
The upcoming changes to the regmap interface will contain a proper check for plausibility when reading/writing from/to a register map. To still have the current tests pass, increase the size of the memory region for the syscon0 device, since one of the tests reads and writes beyond this range.
---
v5 -> v6:
* Fix the test that checks the changed size
v4 -> v5:
No changes
v3 -> v4:
No changes
v2 -> v3:
New in v3
--- arch/sandbox/dts/test.dts | 2 +- test/dm/regmap.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
arch/sandbox/dts/test.dts +1 -1
@@ -439,7 +439,7 @@ syscon at 0 { compatible = "sandbox,syscon0"; - reg = <0x10 4>; + reg = <0x10 16>; }; syscon at 1 {
test/dm/regmap.c +1 -1
@@ -25,7 +25,7 @@ static int dm_test_regmap_base(struct unit_test_state *uts)ut_assertok_ptr (map);ut_asserteq (1 , map->range_count);ut_asserteq (0x10 , map->ranges[0 ].start); -ut_asserteq (4 , map->ranges[0 ].size); +ut_asserteq (16 , map->ranges[0 ].size);ut_asserteq (0x10 ,map_to_sysmem (regmap_get_range (map,0 )));ut_assertok (uclass_get_device (UCLASS_SYSCON ,1 , &dev));
--
2.11.0
PATCH v6 2/14 regmap: Fix documentation
The documentation in regmap.h is not in kernel-doc format. Correct this.
---
v5 -> v6:
No changes
v4 -> v5:
No changes
v3 -> v4:
No changes
v2 -> v3:
New in v3
--- include/regmap.h | 48 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 9 deletions(-)
include/regmap.h +39 -9
@@ -21,8 +21,8 @@ struct regmap_range {/** * struct regmap - a way of accessing hardware/bus registers * -* @range_count: Number of ranges available within the map -* @ranges: Array of ranges +* @range_count: Number of ranges available within the map +* @ranges: Array of ranges */ struct regmap {int range_count;
@@ -33,7 +33,28 @@ struct regmap {* Interface to provide access to registers either through a direct memory * bus or through a peripheral bus like I2C, SPI. */ + +/** +* regmap_write() - Write a 32-bit 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 +* +* 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 +* +* @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 +* +* Return: 0 if OK, -ve on error +*/ int regmap_read (struct regmap *map,uint offset,uint *valp);#define regmap_write32 (map, ptr, member, val) \
@@ -49,31 +70,36 @@ int regmap_read(struct regmap *map, uint offset, uint *valp);* @offset: Offset of the memory * @mask: Mask to apply to the read value * @val: Value to apply to the value to write +* Return: 0 if OK, -ve on error */ 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. -* * @node: Device node that uses this map * @mapp: Returns allocated map +* Return: 0 if OK, -ve on error +* +* Use regmap_uninit() to free it. */ int regmap_init_mem (ofnode node,struct regmap **mapp);/** -* regmap_init_mem_platdata() - Set up a new memory register map for of-platdata +* regmap_init_mem_platdata() - Set up a new memory register map for +* of-platdata +* +* @dev: Device that uses this map +* @reg: List of address, size pairs +* @count: Number of pairs (e.g. 1 if the regmap has a single entry) +* @mapp: Returns allocated map +* Return: 0 if OK, -ve on error * * This creates a new regmap with a list of regions passed in, rather than * using the device tree. It only supports 32-bit machines. * * Use regmap_uninit() to free it. * -* @dev: Device that uses this map -* @reg: List of address, size pairs -* @count: Number of pairs (e.g. 1 if the regmap has a single entry) -* @mapp: Returns allocated map */ int regmap_init_mem_platdata (struct udevice *dev,fdt_val_t *reg,int count,struct regmap **mapp);
@@ -83,11 +109,15 @@ int regmap_init_mem_platdata(struct udevice *dev, fdt_val_t *reg, int count,* * @map: Regmap to query * @range_num: Range to look up +* Return: Pointer to the range in question if OK, NULL on error */ void *regmap_get_range (struct regmap *map,unsigned int range_num);/** * regmap_uninit() - free a previously inited regmap +* +* @map: Regmap to free +* Return: 0 if OK, -ve on error */ int regmap_uninit (struct regmap *map);
--
2.11.0
PATCH v6 3/14 regmap: Add documentation
In reply to Mario SixDocument the regmap_alloc() function.
---
v5 -> v6:
No changes
v4 -> v5:
No changes
v3 -> v4:
No changes
v2 -> v3:
New in v3
--- drivers/core/regmap.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/core/regmap.c +6 -0
@@ -17,6 +17,12 @@DECLARE_GLOBAL_DATA_PTR ; +/** +* regmap_alloc() - Allocate a regmap with a given number of ranges. +* +* @count: Number of ranges to be allocated for the regmap. +* Return: A pointer to the newly allocated regmap, or NULL on error. +*/ static struct regmap *regmap_alloc (int count) {struct regmap *map;
--
2.11.0
PATCH v6 4/14 regmap: Improve error handling
In reply to Mario Sixofnode_read_simple_addr_cells may fail and return a negative error code. Check for this when initializing regmaps.
Also check if both_len is zero, since this is perfectly possible, and would lead to a division-by-zero further down the line.
---
v5 -> v6:
No changes
v4 -> v5:
No changes
v3 -> v4:
No changes
v2 -> v3:
New in v3
--- drivers/core/regmap.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
drivers/core/regmap.c +17 -0
@@ -67,8 +67,25 @@ int regmap_init_mem(ofnode node, struct regmap **mapp)struct resource r; addr_len =ofnode_read_simple_addr_cells (ofnode_get_parent (node)); +if (addr_len <0 ) { +debug ("%s: Error while reading the addr length (ret = %d)\n" , +ofnode_get_name (node), addr_len); +return addr_len; + } + size_len =ofnode_read_simple_size_cells (ofnode_get_parent (node)); +if (size_len <0 ) { +debug ("%s: Error while reading the size length: (ret = %d)\n" , +ofnode_get_name (node), size_len); +return size_len; + } + both_len = addr_len + size_len; +if (!both_len) { +debug ("%s: Both addr and size length are zero\n" , +ofnode_get_name (node)); +return -EINVAL ; + } len =ofnode_read_size (node,"reg" );if (len <0 )
--
2.11.0
PATCH v6 5/14 regmap: Introduce init_range
In reply to Mario SixBoth fdtdec_get_addr_size_fixed and of_address_to_resource can fail with an error, which is not currently checked during regmap initialization.
Since the indentation depth is already quite deep, extract a new 'init_range' method to do the initialization.
---
v5 -> v6:
No changes
v4 -> v5:
No changes
v3 -> v4:
* Introduced else clause in of_live_active() if statement to make the distinction between live and non-live cases clearer
v2 -> v3:
New in v3
--- drivers/core/regmap.c | 68 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 56 insertions(+), 12 deletions(-)
drivers/core/regmap.c +56 -12
@@ -56,6 +56,58 @@ int regmap_init_mem_platdata(struct udevice *dev, fdt_val_t *reg, int count,return 0 ; }#else +/** +* init_range() - Initialize a single range of a regmap +* @node: Device node that will use the map in question +* @range: Pointer to a regmap_range structure that will be initialized +* @addr_len: The length of the addr parts of the reg property +* @size_len: The length of the size parts of the reg property +* @index: The index of the range to initialize +* +* This function will read the necessary 'reg' information from the device tree +* (the 'addr' part, and the 'length' part), and initialize the range in +* quesion. +* +* Return: 0 if OK, -ve on error +*/ +static int init_range (ofnode node,struct regmap_range *range,int addr_len, +int size_len,int index) +{ +fdt_size_t sz; +struct resource r; + +if (of_live_active ()) { +int ret; + + ret =of_address_to_resource (ofnode_to_np (node), + index, &r); +if (ret) { +debug ("%s: Could not read resource of range %d (ret = %d)\n" , +ofnode_get_name (node), index, ret); +return ret; + } + + range->start = r.start; + range->size = r.end - r.start +1 ; + }else { +int offset =ofnode_to_offset (node); + + range->start =fdtdec_get_addr_size_fixed (gd->fdt_blob, offset, +"reg" , index, + addr_len, size_len, + &sz, true); +if (range->start ==FDT_ADDR_T_NONE ) { +debug ("%s: Could not read start of range %d\n" , +ofnode_get_name (node), index); +return -EINVAL ; + } + + range->size = sz; + } + +return 0 ; +} +int regmap_init_mem (ofnode node,struct regmap **mapp) {struct regmap_range *range;
@@ -64,7 +116,6 @@ int regmap_init_mem(ofnode node, struct regmap **mapp)int addr_len, size_len, both_len;int len;int index; -struct resource r; addr_len =ofnode_read_simple_addr_cells (ofnode_get_parent (node));if (addr_len <0 ) {
@@ -101,17 +152,10 @@ int regmap_init_mem(ofnode node, struct regmap **mapp)for (range = map->ranges, index =0 ; count >0 ; count--, range++, index++) { -fdt_size_t sz; -if (of_live_active ()) { -of_address_to_resource (ofnode_to_np (node), index, &r); - range->start = r.start; - range->size = r.end - r.start +1 ; - }else { - range->start =fdtdec_get_addr_size_fixed (gd->fdt_blob, -ofnode_to_offset (node),"reg" , index, - addr_len, size_len, &sz, true); - range->size = sz; - } +int ret =init_range (node, range, addr_len, size_len, index); + +if (ret) +return ret; } *mapp = map;
--
2.11.0
PATCH v6 6/14 regmap: Add error output
In reply to Mario SixAdd some debug output in cases where the initialization of a regmap fails.
---
v5 -> v6:
No changes
v4 -> v5:
No changes
v3 -> v4:
No changes
v2 -> v3:
New in v3
--- drivers/core/regmap.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/core/regmap.c +8 -2
@@ -139,12 +139,18 @@ int regmap_init_mem(ofnode node, struct regmap **mapp) } len =ofnode_read_size (node,"reg" ); -if (len <0 ) +if (len <0 ) { +debug ("%s: Error while reading reg size (ret = %d)\n" , +ofnode_get_name (node), len);return len; + } len /=sizeof (fdt32_t); count = len / both_len; -if (!count) +if (!count) { +debug ("%s: Not enough data in reg property\n" , +ofnode_get_name (node));return -EINVAL ; + } map =regmap_alloc (count);if (!map)
--
2.11.0
PATCH v6 7/14 mips: Implement {in, out}_{le, be}_{16, 32, 64} and {in, out}_8
In reply to Mario SixMIPS is the only architecture currently supported by U-Boot that does not implement any of the in/out register access functions.
To have a interface that is useable across architectures, add the functions to the MIPS architecture (implemented using the __raw_write and __raw_read functions).
---
v5 -> v6:
New in v6
--- arch/mips/include/asm/io.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
arch/mips/include/asm/io.h +22 -0
@@ -547,6 +547,28 @@ __BUILD_CLRSETBITS(bwlq, sfx, end, type)#define __to_cpu (v) (v)#define cpu_to__ (v) (v) +#define out_arch (type, endian, a, v) __raw_write##type(cpu_to_##endian(v),a) +#define in_arch (type, endian, a) endian##_to_cpu(__raw_read##type(a)) + +#define out_le64 (a, v) out_arch(q, le64, a, v) +#define out_le32 (a, v) out_arch(l, le32, a, v) +#define out_le16 (a, v) out_arch(w, le16, a, v) + +#define in_le64 (a) in_arch(q, le64, a) +#define in_le32 (a) in_arch(l, le32, a) +#define in_le16 (a) in_arch(w, le16, a) + +#define out_be64 (a, v) out_arch(q, be64, a, v) +#define out_be32 (a, v) out_arch(l, be32, a, v) +#define out_be16 (a, v) out_arch(w, be16, a, v) + +#define in_be64 (a) in_arch(q, be64, a) +#define in_be32 (a) in_arch(l, be32, a) +#define in_be16 (a) in_arch(w, be16, a) + +#define out_8 (a, v) __raw_writeb(v, a) +#define in_8 (a) __raw_readb(a) + BUILD_CLRSETBITS(b, 8, _, u8) BUILD_CLRSETBITS(w, le16, le16, u16)BUILD_CLRSETBITS (w, be16, be16, u16)
--
2.11.0
PATCH v6 8/14 regmap: Add raw read/write functions
In reply to Mario SixThe 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.
---
v5 -> v6:
* Corrected format specifier
* Added support for 64-bit reads/writes
v4 -> v5:
No changes
v3 -> v4:
* Switched 'ranges[0] + offset' to 'ranges[0].start + offset'
* Explained the difference between the raw and non-raw read/write functions better in the docs
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 | 59 +++++++++++++++++++++++++++++++++++++++++++++------ include/regmap.h | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+), 7 deletions(-)
drivers/core/regmap.c +52 -7
@@ -188,22 +188,67 @@ 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 ].start + 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 ; +#if defined(in_le64) && defined(readq) +case REGMAP_SIZE_64 : + *((u32 *)valp) =in_le64 ((u64 *)ptr); +break ; +#endif +default : +debug ("%s: regmap size %zu 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 ].start + 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 %zu 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)
include/regmap.h +58 -0
80 lines not on this page · raw message
--
2.11.0
PATCH v6 8/14 regmap: Add raw read/write functions
Hi Mario,
Quoted 59 lines · Mario Six
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_readandregmap_raw_writefunctions from the Linux kernel API that specify the width of a desired read or write operation on a regmap.Implement the
regmap_readandregmap_writefunctions using these raw functions in a backwards-compatible manner.Reviewed-by Anatolij Gustschin <[email protected]>Signed-off-by Mario Six <[email protected]>---
v5 -> v6:
* Corrected format specifier
* Added support for 64-bit reads/writesv4 -> v5:
No changesv3 -> v4:
* Switched 'ranges[0] + offset' to 'ranges[0].start + offset'
* Explained the difference between the raw and non-raw read/write functions better in the docsv2 -> v3:
* Implement the "raw" functions from Linux instead of adding a size parameter to the regmap_{read,write} functions
* Fixed style violation
* Improved error handlingv1 -> v2:
New in v2--- drivers/core/regmap.c | 59 +++++++++++++++++++++++++++++++++++++++++++++------ include/regmap.h | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+), 7 deletions(-)drivers/core/regmap.c +9
-0@@ -188,22 +188,67 @@ 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 ].start + offset, val_len,MAP_NOCACHE ); + +switch (val_len) { +case REGMAP_SIZE_8 : + *((u8 *)valp) =in_8 ((u8 *)ptr);
drivers/core/regmap.c int regmap_uninit(struct regmap *map) · line 209
Quoted 10 lines
drivers/core/regmap.c +10
-0+break ; +case REGMAP_SIZE_16 : + *((u16 *)valp) =in_le16 ((u16 *)ptr); +break ; +case REGMAP_SIZE_32 : + *((u32 *)valp) =in_le32 ((u32 *)ptr); +break ; +#if defined(in_le64) && defined(readq) +case REGMAP_SIZE_64 : + *((u32 *)valp) =in_le64 ((u64 *)ptr);
How come this is u32? Can you please add a comment?
Why is this using in/out rather than read/write? Does it not support memory-mapped I/O?
Quoted 23 lines
drivers/core/regmap.c +18
-2+break ; +#endif +default : +debug ("%s: regmap size %zu 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 ].start + offset, val_len,MAP_NOCACHE ); +
drivers/core/regmap.c int regmap_uninit(struct regmap *map) · line 240
Quoted 10 lines
drivers/core/regmap.c +10
-0+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 ;
No 64-bit?
Quoted 107 lines
drivers/core/regmap.c +5
-5+default : +debug ("%s: regmap size %zu 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)include/regmap.h +58
-1@@ -8,6 +8,21 @@#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 +* @REGMAP_SIZE_64: 64-bit read/write access size +*/ +enum regmap_size_t { +REGMAP_SIZE_8 =1 , +REGMAP_SIZE_16 =2 , +REGMAP_SIZE_32 =4 , +REGMAP_SIZE_64 =8 , +}; + +/** * struct regmap_range - a register map range * * @start: Start address @@ -41,6 +56,10 @@ struct regmap {* @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. +* * Return: 0 if OK, -ve on error */ int regmap_write (struct regmap *map,uint offset,uint val);@@ -53,10 +72,49 @@ int regmap_write(struct regmap *map, uint offset, uint val);* @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. +* * Return: 0 if OK, -ve on error */ int regmap_read (struct regmap *map,uint offset,uint *valp); +/** +* regmap_raw_write() - Write a value of specified length to a regmap +* +* @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 +* +* Note that this function will, as opposed to regmap_write, write data of +* arbitrary length to the regmap, and not just 32-bit values, and is thus a +* generalized version of regmap_write. +* +* 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 +* +* @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 +* +* Note that this function will, as opposed to regmap_read, read data of +* arbitrary length from the regmap, and not just 32-bit values, and is thus a +* generalized version of regmap_read. +* +* 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) --
Quoted 2 lines
2.11.0
Regards,
Simon
PATCH v6 8/14 regmap: Add raw read/write functions
Hi Simon,
Quoted 67 lines · Simon Glass
Hi Mario,
Quoted 63 lines · Mario Six
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_readandregmap_raw_writefunctions from the Linux kernel API that specify the width of a desired read or write operation on a regmap.Implement the
regmap_readandregmap_writefunctions using these raw functions in a backwards-compatible manner.Reviewed-by Anatolij Gustschin <[email protected]>Signed-off-by Mario Six <[email protected]>---
v5 -> v6:
* Corrected format specifier
* Added support for 64-bit reads/writesv4 -> v5:
No changesv3 -> v4:
* Switched 'ranges[0] + offset' to 'ranges[0].start + offset'
* Explained the difference between the raw and non-raw read/write functions better in the docsv2 -> v3:
* Implement the "raw" functions from Linux instead of adding a size parameter to the regmap_{read,write} functions
* Fixed style violation
* Improved error handlingv1 -> v2:
New in v2--- drivers/core/regmap.c | 59 +++++++++++++++++++++++++++++++++++++++++++++------ include/regmap.h | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+), 7 deletions(-)drivers/core/regmap.c +13
-0@@ -188,22 +188,67 @@ 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 ].start + 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 ;
Quoted 9 lines
drivers/core/regmap.c int regmap_uninit(struct regmap *map) · line 209
Quoted 6 lines
drivers/core/regmap.c +6
-0+case REGMAP_SIZE_32 : + *((u32 *)valp) =in_le32 ((u32 *)ptr); +break ; +#if defined(in_le64) && defined(readq) +case REGMAP_SIZE_64 : + *((u32 *)valp) =in_le64 ((u64 *)ptr);How come this is u32? Can you please add a comment?
That was a development version of the patch, sorry (I was in a bit of a hurry).
I'll send a corrected version with v7.
Quoted 3 lines
Why is this using in/out rather than read/write? Does it not support memory-mapped I/O?
It does, but I think the endianness of the read/write operations of the regmap should not depend on the architecture, but only on the regmap itself (which is little-endian for now; big-endian support can be introduced later on), so I used in/out rather than read/write.
Quoted 27 lines
Quoted 27 lines
drivers/core/regmap.c +22
-2+break ; +#endif +default : +debug ("%s: regmap size %zu 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 ].start + offset, val_len,MAP_NOCACHE ); + +switch (val_len) { +case REGMAP_SIZE_8 : +out_8 ((u8 *)ptr, *((u8 *)val)); +break ;
Quoted 9 lines
drivers/core/regmap.c int regmap_uninit(struct regmap *map) · line 240
Quoted 6 lines
drivers/core/regmap.c +6
-0+case REGMAP_SIZE_16 : +out_le16 ((u16 *)ptr, *((u16 *)val)); +break ; +case REGMAP_SIZE_32 : +out_le32 ((u32 *)ptr, *((u32 *)val)); +break ;No 64-bit?
See above; half-finished version of the patch.
Quoted 106 lines
Quoted 106 lines
drivers/core/regmap.c +5
-5+default : +debug ("%s: regmap size %zu 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)include/regmap.h +58
-0@@ -8,6 +8,21 @@#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 +* @REGMAP_SIZE_64: 64-bit read/write access size +*/ +enum regmap_size_t { +REGMAP_SIZE_8 =1 , +REGMAP_SIZE_16 =2 , +REGMAP_SIZE_32 =4 , +REGMAP_SIZE_64 =8 , +}; + +/** * struct regmap_range - a register map range * * @start: Start address @@ -41,6 +56,10 @@ struct regmap {* @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. +* * Return: 0 if OK, -ve on error */ int regmap_write (struct regmap *map,uint offset,uint val);@@ -53,10 +72,49 @@ int regmap_write(struct regmap *map, uint offset, uint val);* @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. +* * Return: 0 if OK, -ve on error */ int regmap_read (struct regmap *map,uint offset,uint *valp); +/** +* regmap_raw_write() - Write a value of specified length to a regmap +* +* @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 +* +* Note that this function will, as opposed to regmap_write, write data of +* arbitrary length to the regmap, and not just 32-bit values, and is thus a +* generalized version of regmap_write. +* +* 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 +* +* @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 +* +* Note that this function will, as opposed to regmap_read, read data of +* arbitrary length from the regmap, and not just 32-bit values, and is thus a +* generalized version of regmap_read. +* +* 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)
Quoted 7 lines
Quoted 3 lines
--
2.11.0Regards,
Simon
Best regards,
Mario
PATCH v6 8/14 regmap: Add raw read/write functions
Hi Mario,
Quoted 85 lines · Mario Six
Hi Simon,
Quoted 67 lines · Simon Glass
Hi Mario,
Quoted 63 lines · Mario Six
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_readandregmap_raw_writefunctions from the Linux kernel API that specify the width of a desired read or write operation on a regmap.Implement the
regmap_readandregmap_writefunctions using these raw functions in a backwards-compatible manner.Reviewed-by Anatolij Gustschin <[email protected]>Signed-off-by Mario Six <[email protected]>---
v5 -> v6:
* Corrected format specifier
* Added support for 64-bit reads/writesv4 -> v5:
No changesv3 -> v4:
* Switched 'ranges[0] + offset' to 'ranges[0].start + offset'
* Explained the difference between the raw and non-raw read/write functions better in the docsv2 -> v3:
* Implement the "raw" functions from Linux instead of adding a size parameter to the regmap_{read,write} functions
* Fixed style violation
* Improved error handlingv1 -> v2:
New in v2--- drivers/core/regmap.c | 59 +++++++++++++++++++++++++++++++++++++++++++++------ include/regmap.h | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+), 7 deletions(-)drivers/core/regmap.c +13
-0@@ -188,22 +188,67 @@ 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 ].start + 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 ;Quoted 9 lines
drivers/core/regmap.c int regmap_uninit(struct regmap *map) · line 209
Quoted 6 lines
drivers/core/regmap.c +6
-0+case REGMAP_SIZE_32 : + *((u32 *)valp) =in_le32 ((u32 *)ptr); +break ; +#if defined(in_le64) && defined(readq) +case REGMAP_SIZE_64 : + *((u32 *)valp) =in_le64 ((u64 *)ptr);How come this is u32? Can you please add a comment?
That was a development version of the patch, sorry (I was in a bit of a hurry).
I'll send a corrected version with v7.
Quoted 8 lines
Quoted 3 lines
Why is this using in/out rather than read/write? Does it not support memory-mapped I/O?
It does, but I think the endianness of the read/write operations of the regmap should not depend on the architecture, but only on the regmap itself (which is little-endian for now; big-endian support can be introduced later on), so I used in/out rather than read/write.
What does endianness have to do with whether you use readl/writel or in/out?
On x86 at least these are actually different things, so regmap() won't work on x86 with this change.
Adding Bin who may understand this better.
Regards,
Simon
PATCH v6 8/14 regmap: Add raw read/write functions
Quoted 98 lines · Simon Glass
Hi Mario,
Quoted 93 lines · Mario Six
Hi Simon,
Quoted 67 lines · Simon Glass
Hi Mario,
Quoted 63 lines · Mario Six
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_readandregmap_raw_writefunctions from the Linux kernel API that specify the width of a desired read or write operation on a regmap.Implement the
regmap_readandregmap_writefunctions using these raw functions in a backwards-compatible manner.Reviewed-by Anatolij Gustschin <[email protected]>Signed-off-by Mario Six <[email protected]>---
v5 -> v6:
* Corrected format specifier
* Added support for 64-bit reads/writesv4 -> v5:
No changesv3 -> v4:
* Switched 'ranges[0] + offset' to 'ranges[0].start + offset'
* Explained the difference between the raw and non-raw read/write functions better in the docsv2 -> v3:
* Implement the "raw" functions from Linux instead of adding a size parameter to the regmap_{read,write} functions
* Fixed style violation
* Improved error handlingv1 -> v2:
New in v2--- drivers/core/regmap.c | 59 +++++++++++++++++++++++++++++++++++++++++++++------ include/regmap.h | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+), 7 deletions(-)drivers/core/regmap.c +13
-0@@ -188,22 +188,67 @@ 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 ].start + 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 ;Quoted 9 lines
drivers/core/regmap.c int regmap_uninit(struct regmap *map) · line 209
Quoted 6 lines
drivers/core/regmap.c +6
-0+case REGMAP_SIZE_32 : + *((u32 *)valp) =in_le32 ((u32 *)ptr); +break ; +#if defined(in_le64) && defined(readq) +case REGMAP_SIZE_64 : + *((u32 *)valp) =in_le64 ((u64 *)ptr);How come this is u32? Can you please add a comment?
That was a development version of the patch, sorry (I was in a bit of a hurry).
I'll send a corrected version with v7.
Quoted 3 lines
Why is this using in/out rather than read/write? Does it not support memory-mapped I/O?
It does, but I think the endianness of the read/write operations of the regmap should not depend on the architecture, but only on the regmap itself (which is little-endian for now; big-endian support can be introduced later on), so I used in/out rather than read/write.
If regmap currently only supports little-endian, can we document this somewhere?
Quoted 5 lines
What does endianness have to do with whether you use readl/writel or in/out?
On x86 at least these are actually different things, so
regmap()won't work on x86 with this change.
Looks so far x86's {in,out}_{8,16,32} are using MMIO.
Quoted 1 line
Adding Bin who may understand this better.
BTW: I was trying to understand why we need regmap here. Shouldn't the driver directly call {in,out}{bwl}, or {read,write}{bwlq} APIs?
Regards,
Bin
PATCH v6 8/14 regmap: Add raw read/write functions
Hi Bin,
Quoted 95 lines · Bin Meng
Quoted 93 lines · Simon Glass
Hi Mario,
Quoted 89 lines · Mario Six
Hi Simon,
Quoted 67 lines · Simon Glass
Hi Mario,
Quoted 63 lines · Mario Six
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_readandregmap_raw_writefunctions from the Linux kernel API that specify the width of a desired read or write operation on a regmap.Implement the
regmap_readandregmap_writefunctions using these raw functions in a backwards-compatible manner.Reviewed-by Anatolij Gustschin <[email protected]>Signed-off-by Mario Six <[email protected]>---
v5 -> v6:
* Corrected format specifier
* Added support for 64-bit reads/writesv4 -> v5:
No changesv3 -> v4:
* Switched 'ranges[0] + offset' to 'ranges[0].start + offset'
* Explained the difference between the raw and non-raw read/write functions better in the docsv2 -> v3:
* Implement the "raw" functions from Linux instead of adding a size parameter to the regmap_{read,write} functions
* Fixed style violation
* Improved error handlingv1 -> v2:
New in v2--- drivers/core/regmap.c | 59 +++++++++++++++++++++++++++++++++++++++++++++------ include/regmap.h | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+), 7 deletions(-)drivers/core/regmap.c +13
-0@@ -188,22 +188,67 @@ 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 ].start + 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 ;Quoted 9 lines
drivers/core/regmap.c int regmap_uninit(struct regmap *map) · line 209
Quoted 6 lines
drivers/core/regmap.c +6
-0+case REGMAP_SIZE_32 : + *((u32 *)valp) =in_le32 ((u32 *)ptr); +break ; +#if defined(in_le64) && defined(readq) +case REGMAP_SIZE_64 : + *((u32 *)valp) =in_le64 ((u64 *)ptr);How come this is u32? Can you please add a comment?
That was a development version of the patch, sorry (I was in a bit of a hurry).
I'll send a corrected version with v7.
Quoted 3 lines
Why is this using in/out rather than read/write? Does it not support memory-mapped I/O?
Quoted 8 lines
Quoted 5 lines
Quoted 4 lines
It does, but I think the endianness of the read/write operations of the regmap should not depend on the architecture, but only on the regmap itself (which is little-endian for now; big-endian support can be introduced later on), so I used in/out rather than read/write.
If regmap currently only supports little-endian, can we document this somewhere?
Yes, good idea. I'll send a v7 to address this.
Quoted 6 lines
Quoted 5 lines
What does endianness have to do with whether you use readl/writel or in/out?
On x86 at least these are actually different things, so
regmap()won't work on x86 with this change.
Quoted 7 lines
Looks so far x86's {in,out}_{8,16,32} are using MMIO.
Quoted 1 line
Adding Bin who may understand this better.
BTW: I was trying to understand why we need regmap here. Shouldn't the driver directly call {in,out}{bwl}, or {read,write}{bwlq} APIs?
In this version of the FPGA driver, the regmap is not strictly needed, true. But we also have devices that have multiple FPGAs where the "slave" FPGA's register maps are accessed through a custom bus interface (called MCLink) on the first "master FPGA". With the regmap, I'll be able to use the same driver for both, all that's needed is another version of regmap for the MCLink bus. So the regmap is really there for forward-compatibility reasons.
Quoted 3 lines
Regards,
Bin
Best regards,
Mario
PATCH v6 8/14 regmap: Add raw read/write functions
Hi Mario,
Quoted 122 lines · Mario Six
Hi Bin,
Quoted 95 lines · Bin Meng
Quoted 93 lines · Simon Glass
Hi Mario,
Quoted 89 lines · Mario Six
Hi Simon,
Quoted 67 lines · Simon Glass
Hi Mario,
Quoted 63 lines · Mario Six
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_readandregmap_raw_writefunctions from the Linux kernel API that specify the width of a desired read or write operation on a regmap.Implement the
regmap_readandregmap_writefunctions using these raw functions in a backwards-compatible manner.Reviewed-by Anatolij Gustschin <[email protected]>Signed-off-by Mario Six <[email protected]>---
v5 -> v6:
* Corrected format specifier
* Added support for 64-bit reads/writesv4 -> v5:
No changesv3 -> v4:
* Switched 'ranges[0] + offset' to 'ranges[0].start + offset'
* Explained the difference between the raw and non-raw read/write functions better in the docsv2 -> v3:
* Implement the "raw" functions from Linux instead of adding a size parameter to the regmap_{read,write} functions
* Fixed style violation
* Improved error handlingv1 -> v2:
New in v2--- drivers/core/regmap.c | 59 +++++++++++++++++++++++++++++++++++++++++++++------ include/regmap.h | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+), 7 deletions(-)drivers/core/regmap.c +13
-0@@ -188,22 +188,67 @@ 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 ].start + 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 ;Quoted 9 lines
drivers/core/regmap.c int regmap_uninit(struct regmap *map) · line 209
Quoted 6 lines
drivers/core/regmap.c +6
-0+case REGMAP_SIZE_32 : + *((u32 *)valp) =in_le32 ((u32 *)ptr); +break ; +#if defined(in_le64) && defined(readq) +case REGMAP_SIZE_64 : + *((u32 *)valp) =in_le64 ((u64 *)ptr);How come this is u32? Can you please add a comment?
That was a development version of the patch, sorry (I was in a bit of a hurry).
I'll send a corrected version with v7.
Quoted 3 lines
Why is this using in/out rather than read/write? Does it not support memory-mapped I/O?
Quoted 8 lines
Quoted 5 lines
Quoted 4 lines
It does, but I think the endianness of the read/write operations of the regmap should not depend on the architecture, but only on the regmap itself (which is little-endian for now; big-endian support can be introduced later on), so I used in/out rather than read/write.
If regmap currently only supports little-endian, can we document this somewhere?
Yes, good idea. I'll send a v7 to address this.
Quoted 6 lines
Quoted 5 lines
What does endianness have to do with whether you use readl/writel or in/out?
On x86 at least these are actually different things, so
regmap()won't work on x86 with this change.Quoted 7 lines
Looks so far x86's {in,out}_{8,16,32} are using MMIO.
Quoted 1 line
Adding Bin who may understand this better.
BTW: I was trying to understand why we need regmap here. Shouldn't the driver directly call {in,out}{bwl}, or {read,write}{bwlq} APIs?
Quoted 6 lines
In this version of the FPGA driver, the regmap is not strictly needed, true. But we also have devices that have multiple FPGAs where the "slave" FPGA's register maps are accessed through a custom bus interface (called MCLink) on the first "master FPGA". With the regmap, I'll be able to use the same driver for both, all that's needed is another version of regmap for the MCLink bus. So the regmap is really there for forward-compatibility reasons.
Ah, I see. Thanks for the clarification. So I suspect if the same FPGA someday is connected to I2C, or SPI, the same driver can be used without any issue. In such case, the regmap can be very helpfu. Isn't such documented anywhere in U-Boot's source codes to help people understand? If not, I suggest we can improve something :)
Regards,
Bin
PATCH v6 8/14 regmap: Add raw read/write functions
Hi Bin,
Quoted 133 lines · Bin Meng
Hi Mario,
Quoted 122 lines · Mario Six
Hi Bin,
Quoted 95 lines · Bin Meng
Quoted 93 lines · Simon Glass
Hi Mario,
Quoted 89 lines · Mario Six
Hi Simon,
Quoted 67 lines · Simon Glass
Hi Mario,
Quoted 63 lines · Mario Six
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_readandregmap_raw_writefunctions from the Linux kernel API that specify the width of a desired read or write operation on a regmap.Implement the
regmap_readandregmap_writefunctions using these raw functions in a backwards-compatible manner.Reviewed-by Anatolij Gustschin <[email protected]>Signed-off-by Mario Six <[email protected]>---
v5 -> v6:
* Corrected format specifier
* Added support for 64-bit reads/writesv4 -> v5:
No changesv3 -> v4:
* Switched 'ranges[0] + offset' to 'ranges[0].start + offset'
* Explained the difference between the raw and non-raw read/write functions better in the docsv2 -> v3:
* Implement the "raw" functions from Linux instead of adding a size parameter to the regmap_{read,write} functions
* Fixed style violation
* Improved error handlingv1 -> v2:
New in v2--- drivers/core/regmap.c | 59 +++++++++++++++++++++++++++++++++++++++++++++------ include/regmap.h | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+), 7 deletions(-)drivers/core/regmap.c +13
-0@@ -188,22 +188,67 @@ 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 ].start + 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 ;Quoted 9 lines
drivers/core/regmap.c int regmap_uninit(struct regmap *map) · line 209
Quoted 6 lines
drivers/core/regmap.c +6
-0+case REGMAP_SIZE_32 : + *((u32 *)valp) =in_le32 ((u32 *)ptr); +break ; +#if defined(in_le64) && defined(readq) +case REGMAP_SIZE_64 : + *((u32 *)valp) =in_le64 ((u64 *)ptr);How come this is u32? Can you please add a comment?
That was a development version of the patch, sorry (I was in a bit of a hurry).
I'll send a corrected version with v7.
Quoted 3 lines
Why is this using in/out rather than read/write? Does it not support memory-mapped I/O?
Quoted 8 lines
Quoted 5 lines
Quoted 4 lines
It does, but I think the endianness of the read/write operations of the regmap should not depend on the architecture, but only on the regmap itself (which is little-endian for now; big-endian support can be introduced later on), so I used in/out rather than read/write.
If regmap currently only supports little-endian, can we document this somewhere?
Yes, good idea. I'll send a v7 to address this.
Quoted 6 lines
Quoted 5 lines
What does endianness have to do with whether you use readl/writel or in/out?
On x86 at least these are actually different things, so
regmap()won't work on x86 with this change.Quoted 7 lines
Looks so far x86's {in,out}_{8,16,32} are using MMIO.
Quoted 1 line
Adding Bin who may understand this better.
BTW: I was trying to understand why we need regmap here. Shouldn't the driver directly call {in,out}{bwl}, or {read,write}{bwlq} APIs?
Quoted 6 lines
In this version of the FPGA driver, the regmap is not strictly needed, true. But we also have devices that have multiple FPGAs where the "slave" FPGA's register maps are accessed through a custom bus interface (called MCLink) on the first "master FPGA". With the regmap, I'll be able to use the same driver for both, all that's needed is another version of regmap for the MCLink bus. So the regmap is really there for forward-compatibility reasons.
Quoted 6 lines
Ah, I see. Thanks for the clarification. So I suspect if the same FPGA someday is connected to I2C, or SPI, the same driver can be used without any issue. In such case, the regmap can be very helpfu. Isn't such documented anywhere in U-Boot's source codes to help people understand? If not, I suggest we can improve something :)
Sounds good; I'll add some documentation in v7.
Quoted 3 lines
Regards,
Bin
Best regards,
Mario
PATCH v6 8/14 regmap: Add raw read/write functions
In reply to Simon GlassHi Simon,
Quoted 98 lines · Simon Glass
Hi Mario,
Quoted 85 lines · Mario Six
Hi Simon,
Quoted 67 lines · Simon Glass
Hi Mario,
Quoted 63 lines · Mario Six
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_readandregmap_raw_writefunctions from the Linux kernel API that specify the width of a desired read or write operation on a regmap.Implement the
regmap_readandregmap_writefunctions using these raw functions in a backwards-compatible manner.Reviewed-by Anatolij Gustschin <[email protected]>Signed-off-by Mario Six <[email protected]>---
v5 -> v6:
* Corrected format specifier
* Added support for 64-bit reads/writesv4 -> v5:
No changesv3 -> v4:
* Switched 'ranges[0] + offset' to 'ranges[0].start + offset'
* Explained the difference between the raw and non-raw read/write functions better in the docsv2 -> v3:
* Implement the "raw" functions from Linux instead of adding a size parameter to the regmap_{read,write} functions
* Fixed style violation
* Improved error handlingv1 -> v2:
New in v2--- drivers/core/regmap.c | 59 +++++++++++++++++++++++++++++++++++++++++++++------ include/regmap.h | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+), 7 deletions(-)drivers/core/regmap.c +13
-0@@ -188,22 +188,67 @@ 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 ].start + 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 ;Quoted 9 lines
drivers/core/regmap.c int regmap_uninit(struct regmap *map) · line 209
Quoted 6 lines
drivers/core/regmap.c +6
-0+case REGMAP_SIZE_32 : + *((u32 *)valp) =in_le32 ((u32 *)ptr); +break ; +#if defined(in_le64) && defined(readq) +case REGMAP_SIZE_64 : + *((u32 *)valp) =in_le64 ((u64 *)ptr);How come this is u32? Can you please add a comment?
That was a development version of the patch, sorry (I was in a bit of a hurry).
I'll send a corrected version with v7.
Quoted 8 lines
Quoted 3 lines
Why is this using in/out rather than read/write? Does it not support memory-mapped I/O?
It does, but I think the endianness of the read/write operations of the regmap should not depend on the architecture, but only on the regmap itself (which is little-endian for now; big-endian support can be introduced later on), so I used in/out rather than read/write.
Quoted 5 lines
What does endianness have to do with whether you use readl/writel or in/out?
On x86 at least these are actually different things, so
regmap()won't work on x86 with this change.
Ah, OK, I was not aware of that, because on powerpc we literally have, e.g.
#define readl(addr) in_le32((volatile u32 *)(addr))
So the only difference is really just the explicit endianness. Could you (or Bin, for that matter), explain what the differences are? I think it would be a good thing to document this somewhere, so others are more aware of the issue.
Quoted 5 lines
Adding Bin who may understand this better.
Regards,
Simon
Best regards,
Mario
PATCH v6 9/14 regmap: Support reading from specific range
In reply to Mario SixIt is useful to be able to treat the different ranges of a regmap separately to be able to use distinct offset for them, but this is currently not implemented in the regmap API.
To preserve backwards compatibility, add regmap_read_range and regmap_write_range functions that take an additional parameter 'range_num' that identifies the range to operate on.
---
v5 -> v6:
No changes
v4 -> v5:
No changes
v3 -> v4:
No changes
v2 -> v3:
* Renamed the functions to regmap_{write,read}_range
* Added function comments
* Fixed style violations
* Improved error handling
v1 -> v2:
New in v2
--- drivers/core/regmap.c | 49 ++++++++++++++++++++++++++++++++++++++++++++----- include/regmap.h | 31 +++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 5 deletions(-)
drivers/core/regmap.c +44 -5
@@ -188,11 +188,25 @@ int regmap_uninit(struct regmap *map)return 0 ; } -int regmap_raw_read (struct regmap *map,uint offset,void *valp,size_t val_len) +int regmap_raw_read_range (struct regmap *map,uint range_num,uint offset, +void *valp,size_t val_len) { +struct regmap_range *range;void *ptr; - ptr =map_physmem (map->ranges[0 ].start + offset, val_len,MAP_NOCACHE ); +if (range_num >= map->range_count) { +debug ("%s: range index %d larger than range count\n" , + __func__, range_num); +return -ERANGE ; + } + range = &map->ranges[range_num]; + + ptr =map_physmem (range->start + offset, val_len,MAP_NOCACHE ); + +if (offset + val_len > range->size) { +debug ("%s: offset/size combination invalid\n" , __func__); +return -ERANGE ; + }switch (val_len) {case REGMAP_SIZE_8 :
@@ -213,20 +227,39 @@ int regmap_raw_read(struct regmap *map, uint offset, void *valp, size_t val_len)debug ("%s: regmap size %zu unknown\n" , __func__, val_len);return -EINVAL ; } +return 0 ; } +int regmap_raw_read (struct regmap *map,uint offset,void *valp,size_t val_len) +{ +return regmap_raw_read_range (map,0 , offset, valp, val_len); +} +int regmap_read (struct regmap *map,uint offset,uint *valp) {return regmap_raw_read (map, offset, valp,REGMAP_SIZE_32 ); } -int regmap_raw_write (struct regmap *map,uint offset,const void *val, -size_t val_len) +int regmap_raw_write_range (struct regmap *map,uint range_num,uint offset, +const void *val,size_t val_len) { +struct regmap_range *range;void *ptr; - ptr =map_physmem (map->ranges[0 ].start + offset, val_len,MAP_NOCACHE ); +if (range_num >= map->range_count) { +debug ("%s: range index %d larger than range count\n" , + __func__, range_num); +return -ERANGE ; + } + range = &map->ranges[range_num]; + + ptr =map_physmem (range->start + offset, val_len,MAP_NOCACHE ); + +if (offset + val_len > range->size) { +debug ("%s: offset/size combination invalid\n" , __func__); +return -ERANGE ; + }switch (val_len) {case REGMAP_SIZE_8 :
@@ -246,6 +279,12 @@ int regmap_raw_write(struct regmap *map, uint offset, const void *val,return 0 ; } +int regmap_raw_write (struct regmap *map,uint offset,const void *val, +size_t val_len) +{ +return regmap_raw_write_range (map,0 , offset, val, val_len); +} +int regmap_write (struct regmap *map,uint offset,uint val) {return regmap_raw_write (map, offset, &val,REGMAP_SIZE_32 );
include/regmap.h +31 -0
@@ -115,6 +115,37 @@ int regmap_raw_write(struct regmap *map, uint offset, const void *val,int regmap_raw_read (struct regmap *map,uint offset,void *valp,size_t val_len); +/** +* regmap_raw_write_range() - Write a value of specified length to a range of a +* regmap +* +* @map: Regmap to write to +* @range_num: Number of the range in the 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_range (struct regmap *map,uint range_num,uint offset, +const void *val,size_t val_len); + +/** +* regmap_raw_read_range() - Read a value of specified length from a range of a +* regmap +* +* @map: Regmap to read from +* @range_num: Number of the range in the regmap to write to +* @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_range (struct regmap *map,uint range_num,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
PATCH v6 10/14 regmap: Define regmap_{get,set}
In reply to Mario SixIt would be convenient if one could use the regmap API in conjunction with register maps defined as structs (i.e. structs that directly mirror the memory layout of the registers in question). A similar approach was planned with the regmap_write32/regmap_read32 macros, but was never used.
Hence, implement regmap_set/regmap_range_set and regmap_get/regmap_range_get macros, which, given a register map, a struct describing the layout of the register map, and a member name automatically produce regmap_read/regmap_write calls that access the specified member in the register map.
---
v5 -> v6:
No changes
v4 -> v5:
No changes
v3 -> v4:
No changes
v2 -> v3:
* Fixed style violations
* Added documentation
v1 -> v2:
New in v2
--- include/regmap.h | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 4 deletions(-)
include/regmap.h +50 -4
@@ -146,11 +146,57 @@ int regmap_raw_write_range(struct regmap *map, uint range_num, uint offset,int regmap_raw_read_range (struct regmap *map,uint range_num,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) +/** +* regmap_range_set() - Set a value in a regmap range described by a struct +* @map: Regmap in which a value should be set +* @range: Range of the regmap in which a value should be set +* @type: Structure type that describes the memory layout of the regmap range +* @member: Member of the describing structure that should be set in the regmap +* range +* @val: Value which should be written to the regmap range +*/ +#define regmap_range_set (map, range, type, member, val) \ + do { \ + typeof(((type *)0)->member) __tmp = val; \ + regmap_raw_write_range(map, range, offsetof(type, member), \ + &__tmp, sizeof(((type *)0)->member)); \ + } while (0) + +/** +* regmap_set() - Set a value in a regmap described by a struct +* @map: Regmap in which a value should be set +* @type: Structure type that describes the memory layout of the regmap +* @member: Member of the describing structure that should be set in the regmap +* @val: Value which should be written to the regmap +*/ +#define regmap_set (map, type, member, val) \ + regmap_range_set(map, 0, type, member, val) -#define regmap_read32 (map, ptr, member, valp) \ - regmap_read(map, (uint32_t *)(ptr)->member - (uint32_t *)(ptr), valp) +/** +* regmap_range_get() - Get a value from a regmap range described by a struct +* @map: Regmap from which a value should be read +* @range: Range of the regmap from which a value should be read +* @type: Structure type that describes the memory layout of the regmap +* range +* @member: Member of the describing structure that should be read in the +* regmap range +* @valp: Variable that receives the value read from the regmap range +*/ +#define regmap_range_get (map, range, type, member, valp) \ + regmap_raw_read_range(map, range, offsetof(type, member), \ + (void *)valp, sizeof(((type *)0)->member)) + +/** +* regmap_get() - Get a value from a regmap described by a struct +* @map: Regmap from which a value should be read +* @type: Structure type that describes the memory layout of the regmap +* range +* @member: Member of the describing structure that should be read in the +* regmap +* @valp: Variable that receives the value read from the regmap +*/ +#define regmap_get (map, type, member, valp) \ + regmap_range_get(map, 0, type, member, valp)/** * regmap_update_bits() - Perform a read/modify/write using a mask
--
2.11.0
PATCH v6 11/14 test: regmap: Add test for regmap_{set, get}
In reply to Mario SixAdd test for regmap_{set,get} functions.
---
v5 -> v6:
No changes
v4 -> v5:
No changes
v3 -> v4:
No changes
v2 -> v3:
New in v3
--- test/dm/regmap.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
test/dm/regmap.c +28 -0
@@ -116,3 +116,31 @@ static int dm_test_regmap_rw(struct unit_test_state *uts) }DM_TEST (dm_test_regmap_rw,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); + +/* Get/Set test */ +static int dm_test_regmap_getset (struct unit_test_state *uts) +{ +struct udevice *dev; +struct regmap *map; +uint reg; +struct layout { +u32 val0; +u32 val1; +u32 val2; +u32 val3; + }; + +ut_assertok (uclass_get_device (UCLASS_SYSCON ,0 , &dev)); + map =syscon_get_regmap (dev); +ut_assertok_ptr (map); + + regmap_set(map, struct layout, val0, 0xcacafafa); + regmap_set(map, struct layout, val3, 0x55aa2211); + + ut_assertok(regmap_get(map, struct layout, val0, ®)); + ut_assertok(regmap_get(map, struct layout, val3, ®)); + +return 0 ; +} + +DM_TEST (dm_test_regmap_getset,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );
--
2.11.0
PATCH v6 12/14 misc: Sort Makefile entries
In reply to Mario SixMakefile entries should be sorted.
---
v5 -> v6:
No changes
v4 -> v5:
Drop re-ordered entries that are not in mainline (e.g. CONFIG_GDSYS_IOEP, CONFIG_MPC83XX_SERDES, misc_sandbox.o)
v3 -> v4:
No changes
v2 -> v3:
New in v3
--- drivers/misc/Makefile | 56 +++++++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 26 deletions(-)
drivers/misc/Makefile +30 -26
@@ -4,11 +4,7 @@ # Wolfgang Denk, DENX Software Engineering, wd at denx.de. obj-$(CONFIG_MISC) += misc-uclass.o -obj-$(CONFIG_ALI152X) += ali512x.o -obj-$(CONFIG_ALTERA_SYSID) += altera_sysid.o -obj-$(CONFIG_ATSHA204A) += atsha204a-i2c.o -obj-$(CONFIG_DS4510) += ds4510.o -obj-$(CONFIG_CBMEM_CONSOLE) += cbmem_console.o + ifndef CONFIG_SPL_BUILD obj-$(CONFIG_CROS_EC) += cros_ec.o obj-$(CONFIG_CROS_EC_LPC) += cros_ec_lpc.o
@@ -16,41 +12,49 @@ obj-$(CONFIG_CROS_EC_I2C) += cros_ec_i2c.o obj-$(CONFIG_CROS_EC_SANDBOX) += cros_ec_sandbox.o obj-$(CONFIG_CROS_EC_SPI) += cros_ec_spi.o endif -obj-$(CONFIG_FSL_IIM) += fsl_iim.o -obj-$(CONFIG_LED_STATUS_GPIO) += gpio_led.o -obj-$(CONFIG_$(SPL_)I2C_EEPROM) += i2c_eeprom.o -obj-$(CONFIG_FSL_MC9SDZ60) += mc9sdz60.o -obj-$(CONFIG_MXC_OCOTP) += mxc_ocotp.o -obj-$(CONFIG_MXS_OCOTP) += mxs_ocotp.o -obj-$(CONFIG_NUVOTON_NCT6102D) += nuvoton_nct6102d.o -obj-$(CONFIG_NS87308) += ns87308.o -obj-$(CONFIG_$(SPL_)PWRSEQ) += pwrseq-uclass.o + ifdef CONFIG_DM_I2C ifndef CONFIG_SPL_BUILD obj-$(CONFIG_SANDBOX) += i2c_eeprom_emul.o endif endif -obj-$(CONFIG_SMSC_LPC47M) += smsc_lpc47m.o -obj-$(CONFIG_SMSC_SIO1007) += smsc_sio1007.o -obj-$(CONFIG_LED_STATUS) += status_led.o -obj-$(CONFIG_SANDBOX) += swap_case.o + ifdef CONFIG_SPL_OF_PLATDATA ifdef CONFIG_SPL_BUILD obj-$(CONFIG_SANDBOX) += spltest_sandbox.o endif endif -obj-$(CONFIG_SANDBOX) += syscon_sandbox.o -obj-$(CONFIG_TEGRA_CAR) += tegra_car.o -obj-$(CONFIG_TEGRA186_BPMP) += tegra186_bpmp.o -obj-$(CONFIG_TWL4030_LED) += twl4030_led.o + +obj-$(CONFIG_ALI152X) += ali512x.o +obj-$(CONFIG_ALTERA_SYSID) += altera_sysid.o +obj-$(CONFIG_ATSHA204A) += atsha204a-i2c.o +obj-$(CONFIG_CBMEM_CONSOLE) += cbmem_console.o +obj-$(CONFIG_DS4510) += ds4510.o +obj-$(CONFIG_FSL_DEVICE_DISABLE) += fsl_devdis.o obj-$(CONFIG_FSL_IFC) += fsl_ifc.o +obj-$(CONFIG_FSL_IIM) += fsl_iim.o +obj-$(CONFIG_FSL_MC9SDZ60) += mc9sdz60.o obj-$(CONFIG_FSL_SEC_MON) += fsl_sec_mon.o +obj-$(CONFIG_GDSYS_RXAUI_CTRL) += gdsys_rxaui_ctrl.o +obj-$(CONFIG_$(SPL_)I2C_EEPROM) += i2c_eeprom.o +obj-$(CONFIG_LED_STATUS) += status_led.o +obj-$(CONFIG_LED_STATUS_GPIO) += gpio_led.o +obj-$(CONFIG_MXC_OCOTP) += mxc_ocotp.o +obj-$(CONFIG_MXS_OCOTP) += mxs_ocotp.o +obj-$(CONFIG_NS87308) += ns87308.o +obj-$(CONFIG_NUVOTON_NCT6102D) += nuvoton_nct6102d.o obj-$(CONFIG_PCA9551_LED) += pca9551_led.o -obj-$(CONFIG_FSL_DEVICE_DISABLE) += fsl_devdis.o -obj-$(CONFIG_WINBOND_W83627) += winbond_w83627.o +obj-$(CONFIG_$(SPL_)PWRSEQ) += pwrseq-uclass.o obj-$(CONFIG_QFW) += qfw.o obj-$(CONFIG_ROCKCHIP_EFUSE) += rockchip-efuse.o -obj-$(CONFIG_STM32_RCC) += stm32_rcc.o +obj-$(CONFIG_SANDBOX) += swap_case.o +obj-$(CONFIG_SANDBOX) += syscon_sandbox.o +obj-$(CONFIG_SMSC_LPC47M) += smsc_lpc47m.o +obj-$(CONFIG_SMSC_SIO1007) += smsc_sio1007.o obj-$(CONFIG_STM32MP_FUSE) += stm32mp_fuse.o +obj-$(CONFIG_STM32_RCC) += stm32_rcc.o obj-$(CONFIG_SYS_DPAA_QBMAN) += fsl_portals.o -obj-$(CONFIG_GDSYS_RXAUI_CTRL) += gdsys_rxaui_ctrl.o +obj-$(CONFIG_TEGRA186_BPMP) += tegra186_bpmp.o +obj-$(CONFIG_TEGRA_CAR) += tegra_car.o +obj-$(CONFIG_TWL4030_LED) += twl4030_led.o +obj-$(CONFIG_WINBOND_W83627) += winbond_w83627.o
--
2.11.0
PATCH v6 13/14 misc: Add gdsys_soc driver
In reply to Mario SixThis patch adds a driver for the bus associated with a IHS FPGA.
---
v5 -> v6:
No changes
v4 -> v5:
No changes
v3 -> v4:
No changes
v2 -> v3:
* Fixed style violations
* Added bindings file
* Added more debug output in case of errors
* Switched all printfs to debug
* Documented the private data structure
* Formatted documentation as proper kernel-doc
* Expanded Kconfig description
v1 -> v2:
* Switched to correct uclass for IHS FPGA driver (now in MISC uclass)
--- .../devicetree/bindings/misc/gdsys,soc.txt | 16 +++++ drivers/misc/Kconfig | 9 +++ drivers/misc/Makefile | 1 + drivers/misc/gdsys_soc.c | 74 ++++++++++++++++++++++ drivers/misc/gdsys_soc.h | 23 +++++++ 5 files changed, 123 insertions(+) create mode 100644 Documentation/devicetree/bindings/misc/gdsys,soc.txt create mode 100644 drivers/misc/gdsys_soc.c create mode 100644 drivers/misc/gdsys_soc.h
Documentation/devicetree/bindings/misc/gdsys,soc.txt new file +16 -0
@@ -0,0 +1,16 @@ +gdsys soc bus driver + +This driver provides a simple interface for the busses associated with gdsys +IHS FPGAs. The bus itself contains devices whose register maps are contained +within the FPGA's register space. + +Required properties: +- fpga: A phandle to the controlling IHS FPGA + +Example: + +FPGA0BUS: fpga0bus { + compatible = "gdsys,soc"; + ranges = <0x0 0xe0600000 0x00004000>; + fpga = <&FPGA0>; +};
drivers/misc/Kconfig +9 -0
@@ -277,4 +277,13 @@ config GDSYS_RXAUI_CTRL depends on MISC help Support gdsys FPGA's RXAUI control. + +config GDSYS_SOC + bool "Enable gdsys SOC driver" + depends on MISC + help + Support for gdsys IHS SOC, a simple bus associated with each gdsys + IHS (Integrated Hardware Systems) FPGA, which holds all devices whose + register maps are contained within the FPGA's register map. + endmenu
drivers/misc/Makefile +1 -0
@@ -36,6 +36,7 @@ obj-$(CONFIG_FSL_IIM) += fsl_iim.o obj-$(CONFIG_FSL_MC9SDZ60) += mc9sdz60.o obj-$(CONFIG_FSL_SEC_MON) += fsl_sec_mon.o obj-$(CONFIG_GDSYS_RXAUI_CTRL) += gdsys_rxaui_ctrl.o +obj-$(CONFIG_GDSYS_SOC) += gdsys_soc.o obj-$(CONFIG_$(SPL_)I2C_EEPROM) += i2c_eeprom.o obj-$(CONFIG_LED_STATUS) += status_led.o obj-$(CONFIG_LED_STATUS_GPIO) += gpio_led.o
drivers/misc/gdsys_soc.c new file +74 -0
74 lines not on this page · raw message
drivers/misc/gdsys_soc.h new file +23 -0
@@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* (C) Copyright 2017 +* Mario Six, Guntermann & Drunck GmbH, mario.six at gdsys.cc +*/ + +#ifndef _GDSYS_SOC_H_ +#define _GDSYS_SOC_H_ + +/** +* gdsys_soc_get_fpga() - Retrieve pointer to parent bus' FPGA device +* @child: The child device on the FPGA bus needing access to the FPGA. +* @fpga: Pointer to the retrieved FPGA device. +* +* To access their register maps, devices on gdsys soc buses usually have +* facilitate the accessor function of the IHS FPGA their parent bus is +* attached to. To access the FPGA device from within the bus' children, this +* function returns a pointer to it. +* +* Return: 0 on success, -ve on failure +*/ +int gdsys_soc_get_fpga (struct udevice *child,struct udevice **fpga); +#endif /* _GDSYS_SOC_H_ */
--
2.11.0
PATCH v6 14/14 misc: Add IHS FPGA driver
In reply to Mario SixAdd a driver for gdsys IHS (Integrated Hardware Systems) FPGAs, which supports initialization of the FPGA, as well as information gathering.
---
v5 -> v6:
No changes
v4 -> v5:
No changes
v3 -> v4:
* Switched from 'res' as the name for return variables to 'ret'
v2 -> v3:
* Fixed style violations
* Added full documentation
* Extracted some magic numbers to constants
* Removed unnecessary includes
* Extracted wait_for_fpga_done
* Improved error handling and reporting
* Added device-tree-binding files
* Improved Kconfig entry
v1 -> v2:
New in v2
--- .../devicetree/bindings/misc/gdsys,iocon_fpga.txt | 19 + .../devicetree/bindings/misc/gdsys,iocpu_fpga.txt | 19 + drivers/misc/Kconfig | 9 + drivers/misc/Makefile | 1 + drivers/misc/ihs_fpga.c | 867 +++++++++++++++++++++ drivers/misc/ihs_fpga.h | 49 ++ 6 files changed, 964 insertions(+) create mode 100644 Documentation/devicetree/bindings/misc/gdsys,iocon_fpga.txt create mode 100644 Documentation/devicetree/bindings/misc/gdsys,iocpu_fpga.txt create mode 100644 drivers/misc/ihs_fpga.c create mode 100644 drivers/misc/ihs_fpga.h
Documentation/devicetree/bindings/misc/gdsys,iocon_fpga.txt new file +19 -0
@@ -0,0 +1,19 @@ +gdsys IHS FPGA for CON devices + +The gdsys IHS FPGA is the main FPGA on gdsys CON devices. This driver provides +support for enabling and starting the FPGA, as well as verifying working bus +communication. + +Required properties: +- compatible: must be "gdsys,iocon_fpga" +- reset-gpios: List of GPIOs controlling the FPGA's reset +- done-gpios: List of GPIOs notifying whether the FPGA's reconfiguration is + done + +Example: + +FPGA0 { + compatible = "gdsys,iocon_fpga"; + reset-gpios = <&PPCPCA 26 0>; + done-gpios = <&GPIO_VB0 19 0>; +};
Documentation/devicetree/bindings/misc/gdsys,iocpu_fpga.txt new file +19 -0
@@ -0,0 +1,19 @@ +gdsys IHS FPGA for CPU devices + +The gdsys IHS FPGA is the main FPGA on gdsys CPU devices. This driver provides +support for enabling and starting the FPGA, as well as verifying working bus +communication. + +Required properties: +- compatible: must be "gdsys,iocpu_fpga" +- reset-gpios: List of GPIOs controlling the FPGA's reset +- done-gpios: List of GPIOs notifying whether the FPGA's reconfiguration is + done + +Example: + +FPGA0 { + compatible = "gdsys,iocpu_fpga"; + reset-gpios = <&PPCPCA 26 0>; + done-gpios = <&GPIO_VB0 19 0>; +};
drivers/misc/Kconfig +9 -0
@@ -286,4 +286,13 @@ config GDSYS_SOC IHS (Integrated Hardware Systems) FPGA, which holds all devices whose register maps are contained within the FPGA's register map. +config IHS_FPGA + bool "Enable IHS FPGA driver" + depends on MISC + help + Support IHS (Integrated Hardware Systems) FPGA, the main FPGAs on + gdsys devices, which supply the majority of the functionality offered + by the devices. This driver supports both CON and CPU variants of the + devices, depending on the device tree entry. + endmenu
drivers/misc/Makefile +1 -0
@@ -38,6 +38,7 @@ obj-$(CONFIG_FSL_SEC_MON) += fsl_sec_mon.o obj-$(CONFIG_GDSYS_RXAUI_CTRL) += gdsys_rxaui_ctrl.o obj-$(CONFIG_GDSYS_SOC) += gdsys_soc.o obj-$(CONFIG_$(SPL_)I2C_EEPROM) += i2c_eeprom.o +obj-$(CONFIG_IHS_FPGA) += ihs_fpga.o obj-$(CONFIG_LED_STATUS) += status_led.o obj-$(CONFIG_LED_STATUS_GPIO) += gpio_led.o obj-$(CONFIG_MXC_OCOTP) += mxc_ocotp.o
drivers/misc/ihs_fpga.c new file +867 -0
867 lines not on this page · raw message
drivers/misc/ihs_fpga.h new file +49 -0
49 lines not on this page · raw message
--
2.11.0