mirror of
https://github.com/raspberrypi/linux.git
synced 2025-12-06 10:00:17 +00:00
Add support for the RP1 VEC hardware. Signed-off-by: Nick Hollinghurst <nick.hollinghurst@raspberrypi.com> drm: rp1: rp1-vec: Allow non-standard modes with various crops Tweak sync timings in the advertised modelines. Accept other, custom modes, provided they fit within the active area of one of the existing hardware-supported TV modes. Instead of always padding symmetrically, try to respect the user's [hv]sync_start values, allowing the image to be shifted around the screen (to fine-tune overscan correction). Signed-off-by: Nick Hollinghurst <nick.hollinghurst@raspberrypi.com> drm/rp1: depends on, instead of select, MFD_RP1 According to kconfig-language.txt [1], select should be used only for "non-visible symbols ... and for symbols with no dependencies". Since MFD_RP1 both is visible and has a dependency, "select" should not be used and "depends on" should be used instead. In particular, this fixes the build of this kernel tree on NixOS, where its kernel config system will try to answer 'M' to as many config as possible. [1] https://www.kernel.org/doc/html/latest/kbuild/kconfig-language.html Signed-off-by: Ratchanan Srirattanamet <peathot@hotmail.com> drm: rp1: Use tv_mode from the command line and fix for Linux 6.6 Use the standard enum drm_connector_tv_mode instead of a private enum and switch from the legacy to the standard tv_mode property. Remove the module parameter "tv_norm". Instead, get tv_mode from the command line and make this the connector's default TV mode. Don't restrict the choice of modes based on tv_mode, but interpret nonstandard combinations as NTSC or PAL, depending on resolution. Thus the default tv_mode=NTSC effectively means "Auto". Tweak the advertised horizontal timings for 625/50 to match Rec.601 Signed-off-by: Nick Hollinghurst <nick.hollinghurst@raspberrypi.com> drm: rp1: VEC and DPI drivers: Fix bug #5901 Rework probe() to use devm_drm_dev_alloc(), embedding the DRM device in the DPI or VEC device as now seems to be recommended. Change order of resource allocation and driver initialization. This prevents it trying to write to an unmapped register during clean-up, which previously could crash. Signed-off-by: Nick Hollinghurst <nick.hollinghurst@raspberrypi.com> drm: rp1: vec: Support more video modes in the RP1 VEC driver Support a wider range of pixel clock rates. The driver will round pixclock up to 108MHz/n but tries to honour the desired image width and position (of the centre of the display relative to HSYNC_STARTs). This adds complexity but removes the need for separate 13.5MHz and 15.428MHz modes. Support "fake" double-rate progressive modes (in which only every 2nd scanline is displayed). To work around aspect ratio issues. Add Monochrome TV mode support. Add "vintage" modes (544x380i for System A; 848x738i for System E) when configured for Monochrome. Add a way to create a "custom" display mode from a module parameter. Signed-off-by: Nick Hollinghurst <nick.hollinghurst@raspberrypi.com> drm: rp1: rp1-vec: Add DRM_FORMAT_ARGB8888 and DRM_FORMAT_ABGR8888 Android requires this. As the underlying hardware doesn't support alpha blending, we ignore the alpha value. Signed-off-by: Jan Kehren <jan.kehren@emteria.com> drivers: drm: rp1-vec: Increase width limit, for PAL 16:9 @ 18MHz There was no technical reason for the DRM mode's width limit of 848; increase it to 960 (720*18MHz/13.5MHz) to support ~square pixels on 16:9 screens. Tweak the PAL active window to start slightly earlier. (The maximum number of visible columns at 18MHz is about 942.) Signed-off-by: Nick Hollinghurst <nick.hollinghurst@raspberrypi.com> drm/vc4: Make VEC progressive modes readily accessible Add predefined modelines for the 240p (NTSC) and 288p (PAL) progressive modes, and report them through vc4_vec_connector_get_modes(). Signed-off-by: Mateusz Kwiatkowski <kfyatek+publicgit@gmail.com> drm/rp1-vec: Run DRM default client setup Call drm_client_setup() to run the kernel's default client setup for DRM. Set fbdev_probe in struct drm_driver, so that the client setup can start the common fbdev client. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com> drm: rp1: Enable VEC->GPIO output; cosmetic change to registers In the VEC driver, enable mapping VEC (not DPI) to DPI GPIOs. This is to support VEC output over GPIO on Raspberry Pi CM5. It is harmless as DPI and VEC could not be used concurrently, and the output is anyway conditional on pinctrl. Also, tweak the style of VIDEO_OUT_CFG register definitions (in both DPI and VEC drivers) to be more Linux-friendly. Signed-off-by: Nick Hollinghurst <nick.hollinghurst@raspberrypi.com> drm: rp1: rp1-vec: Support 60fps in interlaced modes; other tweaks To work around the 30fps buffer-flip rate limit when using VEC's "native" interlaced modes, switch to sending individual fields to the VEC BE, using an ISR to flip between fields. When the TV mode is NTSC, change advertised progressive modes to have 263 total lines; this ameliorates colour artifacts, although it reduces the frame rate slightly from 60.05Hz to 59.83Hz. Progressive modes with 262 lines remain supported. Fix an error in equalising pulse configuration for PAL-M/PAL60. Signed-off-by: Nick Hollinghurst <nick.hollinghurst@raspberrypi.com> Fixup rp1-vec Kconfig
891 lines
23 KiB
C
891 lines
23 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* Copyright (C) 2016 Broadcom
|
|
*/
|
|
|
|
/**
|
|
* DOC: VC4 SDTV module
|
|
*
|
|
* The VEC encoder generates PAL or NTSC composite video output.
|
|
*
|
|
* TV mode selection is done by an atomic property on the encoder,
|
|
* because a drm_mode_modeinfo is insufficient to distinguish between
|
|
* PAL and PAL-M or NTSC and NTSC-J.
|
|
*/
|
|
|
|
#include <drm/drm_atomic_helper.h>
|
|
#include <drm/drm_drv.h>
|
|
#include <drm/drm_edid.h>
|
|
#include <drm/drm_panel.h>
|
|
#include <drm/drm_probe_helper.h>
|
|
#include <drm/drm_simple_kms_helper.h>
|
|
#include <linux/clk.h>
|
|
#include <linux/component.h>
|
|
#include <linux/of.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/pm_runtime.h>
|
|
|
|
#include "vc4_drv.h"
|
|
#include "vc4_regs.h"
|
|
|
|
/* WSE Registers */
|
|
#define VEC_WSE_RESET 0xc0
|
|
|
|
#define VEC_WSE_CONTROL 0xc4
|
|
#define VEC_WSE_WSS_ENABLE BIT(7)
|
|
|
|
#define VEC_WSE_WSS_DATA 0xc8
|
|
#define VEC_WSE_VPS_DATA1 0xcc
|
|
#define VEC_WSE_VPS_CONTROL 0xd0
|
|
|
|
/* VEC Registers */
|
|
#define VEC_REVID 0x100
|
|
|
|
#define VEC_CONFIG0 0x104
|
|
#define VEC_CONFIG0_YDEL_MASK GENMASK(28, 26)
|
|
#define VEC_CONFIG0_YDEL(x) ((x) << 26)
|
|
#define VEC_CONFIG0_CDEL_MASK GENMASK(25, 24)
|
|
#define VEC_CONFIG0_CDEL(x) ((x) << 24)
|
|
#define VEC_CONFIG0_SECAM_STD BIT(21)
|
|
#define VEC_CONFIG0_PBPR_FIL BIT(18)
|
|
#define VEC_CONFIG0_CHROMA_GAIN_MASK GENMASK(17, 16)
|
|
#define VEC_CONFIG0_CHROMA_GAIN_UNITY (0 << 16)
|
|
#define VEC_CONFIG0_CHROMA_GAIN_1_32 (1 << 16)
|
|
#define VEC_CONFIG0_CHROMA_GAIN_1_16 (2 << 16)
|
|
#define VEC_CONFIG0_CHROMA_GAIN_1_8 (3 << 16)
|
|
#define VEC_CONFIG0_CBURST_GAIN_MASK GENMASK(14, 13)
|
|
#define VEC_CONFIG0_CBURST_GAIN_UNITY (0 << 13)
|
|
#define VEC_CONFIG0_CBURST_GAIN_1_128 (1 << 13)
|
|
#define VEC_CONFIG0_CBURST_GAIN_1_64 (2 << 13)
|
|
#define VEC_CONFIG0_CBURST_GAIN_1_32 (3 << 13)
|
|
#define VEC_CONFIG0_CHRBW1 BIT(11)
|
|
#define VEC_CONFIG0_CHRBW0 BIT(10)
|
|
#define VEC_CONFIG0_SYNCDIS BIT(9)
|
|
#define VEC_CONFIG0_BURDIS BIT(8)
|
|
#define VEC_CONFIG0_CHRDIS BIT(7)
|
|
#define VEC_CONFIG0_PDEN BIT(6)
|
|
#define VEC_CONFIG0_YCDELAY BIT(4)
|
|
#define VEC_CONFIG0_RAMPEN BIT(2)
|
|
#define VEC_CONFIG0_YCDIS BIT(2)
|
|
#define VEC_CONFIG0_STD_MASK GENMASK(1, 0)
|
|
#define VEC_CONFIG0_NTSC_STD 0
|
|
#define VEC_CONFIG0_PAL_BDGHI_STD 1
|
|
#define VEC_CONFIG0_PAL_M_STD 2
|
|
#define VEC_CONFIG0_PAL_N_STD 3
|
|
|
|
#define VEC_SCHPH 0x108
|
|
#define VEC_SOFT_RESET 0x10c
|
|
#define VEC_CLMP0_START 0x144
|
|
#define VEC_CLMP0_END 0x148
|
|
|
|
/*
|
|
* These set the color subcarrier frequency
|
|
* if VEC_CONFIG1_CUSTOM_FREQ is enabled.
|
|
*
|
|
* VEC_FREQ1_0 contains the most significant 16-bit half-word,
|
|
* VEC_FREQ3_2 contains the least significant 16-bit half-word.
|
|
* 0x80000000 seems to be equivalent to the pixel clock
|
|
* (which itself is the VEC clock divided by 8).
|
|
*
|
|
* Reference values (with the default pixel clock of 13.5 MHz):
|
|
*
|
|
* NTSC (3579545.[45] Hz) - 0x21F07C1F
|
|
* PAL (4433618.75 Hz) - 0x2A098ACB
|
|
* PAL-M (3575611.[888111] Hz) - 0x21E6EFE3
|
|
* PAL-N (3582056.25 Hz) - 0x21F69446
|
|
*
|
|
* NOTE: For SECAM, it is used as the Dr center frequency,
|
|
* regardless of whether VEC_CONFIG1_CUSTOM_FREQ is enabled or not;
|
|
* that is specified as 4406250 Hz, which corresponds to 0x29C71C72.
|
|
*/
|
|
#define VEC_FREQ3_2 0x180
|
|
#define VEC_FREQ1_0 0x184
|
|
|
|
#define VEC_CONFIG1 0x188
|
|
#define VEC_CONFIG_VEC_RESYNC_OFF BIT(18)
|
|
#define VEC_CONFIG_RGB219 BIT(17)
|
|
#define VEC_CONFIG_CBAR_EN BIT(16)
|
|
#define VEC_CONFIG_TC_OBB BIT(15)
|
|
#define VEC_CONFIG1_OUTPUT_MODE_MASK GENMASK(12, 10)
|
|
#define VEC_CONFIG1_C_Y_CVBS (0 << 10)
|
|
#define VEC_CONFIG1_CVBS_Y_C (1 << 10)
|
|
#define VEC_CONFIG1_PR_Y_PB (2 << 10)
|
|
#define VEC_CONFIG1_RGB (4 << 10)
|
|
#define VEC_CONFIG1_Y_C_CVBS (5 << 10)
|
|
#define VEC_CONFIG1_C_CVBS_Y (6 << 10)
|
|
#define VEC_CONFIG1_C_CVBS_CVBS (7 << 10)
|
|
#define VEC_CONFIG1_DIS_CHR BIT(9)
|
|
#define VEC_CONFIG1_DIS_LUMA BIT(8)
|
|
#define VEC_CONFIG1_YCBCR_IN BIT(6)
|
|
#define VEC_CONFIG1_DITHER_TYPE_LFSR 0
|
|
#define VEC_CONFIG1_DITHER_TYPE_COUNTER BIT(5)
|
|
#define VEC_CONFIG1_DITHER_EN BIT(4)
|
|
#define VEC_CONFIG1_CYDELAY BIT(3)
|
|
#define VEC_CONFIG1_LUMADIS BIT(2)
|
|
#define VEC_CONFIG1_COMPDIS BIT(1)
|
|
#define VEC_CONFIG1_CUSTOM_FREQ BIT(0)
|
|
|
|
#define VEC_CONFIG2 0x18c
|
|
#define VEC_CONFIG2_PROG_SCAN BIT(15)
|
|
#define VEC_CONFIG2_SYNC_ADJ_MASK GENMASK(14, 12)
|
|
#define VEC_CONFIG2_SYNC_ADJ(x) (((x) / 2) << 12)
|
|
#define VEC_CONFIG2_PBPR_EN BIT(10)
|
|
#define VEC_CONFIG2_UV_DIG_DIS BIT(6)
|
|
#define VEC_CONFIG2_RGB_DIG_DIS BIT(5)
|
|
#define VEC_CONFIG2_TMUX_MASK GENMASK(3, 2)
|
|
#define VEC_CONFIG2_TMUX_DRIVE0 (0 << 2)
|
|
#define VEC_CONFIG2_TMUX_RG_COMP (1 << 2)
|
|
#define VEC_CONFIG2_TMUX_UV_YC (2 << 2)
|
|
#define VEC_CONFIG2_TMUX_SYNC_YC (3 << 2)
|
|
|
|
#define VEC_INTERRUPT_CONTROL 0x190
|
|
#define VEC_INTERRUPT_STATUS 0x194
|
|
|
|
/*
|
|
* Db center frequency for SECAM; the clock for this is the same as for
|
|
* VEC_FREQ3_2/VEC_FREQ1_0, which is used for Dr center frequency.
|
|
*
|
|
* This is specified as 4250000 Hz, which corresponds to 0x284BDA13.
|
|
* That is also the default value, so no need to set it explicitly.
|
|
*/
|
|
#define VEC_FCW_SECAM_B 0x198
|
|
#define VEC_SECAM_GAIN_VAL 0x19c
|
|
|
|
#define VEC_CONFIG3 0x1a0
|
|
#define VEC_CONFIG3_HORIZ_LEN_STD (0 << 0)
|
|
#define VEC_CONFIG3_HORIZ_LEN_MPEG1_SIF (1 << 0)
|
|
#define VEC_CONFIG3_SHAPE_NON_LINEAR BIT(1)
|
|
|
|
#define VEC_STATUS0 0x200
|
|
#define VEC_MASK0 0x204
|
|
|
|
#define VEC_CFG 0x208
|
|
#define VEC_CFG_SG_MODE_MASK GENMASK(6, 5)
|
|
#define VEC_CFG_SG_MODE(x) ((x) << 5)
|
|
#define VEC_CFG_SG_EN BIT(4)
|
|
#define VEC_CFG_VEC_EN BIT(3)
|
|
#define VEC_CFG_MB_EN BIT(2)
|
|
#define VEC_CFG_ENABLE BIT(1)
|
|
#define VEC_CFG_TB_EN BIT(0)
|
|
|
|
#define VEC_DAC_TEST 0x20c
|
|
|
|
#define VEC_DAC_CONFIG 0x210
|
|
#define VEC_DAC_CONFIG_LDO_BIAS_CTRL(x) ((x) << 24)
|
|
#define VEC_DAC_CONFIG_DRIVER_CTRL(x) ((x) << 16)
|
|
#define VEC_DAC_CONFIG_DAC_CTRL(x) (x)
|
|
|
|
#define VEC_DAC_MISC 0x214
|
|
#define VEC_DAC_MISC_VCD_CTRL_MASK GENMASK(31, 16)
|
|
#define VEC_DAC_MISC_VCD_CTRL(x) ((x) << 16)
|
|
#define VEC_DAC_MISC_VID_ACT BIT(8)
|
|
#define VEC_DAC_MISC_VCD_PWRDN BIT(6)
|
|
#define VEC_DAC_MISC_BIAS_PWRDN BIT(5)
|
|
#define VEC_DAC_MISC_DAC_PWRDN BIT(2)
|
|
#define VEC_DAC_MISC_LDO_PWRDN BIT(1)
|
|
#define VEC_DAC_MISC_DAC_RST_N BIT(0)
|
|
|
|
|
|
struct vc4_vec_variant {
|
|
u32 dac_config;
|
|
};
|
|
|
|
/* General VEC hardware state. */
|
|
struct vc4_vec {
|
|
struct vc4_encoder encoder;
|
|
struct drm_connector connector;
|
|
|
|
struct platform_device *pdev;
|
|
const struct vc4_vec_variant *variant;
|
|
|
|
void __iomem *regs;
|
|
|
|
struct clk *clock;
|
|
|
|
struct drm_property *legacy_tv_mode_property;
|
|
|
|
struct debugfs_regset32 regset;
|
|
};
|
|
|
|
#define VEC_READ(offset) \
|
|
({ \
|
|
kunit_fail_current_test("Accessing a register in a unit test!\n"); \
|
|
readl(vec->regs + (offset)); \
|
|
})
|
|
|
|
#define VEC_WRITE(offset, val) \
|
|
do { \
|
|
kunit_fail_current_test("Accessing a register in a unit test!\n"); \
|
|
writel(val, vec->regs + (offset)); \
|
|
} while (0)
|
|
|
|
#define encoder_to_vc4_vec(_encoder) \
|
|
container_of_const(_encoder, struct vc4_vec, encoder.base)
|
|
|
|
#define connector_to_vc4_vec(_connector) \
|
|
container_of_const(_connector, struct vc4_vec, connector)
|
|
|
|
enum vc4_vec_tv_mode_id {
|
|
VC4_VEC_TV_MODE_NTSC,
|
|
VC4_VEC_TV_MODE_NTSC_J,
|
|
VC4_VEC_TV_MODE_PAL,
|
|
VC4_VEC_TV_MODE_PAL_M,
|
|
VC4_VEC_TV_MODE_NTSC_443,
|
|
VC4_VEC_TV_MODE_PAL_60,
|
|
VC4_VEC_TV_MODE_PAL_N,
|
|
VC4_VEC_TV_MODE_SECAM,
|
|
VC4_VEC_TV_MODE_MONOCHROME,
|
|
};
|
|
|
|
struct vc4_vec_tv_mode {
|
|
unsigned int mode;
|
|
u16 expected_htotal;
|
|
u32 config0;
|
|
u32 config1;
|
|
u32 custom_freq;
|
|
};
|
|
|
|
static const struct debugfs_reg32 vec_regs[] = {
|
|
VC4_REG32(VEC_WSE_CONTROL),
|
|
VC4_REG32(VEC_WSE_WSS_DATA),
|
|
VC4_REG32(VEC_WSE_VPS_DATA1),
|
|
VC4_REG32(VEC_WSE_VPS_CONTROL),
|
|
VC4_REG32(VEC_REVID),
|
|
VC4_REG32(VEC_CONFIG0),
|
|
VC4_REG32(VEC_SCHPH),
|
|
VC4_REG32(VEC_CLMP0_START),
|
|
VC4_REG32(VEC_CLMP0_END),
|
|
VC4_REG32(VEC_FREQ3_2),
|
|
VC4_REG32(VEC_FREQ1_0),
|
|
VC4_REG32(VEC_CONFIG1),
|
|
VC4_REG32(VEC_CONFIG2),
|
|
VC4_REG32(VEC_INTERRUPT_CONTROL),
|
|
VC4_REG32(VEC_INTERRUPT_STATUS),
|
|
VC4_REG32(VEC_FCW_SECAM_B),
|
|
VC4_REG32(VEC_SECAM_GAIN_VAL),
|
|
VC4_REG32(VEC_CONFIG3),
|
|
VC4_REG32(VEC_STATUS0),
|
|
VC4_REG32(VEC_MASK0),
|
|
VC4_REG32(VEC_CFG),
|
|
VC4_REG32(VEC_DAC_TEST),
|
|
VC4_REG32(VEC_DAC_CONFIG),
|
|
VC4_REG32(VEC_DAC_MISC),
|
|
};
|
|
|
|
static const struct drm_display_mode drm_mode_240p = {
|
|
DRM_MODE("720x240", DRM_MODE_TYPE_DRIVER, 13500,
|
|
720, 720 + 14, 720 + 14 + 64, 720 + 14 + 64 + 60, 0,
|
|
240, 240 + 3, 240 + 3 + 3, 262, 0, 0)
|
|
};
|
|
|
|
static const struct drm_display_mode drm_mode_288p = {
|
|
DRM_MODE("720x288", DRM_MODE_TYPE_DRIVER, 13500,
|
|
720, 720 + 20, 720 + 20 + 64, 720 + 20 + 64 + 60, 0,
|
|
288, 288 + 2, 288 + 2 + 3, 312, 0, 0)
|
|
};
|
|
|
|
static const struct vc4_vec_tv_mode vc4_vec_tv_modes[] = {
|
|
{
|
|
.mode = DRM_MODE_TV_MODE_NTSC,
|
|
.expected_htotal = 858,
|
|
.config0 = VEC_CONFIG0_NTSC_STD | VEC_CONFIG0_PDEN,
|
|
.config1 = VEC_CONFIG1_C_CVBS_CVBS,
|
|
},
|
|
{
|
|
.mode = DRM_MODE_TV_MODE_NTSC_443,
|
|
.expected_htotal = 858,
|
|
.config0 = VEC_CONFIG0_NTSC_STD,
|
|
.config1 = VEC_CONFIG1_C_CVBS_CVBS | VEC_CONFIG1_CUSTOM_FREQ,
|
|
.custom_freq = 0x2a098acb,
|
|
},
|
|
{
|
|
.mode = DRM_MODE_TV_MODE_NTSC_J,
|
|
.expected_htotal = 858,
|
|
.config0 = VEC_CONFIG0_NTSC_STD,
|
|
.config1 = VEC_CONFIG1_C_CVBS_CVBS,
|
|
},
|
|
{
|
|
.mode = DRM_MODE_TV_MODE_PAL,
|
|
.expected_htotal = 864,
|
|
.config0 = VEC_CONFIG0_PAL_BDGHI_STD,
|
|
.config1 = VEC_CONFIG1_C_CVBS_CVBS,
|
|
},
|
|
{
|
|
/* PAL-60 */
|
|
.mode = DRM_MODE_TV_MODE_PAL,
|
|
.expected_htotal = 858,
|
|
.config0 = VEC_CONFIG0_PAL_M_STD,
|
|
.config1 = VEC_CONFIG1_C_CVBS_CVBS | VEC_CONFIG1_CUSTOM_FREQ,
|
|
.custom_freq = 0x2a098acb,
|
|
},
|
|
{
|
|
.mode = DRM_MODE_TV_MODE_PAL_M,
|
|
.expected_htotal = 858,
|
|
.config0 = VEC_CONFIG0_PAL_M_STD,
|
|
.config1 = VEC_CONFIG1_C_CVBS_CVBS,
|
|
},
|
|
{
|
|
.mode = DRM_MODE_TV_MODE_PAL_N,
|
|
.expected_htotal = 864,
|
|
.config0 = VEC_CONFIG0_PAL_N_STD,
|
|
.config1 = VEC_CONFIG1_C_CVBS_CVBS,
|
|
},
|
|
{
|
|
.mode = DRM_MODE_TV_MODE_SECAM,
|
|
.expected_htotal = 864,
|
|
.config0 = VEC_CONFIG0_SECAM_STD,
|
|
.config1 = VEC_CONFIG1_C_CVBS_CVBS,
|
|
.custom_freq = 0x29c71c72,
|
|
},
|
|
{
|
|
/* 50Hz mono */
|
|
.mode = DRM_MODE_TV_MODE_MONOCHROME,
|
|
.expected_htotal = 864,
|
|
.config0 = VEC_CONFIG0_PAL_BDGHI_STD | VEC_CONFIG0_BURDIS |
|
|
VEC_CONFIG0_CHRDIS,
|
|
.config1 = VEC_CONFIG1_C_CVBS_CVBS,
|
|
},
|
|
{
|
|
/* 60Hz mono */
|
|
.mode = DRM_MODE_TV_MODE_MONOCHROME,
|
|
.expected_htotal = 858,
|
|
.config0 = VEC_CONFIG0_PAL_M_STD | VEC_CONFIG0_BURDIS |
|
|
VEC_CONFIG0_CHRDIS,
|
|
.config1 = VEC_CONFIG1_C_CVBS_CVBS,
|
|
},
|
|
};
|
|
|
|
static inline const struct vc4_vec_tv_mode *
|
|
vc4_vec_tv_mode_lookup(unsigned int mode, u16 htotal)
|
|
{
|
|
unsigned int i;
|
|
|
|
for (i = 0; i < ARRAY_SIZE(vc4_vec_tv_modes); i++) {
|
|
const struct vc4_vec_tv_mode *tv_mode = &vc4_vec_tv_modes[i];
|
|
|
|
if (tv_mode->mode == mode &&
|
|
tv_mode->expected_htotal == htotal)
|
|
return tv_mode;
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
static const struct drm_prop_enum_list legacy_tv_mode_names[] = {
|
|
{ VC4_VEC_TV_MODE_NTSC, "NTSC", },
|
|
{ VC4_VEC_TV_MODE_NTSC_443, "NTSC-443", },
|
|
{ VC4_VEC_TV_MODE_NTSC_J, "NTSC-J", },
|
|
{ VC4_VEC_TV_MODE_PAL, "PAL", },
|
|
{ VC4_VEC_TV_MODE_PAL_60, "PAL-60", },
|
|
{ VC4_VEC_TV_MODE_PAL_M, "PAL-M", },
|
|
{ VC4_VEC_TV_MODE_PAL_N, "PAL-N", },
|
|
{ VC4_VEC_TV_MODE_SECAM, "SECAM", },
|
|
{ VC4_VEC_TV_MODE_MONOCHROME, "Mono", },
|
|
};
|
|
|
|
static enum drm_connector_status
|
|
vc4_vec_connector_detect(struct drm_connector *connector, bool force)
|
|
{
|
|
return connector_status_unknown;
|
|
}
|
|
|
|
static void vc4_vec_connector_reset(struct drm_connector *connector)
|
|
{
|
|
drm_atomic_helper_connector_reset(connector);
|
|
drm_atomic_helper_connector_tv_reset(connector);
|
|
}
|
|
|
|
static int
|
|
vc4_vec_connector_set_property(struct drm_connector *connector,
|
|
struct drm_connector_state *state,
|
|
struct drm_property *property,
|
|
uint64_t val)
|
|
{
|
|
struct vc4_vec *vec = connector_to_vc4_vec(connector);
|
|
|
|
if (property != vec->legacy_tv_mode_property)
|
|
return -EINVAL;
|
|
|
|
switch (val) {
|
|
case VC4_VEC_TV_MODE_NTSC:
|
|
state->tv.mode = DRM_MODE_TV_MODE_NTSC;
|
|
break;
|
|
|
|
case VC4_VEC_TV_MODE_NTSC_443:
|
|
state->tv.mode = DRM_MODE_TV_MODE_NTSC_443;
|
|
break;
|
|
|
|
case VC4_VEC_TV_MODE_NTSC_J:
|
|
state->tv.mode = DRM_MODE_TV_MODE_NTSC_J;
|
|
break;
|
|
|
|
case VC4_VEC_TV_MODE_PAL:
|
|
case VC4_VEC_TV_MODE_PAL_60:
|
|
state->tv.mode = DRM_MODE_TV_MODE_PAL;
|
|
break;
|
|
|
|
case VC4_VEC_TV_MODE_PAL_M:
|
|
state->tv.mode = DRM_MODE_TV_MODE_PAL_M;
|
|
break;
|
|
|
|
case VC4_VEC_TV_MODE_PAL_N:
|
|
state->tv.mode = DRM_MODE_TV_MODE_PAL_N;
|
|
break;
|
|
|
|
case VC4_VEC_TV_MODE_SECAM:
|
|
state->tv.mode = DRM_MODE_TV_MODE_SECAM;
|
|
break;
|
|
|
|
case VC4_VEC_TV_MODE_MONOCHROME:
|
|
state->tv.mode = DRM_MODE_TV_MODE_MONOCHROME;
|
|
break;
|
|
|
|
default:
|
|
return -EINVAL;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int
|
|
vc4_vec_connector_get_property(struct drm_connector *connector,
|
|
const struct drm_connector_state *state,
|
|
struct drm_property *property,
|
|
uint64_t *val)
|
|
{
|
|
struct vc4_vec *vec = connector_to_vc4_vec(connector);
|
|
|
|
if (property != vec->legacy_tv_mode_property)
|
|
return -EINVAL;
|
|
|
|
switch (state->tv.mode) {
|
|
case DRM_MODE_TV_MODE_NTSC:
|
|
*val = VC4_VEC_TV_MODE_NTSC;
|
|
break;
|
|
|
|
case DRM_MODE_TV_MODE_NTSC_443:
|
|
*val = VC4_VEC_TV_MODE_NTSC_443;
|
|
break;
|
|
|
|
case DRM_MODE_TV_MODE_NTSC_J:
|
|
*val = VC4_VEC_TV_MODE_NTSC_J;
|
|
break;
|
|
|
|
case DRM_MODE_TV_MODE_PAL:
|
|
*val = VC4_VEC_TV_MODE_PAL;
|
|
break;
|
|
|
|
case DRM_MODE_TV_MODE_PAL_M:
|
|
*val = VC4_VEC_TV_MODE_PAL_M;
|
|
break;
|
|
|
|
case DRM_MODE_TV_MODE_PAL_N:
|
|
*val = VC4_VEC_TV_MODE_PAL_N;
|
|
break;
|
|
|
|
case DRM_MODE_TV_MODE_SECAM:
|
|
*val = VC4_VEC_TV_MODE_SECAM;
|
|
break;
|
|
|
|
case DRM_MODE_TV_MODE_MONOCHROME:
|
|
*val = VC4_VEC_TV_MODE_MONOCHROME;
|
|
break;
|
|
|
|
default:
|
|
return -EINVAL;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static const struct drm_connector_funcs vc4_vec_connector_funcs = {
|
|
.detect = vc4_vec_connector_detect,
|
|
.fill_modes = drm_helper_probe_single_connector_modes,
|
|
.reset = vc4_vec_connector_reset,
|
|
.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
|
|
.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
|
|
.atomic_get_property = vc4_vec_connector_get_property,
|
|
.atomic_set_property = vc4_vec_connector_set_property,
|
|
};
|
|
|
|
static int vc4_vec_connector_get_modes(struct drm_connector *connector)
|
|
{
|
|
struct drm_display_mode *mode;
|
|
int count = drm_connector_helper_tv_get_modes(connector);
|
|
|
|
mode = drm_mode_duplicate(connector->dev, &drm_mode_240p);
|
|
if (!mode)
|
|
return -ENOMEM;
|
|
|
|
drm_mode_probed_add(connector, mode);
|
|
count++;
|
|
|
|
mode = drm_mode_duplicate(connector->dev, &drm_mode_288p);
|
|
if (!mode)
|
|
return -ENOMEM;
|
|
|
|
drm_mode_probed_add(connector, mode);
|
|
count++;
|
|
|
|
return count;
|
|
}
|
|
|
|
static const struct drm_connector_helper_funcs vc4_vec_connector_helper_funcs = {
|
|
.atomic_check = drm_atomic_helper_connector_tv_check,
|
|
.get_modes = vc4_vec_connector_get_modes,
|
|
};
|
|
|
|
static int vc4_vec_connector_init(struct drm_device *dev, struct vc4_vec *vec)
|
|
{
|
|
struct drm_connector *connector = &vec->connector;
|
|
struct drm_property *prop;
|
|
int ret;
|
|
|
|
connector->interlace_allowed = true;
|
|
|
|
ret = drmm_connector_init(dev, connector, &vc4_vec_connector_funcs,
|
|
DRM_MODE_CONNECTOR_Composite, NULL);
|
|
if (ret)
|
|
return ret;
|
|
|
|
drm_connector_helper_add(connector, &vc4_vec_connector_helper_funcs);
|
|
|
|
drm_object_attach_property(&connector->base,
|
|
dev->mode_config.tv_mode_property,
|
|
DRM_MODE_TV_MODE_NTSC);
|
|
|
|
prop = drm_property_create_enum(dev, 0, "mode",
|
|
legacy_tv_mode_names,
|
|
ARRAY_SIZE(legacy_tv_mode_names));
|
|
if (!prop)
|
|
return -ENOMEM;
|
|
vec->legacy_tv_mode_property = prop;
|
|
|
|
drm_object_attach_property(&connector->base, prop, VC4_VEC_TV_MODE_NTSC);
|
|
|
|
drm_connector_attach_tv_margin_properties(connector);
|
|
|
|
drm_connector_attach_encoder(connector, &vec->encoder.base);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void vc4_vec_encoder_disable(struct drm_encoder *encoder,
|
|
struct drm_atomic_state *state)
|
|
{
|
|
struct drm_device *drm = encoder->dev;
|
|
struct vc4_vec *vec = encoder_to_vc4_vec(encoder);
|
|
int idx, ret;
|
|
|
|
if (!drm_dev_enter(drm, &idx))
|
|
return;
|
|
|
|
VEC_WRITE(VEC_CFG, 0);
|
|
VEC_WRITE(VEC_DAC_MISC,
|
|
VEC_DAC_MISC_VCD_PWRDN |
|
|
VEC_DAC_MISC_BIAS_PWRDN |
|
|
VEC_DAC_MISC_DAC_PWRDN |
|
|
VEC_DAC_MISC_LDO_PWRDN);
|
|
|
|
clk_disable_unprepare(vec->clock);
|
|
|
|
ret = pm_runtime_put(&vec->pdev->dev);
|
|
if (ret < 0) {
|
|
drm_err(drm, "Failed to release power domain: %d\n", ret);
|
|
goto err_dev_exit;
|
|
}
|
|
|
|
drm_dev_exit(idx);
|
|
return;
|
|
|
|
err_dev_exit:
|
|
drm_dev_exit(idx);
|
|
}
|
|
|
|
static void vc4_vec_encoder_enable(struct drm_encoder *encoder,
|
|
struct drm_atomic_state *state)
|
|
{
|
|
struct drm_device *drm = encoder->dev;
|
|
struct vc4_vec *vec = encoder_to_vc4_vec(encoder);
|
|
struct drm_connector *connector = &vec->connector;
|
|
struct drm_connector_state *conn_state =
|
|
drm_atomic_get_new_connector_state(state, connector);
|
|
struct drm_display_mode *adjusted_mode =
|
|
&encoder->crtc->state->adjusted_mode;
|
|
const struct vc4_vec_tv_mode *tv_mode;
|
|
int idx, ret;
|
|
|
|
if (!drm_dev_enter(drm, &idx))
|
|
return;
|
|
|
|
tv_mode = vc4_vec_tv_mode_lookup(conn_state->tv.mode,
|
|
adjusted_mode->htotal);
|
|
if (!tv_mode)
|
|
goto err_dev_exit;
|
|
|
|
ret = pm_runtime_resume_and_get(&vec->pdev->dev);
|
|
if (ret < 0) {
|
|
drm_err(drm, "Failed to retain power domain: %d\n", ret);
|
|
goto err_dev_exit;
|
|
}
|
|
|
|
/*
|
|
* We need to set the clock rate each time we enable the encoder
|
|
* because there's a chance we share the same parent with the HDMI
|
|
* clock, and both drivers are requesting different rates.
|
|
* The good news is, these 2 encoders cannot be enabled at the same
|
|
* time, thus preventing incompatible rate requests.
|
|
*/
|
|
ret = clk_set_rate(vec->clock, 108000000);
|
|
if (ret) {
|
|
drm_err(drm, "Failed to set clock rate: %d\n", ret);
|
|
goto err_put_runtime_pm;
|
|
}
|
|
|
|
ret = clk_prepare_enable(vec->clock);
|
|
if (ret) {
|
|
drm_err(drm, "Failed to turn on core clock: %d\n", ret);
|
|
goto err_put_runtime_pm;
|
|
}
|
|
|
|
/* Reset the different blocks */
|
|
VEC_WRITE(VEC_WSE_RESET, 1);
|
|
VEC_WRITE(VEC_SOFT_RESET, 1);
|
|
|
|
/* Disable the CGSM-A and WSE blocks */
|
|
VEC_WRITE(VEC_WSE_CONTROL, 0);
|
|
|
|
/* Write config common to all modes. */
|
|
|
|
/*
|
|
* Color subcarrier phase: phase = 360 * SCHPH / 256.
|
|
* 0x28 <=> 39.375 deg.
|
|
*/
|
|
VEC_WRITE(VEC_SCHPH, 0x28);
|
|
|
|
/*
|
|
* Reset to default values.
|
|
*/
|
|
VEC_WRITE(VEC_CLMP0_START, 0xac);
|
|
VEC_WRITE(VEC_CLMP0_END, 0xec);
|
|
VEC_WRITE(VEC_CONFIG2,
|
|
VEC_CONFIG2_UV_DIG_DIS |
|
|
VEC_CONFIG2_RGB_DIG_DIS |
|
|
((adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) ? 0 : VEC_CONFIG2_PROG_SCAN));
|
|
VEC_WRITE(VEC_CONFIG3, VEC_CONFIG3_HORIZ_LEN_STD);
|
|
VEC_WRITE(VEC_DAC_CONFIG, vec->variant->dac_config);
|
|
|
|
/* Mask all interrupts. */
|
|
VEC_WRITE(VEC_MASK0, 0);
|
|
|
|
VEC_WRITE(VEC_CONFIG0, tv_mode->config0);
|
|
VEC_WRITE(VEC_CONFIG1, tv_mode->config1);
|
|
|
|
if (tv_mode->custom_freq) {
|
|
VEC_WRITE(VEC_FREQ3_2,
|
|
(tv_mode->custom_freq >> 16) & 0xffff);
|
|
VEC_WRITE(VEC_FREQ1_0,
|
|
tv_mode->custom_freq & 0xffff);
|
|
}
|
|
|
|
VEC_WRITE(VEC_DAC_MISC,
|
|
VEC_DAC_MISC_VID_ACT | VEC_DAC_MISC_DAC_RST_N);
|
|
VEC_WRITE(VEC_CFG, VEC_CFG_VEC_EN);
|
|
|
|
drm_dev_exit(idx);
|
|
return;
|
|
|
|
err_put_runtime_pm:
|
|
pm_runtime_put(&vec->pdev->dev);
|
|
err_dev_exit:
|
|
drm_dev_exit(idx);
|
|
}
|
|
|
|
static int vc4_vec_encoder_atomic_check(struct drm_encoder *encoder,
|
|
struct drm_crtc_state *crtc_state,
|
|
struct drm_connector_state *conn_state)
|
|
{
|
|
const struct drm_display_mode *mode = &crtc_state->adjusted_mode;
|
|
const struct vc4_vec_tv_mode *tv_mode;
|
|
|
|
tv_mode = vc4_vec_tv_mode_lookup(conn_state->tv.mode, mode->htotal);
|
|
if (!tv_mode)
|
|
return -EINVAL;
|
|
|
|
if (mode->crtc_hdisplay % 4)
|
|
return -EINVAL;
|
|
|
|
if (!(mode->crtc_hsync_end - mode->crtc_hsync_start))
|
|
return -EINVAL;
|
|
|
|
switch (mode->htotal) {
|
|
/* NTSC */
|
|
case 858:
|
|
if (mode->crtc_vtotal > 262)
|
|
return -EINVAL;
|
|
|
|
if (mode->crtc_vdisplay < 1 || mode->crtc_vdisplay > 253)
|
|
return -EINVAL;
|
|
|
|
if (!(mode->crtc_vsync_start - mode->crtc_vdisplay))
|
|
return -EINVAL;
|
|
|
|
if ((mode->crtc_vsync_end - mode->crtc_vsync_start) != 3)
|
|
return -EINVAL;
|
|
|
|
if ((mode->crtc_vtotal - mode->crtc_vsync_end) < 4)
|
|
return -EINVAL;
|
|
|
|
break;
|
|
|
|
/* PAL/SECAM */
|
|
case 864:
|
|
if (mode->crtc_vtotal > 312)
|
|
return -EINVAL;
|
|
|
|
if (mode->crtc_vdisplay < 1 || mode->crtc_vdisplay > 305)
|
|
return -EINVAL;
|
|
|
|
if (!(mode->crtc_vsync_start - mode->crtc_vdisplay))
|
|
return -EINVAL;
|
|
|
|
if ((mode->crtc_vsync_end - mode->crtc_vsync_start) != 3)
|
|
return -EINVAL;
|
|
|
|
if ((mode->crtc_vtotal - mode->crtc_vsync_end) < 2)
|
|
return -EINVAL;
|
|
|
|
break;
|
|
|
|
default:
|
|
return -EINVAL;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static const struct drm_encoder_helper_funcs vc4_vec_encoder_helper_funcs = {
|
|
.atomic_check = vc4_vec_encoder_atomic_check,
|
|
.atomic_disable = vc4_vec_encoder_disable,
|
|
.atomic_enable = vc4_vec_encoder_enable,
|
|
};
|
|
|
|
static int vc4_vec_late_register(struct drm_encoder *encoder)
|
|
{
|
|
struct drm_device *drm = encoder->dev;
|
|
struct vc4_vec *vec = encoder_to_vc4_vec(encoder);
|
|
|
|
vc4_debugfs_add_regset32(drm, "vec_regs", &vec->regset);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static const struct drm_encoder_funcs vc4_vec_encoder_funcs = {
|
|
.late_register = vc4_vec_late_register,
|
|
};
|
|
|
|
static const struct vc4_vec_variant bcm2835_vec_variant = {
|
|
.dac_config = VEC_DAC_CONFIG_DAC_CTRL(0xc) |
|
|
VEC_DAC_CONFIG_DRIVER_CTRL(0xc) |
|
|
VEC_DAC_CONFIG_LDO_BIAS_CTRL(0x46)
|
|
};
|
|
|
|
static const struct vc4_vec_variant bcm2711_vec_variant = {
|
|
.dac_config = VEC_DAC_CONFIG_DAC_CTRL(0x0) |
|
|
VEC_DAC_CONFIG_DRIVER_CTRL(0x80) |
|
|
VEC_DAC_CONFIG_LDO_BIAS_CTRL(0x61)
|
|
};
|
|
|
|
static const struct of_device_id vc4_vec_dt_match[] = {
|
|
{ .compatible = "brcm,bcm2835-vec", .data = &bcm2835_vec_variant },
|
|
{ .compatible = "brcm,bcm2711-vec", .data = &bcm2711_vec_variant },
|
|
{ /* sentinel */ },
|
|
};
|
|
|
|
static int vc4_vec_bind(struct device *dev, struct device *master, void *data)
|
|
{
|
|
struct platform_device *pdev = to_platform_device(dev);
|
|
struct drm_device *drm = dev_get_drvdata(master);
|
|
struct vc4_vec *vec;
|
|
int ret;
|
|
|
|
ret = drm_mode_create_tv_properties(drm,
|
|
BIT(DRM_MODE_TV_MODE_NTSC) |
|
|
BIT(DRM_MODE_TV_MODE_NTSC_443) |
|
|
BIT(DRM_MODE_TV_MODE_NTSC_J) |
|
|
BIT(DRM_MODE_TV_MODE_PAL) |
|
|
BIT(DRM_MODE_TV_MODE_PAL_M) |
|
|
BIT(DRM_MODE_TV_MODE_PAL_N) |
|
|
BIT(DRM_MODE_TV_MODE_SECAM) |
|
|
BIT(DRM_MODE_TV_MODE_MONOCHROME));
|
|
if (ret)
|
|
return ret;
|
|
|
|
vec = drmm_kzalloc(drm, sizeof(*vec), GFP_KERNEL);
|
|
if (!vec)
|
|
return -ENOMEM;
|
|
|
|
vec->encoder.type = VC4_ENCODER_TYPE_VEC;
|
|
vec->pdev = pdev;
|
|
vec->variant = (const struct vc4_vec_variant *)
|
|
of_device_get_match_data(dev);
|
|
vec->regs = vc4_ioremap_regs(pdev, 0);
|
|
if (IS_ERR(vec->regs))
|
|
return PTR_ERR(vec->regs);
|
|
vec->regset.base = vec->regs;
|
|
vec->regset.regs = vec_regs;
|
|
vec->regset.nregs = ARRAY_SIZE(vec_regs);
|
|
|
|
vec->clock = devm_clk_get(dev, NULL);
|
|
if (IS_ERR(vec->clock)) {
|
|
ret = PTR_ERR(vec->clock);
|
|
if (ret != -EPROBE_DEFER)
|
|
drm_err(drm, "Failed to get clock: %d\n", ret);
|
|
return ret;
|
|
}
|
|
|
|
ret = devm_pm_runtime_enable(dev);
|
|
if (ret)
|
|
return ret;
|
|
|
|
ret = drmm_encoder_init(drm, &vec->encoder.base,
|
|
&vc4_vec_encoder_funcs,
|
|
DRM_MODE_ENCODER_TVDAC,
|
|
NULL);
|
|
if (ret)
|
|
return ret;
|
|
|
|
drm_encoder_helper_add(&vec->encoder.base, &vc4_vec_encoder_helper_funcs);
|
|
|
|
ret = vc4_vec_connector_init(drm, vec);
|
|
if (ret)
|
|
return ret;
|
|
|
|
dev_set_drvdata(dev, vec);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static const struct component_ops vc4_vec_ops = {
|
|
.bind = vc4_vec_bind,
|
|
};
|
|
|
|
static int vc4_vec_dev_probe(struct platform_device *pdev)
|
|
{
|
|
return component_add(&pdev->dev, &vc4_vec_ops);
|
|
}
|
|
|
|
static void vc4_vec_dev_remove(struct platform_device *pdev)
|
|
{
|
|
component_del(&pdev->dev, &vc4_vec_ops);
|
|
}
|
|
|
|
struct platform_driver vc4_vec_driver = {
|
|
.probe = vc4_vec_dev_probe,
|
|
.remove = vc4_vec_dev_remove,
|
|
.driver = {
|
|
.name = "vc4_vec",
|
|
.of_match_table = vc4_vec_dt_match,
|
|
},
|
|
};
|