Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6cd31b3f authored by Ram Chandrasekar's avatar Ram Chandrasekar Committed by Manaf Meethalavalappu Pallikunhi
Browse files

drivers: video: backlight: Register thermal cooling device



Backlight display can be a thermal cooling device which can help reduce
the temperature by reducing the screen brightness. To facilitate this
register the backlight as a cooling device with thermal framework.

In order to register a backlight driver as a cooling device the
devicetree should have the property #cooling-cells defined. backlight
framework looks for this property to register the cooling device.

The backlight framework stores the user brightness request for the
backlight and caps the request based on thermal recommendation before
sending it to the driver. Also, when there is a new cap request the
current brightness will be re-evaluated.

Change-Id: I1405ddd6c3cfff99cd84842d3773851168dcfe78
Signed-off-by: default avatarRam Chandrasekar <rkumbako@codeaurora.org>
parent ac3247fe
Loading
Loading
Loading
Loading
+65 −0
Original line number Diff line number Diff line
@@ -204,6 +204,11 @@ static ssize_t brightness_store(struct device *dev,
	if (rc)
		return rc;

	bd->usr_brightness_req = brightness;
	brightness = (brightness <= bd->thermal_brightness_limit) ?
				bd->usr_brightness_req :
				bd->thermal_brightness_limit;

	rc = backlight_device_set_brightness(bd, brightness);

	return rc ? rc : count;
@@ -315,6 +320,63 @@ void backlight_force_update(struct backlight_device *bd,
}
EXPORT_SYMBOL(backlight_force_update);

static int bd_cdev_get_max_brightness(struct thermal_cooling_device *cdev,
					unsigned long *state)
{
	struct backlight_device *bd = (struct backlight_device *)cdev->devdata;

	*state = bd->props.max_brightness;

	return 0;
}

static int bd_cdev_get_cur_brightness(struct thermal_cooling_device *cdev,
					unsigned long *state)
{
	struct backlight_device *bd = (struct backlight_device *)cdev->devdata;

	*state = bd->props.max_brightness - bd->thermal_brightness_limit;

	return 0;
}

static int bd_cdev_set_cur_brightness(struct thermal_cooling_device *cdev,
					unsigned long state)
{
	struct backlight_device *bd = (struct backlight_device *)cdev->devdata;
	int brightness_lvl;

	brightness_lvl = bd->props.max_brightness - state;
	if (brightness_lvl == bd->thermal_brightness_limit)
		return 0;

	bd->thermal_brightness_limit = brightness_lvl;
	brightness_lvl = (bd->usr_brightness_req
				<= bd->thermal_brightness_limit) ?
				bd->usr_brightness_req :
				bd->thermal_brightness_limit;
	backlight_device_set_brightness(bd, brightness_lvl);

	return 0;
}

static struct thermal_cooling_device_ops bd_cdev_ops = {
	.get_max_state = bd_cdev_get_max_brightness,
	.get_cur_state = bd_cdev_get_cur_brightness,
	.set_cur_state = bd_cdev_set_cur_brightness,
};

static void backlight_cdev_register(struct device *parent,
				    struct backlight_device *bd)
{
	if (of_find_property(parent->of_node, "#cooling-cells", NULL)) {
		bd->cdev = thermal_of_cooling_device_register(parent->of_node,
				(char *)dev_name(&bd->dev), bd, &bd_cdev_ops);
		if (!bd->cdev)
			pr_err("Cooling device register failed\n");
	}
}

/**
 * backlight_device_register - create and register a new object of
 *   backlight_device class.
@@ -358,6 +420,8 @@ struct backlight_device *backlight_device_register(const char *name,
			WARN(1, "%s: invalid backlight type", name);
			new_bd->props.type = BACKLIGHT_RAW;
		}
		new_bd->thermal_brightness_limit = props->max_brightness;
		new_bd->usr_brightness_req = props->brightness;
	} else {
		new_bd->props.type = BACKLIGHT_RAW;
	}
@@ -374,6 +438,7 @@ struct backlight_device *backlight_device_register(const char *name,
		return ERR_PTR(rc);
	}

	backlight_cdev_register(parent, new_bd);
	new_bd->ops = ops;

#ifdef CONFIG_PMAC_BACKLIGHT
+7 −0
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@
#include <linux/fb.h>
#include <linux/mutex.h>
#include <linux/notifier.h>
#include <linux/thermal.h>

/* Notes on locking:
 *
@@ -106,6 +107,12 @@ struct backlight_device {
	struct list_head entry;

	struct device dev;
	/* Backlight cooling device */
	struct thermal_cooling_device *cdev;
	/* Thermally limited max brightness */
	int thermal_brightness_limit;
	/* User brightness request */
	int usr_brightness_req;

	/* Multiple framebuffers may share one backlight device */
	bool fb_bl_on[FB_MAX];