tvp5150.c 30 KB

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