• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (c) 2019-2020 Intel Corporation
4  *
5  * Please see Documentation/driver-api/auxiliary_bus.rst for more information.
6  */
7 
8 #ifndef _AUXILIARY_BUS_H_
9 #define _AUXILIARY_BUS_H_
10 
11 #include <linux/device.h>
12 #include <linux/mod_devicetable.h>
13 
14 struct auxiliary_device {
15 	struct device dev;
16 	const char *name;
17 	u32 id;
18 };
19 
20 struct auxiliary_driver {
21 	int (*probe)(struct auxiliary_device *auxdev, const struct auxiliary_device_id *id);
22 	void (*remove)(struct auxiliary_device *auxdev);
23 	void (*shutdown)(struct auxiliary_device *auxdev);
24 	int (*suspend)(struct auxiliary_device *auxdev, pm_message_t state);
25 	int (*resume)(struct auxiliary_device *auxdev);
26 	const char *name;
27 	struct device_driver driver;
28 	const struct auxiliary_device_id *id_table;
29 };
30 
to_auxiliary_dev(struct device * dev)31 static inline struct auxiliary_device *to_auxiliary_dev(struct device *dev)
32 {
33 	return container_of(dev, struct auxiliary_device, dev);
34 }
35 
to_auxiliary_drv(struct device_driver * drv)36 static inline struct auxiliary_driver *to_auxiliary_drv(struct device_driver *drv)
37 {
38 	return container_of(drv, struct auxiliary_driver, driver);
39 }
40 
41 int auxiliary_device_init(struct auxiliary_device *auxdev);
42 int __auxiliary_device_add(struct auxiliary_device *auxdev, const char *modname);
43 #define auxiliary_device_add(auxdev) __auxiliary_device_add(auxdev, KBUILD_MODNAME)
44 
auxiliary_device_uninit(struct auxiliary_device * auxdev)45 static inline void auxiliary_device_uninit(struct auxiliary_device *auxdev)
46 {
47 	put_device(&auxdev->dev);
48 }
49 
auxiliary_device_delete(struct auxiliary_device * auxdev)50 static inline void auxiliary_device_delete(struct auxiliary_device *auxdev)
51 {
52 	device_del(&auxdev->dev);
53 }
54 
55 int __auxiliary_driver_register(struct auxiliary_driver *auxdrv, struct module *owner,
56 				const char *modname);
57 #define auxiliary_driver_register(auxdrv) \
58 	__auxiliary_driver_register(auxdrv, THIS_MODULE, KBUILD_MODNAME)
59 
60 void auxiliary_driver_unregister(struct auxiliary_driver *auxdrv);
61 
62 /**
63  * module_auxiliary_driver() - Helper macro for registering an auxiliary driver
64  * @__auxiliary_driver: auxiliary driver struct
65  *
66  * Helper macro for auxiliary drivers which do not do anything special in
67  * module init/exit. This eliminates a lot of boilerplate. Each module may only
68  * use this macro once, and calling it replaces module_init() and module_exit()
69  */
70 #define module_auxiliary_driver(__auxiliary_driver) \
71 	module_driver(__auxiliary_driver, auxiliary_driver_register, auxiliary_driver_unregister)
72 
73 struct auxiliary_device *auxiliary_find_device(struct device *start,
74 					       const void *data,
75 					       int (*match)(struct device *dev, const void *data));
76 
77 #endif /* _AUXILIARY_BUS_H_ */
78