Home | History | Annotate | Line # | Download | only in marvell
gttwsi.c revision 1.5.8.2
      1  1.5.8.2      yamt /*	$NetBSD: gttwsi.c,v 1.5.8.2 2014/05/22 11:40:23 yamt Exp $	*/
      2      1.1  kiyohara /*
      3      1.1  kiyohara  * Copyright (c) 2008 Eiji Kawauchi.
      4      1.1  kiyohara  * All rights reserved.
      5      1.1  kiyohara  *
      6      1.1  kiyohara  * Redistribution and use in source and binary forms, with or without
      7      1.1  kiyohara  * modification, are permitted provided that the following conditions
      8      1.1  kiyohara  * are met:
      9      1.1  kiyohara  * 1. Redistributions of source code must retain the above copyright
     10      1.1  kiyohara  *    notice, this list of conditions and the following disclaimer.
     11      1.1  kiyohara  * 2. Redistributions in binary form must reproduce the above copyright
     12      1.1  kiyohara  *    notice, this list of conditions and the following disclaimer in the
     13      1.1  kiyohara  *    documentation and/or other materials provided with the distribution.
     14      1.1  kiyohara  * 3. All advertising materials mentioning features or use of this software
     15      1.1  kiyohara  *    must display the following acknowledgement:
     16      1.1  kiyohara  *      This product includes software developed for the NetBSD Project by
     17      1.1  kiyohara  *      Eiji Kawauchi.
     18      1.1  kiyohara  * 4. The name of the author may not be used to endorse or promote products
     19      1.1  kiyohara  *    derived from this software without specific prior written permission
     20      1.1  kiyohara  *
     21      1.1  kiyohara  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22      1.1  kiyohara  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23      1.1  kiyohara  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24      1.1  kiyohara  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25      1.1  kiyohara  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26      1.1  kiyohara  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27      1.1  kiyohara  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28      1.1  kiyohara  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29      1.1  kiyohara  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30      1.1  kiyohara  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31      1.1  kiyohara  */
     32      1.1  kiyohara /*
     33      1.1  kiyohara  * Copyright (c) 2005 Brocade Communcations, inc.
     34      1.1  kiyohara  * All rights reserved.
     35      1.1  kiyohara  *
     36      1.1  kiyohara  * Written by Matt Thomas for Brocade Communcations, Inc.
     37      1.1  kiyohara  *
     38      1.1  kiyohara  * Redistribution and use in source and binary forms, with or without
     39      1.1  kiyohara  * modification, are permitted provided that the following conditions
     40      1.1  kiyohara  * are met:
     41      1.1  kiyohara  * 1. Redistributions of source code must retain the above copyright
     42      1.1  kiyohara  *    notice, this list of conditions and the following disclaimer.
     43      1.1  kiyohara  * 2. Redistributions in binary form must reproduce the above copyright
     44      1.1  kiyohara  *    notice, this list of conditions and the following disclaimer in the
     45      1.1  kiyohara  *    documentation and/or other materials provided with the distribution.
     46      1.1  kiyohara  * 3. The name of Brocade Communications, Inc. may not be used to endorse
     47      1.1  kiyohara  *    or promote products derived from this software without specific prior
     48      1.1  kiyohara  *    written permission.
     49      1.1  kiyohara  *
     50      1.1  kiyohara  * THIS SOFTWARE IS PROVIDED BY BROCADE COMMUNICATIONS, INC. ``AS IS'' AND
     51      1.1  kiyohara  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     52      1.1  kiyohara  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     53      1.1  kiyohara  * ARE DISCLAIMED.  IN NO EVENT SHALL EITHER BROCADE COMMUNICATIONS, INC. BE
     54      1.1  kiyohara  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     55      1.1  kiyohara  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     56      1.1  kiyohara  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     57      1.1  kiyohara  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     58      1.1  kiyohara  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     59      1.1  kiyohara  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
     60      1.1  kiyohara  * OF THE POSSIBILITY OF SUCH DAMAGE.
     61      1.1  kiyohara  */
     62      1.1  kiyohara //#define TWSI_DEBUG
     63      1.1  kiyohara 
     64      1.1  kiyohara /*
     65      1.1  kiyohara  * Marvell Two-Wire Serial Interface (aka I2C) master driver
     66      1.1  kiyohara  */
     67      1.1  kiyohara 
     68      1.1  kiyohara #include <sys/cdefs.h>
     69  1.5.8.2      yamt __KERNEL_RCSID(0, "$NetBSD: gttwsi.c,v 1.5.8.2 2014/05/22 11:40:23 yamt Exp $");
     70      1.1  kiyohara #include "locators.h"
     71      1.1  kiyohara 
     72      1.1  kiyohara #include <sys/param.h>
     73      1.1  kiyohara #include <sys/bus.h>
     74      1.1  kiyohara #include <sys/condvar.h>
     75      1.1  kiyohara #include <sys/device.h>
     76      1.1  kiyohara #include <sys/errno.h>
     77      1.1  kiyohara #include <sys/kernel.h>
     78      1.1  kiyohara #include <sys/mutex.h>
     79      1.1  kiyohara #include <sys/systm.h>
     80      1.1  kiyohara 
     81      1.1  kiyohara #include <machine/cpu.h>
     82      1.1  kiyohara #include <machine/param.h>
     83      1.1  kiyohara 
     84      1.1  kiyohara #include <dev/i2c/i2cvar.h>
     85  1.5.8.2      yamt #include <dev/i2c/gttwsireg.h>
     86  1.5.8.2      yamt #include <dev/i2c/gttwsivar.h>
     87      1.1  kiyohara 
     88      1.1  kiyohara #include <dev/marvell/marvellvar.h>
     89      1.1  kiyohara 
     90      1.1  kiyohara static int	gttwsi_match(device_t, cfdata_t, void *);
     91      1.1  kiyohara static void	gttwsi_attach(device_t, device_t, void *);
     92      1.1  kiyohara 
     93      1.1  kiyohara CFATTACH_DECL_NEW(gttwsi_gt, sizeof(struct gttwsi_softc),
     94      1.1  kiyohara     gttwsi_match, gttwsi_attach, NULL, NULL);
     95      1.1  kiyohara CFATTACH_DECL_NEW(gttwsi_mbus, sizeof(struct gttwsi_softc),
     96      1.1  kiyohara     gttwsi_match, gttwsi_attach, NULL, NULL);
     97      1.1  kiyohara 
     98      1.1  kiyohara /* ARGSUSED */
     99      1.1  kiyohara static int
    100      1.1  kiyohara gttwsi_match(device_t parent, cfdata_t match, void *aux)
    101      1.1  kiyohara {
    102      1.1  kiyohara 	struct marvell_attach_args *mva = aux;
    103      1.1  kiyohara 
    104      1.1  kiyohara 	if (strcmp(mva->mva_name, match->cf_name) != 0)
    105      1.1  kiyohara 		return 0;
    106      1.2  kiyohara 	if (mva->mva_offset == MVA_OFFSET_DEFAULT ||
    107      1.2  kiyohara 	    mva->mva_irq == MVA_IRQ_DEFAULT)
    108      1.1  kiyohara 		return 0;
    109      1.1  kiyohara 
    110      1.1  kiyohara 	mva->mva_size = GTTWSI_SIZE;
    111      1.1  kiyohara 	return 1;
    112      1.1  kiyohara }
    113      1.1  kiyohara 
    114      1.1  kiyohara /* ARGSUSED */
    115      1.1  kiyohara static void
    116      1.1  kiyohara gttwsi_attach(device_t parent, device_t self, void *args)
    117      1.1  kiyohara {
    118      1.1  kiyohara 	struct marvell_attach_args *mva = args;
    119  1.5.8.2      yamt 	bus_space_handle_t ioh;
    120      1.1  kiyohara 
    121      1.1  kiyohara 	if (bus_space_subregion(mva->mva_iot, mva->mva_ioh, mva->mva_offset,
    122  1.5.8.2      yamt 	    mva->mva_size, &ioh)) {
    123  1.5.8.2      yamt 		aprint_error(": cannot map registers\n");
    124      1.1  kiyohara 		return;
    125      1.1  kiyohara 	}
    126      1.1  kiyohara 
    127  1.5.8.2      yamt 	gttwsi_attach_subr(self, mva->mva_iot, ioh);
    128      1.1  kiyohara 
    129  1.5.8.2      yamt 	marvell_intr_establish(mva->mva_irq, IPL_BIO, gttwsi_intr,
    130  1.5.8.2      yamt 	    device_private(self));
    131      1.1  kiyohara 
    132  1.5.8.2      yamt 	gttwsi_config_children(self);
    133      1.1  kiyohara }
    134