2019-05-20 15:19:14 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2009-02-18 19:50:43 +08:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Backlight driver for HP Jornada 700 series (710/720/728)
|
|
|
|
* Copyright (C) 2006-2009 Kristoffer Ericson <kristoffer.ericson@gmail.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/backlight.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/fb.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
|
|
|
|
#include <mach/jornada720.h>
|
|
|
|
#include <mach/hardware.h>
|
|
|
|
|
|
|
|
#include <video/s1d13xxxfb.h>
|
|
|
|
|
|
|
|
#define BL_MAX_BRIGHT 255
|
|
|
|
#define BL_DEF_BRIGHT 25
|
|
|
|
|
|
|
|
static int jornada_bl_get_brightness(struct backlight_device *bd)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* check if backlight is on */
|
|
|
|
if (!(PPSR & PPC_LDD1))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
jornada_ssp_start();
|
|
|
|
|
|
|
|
/* cmd should return txdummy */
|
|
|
|
ret = jornada_ssp_byte(GETBRIGHTNESS);
|
|
|
|
|
|
|
|
if (jornada_ssp_byte(GETBRIGHTNESS) != TXDUMMY) {
|
2013-04-30 07:17:31 +08:00
|
|
|
dev_err(&bd->dev, "get brightness timeout\n");
|
2009-02-18 19:50:43 +08:00
|
|
|
jornada_ssp_end();
|
|
|
|
return -ETIMEDOUT;
|
2013-04-30 07:17:31 +08:00
|
|
|
}
|
2009-02-18 19:50:43 +08:00
|
|
|
|
2014-08-27 09:14:25 +08:00
|
|
|
/* exchange txdummy for value */
|
|
|
|
ret = jornada_ssp_byte(TXDUMMY);
|
|
|
|
|
2009-02-18 19:50:43 +08:00
|
|
|
jornada_ssp_end();
|
|
|
|
|
2012-12-18 08:00:21 +08:00
|
|
|
return BL_MAX_BRIGHT - ret;
|
2009-02-18 19:50:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int jornada_bl_update_status(struct backlight_device *bd)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
jornada_ssp_start();
|
|
|
|
|
|
|
|
/* If backlight is off then really turn it off */
|
|
|
|
if ((bd->props.power != FB_BLANK_UNBLANK) || (bd->props.fb_blank != FB_BLANK_UNBLANK)) {
|
|
|
|
ret = jornada_ssp_byte(BRIGHTNESSOFF);
|
|
|
|
if (ret != TXDUMMY) {
|
2013-04-30 07:17:31 +08:00
|
|
|
dev_info(&bd->dev, "brightness off timeout\n");
|
2009-02-18 19:50:43 +08:00
|
|
|
/* turn off backlight */
|
|
|
|
PPSR &= ~PPC_LDD1;
|
|
|
|
PPDR |= PPC_LDD1;
|
|
|
|
ret = -ETIMEDOUT;
|
|
|
|
}
|
|
|
|
} else /* turn on backlight */
|
|
|
|
PPSR |= PPC_LDD1;
|
|
|
|
|
|
|
|
/* send command to our mcu */
|
|
|
|
if (jornada_ssp_byte(SETBRIGHTNESS) != TXDUMMY) {
|
2013-04-30 07:17:31 +08:00
|
|
|
dev_info(&bd->dev, "failed to set brightness\n");
|
2009-02-18 19:50:43 +08:00
|
|
|
ret = -ETIMEDOUT;
|
2009-07-30 06:04:03 +08:00
|
|
|
goto out;
|
2009-02-18 19:50:43 +08:00
|
|
|
}
|
|
|
|
|
2012-12-18 08:00:21 +08:00
|
|
|
/*
|
|
|
|
* at this point we expect that the mcu has accepted
|
|
|
|
* our command and is waiting for our new value
|
|
|
|
* please note that maximum brightness is 255,
|
|
|
|
* but due to physical layout it is equal to 0, so we simply
|
|
|
|
* invert the value (MAX VALUE - NEW VALUE).
|
|
|
|
*/
|
|
|
|
if (jornada_ssp_byte(BL_MAX_BRIGHT - bd->props.brightness)
|
|
|
|
!= TXDUMMY) {
|
2013-04-30 07:17:31 +08:00
|
|
|
dev_err(&bd->dev, "set brightness failed\n");
|
2009-02-18 19:50:43 +08:00
|
|
|
ret = -ETIMEDOUT;
|
|
|
|
}
|
|
|
|
|
2012-12-18 08:00:21 +08:00
|
|
|
/*
|
|
|
|
* If infact we get an TXDUMMY as output we are happy and dont
|
|
|
|
* make any further comments about it
|
|
|
|
*/
|
2009-02-18 19:50:43 +08:00
|
|
|
out:
|
|
|
|
jornada_ssp_end();
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-12-14 07:58:57 +08:00
|
|
|
static const struct backlight_ops jornada_bl_ops = {
|
2009-02-18 19:50:43 +08:00
|
|
|
.get_brightness = jornada_bl_get_brightness,
|
|
|
|
.update_status = jornada_bl_update_status,
|
|
|
|
.options = BL_CORE_SUSPENDRESUME,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int jornada_bl_probe(struct platform_device *pdev)
|
|
|
|
{
|
2010-02-18 05:39:44 +08:00
|
|
|
struct backlight_properties props;
|
2009-02-18 19:50:43 +08:00
|
|
|
int ret;
|
|
|
|
struct backlight_device *bd;
|
|
|
|
|
2010-02-18 05:39:44 +08:00
|
|
|
memset(&props, 0, sizeof(struct backlight_properties));
|
2011-03-23 07:30:21 +08:00
|
|
|
props.type = BACKLIGHT_RAW;
|
2010-02-18 05:39:44 +08:00
|
|
|
props.max_brightness = BL_MAX_BRIGHT;
|
2009-02-18 19:50:43 +08:00
|
|
|
|
2014-01-24 07:54:24 +08:00
|
|
|
bd = devm_backlight_device_register(&pdev->dev, S1D_DEVICENAME,
|
|
|
|
&pdev->dev, NULL, &jornada_bl_ops,
|
|
|
|
&props);
|
2009-02-18 19:50:43 +08:00
|
|
|
if (IS_ERR(bd)) {
|
|
|
|
ret = PTR_ERR(bd);
|
2013-04-30 07:17:31 +08:00
|
|
|
dev_err(&pdev->dev, "failed to register device, err=%x\n", ret);
|
2009-02-18 19:50:43 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
bd->props.power = FB_BLANK_UNBLANK;
|
|
|
|
bd->props.brightness = BL_DEF_BRIGHT;
|
2012-12-18 08:00:21 +08:00
|
|
|
/*
|
|
|
|
* note. make sure max brightness is set otherwise
|
|
|
|
* you will get seemingly non-related errors when
|
|
|
|
* trying to change brightness
|
|
|
|
*/
|
2009-02-18 19:50:43 +08:00
|
|
|
jornada_bl_update_status(bd);
|
|
|
|
|
|
|
|
platform_set_drvdata(pdev, bd);
|
2013-04-30 07:17:31 +08:00
|
|
|
dev_info(&pdev->dev, "HP Jornada 700 series backlight driver\n");
|
2009-02-18 19:50:43 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver jornada_bl_driver = {
|
|
|
|
.probe = jornada_bl_probe,
|
|
|
|
.driver = {
|
|
|
|
.name = "jornada_bl",
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2012-01-11 07:09:11 +08:00
|
|
|
module_platform_driver(jornada_bl_driver);
|
2009-02-18 19:50:43 +08:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Kristoffer Ericson <kristoffer.ericson>");
|
|
|
|
MODULE_DESCRIPTION("HP Jornada 710/720/728 Backlight driver");
|
|
|
|
MODULE_LICENSE("GPL");
|