tvp5150.c 30 KB

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