Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / media / i2c / ov7640.c
blob9f68d89936eb76b60ec238d0be72dd704df96841
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (C) 2005-2006 Micronas USA Inc.
4 */
6 #include <linux/init.h>
7 #include <linux/module.h>
8 #include <linux/i2c.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");
16 struct reg_val {
17 u8 reg;
18 u8 val;
21 static const struct reg_val regval_init[] = {
22 {0x12, 0x80},
23 {0x12, 0x54},
24 {0x14, 0x24},
25 {0x15, 0x01},
26 {0x28, 0x20},
27 {0x75, 0x82},
30 static int write_regs(struct i2c_client *client,
31 const struct reg_val *rv, int len)
33 while (--len >= 0) {
34 if (i2c_smbus_write_byte_data(client, rv->reg, rv->val) < 0)
35 return -1;
36 rv++;
38 return 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))
51 return -ENODEV;
53 sd = devm_kzalloc(&client->dev, sizeof(*sd), GFP_KERNEL);
54 if (sd == NULL)
55 return -ENOMEM;
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");
65 return -ENODEV;
68 return 0;
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[] = {
80 { "ov7640" },
81 { }
83 MODULE_DEVICE_TABLE(i2c, ov7640_id);
85 static struct i2c_driver ov7640_driver = {
86 .driver = {
87 .name = "ov7640",
89 .probe = ov7640_probe,
90 .remove = ov7640_remove,
91 .id_table = ov7640_id,
93 module_i2c_driver(ov7640_driver);