File: regmap.h

package info (click to toggle)
opensbi 1.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,480 kB
  • sloc: ansic: 34,934; python: 4,658; asm: 1,113; makefile: 639; sh: 329
file content (67 lines) | stat: -rw-r--r-- 1,712 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
 * SPDX-License-Identifier: BSD-2-Clause
 *
 * Copyright (c) 2023 Ventana Micro Systems Inc.
 *
 * Authors:
 *   Anup Patel <apatel@ventanamicro.com>
 */

#ifndef __REGMAP_H__
#define __REGMAP_H__

#include <sbi/sbi_types.h>
#include <sbi/sbi_list.h>

/** Representation of a regmap instance */
struct regmap {
	/** Uniquie ID of the regmap instance assigned by the driver */
	unsigned int id;

	/** Configuration of regmap registers */
	int reg_shift;
	int reg_stride;
	unsigned int reg_base;
	unsigned int reg_max;

	/** Read a regmap register */
	int (*reg_read)(struct regmap *rmap, unsigned int reg,
			unsigned int *val);

	/** Write a regmap register */
	int (*reg_write)(struct regmap *rmap, unsigned int reg,
			 unsigned int val);

	/** Read-modify-write a regmap register */
	int (*reg_update_bits)(struct regmap *rmap, unsigned int reg,
			       unsigned int mask, unsigned int val);

	/** List */
	struct sbi_dlist node;
};

static inline struct regmap *to_regmap(struct sbi_dlist *node)
{
	return container_of(node, struct regmap, node);
}

/** Find a registered regmap instance */
struct regmap *regmap_find(unsigned int id);

/** Register a regmap instance */
int regmap_add(struct regmap *rmap);

/** Un-register a regmap instance */
void regmap_remove(struct regmap *rmap);

/** Read a register in a regmap instance */
int regmap_read(struct regmap *rmap, unsigned int reg, unsigned int *val);

/** Write a register in a regmap instance */
int regmap_write(struct regmap *rmap, unsigned int reg, unsigned int val);

/** Read-modify-write a register in a regmap instance */
int regmap_update_bits(struct regmap *rmap, unsigned int reg,
		       unsigned int mask, unsigned int val);

#endif