Skip to content

Commit

Permalink
media: nuvoton: Add driver for NPCM video capture and encode engine
Browse files Browse the repository at this point in the history
Add driver for Video Capture/Differentiation Engine (VCD) and Encoding
Compression Engine (ECE) present on Nuvoton NPCM SoCs. The VCD can
capture and differentiate video data from digital or analog sources,
then the ECE will compress the data into HEXTILE format. This driver
implements V4L2 interfaces and provides user controls to support KVM
feature, also tested with VNC Viewer and openbmc/obmc-ikvm.

Signed-off-by: Marvin Lin <milkfafa@gmail.com>
  • Loading branch information
linkunfa authored and intel-lab-lkp committed Dec 20, 2022
1 parent 0104ae0 commit e37f65b
Show file tree
Hide file tree
Showing 7 changed files with 2,126 additions and 0 deletions.
12 changes: 12 additions & 0 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -2554,6 +2554,18 @@ F: drivers/rtc/rtc-nct3018y.c
F: include/dt-bindings/clock/nuvoton,npcm7xx-clock.h
F: include/dt-bindings/clock/nuvoton,npcm845-clk.h

ARM/NUVOTON NPCM VIDEO ENGINE DRIVER
M: Joseph Liu <kwliu@nuvoton.com>
M: Marvin Lin <kflin@nuvoton.com>
L: linux-media@vger.kernel.org
L: openbmc@lists.ozlabs.org (moderated for non-subscribers)
S: Maintained
F: Documentation/devicetree/bindings/media/nuvoton,npcm-ece.yaml
F: Documentation/devicetree/bindings/media/nuvoton,npcm-vcd.yaml
F: Documentation/userspace-api/media/drivers/npcm-video.rst
F: drivers/media/platform/nuvoton/
F: include/uapi/linux/npcm-video.h

ARM/NUVOTON WPCM450 ARCHITECTURE
M: Jonathan Neuschäfer <j.neuschaefer@gmx.net>
L: openbmc@lists.ozlabs.org (moderated for non-subscribers)
Expand Down
1 change: 1 addition & 0 deletions drivers/media/platform/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ source "drivers/media/platform/intel/Kconfig"
source "drivers/media/platform/marvell/Kconfig"
source "drivers/media/platform/mediatek/Kconfig"
source "drivers/media/platform/microchip/Kconfig"
source "drivers/media/platform/nuvoton/Kconfig"
source "drivers/media/platform/nvidia/Kconfig"
source "drivers/media/platform/nxp/Kconfig"
source "drivers/media/platform/qcom/Kconfig"
Expand Down
1 change: 1 addition & 0 deletions drivers/media/platform/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ obj-y += intel/
obj-y += marvell/
obj-y += mediatek/
obj-y += microchip/
obj-y += nuvoton/
obj-y += nvidia/
obj-y += nxp/
obj-y += qcom/
Expand Down
15 changes: 15 additions & 0 deletions drivers/media/platform/nuvoton/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# SPDX-License-Identifier: GPL-2.0-only

comment "Nuvoton media platform drivers"

config VIDEO_NPCM_VCD_ECE
tristate "Nuvoton NPCM Video Capture/Encode Engine driver"
depends on V4L_PLATFORM_DRIVERS
depends on VIDEO_DEV
select VIDEOBUF2_DMA_CONTIG
help
Support for the Video Capture/Differentiation Engine (VCD) and
Encoding Compression Engine (ECE) present on Nuvoton NPCM SoCs.
The VCD can capture and differentiate video data from digital or
analog sources, then the ECE will compress the data into HEXTILE
format.
2 changes: 2 additions & 0 deletions drivers/media/platform/nuvoton/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# SPDX-License-Identifier: GPL-2.0-only
obj-$(CONFIG_VIDEO_NPCM_VCD_ECE) += npcm-video.o
171 changes: 171 additions & 0 deletions drivers/media/platform/nuvoton/npcm-regs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Register definition header for NPCM video driver
*
* Copyright (C) 2022 Nuvoton Technologies
*/

#ifndef _NPCM_REGS_H
#define _NPCM_REGS_H

/* VCD Registers */
#define VCD_DIFF_TBL 0x0000
#define VCD_FBA_ADR 0x8000
#define VCD_FBB_ADR 0x8004

#define VCD_FB_LP 0x8008
#define VCD_FBA_LP GENMASK(15, 0)
#define VCD_FBB_LP GENMASK(31, 16)

#define VCD_CAP_RES 0x800c
#define VCD_CAP_RES_VERT_RES GENMASK(10, 0)
#define VCD_CAP_RES_HOR_RES GENMASK(26, 16)

#define VCD_MODE 0x8014
#define VCD_MODE_VCDE BIT(0)
#define VCD_MODE_CM565 BIT(1)
#define VCD_MODE_IDBC BIT(3)
#define VCD_MODE_COLOR_CNVRT GENMASK(5, 4)
#define VCD_MODE_COLOR_CNVRT_NO_CNVRT 0
#define VCD_MODE_COLOR_CNVRT_RGB_222 1
#define VCD_MODE_COLOR_CNVRT_666_MODE 2
#define VCD_MODE_COLOR_CNVRT_RGB_888 3
#define VCD_MODE_KVM_BW_SET BIT(16)

#define VCD_CMD 0x8018
#define VCD_CMD_GO BIT(0)
#define VCD_CMD_RST BIT(1)
#define VCD_CMD_OPERATION GENMASK(6, 4)
#define VCD_CMD_OPERATION_CAPTURE 0
#define VCD_CMD_OPERATION_COMPARE 2

