lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <0D753D10438DA54287A00B02708426976368437C8D@AUSP01VMBX24.collaborationhost.net>
Date:	Fri, 12 Mar 2010 11:10:35 -0600
From:	H Hartley Sweeten <hartleys@...ionengravers.com>
To:	Linux Kernel <linux-kernel@...r.kernel.org>
CC:	"rpurdie@...ys.net" <rpurdie@...ys.net>
Subject: [PATCH] backlight: provide sysfs percent brightness attribute

It's usually more convenient to set the backlight brightness
as a 'percent' of total brightness rather than using the raw
'brightness' value.

This provides the necessary sysfs attributes to handle this.

Signed-off-by: H Hartley Sweeten <hsweeten@...ionengravers.com>
Cc: Richard Purdie <rpurdie@...ys.net>

---

diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c
index 18829cf..af25bfa 100644
--- a/drivers/video/backlight/backlight.c
+++ b/drivers/video/backlight/backlight.c
@@ -190,6 +190,50 @@ static ssize_t backlight_show_actual_brightness(struct device *dev,
 	return rc;
 }
 
+static ssize_t backlight_show_percent(struct device *dev,
+		struct device_attribute *attr, char *buf)
+{
+	struct backlight_device *bd = to_backlight_device(dev);
+	int percent;
+
+	percent = bd->props.brightness * 100 / bd->props.max_brightness;
+	return sprintf(buf, "%d\n", percent);
+}
+
+static ssize_t backlight_store_percent(struct device *dev,
+		struct device_attribute *attr, const char *buf, size_t count)
+{
+	struct backlight_device *bd = to_backlight_device(dev);
+	unsigned long percent, brightness;
+	int rc;
+
+	rc = strict_strtoul(buf, 0, &percent);
+	if (rc)
+		return rc;
+
+	brightness = percent * bd->props.max_brightness / 100;
+
+	rc = -ENXIO;
+
+	mutex_lock(&bd->ops_lock);
+	if (bd->ops) {
+		if (brightness > bd->props.max_brightness)
+			rc = -EINVAL;
+		else {
+			pr_debug("backlight: set to %lu%% (brightness of %lu)\n",
+				 percent, 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 struct class *backlight_class;
 
 static int backlight_suspend(struct device *dev, pm_message_t state)
@@ -233,6 +277,7 @@ static struct device_attribute bl_device_attributes[] = {
 	__ATTR(actual_brightness, 0444, backlight_show_actual_brightness,
 		     NULL),
 	__ATTR(max_brightness, 0444, backlight_show_max_brightness, NULL),
+	__ATTR(percent, 0644, backlight_show_percent, backlight_store_percent),
 	__ATTR_NULL,
 };
 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