1 /* $NetBSD: drm_encoder_slave.h,v 1.3 2021/12/19 10:48:15 riastradh Exp $ */
2
3 /*-
4 * Copyright (c) 2015 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Taylor R. Campbell.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #ifndef _DRM_DRM_ENCODER_SLAVE_H_
33 #define _DRM_DRM_ENCODER_SLAVE_H_
34
35 #include <sys/types.h>
36 #include <sys/rbtree.h>
37
38 #include <drm/drm_connector.h>
39 #include <drm/drm_encoder.h>
40
41 struct drm_connector;
42 struct drm_device;
43 struct drm_display_mode;
44 struct drm_encoder;
45 struct drm_property;
46 struct i2c_client;
47 struct module;
48
49 struct drm_encoder_slave_funcs {
50 void (*set_config)(struct drm_encoder *, void *);
51 void (*destroy)(struct drm_encoder *);
52 void (*dpms)(struct drm_encoder *, int mode);
53 void (*save)(struct drm_encoder *);
54 void (*restore)(struct drm_encoder *);
55 bool (*mode_fixup)(struct drm_encoder *,
56 const struct drm_display_mode *,
57 struct drm_display_mode *);
58 int (*mode_valid)(struct drm_encoder *, struct drm_display_mode *);
59 void (*mode_set)(struct drm_encoder *,
60 const struct drm_display_mode *,
61 struct drm_display_mode *);
62 enum drm_connector_status
63 (*detect)(struct drm_encoder *, struct drm_connector *);
64 int (*get_modes)(struct drm_encoder *, struct drm_connector *);
65 int (*create_resources)(struct drm_encoder *,
66 struct drm_connector *);
67 int (*set_property)(struct drm_encoder *, struct drm_connector *,
68 struct drm_property *, uint64_t);
69 };
70
71 struct drm_encoder_slave {
72 struct drm_encoder base;
73 const struct drm_encoder_slave_funcs *slave_funcs;
74 void *slave_priv;
75 void *bus_priv;
76 };
77
78 static inline struct drm_encoder_slave *
to_encoder_slave(struct drm_encoder * encoder)79 to_encoder_slave(struct drm_encoder *encoder)
80 {
81
82 return container_of(encoder, struct drm_encoder_slave, base);
83 }
84
85 struct drm_i2c_encoder_driver {
86 struct i2c_driver i2c_driver;
87 int (*encoder_init)(struct i2c_client *,
88 struct drm_device *,
89 struct drm_encoder_slave *);
90 rb_node_t rb_node;
91 volatile unsigned refcnt;
92 };
93
94 struct module;
95
96 void drm_i2c_encoders_init(void);
97 void drm_i2c_encoders_fini(void);
98
99 int drm_i2c_encoder_register(struct module *,
100 struct drm_i2c_encoder_driver *);
101 void drm_i2c_encoder_unregister(struct drm_i2c_encoder_driver *);
102
103 int drm_i2c_encoder_init(struct drm_device *, struct drm_encoder_slave *,
104 struct i2c_adapter *, const struct i2c_board_info *);
105 void drm_i2c_encoder_destroy(struct drm_encoder *);
106 struct i2c_client *
107 drm_i2c_encoder_get_client(struct drm_encoder *);
108
109 void drm_i2c_encoder_dpms(struct drm_encoder *, int);
110 bool drm_i2c_encoder_mode_fixup(struct drm_encoder *,
111 const struct drm_display_mode *, struct drm_display_mode *);
112 void drm_i2c_encoder_prepare(struct drm_encoder *);
113 void drm_i2c_encoder_commit(struct drm_encoder *);
114 void drm_i2c_encoder_mode_set(struct drm_encoder *,
115 struct drm_display_mode *, struct drm_display_mode *);
116 enum drm_connector_status
117 drm_i2c_encoder_detect(struct drm_encoder *, struct drm_connector *);
118 void drm_i2c_encoder_save(struct drm_encoder *);
119 void drm_i2c_encoder_restore(struct drm_encoder *);
120
121 #endif /* _DRM_DRM_ENCODER_SLAVE_H_ */
122