saa7114.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233
  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. .force = &ignore,
  728. };
  729. static struct i2c_driver i2c_driver_saa7114;
  730. static int
  731. saa7114_detect_client (struct i2c_adapter *adapter,
  732. int address,
  733. int kind)
  734. {
  735. int i, err[30];
  736. short int hoff = SAA_7114_NTSC_HOFFSET;
  737. short int voff = SAA_7114_NTSC_VOFFSET;
  738. short int w = SAA_7114_NTSC_WIDTH;
  739. short int h = SAA_7114_NTSC_HEIGHT;
  740. struct i2c_client *client;
  741. struct saa7114 *decoder;
  742. dprintk(1,
  743. KERN_INFO
  744. "saa7114.c: detecting saa7114 client on address 0x%x\n",
  745. address << 1);
  746. /* Check if the adapter supports the needed features */
  747. if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
  748. return 0;
  749. client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
  750. if (client == 0)
  751. return -ENOMEM;
  752. memset(client, 0, sizeof(struct i2c_client));
  753. client->addr = address;
  754. client->adapter = adapter;
  755. client->driver = &i2c_driver_saa7114;
  756. client->flags = I2C_CLIENT_ALLOW_USE;
  757. strlcpy(I2C_NAME(client), "saa7114", sizeof(I2C_NAME(client)));
  758. decoder = kmalloc(sizeof(struct saa7114), GFP_KERNEL);
  759. if (decoder == NULL) {
  760. kfree(client);
  761. return -ENOMEM;
  762. }
  763. memset(decoder, 0, sizeof(struct saa7114));
  764. decoder->norm = VIDEO_MODE_NTSC;
  765. decoder->input = -1;
  766. decoder->enable = 1;
  767. decoder->bright = 32768;
  768. decoder->contrast = 32768;
  769. decoder->hue = 32768;
  770. decoder->sat = 32768;
  771. decoder->playback = 0; // initially capture mode useda
  772. i2c_set_clientdata(client, decoder);
  773. memcpy(decoder->reg, init, sizeof(init));
  774. decoder->reg[REG_ADDR(0x94)] = LOBYTE(hoff); // hoffset low
  775. decoder->reg[REG_ADDR(0x95)] = HIBYTE(hoff) & 0x0f; // hoffset high
  776. decoder->reg[REG_ADDR(0x96)] = LOBYTE(w); // width low
  777. decoder->reg[REG_ADDR(0x97)] = HIBYTE(w) & 0x0f; // width high
  778. decoder->reg[REG_ADDR(0x98)] = LOBYTE(voff); // voffset low
  779. decoder->reg[REG_ADDR(0x99)] = HIBYTE(voff) & 0x0f; // voffset high
  780. decoder->reg[REG_ADDR(0x9a)] = LOBYTE(h + 2); // height low
  781. decoder->reg[REG_ADDR(0x9b)] = HIBYTE(h + 2) & 0x0f; // height high
  782. decoder->reg[REG_ADDR(0x9c)] = LOBYTE(w); // out width low
  783. decoder->reg[REG_ADDR(0x9d)] = HIBYTE(w) & 0x0f; // out width high
  784. decoder->reg[REG_ADDR(0x9e)] = LOBYTE(h); // out height low
  785. decoder->reg[REG_ADDR(0x9f)] = HIBYTE(h) & 0x0f; // out height high
  786. decoder->reg[REG_ADDR(0xc4)] = LOBYTE(hoff); // hoffset low
  787. decoder->reg[REG_ADDR(0xc5)] = HIBYTE(hoff) & 0x0f; // hoffset high
  788. decoder->reg[REG_ADDR(0xc6)] = LOBYTE(w); // width low
  789. decoder->reg[REG_ADDR(0xc7)] = HIBYTE(w) & 0x0f; // width high
  790. decoder->reg[REG_ADDR(0xc8)] = LOBYTE(voff); // voffset low
  791. decoder->reg[REG_ADDR(0xc9)] = HIBYTE(voff) & 0x0f; // voffset high
  792. decoder->reg[REG_ADDR(0xca)] = LOBYTE(h + 2); // height low
  793. decoder->reg[REG_ADDR(0xcb)] = HIBYTE(h + 2) & 0x0f; // height high
  794. decoder->reg[REG_ADDR(0xcc)] = LOBYTE(w); // out width low
  795. decoder->reg[REG_ADDR(0xcd)] = HIBYTE(w) & 0x0f; // out width high
  796. decoder->reg[REG_ADDR(0xce)] = LOBYTE(h); // out height low
  797. decoder->reg[REG_ADDR(0xcf)] = HIBYTE(h) & 0x0f; // out height high
  798. decoder->reg[REG_ADDR(0xb8)] =
  799. LOBYTE(LOWORD(SAA_7114_VERTICAL_CHROMA_OFFSET));
  800. decoder->reg[REG_ADDR(0xb9)] =
  801. HIBYTE(LOWORD(SAA_7114_VERTICAL_CHROMA_OFFSET));
  802. decoder->reg[REG_ADDR(0xba)] =
  803. LOBYTE(HIWORD(SAA_7114_VERTICAL_CHROMA_OFFSET));
  804. decoder->reg[REG_ADDR(0xbb)] =
  805. HIBYTE(HIWORD(SAA_7114_VERTICAL_CHROMA_OFFSET));
  806. decoder->reg[REG_ADDR(0xbc)] =
  807. LOBYTE(LOWORD(SAA_7114_VERTICAL_LUMA_OFFSET));
  808. decoder->reg[REG_ADDR(0xbd)] =
  809. HIBYTE(LOWORD(SAA_7114_VERTICAL_LUMA_OFFSET));
  810. decoder->reg[REG_ADDR(0xbe)] =
  811. LOBYTE(HIWORD(SAA_7114_VERTICAL_LUMA_OFFSET));
  812. decoder->reg[REG_ADDR(0xbf)] =
  813. HIBYTE(HIWORD(SAA_7114_VERTICAL_LUMA_OFFSET));
  814. decoder->reg[REG_ADDR(0xe8)] =
  815. LOBYTE(LOWORD(SAA_7114_VERTICAL_CHROMA_OFFSET));
  816. decoder->reg[REG_ADDR(0xe9)] =
  817. HIBYTE(LOWORD(SAA_7114_VERTICAL_CHROMA_OFFSET));
  818. decoder->reg[REG_ADDR(0xea)] =
  819. LOBYTE(HIWORD(SAA_7114_VERTICAL_CHROMA_OFFSET));
  820. decoder->reg[REG_ADDR(0xeb)] =
  821. HIBYTE(HIWORD(SAA_7114_VERTICAL_CHROMA_OFFSET));
  822. decoder->reg[REG_ADDR(0xec)] =
  823. LOBYTE(LOWORD(SAA_7114_VERTICAL_LUMA_OFFSET));
  824. decoder->reg[REG_ADDR(0xed)] =
  825. HIBYTE(LOWORD(SAA_7114_VERTICAL_LUMA_OFFSET));
  826. decoder->reg[REG_ADDR(0xee)] =
  827. LOBYTE(HIWORD(SAA_7114_VERTICAL_LUMA_OFFSET));
  828. decoder->reg[REG_ADDR(0xef)] =
  829. HIBYTE(HIWORD(SAA_7114_VERTICAL_LUMA_OFFSET));
  830. decoder->reg[REG_ADDR(0x13)] = 0x80; // RTC0 on
  831. decoder->reg[REG_ADDR(0x87)] = 0x01; // I-Port
  832. decoder->reg[REG_ADDR(0x12)] = 0xc9; // RTS0
  833. decoder->reg[REG_ADDR(0x02)] = 0xc0; // set composite1 input, aveasy
  834. decoder->reg[REG_ADDR(0x09)] = 0x00; // chrominance trap
  835. decoder->reg[REG_ADDR(0x0e)] |= 1; // combfilter on
  836. dprintk(1, KERN_DEBUG "%s_attach: starting decoder init\n",
  837. I2C_NAME(client));
  838. err[0] =
  839. saa7114_write_block(client, decoder->reg + (0x20 << 1),
  840. 0x10 << 1);
  841. err[1] =
  842. saa7114_write_block(client, decoder->reg + (0x30 << 1),
  843. 0x10 << 1);
  844. err[2] =
  845. saa7114_write_block(client, decoder->reg + (0x63 << 1),
  846. (0x7f + 1 - 0x63) << 1);
  847. err[3] =
  848. saa7114_write_block(client, decoder->reg + (0x89 << 1),
  849. 6 << 1);
  850. err[4] =
  851. saa7114_write_block(client, decoder->reg + (0xb8 << 1),
  852. 8 << 1);
  853. err[5] =
  854. saa7114_write_block(client, decoder->reg + (0xe8 << 1),
  855. 8 << 1);
  856. for (i = 0; i <= 5; i++) {
  857. if (err[i] < 0) {
  858. dprintk(1,
  859. KERN_ERR
  860. "%s_attach: init error %d at stage %d, leaving attach.\n",
  861. I2C_NAME(client), i, err[i]);
  862. kfree(decoder);
  863. kfree(client);
  864. return 0;
  865. }
  866. }
  867. for (i = 6; i < 8; i++) {
  868. dprintk(1,
  869. KERN_DEBUG
  870. "%s_attach: reg[0x%02x] = 0x%02x (0x%02x)\n",
  871. I2C_NAME(client), i, saa7114_read(client, i),
  872. decoder->reg[REG_ADDR(i)]);
  873. }
  874. dprintk(1,
  875. KERN_DEBUG
  876. "%s_attach: performing decoder reset sequence\n",
  877. I2C_NAME(client));
  878. err[6] = saa7114_write(client, 0x80, 0x06); // i-port and scaler backend clock selection, task A&B off
  879. err[7] = saa7114_write(client, 0x88, 0xd8); // sw reset scaler
  880. err[8] = saa7114_write(client, 0x88, 0xf8); // sw reset scaler release
  881. for (i = 6; i <= 8; i++) {
  882. if (err[i] < 0) {
  883. dprintk(1,
  884. KERN_ERR
  885. "%s_attach: init error %d at stage %d, leaving attach.\n",
  886. I2C_NAME(client), i, err[i]);
  887. kfree(decoder);
  888. kfree(client);
  889. return 0;
  890. }
  891. }
  892. dprintk(1, KERN_INFO "%s_attach: performing the rest of init\n",
  893. I2C_NAME(client));
  894. err[9] = saa7114_write(client, 0x01, decoder->reg[REG_ADDR(0x01)]);
  895. err[10] = saa7114_write_block(client, decoder->reg + (0x03 << 1), (0x1e + 1 - 0x03) << 1); // big seq
  896. err[11] = saa7114_write_block(client, decoder->reg + (0x40 << 1), (0x5f + 1 - 0x40) << 1); // slicer
  897. err[12] = saa7114_write_block(client, decoder->reg + (0x81 << 1), 2 << 1); // ?
  898. err[13] = saa7114_write_block(client, decoder->reg + (0x83 << 1), 5 << 1); // ?
  899. err[14] = saa7114_write_block(client, decoder->reg + (0x90 << 1), 4 << 1); // Task A
  900. err[15] =
  901. saa7114_write_block(client, decoder->reg + (0x94 << 1),
  902. 12 << 1);
  903. err[16] =
  904. saa7114_write_block(client, decoder->reg + (0xa0 << 1),
  905. 8 << 1);
  906. err[17] =
  907. saa7114_write_block(client, decoder->reg + (0xa8 << 1),
  908. 8 << 1);
  909. err[18] =
  910. saa7114_write_block(client, decoder->reg + (0xb0 << 1),
  911. 8 << 1);
  912. err[19] = saa7114_write_block(client, decoder->reg + (0xc0 << 1), 4 << 1); // Task B
  913. err[15] =
  914. saa7114_write_block(client, decoder->reg + (0xc4 << 1),
  915. 12 << 1);
  916. err[16] =
  917. saa7114_write_block(client, decoder->reg + (0xd0 << 1),
  918. 8 << 1);
  919. err[17] =
  920. saa7114_write_block(client, decoder->reg + (0xd8 << 1),
  921. 8 << 1);
  922. err[18] =
  923. saa7114_write_block(client, decoder->reg + (0xe0 << 1),
  924. 8 << 1);
  925. for (i = 9; i <= 18; i++) {
  926. if (err[i] < 0) {
  927. dprintk(1,
  928. KERN_ERR
  929. "%s_attach: init error %d at stage %d, leaving attach.\n",
  930. I2C_NAME(client), i, err[i]);
  931. kfree(decoder);
  932. kfree(client);
  933. return 0;
  934. }
  935. }
  936. for (i = 6; i < 8; i++) {
  937. dprintk(1,
  938. KERN_DEBUG
  939. "%s_attach: reg[0x%02x] = 0x%02x (0x%02x)\n",
  940. I2C_NAME(client), i, saa7114_read(client, i),
  941. decoder->reg[REG_ADDR(i)]);
  942. }
  943. for (i = 0x11; i <= 0x13; i++) {
  944. dprintk(1,
  945. KERN_DEBUG
  946. "%s_attach: reg[0x%02x] = 0x%02x (0x%02x)\n",
  947. I2C_NAME(client), i, saa7114_read(client, i),
  948. decoder->reg[REG_ADDR(i)]);
  949. }
  950. dprintk(1, KERN_DEBUG "%s_attach: setting video input\n",
  951. I2C_NAME(client));
  952. err[19] =
  953. saa7114_write(client, 0x02, decoder->reg[REG_ADDR(0x02)]);
  954. err[20] =
  955. saa7114_write(client, 0x09, decoder->reg[REG_ADDR(0x09)]);
  956. err[21] =
  957. saa7114_write(client, 0x0e, decoder->reg[REG_ADDR(0x0e)]);
  958. for (i = 19; i <= 21; i++) {
  959. if (err[i] < 0) {
  960. dprintk(1,
  961. KERN_ERR
  962. "%s_attach: init error %d at stage %d, leaving attach.\n",
  963. I2C_NAME(client), i, err[i]);
  964. kfree(decoder);
  965. kfree(client);
  966. return 0;
  967. }
  968. }
  969. dprintk(1,
  970. KERN_DEBUG
  971. "%s_attach: performing decoder reset sequence\n",
  972. I2C_NAME(client));
  973. err[22] = saa7114_write(client, 0x88, 0xd8); // sw reset scaler
  974. err[23] = saa7114_write(client, 0x88, 0xf8); // sw reset scaler release
  975. err[24] = saa7114_write(client, 0x80, 0x36); // i-port and scaler backend clock selection, task A&B off
  976. for (i = 22; i <= 24; i++) {
  977. if (err[i] < 0) {
  978. dprintk(1,
  979. KERN_ERR
  980. "%s_attach: init error %d at stage %d, leaving attach.\n",
  981. I2C_NAME(client), i, err[i]);
  982. kfree(decoder);
  983. kfree(client);
  984. return 0;
  985. }
  986. }
  987. err[25] = saa7114_write(client, 0x06, init[REG_ADDR(0x06)]);
  988. err[26] = saa7114_write(client, 0x07, init[REG_ADDR(0x07)]);
  989. err[27] = saa7114_write(client, 0x10, init[REG_ADDR(0x10)]);
  990. dprintk(1,
  991. KERN_INFO
  992. "%s_attach: chip version %x, decoder status 0x%02x\n",
  993. I2C_NAME(client), saa7114_read(client, 0x00) >> 4,
  994. saa7114_read(client, 0x1f));
  995. dprintk(1,
  996. KERN_DEBUG
  997. "%s_attach: power save control: 0x%02x, scaler status: 0x%02x\n",
  998. I2C_NAME(client), saa7114_read(client, 0x88),
  999. saa7114_read(client, 0x8f));
  1000. for (i = 0x94; i < 0x96; i++) {
  1001. dprintk(1,
  1002. KERN_DEBUG
  1003. "%s_attach: reg[0x%02x] = 0x%02x (0x%02x)\n",
  1004. I2C_NAME(client), i, saa7114_read(client, i),
  1005. decoder->reg[REG_ADDR(i)]);
  1006. }
  1007. i = i2c_attach_client(client);
  1008. if (i) {
  1009. kfree(client);
  1010. kfree(decoder);
  1011. return i;
  1012. }
  1013. //i = saa7114_write_block(client, init, sizeof(init));
  1014. i = 0;
  1015. if (i < 0) {
  1016. dprintk(1, KERN_ERR "%s_attach error: init status %d\n",
  1017. I2C_NAME(client), i);
  1018. } else {
  1019. dprintk(1,
  1020. KERN_INFO
  1021. "%s_attach: chip version %x at address 0x%x\n",
  1022. I2C_NAME(client), saa7114_read(client, 0x00) >> 4,
  1023. client->addr << 1);
  1024. }
  1025. return 0;
  1026. }
  1027. static int
  1028. saa7114_attach_adapter (struct i2c_adapter *adapter)
  1029. {
  1030. dprintk(1,
  1031. KERN_INFO
  1032. "saa7114.c: starting probe for adapter %s (0x%x)\n",
  1033. I2C_NAME(adapter), adapter->id);
  1034. return i2c_probe(adapter, &addr_data, &saa7114_detect_client);
  1035. }
  1036. static int
  1037. saa7114_detach_client (struct i2c_client *client)
  1038. {
  1039. struct saa7114 *decoder = i2c_get_clientdata(client);
  1040. int err;
  1041. err = i2c_detach_client(client);
  1042. if (err) {
  1043. return err;
  1044. }
  1045. kfree(decoder);
  1046. kfree(client);
  1047. return 0;
  1048. }
  1049. /* ----------------------------------------------------------------------- */
  1050. static struct i2c_driver i2c_driver_saa7114 = {
  1051. .owner = THIS_MODULE,
  1052. .name = "saa7114",
  1053. .id = I2C_DRIVERID_SAA7114,
  1054. .flags = I2C_DF_NOTIFY,
  1055. .attach_adapter = saa7114_attach_adapter,
  1056. .detach_client = saa7114_detach_client,
  1057. .command = saa7114_command,
  1058. };
  1059. static int __init
  1060. saa7114_init (void)
  1061. {
  1062. return i2c_add_driver(&i2c_driver_saa7114);
  1063. }
  1064. static void __exit
  1065. saa7114_exit (void)
  1066. {
  1067. i2c_del_driver(&i2c_driver_saa7114);
  1068. }
  1069. module_init(saa7114_init);
  1070. module_exit(saa7114_exit);