Index: apps/settings.c
===================================================================
--- apps/settings.c  (Revision 19818)
+++ apps/settings.c  (Arbeitskopie)
@@ -773,9 +773,8 @@
 #if CONFIG_CHARGING
     backlight_set_timeout_plugged(global_settings.backlight_timeout_plugged);
 #endif
-#if (defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)) \
-        || defined(USE_BACKLIGHT_SW_FADING) \
-        || defined(USE_BACKLIGHT_CUSTOM_FADING_BOOL)
+#if    defined(HAVE_BACKLIGHT_FADING_INT_SETTING) \
+    || defined(HAVE_BACKLIGHT_FADING_BOOL_SETTING)
     backlight_set_fade_in(global_settings.backlight_fade_in);
     backlight_set_fade_out(global_settings.backlight_fade_out);
 #endif
Index: apps/settings.h
===================================================================
--- apps/settings.h  (Revision 19818)
+++ apps/settings.h  (Arbeitskopie)
@@ -681,11 +681,10 @@
     int lcd_sleep_after_backlight_off; /* when to put lcd to sleep after backlight
                                           has turned off */
 #endif
-#if defined(HAVE_BACKLIGHT_PWM_FADING)
+#if defined(HAVE_BACKLIGHT_FADING_INT_SETTING)
     int backlight_fade_in;  /* backlight fade in timing: 0..3 */
     int backlight_fade_out; /* backlight fade in timing: 0..7 */
-#elif defined(USE_BACKLIGHT_SW_FADING) \
-    || defined(USE_BACKLIGHT_CUSTOM_FADING_BOOL)
+#elif defined(HAVE_BACKLIGHT_FADING_BOOL_SETTING)
     bool backlight_fade_in;
     bool backlight_fade_out;
 #endif
Index: apps/menus/display_menu.c
===================================================================
--- apps/menus/display_menu.c  (Revision 19818)
+++ apps/menus/display_menu.c  (Arbeitskopie)
@@ -91,9 +91,8 @@
                 &global_settings.backlight_on_button_hold, NULL);
 #endif
 MENUITEM_SETTING(caption_backlight, &global_settings.caption_backlight, NULL);
-#if (defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)) || \
-        defined(USE_BACKLIGHT_SW_FADING) || \
-        defined(USE_BACKLIGHT_CUSTOM_FADING_BOOL)
+#if    defined(HAVE_BACKLIGHT_FADING_INT_SETTING) \
+    || defined(HAVE_BACKLIGHT_FADING_BOOL_SETTING)
 MENUITEM_SETTING(backlight_fade_in, &global_settings.backlight_fade_in, NULL);
 MENUITEM_SETTING(backlight_fade_out, &global_settings.backlight_fade_out, NULL);
 #endif
@@ -132,9 +131,8 @@
             ,&backlight_on_button_hold
 # endif
             ,&caption_backlight
-#if (defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)) || \
-        defined(USE_BACKLIGHT_SW_FADING) || \
-        defined(USE_BACKLIGHT_CUSTOM_FADING_BOOL)
+#if    defined(HAVE_BACKLIGHT_FADING_INT_SETTING) \
+    || defined(HAVE_BACKLIGHT_FADING_BOOL_SETTING)
             ,&backlight_fade_in, &backlight_fade_out
 #endif
             ,&bl_filter_first_keypress
Index: apps/settings_list.c
===================================================================
--- apps/settings_list.c  (Revision 19818)
+++ apps/settings_list.c  (Arbeitskopie)
@@ -671,15 +671,14 @@
     OFFON_SETTING(0, remote_caption_backlight, LANG_CAPTION_BACKLIGHT,
                   false, "remote caption backlight", NULL),
 #endif
-#endif /* HAVE_BACKLIGHT */
 #ifdef HAVE_BACKLIGHT_BRIGHTNESS
     INT_SETTING(F_NO_WRAP, brightness, LANG_BRIGHTNESS,
                 DEFAULT_BRIGHTNESS_SETTING, "brightness",UNIT_INT,
                 MIN_BRIGHTNESS_SETTING, MAX_BRIGHTNESS_SETTING, 1,
                 NULL, NULL, backlight_set_brightness),
 #endif
-#if defined(HAVE_BACKLIGHT_PWM_FADING)  && !defined(SIMULATOR)
     /* backlight fading */
+#if defined(HAVE_BACKLIGHT_FADING_INT_SETTING)
     TABLE_SETTING(F_ALLOW_ARBITRARY_VALS, backlight_fade_in,
                   LANG_BACKLIGHT_FADE_IN, 300, "backlight fade in", "off",
                   UNIT_MS, formatter_unit_0_is_off, getlang_unit_0_is_off,
@@ -689,13 +688,13 @@
                   UNIT_MS, formatter_unit_0_is_off, getlang_unit_0_is_off,
                   backlight_set_fade_out, 10,
                   0,100,200,300,500,1000,2000,3000,5000,10000),
-#elif defined(USE_BACKLIGHT_SW_FADING) \
-    || defined(USE_BACKLIGHT_CUSTOM_FADING_BOOL)
+#elif defined(HAVE_BACKLIGHT_FADING_BOOL_SETTING)
     OFFON_SETTING(0, backlight_fade_in, LANG_BACKLIGHT_FADE_IN,
                     true, "backlight fade in", backlight_set_fade_in),
     OFFON_SETTING(0, backlight_fade_out, LANG_BACKLIGHT_FADE_OUT,
                     true, "backlight fade out", backlight_set_fade_out),
 #endif
