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