Re: [PATCHv4] [media] rcar-vin: add Renesas R-Car VIN driver
On 2016-04-21 08:55:46 +0200, Hans Verkuil wrote: > On 04/12/2016 04:33 PM, Niklas Söderlund wrote: > > +static void rect_set_min_size(struct v4l2_rect *r, > > + const struct v4l2_rect *min_size) > > +{ > > + if (r->width < min_size->width) > > + r->width = min_size->width; > > + if (r->height < min_size->height) > > + r->height = min_size->height; > > +} > > + > > +static void rect_set_max_size(struct v4l2_rect *r, > > + const struct v4l2_rect *max_size) > > +{ > > + if (r->width > max_size->width) > > + r->width = max_size->width; > > + if (r->height > max_size->height) > > + r->height = max_size->height; > > +} > > + > > +static void rect_map_inside(struct v4l2_rect *r, > > + const struct v4l2_rect *boundary) > > +{ > > + rect_set_max_size(r, boundary); > > + > > + if (r->left < boundary->left) > > + r->left = boundary->left; > > + if (r->top < boundary->top) > > + r->top = boundary->top; > > + if (r->left + r->width > boundary->width) > > + r->left = boundary->width - r->width; > > + if (r->top + r->height > boundary->height) > > + r->top = boundary->height - r->height; > > +} > > + > > The v4l2-rect.h helpers have been merged, so you should be able to use > those for v5 and drop these functions here. Thanks I'm about to send out a v5 so this was good timing. I did just discover one odd behavior in the driver I would like to look in to today. But will include the v4l2-rect.h helpers in v5. -- Regards, Niklas Söderlund -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCHv4] [media] rcar-vin: add Renesas R-Car VIN driver
On 04/12/2016 04:33 PM, Niklas Söderlund wrote: > +static void rect_set_min_size(struct v4l2_rect *r, > + const struct v4l2_rect *min_size) > +{ > + if (r->width < min_size->width) > + r->width = min_size->width; > + if (r->height < min_size->height) > + r->height = min_size->height; > +} > + > +static void rect_set_max_size(struct v4l2_rect *r, > + const struct v4l2_rect *max_size) > +{ > + if (r->width > max_size->width) > + r->width = max_size->width; > + if (r->height > max_size->height) > + r->height = max_size->height; > +} > + > +static void rect_map_inside(struct v4l2_rect *r, > + const struct v4l2_rect *boundary) > +{ > + rect_set_max_size(r, boundary); > + > + if (r->left < boundary->left) > + r->left = boundary->left; > + if (r->top < boundary->top) > + r->top = boundary->top; > + if (r->left + r->width > boundary->width) > + r->left = boundary->width - r->width; > + if (r->top + r->height > boundary->height) > + r->top = boundary->height - r->height; > +} > + The v4l2-rect.h helpers have been merged, so you should be able to use those for v5 and drop these functions here. Regards, Hans -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCHv4] [media] rcar-vin: add Renesas R-Car VIN driver
Hi Niklas, Thanks for the patch. I've been testing this a bit more and there are a few things missing. On 04/12/2016 04:33 PM, Niklas Söderlund wrote: > diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c > b/drivers/media/platform/rcar-vin/rcar-v4l2.c > new file mode 100644 > index 000..a752171 > --- /dev/null > +++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c > @@ -0,0 +1,732 @@ > +/* > + * Driver for Renesas R-Car VIN > + * > + * Copyright (C) 2016 Renesas Electronics Corp. > + * Copyright (C) 2011-2013 Renesas Solutions Corp. > + * Copyright (C) 2013 Cogent Embedded, Inc.,> + * Copyright (C) 2008 Magnus Damm > + * > + * Based on the soc-camera rcar_vin driver > + * > + * This program is free software; you can redistribute it and/or modify it > + * under the terms of the GNU General Public License as published by the > + * Free Software Foundation; either version 2 of the License, or (at your > + * option) any later version. > + */ > + > +#include > + > +#include > +#include > + > +#include "rcar-vin.h" > + > +#define RVIN_DEFAULT_FORMAT V4L2_PIX_FMT_YUYV > +#define RVIN_MAX_WIDTH 2048 > +#define RVIN_MAX_HEIGHT 2048 > + > +/* > - > + * Format Conversions > + */ > + > +static const struct rvin_video_format rvin_formats[] = { > + { > + .fourcc = V4L2_PIX_FMT_NV16, > + .bpp= 1, > + }, > + { > + .fourcc = V4L2_PIX_FMT_YUYV, > + .bpp= 2, > + }, > + { > + .fourcc = V4L2_PIX_FMT_UYVY, > + .bpp= 2, > + }, > + { > + .fourcc = V4L2_PIX_FMT_RGB565, > + .bpp= 2, > + }, > + { > + .fourcc = V4L2_PIX_FMT_XRGB555, > + .bpp= 2, > + }, > + { > + .fourcc = V4L2_PIX_FMT_XBGR32, > + .bpp= 4, > + }, > +}; > + > +const struct rvin_video_format *rvin_format_from_pixel(u32 pixelformat) > +{ > + int i; > + > + for (i = 0; i < ARRAY_SIZE(rvin_formats); i++) > + if (rvin_formats[i].fourcc == pixelformat) > + return rvin_formats + i; > + > + return NULL; > +} > + > +static u32 rvin_format_bytesperline(struct v4l2_pix_format *pix) > +{ > + const struct rvin_video_format *fmt; > + > + fmt = rvin_format_from_pixel(pix->pixelformat); > + > + if (WARN_ON(!fmt)) > + return -EINVAL; > + > + return pix->width * fmt->bpp; > +} > + > +static u32 rvin_format_sizeimage(struct v4l2_pix_format *pix) > +{ > + if (pix->pixelformat == V4L2_PIX_FMT_NV16) > + return pix->bytesperline * pix->height * 2; > + > + return pix->bytesperline * pix->height; > +} > + > +/* > - > + * V4L2 > + */ > + > +static int __rvin_try_format_sensor(struct rvin_dev *vin, > + u32 which, > + struct v4l2_pix_format *pix, > + struct rvin_sensor *sensor) > +{ > + struct v4l2_subdev *sd; > + struct v4l2_subdev_pad_config pad_cfg; > + struct v4l2_subdev_format format = { > + .which = which, > + }; > + int ret; > + > + sd = vin_to_sd(vin); > + > + v4l2_fill_mbus_format(, pix, vin->sensor.code); > + > + ret = v4l2_device_call_until_err(sd->v4l2_dev, 0, pad, set_fmt, > + _cfg, ); > + if (ret < 0) > + return ret; > + > + v4l2_fill_pix_format(pix, ); > + > + sensor->width = pix->width; > + sensor->height = pix->height; > + > + vin_dbg(vin, "Sensor format: %ux%u\n", sensor->width, sensor->height); > + > + return 0; > +} > + > +static int __rvin_try_format(struct rvin_dev *vin, > + u32 which, > + struct v4l2_pix_format *pix, > + struct rvin_sensor *sensor) > +{ > + const struct rvin_video_format *info; > + u32 rwidth, rheight, walign; > + > + /* Requested */ > + rwidth = pix->width; > + rheight = pix->height; > + > + /* > + * Retrieve format information and select the current format if the > + * requested format isn't supported. > + */ > + info = rvin_format_from_pixel(pix->pixelformat); > + if (!info) { > + vin_dbg(vin, "Format %x not found, keeping %x\n", > + pix->pixelformat, vin->format.pixelformat); > + *pix = vin->format; > + pix->width = rwidth; > + pix->height = rheight; > + } > + > + /* Always recalculate */ > +
[PATCHv4] [media] rcar-vin: add Renesas R-Car VIN driver
A V4L2 driver for Renesas R-Car VIN driver that do not depend on soc_camera. The driver is heavily based on its predecessor and aims to replace it. Signed-off-by: Niklas Söderlund--- The driver is tested on Koelsch and can do streaming using qv4l2 and grab frames using yavta. It passes a v4l2-compliance (git master) run without any failures, see bellow for output. Some issues I know about but will have to wait for future work in other patches. - One can not bind/unbind the subdevice and continue using the driver. - Do not support FIELD_ALTERNATE. - Suggested compat string "renesas,rcar-gen2-vin" is not included. Will address this in a separate patch together with gen3. The goal is to replace the soc_camera driver completely to prepare for Gen3 enablement. I have therefor chosen to inherit the CONFIG_VIDEO_RCAR_VIN name for this new driver and renamed the soc_camera driver CONFIG_VIDEO_RCAR_VIN_OLD. * Changes since v3 - Print error and return EINVAL instead of ENOBUFS if there is not enough buffers to fill HW in start_streaming. This error should not happen since 'min_buffers_needed' should ensure it never happens but we check for the condition anyhow. - Return all buffers with state VB2_BUF_STATE_QUEUED if there is an error in start_streaming. * Changes since v2 - Fix review comments from Hans Verkuil, thanks! - Update description in Kconfig - Drop V4L2_SEL_TGT_COMPOSE_PADDED - Wrong size for NV16 image - Copy ycbcr_enc and xfer_func when keeping old format. - Add vidioc_cropcap - Return -ENOBUFS in start_streaming to signal more buffers are needed instead of sleeping in a critical section... - Move all v4l2 ioctls and file ops to rcar-v4l2.c (and as a follow up moved all HW functions to rcar-dma.c to increase readability). - Fixed RGB formats 's/V4L2_PIX_FMT_RGB555X/V4L2_PIX_FMT_XRGB555' and 's/V4L2_PIX_FMT_RGB32/V4L2_PIX_FMT_XBGR32'. This was an error carried over from soc-camera dirver, whit this fix I get correct colors in qv4l2. - Rework how media bus type and flags are handled. Instead of defining own values and a unsigned int use struct v4l2_mbus_config to store the configuration parsed from DT. - Remove duplicated code from the v4l2_file_operations release code path. There is no need to try and stop the streaming from here. If start_streaming have been called stop_streaming will be called by the framework stopping the streaming. - Remove all special checks for the chip RCAR_E1. There are no compat string that will select this chip model. Neither for this driver or its predecessor in soc-camera. - Force an width alignment of 32 if the NV16 format is used due to HW limitation. * Changes since RFC/PATCH - Fixed review comments from Hans Verkuil, thanks for reviewing. - Added vidioc_[gs]_selection crop and composition is supported. Thanks Laurent for taking the time and explaining to me how to do composition. - Reworked the DMA flow to better support single and continues frame grabbing mode. - Dropped a lot of the formats that was ported from soc_camera, once I looked at it in a working driver it was obvious that the rcar_vin soc_camera driver did not support them. - Added better comments for the core structs - Fixed copyright in file headers - A lot more testing. I have made a few small additions to the adv7180.c driver while doing this driver but are posted in a separate patch. For completeness I included the output of v4l2-compliance both with and with out the adv7180 enhancements. The adv7180 additions enables the std and tvnorms code paths so it tests a bit more of this driver. There is a failure reported here but it's a false positive and is addressed in Hans Verkuil series '[PATCHv2 0/2] v4l2-ioctl: cropcap improvement'. If I apply that series to my tree the failure goes away. (without adv7180 enhancements) # ./v4l2-compliance -d 27 -s -f Driver Info: Driver name : rcar_vin Card type : R_Car_VIN Bus info : platform:e6ef1000.video Driver version: 4.6.0 Capabilities : 0x8521 Video Capture Read/Write Streaming Extended Pix Format Device Capabilities Device Caps : 0x0521 Video Capture Read/Write Streaming Extended Pix Format Compliance test for device /dev/video27 (not using libv4l2): Required ioctls: test VIDIOC_QUERYCAP: OK Allow for multiple opens: test second video open: OK test VIDIOC_QUERYCAP: OK test VIDIOC_G/S_PRIORITY: OK Debug ioctls: test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported) test VIDIOC_LOG_STATUS: OK 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