Add support Add support for Omnivision OV56477
Subsystems (4)
v8 cover Add support Add support for Omnivision OV56477
Hello,
This patchset adds support for the Omnivision OV5647 sensor.
At the moment it only supports 640x480 in RAW 8.
This is the eighth version of the OV5647 camera driver patchset.
v8:
- Remove a part of the initialization procedure which wasn't doing anything
- Check for i2c read/writes return values
- Add stream_on/off functions
v7:
- Remove "0x" and leading 0 from DT documentation examples
v6:
- Add example to DT documentation
- Remove data-lanes and clock-lane property from DT
- Add external clock property to DT
- Order includes
- Remove unused variables and functions
- Add external clock handling
- Add power on counter
- Change from g/s_parm to g/s_frame_interval
v5:
- Refactor code
- Change comments
- Add missing error handling in some functions
v4:
- Add correct license
- Revert debugging info to generic infrastructure
- Turn defines into enums
- Correct code style issues
- Remove unused defines
- Make sure all errors where being handled
- Rename some functions to make code more readable
- Add some debugging info
v3:
- No changes. Re-submitted due to lack of responses
v2:
- Corrections in DT documentation
Ramiro Oliveira (2):
Add OV5647 device tree documentation
Add support for OV5647 sensor.
.../devicetree/bindings/media/i2c/ov5647.txt | 35 + MAINTAINERS | 7 + drivers/media/i2c/Kconfig | 12 + drivers/media/i2c/Makefile | 1 + drivers/media/i2c/ov5647.c | 736 +++++++++++++++++++++ 5 files changed, 791 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/i2c/ov5647.txt create mode 100644 drivers/media/i2c/ov5647.c
Signature · 1 line
2.11.0
PATCH v8 1/2 Add OV5647 device tree documentation
Create device tree bindings documentation.
--- .../devicetree/bindings/media/i2c/ov5647.txt | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/i2c/ov5647.txt
Documentation/devicetree/bindings/media/i2c/ov5647.txt new file +35 -0
@@ -0,0 +1,35 @@ +Omnivision OV5647 raw image sensor +--------------------------------- + +OV5647 is a raw image sensor with MIPI CSI-2 and CCP2 image data interfaces +and CCI (I2C compatible) control bus. + +Required properties: + +- compatible : "ovti,ov5647". +- reg : I2C slave address of the sensor. +- clocks : Reference to the xclk clock. +- clock-names : Should be "xclk". +- clock-frequency : Frequency of the xclk clock. + +The common video interfaces bindings (see video-interfaces.txt) should be +used to specify link to the image data receiver. The OV5647 device +node should contain one 'port' child node with an 'endpoint' subnode. + +Example: + + i2c@2000 { + ... + ov: camera@36 { + compatible = "ovti,ov5647"; + reg = <0x36>; + clocks = <&camera_clk>; + clock-names = "xclk"; + clock-frequency = <30000000>; + port { + camera_1: endpoint { + remote-endpoint = <&csi1_ep1>; + }; + }; + }; + };
Signature · 1 line
2.11.0
PATCH v8 2/2 Add support for OV5647 sensor.
In reply to Ramiro OliveiraModes supported:
- 640x480 RAW 8
--- MAINTAINERS | 7 + drivers/media/i2c/Kconfig | 12 + drivers/media/i2c/Makefile | 1 + drivers/media/i2c/ov5647.c | 736 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 756 insertions(+) create mode 100644 drivers/media/i2c/ov5647.c
MAINTAINERS +7 -0
@@ -9109,6 +9109,13 @@ M: Harald Welte <[email protected]> S: Maintained F: drivers/char/pcmcia/cm4040_cs.* +OMNIVISION OV5647 SENSOR DRIVER +M: Ramiro Oliveira <[email protected]> +L: [email protected] +T: git git://linuxtv.org/media_tree.git +S: Maintained +F: drivers/media/i2c/ov5647.c + OMNIVISION OV7670 SENSOR DRIVER M: Jonathan Corbet <[email protected]> L: [email protected]
drivers/media/i2c/Kconfig +12 -0
@@ -531,6 +531,18 @@ config VIDEO_OV2659 To compile this driver as a module, choose M here: the module will be called ov2659. +config VIDEO_OV5647 + tristate "OmniVision OV5647 sensor support" + depends on OF + depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API + depends on MEDIA_CAMERA_SUPPORT + ---help--- + This is a Video4Linux2 sensor-level driver for the OmniVision + OV5647 camera. + + To compile this driver as a module, choose M here: the + module will be called ov5647. + config VIDEO_OV7640 tristate "OmniVision OV7640 sensor support" depends on I2C && VIDEO_V4L2
drivers/media/i2c/Makefile +1 -0
@@ -83,3 +83,4 @@ obj-$(CONFIG_VIDEO_IR_I2C) += ir-kbd-i2c.o obj-$(CONFIG_VIDEO_ML86V7667) += ml86v7667.o obj-$(CONFIG_VIDEO_OV2659) += ov2659.o obj-$(CONFIG_VIDEO_TC358743) += tc358743.o +obj-$(CONFIG_VIDEO_OV5647) += ov5647.o
drivers/media/i2c/ov5647.c new file +736 -0
736 lines not on this page · raw message
Signature · 1 line
2.11.0
Re: [PATCH v8 2/2] Add support for OV5647 sensor.
Hello Ramiro,
Quoted 3 lines · Ramiro Oliveira
Modes supported:
- 640x480 RAW 8
It is a pretty short commit message, please consider to write a couple of words about the sensor.
Quoted 2 lines
Signed-off-by Ramiro Oliveira <[email protected]>---
[snip]
drivers/media/i2c/ov5647.c line 74
Quoted 5 lines
drivers/media/i2c/ov5647.c new file +5
-0+ +struct cfg_array { +struct regval_list *regs; +int size; +};
struct cfg_array is apparently unused.
drivers/media/i2c/ov5647.c line 206
Quoted 10 lines
drivers/media/i2c/ov5647.c new file +10
-0+ +/** +* @short I2C Write operation +* @param[in] i2c_client I2C client +* @param[in] reg register address +* @param[in] val value to write +* @return Error code +*/ +static int ov5647_write (struct v4l2_subdev *sd,u16 reg,u8 val) +{
The comment contents is probably outdated, because it does not describe the function input arguments properly.
drivers/media/i2c/ov5647.c line 215
Quoted 9 lines
drivers/media/i2c/ov5647.c new file +9
-0+int ret; +unsigned char data[3 ] = { reg >>8 , reg &0xff , val}; +struct i2c_client *client =v4l2_get_subdevdata (sd); + + ret =i2c_master_send (client, data,3 ); +if (ret !=3 ) { +dev_dbg (&client->dev,"%s: i2c write error, reg: %x\n" , + __func__, reg); +return ret <0 ? ret : -EIO ;
Here i2c_master_send() returns only to a negative error or '3', thus the check is redundant.
Please do 'return ret';
drivers/media/i2c/ov5647.c line 228
Quoted 13 lines
drivers/media/i2c/ov5647.c new file +13
-0+ } +return 0 ; +} + +/** +* @short I2C Read operation +* @param[in] i2c_client I2C client +* @param[in] reg register address +* @param[out] val value read +* @return Error code +*/ +static int ov5647_read (struct v4l2_subdev *sd,u16 reg,u8 *val) +{
Same as above, the comment must be updated.
drivers/media/i2c/ov5647.c line 238
Quoted 10 lines
drivers/media/i2c/ov5647.c new file +10
-0+int ret; +unsigned char data_w[2 ] = { reg >>8 , reg &0xff }; +struct i2c_client *client =v4l2_get_subdevdata (sd); + + ret =i2c_master_send (client, data_w,2 ); + +if (ret <2 ) { +dev_dbg (&client->dev,"%s: i2c read error, reg: %x\n" , + __func__, reg); +return ret <0 ? ret : -EIO ;
Here i2c_master_send() returns only to a negative error or '2', thus the check is redundant.
Please do 'return ret';
drivers/media/i2c/ov5647.c line 246
Quoted 8 lines
drivers/media/i2c/ov5647.c new file +8
-0+ } + + ret =i2c_master_recv (client, val,1 ); + +if (ret <1 ) { +dev_dbg (&client->dev,"%s: i2c read error, reg: %x\n" , + __func__, reg); +return ret <0 ? ret : -EIO ;
Here i2c_master_recv() returns only to a negative error or '1', thus the check is redundant.
Please do 'return ret';
drivers/media/i2c/ov5647.c line 255
Quoted 9 lines
drivers/media/i2c/ov5647.c new file +9
-0+ } +return 0 ; +} + +static int ov5647_write_array (struct v4l2_subdev *sd, +struct regval_list *regs,int array_size) +{ +int i =0 ; +int ret =0 ;
Please don't assign a value to 'ret' and please do declarations on a single line.
drivers/media/i2c/ov5647.c line 258
Quoted 3 lines
drivers/media/i2c/ov5647.c new file +3
-0+ +if (!regs) +return -EINVAL ;
!regs is a dead code check, please remove it.
drivers/media/i2c/ov5647.c line 266
Quoted 8 lines
drivers/media/i2c/ov5647.c new file +8
-0+ +while (i < array_size) { + ret =ov5647_write (sd, regs->addr, regs->data); +if (ret <0 ) +return ret; + i++; + regs++; + }
Please do a for-loop, it will save two lines of code:
for (i = 0; i < array_size; i++) {
ret = ov5647_write(sd, regs[i].addr, regs[i].data);
if (ret < 0)
return ret;
}drivers/media/i2c/ov5647.c line 273
Quoted 7 lines
drivers/media/i2c/ov5647.c new file +7
-0+return 0 ; +} + +static int ov5647_set_virtual_channel (struct v4l2_subdev *sd,int channel) +{ +u8 channel_id; +int ret =0 ;
Please don't assign a value to 'ret' on declaration here.
Quoted 31 lines
drivers/media/i2c/ov5647.c new file +31
-0+ + ret =ov5647_read (sd,0x4814 , &channel_id); +if (ret <0 ) +return ret; + + channel_id &= ~(3 <<6 ); +return ov5647_write (sd,0x4814 , channel_id | (channel <<6 )); +} + +static int ov5647_stream_on (struct v4l2_subdev *sd) +{ +struct i2c_client *client =v4l2_get_subdevdata (sd); + +ov5647_write (sd,0x4202 ,0x00 ); + +dev_dbg (&client->dev,"Stream on" ); + +return ov5647_write (sd,0x300D ,0x00 ); +} + +static int ov5647_stream_off (struct v4l2_subdev *sd) +{ +struct i2c_client *client =v4l2_get_subdevdata (sd); + +ov5647_write (sd,0x4202 ,0x0f ); + +dev_dbg (&client->dev,"Stream off" ); + +return ov5647_write (sd,0x300D ,0x01 ); +} +
drivers/media/i2c/ov5647.c line 314
Quoted 10 lines
drivers/media/i2c/ov5647.c new file +10
-0+/** +* @short Set SW standby +* @param[in] sd v4l2 sd +* @param[in] stanby standby mode status (on or off) +* @return Error code +*/ +static int set_sw_standby (struct v4l2_subdev *sd,bool standby) +{ +int ret; +unsigned char rdval;
ov5647_read() return value type is 'u8', please change it here and everywhere else in the code.
drivers/media/i2c/ov5647.c line 317
Quoted 3 lines
drivers/media/i2c/ov5647.c new file +3
-0+ + ret =ov5647_read (sd,0x0100 , &rdval); +if (ret !=0 )
if (ret < 0)
drivers/media/i2c/ov5647.c line 321
Quoted 4 lines
drivers/media/i2c/ov5647.c new file +4
-0+return ret; + +if (standby) + rdval &=0xfe ;
Here 'rdval &= ~0x01' would be preferred to emphasize symmetry.
drivers/media/i2c/ov5647.c line 334
Quoted 13 lines
drivers/media/i2c/ov5647.c new file +13
-0+else + rdval |=0x01 ; + +return ov5647_write (sd,0x0100 , rdval); +} + +/** +* @short Initialize sensor +* @param[in] sd v4l2 subdev +* @param[in] val not used +* @return Error code +*/ +static int __sensor_init (struct v4l2_subdev *sd)
Same as above, the comment must be updated.
drivers/media/i2c/ov5647.c line 344
Quoted 10 lines
drivers/media/i2c/ov5647.c new file +10
-0+{ +int ret; +u8 resetval; +u8 rdval; +struct i2c_client *client =v4l2_get_subdevdata (sd); + +dev_dbg (&client->dev,"sensor init\n" ); + + ret =ov5647_read (sd,0x0100 , &rdval); +if (ret !=0 )
if (ret < 0)
Quoted 98 lines
drivers/media/i2c/ov5647.c new file +98
-0+return ret; + + ret =ov5647_write_array (sd, ov5647_640x480, +ARRAY_SIZE (ov5647_640x480)); +if (ret <0 ) { +dev_err (&client->dev,"write sensor default regs error\n" ); +return ret; + } + + ret =ov5647_set_virtual_channel (sd,0 ); +if (ret <0 ) +return ret; + + ret =ov5647_read (sd,0x0100 , &resetval); +if (ret <0 ) +return ret; + +if (!(resetval &0x01 )) { +dev_err (&client->dev,"Device was in SW standby" ); + ret =ov5647_write (sd,0x0100 ,0x01 ); +if (ret <0 ) +return ret; + } + +return ov5647_write (sd,0x4800 ,0x04 ); +} + +/** +* @short Control sensor power state +* @param[in] sd v4l2 subdev +* @param[in] on Sensor power +* @return Error code +*/ +static int sensor_power (struct v4l2_subdev *sd,int on) +{ +int ret; +struct ov5647 *ov5647 =to_state (sd); +struct i2c_client *client =v4l2_get_subdevdata (sd); + + ret =0 ; +mutex_lock (&ov5647->lock); + +if (on && !ov5647->power_count) { +dev_dbg (&client->dev,"OV5647 power on\n" ); + +clk_set_rate (ov5647->xclk, ov5647->xclk_freq); + + ret =clk_prepare_enable (ov5647->xclk); +if (ret <0 ) { +dev_err (ov5647->dev,"clk prepare enable failed\n" ); + goto out; + } + + ret =ov5647_write_array (sd, sensor_oe_enable_regs, +ARRAY_SIZE (sensor_oe_enable_regs)); +if (ret <0 ) { +clk_disable_unprepare (ov5647->xclk); +dev_err (&client->dev, +"write sensor_oe_enable_regs error\n" ); + goto out; + } + + ret =__sensor_init (sd); +if (ret <0 ) { +clk_disable_unprepare (ov5647->xclk); +dev_err (&client->dev, +"Camera not available, check Power\n" ); + goto out; + } + }else if (!on && ov5647->power_count ==1 ) { +dev_dbg (&client->dev,"OV5647 power off\n" ); + +dev_dbg (&client->dev,"disable oe\n" ); + ret =ov5647_write_array (sd, sensor_oe_disable_regs, +ARRAY_SIZE (sensor_oe_disable_regs)); + +if (ret <0 ) +dev_dbg (&client->dev,"disable oe failed\n" ); + + ret =set_sw_standby (sd, true); + +if (ret <0 ) +dev_dbg (&client->dev,"soft stby failed\n" ); + +clk_disable_unprepare (ov5647->xclk); + } + +/* Update the power count. */ + ov5647->power_count += on ?1 :-1 ; +WARN_ON (ov5647->power_count <0 ); + +out: +mutex_unlock (&ov5647->lock); + +return ret; +} + +#ifdef CONFIG_VIDEO_ADV_DEBUG
drivers/media/i2c/ov5647.c line 452
Quoted 10 lines
drivers/media/i2c/ov5647.c new file +10
-0+/** +* @short Get register value +* @param[in] sd v4l2 subdev +* @param[in] reg register struct +* @return Error code +*/ +static int sensor_get_register (struct v4l2_subdev *sd, +struct v4l2_dbg_register *reg) +{ +unsigned char val =0 ;
ov5647_read() return value type is 'u8', please change it here and everywhere else in the code.
Also please don't assign a value to 'val' n declaration.
drivers/media/i2c/ov5647.c line 456
Quoted 4 lines
drivers/media/i2c/ov5647.c new file +4
-0+int ret; + + ret =ov5647_read (sd, reg->reg &0xff , &val); +if (ret !=0 )
if (ret < 0)
drivers/media/i2c/ov5647.c line 462
Quoted 6 lines
drivers/media/i2c/ov5647.c new file +6
-0+return ret; + + reg->val = val; + reg->size =1 ; + +return ret;
return 0;
Quoted 22 lines
drivers/media/i2c/ov5647.c new file +22
-0+} + +/** +* @short Set register value +* @param[in] sd v4l2 subdev +* @param[in] reg register struct +* @return Error code +*/ +static int sensor_set_register (struct v4l2_subdev *sd, +const struct v4l2_dbg_register *reg) +{ +return ov5647_write (sd, reg->reg &0xff , reg->val &0xff ); +} +#endif + +/** +* @short Subdev core operations registration +*/ +static const struct v4l2_subdev_core_ops subdev_core_ops = { + .s_power = sensor_power, +#ifdef CONFIG_VIDEO_ADV_DEBUG + .g_register = sensor_get_register,
drivers/media/i2c/ov5647.c line 494
Quoted 10 lines
drivers/media/i2c/ov5647.c new file +10
-0+ .s_register = sensor_set_register, +#endif +}; + +static int s_stream (struct v4l2_subdev *sd,int enable) +{ +if (!enable) +return ov5647_stream_off (sd); +else +return ov5647_stream_on (sd);
To avoid a negation please do
if (enable) return ov5647_stream_on(sd); else return ov5647_stream_off(sd);
drivers/media/i2c/ov5647.c line 501
Quoted 7 lines
drivers/media/i2c/ov5647.c new file +7
-0+} + +static const struct v4l2_subdev_video_ops subdev_video_ops = { + .s_stream = s_stream, +}; + +
Please remove one of two empty lines in a row.
Quoted 24 lines
drivers/media/i2c/ov5647.c new file +24
-0+static int enum_mbus_code (struct v4l2_subdev *sd, +struct v4l2_subdev_pad_config *cfg, +struct v4l2_subdev_mbus_code_enum *code) +{ +if (code->index >0 ) +return -EINVAL ; + + code->code =MEDIA_BUS_FMT_SBGGR8_1X8 ; + +return 0 ; +} + +static const struct v4l2_subdev_pad_ops subdev_pad_ops = { + .enum_mbus_code = enum_mbus_code, +}; + +/** +* @short Subdev operations registration +* +*/ +static const struct v4l2_subdev_ops subdev_ops = { + .core = &subdev_core_ops, + .video = &subdev_video_ops, + .pad = &subdev_pad_ops,
drivers/media/i2c/ov5647.c line 535
Quoted 10 lines
drivers/media/i2c/ov5647.c new file +10
-0+}; + +/** +* @short Detect camera version and model +* @param[in] sd v4l2 subdev +* @return Error code +*/ +static int ov5647_detect (struct v4l2_subdev *sd) +{ +unsigned char read;
ov5647_read() return value type is 'u8', please change it here and everywhere else in the code.
Quoted 92 lines
drivers/media/i2c/ov5647.c new file +92
-0+int ret; +struct i2c_client *client =v4l2_get_subdevdata (sd); + + ret =ov5647_write (sd,OV5647_SW_RESET ,0x01 ); +if (ret <0 ) +return ret; + + ret =ov5647_read (sd,OV5647_REG_CHIPID_H , &read); +if (ret <0 ) +return ret; + +if (read !=0x56 ) { +dev_err (&client->dev,"Wrong model version detected" ); +return -ENODEV ; + } + + ret =ov5647_read (sd,OV5647_REG_CHIPID_L , &read); +if (ret <0 ) +return ret; + +if (read !=0x47 ) { +dev_err (&client->dev,"Wrong model version detected" ); +return -ENODEV ; + } + +return ov5647_write (sd,OV5647_SW_RESET ,0x00 ); +} + +/** +* @short Detect if camera is registered +* @param[in] sd v4l2 subdev +* @return Error code +*/ +static int ov5647_registered (struct v4l2_subdev *sd) +{ +return 0 ; +} + +/** +* @short Open device +* @param[in] sd v4l2 subdev +* @param[in] fh v4l2 file handler +* @return Error code +*/ +static int ov5647_open (struct v4l2_subdev *sd,struct v4l2_subdev_fh *fh) +{ +struct v4l2_mbus_framefmt *format = +v4l2_subdev_get_try_format (sd, fh->pad,0 ); +struct v4l2_rect *crop = +v4l2_subdev_get_try_crop (sd, fh->pad,0 ); + + crop->left =OV5647_COLUMN_START_DEF ; + crop->top =OV5647_ROW_START_DEF ; + crop->width =OV5647_WINDOW_WIDTH_DEF ; + crop->height =OV5647_WINDOW_HEIGHT_DEF ; + + format->code =MEDIA_BUS_FMT_SBGGR8_1X8 ; + + format->width =OV5647_WINDOW_WIDTH_DEF ; + format->height =OV5647_WINDOW_HEIGHT_DEF ; + format->field =V4L2_FIELD_NONE ; + format->colorspace =V4L2_COLORSPACE_SRGB ; + +return sensor_power (sd, true); +} + +/** +* @short Open device +* @param[in] sd v4l2 subdev +* @param[in] fh v4l2 file handler +* @return Error code +*/ +static int ov5647_close (struct v4l2_subdev *sd,struct v4l2_subdev_fh *fh) +{ +return sensor_power (sd, false); +} + +/** +* @short Subdev internal operations registration +* +*/ +static const struct v4l2_subdev_internal_ops ov5647_subdev_internal_ops = { + .registered = ov5647_registered, + .open = ov5647_open, + .close = ov5647_close, +}; + +/** +* @short Initialization routine - Entry point of the driver +* @param[in] client pointer to the i2c client structure +* @param[in] id pointer to the i2c device id structure +* @return 0 on success and a negative number on failure
drivers/media/i2c/ov5647.c line 637
Quoted 10 lines
drivers/media/i2c/ov5647.c new file +10
-0+*/ +static int ov5647_probe (struct i2c_client *client, +const struct i2c_device_id *id) +{ +struct device *dev = &client->dev; +struct ov5647 *sensor; +int ret; +struct v4l2_subdev *sd; + +dev_info (&client->dev,"Installing OmniVision OV5647 camera driver\n" );
Please remove the informational line, it will pollute the kernel log for no good reason.
Quoted 11 lines
drivers/media/i2c/ov5647.c new file +11
-0+ + sensor =devm_kzalloc (dev,sizeof (*sensor),GFP_KERNEL ); +if (sensor ==NULL ) +return -ENOMEM ; + +/* get system clock (xclk) */ + sensor->xclk =devm_clk_get (dev,"xclk" ); +if (IS_ERR (sensor->xclk)) { +dev_err (dev,"could not get xclk" ); +return PTR_ERR (sensor->xclk); + }
drivers/media/i2c/ov5647.c line 658
Quoted 10 lines
drivers/media/i2c/ov5647.c new file +10
-0+ + ret =of_property_read_u32 (dev->of_node,"clock-frequency" , + &sensor->xclk_freq); +if (ret) { +dev_err (dev,"could not get xclk frequency\n" ); +return ret; + } + +mutex_init (&sensor->lock); + sensor->dev = dev;
sensor->dev is unused, please remove it from the 'struct ov5647' declaration.
Quoted 58 lines
drivers/media/i2c/ov5647.c new file +52
-0+ + sd = &sensor->sd; +v4l2_i2c_subdev_init (sd, client, &subdev_ops); + sensor->sd.flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ; + + sensor->pad.flags =MEDIA_PAD_FL_SOURCE ; + sd->entity.function =MEDIA_ENT_F_CAM_SENSOR ; + ret =media_entity_pads_init (&sd->entity,1 , &sensor->pad); +if (ret <0 ) + goto mutex_remove; + + ret =ov5647_detect (sd); +if (ret <0 ) + goto error; + + ret =v4l2_async_register_subdev (sd); +if (ret <0 ) + goto error; + +return 0 ; +error: +media_entity_cleanup (&sd->entity); +mutex_remove: +mutex_destroy (&sensor->lock); +return ret; +} + +/** +* @short Exit routine - Exit point of the driver +* @param[in] client pointer to the i2c client structure +* @return 0 on success and a negative number on failure +*/ +static int ov5647_remove (struct i2c_client *client) +{ +struct v4l2_subdev *sd =i2c_get_clientdata (client); +struct ov5647 *ov5647 =to_state (sd); + +v4l2_async_unregister_subdev (&ov5647->sd); +media_entity_cleanup (&ov5647->sd.entity); +v4l2_device_unregister_subdev (sd); +mutex_destroy (&ov5647->lock); + +return 0 ; +} + +static const struct i2c_device_id ov5647_id[] = { + {"ov5647" ,0 }, + { } +}; +MODULE_DEVICE_TABLE (i2c, ov5647_id); + +#if IS_ENABLED (CONFIG_OF )From
Kconfigthe driver depends on OF.drivers/media/i2c/ov5647.c new file +3
-0+static const struct of_device_id ov5647_of_match[] = { + { .compatible ="ovti,ov5647" }, + {/* sentinel */ },
drivers/media/i2c/ov5647.c line 723
Quoted 10 lines
drivers/media/i2c/ov5647.c new file +10
-0+}; +MODULE_DEVICE_TABLE (of, ov5647_of_match); +#endif + +/** +* @short i2c driver structure +*/ +static struct i2c_driver ov5647_driver = { + .driver = { + .of_match_table =of_match_ptr (ov5647_of_match),
Same comment as above, from Kconfig the driver depends on OF.
drivers/media/i2c/ov5647.c line 724
Quoted 1 line
drivers/media/i2c/ov5647.c new file +1
-0+ .owner = THIS_MODULE,
.owner is set by the core, please remove it.
drivers/media/i2c/ov5647.c line 725
Quoted 1 line
drivers/media/i2c/ov5647.c new file +1
-0+ .name = "ov5647",
May be .name = SENSOR_NAME, ?
Otherwise SENSOR_NAME macro is unused and it should be removed.
drivers/media/i2c/ov5647.c line 736
Quoted 12 lines
drivers/media/i2c/ov5647.c new file +11
-0+ }, + .probe = ov5647_probe, + .remove = ov5647_remove, + .id_table = ov5647_id, +}; + +module_i2c_driver (ov5647_driver); + +MODULE_AUTHOR ("Ramiro Oliveira <[email protected]>" ); +MODULE_DESCRIPTION ("A low-level driver for OmniVision ov5647 sensors" ); +MODULE_LICENSE ("GPL v2" );
--
With best wishes,
Vladimir
Re: [PATCH v8 2/2] Add support for OV5647 sensor.
Hi Vladimir,
Thank you for your feedback.
Quoted 10 lines · Vladimir Zapolskiy
Hello Ramiro,
Quoted 3 lines · Ramiro Oliveira
Modes supported:
- 640x480 RAW 8It is a pretty short commit message, please consider to write a couple of words about the sensor.
Sure, I can do that.
Quoted 5 lines
Quoted 2 lines
---
[snip]
Quoted 8 lines
drivers/media/i2c/ov5647.c line 74
Quoted 5 lines
drivers/media/i2c/ov5647.c new file +5
-0+ +struct cfg_array { +struct regval_list *regs; +int size; +};struct
cfg_arrayis apparently unused.
You're right. It's left-over code.
Quoted 5 lines
Quoted 5 lines
drivers/media/i2c/ov5647.c new file +5
-0+ +/** +* @short I2C Write operation +* @param[in] i2c_client I2C client +* @param[in] reg register address
Quoted 9 lines
Review
Quoted 5 lines
+ * @param[in] val value to write
+ * @return Error code
+ */(quoted diff) +2
-0+static int ov5647_write(struct v4l2_subdev *sd, u16 reg, u8 val) +{The comment contents is probably outdated, because it does not describe the function input arguments properly.
I'll remove the comments since the function is self-explanatory, I believe.
Quoted 13 lines
drivers/media/i2c/ov5647.c line 215
Quoted 9 lines
drivers/media/i2c/ov5647.c new file +9
-0+int ret; +unsigned char data[3 ] = { reg >>8 , reg &0xff , val}; +struct i2c_client *client =v4l2_get_subdevdata (sd); + + ret =i2c_master_send (client, data,3 ); +if (ret !=3 ) { +dev_dbg (&client->dev,"%s: i2c write error, reg: %x\n" , + __func__, reg); +return ret <0 ? ret : -EIO ;Here
i2c_master_send()returns only to a negative error or '3', thus the check is redundant.
Quoted 2 lines
Please do 'return ret';
I'll do that.
Quoted 7 lines
Quoted 7 lines
drivers/media/i2c/ov5647.c new file +7
-0+ } +return 0 ; +} + +/** +* @short I2C Read operation +* @param[in] i2c_client I2C client
Quoted 9 lines
Review
Quoted 6 lines
+ * @param[in] reg register address
+ * @param[out] val value read
+ * @return Error code
+ */(quoted diff) +2
-0+static int ov5647_read(struct v4l2_subdev *sd, u16 reg, u8 *val) +{Same as above, the comment must be updated.
I'll remove the comments since the function is self-explanatory, I believe.
Quoted 15 lines
drivers/media/i2c/ov5647.c line 238
Quoted 10 lines
drivers/media/i2c/ov5647.c new file +10
-0+int ret; +unsigned char data_w[2 ] = { reg >>8 , reg &0xff }; +struct i2c_client *client =v4l2_get_subdevdata (sd); + + ret =i2c_master_send (client, data_w,2 ); + +if (ret <2 ) { +dev_dbg (&client->dev,"%s: i2c read error, reg: %x\n" , + __func__, reg); +return ret <0 ? ret : -EIO ;Here
i2c_master_send()returns only to a negative error or '2', thus the check is redundant.
Quoted 2 lines
Please do 'return ret';
I'll do that.
Quoted 12 lines
drivers/media/i2c/ov5647.c line 246
Quoted 8 lines
drivers/media/i2c/ov5647.c new file +8
-0+ } + + ret =i2c_master_recv (client, val,1 ); + +if (ret <1 ) { +dev_dbg (&client->dev,"%s: i2c read error, reg: %x\n" , + __func__, reg); +return ret <0 ? ret : -EIO ;Here
i2c_master_recv()returns only to a negative error or '1', thus the check is redundant.
Quoted 2 lines
Please do 'return ret';
I'll do that.
Quoted 12 lines
drivers/media/i2c/ov5647.c line 255
Quoted 9 lines
drivers/media/i2c/ov5647.c new file +9
-0+ } +return 0 ; +} + +static int ov5647_write_array (struct v4l2_subdev *sd, +struct regval_list *regs,int array_size) +{ +int i =0 ; +int ret =0 ;Please don't assign a value to 'ret' and please do declarations on a single line.
Ok.
Quoted 6 lines
drivers/media/i2c/ov5647.c line 258
Quoted 3 lines
drivers/media/i2c/ov5647.c new file +3
-0+ +if (!regs) +return -EINVAL ;!regs is a dead code check, please remove it.
I'll do that.
Quoted 11 lines
drivers/media/i2c/ov5647.c line 266
Quoted 8 lines
drivers/media/i2c/ov5647.c new file +8
-0+ +while (i < array_size) { + ret =ov5647_write (sd, regs->addr, regs->data); +if (ret <0 ) +return ret; + i++; + regs++; + }Please do a for-loop, it will save two lines of code:
Quoted 6 lines
for (i = 0; i < array_size; i++) {
ret = ov5647_write(sd, regs[i].addr, regs[i].data);
if (ret < 0)
return ret;
}Sure, I can do that.
Quoted 10 lines
drivers/media/i2c/ov5647.c line 273
Quoted 7 lines
drivers/media/i2c/ov5647.c new file +7
-0+return 0 ; +} + +static int ov5647_set_virtual_channel (struct v4l2_subdev *sd,int channel) +{ +u8 channel_id; +int ret =0 ;Please don't assign a value to 'ret' on declaration here.
Ok.
Quoted 36 lines
Quoted 36 lines
drivers/media/i2c/ov5647.c new file +36
-0+ + ret =ov5647_read (sd,0x4814 , &channel_id); +if (ret <0 ) +return ret; + + channel_id &= ~(3 <<6 ); +return ov5647_write (sd,0x4814 , channel_id | (channel <<6 )); +} + +static int ov5647_stream_on (struct v4l2_subdev *sd) +{ +struct i2c_client *client =v4l2_get_subdevdata (sd); + +ov5647_write (sd,0x4202 ,0x00 ); + +dev_dbg (&client->dev,"Stream on" ); + +return ov5647_write (sd,0x300D ,0x00 ); +} + +static int ov5647_stream_off (struct v4l2_subdev *sd) +{ +struct i2c_client *client =v4l2_get_subdevdata (sd); + +ov5647_write (sd,0x4202 ,0x0f ); + +dev_dbg (&client->dev,"Stream off" ); + +return ov5647_write (sd,0x300D ,0x01 ); +} + +/** +* @short Set SW standby +* @param[in] sd v4l2 sd +* @param[in] stanby standby mode status (on or off) +* @return Error code
Quoted 9 lines
drivers/media/i2c/ov5647.c line 314
Quoted 5 lines
+ */
drivers/media/i2c/ov5647.c new file +4
-0+static int set_sw_standby (struct v4l2_subdev *sd,bool standby) +{ +int ret; +unsigned char rdval;
ov5647_read()return value type is 'u8', please change it here and everywhere else in the code.
Ok.
Quoted 6 lines
drivers/media/i2c/ov5647.c line 317
Quoted 3 lines
drivers/media/i2c/ov5647.c new file +3
-0+ + ret =ov5647_read (sd,0x0100 , &rdval); +if (ret !=0 )if (ret < 0)
I'll change it.
Quoted 7 lines
drivers/media/i2c/ov5647.c line 321
Quoted 4 lines
drivers/media/i2c/ov5647.c new file +4
-0+return ret; + +if (standby) + rdval &=0xfe ;Here 'rdval &= ~0x01' would be preferred to emphasize symmetry.
Sure, it makes sense.
Quoted 7 lines
Quoted 7 lines
drivers/media/i2c/ov5647.c new file +7
-0+else + rdval |=0x01 ; + +return ov5647_write (sd,0x0100 , rdval); +} + +/**
Quoted 9 lines
Quoted 6 lines
+ * @short Initialize sensor
+ * @param[in] sd v4l2 subdev
+ * @param[in] val not used
+ * @return Error code
+ */
+static int__sensor_init(struct v4l2_subdev *sd)Same as above, the comment must be updated.
I'll remove the comments since the function is self-explanatory, I believe.
Quoted 4 lines
Quoted 4 lines
drivers/media/i2c/ov5647.c new file +4
-0+{ +int ret; +u8 resetval; +u8 rdval;
Quoted 9 lines
drivers/media/i2c/ov5647.c line 344
Quoted 6 lines
drivers/media/i2c/ov5647.c new file +6
-0+struct i2c_client *client =v4l2_get_subdevdata (sd); + +dev_dbg (&client->dev,"sensor init\n" ); + + ret =ov5647_read (sd,0x0100 , &rdval); +if (ret !=0 )if (ret < 0)
I'll change it.
Quoted 112 lines
Quoted 98 lines
drivers/media/i2c/ov5647.c new file +98
-0+return ret; + + ret =ov5647_write_array (sd, ov5647_640x480, +ARRAY_SIZE (ov5647_640x480)); +if (ret <0 ) { +dev_err (&client->dev,"write sensor default regs error\n" ); +return ret; + } + + ret =ov5647_set_virtual_channel (sd,0 ); +if (ret <0 ) +return ret; + + ret =ov5647_read (sd,0x0100 , &resetval); +if (ret <0 ) +return ret; + +if (!(resetval &0x01 )) { +dev_err (&client->dev,"Device was in SW standby" ); + ret =ov5647_write (sd,0x0100 ,0x01 ); +if (ret <0 ) +return ret; + } + +return ov5647_write (sd,0x4800 ,0x04 ); +} + +/** +* @short Control sensor power state +* @param[in] sd v4l2 subdev +* @param[in] on Sensor power +* @return Error code +*/ +static int sensor_power (struct v4l2_subdev *sd,int on) +{ +int ret; +struct ov5647 *ov5647 =to_state (sd); +struct i2c_client *client =v4l2_get_subdevdata (sd); + + ret =0 ; +mutex_lock (&ov5647->lock); + +if (on && !ov5647->power_count) { +dev_dbg (&client->dev,"OV5647 power on\n" ); + +clk_set_rate (ov5647->xclk, ov5647->xclk_freq); + + ret =clk_prepare_enable (ov5647->xclk); +if (ret <0 ) { +dev_err (ov5647->dev,"clk prepare enable failed\n" ); + goto out; + } + + ret =ov5647_write_array (sd, sensor_oe_enable_regs, +ARRAY_SIZE (sensor_oe_enable_regs)); +if (ret <0 ) { +clk_disable_unprepare (ov5647->xclk); +dev_err (&client->dev, +"write sensor_oe_enable_regs error\n" ); + goto out; + } + + ret =__sensor_init (sd); +if (ret <0 ) { +clk_disable_unprepare (ov5647->xclk); +dev_err (&client->dev, +"Camera not available, check Power\n" ); + goto out; + } + }else if (!on && ov5647->power_count ==1 ) { +dev_dbg (&client->dev,"OV5647 power off\n" ); + +dev_dbg (&client->dev,"disable oe\n" ); + ret =ov5647_write_array (sd, sensor_oe_disable_regs, +ARRAY_SIZE (sensor_oe_disable_regs)); + +if (ret <0 ) +dev_dbg (&client->dev,"disable oe failed\n" ); + + ret =set_sw_standby (sd, true); + +if (ret <0 ) +dev_dbg (&client->dev,"soft stby failed\n" ); + +clk_disable_unprepare (ov5647->xclk); + } + +/* Update the power count. */ + ov5647->power_count += on ?1 :-1 ; +WARN_ON (ov5647->power_count <0 ); + +out: +mutex_unlock (&ov5647->lock); + +return ret; +} + +#ifdef CONFIG_VIDEO_ADV_DEBUG drivers/media/i2c/ov5647.c line 452
Quoted 10 lines
drivers/media/i2c/ov5647.c new file +10
-0+/** +* @short Get register value +* @param[in] sd v4l2 subdev +* @param[in] reg register struct +* @return Error code +*/ +static int sensor_get_register (struct v4l2_subdev *sd, +struct v4l2_dbg_register *reg) +{ +unsigned char val =0 ;
ov5647_read()return value type is 'u8', please change it here and everywhere else in the code.
Quoted 2 lines
Also please don't assign a value to 'val' n declaration.
Ok.
Quoted 7 lines
drivers/media/i2c/ov5647.c line 456
Quoted 4 lines
drivers/media/i2c/ov5647.c new file +4
-0+int ret; + + ret =ov5647_read (sd, reg->reg &0xff , &val); +if (ret !=0 )if (ret < 0)
I'll change it.
Quoted 9 lines
drivers/media/i2c/ov5647.c line 462
Quoted 6 lines
drivers/media/i2c/ov5647.c new file +6
-0+return ret; + + reg->val = val; + reg->size =1 ; + +return ret;return 0;
Ok.
Quoted 35 lines
Quoted 22 lines
drivers/media/i2c/ov5647.c new file +22
-0+} + +/** +* @short Set register value +* @param[in] sd v4l2 subdev +* @param[in] reg register struct +* @return Error code +*/ +static int sensor_set_register (struct v4l2_subdev *sd, +const struct v4l2_dbg_register *reg) +{ +return ov5647_write (sd, reg->reg &0xff , reg->val &0xff ); +} +#endif + +/** +* @short Subdev core operations registration +*/ +static const struct v4l2_subdev_core_ops subdev_core_ops = { + .s_power = sensor_power, +#ifdef CONFIG_VIDEO_ADV_DEBUG + .g_register = sensor_get_register,drivers/media/i2c/ov5647.c line 494
Quoted 10 lines
drivers/media/i2c/ov5647.c new file +10
-0+ .s_register = sensor_set_register, +#endif +}; + +static int s_stream (struct v4l2_subdev *sd,int enable) +{ +if (!enable) +return ov5647_stream_off (sd); +else +return ov5647_stream_on (sd);To avoid a negation please do
Quoted 5 lines
if (enable) return ov5647_stream_on(sd); else return ov5647_stream_off(sd);
No problem, I'll do that.
Quoted 10 lines
drivers/media/i2c/ov5647.c line 501
Quoted 7 lines
drivers/media/i2c/ov5647.c new file +7
-0+} + +static const struct v4l2_subdev_video_ops subdev_video_ops = { + .s_stream = s_stream, +}; + +Please remove one of two empty lines in a row.
Ok.
Quoted 29 lines
Quoted 29 lines
drivers/media/i2c/ov5647.c new file +29
-0+static int enum_mbus_code (struct v4l2_subdev *sd, +struct v4l2_subdev_pad_config *cfg, +struct v4l2_subdev_mbus_code_enum *code) +{ +if (code->index >0 ) +return -EINVAL ; + + code->code =MEDIA_BUS_FMT_SBGGR8_1X8 ; + +return 0 ; +} + +static const struct v4l2_subdev_pad_ops subdev_pad_ops = { + .enum_mbus_code = enum_mbus_code, +}; + +/** +* @short Subdev operations registration +* +*/ +static const struct v4l2_subdev_ops subdev_ops = { + .core = &subdev_core_ops, + .video = &subdev_video_ops, + .pad = &subdev_pad_ops, +}; + +/** +* @short Detect camera version and model +* @param[in] sd v4l2 subdev
Quoted 9 lines
drivers/media/i2c/ov5647.c line 535
Quoted 5 lines
+ * @return Error code
+ */drivers/media/i2c/ov5647.c new file +3
-0+static int ov5647_detect (struct v4l2_subdev *sd) +{ +unsigned char read;
ov5647_read()return value type is 'u8', please change it here and everywhere else in the code.
OK.
Quoted 97 lines
Quoted 97 lines
drivers/media/i2c/ov5647.c new file +97
-0+int ret; +struct i2c_client *client =v4l2_get_subdevdata (sd); + + ret =ov5647_write (sd,OV5647_SW_RESET ,0x01 ); +if (ret <0 ) +return ret; + + ret =ov5647_read (sd,OV5647_REG_CHIPID_H , &read); +if (ret <0 ) +return ret; + +if (read !=0x56 ) { +dev_err (&client->dev,"Wrong model version detected" ); +return -ENODEV ; + } + + ret =ov5647_read (sd,OV5647_REG_CHIPID_L , &read); +if (ret <0 ) +return ret; + +if (read !=0x47 ) { +dev_err (&client->dev,"Wrong model version detected" ); +return -ENODEV ; + } + +return ov5647_write (sd,OV5647_SW_RESET ,0x00 ); +} + +/** +* @short Detect if camera is registered +* @param[in] sd v4l2 subdev +* @return Error code +*/ +static int ov5647_registered (struct v4l2_subdev *sd) +{ +return 0 ; +} + +/** +* @short Open device +* @param[in] sd v4l2 subdev +* @param[in] fh v4l2 file handler +* @return Error code +*/ +static int ov5647_open (struct v4l2_subdev *sd,struct v4l2_subdev_fh *fh) +{ +struct v4l2_mbus_framefmt *format = +v4l2_subdev_get_try_format (sd, fh->pad,0 ); +struct v4l2_rect *crop = +v4l2_subdev_get_try_crop (sd, fh->pad,0 ); + + crop->left =OV5647_COLUMN_START_DEF ; + crop->top =OV5647_ROW_START_DEF ; + crop->width =OV5647_WINDOW_WIDTH_DEF ; + crop->height =OV5647_WINDOW_HEIGHT_DEF ; + + format->code =MEDIA_BUS_FMT_SBGGR8_1X8 ; + + format->width =OV5647_WINDOW_WIDTH_DEF ; + format->height =OV5647_WINDOW_HEIGHT_DEF ; + format->field =V4L2_FIELD_NONE ; + format->colorspace =V4L2_COLORSPACE_SRGB ; + +return sensor_power (sd, true); +} + +/** +* @short Open device +* @param[in] sd v4l2 subdev +* @param[in] fh v4l2 file handler +* @return Error code +*/ +static int ov5647_close (struct v4l2_subdev *sd,struct v4l2_subdev_fh *fh) +{ +return sensor_power (sd, false); +} + +/** +* @short Subdev internal operations registration +* +*/ +static const struct v4l2_subdev_internal_ops ov5647_subdev_internal_ops = { + .registered = ov5647_registered, + .open = ov5647_open, + .close = ov5647_close, +}; + +/** +* @short Initialization routine - Entry point of the driver +* @param[in] client pointer to the i2c client structure +* @param[in] id pointer to the i2c device id structure +* @return 0 on success and a negative number on failure +*/ +static int ov5647_probe (struct i2c_client *client, +const struct i2c_device_id *id) +{ +struct device *dev = &client->dev;
Quoted 9 lines
drivers/media/i2c/ov5647.c line 637
Quoted 5 lines
drivers/media/i2c/ov5647.c new file +5
-0+struct ov5647 *sensor; +int ret; +struct v4l2_subdev *sd; + +dev_info (&client->dev,"Installing OmniVision OV5647 camera driver\n" );Please remove the informational line, it will pollute the kernel log for no good reason.
Is it okay if I change it to debug?
Quoted 15 lines
Quoted 15 lines
drivers/media/i2c/ov5647.c new file +15
-0+ + sensor =devm_kzalloc (dev,sizeof (*sensor),GFP_KERNEL ); +if (sensor ==NULL ) +return -ENOMEM ; + +/* get system clock (xclk) */ + sensor->xclk =devm_clk_get (dev,"xclk" ); +if (IS_ERR (sensor->xclk)) { +dev_err (dev,"could not get xclk" ); +return PTR_ERR (sensor->xclk); + } + + ret =of_property_read_u32 (dev->of_node,"clock-frequency" , + &sensor->xclk_freq); +if (ret) {
Quoted 9 lines
drivers/media/i2c/ov5647.c line 658
Quoted 6 lines
drivers/media/i2c/ov5647.c new file +6
-0+dev_err (dev,"could not get xclk frequency\n" ); +return ret; + } + +mutex_init (&sensor->lock); + sensor->dev = dev;
sensor->devis unused, please remove it from the 'struct ov5647' declaration.
Ok.
Quoted 46 lines
Quoted 46 lines
drivers/media/i2c/ov5647.c new file +46
-0+ + sd = &sensor->sd; +v4l2_i2c_subdev_init (sd, client, &subdev_ops); + sensor->sd.flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ; + + sensor->pad.flags =MEDIA_PAD_FL_SOURCE ; + sd->entity.function =MEDIA_ENT_F_CAM_SENSOR ; + ret =media_entity_pads_init (&sd->entity,1 , &sensor->pad); +if (ret <0 ) + goto mutex_remove; + + ret =ov5647_detect (sd); +if (ret <0 ) + goto error; + + ret =v4l2_async_register_subdev (sd); +if (ret <0 ) + goto error; + +return 0 ; +error: +media_entity_cleanup (&sd->entity); +mutex_remove: +mutex_destroy (&sensor->lock); +return ret; +} + +/** +* @short Exit routine - Exit point of the driver +* @param[in] client pointer to the i2c client structure +* @return 0 on success and a negative number on failure +*/ +static int ov5647_remove (struct i2c_client *client) +{ +struct v4l2_subdev *sd =i2c_get_clientdata (client); +struct ov5647 *ov5647 =to_state (sd); + +v4l2_async_unregister_subdev (&ov5647->sd); +media_entity_cleanup (&ov5647->sd.entity); +v4l2_device_unregister_subdev (sd); +mutex_destroy (&ov5647->lock); + +return 0 ; +} + +static const struct i2c_device_id ov5647_id[] = {
Quoted 9 lines
drivers/media/i2c/ov5647.c line 710
Quoted 6 lines
drivers/media/i2c/ov5647.c new file +6
-0+ { "ov5647", 0 }, + { } +}; +MODULE_DEVICE_TABLE (i2c, ov5647_id); + +#if IS_ENABLED (CONFIG_OF )From
Kconfigthe driver depends on OF.
You're right. Do you think I should remove the dependency in Kconfig or the check here?
Quoted 7 lines
Quoted 7 lines
drivers/media/i2c/ov5647.c new file +7
-0+static const struct of_device_id ov5647_of_match[] = { + { .compatible ="ovti,ov5647" }, + {/* sentinel */ }, +}; +MODULE_DEVICE_TABLE (of, ov5647_of_match); +#endif +
Quoted 9 lines
drivers/media/i2c/ov5647.c line 723
Quoted 6 lines
drivers/media/i2c/ov5647.c new file +6
-0+/** +* @short i2c driver structure +*/ +static struct i2c_driver ov5647_driver = { + .driver = { + .of_match_table =of_match_ptr (ov5647_of_match),Same comment as above, from
Kconfigthe driver depends on OF.
I'm sorry but I'm not understanding what you're trying to say.
Quoted 4 lines
drivers/media/i2c/ov5647.c line 724
Quoted 1 line
drivers/media/i2c/ov5647.c new file +1
-0+ .owner = THIS_MODULE,.owner is set by the core, please remove it.
Ok.
Quoted 6 lines
drivers/media/i2c/ov5647.c line 725
Quoted 1 line
drivers/media/i2c/ov5647.c new file +1
-0+ .name = "ov5647",May be .name =
SENSOR_NAME, ?Otherwise
SENSOR_NAMEmacro is unused and it should be removed.
I'll change it to .name = SENSOR_NAME,
Quoted 17 lines
drivers/media/i2c/ov5647.c line 736
Quoted 12 lines
drivers/media/i2c/ov5647.c new file +11
-0+ }, + .probe = ov5647_probe, + .remove = ov5647_remove, + .id_table = ov5647_id, +}; + +module_i2c_driver (ov5647_driver); + +MODULE_AUTHOR ("Ramiro Oliveira <roliveir-HKixBCOQz3hWk0Htik3J/[email protected]>" ); +MODULE_DESCRIPTION ("A low-level driver for OmniVision ov5647 sensors" ); +MODULE_LICENSE ("GPL v2" );--
With best wishes,
Vladimir
Signature · 8 lines
Best Regards Ramiro Oliveira Ramiro.Oliveira-HKixBCOQz3hWk0Htik3J/[email protected] -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v8 2/2] Add support for OV5647 sensor.
Hi Ramiro,
Quoted 11 lines · Ramiro Oliveira
Hi Vladimir,
Thank you for your feedback.
Quoted 6 lines · Vladimir Zapolskiy
Hello Ramiro,
Quoted 3 lines · Ramiro Oliveira
Modes supported:
- 640x480 RAW 8
[snip]
Quoted 14 lines
Quoted 4 lines
Quoted 4 lines
drivers/media/i2c/ov5647.c new file +4
-0+static int ov5647_probe (struct i2c_client *client, +const struct i2c_device_id *id) +{ +struct device *dev = &client->dev;Quoted 9 lines
drivers/media/i2c/ov5647.c line 637
Quoted 5 lines
drivers/media/i2c/ov5647.c new file +5
-0+struct ov5647 *sensor; +int ret; +struct v4l2_subdev *sd; + +dev_info (&client->dev,"Installing OmniVision OV5647 camera driver\n" );Please remove the informational line, it will pollute the kernel log for no good reason.
Quoted 2 lines
Is it okay if I change it to debug?
Most probably here it is okay to change it to dev_dbg(), however
1) please note that ftrace functionality should provide all the magic for you, and by the way this makes dev_dbg() calls from ov5647_write(), ov5647_read(), ov5647_stream_on(), ov5647_stream_off() and __sensor_init() all redundant,
2) please move the informational message to the end of the .probe function, right before returning success to avoid duplicates on deferred re-probing:
dev_dbg(&client->dev, "OmniVision OV5647 camera driver probed\n"); ^^^^^^^^
[snip]
Quoted 12 lines
Quoted 11 lines
drivers/media/i2c/ov5647.c line 710
Quoted 8 lines
drivers/media/i2c/ov5647.c new file +8
-0+ +static const struct i2c_device_id ov5647_id[] = { + {"ov5647" ,0 }, + { } +}; +MODULE_DEVICE_TABLE (i2c, ov5647_id); + +#if IS_ENABLED (CONFIG_OF )From
Kconfigthe driver depends on OF.
Quoted 3 lines
You're right. Do you think I should remove the dependency in
Kconfigor the check here?
Let see...
I've been able to locate only one place where OF dependency is utterly needed:
ret = of_property_read_u32(dev->of_node, "clock-frequency",
&sensor->xclk_freq);
if (ret) {
dev_err(dev, "could not get xclk frequency\n");
return ret;
}It might be preferred to change this snippet of code into something like one below:
sensor->xclk_freq = clk_get_rate(sensor->xclk);
if (sensor->xclk_freq != 30000000) {
dev_err(dev, "Unsupported clock frequency: %lu\n",
sensor->xclk_freq);
return -EINVAL;
}Then
1) in case of an OF platform "xclk" clock frequency can be set directly in a board DTS file, please reference to clock-bindings.txt,
2) next you can drop 'clock-frequency' property from the sensor bindings,
3) you can drop 'depends on OF' from drivers/media/i2c/Kconfig,
4) you can drop 'clk_set_rate()' from sensor_power().
The proposed code is slightly more flexible, at least the change gives a little chance to run the driver successfully on a non-OF platform, otherwise it is known in advance that the driver is unusable on any non-OF platforms and thus an explicit CONFIG_OF build dependency makes sense.
Quoted 17 lines
Quoted 7 lines
Quoted 7 lines
drivers/media/i2c/ov5647.c new file +7
-0+static const struct of_device_id ov5647_of_match[] = { + { .compatible ="ovti,ov5647" }, + {/* sentinel */ }, +}; +MODULE_DEVICE_TABLE (of, ov5647_of_match); +#endif +Quoted 9 lines
drivers/media/i2c/ov5647.c line 723
Quoted 6 lines
drivers/media/i2c/ov5647.c new file +6
-0+/** +* @short i2c driver structure +*/ +static struct i2c_driver ov5647_driver = { + .driver = { + .of_match_table =of_match_ptr (ov5647_of_match),Same comment as above, from
Kconfigthe driver depends on OF.
Quoted 2 lines
I'm sorry but I'm not understanding what you're trying to say.
You may take a look at of_match_ptr() macro definition from include/linux/of.h:
#ifdef CONFIG_OF
...
#define of_match_ptr(_ptr) (_ptr)
...
#else
...
#define of_match_ptr(_ptr) NULL
...
#endif
Hence if the code compilation always depends on the enabled CONFIG_OF option, then of_match_ptr() macro should be dropped:
.of_match_table = ov5647_of_match,
Quoted 7 lines
Quoted 4 lines
drivers/media/i2c/ov5647.c line 724
Quoted 1 line
drivers/media/i2c/ov5647.c new file +1
-0+ .owner = THIS_MODULE,.owner is set by the core, please remove it.
Ok.
Quoted 22 lines
Quoted 6 lines
drivers/media/i2c/ov5647.c line 725
Quoted 1 line
drivers/media/i2c/ov5647.c new file +1
-0+ .name = "ov5647",May be .name =
SENSOR_NAME, ?Otherwise
SENSOR_NAMEmacro is unused and it should be removed.I'll change it to .name =
SENSOR_NAME,Quoted 13 lines
Quoted 12 lines
drivers/media/i2c/ov5647.c new file +11
-0+ }, + .probe = ov5647_probe, + .remove = ov5647_remove, + .id_table = ov5647_id, +}; + +module_i2c_driver (ov5647_driver); + +MODULE_AUTHOR ("Ramiro Oliveira <roliveir-HKixBCOQz3hWk0Htik3J/[email protected]>" ); +MODULE_DESCRIPTION ("A low-level driver for OmniVision ov5647 sensors" ); +MODULE_LICENSE ("GPL v2" );
--
With best wishes,
Vladimir
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html