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__ */
83