1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2005-2006 Micronas USA Inc.
6 #include <linux/init.h>
7 #include <linux/module.h>
9 #include <linux/videodev2.h>
10 #include <media/v4l2-device.h>
11 #include <linux/slab.h>
13 MODULE_DESCRIPTION("OmniVision ov7640 sensor driver");
14 MODULE_LICENSE("GPL v2");
21 static const struct reg_val regval_init
[] = {
30 static int write_regs(struct i2c_client
*client
,
31 const struct reg_val
*rv
, int len
)
34 if (i2c_smbus_write_byte_data(client
, rv
->reg
, rv
->val
) < 0)
41 /* ----------------------------------------------------------------------- */
43 static const struct v4l2_subdev_ops ov7640_ops
;
45 static int ov7640_probe(struct i2c_client
*client
)
47 struct i2c_adapter
*adapter
= client
->adapter
;
48 struct v4l2_subdev
*sd
;
50 if (!i2c_check_functionality(adapter
, I2C_FUNC_SMBUS_BYTE_DATA
))
53 sd
= devm_kzalloc(&client
->dev
, sizeof(*sd
), GFP_KERNEL
);
56 v4l2_i2c_subdev_init(sd
, client
, &ov7640_ops
);
58 client
->flags
= I2C_CLIENT_SCCB
;
60 v4l_info(client
, "chip found @ 0x%02x (%s)\n",
61 client
->addr
<< 1, client
->adapter
->name
);
63 if (write_regs(client
, regval_init
, ARRAY_SIZE(regval_init
)) < 0) {
64 v4l_err(client
, "error initializing OV7640\n");
72 static void ov7640_remove(struct i2c_client
*client
)
74 struct v4l2_subdev
*sd
= i2c_get_clientdata(client
);
76 v4l2_device_unregister_subdev(sd
);
79 static const struct i2c_device_id ov7640_id
[] = {
83 MODULE_DEVICE_TABLE(i2c
, ov7640_id
);
85 static struct i2c_driver ov7640_driver
= {
89 .probe
= ov7640_probe
,
90 .remove
= ov7640_remove
,
91 .id_table
= ov7640_id
,
93 module_i2c_driver(ov7640_driver
);