hpfb.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. /*
  2. * HP300 Topcat framebuffer support (derived from macfb of all things)
  3. * Phil Blundell <philb@gnu.org> 1998
  4. * DIO-II, colour map and Catseye support by
  5. * Kars de Jong <jongk@linux-m68k.org>, May 2004.
  6. */
  7. #include <linux/module.h>
  8. #include <linux/kernel.h>
  9. #include <linux/errno.h>
  10. #include <linux/string.h>
  11. #include <linux/mm.h>
  12. #include <linux/delay.h>
  13. #include <linux/init.h>
  14. #include <linux/fb.h>
  15. #include <linux/dio.h>
  16. #include <asm/io.h>
  17. #include <asm/uaccess.h>
  18. static struct fb_info fb_info = {
  19. .fix = {
  20. .id = "HP300 ",
  21. .type = FB_TYPE_PACKED_PIXELS,
  22. .visual = FB_VISUAL_PSEUDOCOLOR,
  23. .accel = FB_ACCEL_NONE,
  24. }
  25. };
  26. static unsigned long fb_regs;
  27. static unsigned char fb_bitmask;
  28. #define TC_NBLANK 0x4080
  29. #define TC_WEN 0x4088
  30. #define TC_REN 0x408c
  31. #define TC_FBEN 0x4090
  32. #define TC_PRR 0x40ea
  33. /* These defines match the X window system */
  34. #define RR_CLEAR 0x0
  35. #define RR_COPY 0x3
  36. #define RR_NOOP 0x5
  37. #define RR_XOR 0x6
  38. #define RR_INVERT 0xa
  39. #define RR_COPYINVERTED 0xc
  40. #define RR_SET 0xf
  41. /* blitter regs */
  42. #define BUSY 0x4044
  43. #define WMRR 0x40ef
  44. #define SOURCE_X 0x40f2
  45. #define SOURCE_Y 0x40f6
  46. #define DEST_X 0x40fa
  47. #define DEST_Y 0x40fe
  48. #define WHEIGHT 0x4106
  49. #define WWIDTH 0x4102
  50. #define WMOVE 0x409c
  51. static struct fb_var_screeninfo hpfb_defined = {
  52. .red = {
  53. .length = 8,
  54. },
  55. .green = {
  56. .length = 8,
  57. },
  58. .blue = {
  59. .length = 8,
  60. },
  61. .activate = FB_ACTIVATE_NOW,
  62. .height = -1,
  63. .width = -1,
  64. .vmode = FB_VMODE_NONINTERLACED,
  65. };
  66. static int hpfb_setcolreg(unsigned regno, unsigned red, unsigned green,
  67. unsigned blue, unsigned transp,
  68. struct fb_info *info)
  69. {
  70. /* use MSBs */
  71. unsigned char _red =red>>8;
  72. unsigned char _green=green>>8;
  73. unsigned char _blue =blue>>8;
  74. unsigned char _regno=regno;
  75. /*
  76. * Set a single color register. The values supplied are
  77. * already rounded down to the hardware's capabilities
  78. * (according to the entries in the `var' structure). Return
  79. * != 0 for invalid regno.
  80. */
  81. if (regno >= info->cmap.len)
  82. return 1;
  83. while (in_be16(fb_regs + 0x6002) & 0x4) udelay(1);
  84. out_be16(fb_regs + 0x60ba, 0xff);
  85. out_be16(fb_regs + 0x60b2, _red);
  86. out_be16(fb_regs + 0x60b4, _green);
  87. out_be16(fb_regs + 0x60b6, _blue);
  88. out_be16(fb_regs + 0x60b8, ~_regno);
  89. out_be16(fb_regs + 0x60f0, 0xff);
  90. udelay(100);
  91. while (in_be16(fb_regs + 0x6002) & 0x4) udelay(1);
  92. out_be16(fb_regs + 0x60b2, 0);
  93. out_be16(fb_regs + 0x60b4, 0);
  94. out_be16(fb_regs + 0x60b6, 0);
  95. out_be16(fb_regs + 0x60b8, 0);
  96. return 0;
  97. }
  98. /* 0 unblank, 1 blank, 2 no vsync, 3 no hsync, 4 off */
  99. static int hpfb_blank(int blank, struct fb_info *info)
  100. {
  101. out_8(fb_regs + TC_NBLANK, (blank ? 0x00 : fb_bitmask));
  102. return 0;
  103. }
  104. static void topcat_blit(int x0, int y0, int x1, int y1, int w, int h, int rr)
  105. {
  106. if (rr >= 0) {
  107. while (in_8(fb_regs + BUSY) & fb_bitmask)
  108. ;
  109. }
  110. out_8(fb_regs + TC_FBEN, fb_bitmask);
  111. if (rr >= 0) {
  112. out_8(fb_regs + TC_WEN, fb_bitmask);
  113. out_8(fb_regs + WMRR, rr);
  114. }
  115. out_be16(fb_regs + SOURCE_X, x0);
  116. out_be16(fb_regs + SOURCE_Y, y0);
  117. out_be16(fb_regs + DEST_X, x1);
  118. out_be16(fb_regs + DEST_Y, y1);
  119. out_be16(fb_regs + WWIDTH, w);
  120. out_be16(fb_regs + WHEIGHT, h);
  121. out_8(fb_regs + WMOVE, fb_bitmask);
  122. }
  123. static void hpfb_copyarea(struct fb_info *info, const struct fb_copyarea *area)
  124. {
  125. topcat_blit(area->sx, area->sy, area->dx, area->dy, area->width, area->height, RR_COPY);
  126. }
  127. static void hpfb_fillrect(struct fb_info *p, const struct fb_fillrect *region)
  128. {
  129. u8 clr;
  130. clr = region->color & 0xff;
  131. while (in_8(fb_regs + BUSY) & fb_bitmask)
  132. ;
  133. /* Foreground */
  134. out_8(fb_regs + TC_WEN, fb_bitmask & clr);
  135. out_8(fb_regs + WMRR, (region->rop == ROP_COPY ? RR_SET : RR_INVERT));
  136. /* Background */
  137. out_8(fb_regs + TC_WEN, fb_bitmask & ~clr);
  138. out_8(fb_regs + WMRR, (region->rop == ROP_COPY ? RR_CLEAR : RR_NOOP));
  139. topcat_blit(region->dx, region->dy, region->dx, region->dy, region->width, region->height, -1);
  140. }
  141. static int hpfb_sync(struct fb_info *info)
  142. {
  143. /*
  144. * Since we also access the framebuffer directly, we have to wait
  145. * until the block mover is finished
  146. */
  147. while (in_8(fb_regs + BUSY) & fb_bitmask)
  148. ;
  149. out_8(fb_regs + TC_WEN, fb_bitmask);
  150. out_8(fb_regs + TC_PRR, RR_COPY);
  151. out_8(fb_regs + TC_FBEN, fb_bitmask);
  152. return 0;
  153. }
  154. static struct fb_ops hpfb_ops = {
  155. .owner = THIS_MODULE,
  156. .fb_setcolreg = hpfb_setcolreg,
  157. .fb_blank = hpfb_blank,
  158. .fb_fillrect = hpfb_fillrect,
  159. .fb_copyarea = hpfb_copyarea,
  160. .fb_imageblit = cfb_imageblit,
  161. .fb_sync = hpfb_sync,
  162. };
  163. /* Common to all HP framebuffers */
  164. #define HPFB_FBWMSB 0x05 /* Frame buffer width */
  165. #define HPFB_FBWLSB 0x07
  166. #define HPFB_FBHMSB 0x09 /* Frame buffer height */
  167. #define HPFB_FBHLSB 0x0b
  168. #define HPFB_DWMSB 0x0d /* Display width */
  169. #define HPFB_DWLSB 0x0f
  170. #define HPFB_DHMSB 0x11 /* Display height */
  171. #define HPFB_DHLSB 0x13
  172. #define HPFB_NUMPLANES 0x5b /* Number of colour planes */
  173. #define HPFB_FBOMSB 0x5d /* Frame buffer offset */
  174. #define HPFB_FBOLSB 0x5f
  175. static int __devinit hpfb_init_one(unsigned long phys_base,
  176. unsigned long virt_base)
  177. {
  178. unsigned long fboff, fb_width, fb_height, fb_start;
  179. int ret;
  180. fb_regs = virt_base;
  181. fboff = (in_8(fb_regs + HPFB_FBOMSB) << 8) | in_8(fb_regs + HPFB_FBOLSB);
  182. fb_info.fix.smem_start = (in_8(fb_regs + fboff) << 16);
  183. if (phys_base >= DIOII_BASE) {
  184. fb_info.fix.smem_start += phys_base;
  185. }
  186. if (DIO_SECID(fb_regs) != DIO_ID2_TOPCAT) {
  187. /* This is the magic incantation the HP X server uses to make Catseye boards work. */
  188. while (in_be16(fb_regs+0x4800) & 1)
  189. ;
  190. out_be16(fb_regs+0x4800, 0); /* Catseye status */
  191. out_be16(fb_regs+0x4510, 0); /* VB */
  192. out_be16(fb_regs+0x4512, 0); /* TCNTRL */
  193. out_be16(fb_regs+0x4514, 0); /* ACNTRL */
  194. out_be16(fb_regs+0x4516, 0); /* PNCNTRL */
  195. out_be16(fb_regs+0x4206, 0x90); /* RUG Command/Status */
  196. out_be16(fb_regs+0x60a2, 0); /* Overlay Mask */
  197. out_be16(fb_regs+0x60bc, 0); /* Ram Select */
  198. }
  199. /*
  200. * Fill in the available video resolution
  201. */
  202. fb_width = (in_8(fb_regs + HPFB_FBWMSB) << 8) | in_8(fb_regs + HPFB_FBWLSB);
  203. fb_info.fix.line_length = fb_width;
  204. fb_height = (in_8(fb_regs + HPFB_FBHMSB) << 8) | in_8(fb_regs + HPFB_FBHLSB);
  205. fb_info.fix.smem_len = fb_width * fb_height;
  206. fb_start = (unsigned long)ioremap_writethrough(fb_info.fix.smem_start,
  207. fb_info.fix.smem_len);
  208. hpfb_defined.xres = (in_8(fb_regs + HPFB_DWMSB) << 8) | in_8(fb_regs + HPFB_DWLSB);
  209. hpfb_defined.yres = (in_8(fb_regs + HPFB_DHMSB) << 8) | in_8(fb_regs + HPFB_DHLSB);
  210. hpfb_defined.xres_virtual = hpfb_defined.xres;
  211. hpfb_defined.yres_virtual = hpfb_defined.yres;
  212. hpfb_defined.bits_per_pixel = in_8(fb_regs + HPFB_NUMPLANES);
  213. printk(KERN_INFO "hpfb: framebuffer at 0x%lx, mapped to 0x%lx, size %dk\n",
  214. fb_info.fix.smem_start, fb_start, fb_info.fix.smem_len/1024);
  215. printk(KERN_INFO "hpfb: mode is %dx%dx%d, linelength=%d\n",
  216. hpfb_defined.xres, hpfb_defined.yres, hpfb_defined.bits_per_pixel, fb_info.fix.line_length);
  217. /*
  218. * Give the hardware a bit of a prod and work out how many bits per
  219. * pixel are supported.
  220. */
  221. out_8(fb_regs + TC_WEN, 0xff);
  222. out_8(fb_regs + TC_PRR, RR_COPY);
  223. out_8(fb_regs + TC_FBEN, 0xff);
  224. out_8(fb_start, 0xff);
  225. fb_bitmask = in_8(fb_start);
  226. out_8(fb_start, 0);
  227. /*
  228. * Enable reading/writing of all the planes.
  229. */
  230. out_8(fb_regs + TC_WEN, fb_bitmask);
  231. out_8(fb_regs + TC_PRR, RR_COPY);
  232. out_8(fb_regs + TC_REN, fb_bitmask);
  233. out_8(fb_regs + TC_FBEN, fb_bitmask);
  234. /*
  235. * Clear the screen.
  236. */
  237. topcat_blit(0, 0, 0, 0, fb_width, fb_height, RR_CLEAR);
  238. /*
  239. * Let there be consoles..
  240. */
  241. if (DIO_SECID(fb_regs) == DIO_ID2_TOPCAT)
  242. strcat(fb_info.fix.id, "Topcat");
  243. else
  244. strcat(fb_info.fix.id, "Catseye");
  245. fb_info.fbops = &hpfb_ops;
  246. fb_info.flags = FBINFO_DEFAULT;
  247. fb_info.var = hpfb_defined;
  248. fb_info.screen_base = (char *)fb_start;
  249. ret = fb_alloc_cmap(&fb_info.cmap, 1 << hpfb_defined.bits_per_pixel, 0);
  250. if (ret < 0)
  251. goto unmap_screen_base;
  252. ret = register_framebuffer(&fb_info);
  253. if (ret < 0)
  254. goto dealloc_cmap;
  255. printk(KERN_INFO "fb%d: %s frame buffer device\n",
  256. fb_info.node, fb_info.fix.id);
  257. return 0;
  258. dealloc_cmap:
  259. fb_dealloc_cmap(&fb_info.cmap);
  260. unmap_screen_base:
  261. if (fb_info.screen_base) {
  262. iounmap(fb_info.screen_base);
  263. fb_info.screen_base = NULL;
  264. }
  265. return ret;
  266. }
  267. /*
  268. * Check that the secondary ID indicates that we have some hope of working with this
  269. * framebuffer. The catseye boards are pretty much like topcats and we can muddle through.
  270. */
  271. #define topcat_sid_ok(x) (((x) == DIO_ID2_LRCATSEYE) || ((x) == DIO_ID2_HRCCATSEYE) \
  272. || ((x) == DIO_ID2_HRMCATSEYE) || ((x) == DIO_ID2_TOPCAT))
  273. /*
  274. * Initialise the framebuffer
  275. */
  276. static int __devinit hpfb_dio_probe(struct dio_dev * d, const struct dio_device_id * ent)
  277. {
  278. unsigned long paddr, vaddr;
  279. paddr = d->resource.start;
  280. if (!request_mem_region(d->resource.start, resource_size(&d->resource), d->name))
  281. return -EBUSY;
  282. if (d->scode >= DIOII_SCBASE) {
  283. vaddr = (unsigned long)ioremap(paddr, resource_size(&d->resource));
  284. } else {
  285. vaddr = paddr + DIO_VIRADDRBASE;
  286. }
  287. printk(KERN_INFO "Topcat found at DIO select code %d "
  288. "(secondary id %02x)\n", d->scode, (d->id >> 8) & 0xff);
  289. if (hpfb_init_one(paddr, vaddr)) {
  290. if (d->scode >= DIOII_SCBASE)
  291. iounmap((void *)vaddr);
  292. return -ENOMEM;
  293. }
  294. return 0;
  295. }
  296. static void __devexit hpfb_remove_one(struct dio_dev *d)
  297. {
  298. unregister_framebuffer(&fb_info);
  299. if (d->scode >= DIOII_SCBASE)
  300. iounmap((void *)fb_regs);
  301. release_mem_region(d->resource.start, resource_size(&d->resource));
  302. fb_dealloc_cmap(&fb_info.cmap);
  303. if (fb_info.screen_base)
  304. iounmap(fb_info.screen_base);
  305. }
  306. static struct dio_device_id hpfb_dio_tbl[] = {
  307. { DIO_ENCODE_ID(DIO_ID_FBUFFER, DIO_ID2_LRCATSEYE) },
  308. { DIO_ENCODE_ID(DIO_ID_FBUFFER, DIO_ID2_HRCCATSEYE) },
  309. { DIO_ENCODE_ID(DIO_ID_FBUFFER, DIO_ID2_HRMCATSEYE) },
  310. { DIO_ENCODE_ID(DIO_ID_FBUFFER, DIO_ID2_TOPCAT) },
  311. { 0 }
  312. };
  313. static struct dio_driver hpfb_driver = {
  314. .name = "hpfb",
  315. .id_table = hpfb_dio_tbl,
  316. .probe = hpfb_dio_probe,
  317. .remove = __devexit_p(hpfb_remove_one),
  318. };
  319. int __init hpfb_init(void)
  320. {
  321. unsigned int sid;
  322. mm_segment_t fs;
  323. unsigned char i;
  324. int err;
  325. /* Topcats can be on the internal IO bus or real DIO devices.
  326. * The internal variant sits at 0x560000; it has primary
  327. * and secondary ID registers just like the DIO version.
  328. * So we merge the two detection routines.
  329. *
  330. * Perhaps this #define should be in a global header file:
  331. * I believe it's common to all internal fbs, not just topcat.
  332. */
  333. #define INTFBVADDR 0xf0560000
  334. #define INTFBPADDR 0x560000
  335. if (!MACH_IS_HP300)
  336. return -ENODEV;
  337. if (fb_get_options("hpfb", NULL))
  338. return -ENODEV;
  339. err = dio_register_driver(&hpfb_driver);
  340. if (err)
  341. return err;
  342. fs = get_fs();
  343. set_fs(KERNEL_DS);
  344. err = get_user(i, (unsigned char *)INTFBVADDR + DIO_IDOFF);
  345. set_fs(fs);
  346. if (!err && (i == DIO_ID_FBUFFER) && topcat_sid_ok(sid = DIO_SECID(INTFBVADDR))) {
  347. if (!request_mem_region(INTFBPADDR, DIO_DEVSIZE, "Internal Topcat"))
  348. return -EBUSY;
  349. printk(KERN_INFO "Internal Topcat found (secondary id %02x)\n", sid);
  350. if (hpfb_init_one(INTFBPADDR, INTFBVADDR)) {
  351. return -ENOMEM;
  352. }
  353. }
  354. return 0;
  355. }
  356. void __exit hpfb_cleanup_module(void)
  357. {
  358. dio_unregister_driver(&hpfb_driver);
  359. }
  360. module_init(hpfb_init);
  361. module_exit(hpfb_cleanup_module);
  362. MODULE_LICENSE("GPL");