+#endif /* HAVE_BACKLIGHT */
     INT_SETTING(F_PADTITLE, scroll_speed, LANG_SCROLL_SPEED, 9,"scroll speed",
                 UNIT_INT, 0, 15, 1, NULL, NULL, lcd_scroll_speed),
     INT_SETTING(F_PADTITLE, scroll_delay, LANG_SCROLL_DELAY, 1000,
Index: apps/features.txt
===================================================================
--- apps/features.txt  (Revision 19818)
+++ apps/features.txt  (Arbeitskopie)
@@ -20,12 +20,10 @@
 backlight_brightness
 #endif

-#if defined(HAVE_BACKLIGHT_PWM_FADING)
-backlight_fade_pwm
-#elif defined(USE_BACKLIGHT_SW_FADING)
-backlight_fade_sw
-#elif defined(USE_BACKLIGHT_CUSTOM_FADING_BOOL)
-backlight_fade_custom_bool
+#if defined(HAVE_BACKLIGHT_FADING_INT_SETTING)
+backlight_fade_int
+#elif defined(HAVE_BACKLIGHT_FADING_BOOL_SETTING)
+backlight_fade_bool
 #endif

 #if BATTERY_TYPES_COUNT > 1
Index: apps/apps.make
===================================================================
--- apps/apps.make  (Revision 19818)
+++ apps/apps.make  (Arbeitskopie)
@@ -19,7 +19,8 @@
   $(SILENT)mkdir -p $(BUILDDIR)/apps
   $(call PRINTS,PP $(<F))
   $(SILENT)$(CC) $(PPCFLAGS) \
-                 -E -P -imacros "config.h" -imacros "button.h" -x c $< | \
+                 -E -P -imacros "config.h" -imacros "backlight.h" \
+         -imacros "button.h" -x c $< | \
     grep -v "^\#" | grep -v "^$$" > $(BUILDDIR)/apps/features; \
     for f in `cat $(BUILDDIR)/apps/features`; do feat="$$feat:$$f" ; done ; \
     echo "$$feat" >$(BUILDDIR)/apps/genlang-features
Index: firmware/export/config-c200.h
===================================================================
--- firmware/export/config-c200.h  (Revision 19818)
+++ firmware/export/config-c200.h  (Arbeitskopie)
@@ -111,6 +111,14 @@
 #define HAVE_BACKLIGHT
 #define HAVE_BACKLIGHT_BRIGHTNESS

+/* Main LCD backlight brightness range and defaults */
+#define MIN_BRIGHTNESS_SETTING      1
+#define MAX_BRIGHTNESS_SETTING     12
+#define DEFAULT_BRIGHTNESS_SETTING  6
+
+/* Which backlight fading type? */
+#define CONFIG_BACKLIGHT_FADING BACKLIGHT_FADING_SW_SETTING
+
 /* define this if you have a flash memory storage */
 #define HAVE_FLASH_STORAGE

@@ -138,12 +146,6 @@
 /** Non-simulator section **/
 #ifndef SIMULATOR

-/* define this if the backlight thread is used for fade, not for sim, needs
- * HAVE_BACKLIGHT_BRIGHTNESS */
-#ifndef BOOTLOADER
-#define USE_BACKLIGHT_SW_FADING
-#endif
-
 /* Define this if you have a PortalPlayer PP5024 */
 #define CONFIG_CPU PP5022

@@ -203,13 +205,6 @@

 #endif /* SIMULATOR */

-/** Port-specific settings **/
-
-/* Main LCD backlight brightness range and defaults */
-#define MIN_BRIGHTNESS_SETTING      1
-#define MAX_BRIGHTNESS_SETTING     12
-#define DEFAULT_BRIGHTNESS_SETTING  6
-
 /* Default recording levels */
 #define DEFAULT_REC_MIC_GAIN    23
 #define DEFAULT_REC_LEFT_GAIN   23
Index: firmware/export/config-fuze.h
===================================================================
--- firmware/export/config-fuze.h  (Revision 19818)
+++ firmware/export/config-fuze.h  (Arbeitskopie)
@@ -106,6 +106,14 @@
 #define HAVE_BACKLIGHT
 #define HAVE_BACKLIGHT_BRIGHTNESS

+/* Main LCD backlight brightness range and defaults */
+#define MIN_BRIGHTNESS_SETTING      1
+#define MAX_BRIGHTNESS_SETTING     12
+#define DEFAULT_BRIGHTNESS_SETTING  6
+
+/* Which backlight fading type? */
+#define CONFIG_BACKLIGHT_FADING BACKLIGHT_FADING_SW_SETTING
+
 /* define this if the unit uses a scrollwheel for navigation */
 #define HAVE_SCROLLWHEEL
 /* define from which rotation speed [degree/sec] on the acceleration starts */
@@ -134,12 +142,6 @@
 /** Non-simulator section **/
 #ifndef SIMULATOR

-/* define this if the backlight thread is used for fade, not for sim, needs
- * HAVE_BACKLIGHT_BRIGHTNESS */
-#ifndef BOOTLOADER
-#define USE_BACKLIGHT_SW_FADING
-#endif
-
 /* Define this if you have an AMS AS3525*/
 #define CONFIG_CPU AS3525

@@ -195,13 +197,6 @@

 #endif /* SIMULATOR */

-/** Port-specific settings **/
-
-/* Main LCD backlight brightness range and defaults */
-#define MIN_BRIGHTNESS_SETTING      1
-#define MAX_BRIGHTNESS_SETTING     12
-#define DEFAULT_BRIGHTNESS_SETTING  6
-
 /* Default recording levels */
 #define DEFAULT_REC_MIC_GAIN    23
 #define DEFAULT_REC_LEFT_GAIN   23
Index: firmware/export/config-e200v2.h
===================================================================
--- firmware/export/config-e200v2.h  (Revision 19818)
+++ firmware/export/config-e200v2.h  (Arbeitskopie)
@@ -106,6 +106,14 @@
 #define HAVE_BACKLIGHT
 #define HAVE_BACKLIGHT_BRIGHTNESS

+/* Main LCD backlight brightness range and defaults */
+#define MIN_BRIGHTNESS_SETTING      1
+#define MAX_BRIGHTNESS_SETTING     12
+#define DEFAULT_BRIGHTNESS_SETTING  6
+
+/* Which backlight fading type? */
+#define CONFIG_BACKLIGHT_FADING BACKLIGHT_FADING_SW_SETTING
+
 /* define this if the unit uses a scrollwheel for navigation */
 #define HAVE_SCROLLWHEEL
 /* define from which rotation speed [degree/sec] on the acceleration starts */
@@ -134,12 +142,6 @@
 /** Non-simulator section **/
 #ifndef SIMULATOR

-/* define this if the backlight thread is used for fade, not for sim, needs
- * HAVE_BACKLIGHT_BRIGHTNESS */
-#ifndef BOOTLOADER
-#define USE_BACKLIGHT_SW_FADING
-#endif
-
 /* Define this if you have an AMS AS3525*/
 #define CONFIG_CPU AS3525

@@ -195,13 +197,6 @@

 #endif /* SIMULATOR */

-/** Port-specific settings **/
-
-/* Main LCD backlight brightness range and defaults */
-#define MIN_BRIGHTNESS_SETTING      1
-#define MAX_BRIGHTNESS_SETTING     12
-#define DEFAULT_BRIGHTNESS_SETTING  6
-
 /* Default recording levels */
 #define DEFAULT_REC_MIC_GAIN    23
 #define DEFAULT_REC_LEFT_GAIN   23
Index: firmware/export/config-mrobe100.h
===================================================================
--- firmware/export/config-mrobe100.h  (Revision 19818)
+++ firmware/export/config-mrobe100.h  (Arbeitskopie)
@@ -70,7 +70,7 @@
 #define HAVE_BACKLIGHT

 /* We can fade the backlight by using PWM */
-#define HAVE_BACKLIGHT_PWM_FADING
+#define CONFIG_BACKLIGHT_FADING BACKLIGHT_FADING_PWM

 /* Main LCD backlight brightness range and defaults */
 #define MIN_BRIGHTNESS_SETTING      1
Index: firmware/export/config-e200.h
===================================================================
--- firmware/export/config-e200.h  (Revision 19818)
+++ firmware/export/config-e200.h  (Arbeitskopie)
@@ -101,6 +101,9 @@
 #define HAVE_BACKLIGHT
 #define HAVE_BACKLIGHT_BRIGHTNESS

+/* Which backlight fading type? */
+#define CONFIG_BACKLIGHT_FADING BACKLIGHT_FADING_SW_SETTING
+
 /* define this if the unit uses a scrollwheel for navigation */
 #define HAVE_SCROLLWHEEL
 /* define from which rotation speed [degree/sec] on the acceleration starts */
@@ -135,12 +138,6 @@
 /** Non-simulator section **/
 #ifndef SIMULATOR

-/* define this if the backlight thread is used for fade, not for sim, needs
- * HAVE_BACKLIGHT_BRIGHTNESS */
-#ifndef BOOTLOADER
-#define USE_BACKLIGHT_SW_FADING
-#endif
-
 /* Define this if you have a PortalPlayer PP5024 */
 #define CONFIG_CPU PP5024

Index: firmware/export/config-ipodvideo.h
===================================================================
--- firmware/export/config-ipodvideo.h  (Revision 19818)
+++ firmware/export/config-ipodvideo.h  (Arbeitskopie)
@@ -86,13 +86,14 @@
 #define HAVE_BACKLIGHT
 #define HAVE_BACKLIGHT_BRIGHTNESS

+/* We can fade the backlight by using PWM */
+#define CONFIG_BACKLIGHT_FADING BACKLIGHT_FADING_PWM
+
 /* Main LCD backlight brightness range and defaults */
 #define MIN_BRIGHTNESS_SETTING      1
 #define MAX_BRIGHTNESS_SETTING      32
 #define DEFAULT_BRIGHTNESS_SETTING  16

-/* We can fade the backlight by using PWM */
-#define HAVE_BACKLIGHT_PWM_FADING

 /* define this if the unit uses a scrollwheel for navigation */
 #define HAVE_SCROLLWHEEL
Index: firmware/export/backlight.h
===================================================================
--- firmware/export/backlight.h  (Revision 19818)
+++ firmware/export/backlight.h  (Arbeitskopie)
@@ -23,6 +23,27 @@

 #include "config.h"

+#if !defined(SIMULATOR) && !defined(BOOTLOADER)
+
+/* decide which setting to use in, possibly overridden in target config */
+#if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_PWM)
+
+#ifndef HAVE_BACKLIGHT_FADING_INT_SETTING
+#define HAVE_BACKLIGHT_FADING_INT_SETTING
+#endif
+
+#elif  (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_SETTING) \
+    || (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG) \
+    || (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_TARGET)
+#ifndef HAVE_BACKLIGHT_FADING_BOOL_SETTING
+#define HAVE_BACKLIGHT_FADING_BOOL_SETTING
+#endif
+#endif
+
+#endif
+
+
+
 bool is_backlight_on(bool ignore_always_off);
 void backlight_on(void);
 void backlight_off(void);
@@ -34,12 +55,10 @@

 int  backlight_get_current_timeout(void);

-#if defined(HAVE_BACKLIGHT_PWM_FADING)
+#if defined(HAVE_BACKLIGHT_FADING_INT_SETTING)
 void backlight_set_fade_in(int value);
 void backlight_set_fade_out(int value);
-#endif
-#if defined(USE_BACKLIGHT_SW_FADING) \
-    || defined(USE_BACKLIGHT_CUSTOM_FADING_BOOL)
+#elif defined(HAVE_BACKLIGHT_FADING_BOOL_SETTING)
 void backlight_set_fade_in(bool value);
 void backlight_set_fade_out(bool value);
 #endif
Index: firmware/export/config-ipodmini.h
===================================================================
--- firmware/export/config-ipodmini.h  (Revision 19818)
+++ firmware/export/config-ipodmini.h  (Arbeitskopie)
@@ -101,7 +101,7 @@
 #define HAVE_BACKLIGHT

 /* We can fade the backlight by using PWM */
-#define HAVE_BACKLIGHT_PWM_FADING
+#define CONFIG_BACKLIGHT_FADING BACKLIGHT_FADING_PWM

 /* Define this if you can detect headphones */
 #define HAVE_HEADPHONE_DETECTION
Index: firmware/export/config-h120.h
===================================================================
--- firmware/export/config-h120.h  (Revision 19818)
+++ firmware/export/config-h120.h  (Arbeitskopie)
@@ -69,7 +69,7 @@
 #define HAVE_BACKLIGHT

 /* We can fade the backlight by using PWM */
-#define HAVE_BACKLIGHT_PWM_FADING
+#define CONFIG_BACKLIGHT_FADING BACKLIGHT_FADING_PWM

 /* Define this if you have a software controlled poweroff */
 #define HAVE_SW_POWEROFF
Index: firmware/export/config-c200v2.h
===================================================================
--- firmware/export/config-c200v2.h  (Revision 19818)
+++ firmware/export/config-c200v2.h  (Arbeitskopie)
@@ -136,12 +136,6 @@
 /** Non-simulator section **/
 #ifndef SIMULATOR

-/* define this if the backlight thread is used for fade, not for sim, needs
- * HAVE_BACKLIGHT_BRIGHTNESS */
-#ifndef BOOTLOADER
-#define USE_BACKLIGHT_SW_FADING
-#endif
-
 /* Define this if you have a PortalPlayer PP5024 */
 #define CONFIG_CPU AS3525

Index: firmware/export/config-ipodmini2g.h
===================================================================
--- firmware/export/config-ipodmini2g.h  (Revision 19818)
+++ firmware/export/config-ipodmini2g.h  (Arbeitskopie)
@@ -101,7 +101,7 @@
 #define HAVE_BACKLIGHT

 /* We can fade the backlight by using PWM */
-#define HAVE_BACKLIGHT_PWM_FADING
+#define CONFIG_BACKLIGHT_FADING BACKLIGHT_FADING_PWM

 /* define this if the unit uses a scrollwheel for navigation */
 #define HAVE_SCROLLWHEEL
Index: firmware/export/config.h
===================================================================
--- firmware/export/config.h  (Revision 19818)
+++ firmware/export/config.h  (Arbeitskopie)
@@ -113,6 +113,24 @@
 #define H300_REMOTE 2
 #define X5_REMOTE   3

+/* CONFIG_BACKLIGHT_FADING */
+/* No fading capabilities at all (yet) */
+#define BACKLIGHT_NO_FADING         0x0
+/* Backlight fading is controlled using a hardware PWM mechanism */
+#define BACKLIGHT_FADING_PWM        0x1
+/* Backlight is controlled using a software implementation
+ * BACKLIGHT_FADING_SW_SETTING means that backlight is turned on by only setting
+ * the brightness (i.e. no real difference between backlight_on and
+ * backlight_set_brightness)
+ * BACKLIGHT_FADING_SW_SETTING means that backlight brightness is restored
+ * "in hardware", from a hardware register upon backlight_on
+ * Both types need to have minor adjustments in the software fading code */
+#define BACKLIGHT_FADING_SW_SETTING 0x2
+#define BACKLIGHT_FADING_SW_HW_REG  0x4
+/* Backlight fading is done in a target specific way
+ * for example in hardware, but not controllable*/
+#define BACKLIGHT_FADING_TARGET     0x8
+
 /* CONFIG_CHARGING */

 /* Generic types */
@@ -347,6 +365,20 @@
 /* setup basic macros from capability masks */
 #include "config_caps.h"

+/* some backlight fading specific defines */
+/* Neither backlight fade algorithm to be used on the sim or bootloader */
+
+#if defined(BOOTLOADER) || defined(SIMULATOR)
+#if defined(CONFIG_BACKLIGHT_FADING)
+#undef CONFIG_BACKLIGHT_FADING
+#endif
+#define CONFIG_BACKLIGHT_FADING BACKLIGHT_NO_FADING
+#endif
+
+#if !defined(CONFIG_BACKLIGHT_FADING)
+#define CONFIG_BACKLIGHT_FADING BACKLIGHT_NO_FADING /* 0 */
+#endif
+
 /* now set any CONFIG_ defines correctly if they are not used,
    No need to do this on CONFIG_'s which are compulsary (e.g CONFIG_CODEC ) */
 #ifndef CONFIG_TUNER
Index: firmware/export/config-ipodnano.h
===================================================================
--- firmware/export/config-ipodnano.h  (Revision 19818)
+++ firmware/export/config-ipodnano.h  (Arbeitskopie)
@@ -81,15 +81,14 @@
 /* Define this for LCD backlight available */
 #define HAVE_BACKLIGHT
 #define HAVE_BACKLIGHT_BRIGHTNESS
+/* We can fade the backlight by using PWM */
+#define CONFIG_BACKLIGHT_FADING BACKLIGHT_FADING_PWM
 
 /* Main LCD backlight brightness range and defaults */
 #define MIN_BRIGHTNESS_SETTING      1
 #define MAX_BRIGHTNESS_SETTING      32
 #define DEFAULT_BRIGHTNESS_SETTING  16
 
-/* We can fade the backlight by using PWM */
-#define HAVE_BACKLIGHT_PWM_FADING
-
 /* define this if the unit uses a scrollwheel for navigation */
 #define HAVE_SCROLLWHEEL
 /* define from which rotation speed [degree/sec] on the acceleration starts */
Index: firmware/export/config-sa9200.h
===================================================================
--- firmware/export/config-sa9200.h  (Revision 19818)
+++ firmware/export/config-sa9200.h  (Arbeitskopie)
@@ -90,6 +90,9 @@
 #define MAX_BRIGHTNESS_SETTING     12
 #define DEFAULT_BRIGHTNESS_SETTING  6
 
+/* Which backlight fading type? */
+#define CONFIG_BACKLIGHT_FADING BACKLIGHT_FADING_SW_SETTING
+
 /* define this if you have a flash memory storage */
 #define HAVE_FLASH_STORAGE
 
Index: firmware/export/config-h100.h
===================================================================
--- firmware/export/config-h100.h  (Revision 19818)
+++ firmware/export/config-h100.h  (Arbeitskopie)
@@ -74,7 +74,7 @@
 #define HAVE_BACKLIGHT
 
 /* We can fade the backlight by using PWM */
-#define HAVE_BACKLIGHT_PWM_FADING
+#define CONFIG_BACKLIGHT_FADING BACKLIGHT_FADING_PWM
 
 /* Define this if you have a software controlled poweroff */
 #define HAVE_SW_POWEROFF
Index: firmware/export/config-h300.h
===================================================================
--- firmware/export/config-h300.h  (Revision 19818)
+++ firmware/export/config-h300.h  (Arbeitskopie)
@@ -68,6 +68,8 @@
 /* Define this for LCD backlight available */
 #define HAVE_BACKLIGHT
 #define HAVE_BACKLIGHT_BRIGHTNESS
+/* Which backlight fading type? */
+#define CONFIG_BACKLIGHT_FADING BACKLIGHT_FADING_SW_HW_REG
 
 /* Define this if you have a software controlled poweroff */
 #define HAVE_SW_POWEROFF
@@ -125,12 +127,6 @@
 
 #ifndef SIMULATOR
 
-/* define this if the backlight thread is used for fade, not for sim, needs
- * HAVE_BACKLIGHT_BRIGHTNESS */
-#ifndef BOOTLOADER
-#define USE_BACKLIGHT_SW_FADING
-#endif
-
 /* Define this if your LCD can be enabled/disabled */
 #define HAVE_LCD_ENABLE
 
Index: firmware/export/config-iaudiox5.h
===================================================================
--- firmware/export/config-iaudiox5.h  (Revision 19818)
+++ firmware/export/config-iaudiox5.h  (Arbeitskopie)
@@ -90,6 +90,8 @@
 /* Define this for LCD backlight available */
 #define HAVE_BACKLIGHT
 #define HAVE_BACKLIGHT_BRIGHTNESS
+/* Which backlight fading type? */
+#define CONFIG_BACKLIGHT_FADING BACKLIGHT_FADING_SW_HW_REG
 
 /* define this if you have a disk storage, i.e. something
    that needs spinups and can cause skips when shaked */
@@ -127,12 +129,6 @@
 
 #ifndef SIMULATOR
 
-/* define this if the backlight thread is used for fade, not for sim, needs
- * HAVE_BACKLIGHT_BRIGHTNESS */
-#ifndef BOOTLOADER
-#define USE_BACKLIGHT_SW_FADING
-#endif
-
 /* Define this if your LCD can set contrast */
 #define HAVE_LCD_CONTRAST
 
Index: firmware/export/backlight-sw-fading.h
===================================================================
--- firmware/export/backlight-sw-fading.h  (Revision 19818)
+++ firmware/export/backlight-sw-fading.h  (Arbeitskopie)
@@ -22,10 +22,6 @@
 #ifndef BACKLIGHT_THREAD_FADING_H
 #define BACKLIGHT_THREAD_FADING_H
 
-#include "config.h"
-
-#ifdef USE_BACKLIGHT_SW_FADING
-
 /* delay supposed to be MAX_BRIGHTNESS_SETTING*2 rounded to the next multiple
  * of 5, however not more than 40 */
 #define _FADE_DELAY (((MAX_BRIGHTNESS_SETTING*2+4)/5)*5)
@@ -41,6 +37,5 @@
     FADING_UP,
     FADING_DOWN,
 };
