Linux Audio

Check our new training course

Loading...
v4.10.11
 
  1/*
  2 * drivers/gpu/drm/omapdrm/omap_connector.c
  3 *
  4 * Copyright (C) 2011 Texas Instruments
  5 * Author: Rob Clark <rob@ti.com>
  6 *
  7 * This program is free software; you can redistribute it and/or modify it
  8 * under the terms of the GNU General Public License version 2 as published by
  9 * the Free Software Foundation.
 10 *
 11 * This program is distributed in the hope that it will be useful, but WITHOUT
 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 14 * more details.
 15 *
 16 * You should have received a copy of the GNU General Public License along with
 17 * this program.  If not, see <http://www.gnu.org/licenses/>.
 18 */
 19
 20#include <drm/drm_atomic_helper.h>
 21#include <drm/drm_crtc.h>
 22#include <drm/drm_crtc_helper.h>
 23
 24#include "omap_drv.h"
 25
 26/*
 27 * connector funcs
 28 */
 29
 30#define to_omap_connector(x) container_of(x, struct omap_connector, base)
 31
 32struct omap_connector {
 33	struct drm_connector base;
 34	struct omap_dss_device *dssdev;
 35	bool hdmi_mode;
 36};
 37
 38bool omap_connector_get_hdmi_mode(struct drm_connector *connector)
 39{
 40	struct omap_connector *omap_connector = to_omap_connector(connector);
 41
 42	return omap_connector->hdmi_mode;
 43}
 44
 45static enum drm_connector_status omap_connector_detect(
 46		struct drm_connector *connector, bool force)
 47{
 48	struct omap_connector *omap_connector = to_omap_connector(connector);
 49	struct omap_dss_device *dssdev = omap_connector->dssdev;
 50	struct omap_dss_driver *dssdrv = dssdev->driver;
 51	enum drm_connector_status ret;
 52
 53	if (dssdrv->detect) {
 54		if (dssdrv->detect(dssdev))
 55			ret = connector_status_connected;
 56		else
 57			ret = connector_status_disconnected;
 58	} else if (dssdev->type == OMAP_DISPLAY_TYPE_DPI ||
 59			dssdev->type == OMAP_DISPLAY_TYPE_DBI ||
 60			dssdev->type == OMAP_DISPLAY_TYPE_SDI ||
 61			dssdev->type == OMAP_DISPLAY_TYPE_DSI) {
 62		ret = connector_status_connected;
 63	} else {
 64		ret = connector_status_unknown;
 65	}
 66
 67	VERB("%s: %d (force=%d)", omap_connector->dssdev->name, ret, force);
 68
 69	return ret;
 70}
 71
 72static void omap_connector_destroy(struct drm_connector *connector)
 73{
 74	struct omap_connector *omap_connector = to_omap_connector(connector);
 75	struct omap_dss_device *dssdev = omap_connector->dssdev;
 76
 77	DBG("%s", omap_connector->dssdev->name);
 
 78	drm_connector_unregister(connector);
 79	drm_connector_cleanup(connector);
 80	kfree(omap_connector);
 81
 82	omap_dss_put_device(dssdev);
 83}
 84
 85#define MAX_EDID  512
 
 86
 87static int omap_connector_get_modes(struct drm_connector *connector)
 88{
 89	struct omap_connector *omap_connector = to_omap_connector(connector);
 90	struct omap_dss_device *dssdev = omap_connector->dssdev;
 91	struct omap_dss_driver *dssdrv = dssdev->driver;
 92	struct drm_device *dev = connector->dev;
 93	int n = 0;
 94
 95	DBG("%s", omap_connector->dssdev->name);
 96
 97	/* if display exposes EDID, then we parse that in the normal way to
 98	 * build table of supported modes.. otherwise (ie. fixed resolution
 99	 * LCD panels) we just return a single mode corresponding to the
100	 * currently configured timings:
101	 */
102	if (dssdrv->read_edid) {
103		void *edid = kzalloc(MAX_EDID, GFP_KERNEL);
104
105		if ((dssdrv->read_edid(dssdev, edid, MAX_EDID) > 0) &&
106				drm_edid_is_valid(edid)) {
107			drm_mode_connector_update_edid_property(
108					connector, edid);
109			n = drm_add_edid_modes(connector, edid);
110
111			omap_connector->hdmi_mode =
112				drm_detect_hdmi_monitor(edid);
113		} else {
114			drm_mode_connector_update_edid_property(
115					connector, NULL);
116		}
117
118		kfree(edid);
119	} else {
120		struct drm_display_mode *mode = drm_mode_create(dev);
121		struct videomode vm = {0};
122
123		dssdrv->get_timings(dssdev, &vm);
124
125		drm_display_mode_from_videomode(&vm, mode);
126
127		mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
128		drm_mode_set_name(mode);
129		drm_mode_probed_add(connector, mode);
130
131		n = 1;
 
 
 
 
 
 
132	}
133
134	return n;
 
 
 
 
135}
136
137static int omap_connector_mode_valid(struct drm_connector *connector,
138				 struct drm_display_mode *mode)
 
