1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (c) 2019-2020 Intel Corporation
5 * Please see Documentation/driver-api/auxiliary_bus.rst for more information.
8 #ifndef _AUXILIARY_BUS_H_
9 #define _AUXILIARY_BUS_H_
11 #include <linux/device.h>
12 #include <linux/mod_devicetable.h>
14 struct auxiliary_device {
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);
27 struct device_driver driver;
28 const struct auxiliary_device_id *id_table;
31 static inline struct auxiliary_device *to_auxiliary_dev(struct device *dev)
33 return container_of(dev, struct auxiliary_device, dev);
36 static inline struct auxiliary_driver *to_auxiliary_drv(struct device_driver *drv)
38 return container_of(drv, struct auxiliary_driver, driver);
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)
45 static inline void auxiliary_device_uninit(struct auxiliary_device *auxdev)
47 put_device(&auxdev->dev);
50 static inline void auxiliary_device_delete(struct auxiliary_device *auxdev)
52 device_del(&auxdev->dev);
55 int __auxiliary_driver_register(struct auxiliary_driver *auxdrv, struct module *owner,
57 #define auxiliary_driver_register(auxdrv) \
58 __auxiliary_driver_register(auxdrv, THIS_MODULE, KBUILD_MODNAME)
60 void auxiliary_driver_unregister(struct auxiliary_driver *auxdrv);
63 * module_auxiliary_driver() - Helper macro for registering an auxiliary driver
64 * @__auxiliary_driver: auxiliary driver struct
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()
70 #define module_auxiliary_driver(__auxiliary_driver) \
71 module_driver(__auxiliary_driver, auxiliary_driver_register, auxiliary_driver_unregister)
73 struct auxiliary_device *auxiliary_find_device(struct device *start,
75 int (*match)(struct device *dev, const void *data));
77 #endif /* _AUXILIARY_BUS_H_ */