Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 138166
b: refs/heads/master
c: 09e231b
h: refs/heads/master
v: v3
  • Loading branch information
Guennadi Liakhovetski authored and Mauro Carvalho Chehab committed Mar 30, 2009
1 parent d075d8b commit a96d349
Show file tree
Hide file tree
Showing 13 changed files with 382 additions and 193 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 1cd3c0fa927084549005fc22e54d99684b314f14
refs/heads/master: 09e231b35173313cd92e27532e5028f2042dcee4
19 changes: 17 additions & 2 deletions trunk/drivers/media/video/mt9m001.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ static unsigned long mt9m001_query_bus_param(struct soc_camera_device *icd)
return soc_camera_apply_sensor_flags(icl, flags);
}

static int mt9m001_set_fmt(struct soc_camera_device *icd,
__u32 pixfmt, struct v4l2_rect *rect)
static int mt9m001_set_crop(struct soc_camera_device *icd,
struct v4l2_rect *rect)
{
struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd);
int ret;
Expand Down Expand Up @@ -324,6 +324,20 @@ static int mt9m001_set_fmt(struct soc_camera_device *icd,
return ret;
}

static int mt9m001_set_fmt(struct soc_camera_device *icd,
struct v4l2_format *f)
{
struct v4l2_rect rect = {
.left = icd->x_current,
.top = icd->y_current,
.width = f->fmt.pix.width,
.height = f->fmt.pix.height,
};

/* No support for scaling so far, just crop. TODO: use skipping */
return mt9m001_set_crop(icd, &rect);
}

