Zephyr API Documentation 4.0.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#ifndef ZEPHYR_INCLUDE_DRIVERS_SYSCON_H_
13#define ZEPHYR_INCLUDE_DRIVERS_SYSCON_H_
14
22#include <errno.h>
23
24#include <zephyr/types.h>
25#include <zephyr/device.h>
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
36typedef int (*syscon_api_get_base)(const struct device *dev, uintptr_t *addr);
37
43typedef int (*syscon_api_read_reg)(const struct device *dev, uint16_t reg, uint32_t *val);
44
50typedef int (*syscon_api_write_reg)(const struct device *dev, uint16_t reg, uint32_t val);
51
57typedef int (*syscon_api_get_size)(const struct device *dev, size_t *size);
58
68
76__syscall int syscon_get_base(const struct device *dev, uintptr_t *addr);
77
78static inline int z_impl_syscon_get_base(const struct device *dev, uintptr_t *addr)
79{
80 const struct syscon_driver_api *api = (const struct syscon_driver_api *)dev->api;
81
82 if (api == NULL) {
83 return -ENOTSUP;
84 }
85
86 return api->get_base(dev, addr);
87}
88
89
101__syscall int syscon_read_reg(const struct device *dev, uint16_t reg, uint32_t *val);
102
103static inline int z_impl_syscon_read_reg(const struct device *dev, uint16_t reg, uint32_t *val)
104{
105 const struct syscon_driver_api *api = (const struct syscon_driver_api *)dev->api;
106
107 if (api == NULL) {
108 return -ENOTSUP;
109 }
110
111 return api->read(dev, reg, val);
112}
113
114
126__syscall int syscon_write_reg(const struct device *dev, uint16_t reg, uint32_t val);
127
128static inline int z_impl_syscon_write_reg(const struct device *dev, uint16_t reg, uint32_t val)
129{
130 const struct syscon_driver_api *api = (const struct syscon_driver_api *)dev->api;
131
132 if (api == NULL) {
133 return -ENOTSUP;
134 }
135
136 return api->write(dev, reg, val);
137}
138
146__syscall int syscon_get_size(const struct device *dev, size_t *size);
147
148static inline int z_impl_syscon_get_size(const struct device *dev, size_t *size)
149{
150 const struct syscon_driver_api *api = (const struct syscon_driver_api *)dev->api;
151
152 return api->get_size(dev, size);
153}
154
159#ifdef __cplusplus
160}
161#endif
162
163#include <zephyr/syscalls/syscon.h>
164
165#endif /* ZEPHYR_INCLUDE_DRIVERS_SYSCON_H_ */
System error numbers.
int syscon_get_base(const struct device *dev, uintptr_t *addr)
Get the syscon base address.
int(* syscon_api_write_reg)(const struct device *dev, uint16_t reg, uint32_t val)
API template to write a single register.
Definition syscon.h:50
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_api_get_base)(const struct device *dev, uintptr_t *addr)
API template to get the base address of the syscon region.
Definition syscon.h:36
int(* syscon_api_read_reg)(const struct device *dev, uint16_t reg, uint32_t *val)
API template to read a single register.
Definition syscon.h:43
int syscon_write_reg(const struct device *dev, uint16_t reg, uint32_t val)
Write to syscon register.
int(* syscon_api_get_size)(const struct device *dev, size_t *size)
API template to get the size of the syscon register.
Definition syscon.h:57
#define ENOTSUP
Unsupported value.
Definition errno.h:114
__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:411
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:417
System Control (syscon) register driver API.
Definition syscon.h:62
syscon_api_get_base get_base
Definition syscon.h:65
syscon_api_read_reg read
Definition syscon.h:63
syscon_api_get_size get_size
Definition syscon.h:66
syscon_api_write_reg write
Definition syscon.h:64