Ignore:
Timestamp:
2013-04-04T21:01:11Z (12 years ago)
Author:
Beniamino Galvani <b.galvani@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
44186b01
Parents:
409a996
Message:

Raspberry Pi: add framebuffer initialization

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/genarch/src/drivers/bcm2835/mbox.c

    r409a996 rf22f679  
    3434 */
    3535
     36#include <mm/km.h>
     37#include <mm/slab.h>
    3638#include <typedefs.h>
    3739#include <genarch/drivers/bcm2835/mbox.h>
     
    3941static void mbox_write(bcm2835_mbox_t *mbox, uint8_t chan, uint32_t value)
    4042{
    41         if (!mbox)
    42                 mbox = (bcm2835_mbox_t *)BCM2835_MBOX0_ADDR;
    43 
    4443        while (mbox->status & MBOX_STATUS_FULL) ;
    4544        mbox->write = MBOX_COMPOSE(chan, value);
     
    4948{
    5049        uint32_t msg;
    51 
    52         if (!mbox)
    53                 mbox = (bcm2835_mbox_t *)BCM2835_MBOX0_ADDR;
    5450
    5551        do {
     
    7369        req->zero = 0;
    7470
    75         mbox_write(NULL, MBOX_CHAN_PROP_A2V, KA2VC((uint32_t)req));
    76         mbox_read(NULL, MBOX_CHAN_PROP_A2V);
     71        mbox_write((bcm2835_mbox_t *)BCM2835_MBOX0_ADDR,
     72                   MBOX_CHAN_PROP_A2V, KA2VCA((uint32_t)req));
     73        mbox_read((bcm2835_mbox_t *)BCM2835_MBOX0_ADDR,
     74                  MBOX_CHAN_PROP_A2V);
    7775
    7876        if (req->buf_hdr.code == MBOX_PROP_CODE_RESP_OK) {
     
    8785}
    8886
     87bool bcm2835_fb_init(fb_properties_t *prop)
     88{
     89        bcm2835_mbox_t *fb_mbox;
     90        bcm2835_fb_desc_t *fb_desc;
     91        void *fb_desc_buf;
     92        bool ret = false;
     93
     94        fb_desc_buf = malloc(sizeof(bcm2835_fb_desc_t) + MBOX_ADDR_ALIGN, 0);
     95        if (!fb_desc_buf)
     96                return false;
     97
     98        fb_mbox = (void *) km_map(BCM2835_MBOX0_ADDR, sizeof(bcm2835_mbox_t),
     99                                  PAGE_NOT_CACHEABLE);
     100        fb_desc = (bcm2835_fb_desc_t *) ALIGN_UP((uintptr_t)fb_desc_buf,
     101                                                 MBOX_ADDR_ALIGN);
     102
     103        fb_desc->width = 640;
     104        fb_desc->height = 480;
     105        fb_desc->virt_width = fb_desc->width;
     106        fb_desc->virt_height = fb_desc->height;
     107        fb_desc->pitch = 0;                     /* Set by VC */
     108        fb_desc->bpp = 16;
     109        fb_desc->x_offset = 0;
     110        fb_desc->y_offset = 0;
     111        fb_desc->addr = 0;                      /* Set by VC */
     112        fb_desc->size = 0;                      /* Set by VC */
     113
     114        mbox_write(fb_mbox, MBOX_CHAN_FB, KA2VCA(fb_desc));
     115
     116        if (mbox_read(fb_mbox, MBOX_CHAN_FB)) {
     117                printf("BCM2835 framebuffer initialization failed\n");
     118                goto out;
     119        }
     120
     121        prop->addr = fb_desc->addr;
     122        prop->offset = 0;
     123        prop->x = fb_desc->width;
     124        prop->y = fb_desc->height;
     125        prop->scan = fb_desc->pitch;
     126        prop->visual = VISUAL_RGB_5_6_5_LE;
     127
     128        printf("BCM2835 framebuffer at 0x%08x (%dx%d)\n", prop->addr,
     129               prop->x, prop->y);
     130        ret = true;
     131out:
     132        km_unmap((uintptr_t)fb_mbox, sizeof(bcm2835_mbox_t));
     133        free(fb_desc_buf);
     134        return ret;
     135}
     136
    89137/**
    90138 * @}
Note: See TracChangeset for help on using the changeset viewer.