2019-06-04 16:11:33 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2012-11-16 05:28:22 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 Avionic Design GmbH
|
|
|
|
* Copyright (C) 2012 NVIDIA CORPORATION. All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2014-11-24 23:27:13 +08:00
|
|
|
#include <drm/drm_atomic_helper.h>
|
2013-08-30 21:22:36 +08:00
|
|
|
#include <drm/drm_panel.h>
|
2017-10-13 01:12:57 +08:00
|
|
|
|
2012-11-16 05:28:22 +08:00
|
|
|
#include "drm.h"
|
2017-10-13 01:12:57 +08:00
|
|
|
#include "dc.h"
|
2012-11-16 05:28:22 +08:00
|
|
|
|
2017-09-11 20:29:52 +08:00
|
|
|
#include <media/cec-notifier.h>
|
|
|
|
|
2014-11-28 22:38:40 +08:00
|
|
|
int tegra_output_connector_get_modes(struct drm_connector *connector)
|
2012-11-16 05:28:22 +08:00
|
|
|
{
|
|
|
|
struct tegra_output *output = connector_to_output(connector);
|
|
|
|
struct edid *edid = NULL;
|
|
|
|
int err = 0;
|
|
|
|
|
2014-01-13 19:56:19 +08:00
|
|
|
/*
|
|
|
|
* If the panel provides one or more modes, use them exclusively and
|
|
|
|
* ignore any other means of obtaining a mode.
|
|
|
|
*/
|
2013-08-30 21:22:36 +08:00
|
|
|
if (output->panel) {
|
|
|
|
err = output->panel->funcs->get_modes(output->panel);
|
|
|
|
if (err > 0)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2012-11-16 05:28:22 +08:00
|
|
|
if (output->edid)
|
|
|
|
edid = kmemdup(output->edid, sizeof(*edid), GFP_KERNEL);
|
|
|
|
else if (output->ddc)
|
|
|
|
edid = drm_get_edid(connector, output->ddc);
|
|
|
|
|
2018-12-11 00:34:54 +08:00
|
|
|
cec_notifier_set_phys_addr_from_edid(output->cec, edid);
|
2018-07-09 16:40:06 +08:00
|
|
|
drm_connector_update_edid_property(connector, edid);
|
2012-11-16 05:28:22 +08:00
|
|
|
|
|
|
|
if (edid) {
|
|
|
|
err = drm_add_edid_modes(connector, edid);
|
|
|
|
kfree(edid);
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2014-11-28 22:38:40 +08:00
|
|
|
enum drm_connector_status
|
|
|
|
tegra_output_connector_detect(struct drm_connector *connector, bool force)
|
2012-11-16 05:28:22 +08:00
|
|
|
{
|
|
|
|
struct tegra_output *output = connector_to_output(connector);
|
|
|
|
enum drm_connector_status status = connector_status_unknown;
|
|
|
|
|
2019-06-05 16:46:46 +08:00
|
|
|
if (output->hpd_gpio) {
|
|
|
|
if (gpiod_get_value(output->hpd_gpio) == 0)
|
|
|
|
status = connector_status_disconnected;
|
|
|
|
else
|
|
|
|
status = connector_status_connected;
|
2012-11-16 05:28:22 +08:00
|
|
|
} else {
|
2013-08-30 21:22:36 +08:00
|
|
|
if (!output->panel)
|
|
|
|
status = connector_status_disconnected;
|
|
|
|
else
|
|
|
|
status = connector_status_connected;
|
2012-11-16 05:28:22 +08:00
|
|
|
}
|
|
|
|
|
2017-09-11 20:29:52 +08:00
|
|
|
if (status != connector_status_connected)
|
2018-12-11 00:34:54 +08:00
|
|
|
cec_notifier_phys_addr_invalidate(output->cec);
|
2017-09-11 20:29:52 +08:00
|
|
|
|
2012-11-16 05:28:22 +08:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2014-11-28 22:38:40 +08:00
|
|
|
void tegra_output_connector_destroy(struct drm_connector *connector)
|
2012-11-16 05:28:22 +08:00
|
|
|
{
|
2014-05-29 23:57:41 +08:00
|
|
|
drm_connector_unregister(connector);
|
2012-11-16 05:28:22 +08:00
|
|
|
drm_connector_cleanup(connector);
|
|
|
|
}
|
|
|
|
|
2014-11-28 22:38:40 +08:00
|
|
|
void tegra_output_encoder_destroy(struct drm_encoder *encoder)
|
2012-11-16 05:28:22 +08:00
|
|
|
{
|
|
|
|
drm_encoder_cleanup(encoder);
|
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t hpd_irq(int irq, void *data)
|
|
|
|
{
|
|
|
|
struct tegra_output *output = data;
|
|
|
|
|
2014-10-21 20:00:09 +08:00
|
|
|
if (output->connector.dev)
|
|
|
|
drm_helper_hpd_irq_event(output->connector.dev);
|
2012-11-16 05:28:22 +08:00
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2013-10-14 20:26:42 +08:00
|
|
|
int tegra_output_probe(struct tegra_output *output)
|
2012-11-16 05:28:22 +08:00
|
|
|
{
|
2013-08-30 21:22:36 +08:00
|
|
|
struct device_node *ddc, *panel;
|
2019-06-05 16:46:46 +08:00
|
|
|
unsigned long flags;
|
2014-01-13 20:58:17 +08:00
|
|
|
int err, size;
|
2012-11-16 05:28:22 +08:00
|
|
|
|
|
|
|
if (!output->of_node)
|
|
|
|
output->of_node = output->dev->of_node;
|
|
|
|
|
2013-08-30 21:22:36 +08:00
|
|
|
panel = of_parse_phandle(output->of_node, "nvidia,panel", 0);
|
|
|
|
if (panel) {
|
|
|
|
output->panel = of_drm_find_panel(panel);
|
2018-05-09 21:00:39 +08:00
|
|
|
if (IS_ERR(output->panel))
|
|
|
|
return PTR_ERR(output->panel);
|
2013-08-30 21:22:36 +08:00
|
|
|
|
|
|
|
of_node_put(panel);
|
|
|
|
}
|
|
|
|
|
2012-11-16 05:28:22 +08:00
|
|
|
output->edid = of_get_property(output->of_node, "nvidia,edid", &size);
|
|
|
|
|
|
|
|
ddc = of_parse_phandle(output->of_node, "nvidia,ddc-i2c-bus", 0);
|
|
|
|
if (ddc) {
|
|
|
|
output->ddc = of_find_i2c_adapter_by_node(ddc);
|
|
|
|
if (!output->ddc) {
|
|
|
|
err = -EPROBE_DEFER;
|
|
|
|
of_node_put(ddc);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
of_node_put(ddc);
|
|
|
|
}
|
|
|
|
|
2019-06-05 16:46:46 +08:00
|
|
|
output->hpd_gpio = devm_gpiod_get_from_of_node(output->dev,
|
|
|
|
output->of_node,
|
|
|
|
"nvidia,hpd-gpio", 0,
|
|
|
|
GPIOD_IN,
|
|
|
|
"HDMI hotplug detect");
|
|
|
|
if (IS_ERR(output->hpd_gpio))
|
|
|
|
return PTR_ERR(output->hpd_gpio);
|
2012-11-16 05:28:22 +08:00
|
|
|
|
2019-06-05 16:46:46 +08:00
|
|
|
if (output->hpd_gpio) {
|
|
|
|
err = gpiod_to_irq(output->hpd_gpio);
|
2012-11-16 05:28:22 +08:00
|
|
|
if (err < 0) {
|
2019-06-05 16:46:46 +08:00
|
|
|
dev_err(output->dev, "gpiod_to_irq(): %d\n", err);
|
2013-10-14 20:26:42 +08:00
|
|
|
return err;
|
2012-11-16 05:28:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
output->hpd_irq = err;
|
|
|
|
|
|
|
|
flags = IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING |
|
|
|
|
IRQF_ONESHOT;
|
|
|
|
|
|
|
|
err = request_threaded_irq(output->hpd_irq, NULL, hpd_irq,
|
|
|
|
flags, "hpd", output);
|
|
|
|
if (err < 0) {
|
|
|
|
dev_err(output->dev, "failed to request IRQ#%u: %d\n",
|
|
|
|
output->hpd_irq, err);
|
2013-10-14 20:26:42 +08:00
|
|
|
return err;
|
2012-11-16 05:28:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
output->connector.polled = DRM_CONNECTOR_POLL_HPD;
|
2014-10-21 20:00:09 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Disable the interrupt until the connector has been
|
|
|
|
* initialized to avoid a race in the hotplug interrupt
|
|
|
|
* handler.
|
|
|
|
*/
|
|
|
|
disable_irq(output->hpd_irq);
|
2012-11-16 05:28:22 +08:00
|
|
|
}
|
|
|
|
|
2018-12-11 00:34:54 +08:00
|
|
|
output->cec = cec_notifier_get(output->dev);
|
|
|
|
if (!output->cec)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2013-10-14 20:26:42 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-12-19 22:55:08 +08:00
|
|
|
void tegra_output_remove(struct tegra_output *output)
|
2013-10-14 20:26:42 +08:00
|
|
|
{
|
2018-12-11 00:34:54 +08:00
|
|
|
if (output->cec)
|
|
|
|
cec_notifier_put(output->cec);
|
|
|
|
|
2019-06-05 16:46:46 +08:00
|
|
|
if (output->hpd_gpio)
|
2013-10-14 20:26:42 +08:00
|
|
|
free_irq(output->hpd_irq, output);
|
|
|
|
|
|
|
|
if (output->ddc)
|
|
|
|
put_device(&output->ddc->dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
int tegra_output_init(struct drm_device *drm, struct tegra_output *output)
|
|
|
|
{
|
2014-12-19 22:51:35 +08:00
|
|
|
int err;
|
2012-11-16 05:28:22 +08:00
|
|
|
|
2014-12-19 22:51:35 +08:00
|
|
|
if (output->panel) {
|
|
|
|
err = drm_panel_attach(output->panel, &output->connector);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
}
|
2012-11-16 05:28:22 +08:00
|
|
|
|
2014-10-21 20:00:09 +08:00
|
|
|
/*
|
|
|
|
* The connector is now registered and ready to receive hotplug events
|
|
|
|
* so the hotplug interrupt can be enabled.
|
|
|
|
*/
|
2019-06-05 16:46:46 +08:00
|
|
|
if (output->hpd_gpio)
|
2014-10-21 20:00:09 +08:00
|
|
|
enable_irq(output->hpd_irq);
|
|
|
|
|
2012-11-16 05:28:22 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-12-19 22:55:08 +08:00
|
|
|
void tegra_output_exit(struct tegra_output *output)
|
2012-11-16 05:28:22 +08:00
|
|
|
{
|
2014-10-21 20:00:09 +08:00
|
|
|
/*
|
|
|
|
* The connector is going away, so the interrupt must be disabled to
|
|
|
|
* prevent the hotplug interrupt handler from potentially crashing.
|
|
|
|
*/
|
2019-06-05 16:46:46 +08:00
|
|
|
if (output->hpd_gpio)
|
2014-10-21 20:00:09 +08:00
|
|
|
disable_irq(output->hpd_irq);
|
|
|
|
|
2014-11-04 23:20:20 +08:00
|
|
|
if (output->panel)
|
|
|
|
drm_panel_detach(output->panel);
|
2012-11-16 05:28:22 +08:00
|
|
|
}
|
2017-10-13 01:12:57 +08:00
|
|
|
|
|
|
|
void tegra_output_find_possible_crtcs(struct tegra_output *output,
|
|
|
|
struct drm_device *drm)
|
|
|
|
{
|
|
|
|
struct device *dev = output->dev;
|
|
|
|
struct drm_crtc *crtc;
|
|
|
|
unsigned int mask = 0;
|
|
|
|
|
|
|
|
drm_for_each_crtc(crtc, drm) {
|
|
|
|
struct tegra_dc *dc = to_tegra_dc(crtc);
|
|
|
|
|
|
|
|
if (tegra_dc_has_output(dc, dev))
|
|
|
|
mask |= drm_crtc_mask(crtc);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mask == 0) {
|
|
|
|
dev_warn(dev, "missing output definition for heads in DT\n");
|
|
|
|
mask = 0x3;
|
|
|
|
}
|
|
|
|
|
|
|
|
output->encoder.possible_crtcs = mask;
|
|
|
|
}
|