xref: /openbmc/u-boot/include/regmap.h (revision e974b081)
1 /*
2  * Copyright (c) 2015 Google, Inc
3  * Written by Simon Glass <sjg@chromium.org>
4  *
5  * SPDX-License-Identifier:	GPL-2.0+
6  */
7 
8 #ifndef __REGMAP_H
9 #define __REGMAP_H
10 
11 /**
12  * struct regmap_range - a register map range
13  *
14  * @start:	Start address
15  * @size:	Size in bytes
16  */
17 struct regmap_range {
18 	ulong start;
19 	ulong size;
20 };
21 
22 /**
23  * struct regmap - a way of accessing hardware/bus registers
24  *
25  * @base:	Base address of register map
26  * @range_count: Number of ranges available within the map
27  * @range:	Pointer to the list of ranges, allocated if @range_count > 1
28  * @base_range:	If @range_count is <= 1, @range points here
29  */
30 struct regmap {
31 	phys_addr_t base;
32 	int range_count;
33 	struct regmap_range *range, base_range;
34 };
35 
36 /*
37  * Interface to provide access to registers either through a direct memory
38  * bus or through a peripheral bus like I2C, SPI.
39  */
40 int regmap_write(struct regmap *map, uint offset, uint val);
41 int regmap_read(struct regmap *map, uint offset, uint *valp);
42 
43 #define regmap_write32(map, ptr, member, val) \
44 	regmap_write(map, (uint32_t *)(ptr)->member - (uint32_t *)(ptr), val)
45 
46 #define regmap_read32(map, ptr, member, valp) \
47 	regmap_read(map, (uint32_t *)(ptr)->member - (uint32_t *)(ptr), valp)
48 
49 /**
50  * regmap_init_mem() - Set up a new register map that uses memory access
51  *
52  * Use regmap_uninit() to free it.
53  *
54  * @dev:	Device that uses this map
55  * @mapp:	Returns allocated map
56  */
57 int regmap_init_mem(struct udevice *dev, struct regmap **mapp);
58 
59 /**
60  * regmap_init_mem_platdata() - Set up a new memory register map for of-platdata
61  *
62  * This creates a new regmap with a list of regions passed in, rather than
63  * using the device tree. It only supports 32-bit machines.
64  *
65  * Use regmap_uninit() to free it.
66  *
67  * @dev:	Device that uses this map
68  * @reg:	List of address, size pairs
69  * @count:	Number of pairs (e.g. 1 if the regmap has a single entry)
70  * @mapp:	Returns allocated map
71  */
72 int regmap_init_mem_platdata(struct udevice *dev, fdt_val_t *reg, int count,
73 			     struct regmap **mapp);
74 
75 /**
76  * regmap_get_range() - Obtain the base memory address of a regmap range
77  *
78  * @map:	Regmap to query
79  * @range_num:	Range to look up
80  */
81 void *regmap_get_range(struct regmap *map, unsigned int range_num);
82 
83 /**
84  * regmap_uninit() - free a previously inited regmap
85  */
86 int regmap_uninit(struct regmap *map);
87 
88 #endif
89