2006-02-01 06:06:53 -05:00
|
|
|
/*
|
|
|
|
* Backlight Driver for HP Jornada 680
|
|
|
|
*
|
|
|
|
* Copyright (c) 2005 Andriy Skulysh
|
|
|
|
*
|
|
|
|
* Based on Sharp's Corgi Backlight Driver
|
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU General Public
|
|
|
|
* License. See the file "COPYING" in the main directory of this archive
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/init.h>
|
2006-03-31 05:31:50 -05:00
|
|
|
#include <linux/platform_device.h>
|
2006-02-01 06:06:53 -05:00
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/fb.h>
|
|
|
|
#include <linux/backlight.h>
|
|
|
|
|
|
|
|
#include <asm/cpu/dac.h>
|
2006-10-30 21:47:27 -05:00
|
|
|
#include <asm/hp6xx.h>
|
2006-09-27 03:09:59 -04:00
|
|
|
#include <asm/hd64461.h>
|
2006-02-01 06:06:53 -05:00
|
|
|
|
|
|
|
#define HP680_MAX_INTENSITY 255
|
|
|
|
#define HP680_DEFAULT_INTENSITY 10
|
|
|
|
|
2006-03-31 05:31:50 -05:00
|
|
|
static int hp680bl_suspended;
|
2006-02-01 06:06:53 -05:00
|
|
|
static int current_intensity = 0;
|
2006-06-27 05:53:55 -04:00
|
|
|
static DEFINE_SPINLOCK(bl_lock);
|
2006-03-31 05:31:50 -05:00
|
|
|
static struct backlight_device *hp680_backlight_device;
|
2006-02-01 06:06:53 -05:00
|
|
|
|
2006-03-31 05:31:50 -05:00
|
|
|
static void hp680bl_send_intensity(struct backlight_device *bd)
|
2006-02-01 06:06:53 -05:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
2006-03-31 05:31:50 -05:00
|
|
|
u16 v;
|
|
|
|
int intensity = bd->props->brightness;
|
2006-02-01 06:06:53 -05:00
|
|
|
|
2006-03-31 05:31:50 -05:00
|
|
|
if (bd->props->power != FB_BLANK_UNBLANK)
|
|
|
|
intensity = 0;
|
|
|
|
if (bd->props->fb_blank != FB_BLANK_UNBLANK)
|
|
|
|
intensity = 0;
|
|
|
|
if (hp680bl_suspended)
|
2006-02-01 06:06:53 -05:00
|
|
|
intensity = 0;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&bl_lock, flags);
|
2006-03-31 05:31:50 -05:00
|
|
|
if (intensity && current_intensity == 0) {
|
|
|
|
sh_dac_enable(DAC_LCD_BRIGHTNESS);
|
|
|
|
v = inw(HD64461_GPBDR);
|
|
|
|
v &= ~HD64461_GPBDR_LCDOFF;
|
|
|
|
outw(v, HD64461_GPBDR);
|
|
|
|
sh_dac_output(255-(u8)intensity, DAC_LCD_BRIGHTNESS);
|
|
|
|
} else if (intensity == 0 && current_intensity != 0) {
|
|
|
|
sh_dac_output(255-(u8)intensity, DAC_LCD_BRIGHTNESS);
|
|
|
|
sh_dac_disable(DAC_LCD_BRIGHTNESS);
|
|
|
|
v = inw(HD64461_GPBDR);
|
|
|
|
v |= HD64461_GPBDR_LCDOFF;
|
|
|
|
outw(v, HD64461_GPBDR);
|
|
|
|
} else if (intensity) {
|
|
|
|
sh_dac_output(255-(u8)intensity, DAC_LCD_BRIGHTNESS);
|
|
|
|
}
|
2006-02-01 06:06:53 -05:00
|
|
|
spin_unlock_irqrestore(&bl_lock, flags);
|
|
|
|
|
2006-03-31 05:31:50 -05:00
|
|
|
current_intensity = intensity;
|
2006-02-01 06:06:53 -05:00
|
|
|
}
|
|
|
|
|
2006-03-31 05:31:50 -05:00
|
|
|
|
2006-02-01 06:06:53 -05:00
|
|
|
#ifdef CONFIG_PM
|
2006-03-31 05:31:50 -05:00
|
|
|
static int hp680bl_suspend(struct platform_device *dev, pm_message_t state)
|
2006-02-01 06:06:53 -05:00
|
|
|
{
|
2006-03-31 05:31:50 -05:00
|
|
|
hp680bl_suspended = 1;
|
|
|
|
hp680bl_send_intensity(hp680_backlight_device);
|
2006-02-01 06:06:53 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-03-31 05:31:50 -05:00
|
|
|
static int hp680bl_resume(struct platform_device *dev)
|
2006-02-01 06:06:53 -05:00
|
|
|
{
|
2006-03-31 05:31:50 -05:00
|
|
|
hp680bl_suspended = 0;
|
|
|
|
hp680bl_send_intensity(hp680_backlight_device);
|
2006-02-01 06:06:53 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define hp680bl_suspend NULL
|
|
|
|
#define hp680bl_resume NULL
|
|
|
|
#endif
|
|
|
|
|
2006-03-31 05:31:50 -05:00
|
|
|
static int hp680bl_set_intensity(struct backlight_device *bd)
|
2006-02-01 06:06:53 -05:00
|
|
|
{
|
2006-03-31 05:31:50 -05:00
|
|
|
hp680bl_send_intensity(bd);
|
2006-02-01 06:06:53 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hp680bl_get_intensity(struct backlight_device *bd)
|
|
|
|
{
|
|
|
|
return current_intensity;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct backlight_properties hp680bl_data = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.max_brightness = HP680_MAX_INTENSITY,
|
|
|
|
.get_brightness = hp680bl_get_intensity,
|
2006-03-31 05:31:50 -05:00
|
|
|
.update_status = hp680bl_set_intensity,
|
2006-02-01 06:06:53 -05:00
|
|
|
};
|
|
|
|
|
2006-03-31 05:31:50 -05:00
|
|
|
static int __init hp680bl_probe(struct platform_device *dev)
|
2006-02-01 06:06:53 -05:00
|
|
|
{
|
|
|
|
hp680_backlight_device = backlight_device_register ("hp680-bl",
|
2006-12-30 10:40:11 -05:00
|
|
|
&dev->dev, NULL, &hp680bl_data);
|
2006-02-01 06:06:53 -05:00
|
|
|
if (IS_ERR (hp680_backlight_device))
|
|
|
|
return PTR_ERR (hp680_backlight_device);
|
|
|
|
|
2006-03-31 05:31:50 -05:00
|
|
|
hp680_backlight_device->props->brightness = HP680_DEFAULT_INTENSITY;
|
|
|
|
hp680bl_send_intensity(hp680_backlight_device);
|
2006-02-01 06:06:53 -05:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-03-31 05:31:50 -05:00
|
|
|
static int hp680bl_remove(struct platform_device *dev)
|
2006-02-01 06:06:53 -05:00
|
|
|
{
|
2006-12-08 05:40:49 -05:00
|
|
|
hp680bl_data.brightness = 0;
|
|
|
|
hp680bl_data.power = 0;
|
|
|
|
hp680bl_send_intensity(hp680_backlight_device);
|
|
|
|
|
2006-02-01 06:06:53 -05:00
|
|
|
backlight_device_unregister(hp680_backlight_device);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-03-31 05:31:50 -05:00
|
|
|
static struct platform_driver hp680bl_driver = {
|
2006-02-01 06:06:53 -05:00
|
|
|
.probe = hp680bl_probe,
|
|
|
|
.remove = hp680bl_remove,
|
|
|
|
.suspend = hp680bl_suspend,
|
|
|
|
.resume = hp680bl_resume,
|
2006-03-31 05:31:50 -05:00
|
|
|
.driver = {
|
|
|
|
.name = "hp680-bl",
|
|
|
|
},
|
2006-02-01 06:06:53 -05:00
|
|
|
};
|
|
|
|
|
2006-03-31 05:31:50 -05:00
|
|
|
static struct platform_device *hp680bl_device;
|
2006-02-01 06:06:53 -05:00
|
|
|
|
|
|
|
static int __init hp680bl_init(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2006-03-31 05:31:50 -05:00
|
|
|
ret = platform_driver_register(&hp680bl_driver);
|
2006-02-01 06:06:53 -05:00
|
|
|
if (!ret) {
|
2006-03-31 05:31:50 -05:00
|
|
|
hp680bl_device = platform_device_alloc("hp680-bl", -1);
|
|
|
|
if (!hp680bl_device)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
ret = platform_device_add(hp680bl_device);
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
platform_device_put(hp680bl_device);
|
|
|
|
platform_driver_unregister(&hp680bl_driver);
|
|
|
|
}
|
2006-02-01 06:06:53 -05:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit hp680bl_exit(void)
|
|
|
|
{
|
2006-03-31 05:31:50 -05:00
|
|
|
platform_device_unregister(hp680bl_device);
|
|
|
|
platform_driver_unregister(&hp680bl_driver);
|
2006-02-01 06:06:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(hp680bl_init);
|
|
|
|
module_exit(hp680bl_exit);
|
|
|
|
|
2006-09-27 03:09:59 -04:00
|
|
|
MODULE_AUTHOR("Andriy Skulysh <askulysh@gmail.com>");
|
2006-02-01 06:06:53 -05:00
|
|
|
MODULE_DESCRIPTION("HP Jornada 680 Backlight Driver");
|
|
|
|
MODULE_LICENSE("GPL");
|