hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/drivers/media/i2c/fp5510.c
....@@ -15,11 +15,12 @@
1515 #include <media/v4l2-device.h>
1616 #include <linux/rk_vcm_head.h>
1717 #include <linux/gpio/consumer.h>
18
+#include <linux/compat.h>
1819
1920 #define DRIVER_VERSION KERNEL_VERSION(0, 0x01, 0x0)
2021 #define FP5510_NAME "fp5510"
2122
22
-#define FP5510_MAX_CURRENT 100U
23
+#define FP5510_MAX_CURRENT 120U
2324 #define FP5510_MAX_REG 1023U
2425
2526 #define FP5510_DEFAULT_START_CURRENT 0
....@@ -48,8 +49,8 @@
4849 unsigned int t_src;
4950 unsigned int mclk;
5051
51
- struct timeval start_move_tv;
52
- struct timeval end_move_tv;
52
+ struct __kernel_old_timeval start_move_tv;
53
+ struct __kernel_old_timeval end_move_tv;
5354 unsigned long move_ms;
5455
5556 u32 module_index;
....@@ -383,6 +384,8 @@
383384 if (position > FP5510_MAX_REG)
384385 position = FP5510_MAX_REG;
385386
387
+ dev_info(&client->dev, "%s: set dest_pos %d, position %d\n", __func__, dest_pos, position);
388
+
386389 dev_vcm->current_lens_pos = position;
387390 dev_vcm->current_related_pos = dest_pos;
388391 msb = (0x00U | ((dev_vcm->current_lens_pos & 0x3F0U) >> 4U));
....@@ -437,7 +440,7 @@
437440 (uint32_t)move_pos) /
438441 VCMDRV_MAX_LOG);
439442
440
- dev_vcm->start_move_tv = ns_to_timeval(ktime_get_ns());
443
+ dev_vcm->start_move_tv = ns_to_kernel_old_timeval(ktime_get_ns());
441444 mv_us = dev_vcm->start_move_tv.tv_usec +
442445 dev_vcm->move_ms * 1000;
443446 if (mv_us >= 1000000) {
....@@ -503,7 +506,7 @@
503506 VCMDRV_MAX_LOG * dev_vcm->step;
504507 dev_vcm->step_mode = dev_vcm->vcm_cfg.step_mode;
505508
506
- dev_dbg(&client->dev,
509
+ dev_info(&client->dev,
507510 "vcm_cfg: %d, %d, %d, max_ma %d\n",
508511 dev_vcm->vcm_cfg.start_ma,
509512 dev_vcm->vcm_cfg.rated_ma,
....@@ -560,13 +563,15 @@
560563 unsigned int cmd, unsigned long arg)
561564 {
562565 struct i2c_client *client = v4l2_get_subdevdata(sd);
563
- struct rk_cam_compat_vcm_tim __user *p32 = compat_ptr(arg);
566
+ void __user *up = compat_ptr(arg);
564567 struct rk_cam_compat_vcm_tim compat_vcm_tim;
565568 struct rk_cam_vcm_tim vcm_tim;
566569 struct rk_cam_vcm_cfg vcm_cfg;
567570 long ret;
568571
569572 if (cmd == RK_VIDIOC_COMPAT_VCM_TIMEINFO) {
573
+ struct rk_cam_compat_vcm_tim __user *p32 = up;
574
+
570575 ret = fp5510_ioctl(sd, RK_VIDIOC_VCM_TIMEINFO, &vcm_tim);
571576 compat_vcm_tim.vcm_start_t.tv_sec = vcm_tim.vcm_start_t.tv_sec;
572577 compat_vcm_tim.vcm_start_t.tv_usec =
....@@ -584,12 +589,17 @@
584589 &p32->vcm_end_t.tv_usec);
585590 } else if (cmd == RK_VIDIOC_GET_VCM_CFG) {
586591 ret = fp5510_ioctl(sd, RK_VIDIOC_GET_VCM_CFG, &vcm_cfg);
587
- if (!ret)
592
+ if (!ret) {
588593 ret = copy_to_user(up, &vcm_cfg, sizeof(vcm_cfg));
594
+ if (ret)
595
+ ret = -EFAULT;
596
+ }
589597 } else if (cmd == RK_VIDIOC_SET_VCM_CFG) {
590598 ret = copy_from_user(&vcm_cfg, up, sizeof(vcm_cfg));
591599 if (!ret)
592600 ret = fp5510_ioctl(sd, cmd, &vcm_cfg);
601
+ else
602
+ ret = -EFAULT;
593603 } else {
594604 dev_err(&client->dev,
595605 "cmd 0x%x not supported\n", cmd);
....@@ -742,8 +752,8 @@
742752 fp5510_update_vcm_cfg(fp5510_dev);
743753 fp5510_dev->move_ms = 0;
744754 fp5510_dev->current_related_pos = VCMDRV_MAX_LOG;
745
- fp5510_dev->start_move_tv = ns_to_timeval(ktime_get_ns());
746
- fp5510_dev->end_move_tv = ns_to_timeval(ktime_get_ns());
755
+ fp5510_dev->start_move_tv = ns_to_kernel_old_timeval(ktime_get_ns());
756
+ fp5510_dev->end_move_tv = ns_to_kernel_old_timeval(ktime_get_ns());
747757 /*
748758 * Note:
749759 * 1. At ESC mode, ESC code=1 and TSC must be equal 0.
....@@ -808,7 +818,7 @@
808818 return 0;
809819 }
810820
811
-static int fp5510_vcm_resume(struct device *dev)
821
+static int __maybe_unused fp5510_vcm_resume(struct device *dev)
812822 {
813823 struct i2c_client *client = to_i2c_client(dev);
814824 struct v4l2_subdev *sd = i2c_get_clientdata(client);
....@@ -820,7 +830,7 @@
820830 return 0;
821831 }
822832
823
-static int fp5510_vcm_suspend(struct device *dev)
833
+static int __maybe_unused fp5510_vcm_suspend(struct device *dev)
824834 {
825835 struct i2c_client *client = to_i2c_client(dev);
826836 struct v4l2_subdev *sd = i2c_get_clientdata(client);