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 <media/v4l2-ctrls.h>
11 #include <media/v4l2-device.h>
12 #include <media/v4l2-fwnode.h>
13 #include "power_ctrl_logic.h"
15 #define OV01A1S_LINK_FREQ_400MHZ 400000000ULL
16 #define OV01A1S_SCLK 40000000LL
17 #define OV01A1S_MCLK 19200000
18 #define OV01A1S_DATA_LANES 1
19 #define OV01A1S_RGB_DEPTH 10
21 #define OV01A1S_REG_CHIP_ID 0x300a
22 #define OV01A1S_CHIP_ID 0x560141
24 #define OV01A1S_REG_MODE_SELECT 0x0100
25 #define OV01A1S_MODE_STANDBY 0x00
26 #define OV01A1S_MODE_STREAMING 0x01
28 /* vertical-timings from sensor */
29 #define OV01A1S_REG_VTS 0x380e
30 #define OV01A1S_VTS_DEF 0x0380
31 #define OV01A1S_VTS_MIN 0x0380
32 #define OV01A1S_VTS_MAX 0xffff
34 /* Exposure controls from sensor */
35 #define OV01A1S_REG_EXPOSURE 0x3501
36 #define OV01A1S_EXPOSURE_MIN 4
37 #define OV01A1S_EXPOSURE_MAX_MARGIN 8
38 #define OV01A1S_EXPOSURE_STEP 1
40 /* Analog gain controls from sensor */
41 #define OV01A1S_REG_ANALOG_GAIN 0x3508
42 #define OV01A1S_ANAL_GAIN_MIN 0x100
43 #define OV01A1S_ANAL_GAIN_MAX 0xffff
44 #define OV01A1S_ANAL_GAIN_STEP 1
46 /* Digital gain controls from sensor */
47 #define OV01A1S_REG_DIGILAL_GAIN_B 0x350A
48 #define OV01A1S_REG_DIGITAL_GAIN_GB 0x3510
49 #define OV01A1S_REG_DIGITAL_GAIN_GR 0x3513
50 #define OV01A1S_REG_DIGITAL_GAIN_R 0x3516
51 #define OV01A1S_DGTL_GAIN_MIN 0
52 #define OV01A1S_DGTL_GAIN_MAX 0x3ffff
53 #define OV01A1S_DGTL_GAIN_STEP 1
54 #define OV01A1S_DGTL_GAIN_DEFAULT 1024
56 /* Test Pattern Control */
57 #define OV01A1S_REG_TEST_PATTERN 0x4503
58 #define OV01A1S_TEST_PATTERN_ENABLE BIT(7)
59 #define OV01A1S_TEST_PATTERN_BAR_SHIFT 0
62 OV01A1S_LINK_FREQ_400MHZ_INDEX
,
70 struct ov01a1s_reg_list
{
72 const struct ov01a1s_reg
*regs
;
75 struct ov01a1s_link_freq_config
{
76 const struct ov01a1s_reg_list reg_list
;
80 /* Frame width in pixels */
83 /* Frame height in pixels */
86 /* Horizontal timining size */
89 /* Default vertical timining size */
92 /* Min vertical timining size */
95 /* Link frequency needed for this resolution */
98 /* Sensor register settings for this resolution */
99 const struct ov01a1s_reg_list reg_list
;
102 static const struct ov01a1s_reg mipi_data_rate_720mbps
[] = {
105 static const struct ov01a1s_reg sensor_1296x800_setting
[] = {
249 static const char * const ov01a1s_test_pattern_menu
[] = {
252 "Top-Bottom Darker Color Bar",
253 "Right-Left Darker Color Bar",
257 static const s64 link_freq_menu_items
[] = {
258 OV01A1S_LINK_FREQ_400MHZ
,
261 static const struct ov01a1s_link_freq_config link_freq_configs
[] = {
262 [OV01A1S_LINK_FREQ_400MHZ_INDEX
] = {
264 .num_of_regs
= ARRAY_SIZE(mipi_data_rate_720mbps
),
265 .regs
= mipi_data_rate_720mbps
,
270 static const struct ov01a1s_mode supported_modes
[] = {
275 .vts_def
= OV01A1S_VTS_DEF
,
276 .vts_min
= OV01A1S_VTS_MIN
,
278 .num_of_regs
= ARRAY_SIZE(sensor_1296x800_setting
),
279 .regs
= sensor_1296x800_setting
,
281 .link_freq_index
= OV01A1S_LINK_FREQ_400MHZ_INDEX
,
286 struct v4l2_subdev sd
;
287 struct media_pad pad
;
288 struct v4l2_ctrl_handler ctrl_handler
;
291 struct v4l2_ctrl
*link_freq
;
292 struct v4l2_ctrl
*pixel_rate
;
293 struct v4l2_ctrl
*vblank
;
294 struct v4l2_ctrl
*hblank
;
295 struct v4l2_ctrl
*exposure
;
298 const struct ov01a1s_mode
*cur_mode
;
300 /* To serialize asynchronus callbacks */
303 /* Streaming on/off */
307 static inline struct ov01a1s
*to_ov01a1s(struct v4l2_subdev
*subdev
)
309 return container_of(subdev
, struct ov01a1s
, sd
);
312 static int ov01a1s_read_reg(struct ov01a1s
*ov01a1s
, u16 reg
, u16 len
, u32
*val
)
314 struct i2c_client
*client
= v4l2_get_subdevdata(&ov01a1s
->sd
);
315 struct i2c_msg msgs
[2];
317 u8 data_buf
[4] = {0};
320 if (len
> sizeof(data_buf
))
323 put_unaligned_be16(reg
, addr_buf
);
324 msgs
[0].addr
= client
->addr
;
326 msgs
[0].len
= sizeof(addr_buf
);
327 msgs
[0].buf
= addr_buf
;
328 msgs
[1].addr
= client
->addr
;
329 msgs
[1].flags
= I2C_M_RD
;
331 msgs
[1].buf
= &data_buf
[sizeof(data_buf
) - len
];
333 ret
= i2c_transfer(client
->adapter
, msgs
, ARRAY_SIZE(msgs
));
334 if (ret
!= ARRAY_SIZE(msgs
))
335 return ret
< 0 ? ret
: -EIO
;
337 *val
= get_unaligned_be32(data_buf
);
342 static int ov01a1s_write_reg(struct ov01a1s
*ov01a1s
, u16 reg
, u16 len
, u32 val
)
344 struct i2c_client
*client
= v4l2_get_subdevdata(&ov01a1s
->sd
);
351 put_unaligned_be16(reg
, buf
);
352 put_unaligned_be32(val
<< 8 * (4 - len
), buf
+ 2);
354 ret
= i2c_master_send(client
, buf
, len
+ 2);
356 return ret
< 0 ? ret
: -EIO
;
361 static int ov01a1s_write_reg_list(struct ov01a1s
*ov01a1s
,
362 const struct ov01a1s_reg_list
*r_list
)
364 struct i2c_client
*client
= v4l2_get_subdevdata(&ov01a1s
->sd
);
368 for (i
= 0; i
< r_list
->num_of_regs
; i
++) {
369 ret
= ov01a1s_write_reg(ov01a1s
, r_list
->regs
[i
].address
, 1,
370 r_list
->regs
[i
].val
);
372 dev_err_ratelimited(&client
->dev
,
373 "write reg 0x%4.4x return err = %d",
374 r_list
->regs
[i
].address
, ret
);
382 static int ov01a1s_update_digital_gain(struct ov01a1s
*ov01a1s
, u32 d_gain
)
384 struct i2c_client
*client
= v4l2_get_subdevdata(&ov01a1s
->sd
);
385 u32 real
= d_gain
<< 6;
388 ret
= ov01a1s_write_reg(ov01a1s
, OV01A1S_REG_DIGILAL_GAIN_B
, 3, real
);
390 dev_err(&client
->dev
, "failed to set OV01A1S_REG_DIGITAL_GAIN_B");
393 ret
= ov01a1s_write_reg(ov01a1s
, OV01A1S_REG_DIGITAL_GAIN_GB
, 3, real
);
395 dev_err(&client
->dev
, "failed to set OV01A1S_REG_DIGITAL_GAIN_GB");
398 ret
= ov01a1s_write_reg(ov01a1s
, OV01A1S_REG_DIGITAL_GAIN_GR
, 3, real
);
400 dev_err(&client
->dev
, "failed to set OV01A1S_REG_DIGITAL_GAIN_GR");
404 ret
= ov01a1s_write_reg(ov01a1s
, OV01A1S_REG_DIGITAL_GAIN_R
, 3, real
);
406 dev_err(&client
->dev
, "failed to set OV01A1S_REG_DIGITAL_GAIN_R");
412 static int ov01a1s_test_pattern(struct ov01a1s
*ov01a1s
, u32 pattern
)
415 pattern
= (pattern
- 1) << OV01A1S_TEST_PATTERN_BAR_SHIFT
|
416 OV01A1S_TEST_PATTERN_ENABLE
;
418 return ov01a1s_write_reg(ov01a1s
, OV01A1S_REG_TEST_PATTERN
, 1, pattern
);
421 static int ov01a1s_set_ctrl(struct v4l2_ctrl
*ctrl
)
423 struct ov01a1s
*ov01a1s
= container_of(ctrl
->handler
,
424 struct ov01a1s
, ctrl_handler
);
425 struct i2c_client
*client
= v4l2_get_subdevdata(&ov01a1s
->sd
);
429 /* Propagate change of current control to all related controls */
430 if (ctrl
->id
== V4L2_CID_VBLANK
) {
431 /* Update max exposure while meeting expected vblanking */
432 exposure_max
= ov01a1s
->cur_mode
->height
+ ctrl
->val
-
433 OV01A1S_EXPOSURE_MAX_MARGIN
;
434 __v4l2_ctrl_modify_range(ov01a1s
->exposure
,
435 ov01a1s
->exposure
->minimum
,
436 exposure_max
, ov01a1s
->exposure
->step
,
440 /* V4L2 controls values will be applied only when power is already up */
441 if (!pm_runtime_get_if_in_use(&client
->dev
))
445 case V4L2_CID_ANALOGUE_GAIN
:
446 ret
= ov01a1s_write_reg(ov01a1s
, OV01A1S_REG_ANALOG_GAIN
, 2,
450 case V4L2_CID_DIGITAL_GAIN
:
451 ret
= ov01a1s_update_digital_gain(ov01a1s
, ctrl
->val
);
454 case V4L2_CID_EXPOSURE
:
455 ret
= ov01a1s_write_reg(ov01a1s
, OV01A1S_REG_EXPOSURE
, 2,
459 case V4L2_CID_VBLANK
:
460 ret
= ov01a1s_write_reg(ov01a1s
, OV01A1S_REG_VTS
, 2,
461 ov01a1s
->cur_mode
->height
+ ctrl
->val
);
464 case V4L2_CID_TEST_PATTERN
:
465 ret
= ov01a1s_test_pattern(ov01a1s
, ctrl
->val
);
473 pm_runtime_put(&client
->dev
);
478 static const struct v4l2_ctrl_ops ov01a1s_ctrl_ops
= {
479 .s_ctrl
= ov01a1s_set_ctrl
,
482 static int ov01a1s_init_controls(struct ov01a1s
*ov01a1s
)
484 struct v4l2_ctrl_handler
*ctrl_hdlr
;
485 const struct ov01a1s_mode
*cur_mode
;
486 s64 exposure_max
, h_blank
;
487 u32 vblank_min
, vblank_max
, vblank_default
;
491 ctrl_hdlr
= &ov01a1s
->ctrl_handler
;
492 ret
= v4l2_ctrl_handler_init(ctrl_hdlr
, 8);
496 ctrl_hdlr
->lock
= &ov01a1s
->mutex
;
497 cur_mode
= ov01a1s
->cur_mode
;
498 size
= ARRAY_SIZE(link_freq_menu_items
);
500 ov01a1s
->link_freq
= v4l2_ctrl_new_int_menu(ctrl_hdlr
,
504 link_freq_menu_items
);
505 if (ov01a1s
->link_freq
)
506 ov01a1s
->link_freq
->flags
|= V4L2_CTRL_FLAG_READ_ONLY
;
508 ov01a1s
->pixel_rate
= v4l2_ctrl_new_std(ctrl_hdlr
, &ov01a1s_ctrl_ops
,
509 V4L2_CID_PIXEL_RATE
, 0,
510 OV01A1S_SCLK
, 1, OV01A1S_SCLK
);
512 vblank_min
= cur_mode
->vts_min
- cur_mode
->height
;
513 vblank_max
= OV01A1S_VTS_MAX
- cur_mode
->height
;
514 vblank_default
= cur_mode
->vts_def
- cur_mode
->height
;
515 ov01a1s
->vblank
= v4l2_ctrl_new_std(ctrl_hdlr
, &ov01a1s_ctrl_ops
,
516 V4L2_CID_VBLANK
, vblank_min
,
517 vblank_max
, 1, vblank_default
);
519 h_blank
= cur_mode
->hts
- cur_mode
->width
;
520 ov01a1s
->hblank
= v4l2_ctrl_new_std(ctrl_hdlr
, &ov01a1s_ctrl_ops
,
521 V4L2_CID_HBLANK
, h_blank
, h_blank
,
524 ov01a1s
->hblank
->flags
|= V4L2_CTRL_FLAG_READ_ONLY
;
526 v4l2_ctrl_new_std(ctrl_hdlr
, &ov01a1s_ctrl_ops
, V4L2_CID_ANALOGUE_GAIN
,
527 OV01A1S_ANAL_GAIN_MIN
, OV01A1S_ANAL_GAIN_MAX
,
528 OV01A1S_ANAL_GAIN_STEP
, OV01A1S_ANAL_GAIN_MIN
);
529 v4l2_ctrl_new_std(ctrl_hdlr
, &ov01a1s_ctrl_ops
, V4L2_CID_DIGITAL_GAIN
,
530 OV01A1S_DGTL_GAIN_MIN
, OV01A1S_DGTL_GAIN_MAX
,
531 OV01A1S_DGTL_GAIN_STEP
, OV01A1S_DGTL_GAIN_DEFAULT
);
532 exposure_max
= cur_mode
->vts_def
- OV01A1S_EXPOSURE_MAX_MARGIN
;
533 ov01a1s
->exposure
= v4l2_ctrl_new_std(ctrl_hdlr
, &ov01a1s_ctrl_ops
,
535 OV01A1S_EXPOSURE_MIN
,
537 OV01A1S_EXPOSURE_STEP
,
539 v4l2_ctrl_new_std_menu_items(ctrl_hdlr
, &ov01a1s_ctrl_ops
,
540 V4L2_CID_TEST_PATTERN
,
541 ARRAY_SIZE(ov01a1s_test_pattern_menu
) - 1,
542 0, 0, ov01a1s_test_pattern_menu
);
543 if (ctrl_hdlr
->error
)
544 return ctrl_hdlr
->error
;
546 ov01a1s
->sd
.ctrl_handler
= ctrl_hdlr
;
551 static void ov01a1s_update_pad_format(const struct ov01a1s_mode
*mode
,
552 struct v4l2_mbus_framefmt
*fmt
)
554 fmt
->width
= mode
->width
;
555 fmt
->height
= mode
->height
;
556 fmt
->code
= MEDIA_BUS_FMT_SGRBG10_1X10
;
557 fmt
->field
= V4L2_FIELD_NONE
;
560 static int ov01a1s_start_streaming(struct ov01a1s
*ov01a1s
)
562 struct i2c_client
*client
= v4l2_get_subdevdata(&ov01a1s
->sd
);
563 const struct ov01a1s_reg_list
*reg_list
;
567 power_ctrl_logic_set_power(1);
568 link_freq_index
= ov01a1s
->cur_mode
->link_freq_index
;
569 reg_list
= &link_freq_configs
[link_freq_index
].reg_list
;
570 ret
= ov01a1s_write_reg_list(ov01a1s
, reg_list
);
572 dev_err(&client
->dev
, "failed to set plls");
576 reg_list
= &ov01a1s
->cur_mode
->reg_list
;
577 ret
= ov01a1s_write_reg_list(ov01a1s
, reg_list
);
579 dev_err(&client
->dev
, "failed to set mode");
583 ret
= __v4l2_ctrl_handler_setup(ov01a1s
->sd
.ctrl_handler
);
587 ret
= ov01a1s_write_reg(ov01a1s
, OV01A1S_REG_MODE_SELECT
, 1,
588 OV01A1S_MODE_STREAMING
);
590 dev_err(&client
->dev
, "failed to start streaming");
595 static void ov01a1s_stop_streaming(struct ov01a1s
*ov01a1s
)
597 struct i2c_client
*client
= v4l2_get_subdevdata(&ov01a1s
->sd
);
600 ret
= ov01a1s_write_reg(ov01a1s
, OV01A1S_REG_MODE_SELECT
, 1,
601 OV01A1S_MODE_STANDBY
);
603 dev_err(&client
->dev
, "failed to stop streaming");
604 power_ctrl_logic_set_power(0);
607 static int ov01a1s_set_stream(struct v4l2_subdev
*sd
, int enable
)
609 struct ov01a1s
*ov01a1s
= to_ov01a1s(sd
);
610 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
613 if (ov01a1s
->streaming
== enable
)
616 mutex_lock(&ov01a1s
->mutex
);
618 ret
= pm_runtime_get_sync(&client
->dev
);
620 pm_runtime_put_noidle(&client
->dev
);
621 mutex_unlock(&ov01a1s
->mutex
);
625 ret
= ov01a1s_start_streaming(ov01a1s
);
628 ov01a1s_stop_streaming(ov01a1s
);
629 pm_runtime_put(&client
->dev
);
632 ov01a1s_stop_streaming(ov01a1s
);
633 pm_runtime_put(&client
->dev
);
636 ov01a1s
->streaming
= enable
;
637 mutex_unlock(&ov01a1s
->mutex
);
642 static int __maybe_unused
ov01a1s_suspend(struct device
*dev
)
644 struct i2c_client
*client
= to_i2c_client(dev
);
645 struct v4l2_subdev
*sd
= i2c_get_clientdata(client
);
646 struct ov01a1s
*ov01a1s
= to_ov01a1s(sd
);
648 mutex_lock(&ov01a1s
->mutex
);
649 if (ov01a1s
->streaming
)
650 ov01a1s_stop_streaming(ov01a1s
);
652 mutex_unlock(&ov01a1s
->mutex
);
657 static int __maybe_unused
ov01a1s_resume(struct device
*dev
)
659 struct i2c_client
*client
= to_i2c_client(dev
);
660 struct v4l2_subdev
*sd
= i2c_get_clientdata(client
);
661 struct ov01a1s
*ov01a1s
= to_ov01a1s(sd
);
664 mutex_lock(&ov01a1s
->mutex
);
665 if (!ov01a1s
->streaming
)
668 ret
= ov01a1s_start_streaming(ov01a1s
);
670 ov01a1s
->streaming
= false;
671 ov01a1s_stop_streaming(ov01a1s
);
675 mutex_unlock(&ov01a1s
->mutex
);
679 static int ov01a1s_set_format(struct v4l2_subdev
*sd
,
680 struct v4l2_subdev_pad_config
*cfg
,
681 struct v4l2_subdev_format
*fmt
)
683 struct ov01a1s
*ov01a1s
= to_ov01a1s(sd
);
684 const struct ov01a1s_mode
*mode
;
685 s32 vblank_def
, h_blank
;
687 mode
= v4l2_find_nearest_size(supported_modes
,
688 ARRAY_SIZE(supported_modes
), width
,
689 height
, fmt
->format
.width
,
692 mutex_lock(&ov01a1s
->mutex
);
693 ov01a1s_update_pad_format(mode
, &fmt
->format
);
694 if (fmt
->which
== V4L2_SUBDEV_FORMAT_TRY
) {
695 *v4l2_subdev_get_try_format(sd
, cfg
, fmt
->pad
) = fmt
->format
;
697 ov01a1s
->cur_mode
= mode
;
698 __v4l2_ctrl_s_ctrl(ov01a1s
->link_freq
, mode
->link_freq_index
);
699 __v4l2_ctrl_s_ctrl_int64(ov01a1s
->pixel_rate
, OV01A1S_SCLK
);
701 /* Update limits and set FPS to default */
702 vblank_def
= mode
->vts_def
- mode
->height
;
703 __v4l2_ctrl_modify_range(ov01a1s
->vblank
,
704 mode
->vts_min
- mode
->height
,
705 OV01A1S_VTS_MAX
- mode
->height
, 1,
707 __v4l2_ctrl_s_ctrl(ov01a1s
->vblank
, vblank_def
);
708 h_blank
= mode
->hts
- mode
->width
;
709 __v4l2_ctrl_modify_range(ov01a1s
->hblank
, h_blank
, h_blank
, 1,
712 mutex_unlock(&ov01a1s
->mutex
);
717 static int ov01a1s_get_format(struct v4l2_subdev
*sd
,
718 struct v4l2_subdev_pad_config
*cfg
,
719 struct v4l2_subdev_format
*fmt
)
721 struct ov01a1s
*ov01a1s
= to_ov01a1s(sd
);
723 mutex_lock(&ov01a1s
->mutex
);
724 if (fmt
->which
== V4L2_SUBDEV_FORMAT_TRY
)
725 fmt
->format
= *v4l2_subdev_get_try_format(&ov01a1s
->sd
, cfg
,
728 ov01a1s_update_pad_format(ov01a1s
->cur_mode
, &fmt
->format
);
730 mutex_unlock(&ov01a1s
->mutex
);
735 static int ov01a1s_enum_mbus_code(struct v4l2_subdev
*sd
,
736 struct v4l2_subdev_pad_config
*cfg
,
737 struct v4l2_subdev_mbus_code_enum
*code
)
742 code
->code
= MEDIA_BUS_FMT_SGRBG10_1X10
;
747 static int ov01a1s_enum_frame_size(struct v4l2_subdev
*sd
,
748 struct v4l2_subdev_pad_config
*cfg
,
749 struct v4l2_subdev_frame_size_enum
*fse
)
751 if (fse
->index
>= ARRAY_SIZE(supported_modes
))
754 if (fse
->code
!= MEDIA_BUS_FMT_SGRBG10_1X10
)
757 fse
->min_width
= supported_modes
[fse
->index
].width
;
758 fse
->max_width
= fse
->min_width
;
759 fse
->min_height
= supported_modes
[fse
->index
].height
;
760 fse
->max_height
= fse
->min_height
;
765 static int ov01a1s_open(struct v4l2_subdev
*sd
, struct v4l2_subdev_fh
*fh
)
767 struct ov01a1s
*ov01a1s
= to_ov01a1s(sd
);
769 mutex_lock(&ov01a1s
->mutex
);
770 ov01a1s_update_pad_format(&supported_modes
[0],
771 v4l2_subdev_get_try_format(sd
, fh
->pad
, 0));
772 mutex_unlock(&ov01a1s
->mutex
);
777 static const struct v4l2_subdev_video_ops ov01a1s_video_ops
= {
778 .s_stream
= ov01a1s_set_stream
,
781 static const struct v4l2_subdev_pad_ops ov01a1s_pad_ops
= {
782 .set_fmt
= ov01a1s_set_format
,
783 .get_fmt
= ov01a1s_get_format
,
784 .enum_mbus_code
= ov01a1s_enum_mbus_code
,
785 .enum_frame_size
= ov01a1s_enum_frame_size
,
788 static const struct v4l2_subdev_ops ov01a1s_subdev_ops
= {
789 .video
= &ov01a1s_video_ops
,
790 .pad
= &ov01a1s_pad_ops
,
793 static const struct media_entity_operations ov01a1s_subdev_entity_ops
= {
794 .link_validate
= v4l2_subdev_link_validate
,
797 static const struct v4l2_subdev_internal_ops ov01a1s_internal_ops
= {
798 .open
= ov01a1s_open
,
801 static int ov01a1s_identify_module(struct ov01a1s
*ov01a1s
)
803 struct i2c_client
*client
= v4l2_get_subdevdata(&ov01a1s
->sd
);
807 ret
= ov01a1s_read_reg(ov01a1s
, OV01A1S_REG_CHIP_ID
, 3, &val
);
811 if (val
!= OV01A1S_CHIP_ID
) {
812 dev_err(&client
->dev
, "chip id mismatch: %x!=%x",
813 OV01A1S_CHIP_ID
, val
);
820 static int ov01a1s_remove(struct i2c_client
*client
)
822 struct v4l2_subdev
*sd
= i2c_get_clientdata(client
);
823 struct ov01a1s
*ov01a1s
= to_ov01a1s(sd
);
825 v4l2_async_unregister_subdev(sd
);
826 media_entity_cleanup(&sd
->entity
);
827 v4l2_ctrl_handler_free(sd
->ctrl_handler
);
828 pm_runtime_disable(&client
->dev
);
829 mutex_destroy(&ov01a1s
->mutex
);
834 static int ov01a1s_probe(struct i2c_client
*client
)
836 struct ov01a1s
*ov01a1s
;
839 ov01a1s
= devm_kzalloc(&client
->dev
, sizeof(*ov01a1s
), GFP_KERNEL
);
843 v4l2_i2c_subdev_init(&ov01a1s
->sd
, client
, &ov01a1s_subdev_ops
);
844 power_ctrl_logic_set_power(0);
845 power_ctrl_logic_set_power(1);
846 ret
= ov01a1s_identify_module(ov01a1s
);
848 dev_err(&client
->dev
, "failed to find sensor: %d", ret
);
852 mutex_init(&ov01a1s
->mutex
);
853 ov01a1s
->cur_mode
= &supported_modes
[0];
854 ret
= ov01a1s_init_controls(ov01a1s
);
856 dev_err(&client
->dev
, "failed to init controls: %d", ret
);
857 goto probe_error_v4l2_ctrl_handler_free
;
860 ov01a1s
->sd
.internal_ops
= &ov01a1s_internal_ops
;
861 ov01a1s
->sd
.flags
|= V4L2_SUBDEV_FL_HAS_DEVNODE
;
862 ov01a1s
->sd
.entity
.ops
= &ov01a1s_subdev_entity_ops
;
863 ov01a1s
->sd
.entity
.function
= MEDIA_ENT_F_CAM_SENSOR
;
864 ov01a1s
->pad
.flags
= MEDIA_PAD_FL_SOURCE
;
865 ret
= media_entity_pads_init(&ov01a1s
->sd
.entity
, 1, &ov01a1s
->pad
);
867 dev_err(&client
->dev
, "failed to init entity pads: %d", ret
);
868 goto probe_error_v4l2_ctrl_handler_free
;
871 ret
= v4l2_async_register_subdev_sensor_common(&ov01a1s
->sd
);
873 dev_err(&client
->dev
, "failed to register V4L2 subdev: %d",
875 goto probe_error_media_entity_cleanup
;
879 * Device is already turned on by i2c-core with ACPI domain PM.
880 * Enable runtime PM and turn off the device.
882 pm_runtime_set_active(&client
->dev
);
883 pm_runtime_enable(&client
->dev
);
884 pm_runtime_idle(&client
->dev
);
886 power_ctrl_logic_set_power(0);
889 probe_error_media_entity_cleanup
:
890 media_entity_cleanup(&ov01a1s
->sd
.entity
);
892 probe_error_v4l2_ctrl_handler_free
:
893 v4l2_ctrl_handler_free(ov01a1s
->sd
.ctrl_handler
);
894 mutex_destroy(&ov01a1s
->mutex
);
899 static const struct dev_pm_ops ov01a1s_pm_ops
= {
900 SET_SYSTEM_SLEEP_PM_OPS(ov01a1s_suspend
, ov01a1s_resume
)
904 static const struct acpi_device_id ov01a1s_acpi_ids
[] = {
909 MODULE_DEVICE_TABLE(acpi
, ov01a1s_acpi_ids
);
912 static struct i2c_driver ov01a1s_i2c_driver
= {
915 .pm
= &ov01a1s_pm_ops
,
916 .acpi_match_table
= ACPI_PTR(ov01a1s_acpi_ids
),
918 .probe_new
= ov01a1s_probe
,
919 .remove
= ov01a1s_remove
,
922 module_i2c_driver(ov01a1s_i2c_driver
);
924 MODULE_AUTHOR("Xu, Chongyang <chongyang.xu@intel.com>");
925 MODULE_AUTHOR("Lai, Jim <jim.lai@intel.com>");
926 MODULE_AUTHOR("Qiu, Tianshu <tian.shu.qiu@intel.com>");
927 MODULE_AUTHOR("Shawn Tu <shawnx.tu@intel.com>");
928 MODULE_AUTHOR("Bingbu Cao <bingbu.cao@intel.com>");
929 MODULE_DESCRIPTION("OmniVision OV01A1S sensor driver");
930 MODULE_LICENSE("GPL v2");