Convert bcm2835_mbox to the new mbox interface.
Reviewed by: gonzo
This commit is contained in:
parent
8c78ddbaa3
commit
279cd1010a
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=253006
@ -66,6 +66,8 @@ __FBSDID("$FreeBSD$");
|
||||
#include <arm/broadcom/bcm2835/bcm2835_mbox.h>
|
||||
#include <arm/broadcom/bcm2835/bcm2835_vcbus.h>
|
||||
|
||||
#include "mbox_if.h"
|
||||
|
||||
#define BCMFB_FONT_HEIGHT 16
|
||||
|
||||
struct argb {
|
||||
@ -173,6 +175,7 @@ bcm_fb_init(void *arg)
|
||||
volatile struct bcm_fb_config* fb_config = sc->fb_config;
|
||||
phandle_t node;
|
||||
pcell_t cell;
|
||||
device_t mbox;
|
||||
|
||||
node = ofw_bus_get_node(sc->dev);
|
||||
|
||||
@ -205,8 +208,12 @@ bcm_fb_init(void *arg)
|
||||
|
||||
bus_dmamap_sync(sc->dma_tag, sc->dma_map,
|
||||
BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
|
||||
bcm_mbox_write(BCM2835_MBOX_CHAN_FB, sc->fb_config_phys);
|
||||
bcm_mbox_read(BCM2835_MBOX_CHAN_FB, &err);
|
||||
|
||||
mbox = devclass_get_device(devclass_find("mbox"), 0);
|
||||
if (mbox) {
|
||||
MBOX_WRITE(mbox, BCM2835_MBOX_CHAN_FB, sc->fb_config_phys);
|
||||
MBOX_READ(mbox, BCM2835_MBOX_CHAN_FB, &err);
|
||||
}
|
||||
bus_dmamap_sync(sc->dma_tag, sc->dma_map,
|
||||
BUS_DMASYNC_POSTREAD);
|
||||
|
||||
|
@ -49,8 +49,11 @@ __FBSDID("$FreeBSD$");
|
||||
|
||||
#include <machine/bus.h>
|
||||
#include <machine/fdt.h>
|
||||
|
||||
#include <arm/broadcom/bcm2835/bcm2835_mbox.h>
|
||||
|
||||
#include "mbox_if.h"
|
||||
|
||||
#define REG_READ 0x00
|
||||
#define REG_POL 0x10
|
||||
#define REG_SENDER 0x14
|
||||
@ -65,12 +68,12 @@ __FBSDID("$FreeBSD$");
|
||||
#define MBOX_CHAN(msg) ((msg) & 0xf)
|
||||
#define MBOX_DATA(msg) ((msg) & ~0xf)
|
||||
|
||||
#define MBOX_LOCK do { \
|
||||
mtx_lock(&bcm_mbox_sc->lock); \
|
||||
#define MBOX_LOCK(sc) do { \
|
||||
mtx_lock(&(sc)->lock); \
|
||||
} while(0)
|
||||
|
||||
#define MBOX_UNLOCK do { \
|
||||
mtx_unlock(&bcm_mbox_sc->lock); \
|
||||
#define MBOX_UNLOCK(sc) do { \
|
||||
mtx_unlock(&(sc)->lock); \
|
||||
} while(0)
|
||||
|
||||
#ifdef DEBUG
|
||||
@ -90,12 +93,10 @@ struct bcm_mbox_softc {
|
||||
int msg[BCM2835_MBOX_CHANS];
|
||||
};
|
||||
|
||||
static struct bcm_mbox_softc *bcm_mbox_sc = NULL;
|
||||
|
||||
#define mbox_read_4(reg) \
|
||||
bus_space_read_4(bcm_mbox_sc->bst, bcm_mbox_sc->bsh, reg)
|
||||
#define mbox_write_4(reg, val) \
|
||||
bus_space_write_4(bcm_mbox_sc->bst, bcm_mbox_sc->bsh, reg, val)
|
||||
#define mbox_read_4(sc, reg) \
|
||||
bus_space_read_4((sc)->bst, (sc)->bsh, reg)
|
||||
#define mbox_write_4(sc, reg, val) \
|
||||
bus_space_write_4((sc)->bst, (sc)->bsh, reg, val)
|
||||
|
||||
static void
|
||||
bcm_mbox_intr(void *arg)
|
||||
@ -105,9 +106,9 @@ bcm_mbox_intr(void *arg)
|
||||
uint32_t data;
|
||||
uint32_t msg;
|
||||
|
||||
MBOX_LOCK;
|
||||
while (!(mbox_read_4(REG_STATUS) & STATUS_EMPTY)) {
|
||||
msg = mbox_read_4(REG_READ);
|
||||
MBOX_LOCK(sc);
|
||||
while (!(mbox_read_4(sc, REG_STATUS) & STATUS_EMPTY)) {
|
||||
msg = mbox_read_4(sc, REG_READ);
|
||||
dprintf("bcm_mbox_intr: raw data %08x\n", msg);
|
||||
chan = MBOX_CHAN(msg);
|
||||
data = MBOX_DATA(msg);
|
||||
@ -121,7 +122,7 @@ bcm_mbox_intr(void *arg)
|
||||
wakeup(&sc->msg[chan]);
|
||||
|
||||
}
|
||||
MBOX_UNLOCK;
|
||||
MBOX_UNLOCK(sc);
|
||||
}
|
||||
|
||||
static int
|
||||
@ -143,9 +144,6 @@ bcm_mbox_attach(device_t dev)
|
||||
int i;
|
||||
int rid = 0;
|
||||
|
||||
if (bcm_mbox_sc != NULL)
|
||||
return (EINVAL);
|
||||
|
||||
sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
|
||||
if (sc->mem_res == NULL) {
|
||||
device_printf(dev, "could not allocate memory resource\n");
|
||||
@ -176,12 +174,55 @@ bcm_mbox_attach(device_t dev)
|
||||
sc->msg[0] = 0;
|
||||
}
|
||||
|
||||
bcm_mbox_sc = sc;
|
||||
/* Read all pending messages */
|
||||
bcm_mbox_intr(sc);
|
||||
|
||||
/* Should be called after bcm_mbox_sc initialization */
|
||||
mbox_write_4(REG_CONFIG, CONFIG_DATA_IRQ);
|
||||
mbox_write_4(sc, REG_CONFIG, CONFIG_DATA_IRQ);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Mailbox API
|
||||
*/
|
||||
static int
|
||||
bcm_mbox_write(device_t dev, int chan, uint32_t data)
|
||||
{
|
||||
int limit = 20000;
|
||||
struct bcm_mbox_softc *sc = device_get_softc(dev);
|
||||
|
||||
dprintf("bcm_mbox_write: chan %d, data %08x\n", chan, data);
|
||||
MBOX_LOCK(sc);
|
||||
|
||||
while ((mbox_read_4(sc, REG_STATUS) & STATUS_FULL) && limit--) {
|
||||
DELAY(2);
|
||||
}
|
||||
|
||||
if (limit == 0) {
|
||||
printf("bcm_mbox_write: STATUS_FULL stuck");
|
||||
MBOX_UNLOCK(sc);
|
||||
return (EAGAIN);
|
||||
}
|
||||
|
||||
mbox_write_4(sc, REG_WRITE, MBOX_MSG(chan, data));
|
||||
|
||||
MBOX_UNLOCK(sc);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
bcm_mbox_read(device_t dev, int chan, uint32_t *data)
|
||||
{
|
||||
struct bcm_mbox_softc *sc = device_get_softc(dev);
|
||||
|
||||
dprintf("bcm_mbox_read: chan %d\n", chan);
|
||||
MBOX_LOCK(sc);
|
||||
while (!sc->valid[chan])
|
||||
msleep(&sc->msg[chan], &sc->lock, PZERO, "vcio mbox read", 0);
|
||||
*data = sc->msg[chan];
|
||||
sc->valid[chan] = 0;
|
||||
MBOX_UNLOCK(sc);
|
||||
dprintf("bcm_mbox_read: chan %d, data %08x\n", chan, *data);
|
||||
|
||||
return (0);
|
||||
}
|
||||
@ -189,7 +230,11 @@ bcm_mbox_attach(device_t dev)
|
||||
static device_method_t bcm_mbox_methods[] = {
|
||||
DEVMETHOD(device_probe, bcm_mbox_probe),
|
||||
DEVMETHOD(device_attach, bcm_mbox_attach),
|
||||
{ 0, 0 }
|
||||
|
||||
DEVMETHOD(mbox_read, bcm_mbox_read),
|
||||
DEVMETHOD(mbox_write, bcm_mbox_write),
|
||||
|
||||
DEVMETHOD_END
|
||||
};
|
||||
|
||||
static driver_t bcm_mbox_driver = {
|
||||
@ -202,46 +247,3 @@ static devclass_t bcm_mbox_devclass;
|
||||
|
||||
DRIVER_MODULE(mbox, simplebus, bcm_mbox_driver, bcm_mbox_devclass, 0, 0);
|
||||
|
||||
/*
|
||||
* Mailbox API
|
||||
*/
|
||||
int
|
||||
bcm_mbox_write(int chan, uint32_t data)
|
||||
{
|
||||
int limit = 20000;
|
||||
|
||||
dprintf("bcm_mbox_write: chan %d, data %08x\n", chan, data);
|
||||
MBOX_LOCK;
|
||||
|
||||
while ((mbox_read_4(REG_STATUS) & STATUS_FULL) && limit--) {
|
||||
DELAY(2);
|
||||
}
|
||||
|
||||
if (limit == 0) {
|
||||
printf("bcm_mbox_write: STATUS_FULL stuck");
|
||||
MBOX_UNLOCK;
|
||||
return (EAGAIN);
|
||||
}
|
||||
|
||||
mbox_write_4(REG_WRITE, MBOX_MSG(chan, data));
|
||||
|
||||
MBOX_UNLOCK;
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
bcm_mbox_read(int chan, uint32_t *data)
|
||||
{
|
||||
struct bcm_mbox_softc *sc = bcm_mbox_sc;
|
||||
|
||||
dprintf("bcm_mbox_read: chan %d\n", chan);
|
||||
MBOX_LOCK;
|
||||
while (!sc->valid[chan])
|
||||
msleep(&sc->msg[chan], &sc->lock, PZERO, "vcio mbox read", 0);
|
||||
*data = bcm_mbox_sc->msg[chan];
|
||||
bcm_mbox_sc->valid[chan] = 0;
|
||||
MBOX_UNLOCK;
|
||||
dprintf("bcm_mbox_read: chan %d, data %08x\n", chan, *data);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
@ -38,7 +38,4 @@
|
||||
#define BCM2835_MBOX_CHAN_TS 6
|
||||
#define BCM2835_MBOX_CHANS 7
|
||||
|
||||
int bcm_mbox_write(int chan, uint32_t data);
|
||||
int bcm_mbox_read(int chan, uint32_t *data);
|
||||
|
||||
#endif /* _BCM2835_MBOX_H_ */
|
||||
|
@ -22,3 +22,5 @@ arm/arm/cpufunc_asm_armv6.S standard
|
||||
arm/arm/irq_dispatch.S standard
|
||||
|
||||
kern/kern_clocksource.c standard
|
||||
|
||||
dev/mbox/mbox_if.m standard
|
||||
|
Loading…
Reference in New Issue
Block a user