2012-11-16 04:28:22 +07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 Avionic Design GmbH
|
|
|
|
* Copyright (C) 2012 NVIDIA CORPORATION. All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
|
2014-11-24 22:27:13 +07:00
|
|
|
#include <drm/drm_atomic_helper.h>
|
2013-08-30 20:22:36 +07:00
|
|
|
#include <drm/drm_panel.h>
|
2017-10-13 00:12:57 +07:00
|
|
|
|
2012-11-16 04:28:22 +07:00
|
|
|
#include "drm.h"
|
2017-10-13 00:12:57 +07:00
|
|
|
#include "dc.h"
|
2012-11-16 04:28:22 +07:00
|
|
|
|
2017-09-11 19:29:52 +07:00
|
|
|
#include <media/cec-notifier.h>
|
|
|
|
|
2014-11-28 21:38:40 +07:00
|
|
|
int tegra_output_connector_get_modes(struct drm_connector *connector)
|
2012-11-16 04:28:22 +07:00
|
|
|
{
|
|
|
|
struct tegra_output *output = connector_to_output(connector);
|
|
|
|
struct edid *edid = NULL;
|
|
|
|
int err = 0;
|
|
|
|
|
2014-01-13 18:56:19 +07:00
|
|
|
/*
|
|
|
|
* If the panel provides one or more modes, use them exclusively and
|
|
|
|
* ignore any other means of obtaining a mode.
|
|
|
|
*/
|
2013-08-30 20:22:36 +07:00
|
|
|
if (output->panel) {
|
|
|
|
err = output->panel->funcs->get_modes(output->panel);
|
|
|
|
if (err > 0)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2012-11-16 04:28:22 +07:00
|
|
|
if (output->edid)
|
|
|
|
edid = kmemdup(output->edid, sizeof(*edid), GFP_KERNEL);
|
|
|
|
else if (output->ddc)
|
|
|
|
edid = drm_get_edid(connector, output->ddc);
|
|
|
|
|
2017-09-11 19:29:52 +07:00
|
|
|
cec_notifier_set_phys_addr_from_edid(output->notifier, edid);
|
2012-11-16 04:28:22 +07:00
|
|
|
drm_mode_connector_update_edid_property(connector, edid);
|
|
|
|
|
|
|
|
if (edid) {
|
|
|
|
err = drm_add_edid_modes(connector, edid);
|
|
|
|
kfree(edid);
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2014-11-28 21:38:40 +07:00
|
|
|
enum drm_connector_status
|
|
|
|
tegra_output_connector_detect(struct drm_connector *connector, bool force)
|
2012-11-16 04:28:22 +07:00
|
|
|
{
|
|
|
|
struct tegra_output *output = connector_to_output(connector);
|
|
|
|
enum drm_connector_status status = connector_status_unknown;
|
|
|
|
|
|
|
|
if (gpio_is_valid(output->hpd_gpio)) {
|
2015-04-27 20:12:39 +07:00
|
|
|
if (output->hpd_gpio_flags & OF_GPIO_ACTIVE_LOW) {
|
|
|
|
if (gpio_get_value(output->hpd_gpio) != 0)
|
|
|
|
status = connector_status_disconnected;
|
|
|
|
else
|
|
|
|
status = connector_status_connected;
|
|
|
|
} else {
|
|
|
|
if (gpio_get_value(output->hpd_gpio) == 0)
|
|
|
|
status = connector_status_disconnected;
|
|
|
|
else
|
|
|
|
status = connector_status_connected;
|
|
|
|
}
|
2012-11-16 04:28:22 +07:00
|
|
|
} else {
|
2013-08-30 20:22:36 +07:00
|
|
|
if (!output->panel)
|
|
|
|
status = connector_status_disconnected;
|
|
|
|
else
|
|
|
|
status = connector_status_connected;
|
2012-11-16 04:28:22 +07:00
|
|
|
}
|
|
|
|
|
2017-09-11 19:29:52 +07:00
|
|
|
if (status != connector_status_connected)
|
|
|
|
cec_notifier_phys_addr_invalidate(output->notifier);
|
|
|
|
|
2012-11-16 04:28:22 +07:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2014-11-28 21:38:40 +07:00
|
|
|
void tegra_output_connector_destroy(struct drm_connector *connector)
|
2012-11-16 04:28:22 +07:00
|
|
|
{
|
2014-05-29 22:57:41 +07:00
|
|
|
drm_connector_unregister(connector);
|
2012-11-16 04:28:22 +07:00
|
|
|
drm_connector_cleanup(connector);
|
|
|
|
}
|
|
|
|
|
2014-11-28 21:38:40 +07:00
|
|
|
void tegra_output_encoder_destroy(struct drm_encoder *encoder)
|
2012-11-16 04:28:22 +07:00
|
|
|
{
|
|
|
|
drm_encoder_cleanup(encoder);
|
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t hpd_irq(int irq, void *data)
|
|
|
|
{
|
|
|
|
struct tegra_output *output = data;
|
|
|
|
|
2014-10-21 19:00:09 +07:00
|
|
|
if (output->connector.dev)
|
|
|
|
drm_helper_hpd_irq_event(output->connector.dev);
|
2012-11-16 04:28:22 +07:00
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2013-10-14 19:26:42 +07:00
|
|
|
int tegra_output_probe(struct tegra_output *output)
|
2012-11-16 04:28:22 +07:00
|
|
|
{
|
2013-08-30 20:22:36 +07:00
|
|
|
struct device_node *ddc, *panel;
|
2014-01-13 19:58:17 +07:00
|
|
|
int err, size;
|
2012-11-16 04:28:22 +07:00
|
|
|
|
|
|
|
if (!output->of_node)
|
|
|
|
output->of_node = output->dev->of_node;
|
|
|
|
|
2013-08-30 20:22:36 +07:00
|
|
|
panel = of_parse_phandle(output->of_node, "nvidia,panel", 0);
|
|
|
|
if (panel) {
|
|
|
|
output->panel = of_drm_find_panel(panel);
|
|
|
|
if (!output->panel)
|
|
|
|
return -EPROBE_DEFER;
|
|
|
|
|
|
|
|
of_node_put(panel);
|
|
|
|
}
|
|
|
|
|
2012-11-16 04:28:22 +07: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);
|
|
|
|
}
|
|
|
|
|
|
|
|
output->hpd_gpio = of_get_named_gpio_flags(output->of_node,
|
|
|
|
"nvidia,hpd-gpio", 0,
|
2015-04-27 20:12:39 +07:00
|
|
|
&output->hpd_gpio_flags);
|
2012-11-16 04:28:22 +07:00
|
|
|
if (gpio_is_valid(output->hpd_gpio)) {
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
err = gpio_request_one(output->hpd_gpio, GPIOF_DIR_IN,
|
|
|
|
"HDMI hotplug detect");
|
|
|
|
if (err < 0) {
|
|
|
|
dev_err(output->dev, "gpio_request_one(): %d\n", err);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = gpio_to_irq(output->hpd_gpio);
|
|
|
|
if (err < 0) {
|
|
|
|
dev_err(output->dev, "gpio_to_irq(): %d\n", err);
|
2013-10-14 19:26:42 +07:00
|
|
|
gpio_free(output->hpd_gpio);
|
|
|
|
return err;
|
2012-11-16 04:28:22 +07: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 19:26:42 +07:00
|
|
|
gpio_free(output->hpd_gpio);
|
|
|
|
return err;
|
2012-11-16 04:28:22 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
output->connector.polled = DRM_CONNECTOR_POLL_HPD;
|
2014-10-21 19:00:09 +07: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 04:28:22 +07:00
|
|
|
}
|
|
|
|
|
2013-10-14 19:26:42 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-12-19 21:55:08 +07:00
|
|
|
void tegra_output_remove(struct tegra_output *output)
|
2013-10-14 19:26:42 +07:00
|
|
|
{
|
|
|
|
if (gpio_is_valid(output->hpd_gpio)) {
|
|
|
|
free_irq(output->hpd_irq, output);
|
|
|
|
gpio_free(output->hpd_gpio);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (output->ddc)
|
|
|
|
put_device(&output->ddc->dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
int tegra_output_init(struct drm_device *drm, struct tegra_output *output)
|
|
|
|
{
|
2014-12-19 21:51:35 +07:00
|
|
|
int err;
|
2012-11-16 04:28:22 +07:00
|
|
|
|
2014-12-19 21:51:35 +07:00
|
|
|
if (output->panel) {
|
|
|
|
err = drm_panel_attach(output->panel, &output->connector);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
}
|
2012-11-16 04:28:22 +07:00
|
|
|
|
2014-10-21 19:00:09 +07:00
|
|
|
/*
|
|
|
|
* The connector is now registered and ready to receive hotplug events
|
|
|
|
* so the hotplug interrupt can be enabled.
|
|
|
|
*/
|
|
|
|
if (gpio_is_valid(output->hpd_gpio))
|
|
|
|
enable_irq(output->hpd_irq);
|
|
|
|
|
2012-11-16 04:28:22 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-12-19 21:55:08 +07:00
|
|
|
void tegra_output_exit(struct tegra_output *output)
|
2012-11-16 04:28:22 +07:00
|
|
|
{
|
2014-10-21 19:00:09 +07:00
|
|
|
/*
|
|
|
|
* The connector is going away, so the interrupt must be disabled to
|
|
|
|
* prevent the hotplug interrupt handler from potentially crashing.
|
|
|
|
*/
|
|
|
|
if (gpio_is_valid(output->hpd_gpio))
|
|
|
|
disable_irq(output->hpd_irq);
|
|
|
|
|
2014-11-04 22:20:20 +07:00
|
|
|
if (output->panel)
|
|
|
|
drm_panel_detach(output->panel);
|
2012-11-16 04:28:22 +07:00
|
|
|
}
|
2017-10-13 00:12:57 +07: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;
|
|
|
|
}
|