Source
x
tps65217_bl->bl = devm_backlight_device_register(&pdev->dev, pdev->name,
/*
* tps65217_bl.c
*
* TPS65217 backlight driver
*
* Copyright (C) 2012 Matthias Kaehlcke
* Author: Matthias Kaehlcke <matthias@kaehlcke.net>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation version 2.
*
* This program is distributed "as is" WITHOUT ANY WARRANTY of any
* kind, whether express or implied; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
struct tps65217_bl {
struct tps65217 *tps;
struct device *dev;
struct backlight_device *bl;
bool is_enabled;
};
static int tps65217_bl_enable(struct tps65217_bl *tps65217_bl)
{
int rc;
rc = tps65217_set_bits(tps65217_bl->tps, TPS65217_REG_WLEDCTRL1,
TPS65217_WLEDCTRL1_ISINK_ENABLE,
TPS65217_WLEDCTRL1_ISINK_ENABLE, TPS65217_PROTECT_NONE);
if (rc) {
dev_err(tps65217_bl->dev,
"failed to enable backlight: %d\n", rc);
return rc;
}
tps65217_bl->is_enabled = true;
dev_dbg(tps65217_bl->dev, "backlight enabled\n");
return 0;
}
static int tps65217_bl_disable(struct tps65217_bl *tps65217_bl)
{
int rc;
rc = tps65217_clear_bits(tps65217_bl->tps,
TPS65217_REG_WLEDCTRL1,
TPS65217_WLEDCTRL1_ISINK_ENABLE,
TPS65217_PROTECT_NONE);
if (rc) {
dev_err(tps65217_bl->dev,
"failed to disable backlight: %d\n", rc);
return rc;
}
tps65217_bl->is_enabled = false;
dev_dbg(tps65217_bl->dev, "backlight disabled\n");
return 0;
}
static int tps65217_bl_update_status(struct backlight_device *bl)
{
struct tps65217_bl *tps65217_bl = bl_get_data(bl);
int rc;
int brightness = bl->props.brightness;
if (bl->props.state & BL_CORE_SUSPENDED)
brightness = 0;
if ((bl->props.power != FB_BLANK_UNBLANK) ||
(bl->props.fb_blank != FB_BLANK_UNBLANK))
/* framebuffer in low power mode or blanking active */
brightness = 0;
if (brightness > 0) {
rc = tps65217_reg_write(tps65217_bl->tps,
TPS65217_REG_WLEDCTRL2,