PageRenderTime 29ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/media/i2c/tvp5150.c

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