tvp5150.c 30 KB

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