-#endif /* USE_BACKLIGHT_SW_FADING */
 
 #endif /* _BACKLIGHT_THREAD_FADING_ */
Index: firmware/export/config-gigabeat-s.h
===================================================================
--- firmware/export/config-gigabeat-s.h  (Revision 19818)
+++ firmware/export/config-gigabeat-s.h  (Arbeitskopie)
@@ -117,15 +117,14 @@
 #define MAX_BRIGHTNESS_SETTING          24
 #define DEFAULT_BRIGHTNESS_SETTING      12
 
+/* Implementation-defined fading type with bool settings */
+#define CONFIG_BACKLIGHT_FADING BACKLIGHT_FADING_TARGET
 
 #define HAVE_HEADPHONE_DETECTION
 #endif /* BOOTLOADER */
 
 #ifndef SIMULATOR
 
-/* Implementation-defined fading type with bool settings */
-#define USE_BACKLIGHT_CUSTOM_FADING_BOOL
-
 /* The LCD on a Gigabeat is 240x320 - it is portrait */
 #define HAVE_PORTRAIT_LCD
 
Index: firmware/export/config-cowond2.h
===================================================================
--- firmware/export/config-cowond2.h  (Revision 19818)
+++ firmware/export/config-cowond2.h  (Arbeitskopie)
@@ -108,9 +108,10 @@
 
 /* Define this for LCD backlight available */
 #define HAVE_BACKLIGHT
