Linux Audio

Check our new training course

Loading...
v4.10.11
 
  1/*
  2 * i.MX drm driver - parallel display implementation
  3 *
  4 * Copyright (C) 2012 Sascha Hauer, Pengutronix
  5 *
  6 * This program is free software; you can redistribute it and/or
  7 * modify it under the terms of the GNU General Public License
  8 * as published by the Free Software Foundation; either version 2
  9 * of the License, or (at your option) any later version.
 10 * This program is distributed in the hope that it will be useful,
 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13 * GNU General Public License for more details.
 14 */
 15
 16#include <linux/component.h>
 17#include <linux/module.h>
 18#include <drm/drmP.h>
 
 
 
 
 19#include <drm/drm_atomic_helper.h>
 
 20#include <drm/drm_fb_helper.h>
 21#include <drm/drm_crtc_helper.h>
 22#include <drm/drm_panel.h>
 23#include <linux/videodev2.h>
 24#include <video/of_display_timing.h>
 25#include <linux/of_graph.h>
 26
 27#include "imx-drm.h"
 28
 29struct imx_parallel_display {
 30	struct drm_connector connector;
 31	struct drm_encoder encoder;
 
 32	struct device *dev;
 33	void *edid;
 34	int edid_len;
 35	u32 bus_format;
 36	u32 bus_flags;
 37	struct drm_display_mode mode;
 38	struct drm_panel *panel;
 39	struct drm_bridge *bridge;
 40};
 41
 42static inline struct imx_parallel_display *con_to_imxpd(struct drm_connector *c)
 43{
 44	return container_of(c, struct imx_parallel_display, connector);
 45}
 46
 47static inline struct imx_parallel_display *enc_to_imxpd(struct drm_encoder *e)
 48{
 49	return container_of(e, struct imx_parallel_display, encoder);
 50}
 51
 
 
 
 
 
 52static int imx_pd_connector_get_modes(struct drm_connector *connector)
 53{
 54	struct imx_parallel_display *imxpd = con_to_imxpd(connector);
 55	struct device_node *np = imxpd->dev->of_node;
 56	int num_modes = 0;
 57
 58	if (imxpd->panel && imxpd->panel->funcs &&
 59	    imxpd->panel->funcs->get_modes) {
 60		num_modes = imxpd->panel->funcs->get_modes(imxpd->panel);
 61		if (num_modes > 0)
 62			return num_modes;
 63	}
 64
 65	if (imxpd->edid) {
 66		drm_mode_connector_update_edid_property(connector, imxpd->edid);
 67		num_modes = drm_add_edid_modes(connector, imxpd->edid);
 68	}
 69
 70	if (np) {
 71		struct drm_display_mode *mode = drm_mode_create(connector->dev);
 72		int ret;
 73
 74		if (!mode)
 75			return -EINVAL;
 76
 77		ret = of_get_drm_display_mode(np, &imxpd->mode,
 78					      &imxpd->bus_flags,
 79					      OF_USE_NATIVE_MODE);
 80		if (ret)
 81			return ret;
 82
 83		drm_mode_copy(mode, &imxpd->mode);
 84		mode->type |= DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED,
 85		drm_mode_probed_add(connector, mode);
 86		num_modes++;
 87	}
 88
 89	return num_modes;
 90}
 91
 92static struct drm_encoder *imx_pd_connector_best_encoder(
 93		struct drm_connector *connector)
 94{
 95	struct imx_parallel_display *imxpd = con_to_imxpd(connector);
 96
 97	return &imxpd->encoder;
 98}
 99
