saa7114.c 31 KB

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