allow for a single board specific device to attach to the mbox driver
This commit is contained in:
parent
d26d978fbd
commit
e27de4fba2
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: bcm2835_mbox.c,v 1.2 2012/08/22 13:19:47 jakllsch Exp $ */
|
||||
/* $NetBSD: bcm2835_mbox.c,v 1.3 2013/01/07 20:15:32 jmcneill Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2012 The NetBSD Foundation, Inc.
|
||||
@ -30,7 +30,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: bcm2835_mbox.c,v 1.2 2012/08/22 13:19:47 jakllsch Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: bcm2835_mbox.c,v 1.3 2013/01/07 20:15:32 jmcneill Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
@ -46,9 +46,11 @@ __KERNEL_RCSID(0, "$NetBSD: bcm2835_mbox.c,v 1.2 2012/08/22 13:19:47 jakllsch Ex
|
||||
|
||||
struct bcm2835mbox_softc {
|
||||
device_t sc_dev;
|
||||
device_t sc_platdev;
|
||||
|
||||
bus_space_tag_t sc_iot;
|
||||
bus_space_handle_t sc_ioh;
|
||||
bus_dma_tag_t sc_dmat;
|
||||
};
|
||||
|
||||
static struct bcm2835mbox_softc *bcm2835mbox_sc;
|
||||
@ -76,6 +78,7 @@ bcmmbox_attach(device_t parent, device_t self, void *aux)
|
||||
{
|
||||
struct bcm2835mbox_softc *sc = device_private(self);
|
||||
struct amba_attach_args *aaa = aux;
|
||||
struct bcmmbox_attach_args baa;
|
||||
|
||||
aprint_naive("\n");
|
||||
aprint_normal(": VC mailbox\n");
|
||||
@ -85,12 +88,16 @@ bcmmbox_attach(device_t parent, device_t self, void *aux)
|
||||
|
||||
sc->sc_dev = self;
|
||||
sc->sc_iot = aaa->aaa_iot;
|
||||
sc->sc_dmat = aaa->aaa_dmat;
|
||||
|
||||
if (bus_space_map(aaa->aaa_iot, aaa->aaa_addr, BCM2835_MBOX_SIZE, 0,
|
||||
&sc->sc_ioh)) {
|
||||
aprint_error_dev(sc->sc_dev, "unable to map device\n");
|
||||
return;
|
||||
}
|
||||
|
||||
baa.baa_dmat = aaa->aaa_dmat;
|
||||
sc->sc_platdev = config_found_ia(self, "bcmmboxbus", &baa, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
@ -112,3 +119,52 @@ bcmmbox_write(uint8_t chan, uint32_t data)
|
||||
|
||||
return bcm2835_mbox_write(sc->sc_iot, sc->sc_ioh, chan, data);
|
||||
}
|
||||
|
||||
int
|
||||
bcmmbox_request(uint8_t chan, void *buf, size_t buflen, uint32_t *pres)
|
||||
{
|
||||
struct bcm2835mbox_softc *sc = bcm2835mbox_sc;
|
||||
void *dma_buf;
|
||||
bus_dmamap_t map;
|
||||
bus_dma_segment_t segs[1];
|
||||
int nsegs;
|
||||
int error;
|
||||
|
||||
KASSERT(sc != NULL);
|
||||
|
||||
error = bus_dmamem_alloc(sc->sc_dmat, buflen, 16, 0, segs, 1,
|
||||
&nsegs, BUS_DMA_WAITOK);
|
||||
if (error)
|
||||
return error;
|
||||
error = bus_dmamem_map(sc->sc_dmat, segs, nsegs, buflen, &dma_buf,
|
||||
BUS_DMA_WAITOK);
|
||||
if (error)
|
||||
goto map_failed;
|
||||
error = bus_dmamap_create(sc->sc_dmat, buflen, 1, buflen, 0,
|
||||
BUS_DMA_WAITOK, &map);
|
||||
if (error)
|
||||
goto create_failed;
|
||||
error = bus_dmamap_load(sc->sc_dmat, map, dma_buf, buflen, NULL,
|
||||
BUS_DMA_WAITOK);
|
||||
if (error)
|
||||
goto load_failed;
|
||||
|
||||
memcpy(dma_buf, buf, buflen);
|
||||
|
||||
bus_dmamap_sync(sc->sc_dmat, map, 0, buflen, BUS_DMASYNC_PREWRITE);
|
||||
bcmmbox_write(chan, map->dm_segs[0].ds_addr);
|
||||
bus_dmamap_sync(sc->sc_dmat, map, 0, buflen, BUS_DMASYNC_POSTWRITE);
|
||||
bus_dmamap_sync(sc->sc_dmat, map, 0, buflen, BUS_DMASYNC_PREREAD);
|
||||
bcmmbox_read(chan, pres);
|
||||
|
||||
memcpy(buf, dma_buf, buflen);
|
||||
|
||||
bus_dmamap_unload(sc->sc_dmat, map);
|
||||
load_failed:
|
||||
bus_dmamap_destroy(sc->sc_dmat, map);
|
||||
create_failed:
|
||||
bus_dmamem_unmap(sc->sc_dmat, dma_buf, buflen);
|
||||
map_failed:
|
||||
bus_dmamem_free(sc->sc_dmat, segs, nsegs);
|
||||
return error;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: bcm2835_mbox.h,v 1.3 2012/10/13 08:42:50 skrll Exp $ */
|
||||
/* $NetBSD: bcm2835_mbox.h,v 1.4 2013/01/07 20:15:32 jmcneill Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2012 The NetBSD Foundation, Inc.
|
||||
@ -42,4 +42,10 @@ void bcm2835_mbox_write(bus_space_tag_t, bus_space_handle_t, uint8_t,
|
||||
void bcmmbox_read(uint8_t, uint32_t *);
|
||||
void bcmmbox_write(uint8_t, uint32_t);
|
||||
|
||||
int bcmmbox_request(uint8_t, void *, size_t, uint32_t *);
|
||||
|
||||
struct bcmmbox_attach_args {
|
||||
bus_dma_tag_t baa_dmat;
|
||||
};
|
||||
|
||||
#endif /* _BCM2835_MBOX_H_ */
|
||||
|
@ -1,10 +1,12 @@
|
||||
# $NetBSD: files.bcm2835,v 1.8 2013/01/05 20:31:23 jakllsch Exp $
|
||||
# $NetBSD: files.bcm2835,v 1.9 2013/01/07 20:15:32 jmcneill Exp $
|
||||
#
|
||||
# Configuration info for Broadcom BCM2835 ARM Peripherals
|
||||
#
|
||||
|
||||
include "arch/arm/pic/files.pic"
|
||||
|
||||
define bcmmboxbus { }
|
||||
|
||||
file arch/arm/arm32/irq_dispatch.S
|
||||
file arch/arm/broadcom/bcm2835_dma.c
|
||||
file arch/arm/broadcom/bcm2835_mbox_subr.c
|
||||
@ -26,7 +28,7 @@ attach bcmicu at obio with bcmicu
|
||||
file arch/arm/broadcom/bcm2835_intr.c bcmicu
|
||||
|
||||
# VC Mailbox (BCM2835_ARMMBOX_BASE)
|
||||
device bcmmbox
|
||||
device bcmmbox: bcmmboxbus
|
||||
attach bcmmbox at obio with bcmmbox
|
||||
file arch/arm/broadcom/bcm2835_mbox.c bcmmbox
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user