From: Sakari Ailus <sakari.ailus@linux.intel.com> To: Jacopo Mondi <jacopo@jmondi.org> Cc: mchehab@kernel.org, hverkuil@xs4all.nl, laurent.pinchart@ideasonboard.com, roman.kovalivskyi@globallogic.com, dave.stevenson@raspberrypi.org, naush@raspberrypi.com, mrodin@de.adit-jv.com, hugues.fruchet@st.com, mripard@kernel.org, aford173@gmail.com, sudipi@jp.adit-jv.com, andrew_gabbasov@mentor.com, erosca@de.adit-jv.com, linux-media@vger.kernel.org, libcamera-devel@lists.libcamera.org Subject: Re: [PATCH 15/25] media: ov5647: Break out format handling Date: Fri, 31 Jul 2020 14:44:39 +0300 Message-ID: <20200731114439.GN13316@paasikivi.fi.intel.com> (raw) In-Reply-To: <20200623164224.44476-5-jacopo@jmondi.org> Hi Jacopo, Btw. I've bounced the two DT binding patches to DT list + Rob. Please remember that in v2 if there are changes. On Tue, Jun 23, 2020 at 06:42:24PM +0200, Jacopo Mondi wrote: > Break format handling out from the main driver structure. > > This commit prepares for the introduction of more sensor formats and > resolutions by instrumenting the existing operation to work on multiple > modes instead of assuming a single one supported. > > Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> > --- > drivers/media/i2c/ov5647.c | 84 +++++++++++++++++++++++++++----------- > 1 file changed, 61 insertions(+), 23 deletions(-) > > diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c > index 03f4f1a257ecd..a801ed0249aad 100644 > --- a/drivers/media/i2c/ov5647.c > +++ b/drivers/media/i2c/ov5647.c > @@ -84,18 +84,28 @@ struct regval_list { > u8 data; > }; > > +struct ov5647_mode { > + struct v4l2_mbus_framefmt format; > + struct regval_list *reg_list; > + unsigned int num_regs; > +}; > + > +struct ov5647_format_list { > + unsigned int mbus_code; > + struct ov5647_mode *modes; > + unsigned int num_modes; > +}; > + > struct ov5647 { > struct v4l2_subdev sd; > struct media_pad pad; > struct mutex lock; > - struct v4l2_mbus_framefmt format; > - unsigned int width; > - unsigned int height; > int power_count; > struct clk *xclk; > struct gpio_desc *pwdn; > bool clock_ncont; > struct v4l2_ctrl_handler ctrls; > + struct ov5647_mode *mode; > }; > > static inline struct ov5647 *to_sensor(struct v4l2_subdev *sd) > @@ -205,6 +215,33 @@ static struct regval_list ov5647_640x480[] = { > {0x0100, 0x01}, > }; > > +static struct ov5647_mode ov5647_8bit_modes[] = { const > + { > + .format = { > + .code = MEDIA_BUS_FMT_SBGGR8_1X8, > + .colorspace = V4L2_COLORSPACE_SRGB, > + .field = V4L2_FIELD_NONE, > + .width = 640, > + .height = 480 > + }, > + .reg_list = ov5647_640x480, > + .num_regs = ARRAY_SIZE(ov5647_640x480) > + }, > +}; > + > +static const struct ov5647_format_list ov5647_formats[] = { > + { > + .mbus_code = MEDIA_BUS_FMT_SBGGR8_1X8, > + .modes = ov5647_8bit_modes, > + .num_modes = ARRAY_SIZE(ov5647_8bit_modes), > + }, > +}; > + > +#define OV5647_NUM_FORMATS (ARRAY_SIZE(ov5647_formats)) Please use ARRAY_SIZE() directly, you don't need a macro here. > + > +#define OV5647_DEFAULT_MODE (&ov5647_formats[0].modes[0]) > +#define OV5647_DEFAULT_FORMAT (ov5647_formats[0].modes[0].format) > + > static int ov5647_write(struct v4l2_subdev *sd, u16 reg, u8 val) > { > unsigned char data[3] = { reg >> 8, reg & 0xff, val}; > @@ -282,8 +319,7 @@ static int ov5647_set_mode(struct v4l2_subdev *sd) > if (ret < 0) > return ret; > > - ret = ov5647_write_array(sd, ov5647_640x480, > - ARRAY_SIZE(ov5647_640x480)); > + ret = ov5647_write_array(sd, sensor->mode->reg_list, sensor->mode->num_regs); No need for a line over 80. > if (ret < 0) { > dev_err(&client->dev, "write sensor default regs error\n"); > return ret; > @@ -494,10 +530,10 @@ static int ov5647_enum_mbus_code(struct v4l2_subdev *sd, > struct v4l2_subdev_pad_config *cfg, > struct v4l2_subdev_mbus_code_enum *code) > { > - if (code->index > 0) > + if (code->index >= OV5647_NUM_FORMATS) > return -EINVAL; > > - code->code = MEDIA_BUS_FMT_SBGGR8_1X8; > + code->code = ov5647_formats[code->index].mbus_code; > > return 0; > } > @@ -506,16 +542,24 @@ static int ov5647_enum_frame_size(struct v4l2_subdev *sd, > struct v4l2_subdev_pad_config *cfg, > struct v4l2_subdev_frame_size_enum *fse) > { > - if (fse->index) > + const struct v4l2_mbus_framefmt *fmt; > + unsigned int i = 0; > + > + for (; i < OV5647_NUM_FORMATS; ++i) { > + if (ov5647_formats[i].mbus_code == fse->code) > + break; > + } > + if (i == OV5647_NUM_FORMATS) > return -EINVAL; > > - if (fse->code != MEDIA_BUS_FMT_SBGGR8_1X8) > + if (fse->index >= ov5647_formats[i].num_modes) > return -EINVAL; > > - fse->min_width = 640; > - fse->max_width = 640; > - fse->min_height = 480; > - fse->max_height = 480; > + fmt = &ov5647_formats[i].modes[fse->index].format; > + fse->min_width = fmt->width; > + fse->max_width = fmt->width; > + fse->min_height = fmt->height; > + fse->max_height = fmt->height; > > return 0; > } > @@ -528,11 +572,7 @@ static int ov5647_set_get_fmt(struct v4l2_subdev *sd, > > /* Only one format is supported, so return that. */ > memset(fmt, 0, sizeof(*fmt)); > - fmt->code = MEDIA_BUS_FMT_SBGGR8_1X8; > - fmt->colorspace = V4L2_COLORSPACE_SRGB; > - fmt->field = V4L2_FIELD_NONE; > - fmt->width = 640; > - fmt->height = 480; > + *fmt = OV5647_DEFAULT_FORMAT; > > return 0; > } > @@ -591,11 +631,7 @@ static int ov5647_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) > crop->width = OV5647_WINDOW_WIDTH_DEF; > crop->height = OV5647_WINDOW_HEIGHT_DEF; > > - format->code = MEDIA_BUS_FMT_SBGGR8_1X8; > - format->width = 640; > - format->height = 480; > - format->field = V4L2_FIELD_NONE; > - format->colorspace = V4L2_COLORSPACE_SRGB; > + *format = OV5647_DEFAULT_FORMAT; > > return 0; > } > @@ -813,6 +849,8 @@ static int ov5647_probe(struct i2c_client *client) > > mutex_init(&sensor->lock); > > + sensor->mode = OV5647_DEFAULT_MODE; You could do this without the macro, too. > + > ret = ov5647_init_controls(sensor); > if (ret) > goto mutex_destroy; -- Kind regards, Sakari Ailus
next prev parent reply other threads:[~2020-07-31 11:44 UTC|newest] Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-06-23 10:07 [PATCH 00/25] media: ov5647: Support RaspberryPi Camera Module v1 Jacopo Mondi 2020-06-23 10:07 ` [PATCH 01/25] dt-bindings: media: ov5647: Document pwdn-gpios Jacopo Mondi 2020-06-23 10:07 ` [PATCH 02/25] dt-bindings: media: ov5647: Document clock-noncontinuous Jacopo Mondi 2020-06-23 10:07 ` [PATCH 03/25] media: ov5647: Add support for PWDN GPIO Jacopo Mondi 2020-07-09 20:04 ` [libcamera-devel] " Dafna Hirschfeld 2020-07-14 12:45 ` Jacopo Mondi 2020-06-23 10:07 ` [PATCH 04/25] media: ov5647: Add support for non-continuous clock mode Jacopo Mondi 2020-06-23 10:07 ` [PATCH 05/25] media: ov5647: Add set_fmt and get_fmt calls Jacopo Mondi 2020-06-23 10:07 ` [PATCH 06/25] media: ov5647: Fix format initialization Jacopo Mondi 2020-06-23 10:07 ` [PATCH 07/25] media: ov5647: Fix style issues Jacopo Mondi 2020-06-23 10:07 ` [PATCH 08/25] media: ov5647: Replace license with SPDX identifier Jacopo Mondi 2020-06-23 10:07 ` [PATCH 09/25] media: ov5647: Fix return value from read/write Jacopo Mondi 2020-06-23 10:08 ` [PATCH 10/25] media: ov5647: Program mode at s_stream(1) time Jacopo Mondi 2020-06-23 16:42 ` [PATCH 11/25] media: ov5647: Implement enum_frame_size() Jacopo Mondi 2020-08-18 7:33 ` Sakari Ailus 2020-08-18 7:38 ` Sakari Ailus 2020-06-23 16:42 ` [PATCH 12/25] media: ov5647: Protect s_stream() with mutex Jacopo Mondi 2020-06-23 16:42 ` [PATCH 13/25] media: ov5647: Support gain, exposure and AWB controls Jacopo Mondi 2020-06-23 16:42 ` [PATCH 14/25] media: ov5647: Rationalize driver structure name Jacopo Mondi 2020-06-23 16:42 ` [PATCH 15/25] media: ov5647: Break out format handling Jacopo Mondi 2020-07-31 11:44 ` Sakari Ailus [this message] 2020-06-23 16:49 ` [PATCH 16/25] media: ov5647: Add support for get_selection() Jacopo Mondi 2020-07-09 19:56 ` [libcamera-devel] " Dafna Hirschfeld 2020-06-23 16:49 ` [PATCH 17/25] media: ov5647: Rename SBGGR8 VGA mode Jacopo Mondi 2020-06-23 16:49 ` [PATCH 18/25] media: ov5647: Add SGGBR10_1X10 modes Jacopo Mondi 2020-06-23 16:49 ` [PATCH 19/25] media: ov5647: Implement set_fmt pad operation Jacopo Mondi 2020-06-29 16:54 ` [libcamera-devel] " Dafna Hirschfeld 2020-06-30 10:13 ` Jacopo Mondi 2020-06-30 11:09 ` Dafna Hirschfeld 2020-06-23 16:55 ` [PATCH 20/25] media: ov5647: Program mode only if it has changed Jacopo Mondi 2020-06-29 17:48 ` Dafna Hirschfeld 2020-06-30 7:43 ` Jacopo Mondi 2020-06-30 9:32 ` Dafna Hirschfeld 2020-06-30 10:06 ` Jacopo Mondi 2020-06-30 10:56 ` Dafna Hirschfeld 2020-06-30 12:05 ` Jacopo Mondi 2020-06-30 13:01 ` Dafna Hirschfeld 2020-06-30 14:53 ` [libcamera-devel] " Dave Stevenson 2020-06-30 15:11 ` Dafna Hirschfeld 2020-07-01 7:25 ` Laurent Pinchart 2020-07-03 12:21 ` Jacopo Mondi 2020-07-03 16:33 ` Laurent Pinchart 2020-06-23 16:55 ` [PATCH 21/25] media: ov5647: Set V4L2_SUBDEV_FL_HAS_EVENTS flag Jacopo Mondi 2020-06-23 16:55 ` [PATCH 22/25] media: ov5647: Support V4L2_CID_PIXEL_RATE Jacopo Mondi 2020-06-29 17:01 ` [libcamera-devel] " Dafna Hirschfeld 2020-06-29 21:25 ` Dave Stevenson 2020-06-30 15:13 ` Dave Stevenson 2020-07-01 7:21 ` Laurent Pinchart 2020-06-23 16:55 ` [PATCH 23/25] media: ov5647: Support V4L2_CID_HBLANK control Jacopo Mondi 2020-06-23 16:55 ` [PATCH 24/25] media: ov5647: Support V4L2_CID_VBLANK control Jacopo Mondi 2020-06-23 16:55 ` [PATCH 25/25] media: ov5647: Advertise the correct exposure range Jacopo Mondi 2020-06-29 17:33 ` [PATCH 00/25] media: ov5647: Support RaspberryPi Camera Module v1 Dafna Hirschfeld 2020-06-29 18:08 ` Dafna Hirschfeld 2020-07-10 15:59 ` Dafna Hirschfeld 2020-07-14 12:48 ` Jacopo Mondi
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20200731114439.GN13316@paasikivi.fi.intel.com \ --to=sakari.ailus@linux.intel.com \ --cc=aford173@gmail.com \ --cc=andrew_gabbasov@mentor.com \ --cc=dave.stevenson@raspberrypi.org \ --cc=erosca@de.adit-jv.com \ --cc=hugues.fruchet@st.com \ --cc=hverkuil@xs4all.nl \ --cc=jacopo@jmondi.org \ --cc=laurent.pinchart@ideasonboard.com \ --cc=libcamera-devel@lists.libcamera.org \ --cc=linux-media@vger.kernel.org \ --cc=mchehab@kernel.org \ --cc=mripard@kernel.org \ --cc=mrodin@de.adit-jv.com \ --cc=naush@raspberrypi.com \ --cc=roman.kovalivskyi@globallogic.com \ --cc=sudipi@jp.adit-jv.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Unnamed repository; edit this file 'description' to name the repository. This inbox may be cloned and mirrored by anyone: git clone --mirror http://archive.lwn.net:8080/linux-media/0 linux-media/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 linux-media linux-media/ http://archive.lwn.net:8080/linux-media \ linux-media@vger.kernel.org lwn-linux-media@archive.lwn.net public-inbox-index linux-media Example config snippet for mirrors. Newsgroup available over NNTP: nntp://archive.lwn.net/lwn.kernel.linux-media AGPL code for this site: git clone https://public-inbox.org/public-inbox.git