2 * Backlight Driver for Sharp Zaurus Handhelds (various models)
4 * Copyright (c) 2004-2006 Richard Purdie
6 * Based on Sharp's 2.4 Backlight Driver
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
14 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <linux/platform_device.h>
18 #include <linux/mutex.h>
20 #include <linux/backlight.h>
21 #include <asm/arch/sharpsl.h>
22 #include <asm/hardware/sharpsl_pm.h>
24 static int corgibl_intensity
;
25 static DEFINE_MUTEX(bl_mutex
);
26 static struct backlight_properties corgibl_data
;
27 static struct backlight_device
*corgi_backlight_device
;
28 static struct corgibl_machinfo
*bl_machinfo
;
30 static unsigned long corgibl_flags
;
31 #define CORGIBL_SUSPENDED 0x01
32 #define CORGIBL_BATTLOW 0x02
34 static int corgibl_send_intensity(struct backlight_device
*bd
)
36 void (*corgi_kick_batt
)(void);
37 int intensity
= bd
->props
->brightness
;
39 if (bd
->props
->power
!= FB_BLANK_UNBLANK
)
41 if (bd
->props
->fb_blank
!= FB_BLANK_UNBLANK
)
43 if (corgibl_flags
& CORGIBL_SUSPENDED
)
45 if (corgibl_flags
& CORGIBL_BATTLOW
)
46 intensity
&= bl_machinfo
->limit_mask
;
48 mutex_lock(&bl_mutex
);
49 bl_machinfo
->set_bl_intensity(intensity
);
50 mutex_unlock(&bl_mutex
);
52 corgibl_intensity
= intensity
;
54 corgi_kick_batt
= symbol_get(sharpsl_battery_kick
);
55 if (corgi_kick_batt
) {
57 symbol_put(sharpsl_battery_kick
);
64 static int corgibl_suspend(struct platform_device
*dev
, pm_message_t state
)
66 corgibl_flags
|= CORGIBL_SUSPENDED
;
67 corgibl_send_intensity(corgi_backlight_device
);
71 static int corgibl_resume(struct platform_device
*dev
)
73 corgibl_flags
&= ~CORGIBL_SUSPENDED
;
74 corgibl_send_intensity(corgi_backlight_device
);
78 #define corgibl_suspend NULL
79 #define corgibl_resume NULL
82 static int corgibl_get_intensity(struct backlight_device
*bd
)
84 return corgibl_intensity
;
87 static int corgibl_set_intensity(struct backlight_device
*bd
)
89 corgibl_send_intensity(corgi_backlight_device
);
94 * Called when the battery is low to limit the backlight intensity.
95 * If limit==0 clear any limit, otherwise limit the intensity
97 void corgibl_limit_intensity(int limit
)
100 corgibl_flags
|= CORGIBL_BATTLOW
;
102 corgibl_flags
&= ~CORGIBL_BATTLOW
;
103 corgibl_send_intensity(corgi_backlight_device
);
105 EXPORT_SYMBOL(corgibl_limit_intensity
);
108 static struct backlight_properties corgibl_data
= {
109 .owner
= THIS_MODULE
,
110 .get_brightness
= corgibl_get_intensity
,
111 .update_status
= corgibl_set_intensity
,
114 static int corgibl_probe(struct platform_device
*pdev
)
116 struct corgibl_machinfo
*machinfo
= pdev
->dev
.platform_data
;
118 bl_machinfo
= machinfo
;
119 corgibl_data
.max_brightness
= machinfo
->max_intensity
;
120 if (!machinfo
->limit_mask
)
121 machinfo
->limit_mask
= -1;
123 corgi_backlight_device
= backlight_device_register ("corgi-bl",
124 NULL
, &corgibl_data
);
125 if (IS_ERR (corgi_backlight_device
))
126 return PTR_ERR (corgi_backlight_device
);
128 corgibl_data
.power
= FB_BLANK_UNBLANK
;
129 corgibl_data
.brightness
= machinfo
->default_intensity
;
130 corgibl_send_intensity(corgi_backlight_device
);
132 printk("Corgi Backlight Driver Initialized.\n");
136 static int corgibl_remove(struct platform_device
*dev
)
138 backlight_device_unregister(corgi_backlight_device
);
140 printk("Corgi Backlight Driver Unloaded\n");
144 static struct platform_driver corgibl_driver
= {
145 .probe
= corgibl_probe
,
146 .remove
= corgibl_remove
,
147 .suspend
= corgibl_suspend
,
148 .resume
= corgibl_resume
,
154 static int __init
corgibl_init(void)
156 return platform_driver_register(&corgibl_driver
);
159 static void __exit
corgibl_exit(void)
161 platform_driver_unregister(&corgibl_driver
);
164 module_init(corgibl_init
);
165 module_exit(corgibl_exit
);
167 MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>");
168 MODULE_DESCRIPTION("Corgi Backlight Driver");
169 MODULE_LICENSE("GPLv2");