29 #include <linux/i2c.h>
30 #include <linux/module.h>
41 #define MAX_HALF_FPS (MAX_FPS / 2)
42 #define HIGH_FPS_MODE_LOWER_LIMIT 14
43 #define DEFAULT_FPS MAX_HALF_FPS
56 .description =
"YUYV (YUV 4:2:2), packed",
69 .description =
"RGB565, le",
74 #define TCM825X_NUM_CAPTURE_FORMATS ARRAY_SIZE(tcm825x_formats)
91 #define V4L2_CID_ALC V4L2_CID_PRIVATE_BASE
92 #define V4L2_CID_H_EDGE_EN V4L2_CID_PRIVATE_BASE + 1
93 #define V4L2_CID_V_EDGE_EN V4L2_CID_PRIVATE_BASE + 2
94 #define V4L2_CID_LENS V4L2_CID_PRIVATE_BASE + 3
95 #define V4L2_CID_MAX_EXPOSURE_TIME V4L2_CID_PRIVATE_BASE + 4
96 #define V4L2_CID_LAST_PRIV V4L2_CID_MAX_EXPOSURE_TIME
99 static struct vcontrol {
103 } video_control[] = {
120 .name =
"Red Balance",
132 .name =
"Blue Balance",
144 .name =
"Auto White Balance",
156 .name =
"Exposure Time",
168 .name =
"Mirror Image",
180 .name =
"Vertical Flip",
193 .name =
"Auto Luminance Control",
205 .name =
"Horizontal Edge Enhancement",
217 .name =
"Vertical Edge Enhancement",
229 .name =
"Lens Shading Compensation",
241 .name =
"Maximum Exposure Time",
253 { &subqcif, &qqvga, &qcif, &qvga, &cif, &vga };
256 { &yuv422, &rgb565 };
275 msg[0].buf = ®_buf;
279 msg[1].buf = &data_buf;
297 unsigned char data[2];
314 static int __tcm825x_write_reg_mask(
struct i2c_client *client,
320 rc = tcm825x_read_reg(client, reg);
329 rc = tcm825x_write_reg(client, reg, val);
336 #define tcm825x_write_reg_mask(client, regmask, val) \
337 __tcm825x_write_reg_mask(client, TCM825X_ADDR((regmask)), val, \
338 TCM825X_MASK((regmask)))
347 static int tcm825x_write_default_regs(
struct i2c_client *client,
355 err = tcm825x_write_reg(client, next->
reg, next->
val);
357 dev_err(&client->
dev,
"register writing failed\n");
366 static struct vcontrol *find_vctrl(
int id)
373 for (i = 0; i <
ARRAY_SIZE(video_control); i++)
374 if (video_control[i].qc.id ==
id)
375 return &video_control[
i];
391 unsigned long pixels = width *
height;
395 if (tcm825x_sizes[isize + 1].height
396 * tcm825x_sizes[isize + 1].width > pixels) {
426 err = tcm825x_write_default_regs(
432 val = tcm825x_siz_reg[isize]->
val;
434 "configuring image size %d\n", isize);
436 tcm825x_siz_reg[isize]->
reg, val);
452 "configuring pixel format %d\n", pfmt);
453 val = tcm825x_fmt_reg[
pfmt]->
val;
456 tcm825x_fmt_reg[pfmt]->
reg, val);
466 val = tcm825x_read_reg(sensor->
i2c_client, 0x02);
468 tcm825x_write_reg(sensor->
i2c_client, 0x02, val);
479 control = find_vctrl(qc->
id);
495 struct vcontrol *lvc;
499 int val_lower, val_upper;
501 val_upper = tcm825x_read_reg(client,
505 val_lower = tcm825x_read_reg(client,
510 vc->
value = ((val_upper & 0x1f) << 8) | (val_lower);
514 lvc = find_vctrl(vc->
id);
522 val >>= lvc->start_bit;
539 struct vcontrol *lvc;
544 int val_lower, val_upper;
559 lvc = find_vctrl(vc->
id);
566 val = val << lvc->start_bit;
604 isize = tcm825x_find_size(s, pix->
width, pix->
height);
608 pix->
width = tcm825x_sizes[isize].width;
609 pix->
height = tcm825x_sizes[isize].height;
615 if (ifmt == TCM825X_NUM_CAPTURE_FORMATS)
646 rval = ioctl_try_fmt_cap(s, f);
650 rval = tcm825x_configure(s);
707 }
else if (tgt_fps <
MIN_FPS) {
714 rval = tcm825x_configure(s);
756 p->
u.
bt656.clock_curr = tgt_xclk;
775 return tcm825x_configure(s);
788 r = tcm825x_read_reg(sensor->
i2c_client, 0x01);
834 .ioctls = tcm825x_ioctl_desc,
846 .slave = &tcm825x_slave,
850 static int tcm825x_probe(
struct i2c_client *client,
855 if (i2c_get_clientdata(client))
867 i2c_set_clientdata(client, sensor);
870 sensor->
pix.width = tcm825x_sizes[
QVGA].width;
871 sensor->
pix.height = tcm825x_sizes[
QVGA].height;
877 static int tcm825x_remove(
struct i2c_client *client)
895 static struct i2c_driver tcm825x_i2c_driver = {
899 .probe = tcm825x_probe,
900 .remove = tcm825x_remove,
901 .id_table = tcm825x_id,
911 static int __init tcm825x_init(
void)
915 rval = i2c_add_driver(&tcm825x_i2c_driver);
923 static void __exit tcm825x_exit(
void)