Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 678994
Collapse All | Expand All

(-)pigpio/pigpio.c (+89 lines)
Lines 1511-1516 Link Here
1511
   return valid;
1511
   return valid;
1512
}
1512
}
1513
1513
1514
1515
1516
static unsigned get_dt_ranges(const char *filename, unsigned offset)
1517
{
1518
   unsigned address = ~0;
1519
   FILE *fp = fopen(filename, "rb");
1520
   if (fp)
1521
   {
1522
      unsigned char buf[4];
1523
      fseek(fp, offset, SEEK_SET);
1524
      if (fread(buf, 1, sizeof buf, fp) == sizeof buf)
1525
         address = buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3] << 0;
1526
      fclose(fp);
1527
   }
1528
   return address;
1529
}
1530
1531
unsigned bcm_host_get_peripheral_address(void)
1532
{
1533
   unsigned address = get_dt_ranges("/proc/device-tree/soc/ranges", 4);
1534
   return address == ~0 ? 0x20000000 : address;
1535
}
1536
1537
unsigned bcm_host_get_peripheral_size(void)
1538
{
1539
   unsigned address = get_dt_ranges("/proc/device-tree/soc/ranges", 8);
1540
   return address == ~0 ? 0x01000000 : address;
1541
}
1542
1543
unsigned bcm_host_get_sdram_address(void)
1544
{
1545
    unsigned address = get_dt_ranges("/proc/device-tree/axi/vc_mem/reg", 8);
1546
    return address == ~0 ? 0x40000000 : address;
1547
}
1548
1549
1550
1551
1552
1553
1554
1514
/* ----------------------------------------------------------------------- */
1555
/* ----------------------------------------------------------------------- */
1515
1556
1516
static char * myTimeStamp()
1557
static char * myTimeStamp()
Lines 13338-13343 Link Here
13338
      }
13379
      }
13339
13380
13340
      fclose(filp);
13381
      fclose(filp);
13382
13383
13384
      if ( piCores == 0)
13385
          {
13386
	  if ( !strncasecmp("processor\t: 0", buf, 10) )
13387
	  	{
13388
	  	piCores=1;
13389
                piCores = 1;
13390
                pi_peri_phys = 0x20000000;
13391
                pi_dram_bus  = 0x40000000;
13392
                pi_mem_flag  = 0x0C;
13393
                }
13394
13395
	  else if ( strncasecmp( "processor\t: 3", buf, 10) )
13396
	  	{
13397
	  	piCores=4;
13398
		pi_peri_phys = bcm_host_get_peripheral_address();
13399
		pi_dram_bus  = bcm_host_get_sdram_address();
13400
		pi_mem_flag  = 0x04;
13401
		}
13402
	  }
13403
13404
printf("peripheral address %x\n", pi_peri_phys);
13405
printf("sdram_address %x\n", pi_dram_bus);
13406
      printf("piCores: %d\n", piCores);
13407
13408
      if ( rev == 0 )
13409
      	  {
13410
	  filp =  fopen( "/proc/device-tree/system/linux,revision", "r" );
13411
	  if (filp != NULL)
13412
      		{  
13413
            	while (fgets(buf, sizeof(buf), filp) != NULL)
13414
	            {  
13415
		    rev = (unsigned)buf[0];
13416
		    rev <<= 8;
13417
		    rev |= (unsigned)buf[1];
13418
		    rev <<= 8;
13419
                    rev |= (unsigned)buf[2];
13420
		    rev <<= 8;
13421
		    rev |= (unsigned)buf[3];
13422
		    }
13423
		}
13424
	  fclose( filp );
13425
	  }
13426
	
13427
      printf("revision: %8x\n", rev );
13428
13429
13341
   }
13430
   }
13342
   return rev;
13431
   return rev;
13343
}
13432
}

Return to bug 678994