forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 cde9070d9970eef1f7ec2360586c802a16230ad8
kernel/drivers/media/i2c/ov02b10.c
....@@ -5,6 +5,7 @@
55 * Copyright (C) 2020 Rockchip Electronics Co., Ltd.
66 *
77 * V0.0X01.0X00 first version.
8
+ * V0.0X01.0X01 fix power on & off sequence
89 */
910
1011 #include <linux/clk.h>
....@@ -27,7 +28,7 @@
2728 #include <linux/rk-preisp.h>
2829 #include "../platform/rockchip/isp/rkisp_tb_helper.h"
2930
30
-#define DRIVER_VERSION KERNEL_VERSION(0, 0x01, 0x00)
31
+#define DRIVER_VERSION KERNEL_VERSION(0, 0x01, 0x01)
3132
3233 #ifndef V4L2_CID_DIGITAL_GAIN
3334 #define V4L2_CID_DIGITAL_GAIN V4L2_CID_GAIN
....@@ -91,20 +92,11 @@
9192 #define SENSOR_ID(_msb, _lsb) ((_msb) << 8 | (_lsb))
9293
9394 static const char * const OV02B10_supply_names[] = {
94
- "avdd", /* Analog power */
9595 "dovdd", /* Digital I/O power */
96
- "dvdd", /* Digital core power */
96
+ "avdd", /* Analog power */
9797 };
9898
9999 #define OV02B10_NUM_SUPPLIES ARRAY_SIZE(OV02B10_supply_names)
100
-
101
-enum ov02b10_max_pad {
102
- PAD0,
103
- PAD1,
104
- PAD2,
105
- PAD3,
106
- PAD_MAX,
107
-};
108100
109101 struct regval {
110102 u8 addr;
....@@ -534,14 +526,12 @@
534526 struct ov02b10 *ov02b10 = to_ov02b10(sd);
535527 const struct ov02b10_mode *mode = ov02b10->cur_mode;
536528
537
- mutex_lock(&ov02b10->mutex);
538529 fi->interval = mode->max_fps;
539
- mutex_unlock(&ov02b10->mutex);
540530
541531 return 0;
542532 }
543533
544
-static int ov02b10_g_mbus_config(struct v4l2_subdev *sd,
534
+static int ov02b10_g_mbus_config(struct v4l2_subdev *sd, unsigned int pad_id,
545535 struct v4l2_mbus_config *config)
546536 {
547537 struct ov02b10 *ov02b10 = to_ov02b10(sd);
....@@ -558,7 +548,7 @@
558548 V4L2_MBUS_CSI2_CONTINUOUS_CLOCK |
559549 V4L2_MBUS_CSI2_CHANNEL_1;
560550
561
- config->type = V4L2_MBUS_CSI2;
551
+ config->type = V4L2_MBUS_CSI2_DPHY;
562552 config->flags = val;
563553
564554 return 0;
....@@ -639,8 +629,11 @@
639629 }
640630
641631 ret = ov02b10_ioctl(sd, cmd, inf);
642
- if (!ret)
632
+ if (!ret) {
643633 ret = copy_to_user(up, inf, sizeof(*inf));
634
+ if (ret)
635
+ ret = -EFAULT;
636
+ }
644637 kfree(inf);
645638 break;
646639 case RKMODULE_AWB_CFG:
....@@ -653,6 +646,8 @@
653646 ret = copy_from_user(cfg, up, sizeof(*cfg));
654647 if (!ret)
655648 ret = ov02b10_ioctl(sd, cmd, cfg);
649
+ else
650
+ ret = -EFAULT;
656651 kfree(cfg);
657652 break;
658653 case RKMODULE_GET_HDR_CFG:
....@@ -663,8 +658,11 @@
663658 }
664659
665660 ret = ov02b10_ioctl(sd, cmd, hdr);
666
- if (!ret)
661
+ if (!ret) {
667662 ret = copy_to_user(up, hdr, sizeof(*hdr));
663
+ if (ret)
664
+ ret = -EFAULT;
665
+ }
668666 kfree(hdr);
669667 break;
670668 case RKMODULE_SET_HDR_CFG:
....@@ -677,6 +675,8 @@
677675 ret = copy_from_user(hdr, up, sizeof(*hdr));
678676 if (!ret)
679677 ret = ov02b10_ioctl(sd, cmd, hdr);
678
+ else
679
+ ret = -EFAULT;
680680 kfree(hdr);
681681 break;
682682 case PREISP_CMD_SET_HDRAE_EXP:
....@@ -689,17 +689,23 @@
689689 ret = copy_from_user(hdrae, up, sizeof(*hdrae));
690690 if (!ret)
691691 ret = ov02b10_ioctl(sd, cmd, hdrae);
692
+ else
693
+ ret = -EFAULT;
692694 kfree(hdrae);
693695 break;
694696 case RKMODULE_SET_CONVERSION_GAIN:
695697 ret = copy_from_user(&cg, up, sizeof(cg));
696698 if (!ret)
697699 ret = ov02b10_ioctl(sd, cmd, &cg);
700
+ else
701
+ ret = -EFAULT;
698702 break;
699703 case RKMODULE_SET_QUICK_STREAM:
700704 ret = copy_from_user(&stream, up, sizeof(u32));
701705 if (!ret)
702706 ret = ov02b10_ioctl(sd, cmd, &stream);
707
+ else
708
+ ret = -EFAULT;
703709 break;
704710 default:
705711 ret = -ENOIOCTLCMD;
....@@ -813,6 +819,31 @@
813819 return ret;
814820 }
815821
822
+static int ov02b10_enable_regulators(struct ov02b10 *ov02b10,
823
+ struct regulator_bulk_data *consumers)
824
+{
825
+ int i, j;
826
+ int ret = 0;
827
+ struct device *dev = &ov02b10->client->dev;
828
+ int num_consumers = OV02B10_NUM_SUPPLIES;
829
+
830
+ for (i = 0; i < num_consumers; i++) {
831
+
832
+ ret = regulator_enable(consumers[i].consumer);
833
+ if (ret < 0) {
834
+ dev_err(dev, "Failed to enable regulator: %s\n",
835
+ consumers[i].supply);
836
+ goto err;
837
+ }
838
+ }
839
+ return 0;
840
+err:
841
+ for (j = 0; j < i; j++)
842
+ regulator_disable(consumers[j].consumer);
843
+
844
+ return ret;
845
+}
846
+
816847 static int __ov02b10_power_on(struct ov02b10 *ov02b10)
817848 {
818849 int ret;
....@@ -829,11 +860,6 @@
829860 dev_warn(dev, "Failed to set xvclk rate (24MHz)\n");
830861 if (clk_get_rate(ov02b10->xvclk) != OV02B10_XVCLK_FREQ)
831862 dev_warn(dev, "xvclk mismatched, modes are based on 24MHz\n");
832
- ret = clk_prepare_enable(ov02b10->xvclk);
833
- if (ret < 0) {
834
- dev_err(dev, "Failed to enable xvclk\n");
835
- return ret;
836
- }
837863
838864 if (!IS_ERR(ov02b10->pwdn_gpio))
839865 gpiod_direction_output(ov02b10->pwdn_gpio, 1);
....@@ -841,10 +867,16 @@
841867 if (!IS_ERR(ov02b10->reset_gpio))
842868 gpiod_direction_output(ov02b10->reset_gpio, 1);
843869
844
- ret = regulator_bulk_enable(OV02B10_NUM_SUPPLIES, ov02b10->supplies);
870
+ ret = ov02b10_enable_regulators(ov02b10, ov02b10->supplies);
845871 if (ret < 0) {
846872 dev_err(dev, "Failed to enable regulators\n");
847873 goto disable_clk;
874
+ }
875
+ usleep_range(100, 110);
876
+ ret = clk_prepare_enable(ov02b10->xvclk);
877
+ if (ret < 0) {
878
+ dev_err(dev, "Failed to enable xvclk\n");
879
+ return ret;
848880 }
849881
850882 /* From spec: delay from power stable to pwdn off: 5ms */
....@@ -872,13 +904,14 @@
872904 int ret;
873905 struct device *dev = &ov02b10->client->dev;
874906
875
- if (!IS_ERR(ov02b10->pwdn_gpio))
876
- gpiod_direction_output(ov02b10->pwdn_gpio, 1);
907
+ if (!IS_ERR(ov02b10->reset_gpio))
908
+ gpiod_direction_output(ov02b10->reset_gpio, 1);
877909
878910 clk_disable_unprepare(ov02b10->xvclk);
879911
880
- if (!IS_ERR(ov02b10->reset_gpio))
881
- gpiod_direction_output(ov02b10->reset_gpio, 1);
912
+ if (!IS_ERR(ov02b10->pwdn_gpio))
913
+ gpiod_direction_output(ov02b10->pwdn_gpio, 1);
914
+
882915 if (!IS_ERR_OR_NULL(ov02b10->pins_sleep)) {
883916 ret = pinctrl_select_state(ov02b10->pinctrl,
884917 ov02b10->pins_sleep);
....@@ -888,7 +921,7 @@
888921 regulator_bulk_disable(OV02B10_NUM_SUPPLIES, ov02b10->supplies);
889922 }
890923
891
-static int ov02b10_runtime_resume(struct device *dev)
924
+static int __maybe_unused ov02b10_runtime_resume(struct device *dev)
892925 {
893926 struct i2c_client *client = to_i2c_client(dev);
894927 struct v4l2_subdev *sd = i2c_get_clientdata(client);
....@@ -897,7 +930,7 @@
897930 return __ov02b10_power_on(ov02b10);
898931 }
899932
900
-static int ov02b10_runtime_suspend(struct device *dev)
933
+static int __maybe_unused ov02b10_runtime_suspend(struct device *dev)
901934 {
902935 struct i2c_client *client = to_i2c_client(dev);
903936 struct v4l2_subdev *sd = i2c_get_clientdata(client);
....@@ -969,7 +1002,6 @@
9691002 static const struct v4l2_subdev_video_ops ov02b10_video_ops = {
9701003 .s_stream = ov02b10_s_stream,
9711004 .g_frame_interval = ov02b10_g_frame_interval,
972
- .g_mbus_config = ov02b10_g_mbus_config,
9731005 };
9741006
9751007 static const struct v4l2_subdev_pad_ops ov02b10_pad_ops = {
....@@ -978,6 +1010,7 @@
9781010 .enum_frame_interval = ov02b10_enum_frame_interval,
9791011 .get_fmt = ov02b10_get_fmt,
9801012 .set_fmt = ov02b10_set_fmt,
1013
+ .get_mbus_config = ov02b10_g_mbus_config,
9811014 };
9821015
9831016 static const struct v4l2_subdev_ops ov02b10_subdev_ops = {