1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (c) 2023 Ideas On Board Oy
4  */
5 
6 #ifndef _VCHIQ_DEVICE_H
7 #define _VCHIQ_DEVICE_H
8 
9 #include <linux/device.h>
10 #include <linux/mod_devicetable.h>
11 
12 struct vchiq_device {
13 	struct device dev;
14 };
15 
16 struct vchiq_driver {
17 	int		(*probe)(struct vchiq_device *device);
18 	void		(*remove)(struct vchiq_device *device);
19 	int		(*resume)(struct vchiq_device *device);
20 	int		(*suspend)(struct vchiq_device *device,
21 				   pm_message_t state);
22 
23 	const struct vchiq_device_id *id_table;
24 	struct device_driver driver;
25 };
26 
27 static inline struct vchiq_device *to_vchiq_device(struct device *d)
28 {
29 	return container_of(d, struct vchiq_device, dev);
30 }
31 
32 static inline struct vchiq_driver *to_vchiq_driver(struct device_driver *d)
33 {
34 	return container_of(d, struct vchiq_driver, driver);
35 }
36 
37 extern struct bus_type vchiq_bus_type;
38 
39 struct vchiq_device *
40 vchiq_device_register(struct device *parent, const char *name);
41 void vchiq_device_unregister(struct vchiq_device *dev);
42 
43 int vchiq_driver_register(struct vchiq_driver *vchiq_drv);
44 void vchiq_driver_unregister(struct vchiq_driver *vchiq_drv);
45 
46 /**
47  * module_vchiq_driver() - Helper macro for registering a vchiq driver
48  * @__vchiq_driver: vchiq driver struct
49  *
50  * Helper macro for vchiq drivers which do not do anything special in
51  * module init/exit. This eliminates a lot of boilerplate. Each module may only
52  * use this macro once, and calling it replaces module_init() and module_exit()
53  */
54 #define module_vchiq_driver(__vchiq_driver) \
55 	module_driver(__vchiq_driver, vchiq_driver_register, vchiq_driver_unregister)
56 
57 #endif /* _VCHIQ_DEVICE_H */
58