Date: Sun, 7 Jul 2013 21:23:58 +0000 (UTC) From: Rui Paulo <rpaulo@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r253006 - head/sys/arm/broadcom/bcm2835 Message-ID: <201307072123.r67LNwUb042958@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: rpaulo Date: Sun Jul 7 21:23:58 2013 New Revision: 253006 URL: http://svnweb.freebsd.org/changeset/base/253006 Log: Convert bcm2835_mbox to the new mbox interface. Reviewed by: gonzo Modified: head/sys/arm/broadcom/bcm2835/bcm2835_fb.c head/sys/arm/broadcom/bcm2835/bcm2835_mbox.c head/sys/arm/broadcom/bcm2835/bcm2835_mbox.h head/sys/arm/broadcom/bcm2835/files.bcm2835 Modified: head/sys/arm/broadcom/bcm2835/bcm2835_fb.c ============================================================================== --- head/sys/arm/broadcom/bcm2835/bcm2835_fb.c Sun Jul 7 21:20:52 2013 (r253005) +++ head/sys/arm/broadcom/bcm2835/bcm2835_fb.c Sun Jul 7 21:23:58 2013 (r253006) @@ -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); Modified: head/sys/arm/broadcom/bcm2835/bcm2835_mbox.c ============================================================================== --- head/sys/arm/broadcom/bcm2835/bcm2835_mbox.c Sun Jul 7 21:20:52 2013 (r253005) +++ head/sys/arm/broadcom/bcm2835/bcm2835_mbox.c Sun Jul 7 21:23:58 2013 (r253006) @@ -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,72 +174,76 @@ 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); } -static device_method_t bcm_mbox_methods[] = { - DEVMETHOD(device_probe, bcm_mbox_probe), - DEVMETHOD(device_attach, bcm_mbox_attach), - { 0, 0 } -}; - -static driver_t bcm_mbox_driver = { - "mbox", - bcm_mbox_methods, - sizeof(struct bcm_mbox_softc), -}; - -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) +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; + MBOX_LOCK(sc); - while ((mbox_read_4(REG_STATUS) & STATUS_FULL) && limit--) { + while ((mbox_read_4(sc, REG_STATUS) & STATUS_FULL) && limit--) { DELAY(2); } if (limit == 0) { printf("bcm_mbox_write: STATUS_FULL stuck"); - MBOX_UNLOCK; + MBOX_UNLOCK(sc); return (EAGAIN); } - mbox_write_4(REG_WRITE, MBOX_MSG(chan, data)); + mbox_write_4(sc, REG_WRITE, MBOX_MSG(chan, data)); - MBOX_UNLOCK; + MBOX_UNLOCK(sc); return (0); } -int -bcm_mbox_read(int chan, uint32_t *data) +static int +bcm_mbox_read(device_t dev, int chan, uint32_t *data) { - struct bcm_mbox_softc *sc = bcm_mbox_sc; + struct bcm_mbox_softc *sc = device_get_softc(dev); dprintf("bcm_mbox_read: chan %d\n", chan); - MBOX_LOCK; + MBOX_LOCK(sc); 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; + *data = sc->msg[chan]; + sc->valid[chan] = 0; + MBOX_UNLOCK(sc); dprintf("bcm_mbox_read: chan %d, data %08x\n", chan, *data); return (0); } + +static device_method_t bcm_mbox_methods[] = { + DEVMETHOD(device_probe, bcm_mbox_probe), + DEVMETHOD(device_attach, bcm_mbox_attach), + + DEVMETHOD(mbox_read, bcm_mbox_read), + DEVMETHOD(mbox_write, bcm_mbox_write), + + DEVMETHOD_END +}; + +static driver_t bcm_mbox_driver = { + "mbox", + bcm_mbox_methods, + sizeof(struct bcm_mbox_softc), +}; + +static devclass_t bcm_mbox_devclass; + +DRIVER_MODULE(mbox, simplebus, bcm_mbox_driver, bcm_mbox_devclass, 0, 0); + Modified: head/sys/arm/broadcom/bcm2835/bcm2835_mbox.h ============================================================================== --- head/sys/arm/broadcom/bcm2835/bcm2835_mbox.h Sun Jul 7 21:20:52 2013 (r253005) +++ head/sys/arm/broadcom/bcm2835/bcm2835_mbox.h Sun Jul 7 21:23:58 2013 (r253006) @@ -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_ */ Modified: head/sys/arm/broadcom/bcm2835/files.bcm2835 ============================================================================== --- head/sys/arm/broadcom/bcm2835/files.bcm2835 Sun Jul 7 21:20:52 2013 (r253005) +++ head/sys/arm/broadcom/bcm2835/files.bcm2835 Sun Jul 7 21:23:58 2013 (r253006) @@ -22,3 +22,5 @@ arm/arm/cpufunc_asm_armv6.S arm/arm/irq_dispatch.S standard kern/kern_clocksource.c standard + +dev/mbox/mbox_if.m standard
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201307072123.r67LNwUb042958>