File: regmap.h

package info (click to toggle)
crust-firmware 0.6-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,900 kB
  • sloc: ansic: 19,341; yacc: 596; lex: 479; makefile: 334; asm: 215; sh: 136; python: 42
file content (160 lines) | stat: -rw-r--r-- 4,383 bytes parent folder | download | duplicates (2)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
 * Copyright © 2017-2022 The Crust Firmware Authors.
 * SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0-only
 */

#ifndef DRIVERS_REGMAP_H
#define DRIVERS_REGMAP_H

#include <device.h>
#include <intrusive.h>
#include <stdint.h>

struct regmap {
	const struct device *dev;
	uint32_t             id;
};

struct regmap_device {
	struct device dev;
	struct regmap map;
};

/**
 * Downcast a pointer to a regmap device.
 */
static inline const struct regmap_device *
to_regmap_device(const struct device *dev)
{
	return container_of(dev, const struct regmap_device, dev);
}

/**
 * Get a reference to a regmap and its provider bus/device.
 *
 * This function will verify the existence of the device containing the regmap.
 *
 * This function may fail with:
 *   EIO     There was a problem communicating with the hardware.
 *   ENODEV  The device was not found on its provider bus.
 *
 * @param map  A specifier for the bus/device providing the regmap.
 * @return     Zero on success; an error code on failure.
 */
int regmap_get(const struct regmap *map);

/**
 * Release a reference to a regmap.
 *
 * @param map  A reference to a regmap.
 */
void regmap_put(const struct regmap *map);

/**
 * Read a value from a regmap.
 *
 * This function may fail with:
 *   EIO     There was a problem communicating with the hardware.
 *
 * @param map  A reference to the regmap.
 * @param reg  The register to read.
 * @param val  The location to save the value read from the register.
 * @return     Zero on success; an error code on failure.
 */
int regmap_read(const struct regmap *map, uint8_t reg, uint8_t *val);

/**
 * Write a value to a regmap.
 *
 * This function may fail with:
 *   EIO     There was a problem communicating with the hardware.
 *
 * @param map  A reference to the regmap.
 * @param reg  The register to write.
 * @param val  The value to write to the register.
 * @return     Zero on success; an error code on failure.
 */
int regmap_write(const struct regmap *map, uint8_t reg, uint8_t val);

/**
 * Update a bitfield in a regmap register.
 *
 * This function may fail with:
 *   EIO     There was a problem communicating with the hardware.
 *
 * @param map  A reference to the regmap.
 * @param reg  The register to modify.
 * @param mask A mask of bits representing a bitfield.
 * @param val  The new value of the bitfield.
 * @return     Zero on success; an error code on failure.
 */
int regmap_update_bits(const struct regmap *map, uint8_t reg, uint8_t mask,
                       uint8_t val);

/**
 * Clear bits in a regmap register.
 *
 * This function may fail with:
 *   EIO     There was a problem communicating with the hardware.
 *
 * @param map  A reference to the regmap.
 * @param reg  The register to modify.
 * @param clr  The mask of bits to clear in the register.
 * @return     Zero on success; an error code on failure.
 */
static inline int
regmap_clr_bits(const struct regmap *map, uint8_t reg, uint8_t clr)
{
	return regmap_update_bits(map, reg, clr, 0);
}

/**
 * Set bits in a regmap register.
 *
 * This function may fail with:
 *   EIO     There was a problem communicating with the hardware.
 *
 * @param map  A reference to the regmap.
 * @param reg  The register to modify.
 * @param set  The mask of bits to set in the register.
 * @return     Zero on success; an error code on failure.
 */
static inline int
regmap_set_bits(const struct regmap *map, uint8_t reg, uint8_t set)
{
	return regmap_update_bits(map, reg, set, set);
}

/**
 * Probe a device that owns a regmap.
 *
 * This function can be used to implement a device's .probe hook.
 */
int regmap_device_probe(const struct device *dev);

/**
 * Release a device that owns a regmap.
 *
 * This function can be used to implement a device's .release hook.
 */
void regmap_device_release(const struct device *dev);

/**
 * Probe a device that uses a regmap owned by another device.
 *
 * This function assumes that the regmap's owner is a regmap_device.
 *
 * This function can be used to implement a device's .probe hook.
 */
int regmap_user_probe(const struct regmap *map);

/**
 * Release a device that uses a regmap owned by another device.
 *
 * This function assumes that the regmap's owner is a regmap_device.
 *
 * This function can be used to implement a device's .release hook.
 */
void regmap_user_release(const struct regmap *map);

#endif /* DRIVERS_REGMAP_H */