2005-04-17 06:20:36 +08:00
|
|
|
/*
|
2006-03-31 18:31:51 +08:00
|
|
|
* Backlight Driver for Sharp Zaurus Handhelds (various models)
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
2006-03-31 18:31:51 +08:00
|
|
|
* Copyright (c) 2004-2006 Richard Purdie
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* Based on Sharp's 2.4 Backlight Driver
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/init.h>
|
2005-10-30 02:07:23 +08:00
|
|
|
#include <linux/platform_device.h>
|
2006-03-31 18:31:51 +08:00
|
|
|
#include <linux/mutex.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/fb.h>
|
|
|
|
#include <linux/backlight.h>
|
2005-09-17 10:27:30 +08:00
|
|
|
#include <asm/arch/sharpsl.h>
|
2006-01-06 04:44:55 +08:00
|
|
|
#include <asm/hardware/sharpsl_pm.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-03-31 18:31:49 +08:00
|
|
|
static int corgibl_intensity;
|
2006-03-31 18:31:51 +08:00
|
|
|
static DEFINE_MUTEX(bl_mutex);
|
2005-09-17 10:27:30 +08:00
|
|
|
static struct backlight_properties corgibl_data;
|
2006-03-31 18:31:49 +08:00
|
|
|
static struct backlight_device *corgi_backlight_device;
|
2006-03-31 18:31:51 +08:00
|
|
|
static struct corgibl_machinfo *bl_machinfo;
|
2006-03-31 18:31:49 +08:00
|
|
|
|
|
|
|
static unsigned long corgibl_flags;
|
|
|
|
#define CORGIBL_SUSPENDED 0x01
|
|
|
|
#define CORGIBL_BATTLOW 0x02
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-03-31 18:31:49 +08:00
|
|
|
static int corgibl_send_intensity(struct backlight_device *bd)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
void (*corgi_kick_batt)(void);
|
2006-03-31 18:31:49 +08:00
|
|
|
int intensity = bd->props->brightness;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-03-31 18:31:49 +08:00
|
|
|
if (bd->props->power != FB_BLANK_UNBLANK)
|
|
|
|
intensity = 0;
|
|
|
|
if (bd->props->fb_blank != FB_BLANK_UNBLANK)
|
2005-04-17 06:20:36 +08:00
|
|
|
intensity = 0;
|
2006-03-31 18:31:49 +08:00
|
|
|
if (corgibl_flags & CORGIBL_SUSPENDED)
|
|
|
|
intensity = 0;
|
|
|
|
if (corgibl_flags & CORGIBL_BATTLOW)
|
2006-03-31 18:31:51 +08:00
|
|
|
intensity &= bl_machinfo->limit_mask;
|
2005-09-13 16:25:33 +08:00
|
|
|
|
2006-03-31 18:31:51 +08:00
|
|
|
mutex_lock(&bl_mutex);
|
|
|
|
bl_machinfo->set_bl_intensity(intensity);
|
|
|
|
mutex_unlock(&bl_mutex);
|
2005-11-11 01:42:29 +08:00
|
|
|
|
2006-03-31 18:31:49 +08:00
|
|
|
corgibl_intensity = intensity;
|
|
|
|
|
2005-11-11 01:42:29 +08:00
|
|
|
corgi_kick_batt = symbol_get(sharpsl_battery_kick);
|
|
|
|
if (corgi_kick_batt) {
|
|
|
|
corgi_kick_batt();
|
|
|
|
symbol_put(sharpsl_battery_kick);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-03-31 18:31:49 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_PM
|
2005-11-10 06:32:44 +08:00
|
|
|
static int corgibl_suspend(struct platform_device *dev, pm_message_t state)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-03-31 18:31:49 +08:00
|
|
|
corgibl_flags |= CORGIBL_SUSPENDED;
|
|
|
|
corgibl_send_intensity(corgi_backlight_device);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-10 06:32:44 +08:00
|
|
|
static int corgibl_resume(struct platform_device *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-03-31 18:31:49 +08:00
|
|
|
corgibl_flags &= ~CORGIBL_SUSPENDED;
|
|
|
|
corgibl_send_intensity(corgi_backlight_device);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define corgibl_suspend NULL
|
|
|
|
#define corgibl_resume NULL
|
|
|
|
#endif
|
|
|
|
|
2006-03-31 18:31:49 +08:00
|
|
|
static int corgibl_get_intensity(struct backlight_device *bd)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-03-31 18:31:49 +08:00
|
|
|
return corgibl_intensity;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2006-03-31 18:31:49 +08:00
|
|
|
static int corgibl_set_intensity(struct backlight_device *bd)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-03-31 18:31:49 +08:00
|
|
|
corgibl_send_intensity(corgi_backlight_device);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called when the battery is low to limit the backlight intensity.
|
|
|
|
* If limit==0 clear any limit, otherwise limit the intensity
|
|
|
|
*/
|
|
|
|
void corgibl_limit_intensity(int limit)
|
|
|
|
{
|
2006-03-31 18:31:49 +08:00
|
|
|
if (limit)
|
|
|
|
corgibl_flags |= CORGIBL_BATTLOW;
|
|
|
|
else
|
|
|
|
corgibl_flags &= ~CORGIBL_BATTLOW;
|
|
|
|
corgibl_send_intensity(corgi_backlight_device);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(corgibl_limit_intensity);
|
|
|
|
|
|
|
|
|
|
|
|
static struct backlight_properties corgibl_data = {
|
2006-03-31 18:31:49 +08:00
|
|
|
.owner = THIS_MODULE,
|
2005-04-17 06:20:36 +08:00
|
|
|
.get_brightness = corgibl_get_intensity,
|
2006-03-31 18:31:49 +08:00
|
|
|
.update_status = corgibl_set_intensity,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2006-10-20 07:56:28 +08:00
|
|
|
static int corgibl_probe(struct platform_device *pdev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-10 06:32:44 +08:00
|
|
|
struct corgibl_machinfo *machinfo = pdev->dev.platform_data;
|
2005-09-13 16:25:33 +08:00
|
|
|
|
2006-03-31 18:31:51 +08:00
|
|
|
bl_machinfo = machinfo;
|
2005-09-13 16:25:33 +08:00
|
|
|
corgibl_data.max_brightness = machinfo->max_intensity;
|
2006-03-31 18:31:51 +08:00
|
|
|
if (!machinfo->limit_mask)
|
|
|
|
machinfo->limit_mask = -1;
|
2005-09-13 16:25:33 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
corgi_backlight_device = backlight_device_register ("corgi-bl",
|
|
|
|
NULL, &corgibl_data);
|
|
|
|
if (IS_ERR (corgi_backlight_device))
|
|
|
|
return PTR_ERR (corgi_backlight_device);
|
|
|
|
|
2006-03-31 18:31:49 +08:00
|
|
|
corgibl_data.power = FB_BLANK_UNBLANK;
|
2006-03-31 18:31:51 +08:00
|
|
|
corgibl_data.brightness = machinfo->default_intensity;
|
2006-03-31 18:31:49 +08:00
|
|
|
corgibl_send_intensity(corgi_backlight_device);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
printk("Corgi Backlight Driver Initialized.\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-10 06:32:44 +08:00
|
|
|
static int corgibl_remove(struct platform_device *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
backlight_device_unregister(corgi_backlight_device);
|
|
|
|
|
|
|
|
printk("Corgi Backlight Driver Unloaded\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-10 06:32:44 +08:00
|
|
|
static struct platform_driver corgibl_driver = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.probe = corgibl_probe,
|
|
|
|
.remove = corgibl_remove,
|
|
|
|
.suspend = corgibl_suspend,
|
|
|
|
.resume = corgibl_resume,
|
2005-11-10 06:32:44 +08:00
|
|
|
.driver = {
|
|
|
|
.name = "corgi-bl",
|
|
|
|
},
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int __init corgibl_init(void)
|
|
|
|
{
|
2005-11-10 06:32:44 +08:00
|
|
|
return platform_driver_register(&corgibl_driver);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit corgibl_exit(void)
|
|
|
|
{
|
2005-11-10 06:32:44 +08:00
|
|
|
platform_driver_unregister(&corgibl_driver);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(corgibl_init);
|
|
|
|
module_exit(corgibl_exit);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>");
|
|
|
|
MODULE_DESCRIPTION("Corgi Backlight Driver");
|
|
|
|
MODULE_LICENSE("GPLv2");
|