diff options
author | Benjamin Herrenschmidt <benh@kernel.crashing.org> | 2007-12-19 23:00:21 -0500 |
---|---|---|
committer | Paul Mackerras <paulus@samba.org> | 2007-12-21 06:14:07 -0500 |
commit | 0094f2cdcfb6f2132b2ea3b4e85e0f6899c8595b (patch) | |
tree | 4e537bbfc3bcba2e3a0d93457009052190136078 /drivers/macintosh/via-pmu-backlight.c | |
parent | 7ac5dde99eb9fefdb526973c600075b7c5703a86 (diff) |
[POWERPC] Fix for via-pmu based backlight control
This fixes a few issues with via-pmu based backlight control.
First, it fixes a sign problem with the setup of the backlight
curve since the `range' value there -can- (and will) go negative.
Then, it reworks the interaction between this and the via-pmu sleep
code to properly restore backlight on wakeup from sleep.
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'drivers/macintosh/via-pmu-backlight.c')
-rw-r--r-- | drivers/macintosh/via-pmu-backlight.c | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/drivers/macintosh/via-pmu-backlight.c b/drivers/macintosh/via-pmu-backlight.c index 7e27071746e4..741a2e3f4fc6 100644 --- a/drivers/macintosh/via-pmu-backlight.c +++ b/drivers/macintosh/via-pmu-backlight.c | |||
@@ -22,7 +22,7 @@ static u8 bl_curve[FB_BACKLIGHT_LEVELS]; | |||
22 | 22 | ||
23 | static void pmu_backlight_init_curve(u8 off, u8 min, u8 max) | 23 | static void pmu_backlight_init_curve(u8 off, u8 min, u8 max) |
24 | { | 24 | { |
25 | unsigned int i, flat, count, range = (max - min); | 25 | int i, flat, count, range = (max - min); |
26 | 26 | ||
27 | bl_curve[0] = off; | 27 | bl_curve[0] = off; |
28 | 28 | ||
@@ -68,17 +68,11 @@ static int pmu_backlight_get_level_brightness(int level) | |||
68 | return pmulevel; | 68 | return pmulevel; |
69 | } | 69 | } |
70 | 70 | ||
71 | static int pmu_backlight_update_status(struct backlight_device *bd) | 71 | static int __pmu_backlight_update_status(struct backlight_device *bd) |
72 | { | 72 | { |
73 | struct adb_request req; | 73 | struct adb_request req; |
74 | unsigned long flags; | ||
75 | int level = bd->props.brightness; | 74 | int level = bd->props.brightness; |
76 | 75 | ||
77 | spin_lock_irqsave(&pmu_backlight_lock, flags); | ||
78 | |||
79 | /* Don't update brightness when sleeping */ | ||
80 | if (sleeping) | ||
81 | goto out; | ||
82 | 76 | ||
83 | if (bd->props.power != FB_BLANK_UNBLANK || | 77 | if (bd->props.power != FB_BLANK_UNBLANK || |
84 | bd->props.fb_blank != FB_BLANK_UNBLANK) | 78 | bd->props.fb_blank != FB_BLANK_UNBLANK) |
@@ -99,12 +93,23 @@ static int pmu_backlight_update_status(struct backlight_device *bd) | |||
99 | pmu_wait_complete(&req); | 93 | pmu_wait_complete(&req); |
100 | } | 94 | } |
101 | 95 | ||
102 | out: | ||
103 | spin_unlock_irqrestore(&pmu_backlight_lock, flags); | ||
104 | |||
105 | return 0; | 96 | return 0; |
106 | } | 97 | } |
107 | 98 | ||
99 | static int pmu_backlight_update_status(struct backlight_device *bd) | ||
100 | { | ||
101 | unsigned long flags; | ||
102 | int rc = 0; | ||
103 | |||
104 | spin_lock_irqsave(&pmu_backlight_lock, flags); | ||
105 | /* Don't update brightness when sleeping */ | ||
106 | if (!sleeping) | ||
107 | rc = __pmu_backlight_update_status(bd); | ||
108 | spin_unlock_irqrestore(&pmu_backlight_lock, flags); | ||
109 | return rc; | ||
110 | } | ||
111 | |||
112 | |||
108 | static int pmu_backlight_get_brightness(struct backlight_device *bd) | 113 | static int pmu_backlight_get_brightness(struct backlight_device *bd) |
109 | { | 114 | { |
110 | return bd->props.brightness; | 115 | return bd->props.brightness; |
@@ -123,6 +128,16 @@ void pmu_backlight_set_sleep(int sleep) | |||
123 | 128 | ||
124 | spin_lock_irqsave(&pmu_backlight_lock, flags); | 129 | spin_lock_irqsave(&pmu_backlight_lock, flags); |
125 | sleeping = sleep; | 130 | sleeping = sleep; |
131 | if (pmac_backlight) { | ||
132 | if (sleep) { | ||
133 | struct adb_request req; | ||
134 | |||
135 | pmu_request(&req, NULL, 2, PMU_POWER_CTRL, | ||
136 | PMU_POW_BACKLIGHT | PMU_POW_OFF); | ||
137 | pmu_wait_complete(&req); | ||
138 | } else | ||
139 | __pmu_backlight_update_status(pmac_backlight); | ||
140 | } | ||
126 | spin_unlock_irqrestore(&pmu_backlight_lock, flags); | 141 | spin_unlock_irqrestore(&pmu_backlight_lock, flags); |
127 | } | 142 | } |
128 | #endif /* CONFIG_PM */ | 143 | #endif /* CONFIG_PM */ |
@@ -148,8 +163,8 @@ void __init pmu_backlight_init() | |||
148 | 163 | ||
149 | bd = backlight_device_register(name, NULL, NULL, &pmu_backlight_data); | 164 | bd = backlight_device_register(name, NULL, NULL, &pmu_backlight_data); |
150 | if (IS_ERR(bd)) { | 165 | if (IS_ERR(bd)) { |
151 | printk("pmubl: Backlight registration failed\n"); | 166 | printk(KERN_ERR "PMU Backlight registration failed\n"); |
152 | goto error; | 167 | return; |
153 | } | 168 | } |
154 | bd->props.max_brightness = FB_BACKLIGHT_LEVELS - 1; | 169 | bd->props.max_brightness = FB_BACKLIGHT_LEVELS - 1; |
155 | pmu_backlight_init_curve(0x7F, 0x46, 0x0E); | 170 | pmu_backlight_init_curve(0x7F, 0x46, 0x0E); |
@@ -171,10 +186,5 @@ void __init pmu_backlight_init() | |||
171 | bd->props.power = FB_BLANK_UNBLANK; | 186 | bd->props.power = FB_BLANK_UNBLANK; |
172 | backlight_update_status(bd); | 187 | backlight_update_status(bd); |
173 | 188 | ||
174 | printk("pmubl: Backlight initialized (%s)\n", name); | 189 | printk(KERN_INFO "PMU Backlight initialized (%s)\n", name); |
175 | |||
176 | return; | ||
177 | |||
178 | error: | ||
179 | return; | ||
180 | } | 190 | } |