saa7114.c 32 KB

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