blob: e96c79dd26a219843d6343fb7d789aa63ae1cad5 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glass6f98b752015-06-23 15:38:42 -06002/*
3 * Copyright (c) 2015 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
Simon Glass6f98b752015-06-23 15:38:42 -06005 */
6
7#ifndef __REGMAP_H
8#define __REGMAP_H
9
10/**
11 * struct regmap_range - a register map range
12 *
13 * @start: Start address
14 * @size: Size in bytes
15 */
16struct regmap_range {
17 ulong start;
18 ulong size;
19};
20
21/**
22 * struct regmap - a way of accessing hardware/bus registers
23 *
Simon Glass6f98b752015-06-23 15:38:42 -060024 * @range_count: Number of ranges available within the map
Masahiro Yamada8c1de5e2018-04-19 12:14:01 +090025 * @ranges: Array of ranges
Simon Glass6f98b752015-06-23 15:38:42 -060026 */
27struct regmap {
Simon Glass6f98b752015-06-23 15:38:42 -060028 int range_count;
Masahiro Yamada8c1de5e2018-04-19 12:14:01 +090029 struct regmap_range ranges[0];
Simon Glass6f98b752015-06-23 15:38:42 -060030};
31
32/*
33 * Interface to provide access to registers either through a direct memory
34 * bus or through a peripheral bus like I2C, SPI.
35 */
36int regmap_write(struct regmap *map, uint offset, uint val);
37int regmap_read(struct regmap *map, uint offset, uint *valp);
38
39#define regmap_write32(map, ptr, member, val) \
40 regmap_write(map, (uint32_t *)(ptr)->member - (uint32_t *)(ptr), val)
41
42#define regmap_read32(map, ptr, member, valp) \
43 regmap_read(map, (uint32_t *)(ptr)->member - (uint32_t *)(ptr), valp)
44
45/**
46 * regmap_init_mem() - Set up a new register map that uses memory access
47 *
48 * Use regmap_uninit() to free it.
49 *
Masahiro Yamadad3581232018-04-19 12:14:03 +090050 * @node: Device node that uses this map
Simon Glass6f98b752015-06-23 15:38:42 -060051 * @mapp: Returns allocated map
52 */
Masahiro Yamadad3581232018-04-19 12:14:03 +090053int regmap_init_mem(ofnode node, struct regmap **mapp);
Simon Glass6f98b752015-06-23 15:38:42 -060054
Simon Glass1e6ca1a2016-07-04 11:58:22 -060055/**
56 * regmap_init_mem_platdata() - Set up a new memory register map for of-platdata
57 *
58 * This creates a new regmap with a list of regions passed in, rather than
59 * using the device tree. It only supports 32-bit machines.
60 *
61 * Use regmap_uninit() to free it.
62 *
63 * @dev: Device that uses this map
64 * @reg: List of address, size pairs
65 * @count: Number of pairs (e.g. 1 if the regmap has a single entry)
66 * @mapp: Returns allocated map
67 */
Simon Glassc20ee0e2017-08-29 14:15:50 -060068int regmap_init_mem_platdata(struct udevice *dev, fdt_val_t *reg, int count,
Simon Glass3b2a29e2016-07-04 11:57:59 -060069 struct regmap **mapp);
70
Simon Glass6f98b752015-06-23 15:38:42 -060071/**
72 * regmap_get_range() - Obtain the base memory address of a regmap range
73 *
74 * @map: Regmap to query
75 * @range_num: Range to look up
76 */
77void *regmap_get_range(struct regmap *map, unsigned int range_num);
78
79/**
80 * regmap_uninit() - free a previously inited regmap
81 */
82int regmap_uninit(struct regmap *map);
83
84#endif