summaryrefslogtreecommitdiff
path: root/zephyr/include/drivers/cros_bbram.h
blob: f96ef3dba44fa4f749fd8c6c97db3557aad0fc5a (plain)
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/* Copyright 2021 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef ZEPHYR_INCLUDE_DRIVERS_CROS_BBRAM_H_
#define ZEPHYR_INCLUDE_DRIVERS_CROS_BBRAM_H_

#include <device.h>

/**
 * Check if "Invalid Battery-Backed RAM". This may occur as a result to low
 * voltage at the VBAT pin.
 *
 * @return 0 if the Battery-Backed RAM data is valid.
 */
typedef int (*cros_bbram_api_ibbr)(const struct device *dev);

/**
 * Reset the IBBR status (calling cros_bbram_ibbr will return 0 after this).
 *
 * @return 0 after reset is complete.
 * @see cros_bbram_ibbr
 */
typedef int (*cros_bbram_api_reset_ibbr)(const struct device *dev);

/**
 * Check for V SBY power failure. This will return an error if the V SBY power
 * domain is turned on after it was off.
 *
 * @return 0 if V SBY power domain is in normal operation.
 */
typedef int (*cros_bbram_api_vsby)(const struct device *dev);

/**
 * Reset the V SBY status (calling cros_bbram_vsby will return 0 after this).
 *
 * @return 0 after reset is complete.
 * @see cros_bbram_vsby
 */
typedef int (*cros_bbram_api_reset_vsby)(const struct device *dev);

/**
 * Check for V CC1 power failure. This will return an error if the V CC1 power
 * domain is turned on after it was off.
 *
 * @return 0 if the V CC1 power domain is in normal operation.
 */
typedef int (*cros_bbram_api_vcc1)(const struct device *dev);

/**
 * Reset the V CC1 status (calling cros_bbram_vcc1 will return 0 after this).
 *
 * @return 0 after reset is complete.
 * @see cros_bbram_vcc1
 */
typedef int (*cros_bbram_api_reset_vcc1)(const struct device *dev);

typedef int (*cros_bbram_api_read)(const struct device *dev, int offset,
				   int size, uint8_t *data);

typedef int (*cros_bbram_api_write)(const struct device *dev, int offset,
				    int size, uint8_t *data);

__subsystem struct cros_bbram_driver_api {
	cros_bbram_api_ibbr ibbr;
	cros_bbram_api_reset_ibbr reset_ibbr;
	cros_bbram_api_vsby vsby;
	cros_bbram_api_reset_vsby reset_vsby;
	cros_bbram_api_vcc1 vcc1;
	cros_bbram_api_reset_vcc1 reset_vcc1;
	cros_bbram_api_read read;
	cros_bbram_api_write write;
};

__syscall int cros_bbram_get_ibbr(const struct device *dev);

static inline int z_impl_cros_bbram_get_ibbr(const struct device *dev)
{
	const struct cros_bbram_driver_api *api =
		(const struct cros_bbram_driver_api *)dev->api;

	if (!api->ibbr) {
		return -ENOTSUP;
	}

	return api->ibbr(dev);
}

__syscall int cros_bbram_reset_ibbr(const struct device *dev);

static inline int z_impl_cros_bbram_reset_ibbr(const struct device *dev)
{
	const struct cros_bbram_driver_api *api =
		(const struct cros_bbram_driver_api *)dev->api;

	if (!api->reset_ibbr) {
		return -ENOTSUP;
	}

	return api->reset_ibbr(dev);
}

__syscall int cros_bbram_get_vsby(const struct device *dev);

static inline int z_impl_cros_bbram_get_vsby(const struct device *dev)
{
	const struct cros_bbram_driver_api *api =
		(const struct cros_bbram_driver_api *)dev->api;

	if (!api->vsby) {
		return -ENOTSUP;
	}

	return api->vsby(dev);
}

__syscall int cros_bbram_reset_vsby(const struct device *dev);

static inline int z_impl_cros_bbram_reset_vsby(const struct device *dev)
{
	const struct cros_bbram_driver_api *api =
		(const struct cros_bbram_driver_api *)dev->api;

	if (!api->reset_vsby) {
		return -ENOTSUP;
	}

	return api->reset_vsby(dev);
}

__syscall int cros_bbram_get_vcc1(const struct device *dev);

static inline int z_impl_cros_bbram_get_vcc1(const struct device *dev)
{
	const struct cros_bbram_driver_api *api =
		(const struct cros_bbram_driver_api *)dev->api;

	if (!api->vcc1) {
		return -ENOTSUP;
	}

	return api->vcc1(dev);
}

__syscall int cros_bbram_reset_vcc1(const struct device *dev);

static inline int z_impl_cros_bbram_reset_vcc1(const struct device *dev)
{
	const struct cros_bbram_driver_api *api =
		(const struct cros_bbram_driver_api *)dev->api;

	if (!api->reset_vcc1) {
		return -ENOTSUP;
	}

	return api->reset_vcc1(dev);
}

__syscall int cros_bbram_read(const struct device *dev, int offset, int size,
			      uint8_t *data);

static inline int z_impl_cros_bbram_read(const struct device *dev, int offset,
					 int size, uint8_t *data)
{
	const struct cros_bbram_driver_api *api =
		(const struct cros_bbram_driver_api *)dev->api;

	if (!api->read) {
		return -ENOTSUP;
	}

	return api->read(dev, offset, size, data);
}

__syscall int cros_bbram_write(const struct device *dev, int offset, int size,
			       uint8_t *data);

static inline int z_impl_cros_bbram_write(const struct device *dev, int offset,
					  int size, uint8_t *data)
{
	const struct cros_bbram_driver_api *api =
		(const struct cros_bbram_driver_api *)dev->api;

	if (!api->write) {
		return -ENOTSUP;
	}

	return api->write(dev, offset, size, data);
}

#include <syscalls/cros_bbram.h>
#endif /* ZEPHYR_INCLUDE_DRIVERS_CROS_BBRAM_H_ */