saa7114.c 32 KB

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