Home | History | Annotate | Line # | Download | only in imx
imx51_gpio.c revision 1.3
      1  1.3  hkenken /*	$NetBSD: imx51_gpio.c,v 1.3 2014/07/25 07:49:56 hkenken Exp $ */
      2  1.1      bsh 
      3  1.1      bsh /* derived from imx31_gpio.c */
      4  1.1      bsh /*-
      5  1.1      bsh  * Copyright (c) 2007 The NetBSD Foundation, Inc.
      6  1.1      bsh  * All rights reserved.
      7  1.1      bsh  *
      8  1.1      bsh  * This code is derived from software contributed to The NetBSD Foundation
      9  1.1      bsh  * by Matt Thomas
     10  1.1      bsh  *
     11  1.1      bsh  * Redistribution and use in source and binary forms, with or without
     12  1.1      bsh  * modification, are permitted provided that the following conditions
     13  1.1      bsh  * are met:
     14  1.1      bsh  * 1. Redistributions of source code must retain the above copyright
     15  1.1      bsh  *    notice, this list of conditions and the following disclaimer.
     16  1.1      bsh  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.1      bsh  *    notice, this list of conditions and the following disclaimer in the
     18  1.1      bsh  *    documentation and/or other materials provided with the distribution.
     19  1.1      bsh  *
     20  1.1      bsh  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     21  1.1      bsh  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22  1.1      bsh  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23  1.1      bsh  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     24  1.1      bsh  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25  1.1      bsh  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26  1.1      bsh  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27  1.1      bsh  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28  1.1      bsh  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29  1.1      bsh  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30  1.1      bsh  * POSSIBILITY OF SUCH DAMAGE.
     31  1.1      bsh  */
     32  1.1      bsh #include <sys/cdefs.h>
     33  1.3  hkenken __KERNEL_RCSID(0, "$NetBSD: imx51_gpio.c,v 1.3 2014/07/25 07:49:56 hkenken Exp $");
     34  1.3  hkenken 
     35  1.3  hkenken #include "opt_imx.h"
     36  1.1      bsh 
     37  1.1      bsh #include "locators.h"
     38  1.1      bsh #include "gpio.h"
     39  1.1      bsh 
     40  1.1      bsh #include <sys/param.h>
     41  1.1      bsh #include <sys/evcnt.h>
     42  1.1      bsh #include <sys/atomic.h>
     43  1.1      bsh 
     44  1.1      bsh #include <machine/intr.h>
     45  1.1      bsh 
     46  1.1      bsh #include <arm/cpu.h>
     47  1.1      bsh #include <arm/armreg.h>
     48  1.1      bsh #include <arm/cpufunc.h>
     49  1.1      bsh 
     50  1.2   dyoung #include <sys/bus.h>
     51  1.1      bsh 
     52  1.1      bsh #include <arm/imx/imx51reg.h>
     53  1.1      bsh #include <arm/imx/imx51var.h>
     54  1.1      bsh #include <arm/pic/picvar.h>
     55  1.1      bsh 
     56  1.1      bsh #include <arm/imx/imxgpioreg.h>
     57  1.1      bsh #include <arm/imx/imxgpiovar.h>
     58  1.1      bsh 
     59  1.1      bsh #if NGPIO > 0
     60  1.1      bsh #include <sys/gpio.h>
     61  1.1      bsh #include <dev/gpio/gpiovar.h>
     62  1.1      bsh #endif
     63  1.1      bsh 
     64  1.1      bsh const int imxgpio_ngroups = GPIO_NGROUPS;
     65  1.1      bsh 
     66  1.1      bsh int
     67  1.1      bsh imxgpio_match(device_t parent, cfdata_t cfdata, void *aux)
     68  1.1      bsh {
     69  1.1      bsh 	struct axi_attach_args *aa = aux;
     70  1.1      bsh 
     71  1.1      bsh 	switch(aa->aa_addr) {
     72  1.1      bsh 	case GPIO1_BASE:
     73  1.1      bsh 	case GPIO2_BASE:
     74  1.1      bsh 	case GPIO3_BASE:
     75  1.1      bsh 	case GPIO4_BASE:
     76  1.3  hkenken #ifdef IMX50
     77  1.3  hkenken 	case GPIO5_BASE:
     78  1.3  hkenken 	case GPIO6_BASE:
     79  1.3  hkenken #endif
     80  1.1      bsh 		return 1;
     81  1.1      bsh 	}
     82  1.1      bsh 
     83  1.1      bsh 	return 0;
     84  1.1      bsh }
     85  1.1      bsh 
     86  1.1      bsh void
     87  1.1      bsh imxgpio_attach(device_t parent, device_t self, void *aux)
     88  1.1      bsh {
     89  1.1      bsh 	struct axi_attach_args * const aa = aux;
     90  1.1      bsh 	bus_space_handle_t ioh;
     91  1.1      bsh 	int error;
     92  1.1      bsh 
     93  1.1      bsh 	if (aa->aa_irq == AXICF_IRQ_DEFAULT &&
     94  1.1      bsh 	    aa->aa_irqbase != AXICF_IRQBASE_DEFAULT) {
     95  1.1      bsh 		aprint_error_dev(self, "missing intr in config\n");
     96  1.1      bsh 		return;
     97  1.1      bsh 	}
     98  1.1      bsh 	if (aa->aa_irq != AXICF_IRQ_DEFAULT &&
     99  1.1      bsh 	    aa->aa_irqbase == AXICF_IRQBASE_DEFAULT) {
    100  1.1      bsh 		aprint_error_dev(self, "missing irqbase in config\n");
    101  1.1      bsh 		return;
    102  1.1      bsh 	}
    103  1.1      bsh 
    104  1.1      bsh 	if (aa->aa_size == AXICF_SIZE_DEFAULT)
    105  1.1      bsh 		aa->aa_size = GPIO_SIZE;
    106  1.1      bsh 
    107  1.1      bsh 	error = bus_space_map(aa->aa_iot, aa->aa_addr, aa->aa_size,
    108  1.1      bsh 	    0, &ioh);
    109  1.1      bsh 
    110  1.1      bsh 	if (error) {
    111  1.1      bsh 		aprint_error(": failed to map register %#lx@%#lx: %d\n",
    112  1.1      bsh 		    aa->aa_size, aa->aa_addr, error);
    113  1.1      bsh 		return;
    114  1.1      bsh 	}
    115  1.1      bsh 
    116  1.1      bsh 	imxgpio_attach_common(self, aa->aa_iot, ioh,
    117  1.1      bsh 	    (aa->aa_addr - GPIO1_BASE) / 0x4000,
    118  1.1      bsh 	    aa->aa_irq, aa->aa_irqbase);
    119  1.1      bsh }
    120  1.1      bsh 
    121