Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  Backlight Driver for Intel-based Apples
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  Copyright (c) Red Hat <mjg@redhat.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *  Based on code from Pommed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *  Copyright (C) 2006 Nicolas Boichat <nicolas @boichat.ch>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *  Copyright (C) 2006 Felipe Alfaro Solana <felipe_alfaro @linuxmail.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *  Copyright (C) 2007 Julien BLACHE <jb@jblache.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *  This driver triggers SMIs which cause the firmware to change the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *  backlight brightness. This is icky in many ways, but it's impractical to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *  get at the firmware code in order to figure out what it's actually doing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/backlight.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/atomic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/apple_bl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) static struct backlight_device *apple_backlight_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) struct hw_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	/* I/O resource to allocate. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	unsigned long iostart;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	unsigned long iolen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	/* Backlight operations structure. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	const struct backlight_ops backlight_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	void (*set_brightness)(int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) static const struct hw_data *hw_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) /* Module parameters. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) static int debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) module_param_named(debug, debug, int, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) MODULE_PARM_DESC(debug, "Set to one to enable debugging messages.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  * Implementation for machines with Intel chipset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) static void intel_chipset_set_brightness(int intensity)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	outb(0x04 | (intensity << 4), 0xb3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	outb(0xbf, 0xb2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) static int intel_chipset_send_intensity(struct backlight_device *bd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	int intensity = bd->props.brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	if (debug)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		pr_debug("setting brightness to %d\n", intensity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	intel_chipset_set_brightness(intensity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) static int intel_chipset_get_intensity(struct backlight_device *bd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	int intensity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	outb(0x03, 0xb3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	outb(0xbf, 0xb2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	intensity = inb(0xb3) >> 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	if (debug)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		pr_debug("read brightness of %d\n", intensity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	return intensity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) static const struct hw_data intel_chipset_data = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	.iostart = 0xb2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	.iolen = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	.backlight_ops	= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		.options	= BL_CORE_SUSPENDRESUME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		.get_brightness	= intel_chipset_get_intensity,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		.update_status	= intel_chipset_send_intensity,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	.set_brightness = intel_chipset_set_brightness,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93)  * Implementation for machines with Nvidia chipset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) static void nvidia_chipset_set_brightness(int intensity)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	outb(0x04 | (intensity << 4), 0x52f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	outb(0xbf, 0x52e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) static int nvidia_chipset_send_intensity(struct backlight_device *bd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	int intensity = bd->props.brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	if (debug)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		pr_debug("setting brightness to %d\n", intensity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	nvidia_chipset_set_brightness(intensity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) static int nvidia_chipset_get_intensity(struct backlight_device *bd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	int intensity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	outb(0x03, 0x52f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	outb(0xbf, 0x52e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	intensity = inb(0x52f) >> 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	if (debug)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		pr_debug("read brightness of %d\n", intensity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	return intensity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) static const struct hw_data nvidia_chipset_data = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	.iostart = 0x52e,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	.iolen = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	.backlight_ops		= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		.options	= BL_CORE_SUSPENDRESUME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		.get_brightness	= nvidia_chipset_get_intensity,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		.update_status	= nvidia_chipset_send_intensity
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	.set_brightness = nvidia_chipset_set_brightness,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) static int apple_bl_add(struct acpi_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	struct backlight_properties props;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	struct pci_dev *host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	int intensity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	host = pci_get_domain_bus_and_slot(0, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	if (!host) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		pr_err("unable to find PCI host\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	if (host->vendor == PCI_VENDOR_ID_INTEL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		hw_data = &intel_chipset_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	else if (host->vendor == PCI_VENDOR_ID_NVIDIA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		hw_data = &nvidia_chipset_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	pci_dev_put(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	if (!hw_data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		pr_err("unknown hardware\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	/* Check that the hardware responds - this may not work under EFI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	intensity = hw_data->backlight_ops.get_brightness(NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	if (!intensity) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		hw_data->set_brightness(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		if (!hw_data->backlight_ops.get_brightness(NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 			return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		hw_data->set_brightness(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	if (!request_region(hw_data->iostart, hw_data->iolen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 			    "Apple backlight"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	memset(&props, 0, sizeof(struct backlight_properties));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	props.type = BACKLIGHT_PLATFORM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	props.max_brightness = 15;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	apple_backlight_device = backlight_device_register("apple_backlight",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 				  NULL, NULL, &hw_data->backlight_ops, &props);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	if (IS_ERR(apple_backlight_device)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		release_region(hw_data->iostart, hw_data->iolen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		return PTR_ERR(apple_backlight_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	apple_backlight_device->props.brightness =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		hw_data->backlight_ops.get_brightness(apple_backlight_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	backlight_update_status(apple_backlight_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) static int apple_bl_remove(struct acpi_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	backlight_device_unregister(apple_backlight_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	release_region(hw_data->iostart, hw_data->iolen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	hw_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) static const struct acpi_device_id apple_bl_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	{"APP0002", 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	{"", 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) static struct acpi_driver apple_bl_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	.name = "Apple backlight",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	.ids = apple_bl_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	.ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		.add = apple_bl_add,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		.remove = apple_bl_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) static atomic_t apple_bl_registered = ATOMIC_INIT(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) int apple_bl_register(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	if (atomic_xchg(&apple_bl_registered, 1) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		return acpi_bus_register_driver(&apple_bl_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) EXPORT_SYMBOL_GPL(apple_bl_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) void apple_bl_unregister(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	if (atomic_xchg(&apple_bl_registered, 0) == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		acpi_bus_unregister_driver(&apple_bl_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) EXPORT_SYMBOL_GPL(apple_bl_unregister);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) static int __init apple_bl_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	return apple_bl_register();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) static void __exit apple_bl_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	apple_bl_unregister();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) module_init(apple_bl_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) module_exit(apple_bl_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) MODULE_DESCRIPTION("Apple Backlight Driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) MODULE_DEVICE_TABLE(acpi, apple_bl_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) MODULE_ALIAS("mbp_nvidia_bl");