lxfb_core.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  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[] = {
  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[] = {
  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 get_modedb(struct fb_videomode **modedb, unsigned int *size)
  222. {
  223. if (olpc_has_dcon()) {
  224. *modedb = (struct fb_videomode *) olpc_dcon_modedb;
  225. *size = ARRAY_SIZE(olpc_dcon_modedb);
  226. } else {
  227. *modedb = (struct fb_videomode *) geode_modedb;
  228. *size = ARRAY_SIZE(geode_modedb);
  229. }
  230. }
  231. #else
  232. static void get_modedb(struct fb_videomode **modedb, unsigned int *size)
  233. {
  234. *modedb = (struct fb_videomode *) geode_modedb;
  235. *size = ARRAY_SIZE(geode_modedb);
  236. }
  237. #endif
  238. static int lxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  239. {
  240. if (var->xres > 1920 || var->yres > 1440)
  241. return -EINVAL;
  242. if (var->bits_per_pixel == 32) {
  243. var->red.offset = 16; var->red.length = 8;
  244. var->green.offset = 8; var->green.length = 8;
  245. var->blue.offset = 0; var->blue.length = 8;
  246. } else if (var->bits_per_pixel == 16) {
  247. var->red.offset = 11; var->red.length = 5;
  248. var->green.offset = 5; var->green.length = 6;
  249. var->blue.offset = 0; var->blue.length = 5;
  250. } else if (var->bits_per_pixel == 8) {
  251. var->red.offset = 0; var->red.length = 8;
  252. var->green.offset = 0; var->green.length = 8;
  253. var->blue.offset = 0; var->blue.length = 8;
  254. } else
  255. return -EINVAL;
  256. var->transp.offset = 0; var->transp.length = 0;
  257. /* Enough video memory? */
  258. if ((lx_get_pitch(var->xres, var->bits_per_pixel) * var->yres)
  259. > info->fix.smem_len)
  260. return -EINVAL;
  261. return 0;
  262. }
  263. static int lxfb_set_par(struct fb_info *info)
  264. {
  265. if (info->var.bits_per_pixel > 8)
  266. info->fix.visual = FB_VISUAL_TRUECOLOR;
  267. else
  268. info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
  269. info->fix.line_length = lx_get_pitch(info->var.xres,
  270. info->var.bits_per_pixel);
  271. lx_set_mode(info);
  272. return 0;
  273. }
  274. static inline u_int chan_to_field(u_int chan, struct fb_bitfield *bf)
  275. {
  276. chan &= 0xffff;
  277. chan >>= 16 - bf->length;
  278. return chan << bf->offset;
  279. }
  280. static int lxfb_setcolreg(unsigned regno, unsigned red, unsigned green,
  281. unsigned blue, unsigned transp,
  282. struct fb_info *info)
  283. {
  284. if (info->var.grayscale) {
  285. /* grayscale = 0.30*R + 0.59*G + 0.11*B */
  286. red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8;
  287. }
  288. /* Truecolor has hardware independent palette */
  289. if (info->fix.visual == FB_VISUAL_TRUECOLOR) {
  290. u32 *pal = info->pseudo_palette;
  291. u32 v;
  292. if (regno >= 16)
  293. return -EINVAL;
  294. v = chan_to_field(red, &info->var.red);
  295. v |= chan_to_field(green, &info->var.green);
  296. v |= chan_to_field(blue, &info->var.blue);
  297. pal[regno] = v;
  298. } else {
  299. if (regno >= 256)
  300. return -EINVAL;
  301. lx_set_palette_reg(info, regno, red, green, blue);
  302. }
  303. return 0;
  304. }
  305. static int lxfb_blank(int blank_mode, struct fb_info *info)
  306. {
  307. return lx_blank_display(info, blank_mode);
  308. }
  309. static int lxfb_map_video_memory(struct fb_info *info, struct pci_dev *dev)
  310. {
  311. struct lxfb_par *par = info->par;
  312. int ret;
  313. ret = pci_enable_device(dev);
  314. if (ret)
  315. return ret;
  316. ret = pci_request_region(dev, 0, "lxfb-framebuffer");
  317. if (ret)
  318. return ret;
  319. ret = pci_request_region(dev, 1, "lxfb-gp");
  320. if (ret)
  321. return ret;
  322. ret = pci_request_region(dev, 2, "lxfb-vg");
  323. if (ret)
  324. return ret;
  325. ret = pci_request_region(dev, 3, "lxfb-vp");
  326. if (ret)
  327. return ret;
  328. info->fix.smem_start = pci_resource_start(dev, 0);
  329. info->fix.smem_len = vram ? vram : lx_framebuffer_size();
  330. info->screen_base = ioremap(info->fix.smem_start, info->fix.smem_len);
  331. ret = -ENOMEM;
  332. if (info->screen_base == NULL)
  333. return ret;
  334. par->gp_regs = pci_ioremap_bar(dev, 1);
  335. if (par->gp_regs == NULL)
  336. return ret;
  337. par->dc_regs = pci_ioremap_bar(dev, 2);
  338. if (par->dc_regs == NULL)
  339. return ret;
  340. par->vp_regs = pci_ioremap_bar(dev, 3);
  341. if (par->vp_regs == NULL)
  342. return ret;
  343. write_dc(par, DC_UNLOCK, DC_UNLOCK_UNLOCK);
  344. write_dc(par, DC_GLIU0_MEM_OFFSET, info->fix.smem_start & 0xFF000000);
  345. write_dc(par, DC_UNLOCK, DC_UNLOCK_LOCK);
  346. dev_info(&dev->dev, "%d KB of video memory at 0x%lx\n",
  347. info->fix.smem_len / 1024, info->fix.smem_start);
  348. return 0;
  349. }
  350. static struct fb_ops lxfb_ops = {
  351. .owner = THIS_MODULE,
  352. .fb_check_var = lxfb_check_var,
  353. .fb_set_par = lxfb_set_par,
  354. .fb_setcolreg = lxfb_setcolreg,
  355. .fb_blank = lxfb_blank,
  356. /* No HW acceleration for now. */
  357. .fb_fillrect = cfb_fillrect,
  358. .fb_copyarea = cfb_copyarea,
  359. .fb_imageblit = cfb_imageblit,
  360. };
  361. static struct fb_info *lxfb_init_fbinfo(struct device *dev)
  362. {
  363. struct lxfb_par *par;
  364. struct fb_info *info;
  365. /* Alloc enough space for the pseudo palette. */
  366. info = framebuffer_alloc(sizeof(struct lxfb_par) + sizeof(u32) * 16,
  367. dev);
  368. if (!info)
  369. return NULL;
  370. par = info->par;
  371. strcpy(info->fix.id, "Geode LX");
  372. info->fix.type = FB_TYPE_PACKED_PIXELS;
  373. info->fix.type_aux = 0;
  374. info->fix.xpanstep = 0;
  375. info->fix.ypanstep = 0;
  376. info->fix.ywrapstep = 0;
  377. info->fix.accel = FB_ACCEL_NONE;
  378. info->var.nonstd = 0;
  379. info->var.activate = FB_ACTIVATE_NOW;
  380. info->var.height = -1;
  381. info->var.width = -1;
  382. info->var.accel_flags = 0;
  383. info->var.vmode = FB_VMODE_NONINTERLACED;
  384. info->fbops = &lxfb_ops;
  385. info->flags = FBINFO_DEFAULT;
  386. info->node = -1;
  387. info->pseudo_palette = (void *)par + sizeof(struct lxfb_par);
  388. if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
  389. framebuffer_release(info);
  390. return NULL;
  391. }
  392. info->var.grayscale = 0;
  393. return info;
  394. }
  395. #ifdef CONFIG_PM
  396. static int lxfb_suspend(struct pci_dev *pdev, pm_message_t state)
  397. {
  398. struct fb_info *info = pci_get_drvdata(pdev);
  399. if (state.event == PM_EVENT_SUSPEND) {
  400. console_lock();
  401. lx_powerdown(info);
  402. fb_set_suspend(info, 1);
  403. console_unlock();
  404. }
  405. /* there's no point in setting PCI states; we emulate PCI, so
  406. * we don't end up getting power savings anyways */
  407. return 0;
  408. }
  409. static int lxfb_resume(struct pci_dev *pdev)
  410. {
  411. struct fb_info *info = pci_get_drvdata(pdev);
  412. int ret;
  413. console_lock();
  414. ret = lx_powerup(info);
  415. if (ret) {
  416. printk(KERN_ERR "lxfb: power up failed!\n");
  417. return ret;
  418. }
  419. fb_set_suspend(info, 0);
  420. console_unlock();
  421. return 0;
  422. }
  423. #else
  424. #define lxfb_suspend NULL
  425. #define lxfb_resume NULL
  426. #endif
  427. static int lxfb_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  428. {
  429. struct lxfb_par *par;
  430. struct fb_info *info;
  431. int ret;
  432. struct fb_videomode *modedb_ptr;
  433. unsigned int modedb_size;
  434. info = lxfb_init_fbinfo(&pdev->dev);
  435. if (info == NULL)
  436. return -ENOMEM;
  437. par = info->par;
  438. ret = lxfb_map_video_memory(info, pdev);
  439. if (ret < 0) {
  440. dev_err(&pdev->dev,
  441. "failed to map frame buffer or controller registers\n");
  442. goto err;
  443. }
  444. /* Set up the desired outputs */
  445. par->output = 0;
  446. par->output |= (nopanel) ? 0 : OUTPUT_PANEL;
  447. par->output |= (nocrt) ? 0 : OUTPUT_CRT;
  448. /* Set up the mode database */
  449. get_modedb(&modedb_ptr, &modedb_size);
  450. ret = fb_find_mode(&info->var, info, mode_option,
  451. modedb_ptr, modedb_size, NULL, 16);
  452. if (ret == 0 || ret == 4) {
  453. dev_err(&pdev->dev, "could not find valid video mode\n");
  454. ret = -EINVAL;
  455. goto err;
  456. }
  457. /* Clear the screen of garbage, unless noclear was specified,
  458. * in which case we assume the user knows what he is doing */
  459. if (!noclear)
  460. memset_io(info->screen_base, 0, info->fix.smem_len);
  461. /* Set the mode */
  462. lxfb_check_var(&info->var, info);
  463. lxfb_set_par(info);
  464. pm_set_vt_switch(vt_switch);
  465. if (register_framebuffer(info) < 0) {
  466. ret = -EINVAL;
  467. goto err;
  468. }
  469. pci_set_drvdata(pdev, info);
  470. fb_info(info, "%s frame buffer device\n", info->fix.id);
  471. return 0;
  472. err:
  473. if (info->screen_base) {
  474. iounmap(info->screen_base);
  475. pci_release_region(pdev, 0);
  476. }
  477. if (par->gp_regs) {
  478. iounmap(par->gp_regs);
  479. pci_release_region(pdev, 1);
  480. }
  481. if (par->dc_regs) {
  482. iounmap(par->dc_regs);
  483. pci_release_region(pdev, 2);
  484. }
  485. if (par->vp_regs) {
  486. iounmap(par->vp_regs);
  487. pci_release_region(pdev, 3);
  488. }
  489. fb_dealloc_cmap(&info->cmap);
  490. framebuffer_release(info);
  491. return ret;
  492. }
  493. static void lxfb_remove(struct pci_dev *pdev)
  494. {
  495. struct fb_info *info = pci_get_drvdata(pdev);
  496. struct lxfb_par *par = info->par;
  497. unregister_framebuffer(info);
  498. iounmap(info->screen_base);
  499. pci_release_region(pdev, 0);
  500. iounmap(par->gp_regs);
  501. pci_release_region(pdev, 1);
  502. iounmap(par->dc_regs);
  503. pci_release_region(pdev, 2);
  504. iounmap(par->vp_regs);
  505. pci_release_region(pdev, 3);
  506. fb_dealloc_cmap(&info->cmap);
  507. framebuffer_release(info);
  508. }
  509. static struct pci_device_id lxfb_id_table[] = {
  510. { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_LX_VIDEO) },
  511. { 0, }
  512. };
  513. MODULE_DEVICE_TABLE(pci, lxfb_id_table);
  514. static struct pci_driver lxfb_driver = {
  515. .name = "lxfb",
  516. .id_table = lxfb_id_table,
  517. .probe = lxfb_probe,
  518. .remove = lxfb_remove,
  519. .suspend = lxfb_suspend,
  520. .resume = lxfb_resume,
  521. };
  522. #ifndef MODULE
  523. static int __init lxfb_setup(char *options)
  524. {
  525. char *opt;
  526. if (!options || !*options)
  527. return 0;
  528. while ((opt = strsep(&options, ",")) != NULL) {
  529. if (!*opt)
  530. continue;
  531. if (!strcmp(opt, "noclear"))
  532. noclear = 1;
  533. else if (!strcmp(opt, "nopanel"))
  534. nopanel = 1;
  535. else if (!strcmp(opt, "nocrt"))
  536. nocrt = 1;
  537. else
  538. mode_option = opt;
  539. }
  540. return 0;
  541. }
  542. #endif
  543. static int __init lxfb_init(void)
  544. {
  545. #ifndef MODULE
  546. char *option = NULL;
  547. if (fb_get_options("lxfb", &option))
  548. return -ENODEV;
  549. lxfb_setup(option);
  550. #endif
  551. return pci_register_driver(&lxfb_driver);
  552. }
  553. static void __exit lxfb_cleanup(void)
  554. {
  555. pci_unregister_driver(&lxfb_driver);
  556. }
  557. module_init(lxfb_init);
  558. module_exit(lxfb_cleanup);
  559. module_param(mode_option, charp, 0);
  560. MODULE_PARM_DESC(mode_option, "video mode (<x>x<y>[-<bpp>][@<refr>])");
  561. module_param(vram, int, 0);
  562. MODULE_PARM_DESC(vram, "video memory size");
  563. module_param(vt_switch, int, 0);
  564. MODULE_PARM_DESC(vt_switch, "enable VT switch during suspend/resume");
  565. MODULE_DESCRIPTION("Framebuffer driver for the AMD Geode LX");
  566. MODULE_LICENSE("GPL");