/* $Id: plx9080_eeprom.c,v 1.2 2007/02/09 01:39:03 saa Exp $ */ /* PLX9080 serial EEPROM access (93CS46 device) */ #include #include #include #include #include #include #include #include #include #define BSP_pciFindDevice pci_find_device #ifdef __PPC__ #include #define TBNS (1000000/(BSP_bus_frequency/BSP_time_base_divisor)) #if 0 #define TBNS 60 /* 1 timebase tick is 60ns (66.6 MHz bus) */ #endif #endif /* timing for the 93CS46, 93C66 (in ns) */ #define EE_SETUP_TIME 400 /* exceeds CS setup */ #define EE_CLKHI_TIME 1000 #define EE_CLKLO_TIME 1000 #define EE_CS_LO_TIME 1000 /* EEPROM device parameters (different for the larger CS56) */ #define C46 0 #define C56 1 #define C66 2 typedef struct { char *name; int abits; int size_bits; } Eeprom93CxxDesc; static Eeprom93CxxDesc eeDesc[] = { { "93C46", 6, 1024, }, { "93C56", 8, /* needs the extra clock cycle */ 2048, }, { "93C66", 8, 4096, }, {0} }; #define ABITS (eeDesc[plx9080_ee_type].abits) #define EE_SIZE_BITS (eeDesc[plx9080_ee_type].size_bits) #define EE_WORDS (EE_SIZE_BITS/D_LEN) /* size in words */ #define D_LEN 16 /* data bits */ #define CMD_LEN (ABITS+3) /* EEPROM operations */ #define EE_CMD(op,addr) ((1<<(ABITS + 2)) | \ ((op) << ABITS) | \ ((addr) & ((1<>=1; } while (len); } static long do_write(int address, int *pval, int n) { volatile unsigned *rp = plx9080_ee_reg; /* write enable */ cs(1, rp); ww(CMD_WEN(), CMD_LEN, rp); cs(0, rp); /* write a word of data */ cs(1, rp); while (n--) { /* erase location */ ww(CMD_ERASE(address), CMD_LEN, rp); /* lower CS; this starts the erase cycle */ cs(0,rp); cs(1,rp); do { rtems_task_wake_after(1); } while ( ! (in_le32(rp) & EE_RD) ); cs(0,rp); cs(1,rp); /* write address */ ww(CMD_WRITE(address), CMD_LEN, rp); /* write data */ ww(*pval, D_LEN, rp); /* lower CS; this starts the programming cycle */ cs(0,rp); cs(1,rp); do { rtems_task_wake_after(1); } while ( ! (in_le32(rp) & EE_RD) ); cs(0, rp); cs(1, rp); pval++; address++; } /* write disable */ ww(CMD_WDS(), CMD_LEN, rp); cs(0, rp); return 0; } long plx9080_ee_write(int address, int value) { if ( plx9080_ee_type < 0 ) { fprintf(stderr,"plx9080_ee_init() not executed\n"); return -1; } if ( (address & ~(EE_WORDS-1)) ) { fprintf(stderr,"Invalid address: 0x%08x\n",address); return -1; } if ( (value & ~((1<=EE_WORDS) { fprintf(stderr,"Too many values in file\n"); goto cleanup; } /* skip to EOL or EOF */ do { ch = getc(fp); } while ( EOF !=ch && '\n' != ch ); } assert( i <= EE_WORDS ); #if 1 rval = do_write(0, vals, i); #else { int j; for ( j=0; j 0 ) { rval = 0; for ( i = 0; i < D_LEN; i++) { rval<<=1; rval |= wb(0, rp) ? 1 : 0; } if ( f ) fprintf(f,"0x%04x\n",rval); } cs(0, rp); return rval; } static void usage() { fprintf(stderr,"Usage: plx9080_ee_init(int instance, int plxType, int eeType)\n"); fprintf(stderr," known plxTypes are 9080, 9030\n"); fprintf(stderr," known eeTypes are 46 56 66 (atmel 93Cxx)\n"); } long plx9080_ee_init(int instance, int plxType, int eeType) { int b,d,f,hasee; unsigned base; unsigned devid; unsigned off; unsigned tmp; switch( plxType ) { default: fprintf(stderr,"Unknown PLX type %u\n",plxType); usage(); return -1; case 9030: devid = PCI_DEVICE_ID_PLX_9030; off = EE_REG_OFF_9030; break; case 9080: devid = PCI_DEVICE_ID_PLX_9080; off = EE_REG_OFF_9080; break; } switch (eeType) { default: fprintf(stderr,"Unknown EEPROM type %u\n",eeType); usage(); return -1; case 46: plx9080_ee_type = C46; break; case 56: plx9080_ee_type = C56; break; case 66: plx9080_ee_type = C66; break; } if (0==BSP_pciFindDevice(PCI_VENDOR_ID_PLX, devid, instance, &b,&d,&f)) { pci_read_config_dword(b,d,f,PCI_BASE_ADDRESS_0,&base); printf("PLX %u found at 0x%08x", plxType, base); pci_read_config_dword(b,d,f,PCI_SUBSYSTEM_VENDOR_ID,&tmp); plx9080_ee_reg = (volatile unsigned *)(base + off); } else { fprintf(stderr,"NO PLX %u unit #%u found\n", plxType, instance); return -1; } hasee = (in_le32(plx9080_ee_reg) & EE_PRES); printf(", %sEEPROM present\n", hasee ? "" : "NO "); printf("Subsytem vendor ID 0x%04x, device ID 0x%04x\n", tmp & 0xffff, (tmp>>16)&0xffff); return hasee ? 0 : -1; }