Skip to content

Commit a64ce1f

Browse files
msierszulskicfriedt
authored andcommitted
drivers: fpga controller: add eos_s3 fpga driver
This adds driver for EOS_S3 SoC FPGA. Signed-off-by: Mateusz Sierszulski <[email protected]> Signed-off-by: Tomasz Gorochowik <[email protected]>
1 parent 2c718b2 commit a64ce1f

File tree

13 files changed

+5752
-0
lines changed

13 files changed

+5752
-0
lines changed

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@
232232
/drivers/flash/ @nashif @nvlsianpu
233233
/drivers/flash/*b91* @yurvyn
234234
/drivers/flash/*nrf* @nvlsianpu
235+
/drivers/fpga/ @tgorochowik @kgugala
235236
/drivers/gpio/ @mnkp
236237
/drivers/gpio/*b91* @yurvyn
237238
/drivers/gpio/*lmp90xxx* @henrikbrixandersen

boards/arm/quick_feather/quick_feather.dts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@
5050
label = "User Push Button 0";
5151
};
5252
};
53+
54+
fpga {
55+
status = "okay";
56+
};
5357
};
5458

5559
&cpu0 {

drivers/fpga/CMakeLists.txt

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

33
zephyr_library()
4+
5+
zephyr_library_sources_ifdef(CONFIG_EOS_S3_FPGA fpga_eos_s3.c)

drivers/fpga/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ module = fpga
1414
module-str = fpga
1515
source "subsys/logging/Kconfig.template.log_config"
1616

17+
source "drivers/fpga/Kconfig.eos_s3"
18+
1719
endif # FPGA

drivers/fpga/Kconfig.eos_s3

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# FPGA EOS S3 driver configuration options
2+
3+
# Copyright (c) 2021 Antmicro <www.antmicro.com>
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
config EOS_S3_FPGA
7+
bool "EOS S3 fpga driver"
8+
help
9+
Enable EOS S3 FPGA driver.

drivers/fpga/fpga_eos_s3.c

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
/*
2+
* Copyright (c) 2021 Antmicro <www.antmicro.com>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <errno.h>
8+
#include <string.h>
9+
#include <device.h>
10+
#include <drivers/fpga.h>
11+
#include "fpga_eos_s3.h"
12+
13+
void eos_s3_fpga_enable_clk(void)
14+
{
15+
CRU->C16_CLK_GATE = C16_CLK_GATE_PATH_0_ON;
16+
CRU->C21_CLK_GATE = C21_CLK_GATE_PATH_0_ON;
17+
CRU->C09_CLK_GATE = C09_CLK_GATE_PATH_1_ON | C09_CLK_GATE_PATH_2_ON;
18+
CRU->C02_CLK_GATE = C02_CLK_GATE_PATH_1_ON;
19+
}
20+
21+
void eos_s3_fpga_disable_clk(void)
22+
{
23+
CRU->C16_CLK_GATE = C16_CLK_GATE_PATH_0_OFF;
24+
CRU->C21_CLK_GATE = C21_CLK_GATE_PATH_0_OFF;
25+
CRU->C09_CLK_GATE = C09_CLK_GATE_PATH_1_OFF | C09_CLK_GATE_PATH_2_OFF;
26+
CRU->C02_CLK_GATE = C02_CLK_GATE_PATH_1_OFF;
27+
}
28+
29+
struct quickfeather_fpga_data {
30+
char *FPGA_info;
31+
};
32+
33+
static enum FPGA_status eos_s3_fpga_get_status(const struct device *dev)
34+
{
35+
ARG_UNUSED(dev);
36+
37+
if (PMU->FB_STATUS == FPGA_STATUS_ACTIVE) {
38+
return FPGA_STATUS_ACTIVE;
39+
} else
40+
return FPGA_STATUS_INACTIVE;
41+
}
42+
43+
static const char *eos_s3_fpga_get_info(const struct device *dev)
44+
{
45+
struct quickfeather_fpga_data *data = dev->data;
46+
47+
return data->FPGA_info;
48+
}
49+
50+
static int eos_s3_fpga_on(const struct device *dev)
51+
{
52+
if (eos_s3_fpga_get_status(dev) == FPGA_STATUS_ACTIVE) {
53+
return 0;
54+
}
55+
56+
/* wake up the FPGA power domain */
57+
PMU->FFE_FB_PF_SW_WU = PMU_FFE_FB_PF_SW_WU_FB_WU;
58+
while (PMU->FFE_FB_PF_SW_WU == PMU_FFE_FB_PF_SW_WU_FB_WU) {
59+
/* The register will clear itself if the FPGA starts */
60+
};
61+
62+
eos_s3_fpga_enable_clk();
63+
64+
/* enable FPGA programming */
65+
PMU->GEN_PURPOSE_0 = FB_CFG_ENABLE;
66+
PIF->CFG_CTL = CFG_CTL_LOAD_ENABLE;
67+
68+
return 0;
69+
}
70+
71+
static int eos_s3_fpga_off(const struct device *dev)
72+
{
73+
if (eos_s3_fpga_get_status(dev) == FPGA_STATUS_INACTIVE) {
74+
return 0;
75+
}
76+
77+
PMU->FB_PWR_MODE_CFG = PMU_FB_PWR_MODE_CFG_FB_SD;
78+
PMU->FFE_FB_PF_SW_PD = PMU_FFE_FB_PF_SW_PD_FB_PD;
79+
80+
eos_s3_fpga_disable_clk();
81+
82+
return 0;
83+
}
84+
85+
static int eos_s3_fpga_reset(const struct device *dev)
86+
{
87+
if (eos_s3_fpga_get_status(dev) == FPGA_STATUS_ACTIVE) {
88+
eos_s3_fpga_off(dev);
89+
}
90+
91+
eos_s3_fpga_on(dev);
92+
93+
if (eos_s3_fpga_get_status(dev) == FPGA_STATUS_INACTIVE) {
94+
return -EAGAIN;
95+
}
96+
97+
return 0;
98+
}
99+
100+
static int eos_s3_fpga_load(const struct device *dev, uint32_t *image_ptr, uint32_t img_size)
101+
{
102+
if (eos_s3_fpga_get_status(dev) == FPGA_STATUS_INACTIVE) {
103+
return -EINVAL;
104+
}
105+
106+
volatile uint32_t *bitstream = (volatile uint32_t *)image_ptr;
107+
108+
for (uint32_t chunk_cnt = 0; chunk_cnt < (img_size / 4); chunk_cnt++) {
109+
PIF->CFG_DATA = *bitstream;
110+
bitstream++;
111+
}
112+
113+
/* disable FPGA programming */
114+
PMU->GEN_PURPOSE_0 = FB_CFG_DISABLE;
115+
PIF->CFG_CTL = CFG_CTL_LOAD_DISABLE;
116+
PMU->FB_ISOLATION = FB_ISOLATION_DISABLE;
117+
118+
return 0;
119+
}
120+
121+
static int eos_s3_fpga_init(const struct device *dev)
122+
{
123+
IO_MUX->PAD_19_CTRL = PAD_ENABLE;
124+
125+
struct quickfeather_fpga_data *data = dev->data;
126+
127+
data->FPGA_info = FPGA_INFO;
128+
129+
eos_s3_fpga_reset(dev);
130+
131+
return 0;
132+
}
133+
134+
static struct quickfeather_fpga_data fpga_data;
135+
136+
static const struct fpga_driver_api eos_s3_api = {
137+
.reset = eos_s3_fpga_reset,
138+
.load = eos_s3_fpga_load,
139+
.get_status = eos_s3_fpga_get_status,
140+
.on = eos_s3_fpga_on,
141+
.off = eos_s3_fpga_off,
142+
.get_info = eos_s3_fpga_get_info
143+
};
144+
145+
DEVICE_DEFINE(fpga, "FPGA", &eos_s3_fpga_init, NULL, &fpga_data, NULL, APPLICATION,
146+
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &eos_s3_api);

