diff options
author | Troy Kisky <troy.kisky@boundarydevices.com> | 2014-03-04 19:26:35 -0700 |
---|---|---|
committer | Troy Kisky <troy.kisky@boundarydevices.com> | 2014-04-24 18:59:43 -0700 |
commit | 39d48307d65c0ce343d063d0000c6b97a93c518c (patch) | |
tree | 4ce36c00e0de62bce4d782773f9cc5d7e25b1d08 | |
parent | ab9bbf0b75c0902471da8cd69d36f724e99273da (diff) |
ov5642: add i2c address change feature
-rw-r--r--[-rwxr-xr-x] | drivers/media/platform/mxc/capture/ov5642.c | 51 |
1 files changed, 46 insertions, 5 deletions
diff --git a/drivers/media/platform/mxc/capture/ov5642.c b/drivers/media/platform/mxc/capture/ov5642.c index b6418fe8cb89..2aa9c8524dae 100755..100644 --- a/drivers/media/platform/mxc/capture/ov5642.c +++ b/drivers/media/platform/mxc/capture/ov5642.c @@ -4917,8 +4917,36 @@ static void ov5642_standby(s32 enable) msleep(2); } +static s32 update_device_addr(struct sensor_data *sensor) +{ + int ret; + u8 buf[4]; + unsigned reg = 0x3100; + unsigned default_addr = 0x3c; + struct i2c_msg msg; + + if (sensor->i2c_client->addr == default_addr) + return 0; + + buf[0] = reg >> 8; + buf[1] = reg & 0xff; + buf[2] = sensor->i2c_client->addr << 1; + msg.addr = default_addr; + msg.flags = 0; + msg.len = 3; + msg.buf = buf; + + + ret = i2c_transfer(sensor->i2c_client->adapter, &msg, 1); + if (ret < 0) + pr_err("%s: ov5642 ret=%d\n", __func__, ret); + return ret; +} + static void ov5642_reset(void) { + mxc_camera_common_lock(); + /* camera reset */ gpio_set_value(rst_gpio, 1); @@ -4933,7 +4961,9 @@ static void ov5642_reset(void) msleep(1); gpio_set_value(rst_gpio, 1); - msleep(5); + msleep(20); + update_device_addr(&ov5642_data); + mxc_camera_common_unlock(); gpio_set_value(pwn_gpio, 1); } @@ -5002,18 +5032,29 @@ static int ov5642_power_on(struct device *dev) static s32 ov5642_write_reg(u16 reg, u8 val) { + int ret; u8 au8Buf[3] = {0}; au8Buf[0] = reg >> 8; au8Buf[1] = reg & 0xff; au8Buf[2] = val; - if (i2c_master_send(ov5642_data.i2c_client, au8Buf, 3) < 0) { - pr_err("%s:write reg error:reg=%x,val=%x\n", - __func__, reg, val); - return -1; + if ((reg == 0x3008) && (val & 0x80)) { + mxc_camera_common_lock(); + + ret = i2c_master_send(ov5642_data.i2c_client, au8Buf, 3); + update_device_addr(&ov5642_data); + + mxc_camera_common_unlock(); + } else { + ret = i2c_master_send(ov5642_data.i2c_client, au8Buf, 3); } + if (ret < 0) { + pr_err("%s:write reg error:reg=%x,val=%x ret=%d\n", + __func__, reg, val, ret); + return ret; + } return 0; } |