Skip to content

Commit d28f80b

Browse files
committed
mpfs/mpfs_rcc: Add stub driver for FPGA clock and reset controller
This patch adds a driver framework to control individual FPGA reset and clock gates. For FPGA devices, only the fabric (FIC0/FIC1/FIC3) clock and reset can be controlled, which affects the whole fabric / domain. This is problematic for obvious reasons. For MSS peripherals, clocks and reset are controlled individually for each peripheral via MSS memory mapped registers (MPFS_SYSREG). To get the same capability for FPGA peripherals, the same controller needs to be fabricated on the FPGA. However, the FPGA clock/reset controller is entirely user dependent, so a generic implementation is not possible. However, a generic driver is needed in order to build the current FPGA peripheral drivers. A stub implementation of the driver is provided in order to achieve this.
1 parent f0f54be commit d28f80b

File tree

8 files changed

+271
-1
lines changed

8 files changed

+271
-1
lines changed

arch/risc-v/src/mpfs/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,12 @@ config MPFS_MPUCFG
813813
---help---
814814
Enable driver to set MPUCFG entries.
815815

816+
config MPFS_RCC
817+
bool "Enable Reset and Clock Controller (RCC) driver"
818+
default y
819+
---help---
820+
Enable driver for reset / clock controller.
821+
816822
config MPFS_HAVE_CORERMII
817823
bool "CoreRMII FPGA IP block configured"
818824
default n

arch/risc-v/src/mpfs/Make.defs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,6 @@ ifeq ($(CONFIG_MPFS_MPUCFG),y)
122122
CHIP_CSRCS += mpfs_mpu.c
123123
endif
124124

125+
ifeq ($(CONFIG_MPFS_RCC),y)
126+
CHIP_CSRCS += mpfs_rcc.c
127+
endif

arch/risc-v/src/mpfs/hardware/mpfs_sysreg.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@
137137
#define MPFS_SYSREG_SPARE_PERIM_RW_OFFSET 0x02DC /* Spare signal back to G5C */
138138
#define MPFS_SYSREG_SPARE_FIC_OFFSET 0x02E0 /* Unused FIC resets */
139139

140+
#define MPFS_SYSREG_SOFT_RESET_CR (MPFS_SYSREG_BASE + \
141+
MPFS_SYSREG_SOFT_RESET_CR_OFFSET)
142+
#define MPFS_SYSREG_SUBBLK_CLOCK_CR (MPFS_SYSREG_BASE + \
143+
MPFS_SYSREG_SUBBLK_CLOCK_CR_OFFSET)
144+
140145
/* Register bit field definitions *******************************************/
141146

142147
/* CLOCK_CONFIG_CR:

arch/risc-v/src/mpfs/mpfs_corepwm.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@
4444

4545
#include <arch/board/board.h>
4646

47+
#include "mpfs_rcc.h"
48+
49+
#include "hardware/mpfs_memorymap.h"
4750
#include "hardware/mpfs_corepwm.h"
51+
#include "hardware/mpfs_sysreg.h"
4852
#include "riscv_internal.h"
4953

5054
/****************************************************************************
@@ -752,6 +756,25 @@ static int pwm_ioctl(struct pwm_lowerhalf_s *dev, int cmd,
752756
return -ENOTTY;
753757
}
754758

759+
static int pwm_init(struct mpfs_pwmtimer_s *priv)
760+
{
761+
/* Toggle peripheral reset */
762+
763+
mpfs_set_reset(MPFS_RCC_I2C, priv->pwmid, 1);
764+
mpfs_set_reset(MPFS_RCC_I2C, priv->pwmid, 0);
765+
766+
/* Release FIC reset and enable clocks */
767+
768+
modifyreg32(MPFS_SYSREG_SOFT_RESET_CR,
769+
SYSREG_SOFT_RESET_CR_FIC3 | SYSREG_SOFT_RESET_CR_FPGA,
770+
0);
771+
772+
modifyreg32(MPFS_SYSREG_SUBBLK_CLOCK_CR, 0,
773+
SYSREG_SUBBLK_CLOCK_CR_FIC3);
774+
775+
return OK;
776+
}
777+
755778
/****************************************************************************
756779
* Public Functions
757780
****************************************************************************/
@@ -795,6 +818,7 @@ struct pwm_lowerhalf_s *mpfs_corepwm_init(int pwmid)
795818
return NULL;
796819
}
797820