-
 /* Enable LCD brightness control */
 #define HAVE_BACKLIGHT_BRIGHTNESS
+/* Which backlight fading type? */
+#define CONFIG_BACKLIGHT_FADING BACKLIGHT_FADING_SW_HW_REG
 
 /* Main LCD backlight brightness range and defaults */
 #define MIN_BRIGHTNESS_SETTING      1
@@ -129,13 +130,6 @@
 #define CONFIG_CHARGING CHARGING_SIMPLE
 
 #ifndef SIMULATOR
-
-/* define this if the backlight thread is used for fade, not for sim, needs
- * HAVE_BACKLIGHT_BRIGHTNESS */
-#ifndef BOOTLOADER
-#define USE_BACKLIGHT_SW_FADING
-#endif
-
 /* Define this if you have a TCC7801 */
 #define CONFIG_CPU TCC7801
 
Index: firmware/backlight-sw-fading.c
===================================================================
--- firmware/backlight-sw-fading.c  (Revision 19818)
+++ firmware/backlight-sw-fading.c  (Arbeitskopie)
@@ -30,7 +30,7 @@
 /* To adapt a target do:
  * - make sure _backlight_on doesn't set the brightness to something other than
  *  the previous value (lowest brightness in most cases)
- * - #define USE_BACKLIGHT_SW_FADING in config-<target>.h
+ * add proper #defines for software fading
  */

 /* can be MIN_BRIGHTNESS_SETTING-1 */
