mirror of
				https://source.denx.de/u-boot/u-boot.git
				synced 2025-10-31 00:11:51 +01:00 
			
		
		
		
	When using 32-bit addresses dtoc works correctly. For 64-bit addresses it does not since it ignores the #address-cells and #size-cells properties. Update the tool to use fdt64_t as the element type for reg properties when either the address or size is larger than one cell. Use the correct value so that C code can obtain the information from the device tree easily. Alos create a new type, fdt_val_t, which is defined to either fdt32_t or fdt64_t depending on the word size of the machine. This type corresponds to fdt_addr_t and fdt_size_t. Unfortunately we cannot just use those types since they are defined to phys_addr_t and phys_size_t which use 'unsigned long' in the 32-bit case, rather than 'unsigned int'. Add tests for the four combinations of address and size values (32/32, 64/64, 32/64, 64/32). Also update existing uses for rk3399 and rk3368 which now need to use the new fdt_val_t type. Signed-off-by: Simon Glass <sjg@chromium.org> Suggested-by: Heiko Stuebner <heiko@sntech.de> Reported-by: Kever Yang <kever.yang@rock-chips.com> Reviewed-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com> Tested-by: Kever Yang <kever.yang@rock-chips.com>
		
			
				
	
	
		
			89 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			89 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2015 Google, Inc
 | |
|  * Written by Simon Glass <sjg@chromium.org>
 | |
|  *
 | |
|  * SPDX-License-Identifier:	GPL-2.0+
 | |
|  */
 | |
| 
 | |
| #ifndef __REGMAP_H
 | |
| #define __REGMAP_H
 | |
| 
 | |
| /**
 | |
|  * struct regmap_range - a register map range
 | |
|  *
 | |
|  * @start:	Start address
 | |
|  * @size:	Size in bytes
 | |
|  */
 | |
| struct regmap_range {
 | |
| 	ulong start;
 | |
| 	ulong size;
 | |
| };
 | |
| 
 | |
| /**
 | |
|  * struct regmap - a way of accessing hardware/bus registers
 | |
|  *
 | |
|  * @base:	Base address of register map
 | |
|  * @range_count: Number of ranges available within the map
 | |
|  * @range:	Pointer to the list of ranges, allocated if @range_count > 1
 | |
|  * @base_range:	If @range_count is <= 1, @range points here
 | |
|  */
 | |
| struct regmap {
 | |
| 	phys_addr_t base;
 | |
| 	int range_count;
 | |
| 	struct regmap_range *range, base_range;
 | |
| };
 | |
| 
 | |
| /*
 | |
|  * Interface to provide access to registers either through a direct memory
 | |
|  * bus or through a peripheral bus like I2C, SPI.
 | |
|  */
 | |
| int regmap_write(struct regmap *map, uint offset, uint val);
 | |
| int regmap_read(struct regmap *map, uint offset, uint *valp);
 | |
| 
 | |
| #define regmap_write32(map, ptr, member, val) \
 | |
| 	regmap_write(map, (uint32_t *)(ptr)->member - (uint32_t *)(ptr), val)
 | |
| 
 | |
| #define regmap_read32(map, ptr, member, valp) \
 | |
| 	regmap_read(map, (uint32_t *)(ptr)->member - (uint32_t *)(ptr), valp)
 | |
| 
 | |
| /**
 | |
|  * regmap_init_mem() - Set up a new register map that uses memory access
 | |
|  *
 | |
|  * Use regmap_uninit() to free it.
 | |
|  *
 | |
|  * @dev:	Device that uses this map
 | |
|  * @mapp:	Returns allocated map
 | |
|  */
 | |
| int regmap_init_mem(struct udevice *dev, struct regmap **mapp);
 | |
| 
 | |
| /**
 | |
|  * regmap_init_mem_platdata() - Set up a new memory register map for of-platdata
 | |
|  *
 | |
|  * 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);
 | |
| 
 | |
| /**
 | |
|  * regmap_get_range() - Obtain the base memory address of a regmap range
 | |
|  *
 | |
|  * @map:	Regmap to query
 | |
|  * @range_num:	Range to look up
 | |
|  */
 | |
| void *regmap_get_range(struct regmap *map, unsigned int range_num);
 | |
| 
 | |
| /**
 | |
|  * regmap_uninit() - free a previously inited regmap
 | |
|  */
 | |
| int regmap_uninit(struct regmap *map);
 | |
| 
 | |
| #endif
 |