|
@@ -91,51 +91,49 @@ struct mt9v022 {
|
|
|
u16 chip_control;
|
|
|
};
|
|
|
|
|
|
-static int reg_read(struct soc_camera_device *icd, const u8 reg)
|
|
|
+static int reg_read(struct i2c_client *client, const u8 reg)
|
|
|
{
|
|
|
- struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd);
|
|
|
- struct i2c_client *client = mt9v022->client;
|
|
|
s32 data = i2c_smbus_read_word_data(client, reg);
|
|
|
return data < 0 ? data : swab16(data);
|
|
|
}
|
|
|
|
|
|
-static int reg_write(struct soc_camera_device *icd, const u8 reg,
|
|
|
+static int reg_write(struct i2c_client *client, const u8 reg,
|
|
|
const u16 data)
|
|
|
{
|
|
|
- struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd);
|
|
|
- return i2c_smbus_write_word_data(mt9v022->client, reg, swab16(data));
|
|
|
+ return i2c_smbus_write_word_data(client, reg, swab16(data));
|
|
|
}
|
|
|
|
|
|
-static int reg_set(struct soc_camera_device *icd, const u8 reg,
|
|
|
+static int reg_set(struct i2c_client *client, const u8 reg,
|
|
|
const u16 data)
|
|
|
{
|
|
|
int ret;
|
|
|
|
|
|
- ret = reg_read(icd, reg);
|
|
|
+ ret = reg_read(client, reg);
|
|
|
if (ret < 0)
|
|
|
return ret;
|
|
|
- return reg_write(icd, reg, ret | data);
|
|
|
+ return reg_write(client, reg, ret | data);
|
|
|
}
|
|
|
|
|
|
-static int reg_clear(struct soc_camera_device *icd, const u8 reg,
|
|
|
+static int reg_clear(struct i2c_client *client, const u8 reg,
|
|
|
const u16 data)
|
|
|
{
|
|
|
int ret;
|
|
|
|
|
|
- ret = reg_read(icd, reg);
|
|
|
+ ret = reg_read(client, reg);
|
|
|
if (ret < 0)
|
|
|
return ret;
|
|
|
- return reg_write(icd, reg, ret & ~data);
|
|
|
+ return reg_write(client, reg, ret & ~data);
|
|
|
}
|
|
|
|
|
|
static int mt9v022_init(struct soc_camera_device *icd)
|
|
|
{
|
|
|
+ struct i2c_client *client = to_i2c_client(icd->control);
|
|
|
struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd);
|
|
|
- struct soc_camera_link *icl = mt9v022->client->dev.platform_data;
|
|
|
+ struct soc_camera_link *icl = client->dev.platform_data;
|
|
|
int ret;
|
|
|
|
|
|
if (icl->power) {
|
|
|
- ret = icl->power(&mt9v022->client->dev, 1);
|
|
|
+ ret = icl->power(&client->dev, 1);
|
|
|
if (ret < 0) {
|
|
|
dev_err(icd->vdev->parent,
|
|
|
"Platform failed to power-on the camera.\n");
|
|
@@ -148,27 +146,27 @@ static int mt9v022_init(struct soc_camera_device *icd)
|
|
|
* if available. Soft reset is done in video_probe().
|
|
|
*/
|
|
|
if (icl->reset)
|
|
|
- icl->reset(&mt9v022->client->dev);
|
|
|
+ icl->reset(&client->dev);
|
|
|
|
|
|
/* Almost the default mode: master, parallel, simultaneous, and an
|
|
|
* undocumented bit 0x200, which is present in table 7, but not in 8,
|
|
|
* plus snapshot mode to disable scan for now */
|
|
|
mt9v022->chip_control |= 0x10;
|
|
|
- ret = reg_write(icd, MT9V022_CHIP_CONTROL, mt9v022->chip_control);
|
|
|
+ ret = reg_write(client, MT9V022_CHIP_CONTROL, mt9v022->chip_control);
|
|
|
if (!ret)
|
|
|
- ret = reg_write(icd, MT9V022_READ_MODE, 0x300);
|
|
|
+ ret = reg_write(client, MT9V022_READ_MODE, 0x300);
|
|
|
|
|
|
/* All defaults */
|
|
|
if (!ret)
|
|
|
/* AEC, AGC on */
|
|
|
- ret = reg_set(icd, MT9V022_AEC_AGC_ENABLE, 0x3);
|
|
|
+ ret = reg_set(client, MT9V022_AEC_AGC_ENABLE, 0x3);
|
|
|
if (!ret)
|
|
|
- ret = reg_write(icd, MT9V022_MAX_TOTAL_SHUTTER_WIDTH, 480);
|
|
|
+ ret = reg_write(client, MT9V022_MAX_TOTAL_SHUTTER_WIDTH, 480);
|
|
|
if (!ret)
|
|
|
/* default - auto */
|
|
|
- ret = reg_clear(icd, MT9V022_BLACK_LEVEL_CALIB_CTRL, 1);
|
|
|
+ ret = reg_clear(client, MT9V022_BLACK_LEVEL_CALIB_CTRL, 1);
|
|
|
if (!ret)
|
|
|
- ret = reg_write(icd, MT9V022_DIGITAL_TEST_PATTERN, 0);
|
|
|
+ ret = reg_write(client, MT9V022_DIGITAL_TEST_PATTERN, 0);
|
|
|
|
|
|
return ret;
|
|
|
}
|
|
@@ -186,10 +184,11 @@ static int mt9v022_release(struct soc_camera_device *icd)
|
|
|
|
|
|
static int mt9v022_start_capture(struct soc_camera_device *icd)
|
|
|
{
|
|
|
+ struct i2c_client *client = to_i2c_client(icd->control);
|
|
|
struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd);
|
|
|
/* Switch to master "normal" mode */
|
|
|
mt9v022->chip_control &= ~0x10;
|
|
|
- if (reg_write(icd, MT9V022_CHIP_CONTROL,
|
|
|
+ if (reg_write(client, MT9V022_CHIP_CONTROL,
|
|
|
mt9v022->chip_control) < 0)
|
|
|
return -EIO;
|
|
|
return 0;
|
|
@@ -197,10 +196,11 @@ static int mt9v022_start_capture(struct soc_camera_device *icd)
|
|
|
|
|
|
static int mt9v022_stop_capture(struct soc_camera_device *icd)
|
|
|
{
|
|
|
+ struct i2c_client *client = to_i2c_client(icd->control);
|
|
|
struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd);
|
|
|
/* Switch to snapshot mode */
|
|
|
mt9v022->chip_control |= 0x10;
|
|
|
- if (reg_write(icd, MT9V022_CHIP_CONTROL,
|
|
|
+ if (reg_write(client, MT9V022_CHIP_CONTROL,
|
|
|
mt9v022->chip_control) < 0)
|
|
|
return -EIO;
|
|
|
return 0;
|
|
@@ -209,8 +209,9 @@ static int mt9v022_stop_capture(struct soc_camera_device *icd)
|
|
|
static int mt9v022_set_bus_param(struct soc_camera_device *icd,
|
|
|
unsigned long flags)
|
|
|
{
|
|
|
+ struct i2c_client *client = to_i2c_client(icd->control);
|
|
|
struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd);
|
|
|
- struct soc_camera_link *icl = mt9v022->client->dev.platform_data;
|
|
|
+ struct soc_camera_link *icl = client->dev.platform_data;
|
|
|
unsigned int width_flag = flags & SOCAM_DATAWIDTH_MASK;
|
|
|
int ret;
|
|
|
u16 pixclk = 0;
|
|
@@ -243,14 +244,14 @@ static int mt9v022_set_bus_param(struct soc_camera_device *icd,
|
|
|
if (!(flags & SOCAM_VSYNC_ACTIVE_HIGH))
|
|
|
pixclk |= 0x2;
|
|
|
|
|
|
- ret = reg_write(icd, MT9V022_PIXCLK_FV_LV, pixclk);
|
|
|
+ ret = reg_write(client, MT9V022_PIXCLK_FV_LV, pixclk);
|
|
|
if (ret < 0)
|
|
|
return ret;
|
|
|
|
|
|
if (!(flags & SOCAM_MASTER))
|
|
|
mt9v022->chip_control &= ~0x8;
|
|
|
|
|
|
- ret = reg_write(icd, MT9V022_CHIP_CONTROL, mt9v022->chip_control);
|
|
|
+ ret = reg_write(client, MT9V022_CHIP_CONTROL, mt9v022->chip_control);
|
|
|
if (ret < 0)
|
|
|
return ret;
|
|
|
|
|
@@ -282,35 +283,36 @@ static unsigned long mt9v022_query_bus_param(struct soc_camera_device *icd)
|
|
|
static int mt9v022_set_crop(struct soc_camera_device *icd,
|
|
|
struct v4l2_rect *rect)
|
|
|
{
|
|
|
+ struct i2c_client *client = to_i2c_client(icd->control);
|
|
|
int ret;
|
|
|
|
|
|
/* Like in example app. Contradicts the datasheet though */
|
|
|
- ret = reg_read(icd, MT9V022_AEC_AGC_ENABLE);
|
|
|
+ ret = reg_read(client, MT9V022_AEC_AGC_ENABLE);
|
|
|
if (ret >= 0) {
|
|
|
if (ret & 1) /* Autoexposure */
|
|
|
- ret = reg_write(icd, MT9V022_MAX_TOTAL_SHUTTER_WIDTH,
|
|
|
+ ret = reg_write(client, MT9V022_MAX_TOTAL_SHUTTER_WIDTH,
|
|
|
rect->height + icd->y_skip_top + 43);
|
|
|
else
|
|
|
- ret = reg_write(icd, MT9V022_TOTAL_SHUTTER_WIDTH,
|
|
|
+ ret = reg_write(client, MT9V022_TOTAL_SHUTTER_WIDTH,
|
|
|
rect->height + icd->y_skip_top + 43);
|
|
|
}
|
|
|
/* Setup frame format: defaults apart from width and height */
|
|
|
if (!ret)
|
|
|
- ret = reg_write(icd, MT9V022_COLUMN_START, rect->left);
|
|
|
+ ret = reg_write(client, MT9V022_COLUMN_START, rect->left);
|
|
|
if (!ret)
|
|
|
- ret = reg_write(icd, MT9V022_ROW_START, rect->top);
|
|
|
+ ret = reg_write(client, MT9V022_ROW_START, rect->top);
|
|
|
if (!ret)
|
|
|
/* Default 94, Phytec driver says:
|
|
|
* "width + horizontal blank >= 660" */
|
|
|
- ret = reg_write(icd, MT9V022_HORIZONTAL_BLANKING,
|
|
|
+ ret = reg_write(client, MT9V022_HORIZONTAL_BLANKING,
|
|
|
rect->width > 660 - 43 ? 43 :
|
|
|
660 - rect->width);
|
|
|
if (!ret)
|
|
|
- ret = reg_write(icd, MT9V022_VERTICAL_BLANKING, 45);
|
|
|
+ ret = reg_write(client, MT9V022_VERTICAL_BLANKING, 45);
|
|
|
if (!ret)
|
|
|
- ret = reg_write(icd, MT9V022_WINDOW_WIDTH, rect->width);
|
|
|
+ ret = reg_write(client, MT9V022_WINDOW_WIDTH, rect->width);
|
|
|
if (!ret)
|
|
|
- ret = reg_write(icd, MT9V022_WINDOW_HEIGHT,
|
|
|
+ ret = reg_write(client, MT9V022_WINDOW_HEIGHT,
|
|
|
rect->height + icd->y_skip_top);
|
|
|
|
|
|
if (ret < 0)
|
|
@@ -396,16 +398,16 @@ static int mt9v022_get_chip_id(struct soc_camera_device *icd,
|
|
|
static int mt9v022_get_register(struct soc_camera_device *icd,
|
|
|
struct v4l2_dbg_register *reg)
|
|
|
{
|
|
|
- struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd);
|
|
|
+ struct i2c_client *client = to_i2c_client(icd->control);
|
|
|
|
|
|
if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0xff)
|
|
|
return -EINVAL;
|
|
|
|
|
|
- if (reg->match.addr != mt9v022->client->addr)
|
|
|
+ if (reg->match.addr != client->addr)
|
|
|
return -ENODEV;
|
|
|
|
|
|
reg->size = 2;
|
|
|
- reg->val = reg_read(icd, reg->reg);
|
|
|
+ reg->val = reg_read(client, reg->reg);
|
|
|
|
|
|
if (reg->val > 0xffff)
|
|
|
return -EIO;
|
|
@@ -416,15 +418,15 @@ static int mt9v022_get_register(struct soc_camera_device *icd,
|
|
|
static int mt9v022_set_register(struct soc_camera_device *icd,
|
|
|
struct v4l2_dbg_register *reg)
|
|
|
{
|
|
|
- struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd);
|
|
|
+ struct i2c_client *client = to_i2c_client(icd->control);
|
|
|
|
|
|
if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0xff)
|
|
|
return -EINVAL;
|
|
|
|
|
|
- if (reg->match.addr != mt9v022->client->addr)
|
|
|
+ if (reg->match.addr != client->addr)
|
|
|
return -ENODEV;
|
|
|
|
|
|
- if (reg_write(icd, reg->reg, reg->val) < 0)
|
|
|
+ if (reg_write(client, reg->reg, reg->val) < 0)
|
|
|
return -EIO;
|
|
|
|
|
|
return 0;
|
|
@@ -517,29 +519,30 @@ static struct soc_camera_ops mt9v022_ops = {
|
|
|
static int mt9v022_get_control(struct soc_camera_device *icd,
|
|
|
struct v4l2_control *ctrl)
|
|
|
{
|
|
|
+ struct i2c_client *client = to_i2c_client(icd->control);
|
|
|
int data;
|
|
|
|
|
|
switch (ctrl->id) {
|
|
|
case V4L2_CID_VFLIP:
|
|
|
- data = reg_read(icd, MT9V022_READ_MODE);
|
|
|
+ data = reg_read(client, MT9V022_READ_MODE);
|
|
|
if (data < 0)
|
|
|
return -EIO;
|
|
|
ctrl->value = !!(data & 0x10);
|
|
|
break;
|
|
|
case V4L2_CID_HFLIP:
|
|
|
- data = reg_read(icd, MT9V022_READ_MODE);
|
|
|
+ data = reg_read(client, MT9V022_READ_MODE);
|
|
|
if (data < 0)
|
|
|
return -EIO;
|
|
|
ctrl->value = !!(data & 0x20);
|
|
|
break;
|
|
|
case V4L2_CID_EXPOSURE_AUTO:
|
|
|
- data = reg_read(icd, MT9V022_AEC_AGC_ENABLE);
|
|
|
+ data = reg_read(client, MT9V022_AEC_AGC_ENABLE);
|
|
|
if (data < 0)
|
|
|
return -EIO;
|
|
|
ctrl->value = !!(data & 0x1);
|
|
|
break;
|
|
|
case V4L2_CID_AUTOGAIN:
|
|
|
- data = reg_read(icd, MT9V022_AEC_AGC_ENABLE);
|
|
|
+ data = reg_read(client, MT9V022_AEC_AGC_ENABLE);
|
|
|
if (data < 0)
|
|
|
return -EIO;
|
|
|
ctrl->value = !!(data & 0x2);
|
|
@@ -552,6 +555,7 @@ static int mt9v022_set_control(struct soc_camera_device *icd,
|
|
|
struct v4l2_control *ctrl)
|
|
|
{
|
|
|
int data;
|
|
|
+ struct i2c_client *client = to_i2c_client(icd->control);
|
|
|
const struct v4l2_queryctrl *qctrl;
|
|
|
|
|
|
qctrl = soc_camera_find_qctrl(&mt9v022_ops, ctrl->id);
|
|
@@ -562,17 +566,17 @@ static int mt9v022_set_control(struct soc_camera_device *icd,
|
|
|
switch (ctrl->id) {
|
|
|
case V4L2_CID_VFLIP:
|
|
|
if (ctrl->value)
|
|
|
- data = reg_set(icd, MT9V022_READ_MODE, 0x10);
|
|
|
+ data = reg_set(client, MT9V022_READ_MODE, 0x10);
|
|
|
else
|
|
|
- data = reg_clear(icd, MT9V022_READ_MODE, 0x10);
|
|
|
+ data = reg_clear(client, MT9V022_READ_MODE, 0x10);
|
|
|
if (data < 0)
|
|
|
return -EIO;
|
|
|
break;
|
|
|
case V4L2_CID_HFLIP:
|
|
|
if (ctrl->value)
|
|
|
- data = reg_set(icd, MT9V022_READ_MODE, 0x20);
|
|
|
+ data = reg_set(client, MT9V022_READ_MODE, 0x20);
|
|
|
else
|
|
|
- data = reg_clear(icd, MT9V022_READ_MODE, 0x20);
|
|
|
+ data = reg_clear(client, MT9V022_READ_MODE, 0x20);
|
|
|
if (data < 0)
|
|
|
return -EIO;
|
|
|
break;
|
|
@@ -593,12 +597,12 @@ static int mt9v022_set_control(struct soc_camera_device *icd,
|
|
|
/* The user wants to set gain manually, hope, she
|
|
|
* knows, what she's doing... Switch AGC off. */
|
|
|
|
|
|
- if (reg_clear(icd, MT9V022_AEC_AGC_ENABLE, 0x2) < 0)
|
|
|
+ if (reg_clear(client, MT9V022_AEC_AGC_ENABLE, 0x2) < 0)
|
|
|
return -EIO;
|
|
|
|
|
|
dev_info(&icd->dev, "Setting gain from %d to %lu\n",
|
|
|
- reg_read(icd, MT9V022_ANALOG_GAIN), gain);
|
|
|
- if (reg_write(icd, MT9V022_ANALOG_GAIN, gain) < 0)
|
|
|
+ reg_read(client, MT9V022_ANALOG_GAIN), gain);
|
|
|
+ if (reg_write(client, MT9V022_ANALOG_GAIN, gain) < 0)
|
|
|
return -EIO;
|
|
|
icd->gain = ctrl->value;
|
|
|
}
|
|
@@ -614,13 +618,13 @@ static int mt9v022_set_control(struct soc_camera_device *icd,
|
|
|
/* The user wants to set shutter width manually, hope,
|
|
|
* she knows, what she's doing... Switch AEC off. */
|
|
|
|
|
|
- if (reg_clear(icd, MT9V022_AEC_AGC_ENABLE, 0x1) < 0)
|
|
|
+ if (reg_clear(client, MT9V022_AEC_AGC_ENABLE, 0x1) < 0)
|
|
|
return -EIO;
|
|
|
|
|
|
dev_dbg(&icd->dev, "Shutter width from %d to %lu\n",
|
|
|
- reg_read(icd, MT9V022_TOTAL_SHUTTER_WIDTH),
|
|
|
+ reg_read(client, MT9V022_TOTAL_SHUTTER_WIDTH),
|
|
|
shutter);
|
|
|
- if (reg_write(icd, MT9V022_TOTAL_SHUTTER_WIDTH,
|
|
|
+ if (reg_write(client, MT9V022_TOTAL_SHUTTER_WIDTH,
|
|
|
shutter) < 0)
|
|
|
return -EIO;
|
|
|
icd->exposure = ctrl->value;
|
|
@@ -628,17 +632,17 @@ static int mt9v022_set_control(struct soc_camera_device *icd,
|
|
|
break;
|
|
|
case V4L2_CID_AUTOGAIN:
|
|
|
if (ctrl->value)
|
|
|
- data = reg_set(icd, MT9V022_AEC_AGC_ENABLE, 0x2);
|
|
|
+ data = reg_set(client, MT9V022_AEC_AGC_ENABLE, 0x2);
|
|
|
else
|
|
|
- data = reg_clear(icd, MT9V022_AEC_AGC_ENABLE, 0x2);
|
|
|
+ data = reg_clear(client, MT9V022_AEC_AGC_ENABLE, 0x2);
|
|
|
if (data < 0)
|
|
|
return -EIO;
|
|
|
break;
|
|
|
case V4L2_CID_EXPOSURE_AUTO:
|
|
|
if (ctrl->value)
|
|
|
- data = reg_set(icd, MT9V022_AEC_AGC_ENABLE, 0x1);
|
|
|
+ data = reg_set(client, MT9V022_AEC_AGC_ENABLE, 0x1);
|
|
|
else
|
|
|
- data = reg_clear(icd, MT9V022_AEC_AGC_ENABLE, 0x1);
|
|
|
+ data = reg_clear(client, MT9V022_AEC_AGC_ENABLE, 0x1);
|
|
|
if (data < 0)
|
|
|
return -EIO;
|
|
|
break;
|
|
@@ -650,8 +654,9 @@ static int mt9v022_set_control(struct soc_camera_device *icd,
|
|
|
* this wasn't our capture interface, so, we wait for the right one */
|
|
|
static int mt9v022_video_probe(struct soc_camera_device *icd)
|
|
|
{
|
|
|
+ struct i2c_client *client = to_i2c_client(icd->control);
|
|
|
struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd);
|
|
|
- struct soc_camera_link *icl = mt9v022->client->dev.platform_data;
|
|
|
+ struct soc_camera_link *icl = client->dev.platform_data;
|
|
|
s32 data;
|
|
|
int ret;
|
|
|
unsigned long flags;
|
|
@@ -661,7 +666,7 @@ static int mt9v022_video_probe(struct soc_camera_device *icd)
|
|
|
return -ENODEV;
|
|
|
|
|
|
/* Read out the chip version register */
|
|
|
- data = reg_read(icd, MT9V022_CHIP_VERSION);
|
|
|
+ data = reg_read(client, MT9V022_CHIP_VERSION);
|
|
|
|
|
|
/* must be 0x1311 or 0x1313 */
|
|
|
if (data != 0x1311 && data != 0x1313) {
|
|
@@ -672,12 +677,12 @@ static int mt9v022_video_probe(struct soc_camera_device *icd)
|
|
|
}
|
|
|
|
|
|
/* Soft reset */
|
|
|
- ret = reg_write(icd, MT9V022_RESET, 1);
|
|
|
+ ret = reg_write(client, MT9V022_RESET, 1);
|
|
|
if (ret < 0)
|
|
|
goto ei2c;
|
|
|
/* 15 clock cycles */
|
|
|
udelay(200);
|
|
|
- if (reg_read(icd, MT9V022_RESET)) {
|
|
|
+ if (reg_read(client, MT9V022_RESET)) {
|
|
|
dev_err(&icd->dev, "Resetting MT9V022 failed!\n");
|
|
|
goto ei2c;
|
|
|
}
|
|
@@ -685,11 +690,11 @@ static int mt9v022_video_probe(struct soc_camera_device *icd)
|
|
|
/* Set monochrome or colour sensor type */
|
|
|
if (sensor_type && (!strcmp("colour", sensor_type) ||
|
|
|
!strcmp("color", sensor_type))) {
|
|
|
- ret = reg_write(icd, MT9V022_PIXEL_OPERATION_MODE, 4 | 0x11);
|
|
|
+ ret = reg_write(client, MT9V022_PIXEL_OPERATION_MODE, 4 | 0x11);
|
|
|
mt9v022->model = V4L2_IDENT_MT9V022IX7ATC;
|
|
|
icd->formats = mt9v022_colour_formats;
|
|
|
} else {
|
|
|
- ret = reg_write(icd, MT9V022_PIXEL_OPERATION_MODE, 0x11);
|
|
|
+ ret = reg_write(client, MT9V022_PIXEL_OPERATION_MODE, 0x11);
|
|
|
mt9v022->model = V4L2_IDENT_MT9V022IX7ATM;
|
|
|
icd->formats = mt9v022_monochrome_formats;
|
|
|
}
|