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 | ||
193f3c2f | 21 | #include <cpu/dac.h> |
7639a454 | 22 | #include <mach/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; |
ff10b074 | 29 | static int current_intensity; |
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 | 35 | u16 v; |
599a52d1 | 36 | int intensity = bd->props.brightness; |
06c6f900 | 37 | |
599a52d1 | 38 | if (bd->props.power != FB_BLANK_UNBLANK) |
5f27a27b | 39 | intensity = 0; |
599a52d1 | 40 | if (bd->props.fb_blank != FB_BLANK_UNBLANK) |
5f27a27b RP |
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 | |
b55bb78d JH |
67 | #ifdef CONFIG_PM_SLEEP |
68 | static int hp680bl_suspend(struct device *dev) | |
06c6f900 | 69 | { |
b55bb78d | 70 | struct backlight_device *bd = dev_get_drvdata(dev); |
a8db3c19 | 71 | |
5f27a27b | 72 | hp680bl_suspended = 1; |
a8db3c19 | 73 | hp680bl_send_intensity(bd); |
06c6f900 AS |
74 | return 0; |
75 | } | |
76 | ||
b55bb78d | 77 | static int hp680bl_resume(struct device *dev) |
06c6f900 | 78 | { |
b55bb78d | 79 | struct backlight_device *bd = dev_get_drvdata(dev); |
a8db3c19 | 80 | |
5f27a27b | 81 | hp680bl_suspended = 0; |
a8db3c19 | 82 | hp680bl_send_intensity(bd); |
06c6f900 AS |
83 | return 0; |
84 | } | |
06c6f900 AS |
85 | #endif |
86 | ||
b55bb78d JH |
87 | static SIMPLE_DEV_PM_OPS(hp680bl_pm_ops, hp680bl_suspend, hp680bl_resume); |
88 | ||
5f27a27b | 89 | static int hp680bl_set_intensity(struct backlight_device *bd) |
06c6f900 | 90 | { |
5f27a27b | 91 | hp680bl_send_intensity(bd); |
06c6f900 AS |
92 | return 0; |
93 | } | |
94 | ||
95 | static int hp680bl_get_intensity(struct backlight_device *bd) | |
96 | { | |
97 | return current_intensity; | |
98 | } | |
99 | ||
9905a43b | 100 | static const struct backlight_ops hp680bl_ops = { |
06c6f900 | 101 | .get_brightness = hp680bl_get_intensity, |
5f27a27b | 102 | .update_status = hp680bl_set_intensity, |
06c6f900 AS |
103 | }; |
104 | ||
1b9e450d | 105 | static int hp680bl_probe(struct platform_device *pdev) |
06c6f900 | 106 | { |
a19a6ee6 | 107 | struct backlight_properties props; |
a8db3c19 RP |
108 | struct backlight_device *bd; |
109 | ||
a19a6ee6 | 110 | memset(&props, 0, sizeof(struct backlight_properties)); |
bb7ca747 | 111 | props.type = BACKLIGHT_RAW; |
a19a6ee6 | 112 | props.max_brightness = HP680_MAX_INTENSITY; |
0561c179 JH |
113 | bd = devm_backlight_device_register(&pdev->dev, "hp680-bl", &pdev->dev, |
114 | NULL, &hp680bl_ops, &props); | |
a8db3c19 RP |
115 | if (IS_ERR(bd)) |
116 | return PTR_ERR(bd); | |
06c6f900 | 117 | |
a8db3c19 RP |
118 | platform_set_drvdata(pdev, bd); |
119 | ||
599a52d1 | 120 | bd->props.brightness = HP680_DEFAULT_INTENSITY; |
a8db3c19 | 121 | hp680bl_send_intensity(bd); |
06c6f900 AS |
122 | |
123 | return 0; | |
124 | } | |
125 | ||
a8db3c19 | 126 | static int hp680bl_remove(struct platform_device *pdev) |
06c6f900 | 127 | { |
a8db3c19 RP |
128 | struct backlight_device *bd = platform_get_drvdata(pdev); |
129 | ||
eb650d67 KE |
130 | bd->props.brightness = 0; |
131 | bd->props.power = 0; | |
a8db3c19 | 132 | hp680bl_send_intensity(bd); |
4437cd1e | 133 | |
06c6f900 AS |
134 | return 0; |
135 | } | |
136 | ||
5f27a27b | 137 | static struct platform_driver hp680bl_driver = { |
06c6f900 AS |
138 | .probe = hp680bl_probe, |
139 | .remove = hp680bl_remove, | |
5f27a27b RP |
140 | .driver = { |
141 | .name = "hp680-bl", | |
b55bb78d | 142 | .pm = &hp680bl_pm_ops, |
5f27a27b | 143 | }, |
06c6f900 AS |
144 | }; |
145 | ||
5f27a27b | 146 | static struct platform_device *hp680bl_device; |
06c6f900 AS |
147 | |
148 | static int __init hp680bl_init(void) | |
149 | { | |
150 | int ret; | |
151 | ||
5f27a27b | 152 | ret = platform_driver_register(&hp680bl_driver); |
3bcdcc0e AM |
153 | if (ret) |
154 | return ret; | |
155 | hp680bl_device = platform_device_register_simple("hp680-bl", -1, | |
156 | NULL, 0); | |
157 | if (IS_ERR(hp680bl_device)) { | |
158 | platform_driver_unregister(&hp680bl_driver); | |
159 | return PTR_ERR(hp680bl_device); | |
06c6f900 | 160 | } |
3bcdcc0e | 161 | return 0; |
06c6f900 AS |
162 | } |
163 | ||
164 | static void __exit hp680bl_exit(void) | |
165 | { | |
5f27a27b | 166 | platform_device_unregister(hp680bl_device); |
ff10b074 | 167 | platform_driver_unregister(&hp680bl_driver); |
06c6f900 AS |
168 | } |
169 | ||
170 | module_init(hp680bl_init); | |
171 | module_exit(hp680bl_exit); | |
172 | ||
848dd265 | 173 | MODULE_AUTHOR("Andriy Skulysh <askulysh@gmail.com>"); |
06c6f900 AS |
174 | MODULE_DESCRIPTION("HP Jornada 680 Backlight Driver"); |
175 | MODULE_LICENSE("GPL"); |