lxfb_core.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. /*
  2. * Geode LX framebuffer driver.
  3. *
  4. * Copyright (C) 2007 Advanced Micro Devices, Inc.
  5. * Built from gxfb (which is Copyright (C) 2006 Arcom Control Systems Ltd.)
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2 of the License, or (at your
  10. * option) any later version.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/kernel.h>
  14. #include <linux/errno.h>
  15. #include <linux/string.h>
  16. #include <linux/console.h>
  17. #include <linux/mm.h>
  18. #include <linux/suspend.h>
  19. #include <linux/delay.h>
  20. #include <linux/fb.h>
  21. #include <linux/init.h>
  22. #include <linux/pci.h>
  23. #include <linux/uaccess.h>
  24. #include "lxfb.h"
  25. static char *mode_option;
  26. static int noclear, nopanel, nocrt;
  27. static int vram;
  28. static int vt_switch;
  29. /* Most of these modes are sorted in ascending order, but
  30. * since the first entry in this table is the "default" mode,
  31. * we try to make it something sane - 640x480-60 is sane
  32. */
  33. static struct fb_videomode geode_modedb[] __devinitdata = {
  34. /* 640x480-60 */
  35. { NULL, 60, 640, 480, 39682, 48, 8, 25, 2, 88, 2,
  36. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  37. FB_VMODE_NONINTERLACED, 0 },
  38. /* 640x400-70 */
  39. { NULL, 70, 640, 400, 39770, 40, 8, 28, 5, 96, 2,
  40. FB_SYNC_HOR_HIGH_ACT,
  41. FB_VMODE_NONINTERLACED, 0 },
  42. /* 640x480-70 */
  43. { NULL, 70, 640, 480, 35014, 88, 24, 15, 2, 64, 3,
  44. 0, FB_VMODE_NONINTERLACED, 0 },
  45. /* 640x480-72 */
  46. { NULL, 72, 640, 480, 32102, 120, 16, 20, 1, 40, 3,
  47. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  48. FB_VMODE_NONINTERLACED, 0 },
  49. /* 640x480-75 */
  50. { NULL, 75, 640, 480, 31746, 120, 16, 16, 1, 64, 3,
  51. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  52. FB_VMODE_NONINTERLACED, 0 },
  53. /* 640x480-85 */
  54. { NULL, 85, 640, 480, 27780, 80, 56, 25, 1, 56, 3,
  55. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  56. FB_VMODE_NONINTERLACED, 0 },
  57. /* 640x480-90 */
  58. { NULL, 90, 640, 480, 26392, 96, 32, 22, 1, 64, 3,
  59. 0, FB_VMODE_NONINTERLACED, 0 },
  60. /* 640x480-100 */
  61. { NULL, 100, 640, 480, 23167, 104, 40, 25, 1, 64, 3,
  62. 0, FB_VMODE_NONINTERLACED, 0 },
  63. /* 640x480-60 */
  64. { NULL, 60, 640, 480, 39682, 48, 16, 25, 10, 88, 2,
  65. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  66. FB_VMODE_NONINTERLACED, 0 },
  67. /* 800x600-56 */
  68. { NULL, 56, 800, 600, 27901, 128, 24, 22, 1, 72, 2,
  69. 0, FB_VMODE_NONINTERLACED, 0 },
  70. /* 800x600-60 */
  71. { NULL, 60, 800, 600, 25131, 72, 32, 23, 1, 136, 4,
  72. 0, FB_VMODE_NONINTERLACED, 0 },
  73. /* 800x600-70 */
  74. { NULL, 70, 800, 600, 21873, 120, 40, 21, 4, 80, 3,
  75. 0, FB_VMODE_NONINTERLACED, 0 },
  76. /* 800x600-72 */
  77. { NULL, 72, 800, 600, 20052, 64, 56, 23, 37, 120, 6,
  78. 0, FB_VMODE_NONINTERLACED, 0 },
  79. /* 800x600-75 */
  80. { NULL, 75, 800, 600, 20202, 160, 16, 21, 1, 80, 3,
  81. 0, FB_VMODE_NONINTERLACED, 0 },
  82. /* 800x600-85 */
  83. { NULL, 85, 800, 600, 17790, 152, 32, 27, 1, 64, 3,
  84. 0, FB_VMODE_NONINTERLACED, 0 },
  85. /* 800x600-90 */
  86. { NULL, 90, 800, 600, 16648, 128, 40, 28, 1, 88, 3,
  87. 0, FB_VMODE_NONINTERLACED, 0 },
  88. /* 800x600-100 */
  89. { NULL, 100, 800, 600, 14667, 136, 48, 27, 1, 88, 3,
  90. 0, FB_VMODE_NONINTERLACED, 0 },
  91. /* 800x600-60 */
  92. { NULL, 60, 800, 600, 25131, 88, 40, 23, 1, 128, 4,
  93. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  94. FB_VMODE_NONINTERLACED, 0 },
  95. /* 1024x768-60 */
  96. { NULL, 60, 1024, 768, 15385, 160, 24, 29, 3, 136, 6,
  97. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  98. FB_VMODE_NONINTERLACED, 0 },
  99. /* 1024x768-70 */
  100. { NULL, 70, 1024, 768, 13346, 144, 24, 29, 3, 136, 6,
  101. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  102. FB_VMODE_NONINTERLACED, 0 },
  103. /* 1024x768-72 */
  104. { NULL, 72, 1024, 768, 12702, 168, 56, 29, 4, 112, 3,
  105. 0, FB_VMODE_NONINTERLACED, 0 },
  106. /* 1024x768-75 */
  107. { NULL, 75, 1024, 768, 12703, 176, 16, 28, 1, 96, 3,
  108. 0, FB_VMODE_NONINTERLACED, 0 },
  109. /* 1024x768-85 */
  110. { NULL, 85, 1024, 768, 10581, 208, 48, 36, 1, 96, 3,
  111. 0, FB_VMODE_NONINTERLACED, 0 },
  112. /* 1024x768-90 */
  113. { NULL, 90, 1024, 768, 9981, 176, 64, 37, 1, 112, 3,
  114. 0, FB_VMODE_NONINTERLACED, 0 },
  115. /* 1024x768-100 */
  116. { NULL, 100, 1024, 768, 8825, 184, 72, 42, 1, 112, 3,
  117. 0, FB_VMODE_NONINTERLACED, 0 },
  118. /* 1024x768-60 */
  119. { NULL, 60, 1024, 768, 15385, 160, 24, 29, 3, 136, 6,
  120. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  121. FB_VMODE_NONINTERLACED, 0 },
  122. /* 1152x864-60 */
  123. { NULL, 60, 1152, 864, 12251, 184, 64, 27, 1, 120, 3,
  124. 0, FB_VMODE_NONINTERLACED, 0 },
  125. /* 1152x864-70 */
  126. { NULL, 70, 1152, 864, 10254, 192, 72, 32, 8, 120, 3,
  127. 0, FB_VMODE_NONINTERLACED, 0 },
  128. /* 1152x864-72 */
  129. { NULL, 72, 1152, 864, 9866, 200, 72, 33, 7, 128, 3,
  130. 0, FB_VMODE_NONINTERLACED, 0 },
  131. /* 1152x864-75 */
  132. { NULL, 75, 1152, 864, 9259, 256, 64, 32, 1, 128, 3,
  133. 0, FB_VMODE_NONINTERLACED, 0 },
  134. /* 1152x864-85 */
  135. { NULL, 85, 1152, 864, 8357, 200, 72, 37, 3, 128, 3,
  136. 0, FB_VMODE_NONINTERLACED, 0 },
  137. /* 1152x864-90 */
  138. { NULL, 90, 1152, 864, 7719, 208, 80, 42, 9, 128, 3,
  139. 0, FB_VMODE_NONINTERLACED, 0 },
  140. /* 1152x864-100 */
  141. { NULL, 100, 1152, 864, 6947, 208, 80, 48, 3, 128, 3,
  142. 0, FB_VMODE_NONINTERLACED, 0 },
  143. /* 1152x864-60 */
  144. { NULL, 60, 1152, 864, 12251, 184, 64, 27, 1, 120, 3,
  145. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  146. FB_VMODE_NONINTERLACED, 0 },
  147. /* 1280x1024-60 */
  148. { NULL, 60, 1280, 1024, 9262, 248, 48, 38, 1, 112, 3,
  149. 0, FB_VMODE_NONINTERLACED, 0 },
  150. /* 1280x1024-70 */
  151. { NULL, 70, 1280, 1024, 7719, 224, 88, 38, 6, 136, 3,
  152. 0, FB_VMODE_NONINTERLACED, 0 },
  153. /* 1280x1024-72 */
  154. { NULL, 72, 1280, 1024, 7490, 224, 88, 39, 7, 136, 3,
  155. 0, FB_VMODE_NONINTERLACED, 0 },
  156. /* 1280x1024-75 */
  157. { NULL, 75, 1280, 1024, 7409, 248, 16, 38, 1, 144, 3,
  158. 0, FB_VMODE_NONINTERLACED, 0 },
  159. /* 1280x1024-85 */
  160. { NULL, 85, 1280, 1024, 6351, 224, 64, 44, 1, 160, 3,
  161. 0, FB_VMODE_NONINTERLACED, 0 },
  162. /* 1280x1024-90 */
  163. { NULL, 90, 1280, 1024, 5791, 240, 96, 51, 12, 144, 3,
  164. 0, FB_VMODE_NONINTERLACED, 0 },
  165. /* 1280x1024-100 */
  166. { NULL, 100, 1280, 1024, 5212, 240, 96, 57, 6, 144, 3,
  167. 0, FB_VMODE_NONINTERLACED, 0 },
  168. /* 1280x1024-60 */
  169. { NULL, 60, 1280, 1024, 9262, 248, 48, 38, 1, 112, 3,
  170. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  171. FB_VMODE_NONINTERLACED, 0 },
  172. /* 1600x1200-60 */
  173. { NULL, 60, 1600, 1200, 6172, 304, 64, 46, 1, 192, 3,
  174. 0, FB_VMODE_NONINTERLACED, 0 },
  175. /* 1600x1200-70 */
  176. { NULL, 70, 1600, 1200, 5291, 304, 64, 46, 1, 192, 3,
  177. 0, FB_VMODE_NONINTERLACED, 0 },
  178. /* 1600x1200-72 */
  179. { NULL, 72, 1600, 1200, 5053, 288, 112, 47, 13, 176, 3,
  180. 0, FB_VMODE_NONINTERLACED, 0 },
  181. /* 1600x1200-75 */
  182. { NULL, 75, 1600, 1200, 4938, 304, 64, 46, 1, 192, 3,
  183. 0, FB_VMODE_NONINTERLACED, 0 },
  184. /* 1600x1200-85 */
  185. { NULL, 85, 1600, 1200, 4357, 304, 64, 46, 1, 192, 3,
  186. 0, FB_VMODE_NONINTERLACED, 0 },
  187. /* 1600x1200-90 */
  188. { NULL, 90, 1600, 1200, 3981, 304, 128, 60, 1, 176, 3,
  189. 0, FB_VMODE_NONINTERLACED, 0 },
  190. /* 1600x1200-100 */
  191. { NULL, 100, 1600, 1200, 3563, 304, 128, 67, 1, 176, 3,
  192. 0, FB_VMODE_NONINTERLACED, 0 },
  193. /* 1600x1200-60 */
  194. { NULL, 60, 1600, 1200, 6172, 304, 64, 46, 1, 192, 3,
  195. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  196. FB_VMODE_NONINTERLACED, 0 },
  197. /* 1920x1440-60 */
  198. { NULL, 60, 1920, 1440, 4273, 344, 128, 56, 1, 208, 3,
  199. 0, FB_VMODE_NONINTERLACED, 0 },
  200. /* 1920x1440-70 */
  201. { NULL, 70, 1920, 1440, 3593, 360, 152, 55, 8, 208, 3,
  202. 0, FB_VMODE_NONINTERLACED, 0 },
  203. /* 1920x1440-72 */
  204. { NULL, 72, 1920, 1440, 3472, 360, 152, 68, 4, 208, 3,
  205. 0, FB_VMODE_NONINTERLACED, 0 },
  206. /* 1920x1440-75 */
  207. { NULL, 75, 1920, 1440, 3367, 352, 144, 56, 1, 224, 3,
  208. 0, FB_VMODE_NONINTERLACED, 0 },
  209. /* 1920x1440-85 */
  210. { NULL, 85, 1920, 1440, 2929, 368, 152, 68, 1, 216, 3,
  211. 0, FB_VMODE_NONINTERLACED, 0 },
  212. };
  213. #ifdef CONFIG_OLPC
  214. #include <asm/olpc.h>
  215. static struct fb_videomode olpc_dcon_modedb[] __devinitdata = {
  216. /* The only mode the DCON has is 1200x900 */
  217. { NULL, 50, 1200, 900, 17460, 24, 8, 4, 5, 8, 3,
  218. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  219. FB_VMODE_NONINTERLACED, 0 }
  220. };
  221. static void __devinit get_modedb(struct fb_videomode **modedb,
  222. unsigned int *size)
  223. {
  224. if (olpc_has_dcon()) {
  225. *modedb = (struct fb_videomode *) olpc_dcon_modedb;
  226. *size = ARRAY_SIZE(olpc_dcon_modedb);
  227. } else {
  228. *modedb = (struct fb_videomode *) geode_modedb;
  229. *size = ARRAY_SIZE(geode_modedb);
  230. }
  231. }
  232. #else
  233. static void __devinit get_modedb(struct fb_videomode **modedb,
  234. unsigned int *size)
  235. {
  236. *modedb = (struct fb_videomode *) geode_modedb;
  237. *size = ARRAY_SIZE(geode_modedb);
  238. }
  239. #endif
  240. static int lxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  241. {
  242. if (var->xres > 1920 || var->yres > 1440)
  243. return -EINVAL;
  244. if (var->bits_per_pixel == 32) {
  245. var->red.offset = 16; var->red.length = 8;
  246. var->green.offset = 8; var->green.length = 8;
  247. var->blue.offset = 0; var->blue.length = 8;
  248. } else if (var->bits_per_pixel == 16) {
  249. var->red.offset = 11; var->red.length = 5;
  250. var->green.offset = 5; var->green.length = 6;
  251. var->blue.offset = 0; var->blue.length = 5;
  252. } else if (var->bits_per_pixel == 8) {
  253. var->red.offset = 0; var->red.length = 8;
  254. var->green.offset = 0; var->green.length = 8;
  255. var->blue.offset = 0; var->blue.length = 8;
  256. } else
  257. return -EINVAL;
  258. var->transp.offset = 0; var->transp.length = 0;
  259. /* Enough video memory? */
  260. if ((lx_get_pitch(var->xres, var->bits_per_pixel) * var->yres)
  261. > info->fix.smem_len)
  262. return -EINVAL;
  263. return 0;
  264. }
  265. static int lxfb_set_par(struct fb_info *info)
  266. {
  267. if (info->var.bits_per_pixel > 8)
  268. info->fix.visual = FB_VISUAL_TRUECOLOR;
  269. else
  270. info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
  271. info->fix.line_length = lx_get_pitch(info->var.xres,
  272. info->var.bits_per_pixel);
  273. lx_set_mode(info);
  274. return 0;
  275. }
  276. static inline u_int chan_to_field(u_int chan, struct fb_bitfield *bf)
  277. {
  278. chan &= 0xffff;
  279. chan >>= 16 - bf->length;
  280. return chan << bf->offset;
  281. }
  282. static int lxfb_setcolreg(unsigned regno, unsigned red, unsigned green,
  283. unsigned blue, unsigned transp,
  284. struct fb_info *info)
  285. {
  286. if (info->var.grayscale) {
  287. /* grayscale = 0.30*R + 0.59*G + 0.11*B */
  288. red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8;
  289. }
  290. /* Truecolor has hardware independent palette */
  291. if (info->fix.visual == FB_VISUAL_TRUECOLOR) {
  292. u32 *pal = info->pseudo_palette;
  293. u32 v;
  294. if (regno >= 16)
  295. return -EINVAL;
  296. v = chan_to_field(red, &info->var.red);
  297. v |= chan_to_field(green, &info->var.green);
  298. v |= chan_to_field(blue, &info->var.blue);
  299. pal[regno] = v;
  300. } else {
  301. if (regno >= 256)
  302. return -EINVAL;
  303. lx_set_palette_reg(info, regno, red, green, blue);
  304. }
  305. return 0;
  306. }
  307. static int lxfb_blank(int blank_mode, struct fb_info *info)
  308. {
  309. return lx_blank_display(info, blank_mode);
  310. }
  311. static int __devinit lxfb_map_video_memory(struct fb_info *info,
  312. struct pci_dev *dev)
  313. {
  314. struct lxfb_par *par = info->par;
  315. int ret;
  316. ret = pci_enable_device(dev);
  317. if (ret)
  318. return ret;
  319. ret = pci_request_region(dev, 0, "lxfb-framebuffer");
  320. if (ret)
  321. return ret;
  322. ret = pci_request_region(dev, 1, "lxfb-gp");
  323. if (ret)
  324. return ret;
  325. ret = pci_request_region(dev, 2, "lxfb-vg");
  326. if (ret)
  327. return ret;
  328. ret = pci_request_region(dev, 3, "lxfb-vp");
  329. if (ret)
  330. return ret;
  331. info->fix.smem_start = pci_resource_start(dev, 0);
  332. info->fix.smem_len = vram ? vram : lx_framebuffer_size();
  333. info->screen_base = ioremap(info->fix.smem_start, info->fix.smem_len);
  334. ret = -ENOMEM;
  335. if (info->screen_base == NULL)
  336. return ret;
  337. par->gp_regs = pci_ioremap_bar(dev, 1);
  338. if (par->gp_regs == NULL)
  339. return ret;
  340. par->dc_regs = pci_ioremap_bar(dev, 2);
  341. if (par->dc_regs == NULL)
  342. return ret;
  343. par->vp_regs = pci_ioremap_bar(dev, 3);
  344. if (par->vp_regs == NULL)
  345. return ret;
  346. write_dc(par, DC_UNLOCK, DC_UNLOCK_UNLOCK);
  347. write_dc(par, DC_GLIU0_MEM_OFFSET, info->fix.smem_start & 0xFF000000);
  348. write_dc(par, DC_UNLOCK, DC_UNLOCK_LOCK);
  349. dev_info(&dev->dev, "%d KB of video memory at 0x%lx\n",
  350. info->fix.smem_len / 1024, info->fix.smem_start);
  351. return 0;
  352. }
  353. static struct fb_ops lxfb_ops = {
  354. .owner = THIS_MODULE,
  355. .fb_check_var = lxfb_check_var,
  356. .fb_set_par = lxfb_set_par,
  357. .fb_setcolreg = lxfb_setcolreg,
  358. .fb_blank = lxfb_blank,
  359. /* No HW acceleration for now. */
  360. .fb_fillrect = cfb_fillrect,
  361. .fb_copyarea = cfb_copyarea,
  362. .fb_imageblit = cfb_imageblit,
  363. };
  364. static struct fb_info * __devinit lxfb_init_fbinfo(struct device *dev)
  365. {
  366. struct lxfb_par *par;
  367. struct fb_info *info;
  368. /* Alloc enough space for the pseudo palette. */
  369. info = framebuffer_alloc(sizeof(struct lxfb_par) + sizeof(u32) * 16,
  370. dev);
  371. if (!info)
  372. return NULL;
  373. par = info->par;
  374. strcpy(info->fix.id, "Geode LX");
  375. info->fix.type = FB_TYPE_PACKED_PIXELS;
  376. info->fix.type_aux = 0;
  377. info->fix.xpanstep = 0;
  378. info->fix.ypanstep = 0;
  379. info->fix.ywrapstep = 0;
  380. info->fix.accel = FB_ACCEL_NONE;
  381. info->var.nonstd = 0;
  382. info->var.activate = FB_ACTIVATE_NOW;
  383. info->var.height = -1;
  384. info->var.width = -1;
  385. info->var.accel_flags = 0;
  386. info->var.vmode = FB_VMODE_NONINTERLACED;
  387. info->fbops = &lxfb_ops;
  388. info->flags = FBINFO_DEFAULT;
  389. info->node = -1;
  390. info->pseudo_palette = (void *)par + sizeof(struct lxfb_par);
  391. if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
  392. framebuffer_release(info);
  393. return NULL;
  394. }
  395. info->var.grayscale = 0;
  396. return info;
  397. }
  398. #ifdef CONFIG_PM
  399. static int lxfb_suspend(struct pci_dev *pdev, pm_message_t state)
  400. {
  401. struct fb_info *info = pci_get_drvdata(pdev);
  402. if (state.event == PM_EVENT_SUSPEND) {
  403. console_lock();
  404. lx_powerdown(info);
  405. fb_set_suspend(info, 1);
  406. console_unlock();
  407. }
  408. /* there's no point in setting PCI states; we emulate PCI, so
  409. * we don't end up getting power savings anyways */
  410. return 0;
  411. }
  412. static int lxfb_resume(struct pci_dev *pdev)
  413. {
  414. struct fb_info *info = pci_get_drvdata(pdev);
  415. int ret;
  416. console_lock();
  417. ret = lx_powerup(info);
  418. if (ret) {
  419. printk(KERN_ERR "lxfb: power up failed!\n");
  420. return ret;
  421. }
  422. fb_set_suspend(info, 0);
  423. console_unlock();
  424. return 0;
  425. }
  426. #else
  427. #define lxfb_suspend NULL
  428. #define lxfb_resume NULL
  429. #endif
  430. static int __devinit lxfb_probe(struct pci_dev *pdev,
  431. const struct pci_device_id *id)
  432. {
  433. struct lxfb_par *par;
  434. struct fb_info *info;
  435. int ret;
  436. struct fb_videomode *modedb_ptr;
  437. unsigned int modedb_size;
  438. info = lxfb_init_fbinfo(&pdev->dev);
  439. if (info == NULL)
  440. return -ENOMEM;
  441. par = info->par;
  442. ret = lxfb_map_video_memory(info, pdev);
  443. if (ret < 0) {
  444. dev_err(&pdev->dev,
  445. "failed to map frame buffer or controller registers\n");
  446. goto err;
  447. }
  448. /* Set up the desired outputs */
  449. par->output = 0;
  450. par->output |= (nopanel) ? 0 : OUTPUT_PANEL;
  451. par->output |= (nocrt) ? 0 : OUTPUT_CRT;
  452. /* Set up the mode database */
  453. get_modedb(&modedb_ptr, &modedb_size);
  454. ret = fb_find_mode(&info->var, info, mode_option,
  455. modedb_ptr, modedb_size, NULL, 16);
  456. if (ret == 0 || ret == 4) {
  457. dev_err(&pdev->dev, "could not find valid video mode\n");
  458. ret = -EINVAL;
  459. goto err;
  460. }
  461. /* Clear the screen of garbage, unless noclear was specified,
  462. * in which case we assume the user knows what he is doing */
  463. if (!noclear)
  464. memset_io(info->screen_base, 0, info->fix.smem_len);
  465. /* Set the mode */
  466. lxfb_check_var(&info->var, info);
  467. lxfb_set_par(info);
  468. pm_set_vt_switch(vt_switch);
  469. if (register_framebuffer(info) < 0) {
  470. ret = -EINVAL;
  471. goto err;
  472. }
  473. pci_set_drvdata(pdev, info);
  474. printk(KERN_INFO "fb%d: %s frame buffer device\n",
  475. info->node, info->fix.id);
  476. return 0;
  477. err:
  478. if (info->screen_base) {
  479. iounmap(info->screen_base);
  480. pci_release_region(pdev, 0);
  481. }
  482. if (par->gp_regs) {
  483. iounmap(par->gp_regs);
  484. pci_release_region(pdev, 1);
  485. }
  486. if (par->dc_regs) {
  487. iounmap(par->dc_regs);
  488. pci_release_region(pdev, 2);
  489. }
  490. if (par->vp_regs) {
  491. iounmap(par->vp_regs);
  492. pci_release_region(pdev, 3);
  493. }
  494. if (info) {
  495. fb_dealloc_cmap(&info->cmap);
  496. framebuffer_release(info);
  497. }
  498. return ret;
  499. }
  500. static void __devexit lxfb_remove(struct pci_dev *pdev)
  501. {
  502. struct fb_info *info = pci_get_drvdata(pdev);
  503. struct lxfb_par *par = info->par;
  504. unregister_framebuffer(info);
  505. iounmap(info->screen_base);
  506. pci_release_region(pdev, 0);
  507. iounmap(par->gp_regs);
  508. pci_release_region(pdev, 1);
  509. iounmap(par->dc_regs);
  510. pci_release_region(pdev, 2);
  511. iounmap(par->vp_regs);
  512. pci_release_region(pdev, 3);
  513. fb_dealloc_cmap(&info->cmap);
  514. pci_set_drvdata(pdev, NULL);
  515. framebuffer_release(info);
  516. }
  517. static struct pci_device_id lxfb_id_table[] = {
  518. { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_LX_VIDEO) },
  519. { 0, }
  520. };
  521. MODULE_DEVICE_TABLE(pci, lxfb_id_table);
  522. static struct pci_driver lxfb_driver = {
  523. .name = "lxfb",
  524. .id_table = lxfb_id_table,
  525. .probe = lxfb_probe,
  526. .remove = lxfb_remove,
  527. .suspend = lxfb_suspend,
  528. .resume = lxfb_resume,
  529. };
  530. #ifndef MODULE
  531. static int __init lxfb_setup(char *options)
  532. {
  533. char *opt;
  534. if (!options || !*options)
  535. return 0;
  536. while ((opt = strsep(&options, ",")) != NULL) {
  537. if (!*opt)
  538. continue;
  539. if (!strcmp(opt, "noclear"))
  540. noclear = 1;
  541. else if (!strcmp(opt, "nopanel"))
  542. nopanel = 1;
  543. else if (!strcmp(opt, "nocrt"))
  544. nocrt = 1;
  545. else
  546. mode_option = opt;
  547. }
  548. return 0;
  549. }
  550. #endif
  551. static int __init lxfb_init(void)
  552. {
  553. #ifndef MODULE
  554. char *option = NULL;
  555. if (fb_get_options("lxfb", &option))
  556. return -ENODEV;
  557. lxfb_setup(option);
  558. #endif
  559. return pci_register_driver(&lxfb_driver);
  560. }
  561. static void __exit lxfb_cleanup(void)
  562. {
  563. pci_unregister_driver(&lxfb_driver);
  564. }
  565. module_init(lxfb_init);
  566. module_exit(lxfb_cleanup);
  567. module_param(mode_option, charp, 0);
  568. MODULE_PARM_DESC(mode_option, "video mode (<x>x<y>[-<bpp>][@<refr>])");
  569. module_param(vram, int, 0);
  570. MODULE_PARM_DESC(vram, "video memory size");
  571. module_param(vt_switch, int, 0);
  572. MODULE_PARM_DESC(vt_switch, "enable VT switch during suspend/resume");
  573. MODULE_DESCRIPTION("Framebuffer driver for the AMD Geode LX");
  574. MODULE_LICENSE("GPL");