From fb33b6751a8a72448b0ea74f67167a2a4d80691b Mon Sep 17 00:00:00 2001 From: Emmanuel Vadot Date: Sat, 22 Aug 2020 20:33:10 +0200 Subject: [PATCH] linuxkpi: Use backlight from base linuxkpi --- linuxkpi/Makefile | 2 - linuxkpi/gplv2/include/linux/backlight.h | 174 ------- linuxkpi/gplv2/src/linux_backlight.c | 602 ----------------------- linuxkpi/gplv2/src/linux_video.c | 386 --------------- 4 files changed, 1164 deletions(-) delete mode 100644 linuxkpi/gplv2/include/linux/backlight.h delete mode 100644 linuxkpi/gplv2/src/linux_backlight.c delete mode 100644 linuxkpi/gplv2/src/linux_video.c diff --git a/linuxkpi/Makefile b/linuxkpi/Makefile index 47c2b6168a7..12fd3d8fe90 100644 --- a/linuxkpi/Makefile +++ b/linuxkpi/Makefile @@ -7,7 +7,6 @@ KMOD= linuxkpi_gplv2 SRCS= linux_kmod_gplv2.c \ linux_anon_inodefs.c \ linux_anon_inodes.c \ - linux_backlight.c \ linux_compat.c \ linux_device.c \ linux_firmware.c \ @@ -31,7 +30,6 @@ SRCS+= dma-buf.c \ .if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "aarch64" SRCS+= linux_acpi.c \ - linux_video.c \ opt_acpi.h .endif diff --git a/linuxkpi/gplv2/include/linux/backlight.h b/linuxkpi/gplv2/include/linux/backlight.h deleted file mode 100644 index a014239e674..00000000000 --- a/linuxkpi/gplv2/include/linux/backlight.h +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Backlight Lowlevel Control Abstraction - * - * Copyright (C) 2003,2004 Hewlett-Packard Company - * - */ - -#ifndef _LINUX_BACKLIGHT_H -#define _LINUX_BACKLIGHT_H - -#include -#include -#include -#include - -/* Notes on locking: - * - * backlight_device->ops_lock is an internal backlight lock protecting the - * ops pointer and no code outside the core should need to touch it. - * - * Access to update_status() is serialised by the update_lock mutex since - * most drivers seem to need this and historically get it wrong. - * - * Most drivers don't need locking on their get_brightness() method. - * If yours does, you need to implement it in the driver. You can use the - * update_lock mutex if appropriate. - * - * Any other use of the locks below is probably wrong. - */ - -enum backlight_update_reason { - BACKLIGHT_UPDATE_HOTKEY, - BACKLIGHT_UPDATE_SYSFS, -}; - -enum backlight_type { - BACKLIGHT_RAW = 1, - BACKLIGHT_PLATFORM, - BACKLIGHT_FIRMWARE, - BACKLIGHT_TYPE_MAX, -}; - -enum backlight_notification { - BACKLIGHT_REGISTERED, - BACKLIGHT_UNREGISTERED, -}; - -struct backlight_device; -struct linux_fb_info; - -struct backlight_ops { - unsigned int options; - -#define BL_CORE_SUSPENDRESUME (1 << 0) - - /* Notify the backlight driver some property has changed */ - int (*update_status)(struct backlight_device *); - /* Return the current backlight brightness (accounting for power, - fb_blank etc.) */ - int (*get_brightness)(struct backlight_device *); - /* Check if given framebuffer device is the one bound to this backlight; - return 0 if not, !=0 if it is. If NULL, backlight always matches the fb. */ - int (*check_fb)(struct backlight_device *, struct linux_fb_info *); -}; - -/* This structure defines all the properties of a backlight */ -struct backlight_properties { - /* Current User requested brightness (0 - max_brightness) */ - int brightness; - /* Maximal value for brightness (read-only) */ - int max_brightness; - /* Current FB Power mode (0: full on, 1..3: power saving - modes; 4: full off), see FB_BLANK_XXX */ - int power; - /* FB Blanking active? (values as for power) */ - /* Due to be removed, please use (state & BL_CORE_FBBLANK) */ - int fb_blank; - /* Backlight type */ - enum backlight_type type; - /* Flags used to signal drivers of state changes */ - /* Upper 4 bits are reserved for driver internal use */ - unsigned int state; - -#define BL_CORE_SUSPENDED (1 << 0) /* backlight is suspended */ -#define BL_CORE_FBBLANK (1 << 1) /* backlight is under an fb blank event */ -#define BL_CORE_DRIVER4 (1 << 28) /* reserved for driver specific use */ -#define BL_CORE_DRIVER3 (1 << 29) /* reserved for driver specific use */ -#define BL_CORE_DRIVER2 (1 << 30) /* reserved for driver specific use */ -#define BL_CORE_DRIVER1 (1 << 31) /* reserved for driver specific use */ - -}; - -struct backlight_device { - /* Backlight properties */ - struct backlight_properties props; - - /* Serialise access to update_status method */ - struct mutex update_lock; - - /* This protects the 'ops' field. If 'ops' is NULL, the driver that - registered this device has been unloaded, and if class_get_devdata() - points to something in the body of that driver, it is also invalid. */ - struct mutex ops_lock; - const struct backlight_ops *ops; - - /* The framebuffer notifier block */ - struct notifier_block fb_notif; - - /* list entry of all registered backlight devices */ - struct list_head entry; - - struct device dev; - - /* Multiple framebuffers may share one backlight device */ - bool fb_bl_on[FB_MAX]; - - int use_count; -}; - -static inline int backlight_update_status(struct backlight_device *bd) -{ - int ret = -ENOENT; - - mutex_lock(&bd->update_lock); - if (bd->ops && bd->ops->update_status) - ret = bd->ops->update_status(bd); - mutex_unlock(&bd->update_lock); - - return ret; -} - -extern struct backlight_device *backlight_device_register(const char *name, - struct device *dev, void *devdata, const struct backlight_ops *ops, - const struct backlight_properties *props); -extern struct backlight_device *devm_backlight_device_register( - struct device *dev, const char *name, struct device *parent, - void *devdata, const struct backlight_ops *ops, - const struct backlight_properties *props); -extern void backlight_device_unregister(struct backlight_device *bd); -extern void devm_backlight_device_unregister(struct device *dev, - struct backlight_device *bd); -extern void backlight_force_update(struct backlight_device *bd, - enum backlight_update_reason reason); -extern bool backlight_device_registered(enum backlight_type type); -extern int backlight_register_notifier(struct notifier_block *nb); -extern int backlight_unregister_notifier(struct notifier_block *nb); - -#define to_backlight_device(obj) container_of(obj, struct backlight_device, dev) - -static inline void * bl_get_data(struct backlight_device *bl_dev) -{ - return dev_get_drvdata(&bl_dev->dev); -} - -struct generic_bl_info { - const char *name; - int max_intensity; - int default_intensity; - int limit_mask; - void (*set_bl_intensity)(int intensity); - void (*kick_battery)(void); -}; - -#ifdef CONFIG_OF -struct backlight_device *of_find_backlight_by_node(struct device_node *node); -#else -static inline struct backlight_device * -of_find_backlight_by_node(struct device_node *node) -{ - return NULL; -} -#endif - -#endif diff --git a/linuxkpi/gplv2/src/linux_backlight.c b/linuxkpi/gplv2/src/linux_backlight.c deleted file mode 100644 index 1515e936486..00000000000 --- a/linuxkpi/gplv2/src/linux_backlight.c +++ /dev/null @@ -1,602 +0,0 @@ -/* - * Backlight Lowlevel Control Abstraction - * - * Copyright (C) 2003,2004 Hewlett-Packard Company - * - */ - -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef CONFIG_PMAC_BACKLIGHT -#include -#endif - -static struct list_head backlight_dev_list; -static struct mutex backlight_dev_list_mutex; -static struct blocking_notifier_head backlight_notifier; - -static const char *const backlight_types[] = { - [BACKLIGHT_RAW] = "raw", - [BACKLIGHT_PLATFORM] = "platform", - [BACKLIGHT_FIRMWARE] = "firmware", -}; - -#if defined(CONFIG_FB) || (defined(CONFIG_FB_MODULE) && \ - defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE)) -/* This callback gets called when something important happens inside a - * framebuffer driver. We're looking if that important event is blanking, - * and if it is and necessary, we're switching backlight power as well ... - */ -static int fb_notifier_callback(struct notifier_block *self, - unsigned long event, void *data) -{ - struct backlight_device *bd; - struct fb_event *evdata = data; - int node = evdata->info->node; - int fb_blank = 0; - - /* If we aren't interested in this event, skip it immediately ... */ - if (event != FB_EVENT_BLANK && event != FB_EVENT_CONBLANK) - return 0; - - bd = container_of(self, struct backlight_device, fb_notif); - mutex_lock(&bd->ops_lock); - if (bd->ops) - if (!bd->ops->check_fb || - bd->ops->check_fb(bd, evdata->info)) { - fb_blank = *(int *)evdata->data; - if (fb_blank == FB_BLANK_UNBLANK && - !bd->fb_bl_on[node]) { - bd->fb_bl_on[node] = true; - if (!bd->use_count++) { - bd->props.state &= ~BL_CORE_FBBLANK; - bd->props.fb_blank = FB_BLANK_UNBLANK; - backlight_update_status(bd); - } - } else if (fb_blank != FB_BLANK_UNBLANK && - bd->fb_bl_on[node]) { - bd->fb_bl_on[node] = false; - if (!(--bd->use_count)) { - bd->props.state |= BL_CORE_FBBLANK; - bd->props.fb_blank = fb_blank; - backlight_update_status(bd); - } - } - } - mutex_unlock(&bd->ops_lock); - return 0; -} - -static int backlight_register_fb(struct backlight_device *bd) -{ - memset(&bd->fb_notif, 0, sizeof(bd->fb_notif)); - bd->fb_notif.notifier_call = fb_notifier_callback; - - return fb_register_client(&bd->fb_notif); -} - -static void backlight_unregister_fb(struct backlight_device *bd) -{ - fb_unregister_client(&bd->fb_notif); -} -#else -static inline int backlight_register_fb(struct backlight_device *bd) -{ - return 0; -} - -static inline void backlight_unregister_fb(struct backlight_device *bd) -{ -} -#endif /* CONFIG_FB */ - -static void backlight_generate_event(struct backlight_device *bd, - enum backlight_update_reason reason) -{ - char *envp[2] __unused; - - switch (reason) { - case BACKLIGHT_UPDATE_SYSFS: - envp[0] = "SOURCE=sysfs"; - break; - case BACKLIGHT_UPDATE_HOTKEY: - envp[0] = "SOURCE=hotkey"; - break; - default: - envp[0] = "SOURCE=unknown"; - break; - } - envp[1] = NULL; -#ifdef __linux__ - kobject_uevent_env(&bd->dev.kobj, KOBJ_CHANGE, envp); - sysfs_notify(&bd->dev.kobj, NULL, "actual_brightness"); -#endif -} - -static ssize_t bl_power_show(struct device *dev, struct device_attribute *attr, - char *buf) -{ - struct backlight_device *bd = to_backlight_device(dev); - - return sprintf(buf, "%d\n", bd->props.power); -} - -static ssize_t bl_power_store(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) -{ - int rc; - struct backlight_device *bd = to_backlight_device(dev); - unsigned long power; - - rc = kstrtoul(buf, 0, &power); - if (rc) - return rc; - - rc = -ENXIO; - mutex_lock(&bd->ops_lock); - if (bd->ops) { - pr_debug("set power to %lu\n", power); - if (bd->props.power != power) { - bd->props.power = power; - backlight_update_status(bd); - } - rc = count; - } - mutex_unlock(&bd->ops_lock); - - return rc; -} -static DEVICE_ATTR_RW(bl_power); - -static ssize_t brightness_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct backlight_device *bd = to_backlight_device(dev); - - return sprintf(buf, "%d\n", bd->props.brightness); -} - -static ssize_t brightness_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - int rc; - struct backlight_device *bd = to_backlight_device(dev); - unsigned long brightness; - - rc = kstrtoul(buf, 0, &brightness); - if (rc) - return rc; - - rc = -ENXIO; - - mutex_lock(&bd->ops_lock); - if (bd->ops) { - if (brightness > bd->props.max_brightness) - rc = -EINVAL; - else { - pr_debug("set brightness to %lu\n", brightness); - bd->props.brightness = brightness; - backlight_update_status(bd); - rc = count; - } - } - mutex_unlock(&bd->ops_lock); - - backlight_generate_event(bd, BACKLIGHT_UPDATE_SYSFS); - - return rc; -} -static DEVICE_ATTR_RW(brightness); - -static ssize_t type_show(struct device *dev, struct device_attribute *attr, - char *buf) -{ - struct backlight_device *bd = to_backlight_device(dev); - - return sprintf(buf, "%s\n", backlight_types[bd->props.type]); -} -static DEVICE_ATTR_RO(type); - -static ssize_t max_brightness_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct backlight_device *bd = to_backlight_device(dev); - - return sprintf(buf, "%d\n", bd->props.max_brightness); -} -static DEVICE_ATTR_RO(max_brightness); - -static ssize_t actual_brightness_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - int rc = -ENXIO; - struct backlight_device *bd = to_backlight_device(dev); - - mutex_lock(&bd->ops_lock); - if (bd->ops && bd->ops->get_brightness) - rc = sprintf(buf, "%d\n", bd->ops->get_brightness(bd)); - else - rc = sprintf(buf, "%d\n", bd->props.brightness); - mutex_unlock(&bd->ops_lock); - - return rc; -} -static DEVICE_ATTR_RO(actual_brightness); - -static struct class *backlight_class; - -#ifdef CONFIG_PM_SLEEP -static int backlight_suspend(struct device *dev) -{ - struct backlight_device *bd = to_backlight_device(dev); - - mutex_lock(&bd->ops_lock); - if (bd->ops && bd->ops->options & BL_CORE_SUSPENDRESUME) { - bd->props.state |= BL_CORE_SUSPENDED; - backlight_update_status(bd); - } - mutex_unlock(&bd->ops_lock); - - return 0; -} - -static int backlight_resume(struct device *dev) -{ - struct backlight_device *bd = to_backlight_device(dev); - - mutex_lock(&bd->ops_lock); - if (bd->ops && bd->ops->options & BL_CORE_SUSPENDRESUME) { - bd->props.state &= ~BL_CORE_SUSPENDED; - backlight_update_status(bd); - } - mutex_unlock(&bd->ops_lock); - - return 0; -} -#endif - -static SIMPLE_DEV_PM_OPS(backlight_class_dev_pm_ops, backlight_suspend, - backlight_resume); - -static void bl_device_release(struct device *dev) -{ - struct backlight_device *bd = to_backlight_device(dev); - kfree(bd); -} - -static struct attribute *bl_device_attrs[] = { - &dev_attr_bl_power.attr, - &dev_attr_brightness.attr, - &dev_attr_actual_brightness.attr, - &dev_attr_max_brightness.attr, - &dev_attr_type.attr, - NULL, -}; -ATTRIBUTE_GROUPS(bl_device); - -/** - * backlight_force_update - tell the backlight subsystem that hardware state - * has changed - * @bd: the backlight device to update - * - * Updates the internal state of the backlight in response to a hardware event, - * and generate a uevent to notify userspace - */ -void backlight_force_update(struct backlight_device *bd, - enum backlight_update_reason reason) -{ - mutex_lock(&bd->ops_lock); - if (bd->ops && bd->ops->get_brightness) - bd->props.brightness = bd->ops->get_brightness(bd); - mutex_unlock(&bd->ops_lock); - backlight_generate_event(bd, reason); -} -EXPORT_SYMBOL(backlight_force_update); - -/** - * backlight_device_register - create and register a new object of - * backlight_device class. - * @name: the name of the new object(must be the same as the name of the - * respective framebuffer device). - * @parent: a pointer to the parent device - * @devdata: an optional pointer to be stored for private driver use. The - * methods may retrieve it by using bl_get_data(bd). - * @ops: the backlight operations structure. - * - * Creates and registers new backlight device. Returns either an - * ERR_PTR() or a pointer to the newly allocated device. - */ -struct backlight_device *backlight_device_register(const char *name, - struct device *parent, void *devdata, const struct backlight_ops *ops, - const struct backlight_properties *props) -{ - struct backlight_device *new_bd; - int rc; - - pr_debug("backlight_device_register: name=%s\n", name); - - new_bd = kzalloc(sizeof(struct backlight_device), GFP_KERNEL); - if (!new_bd) - return ERR_PTR(-ENOMEM); - - mutex_init(&new_bd->update_lock); - mutex_init(&new_bd->ops_lock); - - new_bd->dev.class = backlight_class; - new_bd->dev.parent = parent; - new_bd->dev.release = bl_device_release; - dev_set_name(&new_bd->dev, "%s", name); - dev_set_drvdata(&new_bd->dev, devdata); - - /* Set default properties */ - if (props) { - memcpy(&new_bd->props, props, - sizeof(struct backlight_properties)); - if (props->type <= 0 || props->type >= BACKLIGHT_TYPE_MAX) { - WARN(1, "%s: invalid backlight type", name); - new_bd->props.type = BACKLIGHT_RAW; - } - } else { - new_bd->props.type = BACKLIGHT_RAW; - } - - rc = device_register(&new_bd->dev); - if (rc) { - put_device(&new_bd->dev); - return ERR_PTR(rc); - } - - rc = backlight_register_fb(new_bd); - if (rc) { - device_unregister(&new_bd->dev); - return ERR_PTR(rc); - } - - new_bd->ops = ops; - -#ifdef CONFIG_PMAC_BACKLIGHT - mutex_lock(&pmac_backlight_mutex); - if (!pmac_backlight) - pmac_backlight = new_bd; - mutex_unlock(&pmac_backlight_mutex); -#endif - - mutex_lock(&backlight_dev_list_mutex); - list_add(&new_bd->entry, &backlight_dev_list); - mutex_unlock(&backlight_dev_list_mutex); - - blocking_notifier_call_chain(&backlight_notifier, - BACKLIGHT_REGISTERED, new_bd); - - return new_bd; -} -EXPORT_SYMBOL(backlight_device_register); - -bool backlight_device_registered(enum backlight_type type) -{ - bool found = false; - struct backlight_device *bd; - - mutex_lock(&backlight_dev_list_mutex); - list_for_each_entry(bd, &backlight_dev_list, entry) { - if (bd->props.type == type) { - found = true; - break; - } - } - mutex_unlock(&backlight_dev_list_mutex); - - return found; -} -EXPORT_SYMBOL(backlight_device_registered); - -/** - * backlight_device_unregister - unregisters a backlight device object. - * @bd: the backlight device object to be unregistered and freed. - * - * Unregisters a previously registered via backlight_device_register object. - */ -void backlight_device_unregister(struct backlight_device *bd) -{ - if (!bd) - return; - - mutex_lock(&backlight_dev_list_mutex); - list_del(&bd->entry); - mutex_unlock(&backlight_dev_list_mutex); - -#ifdef CONFIG_PMAC_BACKLIGHT - mutex_lock(&pmac_backlight_mutex); - if (pmac_backlight == bd) - pmac_backlight = NULL; - mutex_unlock(&pmac_backlight_mutex); -#endif - - blocking_notifier_call_chain(&backlight_notifier, - BACKLIGHT_UNREGISTERED, bd); - - mutex_lock(&bd->ops_lock); - bd->ops = NULL; - mutex_unlock(&bd->ops_lock); - - backlight_unregister_fb(bd); - device_unregister(&bd->dev); -} -EXPORT_SYMBOL(backlight_device_unregister); - -static void devm_backlight_device_release(struct device *dev, void *res) -{ - struct backlight_device *backlight = *(struct backlight_device **)res; - - backlight_device_unregister(backlight); -} - -static int devm_backlight_device_match(struct device *dev, void *res, - void *data) -{ - struct backlight_device **r = res; - - return *r == data; -} - -/** - * backlight_register_notifier - get notified of backlight (un)registration - * @nb: notifier block with the notifier to call on backlight (un)registration - * - * @return 0 on success, otherwise a negative error code - * - * Register a notifier to get notified when backlight devices get registered - * or unregistered. - */ -int backlight_register_notifier(struct notifier_block *nb) -{ - return blocking_notifier_chain_register(&backlight_notifier, nb); -} -EXPORT_SYMBOL(backlight_register_notifier); - -/** - * backlight_unregister_notifier - unregister a backlight notifier - * @nb: notifier block to unregister - * - * @return 0 on success, otherwise a negative error code - * - * Register a notifier to get notified when backlight devices get registered - * or unregistered. - */ -int backlight_unregister_notifier(struct notifier_block *nb) -{ - return blocking_notifier_chain_unregister(&backlight_notifier, nb); -} -EXPORT_SYMBOL(backlight_unregister_notifier); - -/** - * devm_backlight_device_register - resource managed backlight_device_register() - * @dev: the device to register - * @name: the name of the device - * @parent: a pointer to the parent device - * @devdata: an optional pointer to be stored for private driver use - * @ops: the backlight operations structure - * @props: the backlight properties - * - * @return a struct backlight on success, or an ERR_PTR on error - * - * Managed backlight_device_register(). The backlight_device returned - * from this function are automatically freed on driver detach. - * See backlight_device_register() for more information. - */ -struct backlight_device *devm_backlight_device_register(struct device *dev, - const char *name, struct device *parent, void *devdata, - const struct backlight_ops *ops, - const struct backlight_properties *props) -{ - struct backlight_device **ptr, *backlight; - - ptr = devres_alloc(devm_backlight_device_release, sizeof(*ptr), - GFP_KERNEL); - if (!ptr) - return ERR_PTR(-ENOMEM); - - backlight = backlight_device_register(name, parent, devdata, ops, - props); - if (!IS_ERR(backlight)) { - *ptr = backlight; - devres_add(dev, ptr); - } else { - devres_free(ptr); - } - - return backlight; -} -EXPORT_SYMBOL(devm_backlight_device_register); - -/** - * devm_backlight_device_unregister - resource managed backlight_device_unregister() - * @dev: the device to unregister - * @bd: the backlight device to unregister - * - * Deallocated a backlight allocated with devm_backlight_device_register(). - * Normally this function will not need to be called and the resource management - * code will ensure that the resource is freed. - */ -void devm_backlight_device_unregister(struct device *dev, - struct backlight_device *bd) -{ - int rc; - - rc = devres_release(dev, devm_backlight_device_release, - devm_backlight_device_match, bd); - WARN_ON(rc); -} -EXPORT_SYMBOL(devm_backlight_device_unregister); - -#ifdef CONFIG_OF -static int of_parent_match(struct device *dev, const void *data) -{ - return dev->parent && dev->parent->of_node == data; -} - -/** - * of_find_backlight_by_node() - find backlight device by device-tree node - * @node: device-tree node of the backlight device - * - * Returns a pointer to the backlight device corresponding to the given DT - * node or NULL if no such backlight device exists or if the device hasn't - * been probed yet. - * - * This function obtains a reference on the backlight device and it is the - * caller's responsibility to drop the reference by calling put_device() on - * the backlight device's .dev field. - */ -struct backlight_device *of_find_backlight_by_node(struct device_node *node) -{ - struct device *dev; - - dev = class_find_device(backlight_class, NULL, node, of_parent_match); - - return dev ? to_backlight_device(dev) : NULL; -} -EXPORT_SYMBOL(of_find_backlight_by_node); -#endif - - -static int __init -backlight_class_init(void) -{ - backlight_class = class_create(THIS_MODULE, "backlight"); - if (IS_ERR(backlight_class)) { - pr_warn("Unable to create backlight class; errno = %ld\n", - PTR_ERR(backlight_class)); - return PTR_ERR(backlight_class); - } - - backlight_class->dev_groups = bl_device_groups; - backlight_class->pm = &backlight_class_dev_pm_ops; - INIT_LIST_HEAD(&backlight_dev_list); - mutex_init(&backlight_dev_list_mutex); - BLOCKING_INIT_NOTIFIER_HEAD(&backlight_notifier); - - return 0; -} - -static void __exit -backlight_class_exit(void) -{ - class_destroy(backlight_class); -} - -/* - * if this is compiled into the kernel, we need to ensure that the - * class is registered before users of the class try to register lcd's - */ -postcore_initcall(backlight_class_init); -module_exit(backlight_class_exit); diff --git a/linuxkpi/gplv2/src/linux_video.c b/linuxkpi/gplv2/src/linux_video.c deleted file mode 100644 index d4c8c2e7719..00000000000 --- a/linuxkpi/gplv2/src/linux_video.c +++ /dev/null @@ -1,386 +0,0 @@ -/* - * Copyright (C) 2015 Red Hat Inc. - * Hans de Goede - * Copyright (C) 2008 SuSE Linux Products GmbH - * Thomas Renninger - * - * May be copied or modified under the terms of the GNU General Public License - * - * video_detect.c: - * After PCI devices are glued with ACPI devices - * acpi_get_pci_dev() can be called to identify ACPI graphics - * devices for which a real graphics card is plugged in - * - * Depending on whether ACPI graphics extensions (cmp. ACPI spec Appendix B) - * are available, video.ko should be used to handle the device. - * - * Otherwise vendor specific drivers like thinkpad_acpi, asus-laptop, - * sony_acpi,... can take care about backlight brightness. - * - * Backlight drivers can use acpi_video_get_backlight_type() to determine - * which driver should handle the backlight. - * - * If CONFIG_ACPI_VIDEO is neither set as "compiled in" (y) nor as a module (m) - * this file will not be compiled and acpi_video_get_backlight_type() will - * always return acpi_backlight_vendor. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -static struct work_struct backlight_notify_work; -static bool backlight_notifier_registered; -static struct notifier_block backlight_nb; - -static enum acpi_backlight_type acpi_backlight_dmi = acpi_backlight_undef; - -extern uint8_t AcpiGbl_OsiData; - -static acpi_status -find_video(acpi_handle handle, u32 lvl, void *context, void **rv) -{ - long *cap = context; - struct pci_dev *dev; - struct acpi_device *acpi_dev; - - static const struct acpi_device_id video_ids[] = { - {ACPI_VIDEO_HID, 0}, - {"", 0}, - }; - if (acpi_bus_get_device(handle, &acpi_dev)) - return AE_OK; - - if (!acpi_match_device_ids(acpi_dev, video_ids)) { - dev = acpi_get_pci_dev(handle); - if (!dev) - return AE_OK; - pci_dev_put(dev); - *cap |= acpi_is_video_device(handle); - } - return AE_OK; -} - -static int video_detect_force_vendor(const struct dmi_system_id *d) -{ - acpi_backlight_dmi = acpi_backlight_vendor; - return 0; -} - -static int video_detect_force_video(const struct dmi_system_id *d) -{ - acpi_backlight_dmi = acpi_backlight_video; - return 0; -} - -static int video_detect_force_native(const struct dmi_system_id *d) -{ - acpi_backlight_dmi = acpi_backlight_native; - return 0; -} - -static int video_detect_force_none(const struct dmi_system_id *d) -{ - acpi_backlight_dmi = acpi_backlight_none; - return 0; -} - -static const struct dmi_system_id video_detect_dmi_table[] = { - /* On Samsung X360, the BIOS will set a flag (VDRV) if generic - * ACPI backlight device is used. This flag will definitively break - * the backlight interface (even the vendor interface) untill next - * reboot. It's why we should prevent video.ko from being used here - * and we can't rely on a later call to acpi_video_unregister(). - */ - { - .callback = video_detect_force_vendor, - .ident = "X360", - .matches = { - DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."), - DMI_MATCH(DMI_PRODUCT_NAME, "X360"), - DMI_MATCH(DMI_BOARD_NAME, "X360"), - }, - }, - { - .callback = video_detect_force_vendor, - .ident = "Asus UL30VT", - .matches = { - DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."), - DMI_MATCH(DMI_PRODUCT_NAME, "UL30VT"), - }, - }, - { - .callback = video_detect_force_vendor, - .ident = "Asus UL30A", - .matches = { - DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."), - DMI_MATCH(DMI_PRODUCT_NAME, "UL30A"), - }, - }, - - /* - * These models have a working acpi_video backlight control, and using - * native backlight causes a regression where backlight does not work - * when userspace is not handling brightness key events. Disable - * native_backlight on these to fix this: - * https://bugzilla.kernel.org/show_bug.cgi?id=81691 - */ - { - .callback = video_detect_force_video, - .ident = "ThinkPad T420", - .matches = { - DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), - DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T420"), - }, - }, - { - .callback = video_detect_force_video, - .ident = "ThinkPad T520", - .matches = { - DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), - DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T520"), - }, - }, - { - .callback = video_detect_force_video, - .ident = "ThinkPad X201s", - .matches = { - DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), - DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad X201s"), - }, - }, - { - .callback = video_detect_force_video, - .ident = "ThinkPad X201T", - .matches = { - DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), - DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad X201T"), - }, - }, - - /* The native backlight controls do not work on some older machines */ - { - /* https://bugs.freedesktop.org/show_bug.cgi?id=81515 */ - .callback = video_detect_force_video, - .ident = "HP ENVY 15 Notebook", - .matches = { - DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"), - DMI_MATCH(DMI_PRODUCT_NAME, "HP ENVY 15 Notebook PC"), - }, - }, - { - .callback = video_detect_force_video, - .ident = "SAMSUNG 870Z5E/880Z5E/680Z5E", - .matches = { - DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."), - DMI_MATCH(DMI_PRODUCT_NAME, "870Z5E/880Z5E/680Z5E"), - }, - }, - { - .callback = video_detect_force_video, - .ident = "SAMSUNG 370R4E/370R4V/370R5E/3570RE/370R5V", - .matches = { - DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."), - DMI_MATCH(DMI_PRODUCT_NAME, - "370R4E/370R4V/370R5E/3570RE/370R5V"), - }, - }, - { - /* https://bugzilla.redhat.com/show_bug.cgi?id=1186097 */ - .callback = video_detect_force_video, - .ident = "SAMSUNG 3570R/370R/470R/450R/510R/4450RV", - .matches = { - DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."), - DMI_MATCH(DMI_PRODUCT_NAME, - "3570R/370R/470R/450R/510R/4450RV"), - }, - }, - { - /* https://bugzilla.redhat.com/show_bug.cgi?id=1557060 */ - .callback = video_detect_force_video, - .ident = "SAMSUNG 670Z5E", - .matches = { - DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."), - DMI_MATCH(DMI_PRODUCT_NAME, "670Z5E"), - }, - }, - { - /* https://bugzilla.redhat.com/show_bug.cgi?id=1094948 */ - .callback = video_detect_force_video, - .ident = "SAMSUNG 730U3E/740U3E", - .matches = { - DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."), - DMI_MATCH(DMI_PRODUCT_NAME, "730U3E/740U3E"), - }, - }, - { - /* https://bugs.freedesktop.org/show_bug.cgi?id=87286 */ - .callback = video_detect_force_video, - .ident = "SAMSUNG 900X3C/900X3D/900X3E/900X4C/900X4D", - .matches = { - DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."), - DMI_MATCH(DMI_PRODUCT_NAME, - "900X3C/900X3D/900X3E/900X4C/900X4D"), - }, - }, - { - /* https://bugzilla.redhat.com/show_bug.cgi?id=1272633 */ - .callback = video_detect_force_video, - .ident = "Dell XPS14 L421X", - .matches = { - DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), - DMI_MATCH(DMI_PRODUCT_NAME, "XPS L421X"), - }, - }, - { - /* https://bugzilla.redhat.com/show_bug.cgi?id=1163574 */ - .callback = video_detect_force_video, - .ident = "Dell XPS15 L521X", - .matches = { - DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), - DMI_MATCH(DMI_PRODUCT_NAME, "XPS L521X"), - }, - }, - { - /* https://bugzilla.kernel.org/show_bug.cgi?id=108971 */ - .callback = video_detect_force_video, - .ident = "SAMSUNG 530U4E/540U4E", - .matches = { - DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."), - DMI_MATCH(DMI_PRODUCT_NAME, "530U4E/540U4E"), - }, - }, - - /* Non win8 machines which need native backlight nevertheless */ - { - /* https://bugzilla.redhat.com/show_bug.cgi?id=1201530 */ - .callback = video_detect_force_native, - .ident = "Lenovo Ideapad S405", - .matches = { - DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), - DMI_MATCH(DMI_BOARD_NAME, "Lenovo IdeaPad S405"), - }, - }, - { - /* https://bugzilla.redhat.com/show_bug.cgi?id=1187004 */ - .callback = video_detect_force_native, - .ident = "Lenovo Ideapad Z570", - .matches = { - DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), - DMI_MATCH(DMI_PRODUCT_NAME, "102434U"), - }, - }, - { - /* https://bugzilla.redhat.com/show_bug.cgi?id=1217249 */ - .callback = video_detect_force_native, - .ident = "Apple MacBook Pro 12,1", - .matches = { - DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."), - DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro12,1"), - }, - }, - { - .callback = video_detect_force_native, - .ident = "Dell Vostro V131", - .matches = { - DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), - DMI_MATCH(DMI_PRODUCT_NAME, "Vostro V131"), - }, - }, - { - /* https://bugzilla.redhat.com/show_bug.cgi?id=1123661 */ - .callback = video_detect_force_native, - .ident = "Dell XPS 17 L702X", - .matches = { - DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), - DMI_MATCH(DMI_PRODUCT_NAME, "Dell System XPS L702X"), - }, - }, - { - .callback = video_detect_force_native, - .ident = "Dell Precision 7510", - .matches = { - DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), - DMI_MATCH(DMI_PRODUCT_NAME, "Precision 7510"), - }, - }, - { - .callback = video_detect_force_none, - .ident = "Dell OptiPlex 9020M", - .matches = { - DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), - DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 9020M"), - }, - }, - { }, -}; - - -static void -acpi_video_unregister_backlight(void) -{ - /* XXX */ -} - -/* This uses a workqueue to avoid various locking ordering issues */ -static void -acpi_video_backlight_notify_work(struct work_struct *work) -{ - if (acpi_video_get_backlight_type() != acpi_backlight_video) - acpi_video_unregister_backlight(); -} - -static int -acpi_video_backlight_notify(struct notifier_block *nb, - unsigned long val, void *bd) -{ - struct backlight_device *backlight = bd; - - /* A raw bl registering may change video -> native */ - if (backlight->props.type == BACKLIGHT_RAW && - val == BACKLIGHT_REGISTERED) - schedule_work(&backlight_notify_work); - - return NOTIFY_OK; -} - -enum acpi_backlight_type -acpi_video_get_backlight_type(void) -{ - static DEFINE_MUTEX(init_mutex); - static bool init_done; - static long video_caps; - - /* Parse cmdline, dmi and acpi only once */ - mutex_lock(&init_mutex); - if (!init_done) { - dmi_check_system(video_detect_dmi_table); - acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, - ACPI_UINT32_MAX, find_video, NULL, - &video_caps, NULL); - INIT_WORK(&backlight_notify_work, - acpi_video_backlight_notify_work); - backlight_nb.notifier_call = acpi_video_backlight_notify; - backlight_nb.priority = 0; - if (backlight_register_notifier(&backlight_nb) == 0) - backlight_notifier_registered = true; - init_done = true; - } - mutex_unlock(&init_mutex); - - if (acpi_backlight_dmi != acpi_backlight_undef) - return acpi_backlight_dmi; - - if (!(video_caps & ACPI_VIDEO_BACKLIGHT)) - return acpi_backlight_vendor; - - if ((AcpiGbl_OsiData >= ACPI_OSI_WIN_8) && backlight_device_registered(BACKLIGHT_RAW)) - return acpi_backlight_native; - - return acpi_backlight_video; -}