media: sun6i: One regmap fix and support RGB565 and JPEG
Subsystems (4)
cover media: sun6i: One regmap fix and support RGB565 and JPEG
Hi everyone,
This series is adds support for two (three if you count big / little endian) media bus formats to the sun6i-csi driver. There's also a small fix for an exception I encountered while working on this.
Both modes were tested using an OV5640 sensor. To use JPEG, the patch "media: ov5640: Set JPEG output timings when outputting JPEG data" from my "media: ov5640: JPEG and test pattern improvements" series is also needed.
I prepared this series on 1/18, alone with the "media: ov5640: Set JPEG output timings when outputting JPEG data", but ended up forgetting to send out this one.
Please have a look.
Regards
ChenYu
Chen-Yu Tsai (3):
media: sun6i: Fix CSI regmap's max_register
media: sun6i: Add support for RGB565 formats
media: sun6i: Add support for JPEG media bus format
.../platform/sunxi/sun6i-csi/sun6i_csi.c | 27 ++++++++++++++++--- .../platform/sunxi/sun6i-csi/sun6i_csi.h | 3 +++ .../platform/sunxi/sun6i-csi/sun6i_video.c | 3 +++ 3 files changed, 30 insertions(+), 3 deletions(-)
Signature · 1 line
2.20.1
PATCH 1/3 media: sun6i: Fix CSI regmap's max_register
max_register is currently set to 0x1000. This is beyond the mapped address range of the hardware, so attempts to dump the regmap from debugfs would trigger a kernel exception.
Furthermore, the useful registers only occupy a small section at the beginning of the full range. Change the value to 0x9c, the last known register on the V3s and H3.
On the A31, the register range is extended to support additional capture channels. Since this is not yet supported, ignore it for now.
--- drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c +1 -1
@@ -793,7 +793,7 @@ static const struct regmap_config sun6i_csi_regmap_config = { .reg_bits = 32, .reg_stride = 4, .val_bits = 32, - .max_register = 0x1000, + .max_register = 0x9c, }; static int sun6i_csi_resource_request(struct sun6i_csi_dev *sdev,
Signature · 1 line
2.20.1
Re: [PATCH 1/3] media: sun6i: Fix CSI regmap's max_register
Quoted 8 lines · Chen-Yu Tsai
max_registeris currently set to0x1000. This is beyond the mapped address range of the hardware, so attempts to dump the regmap from debugfs would trigger a kernel exception.Furthermore, the useful registers only occupy a small section at the beginning of the full range. Change the value to
0x9c, the last known register on the V3s and H3.
Quoted 6 lines
On the A31, the register range is extended to support additional capture channels. Since this is not yet supported, ignore it for now.
Fixes 5cc7522d8965 ("media: sun6i: Add support for Allwinner CSI V3s")Cc <[email protected]>Signed-off-by Chen-Yu Tsai <[email protected]>
Maxime
Signature · 3 lines
Maxime Ripard, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
PATCH 2/3 media: sun6i: Add support for RGB565 formats
In reply to Chen-Yu TsaiThe CSI controller can take raw data from the data bus and output RGB565 format. The controller does not distinguish between RGB565 LE and BE. Instead this is determined by the media bus format, i.e. the format or order the sensor is sending data in.
--- .../platform/sunxi/sun6i-csi/sun6i_csi.c | 19 +++++++++++++++++-- .../platform/sunxi/sun6i-csi/sun6i_csi.h | 2 ++ .../platform/sunxi/sun6i-csi/sun6i_video.c | 2 ++ 3 files changed, 21 insertions(+), 2 deletions(-)
drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c +17 -2
@@ -143,6 +143,12 @@ bool sun6i_csi_is_format_supported(struct sun6i_csi *csi,break ; }break ; + +case V4L2_PIX_FMT_RGB565 : +return (mbus_code ==MEDIA_BUS_FMT_RGB565_2X8_LE ); +case V4L2_PIX_FMT_RGB565X : +return (mbus_code ==MEDIA_BUS_FMT_RGB565_2X8_BE ); +default :dev_dbg (sdev->dev,"Unsupported pixformat: 0x%x\n" , pixformat);break ;
@@ -198,8 +204,8 @@ int sun6i_csi_set_power(struct sun6i_csi *csi, bool enable)static enum csi_input_fmt get_csi_input_format (struct sun6i_csi_dev *sdev,u32 mbus_code,u32 pixformat) { -/* bayer */ -if ((mbus_code &0xF000 ) ==0x3000 ) +/* non-YUV */ +if ((mbus_code &0xF000 ) !=0x2000 )return CSI_INPUT_FORMAT_RAW ;switch (pixformat) {
@@ -268,6 +274,11 @@ static enum csi_output_fmt get_csi_output_format(struct sun6i_csi_dev *sdev,case V4L2_PIX_FMT_YUV422P :return buf_interlaced ?CSI_FRAME_PLANAR_YUV422 :CSI_FIELD_PLANAR_YUV422 ; + +case V4L2_PIX_FMT_RGB565 : +case V4L2_PIX_FMT_RGB565X : +return buf_interlaced ?CSI_FRAME_RGB565 :CSI_FIELD_RGB565 ; +default :dev_warn (sdev->dev,"Unsupported pixformat: 0x%x\n" , pixformat);break ;
@@ -279,6 +290,10 @@ static enum csi_output_fmt get_csi_output_format(struct sun6i_csi_dev *sdev,static enum csi_input_seq get_csi_input_seq (struct sun6i_csi_dev *sdev,u32 mbus_code,u32 pixformat) { +/* Input sequence does not apply to non-YUV formats */ +if ((mbus_code &0xF000 ) !=0x2000 ) +return 0 ; +switch (pixformat) {case V4L2_PIX_FMT_HM12 :case V4L2_PIX_FMT_NV12 :
drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.h +2 -0
@@ -117,6 +117,8 @@ static inline int sun6i_csi_get_bpp(unsigned int pixformat)case V4L2_PIX_FMT_NV16 :case V4L2_PIX_FMT_NV61 :case V4L2_PIX_FMT_YUV422P : +case V4L2_PIX_FMT_RGB565 : +case V4L2_PIX_FMT_RGB565X :return 16 ;case V4L2_PIX_FMT_RGB24 :case V4L2_PIX_FMT_BGR24 :
drivers/media/platform/sunxi/sun6i-csi/sun6i_video.c +2 -0
@@ -56,6 +56,8 @@ static const u32 supported_pixformats[] = {V4L2_PIX_FMT_NV16 ,V4L2_PIX_FMT_NV61 ,V4L2_PIX_FMT_YUV422P , +V4L2_PIX_FMT_RGB565 , + V4L2_PIX_FMT_RGB565X, };static bool is_pixformat_valid (unsigned int pixformat)
Signature · 1 line
2.20.1
Re: [PATCH 2/3] media: sun6i: Add support for RGB565 formats
Quoted 6 lines · Chen-Yu Tsai
The CSI controller can take raw data from the data bus and output RGB565 format. The controller does not distinguish between RGB565 LE and BE. Instead this is determined by the media bus format, i.e. the format or order the sensor is sending data in.
Signed-off-by Chen-Yu Tsai <[email protected]>
Maxime
Signature · 3 lines
Maxime Ripard, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
PATCH 3/3 media: sun6i: Add support for JPEG media bus format
In reply to Chen-Yu TsaiThe CSI controller can take raw data from the data bus and output it directly to capture buffers. This can be used to support the JPEG media bus format.
While the controller can report minimum and maximum bytes per line, it has no way to report how many lines were captured in the last frame. Thus, even when the on-bus data is framed correctly, we have no way to accertain the actual amount of data captured, unless we scan the buffer for JPEG EOI markers, or sequential zeros. For now we leave bytesused alone, and leave it up to userspace applications to parse the data.
--- drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c | 6 ++++++ drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.h | 1 + drivers/media/platform/sunxi/sun6i-csi/sun6i_video.c | 1 + 3 files changed, 8 insertions(+)
drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c +6 -0
@@ -149,6 +149,9 @@ bool sun6i_csi_is_format_supported(struct sun6i_csi *csi,case V4L2_PIX_FMT_RGB565X :return (mbus_code ==MEDIA_BUS_FMT_RGB565_2X8_BE ); +case V4L2_PIX_FMT_JPEG : +return (mbus_code ==MEDIA_BUS_FMT_JPEG_1X8 ); +default :dev_dbg (sdev->dev,"Unsupported pixformat: 0x%x\n" , pixformat);break ;
@@ -279,6 +282,9 @@ static enum csi_output_fmt get_csi_output_format(struct sun6i_csi_dev *sdev,case V4L2_PIX_FMT_RGB565X :return buf_interlaced ?CSI_FRAME_RGB565 :CSI_FIELD_RGB565 ; +case V4L2_PIX_FMT_JPEG : +return buf_interlaced ?CSI_FRAME_RAW_8 :CSI_FIELD_RAW_8 ; +default :dev_warn (sdev->dev,"Unsupported pixformat: 0x%x\n" , pixformat);break ;
drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.h +1 -0
@@ -94,6 +94,7 @@ static inline int sun6i_csi_get_bpp(unsigned int pixformat)case V4L2_PIX_FMT_SGBRG8 :case V4L2_PIX_FMT_SGRBG8 :case V4L2_PIX_FMT_SRGGB8 : +case V4L2_PIX_FMT_JPEG :return 8 ;case V4L2_PIX_FMT_SBGGR10 :case V4L2_PIX_FMT_SGBRG10 :
drivers/media/platform/sunxi/sun6i-csi/sun6i_video.c +1 -0
@@ -58,6 +58,7 @@ static const u32 supported_pixformats[] = {V4L2_PIX_FMT_YUV422P ,V4L2_PIX_FMT_RGB565 ,V4L2_PIX_FMT_RGB565X , + V4L2_PIX_FMT_JPEG, };static bool is_pixformat_valid (unsigned int pixformat)
Signature · 1 line
2.20.1