Skip to content

Instantly share code, notes, and snippets.

@fabwu
Created April 24, 2020 15:35
Show Gist options
  • Save fabwu/bb4f51725e5c67a109c893e368dbe98b to your computer and use it in GitHub Desktop.
Save fabwu/bb4f51725e5c67a109c893e368dbe98b to your computer and use it in GitHub Desktop.
#include <linux/i2c.h>
#define OV5693_REG_VALUE_08BIT 1
#define OV5693_REG_VALUE_16BIT 2
#define OV5695_REG_VALUE_24BIT 3
#define OV5693_SC_CMMN_CHIP_ID_H 0x300A
/* Read registers up to 4 at a time */
static int ov5693_read_reg(struct i2c_client *client, u16 reg, unsigned int len,
u32 *val)
{
struct i2c_msg msgs[2];
u8 *data_be_p;
__be32 data_be = 0;
__be16 reg_addr_be = cpu_to_be16(reg);
int ret;
if (len > 4)
return -EINVAL;
data_be_p = (u8 *)&data_be;
/* Write register address */
msgs[0].addr = client->addr;
msgs[0].flags = 0;
msgs[0].len = 2;
msgs[0].buf = (u8 *)&reg_addr_be;
/* Read data from register */
msgs[1].addr = client->addr;
msgs[1].flags = I2C_M_RD;
msgs[1].len = len;
msgs[1].buf = &data_be_p[4 - len];
ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
printk("ret %d\n", ret);
if (ret != ARRAY_SIZE(msgs))
return -EIO;
*val = be32_to_cpu(data_be);
return 0;
}
static int ov5693_probe(struct i2c_client *client)
{
int ret;
u32 id;
printk(KERN_ALERT "ov5693_probe\n");
printk("device addr %x\n",client->addr);
ret = ov5693_read_reg(client, OV5693_SC_CMMN_CHIP_ID_H,
OV5693_REG_VALUE_16BIT, &id);
if (ret) {
dev_err(&client->dev, "Unexpected sensor id(%06x), ret(%d)\n", id, ret);
return ret;
}
return 0;
}
static int __maybe_unused ov5693_suspend(struct device *dev)
{
printk(KERN_ALERT "ov5693_suspend\n");
return 0;
}
static int __maybe_unused ov5693_resume(struct device *dev)
{
printk(KERN_ALERT "ov5693_resume\n");
return 0;
}
static const struct dev_pm_ops ov5693_pm_ops = {
SET_SYSTEM_SLEEP_PM_OPS(ov5693_suspend, ov5693_resume)
};
#ifdef CONFIG_ACPI
static const struct acpi_device_id ov5693_acpi_ids[] = {
{"INT33BE"},
{}
};
MODULE_DEVICE_TABLE(acpi, ov5693_acpi_ids);
#endif
static struct i2c_driver ov5693_i2c_driver = {
.driver = {
.name = "ov5693",
.pm = &ov5693_pm_ops,
.acpi_match_table = ACPI_PTR(ov5693_acpi_ids),
},
.probe_new = ov5693_probe,
// .remove = ov5675_remove,
};
module_i2c_driver(ov5693_i2c_driver);
MODULE_AUTHOR("Fabian Wüthrich <me@fabwu.ch>");
MODULE_DESCRIPTION("OmniVision OV5693 sensor driver");
MODULE_LICENSE("GPL v2");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment