tvp5150.c 30 KB

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