bw2.c 9.9 KB

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