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

Commit c900e978 authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "drivers: video: backlight: Register thermal cooling device" into msm-4.9

parents f842ad22 65e58b4d
Loading
Loading
Loading
Loading
+65 −0
Original line number Diff line number Diff line
@@ -199,6 +199,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;
@@ -310,6 +315,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.
@@ -353,6 +415,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;
	}
@@ -369,6 +433,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
@@ -12,6 +12,7 @@
#include <linux/fb.h>
#include <linux/mutex.h>
#include <linux/notifier.h>
#include <linux/thermal.h>

/* Notes on locking:
 *
@@ -110,6 +111,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];