@@ -209,35 +209,77 @@ static volatile uint32_t *timerIrqRaw ;
static int piModel2 = FALSE ;
const char *piModelNames [7 ] =
const char *piModelNames [16 ] =
{
"Unknown",
"Model A",
"Model B",
"Model B+",
"Compute Module",
"Model A+",
"Model 2", // Quad Core
"Model A", // 0
"Model B", // 1
"Model A+", // 2
"Model B+", // 3
"Pi 2", // 4
"Alpha", // 5
"CM", // 6
"Unknown07", // 07
"Unknown08", // 08
"Pi Zero", // 09
"Unknown10", // 10
"Unknown11", // 11
"Unknown12", // 12
"Unknown13", // 13
"Unknown14", // 14
"Unknown15", // 15
} ;
const char *piRevisionNames [5] =
const char *piRevisionNames [16 ] =
{
"Unknown",
"1",
"1.1",
"1.2",
"2",
"00",
"01",
"02",
"03",
"04",
"05",
"06",
"07",
"08",
"09",
"10",
"11",
"12",
"13",
"14",
"15",
} ;
const char *piMakerNames [5] =
const char *piMakerNames [16 ] =
{
"Unknown",
"Egoman",
"Sony",
"Qusda",
"MBest",
"Sony", // 0
"Egoman", // 1
"Embest", // 2
"Unknown", // 3
"Embest", // 4
"Unknown05", // 5
"Unknown06", // 6
"Unknown07", // 7
"Unknown08", // 8
"Unknown09", // 9
"Unknown10", // 10
"Unknown11", // 11
"Unknown12", // 12
"Unknown13", // 13
"Unknown14", // 14
"Unknown15", // 15
} ;
const int piMemorySize [8] =
{
256, // 0
512, // 1
1024, // 2
0, // 3
0, // 4
0, // 5
0, // 6
0, // 7
} ;
// Time for easy calculations
@@ -612,43 +654,20 @@ int wiringPiFailure (int fatal, const char *message, ...)
/*
* piBoardRev:
* Return a number representing the hardware revision of the board.
* This is not strictly the board revision but is used to check the
* layout of the GPIO connector - and there are 2 types that we are
* really interested in here. The very earliest Pi's and the
* ones that came after that which switched some pins ....
*
* Revision 1 really means the early Model B's.
* Revision 1 really means the early Model A and B's.
* Revision 2 is everything else - it covers the B, B+ and CM.
* ... and the Pi 2 - which is a B+ ++ ...
* ... and the Pi 0 - which is an A+ ...
*
* Seems there are some boards with 0000 in them (mistake in manufacture)
* So the distinction between boards that I can see is:
* 0000 - Error
* 0001 - Not used
* 0002 - Model B, Rev 1, 256MB, Egoman
* 0003 - Model B, Rev 1.1, 256MB, Egoman, Fuses/D14 removed.
* 0004 - Model B, Rev 2, 256MB, Sony
* 0005 - Model B, Rev 2, 256MB, Qisda
* 0006 - Model B, Rev 2, 256MB, Egoman
* 0007 - Model A, Rev 2, 256MB, Egoman
* 0008 - Model A, Rev 2, 256MB, Sony
* 0009 - Model A, Rev 2, 256MB, Qisda
* 000d - Model B, Rev 2, 512MB, Egoman
* 000e - Model B, Rev 2, 512MB, Sony
* 000f - Model B, Rev 2, 512MB, Qisda
* 0010 - Model B+, Rev 1.2, 512MB, Sony
* 0011 - Pi CM, Rev 1.2, 512MB, Sony
* 0012 - Model A+ Rev 1.2, 256MB, Sony
* 0014 - Pi CM, Rev 1.1, 512MB, Sony (Actual Revision might be different)
* 0015 - Model A+ Rev 1.1, 256MB, Sony
*
* For the Pi 2:
* 0010 - Model 2, Rev 1.1, Quad Core, 1GB, Sony
*
* A small thorn is the olde style overvolting - that will add in
* 1000000
*
* The Pi compute module has an revision of 0011 - since we only check the
* last digit, then it's 1, therefore it'll default to not 2 or 3 for a
* Rev 1, so will appear as a Rev 2. This is fine for the most part, but
* we'll properly detect the Compute Module later and adjust accordingly.
* And the next rev of the CN is 0014 ...
* The main difference between the revision 1 and 2 system that I use here
* is the mapping of the GPIO pins. From revision 2, the Pi Foundation changed
* 3 GPIO pins on the (original) 26-way header - BCM_GPIO 22 was dropped and
* replaced with 27, and 0 + 1 - I2C bus 0 was changed to 2 + 3; I2C bus 1.
*
*********************************************************************************
*/
@@ -675,22 +694,28 @@ int piBoardRev (void)
if ((cpuFd = fopen ("/proc/cpuinfo", "r")) == NULL)
piBoardRevOops ("Unable to open /proc/cpuinfo") ;
// Start by looking for the Architecture, then we can look for a B2 revision....
// Start by looking for the Architecture to make sure we're really running
// on a Pi. I'm getting fed-up with people whinging at me because
// they can't get it to work on weirdFruitPi boards...
while (fgets (line, 120, cpuFd) != NULL)
if (strncmp (line, "Hardware", 8) == 0)
break ;
if (strncmp (line, "Hardware", 8) != 0)
piBoardRevOops ("No \"Hardware\" line") ;
piBoardRevOops ("No hardware line") ;
if (wiringPiDebug)
printf ("piboardRev: Hardware: %s\n", line) ;
// See if it's BCM2708 or BCM2709
if (strstr (line, "BCM2709") != NULL)
if (strstr (line, "BCM2709") != NULL) // Pi v2 - no point doing anything more at this point
{
piModel2 = TRUE ;
fclose (cpuFd) ;
return boardRev = 2 ;
}
else if (strstr (line, "BCM2708") == NULL)
{
fprintf (stderr, "Unable to determine hardware version. I see: %s,\n", line) ;
@@ -702,10 +727,12 @@ int piBoardRev (void)
exit (EXIT_FAILURE) ;
}
// Now do the rest of it as before
// Now do the rest of it as before - we just need to see if it's an older
// Rev 1 as anything else is rev 2.
rewind (cpuFd) ;
// Isolate the Revision line
rewind (cpuFd) ;
while (fgets (line, 120, cpuFd) != NULL)
if (strncmp (line, "Revision", 8) == 0)
break ;
@@ -723,28 +750,43 @@ int piBoardRev (void)
if (wiringPiDebug)
printf ("piboardRev: Revision string: %s\n", line) ;
// Scan to first digit
// Scan to the first character of the revision number
for (c = line ; *c ; ++c)
if (isdigit (*c) )
if (*c == ':' )
break ;
if (!isdigit (*c))
piBoardRevOops ("No numeric revision string") ;
if (*c != ':')
piBoardRevOops ("Bogus \"Revision\" line (no colon)") ;
// Chomp spaces
++c ;
while (isspace (*c))
++c ;
if (!isxdigit (*c))
piBoardRevOops ("Bogus \"Revision\" line (no hex digit at start of revision)") ;
// Make sure its long enough
if (strlen (c) < 4)
piBoardRevOops ("Bogus \"Revision\" line (too small)") ;
piBoardRevOops ("Bogus revision line (too small)") ;
// If you have overvolted the Pi, then it appears that the revision
// has 100000 added to it!
// The actual condition for it being set is:
// (force_turbo || current_limit_override || temp_limit>85) && over_voltage>0
// This test is not correct for the new encoding scheme, so we'll remove it here as
// we don't really need it at this point.
/********************
if (wiringPiDebug)
if (strlen (c) != 4)
printf ("piboardRev: This Pi has/is (force_turbo || current_limit_override || temp_limit>85) && over_voltage>0\n") ;
*******************/
// Isolate last 4 characters:
@@ -767,12 +809,49 @@ int piBoardRev (void)
/*
* piBoardId:
* Do more digging into the board revision string as above, but return
* as much details as we can.
* Return the real details of the board we have.
*
* This is undocumented and really only intended for the GPIO command.
* Use at your own risk!
*
* for Pi v2:
* Seems there are some boards with 0000 in them (mistake in manufacture)
* So the distinction between boards that I can see is:
*
* 0000 - Error
* 0001 - Not used
*
* Original Pi boards:
* 0002 - Model B, Rev 1, 256MB, Egoman
* 0003 - Model B, Rev 1.1, 256MB, Egoman, Fuses/D14 removed.
*
* Newer Pi's with remapped GPIO:
* 0004 - Model B, Rev 2, 256MB, Sony
* 0005 - Model B, Rev 2, 256MB, Qisda
* 0006 - Model B, Rev 2, 256MB, Egoman
* 0007 - Model A, Rev 2, 256MB, Egoman
* 0008 - Model A, Rev 2, 256MB, Sony
* 0009 - Model A, Rev 2, 256MB, Qisda
* 000d - Model B, Rev 2, 512MB, Egoman (Red Pi, Blue Pi?)
* 000e - Model B, Rev 2, 512MB, Sony
* 000f - Model B, Rev 2, 512MB, Qisda
* 0010 - Model B+, Rev 1.2, 512MB, Sony
* 0011 - Pi CM, Rev 1.2, 512MB, Sony
* 0012 - Model A+ Rev 1.2, 256MB, Sony
* 0014 - Pi CM, Rev 1.1, 512MB, Sony (Actual Revision might be different)
* 0015 - Model A+ Rev 1.1, 256MB, Sony
*
* A small thorn is the olde style overvolting - that will add in
* 1000000
*
* The Pi compute module has an revision of 0011 or 0014 - since we only
* check the last digit, then it's 1, therefore it'll default to not 2 or
* 3 for a Rev 1, so will appear as a Rev 2. This is fine for the most part, but
* we'll properly detect the Compute Module later and adjust accordingly.
*
* And then things changed with the introduction of the v2...
*
* For Pi v2 and subsequent models - e.g. the Zero:
*
* [USER:8] [NEW:1] [MEMSIZE:3] [MANUFACTURER:4] [PROCESSOR:4] [TYPE:8] [REV:4]
* NEW 23: will be 1 for the new scheme, 0 for the old scheme
* MEMSIZE 20: 0=256M 1=512M 2=1G
@@ -783,11 +862,13 @@ int piBoardRev (void)
*********************************************************************************
*/
void piBoardId (int *model, int *rev, int *mem, int *maker, int *overVolted )
void piBoardId (int *model, int *rev, int *mem, int *maker, int *warranty )
{
FILE *cpuFd ;
char line [120] ;
char *c ;
unsigned int revision ;
int bRev, bType, bProc, bMfg, bMem, bWarranty ;
// Will deal with the properly later on - for now, lets just get it going...
// unsigned int modelNum ;
@@ -814,33 +895,59 @@ void piBoardId (int *model, int *rev, int *mem, int *maker, int *overVolted)
if (wiringPiDebug)
printf ("piboardId: Revision string: %s\n", line) ;
if (piModel2)
{
// Need to work out if it's using the new or old encoding scheme:
// Scan to the colon
// Scan to the first character of the revision number
for (c = line ; *c ; ++c)
if (*c == ':')
break ;
for (c = line ; *c ; ++c)
if (*c == ':')
break ;
if (*c != ':')
piBoardRevOops ("Bogus \"Revision\" line (no colon)") ;
if (*c != ':')
piBoardRevOops ("Bogus \"Revision\" line (no colon)") ;
// modelNum = (unsigned int)strtol (++c, NULL, 16) ; // Hex number with no leading 0x
// Chomp spaces
++c ;
while (isspace (*c))
++c ;
if (!isxdigit (*c))
piBoardRevOops ("Bogus \"Revision\" line (no hex digit at start of revision)") ;
revision = (unsigned int)strtol (c, NULL, 16) ; // Hex number with no leading 0x
// Check for new way:
if ((revision & (1 << 23)) != 0) // New way
{
if (wiringPiDebug)
printf ("piBoardId: New Way: revision is: 0x%08X\n", revision) ;
bRev = (revision & (0x0F << 0)) >> 0 ;
bType = (revision & (0xFF << 4)) >> 4 ;
bProc = (revision & (0x0F << 12)) >> 12 ; // Not used for now.
bMfg = (revision & (0x0F << 16)) >> 16 ;
bMem = (revision & (0x07 << 20)) >> 20 ;
bWarranty = (revision & (0x03 << 24)) != 0 ;
*model = PI_MODEL_2 ;
*rev = PI_VERSION_1_1 ;
*mem = 1024 ;
*maker = PI_MAKER_SONY ;
*model = bType ;
*rev = bRev ;
*mem = bMem ;
*maker = bMfg ;
*warranty = bWarranty ;
if (wiringPiDebug)
printf ("piboardId: rev: %d, type: %d, proc: %d, mfg: %d, mem: %d, warranty: %d\n",
bRev, bType, bProc, bMfg, bMem, bWarranty) ;
}
else
else // Old way
{
if (wiringPiDebug)
printf ("piBoardId: Old Way: revision is: %s\n", c) ;
// Scan to first digit
for (c = line ; *c ; ++c)
if (isdigit (*c))
break ;
if (!isdigit (*c))
piBoardRevOops ("Bogus \"Revision\" line (no digit at start of revision)") ;
// Make sure its long enough
@@ -849,7 +956,7 @@ void piBoardId (int *model, int *rev, int *mem, int *maker, int *overVolted)
// If longer than 4, we'll assume it's been overvolted
*overVolted = strlen (c) > 4 ;
*warranty = strlen (c) > 4 ;
// Extract last 4 characters:
@@ -857,23 +964,23 @@ void piBoardId (int *model, int *rev, int *mem, int *maker, int *overVolted)
// Fill out the replys as appropriate
/**/ if (strcmp (c, "0002") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_1 ; *mem = 256 ; *maker = PI_MAKER_EGOMAN ; }
else if (strcmp (c, "0003") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_1_1 ; *mem = 256 ; *maker = PI_MAKER_EGOMAN ; }
else if (strcmp (c, "0004") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 256 ; *maker = PI_MAKER_SONY ; }
else if (strcmp (c, "0005") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 256 ; *maker = PI_MAKER_QISDA ; }
else if (strcmp (c, "0006") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 256 ; *maker = PI_MAKER_EGOMAN ; }
else if (strcmp (c, "0007") == 0) { *model = PI_MODEL_A ; *rev = PI_VERSION_2 ; *mem = 256 ; *maker = PI_MAKER_EGOMAN ; }
else if (strcmp (c, "0008") == 0) { *model = PI_MODEL_A ; *rev = PI_VERSION_2 ; *mem = 256 ; *maker = PI_MAKER_SONY ; ; }
else if (strcmp (c, "0009") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 256 ; *maker = PI_MAKER_QISDA ; }
else if (strcmp (c, "000d") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 5 12 ; *maker = PI_MAKER_EGOMAN ; }
else if (strcmp (c, "000e") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 5 12 ; *maker = PI_MAKER_SONY ; }
else if (strcmp (c, "000f") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 5 12 ; *maker = PI_MAKER_EGOMAN ; }
else if (strcmp (c, "0010") == 0) { *model = PI_MODEL_BP ; *rev = PI_VERSION_1_2 ; *mem = 5 12 ; *maker = PI_MAKER_SONY ; }
else if (strcmp (c, "0011") == 0) { *model = PI_MODEL_CM ; *rev = PI_VERSION_1_2 ; *mem = 5 12 ; *maker = PI_MAKER_SONY ; }
else if (strcmp (c, "0012") == 0) { *model = PI_MODEL_AP ; *rev = PI_VERSION_1_2 ; *mem = 256 ; *maker = PI_MAKER_SONY ; }
else if (strcmp (c, "0013") == 0) { *model = PI_MODEL_BP ; *rev = PI_VERSION_1_2 ; *mem = 512 ; *maker = PI_MAKER_MBEST ; }
else if (strcmp (c, "0014") == 0) { *model = PI_MODEL_CM ; *rev = PI_VERSION_1_2 ; *mem = 5 12 ; *maker = PI_MAKER_SONY ; }
else if (strcmp (c, "0015") == 0) { *model = PI_MODEL_AP ; *rev = PI_VERSION_1_1 ; *mem = 256 ; *maker = PI_MAKER_SONY ; }
/**/ if (strcmp (c, "0002") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_1 ; *mem = 0 ; *maker = PI_MAKER_EGOMAN ; }
else if (strcmp (c, "0003") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_1_1 ; *mem = 0 ; *maker = PI_MAKER_EGOMAN ; }
else if (strcmp (c, "0004") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 0 ; *maker = PI_MAKER_SONY ; }
else if (strcmp (c, "0005") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 0 ; *maker = PI_MAKER_UNKNOWN ; }
else if (strcmp (c, "0006") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 0 ; *maker = PI_MAKER_EGOMAN ; }
else if (strcmp (c, "0007") == 0) { *model = PI_MODEL_A ; *rev = PI_VERSION_2 ; *mem = 0 ; *maker = PI_MAKER_EGOMAN ; }
else if (strcmp (c, "0008") == 0) { *model = PI_MODEL_A ; *rev = PI_VERSION_2 ; *mem = 0 ; *maker = PI_MAKER_SONY ; ; }
else if (strcmp (c, "0009") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 0 ; *maker = PI_MAKER_UNKNOWN ; }
else if (strcmp (c, "000d") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 1 ; *maker = PI_MAKER_EGOMAN ; }
else if (strcmp (c, "000e") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 1 ; *maker = PI_MAKER_SONY ; }
else if (strcmp (c, "000f") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 1 ; *maker = PI_MAKER_EGOMAN ; }
else if (strcmp (c, "0010") == 0) { *model = PI_MODEL_BP ; *rev = PI_VERSION_1_2 ; *mem = 1 ; *maker = PI_MAKER_SONY ; }
else if (strcmp (c, "0011") == 0) { *model = PI_MODEL_CM ; *rev = PI_VERSION_1_2 ; *mem = 1 ; *maker = PI_MAKER_SONY ; }
else if (strcmp (c, "0012") == 0) { *model = PI_MODEL_AP ; *rev = PI_VERSION_1_2 ; *mem = 0 ; *maker = PI_MAKER_SONY ; }
else if (strcmp (c, "0013") == 0) { *model = PI_MODEL_BP ; *rev = PI_VERSION_1_2 ; *mem = 1 ; *maker = PI_MAKER_EGOMAN ; }
else if (strcmp (c, "0014") == 0) { *model = PI_MODEL_CM ; *rev = PI_VERSION_1_2 ; *mem = 1 ; *maker = PI_MAKER_SONY ; }
else if (strcmp (c, "0015") == 0) { *model = PI_MODEL_AP ; *rev = PI_VERSION_1_1 ; *mem = 0 ; *maker = PI_MAKER_SONY ; }
else { *model = 0 ; *rev = 0 ; *mem = 0 ; *maker = 0 ; }
}
}