Linux Audio

Check our new training course

Loading...
v5.9
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  3 * Copyright (C) 2019 Laurent Pinchart <laurent.pinchart@ideasonboard.com>
  4 */
  5
  6#include <linux/gpio/consumer.h>
  7#include <linux/i2c.h>
  8#include <linux/interrupt.h>
 
  9#include <linux/module.h>
 10#include <linux/mutex.h>
 11#include <linux/of.h>
 12#include <linux/of_device.h>
 13#include <linux/platform_device.h>
 
 14
 
 15#include <drm/drm_bridge.h>
 16#include <drm/drm_edid.h>
 17
 18struct display_connector {
 19	struct drm_bridge	bridge;
 20
 21	struct gpio_desc	*hpd_gpio;
 22	int			hpd_irq;
 
 
 
 23};
 24
 25static inline struct display_connector *
 26to_display_connector(struct drm_bridge *bridge)
 27{
 28	return container_of(bridge, struct display_connector, bridge);
 29}
 30
 31static int display_connector_attach(struct drm_bridge *bridge,
 32				    enum drm_bridge_attach_flags flags)
 33{
 34	return flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR ? 0 : -EINVAL;
 35}
 36
 37static enum drm_connector_status
 38display_connector_detect(struct drm_bridge *bridge)
 39{
 40	struct display_connector *conn = to_display_connector(bridge);
 41
 42	if (conn->hpd_gpio) {
 43		if (gpiod_get_value_cansleep(conn->hpd_gpio))
 44			return connector_status_connected;
 45		else
 46			return connector_status_disconnected;
 47	}
 48
 49	if (conn->bridge.ddc && drm_probe_ddc(conn->bridge.ddc))
 50		return connector_status_connected;
 51
 52	switch (conn->bridge.type) {
 53	case DRM_MODE_CONNECTOR_DVIA:
 54	case DRM_MODE_CONNECTOR_DVID:
 55	case DRM_MODE_CONNECTOR_DVII:
 56	case DRM_MODE_CONNECTOR_HDMIA:
 57	case DRM_MODE_CONNECTOR_HDMIB:
 58		/*
 59		 * For DVI and HDMI connectors a DDC probe failure indicates
 60		 * that no cable is connected.
 61		 */
 62		return connector_status_disconnected;
 63
 64	case DRM_MODE_CONNECTOR_Composite:
 65	case DRM_MODE_CONNECTOR_SVIDEO:
 66	case DRM_MODE_CONNECTOR_VGA:
 67	default:
 68		/*
 69		 * Composite and S-Video connectors have no other detection
 70		 * mean than the HPD GPIO. For VGA connectors, even if we have
 71		 * an I2C bus, we can't assume that the cable is disconnected
 72		 * if drm_probe_ddc fails, as some cables don't wire the DDC
 73		 * pins.
 74		 */
 75		return connector_status_unknown;
 76	}
 77}
 78
 79static struct edid *display_connector_get_edid(struct drm_bridge *bridge,
 80					       struct drm_connector *connector)
 81{
 82	struct display_connector *conn = to_display_connector(bridge);
 83
 84	return drm_get_edid(connector, conn->bridge.ddc);
 85}
 86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 87static const struct drm_bridge_funcs display_connector_bridge_funcs = {
 88	.attach = display_connector_attach,
 89	.detect = display_connector_detect,
 90	.get_edid = display_connector_get_edid,
 
 
 
 
 
 91};
 92
 93static irqreturn_t display_connector_hpd_irq(int irq, void *arg)
 94{
 95	struct display_connector *conn = arg;
 96	struct drm_bridge *bridge = &conn->bridge;
 97
 98	drm_bridge_hpd_notify(bridge, display_connector_detect(bridge));
 99
100	return IRQ_HANDLED;
101}
102
103static int display_connector_probe(struct platform_device *pdev)
104{
105	struct display_connector *conn;
106	unsigned int type;
107	const char *label;
108	int ret;
109
110	conn = devm_kzalloc(&pdev->dev, sizeof(*conn), GFP_KERNEL);
111	if (!conn)
112		return -ENOMEM;
113
114	platform_set_drvdata(pdev, conn);
115
116	type = (uintptr_t)of_device_get_match_data(&pdev->dev);
117
118	/* Get the exact connector type. */
119	switch (type) {
120	case DRM_MODE_CONNECTOR_DVII: {
121		bool analog, digital;
122
123		analog = of_property_read_bool(pdev->dev.of_node, "analog");
124		digital = of_property_read_bool(pdev->dev.of_node, "digital");
125		if (analog && !digital) {
126			conn->bridge.type = DRM_MODE_CONNECTOR_DVIA;
127		} else if (!analog && digital) {
128			conn->bridge.type = DRM_MODE_CONNECTOR_DVID;
129		} else if (analog && digital) {
130			conn->bridge.type = DRM_MODE_CONNECTOR_DVII;
131		} else {
132			dev_err(&pdev->dev, "DVI connector with no type\n");
133			return -EINVAL;
134		}
135		break;
136	}
137
138	case DRM_MODE_CONNECTOR_HDMIA: {
139		const char *hdmi_type;
140
141		ret = of_property_read_string(pdev->dev.of_node, "type",
142					      &hdmi_type);
143		if (ret < 0) {
144			dev_err(&pdev->dev, "HDMI connector with no type\n");
145			return -EINVAL;
146		}
147
148		if (!strcmp(hdmi_type, "a") || !strcmp(hdmi_type, "c") ||
149		    !strcmp(hdmi_type, "d") || !strcmp(hdmi_type, "e")) {
150			conn->bridge.type = DRM_MODE_CONNECTOR_HDMIA;
151		} else if (!strcmp(hdmi_type, "b")) {
152			conn->bridge.type = DRM_MODE_CONNECTOR_HDMIB;
153		} else {
154			dev_err(&pdev->dev,
155				"Unsupported HDMI connector type '%s'\n",
156				hdmi_type);
157			return -EINVAL;
158		}
159
160		break;
161	}
162
163	default:
164		conn->bridge.type = type;
165		break;
166	}
167
168	/* All the supported connector types support interlaced modes. */
169	conn->bridge.interlace_allowed = true;
170
171	/* Get the optional connector label. */
172	of_property_read_string(pdev->dev.of_node, "label", &label);
173
174	/*
175	 * Get the HPD GPIO for DVI and HDMI connectors. If the GPIO can provide
176	 * edge interrupts, register an interrupt handler.
177	 */
178	if (type == DRM_MODE_CONNECTOR_DVII ||
179	    type == DRM_MODE_CONNECTOR_HDMIA) {
 
180		conn->hpd_gpio = devm_gpiod_get_optional(&pdev->dev, "hpd",
181							 GPIOD_IN);
182		if (IS_ERR(conn->hpd_gpio)) {
183			if (PTR_ERR(conn->hpd_gpio) != -EPROBE_DEFER)
184				dev_err(&pdev->dev,
185					"Unable to retrieve HPD GPIO\n");
186			return PTR_ERR(conn->hpd_gpio);
187		}
188
189		conn->hpd_irq = gpiod_to_irq(conn->hpd_gpio);
190	} else {
191		conn->hpd_irq = -EINVAL;
192	}
193
194	if (conn->hpd_irq >= 0) {
195		ret = devm_request_threaded_irq(&pdev->dev, conn->hpd_irq,
196						NULL, display_connector_hpd_irq,
197						IRQF_TRIGGER_RISING |
198						IRQF_TRIGGER_FALLING |
199						IRQF_ONESHOT,
200						"HPD", conn);
201		if (ret) {
202			dev_info(&pdev->dev,
203				 "Failed to request HPD edge interrupt, falling back to polling\n");
204			conn->hpd_irq = -EINVAL;
205		}
206	}
207
208	/* Retrieve the DDC I2C adapter for DVI, HDMI and VGA connectors. */
209	if (type == DRM_MODE_CONNECTOR_DVII ||
210	    type == DRM_MODE_CONNECTOR_HDMIA ||
211	    type == DRM_MODE_CONNECTOR_VGA) {
212		struct device_node *phandle;
213
214		phandle = of_parse_phandle(pdev->dev.of_node, "ddc-i2c-bus", 0);
215		if (phandle) {
216			conn->bridge.ddc = of_get_i2c_adapter_by_node(phandle);
217			of_node_put(phandle);
218			if (!conn->bridge.ddc)
219				return -EPROBE_DEFER;
220		} else {
221			dev_dbg(&pdev->dev,
222				"No I2C bus specified, disabling EDID readout\n");
223		}
224	}
225
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
226	conn->bridge.funcs = &display_connector_bridge_funcs;
227	conn->bridge.of_node = pdev->dev.of_node;
228
229	if (conn->bridge.ddc)
230		conn->bridge.ops |= DRM_BRIDGE_OP_EDID
231				 |  DRM_BRIDGE_OP_DETECT;
232	if (conn->hpd_gpio)
233		conn->bridge.ops |= DRM_BRIDGE_OP_DETECT;
234	if (conn->hpd_irq >= 0)
235		conn->bridge.ops |= DRM_BRIDGE_OP_HPD;
236
237	dev_dbg(&pdev->dev,
238		"Found %s display connector '%s' %s DDC bus and %s HPD GPIO (ops 0x%x)\n",
239		drm_get_connector_type_name(conn->bridge.type),
240		label ? label : "<unlabelled>",
241		conn->bridge.ddc ? "with" : "without",
242		conn->hpd_gpio ? "with" : "without",
243		conn->bridge.ops);
244
245	drm_bridge_add(&conn->bridge);
246
247	return 0;
248}
249
250static int display_connector_remove(struct platform_device *pdev)
251{
252	struct display_connector *conn = platform_get_drvdata(pdev);
253
 
 
 
 
 
 
254	drm_bridge_remove(&conn->bridge);
255
256	if (!IS_ERR(conn->bridge.ddc))
257		i2c_put_adapter(conn->bridge.ddc);
258
259	return 0;
260}
261
262static const struct of_device_id display_connector_match[] = {
263	{
264		.compatible = "composite-video-connector",
265		.data = (void *)DRM_MODE_CONNECTOR_Composite,
266	}, {
267		.compatible = "dvi-connector",
268		.data = (void *)DRM_MODE_CONNECTOR_DVII,
269	}, {
270		.compatible = "hdmi-connector",
271		.data = (void *)DRM_MODE_CONNECTOR_HDMIA,
272	}, {
273		.compatible = "svideo-connector",
274		.data = (void *)DRM_MODE_CONNECTOR_SVIDEO,
275	}, {
276		.compatible = "vga-connector",
277		.data = (void *)DRM_MODE_CONNECTOR_VGA,
 
 
 
278	},
279	{},
280};
281MODULE_DEVICE_TABLE(of, display_connector_match);
282
283static struct platform_driver display_connector_driver = {
284	.probe	= display_connector_probe,
285	.remove	= display_connector_remove,
286	.driver		= {
287		.name		= "display-connector",
288		.of_match_table	= display_connector_match,
289	},
290};
291module_platform_driver(display_connector_driver);
292
293MODULE_AUTHOR("Laurent Pinchart <laurent.pinchart@ideasonboard.com>");
294MODULE_DESCRIPTION("Display connector driver");
295MODULE_LICENSE("GPL");
v6.2
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  3 * Copyright (C) 2019 Laurent Pinchart <laurent.pinchart@ideasonboard.com>
  4 */
  5
  6#include <linux/gpio/consumer.h>
  7#include <linux/i2c.h>
  8#include <linux/interrupt.h>
  9#include <linux/media-bus-format.h>
 10#include <linux/module.h>
 11#include <linux/mutex.h>
 12#include <linux/of.h>
 13#include <linux/of_device.h>
 14#include <linux/platform_device.h>
 15#include <linux/regulator/consumer.h>
 16
 17#include <drm/drm_atomic_helper.h>
 18#include <drm/drm_bridge.h>
 19#include <drm/drm_edid.h>
 20
 21struct display_connector {
 22	struct drm_bridge	bridge;
 23
 24	struct gpio_desc	*hpd_gpio;
 25	int			hpd_irq;
 26
 27	struct regulator	*dp_pwr;
 28	struct gpio_desc	*ddc_en;
 29};
 30
 31static inline struct display_connector *
 32to_display_connector(struct drm_bridge *bridge)
 33{
 34	return container_of(bridge, struct display_connector, bridge);
 35}
 36
 37static int display_connector_attach(struct drm_bridge *bridge,
 38				    enum drm_bridge_attach_flags flags)
 39{
 40	return flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR ? 0 : -EINVAL;
 41}
 42
 43static enum drm_connector_status
 44display_connector_detect(struct drm_bridge *bridge)
 45{
 46	struct display_connector *conn = to_display_connector(bridge);
 47
 48	if (conn->hpd_gpio) {
 49		if (gpiod_get_value_cansleep(conn->hpd_gpio))
 50			return connector_status_connected;
 51		else
 52			return connector_status_disconnected;
 53	}
 54
 55	if (conn->bridge.ddc && drm_probe_ddc(conn->bridge.ddc))
 56		return connector_status_connected;
 57
 58	switch (conn->bridge.type) {
 59	case DRM_MODE_CONNECTOR_DVIA:
 60	case DRM_MODE_CONNECTOR_DVID:
 61	case DRM_MODE_CONNECTOR_DVII:
 62	case DRM_MODE_CONNECTOR_HDMIA:
 63	case DRM_MODE_CONNECTOR_HDMIB:
 64		/*
 65		 * For DVI and HDMI connectors a DDC probe failure indicates
 66		 * that no cable is connected.
 67		 */
 68		return connector_status_disconnected;
 69
 70	case DRM_MODE_CONNECTOR_Composite:
 71	case DRM_MODE_CONNECTOR_SVIDEO:
 72	case DRM_MODE_CONNECTOR_VGA:
 73	default:
 74		/*
 75		 * Composite and S-Video connectors have no other detection
 76		 * mean than the HPD GPIO. For VGA connectors, even if we have
 77		 * an I2C bus, we can't assume that the cable is disconnected
 78		 * if drm_probe_ddc fails, as some cables don't wire the DDC
 79		 * pins.
 80		 */
 81		return connector_status_unknown;
 82	}
 83}
 84
 85static struct edid *display_connector_get_edid(struct drm_bridge *bridge,
 86					       struct drm_connector *connector)
 87{
 88	struct display_connector *conn = to_display_connector(bridge);
 89
 90	return drm_get_edid(connector, conn->bridge.ddc);
 91}
 92
 93/*
 94 * Since this bridge is tied to the connector, it acts like a passthrough,
 95 * so concerning the output bus formats, either pass the bus formats from the
 96 * previous bridge or return fallback data like done in the bridge function:
 97 * drm_atomic_bridge_chain_select_bus_fmts().
 98 * This supports negotiation if the bridge chain has all bits in place.
 99 */
