saa7114.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232
  1. /*
  2. * saa7114 - Philips SAA7114H video decoder driver version 0.0.1
  3. *
  4. * Copyright (C) 2002 Maxim Yevtyushkin <max@linuxmedialabs.com>
  5. *
  6. * Based on saa7111 driver by Dave Perks
  7. *
  8. * Copyright (C) 1998 Dave Perks <dperks@ibm.net>
  9. *
  10. * Slight changes for video timing and attachment output by
  11. * Wolfgang Scherr <scherr@net4you.net>
  12. *
  13. * Changes by Ronald Bultje <rbultje@ronald.bitfreak.net>
  14. * - moved over to linux>=2.4.x i2c protocol (1/1/2003)
  15. *
  16. * This program is free software; you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License as published by
  18. * the Free Software Foundation; either version 2 of the License, or
  19. * (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program; if not, write to the Free Software
  28. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  29. */
  30. #include <linux/module.h>
  31. #include <linux/init.h>
  32. #include <linux/delay.h>
  33. #include <linux/errno.h>
  34. #include <linux/fs.h>
  35. #include <linux/kernel.h>
  36. #include <linux/major.h>
  37. #include <linux/slab.h>
  38. #include <linux/mm.h>
  39. #include <linux/pci.h>
  40. #include <linux/signal.h>
  41. #include <asm/io.h>
  42. #include <asm/pgtable.h>
  43. #include <asm/page.h>
  44. #include <linux/sched.h>
  45. #include <asm/segment.h>
  46. #include <linux/types.h>
  47. #include <linux/videodev.h>
  48. #include <asm/uaccess.h>
  49. MODULE_DESCRIPTION("Philips SAA7114H video decoder driver");
  50. MODULE_AUTHOR("Maxim Yevtyushkin");
  51. MODULE_LICENSE("GPL");
  52. #include <linux/i2c.h>
  53. #include <linux/i2c-dev.h>
  54. #define I2C_NAME(x) (x)->name
  55. #include <linux/video_decoder.h>
  56. static int debug = 0;
  57. module_param(debug, int, 0);
  58. MODULE_PARM_DESC(debug, "Debug level (0-1)");
  59. #define dprintk(num, format, args...) \
  60. do { \
  61. if (debug >= num) \
  62. printk(format, ##args); \
  63. } while (0)
  64. /* ----------------------------------------------------------------------- */
  65. struct saa7114 {
  66. unsigned char reg[0xf0 * 2];
  67. int norm;
  68. int input;
  69. int enable;
  70. int bright;
  71. int contrast;
  72. int hue;
  73. int sat;
  74. int playback;
  75. };
  76. #define I2C_SAA7114 0x42
  77. #define I2C_SAA7114A 0x40
  78. #define I2C_DELAY 10
  79. //#define SAA_7114_NTSC_HSYNC_START (-3)
  80. //#define SAA_7114_NTSC_HSYNC_STOP (-18)
  81. #define SAA_7114_NTSC_HSYNC_START (-17)
  82. #define SAA_7114_NTSC_HSYNC_STOP (-32)
  83. //#define SAA_7114_NTSC_HOFFSET (5)
  84. #define SAA_7114_NTSC_HOFFSET (6)
  85. #define SAA_7114_NTSC_VOFFSET (10)
  86. #define SAA_7114_NTSC_WIDTH (720)
  87. #define SAA_7114_NTSC_HEIGHT (250)
  88. #define SAA_7114_SECAM_HSYNC_START (-17)
  89. #define SAA_7114_SECAM_HSYNC_STOP (-32)
  90. #define SAA_7114_SECAM_HOFFSET (2)
  91. #define SAA_7114_SECAM_VOFFSET (10)
  92. #define SAA_7114_SECAM_WIDTH (720)
  93. #define SAA_7114_SECAM_HEIGHT (300)
  94. #define SAA_7114_PAL_HSYNC_START (-17)
  95. #define SAA_7114_PAL_HSYNC_STOP (-32)
  96. #define SAA_7114_PAL_HOFFSET (2)
  97. #define SAA_7114_PAL_VOFFSET (10)
  98. #define SAA_7114_PAL_WIDTH (720)
  99. #define SAA_7114_PAL_HEIGHT (300)
  100. #define SAA_7114_VERTICAL_CHROMA_OFFSET 0 //0x50504040
  101. #define SAA_7114_VERTICAL_LUMA_OFFSET 0
  102. #define REG_ADDR(x) (((x) << 1) + 1)
  103. #define LOBYTE(x) ((unsigned char)((x) & 0xff))
  104. #define HIBYTE(x) ((unsigned char)(((x) >> 8) & 0xff))
  105. #define LOWORD(x) ((unsigned short int)((x) & 0xffff))
  106. #define HIWORD(x) ((unsigned short int)(((x) >> 16) & 0xffff))
  107. /* ----------------------------------------------------------------------- */
  108. static inline int
  109. saa7114_write (struct i2c_client *client,
  110. u8 reg,
  111. u8 value)
  112. {
  113. /*struct saa7114 *decoder = i2c_get_clientdata(client);*/
  114. /*decoder->reg[reg] = value;*/
  115. return i2c_smbus_write_byte_data(client, reg, value);
  116. }
  117. static int
  118. saa7114_write_block (struct i2c_client *client,
  119. const u8 *data,
  120. unsigned int len)
  121. {
  122. int ret = -1;
  123. u8 reg;
  124. /* the saa7114 has an autoincrement function, use it if
  125. * the adapter understands raw I2C */
  126. if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
  127. /* do raw I2C, not smbus compatible */
  128. /*struct saa7114 *decoder = i2c_get_clientdata(client);*/
  129. struct i2c_msg msg;
  130. u8 block_data[32];
  131. msg.addr = client->addr;
  132. msg.flags = 0;
  133. while (len >= 2) {
  134. msg.buf = (char *) block_data;
  135. msg.len = 0;
  136. block_data[msg.len++] = reg = data[0];
  137. do {
  138. block_data[msg.len++] =
  139. /*decoder->reg[reg++] =*/ data[1];
  140. len -= 2;
  141. data += 2;
  142. } while (len >= 2 && data[0] == reg &&
  143. msg.len < 32);
  144. if ((ret = i2c_transfer(client->adapter,
  145. &msg, 1)) < 0)
  146. break;
  147. }
  148. } else {
  149. /* do some slow I2C emulation kind of thing */
  150. while (len >= 2) {
  151. reg = *data++;
  152. if ((ret = saa7114_write(client, reg,
  153. *data++)) < 0)
  154. break;
  155. len -= 2;
  156. }
  157. }
  158. return ret;
  159. }
  160. static inline int
  161. saa7114_read (struct i2c_client *client,
  162. u8 reg)
  163. {
  164. return i2c_smbus_read_byte_data(client, reg);
  165. }
  166. /* ----------------------------------------------------------------------- */
  167. // initially set NTSC, composite
  168. static const unsigned char init[] = {
  169. 0x00, 0x00, /* 00 - ID byte , chip version,
  170. * read only */
  171. 0x01, 0x08, /* 01 - X,X,X,X, IDEL3 to IDEL0 -
  172. * horizontal increment delay,
  173. * recommended position */
  174. 0x02, 0x00, /* 02 - FUSE=3, GUDL=2, MODE=0 ;
  175. * input control */
  176. 0x03, 0x10, /* 03 - HLNRS=0, VBSL=1, WPOFF=0,
  177. * HOLDG=0, GAFIX=0, GAI1=256, GAI2=256 */
  178. 0x04, 0x90, /* 04 - GAI1=256 */
  179. 0x05, 0x90, /* 05 - GAI2=256 */
  180. 0x06, SAA_7114_NTSC_HSYNC_START, /* 06 - HSB: hsync start,
  181. * depends on the video standard */
  182. 0x07, SAA_7114_NTSC_HSYNC_STOP, /* 07 - HSS: hsync stop, depends
  183. *on the video standard */
  184. 0x08, 0xb8, /* 08 - AUFD=1, FSEL=1, EXFIL=0, VTRC=1,
  185. * HPLL: free running in playback, locked
  186. * in capture, VNOI=0 */
  187. 0x09, 0x80, /* 09 - BYPS=0, PREF=0, BPSS=0, VBLB=0,
  188. * UPTCV=0, APER=1; depends from input */
  189. 0x0a, 0x80, /* 0a - BRIG=128 */
  190. 0x0b, 0x44, /* 0b - CONT=1.109 */
  191. 0x0c, 0x40, /* 0c - SATN=1.0 */
  192. 0x0d, 0x00, /* 0d - HUE=0 */
  193. 0x0e, 0x84, /* 0e - CDTO, CSTD2 to 0, DCVF, FCTC,
  194. * CCOMB; depends from video standard */
  195. 0x0f, 0x24, /* 0f - ACGC,CGAIN6 to CGAIN0; depends
  196. * from video standard */
  197. 0x10, 0x03, /* 10 - OFFU1 to 0, OFFV1 to 0, CHBW,
  198. * LCBW2 to 0 */
  199. 0x11, 0x59, /* 11 - COLO, RTP1, HEDL1 to 0, RTP0,
  200. * YDEL2 to 0 */
  201. 0x12, 0xc9, /* 12 - RT signal control RTSE13 to 10
  202. * and 03 to 00 */
  203. 0x13, 0x80, /* 13 - RT/X port output control */
  204. 0x14, 0x00, /* 14 - analog, ADC, compatibility control */
  205. 0x15, 0x00, /* 15 - VGATE start FID change */
  206. 0x16, 0xfe, /* 16 - VGATE stop */
  207. 0x17, 0x00, /* 17 - Misc., VGATE MSBs */
  208. 0x18, 0x40, /* RAWG */
  209. 0x19, 0x80, /* RAWO */
  210. 0x1a, 0x00,
  211. 0x1b, 0x00,
  212. 0x1c, 0x00,
  213. 0x1d, 0x00,
  214. 0x1e, 0x00,
  215. 0x1f, 0x00, /* status byte, read only */
  216. 0x20, 0x00, /* video decoder reserved part */
  217. 0x21, 0x00,
  218. 0x22, 0x00,
  219. 0x23, 0x00,
  220. 0x24, 0x00,
  221. 0x25, 0x00,
  222. 0x26, 0x00,
  223. 0x27, 0x00,
  224. 0x28, 0x00,
  225. 0x29, 0x00,
  226. 0x2a, 0x00,
  227. 0x2b, 0x00,
  228. 0x2c, 0x00,
  229. 0x2d, 0x00,
  230. 0x2e, 0x00,
  231. 0x2f, 0x00,
  232. 0x30, 0xbc, /* audio clock generator */
  233. 0x31, 0xdf,
  234. 0x32, 0x02,
  235. 0x33, 0x00,
  236. 0x34, 0xcd,
  237. 0x35, 0xcc,
  238. 0x36, 0x3a,
  239. 0x37, 0x00,
  240. 0x38, 0x03,
  241. 0x39, 0x10,
  242. 0x3a, 0x00,
  243. 0x3b, 0x00,
  244. 0x3c, 0x00,
  245. 0x3d, 0x00,
  246. 0x3e, 0x00,
  247. 0x3f, 0x00,
  248. 0x40, 0x00, /* VBI data slicer */
  249. 0x41, 0xff,
  250. 0x42, 0xff,
  251. 0x43, 0xff,
  252. 0x44, 0xff,
  253. 0x45, 0xff,
  254. 0x46, 0xff,
  255. 0x47, 0xff,
  256. 0x48, 0xff,
  257. 0x49, 0xff,
  258. 0x4a, 0xff,
  259. 0x4b, 0xff,
  260. 0x4c, 0xff,
  261. 0x4d, 0xff,
  262. 0x4e, 0xff,
  263. 0x4f, 0xff,
  264. 0x50, 0xff,
  265. 0x51, 0xff,
  266. 0x52, 0xff,
  267. 0x53, 0xff,
  268. 0x54, 0xff,
  269. 0x55, 0xff,
  270. 0x56, 0xff,
  271. 0x57, 0xff,
  272. 0x58, 0x40, // framing code
  273. 0x59, 0x47, // horizontal offset
  274. 0x5a, 0x06, // vertical offset
  275. 0x5b, 0x83, // field offset
  276. 0x5c, 0x00, // reserved
  277. 0x5d, 0x3e, // header and data
  278. 0x5e, 0x00, // sliced data
  279. 0x5f, 0x00, // reserved
  280. 0x60, 0x00, /* video decoder reserved part */
  281. 0x61, 0x00,
  282. 0x62, 0x00,
  283. 0x63, 0x00,
  284. 0x64, 0x00,
  285. 0x65, 0x00,
  286. 0x66, 0x00,
  287. 0x67, 0x00,
  288. 0x68, 0x00,
  289. 0x69, 0x00,
  290. 0x6a, 0x00,
  291. 0x6b, 0x00,
  292. 0x6c, 0x00,
  293. 0x6d, 0x00,
  294. 0x6e, 0x00,
  295. 0x6f, 0x00,
  296. 0x70, 0x00, /* video decoder reserved part */
  297. 0x71, 0x00,
  298. 0x72, 0x00,
  299. 0x73, 0x00,
  300. 0x74, 0x00,
  301. 0x75, 0x00,
  302. 0x76, 0x00,
  303. 0x77, 0x00,
  304. 0x78, 0x00,
  305. 0x79, 0x00,
  306. 0x7a, 0x00,
  307. 0x7b, 0x00,
  308. 0x7c, 0x00,
  309. 0x7d, 0x00,
  310. 0x7e, 0x00,
  311. 0x7f, 0x00,
  312. 0x80, 0x00, /* X-port, I-port and scaler */
  313. 0x81, 0x00,
  314. 0x82, 0x00,
  315. 0x83, 0x00,
  316. 0x84, 0xc5,
  317. 0x85, 0x0d, // hsync and vsync ?
  318. 0x86, 0x40,
  319. 0x87, 0x01,
  320. 0x88, 0x00,
  321. 0x89, 0x00,
  322. 0x8a, 0x00,
  323. 0x8b, 0x00,
  324. 0x8c, 0x00,
  325. 0x8d, 0x00,
  326. 0x8e, 0x00,
  327. 0x8f, 0x00,
  328. 0x90, 0x03, /* Task A definition */
  329. 0x91, 0x08,
  330. 0x92, 0x00,
  331. 0x93, 0x40,
  332. 0x94, 0x00, // window settings
  333. 0x95, 0x00,
  334. 0x96, 0x00,
  335. 0x97, 0x00,
  336. 0x98, 0x00,
  337. 0x99, 0x00,
  338. 0x9a, 0x00,
  339. 0x9b, 0x00,
  340. 0x9c, 0x00,
  341. 0x9d, 0x00,
  342. 0x9e, 0x00,
  343. 0x9f, 0x00,
  344. 0xa0, 0x01, /* horizontal integer prescaling ratio */
  345. 0xa1, 0x00, /* horizontal prescaler accumulation
  346. * sequence length */
  347. 0xa2, 0x00, /* UV FIR filter, Y FIR filter, prescaler
  348. * DC gain */
  349. 0xa3, 0x00,
  350. 0xa4, 0x80, // luminance brightness
  351. 0xa5, 0x40, // luminance gain
  352. 0xa6, 0x40, // chrominance saturation
  353. 0xa7, 0x00,
  354. 0xa8, 0x00, // horizontal luminance scaling increment
  355. 0xa9, 0x04,
  356. 0xaa, 0x00, // horizontal luminance phase offset
  357. 0xab, 0x00,
  358. 0xac, 0x00, // horizontal chrominance scaling increment
  359. 0xad, 0x02,
  360. 0xae, 0x00, // horizontal chrominance phase offset
  361. 0xaf, 0x00,
  362. 0xb0, 0x00, // vertical luminance scaling increment
  363. 0xb1, 0x04,
  364. 0xb2, 0x00, // vertical chrominance scaling increment
  365. 0xb3, 0x04,
  366. 0xb4, 0x00,
  367. 0xb5, 0x00,
  368. 0xb6, 0x00,
  369. 0xb7, 0x00,
  370. 0xb8, 0x00,
  371. 0xb9, 0x00,
  372. 0xba, 0x00,
  373. 0xbb, 0x00,
  374. 0xbc, 0x00,
  375. 0xbd, 0x00,
  376. 0xbe, 0x00,
  377. 0xbf, 0x00,
  378. 0xc0, 0x02, // Task B definition
  379. 0xc1, 0x08,
  380. 0xc2, 0x00,
  381. 0xc3, 0x40,
  382. 0xc4, 0x00, // window settings
  383. 0xc5, 0x00,
  384. 0xc6, 0x00,
  385. 0xc7, 0x00,
  386. 0xc8, 0x00,
  387. 0xc9, 0x00,
  388. 0xca, 0x00,
  389. 0xcb, 0x00,
  390. 0xcc, 0x00,
  391. 0xcd, 0x00,
  392. 0xce, 0x00,
  393. 0xcf, 0x00,
  394. 0xd0, 0x01, // horizontal integer prescaling ratio
  395. 0xd1, 0x00, // horizontal prescaler accumulation sequence length
  396. 0xd2, 0x00, // UV FIR filter, Y FIR filter, prescaler DC gain
  397. 0xd3, 0x00,
  398. 0xd4, 0x80, // luminance brightness
  399. 0xd5, 0x40, // luminance gain
  400. 0xd6, 0x40, // chrominance saturation
  401. 0xd7, 0x00,
  402. 0xd8, 0x00, // horizontal luminance scaling increment
  403. 0xd9, 0x04,
  404. 0xda, 0x00, // horizontal luminance phase offset
  405. 0xdb, 0x00,
  406. 0xdc, 0x00, // horizontal chrominance scaling increment
  407. 0xdd, 0x02,
  408. 0xde, 0x00, // horizontal chrominance phase offset
  409. 0xdf, 0x00,
  410. 0xe0, 0x00, // vertical luminance scaling increment
  411. 0xe1, 0x04,
  412. 0xe2, 0x00, // vertical chrominance scaling increment
  413. 0xe3, 0x04,
  414. 0xe4, 0x00,
  415. 0xe5, 0x00,
  416. 0xe6, 0x00,
  417. 0xe7, 0x00,
  418. 0xe8, 0x00,
  419. 0xe9, 0x00,
  420. 0xea, 0x00,
  421. 0xeb, 0x00,
  422. 0xec, 0x00,
  423. 0xed, 0x00,
  424. 0xee, 0x00,
  425. 0xef, 0x00
  426. };
  427. static int
  428. saa7114_command (struct i2c_client *client,
  429. unsigned int cmd,
  430. void *arg)
  431. {
  432. struct saa7114 *decoder = i2c_get_clientdata(client);
  433. switch (cmd) {
  434. case 0:
  435. //dprintk(1, KERN_INFO "%s: writing init\n", I2C_NAME(client));
  436. //saa7114_write_block(client, init, sizeof(init));
  437. break;
  438. case DECODER_DUMP:
  439. {
  440. int i;
  441. dprintk(1, KERN_INFO "%s: decoder dump\n", I2C_NAME(client));
  442. for (i = 0; i < 32; i += 16) {
  443. int j;
  444. printk(KERN_DEBUG "%s: %03x", I2C_NAME(client), i);
  445. for (j = 0; j < 16; ++j) {
  446. printk(" %02x",
  447. saa7114_read(client, i + j));
  448. }
  449. printk("\n");
  450. }
  451. }
  452. break;
  453. case DECODER_GET_CAPABILITIES:
  454. {
  455. struct video_decoder_capability *cap = arg;
  456. dprintk(1, KERN_DEBUG "%s: decoder get capabilities\n",
  457. I2C_NAME(client));
  458. cap->flags = VIDEO_DECODER_PAL |
  459. VIDEO_DECODER_NTSC |
  460. VIDEO_DECODER_AUTO |
  461. VIDEO_DECODER_CCIR;
  462. cap->inputs = 8;
  463. cap->outputs = 1;
  464. }
  465. break;
  466. case DECODER_GET_STATUS:
  467. {
  468. int *iarg = arg;
  469. int status;
  470. int res;
  471. status = saa7114_read(client, 0x1f);
  472. dprintk(1, KERN_DEBUG "%s status: 0x%02x\n", I2C_NAME(client),
  473. status);
  474. res = 0;
  475. if ((status & (1 << 6)) == 0) {
  476. res |= DECODER_STATUS_GOOD;
  477. }
  478. switch (decoder->norm) {
  479. case VIDEO_MODE_NTSC:
  480. res |= DECODER_STATUS_NTSC;
  481. break;
  482. case VIDEO_MODE_PAL:
  483. res |= DECODER_STATUS_PAL;
  484. break;
  485. case VIDEO_MODE_SECAM:
  486. res |= DECODER_STATUS_SECAM;
  487. break;
  488. default:
  489. case VIDEO_MODE_AUTO:
  490. if ((status & (1 << 5)) != 0) {
  491. res |= DECODER_STATUS_NTSC;
  492. } else {
  493. res |= DECODER_STATUS_PAL;
  494. }
  495. break;
  496. }
  497. if ((status & (1 << 0)) != 0) {
  498. res |= DECODER_STATUS_COLOR;
  499. }
  500. *iarg = res;
  501. }
  502. break;
  503. case DECODER_SET_NORM:
  504. {
  505. int *iarg = arg;
  506. short int hoff = 0, voff = 0, w = 0, h = 0;
  507. dprintk(1, KERN_DEBUG "%s: decoder set norm ",
  508. I2C_NAME(client));
  509. switch (*iarg) {
  510. case VIDEO_MODE_NTSC:
  511. dprintk(1, "NTSC\n");
  512. decoder->reg[REG_ADDR(0x06)] =
  513. SAA_7114_NTSC_HSYNC_START;
  514. decoder->reg[REG_ADDR(0x07)] =
  515. SAA_7114_NTSC_HSYNC_STOP;
  516. decoder->reg[REG_ADDR(0x08)] = decoder->playback ? 0x7c : 0xb8; // PLL free when playback, PLL close when capture
  517. decoder->reg[REG_ADDR(0x0e)] = 0x85;
  518. decoder->reg[REG_ADDR(0x0f)] = 0x24;
  519. hoff = SAA_7114_NTSC_HOFFSET;
  520. voff = SAA_7114_NTSC_VOFFSET;
  521. w = SAA_7114_NTSC_WIDTH;
  522. h = SAA_7114_NTSC_HEIGHT;
  523. break;
  524. case VIDEO_MODE_PAL:
  525. dprintk(1, "PAL\n");
  526. decoder->reg[REG_ADDR(0x06)] =
  527. SAA_7114_PAL_HSYNC_START;
  528. decoder->reg[REG_ADDR(0x07)] =
  529. SAA_7114_PAL_HSYNC_STOP;
  530. decoder->reg[REG_ADDR(0x08)] = decoder->playback ? 0x7c : 0xb8; // PLL free when playback, PLL close when capture
  531. decoder->reg[REG_ADDR(0x0e)] = 0x81;
  532. decoder->reg[REG_ADDR(0x0f)] = 0x24;
  533. hoff = SAA_7114_PAL_HOFFSET;
  534. voff = SAA_7114_PAL_VOFFSET;
  535. w = SAA_7114_PAL_WIDTH;
  536. h = SAA_7114_PAL_HEIGHT;
  537. break;
  538. default:
  539. dprintk(1, " Unknown video mode!!!\n");
  540. return -EINVAL;
  541. }
  542. decoder->reg[REG_ADDR(0x94)] = LOBYTE(hoff); // hoffset low
  543. decoder->reg[REG_ADDR(0x95)] = HIBYTE(hoff) & 0x0f; // hoffset high
  544. decoder->reg[REG_ADDR(0x96)] = LOBYTE(w); // width low
  545. decoder->reg[REG_ADDR(0x97)] = HIBYTE(w) & 0x0f; // width high
  546. decoder->reg[REG_ADDR(0x98)] = LOBYTE(voff); // voffset low
  547. decoder->reg[REG_ADDR(0x99)] = HIBYTE(voff) & 0x0f; // voffset high
  548. decoder->reg[REG_ADDR(0x9a)] = LOBYTE(h + 2); // height low
  549. decoder->reg[REG_ADDR(0x9b)] = HIBYTE(h + 2) & 0x0f; // height high
  550. decoder->reg[REG_ADDR(0x9c)] = LOBYTE(w); // out width low
  551. decoder->reg[REG_ADDR(0x9d)] = HIBYTE(w) & 0x0f; // out width high
  552. decoder->reg[REG_ADDR(0x9e)] = LOBYTE(h); // out height low
  553. decoder->reg[REG_ADDR(0x9f)] = HIBYTE(h) & 0x0f; // out height high
  554. decoder->reg[REG_ADDR(0xc4)] = LOBYTE(hoff); // hoffset low
  555. decoder->reg[REG_ADDR(0xc5)] = HIBYTE(hoff) & 0x0f; // hoffset high
  556. decoder->reg[REG_ADDR(0xc6)] = LOBYTE(w); // width low
  557. decoder->reg[REG_ADDR(0xc7)] = HIBYTE(w) & 0x0f; // width high
  558. decoder->reg[REG_ADDR(0xc8)] = LOBYTE(voff); // voffset low
  559. decoder->reg[REG_ADDR(0xc9)] = HIBYTE(voff) & 0x0f; // voffset high
  560. decoder->reg[REG_ADDR(0xca)] = LOBYTE(h + 2); // height low
  561. decoder->reg[REG_ADDR(0xcb)] = HIBYTE(h + 2) & 0x0f; // height high
  562. decoder->reg[REG_ADDR(0xcc)] = LOBYTE(w); // out width low
  563. decoder->reg[REG_ADDR(0xcd)] = HIBYTE(w) & 0x0f; // out width high
  564. decoder->reg[REG_ADDR(0xce)] = LOBYTE(h); // out height low
  565. decoder->reg[REG_ADDR(0xcf)] = HIBYTE(h) & 0x0f; // out height high
  566. saa7114_write(client, 0x80, 0x06); // i-port and scaler back end clock selection, task A&B off
  567. saa7114_write(client, 0x88, 0xd8); // sw reset scaler
  568. saa7114_write(client, 0x88, 0xf8); // sw reset scaler release
  569. saa7114_write_block(client, decoder->reg + (0x06 << 1),
  570. 3 << 1);
  571. saa7114_write_block(client, decoder->reg + (0x0e << 1),
  572. 2 << 1);
  573. saa7114_write_block(client, decoder->reg + (0x5a << 1),
  574. 2 << 1);
  575. saa7114_write_block(client, decoder->reg + (0x94 << 1),
  576. (0x9f + 1 - 0x94) << 1);
  577. saa7114_write_block(client, decoder->reg + (0xc4 << 1),
  578. (0xcf + 1 - 0xc4) << 1);
  579. saa7114_write(client, 0x88, 0xd8); // sw reset scaler
  580. saa7114_write(client, 0x88, 0xf8); // sw reset scaler release
  581. saa7114_write(client, 0x80, 0x36); // i-port and scaler back end clock selection
  582. decoder->norm = *iarg;
  583. }
  584. break;
  585. case DECODER_SET_INPUT:
  586. {
  587. int *iarg = arg;
  588. dprintk(1, KERN_DEBUG "%s: decoder set input (%d)\n",
  589. I2C_NAME(client), *iarg);
  590. if (*iarg < 0 || *iarg > 7) {
  591. return -EINVAL;
  592. }
  593. if (decoder->input != *iarg) {
  594. dprintk(1, KERN_DEBUG "%s: now setting %s input\n",
  595. I2C_NAME(client),
  596. *iarg >= 6 ? "S-Video" : "Composite");
  597. decoder->input = *iarg;
  598. /* select mode */
  599. decoder->reg[REG_ADDR(0x02)] =
  600. (decoder->
  601. reg[REG_ADDR(0x02)] & 0xf0) | (decoder->
  602. input <
  603. 6 ? 0x0 : 0x9);
  604. saa7114_write(client, 0x02,
  605. decoder->reg[REG_ADDR(0x02)]);
  606. /* bypass chrominance trap for modes 6..9 */
  607. decoder->reg[REG_ADDR(0x09)] =
  608. (decoder->
  609. reg[REG_ADDR(0x09)] & 0x7f) | (decoder->
  610. input <
  611. 6 ? 0x0 :
  612. 0x80);
  613. saa7114_write(client, 0x09,
  614. decoder->reg[REG_ADDR(0x09)]);
  615. decoder->reg[REG_ADDR(0x0e)] =
  616. decoder->input <
  617. 6 ? decoder->
  618. reg[REG_ADDR(0x0e)] | 1 : decoder->
  619. reg[REG_ADDR(0x0e)] & ~1;
  620. saa7114_write(client, 0x0e,
  621. decoder->reg[REG_ADDR(0x0e)]);
  622. }
  623. }
  624. break;
  625. case DECODER_SET_OUTPUT:
  626. {
  627. int *iarg = arg;
  628. dprintk(1, KERN_DEBUG "%s: decoder set output\n",
  629. I2C_NAME(client));
  630. /* not much choice of outputs */
  631. if (*iarg != 0) {
  632. return -EINVAL;
  633. }
  634. }
  635. break;
  636. case DECODER_ENABLE_OUTPUT:
  637. {
  638. int *iarg = arg;
  639. int enable = (*iarg != 0);
  640. dprintk(1, KERN_DEBUG "%s: decoder %s output\n",
  641. I2C_NAME(client), enable ? "enable" : "disable");
  642. decoder->playback = !enable;
  643. if (decoder->enable != enable) {
  644. decoder->enable = enable;
  645. /* RJ: If output should be disabled (for
  646. * playing videos), we also need a open PLL.
  647. * The input is set to 0 (where no input
  648. * source is connected), although this
  649. * is not necessary.
  650. *
  651. * If output should be enabled, we have to
  652. * reverse the above.
  653. */
  654. if (decoder->enable) {
  655. decoder->reg[REG_ADDR(0x08)] = 0xb8;
  656. decoder->reg[REG_ADDR(0x12)] = 0xc9;
  657. decoder->reg[REG_ADDR(0x13)] = 0x80;
  658. decoder->reg[REG_ADDR(0x87)] = 0x01;
  659. } else {
  660. decoder->reg[REG_ADDR(0x08)] = 0x7c;
  661. decoder->reg[REG_ADDR(0x12)] = 0x00;
  662. decoder->reg[REG_ADDR(0x13)] = 0x00;
  663. decoder->reg[REG_ADDR(0x87)] = 0x00;
  664. }
  665. saa7114_write_block(client,
  666. decoder->reg + (0x12 << 1),
  667. 2 << 1);
  668. saa7114_write(client, 0x08,
  669. decoder->reg[REG_ADDR(0x08)]);
  670. saa7114_write(client, 0x87,
  671. decoder->reg[REG_ADDR(0x87)]);
  672. saa7114_write(client, 0x88, 0xd8); // sw reset scaler
  673. saa7114_write(client, 0x88, 0xf8); // sw reset scaler release
  674. saa7114_write(client, 0x80, 0x36);
  675. }
  676. }
  677. break;
  678. case DECODER_SET_PICTURE:
  679. {
  680. struct video_picture *pic = arg;
  681. dprintk(1,
  682. KERN_DEBUG
  683. "%s: decoder set picture bright=%d contrast=%d saturation=%d hue=%d\n",
  684. I2C_NAME(client), pic->brightness, pic->contrast,
  685. pic->colour, pic->hue);
  686. if (decoder->bright != pic->brightness) {
  687. /* We want 0 to 255 we get 0-65535 */
  688. decoder->bright = pic->brightness;
  689. saa7114_write(client, 0x0a, decoder->bright >> 8);
  690. }
  691. if (decoder->contrast != pic->contrast) {
  692. /* We want 0 to 127 we get 0-65535 */
  693. decoder->contrast = pic->contrast;
  694. saa7114_write(client, 0x0b,
  695. decoder->contrast >> 9);
  696. }
  697. if (decoder->sat != pic->colour) {
  698. /* We want 0 to 127 we get 0-65535 */
  699. decoder->sat = pic->colour;
  700. saa7114_write(client, 0x0c, decoder->sat >> 9);
  701. }
  702. if (decoder->hue != pic->hue) {
  703. /* We want -128 to 127 we get 0-65535 */
  704. decoder->hue = pic->hue;
  705. saa7114_write(client, 0x0d,
  706. (decoder->hue - 32768) >> 8);
  707. }
  708. }
  709. break;
  710. default:
  711. return -EINVAL;
  712. }
  713. return 0;
  714. }
  715. /* ----------------------------------------------------------------------- */
  716. /*
  717. * Generic i2c probe
  718. * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1'
  719. */
  720. static unsigned short normal_i2c[] =
  721. { I2C_SAA7114 >> 1, I2C_SAA7114A >> 1, I2C_CLIENT_END };
  722. static unsigned short ignore = I2C_CLIENT_END;
  723. static struct i2c_client_address_data addr_data = {
  724. .normal_i2c = normal_i2c,
  725. .probe = &ignore,
  726. .ignore = &ignore,
  727. };
  728. static struct i2c_driver i2c_driver_saa7114;
  729. static int
  730. saa7114_detect_client (struct i2c_adapter *adapter,
  731. int address,
  732. int kind)
  733. {
  734. int i, err[30];
  735. short int hoff = SAA_7114_NTSC_HOFFSET;
  736. short int voff = SAA_7114_NTSC_VOFFSET;
  737. short int w = SAA_7114_NTSC_WIDTH;
  738. short int h = SAA_7114_NTSC_HEIGHT;
  739. struct i2c_client *client;
  740. struct saa7114 *decoder;
  741. dprintk(1,
  742. KERN_INFO
  743. "saa7114.c: detecting saa7114 client on address 0x%x\n",
  744. address << 1);
  745. /* Check if the adapter supports the needed features */
  746. if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
  747. return 0;
  748. client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
  749. if (client == 0)
  750. return -ENOMEM;
  751. memset(client, 0, sizeof(struct i2c_client));
  752. client->addr = address;
  753. client->adapter = adapter;
  754. client->driver = &i2c_driver_saa7114;
  755. client->flags = I2C_CLIENT_ALLOW_USE;
  756. strlcpy(I2C_NAME(client), "saa7114", sizeof(I2C_NAME(client)));
  757. decoder = kmalloc(sizeof(struct saa7114), GFP_KERNEL);
  758. if (decoder == NULL) {
  759. kfree(client);
  760. return -ENOMEM;
  761. }
  762. memset(decoder, 0, sizeof(struct saa7114));
  763. decoder->norm = VIDEO_MODE_NTSC;
  764. decoder->input = -1;
  765. decoder->enable = 1;
  766. decoder->bright = 32768;
  767. decoder->contrast = 32768;
  768. decoder->hue = 32768;
  769. decoder->sat = 32768;
  770. decoder->playback = 0; // initially capture mode useda
  771. i2c_set_clientdata(client, decoder);
  772. memcpy(decoder->reg, init, sizeof(init));
  773. decoder->reg[REG_ADDR(0x94)] = LOBYTE(hoff); // hoffset low
  774. decoder->reg[REG_ADDR(0x95)] = HIBYTE(hoff) & 0x0f; // hoffset high
  775. decoder->reg[REG_ADDR(0x96)] = LOBYTE(w); // width low
  776. decoder->reg[REG_ADDR(0x97)] = HIBYTE(w) & 0x0f; // width high
  777. decoder->reg[REG_ADDR(0x98)] = LOBYTE(voff); // voffset low
  778. decoder->reg[REG_ADDR(0x99)] = HIBYTE(voff) & 0x0f; // voffset high
  779. decoder->reg[REG_ADDR(0x9a)] = LOBYTE(h + 2); // height low
  780. decoder->reg[REG_ADDR(0x9b)] = HIBYTE(h + 2) & 0x0f; // height high
  781. decoder->reg[REG_ADDR(0x9c)] = LOBYTE(w); // out width low
  782. decoder->reg[REG_ADDR(0x9d)] = HIBYTE(w) & 0x0f; // out width high
  783. decoder->reg[REG_ADDR(0x9e)] = LOBYTE(h); // out height low
  784. decoder->reg[REG_ADDR(0x9f)] = HIBYTE(h) & 0x0f; // out height high
  785. decoder->reg[REG_ADDR(0xc4)] = LOBYTE(hoff); // hoffset low
  786. decoder->reg[REG_ADDR(0xc5)] = HIBYTE(hoff) & 0x0f; // hoffset high
  787. decoder->reg[REG_ADDR(0xc6)] = LOBYTE(w); // width low
  788. decoder->reg[REG_ADDR(0xc7)] = HIBYTE(w) & 0x0f; // width high
  789. decoder->reg[REG_ADDR(0xc8)] = LOBYTE(voff); // voffset low
  790. decoder->reg[REG_ADDR(0xc9)] = HIBYTE(voff) & 0x0f; // voffset high
  791. decoder->reg[REG_ADDR(0xca)] = LOBYTE(h + 2); // height low
  792. decoder->reg[REG_ADDR(0xcb)] = HIBYTE(h + 2) & 0x0f; // height high
  793. decoder->reg[REG_ADDR(0xcc)] = LOBYTE(w); // out width low
  794. decoder->reg[REG_ADDR(0xcd)] = HIBYTE(w) & 0x0f; // out width high
  795. decoder->reg[REG_ADDR(0xce)] = LOBYTE(h); // out height low
  796. decoder->reg[REG_ADDR(0xcf)] = HIBYTE(h) & 0x0f; // out height high
  797. decoder->reg[REG_ADDR(0xb8)] =
  798. LOBYTE(LOWORD(SAA_7114_VERTICAL_CHROMA_OFFSET));
  799. decoder->reg[REG_ADDR(0xb9)] =
  800. HIBYTE(LOWORD(SAA_7114_VERTICAL_CHROMA_OFFSET));
  801. decoder->reg[REG_ADDR(0xba)] =
  802. LOBYTE(HIWORD(SAA_7114_VERTICAL_CHROMA_OFFSET));
  803. decoder->reg[REG_ADDR(0xbb)] =
  804. HIBYTE(HIWORD(SAA_7114_VERTICAL_CHROMA_OFFSET));
  805. decoder->reg[REG_ADDR(0xbc)] =
  806. LOBYTE(LOWORD(SAA_7114_VERTICAL_LUMA_OFFSET));
  807. decoder->reg[REG_ADDR(0xbd)] =
  808. HIBYTE(LOWORD(SAA_7114_VERTICAL_LUMA_OFFSET));
  809. decoder->reg[REG_ADDR(0xbe)] =
  810. LOBYTE(HIWORD(SAA_7114_VERTICAL_LUMA_OFFSET));
  811. decoder->reg[REG_ADDR(0xbf)] =
  812. HIBYTE(HIWORD(SAA_7114_VERTICAL_LUMA_OFFSET));
  813. decoder->reg[REG_ADDR(0xe8)] =
  814. LOBYTE(LOWORD(SAA_7114_VERTICAL_CHROMA_OFFSET));
  815. decoder->reg[REG_ADDR(0xe9)] =
  816. HIBYTE(LOWORD(SAA_7114_VERTICAL_CHROMA_OFFSET));
  817. decoder->reg[REG_ADDR(0xea)] =
  818. LOBYTE(HIWORD(SAA_7114_VERTICAL_CHROMA_OFFSET));
  819. decoder->reg[REG_ADDR(0xeb)] =
  820. HIBYTE(HIWORD(SAA_7114_VERTICAL_CHROMA_OFFSET));
  821. decoder->reg[REG_ADDR(0xec)] =
  822. LOBYTE(LOWORD(SAA_7114_VERTICAL_LUMA_OFFSET));
  823. decoder->reg[REG_ADDR(0xed)] =
  824. HIBYTE(LOWORD(SAA_7114_VERTICAL_LUMA_OFFSET));
  825. decoder->reg[REG_ADDR(0xee)] =
  826. LOBYTE(HIWORD(SAA_7114_VERTICAL_LUMA_OFFSET));
  827. decoder->reg[REG_ADDR(0xef)] =
  828. HIBYTE(HIWORD(SAA_7114_VERTICAL_LUMA_OFFSET));
  829. decoder->reg[REG_ADDR(0x13)] = 0x80; // RTC0 on
  830. decoder->reg[REG_ADDR(0x87)] = 0x01; // I-Port
  831. decoder->reg[REG_ADDR(0x12)] = 0xc9; // RTS0
  832. decoder->reg[REG_ADDR(0x02)] = 0xc0; // set composite1 input, aveasy
  833. decoder->reg[REG_ADDR(0x09)] = 0x00; // chrominance trap
  834. decoder->reg[REG_ADDR(0x0e)] |= 1; // combfilter on
  835. dprintk(1, KERN_DEBUG "%s_attach: starting decoder init\n",
  836. I2C_NAME(client));
  837. err[0] =
  838. saa7114_write_block(client, decoder->reg + (0x20 << 1),
  839. 0x10 << 1);
  840. err[1] =
  841. saa7114_write_block(client, decoder->reg + (0x30 << 1),
  842. 0x10 << 1);
  843. err[2] =
  844. saa7114_write_block(client, decoder->reg + (0x63 << 1),
  845. (0x7f + 1 - 0x63) << 1);
  846. err[3] =
  847. saa7114_write_block(client, decoder->reg + (0x89 << 1),
  848. 6 << 1);
  849. err[4] =
  850. saa7114_write_block(client, decoder->reg + (0xb8 << 1),
  851. 8 << 1);
  852. err[5] =
  853. saa7114_write_block(client, decoder->reg + (0xe8 << 1),
  854. 8 << 1);
  855. for (i = 0; i <= 5; i++) {
  856. if (err[i] < 0) {
  857. dprintk(1,
  858. KERN_ERR
  859. "%s_attach: init error %d at stage %d, leaving attach.\n",
  860. I2C_NAME(client), i, err[i]);
  861. kfree(decoder);
  862. kfree(client);
  863. return 0;
  864. }
  865. }
  866. for (i = 6; i < 8; i++) {
  867. dprintk(1,
  868. KERN_DEBUG
  869. "%s_attach: reg[0x%02x] = 0x%02x (0x%02x)\n",
  870. I2C_NAME(client), i, saa7114_read(client, i),
  871. decoder->reg[REG_ADDR(i)]);
  872. }
  873. dprintk(1,
  874. KERN_DEBUG
  875. "%s_attach: performing decoder reset sequence\n",
  876. I2C_NAME(client));
  877. err[6] = saa7114_write(client, 0x80, 0x06); // i-port and scaler backend clock selection, task A&B off
  878. err[7] = saa7114_write(client, 0x88, 0xd8); // sw reset scaler
  879. err[8] = saa7114_write(client, 0x88, 0xf8); // sw reset scaler release
  880. for (i = 6; i <= 8; i++) {
  881. if (err[i] < 0) {
  882. dprintk(1,
  883. KERN_ERR
  884. "%s_attach: init error %d at stage %d, leaving attach.\n",
  885. I2C_NAME(client), i, err[i]);
  886. kfree(decoder);
  887. kfree(client);
  888. return 0;
  889. }
  890. }
  891. dprintk(1, KERN_INFO "%s_attach: performing the rest of init\n",
  892. I2C_NAME(client));
  893. err[9] = saa7114_write(client, 0x01, decoder->reg[REG_ADDR(0x01)]);
  894. err[10] = saa7114_write_block(client, decoder->reg + (0x03 << 1), (0x1e + 1 - 0x03) << 1); // big seq
  895. err[11] = saa7114_write_block(client, decoder->reg + (0x40 << 1), (0x5f + 1 - 0x40) << 1); // slicer
  896. err[12] = saa7114_write_block(client, decoder->reg + (0x81 << 1), 2 << 1); // ?
  897. err[13] = saa7114_write_block(client, decoder->reg + (0x83 << 1), 5 << 1); // ?
  898. err[14] = saa7114_write_block(client, decoder->reg + (0x90 << 1), 4 << 1); // Task A
  899. err[15] =
  900. saa7114_write_block(client, decoder->reg + (0x94 << 1),
  901. 12 << 1);
  902. err[16] =
  903. saa7114_write_block(client, decoder->reg + (0xa0 << 1),
  904. 8 << 1);
  905. err[17] =
  906. saa7114_write_block(client, decoder->reg + (0xa8 << 1),
  907. 8 << 1);
  908. err[18] =
  909. saa7114_write_block(client, decoder->reg + (0xb0 << 1),
  910. 8 << 1);
  911. err[19] = saa7114_write_block(client, decoder->reg + (0xc0 << 1), 4 << 1); // Task B
  912. err[15] =
  913. saa7114_write_block(client, decoder->reg + (0xc4 << 1),
  914. 12 << 1);
  915. err[16] =
  916. saa7114_write_block(client, decoder->reg + (0xd0 << 1),
  917. 8 << 1);
  918. err[17] =
  919. saa7114_write_block(client, decoder->reg + (0xd8 << 1),
  920. 8 << 1);
  921. err[18] =
  922. saa7114_write_block(client, decoder->reg + (0xe0 << 1),
  923. 8 << 1);
  924. for (i = 9; i <= 18; i++) {
  925. if (err[i] < 0) {
  926. dprintk(1,
  927. KERN_ERR
  928. "%s_attach: init error %d at stage %d, leaving attach.\n",
  929. I2C_NAME(client), i, err[i]);
  930. kfree(decoder);
  931. kfree(client);
  932. return 0;
  933. }
  934. }
  935. for (i = 6; i < 8; i++) {
  936. dprintk(1,
  937. KERN_DEBUG
  938. "%s_attach: reg[0x%02x] = 0x%02x (0x%02x)\n",
  939. I2C_NAME(client), i, saa7114_read(client, i),
  940. decoder->reg[REG_ADDR(i)]);
  941. }
  942. for (i = 0x11; i <= 0x13; i++) {
  943. dprintk(1,
  944. KERN_DEBUG
  945. "%s_attach: reg[0x%02x] = 0x%02x (0x%02x)\n",
  946. I2C_NAME(client), i, saa7114_read(client, i),
  947. decoder->reg[REG_ADDR(i)]);
  948. }
  949. dprintk(1, KERN_DEBUG "%s_attach: setting video input\n",
  950. I2C_NAME(client));
  951. err[19] =
  952. saa7114_write(client, 0x02, decoder->reg[REG_ADDR(0x02)]);
  953. err[20] =
  954. saa7114_write(client, 0x09, decoder->reg[REG_ADDR(0x09)]);
  955. err[21] =
  956. saa7114_write(client, 0x0e, decoder->reg[REG_ADDR(0x0e)]);
  957. for (i = 19; i <= 21; i++) {
  958. if (err[i] < 0) {
  959. dprintk(1,
  960. KERN_ERR
  961. "%s_attach: init error %d at stage %d, leaving attach.\n",
  962. I2C_NAME(client), i, err[i]);
  963. kfree(decoder);
  964. kfree(client);
  965. return 0;
  966. }
  967. }
  968. dprintk(1,
  969. KERN_DEBUG
  970. "%s_attach: performing decoder reset sequence\n",
  971. I2C_NAME(client));
  972. err[22] = saa7114_write(client, 0x88, 0xd8); // sw reset scaler
  973. err[23] = saa7114_write(client, 0x88, 0xf8); // sw reset scaler release
  974. err[24] = saa7114_write(client, 0x80, 0x36); // i-port and scaler backend clock selection, task A&B off
  975. for (i = 22; i <= 24; i++) {
  976. if (err[i] < 0) {
  977. dprintk(1,
  978. KERN_ERR
  979. "%s_attach: init error %d at stage %d, leaving attach.\n",
  980. I2C_NAME(client), i, err[i]);
  981. kfree(decoder);
  982. kfree(client);
  983. return 0;
  984. }
  985. }
  986. err[25] = saa7114_write(client, 0x06, init[REG_ADDR(0x06)]);
  987. err[26] = saa7114_write(client, 0x07, init[REG_ADDR(0x07)]);
  988. err[27] = saa7114_write(client, 0x10, init[REG_ADDR(0x10)]);
  989. dprintk(1,
  990. KERN_INFO
  991. "%s_attach: chip version %x, decoder status 0x%02x\n",
  992. I2C_NAME(client), saa7114_read(client, 0x00) >> 4,
  993. saa7114_read(client, 0x1f));
  994. dprintk(1,
  995. KERN_DEBUG
  996. "%s_attach: power save control: 0x%02x, scaler status: 0x%02x\n",
  997. I2C_NAME(client), saa7114_read(client, 0x88),
  998. saa7114_read(client, 0x8f));
  999. for (i = 0x94; i < 0x96; i++) {
  1000. dprintk(1,
  1001. KERN_DEBUG
  1002. "%s_attach: reg[0x%02x] = 0x%02x (0x%02x)\n",
  1003. I2C_NAME(client), i, saa7114_read(client, i),
  1004. decoder->reg[REG_ADDR(i)]);
  1005. }
  1006. i = i2c_attach_client(client);
  1007. if (i) {
  1008. kfree(client);
  1009. kfree(decoder);
  1010. return i;
  1011. }
  1012. //i = saa7114_write_block(client, init, sizeof(init));
  1013. i = 0;
  1014. if (i < 0) {
  1015. dprintk(1, KERN_ERR "%s_attach error: init status %d\n",
  1016. I2C_NAME(client), i);
  1017. } else {
  1018. dprintk(1,
  1019. KERN_INFO
  1020. "%s_attach: chip version %x at address 0x%x\n",
  1021. I2C_NAME(client), saa7114_read(client, 0x00) >> 4,
  1022. client->addr << 1);
  1023. }
  1024. return 0;
  1025. }
  1026. static int
  1027. saa7114_attach_adapter (struct i2c_adapter *adapter)
  1028. {
  1029. dprintk(1,
  1030. KERN_INFO
  1031. "saa7114.c: starting probe for adapter %s (0x%x)\n",
  1032. I2C_NAME(adapter), adapter->id);
  1033. return i2c_probe(adapter, &addr_data, &saa7114_detect_client);
  1034. }
  1035. static int
  1036. saa7114_detach_client (struct i2c_client *client)
  1037. {
  1038. struct saa7114 *decoder = i2c_get_clientdata(client);
  1039. int err;
  1040. err = i2c_detach_client(client);
  1041. if (err) {
  1042. return err;
  1043. }
  1044. kfree(decoder);
  1045. kfree(client);
  1046. return 0;
  1047. }
  1048. /* ----------------------------------------------------------------------- */
  1049. static struct i2c_driver i2c_driver_saa7114 = {
  1050. .owner = THIS_MODULE,
  1051. .name = "saa7114",
  1052. .id = I2C_DRIVERID_SAA7114,
  1053. .flags = I2C_DF_NOTIFY,
  1054. .attach_adapter = saa7114_attach_adapter,
  1055. .detach_client = saa7114_detach_client,
  1056. .command = saa7114_command,
  1057. };
  1058. static int __init
  1059. saa7114_init (void)
  1060. {
  1061. return i2c_add_driver(&i2c_driver_saa7114);
  1062. }
  1063. static void __exit
  1064. saa7114_exit (void)
  1065. {
  1066. i2c_del_driver(&i2c_driver_saa7114);
  1067. }
  1068. module_init(saa7114_init);
  1069. module_exit(saa7114_exit);