M7350/kernel/drivers/gpu/drm/exynos/exynos_drm_connector.c

246 lines
6.7 KiB
C
Raw Permalink Normal View History

2024-09-09 08:52:07 +00:00
/*
* Copyright (c) 2011 Samsung Electronics Co., Ltd.
* Authors:
* Inki Dae <inki.dae@samsung.com>
* Joonyoung Shim <jy0922.shim@samsung.com>
* Seung-Woo Kim <sw0312.kim@samsung.com>
*
2024-09-09 08:57:42 +00:00
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
2024-09-09 08:52:07 +00:00
*/
2024-09-09 08:57:42 +00:00
#include <drm/drmP.h>
#include <drm/drm_crtc_helper.h>
2024-09-09 08:52:07 +00:00
#include <drm/exynos_drm.h>
#include "exynos_drm_drv.h"
#include "exynos_drm_encoder.h"
2024-09-09 08:57:42 +00:00
#include "exynos_drm_connector.h"
2024-09-09 08:52:07 +00:00
#define to_exynos_connector(x) container_of(x, struct exynos_drm_connector,\
drm_connector)
struct exynos_drm_connector {
2024-09-09 08:57:42 +00:00
struct drm_connector drm_connector;
uint32_t encoder_id;
struct exynos_drm_display *display;
2024-09-09 08:52:07 +00:00
};
static int exynos_drm_connector_get_modes(struct drm_connector *connector)
{
struct exynos_drm_connector *exynos_connector =
to_exynos_connector(connector);
2024-09-09 08:57:42 +00:00
struct exynos_drm_display *display = exynos_connector->display;
struct edid *edid = NULL;
unsigned int count = 0;
int ret;
2024-09-09 08:52:07 +00:00
/*
* if get_edid() exists then get_edid() callback of hdmi side
* is called to get edid data through i2c interface else
* get timing from the FIMD driver(display controller).
*
* P.S. in case of lcd panel, count is always 1 if success
* because lcd panel has only one mode.
*/
2024-09-09 08:57:42 +00:00
if (display->ops->get_edid) {
edid = display->ops->get_edid(display, connector);
if (IS_ERR_OR_NULL(edid)) {
ret = PTR_ERR(edid);
2024-09-09 08:52:07 +00:00
edid = NULL;
2024-09-09 08:57:42 +00:00
DRM_ERROR("Panel operation get_edid failed %d\n", ret);
goto out;
2024-09-09 08:52:07 +00:00
}
count = drm_add_edid_modes(connector, edid);
2024-09-09 08:57:42 +00:00
if (!count) {
DRM_ERROR("Add edid modes failed %d\n", count);
goto out;
}
2024-09-09 08:52:07 +00:00
2024-09-09 08:57:42 +00:00
drm_mode_connector_update_edid_property(connector, edid);
2024-09-09 08:52:07 +00:00
} else {
struct exynos_drm_panel_info *panel;
2024-09-09 08:57:42 +00:00
struct drm_display_mode *mode = drm_mode_create(connector->dev);
if (!mode) {
DRM_ERROR("failed to create a new display mode.\n");
return 0;
}
2024-09-09 08:52:07 +00:00
2024-09-09 08:57:42 +00:00
if (display->ops->get_panel)
panel = display->ops->get_panel(display);
2024-09-09 08:52:07 +00:00
else {
drm_mode_destroy(connector->dev, mode);
return 0;
}
2024-09-09 08:57:42 +00:00
drm_display_mode_from_videomode(&panel->vm, mode);
mode->width_mm = panel->width_mm;
mode->height_mm = panel->height_mm;
2024-09-09 08:52:07 +00:00
connector->display_info.width_mm = mode->width_mm;
connector->display_info.height_mm = mode->height_mm;
mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
drm_mode_set_name(mode);
drm_mode_probed_add(connector, mode);
count = 1;
}
2024-09-09 08:57:42 +00:00
out:
kfree(edid);
2024-09-09 08:52:07 +00:00
return count;
}
static int exynos_drm_connector_mode_valid(struct drm_connector *connector,
struct drm_display_mode *mode)
{
struct exynos_drm_connector *exynos_connector =
to_exynos_connector(connector);
2024-09-09 08:57:42 +00:00
struct exynos_drm_display *display = exynos_connector->display;
2024-09-09 08:52:07 +00:00
int ret = MODE_BAD;
DRM_DEBUG_KMS("%s\n", __FILE__);
2024-09-09 08:57:42 +00:00
if (display->ops->check_mode)
if (!display->ops->check_mode(display, mode))
2024-09-09 08:52:07 +00:00
ret = MODE_OK;
return ret;
}
2024-09-09 08:57:42 +00:00
static struct drm_encoder *exynos_drm_best_encoder(
struct drm_connector *connector)
2024-09-09 08:52:07 +00:00
{
struct drm_device *dev = connector->dev;
struct exynos_drm_connector *exynos_connector =
to_exynos_connector(connector);
2024-09-09 08:57:42 +00:00
return drm_encoder_find(dev, exynos_connector->encoder_id);
2024-09-09 08:52:07 +00:00
}
static struct drm_connector_helper_funcs exynos_connector_helper_funcs = {
.get_modes = exynos_drm_connector_get_modes,
.mode_valid = exynos_drm_connector_mode_valid,
.best_encoder = exynos_drm_best_encoder,
};
static int exynos_drm_connector_fill_modes(struct drm_connector *connector,
unsigned int max_width, unsigned int max_height)
{
struct exynos_drm_connector *exynos_connector =
to_exynos_connector(connector);
2024-09-09 08:57:42 +00:00
struct exynos_drm_display *display = exynos_connector->display;
2024-09-09 08:52:07 +00:00
unsigned int width, height;
width = max_width;
height = max_height;
/*
* if specific driver want to find desired_mode using maxmum
* resolution then get max width and height from that driver.
*/
2024-09-09 08:57:42 +00:00
if (display->ops->get_max_resol)
display->ops->get_max_resol(display, &width, &height);
2024-09-09 08:52:07 +00:00
return drm_helper_probe_single_connector_modes(connector, width,
height);
}
/* get detection status of display device. */
static enum drm_connector_status
exynos_drm_connector_detect(struct drm_connector *connector, bool force)
{
struct exynos_drm_connector *exynos_connector =
to_exynos_connector(connector);
2024-09-09 08:57:42 +00:00
struct exynos_drm_display *display = exynos_connector->display;
2024-09-09 08:52:07 +00:00
enum drm_connector_status status = connector_status_disconnected;
2024-09-09 08:57:42 +00:00
if (display->ops->is_connected) {
if (display->ops->is_connected(display))
2024-09-09 08:52:07 +00:00
status = connector_status_connected;
else
status = connector_status_disconnected;
}
return status;
}
static void exynos_drm_connector_destroy(struct drm_connector *connector)
{
struct exynos_drm_connector *exynos_connector =
to_exynos_connector(connector);
2024-09-09 08:57:42 +00:00
drm_connector_unregister(connector);
2024-09-09 08:52:07 +00:00
drm_connector_cleanup(connector);
kfree(exynos_connector);
}
static struct drm_connector_funcs exynos_connector_funcs = {
.dpms = drm_helper_connector_dpms,
.fill_modes = exynos_drm_connector_fill_modes,
.detect = exynos_drm_connector_detect,
.destroy = exynos_drm_connector_destroy,
};
struct drm_connector *exynos_drm_connector_create(struct drm_device *dev,
struct drm_encoder *encoder)
{
struct exynos_drm_connector *exynos_connector;
2024-09-09 08:57:42 +00:00
struct exynos_drm_display *display = exynos_drm_get_display(encoder);
2024-09-09 08:52:07 +00:00
struct drm_connector *connector;
int type;
int err;
exynos_connector = kzalloc(sizeof(*exynos_connector), GFP_KERNEL);
2024-09-09 08:57:42 +00:00
if (!exynos_connector)
2024-09-09 08:52:07 +00:00
return NULL;
connector = &exynos_connector->drm_connector;
2024-09-09 08:57:42 +00:00
switch (display->type) {
2024-09-09 08:52:07 +00:00
case EXYNOS_DISPLAY_TYPE_HDMI:
type = DRM_MODE_CONNECTOR_HDMIA;
connector->interlace_allowed = true;
connector->polled = DRM_CONNECTOR_POLL_HPD;
break;
case EXYNOS_DISPLAY_TYPE_VIDI:
type = DRM_MODE_CONNECTOR_VIRTUAL;
connector->polled = DRM_CONNECTOR_POLL_HPD;
break;
default:
type = DRM_MODE_CONNECTOR_Unknown;
break;
}
drm_connector_init(dev, connector, &exynos_connector_funcs, type);
drm_connector_helper_add(connector, &exynos_connector_helper_funcs);
2024-09-09 08:57:42 +00:00
err = drm_connector_register(connector);
2024-09-09 08:52:07 +00:00
if (err)
goto err_connector;
exynos_connector->encoder_id = encoder->base.id;
2024-09-09 08:57:42 +00:00
exynos_connector->display = display;
connector->dpms = DRM_MODE_DPMS_OFF;
2024-09-09 08:52:07 +00:00
connector->encoder = encoder;
err = drm_mode_connector_attach_encoder(connector, encoder);
if (err) {
DRM_ERROR("failed to attach a connector to a encoder\n");
goto err_sysfs;
}
DRM_DEBUG_KMS("connector has been created\n");
return connector;
err_sysfs:
2024-09-09 08:57:42 +00:00
drm_connector_unregister(connector);
2024-09-09 08:52:07 +00:00
err_connector:
drm_connector_cleanup(connector);
kfree(exynos_connector);
return NULL;
}