1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2020-2021 Intel Corporation.
4 #include <asm/unaligned.h>
5 #include <linux/acpi.h>
6 #include <linux/delay.h>
8 #include <linux/module.h>
9 #include <linux/pm_runtime.h>
10 #include <linux/version.h>
11 #include <media/v4l2-ctrls.h>
12 #include <media/v4l2-device.h>
13 #include <media/v4l2-fwnode.h>
14 #include "power_ctrl_logic.h"
15 #include <linux/vsc.h>
17 #define OV01A1S_LINK_FREQ_400MHZ 400000000ULL
18 #define OV01A1S_SCLK 40000000LL
19 #define OV01A1S_MCLK 19200000
20 #define OV01A1S_DATA_LANES 1
21 #define OV01A1S_RGB_DEPTH 10
23 #define OV01A1S_REG_CHIP_ID 0x300a
24 #define OV01A1S_CHIP_ID 0x560141
26 #define OV01A1S_REG_MODE_SELECT 0x0100
27 #define OV01A1S_MODE_STANDBY 0x00
28 #define OV01A1S_MODE_STREAMING 0x01
30 /* vertical-timings from sensor */
31 #define OV01A1S_REG_VTS 0x380e
32 #define OV01A1S_VTS_DEF 0x0380
33 #define OV01A1S_VTS_MIN 0x0380
34 #define OV01A1S_VTS_MAX 0xffff
36 /* Exposure controls from sensor */
37 #define OV01A1S_REG_EXPOSURE 0x3501
38 #define OV01A1S_EXPOSURE_MIN 4
39 #define OV01A1S_EXPOSURE_MAX_MARGIN 8
40 #define OV01A1S_EXPOSURE_STEP 1
42 /* Analog gain controls from sensor */
43 #define OV01A1S_REG_ANALOG_GAIN 0x3508
44 #define OV01A1S_ANAL_GAIN_MIN 0x100
45 #define OV01A1S_ANAL_GAIN_MAX 0xffff
46 #define OV01A1S_ANAL_GAIN_STEP 1
48 /* Digital gain controls from sensor */
49 #define OV01A1S_REG_DIGILAL_GAIN_B 0x350A
50 #define OV01A1S_REG_DIGITAL_GAIN_GB 0x3510
51 #define OV01A1S_REG_DIGITAL_GAIN_GR 0x3513
52 #define OV01A1S_REG_DIGITAL_GAIN_R 0x3516
53 #define OV01A1S_DGTL_GAIN_MIN 0
54 #define OV01A1S_DGTL_GAIN_MAX 0x3ffff
55 #define OV01A1S_DGTL_GAIN_STEP 1
56 #define OV01A1S_DGTL_GAIN_DEFAULT 1024
58 /* Test Pattern Control */
59 #define OV01A1S_REG_TEST_PATTERN 0x4503
60 #define OV01A1S_TEST_PATTERN_ENABLE BIT(7)
61 #define OV01A1S_TEST_PATTERN_BAR_SHIFT 0
64 OV01A1S_LINK_FREQ_400MHZ_INDEX
,
72 struct ov01a1s_reg_list
{
74 const struct ov01a1s_reg
*regs
;
77 struct ov01a1s_link_freq_config
{
78 const struct ov01a1s_reg_list reg_list
;
82 /* Frame width in pixels */
85 /* Frame height in pixels */
88 /* Horizontal timining size */
91 /* Default vertical timining size */
94 /* Min vertical timining size */
97 /* Link frequency needed for this resolution */
100 /* Sensor register settings for this resolution */
101 const struct ov01a1s_reg_list reg_list
;
104 static const struct ov01a1s_reg mipi_data_rate_720mbps
[] = {
107 static const struct ov01a1s_reg sensor_1296x800_setting
[] = {
251 static const char * const ov01a1s_test_pattern_menu
[] = {
254 "Top-Bottom Darker Color Bar",
255 "Right-Left Darker Color Bar",
259 static const s64 link_freq_menu_items
[] = {
260 OV01A1S_LINK_FREQ_400MHZ
,
263 static const struct ov01a1s_link_freq_config link_freq_configs
[] = {
264 [OV01A1S_LINK_FREQ_400MHZ_INDEX
] = {
266 .num_of_regs
= ARRAY_SIZE(mipi_data_rate_720mbps
),
267 .regs
= mipi_data_rate_720mbps
,
272 static const struct ov01a1s_mode supported_modes
[] = {
277 .vts_def
= OV01A1S_VTS_DEF
,
278 .vts_min
= OV01A1S_VTS_MIN
,
280 .num_of_regs
= ARRAY_SIZE(sensor_1296x800_setting
),
281 .regs
= sensor_1296x800_setting
,
283 .link_freq_index
= OV01A1S_LINK_FREQ_400MHZ_INDEX
,
288 struct v4l2_subdev sd
;
289 struct media_pad pad
;
290 struct v4l2_ctrl_handler ctrl_handler
;
293 struct v4l2_ctrl
*link_freq
;
294 struct v4l2_ctrl
*pixel_rate
;
295 struct v4l2_ctrl
*vblank
;
296 struct v4l2_ctrl
*hblank
;
297 struct v4l2_ctrl
*exposure
;
300 const struct ov01a1s_mode
*cur_mode
;
302 /* To serialize asynchronus callbacks */
305 /* Streaming on/off */
309 static inline struct ov01a1s
*to_ov01a1s(struct v4l2_subdev
*subdev
)
311 return container_of(subdev
, struct ov01a1s
, sd
);
314 static int ov01a1s_read_reg(struct ov01a1s
*ov01a1s
, u16 reg
, u16 len
, u32
*val
)
316 struct i2c_client
*client
= v4l2_get_subdevdata(&ov01a1s
->sd
);
317 struct i2c_msg msgs
[2];
319 u8 data_buf
[4] = {0};
322 if (len
> sizeof(data_buf
))
325 put_unaligned_be16(reg
, addr_buf
);
326 msgs
[0].addr
= client
->addr
;
328 msgs
[0].len
= sizeof(addr_buf
);
329 msgs
[0].buf
= addr_buf
;
330 msgs
[1].addr
= client
->addr
;
331 msgs
[1].flags
= I2C_M_RD
;
333 msgs
[1].buf
= &data_buf
[sizeof(data_buf
) - len
];
335 ret
= i2c_transfer(client
->adapter
, msgs
, ARRAY_SIZE(msgs
));
336 if (ret
!= ARRAY_SIZE(msgs
))
337 return ret
< 0 ? ret
: -EIO
;
339 *val
= get_unaligned_be32(data_buf
);
344 static int ov01a1s_write_reg(struct ov01a1s
*ov01a1s
, u16 reg
, u16 len
, u32 val
)
346 struct i2c_client
*client
= v4l2_get_subdevdata(&ov01a1s
->sd
);
353 put_unaligned_be16(reg
, buf
);
354 put_unaligned_be32(val
<< 8 * (4 - len
), buf
+ 2);
356 ret
= i2c_master_send(client
, buf
, len
+ 2);
358 return ret
< 0 ? ret
: -EIO
;
363 static int ov01a1s_write_reg_list(struct ov01a1s
*ov01a1s
,
364 const struct ov01a1s_reg_list
*r_list
)
366 struct i2c_client
*client
= v4l2_get_subdevdata(&ov01a1s
->sd
);
370 for (i
= 0; i
< r_list
->num_of_regs
; i
++) {
371 ret
= ov01a1s_write_reg(ov01a1s
, r_list
->regs
[i
].address
, 1,
372 r_list
->regs
[i
].val
);
374 dev_err_ratelimited(&client
->dev
,
375 "write reg 0x%4.4x return err = %d",
376 r_list
->regs
[i
].address
, ret
);
384 static int ov01a1s_update_digital_gain(struct ov01a1s
*ov01a1s
, u32 d_gain
)
386 struct i2c_client
*client
= v4l2_get_subdevdata(&ov01a1s
->sd
);
387 u32 real
= d_gain
<< 6;
390 ret
= ov01a1s_write_reg(ov01a1s
, OV01A1S_REG_DIGILAL_GAIN_B
, 3, real
);
392 dev_err(&client
->dev
, "failed to set OV01A1S_REG_DIGITAL_GAIN_B");
395 ret
= ov01a1s_write_reg(ov01a1s
, OV01A1S_REG_DIGITAL_GAIN_GB
, 3, real
);
397 dev_err(&client
->dev
, "failed to set OV01A1S_REG_DIGITAL_GAIN_GB");
400 ret
= ov01a1s_write_reg(ov01a1s
, OV01A1S_REG_DIGITAL_GAIN_GR
, 3, real
);
402 dev_err(&client
->dev
, "failed to set OV01A1S_REG_DIGITAL_GAIN_GR");
406 ret
= ov01a1s_write_reg(ov01a1s
, OV01A1S_REG_DIGITAL_GAIN_R
, 3, real
);
408 dev_err(&client
->dev
, "failed to set OV01A1S_REG_DIGITAL_GAIN_R");
414 static int ov01a1s_test_pattern(struct ov01a1s
*ov01a1s
, u32 pattern
)
417 pattern
= (pattern
- 1) << OV01A1S_TEST_PATTERN_BAR_SHIFT
|
418 OV01A1S_TEST_PATTERN_ENABLE
;
420 return ov01a1s_write_reg(ov01a1s
, OV01A1S_REG_TEST_PATTERN
, 1, pattern
);
423 static int ov01a1s_set_ctrl(struct v4l2_ctrl
*ctrl
)
425 struct ov01a1s
*ov01a1s
= container_of(ctrl
->handler
,
426 struct ov01a1s
, ctrl_handler
);
427 struct i2c_client
*client
= v4l2_get_subdevdata(&ov01a1s
->sd
);
431 /* Propagate change of current control to all related controls */
432 if (ctrl
->id
== V4L2_CID_VBLANK
) {
433 /* Update max exposure while meeting expected vblanking */
434 exposure_max
= ov01a1s
->cur_mode
->height
+ ctrl
->val
-
435 OV01A1S_EXPOSURE_MAX_MARGIN
;
436 __v4l2_ctrl_modify_range(ov01a1s
->exposure
,
437 ov01a1s
->exposure
->minimum
,
438 exposure_max
, ov01a1s
->exposure
->step
,
442 /* V4L2 controls values will be applied only when power is already up */
443 if (!pm_runtime_get_if_in_use(&client
->dev
))
447 case V4L2_CID_ANALOGUE_GAIN
:
448 ret
= ov01a1s_write_reg(ov01a1s
, OV01A1S_REG_ANALOG_GAIN
, 2,
452 case V4L2_CID_DIGITAL_GAIN
:
453 ret
= ov01a1s_update_digital_gain(ov01a1s
, ctrl
->val
);
456 case V4L2_CID_EXPOSURE
:
457 ret
= ov01a1s_write_reg(ov01a1s
, OV01A1S_REG_EXPOSURE
, 2,
461 case V4L2_CID_VBLANK
:
462 ret
= ov01a1s_write_reg(ov01a1s
, OV01A1S_REG_VTS
, 2,
463 ov01a1s
->cur_mode
->height
+ ctrl
->val
);
466 case V4L2_CID_TEST_PATTERN
:
467 ret
= ov01a1s_test_pattern(ov01a1s
, ctrl
->val
);
475 pm_runtime_put(&client
->dev
);
480 static const struct v4l2_ctrl_ops ov01a1s_ctrl_ops
= {
481 .s_ctrl
= ov01a1s_set_ctrl
,
484 static int ov01a1s_init_controls(struct ov01a1s
*ov01a1s
)
486 struct v4l2_ctrl_handler
*ctrl_hdlr
;
487 const struct ov01a1s_mode
*cur_mode
;
488 s64 exposure_max
, h_blank
;
489 u32 vblank_min
, vblank_max
, vblank_default
;
493 ctrl_hdlr
= &ov01a1s
->ctrl_handler
;
494 ret
= v4l2_ctrl_handler_init(ctrl_hdlr
, 8);
498 ctrl_hdlr
->lock
= &ov01a1s
->mutex
;
499 cur_mode
= ov01a1s
->cur_mode
;
500 size
= ARRAY_SIZE(link_freq_menu_items
);
502 ov01a1s
->link_freq
= v4l2_ctrl_new_int_menu(ctrl_hdlr
,
506 link_freq_menu_items
);
507 if (ov01a1s
->link_freq
)
508 ov01a1s
->link_freq
->flags
|= V4L2_CTRL_FLAG_READ_ONLY
;
510 ov01a1s
->pixel_rate
= v4l2_ctrl_new_std(ctrl_hdlr
, &ov01a1s_ctrl_ops
,
511 V4L2_CID_PIXEL_RATE
, 0,
512 OV01A1S_SCLK
, 1, OV01A1S_SCLK
);
514 vblank_min
= cur_mode
->vts_min
- cur_mode
->height
;
515 vblank_max
= OV01A1S_VTS_MAX
- cur_mode
->height
;
516 vblank_default
= cur_mode
->vts_def
- cur_mode
->height
;
517 ov01a1s
->vblank
= v4l2_ctrl_new_std(ctrl_hdlr
, &ov01a1s_ctrl_ops
,
518 V4L2_CID_VBLANK
, vblank_min
,
519 vblank_max
, 1, vblank_default
);
521 h_blank
= cur_mode
->hts
- cur_mode
->width
;
522 ov01a1s
->hblank
= v4l2_ctrl_new_std(ctrl_hdlr
, &ov01a1s_ctrl_ops
,
523 V4L2_CID_HBLANK
, h_blank
, h_blank
,
526 ov01a1s
->hblank
->flags
|= V4L2_CTRL_FLAG_READ_ONLY
;
528 v4l2_ctrl_new_std(ctrl_hdlr
, &ov01a1s_ctrl_ops
, V4L2_CID_ANALOGUE_GAIN
,
529 OV01A1S_ANAL_GAIN_MIN
, OV01A1S_ANAL_GAIN_MAX
,
530 OV01A1S_ANAL_GAIN_STEP
, OV01A1S_ANAL_GAIN_MIN
);
531 v4l2_ctrl_new_std(ctrl_hdlr
, &ov01a1s_ctrl_ops
, V4L2_CID_DIGITAL_GAIN
,
532 OV01A1S_DGTL_GAIN_MIN
, OV01A1S_DGTL_GAIN_MAX
,
533 OV01A1S_DGTL_GAIN_STEP
, OV01A1S_DGTL_GAIN_DEFAULT
);
534 exposure_max
= cur_mode
->vts_def
- OV01A1S_EXPOSURE_MAX_MARGIN
;
535 ov01a1s
->exposure
= v4l2_ctrl_new_std(ctrl_hdlr
, &ov01a1s_ctrl_ops
,
537 OV01A1S_EXPOSURE_MIN
,
539 OV01A1S_EXPOSURE_STEP
,
541 v4l2_ctrl_new_std_menu_items(ctrl_hdlr
, &ov01a1s_ctrl_ops
,
542 V4L2_CID_TEST_PATTERN
,
543 ARRAY_SIZE(ov01a1s_test_pattern_menu
) - 1,
544 0, 0, ov01a1s_test_pattern_menu
);
545 if (ctrl_hdlr
->error
)
546 return ctrl_hdlr
->error
;
548 ov01a1s
->sd
.ctrl_handler
= ctrl_hdlr
;
553 static void ov01a1s_update_pad_format(const struct ov01a1s_mode
*mode
,
554 struct v4l2_mbus_framefmt
*fmt
)
556 fmt
->width
= mode
->width
;
557 fmt
->height
= mode
->height
;
558 fmt
->code
= MEDIA_BUS_FMT_SGRBG10_1X10
;
559 fmt
->field
= V4L2_FIELD_NONE
;
562 static int ov01a1s_start_streaming(struct ov01a1s
*ov01a1s
)
564 struct i2c_client
*client
= v4l2_get_subdevdata(&ov01a1s
->sd
);
565 const struct ov01a1s_reg_list
*reg_list
;
569 power_ctrl_logic_set_power(1);
570 link_freq_index
= ov01a1s
->cur_mode
->link_freq_index
;
571 reg_list
= &link_freq_configs
[link_freq_index
].reg_list
;
572 ret
= ov01a1s_write_reg_list(ov01a1s
, reg_list
);
574 dev_err(&client
->dev
, "failed to set plls");
578 reg_list
= &ov01a1s
->cur_mode
->reg_list
;
579 ret
= ov01a1s_write_reg_list(ov01a1s
, reg_list
);
581 dev_err(&client
->dev
, "failed to set mode");
585 ret
= __v4l2_ctrl_handler_setup(ov01a1s
->sd
.ctrl_handler
);
589 ret
= ov01a1s_write_reg(ov01a1s
, OV01A1S_REG_MODE_SELECT
, 1,
590 OV01A1S_MODE_STREAMING
);
592 dev_err(&client
->dev
, "failed to start streaming");
597 static void ov01a1s_stop_streaming(struct ov01a1s
*ov01a1s
)
599 struct i2c_client
*client
= v4l2_get_subdevdata(&ov01a1s
->sd
);
602 ret
= ov01a1s_write_reg(ov01a1s
, OV01A1S_REG_MODE_SELECT
, 1,
603 OV01A1S_MODE_STANDBY
);
605 dev_err(&client
->dev
, "failed to stop streaming");
606 power_ctrl_logic_set_power(0);
609 static int ov01a1s_set_stream(struct v4l2_subdev
*sd
, int enable
)
611 struct ov01a1s
*ov01a1s
= to_ov01a1s(sd
);
612 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
615 if (ov01a1s
->streaming
== enable
)
618 mutex_lock(&ov01a1s
->mutex
);
620 ret
= pm_runtime_get_sync(&client
->dev
);
622 pm_runtime_put_noidle(&client
->dev
);
623 mutex_unlock(&ov01a1s
->mutex
);
627 ret
= ov01a1s_start_streaming(ov01a1s
);
630 ov01a1s_stop_streaming(ov01a1s
);
631 pm_runtime_put(&client
->dev
);
634 ov01a1s_stop_streaming(ov01a1s
);
635 pm_runtime_put(&client
->dev
);
638 ov01a1s
->streaming
= enable
;
639 mutex_unlock(&ov01a1s
->mutex
);
644 static int __maybe_unused
ov01a1s_suspend(struct device
*dev
)
646 struct i2c_client
*client
= to_i2c_client(dev
);
647 struct v4l2_subdev
*sd
= i2c_get_clientdata(client
);
648 struct ov01a1s
*ov01a1s
= to_ov01a1s(sd
);
650 mutex_lock(&ov01a1s
->mutex
);
651 if (ov01a1s
->streaming
)
652 ov01a1s_stop_streaming(ov01a1s
);
654 mutex_unlock(&ov01a1s
->mutex
);
659 static int __maybe_unused
ov01a1s_resume(struct device
*dev
)
661 struct i2c_client
*client
= to_i2c_client(dev
);
662 struct v4l2_subdev
*sd
= i2c_get_clientdata(client
);
663 struct ov01a1s
*ov01a1s
= to_ov01a1s(sd
);
666 mutex_lock(&ov01a1s
->mutex
);
667 if (!ov01a1s
->streaming
)
670 ret
= ov01a1s_start_streaming(ov01a1s
);
672 ov01a1s
->streaming
= false;
673 ov01a1s_stop_streaming(ov01a1s
);
677 mutex_unlock(&ov01a1s
->mutex
);
681 static int ov01a1s_set_format(struct v4l2_subdev
*sd
,
682 struct v4l2_subdev_state
*sd_state
,
683 struct v4l2_subdev_format
*fmt
)
685 struct ov01a1s
*ov01a1s
= to_ov01a1s(sd
);
686 const struct ov01a1s_mode
*mode
;
687 s32 vblank_def
, h_blank
;
689 mode
= v4l2_find_nearest_size(supported_modes
,
690 ARRAY_SIZE(supported_modes
), width
,
691 height
, fmt
->format
.width
,
694 mutex_lock(&ov01a1s
->mutex
);
695 ov01a1s_update_pad_format(mode
, &fmt
->format
);
696 if (fmt
->which
== V4L2_SUBDEV_FORMAT_TRY
) {
697 *v4l2_subdev_get_try_format(sd
, sd_state
, fmt
->pad
) = fmt
->format
;
699 ov01a1s
->cur_mode
= mode
;
700 __v4l2_ctrl_s_ctrl(ov01a1s
->link_freq
, mode
->link_freq_index
);
701 __v4l2_ctrl_s_ctrl_int64(ov01a1s
->pixel_rate
, OV01A1S_SCLK
);
703 /* Update limits and set FPS to default */
704 vblank_def
= mode
->vts_def
- mode
->height
;
705 __v4l2_ctrl_modify_range(ov01a1s
->vblank
,
706 mode
->vts_min
- mode
->height
,
707 OV01A1S_VTS_MAX
- mode
->height
, 1,
709 __v4l2_ctrl_s_ctrl(ov01a1s
->vblank
, vblank_def
);
710 h_blank
= mode
->hts
- mode
->width
;
711 __v4l2_ctrl_modify_range(ov01a1s
->hblank
, h_blank
, h_blank
, 1,
714 mutex_unlock(&ov01a1s
->mutex
);
719 static int ov01a1s_get_format(struct v4l2_subdev
*sd
,
720 struct v4l2_subdev_state
*sd_state
,
721 struct v4l2_subdev_format
*fmt
)
723 struct ov01a1s
*ov01a1s
= to_ov01a1s(sd
);
725 mutex_lock(&ov01a1s
->mutex
);
726 if (fmt
->which
== V4L2_SUBDEV_FORMAT_TRY
)
727 fmt
->format
= *v4l2_subdev_get_try_format(&ov01a1s
->sd
,
730 ov01a1s_update_pad_format(ov01a1s
->cur_mode
, &fmt
->format
);
732 mutex_unlock(&ov01a1s
->mutex
);
737 static int ov01a1s_enum_mbus_code(struct v4l2_subdev
*sd
,
738 struct v4l2_subdev_state
*sd_state
,
739 struct v4l2_subdev_mbus_code_enum
*code
)
744 code
->code
= MEDIA_BUS_FMT_SGRBG10_1X10
;
749 static int ov01a1s_enum_frame_size(struct v4l2_subdev
*sd
,
750 struct v4l2_subdev_state
*sd_state
,
751 struct v4l2_subdev_frame_size_enum
*fse
)
753 if (fse
->index
>= ARRAY_SIZE(supported_modes
))
756 if (fse
->code
!= MEDIA_BUS_FMT_SGRBG10_1X10
)
759 fse
->min_width
= supported_modes
[fse
->index
].width
;
760 fse
->max_width
= fse
->min_width
;
761 fse
->min_height
= supported_modes
[fse
->index
].height
;
762 fse
->max_height
= fse
->min_height
;
767 static int ov01a1s_open(struct v4l2_subdev
*sd
, struct v4l2_subdev_fh
*fh
)
769 struct ov01a1s
*ov01a1s
= to_ov01a1s(sd
);
771 mutex_lock(&ov01a1s
->mutex
);
772 ov01a1s_update_pad_format(&supported_modes
[0],
773 v4l2_subdev_get_try_format(sd
, fh
->state
, 0));
774 mutex_unlock(&ov01a1s
->mutex
);
779 static const struct v4l2_subdev_video_ops ov01a1s_video_ops
= {
780 .s_stream
= ov01a1s_set_stream
,
783 static const struct v4l2_subdev_pad_ops ov01a1s_pad_ops
= {
784 .set_fmt
= ov01a1s_set_format
,
785 .get_fmt
= ov01a1s_get_format
,
786 .enum_mbus_code
= ov01a1s_enum_mbus_code
,
787 .enum_frame_size
= ov01a1s_enum_frame_size
,
790 static const struct v4l2_subdev_ops ov01a1s_subdev_ops
= {
791 .video
= &ov01a1s_video_ops
,
792 .pad
= &ov01a1s_pad_ops
,
795 static const struct media_entity_operations ov01a1s_subdev_entity_ops
= {
796 .link_validate
= v4l2_subdev_link_validate
,
799 static const struct v4l2_subdev_internal_ops ov01a1s_internal_ops
= {
800 .open
= ov01a1s_open
,
803 static int ov01a1s_identify_module(struct ov01a1s
*ov01a1s
)
805 struct i2c_client
*client
= v4l2_get_subdevdata(&ov01a1s
->sd
);
809 ret
= ov01a1s_read_reg(ov01a1s
, OV01A1S_REG_CHIP_ID
, 3, &val
);
813 if (val
!= OV01A1S_CHIP_ID
) {
814 dev_err(&client
->dev
, "chip id mismatch: %x!=%x",
815 OV01A1S_CHIP_ID
, val
);
822 static int ov01a1s_remove(struct i2c_client
*client
)
824 struct v4l2_subdev
*sd
= i2c_get_clientdata(client
);
825 struct ov01a1s
*ov01a1s
= to_ov01a1s(sd
);
827 v4l2_async_unregister_subdev(sd
);
828 media_entity_cleanup(&sd
->entity
);
829 v4l2_ctrl_handler_free(sd
->ctrl_handler
);
830 pm_runtime_disable(&client
->dev
);
831 mutex_destroy(&ov01a1s
->mutex
);
836 static int ov01a1s_probe(struct i2c_client
*client
)
838 struct ov01a1s
*ov01a1s
;
840 struct vsc_mipi_config conf
;
841 struct vsc_camera_status status
;
844 conf
.lane_num
= OV01A1S_DATA_LANES
;
845 /* frequency unit 100k */
846 conf
.freq
= OV01A1S_LINK_FREQ_400MHZ
/ 100000;
847 ret
= vsc_acquire_camera_sensor(&conf
, NULL
, NULL
, &status
);
849 ret
= power_ctrl_logic_set_power(1);
851 return -EPROBE_DEFER
;
854 ov01a1s
= devm_kzalloc(&client
->dev
, sizeof(*ov01a1s
), GFP_KERNEL
);
857 goto probe_error_ret
;
860 v4l2_i2c_subdev_init(&ov01a1s
->sd
, client
, &ov01a1s_subdev_ops
);
861 ret
= ov01a1s_identify_module(ov01a1s
);
863 dev_err(&client
->dev
, "failed to find sensor: %d", ret
);
864 goto probe_error_ret
;
867 mutex_init(&ov01a1s
->mutex
);
868 ov01a1s
->cur_mode
= &supported_modes
[0];
869 ret
= ov01a1s_init_controls(ov01a1s
);
871 dev_err(&client
->dev
, "failed to init controls: %d", ret
);
872 goto probe_error_v4l2_ctrl_handler_free
;
875 ov01a1s
->sd
.internal_ops
= &ov01a1s_internal_ops
;
876 ov01a1s
->sd
.flags
|= V4L2_SUBDEV_FL_HAS_DEVNODE
;
877 ov01a1s
->sd
.entity
.ops
= &ov01a1s_subdev_entity_ops
;
878 ov01a1s
->sd
.entity
.function
= MEDIA_ENT_F_CAM_SENSOR
;
879 ov01a1s
->pad
.flags
= MEDIA_PAD_FL_SOURCE
;
880 ret
= media_entity_pads_init(&ov01a1s
->sd
.entity
, 1, &ov01a1s
->pad
);
882 dev_err(&client
->dev
, "failed to init entity pads: %d", ret
);
883 goto probe_error_v4l2_ctrl_handler_free
;
886 ret
= v4l2_async_register_subdev_sensor(&ov01a1s
->sd
);
888 dev_err(&client
->dev
, "failed to register V4L2 subdev: %d",
890 goto probe_error_media_entity_cleanup
;
893 vsc_release_camera_sensor(&status
);
895 * Device is already turned on by i2c-core with ACPI domain PM.
896 * Enable runtime PM and turn off the device.
898 pm_runtime_set_active(&client
->dev
);
899 pm_runtime_enable(&client
->dev
);
900 pm_runtime_idle(&client
->dev
);
902 power_ctrl_logic_set_power(0);
905 probe_error_media_entity_cleanup
:
906 media_entity_cleanup(&ov01a1s
->sd
.entity
);
908 probe_error_v4l2_ctrl_handler_free
:
909 v4l2_ctrl_handler_free(ov01a1s
->sd
.ctrl_handler
);
910 mutex_destroy(&ov01a1s
->mutex
);
913 power_ctrl_logic_set_power(0);
914 vsc_release_camera_sensor(&status
);
918 static const struct dev_pm_ops ov01a1s_pm_ops
= {
919 SET_SYSTEM_SLEEP_PM_OPS(ov01a1s_suspend
, ov01a1s_resume
)
923 static const struct acpi_device_id ov01a1s_acpi_ids
[] = {
928 MODULE_DEVICE_TABLE(acpi
, ov01a1s_acpi_ids
);
931 static struct i2c_driver ov01a1s_i2c_driver
= {
934 .pm
= &ov01a1s_pm_ops
,
935 .acpi_match_table
= ACPI_PTR(ov01a1s_acpi_ids
),
937 .probe_new
= ov01a1s_probe
,
938 .remove
= ov01a1s_remove
,
941 module_i2c_driver(ov01a1s_i2c_driver
);
943 MODULE_AUTHOR("Xu, Chongyang <chongyang.xu@intel.com>");
944 MODULE_AUTHOR("Lai, Jim <jim.lai@intel.com>");
945 MODULE_AUTHOR("Qiu, Tianshu <tian.shu.qiu@intel.com>");
946 MODULE_AUTHOR("Shawn Tu <shawnx.tu@intel.com>");
947 MODULE_AUTHOR("Bingbu Cao <bingbu.cao@intel.com>");
948 MODULE_DESCRIPTION("OmniVision OV01A1S sensor driver");
949 MODULE_LICENSE("GPL v2");