1 From 94203b7e5bbb814c1d18fc5d95fea18b66041c03 Mon Sep 17 00:00:00 2001
2 From: Lee Jackson <info@arducam.com>
3 Date: Thu, 14 Apr 2022 17:31:01 +0800
4 Subject: [PATCH] media: i2c: Add driver of Arducam Pivariety series
7 Add a driver for the Arducam Pivariety series CSI2 camera sensor.
9 Signed-off-by: Lee Jackson <info@arducam.com>
11 drivers/media/i2c/Kconfig | 11 +
12 drivers/media/i2c/Makefile | 1 +
13 drivers/media/i2c/arducam-pivariety.c | 1469 +++++++++++++++++++++++++
14 drivers/media/i2c/arducam-pivariety.h | 107 ++
15 4 files changed, 1588 insertions(+)
16 create mode 100644 drivers/media/i2c/arducam-pivariety.c
17 create mode 100644 drivers/media/i2c/arducam-pivariety.h
19 --- a/drivers/media/i2c/Kconfig
20 +++ b/drivers/media/i2c/Kconfig
21 @@ -730,6 +730,17 @@ config VIDEO_APTINA_PLL
25 +config VIDEO_ARDUCAM_PIVARIETY
26 + tristate "Arducam Pivariety sensor support"
27 + depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
28 + depends on MEDIA_CAMERA_SUPPORT
30 + This is a Video4Linux2 sensor driver for the Arducam
31 + Pivariety camera series.
33 + To compile this driver as a module, choose M here: the
34 + module will be called arducam-pivariety.
37 tristate "Hynix Hi-556 sensor support"
38 depends on I2C && VIDEO_V4L2
39 --- a/drivers/media/i2c/Makefile
40 +++ b/drivers/media/i2c/Makefile
41 @@ -7,6 +7,7 @@ obj-$(CONFIG_VIDEO_ET8EK8) += et8ek8/
42 obj-$(CONFIG_VIDEO_CX25840) += cx25840/
43 obj-$(CONFIG_VIDEO_M5MOLS) += m5mols/
45 +obj-$(CONFIG_VIDEO_ARDUCAM_PIVARIETY) += arducam-pivariety.o
46 obj-$(CONFIG_VIDEO_APTINA_PLL) += aptina-pll.o
47 obj-$(CONFIG_VIDEO_TVAUDIO) += tvaudio.o
48 obj-$(CONFIG_VIDEO_TDA7432) += tda7432.o
50 +++ b/drivers/media/i2c/arducam-pivariety.c
52 +// SPDX-License-Identifier: GPL-2.0
54 + * A V4L2 driver for Arducam Pivariety Cameras
55 + * Copyright (C) 2022 Arducam Technology co., Ltd.
57 + * Based on Sony IMX219 camera driver
58 + * Copyright (C) 2019, Raspberry Pi (Trading) Ltd
60 + * I2C read and write method is taken from the OV9281 driver
61 + * Copyright (C) 2017 Fuzhou Rockchip Electronics Co., Ltd.
64 +#include <linux/clk.h>
65 +#include <linux/delay.h>
66 +#include <linux/gpio/consumer.h>
67 +#include <linux/i2c.h>
68 +#include <linux/module.h>
69 +#include <linux/pm_runtime.h>
70 +#include <linux/regulator/consumer.h>
71 +#include <media/v4l2-ctrls.h>
72 +#include <media/v4l2-device.h>
73 +#include <media/v4l2-event.h>
74 +#include <media/v4l2-fwnode.h>
75 +#include "arducam-pivariety.h"
78 +module_param(debug, int, 0644);
80 +/* regulator supplies */
81 +static const char * const pivariety_supply_name[] = {
82 + /* Supplies can be enabled in any order */
83 + "VANA", /* Analog (2.8V) supply */
84 + "VDIG", /* Digital Core (1.8V) supply */
85 + "VDDL", /* IF (1.2V) supply */
88 +/* The supported raw formats. */
89 +static const u32 codes[] = {
90 + MEDIA_BUS_FMT_SBGGR8_1X8,
91 + MEDIA_BUS_FMT_SGBRG8_1X8,
92 + MEDIA_BUS_FMT_SGRBG8_1X8,
93 + MEDIA_BUS_FMT_SRGGB8_1X8,
94 + MEDIA_BUS_FMT_Y8_1X8,
96 + MEDIA_BUS_FMT_SBGGR10_1X10,
97 + MEDIA_BUS_FMT_SGBRG10_1X10,
98 + MEDIA_BUS_FMT_SGRBG10_1X10,
99 + MEDIA_BUS_FMT_SRGGB10_1X10,
100 + MEDIA_BUS_FMT_Y10_1X10,
102 + MEDIA_BUS_FMT_SBGGR12_1X12,
103 + MEDIA_BUS_FMT_SGBRG12_1X12,
104 + MEDIA_BUS_FMT_SGRBG12_1X12,
105 + MEDIA_BUS_FMT_SRGGB12_1X12,
106 + MEDIA_BUS_FMT_Y12_1X12,
109 +#define ARDUCAM_NUM_SUPPLIES ARRAY_SIZE(pivariety_supply_name)
111 +#define ARDUCAM_XCLR_MIN_DELAY_US 10000
112 +#define ARDUCAM_XCLR_DELAY_RANGE_US 1000
114 +#define MAX_CTRLS 32
117 + struct v4l2_subdev sd;
118 + struct media_pad pad;
120 + struct v4l2_fwnode_bus_mipi_csi2 bus;
124 + struct gpio_desc *reset_gpio;
125 + struct regulator_bulk_data supplies[ARDUCAM_NUM_SUPPLIES];
127 + struct arducam_format *supported_formats;
128 + int num_supported_formats;
129 + int current_format_idx;
130 + int current_resolution_idx;
132 + int bayer_order_volatile;
133 + bool wait_until_free;
135 + struct v4l2_ctrl_handler ctrl_handler;
136 + struct v4l2_ctrl *ctrls[MAX_CTRLS];
137 + /* V4L2 Controls */
138 + struct v4l2_ctrl *vflip;
139 + struct v4l2_ctrl *hflip;
141 + struct v4l2_rect crop;
143 + * Mutex for serialized access:
144 + * Protect sensor module set pad format and start/stop streaming safely.
146 + struct mutex mutex;
148 + /* Streaming on/off */
152 +static inline struct pivariety *to_pivariety(struct v4l2_subdev *_sd)
154 + return container_of(_sd, struct pivariety, sd);
157 +/* Write registers up to 4 at a time */
158 +static int pivariety_write_reg(struct i2c_client *client, u16 reg, u32 val)
160 + unsigned int len = sizeof(u32);
161 + u32 buf_i, val_i = 0;
167 + buf[1] = reg & 0xff;
169 + val_be = cpu_to_be32(val);
170 + val_p = (u8 *)&val_be;
174 + buf[buf_i++] = val_p[val_i++];
176 + if (i2c_master_send(client, buf, len + 2) != len + 2)
182 +/* Read registers up to 4 at a time */
183 +static int pivariety_read_reg(struct i2c_client *client, u16 reg, u32 *val)
185 + struct i2c_msg msgs[2];
186 + unsigned int len = sizeof(u32);
188 + __be32 data_be = 0;
189 + __be16 reg_addr_be = cpu_to_be16(reg);
192 + data_be_p = (u8 *)&data_be;
193 + /* Write register address */
194 + msgs[0].addr = client->addr;
197 + msgs[0].buf = (u8 *)®_addr_be;
199 + /* Read data from register */
200 + msgs[1].addr = client->addr;
201 + msgs[1].flags = I2C_M_RD;
203 + msgs[1].buf = data_be_p;
205 + ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
206 + if (ret != ARRAY_SIZE(msgs))
209 + *val = be32_to_cpu(data_be);
215 +pivariety_read(struct pivariety *pivariety, u16 addr, u32 *value)
217 + struct v4l2_subdev *sd = &pivariety->sd;
218 + struct i2c_client *client = v4l2_get_subdevdata(sd);
219 + int ret, count = 0;
221 + while (count++ < I2C_READ_RETRY_COUNT) {
222 + ret = pivariety_read_reg(client, addr, value);
224 + v4l2_dbg(2, debug, sd, "%s: 0x%02x 0x%04x\n",
225 + __func__, addr, *value);
230 + v4l2_err(sd, "%s: Reading register 0x%02x failed\n",
236 +static int pivariety_write(struct pivariety *pivariety, u16 addr, u32 value)
238 + struct v4l2_subdev *sd = &pivariety->sd;
239 + struct i2c_client *client = v4l2_get_subdevdata(sd);
240 + int ret, count = 0;
242 + while (count++ < I2C_WRITE_RETRY_COUNT) {
243 + ret = pivariety_write_reg(client, addr, value);
248 + v4l2_err(sd, "%s: Write 0x%04x to register 0x%02x failed\n",
249 + __func__, value, addr);
254 +static int wait_for_free(struct pivariety *pivariety, int interval)
259 + while (count++ < (1000 / interval)) {
260 + int ret = pivariety_read(pivariety, SYSTEM_IDLE_REG, &value);
262 + if (!ret && !value)
267 + v4l2_dbg(2, debug, &pivariety->sd, "%s: End wait, Count: %d.\n",
273 +static int is_raw(int pixformat)
275 + return pixformat >= 0x28 && pixformat <= 0x2D;
278 +static u32 bayer_to_mbus_code(int data_type, int bayer_order)
280 + const u32 depth8[] = {
281 + MEDIA_BUS_FMT_SBGGR8_1X8,
282 + MEDIA_BUS_FMT_SGBRG8_1X8,
283 + MEDIA_BUS_FMT_SGRBG8_1X8,
284 + MEDIA_BUS_FMT_SRGGB8_1X8,
285 + MEDIA_BUS_FMT_Y8_1X8,
288 + const u32 depth10[] = {
289 + MEDIA_BUS_FMT_SBGGR10_1X10,
290 + MEDIA_BUS_FMT_SGBRG10_1X10,
291 + MEDIA_BUS_FMT_SGRBG10_1X10,
292 + MEDIA_BUS_FMT_SRGGB10_1X10,
293 + MEDIA_BUS_FMT_Y10_1X10,
296 + const u32 depth12[] = {
297 + MEDIA_BUS_FMT_SBGGR12_1X12,
298 + MEDIA_BUS_FMT_SGBRG12_1X12,
299 + MEDIA_BUS_FMT_SGRBG12_1X12,
300 + MEDIA_BUS_FMT_SRGGB12_1X12,
301 + MEDIA_BUS_FMT_Y12_1X12,
304 + if (bayer_order < 0 || bayer_order > 4)
307 + switch (data_type) {
308 + case IMAGE_DT_RAW8:
309 + return depth8[bayer_order];
310 + case IMAGE_DT_RAW10:
311 + return depth10[bayer_order];
312 + case IMAGE_DT_RAW12:
313 + return depth12[bayer_order];
319 +static u32 yuv422_to_mbus_code(int data_type, int order)
321 + const u32 depth8[] = {
322 + MEDIA_BUS_FMT_YUYV8_1X16,
323 + MEDIA_BUS_FMT_YVYU8_1X16,
324 + MEDIA_BUS_FMT_UYVY8_1X16,
325 + MEDIA_BUS_FMT_VYUY8_1X16,
328 + const u32 depth10[] = {
329 + MEDIA_BUS_FMT_YUYV10_1X20,
330 + MEDIA_BUS_FMT_YVYU10_1X20,
331 + MEDIA_BUS_FMT_UYVY10_1X20,
332 + MEDIA_BUS_FMT_VYUY10_1X20,
335 + if (order < 0 || order > 3)
338 + switch (data_type) {
339 + case IMAGE_DT_YUV422_8:
340 + return depth8[order];
341 + case IMAGE_DT_YUV422_10:
342 + return depth10[order];
348 +static u32 data_type_to_mbus_code(int data_type, int bayer_order)
350 + if (is_raw(data_type))
351 + return bayer_to_mbus_code(data_type, bayer_order);
353 + switch (data_type) {
354 + case IMAGE_DT_YUV422_8:
355 + case IMAGE_DT_YUV422_10:
356 + return yuv422_to_mbus_code(data_type, bayer_order);
357 + case IMAGE_DT_RGB565:
358 + return MEDIA_BUS_FMT_RGB565_2X8_LE;
359 + case IMAGE_DT_RGB888:
360 + return MEDIA_BUS_FMT_RGB888_1X24;
366 +/* Get bayer order based on flip setting. */
367 +static u32 pivariety_get_format_code(struct pivariety *pivariety,
368 + struct arducam_format *format)
370 + unsigned int order, origin_order;
372 + lockdep_assert_held(&pivariety->mutex);
375 + * Only the bayer format needs to transform the format.
377 + if (!is_raw(format->data_type) ||
378 + !pivariety->bayer_order_volatile ||
379 + format->bayer_order == BAYER_ORDER_GRAY)
380 + return data_type_to_mbus_code(format->data_type,
381 + format->bayer_order);
383 + order = format->bayer_order;
385 + origin_order = order;
387 + order = (pivariety->hflip && pivariety->hflip->val ? order ^ 1 : order);
388 + order = (pivariety->vflip && pivariety->vflip->val ? order ^ 2 : order);
390 + v4l2_dbg(1, debug, &pivariety->sd, "%s: before: %d, after: %d.\n",
391 + __func__, origin_order, order);
393 + return data_type_to_mbus_code(format->data_type, order);
396 +/* Power/clock management functions */
397 +static int pivariety_power_on(struct device *dev)
399 + struct i2c_client *client = to_i2c_client(dev);
400 + struct v4l2_subdev *sd = i2c_get_clientdata(client);
401 + struct pivariety *pivariety = to_pivariety(sd);
404 + ret = regulator_bulk_enable(ARDUCAM_NUM_SUPPLIES,
405 + pivariety->supplies);
407 + dev_err(dev, "%s: failed to enable regulators\n",
412 + ret = clk_prepare_enable(pivariety->xclk);
414 + dev_err(dev, "%s: failed to enable clock\n",
419 + gpiod_set_value_cansleep(pivariety->reset_gpio, 1);
420 + usleep_range(ARDUCAM_XCLR_MIN_DELAY_US,
421 + ARDUCAM_XCLR_MIN_DELAY_US + ARDUCAM_XCLR_DELAY_RANGE_US);
426 + regulator_bulk_disable(ARDUCAM_NUM_SUPPLIES, pivariety->supplies);
431 +static int pivariety_power_off(struct device *dev)
433 + struct i2c_client *client = to_i2c_client(dev);
434 + struct v4l2_subdev *sd = i2c_get_clientdata(client);
435 + struct pivariety *pivariety = to_pivariety(sd);
437 + gpiod_set_value_cansleep(pivariety->reset_gpio, 0);
438 + regulator_bulk_disable(ARDUCAM_NUM_SUPPLIES, pivariety->supplies);
439 + clk_disable_unprepare(pivariety->xclk);
444 +static int pivariety_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
446 + struct pivariety *pivariety = to_pivariety(sd);
447 + struct v4l2_mbus_framefmt *try_fmt =
448 + v4l2_subdev_get_try_format(sd, fh->state, 0);
449 + struct arducam_format *def_fmt = &pivariety->supported_formats[0];
451 + /* Initialize try_fmt */
452 + try_fmt->width = def_fmt->resolution_set->width;
453 + try_fmt->height = def_fmt->resolution_set->height;
454 + try_fmt->code = def_fmt->mbus_code;
455 + try_fmt->field = V4L2_FIELD_NONE;
460 +static int pivariety_s_ctrl(struct v4l2_ctrl *ctrl)
463 + struct pivariety *pivariety =
464 + container_of(ctrl->handler, struct pivariety,
466 + struct arducam_format *supported_fmts = pivariety->supported_formats;
467 + int num_supported_formats = pivariety->num_supported_formats;
469 + v4l2_dbg(3, debug, &pivariety->sd, "%s: cid = (0x%X), value = (%d).\n",
470 + __func__, ctrl->id, ctrl->val);
472 + ret = pivariety_write(pivariety, CTRL_ID_REG, ctrl->id);
473 + ret += pivariety_write(pivariety, CTRL_VALUE_REG, ctrl->val);
477 + /* When flip is set, modify all bayer formats */
478 + if (ctrl->id == V4L2_CID_VFLIP || ctrl->id == V4L2_CID_HFLIP) {
479 + for (i = 0; i < num_supported_formats; i++) {
480 + supported_fmts[i].mbus_code =
481 + pivariety_get_format_code(pivariety,
482 + &supported_fmts[i]);
487 + * When starting streaming, controls are set in batches,
488 + * and the short interval will cause some controls to be unsuccessfully
491 + if (pivariety->wait_until_free)
492 + wait_for_free(pivariety, 1);
494 + usleep_range(200, 210);
499 +static const struct v4l2_ctrl_ops pivariety_ctrl_ops = {
500 + .s_ctrl = pivariety_s_ctrl,
503 +static int pivariety_enum_mbus_code(struct v4l2_subdev *sd,
504 + struct v4l2_subdev_state *sd_state,
505 + struct v4l2_subdev_mbus_code_enum *code)
507 + struct pivariety *pivariety = to_pivariety(sd);
508 + struct arducam_format *supported_formats = pivariety->supported_formats;
509 + int num_supported_formats = pivariety->num_supported_formats;
511 + v4l2_dbg(1, debug, sd, "%s: index = (%d)\n", __func__, code->index);
513 + if (code->index >= num_supported_formats)
516 + code->code = supported_formats[code->index].mbus_code;
521 +static int pivariety_enum_framesizes(struct v4l2_subdev *sd,
522 + struct v4l2_subdev_state *sd_state,
523 + struct v4l2_subdev_frame_size_enum *fse)
526 + struct pivariety *pivariety = to_pivariety(sd);
527 + struct arducam_format *supported_formats = pivariety->supported_formats;
528 + int num_supported_formats = pivariety->num_supported_formats;
529 + struct arducam_format *format;
530 + struct arducam_resolution *resolution;
532 + v4l2_dbg(1, debug, sd, "%s: code = (0x%X), index = (%d)\n",
533 + __func__, fse->code, fse->index);
535 + for (i = 0; i < num_supported_formats; i++) {
536 + format = &supported_formats[i];
537 + if (fse->code == format->mbus_code) {
538 + if (fse->index >= format->num_resolution_set)
541 + resolution = &format->resolution_set[fse->index];
542 + fse->min_width = resolution->width;
543 + fse->max_width = resolution->width;
544 + fse->min_height = resolution->height;
545 + fse->max_height = resolution->height;
554 +static int pivariety_get_fmt(struct v4l2_subdev *sd,
555 + struct v4l2_subdev_state *sd_state,
556 + struct v4l2_subdev_format *format)
558 + struct pivariety *pivariety = to_pivariety(sd);
559 + struct arducam_format *current_format;
560 + struct v4l2_mbus_framefmt *fmt = &format->format;
563 + if (format->pad != 0)
566 + mutex_lock(&pivariety->mutex);
569 + &pivariety->supported_formats[pivariety->current_format_idx];
570 + cur_res_idx = pivariety->current_resolution_idx;
571 + format->format.width =
572 + current_format->resolution_set[cur_res_idx].width;
573 + format->format.height =
574 + current_format->resolution_set[cur_res_idx].height;
575 + format->format.code = current_format->mbus_code;
576 + format->format.field = V4L2_FIELD_NONE;
577 + fmt->colorspace = V4L2_COLORSPACE_RAW;
578 + fmt->ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(fmt->colorspace);
579 + fmt->quantization = V4L2_MAP_QUANTIZATION_DEFAULT(true,
582 + fmt->xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(fmt->colorspace);
584 + v4l2_dbg(1, debug, sd, "%s: width: (%d) height: (%d) code: (0x%X)\n",
585 + __func__, format->format.width, format->format.height,
586 + format->format.code);
588 + mutex_unlock(&pivariety->mutex);
592 +static int pivariety_get_fmt_idx_by_code(struct pivariety *pivariety,
597 + struct arducam_format *formats = pivariety->supported_formats;
599 + for (i = 0; i < pivariety->num_supported_formats; i++) {
600 + if (formats[i].mbus_code == mbus_code)
605 + * If the specified format is not found in the list of supported
606 + * formats, try to find a format of the same data type.
608 + for (i = 0; i < ARRAY_SIZE(codes); i++)
609 + if (codes[i] == mbus_code)
612 + if (i >= ARRAY_SIZE(codes))
615 + data_type = i / 5 + IMAGE_DT_RAW8;
617 + for (i = 0; i < pivariety->num_supported_formats; i++) {
618 + if (formats[i].data_type == data_type)
625 +static struct v4l2_ctrl *get_control(struct pivariety *pivariety,
630 + while (index < MAX_CTRLS && pivariety->ctrls[index]) {
631 + if (pivariety->ctrls[index]->id == id)
632 + return pivariety->ctrls[index];
639 +static int update_control(struct pivariety *pivariety, u32 id)
641 + struct v4l2_subdev *sd = &pivariety->sd;
642 + struct v4l2_ctrl *ctrl;
643 + u32 min, max, step, def, id2;
646 + pivariety_write(pivariety, CTRL_ID_REG, id);
647 + pivariety_read(pivariety, CTRL_ID_REG, &id2);
649 + v4l2_dbg(1, debug, sd, "%s: Write ID: 0x%08X Read ID: 0x%08X\n",
650 + __func__, id, id2);
652 + pivariety_write(pivariety, CTRL_VALUE_REG, 0);
653 + wait_for_free(pivariety, 1);
655 + ret += pivariety_read(pivariety, CTRL_MAX_REG, &max);
656 + ret += pivariety_read(pivariety, CTRL_MIN_REG, &min);
657 + ret += pivariety_read(pivariety, CTRL_DEF_REG, &def);
658 + ret += pivariety_read(pivariety, CTRL_STEP_REG, &step);
663 + if (id == NO_DATA_AVAILABLE || max == NO_DATA_AVAILABLE ||
664 + min == NO_DATA_AVAILABLE || def == NO_DATA_AVAILABLE ||
665 + step == NO_DATA_AVAILABLE)
668 + v4l2_dbg(1, debug, sd, "%s: min: %d, max: %d, step: %d, def: %d\n",
669 + __func__, min, max, step, def);
671 + ctrl = get_control(pivariety, id);
672 + return __v4l2_ctrl_modify_range(ctrl, min, max, step, def);
678 +static int update_controls(struct pivariety *pivariety)
683 + wait_for_free(pivariety, 5);
685 + while (index < MAX_CTRLS && pivariety->ctrls[index]) {
686 + ret += update_control(pivariety, pivariety->ctrls[index]->id);
693 +static int pivariety_set_fmt(struct v4l2_subdev *sd,
694 + struct v4l2_subdev_state *sd_state,
695 + struct v4l2_subdev_format *format)
698 + struct pivariety *pivariety = to_pivariety(sd);
699 + struct arducam_format *supported_formats = pivariety->supported_formats;
701 + if (format->pad != 0)
704 + mutex_lock(&pivariety->mutex);
706 + format->format.colorspace = V4L2_COLORSPACE_RAW;
707 + format->format.field = V4L2_FIELD_NONE;
709 + v4l2_dbg(1, debug, sd, "%s: code: 0x%X, width: %d, height: %d\n",
710 + __func__, format->format.code, format->format.width,
711 + format->format.height);
713 + i = pivariety_get_fmt_idx_by_code(pivariety, format->format.code);
717 + format->format.code = supported_formats[i].mbus_code;
719 + for (j = 0; j < supported_formats[i].num_resolution_set; j++) {
720 + if (supported_formats[i].resolution_set[j].width ==
721 + format->format.width &&
722 + supported_formats[i].resolution_set[j].height ==
723 + format->format.height) {
724 + v4l2_dbg(1, debug, sd,
725 + "%s: format match.\n", __func__);
726 + v4l2_dbg(1, debug, sd,
727 + "%s: set format to device: %d %d.\n",
728 + __func__, supported_formats[i].index, j);
730 + pivariety_write(pivariety, PIXFORMAT_INDEX_REG,
731 + supported_formats[i].index);
732 + pivariety_write(pivariety, RESOLUTION_INDEX_REG, j);
734 + pivariety->current_format_idx = i;
735 + pivariety->current_resolution_idx = j;
737 + update_controls(pivariety);
743 + format->format.width = supported_formats[i].resolution_set[0].width;
744 + format->format.height = supported_formats[i].resolution_set[0].height;
746 + pivariety_write(pivariety, PIXFORMAT_INDEX_REG,
747 + supported_formats[i].index);
748 + pivariety_write(pivariety, RESOLUTION_INDEX_REG, 0);
750 + pivariety->current_format_idx = i;
751 + pivariety->current_resolution_idx = 0;
752 + update_controls(pivariety);
756 + mutex_unlock(&pivariety->mutex);
761 +/* Start streaming */
762 +static int pivariety_start_streaming(struct pivariety *pivariety)
766 + /* set stream on register */
767 + ret = pivariety_write(pivariety, MODE_SELECT_REG,
768 + ARDUCAM_MODE_STREAMING);
773 + wait_for_free(pivariety, 2);
776 + * When starting streaming, controls are set in batches,
777 + * and the short interval will cause some controls to be unsuccessfully
780 + pivariety->wait_until_free = true;
781 + /* Apply customized values from user */
782 + ret = __v4l2_ctrl_handler_setup(pivariety->sd.ctrl_handler);
784 + pivariety->wait_until_free = false;
788 + wait_for_free(pivariety, 2);
793 +static int pivariety_read_sel(struct pivariety *pivariety,
794 + struct v4l2_rect *rect)
798 + ret += pivariety_read(pivariety, IPC_SEL_TOP_REG, &rect->top);
799 + ret += pivariety_read(pivariety, IPC_SEL_LEFT_REG, &rect->left);
800 + ret += pivariety_read(pivariety, IPC_SEL_WIDTH_REG, &rect->width);
801 + ret += pivariety_read(pivariety, IPC_SEL_HEIGHT_REG, &rect->height);
803 + if (ret || rect->top == NO_DATA_AVAILABLE ||
804 + rect->left == NO_DATA_AVAILABLE ||
805 + rect->width == NO_DATA_AVAILABLE ||
806 + rect->height == NO_DATA_AVAILABLE) {
807 + v4l2_err(&pivariety->sd, "%s: Failed to read selection.\n",
815 +static const struct v4l2_rect *
816 +__pivariety_get_pad_crop(struct pivariety *pivariety,
817 + struct v4l2_subdev_state *sd_state,
819 + enum v4l2_subdev_format_whence which)
824 + case V4L2_SUBDEV_FORMAT_TRY:
825 + return v4l2_subdev_get_try_crop(&pivariety->sd, sd_state, pad);
826 + case V4L2_SUBDEV_FORMAT_ACTIVE:
827 + ret = pivariety_read_sel(pivariety, &pivariety->crop);
830 + return &pivariety->crop;
836 +static int pivariety_get_selection(struct v4l2_subdev *sd,
837 + struct v4l2_subdev_state *sd_state,
838 + struct v4l2_subdev_selection *sel)
841 + struct v4l2_rect rect;
842 + struct pivariety *pivariety = to_pivariety(sd);
844 + ret = pivariety_write(pivariety, IPC_SEL_TARGET_REG, sel->target);
846 + v4l2_err(sd, "%s: Write register 0x%02x failed\n",
847 + __func__, IPC_SEL_TARGET_REG);
851 + wait_for_free(pivariety, 2);
853 + switch (sel->target) {
854 + case V4L2_SEL_TGT_CROP: {
855 + mutex_lock(&pivariety->mutex);
856 + sel->r = *__pivariety_get_pad_crop(pivariety, sd_state,
859 + mutex_unlock(&pivariety->mutex);
864 + case V4L2_SEL_TGT_NATIVE_SIZE:
865 + case V4L2_SEL_TGT_CROP_DEFAULT:
866 + case V4L2_SEL_TGT_CROP_BOUNDS:
867 + ret = pivariety_read_sel(pivariety, &rect);
878 +/* Stop streaming */
879 +static int pivariety_stop_streaming(struct pivariety *pivariety)
883 + /* set stream off register */
884 + ret = pivariety_write(pivariety, MODE_SELECT_REG, ARDUCAM_MODE_STANDBY);
886 + v4l2_err(&pivariety->sd, "%s failed to set stream\n", __func__);
889 + * Return success even if it was an error, as there is nothing the
890 + * caller can do about it.
895 +static int pivariety_set_stream(struct v4l2_subdev *sd, int enable)
897 + struct pivariety *pivariety = to_pivariety(sd);
898 + struct i2c_client *client = v4l2_get_subdevdata(sd);
901 + mutex_lock(&pivariety->mutex);
902 + if (pivariety->streaming == enable) {
903 + mutex_unlock(&pivariety->mutex);
908 + ret = pm_runtime_get_sync(&client->dev);
910 + pm_runtime_put_noidle(&client->dev);
915 + * Apply default & customized values
916 + * and then start streaming.
918 + ret = pivariety_start_streaming(pivariety);
922 + pivariety_stop_streaming(pivariety);
923 + pm_runtime_put(&client->dev);
926 + pivariety->streaming = enable;
929 + * vflip and hflip cannot change during streaming
930 + * Pivariety may not implement flip control.
932 + if (pivariety->vflip)
933 + __v4l2_ctrl_grab(pivariety->vflip, enable);
935 + if (pivariety->hflip)
936 + __v4l2_ctrl_grab(pivariety->hflip, enable);
938 + mutex_unlock(&pivariety->mutex);
943 + pm_runtime_put(&client->dev);
945 + mutex_unlock(&pivariety->mutex);
950 +static int __maybe_unused pivariety_suspend(struct device *dev)
952 + struct i2c_client *client = to_i2c_client(dev);
953 + struct v4l2_subdev *sd = i2c_get_clientdata(client);
954 + struct pivariety *pivariety = to_pivariety(sd);
956 + if (pivariety->streaming)
957 + pivariety_stop_streaming(pivariety);
962 +static int __maybe_unused pivariety_resume(struct device *dev)
964 + struct i2c_client *client = to_i2c_client(dev);
965 + struct v4l2_subdev *sd = i2c_get_clientdata(client);
966 + struct pivariety *pivariety = to_pivariety(sd);
969 + if (pivariety->streaming) {
970 + ret = pivariety_start_streaming(pivariety);
978 + pivariety_stop_streaming(pivariety);
979 + pivariety->streaming = 0;
983 +static int pivariety_get_regulators(struct pivariety *pivariety)
985 + struct i2c_client *client = v4l2_get_subdevdata(&pivariety->sd);
988 + for (i = 0; i < ARDUCAM_NUM_SUPPLIES; i++)
989 + pivariety->supplies[i].supply = pivariety_supply_name[i];
991 + return devm_regulator_bulk_get(&client->dev,
992 + ARDUCAM_NUM_SUPPLIES,
993 + pivariety->supplies);
996 +static int pivariety_get_mbus_config(struct v4l2_subdev *sd, unsigned int pad,
997 + struct v4l2_mbus_config *cfg)
999 + struct pivariety *pivariety = to_pivariety(sd);
1000 + const u32 mask = V4L2_MBUS_CSI2_LANE_MASK;
1002 + if (pivariety->lanes > pivariety->bus.num_data_lanes)
1005 + cfg->type = V4L2_MBUS_CSI2_DPHY;
1006 + cfg->flags = (pivariety->lanes << __ffs(mask)) & mask;
1011 +static const struct v4l2_subdev_core_ops pivariety_core_ops = {
1012 + .subscribe_event = v4l2_ctrl_subdev_subscribe_event,
1013 + .unsubscribe_event = v4l2_event_subdev_unsubscribe,
1016 +static const struct v4l2_subdev_video_ops pivariety_video_ops = {
1017 + .s_stream = pivariety_set_stream,
1020 +static const struct v4l2_subdev_pad_ops pivariety_pad_ops = {
1021 + .enum_mbus_code = pivariety_enum_mbus_code,
1022 + .get_fmt = pivariety_get_fmt,
1023 + .set_fmt = pivariety_set_fmt,
1024 + .enum_frame_size = pivariety_enum_framesizes,
1025 + .get_selection = pivariety_get_selection,
1026 + .get_mbus_config = pivariety_get_mbus_config,
1029 +static const struct v4l2_subdev_ops pivariety_subdev_ops = {
1030 + .core = &pivariety_core_ops,
1031 + .video = &pivariety_video_ops,
1032 + .pad = &pivariety_pad_ops,
1035 +static const struct v4l2_subdev_internal_ops pivariety_internal_ops = {
1036 + .open = pivariety_open,
1039 +static void pivariety_free_controls(struct pivariety *pivariety)
1041 + v4l2_ctrl_handler_free(pivariety->sd.ctrl_handler);
1042 + mutex_destroy(&pivariety->mutex);
1045 +static int pivariety_get_length_of_set(struct pivariety *pivariety,
1046 + u16 idx_reg, u16 val_reg)
1053 + ret = pivariety_write(pivariety, idx_reg, index);
1054 + ret += pivariety_read(pivariety, val_reg, &val);
1059 + if (val == NO_DATA_AVAILABLE)
1063 + pivariety_write(pivariety, idx_reg, 0);
1067 +static int pivariety_enum_resolution(struct pivariety *pivariety,
1068 + struct arducam_format *format)
1070 + struct i2c_client *client = v4l2_get_subdevdata(&pivariety->sd);
1072 + u32 width, height;
1073 + int num_resolution = 0;
1076 + num_resolution = pivariety_get_length_of_set(pivariety,
1077 + RESOLUTION_INDEX_REG,
1078 + FORMAT_WIDTH_REG);
1079 + if (num_resolution < 0)
1082 + format->resolution_set = devm_kzalloc(&client->dev,
1083 + sizeof(*format->resolution_set) *
1087 + ret = pivariety_write(pivariety, RESOLUTION_INDEX_REG, index);
1088 + ret += pivariety_read(pivariety, FORMAT_WIDTH_REG, &width);
1089 + ret += pivariety_read(pivariety, FORMAT_HEIGHT_REG, &height);
1094 + if (width == NO_DATA_AVAILABLE || height == NO_DATA_AVAILABLE)
1097 + format->resolution_set[index].width = width;
1098 + format->resolution_set[index].height = height;
1103 + format->num_resolution_set = index;
1104 + pivariety_write(pivariety, RESOLUTION_INDEX_REG, 0);
1110 +static int pivariety_enum_pixformat(struct pivariety *pivariety)
1113 + u32 mbus_code = 0;
1116 + int bayer_order_not_volatile;
1119 + int num_pixformat = 0;
1120 + struct arducam_format *arducam_fmt;
1121 + struct i2c_client *client = v4l2_get_subdevdata(&pivariety->sd);
1123 + num_pixformat = pivariety_get_length_of_set(pivariety,
1124 + PIXFORMAT_INDEX_REG,
1125 + PIXFORMAT_TYPE_REG);
1127 + if (num_pixformat < 0)
1130 + ret = pivariety_read(pivariety, FLIPS_DONT_CHANGE_ORDER_REG,
1131 + &bayer_order_not_volatile);
1132 + if (bayer_order_not_volatile == NO_DATA_AVAILABLE)
1133 + pivariety->bayer_order_volatile = 1;
1135 + pivariety->bayer_order_volatile = !bayer_order_not_volatile;
1140 + pivariety->supported_formats =
1141 + devm_kzalloc(&client->dev,
1142 + sizeof(*pivariety->supported_formats) *
1147 + ret = pivariety_write(pivariety, PIXFORMAT_INDEX_REG, index);
1148 + ret += pivariety_read(pivariety, PIXFORMAT_TYPE_REG,
1151 + if (pixfmt_type == NO_DATA_AVAILABLE)
1154 + ret += pivariety_read(pivariety, MIPI_LANES_REG, &lanes);
1155 + if (lanes == NO_DATA_AVAILABLE)
1158 + ret += pivariety_read(pivariety, PIXFORMAT_ORDER_REG,
1163 + mbus_code = data_type_to_mbus_code(pixfmt_type, bayer_order);
1164 + arducam_fmt = &pivariety->supported_formats[index];
1165 + arducam_fmt->index = index;
1166 + arducam_fmt->mbus_code = mbus_code;
1167 + arducam_fmt->bayer_order = bayer_order;
1168 + arducam_fmt->data_type = pixfmt_type;
1169 + if (pivariety_enum_resolution(pivariety, arducam_fmt))
1175 + pivariety_write(pivariety, PIXFORMAT_INDEX_REG, 0);
1176 + pivariety->num_supported_formats = index;
1177 + pivariety->current_format_idx = 0;
1178 + pivariety->current_resolution_idx = 0;
1179 + pivariety->lanes = lanes;
1187 +static const char *pivariety_ctrl_get_name(u32 id)
1190 + case V4L2_CID_ARDUCAM_EXT_TRI:
1191 + return "trigger_mode";
1192 + case V4L2_CID_ARDUCAM_IRCUT:
1199 +enum v4l2_ctrl_type pivariety_get_v4l2_ctrl_type(u32 id)
1202 + case V4L2_CID_ARDUCAM_EXT_TRI:
1203 + return V4L2_CTRL_TYPE_BOOLEAN;
1204 + case V4L2_CID_ARDUCAM_IRCUT:
1205 + return V4L2_CTRL_TYPE_BOOLEAN;
1207 + return V4L2_CTRL_TYPE_INTEGER;
1211 +static struct v4l2_ctrl *v4l2_ctrl_new_arducam(struct v4l2_ctrl_handler *hdl,
1212 + const struct v4l2_ctrl_ops *ops,
1213 + u32 id, s64 min, s64 max,
1214 + u64 step, s64 def)
1216 + struct v4l2_ctrl_config ctrl_cfg = {
1220 + .type = V4L2_CTRL_TYPE_INTEGER,
1228 + ctrl_cfg.name = pivariety_ctrl_get_name(id);
1229 + ctrl_cfg.type = pivariety_get_v4l2_ctrl_type(id);
1231 + return v4l2_ctrl_new_custom(hdl, &ctrl_cfg, NULL);
1234 +static int pivariety_enum_controls(struct pivariety *pivariety)
1236 + struct v4l2_subdev *sd = &pivariety->sd;
1237 + struct i2c_client *client = v4l2_get_subdevdata(sd);
1238 + struct v4l2_ctrl_handler *ctrl_hdlr = &pivariety->ctrl_handler;
1239 + struct v4l2_fwnode_device_properties props;
1240 + struct v4l2_ctrl **ctrl = pivariety->ctrls;
1241 + int ret, index, num_ctrls;
1242 + u32 id, min, max, def, step;
1244 + num_ctrls = pivariety_get_length_of_set(pivariety, CTRL_INDEX_REG,
1246 + if (num_ctrls < 0)
1249 + v4l2_dbg(1, debug, sd, "%s: num_ctrls = %d\n",
1250 + __func__, num_ctrls);
1252 + ret = v4l2_ctrl_handler_init(ctrl_hdlr, num_ctrls);
1258 + ret = pivariety_write(pivariety, CTRL_INDEX_REG, index);
1259 + pivariety_write(pivariety, CTRL_VALUE_REG, 0);
1260 + wait_for_free(pivariety, 1);
1262 + ret += pivariety_read(pivariety, CTRL_ID_REG, &id);
1263 + ret += pivariety_read(pivariety, CTRL_MAX_REG, &max);
1264 + ret += pivariety_read(pivariety, CTRL_MIN_REG, &min);
1265 + ret += pivariety_read(pivariety, CTRL_DEF_REG, &def);
1266 + ret += pivariety_read(pivariety, CTRL_STEP_REG, &step);
1270 + if (id == NO_DATA_AVAILABLE || max == NO_DATA_AVAILABLE ||
1271 + min == NO_DATA_AVAILABLE || def == NO_DATA_AVAILABLE ||
1272 + step == NO_DATA_AVAILABLE)
1275 + v4l2_dbg(1, debug, sd,
1276 + "%s: index = %d, id = 0x%x, max = %d, min = %d, def = %d, step = %d\n",
1277 + __func__, index, id, max, min, def, step);
1279 + if (v4l2_ctrl_get_name(id)) {
1280 + *ctrl = v4l2_ctrl_new_std(ctrl_hdlr,
1281 + &pivariety_ctrl_ops,
1285 + v4l2_dbg(1, debug, sd, "%s: ctrl: 0x%p\n",
1287 + } else if (pivariety_ctrl_get_name(id)) {
1288 + *ctrl = v4l2_ctrl_new_arducam(ctrl_hdlr,
1289 + &pivariety_ctrl_ops,
1290 + id, min, max, step, def);
1292 + v4l2_dbg(1, debug, sd,
1293 + "%s: new custom ctrl, ctrl: 0x%p.\n",
1304 + case V4L2_CID_HFLIP:
1305 + pivariety->hflip = *ctrl;
1306 + if (pivariety->bayer_order_volatile)
1307 + pivariety->hflip->flags |=
1308 + V4L2_CTRL_FLAG_MODIFY_LAYOUT;
1311 + case V4L2_CID_VFLIP:
1312 + pivariety->vflip = *ctrl;
1313 + if (pivariety->bayer_order_volatile)
1314 + pivariety->vflip->flags |=
1315 + V4L2_CTRL_FLAG_MODIFY_LAYOUT;
1318 + case V4L2_CID_HBLANK:
1319 + (*ctrl)->flags |= V4L2_CTRL_FLAG_READ_ONLY;
1327 + pivariety_write(pivariety, CTRL_INDEX_REG, 0);
1329 + ret = v4l2_fwnode_device_parse(&client->dev, &props);
1333 + ret = v4l2_ctrl_new_fwnode_properties(ctrl_hdlr,
1334 + &pivariety_ctrl_ops,
1339 + pivariety->sd.ctrl_handler = ctrl_hdlr;
1340 + v4l2_ctrl_handler_setup(ctrl_hdlr);
1346 +static int pivariety_parse_dt(struct pivariety *pivariety, struct device *dev)
1348 + struct fwnode_handle *endpoint;
1349 + struct v4l2_fwnode_endpoint ep_cfg = {
1350 + .bus_type = V4L2_MBUS_CSI2_DPHY
1352 + int ret = -EINVAL;
1354 + /* Get CSI2 bus config */
1355 + endpoint = fwnode_graph_get_next_endpoint(dev_fwnode(dev), NULL);
1357 + dev_err(dev, "endpoint node not found\n");
1361 + if (v4l2_fwnode_endpoint_alloc_parse(endpoint, &ep_cfg)) {
1362 + dev_err(dev, "could not parse endpoint\n");
1366 + pivariety->bus = ep_cfg.bus.mipi_csi2;
1371 + v4l2_fwnode_endpoint_free(&ep_cfg);
1372 + fwnode_handle_put(endpoint);
1377 +static int pivariety_probe(struct i2c_client *client,
1378 + const struct i2c_device_id *id)
1380 + struct device *dev = &client->dev;
1381 + struct pivariety *pivariety;
1382 + u32 device_id, firmware_version;
1385 + pivariety = devm_kzalloc(&client->dev, sizeof(*pivariety), GFP_KERNEL);
1389 + /* Initialize subdev */
1390 + v4l2_i2c_subdev_init(&pivariety->sd, client,
1391 + &pivariety_subdev_ops);
1393 + if (pivariety_parse_dt(pivariety, dev))
1396 + /* Get system clock (xclk) */
1397 + pivariety->xclk = devm_clk_get(dev, "xclk");
1398 + if (IS_ERR(pivariety->xclk)) {
1399 + dev_err(dev, "failed to get xclk\n");
1400 + return PTR_ERR(pivariety->xclk);
1403 + pivariety->xclk_freq = clk_get_rate(pivariety->xclk);
1404 + if (pivariety->xclk_freq != 24000000) {
1405 + dev_err(dev, "xclk frequency not supported: %d Hz\n",
1406 + pivariety->xclk_freq);
1410 + ret = pivariety_get_regulators(pivariety);
1414 + /* Request optional enable pin */
1415 + pivariety->reset_gpio = devm_gpiod_get_optional(dev, "reset",
1418 + ret = pivariety_power_on(dev);
1422 + ret = pivariety_read(pivariety, DEVICE_ID_REG, &device_id);
1423 + if (ret || device_id != DEVICE_ID) {
1424 + dev_err(dev, "probe failed\n");
1426 + goto error_power_off;
1429 + ret = pivariety_read(pivariety, DEVICE_VERSION_REG, &firmware_version);
1431 + dev_err(dev, "read firmware version failed\n");
1433 + dev_info(dev, "firmware version: 0x%04X\n", firmware_version);
1435 + if (pivariety_enum_pixformat(pivariety)) {
1436 + dev_err(dev, "enum pixformat failed.\n");
1438 + goto error_power_off;
1441 + if (pivariety_enum_controls(pivariety)) {
1442 + dev_err(dev, "enum controls failed.\n");
1444 + goto error_power_off;
1447 + /* Initialize subdev */
1448 + pivariety->sd.internal_ops = &pivariety_internal_ops;
1449 + pivariety->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
1450 + pivariety->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR;
1451 + /* Initialize source pad */
1452 + pivariety->pad.flags = MEDIA_PAD_FL_SOURCE;
1454 + ret = media_entity_pads_init(&pivariety->sd.entity, 1, &pivariety->pad);
1456 + goto error_handler_free;
1458 + ret = v4l2_async_register_subdev_sensor(&pivariety->sd);
1460 + goto error_media_entity;
1462 + pm_runtime_set_active(dev);
1463 + pm_runtime_enable(dev);
1464 + pm_runtime_idle(dev);
1468 +error_media_entity:
1469 + media_entity_cleanup(&pivariety->sd.entity);
1471 +error_handler_free:
1472 + pivariety_free_controls(pivariety);
1475 + pivariety_power_off(dev);
1480 +static int pivariety_remove(struct i2c_client *client)
1482 + struct v4l2_subdev *sd = i2c_get_clientdata(client);
1483 + struct pivariety *pivariety = to_pivariety(sd);
1485 + v4l2_async_unregister_subdev(sd);
1486 + media_entity_cleanup(&sd->entity);
1487 + pivariety_free_controls(pivariety);
1489 + pm_runtime_disable(&client->dev);
1490 + pm_runtime_set_suspended(&client->dev);
1495 +static const struct dev_pm_ops pivariety_pm_ops = {
1496 + SET_SYSTEM_SLEEP_PM_OPS(pivariety_suspend, pivariety_resume)
1497 + SET_RUNTIME_PM_OPS(pivariety_power_off, pivariety_power_on, NULL)
1500 +static const struct of_device_id arducam_pivariety_dt_ids[] = {
1501 + { .compatible = "arducam,arducam-pivariety" },
1502 + { /* sentinel */ }
1504 +MODULE_DEVICE_TABLE(of, arducam_pivariety_dt_ids);
1506 +static struct i2c_driver arducam_pivariety_i2c_driver = {
1508 + .name = "arducam-pivariety",
1509 + .of_match_table = arducam_pivariety_dt_ids,
1510 + .pm = &pivariety_pm_ops,
1512 + .probe = pivariety_probe,
1513 + .remove = pivariety_remove,
1516 +module_i2c_driver(arducam_pivariety_i2c_driver);
1518 +MODULE_AUTHOR("Lee Jackson <info@arducam.com>");
1519 +MODULE_DESCRIPTION("Arducam Pivariety v4l2 driver");
1520 +MODULE_LICENSE("GPL v2");
1522 +++ b/drivers/media/i2c/arducam-pivariety.h
1524 +/* SPDX-License-Identifier: GPL-2.0 */
1525 +#ifndef _ARDUCAM_PIVARIETY_H_
1526 +#define _ARDUCAM_PIVARIETY_H_
1528 +#define DEVICE_REG_BASE 0x0100
1529 +#define PIXFORMAT_REG_BASE 0x0200
1530 +#define FORMAT_REG_BASE 0x0300
1531 +#define CTRL_REG_BASE 0x0400
1532 +#define IPC_REG_BASE 0x0600
1534 +#define ARDUCAM_MODE_STANDBY 0x00
1535 +#define ARDUCAM_MODE_STREAMING 0x01
1537 +#define MODE_SELECT_REG (DEVICE_REG_BASE | 0x0000)
1538 +#define DEVICE_VERSION_REG (DEVICE_REG_BASE | 0x0001)
1539 +#define SENSOR_ID_REG (DEVICE_REG_BASE | 0x0002)
1540 +#define DEVICE_ID_REG (DEVICE_REG_BASE | 0x0003)
1541 +#define SYSTEM_IDLE_REG (DEVICE_REG_BASE | 0x0007)
1543 +#define PIXFORMAT_INDEX_REG (PIXFORMAT_REG_BASE | 0x0000)
1544 +#define PIXFORMAT_TYPE_REG (PIXFORMAT_REG_BASE | 0x0001)
1545 +#define PIXFORMAT_ORDER_REG (PIXFORMAT_REG_BASE | 0x0002)
1546 +#define MIPI_LANES_REG (PIXFORMAT_REG_BASE | 0x0003)
1547 +#define FLIPS_DONT_CHANGE_ORDER_REG (PIXFORMAT_REG_BASE | 0x0004)
1549 +#define RESOLUTION_INDEX_REG (FORMAT_REG_BASE | 0x0000)
1550 +#define FORMAT_WIDTH_REG (FORMAT_REG_BASE | 0x0001)
1551 +#define FORMAT_HEIGHT_REG (FORMAT_REG_BASE | 0x0002)
1553 +#define CTRL_INDEX_REG (CTRL_REG_BASE | 0x0000)
1554 +#define CTRL_ID_REG (CTRL_REG_BASE | 0x0001)
1555 +#define CTRL_MIN_REG (CTRL_REG_BASE | 0x0002)
1556 +#define CTRL_MAX_REG (CTRL_REG_BASE | 0x0003)
1557 +#define CTRL_STEP_REG (CTRL_REG_BASE | 0x0004)
1558 +#define CTRL_DEF_REG (CTRL_REG_BASE | 0x0005)
1559 +#define CTRL_VALUE_REG (CTRL_REG_BASE | 0x0006)
1561 +#define IPC_SEL_TARGET_REG (IPC_REG_BASE | 0x0000)
1562 +#define IPC_SEL_TOP_REG (IPC_REG_BASE | 0x0001)
1563 +#define IPC_SEL_LEFT_REG (IPC_REG_BASE | 0x0002)
1564 +#define IPC_SEL_WIDTH_REG (IPC_REG_BASE | 0x0003)
1565 +#define IPC_SEL_HEIGHT_REG (IPC_REG_BASE | 0x0004)
1566 +#define IPC_DELAY_REG (IPC_REG_BASE | 0x0005)
1568 +#define NO_DATA_AVAILABLE 0xFFFFFFFE
1570 +#define DEVICE_ID 0x0030
1572 +#define I2C_READ_RETRY_COUNT 3
1573 +#define I2C_WRITE_RETRY_COUNT 2
1575 +#define V4L2_CID_ARDUCAM_BASE (V4L2_CID_USER_BASE + 0x1000)
1576 +#define V4L2_CID_ARDUCAM_EXT_TRI (V4L2_CID_ARDUCAM_BASE + 1)
1577 +#define V4L2_CID_ARDUCAM_IRCUT (V4L2_CID_ARDUCAM_BASE + 8)
1580 + IMAGE_DT_YUV420_8 = 0x18,
1581 + IMAGE_DT_YUV420_10,
1583 + IMAGE_DT_YUV420CSPS_8 = 0x1C,
1584 + IMAGE_DT_YUV420CSPS_10,
1585 + IMAGE_DT_YUV422_8,
1586 + IMAGE_DT_YUV422_10,
1593 + IMAGE_DT_RAW6 = 0x28,
1602 + BAYER_ORDER_BGGR = 0,
1603 + BAYER_ORDER_GBRG = 1,
1604 + BAYER_ORDER_GRBG = 2,
1605 + BAYER_ORDER_RGGB = 3,
1606 + BAYER_ORDER_GRAY = 4,
1610 + YUV_ORDER_YUYV = 0,
1611 + YUV_ORDER_YVYU = 1,
1612 + YUV_ORDER_UYVY = 2,
1613 + YUV_ORDER_VYUY = 3,
1616 +struct arducam_resolution {
1621 +struct arducam_format {
1626 + u32 num_resolution_set;
1627 + struct arducam_resolution *resolution_set;