diff options
Diffstat (limited to 'src/uart.c')
-rw-r--r-- | src/uart.c | 19 |
1 files changed, 5 insertions, 14 deletions
@@ -5,6 +5,7 @@ References: | |||
5 | #include <uart.h> | 5 | #include <uart.h> |
6 | 6 | ||
7 | #include <gpio.h> | 7 | #include <gpio.h> |
8 | #include <mailbox.h> | ||
8 | #include <mmio.h> | 9 | #include <mmio.h> |
9 | 10 | ||
10 | enum | 11 | enum |
@@ -31,15 +32,10 @@ enum | |||
31 | UART0_ITIP = (UART0_BASE + 0x84), | 32 | UART0_ITIP = (UART0_BASE + 0x84), |
32 | UART0_ITOP = (UART0_BASE + 0x88), | 33 | UART0_ITOP = (UART0_BASE + 0x88), |
33 | UART0_TDR = (UART0_BASE + 0x8C), | 34 | UART0_TDR = (UART0_BASE + 0x8C), |
34 | // The offsets for Mailbox registers. | ||
35 | MBOX_BASE = 0xB880, | ||
36 | MBOX_READ = (MBOX_BASE + 0x00), | ||
37 | MBOX_STATUS = (MBOX_BASE + 0x18), | ||
38 | MBOX_WRITE = (MBOX_BASE + 0x20) | ||
39 | }; | 35 | }; |
40 | 36 | ||
41 | // A mailbox message with set clock rate of PL011 to 3MHz tag. | 37 | // A mailbox message with set clock rate of PL011 to 3MHz tag. |
42 | static volatile unsigned int __attribute__((aligned(16))) mbox[9] = { | 38 | static const uint32_t __attribute__((aligned(MAIL_ALIGN))) UART_SET_CLK[9] = { |
43 | 9*4, 0, 0x38002, 12, 8, 2, 3000000, 0, 0 | 39 | 9*4, 0, 0x38002, 12, 8, 2, 3000000, 0, 0 |
44 | }; | 40 | }; |
45 | 41 | ||
@@ -77,14 +73,9 @@ void uart_init(int raspi) { | |||
77 | // For Raspi3 and 4 the UART_CLOCK is system-clock dependent by default. | 73 | // For Raspi3 and 4 the UART_CLOCK is system-clock dependent by default. |
78 | // Set it to 3Mhz so that we can consistently set the baud rate | 74 | // Set it to 3Mhz so that we can consistently set the baud rate |
79 | if (raspi >= 3) { | 75 | if (raspi >= 3) { |
80 | // UART_CLOCK = 30000000; | 76 | // Send message over property channel to configure UART clock. |
81 | unsigned int r = (unsigned int) (((uint64_t)(&mbox) & ~0xF) | 8); | 77 | mbox_write(PROPERTY_CHANNEL, UART_SET_CLK); |
82 | // Wait until we can talk to the VC. | 78 | mbox_read(PROPERTY_CHANNEL); |
83 | while (mmio_read(MBOX_STATUS) & 0x80000000); | ||
84 | // Send our message to property channel and wait for the response. | ||
85 | mmio_write(MBOX_WRITE, r); | ||
86 | while ((mmio_read(MBOX_STATUS) & 0x40000000) || | ||
87 | (mmio_read(MBOX_READ) != r)); | ||
88 | } | 79 | } |
89 | 80 | ||
90 | // Divider = 3000000 / (16 * 115200) = 1.627 = ~1. | 81 | // Divider = 3000000 / (16 * 115200) = 1.627 = ~1. |