tvp5150.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237
  1. /*
  2. * tvp5150 - Texas Instruments TVP5150A/AM1 video decoder driver
  3. *
  4. * Copyright (c) 2005,2006 Mauro Carvalho Chehab (mchehab@infradead.org)
  5. * This code is placed under the terms of the GNU General Public License v2
  6. */
  7. #include <linux/i2c.h>
  8. #include <linux/slab.h>
  9. #include <linux/videodev2.h>
  10. #include <linux/delay.h>
  11. #include <linux/module.h>
  12. #include <media/v4l2-async.h>
  13. #include <media/v4l2-device.h>
  14. #include <media/tvp5150.h>
  15. #include <media/v4l2-ctrls.h>
  16. #include "tvp5150_reg.h"
  17. #define TVP5150_H_MAX 720U
  18. #define TVP5150_V_MAX_525_60 480U
  19. #define TVP5150_V_MAX_OTHERS 576U
  20. #define TVP5150_MAX_CROP_LEFT 511
  21. #define TVP5150_MAX_CROP_TOP 127
  22. #define TVP5150_CROP_SHIFT 2
  23. MODULE_DESCRIPTION("Texas Instruments TVP5150A video decoder driver");
  24. MODULE_AUTHOR("Mauro Carvalho Chehab");
  25. MODULE_LICENSE("GPL");
  26. static int debug;
  27. module_param(debug, int, 0644);
  28. MODULE_PARM_DESC(debug, "Debug level (0-2)");
  29. struct tvp5150 {
  30. struct v4l2_subdev sd;
  31. struct v4l2_ctrl_handler hdl;
  32. struct v4l2_rect rect;
  33. v4l2_std_id norm; /* Current set standard */
  34. u32 input;
  35. u32 output;
  36. int enable;
  37. };
  38. static inline struct tvp5150 *to_tvp5150(struct v4l2_subdev *sd)
  39. {
  40. return container_of(sd, struct tvp5150, sd);
  41. }
  42. static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl)
  43. {
  44. return &container_of(ctrl->handler, struct tvp5150, hdl)->sd;
  45. }
  46. static int tvp5150_read(struct v4l2_subdev *sd, unsigned char addr)
  47. {
  48. struct i2c_client *c = v4l2_get_subdevdata(sd);
  49. int rc;
  50. rc = i2c_smbus_read_byte_data(c, addr);
  51. if (rc < 0) {
  52. v4l2_err(sd, "i2c i/o error: rc == %d\n", rc);
  53. return rc;
  54. }
  55. v4l2_dbg(2, debug, sd, "tvp5150: read 0x%02x = 0x%02x\n", addr, rc);
  56. return rc;
  57. }
  58. static inline void tvp5150_write(struct v4l2_subdev *sd, unsigned char addr,
  59. unsigned char value)
  60. {
  61. struct i2c_client *c = v4l2_get_subdevdata(sd);
  62. int rc;
  63. v4l2_dbg(2, debug, sd, "tvp5150: writing 0x%02x 0x%02x\n", addr, value);
  64. rc = i2c_smbus_write_byte_data(c, addr, value);
  65. if (rc < 0)
  66. v4l2_dbg(0, debug, sd, "i2c i/o error: rc == %d\n", rc);
  67. }
  68. static void dump_reg_range(struct v4l2_subdev *sd, char *s, u8 init,
  69. const u8 end, int max_line)
  70. {
  71. int i = 0;
  72. while (init != (u8)(end + 1)) {
  73. if ((i % max_line) == 0) {
  74. if (i > 0)
  75. printk("\n");
  76. printk("tvp5150: %s reg 0x%02x = ", s, init);
  77. }
  78. printk("%02x ", tvp5150_read(sd, init));
  79. init++;
  80. i++;
  81. }
  82. printk("\n");
  83. }
  84. static int tvp5150_log_status(struct v4l2_subdev *sd)
  85. {
  86. printk("tvp5150: Video input source selection #1 = 0x%02x\n",
  87. tvp5150_read(sd, TVP5150_VD_IN_SRC_SEL_1));
  88. printk("tvp5150: Analog channel controls = 0x%02x\n",
  89. tvp5150_read(sd, TVP5150_ANAL_CHL_CTL));
  90. printk("tvp5150: Operation mode controls = 0x%02x\n",
  91. tvp5150_read(sd, TVP5150_OP_MODE_CTL));
  92. printk("tvp5150: Miscellaneous controls = 0x%02x\n",
  93. tvp5150_read(sd, TVP5150_MISC_CTL));
  94. printk("tvp5150: Autoswitch mask= 0x%02x\n",
  95. tvp5150_read(sd, TVP5150_AUTOSW_MSK));
  96. printk("tvp5150: Color killer threshold control = 0x%02x\n",
  97. tvp5150_read(sd, TVP5150_COLOR_KIL_THSH_CTL));
  98. printk("tvp5150: Luminance processing controls #1 #2 and #3 = %02x %02x %02x\n",
  99. tvp5150_read(sd, TVP5150_LUMA_PROC_CTL_1),
  100. tvp5150_read(sd, TVP5150_LUMA_PROC_CTL_2),
  101. tvp5150_read(sd, TVP5150_LUMA_PROC_CTL_3));
  102. printk("tvp5150: Brightness control = 0x%02x\n",
  103. tvp5150_read(sd, TVP5150_BRIGHT_CTL));
  104. printk("tvp5150: Color saturation control = 0x%02x\n",
  105. tvp5150_read(sd, TVP5150_SATURATION_CTL));
  106. printk("tvp5150: Hue control = 0x%02x\n",
  107. tvp5150_read(sd, TVP5150_HUE_CTL));
  108. printk("tvp5150: Contrast control = 0x%02x\n",
  109. tvp5150_read(sd, TVP5150_CONTRAST_CTL));
  110. printk("tvp5150: Outputs and data rates select = 0x%02x\n",
  111. tvp5150_read(sd, TVP5150_DATA_RATE_SEL));
  112. printk("tvp5150: Configuration shared pins = 0x%02x\n",
  113. tvp5150_read(sd, TVP5150_CONF_SHARED_PIN));
  114. printk("tvp5150: Active video cropping start = 0x%02x%02x\n",
  115. tvp5150_read(sd, TVP5150_ACT_VD_CROP_ST_MSB),
  116. tvp5150_read(sd, TVP5150_ACT_VD_CROP_ST_LSB));
  117. printk("tvp5150: Active video cropping stop = 0x%02x%02x\n",
  118. tvp5150_read(sd, TVP5150_ACT_VD_CROP_STP_MSB),
  119. tvp5150_read(sd, TVP5150_ACT_VD_CROP_STP_LSB));
  120. printk("tvp5150: Genlock/RTC = 0x%02x\n",
  121. tvp5150_read(sd, TVP5150_GENLOCK));
  122. printk("tvp5150: Horizontal sync start = 0x%02x\n",
  123. tvp5150_read(sd, TVP5150_HORIZ_SYNC_START));
  124. printk("tvp5150: Vertical blanking start = 0x%02x\n",
  125. tvp5150_read(sd, TVP5150_VERT_BLANKING_START));
  126. printk("tvp5150: Vertical blanking stop = 0x%02x\n",
  127. tvp5150_read(sd, TVP5150_VERT_BLANKING_STOP));
  128. printk("tvp5150: Chrominance processing control #1 and #2 = %02x %02x\n",
  129. tvp5150_read(sd, TVP5150_CHROMA_PROC_CTL_1),
  130. tvp5150_read(sd, TVP5150_CHROMA_PROC_CTL_2));
  131. printk("tvp5150: Interrupt reset register B = 0x%02x\n",
  132. tvp5150_read(sd, TVP5150_INT_RESET_REG_B));
  133. printk("tvp5150: Interrupt enable register B = 0x%02x\n",
  134. tvp5150_read(sd, TVP5150_INT_ENABLE_REG_B));
  135. printk("tvp5150: Interrupt configuration register B = 0x%02x\n",
  136. tvp5150_read(sd, TVP5150_INTT_CONFIG_REG_B));
  137. printk("tvp5150: Video standard = 0x%02x\n",
  138. tvp5150_read(sd, TVP5150_VIDEO_STD));
  139. printk("tvp5150: Chroma gain factor: Cb=0x%02x Cr=0x%02x\n",
  140. tvp5150_read(sd, TVP5150_CB_GAIN_FACT),
  141. tvp5150_read(sd, TVP5150_CR_GAIN_FACTOR));
  142. printk("tvp5150: Macrovision on counter = 0x%02x\n",
  143. tvp5150_read(sd, TVP5150_MACROVISION_ON_CTR));
  144. printk("tvp5150: Macrovision off counter = 0x%02x\n",
  145. tvp5150_read(sd, TVP5150_MACROVISION_OFF_CTR));
  146. printk("tvp5150: ITU-R BT.656.%d timing(TVP5150AM1 only)\n",
  147. (tvp5150_read(sd, TVP5150_REV_SELECT) & 1) ? 3 : 4);
  148. printk("tvp5150: Device ID = %02x%02x\n",
  149. tvp5150_read(sd, TVP5150_MSB_DEV_ID),
  150. tvp5150_read(sd, TVP5150_LSB_DEV_ID));
  151. printk("tvp5150: ROM version = (hex) %02x.%02x\n",
  152. tvp5150_read(sd, TVP5150_ROM_MAJOR_VER),
  153. tvp5150_read(sd, TVP5150_ROM_MINOR_VER));
  154. printk("tvp5150: Vertical line count = 0x%02x%02x\n",
  155. tvp5150_read(sd, TVP5150_VERT_LN_COUNT_MSB),
  156. tvp5150_read(sd, TVP5150_VERT_LN_COUNT_LSB));
  157. printk("tvp5150: Interrupt status register B = 0x%02x\n",
  158. tvp5150_read(sd, TVP5150_INT_STATUS_REG_B));
  159. printk("tvp5150: Interrupt active register B = 0x%02x\n",
  160. tvp5150_read(sd, TVP5150_INT_ACTIVE_REG_B));
  161. printk("tvp5150: Status regs #1 to #5 = %02x %02x %02x %02x %02x\n",
  162. tvp5150_read(sd, TVP5150_STATUS_REG_1),
  163. tvp5150_read(sd, TVP5150_STATUS_REG_2),
  164. tvp5150_read(sd, TVP5150_STATUS_REG_3),
  165. tvp5150_read(sd, TVP5150_STATUS_REG_4),
  166. tvp5150_read(sd, TVP5150_STATUS_REG_5));
  167. dump_reg_range(sd, "Teletext filter 1", TVP5150_TELETEXT_FIL1_INI,
  168. TVP5150_TELETEXT_FIL1_END, 8);
  169. dump_reg_range(sd, "Teletext filter 2", TVP5150_TELETEXT_FIL2_INI,
  170. TVP5150_TELETEXT_FIL2_END, 8);
  171. printk("tvp5150: Teletext filter enable = 0x%02x\n",
  172. tvp5150_read(sd, TVP5150_TELETEXT_FIL_ENA));
  173. printk("tvp5150: Interrupt status register A = 0x%02x\n",
  174. tvp5150_read(sd, TVP5150_INT_STATUS_REG_A));
  175. printk("tvp5150: Interrupt enable register A = 0x%02x\n",
  176. tvp5150_read(sd, TVP5150_INT_ENABLE_REG_A));
  177. printk("tvp5150: Interrupt configuration = 0x%02x\n",
  178. tvp5150_read(sd, TVP5150_INT_CONF));
  179. printk("tvp5150: VDP status register = 0x%02x\n",
  180. tvp5150_read(sd, TVP5150_VDP_STATUS_REG));
  181. printk("tvp5150: FIFO word count = 0x%02x\n",
  182. tvp5150_read(sd, TVP5150_FIFO_WORD_COUNT));
  183. printk("tvp5150: FIFO interrupt threshold = 0x%02x\n",
  184. tvp5150_read(sd, TVP5150_FIFO_INT_THRESHOLD));
  185. printk("tvp5150: FIFO reset = 0x%02x\n",
  186. tvp5150_read(sd, TVP5150_FIFO_RESET));
  187. printk("tvp5150: Line number interrupt = 0x%02x\n",
  188. tvp5150_read(sd, TVP5150_LINE_NUMBER_INT));
  189. printk("tvp5150: Pixel alignment register = 0x%02x%02x\n",
  190. tvp5150_read(sd, TVP5150_PIX_ALIGN_REG_HIGH),
  191. tvp5150_read(sd, TVP5150_PIX_ALIGN_REG_LOW));
  192. printk("tvp5150: FIFO output control = 0x%02x\n",
  193. tvp5150_read(sd, TVP5150_FIFO_OUT_CTRL));
  194. printk("tvp5150: Full field enable = 0x%02x\n",
  195. tvp5150_read(sd, TVP5150_FULL_FIELD_ENA));
  196. printk("tvp5150: Full field mode register = 0x%02x\n",
  197. tvp5150_read(sd, TVP5150_FULL_FIELD_MODE_REG));
  198. dump_reg_range(sd, "CC data", TVP5150_CC_DATA_INI,
  199. TVP5150_CC_DATA_END, 8);
  200. dump_reg_range(sd, "WSS data", TVP5150_WSS_DATA_INI,
  201. TVP5150_WSS_DATA_END, 8);
  202. dump_reg_range(sd, "VPS data", TVP5150_VPS_DATA_INI,
  203. TVP5150_VPS_DATA_END, 8);
  204. dump_reg_range(sd, "VITC data", TVP5150_VITC_DATA_INI,
  205. TVP5150_VITC_DATA_END, 10);
  206. dump_reg_range(sd, "Line mode", TVP5150_LINE_MODE_INI,
  207. TVP5150_LINE_MODE_END, 8);
  208. return 0;
  209. }
  210. /****************************************************************************
  211. Basic functions
  212. ****************************************************************************/
  213. static inline void tvp5150_selmux(struct v4l2_subdev *sd)
  214. {
  215. int opmode = 0;
  216. struct tvp5150 *decoder = to_tvp5150(sd);
  217. int input = 0;
  218. int val;
  219. if ((decoder->output & TVP5150_BLACK_SCREEN) || !decoder->enable)
  220. input = 8;
  221. switch (decoder->input) {
  222. case TVP5150_COMPOSITE1:
  223. input |= 2;
  224. /* fall through */
  225. case TVP5150_COMPOSITE0:
  226. break;
  227. case TVP5150_SVIDEO:
  228. default:
  229. input |= 1;
  230. break;
  231. }
  232. v4l2_dbg(1, debug, sd, "Selecting video route: route input=%i, output=%i "
  233. "=> tvp5150 input=%i, opmode=%i\n",
  234. decoder->input, decoder->output,
  235. input, opmode);
  236. tvp5150_write(sd, TVP5150_OP_MODE_CTL, opmode);
  237. tvp5150_write(sd, TVP5150_VD_IN_SRC_SEL_1, input);
  238. /* Svideo should enable YCrCb output and disable GPCL output
  239. * For Composite and TV, it should be the reverse
  240. */
  241. val = tvp5150_read(sd, TVP5150_MISC_CTL);
  242. if (val < 0) {
  243. v4l2_err(sd, "%s: failed with error = %d\n", __func__, val);
  244. return;
  245. }
  246. if (decoder->input == TVP5150_SVIDEO)
  247. val = (val & ~0x40) | 0x10;
  248. else
  249. val = (val & ~0x10) | 0x40;
  250. tvp5150_write(sd, TVP5150_MISC_CTL, val);
  251. };
  252. struct i2c_reg_value {
  253. unsigned char reg;
  254. unsigned char value;
  255. };
  256. /* Default values as sugested at TVP5150AM1 datasheet */
  257. static const struct i2c_reg_value tvp5150_init_default[] = {
  258. { /* 0x00 */
  259. TVP5150_VD_IN_SRC_SEL_1,0x00
  260. },
  261. { /* 0x01 */
  262. TVP5150_ANAL_CHL_CTL,0x15
  263. },
  264. { /* 0x02 */
  265. TVP5150_OP_MODE_CTL,0x00
  266. },
  267. { /* 0x03 */
  268. TVP5150_MISC_CTL,0x01
  269. },
  270. { /* 0x06 */
  271. TVP5150_COLOR_KIL_THSH_CTL,0x10
  272. },
  273. { /* 0x07 */
  274. TVP5150_LUMA_PROC_CTL_1,0x60
  275. },
  276. { /* 0x08 */
  277. TVP5150_LUMA_PROC_CTL_2,0x00
  278. },
  279. { /* 0x09 */
  280. TVP5150_BRIGHT_CTL,0x80
  281. },
  282. { /* 0x0a */
  283. TVP5150_SATURATION_CTL,0x80
  284. },
  285. { /* 0x0b */
  286. TVP5150_HUE_CTL,0x00
  287. },
  288. { /* 0x0c */
  289. TVP5150_CONTRAST_CTL,0x80
  290. },
  291. { /* 0x0d */
  292. TVP5150_DATA_RATE_SEL,0x47
  293. },
  294. { /* 0x0e */
  295. TVP5150_LUMA_PROC_CTL_3,0x00
  296. },
  297. { /* 0x0f */
  298. TVP5150_CONF_SHARED_PIN,0x08
  299. },
  300. { /* 0x11 */
  301. TVP5150_ACT_VD_CROP_ST_MSB,0x00
  302. },
  303. { /* 0x12 */
  304. TVP5150_ACT_VD_CROP_ST_LSB,0x00
  305. },
  306. { /* 0x13 */
  307. TVP5150_ACT_VD_CROP_STP_MSB,0x00
  308. },
  309. { /* 0x14 */
  310. TVP5150_ACT_VD_CROP_STP_LSB,0x00
  311. },
  312. { /* 0x15 */
  313. TVP5150_GENLOCK,0x01
  314. },
  315. { /* 0x16 */
  316. TVP5150_HORIZ_SYNC_START,0x80
  317. },
  318. { /* 0x18 */
  319. TVP5150_VERT_BLANKING_START,0x00
  320. },
  321. { /* 0x19 */
  322. TVP5150_VERT_BLANKING_STOP,0x00
  323. },
  324. { /* 0x1a */
  325. TVP5150_CHROMA_PROC_CTL_1,0x0c
  326. },
  327. { /* 0x1b */
  328. TVP5150_CHROMA_PROC_CTL_2,0x14
  329. },
  330. { /* 0x1c */
  331. TVP5150_INT_RESET_REG_B,0x00
  332. },
  333. { /* 0x1d */
  334. TVP5150_INT_ENABLE_REG_B,0x00
  335. },
  336. { /* 0x1e */
  337. TVP5150_INTT_CONFIG_REG_B,0x00
  338. },
  339. { /* 0x28 */
  340. TVP5150_VIDEO_STD,0x00
  341. },
  342. { /* 0x2e */
  343. TVP5150_MACROVISION_ON_CTR,0x0f
  344. },
  345. { /* 0x2f */
  346. TVP5150_MACROVISION_OFF_CTR,0x01
  347. },
  348. { /* 0xbb */
  349. TVP5150_TELETEXT_FIL_ENA,0x00
  350. },
  351. { /* 0xc0 */
  352. TVP5150_INT_STATUS_REG_A,0x00
  353. },
  354. { /* 0xc1 */
  355. TVP5150_INT_ENABLE_REG_A,0x00
  356. },
  357. { /* 0xc2 */
  358. TVP5150_INT_CONF,0x04
  359. },
  360. { /* 0xc8 */
  361. TVP5150_FIFO_INT_THRESHOLD,0x80
  362. },
  363. { /* 0xc9 */
  364. TVP5150_FIFO_RESET,0x00
  365. },
  366. { /* 0xca */
  367. TVP5150_LINE_NUMBER_INT,0x00
  368. },
  369. { /* 0xcb */
  370. TVP5150_PIX_ALIGN_REG_LOW,0x4e
  371. },
  372. { /* 0xcc */
  373. TVP5150_PIX_ALIGN_REG_HIGH,0x00
  374. },
  375. { /* 0xcd */
  376. TVP5150_FIFO_OUT_CTRL,0x01
  377. },
  378. { /* 0xcf */
  379. TVP5150_FULL_FIELD_ENA,0x00
  380. },
  381. { /* 0xd0 */
  382. TVP5150_LINE_MODE_INI,0x00
  383. },
  384. { /* 0xfc */
  385. TVP5150_FULL_FIELD_MODE_REG,0x7f
  386. },
  387. { /* end of data */
  388. 0xff,0xff
  389. }
  390. };
  391. /* Default values as sugested at TVP5150AM1 datasheet */
  392. static const struct i2c_reg_value tvp5150_init_enable[] = {
  393. {
  394. TVP5150_CONF_SHARED_PIN, 2
  395. },{ /* Automatic offset and AGC enabled */
  396. TVP5150_ANAL_CHL_CTL, 0x15
  397. },{ /* Activate YCrCb output 0x9 or 0xd ? */
  398. TVP5150_MISC_CTL, 0x6f
  399. },{ /* Activates video std autodetection for all standards */
  400. TVP5150_AUTOSW_MSK, 0x0
  401. },{ /* Default format: 0x47. For 4:2:2: 0x40 */
  402. TVP5150_DATA_RATE_SEL, 0x47
  403. },{
  404. TVP5150_CHROMA_PROC_CTL_1, 0x0c
  405. },{
  406. TVP5150_CHROMA_PROC_CTL_2, 0x54
  407. },{ /* Non documented, but initialized on WinTV USB2 */
  408. 0x27, 0x20
  409. },{
  410. 0xff,0xff
  411. }
  412. };
  413. struct tvp5150_vbi_type {
  414. unsigned int vbi_type;
  415. unsigned int ini_line;
  416. unsigned int end_line;
  417. unsigned int by_field :1;
  418. };
  419. struct i2c_vbi_ram_value {
  420. u16 reg;
  421. struct tvp5150_vbi_type type;
  422. unsigned char values[16];
  423. };
  424. /* This struct have the values for each supported VBI Standard
  425. * by
  426. tvp5150_vbi_types should follow the same order as vbi_ram_default
  427. * value 0 means rom position 0x10, value 1 means rom position 0x30
  428. * and so on. There are 16 possible locations from 0 to 15.
  429. */
  430. static struct i2c_vbi_ram_value vbi_ram_default[] =
  431. {
  432. /* FIXME: Current api doesn't handle all VBI types, those not
  433. yet supported are placed under #if 0 */
  434. #if 0
  435. {0x010, /* Teletext, SECAM, WST System A */
  436. {V4L2_SLICED_TELETEXT_SECAM,6,23,1},
  437. { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x26,
  438. 0xe6, 0xb4, 0x0e, 0x00, 0x00, 0x00, 0x10, 0x00 }
  439. },
  440. #endif
  441. {0x030, /* Teletext, PAL, WST System B */
  442. {V4L2_SLICED_TELETEXT_B,6,22,1},
  443. { 0xaa, 0xaa, 0xff, 0xff, 0x27, 0x2e, 0x20, 0x2b,
  444. 0xa6, 0x72, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00 }
  445. },
  446. #if 0
  447. {0x050, /* Teletext, PAL, WST System C */
  448. {V4L2_SLICED_TELETEXT_PAL_C,6,22,1},
  449. { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x22,
  450. 0xa6, 0x98, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 }
  451. },
  452. {0x070, /* Teletext, NTSC, WST System B */
  453. {V4L2_SLICED_TELETEXT_NTSC_B,10,21,1},
  454. { 0xaa, 0xaa, 0xff, 0xff, 0x27, 0x2e, 0x20, 0x23,
  455. 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 }
  456. },
  457. {0x090, /* Tetetext, NTSC NABTS System C */
  458. {V4L2_SLICED_TELETEXT_NTSC_C,10,21,1},
  459. { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x22,
  460. 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x15, 0x00 }
  461. },
  462. {0x0b0, /* Teletext, NTSC-J, NABTS System D */
  463. {V4L2_SLICED_TELETEXT_NTSC_D,10,21,1},
  464. { 0xaa, 0xaa, 0xff, 0xff, 0xa7, 0x2e, 0x20, 0x23,
  465. 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 }
  466. },
  467. {0x0d0, /* Closed Caption, PAL/SECAM */
  468. {V4L2_SLICED_CAPTION_625,22,22,1},
  469. { 0xaa, 0x2a, 0xff, 0x3f, 0x04, 0x51, 0x6e, 0x02,
  470. 0xa6, 0x7b, 0x09, 0x00, 0x00, 0x00, 0x27, 0x00 }
  471. },
  472. #endif
  473. {0x0f0, /* Closed Caption, NTSC */
  474. {V4L2_SLICED_CAPTION_525,21,21,1},
  475. { 0xaa, 0x2a, 0xff, 0x3f, 0x04, 0x51, 0x6e, 0x02,
  476. 0x69, 0x8c, 0x09, 0x00, 0x00, 0x00, 0x27, 0x00 }
  477. },
  478. {0x110, /* Wide Screen Signal, PAL/SECAM */
  479. {V4L2_SLICED_WSS_625,23,23,1},
  480. { 0x5b, 0x55, 0xc5, 0xff, 0x00, 0x71, 0x6e, 0x42,
  481. 0xa6, 0xcd, 0x0f, 0x00, 0x00, 0x00, 0x3a, 0x00 }
  482. },
  483. #if 0
  484. {0x130, /* Wide Screen Signal, NTSC C */
  485. {V4L2_SLICED_WSS_525,20,20,1},
  486. { 0x38, 0x00, 0x3f, 0x00, 0x00, 0x71, 0x6e, 0x43,
  487. 0x69, 0x7c, 0x08, 0x00, 0x00, 0x00, 0x39, 0x00 }
  488. },
  489. {0x150, /* Vertical Interval Timecode (VITC), PAL/SECAM */
  490. {V4l2_SLICED_VITC_625,6,22,0},
  491. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x8f, 0x6d, 0x49,
  492. 0xa6, 0x85, 0x08, 0x00, 0x00, 0x00, 0x4c, 0x00 }
  493. },
  494. {0x170, /* Vertical Interval Timecode (VITC), NTSC */
  495. {V4l2_SLICED_VITC_525,10,20,0},
  496. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x8f, 0x6d, 0x49,
  497. 0x69, 0x94, 0x08, 0x00, 0x00, 0x00, 0x4c, 0x00 }
  498. },
  499. #endif
  500. {0x190, /* Video Program System (VPS), PAL */
  501. {V4L2_SLICED_VPS,16,16,0},
  502. { 0xaa, 0xaa, 0xff, 0xff, 0xba, 0xce, 0x2b, 0x0d,
  503. 0xa6, 0xda, 0x0b, 0x00, 0x00, 0x00, 0x60, 0x00 }
  504. },
  505. /* 0x1d0 User programmable */
  506. /* End of struct */
  507. { (u16)-1 }
  508. };
  509. static int tvp5150_write_inittab(struct v4l2_subdev *sd,
  510. const struct i2c_reg_value *regs)
  511. {
  512. while (regs->reg != 0xff) {
  513. tvp5150_write(sd, regs->reg, regs->value);
  514. regs++;
  515. }
  516. return 0;
  517. }
  518. static int tvp5150_vdp_init(struct v4l2_subdev *sd,
  519. const struct i2c_vbi_ram_value *regs)
  520. {
  521. unsigned int i;
  522. /* Disable Full Field */
  523. tvp5150_write(sd, TVP5150_FULL_FIELD_ENA, 0);
  524. /* Before programming, Line mode should be at 0xff */
  525. for (i = TVP5150_LINE_MODE_INI; i <= TVP5150_LINE_MODE_END; i++)
  526. tvp5150_write(sd, i, 0xff);
  527. /* Load Ram Table */
  528. while (regs->reg != (u16)-1) {
  529. tvp5150_write(sd, TVP5150_CONF_RAM_ADDR_HIGH, regs->reg >> 8);
  530. tvp5150_write(sd, TVP5150_CONF_RAM_ADDR_LOW, regs->reg);
  531. for (i = 0; i < 16; i++)
  532. tvp5150_write(sd, TVP5150_VDP_CONF_RAM_DATA, regs->values[i]);
  533. regs++;
  534. }
  535. return 0;
  536. }
  537. /* Fills VBI capabilities based on i2c_vbi_ram_value struct */
  538. static int tvp5150_g_sliced_vbi_cap(struct v4l2_subdev *sd,
  539. struct v4l2_sliced_vbi_cap *cap)
  540. {
  541. const struct i2c_vbi_ram_value *regs = vbi_ram_default;
  542. int line;
  543. v4l2_dbg(1, debug, sd, "g_sliced_vbi_cap\n");
  544. memset(cap, 0, sizeof *cap);
  545. while (regs->reg != (u16)-1 ) {
  546. for (line=regs->type.ini_line;line<=regs->type.end_line;line++) {
  547. cap->service_lines[0][line] |= regs->type.vbi_type;
  548. }
  549. cap->service_set |= regs->type.vbi_type;
  550. regs++;
  551. }
  552. return 0;
  553. }
  554. /* Set vbi processing
  555. * type - one of tvp5150_vbi_types
  556. * line - line to gather data
  557. * fields: bit 0 field1, bit 1, field2
  558. * flags (default=0xf0) is a bitmask, were set means:
  559. * bit 7: enable filtering null bytes on CC
  560. * bit 6: send data also to FIFO
  561. * bit 5: don't allow data with errors on FIFO
  562. * bit 4: enable ECC when possible
  563. * pix_align = pix alignment:
  564. * LSB = field1
  565. * MSB = field2
  566. */
  567. static int tvp5150_set_vbi(struct v4l2_subdev *sd,
  568. const struct i2c_vbi_ram_value *regs,
  569. unsigned int type,u8 flags, int line,
  570. const int fields)
  571. {
  572. struct tvp5150 *decoder = to_tvp5150(sd);
  573. v4l2_std_id std = decoder->norm;
  574. u8 reg;
  575. int pos=0;
  576. if (std == V4L2_STD_ALL) {
  577. v4l2_err(sd, "VBI can't be configured without knowing number of lines\n");
  578. return 0;
  579. } else if (std & V4L2_STD_625_50) {
  580. /* Don't follow NTSC Line number convension */
  581. line += 3;
  582. }
  583. if (line<6||line>27)
  584. return 0;
  585. while (regs->reg != (u16)-1 ) {
  586. if ((type & regs->type.vbi_type) &&
  587. (line>=regs->type.ini_line) &&
  588. (line<=regs->type.end_line)) {
  589. type=regs->type.vbi_type;
  590. break;
  591. }
  592. regs++;
  593. pos++;
  594. }
  595. if (regs->reg == (u16)-1)
  596. return 0;
  597. type=pos | (flags & 0xf0);
  598. reg=((line-6)<<1)+TVP5150_LINE_MODE_INI;
  599. if (fields&1) {
  600. tvp5150_write(sd, reg, type);
  601. }
  602. if (fields&2) {
  603. tvp5150_write(sd, reg+1, type);
  604. }
  605. return type;
  606. }
  607. static int tvp5150_get_vbi(struct v4l2_subdev *sd,
  608. const struct i2c_vbi_ram_value *regs, int line)
  609. {
  610. struct tvp5150 *decoder = to_tvp5150(sd);
  611. v4l2_std_id std = decoder->norm;
  612. u8 reg;
  613. int pos, type = 0;
  614. int i, ret = 0;
  615. if (std == V4L2_STD_ALL) {
  616. v4l2_err(sd, "VBI can't be configured without knowing number of lines\n");
  617. return 0;
  618. } else if (std & V4L2_STD_625_50) {
  619. /* Don't follow NTSC Line number convension */
  620. line += 3;
  621. }
  622. if (line < 6 || line > 27)
  623. return 0;
  624. reg = ((line - 6) << 1) + TVP5150_LINE_MODE_INI;
  625. for (i = 0; i <= 1; i++) {
  626. ret = tvp5150_read(sd, reg + i);
  627. if (ret < 0) {
  628. v4l2_err(sd, "%s: failed with error = %d\n",
  629. __func__, ret);
  630. return 0;
  631. }
  632. pos = ret & 0x0f;
  633. if (pos < 0x0f)
  634. type |= regs[pos].type.vbi_type;
  635. }
  636. return type;
  637. }
  638. static int tvp5150_set_std(struct v4l2_subdev *sd, v4l2_std_id std)
  639. {
  640. struct tvp5150 *decoder = to_tvp5150(sd);
  641. int fmt = 0;
  642. decoder->norm = std;
  643. /* First tests should be against specific std */
  644. if (std == V4L2_STD_NTSC_443) {
  645. fmt = VIDEO_STD_NTSC_4_43_BIT;
  646. } else if (std == V4L2_STD_PAL_M) {
  647. fmt = VIDEO_STD_PAL_M_BIT;
  648. } else if (std == V4L2_STD_PAL_N || std == V4L2_STD_PAL_Nc) {
  649. fmt = VIDEO_STD_PAL_COMBINATION_N_BIT;
  650. } else {
  651. /* Then, test against generic ones */
  652. if (std & V4L2_STD_NTSC)
  653. fmt = VIDEO_STD_NTSC_MJ_BIT;
  654. else if (std & V4L2_STD_PAL)
  655. fmt = VIDEO_STD_PAL_BDGHIN_BIT;
  656. else if (std & V4L2_STD_SECAM)
  657. fmt = VIDEO_STD_SECAM_BIT;
  658. }
  659. v4l2_dbg(1, debug, sd, "Set video std register to %d.\n", fmt);
  660. tvp5150_write(sd, TVP5150_VIDEO_STD, fmt);
  661. return 0;
  662. }
  663. static int tvp5150_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
  664. {
  665. struct tvp5150 *decoder = to_tvp5150(sd);
  666. if (decoder->norm == std)
  667. return 0;
  668. /* Change cropping height limits */
  669. if (std & V4L2_STD_525_60)
  670. decoder->rect.height = TVP5150_V_MAX_525_60;
  671. else
  672. decoder->rect.height = TVP5150_V_MAX_OTHERS;
  673. return tvp5150_set_std(sd, std);
  674. }
  675. static int tvp5150_reset(struct v4l2_subdev *sd, u32 val)
  676. {
  677. struct tvp5150 *decoder = to_tvp5150(sd);
  678. /* Initializes TVP5150 to its default values */
  679. tvp5150_write_inittab(sd, tvp5150_init_default);
  680. /* Initializes VDP registers */
  681. tvp5150_vdp_init(sd, vbi_ram_default);
  682. /* Selects decoder input */
  683. tvp5150_selmux(sd);
  684. /* Initializes TVP5150 to stream enabled values */
  685. tvp5150_write_inittab(sd, tvp5150_init_enable);
  686. /* Initialize image preferences */
  687. v4l2_ctrl_handler_setup(&decoder->hdl);
  688. tvp5150_set_std(sd, decoder->norm);
  689. return 0;
  690. };
  691. static int tvp5150_s_ctrl(struct v4l2_ctrl *ctrl)
  692. {
  693. struct v4l2_subdev *sd = to_sd(ctrl);
  694. switch (ctrl->id) {
  695. case V4L2_CID_BRIGHTNESS:
  696. tvp5150_write(sd, TVP5150_BRIGHT_CTL, ctrl->val);
  697. return 0;
  698. case V4L2_CID_CONTRAST:
  699. tvp5150_write(sd, TVP5150_CONTRAST_CTL, ctrl->val);
  700. return 0;
  701. case V4L2_CID_SATURATION:
  702. tvp5150_write(sd, TVP5150_SATURATION_CTL, ctrl->val);
  703. return 0;
  704. case V4L2_CID_HUE:
  705. tvp5150_write(sd, TVP5150_HUE_CTL, ctrl->val);
  706. return 0;
  707. }
  708. return -EINVAL;
  709. }
  710. static v4l2_std_id tvp5150_read_std(struct v4l2_subdev *sd)
  711. {
  712. int val = tvp5150_read(sd, TVP5150_STATUS_REG_5);
  713. switch (val & 0x0F) {
  714. case 0x01:
  715. return V4L2_STD_NTSC;
  716. case 0x03:
  717. return V4L2_STD_PAL;
  718. case 0x05:
  719. return V4L2_STD_PAL_M;
  720. case 0x07:
  721. return V4L2_STD_PAL_N | V4L2_STD_PAL_Nc;
  722. case 0x09:
  723. return V4L2_STD_NTSC_443;
  724. case 0xb:
  725. return V4L2_STD_SECAM;
  726. default:
  727. return V4L2_STD_UNKNOWN;
  728. }
  729. }
  730. static int tvp5150_enum_mbus_code(struct v4l2_subdev *sd,
  731. struct v4l2_subdev_pad_config *cfg,
  732. struct v4l2_subdev_mbus_code_enum *code)
  733. {
  734. if (code->pad || code->index)
  735. return -EINVAL;
  736. code->code = MEDIA_BUS_FMT_UYVY8_2X8;
  737. return 0;
  738. }
  739. static int tvp5150_fill_fmt(struct v4l2_subdev *sd,
  740. struct v4l2_subdev_pad_config *cfg,
  741. struct v4l2_subdev_format *format)
  742. {
  743. struct v4l2_mbus_framefmt *f;
  744. struct tvp5150 *decoder = to_tvp5150(sd);
  745. if (!format || format->pad)
  746. return -EINVAL;
  747. f = &format->format;
  748. tvp5150_reset(sd, 0);
  749. f->width = decoder->rect.width;
  750. f->height = decoder->rect.height;
  751. f->code = MEDIA_BUS_FMT_UYVY8_2X8;
  752. f->field = V4L2_FIELD_SEQ_TB;
  753. f->colorspace = V4L2_COLORSPACE_SMPTE170M;
  754. v4l2_dbg(1, debug, sd, "width = %d, height = %d\n", f->width,
  755. f->height);
  756. return 0;
  757. }
  758. static int tvp5150_s_crop(struct v4l2_subdev *sd, const struct v4l2_crop *a)
  759. {
  760. struct v4l2_rect rect = a->c;
  761. struct tvp5150 *decoder = to_tvp5150(sd);
  762. v4l2_std_id std;
  763. unsigned int hmax;
  764. v4l2_dbg(1, debug, sd, "%s left=%d, top=%d, width=%d, height=%d\n",
  765. __func__, rect.left, rect.top, rect.width, rect.height);
  766. if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  767. return -EINVAL;
  768. /* tvp5150 has some special limits */
  769. rect.left = clamp(rect.left, 0, TVP5150_MAX_CROP_LEFT);
  770. rect.top = clamp(rect.top, 0, TVP5150_MAX_CROP_TOP);
  771. /* Calculate height based on current standard */
  772. if (decoder->norm == V4L2_STD_ALL)
  773. std = tvp5150_read_std(sd);
  774. else
  775. std = decoder->norm;
  776. if (std & V4L2_STD_525_60)
  777. hmax = TVP5150_V_MAX_525_60;
  778. else
  779. hmax = TVP5150_V_MAX_OTHERS;
  780. /*
  781. * alignments:
  782. * - width = 2 due to UYVY colorspace
  783. * - height, image = no special alignment
  784. */
  785. v4l_bound_align_image(&rect.width,
  786. TVP5150_H_MAX - TVP5150_MAX_CROP_LEFT - rect.left,
  787. TVP5150_H_MAX - rect.left, 1, &rect.height,
  788. hmax - TVP5150_MAX_CROP_TOP - rect.top,
  789. hmax - rect.top, 0, 0);
  790. tvp5150_write(sd, TVP5150_VERT_BLANKING_START, rect.top);
  791. tvp5150_write(sd, TVP5150_VERT_BLANKING_STOP,
  792. rect.top + rect.height - hmax);
  793. tvp5150_write(sd, TVP5150_ACT_VD_CROP_ST_MSB,
  794. rect.left >> TVP5150_CROP_SHIFT);
  795. tvp5150_write(sd, TVP5150_ACT_VD_CROP_ST_LSB,
  796. rect.left | (1 << TVP5150_CROP_SHIFT));
  797. tvp5150_write(sd, TVP5150_ACT_VD_CROP_STP_MSB,
  798. (rect.left + rect.width - TVP5150_MAX_CROP_LEFT) >>
  799. TVP5150_CROP_SHIFT);
  800. tvp5150_write(sd, TVP5150_ACT_VD_CROP_STP_LSB,
  801. rect.left + rect.width - TVP5150_MAX_CROP_LEFT);
  802. decoder->rect = rect;
  803. return 0;
  804. }
  805. static int tvp5150_g_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
  806. {
  807. struct tvp5150 *decoder = to_tvp5150(sd);
  808. a->c = decoder->rect;
  809. a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  810. return 0;
  811. }
  812. static int tvp5150_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a)
  813. {
  814. struct tvp5150 *decoder = to_tvp5150(sd);
  815. v4l2_std_id std;
  816. if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  817. return -EINVAL;
  818. a->bounds.left = 0;
  819. a->bounds.top = 0;
  820. a->bounds.width = TVP5150_H_MAX;
  821. /* Calculate height based on current standard */
  822. if (decoder->norm == V4L2_STD_ALL)
  823. std = tvp5150_read_std(sd);
  824. else
  825. std = decoder->norm;
  826. if (std & V4L2_STD_525_60)
  827. a->bounds.height = TVP5150_V_MAX_525_60;
  828. else
  829. a->bounds.height = TVP5150_V_MAX_OTHERS;
  830. a->defrect = a->bounds;
  831. a->pixelaspect.numerator = 1;
  832. a->pixelaspect.denominator = 1;
  833. return 0;
  834. }
  835. /****************************************************************************
  836. I2C Command
  837. ****************************************************************************/
  838. static int tvp5150_s_routing(struct v4l2_subdev *sd,
  839. u32 input, u32 output, u32 config)
  840. {
  841. struct tvp5150 *decoder = to_tvp5150(sd);
  842. decoder->input = input;
  843. decoder->output = output;
  844. tvp5150_selmux(sd);
  845. return 0;
  846. }
  847. static int tvp5150_s_raw_fmt(struct v4l2_subdev *sd, struct v4l2_vbi_format *fmt)
  848. {
  849. /* this is for capturing 36 raw vbi lines
  850. if there's a way to cut off the beginning 2 vbi lines
  851. with the tvp5150 then the vbi line count could be lowered
  852. to 17 lines/field again, although I couldn't find a register
  853. which could do that cropping */
  854. if (fmt->sample_format == V4L2_PIX_FMT_GREY)
  855. tvp5150_write(sd, TVP5150_LUMA_PROC_CTL_1, 0x70);
  856. if (fmt->count[0] == 18 && fmt->count[1] == 18) {
  857. tvp5150_write(sd, TVP5150_VERT_BLANKING_START, 0x00);
  858. tvp5150_write(sd, TVP5150_VERT_BLANKING_STOP, 0x01);
  859. }
  860. return 0;
  861. }
  862. static int tvp5150_s_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *svbi)
  863. {
  864. int i;
  865. if (svbi->service_set != 0) {
  866. for (i = 0; i <= 23; i++) {
  867. svbi->service_lines[1][i] = 0;
  868. svbi->service_lines[0][i] =
  869. tvp5150_set_vbi(sd, vbi_ram_default,
  870. svbi->service_lines[0][i], 0xf0, i, 3);
  871. }
  872. /* Enables FIFO */
  873. tvp5150_write(sd, TVP5150_FIFO_OUT_CTRL, 1);
  874. } else {
  875. /* Disables FIFO*/
  876. tvp5150_write(sd, TVP5150_FIFO_OUT_CTRL, 0);
  877. /* Disable Full Field */
  878. tvp5150_write(sd, TVP5150_FULL_FIELD_ENA, 0);
  879. /* Disable Line modes */
  880. for (i = TVP5150_LINE_MODE_INI; i <= TVP5150_LINE_MODE_END; i++)
  881. tvp5150_write(sd, i, 0xff);
  882. }
  883. return 0;
  884. }
  885. static int tvp5150_g_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *svbi)
  886. {
  887. int i, mask = 0;
  888. memset(svbi->service_lines, 0, sizeof(svbi->service_lines));
  889. for (i = 0; i <= 23; i++) {
  890. svbi->service_lines[0][i] =
  891. tvp5150_get_vbi(sd, vbi_ram_default, i);
  892. mask |= svbi->service_lines[0][i];
  893. }
  894. svbi->service_set = mask;
  895. return 0;
  896. }
  897. #ifdef CONFIG_VIDEO_ADV_DEBUG
  898. static int tvp5150_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg)
  899. {
  900. int res;
  901. res = tvp5150_read(sd, reg->reg & 0xff);
  902. if (res < 0) {
  903. v4l2_err(sd, "%s: failed with error = %d\n", __func__, res);
  904. return res;
  905. }
  906. reg->val = res;
  907. reg->size = 1;
  908. return 0;
  909. }
  910. static int tvp5150_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
  911. {
  912. tvp5150_write(sd, reg->reg & 0xff, reg->val & 0xff);
  913. return 0;
  914. }
  915. #endif
  916. static int tvp5150_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
  917. {
  918. int status = tvp5150_read(sd, 0x88);
  919. vt->signal = ((status & 0x04) && (status & 0x02)) ? 0xffff : 0x0;
  920. return 0;
  921. }
  922. /* ----------------------------------------------------------------------- */
  923. static const struct v4l2_ctrl_ops tvp5150_ctrl_ops = {
  924. .s_ctrl = tvp5150_s_ctrl,
  925. };
  926. static const struct v4l2_subdev_core_ops tvp5150_core_ops = {
  927. .log_status = tvp5150_log_status,
  928. .reset = tvp5150_reset,
  929. #ifdef CONFIG_VIDEO_ADV_DEBUG
  930. .g_register = tvp5150_g_register,
  931. .s_register = tvp5150_s_register,
  932. #endif
  933. };
  934. static const struct v4l2_subdev_tuner_ops tvp5150_tuner_ops = {
  935. .g_tuner = tvp5150_g_tuner,
  936. };
  937. static const struct v4l2_subdev_video_ops tvp5150_video_ops = {
  938. .s_std = tvp5150_s_std,
  939. .s_routing = tvp5150_s_routing,
  940. .s_crop = tvp5150_s_crop,
  941. .g_crop = tvp5150_g_crop,
  942. .cropcap = tvp5150_cropcap,
  943. };
  944. static const struct v4l2_subdev_vbi_ops tvp5150_vbi_ops = {
  945. .g_sliced_vbi_cap = tvp5150_g_sliced_vbi_cap,
  946. .g_sliced_fmt = tvp5150_g_sliced_fmt,
  947. .s_sliced_fmt = tvp5150_s_sliced_fmt,
  948. .s_raw_fmt = tvp5150_s_raw_fmt,
  949. };
  950. static const struct v4l2_subdev_pad_ops tvp5150_pad_ops = {
  951. .enum_mbus_code = tvp5150_enum_mbus_code,
  952. .set_fmt = tvp5150_fill_fmt,
  953. .get_fmt = tvp5150_fill_fmt,
  954. };
  955. static const struct v4l2_subdev_ops tvp5150_ops = {
  956. .core = &tvp5150_core_ops,
  957. .tuner = &tvp5150_tuner_ops,
  958. .video = &tvp5150_video_ops,
  959. .vbi = &tvp5150_vbi_ops,
  960. .pad = &tvp5150_pad_ops,
  961. };
  962. /****************************************************************************
  963. I2C Client & Driver
  964. ****************************************************************************/
  965. static int tvp5150_probe(struct i2c_client *c,
  966. const struct i2c_device_id *id)
  967. {
  968. struct tvp5150 *core;
  969. struct v4l2_subdev *sd;
  970. int tvp5150_id[4];
  971. int i, res;
  972. /* Check if the adapter supports the needed features */
  973. if (!i2c_check_functionality(c->adapter,
  974. I2C_FUNC_SMBUS_READ_BYTE | I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
  975. return -EIO;
  976. core = devm_kzalloc(&c->dev, sizeof(*core), GFP_KERNEL);
  977. if (!core)
  978. return -ENOMEM;
  979. sd = &core->sd;
  980. v4l2_i2c_subdev_init(sd, c, &tvp5150_ops);
  981. /*
  982. * Read consequent registers - TVP5150_MSB_DEV_ID, TVP5150_LSB_DEV_ID,
  983. * TVP5150_ROM_MAJOR_VER, TVP5150_ROM_MINOR_VER
  984. */
  985. for (i = 0; i < 4; i++) {
  986. res = tvp5150_read(sd, TVP5150_MSB_DEV_ID + i);
  987. if (res < 0)
  988. return res;
  989. tvp5150_id[i] = res;
  990. }
  991. v4l_info(c, "chip found @ 0x%02x (%s)\n",
  992. c->addr << 1, c->adapter->name);
  993. if (tvp5150_id[2] == 4 && tvp5150_id[3] == 0) { /* Is TVP5150AM1 */
  994. v4l2_info(sd, "tvp%02x%02xam1 detected.\n",
  995. tvp5150_id[0], tvp5150_id[1]);
  996. /* ITU-T BT.656.4 timing */
  997. tvp5150_write(sd, TVP5150_REV_SELECT, 0);
  998. } else {
  999. /* Is TVP5150A */
  1000. if (tvp5150_id[2] == 3 || tvp5150_id[3] == 0x21) {
  1001. v4l2_info(sd, "tvp%02x%02xa detected.\n",
  1002. tvp5150_id[0], tvp5150_id[1]);
  1003. } else {
  1004. v4l2_info(sd, "*** unknown tvp%02x%02x chip detected.\n",
  1005. tvp5150_id[0], tvp5150_id[1]);
  1006. v4l2_info(sd, "*** Rom ver is %d.%d\n",
  1007. tvp5150_id[2], tvp5150_id[3]);
  1008. }
  1009. }
  1010. core->norm = V4L2_STD_ALL; /* Default is autodetect */
  1011. core->input = TVP5150_COMPOSITE1;
  1012. core->enable = 1;
  1013. v4l2_ctrl_handler_init(&core->hdl, 4);
  1014. v4l2_ctrl_new_std(&core->hdl, &tvp5150_ctrl_ops,
  1015. V4L2_CID_BRIGHTNESS, 0, 255, 1, 128);
  1016. v4l2_ctrl_new_std(&core->hdl, &tvp5150_ctrl_ops,
  1017. V4L2_CID_CONTRAST, 0, 255, 1, 128);
  1018. v4l2_ctrl_new_std(&core->hdl, &tvp5150_ctrl_ops,
  1019. V4L2_CID_SATURATION, 0, 255, 1, 128);
  1020. v4l2_ctrl_new_std(&core->hdl, &tvp5150_ctrl_ops,
  1021. V4L2_CID_HUE, -128, 127, 1, 0);
  1022. sd->ctrl_handler = &core->hdl;
  1023. if (core->hdl.error) {
  1024. res = core->hdl.error;
  1025. goto err;
  1026. }
  1027. v4l2_ctrl_handler_setup(&core->hdl);
  1028. /* Default is no cropping */
  1029. core->rect.top = 0;
  1030. if (tvp5150_read_std(sd) & V4L2_STD_525_60)
  1031. core->rect.height = TVP5150_V_MAX_525_60;
  1032. else
  1033. core->rect.height = TVP5150_V_MAX_OTHERS;
  1034. core->rect.left = 0;
  1035. core->rect.width = TVP5150_H_MAX;
  1036. res = v4l2_async_register_subdev(sd);
  1037. if (res < 0)
  1038. goto err;
  1039. if (debug > 1)
  1040. tvp5150_log_status(sd);
  1041. return 0;
  1042. err:
  1043. v4l2_ctrl_handler_free(&core->hdl);
  1044. return res;
  1045. }
  1046. static int tvp5150_remove(struct i2c_client *c)
  1047. {
  1048. struct v4l2_subdev *sd = i2c_get_clientdata(c);
  1049. struct tvp5150 *decoder = to_tvp5150(sd);
  1050. v4l2_dbg(1, debug, sd,
  1051. "tvp5150.c: removing tvp5150 adapter on address 0x%x\n",
  1052. c->addr << 1);
  1053. v4l2_async_unregister_subdev(sd);
  1054. v4l2_ctrl_handler_free(&decoder->hdl);
  1055. return 0;
  1056. }
  1057. /* ----------------------------------------------------------------------- */
  1058. static const struct i2c_device_id tvp5150_id[] = {
  1059. { "tvp5150", 0 },
  1060. { }
  1061. };
  1062. MODULE_DEVICE_TABLE(i2c, tvp5150_id);
  1063. static struct i2c_driver tvp5150_driver = {
  1064. .driver = {
  1065. .name = "tvp5150",
  1066. },
  1067. .probe = tvp5150_probe,
  1068. .remove = tvp5150_remove,
  1069. .id_table = tvp5150_id,
  1070. };
  1071. module_i2c_driver(tvp5150_driver);