2005-04-17 02:20:36 +04:00
/*
2006-03-31 14:31:51 +04:00
* Backlight Driver for Sharp Zaurus Handhelds ( various models )
2005-04-17 02:20:36 +04:00
*
2006-03-31 14:31:51 +04:00
* Copyright ( c ) 2004 - 2006 Richard Purdie
2005-04-17 02:20:36 +04: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-29 22:07:23 +04:00
# include <linux/platform_device.h>
2006-03-31 14:31:51 +04:00
# include <linux/mutex.h>
2005-04-17 02:20:36 +04:00
# include <linux/fb.h>
# include <linux/backlight.h>
2006-03-31 14:31:49 +04:00
static int corgibl_intensity ;
2005-09-17 06:27:30 +04:00
static struct backlight_properties corgibl_data ;
2006-03-31 14:31:49 +04:00
static struct backlight_device * corgi_backlight_device ;
2007-09-03 03:27:00 +04:00
static struct generic_bl_info * bl_machinfo ;
2006-03-31 14:31:49 +04:00
static unsigned long corgibl_flags ;
# define CORGIBL_SUSPENDED 0x01
# define CORGIBL_BATTLOW 0x02
2005-04-17 02:20:36 +04:00
2006-03-31 14:31:49 +04:00
static int corgibl_send_intensity ( struct backlight_device * bd )
2005-04-17 02:20:36 +04:00
{
2007-02-11 02:07:48 +03:00
int intensity = bd - > props . brightness ;
2005-04-17 02:20:36 +04:00
2007-02-11 02:07:48 +03:00
if ( bd - > props . power ! = FB_BLANK_UNBLANK )
2006-03-31 14:31:49 +04:00
intensity = 0 ;
2007-02-11 02:07:48 +03:00
if ( bd - > props . fb_blank ! = FB_BLANK_UNBLANK )
2005-04-17 02:20:36 +04:00
intensity = 0 ;
2006-03-31 14:31:49 +04:00
if ( corgibl_flags & CORGIBL_SUSPENDED )
intensity = 0 ;
if ( corgibl_flags & CORGIBL_BATTLOW )
2006-03-31 14:31:51 +04:00
intensity & = bl_machinfo - > limit_mask ;
2005-09-13 12:25:33 +04:00
2006-03-31 14:31:51 +04:00
bl_machinfo - > set_bl_intensity ( intensity ) ;
2005-11-10 20:42:29 +03:00
2006-03-31 14:31:49 +04:00
corgibl_intensity = intensity ;
2007-09-03 03:27:00 +04:00
if ( bl_machinfo - > kick_battery )
bl_machinfo - > kick_battery ( ) ;
2005-04-17 02:20:36 +04:00
2006-03-31 14:31:49 +04:00
return 0 ;
2005-04-17 02:20:36 +04:00
}
# ifdef CONFIG_PM
2007-02-08 03:32:14 +03:00
static int corgibl_suspend ( struct platform_device * pdev , pm_message_t state )
2005-04-17 02:20:36 +04:00
{
2007-02-08 03:32:14 +03:00
struct backlight_device * bd = platform_get_drvdata ( pdev ) ;
2006-03-31 14:31:49 +04:00
corgibl_flags | = CORGIBL_SUSPENDED ;
2007-02-11 02:50:39 +03:00
backlight_update_status ( bd ) ;
2005-04-17 02:20:36 +04:00
return 0 ;
}
2007-02-08 03:32:14 +03:00
static int corgibl_resume ( struct platform_device * pdev )
2005-04-17 02:20:36 +04:00
{
2007-02-08 03:32:14 +03:00
struct backlight_device * bd = platform_get_drvdata ( pdev ) ;
2006-03-31 14:31:49 +04:00
corgibl_flags & = ~ CORGIBL_SUSPENDED ;
2007-02-11 02:50:39 +03:00
backlight_update_status ( bd ) ;
2005-04-17 02:20:36 +04:00
return 0 ;
}
# else
# define corgibl_suspend NULL
# define corgibl_resume NULL
# endif
2006-03-31 14:31:49 +04:00
static int corgibl_get_intensity ( struct backlight_device * bd )
2005-04-17 02:20:36 +04:00
{
2006-03-31 14:31:49 +04:00
return corgibl_intensity ;
2005-04-17 02:20:36 +04:00
}
/*
* 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 14:31:49 +04:00
if ( limit )
corgibl_flags | = CORGIBL_BATTLOW ;
else
corgibl_flags & = ~ CORGIBL_BATTLOW ;
2007-02-11 02:50:39 +03:00
backlight_update_status ( corgi_backlight_device ) ;
2005-04-17 02:20:36 +04:00
}
EXPORT_SYMBOL ( corgibl_limit_intensity ) ;
2007-02-11 02:07:48 +03:00
static struct backlight_ops corgibl_ops = {
2005-04-17 02:20:36 +04:00
. get_brightness = corgibl_get_intensity ,
2007-02-08 03:32:14 +03:00
. update_status = corgibl_send_intensity ,
2005-04-17 02:20:36 +04:00
} ;
2006-10-20 03:56:28 +04:00
static int corgibl_probe ( struct platform_device * pdev )
2005-04-17 02:20:36 +04:00
{
2007-09-03 03:27:00 +04:00
struct generic_bl_info * machinfo = pdev - > dev . platform_data ;
const char * name = " generic-bl " ;
2005-09-13 12:25:33 +04:00
2006-03-31 14:31:51 +04:00
bl_machinfo = machinfo ;
if ( ! machinfo - > limit_mask )
machinfo - > limit_mask = - 1 ;
2005-09-13 12:25:33 +04:00
2007-09-03 03:27:00 +04:00
if ( machinfo - > name )
name = machinfo - > name ;
corgi_backlight_device = backlight_device_register ( name ,
2007-02-11 02:07:48 +03:00
& pdev - > dev , NULL , & corgibl_ops ) ;
2005-04-17 02:20:36 +04:00
if ( IS_ERR ( corgi_backlight_device ) )
return PTR_ERR ( corgi_backlight_device ) ;
2007-02-08 03:32:14 +03:00
platform_set_drvdata ( pdev , corgi_backlight_device ) ;
2007-02-11 02:07:48 +03:00
corgi_backlight_device - > props . max_brightness = machinfo - > max_intensity ;
corgi_backlight_device - > props . power = FB_BLANK_UNBLANK ;
corgi_backlight_device - > props . brightness = machinfo - > default_intensity ;
2007-02-11 02:50:39 +03:00
backlight_update_status ( corgi_backlight_device ) ;
2005-04-17 02:20:36 +04:00
printk ( " Corgi Backlight Driver Initialized. \n " ) ;
return 0 ;
}
2007-02-08 03:32:14 +03:00
static int corgibl_remove ( struct platform_device * pdev )
2005-04-17 02:20:36 +04:00
{
2007-02-08 03:32:14 +03:00
struct backlight_device * bd = platform_get_drvdata ( pdev ) ;
2006-12-08 13:40:49 +03:00
corgibl_data . power = 0 ;
corgibl_data . brightness = 0 ;
2007-02-11 02:50:39 +03:00
backlight_update_status ( bd ) ;
2006-12-08 13:40:49 +03:00
2007-02-08 03:32:14 +03:00
backlight_device_unregister ( bd ) ;
2005-04-17 02:20:36 +04:00
printk ( " Corgi Backlight Driver Unloaded \n " ) ;
return 0 ;
}
2005-11-10 01:32:44 +03:00
static struct platform_driver corgibl_driver = {
2005-04-17 02:20:36 +04:00
. probe = corgibl_probe ,
. remove = corgibl_remove ,
. suspend = corgibl_suspend ,
. resume = corgibl_resume ,
2005-11-10 01:32:44 +03:00
. driver = {
2007-09-03 03:27:00 +04:00
. name = " generic-bl " ,
2005-11-10 01:32:44 +03:00
} ,
2005-04-17 02:20:36 +04:00
} ;
static int __init corgibl_init ( void )
{
2005-11-10 01:32:44 +03:00
return platform_driver_register ( & corgibl_driver ) ;
2005-04-17 02:20:36 +04:00
}
static void __exit corgibl_exit ( void )
{
2005-11-10 01:32:44 +03:00
platform_driver_unregister ( & corgibl_driver ) ;
2005-04-17 02:20:36 +04:00
}
module_init ( corgibl_init ) ;
module_exit ( corgibl_exit ) ;
MODULE_AUTHOR ( " Richard Purdie <rpurdie@rpsys.net> " ) ;
MODULE_DESCRIPTION ( " Corgi Backlight Driver " ) ;
2006-10-20 03:58:49 +04:00
MODULE_LICENSE ( " GPL " ) ;