drivers/fpga/fpga_eos_s3.h

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright (c) 2021 Antmicro <www.antmicro.com>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_DRIVERS_FPGA_EOS_S3_H_
8+
#define ZEPHYR_DRIVERS_FPGA_EOS_S3_H_
9+
10+
#include <eoss3_dev.h>
11+
12+
struct PIF_struct {
13+
/* Fabric Configuration Control Register, offset: 0x000 */
14+
__IO uint32_t CFG_CTL;
15+
/* Maximum Bit Length Count, offset: 0x004 */
16+
__IO uint32_t MAX_BL_CNT;
17+
/* Maximum Word Length Count, offset: 0x008 */
18+
__IO uint32_t MAX_WL_CNT;
19+
uint32_t reserved[1020];
20+
/* Configuration Data, offset: 0xFFC */
21+
__IO uint32_t CFG_DATA;
22+
};
23+
24+
#define PIF ((struct PIF_struct *)PIF_CTRL_BASE)
25+
26+
#define FB_CFG_ENABLE ((uint32_t)(0x00000200))
27+
#define FB_CFG_DISABLE ((uint32_t)(0x00000000))
28+
29+
#define CFG_CTL_APB_CFG_WR ((uint32_t)(0x00008000))
30+
#define CFG_CTL_APB_CFG_RD ((uint32_t)(0x00004000))
31+
#define CFG_CTL_APB_WL_DIN ((uint32_t)(0x00003C00))
32+
#define CFG_CTL_APB_PARTIAL_LOAD ((uint32_t)(0x00000200))
33+
#define CFG_CTL_APB_BL_SEL ((uint32_t)(0x00000100))
34+
#define CFG_CTL_APB_BLM_SEL ((uint32_t)(0x00000080))
35+
#define CFG_CTL_APB_BR_SEL ((uint32_t)(0x00000040))
36+
#define CFG_CTL_APB_BRM_SEL ((uint32_t)(0x00000020))
37+
#define CFG_CTL_APB_TL_SEL ((uint32_t)(0x00000010))
38+
#define CFG_CTL_APB_TLM_SEL ((uint32_t)(0x00000008))
39+
#define CFG_CTL_APB_TR_SEL ((uint32_t)(0x00000004))
40+
#define CFG_CTL_APB_TRM_SEL ((uint32_t)(0x00000002))
41+
#define CFG_CTL_APB_SEL_CFG ((uint32_t)(0x00000001))
42+
43+
#define FB_ISOLATION_ENABLE ((uint32_t)(0x00000001))
44+
#define FB_ISOLATION_DISABLE ((uint32_t)(0x00000000))
45+
46+
#define PMU_FFE_FB_PF_SW_PD_FB_PD ((uint32_t)(0x00000002))
47+
#define PMU_FB_PWR_MODE_CFG_FB_SD ((uint32_t)(0x00000002))
48+
#define PMU_FB_PWR_MODE_CFG_FB_DP ((uint32_t)(0x00000001))
49+
50+
#define FPGA_INFO \
51+
"eos_s3 eFPGA features:\n" \
52+
"891 Logic Cells\n" \
53+
"8 FIFO Controllers\n" \
54+
"32 Configurable Interfaces\n" \
55+
"2x32x32(or 4x16x16) Multiplier\n" \
56+
"64Kbit SRAM\n"
57+
58+
#define PAD_ENABLE \
59+
(PAD_E_4MA | PAD_P_PULLDOWN | PAD_OEN_NORMAL | PAD_SMT_DISABLE | PAD_REN_DISABLE | \
60+
PAD_SR_SLOW | PAD_CTRL_SEL_AO_REG)
61+
62+
#define PAD_DISABLE \
63+
(PAD_SMT_DISABLE | PAD_REN_DISABLE | PAD_SR_SLOW | PAD_E_4MA | PAD_P_PULLDOWN | \
64+
PAD_OEN_NORMAL | PAD_CTRL_SEL_AO_REG)
65+
66+
#define CFG_CTL_LOAD_ENABLE \
67+
(CFG_CTL_APB_CFG_WR | CFG_CTL_APB_WL_DIN | CFG_CTL_APB_BL_SEL | CFG_CTL_APB_BLM_SEL | \
68+
CFG_CTL_APB_BR_SEL | CFG_CTL_APB_BRM_SEL | CFG_CTL_APB_TL_SEL | CFG_CTL_APB_TLM_SEL | \
69+
CFG_CTL_APB_TR_SEL | CFG_CTL_APB_TRM_SEL | CFG_CTL_APB_SEL_CFG)
70+
71+
#define CFG_CTL_LOAD_DISABLE 0
72+
73+
#endif /* ZEPHYR_DRIVERS_FPGA_EOS_S3_H_ */
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.13)
4+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
5+
project(fpga_controller)
6+
7+
target_sources(app PRIVATE src/main.c)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Zephyr FPGA controller
2+
This module is an FPGA driver that can easily load a bitstream, reset it, check its status, enable or disable the FPGA.
3+
This sample demonstrates how to use the FPGA driver API.
4+
Currently the sample works with [Quicklogic Quickfeather board](https://github.com/QuickLogic-Corp/quick-feather-dev-board).
5+
6+
## Requirements
7+
* Zephyr RTOS
8+
* [Quicklogic Quickfeather board](https://github.com/QuickLogic-Corp/quick-feather-dev-board)
9+
10+
## Building
11+
12+
For the QuickLogic QuickFeather board:
13+
```bash
14+
west build -b quick_feather samples/drivers/fpga/fpga_controller
15+
```
16+
17+
## Running
18+
See [QuickFeather programming and debugging](https://docs.zephyrproject.org/latest/boards/arm/quick_feather/doc/index.html#programming-and-debugging) on how to load an image to the board.
19+
20+
## Sample output
21+
Once the board is programmed, the LED should alternately flash red and green.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CONFIG_FPGA=y
2+
CONFIG_EOS_S3_FPGA=y

0 commit comments

Comments
 (0)