arkfb.c 32 KB

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