Home | History | Annotate | Line # | Download | only in marvell
gttwsi.c revision 1.12
      1  1.12   thorpej /*	$NetBSD: gttwsi.c,v 1.12 2020/01/12 17:48:42 thorpej 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.12   thorpej __KERNEL_RCSID(0, "$NetBSD: gttwsi.c,v 1.12 2020/01/12 17:48:42 thorpej 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.11      matt #include <dev/i2c/gttwsireg.h>
     86  1.11      matt #include <dev/i2c/gttwsivar.h>
     87   1.1  kiyohara 
     88   1.1  kiyohara #include <dev/marvell/marvellvar.h>
     89   1.1  kiyohara 
     90  1.12   thorpej static const bus_size_t marvell_twsi_regmap[GTTWSI_NREGS] = {
     91  1.12   thorpej 	[TWSI_SLAVEADDR]	= TWSI_MARVELL_SLAVEADDR,
     92  1.12   thorpej 	[TWSI_EXTEND_SLAVEADDR]	= TWSI_MARVELL_EXTEND_SLAVEADDR,
     93  1.12   thorpej 	[TWSI_DATA]		= TWSI_MARVELL_DATA,
     94  1.12   thorpej 	[TWSI_CONTROL]		= TWSI_MARVELL_CONTROL,
     95  1.12   thorpej 	[TWSI_STATUS]		= TWSI_MARVELL_STATUS,
     96  1.12   thorpej 	[TWSI_BAUDRATE]		= TWSI_MARVELL_BAUDRATE,
     97  1.12   thorpej 	[TWSI_SOFTRESET]	= TWSI_MARVELL_SOFTRESET,
     98  1.12   thorpej };
     99  1.12   thorpej 
    100   1.1  kiyohara static int	gttwsi_match(device_t, cfdata_t, void *);
    101   1.1  kiyohara static void	gttwsi_attach(device_t, device_t, void *);
    102   1.1  kiyohara 
    103   1.1  kiyohara CFATTACH_DECL_NEW(gttwsi_gt, sizeof(struct gttwsi_softc),
    104   1.1  kiyohara     gttwsi_match, gttwsi_attach, NULL, NULL);
    105   1.1  kiyohara CFATTACH_DECL_NEW(gttwsi_mbus, sizeof(struct gttwsi_softc),
    106   1.1  kiyohara     gttwsi_match, gttwsi_attach, NULL, NULL);
    107   1.1  kiyohara 
    108   1.1  kiyohara /* ARGSUSED */
    109   1.1  kiyohara static int
    110   1.1  kiyohara gttwsi_match(device_t parent, cfdata_t match, void *aux)
    111   1.1  kiyohara {
    112   1.1  kiyohara 	struct marvell_attach_args *mva = aux;
    113   1.1  kiyohara 
    114   1.1  kiyohara 	if (strcmp(mva->mva_name, match->cf_name) != 0)
    115   1.1  kiyohara 		return 0;
    116   1.2  kiyohara 	if (mva->mva_offset == MVA_OFFSET_DEFAULT ||
    117   1.2  kiyohara 	    mva->mva_irq == MVA_IRQ_DEFAULT)
    118   1.1  kiyohara 		return 0;
    119   1.1  kiyohara 
    120   1.1  kiyohara 	mva->mva_size = GTTWSI_SIZE;
    121   1.1  kiyohara 	return 1;
    122   1.1  kiyohara }
    123   1.1  kiyohara 
    124   1.1  kiyohara /* ARGSUSED */
    125   1.1  kiyohara static void
    126   1.1  kiyohara gttwsi_attach(device_t parent, device_t self, void *args)
    127   1.1  kiyohara {
    128   1.1  kiyohara 	struct marvell_attach_args *mva = args;
    129  1.11      matt 	bus_space_handle_t ioh;
    130   1.1  kiyohara 
    131   1.1  kiyohara 	if (bus_space_subregion(mva->mva_iot, mva->mva_ioh, mva->mva_offset,
    132  1.11      matt 	    mva->mva_size, &ioh)) {
    133  1.11      matt 		aprint_error(": cannot map registers\n");
    134   1.1  kiyohara 		return;
    135   1.1  kiyohara 	}
    136   1.1  kiyohara 
    137  1.12   thorpej 	gttwsi_attach_subr(self, mva->mva_iot, ioh, marvell_twsi_regmap);
    138   1.1  kiyohara 
    139  1.11      matt 	marvell_intr_establish(mva->mva_irq, IPL_BIO, gttwsi_intr,
    140  1.11      matt 	    device_private(self));
    141   1.1  kiyohara 
    142  1.11      matt 	gttwsi_config_children(self);
    143   1.1  kiyohara }
    144