1 /**
2  * Copyright (C) 2015-2021 Alibaba Group Holding Limited
3  */
4 
5 #ifndef _U_DRIVER_H_
6 #define _U_DRIVER_H_
7 
8 #include <drivers/spinlock.h>
9 
10 enum U_PM_EVENT {
11 	E_PM_ENTER,
12 	E_PM_L0,
13 	E_PM_L1,
14 	E_PM_EXIT,
15 };
16 
17 // TODO: should move this to power manager header file
18 typedef struct u_pm_ops {
19 	int event;
20 } u_pm_ops_t;
21 
22 /**
23  * struct u_driver_private - driver private information
24  * should only be accessed by char_core
25  * @dev_list: device list driven by this driver
26  * @bus_node: node in bus driver list
27  *
28  * */
29 typedef struct u_driver_private {
30 	spinlock_t lock;
31 	struct dlist_s dev_list;
32 	struct dlist_s bus_node;
33 	struct u_driver *drv;
34 } u_driver_private_t;
35 
36 
37 /**
38  * struct u_bus - bus struct, virtual or hardware bus
39  *
40  * @name: driver name
41  * @next: driver list
42  * @bus: bus pointer to which the driver belongs
43  * */
44 typedef struct u_driver {
45 	char *name;
46 	struct u_bus *bus;
47 	u_driver_private_t *p;
48 
49 	// for legacy drivers
50 	int (*init)(struct u_device *dev);
51 	int (*deinit)(struct u_device *dev);
52 	int (*pm)(struct u_device *dev, u_pm_ops_t state);
53 
54 	// for linux-like drivers
55 	int (*probe)(struct u_device *dev);
56 	int (*remove)(struct u_device *dev);
57 	void (*shutdown)(struct u_device *dev);
58 	int (*suspend)(struct u_device *dev, u_pm_ops_t state);
59 	int (*resume)(struct u_device *dev);
60 
61 	// TODO: when receive IPC ping message call on_ping
62 	int (*on_ping)(struct u_device *dev);
63 
64 } u_driver_t;
65 
66 /**
67  * register a driver into system, init it's private struct before add it into system
68  *
69  * @param drv - pointer to target driver to be registered
70  * @return 0 for success; negative for failure
71  */
72 int u_driver_register(struct u_driver *drv);
73 
74 /**
75  * unregister a driver from system
76  * delete it and then free its private struct
77  *
78  * @param drv - pointer to target driver to be registered
79  * @return 0 for success; negative for failure
80  */
81 int u_driver_unregister(struct u_driver *drv);
82 
83 /**
84  * dump driver information
85  *
86  * @param drv - pointer to target driver to be dumped
87  * @return 0 for success; -1 for failure
88  *
89  */
90 int u_driver_dump(struct u_driver *drv);
91 
92 #endif //_U_DRIVER_H_
93