Commit 52b1b46c authored by Thomas Zimmermann's avatar Thomas Zimmermann

of: Create platform devices for OF framebuffers

Create a platform device for each OF-declared framebuffer and have
offb bind to these devices. Allows for real hot-unplugging and other
drivers besides offb.

Originally, offb created framebuffer devices while initializing its
module by parsing the OF device tree. No actual Linux device was set
up. This tied OF framebuffers to offb and makes writing other drivers
for the OF framebuffers complicated. The absence of a Linux device
further prevented real hot-unplugging. Adding a distinct platform
device for each OF framebuffer solves both problems. Specifically, a
DRM driver can now provide graphics output for modern userspace.

Some of the offb init code is now located in the OF initialization.
There's now also an implementation of of_platform_default_populate_init(),
which was missing before. The OF side creates different devices for
either OF display nodes or BootX displays as they require different
handling by the driver. The offb drivers picks up each type of device
and runs the appropriate fbdev initialization.

Tested with OF display nodes on qemu's ppc64le target.

v3:
	* declare variable 'node' with function scope (Rob)
v2:
	* run PPC code as part of existing initialization (Rob)
	* add a few more error warnings (Javier)
Signed-off-by: default avatarThomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: default avatarJavier Martinez Canillas <javierm@redhat.com>
Reviewed-by: default avatarRob Herring <robh@kernel.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20220419100405.12600-2-tzimmermann@suse.de
parent ac2f033a
...@@ -507,7 +507,6 @@ int of_platform_default_populate(struct device_node *root, ...@@ -507,7 +507,6 @@ int of_platform_default_populate(struct device_node *root,
} }
EXPORT_SYMBOL_GPL(of_platform_default_populate); EXPORT_SYMBOL_GPL(of_platform_default_populate);
#ifndef CONFIG_PPC
static const struct of_device_id reserved_mem_matches[] = { static const struct of_device_id reserved_mem_matches[] = {
{ .compatible = "qcom,rmtfs-mem" }, { .compatible = "qcom,rmtfs-mem" },
{ .compatible = "qcom,cmd-db" }, { .compatible = "qcom,cmd-db" },
...@@ -527,6 +526,52 @@ static int __init of_platform_default_populate_init(void) ...@@ -527,6 +526,52 @@ static int __init of_platform_default_populate_init(void)
if (!of_have_populated_dt()) if (!of_have_populated_dt())
return -ENODEV; return -ENODEV;
if (IS_ENABLED(CONFIG_PPC)) {
struct device_node *boot_display = NULL;
struct platform_device *dev;
int ret;
/* Check if we have a MacOS display without a node spec */
if (of_get_property(of_chosen, "linux,bootx-noscreen", NULL)) {
/*
* The old code tried to work out which node was the MacOS
* display based on the address. I'm dropping that since the
* lack of a node spec only happens with old BootX versions
* (users can update) and with this code, they'll still get
* a display (just not the palette hacks).
*/
dev = platform_device_alloc("bootx-noscreen", 0);
if (WARN_ON(!dev))
return -ENOMEM;
ret = platform_device_add(dev);
if (WARN_ON(ret)) {
platform_device_put(dev);
return ret;
}
}
/*
* For OF framebuffers, first create the device for the boot display,
* then for the other framebuffers. Only fail for the boot display;
* ignore errors for the rest.
*/
for_each_node_by_type(node, "display") {
if (!of_get_property(node, "linux,opened", NULL) ||
!of_get_property(node, "linux,boot-display", NULL))
continue;
dev = of_platform_device_create(node, "of-display", NULL);
if (WARN_ON(!dev))
return -ENOMEM;
boot_display = node;
break;
}
for_each_node_by_type(node, "display") {
if (!of_get_property(node, "linux,opened", NULL) || node == boot_display)
continue;
of_platform_device_create(node, "of-display", NULL);
}
} else {
/* /*
* Handle certain compatibles explicitly, since we don't want to create * Handle certain compatibles explicitly, since we don't want to create
* platform_devices for every node in /reserved-memory with a * platform_devices for every node in /reserved-memory with a
...@@ -547,6 +592,7 @@ static int __init of_platform_default_populate_init(void) ...@@ -547,6 +592,7 @@ static int __init of_platform_default_populate_init(void)
/* Populate everything else. */ /* Populate everything else. */
of_platform_default_populate(NULL, NULL, NULL); of_platform_default_populate(NULL, NULL, NULL);
}
return 0; return 0;
} }
...@@ -558,7 +604,6 @@ static int __init of_platform_sync_state_init(void) ...@@ -558,7 +604,6 @@ static int __init of_platform_sync_state_init(void)
return 0; return 0;
} }
late_initcall_sync(of_platform_sync_state_init); late_initcall_sync(of_platform_sync_state_init);
#endif
int of_platform_device_destroy(struct device *dev, void *data) int of_platform_device_destroy(struct device *dev, void *data)
{ {
......
...@@ -386,7 +386,7 @@ static void offb_init_palette_hacks(struct fb_info *info, struct device_node *dp ...@@ -386,7 +386,7 @@ static void offb_init_palette_hacks(struct fb_info *info, struct device_node *dp
FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_STATIC_PSEUDOCOLOR; FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_STATIC_PSEUDOCOLOR;
} }
static void __init offb_init_fb(const char *name, static void offb_init_fb(struct platform_device *parent, const char *name,
int width, int height, int depth, int width, int height, int depth,
int pitch, unsigned long address, int pitch, unsigned long address,
int foreign_endian, struct device_node *dp) int foreign_endian, struct device_node *dp)
...@@ -410,12 +410,13 @@ static void __init offb_init_fb(const char *name, ...@@ -410,12 +410,13 @@ static void __init offb_init_fb(const char *name,
return; return;
} }
info = framebuffer_alloc(sizeof(u32) * 16, NULL); info = framebuffer_alloc(sizeof(u32) * 16, &parent->dev);
if (!info) { if (!info) {
release_mem_region(res_start, res_size); release_mem_region(res_start, res_size);
return; return;
} }
platform_set_drvdata(parent, info);
fix = &info->fix; fix = &info->fix;
var = &info->var; var = &info->var;
...@@ -535,7 +536,8 @@ static void __init offb_init_fb(const char *name, ...@@ -535,7 +536,8 @@ static void __init offb_init_fb(const char *name,
} }
static void __init offb_init_nodriver(struct device_node *dp, int no_real_node) static void offb_init_nodriver(struct platform_device *parent, struct device_node *dp,
int no_real_node)
{ {
unsigned int len; unsigned int len;
int i, width = 640, height = 480, depth = 8, pitch = 640; int i, width = 640, height = 480, depth = 8, pitch = 640;
...@@ -650,46 +652,76 @@ static void __init offb_init_nodriver(struct device_node *dp, int no_real_node) ...@@ -650,46 +652,76 @@ static void __init offb_init_nodriver(struct device_node *dp, int no_real_node)
/* kludge for valkyrie */ /* kludge for valkyrie */
if (of_node_name_eq(dp, "valkyrie")) if (of_node_name_eq(dp, "valkyrie"))
address += 0x1000; address += 0x1000;
offb_init_fb(no_real_node ? "bootx" : NULL, offb_init_fb(parent, no_real_node ? "bootx" : NULL,
width, height, depth, pitch, address, width, height, depth, pitch, address,
foreign_endian, no_real_node ? NULL : dp); foreign_endian, no_real_node ? NULL : dp);
} }
} }
static int __init offb_init(void) static int offb_remove(struct platform_device *pdev)
{ {
struct device_node *dp = NULL, *boot_disp = NULL; struct fb_info *info = platform_get_drvdata(pdev);
if (fb_get_options("offb", NULL)) if (info)
return -ENODEV; unregister_framebuffer(info);
/* Check if we have a MacOS display without a node spec */ return 0;
if (of_get_property(of_chosen, "linux,bootx-noscreen", NULL) != NULL) { }
/* The old code tried to work out which node was the MacOS
* display based on the address. I'm dropping that since the
* lack of a node spec only happens with old BootX versions
* (users can update) and with this code, they'll still get
* a display (just not the palette hacks).
*/
offb_init_nodriver(of_chosen, 1);
}
for_each_node_by_type(dp, "display") { static int offb_probe_bootx_noscreen(struct platform_device *pdev)
if (of_get_property(dp, "linux,opened", NULL) && {
of_get_property(dp, "linux,boot-display", NULL)) { offb_init_nodriver(pdev, of_chosen, 1);
boot_disp = dp;
offb_init_nodriver(dp, 0); return 0;
} }
}
for_each_node_by_type(dp, "display") { static struct platform_driver offb_driver_bootx_noscreen = {
if (of_get_property(dp, "linux,opened", NULL) && .driver = {
dp != boot_disp) .name = "bootx-noscreen",
offb_init_nodriver(dp, 0); },
} .probe = offb_probe_bootx_noscreen,
.remove = offb_remove,
};
static int offb_probe_display(struct platform_device *pdev)
{
offb_init_nodriver(pdev, pdev->dev.of_node, 0);
return 0; return 0;
} }
static const struct of_device_id offb_of_match_display[] = {
{ .compatible = "display", },
{ },
};
MODULE_DEVICE_TABLE(of, offb_of_match_display);
static struct platform_driver offb_driver_display = {
.driver = {
.name = "of-display",
.of_match_table = offb_of_match_display,
},
.probe = offb_probe_display,
.remove = offb_remove,
};
static int __init offb_init(void)
{
if (fb_get_options("offb", NULL))
return -ENODEV;
platform_driver_register(&offb_driver_bootx_noscreen);
platform_driver_register(&offb_driver_display);
return 0;
}
module_init(offb_init); module_init(offb_init);
static void __exit offb_exit(void)
{
platform_driver_unregister(&offb_driver_display);
platform_driver_unregister(&offb_driver_bootx_noscreen);
}
module_exit(offb_exit);
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment