Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3)  * Copyright (C) 2005-2006 Micronas USA Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) #include <linux/videodev2.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <media/v4l2-device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) MODULE_DESCRIPTION("OmniVision ov7640 sensor driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) MODULE_LICENSE("GPL v2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) static const u8 initial_registers[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) 	0x12, 0x80,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) 	0x12, 0x54,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) 	0x14, 0x24,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) 	0x15, 0x01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) 	0x28, 0x20,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) 	0x75, 0x82,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) 	0xFF, 0xFF, /* Terminator (reg 0xFF is unused) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) static int write_regs(struct i2c_client *client, const u8 *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 	for (i = 0; regs[i] != 0xFF; i += 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 		if (i2c_smbus_write_byte_data(client, regs[i], regs[i + 1]) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 			return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) /* ----------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) static const struct v4l2_subdev_ops ov7640_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) static int ov7640_probe(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 			const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 	struct i2c_adapter *adapter = client->adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 	struct v4l2_subdev *sd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 	sd = devm_kzalloc(&client->dev, sizeof(*sd), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 	if (sd == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 	v4l2_i2c_subdev_init(sd, client, &ov7640_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 	client->flags = I2C_CLIENT_SCCB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 	v4l_info(client, "chip found @ 0x%02x (%s)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 			client->addr << 1, client->adapter->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 	if (write_regs(client, initial_registers) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 		v4l_err(client, "error initializing OV7640\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) static int ov7640_remove(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) 	struct v4l2_subdev *sd = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) 	v4l2_device_unregister_subdev(sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) static const struct i2c_device_id ov7640_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) 	{ "ov7640", 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) MODULE_DEVICE_TABLE(i2c, ov7640_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) static struct i2c_driver ov7640_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) 		.name	= "ov7640",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) 	.probe = ov7640_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) 	.remove = ov7640_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) 	.id_table = ov7640_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) module_i2c_driver(ov7640_driver);