xref: /linux/include/drm/display/drm_dp_aux_bus.h (revision c532de5a67a70f8533d495f8f2aaa9a0491c3ad0)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright 2021 Google Inc.
4  *
5  * The DP AUX bus is used for devices that are connected over a DisplayPort
6  * AUX bus. The devices on the far side of the bus are referred to as
7  * endpoints in this code.
8  */
9 
10 #ifndef _DP_AUX_BUS_H_
11 #define _DP_AUX_BUS_H_
12 
13 #include <linux/device.h>
14 #include <linux/mod_devicetable.h>
15 
16 /**
17  * struct dp_aux_ep_device - Main dev structure for DP AUX endpoints
18  *
19  * This is used to instantiate devices that are connected via a DP AUX
20  * bus. Usually the device is a panel, but conceivable other devices could
21  * be hooked up there.
22  */
23 struct dp_aux_ep_device {
24 	/** @dev: The normal dev pointer */
25 	struct device dev;
26 	/** @aux: Pointer to the aux bus */
27 	struct drm_dp_aux *aux;
28 };
29 
30 struct dp_aux_ep_driver {
31 	int (*probe)(struct dp_aux_ep_device *aux_ep);
32 	void (*remove)(struct dp_aux_ep_device *aux_ep);
33 	void (*shutdown)(struct dp_aux_ep_device *aux_ep);
34 	struct device_driver driver;
35 };
36 
37 static inline struct dp_aux_ep_device *to_dp_aux_ep_dev(struct device *dev)
38 {
39 	return container_of(dev, struct dp_aux_ep_device, dev);
40 }
41 
42 static inline struct dp_aux_ep_driver *to_dp_aux_ep_drv(struct device_driver *drv)
43 {
44 	return container_of(drv, struct dp_aux_ep_driver, driver);
45 }
46 
47 int of_dp_aux_populate_bus(struct drm_dp_aux *aux,
48 			   int (*done_probing)(struct drm_dp_aux *aux));
49 void of_dp_aux_depopulate_bus(struct drm_dp_aux *aux);
50 int devm_of_dp_aux_populate_bus(struct drm_dp_aux *aux,
51 				int (*done_probing)(struct drm_dp_aux *aux));
52 
53 /* Deprecated versions of the above functions. To be removed when no callers. */
54 static inline int of_dp_aux_populate_ep_devices(struct drm_dp_aux *aux)
55 {
56 	int ret;
57 
58 	ret = of_dp_aux_populate_bus(aux, NULL);
59 
60 	/* New API returns -ENODEV for no child case; adapt to old assumption */
61 	return (ret != -ENODEV) ? ret : 0;
62 }
63 
64 static inline int devm_of_dp_aux_populate_ep_devices(struct drm_dp_aux *aux)
65 {
66 	int ret;
67 
68 	ret = devm_of_dp_aux_populate_bus(aux, NULL);
69 
70 	/* New API returns -ENODEV for no child case; adapt to old assumption */
71 	return (ret != -ENODEV) ? ret : 0;
72 }
73 
74 static inline void of_dp_aux_depopulate_ep_devices(struct drm_dp_aux *aux)
75 {
76 	of_dp_aux_depopulate_bus(aux);
77 }
78 
79 #define dp_aux_dp_driver_register(aux_ep_drv) \
80 	__dp_aux_dp_driver_register(aux_ep_drv, THIS_MODULE)
81 int __dp_aux_dp_driver_register(struct dp_aux_ep_driver *aux_ep_drv,
82 				struct module *owner);
83 void dp_aux_dp_driver_unregister(struct dp_aux_ep_driver *aux_ep_drv);
84 
85 #endif /* _DP_AUX_BUS_H_ */
86