mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-28 11:18:45 +07:00
7d902c05b4
It's dead code, the core handles all this directly now. The only special case is nouveau and tda988x which used one function for both legacy modeset code and -nv50 atomic world instead of 2 vtables. But amounts to exactly the same. v2: Rebase over the panel/brideg refactorings in stm/ltdc. Signed-off-by: Daniel Vetter <daniel.vetter@intel.com> Cc: Archit Taneja <architt@codeaurora.org> Cc: Andrzej Hajda <a.hajda@samsung.com> Cc: Laurent Pinchart <Laurent.pinchart@ideasonboard.com> Cc: Peter Senna Tschudin <peter.senna@collabora.com> Cc: Martin Donnelly <martin.donnelly@ge.com> Cc: Martyn Welch <martyn.welch@collabora.co.uk> Cc: Daniel Vetter <daniel.vetter@intel.com> Cc: Jani Nikula <jani.nikula@linux.intel.com> Cc: Sean Paul <seanpaul@chromium.org> Cc: David Airlie <airlied@linux.ie> Cc: Inki Dae <inki.dae@samsung.com> Cc: Joonyoung Shim <jy0922.shim@samsung.com> Cc: Seung-Woo Kim <sw0312.kim@samsung.com> Cc: Kyungmin Park <kyungmin.park@samsung.com> Cc: Kukjin Kim <kgene@kernel.org> Cc: Krzysztof Kozlowski <krzk@kernel.org> Cc: Stefan Agner <stefan@agner.ch> Cc: Alison Wang <alison.wang@freescale.com> Cc: Russell King <linux@armlinux.org.uk> Cc: Philipp Zabel <p.zabel@pengutronix.de> Cc: CK Hu <ck.hu@mediatek.com> Cc: Matthias Brugger <matthias.bgg@gmail.com> Cc: Neil Armstrong <narmstrong@baylibre.com> Cc: Carlo Caione <carlo@caione.org> Cc: Kevin Hilman <khilman@baylibre.com> Cc: Marek Vasut <marex@denx.de> Cc: Ben Skeggs <bskeggs@redhat.com> Cc: Tomi Valkeinen <tomi.valkeinen@ti.com> Cc: Eric Anholt <eric@anholt.net> Cc: Mark Yao <mark.yao@rock-chips.com> Cc: Heiko Stuebner <heiko@sntech.de> Cc: Benjamin Gaignard <benjamin.gaignard@linaro.org> Cc: Vincent Abriou <vincent.abriou@st.com> Cc: Yannick Fertre <yannick.fertre@st.com> Cc: Philippe Cornu <philippe.cornu@st.com> Cc: Maxime Ripard <maxime.ripard@free-electrons.com> Cc: Chen-Yu Tsai <wens@csie.org> Cc: Thierry Reding <thierry.reding@gmail.com> Cc: Jonathan Hunter <jonathanh@nvidia.com> Cc: Jyri Sarha <jsarha@ti.com> Cc: Gerd Hoffmann <kraxel@redhat.com> Cc: Shawn Guo <shawnguo@kernel.org> Cc: John Stultz <john.stultz@linaro.org> Cc: Lars-Peter Clausen <lars@metafoo.de> Cc: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> Cc: Jeffy Chen <jeffy.chen@rock-chips.com> Cc: Tomeu Vizoso <tomeu.vizoso@collabora.com> Cc: Yakir Yang <kuankuan.y@gmail.com> Cc: Marek Szyprowski <m.szyprowski@samsung.com> Cc: Jose Abreu <Jose.Abreu@synopsys.com> Cc: Romain Perier <romain.perier@collabora.com> Cc: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com> Cc: Xinliang Liu <z.liuxinliang@hisilicon.com> Cc: Alexey Brodkin <abrodkin@synopsys.com> Cc: Alex Deucher <alexander.deucher@amd.com> Cc: Rongrong Zou <zourongrong@gmail.com> Cc: Rob Clark <robdclark@gmail.com> Cc: Hai Li <hali@codeaurora.org> Cc: "Noralf Trønnes" <noralf@tronnes.org> Cc: linux-arm-kernel@lists.infradead.org Cc: linux-samsung-soc@vger.kernel.org Cc: intel-gfx@lists.freedesktop.org Cc: linux-mediatek@lists.infradead.org Cc: linux-amlogic@lists.infradead.org Cc: nouveau@lists.freedesktop.org Cc: linux-renesas-soc@vger.kernel.org Cc: linux-rockchip@lists.infradead.org Cc: linux-tegra@vger.kernel.org Cc: virtualization@lists.linux-foundation.org Cc: zain wang <wzz@rock-chips.com> Cc: Baoyou Xie <baoyou.xie@linaro.org> Cc: Boris Brezillon <boris.brezillon@free-electrons.com> Reviewed-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20170725080122.20548-8-daniel.vetter@ffwll.ch Acked-by: Neil Armstrong <narmstrong@baylibre.com> Reviewed-by: Neil Armstrong <narmstrong@baylibre.com> Acked-by: Philipp Zabel <p.zabel@pengutronix.de> Acked-by: Archit Taneja <architt@codeaurora.org> Tested-by: Philippe Cornu <philippe.cornu@st.com> (on stm) Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Acked-by: Shawn Guo <shawnguo@kernel.org> Acked-by: Shawn Guo <shawnguo@kernel.org> Acked-by: Noralf Trønnes <noralf@tronnes.org> Acked-by: Vincent Abriou <vincent.abriou@st.com>
445 lines
11 KiB
C
445 lines
11 KiB
C
/*
|
|
* Copyright (C) 2012 Texas Instruments
|
|
* Author: Rob Clark <robdclark@gmail.com>
|
|
*
|
|
* 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.
|
|
*
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
* more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along with
|
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include <linux/pinctrl/pinmux.h>
|
|
#include <linux/pinctrl/consumer.h>
|
|
#include <linux/backlight.h>
|
|
#include <linux/gpio/consumer.h>
|
|
#include <video/display_timing.h>
|
|
#include <video/of_display_timing.h>
|
|
#include <video/videomode.h>
|
|
#include <drm/drm_atomic_helper.h>
|
|
|
|
#include "tilcdc_drv.h"
|
|
#include "tilcdc_panel.h"
|
|
|
|
struct panel_module {
|
|
struct tilcdc_module base;
|
|
struct tilcdc_panel_info *info;
|
|
struct display_timings *timings;
|
|
struct backlight_device *backlight;
|
|
struct gpio_desc *enable_gpio;
|
|
};
|
|
#define to_panel_module(x) container_of(x, struct panel_module, base)
|
|
|
|
|
|
/*
|
|
* Encoder:
|
|
*/
|
|
|
|
struct panel_encoder {
|
|
struct drm_encoder base;
|
|
struct panel_module *mod;
|
|
};
|
|
#define to_panel_encoder(x) container_of(x, struct panel_encoder, base)
|
|
|
|
static void panel_encoder_dpms(struct drm_encoder *encoder, int mode)
|
|
{
|
|
struct panel_encoder *panel_encoder = to_panel_encoder(encoder);
|
|
struct backlight_device *backlight = panel_encoder->mod->backlight;
|
|
struct gpio_desc *gpio = panel_encoder->mod->enable_gpio;
|
|
|
|
if (backlight) {
|
|
backlight->props.power = mode == DRM_MODE_DPMS_ON ?
|
|
FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN;
|
|
backlight_update_status(backlight);
|
|
}
|
|
|
|
if (gpio)
|
|
gpiod_set_value_cansleep(gpio,
|
|
mode == DRM_MODE_DPMS_ON ? 1 : 0);
|
|
}
|
|
|
|
static void panel_encoder_prepare(struct drm_encoder *encoder)
|
|
{
|
|
panel_encoder_dpms(encoder, DRM_MODE_DPMS_OFF);
|
|
}
|
|
|
|
static void panel_encoder_commit(struct drm_encoder *encoder)
|
|
{
|
|
panel_encoder_dpms(encoder, DRM_MODE_DPMS_ON);
|
|
}
|
|
|
|
static void panel_encoder_mode_set(struct drm_encoder *encoder,
|
|
struct drm_display_mode *mode,
|
|
struct drm_display_mode *adjusted_mode)
|
|
{
|
|
/* nothing needed */
|
|
}
|
|
|
|
static const struct drm_encoder_funcs panel_encoder_funcs = {
|
|
.destroy = drm_encoder_cleanup,
|
|
};
|
|
|
|
static const struct drm_encoder_helper_funcs panel_encoder_helper_funcs = {
|
|
.dpms = panel_encoder_dpms,
|
|
.prepare = panel_encoder_prepare,
|
|
.commit = panel_encoder_commit,
|
|
.mode_set = panel_encoder_mode_set,
|
|
};
|
|
|
|
static struct drm_encoder *panel_encoder_create(struct drm_device *dev,
|
|
struct panel_module *mod)
|
|
{
|
|
struct panel_encoder *panel_encoder;
|
|
struct drm_encoder *encoder;
|
|
int ret;
|
|
|
|
panel_encoder = devm_kzalloc(dev->dev, sizeof(*panel_encoder),
|
|
GFP_KERNEL);
|
|
if (!panel_encoder) {
|
|
dev_err(dev->dev, "allocation failed\n");
|
|
return NULL;
|
|
}
|
|
|
|
panel_encoder->mod = mod;
|
|
|
|
encoder = &panel_encoder->base;
|
|
encoder->possible_crtcs = 1;
|
|
|
|
ret = drm_encoder_init(dev, encoder, &panel_encoder_funcs,
|
|
DRM_MODE_ENCODER_LVDS, NULL);
|
|
if (ret < 0)
|
|
goto fail;
|
|
|
|
drm_encoder_helper_add(encoder, &panel_encoder_helper_funcs);
|
|
|
|
return encoder;
|
|
|
|
fail:
|
|
drm_encoder_cleanup(encoder);
|
|
return NULL;
|
|
}
|
|
|
|
/*
|
|
* Connector:
|
|
*/
|
|
|
|
struct panel_connector {
|
|
struct drm_connector base;
|
|
|
|
struct drm_encoder *encoder; /* our connected encoder */
|
|
struct panel_module *mod;
|
|
};
|
|
#define to_panel_connector(x) container_of(x, struct panel_connector, base)
|
|
|
|
|
|
static void panel_connector_destroy(struct drm_connector *connector)
|
|
{
|
|
drm_connector_unregister(connector);
|
|
drm_connector_cleanup(connector);
|
|
}
|
|
|
|
static int panel_connector_get_modes(struct drm_connector *connector)
|
|
{
|
|
struct drm_device *dev = connector->dev;
|
|
struct panel_connector *panel_connector = to_panel_connector(connector);
|
|
struct display_timings *timings = panel_connector->mod->timings;
|
|
int i;
|
|
|
|
for (i = 0; i < timings->num_timings; i++) {
|
|
struct drm_display_mode *mode = drm_mode_create(dev);
|
|
struct videomode vm;
|
|
|
|
if (videomode_from_timings(timings, &vm, i))
|
|
break;
|
|
|
|
drm_display_mode_from_videomode(&vm, mode);
|
|
|
|
mode->type = DRM_MODE_TYPE_DRIVER;
|
|
|
|
if (timings->native_mode == i)
|
|
mode->type |= DRM_MODE_TYPE_PREFERRED;
|
|
|
|
drm_mode_set_name(mode);
|
|
drm_mode_probed_add(connector, mode);
|
|
}
|
|
|
|
return i;
|
|
}
|
|
|
|
static int panel_connector_mode_valid(struct drm_connector *connector,
|
|
struct drm_display_mode *mode)
|
|
{
|
|
struct tilcdc_drm_private *priv = connector->dev->dev_private;
|
|
/* our only constraints are what the crtc can generate: */
|
|
return tilcdc_crtc_mode_valid(priv->crtc, mode);
|
|
}
|
|
|
|
static struct drm_encoder *panel_connector_best_encoder(
|
|
struct drm_connector *connector)
|
|
{
|
|
struct panel_connector *panel_connector = to_panel_connector(connector);
|
|
return panel_connector->encoder;
|
|
}
|
|
|
|
static const struct drm_connector_funcs panel_connector_funcs = {
|
|
.destroy = panel_connector_destroy,
|
|
.fill_modes = drm_helper_probe_single_connector_modes,
|
|
.reset = drm_atomic_helper_connector_reset,
|
|
.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
|
|
.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
|
|
};
|
|
|
|
static const struct drm_connector_helper_funcs panel_connector_helper_funcs = {
|
|
.get_modes = panel_connector_get_modes,
|
|
.mode_valid = panel_connector_mode_valid,
|
|
.best_encoder = panel_connector_best_encoder,
|
|
};
|
|
|
|
static struct drm_connector *panel_connector_create(struct drm_device *dev,
|
|
struct panel_module *mod, struct drm_encoder *encoder)
|
|
{
|
|
struct panel_connector *panel_connector;
|
|
struct drm_connector *connector;
|
|
int ret;
|
|
|
|
panel_connector = devm_kzalloc(dev->dev, sizeof(*panel_connector),
|
|
GFP_KERNEL);
|
|
if (!panel_connector) {
|
|
dev_err(dev->dev, "allocation failed\n");
|
|
return NULL;
|
|
}
|
|
|
|
panel_connector->encoder = encoder;
|
|
panel_connector->mod = mod;
|
|
|
|
connector = &panel_connector->base;
|
|
|
|
drm_connector_init(dev, connector, &panel_connector_funcs,
|
|
DRM_MODE_CONNECTOR_LVDS);
|
|
drm_connector_helper_add(connector, &panel_connector_helper_funcs);
|
|
|
|
connector->interlace_allowed = 0;
|
|
connector->doublescan_allowed = 0;
|
|
|
|
ret = drm_mode_connector_attach_encoder(connector, encoder);
|
|
if (ret)
|
|
goto fail;
|
|
|
|
return connector;
|
|
|
|
fail:
|
|
panel_connector_destroy(connector);
|
|
return NULL;
|
|
}
|
|
|
|
/*
|
|
* Module:
|
|
*/
|
|
|
|
static int panel_modeset_init(struct tilcdc_module *mod, struct drm_device *dev)
|
|
{
|
|
struct panel_module *panel_mod = to_panel_module(mod);
|
|
struct tilcdc_drm_private *priv = dev->dev_private;
|
|
struct drm_encoder *encoder;
|
|
struct drm_connector *connector;
|
|
|
|
encoder = panel_encoder_create(dev, panel_mod);
|
|
if (!encoder)
|
|
return -ENOMEM;
|
|
|
|
connector = panel_connector_create(dev, panel_mod, encoder);
|
|
if (!connector)
|
|
return -ENOMEM;
|
|
|
|
priv->encoders[priv->num_encoders++] = encoder;
|
|
priv->connectors[priv->num_connectors++] = connector;
|
|
|
|
tilcdc_crtc_set_panel_info(priv->crtc,
|
|
to_panel_encoder(encoder)->mod->info);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static const struct tilcdc_module_ops panel_module_ops = {
|
|
.modeset_init = panel_modeset_init,
|
|
};
|
|
|
|
/*
|
|
* Device:
|
|
*/
|
|
|
|
/* maybe move this somewhere common if it is needed by other outputs? */
|
|
static struct tilcdc_panel_info *of_get_panel_info(struct device_node *np)
|
|
{
|
|
struct device_node *info_np;
|
|
struct tilcdc_panel_info *info;
|
|
int ret = 0;
|
|
|
|
if (!np) {
|
|
pr_err("%s: no devicenode given\n", __func__);
|
|
return NULL;
|
|
}
|
|
|
|
info_np = of_get_child_by_name(np, "panel-info");
|
|
if (!info_np) {
|
|
pr_err("%s: could not find panel-info node\n", __func__);
|
|
return NULL;
|
|
}
|
|
|
|
info = kzalloc(sizeof(*info), GFP_KERNEL);
|
|
if (!info) {
|
|
pr_err("%s: allocation failed\n", __func__);
|
|
of_node_put(info_np);
|
|
return NULL;
|
|
}
|
|
|
|
ret |= of_property_read_u32(info_np, "ac-bias", &info->ac_bias);
|
|
ret |= of_property_read_u32(info_np, "ac-bias-intrpt", &info->ac_bias_intrpt);
|
|
ret |= of_property_read_u32(info_np, "dma-burst-sz", &info->dma_burst_sz);
|
|
ret |= of_property_read_u32(info_np, "bpp", &info->bpp);
|
|
ret |= of_property_read_u32(info_np, "fdd", &info->fdd);
|
|
ret |= of_property_read_u32(info_np, "sync-edge", &info->sync_edge);
|
|
ret |= of_property_read_u32(info_np, "sync-ctrl", &info->sync_ctrl);
|
|
ret |= of_property_read_u32(info_np, "raster-order", &info->raster_order);
|
|
ret |= of_property_read_u32(info_np, "fifo-th", &info->fifo_th);
|
|
|
|
/* optional: */
|
|
info->tft_alt_mode = of_property_read_bool(info_np, "tft-alt-mode");
|
|
info->invert_pxl_clk = of_property_read_bool(info_np, "invert-pxl-clk");
|
|
|
|
if (ret) {
|
|
pr_err("%s: error reading panel-info properties\n", __func__);
|
|
kfree(info);
|
|
of_node_put(info_np);
|
|
return NULL;
|
|
}
|
|
of_node_put(info_np);
|
|
|
|
return info;
|
|
}
|
|
|
|
static int panel_probe(struct platform_device *pdev)
|
|
{
|
|
struct device_node *bl_node, *node = pdev->dev.of_node;
|
|
struct panel_module *panel_mod;
|
|
struct tilcdc_module *mod;
|
|
struct pinctrl *pinctrl;
|
|
int ret;
|
|
|
|
/* bail out early if no DT data: */
|
|
if (!node) {
|
|
dev_err(&pdev->dev, "device-tree data is missing\n");
|
|
return -ENXIO;
|
|
}
|
|
|
|
panel_mod = devm_kzalloc(&pdev->dev, sizeof(*panel_mod), GFP_KERNEL);
|
|
if (!panel_mod)
|
|
return -ENOMEM;
|
|
|
|
bl_node = of_parse_phandle(node, "backlight", 0);
|
|
if (bl_node) {
|
|
panel_mod->backlight = of_find_backlight_by_node(bl_node);
|
|
of_node_put(bl_node);
|
|
|
|
if (!panel_mod->backlight)
|
|
return -EPROBE_DEFER;
|
|
|
|
dev_info(&pdev->dev, "found backlight\n");
|
|
}
|
|
|
|
panel_mod->enable_gpio = devm_gpiod_get_optional(&pdev->dev, "enable",
|
|
GPIOD_OUT_LOW);
|
|
if (IS_ERR(panel_mod->enable_gpio)) {
|
|
ret = PTR_ERR(panel_mod->enable_gpio);
|
|
dev_err(&pdev->dev, "failed to request enable GPIO\n");
|
|
goto fail_backlight;
|
|
}
|
|
|
|
if (panel_mod->enable_gpio)
|
|
dev_info(&pdev->dev, "found enable GPIO\n");
|
|
|
|
mod = &panel_mod->base;
|
|
pdev->dev.platform_data = mod;
|
|
|
|
tilcdc_module_init(mod, "panel", &panel_module_ops);
|
|
|
|
pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
|
|
if (IS_ERR(pinctrl))
|
|
dev_warn(&pdev->dev, "pins are not configured\n");
|
|
|
|
panel_mod->timings = of_get_display_timings(node);
|
|
if (!panel_mod->timings) {
|
|
dev_err(&pdev->dev, "could not get panel timings\n");
|
|
ret = -EINVAL;
|
|
goto fail_free;
|
|
}
|
|
|
|
panel_mod->info = of_get_panel_info(node);
|
|
if (!panel_mod->info) {
|
|
dev_err(&pdev->dev, "could not get panel info\n");
|
|
ret = -EINVAL;
|
|
goto fail_timings;
|
|
}
|
|
|
|
return 0;
|
|
|
|
fail_timings:
|
|
display_timings_release(panel_mod->timings);
|
|
|
|
fail_free:
|
|
tilcdc_module_cleanup(mod);
|
|
|
|
fail_backlight:
|
|
if (panel_mod->backlight)
|
|
put_device(&panel_mod->backlight->dev);
|
|
return ret;
|
|
}
|
|
|
|
static int panel_remove(struct platform_device *pdev)
|
|
{
|
|
struct tilcdc_module *mod = dev_get_platdata(&pdev->dev);
|
|
struct panel_module *panel_mod = to_panel_module(mod);
|
|
struct backlight_device *backlight = panel_mod->backlight;
|
|
|
|
if (backlight)
|
|
put_device(&backlight->dev);
|
|
|
|
display_timings_release(panel_mod->timings);
|
|
|
|
tilcdc_module_cleanup(mod);
|
|
kfree(panel_mod->info);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static struct of_device_id panel_of_match[] = {
|
|
{ .compatible = "ti,tilcdc,panel", },
|
|
{ },
|
|
};
|
|
|
|
struct platform_driver panel_driver = {
|
|
.probe = panel_probe,
|
|
.remove = panel_remove,
|
|
.driver = {
|
|
.owner = THIS_MODULE,
|
|
.name = "panel",
|
|
.of_match_table = panel_of_match,
|
|
},
|
|
};
|
|
|
|
int __init tilcdc_panel_init(void)
|
|
{
|
|
return platform_driver_register(&panel_driver);
|
|
}
|
|
|
|
void __exit tilcdc_panel_fini(void)
|
|
{
|
|
platform_driver_unregister(&panel_driver);
|
|
}
|