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 Raspberry Pi 4 #363

Merged
merged 6 commits into from
Jul 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 25 additions & 0 deletions rpihw.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

#define PERIPH_BASE_RPI 0x20000000
#define PERIPH_BASE_RPI2 0x3f000000
#define PERIPH_BASE_RPI4 0xfe000000

#define VIDEOCORE_BASE_RPI 0x40000000
#define VIDEOCORE_BASE_RPI2 0xc0000000
Expand All @@ -51,6 +52,30 @@
#define RPI_WARRANTY_MASK (0x3 << 24)

static const rpi_hw_t rpi_hw_info[] = {
//
// Raspberry Pi 4
//
{
.hwver = 0xA03111,
.type = RPI_HWVER_TYPE_PI4,
.periph_base = PERIPH_BASE_RPI4,
.videocore_base = VIDEOCORE_BASE_RPI2,
.desc = "Pi 4 Model B - 1GB"
},
{
.hwver = 0xB03111,
.type = RPI_HWVER_TYPE_PI4,
.periph_base = PERIPH_BASE_RPI4,
.videocore_base = VIDEOCORE_BASE_RPI2,
.desc = "Pi 4 Model B - 2GB"
},
{
.hwver = 0xC03111,
.type = RPI_HWVER_TYPE_PI4,
.periph_base = PERIPH_BASE_RPI4,
.videocore_base = VIDEOCORE_BASE_RPI2,
.desc = "Pi 4 Model B - 4GB"
},
//
// Model B Rev 1.0
//
Expand Down
1 change: 1 addition & 0 deletions rpihw.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ typedef struct {
#define RPI_HWVER_TYPE_UNKNOWN 0
#define RPI_HWVER_TYPE_PI1 1
#define RPI_HWVER_TYPE_PI2 2
#define RPI_HWVER_TYPE_PI4 3
uint32_t hwver;
uint32_t periph_base;
uint32_t videocore_base;
Expand Down
21 changes: 19 additions & 2 deletions ws2811.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#define BUS_TO_PHYS(x) ((x)&~0xC0000000)

#define OSC_FREQ 19200000 // crystal frequency
#define OSC_FREQ_PI4 54000000 // Pi 4 crystal frequency

/* 4 colors (R, G, B + W), 8 bits per byte, 3 symbols per bit + 55uS low for reset signal */
#define LED_COLOURS 4
Expand Down Expand Up @@ -347,10 +348,18 @@ static int setup_pwm(ws2811_t *ws2811)
uint32_t freq = ws2811->freq;
int32_t byte_count;

const rpi_hw_t *rpi_hw = ws2811->rpi_hw;
const uint32_t rpi_type = rpi_hw->type;
uint32_t osc_freq = OSC_FREQ;

if(rpi_type == RPI_HWVER_TYPE_PI4){
osc_freq = OSC_FREQ_PI4;
}

stop_pwm(ws2811);

// Setup the Clock - Use OSC @ 19.2Mhz w/ 3 clocks/tick
cm_clk->div = CM_CLK_DIV_PASSWD | CM_CLK_DIV_DIVI(OSC_FREQ / (3 * freq));
cm_clk->div = CM_CLK_DIV_PASSWD | CM_CLK_DIV_DIVI(osc_freq / (3 * freq));
cm_clk->ctl = CM_CLK_CTL_PASSWD | CM_CLK_CTL_SRC_OSC;
cm_clk->ctl = CM_CLK_CTL_PASSWD | CM_CLK_CTL_SRC_OSC | CM_CLK_CTL_ENAB;
usleep(10);
Expand Down Expand Up @@ -422,10 +431,18 @@ static int setup_pcm(ws2811_t *ws2811)
uint32_t freq = ws2811->freq;
int32_t byte_count;

const rpi_hw_t *rpi_hw = ws2811->rpi_hw;
const uint32_t rpi_type = rpi_hw->type;
uint32_t osc_freq = OSC_FREQ;

if(rpi_type == RPI_HWVER_TYPE_PI4){
osc_freq = OSC_FREQ_PI4;
}

stop_pcm(ws2811);

// Setup the PCM Clock - Use OSC @ 19.2Mhz w/ 3 clocks/tick
cm_clk->div = CM_CLK_DIV_PASSWD | CM_CLK_DIV_DIVI(OSC_FREQ / (3 * freq));
cm_clk->div = CM_CLK_DIV_PASSWD | CM_CLK_DIV_DIVI(osc_freq / (3 * freq));
cm_clk->ctl = CM_CLK_CTL_PASSWD | CM_CLK_CTL_SRC_OSC;
cm_clk->ctl = CM_CLK_CTL_PASSWD | CM_CLK_CTL_SRC_OSC | CM_CLK_CTL_ENAB;
usleep(10);
Expand Down