Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for hwver 0xa01040, Pi 2 pre-release & device-tree auto-detection #104

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions rpihw.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@
#define RPI_MANUFACTURER_MASK (0xf << 16)
#define RPI_WARRANTY_MASK (0x3 << 24)

// Structure to store results of device-tree auto-detect
static rpi_hw_t board_info = {
.hwver = 0x00,
.type = 0x00,
.periph_base = 0x00,
.videocore_base = 0x00,
.desc = "N/A"
};

static const rpi_hw_t rpi_hw_info[] = {
//
// Model B Rev 1.0
Expand Down Expand Up @@ -171,6 +180,13 @@ static const rpi_hw_t rpi_hw_info[] = {
.videocore_base = VIDEOCORE_BASE_RPI,
.desc = "Compute Module",
},
{
.hwver = 0x14,
.type = RPI_HWVER_TYPE_PI1,
.periph_base = PERIPH_BASE_RPI,
.videocore_base = VIDEOCORE_BASE_RPI,
.desc = "Compute Module",
},

//
// Pi Zero
Expand Down Expand Up @@ -211,6 +227,13 @@ static const rpi_hw_t rpi_hw_info[] = {
//
// Pi 2 Model B
//
{
.hwver = 0xa01040,
.type = RPI_HWVER_TYPE_PI2,
.periph_base = PERIPH_BASE_RPI2,
.videocore_base = VIDEOCORE_BASE_RPI2,
.desc = "Pi 2",
},
{
.hwver = 0xa01041,
.type = RPI_HWVER_TYPE_PI2,
Expand Down Expand Up @@ -247,8 +270,54 @@ static const rpi_hw_t rpi_hw_info[] = {
};


static unsigned get_dt_ranges(const char *filename, unsigned offset)
{
unsigned address = ~0;
FILE *fp = fopen(filename, "rb");
if (fp)
{
unsigned char buf[4];
fseek(fp, offset, SEEK_SET);
if (fread(buf, 1, sizeof buf, fp) == sizeof buf)
address = buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3] << 0;
fclose(fp);
}
return address;
}


unsigned bcm_host_get_peripheral_address(void)
{
return get_dt_ranges("/proc/device-tree/soc/ranges", 4);
}


unsigned bcm_host_get_peripheral_size(void)
{
return get_dt_ranges("/proc/device-tree/soc/ranges", 8);
}


unsigned bcm_host_get_sdram_address(void)
{
return get_dt_ranges("/proc/device-tree/axi/vc_mem/reg", 8);
}

const rpi_hw_t *rpi_hw_detect(void)
{
// Attempt to auto-detect addresses from device-tree
unsigned videocore_base = bcm_host_get_sdram_address();
unsigned peripheral_base = bcm_host_get_peripheral_address();

if(videocore_base != ~0 && peripheral_base != ~0){

board_info.periph_base = peripheral_base;
board_info.videocore_base = videocore_base;

return &board_info;
}

// Fall back to old method
FILE *f = fopen("/proc/cpuinfo", "r");
char line[LINE_WIDTH_MAX];
const rpi_hw_t *result = NULL;
Expand Down