From 456e7b1804f762e406297a663e43b2c14e386e75 Mon Sep 17 00:00:00 2001 From: Arnd Bergmann Date: Mon, 27 Nov 2017 10:21:41 -0500 Subject: media: staging: atomisp: convert timestamps to ktime_t timespec overflows in 2038 on 32-bit architectures, and the getnstimeofday() suffers from possible time jumps, so the timestamps here are better done using ktime_get(), which has neither of those problems. In case of ov2680, we don't seem to use the timestamp at all, so I just remove it. Signed-off-by: Arnd Bergmann Reviewed-by: Andy Shevchenko Reviewed-by: Alan Cox Signed-off-by: Sakari Ailus Signed-off-by: Mauro Carvalho Chehab --- .../staging/media/atomisp/i2c/ov5693/atomisp-ov5693.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'drivers/staging/media/atomisp/i2c/ov5693/atomisp-ov5693.c') diff --git a/drivers/staging/media/atomisp/i2c/ov5693/atomisp-ov5693.c b/drivers/staging/media/atomisp/i2c/ov5693/atomisp-ov5693.c index 3e7c3851280f..9fa25bb8f1ee 100644 --- a/drivers/staging/media/atomisp/i2c/ov5693/atomisp-ov5693.c +++ b/drivers/staging/media/atomisp/i2c/ov5693/atomisp-ov5693.c @@ -973,7 +973,7 @@ static int ov5693_t_focus_abs(struct v4l2_subdev *sd, s32 value) if (ret == 0) { dev->number_of_steps = value - dev->focus; dev->focus = value; - getnstimeofday(&(dev->timestamp_t_focus_abs)); + dev->timestamp_t_focus_abs = ktime_get(); } else dev_err(&client->dev, "%s: i2c failed. ret %d\n", __func__, ret); @@ -993,16 +993,13 @@ static int ov5693_q_focus_status(struct v4l2_subdev *sd, s32 *value) { u32 status = 0; struct ov5693_device *dev = to_ov5693_sensor(sd); - struct timespec temptime; - const struct timespec timedelay = { - 0, - min((u32)abs(dev->number_of_steps) * DELAY_PER_STEP_NS, - (u32)DELAY_MAX_PER_STEP_NS), - }; - - getnstimeofday(&temptime); - temptime = timespec_sub(temptime, (dev->timestamp_t_focus_abs)); - if (timespec_compare(&temptime, &timedelay) <= 0) { + ktime_t temptime; + ktime_t timedelay = ns_to_ktime(min_t(u32, + abs(dev->number_of_steps) * DELAY_PER_STEP_NS, + DELAY_MAX_PER_STEP_NS)); + + temptime = ktime_sub(ktime_get(), (dev->timestamp_t_focus_abs)); + if (ktime_compare(temptime, timedelay) <= 0) { status |= ATOMISP_FOCUS_STATUS_MOVING; status |= ATOMISP_FOCUS_HP_IN_PROGRESS; } else { -- cgit From 1e5c49fce62f66c77c8547535ceb4490def5a72c Mon Sep 17 00:00:00 2001 From: Riccardo Schirone Date: Tue, 28 Nov 2017 15:40:01 -0500 Subject: media: staging: add missing blank line after declarations in atomisp-ov5693 Fix "Missing a blank line after declarations" warning reported by checkpatch. Signed-off-by: Riccardo Schirone Signed-off-by: Sakari Ailus Signed-off-by: Mauro Carvalho Chehab --- drivers/staging/media/atomisp/i2c/ov5693/atomisp-ov5693.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'drivers/staging/media/atomisp/i2c/ov5693/atomisp-ov5693.c') diff --git a/drivers/staging/media/atomisp/i2c/ov5693/atomisp-ov5693.c b/drivers/staging/media/atomisp/i2c/ov5693/atomisp-ov5693.c index 9fa25bb8f1ee..d4c4414e186f 100644 --- a/drivers/staging/media/atomisp/i2c/ov5693/atomisp-ov5693.c +++ b/drivers/staging/media/atomisp/i2c/ov5693/atomisp-ov5693.c @@ -82,6 +82,7 @@ static int ad5823_i2c_write(struct i2c_client *client, u8 reg, u8 val) { struct i2c_msg msg; u8 buf[2]; + buf[0] = reg; buf[1] = val; msg.addr = AD5823_VCM_ADDR; @@ -98,6 +99,7 @@ static int ad5823_i2c_read(struct i2c_client *client, u8 reg, u8 *val) { struct i2c_msg msg[2]; u8 buf[2]; + buf[0] = reg; buf[1] = 0; @@ -228,6 +230,7 @@ static int vcm_detect(struct i2c_client *client) int i, ret; struct i2c_msg msg; u16 data0 = 0, data; + for (i = 0; i < 4; i++) { msg.addr = VCM_ADDR; msg.flags = I2C_M_RD; @@ -690,6 +693,7 @@ static long ov5693_s_exposure(struct v4l2_subdev *sd, /* we should not accept the invalid value below */ if (analog_gain == 0) { struct i2c_client *client = v4l2_get_subdevdata(sd); + v4l2_err(client, "%s: invalid value\n", __func__); return -EINVAL; } @@ -722,6 +726,7 @@ static int __ov5693_otp_read(struct v4l2_subdev *sd, u8 *buf) int ret; int i; u8 *b = buf; + dev->otp_size = 0; for (i = 1; i < OV5693_OTP_BANK_MAX; i++) { /*set bank NO and OTP read mode. */ @@ -984,6 +989,7 @@ static int ov5693_t_focus_abs(struct v4l2_subdev *sd, s32 value) static int ov5693_t_focus_rel(struct v4l2_subdev *sd, s32 value) { struct ov5693_device *dev = to_ov5693_sensor(sd); + return ov5693_t_focus_abs(sd, dev->focus + value); } @@ -1030,6 +1036,7 @@ static int ov5693_q_focus_abs(struct v4l2_subdev *sd, s32 *value) static int ov5693_t_vcm_slew(struct v4l2_subdev *sd, s32 value) { struct ov5693_device *dev = to_ov5693_sensor(sd); + dev->number_of_steps = value; dev->vcm_update = true; return 0; @@ -1038,6 +1045,7 @@ static int ov5693_t_vcm_slew(struct v4l2_subdev *sd, s32 value) static int ov5693_t_vcm_timing(struct v4l2_subdev *sd, s32 value) { struct ov5693_device *dev = to_ov5693_sensor(sd); + dev->number_of_steps = value; dev->vcm_update = true; return 0; @@ -1560,6 +1568,7 @@ static int ov5693_set_fmt(struct v4l2_subdev *sd, struct camera_mipi_info *ov5693_info = NULL; int ret = 0; int idx; + if (format->pad) return -EINVAL; if (!fmt) @@ -1596,6 +1605,7 @@ static int ov5693_set_fmt(struct v4l2_subdev *sd, ret = startup(sd); if (ret) { int i = 0; + dev_err(&client->dev, "ov5693 startup err, retry to power up\n"); for (i = 0; i < OV5693_POWER_UP_RETRY_NUM; i++) { dev_err(&client->dev, @@ -1652,6 +1662,7 @@ static int ov5693_get_fmt(struct v4l2_subdev *sd, { struct v4l2_mbus_framefmt *fmt = &format->format; struct ov5693_device *dev = to_ov5693_sensor(sd); + if (format->pad) return -EINVAL; @@ -1815,6 +1826,7 @@ static int ov5693_s_parm(struct v4l2_subdev *sd, struct v4l2_streamparm *param) { struct ov5693_device *dev = to_ov5693_sensor(sd); + dev->run_mode = param->parm.capture.capturemode; mutex_lock(&dev->input_lock); @@ -1904,6 +1916,7 @@ static int ov5693_remove(struct i2c_client *client) { struct v4l2_subdev *sd = i2c_get_clientdata(client); struct ov5693_device *dev = to_ov5693_sensor(sd); + dev_dbg(&client->dev, "ov5693_remove...\n"); dev->platform_data->csi_cfg(sd, 0); -- cgit From 4853dd1ae8f19e50d6d9c905e5bf1cbe5ab8a20a Mon Sep 17 00:00:00 2001 From: Riccardo Schirone Date: Tue, 28 Nov 2017 15:40:02 -0500 Subject: media: staging: improve comments usage in atomisp-ov5693 - Fix "Block comments use a trailing */ on a separate line" checkpatch issue - Fix "Block comments use * on subsequent lines" checkpatch issue Signed-off-by: Riccardo Schirone Signed-off-by: Sakari Ailus Signed-off-by: Mauro Carvalho Chehab --- .../media/atomisp/i2c/ov5693/atomisp-ov5693.c | 38 ++++++++++++++-------- 1 file changed, 25 insertions(+), 13 deletions(-) (limited to 'drivers/staging/media/atomisp/i2c/ov5693/atomisp-ov5693.c') diff --git a/drivers/staging/media/atomisp/i2c/ov5693/atomisp-ov5693.c b/drivers/staging/media/atomisp/i2c/ov5693/atomisp-ov5693.c index d4c4414e186f..b3be89e21666 100644 --- a/drivers/staging/media/atomisp/i2c/ov5693/atomisp-ov5693.c +++ b/drivers/staging/media/atomisp/i2c/ov5693/atomisp-ov5693.c @@ -213,7 +213,8 @@ static int vcm_dw_i2c_write(struct i2c_client *client, u16 data) return ret == num_msg ? 0 : -EIO; } -/* Theory: per datasheet, the two VCMs both allow for a 2-byte read. +/* + * Theory: per datasheet, the two VCMs both allow for a 2-byte read. * The DW9714 doesn't actually specify what this does (it has a * two-byte write-only protocol, but specifies the read sequence as * legal), but it returns the same data (zeroes) always, after an @@ -224,7 +225,8 @@ static int vcm_dw_i2c_write(struct i2c_client *client, u16 data) * these) in AD5823 are not pairwise repetitions of the same 16 bit * word. So all we have to do is sequentially read two bytes at a * time and see if we detect a difference in any of the first four - * pairs. */ + * pairs. + */ static int vcm_detect(struct i2c_client *client) { int i, ret; @@ -238,8 +240,10 @@ static int vcm_detect(struct i2c_client *client) msg.buf = (u8 *)&data; ret = i2c_transfer(client->adapter, &msg, 1); - /* DW9714 always fails the first read and returns - * zeroes for subsequent ones */ + /* + * DW9714 always fails the first read and returns + * zeroes for subsequent ones + */ if (i == 0 && ret == -EREMOTEIO) { data0 = 0; continue; @@ -533,9 +537,11 @@ static long __ov5693_set_exposure(struct v4l2_subdev *sd, int coarse_itg, hts = ov5693_res[dev->fmt_idx].pixels_per_line; vts = ov5693_res[dev->fmt_idx].lines_per_frame; - /*If coarse_itg is larger than 1<<15, can not write to reg directly. - The way is to write coarse_itg/2 to the reg, meanwhile write 2*hts - to the reg. */ + /* + * If coarse_itg is larger than 1<<15, can not write to reg directly. + * The way is to write coarse_itg/2 to the reg, meanwhile write 2*hts + * to the reg. + */ if (coarse_itg > (1 << 15)) { hts = hts * 2; coarse_itg = (int)coarse_itg / 2; @@ -880,8 +886,10 @@ static long ov5693_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg) return 0; } -/* This returns the exposure time being used. This should only be used - for filling in EXIF data, not for actual image processing. */ +/* + * This returns the exposure time being used. This should only be used + * for filling in EXIF data, not for actual image processing. + */ static int ov5693_q_exposure(struct v4l2_subdev *sd, s32 *value) { struct i2c_client *client = v4l2_get_subdevdata(sd); @@ -1298,11 +1306,13 @@ static int power_ctrl(struct v4l2_subdev *sd, bool flag) if (!dev || !dev->platform_data) return -ENODEV; - /* This driver assumes "internal DVDD, PWDNB tied to DOVDD". + /* + * This driver assumes "internal DVDD, PWDNB tied to DOVDD". * In this set up only gpio0 (XSHUTDN) should be available * but in some products (for example ECS) gpio1 (PWDNB) is * also available. If gpio1 is available we emulate it being - * tied to DOVDD here. */ + * tied to DOVDD here. + */ if (flag) { ret = dev->platform_data->v2p8_ctrl(sd, 1); dev->platform_data->gpio1_ctrl(sd, 1); @@ -1941,10 +1951,12 @@ static int ov5693_probe(struct i2c_client *client) struct acpi_device *adev; unsigned int i; - /* Firmware workaround: Some modules use a "secondary default" + /* + * Firmware workaround: Some modules use a "secondary default" * address of 0x10 which doesn't appear on schematics, and * some BIOS versions haven't gotten the memo. Work around - * via config. */ + * via config. + */ i2c = gmin_get_var_int(&client->dev, "I2CAddr", -1); if (i2c != -1) { dev_info(&client->dev, -- cgit From ebcfbf8279f77b453fb4374b96dca7d3739d8252 Mon Sep 17 00:00:00 2001 From: Riccardo Schirone Date: Tue, 28 Nov 2017 15:40:03 -0500 Subject: media: staging: improves comparisons readability in atomisp-ov5693 Fix "Comparisons should place the constant on the right side of the test" checkpatch issue. Signed-off-by: Riccardo Schirone Signed-off-by: Sakari Ailus Signed-off-by: Mauro Carvalho Chehab --- drivers/staging/media/atomisp/i2c/ov5693/atomisp-ov5693.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'drivers/staging/media/atomisp/i2c/ov5693/atomisp-ov5693.c') diff --git a/drivers/staging/media/atomisp/i2c/ov5693/atomisp-ov5693.c b/drivers/staging/media/atomisp/i2c/ov5693/atomisp-ov5693.c index b3be89e21666..5d84cde8af89 100644 --- a/drivers/staging/media/atomisp/i2c/ov5693/atomisp-ov5693.c +++ b/drivers/staging/media/atomisp/i2c/ov5693/atomisp-ov5693.c @@ -764,7 +764,7 @@ static int __ov5693_otp_read(struct v4l2_subdev *sd, u8 *buf) //pr_debug("BANK[%2d] %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", i, *b, *(b+1), *(b+2), *(b+3), *(b+4), *(b+5), *(b+6), *(b+7), *(b+8), *(b+9), *(b+10), *(b+11), *(b+12), *(b+13), *(b+14), *(b+15)); //Intel OTP map, try to read 320byts first. - if (21 == i) { + if (i == 21) { if ((*b) == 0) { dev->otp_size = 320; break; @@ -772,7 +772,7 @@ static int __ov5693_otp_read(struct v4l2_subdev *sd, u8 *buf) b = buf; continue; } - } else if (24 == i) { //if the first 320bytes data doesn't not exist, try to read the next 32bytes data. + } else if (i == 24) { //if the first 320bytes data doesn't not exist, try to read the next 32bytes data. if ((*b) == 0) { dev->otp_size = 32; break; @@ -780,7 +780,7 @@ static int __ov5693_otp_read(struct v4l2_subdev *sd, u8 *buf) b = buf; continue; } - } else if (27 == i) { //if the prvious 32bytes data doesn't exist, try to read the next 32bytes data again. + } else if (i == 27) { //if the prvious 32bytes data doesn't exist, try to read the next 32bytes data again. if ((*b) == 0) { dev->otp_size = 32; break; @@ -1348,7 +1348,7 @@ static int __power_up(struct v4l2_subdev *sd) struct i2c_client *client = v4l2_get_subdevdata(sd); int ret; - if (NULL == dev->platform_data) { + if (!dev->platform_data) { dev_err(&client->dev, "no camera_sensor_platform_data"); return -ENODEV; @@ -1396,7 +1396,7 @@ static int power_down(struct v4l2_subdev *sd) int ret = 0; dev->focus = OV5693_INVALID_CONFIG; - if (NULL == dev->platform_data) { + if (!dev->platform_data) { dev_err(&client->dev, "no camera_sensor_platform_data"); return -ENODEV; -- cgit From c9b56dd21ab60180985b6fc35bd0a55af8029a63 Mon Sep 17 00:00:00 2001 From: Riccardo Schirone Date: Tue, 28 Nov 2017 15:40:04 -0500 Subject: media: staging: fix indentation in atomisp-ov5693 Fix "suspect code indent for conditional statements" checkpatch issue Signed-off-by: Riccardo Schirone Signed-off-by: Sakari Ailus Signed-off-by: Mauro Carvalho Chehab --- drivers/staging/media/atomisp/i2c/ov5693/atomisp-ov5693.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/staging/media/atomisp/i2c/ov5693/atomisp-ov5693.c') diff --git a/drivers/staging/media/atomisp/i2c/ov5693/atomisp-ov5693.c b/drivers/staging/media/atomisp/i2c/ov5693/atomisp-ov5693.c index 5d84cde8af89..d934a086ac46 100644 --- a/drivers/staging/media/atomisp/i2c/ov5693/atomisp-ov5693.c +++ b/drivers/staging/media/atomisp/i2c/ov5693/atomisp-ov5693.c @@ -776,7 +776,7 @@ static int __ov5693_otp_read(struct v4l2_subdev *sd, u8 *buf) if ((*b) == 0) { dev->otp_size = 32; break; - } else { + } else { b = buf; continue; } -- cgit From 9e993ed0536e43ff0031303e8f8d5cb2d1235019 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Tue, 19 Dec 2017 15:59:52 -0500 Subject: media: staging: atomisp: Remove non-ACPI leftovers Since all drivers are solely requiring ACPI enumeration, there is no need to additionally check for legacy platform data or ACPI handle. Remove leftovers from the sensors and platform code. Signed-off-by: Andy Shevchenko Signed-off-by: Sakari Ailus Signed-off-by: Mauro Carvalho Chehab --- drivers/staging/media/atomisp/i2c/ov5693/atomisp-ov5693.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'drivers/staging/media/atomisp/i2c/ov5693/atomisp-ov5693.c') diff --git a/drivers/staging/media/atomisp/i2c/ov5693/atomisp-ov5693.c b/drivers/staging/media/atomisp/i2c/ov5693/atomisp-ov5693.c index d934a086ac46..40d01bf4bf28 100644 --- a/drivers/staging/media/atomisp/i2c/ov5693/atomisp-ov5693.c +++ b/drivers/staging/media/atomisp/i2c/ov5693/atomisp-ov5693.c @@ -1948,7 +1948,6 @@ static int ov5693_probe(struct i2c_client *client) int i2c; int ret = 0; void *pdata = client->dev.platform_data; - struct acpi_device *adev; unsigned int i; /* @@ -1974,14 +1973,9 @@ static int ov5693_probe(struct i2c_client *client) dev->fmt_idx = 0; v4l2_i2c_subdev_init(&(dev->sd), client, &ov5693_ops); - adev = ACPI_COMPANION(&client->dev); - if (adev) { - adev->power.flags.power_resources = 0; - pdata = gmin_camera_platform_data(&dev->sd, - ATOMISP_INPUT_FORMAT_RAW_10, - atomisp_bayer_order_bggr); - } - + pdata = gmin_camera_platform_data(&dev->sd, + ATOMISP_INPUT_FORMAT_RAW_10, + atomisp_bayer_order_bggr); if (!pdata) goto out_free; -- cgit