From 28ee086d5b36aab2931f6740e409bb0fb6c65e5f Mon Sep 17 00:00:00 2001 From: Richard Purdie Date: Thu, 8 Feb 2007 22:25:09 +0000 Subject: backlight: Fix external uses of backlight internal semaphore backlight_device->sem has a very specific use as documented in the header file. The external users of this are using it for a different reason, to serialise access to the update_status() method. backlight users were supposed to implement their own internal serialisation of update_status() if needed but everyone is doing things differently and incorrectly. Therefore add a global mutex to take care of serialisation for everyone, once and for all. Locking for get_brightness remains optional since most users don't need it. Also update the lcd class in a similar way. Signed-off-by: Richard Purdie --- arch/powerpc/kernel/traps.c | 4 +--- arch/powerpc/platforms/powermac/backlight.c | 19 +++++-------------- 2 files changed, 6 insertions(+), 17 deletions(-) (limited to 'arch') diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c index dcc6f15..35ce07b 100644 --- a/arch/powerpc/kernel/traps.c +++ b/arch/powerpc/kernel/traps.c @@ -107,12 +107,10 @@ int die(const char *str, struct pt_regs *regs, long err) if (machine_is(powermac) && pmac_backlight) { struct backlight_properties *props; - down(&pmac_backlight->sem); props = pmac_backlight->props; props->brightness = props->max_brightness; props->power = FB_BLANK_UNBLANK; - props->update_status(pmac_backlight); - up(&pmac_backlight->sem); + backlight_update_status(pmac_backlight); } mutex_unlock(&pmac_backlight_mutex); #endif diff --git a/arch/powerpc/platforms/powermac/backlight.c b/arch/powerpc/platforms/powermac/backlight.c index c3a8941..1be358c 100644 --- a/arch/powerpc/platforms/powermac/backlight.c +++ b/arch/powerpc/platforms/powermac/backlight.c @@ -37,7 +37,9 @@ static int pmac_backlight_set_legacy_queued; */ static atomic_t kernel_backlight_disabled = ATOMIC_INIT(0); -/* Protect the pmac_backlight variable */ +/* Protect the pmac_backlight variable below. + You should hold this lock when using the pmac_backlight pointer to + prevent its potential removal. */ DEFINE_MUTEX(pmac_backlight_mutex); /* Main backlight storage @@ -49,9 +51,6 @@ DEFINE_MUTEX(pmac_backlight_mutex); * internal display, it doesn't matter. Other backlight drivers can be used * independently. * - * Lock ordering: - * pmac_backlight_mutex (global, main backlight) - * pmac_backlight->sem (backlight class) */ struct backlight_device *pmac_backlight; @@ -104,7 +103,6 @@ static void pmac_backlight_key_worker(struct work_struct *work) struct backlight_properties *props; int brightness; - down(&pmac_backlight->sem); props = pmac_backlight->props; brightness = props->brightness + @@ -117,9 +115,7 @@ static void pmac_backlight_key_worker(struct work_struct *work) brightness = props->max_brightness; props->brightness = brightness; - props->update_status(pmac_backlight); - - up(&pmac_backlight->sem); + backlight_update_status(pmac_backlight); } mutex_unlock(&pmac_backlight_mutex); } @@ -145,7 +141,6 @@ static int __pmac_backlight_set_legacy_brightness(int brightness) if (pmac_backlight) { struct backlight_properties *props; - down(&pmac_backlight->sem); props = pmac_backlight->props; props->brightness = brightness * (props->max_brightness + 1) / @@ -156,8 +151,7 @@ static int __pmac_backlight_set_legacy_brightness(int brightness) else if (props->brightness < 0) props->brightness = 0; - props->update_status(pmac_backlight); - up(&pmac_backlight->sem); + backlight_update_status(pmac_backlight); error = 0; } @@ -196,14 +190,11 @@ int pmac_backlight_get_legacy_brightness() if (pmac_backlight) { struct backlight_properties *props; - down(&pmac_backlight->sem); props = pmac_backlight->props; result = props->brightness * (OLD_BACKLIGHT_MAX + 1) / (props->max_brightness + 1); - - up(&pmac_backlight->sem); } mutex_unlock(&pmac_backlight_mutex); -- cgit v1.1 From 599a52d12629394236d785615808845823875868 Mon Sep 17 00:00:00 2001 From: Richard Purdie Date: Sat, 10 Feb 2007 23:07:48 +0000 Subject: backlight: Separate backlight properties from backlight ops pointers Per device data such as brightness belongs to the indivdual device and should therefore be separate from the the backlight operation function pointers. This patch splits the two types of data and allows simplifcation of some code. Signed-off-by: Richard Purdie --- arch/powerpc/kernel/traps.c | 2 +- arch/powerpc/platforms/powermac/backlight.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'arch') diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c index 35ce07b..17724fb 100644 --- a/arch/powerpc/kernel/traps.c +++ b/arch/powerpc/kernel/traps.c @@ -107,7 +107,7 @@ int die(const char *str, struct pt_regs *regs, long err) if (machine_is(powermac) && pmac_backlight) { struct backlight_properties *props; - props = pmac_backlight->props; + props = &pmac_backlight->props; props->brightness = props->max_brightness; props->power = FB_BLANK_UNBLANK; backlight_update_status(pmac_backlight); diff --git a/arch/powerpc/platforms/powermac/backlight.c b/arch/powerpc/platforms/powermac/backlight.c index 1be358c..de7440e 100644 --- a/arch/powerpc/platforms/powermac/backlight.c +++ b/arch/powerpc/platforms/powermac/backlight.c @@ -44,7 +44,7 @@ DEFINE_MUTEX(pmac_backlight_mutex); /* Main backlight storage * - * Backlight drivers in this variable are required to have the "props" + * Backlight drivers in this variable are required to have the "ops" * attribute set and to have an update_status function. * * We can only store one backlight here, but since Apple laptops have only one @@ -103,7 +103,7 @@ static void pmac_backlight_key_worker(struct work_struct *work) struct backlight_properties *props; int brightness; - props = pmac_backlight->props; + props = &pmac_backlight->props; brightness = props->brightness + ((pmac_backlight_key_queued?-1:1) * @@ -141,7 +141,7 @@ static int __pmac_backlight_set_legacy_brightness(int brightness) if (pmac_backlight) { struct backlight_properties *props; - props = pmac_backlight->props; + props = &pmac_backlight->props; props->brightness = brightness * (props->max_brightness + 1) / (OLD_BACKLIGHT_MAX + 1); @@ -190,7 +190,7 @@ int pmac_backlight_get_legacy_brightness() if (pmac_backlight) { struct backlight_properties *props; - props = pmac_backlight->props; + props = &pmac_backlight->props; result = props->brightness * (OLD_BACKLIGHT_MAX + 1) / -- cgit v1.1