@@ -76,8 +76,9 @@ static inline void sysfb_apply_efi_quirks(void)
bool parse_mode(const struct screen_info *si,
struct simplefb_platform_data *mode);
-int create_simplefb(const struct screen_info *si,
+struct platform_device *create_simplefb(const struct screen_info *si,
const struct simplefb_platform_data *mode);
+void sysfb_remove_framebuffers(void);
#else /* CONFIG_X86_SYSFB */
@@ -87,10 +88,10 @@ static inline bool parse_mode(const struct screen_info *si,
return false;
}
-static inline int create_simplefb(const struct screen_info *si,
+static inline struct platform_device *create_simplefb(const struct screen_info *si,
const struct simplefb_platform_data *mode)
{
- return -EINVAL;
+ return ERR_PTR(-EINVAL);
}
#endif /* CONFIG_X86_SYSFB */
@@ -38,23 +38,22 @@
#include <linux/screen_info.h>
#include <asm/sysfb.h>
+static struct platform_device *pd;
+
static __init int sysfb_init(void)
{
struct screen_info *si = &screen_info;
struct simplefb_platform_data mode;
- struct platform_device *pd;
const char *name;
bool compatible;
- int ret;
sysfb_apply_efi_quirks();
/* try to create a simple-framebuffer device */
compatible = parse_mode(si, &mode);
if (compatible) {
- ret = create_simplefb(si, &mode);
- if (!ret)
- return 0;
+ pd = create_simplefb(si, &mode);
+ return IS_ERR(pd) ? PTR_ERR(pd) : 0;
}
/* if the FB is incompatible, create a legacy framebuffer device */
@@ -70,5 +69,14 @@ static __init int sysfb_init(void)
return IS_ERR(pd) ? PTR_ERR(pd) : 0;
}
+void sysfb_remove_framebuffers(void)
+{
+ if (!IS_ERR_OR_NULL(pd)) {
+ platform_device_unregister(pd);
+ pd = NULL;
+ }
+}
+EXPORT_SYMBOL_GPL(sysfb_remove_framebuffers);
+
/* must execute after PCI subsystem for EFI quirks */
device_initcall(sysfb_init);
@@ -61,10 +61,9 @@ __init bool parse_mode(const struct screen_info *si,
return false;
}
-__init int create_simplefb(const struct screen_info *si,
+__init struct platform_device *create_simplefb(const struct screen_info *si,
const struct simplefb_platform_data *mode)
{
- struct platform_device *pd;
struct resource res;
unsigned long len;
@@ -74,7 +73,7 @@ __init int create_simplefb(const struct screen_info *si,
len = PAGE_ALIGN(len);
if (len > (u64)si->lfb_size << 16) {
printk(KERN_WARNING "sysfb: VRAM smaller than advertised\n");
- return -EINVAL;
+ return ERR_PTR(-EINVAL);
}
/* setup IORESOURCE_MEM as framebuffer memory */
@@ -84,12 +83,8 @@ __init int create_simplefb(const struct screen_info *si,
res.start = si->lfb_base;
res.end = si->lfb_base + len - 1;
if (res.end <= res.start)
- return -EINVAL;
+ return ERR_PTR(-EINVAL);
- pd = platform_device_register_resndata(NULL, "simple-framebuffer", 0,
+ return platform_device_register_resndata(NULL, "simple-framebuffer", 0,
&res, 1, mode, sizeof(*mode));
- if (IS_ERR(pd))
- return PTR_ERR(pd);
-
- return 0;
}
@@ -34,6 +34,9 @@
#include <linux/fb.h>
#include <asm/fb.h>
+#ifdef CONFIG_X86
+#include <asm/sysfb.h>
+#endif
/*
@@ -1600,6 +1603,9 @@ static void do_remove_conflicting_framebuffers(struct apertures_struct *a,
"%s vs %s - removing generic driver\n",
name, registered_fb[i]->fix.id);
do_unregister_framebuffer(registered_fb[i]);
+#ifdef CONFIG_X86
+ sysfb_remove_framebuffers();
+#endif
}
}
}
@@ -41,6 +41,11 @@ static struct fb_var_screeninfo simplefb_var = {
.vmode = FB_VMODE_NONINTERLACED,
};
+struct simplefb_priv {
+ u32 pseudo_palette[16];
+ bool fb_registered;
+};
+
static int simplefb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
u_int transp, struct fb_info *info)
{
@@ -68,8 +73,11 @@ static int simplefb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
static void simplefb_destroy(struct fb_info *info)
{
+ struct simplefb_priv *priv = info->par;
+
if (info->screen_base)
iounmap(info->screen_base);
+ priv->fb_registered = false;
}
static struct fb_ops simplefb_ops = {
@@ -169,6 +177,7 @@ static int simplefb_probe(struct platform_device *pdev)
struct simplefb_params params;
struct fb_info *info;
struct resource *mem;
+ struct simplefb_priv *priv;
if (fb_get_options("simplefb", NULL))
return -ENODEV;
@@ -188,7 +197,7 @@ static int simplefb_probe(struct platform_device *pdev)
return -EINVAL;
}
- info = framebuffer_alloc(sizeof(u32) * 16, &pdev->dev);
+ info = framebuffer_alloc(sizeof(struct simplefb_priv), &pdev->dev);
if (!info)
return -ENOMEM;
platform_set_drvdata(pdev, info);
@@ -225,7 +234,9 @@ static int simplefb_probe(struct platform_device *pdev)
framebuffer_release(info);
return -ENODEV;
}
- info->pseudo_palette = (void *)(info + 1);
+
+ priv = info->par;
+ info->pseudo_palette = priv->pseudo_palette;
dev_info(&pdev->dev, "framebuffer at 0x%lx, 0x%x bytes, mapped to 0x%p\n",
info->fix.smem_start, info->fix.smem_len,
@@ -243,6 +254,7 @@ static int simplefb_probe(struct platform_device *pdev)
return ret;
}
+ priv->fb_registered = true;
dev_info(&pdev->dev, "fb%d: simplefb registered!\n", info->node);
return 0;
@@ -251,8 +263,11 @@ static int simplefb_probe(struct platform_device *pdev)
static int simplefb_remove(struct platform_device *pdev)
{
struct fb_info *info = platform_get_drvdata(pdev);
+ struct simplefb_priv *priv = info->par;
+
+ if (priv->fb_registered)
+ unregister_framebuffer(info);
- unregister_framebuffer(info);
framebuffer_release(info);
return 0;