Index: firmware/backlight.c
===================================================================
--- firmware/backlight.c  (Revision 19818)
+++ firmware/backlight.c  (Arbeitskopie)
@@ -52,7 +52,8 @@
 int backlight_brightness = DEFAULT_BRIGHTNESS_SETTING;
 #endif

-#ifdef USE_BACKLIGHT_SW_FADING
+#if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_SETTING) \
+    || (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG)
 #include "backlight-sw-fading.h"
 #endif
 #ifdef SIMULATOR
@@ -230,14 +231,15 @@
 }
 #endif /* HAVE_LCD_SLEEP */

-#ifdef USE_BACKLIGHT_SW_FADING
+#if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_SETTING) \
+    || (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG)
 static int backlight_fading_type = (FADING_UP|FADING_DOWN);
 static int backlight_fading_state = NOT_FADING;
 #endif


-#if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR)
 /* backlight fading */
+#if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_PWM)
 #define BL_PWM_INTERVAL 5  /* Cycle interval in ms */
 #define BL_PWM_BITS     8
 #define BL_PWM_COUNT    (1<<BL_PWM_BITS)
@@ -410,9 +412,9 @@
     else
         bl_fade_out_step = 0;
 }
-#endif /* defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR) */

-#ifdef USE_BACKLIGHT_SW_FADING
+#elif  (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_SETTING) \
+    || (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG)

 void backlight_set_fade_out(bool value)
 {
@@ -430,7 +432,7 @@
         backlight_fading_type &= FADING_DOWN;
 }

