Skip to content

Commit 66df489

Browse files
committed
[DM/FEATURE] Support reset controller
Reset controllers are central units that control the reset signals to multiple peripherals. The reset controller API is split into two parts: 1. The consumer driver interface, which allows peripheral drivers to request control over their reset input signals 2. The reset controller driver interface which is used by drivers for reset controller devices to register their reset controls to provide them to the consumers. Signed-off-by: GuEe-GUI <[email protected]>
1 parent fed7c9a commit 66df489

File tree

7 files changed

+546
-0
lines changed

7 files changed

+546
-0
lines changed

components/drivers/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ rsource "touch/Kconfig"
2121
rsource "graphic/Kconfig"
2222
rsource "hwcrypto/Kconfig"
2323
rsource "wlan/Kconfig"
24+
rsource "reset/Kconfig"
2425
rsource "virtio/Kconfig"
2526
rsource "ofw/Kconfig"
2627
rsource "pci/Kconfig"
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Copyright (c) 2006-2022, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2022-11-26 GuEe-GUI first version
9+
*/
10+
11+
#ifndef __RESET_H__
12+
#define __RESET_H__
13+
14+
#include <rthw.h>
15+
#include <rtthread.h>
16+
#include <drivers/ofw.h>
17+
18+
#define RT_RESET_CONTROLLER_OBJ_NAME "RSTC"
19+
20+
struct rt_reset_control_ops;
21+
22+
struct rt_reset_controller
23+
{
24+
struct rt_object parent;
25+
26+
rt_list_t rstc_nodes;
27+
28+
const char *name;
29+
const struct rt_reset_control_ops *ops;
30+
31+
struct rt_ofw_node *ofw_node;
32+
void *priv;
33+
34+
struct rt_spinlock spinlock;
35+
};
36+
37+
struct rt_reset_control
38+
{
39+
rt_list_t list;
40+
41+
struct rt_reset_controller *rstcer;
42+
43+
int id;
44+
const char *con_id;
45+
rt_bool_t is_array;
46+
47+
void *priv;
48+
};
49+
50+
struct rt_reset_control_ops
51+
{
52+
/*
53+
* rt_ofw_cell_args return:
54+
* args[0] = rstc.id
55+
*/
56+
rt_err_t (*ofw_parse)(struct rt_reset_control *rstc, struct rt_ofw_cell_args *args);
57+
/* API */
58+
rt_err_t (*reset)(struct rt_reset_control *rstc);
59+
rt_err_t (*assert)(struct rt_reset_control *rstc);
60+
rt_err_t (*deassert)(struct rt_reset_control *rstc);
61+
int (*status)(struct rt_reset_control *rstc);
62+
};
63+
64+
rt_err_t rt_reset_controller_register(struct rt_reset_controller *rstcer);
65+
rt_err_t rt_reset_controller_unregister(struct rt_reset_controller *rstcer);
66+
67+
rt_err_t rt_reset_control_reset(struct rt_reset_control *rstc);
68+
rt_err_t rt_reset_control_assert(struct rt_reset_control *rstc);
69+
rt_err_t rt_reset_control_deassert(struct rt_reset_control *rstc);
70+
int rt_reset_control_status(struct rt_reset_control *rstc);
71+
72+
rt_ssize_t rt_reset_control_get_count(struct rt_device *dev);
73+
struct rt_reset_control *rt_reset_control_get_array(struct rt_device *dev);
74+
struct rt_reset_control *rt_reset_control_get_by_index(struct rt_device *dev, int index);
75+
struct rt_reset_control *rt_reset_control_get_by_name(struct rt_device *dev, const char *name);
76+
void rt_reset_control_put(struct rt_reset_control *rstc);
77+
78+
struct rt_reset_control *rt_ofw_get_reset_control_array(struct rt_ofw_node *np);
79+
struct rt_reset_control *rt_ofw_get_reset_control_by_index(struct rt_ofw_node *np, int index);
80+
struct rt_reset_control *rt_ofw_get_reset_control_by_name(struct rt_ofw_node *np, const char *name);
81+
82+
#endif /* __RESET_H__ */

components/drivers/include/rtdevice.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ extern "C" {
5656
#ifdef RT_USING_PIC
5757
#include "drivers/pic.h"
5858
#endif
59+
60+
#ifdef RT_USING_RESET
61+
#include "drivers/reset.h"
62+
#endif
5963
#endif /* RT_USING_DM */
6064

6165
#ifdef RT_USING_RTC

components/drivers/ofw/ofw.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ struct ofw_obj_cmp_list
6969

7070
static const struct ofw_obj_cmp_list ofw_obj_cmp_list[] =
7171
{
72+
#ifdef RT_USING_RESET
73+
{ "#reset-cells", RT_RESET_CONTROLLER_OBJ_NAME, sizeof(struct rt_reset_controller) },
74+
#endif
7275
{ "#power-domain-cells", RT_POWER_DOMAIN_PROXY_OBJ_NAME, sizeof(struct rt_dm_power_domain_proxy) },
7376
{ "#power-domain-cells", RT_POWER_DOMAIN_OBJ_NAME, sizeof(struct rt_dm_power_domain) },
7477
};

components/drivers/reset/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
menuconfig RT_USING_RESET
2+
bool "Using Reset Controller support"
3+
depends on RT_USING_DM
4+
depends on RT_USING_OFW
5+
default n
6+
7+
if RT_USING_RESET
8+
osource "$(SOC_DM_RESET_DIR)/Kconfig"
9+
endif
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from building import *
2+
3+
group = []
4+
5+
if not GetDepend(['RT_USING_RESET']):
6+
Return('group')
7+
8+
cwd = GetCurrentDir()
9+
CPPPATH = [cwd + '/../include']
10+
11+
src = ['reset.c']
12+
13+
group = DefineGroup('DeviceDrivers', src, depend = [''], CPPPATH = CPPPATH)
14+
15+
Return('group')

0 commit comments

Comments
 (0)