blob: 8d18b07c30c3a0c82314163c3c2913f3d4e2134c [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 *
24 * @base: Base address of register map
25 * @range_count: Number of ranges available within the map
26 * @range: Pointer to the list of ranges, allocated if @range_count > 1
27 * @base_range: If @range_count is <= 1, @range points here
28 */
29struct regmap {
30 phys_addr_t base;
31 int range_count;
32 struct regmap_range *range, base_range;
33};
34
35/*
36 * Interface to provide access to registers either through a direct memory
37 * bus or through a peripheral bus like I2C, SPI.
38 */
39int regmap_write(struct regmap *map, uint offset, uint val);
40int regmap_read(struct regmap *map, uint offset, uint *valp);
41
42#define regmap_write32(map, ptr, member, val) \
43 regmap_write(map, (uint32_t *)(ptr)->member - (uint32_t *)(ptr), val)
44
45#define regmap_read32(map, ptr, member, valp) \
46 regmap_read(map, (uint32_t *)(ptr)->member - (uint32_t *)(ptr), valp)
47
48/**
49 * regmap_init_mem() - Set up a new register map that uses memory access
50 *
51 * Use regmap_uninit() to free it.
52 *
53 * @dev: Device that uses this map
54 * @mapp: Returns allocated map
55 */
56int regmap_init_mem(struct udevice *dev, struct regmap **mapp);
57
Simon Glass1e6ca1a2016-07-04 11:58:22 -060058/**
59 * regmap_init_mem_platdata() - Set up a new memory register map for of-platdata
60 *
61 * This creates a new regmap with a list of regions passed in, rather than
62 * using the device tree. It only supports 32-bit machines.
63 *
64 * Use regmap_uninit() to free it.
65 *
66 * @dev: Device that uses this map
67 * @reg: List of address, size pairs
68 * @count: Number of pairs (e.g. 1 if the regmap has a single entry)
69 * @mapp: Returns allocated map
70 */
Simon Glassc20ee0e2017-08-29 14:15:50 -060071int regmap_init_mem_platdata(struct udevice *dev, fdt_val_t *reg, int count,
Simon Glass3b2a29e2016-07-04 11:57:59 -060072 struct regmap **mapp);
73
Simon Glass6f98b752015-06-23 15:38:42 -060074/**
75 * regmap_get_range() - Obtain the base memory address of a regmap range
76 *
77 * @map: Regmap to query
78 * @range_num: Range to look up
79 */
80void *regmap_get_range(struct regmap *map, unsigned int range_num);
81
82/**
83 * regmap_uninit() - free a previously inited regmap
84 */
85int regmap_uninit(struct regmap *map);
86
87#endif