-static void backlight_set_up_fade_up(void)
+static void backlight_setup_fade_up(void)
 {
     if (backlight_fading_type & FADING_UP)
     {
@@ -450,7 +452,7 @@
     }
 }

-static void backlight_set_up_fade_down(void)
+static void backlight_setup_fade_down(void)
 {
     if (backlight_fading_type & FADING_DOWN)
     {
@@ -461,16 +463,14 @@
         backlight_fading_state = NOT_FADING;
         _backlight_fade_update_state(MIN_BRIGHTNESS_SETTING-1);
         _backlight_off();
-    /* h300/x5/d2 go to the last known brightness level at backight_on(),which
-     * should be the lowest level to keep fading up glitch free
-     * targets which set brightness over AS3514 I2C make the backlight on only
-     * by setting the brightness, so this step would be noticeable */
-#if !defined(HAVE_AS3514)
+#if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG)
+        /* write the lowest brightness level to the hardware so that
+         * fading up is glitch free */
         _backlight_set_brightness(MIN_BRIGHTNESS_SETTING);
 #endif
     }
 }
-#endif /* USE_BACKLIGHT_SW_FADING */
+#endif /* CONFIG_BACKLIGHT_FADING */

 /* Update state of backlight according to timeout setting */
 static void backlight_update_state(void)
