forked from Minki/linux
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>
319 lines
9.1 KiB
C
319 lines
9.1 KiB
C
/*
|
|
* 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.
|
|
*/
|
|
|
|
#include <linux/clk.h>
|
|
|
|
#include <drm/drm_atomic_helper.h>
|
|
#include <drm/drm_panel.h>
|
|
|
|
#include "drm.h"
|
|
#include "dc.h"
|
|
|
|
struct tegra_rgb {
|
|
struct tegra_output output;
|
|
struct tegra_dc *dc;
|
|
|
|
struct clk *clk_parent;
|
|
struct clk *clk;
|
|
};
|
|
|
|
static inline struct tegra_rgb *to_rgb(struct tegra_output *output)
|
|
{
|
|
return container_of(output, struct tegra_rgb, output);
|
|
}
|
|
|
|
struct reg_entry {
|
|
unsigned long offset;
|
|
unsigned long value;
|
|
};
|
|
|
|
static const struct reg_entry rgb_enable[] = {
|
|
{ DC_COM_PIN_OUTPUT_ENABLE(0), 0x00000000 },
|
|
{ DC_COM_PIN_OUTPUT_ENABLE(1), 0x00000000 },
|
|
{ DC_COM_PIN_OUTPUT_ENABLE(2), 0x00000000 },
|
|
{ DC_COM_PIN_OUTPUT_ENABLE(3), 0x00000000 },
|
|
{ DC_COM_PIN_OUTPUT_POLARITY(0), 0x00000000 },
|
|
{ DC_COM_PIN_OUTPUT_POLARITY(1), 0x01000000 },
|
|
{ DC_COM_PIN_OUTPUT_POLARITY(2), 0x00000000 },
|
|
{ DC_COM_PIN_OUTPUT_POLARITY(3), 0x00000000 },
|
|
{ DC_COM_PIN_OUTPUT_DATA(0), 0x00000000 },
|
|
{ DC_COM_PIN_OUTPUT_DATA(1), 0x00000000 },
|
|
{ DC_COM_PIN_OUTPUT_DATA(2), 0x00000000 },
|
|
{ DC_COM_PIN_OUTPUT_DATA(3), 0x00000000 },
|
|
{ DC_COM_PIN_OUTPUT_SELECT(0), 0x00000000 },
|
|
{ DC_COM_PIN_OUTPUT_SELECT(1), 0x00000000 },
|
|
{ DC_COM_PIN_OUTPUT_SELECT(2), 0x00000000 },
|
|
{ DC_COM_PIN_OUTPUT_SELECT(3), 0x00000000 },
|
|
{ DC_COM_PIN_OUTPUT_SELECT(4), 0x00210222 },
|
|
{ DC_COM_PIN_OUTPUT_SELECT(5), 0x00002200 },
|
|
{ DC_COM_PIN_OUTPUT_SELECT(6), 0x00020000 },
|
|
};
|
|
|
|
static const struct reg_entry rgb_disable[] = {
|
|
{ DC_COM_PIN_OUTPUT_SELECT(6), 0x00000000 },
|
|
{ DC_COM_PIN_OUTPUT_SELECT(5), 0x00000000 },
|
|
{ DC_COM_PIN_OUTPUT_SELECT(4), 0x00000000 },
|
|
{ DC_COM_PIN_OUTPUT_SELECT(3), 0x00000000 },
|
|
{ DC_COM_PIN_OUTPUT_SELECT(2), 0x00000000 },
|
|
{ DC_COM_PIN_OUTPUT_SELECT(1), 0x00000000 },
|
|
{ DC_COM_PIN_OUTPUT_SELECT(0), 0x00000000 },
|
|
{ DC_COM_PIN_OUTPUT_DATA(3), 0xaaaaaaaa },
|
|
{ DC_COM_PIN_OUTPUT_DATA(2), 0xaaaaaaaa },
|
|
{ DC_COM_PIN_OUTPUT_DATA(1), 0xaaaaaaaa },
|
|
{ DC_COM_PIN_OUTPUT_DATA(0), 0xaaaaaaaa },
|
|
{ DC_COM_PIN_OUTPUT_POLARITY(3), 0x00000000 },
|
|
{ DC_COM_PIN_OUTPUT_POLARITY(2), 0x00000000 },
|
|
{ DC_COM_PIN_OUTPUT_POLARITY(1), 0x00000000 },
|
|
{ DC_COM_PIN_OUTPUT_POLARITY(0), 0x00000000 },
|
|
{ DC_COM_PIN_OUTPUT_ENABLE(3), 0x55555555 },
|
|
{ DC_COM_PIN_OUTPUT_ENABLE(2), 0x55555555 },
|
|
{ DC_COM_PIN_OUTPUT_ENABLE(1), 0x55150005 },
|
|
{ DC_COM_PIN_OUTPUT_ENABLE(0), 0x55555555 },
|
|
};
|
|
|
|
static void tegra_dc_write_regs(struct tegra_dc *dc,
|
|
const struct reg_entry *table,
|
|
unsigned int num)
|
|
{
|
|
unsigned int i;
|
|
|
|
for (i = 0; i < num; i++)
|
|
tegra_dc_writel(dc, table[i].value, table[i].offset);
|
|
}
|
|
|
|
static const struct drm_connector_funcs tegra_rgb_connector_funcs = {
|
|
.reset = drm_atomic_helper_connector_reset,
|
|
.detect = tegra_output_connector_detect,
|
|
.fill_modes = drm_helper_probe_single_connector_modes,
|
|
.destroy = tegra_output_connector_destroy,
|
|
.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
|
|
.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
|
|
};
|
|
|
|
static enum drm_mode_status
|
|
tegra_rgb_connector_mode_valid(struct drm_connector *connector,
|
|
struct drm_display_mode *mode)
|
|
{
|
|
/*
|
|
* FIXME: For now, always assume that the mode is okay. There are
|
|
* unresolved issues with clk_round_rate(), which doesn't always
|
|
* reliably report whether a frequency can be set or not.
|
|
*/
|
|
return MODE_OK;
|
|
}
|
|
|
|
static const struct drm_connector_helper_funcs tegra_rgb_connector_helper_funcs = {
|
|
.get_modes = tegra_output_connector_get_modes,
|
|
.mode_valid = tegra_rgb_connector_mode_valid,
|
|
};
|
|
|
|
static const struct drm_encoder_funcs tegra_rgb_encoder_funcs = {
|
|
.destroy = tegra_output_encoder_destroy,
|
|
};
|
|
|
|
static void tegra_rgb_encoder_disable(struct drm_encoder *encoder)
|
|
{
|
|
struct tegra_output *output = encoder_to_output(encoder);
|
|
struct tegra_rgb *rgb = to_rgb(output);
|
|
|
|
if (output->panel)
|
|
drm_panel_disable(output->panel);
|
|
|
|
tegra_dc_write_regs(rgb->dc, rgb_disable, ARRAY_SIZE(rgb_disable));
|
|
tegra_dc_commit(rgb->dc);
|
|
|
|
if (output->panel)
|
|
drm_panel_unprepare(output->panel);
|
|
}
|
|
|
|
static void tegra_rgb_encoder_enable(struct drm_encoder *encoder)
|
|
{
|
|
struct tegra_output *output = encoder_to_output(encoder);
|
|
struct tegra_rgb *rgb = to_rgb(output);
|
|
u32 value;
|
|
|
|
if (output->panel)
|
|
drm_panel_prepare(output->panel);
|
|
|
|
tegra_dc_write_regs(rgb->dc, rgb_enable, ARRAY_SIZE(rgb_enable));
|
|
|
|
value = DE_SELECT_ACTIVE | DE_CONTROL_NORMAL;
|
|
tegra_dc_writel(rgb->dc, value, DC_DISP_DATA_ENABLE_OPTIONS);
|
|
|
|
/* XXX: parameterize? */
|
|
value = tegra_dc_readl(rgb->dc, DC_COM_PIN_OUTPUT_POLARITY(1));
|
|
value &= ~LVS_OUTPUT_POLARITY_LOW;
|
|
value &= ~LHS_OUTPUT_POLARITY_LOW;
|
|
tegra_dc_writel(rgb->dc, value, DC_COM_PIN_OUTPUT_POLARITY(1));
|
|
|
|
/* XXX: parameterize? */
|
|
value = DISP_DATA_FORMAT_DF1P1C | DISP_ALIGNMENT_MSB |
|
|
DISP_ORDER_RED_BLUE;
|
|
tegra_dc_writel(rgb->dc, value, DC_DISP_DISP_INTERFACE_CONTROL);
|
|
|
|
/* XXX: parameterize? */
|
|
value = SC0_H_QUALIFIER_NONE | SC1_H_QUALIFIER_NONE;
|
|
tegra_dc_writel(rgb->dc, value, DC_DISP_SHIFT_CLOCK_OPTIONS);
|
|
|
|
tegra_dc_commit(rgb->dc);
|
|
|
|
if (output->panel)
|
|
drm_panel_enable(output->panel);
|
|
}
|
|
|
|
static int
|
|
tegra_rgb_encoder_atomic_check(struct drm_encoder *encoder,
|
|
struct drm_crtc_state *crtc_state,
|
|
struct drm_connector_state *conn_state)
|
|
{
|
|
struct tegra_output *output = encoder_to_output(encoder);
|
|
struct tegra_dc *dc = to_tegra_dc(conn_state->crtc);
|
|
unsigned long pclk = crtc_state->mode.clock * 1000;
|
|
struct tegra_rgb *rgb = to_rgb(output);
|
|
unsigned int div;
|
|
int err;
|
|
|
|
/*
|
|
* We may not want to change the frequency of the parent clock, since
|
|
* it may be a parent for other peripherals. This is due to the fact
|
|
* that on Tegra20 there's only a single clock dedicated to display
|
|
* (pll_d_out0), whereas later generations have a second one that can
|
|
* be used to independently drive a second output (pll_d2_out0).
|
|
*
|
|
* As a way to support multiple outputs on Tegra20 as well, pll_p is
|
|
* typically used as the parent clock for the display controllers.
|
|
* But this comes at a cost: pll_p is the parent of several other
|
|
* peripherals, so its frequency shouldn't change out of the blue.
|
|
*
|
|
* The best we can do at this point is to use the shift clock divider
|
|
* and hope that the desired frequency can be matched (or at least
|
|
* matched sufficiently close that the panel will still work).
|
|
*/
|
|
div = ((clk_get_rate(rgb->clk) * 2) / pclk) - 2;
|
|
pclk = 0;
|
|
|
|
err = tegra_dc_state_setup_clock(dc, crtc_state, rgb->clk_parent,
|
|
pclk, div);
|
|
if (err < 0) {
|
|
dev_err(output->dev, "failed to setup CRTC state: %d\n", err);
|
|
return err;
|
|
}
|
|
|
|
return err;
|
|
}
|
|
|
|
static const struct drm_encoder_helper_funcs tegra_rgb_encoder_helper_funcs = {
|
|
.disable = tegra_rgb_encoder_disable,
|
|
.enable = tegra_rgb_encoder_enable,
|
|
.atomic_check = tegra_rgb_encoder_atomic_check,
|
|
};
|
|
|
|
int tegra_dc_rgb_probe(struct tegra_dc *dc)
|
|
{
|
|
struct device_node *np;
|
|
struct tegra_rgb *rgb;
|
|
int err;
|
|
|
|
np = of_get_child_by_name(dc->dev->of_node, "rgb");
|
|
if (!np || !of_device_is_available(np))
|
|
return -ENODEV;
|
|
|
|
rgb = devm_kzalloc(dc->dev, sizeof(*rgb), GFP_KERNEL);
|
|
if (!rgb)
|
|
return -ENOMEM;
|
|
|
|
rgb->output.dev = dc->dev;
|
|
rgb->output.of_node = np;
|
|
rgb->dc = dc;
|
|
|
|
err = tegra_output_probe(&rgb->output);
|
|
if (err < 0)
|
|
return err;
|
|
|
|
rgb->clk = devm_clk_get(dc->dev, NULL);
|
|
if (IS_ERR(rgb->clk)) {
|
|
dev_err(dc->dev, "failed to get clock\n");
|
|
return PTR_ERR(rgb->clk);
|
|
}
|
|
|
|
rgb->clk_parent = devm_clk_get(dc->dev, "parent");
|
|
if (IS_ERR(rgb->clk_parent)) {
|
|
dev_err(dc->dev, "failed to get parent clock\n");
|
|
return PTR_ERR(rgb->clk_parent);
|
|
}
|
|
|
|
err = clk_set_parent(rgb->clk, rgb->clk_parent);
|
|
if (err < 0) {
|
|
dev_err(dc->dev, "failed to set parent clock: %d\n", err);
|
|
return err;
|
|
}
|
|
|
|
dc->rgb = &rgb->output;
|
|
|
|
return 0;
|
|
}
|
|
|
|
int tegra_dc_rgb_remove(struct tegra_dc *dc)
|
|
{
|
|
if (!dc->rgb)
|
|
return 0;
|
|
|
|
tegra_output_remove(dc->rgb);
|
|
dc->rgb = NULL;
|
|
|
|
return 0;
|
|
}
|
|
|
|
int tegra_dc_rgb_init(struct drm_device *drm, struct tegra_dc *dc)
|
|
{
|
|
struct tegra_output *output = dc->rgb;
|
|
int err;
|
|
|
|
if (!dc->rgb)
|
|
return -ENODEV;
|
|
|
|
drm_connector_init(drm, &output->connector, &tegra_rgb_connector_funcs,
|
|
DRM_MODE_CONNECTOR_LVDS);
|
|
drm_connector_helper_add(&output->connector,
|
|
&tegra_rgb_connector_helper_funcs);
|
|
output->connector.dpms = DRM_MODE_DPMS_OFF;
|
|
|
|
drm_encoder_init(drm, &output->encoder, &tegra_rgb_encoder_funcs,
|
|
DRM_MODE_ENCODER_LVDS, NULL);
|
|
drm_encoder_helper_add(&output->encoder,
|
|
&tegra_rgb_encoder_helper_funcs);
|
|
|
|
drm_mode_connector_attach_encoder(&output->connector,
|
|
&output->encoder);
|
|
drm_connector_register(&output->connector);
|
|
|
|
err = tegra_output_init(drm, output);
|
|
if (err < 0) {
|
|
dev_err(output->dev, "failed to initialize output: %d\n", err);
|
|
return err;
|
|
}
|
|
|
|
/*
|
|
* Other outputs can be attached to either display controller. The RGB
|
|
* outputs are an exception and work only with their parent display
|
|
* controller.
|
|
*/
|
|
output->encoder.possible_crtcs = drm_crtc_mask(&dc->base);
|
|
|
|
return 0;
|
|
}
|
|
|
|
int tegra_dc_rgb_exit(struct tegra_dc *dc)
|
|
{
|
|
if (dc->rgb)
|
|
tegra_output_exit(dc->rgb);
|
|
|
|
return 0;
|
|
}
|