tvp5150.c 29 KB

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