#define VCD_STAT 0x801c
#define VCD_STAT_DONE BIT(0)
#define VCD_STAT_IFOT BIT(2)
#define VCD_STAT_IFOR BIT(3)
#define VCD_STAT_BUSY BIT(30)
#define VCD_STAT_CLEAR 0x3fff

#define VCD_INTE 0x8020
#define VCD_INTE_DONE_IE BIT(0)
#define VCD_INTE_IFOT_IE BIT(2)
#define VCD_INTE_IFOR_IE BIT(3)

#define VCD_RCHG 0x8028
#define VCD_RCHG_TIM_PRSCL GENMASK(12, 9)

#define VCD_FIFO 0x805c
#define VCD_FIFO_TH 0x100350ff

#define VCD_MAX_SRC_BUFFER_SIZE 0x500000 /* 1920 x 1200 x 2 bpp */
#define VCD_KVM_BW_PCLK 120000000UL
#define VCD_BUSY_TIMEOUT_US 300000

/* ECE Registers */
#define ECE_DDA_CTRL 0x0000
#define ECE_DDA_CTRL_ECEEN BIT(0)
#define ECE_DDA_CTRL_INTEN BIT(8)

#define ECE_DDA_STS 0x0004
#define ECE_DDA_STS_CDREADY BIT(8)
#define ECE_DDA_STS_ACDRDY BIT(10)

#define ECE_FBR_BA 0x0008
#define ECE_ED_BA 0x000c
#define ECE_RECT_XY 0x0010

#define ECE_RECT_DIMEN 0x0014
#define ECE_RECT_DIMEN_WR GENMASK(10, 0)
#define ECE_RECT_DIMEN_WLTR GENMASK(14, 11)
#define ECE_RECT_DIMEN_HR GENMASK(26, 16)
#define ECE_RECT_DIMEN_HLTR GENMASK(30, 27)

#define ECE_RESOL 0x001c
#define ECE_RESOL_FB_LP_512 0
#define ECE_RESOL_FB_LP_1024 1
#define ECE_RESOL_FB_LP_2048 2
#define ECE_RESOL_FB_LP_2560 3
#define ECE_RESOL_FB_LP_4096 4

#define ECE_HEX_CTRL 0x0040
#define ECE_HEX_CTRL_ENCDIS BIT(0)
#define ECE_HEX_CTRL_ENC_GAP GENMASK(12, 8)

#define ECE_HEX_RECT_OFFSET 0x0048
#define ECE_HEX_RECT_OFFSET_MASK GENMASK(22, 0)

#define ECE_TILE_W 16
#define ECE_TILE_H 16
#define ECE_POLL_TIMEOUT_US 300000

/* GCR Registers */
#define INTCR 0x3c
#define INTCR_GFXIFDIS GENMASK(9, 8)
#define INTCR_DEHS BIT(27)

#define INTCR2 0x60
#define INTCR2_GIRST2 BIT(2)
#define INTCR2_GIHCRST BIT(5)
#define INTCR2_GIVCRST BIT(6)

#define INTCR3 0x9c
#define INTCR3_GMMAP GENMASK(10, 8)
#define INTCR3_GMMAP_128MB 0
#define INTCR3_GMMAP_256MB 1
#define INTCR3_GMMAP_512MB 2
#define INTCR3_GMMAP_1GB 3
#define INTCR3_GMMAP_2GB 4

#define INTCR4 0xc0
#define INTCR4_GMMAP GENMASK(22, 16)
#define INTCR4_GMMAP_512MB 0x1f
#define INTCR4_GMMAP_512MB_ECC 0x1b
#define INTCR4_GMMAP_1GB 0x3f
#define INTCR4_GMMAP_1GB_ECC 0x37
#define INTCR4_GMMAP_2GB 0x7f
#define INTCR4_GMMAP_2GB_ECC 0x6f

#define ADDR_GMMAP_128MB 0x07000000
#define ADDR_GMMAP_256MB 0x0f000000
#define ADDR_GMMAP_512MB 0x1f000000
#define ADDR_GMMAP_512MB_ECC 0x1b000000
#define ADDR_GMMAP_1GB 0x3f000000
#define ADDR_GMMAP_1GB_ECC 0x37000000
#define ADDR_GMMAP_2GB 0x7f000000
#define ADDR_GMMAP_2GB_ECC 0x6f000000

#define GMMAP_LENGTH 0xc00000 /* 4MB preserved, total 16MB */

#define MFSEL1 0x0c
#define MFSEL1_DVH1SEL BIT(27)

/* GFXI Register */
#define DISPST 0x00
#define DISPST_HSCROFF BIT(1)
#define DISPST_MGAMODE BIT(7)

#define HVCNTL 0x10
#define HVCNTL_MASK GENMASK(7, 0)

#define HVCNTH 0x14
#define HVCNTH_MASK GENMASK(2, 0)

#define VVCNTL 0x20
#define VVCNTL_MASK GENMASK(7, 0)

#define VVCNTH 0x24
#define VVCNTH_MASK GENMASK(2, 0)

#define GPLLINDIV 0x40
#define GPLLINDIV_MASK GENMASK(5, 0)
#define GPLLINDIV_GPLLFBDV8 BIT(7)

#define GPLLFBDIV 0x44
#define GPLLFBDIV_MASK GENMASK(7, 0)

#define GPLLST 0x48
#define GPLLST_PLLOTDIV1 GENMASK(2, 0)
#define GPLLST_PLLOTDIV2 GENMASK(5, 3)
#define GPLLST_GPLLFBDV109 GENMASK(7, 6)

#endif /* _NPCM_REGS_H */
Loading

0 comments on commit e37f65b

Please sign in to comment.