Home | History | Annotate | Line # | Download | only in imx
imx51_esdhc.c revision 1.1
      1  1.1  bsh /*	$NetBSD: imx51_esdhc.c,v 1.1 2012/04/19 09:53:53 bsh Exp $ */
      2  1.1  bsh 
      3  1.1  bsh /*-
      4  1.1  bsh  * Copyright (c) 2012  Genetec Corporation.  All rights reserved.
      5  1.1  bsh  * Written by Hiroyuki Bessho for Genetec Corporation.
      6  1.1  bsh  *
      7  1.1  bsh  * Redistribution and use in source and binary forms, with or without
      8  1.1  bsh  * modification, are permitted provided that the following conditions
      9  1.1  bsh  * are met:
     10  1.1  bsh  * 1. Redistributions of source code must retain the above copyright
     11  1.1  bsh  *    notice, this list of conditions and the following disclaimer.
     12  1.1  bsh  * 2. Redistributions in binary form must reproduce the above
     13  1.1  bsh  *    copyright notice, this list of conditions and the following
     14  1.1  bsh  *    disclaimer in the documentation and/or other materials provided
     15  1.1  bsh  *    with the distribution.
     16  1.1  bsh  *
     17  1.1  bsh  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
     18  1.1  bsh  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     19  1.1  bsh  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
     20  1.1  bsh  * PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS
     21  1.1  bsh  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     22  1.1  bsh  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     23  1.1  bsh  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
     24  1.1  bsh  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     25  1.1  bsh  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     26  1.1  bsh  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     27  1.1  bsh  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     28  1.1  bsh  * SUCH DAMAGE.
     29  1.1  bsh  */
     30  1.1  bsh 
     31  1.1  bsh 
     32  1.1  bsh #include <sys/cdefs.h>
     33  1.1  bsh __KERNEL_RCSID(0, "$NetBSD: imx51_esdhc.c,v 1.1 2012/04/19 09:53:53 bsh Exp $");
     34  1.1  bsh 
     35  1.1  bsh #include <sys/param.h>
     36  1.1  bsh #include <sys/device.h>
     37  1.1  bsh #include <sys/systm.h>
     38  1.1  bsh #include <sys/bus.h>
     39  1.1  bsh #include <sys/pmf.h>
     40  1.1  bsh 
     41  1.1  bsh #include <machine/intr.h>
     42  1.1  bsh 
     43  1.1  bsh #include <dev/sdmmc/sdhcvar.h>
     44  1.1  bsh #include <dev/sdmmc/sdmmcvar.h>
     45  1.1  bsh 
     46  1.1  bsh #include <arm/imx/imx51reg.h>
     47  1.1  bsh #include <arm/imx/imx51var.h>
     48  1.1  bsh #include <arm/imx/imx51_ccmvar.h>
     49  1.1  bsh 
     50  1.1  bsh struct sdhc_axi_softc {
     51  1.1  bsh 	struct sdhc_softc  sc_sdhc;
     52  1.1  bsh 	/* we have only one slot */
     53  1.1  bsh 	struct sdhc_host *sc_hosts[1];
     54  1.1  bsh 
     55  1.1  bsh 	void *sc_ih;
     56  1.1  bsh };
     57  1.1  bsh 
     58  1.1  bsh static int sdhc_match(device_t, cfdata_t, void *);
     59  1.1  bsh static void sdhc_attach(device_t, device_t, void *);
     60  1.1  bsh 
     61  1.1  bsh CFATTACH_DECL_NEW(sdhc_axi, sizeof(struct sdhc_axi_softc),
     62  1.1  bsh     sdhc_match, sdhc_attach, NULL, NULL);
     63  1.1  bsh 
     64  1.1  bsh static int
     65  1.1  bsh sdhc_match(device_t parent, cfdata_t cf, void *aux)
     66  1.1  bsh {
     67  1.1  bsh 
     68  1.1  bsh 	struct axi_attach_args *aa = aux;
     69  1.1  bsh 
     70  1.1  bsh 	switch (aa->aa_addr) {
     71  1.1  bsh 	case ESDHC1_BASE:
     72  1.1  bsh 	case ESDHC2_BASE:
     73  1.1  bsh 		return 1;
     74  1.1  bsh 	}
     75  1.1  bsh 
     76  1.1  bsh 	return 0;
     77  1.1  bsh }
     78  1.1  bsh 
     79  1.1  bsh static void
     80  1.1  bsh sdhc_attach(device_t parent, device_t self, void *aux)
     81  1.1  bsh {
     82  1.1  bsh 	struct sdhc_axi_softc *sc = device_private(self);
     83  1.1  bsh 	struct axi_attach_args *aa = aux;
     84  1.1  bsh 	bus_space_tag_t iot = aa->aa_iot;
     85  1.1  bsh 	bus_space_handle_t ioh;
     86  1.1  bsh 	u_int perclk;
     87  1.1  bsh 
     88  1.1  bsh 	sc->sc_sdhc.sc_dev = self;
     89  1.1  bsh 
     90  1.1  bsh 	sc->sc_sdhc.sc_dmat = aa->aa_dmat;
     91  1.1  bsh 
     92  1.1  bsh 	if (bus_space_map(iot, aa->aa_addr, ESDHC_SIZE, 0, &ioh)) {
     93  1.1  bsh 		aprint_error_dev(self, "can't map\n");
     94  1.1  bsh 		return;
     95  1.1  bsh 	}
     96  1.1  bsh 
     97  1.1  bsh 	aprint_normal(": SD/MMC host controller\n");
     98  1.1  bsh 	aprint_naive("\n");
     99  1.1  bsh 
    100  1.1  bsh 
    101  1.1  bsh 	sc->sc_sdhc.sc_host = sc->sc_hosts;
    102  1.1  bsh 	/* base clock frequency in kHz */
    103  1.1  bsh 	perclk = imx51_get_clock(IMX51CLK_PERCLK_ROOT);
    104  1.1  bsh 	sc->sc_sdhc.sc_clkbase = perclk / 1000;
    105  1.1  bsh 	sc->sc_sdhc.sc_flags |= SDHC_FLAG_HAVE_DVS |
    106  1.1  bsh 		SDHC_FLAG_NO_PWR0 |
    107  1.1  bsh 		SDHC_FLAG_32BIT_ACCESS |
    108  1.1  bsh 		SDHC_FLAG_ENHANCED;
    109  1.1  bsh 
    110  1.1  bsh 	sc->sc_ih = intr_establish(aa->aa_irq, IPL_SDMMC, IST_LEVEL,
    111  1.1  bsh 	    sdhc_intr, &sc->sc_sdhc);
    112  1.1  bsh 
    113  1.1  bsh 	if (sc->sc_ih == NULL) {
    114  1.1  bsh 		aprint_error_dev(self, "can't establish interrupt\n");
    115  1.1  bsh 		return;
    116  1.1  bsh 	}
    117  1.1  bsh 
    118  1.1  bsh 	if (sdhc_host_found(&sc->sc_sdhc, iot, ioh, ESDHC_SIZE)) {
    119  1.1  bsh 		aprint_error_dev(self, "can't initialize host\n");
    120  1.1  bsh 		return;
    121  1.1  bsh 	}
    122  1.1  bsh 
    123  1.1  bsh 	if (!pmf_device_register1(self, sdhc_suspend, sdhc_resume,
    124  1.1  bsh 		sdhc_shutdown)) {
    125  1.1  bsh 		aprint_error_dev(self,
    126  1.1  bsh 		    "can't establish power hook\n");
    127  1.1  bsh 	}
    128  1.1  bsh }
    129