static int mt9m001_try_fmt(struct soc_camera_device *icd,
struct v4l2_format *f)
{
Expand Down Expand Up @@ -449,6 +463,7 @@ static struct soc_camera_ops mt9m001_ops = {
.release = mt9m001_release,
.start_capture = mt9m001_start_capture,
.stop_capture = mt9m001_stop_capture,
.set_crop = mt9m001_set_crop,
.set_fmt = mt9m001_set_fmt,
.try_fmt = mt9m001_try_fmt,
.set_bus_param = mt9m001_set_bus_param,
Expand Down
56 changes: 39 additions & 17 deletions trunk/drivers/media/video/mt9m111.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ struct mt9m111 {
struct soc_camera_device icd;
int model; /* V4L2_IDENT_MT9M11x* codes from v4l2-chip-ident.h */
enum mt9m111_context context;
unsigned int left, top, width, height;
struct v4l2_rect rect;
u32 pixfmt;
unsigned char autoexposure;
unsigned char datawidth;
Expand Down Expand Up @@ -249,22 +249,23 @@ static int mt9m111_set_context(struct soc_camera_device *icd,
return reg_write(CONTEXT_CONTROL, valA);
}

static int mt9m111_setup_rect(struct soc_camera_device *icd)
static int mt9m111_setup_rect(struct soc_camera_device *icd,
struct v4l2_rect *rect)
{
struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
int ret, is_raw_format;
int width = mt9m111->width;
int height = mt9m111->height;
int width = rect->width;
int height = rect->height;

if ((mt9m111->pixfmt == V4L2_PIX_FMT_SBGGR8)
|| (mt9m111->pixfmt == V4L2_PIX_FMT_SBGGR16))
is_raw_format = 1;
else
is_raw_format = 0;

ret = reg_write(COLUMN_START, mt9m111->left);
ret = reg_write(COLUMN_START, rect->left);
if (!ret)
ret = reg_write(ROW_START, mt9m111->top);
ret = reg_write(ROW_START, rect->top);

if (is_raw_format) {
if (!ret)
Expand Down Expand Up @@ -436,6 +437,22 @@ static int mt9m111_set_bus_param(struct soc_camera_device *icd, unsigned long f)
return 0;
}

static int mt9m111_set_crop(struct soc_camera_device *icd,
struct v4l2_rect *rect)
{
struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
int ret;

dev_dbg(&icd->dev, "%s left=%d, top=%d, width=%d, height=%d\n",
__func__, rect->left, rect->top, rect->width,
rect->height);

ret = mt9m111_setup_rect(icd, rect);
if (!ret)
mt9m111->rect = *rect;
return ret;
}

static int mt9m111_set_pixfmt(struct soc_camera_device *icd, u32 pixfmt)
{
struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
Expand Down Expand Up @@ -486,23 +503,27 @@ static int mt9m111_set_pixfmt(struct soc_camera_device *icd, u32 pixfmt)
}

static int mt9m111_set_fmt(struct soc_camera_device *icd,
__u32 pixfmt, struct v4l2_rect *rect)
struct v4l2_format *f)
{
struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
struct v4l2_pix_format *pix = &f->fmt.pix;
struct v4l2_rect rect = {
.left = mt9m111->rect.left,
.top = mt9m111->rect.top,
.width = pix->width,
.height = pix->height,
};
int ret;

mt9m111->left = rect->left;
mt9m111->top = rect->top;
mt9m111->width = rect->width;
mt9m111->height = rect->height;

dev_dbg(&icd->dev, "%s fmt=%x left=%d, top=%d, width=%d, height=%d\n",
__func__, pixfmt, mt9m111->left, mt9m111->top, mt9m111->width,
mt9m111->height);
__func__, pix->pixelformat, rect.left, rect.top, rect.width,
rect.height);

ret = mt9m111_setup_rect(icd);
ret = mt9m111_setup_rect(icd, &rect);
if (!ret)
ret = mt9m111_set_pixfmt(icd, pix->pixelformat);
if (!ret)
ret = mt9m111_set_pixfmt(icd, pixfmt);
mt9m111->rect = rect;
return ret;
}

Expand Down Expand Up @@ -633,6 +654,7 @@ static struct soc_camera_ops mt9m111_ops = {
.release = mt9m111_release,
.start_capture = mt9m111_start_capture,
.stop_capture = mt9m111_stop_capture,
.set_crop = mt9m111_set_crop,
.set_fmt = mt9m111_set_fmt,
.try_fmt = mt9m111_try_fmt,
.query_bus_param = mt9m111_query_bus_param,
Expand Down Expand Up @@ -817,7 +839,7 @@ static int mt9m111_restore_state(struct soc_camera_device *icd)

mt9m111_set_context(icd, mt9m111->context);
mt9m111_set_pixfmt(icd, mt9m111->pixfmt);
mt9m111_setup_rect(icd);
mt9m111_setup_rect(icd, &mt9m111->rect);
mt9m111_set_flip(icd, mt9m111->hflip, MT9M111_RMB_MIRROR_COLS);
mt9m111_set_flip(icd, mt9m111->vflip, MT9M111_RMB_MIRROR_ROWS);
mt9m111_set_global_gain(icd, icd->gain);
Expand Down
84 changes: 53 additions & 31 deletions trunk/drivers/media/video/mt9t031.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,36 +213,14 @@ static void recalculate_limits(struct soc_camera_device *icd,
icd->height_max = MT9T031_MAX_HEIGHT / yskip;
}

static int mt9t031_set_fmt(struct soc_camera_device *icd,
__u32 pixfmt, struct v4l2_rect *rect)
static int mt9t031_set_params(struct soc_camera_device *icd,
struct v4l2_rect *rect, u16 xskip, u16 yskip)
{
struct mt9t031 *mt9t031 = container_of(icd, struct mt9t031, icd);
int ret;
u16 xbin, ybin, width, height, left, top;
const u16 hblank = MT9T031_HORIZONTAL_BLANK,
vblank = MT9T031_VERTICAL_BLANK;
u16 xbin, xskip, ybin, yskip, width, height, left, top;

if (pixfmt) {
/*
* try_fmt has put rectangle within limits.
* S_FMT - use binning and skipping for scaling, recalculate
* limits, used for cropping
*/
/* Is this more optimal than just a division? */
for (xskip = 8; xskip > 1; xskip--)
if (rect->width * xskip <= MT9T031_MAX_WIDTH)
break;

for (yskip = 8; yskip > 1; yskip--)
if (rect->height * yskip <= MT9T031_MAX_HEIGHT)
break;

recalculate_limits(icd, xskip, yskip);
} else {
/* CROP - no change in scaling, or in limits */
xskip = mt9t031->xskip;
yskip = mt9t031->yskip;
}

/* Make sure we don't exceed sensor limits */
if (rect->left + rect->width > icd->width_max)
Expand Down Expand Up @@ -289,7 +267,7 @@ static int mt9t031_set_fmt(struct soc_camera_device *icd,
if (ret >= 0)
ret = reg_write(icd, MT9T031_VERTICAL_BLANKING, vblank);

if (pixfmt) {
if (yskip != mt9t031->yskip || xskip != mt9t031->xskip) {
/* Binning, skipping */
if (ret >= 0)
ret = reg_write(icd, MT9T031_COLUMN_ADDRESS_MODE,
Expand Down Expand Up @@ -325,15 +303,58 @@ static int mt9t031_set_fmt(struct soc_camera_device *icd,
}
}

if (!ret && pixfmt) {
/* Re-enable register update, commit all changes */
if (ret >= 0)
ret = reg_clear(icd, MT9T031_OUTPUT_CONTROL, 1);

return ret < 0 ? ret : 0;
}

static int mt9t031_set_crop(struct soc_camera_device *icd,
struct v4l2_rect *rect)
{
struct mt9t031 *mt9t031 = container_of(icd, struct mt9t031, icd);

/* CROP - no change in scaling, or in limits */
return mt9t031_set_params(icd, rect, mt9t031->xskip, mt9t031->yskip);
}

static int mt9t031_set_fmt(struct soc_camera_device *icd,
struct v4l2_format *f)
{
struct mt9t031 *mt9t031 = container_of(icd, struct mt9t031, icd);
int ret;
u16 xskip, yskip;
struct v4l2_rect rect = {
.left = icd->x_current,
.top = icd->y_current,
.width = f->fmt.pix.width,
.height = f->fmt.pix.height,
};

/*
* try_fmt has put rectangle within limits.
* S_FMT - use binning and skipping for scaling, recalculate
* limits, used for cropping
*/
/* Is this more optimal than just a division? */
for (xskip = 8; xskip > 1; xskip--)
if (rect.width * xskip <= MT9T031_MAX_WIDTH)
break;

for (yskip = 8; yskip > 1; yskip--)
if (rect.height * yskip <= MT9T031_MAX_HEIGHT)
break;

recalculate_limits(icd, xskip, yskip);

ret = mt9t031_set_params(icd, &rect, xskip, yskip);
if (!ret) {
mt9t031->xskip = xskip;
mt9t031->yskip = yskip;
}

/* Re-enable register update, commit all changes */
reg_clear(icd, MT9T031_OUTPUT_CONTROL, 1);

return ret < 0 ? ret : 0;
return ret;
}

static int mt9t031_try_fmt(struct soc_camera_device *icd,
Expand Down Expand Up @@ -470,6 +491,7 @@ static struct soc_camera_ops mt9t031_ops = {
.release = mt9t031_release,
.start_capture = mt9t031_start_capture,
.stop_capture = mt9t031_stop_capture,
.set_crop = mt9t031_set_crop,
.set_fmt = mt9t031_set_fmt,
.try_fmt = mt9t031_try_fmt,
.set_bus_param = mt9t031_set_bus_param,
Expand Down
62 changes: 39 additions & 23 deletions trunk/drivers/media/video/mt9v022.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,32 +340,11 @@ static unsigned long mt9v022_query_bus_param(struct soc_camera_device *icd)
width_flag;
}

static int mt9v022_set_fmt(struct soc_camera_device *icd,
__u32 pixfmt, struct v4l2_rect *rect)
static int mt9v022_set_crop(struct soc_camera_device *icd,
struct v4l2_rect *rect)
{
struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd);
int ret;

/* The caller provides a supported format, as verified per call to
* icd->try_fmt(), datawidth is from our supported format list */
switch (pixfmt) {
case V4L2_PIX_FMT_GREY:
case V4L2_PIX_FMT_Y16:
if (mt9v022->model != V4L2_IDENT_MT9V022IX7ATM)
return -EINVAL;
break;
case V4L2_PIX_FMT_SBGGR8:
case V4L2_PIX_FMT_SBGGR16:
if (mt9v022->model != V4L2_IDENT_MT9V022IX7ATC)
return -EINVAL;
break;
case 0:
/* No format change, only geometry */
break;
default:
return -EINVAL;
}

/* Like in example app. Contradicts the datasheet though */
ret = reg_read(icd, MT9V022_AEC_AGC_ENABLE);
if (ret >= 0) {
Expand Down Expand Up @@ -403,6 +382,42 @@ static int mt9v022_set_fmt(struct soc_camera_device *icd,
return 0;
}

static int mt9v022_set_fmt(struct soc_camera_device *icd,
struct v4l2_format *f)
{
struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd);
struct v4l2_pix_format *pix = &f->fmt.pix;
struct v4l2_rect rect = {
.left = icd->x_current,
.top = icd->y_current,
.width = pix->width,
.height = pix->height,
};

/* The caller provides a supported format, as verified per call to
* icd->try_fmt(), datawidth is from our supported format list */
switch (pix->pixelformat) {
case V4L2_PIX_FMT_GREY:
case V4L2_PIX_FMT_Y16:
if (mt9v022->model != V4L2_IDENT_MT9V022IX7ATM)
return -EINVAL;
break;
case V4L2_PIX_FMT_SBGGR8:
case V4L2_PIX_FMT_SBGGR16:
if (mt9v022->model != V4L2_IDENT_MT9V022IX7ATC)
return -EINVAL;
break;
case 0:
/* No format change, only geometry */
break;
default:
return -EINVAL;
}

/* No support for scaling on this camera, just crop. */
return mt9v022_set_crop(icd, &rect);
}

static int mt9v022_try_fmt(struct soc_camera_device *icd,
struct v4l2_format *f)
{
Expand Down Expand Up @@ -544,6 +559,7 @@ static struct soc_camera_ops mt9v022_ops = {
.release = mt9v022_release,
.start_capture = mt9v022_start_capture,
.stop_capture = mt9v022_stop_capture,
.set_crop = mt9v022_set_crop,
.set_fmt = mt9v022_set_fmt,
.try_fmt = mt9v022_try_fmt,
.set_bus_param = mt9v022_set_bus_param,
Expand Down
Loading

0 comments on commit a96d349

Please sign in to comment.