tvp5150.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142
  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_raw_fmt(struct v4l2_subdev *sd, struct v4l2_vbi_format *fmt)
  798. {
  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->sample_format == V4L2_PIX_FMT_GREY)
  805. tvp5150_write(sd, TVP5150_LUMA_PROC_CTL_1, 0x70);
  806. if (fmt->count[0] == 18 && fmt->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. static int tvp5150_s_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *svbi)
  813. {
  814. int i;
  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_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
  836. {
  837. switch (fmt->type) {
  838. case V4L2_BUF_TYPE_VBI_CAPTURE:
  839. return tvp5150_s_raw_fmt(sd, &fmt->fmt.vbi);
  840. case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
  841. return tvp5150_s_sliced_fmt(sd, &fmt->fmt.sliced);
  842. default:
  843. return -EINVAL;
  844. }
  845. }
  846. static int tvp5150_g_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *svbi)
  847. {
  848. int i, mask = 0;
  849. memset(svbi, 0, sizeof(*svbi));
  850. for (i = 0; i <= 23; i++) {
  851. svbi->service_lines[0][i] =
  852. tvp5150_get_vbi(sd, vbi_ram_default, i);
  853. mask |= svbi->service_lines[0][i];
  854. }
  855. svbi->service_set = mask;
  856. return 0;
  857. }
  858. static int tvp5150_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
  859. {
  860. if (fmt->type != V4L2_BUF_TYPE_SLICED_VBI_CAPTURE)
  861. return -EINVAL;
  862. return tvp5150_g_sliced_fmt(sd, &fmt->fmt.sliced);
  863. }
  864. static int tvp5150_g_chip_ident(struct v4l2_subdev *sd,
  865. struct v4l2_dbg_chip_ident *chip)
  866. {
  867. int rev;
  868. struct i2c_client *client = v4l2_get_subdevdata(sd);
  869. rev = tvp5150_read(sd, TVP5150_ROM_MAJOR_VER) << 8 |
  870. tvp5150_read(sd, TVP5150_ROM_MINOR_VER);
  871. return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_TVP5150,
  872. rev);
  873. }
  874. #ifdef CONFIG_VIDEO_ADV_DEBUG
  875. static int tvp5150_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg)
  876. {
  877. struct i2c_client *client = v4l2_get_subdevdata(sd);
  878. if (!v4l2_chip_match_i2c_client(client, &reg->match))
  879. return -EINVAL;
  880. if (!capable(CAP_SYS_ADMIN))
  881. return -EPERM;
  882. reg->val = tvp5150_read(sd, reg->reg & 0xff);
  883. reg->size = 1;
  884. return 0;
  885. }
  886. static int tvp5150_s_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg)
  887. {
  888. struct i2c_client *client = v4l2_get_subdevdata(sd);
  889. if (!v4l2_chip_match_i2c_client(client, &reg->match))
  890. return -EINVAL;
  891. if (!capable(CAP_SYS_ADMIN))
  892. return -EPERM;
  893. tvp5150_write(sd, reg->reg & 0xff, reg->val & 0xff);
  894. return 0;
  895. }
  896. #endif
  897. static int tvp5150_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
  898. {
  899. int status = tvp5150_read(sd, 0x88);
  900. vt->signal = ((status & 0x04) && (status & 0x02)) ? 0xffff : 0x0;
  901. return 0;
  902. }
  903. static int tvp5150_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc)
  904. {
  905. int i;
  906. v4l2_dbg(1, debug, sd, "queryctrl called\n");
  907. for (i = 0; i < ARRAY_SIZE(tvp5150_qctrl); i++)
  908. if (qc->id && qc->id == tvp5150_qctrl[i].id) {
  909. memcpy(qc, &(tvp5150_qctrl[i]),
  910. sizeof(*qc));
  911. return 0;
  912. }
  913. return -EINVAL;
  914. }
  915. /* ----------------------------------------------------------------------- */
  916. static const struct v4l2_subdev_core_ops tvp5150_core_ops = {
  917. .log_status = tvp5150_log_status,
  918. .g_ctrl = tvp5150_g_ctrl,
  919. .s_ctrl = tvp5150_s_ctrl,
  920. .queryctrl = tvp5150_queryctrl,
  921. .s_std = tvp5150_s_std,
  922. .reset = tvp5150_reset,
  923. .g_chip_ident = tvp5150_g_chip_ident,
  924. #ifdef CONFIG_VIDEO_ADV_DEBUG
  925. .g_register = tvp5150_g_register,
  926. .s_register = tvp5150_s_register,
  927. #endif
  928. };
  929. static const struct v4l2_subdev_tuner_ops tvp5150_tuner_ops = {
  930. .g_tuner = tvp5150_g_tuner,
  931. };
  932. static const struct v4l2_subdev_video_ops tvp5150_video_ops = {
  933. .s_routing = tvp5150_s_routing,
  934. .g_fmt = tvp5150_g_fmt,
  935. .s_fmt = tvp5150_s_fmt,
  936. };
  937. static const struct v4l2_subdev_vbi_ops tvp5150_vbi_ops = {
  938. .g_sliced_vbi_cap = tvp5150_g_sliced_vbi_cap,
  939. .g_sliced_fmt = tvp5150_g_sliced_fmt,
  940. .s_sliced_fmt = tvp5150_s_sliced_fmt,
  941. .s_raw_fmt = tvp5150_s_raw_fmt,
  942. };
  943. static const struct v4l2_subdev_ops tvp5150_ops = {
  944. .core = &tvp5150_core_ops,
  945. .tuner = &tvp5150_tuner_ops,
  946. .video = &tvp5150_video_ops,
  947. .vbi = &tvp5150_vbi_ops,
  948. };
  949. /****************************************************************************
  950. I2C Client & Driver
  951. ****************************************************************************/
  952. static int tvp5150_probe(struct i2c_client *c,
  953. const struct i2c_device_id *id)
  954. {
  955. struct tvp5150 *core;
  956. struct v4l2_subdev *sd;
  957. /* Check if the adapter supports the needed features */
  958. if (!i2c_check_functionality(c->adapter,
  959. I2C_FUNC_SMBUS_READ_BYTE | I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
  960. return -EIO;
  961. core = kzalloc(sizeof(struct tvp5150), GFP_KERNEL);
  962. if (!core) {
  963. return -ENOMEM;
  964. }
  965. sd = &core->sd;
  966. v4l2_i2c_subdev_init(sd, c, &tvp5150_ops);
  967. v4l_info(c, "chip found @ 0x%02x (%s)\n",
  968. c->addr << 1, c->adapter->name);
  969. core->norm = V4L2_STD_ALL; /* Default is autodetect */
  970. core->input = TVP5150_COMPOSITE1;
  971. core->enable = 1;
  972. core->bright = 128;
  973. core->contrast = 128;
  974. core->hue = 0;
  975. core->sat = 128;
  976. if (debug > 1)
  977. tvp5150_log_status(sd);
  978. return 0;
  979. }
  980. static int tvp5150_remove(struct i2c_client *c)
  981. {
  982. struct v4l2_subdev *sd = i2c_get_clientdata(c);
  983. v4l2_dbg(1, debug, sd,
  984. "tvp5150.c: removing tvp5150 adapter on address 0x%x\n",
  985. c->addr << 1);
  986. v4l2_device_unregister_subdev(sd);
  987. kfree(to_tvp5150(sd));
  988. return 0;
  989. }
  990. /* ----------------------------------------------------------------------- */
  991. static const struct i2c_device_id tvp5150_id[] = {
  992. { "tvp5150", 0 },
  993. { }
  994. };
  995. MODULE_DEVICE_TABLE(i2c, tvp5150_id);
  996. static struct v4l2_i2c_driver_data v4l2_i2c_data = {
  997. .name = "tvp5150",
  998. .probe = tvp5150_probe,
  999. .remove = tvp5150_remove,
  1000. .id_table = tvp5150_id,
  1001. };