Skip to contentSkip to conversation

Aspeed Video Engine

PATCH In review Eddie James 3 participants 12 messages Jan 3, 2019 – Jan 28, 2019

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover Aspeed Video Engine

From: Eddie James <[email protected]>

This series adds all the necessary bits to enable the Aspeed video engine. The video engine driver has been accepted upstream. I have submitted the clock changes upstream and responded to Joel's comments on those.

Eddie James (6):
clk: aspeed: Add video engine reset index definition
clk: aspeed: Setup video engine clocking
ARM: dts: aspeed-g5: Add video engine node
ARM: dts: aspeed: witherspoon: Enable video engine
media: dt-bindings: media: Add Aspeed Video Engine binding
documentation
media: platform: Add Aspeed Video Engine driver

 .../devicetree/bindings/media/aspeed-video.txt     |   26 +
 MAINTAINERS                                        |    8 +
 arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts   |   11 +-
 arch/arm/boot/dts/aspeed-g5.dtsi                   |   11 +
 drivers/clk/clk-aspeed.c                           |   41 +-
 drivers/media/platform/Kconfig                     |    9 +
 drivers/media/platform/Makefile                    |    1 +
 drivers/media/platform/aspeed-video.c              | 1729 ++++++++++++++++++++
 include/dt-bindings/clock/aspeed-clock.h           |    1 +
 9 files changed, 1834 insertions(+), 3 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/media/aspeed-video.txt
 create mode 100644 drivers/media/platform/aspeed-video.c
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/6 clk: aspeed: Add video engine reset index definition

Add an index into the array of resets kept in the Aspeed clock driver for the video engine. This isn't a HW bit definition.

---
 include/dt-bindings/clock/aspeed-clock.h | 1 +
 1 file changed, 1 insertion(+)
include/dt-bindings/clock/aspeed-clock.h +1 -0
index f437386..15a9059 100644
@@ -50,5 +50,6 @@
 #define ASPEED_RESET_I2C		7
 #define ASPEED_RESET_AHB		8
 #define ASPEED_RESET_CRT1		9
+#define ASPEED_RESET_VIDEO		10
 
 #endif
Signature · 1 line
1.8.3.1
#2 lore raw

PATCH 2/6 clk: aspeed: Setup video engine clocking

In reply to Eddie James

Add the video engine reset bit. Add eclk mux and clock divider table.

---
 drivers/clk/clk-aspeed.c | 41 +++++++++++++++++++++++++++++++++++++++--
 1 file changed, 39 insertions(+), 2 deletions(-)
