xref: /OK3568_Linux_fs/kernel/include/linux/reset-controller.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun #ifndef _LINUX_RESET_CONTROLLER_H_
3*4882a593Smuzhiyun #define _LINUX_RESET_CONTROLLER_H_
4*4882a593Smuzhiyun 
5*4882a593Smuzhiyun #include <linux/list.h>
6*4882a593Smuzhiyun 
7*4882a593Smuzhiyun struct reset_controller_dev;
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun /**
10*4882a593Smuzhiyun  * struct reset_control_ops - reset controller driver callbacks
11*4882a593Smuzhiyun  *
12*4882a593Smuzhiyun  * @reset: for self-deasserting resets, does all necessary
13*4882a593Smuzhiyun  *         things to reset the device
14*4882a593Smuzhiyun  * @assert: manually assert the reset line, if supported
15*4882a593Smuzhiyun  * @deassert: manually deassert the reset line, if supported
16*4882a593Smuzhiyun  * @status: return the status of the reset line, if supported
17*4882a593Smuzhiyun  */
18*4882a593Smuzhiyun struct reset_control_ops {
19*4882a593Smuzhiyun 	int (*reset)(struct reset_controller_dev *rcdev, unsigned long id);
20*4882a593Smuzhiyun 	int (*assert)(struct reset_controller_dev *rcdev, unsigned long id);
21*4882a593Smuzhiyun 	int (*deassert)(struct reset_controller_dev *rcdev, unsigned long id);
22*4882a593Smuzhiyun 	int (*status)(struct reset_controller_dev *rcdev, unsigned long id);
23*4882a593Smuzhiyun };
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun struct module;
26*4882a593Smuzhiyun struct device_node;
27*4882a593Smuzhiyun struct of_phandle_args;
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun /**
30*4882a593Smuzhiyun  * struct reset_control_lookup - represents a single lookup entry
31*4882a593Smuzhiyun  *
32*4882a593Smuzhiyun  * @list: internal list of all reset lookup entries
33*4882a593Smuzhiyun  * @provider: name of the reset controller device controlling this reset line
34*4882a593Smuzhiyun  * @index: ID of the reset controller in the reset controller device
35*4882a593Smuzhiyun  * @dev_id: name of the device associated with this reset line
36*4882a593Smuzhiyun  * @con_id: name of the reset line (can be NULL)
37*4882a593Smuzhiyun  */
38*4882a593Smuzhiyun struct reset_control_lookup {
39*4882a593Smuzhiyun 	struct list_head list;
40*4882a593Smuzhiyun 	const char *provider;
41*4882a593Smuzhiyun 	unsigned int index;
42*4882a593Smuzhiyun 	const char *dev_id;
43*4882a593Smuzhiyun 	const char *con_id;
44*4882a593Smuzhiyun };
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun #define RESET_LOOKUP(_provider, _index, _dev_id, _con_id)		\
47*4882a593Smuzhiyun 	{								\
48*4882a593Smuzhiyun 		.provider = _provider,					\
49*4882a593Smuzhiyun 		.index = _index,					\
50*4882a593Smuzhiyun 		.dev_id = _dev_id,					\
51*4882a593Smuzhiyun 		.con_id = _con_id,					\
52*4882a593Smuzhiyun 	}
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun /**
55*4882a593Smuzhiyun  * struct reset_controller_dev - reset controller entity that might
56*4882a593Smuzhiyun  *                               provide multiple reset controls
57*4882a593Smuzhiyun  * @ops: a pointer to device specific struct reset_control_ops
58*4882a593Smuzhiyun  * @owner: kernel module of the reset controller driver
59*4882a593Smuzhiyun  * @list: internal list of reset controller devices
60*4882a593Smuzhiyun  * @reset_control_head: head of internal list of requested reset controls
61*4882a593Smuzhiyun  * @dev: corresponding driver model device struct
62*4882a593Smuzhiyun  * @of_node: corresponding device tree node as phandle target
63*4882a593Smuzhiyun  * @of_reset_n_cells: number of cells in reset line specifiers
64*4882a593Smuzhiyun  * @of_xlate: translation function to translate from specifier as found in the
65*4882a593Smuzhiyun  *            device tree to id as given to the reset control ops, defaults
66*4882a593Smuzhiyun  *            to :c:func:`of_reset_simple_xlate`.
67*4882a593Smuzhiyun  * @nr_resets: number of reset controls in this reset controller device
68*4882a593Smuzhiyun  */
69*4882a593Smuzhiyun struct reset_controller_dev {
70*4882a593Smuzhiyun 	const struct reset_control_ops *ops;
71*4882a593Smuzhiyun 	struct module *owner;
72*4882a593Smuzhiyun 	struct list_head list;
73*4882a593Smuzhiyun 	struct list_head reset_control_head;
74*4882a593Smuzhiyun 	struct device *dev;
75*4882a593Smuzhiyun 	struct device_node *of_node;
76*4882a593Smuzhiyun 	int of_reset_n_cells;
77*4882a593Smuzhiyun 	int (*of_xlate)(struct reset_controller_dev *rcdev,
78*4882a593Smuzhiyun 			const struct of_phandle_args *reset_spec);
79*4882a593Smuzhiyun 	unsigned int nr_resets;
80*4882a593Smuzhiyun };
81*4882a593Smuzhiyun 
82*4882a593Smuzhiyun int reset_controller_register(struct reset_controller_dev *rcdev);
83*4882a593Smuzhiyun void reset_controller_unregister(struct reset_controller_dev *rcdev);
84*4882a593Smuzhiyun 
85*4882a593Smuzhiyun struct device;
86*4882a593Smuzhiyun int devm_reset_controller_register(struct device *dev,
87*4882a593Smuzhiyun 				   struct reset_controller_dev *rcdev);
88*4882a593Smuzhiyun 
89*4882a593Smuzhiyun void reset_controller_add_lookup(struct reset_control_lookup *lookup,
90*4882a593Smuzhiyun 				 unsigned int num_entries);
91*4882a593Smuzhiyun 
92*4882a593Smuzhiyun #endif
93