bw2.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. /* bw2.c: BWTWO frame buffer driver
  2. *
  3. * Copyright (C) 2003 David S. Miller (davem@redhat.com)
  4. * Copyright (C) 1996,1998 Jakub Jelinek (jj@ultra.linux.cz)
  5. * Copyright (C) 1996 Miguel de Icaza (miguel@nuclecu.unam.mx)
  6. * Copyright (C) 1997 Eddie C. Dost (ecd@skynet.be)
  7. *
  8. * Driver layout based loosely on tgafb.c, see that file for credits.
  9. */
  10. #include <linux/module.h>
  11. #include <linux/kernel.h>
  12. #include <linux/errno.h>
  13. #include <linux/string.h>
  14. #include <linux/slab.h>
  15. #include <linux/delay.h>
  16. #include <linux/init.h>
  17. #include <linux/fb.h>
  18. #include <linux/mm.h>
  19. #include <asm/io.h>
  20. #include <asm/sbus.h>
  21. #include <asm/oplib.h>
  22. #include <asm/fbio.h>
  23. #ifdef CONFIG_SPARC32
  24. #include <asm/sun4paddr.h>
  25. #endif
  26. #include "sbuslib.h"
  27. /*
  28. * Local functions.
  29. */
  30. static int bw2_blank(int, struct fb_info *);
  31. static int bw2_mmap(struct fb_info *, struct vm_area_struct *);
  32. static int bw2_ioctl(struct fb_info *, unsigned int, unsigned long);
  33. /*
  34. * Frame buffer operations
  35. */
  36. static struct fb_ops bw2_ops = {
  37. .owner = THIS_MODULE,
  38. .fb_blank = bw2_blank,
  39. .fb_fillrect = cfb_fillrect,
  40. .fb_copyarea = cfb_copyarea,
  41. .fb_imageblit = cfb_imageblit,
  42. .fb_mmap = bw2_mmap,
  43. .fb_ioctl = bw2_ioctl,
  44. #ifdef CONFIG_COMPAT
  45. .fb_compat_ioctl = sbusfb_compat_ioctl,
  46. #endif
  47. };
  48. /* OBio addresses for the bwtwo registers */
  49. #define BWTWO_REGISTER_OFFSET 0x400000
  50. struct bt_regs {
  51. volatile u32 addr;
  52. volatile u32 color_map;
  53. volatile u32 control;
  54. volatile u32 cursor;
  55. };
  56. struct bw2_regs {
  57. struct bt_regs cmap;
  58. volatile u8 control;
  59. volatile u8 status;
  60. volatile u8 cursor_start;
  61. volatile u8 cursor_end;
  62. volatile u8 h_blank_start;
  63. volatile u8 h_blank_end;
  64. volatile u8 h_sync_start;
  65. volatile u8 h_sync_end;
  66. volatile u8 comp_sync_end;
  67. volatile u8 v_blank_start_high;
  68. volatile u8 v_blank_start_low;
  69. volatile u8 v_blank_end;
  70. volatile u8 v_sync_start;
  71. volatile u8 v_sync_end;
  72. volatile u8 xfer_holdoff_start;
  73. volatile u8 xfer_holdoff_end;
  74. };
  75. /* Status Register Constants */
  76. #define BWTWO_SR_RES_MASK 0x70
  77. #define BWTWO_SR_1600_1280 0x50
  78. #define BWTWO_SR_1152_900_76_A 0x40
  79. #define BWTWO_SR_1152_900_76_B 0x60
  80. #define BWTWO_SR_ID_MASK 0x0f
  81. #define BWTWO_SR_ID_MONO 0x02
  82. #define BWTWO_SR_ID_MONO_ECL 0x03
  83. #define BWTWO_SR_ID_MSYNC 0x04
  84. #define BWTWO_SR_ID_NOCONN 0x0a
  85. /* Control Register Constants */
  86. #define BWTWO_CTL_ENABLE_INTS 0x80
  87. #define BWTWO_CTL_ENABLE_VIDEO 0x40
  88. #define BWTWO_CTL_ENABLE_TIMING 0x20
  89. #define BWTWO_CTL_ENABLE_CURCMP 0x10
  90. #define BWTWO_CTL_XTAL_MASK 0x0C
  91. #define BWTWO_CTL_DIVISOR_MASK 0x03
  92. /* Status Register Constants */
  93. #define BWTWO_STAT_PENDING_INT 0x80
  94. #define BWTWO_STAT_MSENSE_MASK 0x70
  95. #define BWTWO_STAT_ID_MASK 0x0f
  96. struct bw2_par {
  97. spinlock_t lock;
  98. struct bw2_regs __iomem *regs;
  99. u32 flags;
  100. #define BW2_FLAG_BLANKED 0x00000001
  101. unsigned long physbase;
  102. unsigned long fbsize;
  103. struct sbus_dev *sdev;
  104. };
  105. /**
  106. * bw2_blank - Optional function. Blanks the display.
  107. * @blank_mode: the blank mode we want.
  108. * @info: frame buffer structure that represents a single frame buffer
  109. */
  110. static int
  111. bw2_blank(int blank, struct fb_info *info)
  112. {
  113. struct bw2_par *par = (struct bw2_par *) info->par;
  114. struct bw2_regs __iomem *regs = par->regs;
  115. unsigned long flags;
  116. u8 val;
  117. spin_lock_irqsave(&par->lock, flags);
  118. switch (blank) {
  119. case FB_BLANK_UNBLANK: /* Unblanking */
  120. val = sbus_readb(&regs->control);
  121. val |= BWTWO_CTL_ENABLE_VIDEO;
  122. sbus_writeb(val, &regs->control);
  123. par->flags &= ~BW2_FLAG_BLANKED;
  124. break;
  125. case FB_BLANK_NORMAL: /* Normal blanking */
  126. case FB_BLANK_VSYNC_SUSPEND: /* VESA blank (vsync off) */
  127. case FB_BLANK_HSYNC_SUSPEND: /* VESA blank (hsync off) */
  128. case FB_BLANK_POWERDOWN: /* Poweroff */
  129. val = sbus_readb(&regs->control);
  130. val &= ~BWTWO_CTL_ENABLE_VIDEO;
  131. sbus_writeb(val, &regs->control);
  132. par->flags |= BW2_FLAG_BLANKED;
  133. break;
  134. }
  135. spin_unlock_irqrestore(&par->lock, flags);
  136. return 0;
  137. }
  138. static struct sbus_mmap_map bw2_mmap_map[] = {
  139. {
  140. .size = SBUS_MMAP_FBSIZE(1)
  141. },
  142. { .size = 0 }
  143. };
  144. static int bw2_mmap(struct fb_info *info, struct vm_area_struct *vma)
  145. {
  146. struct bw2_par *par = (struct bw2_par *)info->par;
  147. return sbusfb_mmap_helper(bw2_mmap_map,
  148. par->physbase, par->fbsize,
  149. (par->sdev ?
  150. par->sdev->reg_addrs[0].which_io :
  151. 0),
  152. vma);
  153. }
  154. static int bw2_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
  155. {
  156. struct bw2_par *par = (struct bw2_par *) info->par;
  157. return sbusfb_ioctl_helper(cmd, arg, info,
  158. FBTYPE_SUN2BW, 1, par->fbsize);
  159. }
  160. /*
  161. * Initialisation
  162. */
  163. static void
  164. bw2_init_fix(struct fb_info *info, int linebytes)
  165. {
  166. strlcpy(info->fix.id, "bwtwo", sizeof(info->fix.id));
  167. info->fix.type = FB_TYPE_PACKED_PIXELS;
  168. info->fix.visual = FB_VISUAL_MONO01;
  169. info->fix.line_length = linebytes;
  170. info->fix.accel = FB_ACCEL_SUN_BWTWO;
  171. }
  172. static u8 bw2regs_1600[] __initdata = {
  173. 0x14, 0x8b, 0x15, 0x28, 0x16, 0x03, 0x17, 0x13,
  174. 0x18, 0x7b, 0x19, 0x05, 0x1a, 0x34, 0x1b, 0x2e,
  175. 0x1c, 0x00, 0x1d, 0x0a, 0x1e, 0xff, 0x1f, 0x01,
  176. 0x10, 0x21, 0
  177. };
  178. static u8 bw2regs_ecl[] __initdata = {
  179. 0x14, 0x65, 0x15, 0x1e, 0x16, 0x04, 0x17, 0x0c,
  180. 0x18, 0x5e, 0x19, 0x03, 0x1a, 0xa7, 0x1b, 0x23,
  181. 0x1c, 0x00, 0x1d, 0x08, 0x1e, 0xff, 0x1f, 0x01,
  182. 0x10, 0x20, 0
  183. };
  184. static u8 bw2regs_analog[] __initdata = {
  185. 0x14, 0xbb, 0x15, 0x2b, 0x16, 0x03, 0x17, 0x13,
  186. 0x18, 0xb0, 0x19, 0x03, 0x1a, 0xa6, 0x1b, 0x22,
  187. 0x1c, 0x01, 0x1d, 0x05, 0x1e, 0xff, 0x1f, 0x01,
  188. 0x10, 0x20, 0
  189. };
  190. static u8 bw2regs_76hz[] __initdata = {
  191. 0x14, 0xb7, 0x15, 0x27, 0x16, 0x03, 0x17, 0x0f,
  192. 0x18, 0xae, 0x19, 0x03, 0x1a, 0xae, 0x1b, 0x2a,
  193. 0x1c, 0x01, 0x1d, 0x09, 0x1e, 0xff, 0x1f, 0x01,
  194. 0x10, 0x24, 0
  195. };
  196. static u8 bw2regs_66hz[] __initdata = {
  197. 0x14, 0xbb, 0x15, 0x2b, 0x16, 0x04, 0x17, 0x14,
  198. 0x18, 0xae, 0x19, 0x03, 0x1a, 0xa8, 0x1b, 0x24,
  199. 0x1c, 0x01, 0x1d, 0x05, 0x1e, 0xff, 0x1f, 0x01,
  200. 0x10, 0x20, 0
  201. };
  202. static void bw2_do_default_mode(struct bw2_par *par, struct fb_info *info,
  203. int *linebytes)
  204. {
  205. u8 status, mon;
  206. u8 *p;
  207. status = sbus_readb(&par->regs->status);
  208. mon = status & BWTWO_SR_RES_MASK;
  209. switch (status & BWTWO_SR_ID_MASK) {
  210. case BWTWO_SR_ID_MONO_ECL:
  211. if (mon == BWTWO_SR_1600_1280) {
  212. p = bw2regs_1600;
  213. info->var.xres = info->var.xres_virtual = 1600;
  214. info->var.yres = info->var.yres_virtual = 1280;
  215. *linebytes = 1600 / 8;
  216. } else
  217. p = bw2regs_ecl;
  218. break;
  219. case BWTWO_SR_ID_MONO:
  220. p = bw2regs_analog;
  221. break;
  222. case BWTWO_SR_ID_MSYNC:
  223. if (mon == BWTWO_SR_1152_900_76_A ||
  224. mon == BWTWO_SR_1152_900_76_B)
  225. p = bw2regs_76hz;
  226. else
  227. p = bw2regs_66hz;
  228. break;
  229. case BWTWO_SR_ID_NOCONN:
  230. return;
  231. default:
  232. prom_printf("bw2: can't handle SR %02x\n",
  233. status);
  234. prom_halt();
  235. }
  236. for ( ; *p; p += 2) {
  237. u8 __iomem *regp = &((u8 __iomem *)par->regs)[p[0]];
  238. sbus_writeb(p[1], regp);
  239. }
  240. }
  241. struct all_info {
  242. struct fb_info info;
  243. struct bw2_par par;
  244. struct list_head list;
  245. };
  246. static LIST_HEAD(bw2_list);
  247. static void bw2_init_one(struct sbus_dev *sdev)
  248. {
  249. struct all_info *all;
  250. struct resource *resp;
  251. #ifdef CONFIG_SUN4
  252. struct resource res;
  253. #endif
  254. int linebytes;
  255. all = kmalloc(sizeof(*all), GFP_KERNEL);
  256. if (!all) {
  257. printk(KERN_ERR "bw2: Cannot allocate memory.\n");
  258. return;
  259. }
  260. memset(all, 0, sizeof(*all));
  261. INIT_LIST_HEAD(&all->list);
  262. spin_lock_init(&all->par.lock);
  263. all->par.sdev = sdev;
  264. #ifdef CONFIG_SUN4
  265. if (!sdev) {
  266. all->par.physbase = sun4_bwtwo_physaddr;
  267. res.start = sun4_bwtwo_physaddr;
  268. res.end = res.start + BWTWO_REGISTER_OFFSET + sizeof(struct bw2_regs) - 1;
  269. res.flags = IORESOURCE_IO;
  270. resp = &res;
  271. all->info.var.xres = all->info.var.xres_virtual = 1152;
  272. all->info.var.yres = all->info.var.yres_virtual = 900;
  273. all->info.var.bits_per_pixel = 1;
  274. linebytes = 1152 / 8;
  275. } else
  276. #else
  277. {
  278. BUG_ON(!sdev);
  279. all->par.physbase = sdev->reg_addrs[0].phys_addr;
  280. resp = &sdev->resource[0];
  281. sbusfb_fill_var(&all->info.var, (sdev ? sdev->prom_node : 0), 1);
  282. linebytes = prom_getintdefault(sdev->prom_node, "linebytes",
  283. all->info.var.xres);
  284. }
  285. #endif
  286. all->info.var.red.length = all->info.var.green.length =
  287. all->info.var.blue.length = all->info.var.bits_per_pixel;
  288. all->info.var.red.offset = all->info.var.green.offset =
  289. all->info.var.blue.offset = 0;
  290. all->par.regs = sbus_ioremap(resp, BWTWO_REGISTER_OFFSET,
  291. sizeof(struct bw2_regs), "bw2 regs");
  292. if (sdev && !prom_getbool(sdev->prom_node, "width"))
  293. bw2_do_default_mode(&all->par, &all->info, &linebytes);
  294. all->par.fbsize = PAGE_ALIGN(linebytes * all->info.var.yres);
  295. all->info.flags = FBINFO_DEFAULT;
  296. all->info.fbops = &bw2_ops;
  297. #if defined(CONFIG_SPARC32)
  298. if (sdev)
  299. all->info.screen_base = (char __iomem *)
  300. prom_getintdefault(sdev->prom_node, "address", 0);
  301. #endif
  302. if (!all->info.screen_base)
  303. all->info.screen_base =
  304. sbus_ioremap(resp, 0, all->par.fbsize, "bw2 ram");
  305. all->info.par = &all->par;
  306. bw2_blank(0, &all->info);
  307. bw2_init_fix(&all->info, linebytes);
  308. if (register_framebuffer(&all->info) < 0) {
  309. printk(KERN_ERR "bw2: Could not register framebuffer.\n");
  310. kfree(all);
  311. return;
  312. }
  313. list_add(&all->list, &bw2_list);
  314. printk("bw2: bwtwo at %lx:%lx\n",
  315. (long) (sdev ? sdev->reg_addrs[0].which_io : 0),
  316. (long) all->par.physbase);
  317. }
  318. int __init bw2_init(void)
  319. {
  320. struct sbus_bus *sbus;
  321. struct sbus_dev *sdev;
  322. if (fb_get_options("bw2fb", NULL))
  323. return -ENODEV;
  324. #ifdef CONFIG_SUN4
  325. bw2_init_one(NULL);
  326. #endif
  327. for_all_sbusdev(sdev, sbus) {
  328. if (!strcmp(sdev->prom_name, "bwtwo"))
  329. bw2_init_one(sdev);
  330. }
  331. return 0;
  332. }
  333. void __exit bw2_exit(void)
  334. {
  335. struct list_head *pos, *tmp;
  336. list_for_each_safe(pos, tmp, &bw2_list) {
  337. struct all_info *all = list_entry(pos, typeof(*all), list);
  338. unregister_framebuffer(&all->info);
  339. kfree(all);
  340. }
  341. }
  342. int __init
  343. bw2_setup(char *arg)
  344. {
  345. /* No cmdline options yet... */
  346. return 0;
  347. }
  348. module_init(bw2_init);
  349. #ifdef MODULE
  350. module_exit(bw2_exit);
  351. #endif
  352. MODULE_DESCRIPTION("framebuffer driver for BWTWO chipsets");
  353. MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
  354. MODULE_LICENSE("GPL");