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