0

I need to do some changes in my audio card driver on the raspberry pi board.

What I need to do is: I have to check which model board it is and then I have to program the GPIO's based on the revision number that I get.

Can anyone suggest me how to do?

Morgan Courbet
  • 3,703
  • 3
  • 22
  • 38
optimus prime
  • 171
  • 1
  • 10

1 Answers1

2

I use the following code to extract the board revision.

unsigned gpioHardwareRevision(void)
{
   static unsigned rev = 0;

   FILE * filp;
   char buf[512];
   char term;

   if (rev) return rev;

   filp = fopen ("/proc/cpuinfo", "r");

   if (filp != NULL)
   {
      while (fgets(buf, sizeof(buf), filp) != NULL)
      {
         if (!strncasecmp("revision\t", buf, 9))
         {
            if (sscanf(buf+strlen(buf)-5, "%x%c", &rev, &term) == 2)
            {
               if (term == '\n') break;
               rev = 0;
            }
         }
      }
      fclose(filp);
   }
   return rev;
}

See http://elinux.org/RPi_HardwareHistory for the meaning of the returned numbers.

There are three different pinouts according to the revision.

If Revision < 4
   pinout type 1
else if Revision < 16
   pinout type 2
else
   pinout type 3

          0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15
Type.1    X  X  -  -  X  -  -  X  X  X  X  X  -  -  X  X
Type.2    -  -  X  X  X  -  -  X  X  X  X  X  -  -  X  X
Type.3          X  X  X  X  X  X  X  X  X  X  X  X  X  X

         16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
Type.1    -  X  X  -  -  X  X  X  X  X  -  -  -  -  -  -
Type.2    -  X  X  -  -  -  X  X  X  X  -  X  X  X  X  X
Type.3    X  X  X  X  X  X  X  X  X  X  X  X  -  -  -  -
joan
  • 71,024
  • 5
  • 73
  • 106