Commit 0094f2cd authored by Benjamin Herrenschmidt's avatar Benjamin Herrenschmidt Committed by Paul Mackerras

[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: default avatarBenjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: default avatarPaul Mackerras <paulus@samba.org>
parent 7ac5dde9
...@@ -22,7 +22,7 @@ static u8 bl_curve[FB_BACKLIGHT_LEVELS]; ...@@ -22,7 +22,7 @@ static u8 bl_curve[FB_BACKLIGHT_LEVELS];
static void pmu_backlight_init_curve(u8 off, u8 min, u8 max) static void pmu_backlight_init_curve(u8 off, u8 min, u8 max)
{ {
unsigned int i, flat, count, range = (max - min); int i, flat, count, range = (max - min);
bl_curve[0] = off; bl_curve[0] = off;
...@@ -68,17 +68,11 @@ static int pmu_backlight_get_level_brightness(int level) ...@@ -68,17 +68,11 @@ static int pmu_backlight_get_level_brightness(int level)
return pmulevel; return pmulevel;
} }
static int pmu_backlight_update_status(struct backlight_device *bd) static int __pmu_backlight_update_status(struct backlight_device *bd)
{ {
struct adb_request req; struct adb_request req;
unsigned long flags;
int level = bd->props.brightness; int level = bd->props.brightness;
spin_lock_irqsave(&pmu_backlight_lock, flags);
/* Don't update brightness when sleeping */
if (sleeping)
goto out;
if (bd->props.power != FB_BLANK_UNBLANK || if (bd->props.power != FB_BLANK_UNBLANK ||
bd->props.fb_blank != FB_BLANK_UNBLANK) bd->props.fb_blank != FB_BLANK_UNBLANK)
...@@ -99,12 +93,23 @@ static int pmu_backlight_update_status(struct backlight_device *bd) ...@@ -99,12 +93,23 @@ static int pmu_backlight_update_status(struct backlight_device *bd)
pmu_wait_complete(&req); pmu_wait_complete(&req);
} }
out:
spin_unlock_irqrestore(&pmu_backlight_lock, flags);
return 0; return 0;
} }
static int pmu_backlight_update_status(struct backlight_device *bd)
{
unsigned long flags;
int rc = 0;
spin_lock_irqsave(&pmu_backlight_lock, flags);
/* Don't update brightness when sleeping */
if (!sleeping)
rc = __pmu_backlight_update_status(bd);
spin_unlock_irqrestore(&pmu_backlight_lock, flags);
return rc;
}
static int pmu_backlight_get_brightness(struct backlight_device *bd) static int pmu_backlight_get_brightness(struct backlight_device *bd)
{ {
return bd->props.brightness; return bd->props.brightness;
...@@ -123,6 +128,16 @@ void pmu_backlight_set_sleep(int sleep) ...@@ -123,6 +128,16 @@ void pmu_backlight_set_sleep(int sleep)
spin_lock_irqsave(&pmu_backlight_lock, flags); spin_lock_irqsave(&pmu_backlight_lock, flags);
sleeping = sleep; sleeping = sleep;
if (pmac_backlight) {
if (sleep) {
struct adb_request req;
pmu_request(&req, NULL, 2, PMU_POWER_CTRL,
PMU_POW_BACKLIGHT | PMU_POW_OFF);
pmu_wait_complete(&req);
} else
__pmu_backlight_update_status(pmac_backlight);
}
spin_unlock_irqrestore(&pmu_backlight_lock, flags); spin_unlock_irqrestore(&pmu_backlight_lock, flags);
} }
#endif /* CONFIG_PM */ #endif /* CONFIG_PM */
...@@ -148,8 +163,8 @@ void __init pmu_backlight_init() ...@@ -148,8 +163,8 @@ void __init pmu_backlight_init()
bd = backlight_device_register(name, NULL, NULL, &pmu_backlight_data); bd = backlight_device_register(name, NULL, NULL, &pmu_backlight_data);
if (IS_ERR(bd)) { if (IS_ERR(bd)) {
printk("pmubl: Backlight registration failed\n"); printk(KERN_ERR "PMU Backlight registration failed\n");
goto error; return;
} }
bd->props.max_brightness = FB_BACKLIGHT_LEVELS - 1; bd->props.max_brightness = FB_BACKLIGHT_LEVELS - 1;
pmu_backlight_init_curve(0x7F, 0x46, 0x0E); pmu_backlight_init_curve(0x7F, 0x46, 0x0E);
...@@ -171,10 +186,5 @@ void __init pmu_backlight_init() ...@@ -171,10 +186,5 @@ void __init pmu_backlight_init()
bd->props.power = FB_BLANK_UNBLANK; bd->props.power = FB_BLANK_UNBLANK;
backlight_update_status(bd); backlight_update_status(bd);
printk("pmubl: Backlight initialized (%s)\n", name); printk(KERN_INFO "PMU Backlight initialized (%s)\n", name);
return;
error:
return;
} }
...@@ -1748,8 +1748,6 @@ restore_via_state(void) ...@@ -1748,8 +1748,6 @@ restore_via_state(void)
out_8(&via[IER], IER_SET | SR_INT | CB1_INT); out_8(&via[IER], IER_SET | SR_INT | CB1_INT);
} }
extern void pmu_backlight_set_sleep(int sleep);
#define GRACKLE_PM (1<<7) #define GRACKLE_PM (1<<7)
#define GRACKLE_DOZE (1<<5) #define GRACKLE_DOZE (1<<5)
#define GRACKLE_NAP (1<<4) #define GRACKLE_NAP (1<<4)
...@@ -2160,11 +2158,6 @@ pmu_release(struct inode *inode, struct file *file) ...@@ -2160,11 +2158,6 @@ pmu_release(struct inode *inode, struct file *file)
#if defined(CONFIG_SUSPEND) && defined(CONFIG_PPC32) #if defined(CONFIG_SUSPEND) && defined(CONFIG_PPC32)
static void pmac_suspend_disable_irqs(void) static void pmac_suspend_disable_irqs(void)
{ {
#ifdef CONFIG_PMAC_BACKLIGHT
/* Tell backlight code not to muck around with the chip anymore */
pmu_backlight_set_sleep(1);
#endif
/* Call platform functions marked "on sleep" */ /* Call platform functions marked "on sleep" */
pmac_pfunc_i2c_suspend(); pmac_pfunc_i2c_suspend();
pmac_pfunc_base_suspend(); pmac_pfunc_base_suspend();
...@@ -2208,11 +2201,6 @@ static int powerbook_sleep(suspend_state_t state) ...@@ -2208,11 +2201,6 @@ static int powerbook_sleep(suspend_state_t state)
mdelay(100); mdelay(100);
#ifdef CONFIG_PMAC_BACKLIGHT
/* Tell backlight code it can use the chip again */
pmu_backlight_set_sleep(0);
#endif
return 0; return 0;
} }
...@@ -2457,10 +2445,15 @@ static int pmu_sys_suspend(struct sys_device *sysdev, pm_message_t state) ...@@ -2457,10 +2445,15 @@ static int pmu_sys_suspend(struct sys_device *sysdev, pm_message_t state)
if (state.event != PM_EVENT_SUSPEND || pmu_sys_suspended) if (state.event != PM_EVENT_SUSPEND || pmu_sys_suspended)
return 0; return 0;
/* Suspend PMU event interrupts */ /* Suspend PMU event interrupts */\
pmu_suspend(); pmu_suspend();
pmu_sys_suspended = 1; pmu_sys_suspended = 1;
#ifdef CONFIG_PMAC_BACKLIGHT
/* Tell backlight code not to muck around with the chip anymore */
pmu_backlight_set_sleep(1);
#endif
return 0; return 0;
} }
...@@ -2475,9 +2468,12 @@ static int pmu_sys_resume(struct sys_device *sysdev) ...@@ -2475,9 +2468,12 @@ static int pmu_sys_resume(struct sys_device *sysdev)
pmu_request(&req, NULL, 2, PMU_SYSTEM_READY, 2); pmu_request(&req, NULL, 2, PMU_SYSTEM_READY, 2);
pmu_wait_complete(&req); pmu_wait_complete(&req);
#ifdef CONFIG_PMAC_BACKLIGHT
/* Tell backlight code it can use the chip again */
pmu_backlight_set_sleep(0);
#endif
/* Resume PMU event interrupts */ /* Resume PMU event interrupts */
pmu_resume(); pmu_resume();
pmu_sys_suspended = 0; pmu_sys_suspended = 0;
return 0; return 0;
......
...@@ -159,6 +159,8 @@ extern void pmu_unlock(void); ...@@ -159,6 +159,8 @@ extern void pmu_unlock(void);
extern int pmu_present(void); extern int pmu_present(void);
extern int pmu_get_model(void); extern int pmu_get_model(void);
extern void pmu_backlight_set_sleep(int sleep);
#define PMU_MAX_BATTERIES 2 #define PMU_MAX_BATTERIES 2
/* values for pmu_power_flags */ /* values for pmu_power_flags */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment