Merge branch 'for-2.6.35' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie...
[safe/jmp/linux-2.6] / drivers / video / skeletonfb.c
index bb96cb6..89158bc 100644 (file)
@@ -14,7 +14,7 @@
  *  of it. 
  *
  *  First the roles of struct fb_info and struct display have changed. Struct
- *  display will go away. The way the the new framebuffer console code will
+ *  display will go away. The way the new framebuffer console code will
  *  work is that it will act to translate data about the tty/console in 
  *  struct vc_data to data in a device independent way in struct fb_info. Then
  *  various functions in struct fb_ops will be called to store the device 
@@ -51,6 +51,7 @@
 #include <linux/delay.h>
 #include <linux/fb.h>
 #include <linux/init.h>
+#include <linux/pci.h>
 
     /*
      *  This is just simple sample code.
      */
 
 /*
+ * Driver data
+ */
+static char *mode_option __devinitdata;
+
+/*
  *  If your driver supports multiple boards, you should make the  
  *  below data types arrays, or allocate them dynamically (using kmalloc()). 
  */ 
@@ -78,7 +84,7 @@ struct xxx_par;
  * if we don't use modedb. If we do use modedb see xxxfb_init how to use it
  * to get a fb_var_screeninfo. Otherwise define a default var as well. 
  */