821+
pwm_init(lower);
822+
798823
return (struct pwm_lowerhalf_s *)lower;
799824
}
800-

arch/risc-v/src/mpfs/mpfs_corespi.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
#include "mpfs_gpio.h"
4646
#include "mpfs_corespi.h"
47+
#include "mpfs_rcc.h"
4748
#include "hardware/mpfs_corespi.h"
4849
#include "hardware/mpfs_sysreg.h"
4950
#include "riscv_internal.h"
@@ -1513,6 +1514,11 @@ static void mpfs_spi_init(struct spi_dev_s *dev)
15131514

15141515
up_disable_irq(priv->plic_irq);
15151516

1517+
/* Toggle peripheral reset */
1518+
1519+
mpfs_set_reset(MPFS_RCC_SPI, priv->id, 1);
1520+
mpfs_set_reset(MPFS_RCC_SPI, priv->id, 0);
1521+
15161522
/* Release FIC reset and enable clocks */
15171523

15181524
modifyreg32(MPFS_SYSREG_SOFT_RESET_CR,

arch/risc-v/src/mpfs/mpfs_i2c.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848

4949
#include "mpfs_gpio.h"
5050
#include "mpfs_i2c.h"
51+
#include "mpfs_rcc.h"
5152
#include "riscv_internal.h"
5253
#include "hardware/mpfs_i2c.h"
5354

@@ -369,6 +370,11 @@ static int mpfs_i2c_init(struct mpfs_i2c_priv_s *priv)
369370

370371
if (priv->fpga)
371372
{
373+
/* Toggle peripheral reset */
374+
375+
mpfs_set_reset(MPFS_RCC_I2C, priv->id, 1);
376+
mpfs_set_reset(MPFS_RCC_I2C, priv->id, 0);
377+
372378
/* FIC3 is used by many, don't reset it here, or many
373379
* FPGA based modules will stop working right here. Just
374380
* bring out of reset instead.

arch/risc-v/src/mpfs/mpfs_rcc.c

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/****************************************************************************
2+
* arch/risc-v/src/mpfs/mpfs_rcc.c
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed to the Apache Software Foundation (ASF) under one or more
7+
* contributor license agreements. See the NOTICE file distributed with
8+
* this work for additional information regarding copyright ownership. The
9+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
10+
* "License"); you may not use this file except in compliance with the
11+
* License. You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
* License for the specific language governing permissions and limitations
19+
* under the License.
20+
*
21+
****************************************************************************/
22+
23+
/****************************************************************************
24+
* Included Files
25+
****************************************************************************/
26+
27+
#include <nuttx/config.h>
28+
29+
#include <nuttx/spinlock.h>
30+
31+
#include <errno.h>
32+
#include <sys/types.h>
33+
34+
#include "mpfs_rcc.h"
35+
#include "mpfs_memorymap.h"
36+
37+
#include "riscv_internal.h"
38+
39+
/****************************************************************************
40+
* Pre-processor Definitions
41+
****************************************************************************/
42+
43+
/****************************************************************************
44+
* Private Types
45+
****************************************************************************/
46+
47+
/****************************************************************************
48+
* Private Data
49+
****************************************************************************/
50+
51+
/****************************************************************************
52+
* Private Functions
53+
****************************************************************************/
54+
55+
/****************************************************************************
56+
* Public Function Prototypes
57+
****************************************************************************/
58+
59+
/****************************************************************************
60+
* Name: mpfs_set_reset
61+
*
62+
* Description:
63+
* Enable / disable peripheral reset.
64+
*
65+
* Input Parameters:
66+
* rcc_id - Device id.
67+
* instance - Optional instance number for device.
68+
*
69+
* Returned Value:
70+
* Zero (OK) is returned on success; a negated errno value is returned on
71+
* any failure.
72+
*
73+
****************************************************************************/
74+
75+
int mpfs_set_reset(int rcc_id, int instance, bool state)
76+
{
77+
return -ENODEV;
78+
}
79+
80+
/****************************************************************************
81+
* Name: mpfs_set_clock
82+
*
83+
* Description:
84+
* Enable / disable peripheral clock.
85+
*
86+
* Input Parameters:
87+
* rcc_id - Device id.
88+
* instance - Optional instance number for device.
89+
*
90+
* Returned Value:
91+
* Zero (OK) is returned on success; a negated errno value is returned on
92+
* any failure.
93+
*
94+
****************************************************************************/
95+
96+
int mpfs_set_clock(int rcc_id, int instance, bool state)
97+
{
98+
return -ENODEV;
99+
}

arch/risc-v/src/mpfs/mpfs_rcc.h

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/****************************************************************************
2+
* arch/risc-v/src/mpfs/mpfs_rcc.h
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed to the Apache Software Foundation (ASF) under one or more
7+
* contributor license agreements. See the NOTICE file distributed with
8+
* this work for additional information regarding copyright ownership. The
9+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
10+
* "License"); you may not use this file except in compliance with the
11+
* License. You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
* License for the specific language governing permissions and limitations
19+
* under the License.
20+
*
21+
****************************************************************************/
22+
23+
#ifndef ARCH_RISC_V_SRC_MPFS_MPFS_RCC_H
24+
#define ARCH_RISC_V_SRC_MPFS_MPFS_RCC_H
25+
26+
/****************************************************************************
27+
* Included Files
28+
****************************************************************************/
29+
30+
#include <nuttx/config.h>
31+
32+
#include <stdint.h>
33+
34+
/****************************************************************************
35+
* Pre-processor Definitions
36+
****************************************************************************/
37+
38+
/****************************************************************************
39+
* Public Types
40+
****************************************************************************/
41+
42+
enum mpfs_rcc_id_e
43+
{
44+
MPFS_RCC_CAN,
45+
MPFS_RCC_I2C,
46+
MPFS_RCC_PWM,
47+
MPFS_RCC_SPI,
48+
MPFS_RCC_UART,
49+
MPFS_RCC_LAST,
50+
};
51+
52+
#ifndef __ASSEMBLY__
53+
54+
/****************************************************************************
55+
* Public Data
56+
****************************************************************************/
57+
58+
#undef EXTERN
59+
#if defined(__cplusplus)
60+
#define EXTERN extern "C"
61+
extern "C"
62+
{
63+
#else
64+
#define EXTERN extern
65+
#endif
66+
67+
/****************************************************************************
68+
* Public Function Prototypes
69+
****************************************************************************/
70+
71+
/****************************************************************************
72+
* Name: mpfs_set_reset
73+
*
74+
* Description:
75+
* Enable / disable peripheral reset.
76+
*
77+
* Input Parameters:
78+
* rcc_id - Device id.
79+
* instance - Optional instance number for device.
80+
*
81+
* Returned Value:
82+
* Zero (OK) is returned on success; a negated errno value is returned on
83+
* any failure.
84+
*
85+
****************************************************************************/
86+
87+
#ifdef CONFIG_MPFS_RCC
88+
int mpfs_set_reset(int rcc_id, int instance, bool state);
89+
#else
90+
# define mpfs_set_reset(rcc_id, instance, state) (0)
91+
#endif
92+
93+
/****************************************************************************
94+
* Name: mpfs_set_clock
95+
*
96+
* Description:
97+
* Enable / disable peripheral clock.
98+
*
99+
* Input Parameters:
100+
* rcc_id - Device id.
101+
* instance - Optional instance number for device.
102+
*
103+
* Returned Value:
104+
* Zero (OK) is returned on success; a negated errno value is returned on
105+
* any failure.
106+
*
107+
****************************************************************************/
108+
109+
#ifdef CONFIG_MPFS_RCC
110+
int mpfs_set_clock(int rcc_id, int instance, bool state);
111+
#else
112+
# define mpfs_set_clock(rcc_id, instance, state) (0)
113+
#endif
114+
115+
#if defined(__cplusplus)
116+
}
117+
#endif
118+
#undef EXTERN
119+
120+
#endif /* __ASSEMBLY__ */
121+
#endif /* ARCH_RISC_V_SRC_MPFS_MPFS_RCC_H */

0 commit comments

Comments
 (0)