diff --git a/bootloader/SOURCES b/bootloader/SOURCES index 919e002f1b..11dfb667ae 100644 --- a/bootloader/SOURCES +++ b/bootloader/SOURCES @@ -22,6 +22,8 @@ iaudio_x5.c iriver_h300.c #elif defined(MROBE_500) mrobe500.c +#elif defined(CPU_TCC77X) +telechips.c #else main.c #endif diff --git a/bootloader/telechips.c b/bootloader/telechips.c new file mode 100644 index 0000000000..c1dcda0dae --- /dev/null +++ b/bootloader/telechips.c @@ -0,0 +1,81 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2007 by Dave Chapman + * + * Based on Rockbox iriver bootloader 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 +#include +#include "cpu.h" +#include "system.h" +#include "lcd.h" +#include "kernel.h" +#include "thread.h" +#include "ata.h" +#include "fat.h" +#include "disk.h" +#include "font.h" +#include "adc.h" +#include "adc-target.h" +#include "backlight-target.h" +#include "panic.h" +#include "power.h" +#include "file.h" +#include "common.h" + +char version[] = APPSVERSION; + +extern int line; + +void* main(void) +{ + unsigned short button; + int gpioa; + + system_init(); + adc_init(); + lcd_init(); + font_init(); + + __backlight_on(); + + while(1) { + line = 0; + printf("Hello World!"); + + gpioa = GPIOA; + printf("GPIOA: 0x%08x",gpioa); + + button = adc_read(ADC_BUTTONS); + printf("ADC[0]: 0x%04x",button); + } + + return 0; +} + +/* These functions are present in the firmware library, but we reimplement + them here because the originals do a lot more than we want */ +void usb_acknowledge(void) +{ +} + +void usb_wait_for_disconnect(void) +{ +} diff --git a/firmware/FILES b/firmware/FILES index a3cfc0c8c2..1882f3dd07 100644 --- a/firmware/FILES +++ b/firmware/FILES @@ -25,6 +25,8 @@ target/arm/archos/av300/*.[chS] target/arm/s3c2440/gigabeat-fx/*.[chS] target/arm/iriver/*.[chS] target/arm/iriver/h10/*.[chS] +target/arm/tcc77x/*.[chS] +target/arm/tcc77x/logikdax/*.[chS] target/arm/tms320dm320/*.[chS] target/arm/tms320dm320/mrobe-500/*.[chS] target/arm/pnx0101/*.[chS] diff --git a/firmware/SOURCES b/firmware/SOURCES index 9e501b661a..5061ac7370 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES @@ -111,7 +111,7 @@ drivers/ata_mmc.c #ifdef HAVE_FLASH_DISK drivers/ata_flash.c #else /* !HAVE_FLASH_DISK */ -#if !defined(SANSA_E200) && !defined(SANSA_C200) +#if !defined(SANSA_E200) && !defined(SANSA_C200) && !defined(LOGIK_DAX) && !defined(IAUDIO_7) drivers/ata.c #endif /* SANSA_E200 */ #endif /* HAVE_FLASH_DISK */ @@ -336,6 +336,8 @@ target/arm/crt0-pp.S target/arm/pnx0101/crt0-pnx0101.S #elif defined(OLYMPUS_MROBE_500) target/arm/tms320dm320/crt0.S +#elif defined(CPU_TCC77X) +target/arm/tcc77x/crt0.S #elif defined(CPU_ARM) target/arm/crt0.S #endif /* defined(CPU_*) */ @@ -814,3 +816,22 @@ target/arm/pnx0101/pcm-pnx0101.c #endif /* SIMULATOR */ #endif /* IRIVER_IFP7XX */ +#ifdef LOGIK_DAX +#ifndef SIMULATOR +target/arm/tcc77x/adc-tcc77x.c +target/arm/tcc77x/ata-nand-tcc77x.c +target/arm/tcc77x/system-tcc77x.c +target/arm/tcc77x/logikdax/lcd-logikdax.c +target/arm/tcc77x/logikdax/power-logikdax.c +#endif /* SIMULATOR */ +#endif /* LOGIK_DAX */ + +#ifdef IAUDIO_7 +#ifndef SIMULATOR +target/arm/tcc77x/adc-tcc77x.c +target/arm/tcc77x/ata-nand-tcc77x.c +target/arm/tcc77x/system-tcc77x.c +target/arm/tcc77x/iaudio7/lcd-iaudio7.c +target/arm/tcc77x/iaudio7/power-iaudio7.c +#endif /* SIMULATOR */ +#endif /* IAUDIO_7 */ diff --git a/firmware/boot.lds b/firmware/boot.lds index a8404134ae..d2ea10a30d 100644 --- a/firmware/boot.lds +++ b/firmware/boot.lds @@ -11,6 +11,8 @@ OUTPUT_ARCH(arm) INPUT(target/arm/crt0-pp-bl.o) #elif defined(OLYMPUS_MROBE_500) INPUT(target/arm/tms320dm320/crt0.o) +#elif defined(CPU_TCC77X) +INPUT(target/arm/tcc77x/crt0.o) #else INPUT(target/arm/crt0.o) #endif @@ -77,6 +79,12 @@ INPUT(target/sh/crt0.o) #define IRAMSIZE 16K #define FLASHORIG 0x0000000 #define FLASHSIZE 1M +#elif defined(CPU_TCC77X) +#define DRAMORIG 0x20000000 +#define IRAMORIG 0x00000000 +#define IRAMSIZE 64K +#define FLASHORIG 0x0000000 +#define FLASHSIZE 1M #else #define DRAMORIG 0x09000000 #define IRAMORIG 0x0f000000 @@ -85,7 +93,17 @@ INPUT(target/sh/crt0.o) #define FLASHSIZE 256K - ROM_START #endif -#if !defined(CPU_PP) && (CONFIG_CPU!=S3C2440) && (CONFIG_CPU!=IMX31L) +#if defined(CPU_TCC77X) +MEMORY +{ +#ifdef TCCBOOT + DRAM : ORIGIN = DRAMORIG + DRAMSIZE - 0x100000, LENGTH = 0x100000 +#else + DRAM : ORIGIN = DRAMORIG, LENGTH = DRAMSIZE +#endif + IRAM : ORIGIN = IRAMORIG, LENGTH = IRAMSIZE +} +#elif !defined(CPU_PP) && (CONFIG_CPU!=S3C2440) && (CONFIG_CPU!=IMX31L) MEMORY { DRAM : ORIGIN = DRAMORIG, LENGTH = DRAMSIZE @@ -168,6 +186,43 @@ SECTIONS _end = .; } } +#elif defined(CPU_TCC77X) +{ + .text : { + *(.init.text) + *(.text) + *(.text*) + *(.glue_7) + *(.glue_7t) + } > DRAM + + .data : { + *(.icode) + *(.irodata) + *(.idata) + *(.data*) + *(.rodata.*) + . = ALIGN(0x4); + _dataend = . ; + } > DRAM + + .stack : + { + *(.stack) + _stackbegin = .; + stackbegin = .; + . += 0x2000; + _stackend = .; + stackend = .; + } > DRAM + .bss : { + _edata = .; + *(.bss*); + *(.ibss); + *(COMMON) + _end = .; + } > DRAM +} #elif (CONFIG_CPU==DM320) { . = DRAMORIG + 0x1000000; diff --git a/firmware/export/config-logikdax.h b/firmware/export/config-logikdax.h new file mode 100644 index 0000000000..384dac4e11 --- /dev/null +++ b/firmware/export/config-logikdax.h @@ -0,0 +1,107 @@ +/* + * This config file is for the Logik DAX MP3/DAB + */ +#define TARGET_TREE /* this target is using the target tree system */ + +/* For Rolo and boot loader */ +#define MODEL_NUMBER 23 + +/* define this if you have recording possibility */ +//#define HAVE_RECORDING + +/* Define bitmask of input sources - recordable bitmask can be defined + explicitly if different */ +//#define INPUT_SRC_CAPS (SRC_CAP_MIC | SRC_CAP_LINEIN | SRC_CAP_SPDIF) + +/* define this if you have a bitmap LCD display */ +#define HAVE_LCD_BITMAP + +/* define this if you can flip your LCD */ +#define HAVE_LCD_FLIP + +/* define this if you can invert the colours on your LCD */ +#define HAVE_LCD_INVERT + +/* define this if you have access to the quickscreen */ +#define HAVE_QUICKSCREEN +/* define this if you have access to the pitchscreen */ +#define HAVE_PITCHSCREEN + +/* define this if you would like tagcache to build on this target */ +#define HAVE_TAGCACHE + +/* define this if you have a flash memory storage */ +#define HAVE_FLASH_STORAGE + +/* LCD dimensions */ +#define LCD_WIDTH 128 +#define LCD_HEIGHT 64 +#define LCD_DEPTH 1 + +#define LCD_PIXELFORMAT VERTICAL_PACKING + +/* define this to indicate your device's keypad */ +#define CONFIG_KEYPAD LOGIK_DAX_PAD + +/* define this if you have a real-time clock */ +#define CONFIG_RTC RTC_TCC77X + +/* define this if you have RTC RAM available for settings */ +//#define HAVE_RTC_RAM + +/* The number of bytes reserved for loadable plugins */ +#define PLUGIN_BUFFER_SIZE 0x8000 + +#define AB_REPEAT_ENABLE 1 + +/* Define this if you do software codec */ +#define CONFIG_CODEC SWCODEC + +/* Define this for LCD backlight available */ +#define HAVE_BACKLIGHT + +#define CONFIG_I2C I2C_TCC77X + +#define BATTERY_CAPACITY_DEFAULT 1500 /* default battery capacity */ +#define BATTERY_CAPACITY_MIN 1500 /* min. capacity selectable */ +#define BATTERY_CAPACITY_MAX 3200 /* max. capacity selectable */ +#define BATTERY_CAPACITY_INC 50 /* capacity increment */ +#define BATTERY_TYPES_COUNT 1 /* only one type */ + +/* define this if the unit should not shut down on low battery. */ +#define NO_LOW_BATTERY_SHUTDOWN + +#ifndef SIMULATOR + +/* Define this if you have a TCC773L */ +#define CONFIG_CPU TCC773L + +/* Define this if you have ATA power-off control */ +#define HAVE_ATA_POWER_OFF + +/* Define this to the CPU frequency */ +#define CPU_FREQ 120000000 + +/* Offset ( in the firmware file's header ) to the file length */ +#define FIRMWARE_OFFSET_FILE_LENGTH 0 + +/* Offset ( in the firmware file's header ) to the file CRC */ +#define FIRMWARE_OFFSET_FILE_CRC 4 + +/* Offset ( in the firmware file's header ) to the real data */ +#define FIRMWARE_OFFSET_FILE_DATA 6 + +/* The start address index for ROM builds */ +/* #define ROM_START 0x11010 for behind original Archos */ +#define ROM_START 0x7010 /* for behind BootBox */ + +/* Software controlled LED */ +#define CONFIG_LED LED_VIRTUAL + +#define CONFIG_LCD LCD_SSD1815 + +#define BOOTFILE_EXT "logik" +#define BOOTFILE "rockbox." BOOTFILE_EXT +#define BOOTDIR "/" + +#endif /* SIMULATOR */ diff --git a/firmware/export/config.h b/firmware/export/config.h index 05938d14ec..538c75d08a 100644 --- a/firmware/export/config.h +++ b/firmware/export/config.h @@ -51,6 +51,8 @@ #define DSC25 25 #define DM320 320 #define IMX31L 31 +#define TCC771L 771 +#define TCC773L 773 /* CONFIG_KEYPAD */ #define PLAYER_PAD 1 @@ -71,6 +73,8 @@ #define ARCHOS_AV300_PAD 16 #define MROBE500_PAD 17 #define GIGABEAT_S_PAD 18 +#define LOGIK_DAX_PAD 19 +#define IAUDIO67_PAD 20 /* CONFIG_REMOTE_KEYPAD */ #define H100_REMOTE 1 @@ -103,6 +107,8 @@ #define LCD_DSC25 16 /* as used by Archos AV300 */ #define LCD_C200 17 /* as used by Sandisk Sansa c200 */ #define LCD_MROBE500 18 /* as used by Olympus M:Robe 500i */ +#define LCD_LOGIKDAX 19 /* as used by Logik DAX - SSD1815 */ +#define LCD_IAUDIO67 20 /* as used by iAudio 6/7 - unknown */ /* LCD_PIXELFORMAT */ #define HORIZONTAL_PACKING 1 @@ -122,6 +128,7 @@ #define I2C_S3C2440 7 #define I2C_PP5024 8 /* PP5024 style */ #define I2C_IMX31L 9 +#define I2C_TCC77X 10 /* CONFIG_LED */ #define LED_REAL 1 /* SW controlled LED (Archos recorders, player) */ @@ -141,6 +148,7 @@ #define RTC_DS1339_DS3231 7 /* h1x0 RTC mod */ #define RTC_IMX31L 8 #define RTC_RX5X348AB 9 +#define RTC_TCC77X 10 /* USB On-the-go */ #define USBOTG_ISP1362 1362 /* iriver H300 */ @@ -210,6 +218,10 @@ #include "config-tpj1022.h" #elif defined(MROBE_500) #include "config-mrobe500.h" +#elif defined(LOGIK_DAX) +#include "config-logikdax.h" +#elif defined(IAUDIO_7) +#include "config-iaudio7.h" #else /* no known platform */ #endif @@ -309,6 +321,11 @@ #define CPU_PP502x #endif +/* define for all cpus from TCC77X family */ +#if (CONFIG_CPU == TCC771L) || (CONFIG_CPU == TCC773L) +#define CPU_TCC77X +#endif + /* define for all cpus from ARM7TDMI family (for specific optimisations) */ #if defined(CPU_PP) || (CONFIG_CPU == PNX0101) || (CONFIG_CPU == DSC25) #define CPU_ARM7TDMI @@ -316,7 +333,8 @@ /* define for all cpus from ARM family */ #if defined(CPU_PP) || (CONFIG_CPU == PNX0101) || (CONFIG_CPU == S3C2440) \ - || (CONFIG_CPU == DSC25) || (CONFIG_CPU == IMX31L) || (CONFIG_CPU == DM320) + || (CONFIG_CPU == DSC25) || (CONFIG_CPU == IMX31L) || (CONFIG_CPU == DM320) \ + || defined(CPU_TCC77X) #define CPU_ARM #endif @@ -342,6 +360,7 @@ (((CONFIG_CPU == SH7034) && !defined(PLUGIN)) || /* SH1 archos: core only */ \ defined(CPU_COLDFIRE) || /* Coldfire: core, plugins, codecs */ \ defined(CPU_PP) || /* PortalPlayer: core, plugins, codecs */ \ + defined(CPU_TCC77X) || /* Telechips: core, plugins, codecs */ \ (CONFIG_CPU == PNX0101)) #define ICODE_ATTR __attribute__ ((section(".icode"))) #define ICONST_ATTR __attribute__ ((section(".irodata"))) diff --git a/firmware/export/cpu.h b/firmware/export/cpu.h index 893e7ffaa8..84229378ec 100644 --- a/firmware/export/cpu.h +++ b/firmware/export/cpu.h @@ -48,3 +48,6 @@ #if CONFIG_CPU == IMX31L #include "imx31l.h" #endif +#ifdef CPU_TCC77X +#include "tcc77x.h" +#endif diff --git a/firmware/export/tcc77x.h b/firmware/export/tcc77x.h new file mode 100644 index 0000000000..1ab1888649 --- /dev/null +++ b/firmware/export/tcc77x.h @@ -0,0 +1,81 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2007 Dave Chapman + * + * 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 __TCC77X_H__ +#define __TCC77X_H__ + +/* General-purpose IO */ + +#define GPIOA (*(volatile unsigned long *)0x80000300) +#define GPIOB (*(volatile unsigned long *)0x80000310) +#define GPIOC (*(volatile unsigned long *)0x80000320) +#define GPIOD (*(volatile unsigned long *)0x80000330) +#define GPIOE (*(volatile unsigned long *)0x80000340) + +#define GPIOA_DIR (*(volatile unsigned long *)0x80000304) +#define GPIOB_DIR (*(volatile unsigned long *)0x80000314) +#define GPIOC_DIR (*(volatile unsigned long *)0x80000324) +#define GPIOD_DIR (*(volatile unsigned long *)0x80000334) +#define GPIOE_DIR (*(volatile unsigned long *)0x80000344) + +#define GPIOA_FUNC (*(volatile unsigned long *)0x80000308) +#define GPIOB_FUNC (*(volatile unsigned long *)0x80000318) +#define GPIOC_FUNC (*(volatile unsigned long *)0x80000328) +#define GPIOD_FUNC (*(volatile unsigned long *)0x80000338) +#define GPIOE_FUNC (*(volatile unsigned long *)0x80000348) + +#define BMI (*(volatile unsigned long *)0x80000364) + +/* Clock Generator */ + +#define CLKCTRL (*(volatile unsigned long *)0x80000400) +#define PLL0CFG (*(volatile unsigned long *)0x80000404) +#define CLKDIV0 (*(volatile unsigned long *)0x8000040c) +#define MODECTR (*(volatile unsigned long *)0x80000410) +#define BCLKCTR (*(volatile unsigned long *)0x80000414) +#define SWRESET (*(volatile unsigned long *)0x80000418) +#define PCLKCFG0 (*(volatile unsigned long *)0x8000041c) +#define PCLKCFG1 (*(volatile unsigned long *)0x80000420) +#define PCLKCFG2 (*(volatile unsigned long *)0x80000424) +#define PCLKCFG3 (*(volatile unsigned long *)0x80000428) +#define PCLKCFG4 (*(volatile unsigned long *)0x8000042c) +#define PCLKCFG5 (*(volatile unsigned long *)0x80000430) +#define PCLKCFG6 (*(volatile unsigned long *)0x80000434) + +/* ADC */ + +#define ADCCON (*(volatile unsigned long *)0x80000a00) +#define ADCDATA (*(volatile unsigned long *)0x80000a04) +#define ADCCONA (*(volatile unsigned long *)0x80000a80) +#define ADCSTATUS (*(volatile unsigned long *)0x80000a84) +#define ADCCFG (*(volatile unsigned long *)0x80000a88) + + +/* Memory Controller */ +#define SDCFG (*(volatile unsigned long *)0xf0000000) +#define SDFSM (*(volatile unsigned long *)0xf0000004) +#define MCFG (*(volatile unsigned long *)0xf0000008) +#define TST (*(volatile unsigned long *)0xf000000c) +#define CSCFG0 (*(volatile unsigned long *)0xf0000010) +#define CSCFG1 (*(volatile unsigned long *)0xf0000014) +#define CSCFG2 (*(volatile unsigned long *)0xf0000018) +#define CSCFG3 (*(volatile unsigned long *)0xf000001c) +#define CLKCFG (*(volatile unsigned long *)0xf0000020) +#define SDCMD (*(volatile unsigned long *)0xf0000024) + +#endif diff --git a/firmware/target/arm/tcc77x/adc-tcc77x.c b/firmware/target/arm/tcc77x/adc-tcc77x.c new file mode 100644 index 0000000000..d6d97aaf84 --- /dev/null +++ b/firmware/target/arm/tcc77x/adc-tcc77x.c @@ -0,0 +1,71 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2007 by Dave Chapman + * + * 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 "string.h" +#include "adc.h" + +/* + TODO: We probably want to do this on the timer interrupt once we get + interrupts going - see the sh-adc.c implementation for an example which + looks like it should work well with the TCC77x. +*/ + +static unsigned short adcdata[8]; + +static void adc_do_read(void) +{ + int i; + uint32_t adc_status; + + PCLKCFG6 |= (1<<15); /* Enable ADC clock */ + + /* Start converting the first 4 channels */ + for (i = 0; i < 4; i++) + ADCCON = i; + + /* Wait for data to become stable */ + while ((ADCDATA & 0x1) == 0); + + /* Now read the values back */ + for (i=0;i < 4; i++) { + adc_status = ADCSTATUS; + adcdata[(adc_status >> 16) & 0x7] = adc_status & 0x3ff; + } + + PCLKCFG6 &= ~(1<<15); /* Disable ADC clock */ +} + +unsigned short adc_read(int channel) +{ + adc_do_read(); + + return adcdata[channel]; +} + +void adc_init(void) +{ + int i; + + ADCCON = (1<<4); /* Leave standby mode */ + ADCCFG |= 0x00000003; /* Single-mode, auto power-down */ +} diff --git a/firmware/target/arm/tcc77x/ata-nand-tcc77x.c b/firmware/target/arm/tcc77x/ata-nand-tcc77x.c new file mode 100644 index 0000000000..dd0ae7a950 --- /dev/null +++ b/firmware/target/arm/tcc77x/ata-nand-tcc77x.c @@ -0,0 +1,94 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2007 Dave Chapman + * + * 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 "ata.h" +#include "ata-target.h" +#include "ata_idle_notify.h" +#include "system.h" +#include +#include "thread.h" +#include "led.h" +#include "disk.h" +#include "panic.h" +#include "usb.h" + +/* for compatibility */ +int ata_spinup_time = 0; + +long last_disk_activity = -1; + +/** static, private data **/ +static bool initialized = false; + +static long next_yield = 0; +#define MIN_YIELD_PERIOD 2000 + +/* API Functions */ + +void ata_led(bool onoff) +{ + led(onoff); +} + +int ata_read_sectors(IF_MV2(int drive,) unsigned long start, int incount, + void* inbuf) +{ + +} + +int ata_write_sectors(IF_MV2(int drive,) unsigned long start, int count, + const void* outbuf) +{ +} + +void ata_spindown(int seconds) +{ + (void)seconds; +} + +bool ata_disk_is_active(void) +{ + return 0; +} + +void ata_sleep(void) +{ +} + +void ata_spin(void) +{ +} + +/* Hardware reset protocol as specified in chapter 9.1, ATA spec draft v5 */ +int ata_hard_reset(void) +{ + return 0; +} + +int ata_soft_reset(void) +{ + return 0; +} + +void ata_enable(bool on) +{ +} + +int ata_init(void) +{ +} diff --git a/firmware/target/arm/tcc77x/ata-target.h b/firmware/target/arm/tcc77x/ata-target.h new file mode 100644 index 0000000000..79ac638de1 --- /dev/null +++ b/firmware/target/arm/tcc77x/ata-target.h @@ -0,0 +1,22 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2007 Dave Chapman + * + * 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 + +#endif diff --git a/firmware/target/arm/tcc77x/crt0.S b/firmware/target/arm/tcc77x/crt0.S new file mode 100644 index 0000000000..e4ecb05a4e --- /dev/null +++ b/firmware/target/arm/tcc77x/crt0.S @@ -0,0 +1,153 @@ +/*************************************************************************** + * __________ __ ___. + * 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. + * + ****************************************************************************/ + +/* Arm bootloader and startup code based on startup.s from the iPodLinux loader + * + * Copyright (c) 2003, Daniel Palffy (dpalffy (at) rainstorm.org) + * Copyright (c) 2005, Bernard Leach + * + */ + +#include "config.h" +#include "cpu.h" + + .section .init.text,"ax",%progbits + + .global start + +/* Telechips firmware files start with a 32-byte header, as part of the code. */ + +start: +#ifdef TCCBOOT + /* Add -DTCCBOOT to EXTRA_DEFINES in the bootloader Makefile to + enable building the bootloader to be appended to the end of the + original firmware, dual-booting based on a key-press. + + The following two values are filled in by mktccboot. + */ + .word 0 /* Saved entrypoint of original firmware*/ + .word 0 /* Location in RAM of the start of our bootloader */ +#else + ldr pc, =start_loc /* jump to the main entry point */ + + .word 0xffff0601 /* Unknown magic */ + .word 0x3a726556 /* "Ver:" */ + .word 0x31373030 /* "0071" */ + .word 0 /* First CRC32 */ + .word 0 /* Unknown - always 0 */ + .word 0 /* Second CRC32 */ + .word 0 /* length of firmware file */ + +#ifdef LOGIK_DAX + /* Some original firmwares have 0x40 bytes of zeroes here - we + don't know why, but err on the side of caution and include it + here. */ + .space 0x40 +#endif +#endif + +start_loc: + +#ifdef BOOTLOADER +#ifdef TCCBOOT +#ifdef LOGIK_DAX + mov r0, #0x80000000 + ldr r0, [r0, #0x300] /* Read GPIO A */ + tst r0, #0x2 + ldrne pc, [pc, #-28] /* Jump to original firmware if HOLD button not pressed */ +#else + #error No bootup key detection implemented for this target +#endif + + /* Copy bootloader to safe area - 0x21000000 (DRAM) */ + /* TODO: Adjust this for other targets - DRAM + DRAMSIZE - 0x100000 */ + ldr r0, [pc, #-28] + mov r1, #0x20000000 + add r1, r1, #0x100000 + ldr r2, =_dataend +1: + cmp r2, r1 + ldrhi r3, [r0], #4 + strhi r3, [r1], #4 + bhi 1b + + ldr pc, =copied_start /* jump to the relocated start_loc: */ + +copied_start: +#endif +#else + /* We don't use interrupts in the bootloader */ + + /* Set up stack for IRQ mode */ + mov r0,#0xd2 + msr cpsr, r0 + ldr sp, =irq_stack + /* Set up stack for FIQ mode */ + mov r0,#0xd1 + msr cpsr, r0 + ldr sp, =fiq_stack + + /* Let abort and undefined modes use IRQ stack */ + mov r0,#0xd7 + msr cpsr, r0 + ldr sp, =irq_stack + mov r0,#0xdb + msr cpsr, r0 + ldr sp, =irq_stack +#endif + + /* Switch to supervisor mode */ + mov r0,#0xd3 + msr cpsr, r0 + ldr sp, =stackend + + /* Initialise bss section to zero */ + ldr r2, =_edata + ldr r3, =_end + mov r4, #0 +1: + cmp r3, r2 + strhi r4, [r2], #4 + bhi 1b + + /* Set up some stack and munge it with 0xdeadbeef */ + ldr sp, =stackend + mov r3, sp + ldr r2, =stackbegin + ldr r4, =0xdeadbeef +1: + cmp r3, r2 + strhi r4, [r2], #4 + bhi 1b + + bl main + /* main() should never return */ + +#ifndef BOOTLOADER + /* We don't use interrupts in the bootloader */ + +/* 256 words of IRQ stack */ + .space 256*4 +irq_stack: + +/* 256 words of FIQ stack */ + .space 256*4 +fiq_stack: + +#endif diff --git a/firmware/target/arm/tcc77x/logikdax/adc-target.h b/firmware/target/arm/tcc77x/logikdax/adc-target.h new file mode 100644 index 0000000000..cfc8117a99 --- /dev/null +++ b/firmware/target/arm/tcc77x/logikdax/adc-target.h @@ -0,0 +1,26 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2007 Dave Chapman + * + * 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 _ADC_TARGET_H_ +#define _ADC_TARGET_H_ + +#define NUM_ADC_CHANNELS 8 + +#define ADC_BUTTONS 0 + +#endif /* _ADC_TARGET_H_ */ diff --git a/firmware/target/arm/tcc77x/logikdax/backlight-target.h b/firmware/target/arm/tcc77x/logikdax/backlight-target.h new file mode 100644 index 0000000000..4714f22aa3 --- /dev/null +++ b/firmware/target/arm/tcc77x/logikdax/backlight-target.h @@ -0,0 +1,38 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2007 by Dave Chapman + * + * 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 + +#include "tcc77x.h" + +#define __backlight_init() true + +static inline void __backlight_on(void) +{ + /* Enable backlight */ + GPIOD |= 0x10; +} + +static inline void __backlight_off(void) +{ + /* Disable backlight */ + GPIOD &= ~0x10; +} + +#endif diff --git a/firmware/target/arm/tcc77x/logikdax/button-target.h b/firmware/target/arm/tcc77x/logikdax/button-target.h new file mode 100644 index 0000000000..2925a423b6 --- /dev/null +++ b/firmware/target/arm/tcc77x/logikdax/button-target.h @@ -0,0 +1,70 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2007 by Dave Chapman + * + * 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 _BUTTON_TARGET_H_ +#define _BUTTON_TARGET_H_ + +#include +#include "config.h" + +/* + +Results of button testing: + +HOLD: GPIOA & 0x0002 (0=pressed, 0x0002 = released) +POWER: GPIOA & 0x8000 (0=pressed, 0x8000 = released) + +ADC[0]: (approx values) + +RIGHT - 0x37 +LEFT - 0x7f +JOYSTICK PRESS - 0xc7 +UP - 0x11e +DOWN - 0x184 +MODE - 0x1f0/0x1ff +PRESET - 0x268/0x269 +TIMESHIFT - 0x2dd + +Values of ADC[0] tested in OF disassembly: 0x50, 0x96, 0xdc, 0x208, 0x384 + +*/ + + +void button_init_device(void); +int button_read_device(void); + +/* Main unit's buttons */ +#define BUTTON_POWERPLAY 0x00000001 +#define BUTTON_MODE 0x00000002 +#define BUTTON_HOLD 0x00000004 +#define BUTTON_REC 0x00000008 +#define BUTTON_PRESET 0x00000010 +#define BUTTON_LEFT 0x00000020 +#define BUTTON_RIGHT 0x00000040 +#define BUTTON_UP 0x00000080 +#define BUTTON_DOWN 0x00000100 +#define BUTTON_SELECT 0x00000200 + +#define BUTTON_MAIN (BUTTON_POWERPLAY|BUTTON_MODE|BUTTON_HOLD\ + |BUTTON_REC|BUTTON_PRESET|BUTTON_LEFT\ + |BUTTON_RIGHT|BUTTON_UP|BUTTON_DOWN|BUTTON_SELECT) + +#define BUTTON_REMOTE 0 + +#endif /* _BUTTON_TARGET_H_ */ diff --git a/firmware/target/arm/tcc77x/logikdax/lcd-logikdax.c b/firmware/target/arm/tcc77x/logikdax/lcd-logikdax.c new file mode 100644 index 0000000000..973d4cb333 --- /dev/null +++ b/firmware/target/arm/tcc77x/logikdax/lcd-logikdax.c @@ -0,0 +1,253 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2002 by Alan Korr + * + * 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 "hwcompat.h" +#include "kernel.h" +#include "lcd.h" +#include "system.h" +#include "cpu.h" + +/*** definitions ***/ + +#define LCD_SET_LOWER_COLUMN_ADDRESS ((char)0x00) +#define LCD_SET_HIGHER_COLUMN_ADDRESS ((char)0x10) +#define LCD_SET_INTERNAL_REGULATOR_RESISTOR_RATIO ((char)0x20) +#define LCD_SET_POWER_CONTROL_REGISTER ((char)0x28) +#define LCD_SET_DISPLAY_START_LINE ((char)0x40) +#define LCD_SET_CONTRAST_CONTROL_REGISTER ((char)0x81) +#define LCD_SET_SEGMENT_REMAP ((char)0xA0) +#define LCD_SET_LCD_BIAS ((char)0xA2) +#define LCD_SET_ENTIRE_DISPLAY_OFF ((char)0xA4) +#define LCD_SET_ENTIRE_DISPLAY_ON ((char)0xA5) +#define LCD_SET_NORMAL_DISPLAY ((char)0xA6) +#define LCD_SET_REVERSE_DISPLAY ((char)0xA7) +#define LCD_SET_MULTIPLEX_RATIO ((char)0xA8) +#define LCD_SET_BIAS_TC_OSC ((char)0xA9) +#define LCD_SET_1OVER4_BIAS_RATIO ((char)0xAA) +#define LCD_SET_INDICATOR_OFF ((char)0xAC) +#define LCD_SET_INDICATOR_ON ((char)0xAD) +#define LCD_SET_DISPLAY_OFF ((char)0xAE) +#define LCD_SET_DISPLAY_ON ((char)0xAF) +#define LCD_SET_PAGE_ADDRESS ((char)0xB0) +#define LCD_SET_COM_OUTPUT_SCAN_DIRECTION ((char)0xC0) +#define LCD_SET_TOTAL_FRAME_PHASES ((char)0xD2) +#define LCD_SET_DISPLAY_OFFSET ((char)0xD3) +#define LCD_SET_READ_MODIFY_WRITE_MODE ((char)0xE0) +#define LCD_SOFTWARE_RESET ((char)0xE2) +#define LCD_NOP ((char)0xE3) +#define LCD_SET_END_OF_READ_MODIFY_WRITE_MODE ((char)0xEE) + +/* LCD command codes */ +#define LCD_CNTL_RESET 0xe2 /* Software reset */ +#define LCD_CNTL_POWER 0x2f /* Power control */ +#define LCD_CNTL_CONTRAST 0x81 /* Contrast */ +#define LCD_CNTL_OUTSCAN 0xc8 /* Output scan direction */ +#define LCD_CNTL_SEGREMAP 0xa1 /* Segment remap */ +#define LCD_CNTL_DISPON 0xaf /* Display on */ + +#define LCD_CNTL_PAGE 0xb0 /* Page address */ +#define LCD_CNTL_HIGHCOL 0x10 /* Upper column address */ +#define LCD_CNTL_LOWCOL 0x00 /* Lower column address */ + +/* TCC77x specific defines */ +#define LCD_BASE 0x50000000 +#define LCD_CMD *(volatile unsigned char*)(LCD_BASE) +#define LCD_DATA *(volatile unsigned char*)(LCD_BASE+1) + +void lcd_write_command(int byte) +{ + LCD_CMD = byte; + + asm volatile ( + "nop \n\t" + "nop \n\t" + "nop \n\t" + ); +} + +void lcd_write_data(const fb_data* p_bytes, int count) +{ + while (count--) + { + LCD_DATA = *(p_bytes++); + + asm volatile ( + "nop \n\t" + "nop \n\t" + "nop \n\t" + ); + } +} + +/* End of TCC77x specific defines */ + + +/** globals **/ + +static int xoffset; /* needed for flip */ + +/*** hardware configuration ***/ + +int lcd_default_contrast(void) +{ + return 0x1f; +} + +void lcd_set_contrast(int val) +{ + lcd_write_command(LCD_CNTL_CONTRAST); + lcd_write_command(val); +} + +void lcd_set_invert_display(bool yesno) +{ + if (yesno) + lcd_write_command(LCD_SET_REVERSE_DISPLAY); + else + lcd_write_command(LCD_SET_NORMAL_DISPLAY); +} + +/* turn the display upside down (call lcd_update() afterwards) */ +void lcd_set_flip(bool yesno) +{ + /* TODO: flip mode isn't working. The commands in the else part of + this function are how the original firmware inits the LCD */ + + if (yesno) + { + lcd_write_command(LCD_SET_SEGMENT_REMAP | 0x01); + lcd_write_command(LCD_SET_COM_OUTPUT_SCAN_DIRECTION); + xoffset = 132 - LCD_WIDTH; /* 132 colums minus the 128 we have */ + } + else + { + lcd_write_command(LCD_SET_SEGMENT_REMAP); + lcd_write_command(LCD_SET_COM_OUTPUT_SCAN_DIRECTION | 0x08); + xoffset = 0; + } +} + + +/* LCD init */ +void lcd_init_device(void) +{ + uint32_t bus_width; + + /* Telechips init the same as the original firmware */ + CSCFG1 &= 0xc3ffc000; + CSCFG1 |= 0x3400101a; + CSCFG1 |= (1 << 21); + CSCFG1 &= ~(1 << 21); + + bus_width = ((MCFG >> 11) & 0x3) ^ 3; + + CSCFG1 = (bus_width << 28) | + (3 << 26) | /* MTYPE = 3 */ + ((LCD_BASE >> 28) << 22) | /* CSBASE = 0x5 */ + (1 << 20) | /* Unknown */ + (3 << 11) | /* Setup time = 3 cycles */ + (3 << 3) | /* Pulse width = 3+1 cycles */ + (1 << 0); /* Hold time = 1 cycle */ + + /* SSD1815 inits like the original firmware */ + lcd_write_command(LCD_SET_DISPLAY_OFF); + lcd_set_flip(false); + lcd_write_command(LCD_SET_INTERNAL_REGULATOR_RESISTOR_RATIO | 5); + lcd_set_contrast(lcd_default_contrast()); + lcd_write_command(LCD_SET_POWER_CONTROL_REGISTER | 7); + /* power control register: op-amp=1, regulator=1, booster=1 */ + lcd_write_command(LCD_SET_BIAS_TC_OSC); + + /* 0xc2 = 110 000 10: Osc. Freq 110 - ??? + TC value 000 - "-0.01%/C (TC0, POR)" + Bias ratio 10 - "1/9, 1/7 (POR)" + */ + lcd_write_command(0xc2); + lcd_write_command(LCD_SET_DISPLAY_ON); + + lcd_clear_display(); + lcd_update(); +} + +/*** Update functions ***/ + +/* Performance function that works with an external buffer + note that by and bheight are in 8-pixel units! */ +void lcd_blit(const unsigned char* data, int x, int by, int width, + int bheight, int stride) +{ + /* Copy display bitmap to hardware */ + while (bheight--) + { + lcd_write_command (LCD_CNTL_PAGE | (by++ & 0xf)); + lcd_write_command (LCD_CNTL_HIGHCOL | (((x+xoffset)>>4) & 0xf)); + lcd_write_command (LCD_CNTL_LOWCOL | ((x+xoffset) & 0xf)); + + lcd_write_data(data, width); + data += stride; + } +} + + +/* Update the display. + This must be called after all other LCD functions that change the display. */ +void lcd_update(void) ICODE_ATTR; +void lcd_update(void) +{ + int y; + + /* Copy display bitmap to hardware */ + for (y = 0; y < LCD_FBHEIGHT; y++) + { + lcd_write_command (LCD_CNTL_PAGE | (y & 0xf)); + lcd_write_command (LCD_CNTL_HIGHCOL | ((xoffset >> 4) & 0xf)); + lcd_write_command (LCD_CNTL_LOWCOL | (xoffset & 0xf)); + + lcd_write_data (lcd_framebuffer[y], LCD_WIDTH); + } +} + +/* Update a fraction of the display. */ +void lcd_update_rect(int, int, int, int) ICODE_ATTR; +void lcd_update_rect(int x, int y, int width, int height) +{ + int ymax; + + /* The Y coordinates have to work on even 8 pixel rows */ + ymax = (y + height-1) >> 3; + y >>= 3; + + if(x + width > LCD_WIDTH) + width = LCD_WIDTH - x; + if (width <= 0) + return; /* nothing left to do, 0 is harmful to lcd_write_data() */ + if(ymax >= LCD_FBHEIGHT) + ymax = LCD_FBHEIGHT-1; + + /* Copy specified rectange bitmap to hardware */ + for (; y <= ymax; y++) + { + lcd_write_command (LCD_CNTL_PAGE | (y & 0xf)); + lcd_write_command (LCD_CNTL_HIGHCOL | (((x+xoffset) >> 4) & 0xf)); + lcd_write_command (LCD_CNTL_LOWCOL | ((x+xoffset) & 0xf)); + + lcd_write_data (&lcd_framebuffer[y][x], width); + } +} diff --git a/firmware/target/arm/tcc77x/logikdax/power-logikdax.c b/firmware/target/arm/tcc77x/logikdax/power-logikdax.c new file mode 100644 index 0000000000..df2ee10d6b --- /dev/null +++ b/firmware/target/arm/tcc77x/logikdax/power-logikdax.c @@ -0,0 +1,66 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2007 Dave Chapman + * + * 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" + +#ifndef SIMULATOR + +void power_init(void) +{ +} + +void ide_power_enable(bool on) +{ +} + +bool ide_powered(void) +{ + return true; +} + +void power_off(void) +{ +} + +#else /* SIMULATOR */ + +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; +} + +#endif /* SIMULATOR */ diff --git a/firmware/target/arm/tcc77x/system-target.h b/firmware/target/arm/tcc77x/system-target.h new file mode 100644 index 0000000000..0df92e3263 --- /dev/null +++ b/firmware/target/arm/tcc77x/system-target.h @@ -0,0 +1,35 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2007 by Dave Chapman + * + * 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 SYSTEM_TARGET_H +#define SYSTEM_TARGET_H + +#include "system-arm.h" + +#define CPUFREQ_DEFAULT 98784000 +#define CPUFREQ_NORMAL 98784000 +#define CPUFREQ_MAX 120000000 + +#define inl(a) (*(volatile unsigned long *) (a)) +#define outl(a,b) (*(volatile unsigned long *) (b) = (a)) +#define inb(a) (*(volatile unsigned char *) (a)) +#define outb(a,b) (*(volatile unsigned char *) (b) = (a)) +#define inw(a) (*(volatile unsigned short *) (a)) +#define outw(a,b) (*(volatile unsigned short *) (b) = (a)) + +#endif /* SYSTEM_TARGET_H */ diff --git a/firmware/target/arm/tcc77x/system-tcc77x.c b/firmware/target/arm/tcc77x/system-tcc77x.c new file mode 100644 index 0000000000..baa1641c78 --- /dev/null +++ b/firmware/target/arm/tcc77x/system-tcc77x.c @@ -0,0 +1,136 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2007 by Dave Chapman + * + * 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 "kernel.h" +#include "system.h" +#include "panic.h" + +void system_reboot(void) +{ +} + +/* TODO - these should live in the target-specific directories and + once we understand what all the GPIO pins do, move the init to the + specific driver for that hardware. For now, we just perform the + same GPIO init as the original firmware - this makes it easier to + investigate what the GPIO pins do. +*/ + +#ifdef LOGIK_DAX +static void gpio_init(void) +{ + /* Do what the original firmware does */ + GPIOD_FUNC = 0; + GPIOD_DIR = 0x3f0; + GPIOD = 0xe0; + GPIOE_FUNC = 0; + GPIOE_DIR = 0xe0; + GPIOE = 0; + GPIOA_FUNC = 0; + GPIOA_DIR = 0xffff1000; /* 0 - 0xf000 */ + GPIOA = 0x1080; + GPIOB_FUNC = 0x16a3; + GPIOB_DIR = 0x6ffff; + GPIOB = 0; + GPIOC_FUNC = 1; + GPIOC_DIR = 0x03ffffff; /* mvn r2, 0xfc000000 */ + GPIOC = 0; +} +#elif defined(IAUDIO_7) +static void gpio_init(void) +{ + /* Do what the original firmware does */ + GPIOA_FUNC = 0; + GPIOB_FUNC = 0x1623; + GPIOC_FUNC = 1; + GPIOD_FUNC = 0; + GPIOE_FUNC = 0; + GPIOA = 0x30; + GPIOB = 0x80000; + GPIOC = 0; + GPIOD = 0x180; + GPIOE = 0; + GPIOA_DIR = 0x84b0 + GPIOB_DIR = 0x80800; + GPIOC_DIR = 0x2000000; + GPIOD_DIR = 0x3e3; + GPIOE_DIR = 0x88; +} +#endif + +/* Second function called in the original firmware's startup code - we just + set up the clocks in the same way as the original firmware for now. */ +static void clock_init(void) +{ + unsigned int i; + + CSCFG3 = (CSCFG3 &~ 0x3fff) | 0x820; + + CLKCTRL = (CLKCTRL & ~0xff) | 0x14; + + if (BMI & 0x20) + PCLKCFG0 = 0xc82d7000; + else + PCLKCFG0 = 0xc8ba7000; + + MCFG |= 0x2000; + +#ifdef LOGIK_DAX + /* Only seen in the Logik DAX original firmware */ + SDCFG = (SDCFG & ~0x7000) | 0x2000; +#endif + + PLL0CFG |= 0x80000000; + + PLL0CFG = 0x0000cf13; + + i = 8000; + while (--i) {}; + + CLKDIV0 = 0x81000000; + CLKCTRL = 0x80000010; + + asm volatile ( + "nop \n\t" + "nop \n\t" + ); +} + + +void system_init(void) +{ + /* TODO: cache init - the original firmwares have cache init code which + is called at the very start of the firmware */ + clock_init(); + gpio_init(); +} + +int system_memory_guard(int newmode) +{ + (void)newmode; + return 0; +} + +#ifdef HAVE_ADJUSTABLE_CPU_FREQ + +void set_cpu_frequency(long frequency) +{ +} + +#endif diff --git a/firmware/thread.c b/firmware/thread.c index 896cc0fb3d..4bcea0542d 100644 --- a/firmware/thread.c +++ b/firmware/thread.c @@ -651,6 +651,11 @@ static inline void core_sleep(struct thread_entry **waking) "msr cpsr_c, r0 \n" : : "r"(waking) : "r0", "r1", "r2", "r3"); } +#elif defined(CPU_TCC77X) +static inline void core_sleep(struct thread_entry **waking) +{ + #warning TODO: Implement core_sleep +} #else static inline void core_sleep(struct thread_entry **waking) { diff --git a/tools/Makefile b/tools/Makefile index 347b113287..f45c5df036 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -11,7 +11,7 @@ LDFLAGS := -g CLEANALL := scramble descramble iriver sh2d bmp2rb rdf2binary convbdf \ generate_rocklatin mkboot ipod_fw codepages uclpack mi4 gigabeat database \ - lngdump telechips gigabeats + lngdump telechips gigabeats mktccboot all: @echo "Run make in your build directory!" @@ -38,6 +38,9 @@ rdf2binary: rdf2binary.c mkboot: mkboot.c $(SILENT)$(CC) -g $+ -o $@ +mktccboot: mktccboot.c telechips.o + $(SILENT)$(CC) -g $+ -o $@ + lngdump: lngdump.c $(SILENT)$(CC) -g $+ -o $@ diff --git a/tools/configure b/tools/configure index 1cc7e6220e..3971bcb2e4 100755 --- a/tools/configure +++ b/tools/configure @@ -212,6 +212,13 @@ arm9tdmicc () { endian="little" } +arm946cc () { + prefixtools arm-elf- + GCCOPTS="$CCOPTS -mcpu=arm9e -mlong-calls" + GCCOPTIMIZE="-fomit-frame-pointer" + endian="little" +} + whichadvanced () { ################################################################## # Prompt for specific developer options @@ -619,10 +626,10 @@ cat < ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2007 by Dave Chapman + * + * Based on mkboot, Copyright (C) 2005 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 +#include +#include +#include +#include +#include +#include +#include "telechips.h" + +/* + +Append a Rockbox bootloader to a Telechips original firmware file. + +The first instruction in a TCC firmware file is always of the form: + + ldr pc, [pc, #xxx] + +where [pc, #xxx] is the entry point of the firmware - e.g. 0x20000020 + +mktccboot appends the Rockbox bootloader to the end of the original +firmware image and replaces the contents of [pc, #xxx] with the entry +point of our bootloader - i.e. the length of the original firmware plus +0x20000000. + +It then stores the original entry point from [pc, #xxx] in a fixed +offset in the Rockbox boootloader, which is used by the bootloader to +dual-boot. + +Finally, mktccboot corrects the length and CRCs in the main firmware +header, creating a new legal firmware file which can be installed on +the device. + +*/ + +/* win32 compatibility */ + +#ifndef O_BINARY +#define O_BINARY 0 +#endif + +static void put_uint32le(uint32_t x, unsigned char* p) +{ + p[0] = x & 0xff; + p[1] = (x >> 8) & 0xff; + p[2] = (x >> 16) & 0xff; + p[3] = (x >> 24) & 0xff; +} + +static uint32_t get_uint32le(unsigned char* p) +{ + return (p[3] << 24) | (p[2] << 16) | (p[1]<<8) | p[0]; +} + +void usage(void) +{ + printf("Usage: mktccboot \n"); + + exit(1); +} + +off_t filesize(int fd) { + struct stat buf; + + if (fstat(fd,&buf) < 0) { + perror("[ERR] Checking filesize of input file"); + return -1; + } else { + return(buf.st_size); + } +} + + +int main(int argc, char *argv[]) +{ + char *infile, *bootfile, *outfile; + int fdin, fdboot,fdout; + int i,n; + int inlength,bootlength; + uint32_t ldr; + unsigned char* image; + int origoffset; + + if(argc < 3) { + usage(); + } + + infile = argv[1]; + bootfile = argv[2]; + outfile = argv[3]; + + fdin = open(infile, O_RDONLY|O_BINARY); + if (fdin < 0) + { + perror(infile); + } + + fdboot = open(bootfile, O_RDONLY|O_BINARY); + if (fdboot < 0) + { + perror(bootfile); + } + + inlength = filesize(fdin); + bootlength = filesize(fdboot); + + image = malloc(inlength + bootlength); + + if (image==NULL) + { + printf("[ERR] Could not allocate memory, aborting\n"); + return 1; + } + + n = read(fdin, image, inlength); + if (n != inlength) + { + printf("[ERR] Could not read from %s\n",infile); + return 2; + } + + n = read(fdboot, image + inlength, bootlength); + if (n != bootlength) + { + printf("[ERR] Could not read from %s\n",bootfile); + return 3; + } + + ldr = get_uint32le(image); + + /* TODO: Verify it's a LDR instruction */ + origoffset = (ldr&0xfff) + 8; + + printf("original firmware entry point: 0x%08x\n",get_uint32le(image + origoffset)); + printf("New entry point: 0x%08x\n",0x20000000 + inlength + 8); + + /* Save the original firmware entry point at the start of the bootloader image */ + put_uint32le(get_uint32le(image + origoffset),image+inlength); + put_uint32le(0x20000000 + inlength,image + inlength + 4); + + /* Change the original firmware entry point to the third word in our bootloader */ + put_uint32le(0x20000000 + inlength + 8,image+origoffset); + + + telechips_encode_crc(image, inlength + bootlength); + + fdout = open(outfile, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644); + if (fdout < 0) + { + perror(bootfile); + } + + n = write(fdout, image, inlength + bootlength); + if (n != inlength + bootlength) + { + printf("[ERR] Could not write output file %s\n",outfile); + return 3; + } + + close(fdin); + close(fdboot); + close(fdout); + + return 0; +}