media: atomisp: Big power-management changes + lots of fixes
Subsystems (4)
Andy Shevchenko
maintainerRe: [PATCH 33/57] media: atomisp: ov2680: Add test pattern control
In reply to Hans de GoedeQuoted 15 lines · Hans de Goede
Quoted 8 lines · Andy Shevchenko
Quoted 2 lines · Hans de Goede
Add a test pattern control. This is a 1:1 copy of the test pattern control in the main
drivers/media/i2c/ov2680.cdriver.Hmm... I'm not sure I understand the trend of the changes. We have two drivers of the same sensor, correct? So, the idea is to move the AtomISP-specific one to be like the generic and then kill it eventually?
The goal is to kill one eventually yes. I'm not sure which one to kill yet though. I have actually found a whole bunch of bugs in the main
drivers/media/i2c/ov2680.ccode and given its buggy-ness I wonder if anyone is actually using it.
Quoted 8 lines
I need to start an email thread about this (and a couple of other open questions which I have), I have a bunch of notes which I need to turn into emails for this.
Quoted 1 line
If so, why do we add something here?
Because I suspect that the atomisp version might eventually be the one we want to keep (and move to
drivers/media/i2c).
Fine, just add a few words into cover letter.
Btw, do you use b4 tool to handle patch(es) series? It has a nice feature to handle a series as a PR. In that case the cover letter becomes a merge-commit message which is cool feature in my opinion.
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 34/57 media: atomisp: ov2680: Fix window settings and enable window for all resolutions
In reply to Hans de GoedeBy default the ov2680 automatically sets the window to match the outputsize and automatically adjusts it to keep the bayer pattern stable when enabling hflip/vflip.
This does not work for the 1616x1216 mode because there is no room to adjust the window there. To make flipping work in the 1616 wide modes the register lists for those modes set bit 0 of 0x5708 (manual_win_en) to 1 and ov2680_set_bayer_order() updates the bayer-order on the pad to match.
But ov2680_set_bayer_order() is always called, so when enabling flipping on modes with a width of less then 1616 now results in the wrong bayer order being reported on the pad since the sensor is auto-adjusting the window in this case.
Specify the correct (== output-size) window-size in all resolutions register-list and always set the manual_win_en bit, so that the bayer order is changed on hflip/vflip enable on all resolutions.
--- drivers/staging/media/atomisp/i2c/ov2680.h | 76 +++++++++++----------- 1 file changed, 38 insertions(+), 38 deletions(-)
drivers/staging/media/atomisp/i2c/ov2680.h +38 -38
@@ -316,11 +316,11 @@ static struct ov2680_reg const ov2680_QCIF_30fps[] = { {0x4008, 0x00}, {0x4009, 0x03}, {0x5081, 0x41}, - {0x5708, 0x00}, //add for full size flip off and mirror off 2014/09/11 - {0x5704, 0x10}, - {0x5705, 0xa0}, - {0x5706, 0x0c}, - {0x5707, 0x78}, + {0x5708, 0x01}, //add for full size flip off and mirror off 2014/09/11 + {0x5704, 0x00}, + {0x5705, 0xc0}, + {0x5706, 0x00}, + {0x5707, 0xa0}, {0x3820, 0xc2}, {0x3821, 0x01}, // {0x5090, 0x0c},
@@ -355,11 +355,11 @@ static struct ov2680_reg const ov2680_CIF_30fps[] = { {0x4008, 0x00}, {0x4009, 0x03}, {0x5081, 0x41}, - {0x5708, 0x00}, //add for full size flip off and mirror off 2014/09/11 - {0x5704, 0x10}, - {0x5705, 0xa0}, - {0x5706, 0x0c}, - {0x5707, 0x78}, + {0x5708, 0x01}, //add for full size flip off and mirror off 2014/09/11 + {0x5704, 0x01}, + {0x5705, 0x70}, + {0x5706, 0x01}, + {0x5707, 0x30}, {0x3820, 0xc2}, {0x3821, 0x01}, // {0x5090, 0x0c},
@@ -394,11 +394,11 @@ static struct ov2680_reg const ov2680_QVGA_30fps[] = { {0x4008, 0x00}, {0x4009, 0x03}, {0x5081, 0x41}, - {0x5708, 0x00}, //add for full size flip off and mirror off 2014/09/11 - {0x5704, 0x10}, - {0x5705, 0xa0}, - {0x5706, 0x0c}, - {0x5707, 0x78}, + {0x5708, 0x01}, //add for full size flip off and mirror off 2014/09/11 + {0x5704, 0x01}, + {0x5705, 0x50}, + {0x5706, 0x01}, + {0x5707, 0x00}, {0x3820, 0xc2}, {0x3821, 0x01}, // {0x5090, 0x0c},
@@ -433,11 +433,11 @@ static struct ov2680_reg const ov2680_656x496_30fps[] = { {0x4008, 0x00}, {0x4009, 0x03}, {0x5081, 0x41}, - {0x5708, 0x00}, //add for full size flip off and mirror off 2014/09/11 - {0x5704, 0x10}, - {0x5705, 0xa0}, - {0x5706, 0x0c}, - {0x5707, 0x78}, + {0x5708, 0x01}, //add for full size flip off and mirror off 2014/09/11 + {0x5704, 0x02}, + {0x5705, 0x90}, + {0x5706, 0x01}, + {0x5707, 0xf0}, {0x3820, 0xc2}, {0x3821, 0x01}, // {0x5090, 0x0c},
@@ -471,7 +471,7 @@ static struct ov2680_reg const ov2680_720x592_30fps[] = { {0x3815, 0x31}, {0x4008, 0x00}, {0x4009, 0x03}, - {0x5708, 0x00}, + {0x5708, 0x01}, {0x5704, 0x02}, {0x5705, 0xd0}, // X_WIN; {0x5706, 0x02},
@@ -510,7 +510,7 @@ static struct ov2680_reg const ov2680_800x600_30fps[] = { {0x3813, 0x00}, {0x3814, 0x31}, {0x3815, 0x31}, - {0x5708, 0x00}, + {0x5708, 0x01}, {0x5704, 0x03}, {0x5705, 0x20}, {0x5706, 0x02},
@@ -552,11 +552,11 @@ static struct ov2680_reg const ov2680_720p_30fps[] = { {0x4008, 0x02}, {0x4009, 0x09}, {0x5081, 0x41}, - {0x5708, 0x00}, //add for full size flip off and mirror off 2014/09/11 - {0x5704, 0x10}, - {0x5705, 0xa0}, - {0x5706, 0x0c}, - {0x5707, 0x78}, + {0x5708, 0x01}, //add for full size flip off and mirror off 2014/09/11 + {0x5704, 0x05}, + {0x5705, 0x10}, + {0x5706, 0x02}, + {0x5707, 0xe0}, {0x3820, 0xc0}, {0x3821, 0x00}, // {0x5090, 0x0c},
@@ -591,11 +591,11 @@ static struct ov2680_reg const ov2680_1296x976_30fps[] = { {0x4008, 0x02}, {0x4009, 0x09}, {0x5081, 0x41}, - {0x5708, 0x00}, //add for full size flip off and mirror off 2014/09/11 - {0x5704, 0x10}, - {0x5705, 0xa0}, - {0x5706, 0x0c}, - {0x5707, 0x78}, + {0x5708, 0x01}, //add for full size flip off and mirror off 2014/09/11 + {0x5704, 0x05}, + {0x5705, 0x10}, + {0x5706, 0x03}, + {0x5707, 0xd0}, {0x3820, 0xc0}, {0x3821, 0x00}, //mirror/flip // {0x5090, 0x0c},
@@ -630,11 +630,11 @@ static struct ov2680_reg const ov2680_1456x1096_30fps[] = { {0x4008, 0x02}, {0x4009, 0x09}, {0x5081, 0x41}, - {0x5708, 0x00}, //add for full size flip off and mirror off 2014/09/11 - {0x5704, 0x10}, - {0x5705, 0xa0}, - {0x5706, 0x0c}, - {0x5707, 0x78}, + {0x5708, 0x01}, //add for full size flip off and mirror off 2014/09/11 + {0x5704, 0x05}, + {0x5705, 0xb0}, + {0x5706, 0x04}, + {0x5707, 0x48}, {0x3820, 0xc0}, {0x3821, 0x00}, // {0x5090, 0x0c},
@@ -752,7 +752,7 @@ static struct ov2680_reg const ov2680_1616x1216_30fps[] = { {0x5704, 0x06}, {0x5705, 0x50}, {0x5706, 0x04}, - {0x5707, 0xcc}, + {0x5707, 0xc0}, {0x3820, 0xc0}, {0x3821, 0x00}, // {0x5090, 0x0C},
Signature · 1 line
2.39.0
Andy Shevchenko
maintainerRe: [PATCH 34/57] media: atomisp: ov2680: Fix window settings and enable window for all resolutions
Quoted 17 lines · Hans de Goede
By default the ov2680 automatically sets the window to match the outputsize and automatically adjusts it to keep the bayer pattern stable when enabling hflip/vflip.
This does not work for the 1616x1216 mode because there is no room to adjust the window there. To make flipping work in the 1616 wide modes the register lists for those modes set bit 0 of
0x5708(manual_win_en) to 1 andov2680_set_bayer_order()updates the bayer-order on the pad to match.But
ov2680_set_bayer_order()is always called, so when enabling flipping on modes with a width of less then 1616 now results in the wrong bayer order being reported on the pad since the sensor is auto-adjusting the window in this case.Specify the correct (== output-size) window-size in all resolutions register-list and always set the
manual_win_enbit, so that the bayer order is changed on hflip/vflip enable on all resolutions.
...
Review
Quoted 1 line
(quoted diff) +1
-0+ {0x5708, 0x01}, //add for full size flip off and mirror off 2014/09/11
While at it, perhaps replace // with proper /* comment */? Same to the rest of the similar cases.
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 35/57 media: atomisp: ov2680: Make setting the modes algorithm based
In reply to Hans de GoedeInstead of using a long fixed register settings list for each resolution, calculate the register settings based on the requested width + height.
This will allow future enhancements like adding hblank and vblank controls and adding selection support.
--- .../media/atomisp/i2c/atomisp-ov2680.c | 137 ++++++++++++++++-- drivers/staging/media/atomisp/i2c/ov2680.h | 41 +++++- 2 files changed, 164 insertions(+), 14 deletions(-)
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +127 -10
@@ -380,6 +380,131 @@ static void ov2680_fill_format(struct ov2680_device *sensor,ov2680_set_bayer_order (sensor, fmt); } +static void ov2680_calc_mode (struct ov2680_device *sensor,int width,int height) +{ +int orig_width = width; +int orig_height = height; + +if (width <= (OV2680_NATIVE_WIDTH /2 ) && + height <= (OV2680_NATIVE_HEIGHT /2 )) { + sensor->mode.binning = true; + width *=2 ; + height *=2 ; + }else { + sensor->mode.binning = false; + } + + sensor->mode.h_start = ((OV2680_NATIVE_WIDTH - width) /2 ) & ~1 ; + sensor->mode.v_start = ((OV2680_NATIVE_HEIGHT - height) /2 ) & ~1 ; + sensor->mode.h_end =min (sensor->mode.h_start + width +OV2680_END_MARGIN -1 , +OV2680_NATIVE_WIDTH -1 ); + sensor->mode.v_end =min (sensor->mode.v_start + height +OV2680_END_MARGIN -1 , +OV2680_NATIVE_HEIGHT -1 ); + sensor->mode.h_output_size = orig_width; + sensor->mode.v_output_size = orig_height; + sensor->mode.hts =OV2680_PIXELS_PER_LINE ; + sensor->mode.vts =OV2680_LINES_PER_FRAME ; +} + +static int ov2680_set_mode (struct ov2680_device *sensor,int width,int height) +{ +struct i2c_client *client = sensor->client; +u8 pll_div, unknown, inc, fmt1, fmt2; +int ret; + +ov2680_calc_mode (sensor, width, height); + +if (sensor->mode.binning) { + pll_div =1 ; + unknown =0x23 ; + inc =0x31 ; + fmt1 =0xc2 ; + fmt2 =0x01 ; + }else { + pll_div =0 ; + unknown =0x21 ; + inc =0x11 ; + fmt1 =0xc0 ; + fmt2 =0x00 ; + } + + ret =ovxxxx_write_reg8 (client,0x3086 , pll_div); +if (ret) +return ret; + + ret =ovxxxx_write_reg8 (client,0x370a , unknown); +if (ret) +return ret; + + ret =ovxxxx_write_reg16 (client,OV2680_HORIZONTAL_START_H , sensor->mode.h_start); +if (ret) +return ret; + + ret =ovxxxx_write_reg16 (client,OV2680_VERTICAL_START_H , sensor->mode.v_start); +if (ret) +return ret; + + ret =ovxxxx_write_reg16 (client,OV2680_HORIZONTAL_END_H , sensor->mode.h_end); +if (ret) +return ret; + + ret =ovxxxx_write_reg16 (client,OV2680_VERTICAL_END_H , sensor->mode.v_end); +if (ret) +return ret; + + ret =ovxxxx_write_reg16 (client,OV2680_HORIZONTAL_OUTPUT_SIZE_H , + sensor->mode.h_output_size); +if (ret) +return ret; + + ret =ovxxxx_write_reg16 (client,OV2680_VERTICAL_OUTPUT_SIZE_H , + sensor->mode.v_output_size); +if (ret) +return ret; + + ret =ovxxxx_write_reg16 (client,OV2680_HTS_H , sensor->mode.hts); +if (ret) +return ret; + + ret =ovxxxx_write_reg16 (client,OV2680_VTS_H , sensor->mode.vts); +if (ret) +return ret; + + ret =ovxxxx_write_reg16 (client,OV2680_ISP_X_WIN_H ,0 ); +if (ret) +return ret; + + ret =ovxxxx_write_reg16 (client,OV2680_ISP_Y_WIN_H ,0 ); +if (ret) +return ret; + + ret =ovxxxx_write_reg8 (client,OV2680_X_INC , inc); +if (ret) +return ret; + + ret =ovxxxx_write_reg8 (client,OV2680_Y_INC , inc); +if (ret) +return ret; + + ret =ovxxxx_write_reg16 (client,OV2680_X_WIN_H , sensor->mode.h_output_size); +if (ret) +return ret; + + ret =ovxxxx_write_reg16 (client,OV2680_Y_WIN_H , sensor->mode.v_output_size); +if (ret) +return ret; + + ret =ovxxxx_write_reg8 (client,OV2680_REG_FORMAT1 , fmt1); +if (ret) +return ret; + + ret =ovxxxx_write_reg8 (client,OV2680_REG_FORMAT2 , fmt2); +if (ret) +return ret; + +return 0 ; +} +static int ov2680_set_fmt (struct v4l2_subdev *sd,struct v4l2_subdev_state *sd_state,struct v4l2_subdev_format *format)
@@ -416,18 +541,10 @@ static int ov2680_set_fmt(struct v4l2_subdev *sd,/* s_power has not been called yet for std v4l2 clients (camorama) */ power_up (sd); - ret =ov2680_write_reg_array (client, dev->res->regs); -if (ret) { -dev_err (&client->dev, -"ov2680 write resolution register err: %d\n" , ret); - goto err; - } - ret =ovxxxx_write_reg16 (client,OV2680_TIMING_VTS_H , dev->res->lines_per_frame); -if (ret) { -dev_err (&client->dev,"ov2680 write vts err: %d\n" , ret); + ret =ov2680_set_mode (dev, fmt->width, fmt->height); +if (ret <0 ) goto err; - }/* Restore value of all ctrls */ ret =__v4l2_ctrl_handler_setup (&dev->ctrls.handler);
drivers/staging/media/atomisp/i2c/ov2680.h +37 -4
77 lines not on this page · raw message
Signature · 1 line
2.39.0
Andy Shevchenko
maintainerRe: [PATCH 35/57] media: atomisp: ov2680: Make setting the modes algorithm based
Quoted 5 lines · Hans de Goede
Instead of using a long fixed register settings list for each resolution, calculate the register settings based on the requested width + height.
This will allow future enhancements like adding hblank and vblank controls and adding selection support.
...
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c static void ov2680_fill_format(struct ov2680_device *sensor, · line 445
Quoted 7 lines
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +7
-0+ ret =ovxxxx_write_reg16 (client,OV2680_HORIZONTAL_START_H , sensor->mode.h_start); +if (ret) +return ret; + + ret =ovxxxx_write_reg16 (client,OV2680_VERTICAL_START_H , sensor->mode.v_start); +if (ret) +return ret;
Wondering if those registers are always being accessed as 16-bit. In such case I would consider to drop _L definitions along with _H suffixes.
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 36/57 media: atomisp: ov2680: Use defines for fps, lines-per-frame and skip-frames
In reply to Hans de GoedeThe fps, lines-per-frame and skip-frames values are the same for all resolutions, use defines for these.
The ov2680_res_preview[] incorrectly sets fps to 60 for some low-res modes, this is incorrect with the current fixed (resolution independent) lines-per-frame value.
Note this not drop the now no longer used fps, lines-per-frame and skip-frames struct ov2680_resolution members. The entire struct is going away in the next patches so that would just cause unnecessary changes.
--- .../staging/media/atomisp/i2c/atomisp-ov2680.c | 16 ++++------------ drivers/staging/media/atomisp/i2c/ov2680.h | 2 ++ 2 files changed, 6 insertions(+), 12 deletions(-)
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +4 -12
@@ -685,11 +685,8 @@ static int ov2680_s_config(struct v4l2_subdev *sd,static int ov2680_g_frame_interval (struct v4l2_subdev *sd,struct v4l2_subdev_frame_interval *interval) { -struct ov2680_device *dev =to_ov2680_sensor (sd); - interval->interval.numerator =1 ; - interval->interval.denominator = dev->res->fps; - + interval->interval.denominator =OV2680_FPS ;return 0 ; }
@@ -733,8 +730,8 @@ static int ov2680_enum_frame_interval(struct v4l2_subdev *sd, fie->which > V4L2_SUBDEV_FORMAT_ACTIVE)return -EINVAL ; - fract.denominator = ov2680_res_preview[fie->index].fps; fract.numerator =1 ; + fract.denominator =OV2680_FPS ; fie->interval = fract;
@@ -743,12 +740,7 @@ static int ov2680_enum_frame_interval(struct v4l2_subdev *sd,static int ov2680_g_skip_frames (struct v4l2_subdev *sd,u32 *frames) { -struct ov2680_device *dev =to_ov2680_sensor (sd); - -mutex_lock (&dev->input_lock); - *frames = dev->res->skip_frames; -mutex_unlock (&dev->input_lock); - + *frames =OV2680_SKIP_FRAMES ;return 0 ; }
@@ -792,7 +784,7 @@ static int ov2680_init_controls(struct ov2680_device *sensor)const struct v4l2_ctrl_ops *ops = &ov2680_ctrl_ops;struct ov2680_ctrls *ctrls = &sensor->ctrls;struct v4l2_ctrl_handler *hdl = &ctrls->handler; -int exp_max = sensor->res->lines_per_frame -OV2680_INTEGRATION_TIME_MARGIN ; +int exp_max =OV2680_LINES_PER_FRAME -OV2680_INTEGRATION_TIME_MARGIN ;v4l2_ctrl_handler_init (hdl,4 );
drivers/staging/media/atomisp/i2c/ov2680.h +2 -0
@@ -38,6 +38,8 @@/* 1704 * 1294 * 30fps = 66MHz pixel clock */ #define OV2680_PIXELS_PER_LINE 1704#define OV2680_LINES_PER_FRAME 1294 +#define OV2680_FPS 30 +#define OV2680_SKIP_FRAMES 3/* If possible send 16 extra rows / lines to the ISP as padding */ #define OV2680_END_MARGIN 16
Signature · 1 line
2.39.0
Re: [PATCH 36/57] media: atomisp: ov2680: Use defines for fps, lines-per-frame and skip-frames
Quoted 10 lines · Hans de Goede
The fps, lines-per-frame and skip-frames values are the same for all resolutions, use defines for these.
The ov2680_res_preview[] incorrectly sets fps to 60 for some low-res modes, this is incorrect with the current fixed (resolution independent) lines-per-frame value.
Note this not drop the now no longer used fps, lines-per-frame and skip-frames struct
ov2680_resolutionmembers. The entire struct is going away in the next patches so that would just cause unnecessary changes.
Quoted 72 lines
Signed-off-by Hans de Goede <[email protected]>--- .../staging/media/atomisp/i2c/atomisp-ov2680.c | 16 ++++------------ drivers/staging/media/atomisp/i2c/ov2680.h | 2 ++ 2 files changed, 6 insertions(+), 12 deletions(-)drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +4
-12@@ -685,11 +685,8 @@ static int ov2680_s_config(struct v4l2_subdev *sd,static int ov2680_g_frame_interval (struct v4l2_subdev *sd,struct v4l2_subdev_frame_interval *interval) { -struct ov2680_device *dev =to_ov2680_sensor (sd); - interval->interval.numerator =1 ; - interval->interval.denominator = dev->res->fps; - + interval->interval.denominator =OV2680_FPS ;return 0 ; }@@ -733,8 +730,8 @@ static int ov2680_enum_frame_interval(struct v4l2_subdev *sd, fie->which > V4L2_SUBDEV_FORMAT_ACTIVE)return -EINVAL ; - fract.denominator = ov2680_res_preview[fie->index].fps; fract.numerator =1 ; + fract.denominator =OV2680_FPS ; fie->interval = fract;@@ -743,12 +740,7 @@ static int ov2680_enum_frame_interval(struct v4l2_subdev *sd,static int ov2680_g_skip_frames (struct v4l2_subdev *sd,u32 *frames) { -struct ov2680_device *dev =to_ov2680_sensor (sd); - -mutex_lock (&dev->input_lock); - *frames = dev->res->skip_frames; -mutex_unlock (&dev->input_lock); - + *frames =OV2680_SKIP_FRAMES ;return 0 ; }@@ -792,7 +784,7 @@ static int ov2680_init_controls(struct ov2680_device *sensor)const struct v4l2_ctrl_ops *ops = &ov2680_ctrl_ops;struct ov2680_ctrls *ctrls = &sensor->ctrls;struct v4l2_ctrl_handler *hdl = &ctrls->handler; -int exp_max = sensor->res->lines_per_frame -OV2680_INTEGRATION_TIME_MARGIN ; +int exp_max =OV2680_LINES_PER_FRAME -OV2680_INTEGRATION_TIME_MARGIN ;v4l2_ctrl_handler_init (hdl,4 );drivers/staging/media/atomisp/i2c/ov2680.h +2
-0@@ -38,6 +38,8 @@/* 1704 * 1294 * 30fps = 66MHz pixel clock */ #define OV2680_PIXELS_PER_LINE 1704#define OV2680_LINES_PER_FRAME 1294 +#define OV2680_FPS 30 +#define OV2680_SKIP_FRAMES 3/* If possible send 16 extra rows / lines to the ISP as padding */ #define OV2680_END_MARGIN 16Signature · 1 line
2.39.0
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 37/57 media: atomisp: ov2680: Drop unused res member from struct ov2680_device
In reply to Hans de GoedeThe res member of struct ov2680_device isn't read anywhere anymore, drop it.
--- drivers/staging/media/atomisp/i2c/atomisp-ov2680.c | 5 ----- drivers/staging/media/atomisp/i2c/ov2680.h | 1 - 2 files changed, 6 deletions(-)
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +0 -5
@@ -548,10 +548,6 @@ static int ov2680_set_fmt(struct v4l2_subdev *sd,/* Restore value of all ctrls */ ret =__v4l2_ctrl_handler_setup (&dev->ctrls.handler); -if (ret <0 ) - goto err; - - dev->res = res; err:mutex_unlock (&dev->input_lock);return ret;
@@ -839,7 +835,6 @@ static int ov2680_probe(struct i2c_client *client)mutex_init (&dev->input_lock); dev->client = client; - dev->res = &ov2680_res_preview[0 ];v4l2_i2c_subdev_init (&dev->sd, client, &ov2680_ops); pdata = gmin_camera_platform_data(&dev->sd,
drivers/staging/media/atomisp/i2c/ov2680.h +0 -1
@@ -180,7 +180,6 @@ struct ov2680_device {struct media_pad pad;struct mutex input_lock;struct i2c_client *client; -struct ov2680_resolution *res;struct camera_sensor_platform_data *platform_data;bool power_on;bool is_streaming;
Signature · 1 line
2.39.0
Re: [PATCH 37/57] media: atomisp: ov2680: Drop unused res member from struct ov2680_device
Quoted 2 lines · Hans de Goede
The res member of struct
ov2680_deviceisn't read anywhere anymore, drop it.
Quoted 44 lines
Signed-off-by Hans de Goede <[email protected]>--- drivers/staging/media/atomisp/i2c/atomisp-ov2680.c | 5 ----- drivers/staging/media/atomisp/i2c/ov2680.h | 1 - 2 files changed, 6 deletions(-)drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +0
-5@@ -548,10 +548,6 @@ static int ov2680_set_fmt(struct v4l2_subdev *sd,/* Restore value of all ctrls */ ret =__v4l2_ctrl_handler_setup (&dev->ctrls.handler); -if (ret <0 ) - goto err; - - dev->res = res; err:mutex_unlock (&dev->input_lock);return ret;@@ -839,7 +835,6 @@ static int ov2680_probe(struct i2c_client *client)mutex_init (&dev->input_lock); dev->client = client; - dev->res = &ov2680_res_preview[0 ];v4l2_i2c_subdev_init (&dev->sd, client, &ov2680_ops); pdata = gmin_camera_platform_data(&dev->sd,drivers/staging/media/atomisp/i2c/ov2680.h +0
-1@@ -180,7 +180,6 @@ struct ov2680_device {struct media_pad pad;struct mutex input_lock;struct i2c_client *client; -struct ov2680_resolution *res;struct camera_sensor_platform_data *platform_data;bool power_on;bool is_streaming;Signature · 1 line
2.39.0
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 38/57 media: atomisp: ov2680: Fix ov2680_enum_frame_interval()
In reply to Hans de GoedeFix and simplify ov2680_enum_frame_interval(), the index is not an index into ov2680_res_preview[], so using N_PREVIEW is wrong.
Instead it is an index indexing the different framerates for the resolution specified in fie->width, fie->height.
Since the ov2680 code only supports a single fixed 30 fps, index must always be 0 and we don't need to check the other fie input values.
--- .../staging/media/atomisp/i2c/atomisp-ov2680.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-)
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +4 -11
@@ -718,19 +718,12 @@ static int ov2680_enum_frame_interval(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_state, struct v4l2_subdev_frame_interval_enum *fie) { - struct v4l2_fract fract; - -if (fie->index >=N_RES_PREVIEW || - fie->width > ov2680_res_preview[0 ].width || - fie->height > ov2680_res_preview[0 ].height || - fie->which >V4L2_SUBDEV_FORMAT_ACTIVE ) +/* Only 1 framerate */ +if (fie->index)return -EINVAL ; - fract.numerator =1 ; - fract.denominator =OV2680_FPS ; - - fie->interval = fract; - + fie->interval.numerator =1 ; + fie->interval.denominator =OV2680_FPS ;return 0 ; }
Signature · 1 line
2.39.0
Re: [PATCH 38/57] media: atomisp: ov2680: Fix ov2680_enum_frame_interval()
Quoted 9 lines · Hans de Goede
Fix and simplify
ov2680_enum_frame_interval(), the index is not an index into ov2680_res_preview[], so usingN_PREVIEWis wrong.Instead it is an index indexing the different framerates for the resolution specified in
fie->width,fie->height.Since the ov2680 code only supports a single fixed 30 fps, index must always be 0 and we don't need to check the other fie input values.
Quoted 36 lines
Signed-off-by Hans de Goede <[email protected]>--- .../staging/media/atomisp/i2c/atomisp-ov2680.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-)drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +4
-11@@ -718,19 +718,12 @@ static int ov2680_enum_frame_interval(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_state, struct v4l2_subdev_frame_interval_enum *fie) { - struct v4l2_fract fract; - -if (fie->index >=N_RES_PREVIEW || - fie->width > ov2680_res_preview[0 ].width || - fie->height > ov2680_res_preview[0 ].height || - fie->which >V4L2_SUBDEV_FORMAT_ACTIVE ) +/* Only 1 framerate */ +if (fie->index)return -EINVAL ; - fract.numerator =1 ; - fract.denominator =OV2680_FPS ; - - fie->interval = fract; - + fie->interval.numerator =1 ; + fie->interval.denominator =OV2680_FPS ;return 0 ; }Signature · 1 line
2.39.0
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 39/57 media: atomisp: ov2680: Drop v4l2_find_nearest_size() call from set_fmt()
In reply to Hans de GoedeSince we now calculate timings baded on the desired width and height, any width and height are valid as long as they don't exceed the sensor's dimensions.
Drop the v4l2_find_nearest_size() call and instead clamp the requested width and height.
--- drivers/staging/media/atomisp/i2c/atomisp-ov2680.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +4 -7
@@ -512,7 +512,7 @@ static int ov2680_set_fmt(struct v4l2_subdev *sd,struct ov2680_device *dev =to_ov2680_sensor (sd);struct i2c_client *client =v4l2_get_subdevdata (sd);struct v4l2_mbus_framefmt *fmt; -struct ov2680_resolution *res; +unsigned int width, height;int ret =0 ; dev_dbg(&client->dev, "%s: %s: pad: %d, fmt: %p\n",
@@ -520,14 +520,11 @@ static int ov2680_set_fmt(struct v4l2_subdev *sd, (format->which ==V4L2_SUBDEV_FORMAT_TRY ) ?"try" :"set" , format->pad, fmt); - res =v4l2_find_nearest_size (ov2680_res_preview,ARRAY_SIZE (ov2680_res_preview), - width, height, - format->format.width, format->format.height); -if (!res) - res = &ov2680_res_preview[N_RES_PREVIEW -1 ]; + width = min_t(unsigned int, ALIGN(format->format.width, 2), OV2680_NATIVE_WIDTH); + height = min_t(unsigned int, ALIGN(format->format.height, 2), OV2680_NATIVE_HEIGHT); fmt =__ov2680_get_pad_format (dev, sd_state, format->pad, format->which); -ov2680_fill_format (dev, fmt, res->width, res->height); +ov2680_fill_format (dev, fmt, width, height); format->format = *fmt;
Signature · 1 line
2.39.0
Re: [PATCH 39/57] media: atomisp: ov2680: Drop v4l2_find_nearest_size() call from set_fmt()
Quoted 6 lines · Hans de Goede
Since we now calculate timings baded on the desired width and height, any width and height are valid as long as they don't exceed the sensor's dimensions.
Drop the
v4l2_find_nearest_size()call and instead clamp the requested width and height.
Quoted 39 lines
Signed-off-by Hans de Goede <[email protected]>--- drivers/staging/media/atomisp/i2c/atomisp-ov2680.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +4
-7@@ -512,7 +512,7 @@ static int ov2680_set_fmt(struct v4l2_subdev *sd,struct ov2680_device *dev =to_ov2680_sensor (sd);struct i2c_client *client =v4l2_get_subdevdata (sd);struct v4l2_mbus_framefmt *fmt; -struct ov2680_resolution *res; +unsigned int width, height;int ret =0 ; dev_dbg(&client->dev, "%s: %s: pad: %d, fmt: %p\n",@@ -520,14 +520,11 @@ static int ov2680_set_fmt(struct v4l2_subdev *sd, (format->which ==V4L2_SUBDEV_FORMAT_TRY ) ?"try" :"set" , format->pad, fmt); - res =v4l2_find_nearest_size (ov2680_res_preview,ARRAY_SIZE (ov2680_res_preview), - width, height, - format->format.width, format->format.height); -if (!res) - res = &ov2680_res_preview[N_RES_PREVIEW -1 ]; + width = min_t(unsigned int, ALIGN(format->format.width, 2), OV2680_NATIVE_WIDTH); + height = min_t(unsigned int, ALIGN(format->format.height, 2), OV2680_NATIVE_HEIGHT); fmt =__ov2680_get_pad_format (dev, sd_state, format->pad, format->which); -ov2680_fill_format (dev, fmt, res->width, res->height); +ov2680_fill_format (dev, fmt, width, height); format->format = *fmt;Signature · 1 line
2.39.0
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 40/57 media: atomisp: ov2680: Drop struct ov2680_resolution / ov2680_res_preview
In reply to Hans de GoedeDrop struct ov2680_resolution and the ov2680_res_preview[] array, this is now only used in ov2680_enum_frame_size() and only the width + height are used there.
Replace this with a new struct v4l2_frmsize_discrete ov2680_frame_sizes[] array.
No functional changes.
--- .../media/atomisp/i2c/atomisp-ov2680.c | 24 +- drivers/staging/media/atomisp/i2c/ov2680.h | 610 ------------------ 2 files changed, 19 insertions(+), 615 deletions(-)
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +19 -5
@@ -698,15 +698,29 @@ static int ov2680_enum_frame_size(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_state, struct v4l2_subdev_frame_size_enum *fse) { +static const struct v4l2_frmsize_discrete ov2680_frame_sizes[] = { + {1616 ,1216 }, + {1616 ,1082 }, + {1616 ,916 }, + {1456 ,1096 }, + {1296 ,976 }, + {1296 ,736 }, + {800 ,600 }, + {720 ,592 }, + {656 ,496 }, + {336 ,256 }, + {352 ,288 }, + {176 ,144 }, + };int index = fse->index; -if (index >=N_RES_PREVIEW ) +if (index >=ARRAY_SIZE (ov2680_frame_sizes))return -EINVAL ; - fse->min_width = ov2680_res_preview[index].width; - fse->min_height = ov2680_res_preview[index].height; - fse->max_width = ov2680_res_preview[index].width; - fse->max_height = ov2680_res_preview[index].height; + fse->min_width = ov2680_frame_sizes[index].width; + fse->min_height = ov2680_frame_sizes[index].height; + fse->max_width = ov2680_frame_sizes[index].width; + fse->max_height = ov2680_frame_sizes[index].height;return 0 ; }
drivers/staging/media/atomisp/i2c/ov2680.h +0 -610
620 lines not on this page · raw message
Signature · 1 line
2.39.0
Re: [PATCH 40/57] media: atomisp: ov2680: Drop struct ov2680_resolution / ov2680_res_preview
Quoted 8 lines · Hans de Goede
Drop struct
ov2680_resolutionand the ov2680_res_preview[] array, this is now only used inov2680_enum_frame_size()and only the width + height are used there.Replace this with a new struct
v4l2_frmsize_discreteov2680_frame_sizes[] array.No functional changes.
Makes sense,
Quoted 674 lines
Signed-off-by Hans de Goede <[email protected]>--- .../media/atomisp/i2c/atomisp-ov2680.c | 24 +- drivers/staging/media/atomisp/i2c/ov2680.h | 610 ------------------ 2 files changed, 19 insertions(+), 615 deletions(-)drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +19
-5@@ -698,15 +698,29 @@ static int ov2680_enum_frame_size(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_state, struct v4l2_subdev_frame_size_enum *fse) { +static const struct v4l2_frmsize_discrete ov2680_frame_sizes[] = { + {1616 ,1216 }, + {1616 ,1082 }, + {1616 ,916 }, + {1456 ,1096 }, + {1296 ,976 }, + {1296 ,736 }, + {800 ,600 }, + {720 ,592 }, + {656 ,496 }, + {336 ,256 }, + {352 ,288 }, + {176 ,144 }, + };int index = fse->index; -if (index >=N_RES_PREVIEW ) +if (index >=ARRAY_SIZE (ov2680_frame_sizes))return -EINVAL ; - fse->min_width = ov2680_res_preview[index].width; - fse->min_height = ov2680_res_preview[index].height; - fse->max_width = ov2680_res_preview[index].width; - fse->max_height = ov2680_res_preview[index].height; + fse->min_width = ov2680_frame_sizes[index].width; + fse->min_height = ov2680_frame_sizes[index].height; + fse->max_width = ov2680_frame_sizes[index].width; + fse->max_height = ov2680_frame_sizes[index].height;return 0 ; }drivers/staging/media/atomisp/i2c/ov2680.h +0
-610@@ -154,18 +154,6 @@ struct regval_list {u8 value; }; -struct ov2680_resolution { -const struct ov2680_reg *regs; -int res; -int width; -int height; -int fps; -int pix_clk_freq; -u32 skip_frames; -u16 pixels_per_line; -u16 lines_per_frame; -}; -struct ov2680_format {u8 *desc;u32 pixelformat;@@ -320,602 +308,4 @@ static struct ov2680_reg const ov2680_global_setting[] = { {} }; -/* -* 176x144 30fps VBlanking 1lane 10Bit (binning) -*/ -static struct ov2680_reg const ov2680_QCIF_30fps[] = { - {0x3086 ,0x01 }, - {0x370a ,0x23 }, - {0x3801 ,0xa0 }, - {0x3802 ,0x00 }, - {0x3803 ,0x78 }, - {0x3804 ,0x05 }, - {0x3805 ,0xaf }, - {0x3806 ,0x04 }, - {0x3807 ,0x47 }, - {0x3808 ,0x00 }, - {0x3809 ,0xC0 }, - {0x380a ,0x00 }, - {0x380b ,0xa0 }, - {0x380c ,0x06 }, - {0x380d ,0xb0 }, - {0x3810 ,0x00 }, - {0x3811 ,0x04 }, - {0x3812 ,0x00 }, - {0x3813 ,0x04 }, - {0x3814 ,0x31 }, - {0x3815 ,0x31 }, - {0x4000 ,0x81 }, - {0x4001 ,0x40 }, - {0x4008 ,0x00 }, - {0x4009 ,0x03 }, - {0x5081 ,0x41 }, - {0x5708 ,0x01 },//add for full size flip off and mirror off 2014/09/11 - {0x5704 ,0x00 }, - {0x5705 ,0xc0 }, - {0x5706 ,0x00 }, - {0x5707 ,0xa0 }, - {0x3820 ,0xc2 }, - {0x3821 ,0x01 }, -// {0x5090, 0x0c}, - {} -}; - -/* -* 352x288 30fps VBlanking 1lane 10Bit (binning) -*/ -static struct ov2680_reg const ov2680_CIF_30fps[] = { - {0x3086 ,0x01 }, - {0x370a ,0x23 }, - {0x3801 ,0xa0 }, - {0x3802 ,0x00 }, - {0x3803 ,0x78 }, - {0x3804 ,0x03 }, - {0x3805 ,0x8f }, - {0x3806 ,0x02 }, - {0x3807 ,0xe7 }, - {0x3808 ,0x01 }, - {0x3809 ,0x70 }, - {0x380a ,0x01 }, - {0x380b ,0x30 }, - {0x380c ,0x06 }, - {0x380d ,0xb0 }, - {0x3810 ,0x00 }, - {0x3811 ,0x04 }, - {0x3812 ,0x00 }, - {0x3813 ,0x04 }, - {0x3814 ,0x31 }, - {0x3815 ,0x31 }, - {0x4008 ,0x00 }, - {0x4009 ,0x03 }, - {0x5081 ,0x41 }, - {0x5708 ,0x01 },//add for full size flip off and mirror off 2014/09/11 - {0x5704 ,0x01 }, - {0x5705 ,0x70 }, - {0x5706 ,0x01 }, - {0x5707 ,0x30 }, - {0x3820 ,0xc2 }, - {0x3821 ,0x01 }, -// {0x5090, 0x0c}, - {} -}; - -/* -* 336x256 30fps VBlanking 1lane 10Bit (binning) -*/ -static struct ov2680_reg const ov2680_QVGA_30fps[] = { - {0x3086 ,0x01 }, - {0x370a ,0x23 }, - {0x3801 ,0xa0 }, - {0x3802 ,0x00 }, - {0x3803 ,0x78 }, - {0x3804 ,0x03 }, - {0x3805 ,0x4f }, - {0x3806 ,0x02 }, - {0x3807 ,0x87 }, - {0x3808 ,0x01 }, - {0x3809 ,0x50 }, - {0x380a ,0x01 }, - {0x380b ,0x00 }, - {0x380c ,0x06 }, - {0x380d ,0xb0 }, - {0x3810 ,0x00 }, - {0x3811 ,0x04 }, - {0x3812 ,0x00 }, - {0x3813 ,0x04 }, - {0x3814 ,0x31 }, - {0x3815 ,0x31 }, - {0x4008 ,0x00 }, - {0x4009 ,0x03 }, - {0x5081 ,0x41 }, - {0x5708 ,0x01 },//add for full size flip off and mirror off 2014/09/11 - {0x5704 ,0x01 }, - {0x5705 ,0x50 }, - {0x5706 ,0x01 }, - {0x5707 ,0x00 }, - {0x3820 ,0xc2 }, - {0x3821 ,0x01 }, -// {0x5090, 0x0c}, - {} -}; - -/* -* 656x496 30fps VBlanking 1lane 10Bit (binning) -*/ -static struct ov2680_reg const ov2680_656x496_30fps[] = { - {0x3086 ,0x01 }, - {0x370a ,0x23 }, - {0x3801 ,0xa0 }, - {0x3802 ,0x00 }, - {0x3803 ,0x78 }, - {0x3804 ,0x05 }, - {0x3805 ,0xcf }, - {0x3806 ,0x04 }, - {0x3807 ,0x67 }, - {0x3808 ,0x02 }, - {0x3809 ,0x90 }, - {0x380a ,0x01 }, - {0x380b ,0xf0 }, - {0x380c ,0x06 }, - {0x380d ,0xb0 }, - {0x3810 ,0x00 }, - {0x3811 ,0x04 }, - {0x3812 ,0x00 }, - {0x3813 ,0x04 }, - {0x3814 ,0x31 }, - {0x3815 ,0x31 }, - {0x4008 ,0x00 }, - {0x4009 ,0x03 }, - {0x5081 ,0x41 }, - {0x5708 ,0x01 },//add for full size flip off and mirror off 2014/09/11 - {0x5704 ,0x02 }, - {0x5705 ,0x90 }, - {0x5706 ,0x01 }, - {0x5707 ,0xf0 }, - {0x3820 ,0xc2 }, - {0x3821 ,0x01 }, -// {0x5090, 0x0c}, - {} -}; - -/* -* 720x592 30fps VBlanking 1lane 10Bit (binning) -*/ -static struct ov2680_reg const ov2680_720x592_30fps[] = { - {0x3086 ,0x01 }, - {0x370a ,0x23 }, - {0x3801 ,0x00 },// X_ADDR_START; - {0x3802 ,0x00 }, - {0x3803 ,0x00 },// Y_ADDR_START; - {0x3804 ,0x05 }, - {0x3805 ,0xaf },// X_ADDR_END; - {0x3806 ,0x04 }, - {0x3807 ,0xaf },// Y_ADDR_END; - {0x3808 ,0x02 }, - {0x3809 ,0xd0 },// X_OUTPUT_SIZE; - {0x380a ,0x02 }, - {0x380b ,0x50 },// Y_OUTPUT_SIZE; - {0x380c ,0x06 }, - {0x380d ,0xac },// HTS; - {0x3810 ,0x00 }, - {0x3811 ,0x00 }, - {0x3812 ,0x00 }, - {0x3813 ,0x00 }, - {0x3814 ,0x31 }, - {0x3815 ,0x31 }, - {0x4008 ,0x00 }, - {0x4009 ,0x03 }, - {0x5708 ,0x01 }, - {0x5704 ,0x02 }, - {0x5705 ,0xd0 },// X_WIN; - {0x5706 ,0x02 }, - {0x5707 ,0x50 },// Y_WIN; - {0x3820 ,0xc2 },// FLIP_FORMAT; - {0x3821 ,0x01 },// MIRROR_FORMAT; - {0x5090 ,0x00 },// PRE ISP CTRL16, default value is 0x0C; -// BIT[3]: Mirror order, BG or GB; -// BIT[2]: Flip order, BR or RB; - {0x5081 ,0x41 }, - {} -}; - -/* -* 800x600 30fps VBlanking 1lane 10Bit (binning) -*/ -static struct ov2680_reg const ov2680_800x600_30fps[] = { - {0x3086 ,0x01 }, - {0x370a ,0x23 }, - {0x3801 ,0x00 },/* hstart 0 */ - {0x3802 ,0x00 }, - {0x3803 ,0x00 },/* vstart 0 */ - {0x3804 ,0x06 }, - {0x3805 ,0x4f },/* hend 1615 */ - {0x3806 ,0x04 }, - {0x3807 ,0xbf },/* vend 1215 */ - {0x3808 ,0x03 }, - {0x3809 ,0x20 },/* hsize 800 */ - {0x380a ,0x02 }, - {0x380b ,0x58 },/* vsize 600 */ - {0x380c ,0x06 }, - {0x380d ,0xac },/* htotal 1708 */ - {0x3810 ,0x00 }, - {0x3811 ,0x00 }, - {0x3812 ,0x00 }, - {0x3813 ,0x00 }, - {0x3814 ,0x31 }, - {0x3815 ,0x31 }, - {0x5708 ,0x01 }, - {0x5704 ,0x03 }, - {0x5705 ,0x20 }, - {0x5706 ,0x02 }, - {0x5707 ,0x58 }, - {0x3820 ,0xc2 }, - {0x3821 ,0x01 }, - {0x5090 ,0x00 }, - {0x4008 ,0x00 }, - {0x4009 ,0x03 }, - {0x5081 ,0x41 }, - {} -}; - -/* -* 720p=1280*720 30fps VBlanking 1lane 10Bit (no-Scaling) -*/ -static struct ov2680_reg const ov2680_720p_30fps[] = { - {0x3086 ,0x00 }, - {0x370a ,0x21 }, - {0x3801 ,0xa0 },/* hstart 160 */ - {0x3802 ,0x00 }, - {0x3803 ,0xf2 },/* vstart 242 */ - {0x3804 ,0x05 }, - {0x3805 ,0xbf },/* hend 1471 */ - {0x3806 ,0x03 }, - {0x3807 ,0xdd },/* vend 989 */ - {0x3808 ,0x05 }, - {0x3809 ,0x10 },/* hsize 1296 */ - {0x380a ,0x02 }, - {0x380b ,0xe0 },/* vsize 736 */ - {0x380c ,0x06 }, - {0x380d ,0xa8 },/* htotal 1704 */ - {0x3810 ,0x00 }, - {0x3811 ,0x08 }, - {0x3812 ,0x00 }, - {0x3813 ,0x06 }, - {0x3814 ,0x11 }, - {0x3815 ,0x11 }, - {0x4008 ,0x02 }, - {0x4009 ,0x09 }, - {0x5081 ,0x41 }, - {0x5708 ,0x01 },//add for full size flip off and mirror off 2014/09/11 - {0x5704 ,0x05 }, - {0x5705 ,0x10 }, - {0x5706 ,0x02 }, - {0x5707 ,0xe0 }, - {0x3820 ,0xc0 }, - {0x3821 ,0x00 }, -// {0x5090, 0x0c}, - {} -}; - -/* -* 1296x976 30fps VBlanking 1lane 10Bit(no-scaling) -*/ -static struct ov2680_reg const ov2680_1296x976_30fps[] = { - {0x3086 ,0x00 }, - {0x370a ,0x21 }, - {0x3801 ,0xa0 },/* hstart 160 */ - {0x3802 ,0x00 }, - {0x3803 ,0x78 },/* vstart 120 */ - {0x3804 ,0x05 }, - {0x3805 ,0xbf },/* hend 1471 */ - {0x3806 ,0x04 }, - {0x3807 ,0x57 },/* vend 1111 */ - {0x3808 ,0x05 }, - {0x3809 ,0x10 },/* hsize 1296 */ - {0x380a ,0x03 }, - {0x380b ,0xd0 },/* vsize 976 */ - {0x380c ,0x06 }, - {0x380d ,0xa8 },/* htotal 1704 */ - {0x3810 ,0x00 }, - {0x3811 ,0x08 }, - {0x3812 ,0x00 }, - {0x3813 ,0x08 }, - {0x3814 ,0x11 }, - {0x3815 ,0x11 }, - {0x4008 ,0x02 }, - {0x4009 ,0x09 }, - {0x5081 ,0x41 }, - {0x5708 ,0x01 },//add for full size flip off and mirror off 2014/09/11 - {0x5704 ,0x05 }, - {0x5705 ,0x10 }, - {0x5706 ,0x03 }, - {0x5707 ,0xd0 }, - {0x3820 ,0xc0 }, - {0x3821 ,0x00 },//mirror/flip -// {0x5090, 0x0c}, - {} -}; - -/* -* 1456*1096 30fps VBlanking 1lane 10bit(no-scaling) -*/ -static struct ov2680_reg const ov2680_1456x1096_30fps[] = { - {0x3086 ,0x00 }, - {0x370a ,0x21 }, - {0x3801 ,0x90 }, - {0x3802 ,0x00 }, - {0x3803 ,0x78 }, - {0x3804 ,0x06 }, - {0x3805 ,0x4f }, - {0x3806 ,0x04 }, - {0x3807 ,0xC0 }, - {0x3808 ,0x05 }, - {0x3809 ,0xb0 }, - {0x380a ,0x04 }, - {0x380b ,0x48 }, - {0x380c ,0x06 }, - {0x380d ,0xa8 }, - {0x3810 ,0x00 }, - {0x3811 ,0x08 }, - {0x3812 ,0x00 }, - {0x3813 ,0x00 }, - {0x3814 ,0x11 }, - {0x3815 ,0x11 }, - {0x4008 ,0x02 }, - {0x4009 ,0x09 }, - {0x5081 ,0x41 }, - {0x5708 ,0x01 },//add for full size flip off and mirror off 2014/09/11 - {0x5704 ,0x05 }, - {0x5705 ,0xb0 }, - {0x5706 ,0x04 }, - {0x5707 ,0x48 }, - {0x3820 ,0xc0 }, - {0x3821 ,0x00 }, -// {0x5090, 0x0c}, - {} -}; - -/* -*1616x916 30fps VBlanking 1lane 10bit -*/ - -static struct ov2680_reg const ov2680_1616x916_30fps[] = { - {0x3086 ,0x00 }, - {0x370a ,0x21 }, - {0x3801 ,0x00 }, - {0x3802 ,0x00 }, - {0x3803 ,0x96 }, - {0x3804 ,0x06 }, - {0x3805 ,0x4f }, - {0x3806 ,0x04 }, - {0x3807 ,0x39 }, - {0x3808 ,0x06 }, - {0x3809 ,0x50 }, - {0x380a ,0x03 }, - {0x380b ,0x94 }, - {0x380c ,0x06 }, - {0x380d ,0xa8 }, - {0x3810 ,0x00 }, - {0x3811 ,0x00 }, - {0x3812 ,0x00 }, - {0x3813 ,0x08 }, - {0x3814 ,0x11 }, - {0x3815 ,0x11 }, - {0x4008 ,0x02 }, - {0x4009 ,0x09 }, - {0x5081 ,0x41 }, - {0x5708 ,0x01 },//add for full size flip off and mirror off 2014/09/11 - {0x5704 ,0x06 }, - {0x5705 ,0x50 }, - {0x5706 ,0x03 }, - {0x5707 ,0x94 }, - {0x3820 ,0xc0 }, - {0x3821 ,0x00 }, -// {0x5090, 0x0C}, - {} -}; - -/* -* 1616x1082 30fps VBlanking 1lane 10Bit -*/ -static struct ov2680_reg const ov2680_1616x1082_30fps[] = { - {0x3086 ,0x00 }, - {0x370a ,0x21 }, - {0x3801 ,0x00 }, - {0x3802 ,0x00 }, - {0x3803 ,0x86 }, - {0x3804 ,0x06 }, - {0x3805 ,0x4f }, - {0x3806 ,0x04 }, - {0x3807 ,0xbf }, - {0x3808 ,0x06 }, - {0x3809 ,0x50 }, - {0x380a ,0x04 }, - {0x380b ,0x3a }, - {0x380c ,0x06 }, - {0x380d ,0xa8 }, - {0x3810 ,0x00 }, - {0x3811 ,0x00 }, - {0x3812 ,0x00 }, - {0x3813 ,0x00 }, - {0x3814 ,0x11 }, - {0x3815 ,0x11 }, - {0x5708 ,0x01 },//add for full size flip off and mirror off 2014/09/11 - {0x5704 ,0x06 }, - {0x5705 ,0x50 }, - {0x5706 ,0x04 }, - {0x5707 ,0x3a }, - {0x3820 ,0xc0 }, - {0x3821 ,0x00 }, -// {0x5090, 0x0C}, - {0x4008 ,0x02 }, - {0x4009 ,0x09 }, - {0x5081 ,0x41 }, - {} -}; - -/* -* 1616x1216 30fps VBlanking 1lane 10Bit -*/ -static struct ov2680_reg const ov2680_1616x1216_30fps[] = { - {0x3086 ,0x00 }, - {0x370a ,0x21 }, - {0x3801 ,0x00 }, - {0x3802 ,0x00 }, - {0x3803 ,0x00 }, - {0x3804 ,0x06 }, - {0x3805 ,0x4f }, - {0x3806 ,0x04 }, - {0x3807 ,0xbf }, - {0x3808 ,0x06 }, - {0x3809 ,0x50 },//50},//4line for mirror and flip - {0x380a ,0x04 }, - {0x380b ,0xc0 },//c0}, - {0x380c ,0x06 }, - {0x380d ,0xa8 }, - {0x3810 ,0x00 }, - {0x3811 ,0x00 }, - {0x3812 ,0x00 }, - {0x3813 ,0x00 }, - {0x3814 ,0x11 }, - {0x3815 ,0x11 }, - {0x4008 ,0x00 }, - {0x4009 ,0x0b }, - {0x5081 ,0x01 }, - {0x5708 ,0x01 },//add for full size flip off and mirror off 2014/09/11 - {0x5704 ,0x06 }, - {0x5705 ,0x50 }, - {0x5706 ,0x04 }, - {0x5707 ,0xc0 }, - {0x3820 ,0xc0 }, - {0x3821 ,0x00 }, -// {0x5090, 0x0C}, - {} -}; - -static struct ov2680_resolution ov2680_res_preview[] = { - { - .width =1616 , - .height =1216 , - .pix_clk_freq =66 , - .fps =30 , - .pixels_per_line =1698 ,//1704, - .lines_per_frame =1294 , - .skip_frames =3 , - .regs = ov2680_1616x1216_30fps, - }, - { - .width =1616 , - .height =1082 , - .pix_clk_freq =66 , - .fps =30 , - .pixels_per_line =1698 ,//1704, - .lines_per_frame =1294 , - .skip_frames =3 , - .regs = ov2680_1616x1082_30fps, - }, - { - .width =1616 , - .height =916 , - .fps =30 , - .pix_clk_freq =66 , - .pixels_per_line =1698 ,//1704, - .lines_per_frame =1294 , - .skip_frames =3 , - .regs = ov2680_1616x916_30fps, - }, - { - .width =1456 , - .height =1096 , - .fps =30 , - .pix_clk_freq =66 , - .pixels_per_line =1698 ,//1704, - .lines_per_frame =1294 , - .skip_frames =3 , - .regs = ov2680_1456x1096_30fps, - }, - { - .width =1296 , - .height =976 , - .fps =30 , - .pix_clk_freq =66 , - .pixels_per_line =1698 ,//1704, - .lines_per_frame =1294 , - .skip_frames =3 , - .regs = ov2680_1296x976_30fps, - }, - { - .width =1296 , - .height =736 , - .fps =60 , - .pix_clk_freq =66 , - .pixels_per_line =1698 ,//1704, - .lines_per_frame =1294 , - .skip_frames =3 , - .regs = ov2680_720p_30fps, - }, - { - .width =800 , - .height =600 , - .fps =60 , - .pix_clk_freq =66 , - .pixels_per_line =1698 ,//1704, - .lines_per_frame =1294 , - .skip_frames =3 , - .regs = ov2680_800x600_30fps, - }, - { - .width =720 , - .height =592 , - .fps =60 , - .pix_clk_freq =66 , - .pixels_per_line =1698 ,//1704, - .lines_per_frame =1294 , - .skip_frames =3 , - .regs = ov2680_720x592_30fps, - }, - { - .width =656 , - .height =496 , - .fps =60 , - .pix_clk_freq =66 , - .pixels_per_line =1698 ,//1704, - .lines_per_frame =1294 , - .skip_frames =3 , - .regs = ov2680_656x496_30fps, - }, - { - .width =336 , - .height =256 , - .fps =60 , - .pix_clk_freq =66 , - .pixels_per_line =1698 ,//1704, - .lines_per_frame =1294 , - .skip_frames =3 , - .regs = ov2680_QVGA_30fps, - }, - { - .width =352 , - .height =288 , - .fps =60 , - .pix_clk_freq =66 , - .pixels_per_line =1698 ,//1704, - .lines_per_frame =1294 , - .skip_frames =3 , - .regs = ov2680_CIF_30fps, - }, - { - .width =176 , - .height =144 , - .fps =60 , - .pix_clk_freq =66 , - .pixels_per_line =1698 ,//1704, - .lines_per_frame =1294 , - .skip_frames =3 , - .regs = ov2680_QCIF_30fps, - }, -}; - -#define N_RES_PREVIEW (ARRAY_SIZE(ov2680_res_preview)) -#endif Signature · 1 line
2.39.0
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 41/57 media: atomisp: ov2680: Fix frame_size list
In reply to Hans de Goede3 fixes for the framesize list:
1. Drop modes < 640x480, these are made by significant cropping, leading to such a small remainig field-of-view that they are not really usable
2. 1616x1082 is presumably intended to be 1600x1080 + 16 pixels padding in both dimensions, but the height is wrong. Change this to 1616x1096.
3. The 800x600 mode is missing the 16 pixels padding and 720x592 is missing 16 pixels padding in its width and the 720x576 base mode is a mode with non square pixels, while the sensor has square pixels.
Replace both with 768x576 + 16 pixels padding -> 784x592
--- drivers/staging/media/atomisp/i2c/atomisp-ov2680.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +2 -6
@@ -700,17 +700,13 @@ static int ov2680_enum_frame_size(struct v4l2_subdev *sd, {static const struct v4l2_frmsize_discrete ov2680_frame_sizes[] = { {1616 ,1216 }, - {1616 ,1082 }, + {1616 ,1096 }, {1616 ,916 }, {1456 ,1096 }, {1296 ,976 }, {1296 ,736 }, - {800 ,600 }, - {720 ,592 }, + {784 ,592 }, {656 ,496 }, - {336 ,256 }, - {352 ,288 }, - {176 ,144 }, };int index = fse->index;
Signature · 1 line
2.39.0
Re: [PATCH 41/57] media: atomisp: ov2680: Fix frame_size list
Quoted 5 lines · Hans de Goede
3 fixes for the framesize list:
1. Drop modes < 640x480, these are made by significant cropping, leading to such a small remainig field-of-view that they are not really usable
Wondering if we have an algo to actually scale instead of crop.
Quoted 9 lines
2. 1616x1082 is presumably intended to be 1600x1080 + 16 pixels padding in both dimensions, but the height is wrong. Change this to 1616x1096.
3. The 800x600 mode is missing the 16 pixels padding and 720x592 is missing 16 pixels padding in its width and the 720x576 base mode is a mode with non square pixels, while the sensor has square pixels.
Replace both with 768x576 + 16 pixels padding -> 784x592
Quoted 32 lines
Signed-off-by Hans de Goede <[email protected]>--- drivers/staging/media/atomisp/i2c/atomisp-ov2680.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +2
-6@@ -700,17 +700,13 @@ static int ov2680_enum_frame_size(struct v4l2_subdev *sd, {static const struct v4l2_frmsize_discrete ov2680_frame_sizes[] = { {1616 ,1216 }, - {1616 ,1082 }, + {1616 ,1096 }, {1616 ,916 }, {1456 ,1096 }, {1296 ,976 }, {1296 ,736 }, - {800 ,600 }, - {720 ,592 }, + {784 ,592 }, {656 ,496 }, - {336 ,256 }, - {352 ,288 }, - {176 ,144 }, };int index = fse->index;Signature · 1 line
2.39.0
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 41/57] media: atomisp: ov2680: Fix frame_size list
Hi,
Quoted 8 lines · Andy Shevchenko
Quoted 5 lines · Hans de Goede
3 fixes for the framesize list:
1. Drop modes < 640x480, these are made by significant cropping, leading to such a small remainig field-of-view that they are not really usable
Wondering if we have an algo to actually scale instead of crop.
The sensor can "bin" the pixels, that is use every other pixel, that already is used. Plain binning gives us 1600x1200 -> 800x600, 640x480 is binning + some cropping.
Regards,
Hans
Quoted 46 lines
Quoted 10 lines
2. 1616x1082 is presumably intended to be 1600x1080 + 16 pixels padding in both dimensions, but the height is wrong. Change this to 1616x1096.
3. The 800x600 mode is missing the 16 pixels padding and 720x592 is missing 16 pixels padding in its width and the 720x576 base mode is a mode with non square pixels, while the sensor has square pixels.
Replace both with 768x576 + 16 pixels padding -> 784x592Reviewed-by Andy Shevchenko <[email protected]>Quoted 32 lines
Signed-off-by Hans de Goede <[email protected]>--- drivers/staging/media/atomisp/i2c/atomisp-ov2680.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +2
-6@@ -700,17 +700,13 @@ static int ov2680_enum_frame_size(struct v4l2_subdev *sd, {static const struct v4l2_frmsize_discrete ov2680_frame_sizes[] = { {1616 ,1216 }, - {1616 ,1082 }, + {1616 ,1096 }, {1616 ,916 }, {1456 ,1096 }, {1296 ,976 }, {1296 ,736 }, - {800 ,600 }, - {720 ,592 }, + {784 ,592 }, {656 ,496 }, - {336 ,256 }, - {352 ,288 }, - {176 ,144 }, };int index = fse->index;Signature · 1 line
2.39.0
PATCH 42/57 media: atomisp: ov2680: Remove unused data-types and defines from ov2680.h
In reply to Hans de GoedeRemove a bunch of unused data-types and defines from ov2680.h.
--- drivers/staging/media/atomisp/i2c/ov2680.h | 60 ---------------------- 1 file changed, 60 deletions(-)
drivers/staging/media/atomisp/i2c/ov2680.h +0 -60
@@ -46,45 +46,11 @@#define OV2680_FOCAL_LENGTH_NUM 334/*3.34mm*/ -#define OV2680_BIN_FACTOR_MAX 4 -#define MAX_FMTS 1 -/* sensor_mode_data read_mode adaptation */ -#define OV2680_READ_MODE_BINNING_ON 0x0400 -#define OV2680_READ_MODE_BINNING_OFF 0x00#define OV2680_INTEGRATION_TIME_MARGIN 8 - -#define OV2680_MAX_EXPOSURE_VALUE 0xFFF1 -#define OV2680_MAX_GAIN_VALUE 0xFF - -/* -* focal length bits definition: -* bits 31-16: numerator, bits 15-0: denominator -*/ -#define OV2680_FOCAL_LENGTH_DEFAULT 0x1B70064 - -/* -* current f-number bits definition: -* bits 31-16: numerator, bits 15-0: denominator -*/ -#define OV2680_F_NUMBER_DEFAULT 0x18000a - -/* -* f-number range bits definition: -* bits 31-24: max f-number numerator -* bits 23-16: max f-number denominator -* bits 15-8: min f-number numerator -* bits 7-0: min f-number denominator -*/ -#define OV2680_F_NUMBER_RANGE 0x180a180a#define OV2680_ID 0x2680 -#define OV2680_FINE_INTG_TIME_MIN 0 -#define OV2680_FINE_INTG_TIME_MAX_MARGIN 0 -#define OV2680_COARSE_INTG_TIME_MIN 1 -#define OV2680_COARSE_INTG_TIME_MAX_MARGIN 6 -/* * OV2680 System control registers */
@@ -147,19 +113,6 @@#define OV2680_START_STREAMING 0x01#define OV2680_STOP_STREAMING 0x00 -#define OV2680_INVALID_CONFIG 0xffffffff - -struct regval_list { -u16 reg_num; -u8 value; -}; - -struct ov2680_format { -u8 *desc; -u32 pixelformat; -struct ov2680_reg *regs; -}; -/* * ov2680 device structure. */
@@ -216,18 +169,6 @@ static inline struct v4l2_subdev *ctrl_to_sd(struct v4l2_ctrl *ctrl) ctrls.handler)->sd; } -#define OV2680_MAX_WRITE_BUF_SIZE 30 - -struct ov2680_write_buffer { -u16 addr; -u8 data[OV2680_MAX_WRITE_BUF_SIZE ]; -}; - -struct ov2680_write_ctrl { -int index; -struct ov2680_write_buffer buffer; -}; -static struct ov2680_reg const ov2680_global_setting[] = { {0x0103 ,0x01 }, {0x3002 ,0x00 },
@@ -304,7 +245,6 @@ static struct ov2680_reg const ov2680_global_setting[] = { {0x5793, 0x00}, {0x5794, 0x03}, //based OV2680_R1A_AM10.ovt,Adjust DPC setting (57xx) on 14/06/13 {0x0100, 0x00}, //stream off - {} };
Signature · 1 line
2.39.0
Re: [PATCH 42/57] media: atomisp: ov2680: Remove unused data-types and defines from ov2680.h
Quoted 1 line · Hans de Goede
Remove a bunch of unused data-types and defines from
ov2680.h.
Good patch!
Quoted 105 lines
Signed-off-by Hans de Goede <[email protected]>--- drivers/staging/media/atomisp/i2c/ov2680.h | 60 ---------------------- 1 file changed, 60 deletions(-)drivers/staging/media/atomisp/i2c/ov2680.h +0
-60@@ -46,45 +46,11 @@#define OV2680_FOCAL_LENGTH_NUM 334/*3.34mm*/ -#define OV2680_BIN_FACTOR_MAX 4 -#define MAX_FMTS 1 -/* sensor_mode_data read_mode adaptation */ -#define OV2680_READ_MODE_BINNING_ON 0x0400 -#define OV2680_READ_MODE_BINNING_OFF 0x00#define OV2680_INTEGRATION_TIME_MARGIN 8 - -#define OV2680_MAX_EXPOSURE_VALUE 0xFFF1 -#define OV2680_MAX_GAIN_VALUE 0xFF - -/* -* focal length bits definition: -* bits 31-16: numerator, bits 15-0: denominator -*/ -#define OV2680_FOCAL_LENGTH_DEFAULT 0x1B70064 - -/* -* current f-number bits definition: -* bits 31-16: numerator, bits 15-0: denominator -*/ -#define OV2680_F_NUMBER_DEFAULT 0x18000a - -/* -* f-number range bits definition: -* bits 31-24: max f-number numerator -* bits 23-16: max f-number denominator -* bits 15-8: min f-number numerator -* bits 7-0: min f-number denominator -*/ -#define OV2680_F_NUMBER_RANGE 0x180a180a#define OV2680_ID 0x2680 -#define OV2680_FINE_INTG_TIME_MIN 0 -#define OV2680_FINE_INTG_TIME_MAX_MARGIN 0 -#define OV2680_COARSE_INTG_TIME_MIN 1 -#define OV2680_COARSE_INTG_TIME_MAX_MARGIN 6 -/* * OV2680 System control registers */ @@ -147,19 +113,6 @@#define OV2680_START_STREAMING 0x01#define OV2680_STOP_STREAMING 0x00 -#define OV2680_INVALID_CONFIG 0xffffffff - -struct regval_list { -u16 reg_num; -u8 value; -}; - -struct ov2680_format { -u8 *desc; -u32 pixelformat; -struct ov2680_reg *regs; -}; -/* * ov2680 device structure. */ @@ -216,18 +169,6 @@ static inline struct v4l2_subdev *ctrl_to_sd(struct v4l2_ctrl *ctrl) ctrls.handler)->sd; } -#define OV2680_MAX_WRITE_BUF_SIZE 30 - -struct ov2680_write_buffer { -u16 addr; -u8 data[OV2680_MAX_WRITE_BUF_SIZE ]; -}; - -struct ov2680_write_ctrl { -int index; -struct ov2680_write_buffer buffer; -}; -static struct ov2680_reg const ov2680_global_setting[] = { {0x0103 ,0x01 }, {0x3002 ,0x00 },@@ -304,7 +245,6 @@ static struct ov2680_reg const ov2680_global_setting[] = { {0x5793, 0x00}, {0x5794, 0x03}, //based OV2680_R1A_AM10.ovt,Adjust DPC setting (57xx) on 14/06/13 {0x0100, 0x00}, //stream off - {} };Signature · 1 line
2.39.0
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 43/57 media: atomisp: ov2680: Drop MAX_FMTS define
In reply to Hans de GoedeThe ov2680 only supports a single format, there is no need to use a define for this.
--- drivers/staging/media/atomisp/i2c/atomisp-ov2680.c | 2 +- drivers/staging/media/atomisp/i2c/ov2680.h | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-)
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +1 -1
@@ -687,7 +687,7 @@ static int ov2680_enum_mbus_code(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_state, struct v4l2_subdev_mbus_code_enum *code) { -if (code->index >=MAX_FMTS ) +if (code->index)return -EINVAL ; code->code =MEDIA_BUS_FMT_SBGGR10_1X10 ;
drivers/staging/media/atomisp/i2c/ov2680.h +0 -2
@@ -46,8 +46,6 @@#define OV2680_FOCAL_LENGTH_NUM 334/*3.34mm*/ -#define MAX_FMTS 1 -#define OV2680_INTEGRATION_TIME_MARGIN 8#define OV2680_ID 0x2680
Signature · 1 line
2.39.0
Re: [PATCH 43/57] media: atomisp: ov2680: Drop MAX_FMTS define
Quoted 2 lines · Hans de Goede
The ov2680 only supports a single format, there is no need to use a define for this.
(One nit-pick below)
Quoted 11 lines
Signed-off-by Hans de Goede <[email protected]>--- drivers/staging/media/atomisp/i2c/atomisp-ov2680.c | 2 +- drivers/staging/media/atomisp/i2c/ov2680.h | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-)drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +0
-0
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c static int ov2680_enum_mbus_code(struct v4l2_subdev *sd, · line 690
Quoted 5 lines
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +1
-1@@ -687,7 +687,7 @@ static int ov2680_enum_mbus_code(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_state, struct v4l2_subdev_mbus_code_enum *code) { -if (code->index >=MAX_FMTS ) +if (code->index)
Perhaps a comment above?
/* We support only a single format */
Quoted 19 lines
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +0
-0return -EINVAL ; code->code =MEDIA_BUS_FMT_SBGGR10_1X10 ;drivers/staging/media/atomisp/i2c/ov2680.h +0
-2@@ -46,8 +46,6 @@#define OV2680_FOCAL_LENGTH_NUM 334/*3.34mm*/ -#define MAX_FMTS 1 -#define OV2680_INTEGRATION_TIME_MARGIN 8#define OV2680_ID 0x2680Signature · 1 line
2.39.0
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 44/57 media: atomisp: ov2680: Consistently indent define values
In reply to Hans de GoedeUse the same indentation level for all #define values.
--- drivers/staging/media/atomisp/i2c/ov2680.h | 36 +++++++++++----------- 1 file changed, 18 insertions(+), 18 deletions(-)
drivers/staging/media/atomisp/i2c/ov2680.h +18 -18
@@ -44,10 +44,10 @@/* If possible send 16 extra rows / lines to the ISP as padding */ #define OV2680_END_MARGIN 16 -#define OV2680_FOCAL_LENGTH_NUM 334/*3.34mm*/ +#define OV2680_FOCAL_LENGTH_NUM 334/*3.34mm*/ -#define OV2680_INTEGRATION_TIME_MARGIN 8 -#define OV2680_ID 0x2680 +#define OV2680_INTEGRATION_TIME_MARGIN 8 +#define OV2680_ID 0x2680/* * OV2680 System control registers
@@ -61,23 +61,23 @@#define OV2680_SC_CMMN_SCCB_ID 0x302B/* 0x300C*/ #define OV2680_SC_CMMN_SUB_ID 0x302A/* process, version*/ -#define OV2680_GROUP_ACCESS 0x3208/*Bit[7:4] Group control, Bit[3:0] Group ID*/ +#define OV2680_GROUP_ACCESS 0x3208/*Bit[7:4] Group control, Bit[3:0] Group ID*/ #define OV2680_REG_EXPOSURE_PK_HIGH 0x3500#define OV2680_REG_GAIN_PK 0x350a -#define OV2680_HORIZONTAL_START_H 0x3800/*Bit[11:8]*/ -#define OV2680_HORIZONTAL_START_L 0x3801/*Bit[7:0]*/ -#define OV2680_VERTICAL_START_H 0x3802/*Bit[11:8]*/ -#define OV2680_VERTICAL_START_L 0x3803/*Bit[7:0]*/ -#define OV2680_HORIZONTAL_END_H 0x3804/*Bit[11:8]*/ -#define OV2680_HORIZONTAL_END_L 0x3805/*Bit[7:0]*/ -#define OV2680_VERTICAL_END_H 0x3806/*Bit[11:8]*/ -#define OV2680_VERTICAL_END_L 0x3807/*Bit[7:0]*/ -#define OV2680_HORIZONTAL_OUTPUT_SIZE_H 0x3808/*Bit[3:0]*/ -#define OV2680_HORIZONTAL_OUTPUT_SIZE_L 0x3809/*Bit[7:0]*/ -#define OV2680_VERTICAL_OUTPUT_SIZE_H 0x380a/*Bit[3:0]*/ -#define OV2680_VERTICAL_OUTPUT_SIZE_L 0x380b/*Bit[7:0]*/ +#define OV2680_HORIZONTAL_START_H 0x3800/*Bit[11:8]*/ +#define OV2680_HORIZONTAL_START_L 0x3801/*Bit[7:0]*/ +#define OV2680_VERTICAL_START_H 0x3802/*Bit[11:8]*/ +#define OV2680_VERTICAL_START_L 0x3803/*Bit[7:0]*/ +#define OV2680_HORIZONTAL_END_H 0x3804/*Bit[11:8]*/ +#define OV2680_HORIZONTAL_END_L 0x3805/*Bit[7:0]*/ +#define OV2680_VERTICAL_END_H 0x3806/*Bit[11:8]*/ +#define OV2680_VERTICAL_END_L 0x3807/*Bit[7:0]*/ +#define OV2680_HORIZONTAL_OUTPUT_SIZE_H 0x3808/*Bit[3:0]*/ +#define OV2680_HORIZONTAL_OUTPUT_SIZE_L 0x3809/*Bit[7:0]*/ +#define OV2680_VERTICAL_OUTPUT_SIZE_H 0x380a/*Bit[3:0]*/ +#define OV2680_VERTICAL_OUTPUT_SIZE_L 0x380b/*Bit[7:0]*/ #define OV2680_HTS_H 0x380c#define OV2680_HTS_L 0x380d#define OV2680_VTS_H 0x380e
@@ -89,7 +89,7 @@#define OV2680_X_INC 0x3814#define OV2680_Y_INC 0x3815 -#define OV2680_FRAME_OFF_NUM 0x4202 +#define OV2680_FRAME_OFF_NUM 0x4202/*Flip/Mirror*/ #define OV2680_REG_FORMAT1 0x3820
@@ -98,7 +98,7 @@#define OV2680_MWB_RED_GAIN_H 0x5004/*0x3400*/ #define OV2680_MWB_GREEN_GAIN_H 0x5006/*0x3402*/ #define OV2680_MWB_BLUE_GAIN_H 0x5008/*0x3404*/ -#define OV2680_MWB_GAIN_MAX 0x0fff +#define OV2680_MWB_GAIN_MAX 0x0fff#define OV2680_REG_ISP_CTRL00 0x5080
Signature · 1 line
2.39.0
Re: [PATCH 44/57] media: atomisp: ov2680: Consistently indent define values
Quoted 1 line · Hans de Goede
Use the same indentation level for all #define values.
Can we at the same time add spaces surround the text? With that,
Quoted 81 lines
Signed-off-by Hans de Goede <[email protected]>--- drivers/staging/media/atomisp/i2c/ov2680.h | 36 +++++++++++----------- 1 file changed, 18 insertions(+), 18 deletions(-)drivers/staging/media/atomisp/i2c/ov2680.h +18
-18@@ -44,10 +44,10 @@/* If possible send 16 extra rows / lines to the ISP as padding */ #define OV2680_END_MARGIN 16 -#define OV2680_FOCAL_LENGTH_NUM 334/*3.34mm*/ +#define OV2680_FOCAL_LENGTH_NUM 334/*3.34mm*/ -#define OV2680_INTEGRATION_TIME_MARGIN 8 -#define OV2680_ID 0x2680 +#define OV2680_INTEGRATION_TIME_MARGIN 8 +#define OV2680_ID 0x2680/* * OV2680 System control registers @@ -61,23 +61,23 @@#define OV2680_SC_CMMN_SCCB_ID 0x302B/* 0x300C*/ #define OV2680_SC_CMMN_SUB_ID 0x302A/* process, version*/ -#define OV2680_GROUP_ACCESS 0x3208/*Bit[7:4] Group control, Bit[3:0] Group ID*/ +#define OV2680_GROUP_ACCESS 0x3208/*Bit[7:4] Group control, Bit[3:0] Group ID*/ #define OV2680_REG_EXPOSURE_PK_HIGH 0x3500#define OV2680_REG_GAIN_PK 0x350a -#define OV2680_HORIZONTAL_START_H 0x3800/*Bit[11:8]*/ -#define OV2680_HORIZONTAL_START_L 0x3801/*Bit[7:0]*/ -#define OV2680_VERTICAL_START_H 0x3802/*Bit[11:8]*/ -#define OV2680_VERTICAL_START_L 0x3803/*Bit[7:0]*/ -#define OV2680_HORIZONTAL_END_H 0x3804/*Bit[11:8]*/ -#define OV2680_HORIZONTAL_END_L 0x3805/*Bit[7:0]*/ -#define OV2680_VERTICAL_END_H 0x3806/*Bit[11:8]*/ -#define OV2680_VERTICAL_END_L 0x3807/*Bit[7:0]*/ -#define OV2680_HORIZONTAL_OUTPUT_SIZE_H 0x3808/*Bit[3:0]*/ -#define OV2680_HORIZONTAL_OUTPUT_SIZE_L 0x3809/*Bit[7:0]*/ -#define OV2680_VERTICAL_OUTPUT_SIZE_H 0x380a/*Bit[3:0]*/ -#define OV2680_VERTICAL_OUTPUT_SIZE_L 0x380b/*Bit[7:0]*/ +#define OV2680_HORIZONTAL_START_H 0x3800/*Bit[11:8]*/ +#define OV2680_HORIZONTAL_START_L 0x3801/*Bit[7:0]*/ +#define OV2680_VERTICAL_START_H 0x3802/*Bit[11:8]*/ +#define OV2680_VERTICAL_START_L 0x3803/*Bit[7:0]*/ +#define OV2680_HORIZONTAL_END_H 0x3804/*Bit[11:8]*/ +#define OV2680_HORIZONTAL_END_L 0x3805/*Bit[7:0]*/ +#define OV2680_VERTICAL_END_H 0x3806/*Bit[11:8]*/ +#define OV2680_VERTICAL_END_L 0x3807/*Bit[7:0]*/ +#define OV2680_HORIZONTAL_OUTPUT_SIZE_H 0x3808/*Bit[3:0]*/ +#define OV2680_HORIZONTAL_OUTPUT_SIZE_L 0x3809/*Bit[7:0]*/ +#define OV2680_VERTICAL_OUTPUT_SIZE_H 0x380a/*Bit[3:0]*/ +#define OV2680_VERTICAL_OUTPUT_SIZE_L 0x380b/*Bit[7:0]*/ #define OV2680_HTS_H 0x380c#define OV2680_HTS_L 0x380d#define OV2680_VTS_H 0x380e@@ -89,7 +89,7 @@#define OV2680_X_INC 0x3814#define OV2680_Y_INC 0x3815 -#define OV2680_FRAME_OFF_NUM 0x4202 +#define OV2680_FRAME_OFF_NUM 0x4202/*Flip/Mirror*/ #define OV2680_REG_FORMAT1 0x3820@@ -98,7 +98,7 @@#define OV2680_MWB_RED_GAIN_H 0x5004/*0x3400*/ #define OV2680_MWB_GREEN_GAIN_H 0x5006/*0x3402*/ #define OV2680_MWB_BLUE_GAIN_H 0x5008/*0x3404*/ -#define OV2680_MWB_GAIN_MAX 0x0fff +#define OV2680_MWB_GAIN_MAX 0x0fff#define OV2680_REG_ISP_CTRL00 0x5080Signature · 1 line
2.39.0
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 45/57 media: atomisp: ov2680: Cleanup includes
In reply to Hans de GoedeRemove unused includes and sort the remaining ones alphabetically.
--- .../media/atomisp/i2c/atomisp-ov2680.c | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-)
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +3 -16
@@ -15,27 +15,14 @@* */ -#include <asm/unaligned.h> - -#include <linux/module.h> -#include <linux/types.h> -#include <linux/kernel.h> -#include <linux/mm.h> -#include <linux/string.h> -#include <linux/errno.h> -#include <linux/init.h> -#include <linux/kmod.h> +#include <linux/acpi.h> #include <linux/device.h> -#include <linux/delay.h> -#include <linux/slab.h> #include <linux/i2c.h> -#include <linux/moduleparam.h> +#include <linux/module.h> +#include <linux/types.h> #include <media/ovxxxx_16bit_addr_reg_helpers.h> #include <media/v4l2-device.h> -#include <linux/io.h> -#include <linux/acpi.h> #include "../include/linux/atomisp_gmin_platform.h" -#include "ov2680.h" static enum atomisp_bayer_order ov2680_bayer_order_mapping[] = {
Signature · 1 line
2.39.0
Re: [PATCH 45/57] media: atomisp: ov2680: Cleanup includes
Quoted 1 line · Hans de Goede
Remove unused includes and sort the remaining ones alphabetically.
See below.
Quoted 21 lines
Signed-off-by Hans de Goede <[email protected]>--- .../media/atomisp/i2c/atomisp-ov2680.c | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-)drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +0
-8@@ -15,27 +15,14 @@* */ -#include <asm/unaligned.h> - -#include <linux/module.h> -#include <linux/types.h> -#include <linux/kernel.h> -#include <linux/mm.h> -#include <linux/string.h> -#include <linux/errno.h>
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c line 22
Quoted 10 lines
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +3
-5-#include <linux/init.h> -#include <linux/kmod.h> +#include <linux/acpi.h> #include <linux/device.h> -#include <linux/delay.h> -#include <linux/slab.h> #include <linux/i2c.h> -#include <linux/moduleparam.h> +#include <linux/module.h> +#include <linux/types.h>
+ Blank line?
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c line 36
Quoted 4 lines
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +0
-2#include <media/ovxxxx_16bit_addr_reg_helpers.h> #include <media/v4l2-device.h> -#include <linux/io.h> -#include <linux/acpi.h>
+ Blank line?
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c
Quoted 3 lines
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +0
-1#include "../include/linux/atomisp_gmin_platform.h" -
I would leave it to make separate groups of headers.
Quoted 6 lines
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +0
-0#include "ov2680.h" static enum
atomisp_bayer_orderov2680_bayer_order_mapping[] = {Signature · 1 line
2.39.0
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 46/57 media: atomisp: ov2680: Delay power-on till streaming is started
In reply to Hans de GoedeMove the setting of the mode to stream on, this also allows delaying power-on till streaming is started.
And drop the deprecated s_power callback since this now no long is necessary.
--- .../media/atomisp/i2c/atomisp-ov2680.c | 101 +++++++----------- 1 file changed, 41 insertions(+), 60 deletions(-)
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +41 -60
@@ -327,24 +327,6 @@ static int power_down(struct v4l2_subdev *sd)return 0 ; } -static int ov2680_s_power (struct v4l2_subdev *sd,int on) -{ -struct ov2680_device *dev =to_ov2680_sensor (sd); -int ret; - -mutex_lock (&dev->input_lock); - -if (on ==0 ) { - ret =power_down (sd); - }else { - ret =power_up (sd); - } - -mutex_unlock (&dev->input_lock); - -return ret; -} -static struct v4l2_mbus_framefmt * __ov2680_get_pad_format(struct ov2680_device *sensor, struct v4l2_subdev_state *state,
@@ -393,14 +375,12 @@ static void ov2680_calc_mode(struct ov2680_device *sensor, int width, int height sensor->mode.vts =OV2680_LINES_PER_FRAME ; } -static int ov2680_set_mode (struct ov2680_device *sensor,int width,int height) +static int ov2680_set_mode (struct ov2680_device *sensor) {struct i2c_client *client = sensor->client;u8 pll_div, unknown, inc, fmt1, fmt2;int ret; -ov2680_calc_mode (sensor, width, height); -if (sensor->mode.binning) { pll_div =1 ; unknown =0x23 ;
@@ -500,7 +480,6 @@ static int ov2680_set_fmt(struct v4l2_subdev *sd,struct i2c_client *client =v4l2_get_subdevdata (sd);struct v4l2_mbus_framefmt *fmt;unsigned int width, height; -int ret =0 ; dev_dbg(&client->dev, "%s: %s: pad: %d, fmt: %p\n", __func__,
@@ -518,23 +497,10 @@ static int ov2680_set_fmt(struct v4l2_subdev *sd,if (format->which ==V4L2_SUBDEV_FORMAT_TRY )return 0 ; -dev_dbg (&client->dev,"%s: %dx%d\n" , - __func__, fmt->width, fmt->height); -mutex_lock (&dev->input_lock); - -/* s_power has not been called yet for std v4l2 clients (camorama) */ -power_up (sd); - - ret =ov2680_set_mode (dev, fmt->width, fmt->height); -if (ret <0 ) - goto err; - -/* Restore value of all ctrls */ - ret =__v4l2_ctrl_handler_setup (&dev->ctrls.handler); -err: +ov2680_calc_mode (dev, fmt->width, fmt->height);mutex_unlock (&dev->input_lock); -return ret; +return 0 ; } static int ov2680_get_fmt(struct v4l2_subdev *sd,
@@ -584,30 +550,50 @@ static int ov2680_detect(struct i2c_client *client)static int ov2680_s_stream (struct v4l2_subdev *sd,int enable) { -struct ov2680_device *dev =to_ov2680_sensor (sd); +struct ov2680_device *sensor =to_ov2680_sensor (sd);struct i2c_client *client =v4l2_get_subdevdata (sd); -int ret; +int ret =0 ; -mutex_lock (&dev->input_lock); -if (enable) -dev_dbg (&client->dev,"ov2680_s_stream one\n" ); -else -dev_dbg (&client->dev,"ov2680_s_stream off\n" ); - - ret =ovxxxx_write_reg8 (client,OV2680_SW_STREAM , - enable ?OV2680_START_STREAMING :OV2680_STOP_STREAMING ); -if (ret ==0 ) { - dev->is_streaming = enable; -v4l2_ctrl_activate (dev->ctrls.vflip, !enable); -v4l2_ctrl_activate (dev->ctrls.hflip, !enable); +mutex_lock (&sensor->input_lock); + +if (sensor->is_streaming == enable) { +dev_warn (&client->dev,"stream already %sed\n" , enable ?"start" :"stopp" ); + goto error_unlock; } -//otp valid at stream on state -//if(!dev->otp_data) -// dev->otp_data = ov2680_otp_read(sd); +if (enable) { + ret =power_up (sd); +if (ret) + goto error_unlock; -mutex_unlock (&dev->input_lock); + ret =ov2680_set_mode (sensor); +if (ret) + goto error_power_down; +/* Restore value of all ctrls */ + ret =__v4l2_ctrl_handler_setup (&sensor->ctrls.handler); +if (ret) + goto error_power_down; + + ret =ovxxxx_write_reg8 (client,OV2680_SW_STREAM ,OV2680_START_STREAMING ); +if (ret) + goto error_power_down; + }else { +ovxxxx_write_reg8 (client,OV2680_SW_STREAM ,OV2680_STOP_STREAMING ); +power_down (sd); + } + + sensor->is_streaming = enable; +v4l2_ctrl_activate (sensor->ctrls.vflip, !enable); +v4l2_ctrl_activate (sensor->ctrls.hflip, !enable); + +mutex_unlock (&sensor->input_lock); +return 0 ; + +error_power_down: +power_down (sd); +error_unlock: +mutex_unlock (&sensor->input_lock);return ret; }
@@ -736,10 +722,6 @@ static const struct v4l2_subdev_sensor_ops ov2680_sensor_ops = { .g_skip_frames = ov2680_g_skip_frames, }; -static const struct v4l2_subdev_core_ops ov2680_core_ops = { - .s_power = ov2680_s_power, -}; -static const struct v4l2_subdev_pad_ops ov2680_pad_ops = { .enum_mbus_code = ov2680_enum_mbus_code, .enum_frame_size = ov2680_enum_frame_size,
@@ -749,7 +731,6 @@ static const struct v4l2_subdev_pad_ops ov2680_pad_ops = { };static const struct v4l2_subdev_ops ov2680_ops = { - .core = &ov2680_core_ops, .video = &ov2680_video_ops, .pad = &ov2680_pad_ops, .sensor = &ov2680_sensor_ops,
Signature · 1 line
2.39.0
Re: [PATCH 46/57] media: atomisp: ov2680: Delay power-on till streaming is started
Quoted 5 lines · Hans de Goede
Move the setting of the mode to stream on, this also allows delaying power-on till streaming is started.
And drop the deprecated
s_powercallback since this now no long is necessary.
See below.
Quoted 100 lines
Signed-off-by Hans de Goede <[email protected]>--- .../media/atomisp/i2c/atomisp-ov2680.c | 101 +++++++----------- 1 file changed, 41 insertions(+), 60 deletions(-)drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +5
-45@@ -327,24 +327,6 @@ static int power_down(struct v4l2_subdev *sd)return 0 ; } -static int ov2680_s_power (struct v4l2_subdev *sd,int on) -{ -struct ov2680_device *dev =to_ov2680_sensor (sd); -int ret; - -mutex_lock (&dev->input_lock); - -if (on ==0 ) { - ret =power_down (sd); - }else { - ret =power_up (sd); - } - -mutex_unlock (&dev->input_lock); - -return ret; -} -static struct v4l2_mbus_framefmt * __ov2680_get_pad_format(struct ov2680_device *sensor, struct v4l2_subdev_state *state,@@ -393,14 +375,12 @@ static void ov2680_calc_mode(struct ov2680_device *sensor, int width, int height sensor->mode.vts =OV2680_LINES_PER_FRAME ; } -static int ov2680_set_mode (struct ov2680_device *sensor,int width,int height) +static int ov2680_set_mode (struct ov2680_device *sensor) {struct i2c_client *client = sensor->client;u8 pll_div, unknown, inc, fmt1, fmt2;int ret; -ov2680_calc_mode (sensor, width, height); -if (sensor->mode.binning) { pll_div =1 ; unknown =0x23 ;@@ -500,7 +480,6 @@ static int ov2680_set_fmt(struct v4l2_subdev *sd,struct i2c_client *client =v4l2_get_subdevdata (sd);struct v4l2_mbus_framefmt *fmt;unsigned int width, height; -int ret =0 ; dev_dbg(&client->dev, "%s: %s: pad: %d, fmt: %p\n", __func__,@@ -518,23 +497,10 @@ static int ov2680_set_fmt(struct v4l2_subdev *sd,if (format->which ==V4L2_SUBDEV_FORMAT_TRY )return 0 ; -dev_dbg (&client->dev,"%s: %dx%d\n" , - __func__, fmt->width, fmt->height); -mutex_lock (&dev->input_lock); - -/* s_power has not been called yet for std v4l2 clients (camorama) */ -power_up (sd); - - ret =ov2680_set_mode (dev, fmt->width, fmt->height); -if (ret <0 ) - goto err; - -/* Restore value of all ctrls */ - ret =__v4l2_ctrl_handler_setup (&dev->ctrls.handler); -err: +ov2680_calc_mode (dev, fmt->width, fmt->height);mutex_unlock (&dev->input_lock); -return ret; +return 0 ; } static int ov2680_get_fmt(struct v4l2_subdev *sd,@@ -584,30 +550,50 @@ static int ov2680_detect(struct i2c_client *client)static int ov2680_s_stream (struct v4l2_subdev *sd,int enable) { -struct ov2680_device *dev =to_ov2680_sensor (sd); +struct ov2680_device *sensor =to_ov2680_sensor (sd);struct i2c_client *client =v4l2_get_subdevdata (sd); -int ret; +int ret =0 ; -mutex_lock (&dev->input_lock); -if (enable) -dev_dbg (&client->dev,"ov2680_s_stream one\n" ); -else -dev_dbg (&client->dev,"ov2680_s_stream off\n" ); -
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c static int ov2680_detect(struct i2c_client *client) · line 560
Quoted 10 lines
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +4
-6- ret =ovxxxx_write_reg8 (client,OV2680_SW_STREAM , - enable ?OV2680_START_STREAMING :OV2680_STOP_STREAMING ); -if (ret ==0 ) { - dev->is_streaming = enable; -v4l2_ctrl_activate (dev->ctrls.vflip, !enable); -v4l2_ctrl_activate (dev->ctrls.hflip, !enable); +mutex_lock (&sensor->input_lock); + +if (sensor->is_streaming == enable) { +dev_warn (&client->dev,"stream already %sed\n" , enable ?"start" :"stopp" );
stopP ?!
Quoted 65 lines
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +32
-9+ goto error_unlock; } -//otp valid at stream on state -//if(!dev->otp_data) -// dev->otp_data = ov2680_otp_read(sd); +if (enable) { + ret =power_up (sd); +if (ret) + goto error_unlock; -mutex_unlock (&dev->input_lock); + ret =ov2680_set_mode (sensor); +if (ret) + goto error_power_down; +/* Restore value of all ctrls */ + ret =__v4l2_ctrl_handler_setup (&sensor->ctrls.handler); +if (ret) + goto error_power_down; + + ret =ovxxxx_write_reg8 (client,OV2680_SW_STREAM ,OV2680_START_STREAMING ); +if (ret) + goto error_power_down; + }else { +ovxxxx_write_reg8 (client,OV2680_SW_STREAM ,OV2680_STOP_STREAMING ); +power_down (sd); + } + + sensor->is_streaming = enable; +v4l2_ctrl_activate (sensor->ctrls.vflip, !enable); +v4l2_ctrl_activate (sensor->ctrls.hflip, !enable); + +mutex_unlock (&sensor->input_lock); +return 0 ; + +error_power_down: +power_down (sd); +error_unlock: +mutex_unlock (&sensor->input_lock);return ret; }@@ -736,10 +722,6 @@ static const struct v4l2_subdev_sensor_ops ov2680_sensor_ops = { .g_skip_frames = ov2680_g_skip_frames, }; -static const struct v4l2_subdev_core_ops ov2680_core_ops = { - .s_power = ov2680_s_power, -}; -static const struct v4l2_subdev_pad_ops ov2680_pad_ops = { .enum_mbus_code = ov2680_enum_mbus_code, .enum_frame_size = ov2680_enum_frame_size,@@ -749,7 +731,6 @@ static const struct v4l2_subdev_pad_ops ov2680_pad_ops = { };static const struct v4l2_subdev_ops ov2680_ops = { - .core = &ov2680_core_ops, .video = &ov2680_video_ops, .pad = &ov2680_pad_ops, .sensor = &ov2680_sensor_ops,Signature · 1 line
2.39.0
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 46/57] media: atomisp: ov2680: Delay power-on till streaming is started
Hi,
Quoted 20 lines · Andy Shevchenko
Quoted 5 lines · Hans de Goede
Move the setting of the mode to stream on, this also allows delaying power-on till streaming is started.
And drop the deprecated
s_powercallback since this now no long is necessary.Reviewed-by Andy Shevchenko <[email protected]>See below.
Quoted 9 lines
Signed-off-by Hans de Goede <[email protected]>--- .../media/atomisp/i2c/atomisp-ov2680.c | 101 +++++++----------- 1 file changed, 41 insertions(+), 60 deletions(-)drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +0
-0
<snip>
Quoted 4 lines
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c static int ov2680_detect(struct i2c_client *client) · line 560
Quoted 2 lines
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +2
-0+if (sensor->is_streaming == enable) { +dev_warn (&client->dev,"stream already %sed\n" , enable ?"start" :"stopp" );stopP ?!
Yes the format string is "%sed" so "stopp" gives us "stopped".
Regards,
Hans
Andy Shevchenko
maintainerRe: [PATCH 46/57] media: atomisp: ov2680: Delay power-on till streaming is started
Quoted 2 lines · Hans de Goede
Quoted 1 line · Andy Shevchenko
On Mon, Jan 23, 2023 at 01:51:54PM +0100, Hans de Goede wrote:
...
Quoted 6 lines
Quoted 4 lines
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c static int ov2680_detect(struct i2c_client *client) · line 560
Quoted 2 lines
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +2
-0+if (sensor->is_streaming == enable) { +dev_warn (&client->dev,"stream already %sed\n" , enable ?"start" :"stopp" );stopP ?!
Yes the format string is "%sed" so "stopp" gives us "stopped".
Can we, please, use full words, so it will be easier to find a candidate for including into string_choices.h or so?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 46/57] media: atomisp: ov2680: Delay power-on till streaming is started
Hi,
Quoted 11 lines · Andy Shevchenko
Quoted 2 lines · Hans de Goede
Quoted 1 line · Andy Shevchenko
On Mon, Jan 23, 2023 at 01:51:54PM +0100, Hans de Goede wrote:
...
Quoted 5 lines
Quoted 4 lines
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c static int ov2680_detect(struct i2c_client *client) · line 560
Quoted 2 lines
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +2
-0+if (sensor->is_streaming == enable) { +dev_warn (&client->dev,"stream already %sed\n" , enable ?"start" :"stopp" );stopP ?!
Quoted 4 lines
Quoted 1 line
Yes the format string is "%sed" so "stopp" gives us "stopped".
Can we, please, use full words, so it will be easier to find a candidate for including into
string_choices.hor so?
Sure I'll update this before adding it to the PR.
Regards,
Hans
PATCH 47/57 media: atomisp: ov2680: Add runtime-pm support
In reply to Hans de GoedeAdd runtime-pm support. This is a preparation patch for letting ACPI deal with the regulators and clocks instead of the DIY code in atomisp_gmin_platform.c.
--- .../media/atomisp/i2c/atomisp-ov2680.c | 57 ++++++++++++------- drivers/staging/media/atomisp/i2c/ov2680.h | 1 - 2 files changed, 36 insertions(+), 22 deletions(-)
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +36 -21
@@ -19,6 +19,7 @@#include <linux/device.h> #include <linux/i2c.h> #include <linux/module.h> +#include <linux/pm_runtime.h> #include <linux/types.h> #include <media/ovxxxx_16bit_addr_reg_helpers.h> #include <media/v4l2-device.h>
@@ -138,7 +139,8 @@ static int ov2680_s_ctrl(struct v4l2_ctrl *ctrl)struct ov2680_device *sensor =to_ov2680_sensor (sd);int ret; -if (!sensor->power_on) { +/* Only apply changes to the controls if the device is powered up */ +if (!pm_runtime_get_if_in_use (sensor->sd.dev)) {ov2680_set_bayer_order (sensor, &sensor->mode.fmt);return 0 ; }
@@ -162,6 +164,8 @@ static int ov2680_s_ctrl(struct v4l2_ctrl *ctrl)default : ret = -EINVAL ; } + +pm_runtime_put (sensor->sd.dev);return ret; }
@@ -244,9 +248,6 @@ static int power_up(struct v4l2_subdev *sd)return -ENODEV ; } -if (dev->power_on) -return 0 ;/* Already on */ -/* power control */ ret =power_ctrl (sd,1 );if (ret)
@@ -275,7 +276,6 @@ static int power_up(struct v4l2_subdev *sd)if (ret) goto fail_init_registers; - dev->power_on = true;return 0 ; fail_init_registers:
@@ -301,9 +301,6 @@ static int power_down(struct v4l2_subdev *sd)return -ENODEV ; } -if (!dev->power_on) -return 0 ;/* Already off */ - ret = dev->platform_data->flisclk_ctrl (sd,0 );if (ret)dev_err (&client->dev,"flisclk failed\n" );
@@ -323,7 +320,6 @@ static int power_down(struct v4l2_subdev *sd)return ret; } - dev->power_on = false;return 0 ; }
@@ -562,8 +558,8 @@ static int ov2680_s_stream(struct v4l2_subdev *sd, int enable) }if (enable) { - ret =power_up (sd); -if (ret) + ret =pm_runtime_get_sync (sensor->sd.dev); +if (ret <0 ) goto error_unlock; ret =ov2680_set_mode (sensor);
@@ -580,7 +576,7 @@ static int ov2680_s_stream(struct v4l2_subdev *sd, int enable) goto error_power_down; }else {ovxxxx_write_reg8 (client,OV2680_SW_STREAM ,OV2680_STOP_STREAMING ); -power_down (sd); +pm_runtime_put (sensor->sd.dev); } sensor->is_streaming = enable;
@@ -591,7 +587,7 @@ static int ov2680_s_stream(struct v4l2_subdev *sd, int enable)return 0 ; error_power_down: -power_down (sd); +pm_runtime_put (sensor->sd.dev); error_unlock:mutex_unlock (&sensor->input_lock);return ret;
@@ -612,8 +608,8 @@ static int ov2680_s_config(struct v4l2_subdev *sd,mutex_lock (&dev->input_lock); - ret =power_up (sd); -if (ret) { + ret =pm_runtime_get_sync (&client->dev); +if (ret <0 ) {dev_err (&client->dev,"ov2680 power-up err.\n" ); goto fail_power_on; }
@@ -630,11 +626,7 @@ static int ov2680_s_config(struct v4l2_subdev *sd, }/* turn off sensor, after probed */ - ret =power_down (sd); -if (ret) { -dev_err (&client->dev,"ov2680 power-off err.\n" ); - goto fail_csi_cfg; - } +pm_runtime_put (&client->dev);mutex_unlock (&dev->input_lock);return 0 ;
@@ -642,7 +634,7 @@ static int ov2680_s_config(struct v4l2_subdev *sd, fail_csi_cfg: dev->platform_data->csi_cfg (sd,0 ); fail_power_on: -power_down (sd); +pm_runtime_put (&client->dev);dev_err (&client->dev,"sensor power-gating failed\n" );mutex_unlock (&dev->input_lock);return ret;
@@ -787,6 +779,7 @@ static void ov2680_remove(struct i2c_client *client)v4l2_device_unregister_subdev (sd);media_entity_cleanup (&dev->sd.entity);v4l2_ctrl_handler_free (&dev->ctrls.handler); +pm_runtime_disable (&client->dev);kfree (dev); }
@@ -813,6 +806,11 @@ static int ov2680_probe(struct i2c_client *client) goto out_free; } +pm_runtime_set_suspended (&client->dev); +pm_runtime_enable (&client->dev); +pm_runtime_set_autosuspend_delay (&client->dev,1000 ); +pm_runtime_use_autosuspend (&client->dev); + ret =ov2680_s_config (&dev->sd, client->irq, pdata);if (ret) goto out_free;
@@ -849,6 +847,22 @@ static int ov2680_probe(struct i2c_client *client)return ret; } +static int ov2680_suspend (struct device *dev) +{ +struct v4l2_subdev *sd =dev_get_drvdata (dev); + +return power_down (sd); +} + +static int ov2680_resume (struct device *dev) +{ +struct v4l2_subdev *sd =dev_get_drvdata (dev); + +return power_up (sd); +} + +static DEFINE_RUNTIME_DEV_PM_OPS(ov2680_pm_ops, ov2680_suspend, ov2680_resume, NULL); +static const struct acpi_device_id ov2680_acpi_match[] = { {"XXOV2680" }, {"OVTI2680" },
@@ -859,6 +873,7 @@ MODULE_DEVICE_TABLE(acpi, ov2680_acpi_match);static struct i2c_driver ov2680_driver = { .driver = { .name ="ov2680" , + .pm =pm_sleep_ptr (&ov2680_pm_ops), .acpi_match_table = ov2680_acpi_match, }, .probe_new = ov2680_probe,
drivers/staging/media/atomisp/i2c/ov2680.h +0 -1
@@ -120,7 +120,6 @@ struct ov2680_device {struct mutex input_lock;struct i2c_client *client;struct camera_sensor_platform_data *platform_data; -bool power_on;bool is_streaming;struct ov2680_mode {
Signature · 1 line
2.39.0
Re: [PATCH 47/57] media: atomisp: ov2680: Add runtime-pm support
Quoted 3 lines · Hans de Goede
Add runtime-pm support. This is a preparation patch for letting ACPI deal with the regulators and clocks instead of the DIY code in
atomisp_gmin_platform.c.
Good one!
Quoted 201 lines
Signed-off-by Hans de Goede <[email protected]>--- .../media/atomisp/i2c/atomisp-ov2680.c | 57 ++++++++++++------- drivers/staging/media/atomisp/i2c/ov2680.h | 1 - 2 files changed, 36 insertions(+), 22 deletions(-)drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +36
-21@@ -19,6 +19,7 @@#include <linux/device.h> #include <linux/i2c.h> #include <linux/module.h> +#include <linux/pm_runtime.h> #include <linux/types.h> #include <media/ovxxxx_16bit_addr_reg_helpers.h> #include <media/v4l2-device.h> @@ -138,7 +139,8 @@ static int ov2680_s_ctrl(struct v4l2_ctrl *ctrl)struct ov2680_device *sensor =to_ov2680_sensor (sd);int ret; -if (!sensor->power_on) { +/* Only apply changes to the controls if the device is powered up */ +if (!pm_runtime_get_if_in_use (sensor->sd.dev)) {ov2680_set_bayer_order (sensor, &sensor->mode.fmt);return 0 ; }@@ -162,6 +164,8 @@ static int ov2680_s_ctrl(struct v4l2_ctrl *ctrl)default : ret = -EINVAL ; } + +pm_runtime_put (sensor->sd.dev);return ret; }@@ -244,9 +248,6 @@ static int power_up(struct v4l2_subdev *sd)return -ENODEV ; } -if (dev->power_on) -return 0 ;/* Already on */ -/* power control */ ret =power_ctrl (sd,1 );if (ret)@@ -275,7 +276,6 @@ static int power_up(struct v4l2_subdev *sd)if (ret) goto fail_init_registers; - dev->power_on = true;return 0 ; fail_init_registers:@@ -301,9 +301,6 @@ static int power_down(struct v4l2_subdev *sd)return -ENODEV ; } -if (!dev->power_on) -return 0 ;/* Already off */ - ret = dev->platform_data->flisclk_ctrl (sd,0 );if (ret)dev_err (&client->dev,"flisclk failed\n" );@@ -323,7 +320,6 @@ static int power_down(struct v4l2_subdev *sd)return ret; } - dev->power_on = false;return 0 ; }@@ -562,8 +558,8 @@ static int ov2680_s_stream(struct v4l2_subdev *sd, int enable) }if (enable) { - ret =power_up (sd); -if (ret) + ret =pm_runtime_get_sync (sensor->sd.dev); +if (ret <0 ) goto error_unlock; ret =ov2680_set_mode (sensor);@@ -580,7 +576,7 @@ static int ov2680_s_stream(struct v4l2_subdev *sd, int enable) goto error_power_down; }else {ovxxxx_write_reg8 (client,OV2680_SW_STREAM ,OV2680_STOP_STREAMING ); -power_down (sd); +pm_runtime_put (sensor->sd.dev); } sensor->is_streaming = enable;@@ -591,7 +587,7 @@ static int ov2680_s_stream(struct v4l2_subdev *sd, int enable)return 0 ; error_power_down: -power_down (sd); +pm_runtime_put (sensor->sd.dev); error_unlock:mutex_unlock (&sensor->input_lock);return ret;@@ -612,8 +608,8 @@ static int ov2680_s_config(struct v4l2_subdev *sd,mutex_lock (&dev->input_lock); - ret =power_up (sd); -if (ret) { + ret =pm_runtime_get_sync (&client->dev); +if (ret <0 ) {dev_err (&client->dev,"ov2680 power-up err.\n" ); goto fail_power_on; }@@ -630,11 +626,7 @@ static int ov2680_s_config(struct v4l2_subdev *sd, }/* turn off sensor, after probed */ - ret =power_down (sd); -if (ret) { -dev_err (&client->dev,"ov2680 power-off err.\n" ); - goto fail_csi_cfg; - } +pm_runtime_put (&client->dev);mutex_unlock (&dev->input_lock);return 0 ;@@ -642,7 +634,7 @@ static int ov2680_s_config(struct v4l2_subdev *sd, fail_csi_cfg: dev->platform_data->csi_cfg (sd,0 ); fail_power_on: -power_down (sd); +pm_runtime_put (&client->dev);dev_err (&client->dev,"sensor power-gating failed\n" );mutex_unlock (&dev->input_lock);return ret;@@ -787,6 +779,7 @@ static void ov2680_remove(struct i2c_client *client)v4l2_device_unregister_subdev (sd);media_entity_cleanup (&dev->sd.entity);v4l2_ctrl_handler_free (&dev->ctrls.handler); +pm_runtime_disable (&client->dev);kfree (dev); }@@ -813,6 +806,11 @@ static int ov2680_probe(struct i2c_client *client) goto out_free; } +pm_runtime_set_suspended (&client->dev); +pm_runtime_enable (&client->dev); +pm_runtime_set_autosuspend_delay (&client->dev,1000 ); +pm_runtime_use_autosuspend (&client->dev); + ret =ov2680_s_config (&dev->sd, client->irq, pdata);if (ret) goto out_free;@@ -849,6 +847,22 @@ static int ov2680_probe(struct i2c_client *client)return ret; } +static int ov2680_suspend (struct device *dev) +{ +struct v4l2_subdev *sd =dev_get_drvdata (dev); + +return power_down (sd); +} + +static int ov2680_resume (struct device *dev) +{ +struct v4l2_subdev *sd =dev_get_drvdata (dev); + +return power_up (sd); +} + +static DEFINE_RUNTIME_DEV_PM_OPS(ov2680_pm_ops, ov2680_suspend, ov2680_resume, NULL); +static const struct acpi_device_id ov2680_acpi_match[] = { {"XXOV2680" }, {"OVTI2680" },@@ -859,6 +873,7 @@ MODULE_DEVICE_TABLE(acpi, ov2680_acpi_match);static struct i2c_driver ov2680_driver = { .driver = { .name ="ov2680" , + .pm =pm_sleep_ptr (&ov2680_pm_ops), .acpi_match_table = ov2680_acpi_match, }, .probe_new = ov2680_probe,drivers/staging/media/atomisp/i2c/ov2680.h +0
-1@@ -120,7 +120,6 @@ struct ov2680_device {struct mutex input_lock;struct i2c_client *client;struct camera_sensor_platform_data *platform_data; -bool power_on;bool is_streaming;struct ov2680_mode {Signature · 1 line
2.39.0
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 48/57 media: atomisp: ov2680: s/dev/sensor/
In reply to Hans de GoedeUsing dev as name for variables pointing to struct ov2680_device is a bit unfortunate choice.
All the recently added / rewritten code is already using sensor for this, replace the remaining usages of "struct ov2680_device *dev" with "struct ov2680_device *sensor".
Note the power_up()/power_down() related functions are not changed as these will be removed in one of the next patches.
--- .../media/atomisp/i2c/atomisp-ov2680.c | 74 +++++++++---------- 1 file changed, 37 insertions(+), 37 deletions(-)
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +37 -37
@@ -472,7 +472,7 @@ static int ov2680_set_fmt(struct v4l2_subdev *sd,struct v4l2_subdev_state *sd_state, struct v4l2_subdev_format *format) { - struct ov2680_device *dev = to_ov2680_sensor(sd); + struct ov2680_device *sensor = to_ov2680_sensor(sd);struct i2c_client *client =v4l2_get_subdevdata (sd);struct v4l2_mbus_framefmt *fmt;unsigned int width, height;
@@ -485,17 +485,17 @@ static int ov2680_set_fmt(struct v4l2_subdev *sd, width = min_t(unsigned int, ALIGN(format->format.width, 2), OV2680_NATIVE_WIDTH); height = min_t(unsigned int, ALIGN(format->format.height, 2), OV2680_NATIVE_HEIGHT); - fmt =__ov2680_get_pad_format (dev, sd_state, format->pad, format->which); -ov2680_fill_format (dev, fmt, width, height); + fmt =__ov2680_get_pad_format (sensor, sd_state, format->pad, format->which); +ov2680_fill_format (sensor, fmt, width, height); format->format = *fmt;if (format->which ==V4L2_SUBDEV_FORMAT_TRY )return 0 ; -mutex_lock (&dev->input_lock); -ov2680_calc_mode (dev, fmt->width, fmt->height); -mutex_unlock (&dev->input_lock); +mutex_lock (&sensor->input_lock); +ov2680_calc_mode (sensor, fmt->width, fmt->height); +mutex_unlock (&sensor->input_lock);return 0 ; }
@@ -503,10 +503,10 @@ static int ov2680_get_fmt(struct v4l2_subdev *sd,struct v4l2_subdev_state *sd_state, struct v4l2_subdev_format *format) { - struct ov2680_device *dev = to_ov2680_sensor(sd); + struct ov2680_device *sensor = to_ov2680_sensor(sd);struct v4l2_mbus_framefmt *fmt; - fmt =__ov2680_get_pad_format (dev, sd_state, format->pad, format->which); + fmt =__ov2680_get_pad_format (sensor, sd_state, format->pad, format->which); format->format = *fmt;return 0 ; }
@@ -596,17 +596,17 @@ static int ov2680_s_stream(struct v4l2_subdev *sd, int enable)static int ov2680_s_config (struct v4l2_subdev *sd,int irq,void *platform_data) { -struct ov2680_device *dev =to_ov2680_sensor (sd); +struct ov2680_device *sensor =to_ov2680_sensor (sd);struct i2c_client *client =v4l2_get_subdevdata (sd);int ret =0 ;if (!platform_data)return -ENODEV ; - dev->platform_data = + sensor->platform_data = (struct camera_sensor_platform_data *)platform_data; -mutex_lock (&dev->input_lock); +mutex_lock (&sensor->input_lock); ret =pm_runtime_get_sync (&client->dev);if (ret <0 ) {
@@ -614,7 +614,7 @@ static int ov2680_s_config(struct v4l2_subdev *sd, goto fail_power_on; } - ret = dev->platform_data->csi_cfg (sd,1 ); + ret = sensor->platform_data->csi_cfg (sd,1 );if (ret) goto fail_csi_cfg;
@@ -627,16 +627,16 @@ static int ov2680_s_config(struct v4l2_subdev *sd,/* turn off sensor, after probed */ pm_runtime_put (&client->dev); -mutex_unlock (&dev->input_lock); +mutex_unlock (&sensor->input_lock);return 0 ; fail_csi_cfg: - dev->platform_data->csi_cfg (sd,0 ); + sensor->platform_data->csi_cfg (sd,0 ); fail_power_on:pm_runtime_put (&client->dev);dev_err (&client->dev,"sensor power-gating failed\n" ); -mutex_unlock (&dev->input_lock); +mutex_unlock (&sensor->input_lock);return ret; }
@@ -770,35 +770,35 @@ static int ov2680_init_controls(struct ov2680_device *sensor)static void ov2680_remove (struct i2c_client *client) {struct v4l2_subdev *sd =i2c_get_clientdata (client); -struct ov2680_device *dev =to_ov2680_sensor (sd); +struct ov2680_device *sensor =to_ov2680_sensor (sd);dev_dbg (&client->dev,"ov2680_remove...\n" ); - dev->platform_data->csi_cfg (sd,0 ); + sensor->platform_data->csi_cfg (sd,0 );v4l2_device_unregister_subdev (sd); -media_entity_cleanup (&dev->sd.entity); -v4l2_ctrl_handler_free (&dev->ctrls.handler); +media_entity_cleanup (&sensor->sd.entity); +v4l2_ctrl_handler_free (&sensor->ctrls.handler);pm_runtime_disable (&client->dev); -kfree (dev); +kfree (sensor); }static int ov2680_probe (struct i2c_client *client) { -struct ov2680_device *dev; +struct ov2680_device *sensor;int ret;void *pdata; - dev =kzalloc (sizeof (*dev),GFP_KERNEL ); -if (!dev) + sensor =kzalloc (sizeof (*sensor),GFP_KERNEL ); +if (!sensor)return -ENOMEM ; -mutex_init (&dev->input_lock); +mutex_init (&sensor->input_lock); - dev->client = client; -v4l2_i2c_subdev_init (&dev->sd, client, &ov2680_ops); + sensor->client = client; +v4l2_i2c_subdev_init (&sensor->sd, client, &ov2680_ops); - pdata =gmin_camera_platform_data (&dev->sd, + pdata =gmin_camera_platform_data (&sensor->sd,ATOMISP_INPUT_FORMAT_RAW_10 , atomisp_bayer_order_bggr);if (!pdata) {
@@ -811,29 +811,29 @@ static int ov2680_probe(struct i2c_client *client)pm_runtime_set_autosuspend_delay (&client->dev,1000 );pm_runtime_use_autosuspend (&client->dev); - ret =ov2680_s_config (&dev->sd, client->irq, pdata); + ret =ov2680_s_config (&sensor->sd, client->irq, pdata);if (ret) goto out_free; - dev->sd.flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ; - dev->pad.flags =MEDIA_PAD_FL_SOURCE ; - dev->sd.entity.function =MEDIA_ENT_F_CAM_SENSOR ; + sensor->sd.flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ; + sensor->pad.flags =MEDIA_PAD_FL_SOURCE ; + sensor->sd.entity.function =MEDIA_ENT_F_CAM_SENSOR ; - ret =ov2680_init_controls (dev); + ret =ov2680_init_controls (sensor);if (ret) {ov2680_remove (client);return ret; } - ret =media_entity_pads_init (&dev->sd.entity,1 , &dev->pad); + ret =media_entity_pads_init (&sensor->sd.entity,1 , &sensor->pad);if (ret) {ov2680_remove (client);return ret; } -ov2680_fill_format (dev, &dev->mode.fmt,OV2680_NATIVE_WIDTH ,OV2680_NATIVE_HEIGHT ); +ov2680_fill_format (sensor, &sensor->mode.fmt,OV2680_NATIVE_WIDTH ,OV2680_NATIVE_HEIGHT ); - ret =atomisp_register_i2c_module (&dev->sd, pdata,RAW_CAMERA ); + ret =atomisp_register_i2c_module (&sensor->sd, pdata,RAW_CAMERA );if (ret) {ov2680_remove (client);return ret;
@@ -842,8 +842,8 @@ static int ov2680_probe(struct i2c_client *client)return 0 ; out_free:dev_dbg (&client->dev,"+++ out free\n" ); -v4l2_device_unregister_subdev (&dev->sd); -kfree (dev); +v4l2_device_unregister_subdev (&sensor->sd); +kfree (sensor);return ret; }
Signature · 1 line
2.39.0
Re: [PATCH 48/57] media: atomisp: ov2680: s/dev/sensor/
Quoted 9 lines · Hans de Goede
Using dev as name for variables pointing to struct
ov2680_deviceis a bit unfortunate choice.All the recently added / rewritten code is already using sensor for this, replace the remaining usages of "struct
ov2680_device*dev" with "structov2680_device*sensor".Note the power_up()/power_down() related functions are not changed as these will be removed in one of the next patches.
No functional changes. ?
Quoted 204 lines
Signed-off-by Hans de Goede <[email protected]>--- .../media/atomisp/i2c/atomisp-ov2680.c | 74 +++++++++---------- 1 file changed, 37 insertions(+), 37 deletions(-)drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +37
-37@@ -472,7 +472,7 @@ static int ov2680_set_fmt(struct v4l2_subdev *sd,struct v4l2_subdev_state *sd_state, struct v4l2_subdev_format *format) { - struct ov2680_device *dev = to_ov2680_sensor(sd); + struct ov2680_device *sensor = to_ov2680_sensor(sd);struct i2c_client *client =v4l2_get_subdevdata (sd);struct v4l2_mbus_framefmt *fmt;unsigned int width, height;@@ -485,17 +485,17 @@ static int ov2680_set_fmt(struct v4l2_subdev *sd, width = min_t(unsigned int, ALIGN(format->format.width, 2), OV2680_NATIVE_WIDTH); height = min_t(unsigned int, ALIGN(format->format.height, 2), OV2680_NATIVE_HEIGHT); - fmt =__ov2680_get_pad_format (dev, sd_state, format->pad, format->which); -ov2680_fill_format (dev, fmt, width, height); + fmt =__ov2680_get_pad_format (sensor, sd_state, format->pad, format->which); +ov2680_fill_format (sensor, fmt, width, height); format->format = *fmt;if (format->which ==V4L2_SUBDEV_FORMAT_TRY )return 0 ; -mutex_lock (&dev->input_lock); -ov2680_calc_mode (dev, fmt->width, fmt->height); -mutex_unlock (&dev->input_lock); +mutex_lock (&sensor->input_lock); +ov2680_calc_mode (sensor, fmt->width, fmt->height); +mutex_unlock (&sensor->input_lock);return 0 ; }@@ -503,10 +503,10 @@ static int ov2680_get_fmt(struct v4l2_subdev *sd,struct v4l2_subdev_state *sd_state, struct v4l2_subdev_format *format) { - struct ov2680_device *dev = to_ov2680_sensor(sd); + struct ov2680_device *sensor = to_ov2680_sensor(sd);struct v4l2_mbus_framefmt *fmt; - fmt =__ov2680_get_pad_format (dev, sd_state, format->pad, format->which); + fmt =__ov2680_get_pad_format (sensor, sd_state, format->pad, format->which); format->format = *fmt;return 0 ; }@@ -596,17 +596,17 @@ static int ov2680_s_stream(struct v4l2_subdev *sd, int enable)static int ov2680_s_config (struct v4l2_subdev *sd,int irq,void *platform_data) { -struct ov2680_device *dev =to_ov2680_sensor (sd); +struct ov2680_device *sensor =to_ov2680_sensor (sd);struct i2c_client *client =v4l2_get_subdevdata (sd);int ret =0 ;if (!platform_data)return -ENODEV ; - dev->platform_data = + sensor->platform_data = (struct camera_sensor_platform_data *)platform_data; -mutex_lock (&dev->input_lock); +mutex_lock (&sensor->input_lock); ret =pm_runtime_get_sync (&client->dev);if (ret <0 ) {@@ -614,7 +614,7 @@ static int ov2680_s_config(struct v4l2_subdev *sd, goto fail_power_on; } - ret = dev->platform_data->csi_cfg (sd,1 ); + ret = sensor->platform_data->csi_cfg (sd,1 );if (ret) goto fail_csi_cfg;@@ -627,16 +627,16 @@ static int ov2680_s_config(struct v4l2_subdev *sd,/* turn off sensor, after probed */ pm_runtime_put (&client->dev); -mutex_unlock (&dev->input_lock); +mutex_unlock (&sensor->input_lock);return 0 ; fail_csi_cfg: - dev->platform_data->csi_cfg (sd,0 ); + sensor->platform_data->csi_cfg (sd,0 ); fail_power_on:pm_runtime_put (&client->dev);dev_err (&client->dev,"sensor power-gating failed\n" ); -mutex_unlock (&dev->input_lock); +mutex_unlock (&sensor->input_lock);return ret; }@@ -770,35 +770,35 @@ static int ov2680_init_controls(struct ov2680_device *sensor)static void ov2680_remove (struct i2c_client *client) {struct v4l2_subdev *sd =i2c_get_clientdata (client); -struct ov2680_device *dev =to_ov2680_sensor (sd); +struct ov2680_device *sensor =to_ov2680_sensor (sd);dev_dbg (&client->dev,"ov2680_remove...\n" ); - dev->platform_data->csi_cfg (sd,0 ); + sensor->platform_data->csi_cfg (sd,0 );v4l2_device_unregister_subdev (sd); -media_entity_cleanup (&dev->sd.entity); -v4l2_ctrl_handler_free (&dev->ctrls.handler); +media_entity_cleanup (&sensor->sd.entity); +v4l2_ctrl_handler_free (&sensor->ctrls.handler);pm_runtime_disable (&client->dev); -kfree (dev); +kfree (sensor); }static int ov2680_probe (struct i2c_client *client) { -struct ov2680_device *dev; +struct ov2680_device *sensor;int ret;void *pdata; - dev =kzalloc (sizeof (*dev),GFP_KERNEL ); -if (!dev) + sensor =kzalloc (sizeof (*sensor),GFP_KERNEL ); +if (!sensor)return -ENOMEM ; -mutex_init (&dev->input_lock); +mutex_init (&sensor->input_lock); - dev->client = client; -v4l2_i2c_subdev_init (&dev->sd, client, &ov2680_ops); + sensor->client = client; +v4l2_i2c_subdev_init (&sensor->sd, client, &ov2680_ops); - pdata =gmin_camera_platform_data (&dev->sd, + pdata =gmin_camera_platform_data (&sensor->sd,ATOMISP_INPUT_FORMAT_RAW_10 , atomisp_bayer_order_bggr);if (!pdata) {@@ -811,29 +811,29 @@ static int ov2680_probe(struct i2c_client *client)pm_runtime_set_autosuspend_delay (&client->dev,1000 );pm_runtime_use_autosuspend (&client->dev); - ret =ov2680_s_config (&dev->sd, client->irq, pdata); + ret =ov2680_s_config (&sensor->sd, client->irq, pdata);if (ret) goto out_free; - dev->sd.flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ; - dev->pad.flags =MEDIA_PAD_FL_SOURCE ; - dev->sd.entity.function =MEDIA_ENT_F_CAM_SENSOR ; + sensor->sd.flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ; + sensor->pad.flags =MEDIA_PAD_FL_SOURCE ; + sensor->sd.entity.function =MEDIA_ENT_F_CAM_SENSOR ; - ret =ov2680_init_controls (dev); + ret =ov2680_init_controls (sensor);if (ret) {ov2680_remove (client);return ret; } - ret =media_entity_pads_init (&dev->sd.entity,1 , &dev->pad); + ret =media_entity_pads_init (&sensor->sd.entity,1 , &sensor->pad);if (ret) {ov2680_remove (client);return ret; } -ov2680_fill_format (dev, &dev->mode.fmt,OV2680_NATIVE_WIDTH ,OV2680_NATIVE_HEIGHT ); +ov2680_fill_format (sensor, &sensor->mode.fmt,OV2680_NATIVE_WIDTH ,OV2680_NATIVE_HEIGHT ); - ret =atomisp_register_i2c_module (&dev->sd, pdata,RAW_CAMERA ); + ret =atomisp_register_i2c_module (&sensor->sd, pdata,RAW_CAMERA );if (ret) {ov2680_remove (client);return ret;@@ -842,8 +842,8 @@ static int ov2680_probe(struct i2c_client *client)return 0 ; out_free:dev_dbg (&client->dev,"+++ out free\n" ); -v4l2_device_unregister_subdev (&dev->sd); -kfree (dev); +v4l2_device_unregister_subdev (&sensor->sd); +kfree (sensor);return ret; }Signature · 1 line
2.39.0
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 49/57 media: atomisp: ov2680: Use devm_kzalloc() for sensor data struct
In reply to Hans de GoedeUse devm_kzalloc() to allocate the sensor data struct. It is always free-ed as the last step of probe-error-exit or remove, so it can be devm-managed.
This will make unwinding things easier when support is added to the ov2680 code to use standard GPIO APIs instead of the custom atomisp_gmin code.
This also allows dropping the out_free label and use direct return on errors.
This may seem like a functional change since the out_free label also did a v4l2_device_unregister_subdev() but at the 2 changed returns the device is not registered yet, so that always is a no-op and can be dropped.
--- .../staging/media/atomisp/i2c/atomisp-ov2680.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +4 -12
@@ -780,7 +780,6 @@ static void ov2680_remove(struct i2c_client *client)media_entity_cleanup (&sensor->sd.entity);v4l2_ctrl_handler_free (&sensor->ctrls.handler);pm_runtime_disable (&client->dev); -kfree (sensor); }static int ov2680_probe (struct i2c_client *client)
@@ -789,7 +788,7 @@ static int ov2680_probe(struct i2c_client *client)int ret;void *pdata; - sensor =kzalloc (sizeof (*sensor),GFP_KERNEL ); + sensor =devm_kzalloc (&client->dev,sizeof (*sensor),GFP_KERNEL );if (!sensor)return -ENOMEM ;
@@ -801,10 +800,8 @@ static int ov2680_probe(struct i2c_client *client) pdata =gmin_camera_platform_data (&sensor->sd,ATOMISP_INPUT_FORMAT_RAW_10 , atomisp_bayer_order_bggr); -if (!pdata) { - ret = -EINVAL ; - goto out_free; - } +if (!pdata) +return -EINVAL ;pm_runtime_set_suspended (&client->dev);pm_runtime_enable (&client->dev);
@@ -813,7 +810,7 @@ static int ov2680_probe(struct i2c_client *client) ret =ov2680_s_config (&sensor->sd, client->irq, pdata);if (ret) - goto out_free; +return ret; sensor->sd.flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ; sensor->pad.flags =MEDIA_PAD_FL_SOURCE ;
@@ -840,11 +837,6 @@ static int ov2680_probe(struct i2c_client *client) }return 0 ; -out_free: -dev_dbg (&client->dev,"+++ out free\n" ); -v4l2_device_unregister_subdev (&sensor->sd); -kfree (sensor); -return ret; }static int ov2680_suspend (struct device *dev)
Signature · 1 line
2.39.0
Re: [PATCH 49/57] media: atomisp: ov2680: Use devm_kzalloc() for sensor data struct
Quoted 6 lines · Hans de Goede
Use
devm_kzalloc()to allocate the sensor data struct. It is always free-ed as the last step of probe-error-exit or remove, so it can be devm-managed.This will make unwinding things easier when support is added to the ov2680 code to use standard GPIO APIs instead of the custom
atomisp_gmincode.
Quoted 7 lines
This also allows dropping the
out_freelabel and use direct return on errors.This may seem like a functional change since the
out_freelabel also did av4l2_device_unregister_subdev()but at the 2 changed returns the device is not registered yet, so that always is a no-op and can be dropped.
Quoted 63 lines
Signed-off-by Hans de Goede <[email protected]>--- .../staging/media/atomisp/i2c/atomisp-ov2680.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +4
-12@@ -780,7 +780,6 @@ static void ov2680_remove(struct i2c_client *client)media_entity_cleanup (&sensor->sd.entity);v4l2_ctrl_handler_free (&sensor->ctrls.handler);pm_runtime_disable (&client->dev); -kfree (sensor); }static int ov2680_probe (struct i2c_client *client)@@ -789,7 +788,7 @@ static int ov2680_probe(struct i2c_client *client)int ret;void *pdata; - sensor =kzalloc (sizeof (*sensor),GFP_KERNEL ); + sensor =devm_kzalloc (&client->dev,sizeof (*sensor),GFP_KERNEL );if (!sensor)return -ENOMEM ;@@ -801,10 +800,8 @@ static int ov2680_probe(struct i2c_client *client) pdata =gmin_camera_platform_data (&sensor->sd,ATOMISP_INPUT_FORMAT_RAW_10 , atomisp_bayer_order_bggr); -if (!pdata) { - ret = -EINVAL ; - goto out_free; - } +if (!pdata) +return -EINVAL ;pm_runtime_set_suspended (&client->dev);pm_runtime_enable (&client->dev);@@ -813,7 +810,7 @@ static int ov2680_probe(struct i2c_client *client) ret =ov2680_s_config (&sensor->sd, client->irq, pdata);if (ret) - goto out_free; +return ret; sensor->sd.flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ; sensor->pad.flags =MEDIA_PAD_FL_SOURCE ;@@ -840,11 +837,6 @@ static int ov2680_probe(struct i2c_client *client) }return 0 ; -out_free: -dev_dbg (&client->dev,"+++ out free\n" ); -v4l2_device_unregister_subdev (&sensor->sd); -kfree (sensor); -return ret; }static int ov2680_suspend (struct device *dev)Signature · 1 line
2.39.0
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 50/57 media: atomisp: ov2680: Switch over to ACPI powermanagement
In reply to Hans de GoedeThe DSDT of all Windows BYT / CHT devices which I have seen has proper ACPI powermagement for the clk and regulators used by the sensors.
So there is no need for the whole custom atomisp_gmin custom code to disable the ACPI pm and directly poke at the PMIC for this.
Replace all the atomisp_gmin usage with using the new atomisp_register_sensor_no_gmin() / atomisp_unregister_subdev() helpers which allow registering a sensor with the atomisp code without using any of the atomisp_gmin power-management code.
Note eventually these calls should be replaced by the standard v4l2_async_register_subdev_sensor() mechanism.
But this first requires a bunch of work to the atomisp main code to make it set the necessary fwnodes up, similar to how drivers/media/pci/intel/ipu3/cio2-bridge.c does this.
This has been tested on:
-Trekstor Surftab duo W1 10.1, CHT, AXP288 PMIC, 2x ov2680 sensor -Asus T101HA, CHT, TI PMIC, 1x ov2680 sensor
-MPMAN Converter 9, BYT, AXP288 PMIC, ov2680 back, gc0310 front sensor
--- .../media/atomisp/i2c/atomisp-ov2680.c | 231 ++++-------------- drivers/staging/media/atomisp/i2c/ov2680.h | 3 +- 2 files changed, 53 insertions(+), 181 deletions(-)
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +51 -180
@@ -17,6 +17,8 @@#include <linux/acpi.h> #include <linux/device.h> +#include <linux/gpio/consumer.h> +#include <linux/gpio/machine.h> #include <linux/i2c.h> #include <linux/module.h> #include <linux/pm_runtime.h>
@@ -184,145 +186,6 @@ static int ov2680_init_registers(struct v4l2_subdev *sd)return ret; } -static int power_ctrl (struct v4l2_subdev *sd,bool flag) -{ -int ret =0 ; -struct ov2680_device *dev =to_ov2680_sensor (sd); -struct i2c_client *client =v4l2_get_subdevdata (sd); - -if (!dev || !dev->platform_data) -return -ENODEV ; - -dev_dbg (&client->dev,"%s: %s" , __func__, flag ?"on" :"off" ); - -if (flag) { - ret |= dev->platform_data->v1p8_ctrl (sd,1 ); - ret |= dev->platform_data->v2p8_ctrl (sd,1 ); -usleep_range (10000 ,15000 ); - } - -if (!flag || ret) { - ret |= dev->platform_data->v1p8_ctrl (sd,0 ); - ret |= dev->platform_data->v2p8_ctrl (sd,0 ); - } -return ret; -} - -static int gpio_ctrl (struct v4l2_subdev *sd,bool flag) -{ -int ret; -struct ov2680_device *dev =to_ov2680_sensor (sd); - -if (!dev || !dev->platform_data) -return -ENODEV ; - -/* -* The OV2680 documents only one GPIO input (#XSHUTDN), but -* existing integrations often wire two (reset/power_down) -* because that is the way other sensors work. There is no -* way to tell how it is wired internally, so existing -* firmwares expose both and we drive them symmetrically. -*/ -if (flag) { - ret = dev->platform_data->gpio0_ctrl (sd,1 ); -usleep_range (10000 ,15000 ); -/* Ignore return from second gpio, it may not be there */ - dev->platform_data->gpio1_ctrl (sd,1 ); -usleep_range (10000 ,15000 ); - }else { - dev->platform_data->gpio1_ctrl (sd,0 ); - ret = dev->platform_data->gpio0_ctrl (sd,0 ); - } -return ret; -} - -static int power_up (struct v4l2_subdev *sd) -{ -struct ov2680_device *dev =to_ov2680_sensor (sd); -struct i2c_client *client =v4l2_get_subdevdata (sd); -int ret; - -if (!dev->platform_data) { -dev_err (&client->dev, -"no camera_sensor_platform_data" ); -return -ENODEV ; - } - -/* power control */ - ret =power_ctrl (sd,1 ); -if (ret) - goto fail_power; - -/* according to DS, at least 5ms is needed between DOVDD and PWDN */ -usleep_range (5000 ,6000 ); - -/* gpio ctrl */ - ret =gpio_ctrl (sd,1 ); -if (ret) { - ret =gpio_ctrl (sd,1 ); -if (ret) - goto fail_power; - } - -/* flis clock control */ - ret = dev->platform_data->flisclk_ctrl (sd,1 ); -if (ret) - goto fail_clk; - -/* according to DS, 20ms is needed between PWDN and i2c access */ -msleep (20 ); - - ret =ov2680_init_registers (sd); -if (ret) - goto fail_init_registers; - -return 0 ; - -fail_init_registers: - dev->platform_data->flisclk_ctrl (sd,0 ); -fail_clk: -gpio_ctrl (sd,0 ); -fail_power: -power_ctrl (sd,0 ); -dev_err (&client->dev,"sensor power-up failed\n" ); - -return ret; -} - -static int power_down (struct v4l2_subdev *sd) -{ -struct ov2680_device *dev =to_ov2680_sensor (sd); -struct i2c_client *client =v4l2_get_subdevdata (sd); -int ret =0 ; - -if (!dev->platform_data) { -dev_err (&client->dev, -"no camera_sensor_platform_data" ); -return -ENODEV ; - } - - ret = dev->platform_data->flisclk_ctrl (sd,0 ); -if (ret) -dev_err (&client->dev,"flisclk failed\n" ); - -/* gpio ctrl */ - ret =gpio_ctrl (sd,0 ); -if (ret) { - ret =gpio_ctrl (sd,0 ); -if (ret) -dev_err (&client->dev,"gpio failed 2\n" ); - } - -/* power control */ - ret =power_ctrl (sd,0 ); -if (ret) { -dev_err (&client->dev,"vprog failed.\n" ); -return ret; - } - -return 0 ; -} -static struct v4l2_mbus_framefmt * __ov2680_get_pad_format(struct ov2680_device *sensor, struct v4l2_subdev_state *state,
@@ -593,20 +456,10 @@ static int ov2680_s_stream(struct v4l2_subdev *sd, int enable)return ret; } -static int ov2680_s_config (struct v4l2_subdev *sd, -int irq,void *platform_data) +static int ov2680_s_config (struct v4l2_subdev *sd) { -struct ov2680_device *sensor =to_ov2680_sensor (sd);struct i2c_client *client =v4l2_get_subdevdata (sd); -int ret =0 ; - -if (!platform_data) -return -ENODEV ; - - sensor->platform_data = - (struct camera_sensor_platform_data *)platform_data; - -mutex_lock (&sensor->input_lock); +int ret; ret =pm_runtime_get_sync (&client->dev);if (ret <0 ) {
@@ -614,29 +467,13 @@ static int ov2680_s_config(struct v4l2_subdev *sd, goto fail_power_on; } - ret = sensor->platform_data->csi_cfg (sd,1 ); -if (ret) - goto fail_csi_cfg; -/* config & detect sensor */ ret =ov2680_detect (client); -if (ret) { +if (ret)dev_err (&client->dev,"ov2680_detect err s_config.\n" ); - goto fail_csi_cfg; - } -/* turn off sensor, after probed */ -pm_runtime_put (&client->dev); -mutex_unlock (&sensor->input_lock); - -return 0 ; - -fail_csi_cfg: - sensor->platform_data->csi_cfg (sd,0 ); fail_power_on:pm_runtime_put (&client->dev); -dev_err (&client->dev,"sensor power-gating failed\n" ); -mutex_unlock (&sensor->input_lock);return ret; }
@@ -774,19 +611,32 @@ static void ov2680_remove(struct i2c_client *client)dev_dbg (&client->dev,"ov2680_remove...\n" ); - sensor->platform_data->csi_cfg (sd,0 ); - +atomisp_unregister_subdev (sd);v4l2_device_unregister_subdev (sd);media_entity_cleanup (&sensor->sd.entity);v4l2_ctrl_handler_free (&sensor->ctrls.handler);pm_runtime_disable (&client->dev); } +/* +* Unlike other sensors which have both a rest and powerdown input pins, +* the OV2680 only has a powerdown input. But some ACPI tables still list +* 2 GPIOs for the OV2680 and it is unclear which to use. So try to get +* up to 2 GPIOs (1 mandatory, 1 optional) and control them in sync. +*/ +static const struct acpi_gpio_params ov2680_first_gpio = {0 ,0 , true }; +static const struct acpi_gpio_params ov2680_second_gpio = {1 ,0 , true }; + +static const struct acpi_gpio_mapping ov2680_gpio_mapping[] = { + {"powerdown-gpios" , &ov2680_first_gpio,1 }, + {"powerdown-alt-gpios" , &ov2680_second_gpio,1 }, + { }, +}; +static int ov2680_probe (struct i2c_client *client) {struct ov2680_device *sensor;int ret; -void *pdata; sensor =devm_kzalloc (&client->dev,sizeof (*sensor),GFP_KERNEL );if (!sensor)
@@ -797,18 +647,24 @@ static int ov2680_probe(struct i2c_client *client) sensor->client = client;v4l2_i2c_subdev_init (&sensor->sd, client, &ov2680_ops); - pdata =gmin_camera_platform_data (&sensor->sd, -ATOMISP_INPUT_FORMAT_RAW_10 , - atomisp_bayer_order_bggr); -if (!pdata) -return -EINVAL ; + ret =devm_acpi_dev_add_driver_gpios (&client->dev, ov2680_gpio_mapping); +if (ret) +return ret; + + sensor->powerdown =devm_gpiod_get (&client->dev,"powerdown" ,GPIOD_OUT_HIGH ); +if (IS_ERR (sensor->powerdown)) +return dev_err_probe (&client->dev,PTR_ERR (sensor->powerdown),"getting powerdown GPIO\n" ); + + sensor->powerdown_alt =devm_gpiod_get_optional (&client->dev,"powerdown-alt" ,GPIOD_OUT_HIGH ); +if (IS_ERR (sensor->powerdown_alt)) +return dev_err_probe (&client->dev,PTR_ERR (sensor->powerdown_alt),"getting powerdown-alt GPIO\n" );pm_runtime_set_suspended (&client->dev);pm_runtime_enable (&client->dev);pm_runtime_set_autosuspend_delay (&client->dev,1000 );pm_runtime_use_autosuspend (&client->dev); - ret =ov2680_s_config (&sensor->sd, client->irq, pdata); + ret =ov2680_s_config (&sensor->sd);if (ret)return ret;
@@ -830,7 +686,8 @@ static int ov2680_probe(struct i2c_client *client)ov2680_fill_format (sensor, &sensor->mode.fmt,OV2680_NATIVE_WIDTH ,OV2680_NATIVE_HEIGHT ); - ret =atomisp_register_i2c_module (&sensor->sd, pdata,RAW_CAMERA ); + ret =atomisp_register_sensor_no_gmin (&sensor->sd,1 ,ATOMISP_INPUT_FORMAT_RAW_10 , + atomisp_bayer_order_bggr);if (ret) {ov2680_remove (client);return ret;
@@ -842,15 +699,29 @@ static int ov2680_probe(struct i2c_client *client)static int ov2680_suspend (struct device *dev) {struct v4l2_subdev *sd =dev_get_drvdata (dev); +struct ov2680_device *sensor =to_ov2680_sensor (sd); -return power_down (sd); +gpiod_set_value_cansleep (sensor->powerdown,1 ); +gpiod_set_value_cansleep (sensor->powerdown_alt,1 ); +return 0 ; }static int ov2680_resume (struct device *dev) {struct v4l2_subdev *sd =dev_get_drvdata (dev); +struct ov2680_device *sensor =to_ov2680_sensor (sd); -return power_up (sd); +/* according to DS, at least 5ms is needed after DOVDD (enabled by ACPI) */ +usleep_range (5000 ,6000 ); + +gpiod_set_value_cansleep (sensor->powerdown,0 ); +gpiod_set_value_cansleep (sensor->powerdown_alt,0 ); + +/* according to DS, 20ms is needed between PWDN and i2c access */ +msleep (20 ); + +ov2680_init_registers (sd); +return 0 ; } static DEFINE_RUNTIME_DEV_PM_OPS(ov2680_pm_ops, ov2680_suspend, ov2680_resume, NULL);
drivers/staging/media/atomisp/i2c/ov2680.h +2 -1
@@ -119,7 +119,8 @@ struct ov2680_device {struct media_pad pad;struct mutex input_lock;struct i2c_client *client; -struct camera_sensor_platform_data *platform_data; +struct gpio_desc *powerdown; +struct gpio_desc *powerdown_alt;bool is_streaming;struct ov2680_mode {
Signature · 1 line
2.39.0
Re: [PATCH 50/57] media: atomisp: ov2680: Switch over to ACPI powermanagement
Quoted 19 lines · Hans de Goede
The DSDT of all Windows BYT / CHT devices which I have seen has proper ACPI powermagement for the clk and regulators used by the sensors.
So there is no need for the whole custom
atomisp_gmincustom code to disable the ACPI pm and directly poke at the PMIC for this.Replace all the
atomisp_gminusage with using the newatomisp_register_sensor_no_gmin()/atomisp_unregister_subdev()helpers which allow registering a sensor with the atomisp code without using any of theatomisp_gminpower-management code.Note eventually these calls should be replaced by the standard
v4l2_async_register_subdev_sensor()mechanism.But this first requires a bunch of work to the atomisp main code to make it set the necessary fwnodes up, similar to how
drivers/media/pci/intel/ipu3/cio2-bridge.cdoes this.This has been tested on:
Review
Quoted 3 lines
(quoted diff) +0
-3-Trekstor Surftab duo W1 10.1, CHT, AXP288 PMIC, 2x ov2680 sensor -Asus T101HA, CHT, TI PMIC, 1x ov2680 sensor -MPMAN Converter 9, BYT, AXP288 PMIC, ov2680 back, gc0310 front sensor
Very nice! Long waited change, thanks!
See below.
Quoted 224 lines
Signed-off-by Hans de Goede <[email protected]>--- .../media/atomisp/i2c/atomisp-ov2680.c | 231 ++++-------------- drivers/staging/media/atomisp/i2c/ov2680.h | 3 +- 2 files changed, 53 insertions(+), 181 deletions(-)drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +5
-169@@ -17,6 +17,8 @@#include <linux/acpi.h> #include <linux/device.h> +#include <linux/gpio/consumer.h> +#include <linux/gpio/machine.h> #include <linux/i2c.h> #include <linux/module.h> #include <linux/pm_runtime.h> @@ -184,145 +186,6 @@ static int ov2680_init_registers(struct v4l2_subdev *sd)return ret; } -static int power_ctrl (struct v4l2_subdev *sd,bool flag) -{ -int ret =0 ; -struct ov2680_device *dev =to_ov2680_sensor (sd); -struct i2c_client *client =v4l2_get_subdevdata (sd); - -if (!dev || !dev->platform_data) -return -ENODEV ; - -dev_dbg (&client->dev,"%s: %s" , __func__, flag ?"on" :"off" ); - -if (flag) { - ret |= dev->platform_data->v1p8_ctrl (sd,1 ); - ret |= dev->platform_data->v2p8_ctrl (sd,1 ); -usleep_range (10000 ,15000 ); - } - -if (!flag || ret) { - ret |= dev->platform_data->v1p8_ctrl (sd,0 ); - ret |= dev->platform_data->v2p8_ctrl (sd,0 ); - } -return ret; -} - -static int gpio_ctrl (struct v4l2_subdev *sd,bool flag) -{ -int ret; -struct ov2680_device *dev =to_ov2680_sensor (sd); - -if (!dev || !dev->platform_data) -return -ENODEV ; - -/* -* The OV2680 documents only one GPIO input (#XSHUTDN), but -* existing integrations often wire two (reset/power_down) -* because that is the way other sensors work. There is no -* way to tell how it is wired internally, so existing -* firmwares expose both and we drive them symmetrically. -*/ -if (flag) { - ret = dev->platform_data->gpio0_ctrl (sd,1 ); -usleep_range (10000 ,15000 ); -/* Ignore return from second gpio, it may not be there */ - dev->platform_data->gpio1_ctrl (sd,1 ); -usleep_range (10000 ,15000 ); - }else { - dev->platform_data->gpio1_ctrl (sd,0 ); - ret = dev->platform_data->gpio0_ctrl (sd,0 ); - } -return ret; -} - -static int power_up (struct v4l2_subdev *sd) -{ -struct ov2680_device *dev =to_ov2680_sensor (sd); -struct i2c_client *client =v4l2_get_subdevdata (sd); -int ret; - -if (!dev->platform_data) { -dev_err (&client->dev, -"no camera_sensor_platform_data" ); -return -ENODEV ; - } - -/* power control */ - ret =power_ctrl (sd,1 ); -if (ret) - goto fail_power; - -/* according to DS, at least 5ms is needed between DOVDD and PWDN */ -usleep_range (5000 ,6000 ); - -/* gpio ctrl */ - ret =gpio_ctrl (sd,1 ); -if (ret) { - ret =gpio_ctrl (sd,1 ); -if (ret) - goto fail_power; - } - -/* flis clock control */ - ret = dev->platform_data->flisclk_ctrl (sd,1 ); -if (ret) - goto fail_clk; - -/* according to DS, 20ms is needed between PWDN and i2c access */ -msleep (20 ); - - ret =ov2680_init_registers (sd); -if (ret) - goto fail_init_registers; - -return 0 ; - -fail_init_registers: - dev->platform_data->flisclk_ctrl (sd,0 ); -fail_clk: -gpio_ctrl (sd,0 ); -fail_power: -power_ctrl (sd,0 ); -dev_err (&client->dev,"sensor power-up failed\n" ); - -return ret; -} - -static int power_down (struct v4l2_subdev *sd) -{ -struct ov2680_device *dev =to_ov2680_sensor (sd); -struct i2c_client *client =v4l2_get_subdevdata (sd); -int ret =0 ; - -if (!dev->platform_data) { -dev_err (&client->dev, -"no camera_sensor_platform_data" ); -return -ENODEV ; - } - - ret = dev->platform_data->flisclk_ctrl (sd,0 ); -if (ret) -dev_err (&client->dev,"flisclk failed\n" ); - -/* gpio ctrl */ - ret =gpio_ctrl (sd,0 ); -if (ret) { - ret =gpio_ctrl (sd,0 ); -if (ret) -dev_err (&client->dev,"gpio failed 2\n" ); - } - -/* power control */ - ret =power_ctrl (sd,0 ); -if (ret) { -dev_err (&client->dev,"vprog failed.\n" ); -return ret; - } - -return 0 ; -} -static struct v4l2_mbus_framefmt * __ov2680_get_pad_format(struct ov2680_device *sensor, struct v4l2_subdev_state *state,@@ -593,20 +456,10 @@ static int ov2680_s_stream(struct v4l2_subdev *sd, int enable)return ret; } -static int ov2680_s_config (struct v4l2_subdev *sd, -int irq,void *platform_data) +static int ov2680_s_config (struct v4l2_subdev *sd) { -struct ov2680_device *sensor =to_ov2680_sensor (sd);struct i2c_client *client =v4l2_get_subdevdata (sd); -int ret =0 ; - -if (!platform_data) -return -ENODEV ; - - sensor->platform_data = - (struct camera_sensor_platform_data *)platform_data; - -mutex_lock (&sensor->input_lock); +int ret; ret =pm_runtime_get_sync (&client->dev);if (ret <0 ) {@@ -614,29 +467,13 @@ static int ov2680_s_config(struct v4l2_subdev *sd, goto fail_power_on; } - ret = sensor->platform_data->csi_cfg (sd,1 ); -if (ret) - goto fail_csi_cfg; -/* config & detect sensor */ ret =ov2680_detect (client); -if (ret) { +if (ret)dev_err (&client->dev,"ov2680_detect err s_config.\n" ); - goto fail_csi_cfg; - } -/* turn off sensor, after probed */ -pm_runtime_put (&client->dev); -mutex_unlock (&sensor->input_lock); - -return 0 ; - -fail_csi_cfg: - sensor->platform_data->csi_cfg (sd,0 ); fail_power_on:pm_runtime_put (&client->dev); -dev_err (&client->dev,"sensor power-gating failed\n" ); -mutex_unlock (&sensor->input_lock);return ret; }@@ -774,19 +611,32 @@ static void ov2680_remove(struct i2c_client *client)dev_dbg (&client->dev,"ov2680_remove...\n" ); - sensor->platform_data->csi_cfg (sd,0 );
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c static void ov2680_remove(struct i2c_client *client) · line 622
Quoted 10 lines
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +3
-1- +atomisp_unregister_subdev (sd);v4l2_device_unregister_subdev (sd);media_entity_cleanup (&sensor->sd.entity);v4l2_ctrl_handler_free (&sensor->ctrls.handler);pm_runtime_disable (&client->dev); } +/* +* Unlike other sensors which have both a rest and powerdown input pins,
reset ?
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c static void ov2680_remove(struct i2c_client *client)
Quoted 12 lines
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +11
-0+* the OV2680 only has a powerdown input. But some ACPI tables still list +* 2 GPIOs for the OV2680 and it is unclear which to use. So try to get +* up to 2 GPIOs (1 mandatory, 1 optional) and control them in sync. +*/ +static const struct acpi_gpio_params ov2680_first_gpio = {0 ,0 , true }; +static const struct acpi_gpio_params ov2680_second_gpio = {1 ,0 , true }; + +static const struct acpi_gpio_mapping ov2680_gpio_mapping[] = { + {"powerdown-gpios" , &ov2680_first_gpio,1 }, + {"powerdown-alt-gpios" , &ov2680_second_gpio,1 }, + { },
No comma for the terminator entry.
Quoted 20 lines
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +2
-1+}; +static int ov2680_probe (struct i2c_client *client) {struct ov2680_device *sensor;int ret; -void *pdata; sensor =devm_kzalloc (&client->dev,sizeof (*sensor),GFP_KERNEL );drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +1
-5if (!sensor)@@ -797,18 +647,24 @@ static int ov2680_probe(struct i2c_client *client) sensor->client = client;v4l2_i2c_subdev_init (&sensor->sd, client, &ov2680_ops); - pdata =gmin_camera_platform_data (&sensor->sd, -ATOMISP_INPUT_FORMAT_RAW_10 , - atomisp_bayer_order_bggr); -if (!pdata) -return -EINVAL ; + ret =devm_acpi_dev_add_driver_gpios (&client->dev, ov2680_gpio_mapping);
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c static int ov2680_probe(struct i2c_client *client) · line 660
Quoted 10 lines
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +10
-0+if (ret) +return ret; + + sensor->powerdown =devm_gpiod_get (&client->dev,"powerdown" ,GPIOD_OUT_HIGH ); +if (IS_ERR (sensor->powerdown)) +return dev_err_probe (&client->dev,PTR_ERR (sensor->powerdown),"getting powerdown GPIO\n" ); + + sensor->powerdown_alt =devm_gpiod_get_optional (&client->dev,"powerdown-alt" ,GPIOD_OUT_HIGH ); +if (IS_ERR (sensor->powerdown_alt)) +return dev_err_probe (&client->dev,PTR_ERR (sensor->powerdown_alt),"getting powerdown-alt GPIO\n" );
You may shorten these by
struct device *dev = &client->dev;
at the top of the function.
Quoted 29 lines
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +6
-3pm_runtime_set_suspended (&client->dev);pm_runtime_enable (&client->dev);pm_runtime_set_autosuspend_delay (&client->dev,1000 );pm_runtime_use_autosuspend (&client->dev); - ret =ov2680_s_config (&sensor->sd, client->irq, pdata); + ret =ov2680_s_config (&sensor->sd);if (ret)return ret;@@ -830,7 +686,8 @@ static int ov2680_probe(struct i2c_client *client)ov2680_fill_format (sensor, &sensor->mode.fmt,OV2680_NATIVE_WIDTH ,OV2680_NATIVE_HEIGHT ); - ret =atomisp_register_i2c_module (&sensor->sd, pdata,RAW_CAMERA ); + ret =atomisp_register_sensor_no_gmin (&sensor->sd,1 ,ATOMISP_INPUT_FORMAT_RAW_10 , + atomisp_bayer_order_bggr);if (ret) {ov2680_remove (client);return ret;@@ -842,15 +699,29 @@ static int ov2680_probe(struct i2c_client *client)static int ov2680_suspend (struct device *dev) {struct v4l2_subdev *sd =dev_get_drvdata (dev); +struct ov2680_device *sensor =to_ov2680_sensor (sd); -return power_down (sd); +gpiod_set_value_cansleep (sensor->powerdown,1 ); +gpiod_set_value_cansleep (sensor->powerdown_alt,1 );
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c static int ov2680_probe(struct i2c_client *client) · line 714
Quoted 10 lines
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +3
-1+return 0 ; }static int ov2680_resume (struct device *dev) {struct v4l2_subdev *sd =dev_get_drvdata (dev); +struct ov2680_device *sensor =to_ov2680_sensor (sd); -return power_up (sd); +/* according to DS, at least 5ms is needed after DOVDD (enabled by ACPI) */
datasheet (DS can be acronym of some [unknown?] person).
Quoted 30 lines
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +10
-0+usleep_range (5000 ,6000 ); + +gpiod_set_value_cansleep (sensor->powerdown,0 ); +gpiod_set_value_cansleep (sensor->powerdown_alt,0 ); + +/* according to DS, 20ms is needed between PWDN and i2c access */ +msleep (20 ); + +ov2680_init_registers (sd); +return 0 ; } static DEFINE_RUNTIME_DEV_PM_OPS(ov2680_pm_ops, ov2680_suspend, ov2680_resume, NULL);drivers/staging/media/atomisp/i2c/ov2680.h +2
-1@@ -119,7 +119,8 @@ struct ov2680_device {struct media_pad pad;struct mutex input_lock;struct i2c_client *client; -struct camera_sensor_platform_data *platform_data; +struct gpio_desc *powerdown; +struct gpio_desc *powerdown_alt;bool is_streaming;struct ov2680_mode {Signature · 1 line
2.39.0
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 51/57 media: atomisp: ov2722: Call atomisp_gmin_remove_subdev() on probe failure
In reply to Hans de GoedeCall atomisp_gmin_remove_subdev() on probe failure to properly free the GPIOs and other resources acquired by the gmin_camera_platform_data() call earlier.
--- drivers/staging/media/atomisp/i2c/atomisp-ov2722.c | 1 + 1 file changed, 1 insertion(+)
drivers/staging/media/atomisp/i2c/atomisp-ov2722.c +1 -0
@@ -994,6 +994,7 @@ static int ov2722_probe(struct i2c_client *client)v4l2_ctrl_handler_free (&dev->ctrl_handler); out_free: +atomisp_gmin_remove_subdev (&dev->sd);v4l2_device_unregister_subdev (&dev->sd);kfree (dev);return ret;
Signature · 1 line
2.39.0
Re: [PATCH 51/57] media: atomisp: ov2722: Call atomisp_gmin_remove_subdev() on probe failure
Quoted 3 lines · Hans de Goede
Call
atomisp_gmin_remove_subdev()on probe failure to properly free the GPIOs and other resources acquired by thegmin_camera_platform_data()call earlier.
Fixes?
Quoted 20 lines
Signed-off-by Hans de Goede <[email protected]>--- drivers/staging/media/atomisp/i2c/atomisp-ov2722.c | 1 + 1 file changed, 1 insertion(+)drivers/staging/media/atomisp/i2c/atomisp-ov2722.c +1
-0@@ -994,6 +994,7 @@ static int ov2722_probe(struct i2c_client *client)v4l2_ctrl_handler_free (&dev->ctrl_handler); out_free: +atomisp_gmin_remove_subdev (&dev->sd);v4l2_device_unregister_subdev (&dev->sd);kfree (dev);return ret;Signature · 1 line
2.39.0
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 52/57 media: atomisp: ov2722: Fix GPIO1 polarity
In reply to Hans de GoedeThe comment claims the PWDN pin is active when pulled down in other words, it is /power-down so it needs to be driven high to get the sensor powered-up (not powered down) and flag is 1 when powering-up the sensor so the ! is wrong, drop it.
This also matches with the schematics which I have which shows GPIO1 also enables a 3.3v line to the sensor-module which controls the privacy-LED and indeed before this patch the privacy LED was inverted from what it should be (and the sensor did not work).
--- drivers/staging/media/atomisp/i2c/atomisp-ov2722.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/staging/media/atomisp/i2c/atomisp-ov2722.c +1 -4
@@ -512,10 +512,7 @@ static int gpio_ctrl(struct v4l2_subdev *sd, bool flag)* before PWDN# when turning it on or off. */ ret = dev->platform_data->gpio0_ctrl (sd, flag); -/* -*ov2722 PWDN# active high when pull down,opposite to the convention -*/ - ret |= dev->platform_data->gpio1_ctrl (sd, !flag); + ret |= dev->platform_data->gpio1_ctrl (sd, flag);return ret; }
Signature · 1 line
2.39.0
Andy Shevchenko
maintainerRe: [PATCH 52/57] media: atomisp: ov2722: Fix GPIO1 polarity
Quoted 9 lines · Hans de Goede
The comment claims the PWDN pin is active when pulled down in other words, it is /power-down so it needs to be driven high to get the sensor powered-up (not powered down) and flag is 1 when powering-up the sensor so the ! is wrong, drop it.
This also matches with the schematics which I have which shows GPIO1 also enables a 3.3v line to the sensor-module which controls the privacy-LED and indeed before this patch the privacy LED was inverted from what it should be (and the sensor did not work).
It's unclear if this is logical state or raw one? Maybe this the root cause of the initial confusion?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 52/57] media: atomisp: ov2722: Fix GPIO1 polarity
In reply to Hans de GoedeQuoted 9 lines · Hans de Goede
The comment claims the PWDN pin is active when pulled down in other words, it is /power-down so it needs to be driven high to get the sensor powered-up (not powered down) and flag is 1 when powering-up the sensor so the ! is wrong, drop it.
This also matches with the schematics which I have which shows GPIO1 also enables a 3.3v line to the sensor-module which controls the privacy-LED and indeed before this patch the privacy LED was inverted from what it should be (and the sensor did not work).
Code-wise it's okay
Quoted 24 lines
Signed-off-by Hans de Goede <[email protected]>--- drivers/staging/media/atomisp/i2c/atomisp-ov2722.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)drivers/staging/media/atomisp/i2c/atomisp-ov2722.c +1
-4@@ -512,10 +512,7 @@ static int gpio_ctrl(struct v4l2_subdev *sd, bool flag)* before PWDN# when turning it on or off. */ ret = dev->platform_data->gpio0_ctrl (sd, flag); -/* -*ov2722 PWDN# active high when pull down,opposite to the convention -*/ - ret |= dev->platform_data->gpio1_ctrl (sd, !flag); + ret |= dev->platform_data->gpio1_ctrl (sd, flag);return ret; }Signature · 1 line
2.39.0
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 53/57 media: atomisp: ov2722: Don't take the input_lock for try_fmt calls.
In reply to Hans de GoedeOn ov2722_set_fmt() calls with format->which == V4L2_SUBDEV_FORMAT_TRY, ov2722_set_fmt() does not talk to the sensor, so there is no need to lock the dev->input_lock mutex in this case.
--- drivers/staging/media/atomisp/i2c/atomisp-ov2722.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/media/atomisp/i2c/atomisp-ov2722.c +1 -2
@@ -651,7 +651,6 @@ static int ov2722_set_fmt(struct v4l2_subdev *sd,if (!ov2722_info)return -EINVAL ; -mutex_lock (&dev->input_lock); res =v4l2_find_nearest_size (ov2722_res_preview,ARRAY_SIZE (ov2722_res_preview), width, height, fmt->width, fmt->height);
@@ -665,10 +664,10 @@ static int ov2722_set_fmt(struct v4l2_subdev *sd, fmt->code =MEDIA_BUS_FMT_SGRBG10_1X10 ;if (format->which ==V4L2_SUBDEV_FORMAT_TRY ) { sd_state->pads->try_fmt = *fmt; -mutex_unlock (&dev->input_lock);return 0 ; } +mutex_lock (&dev->input_lock); dev->pixels_per_line = dev->res->pixels_per_line; dev->lines_per_frame = dev->res->lines_per_frame;
Signature · 1 line
2.39.0
Re: [PATCH 53/57] media: atomisp: ov2722: Don't take the input_lock for try_fmt calls.
Quoted 3 lines · Hans de Goede
On
ov2722_set_fmt()calls withformat->which==V4L2_SUBDEV_FORMAT_TRY,ov2722_set_fmt()does not talk to the sensor, so there is no need to lock thedev->input_lockmutex in this case.
Quoted 32 lines
Signed-off-by Hans de Goede <[email protected]>--- drivers/staging/media/atomisp/i2c/atomisp-ov2722.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/staging/media/atomisp/i2c/atomisp-ov2722.c +1
-2@@ -651,7 +651,6 @@ static int ov2722_set_fmt(struct v4l2_subdev *sd,if (!ov2722_info)return -EINVAL ; -mutex_lock (&dev->input_lock); res =v4l2_find_nearest_size (ov2722_res_preview,ARRAY_SIZE (ov2722_res_preview), width, height, fmt->width, fmt->height);@@ -665,10 +664,10 @@ static int ov2722_set_fmt(struct v4l2_subdev *sd, fmt->code =MEDIA_BUS_FMT_SGRBG10_1X10 ;if (format->which ==V4L2_SUBDEV_FORMAT_TRY ) { sd_state->pads->try_fmt = *fmt; -mutex_unlock (&dev->input_lock);return 0 ; } +mutex_lock (&dev->input_lock); dev->pixels_per_line = dev->res->pixels_per_line; dev->lines_per_frame = dev->res->lines_per_frame;Signature · 1 line
2.39.0
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 54/57 media: atomisp: ov2722: Power on sensor from set_fmt() callback
In reply to Hans de GoedeDepending on which order userspace makes various v4l2 calls, the sensor might still be powered down when set_fmt is called.
What should really happen here is delay the writing of the mode-related registers till streaming is started, but for now use the same quick fix as the atomisp_ov2680 / atomisp_gc0310 code and call power_up() from set_fmt() in combination with keeping track of the power-state to avoid doing the power-up sequence twice.
--- drivers/staging/media/atomisp/i2c/atomisp-ov2722.c | 12 ++++++++++++ drivers/staging/media/atomisp/i2c/ov2722.h | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-)
drivers/staging/media/atomisp/i2c/atomisp-ov2722.c +12 -0
@@ -528,6 +528,9 @@ static int power_up(struct v4l2_subdev *sd)return -ENODEV ; } +if (dev->power_on ==1 ) +return 0 ;/* Already on */ +/* power control */ ret =power_ctrl (sd,1 );if (ret)
@@ -552,6 +555,7 @@ static int power_up(struct v4l2_subdev *sd)/* according to DS, 20ms is needed between PWDN and i2c access */ msleep (20 ); + dev->power_on =1 ;return 0 ; fail_clk:
@@ -575,6 +579,9 @@ static int power_down(struct v4l2_subdev *sd)return -ENODEV ; } +if (dev->power_on ==0 ) +return 0 ;/* Already off */ + ret = dev->platform_data->flisclk_ctrl (sd,0 );if (ret)dev_err (&client->dev,"flisclk failed\n" );
@@ -592,6 +599,7 @@ static int power_down(struct v4l2_subdev *sd)if (ret)dev_err (&client->dev,"vprog failed.\n" ); + dev->power_on =0 ;return ret; }
@@ -669,6 +677,9 @@ static int ov2722_set_fmt(struct v4l2_subdev *sd,mutex_lock (&dev->input_lock); +/* s_power has not been called yet for std v4l2 clients (camorama) */ +power_up (sd); + dev->pixels_per_line = dev->res->pixels_per_line; dev->lines_per_frame = dev->res->lines_per_frame;
@@ -959,6 +970,7 @@ static int ov2722_probe(struct i2c_client *client)return -ENOMEM ;mutex_init (&dev->input_lock); + dev->power_on =-1 ; dev->res = &ov2722_res_preview[0 ];v4l2_i2c_subdev_init (&dev->sd, client, &ov2722_ops);
drivers/staging/media/atomisp/i2c/ov2722.h +1 -1
@@ -198,7 +198,7 @@ struct ov2722_device {struct ov2722_resolution *res;struct camera_sensor_platform_data *platform_data; -int run_mode; +int power_on;u16 pixels_per_line;u16 lines_per_frame;u8 type;
Signature · 1 line
2.39.0
Re: [PATCH 54/57] media: atomisp: ov2722: Power on sensor from set_fmt() callback
Quoted 8 lines · Hans de Goede
Depending on which order userspace makes various v4l2 calls, the sensor might still be powered down when
set_fmtis called.What should really happen here is delay the writing of the mode-related registers till streaming is started, but for now use the same quick fix as the
atomisp_ov2680/atomisp_gc0310code and callpower_up()fromset_fmt()in combination with keeping track of the power-state to avoid doing the power-up sequence twice.
OK.
Is there a plan to drop this hack from all of the (AtomISP) sensor drivers?
Quoted 80 lines
Signed-off-by Hans de Goede <[email protected]>--- drivers/staging/media/atomisp/i2c/atomisp-ov2722.c | 12 ++++++++++++ drivers/staging/media/atomisp/i2c/ov2722.h | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-)drivers/staging/media/atomisp/i2c/atomisp-ov2722.c +12
-0@@ -528,6 +528,9 @@ static int power_up(struct v4l2_subdev *sd)return -ENODEV ; } +if (dev->power_on ==1 ) +return 0 ;/* Already on */ +/* power control */ ret =power_ctrl (sd,1 );if (ret)@@ -552,6 +555,7 @@ static int power_up(struct v4l2_subdev *sd)/* according to DS, 20ms is needed between PWDN and i2c access */ msleep (20 ); + dev->power_on =1 ;return 0 ; fail_clk:@@ -575,6 +579,9 @@ static int power_down(struct v4l2_subdev *sd)return -ENODEV ; } +if (dev->power_on ==0 ) +return 0 ;/* Already off */ + ret = dev->platform_data->flisclk_ctrl (sd,0 );if (ret)dev_err (&client->dev,"flisclk failed\n" );@@ -592,6 +599,7 @@ static int power_down(struct v4l2_subdev *sd)if (ret)dev_err (&client->dev,"vprog failed.\n" ); + dev->power_on =0 ;return ret; }@@ -669,6 +677,9 @@ static int ov2722_set_fmt(struct v4l2_subdev *sd,mutex_lock (&dev->input_lock); +/* s_power has not been called yet for std v4l2 clients (camorama) */ +power_up (sd); + dev->pixels_per_line = dev->res->pixels_per_line; dev->lines_per_frame = dev->res->lines_per_frame;@@ -959,6 +970,7 @@ static int ov2722_probe(struct i2c_client *client)return -ENOMEM ;mutex_init (&dev->input_lock); + dev->power_on =-1 ; dev->res = &ov2722_res_preview[0 ];v4l2_i2c_subdev_init (&dev->sd, client, &ov2722_ops);drivers/staging/media/atomisp/i2c/ov2722.h +1
-1@@ -198,7 +198,7 @@ struct ov2722_device {struct ov2722_resolution *res;struct camera_sensor_platform_data *platform_data; -int run_mode; +int power_on;u16 pixels_per_line;u16 lines_per_frame;u8 type;Signature · 1 line
2.39.0
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 54/57] media: atomisp: ov2722: Power on sensor from set_fmt() callback
Hi,
Quoted 10 lines · Andy Shevchenko
Quoted 8 lines · Hans de Goede
Depending on which order userspace makes various v4l2 calls, the sensor might still be powered down when
set_fmtis called.What should really happen here is delay the writing of the mode-related registers till streaming is started, but for now use the same quick fix as the
atomisp_ov2680/atomisp_gc0310code and callpower_up()fromset_fmt()in combination with keeping track of the power-state to avoid doing the power-up sequence twice.
Quoted 4 lines
OK.
Reviewed-by Andy Shevchenko <[email protected]>Is there a plan to drop this hack from all of the (AtomISP) sensor drivers?
Yes this is the next one on my list to convert to runtime-pm + ACPI powermanagement. Which needs to be done on a sensor by sensor basis :|
Regards,
Hans
Quoted 82 lines
Quoted 81 lines
Signed-off-by Hans de Goede <[email protected]>--- drivers/staging/media/atomisp/i2c/atomisp-ov2722.c | 12 ++++++++++++ drivers/staging/media/atomisp/i2c/ov2722.h | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-)drivers/staging/media/atomisp/i2c/atomisp-ov2722.c +12
-0@@ -528,6 +528,9 @@ static int power_up(struct v4l2_subdev *sd)return -ENODEV ; } +if (dev->power_on ==1 ) +return 0 ;/* Already on */ +/* power control */ ret =power_ctrl (sd,1 );if (ret)@@ -552,6 +555,7 @@ static int power_up(struct v4l2_subdev *sd)/* according to DS, 20ms is needed between PWDN and i2c access */ msleep (20 ); + dev->power_on =1 ;return 0 ; fail_clk:@@ -575,6 +579,9 @@ static int power_down(struct v4l2_subdev *sd)return -ENODEV ; } +if (dev->power_on ==0 ) +return 0 ;/* Already off */ + ret = dev->platform_data->flisclk_ctrl (sd,0 );if (ret)dev_err (&client->dev,"flisclk failed\n" );@@ -592,6 +599,7 @@ static int power_down(struct v4l2_subdev *sd)if (ret)dev_err (&client->dev,"vprog failed.\n" ); + dev->power_on =0 ;return ret; }@@ -669,6 +677,9 @@ static int ov2722_set_fmt(struct v4l2_subdev *sd,mutex_lock (&dev->input_lock); +/* s_power has not been called yet for std v4l2 clients (camorama) */ +power_up (sd); + dev->pixels_per_line = dev->res->pixels_per_line; dev->lines_per_frame = dev->res->lines_per_frame;@@ -959,6 +970,7 @@ static int ov2722_probe(struct i2c_client *client)return -ENOMEM ;mutex_init (&dev->input_lock); + dev->power_on =-1 ; dev->res = &ov2722_res_preview[0 ];v4l2_i2c_subdev_init (&dev->sd, client, &ov2722_ops);drivers/staging/media/atomisp/i2c/ov2722.h +1
-1@@ -198,7 +198,7 @@ struct ov2722_device {struct ov2722_resolution *res;struct camera_sensor_platform_data *platform_data; -int run_mode; +int power_on;u16 pixels_per_line;u16 lines_per_frame;u8 type;Signature · 1 line
2.39.0
PATCH 55/57 media: atomisp: pci: Replace bytes macros with functions
In reply to Hans de GoedeFrom: Brent Pappas <[email protected]>
Replace the function-like macros FPNTBL_BYTES(), SCTBL_BYTES(), and MORPH_PLANE_BYTES() with functions to comply with Linux coding style standards.
Replace multiplication with calls to array_size() and array3_size() to prevent accidental arithmetic overflow.
--- .../staging/media/atomisp/pci/sh_css_params.c | 38 +++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-)
drivers/staging/media/atomisp/pci/sh_css_params.c +23 -15
@@ -98,17 +98,27 @@#include "sh_css_frac.h" #include "ia_css_bufq.h" -#define FPNTBL_BYTES (binary) \ - (sizeof(char) * (binary)->in_frame_info.res.height * \ - (binary)->in_frame_info.padded_width) +static size_t fpntbl_bytes (const struct ia_css_binary *binary) +{ +return array3_size (sizeof (char ), + binary->in_frame_info.res.height, + binary->in_frame_info.padded_width); +} -#define SCTBL_BYTES (binary) \ - (sizeof(unsigned short) * (binary)->sctbl_height * \ - (binary)->sctbl_aligned_width_per_color * IA_CSS_SC_NUM_COLORS) +static size_t sctbl_bytes (const struct ia_css_binary *binary) +{ +return size_mul (sizeof (unsigned short ), +array3_size (binary->sctbl_height, + binary->sctbl_aligned_width_per_color, +IA_CSS_SC_NUM_COLORS )); +} -#define MORPH_PLANE_BYTES (binary) \ - (SH_CSS_MORPH_TABLE_ELEM_BYTES * (binary)->morph_tbl_aligned_width * \ - (binary)->morph_tbl_height) +static size_t morph_plane_bytes (const struct ia_css_binary *binary) +{ +return array3_size (SH_CSS_MORPH_TABLE_ELEM_BYTES , + binary->morph_tbl_aligned_width, + binary->morph_tbl_height); +}/* We keep a second copy of the ptr struct for the SP to access. Again, this would not be necessary on the chip. */
@@ -3279,7 +3289,7 @@ sh_css_params_write_to_ddr_internal(if (binary->info->sp.enable.fpnr) { buff_realloced =reallocate_buffer (&ddr_map->fpn_tbl, &ddr_map_size->fpn_tbl, - (size_t )(FPNTBL_BYTES (binary)), +fpntbl_bytes (binary), params->config_changed[IA_CSS_FPN_ID ], &err);if (err) {
@@ -3304,7 +3314,7 @@ sh_css_params_write_to_ddr_internal( buff_realloced =reallocate_buffer (&ddr_map->sc_tbl, &ddr_map_size->sc_tbl, -SCTBL_BYTES (binary), +sctbl_bytes (binary), params->sc_table_changed, &err);if (err) {
@@ -3538,8 +3548,7 @@ sh_css_params_write_to_ddr_internal( buff_realloced |=reallocate_buffer (virt_addr_tetra_x[i], virt_size_tetra_x[i], - (size_t ) - (MORPH_PLANE_BYTES (binary)), +morph_plane_bytes (binary), params->morph_table_changed, &err);if (err) {
@@ -3549,8 +3558,7 @@ sh_css_params_write_to_ddr_internal( buff_realloced |=reallocate_buffer (virt_addr_tetra_y[i], virt_size_tetra_y[i], - (size_t ) - (MORPH_PLANE_BYTES (binary)), +morph_plane_bytes (binary), params->morph_table_changed, &err);if (err) {
Signature · 1 line
2.39.0
PATCH 56/57 media: atomisp: pci: hive_isp_css_common: host: vmem: Replace SUBWORD macros with functions
In reply to Hans de GoedeFrom: Brent Pappas <[email protected]>
Replace the macros SUBWORD() and INV_SUBWORD() with functions to comply with Linux coding style standards.
--- .../pci/hive_isp_css_common/host/vmem.c | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
drivers/staging/media/atomisp/pci/hive_isp_css_common/host/vmem.c +14 -6
@@ -28,10 +28,18 @@ typedef hive_uedge *hive_wide;/* Copied from SDK: sim_semantics.c */ /* subword bits move like this: MSB[____xxxx____]LSB -> MSB[00000000xxxx]LSB */ -#define SUBWORD (w, start, end) (((w) & (((1ULL << ((end) - 1)) - 1) << 1 | 1)) >> (start)) +static inline hive_uedge +subword (hive_uedge w,unsigned int start,unsigned int end) +{ +return (w & (((1ULL << (end -1 )) -1 ) <<1 |1 )) >> start; +}/* inverse subword bits move like this: MSB[xxxx____xxxx]LSB -> MSB[xxxx0000xxxx]LSB */ -#define INV_SUBWORD (w, start, end) ((w) & (~(((1ULL << ((end) - 1)) - 1) << 1 | 1) | ((1ULL << (start)) - 1))) +static inline hive_uedge +inv_subword (hive_uedge w,unsigned int start,unsigned int end) +{ +return w & (~(((1ULL << (end -1 )) -1 ) <<1 |1 ) | ((1ULL << start) -1 )); +}#define uedge_bits (8 * sizeof(hive_uedge))#define move_lower_bits (target, target_bit, src, src_bit) move_subword(target, target_bit, src, 0, src_bit)
@@ -50,18 +58,18 @@ move_subword(unsigned int start_bit = target_bit % uedge_bits;unsigned int subword_width = src_end - src_start; -hive_uedge src_subword =SUBWORD (src, src_start, src_end); +hive_uedge src_subword =subword (src, src_start, src_end);if (subword_width + start_bit > uedge_bits) {/* overlap */ hive_uedge old_val1; -hive_uedge old_val0 =INV_SUBWORD (target[start_elem], start_bit, uedge_bits); +hive_uedge old_val0 =inv_subword (target[start_elem], start_bit, uedge_bits); target[start_elem] = old_val0 | (src_subword << start_bit); - old_val1 =INV_SUBWORD (target[start_elem +1 ],0 , + old_val1 =inv_subword (target[start_elem +1 ],0 , subword_width + start_bit - uedge_bits); target[start_elem +1 ] = old_val1 | (src_subword >> (uedge_bits - start_bit)); }else { -hive_uedge old_val =INV_SUBWORD (target[start_elem], start_bit, +hive_uedge old_val =inv_subword (target[start_elem], start_bit, start_bit + subword_width); target[start_elem] = old_val | (src_subword << start_bit);
Signature · 1 line
2.39.0
Andy Shevchenko
maintainerRe: [PATCH 56/57] media: atomisp: pci: hive_isp_css_common: host: vmem: Replace SUBWORD macros with functions
Quoted 4 lines · Hans de Goede
From: Brent Pappas <[email protected]>
Replace the macros
SUBWORD()andINV_SUBWORD()with functions to comply with Linux coding style standards.
...
Quoted 5 lines
drivers/staging/media/atomisp/pci/hive_isp_css_common/host/vmem.c +5
-0+static inline hive_uedge +subword (hive_uedge w,unsigned int start,unsigned int end) +{ +return (w & (((1ULL << (end -1 )) -1 ) <<1 |1 )) >> start; +}
...
drivers/staging/media/atomisp/pci/hive_isp_css_common/host/vmem.c typedef hive_uedge *hive_wide; · line 42
Quoted 5 lines
drivers/staging/media/atomisp/pci/hive_isp_css_common/host/vmem.c +5
-0+static inline hive_uedge +inv_subword (hive_uedge w,unsigned int start,unsigned int end) +{ +return w & (~(((1ULL << (end -1 )) -1 ) <<1 |1 ) | ((1ULL << start) -1 )); +}
...
Brent, maybe you can look at these deeply and convert them to use GENMASK() instead? (It can be done as a followup patch, this one is fine)
Signature · 2 lines
With Best Regards, Andy Shevchenko
Andy Shevchenko
maintainerRe: [PATCH 56/57] media: atomisp: pci: hive_isp_css_common: host: vmem: Replace SUBWORD macros with functions
Quoted 5 lines · Andy Shevchenko
Quoted 4 lines · Hans de Goede
From: Brent Pappas <[email protected]>
Replace the macros
SUBWORD()andINV_SUBWORD()with functions to comply with Linux coding style standards.
...
Quoted 16 lines
Quoted 5 lines
drivers/staging/media/atomisp/pci/hive_isp_css_common/host/vmem.c +5
-0+static inline hive_uedge +subword (hive_uedge w,unsigned int start,unsigned int end) +{ +return (w & (((1ULL << (end -1 )) -1 ) <<1 |1 )) >> start; +}...
Quoted 5 lines
drivers/staging/media/atomisp/pci/hive_isp_css_common/host/vmem.c +5
-0+static inline hive_uedge +inv_subword (hive_uedge w,unsigned int start,unsigned int end) +{ +return w & (~(((1ULL << (end -1 )) -1 ) <<1 |1 ) | ((1ULL << start) -1 )); +}...
Quoted 2 lines
Brent, maybe you can look at these deeply and convert them to use
GENMASK()instead? (It can be done as a followup patch, this one is fine)
Note, with such conversion done you may kill these macros and use GENMASK() inline.
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 57/57 media: atomisp: pci: sh_css: Inline single invocation of macro STATS_ENABLED()
In reply to Hans de GoedeFrom: Brent Pappas <[email protected]>
Inline the single invocation of the macro STATS_ENABLED().
The macro abstraction is not necessary because the logic behind it is only used once.
--- drivers/staging/media/atomisp/pci/sh_css.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/staging/media/atomisp/pci/sh_css.c +3 -4
@@ -97,9 +97,6 @@*/ #define JPEG_BYTES (16 * 1024 * 1024) -#define STATS_ENABLED (stage) (stage && stage->binary && stage->binary->info && \ - (stage->binary->info->sp.enable.s3a || stage->binary->info->sp.enable.dis)) -struct sh_css my_css; int __printf(1, 0) (*sh_css_printf)(const char *fmt, va_list args) = NULL;
@@ -3743,7 +3740,9 @@ ia_css_pipe_enqueue_buffer(struct ia_css_pipe *pipe,* The SP will read the params after it got * empty 3a and dis */ -if (STATS_ENABLED (stage)) { +if (stage->binary && stage->binary->info && + (stage->binary->info->sp.enable.s3a || + stage->binary->info->sp.enable.dis)) {/* there is a stage that needs it */ return_err = ia_css_bufq_enqueue_buffer(thread_id, queue_id,
Signature · 1 line
2.39.0
Andy Shevchenko
maintainerQuoted 30 lines · Hans de Goede
Hi All,
Here is another set of patches resulting from my continued work on cleaning up / improving the atomisp driver.
The main changes here are power-management related, divided into 2 sets:
1. Move the pm of the core atomisp device to its own custom PM domain. We turn the ISP on/off through the P-Unit and when off the PCI subsystem resume method complains about the PCI config space not being reachable. Changing to a custom PM domain fixes the logs getting filled with PCI subsys errors on every open of a /dev/video# node
2. Except for devices shipped with Android as factory image, all the DSDTs I have seen have proper ACPI pm code for the sensors. So we really should be using ACPI pm for this.
This series contains a lot of ov2680 patches, including reworking the controls (so that control changes can be delayed to stream on time instead of directly trying to do i2c writes to the turned off sensor). Basically modernizing the ov2680 driver a lot (there are still some atomisp-isms left).
And then finally after all the ov2680 cleanups it moves the ov2680 code over to using runtime-pm + ACPI pm, dropping all the direct PMIC + clk poking done by the
atomisp_gmin_platformcode.
Quoted 5 lines
Besides that this also contains quite a few other fixes / cleanups for things which I encountered during the way and it contains the start of making the ov2722 driver work. With the changes present in that driver I get a working (but very dark) stream. I expect that once I add a proper exposure control this will start working
The non-commented patches were reviewed, but I'm not so familiar with the details of the functionality of the PM parts there. So I left them for others to review.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi Andy,
Quoted 37 lines · Andy Shevchenko
Quoted 30 lines · Hans de Goede
Hi All,
Here is another set of patches resulting from my continued work on cleaning up / improving the atomisp driver.
The main changes here are power-management related, divided into 2 sets:
1. Move the pm of the core atomisp device to its own custom PM domain. We turn the ISP on/off through the P-Unit and when off the PCI subsystem resume method complains about the PCI config space not being reachable. Changing to a custom PM domain fixes the logs getting filled with PCI subsys errors on every open of a /dev/video# node
2. Except for devices shipped with Android as factory image, all the DSDTs I have seen have proper ACPI pm code for the sensors. So we really should be using ACPI pm for this.
This series contains a lot of ov2680 patches, including reworking the controls (so that control changes can be delayed to stream on time instead of directly trying to do i2c writes to the turned off sensor). Basically modernizing the ov2680 driver a lot (there are still some atomisp-isms left).
And then finally after all the ov2680 cleanups it moves the ov2680 code over to using runtime-pm + ACPI pm, dropping all the direct PMIC + clk poking done by the
atomisp_gmin_platformcode.Quoted 5 lines
Besides that this also contains quite a few other fixes / cleanups for things which I encountered during the way and it contains the start of making the ov2722 driver work. With the changes present in that driver I get a working (but very dark) stream. I expect that once I add a proper exposure control this will start working
Quoted 3 lines
The non-commented patches were reviewed, but I'm not so familiar with the details of the functionality of the PM parts there. So I left them for others to review.
Thank you very much for reviewing this monster series!
I agree with all your code remarks / requested changes.
I'll make this changes in my personal tree and then prepare a pull-req for Mauro with the updated patches.
I'll go over the couple of cases where you had questions about things now.
I'll process the requested code changes (and add your Reviewed-by-s) when I can make some time to work on this later this week.
Regards,
Hans