blob: eccf7707f456568de6cd371d6d971e71bd403ee6 [file] [log] [blame]
Simon Glass6f98b752015-06-23 15:38:42 -06001/*
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 */
17struct 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 */
30struct 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 */
40int regmap_write(struct regmap *map, uint offset, uint val);
41int 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 */
57int regmap_init_mem(struct udevice *dev, struct regmap **mapp);
58
59/**
60 * regmap_get_range() - Obtain the base memory address of a regmap range
61 *
62 * @map: Regmap to query
63 * @range_num: Range to look up
64 */
65void *regmap_get_range(struct regmap *map, unsigned int range_num);
66
67/**
68 * regmap_uninit() - free a previously inited regmap
69 */
70int regmap_uninit(struct regmap *map);
71
72#endif