2 * Backlight Driver for HP Jornada 680
4 * Copyright (c) 2005 Andriy Skulysh
6 * Based on Sharp's Corgi Backlight Driver
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file "COPYING" in the main directory of this archive
13 #include <linux/module.h>
14 #include <linux/kernel.h>
15 #include <linux/init.h>
16 #include <linux/platform_device.h>
17 #include <linux/spinlock.h>
19 #include <linux/backlight.h>
22 #include <mach/hp6xx.h>
23 #include <asm/hd64461.h>
25 #define HP680_MAX_INTENSITY 255
26 #define HP680_DEFAULT_INTENSITY 10
28 static int hp680bl_suspended
;
29 static int current_intensity
= 0;
30 static DEFINE_SPINLOCK(bl_lock
);
32 static void hp680bl_send_intensity(struct backlight_device
*bd
)
36 int intensity
= bd
->props
.brightness
;
38 if (bd
->props
.power
!= FB_BLANK_UNBLANK
)
40 if (bd
->props
.fb_blank
!= FB_BLANK_UNBLANK
)
42 if (hp680bl_suspended
)
45 spin_lock_irqsave(&bl_lock
, flags
);
46 if (intensity
&& current_intensity
== 0) {
47 sh_dac_enable(DAC_LCD_BRIGHTNESS
);
48 v
= inw(HD64461_GPBDR
);
49 v
&= ~HD64461_GPBDR_LCDOFF
;
50 outw(v
, HD64461_GPBDR
);
51 sh_dac_output(255-(u8
)intensity
, DAC_LCD_BRIGHTNESS
);
52 } else if (intensity
== 0 && current_intensity
!= 0) {
53 sh_dac_output(255-(u8
)intensity
, DAC_LCD_BRIGHTNESS
);
54 sh_dac_disable(DAC_LCD_BRIGHTNESS
);
55 v
= inw(HD64461_GPBDR
);
56 v
|= HD64461_GPBDR_LCDOFF
;
57 outw(v
, HD64461_GPBDR
);
58 } else if (intensity
) {
59 sh_dac_output(255-(u8
)intensity
, DAC_LCD_BRIGHTNESS
);
61 spin_unlock_irqrestore(&bl_lock
, flags
);
63 current_intensity
= intensity
;
68 static int hp680bl_suspend(struct platform_device
*pdev
, pm_message_t state
)
70 struct backlight_device
*bd
= platform_get_drvdata(pdev
);
72 hp680bl_suspended
= 1;
73 hp680bl_send_intensity(bd
);
77 static int hp680bl_resume(struct platform_device
*pdev
)
79 struct backlight_device
*bd
= platform_get_drvdata(pdev
);
81 hp680bl_suspended
= 0;
82 hp680bl_send_intensity(bd
);
86 #define hp680bl_suspend NULL
87 #define hp680bl_resume NULL
90 static int hp680bl_set_intensity(struct backlight_device
*bd
)
92 hp680bl_send_intensity(bd
);
96 static int hp680bl_get_intensity(struct backlight_device
*bd
)
98 return current_intensity
;
101 static const struct backlight_ops hp680bl_ops
= {
102 .get_brightness
= hp680bl_get_intensity
,
103 .update_status
= hp680bl_set_intensity
,
106 static int __devinit
hp680bl_probe(struct platform_device
*pdev
)
108 struct backlight_properties props
;
109 struct backlight_device
*bd
;
111 memset(&props
, 0, sizeof(struct backlight_properties
));
112 props
.max_brightness
= HP680_MAX_INTENSITY
;
113 bd
= backlight_device_register("hp680-bl", &pdev
->dev
, NULL
,
114 &hp680bl_ops
, &props
);
118 platform_set_drvdata(pdev
, bd
);
120 bd
->props
.brightness
= HP680_DEFAULT_INTENSITY
;
121 hp680bl_send_intensity(bd
);
126 static int hp680bl_remove(struct platform_device
*pdev
)
128 struct backlight_device
*bd
= platform_get_drvdata(pdev
);
130 bd
->props
.brightness
= 0;
132 hp680bl_send_intensity(bd
);
134 backlight_device_unregister(bd
);
139 static struct platform_driver hp680bl_driver
= {
140 .probe
= hp680bl_probe
,
141 .remove
= hp680bl_remove
,
142 .suspend
= hp680bl_suspend
,
143 .resume
= hp680bl_resume
,
149 static struct platform_device
*hp680bl_device
;
151 static int __init
hp680bl_init(void)
155 ret
= platform_driver_register(&hp680bl_driver
);
158 hp680bl_device
= platform_device_register_simple("hp680-bl", -1,
160 if (IS_ERR(hp680bl_device
)) {
161 platform_driver_unregister(&hp680bl_driver
);
162 return PTR_ERR(hp680bl_device
);
167 static void __exit
hp680bl_exit(void)
169 platform_device_unregister(hp680bl_device
);
170 platform_driver_unregister(&hp680bl_driver
);
173 module_init(hp680bl_init
);
174 module_exit(hp680bl_exit
);
176 MODULE_AUTHOR("Andriy Skulysh <askulysh@gmail.com>");
177 MODULE_DESCRIPTION("HP Jornada 680 Backlight Driver");
178 MODULE_LICENSE("GPL");