tvp5150.c 29 KB

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