@@ -498,8 +498,9 @@
     if (UNLIKELY(backlight_timeout < 0))
     {
         backlight_timer = 0; /* Disable the timeout */
-#ifdef USE_BACKLIGHT_SW_FADING
-        backlight_set_up_fade_down();
+#if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_SETTING) \
+    || (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG)
+        backlight_setup_fade_down();
         /* necessary step to issue fading down when the setting is selected */
         queue_post(&backlight_queue, SYS_TIMEOUT, 0);
 #else
@@ -509,8 +510,9 @@
     else
     {
         backlight_timer = backlight_timeout;
-#if defined(USE_BACKLIGHT_SW_FADING)
-        backlight_set_up_fade_up();
+#if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_SETTING) \
+    || (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG)
+        backlight_setup_fade_up();
 #else
         _backlight_on();
 #endif
@@ -555,15 +557,13 @@

     while(1)
     {
-#if defined(USE_BACKLIGHT_SW_FADING)
+#if  (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_SETTING) \
+    || (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG)
         if (backlight_fading_state)
             queue_wait_w_tmo(&backlight_queue, &ev, FADE_DELAY);
         else
 #endif
             queue_wait(&backlight_queue, &ev);
-/*
-#endif
-*/
         switch(ev.id)
         {   /* These events must always be processed */
 #ifdef _BACKLIGHT_FADE_BOOST
@@ -643,11 +643,12 @@

             case BACKLIGHT_OFF:
                 backlight_timer = 0; /* Disable the timeout */
-#ifndef USE_BACKLIGHT_SW_FADING
+#if  (CONFIG_BACKLIGHT_FADING != BACKLIGHT_FADING_SW_SETTING) \
+    && (CONFIG_BACKLIGHT_FADING != BACKLIGHT_FADING_SW_HW_REG)
                 _backlight_off();
 #else
-                backlight_set_up_fade_down();
-#endif /* USE_BACKLIGHT_SW_FADING */
+                backlight_setup_fade_down();
+#endif /* CONFIG_BACKLIGHT_FADING */
                 break;
 #ifdef HAVE_LCD_SLEEP
             case LCD_SLEEP:
@@ -677,12 +678,13 @@
                 remote_backlight_update_state();
 #endif
                 break;
-#if defined(USE_BACKLIGHT_SW_FADING)
+#if  (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_SETTING) \
+    || (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG)
             case SYS_TIMEOUT:
                 if ((_backlight_fade_step(backlight_fading_state)))
-                    backlight_fading_state = NOT_FADING;
+                    backlight_fading_state = NOT_FADING; /* finished fading */
                 break;
-#endif /* USE_BACKLIGHT_SW_FADING */
+#endif /* CONFIG_BACKLIGHT_FADING */
         }
     } /* end while */
 }
@@ -733,11 +735,11 @@
 #ifndef SIMULATOR
     if (_backlight_init())
     {
-# ifdef HAVE_BACKLIGHT_PWM_FADING
+#if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_PWM)
         /* If backlight is already on, don't fade in. */
         bl_dim_target = BL_PWM_COUNT;
         bl_dim_fraction = (BL_PWM_COUNT<<16);
-# endif
+#endif
     }
 #endif
     /* Leave all lights as set by the bootloader here. The settings load will
@@ -922,7 +924,8 @@
 
     backlight_brightness = val;
     _backlight_set_brightness(val);
-#ifdef USE_BACKLIGHT_SW_FADING
+#if  (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_SETTING) \
+    || (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG)
     /* receive backlight brightness */
     _backlight_fade_update_state(val);
 #endif
Index: firmware/SOURCES
===================================================================
--- firmware/SOURCES  (Revision 19818)
+++ firmware/SOURCES  (Arbeitskopie)
@@ -96,9 +96,10 @@
 #endif /* LCD_REMOTE_DEPTH */
 #endif /* HAVE_REMOTE_LCD */
 
-#ifdef USE_BACKLIGHT_SW_FADING
+#if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_SETTING) \
+    || (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG)
 backlight-sw-fading.c
-#endif /* USE_BACKLIGHT_SW_FADING */
+#endif /* CONFIG_BACKLIGHT_FADING */
 
 /* Misc. */
 drivers/led.c
Index: firmware/target/arm/as3525/backlight-e200v2-fuze.c
===================================================================
--- firmware/target/arm/as3525/backlight-e200v2-fuze.c  (Revision 19818)
+++ firmware/target/arm/as3525/backlight-e200v2-fuze.c  (Arbeitskopie)
@@ -39,7 +39,9 @@
 #ifdef HAVE_LCD_ENABLE
     lcd_enable(true); /* power on lcd + visible display */
 #endif
-#ifndef USE_BACKLIGHT_SW_FADING
+#if (CONFIG_BACKLIGHT_FADING != BACKLIGHT_FADING_SW_SETTING) /* in bootloader/sim */
+    /* if we set the brightness to the settings value, then fading up
+     * is glitchy */
     ascodec_write(AS3514_DCDC15, backlight_brightness);
 #endif
 }
