powermac: Combined fixes for backlight code
Subsystems (3)
Hello Andrew
Sorry, I already had two other patches earlier today. Now Michael Buesch pointed out that I should have used inline's instead of #define. Thus I decided to combine all the patches and ask you to ignore the other ones. The subjects were "Locking fixes for powermac backlight infrastructure" and "powermac: defer work in backlight key press (and export fixes)".
Here's the description for the combined patch:
This patch fixes several problems:
- pmac_backlight_key() is called under interrupt context, and therefore can't use mutexes or semaphores, so defer the backlight level for later, as it's not critical (original code by Aristeu S. Rozanski F. <[email protected]>).
- Add exports for functions that might be called from modules
- Fix Kconfig depdencies on PMAC_BACKLIGHT.
- Fix locking issues on calls from inside the driver (reported by Aristeu S. Rozanski F., too)
- Fix wrong calculation of backlight values in some of the drivers
- Replace pmac_backlight_key_up/down by inline functions
---
arch/powerpc/platforms/powermac/backlight.c +22 -9
@@ -15,6 +15,15 @@#define OLD_BACKLIGHT_MAX 15 +static void pmac_backlight_key_worker (void *data); +static DECLARE_WORK(pmac_backlight_key_work, pmac_backlight_key_worker, NULL); + +/* Although this variable is used in interrupt context, it makes no sense to +* protect it. No user is able to produce enough key events per second and +* notice the errors that might happen. +*/ +static int pmac_backlight_key_queued; +/* Protect the pmac_backlight variable */ DEFINE_MUTEX (pmac_backlight_mutex);
@@ -71,7 +80,7 @@ int pmac_backlight_curve_lookup(struct freturn level; } -static void pmac_backlight_key (int direction) +static void pmac_backlight_key_worker (void *data) {mutex_lock (&pmac_backlight_mutex);if (pmac_backlight) {
@@ -82,7 +91,8 @@ static void pmac_backlight_key(int direc props = pmac_backlight->props; brightness = props->brightness + - ((direction?-1 :1 ) * (props->max_brightness /15 )); + ((pmac_backlight_key_queued?-1 :1 ) * + (props->max_brightness /15 ));if (brightness <0 ) brightness =0 ;
@@ -97,14 +107,13 @@ static void pmac_backlight_key(int direcmutex_unlock (&pmac_backlight_mutex); } -void pmac_backlight_key_up () +void pmac_backlight_key (int direction) { -pmac_backlight_key (0 ); -} - -void pmac_backlight_key_down () -{ -pmac_backlight_key (1 ); +/* we can receive multiple interrupts here, but the scheduled work +* will run only once, with the last value +*/ + pmac_backlight_key_queued = direction; +schedule_work (&pmac_backlight_key_work); }int pmac_backlight_set_legacy_brightness (int brightness)
@@ -157,3 +166,7 @@ int pmac_backlight_get_legacy_brightnessreturn result; } + +EXPORT_SYMBOL_GPL (pmac_backlight); +EXPORT_SYMBOL_GPL (pmac_backlight_mutex); +EXPORT_SYMBOL_GPL (pmac_has_backlight_type);
drivers/macintosh/Kconfig +4 -1
@@ -113,7 +113,10 @@ config PMAC_MEDIABAY config PMAC_BACKLIGHT bool "Backlight control for LCD screens" - depends on ADB_PMU && (BROKEN || !PPC64) + depends on ADB_PMU && FB = y && (BROKEN || !PPC64) + select FB_BACKLIGHT + select BACKLIGHT_CLASS_DEVICE + select BACKLIGHT_LCD_SUPPORT help Say Y here to enable Macintosh specific extensions of the generic backlight code. With this enabled, the brightness keys on older
drivers/video/aty/aty128fb.c +35 -31
127 lines not on this page · raw message
drivers/video/aty/atyfb_base.c +30 -23
96 lines not on this page · raw message
drivers/video/chipsfb.c +1 -2
@@ -150,12 +150,11 @@ static int chipsfb_blank(int blank, strumutex_lock (&pmac_backlight_mutex);if (pmac_backlight) { -down (&pmac_backlight->sem); -/* used to disable backlight only for blank > 1, but it seems * useful at blank = 1 too (saves battery, extends backlight * life) */ +down (&pmac_backlight->sem);if (blank) pmac_backlight->props->power =FB_BLANK_POWERDOWN ;else
drivers/video/nvidia/nv_backlight.c +28 -4
@@ -26,9 +26,11 @@*/ #define MIN_LEVEL 0x158#define MAX_LEVEL 0x534 +#define LEVEL_STEP ((MAX_LEVEL - MIN_LEVEL) / FB_BACKLIGHT_MAX)static struct backlight_properties nvidia_bl_data; +/* Call with fb_info->bl_mutex held */ static int nvidia_bl_get_level_brightness (struct nvidia_par *par,int level) {
@@ -36,9 +38,7 @@ static int nvidia_bl_get_level_brightnesint nlevel;/* Get and convert the value */ -mutex_lock (&info->bl_mutex); - nlevel = info->bl_curve[level] *FB_BACKLIGHT_MAX /MAX_LEVEL ; -mutex_unlock (&info->bl_mutex); + nlevel =MIN_LEVEL + info->bl_curve[level] *LEVEL_STEP ;if (nlevel <0 ) nlevel =0 ;
@@ -50,7 +50,8 @@ static int nvidia_bl_get_level_brightnesreturn nlevel; } -static int nvidia_bl_update_status (struct backlight_device *bd) +/* Call with fb_info->bl_mutex held */ +static int __nvidia_bl_update_status (struct backlight_device *bd) {struct nvidia_par *par =class_get_devdata (&bd->class_dev);u32 tmp_pcrt, tmp_pmc, fpcontrol;
@@ -84,6 +85,19 @@ static int nvidia_bl_update_status(strucreturn 0 ; } +static int nvidia_bl_update_status (struct backlight_device *bd) +{ +struct nvidia_par *par =class_get_devdata (&bd->class_dev); +struct fb_info *info =pci_get_drvdata (par->pci_dev); +int ret; + +mutex_lock (&info->bl_mutex); + ret =__nvidia_bl_update_status (bd); +mutex_unlock (&info->bl_mutex); + +return ret; +} +static int nvidia_bl_get_brightness (struct backlight_device *bd) {return bd->props->brightness;
@@ -96,6 +110,16 @@ static struct backlight_properties nvidi .max_brightness = (FB_BACKLIGHT_LEVELS - 1), }; +void nvidia_bl_set_power (struct fb_info *info,int power) +{ +mutex_lock (&info->bl_mutex); +up (&info->bl_dev->sem); + info->bl_dev->props->power = power; +__nvidia_bl_update_status (info->bl_dev); +down (&info->bl_dev->sem); +mutex_unlock (&info->bl_mutex); +} +void nvidia_bl_init (struct nvidia_par *par) {struct fb_info *info =pci_get_drvdata (par->pci_dev);
drivers/video/nvidia/nvidia.c +1 -10
@@ -933,16 +933,7 @@ static int nvidiafb_blank(int blank, strNVWriteSeq (par,0x01 , tmp);NVWriteCrtc (par,0x1a , vesa); -#ifdef CONFIG_FB_NVIDIA_BACKLIGHT -mutex_lock (&info->bl_mutex); -if (info->bl_dev) { -down (&info->bl_dev->sem); - info->bl_dev->props->power = blank; - info->bl_dev->props->update_status (info->bl_dev); -up (&info->bl_dev->sem); - } -mutex_unlock (&info->bl_mutex); -#endif +nvidia_bl_set_power (info, blank);NVTRACE_LEAVE ();
drivers/video/nvidia/nv_proto.h +2 -0
@@ -68,9 +68,11 @@ extern u8 byte_rev[256];#ifdef CONFIG_FB_NVIDIA_BACKLIGHT extern void nvidia_bl_init (struct nvidia_par *par);extern void nvidia_bl_exit (struct nvidia_par *par); +extern void nvidia_bl_set_power (struct fb_info *info,int power);#else static inline void nvidia_bl_init (struct nvidia_par *par) {}static inline void nvidia_bl_exit (struct nvidia_par *par) {} +static inline void nvidia_bl_set_power (struct fb_info *info,int power) {}#endif #endif /* __NV_PROTO_H__ */
drivers/video/riva/fbdev.c +30 -14
89 lines not on this page · raw message
include/asm-powerpc/backlight.h +3 -3
@@ -16,13 +16,13 @@extern struct backlight_device *pmac_backlight;extern struct mutex pmac_backlight_mutex; -extern void pmac_backlight_calc_curve (struct fb_info *);extern int pmac_backlight_curve_lookup (struct fb_info *info,int value);extern int pmac_has_backlight_type (const char *type); -extern void pmac_backlight_key_up (void ); -extern void pmac_backlight_key_down (void ); +extern void pmac_backlight_key (int direction); +static inline void pmac_backlight_key_up () {pmac_backlight_key (0 ); } +static inline void pmac_backlight_key_down () {pmac_backlight_key (1 ); }extern int pmac_backlight_set_legacy_brightness (int brightness);extern int pmac_backlight_get_legacy_brightness (void );