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 HM11B1_LINK_FREQ_384MHZ 384000000ULL
16 #define HM11B1_SCLK 72000000LL
17 #define HM11B1_MCLK 19200000
18 #define HM11B1_DATA_LANES 1
19 #define HM11B1_RGB_DEPTH 10
21 #define HM11B1_REG_CHIP_ID 0x0000
22 #define HM11B1_CHIP_ID 0x11B1
24 #define HM11B1_REG_MODE_SELECT 0x0100
25 #define HM11B1_MODE_STANDBY 0x00
26 #define HM11B1_MODE_STREAMING 0x01
28 /* vertical-timings from sensor */
29 #define HM11B1_REG_VTS 0x3402
30 #define HM11B1_VTS_DEF 0x037d
31 #define HM11B1_VTS_MIN 0x0346
32 #define HM11B1_VTS_MAX 0xffff
34 /* horizontal-timings from sensor */
35 #define HM11B1_REG_HTS 0x3404
37 /* Exposure controls from sensor */
38 #define HM11B1_REG_EXPOSURE 0x0202
39 #define HM11B1_EXPOSURE_MIN 2
40 #define HM11B1_EXPOSURE_MAX_MARGIN 2
41 #define HM11B1_EXPOSURE_STEP 1
43 /* Analog gain controls from sensor */
44 #define HM11B1_REG_ANALOG_GAIN 0x0205
45 #define HM11B1_REG_ANALOG_GAIN_IR 0x0206
46 #define HM11B1_ANAL_GAIN_MIN 0
47 #define HM11B1_ANAL_GAIN_MAX 0xFF
48 #define HM11B1_ANAL_GAIN_STEP 1
50 /* Digital gain controls from sensor */
51 #define HM11B1_REG_DGTL_GAIN 0x0207
52 #define HM11B1_REG_DGTL_GAIN_IR 0x0209
53 #define HM11B1_DGTL_GAIN_MIN 0x0
54 #define HM11B1_DGTL_GAIN_MAX 0x3FF
55 #define HM11B1_DGTL_GAIN_STEP 1
56 #define HM11B1_DGTL_GAIN_DEFAULT 0x100
57 /* register update control */
58 #define HM11B1_REG_COMMAND_UPDATE 0x104
60 /* Test Pattern Control */
61 #define HM11B1_REG_TEST_PATTERN 0x0601
62 #define HM11B1_TEST_PATTERN_ENABLE 1
63 #define HM11B1_TEST_PATTERN_BAR_SHIFT 1
66 HM11B1_LINK_FREQ_384MHZ_INDEX
,
74 struct hm11b1_reg_list
{
76 const struct hm11b1_reg
*regs
;
79 struct hm11b1_link_freq_config
{
80 const struct hm11b1_reg_list reg_list
;
84 /* Frame width in pixels */
87 /* Frame height in pixels */
90 /* Horizontal timining size */
93 /* Default vertical timining size */
96 /* Min vertical timining size */
99 /* Link frequency needed for this resolution */
102 /* Sensor register settings for this resolution */
103 const struct hm11b1_reg_list reg_list
;
106 static const struct hm11b1_reg mipi_data_rate_384mbps
[] = {
109 //RAW 10bit 1292x800_30fps_MIPI 384Mbps/lane
110 static const struct hm11b1_reg sensor_1292x800_30fps_setting
[] = {
402 static const char * const hm11b1_test_pattern_menu
[] = {
406 "Color Bar Blending",
410 static const s64 link_freq_menu_items
[] = {
411 HM11B1_LINK_FREQ_384MHZ
,
414 static const struct hm11b1_link_freq_config link_freq_configs
[] = {
415 [HM11B1_LINK_FREQ_384MHZ_INDEX
] = {
417 .num_of_regs
= ARRAY_SIZE(mipi_data_rate_384mbps
),
418 .regs
= mipi_data_rate_384mbps
,
423 static const struct hm11b1_mode supported_modes
[] = {
428 .vts_def
= HM11B1_VTS_DEF
,
429 .vts_min
= HM11B1_VTS_MIN
,
432 ARRAY_SIZE(sensor_1292x800_30fps_setting
),
433 .regs
= sensor_1292x800_30fps_setting
,
435 .link_freq_index
= HM11B1_LINK_FREQ_384MHZ_INDEX
,
440 struct v4l2_subdev sd
;
441 struct media_pad pad
;
442 struct v4l2_ctrl_handler ctrl_handler
;
445 struct v4l2_ctrl
*link_freq
;
446 struct v4l2_ctrl
*pixel_rate
;
447 struct v4l2_ctrl
*vblank
;
448 struct v4l2_ctrl
*hblank
;
449 struct v4l2_ctrl
*exposure
;
452 const struct hm11b1_mode
*cur_mode
;
454 /* To serialize asynchronus callbacks */
457 /* Streaming on/off */
461 static inline struct hm11b1
*to_hm11b1(struct v4l2_subdev
*subdev
)
463 return container_of(subdev
, struct hm11b1
, sd
);
466 static u64
to_pixel_rate(u32 f_index
)
468 u64 pixel_rate
= link_freq_menu_items
[f_index
] * 2 * HM11B1_DATA_LANES
;
470 do_div(pixel_rate
, HM11B1_RGB_DEPTH
);
475 static u64
to_pixels_per_line(u32 hts
, u32 f_index
)
477 u64 ppl
= hts
* to_pixel_rate(f_index
);
479 do_div(ppl
, HM11B1_SCLK
);
484 static int hm11b1_read_reg(struct hm11b1
*hm11b1
, u16 reg
, u16 len
, u32
*val
)
486 struct i2c_client
*client
= v4l2_get_subdevdata(&hm11b1
->sd
);
487 struct i2c_msg msgs
[2];
489 u8 data_buf
[4] = {0};
492 if (len
> sizeof(data_buf
))
495 put_unaligned_be16(reg
, addr_buf
);
496 msgs
[0].addr
= client
->addr
;
498 msgs
[0].len
= sizeof(addr_buf
);
499 msgs
[0].buf
= addr_buf
;
500 msgs
[1].addr
= client
->addr
;
501 msgs
[1].flags
= I2C_M_RD
;
503 msgs
[1].buf
= &data_buf
[sizeof(data_buf
) - len
];
505 ret
= i2c_transfer(client
->adapter
, msgs
, ARRAY_SIZE(msgs
));
506 if (ret
!= ARRAY_SIZE(msgs
))
507 return ret
< 0 ? ret
: -EIO
;
509 *val
= get_unaligned_be32(data_buf
);
514 static int hm11b1_write_reg(struct hm11b1
*hm11b1
, u16 reg
, u16 len
, u32 val
)
516 struct i2c_client
*client
= v4l2_get_subdevdata(&hm11b1
->sd
);
523 put_unaligned_be16(reg
, buf
);
524 put_unaligned_be32(val
<< 8 * (4 - len
), buf
+ 2);
526 ret
= i2c_master_send(client
, buf
, len
+ 2);
528 return ret
< 0 ? ret
: -EIO
;
533 static int hm11b1_write_reg_list(struct hm11b1
*hm11b1
,
534 const struct hm11b1_reg_list
*r_list
)
536 struct i2c_client
*client
= v4l2_get_subdevdata(&hm11b1
->sd
);
540 for (i
= 0; i
< r_list
->num_of_regs
; i
++) {
541 ret
= hm11b1_write_reg(hm11b1
, r_list
->regs
[i
].address
, 1,
542 r_list
->regs
[i
].val
);
544 dev_err_ratelimited(&client
->dev
,
545 "write reg 0x%4.4x return err = %d",
546 r_list
->regs
[i
].address
, ret
);
554 static int hm11b1_update_digital_gain(struct hm11b1
*hm11b1
, u32 d_gain
)
556 struct i2c_client
*client
= v4l2_get_subdevdata(&hm11b1
->sd
);
559 ret
= hm11b1_write_reg(hm11b1
, HM11B1_REG_DGTL_GAIN
, 2, d_gain
);
561 dev_err(&client
->dev
, "failed to set HM11B1_REG_DGTL_GAIN");
565 ret
= hm11b1_write_reg(hm11b1
, HM11B1_REG_DGTL_GAIN_IR
, 2, d_gain
);
567 dev_err(&client
->dev
, "failed to set HM11B1_REG_DGTL_GAIN_IR");
574 static int hm11b1_test_pattern(struct hm11b1
*hm11b1
, u32 pattern
)
577 pattern
= pattern
<< HM11B1_TEST_PATTERN_BAR_SHIFT
|
578 HM11B1_TEST_PATTERN_ENABLE
;
580 return hm11b1_write_reg(hm11b1
, HM11B1_REG_TEST_PATTERN
, 1, pattern
);
583 static int hm11b1_set_ctrl(struct v4l2_ctrl
*ctrl
)
585 struct hm11b1
*hm11b1
= container_of(ctrl
->handler
,
586 struct hm11b1
, ctrl_handler
);
587 struct i2c_client
*client
= v4l2_get_subdevdata(&hm11b1
->sd
);
591 /* Propagate change of current control to all related controls */
592 if (ctrl
->id
== V4L2_CID_VBLANK
) {
593 /* Update max exposure while meeting expected vblanking */
594 exposure_max
= hm11b1
->cur_mode
->height
+ ctrl
->val
-
595 HM11B1_EXPOSURE_MAX_MARGIN
;
596 __v4l2_ctrl_modify_range(hm11b1
->exposure
,
597 hm11b1
->exposure
->minimum
,
598 exposure_max
, hm11b1
->exposure
->step
,
602 /* V4L2 controls values will be applied only when power is already up */
603 if (!pm_runtime_get_if_in_use(&client
->dev
))
606 ret
= hm11b1_write_reg(hm11b1
, HM11B1_REG_COMMAND_UPDATE
, 1, 1);
608 dev_err(&client
->dev
, "failed to enable HM11B1_REG_COMMAND_UPDATE");
609 pm_runtime_put(&client
->dev
);
613 case V4L2_CID_ANALOGUE_GAIN
:
614 ret
= hm11b1_write_reg(hm11b1
, HM11B1_REG_ANALOG_GAIN
, 1,
616 ret
|= hm11b1_write_reg(hm11b1
, HM11B1_REG_ANALOG_GAIN_IR
, 1,
620 case V4L2_CID_DIGITAL_GAIN
:
621 ret
= hm11b1_update_digital_gain(hm11b1
, ctrl
->val
);
624 case V4L2_CID_EXPOSURE
:
625 /* 4 least significant bits of expsoure are fractional part */
626 ret
= hm11b1_write_reg(hm11b1
, HM11B1_REG_EXPOSURE
, 2,
630 case V4L2_CID_VBLANK
:
631 ret
= hm11b1_write_reg(hm11b1
, HM11B1_REG_VTS
, 2,
632 hm11b1
->cur_mode
->height
+ ctrl
->val
);
635 case V4L2_CID_TEST_PATTERN
:
636 ret
= hm11b1_test_pattern(hm11b1
, ctrl
->val
);
644 ret
|= hm11b1_write_reg(hm11b1
, HM11B1_REG_COMMAND_UPDATE
, 1, 0);
645 pm_runtime_put(&client
->dev
);
650 static const struct v4l2_ctrl_ops hm11b1_ctrl_ops
= {
651 .s_ctrl
= hm11b1_set_ctrl
,
654 static int hm11b1_init_controls(struct hm11b1
*hm11b1
)
656 struct v4l2_ctrl_handler
*ctrl_hdlr
;
657 const struct hm11b1_mode
*cur_mode
;
658 s64 exposure_max
, h_blank
, pixel_rate
;
659 u32 vblank_min
, vblank_max
, vblank_default
;
663 ctrl_hdlr
= &hm11b1
->ctrl_handler
;
664 ret
= v4l2_ctrl_handler_init(ctrl_hdlr
, 8);
668 ctrl_hdlr
->lock
= &hm11b1
->mutex
;
669 cur_mode
= hm11b1
->cur_mode
;
670 size
= ARRAY_SIZE(link_freq_menu_items
);
672 hm11b1
->link_freq
= v4l2_ctrl_new_int_menu(ctrl_hdlr
, &hm11b1_ctrl_ops
,
675 link_freq_menu_items
);
676 if (hm11b1
->link_freq
)
677 hm11b1
->link_freq
->flags
|= V4L2_CTRL_FLAG_READ_ONLY
;
679 pixel_rate
= to_pixel_rate(HM11B1_LINK_FREQ_384MHZ_INDEX
);
680 hm11b1
->pixel_rate
= v4l2_ctrl_new_std(ctrl_hdlr
, &hm11b1_ctrl_ops
,
681 V4L2_CID_PIXEL_RATE
, 0,
682 pixel_rate
, 1, pixel_rate
);
684 vblank_min
= cur_mode
->vts_min
- cur_mode
->height
;
685 vblank_max
= HM11B1_VTS_MAX
- cur_mode
->height
;
686 vblank_default
= cur_mode
->vts_def
- cur_mode
->height
;
687 hm11b1
->vblank
= v4l2_ctrl_new_std(ctrl_hdlr
, &hm11b1_ctrl_ops
,
688 V4L2_CID_VBLANK
, vblank_min
,
689 vblank_max
, 1, vblank_default
);
691 h_blank
= to_pixels_per_line(cur_mode
->hts
, cur_mode
->link_freq_index
);
692 h_blank
-= cur_mode
->width
;
693 hm11b1
->hblank
= v4l2_ctrl_new_std(ctrl_hdlr
, &hm11b1_ctrl_ops
,
694 V4L2_CID_HBLANK
, h_blank
, h_blank
, 1,
697 hm11b1
->hblank
->flags
|= V4L2_CTRL_FLAG_READ_ONLY
;
699 v4l2_ctrl_new_std(ctrl_hdlr
, &hm11b1_ctrl_ops
, V4L2_CID_ANALOGUE_GAIN
,
700 HM11B1_ANAL_GAIN_MIN
, HM11B1_ANAL_GAIN_MAX
,
701 HM11B1_ANAL_GAIN_STEP
, HM11B1_ANAL_GAIN_MIN
);
702 v4l2_ctrl_new_std(ctrl_hdlr
, &hm11b1_ctrl_ops
, V4L2_CID_DIGITAL_GAIN
,
703 HM11B1_DGTL_GAIN_MIN
, HM11B1_DGTL_GAIN_MAX
,
704 HM11B1_DGTL_GAIN_STEP
, HM11B1_DGTL_GAIN_DEFAULT
);
705 exposure_max
= cur_mode
->vts_def
- HM11B1_EXPOSURE_MAX_MARGIN
;
706 hm11b1
->exposure
= v4l2_ctrl_new_std(ctrl_hdlr
, &hm11b1_ctrl_ops
,
708 HM11B1_EXPOSURE_MIN
, exposure_max
,
709 HM11B1_EXPOSURE_STEP
,
711 v4l2_ctrl_new_std_menu_items(ctrl_hdlr
, &hm11b1_ctrl_ops
,
712 V4L2_CID_TEST_PATTERN
,
713 ARRAY_SIZE(hm11b1_test_pattern_menu
) - 1,
714 0, 0, hm11b1_test_pattern_menu
);
715 if (ctrl_hdlr
->error
)
716 return ctrl_hdlr
->error
;
718 hm11b1
->sd
.ctrl_handler
= ctrl_hdlr
;
723 static void hm11b1_update_pad_format(const struct hm11b1_mode
*mode
,
724 struct v4l2_mbus_framefmt
*fmt
)
726 fmt
->width
= mode
->width
;
727 fmt
->height
= mode
->height
;
728 fmt
->code
= MEDIA_BUS_FMT_SGRBG10_1X10
;
729 fmt
->field
= V4L2_FIELD_NONE
;
732 static int hm11b1_start_streaming(struct hm11b1
*hm11b1
)
734 struct i2c_client
*client
= v4l2_get_subdevdata(&hm11b1
->sd
);
735 const struct hm11b1_reg_list
*reg_list
;
739 power_ctrl_logic_set_power(1);
740 link_freq_index
= hm11b1
->cur_mode
->link_freq_index
;
741 reg_list
= &link_freq_configs
[link_freq_index
].reg_list
;
742 ret
= hm11b1_write_reg_list(hm11b1
, reg_list
);
744 dev_err(&client
->dev
, "failed to set plls");
748 reg_list
= &hm11b1
->cur_mode
->reg_list
;
749 ret
= hm11b1_write_reg_list(hm11b1
, reg_list
);
751 dev_err(&client
->dev
, "failed to set mode");
755 ret
= __v4l2_ctrl_handler_setup(hm11b1
->sd
.ctrl_handler
);
759 ret
= hm11b1_write_reg(hm11b1
, HM11B1_REG_MODE_SELECT
, 1,
760 HM11B1_MODE_STREAMING
);
762 dev_err(&client
->dev
, "failed to start streaming");
767 static void hm11b1_stop_streaming(struct hm11b1
*hm11b1
)
769 struct i2c_client
*client
= v4l2_get_subdevdata(&hm11b1
->sd
);
771 if (hm11b1_write_reg(hm11b1
, HM11B1_REG_MODE_SELECT
, 1,
772 HM11B1_MODE_STANDBY
))
773 dev_err(&client
->dev
, "failed to stop streaming");
774 power_ctrl_logic_set_power(0);
777 static int hm11b1_set_stream(struct v4l2_subdev
*sd
, int enable
)
779 struct hm11b1
*hm11b1
= to_hm11b1(sd
);
780 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
783 if (hm11b1
->streaming
== enable
)
786 mutex_lock(&hm11b1
->mutex
);
788 ret
= pm_runtime_get_sync(&client
->dev
);
790 pm_runtime_put_noidle(&client
->dev
);
791 mutex_unlock(&hm11b1
->mutex
);
795 ret
= hm11b1_start_streaming(hm11b1
);
798 hm11b1_stop_streaming(hm11b1
);
799 pm_runtime_put(&client
->dev
);
802 hm11b1_stop_streaming(hm11b1
);
803 pm_runtime_put(&client
->dev
);
806 hm11b1
->streaming
= enable
;
807 mutex_unlock(&hm11b1
->mutex
);
812 static int __maybe_unused
hm11b1_suspend(struct device
*dev
)
814 struct i2c_client
*client
= to_i2c_client(dev
);
815 struct v4l2_subdev
*sd
= i2c_get_clientdata(client
);
816 struct hm11b1
*hm11b1
= to_hm11b1(sd
);
818 mutex_lock(&hm11b1
->mutex
);
819 if (hm11b1
->streaming
)
820 hm11b1_stop_streaming(hm11b1
);
822 mutex_unlock(&hm11b1
->mutex
);
827 static int __maybe_unused
hm11b1_resume(struct device
*dev
)
829 struct i2c_client
*client
= to_i2c_client(dev
);
830 struct v4l2_subdev
*sd
= i2c_get_clientdata(client
);
831 struct hm11b1
*hm11b1
= to_hm11b1(sd
);
834 mutex_lock(&hm11b1
->mutex
);
835 if (!hm11b1
->streaming
)
838 ret
= hm11b1_start_streaming(hm11b1
);
840 hm11b1
->streaming
= false;
841 hm11b1_stop_streaming(hm11b1
);
845 mutex_unlock(&hm11b1
->mutex
);
849 static int hm11b1_set_format(struct v4l2_subdev
*sd
,
850 struct v4l2_subdev_pad_config
*cfg
,
851 struct v4l2_subdev_format
*fmt
)
853 struct hm11b1
*hm11b1
= to_hm11b1(sd
);
854 const struct hm11b1_mode
*mode
;
855 s32 vblank_def
, h_blank
;
857 mode
= v4l2_find_nearest_size(supported_modes
,
858 ARRAY_SIZE(supported_modes
), width
,
859 height
, fmt
->format
.width
,
862 mutex_lock(&hm11b1
->mutex
);
863 hm11b1_update_pad_format(mode
, &fmt
->format
);
864 if (fmt
->which
== V4L2_SUBDEV_FORMAT_TRY
) {
865 *v4l2_subdev_get_try_format(sd
, cfg
, fmt
->pad
) = fmt
->format
;
867 hm11b1
->cur_mode
= mode
;
868 __v4l2_ctrl_s_ctrl(hm11b1
->link_freq
, mode
->link_freq_index
);
869 __v4l2_ctrl_s_ctrl_int64(hm11b1
->pixel_rate
,
870 to_pixel_rate(mode
->link_freq_index
));
872 /* Update limits and set FPS to default */
873 vblank_def
= mode
->vts_def
- mode
->height
;
874 __v4l2_ctrl_modify_range(hm11b1
->vblank
,
875 mode
->vts_min
- mode
->height
,
876 HM11B1_VTS_MAX
- mode
->height
, 1,
878 __v4l2_ctrl_s_ctrl(hm11b1
->vblank
, vblank_def
);
879 h_blank
= to_pixels_per_line(mode
->hts
, mode
->link_freq_index
) -
881 __v4l2_ctrl_modify_range(hm11b1
->hblank
, h_blank
, h_blank
, 1,
884 mutex_unlock(&hm11b1
->mutex
);
889 static int hm11b1_get_format(struct v4l2_subdev
*sd
,
890 struct v4l2_subdev_pad_config
*cfg
,
891 struct v4l2_subdev_format
*fmt
)
893 struct hm11b1
*hm11b1
= to_hm11b1(sd
);
895 mutex_lock(&hm11b1
->mutex
);
896 if (fmt
->which
== V4L2_SUBDEV_FORMAT_TRY
)
897 fmt
->format
= *v4l2_subdev_get_try_format(&hm11b1
->sd
, cfg
,
900 hm11b1_update_pad_format(hm11b1
->cur_mode
, &fmt
->format
);
902 mutex_unlock(&hm11b1
->mutex
);
907 static int hm11b1_enum_mbus_code(struct v4l2_subdev
*sd
,
908 struct v4l2_subdev_pad_config
*cfg
,
909 struct v4l2_subdev_mbus_code_enum
*code
)
914 code
->code
= MEDIA_BUS_FMT_SGRBG10_1X10
;
919 static int hm11b1_enum_frame_size(struct v4l2_subdev
*sd
,
920 struct v4l2_subdev_pad_config
*cfg
,
921 struct v4l2_subdev_frame_size_enum
*fse
)
923 if (fse
->index
>= ARRAY_SIZE(supported_modes
))
926 if (fse
->code
!= MEDIA_BUS_FMT_SGRBG10_1X10
)
929 fse
->min_width
= supported_modes
[fse
->index
].width
;
930 fse
->max_width
= fse
->min_width
;
931 fse
->min_height
= supported_modes
[fse
->index
].height
;
932 fse
->max_height
= fse
->min_height
;
937 static int hm11b1_open(struct v4l2_subdev
*sd
, struct v4l2_subdev_fh
*fh
)
939 struct hm11b1
*hm11b1
= to_hm11b1(sd
);
941 mutex_lock(&hm11b1
->mutex
);
942 hm11b1_update_pad_format(&supported_modes
[0],
943 v4l2_subdev_get_try_format(sd
, fh
->pad
, 0));
944 mutex_unlock(&hm11b1
->mutex
);
949 static const struct v4l2_subdev_video_ops hm11b1_video_ops
= {
950 .s_stream
= hm11b1_set_stream
,
953 static const struct v4l2_subdev_pad_ops hm11b1_pad_ops
= {
954 .set_fmt
= hm11b1_set_format
,
955 .get_fmt
= hm11b1_get_format
,
956 .enum_mbus_code
= hm11b1_enum_mbus_code
,
957 .enum_frame_size
= hm11b1_enum_frame_size
,
960 static const struct v4l2_subdev_ops hm11b1_subdev_ops
= {
961 .video
= &hm11b1_video_ops
,
962 .pad
= &hm11b1_pad_ops
,
965 static const struct media_entity_operations hm11b1_subdev_entity_ops
= {
966 .link_validate
= v4l2_subdev_link_validate
,
969 static const struct v4l2_subdev_internal_ops hm11b1_internal_ops
= {
973 static int hm11b1_identify_module(struct hm11b1
*hm11b1
)
975 struct i2c_client
*client
= v4l2_get_subdevdata(&hm11b1
->sd
);
979 ret
= hm11b1_read_reg(hm11b1
, HM11B1_REG_CHIP_ID
, 2, &val
);
983 if (val
!= HM11B1_CHIP_ID
) {
984 dev_err(&client
->dev
, "chip id mismatch: %x!=%x",
985 HM11B1_CHIP_ID
, val
);
992 static int hm11b1_remove(struct i2c_client
*client
)
994 struct v4l2_subdev
*sd
= i2c_get_clientdata(client
);
995 struct hm11b1
*hm11b1
= to_hm11b1(sd
);
997 v4l2_async_unregister_subdev(sd
);
998 media_entity_cleanup(&sd
->entity
);
999 v4l2_ctrl_handler_free(sd
->ctrl_handler
);
1000 pm_runtime_disable(&client
->dev
);
1001 mutex_destroy(&hm11b1
->mutex
);
1006 static int hm11b1_probe(struct i2c_client
*client
)
1008 struct hm11b1
*hm11b1
;
1011 hm11b1
= devm_kzalloc(&client
->dev
, sizeof(*hm11b1
), GFP_KERNEL
);
1015 v4l2_i2c_subdev_init(&hm11b1
->sd
, client
, &hm11b1_subdev_ops
);
1016 power_ctrl_logic_set_power(0);
1017 power_ctrl_logic_set_power(1);
1018 ret
= hm11b1_identify_module(hm11b1
);
1020 dev_err(&client
->dev
, "failed to find sensor: %d", ret
);
1024 mutex_init(&hm11b1
->mutex
);
1025 hm11b1
->cur_mode
= &supported_modes
[0];
1026 ret
= hm11b1_init_controls(hm11b1
);
1028 dev_err(&client
->dev
, "failed to init controls: %d", ret
);
1029 goto probe_error_v4l2_ctrl_handler_free
;
1032 hm11b1
->sd
.internal_ops
= &hm11b1_internal_ops
;
1033 hm11b1
->sd
.flags
|= V4L2_SUBDEV_FL_HAS_DEVNODE
;
1034 hm11b1
->sd
.entity
.ops
= &hm11b1_subdev_entity_ops
;
1035 hm11b1
->sd
.entity
.function
= MEDIA_ENT_F_CAM_SENSOR
;
1036 hm11b1
->pad
.flags
= MEDIA_PAD_FL_SOURCE
;
1037 ret
= media_entity_pads_init(&hm11b1
->sd
.entity
, 1, &hm11b1
->pad
);
1039 dev_err(&client
->dev
, "failed to init entity pads: %d", ret
);
1040 goto probe_error_v4l2_ctrl_handler_free
;
1043 ret
= v4l2_async_register_subdev_sensor(&hm11b1
->sd
);
1045 dev_err(&client
->dev
, "failed to register V4L2 subdev: %d",
1047 goto probe_error_media_entity_cleanup
;
1051 * Device is already turned on by i2c-core with ACPI domain PM.
1052 * Enable runtime PM and turn off the device.
1054 pm_runtime_set_active(&client
->dev
);
1055 pm_runtime_enable(&client
->dev
);
1056 pm_runtime_idle(&client
->dev
);
1058 power_ctrl_logic_set_power(0);
1061 probe_error_media_entity_cleanup
:
1062 media_entity_cleanup(&hm11b1
->sd
.entity
);
1064 probe_error_v4l2_ctrl_handler_free
:
1065 v4l2_ctrl_handler_free(hm11b1
->sd
.ctrl_handler
);
1066 mutex_destroy(&hm11b1
->mutex
);
1071 static const struct dev_pm_ops hm11b1_pm_ops
= {
1072 SET_SYSTEM_SLEEP_PM_OPS(hm11b1_suspend
, hm11b1_resume
)
1076 static const struct acpi_device_id hm11b1_acpi_ids
[] = {
1081 MODULE_DEVICE_TABLE(acpi
, hm11b1_acpi_ids
);
1084 static struct i2c_driver hm11b1_i2c_driver
= {
1087 .pm
= &hm11b1_pm_ops
,
1088 .acpi_match_table
= ACPI_PTR(hm11b1_acpi_ids
),
1090 .probe_new
= hm11b1_probe
,
1091 .remove
= hm11b1_remove
,
1094 module_i2c_driver(hm11b1_i2c_driver
);
1096 MODULE_AUTHOR("Qiu, Tianshu <tian.shu.qiu@intel.com>");
1097 MODULE_AUTHOR("Shawn Tu <shawnx.tu@intel.com>");
1098 MODULE_AUTHOR("Bingbu Cao <bingbu.cao@intel.com>");
1099 MODULE_AUTHOR("Lai, Jim <jim.lai@intel.com>");
1100 MODULE_DESCRIPTION("Himax HM11B1 sensor driver");
1101 MODULE_LICENSE("GPL v2");