139{
140	struct omap_connector *omap_connector = to_omap_connector(connector);
141	struct omap_dss_device *dssdev = omap_connector->dssdev;
142	struct omap_dss_driver *dssdrv = dssdev->driver;
143	struct videomode vm = {0};
144	struct drm_device *dev = connector->dev;
145	struct drm_display_mode *new_mode;
146	int r, ret = MODE_BAD;
147
148	drm_display_mode_to_videomode(mode, &vm);
149	vm.flags |= DISPLAY_FLAGS_DE_HIGH | DISPLAY_FLAGS_PIXDATA_POSEDGE |
150		    DISPLAY_FLAGS_SYNC_NEGEDGE;
151	mode->vrefresh = drm_mode_vrefresh(mode);
152
153	/*
154	 * if the panel driver doesn't have a check_timings, it's most likely
155	 * a fixed resolution panel, check if the timings match with the
156	 * panel's timings
157	 */
158	if (dssdrv->check_timings) {
159		r = dssdrv->check_timings(dssdev, &vm);
160	} else {
161		struct videomode t = {0};
162
163		dssdrv->get_timings(dssdev, &t);
164
165		if (memcmp(&vm, &t, sizeof(struct videomode)))
166			r = -EINVAL;
167		else
168			r = 0;
169	}
170
171	if (!r) {
172		/* check if vrefresh is still valid */
173		new_mode = drm_mode_duplicate(dev, mode);
174		new_mode->clock = vm.pixelclock / 1000;
175		new_mode->vrefresh = 0;
176		if (mode->vrefresh == drm_mode_vrefresh(new_mode))
177			ret = MODE_OK;
178		drm_mode_destroy(dev, new_mode);
179	}
180
181	DBG("connector: mode %s: "
182			"%d:\"%s\" %d %d %d %d %d %d %d %d %d %d 0x%x 0x%x",
183			(ret == MODE_OK) ? "valid" : "invalid",
184			mode->base.id, mode->name, mode->vrefresh, mode->clock,
185			mode->hdisplay, mode->hsync_start,
186			mode->hsync_end, mode->htotal,
187			mode->vdisplay, mode->vsync_start,
188			mode->vsync_end, mode->vtotal, mode->type, mode->flags);
 
189
190	return ret;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
191}
192
193static const struct drm_connector_funcs omap_connector_funcs = {
194	.dpms = drm_atomic_helper_connector_dpms,
195	.reset = drm_atomic_helper_connector_reset,
196	.detect = omap_connector_detect,
197	.fill_modes = drm_helper_probe_single_connector_modes,
198	.destroy = omap_connector_destroy,
199	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
200	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
201};
202
203static const struct drm_connector_helper_funcs omap_connector_helper_funcs = {
204	.get_modes = omap_connector_get_modes,
205	.mode_valid = omap_connector_mode_valid,
206};
207
208/* initialize connector */
209struct drm_connector *omap_connector_init(struct drm_device *dev,
210		int connector_type, struct omap_dss_device *dssdev,
211		struct drm_encoder *encoder)
212{
213	struct drm_connector *connector = NULL;
214	struct omap_connector *omap_connector;
215
216	DBG("%s", dssdev->name);
217
218	omap_dss_get_device(dssdev);
219
220	omap_connector = kzalloc(sizeof(struct omap_connector), GFP_KERNEL);
221	if (!omap_connector)
222		goto fail;
223
224	omap_connector->dssdev = dssdev;
225
226	connector = &omap_connector->base;
227
228	drm_connector_init(dev, connector, &omap_connector_funcs,
229				connector_type);
230	drm_connector_helper_add(connector, &omap_connector_helper_funcs);
231
232#if 0 /* enable when dss2 supports hotplug */
233	if (dssdev->caps & OMAP_DSS_DISPLAY_CAP_HPD)
234		connector->polled = 0;
235	else
236#endif
237		connector->polled = DRM_CONNECTOR_POLL_CONNECT |
238				DRM_CONNECTOR_POLL_DISCONNECT;
239
240	connector->interlace_allowed = 1;
241	connector->doublescan_allowed = 0;
242
243	drm_connector_register(connector);
 
 
244
245	return connector;
246
247fail:
248	if (connector)
249		omap_connector_destroy(connector);
250
251	return NULL;
252}
v5.9
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
 
 
  4 * Author: Rob Clark <rob@ti.com>
 
 
 
 
 
 
 
 
 
 
 
 
  5 */
  6
  7#include <drm/drm_atomic_helper.h>
  8#include <drm/drm_crtc.h>
  9#include <drm/drm_probe_helper.h>
 10
 11#include "omap_drv.h"
 12
 13/*
 14 * connector funcs
 15 */
 16
 17#define to_omap_connector(x) container_of(x, struct omap_connector, base)
 18
 19struct omap_connector {
 20	struct drm_connector base;
 21	struct omap_dss_device *output;
 
 22};
 23
 
 
 
 
 
 
 
 24static enum drm_connector_status omap_connector_detect(
 25		struct drm_connector *connector, bool force)
 26{
 27	return connector_status_connected;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 28}
 29
 30static void omap_connector_destroy(struct drm_connector *connector)
 31{
 32	struct omap_connector *omap_connector = to_omap_connector(connector);
 
 33
 34	DBG("%s", connector->name);
 35
 36	drm_connector_unregister(connector);
 37	drm_connector_cleanup(connector);
 
 38
 39	omapdss_device_put(omap_connector->output);
 
 40
 41	kfree(omap_connector);
 42}
 43
 44static int omap_connector_get_modes(struct drm_connector *connector)
 45{
 46	struct omap_connector *omap_connector = to_omap_connector(connector);
 47	struct omap_dss_device *dssdev = NULL;
 48	struct omap_dss_device *d;
 
 
 
 
 
 
 
 
 
 
 
 
 49
 50	DBG("%s", connector->name);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 51
 52	/*
 53	 * If the display pipeline reports modes (e.g. with a fixed resolution
 54	 * panel or an analog TV output), query it.
 55	 */
 56	for (d = omap_connector->output; d; d = d->next) {
 57		if (d->ops_flags & OMAP_DSS_DEVICE_OP_MODES)
 58			dssdev = d;
 59	}
 60
 61	if (dssdev)
 62		return dssdev->ops->get_modes(dssdev, connector);
 63
 64	/* We can't retrieve modes. The KMS core will add the default modes. */
 65	return 0;
 66}
 67
 68enum drm_mode_status omap_connector_mode_fixup(struct omap_dss_device *dssdev,
 69					const struct drm_display_mode *mode,
 70					struct drm_display_mode *adjusted_mode)
 71{
 72	int ret;
 
 
 
 
 
 
 
 
 
 
 
 73
 74	drm_mode_copy(adjusted_mode, mode);
 75
 76	for (; dssdev; dssdev = dssdev->next) {
 77		if (!dssdev->ops || !dssdev->ops->check_timings)
 78			continue;
 
 
 
 
 
 
 
 
 
 
 
 
 79
 80		ret = dssdev->ops->check_timings(dssdev, adjusted_mode);
 81		if (ret)
 82			return MODE_BAD;
 
 
 
 
 
 83	}
 84
 85	return MODE_OK;
 86}
 87
 88static enum drm_mode_status omap_connector_mode_valid(struct drm_connector *connector,
 89				 struct drm_display_mode *mode)
 90{
 91	struct omap_connector *omap_connector = to_omap_connector(connector);
 92	struct drm_display_mode new_mode = {};
 93	enum drm_mode_status status;
 94
 95	status = omap_connector_mode_fixup(omap_connector->output, mode,
 96					   &new_mode);
 97	if (status != MODE_OK)
 98		goto done;
 99
100	/* Check if vrefresh is still valid. */
101	if (drm_mode_vrefresh(mode) != drm_mode_vrefresh(&new_mode))
102		status = MODE_NOCLOCK;
103
104done:
105	DBG("connector: mode %s: " DRM_MODE_FMT,
106			(status == MODE_OK) ? "valid" : "invalid",
107			DRM_MODE_ARG(mode));
108
109	return status;
110}
111
112static const struct drm_connector_funcs omap_connector_funcs = {
 
113	.reset = drm_atomic_helper_connector_reset,
114	.detect = omap_connector_detect,
115	.fill_modes = drm_helper_probe_single_connector_modes,
116	.destroy = omap_connector_destroy,
117	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
118	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
119};
120
121static const struct drm_connector_helper_funcs omap_connector_helper_funcs = {
122	.get_modes = omap_connector_get_modes,
123	.mode_valid = omap_connector_mode_valid,
124};
125
126/* initialize connector */
127struct drm_connector *omap_connector_init(struct drm_device *dev,
128					  struct omap_dss_device *output,
129					  struct drm_encoder *encoder)
130{
131	struct drm_connector *connector = NULL;
132	struct omap_connector *omap_connector;
133
134	DBG("%s", output->name);
 
 
135
136	omap_connector = kzalloc(sizeof(*omap_connector), GFP_KERNEL);
137	if (!omap_connector)
138		goto fail;
139
140	omap_connector->output = omapdss_device_get(output);
141
142	connector = &omap_connector->base;
 
 
 
 
 
 
 
 
 
 
 
 
 
143	connector->interlace_allowed = 1;
144	connector->doublescan_allowed = 0;
145
146	drm_connector_init(dev, connector, &omap_connector_funcs,
147			   DRM_MODE_CONNECTOR_DSI);
148	drm_connector_helper_add(connector, &omap_connector_helper_funcs);
149
150	return connector;
151
152fail:
153	if (connector)
154		omap_connector_destroy(connector);
155
156	return NULL;
157}