1 /* mailbox registers (MB 0: input 1: output)
2 * function | MB 0 | MB 1
3 * rd/wr | 00 | 20 ( upper 28: data, lower 4: channel )
9 * channel 1: framebuffer
12 * read: read status reg loop while empty flag is set
13 * write: read status loop while full flag is set
19 #define IOBASEADDR 0x20000000
21 #define IOBASEADDR 0x3f000000
24 #define phys2bus(addr) ((addr) | 0x40000000)
25 #define bus2phys(addr) ((addr) & 0x3fffffff)
27 #define IOREG_ADDR(x) (IOBASEADDR | (x))
28 #define REG_MB_READ *((volatile uint32_t*)IOREG_ADDR(0xb880))
29 #define REG_MB_STAT *((volatile uint32_t*)IOREG_ADDR(0xb898))
30 #define REG_MB_WRITE *((volatile uint32_t*)IOREG_ADDR(0xb8a0))
32 #define MB_STAT_FULL 0x80000000
33 #define MB_STAT_EMPTY 0x40000000
35 #define MB_CHAN_FRAMEBUF 1
36 #define MB_CHAN_PROP 8
38 #define PROP_CODE_REQ 0
39 #define PROP_RESP_OK 0x80000000
42 #define PROP_TAG_END 0
44 #define PROP_TAG_SET 0x08000
45 #define PROP_TAG_TEST 0x04000
46 #define PROP_TAG_GET 0
48 #define PROP_TAG_ALLOCBUF 0x40001
49 #define PROP_TAG_BLANKSCR 0x40002
50 #define PROP_TAG_PHYSRES 0x40003
51 #define PROP_TAG_VIRTRES 0x40004
52 #define PROP_TAG_DEPTH 0x40005
53 #define PROP_TAG_PIXEL_ORDER 0x40006
54 #define PROP_TAG_ALPHA_MODE 0x40007
55 #define PROP_TAG_PITCH 0x40008
56 #define PROP_TAG_VOFFS 0x40009
57 #define PROP_TAG_OVERSCAN 0x4000a
58 #define PROP_TAG_PALETTE 0x4000b
59 #define PROP_TAG_CUR_INFO 0x00010
60 #define PROP_TAG_CUR_STATE 0x00011
63 int prop_blankscr(int onoff);
64 int prop_setvres(int xsz, int ysz);
65 void *prop_allocbuf(void);
67 uint32_t mb_read(int chan);
68 void mb_write(int chan, uint32_t val);
75 prop_setvres(640, 480);
78 for(i=0; i<640 * 480; i++) {
79 *fb++ = (i & 0xff) | ((i & 0xff) << 8);
85 static uint32_t propbuf[64] __attribute__((aligned(16)));
87 static int send_prop(uint32_t *buf)
89 mb_write(MB_CHAN_PROP, (uint32_t)buf >> 4);
90 mb_read(MB_CHAN_PROP);
91 return propbuf[1] == PROP_RESP_OK ? 0 : -1;
94 int prop_blankscr(int onoff)
96 uint32_t *pb = propbuf;
100 *pb++ = PROP_TAG_BLANKSCR;
101 *pb++ = 4; /* data size */
102 *pb++ = PROP_CODE_REQ;
103 *pb++ = onoff ? 1 : 0;
104 *pb++ = PROP_TAG_END;
105 *pb++ = 0; /* padding */
106 propbuf[0] = (char*)pb - (char*)propbuf;
108 return send_prop(propbuf);
111 int prop_setvres(int xsz, int ysz)
113 uint32_t *pb = propbuf;
117 *pb++ = PROP_TAG_VIRTRES | PROP_TAG_SET;
118 *pb++ = 8; /* data size */
119 *pb++ = PROP_CODE_REQ;
122 *pb++ = PROP_TAG_END;
123 propbuf[0] = (char*)pb - (char*)propbuf;
125 return send_prop(propbuf);
128 void *prop_allocbuf(void)
130 uint32_t *pb = propbuf;
135 *pb++ = PROP_TAG_ALLOCBUF;
136 *pb++ = 8; /* data size */
137 *pb++ = PROP_CODE_REQ;
139 *pb++ = 16; /* alignment */
141 *pb++ = PROP_TAG_END;
142 propbuf[0] = (char*)pb - (char*)propbuf;
144 if(send_prop(propbuf) == -1) {
148 return (void*)bus2phys(*data);
151 uint32_t mb_read(int chan)
155 while(REG_MB_STAT & MB_STAT_EMPTY);
157 } while((val & 0xf) != chan);
161 void mb_write(int chan, uint32_t val)
163 while(REG_MB_STAT & MB_STAT_FULL);
164 REG_MB_WRITE = (val << 4) | chan;