Lines Matching refs:softc

142 static int flash_sector_query(flashdev_t *softc,flash_sector_t *sector);
206 * FLASH_OP_BEGIN(softc)
212 * softc - our softc.
218 #define flash_op_begin(softc) softc->fd_iptr = 0;
221 * FLASH_OP_ADD(softc,op,dest,src,cnt)
226 * softc - our flash
233 static void flash_op_add(flashdev_t *softc,long base,long op,long dest,long src,long cnt)
235 flashinstr_t *fi = &(softc->fd_inst[softc->fd_iptr]);
243 softc->fd_iptr++;
248 * FLASH_OP_EXECUTE(softc)
253 * softc - our flash
259 static int flash_op_execute(flashdev_t *softc)
261 flash_op_add(softc,softc->fd_probe.flash_phys,FEOP_RETURN,0,0,0);
266 for (idx = 0; idx < softc->fd_iptr; idx++) {
268 softc->fd_inst[idx].fi_op,
269 softc->fd_inst[idx].fi_base,
270 softc->fd_inst[idx].fi_dest,
271 softc->fd_inst[idx].fi_src,
272 softc->fd_inst[idx].fi_cnt);
277 if (softc->fd_probe.flash_engine_hook) {
278 return (*(softc->fd_probe.flash_engine_hook))(&(softc->fd_inst[0]));
283 return (*flashop_engine_ram)(&(softc->fd_inst[0]));
288 * FLASH_ERASE_RANGE(softc,range)
293 * softc - our flash
301 static int flash_erase_range(flashdev_t *softc,flash_range_t *range)
306 if (softc->fd_probe.flash_type != FLASH_TYPE_FLASH) {
310 if (range->range_base+range->range_length > softc->fd_probe.flash_size) {
319 res = flash_sector_query(softc,&sector);
329 flash_op_begin(softc);
330 flash_op_add(softc,softc->fd_probe.flash_phys,
331 softc->fd_erasefunc,
334 res = flash_op_execute(softc);
346 * FLASH_ERASE_ALL(softc)
352 * softc - our flash
359 static int flash_erase_all(flashdev_t *softc)
364 range.range_length = softc->fd_probe.flash_size *
365 softc->fd_probe.flash_nchips;
367 return flash_erase_range(softc,&range);
425 * FLASH_SECTOR_QUERY(softc,sector)
431 * softc - our flash info
439 static int flash_sector_query(flashdev_t *softc,flash_sector_t *sector)
449 if (softc->fd_probe.flash_type != FLASH_TYPE_FLASH) {
453 if (softc->fd_probe.flash_nsectors == 0) {
458 whichchip = sector->flash_sector_idx / softc->fd_ttlsect;
459 if (whichchip >= softc->fd_probe.flash_nchips) {
465 offset = softc->fd_probe.flash_size * whichchip;
466 secidx = sector->flash_sector_idx % softc->fd_ttlsect;
469 for (idx = 0; idx < softc->fd_probe.flash_nsectors; idx++) {
470 nblks = FLASH_SECTOR_NBLKS(softc->fd_probe.flash_sectors[idx]);
471 blksiz = FLASH_SECTOR_SIZE(softc->fd_probe.flash_sectors[idx]);
485 if (idx == softc->fd_probe.flash_nsectors) {
494 * FLASH_SET_CMDSET(softc,cmdset,bus16,dev16)
499 * softc - our flash
512 static void flash_set_cmdset(flashdev_t *softc,int cmdset,int bus16,int dev16)
519 softc->fd_erasefunc = FEOP_INTEL_ERASE16;
520 softc->fd_pgmfunc = FEOP_INTEL_PGM16;
521 softc->fd_readfunc = FEOP_READ16;
524 softc->fd_erasefunc = FEOP_INTEL_ERASE8;
525 softc->fd_pgmfunc = FEOP_INTEL_PGM32B;
526 softc->fd_readfunc = FEOP_READ8;
534 softc->fd_erasefunc = FEOP_AMD_ERASE8;
535 softc->fd_pgmfunc = FEOP_AMD_PGM8;
536 softc->fd_readfunc = FEOP_READ8;
539 softc->fd_erasefunc = FEOP_AMD_ERASE16;
540 softc->fd_pgmfunc = FEOP_AMD_PGM16;
541 softc->fd_readfunc = FEOP_READ16;
544 softc->fd_erasefunc = FEOP_AMD_ERASE16B;
545 softc->fd_pgmfunc = FEOP_AMD_PGM16B;
546 softc->fd_readfunc = FEOP_READ8;
552 if (softc->fd_probe.flash_type == FLASH_TYPE_FLASH)
553 softc->fd_probe.flash_type = FLASH_TYPE_ROM;
554 softc->fd_erasefunc = FEOP_RETURN;
555 softc->fd_pgmfunc = FEOP_RETURN;
556 softc->fd_readfunc = bus16 ? FEOP_READ16 : FEOP_READ8;
563 * FLASH_CFI_PROBE(softc)
570 * softc - out flash
575 static int flash_cfi_probe(flashdev_t *softc)
589 if (softc->fd_probe.flash_flags & FLASH_FLG_BUS16) {
595 if (softc->fd_probe.flash_flags & FLASH_FLG_DEV16) {
599 flash_op_begin(softc);
600 flash_op_add(softc,softc->fd_probe.flash_phys,
602 flash_op_execute(softc);
608 printf(" flash at %08x, CFI:", softc->fd_probe.flash_phys);
639 softc->fd_probe.flash_type = FLASH_TYPE_FLASH;
644 softc->fd_probe.flash_size =
658 softc->fd_probe.flash_nsectors = regcnt;
669 if (softc->fd_probe.flash_flags & FLASH_FLG_DEV16) {
670 idx = (softc->fd_probe.flash_flags & FLASH_FLG_BUS16) ?
674 flash_op_begin(softc);
675 flash_op_add(softc,softc->fd_probe.flash_phys,
677 flash_op_execute(softc);
693 softc->fd_probe.flash_sectors[((regcnt-1)-idx)] =
698 softc->fd_probe.flash_sectors[idx] =
704 flash_set_cmdset(softc,cmdset,bus16,dev16);
711 * FLASH_JEDEC_PROBE(softc)
718 * softc - out flash
723 static int flash_jedec_probe(flashdev_t *softc)
737 int bus16 = (softc->fd_probe.flash_flags & FLASH_FLG_BUS16) != 0;
748 if (softc->fd_probe.flash_flags & FLASH_FLG_DEV16) {
752 flash_op_begin(softc);
753 flash_op_add(softc,softc->fd_probe.flash_phys,idx,(long)&vendor,0,0);
754 flash_op_execute(softc);
757 if (softc->fd_probe.flash_flags & FLASH_FLG_DEV16) {
761 flash_op_begin(softc);
762 flash_op_add(softc,softc->fd_probe.flash_phys,idx,(long)&device,0,0);
763 flash_op_execute(softc);
783 softc->fd_probe.flash_type = FLASH_TYPE_FLASH;
788 softc->fd_probe.flash_size = jedec_table[i].size;
795 blksiz = softc->fd_probe.flash_size/nsectors;
798 softc->fd_probe.flash_nsectors = nsectors;
800 softc->fd_probe.flash_sectors[i] = FLASH_SECTOR_RANGE(nblks,blksiz);
804 flash_set_cmdset(softc,cmdset,bus16,dev16);
811 * FLASH_DO_PROBE(softc)
817 * softc - our structure
822 static int flash_do_probe(flashdev_t *softc)
834 softc->fd_inst = KMALLOC(FLASH_MAX_INST*sizeof(flashinstr_t),0);
835 if (!softc->fd_inst) return FLASH_TYPE_ROM;
844 ptr = (volatile uint8_t *) UNCADDR(softc->fd_probe.flash_phys);
851 softc->fd_probe.flash_type = FLASH_TYPE_SRAM;
862 softc->fd_probe.flash_type = FLASH_TYPE_ROM;
872 found = (flash_cfi_probe(softc) == 0);
874 found = (flash_jedec_probe(softc) == 0);
878 flash_set_cmdset(softc,-1,
879 (softc->fd_probe.flash_flags & FLASH_FLG_BUS16),
880 (softc->fd_probe.flash_flags & FLASH_FLG_DEV16));
883 KFREE(softc->fd_inst);
884 softc->fd_inst = NULL;
886 return softc->fd_probe.flash_type;
914 static void flash_do_parts(flashdev_t *softc)
919 newflash_probe_t *probe = &(softc->fd_probe);
920 flashpart_t *parts = &(softc->fd_parts[0]);
971 static void flashdrv_allocbuf(flashdev_t *softc)
985 softc->fd_sectorbuffer = flash_sector_buffer;
1008 flashdev_t *softc;
1018 softc = (flashdev_t *) KMALLOC(sizeof(flashdev_t),0);
1019 if (softc) {
1020 memset(softc,0,sizeof(flashdev_t));
1022 flashdrv_allocbuf(softc);
1026 memcpy(&(softc->fd_probe),probe,sizeof(newflash_probe_t));
1027 if (softc->fd_probe.flash_nchips == 0) {
1028 softc->fd_probe.flash_nchips = 1;
1033 softc->fd_probe.flash_phys = probe_a;
1034 softc->fd_probe.flash_size = (probe_b & FLASH_SIZE_MASK);
1035 softc->fd_probe.flash_flags = (probe_b & FLASH_FLG_MASK);
1036 softc->fd_probe.flash_nchips = 1;
1039 if (softc->fd_probe.flash_flags & FLASH_FLG_MANUAL) {
1041 flash_set_cmdset(softc,softc->fd_probe.flash_cmdset,
1042 (softc->fd_probe.flash_flags & FLASH_FLG_BUS16),
1043 (softc->fd_probe.flash_flags & FLASH_FLG_DEV16));
1048 flash_do_probe(softc);
1055 softc->fd_ttlsize = softc->fd_probe.flash_nchips * softc->fd_probe.flash_size;
1060 softc->fd_probe.flash_phys,
1061 softc->fd_ttlsize/1024);
1062 if (softc->fd_probe.flash_nchips > 1) {
1063 xsprintf(x," (%d chips)",softc->fd_probe.flash_nchips);
1071 if (softc->fd_probe.flash_nparts == 0) {
1072 softc->fd_parts[0].fp_dev = softc;
1073 softc->fd_parts[0].fp_offset = 0;
1074 softc->fd_parts[0].fp_size = softc->fd_probe.flash_size;
1075 cfe_attach_idx(drv,flashidx,&(softc->fd_parts[0]),NULL,descr);
1079 flash_do_parts(softc);
1082 for (idx = 0; idx < softc->fd_probe.flash_nparts; idx++) {
1088 softc->fd_probe.flash_phys,
1089 softc->fd_parts[idx].fp_offset,
1090 (softc->fd_parts[idx].fp_size+1023)/1024);
1092 softc->fd_parts[idx].fp_dev = softc;
1093 if (softc->fd_probe.flash_parts[idx].fp_name == NULL) {
1098 nptr = softc->fd_probe.flash_parts[idx].fp_name;
1102 &(softc->fd_parts[idx]),
1111 softc->fd_ttlsect = 0;
1112 for (idx = 0; idx < softc->fd_probe.flash_nsectors; idx++) {
1113 softc->fd_ttlsect += FLASH_SECTOR_NBLKS(softc->fd_probe.flash_sectors[idx]);
1134 flashdev_t *softc = part->fp_dev;
1135 int ttlsect = softc->fd_ttlsect;
1143 ttlsect = (ttlsect * 2 * softc->fd_probe.flash_nchips) + 6;
1148 softc->fd_inst = KMALLOC(ttlsect*sizeof(flashinstr_t),0);
1149 if (!softc->fd_inst) return CFE_ERR_NOMEM;
1172 flashdev_t *softc = part->fp_dev;
1186 flash_op_begin(softc);
1187 flash_op_add(softc,softc->fd_probe.flash_phys,
1188 softc->fd_readfunc,(long)buffer->buf_ptr,offset,blen);
1189 flash_op_execute(softc);
1234 flashdev_t *softc = part->fp_dev;
1269 flash_op_begin(softc);
1272 res = flash_sector_query(softc,&sector);
1278 whichchip = sector.flash_sector_idx / softc->fd_ttlsect;
1279 chipbase = softc->fd_probe.flash_phys +
1280 (long) (whichchip * softc->fd_probe.flash_size);
1301 flash_op_add(softc,chipbase,
1302 softc->fd_erasefunc,
1305 flash_op_add(softc,chipbase,
1306 softc->fd_pgmfunc,
1314 flash_op_add(softc,chipbase,
1315 softc->fd_readfunc,
1316 (long)(softc->fd_sectorbuffer),
1320 flash_op_add(softc,chipbase,
1322 ((long)(softc->fd_sectorbuffer))+(outrange.range_base-sector.flash_sector_offset),
1326 flash_op_add(softc,chipbase,
1327 softc->fd_erasefunc,
1331 flash_op_add(softc,chipbase,
1332 softc->fd_pgmfunc,
1334 (long)(softc->fd_sectorbuffer),
1347 flash_op_add(softc,softc->fd_probe.flash_phys,FEOP_REBOOT,0,0,0);
1350 res = flash_op_execute(softc);
1380 flashdev_t *softc = part->fp_dev;
1396 if (softc->fd_probe.flash_nparts <= 1) {
1412 if (offset >= softc->fd_probe.flash_size) return -1;
1414 flash_op_begin(softc);
1415 flash_op_add(softc,
1416 softc->fd_probe.flash_phys,
1417 softc->fd_erasefunc,
1420 flash_op_execute(softc);
1426 flash_erase_all(softc);
1435 info.flash_base = softc->fd_probe.flash_phys;
1436 info.flash_size = softc->fd_probe.flash_size;
1437 info.flash_type = softc->fd_probe.flash_type;
1444 ret = flash_sector_query(softc,&fsect);
1454 ret = flash_erase_range(softc,&range);
1461 if (softc->fd_probe.flash_ioctl_hook) {
1462 return (*(softc->fd_probe.flash_ioctl_hook))(ctx,buffer);
1485 flashdev_t *softc = part->fp_dev;
1487 if (softc->fd_inst) {
1488 KFREE(softc->fd_inst);
1491 softc->fd_inst = NULL;