Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

fbdev/core: Move framebuffer and backlight helpers into separate files

Move framebuffer and backlight helpers into separate files. Leave
fbsysfs.c to sysfs-related code. No functional changes.

The framebuffer helpers are not in fbmem.c because they are under
GPL-2.0-or-later copyright, while fbmem.c is GPL-2.0.

v2:
* include <linux/mutex.h> (Sam)

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Sam Ravnborg <sam@ravnborg.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20230613110953.24176-34-tzimmermann@suse.de

+115 -110
+3 -1
drivers/video/fbdev/core/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 obj-$(CONFIG_FB_NOTIFY) += fb_notify.o 3 3 obj-$(CONFIG_FB) += fb.o 4 - fb-y := fbmem.o fbmon.o fbcmap.o fbsysfs.o \ 4 + fb-y := fb_backlight.o \ 5 + fb_info.o \ 6 + fbmem.o fbmon.o fbcmap.o fbsysfs.o \ 5 7 modedb.o fbcvt.o fb_cmdline.o fb_io_fops.o 6 8 fb-$(CONFIG_FB_DEFERRED_IO) += fb_defio.o 7 9
+33
drivers/video/fbdev/core/fb_backlight.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + 3 + #include <linux/export.h> 4 + #include <linux/fb.h> 5 + #include <linux/mutex.h> 6 + 7 + #if IS_ENABLED(CONFIG_FB_BACKLIGHT) 8 + /* 9 + * This function generates a linear backlight curve 10 + * 11 + * 0: off 12 + * 1-7: min 13 + * 8-127: linear from min to max 14 + */ 15 + void fb_bl_default_curve(struct fb_info *fb_info, u8 off, u8 min, u8 max) 16 + { 17 + unsigned int i, flat, count, range = (max - min); 18 + 19 + mutex_lock(&fb_info->bl_curve_mutex); 20 + 21 + fb_info->bl_curve[0] = off; 22 + 23 + for (flat = 1; flat < (FB_BACKLIGHT_LEVELS / 16); ++flat) 24 + fb_info->bl_curve[flat] = min; 25 + 26 + count = FB_BACKLIGHT_LEVELS * 15 / 16; 27 + for (i = 0; i < count; ++i) 28 + fb_info->bl_curve[flat + i] = min + (range * (i + 1) / count); 29 + 30 + mutex_unlock(&fb_info->bl_curve_mutex); 31 + } 32 + EXPORT_SYMBOL_GPL(fb_bl_default_curve); 33 + #endif
+78
drivers/video/fbdev/core/fb_info.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + 3 + #include <linux/export.h> 4 + #include <linux/fb.h> 5 + #include <linux/mutex.h> 6 + #include <linux/slab.h> 7 + 8 + /** 9 + * framebuffer_alloc - creates a new frame buffer info structure 10 + * 11 + * @size: size of driver private data, can be zero 12 + * @dev: pointer to the device for this fb, this can be NULL 13 + * 14 + * Creates a new frame buffer info structure. Also reserves @size bytes 15 + * for driver private data (info->par). info->par (if any) will be 16 + * aligned to sizeof(long). 17 + * 18 + * Returns the new structure, or NULL if an error occurred. 19 + * 20 + */ 21 + struct fb_info *framebuffer_alloc(size_t size, struct device *dev) 22 + { 23 + #define BYTES_PER_LONG (BITS_PER_LONG/8) 24 + #define PADDING (BYTES_PER_LONG - (sizeof(struct fb_info) % BYTES_PER_LONG)) 25 + int fb_info_size = sizeof(struct fb_info); 26 + struct fb_info *info; 27 + char *p; 28 + 29 + if (size) 30 + fb_info_size += PADDING; 31 + 32 + p = kzalloc(fb_info_size + size, GFP_KERNEL); 33 + 34 + if (!p) 35 + return NULL; 36 + 37 + info = (struct fb_info *) p; 38 + 39 + if (size) 40 + info->par = p + fb_info_size; 41 + 42 + info->device = dev; 43 + info->fbcon_rotate_hint = -1; 44 + 45 + #if IS_ENABLED(CONFIG_FB_BACKLIGHT) 46 + mutex_init(&info->bl_curve_mutex); 47 + #endif 48 + 49 + return info; 50 + #undef PADDING 51 + #undef BYTES_PER_LONG 52 + } 53 + EXPORT_SYMBOL(framebuffer_alloc); 54 + 55 + /** 56 + * framebuffer_release - marks the structure available for freeing 57 + * 58 + * @info: frame buffer info structure 59 + * 60 + * Drop the reference count of the device embedded in the 61 + * framebuffer info structure. 62 + * 63 + */ 64 + void framebuffer_release(struct fb_info *info) 65 + { 66 + if (!info) 67 + return; 68 + 69 + if (WARN_ON(refcount_read(&info->count))) 70 + return; 71 + 72 + #if IS_ENABLED(CONFIG_FB_BACKLIGHT) 73 + mutex_destroy(&info->bl_curve_mutex); 74 + #endif 75 + 76 + kfree(info); 77 + } 78 + EXPORT_SYMBOL(framebuffer_release);
+1 -109
drivers/video/fbdev/core/fbsysfs.c
··· 5 5 * Copyright (c) 2004 James Simmons <jsimmons@infradead.org> 6 6 */ 7 7 8 - /* 9 - * Note: currently there's only stubs for framebuffer_alloc and 10 - * framebuffer_release here. The reson for that is that until all drivers 11 - * are converted to use it a sysfsification will open OOPSable races. 12 - */ 13 - 14 - #include <linux/kernel.h> 15 - #include <linux/slab.h> 8 + #include <linux/console.h> 16 9 #include <linux/fb.h> 17 10 #include <linux/fbcon.h> 18 - #include <linux/console.h> 19 - #include <linux/module.h> 20 11 21 12 #define FB_SYSFS_FLAG_ATTR 1 22 - 23 - /** 24 - * framebuffer_alloc - creates a new frame buffer info structure 25 - * 26 - * @size: size of driver private data, can be zero 27 - * @dev: pointer to the device for this fb, this can be NULL 28 - * 29 - * Creates a new frame buffer info structure. Also reserves @size bytes 30 - * for driver private data (info->par). info->par (if any) will be 31 - * aligned to sizeof(long). 32 - * 33 - * Returns the new structure, or NULL if an error occurred. 34 - * 35 - */ 36 - struct fb_info *framebuffer_alloc(size_t size, struct device *dev) 37 - { 38 - #define BYTES_PER_LONG (BITS_PER_LONG/8) 39 - #define PADDING (BYTES_PER_LONG - (sizeof(struct fb_info) % BYTES_PER_LONG)) 40 - int fb_info_size = sizeof(struct fb_info); 41 - struct fb_info *info; 42 - char *p; 43 - 44 - if (size) 45 - fb_info_size += PADDING; 46 - 47 - p = kzalloc(fb_info_size + size, GFP_KERNEL); 48 - 49 - if (!p) 50 - return NULL; 51 - 52 - info = (struct fb_info *) p; 53 - 54 - if (size) 55 - info->par = p + fb_info_size; 56 - 57 - info->device = dev; 58 - info->fbcon_rotate_hint = -1; 59 - 60 - #if IS_ENABLED(CONFIG_FB_BACKLIGHT) 61 - mutex_init(&info->bl_curve_mutex); 62 - #endif 63 - 64 - return info; 65 - #undef PADDING 66 - #undef BYTES_PER_LONG 67 - } 68 - EXPORT_SYMBOL(framebuffer_alloc); 69 - 70 - /** 71 - * framebuffer_release - marks the structure available for freeing 72 - * 73 - * @info: frame buffer info structure 74 - * 75 - * Drop the reference count of the device embedded in the 76 - * framebuffer info structure. 77 - * 78 - */ 79 - void framebuffer_release(struct fb_info *info) 80 - { 81 - if (!info) 82 - return; 83 - 84 - if (WARN_ON(refcount_read(&info->count))) 85 - return; 86 - 87 - #if IS_ENABLED(CONFIG_FB_BACKLIGHT) 88 - mutex_destroy(&info->bl_curve_mutex); 89 - #endif 90 - 91 - kfree(info); 92 - } 93 - EXPORT_SYMBOL(framebuffer_release); 94 13 95 14 static int activate(struct fb_info *fb_info, struct fb_var_screeninfo *var) 96 15 { ··· 470 551 fb_info->class_flag &= ~FB_SYSFS_FLAG_ATTR; 471 552 } 472 553 } 473 - 474 - #if IS_ENABLED(CONFIG_FB_BACKLIGHT) 475 - /* This function generates a linear backlight curve 476 - * 477 - * 0: off 478 - * 1-7: min 479 - * 8-127: linear from min to max 480 - */ 481 - void fb_bl_default_curve(struct fb_info *fb_info, u8 off, u8 min, u8 max) 482 - { 483 - unsigned int i, flat, count, range = (max - min); 484 - 485 - mutex_lock(&fb_info->bl_curve_mutex); 486 - 487 - fb_info->bl_curve[0] = off; 488 - 489 - for (flat = 1; flat < (FB_BACKLIGHT_LEVELS / 16); ++flat) 490 - fb_info->bl_curve[flat] = min; 491 - 492 - count = FB_BACKLIGHT_LEVELS * 15 / 16; 493 - for (i = 0; i < count; ++i) 494 - fb_info->bl_curve[flat + i] = min + (range * (i + 1) / count); 495 - 496 - mutex_unlock(&fb_info->bl_curve_mutex); 497 - } 498 - EXPORT_SYMBOL_GPL(fb_bl_default_curve); 499 - #endif