100static void imx_pd_encoder_enable(struct drm_encoder *encoder)
101{
102	struct imx_parallel_display *imxpd = enc_to_imxpd(encoder);
103
104	drm_panel_prepare(imxpd->panel);
105	drm_panel_enable(imxpd->panel);
106}
107
108static void imx_pd_encoder_disable(struct drm_encoder *encoder)
109{
110	struct imx_parallel_display *imxpd = enc_to_imxpd(encoder);
111
112	drm_panel_disable(imxpd->panel);
113	drm_panel_unprepare(imxpd->panel);
114}
115
116static int imx_pd_encoder_atomic_check(struct drm_encoder *encoder,
117				       struct drm_crtc_state *crtc_state,
118				       struct drm_connector_state *conn_state)
 
 
 
 
 
 
 
 
 
 
 
 
119{
120	struct imx_crtc_state *imx_crtc_state = to_imx_crtc_state(crtc_state);
121	struct drm_display_info *di = &conn_state->connector->display_info;
122	struct imx_parallel_display *imxpd = enc_to_imxpd(encoder);
 
123
124	if (!imxpd->bus_format && di->num_bus_formats) {
125		imx_crtc_state->bus_flags = di->bus_flags;
126		imx_crtc_state->bus_format = di->bus_formats[0];
127	} else {
128		imx_crtc_state->bus_flags = imxpd->bus_flags;
129		imx_crtc_state->bus_format = imxpd->bus_format;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130	}
 
 
 
 
 
131	imx_crtc_state->di_hsync_pin = 2;
132	imx_crtc_state->di_vsync_pin = 3;
133
134	return 0;
135}
136
137static const struct drm_connector_funcs imx_pd_connector_funcs = {
138	.dpms = drm_atomic_helper_connector_dpms,
139	.fill_modes = drm_helper_probe_single_connector_modes,
140	.destroy = imx_drm_connector_destroy,
141	.reset = drm_atomic_helper_connector_reset,
142	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
143	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
144};
145
146static const struct drm_connector_helper_funcs imx_pd_connector_helper_funcs = {
147	.get_modes = imx_pd_connector_get_modes,
148	.best_encoder = imx_pd_connector_best_encoder,
149};
150
151static const struct drm_encoder_funcs imx_pd_encoder_funcs = {
152	.destroy = imx_drm_encoder_destroy,
153};
154
155static const struct drm_encoder_helper_funcs imx_pd_encoder_helper_funcs = {
156	.enable = imx_pd_encoder_enable,
157	.disable = imx_pd_encoder_disable,
158	.atomic_check = imx_pd_encoder_atomic_check,
 
 
 
 
 
159};
160
161static int imx_pd_register(struct drm_device *drm,
162	struct imx_parallel_display *imxpd)
163{
164	struct drm_encoder *encoder = &imxpd->encoder;
165	int ret;
166
167	ret = imx_drm_encoder_parse_of(drm, encoder, imxpd->dev->of_node);
168	if (ret)
169		return ret;
170
171	/* set the connector's dpms to OFF so that
172	 * drm_helper_connector_dpms() won't return
173	 * immediately since the current state is ON
174	 * at this point.
175	 */
176	imxpd->connector.dpms = DRM_MODE_DPMS_OFF;
177
178	drm_encoder_helper_add(encoder, &imx_pd_encoder_helper_funcs);
179	drm_encoder_init(drm, encoder, &imx_pd_encoder_funcs,
180			 DRM_MODE_ENCODER_NONE, NULL);
181
182	if (!imxpd->bridge) {
 
 
 
183		drm_connector_helper_add(&imxpd->connector,
184				&imx_pd_connector_helper_funcs);
185		drm_connector_init(drm, &imxpd->connector,
186				   &imx_pd_connector_funcs,
187				   DRM_MODE_CONNECTOR_VGA);
188	}
189
190	if (imxpd->panel)
191		drm_panel_attach(imxpd->panel, &imxpd->connector);
192
193	if (imxpd->bridge) {
194		imxpd->bridge->encoder = encoder;
195		encoder->bridge = imxpd->bridge;
196		ret = drm_bridge_attach(drm, imxpd->bridge);
197		if (ret < 0) {
198			dev_err(imxpd->dev, "failed to attach bridge: %d\n",
199				ret);
200			return ret;
201		}
202	} else {
203		drm_mode_connector_attach_encoder(&imxpd->connector, encoder);
204	}
205
206	return 0;
207}
208
209static int imx_pd_bind(struct device *dev, struct device *master, void *data)
210{
211	struct drm_device *drm = data;
212	struct device_node *np = dev->of_node;
213	struct device_node *ep;
214	const u8 *edidp;
215	struct imx_parallel_display *imxpd;
216	int ret;
217	u32 bus_format = 0;
218	const char *fmt;
219
220	imxpd = devm_kzalloc(dev, sizeof(*imxpd), GFP_KERNEL);
221	if (!imxpd)
222		return -ENOMEM;
 
 
 
 
 
223
224	edidp = of_get_property(np, "edid", &imxpd->edid_len);
225	if (edidp)
226		imxpd->edid = kmemdup(edidp, imxpd->edid_len, GFP_KERNEL);
227
228	ret = of_property_read_string(np, "interface-pix-fmt", &fmt);
229	if (!ret) {
230		if (!strcmp(fmt, "rgb24"))
231			bus_format = MEDIA_BUS_FMT_RGB888_1X24;
232		else if (!strcmp(fmt, "rgb565"))
233			bus_format = MEDIA_BUS_FMT_RGB565_1X16;
234		else if (!strcmp(fmt, "bgr666"))
235			bus_format = MEDIA_BUS_FMT_RGB666_1X18;
236		else if (!strcmp(fmt, "lvds666"))
237			bus_format = MEDIA_BUS_FMT_RGB666_1X24_CPADHI;
238	}
239	imxpd->bus_format = bus_format;
240
241	/* port@1 is the output port */
242	ep = of_graph_get_endpoint_by_regs(np, 1, -1);
243	if (ep) {
244		struct device_node *remote;
245
246		remote = of_graph_get_remote_port_parent(ep);
247		if (!remote) {
248			dev_warn(dev, "endpoint %s not connected\n",
249				 ep->full_name);
250			of_node_put(ep);
251			return -ENODEV;
252		}
253		of_node_put(ep);
254
255		imxpd->panel = of_drm_find_panel(remote);
256		if (imxpd->panel) {
257			dev_dbg(dev, "found panel %s\n", remote->full_name);
258		} else {
259			imxpd->bridge = of_drm_find_bridge(remote);
260			if (imxpd->bridge)
261				dev_dbg(dev, "found bridge %s\n",
262					remote->full_name);
263		}
264		if (!imxpd->panel && !imxpd->bridge) {
265			dev_dbg(dev, "waiting for panel or bridge %s\n",
266				remote->full_name);
267			of_node_put(remote);
268			return -EPROBE_DEFER;
269		}
270		of_node_put(remote);
271	}
272
273	imxpd->dev = dev;
274
275	ret = imx_pd_register(drm, imxpd);
276	if (ret)
277		return ret;
278
279	dev_set_drvdata(dev, imxpd);
280
281	return 0;
282}
283
284static void imx_pd_unbind(struct device *dev, struct device *master,
285	void *data)
286{
287	struct imx_parallel_display *imxpd = dev_get_drvdata(dev);
288
289	if (imxpd->bridge)
290		drm_bridge_detach(imxpd->bridge);
291	if (imxpd->panel)
292		drm_panel_detach(imxpd->panel);
293
294	kfree(imxpd->edid);
295}
296
297static const struct component_ops imx_pd_ops = {
298	.bind	= imx_pd_bind,
299	.unbind	= imx_pd_unbind,
300};
301
302static int imx_pd_probe(struct platform_device *pdev)
303{
 
 
 
 
 
 
 
 
304	return component_add(&pdev->dev, &imx_pd_ops);
305}
306
307static int imx_pd_remove(struct platform_device *pdev)
308{
309	component_del(&pdev->dev, &imx_pd_ops);
310
311	return 0;
312}
313
314static const struct of_device_id imx_pd_dt_ids[] = {
315	{ .compatible = "fsl,imx-parallel-display", },
316	{ /* sentinel */ }
317};
318MODULE_DEVICE_TABLE(of, imx_pd_dt_ids);
319
320static struct platform_driver imx_pd_driver = {
321	.probe		= imx_pd_probe,
322	.remove		= imx_pd_remove,
323	.driver		= {
324		.of_match_table = imx_pd_dt_ids,
325		.name	= "imx-parallel-display",
326	},
327};
328
329module_platform_driver(imx_pd_driver);
330
331MODULE_DESCRIPTION("i.MX parallel display driver");
332MODULE_AUTHOR("Sascha Hauer, Pengutronix");
333MODULE_LICENSE("GPL");
334MODULE_ALIAS("platform:imx-parallel-display");
v5.9
  1// SPDX-License-Identifier: GPL-2.0+
  2/*
  3 * i.MX drm driver - parallel display implementation
  4 *
  5 * Copyright (C) 2012 Sascha Hauer, Pengutronix
 
 
 
 
 
 
 
 
 
  6 */
  7
  8#include <linux/component.h>
  9#include <linux/module.h>
 10#include <linux/platform_device.h>
 11#include <linux/videodev2.h>
 12
 13#include <video/of_display_timing.h>
 14
 15#include <drm/drm_atomic_helper.h>
 16#include <drm/drm_bridge.h>
 17#include <drm/drm_fb_helper.h>
 18#include <drm/drm_of.h>
 19#include <drm/drm_panel.h>
 20#include <drm/drm_probe_helper.h>
 21#include <drm/drm_simple_kms_helper.h>
 
 22
 23#include "imx-drm.h"
 24
 25struct imx_parallel_display {
 26	struct drm_connector connector;
 27	struct drm_encoder encoder;
 28	struct drm_bridge bridge;
 29	struct device *dev;
 30	void *edid;
 31	int edid_len;
 32	u32 bus_format;
 33	u32 bus_flags;
 34	struct drm_display_mode mode;
 35	struct drm_panel *panel;
 36	struct drm_bridge *next_bridge;
 37};
 38
 39static inline struct imx_parallel_display *con_to_imxpd(struct drm_connector *c)
 40{
 41	return container_of(c, struct imx_parallel_display, connector);
 42}
 43
 44static inline struct imx_parallel_display *enc_to_imxpd(struct drm_encoder *e)
 45{
 46	return container_of(e, struct imx_parallel_display, encoder);
 47}
 48
 49static inline struct imx_parallel_display *bridge_to_imxpd(struct drm_bridge *b)
 50{
 51	return container_of(b, struct imx_parallel_display, bridge);
 52}
 53
 54static int imx_pd_connector_get_modes(struct drm_connector *connector)
 55{
 56	struct imx_parallel_display *imxpd = con_to_imxpd(connector);
 57	struct device_node *np = imxpd->dev->of_node;
 58	int num_modes;
 59
 60	num_modes = drm_panel_get_modes(imxpd->panel, connector);
 61	if (num_modes > 0)
 62		return num_modes;
 
 
 
 63
 64	if (imxpd->edid) {
 65		drm_connector_update_edid_property(connector, imxpd->edid);
 66		num_modes = drm_add_edid_modes(connector, imxpd->edid);
 67	}
 68
 69	if (np) {
 70		struct drm_display_mode *mode = drm_mode_create(connector->dev);
 71		int ret;
 72
 73		if (!mode)
 74			return -EINVAL;
 75
 76		ret = of_get_drm_display_mode(np, &imxpd->mode,
 77					      &imxpd->bus_flags,
 78					      OF_USE_NATIVE_MODE);
 79		if (ret)
 80			return ret;
 81
 82		drm_mode_copy(mode, &imxpd->mode);
 83		mode->type |= DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED,
 84		drm_mode_probed_add(connector, mode);
 85		num_modes++;
 86	}
 87
 88	return num_modes;
 89}
 90
 91static void imx_pd_bridge_enable(struct drm_bridge *bridge)
 
 
 
 
 
 
 
 
 92{
 93	struct imx_parallel_display *imxpd = bridge_to_imxpd(bridge);
 94
 95	drm_panel_prepare(imxpd->panel);
 96	drm_panel_enable(imxpd->panel);
 97}
 98
 99static void imx_pd_bridge_disable(struct drm_bridge *bridge)
100{
101	struct imx_parallel_display *imxpd = bridge_to_imxpd(bridge);
102
103	drm_panel_disable(imxpd->panel);
104	drm_panel_unprepare(imxpd->panel);
105}
106
107static const u32 imx_pd_bus_fmts[] = {
108	MEDIA_BUS_FMT_RGB888_1X24,
109	MEDIA_BUS_FMT_BGR888_1X24,
110	MEDIA_BUS_FMT_GBR888_1X24,
111	MEDIA_BUS_FMT_RGB666_1X18,
112	MEDIA_BUS_FMT_RGB666_1X24_CPADHI,
113	MEDIA_BUS_FMT_RGB565_1X16,
114};
115
116static u32 *
117imx_pd_bridge_atomic_get_output_bus_fmts(struct drm_bridge *bridge,
118					 struct drm_bridge_state *bridge_state,
119					 struct drm_crtc_state *crtc_state,
120					 struct drm_connector_state *conn_state,
121					 unsigned int *num_output_fmts)
122{
 
123	struct drm_display_info *di = &conn_state->connector->display_info;
124	struct imx_parallel_display *imxpd = bridge_to_imxpd(bridge);
125	u32 *output_fmts;
126
127	if (!imxpd->bus_format && !di->num_bus_formats) {
128		*num_output_fmts = ARRAY_SIZE(imx_pd_bus_fmts);
129		return kmemdup(imx_pd_bus_fmts, sizeof(imx_pd_bus_fmts),
130			       GFP_KERNEL);
131	}
132
133	*num_output_fmts = 1;
134	output_fmts = kmalloc(sizeof(*output_fmts), GFP_KERNEL);
135	if (!output_fmts)
136		return NULL;
137
138	if (!imxpd->bus_format && di->num_bus_formats)
139		output_fmts[0] = di->bus_formats[0];
140	else
141		output_fmts[0] = imxpd->bus_format;
142
143	return output_fmts;
144}
145
146static bool imx_pd_format_supported(u32 output_fmt)
147{
148	unsigned int i;
149
150	for (i = 0; i < ARRAY_SIZE(imx_pd_bus_fmts); i++) {
151		if (imx_pd_bus_fmts[i] == output_fmt)
152			return true;
153	}
154
155	return false;
156}
157
158static u32 *
159imx_pd_bridge_atomic_get_input_bus_fmts(struct drm_bridge *bridge,
160					struct drm_bridge_state *bridge_state,
161					struct drm_crtc_state *crtc_state,
162					struct drm_connector_state *conn_state,
163					u32 output_fmt,
164					unsigned int *num_input_fmts)
165{
166	struct imx_parallel_display *imxpd = bridge_to_imxpd(bridge);
167	u32 *input_fmts;
168
169	/*
170	 * If the next bridge does not support bus format negotiation, let's
171	 * use the static bus format definition (imxpd->bus_format) if it's
172	 * specified, RGB888 when it's not.
173	 */
174	if (output_fmt == MEDIA_BUS_FMT_FIXED)
175		output_fmt = imxpd->bus_format ? : MEDIA_BUS_FMT_RGB888_1X24;
176
177	/* Now make sure the requested output format is supported. */
178	if ((imxpd->bus_format && imxpd->bus_format != output_fmt) ||
179	    !imx_pd_format_supported(output_fmt)) {
180		*num_input_fmts = 0;
181		return NULL;
182	}
183
184	*num_input_fmts = 1;
185	input_fmts = kmalloc(sizeof(*input_fmts), GFP_KERNEL);
186	if (!input_fmts)
187		return NULL;
188
189	input_fmts[0] = output_fmt;
190	return input_fmts;
191}
192
193static int imx_pd_bridge_atomic_check(struct drm_bridge *bridge,
194				      struct drm_bridge_state *bridge_state,
195				      struct drm_crtc_state *crtc_state,
196				      struct drm_connector_state *conn_state)
197{
198	struct imx_crtc_state *imx_crtc_state = to_imx_crtc_state(crtc_state);
199	struct drm_display_info *di = &conn_state->connector->display_info;
200	struct imx_parallel_display *imxpd = bridge_to_imxpd(bridge);
201	struct drm_bridge_state *next_bridge_state = NULL;
202	struct drm_bridge *next_bridge;
203	u32 bus_flags, bus_fmt;
204
205	next_bridge = drm_bridge_get_next_bridge(bridge);
206	if (next_bridge)
207		next_bridge_state = drm_atomic_get_new_bridge_state(crtc_state->state,
208								    next_bridge);
209
210	if (next_bridge_state)
211		bus_flags = next_bridge_state->input_bus_cfg.flags;
212	else if (di->num_bus_formats)
213		bus_flags = di->bus_flags;
214	else
215		bus_flags = imxpd->bus_flags;
216
217	bus_fmt = bridge_state->input_bus_cfg.format;
218	if (!imx_pd_format_supported(bus_fmt))
219		return -EINVAL;
220
221	if (bus_flags &
222	    ~(DRM_BUS_FLAG_DE_LOW | DRM_BUS_FLAG_DE_HIGH |
223	      DRM_BUS_FLAG_PIXDATA_DRIVE_POSEDGE |
224	      DRM_BUS_FLAG_PIXDATA_DRIVE_NEGEDGE)) {
225		dev_warn(imxpd->dev, "invalid bus_flags (%x)\n", bus_flags);
226		return -EINVAL;
227	}
228
229	bridge_state->output_bus_cfg.flags = bus_flags;
230	bridge_state->input_bus_cfg.flags = bus_flags;
231	imx_crtc_state->bus_flags = bus_flags;
232	imx_crtc_state->bus_format = bridge_state->input_bus_cfg.format;
233	imx_crtc_state->di_hsync_pin = 2;
234	imx_crtc_state->di_vsync_pin = 3;
235
236	return 0;
237}
238
239static const struct drm_connector_funcs imx_pd_connector_funcs = {
 
240	.fill_modes = drm_helper_probe_single_connector_modes,
241	.destroy = imx_drm_connector_destroy,
242	.reset = drm_atomic_helper_connector_reset,
243	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
244	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
245};
246
247static const struct drm_connector_helper_funcs imx_pd_connector_helper_funcs = {
248	.get_modes = imx_pd_connector_get_modes,
 
 
 
 
 
249};
250
251static const struct drm_bridge_funcs imx_pd_bridge_funcs = {
252	.enable = imx_pd_bridge_enable,
253	.disable = imx_pd_bridge_disable,
254	.atomic_reset = drm_atomic_helper_bridge_reset,
255	.atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state,
256	.atomic_destroy_state = drm_atomic_helper_bridge_destroy_state,
257	.atomic_check = imx_pd_bridge_atomic_check,
258	.atomic_get_input_bus_fmts = imx_pd_bridge_atomic_get_input_bus_fmts,
259	.atomic_get_output_bus_fmts = imx_pd_bridge_atomic_get_output_bus_fmts,
260};
261
262static int imx_pd_register(struct drm_device *drm,
263	struct imx_parallel_display *imxpd)
264{
265	struct drm_encoder *encoder = &imxpd->encoder;
266	int ret;
267
268	ret = imx_drm_encoder_parse_of(drm, encoder, imxpd->dev->of_node);
269	if (ret)
270		return ret;
271
272	/* set the connector's dpms to OFF so that
273	 * drm_helper_connector_dpms() won't return
274	 * immediately since the current state is ON
275	 * at this point.
276	 */
277	imxpd->connector.dpms = DRM_MODE_DPMS_OFF;
278
279	drm_simple_encoder_init(drm, encoder, DRM_MODE_ENCODER_NONE);
 
 
280
281	imxpd->bridge.funcs = &imx_pd_bridge_funcs;
282	drm_bridge_attach(encoder, &imxpd->bridge, NULL, 0);
283
284	if (!imxpd->next_bridge) {
285		drm_connector_helper_add(&imxpd->connector,
286				&imx_pd_connector_helper_funcs);
287		drm_connector_init(drm, &imxpd->connector,
288				   &imx_pd_connector_funcs,
289				   DRM_MODE_CONNECTOR_DPI);
290	}
291
292	if (imxpd->panel)
293		drm_panel_attach(imxpd->panel, &imxpd->connector);
294
295	if (imxpd->next_bridge) {
296		ret = drm_bridge_attach(encoder, imxpd->next_bridge,
297					&imxpd->bridge, 0);
 
298		if (ret < 0) {
299			dev_err(imxpd->dev, "failed to attach bridge: %d\n",
300				ret);
301			return ret;
302		}
303	} else {
304		drm_connector_attach_encoder(&imxpd->connector, encoder);
305	}
306
307	return 0;
308}
309
310static int imx_pd_bind(struct device *dev, struct device *master, void *data)
311{
312	struct drm_device *drm = data;
313	struct device_node *np = dev->of_node;
 
314	const u8 *edidp;
315	struct imx_parallel_display *imxpd;
316	int ret;
317	u32 bus_format = 0;
318	const char *fmt;
319
320	imxpd = dev_get_drvdata(dev);
321	memset(imxpd, 0, sizeof(*imxpd));
322
323	/* port@1 is the output port */
324	ret = drm_of_find_panel_or_bridge(np, 1, 0, &imxpd->panel,
325					  &imxpd->next_bridge);
326	if (ret && ret != -ENODEV)
327		return ret;
328
329	edidp = of_get_property(np, "edid", &imxpd->edid_len);
330	if (edidp)
331		imxpd->edid = kmemdup(edidp, imxpd->edid_len, GFP_KERNEL);
332
333	ret = of_property_read_string(np, "interface-pix-fmt", &fmt);
334	if (!ret) {
335		if (!strcmp(fmt, "rgb24"))
336			bus_format = MEDIA_BUS_FMT_RGB888_1X24;
337		else if (!strcmp(fmt, "rgb565"))
338			bus_format = MEDIA_BUS_FMT_RGB565_1X16;
339		else if (!strcmp(fmt, "bgr666"))
340			bus_format = MEDIA_BUS_FMT_RGB666_1X18;
341		else if (!strcmp(fmt, "lvds666"))
342			bus_format = MEDIA_BUS_FMT_RGB666_1X24_CPADHI;
343	}
344	imxpd->bus_format = bus_format;
345
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
346	imxpd->dev = dev;
347
348	ret = imx_pd_register(drm, imxpd);
349	if (ret)
350		return ret;
351
 
 
352	return 0;
353}
354
355static void imx_pd_unbind(struct device *dev, struct device *master,
356	void *data)
357{
358	struct imx_parallel_display *imxpd = dev_get_drvdata(dev);
359
 
 
360	if (imxpd->panel)
361		drm_panel_detach(imxpd->panel);
362
363	kfree(imxpd->edid);
364}
365
366static const struct component_ops imx_pd_ops = {
367	.bind	= imx_pd_bind,
368	.unbind	= imx_pd_unbind,
369};
370
371static int imx_pd_probe(struct platform_device *pdev)
372{
373	struct imx_parallel_display *imxpd;
374
375	imxpd = devm_kzalloc(&pdev->dev, sizeof(*imxpd), GFP_KERNEL);
376	if (!imxpd)
377		return -ENOMEM;
378
379	platform_set_drvdata(pdev, imxpd);
380
381	return component_add(&pdev->dev, &imx_pd_ops);
382}
383
384static int imx_pd_remove(struct platform_device *pdev)
385{
386	component_del(&pdev->dev, &imx_pd_ops);
387
388	return 0;
389}
390
391static const struct of_device_id imx_pd_dt_ids[] = {
392	{ .compatible = "fsl,imx-parallel-display", },
393	{ /* sentinel */ }
394};
395MODULE_DEVICE_TABLE(of, imx_pd_dt_ids);
396
397static struct platform_driver imx_pd_driver = {
398	.probe		= imx_pd_probe,
399	.remove		= imx_pd_remove,
400	.driver		= {
401		.of_match_table = imx_pd_dt_ids,
402		.name	= "imx-parallel-display",
403	},
404};
405
406module_platform_driver(imx_pd_driver);
407
408MODULE_DESCRIPTION("i.MX parallel display driver");
409MODULE_AUTHOR("Sascha Hauer, Pengutronix");
410MODULE_LICENSE("GPL");
411MODULE_ALIAS("platform:imx-parallel-display");