drivers/clk/clk-aspeed.c +39 -2
index 5961367..f16ce7d 100644
@@ -87,7 +87,7 @@ struct aspeed_clk_gate {
 /* TODO: ask Aspeed about the actual parent data */
 static const struct aspeed_gate_data aspeed_gates[] = {
 	/*				 clk rst   name			parent	flags */
-	[ASPEED_CLK_GATE_ECLK] =	{  0, -1, "eclk-gate",		"eclk",	0 }, /* Video Engine */
+	[ASPEED_CLK_GATE_ECLK] =	{  0,  6, "eclk-gate",		"eclk",	0 }, /* Video Engine */
 	[ASPEED_CLK_GATE_GCLK] =	{  1,  7, "gclk-gate",		NULL,	0 }, /* 2D engine */
 	[ASPEED_CLK_GATE_MCLK] =	{  2, -1, "mclk-gate",		"mpll",	CLK_IS_CRITICAL }, /* SDRAM */
 	[ASPEED_CLK_GATE_VCLK] =	{  3,  6, "vclk-gate",		NULL,	0 }, /* Video Capture */
@@ -113,6 +113,24 @@ struct aspeed_clk_gate {
 	[ASPEED_CLK_GATE_LHCCLK] =	{ 28, -1, "lhclk-gate",		"lhclk", 0 }, /* LPC master/LPC+ */
 };
 
+static const char * const eclk_parent_names[] = {
+	"mpll",
+	"hpll",
+	"dpll",
+};
+
+static const struct clk_div_table ast2500_eclk_div_table[] = {
+	{ 0x0, 2 },
+	{ 0x1, 2 },
+	{ 0x2, 3 },
+	{ 0x3, 4 },
+	{ 0x4, 5 },
+	{ 0x5, 6 },
+	{ 0x6, 7 },
+	{ 0x7, 8 },
+	{ 0 }
+};
+
 static const struct clk_div_table ast2500_mac_div_table[] = {
 	{ 0x0, 4 }, /* Yep, really. Aspeed confirmed this is correct */
 	{ 0x1, 4 },
@@ -192,18 +210,21 @@ static struct clk_hw *aspeed_ast2500_calc_pll(const char *name, u32 val)
 
 struct aspeed_clk_soc_data {
 	const struct clk_div_table *div_table;
+	const struct clk_div_table *eclk_div_table;
 	const struct clk_div_table *mac_div_table;
 	struct clk_hw *(*calc_pll)(const char *name, u32 val);
 };
 
 static const struct aspeed_clk_soc_data ast2500_data = {
 	.div_table = ast2500_div_table,
+	.eclk_div_table = ast2500_eclk_div_table,
 	.mac_div_table = ast2500_mac_div_table,
 	.calc_pll = aspeed_ast2500_calc_pll,
 };
 
 static const struct aspeed_clk_soc_data ast2400_data = {
 	.div_table = ast2400_div_table,
+	.eclk_div_table = ast2400_div_table,
 	.mac_div_table = ast2400_div_table,
 	.calc_pll = aspeed_ast2400_calc_pll,
 };
@@ -317,6 +338,7 @@ struct aspeed_reset {
 	[ASPEED_RESET_PECI]	= 10,
 	[ASPEED_RESET_I2C]	=  2,
 	[ASPEED_RESET_AHB]	=  1,
+	[ASPEED_RESET_VIDEO]	=  6,
 
 	/*
 	 * SCUD4 resets start at an offset to separate them from
@@ -522,6 +544,22 @@ static int aspeed_clk_probe(struct platform_device *pdev)
 		return PTR_ERR(hw);
 	aspeed_clk_data->hws[ASPEED_CLK_24M] = hw;
 
+	hw = clk_hw_register_mux(dev, "eclk-mux", eclk_parent_names,
+				 ARRAY_SIZE(eclk_parent_names), 0,
+				 scu_base + ASPEED_CLK_SELECTION, 2, 0x3, 0,
+				 &aspeed_clk_lock);
+	if (IS_ERR(hw))
+		return PTR_ERR(hw);
+	aspeed_clk_data->hws[ASPEED_CLK_ECLK_MUX] = hw;
+
+	hw = clk_hw_register_divider_table(dev, "eclk", "eclk-mux", 0,
+					   scu_base + ASPEED_CLK_SELECTION, 28,
+					   3, 0, soc_data->eclk_div_table,
+					   &aspeed_clk_lock);
+	if (IS_ERR(hw))
+		return PTR_ERR(hw);
+	aspeed_clk_data->hws[ASPEED_CLK_ECLK] = hw;
+
 	/*
 	 * TODO: There are a number of clocks that not included in this driver
 	 * as more information is required:
@@ -531,7 +569,6 @@ static int aspeed_clk_probe(struct platform_device *pdev)
 	 *   RGMII
 	 *   RMII
 	 *   UART[1..5] clock source mux
-	 *   Video Engine (ECLK) mux and clock divider
 	 */
 
 	for (i = 0; i < ARRAY_SIZE(aspeed_gates); i++) {
Signature · 1 line
1.8.3.1
maintainer
#3 lore raw

Re: [PATCH dev-4.19 2/6] clk: aspeed: Setup video engine clocking

drivers/clk/clk-aspeed.c struct aspeed_reset { · line 341

Quoted 13 lines · Eddie James
 static const struct aspeed_gate_data aspeed_gates[] = {
        /*                               clk rst   name                 parent  flags */
drivers/clk/clk-aspeed.c +2 -1
-       [ASPEED_CLK_GATE_ECLK] =        {  0, -1, "eclk-gate",          "eclk", 0 }, /* Video Engine */
+       [ASPEED_CLK_GATE_ECLK] =        {  0,  6, "eclk-gate",          "eclk", 0 }, /* Video Engine */
        [ASPEED_CLK_GATE_GCLK] =        {  1,  7, "gclk-gate",          NULL,   0 }, /* 2D engine */
        [ASPEED_CLK_GATE_MCLK] =        {  2, -1, "mclk-gate",          "mpll", CLK_IS_CRITICAL }, /* SDRAM */
        [ASPEED_CLK_GATE_VCLK] =        {  3,  6, "vclk-gate",          NULL,   0 }, /* Video Capture */
@@ -317,6 +338,7 @@ struct aspeed_reset {
        [ASPEED_RESET_PECI]     = 10,
        [ASPEED_RESET_I2C]      =  2,
        [ASPEED_RESET_AHB]      =  1,
+       [ASPEED_RESET_VIDEO]    =  6,

This is incorrect. You've already added the video reset to the video clock, so the reset will be released by enabling the clock.

If this is the patch that went upstream then upstream needs to be fixed too.

#4 lore raw

Re: [PATCH dev-4.19 2/6] clk: aspeed: Setup video engine clocking

Quoted 16 lines · Joel Stanley

drivers/clk/clk-aspeed.c struct aspeed_reset { · line 341

Quoted 12 lines · Eddie James
  static const struct aspeed_gate_data aspeed_gates[] = {
         /*                               clk rst   name                 parent  flags */
drivers/clk/clk-aspeed.c +2 -1
-       [ASPEED_CLK_GATE_ECLK] =        {  0, -1, "eclk-gate",          "eclk", 0 }, /* Video Engine */
+       [ASPEED_CLK_GATE_ECLK] =        {  0,  6, "eclk-gate",          "eclk", 0 }, /* Video Engine */
         [ASPEED_CLK_GATE_GCLK] =        {  1,  7, "gclk-gate",          NULL,   0 }, /* 2D engine */
         [ASPEED_CLK_GATE_MCLK] =        {  2, -1, "mclk-gate",          "mpll", CLK_IS_CRITICAL }, /* SDRAM */
         [ASPEED_CLK_GATE_VCLK] =        {  3,  6, "vclk-gate",          NULL,   0 }, /* Video Capture */
@@ -317,6 +338,7 @@ struct aspeed_reset {
         [ASPEED_RESET_PECI]     = 10,
         [ASPEED_RESET_I2C]      =  2,
         [ASPEED_RESET_AHB]      =  1,
+       [ASPEED_RESET_VIDEO]    =  6,

This is incorrect. You've already added the video reset to the video clock, so the reset will be released by enabling the clock.

I don't quite understand what's wrong about this. Why can't the clock control and reset control both be done independently? Of course the clock control overrides the reset control, but that's fine, presumably?

I'd rather have the reset available separately, so if this must be changed, I'd prefer to drop the reset from the clock description. That way the video driver doesn't need changes.

Thanks,
Eddie

Quoted 3 lines

If this is the patch that went upstream then upstream needs to be fixed too.

#5 lore raw

Re: [PATCH dev-4.19 2/6] clk: aspeed: Setup video engine clocking

Quoted 22 lines · Eddie James
Quoted 18 lines · Joel Stanley
Quoted 10 lines · Eddie James

  static const struct aspeed_gate_data aspeed_gates[] = {
         /*                               clk rst name                 parent  flags */
-       [ASPEED_CLK_GATE_ECLK] =        {  0, -1,
"eclk-gate",          "eclk", 0 }, /* Video Engine */
+       [ASPEED_CLK_GATE_ECLK] =        {  0,  6,
"eclk-gate",          "eclk", 0 }, /* Video Engine */
         [ASPEED_CLK_GATE_GCLK] =        {  1,  7, "gclk-gate",          NULL,   0 }, /* 2D engine */ [ASPEED_CLK_GATE_MCLK] =        {  2, -1, "mclk-gate",          "mpll", CLK_IS_CRITICAL }, /* SDRAM */ [ASPEED_CLK_GATE_VCLK] =        {  3,  6, "vclk-gate",          NULL,   0 }, /* Video Capture */

drivers/clk/clk-aspeed.c struct aspeed_reset { · line 341

Quoted 4 lines
drivers/clk/clk-aspeed.c +1 -0
@@ -317,6 +338,7 @@ struct aspeed_reset {
          [ASPEED_RESET_PECI]     = 10,
          [ASPEED_RESET_I2C]      =  2,
          [ASPEED_RESET_AHB]      =  1,
+       [ASPEED_RESET_VIDEO]    =  6,

This is incorrect. You've already added the video reset to the video clock, so the reset will be released by enabling the clock.

Quoted 3 lines

I don't quite understand what's wrong about this. Why can't the clock control and reset control both be done independently? Of course the clock control overrides the reset control, but that's fine, presumably?

I'd rather have the reset available separately, so if this must be changed, I'd prefer to drop the reset from the clock description. That way the video driver doesn't need changes.

Nevermind, clock start requires the reset toggle according to the spec, so can't drop that...

Quoted 8 lines

Thanks,
Eddie

Quoted 3 lines

If this is the patch that went upstream then upstream needs to be fixed too.

#6 lore raw

Re: [PATCH dev-4.19 2/6] clk: aspeed: Setup video engine clocking

In reply to Eddie James
Quoted 22 lines · Eddie James
Quoted 18 lines · Joel Stanley
Quoted 10 lines · Eddie James

  static const struct aspeed_gate_data aspeed_gates[] = {
         /*                               clk rst name                 parent  flags */
-       [ASPEED_CLK_GATE_ECLK] =        {  0, -1,
"eclk-gate",          "eclk", 0 }, /* Video Engine */
+       [ASPEED_CLK_GATE_ECLK] =        {  0,  6,
"eclk-gate",          "eclk", 0 }, /* Video Engine */
         [ASPEED_CLK_GATE_GCLK] =        {  1,  7, "gclk-gate",          NULL,   0 }, /* 2D engine */ [ASPEED_CLK_GATE_MCLK] =        {  2, -1, "mclk-gate",          "mpll", CLK_IS_CRITICAL }, /* SDRAM */ [ASPEED_CLK_GATE_VCLK] =        {  3,  6, "vclk-gate",          NULL,   0 }, /* Video Capture */

drivers/clk/clk-aspeed.c struct aspeed_reset { · line 341

Quoted 4 lines
drivers/clk/clk-aspeed.c +1 -0
@@ -317,6 +338,7 @@ struct aspeed_reset {
          [ASPEED_RESET_PECI]     = 10,
          [ASPEED_RESET_I2C]      =  2,
          [ASPEED_RESET_AHB]      =  1,
+       [ASPEED_RESET_VIDEO]    =  6,

This is incorrect. You've already added the video reset to the video clock, so the reset will be released by enabling the clock.

Quoted 1 line

I don't quite understand what's wrong about this. Why can't the clock control and reset control both be done independently? Of course the clock control overrides the reset control, but that's fine, presumably?

Hey Joel,

After some more testing, the driver NEEDS to have the reset available separately. The problem is that the clock driver doesn't enable reset before the clocks turn off, resulting in odd behavior. For example, I get endless IRQs and can't disable them by writing the engine registers, since the clocks are off.

What do you suggest here?

Thanks,
Eddie

Quoted 10 lines

I'd rather have the reset available separately, so if this must be changed, I'd prefer to drop the reset from the clock description. That way the video driver doesn't need changes.

Thanks,
Eddie

Quoted 3 lines

If this is the patch that went upstream then upstream needs to be fixed too.

#7 lore raw

PATCH 3/6 ARM: dts: aspeed-g5: Add video engine node

In reply to Eddie James

From: Eddie James <[email protected]>

Add a node to describe the video engine on the AST2500.

---
 arch/arm/boot/dts/aspeed-g5.dtsi | 11 +++++++++++
 1 file changed, 11 insertions(+)
arch/arm/boot/dts/aspeed-g5.dtsi +11 -0
index f6e630f..8000877 100644
@@ -243,6 +243,17 @@
 				interrupts = <0x19>;
 			};
 
+			video: video@1e700000 {
+				compatible = "aspeed,ast2500-video-engine";
+				reg = <0x1e700000 0x20000>;
+				clocks = <&syscon ASPEED_CLK_GATE_VCLK>,
+					 <&syscon ASPEED_CLK_GATE_ECLK>;
+				clock-names = "vclk", "eclk";
+				resets = <&syscon ASPEED_RESET_VIDEO>;
+				interrupts = <7>;
+				status = "disabled";
+			};
+
 			adc: adc@1e6e9000 {
 				compatible = "aspeed,ast2500-adc";
 				reg = <0x1e6e9000 0xb0>;
Signature · 1 line
1.8.3.1
#8 lore raw

PATCH 4/6 ARM: dts: aspeed: witherspoon: Enable video engine

In reply to Eddie James

From: Eddie James <[email protected]>

Enable the video engine and set it's required memory-region property

---
 arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts +10 -1
index b933ced..2ed09da 100644
@@ -28,7 +28,7 @@
 		};
 
 		gfx_memory: framebuffer {
-			size = <0x01000000>;
+			size = <0x04000000>;
 			alignment = <0x01000000>;
 			compatible = "shared-dma-pool";
 			reusable;
@@ -634,6 +634,15 @@
 	memory-region = <&gfx_memory>;
 };
 
+&video {
+	status = "okay";
+	memory-region = <&gfx_memory>;
+};
+
+&vhub {
+	status = "okay";
+};
+
 &pinctrl {
 	aspeed,external-nodes = <&gfx &lhc>;
 };
Signature · 1 line
1.8.3.1
#9 lore raw

PATCH 5/6 media: dt-bindings: media: Add Aspeed Video Engine binding documentation

In reply to Eddie James

Document the bindings.

---
 .../devicetree/bindings/media/aspeed-video.txt     | 26 ++++++++++++++++++++++
 1 file changed, 26 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/aspeed-video.txt
Documentation/devicetree/bindings/media/aspeed-video.txt new file +26 -0
new file mode 100644
index 0000000..78b464a
@@ -0,0 +1,26 @@
+* Device tree bindings for Aspeed Video Engine
+
+The Video Engine (VE) embedded in the Aspeed AST2400 and AST2500 SOCs can
+capture and compress video data from digital or analog sources.
+
+Required properties:
+ - compatible:		"aspeed,ast2400-video-engine" or
+			"aspeed,ast2500-video-engine"
+ - reg:			contains the offset and length of the VE memory region
+ - clocks:		clock specifiers for the syscon clocks associated with
+			the VE (ordering must match the clock-names property)
+ - clock-names:		"vclk" and "eclk"
+ - resets:		reset specifier for the syscon reset associated with
+			the VE
+ - interrupts:		the interrupt associated with the VE on this platform
+
+Example:
+
+video-engine@1e700000 {
+    compatible = "aspeed,ast2500-video-engine";
+    reg = <0x1e700000 0x20000>;
+    clocks = <&syscon ASPEED_CLK_GATE_VCLK>, <&syscon ASPEED_CLK_GATE_ECLK>;
+    clock-names = "vclk", "eclk";
+    resets = <&syscon ASPEED_RESET_VIDEO>;
+    interrupts = <7>;
+};
Signature · 1 line
1.8.3.1
#10 lore raw

PATCH 6/6 media: platform: Add Aspeed Video Engine driver

In reply to Eddie James

The Video Engine (VE) embedded in the Aspeed AST2400 and AST2500 SOCs can capture and compress video data from digital or analog sources. With the Aspeed chip acting a service processor, the Video Engine can capture the host processor graphics output.

Add a V4L2 driver to capture video data and compress it to JPEG images. Make the video frames available through the V4L2 streaming interface.

---
 MAINTAINERS                           |    8 +
 drivers/media/platform/Kconfig        |    9 +
 drivers/media/platform/Makefile       |    1 +
 drivers/media/platform/aspeed-video.c | 1729 +++++++++++++++++++++++++++++++++
 4 files changed, 1747 insertions(+)
 create mode 100644 drivers/media/platform/aspeed-video.c
MAINTAINERS +8 -0
index b98a576..cdd8f82 100644
@@ -2358,6 +2358,14 @@ S:	Maintained
 F:	Documentation/hwmon/asc7621
 F:	drivers/hwmon/asc7621.c
 
+ASPEED VIDEO ENGINE DRIVER
+M:	Eddie James <[email protected]>
+L:	[email protected]
+L:	[email protected] (moderated for non-subscribers)
+S:	Maintained
+F:	drivers/media/platform/aspeed-video.c
+F:	Documentation/devicetree/bindings/media/aspeed-video.txt
+
 ASUS NOTEBOOKS AND EEEPC ACPI/WMI EXTRAS DRIVERS
 M:	Corentin Chary <[email protected]>
 L:	[email protected]
drivers/media/platform/Kconfig +9 -0
index 54fe90a..d6edf2d 100644
@@ -32,6 +32,15 @@ source "drivers/media/platform/davinci/Kconfig"
 
 source "drivers/media/platform/omap/Kconfig"
 
+config VIDEO_ASPEED
+	tristate "Aspeed AST2400 and AST2500 Video Engine driver"
+	depends on VIDEO_V4L2
+	select VIDEOBUF2_DMA_CONTIG
+	help
+	  Support for the Aspeed Video Engine (VE) embedded in the Aspeed
+	  AST2400 and AST2500 SOCs. The VE can capture and compress video data
+	  from digital or analog sources.
+
 config VIDEO_SH_VOU
 	tristate "SuperH VOU video output driver"
 	depends on MEDIA_CAMERA_SUPPORT
drivers/media/platform/Makefile +1 -0
index 41322ab..205c33a 100644
@@ -3,6 +3,7 @@
 # Makefile for the video capture/playback device drivers.
 #
 
+obj-$(CONFIG_VIDEO_ASPEED)		+= aspeed-video.o
 obj-$(CONFIG_VIDEO_CADENCE)		+= cadence/
 obj-$(CONFIG_VIDEO_VIA_CAMERA) += via-camera.o
 obj-$(CONFIG_VIDEO_CAFE_CCIC) += marvell-ccic/
drivers/media/platform/aspeed-video.c new file +1729 -0

1,729 lines not on this page · raw message

Signature · 1 line
1.8.3.1
maintainer
#11 lore raw

Re: [PATCH dev-4.19 6/6] media: platform: Add Aspeed Video Engine driver

Quoted 7 lines · Eddie James
drivers/media/platform/aspeed-video.c new file +7 -0
+       video->eclk = devm_clk_get(dev, "eclk");
+       if (IS_ERR(video->eclk)) {
+               dev_err(dev, "Unable to get ECLK\n");
+               return PTR_ERR(video->eclk);
+       }
+
+       video->vclk = devm_clk_get(dev, "vclk");

drivers/media/platform/aspeed-video.c line 1626

Quoted 10 lines
drivers/media/platform/aspeed-video.c new file +10 -0
+       if (IS_ERR(video->vclk)) {
+               dev_err(dev, "Unable to get VCLK\n");
+               return PTR_ERR(video->vclk);
+       }
+
+       video->rst = devm_reset_control_get_exclusive(dev, NULL);
+       if (IS_ERR(video->rst)) {
+               dev_err(dev, "Unable to get VE reset\n");
+               return PTR_ERR(video->rst);
+       }

Once you've fixed the clock you will need to fix this too.

I suggest we do this before merging as it will also lead to device tree changes.