igafb.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. /*
  2. * linux/drivers/video/igafb.c -- Frame buffer device for IGA 1682
  3. *
  4. * Copyright (C) 1998 Vladimir Roganov and Gleb Raiko
  5. *
  6. * This driver is partly based on the Frame buffer device for ATI Mach64
  7. * and partially on VESA-related code.
  8. *
  9. * Copyright (C) 1997-1998 Geert Uytterhoeven
  10. * Copyright (C) 1998 Bernd Harries
  11. * Copyright (C) 1998 Eddie C. Dost (ecd@skynet.be)
  12. *
  13. * This file is subject to the terms and conditions of the GNU General Public
  14. * License. See the file COPYING in the main directory of this archive for
  15. * more details.
  16. */
  17. /******************************************************************************
  18. TODO:
  19. Despite of IGA Card has advanced graphic acceleration,
  20. initial version is almost dummy and does not support it.
  21. Support for video modes and acceleration must be added
  22. together with accelerated X-Windows driver implementation.
  23. Most important thing at this moment is that we have working
  24. JavaEngine1 console & X with new console interface.
  25. ******************************************************************************/
  26. #include <linux/module.h>
  27. #include <linux/kernel.h>
  28. #include <linux/errno.h>
  29. #include <linux/string.h>
  30. #include <linux/mm.h>
  31. #include <linux/slab.h>
  32. #include <linux/vmalloc.h>
  33. #include <linux/delay.h>
  34. #include <linux/interrupt.h>
  35. #include <linux/fb.h>
  36. #include <linux/init.h>
  37. #include <linux/pci.h>
  38. #include <linux/nvram.h>
  39. #include <asm/io.h>
  40. #ifdef __sparc__
  41. #include <asm/pbm.h>
  42. #include <asm/pcic.h>
  43. #endif
  44. #include <video/iga.h>
  45. struct pci_mmap_map {
  46. unsigned long voff;
  47. unsigned long poff;
  48. unsigned long size;
  49. unsigned long prot_flag;
  50. unsigned long prot_mask;
  51. };
  52. struct iga_par {
  53. struct pci_mmap_map *mmap_map;
  54. unsigned long frame_buffer_phys;
  55. unsigned long io_base;
  56. };
  57. struct fb_info fb_info;
  58. struct fb_fix_screeninfo igafb_fix __initdata = {
  59. .id = "IGA 1682",
  60. .type = FB_TYPE_PACKED_PIXELS,
  61. .mmio_len = 1000
  62. };
  63. struct fb_var_screeninfo default_var = {
  64. /* 640x480, 60 Hz, Non-Interlaced (25.175 MHz dotclock) */
  65. .xres = 640,
  66. .yres = 480,
  67. .xres_virtual = 640,
  68. .yres_virtual = 480,
  69. .bits_per_pixel = 8,
  70. .red = {0, 8, 0 },
  71. .green = {0, 8, 0 },
  72. .blue = {0, 8, 0 },
  73. .height = -1,
  74. .width = -1,
  75. .accel_flags = FB_ACCEL_NONE,
  76. .pixclock = 39722,
  77. .left_margin = 48,
  78. .right_margin = 16,
  79. .upper_margin = 33,
  80. .lower_margin = 10,
  81. .hsync_len = 96,
  82. .vsync_len = 2,
  83. .vmode = FB_VMODE_NONINTERLACED
  84. };
  85. #ifdef __sparc__
  86. struct fb_var_screeninfo default_var_1024x768 __initdata = {
  87. /* 1024x768, 75 Hz, Non-Interlaced (78.75 MHz dotclock) */
  88. .xres = 1024,
  89. .yres = 768,
  90. .xres_virtual = 1024,
  91. .yres_virtual = 768,
  92. .bits_per_pixel = 8,
  93. .red = {0, 8, 0 },
  94. .green = {0, 8, 0 },
  95. .blue = {0, 8, 0 },
  96. .height = -1,
  97. .width = -1,
  98. .accel_flags = FB_ACCEL_NONE,
  99. .pixclock = 12699,
  100. .left_margin = 176,
  101. .right_margin = 16,
  102. .upper_margin = 28,
  103. .lower_margin = 1,
  104. .hsync_len = 96,
  105. .vsync_len = 3,
  106. .vmode = FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
  107. };
  108. struct fb_var_screeninfo default_var_1152x900 __initdata = {
  109. /* 1152x900, 76 Hz, Non-Interlaced (110.0 MHz dotclock) */
  110. .xres = 1152,
  111. .yres = 900,
  112. .xres_virtual = 1152,
  113. .yres_virtual = 900,
  114. .bits_per_pixel = 8,
  115. .red = { 0, 8, 0 },
  116. .green = { 0, 8, 0 },
  117. .blue = { 0, 8, 0 },
  118. .height = -1,
  119. .width = -1,
  120. .accel_flags = FB_ACCEL_NONE,
  121. .pixclock = 9091,
  122. .left_margin = 234,
  123. .right_margin = 24,
  124. .upper_margin = 34,
  125. .lower_margin = 3,
  126. .hsync_len = 100,
  127. .vsync_len = 3,
  128. .vmode = FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
  129. };
  130. struct fb_var_screeninfo default_var_1280x1024 __initdata = {
  131. /* 1280x1024, 75 Hz, Non-Interlaced (135.00 MHz dotclock) */
  132. .xres = 1280,
  133. .yres = 1024,
  134. .xres_virtual = 1280,
  135. .yres_virtual = 1024,
  136. .bits_per_pixel = 8,
  137. .red = {0, 8, 0 },
  138. .green = {0, 8, 0 },
  139. .blue = {0, 8, 0 },
  140. .height = -1,
  141. .width = -1,
  142. .accel_flags = 0,
  143. .pixclock = 7408,
  144. .left_margin = 248,
  145. .right_margin = 16,
  146. .upper_margin = 38,
  147. .lower_margin = 1,
  148. .hsync_len = 144,
  149. .vsync_len = 3,
  150. .vmode = FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
  151. };
  152. /*
  153. * Memory-mapped I/O functions for Sparc PCI
  154. *
  155. * On sparc we happen to access I/O with memory mapped functions too.
  156. */
  157. #define pci_inb(par, reg) readb(par->io_base+(reg))
  158. #define pci_outb(par, val, reg) writeb(val, par->io_base+(reg))
  159. static inline unsigned int iga_inb(struct iga_par *par, unsigned int reg,
  160. unsigned int idx)
  161. {
  162. pci_outb(par, idx, reg);
  163. return pci_inb(par, reg + 1);
  164. }
  165. static inline void iga_outb(struct iga_par *par, unsigned char val,
  166. unsigned int reg, unsigned int idx )
  167. {
  168. pci_outb(par, idx, reg);
  169. pci_outb(par, val, reg+1);
  170. }
  171. #endif /* __sparc__ */
  172. /*
  173. * Very important functionality for the JavaEngine1 computer:
  174. * make screen border black (usign special IGA registers)
  175. */
  176. static void iga_blank_border(struct iga_par *par)
  177. {
  178. int i;
  179. #if 0
  180. /*
  181. * PROM does this for us, so keep this code as a reminder
  182. * about required read from 0x3DA and writing of 0x20 in the end.
  183. */
  184. (void) pci_inb(par, 0x3DA); /* required for every access */
  185. pci_outb(par, IGA_IDX_VGA_OVERSCAN, IGA_ATTR_CTL);
  186. (void) pci_inb(par, IGA_ATTR_CTL+1);
  187. pci_outb(par, 0x38, IGA_ATTR_CTL);
  188. pci_outb(par, 0x20, IGA_ATTR_CTL); /* re-enable visual */
  189. #endif
  190. /*
  191. * This does not work as it was designed because the overscan
  192. * color is looked up in the palette. Therefore, under X11
  193. * overscan changes color.
  194. */
  195. for (i=0; i < 3; i++)
  196. iga_outb(par, 0, IGA_EXT_CNTRL, IGA_IDX_OVERSCAN_COLOR + i);
  197. }
  198. #ifdef __sparc__
  199. static int igafb_mmap(struct fb_info *info,
  200. struct vm_area_struct *vma)
  201. {
  202. struct iga_par *par = (struct iga_par *)info->par;
  203. unsigned int size, page, map_size = 0;
  204. unsigned long map_offset = 0;
  205. int i;
  206. if (!par->mmap_map)
  207. return -ENXIO;
  208. size = vma->vm_end - vma->vm_start;
  209. /* Each page, see which map applies */
  210. for (page = 0; page < size; ) {
  211. map_size = 0;
  212. for (i = 0; par->mmap_map[i].size; i++) {
  213. unsigned long start = par->mmap_map[i].voff;
  214. unsigned long end = start + par->mmap_map[i].size;
  215. unsigned long offset = (vma->vm_pgoff << PAGE_SHIFT) + page;
  216. if (start > offset)
  217. continue;
  218. if (offset >= end)
  219. continue;
  220. map_size = par->mmap_map[i].size - (offset - start);
  221. map_offset = par->mmap_map[i].poff + (offset - start);
  222. break;
  223. }
  224. if (!map_size) {
  225. page += PAGE_SIZE;
  226. continue;
  227. }
  228. if (page + map_size > size)
  229. map_size = size - page;
  230. pgprot_val(vma->vm_page_prot) &= ~(par->mmap_map[i].prot_mask);
  231. pgprot_val(vma->vm_page_prot) |= par->mmap_map[i].prot_flag;
  232. if (remap_pfn_range(vma, vma->vm_start + page,
  233. map_offset >> PAGE_SHIFT, map_size, vma->vm_page_prot))
  234. return -EAGAIN;
  235. page += map_size;
  236. }
  237. if (!map_size)
  238. return -EINVAL;
  239. vma->vm_flags |= VM_IO;
  240. return 0;
  241. }
  242. #endif /* __sparc__ */
  243. static int igafb_setcolreg(unsigned regno, unsigned red, unsigned green,
  244. unsigned blue, unsigned transp,
  245. struct fb_info *info)
  246. {
  247. /*
  248. * Set a single color register. The values supplied are
  249. * already rounded down to the hardware's capabilities
  250. * (according to the entries in the `var' structure). Return
  251. * != 0 for invalid regno.
  252. */
  253. struct iga_par *par = (struct iga_par *)info->par;
  254. if (regno >= info->cmap.len)
  255. return 1;
  256. pci_outb(par, regno, DAC_W_INDEX);
  257. pci_outb(par, red, DAC_DATA);
  258. pci_outb(par, green, DAC_DATA);
  259. pci_outb(par, blue, DAC_DATA);
  260. if (regno < 16) {
  261. switch (info->var.bits_per_pixel) {
  262. case 16:
  263. ((u16*)(info->pseudo_palette))[regno] =
  264. (regno << 10) | (regno << 5) | regno;
  265. break;
  266. case 24:
  267. ((u32*)(info->pseudo_palette))[regno] =
  268. (regno << 16) | (regno << 8) | regno;
  269. break;
  270. case 32:
  271. { int i;
  272. i = (regno << 8) | regno;
  273. ((u32*)(info->pseudo_palette))[regno] = (i << 16) | i;
  274. }
  275. break;
  276. }
  277. }
  278. return 0;
  279. }
  280. /*
  281. * Framebuffer option structure
  282. */
  283. static struct fb_ops igafb_ops = {
  284. .owner = THIS_MODULE,
  285. .fb_setcolreg = igafb_setcolreg,
  286. .fb_fillrect = cfb_fillrect,
  287. .fb_copyarea = cfb_copyarea,
  288. .fb_imageblit = cfb_imageblit,
  289. #ifdef __sparc__
  290. .fb_mmap = igafb_mmap,
  291. #endif
  292. };
  293. static int __init iga_init(struct fb_info *info, struct iga_par *par)
  294. {
  295. char vramsz = iga_inb(par, IGA_EXT_CNTRL, IGA_IDX_EXT_BUS_CNTL)
  296. & MEM_SIZE_ALIAS;
  297. int video_cmap_len;
  298. switch (vramsz) {
  299. case MEM_SIZE_1M:
  300. info->fix.smem_len = 0x100000;
  301. break;
  302. case MEM_SIZE_2M:
  303. info->fix.smem_len = 0x200000;
  304. break;
  305. case MEM_SIZE_4M:
  306. case MEM_SIZE_RESERVED:
  307. info->fix.smem_len = 0x400000;
  308. break;
  309. }
  310. if (info->var.bits_per_pixel > 8)
  311. video_cmap_len = 16;
  312. else
  313. video_cmap_len = 256;
  314. info->fbops = &igafb_ops;
  315. info->flags = FBINFO_DEFAULT;
  316. fb_alloc_cmap(&info->cmap, video_cmap_len, 0);
  317. if (register_framebuffer(info) < 0)
  318. return 0;
  319. printk("fb%d: %s frame buffer device at 0x%08lx [%dMB VRAM]\n",
  320. info->node, info->fix.id,
  321. par->frame_buffer_phys, info->fix.smem_len >> 20);
  322. iga_blank_border(par);
  323. return 1;
  324. }
  325. int __init igafb_init(void)
  326. {
  327. struct fb_info *info;
  328. struct pci_dev *pdev;
  329. struct iga_par *par;
  330. unsigned long addr;
  331. int size, iga2000 = 0;
  332. if (fb_get_options("igafb", NULL))
  333. return -ENODEV;
  334. /* Do not attach when we have a serial console. */
  335. if (!con_is_present())
  336. return -ENXIO;
  337. pdev = pci_get_device(PCI_VENDOR_ID_INTERG,
  338. PCI_DEVICE_ID_INTERG_1682, 0);
  339. if (pdev == NULL) {
  340. /*
  341. * XXX We tried to use cyber2000fb.c for IGS 2000.
  342. * But it does not initialize the chip in JavaStation-E, alas.
  343. */
  344. pdev = pci_get_device(PCI_VENDOR_ID_INTERG, 0x2000, 0);
  345. if(pdev == NULL) {
  346. return -ENXIO;
  347. }
  348. iga2000 = 1;
  349. }
  350. /* We leak a reference here but as it cannot be unloaded this is
  351. fine. If you write unload code remember to free it in unload */
  352. size = sizeof(struct fb_info) + sizeof(struct iga_par) + sizeof(u32)*16;
  353. info = kzalloc(size, GFP_ATOMIC);
  354. if (!info) {
  355. printk("igafb_init: can't alloc fb_info\n");
  356. return -ENOMEM;
  357. }
  358. par = (struct iga_par *) (info + 1);
  359. if ((addr = pdev->resource[0].start) == 0) {
  360. printk("igafb_init: no memory start\n");
  361. kfree(info);
  362. return -ENXIO;
  363. }
  364. if ((info->screen_base = ioremap(addr, 1024*1024*2)) == 0) {
  365. printk("igafb_init: can't remap %lx[2M]\n", addr);
  366. kfree(info);
  367. return -ENXIO;
  368. }
  369. par->frame_buffer_phys = addr & PCI_BASE_ADDRESS_MEM_MASK;
  370. #ifdef __sparc__
  371. /*
  372. * The following is sparc specific and this is why:
  373. *
  374. * IGS2000 has its I/O memory mapped and we want
  375. * to generate memory cycles on PCI, e.g. do ioremap(),
  376. * then readb/writeb() as in Documentation/IO-mapping.txt.
  377. *
  378. * IGS1682 is more traditional, it responds to PCI I/O
  379. * cycles, so we want to access it with inb()/outb().
  380. *
  381. * On sparc, PCIC converts CPU memory access within
  382. * phys window 0x3000xxxx into PCI I/O cycles. Therefore
  383. * we may use readb/writeb to access them with IGS1682.
  384. *
  385. * We do not take io_base_phys from resource[n].start
  386. * on IGS1682 because that chip is BROKEN. It does not
  387. * have a base register for I/O. We just "know" what its
  388. * I/O addresses are.
  389. */
  390. if (iga2000) {
  391. igafb_fix.mmio_start = par->frame_buffer_phys | 0x00800000;
  392. } else {
  393. igafb_fix.mmio_start = 0x30000000; /* XXX */
  394. }
  395. if ((par->io_base = (int) ioremap(igafb_fix.mmio_start, igafb_fix.smem_len)) == 0) {
  396. printk("igafb_init: can't remap %lx[4K]\n", igafb_fix.mmio_start);
  397. iounmap((void *)info->screen_base);
  398. kfree(info);
  399. return -ENXIO;
  400. }
  401. /*
  402. * Figure mmap addresses from PCI config space.
  403. * We need two regions: for video memory and for I/O ports.
  404. * Later one can add region for video coprocessor registers.
  405. * However, mmap routine loops until size != 0, so we put
  406. * one additional region with size == 0.
  407. */
  408. par->mmap_map = kzalloc(4 * sizeof(*par->mmap_map), GFP_ATOMIC);
  409. if (!par->mmap_map) {
  410. printk("igafb_init: can't alloc mmap_map\n");
  411. iounmap((void *)par->io_base);
  412. iounmap(info->screen_base);
  413. kfree(info);
  414. return -ENOMEM;
  415. }
  416. /*
  417. * Set default vmode and cmode from PROM properties.
  418. */
  419. {
  420. struct pcidev_cookie *cookie = pdev->sysdata;
  421. int node = cookie->prom_node;
  422. int width = prom_getintdefault(node, "width", 1024);
  423. int height = prom_getintdefault(node, "height", 768);
  424. int depth = prom_getintdefault(node, "depth", 8);
  425. switch (width) {
  426. case 1024:
  427. if (height == 768)
  428. default_var = default_var_1024x768;
  429. break;
  430. case 1152:
  431. if (height == 900)
  432. default_var = default_var_1152x900;
  433. break;
  434. case 1280:
  435. if (height == 1024)
  436. default_var = default_var_1280x1024;
  437. break;
  438. default:
  439. break;
  440. }
  441. switch (depth) {
  442. case 8:
  443. default_var.bits_per_pixel = 8;
  444. break;
  445. case 16:
  446. default_var.bits_per_pixel = 16;
  447. break;
  448. case 24:
  449. default_var.bits_per_pixel = 24;
  450. break;
  451. case 32:
  452. default_var.bits_per_pixel = 32;
  453. break;
  454. default:
  455. break;
  456. }
  457. }
  458. #endif
  459. igafb_fix.smem_start = (unsigned long) info->screen_base;
  460. igafb_fix.line_length = default_var.xres*(default_var.bits_per_pixel/8);
  461. igafb_fix.visual = default_var.bits_per_pixel <= 8 ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_DIRECTCOLOR;
  462. info->var = default_var;
  463. info->fix = igafb_fix;
  464. info->pseudo_palette = (void *)(par + 1);
  465. info->device = &pdev->dev;
  466. if (!iga_init(info, par)) {
  467. iounmap((void *)par->io_base);
  468. iounmap(info->screen_base);
  469. kfree(par->mmap_map);
  470. kfree(info);
  471. }
  472. #ifdef __sparc__
  473. /*
  474. * Add /dev/fb mmap values.
  475. */
  476. /* First region is for video memory */
  477. par->mmap_map[0].voff = 0x0;
  478. par->mmap_map[0].poff = par->frame_buffer_phys & PAGE_MASK;
  479. par->mmap_map[0].size = info->fix.smem_len & PAGE_MASK;
  480. par->mmap_map[0].prot_mask = SRMMU_CACHE;
  481. par->mmap_map[0].prot_flag = SRMMU_WRITE;
  482. /* Second region is for I/O ports */
  483. par->mmap_map[1].voff = par->frame_buffer_phys & PAGE_MASK;
  484. par->mmap_map[1].poff = info->fix.smem_start & PAGE_MASK;
  485. par->mmap_map[1].size = PAGE_SIZE * 2; /* X wants 2 pages */
  486. par->mmap_map[1].prot_mask = SRMMU_CACHE;
  487. par->mmap_map[1].prot_flag = SRMMU_WRITE;
  488. #endif /* __sparc__ */
  489. return 0;
  490. }
  491. int __init igafb_setup(char *options)
  492. {
  493. char *this_opt;
  494. if (!options || !*options)
  495. return 0;
  496. while ((this_opt = strsep(&options, ",")) != NULL) {
  497. }
  498. return 0;
  499. }
  500. module_init(igafb_init);
  501. MODULE_LICENSE("GPL");
  502. static struct pci_device_id igafb_pci_tbl[] __devinitdata = {
  503. { PCI_VENDOR_ID_INTERG, PCI_DEVICE_ID_INTERG_1682,
  504. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  505. { }
  506. };
  507. MODULE_DEVICE_TABLE(pci, igafb_pci_tbl);