Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
syscon.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 Carlo Caione <ccaione@baylibre.com>
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
12
13#ifndef ZEPHYR_INCLUDE_DRIVERS_SYSCON_H_
14#define ZEPHYR_INCLUDE_DRIVERS_SYSCON_H_
15
22
23#include <errno.h>
24
25#include <zephyr/types.h>
26#include <zephyr/device.h>
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
36
41typedef int (*syscon_api_get_base)(const struct device *dev, uintptr_t *addr);
42
47typedef int (*syscon_api_read_reg)(const struct device *dev, uint16_t reg, uint32_t *val);
48
53typedef int (*syscon_api_write_reg)(const struct device *dev, uint16_t reg, uint32_t val);
54
59typedef int (*syscon_api_update_bits)(const struct device *dev, uint16_t reg,
60 uint32_t mask, uint32_t val);
61
66typedef int (*syscon_api_get_size)(const struct device *dev, size_t *size);
67
83
85
95__syscall int syscon_get_base(const struct device *dev, uintptr_t *addr);
96
97static inline int z_impl_syscon_get_base(const struct device *dev, uintptr_t *addr)
98{
99 const struct syscon_driver_api *api = DEVICE_API_GET(syscon, dev);
100
101 if ((api == NULL) || (api->get_base == NULL)) {
102 return -ENOSYS;
103 }
104
105 return api->get_base(dev, addr);
106}
107
108
121__syscall int syscon_read_reg(const struct device *dev, uint16_t reg, uint32_t *val);
122
123static inline int z_impl_syscon_read_reg(const struct device *dev, uint16_t reg, uint32_t *val)
124{
125 const struct syscon_driver_api *api = DEVICE_API_GET(syscon, dev);
126
127 if ((api == NULL) || (api->read == NULL)) {
128 return -ENOSYS;
129 }
130
131 return api->read(dev, reg, val);
132}
133
134
147__syscall int syscon_write_reg(const struct device *dev, uint16_t reg, uint32_t val);
148
149static inline int z_impl_syscon_write_reg(const struct device *dev, uint16_t reg, uint32_t val)
150{
151 const struct syscon_driver_api *api = DEVICE_API_GET(syscon, dev);
152
153 if ((api == NULL) || (api->write == NULL)) {
154 return -ENOSYS;
155 }
156
157 return api->write(dev, reg, val);
158}
159
182__syscall int syscon_update_bits(const struct device *dev, uint16_t reg,
183 uint32_t mask, uint32_t val);
184
185static inline int z_impl_syscon_update_bits(const struct device *dev, uint16_t reg,
186 uint32_t mask, uint32_t val)
187{
188 const struct syscon_driver_api *api = (const struct syscon_driver_api *)dev->api;
189
190 if ((api == NULL) || (api->update_bits == NULL)) {
191 return -ENOSYS;
192 }
193
194 return api->update_bits(dev, reg, mask, val);
195}
196
206__syscall int syscon_get_size(const struct device *dev, size_t *size);
207
208static inline int z_impl_syscon_get_size(const struct device *dev, size_t *size)
209{
210 const struct syscon_driver_api *api = DEVICE_API_GET(syscon, dev);
211
212 if ((api == NULL) || (api->get_size == NULL)) {
213 return -ENOSYS;
214 }
215
216 return api->get_size(dev, size);
217}
218
222
223#ifdef __cplusplus
224}
225#endif
226
227#include <zephyr/syscalls/syscon.h>
228
229#endif /* ZEPHYR_INCLUDE_DRIVERS_SYSCON_H_ */
#define DEVICE_API_GET(_class, _dev)
Expands to the pointer of a device's API for a given class.
Definition device.h:1375
System error numbers.
int(* syscon_api_write_reg)(const struct device *dev, uint16_t reg, uint32_t val)
Write a single register.
Definition syscon.h:53
int(* syscon_api_get_base)(const struct device *dev, uintptr_t *addr)
Get the base address of the syscon region.
Definition syscon.h:41
int(* syscon_api_update_bits)(const struct device *dev, uint16_t reg, uint32_t mask, uint32_t val)
Atomically update bits in a register.
Definition syscon.h:59
int(* syscon_api_read_reg)(const struct device *dev, uint16_t reg, uint32_t *val)
Read a single register.
Definition syscon.h:47
int(* syscon_api_get_size)(const struct device *dev, size_t *size)
Get the size of the syscon register region.
Definition syscon.h:66
int syscon_get_base(const struct device *dev, uintptr_t *addr)
Get the syscon base address.
int syscon_read_reg(const struct device *dev, uint16_t reg, uint32_t *val)
Read from syscon register.
int syscon_get_size(const struct device *dev, size_t *size)
Get the size of the syscon register in bytes.
int syscon_write_reg(const struct device *dev, uint16_t reg, uint32_t val)
Write to syscon register.
int syscon_update_bits(const struct device *dev, uint16_t reg, uint32_t mask, uint32_t val)
Atomically update bits in a syscon register.
#define ENOSYS
Function not implemented.
Definition errno.h:82
#define NULL
Definition iar_missing_defs.h:20
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINTPTR_TYPE__ uintptr_t
Definition stdint.h:105
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Runtime device structure (in ROM) per driver instance.
Definition device.h:513
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:519
<span class="mlabel">Driver Operations</span> SYSCON driver operations
Definition syscon.h:71
syscon_api_get_base get_base
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition syscon.h:79
syscon_api_read_reg read
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition syscon.h:73
syscon_api_get_size get_size
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition syscon.h:81
syscon_api_update_bits update_bits
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition syscon.h:77
syscon_api_write_reg write
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition syscon.h:75