Home | History | Annotate | Line # | Download | only in broadcom
bcm2835_emmc.c revision 1.1.6.2
      1  1.1.6.2  yamt /*	$NetBSD: bcm2835_emmc.c,v 1.1.6.2 2012/10/30 17:18:58 yamt Exp $	*/
      2  1.1.6.2  yamt 
      3  1.1.6.2  yamt /*-
      4  1.1.6.2  yamt  * Copyright (c) 2012 The NetBSD Foundation, Inc.
      5  1.1.6.2  yamt  * All rights reserved.
      6  1.1.6.2  yamt  *
      7  1.1.6.2  yamt  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1.6.2  yamt  * by Nick Hudson
      9  1.1.6.2  yamt  *
     10  1.1.6.2  yamt  * Redistribution and use in source and binary forms, with or without
     11  1.1.6.2  yamt  * modification, are permitted provided that the following conditions
     12  1.1.6.2  yamt  * are met:
     13  1.1.6.2  yamt  * 1. Redistributions of source code must retain the above copyright
     14  1.1.6.2  yamt  *    notice, this list of conditions and the following disclaimer.
     15  1.1.6.2  yamt  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1.6.2  yamt  *    notice, this list of conditions and the following disclaimer in the
     17  1.1.6.2  yamt  *    documentation and/or other materials provided with the distribution.
     18  1.1.6.2  yamt  *
     19  1.1.6.2  yamt  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.1.6.2  yamt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.1.6.2  yamt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.1.6.2  yamt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.1.6.2  yamt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.1.6.2  yamt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.1.6.2  yamt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.1.6.2  yamt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.1.6.2  yamt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.1.6.2  yamt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.1.6.2  yamt  * POSSIBILITY OF SUCH DAMAGE.
     30  1.1.6.2  yamt  */
     31  1.1.6.2  yamt 
     32  1.1.6.2  yamt #include <sys/cdefs.h>
     33  1.1.6.2  yamt __KERNEL_RCSID(0, "$NetBSD: bcm2835_emmc.c,v 1.1.6.2 2012/10/30 17:18:58 yamt Exp $");
     34  1.1.6.2  yamt 
     35  1.1.6.2  yamt #include <sys/param.h>
     36  1.1.6.2  yamt #include <sys/systm.h>
     37  1.1.6.2  yamt #include <sys/device.h>
     38  1.1.6.2  yamt #include <sys/bus.h>
     39  1.1.6.2  yamt 
     40  1.1.6.2  yamt #include <arm/broadcom/bcm2835reg.h>
     41  1.1.6.2  yamt #include <arm/broadcom/bcm_amba.h>
     42  1.1.6.2  yamt 
     43  1.1.6.2  yamt #include <dev/sdmmc/sdhcreg.h>
     44  1.1.6.2  yamt #include <dev/sdmmc/sdhcvar.h>
     45  1.1.6.2  yamt #include <dev/sdmmc/sdmmcvar.h>
     46  1.1.6.2  yamt 
     47  1.1.6.2  yamt struct bcmemmc_softc {
     48  1.1.6.2  yamt 	struct sdhc_softc	sc;
     49  1.1.6.2  yamt 	device_t		sc_sdmmc;
     50  1.1.6.2  yamt 
     51  1.1.6.2  yamt 	bus_space_tag_t		sc_iot;
     52  1.1.6.2  yamt 	bus_space_handle_t	sc_ioh;
     53  1.1.6.2  yamt 	struct sdhc_host	*sc_hosts[1];
     54  1.1.6.2  yamt 	void			*sc_ih;
     55  1.1.6.2  yamt };
     56  1.1.6.2  yamt 
     57  1.1.6.2  yamt static int bcmemmc_match(device_t, struct cfdata *, void *);
     58  1.1.6.2  yamt static void bcmemmc_attach(device_t, device_t, void *);
     59  1.1.6.2  yamt 
     60  1.1.6.2  yamt CFATTACH_DECL_NEW(bcmemmc, sizeof(struct bcmemmc_softc),
     61  1.1.6.2  yamt     bcmemmc_match, bcmemmc_attach, NULL, NULL);
     62  1.1.6.2  yamt 
     63  1.1.6.2  yamt /* ARGSUSED */
     64  1.1.6.2  yamt static int
     65  1.1.6.2  yamt bcmemmc_match(device_t parent, struct cfdata *match, void *aux)
     66  1.1.6.2  yamt {
     67  1.1.6.2  yamt 	struct amba_attach_args *aaa = aux;
     68  1.1.6.2  yamt 
     69  1.1.6.2  yamt 	if (strcmp(aaa->aaa_name, "emmc") != 0)
     70  1.1.6.2  yamt 		return 0;
     71  1.1.6.2  yamt 
     72  1.1.6.2  yamt 	return 1;
     73  1.1.6.2  yamt }
     74  1.1.6.2  yamt 
     75  1.1.6.2  yamt /* ARGSUSED */
     76  1.1.6.2  yamt static void
     77  1.1.6.2  yamt bcmemmc_attach(device_t parent, device_t self, void *aux)
     78  1.1.6.2  yamt {
     79  1.1.6.2  yamt 	struct bcmemmc_softc *sc = device_private(self);
     80  1.1.6.2  yamt 	struct amba_attach_args *aaa = aux;
     81  1.1.6.2  yamt 	int error;
     82  1.1.6.2  yamt 
     83  1.1.6.2  yamt 	sc->sc.sc_dev = self;
     84  1.1.6.2  yamt // 	sc->sc.sc_dmat = aaa->amba_dmat;
     85  1.1.6.2  yamt 	sc->sc.sc_flags = 0;
     86  1.1.6.2  yamt // 	sc->sc.sc_flags |= SDHC_FLAG_USE_DMA;		/* not available (yet) */
     87  1.1.6.2  yamt 	sc->sc.sc_flags |= SDHC_FLAG_32BIT_ACCESS;
     88  1.1.6.2  yamt 	sc->sc.sc_flags |= SDHC_FLAG_HOSTCAPS;
     89  1.1.6.2  yamt 	sc->sc.sc_caps = SDHC_VOLTAGE_SUPP_3_3V;
     90  1.1.6.2  yamt 	sc->sc.sc_host = sc->sc_hosts;
     91  1.1.6.2  yamt 	sc->sc.sc_clkbase = 50000;	/* 50MHz */
     92  1.1.6.2  yamt 	sc->sc_iot = aaa->aaa_iot;
     93  1.1.6.2  yamt 
     94  1.1.6.2  yamt 	error = bus_space_map(sc->sc_iot, aaa->aaa_addr, aaa->aaa_size, 0,
     95  1.1.6.2  yamt 	    &sc->sc_ioh);
     96  1.1.6.2  yamt 	if (error) {
     97  1.1.6.2  yamt 		aprint_error_dev(self,
     98  1.1.6.2  yamt 		    "can't map registers for %s: %d\n", aaa->aaa_name, error);
     99  1.1.6.2  yamt 		return;
    100  1.1.6.2  yamt 	}
    101  1.1.6.2  yamt 
    102  1.1.6.2  yamt 	aprint_naive(": SDHC controller\n");
    103  1.1.6.2  yamt 	aprint_normal(": SDHC controller\n");
    104  1.1.6.2  yamt 
    105  1.1.6.2  yamt  	sc->sc_ih = bcm2835_intr_establish(aaa->aaa_intr, IPL_SDMMC, sdhc_intr,
    106  1.1.6.2  yamt  	    &sc->sc);
    107  1.1.6.2  yamt 
    108  1.1.6.2  yamt 	if (sc->sc_ih == NULL) {
    109  1.1.6.2  yamt 		aprint_error_dev(self, "failed to establish interrupt %d\n",
    110  1.1.6.2  yamt 		     aaa->aaa_intr);
    111  1.1.6.2  yamt 		goto fail;
    112  1.1.6.2  yamt 	}
    113  1.1.6.2  yamt 	aprint_normal_dev(self, "interrupting on intr %d\n", aaa->aaa_intr);
    114  1.1.6.2  yamt 
    115  1.1.6.2  yamt 	error = sdhc_host_found(&sc->sc, sc->sc_iot, sc->sc_ioh,
    116  1.1.6.2  yamt  	    aaa->aaa_size);
    117  1.1.6.2  yamt 	if (error != 0) {
    118  1.1.6.2  yamt 		aprint_error_dev(self, "couldn't initialize host, error=%d\n",
    119  1.1.6.2  yamt 		    error);
    120  1.1.6.2  yamt 		goto fail;
    121  1.1.6.2  yamt 	}
    122  1.1.6.2  yamt 	return;
    123  1.1.6.2  yamt 
    124  1.1.6.2  yamt fail:
    125  1.1.6.2  yamt 	if (sc->sc_ih) {
    126  1.1.6.2  yamt 		intr_disestablish(sc->sc_ih);
    127  1.1.6.2  yamt 		sc->sc_ih = NULL;
    128  1.1.6.2  yamt 	}
    129  1.1.6.2  yamt 	bus_space_unmap(sc->sc_iot, sc->sc_ioh, aaa->aaa_size);
    130  1.1.6.2  yamt }
    131