Skip to content

Commit 2c718b2

Browse files
msierszulskicfriedt
authored andcommitted
drivers: fpga controller: add fpga api
This adds new FPGA controller which allow to control FPGA chips. FPGA controller has been created to enable bitstream loading into the reprogrammable logic. It adds completely new API, which enables to check status of the FPGA chip, power it on or off and reset it. Signed-off-by: Mateusz Sierszulski <[email protected]> Signed-off-by: Tomasz Gorochowik <[email protected]>
1 parent ffdd606 commit 2c718b2

File tree

5 files changed

+179
-0
lines changed

5 files changed

+179
-0
lines changed

drivers/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,4 @@ add_subdirectory_ifdef(CONFIG_EDAC edac)
6060
add_subdirectory_ifdef(CONFIG_CACHE_MANAGEMENT cache)
6161
add_subdirectory_ifdef(CONFIG_SYSCON syscon)
6262
add_subdirectory_ifdef(CONFIG_BBRAM bbram)
63+
add_subdirectory_ifdef(CONFIG_FPGA fpga)

drivers/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,6 @@ source "drivers/syscon/Kconfig"
121121

122122
source "drivers/bbram/Kconfig"
123123

124+
source "drivers/fpga/Kconfig"
125+
124126
endmenu

drivers/fpga/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
zephyr_library()

drivers/fpga/Kconfig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# FPGA driver configuration options
2+
3+
# Copyright (c) 2021 Antmicro <www.antmicro.com>
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
menuconfig FPGA
7+
bool "FPGA Drivers"
8+
help
9+
Enable support for FPGA drivers.
10+
11+
if FPGA
12+
13+
module = fpga
14+
module-str = fpga
15+
source "subsys/logging/Kconfig.template.log_config"
16+
17+
endif # FPGA

include/drivers/fpga.h

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
/*
2+
* Copyright (c) 2021 Antmicro <www.antmicro.com>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_INCLUDE_DRIVERS_FPGA_H_
8+
#define ZEPHYR_INCLUDE_DRIVERS_FPGA_H_
9+
10+
#include <zephyr/types.h>
11+
#include <sys/util.h>
12+
#include <device.h>
13+
14+
#ifdef __cplusplus
15+
extern "C" {
16+
#endif
17+
18+
enum FPGA_status {
19+
/* Inactive is when the FPGA cannot accept the bitstream
20+
* and will not be programmed correctly
21+
*/
22+
FPGA_STATUS_INACTIVE,
23+
/* Active is when the FPGA can accept the bitstream and
24+
* can be programmed correctly
25+
*/
26+
FPGA_STATUS_ACTIVE
27+
};
28+
29+
typedef enum FPGA_status (*fpga_api_get_status)(const struct device *dev);
30+
typedef int (*fpga_api_load)(const struct device *dev, uint32_t *image_ptr,
31+
uint32_t img_size);
32+
typedef int (*fpga_api_reset)(const struct device *dev);
33+
typedef int (*fpga_api_on)(const struct device *dev);
34+
typedef int (*fpga_api_off)(const struct device *dev);
35+
typedef const char *(*fpga_api_get_info)(const struct device *dev);
36+
37+
__subsystem struct fpga_driver_api {
38+
fpga_api_get_status get_status;
39+
fpga_api_reset reset;
40+
fpga_api_load load;
41+
fpga_api_on on;
42+
fpga_api_off off;
43+
fpga_api_get_info get_info;
44+
};
45+
46+
/**
47+
* @brief Read the status of FPGA.
48+
*
49+
* @param dev FPGA device structure.
50+
*
51+
* @retval 0 if the FPGA is in ACTIVE state.
52+
* @retval 1 if the FPGA is in INACTIVE state.
53+
*/
54+
static inline enum FPGA_status fpga_get_status(const struct device *dev)
55+
{
56+
const struct fpga_driver_api *api =
57+
(const struct fpga_driver_api *)dev->api;
58+
59+
return api->get_status(dev);
60+
}
61+
62+
/**
63+
* @brief Reset the FPGA.
64+
*
65+
* @param dev FPGA device structure.
66+
*
67+
* @retval 0 if successful.
68+
* @retval Failed Otherwise.
69+
*/
70+
static inline int fpga_reset(const struct device *dev)
71+
{
72+
const struct fpga_driver_api *api =
73+
(const struct fpga_driver_api *)dev->api;
74+
75+
return api->reset(dev);
76+
}
77+
78+
/**
79+
* @brief Load the bitstream and program the FPGA
80+
*
81+
* @param dev FPGA device structure.
82+
* @param image_ptr Pointer to bitstream.
83+
* @param img_size Bitstream size in bytes.
84+
*
85+
* @retval 0 if successful.
86+
* @retval Failed Otherwise.
87+
*/
88+
static inline int fpga_load(const struct device *dev, uint32_t *image_ptr,
89+
uint32_t img_size)
90+
{
91+
const struct fpga_driver_api *api =
92+
(const struct fpga_driver_api *)dev->api;
93+
94+
return api->load(dev, image_ptr, img_size);
95+
}
96+
97+
/**
98+
* @brief Turns on the FPGA.
99+
*
100+
* @param dev FPGA device structure.
101+
*
102+
* @retval 0 if successful.
103+
* @retval negative errno code on failure.
104+
*/
105+
static inline int fpga_on(const struct device *dev)
106+
{
107+
const struct fpga_driver_api *api =
108+
(const struct fpga_driver_api *)dev->api;
109+
110+
if (api->on == NULL) {
111+
return -ENOTSUP;
112+
}
113+
114+
return api->on(dev);
115+
}
116+
117+
/**
118+
* @brief Returns information about the FPGA.
119+
*
120+
* @param dev FPGA device structure.
121+
*
122+
* @return String containing information.
123+
*/
124+
static inline const char *fpga_get_info(const struct device *dev)
125+
{
126+
const struct fpga_driver_api *api =
127+
(const struct fpga_driver_api *)dev->api;
128+
129+
return api->get_info(dev);
130+
}
131+
132+
/**
133+
* @brief Turns off the FPGA.
134+
*
135+
* @param dev FPGA device structure.
136+
*
137+
* @retval 0 if successful.
138+
* @retval negative errno code on failure.
139+
*/
140+
static inline int fpga_off(const struct device *dev)
141+
{
142+
const struct fpga_driver_api *api =
143+
(const struct fpga_driver_api *)dev->api;
144+
145+
if (api->off == NULL) {
146+
return -ENOTSUP;
147+
}
148+
149+
return api->off(dev);
150+
}
151+
152+
#ifdef __cplusplus
153+
}
154+
#endif
155+
156+
#endif /* ZEPHYR_INCLUDE_DRIVERS_FPGA_H_ */

0 commit comments

Comments
 (0)