tvp5150.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161
  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. unsigned char val;
  263. if ((decoder->route.output & TVP5150_BLACK_SCREEN) || !decoder->enable)
  264. input = 8;
  265. switch (decoder->route.input) {
  266. case TVP5150_COMPOSITE1:
  267. input |= 2;
  268. /* fall through */
  269. case TVP5150_COMPOSITE0:
  270. opmode=0x30; /* TV Mode */
  271. break;
  272. case TVP5150_SVIDEO:
  273. default:
  274. input |= 1;
  275. opmode=0; /* Auto Mode */
  276. break;
  277. }
  278. tvp5150_dbg( 1, "Selecting video route: route input=%i, output=%i "
  279. "=> tvp5150 input=%i, opmode=%i\n",
  280. decoder->route.input,decoder->route.output,
  281. input, opmode );
  282. tvp5150_write(c, TVP5150_OP_MODE_CTL, opmode);
  283. tvp5150_write(c, TVP5150_VD_IN_SRC_SEL_1, input);
  284. /* Svideo should enable YCrCb output and disable GPCL output
  285. * For Composite and TV, it should be the reverse
  286. */
  287. val = tvp5150_read(c, TVP5150_MISC_CTL);
  288. if (decoder->route.input == TVP5150_SVIDEO)
  289. val = (val & ~0x40) | 0x10;
  290. else
  291. val = (val & ~0x10) | 0x40;
  292. tvp5150_write(c, TVP5150_MISC_CTL, val);
  293. };
  294. struct i2c_reg_value {
  295. unsigned char reg;
  296. unsigned char value;
  297. };
  298. /* Default values as sugested at TVP5150AM1 datasheet */
  299. static const struct i2c_reg_value tvp5150_init_default[] = {
  300. { /* 0x00 */
  301. TVP5150_VD_IN_SRC_SEL_1,0x00
  302. },
  303. { /* 0x01 */
  304. TVP5150_ANAL_CHL_CTL,0x15
  305. },
  306. { /* 0x02 */
  307. TVP5150_OP_MODE_CTL,0x00
  308. },
  309. { /* 0x03 */
  310. TVP5150_MISC_CTL,0x01
  311. },
  312. { /* 0x06 */
  313. TVP5150_COLOR_KIL_THSH_CTL,0x10
  314. },
  315. { /* 0x07 */
  316. TVP5150_LUMA_PROC_CTL_1,0x60
  317. },
  318. { /* 0x08 */
  319. TVP5150_LUMA_PROC_CTL_2,0x00
  320. },
  321. { /* 0x09 */
  322. TVP5150_BRIGHT_CTL,0x80
  323. },
  324. { /* 0x0a */
  325. TVP5150_SATURATION_CTL,0x80
  326. },
  327. { /* 0x0b */
  328. TVP5150_HUE_CTL,0x00
  329. },
  330. { /* 0x0c */
  331. TVP5150_CONTRAST_CTL,0x80
  332. },
  333. { /* 0x0d */
  334. TVP5150_DATA_RATE_SEL,0x47
  335. },
  336. { /* 0x0e */
  337. TVP5150_LUMA_PROC_CTL_3,0x00
  338. },
  339. { /* 0x0f */
  340. TVP5150_CONF_SHARED_PIN,0x08
  341. },
  342. { /* 0x11 */
  343. TVP5150_ACT_VD_CROP_ST_MSB,0x00
  344. },
  345. { /* 0x12 */
  346. TVP5150_ACT_VD_CROP_ST_LSB,0x00
  347. },
  348. { /* 0x13 */
  349. TVP5150_ACT_VD_CROP_STP_MSB,0x00
  350. },
  351. { /* 0x14 */
  352. TVP5150_ACT_VD_CROP_STP_LSB,0x00
  353. },
  354. { /* 0x15 */
  355. TVP5150_GENLOCK,0x01
  356. },
  357. { /* 0x16 */
  358. TVP5150_HORIZ_SYNC_START,0x80
  359. },
  360. { /* 0x18 */
  361. TVP5150_VERT_BLANKING_START,0x00
  362. },
  363. { /* 0x19 */
  364. TVP5150_VERT_BLANKING_STOP,0x00
  365. },
  366. { /* 0x1a */
  367. TVP5150_CHROMA_PROC_CTL_1,0x0c
  368. },
  369. { /* 0x1b */
  370. TVP5150_CHROMA_PROC_CTL_2,0x14
  371. },
  372. { /* 0x1c */
  373. TVP5150_INT_RESET_REG_B,0x00
  374. },
  375. { /* 0x1d */
  376. TVP5150_INT_ENABLE_REG_B,0x00
  377. },
  378. { /* 0x1e */
  379. TVP5150_INTT_CONFIG_REG_B,0x00
  380. },
  381. { /* 0x28 */
  382. TVP5150_VIDEO_STD,0x00
  383. },
  384. { /* 0x2e */
  385. TVP5150_MACROVISION_ON_CTR,0x0f
  386. },
  387. { /* 0x2f */
  388. TVP5150_MACROVISION_OFF_CTR,0x01
  389. },
  390. { /* 0xbb */
  391. TVP5150_TELETEXT_FIL_ENA,0x00
  392. },
  393. { /* 0xc0 */
  394. TVP5150_INT_STATUS_REG_A,0x00
  395. },
  396. { /* 0xc1 */
  397. TVP5150_INT_ENABLE_REG_A,0x00
  398. },
  399. { /* 0xc2 */
  400. TVP5150_INT_CONF,0x04
  401. },
  402. { /* 0xc8 */
  403. TVP5150_FIFO_INT_THRESHOLD,0x80
  404. },
  405. { /* 0xc9 */
  406. TVP5150_FIFO_RESET,0x00
  407. },
  408. { /* 0xca */
  409. TVP5150_LINE_NUMBER_INT,0x00
  410. },
  411. { /* 0xcb */
  412. TVP5150_PIX_ALIGN_REG_LOW,0x4e
  413. },
  414. { /* 0xcc */
  415. TVP5150_PIX_ALIGN_REG_HIGH,0x00
  416. },
  417. { /* 0xcd */
  418. TVP5150_FIFO_OUT_CTRL,0x01
  419. },
  420. { /* 0xcf */
  421. TVP5150_FULL_FIELD_ENA,0x00
  422. },
  423. { /* 0xd0 */
  424. TVP5150_LINE_MODE_INI,0x00
  425. },
  426. { /* 0xfc */
  427. TVP5150_FULL_FIELD_MODE_REG,0x7f
  428. },
  429. { /* end of data */
  430. 0xff,0xff
  431. }
  432. };
  433. /* Default values as sugested at TVP5150AM1 datasheet */
  434. static const struct i2c_reg_value tvp5150_init_enable[] = {
  435. {
  436. TVP5150_CONF_SHARED_PIN, 2
  437. },{ /* Automatic offset and AGC enabled */
  438. TVP5150_ANAL_CHL_CTL, 0x15
  439. },{ /* Activate YCrCb output 0x9 or 0xd ? */
  440. TVP5150_MISC_CTL, 0x6f
  441. },{ /* Activates video std autodetection for all standards */
  442. TVP5150_AUTOSW_MSK, 0x0
  443. },{ /* Default format: 0x47. For 4:2:2: 0x40 */
  444. TVP5150_DATA_RATE_SEL, 0x47
  445. },{
  446. TVP5150_CHROMA_PROC_CTL_1, 0x0c
  447. },{
  448. TVP5150_CHROMA_PROC_CTL_2, 0x54
  449. },{ /* Non documented, but initialized on WinTV USB2 */
  450. 0x27, 0x20
  451. },{
  452. 0xff,0xff
  453. }
  454. };
  455. struct tvp5150_vbi_type {
  456. unsigned int vbi_type;
  457. unsigned int ini_line;
  458. unsigned int end_line;
  459. unsigned int by_field :1;
  460. };
  461. struct i2c_vbi_ram_value {
  462. u16 reg;
  463. struct tvp5150_vbi_type type;
  464. unsigned char values[16];
  465. };
  466. /* This struct have the values for each supported VBI Standard
  467. * by
  468. tvp5150_vbi_types should follow the same order as vbi_ram_default
  469. * value 0 means rom position 0x10, value 1 means rom position 0x30
  470. * and so on. There are 16 possible locations from 0 to 15.
  471. */
  472. static struct i2c_vbi_ram_value vbi_ram_default[] =
  473. {
  474. /* FIXME: Current api doesn't handle all VBI types, those not
  475. yet supported are placed under #if 0 */
  476. #if 0
  477. {0x010, /* Teletext, SECAM, WST System A */
  478. {V4L2_SLICED_TELETEXT_SECAM,6,23,1},
  479. { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x26,
  480. 0xe6, 0xb4, 0x0e, 0x00, 0x00, 0x00, 0x10, 0x00 }
  481. },
  482. #endif
  483. {0x030, /* Teletext, PAL, WST System B */
  484. {V4L2_SLICED_TELETEXT_B,6,22,1},
  485. { 0xaa, 0xaa, 0xff, 0xff, 0x27, 0x2e, 0x20, 0x2b,
  486. 0xa6, 0x72, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00 }
  487. },
  488. #if 0
  489. {0x050, /* Teletext, PAL, WST System C */
  490. {V4L2_SLICED_TELETEXT_PAL_C,6,22,1},
  491. { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x22,
  492. 0xa6, 0x98, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 }
  493. },
  494. {0x070, /* Teletext, NTSC, WST System B */
  495. {V4L2_SLICED_TELETEXT_NTSC_B,10,21,1},
  496. { 0xaa, 0xaa, 0xff, 0xff, 0x27, 0x2e, 0x20, 0x23,
  497. 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 }
  498. },
  499. {0x090, /* Tetetext, NTSC NABTS System C */
  500. {V4L2_SLICED_TELETEXT_NTSC_C,10,21,1},
  501. { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x22,
  502. 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x15, 0x00 }
  503. },
  504. {0x0b0, /* Teletext, NTSC-J, NABTS System D */
  505. {V4L2_SLICED_TELETEXT_NTSC_D,10,21,1},
  506. { 0xaa, 0xaa, 0xff, 0xff, 0xa7, 0x2e, 0x20, 0x23,
  507. 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 }
  508. },
  509. {0x0d0, /* Closed Caption, PAL/SECAM */
  510. {V4L2_SLICED_CAPTION_625,22,22,1},
  511. { 0xaa, 0x2a, 0xff, 0x3f, 0x04, 0x51, 0x6e, 0x02,
  512. 0xa6, 0x7b, 0x09, 0x00, 0x00, 0x00, 0x27, 0x00 }
  513. },
  514. #endif
  515. {0x0f0, /* Closed Caption, NTSC */
  516. {V4L2_SLICED_CAPTION_525,21,21,1},
  517. { 0xaa, 0x2a, 0xff, 0x3f, 0x04, 0x51, 0x6e, 0x02,
  518. 0x69, 0x8c, 0x09, 0x00, 0x00, 0x00, 0x27, 0x00 }
  519. },
  520. {0x110, /* Wide Screen Signal, PAL/SECAM */
  521. {V4L2_SLICED_WSS_625,23,23,1},
  522. { 0x5b, 0x55, 0xc5, 0xff, 0x00, 0x71, 0x6e, 0x42,
  523. 0xa6, 0xcd, 0x0f, 0x00, 0x00, 0x00, 0x3a, 0x00 }
  524. },
  525. #if 0
  526. {0x130, /* Wide Screen Signal, NTSC C */
  527. {V4L2_SLICED_WSS_525,20,20,1},
  528. { 0x38, 0x00, 0x3f, 0x00, 0x00, 0x71, 0x6e, 0x43,
  529. 0x69, 0x7c, 0x08, 0x00, 0x00, 0x00, 0x39, 0x00 }
  530. },
  531. {0x150, /* Vertical Interval Timecode (VITC), PAL/SECAM */
  532. {V4l2_SLICED_VITC_625,6,22,0},
  533. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x8f, 0x6d, 0x49,
  534. 0xa6, 0x85, 0x08, 0x00, 0x00, 0x00, 0x4c, 0x00 }
  535. },
  536. {0x170, /* Vertical Interval Timecode (VITC), NTSC */
  537. {V4l2_SLICED_VITC_525,10,20,0},
  538. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x8f, 0x6d, 0x49,
  539. 0x69, 0x94, 0x08, 0x00, 0x00, 0x00, 0x4c, 0x00 }
  540. },
  541. #endif
  542. {0x190, /* Video Program System (VPS), PAL */
  543. {V4L2_SLICED_VPS,16,16,0},
  544. { 0xaa, 0xaa, 0xff, 0xff, 0xba, 0xce, 0x2b, 0x0d,
  545. 0xa6, 0xda, 0x0b, 0x00, 0x00, 0x00, 0x60, 0x00 }
  546. },
  547. /* 0x1d0 User programmable */
  548. /* End of struct */
  549. { (u16)-1 }
  550. };
  551. static int tvp5150_write_inittab(struct i2c_client *c,
  552. const struct i2c_reg_value *regs)
  553. {
  554. while (regs->reg != 0xff) {
  555. tvp5150_write(c, regs->reg, regs->value);
  556. regs++;
  557. }
  558. return 0;
  559. }
  560. static int tvp5150_vdp_init(struct i2c_client *c,
  561. const struct i2c_vbi_ram_value *regs)
  562. {
  563. unsigned int i;
  564. /* Disable Full Field */
  565. tvp5150_write(c, TVP5150_FULL_FIELD_ENA, 0);
  566. /* Before programming, Line mode should be at 0xff */
  567. for (i=TVP5150_LINE_MODE_INI; i<=TVP5150_LINE_MODE_END; i++)
  568. tvp5150_write(c, i, 0xff);
  569. /* Load Ram Table */
  570. while (regs->reg != (u16)-1 ) {
  571. tvp5150_write(c, TVP5150_CONF_RAM_ADDR_HIGH,regs->reg>>8);
  572. tvp5150_write(c, TVP5150_CONF_RAM_ADDR_LOW,regs->reg);
  573. for (i=0;i<16;i++)
  574. tvp5150_write(c, TVP5150_VDP_CONF_RAM_DATA,regs->values[i]);
  575. regs++;
  576. }
  577. return 0;
  578. }
  579. /* Fills VBI capabilities based on i2c_vbi_ram_value struct */
  580. static void tvp5150_vbi_get_cap(const struct i2c_vbi_ram_value *regs,
  581. struct v4l2_sliced_vbi_cap *cap)
  582. {
  583. int line;
  584. memset(cap, 0, sizeof *cap);
  585. while (regs->reg != (u16)-1 ) {
  586. for (line=regs->type.ini_line;line<=regs->type.end_line;line++) {
  587. cap->service_lines[0][line] |= regs->type.vbi_type;
  588. }
  589. cap->service_set |= regs->type.vbi_type;
  590. regs++;
  591. }
  592. }
  593. /* Set vbi processing
  594. * type - one of tvp5150_vbi_types
  595. * line - line to gather data
  596. * fields: bit 0 field1, bit 1, field2
  597. * flags (default=0xf0) is a bitmask, were set means:
  598. * bit 7: enable filtering null bytes on CC
  599. * bit 6: send data also to FIFO
  600. * bit 5: don't allow data with errors on FIFO
  601. * bit 4: enable ECC when possible
  602. * pix_align = pix alignment:
  603. * LSB = field1
  604. * MSB = field2
  605. */
  606. static int tvp5150_set_vbi(struct i2c_client *c,
  607. const struct i2c_vbi_ram_value *regs,
  608. unsigned int type,u8 flags, int line,
  609. const int fields)
  610. {
  611. struct tvp5150 *decoder = i2c_get_clientdata(c);
  612. v4l2_std_id std=decoder->norm;
  613. u8 reg;
  614. int pos=0;
  615. if (std == V4L2_STD_ALL) {
  616. tvp5150_err("VBI can't be configured without knowing number of lines\n");
  617. return 0;
  618. } else if (std & V4L2_STD_625_50) {
  619. /* Don't follow NTSC Line number convension */
  620. line += 3;
  621. }
  622. if (line<6||line>27)
  623. return 0;
  624. while (regs->reg != (u16)-1 ) {
  625. if ((type & regs->type.vbi_type) &&
  626. (line>=regs->type.ini_line) &&
  627. (line<=regs->type.end_line)) {
  628. type=regs->type.vbi_type;
  629. break;
  630. }
  631. regs++;
  632. pos++;
  633. }
  634. if (regs->reg == (u16)-1)
  635. return 0;
  636. type=pos | (flags & 0xf0);
  637. reg=((line-6)<<1)+TVP5150_LINE_MODE_INI;
  638. if (fields&1) {
  639. tvp5150_write(c, reg, type);
  640. }
  641. if (fields&2) {
  642. tvp5150_write(c, reg+1, type);
  643. }
  644. return type;
  645. }
  646. static int tvp5150_get_vbi(struct i2c_client *c,
  647. const struct i2c_vbi_ram_value *regs, int line)
  648. {
  649. struct tvp5150 *decoder = i2c_get_clientdata(c);
  650. v4l2_std_id std=decoder->norm;
  651. u8 reg;
  652. int pos, type=0;
  653. if (std == V4L2_STD_ALL) {
  654. tvp5150_err("VBI can't be configured without knowing number of lines\n");
  655. return 0;
  656. } else if (std & V4L2_STD_625_50) {
  657. /* Don't follow NTSC Line number convension */
  658. line += 3;
  659. }
  660. if (line<6||line>27)
  661. return 0;
  662. reg=((line-6)<<1)+TVP5150_LINE_MODE_INI;
  663. pos=tvp5150_read(c, reg)&0x0f;
  664. if (pos<0x0f)
  665. type=regs[pos].type.vbi_type;
  666. pos=tvp5150_read(c, reg+1)&0x0f;
  667. if (pos<0x0f)
  668. type|=regs[pos].type.vbi_type;
  669. return type;
  670. }
  671. static int tvp5150_set_std(struct i2c_client *c, v4l2_std_id std)
  672. {
  673. struct tvp5150 *decoder = i2c_get_clientdata(c);
  674. int fmt=0;
  675. decoder->norm=std;
  676. /* First tests should be against specific std */
  677. if (std == V4L2_STD_ALL) {
  678. fmt=0; /* Autodetect mode */
  679. } else if (std & V4L2_STD_NTSC_443) {
  680. fmt=0xa;
  681. } else if (std & V4L2_STD_PAL_M) {
  682. fmt=0x6;
  683. } else if (std & (V4L2_STD_PAL_N| V4L2_STD_PAL_Nc)) {
  684. fmt=0x8;
  685. } else {
  686. /* Then, test against generic ones */
  687. if (std & V4L2_STD_NTSC) {
  688. fmt=0x2;
  689. } else if (std & V4L2_STD_PAL) {
  690. fmt=0x4;
  691. } else if (std & V4L2_STD_SECAM) {
  692. fmt=0xc;
  693. }
  694. }
  695. tvp5150_dbg(1,"Set video std register to %d.\n",fmt);
  696. tvp5150_write(c, TVP5150_VIDEO_STD, fmt);
  697. return 0;
  698. }
  699. static inline void tvp5150_reset(struct i2c_client *c)
  700. {
  701. u8 msb_id, lsb_id, msb_rom, lsb_rom;
  702. struct tvp5150 *decoder = i2c_get_clientdata(c);
  703. msb_id=tvp5150_read(c,TVP5150_MSB_DEV_ID);
  704. lsb_id=tvp5150_read(c,TVP5150_LSB_DEV_ID);
  705. msb_rom=tvp5150_read(c,TVP5150_ROM_MAJOR_VER);
  706. lsb_rom=tvp5150_read(c,TVP5150_ROM_MINOR_VER);
  707. if ((msb_rom==4)&&(lsb_rom==0)) { /* Is TVP5150AM1 */
  708. tvp5150_info("tvp%02x%02xam1 detected.\n",msb_id, lsb_id);
  709. /* ITU-T BT.656.4 timing */
  710. tvp5150_write(c,TVP5150_REV_SELECT,0);
  711. } else {
  712. if ((msb_rom==3)||(lsb_rom==0x21)) { /* Is TVP5150A */
  713. tvp5150_info("tvp%02x%02xa detected.\n",msb_id, lsb_id);
  714. } else {
  715. tvp5150_info("*** unknown tvp%02x%02x chip detected.\n",msb_id,lsb_id);
  716. tvp5150_info("*** Rom ver is %d.%d\n",msb_rom,lsb_rom);
  717. }
  718. }
  719. /* Initializes TVP5150 to its default values */
  720. tvp5150_write_inittab(c, tvp5150_init_default);
  721. /* Initializes VDP registers */
  722. tvp5150_vdp_init(c, vbi_ram_default);
  723. /* Selects decoder input */
  724. tvp5150_selmux(c);
  725. /* Initializes TVP5150 to stream enabled values */
  726. tvp5150_write_inittab(c, tvp5150_init_enable);
  727. /* Initialize image preferences */
  728. tvp5150_write(c, TVP5150_BRIGHT_CTL, decoder->bright);
  729. tvp5150_write(c, TVP5150_CONTRAST_CTL, decoder->contrast);
  730. tvp5150_write(c, TVP5150_SATURATION_CTL, decoder->contrast);
  731. tvp5150_write(c, TVP5150_HUE_CTL, decoder->hue);
  732. tvp5150_set_std(c, decoder->norm);
  733. };
  734. static int tvp5150_get_ctrl(struct i2c_client *c, struct v4l2_control *ctrl)
  735. {
  736. /* struct tvp5150 *decoder = i2c_get_clientdata(c); */
  737. switch (ctrl->id) {
  738. case V4L2_CID_BRIGHTNESS:
  739. ctrl->value = tvp5150_read(c, TVP5150_BRIGHT_CTL);
  740. return 0;
  741. case V4L2_CID_CONTRAST:
  742. ctrl->value = tvp5150_read(c, TVP5150_CONTRAST_CTL);
  743. return 0;
  744. case V4L2_CID_SATURATION:
  745. ctrl->value = tvp5150_read(c, TVP5150_SATURATION_CTL);
  746. return 0;
  747. case V4L2_CID_HUE:
  748. ctrl->value = tvp5150_read(c, TVP5150_HUE_CTL);
  749. return 0;
  750. }
  751. return -EINVAL;
  752. }
  753. static int tvp5150_set_ctrl(struct i2c_client *c, struct v4l2_control *ctrl)
  754. {
  755. /* struct tvp5150 *decoder = i2c_get_clientdata(c); */
  756. switch (ctrl->id) {
  757. case V4L2_CID_BRIGHTNESS:
  758. tvp5150_write(c, TVP5150_BRIGHT_CTL, ctrl->value);
  759. return 0;
  760. case V4L2_CID_CONTRAST:
  761. tvp5150_write(c, TVP5150_CONTRAST_CTL, ctrl->value);
  762. return 0;
  763. case V4L2_CID_SATURATION:
  764. tvp5150_write(c, TVP5150_SATURATION_CTL, ctrl->value);
  765. return 0;
  766. case V4L2_CID_HUE:
  767. tvp5150_write(c, TVP5150_HUE_CTL, ctrl->value);
  768. return 0;
  769. }
  770. return -EINVAL;
  771. }
  772. /****************************************************************************
  773. I2C Command
  774. ****************************************************************************/
  775. static int tvp5150_command(struct i2c_client *c,
  776. unsigned int cmd, void *arg)
  777. {
  778. struct tvp5150 *decoder = i2c_get_clientdata(c);
  779. switch (cmd) {
  780. case 0:
  781. case VIDIOC_INT_RESET:
  782. tvp5150_reset(c);
  783. break;
  784. case VIDIOC_INT_G_VIDEO_ROUTING:
  785. {
  786. struct v4l2_routing *route = arg;
  787. *route = decoder->route;
  788. break;
  789. }
  790. case VIDIOC_INT_S_VIDEO_ROUTING:
  791. {
  792. struct v4l2_routing *route = arg;
  793. decoder->route = *route;
  794. tvp5150_selmux(c);
  795. break;
  796. }
  797. case VIDIOC_S_STD:
  798. if (decoder->norm == *(v4l2_std_id *)arg)
  799. break;
  800. return tvp5150_set_std(c, *(v4l2_std_id *)arg);
  801. case VIDIOC_G_STD:
  802. *(v4l2_std_id *)arg = decoder->norm;
  803. break;
  804. case VIDIOC_G_SLICED_VBI_CAP:
  805. {
  806. struct v4l2_sliced_vbi_cap *cap = arg;
  807. tvp5150_dbg(1, "VIDIOC_G_SLICED_VBI_CAP\n");
  808. tvp5150_vbi_get_cap(vbi_ram_default, cap);
  809. break;
  810. }
  811. case VIDIOC_S_FMT:
  812. {
  813. struct v4l2_format *fmt;
  814. struct v4l2_sliced_vbi_format *svbi;
  815. int i;
  816. fmt = arg;
  817. if (fmt->type != V4L2_BUF_TYPE_SLICED_VBI_CAPTURE)
  818. return -EINVAL;
  819. svbi = &fmt->fmt.sliced;
  820. if (svbi->service_set != 0) {
  821. for (i = 0; i <= 23; i++) {
  822. svbi->service_lines[1][i] = 0;
  823. svbi->service_lines[0][i]=tvp5150_set_vbi(c,
  824. vbi_ram_default,
  825. svbi->service_lines[0][i],0xf0,i,3);
  826. }
  827. /* Enables FIFO */
  828. tvp5150_write(c, TVP5150_FIFO_OUT_CTRL,1);
  829. } else {
  830. /* Disables FIFO*/
  831. tvp5150_write(c, TVP5150_FIFO_OUT_CTRL,0);
  832. /* Disable Full Field */
  833. tvp5150_write(c, TVP5150_FULL_FIELD_ENA, 0);
  834. /* Disable Line modes */
  835. for (i=TVP5150_LINE_MODE_INI; i<=TVP5150_LINE_MODE_END; i++)
  836. tvp5150_write(c, i, 0xff);
  837. }
  838. break;
  839. }
  840. case VIDIOC_G_FMT:
  841. {
  842. struct v4l2_format *fmt;
  843. struct v4l2_sliced_vbi_format *svbi;
  844. int i, mask=0;
  845. fmt = arg;
  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]=tvp5150_get_vbi(c,
  852. vbi_ram_default,i);
  853. mask|=svbi->service_lines[0][i];
  854. }
  855. svbi->service_set=mask;
  856. break;
  857. }
  858. #ifdef CONFIG_VIDEO_ADV_DEBUG
  859. case VIDIOC_DBG_G_REGISTER:
  860. case VIDIOC_DBG_S_REGISTER:
  861. {
  862. struct v4l2_register *reg = arg;
  863. if (!v4l2_chip_match_i2c_client(c, reg->match_type, reg->match_chip))
  864. return -EINVAL;
  865. if (!capable(CAP_SYS_ADMIN))
  866. return -EPERM;
  867. if (cmd == VIDIOC_DBG_G_REGISTER)
  868. reg->val = tvp5150_read(c, reg->reg & 0xff);
  869. else
  870. tvp5150_write(c, reg->reg & 0xff, reg->val & 0xff);
  871. break;
  872. }
  873. #endif
  874. case VIDIOC_LOG_STATUS:
  875. dump_reg(c);
  876. break;
  877. case VIDIOC_G_TUNER:
  878. {
  879. struct v4l2_tuner *vt = arg;
  880. int status = tvp5150_read(c, 0x88);
  881. vt->signal = ((status & 0x04) && (status & 0x02)) ? 0xffff : 0x0;
  882. break;
  883. }
  884. case VIDIOC_QUERYCTRL:
  885. {
  886. struct v4l2_queryctrl *qc = arg;
  887. int i;
  888. tvp5150_dbg(1, "VIDIOC_QUERYCTRL called\n");
  889. for (i = 0; i < ARRAY_SIZE(tvp5150_qctrl); i++)
  890. if (qc->id && qc->id == tvp5150_qctrl[i].id) {
  891. memcpy(qc, &(tvp5150_qctrl[i]),
  892. sizeof(*qc));
  893. return 0;
  894. }
  895. return -EINVAL;
  896. }
  897. case VIDIOC_G_CTRL:
  898. {
  899. struct v4l2_control *ctrl = arg;
  900. tvp5150_dbg(1, "VIDIOC_G_CTRL called\n");
  901. return tvp5150_get_ctrl(c, ctrl);
  902. }
  903. case VIDIOC_S_CTRL:
  904. {
  905. struct v4l2_control *ctrl = arg;
  906. u8 i, n;
  907. n = ARRAY_SIZE(tvp5150_qctrl);
  908. for (i = 0; i < n; i++)
  909. if (ctrl->id == tvp5150_qctrl[i].id) {
  910. if (ctrl->value <
  911. tvp5150_qctrl[i].minimum
  912. || ctrl->value >
  913. tvp5150_qctrl[i].maximum)
  914. return -ERANGE;
  915. tvp5150_dbg(1,
  916. "VIDIOC_S_CTRL: id=%d, value=%d\n",
  917. ctrl->id, ctrl->value);
  918. return tvp5150_set_ctrl(c, ctrl);
  919. }
  920. return -EINVAL;
  921. }
  922. default:
  923. return -EINVAL;
  924. }
  925. return 0;
  926. }
  927. /****************************************************************************
  928. I2C Client & Driver
  929. ****************************************************************************/
  930. static struct i2c_driver driver;
  931. static struct i2c_client client_template = {
  932. .name = "(unset)",
  933. .driver = &driver,
  934. };
  935. static int tvp5150_detect_client(struct i2c_adapter *adapter,
  936. int address, int kind)
  937. {
  938. struct i2c_client *c;
  939. struct tvp5150 *core;
  940. int rv;
  941. if (debug)
  942. printk( KERN_INFO
  943. "tvp5150.c: detecting tvp5150 client on address 0x%x\n",
  944. address << 1);
  945. client_template.adapter = adapter;
  946. client_template.addr = address;
  947. /* Check if the adapter supports the needed features */
  948. if (!i2c_check_functionality
  949. (adapter,
  950. I2C_FUNC_SMBUS_READ_BYTE | I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
  951. return 0;
  952. c = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
  953. if (!c)
  954. return -ENOMEM;
  955. memcpy(c, &client_template, sizeof(struct i2c_client));
  956. core = kzalloc(sizeof(struct tvp5150), GFP_KERNEL);
  957. if (!core) {
  958. kfree(c);
  959. return -ENOMEM;
  960. }
  961. i2c_set_clientdata(c, core);
  962. rv = i2c_attach_client(c);
  963. core->norm = V4L2_STD_ALL; /* Default is autodetect */
  964. core->route.input = TVP5150_COMPOSITE1;
  965. core->enable = 1;
  966. core->bright = 128;
  967. core->contrast = 128;
  968. core->hue = 0;
  969. core->sat = 128;
  970. if (rv) {
  971. kfree(c);
  972. kfree(core);
  973. return rv;
  974. }
  975. if (debug > 1)
  976. dump_reg(c);
  977. return 0;
  978. }
  979. static int tvp5150_attach_adapter(struct i2c_adapter *adapter)
  980. {
  981. if (debug)
  982. printk( KERN_INFO
  983. "tvp5150.c: starting probe for adapter %s (0x%x)\n",
  984. adapter->name, adapter->id);
  985. return i2c_probe(adapter, &addr_data, &tvp5150_detect_client);
  986. }
  987. static int tvp5150_detach_client(struct i2c_client *c)
  988. {
  989. struct tvp5150 *decoder = i2c_get_clientdata(c);
  990. int err;
  991. tvp5150_dbg(1,
  992. "tvp5150.c: removing tvp5150 adapter on address 0x%x\n",
  993. c->addr << 1);
  994. err = i2c_detach_client(c);
  995. if (err) {
  996. return err;
  997. }
  998. kfree(decoder);
  999. kfree(c);
  1000. return 0;
  1001. }
  1002. /* ----------------------------------------------------------------------- */
  1003. static struct i2c_driver driver = {
  1004. .driver = {
  1005. .name = "tvp5150",
  1006. },
  1007. .id = I2C_DRIVERID_TVP5150,
  1008. .attach_adapter = tvp5150_attach_adapter,
  1009. .detach_client = tvp5150_detach_client,
  1010. .command = tvp5150_command,
  1011. };
  1012. static int __init tvp5150_init(void)
  1013. {
  1014. return i2c_add_driver(&driver);
  1015. }
  1016. static void __exit tvp5150_exit(void)
  1017. {
  1018. i2c_del_driver(&driver);
  1019. }
  1020. module_init(tvp5150_init);
  1021. module_exit(tvp5150_exit);