From 139f9f28e9179a881c0bdd5c6bed6790591a07cb Mon Sep 17 00:00:00 2001 From: Jonathan Gordon Date: Mon, 30 Oct 2006 08:56:06 +0000 Subject: move the iriver h1x0/h3x0 targets to the target tree git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11392 a1c6a512-1295-4272-9138-f99709370657 --- firmware/SOURCES | 26 +++- firmware/backlight.c | 37 +----- firmware/drivers/adc.c | 129 ------------------- firmware/drivers/ata.c | 16 --- firmware/export/adc.h | 27 ---- firmware/export/config-h100.h | 9 ++ firmware/export/config-h120.h | 8 ++ firmware/export/config-h300.h | 12 +- firmware/system.c | 113 +--------------- firmware/target/coldfire/iriver/ata-iriver.c | 66 ++++++++++ firmware/target/coldfire/iriver/ata-target.h | 26 ++++ firmware/target/coldfire/iriver/backlight-target.h | 27 ++++ firmware/target/coldfire/iriver/h100/adc-h100.c | 117 +++++++++++++++++ firmware/target/coldfire/iriver/h100/adc-target.h | 41 ++++++ .../target/coldfire/iriver/h100/backlight-h100.c | 45 +++++++ firmware/target/coldfire/iriver/h100/power-h100.c | 143 +++++++++++++++++++++ firmware/target/coldfire/iriver/h100/usb-h100.c | 51 ++++++++ firmware/target/coldfire/iriver/h300/adc-h300.c | 83 ++++++++++++ firmware/target/coldfire/iriver/h300/adc-target.h | 41 ++++++ .../target/coldfire/iriver/h300/backlight-h300.c | 49 +++++++ firmware/target/coldfire/iriver/h300/power-h300.c | 101 +++++++++++++++ firmware/target/coldfire/iriver/h300/usb-h300.c | 56 ++++++++ firmware/target/coldfire/iriver/system-iriver.c | 133 +++++++++++++++++++ firmware/target/coldfire/iriver/usb-target.h | 24 ++++ firmware/usb.c | 41 ------ 25 files changed, 1055 insertions(+), 366 deletions(-) create mode 100644 firmware/target/coldfire/iriver/ata-iriver.c create mode 100644 firmware/target/coldfire/iriver/ata-target.h create mode 100644 firmware/target/coldfire/iriver/backlight-target.h create mode 100644 firmware/target/coldfire/iriver/h100/adc-h100.c create mode 100644 firmware/target/coldfire/iriver/h100/adc-target.h create mode 100644 firmware/target/coldfire/iriver/h100/backlight-h100.c create mode 100644 firmware/target/coldfire/iriver/h100/power-h100.c create mode 100644 firmware/target/coldfire/iriver/h100/usb-h100.c create mode 100644 firmware/target/coldfire/iriver/h300/adc-h300.c create mode 100644 firmware/target/coldfire/iriver/h300/adc-target.h create mode 100644 firmware/target/coldfire/iriver/h300/backlight-h300.c create mode 100644 firmware/target/coldfire/iriver/h300/power-h300.c create mode 100644 firmware/target/coldfire/iriver/h300/usb-h300.c create mode 100644 firmware/target/coldfire/iriver/system-iriver.c create mode 100644 firmware/target/coldfire/iriver/usb-target.h diff --git a/firmware/SOURCES b/firmware/SOURCES index 95e8450d00..e506a1bcf6 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES @@ -253,18 +253,30 @@ target/coldfire/iaudio/x5/lcd-remote-x5.c #endif #endif -#ifdef IRIVER_H100_SERIES +#ifdef IRIVER_H300_SERIES +target/coldfire/iriver/h300/power-h300.c #ifndef SIMULATOR -target/coldfire/iriver/h100/button-h100.c +target/coldfire/pcf50606-coldfire.c +target/coldfire/iriver/ata-iriver.c +target/coldfire/iriver/system-iriver.c +target/coldfire/iriver/h300/adc-h300.c +target/coldfire/iriver/h300/backlight-h300.c +target/coldfire/iriver/h300/button-h300.c +target/coldfire/iriver/h300/lcd-as-h300.S +target/coldfire/iriver/h300/pcf50606-h300.c +target/coldfire/iriver/h300/usb-h300.c #endif #endif -#ifdef IRIVER_H300_SERIES +#ifdef IRIVER_H100_SERIES +target/coldfire/iriver/h100/power-h100.c #ifndef SIMULATOR -target/coldfire/iriver/h300/lcd-as-h300.S -target/coldfire/iriver/h300/button-h300.c -target/coldfire/pcf50606-coldfire.c -target/coldfire/iriver/h300/pcf50606-h300.c +target/coldfire/iriver/ata-iriver.c +target/coldfire/iriver/system-iriver.c +target/coldfire/iriver/h100/adc-h100.c +target/coldfire/iriver/h100/backlight-h100.c +target/coldfire/iriver/h100/button-h100.c +target/coldfire/iriver/h100/usb-h100.c #endif #endif diff --git a/firmware/backlight.c b/firmware/backlight.c index 997e26daa7..46e28824d3 100644 --- a/firmware/backlight.c +++ b/firmware/backlight.c @@ -61,13 +61,7 @@ static inline void __backlight_off(void) #ifndef TARGET_TREE static inline void __backlight_on(void) { -#if CONFIG_BACKLIGHT == BL_IRIVER_H100 - and_l(~0x00020000, &GPIO1_OUT); -#elif CONFIG_BACKLIGHT == BL_IRIVER_H300 - lcd_enable(true); - sleep(HZ/100); /* lcd needs time - avoid flashing for dark screens */ - or_l(0x00020000, &GPIO1_OUT); -#elif CONFIG_BACKLIGHT == BL_RTC +#if CONFIG_BACKLIGHT == BL_RTC /* Enable square wave */ rtc_write(0x0a, rtc_read(0x0a) | 0x40); #elif CONFIG_BACKLIGHT == BL_PA14_LO /* Player */ @@ -84,12 +78,7 @@ static inline void __backlight_on(void) static inline void __backlight_off(void) { -#if CONFIG_BACKLIGHT == BL_IRIVER_H100 - or_l(0x00020000, &GPIO1_OUT); -#elif CONFIG_BACKLIGHT == BL_IRIVER_H300 - and_l(~0x00020000, &GPIO1_OUT); - lcd_enable(false); -#elif CONFIG_BACKLIGHT == BL_RTC +#if CONFIG_BACKLIGHT == BL_RTC /* Disable square wave */ rtc_write(0x0a, rtc_read(0x0a) & ~0x40); #elif CONFIG_BACKLIGHT == BL_PA14_LO /* Player */ @@ -162,7 +151,7 @@ static int lcd_sleep_timeout = 10*HZ; #if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR) /* backlight fading */ -#define BL_PWM_INTERVAL 5000 /* Cycle interval in µs */ +#define BL_PWM_INTERVAL 5000 /* Cycle interval in s */ #define BL_PWM_COUNT 100 static const char backlight_fade_value[8] = { 0, 1, 2, 4, 6, 8, 10, 20 }; static int fade_in_count = 1; @@ -352,26 +341,6 @@ static void __remote_backlight_off(void) { sim_remote_backlight(0); } -#else -#ifndef TARGET_TREE -static void __remote_backlight_on(void) -{ -#if defined(IRIVER_H300_SERIES) - and_l(~0x00000002, &GPIO1_OUT); -#else - and_l(~0x00000800, &GPIO_OUT); -#endif -} - -static void __remote_backlight_off(void) -{ -#if defined(IRIVER_H300_SERIES) - or_l(0x00000002, &GPIO1_OUT); -#else - or_l(0x00000800, &GPIO_OUT); -#endif -} -#endif /* TARGET_TREE */ #endif /* SIMULATOR */ #endif /* HAVE_REMOTE_LCD */ diff --git a/firmware/drivers/adc.c b/firmware/drivers/adc.c index 646509b8a8..388ff66d5f 100644 --- a/firmware/drivers/adc.c +++ b/firmware/drivers/adc.c @@ -108,135 +108,6 @@ void adc_init(void) sleep(2); /* Ensure valid readings when adc_init returns */ } -#elif CONFIG_CPU == MCF5249 -static unsigned char adcdata[NUM_ADC_CHANNELS]; - -#ifdef IRIVER_H300_SERIES -static int adcc2_parms[] = -{ - [ADC_BUTTONS] = 0x80 | (5 << 1) | 1, /* ADCIN2 */ - [ADC_REMOTE] = 0x80 | (6 << 1) | 1, /* ADCIN3 */ - [ADC_BATTERY] = 0x80 | (0 << 1) | 1, /* BATVOLT, resistive divider */ - [ADC_REMOTEDETECT] = 0x80 | (2 << 1) | 1, /* ADCIN1, resistive divider */ -}; - -unsigned short adc_scan(int channel) -{ - int level = set_irq_level(HIGHEST_IRQ_LEVEL); - unsigned char data; - - pcf50606_write(0x2f, adcc2_parms[channel]); - data = pcf50606_read(0x30); - - adcdata[channel] = data; - - set_irq_level(level); - return data; -} -#else - -#define CS_LO and_l(~0x80, &GPIO_OUT) -#define CS_HI or_l(0x80, &GPIO_OUT) -#define CLK_LO and_l(~0x00400000, &GPIO_OUT) -#define CLK_HI or_l(0x00400000, &GPIO_OUT) -#define DO (GPIO_READ & 0x80000000) -#define DI_LO and_l(~0x00200000, &GPIO_OUT) -#define DI_HI or_l(0x00200000, &GPIO_OUT) - -/* delay loop */ -#define DELAY do { int _x; for(_x=0;_x<10;_x++);} while (0) - -unsigned short adc_scan(int channel) -{ - unsigned char data = 0; - int i; - - CS_LO; - - DI_HI; /* Start bit */ - DELAY; - CLK_HI; - DELAY; - CLK_LO; - - DI_HI; /* Single channel */ - DELAY; - CLK_HI; - DELAY; - CLK_LO; - - if(channel & 1) /* LSB of channel number */ - DI_HI; - else - DI_LO; - DELAY; - CLK_HI; - DELAY; - CLK_LO; - - if(channel & 2) /* MSB of channel number */ - DI_HI; - else - DI_LO; - DELAY; - CLK_HI; - DELAY; - CLK_LO; - - DELAY; - - for(i = 0;i < 8;i++) /* 8 bits of data */ - { - CLK_HI; - DELAY; - CLK_LO; - DELAY; - data <<= 1; - data |= DO?1:0; - } - - CS_HI; - - adcdata[channel] = data; - - return data; -} -#endif - -unsigned short adc_read(int channel) -{ - return adcdata[channel]; -} - -static int adc_counter; - -static void adc_tick(void) -{ - if(++adc_counter == HZ) - { - adc_counter = 0; - adc_scan(ADC_BATTERY); - adc_scan(ADC_REMOTEDETECT); /* Temporary. Remove when the remote - detection feels stable. */ - } -} - -void adc_init(void) -{ -#ifndef IRIVER_H300_SERIES - or_l(0x80600080, &GPIO_FUNCTION); /* GPIO7: CS - GPIO21: Data In (to the ADC) - GPIO22: CLK - GPIO31: Data Out (from the ADC) */ - or_l(0x00600080, &GPIO_ENABLE); - or_l(0x80, &GPIO_OUT); /* CS high */ - and_l(~0x00400000, &GPIO_OUT); /* CLK low */ -#endif - - adc_scan(ADC_BATTERY); - - tick_add_task(adc_tick); -} #elif CONFIG_CPU == TCC730 diff --git a/firmware/drivers/ata.c b/firmware/drivers/ata.c index babbab016a..39827f7188 100644 --- a/firmware/drivers/ata.c +++ b/firmware/drivers/ata.c @@ -1476,12 +1476,6 @@ int ata_hard_reset(void) /* state HRR1 */ or_b(0x02, &PADRH); /* negate _RESET */ sleep(1); /* > 2ms */ -#elif defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES) - and_l(~0x00080000, &GPIO_OUT); - sleep(1); /* > 25us */ - - or_l(0x00080000, &GPIO_OUT); - sleep(1); /* > 25us */ #elif CONFIG_CPU == TCC730 P6 &= ~0x40; @@ -1627,14 +1621,6 @@ void ata_enable(bool on) or_b(0x80, &PADRL); /* disable ATA */ or_b(0x80, &PAIORL); -#elif defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES) - if(on) - and_l(~0x0040000, &GPIO_OUT); - else - or_l(0x0040000, &GPIO_OUT); - - or_l(0x00040000, &GPIO_ENABLE); - or_l(0x00040000, &GPIO_FUNCTION); #elif CONFIG_CPU == TCC730 #endif @@ -1788,8 +1774,6 @@ int ata_init(void) bool coldstart = ata_is_coldstart(); #elif CONFIG_CPU == TCC730 bool coldstart = (P1 & 0x80) == 0; -#elif defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES) - bool coldstart = (GPIO_FUNCTION & 0x00080000) == 0; #else bool coldstart = (PACR2 & 0x4000) != 0; #endif diff --git a/firmware/export/adc.h b/firmware/export/adc.h index 95728d432f..4dced55f09 100644 --- a/firmware/export/adc.h +++ b/firmware/export/adc.h @@ -24,28 +24,6 @@ #ifdef TARGET_TREE #include "adc-target.h" -#elif defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES) -#define NUM_ADC_CHANNELS 4 - -#define ADC_BUTTONS 0 -#define ADC_REMOTE 1 -#define ADC_BATTERY 2 -#define ADC_REMOTEDETECT 3 -#define ADC_UNREG_POWER ADC_BATTERY /* For compatibility */ - -/* ADC values for different remote control types */ -#ifdef IRIVER_H100_SERIES -#define ADCVAL_H300_LCD_REMOTE 0x5E -#define ADCVAL_H100_LCD_REMOTE 0x96 -#define ADCVAL_H300_LCD_REMOTE_HOLD 0xCC -#define ADCVAL_H100_LCD_REMOTE_HOLD 0xEA -#else /* H300 series */ -#define ADCVAL_H300_LCD_REMOTE 0x35 -#define ADCVAL_H100_LCD_REMOTE 0x54 -#define ADCVAL_H300_LCD_REMOTE_HOLD 0x72 -#define ADCVAL_H100_LCD_REMOTE_HOLD 0x83 -#endif - #elif defined(IRIVER_IFP7XX) #define NUM_ADC_CHANNELS 5 @@ -100,9 +78,4 @@ unsigned short adc_read(int channel); void adc_init(void); -#if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES) -/* Force a scan now */ -unsigned short adc_scan(int channel); -#endif - #endif /* _ADC_H_ */ diff --git a/firmware/export/config-h100.h b/firmware/export/config-h100.h index 12f1066d3a..6f74078e1e 100644 --- a/firmware/export/config-h100.h +++ b/firmware/export/config-h100.h @@ -2,6 +2,8 @@ #error "re-run configure this just so wrong" #endif +#define TARGET_TREE /* this target is using the target tree system */ + /* * This config file is for iriver iHP-100, iHP-110, iHP-115 */ @@ -145,6 +147,13 @@ #endif /* !SIMULATOR */ +#define DEFAULT_CONTRAST_SETTING 40 +#define MIN_CONTRAST_SETTING 5 +#define MAX_CONTRAST_SETTING 63 +#define DEFAULT_REMOTE_CONTRAST_SETTING 42 +#define MIN_REMOTE_CONTRAST_SETTING MIN_CONTRAST_SETTING +#define MAX_REMOTE_CONTRAST_SETTING MAX_CONTRAST_SETTING + /* Define this for S/PDIF input available */ #define HAVE_SPDIF_IN diff --git a/firmware/export/config-h120.h b/firmware/export/config-h120.h index 21451dcdac..1476102100 100644 --- a/firmware/export/config-h120.h +++ b/firmware/export/config-h120.h @@ -1,3 +1,4 @@ +#define TARGET_TREE /* this target is using the target tree system */ /* * This config file is for iriver H120 and H140 */ @@ -142,6 +143,13 @@ #endif /* !SIMULATOR */ +#define DEFAULT_CONTRAST_SETTING 40 +#define MIN_CONTRAST_SETTING 5 +#define MAX_CONTRAST_SETTING 63 +#define DEFAULT_REMOTE_CONTRAST_SETTING 42 +#define MIN_REMOTE_CONTRAST_SETTING MIN_CONTRAST_SETTING +#define MAX_REMOTE_CONTRAST_SETTING MAX_CONTRAST_SETTING + /* Define this for S/PDIF input available */ #define HAVE_SPDIF_IN diff --git a/firmware/export/config-h300.h b/firmware/export/config-h300.h index c9aad436f1..31f0f6729f 100644 --- a/firmware/export/config-h300.h +++ b/firmware/export/config-h300.h @@ -1,3 +1,4 @@ +#define TARGET_TREE /* this target is using the target tree system */ /* * This config file is for iriver H320, H340 */ @@ -144,8 +145,15 @@ #define HAVE_EEPROM #endif /* SIMULATOR */ - -#define DEFAULT_REMOTE_CONTRAST_SETTING 42 +/* Main LCD contrast range and defaults */ +#define MIN_CONTRAST_SETTING 5 +#define MAX_CONTRAST_SETTING 63 +#define DEFAULT_CONTRAST_SETTING 40 + +/* Remote LCD contrast range and defaults */ +#define MIN_REMOTE_CONTRAST_SETTING MIN_CONTRAST_SETTING +#define MAX_REMOTE_CONTRAST_SETTING MAX_CONTRAST_SETTING +#define DEFAULT_REMOTE_CONTRAST_SETTING 42 /* Define this for FM radio input available */ #define HAVE_FMRADIO_IN diff --git a/firmware/system.c b/firmware/system.c index c597fc5995..4dbc41b515 100644 --- a/firmware/system.c +++ b/firmware/system.c @@ -376,7 +376,7 @@ void system_init(void) /* IRQ12 SIO INT */ /* IRQ13 IIS0 INT */ /* IRQ14 IIS1 INT */ -/* IRQ15 ­ */ +/* IRQ15 */ extra_init(); } @@ -667,115 +667,8 @@ int system_memory_guard(int newmode) return oldmode; } -#ifndef TARGET_TREE -#if MEM < 32 -#define MAX_REFRESH_TIMER 59 -#define NORMAL_REFRESH_TIMER 21 -#define DEFAULT_REFRESH_TIMER 4 -#else -#define MAX_REFRESH_TIMER 29 -#define NORMAL_REFRESH_TIMER 10 -#define DEFAULT_REFRESH_TIMER 1 -#endif - -#ifdef IRIVER_H300_SERIES -#define RECALC_DELAYS(f) \ - pcf50606_i2c_recalc_delay(f) -#else -#define RECALC_DELAYS(f) -#endif - -#ifdef HAVE_SERIAL -#define BAUD_RATE 57600 -#define BAUDRATE_DIV_DEFAULT (CPUFREQ_DEFAULT/(BAUD_RATE*32*2)) -#define BAUDRATE_DIV_NORMAL (CPUFREQ_NORMAL/(BAUD_RATE*32*2)) -#define BAUDRATE_DIV_MAX (CPUFREQ_MAX/(BAUD_RATE*32*2)) -#endif - -void set_cpu_frequency (long) __attribute__ ((section (".icode"))); -void set_cpu_frequency(long frequency) -{ - switch(frequency) - { - case CPUFREQ_MAX: - DCR = (0x8200 | DEFAULT_REFRESH_TIMER); - /* Refresh timer for bypass frequency */ - PLLCR &= ~1; /* Bypass mode */ - timers_adjust_prescale(CPUFREQ_DEFAULT_MULT, false); - RECALC_DELAYS(CPUFREQ_MAX); - PLLCR = 0x11c56005; - CSCR0 = 0x00001180; /* Flash: 4 wait states */ - CSCR1 = 0x00000980; /* LCD: 2 wait states */ -#if CONFIG_USBOTG == USBOTG_ISP1362 - CSCR3 = 0x00002180; /* USBOTG: 8 wait states */ -#endif - while(!(PLLCR & 0x80000000)) {}; /* Wait until the PLL has locked. - This may take up to 10ms! */ - timers_adjust_prescale(CPUFREQ_MAX_MULT, true); - DCR = (0x8200 | MAX_REFRESH_TIMER); /* Refresh timer */ - cpu_frequency = CPUFREQ_MAX; - IDECONFIG1 = 0x10100000 | (1 << 13) | (2 << 10); - /* SRE active on write (H300 USBOTG) | BUFEN2 enable | CS2Post | CS2Pre */ - IDECONFIG2 = 0x40000 | (2 << 8); /* TA enable + CS2wait */ - -#ifdef HAVE_SERIAL - UBG10 = BAUDRATE_DIV_MAX >> 8; - UBG20 = BAUDRATE_DIV_MAX & 0xff; -#endif - break; - - case CPUFREQ_NORMAL: - DCR = (DCR & ~0x01ff) | DEFAULT_REFRESH_TIMER; - /* Refresh timer for bypass frequency */ - PLLCR &= ~1; /* Bypass mode */ - timers_adjust_prescale(CPUFREQ_DEFAULT_MULT, false); - RECALC_DELAYS(CPUFREQ_NORMAL); - PLLCR = 0x13c5e005; - CSCR0 = 0x00000580; /* Flash: 1 wait state */ - CSCR1 = 0x00000180; /* LCD: 0 wait states */ -#if CONFIG_USBOTG == USBOTG_ISP1362 - CSCR3 = 0x00000580; /* USBOTG: 1 wait state */ -#endif - while(!(PLLCR & 0x80000000)) {}; /* Wait until the PLL has locked. - This may take up to 10ms! */ - timers_adjust_prescale(CPUFREQ_NORMAL_MULT, true); - DCR = (0x8000 | NORMAL_REFRESH_TIMER); /* Refresh timer */ - cpu_frequency = CPUFREQ_NORMAL; - IDECONFIG1 = 0x10100000 | (0 << 13) | (1 << 10); - /* SRE active on write (H300 USBOTG) | BUFEN2 enable | CS2Post | CS2Pre */ - IDECONFIG2 = 0x40000 | (0 << 8); /* TA enable + CS2wait */ - -#ifdef HAVE_SERIAL - UBG10 = BAUDRATE_DIV_NORMAL >> 8; - UBG20 = BAUDRATE_DIV_NORMAL & 0xff; -#endif - break; - default: - DCR = (DCR & ~0x01ff) | DEFAULT_REFRESH_TIMER; - /* Refresh timer for bypass frequency */ - PLLCR &= ~1; /* Bypass mode */ - timers_adjust_prescale(CPUFREQ_DEFAULT_MULT, true); - RECALC_DELAYS(CPUFREQ_DEFAULT); - PLLCR = 0x10c00200; /* Power down PLL, but keep CLSEL and CRSEL */ - CSCR0 = 0x00000180; /* Flash: 0 wait states */ - CSCR1 = 0x00000180; /* LCD: 0 wait states */ -#if CONFIG_USBOTG == USBOTG_ISP1362 - CSCR3 = 0x00000180; /* USBOTG: 0 wait states */ -#endif - DCR = (0x8000 | DEFAULT_REFRESH_TIMER); /* Refresh timer */ - cpu_frequency = CPUFREQ_DEFAULT; - IDECONFIG1 = 0x10100000 | (0 << 13) | (1 << 10); - /* SRE active on write (H300 USBOTG) | BUFEN2 enable | CS2Post | CS2Pre */ - IDECONFIG2 = 0x40000 | (0 << 8); /* TA enable + CS2wait */ - -#ifdef HAVE_SERIAL - UBG10 = BAUDRATE_DIV_DEFAULT >> 8; - UBG20 = BAUDRATE_DIV_DEFAULT & 0xff; -#endif - break; - } -} -#endif +/* void set_cpu_frequency(long frequency) is in + target tree for all 3 coldfire targets */ #elif CONFIG_CPU == SH7034 #include "led.h" diff --git a/firmware/target/coldfire/iriver/ata-iriver.c b/firmware/target/coldfire/iriver/ata-iriver.c new file mode 100644 index 0000000000..82dae32a97 --- /dev/null +++ b/firmware/target/coldfire/iriver/ata-iriver.c @@ -0,0 +1,66 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2006 by Linus Nielsen Feltzing + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#include "config.h" +#include "cpu.h" +#include +#include "kernel.h" +#include "system.h" +#include "power.h" +#include "pcf50606.h" + +void ata_reset(void) +{ + and_l(~0x00080000, &GPIO_OUT); + sleep(1); /* > 25us */ + + or_l(0x00080000, &GPIO_OUT); + sleep(1); /* > 25us */ +} + +void ata_enable(bool on) +{ + if(on) + and_l(~0x0040000, &GPIO_OUT); + else + or_l(0x0040000, &GPIO_OUT); + + or_l(0x00040000, &GPIO_ENABLE); + or_l(0x00040000, &GPIO_FUNCTION); +} + +bool ata_is_coldstart(void) +{ + return (GPIO_FUNCTION & 0x00080000) == 0; +} + +void ata_device_init(void) +{ +#ifdef HAVE_ATA_LED_CTRL + /* Enable disk LED & ISD chip power control */ + and_l(~0x0000240, &GPIO_OUT); + or_l(0x00000240, &GPIO_ENABLE); + or_l(0x00000200, &GPIO_FUNCTION); +#endif + + /* ATA reset */ + or_l(0x00080000, &GPIO_OUT); + or_l(0x00080000, &GPIO_ENABLE); + or_l(0x00080000, &GPIO_FUNCTION); + +} diff --git a/firmware/target/coldfire/iriver/ata-target.h b/firmware/target/coldfire/iriver/ata-target.h new file mode 100644 index 0000000000..1801a7d376 --- /dev/null +++ b/firmware/target/coldfire/iriver/ata-target.h @@ -0,0 +1,26 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2006 by Linus Nielsen Feltzing + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#ifndef ATA_TARGET_H +#define ATA_TARGET_H + +void ata_reset(void); +void ata_device_init(void); +bool ata_is_coldstart(void); + +#endif diff --git a/firmware/target/coldfire/iriver/backlight-target.h b/firmware/target/coldfire/iriver/backlight-target.h new file mode 100644 index 0000000000..262650ae24 --- /dev/null +++ b/firmware/target/coldfire/iriver/backlight-target.h @@ -0,0 +1,27 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2006 by Linus Nielsen Feltzing + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#ifndef BACKLIGHT_TARGET_H +#define BACKLIGHT_TARGET_H + +void __backlight_on(void); +void __backlight_off(void); +void __remote_backlight_on(void); +void __remote_backlight_off(void); + +#endif diff --git a/firmware/target/coldfire/iriver/h100/adc-h100.c b/firmware/target/coldfire/iriver/h100/adc-h100.c new file mode 100644 index 0000000000..b29a2247ad --- /dev/null +++ b/firmware/target/coldfire/iriver/h100/adc-h100.c @@ -0,0 +1,117 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2006 by Linus Nielsen Feltzing + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#include "config.h" +#include "cpu.h" +#include "system.h" +#include "kernel.h" +#include "thread.h" +#include "adc.h" +static unsigned char adcdata[NUM_ADC_CHANNELS]; + + +#define CS_LO and_l(~0x80, &GPIO_OUT) +#define CS_HI or_l(0x80, &GPIO_OUT) +#define CLK_LO and_l(~0x00400000, &GPIO_OUT) +#define CLK_HI or_l(0x00400000, &GPIO_OUT) +#define DO (GPIO_READ & 0x80000000) +#define DI_LO and_l(~0x00200000, &GPIO_OUT) +#define DI_HI or_l(0x00200000, &GPIO_OUT) + +/* delay loop */ +#define DELAY do { int _x; for(_x=0;_x<10;_x++);} while (0) + +unsigned short adc_scan(int channel) +{ + unsigned char data = 0; + int i; + + CS_LO; + + DI_HI; /* Start bit */ + DELAY; + CLK_HI; + DELAY; + CLK_LO; + + DI_HI; /* Single channel */ + DELAY; + CLK_HI; + DELAY; + CLK_LO; + + if(channel & 1) /* LSB of channel number */ + DI_HI; + else + DI_LO; + DELAY; + CLK_HI; + DELAY; + CLK_LO; + + if(channel & 2) /* MSB of channel number */ + DI_HI; + else + DI_LO; + DELAY; + CLK_HI; + DELAY; + CLK_LO; + + DELAY; + + for(i = 0;i < 8;i++) /* 8 bits of data */ + { + CLK_HI; + DELAY; + CLK_LO; + DELAY; + data <<= 1; + data |= DO?1:0; + } + + CS_HI; + + adcdata[channel] = data; + + return data; +} +unsigned short adc_read(int channel) +{ + return adcdata[channel]; +} + +static int adc_counter; + +static void adc_tick(void) +{ + if(++adc_counter == HZ) + { + adc_counter = 0; + adc_scan(ADC_BATTERY); + adc_scan(ADC_REMOTEDETECT); /* Temporary. Remove when the remote + detection feels stable. */ + } +} + +void adc_init(void) +{ + adc_scan(ADC_BATTERY); + + tick_add_task(adc_tick); +} diff --git a/firmware/target/coldfire/iriver/h100/adc-target.h b/firmware/target/coldfire/iriver/h100/adc-target.h new file mode 100644 index 0000000000..54e7bc936a --- /dev/null +++ b/firmware/target/coldfire/iriver/h100/adc-target.h @@ -0,0 +1,41 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2002 by Linus Nielsen Feltzing + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +/* for the iriver h1x0 */ + +#ifndef _ADC_TARGET_H_ +#define _ADC_TARGET_H_ + +#define NUM_ADC_CHANNELS 4 + +#define ADC_BUTTONS 0 +#define ADC_REMOTE 1 +#define ADC_BATTERY 2 +#define ADC_REMOTEDETECT 3 +#define ADC_UNREG_POWER ADC_BATTERY /* For compatibility */ + +/* ADC values for different remote control types */ +#define ADCVAL_H300_LCD_REMOTE 0x5E +#define ADCVAL_H100_LCD_REMOTE 0x96 +#define ADCVAL_H300_LCD_REMOTE_HOLD 0xCC +#define ADCVAL_H100_LCD_REMOTE_HOLD 0xEA + +/* Force a scan now */ +unsigned short adc_scan(int channel); + +#endif /* _ADC_TARGET_H_ */ diff --git a/firmware/target/coldfire/iriver/h100/backlight-h100.c b/firmware/target/coldfire/iriver/h100/backlight-h100.c new file mode 100644 index 0000000000..8ceac8a6ff --- /dev/null +++ b/firmware/target/coldfire/iriver/h100/backlight-h100.c @@ -0,0 +1,45 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2006 by Linus Nielsen Feltzing + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#include "config.h" +#include "cpu.h" +#include "kernel.h" +#include "thread.h" +#include "system.h" +#include "backlight.h" +#include "lcd.h" + +void __backlight_on(void) +{ + and_l(~0x00020000, &GPIO1_OUT); +} + +void __backlight_off(void) +{ + or_l(0x00020000, &GPIO1_OUT); +} + +void __remote_backlight_on(void) +{ + and_l(~0x00000800, &GPIO_OUT); +} + +void __remote_backlight_off(void) +{ + or_l(0x00000800, &GPIO_OUT); +} diff --git a/firmware/target/coldfire/iriver/h100/power-h100.c b/firmware/target/coldfire/iriver/h100/power-h100.c new file mode 100644 index 0000000000..0714ab2d3f --- /dev/null +++ b/firmware/target/coldfire/iriver/h100/power-h100.c @@ -0,0 +1,143 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2002 by Linus Nielsen Feltzing + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#include "config.h" +#include "cpu.h" +#include +#include "kernel.h" +#include "system.h" +#include "power.h" + + +#ifdef CONFIG_TUNER + +static bool powered = false; + +bool radio_powered(void) +{ + return powered; +} + +bool radio_power(bool status) +{ + bool old_status = powered; + powered = status; + return old_status; +} + +#endif /* #ifdef CONFIG_TUNER */ + +#ifndef SIMULATOR + +void power_init(void) +{ + or_l(0x00080000, &GPIO1_OUT); + or_l(0x00080000, &GPIO1_ENABLE); + or_l(0x00080000, &GPIO1_FUNCTION); + +#ifndef BOOTLOADER + /* The boot loader controls the power */ + ide_power_enable(true); +#endif + or_l(0x80000000, &GPIO_ENABLE); + or_l(0x80000000, &GPIO_FUNCTION); +#ifdef HAVE_SPDIF_POWER + spdif_power_enable(false); +#endif +} + + +bool charger_inserted(void) +{ + return (GPIO1_READ & 0x00400000)?true:false; +} +/* Returns true if the unit is charging the batteries. */ +bool charging_state(void) { + return charger_inserted(); +} + +#ifdef HAVE_SPDIF_POWER +void spdif_power_enable(bool on) +{ + or_l(0x01000000, &GPIO1_FUNCTION); + or_l(0x01000000, &GPIO1_ENABLE); + +#ifdef SPDIF_POWER_INVERTED + if(!on) +#else + if(on) +#endif + and_l(~0x01000000, &GPIO1_OUT); + else + or_l(0x01000000, &GPIO1_OUT); +} +#endif + +void ide_power_enable(bool on) +{ + if(on) + and_l(~0x80000000, &GPIO_OUT); + else + or_l(0x80000000, &GPIO_OUT); +} + + +bool ide_powered(void) +{ + return (GPIO_OUT & 0x80000000)?false:true; +} + + +void power_off(void) +{ + set_irq_level(HIGHEST_IRQ_LEVEL); + and_l(~0x00080000, &GPIO1_OUT); + asm("halt"); + while(1) + yield(); +} + +#else + +bool charger_inserted(void) +{ + return false; +} + +void charger_enable(bool on) +{ + (void)on; +} + +void power_off(void) +{ +} + +void ide_power_enable(bool on) +{ + (void)on; +} + +#ifdef HAVE_SPDIF_POWER +void spdif_power_enable(bool on) +{ + (void)on; +} +#endif + +#endif /* SIMULATOR */ diff --git a/firmware/target/coldfire/iriver/h100/usb-h100.c b/firmware/target/coldfire/iriver/h100/usb-h100.c new file mode 100644 index 0000000000..3b00e967da --- /dev/null +++ b/firmware/target/coldfire/iriver/h100/usb-h100.c @@ -0,0 +1,51 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2006 by Linus Nielsen Feltzing + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#include "config.h" +#include +#include "cpu.h" +#include "system.h" +#include "kernel.h" + +void usb_init_device(void) +{ + or_l(0x00000080, &GPIO1_FUNCTION); /* GPIO39 is the USB detect input */ + and_l(~0x01000040, &GPIO_OUT); /* GPIO24 is the Cypress chip power */ + or_l(0x01000040, &GPIO_ENABLE); + or_l(0x01000040, &GPIO_FUNCTION); +} + +bool usb_detect(void) +{ + return (GPIO1_READ & 0x80)?true:false; +} + +void usb_enable(bool on) +{ + if(on) + { + /* Power on the Cypress chip */ + or_l(0x01000040, &GPIO_OUT); + sleep(2); + } + else + { + /* Power off the Cypress chip */ + and_l(~0x01000040, &GPIO_OUT); + } +} diff --git a/firmware/target/coldfire/iriver/h300/adc-h300.c b/firmware/target/coldfire/iriver/h300/adc-h300.c new file mode 100644 index 0000000000..31702eaef1 --- /dev/null +++ b/firmware/target/coldfire/iriver/h300/adc-h300.c @@ -0,0 +1,83 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2006 by Linus Nielsen Feltzing + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#include "config.h" +#include "cpu.h" +#include "system.h" +#include "kernel.h" +#include "thread.h" +#include "adc.h" +#include "pcf50606.h" + +static unsigned char adcdata[NUM_ADC_CHANNELS]; + +static int adcc2_parms[] = +{ + [ADC_BUTTONS] = 0x80 | (5 << 1) | 1, /* ADCIN2 */ + [ADC_REMOTE] = 0x80 | (6 << 1) | 1, /* ADCIN3 */ + [ADC_BATTERY] = 0x80 | (0 << 1) | 1, /* BATVOLT, resistive divider */ + [ADC_REMOTEDETECT] = 0x80 | (2 << 1) | 1, /* ADCIN1, resistive divider */ +}; + +unsigned short adc_scan(int channel) +{ + int level = set_irq_level(HIGHEST_IRQ_LEVEL); + unsigned char data; + + pcf50606_write(0x2f, adcc2_parms[channel]); + data = pcf50606_read(0x30); + + adcdata[channel] = data; + + set_irq_level(level); + return data; +} + + +unsigned short adc_read(int channel) +{ + return adcdata[channel]; +} + +static int adc_counter; + +static void adc_tick(void) +{ + if(++adc_counter == HZ) + { + adc_counter = 0; + adc_scan(ADC_BATTERY); + adc_scan(ADC_REMOTEDETECT); /* Temporary. Remove when the remote + detection feels stable. */ + } +} + +void adc_init(void) +{ + or_l(0x80600080, &GPIO_FUNCTION); /* GPIO7: CS + GPIO21: Data In (to the ADC) + GPIO22: CLK + GPIO31: Data Out (from the ADC) */ + or_l(0x00600080, &GPIO_ENABLE); + or_l(0x80, &GPIO_OUT); /* CS high */ + and_l(~0x00400000, &GPIO_OUT); /* CLK low */ + + adc_scan(ADC_BATTERY); + + tick_add_task(adc_tick); +} diff --git a/firmware/target/coldfire/iriver/h300/adc-target.h b/firmware/target/coldfire/iriver/h300/adc-target.h new file mode 100644 index 0000000000..04200904a2 --- /dev/null +++ b/firmware/target/coldfire/iriver/h300/adc-target.h @@ -0,0 +1,41 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2002 by Linus Nielsen Feltzing + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +/* for the iriver h3x0 */ + +#ifndef _ADC_TARGET_H_ +#define _ADC_TARGET_H_ + +#define NUM_ADC_CHANNELS 4 + +#define ADC_BUTTONS 0 +#define ADC_REMOTE 1 +#define ADC_BATTERY 2 +#define ADC_REMOTEDETECT 3 +#define ADC_UNREG_POWER ADC_BATTERY /* For compatibility */ + +/* ADC values for different remote control types */ +#define ADCVAL_H300_LCD_REMOTE 0x35 +#define ADCVAL_H100_LCD_REMOTE 0x54 +#define ADCVAL_H300_LCD_REMOTE_HOLD 0x72 +#define ADCVAL_H100_LCD_REMOTE_HOLD 0x83 + +/* Force a scan now */ +unsigned short adc_scan(int channel); + +#endif /* _ADC_TARGET_H_ */ diff --git a/firmware/target/coldfire/iriver/h300/backlight-h300.c b/firmware/target/coldfire/iriver/h300/backlight-h300.c new file mode 100644 index 0000000000..d5322c2cf7 --- /dev/null +++ b/firmware/target/coldfire/iriver/h300/backlight-h300.c @@ -0,0 +1,49 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2006 by Linus Nielsen Feltzing + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#include "config.h" +#include "cpu.h" +#include "kernel.h" +#include "thread.h" +#include "system.h" +#include "backlight.h" +#include "pcf50606.h" +#include "lcd.h" + +void __backlight_on(void) +{ + lcd_enable(true); + sleep(HZ/100); /* lcd needs time - avoid flashing for dark screens */ + or_l(0x00020000, &GPIO1_OUT); +} + +void __backlight_off(void) +{ + and_l(~0x00020000, &GPIO1_OUT); + lcd_enable(false); +} + +void __remote_backlight_on(void) +{ + and_l(~0x00000002, &GPIO1_OUT); +} + +void __remote_backlight_off(void) +{ + or_l(0x00000002, &GPIO1_OUT); +} diff --git a/firmware/target/coldfire/iriver/h300/power-h300.c b/firmware/target/coldfire/iriver/h300/power-h300.c new file mode 100644 index 0000000000..7c95aaf200 --- /dev/null +++ b/firmware/target/coldfire/iriver/h300/power-h300.c @@ -0,0 +1,101 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2002 by Linus Nielsen Feltzing + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#include "config.h" +#include "cpu.h" +#include +#include "kernel.h" +#include "system.h" +#include "power.h" +#include "pcf50606.h" + + +#ifdef CONFIG_TUNER + +static bool powered = false; + +bool radio_powered(void) +{ + return powered; +} + +bool radio_power(bool status) +{ + bool old_status = powered; + powered = status; + return old_status; +} + +#endif /* #ifdef CONFIG_TUNER */ + +#ifndef SIMULATOR + +void power_init(void) +{ + or_l(0x00080000, &GPIO1_OUT); + or_l(0x00080000, &GPIO1_ENABLE); + or_l(0x00080000, &GPIO1_FUNCTION); + +#ifndef BOOTLOADER + /* The boot loader controls the power */ + ide_power_enable(true); +#endif + or_l(0x80000000, &GPIO_ENABLE); + or_l(0x80000000, &GPIO_FUNCTION); + pcf50606_init(); +} + + +#ifdef CONFIG_CHARGING +bool charger_inserted(void) +{ + return (GPIO1_READ & 0x00400000)?true:false; +} +#endif /* CONFIG_CHARGING */ + +/* Returns true if the unit is charging the batteries. */ +bool charging_state(void) { + return (GPIO_READ & 0x00800000)?true:false; +} + + +void ide_power_enable(bool on) +{ + if(on) + and_l(~0x80000000, &GPIO_OUT); + else + or_l(0x80000000, &GPIO_OUT); +} + + +bool ide_powered(void) +{ + return (GPIO_OUT & 0x80000000)?false:true; +} + + +void power_off(void) +{ + set_irq_level(HIGHEST_IRQ_LEVEL); + and_l(~0x00080000, &GPIO1_OUT); + asm("halt"); + while(1) + yield(); +} + +#endif /* SIMULATOR */ diff --git a/firmware/target/coldfire/iriver/h300/usb-h300.c b/firmware/target/coldfire/iriver/h300/usb-h300.c new file mode 100644 index 0000000000..d08cc24dba --- /dev/null +++ b/firmware/target/coldfire/iriver/h300/usb-h300.c @@ -0,0 +1,56 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2006 by Linus Nielsen Feltzing + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#include "config.h" +#include +#include "cpu.h" +#include "system.h" +#include "kernel.h" + +void usb_init_device(void) +{ + or_l(0x00000080, &GPIO1_FUNCTION); /* GPIO39 is the USB detect input */ + /* ISD300 3.3V ON */ + or_l(8,&GPIO1_FUNCTION); + or_l(8,&GPIO1_OUT); + or_l(8,&GPIO1_ENABLE); + + /* Tristate the SCK/SDA to the ISD300 config EEPROM */ + and_l(~0x03000000, &GPIO_ENABLE); + or_l(0x03000000, &GPIO_FUNCTION); +} + +bool usb_detect(void) +{ + return (GPIO1_READ & 0x80)?true:false; +} + +void usb_enable(bool on) +{ + if(on) + { + /* Power on the Cypress chip */ + and_l(~0x00000008,&GPIO1_OUT); + sleep(2); + } + else + { + /* Power off the Cypress chip */ + or_l(0x00000008,&GPIO1_OUT); + } +} diff --git a/firmware/target/coldfire/iriver/system-iriver.c b/firmware/target/coldfire/iriver/system-iriver.c new file mode 100644 index 0000000000..5f404fb8cf --- /dev/null +++ b/firmware/target/coldfire/iriver/system-iriver.c @@ -0,0 +1,133 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2006 by Linus Nielsen Feltzing + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#include "config.h" +#include "cpu.h" +#include "kernel.h" +#include "system.h" +#include "power.h" +#include "timer.h" +#include "pcf50606.h" + +#if MEM < 32 +#define MAX_REFRESH_TIMER 59 +#define NORMAL_REFRESH_TIMER 21 +#define DEFAULT_REFRESH_TIMER 4 +#else +#define MAX_REFRESH_TIMER 29 +#define NORMAL_REFRESH_TIMER 10 +#define DEFAULT_REFRESH_TIMER 1 +#endif + +#ifdef IRIVER_H300_SERIES +#define RECALC_DELAYS(f) \ + pcf50606_i2c_recalc_delay(f) +#else +#define RECALC_DELAYS(f) +#endif + +#ifdef HAVE_SERIAL +#define BAUD_RATE 57600 +#define BAUDRATE_DIV_DEFAULT (CPUFREQ_DEFAULT/(BAUD_RATE*32*2)) +#define BAUDRATE_DIV_NORMAL (CPUFREQ_NORMAL/(BAUD_RATE*32*2)) +#define BAUDRATE_DIV_MAX (CPUFREQ_MAX/(BAUD_RATE*32*2)) +#endif + +void set_cpu_frequency (long) __attribute__ ((section (".icode"))); +void set_cpu_frequency(long frequency) +{ + switch(frequency) + { + case CPUFREQ_MAX: + DCR = (0x8200 | DEFAULT_REFRESH_TIMER); + /* Refresh timer for bypass frequency */ + PLLCR &= ~1; /* Bypass mode */ + timers_adjust_prescale(CPUFREQ_DEFAULT_MULT, false); + RECALC_DELAYS(CPUFREQ_MAX); + PLLCR = 0x11c56005; + CSCR0 = 0x00001180; /* Flash: 4 wait states */ + CSCR1 = 0x00000980; /* LCD: 2 wait states */ +#if CONFIG_USBOTG == USBOTG_ISP1362 + CSCR3 = 0x00002180; /* USBOTG: 8 wait states */ +#endif + while(!(PLLCR & 0x80000000)) {}; /* Wait until the PLL has locked. + This may take up to 10ms! */ + timers_adjust_prescale(CPUFREQ_MAX_MULT, true); + DCR = (0x8200 | MAX_REFRESH_TIMER); /* Refresh timer */ + cpu_frequency = CPUFREQ_MAX; + IDECONFIG1 = 0x10100000 | (1 << 13) | (2 << 10); + /* SRE active on write (H300 USBOTG) | BUFEN2 enable | CS2Post | CS2Pre */ + IDECONFIG2 = 0x40000 | (2 << 8); /* TA enable + CS2wait */ + +#ifdef HAVE_SERIAL + UBG10 = BAUDRATE_DIV_MAX >> 8; + UBG20 = BAUDRATE_DIV_MAX & 0xff; +#endif + break; + + case CPUFREQ_NORMAL: + DCR = (DCR & ~0x01ff) | DEFAULT_REFRESH_TIMER; + /* Refresh timer for bypass frequency */ + PLLCR &= ~1; /* Bypass mode */ + timers_adjust_prescale(CPUFREQ_DEFAULT_MULT, false); + RECALC_DELAYS(CPUFREQ_NORMAL); + PLLCR = 0x13c5e005; + CSCR0 = 0x00000580; /* Flash: 1 wait state */ + CSCR1 = 0x00000180; /* LCD: 0 wait states */ +#if CONFIG_USBOTG == USBOTG_ISP1362 + CSCR3 = 0x00000580; /* USBOTG: 1 wait state */ +#endif + while(!(PLLCR & 0x80000000)) {}; /* Wait until the PLL has locked. + This may take up to 10ms! */ + timers_adjust_prescale(CPUFREQ_NORMAL_MULT, true); + DCR = (0x8000 | NORMAL_REFRESH_TIMER); /* Refresh timer */ + cpu_frequency = CPUFREQ_NORMAL; + IDECONFIG1 = 0x10100000 | (0 << 13) | (1 << 10); + /* SRE active on write (H300 USBOTG) | BUFEN2 enable | CS2Post | CS2Pre */ + IDECONFIG2 = 0x40000 | (0 << 8); /* TA enable + CS2wait */ + +#ifdef HAVE_SERIAL + UBG10 = BAUDRATE_DIV_NORMAL >> 8; + UBG20 = BAUDRATE_DIV_NORMAL & 0xff; +#endif + break; + default: + DCR = (DCR & ~0x01ff) | DEFAULT_REFRESH_TIMER; + /* Refresh timer for bypass frequency */ + PLLCR &= ~1; /* Bypass mode */ + timers_adjust_prescale(CPUFREQ_DEFAULT_MULT, true); + RECALC_DELAYS(CPUFREQ_DEFAULT); + PLLCR = 0x10c00200; /* Power down PLL, but keep CLSEL and CRSEL */ + CSCR0 = 0x00000180; /* Flash: 0 wait states */ + CSCR1 = 0x00000180; /* LCD: 0 wait states */ +#if CONFIG_USBOTG == USBOTG_ISP1362 + CSCR3 = 0x00000180; /* USBOTG: 0 wait states */ +#endif + DCR = (0x8000 | DEFAULT_REFRESH_TIMER); /* Refresh timer */ + cpu_frequency = CPUFREQ_DEFAULT; + IDECONFIG1 = 0x10100000 | (0 << 13) | (1 << 10); + /* SRE active on write (H300 USBOTG) | BUFEN2 enable | CS2Post | CS2Pre */ + IDECONFIG2 = 0x40000 | (0 << 8); /* TA enable + CS2wait */ + +#ifdef HAVE_SERIAL + UBG10 = BAUDRATE_DIV_DEFAULT >> 8; + UBG20 = BAUDRATE_DIV_DEFAULT & 0xff; +#endif + break; + } +} diff --git a/firmware/target/coldfire/iriver/usb-target.h b/firmware/target/coldfire/iriver/usb-target.h new file mode 100644 index 0000000000..ab8cac6f99 --- /dev/null +++ b/firmware/target/coldfire/iriver/usb-target.h @@ -0,0 +1,24 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2006 by Linus Nielsen Feltzing + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#ifndef USB_TARGET_H +#define USB_TARGET_H + +bool usb_init_device(void); + +#endif diff --git a/firmware/usb.c b/firmware/usb.c index f83cb44e17..a0ffef1011 100644 --- a/firmware/usb.c +++ b/firmware/usb.c @@ -155,26 +155,6 @@ void usb_enable(bool on) } } } -#elif defined(USB_IRIVERSTYLE) - if(on) - { - /* Power on the Cypress chip */ -#ifdef IRIVER_H100_SERIES - or_l(0x01000040, &GPIO_OUT); -#else - and_l(~0x00000008,&GPIO1_OUT); -#endif - sleep(2); - } - else - { - /* Power off the Cypress chip */ -#ifdef IRIVER_H100_SERIES - and_l(~0x01000040, &GPIO_OUT); -#else - or_l(0x00000008,&GPIO1_OUT); -#endif - } #elif defined(USB_ISP1582) /* TODO: Implement USB_ISP1582 */ (void) on; @@ -391,9 +371,6 @@ bool usb_detect(void) #ifdef USB_PLAYERSTYLE current_status = (PADR & 0x8000)?false:true; #endif -#ifdef USB_IRIVERSTYLE - current_status = (GPIO1_READ & 0x80)?true:false; -#endif #ifdef USB_GMINISTYLE current_status = (P5 & 0x10)?true:false; #endif @@ -481,24 +458,6 @@ void usb_init(void) #ifdef TARGET_TREE usb_init_device(); -#elif defined USB_IRIVERSTYLE - or_l(0x00000080, &GPIO1_FUNCTION); /* GPIO39 is the USB detect input */ - -#ifdef IRIVER_H300_SERIES - /* ISD300 3.3V ON */ - or_l(8,&GPIO1_FUNCTION); - or_l(8,&GPIO1_OUT); - or_l(8,&GPIO1_ENABLE); - - /* Tristate the SCK/SDA to the ISD300 config EEPROM */ - and_l(~0x03000000, &GPIO_ENABLE); - or_l(0x03000000, &GPIO_FUNCTION); -#else - and_l(~0x01000040, &GPIO_OUT); /* GPIO24 is the Cypress chip power */ - or_l(0x01000040, &GPIO_ENABLE); - or_l(0x01000040, &GPIO_FUNCTION); -#endif - #endif usb_enable(false); -- cgit v1.2.3