Commit | Line | Data |
---|---|---|
06c6f900 AS |
1 | /* |
2 | * Backlight Driver for HP Jornada 680 | |
3 | * | |
4 | * Copyright (c) 2005 Andriy Skulysh | |
5 | * | |
6 | * Based on Sharp's Corgi Backlight Driver | |
7 | * | |
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 | |
10 | * for more details. | |
11 | */ | |
12 | ||
13 | #include <linux/module.h> | |
14 | #include <linux/kernel.h> | |
15 | #include <linux/init.h> | |
5f27a27b | 16 | #include <linux/platform_device.h> |
06c6f900 AS |
17 | #include <linux/spinlock.h> |
18 | #include <linux/fb.h> | |
19 | #include <linux/backlight.h> | |
20 | ||
21 | #include <asm/cpu/dac.h> | |
1aea7e00 | 22 | #include <asm/hp6xx.h> |
848dd265 | 23 | #include <asm/hd64461.h> |
06c6f900 AS |
24 | |
25 | #define HP680_MAX_INTENSITY 255 | |
26 | #define HP680_DEFAULT_INTENSITY 10 | |
27 | ||
5f27a27b | 28 | static int hp680bl_suspended; |
06c6f900 | 29 | static int current_intensity = 0; |
34af946a | 30 | static DEFINE_SPINLOCK(bl_lock); |
06c6f900 | 31 | |
5f27a27b | 32 | static void hp680bl_send_intensity(struct backlight_device *bd) |
06c6f900 AS |
33 | { |
34 | unsigned long flags; | |
5f27a27b RP |
35 | u16 v; |
36 | int intensity = bd->props->brightness; | |
06c6f900 | 37 | |
5f27a27b RP |
38 | if (bd->props->power != FB_BLANK_UNBLANK) |
39 | intensity = 0; | |
40 | if (bd->props->fb_blank != FB_BLANK_UNBLANK) | |
41 | intensity = 0; | |
42 | if (hp680bl_suspended) | |
06c6f900 AS |
43 | intensity = 0; |
44 | ||
45 | spin_lock_irqsave(&bl_lock, flags); | |
5f27a27b RP |
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); | |
60 | } | |
06c6f900 | 61 | spin_unlock_irqrestore(&bl_lock, flags); |
06c6f900 | 62 | |
5f27a27b | 63 | current_intensity = intensity; |
06c6f900 AS |
64 | } |
65 | ||
5f27a27b | 66 | |
06c6f900 | 67 | #ifdef CONFIG_PM |
a8db3c19 | 68 | static int hp680bl_suspend(struct platform_device *pdev, pm_message_t state) |
06c6f900 | 69 | { |
a8db3c19 RP |
70 | struct backlight_device *bd = platform_get_drvdata(pdev); |
71 | ||
5f27a27b | 72 | hp680bl_suspended = 1; |
a8db3c19 | 73 | hp680bl_send_intensity(bd); |
06c6f900 AS |
74 | return 0; |
75 | } | |
76 | ||
a8db3c19 | 77 | static int hp680bl_resume(struct platform_device *pdev) |
06c6f900 | 78 | { |
a8db3c19 RP |
79 | struct backlight_device *bd = platform_get_drvdata(pdev); |
80 | ||
5f27a27b | 81 | hp680bl_suspended = 0; |
a8db3c19 | 82 | hp680bl_send_intensity(bd); |
06c6f900 AS |
83 | return 0; |
84 | } | |
85 | #else | |
86 | #define hp680bl_suspend NULL | |
87 | #define hp680bl_resume NULL | |
88 | #endif | |
89 | ||
5f27a27b | 90 | static int hp680bl_set_intensity(struct backlight_device *bd) |
06c6f900 | 91 | { |
5f27a27b | 92 | hp680bl_send_intensity(bd); |
06c6f900 AS |
93 | return 0; |
94 | } | |
95 | ||
96 | static int hp680bl_get_intensity(struct backlight_device *bd) | |
97 | { | |
98 | return current_intensity; | |
99 | } | |
100 | ||
101 | static struct backlight_properties hp680bl_data = { | |
06c6f900 AS |
102 | .max_brightness = HP680_MAX_INTENSITY, |
103 | .get_brightness = hp680bl_get_intensity, | |
5f27a27b | 104 | .update_status = hp680bl_set_intensity, |
06c6f900 AS |
105 | }; |
106 | ||
a8db3c19 | 107 | static int __init hp680bl_probe(struct platform_device *pdev) |
06c6f900 | 108 | { |
a8db3c19 RP |
109 | struct backlight_device *bd; |
110 | ||
111 | bd = backlight_device_register ("hp680-bl", &pdev->dev, NULL, | |
112 | &hp680bl_data); | |
113 | if (IS_ERR(bd)) | |
114 | return PTR_ERR(bd); | |
06c6f900 | 115 | |
a8db3c19 RP |
116 | platform_set_drvdata(pdev, bd); |
117 | ||
118 | bd->props->brightness = HP680_DEFAULT_INTENSITY; | |
119 | hp680bl_send_intensity(bd); | |
06c6f900 AS |
120 | |
121 | return 0; | |
122 | } | |
123 | ||
a8db3c19 | 124 | static int hp680bl_remove(struct platform_device *pdev) |
06c6f900 | 125 | { |
a8db3c19 RP |
126 | struct backlight_device *bd = platform_get_drvdata(pdev); |
127 | ||
4437cd1e HMH |
128 | hp680bl_data.brightness = 0; |
129 | hp680bl_data.power = 0; | |
a8db3c19 | 130 | hp680bl_send_intensity(bd); |
4437cd1e | 131 | |
a8db3c19 | 132 | backlight_device_unregister(bd); |
06c6f900 AS |
133 | |
134 | return 0; | |
135 | } | |
136 | ||
5f27a27b | 137 | static struct platform_driver hp680bl_driver = { |
06c6f900 AS |
138 | .probe = hp680bl_probe, |
139 | .remove = hp680bl_remove, | |
140 | .suspend = hp680bl_suspend, | |
141 | .resume = hp680bl_resume, | |
5f27a27b RP |
142 | .driver = { |
143 | .name = "hp680-bl", | |
144 | }, | |
06c6f900 AS |
145 | }; |
146 | ||
5f27a27b | 147 | static struct platform_device *hp680bl_device; |
06c6f900 AS |
148 | |
149 | static int __init hp680bl_init(void) | |
150 | { | |
151 | int ret; | |
152 | ||
5f27a27b | 153 | ret = platform_driver_register(&hp680bl_driver); |
06c6f900 | 154 | if (!ret) { |
5f27a27b RP |
155 | hp680bl_device = platform_device_alloc("hp680-bl", -1); |
156 | if (!hp680bl_device) | |
157 | return -ENOMEM; | |
158 | ||
159 | ret = platform_device_add(hp680bl_device); | |
160 | ||
161 | if (ret) { | |
162 | platform_device_put(hp680bl_device); | |
163 | platform_driver_unregister(&hp680bl_driver); | |
164 | } | |
06c6f900 AS |
165 | } |
166 | return ret; | |
167 | } | |
168 | ||
169 | static void __exit hp680bl_exit(void) | |
170 | { | |
5f27a27b RP |
171 | platform_device_unregister(hp680bl_device); |
172 | platform_driver_unregister(&hp680bl_driver); | |
06c6f900 AS |
173 | } |
174 | ||
175 | module_init(hp680bl_init); | |
176 | module_exit(hp680bl_exit); | |
177 | ||
848dd265 | 178 | MODULE_AUTHOR("Andriy Skulysh <askulysh@gmail.com>"); |
06c6f900 AS |
179 | MODULE_DESCRIPTION("HP Jornada 680 Backlight Driver"); |
180 | MODULE_LICENSE("GPL"); |