2 * Backlight Driver for HP iPAQ hx2750
4 * Copyright 2005 Openedhand Ltd.
6 * Author: Richard Purdie <richard@o-hand.com>
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/device.h>
18 #include <linux/spinlock.h>
20 #include <linux/backlight.h>
22 #include <asm/arch/pxa-regs.h>
23 #include <asm/arch/hx2750.h>
25 #define HX2750_MAX_INTENSITY 0x190
26 #define HX2750_DEFAULT_INTENSITY 0x082
28 static int hx2750_bl_powermode
= FB_BLANK_UNBLANK
;
29 static int current_intensity
= 0;
30 static spinlock_t bl_lock
= SPIN_LOCK_UNLOCKED
;
32 static void hx2750_set_intensity(int intensity
)
36 if (hx2750_bl_powermode
!= FB_BLANK_UNBLANK
) {
40 spin_lock_irqsave(&bl_lock
, flags
);
42 PWM_CTRL0
= 2; /* pre-scaler */
43 PWM_PWDUTY0
= intensity
; /* duty cycle */
44 PWM_PERVAL0
= 0x1f4; /* period */
47 pxa_set_cken(CKEN0_PWM0
,1);
48 hx2750_set_egpio(HX2750_EGPIO_LCD_PWR
| HX2750_EGPIO_BL_PWR
);
50 pxa_set_cken(CKEN0_PWM0
,0);
51 hx2750_clear_egpio(HX2750_EGPIO_LCD_PWR
| HX2750_EGPIO_BL_PWR
);
54 spin_unlock_irqrestore(&bl_lock
, flags
);
57 static void hx2750_bl_blank(int blank
)
62 case FB_BLANK_VSYNC_SUSPEND
:
63 case FB_BLANK_HSYNC_SUSPEND
:
64 case FB_BLANK_POWERDOWN
:
65 if (hx2750_bl_powermode
== FB_BLANK_UNBLANK
) {
66 hx2750_set_intensity(0);
67 hx2750_bl_powermode
= blank
;
70 case FB_BLANK_UNBLANK
:
71 if (hx2750_bl_powermode
!= FB_BLANK_UNBLANK
) {
72 hx2750_bl_powermode
= blank
;
73 hx2750_set_intensity(current_intensity
);
80 static int hx2750_bl_suspend(struct device
*dev
, u32 state
, u32 level
)
82 if (level
== SUSPEND_POWER_DOWN
)
83 hx2750_bl_blank(FB_BLANK_POWERDOWN
);
87 static int hx2750_bl_resume(struct device
*dev
, u32 level
)
89 if (level
== RESUME_POWER_ON
)
90 hx2750_bl_blank(FB_BLANK_UNBLANK
);
94 #define hx2750_bl_suspend NULL
95 #define hx2750_bl_resume NULL
99 static int hx2750_bl_set_power(struct backlight_device
*bd
, int state
)
101 hx2750_bl_blank(state
);
105 static int hx2750_bl_get_power(struct backlight_device
*bd
)
107 return hx2750_bl_powermode
;
110 static int hx2750_bl_set_intensity(struct backlight_device
*bd
, int intensity
)
112 if (intensity
> HX2750_MAX_INTENSITY
)
113 intensity
= HX2750_MAX_INTENSITY
;
114 hx2750_set_intensity(intensity
);
115 current_intensity
=intensity
;
119 static int hx2750_bl_get_intensity(struct backlight_device
*bd
)
121 return current_intensity
;
124 static struct backlight_properties hx2750_bl_data
= {
125 .owner
= THIS_MODULE
,
126 .get_power
= hx2750_bl_get_power
,
127 .set_power
= hx2750_bl_set_power
,
128 .max_brightness
= HX2750_MAX_INTENSITY
,
129 .get_brightness
= hx2750_bl_get_intensity
,
130 .set_brightness
= hx2750_bl_set_intensity
,
133 static struct backlight_device
*hx2750_backlight_device
;
135 static int __init
hx2750_bl_probe(struct device
*dev
)
137 hx2750_backlight_device
= backlight_device_register ("hx2750-bl",
138 NULL
, &hx2750_bl_data
);
139 if (IS_ERR (hx2750_backlight_device
))
140 return PTR_ERR (hx2750_backlight_device
);
142 hx2750_bl_powermode
= FB_BLANK_UNBLANK
;
143 hx2750_bl_set_intensity(NULL
, HX2750_DEFAULT_INTENSITY
);
145 pxa_set_cken(CKEN0_PWM0
,1);
147 printk("hx2750 Backlight Driver Initialized.\n");
151 static int hx2750_bl_remove(struct device
*dev
)
153 backlight_device_unregister(hx2750_backlight_device
);
155 hx2750_bl_set_intensity(NULL
, 0);
157 printk("hx2750 Backlight Driver Unloaded\n");
161 static struct device_driver hx2750_bl_driver
= {
163 .bus
= &platform_bus_type
,
164 .probe
= hx2750_bl_probe
,
165 .remove
= hx2750_bl_remove
,
166 .suspend
= hx2750_bl_suspend
,
167 .resume
= hx2750_bl_resume
,
170 static int __init
hx2750_bl_init(void)
172 return driver_register(&hx2750_bl_driver
);
175 static void __exit
hx2750_bl_exit(void)
177 driver_unregister(&hx2750_bl_driver
);
180 module_init(hx2750_bl_init
);
181 module_exit(hx2750_bl_exit
);
183 MODULE_AUTHOR("Richard Purdie <rpurdie@o-hand.com>");
184 MODULE_DESCRIPTION("iPAQ hx2750 Backlight Driver");
185 MODULE_LICENSE("GPLv2");