10c275c30SLaurent Pinchart // SPDX-License-Identifier: GPL-2.0
20c275c30SLaurent Pinchart /*
30c275c30SLaurent Pinchart * Copyright (C) 2019 Laurent Pinchart <laurent.pinchart@ideasonboard.com>
40c275c30SLaurent Pinchart */
50c275c30SLaurent Pinchart
60c275c30SLaurent Pinchart #include <linux/gpio/consumer.h>
70c275c30SLaurent Pinchart #include <linux/i2c.h>
80c275c30SLaurent Pinchart #include <linux/interrupt.h>
972bd9ea3SVille Syrjälä #include <linux/media-bus-format.h>
100c275c30SLaurent Pinchart #include <linux/module.h>
110c275c30SLaurent Pinchart #include <linux/mutex.h>
120c275c30SLaurent Pinchart #include <linux/of.h>
130c275c30SLaurent Pinchart #include <linux/platform_device.h>
142e2bf3a5STomi Valkeinen #include <linux/regulator/consumer.h>
150c275c30SLaurent Pinchart
167cd70656SNeil Armstrong #include <drm/drm_atomic_helper.h>
170c275c30SLaurent Pinchart #include <drm/drm_bridge.h>
180c275c30SLaurent Pinchart #include <drm/drm_edid.h>
190c275c30SLaurent Pinchart
200c275c30SLaurent Pinchart struct display_connector {
210c275c30SLaurent Pinchart struct drm_bridge bridge;
220c275c30SLaurent Pinchart
230c275c30SLaurent Pinchart struct gpio_desc *hpd_gpio;
240c275c30SLaurent Pinchart int hpd_irq;
252e2bf3a5STomi Valkeinen
2699304fd0SDmitry Baryshkov struct regulator *supply;
276de79dd3SH. Nikolaus Schaller struct gpio_desc *ddc_en;
280c275c30SLaurent Pinchart };
290c275c30SLaurent Pinchart
300c275c30SLaurent Pinchart static inline struct display_connector *
to_display_connector(struct drm_bridge * bridge)310c275c30SLaurent Pinchart to_display_connector(struct drm_bridge *bridge)
320c275c30SLaurent Pinchart {
330c275c30SLaurent Pinchart return container_of(bridge, struct display_connector, bridge);
340c275c30SLaurent Pinchart }
350c275c30SLaurent Pinchart
display_connector_attach(struct drm_bridge * bridge,enum drm_bridge_attach_flags flags)360c275c30SLaurent Pinchart static int display_connector_attach(struct drm_bridge *bridge,
370c275c30SLaurent Pinchart enum drm_bridge_attach_flags flags)
380c275c30SLaurent Pinchart {
390c275c30SLaurent Pinchart return flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR ? 0 : -EINVAL;
400c275c30SLaurent Pinchart }
410c275c30SLaurent Pinchart
420c275c30SLaurent Pinchart static enum drm_connector_status
display_connector_detect(struct drm_bridge * bridge)430c275c30SLaurent Pinchart display_connector_detect(struct drm_bridge *bridge)
440c275c30SLaurent Pinchart {
450c275c30SLaurent Pinchart struct display_connector *conn = to_display_connector(bridge);
460c275c30SLaurent Pinchart
470c275c30SLaurent Pinchart if (conn->hpd_gpio) {
480c275c30SLaurent Pinchart if (gpiod_get_value_cansleep(conn->hpd_gpio))
490c275c30SLaurent Pinchart return connector_status_connected;
500c275c30SLaurent Pinchart else
510c275c30SLaurent Pinchart return connector_status_disconnected;
520c275c30SLaurent Pinchart }
530c275c30SLaurent Pinchart
540c275c30SLaurent Pinchart if (conn->bridge.ddc && drm_probe_ddc(conn->bridge.ddc))
550c275c30SLaurent Pinchart return connector_status_connected;
560c275c30SLaurent Pinchart
570c275c30SLaurent Pinchart switch (conn->bridge.type) {
580c275c30SLaurent Pinchart case DRM_MODE_CONNECTOR_DVIA:
590c275c30SLaurent Pinchart case DRM_MODE_CONNECTOR_DVID:
600c275c30SLaurent Pinchart case DRM_MODE_CONNECTOR_DVII:
610c275c30SLaurent Pinchart case DRM_MODE_CONNECTOR_HDMIA:
620c275c30SLaurent Pinchart case DRM_MODE_CONNECTOR_HDMIB:
630c275c30SLaurent Pinchart /*
640c275c30SLaurent Pinchart * For DVI and HDMI connectors a DDC probe failure indicates
650c275c30SLaurent Pinchart * that no cable is connected.
660c275c30SLaurent Pinchart */
670c275c30SLaurent Pinchart return connector_status_disconnected;
680c275c30SLaurent Pinchart
690c275c30SLaurent Pinchart case DRM_MODE_CONNECTOR_Composite:
700c275c30SLaurent Pinchart case DRM_MODE_CONNECTOR_SVIDEO:
710c275c30SLaurent Pinchart case DRM_MODE_CONNECTOR_VGA:
720c275c30SLaurent Pinchart default:
730c275c30SLaurent Pinchart /*
740c275c30SLaurent Pinchart * Composite and S-Video connectors have no other detection
750c275c30SLaurent Pinchart * mean than the HPD GPIO. For VGA connectors, even if we have
760c275c30SLaurent Pinchart * an I2C bus, we can't assume that the cable is disconnected
770c275c30SLaurent Pinchart * if drm_probe_ddc fails, as some cables don't wire the DDC
780c275c30SLaurent Pinchart * pins.
790c275c30SLaurent Pinchart */
800c275c30SLaurent Pinchart return connector_status_unknown;
810c275c30SLaurent Pinchart }
820c275c30SLaurent Pinchart }
830c275c30SLaurent Pinchart
display_connector_get_edid(struct drm_bridge * bridge,struct drm_connector * connector)840c275c30SLaurent Pinchart static struct edid *display_connector_get_edid(struct drm_bridge *bridge,
850c275c30SLaurent Pinchart struct drm_connector *connector)
860c275c30SLaurent Pinchart {
870c275c30SLaurent Pinchart struct display_connector *conn = to_display_connector(bridge);
880c275c30SLaurent Pinchart
890c275c30SLaurent Pinchart return drm_get_edid(connector, conn->bridge.ddc);
900c275c30SLaurent Pinchart }
910c275c30SLaurent Pinchart
927cd70656SNeil Armstrong /*
937cd70656SNeil Armstrong * Since this bridge is tied to the connector, it acts like a passthrough,
947cd70656SNeil Armstrong * so concerning the output bus formats, either pass the bus formats from the
957cd70656SNeil Armstrong * previous bridge or return fallback data like done in the bridge function:
967cd70656SNeil Armstrong * drm_atomic_bridge_chain_select_bus_fmts().
977cd70656SNeil Armstrong * This supports negotiation if the bridge chain has all bits in place.
987cd70656SNeil Armstrong */
display_connector_get_output_bus_fmts(struct drm_bridge * bridge,struct drm_bridge_state * bridge_state,struct drm_crtc_state * crtc_state,struct drm_connector_state * conn_state,unsigned int * num_output_fmts)997cd70656SNeil Armstrong static u32 *display_connector_get_output_bus_fmts(struct drm_bridge *bridge,
1007cd70656SNeil Armstrong struct drm_bridge_state *bridge_state,
1017cd70656SNeil Armstrong struct drm_crtc_state *crtc_state,
1027cd70656SNeil Armstrong struct drm_connector_state *conn_state,
1037cd70656SNeil Armstrong unsigned int *num_output_fmts)
1047cd70656SNeil Armstrong {
1057cd70656SNeil Armstrong struct drm_bridge *prev_bridge = drm_bridge_get_prev_bridge(bridge);
1067cd70656SNeil Armstrong struct drm_bridge_state *prev_bridge_state;
1077cd70656SNeil Armstrong
1087cd70656SNeil Armstrong if (!prev_bridge || !prev_bridge->funcs->atomic_get_output_bus_fmts) {
1097cd70656SNeil Armstrong struct drm_connector *conn = conn_state->connector;
1107cd70656SNeil Armstrong u32 *out_bus_fmts;
1117cd70656SNeil Armstrong
1127cd70656SNeil Armstrong *num_output_fmts = 1;
1137cd70656SNeil Armstrong out_bus_fmts = kmalloc(sizeof(*out_bus_fmts), GFP_KERNEL);
1147cd70656SNeil Armstrong if (!out_bus_fmts)
1157cd70656SNeil Armstrong return NULL;
1167cd70656SNeil Armstrong
1177cd70656SNeil Armstrong if (conn->display_info.num_bus_formats &&
1187cd70656SNeil Armstrong conn->display_info.bus_formats)
1197cd70656SNeil Armstrong out_bus_fmts[0] = conn->display_info.bus_formats[0];
1207cd70656SNeil Armstrong else
1217cd70656SNeil Armstrong out_bus_fmts[0] = MEDIA_BUS_FMT_FIXED;
1227cd70656SNeil Armstrong
1237cd70656SNeil Armstrong return out_bus_fmts;
1247cd70656SNeil Armstrong }
1257cd70656SNeil Armstrong
1267cd70656SNeil Armstrong prev_bridge_state = drm_atomic_get_new_bridge_state(crtc_state->state,
1277cd70656SNeil Armstrong prev_bridge);
1287cd70656SNeil Armstrong
1297cd70656SNeil Armstrong return prev_bridge->funcs->atomic_get_output_bus_fmts(prev_bridge, prev_bridge_state,
1307cd70656SNeil Armstrong crtc_state, conn_state,
1317cd70656SNeil Armstrong num_output_fmts);
1327cd70656SNeil Armstrong }
1337cd70656SNeil Armstrong
1347cd70656SNeil Armstrong /*
1357cd70656SNeil Armstrong * Since this bridge is tied to the connector, it acts like a passthrough,
1367cd70656SNeil Armstrong * so concerning the input bus formats, either pass the bus formats from the
1377cd70656SNeil Armstrong * previous bridge or MEDIA_BUS_FMT_FIXED (like select_bus_fmt_recursive())
1387cd70656SNeil Armstrong * when atomic_get_input_bus_fmts is not supported.
1397cd70656SNeil Armstrong * This supports negotiation if the bridge chain has all bits in place.
1407cd70656SNeil Armstrong */
display_connector_get_input_bus_fmts(struct drm_bridge * bridge,struct drm_bridge_state * bridge_state,struct drm_crtc_state * crtc_state,struct drm_connector_state * conn_state,u32 output_fmt,unsigned int * num_input_fmts)1417cd70656SNeil Armstrong static u32 *display_connector_get_input_bus_fmts(struct drm_bridge *bridge,
1427cd70656SNeil Armstrong struct drm_bridge_state *bridge_state,
1437cd70656SNeil Armstrong struct drm_crtc_state *crtc_state,
1447cd70656SNeil Armstrong struct drm_connector_state *conn_state,
1457cd70656SNeil Armstrong u32 output_fmt,
1467cd70656SNeil Armstrong unsigned int *num_input_fmts)
1477cd70656SNeil Armstrong {
1487cd70656SNeil Armstrong struct drm_bridge *prev_bridge = drm_bridge_get_prev_bridge(bridge);
1497cd70656SNeil Armstrong struct drm_bridge_state *prev_bridge_state;
1507cd70656SNeil Armstrong
1517cd70656SNeil Armstrong if (!prev_bridge || !prev_bridge->funcs->atomic_get_input_bus_fmts) {
1527cd70656SNeil Armstrong u32 *in_bus_fmts;
1537cd70656SNeil Armstrong
1547cd70656SNeil Armstrong *num_input_fmts = 1;
1557cd70656SNeil Armstrong in_bus_fmts = kmalloc(sizeof(*in_bus_fmts), GFP_KERNEL);
1567cd70656SNeil Armstrong if (!in_bus_fmts)
1577cd70656SNeil Armstrong return NULL;
1587cd70656SNeil Armstrong
1597cd70656SNeil Armstrong in_bus_fmts[0] = MEDIA_BUS_FMT_FIXED;
1607cd70656SNeil Armstrong
1617cd70656SNeil Armstrong return in_bus_fmts;
1627cd70656SNeil Armstrong }
1637cd70656SNeil Armstrong
1647cd70656SNeil Armstrong prev_bridge_state = drm_atomic_get_new_bridge_state(crtc_state->state,
1657cd70656SNeil Armstrong prev_bridge);
1667cd70656SNeil Armstrong
1677cd70656SNeil Armstrong return prev_bridge->funcs->atomic_get_input_bus_fmts(prev_bridge, prev_bridge_state,
1687cd70656SNeil Armstrong crtc_state, conn_state, output_fmt,
1697cd70656SNeil Armstrong num_input_fmts);
1707cd70656SNeil Armstrong }
1717cd70656SNeil Armstrong
1720c275c30SLaurent Pinchart static const struct drm_bridge_funcs display_connector_bridge_funcs = {
1730c275c30SLaurent Pinchart .attach = display_connector_attach,
1740c275c30SLaurent Pinchart .detect = display_connector_detect,
1750c275c30SLaurent Pinchart .get_edid = display_connector_get_edid,
1767cd70656SNeil Armstrong .atomic_get_output_bus_fmts = display_connector_get_output_bus_fmts,
1777cd70656SNeil Armstrong .atomic_get_input_bus_fmts = display_connector_get_input_bus_fmts,
1787cd70656SNeil Armstrong .atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state,
1797cd70656SNeil Armstrong .atomic_destroy_state = drm_atomic_helper_bridge_destroy_state,
1807cd70656SNeil Armstrong .atomic_reset = drm_atomic_helper_bridge_reset,
1810c275c30SLaurent Pinchart };
1820c275c30SLaurent Pinchart
display_connector_hpd_irq(int irq,void * arg)1830c275c30SLaurent Pinchart static irqreturn_t display_connector_hpd_irq(int irq, void *arg)
1840c275c30SLaurent Pinchart {
1850c275c30SLaurent Pinchart struct display_connector *conn = arg;
1860c275c30SLaurent Pinchart struct drm_bridge *bridge = &conn->bridge;
1870c275c30SLaurent Pinchart
1880c275c30SLaurent Pinchart drm_bridge_hpd_notify(bridge, display_connector_detect(bridge));
1890c275c30SLaurent Pinchart
1900c275c30SLaurent Pinchart return IRQ_HANDLED;
1910c275c30SLaurent Pinchart }
1920c275c30SLaurent Pinchart
display_connector_get_supply(struct platform_device * pdev,struct display_connector * conn,const char * name)193*6eb6b6f0SDmitry Baryshkov static int display_connector_get_supply(struct platform_device *pdev,
194*6eb6b6f0SDmitry Baryshkov struct display_connector *conn,
195*6eb6b6f0SDmitry Baryshkov const char *name)
196*6eb6b6f0SDmitry Baryshkov {
197*6eb6b6f0SDmitry Baryshkov conn->supply = devm_regulator_get_optional(&pdev->dev, name);
198*6eb6b6f0SDmitry Baryshkov
199*6eb6b6f0SDmitry Baryshkov if (conn->supply == ERR_PTR(-ENODEV))
200*6eb6b6f0SDmitry Baryshkov conn->supply = NULL;
201*6eb6b6f0SDmitry Baryshkov
202*6eb6b6f0SDmitry Baryshkov return PTR_ERR_OR_ZERO(conn->supply);
203*6eb6b6f0SDmitry Baryshkov }
204*6eb6b6f0SDmitry Baryshkov
display_connector_probe(struct platform_device * pdev)2050c275c30SLaurent Pinchart static int display_connector_probe(struct platform_device *pdev)
2060c275c30SLaurent Pinchart {
2070c275c30SLaurent Pinchart struct display_connector *conn;
2080c275c30SLaurent Pinchart unsigned int type;
209189723fbSDan Carpenter const char *label = NULL;
2100c275c30SLaurent Pinchart int ret;
2110c275c30SLaurent Pinchart
2120c275c30SLaurent Pinchart conn = devm_kzalloc(&pdev->dev, sizeof(*conn), GFP_KERNEL);
2130c275c30SLaurent Pinchart if (!conn)
2140c275c30SLaurent Pinchart return -ENOMEM;
2150c275c30SLaurent Pinchart
2160c275c30SLaurent Pinchart platform_set_drvdata(pdev, conn);
2170c275c30SLaurent Pinchart
2180c275c30SLaurent Pinchart type = (uintptr_t)of_device_get_match_data(&pdev->dev);
2190c275c30SLaurent Pinchart
2200c275c30SLaurent Pinchart /* Get the exact connector type. */
2210c275c30SLaurent Pinchart switch (type) {
2220c275c30SLaurent Pinchart case DRM_MODE_CONNECTOR_DVII: {
2230c275c30SLaurent Pinchart bool analog, digital;
2240c275c30SLaurent Pinchart
2250c275c30SLaurent Pinchart analog = of_property_read_bool(pdev->dev.of_node, "analog");
2260c275c30SLaurent Pinchart digital = of_property_read_bool(pdev->dev.of_node, "digital");
2270c275c30SLaurent Pinchart if (analog && !digital) {
2280c275c30SLaurent Pinchart conn->bridge.type = DRM_MODE_CONNECTOR_DVIA;
2290c275c30SLaurent Pinchart } else if (!analog && digital) {
2300c275c30SLaurent Pinchart conn->bridge.type = DRM_MODE_CONNECTOR_DVID;
2310c275c30SLaurent Pinchart } else if (analog && digital) {
2320c275c30SLaurent Pinchart conn->bridge.type = DRM_MODE_CONNECTOR_DVII;
2330c275c30SLaurent Pinchart } else {
2340c275c30SLaurent Pinchart dev_err(&pdev->dev, "DVI connector with no type\n");
2350c275c30SLaurent Pinchart return -EINVAL;
2360c275c30SLaurent Pinchart }
2370c275c30SLaurent Pinchart break;
2380c275c30SLaurent Pinchart }
2390c275c30SLaurent Pinchart
2400c275c30SLaurent Pinchart case DRM_MODE_CONNECTOR_HDMIA: {
2410c275c30SLaurent Pinchart const char *hdmi_type;
2420c275c30SLaurent Pinchart
2430c275c30SLaurent Pinchart ret = of_property_read_string(pdev->dev.of_node, "type",
2440c275c30SLaurent Pinchart &hdmi_type);
2450c275c30SLaurent Pinchart if (ret < 0) {
2460c275c30SLaurent Pinchart dev_err(&pdev->dev, "HDMI connector with no type\n");
2470c275c30SLaurent Pinchart return -EINVAL;
2480c275c30SLaurent Pinchart }
2490c275c30SLaurent Pinchart
2500c275c30SLaurent Pinchart if (!strcmp(hdmi_type, "a") || !strcmp(hdmi_type, "c") ||
2510c275c30SLaurent Pinchart !strcmp(hdmi_type, "d") || !strcmp(hdmi_type, "e")) {
2520c275c30SLaurent Pinchart conn->bridge.type = DRM_MODE_CONNECTOR_HDMIA;
2530c275c30SLaurent Pinchart } else if (!strcmp(hdmi_type, "b")) {
2540c275c30SLaurent Pinchart conn->bridge.type = DRM_MODE_CONNECTOR_HDMIB;
2550c275c30SLaurent Pinchart } else {
2560c275c30SLaurent Pinchart dev_err(&pdev->dev,
2570c275c30SLaurent Pinchart "Unsupported HDMI connector type '%s'\n",
2580c275c30SLaurent Pinchart hdmi_type);
2590c275c30SLaurent Pinchart return -EINVAL;
2600c275c30SLaurent Pinchart }
2610c275c30SLaurent Pinchart
2620c275c30SLaurent Pinchart break;
2630c275c30SLaurent Pinchart }
2640c275c30SLaurent Pinchart
2650c275c30SLaurent Pinchart default:
2660c275c30SLaurent Pinchart conn->bridge.type = type;
2670c275c30SLaurent Pinchart break;
2680c275c30SLaurent Pinchart }
2690c275c30SLaurent Pinchart
2700c275c30SLaurent Pinchart /* All the supported connector types support interlaced modes. */
2710c275c30SLaurent Pinchart conn->bridge.interlace_allowed = true;
2720c275c30SLaurent Pinchart
2730c275c30SLaurent Pinchart /* Get the optional connector label. */
2740c275c30SLaurent Pinchart of_property_read_string(pdev->dev.of_node, "label", &label);
2750c275c30SLaurent Pinchart
2760c275c30SLaurent Pinchart /*
2772e2bf3a5STomi Valkeinen * Get the HPD GPIO for DVI, HDMI and DP connectors. If the GPIO can provide
2780c275c30SLaurent Pinchart * edge interrupts, register an interrupt handler.
2790c275c30SLaurent Pinchart */
2800c275c30SLaurent Pinchart if (type == DRM_MODE_CONNECTOR_DVII ||
2812e2bf3a5STomi Valkeinen type == DRM_MODE_CONNECTOR_HDMIA ||
2822e2bf3a5STomi Valkeinen type == DRM_MODE_CONNECTOR_DisplayPort) {
2830c275c30SLaurent Pinchart conn->hpd_gpio = devm_gpiod_get_optional(&pdev->dev, "hpd",
2840c275c30SLaurent Pinchart GPIOD_IN);
285ed8f4e10SYe Xingchen if (IS_ERR(conn->hpd_gpio))
286ed8f4e10SYe Xingchen return dev_err_probe(&pdev->dev, PTR_ERR(conn->hpd_gpio),
2870c275c30SLaurent Pinchart "Unable to retrieve HPD GPIO\n");
2880c275c30SLaurent Pinchart
2890c275c30SLaurent Pinchart conn->hpd_irq = gpiod_to_irq(conn->hpd_gpio);
2900c275c30SLaurent Pinchart } else {
2910c275c30SLaurent Pinchart conn->hpd_irq = -EINVAL;
2920c275c30SLaurent Pinchart }
2930c275c30SLaurent Pinchart
2940c275c30SLaurent Pinchart if (conn->hpd_irq >= 0) {
2950c275c30SLaurent Pinchart ret = devm_request_threaded_irq(&pdev->dev, conn->hpd_irq,
2960c275c30SLaurent Pinchart NULL, display_connector_hpd_irq,
2970c275c30SLaurent Pinchart IRQF_TRIGGER_RISING |
2980c275c30SLaurent Pinchart IRQF_TRIGGER_FALLING |
2990c275c30SLaurent Pinchart IRQF_ONESHOT,
3000c275c30SLaurent Pinchart "HPD", conn);
3010c275c30SLaurent Pinchart if (ret) {
3020c275c30SLaurent Pinchart dev_info(&pdev->dev,
3030c275c30SLaurent Pinchart "Failed to request HPD edge interrupt, falling back to polling\n");
3040c275c30SLaurent Pinchart conn->hpd_irq = -EINVAL;
3050c275c30SLaurent Pinchart }
3060c275c30SLaurent Pinchart }
3070c275c30SLaurent Pinchart
3080c275c30SLaurent Pinchart /* Retrieve the DDC I2C adapter for DVI, HDMI and VGA connectors. */
3090c275c30SLaurent Pinchart if (type == DRM_MODE_CONNECTOR_DVII ||
3100c275c30SLaurent Pinchart type == DRM_MODE_CONNECTOR_HDMIA ||
3110c275c30SLaurent Pinchart type == DRM_MODE_CONNECTOR_VGA) {
3120c275c30SLaurent Pinchart struct device_node *phandle;
3130c275c30SLaurent Pinchart
3140c275c30SLaurent Pinchart phandle = of_parse_phandle(pdev->dev.of_node, "ddc-i2c-bus", 0);
3150c275c30SLaurent Pinchart if (phandle) {
3160c275c30SLaurent Pinchart conn->bridge.ddc = of_get_i2c_adapter_by_node(phandle);
3170c275c30SLaurent Pinchart of_node_put(phandle);
3180c275c30SLaurent Pinchart if (!conn->bridge.ddc)
3190c275c30SLaurent Pinchart return -EPROBE_DEFER;
3200c275c30SLaurent Pinchart } else {
3210c275c30SLaurent Pinchart dev_dbg(&pdev->dev,
3220c275c30SLaurent Pinchart "No I2C bus specified, disabling EDID readout\n");
3230c275c30SLaurent Pinchart }
3240c275c30SLaurent Pinchart }
3250c275c30SLaurent Pinchart
3262e2bf3a5STomi Valkeinen /* Get the DP PWR for DP connector. */
3272e2bf3a5STomi Valkeinen if (type == DRM_MODE_CONNECTOR_DisplayPort) {
3282e2bf3a5STomi Valkeinen int ret;
3292e2bf3a5STomi Valkeinen
330*6eb6b6f0SDmitry Baryshkov ret = display_connector_get_supply(pdev, conn, "dp-pwr");
331*6eb6b6f0SDmitry Baryshkov if (ret < 0)
332*6eb6b6f0SDmitry Baryshkov return dev_err_probe(&pdev->dev, ret, "failed to get DP PWR regulator\n");
3332e2bf3a5STomi Valkeinen }
3342e2bf3a5STomi Valkeinen
3356de79dd3SH. Nikolaus Schaller /* enable DDC */
3366de79dd3SH. Nikolaus Schaller if (type == DRM_MODE_CONNECTOR_HDMIA) {
337*6eb6b6f0SDmitry Baryshkov int ret;
338*6eb6b6f0SDmitry Baryshkov
3396de79dd3SH. Nikolaus Schaller conn->ddc_en = devm_gpiod_get_optional(&pdev->dev, "ddc-en",
3406de79dd3SH. Nikolaus Schaller GPIOD_OUT_HIGH);
3416de79dd3SH. Nikolaus Schaller
3426de79dd3SH. Nikolaus Schaller if (IS_ERR(conn->ddc_en)) {
3436de79dd3SH. Nikolaus Schaller dev_err(&pdev->dev, "Couldn't get ddc-en gpio\n");
3446de79dd3SH. Nikolaus Schaller return PTR_ERR(conn->ddc_en);
3456de79dd3SH. Nikolaus Schaller }
346*6eb6b6f0SDmitry Baryshkov
347*6eb6b6f0SDmitry Baryshkov ret = display_connector_get_supply(pdev, conn, "hdmi-pwr");
348*6eb6b6f0SDmitry Baryshkov if (ret < 0)
349*6eb6b6f0SDmitry Baryshkov return dev_err_probe(&pdev->dev, ret, "failed to get HDMI +5V Power regulator\n");
350*6eb6b6f0SDmitry Baryshkov }
351*6eb6b6f0SDmitry Baryshkov
352*6eb6b6f0SDmitry Baryshkov if (conn->supply) {
353*6eb6b6f0SDmitry Baryshkov ret = regulator_enable(conn->supply);
354*6eb6b6f0SDmitry Baryshkov if (ret) {
355*6eb6b6f0SDmitry Baryshkov dev_err(&pdev->dev, "failed to enable PWR regulator: %d\n", ret);
356*6eb6b6f0SDmitry Baryshkov return ret;
357*6eb6b6f0SDmitry Baryshkov }
3586de79dd3SH. Nikolaus Schaller }
3596de79dd3SH. Nikolaus Schaller
3600c275c30SLaurent Pinchart conn->bridge.funcs = &display_connector_bridge_funcs;
3610c275c30SLaurent Pinchart conn->bridge.of_node = pdev->dev.of_node;
3620c275c30SLaurent Pinchart
3630c275c30SLaurent Pinchart if (conn->bridge.ddc)
3640c275c30SLaurent Pinchart conn->bridge.ops |= DRM_BRIDGE_OP_EDID
3650c275c30SLaurent Pinchart | DRM_BRIDGE_OP_DETECT;
3660c275c30SLaurent Pinchart if (conn->hpd_gpio)
3670c275c30SLaurent Pinchart conn->bridge.ops |= DRM_BRIDGE_OP_DETECT;
3680c275c30SLaurent Pinchart if (conn->hpd_irq >= 0)
3690c275c30SLaurent Pinchart conn->bridge.ops |= DRM_BRIDGE_OP_HPD;
3700c275c30SLaurent Pinchart
3710c275c30SLaurent Pinchart dev_dbg(&pdev->dev,
3720c275c30SLaurent Pinchart "Found %s display connector '%s' %s DDC bus and %s HPD GPIO (ops 0x%x)\n",
3730c275c30SLaurent Pinchart drm_get_connector_type_name(conn->bridge.type),
3740c275c30SLaurent Pinchart label ? label : "<unlabelled>",
3750c275c30SLaurent Pinchart conn->bridge.ddc ? "with" : "without",
3760c275c30SLaurent Pinchart conn->hpd_gpio ? "with" : "without",
3770c275c30SLaurent Pinchart conn->bridge.ops);
3780c275c30SLaurent Pinchart
3790c275c30SLaurent Pinchart drm_bridge_add(&conn->bridge);
3800c275c30SLaurent Pinchart
3810c275c30SLaurent Pinchart return 0;
3820c275c30SLaurent Pinchart }
3830c275c30SLaurent Pinchart
display_connector_remove(struct platform_device * pdev)384d1837136SUwe Kleine-König static void display_connector_remove(struct platform_device *pdev)
3850c275c30SLaurent Pinchart {
3860c275c30SLaurent Pinchart struct display_connector *conn = platform_get_drvdata(pdev);
3870c275c30SLaurent Pinchart
3886de79dd3SH. Nikolaus Schaller if (conn->ddc_en)
3896de79dd3SH. Nikolaus Schaller gpiod_set_value(conn->ddc_en, 0);
3906de79dd3SH. Nikolaus Schaller
39199304fd0SDmitry Baryshkov if (conn->supply)
39299304fd0SDmitry Baryshkov regulator_disable(conn->supply);
3932e2bf3a5STomi Valkeinen
3940c275c30SLaurent Pinchart drm_bridge_remove(&conn->bridge);
3950c275c30SLaurent Pinchart
3960c275c30SLaurent Pinchart if (!IS_ERR(conn->bridge.ddc))
3970c275c30SLaurent Pinchart i2c_put_adapter(conn->bridge.ddc);
3980c275c30SLaurent Pinchart }
3990c275c30SLaurent Pinchart
4000c275c30SLaurent Pinchart static const struct of_device_id display_connector_match[] = {
4010c275c30SLaurent Pinchart {
4020c275c30SLaurent Pinchart .compatible = "composite-video-connector",
4030c275c30SLaurent Pinchart .data = (void *)DRM_MODE_CONNECTOR_Composite,
4040c275c30SLaurent Pinchart }, {
4050c275c30SLaurent Pinchart .compatible = "dvi-connector",
4060c275c30SLaurent Pinchart .data = (void *)DRM_MODE_CONNECTOR_DVII,
4070c275c30SLaurent Pinchart }, {
4080c275c30SLaurent Pinchart .compatible = "hdmi-connector",
4090c275c30SLaurent Pinchart .data = (void *)DRM_MODE_CONNECTOR_HDMIA,
4100c275c30SLaurent Pinchart }, {
4110c275c30SLaurent Pinchart .compatible = "svideo-connector",
4120c275c30SLaurent Pinchart .data = (void *)DRM_MODE_CONNECTOR_SVIDEO,
4130c275c30SLaurent Pinchart }, {
4140c275c30SLaurent Pinchart .compatible = "vga-connector",
4150c275c30SLaurent Pinchart .data = (void *)DRM_MODE_CONNECTOR_VGA,
4162e2bf3a5STomi Valkeinen }, {
4172e2bf3a5STomi Valkeinen .compatible = "dp-connector",
4182e2bf3a5STomi Valkeinen .data = (void *)DRM_MODE_CONNECTOR_DisplayPort,
4190c275c30SLaurent Pinchart },
4200c275c30SLaurent Pinchart {},
4210c275c30SLaurent Pinchart };
4220c275c30SLaurent Pinchart MODULE_DEVICE_TABLE(of, display_connector_match);
4230c275c30SLaurent Pinchart
4240c275c30SLaurent Pinchart static struct platform_driver display_connector_driver = {
4250c275c30SLaurent Pinchart .probe = display_connector_probe,
426d1837136SUwe Kleine-König .remove_new = display_connector_remove,
4270c275c30SLaurent Pinchart .driver = {
4280c275c30SLaurent Pinchart .name = "display-connector",
4290c275c30SLaurent Pinchart .of_match_table = display_connector_match,
4300c275c30SLaurent Pinchart },
4310c275c30SLaurent Pinchart };
4320c275c30SLaurent Pinchart module_platform_driver(display_connector_driver);
4330c275c30SLaurent Pinchart
4340c275c30SLaurent Pinchart MODULE_AUTHOR("Laurent Pinchart <laurent.pinchart@ideasonboard.com>");
4350c275c30SLaurent Pinchart MODULE_DESCRIPTION("Display connector driver");
4360c275c30SLaurent Pinchart MODULE_LICENSE("GPL");
437