linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / drivers / video / bw2.c
index c66e3d5..c029db4 100644 (file)
@@ -1,6 +1,6 @@
 /* bw2.c: BWTWO frame buffer driver
  *
- * Copyright (C) 2003, 2006 David S. Miller (davem@davemloft.net)
+ * Copyright (C) 2003 David S. Miller (davem@redhat.com)
  * Copyright (C) 1996,1998 Jakub Jelinek (jj@ultra.linux.cz)
  * Copyright (C) 1996 Miguel de Icaza (miguel@nuclecu.unam.mx)
  * Copyright (C) 1997 Eddie C. Dost (ecd@skynet.be)
 #include <linux/mm.h>
 
 #include <asm/io.h>
+#include <asm/sbus.h>
 #include <asm/oplib.h>
-#include <asm/prom.h>
-#include <asm/of_device.h>
 #include <asm/fbio.h>
 
+#ifdef CONFIG_SPARC32
+#include <asm/sun4paddr.h>
+#endif
+
 #include "sbuslib.h"
 
 /*
@@ -56,30 +59,30 @@ static struct fb_ops bw2_ops = {
 #define BWTWO_REGISTER_OFFSET 0x400000
 
 struct bt_regs {
-       u32 addr;
-       u32 color_map;
-       u32 control;
-       u32 cursor;
+       volatile u32 addr;
+       volatile u32 color_map;
+       volatile u32 control;
+       volatile u32 cursor;
 };
 
 struct bw2_regs {
        struct bt_regs  cmap;
-       u8      control;
-       u8      status;
-       u8      cursor_start;
-       u8      cursor_end;
-       u8      h_blank_start;
-       u8      h_blank_end;
-       u8      h_sync_start;
-       u8      h_sync_end;
-       u8      comp_sync_end;
-       u8      v_blank_start_high;
-       u8      v_blank_start_low;
-       u8      v_blank_end;
-       u8      v_sync_start;
-       u8      v_sync_end;
-       u8      xfer_holdoff_start;
-       u8      xfer_holdoff_end;
+       volatile u8     control;
+       volatile u8     status;
+       volatile u8     cursor_start;
+       volatile u8     cursor_end;
+       volatile u8     h_blank_start;
+       volatile u8     h_blank_end;
+       volatile u8     h_sync_start;
+       volatile u8     h_sync_end;
+       volatile u8     comp_sync_end;
+       volatile u8     v_blank_start_high;
+       volatile u8     v_blank_start_low;
+       volatile u8     v_blank_end;
+       volatile u8     v_sync_start;
+       volatile u8     v_sync_end;
+       volatile u8     xfer_holdoff_start;
+       volatile u8     xfer_holdoff_end;
 };
 
 /* Status Register Constants */
