tvp5150.c 31 KB

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