aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Herrenschmidt <benh@kernel.crashing.org>2007-12-19 23:00:21 -0500
committerPaul Mackerras <paulus@samba.org>2007-12-21 06:14:07 -0500
commit0094f2cdcfb6f2132b2ea3b4e85e0f6899c8595b (patch)
tree4e537bbfc3bcba2e3a0d93457009052190136078
parent7ac5dde99eb9fefdb526973c600075b7c5703a86 (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>
-rw-r--r--drivers/macintosh/via-pmu-backlight.c48
-rw-r--r--drivers/macintosh/via-pmu.c26
-rw-r--r--include/linux/pmu.h2
3 files changed, 42 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
23static void pmu_backlight_init_curve(u8 off, u8 min, u8 max) 23static 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
71static int pmu_backlight_update_status(struct backlight_device *bd) 71static 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
102out:
103 spin_unlock_irqrestore(&pmu_backlight_lock, flags);
104
105 return 0; 96 return 0;
106} 97}
107 98
99static 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
108static int pmu_backlight_get_brightness(struct backlight_device *bd) 113static 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
178error:
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
1751extern 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)
2161static void pmac_suspend_disable_irqs(void) 2159static 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;
diff --git a/include/linux/pmu.h b/include/linux/pmu.h
index 177ae4812b88..4c5f65392d36 100644
--- a/include/linux/pmu.h
+++ b/include/linux/pmu.h
@@ -159,6 +159,8 @@ extern void pmu_unlock(void);
159extern int pmu_present(void); 159extern int pmu_present(void);
160extern int pmu_get_model(void); 160extern int pmu_get_model(void);
161 161
162extern void pmu_backlight_set_sleep(int sleep);
163
162#define PMU_MAX_BATTERIES 2 164#define PMU_MAX_BATTERIES 2
163 165
164/* values for pmu_power_flags */ 166/* values for pmu_power_flags */