-static struct fb_fix_screeninfo xxxfb_fix __initdata = {
+static struct fb_fix_screeninfo xxxfb_fix __devinitdata = {
        .id =           "FB's name", 
        .type =         FB_TYPE_PACKED_PIXELS,
        .visual =       FB_VISUAL_PSEUDOCOLOR,
@@ -126,7 +132,6 @@ static struct fb_info info;
 static struct xxx_par __initdata current_par;
 
 int xxxfb_init(void);
-int xxxfb_setup(char*);
 
 /**
  *     xxxfb_open - Optional function. Called when the framebuffer is
@@ -142,7 +147,7 @@ int xxxfb_setup(char*);
  *
  *     Returns negative errno on error, or zero on success.
  */
-static int xxxfb_open(const struct fb_info *info, int user)
+static int xxxfb_open(struct fb_info *info, int user)
 {
     return 0;
 }
@@ -161,7 +166,7 @@ static int xxxfb_open(const struct fb_info *info, int user)
  *
  *     Returns negative errno on error, or zero on success.
  */
-static int xxxfb_release(const struct fb_info *info, int user)
+static int xxxfb_release(struct fb_info *info, int user)
 {
     return 0;
 }
@@ -278,7 +283,7 @@ static int xxxfb_set_par(struct fb_info *info)
  */
 static int xxxfb_setcolreg(unsigned regno, unsigned red, unsigned green,
                           unsigned blue, unsigned transp,
-                          const struct fb_info *info)
+                          struct fb_info *info)
 {
     if (regno >= 256)  /* no. of hw registers */
        return -EINVAL;
@@ -303,9 +308,11 @@ static int xxxfb_setcolreg(unsigned regno, unsigned red, unsigned green,
      *   color depth = SUM(var->{color}.length)
      *
      * Pseudocolor:
-     *    var->{color}.offset is 0
-     *    var->{color}.length contains width of DAC or the number of unique
-     *                        colors available (color depth)
+     *    var->{color}.offset is 0 unless the palette index takes less than
+     *                        bits_per_pixel bits and is stored in the upper
+     *                        bits of the pixel value
+     *    var->{color}.length is set so that 1 << length is the number of
+     *                        available palette entries
      *    pseudo_palette is not used
      *    RAMDAC[X] is programmed to (red, green, blue)
      *    color depth = var->{color}.length
@@ -416,7 +423,7 @@ static int xxxfb_setcolreg(unsigned regno, unsigned red, unsigned green,
  *      Returns negative errno on error, or zero on success.
  */
 static int xxxfb_pan_display(struct fb_var_screeninfo *var,
-                            const struct fb_info *info)
+                            struct fb_info *info)
 {
     /*
      * If your hardware does not support panning, _do_ _not_ implement this
@@ -454,7 +461,7 @@ static int xxxfb_pan_display(struct fb_var_screeninfo *var,
  *      Return !0 for any modes that are unimplemented.
  *
  */
-static int xxxfb_blank(int blank_mode, const struct fb_info *info)
+static int xxxfb_blank(int blank_mode, struct fb_info *info)
 {
     /* ... */
     return 0;
@@ -483,7 +490,7 @@ static int xxxfb_blank(int blank_mode, const struct fb_info *info)
  *     depending on the rastering operation with the value of color which
  *     is in the current color depth format.
  */
-void xxfb_fillrect(struct fb_info *p, const struct fb_fillrect *region)
+void xxxfb_fillrect(struct fb_info *p, const struct fb_fillrect *region)
 {
 /*     Meaning of struct fb_fillrect
  *
@@ -623,19 +630,6 @@ void xxxfb_rotate(struct fb_info *info, int angle)
 }
 
 /**
- *     xxxfb_poll - NOT a required function. The purpose of this
- *                  function is to provide a way for some process
- *                  to wait until a specific hardware event occurs
- *                  for the framebuffer device.
- *                              
- *      @info: frame buffer structure that represents a single frame buffer
- *     @wait: poll table where we store process that await a event.     
- */
-void xxxfb_poll(struct fb_info *info, poll_table *wait)
-{
-}
-
-/**
  *     xxxfb_sync - NOT a required function. Normally the accel engine 
  *                  for a graphics card take a specific amount of time.
  *                  Often we have to wait for the accelerator to finish
@@ -647,21 +641,49 @@ void xxxfb_poll(struct fb_info *info, poll_table *wait)
  *      If the driver has implemented its own hardware-based drawing function,
  *      implementing this function is highly recommended.
  */
-void xxxfb_sync(struct fb_info *info)
+int xxxfb_sync(struct fb_info *info)
 {
+       return 0;
 }
 
     /*
+     *  Frame buffer operations
+     */
+
+static struct fb_ops xxxfb_ops = {
+       .owner          = THIS_MODULE,
+       .fb_open        = xxxfb_open,
+       .fb_read        = xxxfb_read,
+       .fb_write       = xxxfb_write,
+       .fb_release     = xxxfb_release,
+       .fb_check_var   = xxxfb_check_var,
+       .fb_set_par     = xxxfb_set_par,
+       .fb_setcolreg   = xxxfb_setcolreg,
+       .fb_blank       = xxxfb_blank,
+       .fb_pan_display = xxxfb_pan_display,
+       .fb_fillrect    = xxxfb_fillrect,       /* Needed !!! */
+       .fb_copyarea    = xxxfb_copyarea,       /* Needed !!! */
+       .fb_imageblit   = xxxfb_imageblit,      /* Needed !!! */
+       .fb_cursor      = xxxfb_cursor,         /* Optional !!! */
+       .fb_rotate      = xxxfb_rotate,
+       .fb_sync        = xxxfb_sync,
+       .fb_ioctl       = xxxfb_ioctl,
+       .fb_mmap        = xxxfb_mmap,
+};
+
+/* ------------------------------------------------------------------------- */
+
+    /*
      *  Initialization
      */
 
-/* static int __init xxfb_probe (struct device *device) -- for platform devs */
-static int __init xxxfb_probe(struct pci_dev *dev,
-                             const_struct pci_device_id *ent)
+/* static int __init xxfb_probe (struct platform_device *pdev) -- for platform devs */
+static int __devinit xxxfb_probe(struct pci_dev *dev,
+                             const struct pci_device_id *ent)
 {
     struct fb_info *info;
     struct xxx_par *par;
-    struct device = &dev->dev; /* for pci drivers */
+    struct device *device = &dev->dev; /* or &pdev->dev */
     int cmap_len, retval;      
    
     /*
@@ -684,7 +706,7 @@ static int __init xxxfb_probe(struct pci_dev *dev,
     info->screen_base = framebuffer_virtual_memory;
     info->fbops = &xxxfb_ops;
     info->fix = xxxfb_fix; /* this will be the only time xxxfb_fix will be
-                           * used, so mark it as __initdata
+                           * used, so mark it as __devinitdata
                            */
     info->pseudo_palette = pseudo_palette; /* The pseudopalette is an
                                            * 16-member array
@@ -760,7 +782,7 @@ static int __init xxxfb_probe(struct pci_dev *dev,
      *
      * NOTE: This field is currently unused.
      */
-    info->pixmap.scan_align = 32
+    info->pixmap.access_align = 32;
 /***************************** End optional stage ***************************/
 
     /*
@@ -770,13 +792,14 @@ static int __init xxxfb_probe(struct pci_dev *dev,
     if (!mode_option)
        mode_option = "640x480@60";             
 
-    retval = fb_find_mode(info->var, info, mode_option, NULL, 0, NULL, 8);
+    retval = fb_find_mode(&info->var, info, mode_option, NULL, 0, NULL, 8);
   
     if (!retval || retval == 4)
        return -EINVAL;                 
 
-    /* This has to been done !!! */    
-    fb_alloc_cmap(info->cmap, cmap_len, 0);
+    /* This has to be done! */
+    if (fb_alloc_cmap(&info->cmap, cmap_len, 0))
+       return -ENOMEM;
        
     /* 
      * The following is done in the case of having hardware with a static 
@@ -800,45 +823,90 @@ static int __init xxxfb_probe(struct pci_dev *dev,
      */
     /* xxxfb_set_par(info); */
 
-    if (register_framebuffer(info) < 0)
+    if (register_framebuffer(info) < 0) {
+       fb_dealloc_cmap(&info->cmap);
        return -EINVAL;
+    }
     printk(KERN_INFO "fb%d: %s frame buffer device\n", info->node,
           info->fix.id);
-    pci_set_drvdata(dev, info); /* or dev_set_drvdata(device, info) */
+    pci_set_drvdata(dev, info); /* or platform_set_drvdata(pdev, info) */
     return 0;
 }
 
     /*
      *  Cleanup
      */
-/* static void __exit xxxfb_remove(struct device *device) */
-static void __exit xxxfb_remove(struct pci_dev *dev)
+/* static void __devexit xxxfb_remove(struct platform_device *pdev) */
+static void __devexit xxxfb_remove(struct pci_dev *dev)
 {
-       struct fb_info *info = pci_get_drv_data(dev);
-       /* or dev_get_drv_data(device); */
+       struct fb_info *info = pci_get_drvdata(dev);
+       /* or platform_get_drvdata(pdev); */
 
        if (info) {
                unregister_framebuffer(info);
-               fb_dealloc_cmap(&info.cmap);
+               fb_dealloc_cmap(&info->cmap);
                /* ... */
                framebuffer_release(info);
        }
+}
+
+#ifdef CONFIG_PCI
+#ifdef CONFIG_PM
+/**
+ *     xxxfb_suspend - Optional but recommended function. Suspend the device.
+ *     @dev: PCI device
+ *     @msg: the suspend event code.
+ *
+ *      See Documentation/power/devices.txt for more information
+ */
+static int xxxfb_suspend(struct pci_dev *dev, pm_message_t msg)
+{
+       struct fb_info *info = pci_get_drvdata(dev);
+       struct xxxfb_par *par = info->par;
 
+       /* suspend here */
        return 0;
 }
 
-#if CONFIG_PCI
+/**
+ *     xxxfb_resume - Optional but recommended function. Resume the device.
+ *     @dev: PCI device
+ *
+ *      See Documentation/power/devices.txt for more information
+ */
+static int xxxfb_resume(struct pci_dev *dev)
+{
+       struct fb_info *info = pci_get_drvdata(dev);
+       struct xxxfb_par *par = info->par;
+
+       /* resume here */
+       return 0;
+}
+#else
+#define xxxfb_suspend NULL
+#define xxxfb_resume NULL
+#endif /* CONFIG_PM */
+
+static struct pci_device_id xxxfb_id_table[] = {
+       { PCI_VENDOR_ID_XXX, PCI_DEVICE_ID_XXX,
+         PCI_ANY_ID, PCI_ANY_ID, PCI_BASE_CLASS_DISPLAY << 16,
+         PCI_CLASS_MASK, 0 },
+       { 0, }
+};
+
 /* For PCI drivers */
 static struct pci_driver xxxfb_driver = {
        .name =         "xxxfb",
-       .id_table =     xxxfb_devices,
+       .id_table =     xxxfb_id_table,
        .probe =        xxxfb_probe,
        .remove =       __devexit_p(xxxfb_remove),
-       .suspend =      xxxfb_suspend, /* optional */
-       .resume =       xxxfb_resume,  /* optional */
+       .suspend =      xxxfb_suspend, /* optional but recommended */
+       .resume =       xxxfb_resume,  /* optional but recommended */
 };
 
-static int __init xxxfb_init(void)
+MODULE_DEVICE_TABLE(pci, xxxfb_id_table);
+
+int __init xxxfb_init(void)
 {
        /*
         *  For kernel boot options (in 'video=xxxfb:<options>' format)
@@ -858,21 +926,72 @@ static void __exit xxxfb_exit(void)
 {
        pci_unregister_driver(&xxxfb_driver);
 }
-#else
+#else /* non PCI, platform drivers */
 #include <linux/platform_device.h>
 /* for platform devices */
-static struct device_driver xxxfb_driver = {
-       .name = "xxxfb",
-       .bus  = &platform_bus_type,
+
+#ifdef CONFIG_PM
+/**
+ *     xxxfb_suspend - Optional but recommended function. Suspend the device.
+ *     @dev: platform device
+ *     @msg: the suspend event code.
+ *
+ *      See Documentation/power/devices.txt for more information
+ */
+static int xxxfb_suspend(struct platform_device *dev, pm_message_t msg)
+{
+       struct fb_info *info = platform_get_drvdata(dev);
+       struct xxxfb_par *par = info->par;
+
+       /* suspend here */
+       return 0;
+}
+
+/**
+ *     xxxfb_resume - Optional but recommended function. Resume the device.
+ *     @dev: platform device
+ *
+ *      See Documentation/power/devices.txt for more information
+ */
+static int xxxfb_resume(struct platform_dev *dev)
+{
+       struct fb_info *info = platform_get_drvdata(dev);
+       struct xxxfb_par *par = info->par;
+
+       /* resume here */
+       return 0;
+}
+#else
+#define xxxfb_suspend NULL
+#define xxxfb_resume NULL
+#endif /* CONFIG_PM */
+
+static struct platform_device_driver xxxfb_driver = {
        .probe = xxxfb_probe,
        .remove = xxxfb_remove,
-       .suspend = xxxfb_suspend, /* optional */
-       .resume = xxxfb_resume,   /* optional */
+       .suspend = xxxfb_suspend, /* optional but recommended */
+       .resume = xxxfb_resume,   /* optional but recommended */
+       .driver = {
+               .name = "xxxfb",
+       },
 };
 
-static struct platform_device xxxfb_device = {
-       .name = "xxxfb",
-};
+static struct platform_device *xxxfb_device;
+
+#ifndef MODULE
+    /*
+     *  Setup
+     */
+
+/*
+ * Only necessary if your driver takes special options,
+ * otherwise we fall back on the generic fb_setup().
+ */
+int __init xxxfb_setup(char *options)
+{
+    /* Parse user speficied options (`video=xxxfb:') */
+}
+#endif /* MODULE */
 
 static int __init xxxfb_init(void)
 {
@@ -887,12 +1006,16 @@ static int __init xxxfb_init(void)
                return -ENODEV;
        xxxfb_setup(option);
 #endif
-       ret = driver_register(&xxxfb_driver);
+       ret = platform_driver_register(&xxxfb_driver);
 
        if (!ret) {
-               ret = platform_device_register(&xxxfb_device);
-               if (ret)
-                       driver_unregister(&xxxfb_driver);
+               xxxfb_device = platform_device_register_simple("xxxfb", 0,
+                                                               NULL, 0);
+
+               if (IS_ERR(xxxfb_device)) {
+                       platform_driver_unregister(&xxxfb_driver);
+                       ret = PTR_ERR(xxxfb_device);
+               }
        }
 
        return ret;
@@ -900,51 +1023,10 @@ static int __init xxxfb_init(void)
 
 static void __exit xxxfb_exit(void)
 {
-       platform_device_unregister(&xxxfb_device);
-       driver_unregister(&xxxfb_driver);
+       platform_device_unregister(xxxfb_device);
+       platform_driver_unregister(&xxxfb_driver);
 }
-#endif
-
-    /*
-     *  Setup
-     */
-
-/* 
- * Only necessary if your driver takes special options,
- * otherwise we fall back on the generic fb_setup().
- */
-int __init xxxfb_setup(char *options)
-{
-    /* Parse user speficied options (`video=xxxfb:') */
-}
-
-/* ------------------------------------------------------------------------- */
-
-    /*
-     *  Frame buffer operations
-     */
-
-static struct fb_ops xxxfb_ops = {
-       .owner          = THIS_MODULE,
-       .fb_open        = xxxfb_open,
-       .fb_read        = xxxfb_read,
-       .fb_write       = xxxfb_write,
-       .fb_release     = xxxfb_release,
-       .fb_check_var   = xxxfb_check_var,
-       .fb_set_par     = xxxfb_set_par,        
-       .fb_setcolreg   = xxxfb_setcolreg,
-       .fb_blank       = xxxfb_blank,
-       .fb_pan_display = xxxfb_pan_display,    
-       .fb_fillrect    = xxxfb_fillrect,       /* Needed !!! */ 
-       .fb_copyarea    = xxxfb_copyarea,       /* Needed !!! */ 
-       .fb_imageblit   = xxxfb_imageblit,      /* Needed !!! */
-       .fb_cursor      = xxxfb_cursor,         /* Optional !!! */
-       .fb_rotate      = xxxfb_rotate,
-       .fb_poll        = xxxfb_poll,
-       .fb_sync        = xxxfb_sync,
-       .fb_ioctl       = xxxfb_ioctl,
-       .fb_mmap        = xxxfb_mmap,   
-};
+#endif /* CONFIG_PCI */
 
 /* ------------------------------------------------------------------------- */
 
@@ -954,6 +1036,6 @@ static struct fb_ops xxxfb_ops = {
      */
 
 module_init(xxxfb_init);
-module_exit(xxxfb_cleanup);
+module_exit(xxxfb_remove);
 
 MODULE_LICENSE("GPL");