All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] backlight: provide sysfs percent brightness attribute
@ 2010-03-12 17:10 H Hartley Sweeten
  2010-03-12 17:27 ` Matthew Garrett
  2010-03-12 17:33 ` Henrique de Moraes Holschuh
  0 siblings, 2 replies; 5+ messages in thread
From: H Hartley Sweeten @ 2010-03-12 17:10 UTC (permalink / raw)
  To: Linux Kernel; +Cc: rpurdie@rpsys.net

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="utf-8", Size: 2306 bytes --]

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@visionengravers.com>
Cc: Richard Purdie <rpurdie@rpsys.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,
 };
 
ÿôèº{.nÇ+‰·Ÿ®‰­†+%ŠËÿ±éݶ\x17¥Šwÿº{.nÇ+‰·¥Š{±þG«éÿŠ{ayº\x1dʇڙë,j\a­¢f£¢·hšïêÿ‘êçz_è®\x03(­éšŽŠÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?™¨è­Ú&£ø§~á¶iO•æ¬z·švØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?–I¥

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] backlight: provide sysfs percent brightness attribute
  2010-03-12 17:10 [PATCH] backlight: provide sysfs percent brightness attribute H Hartley Sweeten
@ 2010-03-12 17:27 ` Matthew Garrett
  2010-03-12 17:33 ` Henrique de Moraes Holschuh
  1 sibling, 0 replies; 5+ messages in thread
From: Matthew Garrett @ 2010-03-12 17:27 UTC (permalink / raw)
  To: H Hartley Sweeten; +Cc: Linux Kernel, rpurdie@rpsys.net

On Fri, Mar 12, 2010 at 11:10:35AM -0600, H Hartley Sweeten wrote:
> 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.

Why not just do this in the app?

-- 
Matthew Garrett | mjg59@srcf.ucam.org

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] backlight: provide sysfs percent brightness attribute
  2010-03-12 17:10 [PATCH] backlight: provide sysfs percent brightness attribute H Hartley Sweeten
  2010-03-12 17:27 ` Matthew Garrett
@ 2010-03-12 17:33 ` Henrique de Moraes Holschuh
  2010-03-12 17:39   ` Richard Purdie
  1 sibling, 1 reply; 5+ messages in thread
From: Henrique de Moraes Holschuh @ 2010-03-12 17:33 UTC (permalink / raw)
  To: H Hartley Sweeten; +Cc: Linux Kernel, rpurdie@rpsys.net

On Fri, 12 Mar 2010, H Hartley Sweeten wrote:
> It's usually more convenient to set the backlight brightness
> as a 'percent' of total brightness rather than using the raw
> 'brightness' value.

Well, that scale is often not linear, so you are not dealing with fractions
of the effective brightness, just with fractions of an arbritary scale
exported by the backend driver.  Much of the "usefulness" of a "percent"
scale dies right there.

-- 
  "One disk to rule them all, One disk to find them. One disk to bring
  them all and in the darkness grind them. In the Land of Redmond
  where the shadows lie." -- The Silicon Valley Tarot
  Henrique Holschuh

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] backlight: provide sysfs percent brightness attribute
  2010-03-12 17:33 ` Henrique de Moraes Holschuh
@ 2010-03-12 17:39   ` Richard Purdie
  2010-03-12 17:49     ` H Hartley Sweeten
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Purdie @ 2010-03-12 17:39 UTC (permalink / raw)
  To: Henrique de Moraes Holschuh; +Cc: H Hartley Sweeten, Linux Kernel

On Fri, 2010-03-12 at 14:33 -0300, Henrique de Moraes Holschuh wrote:
> On Fri, 12 Mar 2010, H Hartley Sweeten wrote:
> > It's usually more convenient to set the backlight brightness
> > as a 'percent' of total brightness rather than using the raw
> > 'brightness' value.
> 
> Well, that scale is often not linear, so you are not dealing with fractions
> of the effective brightness, just with fractions of an arbritary scale
> exported by the backend driver.  Much of the "usefulness" of a "percent"
> scale dies right there.

This patch does nothing to address that though.

I agree this is a userland issue and having two interfaces to the kernel
to do the same thing is not a good idea in general.

So no, I'm not going to take that patch, sorry.

Cheers,

Richard


^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH] backlight: provide sysfs percent brightness attribute
  2010-03-12 17:39   ` Richard Purdie
@ 2010-03-12 17:49     ` H Hartley Sweeten
  0 siblings, 0 replies; 5+ messages in thread
From: H Hartley Sweeten @ 2010-03-12 17:49 UTC (permalink / raw)
  To: Richard Purdie, Henrique de Moraes Holschuh; +Cc: Linux Kernel

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="utf-8", Size: 1033 bytes --]

On Friday, March 12, 2010 10:40 AM, Richard Purdie wrote:
> On Fri, 2010-03-12 at 14:33 -0300, Henrique de Moraes Holschuh wrote:
>> On Fri, 12 Mar 2010, H Hartley Sweeten wrote:
>>> It's usually more convenient to set the backlight brightness
>>> as a 'percent' of total brightness rather than using the raw
>>> 'brightness' value.
>> 
>> Well, that scale is often not linear, so you are not dealing with fractions
>> of the effective brightness, just with fractions of an arbritary scale
>> exported by the backend driver.  Much of the "usefulness" of a "percent"
>> scale dies right there.
>
> This patch does nothing to address that though.
>
> I agree this is a userland issue and having two interfaces to the kernel
> to do the same thing is not a good idea in general.
>
> So no, I'm not going to take that patch, sorry.

OK.  Thank for your input.

Regards,
Hartleyÿôèº{.nÇ+‰·Ÿ®‰­†+%ŠËÿ±éݶ\x17¥Šwÿº{.nÇ+‰·¥Š{±þG«éÿŠ{ayº\x1dʇڙë,j\a­¢f£¢·hšïêÿ‘êçz_è®\x03(­éšŽŠÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?™¨è­Ú&£ø§~á¶iO•æ¬z·švØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?–I¥

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-03-12 17:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-12 17:10 [PATCH] backlight: provide sysfs percent brightness attribute H Hartley Sweeten
2010-03-12 17:27 ` Matthew Garrett
2010-03-12 17:33 ` Henrique de Moraes Holschuh
2010-03-12 17:39   ` Richard Purdie
2010-03-12 17:49     ` H Hartley Sweeten

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.