@@ -114,8 +117,9 @@ struct bw2_par {
 #define BW2_FLAG_BLANKED       0x00000001
 
        unsigned long           physbase;
-       unsigned long           which_io;
        unsigned long           fbsize;
+
+       struct sbus_dev         *sdev;
 };
 
 /**
@@ -170,7 +174,9 @@ static int bw2_mmap(struct fb_info *info, struct vm_area_struct *vma)
 
        return sbusfb_mmap_helper(bw2_mmap_map,
                                  par->physbase, par->fbsize,
-                                 par->which_io,
+                                 (par->sdev ?
+                                  par->sdev->reg_addrs[0].which_io :
+                                  0),
                                  vma);
 }
 
@@ -282,124 +288,140 @@ static void bw2_do_default_mode(struct bw2_par *par, struct fb_info *info,
 struct all_info {
        struct fb_info info;
        struct bw2_par par;
+       struct list_head list;
 };
+static LIST_HEAD(bw2_list);
 
-static int __devinit bw2_init_one(struct of_device *op)
+static void bw2_init_one(struct sbus_dev *sdev)
 {
-       struct device_node *dp = op->node;
        struct all_info *all;
-       int linebytes, err;
-
-       all = kzalloc(sizeof(*all), GFP_KERNEL);
-       if (!all)
-               return -ENOMEM;
-
-       spin_lock_init(&all->par.lock);
+       struct resource *resp;
+#ifdef CONFIG_SUN4
+       struct resource res;
+#endif
+       int linebytes;
 
-       all->par.physbase = op->resource[0].start;
-       all->par.which_io = op->resource[0].flags & IORESOURCE_BITS;
+       all = kmalloc(sizeof(*all), GFP_KERNEL);
+       if (!all) {
+               printk(KERN_ERR "bw2: Cannot allocate memory.\n");
+               return;
+       }
+       memset(all, 0, sizeof(*all));
 
-       sbusfb_fill_var(&all->info.var, dp->node, 1);
-       linebytes = of_getintprop_default(dp, "linebytes",
-                                         all->info.var.xres);
+       INIT_LIST_HEAD(&all->list);
 
+       spin_lock_init(&all->par.lock);
+       all->par.sdev = sdev;
+
+#ifdef CONFIG_SUN4
+       if (!sdev) {
+               all->par.physbase = sun4_bwtwo_physaddr;
+               res.start = sun4_bwtwo_physaddr;
+               res.end = res.start + BWTWO_REGISTER_OFFSET + sizeof(struct bw2_regs) - 1;
+               res.flags = IORESOURCE_IO;
+               resp = &res;
+               all->info.var.xres = all->info.var.xres_virtual = 1152;
+               all->info.var.yres = all->info.var.yres_virtual = 900;
+               all->info.var.bits_per_pixel = 1;
+               linebytes = 1152 / 8;
+       } else
+#else
+       {
+               if (!sdev)
+                       BUG();
+               all->par.physbase = sdev->reg_addrs[0].phys_addr;
+               resp = &sdev->resource[0];
+               sbusfb_fill_var(&all->info.var, (sdev ? sdev->prom_node : 0), 1);
+               linebytes = prom_getintdefault(sdev->prom_node, "linebytes",
+                                              all->info.var.xres);
+       }
+#endif
        all->info.var.red.length = all->info.var.green.length =
                all->info.var.blue.length = all->info.var.bits_per_pixel;
        all->info.var.red.offset = all->info.var.green.offset =
                all->info.var.blue.offset = 0;
 
-       all->par.regs = of_ioremap(&op->resource[0], BWTWO_REGISTER_OFFSET,
-                                  sizeof(struct bw2_regs), "bw2 regs");
+       all->par.regs = sbus_ioremap(resp, BWTWO_REGISTER_OFFSET,
+                            sizeof(struct bw2_regs), "bw2 regs");
 
-       if (!of_find_property(dp, "width", NULL))
+       if (sdev && !prom_getbool(sdev->prom_node, "width"))
                bw2_do_default_mode(&all->par, &all->info, &linebytes);
 
        all->par.fbsize = PAGE_ALIGN(linebytes * all->info.var.yres);
 
        all->info.flags = FBINFO_DEFAULT;
        all->info.fbops = &bw2_ops;
-
-       all->info.screen_base =
-               sbus_ioremap(&op->resource[0], 0, all->par.fbsize, "bw2 ram");
+#if defined(CONFIG_SPARC32)
+       if (sdev)
+               all->info.screen_base = (char __iomem *)
+                       prom_getintdefault(sdev->prom_node, "address", 0);
+#endif
+       if (!all->info.screen_base)
+               all->info.screen_base =
+                       sbus_ioremap(resp, 0, all->par.fbsize, "bw2 ram");
        all->info.par = &all->par;
 
        bw2_blank(0, &all->info);
 
        bw2_init_fix(&all->info, linebytes);
 
-       err= register_framebuffer(&all->info);
-       if (err < 0) {
-               of_iounmap(all->par.regs, sizeof(struct bw2_regs));
-               of_iounmap(all->info.screen_base, all->par.fbsize);
+       if (register_framebuffer(&all->info) < 0) {
+               printk(KERN_ERR "bw2: Could not register framebuffer.\n");
                kfree(all);
-               return err;
+               return;
        }
 
-       dev_set_drvdata(&op->dev, all);
-
-       printk("%s: bwtwo at %lx:%lx\n",
-              dp->full_name,
-              all->par.which_io, all->par.physbase);
-
-       return 0;
-}
-
-static int __devinit bw2_probe(struct of_device *dev, const struct of_device_id *match)
-{
-       struct of_device *op = to_of_device(&dev->dev);
+       list_add(&all->list, &bw2_list);
 
-       return bw2_init_one(op);
+       printk("bw2: bwtwo at %lx:%lx\n",
+              (long) (sdev ? sdev->reg_addrs[0].which_io : 0),
+              (long) all->par.physbase);
 }
 
-static int __devexit bw2_remove(struct of_device *dev)
+int __init bw2_init(void)
 {
-       struct all_info *all = dev_get_drvdata(&dev->dev);
+       struct sbus_bus *sbus;
+       struct sbus_dev *sdev;
 
-       unregister_framebuffer(&all->info);
-
-       of_iounmap(all->par.regs, sizeof(struct bw2_regs));
-       of_iounmap(all->info.screen_base, all->par.fbsize);
-
-       kfree(all);
+       if (fb_get_options("bw2fb", NULL))
+               return -ENODEV;
 
-       dev_set_drvdata(&dev->dev, NULL);
+#ifdef CONFIG_SUN4
+       bw2_init_one(NULL);
+#endif
+       for_all_sbusdev(sdev, sbus) {
+               if (!strcmp(sdev->prom_name, "bwtwo"))
+                       bw2_init_one(sdev);
+       }
 
        return 0;
 }
 
-static struct of_device_id bw2_match[] = {
-       {
-               .name = "bwtwo",
-       },
-       {},
-};
-MODULE_DEVICE_TABLE(of, bw2_match);
-
-static struct of_platform_driver bw2_driver = {
-       .name           = "bw2",
-       .match_table    = bw2_match,
-       .probe          = bw2_probe,
-       .remove         = __devexit_p(bw2_remove),
-};
-
-static int __init bw2_init(void)
+void __exit bw2_exit(void)
 {
-       if (fb_get_options("bw2fb", NULL))
-               return -ENODEV;
+       struct list_head *pos, *tmp;
 
-       return of_register_driver(&bw2_driver, &of_bus_type);
+       list_for_each_safe(pos, tmp, &bw2_list) {
+               struct all_info *all = list_entry(pos, typeof(*all), list);
+
+               unregister_framebuffer(&all->info);
+               kfree(all);
+       }
 }
 
-static void __exit bw2_exit(void)
+int __init
+bw2_setup(char *arg)
 {
-       return of_unregister_driver(&bw2_driver);
+       /* No cmdline options yet... */
+       return 0;
 }
 
-
 module_init(bw2_init);
+
+#ifdef MODULE
 module_exit(bw2_exit);
+#endif
 
 MODULE_DESCRIPTION("framebuffer driver for BWTWO chipsets");
-MODULE_AUTHOR("David S. Miller <davem@davemloft.net>");
-MODULE_VERSION("2.0");
+MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
 MODULE_LICENSE("GPL");