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)  * LCD Lowlevel Control Abstraction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2003,2004 Hewlett-Packard Company
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/lcd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/notifier.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/fb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #if defined(CONFIG_FB) || (defined(CONFIG_FB_MODULE) && \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 			   defined(CONFIG_LCD_CLASS_DEVICE_MODULE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) /* This callback gets called when something important happens inside a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * framebuffer driver. We're looking if that important event is blanking,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * and if it is, we're switching lcd power as well ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) static int fb_notifier_callback(struct notifier_block *self,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 				 unsigned long event, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	struct lcd_device *ld;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	struct fb_event *evdata = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	ld = container_of(self, struct lcd_device, fb_notif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	if (!ld->ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	mutex_lock(&ld->ops_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	if (!ld->ops->check_fb || ld->ops->check_fb(ld, evdata->info)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 		if (event == FB_EVENT_BLANK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 			if (ld->ops->set_power)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 				ld->ops->set_power(ld, *(int *)evdata->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 			if (ld->ops->set_mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 				ld->ops->set_mode(ld, evdata->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	mutex_unlock(&ld->ops_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) static int lcd_register_fb(struct lcd_device *ld)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	memset(&ld->fb_notif, 0, sizeof(ld->fb_notif));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	ld->fb_notif.notifier_call = fb_notifier_callback;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	return fb_register_client(&ld->fb_notif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) static void lcd_unregister_fb(struct lcd_device *ld)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	fb_unregister_client(&ld->fb_notif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) static int lcd_register_fb(struct lcd_device *ld)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) static inline void lcd_unregister_fb(struct lcd_device *ld)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) #endif /* CONFIG_FB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) static ssize_t lcd_power_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	struct lcd_device *ld = to_lcd_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	mutex_lock(&ld->ops_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	if (ld->ops && ld->ops->get_power)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		rc = sprintf(buf, "%d\n", ld->ops->get_power(ld));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		rc = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	mutex_unlock(&ld->ops_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) static ssize_t lcd_power_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		struct device_attribute *attr, const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	struct lcd_device *ld = to_lcd_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	unsigned long power;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	rc = kstrtoul(buf, 0, &power);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	rc = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	mutex_lock(&ld->ops_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	if (ld->ops && ld->ops->set_power) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		pr_debug("set power to %lu\n", power);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		ld->ops->set_power(ld, power);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		rc = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	mutex_unlock(&ld->ops_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) static DEVICE_ATTR_RW(lcd_power);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static ssize_t contrast_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	int rc = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	struct lcd_device *ld = to_lcd_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	mutex_lock(&ld->ops_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	if (ld->ops && ld->ops->get_contrast)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		rc = sprintf(buf, "%d\n", ld->ops->get_contrast(ld));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	mutex_unlock(&ld->ops_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) static ssize_t contrast_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		struct device_attribute *attr, const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	struct lcd_device *ld = to_lcd_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	unsigned long contrast;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	rc = kstrtoul(buf, 0, &contrast);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	rc = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	mutex_lock(&ld->ops_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	if (ld->ops && ld->ops->set_contrast) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		pr_debug("set contrast to %lu\n", contrast);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		ld->ops->set_contrast(ld, contrast);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		rc = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	mutex_unlock(&ld->ops_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) static DEVICE_ATTR_RW(contrast);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) static ssize_t max_contrast_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	struct lcd_device *ld = to_lcd_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	return sprintf(buf, "%d\n", ld->props.max_contrast);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) static DEVICE_ATTR_RO(max_contrast);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) static struct class *lcd_class;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) static void lcd_device_release(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	struct lcd_device *ld = to_lcd_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	kfree(ld);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) static struct attribute *lcd_device_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	&dev_attr_lcd_power.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	&dev_attr_contrast.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	&dev_attr_max_contrast.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) ATTRIBUTE_GROUPS(lcd_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)  * lcd_device_register - register a new object of lcd_device class.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)  * @name: the name of the new object(must be the same as the name of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)  *   respective framebuffer device).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)  * @parent: pointer to the parent's struct device .
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)  * @devdata: an optional pointer to be stored in the device. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)  *   methods may retrieve it by using lcd_get_data(ld).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)  * @ops: the lcd operations structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)  * Creates and registers a new lcd device. Returns either an ERR_PTR()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)  * or a pointer to the newly allocated device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) struct lcd_device *lcd_device_register(const char *name, struct device *parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		void *devdata, struct lcd_ops *ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	struct lcd_device *new_ld;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	pr_debug("lcd_device_register: name=%s\n", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	new_ld = kzalloc(sizeof(struct lcd_device), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	if (!new_ld)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	mutex_init(&new_ld->ops_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	mutex_init(&new_ld->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	new_ld->dev.class = lcd_class;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	new_ld->dev.parent = parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	new_ld->dev.release = lcd_device_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	dev_set_name(&new_ld->dev, "%s", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	dev_set_drvdata(&new_ld->dev, devdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	new_ld->ops = ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	rc = device_register(&new_ld->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		put_device(&new_ld->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		return ERR_PTR(rc);
^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) 	rc = lcd_register_fb(new_ld);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		device_unregister(&new_ld->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		return ERR_PTR(rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	return new_ld;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) EXPORT_SYMBOL(lcd_device_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)  * lcd_device_unregister - unregisters a object of lcd_device class.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)  * @ld: the lcd device object to be unregistered and freed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)  * Unregisters a previously registered via lcd_device_register object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) void lcd_device_unregister(struct lcd_device *ld)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	if (!ld)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	mutex_lock(&ld->ops_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	ld->ops = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	mutex_unlock(&ld->ops_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	lcd_unregister_fb(ld);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	device_unregister(&ld->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) EXPORT_SYMBOL(lcd_device_unregister);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) static void devm_lcd_device_release(struct device *dev, void *res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	struct lcd_device *lcd = *(struct lcd_device **)res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	lcd_device_unregister(lcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) static int devm_lcd_device_match(struct device *dev, void *res, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	struct lcd_device **r = res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	return *r == data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)  * devm_lcd_device_register - resource managed lcd_device_register()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)  * @dev: the device to register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)  * @name: the name of the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)  * @parent: a pointer to the parent device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)  * @devdata: an optional pointer to be stored for private driver use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)  * @ops: the lcd operations structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)  * @return a struct lcd on success, or an ERR_PTR on error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)  * Managed lcd_device_register(). The lcd_device returned from this function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)  * are automatically freed on driver detach. See lcd_device_register()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)  * for more information.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) struct lcd_device *devm_lcd_device_register(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		const char *name, struct device *parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		void *devdata, struct lcd_ops *ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	struct lcd_device **ptr, *lcd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	ptr = devres_alloc(devm_lcd_device_release, sizeof(*ptr), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	if (!ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	lcd = lcd_device_register(name, parent, devdata, ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	if (!IS_ERR(lcd)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 		*ptr = lcd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		devres_add(dev, ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		devres_free(ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	return lcd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) EXPORT_SYMBOL(devm_lcd_device_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)  * devm_lcd_device_unregister - resource managed lcd_device_unregister()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)  * @dev: the device to unregister
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)  * @ld: the lcd device to unregister
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)  * Deallocated a lcd allocated with devm_lcd_device_register(). Normally
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)  * this function will not need to be called and the resource management
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)  * code will ensure that the resource is freed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) void devm_lcd_device_unregister(struct device *dev, struct lcd_device *ld)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	rc = devres_release(dev, devm_lcd_device_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 				devm_lcd_device_match, ld);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	WARN_ON(rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) EXPORT_SYMBOL(devm_lcd_device_unregister);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) static void __exit lcd_class_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	class_destroy(lcd_class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) static int __init lcd_class_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	lcd_class = class_create(THIS_MODULE, "lcd");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	if (IS_ERR(lcd_class)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 		pr_warn("Unable to create backlight class; errno = %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 			PTR_ERR(lcd_class));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 		return PTR_ERR(lcd_class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	lcd_class->dev_groups = lcd_device_groups;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)  * if this is compiled into the kernel, we need to ensure that the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)  * class is registered before users of the class try to register lcd's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) postcore_initcall(lcd_class_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) module_exit(lcd_class_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) MODULE_AUTHOR("Jamey Hicks <jamey.hicks@hp.com>, Andrew Zabolotny <zap@homelink.ru>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) MODULE_DESCRIPTION("LCD Lowlevel Control Abstraction");