tvp5150.c 31 KB

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