Linux Audio

Check our new training course

Loading...
v5.4
  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 <linux/list.h>
  8
  9#include <drm/drm_crtc.h>
 10#include <drm/drm_modeset_helper_vtables.h>
 11#include <drm/drm_edid.h>
 12#include <drm/drm_panel.h>
 13
 14#include "omap_drv.h"
 15
 16/*
 17 * encoder funcs
 18 */
 19
 20#define to_omap_encoder(x) container_of(x, struct omap_encoder, base)
 21
 22/* The encoder and connector both map to same dssdev.. the encoder
 23 * handles the 'active' parts, ie. anything the modifies the state
 24 * of the hw, and the connector handles the 'read-only' parts, like
 25 * detecting connection and reading edid.
 26 */
 27struct omap_encoder {
 28	struct drm_encoder base;
 29	struct omap_dss_device *output;
 30};
 31
 
 
 
 
 
 
 
 32static void omap_encoder_destroy(struct drm_encoder *encoder)
 33{
 34	struct omap_encoder *omap_encoder = to_omap_encoder(encoder);
 35
 36	drm_encoder_cleanup(encoder);
 37	kfree(omap_encoder);
 38}
 39
 40static const struct drm_encoder_funcs omap_encoder_funcs = {
 41	.destroy = omap_encoder_destroy,
 42};
 43
 44static void omap_encoder_update_videomode_flags(struct videomode *vm,
 45						u32 bus_flags)
 46{
 47	if (!(vm->flags & (DISPLAY_FLAGS_DE_LOW |
 48			   DISPLAY_FLAGS_DE_HIGH))) {
 49		if (bus_flags & DRM_BUS_FLAG_DE_LOW)
 50			vm->flags |= DISPLAY_FLAGS_DE_LOW;
 51		else if (bus_flags & DRM_BUS_FLAG_DE_HIGH)
 52			vm->flags |= DISPLAY_FLAGS_DE_HIGH;
 53	}
 54
 55	if (!(vm->flags & (DISPLAY_FLAGS_PIXDATA_POSEDGE |
 56			   DISPLAY_FLAGS_PIXDATA_NEGEDGE))) {
 57		if (bus_flags & DRM_BUS_FLAG_PIXDATA_DRIVE_POSEDGE)
 58			vm->flags |= DISPLAY_FLAGS_PIXDATA_POSEDGE;
 59		else if (bus_flags & DRM_BUS_FLAG_PIXDATA_DRIVE_NEGEDGE)
 60			vm->flags |= DISPLAY_FLAGS_PIXDATA_NEGEDGE;
 61	}
 62
 63	if (!(vm->flags & (DISPLAY_FLAGS_SYNC_POSEDGE |
 64			   DISPLAY_FLAGS_SYNC_NEGEDGE))) {
 65		if (bus_flags & DRM_BUS_FLAG_SYNC_DRIVE_POSEDGE)
 66			vm->flags |= DISPLAY_FLAGS_SYNC_POSEDGE;
 67		else if (bus_flags & DRM_BUS_FLAG_SYNC_DRIVE_NEGEDGE)
 68			vm->flags |= DISPLAY_FLAGS_SYNC_NEGEDGE;
 69	}
 70}
 71
 72static void omap_encoder_hdmi_mode_set(struct drm_connector *connector,
 73				       struct drm_encoder *encoder,
 74				       struct drm_display_mode *adjusted_mode)
 75{
 
 76	struct omap_encoder *omap_encoder = to_omap_encoder(encoder);
 77	struct omap_dss_device *dssdev = omap_encoder->output;
 
 78	bool hdmi_mode;
 
 79
 80	hdmi_mode = omap_connector_get_hdmi_mode(connector);
 
 
 
 
 
 
 81
 82	if (dssdev->ops->hdmi.set_hdmi_mode)
 83		dssdev->ops->hdmi.set_hdmi_mode(dssdev, hdmi_mode);
 84
 85	if (hdmi_mode && dssdev->ops->hdmi.set_infoframe) {
 86		struct hdmi_avi_infoframe avi;
 87		int r;
 88
 89		r = drm_hdmi_avi_infoframe_from_display_mode(&avi, connector,
 90							     adjusted_mode);
 91		if (r == 0)
 92			dssdev->ops->hdmi.set_infoframe(dssdev, &avi);
 93	}
 94}
 95
 96static void omap_encoder_mode_set(struct drm_encoder *encoder,
 97				  struct drm_display_mode *mode,
 98				  struct drm_display_mode *adjusted_mode)
 99{
100	struct omap_encoder *omap_encoder = to_omap_encoder(encoder);
101	struct omap_dss_device *output = omap_encoder->output;
102	struct omap_dss_device *dssdev;
103	struct drm_device *dev = encoder->dev;
104	struct drm_connector *connector;
105	struct drm_bridge *bridge;
106	struct videomode vm = { 0 };
107	u32 bus_flags;
108
109	list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
110		if (connector->encoder == encoder)
111			break;
112	}
113
114	drm_display_mode_to_videomode(adjusted_mode, &vm);
115
116	/*
117	 * HACK: This fixes the vm flags.
118	 * struct drm_display_mode does not contain the VSYNC/HSYNC/DE flags and
119	 * they get lost when converting back and forth between struct
120	 * drm_display_mode and struct videomode. The hack below goes and
121	 * fetches the missing flags.
122	 *
123	 * A better solution is to use DRM's bus-flags through the whole driver.
124	 */
125	for (dssdev = output; dssdev; dssdev = dssdev->next)
126		omap_encoder_update_videomode_flags(&vm, dssdev->bus_flags);
127
128	for (bridge = output->bridge; bridge; bridge = bridge->next) {
129		if (!bridge->timings)
130			continue;
131
132		bus_flags = bridge->timings->input_bus_flags;
133		omap_encoder_update_videomode_flags(&vm, bus_flags);
134	}
135
136	bus_flags = connector->display_info.bus_flags;
137	omap_encoder_update_videomode_flags(&vm, bus_flags);
138
139	/* Set timings for all devices in the display pipeline. */
140	dss_mgr_set_timings(output, &vm);
141
142	for (dssdev = output; dssdev; dssdev = dssdev->next) {
143		if (dssdev->ops->set_timings)
144			dssdev->ops->set_timings(dssdev, adjusted_mode);
145	}
146
147	/* Set the HDMI mode and HDMI infoframe if applicable. */
148	if (output->type == OMAP_DISPLAY_TYPE_HDMI)
149		omap_encoder_hdmi_mode_set(connector, encoder, adjusted_mode);
150}
151
152static void omap_encoder_disable(struct drm_encoder *encoder)
 
 
153{
154	struct omap_encoder *omap_encoder = to_omap_encoder(encoder);
155	struct omap_dss_device *dssdev = omap_encoder->output;
156	struct drm_device *dev = encoder->dev;
 
 
 
 
 
 
 
 
 
157
158	dev_dbg(dev->dev, "disable(%s)\n", dssdev->name);
159
160	/* Disable the panel if present. */
161	if (dssdev->panel) {
162		drm_panel_disable(dssdev->panel);
163		drm_panel_unprepare(dssdev->panel);
164	}
165
166	/*
167	 * Disable the chain of external devices, starting at the one at the
168	 * internal encoder's output.
169	 */
170	omapdss_device_disable(dssdev->next);
171
172	/*
173	 * Disable the internal encoder. This will disable the DSS output. The
174	 * DSI is treated as an exception as DSI pipelines still use the legacy
175	 * flow where the pipeline output controls the encoder.
176	 */
177	if (dssdev->type != OMAP_DISPLAY_TYPE_DSI) {
178		dssdev->ops->disable(dssdev);
179		dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
180	}
181
182	/*
183	 * Perform the post-disable operations on the chain of external devices
184	 * to complete the display pipeline disable.
185	 */
186	omapdss_device_post_disable(dssdev->next);
187}
188
189static void omap_encoder_enable(struct drm_encoder *encoder)
190{
191	struct omap_encoder *omap_encoder = to_omap_encoder(encoder);
192	struct omap_dss_device *dssdev = omap_encoder->output;
193	struct drm_device *dev = encoder->dev;
194
195	dev_dbg(dev->dev, "enable(%s)\n", dssdev->name);
196
197	/* Prepare the chain of external devices for pipeline enable. */
198	omapdss_device_pre_enable(dssdev->next);
199
200	/*
201	 * Enable the internal encoder. This will enable the DSS output. The
202	 * DSI is treated as an exception as DSI pipelines still use the legacy
203	 * flow where the pipeline output controls the encoder.
204	 */
205	if (dssdev->type != OMAP_DISPLAY_TYPE_DSI) {
206		dssdev->ops->enable(dssdev);
207		dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
208	}
209
210	/*
211	 * Enable the chain of external devices, starting at the one at the
212	 * internal encoder's output.
213	 */
214	omapdss_device_enable(dssdev->next);
215
216	/* Enable the panel if present. */
217	if (dssdev->panel) {
218		drm_panel_prepare(dssdev->panel);
219		drm_panel_enable(dssdev->panel);
220	}
221}
222
223static int omap_encoder_atomic_check(struct drm_encoder *encoder,
224				     struct drm_crtc_state *crtc_state,
225				     struct drm_connector_state *conn_state)
226{
227	struct omap_encoder *omap_encoder = to_omap_encoder(encoder);
228	enum drm_mode_status status;
229
230	status = omap_connector_mode_fixup(omap_encoder->output,
231					   &crtc_state->mode,
232					   &crtc_state->adjusted_mode);
233	if (status != MODE_OK) {
234		dev_err(encoder->dev->dev, "invalid timings: %d\n", status);
235		return -EINVAL;
236	}
237
238	return 0;
239}
240
241static const struct drm_encoder_helper_funcs omap_encoder_helper_funcs = {
242	.mode_set = omap_encoder_mode_set,
243	.disable = omap_encoder_disable,
244	.enable = omap_encoder_enable,
245	.atomic_check = omap_encoder_atomic_check,
246};
247
248/* initialize encoder */
249struct drm_encoder *omap_encoder_init(struct drm_device *dev,
250				      struct omap_dss_device *output)
251{
252	struct drm_encoder *encoder = NULL;
253	struct omap_encoder *omap_encoder;
254
255	omap_encoder = kzalloc(sizeof(*omap_encoder), GFP_KERNEL);
256	if (!omap_encoder)
257		goto fail;
258
259	omap_encoder->output = output;
260
261	encoder = &omap_encoder->base;
262
263	drm_encoder_init(dev, encoder, &omap_encoder_funcs,
264			 DRM_MODE_ENCODER_TMDS, NULL);
265	drm_encoder_helper_add(encoder, &omap_encoder_helper_funcs);
266
267	return encoder;
268
269fail:
270	if (encoder)
271		omap_encoder_destroy(encoder);
272
273	return NULL;
274}
v4.17
 
  1/*
  2 * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
  3 * Author: Rob Clark <rob@ti.com>
  4 *
  5 * This program is free software; you can redistribute it and/or modify it
  6 * under the terms of the GNU General Public License version 2 as published by
  7 * the Free Software Foundation.
  8 *
  9 * This program is distributed in the hope that it will be useful, but WITHOUT
 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 12 * more details.
 13 *
 14 * You should have received a copy of the GNU General Public License along with
 15 * this program.  If not, see <http://www.gnu.org/licenses/>.
 16 */
 17
 18#include <linux/list.h>
 19
 20#include <drm/drm_crtc.h>
 21#include <drm/drm_crtc_helper.h>
 22#include <drm/drm_edid.h>
 
 23
 24#include "omap_drv.h"
 25
 26/*
 27 * encoder funcs
 28 */
 29
 30#define to_omap_encoder(x) container_of(x, struct omap_encoder, base)
 31
 32/* The encoder and connector both map to same dssdev.. the encoder
 33 * handles the 'active' parts, ie. anything the modifies the state
 34 * of the hw, and the connector handles the 'read-only' parts, like
 35 * detecting connection and reading edid.
 36 */
 37struct omap_encoder {
 38	struct drm_encoder base;
 39	struct omap_dss_device *dssdev;
 40};
 41
 42struct omap_dss_device *omap_encoder_get_dssdev(struct drm_encoder *encoder)
 43{
 44	struct omap_encoder *omap_encoder = to_omap_encoder(encoder);
 45
 46	return omap_encoder->dssdev;
 47}
 48
 49static void omap_encoder_destroy(struct drm_encoder *encoder)
 50{
 51	struct omap_encoder *omap_encoder = to_omap_encoder(encoder);
 52
 53	drm_encoder_cleanup(encoder);
 54	kfree(omap_encoder);
 55}
 56
 57static const struct drm_encoder_funcs omap_encoder_funcs = {
 58	.destroy = omap_encoder_destroy,
 59};
 60
 61static void omap_encoder_mode_set(struct drm_encoder *encoder,
 62				struct drm_display_mode *mode,
 63				struct drm_display_mode *adjusted_mode)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 64{
 65	struct drm_device *dev = encoder->dev;
 66	struct omap_encoder *omap_encoder = to_omap_encoder(encoder);
 67	struct omap_dss_device *dssdev = omap_encoder->dssdev;
 68	struct drm_connector *connector;
 69	bool hdmi_mode;
 70	int r;
 71
 72	hdmi_mode = false;
 73	list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
 74		if (connector->encoder == encoder) {
 75			hdmi_mode = omap_connector_get_hdmi_mode(connector);
 76			break;
 77		}
 78	}
 79
 80	if (dssdev->driver->set_hdmi_mode)
 81		dssdev->driver->set_hdmi_mode(dssdev, hdmi_mode);
 82
 83	if (hdmi_mode && dssdev->driver->set_hdmi_infoframe) {
 84		struct hdmi_avi_infoframe avi;
 
 85
 86		r = drm_hdmi_avi_infoframe_from_display_mode(&avi, adjusted_mode,
 87							     false);
 88		if (r == 0)
 89			dssdev->driver->set_hdmi_infoframe(dssdev, &avi);
 90	}
 91}
 92
 93static void omap_encoder_disable(struct drm_encoder *encoder)
 
 
 94{
 95	struct omap_encoder *omap_encoder = to_omap_encoder(encoder);
 96	struct omap_dss_device *dssdev = omap_encoder->dssdev;
 97	struct omap_dss_driver *dssdrv = dssdev->driver;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 98
 99	dssdrv->disable(dssdev);
 
 
 
 
 
 
 
 
 
 
100}
101
102static int omap_encoder_update(struct drm_encoder *encoder,
103			       enum omap_channel channel,
104			       struct videomode *vm)
105{
 
 
106	struct drm_device *dev = encoder->dev;
107	struct omap_encoder *omap_encoder = to_omap_encoder(encoder);
108	struct omap_dss_device *dssdev = omap_encoder->dssdev;
109	struct omap_dss_driver *dssdrv = dssdev->driver;
110	int ret;
111
112	if (dssdrv->check_timings) {
113		ret = dssdrv->check_timings(dssdev, vm);
114	} else {
115		struct videomode t = {0};
116
117		dssdrv->get_timings(dssdev, &t);
118
119		if (memcmp(vm, &t, sizeof(*vm)))
120			ret = -EINVAL;
121		else
122			ret = 0;
123	}
124
125	if (ret) {
126		dev_err(dev->dev, "could not set timings: %d\n", ret);
127		return ret;
 
 
 
 
 
 
 
 
 
 
 
128	}
129
130	if (dssdrv->set_timings)
131		dssdrv->set_timings(dssdev, vm);
132
133	return 0;
 
134}
135
136static void omap_encoder_enable(struct drm_encoder *encoder)
137{
138	struct omap_encoder *omap_encoder = to_omap_encoder(encoder);
139	struct omap_dss_device *dssdev = omap_encoder->dssdev;
140	struct omap_dss_driver *dssdrv = dssdev->driver;
141	int r;
142
143	omap_encoder_update(encoder, omap_crtc_channel(encoder->crtc),
144			    omap_crtc_timings(encoder->crtc));
145
146	r = dssdrv->enable(dssdev);
147	if (r)
148		dev_err(encoder->dev->dev,
149			"Failed to enable display '%s': %d\n",
150			dssdev->name, r);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
151}
152
153static int omap_encoder_atomic_check(struct drm_encoder *encoder,
154				     struct drm_crtc_state *crtc_state,
155				     struct drm_connector_state *conn_state)
156{
 
 
 
 
 
 
 
 
 
 
 
157	return 0;
158}
159
160static const struct drm_encoder_helper_funcs omap_encoder_helper_funcs = {
161	.mode_set = omap_encoder_mode_set,
162	.disable = omap_encoder_disable,
163	.enable = omap_encoder_enable,
164	.atomic_check = omap_encoder_atomic_check,
165};
166
167/* initialize encoder */
168struct drm_encoder *omap_encoder_init(struct drm_device *dev,
169		struct omap_dss_device *dssdev)
170{
171	struct drm_encoder *encoder = NULL;
172	struct omap_encoder *omap_encoder;
173
174	omap_encoder = kzalloc(sizeof(*omap_encoder), GFP_KERNEL);
175	if (!omap_encoder)
176		goto fail;
177
178	omap_encoder->dssdev = dssdev;
179
180	encoder = &omap_encoder->base;
181
182	drm_encoder_init(dev, encoder, &omap_encoder_funcs,
183			 DRM_MODE_ENCODER_TMDS, NULL);
184	drm_encoder_helper_add(encoder, &omap_encoder_helper_funcs);
185
186	return encoder;
187
188fail:
189	if (encoder)
190		omap_encoder_destroy(encoder);
191
192	return NULL;
193}