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