aboutsummaryrefslogtreecommitdiffstats
path: root/src/common.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/common.h')
-rw-r--r--src/common.h105
1 files changed, 103 insertions, 2 deletions
diff --git a/src/common.h b/src/common.h
index a6af346..0bd365a 100644
--- a/src/common.h
+++ b/src/common.h
@@ -60,11 +60,9 @@ static inline void
60gpio_pin_set_func(u8 pin, GpioFunc func) { 60gpio_pin_set_func(u8 pin, GpioFunc func) {
61 u8 start = (pin * 3) % 30; 61 u8 start = (pin * 3) % 30;
62 u8 reg = pin / 10; 62 u8 reg = pin / 10;
63
64 u32 selector = GPIO->func_select[reg]; 63 u32 selector = GPIO->func_select[reg];
65 selector &= ~(7 << start); 64 selector &= ~(7 << start);
66 selector |= (func << start); 65 selector |= (func << start);
67
68 GPIO->func_select[reg] = selector; 66 GPIO->func_select[reg] = selector;
69} 67}
70 68
@@ -144,4 +142,107 @@ uart_puts(char *s) {
144 } 142 }
145} 143}
146 144
145static inline void
146uart_hex(unsigned int d) {
147 unsigned int n;
148 uart_puts("0x");
149 for(int c = 28; c >= 0; c -= 4) {
150 n = (d>>c) & 0xF;
151 n += n> 9 ? 0x37 : 0x30;
152 uart_putc(n);
153 }
154}
155
156//
157// VideoCore Mailboxes.
158//
159
160typedef struct MboxTagHeader {
161 u32 id;
162 u32 buf_size;
163 u32 code;
164} MboxTagHeader;
165
166typedef struct MboxScreenTag {
167 MboxTagHeader header;
168 u32 width;
169 u32 height;
170} MboxScreenTag;
171
172typedef struct MboxDepthTag {
173 MboxTagHeader header;
174 u32 depth;
175} MboxDepthTag;
176
177typedef struct MboxFramebufferTag {
178 MboxTagHeader header;
179 u32 fb_addr;
180 u32 fb_size;
181} MboxFramebufferTag;
182
183typedef struct MboxFramebufferRequest {
184 u32 buf_size;
185 u32 code;
186 MboxScreenTag screen_tag;
187 MboxScreenTag virtual_screen_tag;
188 MboxDepthTag depth_tag;
189 MboxFramebufferTag framebuffer_tag;
190 u32 end_tag;
191 u8 padding[8];
192} MboxFramebufferRequest;
193
194typedef struct MailboxRegs {
195 vu32 read;
196 vu32 reserved[5];
197 vu32 status;
198 vu32 config;
199 vu32 write;
200} MailboxRegs;
201
202#define MBOX ((MailboxRegs *)(MEM_BASE + 0x0000B880))
203
204typedef enum MboxChannels {
205 MBOX_CH_POWER = 0,
206 MBOX_CH_FB = 1,
207 MBOX_CH_VUART = 2,
208 MBOX_CH_VCHIQ = 3,
209 MBOX_CH_LEDS = 4,
210 MBOX_CH_BTNS = 5,
211 MBOX_CH_TOUCH = 6,
212 MBOX_CH_COUNT = 7,
213 MBOX_CH_PROP = 8,
214} MboxChannels;
215
216// Property channel response type.
217#define MBOX_REQUEST 0
218#define MBOX_RESPONSE_OK 0x80000000
219#define MBOX_RESPONSE_ERR 0x80000001
220
221// Mailbox status codes.
222#define MBOX_FULL 0x80000000
223#define MBOX_EMPTY 0x40000000
224
225static inline void
226mb_write(u8 channel, void *data) {
227 while(MBOX->status & MBOX_FULL);
228 MBOX->write = ((uintptr_t)data & ~0xF) | (channel & 0xF);
229}
230
231static inline u32
232mb_read(u8 channel) {
233 while(true) {
234 while(MBOX->status & MBOX_EMPTY);
235 u32 data = MBOX->read;
236 if ((u8)(data & 0xF) == channel) {
237 return data & 0xFFFFFFF0;
238 }
239 }
240}
241
242static inline int
243mb_call(unsigned char ch, void *msg) {
244 mb_write(ch, msg);
245 return mb_read(ch);
246}
247
147#endif // COMMON_RPIBM_H 248#endif // COMMON_RPIBM_H