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