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 | |
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')
-rw-r--r-- | drivers/macintosh/via-pmu-backlight.c | 48 | ||||
-rw-r--r-- | drivers/macintosh/via-pmu.c | 26 |
2 files changed, 40 insertions, 34 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 | } |
diff --git a/drivers/macintosh/via-pmu.c b/drivers/macintosh/via-pmu.c index 7e77ac7e3705..82ec12e0edd2 100644 --- a/drivers/macintosh/via-pmu.c +++ b/drivers/macintosh/via-pmu.c | |||
@@ -1748,8 +1748,6 @@ restore_via_state(void) | |||
1748 | out_8(&via[IER], IER_SET | SR_INT | CB1_INT); | 1748 | out_8(&via[IER], IER_SET | SR_INT | CB1_INT); |
1749 | } | 1749 | } |
1750 | 1750 | ||
1751 | extern void pmu_backlight_set_sleep(int sleep); | ||
1752 | |||
1753 | #define GRACKLE_PM (1<<7) | 1751 | #define GRACKLE_PM (1<<7) |
1754 | #define GRACKLE_DOZE (1<<5) | 1752 | #define GRACKLE_DOZE (1<<5) |
1755 | #define GRACKLE_NAP (1<<4) | 1753 | #define GRACKLE_NAP (1<<4) |
@@ -2160,11 +2158,6 @@ pmu_release(struct inode *inode, struct file *file) | |||
2160 | #if defined(CONFIG_SUSPEND) && defined(CONFIG_PPC32) | 2158 | #if defined(CONFIG_SUSPEND) && defined(CONFIG_PPC32) |
2161 | static void pmac_suspend_disable_irqs(void) | 2159 | static void pmac_suspend_disable_irqs(void) |
2162 | { | 2160 | { |
2163 | #ifdef CONFIG_PMAC_BACKLIGHT | ||
2164 | /* Tell backlight code not to muck around with the chip anymore */ | ||
2165 | pmu_backlight_set_sleep(1); | ||
2166 | #endif | ||
2167 | |||
2168 | /* Call platform functions marked "on sleep" */ | 2161 | /* Call platform functions marked "on sleep" */ |
2169 | pmac_pfunc_i2c_suspend(); | 2162 | pmac_pfunc_i2c_suspend(); |
2170 | pmac_pfunc_base_suspend(); | 2163 | pmac_pfunc_base_suspend(); |
@@ -2208,11 +2201,6 @@ static int powerbook_sleep(suspend_state_t state) | |||
2208 | 2201 | ||
2209 | mdelay(100); | 2202 | mdelay(100); |
2210 | 2203 | ||
2211 | #ifdef CONFIG_PMAC_BACKLIGHT | ||
2212 | /* Tell backlight code it can use the chip again */ | ||
2213 | pmu_backlight_set_sleep(0); | ||
2214 | #endif | ||
2215 | |||
2216 | return 0; | 2204 | return 0; |
2217 | } | 2205 | } |
2218 | 2206 | ||
@@ -2457,10 +2445,15 @@ static int pmu_sys_suspend(struct sys_device *sysdev, pm_message_t state) | |||
2457 | if (state.event != PM_EVENT_SUSPEND || pmu_sys_suspended) | 2445 | if (state.event != PM_EVENT_SUSPEND || pmu_sys_suspended) |
2458 | return 0; | 2446 | return 0; |
2459 | 2447 | ||
2460 | /* Suspend PMU event interrupts */ | 2448 | /* Suspend PMU event interrupts */\ |
2461 | pmu_suspend(); | 2449 | pmu_suspend(); |
2462 | |||
2463 | pmu_sys_suspended = 1; | 2450 | pmu_sys_suspended = 1; |
2451 | |||
2452 | #ifdef CONFIG_PMAC_BACKLIGHT | ||
2453 | /* Tell backlight code not to muck around with the chip anymore */ | ||
2454 | pmu_backlight_set_sleep(1); | ||
2455 | #endif | ||
2456 | |||
2464 | return 0; | 2457 | return 0; |
2465 | } | 2458 | } |
2466 | 2459 | ||
@@ -2475,9 +2468,12 @@ static int pmu_sys_resume(struct sys_device *sysdev) | |||
2475 | pmu_request(&req, NULL, 2, PMU_SYSTEM_READY, 2); | 2468 | pmu_request(&req, NULL, 2, PMU_SYSTEM_READY, 2); |
2476 | pmu_wait_complete(&req); | 2469 | pmu_wait_complete(&req); |
2477 | 2470 | ||
2471 | #ifdef CONFIG_PMAC_BACKLIGHT | ||
2472 | /* Tell backlight code it can use the chip again */ | ||
2473 | pmu_backlight_set_sleep(0); | ||
2474 | #endif | ||
2478 | /* Resume PMU event interrupts */ | 2475 | /* Resume PMU event interrupts */ |
2479 | pmu_resume(); | 2476 | pmu_resume(); |
2480 | |||
2481 | pmu_sys_suspended = 0; | 2477 | pmu_sys_suspended = 0; |
2482 | 2478 | ||
2483 | return 0; | 2479 | return 0; |