matroxfb_maven.c 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301
  1. /*
  2. *
  3. * Hardware accelerated Matrox Millennium I, II, Mystique, G100, G200, G400 and G450.
  4. *
  5. * (c) 1998-2002 Petr Vandrovec <vandrove@vc.cvut.cz>
  6. *
  7. * Portions Copyright (c) 2001 Matrox Graphics Inc.
  8. *
  9. * Version: 1.65 2002/08/14
  10. *
  11. * See matroxfb_base.c for contributors.
  12. *
  13. */
  14. #include "matroxfb_maven.h"
  15. #include "matroxfb_misc.h"
  16. #include "matroxfb_DAC1064.h"
  17. #include <linux/i2c.h>
  18. #include <linux/matroxfb.h>
  19. #include <linux/slab.h>
  20. #include <asm/div64.h>
  21. #define MGATVO_B 1
  22. #define MGATVO_C 2
  23. static const struct maven_gamma {
  24. unsigned char reg83;
  25. unsigned char reg84;
  26. unsigned char reg85;
  27. unsigned char reg86;
  28. unsigned char reg87;
  29. unsigned char reg88;
  30. unsigned char reg89;
  31. unsigned char reg8a;
  32. unsigned char reg8b;
  33. } maven_gamma[] = {
  34. { 131, 57, 223, 15, 117, 212, 251, 91, 156},
  35. { 133, 61, 128, 63, 180, 147, 195, 100, 180},
  36. { 131, 19, 63, 31, 50, 66, 171, 64, 176},
  37. { 0, 0, 0, 31, 16, 16, 16, 100, 200},
  38. { 8, 23, 47, 73, 147, 244, 220, 80, 195},
  39. { 22, 43, 64, 80, 147, 115, 58, 85, 168},
  40. { 34, 60, 80, 214, 147, 212, 188, 85, 167},
  41. { 45, 77, 96, 216, 147, 99, 91, 85, 159},
  42. { 56, 76, 112, 107, 147, 212, 148, 64, 144},
  43. { 65, 91, 128, 137, 147, 196, 17, 69, 148},
  44. { 72, 104, 136, 138, 147, 180, 245, 73, 147},
  45. { 87, 116, 143, 126, 16, 83, 229, 77, 144},
  46. { 95, 119, 152, 254, 244, 83, 221, 77, 151},
  47. { 100, 129, 159, 156, 244, 148, 197, 77, 160},
  48. { 105, 141, 167, 247, 244, 132, 181, 84, 166},
  49. { 105, 147, 168, 247, 244, 245, 181, 90, 170},
  50. { 120, 153, 175, 248, 212, 229, 165, 90, 180},
  51. { 119, 156, 176, 248, 244, 229, 84, 74, 160},
  52. { 119, 158, 183, 248, 244, 229, 149, 78, 165}
  53. };
  54. /* Definition of the various controls */
  55. struct mctl {
  56. struct v4l2_queryctrl desc;
  57. size_t control;
  58. };
  59. #define BLMIN 0x0FF
  60. #define WLMAX 0x3FF
  61. static const struct mctl maven_controls[] =
  62. { { { V4L2_CID_BRIGHTNESS, V4L2_CTRL_TYPE_INTEGER,
  63. "brightness",
  64. 0, WLMAX - BLMIN, 1, 379 - BLMIN,
  65. 0,
  66. }, offsetof(struct matrox_fb_info, altout.tvo_params.brightness) },
  67. { { V4L2_CID_CONTRAST, V4L2_CTRL_TYPE_INTEGER,
  68. "contrast",
  69. 0, 1023, 1, 127,
  70. 0,
  71. }, offsetof(struct matrox_fb_info, altout.tvo_params.contrast) },
  72. { { V4L2_CID_SATURATION, V4L2_CTRL_TYPE_INTEGER,
  73. "saturation",
  74. 0, 255, 1, 155,
  75. 0,
  76. }, offsetof(struct matrox_fb_info, altout.tvo_params.saturation) },
  77. { { V4L2_CID_HUE, V4L2_CTRL_TYPE_INTEGER,
  78. "hue",
  79. 0, 255, 1, 0,
  80. 0,
  81. }, offsetof(struct matrox_fb_info, altout.tvo_params.hue) },
  82. { { V4L2_CID_GAMMA, V4L2_CTRL_TYPE_INTEGER,
  83. "gamma",
  84. 0, ARRAY_SIZE(maven_gamma) - 1, 1, 3,
  85. 0,
  86. }, offsetof(struct matrox_fb_info, altout.tvo_params.gamma) },
  87. { { MATROXFB_CID_TESTOUT, V4L2_CTRL_TYPE_BOOLEAN,
  88. "test output",
  89. 0, 1, 1, 0,
  90. 0,
  91. }, offsetof(struct matrox_fb_info, altout.tvo_params.testout) },
  92. { { MATROXFB_CID_DEFLICKER, V4L2_CTRL_TYPE_INTEGER,
  93. "deflicker mode",
  94. 0, 2, 1, 0,
  95. 0,
  96. }, offsetof(struct matrox_fb_info, altout.tvo_params.deflicker) },
  97. };
  98. #define MAVCTRLS ARRAY_SIZE(maven_controls)
  99. /* Return: positive number: id found
  100. -EINVAL: id not found, return failure
  101. -ENOENT: id not found, create fake disabled control */
  102. static int get_ctrl_id(__u32 v4l2_id) {
  103. int i;
  104. for (i = 0; i < MAVCTRLS; i++) {
  105. if (v4l2_id < maven_controls[i].desc.id) {
  106. if (maven_controls[i].desc.id == 0x08000000) {
  107. return -EINVAL;
  108. }
  109. return -ENOENT;
  110. }
  111. if (v4l2_id == maven_controls[i].desc.id) {
  112. return i;
  113. }
  114. }
  115. return -EINVAL;
  116. }
  117. struct maven_data {
  118. struct matrox_fb_info* primary_head;
  119. struct i2c_client *client;
  120. int version;
  121. };
  122. static int* get_ctrl_ptr(struct maven_data* md, int idx) {
  123. return (int*)((char*)(md->primary_head) + maven_controls[idx].control);
  124. }
  125. static int maven_get_reg(struct i2c_client* c, char reg) {
  126. char dst;
  127. struct i2c_msg msgs[] = {{ c->addr, I2C_M_REV_DIR_ADDR, sizeof(reg), &reg },
  128. { c->addr, I2C_M_RD | I2C_M_NOSTART, sizeof(dst), &dst }};
  129. s32 err;
  130. err = i2c_transfer(c->adapter, msgs, 2);
  131. if (err < 0)
  132. printk(KERN_INFO "ReadReg(%d) failed\n", reg);
  133. return dst & 0xFF;
  134. }
  135. static int maven_set_reg(struct i2c_client* c, int reg, int val) {
  136. s32 err;
  137. err = i2c_smbus_write_byte_data(c, reg, val);
  138. if (err)
  139. printk(KERN_INFO "WriteReg(%d) failed\n", reg);
  140. return err;
  141. }
  142. static int maven_set_reg_pair(struct i2c_client* c, int reg, int val) {
  143. s32 err;
  144. err = i2c_smbus_write_word_data(c, reg, val);
  145. if (err)
  146. printk(KERN_INFO "WriteRegPair(%d) failed\n", reg);
  147. return err;
  148. }
  149. static const struct matrox_pll_features maven_pll = {
  150. 50000,
  151. 27000,
  152. 4, 127,
  153. 2, 31,
  154. 3
  155. };
  156. struct matrox_pll_features2 {
  157. unsigned int vco_freq_min;
  158. unsigned int vco_freq_max;
  159. unsigned int feed_div_min;
  160. unsigned int feed_div_max;
  161. unsigned int in_div_min;
  162. unsigned int in_div_max;
  163. unsigned int post_shift_max;
  164. };
  165. struct matrox_pll_ctl {
  166. unsigned int ref_freq;
  167. unsigned int den;
  168. };
  169. static const struct matrox_pll_features2 maven1000_pll = {
  170. 50000000,
  171. 300000000,
  172. 5, 128,
  173. 3, 32,
  174. 3
  175. };
  176. static const struct matrox_pll_ctl maven_PAL = {
  177. 540000,
  178. 50
  179. };
  180. static const struct matrox_pll_ctl maven_NTSC = {
  181. 450450, /* 27027000/60 == 27000000/59.94005994 */
  182. 60
  183. };
  184. static int matroxfb_PLL_mavenclock(const struct matrox_pll_features2* pll,
  185. const struct matrox_pll_ctl* ctl,
  186. unsigned int htotal, unsigned int vtotal,
  187. unsigned int* in, unsigned int* feed, unsigned int* post,
  188. unsigned int* h2) {
  189. unsigned int besth2 = 0;
  190. unsigned int fxtal = ctl->ref_freq;
  191. unsigned int fmin = pll->vco_freq_min / ctl->den;
  192. unsigned int fwant;
  193. unsigned int p;
  194. unsigned int scrlen;
  195. unsigned int fmax;
  196. DBG(__func__)
  197. scrlen = htotal * (vtotal - 1);
  198. fwant = htotal * vtotal;
  199. fmax = pll->vco_freq_max / ctl->den;
  200. dprintk(KERN_DEBUG "want: %u, xtal: %u, h: %u, v: %u, fmax: %u\n",
  201. fwant, fxtal, htotal, vtotal, fmax);
  202. for (p = 1; p <= pll->post_shift_max; p++) {
  203. if (fwant * 2 > fmax)
  204. break;
  205. fwant *= 2;
  206. }
  207. if (fwant > fmax)
  208. return 0;
  209. for (; p-- > 0; fwant >>= 1) {
  210. unsigned int m;
  211. if (fwant < fmin) break;
  212. for (m = pll->in_div_min; m <= pll->in_div_max; m++) {
  213. unsigned int n;
  214. unsigned int dvd;
  215. unsigned int ln;
  216. n = (fwant * m) / fxtal;
  217. if (n < pll->feed_div_min)
  218. continue;
  219. if (n > pll->feed_div_max)
  220. break;
  221. ln = fxtal * n;
  222. dvd = m << p;
  223. if (ln % dvd)
  224. continue;
  225. ln = ln / dvd;
  226. if (ln < scrlen + 2)
  227. continue;
  228. ln = ln - scrlen;
  229. if (ln > htotal)
  230. continue;
  231. dprintk(KERN_DEBUG "Match: %u / %u / %u / %u\n", n, m, p, ln);
  232. if (ln > besth2) {
  233. dprintk(KERN_DEBUG "Better...\n");
  234. *h2 = besth2 = ln;
  235. *post = p;
  236. *in = m;
  237. *feed = n;
  238. }
  239. }
  240. }
  241. /* if h2/post/in/feed have not been assigned, return zero (error) */
  242. if (besth2 < 2)
  243. return 0;
  244. dprintk(KERN_ERR "clk: %02X %02X %02X %d %d\n", *in, *feed, *post, fxtal, fwant);
  245. return fxtal * (*feed) / (*in) * ctl->den;
  246. }
  247. static int matroxfb_mavenclock(const struct matrox_pll_ctl *ctl,
  248. unsigned int htotal, unsigned int vtotal,
  249. unsigned int* in, unsigned int* feed, unsigned int* post,
  250. unsigned int* htotal2) {
  251. unsigned int fvco;
  252. unsigned int uninitialized_var(p);
  253. fvco = matroxfb_PLL_mavenclock(&maven1000_pll, ctl, htotal, vtotal, in, feed, &p, htotal2);
  254. if (!fvco)
  255. return -EINVAL;
  256. p = (1 << p) - 1;
  257. if (fvco <= 100000000)
  258. ;
  259. else if (fvco <= 140000000)
  260. p |= 0x08;
  261. else if (fvco <= 180000000)
  262. p |= 0x10;
  263. else
  264. p |= 0x18;
  265. *post = p;
  266. return 0;
  267. }
  268. static void DAC1064_calcclock(unsigned int freq, unsigned int fmax,
  269. unsigned int* in, unsigned int* feed, unsigned int* post) {
  270. unsigned int fvco;
  271. unsigned int p;
  272. fvco = matroxfb_PLL_calcclock(&maven_pll, freq, fmax, in, feed, &p);
  273. p = (1 << p) - 1;
  274. if (fvco <= 100000)
  275. ;
  276. else if (fvco <= 140000)
  277. p |= 0x08;
  278. else if (fvco <= 180000)
  279. p |= 0x10;
  280. else
  281. p |= 0x18;
  282. *post = p;
  283. return;
  284. }
  285. static unsigned char maven_compute_deflicker (const struct maven_data* md) {
  286. unsigned char df;
  287. df = (md->version == MGATVO_B?0x40:0x00);
  288. switch (md->primary_head->altout.tvo_params.deflicker) {
  289. case 0:
  290. /* df |= 0x00; */
  291. break;
  292. case 1:
  293. df |= 0xB1;
  294. break;
  295. case 2:
  296. df |= 0xA2;
  297. break;
  298. }
  299. return df;
  300. }
  301. static void maven_compute_bwlevel (const struct maven_data* md,
  302. int *bl, int *wl) {
  303. const int b = md->primary_head->altout.tvo_params.brightness + BLMIN;
  304. const int c = md->primary_head->altout.tvo_params.contrast;
  305. *bl = max(b - c, BLMIN);
  306. *wl = min(b + c, WLMAX);
  307. }
  308. static const struct maven_gamma* maven_compute_gamma (const struct maven_data* md) {
  309. return maven_gamma + md->primary_head->altout.tvo_params.gamma;
  310. }
  311. static void maven_init_TVdata(const struct maven_data* md, struct mavenregs* data) {
  312. static struct mavenregs palregs = { {
  313. 0x2A, 0x09, 0x8A, 0xCB, /* 00: chroma subcarrier */
  314. 0x00,
  315. 0x00, /* ? not written */
  316. 0x00, /* modified by code (F9 written...) */
  317. 0x00, /* ? not written */
  318. 0x7E, /* 08 */
  319. 0x44, /* 09 */
  320. 0x9C, /* 0A */
  321. 0x2E, /* 0B */
  322. 0x21, /* 0C */
  323. 0x00, /* ? not written */
  324. 0x3F, 0x03, /* 0E-0F */
  325. 0x3F, 0x03, /* 10-11 */
  326. 0x1A, /* 12 */
  327. 0x2A, /* 13 */
  328. 0x1C, 0x3D, 0x14, /* 14-16 */
  329. 0x9C, 0x01, /* 17-18 */
  330. 0x00, /* 19 */
  331. 0xFE, /* 1A */
  332. 0x7E, /* 1B */
  333. 0x60, /* 1C */
  334. 0x05, /* 1D */
  335. 0x89, 0x03, /* 1E-1F */
  336. 0x72, /* 20 */
  337. 0x07, /* 21 */
  338. 0x72, /* 22 */
  339. 0x00, /* 23 */
  340. 0x00, /* 24 */
  341. 0x00, /* 25 */
  342. 0x08, /* 26 */
  343. 0x04, /* 27 */
  344. 0x00, /* 28 */
  345. 0x1A, /* 29 */
  346. 0x55, 0x01, /* 2A-2B */
  347. 0x26, /* 2C */
  348. 0x07, 0x7E, /* 2D-2E */
  349. 0x02, 0x54, /* 2F-30 */
  350. 0xB0, 0x00, /* 31-32 */
  351. 0x14, /* 33 */
  352. 0x49, /* 34 */
  353. 0x00, /* 35 written multiple times */
  354. 0x00, /* 36 not written */
  355. 0xA3, /* 37 */
  356. 0xC8, /* 38 */
  357. 0x22, /* 39 */
  358. 0x02, /* 3A */
  359. 0x22, /* 3B */
  360. 0x3F, 0x03, /* 3C-3D */
  361. 0x00, /* 3E written multiple times */
  362. 0x00, /* 3F not written */
  363. }, MATROXFB_OUTPUT_MODE_PAL, 625, 50 };
  364. static struct mavenregs ntscregs = { {
  365. 0x21, 0xF0, 0x7C, 0x1F, /* 00: chroma subcarrier */
  366. 0x00,
  367. 0x00, /* ? not written */
  368. 0x00, /* modified by code (F9 written...) */
  369. 0x00, /* ? not written */
  370. 0x7E, /* 08 */
  371. 0x43, /* 09 */
  372. 0x7E, /* 0A */
  373. 0x3D, /* 0B */
  374. 0x00, /* 0C */
  375. 0x00, /* ? not written */
  376. 0x41, 0x00, /* 0E-0F */
  377. 0x3C, 0x00, /* 10-11 */
  378. 0x17, /* 12 */
  379. 0x21, /* 13 */
  380. 0x1B, 0x1B, 0x24, /* 14-16 */
  381. 0x83, 0x01, /* 17-18 */
  382. 0x00, /* 19 */
  383. 0x0F, /* 1A */
  384. 0x0F, /* 1B */
  385. 0x60, /* 1C */
  386. 0x05, /* 1D */
  387. 0x89, 0x02, /* 1E-1F */
  388. 0x5F, /* 20 */
  389. 0x04, /* 21 */
  390. 0x5F, /* 22 */
  391. 0x01, /* 23 */
  392. 0x02, /* 24 */
  393. 0x00, /* 25 */
  394. 0x0A, /* 26 */
  395. 0x05, /* 27 */
  396. 0x00, /* 28 */
  397. 0x10, /* 29 */
  398. 0xFF, 0x03, /* 2A-2B */
  399. 0x24, /* 2C */
  400. 0x0F, 0x78, /* 2D-2E */
  401. 0x00, 0x00, /* 2F-30 */
  402. 0xB2, 0x04, /* 31-32 */
  403. 0x14, /* 33 */
  404. 0x02, /* 34 */
  405. 0x00, /* 35 written multiple times */
  406. 0x00, /* 36 not written */
  407. 0xA3, /* 37 */
  408. 0xC8, /* 38 */
  409. 0x15, /* 39 */
  410. 0x05, /* 3A */
  411. 0x3B, /* 3B */
  412. 0x3C, 0x00, /* 3C-3D */
  413. 0x00, /* 3E written multiple times */
  414. 0x00, /* never written */
  415. }, MATROXFB_OUTPUT_MODE_NTSC, 525, 60 };
  416. struct matrox_fb_info *minfo = md->primary_head;
  417. if (minfo->outputs[1].mode == MATROXFB_OUTPUT_MODE_PAL)
  418. *data = palregs;
  419. else
  420. *data = ntscregs;
  421. /* Set deflicker */
  422. data->regs[0x93] = maven_compute_deflicker(md);
  423. /* set gamma */
  424. {
  425. const struct maven_gamma* g;
  426. g = maven_compute_gamma(md);
  427. data->regs[0x83] = g->reg83;
  428. data->regs[0x84] = g->reg84;
  429. data->regs[0x85] = g->reg85;
  430. data->regs[0x86] = g->reg86;
  431. data->regs[0x87] = g->reg87;
  432. data->regs[0x88] = g->reg88;
  433. data->regs[0x89] = g->reg89;
  434. data->regs[0x8A] = g->reg8a;
  435. data->regs[0x8B] = g->reg8b;
  436. }
  437. /* Set contrast / brightness */
  438. {
  439. int bl, wl;
  440. maven_compute_bwlevel (md, &bl, &wl);
  441. data->regs[0x0e] = bl >> 2;
  442. data->regs[0x0f] = bl & 3;
  443. data->regs[0x1e] = wl >> 2;
  444. data->regs[0x1f] = wl & 3;
  445. }
  446. /* Set saturation */
  447. {
  448. data->regs[0x20] =
  449. data->regs[0x22] = minfo->altout.tvo_params.saturation;
  450. }
  451. /* Set HUE */
  452. data->regs[0x25] = minfo->altout.tvo_params.hue;
  453. return;
  454. }
  455. #define LR(x) maven_set_reg(c, (x), m->regs[(x)])
  456. #define LRP(x) maven_set_reg_pair(c, (x), m->regs[(x)] | (m->regs[(x)+1] << 8))
  457. static void maven_init_TV(struct i2c_client* c, const struct mavenregs* m) {
  458. int val;
  459. maven_set_reg(c, 0x3E, 0x01);
  460. maven_get_reg(c, 0x82); /* fetch oscillator state? */
  461. maven_set_reg(c, 0x8C, 0x00);
  462. maven_get_reg(c, 0x94); /* get 0x82 */
  463. maven_set_reg(c, 0x94, 0xA2);
  464. /* xmiscctrl */
  465. maven_set_reg_pair(c, 0x8E, 0x1EFF);
  466. maven_set_reg(c, 0xC6, 0x01);
  467. /* removed code... */
  468. maven_get_reg(c, 0x06);
  469. maven_set_reg(c, 0x06, 0xF9); /* or read |= 0xF0 ? */
  470. /* removed code here... */
  471. /* real code begins here? */
  472. /* chroma subcarrier */
  473. LR(0x00); LR(0x01); LR(0x02); LR(0x03);
  474. LR(0x04);
  475. LR(0x2C);
  476. LR(0x08);
  477. LR(0x0A);
  478. LR(0x09);
  479. LR(0x29);
  480. LRP(0x31);
  481. LRP(0x17);
  482. LR(0x0B);
  483. LR(0x0C);
  484. if (m->mode == MATROXFB_OUTPUT_MODE_PAL) {
  485. maven_set_reg(c, 0x35, 0x10); /* ... */
  486. } else {
  487. maven_set_reg(c, 0x35, 0x0F); /* ... */
  488. }
  489. LRP(0x10);
  490. LRP(0x0E);
  491. LRP(0x1E);
  492. LR(0x20); /* saturation #1 */
  493. LR(0x22); /* saturation #2 */
  494. LR(0x25); /* hue */
  495. LR(0x34);
  496. LR(0x33);
  497. LR(0x19);
  498. LR(0x12);
  499. LR(0x3B);
  500. LR(0x13);
  501. LR(0x39);
  502. LR(0x1D);
  503. LR(0x3A);
  504. LR(0x24);
  505. LR(0x14);
  506. LR(0x15);
  507. LR(0x16);
  508. LRP(0x2D);
  509. LRP(0x2F);
  510. LR(0x1A);
  511. LR(0x1B);
  512. LR(0x1C);
  513. LR(0x23);
  514. LR(0x26);
  515. LR(0x28);
  516. LR(0x27);
  517. LR(0x21);
  518. LRP(0x2A);
  519. if (m->mode == MATROXFB_OUTPUT_MODE_PAL)
  520. maven_set_reg(c, 0x35, 0x1D); /* ... */
  521. else
  522. maven_set_reg(c, 0x35, 0x1C);
  523. LRP(0x3C);
  524. LR(0x37);
  525. LR(0x38);
  526. maven_set_reg(c, 0xB3, 0x01);
  527. maven_get_reg(c, 0xB0); /* read 0x80 */
  528. maven_set_reg(c, 0xB0, 0x08); /* ugh... */
  529. maven_get_reg(c, 0xB9); /* read 0x7C */
  530. maven_set_reg(c, 0xB9, 0x78);
  531. maven_get_reg(c, 0xBF); /* read 0x00 */
  532. maven_set_reg(c, 0xBF, 0x02);
  533. maven_get_reg(c, 0x94); /* read 0x82 */
  534. maven_set_reg(c, 0x94, 0xB3);
  535. LR(0x80); /* 04 1A 91 or 05 21 91 */
  536. LR(0x81);
  537. LR(0x82);
  538. maven_set_reg(c, 0x8C, 0x20);
  539. maven_get_reg(c, 0x8D);
  540. maven_set_reg(c, 0x8D, 0x10);
  541. LR(0x90); /* 4D 50 52 or 4E 05 45 */
  542. LR(0x91);
  543. LR(0x92);
  544. LRP(0x9A); /* 0049 or 004F */
  545. LRP(0x9C); /* 0004 or 0004 */
  546. LRP(0x9E); /* 0458 or 045E */
  547. LRP(0xA0); /* 05DA or 051B */
  548. LRP(0xA2); /* 00CC or 00CF */
  549. LRP(0xA4); /* 007D or 007F */
  550. LRP(0xA6); /* 007C or 007E */
  551. LRP(0xA8); /* 03CB or 03CE */
  552. LRP(0x98); /* 0000 or 0000 */
  553. LRP(0xAE); /* 0044 or 003A */
  554. LRP(0x96); /* 05DA or 051B */
  555. LRP(0xAA); /* 04BC or 046A */
  556. LRP(0xAC); /* 004D or 004E */
  557. LR(0xBE);
  558. LR(0xC2);
  559. maven_get_reg(c, 0x8D);
  560. maven_set_reg(c, 0x8D, 0x04);
  561. LR(0x20); /* saturation #1 */
  562. LR(0x22); /* saturation #2 */
  563. LR(0x93); /* whoops */
  564. LR(0x20); /* oh, saturation #1 again */
  565. LR(0x22); /* oh, saturation #2 again */
  566. LR(0x25); /* hue */
  567. LRP(0x0E);
  568. LRP(0x1E);
  569. LRP(0x0E); /* problems with memory? */
  570. LRP(0x1E); /* yes, matrox must have problems in memory area... */
  571. /* load gamma correction stuff */
  572. LR(0x83);
  573. LR(0x84);
  574. LR(0x85);
  575. LR(0x86);
  576. LR(0x87);
  577. LR(0x88);
  578. LR(0x89);
  579. LR(0x8A);
  580. LR(0x8B);
  581. val = maven_get_reg(c, 0x8D);
  582. val &= 0x14; /* 0x10 or anything ored with it */
  583. maven_set_reg(c, 0x8D, val);
  584. LR(0x33);
  585. LR(0x19);
  586. LR(0x12);
  587. LR(0x3B);
  588. LR(0x13);
  589. LR(0x39);
  590. LR(0x1D);
  591. LR(0x3A);
  592. LR(0x24);
  593. LR(0x14);
  594. LR(0x15);
  595. LR(0x16);
  596. LRP(0x2D);
  597. LRP(0x2F);
  598. LR(0x1A);
  599. LR(0x1B);
  600. LR(0x1C);
  601. LR(0x23);
  602. LR(0x26);
  603. LR(0x28);
  604. LR(0x27);
  605. LR(0x21);
  606. LRP(0x2A);
  607. if (m->mode == MATROXFB_OUTPUT_MODE_PAL)
  608. maven_set_reg(c, 0x35, 0x1D);
  609. else
  610. maven_set_reg(c, 0x35, 0x1C);
  611. LRP(0x3C);
  612. LR(0x37);
  613. LR(0x38);
  614. maven_get_reg(c, 0xB0);
  615. LR(0xB0); /* output mode */
  616. LR(0x90);
  617. LR(0xBE);
  618. LR(0xC2);
  619. LRP(0x9A);
  620. LRP(0xA2);
  621. LRP(0x9E);
  622. LRP(0xA6);
  623. LRP(0xAA);
  624. LRP(0xAC);
  625. maven_set_reg(c, 0x3E, 0x00);
  626. maven_set_reg(c, 0x95, 0x20);
  627. }
  628. static int maven_find_exact_clocks(unsigned int ht, unsigned int vt,
  629. struct mavenregs* m) {
  630. unsigned int x;
  631. unsigned int err = ~0;
  632. /* 1:1 */
  633. m->regs[0x80] = 0x0F;
  634. m->regs[0x81] = 0x07;
  635. m->regs[0x82] = 0x81;
  636. for (x = 0; x < 8; x++) {
  637. unsigned int c;
  638. unsigned int uninitialized_var(a), uninitialized_var(b),
  639. uninitialized_var(h2);
  640. unsigned int h = ht + 2 + x;
  641. if (!matroxfb_mavenclock((m->mode == MATROXFB_OUTPUT_MODE_PAL) ? &maven_PAL : &maven_NTSC, h, vt, &a, &b, &c, &h2)) {
  642. unsigned int diff = h - h2;
  643. if (diff < err) {
  644. err = diff;
  645. m->regs[0x80] = a - 1;
  646. m->regs[0x81] = b - 1;
  647. m->regs[0x82] = c | 0x80;
  648. m->hcorr = h2 - 2;
  649. m->htotal = h - 2;
  650. }
  651. }
  652. }
  653. return err != ~0U;
  654. }
  655. static inline int maven_compute_timming(struct maven_data* md,
  656. struct my_timming* mt,
  657. struct mavenregs* m) {
  658. unsigned int tmpi;
  659. unsigned int a, bv, c;
  660. struct matrox_fb_info *minfo = md->primary_head;
  661. m->mode = minfo->outputs[1].mode;
  662. if (m->mode != MATROXFB_OUTPUT_MODE_MONITOR) {
  663. unsigned int lmargin;
  664. unsigned int umargin;
  665. unsigned int vslen;
  666. unsigned int hcrt;
  667. unsigned int slen;
  668. maven_init_TVdata(md, m);
  669. if (maven_find_exact_clocks(mt->HTotal, mt->VTotal, m) == 0)
  670. return -EINVAL;
  671. lmargin = mt->HTotal - mt->HSyncEnd;
  672. slen = mt->HSyncEnd - mt->HSyncStart;
  673. hcrt = mt->HTotal - slen - mt->delay;
  674. umargin = mt->VTotal - mt->VSyncEnd;
  675. vslen = mt->VSyncEnd - mt->VSyncStart;
  676. if (m->hcorr < mt->HTotal)
  677. hcrt += m->hcorr;
  678. if (hcrt > mt->HTotal)
  679. hcrt -= mt->HTotal;
  680. if (hcrt + 2 > mt->HTotal)
  681. hcrt = 0; /* or issue warning? */
  682. /* last (first? middle?) line in picture can have different length */
  683. /* hlen - 2 */
  684. m->regs[0x96] = m->hcorr;
  685. m->regs[0x97] = m->hcorr >> 8;
  686. /* ... */
  687. m->regs[0x98] = 0x00; m->regs[0x99] = 0x00;
  688. /* hblanking end */
  689. m->regs[0x9A] = lmargin; /* 100% */
  690. m->regs[0x9B] = lmargin >> 8; /* 100% */
  691. /* who knows */
  692. m->regs[0x9C] = 0x04;
  693. m->regs[0x9D] = 0x00;
  694. /* htotal - 2 */
  695. m->regs[0xA0] = m->htotal;
  696. m->regs[0xA1] = m->htotal >> 8;
  697. /* vblanking end */
  698. m->regs[0xA2] = mt->VTotal - mt->VSyncStart - 1; /* stop vblanking */
  699. m->regs[0xA3] = (mt->VTotal - mt->VSyncStart - 1) >> 8;
  700. /* something end... [A6]+1..[A8] */
  701. if (md->version == MGATVO_B) {
  702. m->regs[0xA4] = 0x04;
  703. m->regs[0xA5] = 0x00;
  704. } else {
  705. m->regs[0xA4] = 0x01;
  706. m->regs[0xA5] = 0x00;
  707. }
  708. /* something start... 0..[A4]-1 */
  709. m->regs[0xA6] = 0x00;
  710. m->regs[0xA7] = 0x00;
  711. /* vertical line count - 1 */
  712. m->regs[0xA8] = mt->VTotal - 1;
  713. m->regs[0xA9] = (mt->VTotal - 1) >> 8;
  714. /* horizontal vidrst pos */
  715. m->regs[0xAA] = hcrt; /* 0 <= hcrt <= htotal - 2 */
  716. m->regs[0xAB] = hcrt >> 8;
  717. /* vertical vidrst pos */
  718. m->regs[0xAC] = mt->VTotal - 2;
  719. m->regs[0xAD] = (mt->VTotal - 2) >> 8;
  720. /* moves picture up/down and so on... */
  721. m->regs[0xAE] = 0x01; /* Fix this... 0..VTotal */
  722. m->regs[0xAF] = 0x00;
  723. {
  724. int hdec;
  725. int hlen;
  726. unsigned int ibmin = 4 + lmargin + mt->HDisplay;
  727. unsigned int ib;
  728. int i;
  729. /* Verify! */
  730. /* Where 94208 came from? */
  731. if (mt->HTotal)
  732. hdec = 94208 / (mt->HTotal);
  733. else
  734. hdec = 0x81;
  735. if (hdec > 0x81)
  736. hdec = 0x81;
  737. if (hdec < 0x41)
  738. hdec = 0x41;
  739. hdec--;
  740. hlen = 98304 - 128 - ((lmargin + mt->HDisplay - 8) * hdec);
  741. if (hlen < 0)
  742. hlen = 0;
  743. hlen = hlen >> 8;
  744. if (hlen > 0xFF)
  745. hlen = 0xFF;
  746. /* Now we have to compute input buffer length.
  747. If you want any picture, it must be between
  748. 4 + lmargin + xres
  749. and
  750. 94208 / hdec
  751. If you want perfect picture even on the top
  752. of screen, it must be also
  753. 0x3C0000 * i / hdec + Q - R / hdec
  754. where
  755. R Qmin Qmax
  756. 0x07000 0x5AE 0x5BF
  757. 0x08000 0x5CF 0x5FF
  758. 0x0C000 0x653 0x67F
  759. 0x10000 0x6F8 0x6FF
  760. */
  761. i = 1;
  762. do {
  763. ib = ((0x3C0000 * i - 0x8000)/ hdec + 0x05E7) >> 8;
  764. i++;
  765. } while (ib < ibmin);
  766. if (ib >= m->htotal + 2) {
  767. ib = ibmin;
  768. }
  769. m->regs[0x90] = hdec; /* < 0x40 || > 0x80 is bad... 0x80 is questionable */
  770. m->regs[0xC2] = hlen;
  771. /* 'valid' input line length */
  772. m->regs[0x9E] = ib;
  773. m->regs[0x9F] = ib >> 8;
  774. }
  775. {
  776. int vdec;
  777. int vlen;
  778. #define MATROX_USE64BIT_DIVIDE
  779. if (mt->VTotal) {
  780. #ifdef MATROX_USE64BIT_DIVIDE
  781. u64 f1;
  782. u32 a;
  783. u32 b;
  784. a = m->vlines * (m->htotal + 2);
  785. b = (mt->VTotal - 1) * (m->htotal + 2) + m->hcorr + 2;
  786. f1 = ((u64)a) << 15; /* *32768 */
  787. do_div(f1, b);
  788. vdec = f1;
  789. #else
  790. vdec = m->vlines * 32768 / mt->VTotal;
  791. #endif
  792. } else
  793. vdec = 0x8000;
  794. if (vdec > 0x8000)
  795. vdec = 0x8000;
  796. vlen = (vslen + umargin + mt->VDisplay) * vdec;
  797. vlen = (vlen >> 16) - 146; /* FIXME: 146?! */
  798. if (vlen < 0)
  799. vlen = 0;
  800. if (vlen > 0xFF)
  801. vlen = 0xFF;
  802. vdec--;
  803. m->regs[0x91] = vdec;
  804. m->regs[0x92] = vdec >> 8;
  805. m->regs[0xBE] = vlen;
  806. }
  807. m->regs[0xB0] = 0x08; /* output: SVideo/Composite */
  808. return 0;
  809. }
  810. DAC1064_calcclock(mt->pixclock, 450000, &a, &bv, &c);
  811. m->regs[0x80] = a;
  812. m->regs[0x81] = bv;
  813. m->regs[0x82] = c | 0x80;
  814. m->regs[0xB3] = 0x01;
  815. m->regs[0x94] = 0xB2;
  816. /* htotal... */
  817. m->regs[0x96] = mt->HTotal;
  818. m->regs[0x97] = mt->HTotal >> 8;
  819. /* ?? */
  820. m->regs[0x98] = 0x00;
  821. m->regs[0x99] = 0x00;
  822. /* hsync len */
  823. tmpi = mt->HSyncEnd - mt->HSyncStart;
  824. m->regs[0x9A] = tmpi;
  825. m->regs[0x9B] = tmpi >> 8;
  826. /* hblank end */
  827. tmpi = mt->HTotal - mt->HSyncStart;
  828. m->regs[0x9C] = tmpi;
  829. m->regs[0x9D] = tmpi >> 8;
  830. /* hblank start */
  831. tmpi += mt->HDisplay;
  832. m->regs[0x9E] = tmpi;
  833. m->regs[0x9F] = tmpi >> 8;
  834. /* htotal + 1 */
  835. tmpi = mt->HTotal + 1;
  836. m->regs[0xA0] = tmpi;
  837. m->regs[0xA1] = tmpi >> 8;
  838. /* vsync?! */
  839. tmpi = mt->VSyncEnd - mt->VSyncStart - 1;
  840. m->regs[0xA2] = tmpi;
  841. m->regs[0xA3] = tmpi >> 8;
  842. /* ignored? */
  843. tmpi = mt->VTotal - mt->VSyncStart;
  844. m->regs[0xA4] = tmpi;
  845. m->regs[0xA5] = tmpi >> 8;
  846. /* ignored? */
  847. tmpi = mt->VTotal - 1;
  848. m->regs[0xA6] = tmpi;
  849. m->regs[0xA7] = tmpi >> 8;
  850. /* vtotal - 1 */
  851. m->regs[0xA8] = tmpi;
  852. m->regs[0xA9] = tmpi >> 8;
  853. /* hor vidrst */
  854. tmpi = mt->HTotal - mt->delay;
  855. m->regs[0xAA] = tmpi;
  856. m->regs[0xAB] = tmpi >> 8;
  857. /* vert vidrst */
  858. tmpi = mt->VTotal - 2;
  859. m->regs[0xAC] = tmpi;
  860. m->regs[0xAD] = tmpi >> 8;
  861. /* ignored? */
  862. m->regs[0xAE] = 0x00;
  863. m->regs[0xAF] = 0x00;
  864. m->regs[0xB0] = 0x03; /* output: monitor */
  865. m->regs[0xB1] = 0xA0; /* ??? */
  866. m->regs[0x8C] = 0x20; /* must be set... */
  867. m->regs[0x8D] = 0x04; /* defaults to 0x10: test signal */
  868. m->regs[0xB9] = 0x1A; /* defaults to 0x2C: too bright */
  869. m->regs[0xBF] = 0x22; /* makes picture stable */
  870. return 0;
  871. }
  872. static int maven_program_timming(struct maven_data* md,
  873. const struct mavenregs* m) {
  874. struct i2c_client *c = md->client;
  875. if (m->mode == MATROXFB_OUTPUT_MODE_MONITOR) {
  876. LR(0x80);
  877. LR(0x81);
  878. LR(0x82);
  879. LR(0xB3);
  880. LR(0x94);
  881. LRP(0x96);
  882. LRP(0x98);
  883. LRP(0x9A);
  884. LRP(0x9C);
  885. LRP(0x9E);
  886. LRP(0xA0);
  887. LRP(0xA2);
  888. LRP(0xA4);
  889. LRP(0xA6);
  890. LRP(0xA8);
  891. LRP(0xAA);
  892. LRP(0xAC);
  893. LRP(0xAE);
  894. LR(0xB0); /* output: monitor */
  895. LR(0xB1); /* ??? */
  896. LR(0x8C); /* must be set... */
  897. LR(0x8D); /* defaults to 0x10: test signal */
  898. LR(0xB9); /* defaults to 0x2C: too bright */
  899. LR(0xBF); /* makes picture stable */
  900. } else {
  901. maven_init_TV(c, m);
  902. }
  903. return 0;
  904. }
  905. static inline int maven_resync(struct maven_data* md) {
  906. struct i2c_client *c = md->client;
  907. maven_set_reg(c, 0x95, 0x20); /* start whole thing */
  908. return 0;
  909. }
  910. static int maven_get_queryctrl (struct maven_data* md,
  911. struct v4l2_queryctrl *p) {
  912. int i;
  913. i = get_ctrl_id(p->id);
  914. if (i >= 0) {
  915. *p = maven_controls[i].desc;
  916. return 0;
  917. }
  918. if (i == -ENOENT) {
  919. static const struct v4l2_queryctrl disctrl =
  920. { .flags = V4L2_CTRL_FLAG_DISABLED };
  921. i = p->id;
  922. *p = disctrl;
  923. p->id = i;
  924. sprintf(p->name, "Ctrl #%08X", i);
  925. return 0;
  926. }
  927. return -EINVAL;
  928. }
  929. static int maven_set_control (struct maven_data* md,
  930. struct v4l2_control *p) {
  931. int i;
  932. i = get_ctrl_id(p->id);
  933. if (i < 0) return -EINVAL;
  934. /*
  935. * Check if changed.
  936. */
  937. if (p->value == *get_ctrl_ptr(md, i)) return 0;
  938. /*
  939. * Check limits.
  940. */
  941. if (p->value > maven_controls[i].desc.maximum) return -EINVAL;
  942. if (p->value < maven_controls[i].desc.minimum) return -EINVAL;
  943. /*
  944. * Store new value.
  945. */
  946. *get_ctrl_ptr(md, i) = p->value;
  947. switch (p->id) {
  948. case V4L2_CID_BRIGHTNESS:
  949. case V4L2_CID_CONTRAST:
  950. {
  951. int blacklevel, whitelevel;
  952. maven_compute_bwlevel(md, &blacklevel, &whitelevel);
  953. blacklevel = (blacklevel >> 2) | ((blacklevel & 3) << 8);
  954. whitelevel = (whitelevel >> 2) | ((whitelevel & 3) << 8);
  955. maven_set_reg_pair(md->client, 0x0e, blacklevel);
  956. maven_set_reg_pair(md->client, 0x1e, whitelevel);
  957. }
  958. break;
  959. case V4L2_CID_SATURATION:
  960. {
  961. maven_set_reg(md->client, 0x20, p->value);
  962. maven_set_reg(md->client, 0x22, p->value);
  963. }
  964. break;
  965. case V4L2_CID_HUE:
  966. {
  967. maven_set_reg(md->client, 0x25, p->value);
  968. }
  969. break;
  970. case V4L2_CID_GAMMA:
  971. {
  972. const struct maven_gamma* g;
  973. g = maven_compute_gamma(md);
  974. maven_set_reg(md->client, 0x83, g->reg83);
  975. maven_set_reg(md->client, 0x84, g->reg84);
  976. maven_set_reg(md->client, 0x85, g->reg85);
  977. maven_set_reg(md->client, 0x86, g->reg86);
  978. maven_set_reg(md->client, 0x87, g->reg87);
  979. maven_set_reg(md->client, 0x88, g->reg88);
  980. maven_set_reg(md->client, 0x89, g->reg89);
  981. maven_set_reg(md->client, 0x8a, g->reg8a);
  982. maven_set_reg(md->client, 0x8b, g->reg8b);
  983. }
  984. break;
  985. case MATROXFB_CID_TESTOUT:
  986. {
  987. unsigned char val
  988. = maven_get_reg(md->client, 0x8d);
  989. if (p->value) val |= 0x10;
  990. else val &= ~0x10;
  991. maven_set_reg(md->client, 0x8d, val);
  992. }
  993. break;
  994. case MATROXFB_CID_DEFLICKER:
  995. {
  996. maven_set_reg(md->client, 0x93, maven_compute_deflicker(md));
  997. }
  998. break;
  999. }
  1000. return 0;
  1001. }
  1002. static int maven_get_control (struct maven_data* md,
  1003. struct v4l2_control *p) {
  1004. int i;
  1005. i = get_ctrl_id(p->id);
  1006. if (i < 0) return -EINVAL;
  1007. p->value = *get_ctrl_ptr(md, i);
  1008. return 0;
  1009. }
  1010. /******************************************************/
  1011. static int maven_out_compute(void* md, struct my_timming* mt) {
  1012. #define mdinfo ((struct maven_data*)md)
  1013. #define minfo (mdinfo->primary_head)
  1014. return maven_compute_timming(md, mt, &minfo->hw.maven);
  1015. #undef minfo
  1016. #undef mdinfo
  1017. }
  1018. static int maven_out_program(void* md) {
  1019. #define mdinfo ((struct maven_data*)md)
  1020. #define minfo (mdinfo->primary_head)
  1021. return maven_program_timming(md, &minfo->hw.maven);
  1022. #undef minfo
  1023. #undef mdinfo
  1024. }
  1025. static int maven_out_start(void* md) {
  1026. return maven_resync(md);
  1027. }
  1028. static int maven_out_verify_mode(void* md, u_int32_t arg) {
  1029. switch (arg) {
  1030. case MATROXFB_OUTPUT_MODE_PAL:
  1031. case MATROXFB_OUTPUT_MODE_NTSC:
  1032. case MATROXFB_OUTPUT_MODE_MONITOR:
  1033. return 0;
  1034. }
  1035. return -EINVAL;
  1036. }
  1037. static int maven_out_get_queryctrl(void* md, struct v4l2_queryctrl* p) {
  1038. return maven_get_queryctrl(md, p);
  1039. }
  1040. static int maven_out_get_ctrl(void* md, struct v4l2_control* p) {
  1041. return maven_get_control(md, p);
  1042. }
  1043. static int maven_out_set_ctrl(void* md, struct v4l2_control* p) {
  1044. return maven_set_control(md, p);
  1045. }
  1046. static struct matrox_altout maven_altout = {
  1047. .name = "Secondary output",
  1048. .compute = maven_out_compute,
  1049. .program = maven_out_program,
  1050. .start = maven_out_start,
  1051. .verifymode = maven_out_verify_mode,
  1052. .getqueryctrl = maven_out_get_queryctrl,
  1053. .getctrl = maven_out_get_ctrl,
  1054. .setctrl = maven_out_set_ctrl,
  1055. };
  1056. static int maven_init_client(struct i2c_client* clnt) {
  1057. struct maven_data* md = i2c_get_clientdata(clnt);
  1058. struct matrox_fb_info *minfo = container_of(clnt->adapter,
  1059. struct i2c_bit_adapter,
  1060. adapter)->minfo;
  1061. md->primary_head = minfo;
  1062. md->client = clnt;
  1063. down_write(&minfo->altout.lock);
  1064. minfo->outputs[1].output = &maven_altout;
  1065. minfo->outputs[1].src = minfo->outputs[1].default_src;
  1066. minfo->outputs[1].data = md;
  1067. minfo->outputs[1].mode = MATROXFB_OUTPUT_MODE_MONITOR;
  1068. up_write(&minfo->altout.lock);
  1069. if (maven_get_reg(clnt, 0xB2) < 0x14) {
  1070. md->version = MGATVO_B;
  1071. /* Tweak some things for this old chip */
  1072. } else {
  1073. md->version = MGATVO_C;
  1074. }
  1075. /*
  1076. * Set all parameters to its initial values.
  1077. */
  1078. {
  1079. unsigned int i;
  1080. for (i = 0; i < MAVCTRLS; ++i) {
  1081. *get_ctrl_ptr(md, i) = maven_controls[i].desc.default_value;
  1082. }
  1083. }
  1084. return 0;
  1085. }
  1086. static int maven_shutdown_client(struct i2c_client* clnt) {
  1087. struct maven_data* md = i2c_get_clientdata(clnt);
  1088. if (md->primary_head) {
  1089. struct matrox_fb_info *minfo = md->primary_head;
  1090. down_write(&minfo->altout.lock);
  1091. minfo->outputs[1].src = MATROXFB_SRC_NONE;
  1092. minfo->outputs[1].output = NULL;
  1093. minfo->outputs[1].data = NULL;
  1094. minfo->outputs[1].mode = MATROXFB_OUTPUT_MODE_MONITOR;
  1095. up_write(&minfo->altout.lock);
  1096. md->primary_head = NULL;
  1097. }
  1098. return 0;
  1099. }
  1100. static int maven_probe(struct i2c_client *client,
  1101. const struct i2c_device_id *id)
  1102. {
  1103. struct i2c_adapter *adapter = client->adapter;
  1104. int err = -ENODEV;
  1105. struct maven_data* data;
  1106. if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WRITE_WORD_DATA |
  1107. I2C_FUNC_SMBUS_BYTE_DATA |
  1108. I2C_FUNC_PROTOCOL_MANGLING))
  1109. goto ERROR0;
  1110. if (!(data = kzalloc(sizeof(*data), GFP_KERNEL))) {
  1111. err = -ENOMEM;
  1112. goto ERROR0;
  1113. }
  1114. i2c_set_clientdata(client, data);
  1115. err = maven_init_client(client);
  1116. if (err)
  1117. goto ERROR4;
  1118. return 0;
  1119. ERROR4:;
  1120. kfree(data);
  1121. ERROR0:;
  1122. return err;
  1123. }
  1124. static int maven_remove(struct i2c_client *client)
  1125. {
  1126. maven_shutdown_client(client);
  1127. kfree(i2c_get_clientdata(client));
  1128. return 0;
  1129. }
  1130. static const struct i2c_device_id maven_id[] = {
  1131. { "maven", 0 },
  1132. { }
  1133. };
  1134. MODULE_DEVICE_TABLE(i2c, maven_id);
  1135. static struct i2c_driver maven_driver={
  1136. .driver = {
  1137. .name = "maven",
  1138. },
  1139. .probe = maven_probe,
  1140. .remove = maven_remove,
  1141. .id_table = maven_id,
  1142. };
  1143. static int __init matroxfb_maven_init(void)
  1144. {
  1145. return i2c_add_driver(&maven_driver);
  1146. }
  1147. static void __exit matroxfb_maven_exit(void)
  1148. {
  1149. i2c_del_driver(&maven_driver);
  1150. }
  1151. MODULE_AUTHOR("(c) 1999-2002 Petr Vandrovec <vandrove@vc.cvut.cz>");
  1152. MODULE_DESCRIPTION("Matrox G200/G400 Matrox MGA-TVO driver");
  1153. MODULE_LICENSE("GPL");
  1154. module_init(matroxfb_maven_init);
  1155. module_exit(matroxfb_maven_exit);
  1156. /* we do not have __setup() yet */