1 /* SPDX-License-Identifier: MIT */
7 #include <linux/platform_device.h>
9 #include <drm/drm_drv.h>
14 * This library provides helpers registering DRM drivers during module
15 * initialization and shutdown. The provided helpers act like bus-specific
16 * module helpers, such as module_pci_driver(), but respect additional
17 * parameters that control DRM driver registration.
19 * Below is an example of initializing a DRM driver for a device on the
24 * struct pci_driver my_pci_drv = {
27 * drm_module_pci_driver(my_pci_drv);
29 * The generated code will test if DRM drivers are enabled and register
30 * the PCI driver my_pci_drv. For more complex module initialization, you
31 * can still use module_init() and module_exit() in your driver.
38 static inline int __init drm_pci_register_driver(struct pci_driver *pci_drv)
40 if (drm_firmware_drivers_only())
43 return pci_register_driver(pci_drv);
47 * drm_module_pci_driver - Register a DRM driver for PCI-based devices
48 * @__pci_drv: the PCI driver structure
50 * Registers a DRM driver for devices on the PCI bus. The helper
51 * macro behaves like module_pci_driver() but tests the state of
52 * drm_firmware_drivers_only(). For more complex module initialization,
53 * use module_init() and module_exit() directly.
55 * Each module may only use this macro once. Calling it replaces
56 * module_init() and module_exit().
58 #define drm_module_pci_driver(__pci_drv) \
59 module_driver(__pci_drv, drm_pci_register_driver, pci_unregister_driver)
61 static inline int __init
62 drm_pci_register_driver_if_modeset(struct pci_driver *pci_drv, int modeset)
64 if (drm_firmware_drivers_only() && modeset == -1)
69 return pci_register_driver(pci_drv);
72 static inline void __exit
73 drm_pci_unregister_driver_if_modeset(struct pci_driver *pci_drv, int modeset)
75 pci_unregister_driver(pci_drv);
79 * drm_module_pci_driver_if_modeset - Register a DRM driver for PCI-based devices
80 * @__pci_drv: the PCI driver structure
81 * @__modeset: an additional parameter that disables the driver
83 * This macro is deprecated and only provided for existing drivers. For
84 * new drivers, use drm_module_pci_driver().
86 * Registers a DRM driver for devices on the PCI bus. The helper macro
87 * behaves like drm_module_pci_driver() with an additional driver-specific
88 * flag. If __modeset is 0, the driver has been disabled, if __modeset is
89 * -1 the driver state depends on the global DRM state. For all other
90 * values, the PCI driver has been enabled. The default should be -1.
92 #define drm_module_pci_driver_if_modeset(__pci_drv, __modeset) \
93 module_driver(__pci_drv, drm_pci_register_driver_if_modeset, \
94 drm_pci_unregister_driver_if_modeset, __modeset)
100 static inline int __init
101 drm_platform_driver_register(struct platform_driver *platform_drv)
103 if (drm_firmware_drivers_only())
106 return platform_driver_register(platform_drv);
110 * drm_module_platform_driver - Register a DRM driver for platform devices
111 * @__platform_drv: the platform driver structure
113 * Registers a DRM driver for devices on the platform bus. The helper
114 * macro behaves like module_platform_driver() but tests the state of
115 * drm_firmware_drivers_only(). For more complex module initialization,
116 * use module_init() and module_exit() directly.
118 * Each module may only use this macro once. Calling it replaces
119 * module_init() and module_exit().
121 #define drm_module_platform_driver(__platform_drv) \
122 module_driver(__platform_drv, drm_platform_driver_register, \
123 platform_driver_unregister)