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