47 #include <linux/module.h>
48 #include <linux/types.h>
49 #include <linux/kernel.h>
51 #include <linux/string.h>
52 #include <linux/errno.h>
53 #include <linux/i2c.h>
54 #if defined(CONFIG_SPI)
57 #include <asm/uaccess.h>
58 #include <asm/pgtable.h>
60 #include <asm/div64.h>
66 #include <linux/videodev2.h>
88 const char *
const *menu_items)
104 menu_items[ctrl->
value][0] ==
'\0')
120 &min, &max, &step, &def, &qctrl->
flags);
140 const char *
const *menu_items)
145 if (menu_items ==
NULL)
147 if (menu_items ==
NULL ||
150 for (i = 0; i < qmenu->
index && menu_items[
i]; i++) ;
151 if (menu_items[i] ==
NULL || menu_items[i][0] ==
'\0')
166 if (menu_items ==
NULL || ids ==
NULL)
169 if (*ids++ == qmenu->
index) {
171 sizeof(qmenu->
name));
192 if (ctrl_classes ==
NULL)
200 if (*ctrl_classes ==
NULL)
202 pctrl = *ctrl_classes;
204 while (*pctrl && *pctrl !=
id) pctrl++;
205 return *pctrl ?
id : 0;
214 if (*ctrl_classes ==
NULL)
216 pctrl = *ctrl_classes;
218 while (*pctrl && *pctrl <
id) pctrl++;
224 if (*ctrl_classes ==
NULL)
226 return **ctrl_classes;
232 switch (match->
type) {
234 return match->
addr == 0;
241 #if defined(CONFIG_I2C) || (defined(CONFIG_I2C_MODULE) && defined(MODULE))
249 switch (match->
type) {
255 if (len && c->
driver->driver.name[len - 1] ==
'\'')
296 v4l2_set_subdevdata(sd, client);
297 i2c_set_clientdata(client, sd);
300 client->
driver->driver.name, i2c_adapter_id(client->
adapter),
310 const unsigned short *probe_addrs)
320 if (info->
addr == 0 && probe_addrs)
337 if (!try_module_get(client->
driver->driver.owner))
339 sd = i2c_get_clientdata(client);
346 module_put(client->
driver->driver.owner);
351 if (client && sd ==
NULL)
358 struct i2c_adapter *adapter,
const char *client_type,
359 u8 addr,
const unsigned short *probe_addrs)
365 memset(&info, 0,
sizeof(info));
376 struct i2c_client *client = v4l2_get_subdevdata(sd);
386 static const unsigned short radio_addrs[] = {
387 #if defined(CONFIG_MEDIA_TUNER_TEA5761) || defined(CONFIG_MEDIA_TUNER_TEA5761_MODULE)
393 static const unsigned short demod_addrs[] = {
394 0x42, 0x43, 0x4a, 0x4b,
397 static const unsigned short tv_addrs[] = {
398 0x42, 0x43, 0x4a, 0x4b,
399 0x60, 0x61, 0x62, 0x63, 0x64,
419 #if defined(CONFIG_SPI)
431 v4l2_set_subdevdata(sd, spi);
432 spi_set_drvdata(spi, sd);
454 if (!try_module_get(spi->
dev.driver->owner))
457 sd = spi_get_drvdata(spi);
465 module_put(spi->
dev.driver->owner);
470 if (spi && sd ==
NULL)
471 spi_unregister_device(spi);
483 static unsigned int clamp_align(
unsigned int x,
unsigned int min,
484 unsigned int max,
unsigned int align)
491 x = (x + (1 << (align - 1))) & mask;
495 x = (min + ~mask) & mask;
518 u32 *
h,
unsigned int hmin,
unsigned int hmax,
519 unsigned int halign,
unsigned int salign)
521 *w = clamp_align(*w, wmin, wmax, walign);
522 *h = clamp_align(*h, hmin, hmax, halign);
532 if (walign + halign < salign) {
534 unsigned int wmaxa =
__fls(wmax ^ (wmin - 1));
536 unsigned int hmaxa =
__fls(hmax ^ (hmin - 1));
540 if (halign >= hmaxa ||
541 (walign <= halign && walign < wmaxa)) {
542 *w = clamp_align(*w, wmin, wmax, walign + 1);
545 *h = clamp_align(*h, hmin, hmax, halign + 1);
548 }
while (halign + walign < salign);
563 static const struct v4l2_dv_preset_info {
570 { 720, 576,
"576p@50" },
571 { 1280, 720,
"720p@24" },
572 { 1280, 720,
"720p@25" },
573 { 1280, 720,
"720p@30" },
574 { 1280, 720,
"720p@50" },
576 { 1280, 720,
"720p@60" },
578 { 1920, 1080,
"1080i@30" },
579 { 1920, 1080,
"1080i@25" },
580 { 1920, 1080,
"1080i@50" },
581 { 1920, 1080,
"1080i@60" },
582 { 1920, 1080,
"1080p@24" },
583 { 1920, 1080,
"1080p@25" },
584 { 1920, 1080,
"1080p@30" },
585 { 1920, 1080,
"1080p@50" },
586 { 1920, 1080,
"1080p@60" },
610 unsigned pclock_delta)
614 if (t1->
bt.width == t2->
bt.width &&
615 t1->
bt.height == t2->
bt.height &&
616 t1->
bt.interlaced == t2->
bt.interlaced &&
617 t1->
bt.polarities == t2->
bt.polarities &&
618 t1->
bt.pixelclock >= t2->
bt.pixelclock - pclock_delta &&
619 t1->
bt.pixelclock <= t2->
bt.pixelclock + pclock_delta &&
620 t1->
bt.hfrontporch == t2->
bt.hfrontporch &&
621 t1->
bt.vfrontporch == t2->
bt.vfrontporch &&
622 t1->
bt.vsync == t2->
bt.vsync &&
623 t1->
bt.vbackporch == t2->
bt.vbackporch &&
624 (!t1->
bt.interlaced ||
625 (t1->
bt.il_vfrontporch == t2->
bt.il_vfrontporch &&
626 t1->
bt.il_vsync == t2->
bt.il_vsync &&
627 t1->
bt.il_vbackporch == t2->
bt.il_vbackporch)))
639 #define CVT_PXL_CLK_GRAN 250000
642 #define CVT_MIN_V_BPORCH 7
643 #define CVT_MIN_V_PORCH_RND 3
644 #define CVT_MIN_VSYNC_BP 550
647 #define CVT_CELL_GRAN 8
652 #define CVT_C_PRIME (((CVT_C - CVT_J) * CVT_K / 256) + CVT_J)
653 #define CVT_M_PRIME (CVT_K * CVT_M / 256)
656 #define CVT_RB_MIN_V_BPORCH 7
657 #define CVT_RB_V_FPORCH 3
658 #define CVT_RB_MIN_V_BLANK 460
659 #define CVT_RB_H_SYNC 32
660 #define CVT_RB_H_BPORCH 80
661 #define CVT_RB_H_BLANK 160
678 int v_fp, v_bp, h_fp, h_bp,
hsync;
679 int frame_width, image_height, image_width;
680 bool reduced_blanking;
683 if (vsync < 4 || vsync > 7)
687 reduced_blanking =
false;
689 reduced_blanking =
true;
694 if (reduced_blanking) {
697 v_bp -= vsync + v_fp;
708 image_height = (frame_height - v_fp - vsync - v_bp + 1) & ~0x1;
713 image_width = (image_height * 4) / 3;
716 image_width = (image_height * 16) / 9;
719 image_width = (image_height * 16) / 10;
723 if (image_height == 1024)
724 image_width = (image_height * 5) / 4;
725 else if (image_height == 768)
726 image_width = (image_height * 15) / 9;
734 image_width = image_width & ~7;
737 if (reduced_blanking) {
750 h_blank = (image_width * ideal_duty_cycle + (100 - ideal_duty_cycle) / 2) /
751 (100 - ideal_duty_cycle);
754 if (h_blank * 100 / image_width < 20) {
755 h_blank = image_width / 5;
756 h_blank = (h_blank + 0x7) & ~0x7;
759 pix_clk = (image_width +
h_blank) * hfreq;
763 frame_width = image_width +
h_blank;
765 hsync = (frame_width * 8 + 50) / 100;
767 h_fp = h_blank - hsync - h_bp;
771 fmt->
bt.width = image_width;
772 fmt->
bt.height = image_height;
773 fmt->
bt.hfrontporch = h_fp;
774 fmt->
bt.vfrontporch = v_fp;
777 fmt->
bt.hbackporch = frame_width - image_width - h_fp -
hsync;
778 fmt->
bt.vbackporch = frame_height - image_height - v_fp -
vsync;
779 fmt->
bt.pixelclock = pix_clk;
781 if (reduced_blanking)
793 #define GTF_PXL_CLK_GRAN 250000
795 #define GTF_MIN_VSYNC_BP 550
797 #define GTF_CELL_GRAN 8
804 #define GTF_D_C_PRIME ((((GTF_D_C - GTF_D_J) * GTF_D_K) / 256) + GTF_D_J)
805 #define GTF_D_M_PRIME ((GTF_D_K * GTF_D_M) / 256)
812 #define GTF_S_C_PRIME ((((GTF_S_C - GTF_S_J) * GTF_S_K) / 256) + GTF_S_J)
813 #define GTF_S_M_PRIME ((GTF_S_K * GTF_S_M) / 256)
840 int v_fp, v_bp, h_fp, h_bp,
hsync;
841 int frame_width, image_height, image_width;
858 image_height = (frame_height - v_fp - vsync - v_bp + 1) & ~0x1;
870 (hfreq * (100 -
GTF_D_C_PRIME) + GTF_D_M_PRIME * 1000) / 2) /
875 (hfreq * (100 -
GTF_S_C_PRIME) + GTF_S_M_PRIME * 1000) / 2) /
879 frame_width = image_width +
h_blank;
881 pix_clk = (image_width +
h_blank) * hfreq;
884 hsync = (frame_width * 8 + 50) / 100;
887 h_fp = h_blank / 2 -
hsync;
891 fmt->
bt.width = image_width;
892 fmt->
bt.height = image_height;
893 fmt->
bt.hfrontporch = h_fp;
894 fmt->
bt.vfrontporch = v_fp;
897 fmt->
bt.hbackporch = frame_width - image_width - h_fp -
hsync;
898 fmt->
bt.vbackporch = frame_height - image_height - v_fp -
vsync;
899 fmt->
bt.pixelclock = pix_clk;
923 if (!hor_landscape && !vert_portrait)
926 if (hor_landscape && vert_portrait) {
933 ratio = hor_landscape | vert_portrait;
938 }
else if (
ratio == 34) {
941 }
else if (
ratio == 68) {
969 for (i = 0, size = probe->
sizes; i < probe->num_sizes; i++, size++) {
971 if (error < min_error) {