rpi: use /proc/device-tree/compatible
While some distributions have a modified /proc/cpuinfo including the board revision for raspberry pi, most distributions don't have this. In order to guess the raspberry pi version in such cases, use the /proc/device-tree/compatible content as a fallback solution. The values expected from this file have been taken from upstream kernel documentation: Documentation/devicetree/bindings/arm/bcm/brcm,bcm2835.txt Signed-off-by: Cédric Bosdonnat <cbosdonnat@suse.com> Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
committed by
Brendan Le Foll
parent
b453f6633b
commit
b20fe9163a
@@ -87,6 +87,8 @@ mraa_arm_platform()
|
||||
platform_type = MRAA_96BOARDS;
|
||||
else if (mraa_file_contains("/proc/device-tree/model", "s900"))
|
||||
platform_type = MRAA_96BOARDS;
|
||||
else if (mraa_file_contains("/proc/device-tree/compatible", "raspberrypi,"))
|
||||
platform_type = MRAA_RASPBERRY_PI;
|
||||
}
|
||||
|
||||
switch (platform_type) {
|
||||
|
||||
@@ -219,10 +219,13 @@ mraa_raspberry_pi()
|
||||
size_t len = 100;
|
||||
char* line = calloc(len, sizeof(char));
|
||||
|
||||
mraa_boolean_t tweakedCpuinfo = 0;
|
||||
|
||||
FILE* fh = fopen("/proc/cpuinfo", "r");
|
||||
if (fh != NULL) {
|
||||
while (getline(&line, &len, fh) != -1) {
|
||||
if (strncmp(line, "Revision", 8) == 0) {
|
||||
tweakedCpuinfo = 1;
|
||||
if (strstr(line, "0002") || strstr(line, "0003")) {
|
||||
b->platform_name = PLATFORM_NAME_RASPBERRY_PI_B_REV_1;
|
||||
platform_detected = PLATFORM_RASPBERRY_PI_B_REV_1;
|
||||
@@ -267,6 +270,52 @@ mraa_raspberry_pi()
|
||||
}
|
||||
free(line);
|
||||
|
||||
// Some distros have a Revision line in /proc/cpuinfo for rpi.
|
||||
// As this may not be the case for all distros, we need to find
|
||||
// another way to guess the raspberry pi model.
|
||||
if (!tweakedCpuinfo) {
|
||||
// See Documentation/devicetree/bindings/arm/bcm/brcm,bcm2835.txt
|
||||
// for the values
|
||||
const char *compatible_path = "/proc/device-tree/compatible";
|
||||
if (mraa_file_contains(compatible_path, "raspberrypi,model-b")) {
|
||||
b->platform_name = PLATFORM_NAME_RASPBERRY_PI_B_REV_1;
|
||||
platform_detected = PLATFORM_RASPBERRY_PI_B_REV_1;
|
||||
b->phy_pin_count = MRAA_RASPBERRY_PI_B_REV_1_PINCOUNT;
|
||||
} else if (mraa_file_contains(compatible_path, "raspberrypi,model-b-rev2")) {
|
||||
b->platform_name = PLATFORM_NAME_RASPBERRY_PI_B_REV_2;
|
||||
platform_detected = PLATFORM_RASPBERRY_PI_B_REV_2;
|
||||
b->phy_pin_count = MRAA_RASPBERRY_PI_AB_REV_2_PINCOUNT;
|
||||
} else if (mraa_file_contains(compatible_path, "raspberrypi,model-zero")) {
|
||||
b->platform_name = PLATFORM_NAME_RASPBERRY_PI_ZERO;
|
||||
platform_detected = PLATFORM_RASPBERRY_PI_ZERO;
|
||||
b->phy_pin_count = MRAA_RASPBERRY_PI_ZERO_PINCOUNT;
|
||||
} else if (mraa_file_contains(compatible_path, "raspberrypi,model-a")) {
|
||||
b->platform_name = PLATFORM_NAME_RASPBERRY_PI_A_REV_2;
|
||||
platform_detected = PLATFORM_RASPBERRY_PI_A_REV_2;
|
||||
b->phy_pin_count = MRAA_RASPBERRY_PI_AB_REV_2_PINCOUNT;
|
||||
} else if (mraa_file_contains(compatible_path, "raspberrypi,model-b-plus")) {
|
||||
b->platform_name = PLATFORM_NAME_RASPBERRY_PI_B_PLUS_REV_1;
|
||||
platform_detected = PLATFORM_RASPBERRY_PI_B_PLUS_REV_1;
|
||||
b->phy_pin_count = MRAA_RASPBERRY_PI_AB_PLUS_PINCOUNT;
|
||||
} else if (mraa_file_contains(compatible_path, "raspberrypi,compute-module")) {
|
||||
b->platform_name = PLATFORM_NAME_RASPBERRY_PI_COMPUTE_MODULE_REV_1;
|
||||
platform_detected = PLATFORM_RASPBERRY_PI_COMPUTE_MODULE_REV_1;
|
||||
b->phy_pin_count = MRAA_RASPBERRY_PI_COMPUTE_MODULE_PINCOUNT;
|
||||
} else if (mraa_file_contains(compatible_path, "raspberrypi,model-a-plus")) {
|
||||
b->platform_name = PLATFORM_NAME_RASPBERRY_PI_A_PLUS_REV_1;
|
||||
platform_detected = PLATFORM_RASPBERRY_PI_A_PLUS_REV_1;
|
||||
b->phy_pin_count = MRAA_RASPBERRY_PI_AB_PLUS_PINCOUNT;
|
||||
} else if (mraa_file_contains(compatible_path, "raspberrypi,2-model-b")) {
|
||||
b->platform_name = PLATFORM_NAME_RASPBERRY_PI2_B_REV_1;
|
||||
platform_detected = PLATFORM_RASPBERRY_PI2_B_REV_1;
|
||||
b->phy_pin_count = MRAA_RASPBERRY_PI2_B_REV_1_PINCOUNT;
|
||||
} else if (mraa_file_contains(compatible_path, "raspberrypi,model-b")) {
|
||||
b->platform_name = PLATFORM_NAME_RASPBERRY_PI_B_REV_1;
|
||||
platform_detected = PLATFORM_RASPBERRY_PI_B_REV_1;
|
||||
b->phy_pin_count = MRAA_RASPBERRY_PI_B_REV_1_PINCOUNT;
|
||||
}
|
||||
}
|
||||
|
||||
b->aio_count = 0;
|
||||
b->adc_raw = 0;
|
||||
b->adc_supported = 0;
|
||||
|
||||
Reference in New Issue
Block a user