media: platform: Add Aspeed Video Engine driver
Subsystems (3)
v8 cover media: platform: Add Aspeed Video Engine driver
From: Eddie James <[email protected]>
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 as a service processor, the Video Engine can capture the host processor graphics output.
This series adds a V4L2 driver for the VE, providing the usual V4L2 streaming interface by way of videobuf2. Each frame, the driver triggers the hardware to capture the host graphics output and compress it to JPEG format.
v4l2-compliance SHA: d039b47a108596ca004b11e52989054882d45888, 32 bits
Compliance test for device /dev/video0:
Driver Info:
Driver name : aspeed-video Card type : Aspeed Video Engine Bus info : platform:aspeed-video Driver version : 4.19.6 Capabilities : 0x85200001
Video Capture
Read/Write
Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x05200001
Video Capture
Read/Write
Streaming
Extended Pix Format
Required ioctls:
test VIDIOC_QUERYCAP: OK
Allow for multiple opens:
test second /dev/video0 open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK
Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported) test VIDIOC_LOG_STATUS: OK (Not Supported)
Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported) test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK
test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 1 Audio Inputs: 0 Tuners: 0
Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_ENUMAUDOUT: OK (Not Supported) test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported) test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0
Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported) test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK test VIDIOC_DV_TIMINGS_CAP: OK
test VIDIOC_G/S_EDID: OK (Not Supported)
Control ioctls (Input 0):
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK
test VIDIOC_QUERYCTRL: OK
test VIDIOC_G/S_CTRL: OK
test VIDIOC_G/S/TRY_EXT_CTRLS: OK
warn: v4l2-test-controls.cpp(853): V4L2_CID_DV_RX_POWER_PRESENT not found for input 0
test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK
test VIDIOC_G/S_JPEGCOMP: OK (Not Supported)
Standard Controls: 3 Private Controls: 0
Format ioctls (Input 0):
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK test VIDIOC_G/S_PARM: OK
test VIDIOC_G_FBUF: OK (Not Supported) test VIDIOC_G_FMT: OK
test VIDIOC_TRY_FMT: OK
test VIDIOC_S_FMT: OK
test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported) test Cropping: OK (Not Supported)
test Composing: OK (Not Supported)
test Scaling: OK (Not Supported)
Codec ioctls (Input 0):
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported) test VIDIOC_G_ENC_INDEX: OK (Not Supported) test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)
Buffer ioctls (Input 0):
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK test VIDIOC_EXPBUF: OK
test Requests: OK (Not Supported)
Test input 0:
Streaming ioctls:
test read/write: OK
test blocking wait: OK
test MMAP: OK
test USERPTR: OK (Not Supported)
test DMABUF: Cannot test, specify --expbuf-device
Total: 48, Succeeded: 48, Failed: 0, Warnings: 1
I'm unable to run linux-next or the media tree as our system doesn't boot without quite a few patches that aren't yet upstreamed, so I can't grab the fix for that warning Hans mentioned.
Changes since v7:
- Fix the check for sending the source change event to include acquiring or losing a signal without changing resolution
- Fix return value of query_timings to reflect signal status
- Added and improved a few comments
Changes since v6:
- Refactor open/start process such that the file handle can be opened without a video signal present
- Added standards and capabilities
- Removed used of VB2_BUF_FLAG_LAST
- Added a few comments
- Removed a couple of functions that were only used once
- Removed client counter
Changes since v5:
- Rework resolution change and v4l2 timings functions again with active and detected timings.
- Renamed a few things.
- Fixed polarities in the timings.
Changes since v4:
- Set real min and max resolution in enum_dv_timings
- Add check for vb2_is_busy before settings the timings
- Set max frame rate to the actual max rather than max + 1
- Correct the input status to 0.
- Rework resolution change to only set the relevant h/w regs during startup or when set_timings is called.
Changes since v3:
- Switch update reg function to use u32 clear rather than unsigned long mask
- Add timing information from host VGA signal
- Fix binding documentation mispelling
- Fix upper case hex values
- Add wait_prepare and wait_finish
- Set buffer state to queued (rather than error) if streaming fails to start
- Switch engine busy print statement to error
- Removed a couple unecessary type assignments in v4l2 ioctls
- Added query_dv_timings, fixed get_dv_timings
- Corrected source change event to fire if and only if size actually changes
- Locked open and release
Changes since v2:
- Switch to streaming interface. This involved a lot of changes.
- Rework memory allocation due to using videobuf2 buffers, but also only allocate the necessary size of source buffer rather than the max size
Changes since v1:
- Removed le32_to_cpu calls for JPEG header data
- Reworked v4l2 ioctls to be compliant.
- Added JPEG controls
- Updated devicetree docs according to Rob's suggestions.
- Added myself to MAINTAINERS
Eddie James (2):
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 + drivers/media/platform/Kconfig | 9 + drivers/media/platform/Makefile | 1 + drivers/media/platform/aspeed-video.c | 1729 ++++++++++++++++++++ 5 files changed, 1773 insertions(+) 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
PATCH v8 1/2 dt-bindings: media: Add Aspeed Video Engine binding documentation
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
@@ -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 at 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
PATCH v8 2/2 media: platform: Add Aspeed Video Engine driver
In reply to Eddie JamesThe 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
@@ -2427,6 +2427,14 @@ S: Maintained F: Documentation/hwmon/asc7621 F: drivers/hwmon/asc7621.c +ASPEED VIDEO ENGINE DRIVER +M: Eddie James <[email protected]> +L: linux-media at vger.kernel.org +L: openbmc at lists.ozlabs.org (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: acpi4asus-user at lists.sourceforge.net
drivers/media/platform/Kconfig +9 -0
@@ -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
@@ -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
Joel Stanley
maintainerMAINTAINERS S: Maintained · line 2433
Quoted 10 lines · 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.
MAINTAINERS +4
-0+ASPEED VIDEO ENGINE DRIVER +M: Eddie James <[email protected]> +L: linux-media at vger.kernel.org +L: openbmc at lists.ozlabs.org (moderated for non-subscribers)
We tend to use the linux-aspeed list for upstream kernel discussions. Up to you if you want to use the openbmc list though.
drivers/media/platform/Kconfig source "drivers/media/platform/davinci/Kconfig" · line 42
Quoted 10 lines
source "
drivers/media/platform/omap/Kconfig"drivers/media/platform/Kconfig +8
-0+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.
This might need updating in response to my questions below about ast2400 testing.
drivers/media/platform/aspeed-video.c line 1
Quoted 3 lines
+++
b/drivers/media/platform/aspeed-video.cdrivers/media/platform/aspeed-video.c new file +1
-0@@ -0,0 +1,1729 @@ +// SPDX-License-Identifier: GPL-2.0+
You need to put this there as well:
// Copyright 2018 IBM Corp
drivers/media/platform/aspeed-video.c line 1603
Quoted 13 lines
drivers/media/platform/aspeed-video.c new file +13
-0+static int aspeed_video_init (struct aspeed_video *video) +{ +int irq; +int rc; +struct device *dev = video->dev; + + irq =irq_of_parse_and_map (dev->of_node,0 ); +if (!irq) { +dev_err (dev,"Unable to find IRQ\n" ); +return -ENODEV ; + } + + rc = devm_request_irq(dev, irq, aspeed_video_irq, IRQF_SHARED,
The datasheet indicates this IRQ is for the video engline only, so I don't think you want IRQF_SHARED.
Quoted 13 lines
drivers/media/platform/aspeed-video.c new file +13
-0+ DEVICE_NAME, video); +if (rc <0 ) { +dev_err (dev,"Unable to request IRQ %d\n" , irq); +return rc; + } + + 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); + }
As discussed in the clock driver, this can go as you've already released the reset when enabling the eclk.
However, you're requesting the clock without enabling it. You need to do a clk_prepare_enable().
Quoted 19 lines
drivers/media/platform/aspeed-video.c new file +19
-0+ + rc =of_reserved_mem_device_init (dev); +if (rc) { +dev_err (dev,"Unable to reserve memory\n" ); +return rc; + } + + rc =dma_set_mask_and_coherent (dev,DMA_BIT_MASK (32 )); +if (rc) { +dev_err (dev,"Failed to set DMA mask\n" ); +of_reserved_mem_device_release (dev); +return rc; + } + +if (!aspeed_video_alloc_buf (video, &video->jpeg, +VE_JPEG_HEADER_SIZE )) { +dev_err (dev,"Failed to allocate DMA for JPEG header\n" ); +of_reserved_mem_device_release (dev); +return rc;
drivers/media/platform/aspeed-video.c line 1710
Quoted 10 lines
drivers/media/platform/aspeed-video.c new file +9
-0+ } + +aspeed_video_init_jpeg_table (video->jpeg.virt, video->yuv420); + +return 0 ; +} + +static const struct of_device_id aspeed_video_of_match[] = { + { .compatible ="aspeed,ast2400-video-engine" },
I noticed the clock driver did not have the changed required for the 2400. Have you tested this on the ast2400?
Quoted 13 lines
drivers/media/platform/aspeed-video.c new file +13
-0+ { .compatible = "aspeed,ast2500-video-engine" }, + {} +}; +MODULE_DEVICE_TABLE (of, aspeed_video_of_match); + +static struct platform_driver aspeed_video_driver = { + .driver = { + .name =DEVICE_NAME , + .of_match_table = aspeed_video_of_match, + }, + .probe = aspeed_video_probe, + .remove = aspeed_video_remove, +};
Quoted 66 lines · Joel Stanley
MAINTAINERS S: Maintained · line 2433
Quoted 8 lines · 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.
MAINTAINERS +4
-0+ASPEED VIDEO ENGINE DRIVER +M: Eddie James <[email protected]> +L: linux-media at vger.kernel.org +L: openbmc at lists.ozlabs.org (moderated for non-subscribers)We tend to use the linux-aspeed list for upstream kernel discussions. Up to you if you want to use the openbmc list though.
drivers/media/platform/Kconfig source "drivers/media/platform/davinci/Kconfig" · line 42
Quoted 10 lines
source "
drivers/media/platform/omap/Kconfig"drivers/media/platform/Kconfig +8
-0+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.This might need updating in response to my questions below about ast2400 testing.
drivers/media/platform/aspeed-video.c line 1
Quoted 3 lines
+++
b/drivers/media/platform/aspeed-video.cdrivers/media/platform/aspeed-video.c new file +1
-0@@ -0,0 +1,1729 @@ +// SPDX-License-Identifier: GPL-2.0+ You need to put this there as well:
// Copyright 2018 IBM Corp
drivers/media/platform/aspeed-video.c line 1603
Quoted 13 lines
drivers/media/platform/aspeed-video.c new file +13
-0+static int aspeed_video_init (struct aspeed_video *video) +{ +int irq; +int rc; +struct device *dev = video->dev; + + irq =irq_of_parse_and_map (dev->of_node,0 ); +if (!irq) { +dev_err (dev,"Unable to find IRQ\n" ); +return -ENODEV ; + } + + rc = devm_request_irq(dev, irq, aspeed_video_irq, IRQF_SHARED,The datasheet indicates this IRQ is for the video engline only, so I don't think you want
IRQF_SHARED.Quoted 17 lines
drivers/media/platform/aspeed-video.c new file +17
-0+ DEVICE_NAME, video); +if (rc <0 ) { +dev_err (dev,"Unable to request IRQ %d\n" , irq); +return rc; + } + + 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" ); +if (IS_ERR (video->vclk)) { +dev_err (dev,"Unable to get VCLK\n" ); +return PTR_ERR (video->vclk); + }
Quoted 8 lines
drivers/media/platform/aspeed-video.c line 1626
Quoted 6 lines
drivers/media/platform/aspeed-video.c new file +6
-0+ + 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); + }As discussed in the clock driver, this can go as you've already released the reset when enabling the eclk.
I use the reset control by itself during a resolution change, so I would like to have it available.
Quoted 3 lines
However, you're requesting the clock without enabling it. You need to do a
clk_prepare_enable().
That's because the clock is only enabled when the device is opened. No reason to turn it on at boot time.
Quoted 23 lines
Quoted 23 lines
drivers/media/platform/aspeed-video.c new file +22
-0+ + rc =of_reserved_mem_device_init (dev); +if (rc) { +dev_err (dev,"Unable to reserve memory\n" ); +return rc; + } + + rc =dma_set_mask_and_coherent (dev,DMA_BIT_MASK (32 )); +if (rc) { +dev_err (dev,"Failed to set DMA mask\n" ); +of_reserved_mem_device_release (dev); +return rc; + } + +if (!aspeed_video_alloc_buf (video, &video->jpeg, +VE_JPEG_HEADER_SIZE )) { +dev_err (dev,"Failed to allocate DMA for JPEG header\n" ); +of_reserved_mem_device_release (dev); +return rc; + } + +aspeed_video_init_jpeg_table (video->jpeg.virt, video->yuv420);
Quoted 8 lines
drivers/media/platform/aspeed-video.c line 1710
Quoted 6 lines
drivers/media/platform/aspeed-video.c new file +6
-0+ +return 0 ; +} + +static const struct of_device_id aspeed_video_of_match[] = { + { .compatible ="aspeed,ast2400-video-engine" },I noticed the clock driver did not have the changed required for the 2400. Have you tested this on the ast2400?
The clocking setup is different on the ast2400. Xiuzhi on the openbmc list has been testing on the ast2400 successfully.
Thanks,
Eddie
Quoted 15 lines
Quoted 15 lines
drivers/media/platform/aspeed-video.c new file +13
-0+ { .compatible = "aspeed,ast2500-video-engine" }, + {} +}; +MODULE_DEVICE_TABLE (of, aspeed_video_of_match); + +static struct platform_driver aspeed_video_driver = { + .driver = { + .name =DEVICE_NAME , + .of_match_table = aspeed_video_of_match, + }, + .probe = aspeed_video_probe, + .remove = aspeed_video_remove, +};