![Neil Armstrong](/assets/img/avatar_default.png)
The Amlogic Meson Display controller is composed of several components : DMC|---------------VPU (Video Processing Unit)----------------|------HHI------| | vd1 _______ _____________ _________________ | | D |-------| |----| | | | | HDMI PLL | D | vd2 | VIU | | Video Post | | Video Encoders |<---|-----VCLK | R |-------| |----| Processing | | | | | | osd2 | | | |---| Enci ----------|----|-----VDAC------| R |-------| CSC |----| Scalers | | Encp ----------|----|----HDMI-TX----| A | osd1 | | | Blenders | | Encl ----------|----|---------------| M |-------|______|----|____________| |________________| | | ___|__________________________________________________________|_______________| VIU: Video Input Unit --------------------- The Video Input Unit is in charge of the pixel scanout from the DDR memory. It fetches the frames addresses, stride and parameters from the "Canvas" memory. This part is also in charge of the CSC (Colorspace Conversion). It can handle 2 OSD Planes and 2 Video Planes. VPP: Video Post Processing -------------------------- The Video Post Processing is in charge of the scaling and blending of the various planes into a single pixel stream. There is a special "pre-blending" used by the video planes with a dedicated scaler and a "post-blending" to merge with the OSD Planes. The OSD planes also have a dedicated scaler for one of the OSD. VENC: Video Encoders -------------------- The VENC is composed of the multiple pixel encoders : - ENCI : Interlace Video encoder for CVBS and Interlace HDMI - ENCP : Progressive Video Encoder for HDMI - ENCL : LCD LVDS Encoder The VENC Unit gets a Pixel Clocks (VCLK) from a dedicated HDMI PLL and clock tree and provides the scanout clock to the VPP and VIU. The ENCI is connected to a single VDAC for Composite Output. The ENCI and ENCP are connected to an on-chip HDMI Transceiver. This driver is a DRM/KMS driver using the following DRM components : - GEM-CMA - PRIME-CMA - Atomic Modesetting - FBDev-CMA For the following SoCs : - GXBB Family (S905) - GXL Family (S905X, S905D) - GXM Family (S912) The current driver only supports the CVBS PAL/NTSC output modes, but the CRTC/Planes management should support bigger modes. But Advanced Colorspace Conversion, Scaling and HDMI Modes will be added in a second time. The Device Tree bindings makes use of the endpoints video interface definitions to connect to the optional CVBS and in the future the HDMI Connector nodes. HDMI Support is planned for a next release. Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch> Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
168 lines
6 KiB
C
168 lines
6 KiB
C
/*
|
|
* Copyright (C) 2016 BayLibre, SAS
|
|
* Author: Neil Armstrong <narmstrong@baylibre.com>
|
|
* Copyright (C) 2015 Amlogic, Inc. 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 as
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
* License, or (at your option) any later version.
|
|
*
|
|
* 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/kernel.h>
|
|
#include <linux/module.h>
|
|
#include <drm/drmP.h>
|
|
#include "meson_drv.h"
|
|
#include "meson_vclk.h"
|
|
|
|
/*
|
|
* VCLK is the "Pixel Clock" frequency generator from a dedicated PLL.
|
|
* We handle the following encodings :
|
|
* - CVBS 27MHz generator via the VCLK2 to the VENCI and VDAC blocks
|
|
*
|
|
* What is missing :
|
|
* - HDMI Pixel Clocks generation
|
|
*/
|
|
|
|
/* HHI Registers */
|
|
#define HHI_VID_PLL_CLK_DIV 0x1a0 /* 0x68 offset in data sheet */
|
|
#define VID_PLL_EN BIT(19)
|
|
#define VID_PLL_BYPASS BIT(18)
|
|
#define VID_PLL_PRESET BIT(15)
|
|
#define HHI_VIID_CLK_DIV 0x128 /* 0x4a offset in data sheet */
|
|
#define VCLK2_DIV_MASK 0xff
|
|
#define VCLK2_DIV_EN BIT(16)
|
|
#define VCLK2_DIV_RESET BIT(17)
|
|
#define CTS_VDAC_SEL_MASK (0xf << 28)
|
|
#define CTS_VDAC_SEL_SHIFT 28
|
|
#define HHI_VIID_CLK_CNTL 0x12c /* 0x4b offset in data sheet */
|
|
#define VCLK2_EN BIT(19)
|
|
#define VCLK2_SEL_MASK (0x7 << 16)
|
|
#define VCLK2_SEL_SHIFT 16
|
|
#define VCLK2_SOFT_RESET BIT(15)
|
|
#define VCLK2_DIV1_EN BIT(0)
|
|
#define HHI_VID_CLK_DIV 0x164 /* 0x59 offset in data sheet */
|
|
#define CTS_ENCI_SEL_MASK (0xf << 28)
|
|
#define CTS_ENCI_SEL_SHIFT 28
|
|
#define HHI_VID_CLK_CNTL2 0x194 /* 0x65 offset in data sheet */
|
|
#define CTS_ENCI_EN BIT(0)
|
|
#define CTS_VDAC_EN BIT(4)
|
|
|
|
#define HHI_VDAC_CNTL0 0x2F4 /* 0xbd offset in data sheet */
|
|
#define HHI_VDAC_CNTL1 0x2F8 /* 0xbe offset in data sheet */
|
|
|
|
#define HHI_HDMI_PLL_CNTL 0x320 /* 0xc8 offset in data sheet */
|
|
#define HHI_HDMI_PLL_CNTL2 0x324 /* 0xc9 offset in data sheet */
|
|
#define HHI_HDMI_PLL_CNTL3 0x328 /* 0xca offset in data sheet */
|
|
#define HHI_HDMI_PLL_CNTL4 0x32C /* 0xcb offset in data sheet */
|
|
#define HHI_HDMI_PLL_CNTL5 0x330 /* 0xcc offset in data sheet */
|
|
#define HHI_HDMI_PLL_CNTL6 0x334 /* 0xcd offset in data sheet */
|
|
|
|
#define HDMI_PLL_RESET BIT(28)
|
|
#define HDMI_PLL_LOCK BIT(31)
|
|
|
|
/*
|
|
* Setup VCLK2 for 27MHz, and enable clocks for ENCI and VDAC
|
|
*
|
|
* TOFIX: Refactor into table to also handle HDMI frequency and paths
|
|
*/
|
|
static void meson_venci_cvbs_clock_config(struct meson_drm *priv)
|
|
{
|
|
unsigned int val;
|
|
|
|
/* Setup PLL to output 1.485GHz */
|
|
if (meson_vpu_is_compatible(priv, "amlogic,meson-gxbb-vpu")) {
|
|
regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL, 0x5800023d);
|
|
regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL2, 0x00404e00);
|
|
regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL3, 0x0d5c5091);
|
|
regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL4, 0x801da72c);
|
|
regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL5, 0x71486980);
|
|
regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL6, 0x00000e55);
|
|
regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL, 0x4800023d);
|
|
} else if (meson_vpu_is_compatible(priv, "amlogic,meson-gxm-vpu") ||
|
|
meson_vpu_is_compatible(priv, "amlogic,meson-gxl-vpu")) {
|
|
regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL, 0x4000027b);
|
|
regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL2, 0x800cb300);
|
|
regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL3, 0xa6212844);
|
|
regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL4, 0x0c4d000c);
|
|
regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL5, 0x001fa729);
|
|
regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL6, 0x01a31500);
|
|
|
|
/* Reset PLL */
|
|
regmap_update_bits(priv->hhi, HHI_HDMI_PLL_CNTL,
|
|
HDMI_PLL_RESET, HDMI_PLL_RESET);
|
|
regmap_update_bits(priv->hhi, HHI_HDMI_PLL_CNTL,
|
|
HDMI_PLL_RESET, 0);
|
|
}
|
|
|
|
/* Poll for lock bit */
|
|
regmap_read_poll_timeout(priv->hhi, HHI_HDMI_PLL_CNTL, val,
|
|
(val & HDMI_PLL_LOCK), 10, 0);
|
|
|
|
/* Disable VCLK2 */
|
|
regmap_update_bits(priv->hhi, HHI_VIID_CLK_CNTL, VCLK2_EN, 0);
|
|
|
|
/* Disable vid_pll output clock */
|
|
regmap_update_bits(priv->hhi, HHI_VID_PLL_CLK_DIV, VID_PLL_EN, 0);
|
|
regmap_update_bits(priv->hhi, HHI_VID_PLL_CLK_DIV, VID_PLL_PRESET, 0);
|
|
/* Enable vid_pll bypass to HDMI pll */
|
|
regmap_update_bits(priv->hhi, HHI_VID_PLL_CLK_DIV,
|
|
VID_PLL_BYPASS, VID_PLL_BYPASS);
|
|
/* Enable the vid_pll output clock */
|
|
regmap_update_bits(priv->hhi, HHI_VID_PLL_CLK_DIV,
|
|
VID_PLL_EN, VID_PLL_EN);
|
|
|
|
/* Setup the VCLK2 divider value to achieve 27MHz */
|
|
regmap_update_bits(priv->hhi, HHI_VIID_CLK_DIV,
|
|
VCLK2_DIV_MASK, (55 - 1));
|
|
|
|
/* select vid_pll for vclk2 */
|
|
regmap_update_bits(priv->hhi, HHI_VIID_CLK_CNTL,
|
|
VCLK2_SEL_MASK, (4 << VCLK2_SEL_SHIFT));
|
|
/* enable vclk2 gate */
|
|
regmap_update_bits(priv->hhi, HHI_VIID_CLK_CNTL, VCLK2_EN, VCLK2_EN);
|
|
|
|
/* select vclk_div1 for enci */
|
|
regmap_update_bits(priv->hhi, HHI_VID_CLK_DIV,
|
|
CTS_ENCI_SEL_MASK, (8 << CTS_ENCI_SEL_SHIFT));
|
|
/* select vclk_div1 for vdac */
|
|
regmap_update_bits(priv->hhi, HHI_VIID_CLK_DIV,
|
|
CTS_VDAC_SEL_MASK, (8 << CTS_VDAC_SEL_SHIFT));
|
|
|
|
/* release vclk2_div_reset and enable vclk2_div */
|
|
regmap_update_bits(priv->hhi, HHI_VIID_CLK_DIV,
|
|
VCLK2_DIV_EN | VCLK2_DIV_RESET, VCLK2_DIV_EN);
|
|
|
|
/* enable vclk2_div1 gate */
|
|
regmap_update_bits(priv->hhi, HHI_VIID_CLK_CNTL,
|
|
VCLK2_DIV1_EN, VCLK2_DIV1_EN);
|
|
|
|
/* reset vclk2 */
|
|
regmap_update_bits(priv->hhi, HHI_VIID_CLK_CNTL,
|
|
VCLK2_SOFT_RESET, VCLK2_SOFT_RESET);
|
|
regmap_update_bits(priv->hhi, HHI_VIID_CLK_CNTL,
|
|
VCLK2_SOFT_RESET, 0);
|
|
|
|
/* enable enci_clk */
|
|
regmap_update_bits(priv->hhi, HHI_VID_CLK_CNTL2,
|
|
CTS_ENCI_EN, CTS_ENCI_EN);
|
|
/* enable vdac_clk */
|
|
regmap_update_bits(priv->hhi, HHI_VID_CLK_CNTL2,
|
|
CTS_VDAC_EN, CTS_VDAC_EN);
|
|
}
|
|
|
|
void meson_vclk_setup(struct meson_drm *priv, unsigned int target,
|
|
unsigned int freq)
|
|
{
|
|
if (target == MESON_VCLK_TARGET_CVBS && freq == MESON_VCLK_CVBS)
|
|
meson_venci_cvbs_clock_config(priv);
|
|
}
|