drm/exynos: Stop using drm_framebuffer_unregister_private
[linux/fpc-iii.git] / drivers / gpu / drm / tegra / output.c
blob595d1ec3e02e8ff6e42c0574b0d1d1218bd8210f
1 /*
2 * Copyright (C) 2012 Avionic Design GmbH
3 * Copyright (C) 2012 NVIDIA CORPORATION. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
10 #include <drm/drm_atomic_helper.h>
11 #include <drm/drm_panel.h>
12 #include "drm.h"
14 int tegra_output_connector_get_modes(struct drm_connector *connector)
16 struct tegra_output *output = connector_to_output(connector);
17 struct edid *edid = NULL;
18 int err = 0;
21 * If the panel provides one or more modes, use them exclusively and
22 * ignore any other means of obtaining a mode.
24 if (output->panel) {
25 err = output->panel->funcs->get_modes(output->panel);
26 if (err > 0)
27 return err;
30 if (output->edid)
31 edid = kmemdup(output->edid, sizeof(*edid), GFP_KERNEL);
32 else if (output->ddc)
33 edid = drm_get_edid(connector, output->ddc);
35 drm_mode_connector_update_edid_property(connector, edid);
37 if (edid) {
38 err = drm_add_edid_modes(connector, edid);
39 drm_edid_to_eld(connector, edid);
40 kfree(edid);
43 return err;
46 enum drm_connector_status
47 tegra_output_connector_detect(struct drm_connector *connector, bool force)
49 struct tegra_output *output = connector_to_output(connector);
50 enum drm_connector_status status = connector_status_unknown;
52 if (gpio_is_valid(output->hpd_gpio)) {
53 if (output->hpd_gpio_flags & OF_GPIO_ACTIVE_LOW) {
54 if (gpio_get_value(output->hpd_gpio) != 0)
55 status = connector_status_disconnected;
56 else
57 status = connector_status_connected;
58 } else {
59 if (gpio_get_value(output->hpd_gpio) == 0)
60 status = connector_status_disconnected;
61 else
62 status = connector_status_connected;
64 } else {
65 if (!output->panel)
66 status = connector_status_disconnected;
67 else
68 status = connector_status_connected;
71 return status;
74 void tegra_output_connector_destroy(struct drm_connector *connector)
76 drm_connector_unregister(connector);
77 drm_connector_cleanup(connector);
80 void tegra_output_encoder_destroy(struct drm_encoder *encoder)
82 drm_encoder_cleanup(encoder);
85 static irqreturn_t hpd_irq(int irq, void *data)
87 struct tegra_output *output = data;
89 if (output->connector.dev)
90 drm_helper_hpd_irq_event(output->connector.dev);
92 return IRQ_HANDLED;
95 int tegra_output_probe(struct tegra_output *output)
97 struct device_node *ddc, *panel;
98 int err, size;
100 if (!output->of_node)
101 output->of_node = output->dev->of_node;
103 panel = of_parse_phandle(output->of_node, "nvidia,panel", 0);
104 if (panel) {
105 output->panel = of_drm_find_panel(panel);
106 if (!output->panel)
107 return -EPROBE_DEFER;
109 of_node_put(panel);
112 output->edid = of_get_property(output->of_node, "nvidia,edid", &size);
114 ddc = of_parse_phandle(output->of_node, "nvidia,ddc-i2c-bus", 0);
115 if (ddc) {
116 output->ddc = of_find_i2c_adapter_by_node(ddc);
117 if (!output->ddc) {
118 err = -EPROBE_DEFER;
119 of_node_put(ddc);
120 return err;
123 of_node_put(ddc);
126 output->hpd_gpio = of_get_named_gpio_flags(output->of_node,
127 "nvidia,hpd-gpio", 0,
128 &output->hpd_gpio_flags);
129 if (gpio_is_valid(output->hpd_gpio)) {
130 unsigned long flags;
132 err = gpio_request_one(output->hpd_gpio, GPIOF_DIR_IN,
133 "HDMI hotplug detect");
134 if (err < 0) {
135 dev_err(output->dev, "gpio_request_one(): %d\n", err);
136 return err;
139 err = gpio_to_irq(output->hpd_gpio);
140 if (err < 0) {
141 dev_err(output->dev, "gpio_to_irq(): %d\n", err);
142 gpio_free(output->hpd_gpio);
143 return err;
146 output->hpd_irq = err;
148 flags = IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING |
149 IRQF_ONESHOT;
151 err = request_threaded_irq(output->hpd_irq, NULL, hpd_irq,
152 flags, "hpd", output);
153 if (err < 0) {
154 dev_err(output->dev, "failed to request IRQ#%u: %d\n",
155 output->hpd_irq, err);
156 gpio_free(output->hpd_gpio);
157 return err;
160 output->connector.polled = DRM_CONNECTOR_POLL_HPD;
163 * Disable the interrupt until the connector has been
164 * initialized to avoid a race in the hotplug interrupt
165 * handler.
167 disable_irq(output->hpd_irq);
170 return 0;
173 void tegra_output_remove(struct tegra_output *output)
175 if (gpio_is_valid(output->hpd_gpio)) {
176 free_irq(output->hpd_irq, output);
177 gpio_free(output->hpd_gpio);
180 if (output->ddc)
181 put_device(&output->ddc->dev);
184 int tegra_output_init(struct drm_device *drm, struct tegra_output *output)
186 int err;
188 if (output->panel) {
189 err = drm_panel_attach(output->panel, &output->connector);
190 if (err < 0)
191 return err;
195 * The connector is now registered and ready to receive hotplug events
196 * so the hotplug interrupt can be enabled.
198 if (gpio_is_valid(output->hpd_gpio))
199 enable_irq(output->hpd_irq);
201 return 0;
204 void tegra_output_exit(struct tegra_output *output)
207 * The connector is going away, so the interrupt must be disabled to
208 * prevent the hotplug interrupt handler from potentially crashing.
210 if (gpio_is_valid(output->hpd_gpio))
211 disable_irq(output->hpd_irq);
213 if (output->panel)
214 drm_panel_detach(output->panel);