Home | History | Annotate | Line # | Download | only in broadcom
bcm2835_mbox.c revision 1.2.4.2
      1  1.2.4.2  yamt /*	$NetBSD: bcm2835_mbox.c,v 1.2.4.2 2012/10/30 17:18:59 yamt Exp $	*/
      2  1.2.4.2  yamt 
      3  1.2.4.2  yamt /*-
      4  1.2.4.2  yamt  * Copyright (c) 2012 The NetBSD Foundation, Inc.
      5  1.2.4.2  yamt  * All rights reserved.
      6  1.2.4.2  yamt  *
      7  1.2.4.2  yamt  * This code is derived from software contributed to The NetBSD Foundation
      8  1.2.4.2  yamt  * by Nick Hudson
      9  1.2.4.2  yamt  *
     10  1.2.4.2  yamt  * Redistribution and use in source and binary forms, with or without
     11  1.2.4.2  yamt  * modification, are permitted provided that the following conditions
     12  1.2.4.2  yamt  * are met:
     13  1.2.4.2  yamt  * 1. Redistributions of source code must retain the above copyright
     14  1.2.4.2  yamt  *    notice, this list of conditions and the following disclaimer.
     15  1.2.4.2  yamt  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.2.4.2  yamt  *    notice, this list of conditions and the following disclaimer in the
     17  1.2.4.2  yamt  *    documentation and/or other materials provided with the distribution.
     18  1.2.4.2  yamt  *
     19  1.2.4.2  yamt  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.2.4.2  yamt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.2.4.2  yamt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.2.4.2  yamt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.2.4.2  yamt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.2.4.2  yamt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.2.4.2  yamt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.2.4.2  yamt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.2.4.2  yamt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.2.4.2  yamt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.2.4.2  yamt  * POSSIBILITY OF SUCH DAMAGE.
     30  1.2.4.2  yamt  */
     31  1.2.4.2  yamt 
     32  1.2.4.2  yamt #include <sys/cdefs.h>
     33  1.2.4.2  yamt __KERNEL_RCSID(0, "$NetBSD: bcm2835_mbox.c,v 1.2.4.2 2012/10/30 17:18:59 yamt Exp $");
     34  1.2.4.2  yamt 
     35  1.2.4.2  yamt #include <sys/param.h>
     36  1.2.4.2  yamt #include <sys/systm.h>
     37  1.2.4.2  yamt #include <sys/device.h>
     38  1.2.4.2  yamt #include <sys/kernel.h>
     39  1.2.4.2  yamt #include <sys/timetc.h>
     40  1.2.4.2  yamt #include <sys/bus.h>
     41  1.2.4.2  yamt 
     42  1.2.4.2  yamt #include <arm/broadcom/bcm_amba.h>
     43  1.2.4.2  yamt #include <arm/broadcom/bcm2835_mbox.h>
     44  1.2.4.2  yamt #include <arm/broadcom/bcm2835_mboxreg.h>
     45  1.2.4.2  yamt #include <arm/broadcom/bcm2835reg.h>
     46  1.2.4.2  yamt 
     47  1.2.4.2  yamt struct bcm2835mbox_softc {
     48  1.2.4.2  yamt 	device_t sc_dev;
     49  1.2.4.2  yamt 
     50  1.2.4.2  yamt 	bus_space_tag_t sc_iot;
     51  1.2.4.2  yamt 	bus_space_handle_t sc_ioh;
     52  1.2.4.2  yamt };
     53  1.2.4.2  yamt 
     54  1.2.4.2  yamt static struct bcm2835mbox_softc *bcm2835mbox_sc;
     55  1.2.4.2  yamt 
     56  1.2.4.2  yamt static int bcmmbox_match(device_t, cfdata_t, void *);
     57  1.2.4.2  yamt static void bcmmbox_attach(device_t, device_t, void *);
     58  1.2.4.2  yamt 
     59  1.2.4.2  yamt CFATTACH_DECL_NEW(bcmmbox, sizeof(struct bcm2835mbox_softc),
     60  1.2.4.2  yamt     bcmmbox_match, bcmmbox_attach, NULL, NULL);
     61  1.2.4.2  yamt 
     62  1.2.4.2  yamt /* ARGSUSED */
     63  1.2.4.2  yamt static int
     64  1.2.4.2  yamt bcmmbox_match(device_t parent, cfdata_t match, void *aux)
     65  1.2.4.2  yamt {
     66  1.2.4.2  yamt 	struct amba_attach_args *aaa = aux;
     67  1.2.4.2  yamt 
     68  1.2.4.2  yamt 	if (strcmp(aaa->aaa_name, "bcmmbox") != 0)
     69  1.2.4.2  yamt 		return 0;
     70  1.2.4.2  yamt 
     71  1.2.4.2  yamt 	return 1;
     72  1.2.4.2  yamt }
     73  1.2.4.2  yamt 
     74  1.2.4.2  yamt static void
     75  1.2.4.2  yamt bcmmbox_attach(device_t parent, device_t self, void *aux)
     76  1.2.4.2  yamt {
     77  1.2.4.2  yamt         struct bcm2835mbox_softc *sc = device_private(self);
     78  1.2.4.2  yamt  	struct amba_attach_args *aaa = aux;
     79  1.2.4.2  yamt 
     80  1.2.4.2  yamt 	aprint_naive("\n");
     81  1.2.4.2  yamt 	aprint_normal(": VC mailbox\n");
     82  1.2.4.2  yamt 
     83  1.2.4.2  yamt 	if (bcm2835mbox_sc == NULL)
     84  1.2.4.2  yamt 		bcm2835mbox_sc = sc;
     85  1.2.4.2  yamt 
     86  1.2.4.2  yamt 	sc->sc_dev = self;
     87  1.2.4.2  yamt 	sc->sc_iot = aaa->aaa_iot;
     88  1.2.4.2  yamt 
     89  1.2.4.2  yamt 	if (bus_space_map(aaa->aaa_iot, aaa->aaa_addr, BCM2835_MBOX_SIZE, 0,
     90  1.2.4.2  yamt 	    &sc->sc_ioh)) {
     91  1.2.4.2  yamt 		aprint_error_dev(sc->sc_dev, "unable to map device\n");
     92  1.2.4.2  yamt 		return;
     93  1.2.4.2  yamt 	}
     94  1.2.4.2  yamt }
     95  1.2.4.2  yamt 
     96  1.2.4.2  yamt void
     97  1.2.4.2  yamt bcmmbox_read(uint8_t chan, uint32_t *data)
     98  1.2.4.2  yamt {
     99  1.2.4.2  yamt 	struct bcm2835mbox_softc *sc = bcm2835mbox_sc;
    100  1.2.4.2  yamt 
    101  1.2.4.2  yamt 	KASSERT(sc != NULL);
    102  1.2.4.2  yamt 
    103  1.2.4.2  yamt 	return bcm2835_mbox_read(sc->sc_iot, sc->sc_ioh, chan, data);
    104  1.2.4.2  yamt }
    105  1.2.4.2  yamt 
    106  1.2.4.2  yamt void
    107  1.2.4.2  yamt bcmmbox_write(uint8_t chan, uint32_t data)
    108  1.2.4.2  yamt {
    109  1.2.4.2  yamt 	struct bcm2835mbox_softc *sc = bcm2835mbox_sc;
    110  1.2.4.2  yamt 
    111  1.2.4.2  yamt 	KASSERT(sc != NULL);
    112  1.2.4.2  yamt 
    113  1.2.4.2  yamt 	return bcm2835_mbox_write(sc->sc_iot, sc->sc_ioh, chan, data);
    114  1.2.4.2  yamt }
    115