2 * Copyright (c) 2015 Michal Meloun
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/param.h>
31 #include <sys/systm.h>
33 #include <sys/kernel.h>
34 #include <sys/malloc.h>
36 #include <machine/bus.h>
38 #include <dev/extres/clk/clk.h>
39 #include <dev/drm2/drmP.h>
40 #include <dev/drm2/drm_crtc.h>
41 #include <dev/drm2/drm_crtc_helper.h>
42 #include <dev/drm2/drm_edid.h>
43 #include <dev/drm2/drm_fb_helper.h>
44 #include <dev/gpio/gpiobusvar.h>
45 #include <dev/ofw/ofw_bus_subr.h>
47 #include <arm/nvidia/drm2/tegra_drm.h>
49 #include <gnu/dts/include/dt-bindings/gpio/gpio.h>
52 tegra_drm_connector_get_modes(struct drm_connector *connector)
54 struct tegra_drm_encoder *output;
55 struct edid *edid = NULL;
58 output = container_of(connector, struct tegra_drm_encoder,
62 if (output->panel != NULL) {
63 /* XXX panel parsing */
67 /* static EDID is second*/
70 /* EDID from monitor is last */
72 edid = drm_get_edid(connector, output->ddc);
78 drm_mode_connector_update_edid_property(connector, edid);
79 rv = drm_add_edid_modes(connector, edid);
80 drm_edid_to_eld(connector, edid);
85 tegra_drm_connector_best_encoder(struct drm_connector *connector)
87 struct tegra_drm_encoder *output;
89 output = container_of(connector, struct tegra_drm_encoder,
92 return &(output->encoder);
95 enum drm_connector_status
96 tegra_drm_connector_detect(struct drm_connector *connector, bool force)
98 struct tegra_drm_encoder *output;
102 output = container_of(connector, struct tegra_drm_encoder,
104 if (output->gpio_hpd == NULL) {
105 return ((output->panel != NULL) ?
106 connector_status_connected:
107 connector_status_disconnected);
110 rv = gpio_pin_is_active(output->gpio_hpd, &active);
112 device_printf(output->dev, " GPIO read failed: %d\n", rv);
113 return (connector_status_unknown);
117 connector_status_connected : connector_status_disconnected);
121 tegra_drm_encoder_attach(struct tegra_drm_encoder *output, phandle_t node)
126 /* XXX parse output panel here */
128 rv = OF_getencprop_alloc(node, "nvidia,edid",
129 (void **)&output->edid);
131 /* EDID exist but have invalid size */
132 if ((rv >= 0) && (rv != sizeof(struct edid))) {
133 device_printf(output->dev,
134 "Malformed \"nvidia,edid\" property\n");
135 if (output->edid != NULL)
136 free(output->edid, M_OFWPROP);
140 gpio_pin_get_by_ofw_property(output->dev, node, "nvidia,hpd-gpio",
143 OF_getencprop(node, "nvidia,ddc-i2c-bus", &ddc, sizeof(ddc));
145 output->ddc = OF_device_from_xref(ddc);
146 if ((output->edid == NULL) && (output->ddc == NULL))
149 if (output->gpio_hpd != NULL) {
150 output->connector.polled =
151 // DRM_CONNECTOR_POLL_HPD;
152 DRM_CONNECTOR_POLL_DISCONNECT |
153 DRM_CONNECTOR_POLL_CONNECT;
159 int tegra_drm_encoder_init(struct tegra_drm_encoder *output,
160 struct tegra_drm *drm)
169 int tegra_drm_encoder_exit(struct tegra_drm_encoder *output,
170 struct tegra_drm *drm)