Index: firmware/target/arm/ipod/backlight-target.h
===================================================================
--- firmware/target/arm/ipod/backlight-target.h  (Revision 19818)
+++ firmware/target/arm/ipod/backlight-target.h  (Arbeitskopie)
@@ -50,7 +50,8 @@
 void _backlight_on(void);
 void _backlight_off(void);
 
-#elif defined HAVE_BACKLIGHT_PWM_FADING  /* Mini G1, G2 */
+/* Mini G1, G2, Video, Nano */
+#elif (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_PWM) 
 
 #define _backlight_init() true
 void _backlight_hw_on(void);
Index: firmware/target/arm/sandisk/backlight-c200_e200.c
===================================================================
--- firmware/target/arm/sandisk/backlight-c200_e200.c  (Revision 19818)
+++ firmware/target/arm/sandisk/backlight-c200_e200.c  (Arbeitskopie)
@@ -39,15 +39,16 @@
 #ifdef HAVE_LCD_ENABLE
     lcd_enable(true); /* power on lcd + visible display */
 #endif
-#ifndef USE_BACKLIGHT_SW_FADING
-    /* that part ain't useful when fading */
+#if (CONFIG_BACKLIGHT_FADING != BACKLIGHT_FADING_SW_SETTING) /* in bootloader/sim */
+    /* if we set the brightness to the settings value, then fading up
+     * is glitchy */
     _backlight_set_brightness(backlight_brightness);
 #endif
 }

 void _backlight_off(void)
 {
-    ascodec_write(AS3514_DCDC15, 0x0);
+    _backlight_set_brightness(0);
 #ifdef HAVE_LCD_ENABLE
     lcd_enable(false); /* power off visible display */
 #endif
Index: firmware/target/arm/philips/sa9200/backlight-sa9200.c
===================================================================
--- firmware/target/arm/philips/sa9200/backlight-sa9200.c  (Revision 19818)
+++ firmware/target/arm/philips/sa9200/backlight-sa9200.c  (Arbeitskopie)
@@ -39,15 +39,16 @@
 #ifdef HAVE_LCD_ENABLE
     lcd_enable(true); /* power on lcd + visible display */
 #endif
-#ifndef USE_BACKLIGHT_SW_FADING
-    /* that part ain't useful when fading */
+#if (CONFIG_BACKLIGHT_FADING != BACKLIGHT_FADING_SW_SETTING) /* in bootloader/sim */
+    /* if we set the brightness to the settings value, then fading up
+     * is glitchy */
     _backlight_set_brightness(backlight_brightness);
 #endif
 }
 
 void _backlight_off(void)
 {
-    ascodec_write(AS3514_DCDC15, 0x0);
+    _backlight_set_brightness(0);
 #ifdef HAVE_LCD_ENABLE
     lcd_enable(false); /* power off visible display */
 #endif
Index: manual/configure_rockbox/display_options.tex
===================================================================
--- manual/configure_rockbox/display_options.tex  (Revision 19818)
+++ manual/configure_rockbox/display_options.tex  (Arbeitskopie)
@@ -28,7 +28,7 @@
       beginning so that the display can be read to see song information. The
       amount of time is determined by the value of the backlight timeout
       setting, but is no less than 5 seconds.
-      \opt{backlight_fade_pwm}{
+      \opt{backlight_fade_int}{
         \item[Backlight Fade In:]
         The amount of time that the backlight will take to fade from off to on
         after a button is pressed. If set to \setting{Off} the backlight will
@@ -41,14 +41,14 @@
         fade out. Other valid values: \setting{500ms}, \setting{1s},
         \setting{2s}, \setting{3s}, \setting{4s}, \setting{5s} or \setting{10s}.
       }
-      \opt{backlight_fade_sw}{
+      \opt{backlight_fade_bool}{
         \item[Backlight Fade In:]
         This options turns on smooth backlight fading when the backlight is
-        activated. The fading time is dependent on the brightness level you
+        turning on. The fading time may dependent on the brightness level you
         have chosen. If it is turned off, the backlight will turn on immediately.
         \item[Backlight Fade Out:]
         This options turns on smooth backlight fading when the backlight is
-        deactivated. The fading time is dependent on the brightness level you
+        turning off. The fading time may dependent on the brightness level you
         have chosen. If it is turned off, the backlight will turn off immediately.
       }
       \item[First Keypress Enables Backlight Only:]