From 1616e66e553226b6882033c4f033bb4326557752 Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Thu, 4 Dec 2008 04:16:53 +0000 Subject: [PATCH] Gigabeat S: Turn off backlight LED supply after a 2-second delay and save a little power. Hardware fading required keeping supply enabled during fade out. Let fade happen at poweroff (might as well~~~). git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19322 a1c6a512-1295-4272-9138-f99709370657 --- firmware/export/config-gigabeat-s.h | 10 +++++- .../arm/imx31/gigabeat-s/backlight-imx31.c | 33 ++++++++++++++++--- .../arm/imx31/gigabeat-s/backlight-target.h | 2 ++ .../target/arm/imx31/gigabeat-s/lcd-imx31.c | 17 ++++++---- .../target/arm/imx31/gigabeat-s/power-imx31.c | 9 +++++ 5 files changed, 58 insertions(+), 13 deletions(-) diff --git a/firmware/export/config-gigabeat-s.h b/firmware/export/config-gigabeat-s.h index f0e9e92a04..72b1cb76a8 100644 --- a/firmware/export/config-gigabeat-s.h +++ b/firmware/export/config-gigabeat-s.h @@ -76,9 +76,17 @@ SAMPR_CAP_24 | SAMPR_CAP_22 | SAMPR_CAP_16 | \ SAMPR_CAP_12 | SAMPR_CAP_11 | SAMPR_CAP_8) +/* Define this if your LCD can be put to sleep. */ +#define HAVE_LCD_SLEEP +/* We don't use a setting but a fixed delay after the backlight has + * turned off */ +#define LCD_SLEEP_TIMEOUT (2*HZ) + #ifndef BOOTLOADER -/* Not for bootloader */ +#if 0 +/* Define this if your LCD can be enabled/disabled */ #define HAVE_LCD_ENABLE +#endif #define HAVE_BACKLIGHT_BRIGHTNESS diff --git a/firmware/target/arm/imx31/gigabeat-s/backlight-imx31.c b/firmware/target/arm/imx31/gigabeat-s/backlight-imx31.c index db6de3e71e..8b4459c3a9 100644 --- a/firmware/target/arm/imx31/gigabeat-s/backlight-imx31.c +++ b/firmware/target/arm/imx31/gigabeat-s/backlight-imx31.c @@ -67,7 +67,7 @@ static const struct /* Bits always combined with ramping bits */ #define MC13783_LED_CONTROL0_BITS \ - (MC13783_LEDEN | MC13783_BOOSTEN | MC13783_ABMODE_MONCH_LEDMD1234 | \ + (MC13783_BOOSTEN | MC13783_ABMODE_MONCH_LEDMD1234 | \ MC13783_ABREF_400MV) static struct mutex backlight_mutex; /* Block brightness change while @@ -83,7 +83,8 @@ bool _backlight_init(void) mutex_init(&backlight_mutex); /* Set default LED register value */ - mc13783_write(MC13783_LED_CONTROL0, MC13783_LED_CONTROL0_BITS); + mc13783_write(MC13783_LED_CONTROL0, + MC13783_LED_CONTROL0_BITS | MC13783_LEDEN); #ifdef HAVE_BACKLIGHT_BRIGHTNESS /* Our PWM and I-Level is different than retailos (but same apparent @@ -125,8 +126,13 @@ void _backlight_on(void) mutex_lock(&backlight_mutex); - /* Set/clear LEDRAMPUP bit, clear LEDRAMPDOWN bit */ - data[0] = MC13783_LED_CONTROL0_BITS; +#ifdef HAVE_LCD_SLEEP + backlight_lcd_sleep_countdown(false); /* stop counter */ +#endif + + /* Set/clear LEDRAMPUP bit, clear LEDRAMPDOWN bit, + * Ensure LED supply is on. */ + data[0] = MC13783_LED_CONTROL0_BITS | MC13783_LEDEN; if (!backlight_on_status) data[0] |= led_ramp_mask & MC13783_LEDMDRAMPUP; @@ -150,7 +156,7 @@ void _backlight_on(void) void _backlight_off(void) { - uint32_t ctrl0 = MC13783_LED_CONTROL0_BITS; + uint32_t ctrl0 = MC13783_LED_CONTROL0_BITS | MC13783_LEDEN; mutex_lock(&backlight_mutex); @@ -169,6 +175,11 @@ void _backlight_off(void) mc13783_write_masked(MC13783_LED_CONTROL2, MC13783_LEDMDDCw(0), MC13783_LEDMDDC); +#ifdef HAVE_LCD_SLEEP + /* Disable lcd after fade completes (when lcd_sleep timeout expires) */ + backlight_lcd_sleep_countdown(true); /* start countdown */ +#endif + mutex_unlock(&backlight_mutex); } @@ -192,3 +203,15 @@ void _backlight_set_brightness(int brightness) mutex_unlock(&backlight_mutex); } #endif /* HAVE_BACKLIGHT_BRIGHTNESS */ + +#ifdef HAVE_LCD_SLEEP +/* Turn off LED supply */ +void _backlight_lcd_sleep(void) +{ + mutex_lock(&backlight_mutex); + + mc13783_clear(MC13783_LED_CONTROL0, MC13783_LEDEN); + + mutex_unlock(&backlight_mutex); +} +#endif diff --git a/firmware/target/arm/imx31/gigabeat-s/backlight-target.h b/firmware/target/arm/imx31/gigabeat-s/backlight-target.h index 3c378fc7c2..2ae1372815 100644 --- a/firmware/target/arm/imx31/gigabeat-s/backlight-target.h +++ b/firmware/target/arm/imx31/gigabeat-s/backlight-target.h @@ -32,4 +32,6 @@ void _backlight_on(void); void _backlight_off(void); void _backlight_set_brightness(int brightness); +void _backlight_lcd_sleep(void); + #endif /* BACKLIGHT_TARGET_H */ diff --git a/firmware/target/arm/imx31/gigabeat-s/lcd-imx31.c b/firmware/target/arm/imx31/gigabeat-s/lcd-imx31.c index 14d83bf138..5ebc3bd573 100644 --- a/firmware/target/arm/imx31/gigabeat-s/lcd-imx31.c +++ b/firmware/target/arm/imx31/gigabeat-s/lcd-imx31.c @@ -25,6 +25,7 @@ #include "lcd.h" #include "kernel.h" #include "lcd-target.h" +#include "backlight-target.h" #define LCDADDR(x, y) (&lcd_framebuffer[(y)][(x)]) @@ -42,13 +43,6 @@ extern struct viewport* current_vp; extern void lcd_copy_buffer_rect(fb_data *dst, const fb_data *src, int width, int height); -#if 0 -bool lcd_enabled() -{ - return lcd_on; -} -#endif - /* LCD init */ void lcd_init_device(void) { @@ -94,6 +88,14 @@ void lcd_update_rect(int x, int y, int width, int height) } } +#ifdef HAVE_LCD_SLEEP +void lcd_sleep(void) +{ + _backlight_lcd_sleep(); +} +#endif /* HAVE_LCD_SLEEP */ + +#if 0 void lcd_enable(bool state) { (void)state; @@ -103,6 +105,7 @@ bool lcd_enabled(void) { return true; } +#endif /* Update the display. This must be called after all other LCD functions that change the display. */ diff --git a/firmware/target/arm/imx31/gigabeat-s/power-imx31.c b/firmware/target/arm/imx31/gigabeat-s/power-imx31.c index 62f9982dd5..de7f5800e6 100644 --- a/firmware/target/arm/imx31/gigabeat-s/power-imx31.c +++ b/firmware/target/arm/imx31/gigabeat-s/power-imx31.c @@ -81,9 +81,18 @@ bool ide_powered(void) void power_off(void) { + /* Cut backlight */ + _backlight_off(); + + /* Let it fade */ + sleep(5*HZ/4); + + /* Set user off mode */ mc13783_set(MC13783_POWER_CONTROL0, MC13783_USEROFFSPI); + /* Wait for power cut */ disable_interrupt(IRQ_FIQ_STATUS); + while (1); }