anxedp.c revision 1.2.4.3 1 1.2.4.3 martin /* $NetBSD: anxedp.c,v 1.2.4.3 2020/04/08 14:08:05 martin Exp $ */
2 1.2.4.2 christos
3 1.2.4.2 christos /*-
4 1.2.4.2 christos * Copyright (c) 2019 Jared D. McNeill <jmcneill (at) invisible.ca>
5 1.2.4.2 christos * All rights reserved.
6 1.2.4.2 christos *
7 1.2.4.2 christos * Redistribution and use in source and binary forms, with or without
8 1.2.4.2 christos * modification, are permitted provided that the following conditions
9 1.2.4.2 christos * are met:
10 1.2.4.2 christos * 1. Redistributions of source code must retain the above copyright
11 1.2.4.2 christos * notice, this list of conditions and the following disclaimer.
12 1.2.4.2 christos * 2. Redistributions in binary form must reproduce the above copyright
13 1.2.4.2 christos * notice, this list of conditions and the following disclaimer in the
14 1.2.4.2 christos * documentation and/or other materials provided with the distribution.
15 1.2.4.2 christos *
16 1.2.4.2 christos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.2.4.2 christos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.2.4.2 christos * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.2.4.2 christos * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.2.4.2 christos * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 1.2.4.2 christos * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 1.2.4.2 christos * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 1.2.4.2 christos * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 1.2.4.2 christos * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.2.4.2 christos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.2.4.2 christos * SUCH DAMAGE.
27 1.2.4.2 christos */
28 1.2.4.2 christos
29 1.2.4.2 christos #include <sys/cdefs.h>
30 1.2.4.3 martin __KERNEL_RCSID(0, "$NetBSD: anxedp.c,v 1.2.4.3 2020/04/08 14:08:05 martin Exp $");
31 1.2.4.2 christos
32 1.2.4.2 christos #include <sys/param.h>
33 1.2.4.2 christos #include <sys/bus.h>
34 1.2.4.2 christos #include <sys/device.h>
35 1.2.4.2 christos #include <sys/intr.h>
36 1.2.4.2 christos #include <sys/systm.h>
37 1.2.4.2 christos #include <sys/kernel.h>
38 1.2.4.2 christos #include <sys/conf.h>
39 1.2.4.2 christos
40 1.2.4.2 christos #include <dev/ic/dw_hdmi.h>
41 1.2.4.2 christos
42 1.2.4.2 christos #include <dev/i2c/i2cvar.h>
43 1.2.4.2 christos #include <dev/i2c/ddcvar.h>
44 1.2.4.2 christos #include <dev/i2c/ddcreg.h>
45 1.2.4.2 christos #include <dev/videomode/videomode.h>
46 1.2.4.2 christos #include <dev/videomode/edidvar.h>
47 1.2.4.2 christos
48 1.2.4.2 christos #include <dev/fdt/fdtvar.h>
49 1.2.4.2 christos #include <dev/fdt/fdt_port.h>
50 1.2.4.2 christos
51 1.2.4.2 christos #include <drm/drmP.h>
52 1.2.4.2 christos #include <drm/drm_crtc.h>
53 1.2.4.2 christos #include <drm/drm_crtc_helper.h>
54 1.2.4.2 christos #include <drm/drm_edid.h>
55 1.2.4.2 christos
56 1.2.4.2 christos #define ANX_DP_AUX_CH_CTL_1 0xe5
57 1.2.4.2 christos #define ANX_AUX_LENGTH __BITS(7,4)
58 1.2.4.2 christos #define ANX_AUX_TX_COMM __BITS(3,0)
59 1.2.4.2 christos #define ANX_AUX_TX_COMM_MOT 4
60 1.2.4.2 christos #define ANX_AUX_TX_COMM_READ 1
61 1.2.4.2 christos #define ANX_DP_AUX_ADDR(n) (0xe6 + (n))
62 1.2.4.2 christos #define ANX_DP_AUX_CH_CTL_2 0xe9
63 1.2.4.2 christos #define ANX_ADDR_ONLY __BIT(1)
64 1.2.4.2 christos #define ANX_AUX_EN __BIT(0)
65 1.2.4.2 christos #define ANX_BUF_DATA(n) (0xf0 + (n))
66 1.2.4.2 christos
67 1.2.4.2 christos #define ANX_DP_INT_STA 0xf7
68 1.2.4.2 christos #define ANX_RPLY_RECEIV __BIT(1)
69 1.2.4.2 christos
70 1.2.4.2 christos static const struct device_compatible_entry compat_data[] = {
71 1.2.4.2 christos { "analogix,anx6345", 1 },
72 1.2.4.2 christos { NULL }
73 1.2.4.2 christos };
74 1.2.4.2 christos
75 1.2.4.2 christos struct anxedp_softc;
76 1.2.4.2 christos
77 1.2.4.2 christos struct anxedp_connector {
78 1.2.4.2 christos struct drm_connector base;
79 1.2.4.2 christos struct anxedp_softc *sc;
80 1.2.4.2 christos };
81 1.2.4.2 christos
82 1.2.4.2 christos struct anxedp_softc {
83 1.2.4.2 christos device_t sc_dev;
84 1.2.4.2 christos i2c_tag_t sc_i2c;
85 1.2.4.2 christos i2c_addr_t sc_addr;
86 1.2.4.2 christos int sc_phandle;
87 1.2.4.2 christos
88 1.2.4.2 christos struct anxedp_connector sc_connector;
89 1.2.4.2 christos struct drm_bridge sc_bridge;
90 1.2.4.2 christos
91 1.2.4.2 christos struct fdt_device_ports sc_ports;
92 1.2.4.2 christos struct drm_display_mode sc_curmode;
93 1.2.4.2 christos };
94 1.2.4.2 christos
95 1.2.4.2 christos #define to_anxedp_connector(x) container_of(x, struct anxedp_connector, base)
96 1.2.4.2 christos
97 1.2.4.2 christos static uint8_t
98 1.2.4.2 christos anxedp_read(struct anxedp_softc *sc, u_int off, uint8_t reg)
99 1.2.4.2 christos {
100 1.2.4.2 christos uint8_t val;
101 1.2.4.2 christos
102 1.2.4.3 martin if (iic_smbus_read_byte(sc->sc_i2c, sc->sc_addr + off, reg, &val, 0) != 0)
103 1.2.4.2 christos val = 0xff;
104 1.2.4.2 christos
105 1.2.4.2 christos return val;
106 1.2.4.2 christos }
107 1.2.4.2 christos
108 1.2.4.2 christos static void
109 1.2.4.2 christos anxedp_write(struct anxedp_softc *sc, u_int off, uint8_t reg, uint8_t val)
110 1.2.4.2 christos {
111 1.2.4.3 martin (void)iic_smbus_write_byte(sc->sc_i2c, sc->sc_addr + off, reg, val, 0);
112 1.2.4.2 christos }
113 1.2.4.2 christos
114 1.2.4.2 christos static int
115 1.2.4.2 christos anxedp_connector_dpms(struct drm_connector *connector, int mode)
116 1.2.4.2 christos {
117 1.2.4.2 christos int error;
118 1.2.4.2 christos
119 1.2.4.2 christos if (mode != DRM_MODE_DPMS_ON)
120 1.2.4.2 christos pmf_event_inject(NULL, PMFE_DISPLAY_OFF);
121 1.2.4.2 christos
122 1.2.4.2 christos error = drm_helper_connector_dpms(connector, mode);
123 1.2.4.2 christos
124 1.2.4.2 christos if (mode == DRM_MODE_DPMS_ON)
125 1.2.4.2 christos pmf_event_inject(NULL, PMFE_DISPLAY_ON);
126 1.2.4.2 christos
127 1.2.4.2 christos return error;
128 1.2.4.2 christos }
129 1.2.4.2 christos
130 1.2.4.2 christos static enum drm_connector_status
131 1.2.4.2 christos anxedp_connector_detect(struct drm_connector *connector, bool force)
132 1.2.4.2 christos {
133 1.2.4.2 christos return connector_status_connected;
134 1.2.4.2 christos }
135 1.2.4.2 christos
136 1.2.4.2 christos static void
137 1.2.4.2 christos anxedp_connector_destroy(struct drm_connector *connector)
138 1.2.4.2 christos {
139 1.2.4.2 christos drm_connector_unregister(connector);
140 1.2.4.2 christos drm_connector_cleanup(connector);
141 1.2.4.2 christos }
142 1.2.4.2 christos
143 1.2.4.2 christos static const struct drm_connector_funcs anxedp_connector_funcs = {
144 1.2.4.2 christos .dpms = anxedp_connector_dpms,
145 1.2.4.2 christos .detect = anxedp_connector_detect,
146 1.2.4.2 christos .fill_modes = drm_helper_probe_single_connector_modes,
147 1.2.4.2 christos .destroy = anxedp_connector_destroy,
148 1.2.4.2 christos };
149 1.2.4.2 christos
150 1.2.4.2 christos static int
151 1.2.4.2 christos anxedp_aux_wait(struct anxedp_softc *sc)
152 1.2.4.2 christos {
153 1.2.4.2 christos uint8_t val;
154 1.2.4.2 christos int retry;
155 1.2.4.2 christos
156 1.2.4.2 christos for (retry = 1000; retry > 0; retry--) {
157 1.2.4.2 christos val = anxedp_read(sc, 0, ANX_DP_AUX_CH_CTL_2);
158 1.2.4.2 christos if ((val & ANX_AUX_EN) == 0)
159 1.2.4.2 christos break;
160 1.2.4.2 christos delay(100);
161 1.2.4.2 christos }
162 1.2.4.2 christos if (retry == 0) {
163 1.2.4.2 christos device_printf(sc->sc_dev, "aux transfer timeout\n");
164 1.2.4.2 christos return ETIMEDOUT;
165 1.2.4.2 christos }
166 1.2.4.2 christos
167 1.2.4.2 christos for (retry = 1000; retry > 0; retry--) {
168 1.2.4.2 christos val = anxedp_read(sc, 1, ANX_DP_INT_STA);
169 1.2.4.2 christos if ((val & ANX_RPLY_RECEIV) != 0) {
170 1.2.4.2 christos anxedp_write(sc, 1, ANX_DP_INT_STA, val);
171 1.2.4.2 christos break;
172 1.2.4.2 christos }
173 1.2.4.2 christos delay(100);
174 1.2.4.2 christos }
175 1.2.4.2 christos if (retry == 0) {
176 1.2.4.2 christos device_printf(sc->sc_dev, "aux transfer timeout\n");
177 1.2.4.2 christos return ETIMEDOUT;
178 1.2.4.2 christos }
179 1.2.4.2 christos
180 1.2.4.2 christos return 0;
181 1.2.4.2 christos }
182 1.2.4.2 christos
183 1.2.4.2 christos static int
184 1.2.4.2 christos anxedp_aux_transfer(struct anxedp_softc *sc, uint8_t comm, uint32_t addr,
185 1.2.4.2 christos uint8_t *buf, int buflen)
186 1.2.4.2 christos {
187 1.2.4.2 christos uint8_t ctrl[2];
188 1.2.4.2 christos int n, error;
189 1.2.4.2 christos
190 1.2.4.2 christos ctrl[0] = __SHIFTIN(comm, ANX_AUX_TX_COMM);
191 1.2.4.2 christos if (buflen > 0)
192 1.2.4.2 christos ctrl[0] |= __SHIFTIN(buflen - 1, ANX_AUX_LENGTH);
193 1.2.4.2 christos ctrl[1] = ANX_AUX_EN;
194 1.2.4.2 christos if (buflen == 0)
195 1.2.4.2 christos ctrl[1] |= ANX_ADDR_ONLY;
196 1.2.4.2 christos
197 1.2.4.2 christos if (comm != ANX_AUX_TX_COMM_READ) {
198 1.2.4.2 christos for (n = 0; n < buflen; n++)
199 1.2.4.2 christos anxedp_write(sc, 0, ANX_BUF_DATA(n), buf[n]);
200 1.2.4.2 christos }
201 1.2.4.2 christos
202 1.2.4.2 christos anxedp_write(sc, 0, ANX_DP_AUX_ADDR(0), addr & 0xff);
203 1.2.4.2 christos anxedp_write(sc, 0, ANX_DP_AUX_ADDR(1), (addr >> 8) & 0xff);
204 1.2.4.2 christos anxedp_write(sc, 0, ANX_DP_AUX_ADDR(2), (addr >> 16) & 0xf);
205 1.2.4.2 christos anxedp_write(sc, 0, ANX_DP_AUX_CH_CTL_1, ctrl[0]);
206 1.2.4.2 christos anxedp_write(sc, 0, ANX_DP_AUX_CH_CTL_2, ctrl[1]);
207 1.2.4.2 christos
208 1.2.4.2 christos error = anxedp_aux_wait(sc);
209 1.2.4.2 christos if (error != 0)
210 1.2.4.2 christos return error;
211 1.2.4.2 christos
212 1.2.4.2 christos if (comm == ANX_AUX_TX_COMM_READ) {
213 1.2.4.2 christos for (n = 0; n < buflen; n++)
214 1.2.4.2 christos buf[n] = anxedp_read(sc, 0, ANX_BUF_DATA(n));
215 1.2.4.2 christos }
216 1.2.4.2 christos
217 1.2.4.2 christos return 0;
218 1.2.4.2 christos }
219 1.2.4.2 christos
220 1.2.4.2 christos static int
221 1.2.4.2 christos anxedp_read_edid(struct anxedp_softc *sc, uint8_t *edid, int edidlen)
222 1.2.4.2 christos {
223 1.2.4.2 christos int error;
224 1.2.4.2 christos uint8_t n;
225 1.2.4.2 christos
226 1.2.4.2 christos for (n = 0; n < edidlen; n += 16) {
227 1.2.4.2 christos const int xferlen = MIN(edidlen - n, 16);
228 1.2.4.2 christos
229 1.2.4.2 christos error = anxedp_aux_transfer(sc, ANX_AUX_TX_COMM_MOT, DDC_ADDR, &n, 1);
230 1.2.4.2 christos if (error != 0)
231 1.2.4.2 christos return error;
232 1.2.4.2 christos
233 1.2.4.2 christos error = anxedp_aux_transfer(sc, ANX_AUX_TX_COMM_READ, DDC_ADDR, &edid[n], xferlen);
234 1.2.4.2 christos if (error != 0)
235 1.2.4.2 christos return error;
236 1.2.4.2 christos }
237 1.2.4.2 christos
238 1.2.4.2 christos return 0;
239 1.2.4.2 christos }
240 1.2.4.2 christos
241 1.2.4.2 christos static int
242 1.2.4.2 christos anxedp_connector_get_modes(struct drm_connector *connector)
243 1.2.4.2 christos {
244 1.2.4.2 christos struct anxedp_connector *anxedp_connector = to_anxedp_connector(connector);
245 1.2.4.2 christos struct anxedp_softc * const sc = anxedp_connector->sc;
246 1.2.4.2 christos char edid[EDID_LENGTH];
247 1.2.4.2 christos struct edid *pedid = NULL;
248 1.2.4.2 christos int error;
249 1.2.4.2 christos
250 1.2.4.3 martin iic_acquire_bus(sc->sc_i2c, 0);
251 1.2.4.2 christos error = anxedp_read_edid(sc, edid, sizeof(edid));
252 1.2.4.3 martin iic_release_bus(sc->sc_i2c, 0);
253 1.2.4.2 christos if (error == 0)
254 1.2.4.2 christos pedid = (struct edid *)edid;
255 1.2.4.2 christos
256 1.2.4.2 christos drm_mode_connector_update_edid_property(connector, pedid);
257 1.2.4.2 christos if (pedid == NULL)
258 1.2.4.2 christos return 0;
259 1.2.4.2 christos
260 1.2.4.2 christos error = drm_add_edid_modes(connector, pedid);
261 1.2.4.2 christos drm_edid_to_eld(connector, pedid);
262 1.2.4.2 christos
263 1.2.4.2 christos return error;
264 1.2.4.2 christos }
265 1.2.4.2 christos
266 1.2.4.2 christos static struct drm_encoder *
267 1.2.4.2 christos anxedp_connector_best_encoder(struct drm_connector *connector)
268 1.2.4.2 christos {
269 1.2.4.2 christos int enc_id = connector->encoder_ids[0];
270 1.2.4.2 christos struct drm_mode_object *obj;
271 1.2.4.2 christos struct drm_encoder *encoder = NULL;
272 1.2.4.2 christos
273 1.2.4.2 christos if (enc_id) {
274 1.2.4.2 christos obj = drm_mode_object_find(connector->dev, enc_id,
275 1.2.4.2 christos DRM_MODE_OBJECT_ENCODER);
276 1.2.4.2 christos if (obj == NULL)
277 1.2.4.2 christos return NULL;
278 1.2.4.2 christos encoder = obj_to_encoder(obj);
279 1.2.4.2 christos }
280 1.2.4.2 christos
281 1.2.4.2 christos return encoder;
282 1.2.4.2 christos }
283 1.2.4.2 christos
284 1.2.4.2 christos static const struct drm_connector_helper_funcs anxedp_connector_helper_funcs = {
285 1.2.4.2 christos .get_modes = anxedp_connector_get_modes,
286 1.2.4.2 christos .best_encoder = anxedp_connector_best_encoder,
287 1.2.4.2 christos };
288 1.2.4.2 christos
289 1.2.4.2 christos static int
290 1.2.4.2 christos anxedp_bridge_attach(struct drm_bridge *bridge)
291 1.2.4.2 christos {
292 1.2.4.2 christos struct anxedp_softc * const sc = bridge->driver_private;
293 1.2.4.2 christos struct anxedp_connector *anxedp_connector = &sc->sc_connector;
294 1.2.4.2 christos struct drm_connector *connector = &anxedp_connector->base;
295 1.2.4.2 christos int error;
296 1.2.4.2 christos
297 1.2.4.2 christos anxedp_connector->sc = sc;
298 1.2.4.2 christos
299 1.2.4.2 christos connector->polled = DRM_CONNECTOR_POLL_CONNECT | DRM_CONNECTOR_POLL_DISCONNECT;
300 1.2.4.2 christos connector->interlace_allowed = 0;
301 1.2.4.2 christos connector->doublescan_allowed = 0;
302 1.2.4.2 christos
303 1.2.4.2 christos drm_connector_init(bridge->dev, connector, &anxedp_connector_funcs,
304 1.2.4.2 christos connector->connector_type);
305 1.2.4.2 christos drm_connector_helper_add(connector, &anxedp_connector_helper_funcs);
306 1.2.4.2 christos
307 1.2.4.2 christos error = drm_mode_connector_attach_encoder(connector, bridge->encoder);
308 1.2.4.2 christos if (error != 0)
309 1.2.4.2 christos return error;
310 1.2.4.2 christos
311 1.2.4.2 christos return drm_connector_register(connector);
312 1.2.4.2 christos }
313 1.2.4.2 christos
314 1.2.4.2 christos static void
315 1.2.4.2 christos anxedp_bridge_enable(struct drm_bridge *bridge)
316 1.2.4.2 christos {
317 1.2.4.2 christos }
318 1.2.4.2 christos
319 1.2.4.2 christos static void
320 1.2.4.2 christos anxedp_bridge_pre_enable(struct drm_bridge *bridge)
321 1.2.4.2 christos {
322 1.2.4.2 christos }
323 1.2.4.2 christos
324 1.2.4.2 christos static void
325 1.2.4.2 christos anxedp_bridge_disable(struct drm_bridge *bridge)
326 1.2.4.2 christos {
327 1.2.4.2 christos }
328 1.2.4.2 christos
329 1.2.4.2 christos static void
330 1.2.4.2 christos anxedp_bridge_post_disable(struct drm_bridge *bridge)
331 1.2.4.2 christos {
332 1.2.4.2 christos }
333 1.2.4.2 christos
334 1.2.4.2 christos static void
335 1.2.4.2 christos anxedp_bridge_mode_set(struct drm_bridge *bridge,
336 1.2.4.2 christos struct drm_display_mode *mode, struct drm_display_mode *adjusted_mode)
337 1.2.4.2 christos {
338 1.2.4.2 christos struct anxedp_softc * const sc = bridge->driver_private;
339 1.2.4.2 christos
340 1.2.4.2 christos sc->sc_curmode = *adjusted_mode;
341 1.2.4.2 christos }
342 1.2.4.2 christos
343 1.2.4.2 christos static bool
344 1.2.4.2 christos anxedp_bridge_mode_fixup(struct drm_bridge *bridge,
345 1.2.4.2 christos const struct drm_display_mode *mode, struct drm_display_mode *adjusted_mode)
346 1.2.4.2 christos {
347 1.2.4.2 christos return true;
348 1.2.4.2 christos }
349 1.2.4.2 christos
350 1.2.4.2 christos static const struct drm_bridge_funcs anxedp_bridge_funcs = {
351 1.2.4.2 christos .attach = anxedp_bridge_attach,
352 1.2.4.2 christos .enable = anxedp_bridge_enable,
353 1.2.4.2 christos .pre_enable = anxedp_bridge_pre_enable,
354 1.2.4.2 christos .disable = anxedp_bridge_disable,
355 1.2.4.2 christos .post_disable = anxedp_bridge_post_disable,
356 1.2.4.2 christos .mode_set = anxedp_bridge_mode_set,
357 1.2.4.2 christos .mode_fixup = anxedp_bridge_mode_fixup,
358 1.2.4.2 christos };
359 1.2.4.2 christos
360 1.2.4.2 christos static int
361 1.2.4.2 christos anxedp_ep_activate(device_t dev, struct fdt_endpoint *ep, bool activate)
362 1.2.4.2 christos {
363 1.2.4.2 christos struct anxedp_softc * const sc = device_private(dev);
364 1.2.4.2 christos struct fdt_endpoint *in_ep = fdt_endpoint_remote(ep);
365 1.2.4.2 christos struct drm_encoder *encoder;
366 1.2.4.2 christos struct drm_bridge *bridge;
367 1.2.4.2 christos int error;
368 1.2.4.2 christos
369 1.2.4.2 christos if (!activate)
370 1.2.4.2 christos return EINVAL;
371 1.2.4.2 christos
372 1.2.4.2 christos if (fdt_endpoint_port_index(ep) != 0)
373 1.2.4.2 christos return EINVAL;
374 1.2.4.2 christos
375 1.2.4.2 christos switch (fdt_endpoint_type(in_ep)) {
376 1.2.4.2 christos case EP_DRM_ENCODER:
377 1.2.4.2 christos encoder = fdt_endpoint_get_data(in_ep);
378 1.2.4.2 christos break;
379 1.2.4.2 christos case EP_DRM_BRIDGE:
380 1.2.4.2 christos bridge = fdt_endpoint_get_data(in_ep);
381 1.2.4.2 christos encoder = bridge->encoder;
382 1.2.4.2 christos break;
383 1.2.4.2 christos default:
384 1.2.4.2 christos encoder = NULL;
385 1.2.4.2 christos break;
386 1.2.4.2 christos }
387 1.2.4.2 christos
388 1.2.4.2 christos if (encoder == NULL)
389 1.2.4.2 christos return EINVAL;
390 1.2.4.2 christos
391 1.2.4.2 christos sc->sc_connector.base.connector_type = DRM_MODE_CONNECTOR_eDP;
392 1.2.4.2 christos
393 1.2.4.2 christos sc->sc_bridge.driver_private = sc;
394 1.2.4.2 christos sc->sc_bridge.funcs = &anxedp_bridge_funcs;
395 1.2.4.2 christos sc->sc_bridge.encoder = encoder;
396 1.2.4.2 christos
397 1.2.4.2 christos error = drm_bridge_attach(encoder->dev, &sc->sc_bridge);
398 1.2.4.2 christos if (error != 0)
399 1.2.4.2 christos return EIO;
400 1.2.4.2 christos
401 1.2.4.2 christos encoder->bridge = &sc->sc_bridge;
402 1.2.4.2 christos
403 1.2.4.2 christos return 0;
404 1.2.4.2 christos }
405 1.2.4.2 christos
406 1.2.4.2 christos static void *
407 1.2.4.2 christos anxedp_ep_get_data(device_t dev, struct fdt_endpoint *ep)
408 1.2.4.2 christos {
409 1.2.4.2 christos struct anxedp_softc * const sc = device_private(dev);
410 1.2.4.2 christos
411 1.2.4.2 christos return &sc->sc_bridge;
412 1.2.4.2 christos }
413 1.2.4.2 christos
414 1.2.4.2 christos static int
415 1.2.4.2 christos anxedp_match(device_t parent, cfdata_t match, void *aux)
416 1.2.4.2 christos {
417 1.2.4.2 christos struct i2c_attach_args *ia = aux;
418 1.2.4.2 christos int match_result;
419 1.2.4.2 christos
420 1.2.4.2 christos if (iic_use_direct_match(ia, match, compat_data, &match_result))
421 1.2.4.2 christos return match_result;
422 1.2.4.2 christos
423 1.2.4.2 christos /* This device is direct-config only */
424 1.2.4.2 christos
425 1.2.4.2 christos return 0;
426 1.2.4.2 christos }
427 1.2.4.2 christos
428 1.2.4.2 christos static void
429 1.2.4.2 christos anxedp_attach(device_t parent, device_t self, void *aux)
430 1.2.4.2 christos {
431 1.2.4.2 christos struct anxedp_softc * const sc = device_private(self);
432 1.2.4.2 christos struct i2c_attach_args * const ia = aux;
433 1.2.4.2 christos
434 1.2.4.2 christos sc->sc_dev = self;
435 1.2.4.2 christos sc->sc_i2c = ia->ia_tag;
436 1.2.4.2 christos sc->sc_addr = ia->ia_addr;
437 1.2.4.2 christos sc->sc_phandle = ia->ia_cookie;
438 1.2.4.2 christos
439 1.2.4.2 christos aprint_naive("\n");
440 1.2.4.2 christos aprint_normal(": eDP TX\n");
441 1.2.4.2 christos
442 1.2.4.2 christos sc->sc_ports.dp_ep_activate = anxedp_ep_activate;
443 1.2.4.2 christos sc->sc_ports.dp_ep_get_data = anxedp_ep_get_data;
444 1.2.4.2 christos fdt_ports_register(&sc->sc_ports, self, sc->sc_phandle, EP_DRM_BRIDGE);
445 1.2.4.2 christos }
446 1.2.4.2 christos
447 1.2.4.2 christos CFATTACH_DECL_NEW(anxedp, sizeof(struct anxedp_softc),
448 1.2.4.2 christos anxedp_match, anxedp_attach, NULL, NULL);
449