Index: bootloader/creativezvm.c =================================================================== --- bootloader/creativezvm.c (revision 0) +++ bootloader/creativezvm.c (revision 0) @@ -0,0 +1,611 @@ +/*************************************************************************** +* __________ __ ___. +* Open \______ \ ____ ____ | | _\_ |__ _______ ___ +* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / +* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < +* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ +* \/ \/ \/ \/ \/ +* $Id$ +* +* Copyright (C) 2008 by Maurus Cuelenaere +* +* 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 "inttypes.h" +#include "string.h" +#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 "backlight.h" +#include "backlight-target.h" +#include "button.h" +#include "panic.h" +#include "power.h" +#include "file.h" +#include "common.h" +#include "rbunicode.h" +#include "usb.h" +#include "spi.h" +#include "uart-target.h" +#include "time.h" +#include "system-arm.h" +#include +#include "sprintf.h" +#include "memory.h" +#include "i2c-dm320.h" +#include "ata-target.h" +#include "timer.h" +#include "usb-target.h" +#include "isp1583.h" + +#define OF_firmware_load(mem_addr, size) asm volatile ( \ + "mov r1, %1\n" \ + "mov r0, %0\n" \ + "ldr pc, =0x1EE0000\n" \ + : \ + : "r"(mem_addr), "r"(size)\ + ); + +void i2c_reading(void){ + + reset_screen(); + printf("Starting I2C reading..."); + + unsigned char test[16]; + unsigned char msg[40]; + int i, j, ret; + bool flag; + while(true){ + for(i=0;i<0x7F;i++){ //max=7-bit + snprintf(msg, sizeof(char)*20, "0x%x ", i); + lcd_putsxy(260, 0, msg); + lcd_update(); + ret = i2c_read(i, test, 16); + flag = false; + for(j=0;j<16;j++){ + if((test[j]!=0xFF) & (test[j]!=0)) + flag = true; + } + if(flag){ + snprintf(msg, sizeof(char)*40, "%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x", + test[0], test[1], test[2], test[3], test[4], + test[5], test[6], test[7], test[8], test[9], + test[10], test[11], test[12], test[13], test[14], + test[15]); + printf("0x%x: %s [%d]", i, msg, ret); + } + asm volatile("nop\nnop\nnop\nnop\nnop\nnop\nnop\n"); + } + } +} + +void dbg_dump_buffer(unsigned char *buf, int len, bool hex_mode) +{ + int i, j; + unsigned char c; + unsigned char ascii[60]; + + if(hex_mode) + { + for(i = 0; i < len/26; i++) + { + for(j = 0; j < 26; j++) + snprintf(&ascii[j*2], 3, "%02x", buf[i*26+j]); + printf("%s", ascii); + } + } + else + { + for(i = 0;i < len/32; i++) + { + for(j = 0;j < 32; j++) + { + c = buf[i*32+j]; + + if(c < 32 || c > 127) + ascii[j] = '.'; + else + ascii[j] = c; + } + ascii[j] = 0; + printf("%s", ascii); + } + } +} + +static struct partition_struct +{ + unsigned int end; + unsigned int start; + char name[8]; +} partition_struct; + +static struct hdd_struct +{ + char MBLK[4]; + int block_size; + long long total_disk_size; + struct partition_struct minifs; + struct partition_struct cfs; +} hdd_struct; + +static struct __attribute__ ((aligned (32))) minifs_file +{ + char name[16]; + unsigned int unk; + unsigned int size; + unsigned int index; + unsigned int index2; +} minifs_file; + +void do_hdd_browsing(void) +{ + unsigned int i; + unsigned short* identify_info; + identify_info = ata_get_identify(); + reset_screen(); + printf("[ATA_IDENTIFY]"); + for(i=0;i<256;i+=16) + printf("%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x", + identify_info[i], identify_info[i+1], identify_info[i+2], identify_info[i+3],identify_info[i+4], identify_info[i+5], identify_info[i+6], identify_info[i+7], + identify_info[i+8], identify_info[i+9], identify_info[i+10], identify_info[i+11],identify_info[i+12], identify_info[i+13], identify_info[i+14], identify_info[i+15]); + while(button_read_device() ^ BUTTON_CUSTOM) + yield(); + unsigned char temp[512]; + char temp3[512]; + struct hdd_struct* temp2; + int j; + reset_screen(); + bool hex_mode = false, mode_changed = false; + ata_read_sectors(0, 1, &temp); + temp2 = (struct hdd_struct*)temp; + i = 0; + j = 1; + while(button_read_device() ^ BUTTON_BACK) + { + if(i!=j || mode_changed) + { + reset_screen(); + printf("---------------------------------------"); + #define _M(x) temp2->MBLK[x] + printf("[%c%c%c%c]", _M(3), _M(2), _M(1), _M(0)); + #undef _M + printf("-> %d * 0x%x -> 0x%x", temp2->block_size, temp2->total_disk_size, temp2->block_size*temp2->total_disk_size); + printf(" * [%s]: 0x%x -> 0x%x", temp2->minifs.name, temp2->minifs.start, temp2->minifs.end); + printf(" * [%s]: 0x%x -> 0x%x", temp2->cfs.name, temp2->cfs.start, temp2->cfs.end); + printf("---------------------------------------"); + printf("[CURRENTLY]: 0x%x * %d = 0x%x", i, temp2->block_size, i*temp2->block_size); + if(!mode_changed) + ata_read_sectors(i*temp2->block_size, 1, &temp3); + dbg_dump_buffer(temp3, 512, hex_mode); + mode_changed = false; + j = i; + } + if((button_read_device() & BUTTON_DOWN) && j==i) + i++; + else if((button_read_device() & BUTTON_UP) && j==i) + i--; + else if((button_read_device() & BUTTON_LEFT) && hex_mode) + { + hex_mode = false; + mode_changed = true; + } + else if(button_read_device() & BUTTON_MENU) + { + char msg[30]; + while(button_read_device() ^ BUTTON_PLAY) + { + if(button_read_device() & BUTTON_DOWN) + i+= 2 * (button_read_device() & BUTTON_HOLD ? 2 : 1); + else if(button_read_device() & BUTTON_UP) + i-= 2 * (button_read_device() & BUTTON_HOLD ? 2 : 1); + snprintf(msg, sizeof(char)*30, "0x%0x", i); + lcd_set_foreground(LCD_RGBPACK(200, 255, 0)); + lcd_putsxy(SYSFONT_WIDTH*12, SYSFONT_HEIGHT*6, msg); + lcd_update(); + } + lcd_set_foreground(LCD_BLACK); + } + else if((button_read_device() & BUTTON_RIGHT) && !hex_mode) + { + hex_mode = true; + mode_changed = true; + } + if(i*temp2->block_size > temp2->total_disk_size) + i = temp2->total_disk_size * temp2->block_size; + yield(); + } +} + +#define ACCESS_DATA(x) (*(volatile unsigned char *)(address + x)) +void do_data_browsing(unsigned int address) +{ + reset_screen(); + char msg[30]; + char put[4]; + unsigned int i=address, lasti=0; + int j,k,l; + while(true) + { + if((button_read_device() & BUTTON_DOWN) && lasti==i) + i+= LCD_WIDTH/(SYSFONT_WIDTH*2); + else if((button_read_device() & BUTTON_UP) && lasti==i) + i-= LCD_WIDTH/(SYSFONT_WIDTH*2); + else if(button_read_device() & BUTTON_MENU) + { + lcd_set_foreground(LCD_RGBPACK(100, 255, 0)); + while(button_read_device() ^ BUTTON_PLAY) + { + if(button_read_device() & BUTTON_DOWN) + i+= LCD_WIDTH/(SYSFONT_WIDTH*2); + else if(button_read_device() & BUTTON_UP) + i-= LCD_WIDTH/(SYSFONT_WIDTH*2); + snprintf(msg, sizeof(char)*30, "%0x", i); + lcd_putsxy(0, 0, msg); + lcd_update(); + } + lcd_set_foreground(LCD_BLACK); + } + else if(button_read_device() & BUTTON_BACK) + return; + if(iAMOUNT_CHOICES-1) + sel_choice = 0; + lastbtn = btn; + } + lcd_update(); + yield(); + } +} + +void read_rtc(void) +{ + unsigned char test[12]; + char temp2[20]; + i2c_read(0x51, test, 12); + snprintf(temp2, sizeof(char)*20, "%x%x%x%x%x%x%x%x%x%x%x%x", + test[0], test[1], test[2], test[3], test[4], + test[5], test[6], test[7], test[8], test[9], + test[10], test[11]); + printf("RTC = %s", temp2); + return; +} +void do_pic(void) +{ + unsigned char test[16]; + char msg[20]; + IO_INTC_EINT1 &= ~INTR_EINT1_EXT0; + i2c_write(0x07, 1, 1); + i2c_read(0x07, test, 16); + snprintf(msg, sizeof(char)*20, "%x%x%x%x%x%x%x%x%x%x%x%x", + test[0], test[1], test[2], test[3], test[4], + test[5], test[6], test[7], test[8], test[9], + test[10], test[11], test[12], test[13], test[14], test[15]); + printf("%s", msg); + i2c_write(0x07, 2, 1); + i2c_read(0x07, test, 16); + snprintf(msg, sizeof(char)*20, "%x%x%x%x%x%x%x%x%x%x%x%x", + test[0], test[1], test[2], test[3], test[4], + test[5], test[6], test[7], test[8], test[9], + test[10], test[11], test[12], test[13], test[14], test[15]); + printf("%s", msg); + i2c_write(0x07, 9, 1); + i2c_read(0x07, test, 16); + snprintf(msg, sizeof(char)*20, "%x%x%x%x%x%x%x%x%x%x%x%x", + test[0], test[1], test[2], test[3], test[4], + test[5], test[6], test[7], test[8], test[9], + test[10], test[11], test[12], test[13], test[14], test[15]); + printf("%s", msg); + i2c_write(0x07, 10, 1); + i2c_read(0x07, test, 16); + snprintf(msg, sizeof(char)*20, "%x%x%x%x%x%x%x%x%x%x%x%x", + test[0], test[1], test[2], test[3], test[4], + test[5], test[6], test[7], test[8], test[9], + test[10], test[11], test[12], test[13], test[14], test[15]); + printf("%s", msg); + IO_INTC_IRQ1 = INTR_IRQ1_EXT0; + IO_INTC_EINT1 |= INTR_EINT1_EXT0; + sleep(5); + return; +} + +#include "dsp-target.h" +#include "dsp_image_helloworld.h" +void main(void) +{ + unsigned char* loadbuffer; + int buffer_size; + int rc; + int(*kernel_entry)(void); + + + /* Make sure interrupts are disabled */ + set_irq_level(IRQ_DISABLED); + set_fiq_status(FIQ_DISABLED); + //power_init(); + system_init(); + kernel_init(); + + /* Now enable interrupts */ + set_irq_level(IRQ_ENABLED); + set_fiq_status(FIQ_ENABLED); + lcd_init(); + font_init(); + + lcd_enable(true); + lcd_setfont(FONT_SYSFIXED); + reset_screen(); + printf("Rockbox boot loader"); + printf("Version %s", APPSVERSION); + switch (IO_BUSC_REVR) + { + case 0x0010: + printf("DM320 Rev. A"); + break; + case 0x0011: + printf("DM320 Rev. B/C"); + break; + default: + printf("Unknown DM320 Chip ID"); + } + + + asm volatile("msr cpsr_c, #0x13"); // Supervisory mode with interrupts(IRQ/FIQ) enabled + + printf("Initing DSP..."); + dsp_init(); + + button_init(); + + int ret = ata_init(); + if(ret) + printf("ATA error: %d", ret); + + if(button_read_device() & BUTTON_HOLD) + do_rescue_menu(); + + unsigned char temp[512]; + struct hdd_struct* temp2; + ata_read_sectors(0, 1, &temp); + temp2 = (struct hdd_struct*)temp; + + ret = fat_mount(IF_MV2(0,) IF_MV2(0,) temp2->cfs.start); + if(ret) + printf("FAT mount error: %d", ret); +#if 0 + printf("Loading firmware..."); + + loadbuffer = (unsigned char*) 0x00900000; + buffer_size = (unsigned char*)0x01900000 - loadbuffer; + + rc = load_firmware(loadbuffer, BOOTFILE, buffer_size); + if(rc < 0) + error(EBOOTFILE, rc); + + printf("Loading Rockbox..."); + sleep(5000); + if (rc == EOK) + { + kernel_entry = (void*) loadbuffer; + rc = kernel_entry(); + } +#endif + + printf("initing USB"); + usb_init(); + + printf("start USB monitoring..."); + usb_start_monitoring(); + + int lastcall = USB_EXTRACTED; + unsigned char test[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; + while(1) + { + snprintf(test, sizeof(char)*16, "%x ", button_read_device()); + lcd_putsxy(LCD_WIDTH-SYSFONT_WIDTH*5, SYSFONT_HEIGHT*2, test); + lcd_update(); + if(button_read_device() & BUTTON_PLAY) + do_hdd_browsing(); + else if(button_read_device() & BUTTON_MENU) + do_rescue_menu(); + else if(button_read_device() & BUTTON_BACK) + do_pic(); + /*else if(button_read_device() & BUTTON_CUSTOM) + do_data_browsing(0x90000000);*/ + yield(); + } + + //adc_init(); + //button_init(); + //backlight_init(); + + + /* Show debug messages if button is pressed */ + // if(button_read_device()) + verbose = true; + +#if 0 + printf("Initing USB..."); + usb_init(); + + char msg[400]; + unsigned int i; + #define TEST_REG(addr) (*(volatile unsigned short *)(addr)) + #define UNK2 TEST_REG(0x4F0000) + #define UNK3 TEST_REG(0x50FFC000) + #define UNK7 TEST_REG(0x50FF600C) + #define MAYBEUSB TEST_REG(0x60FFC0F8) + + const char* const names[] = + { + "IO_GIO_BITSET0","IO_GIO_BITSET1","IO_GIO_BITSET2","IO_GIO_BITCLR0","IO_GIO_BITCLR1","IO_GIO_BITCLR2"//,"IO_GIO_DIR0","IO_GIO_DIR1","IO_GIO_DIR2","IO_GIO_INV0","IO_GIO_INV1","IO_GIO_INV2" + ,"IO_GIO_FSEL0","IO_GIO_FSEL1","IO_GIO_FSEL2","IO_GIO_FSEL3","IO_GIO_FSEL4"//,"IO_GIO_IRQPORT","IO_GIO_IRQEDGE","IO_GIO_CHAT0","IO_GIO_CHAT1","IO_GIO_CHAT2","IO_GIO_NCHAT" + ,"0x4F0000","0x50FFC000","IO_I2C_TXDATA","IO_TIMER1_TMCNT" + //,"IO_CLK_PLLA","IO_CLK_PLLB","IO_CLK_SEL0","IO_CLK_SEL1","IO_CLK_SEL2","IO_CLK_DIV0","IO_CLK_DIV1","IO_CLK_DIV2","IO_CLK_DIV3","IO_CLK_DIV4" + //,"IO_DSPC_HPIB_CONTROL","IO_DSPC_HPIB_STATUS" + ,"IO_CLK_MOD0","IO_CLK_MOD1","IO_CLK_MOD2","current_tick" + ,"IO_INTC_IRQ0","IO_INTC_IRQ1","IO_INTC_IRQ2" + ,"ISP1583_GEN_INT","ISP1583_INIT_MODE","ISP1583_INIT_INTCONF","ISP1583_INIT_OTG","ISP1583_INIT_INTEN" + ,"ISP1583_GEN_UNLCKDEV","MAYBEUSB" + }; + volatile unsigned short * vars[] = + { + &IO_GIO_BITSET0,&IO_GIO_BITSET1,&IO_GIO_BITSET2,&IO_GIO_BITCLR0,&IO_GIO_BITCLR1,&IO_GIO_BITCLR2//,&IO_GIO_DIR0,&IO_GIO_DIR1,&IO_GIO_DIR2,&IO_GIO_INV0,&IO_GIO_INV1,&IO_GIO_INV2 + ,&IO_GIO_FSEL0,&IO_GIO_FSEL1,&IO_GIO_FSEL2,&IO_GIO_FSEL3,&IO_GIO_FSEL4//,&IO_GIO_IRQPORT,&IO_GIO_IRQEDGE,&IO_GIO_CHAT0,&IO_GIO_CHAT1,&IO_GIO_CHAT2,&IO_GIO_NCHAT + ,&UNK2,&UNK3,&IO_I2C_TXDATA,&IO_TIMER1_TMCNT + //,&IO_CLK_PLLA,&IO_CLK_PLLB,&IO_CLK_SEL0,&IO_CLK_SEL1,&IO_CLK_SEL2,&IO_CLK_DIV0,&IO_CLK_DIV1,&IO_CLK_DIV2,&IO_CLK_DIV3,&IO_CLK_DIV4 + //,&IO_DSPC_HPIB_CONTROL,&IO_DSPC_HPIB_STATUS + ,&IO_CLK_MOD0,&IO_CLK_MOD1,&IO_CLK_MOD2,¤t_tick + ,&IO_INTC_IRQ0,&IO_INTC_IRQ1,&IO_INTC_IRQ2 + ,&ISP1583_GEN_INT,&ISP1583_INIT_MODE,&ISP1583_INIT_INTCONF,&ISP1583_INIT_OTG,&ISP1583_INIT_INTEN + ,&ISP1583_GEN_UNLCKDEV,&MAYBEUSB + }; + unsigned int tempval[sizeof(vars)/sizeof(volatile unsigned short*)]; + unsigned int temp; + int flag=0; + reset_screen(); + lcd_set_foreground(LCD_RGBPACK(255,0,0)); + lcd_putsxy(0, LCD_HEIGHT-SYSFONT_HEIGHT, "RED means higher"); + lcd_set_foreground(LCD_RGBPACK(0,255,0)); + lcd_putsxy(100, LCD_HEIGHT-SYSFONT_HEIGHT, "GREEN means lower"); + lcd_set_foreground(LCD_BLACK); + lcd_putsxy(210, LCD_HEIGHT-SYSFONT_HEIGHT, "BLACK means equal"); + while(true) { + for(i=0;itempval[i]) + lcd_set_foreground(LCD_RGBPACK(255,0,0)); + else if(temptempval[i+1]) + lcd_set_foreground(LCD_RGBPACK(255,0,0)); + else if(temp (included via "sha1.h" to define 32 and 8 + * bit unsigned integer types. If your C compiler does not + * support 32 bit unsigned integers, this code is not + * appropriate. + * + * Caveats: + * SHA-1 is designed to work with messages less than 2^64 bits + * long. Although SHA-1 allows a message digest to be generated + * for messages of any number of bits less than 2^64, this + * implementation only works with messages with a length that is + * a multiple of the size of an 8-bit character. + * + */ + +#include "hmac-sha1.h" + +/* + * Define the SHA1 circular left shift macro + */ +#define SHA1CircularShift(bits,word) \ + (((word) << (bits)) | ((word) >> (32-(bits)))) + +/* Local Function Prototyptes */ +void SHA1PadMessage(SHA1Context *); +void SHA1ProcessMessageBlock(SHA1Context *); + +/* + * SHA1Reset + * + * Description: + * This function will initialize the SHA1Context in preparation + * for computing a new SHA1 message digest. + * + * Parameters: + * context: [in/out] + * The context to reset. + * + * Returns: + * sha Error Code. + * + */ +int SHA1Reset(SHA1Context *context) +{ + if (!context) + { + return shaNull; + } + + context->Length_Low = 0; + context->Length_High = 0; + context->Message_Block_Index = 0; + + context->Intermediate_Hash[0] = 0x67452301; + context->Intermediate_Hash[1] = 0xEFCDAB89; + context->Intermediate_Hash[2] = 0x98BADCFE; + context->Intermediate_Hash[3] = 0x10325476; + context->Intermediate_Hash[4] = 0xC3D2E1F0; + + context->Computed = 0; + context->Corrupted = 0; + + return shaSuccess; +} + +/* + * SHA1Result + * + * Description: + * This function will return the 160-bit message digest into the + * Message_Digest array provided by the caller. + * NOTE: The first octet of hash is stored in the 0th element, + * the last octet of hash in the 19th element. + * + * Parameters: + * context: [in/out] + * The context to use to calculate the SHA-1 hash. + * Message_Digest: [out] + * Where the digest is returned. + * + * Returns: + * sha Error Code. + * + */ +int SHA1Result( SHA1Context *context, + uint8_t Message_Digest[SHA1HashSize]) +{ + int i; + + if (!context || !Message_Digest) + { + return shaNull; + } + + if (context->Corrupted) + { + return context->Corrupted; + } + + if (!context->Computed) + { + SHA1PadMessage(context); + for(i=0; i<64; ++i) + { + /* message may be sensitive, clear it out */ + context->Message_Block[i] = 0; + } + context->Length_Low = 0; /* and clear length */ + context->Length_High = 0; + context->Computed = 1; + } + + for(i = 0; i < SHA1HashSize; ++i) + { + Message_Digest[i] = context->Intermediate_Hash[i>>2] + >> 8 * ( 3 - ( i & 0x03 ) ); + } + + return shaSuccess; +} + +/* + * SHA1Input + * + * Description: + * This function accepts an array of octets as the next portion + * of the message. + * + * Parameters: + * context: [in/out] + * The SHA context to update + * message_array: [in] + * An array of characters representing the next portion of + * the message. + * length: [in] + * The length of the message in message_array + * + * Returns: + * sha Error Code. + * + */ +int SHA1Input( SHA1Context *context, + const uint8_t *message_array, + unsigned length) +{ + if (!length) + { + return shaSuccess; + } + + if (!context || !message_array) + { + return shaNull; + } + + if (context->Computed) + { + context->Corrupted = shaStateError; + return shaStateError; + } + + if (context->Corrupted) + { + return context->Corrupted; + } + while(length-- && !context->Corrupted) + { + context->Message_Block[context->Message_Block_Index++] = + (*message_array & 0xFF); + + context->Length_Low += 8; + if (context->Length_Low == 0) + { + context->Length_High++; + if (context->Length_High == 0) + { + /* Message is too long */ + context->Corrupted = 1; + } + } + + if (context->Message_Block_Index == 64) + { + SHA1ProcessMessageBlock(context); + } + + message_array++; + } + + return shaSuccess; +} + +/* + * SHA1ProcessMessageBlock + * + * Description: + * This function will process the next 512 bits of the message + * stored in the Message_Block array. + * + * Parameters: + * None. + * + * Returns: + * Nothing. + * + * Comments: + * Many of the variable names in this code, especially the + * single character names, were used because those were the + * names used in the publication. + * + * + */ +void SHA1ProcessMessageBlock(SHA1Context *context) +{ + const uint32_t K[] = { /* Constants defined in SHA-1 */ + 0x5A827999, + 0x6ED9EBA1, + 0x8F1BBCDC, + 0xCA62C1D6 + }; + int t; /* Loop counter */ + uint32_t temp; /* Temporary word value */ + uint32_t W[80]; /* Word sequence */ + uint32_t A, B, C, D, E; /* Word buffers */ + + /* + * Initialize the first 16 words in the array W + */ + for(t = 0; t < 16; t++) + { + W[t] = context->Message_Block[t * 4] << 24; + W[t] |= context->Message_Block[t * 4 + 1] << 16; + W[t] |= context->Message_Block[t * 4 + 2] << 8; + W[t] |= context->Message_Block[t * 4 + 3]; + } + + for(t = 16; t < 80; t++) + { + W[t] = SHA1CircularShift(1,W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16]); + } + + A = context->Intermediate_Hash[0]; + B = context->Intermediate_Hash[1]; + C = context->Intermediate_Hash[2]; + D = context->Intermediate_Hash[3]; + E = context->Intermediate_Hash[4]; + + for(t = 0; t < 20; t++) + { + temp = SHA1CircularShift(5,A) + + ((B & C) | ((~B) & D)) + E + W[t] + K[0]; + E = D; + D = C; + C = SHA1CircularShift(30,B); + B = A; + A = temp; + } + + for(t = 20; t < 40; t++) + { + temp = SHA1CircularShift(5,A) + (B ^ C ^ D) + E + W[t] + K[1]; + E = D; + D = C; + C = SHA1CircularShift(30,B); + B = A; + A = temp; + } + + for(t = 40; t < 60; t++) + { + temp = SHA1CircularShift(5,A) + + ((B & C) | (B & D) | (C & D)) + E + W[t] + K[2]; + E = D; + D = C; + C = SHA1CircularShift(30,B); + B = A; + A = temp; + } + + for(t = 60; t < 80; t++) + { + temp = SHA1CircularShift(5,A) + (B ^ C ^ D) + E + W[t] + K[3]; + E = D; + D = C; + C = SHA1CircularShift(30,B); + B = A; + A = temp; + } + + context->Intermediate_Hash[0] += A; + context->Intermediate_Hash[1] += B; + context->Intermediate_Hash[2] += C; + context->Intermediate_Hash[3] += D; + context->Intermediate_Hash[4] += E; + + context->Message_Block_Index = 0; +} + + +/* + * SHA1PadMessage + * + * Description: + * According to the standard, the message must be padded to an even + * 512 bits. The first padding bit must be a '1'. The last 64 + * bits represent the length of the original message. All bits in + * between should be 0. This function will pad the message + * according to those rules by filling the Message_Block array + * accordingly. It will also call the ProcessMessageBlock function + * provided appropriately. When it returns, it can be assumed that + * the message digest has been computed. + * + * Parameters: + * context: [in/out] + * The context to pad + * ProcessMessageBlock: [in] + * The appropriate SHA*ProcessMessageBlock function + * Returns: + * Nothing. + * + */ + +void SHA1PadMessage(SHA1Context *context) +{ + /* + * Check to see if the current message block is too small to hold + * the initial padding bits and length. If so, we will pad the + * block, process it, and then continue padding into a second + * block. + */ + if (context->Message_Block_Index > 55) + { + context->Message_Block[context->Message_Block_Index++] = 0x80; + while(context->Message_Block_Index < 64) + { + context->Message_Block[context->Message_Block_Index++] = 0; + } + + SHA1ProcessMessageBlock(context); + + while(context->Message_Block_Index < 56) + { + context->Message_Block[context->Message_Block_Index++] = 0; + } + } + else + { + context->Message_Block[context->Message_Block_Index++] = 0x80; + while(context->Message_Block_Index < 56) + { + context->Message_Block[context->Message_Block_Index++] = 0; + } + } + + /* + * Store the message length as the last 8 octets + */ + context->Message_Block[56] = context->Length_High >> 24; + context->Message_Block[57] = context->Length_High >> 16; + context->Message_Block[58] = context->Length_High >> 8; + context->Message_Block[59] = context->Length_High; + context->Message_Block[60] = context->Length_Low >> 24; + context->Message_Block[61] = context->Length_Low >> 16; + context->Message_Block[62] = context->Length_Low >> 8; + context->Message_Block[63] = context->Length_Low; + + SHA1ProcessMessageBlock(context); +} +#define SHA_DIGESTSIZE 20 + +#define SHA_BLOCKSIZE 64 + +static void truncate +( + char* d1, /* data to be truncated */ + char* d2, /* truncated data */ + int len /* length in bytes to keep */ +) +{ + int i ; + for (i = 0 ; i < len ; i++) d2[i] = d1[i]; +} + + +/* Function to compute the digest */ +void +hmac_sha +( + char* k, /* secret key */ + int lk, /* length of the key in bytes */ + char* d, /* data */ + int ld, /* length of data in bytes */ + char* out, /* output buffer, at least "t" bytes */ + int t +) +{ + SHA1Context ictx, octx ; + char isha[SHA_DIGESTSIZE], osha[SHA_DIGESTSIZE] ; + char key[SHA_DIGESTSIZE] ; + char buf[SHA_BLOCKSIZE] ; + int i ; + + if (lk > SHA_BLOCKSIZE) { + + SHA1Context tctx ; + + SHA1Reset(&tctx) ; + SHA1Input(&tctx, k, lk) ; + SHA1Result(&tctx, key) ; + + k = key ; + lk = SHA_DIGESTSIZE ; + } + + /**** Inner Digest ****/ + + SHA1Reset(&ictx) ; + + /* Pad the key for inner digest */ + for (i = 0 ; i < lk ; ++i) buf[i] = k[i] ^ 0x36 ; + for (i = lk ; i < SHA_BLOCKSIZE ; ++i) buf[i] = 0x36 ; + + SHA1Input(&ictx, buf, SHA_BLOCKSIZE) ; + SHA1Input(&ictx, d, ld) ; + + SHA1Result(&ictx, isha) ; + + /**** Outter Digest ****/ + + SHA1Reset(&octx) ; + + /* Pad the key for outter digest */ + + + for (i = 0 ; i < lk ; ++i) buf[i] = k[i] ^ 0x5C ; + for (i = lk ; i < SHA_BLOCKSIZE ; ++i) buf[i] = 0x5C ; + + SHA1Input(&octx, buf, SHA_BLOCKSIZE) ; + SHA1Input(&octx, isha, SHA_DIGESTSIZE) ; + + SHA1Result(&octx, osha) ; + + /* truncate and print the results */ + t = t > SHA_DIGESTSIZE ? SHA_DIGESTSIZE : t ; + truncate(osha, out, t) ; + +} Index: tools/hmac-sha1.h =================================================================== --- tools/hmac-sha1.h (revision 0) +++ tools/hmac-sha1.h (revision 0) @@ -0,0 +1,84 @@ +/* + * sha1.h + * + * Description: + * This is the header file for code which implements the Secure + * Hashing Algorithm 1 as defined in FIPS PUB 180-1 published + * April 17, 1995. + * + * Many of the variable names in this code, especially the + * single character names, were used because those were the names + * used in the publication. + * + * Please read the file sha1.c for more information. + * + */ + +#ifndef _SHA1_H_ +#define _SHA1_H_ + +#include +/* + * If you do not have the ISO standard stdint.h header file, then you + * must typdef the following: + * name meaning + * uint32_t unsigned 32 bit integer + * uint8_t unsigned 8 bit integer (i.e., unsigned char) + * int_least16_t integer of >= 16 bits + * + */ + +#ifndef _SHA_enum_ +#define _SHA_enum_ +enum +{ + shaSuccess = 0, + shaNull, /* Null pointer parameter */ + shaInputTooLong, /* input data too long */ + shaStateError /* called Input after Result */ +}; +#endif +#define SHA1HashSize 20 + +/* + * This structure will hold context information for the SHA-1 + * hashing operation + */ +typedef struct SHA1Context +{ + uint32_t Intermediate_Hash[SHA1HashSize/4]; /* Message Digest */ + + uint32_t Length_Low; /* Message length in bits */ + uint32_t Length_High; /* Message length in bits */ + + /* Index into message block array */ + int_least16_t Message_Block_Index; + uint8_t Message_Block[64]; /* 512-bit message blocks */ + + int Computed; /* Is the digest computed? */ + int Corrupted; /* Is the message digest corrupted? */ +} SHA1Context; + +/* + * Function Prototypes + */ + +int SHA1Reset( SHA1Context *); +int SHA1Input( SHA1Context *, + const uint8_t *, + unsigned int); +int SHA1Result( SHA1Context *, + uint8_t Message_Digest[SHA1HashSize]); + +void +hmac_sha +( + char* k, + int lk, + char* d, + int ld, + char* out, + int t +); + +#endif Index: tools/Makefile =================================================================== --- tools/Makefile (revision 16999) +++ tools/Makefile (working copy) @@ -13,16 +13,18 @@ CLEANALL := scramble descramble iriver sh2d bmp2rb rdf2binary convbdf \ generate_rocklatin mkboot ipod_fw codepages uclpack mi4 gigabeat database \ - lngdump telechips gigabeats mktccboot mknkboot rbspeexenc + lngdump telechips gigabeats creative hmac-sha1 mktccboot mknkboot rbspeexenc all: @echo "Run make in your build directory!" -scramble: scramble.o iriver.o mi4.o gigabeat.o gigabeats.o telechips.o iaudio_bl_flash.o +scramble: scramble.o iriver.o mi4.o gigabeat.o gigabeats.o telechips.o iaudio_bl_flash.o creative.o hmac-sha1.o descramble: descramble.o iriver.o gigabeat.o +scramble.o: scramble.c iriver.h mi4.h gigabeat.h telechips.h iaudio_bl_flash.h creative.h -scramble.o: scramble.c iriver.h mi4.h gigabeat.h telechips.h iaudio_bl_flash.h descramble.o: descramble.c iriver.h gigabeat.h +creative.o: creative.c creative.h +hmac-sha1.o: hmac-sha1.c hmac-sha1.h iriver.o: iriver.c iriver.h gigabeat.o: gigabeat.c gigabeat.h gigabeats.o: gigabeats.c gigabeats.h Index: tools/creative.c =================================================================== --- tools/creative.c (revision 0) +++ tools/creative.c (revision 0) @@ -0,0 +1,159 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2008 by Maurus Cuelenaere + * + * 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 "creative.h" +#include "hmac-sha1.h" +#include +#include + +/* +Create a Zen Vision:M FRESCUE structure file +*/ + + +static int make_ciff_file(char *inbuf, int length, char *outbuf, int device) +{ + memcpy(outbuf, "FFIC", 4); + int2le(length+90, &outbuf[4]); + memcpy(&outbuf[8], "FNIC", 4); + int2le(96, &outbuf[0xC]); + memcpy(&outbuf[0x10], devices[device].cinf, devices[device].cinf_size); + memset(&outbuf[0x10+devices[device].cinf_size], 0, 96 - devices[device].cinf_size); + memcpy(&outbuf[0x70], "ATAD", 4); + int2le(length+32, &outbuf[0x74]); + memcpy(&outbuf[0x78], "H\0j\0u\0k\0e\0b\0o\0x\0\x32\0.\0j\0r\0m", 32); /*Unicode encoded*/ + memcpy(&outbuf[0x98], inbuf, length); + memcpy(&outbuf[0x98+length], "LLUN", 4); + int2le(20, &outbuf[0x98+length+4]); + /* Do checksum */ + char key[20]; + hmac_sha((char*)devices[device].null, strlen(devices[device].null), outbuf, 0x98+length, key, 20); + memcpy(&outbuf[0x98+length+8], key, 20); + return length+0x90+0x1C+8; +} + +static int make_jrm_file(char *inbuf, int length, char *outbuf) +{ + int i; + unsigned int sum = 0; + /* Calculate checksum for later use in header */ + for(i=0; i>16); + + /* Clear the header area to zero */ + memset(outbuf, 0, 0x18); + + /* Header (EDOC) */ + memcpy(outbuf, "EDOC", 4); + /* Total Size */ + int2le(length+0x20, &outbuf[0x4]); + /* 4 bytes of zero */ + + /* Address = 0x900000 */ + int2le(0x900000, &outbuf[0xC]); + /* Size */ + int2le(length, &outbuf[0x10]); + /* Checksum */ + int2le(sum, &outbuf[0x14]); + outbuf[0x16] = 0; + outbuf[0x17] = 0; + /* Data starts here... */ + memcpy(&outbuf[0x18], inbuf, length); + + /* Second block starts here ... */ + /* Address = 0x0 */ + /* Size */ + int2le(0x4, &outbuf[0x18+length+0x4]); + /* Checksum */ + outbuf[0x18+length+0x8] = 0xA9; + outbuf[0x18+length+0x9] = 0xD9; + /* Data: MOV PC, 0x900000 */ + outbuf[0x18+length+0xC] = 0x09; + outbuf[0x18+length+0xD] = 0xF6; + outbuf[0x18+length+0xE] = 0xA0; + outbuf[0x18+length+0xF] = 0xE3; + + return length+0x18+0x10; +} + +int zvm_encode(char *iname, char *oname, int device) +{ + size_t len; + int length; + FILE *file; + unsigned char *outbuf; + unsigned char *buf; + int i; + + file = fopen(iname, "rb"); + if (!file) { + perror(iname); + return -1; + } + fseek(file, 0, SEEK_END); + length = ftell(file); + + fseek(file, 0, SEEK_SET); + + buf = (unsigned char*)malloc(length); + if ( !buf ) { + printf("out of memory!\n"); + return -1; + } + + len = fread(buf, 1, length, file); + if(len < length) { + perror(iname); + return -2; + } + fclose(file); + + outbuf = (unsigned char*)malloc(length+0x300); + if ( !outbuf ) { + free(buf); + printf("out of memory!\n"); + return -1; + } + length = make_jrm_file(buf, len, outbuf); + free(buf); + buf = (unsigned char*)malloc(length+0x200); + memset(buf, 0, length+0x200); + length = make_ciff_file(outbuf, length, buf, device); + free(outbuf); + + file = fopen(oname, "wb"); + if (!file) { + free(buf); + perror(oname); + return -3; + } + + len = fwrite(buf, 1, length, file); + if(len < length) { + free(buf); + perror(oname); + return -4; + } + + free(buf); + + fclose(file); + + return 0; +} Index: tools/creative.h =================================================================== --- tools/creative.h (revision 0) +++ tools/creative.h (revision 0) @@ -0,0 +1,53 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2008 by Maurus Cuelenaere + * + * 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 CREATIVE_H_ +#define CREATIVE_H_ + +enum +{ + ZENVISIONM = 0, + ZENVISIONM60 = 1, + ZENVISION = 2, + ZENV = 3 +}; + +static struct device_info +{ + const char* cinf; /*Must be Unicode encoded*/ + const int cinf_size; + const char* null; +} device_info; + +static const char null_key_v1[] = "CTL:N0MAD|PDE0.SIGN."; +static const char null_key_v2[] = "CTL:N0MAD|PDE0.DPMP."; +static const char null_key_v3[] = "CTL:Z3N07|PDE0.DPMP."; +static const char null_key_v4[] = "CTL:N0MAD|PDE0.DPFP."; + +static const struct device_info devices[] = +{ + {"C\0r\0e\0a\0t\0i\0v\0e\0 \0Z\0e\0n\0 \0V\0i\0s\0i\0o\0n\0:\0M", 42, null_key_v2}, + {"C\0r\0e\0a\0t\0i\0v\0e\0 \0Z\0e\0n\0 \0V\0i\0s\0i\0o\0n\0:\0M\0 \0G\0o\0!", 50, null_key_v2}, + {"C\0r\0e\0a\0t\0i\0v\0e\0 \0Z\0e\0n\0 \0V\0i\0s\0i\0o\0n\0 \0©\0T\0L", 48, null_key_v2}, + {"C\0r\0e\0a\0t\0i\0v\0e\0 \0Z\0E\0N\0 \0V", 42, null_key_v4} +}; + +int zvm_encode(char *iname, char *oname, int device); + +#endif /*CREATIVE_H_*/ Index: tools/configure =================================================================== --- tools/configure (revision 16999) +++ tools/configure (working copy) @@ -1455,18 +1455,19 @@ target_id=35 modelname="creativezvm" target="-DCREATIVE_ZVM" - memory=32 # always + memory=64 arm926ejscc bmp2rb_mono="$rootdir/tools/bmp2rb -f 0" bmp2rb_native="$rootdir/tools/bmp2rb -f 4" bmp2rb_remotemono="$rootdir/tools/bmp2rb -f 0" bmp2rb_remotenative="$rootdir/tools/bmp2rb -f 0" + tool="cp" output="rockbox.zvm" appextra="recorder:gui" - plugins="yes" + plugins="" swcodec="yes" toolset=$gigabeatbitmaptools - boottool="$rootdir/tools/scramble -zvm" + boottool="$rootdir/tools/scramble -creative=zvm" bootoutput="rockbox.zvmboot" # architecture, manufacturer and model for the target-tree build t_cpu="arm" @@ -1998,7 +1999,7 @@ -e "s,@VOICETOOLSET@,${voicetoolset},g" \ -e "s,@LANGS@,${buildlangs},g" \ <>16); - - /* Clear the header area to zero */ - memset(outbuf, 0, 0x18); - - /* Header (EDOC) */ - memcpy((char*)outbuf, "EDOC", 4); - /* Total Size */ - int2le(length+0x20, &outbuf[0x4]); - /* 4 bytes of zero */ - - /* Address = 0x900000 */ - int2le(0x900000, &outbuf[0xC]); - /* Size */ - int2le(length, &outbuf[0x10]); - /* Checksum */ - int2le(sum, &outbuf[0x14]); - outbuf[0x16] = 0; - outbuf[0x17] = 0; - /* Data starts here... */ - - /* Second block starts here ... */ - /* Address = 0x0 */ - /* Size */ - int2le(0x4, &outbuf[0x18+length+0x4]); - /* Checksum */ - outbuf[0x18+length+0x8] = 0xB7; - outbuf[0x18+length+0x9] = 0xD5; - /* Data: LDR PC, =0x900000 */ - outbuf[0x18+length+0xC] = 0x18; - outbuf[0x18+length+0xD] = 0xF0; - outbuf[0x18+length+0xE] = 0x9F; - outbuf[0x18+length+0xF] = 0xE5; - - - file = fopen(oname, "wb"); - if (!file) { - perror(oname); - return -3; - } - - len = fwrite(outbuf, 1, length+0x28, file); - if(len < length+0x18) { - perror(oname); - return -4; - } - - free(outbuf); - - fclose(file); - - return 0; -} - Index: apps/SOURCES =================================================================== --- apps/SOURCES (revision 16999) +++ apps/SOURCES (working copy) @@ -175,4 +175,6 @@ keymaps/keymap-mr100.c #elif CONFIG_KEYPAD == COWOND2_PAD keymaps/keymap-cowond2.c +#elif CONFIG_KEYPAD == CREATIVEZVM_PAD +keymaps/keymap-creativezvm.c #endif Index: firmware/export/dm320.h =================================================================== --- firmware/export/dm320.h (revision 16999) +++ firmware/export/dm320.h (working copy) @@ -8,6 +8,7 @@ * $Id$ * * Copyright (C) 2007 by Karl Kurbjun + * Copyright (C) 2008 by Maurus Cuelenaere * * 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. @@ -24,13 +25,13 @@ #ifndef __DM320_H__ #define __DM320_H__ -#define LCD_BUFFER_SIZE (640*480*2) -#define TTB_SIZE (0x4000) +#define LCD_BUFFER_SIZE (LCD_WIDTH*LCD_HEIGHT*2) +#define TTB_SIZE (0x4000) /* must be 16Kb (0x4000) aligned */ -#define TTB_BASE ((unsigned int *)(0x04900000 - TTB_SIZE)) /* End of memory */ -#define FRAME ((short *) ((char*)TTB_BASE - LCD_BUFFER_SIZE)) /* Right before TTB */ +#define TTB_BASE ((unsigned int *)(0x04900000 - TTB_SIZE)) /* End of memory */ +#define FRAME ((short *) ((char*)TTB_BASE - LCD_BUFFER_SIZE)) /* Right before TTB */ -#define PHY_IO_BASE 0x00030000 +#define PHY_IO_BASE 0x00030000 #define DM320_REG(addr) (*(volatile unsigned short *)(PHY_IO_BASE + (addr))) /* Timer 0-3 */ @@ -96,11 +97,11 @@ #define IO_UART1_SR DM320_REG(0x038C) /* Watchdog Timer */ -#define IO_WATCHDOG_MODE 0x0400 -#define IO_WATCHDOG_RESET 0x0402 -#define IO_WATCHDOG_PRESCALAR 0x0404 -#define IO_WATCHDOG_DIVISOR 0x0406 -#define IO_WATCHDOG_EXT_RESET 0x0408 +#define IO_WATCHDOG_MODE DM320_REG(0x0400) +#define IO_WATCHDOG_RESET DM320_REG(0x0402) +#define IO_WATCHDOG_PRESCALAR DM320_REG(0x0404) +#define IO_WATCHDOG_DIVISOR DM320_REG(0x0406) +#define IO_WATCHDOG_EXT_RESET DM320_REG(0x0408) /* MMC/SD Controller */ #define IO_MMC_CONTROL 0x0480 @@ -342,49 +343,49 @@ #define IO_CCD_FMTPTNB 0x0758 /* NTSC/PAL Encoder */ -#define IO_VID_ENC_VMOD 0x0800 -#define IO_VID_ENC_VDCTL 0x0802 -#define IO_VID_ENC_VDPRO 0x0804 -#define IO_VID_ENC_SYNCCTL 0x0806 -#define IO_VID_ENC_HSPLS 0x0808 -#define IO_VID_ENC_VSPLS 0x080A -#define IO_VID_ENC_HINT 0x080C -#define IO_VID_ENC_HSTART 0x080E -#define IO_VID_ENC_HVALID 0x0810 -#define IO_VID_ENC_VINT 0x0812 -#define IO_VID_ENC_VSTART 0x0814 -#define IO_VID_ENC_VVALID 0x0816 -#define IO_VID_ENC_HSDLY 0x0818 -#define IO_VID_ENC_VSDLY 0x081A -#define IO_VID_ENC_YCCTL 0x081C -#define IO_VID_ENC_RGBCTL 0x081E -#define IO_VID_ENC_RGBCLP 0x0820 -#define IO_VID_ENC_LNECTL 0x0822 -#define IO_VID_ENC_CULLLNE 0x0824 -#define IO_VID_ENC_LCDOUT 0x0826 -#define IO_VID_ENC_BRTS 0x0828 -#define IO_VID_ENC_BRTW 0x082A -#define IO_VID_ENC_ACCTL 0x082C -#define IO_VID_ENC_PWMP 0x082E -#define IO_VID_ENC_PWMW 0x0830 -#define IO_VID_ENC_DCLKCTL 0x0832 -#define IO_VID_ENC_DCLKPTN0 0x0834 -#define IO_VID_ENC_DCLKPTN1 0x0836 -#define IO_VID_ENC_DCLKPTN2 0x0838 -#define IO_VID_ENC_DCLKPTN3 0x083A -#define IO_VID_ENC_DCLKPTN0A 0x083C -#define IO_VID_ENC_DCLKPTN1A 0x083E -#define IO_VID_ENC_DCLKPTN2A 0x0840 -#define IO_VID_ENC_DCLKPTN3A 0x0842 -#define IO_VID_ENC_DCLKHS 0x0844 -#define IO_VID_ENC_DCLKHSA 0x0846 -#define IO_VID_ENC_DCLKHR 0x0848 -#define IO_VID_ENC_DCLKVS 0x084A -#define IO_VID_ENC_DCLKVR 0x084C -#define IO_VID_ENC_CAPCTL 0x084E -#define IO_VID_ENC_CAPDO 0x0850 -#define IO_VID_ENC_CAPDE 0x0852 -#define IO_VID_ENC_ATR0 0x0854 +#define IO_VID_ENC_VMOD DM320_REG(0x0800) +#define IO_VID_ENC_VDCTL DM320_REG(0x0802) +#define IO_VID_ENC_VDPRO DM320_REG(0x0804) +#define IO_VID_ENC_SYNCCTL DM320_REG(0x0806) +#define IO_VID_ENC_HSPLS DM320_REG(0x0808) +#define IO_VID_ENC_VSPLS DM320_REG(0x080A) +#define IO_VID_ENC_HINT DM320_REG(0x080C) +#define IO_VID_ENC_HSTART DM320_REG(0x080E) +#define IO_VID_ENC_HVALID DM320_REG(0x0810) +#define IO_VID_ENC_VINT DM320_REG(0x0812) +#define IO_VID_ENC_VSTART DM320_REG(0x0814) +#define IO_VID_ENC_VVALID DM320_REG(0x0816) +#define IO_VID_ENC_HSDLY DM320_REG(0x0818) +#define IO_VID_ENC_VSDLY DM320_REG(0x081A) +#define IO_VID_ENC_YCCTL DM320_REG(0x081C) +#define IO_VID_ENC_RGBCTL DM320_REG(0x081E) +#define IO_VID_ENC_RGBCLP DM320_REG(0x0820) +#define IO_VID_ENC_LNECTL DM320_REG(0x0822) +#define IO_VID_ENC_CULLLNE DM320_REG(0x0824) +#define IO_VID_ENC_LCDOUT DM320_REG(0x0826) +#define IO_VID_ENC_BRTS DM320_REG(0x0828) +#define IO_VID_ENC_BRTW DM320_REG(0x082A) +#define IO_VID_ENC_ACCTL DM320_REG(0x082C) +#define IO_VID_ENC_PWMP DM320_REG(0x082E) +#define IO_VID_ENC_PWMW DM320_REG(0x0830) +#define IO_VID_ENC_DCLKCTL DM320_REG(0x0832) +#define IO_VID_ENC_DCLKPTN0 DM320_REG(0x0834) +#define IO_VID_ENC_DCLKPTN1 DM320_REG(0x0836) +#define IO_VID_ENC_DCLKPTN2 DM320_REG(0x0838) +#define IO_VID_ENC_DCLKPTN3 DM320_REG(0x083A) +#define IO_VID_ENC_DCLKPTN0A DM320_REG(0x083C) +#define IO_VID_ENC_DCLKPTN1A DM320_REG(0x083E) +#define IO_VID_ENC_DCLKPTN2A DM320_REG(0x0840) +#define IO_VID_ENC_DCLKPTN3A DM320_REG(0x0842) +#define IO_VID_ENC_DCLKHS DM320_REG(0x0844) +#define IO_VID_ENC_DCLKHSA DM320_REG(0x0846) +#define IO_VID_ENC_DCLKHR DM320_REG(0x0848) +#define IO_VID_ENC_DCLKVS DM320_REG(0x084A) +#define IO_VID_ENC_DCLKVR DM320_REG(0x084C) +#define IO_VID_ENC_CAPCTL DM320_REG(0x084E) +#define IO_VID_ENC_CAPDO DM320_REG(0x0850) +#define IO_VID_ENC_CAPDE DM320_REG(0x0852) +#define IO_VID_ENC_ATR0 DM320_REG(0x0854) /* Clock Controller */ #define IO_CLK_PLLA DM320_REG(0x0880) @@ -414,102 +415,102 @@ #define IO_CLK_PWM1H DM320_REG(0x08B0) /* Bus Controller */ -#define IO_BUSC_ECR 0x0900 -#define IO_BUSC_EBYTER 0x0902 -#define IO_BUSC_EBITR 0x0904 -#define IO_BUSC_REVR 0x0906 +#define IO_BUSC_ECR DM320_REG(0x0900) +#define IO_BUSC_EBYTER DM320_REG(0x0902) +#define IO_BUSC_EBITR DM320_REG(0x0904) +#define IO_BUSC_REVR DM320_REG(0x0906) /* SDRAM Controller */ -#define IO_SDRAM_SDBUFD0L 0x0980 -#define IO_SDRAM_SDBUFD0H 0x0982 -#define IO_SDRAM_SDBUFD1L 0x0984 -#define IO_SDRAM_SDBUFD1H 0x0986 -#define IO_SDRAM_SDBUFD2L 0x0988 -#define IO_SDRAM_SDBUFD2H 0x098A -#define IO_SDRAM_SDBUFD3L 0x098C -#define IO_SDRAM_SDBUFD3H 0x098E -#define IO_SDRAM_SDBUFD4L 0x0990 -#define IO_SDRAM_SDBUFD4H 0x0992 -#define IO_SDRAM_SDBUFD5L 0x0994 -#define IO_SDRAM_SDBUFD5H 0x0996 -#define IO_SDRAM_SDBUFD6L 0x0998 -#define IO_SDRAM_SDBUFD6H 0x099A -#define IO_SDRAM_SDBUFD7L 0x099C -#define IO_SDRAM_SDBUFD7H 0x099E -#define IO_SDRAM_SDBUFAD1 0x09A0 -#define IO_SDRAM_SDBUFAD2 0x09A2 -#define IO_SDRAM_SDBUFCTL 0x09A4 -#define IO_SDRAM_SDMODE 0x09A6 -#define IO_SDRAM_REFCTL 0x09A8 -#define IO_SDRAM_SDPRTY1 0x09AA -#define IO_SDRAM_SDPRTY2 0x09AC -#define IO_SDRAM_SDPRTY3 0x09AE -#define IO_SDRAM_SDPRTY4 0x09B0 -#define IO_SDRAM_SDPRTY5 0x09B2 -#define IO_SDRAM_SDPRTY6 0x09B4 -#define IO_SDRAM_SDPRTY7 0x09B6 -#define IO_SDRAM_SDPRTY8 0x09B8 -#define IO_SDRAM_SDPRTY9 0x09BA -#define IO_SDRAM_SDPRTY10 0x09BC -#define IO_SDRAM_SDPRTY11 0x09BE -#define IO_SDRAM_SDPRTY12 0x09C0 -#define IO_SDRAM_RSV 0x09C2 -#define IO_SDRAM_SDPRTYON 0x09C4 -#define IO_SDRAM_SDDMASEL 0x09C6 +#define IO_SDRAM_SDBUFD0L DM320_REG(0x0980) +#define IO_SDRAM_SDBUFD0H DM320_REG(0x0982) +#define IO_SDRAM_SDBUFD1L DM320_REG(0x0984) +#define IO_SDRAM_SDBUFD1H DM320_REG(0x0986) +#define IO_SDRAM_SDBUFD2L DM320_REG(0x0988) +#define IO_SDRAM_SDBUFD2H DM320_REG(0x098A) +#define IO_SDRAM_SDBUFD3L DM320_REG(0x098C) +#define IO_SDRAM_SDBUFD3H DM320_REG(0x098E) +#define IO_SDRAM_SDBUFD4L DM320_REG(0x0990) +#define IO_SDRAM_SDBUFD4H DM320_REG(0x0992) +#define IO_SDRAM_SDBUFD5L DM320_REG(0x0994) +#define IO_SDRAM_SDBUFD5H DM320_REG(0x0996) +#define IO_SDRAM_SDBUFD6L DM320_REG(0x0998) +#define IO_SDRAM_SDBUFD6H DM320_REG(0x099A) +#define IO_SDRAM_SDBUFD7L DM320_REG(0x099C) +#define IO_SDRAM_SDBUFD7H DM320_REG(0x099E) +#define IO_SDRAM_SDBUFAD1 DM320_REG(0x09A0) +#define IO_SDRAM_SDBUFAD2 DM320_REG(0x09A2) +#define IO_SDRAM_SDBUFCTL DM320_REG(0x09A4) +#define IO_SDRAM_SDMODE DM320_REG(0x09A6) +#define IO_SDRAM_REFCTL DM320_REG(0x09A8) +#define IO_SDRAM_SDPRTY1 DM320_REG(0x09AA) +#define IO_SDRAM_SDPRTY2 DM320_REG(0x09AC) +#define IO_SDRAM_SDPRTY3 DM320_REG(0x09AE) +#define IO_SDRAM_SDPRTY4 DM320_REG(0x09B0) +#define IO_SDRAM_SDPRTY5 DM320_REG(0x09B2) +#define IO_SDRAM_SDPRTY6 DM320_REG(0x09B4) +#define IO_SDRAM_SDPRTY7 DM320_REG(0x09B6) +#define IO_SDRAM_SDPRTY8 DM320_REG(0x09B8) +#define IO_SDRAM_SDPRTY9 DM320_REG(0x09BA) +#define IO_SDRAM_SDPRTY10 DM320_REG(0x09BC) +#define IO_SDRAM_SDPRTY11 DM320_REG(0x09BE) +#define IO_SDRAM_SDPRTY12 DM320_REG(0x09C0) +#define IO_SDRAM_RSV DM320_REG(0x09C2) +#define IO_SDRAM_SDPRTYON DM320_REG(0x09C4) +#define IO_SDRAM_SDDMASEL DM320_REG(0x09C6) /* EMIF Controller */ -#define IO_EMIF_CS0CTRL1 0x0A00 -#define IO_EMIF_CS0CTRL2 0x0A02 -#define IO_EMIF_CS0CTRL3 0x0A04 -#define IO_EMIF_CS1CTRL1A 0x0A06 -#define IO_EMIF_CS1CTRL1B 0x0A08 -#define IO_EMIF_CS1CTRL2 0x0A0A -#define IO_EMIF_CS2CTRL1 0x0A0C -#define IO_EMIF_CS2CTRL2 0x0A0E -#define IO_EMIF_CS3CTRL1 0x0A10 -#define IO_EMIF_CS3CTRL2 0x0A12 -#define IO_EMIF_CS4CTRL1 0x0A14 -#define IO_EMIF_CS4CTRL2 0x0A16 -#define IO_EMIF_BUSCTRL 0x0A18 -#define IO_EMIF_BUSRLS 0x0A1A -#define IO_EMIF_CFCTRL1 0x0A1C -#define IO_EMIF_CFCTRL2 0x0A1E -#define IO_EMIF_SMCTRL 0x0A20 -#define IO_EMIF_BUSINTEN 0x0A22 -#define IO_EMIF_BUSSTS 0x0A24 -#define IO_EMIF_BUSWAITMD 0x0A26 -#define IO_EMIF_ECC1CP 0x0A28 -#define IO_EMIF_ECC1LP 0x0A2A -#define IO_EMIF_ECC2CP 0x0A2C -#define IO_EMIF_ECC2LP 0x0A2E -#define IO_EMIF_ECC3CP 0x0A30 -#define IO_EMIF_ECC3LP 0x0A32 -#define IO_EMIF_ECC4CP 0x0A34 -#define IO_EMIF_ECC4LP 0x0A36 -#define IO_EMIF_ECC5CP 0x0A38 -#define IO_EMIF_ECC5LP 0x0A3A -#define IO_EMIF_ECC6CP 0x0A3C -#define IO_EMIF_ECC6LP 0x0A3E -#define IO_EMIF_ECC7CP 0x0A40 -#define IO_EMIF_ECC7LP 0x0A42 -#define IO_EMIF_ECC8CP 0x0A44 -#define IO_EMIF_ECC8LP 0x0A46 -#define IO_EMIF_ECCCLR 0x0A48 -#define IO_EMIF_PAGESZ 0x0A4A -#define IO_EMIF_PRIORCTL 0x0A4C -#define IO_EMIF_MGDSPDEST 0x0A4E -#define IO_EMIF_MGDSPADDH 0x0A50 -#define IO_EMIF_MGDSPADDL 0x0A52 -#define IO_EMIF_AHBADDH 0x0A54 -#define IO_EMIF_AHBADDL 0x0A56 -#define IO_EMIF_MTCADDH 0x0A58 -#define IO_EMIF_MTCADDL 0x0A5A -#define IO_EMIF_DMASIZE 0x0A5C -#define IO_EMIF_DMAMTCSEL 0x0A5E -#define IO_EMIF_DMACTL 0x0A60 +#define IO_EMIF_CS0CTRL1 DM320_REG(0x0A00) +#define IO_EMIF_CS0CTRL2 DM320_REG(0x0A02) +#define IO_EMIF_CS0CTRL3 DM320_REG(0x0A04) +#define IO_EMIF_CS1CTRL1A DM320_REG(0x0A06) +#define IO_EMIF_CS1CTRL1B DM320_REG(0x0A08) +#define IO_EMIF_CS1CTRL2 DM320_REG(0x0A0A) +#define IO_EMIF_CS2CTRL1 DM320_REG(0x0A0C) +#define IO_EMIF_CS2CTRL2 DM320_REG(0x0A0E) +#define IO_EMIF_CS3CTRL1 DM320_REG(0x0A10) +#define IO_EMIF_CS3CTRL2 DM320_REG(0x0A12) +#define IO_EMIF_CS4CTRL1 DM320_REG(0x0A14) +#define IO_EMIF_CS4CTRL2 DM320_REG(0x0A16) +#define IO_EMIF_BUSCTRL DM320_REG(0x0A18) +#define IO_EMIF_BUSRLS DM320_REG(0x0A1A) +#define IO_EMIF_CFCTRL1 DM320_REG(0x0A1C) +#define IO_EMIF_CFCTRL2 DM320_REG(0x0A1E) +#define IO_EMIF_SMCTRL DM320_REG(0x0A20) +#define IO_EMIF_BUSINTEN DM320_REG(0x0A22) +#define IO_EMIF_BUSSTS DM320_REG(0x0A24) +#define IO_EMIF_BUSWAITMD DM320_REG(0x0A26) +#define IO_EMIF_ECC1CP DM320_REG(0x0A28) +#define IO_EMIF_ECC1LP DM320_REG(0x0A2A) +#define IO_EMIF_ECC2CP DM320_REG(0x0A2C) +#define IO_EMIF_ECC2LP DM320_REG(0x0A2E) +#define IO_EMIF_ECC3CP DM320_REG(0x0A30) +#define IO_EMIF_ECC3LP DM320_REG(0x0A32) +#define IO_EMIF_ECC4CP DM320_REG(0x0A34) +#define IO_EMIF_ECC4LP DM320_REG(0x0A36) +#define IO_EMIF_ECC5CP DM320_REG(0x0A38) +#define IO_EMIF_ECC5LP DM320_REG(0x0A3A) +#define IO_EMIF_ECC6CP DM320_REG(0x0A3C) +#define IO_EMIF_ECC6LP DM320_REG(0x0A3E) +#define IO_EMIF_ECC7CP DM320_REG(0x0A40) +#define IO_EMIF_ECC7LP DM320_REG(0x0A42) +#define IO_EMIF_ECC8CP DM320_REG(0x0A44) +#define IO_EMIF_ECC8LP DM320_REG(0x0A46) +#define IO_EMIF_ECCCLR DM320_REG(0x0A48) +#define IO_EMIF_PAGESZ DM320_REG(0x0A4A) +#define IO_EMIF_PRIORCTL DM320_REG(0x0A4C) +#define IO_EMIF_MGDSPDEST DM320_REG(0x0A4E) +#define IO_EMIF_MGDSPADDH DM320_REG(0x0A50) +#define IO_EMIF_MGDSPADDL DM320_REG(0x0A52) +#define IO_EMIF_AHBADDH DM320_REG(0x0A54) +#define IO_EMIF_AHBADDL DM320_REG(0x0A56) +#define IO_EMIF_MTCADDH DM320_REG(0x0A58) +#define IO_EMIF_MTCADDL DM320_REG(0x0A5A) +#define IO_EMIF_DMASIZE DM320_REG(0x0A5C) +#define IO_EMIF_DMAMTCSEL DM320_REG(0x0A5E) +#define IO_EMIF_DMACTL DM320_REG(0x0A60) /* Preivew Engine */ -#define IO_PREV_ENG_PVEN 0x0A80 +#define IO_PREV_ENG_PVEN DM320_REG(0x0A80) #define IO_PREV_ENG_PVSET1 0x0A82 #define IO_PREV_ENG_RADRH 0x0A84 #define IO_PREV_ENG_RADRL 0x0A86 @@ -623,27 +624,75 @@ /* Reserved 0x0C00 - 0x0CCFF */ /* Memory Stick Controller : */ -#define IO_MEM_STICK_MODE 0x0C80 -#define IO_MEM_STICK_CMD 0x0C82 -#define IO_MEM_STICK_DATA 0x0C84 -#define IO_MEM_STICK_STATUS 0x0C86 -#define IO_MEM_STICK_SYS 0x0C88 -#define IO_MEM_STICK_ENDIAN 0x0C8A -#define IO_MEM_STICK_INT_STATUS 0x0C8C -#define IO_MEM_STICK_DMA_TRG 0x0C8E -#define IO_MEM_STICK_DMA_MODE 0x0C90 -#define IO_MEM_STICK_SDRAM_ADDL 0x0C92 -#define IO_MEM_STICK_SDRAM_ADDH 0x0C94 -#define IO_MEM_STICK_DMA_STATUS 0x0C96 +#define IO_MEM_STICK_MODE 0x0C80 +#define IO_MEM_STICK_CMD 0x0C82 +#define IO_MEM_STICK_DATA 0x0C84 +#define IO_MEM_STICK_STATUS 0x0C86 +#define IO_MEM_STICK_SYS 0x0C88 +#define IO_MEM_STICK_ENDIAN 0x0C8A +#define IO_MEM_STICK_INT_STATUS 0x0C8C +#define IO_MEM_STICK_DMA_TRG 0x0C8E +#define IO_MEM_STICK_DMA_MODE 0x0C90 +#define IO_MEM_STICK_SDRAM_ADDL 0x0C92 +#define IO_MEM_STICK_SDRAM_ADDH 0x0C94 +#define IO_MEM_STICK_DMA_STATUS 0x0C96 /* ATM : WBB Need to find these Register values */ #define IO_ATM_ 0x0D00 /* I2C */ -#define IO_I2C_TXDATA 0x0D80 -#define IO_I2C_RXDATA 0x0D82 -#define IO_I2C_SCS 0x0D84 +#define IO_I2C_TXDATA DM320_REG(0x0D80) +#define IO_I2C_RXDATA DM320_REG(0x0D82) +#define IO_I2C_SCS DM320_REG(0x0D84) +/* VLYNQ */ +#define VL_ID DM320_REG(0x30300) +#define VL_CTRL DM320_REG(0x30304) +#define VL_STAT DM320_REG(0x30308) +#define VL_INTPRI DM320_REG(0x3030c) +#define VL_INTST DM320_REG(0x30310) +#define VL_INTPND DM320_REG(0x30314) +#define VL_INTPTR DM320_REG(0x30318) +#define VL_TXMAP DM320_REG(0x3031c) +#define VL_RXMAPSZ1 DM320_REG(0x30320) +#define VL_RXMAPOF1 DM320_REG(0x30324) +#define VL_RXMAPSZ2 DM320_REG(0x30328) +#define VL_RXMAPOF2 DM320_REG(0x3032c) +#define VL_RXMAPSZ3 DM320_REG(0x30330) +#define VL_RXMAPOF3 DM320_REG(0x30334) +#define VL_RXMAPSZ4 DM320_REG(0x30338) +#define VL_RXMAPOF4 DM320_REG(0x3033c) +#define VL_CHIPVER DM320_REG(0x30340) +#define VL_AUTONEG DM320_REG(0x30344) +#define VL_MANNEG DM320_REG(0x30348) +#define VL_NEGSTAT DM320_REG(0x3034c) +#define VL_ENDIAN DM320_REG(0x3035c) +#define VL_INTVEC30 DM320_REG(0x30360) +#define VL_INTVEC74 DM320_REG(0x30364) +#define VL_ID_R DM320_REG(0x30380) +#define VL_CTRL_R DM320_REG(0x30384) +#define VL_STAT_R DM320_REG(0x30388) +#define VL_INTPRI_R DM320_REG(0x3038c) +#define VL_INTST_R DM320_REG(0x30390) +#define VL_INTPND_R DM320_REG(0x30394) +#define VL_INTPTR_R DM320_REG(0x30398) +#define VL_TXMAP_R DM320_REG(0x3039c) +#define VL_RXMAPSZ1_R DM320_REG(0x303a0) +#define VL_RXMAPOF1_R DM320_REG(0x303a4) +#define VL_RXMAPSZ2_R DM320_REG(0x303a8) +#define VL_RXMAPOF2_R DM320_REG(0x303ac) +#define VL_RXMAPSZ3_R DM320_REG(0x303b0) +#define VL_RXMAPOF3_R DM320_REG(0x303b4) +#define VL_RXMAPSZ4_R DM320_REG(0x303b8) +#define VL_RXMAPOF4_R DM320_REG(0x303bc) +#define VL_CHIPVER_R DM320_REG(0x303c0) +#define VL_AUTONEG_R DM320_REG(0x303c4) +#define VL_MANNEG_R DM320_REG(0x303c8) +#define VL_NEGSTAT_R DM320_REG(0x303cc) +#define VL_ENDIAN_R DM320_REG(0x303dc) +#define VL_INTVEC30_R DM320_REG(0x303e0) +#define VL_INTVEC74_R DM320_REG(0x303e4) + /* Taken from linux/include/asm-arm/arch-itdm320/irqs.h * * Copyright (C) 1999 ARM Limited @@ -738,5 +787,117 @@ #define CONFIG_TIMER3_TMMD_TRG_READY 0x1000 #define CONFIG_TIMER3_TMMD_SIGNAL 0x2000 +/* + * IO_MODx bits + */ +#define CLK_MOD0_HPIB (1 << 11) +#define CLK_MOD0_DSP (1 << 10) +#define CLK_MOD0_EXTHOST (1 << 9) +#define CLK_MOD0_SDRAMC (1 << 8) +#define CLK_MOD0_EMIF (1 << 7) +#define CLK_MOD0_INTC (1 << 6) +#define CLK_MOD0_AIM (1 << 5) +#define CLK_MOD0_E2ICE (1 << 4) +#define CLK_MOD0_ETM (1 << 3) +#define CLK_MOD0_AHB (1 << 2) +#define CLK_MOD0_BUSC (1 << 1) +#define CLK_MOD0_ARM (1 << 0) +#define CLK_MOD1_CPBUS (1 << 11) +#define CLK_MOD1_SEQ (1 << 10) +#define CLK_MOD1_DCT (1 << 9) +#define CLK_MOD1_IMGBUF (1 << 8) +#define CLK_MOD1_IMX (1 << 7) +#define CLK_MOD1_VLCD (1 << 6) +#define CLK_MOD1_DAC (1 << 5) +#define CLK_MOD1_VENC (1 << 4) +#define CLK_MOD1_OSD (1 << 3) +#define CLK_MOD1_PRV (1 << 2) +#define CLK_MOD1_H3A (1 << 1) +#define CLK_MOD1_CCDC (1 << 0) + +#define CLK_MOD2_TEST (1 << 15) +#define CLK_MOD2_MS (1 << 14) +#define CLK_MOD2_VLYNQ (1 << 13) +#define CLK_MOD2_I2C (1 << 12) +#define CLK_MOD2_MMC (1 << 11) +#define CLK_MOD2_SIF1 (1 << 10) +#define CLK_MOD2_SIF0 (1 << 9) +#define CLK_MOD2_UART1 (1 << 8) +#define CLK_MOD2_UART0 (1 << 7) +#define CLK_MOD2_USB (1 << 6) +#define CLK_MOD2_GIO (1 << 5) +#define CLK_MOD2_CCDTMR1 (1 << 4) +#define CLK_MOD2_CCDTMR0 (1 << 3) +#define CLK_MOD2_TMR1 (1 << 2) +#define CLK_MOD2_TMR0 (1 << 1) +#define CLK_MOD2_WDT (1 << 0) + +/* + * IO_EINTx bits + */ +#define INTR_EINT0_USB1 (1 << 15) +#define INTR_EINT0_USB0 (1 << 14) +#define INTR_EINT0_UART1 (1 << 13) +#define INTR_EINT0_UART0 (1 << 12) +#define INTR_EINT0_IMGBUF (1 << 11) +#define INTR_EINT0_EXTHOST (1 << 10) +#define INTR_EINT0_SP1 (1 << 9) +#define INTR_EINT0_SP0 (1 << 8) +#define INTR_EINT0_VENC (1 << 7) +#define INTR_EINT0_CCDWEN (1 << 6) +#define INTR_EINT0_CCDVD1 (1 << 5) +#define INTR_EINT0_CCDVD0 (1 << 4) +#define INTR_EINT0_TMR3 (1 << 3) +#define INTR_EINT0_TMR2 (1 << 2) +#define INTR_EINT0_TMR1 (1 << 1) +#define INTR_EINT0_TMR0 (1 << 0) + +#define INTR_EINT1_EXT10 (1 << 15) +#define INTR_EINT1_EXT9 (1 << 14) +#define INTR_EINT1_EXT8 (1 << 13) +#define INTR_EINT1_EXT7 (1 << 12) +#define INTR_EINT1_EXT6 (1 << 11) +#define INTR_EINT1_EXT5 (1 << 10) +#define INTR_EINT1_EXT4 (1 << 9) +#define INTR_EINT1_EXT3 (1 << 8) +#define INTR_EINT1_EXT2 (1 << 7) +#define INTR_EINT1_EXT1 (1 << 6) +#define INTR_EINT1_EXT0 (1 << 5) +#define INTR_EINT1_MMCSDMS1 (1 << 4) +#define INTR_EINT1_MMCSDMS0 (1 << 3) +#define INTR_EINT1_MTC1 (1 << 2) +#define INTR_EINT1_MTC0 (1 << 1) +#define INTR_EINT1_VLYNQ (1 << 0) + +#define INTR_EINT2_RSVINT (1 << 13) +#define INTR_EINT2_ARMCOMTX (1 << 12) +#define INTR_EINT2_ARMCOMRX (1 << 11) +#define INTR_EINT2_E2ICE (1 << 10) +#define INTR_EINT2_INTRC (1 << 9) +#define INTR_EINT2_I2C (1 << 8) +#define INTR_EINT2_WDT (1 << 7) +#define INTR_EINT2_PREV1 (1 << 6) +#define INTR_EINT2_PREV0 (1 << 5) +#define INTR_EINT2_EXT15 (1 << 4) +#define INTR_EINT2_EXT14 (1 << 3) +#define INTR_EINT2_EXT13 (1 << 2) +#define INTR_EINT2_EXT12 (1 << 1) +#define INTR_EINT2_EXT11 (1 << 0) + +/* +* IO_IRQx bits +*/ +#define INTR_IRQ0_TMR0 INTR_EINT0_TMR0 +#define INTR_IRQ0_TMR1 INTR_EINT0_TMR1 +#define INTR_IRQ0_TMR2 INTR_EINT0_TMR2 +#define INTR_IRQ0_TMR3 INTR_EINT0_TMR3 +#define INTR_IRQ0_UART1 INTR_EINT0_UART1 +#define INTR_IRQ0_CCDVD1 INTR_EINT0_CCDVD1 +#define INTR_IRQ0_IMGBUF INTR_EINT0_IMGBUF + +#define INTR_IRQ1_EXT0 INTR_EINT1_EXT0 +#define INTR_IRQ1_EXT2 INTR_EINT1_EXT2 +#define INTR_IRQ1_EXT7 INTR_EINT1_EXT7 + #endif Index: firmware/export/config-creativezvm.h =================================================================== --- firmware/export/config-creativezvm.h (revision 16999) +++ firmware/export/config-creativezvm.h (working copy) @@ -65,16 +65,13 @@ /* Define this if your LCD can be enabled/disabled */ #define HAVE_LCD_ENABLE -#define LCD_REMOTE_PIXELFORMAT VERTICAL_PACKING +#define CONFIG_KEYPAD CREATIVEZVM_PAD +#define HAS_BUTTON_HOLD +#define HAVE_HEADPHONE_DETECTION +//#define HAVE_TOUCHPAD -#define MIN_REMOTE_CONTRAST_SETTING 0 -#define MAX_REMOTE_CONTRAST_SETTING 15 -#define DEFAULT_REMOTE_CONTRAST_SETTING 7 +#define CONFIG_I2C I2C_DM320 -#define CONFIG_KEYPAD MROBE500_PAD -//#define HAVE_TOUCHPAD -#define HAVE_BUTTON_DATA - /* Define this if you do software codec */ #define CONFIG_CODEC SWCODEC @@ -84,16 +81,17 @@ /* Define this for LCD backlight available */ //#define HAVE_BACKLIGHT -#define HAVE_BACKLIGHT_BRIGHTNESS +//#define HAVE_BACKLIGHT_BRIGHTNESS /* Main LCD backlight brightness range and defaults */ -#define MIN_BRIGHTNESS_SETTING 0 -#define MAX_BRIGHTNESS_SETTING 127 -#define DEFAULT_BRIGHTNESS_SETTING 85 /* OF "full brightness" */ -#define DEFAULT_DIMNESS_SETTING 22 /* OF "most dim" */ +//#define MIN_BRIGHTNESS_SETTING 0 +//#define MAX_BRIGHTNESS_SETTING 127 +//#define DEFAULT_BRIGHTNESS_SETTING 85 /* OF "full brightness" */ +//#define DEFAULT_DIMNESS_SETTING 22 /* OF "most dim" */ /* Define this if you have a software controlled poweroff */ -#define HAVE_SW_POWEROFF +//#define HAVE_SW_POWEROFF +//TODO: enable this back /* The number of bytes reserved for loadable codecs */ #define CODEC_SIZE 0x80000 @@ -104,11 +102,11 @@ /* Define this if you have the TLV320 audio codec */ //#define HAVE_TLV320 -/* Define this if you want to use the adaptive bass capibility of the 8751 */ -/* #define USE_ADAPTIVE_BASS */ +/* TLV320 has no tone controls, so we use the software ones */ +//#define HAVE_SW_TONE_CONTROLS -#define HW_SAMPR_CAPS (SAMPR_CAP_88 | SAMPR_CAP_44 | SAMPR_CAP_22 | \ - SAMPR_CAP_11) +/*#define HW_SAMPR_CAPS (SAMPR_CAP_88 | SAMPR_CAP_44 | SAMPR_CAP_22 | \ + SAMPR_CAP_11)*/ #define BATTERY_CAPACITY_DEFAULT 1100 /* default battery capacity */ #define BATTERY_CAPACITY_MIN 500 /* min. capacity selectable */ @@ -117,7 +115,7 @@ #define BATTERY_TYPES_COUNT 1 /* only one type */ /* Hardware controlled charging with monitoring */ -#define CONFIG_CHARGING CHARGING_MONITOR +//#define CONFIG_CHARGING CHARGING_MONITOR #ifndef SIMULATOR @@ -127,8 +125,7 @@ /* Define this if you have a Texas Instruments TSC2100 touch screen */ //#define HAVE_TSC2100 -/* Define this if you want to use coldfire's i2c interface */ -//#define CONFIG_I2C I2C_S3C2440 +#define CONFIG_USBOTG USBOTG_ISP1583 /* define this if the hardware can be powered off while charging */ #define HAVE_POWEROFF_WHILE_CHARGING @@ -161,4 +158,23 @@ #define BOOTFILE "rockbox." BOOTFILE_EXT #define BOOTDIR "/.rockbox" +#define HAVE_USBSTACK +#define USB_VENDOR_ID 0x041e +#define USB_PRODUCT_ID 0x4133 + +#define USB_SERIAL + +//DEBUGGING! +#ifdef BOOTLOADER +#define THREAD_EXTRA_CHECKS 1 +#define DEBUG 1 +#define debug(msg) printf(msg) +#define BUTTON_DEBUG + +#define DO_THREAD_TEST #endif + + +//Uncomment next line to make this build Zen Vision compatible +//#define ZEN_VISION +#endif Index: firmware/export/config.h =================================================================== --- firmware/export/config.h (revision 16999) +++ firmware/export/config.h (working copy) @@ -79,6 +79,7 @@ #define IAUDIO67_PAD 21 #define COWOND2_PAD 22 #define IAUDIO_M3_PAD 23 +#define CREATIVEZVM_PAD 24 /* CONFIG_REMOTE_KEYPAD */ #define H100_REMOTE 1 @@ -143,6 +144,7 @@ #define I2C_IMX31L 9 #define I2C_TCC77X 10 #define I2C_TCC780X 11 +#define I2C_DM320 12 /* CONFIG_LED */ #define LED_REAL 1 /* SW controlled LED (Archos recorders, player) */ @@ -168,6 +170,7 @@ /* USB On-the-go */ #define USBOTG_ISP1362 1362 /* iriver H300 */ +#define USBOTG_ISP1538 1538 /* Creative Zen Vision:M */ #define USBOTG_M5636 5636 /* iAudio X5 */ #define USBOTG_ARC 5020 /* PortalPlayer 502x */ Index: firmware/export/isp1583.h =================================================================== --- firmware/export/isp1583.h (revision 0) +++ firmware/export/isp1583.h (revision 0) @@ -0,0 +1,135 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2008 by Maurus Cuelenaere + * + * 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 ISP1583_H +#define ISP1583_H + +#ifndef ISP1583_H_OVERRIDE +/* Initialization registers */ +#define ISP1583_INIT_ADDRESS (*((volatile unsigned char*)(ISP1583_IOBASE+0x0))) +#define ISP1583_INIT_MODE (*((volatile unsigned char*)(ISP1583_IOBASE+0xC))) +#define ISP1583_INIT_INTCONF (*((volatile unsigned char*)(ISP1583_IOBASE+0x10))) +#define ISP1583_INIT_OTG (*((volatile unsigned char*)(ISP1583_IOBASE+0x12))) +#define ISP1583_INIT_INTEN (*((volatile unsigned int*)(ISP1583_IOBASE+0x14))) +/* Data Flow registers */ +#define ISP1583_DFLOW_EPINDEX (*((volatile unsigned char*)(ISP1583_IOBASE+0xC2))) +#define ISP1583_DFLOW_CTRLFUN (*((volatile unsigned char*)(ISP1583_IOBASE+0x28))) +#define ISP1583_DFLOW_DATA (*((volatile unsigned short*)(ISP1583_IOBASE+0x20))) +#define ISP1583_DFLOW_BUFLEN (*((volatile unsigned short*)(ISP1583_IOBASE+0x1C))) +#define ISP1583_DFLOW_BUFSTAT (*((volatile unsigned char*)(ISP1583_IOBASE+0x1E))) +#define ISP1583_DFLOW_MAXPKSZ (*((volatile unsigned short*)(ISP1583_IOBASE+0x04))) +#define ISP1583_DFLOW_EPTYPE (*((volatile unsigned short*)(ISP1583_IOBASE+0x08))) +/* DMA registers */ +#define ISP1583_DMA_ENDPOINT (*((volatile unsigned char*)(ISP1583_IOBASE+0x58))) +/* General registers */ +#define ISP1583_GEN_INT (*((volatile unsigned int*)(ISP1583_IOBASE+0x18))) +#define ISP1583_GEN_CHIPID (*((volatile unsigned int*)(ISP1583_IOBASE+0x70))) //Size=3 bytes +#define ISP1583_GEN_FRAMEN0 (*((volatile unsigned short*)(ISP1583_IOBASE+0x74))) +#define ISP1583_GEN_SCRATCH (*((volatile unsigned short*)(ISP1583_IOBASE+0x78))) +#define ISP1583_GEN_UNLCKDEV (*((volatile unsigned short*)(ISP1583_IOBASE+0x7C))) +#define ISP1583_GEN_TSTMOD (*((volatile unsigned char*)(ISP1583_IOBASE+0x84))) +#endif + +#define ISP1583_UNLOCK_CODE 0xaa37 + +/* Initialization registers' bits */ + +/* Initialization OTG register bits */ +#define INIT_OTG_BSESS_VALID (1 << 4) + +/* Initialization Mode register bits */ +#define INIT_MODE_TEST2 (1 << 15) +#define INIT_MODE_TEST1 (1 << 14) +#define INIT_MODE_TEST0 (1 << 13) +#define INIT_MODE_DMA (1 << 10) +#define INIT_MODE_CLKON (1 << 9) +#define INIT_MODE_VBUSSTAT (1 << 8) +#define INIT_MODE_CLKAON (1 << 7) +#define INIT_MODE_SNDRSU (1 << 6) +#define INIT_MODE_GOSUSP (1 << 5) +#define INIT_MODE_SFRESET (1 << 4) +#define INIT_MODE_GLINTENA (1 << 3) +#define INIT_MODE_WKUPCS (1 << 2) +#define INIT_MODE_PWRON (1 << 1) +#define INIT_MODE_SOFTCT (1 << 0) + +/* Initialization Interrupt Enable register bits */ +#define INIT_INTEN_IEP7TX (1 << 25) +#define INIT_INTEN_IEP7RX (1 << 24) +#define INIT_INTEN_IEP6TX (1 << 23) +#define INIT_INTEN_IEP6RX (1 << 22) +#define INIT_INTEN_IEP5TX (1 << 21) +#define INIT_INTEN_IEP5RX (1 << 20) +#define INIT_INTEN_IEP4TX (1 << 19) +#define INIT_INTEN_IEP4RX (1 << 18) +#define INIT_INTEN_IEP3TX (1 << 17) +#define INIT_INTEN_IEP3RX (1 << 16) +#define INIT_INTEN_IEP2TX (1 << 15) +#define INIT_INTEN_IEP2RX (1 << 14) +#define INIT_INTEN_IEP1TX (1 << 13) +#define INIT_INTEN_IEP1RX (1 << 12) +#define INIT_INTEN_IEP0TX (1 << 11) +#define INIT_INTEN_IEP0RX (1 << 10) +#define INIT_INTEN_IEP0SETUP (1 << 8) +#define INIT_INTEN_IEVBUS (1 << 7) +#define INIT_INTEN_IEDMA (1 << 6) +#define INIT_INTEN_IEHS_STA (1 << 5) +#define INIT_INTEN_IERESM (1 << 4) +#define INIT_INTEN_IESUSP (1 << 3) +#define INIT_INTEN_IEPSOF (1 << 2) +#define INIT_INTEN_IESOF (1 << 1) +#define INIT_INTEN_IEBRST (1 << 0) + +/* Initialization Interrupt Configuration register bits */ +#define INIT_INTCONF_INTLVL (1 << 1) +#define INIT_INTCONF_INTPOL (1 << 0) + +/* Initialization Address register bits */ +#define INIT_ADDRESS_DEVEN (1 << 7) + +/* Data Flow registers' bits */ + +/* Data Flow Endpoint Index register bits */ +#define DFLOW_EPINDEX_EP0SETUP (1 << 5) +#define DIR_RX 0 +#define DIR_TX 1 + +/* Data Flow Control Function register bits */ +#define DFLOW_CTRLFUN_CLBUF (1 << 4) +#define DFLOW_CTRLFUN_VENDP (1 << 3) +#define DFLOW_CTRLFUN_DSEN (1 << 2) +#define DFLOW_CTRLFUN_STATUS (1 << 1) +#define DFLOW_CTRLFUN_STALL (1 << 0) + +/* Data Flow Endpoint Type register bits */ +#define DFLOW_EPTYPE_NOEMPKT (1 << 4) +#define DFLOW_EPTYPE_ENABLE (1 << 3) +#define DFLOW_EPTYPE_DBLBUF (1 << 2) + +/* General registers' bits */ + +/* General Test Mode register bits */ +#define GEN_TSTMOD_FORCEHS (1 << 7) +#define GEN_TSTMOD_FORCEFS (1 << 4) +#define GEN_TSTMOD_PRBS (1 << 3) +#define GEN_TSTMOD_KSTATE (1 << 2) +#define GEN_TSTMOD_JSTATE (1 << 1) +#define GEN_TSTMOD_SE0_NAK (1 << 0) + + +#endif Index: firmware/kernel.c =================================================================== --- firmware/kernel.c (revision 16999) +++ firmware/kernel.c (working copy) @@ -432,6 +432,10 @@ unsigned stop = USEC_TIMER + ticks * (1000000/HZ); while (TIME_BEFORE(USEC_TIMER, stop)) switch_thread(); +#elif defined(CREATIVE_ZVM) && defined(BOOTLOADER) + long sleep_ticks = current_tick + ticks + 1; + while (sleep_ticks > current_tick) + yield(); #else disable_irq(); sleep_thread(ticks); Index: firmware/panic.c =================================================================== --- firmware/panic.c (revision 16999) +++ firmware/panic.c (working copy) @@ -126,6 +126,8 @@ #elif CONFIG_KEYPAD == ONDIO_PAD if (!(PCDR & 0x0008)) #endif /* CONFIG_KEYPAD */ +#elif defined(CREATIVE_ZVM) + if(false) #endif /* CPU */ system_reboot(); #endif /* !SIMULATOR */ Index: firmware/usbstack/usb_core.c =================================================================== --- firmware/usbstack/usb_core.c (revision 16999) +++ firmware/usbstack/usb_core.c (working copy) @@ -21,8 +21,13 @@ #include "kernel.h" #include "string.h" //#define LOGF_ENABLE -#include "logf.h" +//#include "logf.h" +#define USB_SERIAL +#undef USB_CHARGING_ONLY + +#define logf printf + #include "usb.h" #include "usb_ch9.h" #include "usb_drv.h" Index: firmware/usbstack/usb_serial.c =================================================================== --- firmware/usbstack/usb_serial.c (revision 16999) +++ firmware/usbstack/usb_serial.c (working copy) @@ -23,8 +23,11 @@ #include "kernel.h" //#define LOGF_ENABLE -#include "logf.h" +//#include "logf.h" +#define logf printf +#define USB_SERIAL + #ifdef USB_SERIAL /* serial interface */ Index: firmware/SOURCES =================================================================== --- firmware/SOURCES (revision 16999) +++ firmware/SOURCES (working copy) @@ -235,10 +235,14 @@ usbstack/usb_serial.c #ifdef CPU_PP502x target/arm/usb-drv-pp502x.c +#elif CONFIG_USBOTG == USBOTG_ISP1583 +drivers/isp1583.c #endif #else /* !defined(HAVE_USBSTACK) */ #if CONFIG_USBOTG == USBOTG_ISP1362 -drivers/isp1362.c +drivers/isp1362.c +#elif CONFIG_USBOTG == USBOTG_ISP1583 +drivers/isp1583.c #elif CONFIG_USBOTG == USBOTG_M5636 drivers/m5636.c #endif @@ -691,6 +695,31 @@ #endif /* SIMULATOR */ #endif /* MROBE_500 */ +#ifdef CREATIVE_ZVM +#ifndef SIMULATOR +target/arm/lcd-as-memframe.S +target/arm/mmu-arm.c +target/arm/tms320dm320/creative-zvm/adc-creativezvm.c +target/arm/tms320dm320/creative-zvm/audio-creativezvm.c +target/arm/tms320dm320/creative-zvm/lcd-creativezvm.c +target/arm/tms320dm320/creative-zvm/ata-creativezvm.c +target/arm/tms320dm320/creative-zvm/pcm-creativezvm.c +target/arm/tms320dm320/creative-zvm/pic-creativezvm.c +target/arm/tms320dm320/creative-zvm/power-creativezvm.c +target/arm/tms320dm320/creative-zvm/powermgmt-creativezvm.c +target/arm/tms320dm320/creative-zvm/usb-creativezvm.c +target/arm/tms320dm320/creative-zvm/usb-test.c +target/arm/tms320dm320/debug-dm320.c +target/arm/tms320dm320/i2c-dm320.c +target/arm/tms320dm320/kernel-dm320.c +target/arm/tms320dm320/spi-dm320.c +target/arm/tms320dm320/system-dm320.c +target/arm/tms320dm320/timer-dm320.c +target/arm/tms320dm320/uart-dm320.c +target/arm/tms320dm320/dsp-dm320.c +#endif /* SIMULATOR */ +#endif /* CREATIVE_ZVM */ + #ifdef MROBE_100 #ifndef SIMULATOR drivers/sw_i2c.c Index: firmware/target/arm/tms320dm320/uart-dm320.c =================================================================== --- firmware/target/arm/tms320dm320/uart-dm320.c (revision 16999) +++ firmware/target/arm/tms320dm320/uart-dm320.c (working copy) @@ -36,11 +36,11 @@ void uart_init(void) { // 8-N-1 - IO_UART1_MSR=0x8000; - IO_UART1_BRSR=0x0057; + IO_UART1_MSR = 0x8000; + IO_UART1_BRSR = 0x0057; IO_UART1_RFCR = 0x8010; /* Trigger later */ /* gio 27 is input, uart1 rx - gio 28 is output, uart1 tx */ + gio 28 is output, uart1 tx */ IO_GIO_DIR1 |= (1<<11); /* gio 27 */ IO_GIO_DIR1 &= ~(1<<12); /* gio 28 */ @@ -50,7 +50,7 @@ uart1_recieve_write=0; /* Enable the interrupt */ - IO_INTC_EINT0 |= (1< RECIEVE_RING_SIZE) - panicf("UART1 buffer overflow"); + panicf("UART1 buffer overflow"); else { if(uart1_recieve_write==RECIEVE_RING_SIZE) - uart1_recieve_write=0; + uart1_recieve_write=0; uart1_recieve_buffer_ring[uart1_recieve_write] = IO_UART1_DTRR & 0xff; uart1_recieve_write++; @@ -129,5 +129,5 @@ } } - IO_INTC_IRQ0 = (1< ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2007 by Karl Kurbjun - * - * 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. - * - ****************************************************************************/ +* __________ __ ___. +* Open \______ \ ____ ____ | | _\_ |__ _______ ___ +* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / +* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < +* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ +* \/ \/ \/ \/ \/ +* $Id$ +* +* Copyright (C) 2008 by Maurus Cuelenaere +* +* DM320 I²C driver +* +* 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 "system.h" +#include "thread.h" #include "i2c-dm320.h" -#if 0 -static int i2c_getack(void) +#define I2C_SCS_COND_START 0x0001 +#define I2C_SCS_COND_STOP 0x0002 +#define I2C_SCS_XMIT 0x0004 + +#define I2C_TX_ACK (1 << 20) + +static struct mutex i2c_mtx; + +static inline void i2c_begin(void) { - return 0; + mutex_lock(&i2c_mtx); } -static int i2c_start(void) +static inline void i2c_end(void) { - return 0; + mutex_unlock(&i2c_mtx); } -static void i2c_stop(void) +static inline bool i2c_getack(void) { + return (IO_I2C_RXDATA & 0x100)>>8; +} +#define WAIT_FOR_I2C if(IO_I2C_SCS & 0x4){ \ + while(IO_I2C_SCS & 0x4) { \ + asm volatile("nop"); \ + } \ + } \ + +static inline void i2c_start(void) +{ + IO_I2C_SCS |= I2C_SCS_XMIT; + return; } -static int i2c_outb(unsigned char byte) +int i2c_write(unsigned short address, const unsigned char *buf, int count) { - (void) byte; - return 0; + int i; + int ret=0; + i2c_begin(); + IO_I2C_TXDATA = ( (address << 1) & 0xFF ) | (address>0x7F ? 0 : 1 ) | I2C_TX_ACK; + IO_I2C_SCS &= ~0x3; //clear conditions + IO_I2C_SCS |= I2C_SCS_COND_START; // write 'start condition' + i2c_start(); + WAIT_FOR_I2C; + /* experimental */ + if(address>0x7F){ // check if it is 10-bit instead of 7-bit + IO_I2C_TXDATA = ( (address >> 7) & 0xFF) | I2C_TX_ACK; + IO_I2C_SCS &= ~0x3; //normal transfer + i2c_start(); + WAIT_FOR_I2C; + IO_I2C_TXDATA = ( (address << 1) & 0xFF) | 1 | I2C_TX_ACK; + IO_I2C_SCS &= ~0x3; //clear conditions + IO_I2C_SCS |= I2C_SCS_COND_START; //write 'start condition' + i2c_start(); + WAIT_FOR_I2C; + } + + for(i=0; i0x7F ? 0 : 1 ) | I2C_TX_ACK; + IO_I2C_SCS &= ~0x3; //clear conditions + IO_I2C_SCS |= I2C_SCS_COND_START; // write 'start condition' + i2c_start(); + WAIT_FOR_I2C; + /* experimental */ + if(address>0x7F){ // check if it is 10-bit instead of 7-bit + IO_I2C_TXDATA = ( (address >> 7) & 0xFF ) | I2C_TX_ACK; + IO_I2C_SCS &= ~0x3; //normal transfer + i2c_start(); + WAIT_FOR_I2C; + IO_I2C_TXDATA = ( (address << 1) & 0xFF ) | 1 | I2C_TX_ACK; + IO_I2C_SCS &= ~0x3; //clear conditions + IO_I2C_SCS |= I2C_SCS_COND_START; //write 'start condition' + i2c_start(); + WAIT_FOR_I2C; + } + + for(i=0; i> 8; + } + IO_I2C_SCS &= ~0x3; //clear conditions + IO_I2C_SCS |= I2C_SCS_COND_STOP; //write 'stop condition' + i2c_start(); + WAIT_FOR_I2C; + i2c_end(); + return ack; } void i2c_init(void) { - +#if 0 //TODO: mimic OF I2C clock settings; currently this is done by the bootloader + IO_CLK_MOD2 &= ~CLK_MOD2_I2C; // turn I²C clock off (just to be sure) + IO_CLK_LPCTL1 &= ~1; // set Powerdown mode to off + IO_CLK_SEL0 &= ~0x800; // set I²C clock to PLLA + IO_CLK_DIV4 &= ~0x1F; // I²C clock division = 1 + IO_CLK_MOD2 |= CLK_MOD2_I2C; // enable I²C clock +#endif + IO_I2C_SCS &= ~0x8; //set clock to 100 kHz + IO_INTC_EINT2 &= ~INTR_EINT2_I2C; // disable I²C interrupt } Index: firmware/target/arm/tms320dm320/timer-dm320.c =================================================================== --- firmware/target/arm/tms320dm320/timer-dm320.c (revision 16999) +++ firmware/target/arm/tms320dm320/timer-dm320.c (working copy) @@ -8,6 +8,7 @@ * $Id$ * * Copyright (C) 2007 by Karl Kurbjun +* Copyright (C) 2008 by Maurus Cuelenaere * * 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. @@ -24,12 +25,12 @@ #include "logf.h" /* GPB0/TOUT0 should already have been configured as output so that pin - should not be a functional pin and TIMER0 output unseen there */ + should not be a functional pin and TIMER0 output unseen there */ void TIMER0(void) { if (pfn_timer != NULL) pfn_timer(); - IO_INTC_IRQ0 |= 1< ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2007 by Karl Kurbjun - * - * 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. - * - ****************************************************************************/ +* __________ __ ___. +* Open \______ \ ____ ____ | | _\_ |__ _______ ___ +* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / +* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < +* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ +* \/ \/ \/ \/ \/ +* $Id$ +* +* Copyright (C) 2007 by Karl Kurbjun +* +* 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 "system.h" @@ -27,21 +27,25 @@ void tick_start(unsigned int interval_in_ms) { +/* TODO: set up TIMER1 clock settings + IO_CLK_MOD2 &= ~CLK_MOD2_TMR1; //disable TIMER1 clock + IO_CLK_SEL0 |= (1 << 2); //set TIMER1 clock to PLLIN*/ + IO_CLK_MOD2 |= CLK_MOD2_TMR1; //enable TIMER1 clock!!!!!!!!! IO_TIMER1_TMMD = CONFIG_TIMER1_TMMD_STOP; /* Setup the Prescalar (Divide by 10) - * Based on linux/include/asm-arm/arch-integrator/timex.h - */ + * Based on linux/include/asm-arm/arch-integrator/timex.h + */ IO_TIMER1_TMPRSCL = 0x0009; /* Setup the Divisor */ - IO_TIMER1_TMDIV = (TIMER_FREQ / (10*1000))*interval_in_ms; - + IO_TIMER1_TMDIV = (TIMER_FREQ / (10*1000))*interval_in_ms - 1; + /* Turn Timer1 to Free Run mode */ IO_TIMER1_TMMD = CONFIG_TIMER1_TMMD_FREE_RUN; - + /* Enable the interrupt */ - IO_INTC_EINT0 |= 1< ) \___| < | \_\ ( <_> > < < * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ * \/ \/ \/ \/ \/ - * $Id: i2c-meg-fx.h 13720 2007-06-26 02:11:30Z jethead71 $ + * $Id$ * - * Copyright (C) 2007 by Michael Sevakis + * Copyright (C) 2008 by Maurus Cuelenaere * * 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. @@ -17,28 +17,7 @@ * ****************************************************************************/ -/* chip-specific i2c functions */ - -/* IICCON */ -#define I2C_ACKGEN (1 << 7) -#define I2C_TXCLK_512 (1 << 6) -#define I2C_TXRX_INTENB (1 << 5) -#define I2C_TXRX_INTPND (1 << 4) - -/* IICSTAT */ -#define I2C_MODE_MASTER (2 << 6) -#define I2C_MODE_TX (1 << 6) -#define I2C_BUSY (1 << 5) -#define I2C_START (1 << 5) -#define I2C_RXTX_ENB (1 << 4) -#define I2C_BUS_ARB_FAILED (1 << 3) -#define I2C_S_ADDR_STAT (1 << 2) -#define I2C_S_ADDR_MATCH (1 << 1) -#define I2C_ACK_L (1 << 0) - -/* IICLC */ -#define I2C_FLT_ENB (1 << 2) - void i2c_init(void); -void i2c_write(int addr, const unsigned char *data, int count); +int i2c_write(unsigned short address, const unsigned char *data, int count); +int i2c_read(unsigned short address, unsigned char* buf, int count); Index: firmware/target/arm/tms320dm320/system-dm320.c =================================================================== --- firmware/target/arm/tms320dm320/system-dm320.c (revision 16999) +++ firmware/target/arm/tms320dm320/system-dm320.c (working copy) @@ -8,6 +8,7 @@ * $Id$ * * Copyright (C) 2007 by Karl Kurbjun + * Copyright (C) 2008 by Maurus Cuelenaere * * 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. @@ -114,7 +115,12 @@ asm volatile( "stmfd sp!, {r0-r7, ip, lr} \n" /* Store context */ "sub sp, sp, #8 \n"); /* Reserve stack */ - irqvector[(IO_INTC_IRQENTRY0>>2)-1](); + unsigned short addr = IO_INTC_IRQENTRY0>>2; + if(addr != 0) + { + addr--; + irqvector[addr](); + } asm volatile( "add sp, sp, #8 \n" /* Cleanup stack */ "ldmfd sp!, {r0-r7, ip, lr} \n" /* Restore context */ "subs pc, lr, #4 \n"); /* Return from FIQ */ @@ -130,18 +136,33 @@ "sub lr, lr, #4 \r\n" "stmfd sp!, {r0-r3, ip, lr} \r\n" "mov r0, #0x00030000 \r\n" - "ldr r0, [r0, #0x518] \r\n" + "ldr r0, [r0, #0x518] \r\n" + "sub r0, r0, #1 \r\n" "ldr r1, =irqvector \r\n" "ldr r1, [r1, r0, lsl #2] \r\n" - "mov lr, pc \r\n" - "bx r1 \r\n" + "blx r1 \r\n" "ldmfd sp!, {r0-r3, ip, pc}^ \r\n" ); } void system_reboot(void) { - + /* Code taken from linux/include/asm-arm/arch-itdm320-20/system.h at NeuroSVN */ + __asm__ __volatile__( + "mov ip, #0 \n" + "mcr p15, 0, ip, c7, c7, 0 @ invalidate cache \n" + "mcr p15, 0, ip, c8, c7, 0 @ flush TLB (v4) \n" + "mrc p15, 0, ip, c1, c0, 0 @ get ctrl register\n" + "bic ip, ip, #0x000f @ ............wcam \n" + "bic ip, ip, #0x2100 @ ..v....s........ \n" + "mcr p15, 0, ip, c1, c0, 0 @ ctrl register \n" + "mov ip, #0xFF000000 \n" + "orr ip, ip, #0xFF0000 @ ip = 0xFFFF0000 \n" + "mov pc, ip \n" + : + : + : "cc" + ); } void system_init(void) @@ -167,16 +188,28 @@ IO_INTC_FISEL1 = 0; IO_INTC_FISEL2 = 0; + /* IRQENTRY only reflects enabled interrupts */ + IO_INTC_RAW = 0; + IO_INTC_ENTRY_TBA0 = 0; IO_INTC_ENTRY_TBA1 = 0; - /* Turn off other timers */ + unsigned short i; + /* Reset interrupt priorities to default values */ + for(i = 0; i < 23; i++) + DM320_REG(0x0540+i*2) = ( (i*2+1) << 8 ) | i*2 ;//IO_INTC_PRIORITYx + + /* Turn off all timers */ + IO_TIMER0_TMMD = CONFIG_TIMER0_TMMD_STOP; + IO_TIMER1_TMMD = CONFIG_TIMER1_TMMD_STOP; IO_TIMER2_TMMD = CONFIG_TIMER2_TMMD_STOP; IO_TIMER3_TMMD = CONFIG_TIMER3_TMMD_STOP; +#ifndef CREATIVE_ZVM /* set GIO26 (reset pin) to output and low */ IO_GIO_BITCLR1=(1<<10); IO_GIO_DIR1&=~(1<<10); +#endif uart_init(); spi_init(); @@ -186,9 +219,18 @@ /* Make sure everything is mapped on itself */ map_section(0, 0, 0x1000, CACHE_NONE); /* Enable caching for RAM */ - map_section(0x00900000, 0x00900000, 64, CACHE_ALL); + map_section(CONFIG_SDRAM_START, CONFIG_SDRAM_START, MEM, CACHE_ALL); /* enable buffered writing for the framebuffer */ map_section((int)FRAME, (int)FRAME, 1, BUFFERED); +#ifdef CREATIVE_ZVM + //mimic OF + map_section(0x00100000, 0x00100000, 4, CACHE_NONE); + map_section(0x04700000, 0x04700000, 2, BUFFERED); + map_section(0x40000000, 0x40000000, 16, CACHE_NONE); + map_section(0x50000000, 0x50000000, 16, CACHE_NONE); + map_section(0x60000000, 0x60000000, 16, CACHE_NONE); + map_section(0x80000000, 0x80000000, 1, CACHE_NONE); +#endif enable_mmu(); } Index: firmware/target/arm/tms320dm320/dsp-dm320.c =================================================================== --- firmware/target/arm/tms320dm320/dsp-dm320.c (revision 16999) +++ firmware/target/arm/tms320dm320/dsp-dm320.c (working copy) @@ -23,27 +23,22 @@ #include "string.h" #include "dsp-target.h" -/* A "DSP image" is an array of these, terminated by raw_data_size_half = 0. */ -struct dsp_section { - const unsigned short *raw_data; - unsigned short physical_addr; - unsigned short raw_data_size_half; -}; - /* Must define struct dsp_section before including the image. */ #include "dsp_image_helloworld.h" #ifdef DEBUG -static void dsp_status(void) +void dsp_status(void) { unsigned short hpib_ctl = IO_DSPC_HPIB_CONTROL; unsigned short hpib_stat = IO_DSPC_HPIB_STATUS; char buffer1[80], buffer2[80]; - DEBUGF("dsp_status(): clkc_hpib=%u clkc_dsp=%u", - !!(IO_CLK_MOD0 & (1 << 11)), !!(IO_CLK_MOD0 & (1 << 10))); + DEBUGF("[dsp_status()]"); - DEBUGF("dsp_status(): irq_dsphint=%u 7fff=%04x scratch_status=%04x" + DEBUGF("clkc_hpib=%u clkc_dsp=%u", + !!(IO_CLK_MOD0 & CLK_MOD0_HPIB), !!(IO_CLK_MOD0 & CLK_MOD0_DSP)); + + DEBUGF("irq_dsphint=%u 7fff=%04x scratch_status=%04x" " acked=%04x", (IO_INTC_IRQ0 >> IRQ_DSPHINT) & 1, DSP_(0x7fff), DSP_(_status), DSP_(_acked)); @@ -63,8 +58,26 @@ B(buffer2, hpib_stat, 8, HOLDA); B(buffer2, hpib_stat, 12, DXF); - DEBUGF("dsp_status(): hpib: ctl=%s stat=%s", buffer1, buffer2); + DEBUGF("hpib: ctl=%s stat=%s", buffer1, buffer2); #undef B + DEBUGF("scratch_status=%04x" + " acked=%04x", + DSP_(_status), + DSP_(_acked)); + DSP_(_status) = 0x01; + hpib_ctl = DSP_(_acked); + while(DSP_(_acked) == hpib_ctl) + DEBUGF("scratch_status=%04x" + " acked=%04x", + DSP_(_status), + DSP_(_acked)); + DSP_(_status) = 0x02; + hpib_ctl = DSP_(_acked); + while(DSP_(_acked) == hpib_ctl); + DEBUGF("scratch_status=%04x" + " acked=%04x", + DSP_(_status), + DSP_(_acked)); } #endif @@ -72,10 +85,10 @@ { DSP_(0x7fff) = 0xdead; - IO_DSPC_HPIB_CONTROL &= ~(1 << 8); + IO_DSPC_HPIB_CONTROL &= ~HPIB_CTL_DRST; /* HPIB bus cycles will lock up the ARM in here. Don't touch DSP RAM. */ nop; nop; - IO_DSPC_HPIB_CONTROL |= 1 << 8; + IO_DSPC_HPIB_CONTROL |= HPIB_CTL_DRST; /* TODO: Timeout. */ while (DSP_(0x7fff) != 0); @@ -89,9 +102,9 @@ /* The first time you INT0 the DSP, the ROM loader will branch to your RST handler. Subsequent times, your INT0 handler will get executed. */ - IO_DSPC_HPIB_CONTROL &= ~(1 << 7); + IO_DSPC_HPIB_CONTROL &= ~HPIB_CTL_DINT0; nop; nop; - IO_DSPC_HPIB_CONTROL |= 1 << 7; + IO_DSPC_HPIB_CONTROL |= HPIB_CTL_DINT0; restore_irq(old_level); } @@ -127,13 +140,16 @@ void dsp_init(void) { - IO_INTC_IRQ0 = 1 << 11; - IO_INTC_EINT0 |= 1 << 11; + IO_INTC_IRQ0 = INTR_IRQ0_IMGBUF; + IO_INTC_EINT0 |= INTR_EINT0_IMGBUF; - IO_DSPC_HPIB_CONTROL = 1 << 10 | 1 << 9 | 1 << 8 | 1 << 7 | 1 << 3 | 1 << 0; + IO_CLK_MOD0 |= CLK_MOD0_DSP | CLK_MOD0_HPIB; + + IO_DSPC_HPIB_CONTROL = HPIB_CTL_DBIO | HPIB_CTL_DHOLD | HPIB_CTL_DRST | HPIB_CTL_DINT0 | HPIB_CTL_HPNMI | HPIB_CTL_HPIEN; dsp_reset(); dsp_load(dsp_image_helloworld); + dsp_wake(); } void DSPHINT(void) @@ -141,7 +157,7 @@ unsigned int i; char buffer[80]; - IO_INTC_IRQ0 = 1 << 11; + IO_INTC_IRQ0 = INTR_IRQ0_IMGBUF; /* DSP stores one character per word. */ for (i = 0; i < sizeof(buffer); i++) { Index: firmware/target/arm/tms320dm320/debug-dm320.c =================================================================== --- firmware/target/arm/tms320dm320/debug-dm320.c (revision 16999) +++ firmware/target/arm/tms320dm320/debug-dm320.c (working copy) @@ -8,6 +8,7 @@ * $Id$ * * Copyright (C) 2007 by Karl Kurbjun + * Copyright (C) 2008 by Maurus Cuelenaere * * 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. @@ -33,12 +34,17 @@ return false; } +#ifndef CREATIVE_ZVM extern char r_buffer[5]; extern int r_button; +#endif bool __dbg_hw_info(void) { - int line = 0, button, oldline; + int line = 0, oldline; +#ifndef CREATIVE_ZVM + int button; int *address=0x0; +#endif bool done=false; char buf[100]; @@ -58,12 +64,25 @@ IO_CLK_DIV3, IO_CLK_DIV4, IO_CLK_BYP, IO_CLK_INV); lcd_puts(0, line++, buf); snprintf(buf, sizeof(buf), "IO_CLK_MOD0: 0x%04x IO_CLK_MOD1: 0x%04x IO_CLK_MOD2: 0x%04x IO_CLK_LPCTL0: 0x%04x", IO_CLK_MOD0, IO_CLK_MOD1, IO_CLK_MOD2, IO_CLK_LPCTL0); lcd_puts(0, line++, buf); + + lcd_puts(0, line++, "Board revision:"); + switch (IO_BUSC_REVR) { + case 0x0010: + lcd_puts(0, line++, "DM320 Rev. A"); + break; + case 0x0011: + lcd_puts(0, line++, "DM320 Rev. B/C"); + break; + default: + lcd_puts(0, line++, "Unknown DM320 Chip ID"); + } line++; oldline=line; while(!done) { line = oldline; +#ifndef CREATIVE_ZVM button = button_get(false); button&=~BUTTON_REPEAT; if (button == BUTTON_POWER) @@ -81,14 +100,17 @@ r_buffer[0], r_buffer[1], r_buffer[2], r_buffer[3],r_buffer[4] ); lcd_puts(0, line++, buf); snprintf(buf, sizeof(buf), "Button: 0x%08x, HWread: 0x%08x", (unsigned int)button, r_button); lcd_puts(0, line++, buf); +#endif snprintf(buf, sizeof(buf), "current tick: %08x Seconds running: %08d", (unsigned int)current_tick, (unsigned int)current_tick/100); lcd_puts(0, line++, buf); +#ifndef CREATIVE_ZVM snprintf(buf, sizeof(buf), "Address: 0x%08x Data: 0x%08x", (unsigned int)address, *address); lcd_puts(0, line++, buf); snprintf(buf, sizeof(buf), "Address: 0x%08x Data: 0x%08x", (unsigned int)(address+1), *(address+1)); lcd_puts(0, line++, buf); snprintf(buf, sizeof(buf), "Address: 0x%08x Data: 0x%08x", (unsigned int)(address+2), *(address+2)); lcd_puts(0, line++, buf); +#endif lcd_update(); } Index: firmware/target/arm/tms320dm320/system-target.h =================================================================== --- firmware/target/arm/tms320dm320/system-target.h (revision 16999) +++ firmware/target/arm/tms320dm320/system-target.h (working copy) @@ -26,4 +26,6 @@ #define CPUFREQ_NORMAL 30000000 #define CPUFREQ_MAX 80000000 +#define UNCACHED_ADDR(a) a + #endif /* SYSTEM_TARGET_H */ Index: firmware/target/arm/tms320dm320/spi-dm320.c =================================================================== --- firmware/target/arm/tms320dm320/spi-dm320.c (revision 16999) +++ firmware/target/arm/tms320dm320/spi-dm320.c (working copy) @@ -31,6 +31,7 @@ #define GIO_TS_ENABLE (1<<2) #define GIO_RTC_ENABLE (1<<12) #define GIO_BL_ENABLE (1<<13) +#define GIO_LCD_ENABLE (1<<5) struct mutex spi_mtx; @@ -42,9 +43,12 @@ #define reg(a) ((volatile unsigned short *)(PHY_IO_BASE+a)) struct SPI_info spi_targets[] = { +#ifndef CREATIVE_ZVM [SPI_target_TSC2100] = { &IO_GIO_BITCLR1, &IO_GIO_BITSET1, GIO_TS_ENABLE }, - [SPI_target_RX5X348AB] = { &IO_GIO_BITSET0, &IO_GIO_BITCLR0, GIO_RTC_ENABLE }, + [SPI_target_RX5X348AB] = { &IO_GIO_BITSET0, &IO_GIO_BITCLR0, GIO_RTC_ENABLE}, [SPI_target_BACKLIGHT] = { &IO_GIO_BITCLR1, &IO_GIO_BITSET1, GIO_BL_ENABLE }, +#endif + [SPI_target_LTV250QV] = { &IO_GIO_BITCLR2, &IO_GIO_BITSET2, GIO_LCD_ENABLE}, }; static void spi_disable_all_targets(void) @@ -98,11 +102,12 @@ IO_SERIAL0_MODE |= 1<<10; /* Enable TX */ IO_SERIAL0_TX_ENABLE = 0x0001; - +#ifndef CREATIVE_ZVM /* Set GIO 18 to output for touch screen slave enable */ IO_GIO_DIR1 &= ~GIO_TS_ENABLE; /* Set GIO 12 to output for rtc slave enable */ IO_GIO_DIR0 &= ~GIO_RTC_ENABLE; - +#endif spi_disable_all_targets(); /* make sure only one is ever enabled at a time */ + } Index: firmware/target/arm/tms320dm320/dsp-target.h =================================================================== --- firmware/target/arm/tms320dm320/dsp-target.h (revision 16999) +++ firmware/target/arm/tms320dm320/dsp-target.h (working copy) @@ -23,6 +23,21 @@ /* DSP memory is mapped into ARM space via HPIB. */ #define DSP_(addr) (*(volatile unsigned short *)(0x40000 + ((addr) << 1))) +/* A "DSP image" is an array of these, terminated by raw_data_size_half = 0. */ +struct dsp_section { + const unsigned short *raw_data; + unsigned short physical_addr; + unsigned short raw_data_size_half; +}; + +#define HPIB_CTL_DBIO (1 << 10) +#define HPIB_CTL_DHOLD (1 << 9) +#define HPIB_CTL_DRST (1 << 8) +#define HPIB_CTL_DINT0 (1 << 7) +#define HPIB_CTL_EXCHG (1 << 5) +#define HPIB_CTL_HPNMI (1 << 3) +#define HPIB_CTL_HPIEN (1 << 0) + void dsp_init(void); void dsp_wake(void); Index: firmware/target/arm/tms320dm320/spi-target.h =================================================================== --- firmware/target/arm/tms320dm320/spi-target.h (revision 16999) +++ firmware/target/arm/tms320dm320/spi-target.h (working copy) @@ -27,6 +27,7 @@ SPI_target_TSC2100 = 0, SPI_target_RX5X348AB, SPI_target_BACKLIGHT, + SPI_target_LTV250QV, SPI_MAX_TARGETS, }; Index: firmware/target/arm/tms320dm320/dsp_image_helloworld.h =================================================================== --- firmware/target/arm/tms320dm320/dsp_image_helloworld.h (revision 16999) +++ firmware/target/arm/tms320dm320/dsp_image_helloworld.h (working copy) @@ -19,13 +19,20 @@ * MA 02111-1307 USA * */ +static const unsigned short helloworld_data[] = { +0x4A11, 0x7711, 0x0200, 0x7681, 0xDEAD, 0x6081, 0xDEAD, 0xF820, 0x0021, 0x6081, 0xDEAD, 0xF830, 0x0009, 0xF073, 0x0021, 0x7711, +0x0300, 0xF273, 0x0001, 0x7681, 0x0001, 0x7711, 0x0300, 0xF273, 0x0001, 0x7681, 0x0002, 0x7711, 0x0300, 0xF273, 0x0001, 0x7681, +0x00FF, 0x1181, 0x7711, 0x0001, 0x10F8, 0x000B, 0x08F8, 0x0011, 0xF845, 0x000F, 0x7711, 0x0002, 0x10F8, 0x000B, 0x08F8, 0x0011, +0xF845, 0x0015, 0xF073, 0x001B +}; static const struct dsp_section dsp_image_helloworld[] = { - {NULL, 0, 0} + {helloworld_data, 0x07F80, sizeof(helloworld_data)/sizeof(unsigned short)}, + {NULL, 0, 0} }; /* Symbol table, usable with the DSP_() macro (see dsp-target.h). */ -#define _status 0x0000 -#define _acked 0x0000 +#define _status 0x0200 +#define _acked 0x0300 #endif Index: firmware/target/arm/tms320dm320/crt0.S =================================================================== --- firmware/target/arm/tms320dm320/crt0.S (revision 16999) +++ firmware/target/arm/tms320dm320/crt0.S (working copy) @@ -159,7 +159,7 @@ and r4, pc, r2 /* Copy bootloader to safe area - 0x01900000 */ - mov r5, #0x01900000 + mov r5, #0x1900000 ldr r6, = _dataend sub r0, r6, r5 /* length of loader */ add r0, r4, r0 /* r0 points to start of loader */ Index: firmware/target/arm/tms320dm320/creative-zvm/audio-creativezvm.c =================================================================== --- firmware/target/arm/tms320dm320/creative-zvm/audio-creativezvm.c (revision 0) +++ firmware/target/arm/tms320dm320/creative-zvm/audio-creativezvm.c (revision 0) @@ -0,0 +1,44 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: audio-c200_e200.c 14624 2007-09-06 03:01:41Z lowlight $ + * + * Copyright (C) 2007 by Michael Sevakis + * + * 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 "cpu.h" +#include "kernel.h" +#include "sound.h" + +const struct sound_settings_info audiohw_settings[] = { + [SOUND_VOLUME] = {"dB", 0, 1, -74, 6, -25}, + [SOUND_BASS] = {"dB", 1, 15, -60, 90, 0}, + [SOUND_TREBLE] = {"dB", 1, 15, -60, 90, 0}, + [SOUND_BALANCE] = {"%", 0, 1,-100, 100, 0}, + [SOUND_CHANNELS] = {"", 0, 1, 0, 5, 0}, + [SOUND_STEREO_WIDTH] = {"%", 0, 5, 0, 250, 100}, +}; + + +void audiohw_init(void) +{ +} + +void audiohw_close(void) +{ +} + +void audiohw_mute(bool mute) +{ + (void) mute; +} Index: firmware/target/arm/tms320dm320/creative-zvm/ata-target.h =================================================================== --- firmware/target/arm/tms320dm320/creative-zvm/ata-target.h (revision 0) +++ firmware/target/arm/tms320dm320/creative-zvm/ata-target.h (revision 0) @@ -0,0 +1,68 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2007 by Maurus Cuelenaere + * + * 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 + +/* Plain C read & write loops */ +#define PREFER_C_READING +#define PREFER_C_WRITING + +#define ATA_IOBASE 0x50FEE000 +#define ATA_DATA (*((volatile unsigned short*)(ATA_IOBASE))) +#define ATA_ERROR (*((volatile unsigned char*)(ATA_IOBASE+0x2))) +#define ATA_NSECTOR (*((volatile unsigned char*)(ATA_IOBASE+0x4))) +#define ATA_SECTOR (*((volatile unsigned char*)(ATA_IOBASE+0x6))) +#define ATA_LCYL (*((volatile unsigned char*)(ATA_IOBASE+0x8))) +#define ATA_HCYL (*((volatile unsigned char*)(ATA_IOBASE+0xA))) +#define ATA_SELECT (*((volatile unsigned char*)(ATA_IOBASE+0xC))) +#define ATA_COMMAND (*((volatile unsigned char*)(ATA_IOBASE+0xE))) +#define ATA_CONTROL (*((volatile unsigned char*)(ATA_IOBASE+0x800C))) + +#define STATUS_BSY 0x80 +#define STATUS_RDY 0x40 +#define STATUS_DF 0x20 +#define STATUS_DRQ 0x08 +#define STATUS_ERR 0x01 +#define ERROR_ABRT 0x04 + +#define WRITE_PATTERN1 0xa5 +#define WRITE_PATTERN2 0x5a +#define WRITE_PATTERN3 0xaa +#define WRITE_PATTERN4 0x55 + +#define READ_PATTERN1 0xa5 +#define READ_PATTERN2 0x5a +#define READ_PATTERN3 0xaa +#define READ_PATTERN4 0x55 + +#define READ_PATTERN1_MASK 0xff +#define READ_PATTERN2_MASK 0xff +#define READ_PATTERN3_MASK 0xff +#define READ_PATTERN4_MASK 0xff + +#define SET_REG(reg,val) reg = (val) +#define SET_16BITREG(reg,val) reg = (val) + +void ata_reset(void); +void ata_device_init(void); +bool ata_is_coldstart(void); +void ide_power_enable(bool on); + +#endif Index: firmware/target/arm/tms320dm320/creative-zvm/lcd-creativezvm.c =================================================================== --- firmware/target/arm/tms320dm320/creative-zvm/lcd-creativezvm.c (revision 0) +++ firmware/target/arm/tms320dm320/creative-zvm/lcd-creativezvm.c (revision 0) @@ -0,0 +1,385 @@ +/*************************************************************************** +* __________ __ ___. +* Open \______ \ ____ ____ | | _\_ |__ _______ ___ +* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / +* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < +* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ +* \/ \/ \/ \/ \/ +* $Id$ +* +* Copyright (C) 2008 by Maurus Cuelenaere +* +* 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 "memory.h" +#include "cpu.h" +#include "spi.h" +#include "spi-target.h" +#include "lcd-target.h" + +/* Power and display status */ +static bool display_on = false; /* Is the display turned on? */ + +int lcd_default_contrast(void) +{ + return 0x1f; +} + +void lcd_set_contrast(int val) +{ + /* iirc there is an ltv250qv command to do this */ + #warning function not implemented + (void)val; +} + +void lcd_set_invert_display(bool yesno) { + (void) yesno; + // TODO: +} + +void lcd_set_flip(bool yesno) { + (void) yesno; + // TODO: +} + + +/* LTV250QV panel functions */ + +static void lcd_write_reg(unsigned char reg, unsigned short val) +{ + unsigned char block[3]; + block[0] = 0x74; + block[1] = 0; + block[2] = reg | 0xFF; + spi_block_transfer(SPI_target_LTV250QV, block, sizeof(block), NULL, 0); + block[0] = 0x76; + block[1] = (val >> 8) & 0xFF; + block[2] = val & 0xFF; + spi_block_transfer(SPI_target_LTV250QV, block, sizeof(block), NULL, 0); +} + +static void sleep_ms(unsigned int ms) +{ + unsigned int temp = current_tick; + while(current_tick> 16; + IO_OSD_OSDWIN0ADL=addr & 0xFFFF; + +#ifndef ZEN_VISION + IO_OSD_BASEPX=26; + IO_OSD_BASEPY=5; +#else + IO_OSD_BASEPX=80; + IO_OSD_BASEPY=0; +#endif + + IO_OSD_OSDWIN0XP=0; + IO_OSD_OSDWIN0YP=0; + IO_OSD_OSDWIN0XL=LCD_WIDTH; + IO_OSD_OSDWIN0YL=LCD_HEIGHT; +#if 0 + //TODO: set LCD clock! + IO_CLK_MOD1 &= ~0x18; // disable OSD clock and VENC clock + IO_CLK_02DIV = 3; + IO_CLK_OSEL = (IO_CLK_OSEL & ~0xF00) | 0x400; // reset 'General purpose clock output (GIO26, GIO34)' and set to 'PLLIN clock' + IO_CLK_SEL1 = (IO_CLK_SEL1 | 7) | 0x1000; // set to 'GP clock output 2 (GIO26, GIO34)' and turn on 'VENC clock' + IO_CLK_MOD1 |= 0x18; // enable OSD clock and VENC clock + + /* Set LCD values in OSD */ + IO_VID_ENC_VMOD = ( ( (IO_VID_ENC_VMOD & 0xFFFF8C00) | 0x14) | 0x2400 ); // disable NTSC/PAL encoder & set mode to RGB666 parallel 18 bit + IO_VID_ENC_VDCTL = ( ( (IO_VID_ENC_VDCTL & 0xFFFFCFE8) | 0x20) | 0x4000 ); + //TODO: finish this... +#endif + set_irq_level(oldlevel); +} + + +/*** Update functions ***/ + + + +/* Update a fraction of the display. */ +void lcd_update_rect(int x, int y, int width, int height) +{ + register fb_data *dst, *src; + + if (!display_on) + return; + + if (x + width > LCD_WIDTH) + width = LCD_WIDTH - x; /* Clip right */ + if (x < 0) + width += x, x = 0; /* Clip left */ + if (width <= 0) + return; /* nothing left to do */ + + if (y + height > LCD_HEIGHT) + height = LCD_HEIGHT - y; /* Clip bottom */ + if (y < 0) + height += y, y = 0; /* Clip top */ + if (height <= 0) + return; /* nothing left to do */ + +#if CONFIG_ORIENTATION == SCREEN_PORTAIT + dst = (fb_data *)FRAME + LCD_WIDTH*y + x; + src = &lcd_framebuffer[y][x]; + + /* Copy part of the Rockbox framebuffer to the second framebuffer */ + if (width < LCD_WIDTH) + { + /* Not full width - do line-by-line */ + lcd_copy_buffer_rect(dst, src, width, height); + } + else + { + /* Full width - copy as one line */ + lcd_copy_buffer_rect(dst, src, LCD_WIDTH*height, 1); + } +#else + src = &lcd_framebuffer[y][x]; + + register int xc, yc; + register fb_data *start=FRAME + LCD_HEIGHT*(LCD_WIDTH-x-1) + y + 1; + + for(yc=0;yc= 2 or else */ + width &= ~1; + height >>= 1; + + fb_data *dst = (fb_data*)FRAME + x * LCD_WIDTH + (LCD_WIDTH - y) - 1; + + z = stride*src_y; + yuv_src[0] = src[0] + z + src_x; + yuv_src[1] = src[1] + (z >> 2) + (src_x >> 1); + yuv_src[2] = src[2] + (yuv_src[1] - src[1]); + + do + { + lcd_write_yuv420_lines(dst, chroma_buf, yuv_src, width, + stride); + + yuv_src[0] += stride << 1; /* Skip down two luma lines */ + yuv_src[1] += stride >> 1; /* Skip down one chroma line */ + yuv_src[2] += stride >> 1; + dst -= 2; + } + while (--height > 0); +} + Index: firmware/target/arm/tms320dm320/creative-zvm/ata-creativezvm.c =================================================================== --- firmware/target/arm/tms320dm320/creative-zvm/ata-creativezvm.c (revision 0) +++ firmware/target/arm/tms320dm320/creative-zvm/ata-creativezvm.c (revision 0) @@ -0,0 +1,97 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2008 by Maurus Cuelenaere + * + * 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 "power.h" +#include "panic.h" +#include "ata-target.h" + +void ide_power_enable(bool on){ + IO_INTC_EINT1 &= ~INTR_EINT1_EXT2; + if(on) + { + IO_GIO_BITSET0 = (1 << 14); + ata_reset(); + } + else + IO_GIO_BITCLR0 = (1 << 14); + IO_INTC_EINT1 |= INTR_EINT1_EXT2; + return; +} + +inline bool ide_powered(){ + return (IO_GIO_BITSET0 & (1 << 14)); +} + +void ata_reset(void) +{ +/* Disabled until figured out what's wrong */ + //int level = set_irq_level(IRQ_DISABLED); + IO_INTC_EINT1 &= ~INTR_EINT1_EXT2; //disable GIO2 interrupt + if(!ide_powered()) + { + ide_power_enable(true); + sleep(150); + } + else + { + IO_GIO_BITSET0 = (1 << 5); + IO_GIO_BITCLR0 = (1 << 3); + sleep(1); + } + IO_GIO_BITCLR0 = (1 << 5); + sleep(10); + IO_GIO_BITSET0 = (1 << 3); + while(!(ATA_COMMAND & STATUS_RDY)) + sleep(50); + IO_INTC_EINT1 |= INTR_EINT1_EXT2; //enable GIO2 interrupt + //set_irq_level(level); + return; +} + +void ata_enable(bool on) +{ + (void)on; + return; +} + +bool ata_is_coldstart(void) +{ + return true; +} + +void ata_device_init(void) +{ + IO_INTC_EINT1 |= INTR_EINT1_EXT2; //enable GIO2 interrupt + //TODO: mimic OF inits... + return; +} + +void GIO2(void) +{ +#ifdef DEBUG + printf("GIO2 interrupt..."); +#endif + IO_INTC_IRQ1 = INTR_IRQ1_EXT2; //Mask GIO2 interrupt + return; +} Index: firmware/target/arm/tms320dm320/creative-zvm/button-target.h =================================================================== --- firmware/target/arm/tms320dm320/creative-zvm/button-target.h (revision 0) +++ firmware/target/arm/tms320dm320/creative-zvm/button-target.h (revision 0) @@ -0,0 +1,63 @@ +/*************************************************************************** +* __________ __ ___. +* Open \______ \ ____ ____ | | _\_ |__ _______ ___ +* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / +* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < +* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ +* \/ \/ \/ \/ \/ +* $Id$ +* +* Copyright (C) 2008 by Maurus Cuelenaere +* +* 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 "config.h" + +#define BUTTON_BACK (1 << 0) +#define BUTTON_CUSTOM (1 << 1) +#define BUTTON_MENU (1 << 2) + +#define BUTTON_LEFT (1 << 3) +#define BUTTON_RIGHT (1 << 4) +#define BUTTON_UP (1 << 5) +#define BUTTON_DOWN (1 << 6) +#define BUTTON_SELECT (1 << 7) + +#define BUTTON_POWER (1 << 8) +#define BUTTON_PLAY (1 << 9) + +#define BUTTON_HOLD (1 << 10) + +#define BUTTON_LONG (1 << 11) + +#define BUTTON_REMOTE (1 << 12) /* Not used! */ + +#define BUTTON_MAIN (BUTTON_BACK|BUTTON_MENU|BUTTON_LEFT|BUTTON_RIGHT \ + |BUTTON_UP|BUTTON_DOWN|BUTTON_SELECT|BUTTON_POWER \ + |BUTTON_PLAY|BUTTON_HOLD|BUTTON_CUSTOM) + +#define POWEROFF_BUTTON BUTTON_POWER +#define POWEROFF_COUNT 10 + +#define NONBUTTON_HEADPHONE (1 << 0) +#define NONBUTTON_DOCK (1 << 1) +#define NONBUTTON_USB (1 << 2) +#define NONBUTTON_POWER (1 << 3) +#define NONBUTTON_VIDEOUT (1 << 4) + +void button_init_device(void); +int button_read_device(void); +bool headphones_inserted(void); +bool button_hold(void); +bool button_usb_connected(void); + +#endif /* _BUTTON_TARGET_H_ */ Index: firmware/target/arm/tms320dm320/creative-zvm/usb-test.c =================================================================== --- firmware/target/arm/tms320dm320/creative-zvm/usb-test.c (revision 0) +++ firmware/target/arm/tms320dm320/creative-zvm/usb-test.c (revision 0) @@ -0,0 +1,1097 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: ifp_usb_serial.c 16484 2008-03-02 18:16:24Z gevaerts $ + * + * Copyright (C) 2006 by Tomasz Malesinski + * + * 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. + * + ****************************************************************************/ + + +#define LCD_DEBUG + +#include "config.h" +#include + +#ifdef LCD_DEBUG +#include "lcd.h" +#include "sprintf.h" +#endif + + +#define ISP1582_BASE (0x60FFC000) +#define ISP1582_ADDRESS (*(volatile unsigned char *)ISP1582_BASE) +#define ISP1582_MODE (*(volatile unsigned short *)(ISP1582_BASE + 0xc*2)) +#define ISP1582_INTCONF (*(volatile unsigned char *)(ISP1582_BASE + 0x10*2)) +#define ISP1582_OTG (*(volatile unsigned char *)(ISP1582_BASE + 0x12*2)) +#define ISP1582_INTEN (*(volatile unsigned long *)(ISP1582_BASE + 0x14*2)) + +#define ISP1582_EPINDEX (*(volatile unsigned char *)(ISP1582_BASE + 0x2c*2)) +#define ISP1582_CTRLFUN (*(volatile unsigned char *)(ISP1582_BASE + 0x28*2)) +#define ISP1582_DATA (*(volatile unsigned short *)(ISP1582_BASE + 0x20*2)) +#define ISP1582_BUFLEN (*(volatile unsigned short *)(ISP1582_BASE + 0x1c*2)) +#define ISP1582_BUFSTAT (*(volatile unsigned char *)(ISP1582_BASE + 0x1e*2)) +#define ISP1582_MAXPKSZ (*(volatile unsigned short *)(ISP1582_BASE + 0x04*2)) +#define ISP1582_EPTYPE (*(volatile unsigned short *)(ISP1582_BASE + 0x08*2)) + +#define ISP1582_INT (*(volatile unsigned long *)(ISP1582_BASE + 0x18*2)) +#define ISP1582_CHIPID (*(volatile unsigned long *)(ISP1582_BASE + 0x70*2)) +#define ISP1582_FRAMENO (*(volatile unsigned short *)(ISP1582_BASE + 0x74*2)) +#define ISP1582_UNLOCK (*(volatile unsigned short *)(ISP1582_BASE + 0x7c*2)) + +#define ISP1582_UNLOCK_CODE 0xaa37 + +#define DIR_RX 0 +#define DIR_TX 1 + +#define TYPE_BULK 2 + +#define STATE_DEFAULT 0 +#define STATE_ADDRESS 1 +#define STATE_CONFIGURED 2 + +#define N_ENDPOINTS 2 + +struct usb_endpoint +{ + unsigned char *out_buf; + short out_len; + short out_ptr; + void (*out_done)(int, unsigned char *, int); + unsigned char out_in_progress; + + unsigned char *in_buf; + short in_min_len; + short in_max_len; + short in_ptr; + void (*in_done)(int, unsigned char *, int); + unsigned char in_ack; + + unsigned char halt[2]; + unsigned char enabled[2]; + short max_pkt_size[2]; +}; + +static char usb_connect_state; + +static struct usb_endpoint endpoints[N_ENDPOINTS]; + +static unsigned char setup_pkt_buf[8]; +static unsigned char setup_out_buf[8]; +static unsigned char usb_state; +static unsigned char usb_remote_wakeup; + +#ifdef LCD_DEBUG +static unsigned char int_count[32]; + +static int log_pos_x = 0; +static int log_pos_y = 3; +#endif + +static inline void nop_f(void) +{ + asm("nop"); +} + +#ifdef LCD_DEBUG +static void log_char(char c) +{ + char s[2]; + + s[0] = c; + s[1] = 0; + + lcd_puts(log_pos_x, log_pos_y, s); + lcd_update(); + log_pos_x++; + if (log_pos_x >= 16) + { + log_pos_x = 0; + log_pos_y++; + if (log_pos_y > 5) + log_pos_y = 3; + } +} +#else +#define log_char(c) +#endif + +#define SERIAL_BUF_SIZE 1024 + +struct serial_fifo +{ + unsigned char buf[SERIAL_BUF_SIZE]; + short head, tail; +}; + +static struct serial_fifo serial_in_fifo; +static struct serial_fifo serial_out_fifo; +static unsigned char serial_in_pkt[64]; + +static unsigned char device_descriptor[18] = { + 0x12, /* length */ + 0x01, /* descriptor type */ + 0x10, 0x01, /* USB version (1.1) */ + 0xff, 0xff, /* class and subclass */ + 0xff, /* protocol */ + 0x40, /* max packet size 0 */ + 0x02, 0x41, /* vendor (iRiver) */ + 0x07, 0xee, /* product (0xee07) */ + 0x01, 0x00, /* device version */ + 0x01, /* manufacturer string */ + 0x02, /* product string */ + 0x00, /* serial number string */ + 0x01 /* number of configurations */ +}; + +static unsigned char cfg_descriptor[32] = { + 0x09, /* length */ + 0x02, /* descriptor type */ + 0x20, 0x00, /* total length */ + 0x01, /* number of interfaces */ + 0x01, /* configuration value */ + 0x00, /* configuration string */ + 0x80, /* attributes (none) */ + 0x32, /* max power (100 mA) */ + /* interface descriptor */ + 0x09, /* length */ + 0x04, /* descriptor type */ + 0x00, /* interface number */ + 0x00, /* alternate setting */ + 0x02, /* number of endpoints */ + 0xff, /* interface class */ + 0xff, /* interface subclass */ + 0xff, /* interface protocol */ + 0x00, /* interface string */ + /* endpoint IN */ + 0x07, /* length */ + 0x05, /* descriptor type */ + 0x81, /* endpoint 1 IN */ + 0x02, /* attributes (bulk) */ + 0x40, 0x00, /* max packet size */ + 0x00, /* interval */ + /* endpoint OUT */ + 0x07, /* length */ + 0x05, /* descriptor type */ + 0x01, /* endpoint 1 IN */ + 0x02, /* attributes (bulk) */ + 0x40, 0x00, /* max packet size */ + 0x00 /* interval */ +}; + +static unsigned char lang_descriptor[4] = { + 0x04, /* length */ + 0x03, /* descriptor type */ + 0x09, 0x04 /* English (US) */ +}; + +#define N_STRING_DESCRIPTORS 2 + +static unsigned char string_descriptor_vendor[] = { + 0x2e, 0x03, + 'i', 0, 'R', 0, 'i', 0, 'v', 0, 'e', 0, 'r', 0, ' ', 0, 'L', 0, + 't', 0, 'd', 0, ' ', 0, 'a', 0, 'n', 0, 'd', 0, ' ', 0, 'R', 0, + 'o', 0, 'c', 0, 'k', 0, 'b', 0, 'o', 0, 'x', 0}; + +static unsigned char string_descriptor_product[] = { + 0x1c, 0x03, + 'i', 0, 'R', 0, 'i', 0, 'v', 0, 'e', 0, 'r', 0, ' ', 0, 'i', 0, + 'F', 0, 'P', 0, '7', 0, '0', 0, '0', 0}; + +static unsigned char *string_descriptor[N_STRING_DESCRIPTORS] = { + string_descriptor_vendor, + string_descriptor_product +}; + +static inline int ep_index(int n, int dir) +{ + return (n << 1) | dir; +} + +static inline int epidx_dir(int idx) +{ + return idx & 1; +} + +static inline int epidx_n(int idx) +{ + return idx >> 1; +} + +#include "button-target.h" +int usb_connected(void) +{ + return (int)button_usb_connected(); +} + +static inline void usb_select_endpoint(int idx) +{ + ISP1582_EPINDEX = idx; +} + +static inline void usb_select_setup_endpoint(void) +{ + ISP1582_EPINDEX = 0x20; +} + +void usb_setup_endpoint(int idx, int max_pkt_size, int type) +{ + struct usb_endpoint *ep; + + usb_select_endpoint(idx); + ISP1582_MAXPKSZ = max_pkt_size; + /* |= is in the original firmware */ + ISP1582_EPTYPE |= 0x1c | type; + /* clear buffer */ + ISP1582_CTRLFUN |= 0x10; + ISP1582_INTEN |= (1 << (10 + idx)); + + ep = &(endpoints[epidx_n(idx)]); + ep->halt[epidx_dir(idx)] = 0; + ep->enabled[epidx_dir(idx)] = 1; + ep->out_in_progress = 0; + ep->in_min_len = -1; + ep->in_ack = 0; + ep->max_pkt_size[epidx_dir(idx)] = max_pkt_size; +} + +void usb_disable_endpoint(int idx) +{ + usb_select_endpoint(idx); + ISP1582_EPTYPE &= 8; + ISP1582_INTEN &= ~(1 << (10 + idx)); + endpoints[epidx_n(idx)].enabled[epidx_dir(idx)] = 1; +} + +void usb_reconnect(void) +{ + int i; + ISP1582_MODE &= ~1; /* SOFTCT off */ + for (i = 0; i < 10000; i++) + nop_f(); + ISP1582_MODE |= 1; /* SOFTCT on */ +} + +void usb_cleanup(void) +{ + ISP1582_MODE &= ~1; /* SOFTCT off */ +} + +void usb_setup(int reset) +{ + int i; + + for (i = 0; i < N_ENDPOINTS; i++) + endpoints[i].enabled[0] = endpoints[i].enabled[1] = 0; + + ISP1582_UNLOCK = ISP1582_UNLOCK_CODE; + if (!reset) + ISP1582_MODE = 0x88; /* CLKAON | GLINTENA */ + ISP1582_INTCONF = 0x57; + ISP1582_INTEN = 0xd39; + + ISP1582_ADDRESS = reset ? 0x80: 0; + + usb_setup_endpoint(ep_index(0, DIR_RX), 64, 0); + usb_setup_endpoint(ep_index(0, DIR_TX), 64, 0); + + ISP1582_MODE |= 1; /* SOFTCT on */ + + usb_state = STATE_DEFAULT; + usb_remote_wakeup = 0; +} + +static int usb_get_packet(unsigned char *buf, int max_len) +{ + int len, i; + len = ISP1582_BUFLEN; + + if (max_len < 0 || max_len > len) + max_len = len; + + i = 0; + while (i < len) + { + unsigned short d = ISP1582_DATA; + if (i < max_len) + buf[i] = d & 0xff; + i++; + if (i < max_len) + buf[i] = (d >> 8) & 0xff; + i++; + } + return max_len; +} + +static void usb_receive(int n) +{ + int len; + + if (endpoints[n].halt[DIR_RX] + || !endpoints[n].enabled[DIR_RX] + || endpoints[n].in_min_len < 0 + || !endpoints[n].in_ack) + return; + + endpoints[n].in_ack = 0; + + usb_select_endpoint(ep_index(n, DIR_RX)); + + len = usb_get_packet(endpoints[n].in_buf + endpoints[n].in_ptr, + endpoints[n].in_max_len - endpoints[n].in_ptr); + endpoints[n].in_ptr += len; + if (endpoints[n].in_ptr >= endpoints[n].in_min_len) { + endpoints[n].in_min_len = -1; + if (endpoints[n].in_done) + (*(endpoints[n].in_done))(n, endpoints[n].in_buf, + endpoints[n].in_ptr); + } +} + +static int usb_out_buffer_full(int ep) +{ + usb_select_endpoint(ep_index(ep, DIR_TX)); + if (ISP1582_EPTYPE & 4) + return (ISP1582_BUFSTAT & 3) == 3; + else + return (ISP1582_BUFSTAT & 3) != 0; +} + +static void usb_send(int n) +{ + int max_pkt_size, len; + int i; + unsigned char *p; + +#ifdef LCD_DEBUG + if (endpoints[n].halt[DIR_TX]) + log_char('H'); + if (!endpoints[n].out_in_progress) + log_char('$'); +#endif + + if (endpoints[n].halt[DIR_TX] + || !endpoints[n].enabled[DIR_TX] + || !endpoints[n].out_in_progress) + return; + + if (endpoints[n].out_ptr < 0) + { + endpoints[n].out_in_progress = 0; + if (endpoints[n].out_done) + (*(endpoints[n].out_done))(n, endpoints[n].out_buf, + endpoints[n].out_len); + return; + } + + if (usb_out_buffer_full(n)) + { + log_char('F'); + return; + } + + usb_select_endpoint(ep_index(n, DIR_TX)); + max_pkt_size = endpoints[n].max_pkt_size[DIR_TX]; + len = endpoints[n].out_len - endpoints[n].out_ptr; + if (len > max_pkt_size) + len = max_pkt_size; + + log_char('0' + (len % 10)); + ISP1582_BUFLEN = len; + p = endpoints[n].out_buf + endpoints[n].out_ptr; + i = 0; + while (len - i >= 2) { + ISP1582_DATA = p[i] | (p[i + 1] << 8); + i += 2; + } + if (i < len) + ISP1582_DATA = p[i]; + + endpoints[n].out_ptr += len; + +/* + if (endpoints[n].out_ptr == endpoints[n].out_len + && len < max_pkt_size) +*/ + if (endpoints[n].out_ptr == endpoints[n].out_len) + endpoints[n].out_ptr = -1; +} + +static void usb_stall_endpoint(int idx) +{ + usb_select_endpoint(idx); + ISP1582_CTRLFUN |= 1; + endpoints[epidx_n(idx)].halt[epidx_dir(idx)] = 1; +} + +static void usb_unstall_endpoint(int idx) +{ + usb_select_endpoint(idx); + ISP1582_CTRLFUN &= ~1; + ISP1582_EPTYPE &= ~8; + ISP1582_EPTYPE |= 8; + ISP1582_CTRLFUN |= 0x10; + if (epidx_dir(idx) == DIR_TX) + endpoints[epidx_n(idx)].out_in_progress = 0; + else + { + endpoints[epidx_n(idx)].in_min_len = -1; + endpoints[epidx_n(idx)].in_ack = 0; + } + endpoints[epidx_n(idx)].halt[epidx_dir(idx)] = 0; +} + +static void usb_status_ack(int dir) +{ + log_char(dir ? '@' : '#'); + usb_select_endpoint(ep_index(0, dir)); + ISP1582_CTRLFUN |= 2; +} + +static void usb_set_address(int adr) +{ + ISP1582_ADDRESS = adr | 0x80; +} + +static void usb_data_stage_enable(int dir) +{ + usb_select_endpoint(ep_index(0, dir)); + ISP1582_CTRLFUN |= 4; +} + +static void usb_request_error(void) +{ + usb_stall_endpoint(ep_index(0, DIR_TX)); + usb_stall_endpoint(ep_index(0, DIR_RX)); +} + +static void usb_receive_block(unsigned char *buf, int min_len, + int max_len, + void (*in_done)(int, unsigned char *, int), + int ep) +{ + endpoints[ep].in_done = in_done; + endpoints[ep].in_buf = buf; + endpoints[ep].in_max_len = max_len; + endpoints[ep].in_min_len = min_len; + endpoints[ep].in_ptr = 0; + usb_receive(ep); +} + +static void usb_send_block(unsigned char *buf, int len, + void (*done)(int, unsigned char *, int), + int ep) +{ + endpoints[ep].out_done = done; + endpoints[ep].out_buf = buf; + endpoints[ep].out_len = len; + endpoints[ep].out_ptr = 0; + endpoints[ep].out_in_progress = 1; + usb_send(ep); +} + +static void out_send_status(int n, unsigned char *buf, int len) +{ + (void)n; + (void)buf; + (void)len; + usb_status_ack(DIR_RX); +} + +static void usb_send_block_and_status(unsigned char *buf, int len, int ep) +{ + usb_send_block(buf, len, out_send_status, ep); +} + +static void usb_setup_set_address(int adr) +{ + usb_set_address(adr); + usb_state = adr ? STATE_ADDRESS : STATE_DEFAULT; + usb_status_ack(DIR_TX); +} + +static void usb_send_descriptor(unsigned char *device_descriptor, + int descriptor_len, int buffer_len) +{ + int len = descriptor_len < buffer_len ? descriptor_len : buffer_len; + usb_send_block_and_status(device_descriptor, len, 0); +} + +static void usb_setup_get_descriptor(int type, int index, int lang, int len) +{ + (void)lang; + usb_data_stage_enable(DIR_TX); + switch (type) + { + case 1: + if (index == 0) + usb_send_descriptor(device_descriptor, + sizeof(device_descriptor), len); + else + usb_request_error(); + break; + case 2: + if (index == 0) + usb_send_descriptor(cfg_descriptor, + sizeof(cfg_descriptor), len); + else + usb_request_error(); + break; + case 3: + if (index == 0) + usb_send_descriptor(lang_descriptor, + sizeof(lang_descriptor), len); + else if (index <= N_STRING_DESCRIPTORS) + usb_send_descriptor(string_descriptor[index - 1], + string_descriptor[index - 1][0], + len); + else + usb_request_error(); + break; + default: + usb_request_error(); + } +} + +static void usb_setup_get_configuration(void) +{ + setup_out_buf[0] = (usb_state == STATE_CONFIGURED) ? 1 : 0; + usb_data_stage_enable(DIR_TX); + usb_send_block_and_status(setup_out_buf, 1, 0); +} + +static void usb_setup_interface(void) +{ + usb_setup_endpoint(ep_index(1, DIR_RX), 64, TYPE_BULK); + usb_setup_endpoint(ep_index(1, DIR_TX), 64, TYPE_BULK); +} + +static void usb_setup_set_configuration(int value) +{ + switch (value) + { + case 0: + usb_disable_endpoint(ep_index(1, DIR_RX)); + usb_disable_endpoint(ep_index(1, DIR_TX)); + usb_state = STATE_ADDRESS; + usb_status_ack(DIR_TX); + break; + case 1: + usb_setup_interface(); + usb_state = STATE_CONFIGURED; + usb_status_ack(DIR_TX); + break; + default: + usb_request_error(); + } +} + +static void usb_send_status(void) +{ + usb_data_stage_enable(DIR_TX); + usb_send_block_and_status(setup_out_buf, 2, 0); +} + +static void usb_setup_get_device_status(void) +{ + setup_out_buf[0] = (usb_remote_wakeup != 0) ? 2 : 0; + setup_out_buf[1] = 0; + usb_send_status(); +} + +static void usb_setup_clear_device_feature(int feature) +{ + if (feature == 1) { + usb_remote_wakeup = 0; + usb_status_ack(DIR_TX); + } else + usb_request_error(); +} + +static void usb_setup_set_device_feature(int feature) +{ + if (feature == 1) { + usb_remote_wakeup = 1; + usb_status_ack(DIR_TX); + } else + usb_request_error(); +} + +static void usb_setup_clear_endpoint_feature(int endpoint, int feature) +{ + if (usb_state != STATE_CONFIGURED || feature != 0) + usb_request_error(); + else if ((endpoint & 0xf) == 1) + { + usb_unstall_endpoint(ep_index(endpoint & 0xf, endpoint >> 7)); + usb_status_ack(DIR_TX); + } + else + usb_request_error(); +} + +static void usb_setup_set_endpoint_feature(int endpoint, int feature) +{ + if (usb_state != STATE_CONFIGURED || feature != 0) + usb_request_error(); + else if ((endpoint & 0xf) == 1) + { + usb_stall_endpoint(ep_index(endpoint & 0xf, endpoint >> 7)); + usb_status_ack(DIR_TX); + } + else + usb_request_error(); +} + +static void usb_setup_get_interface_status(int interface) +{ + if (usb_state != STATE_CONFIGURED || interface != 0) + usb_request_error(); + else + { + setup_out_buf[0] = setup_out_buf[1] = 0; + usb_send_status(); + } +} + +static void usb_setup_get_endpoint_status(int endpoint) +{ + if ((usb_state == STATE_CONFIGURED && (endpoint & 0xf) <= 1) + || (usb_state == STATE_ADDRESS && (endpoint & 0xf) == 0)) + { + setup_out_buf[0] = endpoints[endpoint & 0xf].halt[endpoint >> 7]; + setup_out_buf[1] = 0; + usb_send_status(); + } + else + usb_request_error(); +} + +static void usb_setup_get_interface(int interface) +{ + if (usb_state != STATE_CONFIGURED || interface != 0) + usb_request_error(); + else + { + setup_out_buf[0] = 0; + usb_data_stage_enable(DIR_TX); + usb_send_block_and_status(setup_out_buf, 1, 0); + } +} + +static void usb_setup_set_interface(int interface, int setting) +{ + if (usb_state != STATE_CONFIGURED || interface != 0 || setting != 0) + usb_request_error(); + else + { + usb_setup_interface(); + usb_status_ack(DIR_TX); + } +} + +static void usb_handle_setup_pkt(unsigned char *pkt) +{ + switch ((pkt[0] << 8) | pkt[1]) + { + case 0x0005: + log_char('A'); + usb_setup_set_address(pkt[2]); + break; + case 0x8006: + log_char('D'); + usb_setup_get_descriptor(pkt[3], pkt[2], (pkt[5] << 8) | pkt[4], + (pkt[7] << 8) | pkt[6]); + break; + case 0x8008: + usb_setup_get_configuration(); + break; + case 0x0009: + usb_setup_set_configuration(pkt[2]); + break; + case 0x8000: + usb_setup_get_device_status(); + break; + case 0x8100: + usb_setup_get_interface_status(pkt[4]); + break; + case 0x8200: + usb_setup_get_endpoint_status(pkt[4]); + break; + case 0x0001: + usb_setup_clear_device_feature(pkt[2]); + break; + case 0x0201: + usb_setup_clear_endpoint_feature(pkt[4], pkt[2]); + break; + case 0x0003: + usb_setup_set_device_feature(pkt[2]); + break; + case 0x0203: + usb_setup_set_endpoint_feature(pkt[4], pkt[2]); + break; + case 0x810a: + usb_setup_get_interface(pkt[4]); + break; + case 0x010b: + usb_setup_set_interface(pkt[4], pkt[2]); + break; + case 0x0103: + /* set interface feature */ + case 0x0101: + /* clear interface feature */ + case 0x0007: + /* set descriptor */ + case 0x820c: + /* synch frame */ + default: + usb_request_error(); + } +} + +static void usb_handle_setup_rx(void) +{ + int len; +#ifdef LCD_DEBUG + char s[20]; + int i; +#endif + usb_select_setup_endpoint(); + len = usb_get_packet(setup_pkt_buf, 8); + + if (len == 8) + usb_handle_setup_pkt(setup_pkt_buf); + +#ifdef LCD_DEBUG +/* + snprintf(s, 10, "l%02x", len); + lcd_puts(0, 5, s); +*/ + for (i = 0; i < 8; i++) + snprintf(s + i * 2, 3, "%02x", setup_pkt_buf[i]); + lcd_puts(0, 0, s); + lcd_update(); +#endif +} + +static void usb_handle_data_int(int ep, int dir) +{ + if (dir == DIR_TX) + usb_send(ep); + else + { + endpoints[ep].in_ack = 1; + usb_receive(ep); + } +} + +static void usb_handle_int(int i) +{ +#ifdef LCD_DEBUG +/* + char s[10]; + snprintf(s, sizeof(s), "%02d", i); + lcd_puts(0, 2, s); + lcd_update(); +*/ + int_count[i]++; + if (i == 10) + log_char('o'); + if (i == 11) + log_char('i'); + if (i == 12) + log_char('O'); + if (i == 13) + log_char('I'); +#endif + + if (i >= 10) + usb_handle_data_int((i - 10) / 2, i % 2); + else + { + switch (i) + { + case 0: + log_char('r'); + usb_setup(1); + break; + case 8: + log_char('s'); + usb_handle_setup_rx(); + break; + } + } + +} + +void usb_handle_interrupts(void) +{ +#ifdef LCD_DEBUG + char s[20]; +#endif + + while (1) + { + unsigned long ints; + int i; + +#ifdef LCD_DEBUG + + snprintf(s, sizeof(s), "i%08lx", ISP1582_INT); + lcd_puts(0, 2, s); + +#endif + + ints = ISP1582_INT & ISP1582_INTEN; + if (!ints) break; + + i = 0; + while (!(ints & (1 << i))) + i++; + ISP1582_INT = 1 << i; + usb_handle_int(i); + +#ifdef LCD_DEBUG + for (i = 0; i < 8; i++) + snprintf(s + i * 2, 3, "%02x", int_count[i]); + lcd_puts(0, 6, s); + for (i = 0; i < 8; i++) + snprintf(s + i * 2, 3, "%02x", int_count[i + 8]); + lcd_puts(0, 7, s); +#endif + } +#ifdef LCD_DEBUG + + lcd_puts(0, 3, usb_connected() ? "C" : "N"); + lcd_update(); + +#endif +} + +static inline int fifo_mod(int n) +{ + return (n >= SERIAL_BUF_SIZE) ? n - SERIAL_BUF_SIZE : n; +} + +static void fifo_init(struct serial_fifo *fifo) +{ + fifo->head = fifo->tail = 0; +} + +static int fifo_empty(struct serial_fifo *fifo) +{ + return fifo->head == fifo->tail; +} + +static int fifo_full(struct serial_fifo *fifo) +{ + return fifo_mod(fifo->head + 1) == fifo->tail; +} + +static void fifo_remove(struct serial_fifo *fifo, int n) +{ + fifo->tail = fifo_mod(fifo->tail + n); +} + +/* + Not used: +static void fifo_add(struct serial_fifo *fifo, int n) +{ + fifo->head = fifo_mod(fifo->head + n); +} + +static void fifo_free_block(struct serial_fifo *fifo, + unsigned char **ptr, int *len) +{ + *ptr = fifo->buf + fifo->head; + if (fifo->head >= fifo->tail) + { + int l = SERIAL_BUF_SIZE - fifo->head; + if (fifo->tail == 0) + l--; + *len = l; + } + else + *len = fifo->tail - fifo->head - 1; +} +*/ + +static int fifo_free_space(struct serial_fifo *fifo) +{ + if (fifo->head >= fifo->tail) + return SERIAL_BUF_SIZE - (fifo->head - fifo->tail) - 1; + else + return fifo->tail - fifo->head - 1; +} + +static int fifo_get_byte(struct serial_fifo *fifo) +{ + int r = fifo->buf[fifo->tail]; + fifo->tail = fifo_mod(fifo->tail + 1); + return r; +} + +static void fifo_put_byte(struct serial_fifo *fifo, int b) +{ + fifo->buf[fifo->head] = b; + fifo->head = fifo_mod(fifo->head + 1); +} + +static void fifo_full_block(struct serial_fifo *fifo, + unsigned char **ptr, int *len) +{ + *ptr = fifo->buf + fifo->tail; + if (fifo->head >= fifo->tail) + *len = fifo->head - fifo->tail; + else + *len = SERIAL_BUF_SIZE - fifo->tail; +} + +static void serial_fill_in_fifo(int ep, unsigned char *buf, int len); +static void serial_free_out_fifo(int ep, unsigned char *buf, int len); + +static void serial_restart_input(int ep) +{ + if (fifo_free_space(&serial_in_fifo) >= 64) + usb_receive_block(serial_in_pkt, 1, 64, serial_fill_in_fifo, ep); +} + +static void serial_fill_in_fifo(int ep, unsigned char *buf, int len) +{ + int i; + for (i = 0; i < len; i++) + fifo_put_byte(&serial_in_fifo, buf[i]); + serial_restart_input(ep); +} + +static void serial_restart_output(int ep) +{ + unsigned char *block; + int blen; + fifo_full_block(&serial_out_fifo, &block, &blen); + if (blen) + { +#ifdef LCD_DEBUG + char s[20]; + snprintf(s, sizeof(s), "o%03lx/%03x", block - serial_out_fifo.buf, + blen); + lcd_puts(0, 2, s); + lcd_update(); +#endif + usb_send_block(block, blen, serial_free_out_fifo, ep); + } +} + +static void serial_free_out_fifo(int ep, unsigned char *buf, int len) +{ + (void)buf; + fifo_remove(&serial_out_fifo, len); + serial_restart_output(ep); +} + +void usb_serial_handle(void) +{ + if (!usb_connect_state) + { + if (usb_connected()) + { + usb_setup(0); + usb_connect_state = 1; + lcd_puts(5,1,"P"); + } + } + else + { + if (!usb_connected()) + { + usb_connect_state = 0; + usb_cleanup(); + lcd_puts(5,1,"p"); + } + else + { + usb_handle_interrupts(); + + if (usb_state == STATE_CONFIGURED) + { + if (endpoints[1].in_min_len < 0) + serial_restart_input(1); + if (!endpoints[1].out_in_progress) + serial_restart_output(1); + } + lcd_puts(5,1,"q"); + } + } +} + + +/* + Not used: +static int usb_serial_in_empty(void) +{ + return fifo_empty(&serial_in_fifo); +} +*/ + +int usb_serial_get_byte(void) +{ + while (fifo_empty(&serial_in_fifo)) + usb_serial_handle(); + return fifo_get_byte(&serial_in_fifo); +} + +int usb_serial_try_get_byte(void) +{ + int r; + if (fifo_empty(&serial_in_fifo)) + r = -1; + else + r = fifo_get_byte(&serial_in_fifo); + usb_serial_handle(); + return r; +} + +/* + Not used: +static int usb_serial_out_full(void) +{ + return fifo_full(&serial_out_fifo); +} +*/ + +void usb_serial_put_byte(int b) +{ + while (fifo_full(&serial_out_fifo)) + usb_serial_handle(); + fifo_put_byte(&serial_out_fifo, b); + usb_serial_handle(); +} + +int usb_serial_try_put_byte(int b) +{ + int r = -1; + if (!fifo_full(&serial_out_fifo)) + { + fifo_put_byte(&serial_out_fifo, b); + r = 0; + } + usb_serial_handle(); + return r; +} + +void usb_serial_init(void) +{ + fifo_init(&serial_in_fifo); + fifo_init(&serial_out_fifo); + usb_connect_state = 0; +} Index: firmware/target/arm/tms320dm320/creative-zvm/pic-creativezvm.c =================================================================== --- firmware/target/arm/tms320dm320/creative-zvm/pic-creativezvm.c (revision 0) +++ firmware/target/arm/tms320dm320/creative-zvm/pic-creativezvm.c (revision 0) @@ -0,0 +1,297 @@ +/*************************************************************************** +* __________ __ ___. +* Open \______ \ ____ ____ | | _\_ |__ _______ ___ +* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / +* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < +* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ +* \/ \/ \/ \/ \/ +* $Id$ +* +* Copyright (C) 2008 by Maurus Cuelenaere +* +* Creative Zen Vision:M interrupt based PIC driver +* +* 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 "system.h" +#include "kernel.h" +#include "button-target.h" +#include "i2c-dm320.h" + + +#include "lcd-target.h" +#include "lcd.h" +#include "sprintf.h" +#include "font.h" + +#ifndef ZEN_VISION +/* Creative Zen Vision:M */ +#define BTN_LEFT 0xAF00 +#define BTN_RIGHT 0xA700 +#define BTN_BACK 0xDF00 +#define BTN_CUSTOM 0xC700 +#define BTN_PLAY 0x9700 +#define BTN_POWER 0x8700 +#define BTN_MENU 0xCF00 +#define BTN_HOLD 0xCF07 +#define BTN_UNHOLD 0xD707 + +#define BTN_LONG (1 << 15) + +#define BTN_TOUCHPAD_PRESS 0x8F00 +#define BTN_TOUCHPAD_DOWN_A 0x8701 +#define BTN_TOUCHPAD_DOWN_B 0x8F01 +#define BTN_TOUCHPAD_UP_A 0x8706 +#define BTN_TOUCHPAD_UP_B 0x9706 +#define BTN_TOUCHPAD_CORNER_DOWN 0xD700 +#define BTN_TOUCHPAD_CORNER_UP 0x9F00 + +#define HEADPHONE_PLUGIN_A 0x5707 +#define HEADPHONE_PLUGIN_B 0x5F07 +#define HEADPHONE_UNPLUG_A 0x3707 +#define HEADPHONE_UNPLUG_B 0x3F07 + +#define DOCK_INSERT 0x6707 +#define DOCK_UNPLUG 0x6F07 +#define DOCK_USB_INSERT 0x1707 +#define DOCK_USB_UNPLUG_A 0x1F03 +#define DOCK_USB_UNPLUG_B 0x1F07 +#define DOCK_POWER_INSERT 0x2707 +#define DOCK_POWER_UNPLUG 0x2F07 + +#else +/* Creative Zen Vision */ +#define BTN_LEFT 0xCF00 +#define BTN_RIGHT 0xEF00 +#define BTN_BACK 0xBF00 +#define BTN_CUSTOM 0x0 +#define BTN_PLAY 0x2F00 +#define BTN_POWER 0x0F00 +#define BTN_MENU 0x9F00 +#define BTN_HOLD 0x9F06 +#define BTN_UNHOLD 0xAF06 +/* TODO: other values +First number is just pressing it, second is when you release it or keep it pressed a bit longer +On/Off = 0F00 && 0F01 +Hold = 9F06 && AF06 +Volume Up = 6F00 && 6F01 +Vol Down = 7F00 && 7F01 +Up = DF00 && DF01 +Right = EF00 && EF01 +Down = FF00 && FF01 +Left = CF00 && CF01 +Back = BF00 && BF01 +Menu = 9F00 && Etcetera +Ok = 1F00 +Play = 2F00 +Next = 4F00 +Prev = 5F00 + +USB = 2F06 +USB ouot = 3F06 +Headphones= AF06 +Hdphns out= BF06 +Charger = 4F06 -> 9F05 +Chgrout = 5F06 -> 8F05 +AV in = 8F06 +AV out = 9F06 */ + +#define BTN_LONG 1 + +#define BTN_TOUCHPAD_PRESS 0x8F00 +#define BTN_TOUCHPAD_LONG_PRESS 0x0F00 +#define BTN_TOUCHPAD_CORNER_DOWN 0xD700 +#define BTN_TOUCHPAD_CORNER_LONG_DOWN 0x5700 +#define BTN_TOUCHPAD_CORNER_UP 0x9F00 +#define BTN_TOUCHPAD_CORNER_LONG_UP 0x1F00 + +#define HEADPHONE_PLUGIN_A 0xAF06 +#define HEADPHONE_PLUGIN_B 0xAF06 +#define HEADPHONE_UNPLUG_A 0xBF06 +#define HEADPHONE_UNPLUG_B 0xBF06 + +#define DOCK_INSERT 0x0 +#define DOCK_UNPLUG 0x0 +#define DOCK_USB_INSERT 0x2F06 +#define DOCK_USB_UNPLUG_A 0x3F06 +#define DOCK_USB_UNPLUG_B 0x3F06 +#define DOCK_POWER_INSERT 0x4F06 +#define DOCK_POWER_UNPLUG 0x5F06 +#define DOCK_AV_INSERT 0x8F06 +#define DOCK_AV_UNPLUG 0x9F06 +#endif + +#define PIC_READ_ADR 0x07 +#define PIC_WRITE_ADR 0x08 + +static int btn; +static unsigned char nonbtn; + +/* Taken from scramble.c */ +inline unsigned int le2int(unsigned char* buf) +{ + return (unsigned int)(buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0]; +} + +#define do_short(BtN) btn = (btn ^ BtN) & ~BUTTON_LONG; +#define do_long(BtN) btn |= BtN | BUTTON_LONG; + +#ifdef BUTTON_DEBUG +static bool sw = false; +#endif + +void GIO0(void) +{ + unsigned char msg[16]; + i2c_read(PIC_READ_ADR, msg, 16); + switch(le2int(msg) & 0xFFFF) + { + case BTN_LEFT: + do_short(BUTTON_LEFT); + break; + case BTN_LEFT ^ BTN_LONG: + do_long(BUTTON_LEFT); + break; + case BTN_RIGHT: + do_short(BUTTON_RIGHT); + break; + case BTN_RIGHT ^ BTN_LONG: + do_long(BUTTON_RIGHT); + break; + case BTN_BACK: + do_short(BUTTON_BACK); + break; + case BTN_BACK ^ BTN_LONG: + do_long(BUTTON_BACK); + break; + case BTN_CUSTOM: + do_short(BUTTON_CUSTOM); + break; + case BTN_CUSTOM ^ BTN_LONG: + do_long(BUTTON_CUSTOM); + break; + case BTN_MENU: + do_short(BUTTON_MENU); + break; + case BTN_MENU ^ BTN_LONG: + do_long(BUTTON_MENU); + break; + case BTN_PLAY: + do_short(BUTTON_PLAY); + break; + case BTN_PLAY ^ BTN_LONG: + do_long(BUTTON_PLAY); + break; + case BTN_POWER: + do_short(BUTTON_POWER); + break; + case BTN_POWER ^ BTN_LONG: + do_long(BUTTON_POWER); + break; + case BTN_HOLD: + btn |= BUTTON_HOLD; + break; + case BTN_UNHOLD: + btn &= ~BUTTON_HOLD; + btn &= ~BUTTON_POWER; + break; + case BTN_TOUCHPAD_PRESS: + do_short(BUTTON_SELECT); + break; + case BTN_TOUCHPAD_PRESS ^ BTN_LONG: + do_long(BUTTON_SELECT); + break; + case BTN_TOUCHPAD_CORNER_DOWN: + do_short(BUTTON_DOWN); + break; + case BTN_TOUCHPAD_CORNER_DOWN ^ BTN_LONG: + do_long(BUTTON_DOWN); + break; + case BTN_TOUCHPAD_CORNER_UP: + do_short(BUTTON_UP); + break; + case BTN_TOUCHPAD_CORNER_UP ^ BTN_LONG: + do_long(BUTTON_UP); + break; + case HEADPHONE_PLUGIN_A: + case HEADPHONE_PLUGIN_B: + nonbtn |= NONBUTTON_HEADPHONE; + break; + case HEADPHONE_UNPLUG_A: + case HEADPHONE_UNPLUG_B: + nonbtn &= ~NONBUTTON_HEADPHONE; + break; + case DOCK_INSERT: + nonbtn |= NONBUTTON_DOCK; + break; + case DOCK_UNPLUG: + nonbtn &= ~NONBUTTON_DOCK; + nonbtn &= ~NONBUTTON_USB; + nonbtn &= ~NONBUTTON_POWER; + break; + case DOCK_USB_INSERT: + nonbtn |= NONBUTTON_USB; + break; + case DOCK_USB_UNPLUG_A: + case DOCK_USB_UNPLUG_B: + nonbtn &= ~NONBUTTON_USB; + break; + case DOCK_POWER_INSERT: + nonbtn |= NONBUTTON_POWER; + break; + case DOCK_POWER_UNPLUG: + nonbtn &= ~NONBUTTON_POWER; + break; + } +#ifdef BUTTON_DEBUG + unsigned char weergvn[10]; + lcd_set_foreground((sw ? LCD_RGBPACK(255,0,0) : LCD_RGBPACK(0,255,0) )); + snprintf(weergvn, sizeof(char)*10, "%x", (unsigned int)(msg[3] << 24) | (msg[2] << 16) | (msg[1] << 8) | msg[0]); + lcd_putsxy(LCD_WIDTH-SYSFONT_WIDTH*10, LCD_HEIGHT-SYSFONT_HEIGHT*10, weergvn); + snprintf(weergvn, sizeof(char)*10, "%x", (unsigned int)(msg[7] << 24) | (msg[6] << 16) | (msg[5] << 8) | msg[4]); + lcd_putsxy(LCD_WIDTH-SYSFONT_WIDTH*10, LCD_HEIGHT-SYSFONT_HEIGHT*9, weergvn); + snprintf(weergvn, sizeof(char)*10, "%x", (unsigned int)(msg[11] << 24) | (msg[10] << 16) | (msg[9] << 8) | msg[8]); + lcd_putsxy(LCD_WIDTH-SYSFONT_WIDTH*10, LCD_HEIGHT-SYSFONT_HEIGHT*8, weergvn); + snprintf(weergvn, sizeof(char)*10, "%x", (unsigned int)(msg[15] << 24) | (msg[14] << 16) | (msg[13] << 8) | msg[12]); + lcd_putsxy(LCD_WIDTH-SYSFONT_WIDTH*10, LCD_HEIGHT-SYSFONT_HEIGHT*7, weergvn); + lcd_set_foreground(LCD_BLACK); + lcd_update(); + sw = !sw; +#endif + IO_INTC_IRQ1 = INTR_IRQ1_EXT0; /* Mask GIO0 interrupt */ + return; +} + +bool headphones_inserted(void) +{ + return (bool)(nonbtn & NONBUTTON_HEADPHONE); +} + +void button_init_device(void) +{ + /* TODO: I suppose GIO0 has to be set to input and enable interrupts on it? */ + IO_INTC_EINT1 |= INTR_EINT1_EXT0; /* Enable GIO0 interrupt */ + btn = 0; + nonbtn = 0; +} +int button_read_device(void) +{ + return btn; +} + +bool button_hold(void) +{ + return (bool)(btn & BUTTON_HOLD); +} + +bool button_usb_connected(void) +{ + return (bool)(nonbtn & NONBUTTON_USB); +} Index: firmware/target/arm/tms320dm320/creative-zvm/pcm-creativezvm.c =================================================================== --- firmware/target/arm/tms320dm320/creative-zvm/pcm-creativezvm.c (revision 0) +++ firmware/target/arm/tms320dm320/creative-zvm/pcm-creativezvm.c (revision 0) @@ -0,0 +1,81 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2007 by Karl Kurbjun + * + * 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 "system.h" +#include "kernel.h" +#include "logf.h" +#include "audio.h" +#include "sound.h" +#include "file.h" + +void pcm_postinit(void) +{ + +} + +const void * pcm_play_dma_get_peak_buffer(int *count) +{ + (void) count; + return 0; +} + +void pcm_play_dma_init(void) +{ + +} + +void pcm_apply_settings(void) +{ + +} + +void pcm_set_frequency(unsigned int frequency) +{ + (void) frequency; +} + +void pcm_play_dma_start(const void *addr, size_t size) +{ + (void) addr; + (void) size; +} + +void pcm_play_dma_stop(void) +{ + +} + +void pcm_play_lock(void) +{ + +} + +void pcm_play_unlock(void) +{ + +} + +void pcm_play_dma_pause(bool pause) +{ + (void) pause; +} + +size_t pcm_get_bytes_waiting(void) +{ + return 0; +} Index: firmware/target/arm/tms320dm320/creative-zvm/powermgmt-creativezvm.c =================================================================== --- firmware/target/arm/tms320dm320/creative-zvm/powermgmt-creativezvm.c (revision 0) +++ firmware/target/arm/tms320dm320/creative-zvm/powermgmt-creativezvm.c (revision 0) @@ -0,0 +1,57 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2007 by Karl Kurbjun + * + * 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 "adc.h" +#include "powermgmt.h" +#include "kernel.h" + +/* THIS CONTAINS CURRENTLY DUMMY CODE! */ + +unsigned short current_voltage = 3910; +const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = +{ + 0 +}; + +const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] = +{ + 0 +}; + +/* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */ +const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] = +{ + { 100, 300, 400, 500, 600, 700, 800, 900, 1000, 1200, 1320 }, +}; + +/* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */ +const unsigned short percent_to_volt_charge[11] = +{ + 100, 300, 400, 500, 600, 700, 800, 900, 1000, 1200, 1320, +}; +void read_battery_inputs(void) +{ +} + +/* Returns battery voltage from ADC [millivolts] */ +unsigned int battery_adc_voltage(void) +{ + return current_voltage; +} Index: firmware/target/arm/tms320dm320/creative-zvm/adc-target.h =================================================================== --- firmware/target/arm/tms320dm320/creative-zvm/adc-target.h (revision 0) +++ firmware/target/arm/tms320dm320/creative-zvm/adc-target.h (revision 0) @@ -0,0 +1,38 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: adc-target.h 14817 2007-09-22 15:43:38Z kkurbjun $ + * + * Copyright (C) 2007 by Karl Kurbjun + * + * 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_ + +/* only two channels used by the Gigabeat */ +#define NUM_ADC_CHANNELS 2 + +#define ADC_BATTERY 0 +#define ADC_HPREMOTE 1 +#define ADC_UNKNOWN_3 2 +#define ADC_UNKNOWN_4 3 +#define ADC_UNKNOWN_5 4 +#define ADC_UNKNOWN_6 5 +#define ADC_UNKNOWN_7 6 +#define ADC_UNKNOWN_8 7 + +#define ADC_UNREG_POWER ADC_BATTERY /* For compatibility */ +#define ADC_READ_ERROR 0xFFFF + +#endif Index: firmware/target/arm/tms320dm320/creative-zvm/backlight-target.h =================================================================== --- firmware/target/arm/tms320dm320/creative-zvm/backlight-target.h (revision 0) +++ firmware/target/arm/tms320dm320/creative-zvm/backlight-target.h (revision 0) @@ -0,0 +1,31 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: backlight-target.h 15599 2007-11-12 18:49:53Z amiconn $ + * + * Copyright (C) 2007 by Karl Kurbjun + * + * 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 + +bool _backlight_init(void); +void _backlight_on(void); +void _backlight_off(void); +void _backlight_set_brightness(int brightness); + +/* true: backlight fades off - false: backlight fades on */ +void __backlight_dim(bool dim); + +#endif Index: firmware/target/arm/tms320dm320/creative-zvm/usb-target.h =================================================================== --- firmware/target/arm/tms320dm320/creative-zvm/usb-target.h (revision 0) +++ firmware/target/arm/tms320dm320/creative-zvm/usb-target.h (revision 0) @@ -0,0 +1,67 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2008 by Maurus Cuelenaere + * + * 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 + +#include "dm320.h" + +#define ISP1583_IOBASE 0x60FFC000 +#define ISP1583_H_OVERRIDE + +#define ISP1583_INIT_ADDRESS (*((volatile unsigned char*)(ISP1583_IOBASE+0x0))) +#define ISP1583_INIT_MODE (*((volatile unsigned char*)(ISP1583_IOBASE+0xC*2))) +#define ISP1583_INIT_INTCONF (*((volatile unsigned char*)(ISP1583_IOBASE+0x10*2))) +#define ISP1583_INIT_OTG (*((volatile unsigned char*)(ISP1583_IOBASE+0x12*2))) +#define ISP1583_INIT_INTEN_A (*((volatile unsigned short*)(ISP1583_IOBASE+0x14*2))) +#define ISP1583_INIT_INTEN_B (*((volatile unsigned short*)(ISP1583_IOBASE+0x15*2))) +#define ISP1583_INIT_INTEN_READ (ISP1583_INIT_INTEN_A + (ISP1583_INIT_INTEN_B << 16)) +#define ISP1583_INIT_INTEN ISP1583_INIT_INTEN_A +/* Data flow registers */ +#define ISP1583_DFLOW_EPINDEX (*((volatile unsigned char*)(ISP1583_IOBASE+0xC2*2))) +#define ISP1583_DFLOW_CTRLFUN (*((volatile unsigned char*)(ISP1583_IOBASE+0x28*2))) +#define ISP1583_DFLOW_DATA (*((volatile unsigned short*)(ISP1583_IOBASE+0x20*2))) +#define ISP1583_DFLOW_BUFLEN (*((volatile unsigned short*)(ISP1583_IOBASE+0x1C*2))) +#define ISP1583_DFLOW_BUFSTAT (*((volatile unsigned char*)(ISP1583_IOBASE+0x1E*2))) +#define ISP1583_DFLOW_MAXPKSZ (*((volatile unsigned short*)(ISP1583_IOBASE+0x04*2))) +#define ISP1583_DFLOW_EPTYPE (*((volatile unsigned short*)(ISP1583_IOBASE+0x08*2))) +/* DMA registers */ +#define ISP1583_DMA_ENDPOINT (*((volatile unsigned char*)(ISP1583_IOBASE+0x58*2))) +/* General registers */ +#define ISP1583_GEN_INT_A (*((volatile unsigned short*)(ISP1583_IOBASE+0x18*2))) +#define ISP1583_GEN_INT_B (*((volatile unsigned short*)(ISP1583_IOBASE+0x19*2))) +#define ISP1583_GEN_INT ISP1583_GEN_INT_A +#define ISP1583_GEN_INT_READ (ISP1583_GEN_INT_A + (ISP1583_GEN_INT_B << 16)) +#define ISP1583_GEN_CHIPID_A (*((volatile unsigned short*)(ISP1583_IOBASE+0x70*2))) +#define ISP1583_GEN_CHIPID_B (*((volatile unsigned char*)(ISP1583_IOBASE+0x71*2))) +#define ISP1583_GEN_CHIPID (ISP1583_GEN_CHIPID_A + (ISP1583_GEN_CHIPID_B << 16)) +#define ISP1583_GEN_FRAMEN0 (*((volatile unsigned short*)(ISP1583_IOBASE+0x74*2))) +#define ISP1583_GEN_SCRATCH (*((volatile unsigned short*)(ISP1583_IOBASE+0x78*2))) +#define ISP1583_GEN_UNLCKDEV (*((volatile unsigned short*)(ISP1583_IOBASE+0x7C*2))) +#define ISP1583_GEN_TSTMOD (*((volatile unsigned char*)(ISP1583_IOBASE+0x84*2))) + +#define EN_INT_CPU_TARGET IO_INTC_EINT1 |= INTR_EINT1_EXT7 +#define DIS_INT_CPU_TARGET IO_INTC_EINT1 &= ~INTR_EINT1_EXT7 +#define INT_CONF_TARGET 0x54 +//#define INT_CONF_TARGET 0x57 + +int usb_detect(void); +int usb_init_device(void); + +#endif Index: firmware/target/arm/tms320dm320/creative-zvm/adc-creativezvm.c =================================================================== --- firmware/target/arm/tms320dm320/creative-zvm/adc-creativezvm.c (revision 0) +++ firmware/target/arm/tms320dm320/creative-zvm/adc-creativezvm.c (revision 0) @@ -0,0 +1,42 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: adc-mr500.c 14817 2007-09-22 15:43:38Z kkurbjun $ + * + * Copyright (C) 2007 by Karl Kurbjun + * + * 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 "cpu.h" +#include "adc-target.h" +#include "kernel.h" + +/* prototypes */ +static void adc_tick(void); + +void adc_init(void) +{ + /* attach the adc reading to the tick */ + tick_add_task(adc_tick); +} + +/* Called to get the recent ADC reading */ +inline unsigned short adc_read(int channel) +{ + return (short)channel; +} + +/* add this to the tick so that the ADC converts are done in the background */ +static void adc_tick(void) +{ +} Index: firmware/target/arm/tms320dm320/creative-zvm/usb-creativezvm.c =================================================================== --- firmware/target/arm/tms320dm320/creative-zvm/usb-creativezvm.c (revision 0) +++ firmware/target/arm/tms320dm320/creative-zvm/usb-creativezvm.c (revision 0) @@ -0,0 +1,83 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2008 by Maurus Cuelenaere + * + * 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 "system.h" +#include "kernel.h" +#include "usb.h" +#include "usb-target.h" +#include "usb_drv.h" +#include "usb_core.h" +#include "isp1583.h" + +static struct mutex usb_mutex; + +bool usb_drv_connected(void) +{ + return button_usb_connected(); +} + +int usb_detect(void) +{ + if(button_usb_connected()) + return USB_INSERTED; + else + return USB_EXTRACTED; +} + +int usb_init_device(void) +{ +#if 0 + ISP1583_GEN_UNLCKDEV = ISP1583_UNLOCK_CODE; + ISP1583_INIT_MODE = 0x88; /* CLKAON | GLINTENA */ + ISP1583_INIT_INTCONF = 0x57; + ISP1583_INIT_INTEN = 0xd39; + ISP1583_INIT_ADDRESS = 0x80; + ISP1583_INIT_MODE |= 1; /* SOFTCT on */ +#endif + return false; +} + +void usb_enable(bool on) +{ +#if 0 + if(on) + ISP1583_INIT_ADDRESS |= (1 << 7); + else + ISP1583_INIT_ADDRESS &= ~(1 << 7); +#endif + if(on) + usb_core_init(); + else + usb_core_exit(); + printf("doing usb_enable(%d)", on); + return; +} + +void GIO7(void) +{ + IO_INTC_EINT1 &= ~INTR_EINT1_EXT7; +#ifdef DEBUG + printf("GIO7 interrupt..."); +#endif + usb_drv_int(); + IO_INTC_EINT1 |= INTR_EINT1_EXT7; + + IO_INTC_IRQ1 = INTR_IRQ1_EXT7; +} Index: firmware/target/arm/tms320dm320/creative-zvm/power-creativezvm.c =================================================================== --- firmware/target/arm/tms320dm320/creative-zvm/power-creativezvm.c (revision 0) +++ firmware/target/arm/tms320dm320/creative-zvm/power-creativezvm.c (revision 0) @@ -0,0 +1,68 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: power-mr500.c 15599 2007-11-12 18:49:53Z amiconn $ + * + * Copyright (C) 2007 by Karl Kurbjun + * + * 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 "backlight.h" +#include "backlight-target.h" + +#ifndef SIMULATOR + +void power_init(void) +{ + /* Initialize IDE power pin */ + /* set ATA power on and output */ + /* Charger detect */ +} + +bool charger_inserted(void) +{ + return false; +} + +/* Returns true if the unit is charging the batteries. */ +bool charging_state(void) { + return false; +} + +void power_off(void) +{ +} + +#else /* SIMULATOR */ + +bool charger_inserted(void) +{ + return false; +} + +void charger_enable(bool on) +{ + (void)on; +} + +void power_off(void) +{ +} + +#endif /* SIMULATOR */ Index: firmware/target/arm/tms320dm320/creative-zvm/lcd-target.h =================================================================== --- firmware/target/arm/tms320dm320/creative-zvm/lcd-target.h (revision 0) +++ firmware/target/arm/tms320dm320/creative-zvm/lcd-target.h (revision 0) @@ -0,0 +1,25 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2007 by Karl Kurbjun + * + * 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 _LCD_TARGET_H_ +#define _LCD_TARGET_H_ + +extern void lcd_enable(bool state); + +#endif Index: firmware/thread.c =================================================================== --- firmware/thread.c (revision 16999) +++ firmware/thread.c (working copy) @@ -795,6 +795,18 @@ ); enable_irq(); } +#elif CONFIG_CPU == DM320 +static inline void core_sleep(void) +{ + asm volatile ( + "mov r0, #0 \n" + "mcr p15, 0, r0, c7, c0, 4 \n" /* Wait for interrupt */ + "mrs r0, cpsr \n" /* Unmask IRQ/FIQ at core level */ + "bic r0, r0, #0xc0 \n" + "msr cpsr_c, r0 \n" + : : : "r0" + ); +} #else static inline void core_sleep(void) { @@ -2011,7 +2023,10 @@ cores[core].running = thread; } #endif /* HAVE_PRIORITY_SCHEDULING */ - +#ifdef DEBUG + lcd_putsxy(280, 0, thread->name); + lcd_update(); +#endif RTR_UNLOCK(core); enable_irq(); break; Index: firmware/timer.c =================================================================== --- firmware/timer.c (revision 16999) +++ firmware/timer.c (working copy) @@ -313,7 +313,7 @@ #elif CONFIG_CPU == PNX0101 TIMER1.ctrl &= ~0x80; /* disable timer 1 */ irq_disable_int(IRQ_TIMER1); -#elif CONFIG_CPU == S3C2440 +#else __TIMER_UNREGISTER(); #endif pfn_timer = NULL; Index: firmware/usb.c =================================================================== --- firmware/usb.c (revision 16999) +++ firmware/usb.c (working copy) @@ -65,11 +65,11 @@ /* FIXME: The extra 0x800 is consumed by fat_mount() when the fsinfo needs updating */ -#ifndef BOOTLOADER +//#ifndef BOOTLOADER static long usb_stack[(DEFAULT_STACK_SIZE + 0x800)/sizeof(long)]; static const char usb_thread_name[] = "usb"; static struct thread_entry *usb_thread_entry; -#endif +//#endif static struct event_queue usb_queue; static int last_usb_status; static bool usb_monitor_enabled; @@ -86,7 +86,7 @@ -#ifndef BOOTLOADER +//#ifndef BOOTLOADER #ifndef HAVE_USBSTACK static void usb_slave_mode(bool on) { @@ -174,7 +174,7 @@ break; #endif case USB_INSERTED: -#ifdef HAVE_LCD_BITMAP +#if defined(HAVE_LCD_BITMAP) && !defined(BOOTLOADER) if(do_screendump_instead_of_usb) { screen_dump(); @@ -367,16 +367,16 @@ } } } -#endif +//#endif /* BOOTLOADER */ #ifdef HAVE_USBSTACK void usb_signal_transfer_completion(struct usb_transfer_completion_event_data* event_data) { queue_post(&usb_queue, USB_TRANSFER_COMPLETION, (intptr_t)event_data); } -#endif +#endif -#ifndef BOOTLOADER +//#ifndef BOOTLOADER static void usb_tick(void) { int current_status; @@ -437,7 +437,7 @@ } #endif } -#endif +//#endif /* BOOTLOADER */ void usb_acknowledge(long id) { @@ -465,7 +465,7 @@ /* We assume that the USB cable is extracted */ last_usb_status = USB_EXTRACTED; -#ifndef BOOTLOADER +//#ifndef BOOTLOADER queue_init(&usb_queue, true); usb_thread_entry = create_thread(usb_thread, usb_stack, @@ -473,7 +473,7 @@ IF_PRIO(, PRIORITY_SYSTEM) IF_COP(, CPU)); tick_add_task(usb_tick); -#endif +//#endif } Index: firmware/drivers/rtc/rtc_zenvisionm.c =================================================================== --- firmware/drivers/rtc/rtc_zenvisionm.c (revision 0) +++ firmware/drivers/rtc/rtc_zenvisionm.c (revision 0) @@ -0,0 +1,37 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2008 by Maurus Cuelenaere + * + * 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 "i2c-dm320.h" + + #define I2C_ADDRESS 0x51 + + unsigned char* rtc_send_command(short unk1, short unk2) + { + unsigned char ret[12]; + i2c_write(I2C_ADDRESS, (unk2 & 0xFF) | (unk << 8), 1); + i2c_read(I2C_ADDRESS, ret, 12); + return ret; + } + + unsigned char* rtc_read(void) + { + unsigned char ret[12]; + i2c_read(I2C_ADDRESS, ret, 12); + return ret; + } \ No newline at end of file Index: firmware/drivers/audio/tlv320.c =================================================================== --- firmware/drivers/audio/tlv320.c (revision 16999) +++ firmware/drivers/audio/tlv320.c (working copy) @@ -43,7 +43,7 @@ /* +6 to -73dB 1dB steps (plus mute == 80levels) 7bits */ /* 1111111 == +6dB (0x7f) */ /* 1111001 == 0dB (0x79) */ - /* 0110000 == -73dB (0x30 */ + /* 0110000 == -73dB (0x30) */ /* 0101111 == mute (0x2f) */ if (db < VOLUME_MIN) { Index: firmware/drivers/isp1583.c =================================================================== --- firmware/drivers/isp1583.c (revision 0) +++ firmware/drivers/isp1583.c (revision 0) @@ -0,0 +1,619 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2006 by Tomasz Malesinski + * Copyright (C) 2008 by Maurus Cuelenaere + * + * 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 "usb-target.h" +#include "usb_ch9.h" +#include "usb_drv.h" +#include "usb_core.h" +#include "isp1583.h" + +#define logf printf + +struct usb_endpoint +{ + unsigned char *out_buf; + short out_len; + short out_ptr; + void (*out_done)(int, unsigned char *, int); + unsigned char out_in_progress; + + unsigned char *in_buf; + short in_min_len; + short in_max_len; + short in_ptr; + void (*in_done)(int, unsigned char *, int); + unsigned char in_ack; + + unsigned char halt[2]; + unsigned char enabled[2]; + short max_pkt_size[2]; + short type; +}; + +static struct usb_endpoint endpoints[NUM_ENDPOINTS]; + +static unsigned char setup_pkt_buf[8]; +static unsigned char setup_out_buf[8]; + +static bool high_speed_mode = false; + +static inline void nop_f(void) +{ + yield(); +} + +static inline int ep_index(int n, int dir) +{ + return (n << 1) | dir; +} + +static inline int epidx_dir(int idx) +{ + return idx & 1; +} + +static inline int epidx_n(int idx) +{ + return idx >> 1; +} + +static inline void usb_select_endpoint(int idx) +{ + /* Select the endpoint */ + ISP1583_DFLOW_EPINDEX = idx; + /* Make sure DMA is pointed to another endpoint (in this case EP0 RX) */ + ISP1583_DMA_ENDPOINT = 0; + sleep(1); +} + +static inline void usb_select_setup_endpoint(void) +{ + /* Select the endpoint */ + ISP1583_DFLOW_EPINDEX = DFLOW_EPINDEX_EP0SETUP; + /* Make sure DMA is pointed to another endpoint (in this case EP1 RX) */ + ISP1583_DMA_ENDPOINT = 2; + sleep(1); +} + +static void usb_setup_endpoint(int idx, int max_pkt_size, int type) +{ + struct usb_endpoint *ep; + + usb_select_endpoint(idx); + ISP1583_DFLOW_MAXPKSZ = max_pkt_size; + ISP1583_DFLOW_EPTYPE = (DFLOW_EPTYPE_NOEMPKT | DFLOW_EPTYPE_ENABLE | DFLOW_EPTYPE_DBLBUF | (type & 0x3)); + /* clear buffer */ + ISP1583_DFLOW_CTRLFUN |= DFLOW_CTRLFUN_CLBUF; + ISP1583_INIT_INTEN |= (1 << (10 + idx)); + + ep = &(endpoints[epidx_n(idx)]); + ep->halt[epidx_dir(idx)] = 0; + ep->enabled[epidx_dir(idx)] = 1; + ep->out_in_progress = 0; + ep->in_min_len = -1; + ep->in_ack = 0; + ep->type = type; + ep->max_pkt_size[epidx_dir(idx)] = max_pkt_size; +} + +static void usb_disable_endpoint(int idx) +{ + usb_select_endpoint(idx); + ISP1583_DFLOW_EPTYPE &= ~DFLOW_EPTYPE_ENABLE; + ISP1583_INIT_INTEN &= ~(1 << (10 + idx)); + endpoints[epidx_n(idx)].enabled[epidx_dir(idx)] = 0; +} + +static void usb_reconnect(void) +{ + int i; + ISP1583_INIT_MODE &= ~INIT_MODE_SOFTCT; /* SOFTCT off */ + for (i = 0; i < 10000; i++) + nop_f(); + ISP1583_INIT_MODE |= INIT_MODE_SOFTCT; /* SOFTCT on */ + logf("usb_reconnect"); +} + +static inline void usb_cleanup(void) +{ + ISP1583_INIT_MODE &= ~INIT_MODE_SOFTCT; /* SOFTCT off */ +} + +static int usb_get_packet(unsigned char *buf, int max_len) +{ + int len, i; + len = ISP1583_DFLOW_BUFLEN; + + if (max_len < 0 || max_len > len) + max_len = len; + + i = 0; + while (i < len) + { + unsigned short d = ISP1583_DFLOW_DATA; + if (i < max_len) + buf[i] = d & 0xff; + i++; + if (i < max_len) + buf[i] = (d >> 8) & 0xff; + i++; + } + return max_len; +} + +static int usb_receive(int n) +{ + int len; + + if (endpoints[n].halt[DIR_RX] + || !endpoints[n].enabled[DIR_RX] + || endpoints[n].in_min_len < 0 + || !endpoints[n].in_ack) + return -1; + + endpoints[n].in_ack = 0; + + usb_select_endpoint(ep_index(n, DIR_RX)); + + len = usb_get_packet(endpoints[n].in_buf + endpoints[n].in_ptr, + endpoints[n].in_max_len - endpoints[n].in_ptr); + endpoints[n].in_ptr += len; + if (endpoints[n].in_ptr >= endpoints[n].in_min_len) { + endpoints[n].in_min_len = -1; + if (endpoints[n].in_done) + (*(endpoints[n].in_done))(n, endpoints[n].in_buf, + endpoints[n].in_ptr); + } + return len; +} + +static int usb_out_buffer_full(int ep) +{ + usb_select_endpoint(ep_index(ep, DIR_TX)); + if (ISP1583_DFLOW_EPTYPE & 4) + return (ISP1583_DFLOW_BUFSTAT & 3) == 3; + else + return (ISP1583_DFLOW_BUFSTAT & 3) != 0; +} + +static int usb_send(int n) +{ + int max_pkt_size, len; + int i; + unsigned char *p; + + if (endpoints[n].halt[DIR_TX] + || !endpoints[n].enabled[DIR_TX] + || !endpoints[n].out_in_progress) + return -1; + + if (endpoints[n].out_ptr < 0) + { + endpoints[n].out_in_progress = 0; + if (endpoints[n].out_done) + (*(endpoints[n].out_done))(n, endpoints[n].out_buf, + endpoints[n].out_len); + return -1; + } + + if (usb_out_buffer_full(n)) + return -1; + + usb_select_endpoint(ep_index(n, DIR_TX)); + max_pkt_size = endpoints[n].max_pkt_size[DIR_TX]; + len = endpoints[n].out_len - endpoints[n].out_ptr; + if (len > max_pkt_size) + len = max_pkt_size; + + ISP1583_DFLOW_BUFLEN = len; + p = endpoints[n].out_buf + endpoints[n].out_ptr; + i = 0; + while (len - i >= 2) { + ISP1583_DFLOW_DATA = p[i] | (p[i + 1] << 8); + i += 2; + } + if (i < len) + ISP1583_DFLOW_DATA = p[i]; + + endpoints[n].out_ptr += len; + +/* + if (endpoints[n].out_ptr == endpoints[n].out_len + && len < max_pkt_size) +*/ + if (endpoints[n].out_ptr == endpoints[n].out_len) + endpoints[n].out_ptr = -1; + return len; +} + +static void usb_stall_endpoint(int idx) +{ + usb_select_endpoint(idx); + ISP1583_DFLOW_CTRLFUN |= DFLOW_CTRLFUN_STALL; + endpoints[epidx_n(idx)].halt[epidx_dir(idx)] = 1; +} + +static void usb_unstall_endpoint(int idx) +{ + usb_select_endpoint(idx); + ISP1583_DFLOW_CTRLFUN &= ~DFLOW_CTRLFUN_STALL; + ISP1583_DFLOW_EPTYPE &= ~DFLOW_EPTYPE_ENABLE; + ISP1583_DFLOW_EPTYPE |= DFLOW_EPTYPE_ENABLE; + ISP1583_DFLOW_CTRLFUN |= DFLOW_CTRLFUN_CLBUF; + if (epidx_dir(idx) == DIR_TX) + endpoints[epidx_n(idx)].out_in_progress = 0; + else + { + endpoints[epidx_n(idx)].in_min_len = -1; + endpoints[epidx_n(idx)].in_ack = 0; + } + endpoints[epidx_n(idx)].halt[epidx_dir(idx)] = 0; +} +/* +static void usb_status_ack(int dir) +{ + usb_select_endpoint(ep_index(0, dir)); + ISP1583_DFLOW_CTRLFUN |= DFLOW_CTRLFUN_STATUS; +} + +static void usb_data_stage_enable(int dir) +{ + usb_select_endpoint(ep_index(0, dir)); + ISP1583_DFLOW_CTRLFUN |= DFLOW_CTRLFUN_DSEN; +}*/ + +static void usb_handle_setup_rx(void) +{ + int len; + usb_select_setup_endpoint(); + len = usb_get_packet(setup_pkt_buf, 8); + + if (len == 8) + usb_core_control_request((struct usb_ctrlrequest*)setup_pkt_buf); + logf("usb_handle_setup_rx() finished"); +} + +static void usb_handle_data_int(int ep, int dir) +{ + int len; + if (dir == DIR_TX) + len = usb_send(ep); + else + { + len = usb_receive(ep); + endpoints[ep].in_ack = 1; + } + usb_core_transfer_complete(ep, dir, 0, len); + logf("usb_handle_data_int(%d, %d) finished", ep, dir); +} + +bool usb_drv_powered(void) +{ +#if 0 + return (ISP1583_INIT_OTG & INIT_OTG_BSESS_VALID) ? true : false; +#else + return (ISP1583_INIT_MODE & INIT_MODE_VBUSSTAT) ? true : false; +#endif +} + +static void setup_endpoints(void) +{ + int i; + + for(i = 0; i < 7; i++) + { + usb_disable_endpoint(ep_index(i, DIR_RX)); + usb_disable_endpoint(ep_index(i, DIR_TX)); + } + + usb_setup_endpoint(ep_index(0, DIR_RX), 64, 0); + usb_setup_endpoint(ep_index(0, DIR_TX), 64, 0); + + for (i = 1; i < NUM_ENDPOINTS-1; i++) + { + usb_setup_endpoint(ep_index(i, DIR_RX), (high_speed_mode ? 512 : 64), 2); //2 = TYPE_BULK + usb_setup_endpoint(ep_index(i, DIR_TX), (high_speed_mode ? 512 : 64), 2); + } +} + +static void usb_debug(void) +{ + logf("ISP1583_INIT_INTEN: %x", ISP1583_INIT_INTEN_READ); + logf("ISP1583_GEN_INT: %x", ISP1583_GEN_INT_READ); + logf("ISP1583_GEN_CHIPID: %x", ISP1583_GEN_CHIPID); + sleep(1000); +} + +void usb_drv_init(void) +{ + int i; + + for (i = 0; i < NUM_ENDPOINTS; i++) + endpoints[i].enabled[0] = endpoints[i].enabled[1] = 0; + + /* Unlock the device's registers */ + ISP1583_GEN_UNLCKDEV = ISP1583_UNLOCK_CODE; + sleep(1); + /* Soft reset the device */ + ISP1583_INIT_MODE = INIT_MODE_SFRESET; + sleep(1); + ISP1583_INIT_MODE = 0; + sleep(5); + /* Enable CLKAON & GLINTENA */ + ISP1583_INIT_MODE = (INIT_MODE_CLKAON | INIT_MODE_GLINTENA); + sleep(1); + + usb_debug(); + +#if 0 + #ifdef USE_HIGH_SPEED + /* Force device to high speed */ + ISP1583_GEN_TSTMOD = GEN_TSTMOD_FORCEHS; + high_speed_mode = true; + #endif +#endif + + #ifdef DEBUG + logf("BUS_CONF/DA0:%d MODE0/DA1: %d MODE1: %d", ISP1583_INIT_MODE & INIT_MODE_TEST0, ISP1583_INIT_MODE & INIT_MODE_TEST1, ISP1583_INIT_MODE & INIT_MODE_TEST2); + logf("Chip ID: %x", ISP1583_GEN_CHIPID >> 8); + #endif + + /* Set interrupt generation to target-specific mode */ + ISP1583_INIT_INTCONF = INT_CONF_TARGET; + /* Enable USB interrupts */ + ISP1583_INIT_INTEN = ( + //INIT_INTEN_IEBRST | INIT_INTEN_IEHS_STA + INIT_INTEN_IEHS_STA + | INIT_INTEN_IERESM | INIT_INTEN_IESUSP + | INIT_INTEN_IEP0SETUP | INIT_INTEN_IEP0RX + | INIT_INTEN_IEP0TX + ); +#if 0 + /* Mask all interrupts */ + ISP1583_GEN_INT = 0x3FFFFFF; +#endif + + /* Enable interrupt at CPU level */ + EN_INT_CPU_TARGET; + + /* Clear device address and enable it */ + ISP1583_INIT_ADDRESS = INIT_ADDRESS_DEVEN; + + setup_endpoints(); + + /* SOFTCT on */ + ISP1583_INIT_MODE |= INIT_MODE_SOFTCT; + + logf("usb_drv_init() finished"); +} + +int usb_drv_port_speed(void) +{ + return (int)high_speed_mode; +} + +void usb_drv_exit(void) +{ + logf("usb_drv_exit()"); + /* Disable interrupts */ + ISP1583_INIT_INTEN = 0; + /* and the CPU's one... */ + DIS_INT_CPU_TARGET; + + /* Disable device */ + ISP1583_INIT_ADDRESS = 0; + + /* Send usb controller to suspend mode */ + ISP1583_INIT_MODE = INIT_MODE_GOSUSP; + ISP1583_INIT_MODE = 0; + + //cancel_cpu_boost(); +} + +void usb_drv_stall(int endpoint, bool stall, bool in) +{ + logf("%sstall EP%d %s", (stall ? "" : "un"), endpoint, (in ? "RX" : "TX" )); + if (stall) + usb_stall_endpoint(ep_index(endpoint, (int)in)); + else + usb_unstall_endpoint(ep_index(endpoint, (int)in)); +} + +bool usb_drv_stalled(int endpoint, bool in) +{ + return (endpoints[endpoint].halt[(int)in] == 1); +} + +int usb_drv_recv(int ep, void* ptr, int length) +{ + logf("usb_drv_recv(%d, ...)", ep); + endpoints[ep].in_done = NULL; + endpoints[ep].in_buf = ptr; + endpoints[ep].in_max_len = length; + endpoints[ep].in_min_len = length; + endpoints[ep].in_ptr = 0; + return usb_receive(ep); +} + +int usb_drv_send_nonblocking(int ep, void* ptr, int length) +{ + logf("usb_drv_send(%d, ...)", ep); + endpoints[ep].out_done = NULL; + endpoints[ep].out_buf = ptr; + endpoints[ep].out_len = length; + endpoints[ep].out_ptr = 0; + endpoints[ep].out_in_progress = 1; + return usb_send(ep); +} + +int usb_drv_send(int endpoint, void* ptr, int length) +{ + return usb_drv_send_nonblocking(endpoint, ptr, length); +} + +void usb_drv_reset_endpoint(int ep, bool send) +{ + logf("reset endpoint(%d, %d)", ep, send); + usb_setup_endpoint(ep_index(ep, (int)send), endpoints[ep].max_pkt_size[(int)send], endpoints[ep].type); +} + +void usb_drv_wait(int ep, bool send) +{ + logf("usb_drv_wait(%d, %d)", ep, send); + if(send) + { + while (endpoints[ep].out_in_progress) + nop_f(); + } + else + { + while (endpoints[ep].in_ack) + nop_f(); + } +} + +void usb_drv_cancel_all_transfers(void) +{ + logf("usb_drv_cancel_all_tranfers()"); + int i; + + for(i=0;idone"); +} + +static int count_bus_reset = 0; + +static void usb_handle_int(int i) +{ + printf("usb_handle_int(%d)", i); + if (i >= 10) /* Endpoint interrupt */ + { + printf("EP%d int", (i - 10) / 2); + usb_handle_data_int((i - 10) / 2, i % 2); + } + else + { + switch (i) + { + case 0: /* Bus reset */ + if(count_bus_reset>10) + break; + printf("bus reset"); + bus_reset(); + usb_core_bus_reset(); /* tell mom */ + count_bus_reset++; + break; + case 1: /* SOF interrupt */ + case 2: /* PseudoSOF interrupt */ + case 3: /* Suspend status: status change from active to suspend */ + case 4: /* Resume status: status change from suspend to resume (active) */ + case 5: /* change from full-speed to high-speed mode -> endpoints need to get reconfigured!! */ + case 6: /* change in the DMA Interrupt Reason register */ + case 7: /* transition from LOW to HIGH on VBUS */ + printf("other interrupt: %d", i); + break; + case 8: /* EP0SETUP interrupt */ + printf("EP0SETUP int"); + usb_handle_setup_rx(); + break; + } + } + +} + +/* Method for handling interrupts, must be called from usb-.c */ +void usb_drv_int(void) +{ + unsigned long ints; + int i; + int j = 0; + while (1) + { + #ifdef DEBUG + ints = ISP1583_GEN_INT; + logf("ints available: %x [%x]", ints, ISP1583_INIT_INTEN); + ints &= ISP1583_INIT_INTEN; + #else + ints = ISP1583_GEN_INT & ISP1583_INIT_INTEN; + #endif + if (!ints) break; + + logf(" [%d] handling int %x", j, ints); + + i = 0; + while (!(ints & (1 << i))) + i++; + ISP1583_GEN_INT = (1 << i); + usb_handle_int(i); + j++; + } + logf("leaving int handling (%d)", j); +} + +void usb_drv_set_address(int address) +{ + logf("usb_drv_set_address(%x)", address); + ISP1583_INIT_ADDRESS = (address & 0x7F) | INIT_ADDRESS_DEVEN; +} + +void usb_drv_set_test_mode(int mode) +{ + logf("usb_drv_set_test_mode(%d)", mode); + switch(mode){ + case 0: + //REG_PORTSC1 &= ~PORTSCX_PORT_TEST_CTRL; + break; + case 1: + ISP1583_GEN_TSTMOD = GEN_TSTMOD_JSTATE; + break; + case 2: + ISP1583_GEN_TSTMOD = GEN_TSTMOD_KSTATE; + break; + case 3: + ISP1583_GEN_TSTMOD = GEN_TSTMOD_SE0_NAK; + break; + case 4: + //REG_PORTSC1 |= PORTSCX_PTC_PACKET; + break; + case 5: + //REG_PORTSC1 |= PORTSCX_PTC_FORCE_EN; + break; + } + /*REG_USBCMD &= ~USBCMD_RUN; + udelay(50000); + REG_USBCMD |= USBCMD_CTRL_RESET; + while (REG_USBCMD & USBCMD_CTRL_RESET); + REG_USBCMD |= USBCMD_RUN;*/ +}