arkfb.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232
  1. /*
  2. * linux/drivers/video/arkfb.c -- Frame buffer device driver for ARK 2000PV
  3. * with ICS 5342 dac (it is easy to add support for different dacs).
  4. *
  5. * Copyright (c) 2007 Ondrej Zajicek <santiago@crfreenet.org>
  6. *
  7. * This file is subject to the terms and conditions of the GNU General Public
  8. * License. See the file COPYING in the main directory of this archive for
  9. * more details.
  10. *
  11. * Code is based on s3fb
  12. */
  13. #include <linux/module.h>
  14. #include <linux/kernel.h>
  15. #include <linux/errno.h>
  16. #include <linux/string.h>
  17. #include <linux/mm.h>
  18. #include <linux/tty.h>
  19. #include <linux/slab.h>
  20. #include <linux/delay.h>
  21. #include <linux/fb.h>
  22. #include <linux/svga.h>
  23. #include <linux/init.h>
  24. #include <linux/pci.h>
  25. #include <linux/console.h> /* Why should fb driver call console functions? because console_lock() */
  26. #include <video/vga.h>
  27. #ifdef CONFIG_MTRR
  28. #include <asm/mtrr.h>
  29. #endif
  30. struct arkfb_info {
  31. int mclk_freq;
  32. int mtrr_reg;
  33. struct dac_info *dac;
  34. struct vgastate state;
  35. struct mutex open_lock;
  36. unsigned int ref_count;
  37. u32 pseudo_palette[16];
  38. };
  39. /* ------------------------------------------------------------------------- */
  40. static const struct svga_fb_format arkfb_formats[] = {
  41. { 0, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 0,
  42. FB_TYPE_TEXT, FB_AUX_TEXT_SVGA_STEP4, FB_VISUAL_PSEUDOCOLOR, 8, 8},
  43. { 4, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 0,
  44. FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_PSEUDOCOLOR, 8, 16},
  45. { 4, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 1,
  46. FB_TYPE_INTERLEAVED_PLANES, 1, FB_VISUAL_PSEUDOCOLOR, 8, 16},
  47. { 8, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 0,
  48. FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_PSEUDOCOLOR, 8, 8},
  49. {16, {10, 5, 0}, {5, 5, 0}, {0, 5, 0}, {0, 0, 0}, 0,
  50. FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 4, 4},
  51. {16, {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0}, 0,
  52. FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 4, 4},
  53. {24, {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {0, 0, 0}, 0,
  54. FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 8, 8},
  55. {32, {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {0, 0, 0}, 0,
  56. FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 2, 2},
  57. SVGA_FORMAT_END
  58. };
  59. /* CRT timing register sets */
  60. static const struct vga_regset ark_h_total_regs[] = {{0x00, 0, 7}, {0x41, 7, 7}, VGA_REGSET_END};
  61. static const struct vga_regset ark_h_display_regs[] = {{0x01, 0, 7}, {0x41, 6, 6}, VGA_REGSET_END};
  62. static const struct vga_regset ark_h_blank_start_regs[] = {{0x02, 0, 7}, {0x41, 5, 5}, VGA_REGSET_END};
  63. static const struct vga_regset ark_h_blank_end_regs[] = {{0x03, 0, 4}, {0x05, 7, 7 }, VGA_REGSET_END};
  64. static const struct vga_regset ark_h_sync_start_regs[] = {{0x04, 0, 7}, {0x41, 4, 4}, VGA_REGSET_END};
  65. static const struct vga_regset ark_h_sync_end_regs[] = {{0x05, 0, 4}, VGA_REGSET_END};
  66. static const struct vga_regset ark_v_total_regs[] = {{0x06, 0, 7}, {0x07, 0, 0}, {0x07, 5, 5}, {0x40, 7, 7}, VGA_REGSET_END};
  67. static const struct vga_regset ark_v_display_regs[] = {{0x12, 0, 7}, {0x07, 1, 1}, {0x07, 6, 6}, {0x40, 6, 6}, VGA_REGSET_END};
  68. static const struct vga_regset ark_v_blank_start_regs[] = {{0x15, 0, 7}, {0x07, 3, 3}, {0x09, 5, 5}, {0x40, 5, 5}, VGA_REGSET_END};
  69. // const struct vga_regset ark_v_blank_end_regs[] = {{0x16, 0, 6}, VGA_REGSET_END};
  70. static const struct vga_regset ark_v_blank_end_regs[] = {{0x16, 0, 7}, VGA_REGSET_END};
  71. static const struct vga_regset ark_v_sync_start_regs[] = {{0x10, 0, 7}, {0x07, 2, 2}, {0x07, 7, 7}, {0x40, 4, 4}, VGA_REGSET_END};
  72. static const struct vga_regset ark_v_sync_end_regs[] = {{0x11, 0, 3}, VGA_REGSET_END};
  73. static const struct vga_regset ark_line_compare_regs[] = {{0x18, 0, 7}, {0x07, 4, 4}, {0x09, 6, 6}, VGA_REGSET_END};
  74. static const struct vga_regset ark_start_address_regs[] = {{0x0d, 0, 7}, {0x0c, 0, 7}, {0x40, 0, 2}, VGA_REGSET_END};
  75. static const struct vga_regset ark_offset_regs[] = {{0x13, 0, 7}, {0x41, 3, 3}, VGA_REGSET_END};
  76. static const struct svga_timing_regs ark_timing_regs = {
  77. ark_h_total_regs, ark_h_display_regs, ark_h_blank_start_regs,
  78. ark_h_blank_end_regs, ark_h_sync_start_regs, ark_h_sync_end_regs,
  79. ark_v_total_regs, ark_v_display_regs, ark_v_blank_start_regs,
  80. ark_v_blank_end_regs, ark_v_sync_start_regs, ark_v_sync_end_regs,
  81. };
  82. /* ------------------------------------------------------------------------- */
  83. /* Module parameters */
  84. static char *mode_option __devinitdata = "640x480-8@60";
  85. #ifdef CONFIG_MTRR
  86. static int mtrr = 1;
  87. #endif
  88. MODULE_AUTHOR("(c) 2007 Ondrej Zajicek <santiago@crfreenet.org>");
  89. MODULE_LICENSE("GPL");
  90. MODULE_DESCRIPTION("fbdev driver for ARK 2000PV");
  91. module_param(mode_option, charp, 0444);
  92. MODULE_PARM_DESC(mode_option, "Default video mode ('640x480-8@60', etc)");
  93. module_param_named(mode, mode_option, charp, 0444);
  94. MODULE_PARM_DESC(mode, "Default video mode ('640x480-8@60', etc) (deprecated)");
  95. #ifdef CONFIG_MTRR
  96. module_param(mtrr, int, 0444);
  97. MODULE_PARM_DESC(mtrr, "Enable write-combining with MTRR (1=enable, 0=disable, default=1)");
  98. #endif
  99. static int threshold = 4;
  100. module_param(threshold, int, 0644);
  101. MODULE_PARM_DESC(threshold, "FIFO threshold");
  102. /* ------------------------------------------------------------------------- */
  103. static void arkfb_settile(struct fb_info *info, struct fb_tilemap *map)
  104. {
  105. const u8 *font = map->data;
  106. u8 __iomem *fb = (u8 __iomem *)info->screen_base;
  107. int i, c;
  108. if ((map->width != 8) || (map->height != 16) ||
  109. (map->depth != 1) || (map->length != 256)) {
  110. printk(KERN_ERR "fb%d: unsupported font parameters: width %d, "
  111. "height %d, depth %d, length %d\n", info->node,
  112. map->width, map->height, map->depth, map->length);
  113. return;
  114. }
  115. fb += 2;
  116. for (c = 0; c < map->length; c++) {
  117. for (i = 0; i < map->height; i++) {
  118. fb_writeb(font[i], &fb[i * 4]);
  119. fb_writeb(font[i], &fb[i * 4 + (128 * 8)]);
  120. }
  121. fb += 128;
  122. if ((c % 8) == 7)
  123. fb += 128*8;
  124. font += map->height;
  125. }
  126. }
  127. static void arkfb_tilecursor(struct fb_info *info, struct fb_tilecursor *cursor)
  128. {
  129. struct arkfb_info *par = info->par;
  130. svga_tilecursor(par->state.vgabase, info, cursor);
  131. }
  132. static struct fb_tile_ops arkfb_tile_ops = {
  133. .fb_settile = arkfb_settile,
  134. .fb_tilecopy = svga_tilecopy,
  135. .fb_tilefill = svga_tilefill,
  136. .fb_tileblit = svga_tileblit,
  137. .fb_tilecursor = arkfb_tilecursor,
  138. .fb_get_tilemax = svga_get_tilemax,
  139. };
  140. /* ------------------------------------------------------------------------- */
  141. /* image data is MSB-first, fb structure is MSB-first too */
  142. static inline u32 expand_color(u32 c)
  143. {
  144. return ((c & 1) | ((c & 2) << 7) | ((c & 4) << 14) | ((c & 8) << 21)) * 0xFF;
  145. }
  146. /* arkfb_iplan_imageblit silently assumes that almost everything is 8-pixel aligned */
  147. static void arkfb_iplan_imageblit(struct fb_info *info, const struct fb_image *image)
  148. {
  149. u32 fg = expand_color(image->fg_color);
  150. u32 bg = expand_color(image->bg_color);
  151. const u8 *src1, *src;
  152. u8 __iomem *dst1;
  153. u32 __iomem *dst;
  154. u32 val;
  155. int x, y;
  156. src1 = image->data;
  157. dst1 = info->screen_base + (image->dy * info->fix.line_length)
  158. + ((image->dx / 8) * 4);
  159. for (y = 0; y < image->height; y++) {
  160. src = src1;
  161. dst = (u32 __iomem *) dst1;
  162. for (x = 0; x < image->width; x += 8) {
  163. val = *(src++) * 0x01010101;
  164. val = (val & fg) | (~val & bg);
  165. fb_writel(val, dst++);
  166. }
  167. src1 += image->width / 8;
  168. dst1 += info->fix.line_length;
  169. }
  170. }
  171. /* arkfb_iplan_fillrect silently assumes that almost everything is 8-pixel aligned */
  172. static void arkfb_iplan_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
  173. {
  174. u32 fg = expand_color(rect->color);
  175. u8 __iomem *dst1;
  176. u32 __iomem *dst;
  177. int x, y;
  178. dst1 = info->screen_base + (rect->dy * info->fix.line_length)
  179. + ((rect->dx / 8) * 4);
  180. for (y = 0; y < rect->height; y++) {
  181. dst = (u32 __iomem *) dst1;
  182. for (x = 0; x < rect->width; x += 8) {
  183. fb_writel(fg, dst++);
  184. }
  185. dst1 += info->fix.line_length;
  186. }
  187. }
  188. /* image data is MSB-first, fb structure is high-nibble-in-low-byte-first */
  189. static inline u32 expand_pixel(u32 c)
  190. {
  191. return (((c & 1) << 24) | ((c & 2) << 27) | ((c & 4) << 14) | ((c & 8) << 17) |
  192. ((c & 16) << 4) | ((c & 32) << 7) | ((c & 64) >> 6) | ((c & 128) >> 3)) * 0xF;
  193. }
  194. /* arkfb_cfb4_imageblit silently assumes that almost everything is 8-pixel aligned */
  195. static void arkfb_cfb4_imageblit(struct fb_info *info, const struct fb_image *image)
  196. {
  197. u32 fg = image->fg_color * 0x11111111;
  198. u32 bg = image->bg_color * 0x11111111;
  199. const u8 *src1, *src;
  200. u8 __iomem *dst1;
  201. u32 __iomem *dst;
  202. u32 val;
  203. int x, y;
  204. src1 = image->data;
  205. dst1 = info->screen_base + (image->dy * info->fix.line_length)
  206. + ((image->dx / 8) * 4);
  207. for (y = 0; y < image->height; y++) {
  208. src = src1;
  209. dst = (u32 __iomem *) dst1;
  210. for (x = 0; x < image->width; x += 8) {
  211. val = expand_pixel(*(src++));
  212. val = (val & fg) | (~val & bg);
  213. fb_writel(val, dst++);
  214. }
  215. src1 += image->width / 8;
  216. dst1 += info->fix.line_length;
  217. }
  218. }
  219. static void arkfb_imageblit(struct fb_info *info, const struct fb_image *image)
  220. {
  221. if ((info->var.bits_per_pixel == 4) && (image->depth == 1)
  222. && ((image->width % 8) == 0) && ((image->dx % 8) == 0)) {
  223. if (info->fix.type == FB_TYPE_INTERLEAVED_PLANES)
  224. arkfb_iplan_imageblit(info, image);
  225. else
  226. arkfb_cfb4_imageblit(info, image);
  227. } else
  228. cfb_imageblit(info, image);
  229. }
  230. static void arkfb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
  231. {
  232. if ((info->var.bits_per_pixel == 4)
  233. && ((rect->width % 8) == 0) && ((rect->dx % 8) == 0)
  234. && (info->fix.type == FB_TYPE_INTERLEAVED_PLANES))
  235. arkfb_iplan_fillrect(info, rect);
  236. else
  237. cfb_fillrect(info, rect);
  238. }
  239. /* ------------------------------------------------------------------------- */
  240. enum
  241. {
  242. DAC_PSEUDO8_8,
  243. DAC_RGB1555_8,
  244. DAC_RGB0565_8,
  245. DAC_RGB0888_8,
  246. DAC_RGB8888_8,
  247. DAC_PSEUDO8_16,
  248. DAC_RGB1555_16,
  249. DAC_RGB0565_16,
  250. DAC_RGB0888_16,
  251. DAC_RGB8888_16,
  252. DAC_MAX
  253. };
  254. struct dac_ops {
  255. int (*dac_get_mode)(struct dac_info *info);
  256. int (*dac_set_mode)(struct dac_info *info, int mode);
  257. int (*dac_get_freq)(struct dac_info *info, int channel);
  258. int (*dac_set_freq)(struct dac_info *info, int channel, u32 freq);
  259. void (*dac_release)(struct dac_info *info);
  260. };
  261. typedef void (*dac_read_regs_t)(void *data, u8 *code, int count);
  262. typedef void (*dac_write_regs_t)(void *data, u8 *code, int count);
  263. struct dac_info
  264. {
  265. struct dac_ops *dacops;
  266. dac_read_regs_t dac_read_regs;
  267. dac_write_regs_t dac_write_regs;
  268. void *data;
  269. };
  270. static inline u8 dac_read_reg(struct dac_info *info, u8 reg)
  271. {
  272. u8 code[2] = {reg, 0};
  273. info->dac_read_regs(info->data, code, 1);
  274. return code[1];
  275. }
  276. static inline void dac_read_regs(struct dac_info *info, u8 *code, int count)
  277. {
  278. info->dac_read_regs(info->data, code, count);
  279. }
  280. static inline void dac_write_reg(struct dac_info *info, u8 reg, u8 val)
  281. {
  282. u8 code[2] = {reg, val};
  283. info->dac_write_regs(info->data, code, 1);
  284. }
  285. static inline void dac_write_regs(struct dac_info *info, u8 *code, int count)
  286. {
  287. info->dac_write_regs(info->data, code, count);
  288. }
  289. static inline int dac_set_mode(struct dac_info *info, int mode)
  290. {
  291. return info->dacops->dac_set_mode(info, mode);
  292. }
  293. static inline int dac_set_freq(struct dac_info *info, int channel, u32 freq)
  294. {
  295. return info->dacops->dac_set_freq(info, channel, freq);
  296. }
  297. static inline void dac_release(struct dac_info *info)
  298. {
  299. info->dacops->dac_release(info);
  300. }
  301. /* ------------------------------------------------------------------------- */
  302. /* ICS5342 DAC */
  303. struct ics5342_info
  304. {
  305. struct dac_info dac;
  306. u8 mode;
  307. };
  308. #define DAC_PAR(info) ((struct ics5342_info *) info)
  309. /* LSB is set to distinguish unused slots */
  310. static const u8 ics5342_mode_table[DAC_MAX] = {
  311. [DAC_PSEUDO8_8] = 0x01, [DAC_RGB1555_8] = 0x21, [DAC_RGB0565_8] = 0x61,
  312. [DAC_RGB0888_8] = 0x41, [DAC_PSEUDO8_16] = 0x11, [DAC_RGB1555_16] = 0x31,
  313. [DAC_RGB0565_16] = 0x51, [DAC_RGB0888_16] = 0x91, [DAC_RGB8888_16] = 0x71
  314. };
  315. static int ics5342_set_mode(struct dac_info *info, int mode)
  316. {
  317. u8 code;
  318. if (mode >= DAC_MAX)
  319. return -EINVAL;
  320. code = ics5342_mode_table[mode];
  321. if (! code)
  322. return -EINVAL;
  323. dac_write_reg(info, 6, code & 0xF0);
  324. DAC_PAR(info)->mode = mode;
  325. return 0;
  326. }
  327. static const struct svga_pll ics5342_pll = {3, 129, 3, 33, 0, 3,
  328. 60000, 250000, 14318};
  329. /* pd4 - allow only posdivider 4 (r=2) */
  330. static const struct svga_pll ics5342_pll_pd4 = {3, 129, 3, 33, 2, 2,
  331. 60000, 335000, 14318};
  332. /* 270 MHz should be upper bound for VCO clock according to specs,
  333. but that is too restrictive in pd4 case */
  334. static int ics5342_set_freq(struct dac_info *info, int channel, u32 freq)
  335. {
  336. u16 m, n, r;
  337. /* only postdivider 4 (r=2) is valid in mode DAC_PSEUDO8_16 */
  338. int rv = svga_compute_pll((DAC_PAR(info)->mode == DAC_PSEUDO8_16)
  339. ? &ics5342_pll_pd4 : &ics5342_pll,
  340. freq, &m, &n, &r, 0);
  341. if (rv < 0) {
  342. return -EINVAL;
  343. } else {
  344. u8 code[6] = {4, 3, 5, m-2, 5, (n-2) | (r << 5)};
  345. dac_write_regs(info, code, 3);
  346. return 0;
  347. }
  348. }
  349. static void ics5342_release(struct dac_info *info)
  350. {
  351. ics5342_set_mode(info, DAC_PSEUDO8_8);
  352. kfree(info);
  353. }
  354. static struct dac_ops ics5342_ops = {
  355. .dac_set_mode = ics5342_set_mode,
  356. .dac_set_freq = ics5342_set_freq,
  357. .dac_release = ics5342_release
  358. };
  359. static struct dac_info * ics5342_init(dac_read_regs_t drr, dac_write_regs_t dwr, void *data)
  360. {
  361. struct dac_info *info = kzalloc(sizeof(struct ics5342_info), GFP_KERNEL);
  362. if (! info)
  363. return NULL;
  364. info->dacops = &ics5342_ops;
  365. info->dac_read_regs = drr;
  366. info->dac_write_regs = dwr;
  367. info->data = data;
  368. DAC_PAR(info)->mode = DAC_PSEUDO8_8; /* estimation */
  369. return info;
  370. }
  371. /* ------------------------------------------------------------------------- */
  372. static unsigned short dac_regs[4] = {0x3c8, 0x3c9, 0x3c6, 0x3c7};
  373. static void ark_dac_read_regs(void *data, u8 *code, int count)
  374. {
  375. struct fb_info *info = data;
  376. struct arkfb_info *par;
  377. u8 regval;
  378. par = info->par;
  379. regval = vga_rseq(par->state.vgabase, 0x1C);
  380. while (count != 0)
  381. {
  382. vga_wseq(par->state.vgabase, 0x1C, regval | (code[0] & 4 ? 0x80 : 0));
  383. code[1] = vga_r(par->state.vgabase, dac_regs[code[0] & 3]);
  384. count--;
  385. code += 2;
  386. }
  387. vga_wseq(par->state.vgabase, 0x1C, regval);
  388. }
  389. static void ark_dac_write_regs(void *data, u8 *code, int count)
  390. {
  391. struct fb_info *info = data;
  392. struct arkfb_info *par;
  393. u8 regval;
  394. par = info->par;
  395. regval = vga_rseq(par->state.vgabase, 0x1C);
  396. while (count != 0)
  397. {
  398. vga_wseq(par->state.vgabase, 0x1C, regval | (code[0] & 4 ? 0x80 : 0));
  399. vga_w(par->state.vgabase, dac_regs[code[0] & 3], code[1]);
  400. count--;
  401. code += 2;
  402. }
  403. vga_wseq(par->state.vgabase, 0x1C, regval);
  404. }
  405. static void ark_set_pixclock(struct fb_info *info, u32 pixclock)
  406. {
  407. struct arkfb_info *par = info->par;
  408. u8 regval;
  409. int rv = dac_set_freq(par->dac, 0, 1000000000 / pixclock);
  410. if (rv < 0) {
  411. printk(KERN_ERR "fb%d: cannot set requested pixclock, keeping old value\n", info->node);
  412. return;
  413. }
  414. /* Set VGA misc register */
  415. regval = vga_r(par->state.vgabase, VGA_MIS_R);
  416. vga_w(par->state.vgabase, VGA_MIS_W, regval | VGA_MIS_ENB_PLL_LOAD);
  417. }
  418. /* Open framebuffer */
  419. static int arkfb_open(struct fb_info *info, int user)
  420. {
  421. struct arkfb_info *par = info->par;
  422. mutex_lock(&(par->open_lock));
  423. if (par->ref_count == 0) {
  424. void __iomem *vgabase = par->state.vgabase;
  425. memset(&(par->state), 0, sizeof(struct vgastate));
  426. par->state.vgabase = vgabase;
  427. par->state.flags = VGA_SAVE_MODE | VGA_SAVE_FONTS | VGA_SAVE_CMAP;
  428. par->state.num_crtc = 0x60;
  429. par->state.num_seq = 0x30;
  430. save_vga(&(par->state));
  431. }
  432. par->ref_count++;
  433. mutex_unlock(&(par->open_lock));
  434. return 0;
  435. }
  436. /* Close framebuffer */
  437. static int arkfb_release(struct fb_info *info, int user)
  438. {
  439. struct arkfb_info *par = info->par;
  440. mutex_lock(&(par->open_lock));
  441. if (par->ref_count == 0) {
  442. mutex_unlock(&(par->open_lock));
  443. return -EINVAL;
  444. }
  445. if (par->ref_count == 1) {
  446. restore_vga(&(par->state));
  447. dac_set_mode(par->dac, DAC_PSEUDO8_8);
  448. }
  449. par->ref_count--;
  450. mutex_unlock(&(par->open_lock));
  451. return 0;
  452. }
  453. /* Validate passed in var */
  454. static int arkfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  455. {
  456. int rv, mem, step;
  457. /* Find appropriate format */
  458. rv = svga_match_format (arkfb_formats, var, NULL);
  459. if (rv < 0)
  460. {
  461. printk(KERN_ERR "fb%d: unsupported mode requested\n", info->node);
  462. return rv;
  463. }
  464. /* Do not allow to have real resoulution larger than virtual */
  465. if (var->xres > var->xres_virtual)
  466. var->xres_virtual = var->xres;
  467. if (var->yres > var->yres_virtual)
  468. var->yres_virtual = var->yres;
  469. /* Round up xres_virtual to have proper alignment of lines */
  470. step = arkfb_formats[rv].xresstep - 1;
  471. var->xres_virtual = (var->xres_virtual+step) & ~step;
  472. /* Check whether have enough memory */
  473. mem = ((var->bits_per_pixel * var->xres_virtual) >> 3) * var->yres_virtual;
  474. if (mem > info->screen_size)
  475. {
  476. printk(KERN_ERR "fb%d: not enough framebuffer memory (%d kB requested , %d kB available)\n", info->node, mem >> 10, (unsigned int) (info->screen_size >> 10));
  477. return -EINVAL;
  478. }
  479. rv = svga_check_timings (&ark_timing_regs, var, info->node);
  480. if (rv < 0)
  481. {
  482. printk(KERN_ERR "fb%d: invalid timings requested\n", info->node);
  483. return rv;
  484. }
  485. /* Interlaced mode is broken */
  486. if (var->vmode & FB_VMODE_INTERLACED)
  487. return -EINVAL;
  488. return 0;
  489. }
  490. /* Set video mode from par */
  491. static int arkfb_set_par(struct fb_info *info)
  492. {
  493. struct arkfb_info *par = info->par;
  494. u32 value, mode, hmul, hdiv, offset_value, screen_size;
  495. u32 bpp = info->var.bits_per_pixel;
  496. u8 regval;
  497. if (bpp != 0) {
  498. info->fix.ypanstep = 1;
  499. info->fix.line_length = (info->var.xres_virtual * bpp) / 8;
  500. info->flags &= ~FBINFO_MISC_TILEBLITTING;
  501. info->tileops = NULL;
  502. /* in 4bpp supports 8p wide tiles only, any tiles otherwise */
  503. info->pixmap.blit_x = (bpp == 4) ? (1 << (8 - 1)) : (~(u32)0);
  504. info->pixmap.blit_y = ~(u32)0;
  505. offset_value = (info->var.xres_virtual * bpp) / 64;
  506. screen_size = info->var.yres_virtual * info->fix.line_length;
  507. } else {
  508. info->fix.ypanstep = 16;
  509. info->fix.line_length = 0;
  510. info->flags |= FBINFO_MISC_TILEBLITTING;
  511. info->tileops = &arkfb_tile_ops;
  512. /* supports 8x16 tiles only */
  513. info->pixmap.blit_x = 1 << (8 - 1);
  514. info->pixmap.blit_y = 1 << (16 - 1);
  515. offset_value = info->var.xres_virtual / 16;
  516. screen_size = (info->var.xres_virtual * info->var.yres_virtual) / 64;
  517. }
  518. info->var.xoffset = 0;
  519. info->var.yoffset = 0;
  520. info->var.activate = FB_ACTIVATE_NOW;
  521. /* Unlock registers */
  522. svga_wcrt_mask(par->state.vgabase, 0x11, 0x00, 0x80);
  523. /* Blank screen and turn off sync */
  524. svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20);
  525. svga_wcrt_mask(par->state.vgabase, 0x17, 0x00, 0x80);
  526. /* Set default values */
  527. svga_set_default_gfx_regs(par->state.vgabase);
  528. svga_set_default_atc_regs(par->state.vgabase);
  529. svga_set_default_seq_regs(par->state.vgabase);
  530. svga_set_default_crt_regs(par->state.vgabase);
  531. svga_wcrt_multi(par->state.vgabase, ark_line_compare_regs, 0xFFFFFFFF);
  532. svga_wcrt_multi(par->state.vgabase, ark_start_address_regs, 0);
  533. /* ARK specific initialization */
  534. svga_wseq_mask(par->state.vgabase, 0x10, 0x1F, 0x1F); /* enable linear framebuffer and full memory access */
  535. svga_wseq_mask(par->state.vgabase, 0x12, 0x03, 0x03); /* 4 MB linear framebuffer size */
  536. vga_wseq(par->state.vgabase, 0x13, info->fix.smem_start >> 16);
  537. vga_wseq(par->state.vgabase, 0x14, info->fix.smem_start >> 24);
  538. vga_wseq(par->state.vgabase, 0x15, 0);
  539. vga_wseq(par->state.vgabase, 0x16, 0);
  540. /* Set the FIFO threshold register */
  541. /* It is fascinating way to store 5-bit value in 8-bit register */
  542. regval = 0x10 | ((threshold & 0x0E) >> 1) | (threshold & 0x01) << 7 | (threshold & 0x10) << 1;
  543. vga_wseq(par->state.vgabase, 0x18, regval);
  544. /* Set the offset register */
  545. pr_debug("fb%d: offset register : %d\n", info->node, offset_value);
  546. svga_wcrt_multi(par->state.vgabase, ark_offset_regs, offset_value);
  547. /* fix for hi-res textmode */
  548. svga_wcrt_mask(par->state.vgabase, 0x40, 0x08, 0x08);
  549. if (info->var.vmode & FB_VMODE_DOUBLE)
  550. svga_wcrt_mask(par->state.vgabase, 0x09, 0x80, 0x80);
  551. else
  552. svga_wcrt_mask(par->state.vgabase, 0x09, 0x00, 0x80);
  553. if (info->var.vmode & FB_VMODE_INTERLACED)
  554. svga_wcrt_mask(par->state.vgabase, 0x44, 0x04, 0x04);
  555. else
  556. svga_wcrt_mask(par->state.vgabase, 0x44, 0x00, 0x04);
  557. hmul = 1;
  558. hdiv = 1;
  559. mode = svga_match_format(arkfb_formats, &(info->var), &(info->fix));
  560. /* Set mode-specific register values */
  561. switch (mode) {
  562. case 0:
  563. pr_debug("fb%d: text mode\n", info->node);
  564. svga_set_textmode_vga_regs(par->state.vgabase);
  565. vga_wseq(par->state.vgabase, 0x11, 0x10); /* basic VGA mode */
  566. svga_wcrt_mask(par->state.vgabase, 0x46, 0x00, 0x04); /* 8bit pixel path */
  567. dac_set_mode(par->dac, DAC_PSEUDO8_8);
  568. break;
  569. case 1:
  570. pr_debug("fb%d: 4 bit pseudocolor\n", info->node);
  571. vga_wgfx(par->state.vgabase, VGA_GFX_MODE, 0x40);
  572. vga_wseq(par->state.vgabase, 0x11, 0x10); /* basic VGA mode */
  573. svga_wcrt_mask(par->state.vgabase, 0x46, 0x00, 0x04); /* 8bit pixel path */
  574. dac_set_mode(par->dac, DAC_PSEUDO8_8);
  575. break;
  576. case 2:
  577. pr_debug("fb%d: 4 bit pseudocolor, planar\n", info->node);
  578. vga_wseq(par->state.vgabase, 0x11, 0x10); /* basic VGA mode */
  579. svga_wcrt_mask(par->state.vgabase, 0x46, 0x00, 0x04); /* 8bit pixel path */
  580. dac_set_mode(par->dac, DAC_PSEUDO8_8);
  581. break;
  582. case 3:
  583. pr_debug("fb%d: 8 bit pseudocolor\n", info->node);
  584. vga_wseq(par->state.vgabase, 0x11, 0x16); /* 8bpp accel mode */
  585. if (info->var.pixclock > 20000) {
  586. pr_debug("fb%d: not using multiplex\n", info->node);
  587. svga_wcrt_mask(par->state.vgabase, 0x46, 0x00, 0x04); /* 8bit pixel path */
  588. dac_set_mode(par->dac, DAC_PSEUDO8_8);
  589. } else {
  590. pr_debug("fb%d: using multiplex\n", info->node);
  591. svga_wcrt_mask(par->state.vgabase, 0x46, 0x04, 0x04); /* 16bit pixel path */
  592. dac_set_mode(par->dac, DAC_PSEUDO8_16);
  593. hdiv = 2;
  594. }
  595. break;
  596. case 4:
  597. pr_debug("fb%d: 5/5/5 truecolor\n", info->node);
  598. vga_wseq(par->state.vgabase, 0x11, 0x1A); /* 16bpp accel mode */
  599. svga_wcrt_mask(par->state.vgabase, 0x46, 0x04, 0x04); /* 16bit pixel path */
  600. dac_set_mode(par->dac, DAC_RGB1555_16);
  601. break;
  602. case 5:
  603. pr_debug("fb%d: 5/6/5 truecolor\n", info->node);
  604. vga_wseq(par->state.vgabase, 0x11, 0x1A); /* 16bpp accel mode */
  605. svga_wcrt_mask(par->state.vgabase, 0x46, 0x04, 0x04); /* 16bit pixel path */
  606. dac_set_mode(par->dac, DAC_RGB0565_16);
  607. break;
  608. case 6:
  609. pr_debug("fb%d: 8/8/8 truecolor\n", info->node);
  610. vga_wseq(par->state.vgabase, 0x11, 0x16); /* 8bpp accel mode ??? */
  611. svga_wcrt_mask(par->state.vgabase, 0x46, 0x04, 0x04); /* 16bit pixel path */
  612. dac_set_mode(par->dac, DAC_RGB0888_16);
  613. hmul = 3;
  614. hdiv = 2;
  615. break;
  616. case 7:
  617. pr_debug("fb%d: 8/8/8/8 truecolor\n", info->node);
  618. vga_wseq(par->state.vgabase, 0x11, 0x1E); /* 32bpp accel mode */
  619. svga_wcrt_mask(par->state.vgabase, 0x46, 0x04, 0x04); /* 16bit pixel path */
  620. dac_set_mode(par->dac, DAC_RGB8888_16);
  621. hmul = 2;
  622. break;
  623. default:
  624. printk(KERN_ERR "fb%d: unsupported mode - bug\n", info->node);
  625. return -EINVAL;
  626. }
  627. ark_set_pixclock(info, (hdiv * info->var.pixclock) / hmul);
  628. svga_set_timings(par->state.vgabase, &ark_timing_regs, &(info->var), hmul, hdiv,
  629. (info->var.vmode & FB_VMODE_DOUBLE) ? 2 : 1,
  630. (info->var.vmode & FB_VMODE_INTERLACED) ? 2 : 1,
  631. hmul, info->node);
  632. /* Set interlaced mode start/end register */
  633. value = info->var.xres + info->var.left_margin + info->var.right_margin + info->var.hsync_len;
  634. value = ((value * hmul / hdiv) / 8) - 5;
  635. vga_wcrt(par->state.vgabase, 0x42, (value + 1) / 2);
  636. memset_io(info->screen_base, 0x00, screen_size);
  637. /* Device and screen back on */
  638. svga_wcrt_mask(par->state.vgabase, 0x17, 0x80, 0x80);
  639. svga_wseq_mask(par->state.vgabase, 0x01, 0x00, 0x20);
  640. return 0;
  641. }
  642. /* Set a colour register */
  643. static int arkfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  644. u_int transp, struct fb_info *fb)
  645. {
  646. switch (fb->var.bits_per_pixel) {
  647. case 0:
  648. case 4:
  649. if (regno >= 16)
  650. return -EINVAL;
  651. if ((fb->var.bits_per_pixel == 4) &&
  652. (fb->var.nonstd == 0)) {
  653. outb(0xF0, VGA_PEL_MSK);
  654. outb(regno*16, VGA_PEL_IW);
  655. } else {
  656. outb(0x0F, VGA_PEL_MSK);
  657. outb(regno, VGA_PEL_IW);
  658. }
  659. outb(red >> 10, VGA_PEL_D);
  660. outb(green >> 10, VGA_PEL_D);
  661. outb(blue >> 10, VGA_PEL_D);
  662. break;
  663. case 8:
  664. if (regno >= 256)
  665. return -EINVAL;
  666. outb(0xFF, VGA_PEL_MSK);
  667. outb(regno, VGA_PEL_IW);
  668. outb(red >> 10, VGA_PEL_D);
  669. outb(green >> 10, VGA_PEL_D);
  670. outb(blue >> 10, VGA_PEL_D);
  671. break;
  672. case 16:
  673. if (regno >= 16)
  674. return 0;
  675. if (fb->var.green.length == 5)
  676. ((u32*)fb->pseudo_palette)[regno] = ((red & 0xF800) >> 1) |
  677. ((green & 0xF800) >> 6) | ((blue & 0xF800) >> 11);
  678. else if (fb->var.green.length == 6)
  679. ((u32*)fb->pseudo_palette)[regno] = (red & 0xF800) |
  680. ((green & 0xFC00) >> 5) | ((blue & 0xF800) >> 11);
  681. else
  682. return -EINVAL;
  683. break;
  684. case 24:
  685. case 32:
  686. if (regno >= 16)
  687. return 0;
  688. ((u32*)fb->pseudo_palette)[regno] = ((red & 0xFF00) << 8) |
  689. (green & 0xFF00) | ((blue & 0xFF00) >> 8);
  690. break;
  691. default:
  692. return -EINVAL;
  693. }
  694. return 0;
  695. }
  696. /* Set the display blanking state */
  697. static int arkfb_blank(int blank_mode, struct fb_info *info)
  698. {
  699. struct arkfb_info *par = info->par;
  700. switch (blank_mode) {
  701. case FB_BLANK_UNBLANK:
  702. pr_debug("fb%d: unblank\n", info->node);
  703. svga_wseq_mask(par->state.vgabase, 0x01, 0x00, 0x20);
  704. svga_wcrt_mask(par->state.vgabase, 0x17, 0x80, 0x80);
  705. break;
  706. case FB_BLANK_NORMAL:
  707. pr_debug("fb%d: blank\n", info->node);
  708. svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20);
  709. svga_wcrt_mask(par->state.vgabase, 0x17, 0x80, 0x80);
  710. break;
  711. case FB_BLANK_POWERDOWN:
  712. case FB_BLANK_HSYNC_SUSPEND:
  713. case FB_BLANK_VSYNC_SUSPEND:
  714. pr_debug("fb%d: sync down\n", info->node);
  715. svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20);
  716. svga_wcrt_mask(par->state.vgabase, 0x17, 0x00, 0x80);
  717. break;
  718. }
  719. return 0;
  720. }
  721. /* Pan the display */
  722. static int arkfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
  723. {
  724. struct arkfb_info *par = info->par;
  725. unsigned int offset;
  726. /* Calculate the offset */
  727. if (var->bits_per_pixel == 0) {
  728. offset = (var->yoffset / 16) * (var->xres_virtual / 2) + (var->xoffset / 2);
  729. offset = offset >> 2;
  730. } else {
  731. offset = (var->yoffset * info->fix.line_length) +
  732. (var->xoffset * var->bits_per_pixel / 8);
  733. offset = offset >> ((var->bits_per_pixel == 4) ? 2 : 3);
  734. }
  735. /* Set the offset */
  736. svga_wcrt_multi(par->state.vgabase, ark_start_address_regs, offset);
  737. return 0;
  738. }
  739. /* ------------------------------------------------------------------------- */
  740. /* Frame buffer operations */
  741. static struct fb_ops arkfb_ops = {
  742. .owner = THIS_MODULE,
  743. .fb_open = arkfb_open,
  744. .fb_release = arkfb_release,
  745. .fb_check_var = arkfb_check_var,
  746. .fb_set_par = arkfb_set_par,
  747. .fb_setcolreg = arkfb_setcolreg,
  748. .fb_blank = arkfb_blank,
  749. .fb_pan_display = arkfb_pan_display,
  750. .fb_fillrect = arkfb_fillrect,
  751. .fb_copyarea = cfb_copyarea,
  752. .fb_imageblit = arkfb_imageblit,
  753. .fb_get_caps = svga_get_caps,
  754. };
  755. /* ------------------------------------------------------------------------- */
  756. /* PCI probe */
  757. static int __devinit ark_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
  758. {
  759. struct pci_bus_region bus_reg;
  760. struct resource vga_res;
  761. struct fb_info *info;
  762. struct arkfb_info *par;
  763. int rc;
  764. u8 regval;
  765. /* Ignore secondary VGA device because there is no VGA arbitration */
  766. if (! svga_primary_device(dev)) {
  767. dev_info(&(dev->dev), "ignoring secondary device\n");
  768. return -ENODEV;
  769. }
  770. /* Allocate and fill driver data structure */
  771. info = framebuffer_alloc(sizeof(struct arkfb_info), &(dev->dev));
  772. if (! info) {
  773. dev_err(&(dev->dev), "cannot allocate memory\n");
  774. return -ENOMEM;
  775. }
  776. par = info->par;
  777. mutex_init(&par->open_lock);
  778. info->flags = FBINFO_PARTIAL_PAN_OK | FBINFO_HWACCEL_YPAN;
  779. info->fbops = &arkfb_ops;
  780. /* Prepare PCI device */
  781. rc = pci_enable_device(dev);
  782. if (rc < 0) {
  783. dev_err(info->device, "cannot enable PCI device\n");
  784. goto err_enable_device;
  785. }
  786. rc = pci_request_regions(dev, "arkfb");
  787. if (rc < 0) {
  788. dev_err(info->device, "cannot reserve framebuffer region\n");
  789. goto err_request_regions;
  790. }
  791. par->dac = ics5342_init(ark_dac_read_regs, ark_dac_write_regs, info);
  792. if (! par->dac) {
  793. rc = -ENOMEM;
  794. dev_err(info->device, "RAMDAC initialization failed\n");
  795. goto err_dac;
  796. }
  797. info->fix.smem_start = pci_resource_start(dev, 0);
  798. info->fix.smem_len = pci_resource_len(dev, 0);
  799. /* Map physical IO memory address into kernel space */
  800. info->screen_base = pci_iomap(dev, 0, 0);
  801. if (! info->screen_base) {
  802. rc = -ENOMEM;
  803. dev_err(info->device, "iomap for framebuffer failed\n");
  804. goto err_iomap;
  805. }
  806. bus_reg.start = 0;
  807. bus_reg.end = 64 * 1024;
  808. vga_res.flags = IORESOURCE_IO;
  809. pcibios_bus_to_resource(dev, &vga_res, &bus_reg);
  810. par->state.vgabase = (void __iomem *) vga_res.start;
  811. /* FIXME get memsize */
  812. regval = vga_rseq(par->state.vgabase, 0x10);
  813. info->screen_size = (1 << (regval >> 6)) << 20;
  814. info->fix.smem_len = info->screen_size;
  815. strcpy(info->fix.id, "ARK 2000PV");
  816. info->fix.mmio_start = 0;
  817. info->fix.mmio_len = 0;
  818. info->fix.type = FB_TYPE_PACKED_PIXELS;
  819. info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
  820. info->fix.ypanstep = 0;
  821. info->fix.accel = FB_ACCEL_NONE;
  822. info->pseudo_palette = (void*) (par->pseudo_palette);
  823. /* Prepare startup mode */
  824. rc = fb_find_mode(&(info->var), info, mode_option, NULL, 0, NULL, 8);
  825. if (! ((rc == 1) || (rc == 2))) {
  826. rc = -EINVAL;
  827. dev_err(info->device, "mode %s not found\n", mode_option);
  828. goto err_find_mode;
  829. }
  830. rc = fb_alloc_cmap(&info->cmap, 256, 0);
  831. if (rc < 0) {
  832. dev_err(info->device, "cannot allocate colormap\n");
  833. goto err_alloc_cmap;
  834. }
  835. rc = register_framebuffer(info);
  836. if (rc < 0) {
  837. dev_err(info->device, "cannot register framebugger\n");
  838. goto err_reg_fb;
  839. }
  840. printk(KERN_INFO "fb%d: %s on %s, %d MB RAM\n", info->node, info->fix.id,
  841. pci_name(dev), info->fix.smem_len >> 20);
  842. /* Record a reference to the driver data */
  843. pci_set_drvdata(dev, info);
  844. #ifdef CONFIG_MTRR
  845. if (mtrr) {
  846. par->mtrr_reg = -1;
  847. par->mtrr_reg = mtrr_add(info->fix.smem_start, info->fix.smem_len, MTRR_TYPE_WRCOMB, 1);
  848. }
  849. #endif
  850. return 0;
  851. /* Error handling */
  852. err_reg_fb:
  853. fb_dealloc_cmap(&info->cmap);
  854. err_alloc_cmap:
  855. err_find_mode:
  856. pci_iounmap(dev, info->screen_base);
  857. err_iomap:
  858. dac_release(par->dac);
  859. err_dac:
  860. pci_release_regions(dev);
  861. err_request_regions:
  862. /* pci_disable_device(dev); */
  863. err_enable_device:
  864. framebuffer_release(info);
  865. return rc;
  866. }
  867. /* PCI remove */
  868. static void __devexit ark_pci_remove(struct pci_dev *dev)
  869. {
  870. struct fb_info *info = pci_get_drvdata(dev);
  871. if (info) {
  872. struct arkfb_info *par = info->par;
  873. #ifdef CONFIG_MTRR
  874. if (par->mtrr_reg >= 0) {
  875. mtrr_del(par->mtrr_reg, 0, 0);
  876. par->mtrr_reg = -1;
  877. }
  878. #endif
  879. dac_release(par->dac);
  880. unregister_framebuffer(info);
  881. fb_dealloc_cmap(&info->cmap);
  882. pci_iounmap(dev, info->screen_base);
  883. pci_release_regions(dev);
  884. /* pci_disable_device(dev); */
  885. pci_set_drvdata(dev, NULL);
  886. framebuffer_release(info);
  887. }
  888. }
  889. #ifdef CONFIG_PM
  890. /* PCI suspend */
  891. static int ark_pci_suspend (struct pci_dev* dev, pm_message_t state)
  892. {
  893. struct fb_info *info = pci_get_drvdata(dev);
  894. struct arkfb_info *par = info->par;
  895. dev_info(info->device, "suspend\n");
  896. console_lock();
  897. mutex_lock(&(par->open_lock));
  898. if ((state.event == PM_EVENT_FREEZE) || (par->ref_count == 0)) {
  899. mutex_unlock(&(par->open_lock));
  900. console_unlock();
  901. return 0;
  902. }
  903. fb_set_suspend(info, 1);
  904. pci_save_state(dev);
  905. pci_disable_device(dev);
  906. pci_set_power_state(dev, pci_choose_state(dev, state));
  907. mutex_unlock(&(par->open_lock));
  908. console_unlock();
  909. return 0;
  910. }
  911. /* PCI resume */
  912. static int ark_pci_resume (struct pci_dev* dev)
  913. {
  914. struct fb_info *info = pci_get_drvdata(dev);
  915. struct arkfb_info *par = info->par;
  916. dev_info(info->device, "resume\n");
  917. console_lock();
  918. mutex_lock(&(par->open_lock));
  919. if (par->ref_count == 0)
  920. goto fail;
  921. pci_set_power_state(dev, PCI_D0);
  922. pci_restore_state(dev);
  923. if (pci_enable_device(dev))
  924. goto fail;
  925. pci_set_master(dev);
  926. arkfb_set_par(info);
  927. fb_set_suspend(info, 0);
  928. fail:
  929. mutex_unlock(&(par->open_lock));
  930. console_unlock();
  931. return 0;
  932. }
  933. #else
  934. #define ark_pci_suspend NULL
  935. #define ark_pci_resume NULL
  936. #endif /* CONFIG_PM */
  937. /* List of boards that we are trying to support */
  938. static struct pci_device_id ark_devices[] __devinitdata = {
  939. {PCI_DEVICE(0xEDD8, 0xA099)},
  940. {0, 0, 0, 0, 0, 0, 0}
  941. };
  942. MODULE_DEVICE_TABLE(pci, ark_devices);
  943. static struct pci_driver arkfb_pci_driver = {
  944. .name = "arkfb",
  945. .id_table = ark_devices,
  946. .probe = ark_pci_probe,
  947. .remove = __devexit_p(ark_pci_remove),
  948. .suspend = ark_pci_suspend,
  949. .resume = ark_pci_resume,
  950. };
  951. /* Cleanup */
  952. static void __exit arkfb_cleanup(void)
  953. {
  954. pr_debug("arkfb: cleaning up\n");
  955. pci_unregister_driver(&arkfb_pci_driver);
  956. }
  957. /* Driver Initialisation */
  958. static int __init arkfb_init(void)
  959. {
  960. #ifndef MODULE
  961. char *option = NULL;
  962. if (fb_get_options("arkfb", &option))
  963. return -ENODEV;
  964. if (option && *option)
  965. mode_option = option;
  966. #endif
  967. pr_debug("arkfb: initializing\n");
  968. return pci_register_driver(&arkfb_pci_driver);
  969. }
  970. module_init(arkfb_init);
  971. module_exit(arkfb_cleanup);