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.
10 #include <drm/drm_atomic_helper.h>
11 #include <drm/drm_panel.h>
16 #include <media/cec-notifier.h>
18 int tegra_output_connector_get_modes(struct drm_connector
*connector
)
20 struct tegra_output
*output
= connector_to_output(connector
);
21 struct edid
*edid
= NULL
;
25 * If the panel provides one or more modes, use them exclusively and
26 * ignore any other means of obtaining a mode.
29 err
= output
->panel
->funcs
->get_modes(output
->panel
);
35 edid
= kmemdup(output
->edid
, sizeof(*edid
), GFP_KERNEL
);
37 edid
= drm_get_edid(connector
, output
->ddc
);
39 cec_notifier_set_phys_addr_from_edid(output
->notifier
, edid
);
40 drm_connector_update_edid_property(connector
, edid
);
43 err
= drm_add_edid_modes(connector
, edid
);
50 enum drm_connector_status
51 tegra_output_connector_detect(struct drm_connector
*connector
, bool force
)
53 struct tegra_output
*output
= connector_to_output(connector
);
54 enum drm_connector_status status
= connector_status_unknown
;
56 if (gpio_is_valid(output
->hpd_gpio
)) {
57 if (output
->hpd_gpio_flags
& OF_GPIO_ACTIVE_LOW
) {
58 if (gpio_get_value(output
->hpd_gpio
) != 0)
59 status
= connector_status_disconnected
;
61 status
= connector_status_connected
;
63 if (gpio_get_value(output
->hpd_gpio
) == 0)
64 status
= connector_status_disconnected
;
66 status
= connector_status_connected
;
70 status
= connector_status_disconnected
;
72 status
= connector_status_connected
;
75 if (status
!= connector_status_connected
)
76 cec_notifier_phys_addr_invalidate(output
->notifier
);
81 void tegra_output_connector_destroy(struct drm_connector
*connector
)
83 drm_connector_unregister(connector
);
84 drm_connector_cleanup(connector
);
87 void tegra_output_encoder_destroy(struct drm_encoder
*encoder
)
89 drm_encoder_cleanup(encoder
);
92 static irqreturn_t
hpd_irq(int irq
, void *data
)
94 struct tegra_output
*output
= data
;
96 if (output
->connector
.dev
)
97 drm_helper_hpd_irq_event(output
->connector
.dev
);
102 int tegra_output_probe(struct tegra_output
*output
)
104 struct device_node
*ddc
, *panel
;
107 if (!output
->of_node
)
108 output
->of_node
= output
->dev
->of_node
;
110 panel
= of_parse_phandle(output
->of_node
, "nvidia,panel", 0);
112 output
->panel
= of_drm_find_panel(panel
);
113 if (IS_ERR(output
->panel
))
114 return PTR_ERR(output
->panel
);
119 output
->edid
= of_get_property(output
->of_node
, "nvidia,edid", &size
);
121 ddc
= of_parse_phandle(output
->of_node
, "nvidia,ddc-i2c-bus", 0);
123 output
->ddc
= of_find_i2c_adapter_by_node(ddc
);
133 output
->hpd_gpio
= of_get_named_gpio_flags(output
->of_node
,
134 "nvidia,hpd-gpio", 0,
135 &output
->hpd_gpio_flags
);
136 if (gpio_is_valid(output
->hpd_gpio
)) {
139 err
= gpio_request_one(output
->hpd_gpio
, GPIOF_DIR_IN
,
140 "HDMI hotplug detect");
142 dev_err(output
->dev
, "gpio_request_one(): %d\n", err
);
146 err
= gpio_to_irq(output
->hpd_gpio
);
148 dev_err(output
->dev
, "gpio_to_irq(): %d\n", err
);
149 gpio_free(output
->hpd_gpio
);
153 output
->hpd_irq
= err
;
155 flags
= IRQF_TRIGGER_RISING
| IRQF_TRIGGER_FALLING
|
158 err
= request_threaded_irq(output
->hpd_irq
, NULL
, hpd_irq
,
159 flags
, "hpd", output
);
161 dev_err(output
->dev
, "failed to request IRQ#%u: %d\n",
162 output
->hpd_irq
, err
);
163 gpio_free(output
->hpd_gpio
);
167 output
->connector
.polled
= DRM_CONNECTOR_POLL_HPD
;
170 * Disable the interrupt until the connector has been
171 * initialized to avoid a race in the hotplug interrupt
174 disable_irq(output
->hpd_irq
);
180 void tegra_output_remove(struct tegra_output
*output
)
182 if (gpio_is_valid(output
->hpd_gpio
)) {
183 free_irq(output
->hpd_irq
, output
);
184 gpio_free(output
->hpd_gpio
);
188 put_device(&output
->ddc
->dev
);
191 int tegra_output_init(struct drm_device
*drm
, struct tegra_output
*output
)
196 err
= drm_panel_attach(output
->panel
, &output
->connector
);
202 * The connector is now registered and ready to receive hotplug events
203 * so the hotplug interrupt can be enabled.
205 if (gpio_is_valid(output
->hpd_gpio
))
206 enable_irq(output
->hpd_irq
);
211 void tegra_output_exit(struct tegra_output
*output
)
214 * The connector is going away, so the interrupt must be disabled to
215 * prevent the hotplug interrupt handler from potentially crashing.
217 if (gpio_is_valid(output
->hpd_gpio
))
218 disable_irq(output
->hpd_irq
);
221 drm_panel_detach(output
->panel
);
224 void tegra_output_find_possible_crtcs(struct tegra_output
*output
,
225 struct drm_device
*drm
)
227 struct device
*dev
= output
->dev
;
228 struct drm_crtc
*crtc
;
229 unsigned int mask
= 0;
231 drm_for_each_crtc(crtc
, drm
) {
232 struct tegra_dc
*dc
= to_tegra_dc(crtc
);
234 if (tegra_dc_has_output(dc
, dev
))
235 mask
|= drm_crtc_mask(crtc
);
239 dev_warn(dev
, "missing output definition for heads in DT\n");
243 output
->encoder
.possible_crtcs
= mask
;