Home | History | Annotate | Line # | Download | only in imx
imx51_iomux.c revision 1.3.2.1
      1  1.3.2.1     tls /*	$NetBSD: imx51_iomux.c,v 1.3.2.1 2012/11/20 03:01:05 tls Exp $	*/
      2      1.1     bsh 
      3      1.1     bsh /*
      4      1.1     bsh  * Copyright (c) 2009, 2010  Genetec Corporation.  All rights reserved.
      5      1.1     bsh  * Written by Hashimoto Kenichi 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 copyright
     13      1.1     bsh  *    notice, this list of conditions and the following disclaimer in the
     14      1.1     bsh  *    documentation and/or other materials provided with the distribution.
     15      1.1     bsh  *
     16      1.1     bsh  * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
     17      1.1     bsh  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18      1.1     bsh  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19      1.1     bsh  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL GENETEC CORPORATION
     20      1.1     bsh  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21      1.1     bsh  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22      1.1     bsh  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23      1.1     bsh  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24      1.1     bsh  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25      1.1     bsh  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26      1.1     bsh  * POSSIBILITY OF SUCH DAMAGE.
     27      1.1     bsh  */
     28      1.1     bsh #include <sys/cdefs.h>
     29  1.3.2.1     tls __KERNEL_RCSID(0, "$NetBSD: imx51_iomux.c,v 1.3.2.1 2012/11/20 03:01:05 tls Exp $");
     30      1.1     bsh 
     31      1.1     bsh #define	_INTR_PRIVATE
     32      1.1     bsh 
     33      1.1     bsh #include "locators.h"
     34      1.1     bsh 
     35      1.1     bsh #include <sys/param.h>
     36      1.1     bsh #include <sys/evcnt.h>
     37      1.1     bsh #include <sys/atomic.h>
     38      1.1     bsh #include <sys/device.h>
     39      1.1     bsh 
     40      1.1     bsh #include <uvm/uvm_extern.h>
     41      1.1     bsh 
     42      1.1     bsh #include <machine/intr.h>
     43      1.1     bsh 
     44      1.1     bsh #include <arm/cpu.h>
     45      1.1     bsh #include <arm/armreg.h>
     46      1.1     bsh #include <arm/cpufunc.h>
     47      1.1     bsh 
     48      1.2  dyoung #include <sys/bus.h>
     49      1.1     bsh 
     50      1.1     bsh #include <arm/imx/imx51reg.h>
     51      1.1     bsh #include <arm/imx/imx51var.h>
     52      1.1     bsh 
     53      1.1     bsh struct iomux_softc {
     54      1.1     bsh 	bus_space_tag_t iomux_memt;
     55      1.1     bsh 	bus_space_handle_t iomux_memh;
     56      1.1     bsh };
     57      1.1     bsh 
     58      1.1     bsh #define	IOMUX_READ(iomux, reg) \
     59      1.1     bsh 	bus_space_read_4((iomux)->iomux_memt, (iomux)->iomux_memh, (reg))
     60      1.1     bsh #define	IOMUX_WRITE(iomux, reg, val) \
     61      1.1     bsh 	bus_space_write_4((iomux)->iomux_memt, (iomux)->iomux_memh, (reg), (val))
     62      1.1     bsh 
     63      1.1     bsh static int iomux_match(device_t, cfdata_t, void *);
     64      1.1     bsh static void iomux_attach(device_t, device_t, void *);
     65      1.1     bsh 
     66      1.1     bsh static struct iomux_softc *iomuxsc = NULL;
     67      1.1     bsh 
     68      1.3     bsh CFATTACH_DECL_NEW(imxiomux, sizeof(struct iomux_softc),
     69      1.3     bsh     iomux_match, iomux_attach, NULL, NULL);
     70      1.1     bsh 
     71      1.1     bsh int
     72      1.1     bsh iomux_match(device_t parent, cfdata_t cfdata, void *aux)
     73      1.1     bsh {
     74      1.1     bsh 	struct axi_attach_args *axia = aux;
     75      1.1     bsh 
     76      1.1     bsh 	if (axia->aa_addr != IOMUXC_BASE)
     77      1.1     bsh 		return 0;
     78      1.1     bsh 
     79      1.1     bsh 	return 1;
     80      1.1     bsh }
     81      1.1     bsh 
     82      1.1     bsh void
     83      1.1     bsh iomux_attach(device_t parent, device_t self, void *aux)
     84      1.1     bsh {
     85      1.1     bsh 	struct axi_attach_args * const axia = aux;
     86      1.1     bsh 	struct iomux_softc * const iomux = device_private(self);
     87      1.1     bsh 	int error;
     88      1.1     bsh 
     89      1.1     bsh 	if (axia->aa_size == AXICF_SIZE_DEFAULT)
     90      1.1     bsh 		axia->aa_size = IOMUXC_SIZE;
     91      1.1     bsh 
     92      1.1     bsh 	iomux->iomux_memt = axia->aa_iot;
     93      1.1     bsh 	error = bus_space_map(axia->aa_iot, axia->aa_addr, axia->aa_size,
     94      1.1     bsh 			      0, &iomux->iomux_memh);
     95      1.1     bsh 
     96      1.1     bsh 	if (error) {
     97      1.1     bsh 		aprint_error(": failed to map register %#lx@%#lx: %d\n",
     98      1.1     bsh 		    axia->aa_size, axia->aa_addr, error);
     99      1.1     bsh 		return;
    100      1.1     bsh 	}
    101      1.1     bsh 
    102      1.1     bsh 	aprint_normal("\n");
    103      1.1     bsh 
    104      1.1     bsh 	iomuxsc = iomux;
    105      1.1     bsh }
    106      1.1     bsh 
    107      1.1     bsh static void
    108      1.1     bsh iomux_set_function_sub(struct iomux_softc *sc, uint32_t pin, uint32_t fn)
    109      1.1     bsh {
    110      1.1     bsh 	bus_size_t mux_ctl_reg = IOMUX_PIN_TO_MUX_ADDRESS(pin);
    111      1.1     bsh 
    112      1.1     bsh 	if (mux_ctl_reg != IOMUX_MUX_NONE)
    113      1.1     bsh 		bus_space_write_4(sc->iomux_memt, sc->iomux_memh,
    114      1.1     bsh 		    mux_ctl_reg, fn);
    115      1.1     bsh }
    116      1.1     bsh 
    117      1.1     bsh void
    118      1.1     bsh iomux_set_function(unsigned int pin, unsigned int fn)
    119      1.1     bsh {
    120      1.1     bsh 	iomux_set_function_sub(iomuxsc, pin, fn);
    121      1.1     bsh }
    122      1.1     bsh 
    123      1.1     bsh 
    124      1.1     bsh static void
    125      1.1     bsh iomux_set_pad_sub(struct iomux_softc *sc, uint32_t pin, uint32_t config)
    126      1.1     bsh {
    127      1.1     bsh 	bus_size_t pad_ctl_reg = IOMUX_PIN_TO_PAD_ADDRESS(pin);
    128      1.1     bsh 
    129      1.1     bsh 	if (pad_ctl_reg != IOMUX_PAD_NONE)
    130      1.1     bsh 		bus_space_write_4(sc->iomux_memt, sc->iomux_memh,
    131      1.1     bsh 		    pad_ctl_reg, config);
    132      1.1     bsh }
    133      1.1     bsh 
    134      1.1     bsh void
    135      1.1     bsh iomux_set_pad(unsigned int pin, unsigned int config)
    136      1.1     bsh {
    137      1.1     bsh 	iomux_set_pad_sub(iomuxsc, pin, config);
    138      1.1     bsh }
    139      1.1     bsh 
    140      1.1     bsh #if 0
    141      1.1     bsh void
    142      1.1     bsh iomux_set_input(unsigned int input, unsigned int config)
    143      1.1     bsh {
    144      1.1     bsh 	bus_size_t input_ctl_reg = input;
    145      1.1     bsh 
    146      1.1     bsh 	bus_space_write_4(iomuxsc->iomux_memt, iomuxsc->iomux_memh,
    147      1.1     bsh 	    input_ctl_reg, config);
    148      1.1     bsh }
    149      1.1     bsh #endif
    150      1.1     bsh 
    151      1.1     bsh void
    152      1.1     bsh iomux_mux_config(const struct iomux_conf *conflist)
    153      1.1     bsh {
    154      1.1     bsh 	int i;
    155      1.1     bsh 
    156      1.1     bsh 	for (i = 0; conflist[i].pin != IOMUX_CONF_EOT; i++) {
    157      1.1     bsh 		iomux_set_pad_sub(iomuxsc, conflist[i].pin, conflist[i].pad);
    158      1.3     bsh 		iomux_set_function_sub(iomuxsc, conflist[i].pin,
    159      1.1     bsh 		    conflist[i].mux);
    160      1.1     bsh 	}
    161      1.1     bsh }
    162      1.1     bsh 
    163      1.1     bsh #if 0
    164      1.1     bsh void
    165      1.1     bsh iomux_input_config(const struct iomux_input_conf *conflist)
    166      1.1     bsh {
    167      1.1     bsh 	int i;
    168      1.1     bsh 
    169      1.1     bsh 	for (i = 0; conflist[i].inout != -1; i++) {
    170      1.3     bsh 		iomux_set_inout(iomuxsc, conflist[i].inout,
    171      1.1     bsh 		    conflist[i].inout_mode);
    172      1.1     bsh 	}
    173      1.1     bsh }
    174      1.1     bsh #endif
    175      1.1     bsh 
    176