tvp5150.c 30 KB

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