df87a1b75785a7a1370694a7d4835d5081d94e51
[openwrt/staging/pepe2k.git] /
1 From 0c7fb448e0e0e47c2b3be64e438208682c6a5e61 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Mon, 9 Oct 2023 16:32:45 +0100
4 Subject: [PATCH] fbdev: Allow client to request a particular /dev/fbN node
5
6 Add a flag custom_fb_num to denote that the client has
7 requested a specific fbdev node number via node.
8
9 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
10 ---
11 drivers/video/fbdev/core/fbmem.c | 24 +++++++++++++++++-------
12 include/linux/fb.h | 2 ++
13 2 files changed, 19 insertions(+), 7 deletions(-)
14
15 --- a/drivers/video/fbdev/core/fbmem.c
16 +++ b/drivers/video/fbdev/core/fbmem.c
17 @@ -52,6 +52,7 @@ static DEFINE_MUTEX(registration_lock);
18
19 struct fb_info *registered_fb[FB_MAX] __read_mostly;
20 int num_registered_fb __read_mostly;
21 +int min_dynamic_fb __read_mostly;
22 #define for_each_registered_fb(i) \
23 for (i = 0; i < FB_MAX; i++) \
24 if (!registered_fb[i]) {} else
25 @@ -1579,19 +1580,22 @@ static int do_register_framebuffer(struc
26 return -ENXIO;
27
28 num_registered_fb++;
29 - for (i = 0 ; i < FB_MAX; i++)
30 - if (!registered_fb[i])
31 - break;
32 - fb_info->node = i;
33 + if (!fb_info->custom_fb_num || fb_info->node >= FB_MAX || registered_fb[fb_info->node]) {
34 + for (i = min_dynamic_fb ; i < FB_MAX; i++)
35 + if (!registered_fb[i])
36 + break;
37 + fb_info->node = i;
38 + }
39 refcount_set(&fb_info->count, 1);
40 mutex_init(&fb_info->lock);
41 mutex_init(&fb_info->mm_lock);
42
43 fb_info->dev = device_create(fb_class, fb_info->device,
44 - MKDEV(FB_MAJOR, i), NULL, "fb%d", i);
45 + MKDEV(FB_MAJOR, fb_info->node), NULL, "fb%d", fb_info->node);
46 if (IS_ERR(fb_info->dev)) {
47 /* Not fatal */
48 - printk(KERN_WARNING "Unable to create device for framebuffer %d; errno = %ld\n", i, PTR_ERR(fb_info->dev));
49 + printk(KERN_WARNING "Unable to create device for framebuffer %d; errno = %ld\n",
50 + fb_info->node, PTR_ERR(fb_info->dev));
51 fb_info->dev = NULL;
52 } else
53 fb_init_device(fb_info);
54 @@ -1624,7 +1628,7 @@ static int do_register_framebuffer(struc
55
56 fb_var_to_videomode(&mode, &fb_info->var);
57 fb_add_videomode(&mode, &fb_info->modelist);
58 - registered_fb[i] = fb_info;
59 + registered_fb[fb_info->node] = fb_info;
60
61 #ifdef CONFIG_GUMSTIX_AM200EPD
62 {
63 @@ -1719,6 +1723,12 @@ static int fb_aperture_acquire_for_platf
64 return ret;
65 }
66
67 +void fb_set_lowest_dynamic_fb(int min_fb_dev)
68 +{
69 + min_dynamic_fb = min_fb_dev;
70 +}
71 +EXPORT_SYMBOL(fb_set_lowest_dynamic_fb);
72 +
73 /**
74 * register_framebuffer - registers a frame buffer device
75 * @fb_info: frame buffer info structure
76 --- a/include/linux/fb.h
77 +++ b/include/linux/fb.h
78 @@ -512,6 +512,7 @@ struct fb_info {
79 } *apertures;
80
81 bool skip_vt_switch; /* no VT switch on suspend/resume required */
82 + bool custom_fb_num; /* Use value in node as the preferred node number */
83 };
84
85 static inline struct apertures_struct *alloc_apertures(unsigned int max_num) {
86 @@ -614,6 +615,7 @@ extern ssize_t fb_sys_write(struct fb_in
87 size_t count, loff_t *ppos);
88
89 /* drivers/video/fbmem.c */
90 +extern void fb_set_lowest_dynamic_fb(int min_fb_dev);
91 extern int register_framebuffer(struct fb_info *fb_info);
92 extern void unregister_framebuffer(struct fb_info *fb_info);
93 extern int fb_prepare_logo(struct fb_info *fb_info, int rotate);