100static u32 *display_connector_get_output_bus_fmts(struct drm_bridge *bridge,
101					struct drm_bridge_state *bridge_state,
102					struct drm_crtc_state *crtc_state,
103					struct drm_connector_state *conn_state,
104					unsigned int *num_output_fmts)
105{
106	struct drm_bridge *prev_bridge = drm_bridge_get_prev_bridge(bridge);
107	struct drm_bridge_state *prev_bridge_state;
108
109	if (!prev_bridge || !prev_bridge->funcs->atomic_get_output_bus_fmts) {
110		struct drm_connector *conn = conn_state->connector;
111		u32 *out_bus_fmts;
112
113		*num_output_fmts = 1;
114		out_bus_fmts = kmalloc(sizeof(*out_bus_fmts), GFP_KERNEL);
115		if (!out_bus_fmts)
116			return NULL;
117
118		if (conn->display_info.num_bus_formats &&
119		    conn->display_info.bus_formats)
120			out_bus_fmts[0] = conn->display_info.bus_formats[0];
121		else
122			out_bus_fmts[0] = MEDIA_BUS_FMT_FIXED;
123
124		return out_bus_fmts;
125	}
126
127	prev_bridge_state = drm_atomic_get_new_bridge_state(crtc_state->state,
128							    prev_bridge);
129
130	return prev_bridge->funcs->atomic_get_output_bus_fmts(prev_bridge, prev_bridge_state,
131							      crtc_state, conn_state,
132							      num_output_fmts);
133}
134
135/*
136 * Since this bridge is tied to the connector, it acts like a passthrough,
137 * so concerning the input bus formats, either pass the bus formats from the
138 * previous bridge or MEDIA_BUS_FMT_FIXED (like select_bus_fmt_recursive())
139 * when atomic_get_input_bus_fmts is not supported.
140 * This supports negotiation if the bridge chain has all bits in place.
141 */
142static u32 *display_connector_get_input_bus_fmts(struct drm_bridge *bridge,
143					struct drm_bridge_state *bridge_state,
144					struct drm_crtc_state *crtc_state,
145					struct drm_connector_state *conn_state,
146					u32 output_fmt,
147					unsigned int *num_input_fmts)
148{
149	struct drm_bridge *prev_bridge = drm_bridge_get_prev_bridge(bridge);
150	struct drm_bridge_state *prev_bridge_state;
151
152	if (!prev_bridge || !prev_bridge->funcs->atomic_get_input_bus_fmts) {
153		u32 *in_bus_fmts;
154
155		*num_input_fmts = 1;
156		in_bus_fmts = kmalloc(sizeof(*in_bus_fmts), GFP_KERNEL);
157		if (!in_bus_fmts)
158			return NULL;
159
160		in_bus_fmts[0] = MEDIA_BUS_FMT_FIXED;
161
162		return in_bus_fmts;
163	}
164
165	prev_bridge_state = drm_atomic_get_new_bridge_state(crtc_state->state,
166							    prev_bridge);
167
168	return prev_bridge->funcs->atomic_get_input_bus_fmts(prev_bridge, prev_bridge_state,
169							     crtc_state, conn_state, output_fmt,
170							     num_input_fmts);
171}
172
173static const struct drm_bridge_funcs display_connector_bridge_funcs = {
174	.attach = display_connector_attach,
175	.detect = display_connector_detect,
176	.get_edid = display_connector_get_edid,
177	.atomic_get_output_bus_fmts = display_connector_get_output_bus_fmts,
178	.atomic_get_input_bus_fmts = display_connector_get_input_bus_fmts,
179	.atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state,
180	.atomic_destroy_state = drm_atomic_helper_bridge_destroy_state,
181	.atomic_reset = drm_atomic_helper_bridge_reset,
182};
183
184static irqreturn_t display_connector_hpd_irq(int irq, void *arg)
185{
186	struct display_connector *conn = arg;
187	struct drm_bridge *bridge = &conn->bridge;
188
189	drm_bridge_hpd_notify(bridge, display_connector_detect(bridge));
190
191	return IRQ_HANDLED;
192}
193
194static int display_connector_probe(struct platform_device *pdev)
195{
196	struct display_connector *conn;
197	unsigned int type;
198	const char *label = NULL;
199	int ret;
200
201	conn = devm_kzalloc(&pdev->dev, sizeof(*conn), GFP_KERNEL);
202	if (!conn)
203		return -ENOMEM;
204
205	platform_set_drvdata(pdev, conn);
206
207	type = (uintptr_t)of_device_get_match_data(&pdev->dev);
208
209	/* Get the exact connector type. */
210	switch (type) {
211	case DRM_MODE_CONNECTOR_DVII: {
212		bool analog, digital;
213
214		analog = of_property_read_bool(pdev->dev.of_node, "analog");
215		digital = of_property_read_bool(pdev->dev.of_node, "digital");
216		if (analog && !digital) {
217			conn->bridge.type = DRM_MODE_CONNECTOR_DVIA;
218		} else if (!analog && digital) {
219			conn->bridge.type = DRM_MODE_CONNECTOR_DVID;
220		} else if (analog && digital) {
221			conn->bridge.type = DRM_MODE_CONNECTOR_DVII;
222		} else {
223			dev_err(&pdev->dev, "DVI connector with no type\n");
224			return -EINVAL;
225		}
226		break;
227	}
228
229	case DRM_MODE_CONNECTOR_HDMIA: {
230		const char *hdmi_type;
231
232		ret = of_property_read_string(pdev->dev.of_node, "type",
233					      &hdmi_type);
234		if (ret < 0) {
235			dev_err(&pdev->dev, "HDMI connector with no type\n");
236			return -EINVAL;
237		}
238
239		if (!strcmp(hdmi_type, "a") || !strcmp(hdmi_type, "c") ||
240		    !strcmp(hdmi_type, "d") || !strcmp(hdmi_type, "e")) {
241			conn->bridge.type = DRM_MODE_CONNECTOR_HDMIA;
242		} else if (!strcmp(hdmi_type, "b")) {
243			conn->bridge.type = DRM_MODE_CONNECTOR_HDMIB;
244		} else {
245			dev_err(&pdev->dev,
246				"Unsupported HDMI connector type '%s'\n",
247				hdmi_type);
248			return -EINVAL;
249		}
250
251		break;
252	}
253
254	default:
255		conn->bridge.type = type;
256		break;
257	}
258
259	/* All the supported connector types support interlaced modes. */
260	conn->bridge.interlace_allowed = true;
261
262	/* Get the optional connector label. */
263	of_property_read_string(pdev->dev.of_node, "label", &label);
264
265	/*
266	 * Get the HPD GPIO for DVI, HDMI and DP connectors. If the GPIO can provide
267	 * edge interrupts, register an interrupt handler.
268	 */
269	if (type == DRM_MODE_CONNECTOR_DVII ||
270	    type == DRM_MODE_CONNECTOR_HDMIA ||
271	    type == DRM_MODE_CONNECTOR_DisplayPort) {
272		conn->hpd_gpio = devm_gpiod_get_optional(&pdev->dev, "hpd",
273							 GPIOD_IN);
274		if (IS_ERR(conn->hpd_gpio)) {
275			if (PTR_ERR(conn->hpd_gpio) != -EPROBE_DEFER)
276				dev_err(&pdev->dev,
277					"Unable to retrieve HPD GPIO\n");
278			return PTR_ERR(conn->hpd_gpio);
279		}
280
281		conn->hpd_irq = gpiod_to_irq(conn->hpd_gpio);
282	} else {
283		conn->hpd_irq = -EINVAL;
284	}
285
286	if (conn->hpd_irq >= 0) {
287		ret = devm_request_threaded_irq(&pdev->dev, conn->hpd_irq,
288						NULL, display_connector_hpd_irq,
289						IRQF_TRIGGER_RISING |
290						IRQF_TRIGGER_FALLING |
291						IRQF_ONESHOT,
292						"HPD", conn);
293		if (ret) {
294			dev_info(&pdev->dev,
295				 "Failed to request HPD edge interrupt, falling back to polling\n");
296			conn->hpd_irq = -EINVAL;
297		}
298	}
299
300	/* Retrieve the DDC I2C adapter for DVI, HDMI and VGA connectors. */
301	if (type == DRM_MODE_CONNECTOR_DVII ||
302	    type == DRM_MODE_CONNECTOR_HDMIA ||
303	    type == DRM_MODE_CONNECTOR_VGA) {
304		struct device_node *phandle;
305
306		phandle = of_parse_phandle(pdev->dev.of_node, "ddc-i2c-bus", 0);
307		if (phandle) {
308			conn->bridge.ddc = of_get_i2c_adapter_by_node(phandle);
309			of_node_put(phandle);
310			if (!conn->bridge.ddc)
311				return -EPROBE_DEFER;
312		} else {
313			dev_dbg(&pdev->dev,
314				"No I2C bus specified, disabling EDID readout\n");
315		}
316	}
317
318	/* Get the DP PWR for DP connector. */
319	if (type == DRM_MODE_CONNECTOR_DisplayPort) {
320		int ret;
321
322		conn->dp_pwr = devm_regulator_get_optional(&pdev->dev, "dp-pwr");
323
324		if (IS_ERR(conn->dp_pwr)) {
325			ret = PTR_ERR(conn->dp_pwr);
326
327			switch (ret) {
328			case -ENODEV:
329				conn->dp_pwr = NULL;
330				break;
331
332			case -EPROBE_DEFER:
333				return -EPROBE_DEFER;
334
335			default:
336				dev_err(&pdev->dev, "failed to get DP PWR regulator: %d\n", ret);
337				return ret;
338			}
339		}
340
341		if (conn->dp_pwr) {
342			ret = regulator_enable(conn->dp_pwr);
343			if (ret) {
344				dev_err(&pdev->dev, "failed to enable DP PWR regulator: %d\n", ret);
345				return ret;
346			}
347		}
348	}
349
350	/* enable DDC */
351	if (type == DRM_MODE_CONNECTOR_HDMIA) {
352		conn->ddc_en = devm_gpiod_get_optional(&pdev->dev, "ddc-en",
353						       GPIOD_OUT_HIGH);
354
355		if (IS_ERR(conn->ddc_en)) {
356			dev_err(&pdev->dev, "Couldn't get ddc-en gpio\n");
357			return PTR_ERR(conn->ddc_en);
358		}
359	}
360
361	conn->bridge.funcs = &display_connector_bridge_funcs;
362	conn->bridge.of_node = pdev->dev.of_node;
363
364	if (conn->bridge.ddc)
365		conn->bridge.ops |= DRM_BRIDGE_OP_EDID
366				 |  DRM_BRIDGE_OP_DETECT;
367	if (conn->hpd_gpio)
368		conn->bridge.ops |= DRM_BRIDGE_OP_DETECT;
369	if (conn->hpd_irq >= 0)
370		conn->bridge.ops |= DRM_BRIDGE_OP_HPD;
371
372	dev_dbg(&pdev->dev,
373		"Found %s display connector '%s' %s DDC bus and %s HPD GPIO (ops 0x%x)\n",
374		drm_get_connector_type_name(conn->bridge.type),
375		label ? label : "<unlabelled>",
376		conn->bridge.ddc ? "with" : "without",
377		conn->hpd_gpio ? "with" : "without",
378		conn->bridge.ops);
379
380	drm_bridge_add(&conn->bridge);
381
382	return 0;
383}
384
385static int display_connector_remove(struct platform_device *pdev)
386{
387	struct display_connector *conn = platform_get_drvdata(pdev);
388
389	if (conn->ddc_en)
390		gpiod_set_value(conn->ddc_en, 0);
391
392	if (conn->dp_pwr)
393		regulator_disable(conn->dp_pwr);
394
395	drm_bridge_remove(&conn->bridge);
396
397	if (!IS_ERR(conn->bridge.ddc))
398		i2c_put_adapter(conn->bridge.ddc);
399
400	return 0;
401}
402
403static const struct of_device_id display_connector_match[] = {
404	{
405		.compatible = "composite-video-connector",
406		.data = (void *)DRM_MODE_CONNECTOR_Composite,
407	}, {
408		.compatible = "dvi-connector",
409		.data = (void *)DRM_MODE_CONNECTOR_DVII,
410	}, {
411		.compatible = "hdmi-connector",
412		.data = (void *)DRM_MODE_CONNECTOR_HDMIA,
413	}, {
414		.compatible = "svideo-connector",
415		.data = (void *)DRM_MODE_CONNECTOR_SVIDEO,
416	}, {
417		.compatible = "vga-connector",
418		.data = (void *)DRM_MODE_CONNECTOR_VGA,
419	}, {
420		.compatible = "dp-connector",
421		.data = (void *)DRM_MODE_CONNECTOR_DisplayPort,
422	},
423	{},
424};
425MODULE_DEVICE_TABLE(of, display_connector_match);
426
427static struct platform_driver display_connector_driver = {
428	.probe	= display_connector_probe,
429	.remove	= display_connector_remove,
430	.driver		= {
431		.name		= "display-connector",
432		.of_match_table	= display_connector_match,
433	},
434};
435module_platform_driver(display_connector_driver);
436
437MODULE_AUTHOR("Laurent Pinchart <laurent.pinchart@ideasonboard.com>");
438MODULE_DESCRIPTION("Display connector driver");
439MODULE_LICENSE("GPL");