summaryrefslogtreecommitdiffstats
path: root/drivers/media/i2c/imx274.c
AgeCommit message (Collapse)AuthorFilesLines
2019-03-01media: i2c: fix several typosMauro Carvalho Chehab1-2/+2
Use codespell to fix lots of typos over frontends. Manually verified to avoid false-positives. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2019-01-25media: imx274: remote unused function imx274_read_regLuca Ceresoli1-18/+0
imx274_read_reg() is not used since commit ca017467c78b ("media: imx274: add helper to read multibyte registers"). Signed-off-by: Luca Ceresoli <luca@lucaceresoli.net> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2019-01-16media: imx274: fix wrong order in test pattern menusLuca Ceresoli1-1/+1
The description of test patterns 11 and 12 are swapped. Checked against the live sensor. Signed-off-by: Luca Ceresoli <luca@lucaceresoli.net> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2018-12-05media: imx274: declare the correct number of controlsLuca Ceresoli1-1/+1
v4l2_ctrl_handler_init() expects a hint of how many controls this handler is expected to refer to. Since this number here is always 4, let's pass exactly 4. Signed-off-by: Luca Ceresoli <luca@lucaceresoli.net> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2018-12-05media: imx274: fix stack corruption in imx274_read_regLuca Ceresoli1-2/+5
imx274_read_reg() takes a u8 pointer ("reg") and casts it to pass it to regmap_read(), which takes an unsigned int pointer. This results in a corrupted stack and random crashes. Fixes: 0985dd306f72 ("media: imx274: V4l2 driver for Sony imx274 CMOS sensor") Cc: stable@vger.kernel.org # for 4.15 and up Signed-off-by: Luca Ceresoli <luca@lucaceresoli.net> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2018-09-17media: imx274: switch to SPDX license identifierLuca Ceresoli1-12/+1
Signed-off-by: Luca Ceresoli <luca@lucaceresoli.net> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2018-09-17media: imx274: add helper to read multibyte registersLuca Ceresoli1-46/+47
Currently 2-bytes and 3-bytes registers are read one byte at a time, doing the needed shift & mask each time. Replace all of this code by a unique helper function that calls regmap_bulk_read(), which has two advantages: - reads all the bytes in a unique I2C transaction - simplifies code to read multibyte registers Signed-off-by: Luca Ceresoli <luca@lucaceresoli.net> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2018-09-17media: imx274: fix error in function docsLuca Ceresoli1-1/+1
This parameter holds the number of bytes, not bits. Signed-off-by: Luca Ceresoli <luca@lucaceresoli.net> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2018-09-17media: imx274: rename frmfmt and format to "mode"Luca Ceresoli1-9/+9
A mix of "mode", "format" and "frmfmt" is used to refer to the sensor readout mode. Use the term "mode" for all of them. Now "format" is only used in the V4L2 meaning. Signed-off-by: Luca Ceresoli <luca@lucaceresoli.net> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2018-09-17media: imx274: don't hard-code the subdev name to DRIVER_NAMELuca Ceresoli1-1/+0
Forcibly setting the subdev name to DRIVER_NAME (i.e. "IMX274") makes it non-unique and less informative. Let the driver use the default name from i2c, e.g. "IMX274 2-001a". Signed-off-by: Luca Ceresoli <luca@lucaceresoli.net> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2018-09-17media: imx274: rearrange sensor startup register tablesLuca Ceresoli1-23/+13
Rearrange the imx274_start_<N> register tables to better match the datasheet and slightly simplify code: - collapes tables 1 and 2, they are applied one after each other and together they implement the fixed part 1 of the startup procedure in the datasheet - while there, cleanup comments - rename tables 3 and 4 -> 2 and 3, coherently with the datasheet Signed-off-by: Luca Ceresoli <luca@lucaceresoli.net> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2018-09-17media: imx274: rename IMX274_DEFAULT_MODE to IMX274_DEFAULT_BINNINGLuca Ceresoli1-2/+2
The "mode" has been renamed to "binning" in commit 39dd23dc9d4c ("media: imx274: add cropping support via SELECTION API"), but this define has not been updated. Signed-off-by: Luca Ceresoli <luca@lucaceresoli.net> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2018-09-11media: use strscpy() instead of strlcpy()Mauro Carvalho Chehab1-1/+1
The implementation of strscpy() is more robust and safer. That's now the recommended way to copy NUL terminated strings. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> Reviewed-by: Kees Cook <keescook@chromium.org> Acked-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2018-07-27media: imx274: add cropping support via SELECTION APILuca Ceresoli1-91/+375
Currently this driver does not support cropping. The supported modes are the following, all capturing the entire area: - 3840x2160, 1:1 binning (native sensor resolution) - 1920x1080, 2:1 binning - 1280x720, 3:1 binning The VIDIOC_SUBDEV_S_FMT ioctl chooses among these 3 configurations the one that matches the requested format. Add cropping support via VIDIOC_SUBDEV_S_SELECTION: with target V4L2_SEL_TGT_CROP to choose the captured area, with V4L2_SEL_TGT_COMPOSE to choose the output resolution. To maintain backward compatibility we also allow setting the compose format via VIDIOC_SUBDEV_S_FMT. To obtain this, compose rect and output format are computed in the common helper function __imx274_change_compose(), which sets both to the same width/height values. Cropping also calls __imx274_change_compose() whenever cropping rect size changes in order to reset the compose rect (and output format size) for 1:1 binning. Also rename enum imx274_mode to imx274_binning (and its values from IMX274_MODE_BINNING_* to IMX274_BINNING_*). Without cropping, the two naming are equivalent. With cropping, the resolution could be different, e.g. using 2:1 binning mode to crop 1200x960 and output a 600x480 format. Using binning in the names avoids any misunderstanding. For the same reason, replace the 'size' field in struct imx274_frmfmt with 'bin_ratio'. [Sakari Ailus: Remove leftover condition in imx274_apply_trimming] Signed-off-by: Luca Ceresoli <luca@lucaceresoli.net> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2018-07-27media: imx274: use regmap_bulk_write to write multybyte registersLuca Ceresoli1-63/+39
Currently 2-bytes and 3-bytes registers are set by very similar functions doing the needed shift & mask manipulation, followed by very similar for loops setting one byte at a time over I2C. Replace all of this code by a unique helper function that calls regmap_bulk_write(), which has two advantages: - sets all the bytes in a unique I2C transaction - removes lots of now unused code. Signed-off-by: Luca Ceresoli <luca@lucaceresoli.net> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2018-07-04media: imx274: fix typoLuca Ceresoli1-1/+1
pd -> pad Signed-off-by: Luca Ceresoli <luca@lucaceresoli.net> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2018-07-04media: imx274: simplify imx274_write_table()Luca Ceresoli1-18/+10
imx274_write_table() is a mere wrapper (and the only user) to imx274_regmap_util_write_table_8(). Remove this useless indirection by merging the two functions into one. Also get rid of the wait_ms_addr and end_addr parameters since it does not make any sense to give them any values other than IMX274_TABLE_WAIT_MS and IMX274_TABLE_END. Signed-off-by: Luca Ceresoli <luca@lucaceresoli.net> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2018-07-04media: imx274: actually use IMX274_DEFAULT_MODELuca Ceresoli1-1/+1
IMX274_DEFAULT_MODE is defined but not used. Start using it, so the default can be more easily changed without digging into the code. Signed-off-by: Luca Ceresoli <luca@lucaceresoli.net> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2018-07-04media: imx274: get rid of mode_indexLuca Ceresoli1-10/+5
After restructuring struct imx274_frmfmt, the mode_index field is still in use only for two dev_dbg() calls in imx274_s_stream(). Let's remove it and avoid duplicated information. Replacing the first usage requires some rather annoying but trivial pointer math. The other one can be removed entirely since it would print the same value anyway. Signed-off-by: Luca Ceresoli <luca@lucaceresoli.net> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2018-07-04media: imx274: consolidate per-mode data in imx274_frmfmtLuca Ceresoli1-73/+66
Data about the implemented readout modes is partially stored in imx274_formats[], the rest is scattered in several arrays. The latter are then accessed using the mode index, e.g.: min_frame_len[priv->mode_index] Consolidate all these data in imx274_formats[], and store a pointer to the selected mode (i.e. imx274_formats[priv->mode_index]) in the main device struct. This way code to use these data becomes more readable, e.g.: priv->mode->min_frame_len This removes lots of scaffolding code and keeps data about each mode in a unique place. Also remove a parameter to imx274_mode_regs() that is now unused. While this adds the mode pointer to the device struct, it does not remove the mode_index from it because mode_index is still used in two dev_dbg() calls. This will be handled in a follow-up commit. Signed-off-by: Luca Ceresoli <luca@lucaceresoli.net> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2018-07-04media: imx274: initialize format before v4l2 controlsLuca Ceresoli1-10/+10
The current probe function calls v4l2_ctrl_handler_setup() before initializing the format info. This triggers call paths such as: imx274_probe -> v4l2_ctrl_handler_setup -> imx274_s_ctrl -> imx274_set_exposure, where priv->mode_index is accessed before being assigned. This is wrong but does not trigger a visible bug because priv is zero-initialized and 0 is the default value for priv->mode_index. But this would become a crash in follow-up commits when mode_index is replaced by a pointer that must always be valid. Fix the bug before it shows up by initializing struct members early. Signed-off-by: Luca Ceresoli <luca@lucaceresoli.net> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2018-05-17media: imx274: remove non-indexed pointers from mode_tableLuca Ceresoli1-19/+6
mode_table[] has 3 members that are accessed based on their index, which makes worth using an array. The other members are always accessed with a constant index. This added indirection gives no improvement and only makes code more verbose. Remove these pointers from the array and access them directly. Signed-off-by: Luca Ceresoli <luca@lucaceresoli.net> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2018-05-17media: imx274: rename and reorder register address definitionsLuca Ceresoli1-13/+13
Most registers are defined using the name used in the datasheet. E.g. the defines for the HMAX register are IMX274_HMAX_REG_*. Rename the SHR and VMAX register accordingly. Also move them close to related registers: SHR close to SVR, VMAX close to HMAX. Signed-off-by: Luca Ceresoli <luca@lucaceresoli.net> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2018-05-17media: imx274: remove unused data from struct imx274_frmfmtLuca Ceresoli1-12/+5
struct imx274_frmfmt is instantiated only in the imx274_formats[] array, where imx274_formats[N].mode always equals N (via enum imx274_mode). So .mode carries no information, and unsurprisingly it is never used. mbus_code is never used because the 12 bit modes are not implemented. The colorspace member is also never used, which is normal since the imx274 sensor can output only one colorspace. Let's get rid of all of them. Signed-off-by: Luca Ceresoli <luca@lucaceresoli.net> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2018-05-17media: imx274: slightly simplify codeLuca Ceresoli1-1/+1
imx274_s_frame_interval() already has a direct pointer to the v4l2 exposure control, so reuse it to simplify code. Signed-off-by: Luca Ceresoli <luca@lucaceresoli.net> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2018-05-17media: imx274: fix typo in commentLuca Ceresoli1-1/+1
interal->interval Signed-off-by: Luca Ceresoli <luca@lucaceresoli.net> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2018-05-17media: imx274: document reset delays more clearlyLuca Ceresoli1-1/+1
Document the unit to avoid having to look through the code to compute it. Also clarify that these are min and max values. Signed-off-by: Luca Ceresoli <luca@lucaceresoli.net> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2018-04-04media: imx274: fix typo in error messageLuca Ceresoli1-1/+1
Signed-off-by: Luca Ceresoli <luca@lucaceresoli.net> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2018-01-05media: imx274: Silence uninitialized variable warningDan Carpenter1-1/+1
Smatch complains that "err" can be uninitialized if we have a zero size write. The flow analysis is a little complicated so I'm not sure if that's possible or not, but it's harmless to set this to zero and it makes the code easier to read. Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2017-12-11media: imx274: don't randomly return if range_count is zeroMauro Carvalho Chehab1-0/+2
As smatch reported: drivers/media/i2c/imx274.c:659 imx274_regmap_util_write_table_8() error: uninitialized symbol 'err'. There is a bug at imx274_regmap_util_write_table_8() with causes it to randomly return a random error if range_count is zero. Worse than that, the logic there starts with range_count equal to zero, and periodically resets it to zero again. As it is a way more likely that err assumes a non-zero value, I suspect that the chance of this code to run is very small, so, it would be worth to review the entire function. Anyway, clearly it shouldn't be returning error if range_count is zero. So, let's fix it. Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2017-11-30media: imx274: Fix error handling, add MAINTAINERS entrySakari Ailus1-3/+2
Add the missing MAINTAINERS entry for imx274, fix error handling in driver probe and unregister the correct control handler in driver remove. Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2017-11-07media: imx274: fix missing return assignment from call to imx274_mode_regsColin Ian King1-1/+1
The variable ret is being checked for failure however it is not being set from the return status from the call to imx274_mode_regs. Currently ret is alwayus zero and the check is redundant. Fix this by assigning it. Detected by CoverityScan, CID#1460278 ("Logically dead code") Fixes: 0985dd306f72 ("media: imx274: V4l2 driver for Sony imx274 CMOS sensor") Signed-off-by: Colin Ian King <colin.king@canonical.com> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2017-10-27media: imx274: V4l2 driver for Sony imx274 CMOS sensorLeon Luo1-0/+1811
The imx274 is a Sony CMOS image sensor that has 1/2.5 image size. It supports up to 3840x2160 (4K) 60fps, 1080p 120fps. The interface is 4-lane MIPI CSI-2 running at 1.44Gbps each. This driver has been tested on Xilinx ZCU102 platform with a Leopard LI-IMX274MIPI-FMC camera board. Support for the following features: -Resolutions: 3840x2160, 1920x1080, 1280x720 -Frame rate: 3840x2160 : 5 – 60fps 1920x1080 : 5 – 120fps 1280x720 : 5 – 120fps -Exposure time: 16 – (frame interval) micro-seconds -Gain: 1x - 180x -VFLIP: enable/disabledrivers/media/i2c/imx274.c -Test pattern: 12 test patterns Signed-off-by: Leon Luo <leonl@leopardimaging.com> Tested-by: Sören Brinkmann <soren.brinkmann@xilinx.com> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>