Home | History | Annotate | Line # | Download | only in mpcsa
mpcsa_cf.c revision 1.1.20.1
      1  1.1.20.1  yamt /*	$Id: mpcsa_cf.c,v 1.1.20.1 2009/05/04 08:10:59 yamt Exp $	*/
      2  1.1.20.1  yamt /*	$NetBSD: mpcsa_cf.c,v 1.1.20.1 2009/05/04 08:10:59 yamt Exp $	*/
      3  1.1.20.1  yamt 
      4  1.1.20.1  yamt /*
      5  1.1.20.1  yamt  * Copyright (c) 2007 Embedtronics Oy. All rights reserved.
      6  1.1.20.1  yamt  *
      7  1.1.20.1  yamt  * Redistribution and use in source and binary forms, with or without
      8  1.1.20.1  yamt  * modification, are permitted provided that the following conditions
      9  1.1.20.1  yamt  * are met:
     10  1.1.20.1  yamt  * 1. Redistributions of source code must retain the above copyright
     11  1.1.20.1  yamt  *    notice, this list of conditions and the following disclaimer.
     12  1.1.20.1  yamt  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1.20.1  yamt  *    notice, this list of conditions and the following disclaimer in the
     14  1.1.20.1  yamt  *    documentation and/or other materials provided with the distribution.
     15  1.1.20.1  yamt  *
     16  1.1.20.1  yamt  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     17  1.1.20.1  yamt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18  1.1.20.1  yamt  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19  1.1.20.1  yamt  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     20  1.1.20.1  yamt  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21  1.1.20.1  yamt  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     22  1.1.20.1  yamt  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23  1.1.20.1  yamt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24  1.1.20.1  yamt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  1.1.20.1  yamt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  1.1.20.1  yamt  * SUCH DAMAGE.
     27  1.1.20.1  yamt  */
     28  1.1.20.1  yamt 
     29  1.1.20.1  yamt #include <sys/cdefs.h>
     30  1.1.20.1  yamt __KERNEL_RCSID(0, "$NetBSD: mpcsa_cf.c,v 1.1.20.1 2009/05/04 08:10:59 yamt Exp $");
     31  1.1.20.1  yamt 
     32  1.1.20.1  yamt #include <sys/param.h>
     33  1.1.20.1  yamt #include <sys/systm.h>
     34  1.1.20.1  yamt #include <sys/kernel.h>
     35  1.1.20.1  yamt #include <sys/device.h>
     36  1.1.20.1  yamt #include <arm/at91/at91reg.h>
     37  1.1.20.1  yamt #include <arm/at91/at91var.h>
     38  1.1.20.1  yamt #include <arm/at91/at91cfvar.h>
     39  1.1.20.1  yamt #include <arm/at91/at91piovar.h>
     40  1.1.20.1  yamt 
     41  1.1.20.1  yamt #ifdef MPCA_CF_DEBUG
     42  1.1.20.1  yamt int mpcsa_cf_debug = MPCA_CF_DEBUG;
     43  1.1.20.1  yamt #define DPRINTFN(n,x)	if (mpcsa_cf_debug>(n)) printf x;
     44  1.1.20.1  yamt #else
     45  1.1.20.1  yamt #define DPRINTFN(n,x)
     46  1.1.20.1  yamt #endif
     47  1.1.20.1  yamt 
     48  1.1.20.1  yamt struct at91_gpio_softc;
     49  1.1.20.1  yamt 
     50  1.1.20.1  yamt struct mpcsa_cf_softc {
     51  1.1.20.1  yamt 	struct at91cf_softc	sc_dev;
     52  1.1.20.1  yamt 	struct at91pio_softc	*sc_pioc;
     53  1.1.20.1  yamt };
     54  1.1.20.1  yamt 
     55  1.1.20.1  yamt static int mpcsa_cf_match(struct device *, struct cfdata *, void *);
     56  1.1.20.1  yamt static void mpcsa_cf_attach(struct device *, struct device *, void *);
     57  1.1.20.1  yamt 
     58  1.1.20.1  yamt CFATTACH_DECL_NEW(mpcsa_cf, sizeof(struct mpcsa_cf_softc),
     59  1.1.20.1  yamt 	      mpcsa_cf_match, mpcsa_cf_attach, NULL, NULL);
     60  1.1.20.1  yamt 
     61  1.1.20.1  yamt static int	mpcsa_cf_power_ctl(void *self, int onoff);
     62  1.1.20.1  yamt static int	mpcsa_cf_card_detect(void *self);
     63  1.1.20.1  yamt static int	mpcsa_cf_irq_line(void *self);
     64  1.1.20.1  yamt static void *	mpcsa_cf_intr_establish(void *self, int which, int ipl, int (*ih_func)(void *), void *arg);
     65  1.1.20.1  yamt static void	mpcsa_cf_intr_disestablish(void *self, int which, void *cookie);
     66  1.1.20.1  yamt 
     67  1.1.20.1  yamt struct at91cf_chipset_tag mpcsa_cf_tag = {
     68  1.1.20.1  yamt 	mpcsa_cf_power_ctl,
     69  1.1.20.1  yamt 	mpcsa_cf_card_detect,
     70  1.1.20.1  yamt 	mpcsa_cf_irq_line,
     71  1.1.20.1  yamt 	mpcsa_cf_intr_establish,
     72  1.1.20.1  yamt 	mpcsa_cf_intr_disestablish
     73  1.1.20.1  yamt };
     74  1.1.20.1  yamt 
     75  1.1.20.1  yamt static int
     76  1.1.20.1  yamt mpcsa_cf_match(struct device *parent, struct cfdata *match, void *aux)
     77  1.1.20.1  yamt {
     78  1.1.20.1  yamt 	if (strcmp(match->cf_name, "at91cf") == 0 && strcmp(match->cf_atname, "mpcsa_cf") == 0)
     79  1.1.20.1  yamt 		return 2;
     80  1.1.20.1  yamt 	return 0;
     81  1.1.20.1  yamt }
     82  1.1.20.1  yamt 
     83  1.1.20.1  yamt static void
     84  1.1.20.1  yamt mpcsa_cf_attach(struct device *parent, struct device *self, void *aux)
     85  1.1.20.1  yamt {
     86  1.1.20.1  yamt 	struct mpcsa_cf_softc *sc = device_private(self);
     87  1.1.20.1  yamt //	at91cf_chipset_tag_t cscf = sc->sc_dev.sc_cscf;
     88  1.1.20.1  yamt 	struct at91pio_softc *pioc;
     89  1.1.20.1  yamt 
     90  1.1.20.1  yamt 	if ((pioc = at91pio_sc(AT91_PIOC)) == NULL) {
     91  1.1.20.1  yamt 		printf("no PIOC!\n");
     92  1.1.20.1  yamt 		return;
     93  1.1.20.1  yamt 	}
     94  1.1.20.1  yamt 
     95  1.1.20.1  yamt 	// configure PIO!
     96  1.1.20.1  yamt 	sc->sc_pioc = pioc;
     97  1.1.20.1  yamt 	at91pio_in(sc->sc_pioc, 3);	// CFIRQ
     98  1.1.20.1  yamt 	at91pio_in(sc->sc_pioc, 4);	// CFCD
     99  1.1.20.1  yamt 	at91pio_out(sc->sc_pioc, 5);	// CFRESET
    100  1.1.20.1  yamt 
    101  1.1.20.1  yamt 	// and call common routine
    102  1.1.20.1  yamt 	at91cf_attach_common(parent, self, aux, &mpcsa_cf_tag);
    103  1.1.20.1  yamt }
    104  1.1.20.1  yamt 
    105  1.1.20.1  yamt static int
    106  1.1.20.1  yamt mpcsa_cf_power_ctl(void *self, int onoff)
    107  1.1.20.1  yamt {
    108  1.1.20.1  yamt 	struct mpcsa_cf_softc *sc = self;
    109  1.1.20.1  yamt 	if (onoff) {
    110  1.1.20.1  yamt 		at91pio_set(sc->sc_pioc, 5);
    111  1.1.20.1  yamt 		return 20000;
    112  1.1.20.1  yamt 	} else {
    113  1.1.20.1  yamt 		at91pio_clear(sc->sc_pioc, 5);
    114  1.1.20.1  yamt 		return 20000;
    115  1.1.20.1  yamt 	}
    116  1.1.20.1  yamt }
    117  1.1.20.1  yamt 
    118  1.1.20.1  yamt static int	mpcsa_cf_card_detect(void *self)
    119  1.1.20.1  yamt {
    120  1.1.20.1  yamt 	struct mpcsa_cf_softc *sc = self;
    121  1.1.20.1  yamt 	return at91pio_read(sc->sc_pioc, 4) == 0;
    122  1.1.20.1  yamt }
    123  1.1.20.1  yamt 
    124  1.1.20.1  yamt static int	mpcsa_cf_irq_line(void *self)
    125  1.1.20.1  yamt {
    126  1.1.20.1  yamt 	struct mpcsa_cf_softc *sc = self;
    127  1.1.20.1  yamt 	return at91pio_read(sc->sc_pioc, 3);
    128  1.1.20.1  yamt }
    129  1.1.20.1  yamt 
    130  1.1.20.1  yamt static void *	mpcsa_cf_intr_establish(void *self, int which, int ipl, int (*ih_func)(void *), void *ih_arg)
    131  1.1.20.1  yamt {
    132  1.1.20.1  yamt 	struct mpcsa_cf_softc *sc = self;
    133  1.1.20.1  yamt 	return at91pio_intr_establish(sc->sc_pioc, which == CD_IRQ ? 4 : 3,
    134  1.1.20.1  yamt 					ipl, ih_func, ih_arg);
    135  1.1.20.1  yamt }
    136  1.1.20.1  yamt 
    137  1.1.20.1  yamt static void	mpcsa_cf_intr_disestablish(void *self, int which, void *cookie)
    138  1.1.20.1  yamt {
    139  1.1.20.1  yamt 	struct mpcsa_cf_softc *sc = self;
    140  1.1.20.1  yamt 	at91pio_intr_disestablish(sc->sc_pioc, which == CD_IRQ ? 4 : 3, cookie);
    141  1.1.20.1  yamt }
    142  1.1.20.1  yamt 
    143