Home | History | Annotate | Line # | Download | only in dev
com_arbus.c revision 1.11
      1  1.11   msaitoh /* $NetBSD: com_arbus.c,v 1.11 2014/02/07 15:49:40 msaitoh Exp $ */
      2   1.1   gdamore /*-
      3   1.1   gdamore  * Copyright (c) 2006 Urbana-Champaign Independent Media Center.
      4   1.1   gdamore  * Copyright (c) 2006 Garrett D'Amore.
      5   1.1   gdamore  * All rights reserved.
      6   1.1   gdamore  *
      7   1.1   gdamore  * Portions of this code were written by Garrett D'Amore for the
      8   1.1   gdamore  * Champaign-Urbana Community Wireless Network Project.
      9   1.1   gdamore  *
     10   1.1   gdamore  * Redistribution and use in source and binary forms, with or
     11   1.1   gdamore  * without modification, are permitted provided that the following
     12   1.1   gdamore  * conditions are met:
     13   1.1   gdamore  * 1. Redistributions of source code must retain the above copyright
     14   1.1   gdamore  *    notice, this list of conditions and the following disclaimer.
     15   1.1   gdamore  * 2. Redistributions in binary form must reproduce the above
     16   1.1   gdamore  *    copyright notice, this list of conditions and the following
     17   1.1   gdamore  *    disclaimer in the documentation and/or other materials provided
     18   1.1   gdamore  *    with the distribution.
     19   1.1   gdamore  * 3. All advertising materials mentioning features or use of this
     20   1.1   gdamore  *    software must display the following acknowledgements:
     21   1.1   gdamore  *      This product includes software developed by the Urbana-Champaign
     22   1.1   gdamore  *      Independent Media Center.
     23   1.1   gdamore  *	This product includes software developed by Garrett D'Amore.
     24   1.1   gdamore  * 4. Urbana-Champaign Independent Media Center's name and Garrett
     25   1.1   gdamore  *    D'Amore's name may not be used to endorse or promote products
     26   1.1   gdamore  *    derived from this software without specific prior written permission.
     27   1.1   gdamore  *
     28   1.1   gdamore  * THIS SOFTWARE IS PROVIDED BY THE URBANA-CHAMPAIGN INDEPENDENT
     29   1.1   gdamore  * MEDIA CENTER AND GARRETT D'AMORE ``AS IS'' AND ANY EXPRESS OR
     30   1.1   gdamore  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     31   1.1   gdamore  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     32   1.1   gdamore  * ARE DISCLAIMED.  IN NO EVENT SHALL THE URBANA-CHAMPAIGN INDEPENDENT
     33   1.1   gdamore  * MEDIA CENTER OR GARRETT D'AMORE BE LIABLE FOR ANY DIRECT, INDIRECT,
     34   1.1   gdamore  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     35   1.1   gdamore  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     36   1.1   gdamore  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
     37   1.1   gdamore  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     38   1.1   gdamore  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     39   1.1   gdamore  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     40   1.1   gdamore  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     41   1.1   gdamore  */
     42   1.1   gdamore 
     43   1.1   gdamore /*-
     44   1.1   gdamore  * Copyright (c) 1998 The NetBSD Foundation, Inc.
     45   1.1   gdamore  * All rights reserved.
     46   1.1   gdamore  *
     47   1.1   gdamore  * This code is derived from software contributed to The NetBSD Foundation
     48   1.1   gdamore  * by Charles M. Hannum.
     49   1.1   gdamore  *
     50   1.1   gdamore  * Redistribution and use in source and binary forms, with or without
     51   1.1   gdamore  * modification, are permitted provided that the following conditions
     52   1.1   gdamore  * are met:
     53   1.1   gdamore  * 1. Redistributions of source code must retain the above copyright
     54   1.1   gdamore  *    notice, this list of conditions and the following disclaimer.
     55   1.1   gdamore  * 2. Redistributions in binary form must reproduce the above copyright
     56   1.1   gdamore  *    notice, this list of conditions and the following disclaimer in the
     57   1.1   gdamore  *    documentation and/or other materials provided with the distribution.
     58   1.1   gdamore  *
     59   1.1   gdamore  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     60   1.1   gdamore  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     61   1.1   gdamore  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     62   1.1   gdamore  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     63   1.1   gdamore  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     64   1.1   gdamore  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     65   1.1   gdamore  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     66   1.1   gdamore  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     67   1.1   gdamore  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     68   1.1   gdamore  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     69   1.1   gdamore  * POSSIBILITY OF SUCH DAMAGE.
     70   1.1   gdamore  */
     71   1.1   gdamore 
     72   1.1   gdamore /*-
     73   1.1   gdamore  * Copyright (c) 1991 The Regents of the University of California.
     74   1.1   gdamore  * All rights reserved.
     75   1.1   gdamore  *
     76   1.1   gdamore  * Redistribution and use in source and binary forms, with or without
     77   1.1   gdamore  * modification, are permitted provided that the following conditions
     78   1.1   gdamore  * are met:
     79   1.1   gdamore  * 1. Redistributions of source code must retain the above copyright
     80   1.1   gdamore  *    notice, this list of conditions and the following disclaimer.
     81   1.1   gdamore  * 2. Redistributions in binary form must reproduce the above copyright
     82   1.1   gdamore  *    notice, this list of conditions and the following disclaimer in the
     83   1.1   gdamore  *    documentation and/or other materials provided with the distribution.
     84   1.1   gdamore  * 3. Neither the name of the University nor the names of its contributors
     85   1.1   gdamore  *    may be used to endorse or promote products derived from this software
     86   1.1   gdamore  *    without specific prior written permission.
     87   1.1   gdamore  *
     88   1.1   gdamore  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     89   1.1   gdamore  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     90   1.1   gdamore  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     91   1.1   gdamore  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     92   1.1   gdamore  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     93   1.1   gdamore  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     94   1.1   gdamore  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     95   1.1   gdamore  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     96   1.1   gdamore  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     97   1.1   gdamore  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     98   1.1   gdamore  * SUCH DAMAGE.
     99   1.1   gdamore  *
    100   1.1   gdamore  *	@(#)com.c	7.5 (Berkeley) 5/16/91
    101   1.1   gdamore  */
    102   1.1   gdamore 
    103   1.1   gdamore #include <sys/cdefs.h>
    104  1.11   msaitoh __KERNEL_RCSID(0, "$NetBSD: com_arbus.c,v 1.11 2014/02/07 15:49:40 msaitoh Exp $");
    105   1.1   gdamore 
    106   1.1   gdamore #include <sys/param.h>
    107   1.1   gdamore #include <sys/systm.h>
    108   1.1   gdamore #include <sys/device.h>
    109   1.4   gdamore #include <sys/kernel.h>
    110   1.1   gdamore #include <sys/termios.h>
    111   1.1   gdamore #include <sys/ttydefaults.h>
    112   1.1   gdamore #include <sys/types.h>
    113   1.1   gdamore 
    114   1.9    dyoung #include <sys/bus.h>
    115   1.1   gdamore 
    116   1.1   gdamore #include <dev/cons.h>
    117   1.1   gdamore #include <dev/ic/comreg.h>
    118   1.1   gdamore #include <dev/ic/comvar.h>
    119   1.1   gdamore 
    120   1.1   gdamore #include <mips/cpuregs.h>
    121   1.1   gdamore #include <mips/atheros/include/arbusvar.h>
    122   1.1   gdamore 
    123   1.5  jmcneill #include "opt_com.h"
    124   1.5  jmcneill 
    125   1.1   gdamore struct com_arbus_softc {
    126   1.1   gdamore 	struct com_softc sc_com;
    127   1.1   gdamore };
    128   1.1   gdamore 
    129   1.2   gdamore static void com_arbus_initmap(struct com_regs *);
    130   1.2   gdamore //static bus_space_tag_t com_arbus_get_bus_space_tag(void);
    131   1.6      cube static int com_arbus_match(device_t, cfdata_t , void *);
    132   1.6      cube static void com_arbus_attach(device_t, device_t, void *);
    133   1.1   gdamore 
    134   1.6      cube CFATTACH_DECL_NEW(com_arbus, sizeof(struct com_arbus_softc),
    135   1.1   gdamore     com_arbus_match, com_arbus_attach, NULL, NULL);
    136   1.1   gdamore 
    137   1.1   gdamore #if 0
    138   1.1   gdamore #ifdef	TTYDEF_SPEED
    139   1.1   gdamore #define	COM_ARBUS_BAUD	TTYDEF_SPEED
    140   1.1   gdamore #else
    141   1.1   gdamore #define	COM_ARBUS_BAUD	115200
    142   1.1   gdamore #endif
    143   1.1   gdamore #endif
    144   1.5  jmcneill 
    145   1.5  jmcneill #ifndef COM_ARBUS_BAUD
    146   1.1   gdamore #define	COM_ARBUS_BAUD	115200
    147   1.5  jmcneill #endif
    148   1.1   gdamore 
    149   1.1   gdamore int	com_arbus_baud = COM_ARBUS_BAUD;
    150   1.1   gdamore 
    151   1.1   gdamore #define CONMODE	((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
    152   1.1   gdamore 
    153   1.2   gdamore #ifndef	COM_REGMAP
    154   1.2   gdamore #error	COM_REGMAP not defined!
    155   1.2   gdamore #endif
    156   1.2   gdamore 
    157   1.1   gdamore int
    158   1.6      cube com_arbus_match(device_t parent, cfdata_t cf, void *aux)
    159   1.1   gdamore {
    160   1.1   gdamore 	struct arbus_attach_args	*aa = aux;
    161   1.2   gdamore 	struct com_regs			regs;
    162   1.1   gdamore 	int				rv;
    163   1.1   gdamore 
    164   1.2   gdamore 	if (strcmp(aa->aa_name, cf->cf_name) != 0)
    165   1.2   gdamore 		return 0;
    166   1.2   gdamore 
    167   1.2   gdamore 	if (com_is_console(aa->aa_bst, aa->aa_addr, &regs.cr_ioh))
    168   1.1   gdamore 		return 1;
    169   1.1   gdamore 
    170   1.1   gdamore 	if (bus_space_map(aa->aa_bst, aa->aa_addr, aa->aa_size,
    171   1.2   gdamore 		0, &regs.cr_ioh))
    172   1.1   gdamore 		return 0;
    173   1.1   gdamore 
    174   1.2   gdamore 	regs.cr_iot = aa->aa_bst;
    175   1.2   gdamore 	regs.cr_iobase = aa->aa_addr;
    176   1.2   gdamore 	regs.cr_nports = aa->aa_size;
    177   1.2   gdamore 	com_arbus_initmap(&regs);
    178   1.2   gdamore 
    179   1.2   gdamore 	rv = com_probe_subr(&regs);
    180   1.2   gdamore 
    181   1.2   gdamore 	bus_space_unmap(aa->aa_bst, regs.cr_ioh, aa->aa_size);
    182   1.1   gdamore 
    183   1.1   gdamore 	return rv;
    184   1.1   gdamore }
    185   1.1   gdamore 
    186   1.1   gdamore void
    187   1.6      cube com_arbus_attach(device_t parent, device_t self, void *aux)
    188   1.1   gdamore {
    189   1.6      cube 	struct com_arbus_softc *arsc = device_private(self);
    190   1.1   gdamore 	struct com_softc *sc = &arsc->sc_com;
    191   1.1   gdamore 	struct arbus_attach_args *aa = aux;
    192   1.4   gdamore 	prop_number_t prop;
    193   1.2   gdamore 	bus_space_handle_t ioh;
    194   1.1   gdamore 
    195   1.6      cube 	sc->sc_dev = self;
    196   1.6      cube 
    197   1.6      cube 	prop = prop_dictionary_get(device_properties(sc->sc_dev),
    198   1.4   gdamore 	    "frequency");
    199   1.4   gdamore 	if (prop == NULL) {
    200   1.6      cube 		aprint_error(": unable to get frequency property\n");
    201   1.4   gdamore 		return;
    202   1.4   gdamore 	}
    203   1.4   gdamore 	KASSERT(prop_object_type(prop) == PROP_TYPE_NUMBER);
    204   1.4   gdamore 
    205   1.4   gdamore 	sc->sc_frequency = (int)prop_number_integer_value(prop);
    206   1.1   gdamore 
    207  1.10      matt 	if (!com_is_console(aa->aa_bst, aa->aa_addr, &ioh)
    208  1.10      matt 	    && bus_space_map(aa->aa_bst, aa->aa_addr, aa->aa_size, 0,
    209  1.10      matt 		    &ioh) != 0) {
    210   1.6      cube 		aprint_error(": can't map registers\n");
    211   1.1   gdamore 		return;
    212   1.1   gdamore 	}
    213   1.1   gdamore 
    214   1.2   gdamore 	COM_INIT_REGS(sc->sc_regs, aa->aa_bst, ioh, aa->aa_addr);
    215   1.2   gdamore 	sc->sc_regs.cr_nports = aa->aa_size;
    216   1.2   gdamore 	com_arbus_initmap(&sc->sc_regs);
    217   1.2   gdamore 
    218   1.1   gdamore 	com_attach_subr(sc);
    219   1.1   gdamore 
    220   1.4   gdamore 	arbus_intr_establish(aa->aa_cirq, aa->aa_mirq, comintr, sc);
    221   1.1   gdamore }
    222   1.1   gdamore 
    223   1.2   gdamore void
    224   1.2   gdamore com_arbus_initmap(struct com_regs *regsp)
    225   1.1   gdamore {
    226  1.11   msaitoh #if _BYTE_ORDER == _BIG_ENDIAN
    227  1.11   msaitoh 	int off = 3;
    228  1.11   msaitoh #else
    229  1.11   msaitoh 	int off = 0;
    230  1.11   msaitoh #endif;
    231   1.1   gdamore 
    232   1.2   gdamore 	/* rewrite the map to shift for alignment */
    233  1.10      matt 	for (size_t i = 0; i < __arraycount(regsp->cr_map); i++) {
    234  1.11   msaitoh 		regsp->cr_map[i] = (com_std_map[i] * 4) + off;
    235   1.1   gdamore 	}
    236   1.1   gdamore }
    237   1.1   gdamore 
    238   1.1   gdamore void
    239   1.4   gdamore com_arbus_cnattach(bus_addr_t addr, uint32_t freq)
    240   1.1   gdamore {
    241   1.2   gdamore 	struct com_regs		regs;
    242   1.1   gdamore 
    243   1.2   gdamore 	regs.cr_iot = arbus_get_bus_space_tag();
    244   1.2   gdamore 	regs.cr_iobase = addr;
    245   1.2   gdamore 	regs.cr_nports = 0x1000;
    246   1.2   gdamore 	com_arbus_initmap(&regs);
    247   1.2   gdamore 
    248   1.2   gdamore 	if (bus_space_map(regs.cr_iot, regs.cr_iobase, regs.cr_nports, 0,
    249   1.2   gdamore 		&regs.cr_ioh))
    250   1.1   gdamore 		return;
    251   1.1   gdamore 
    252   1.4   gdamore 	comcnattach1(&regs, com_arbus_baud, freq, COM_TYPE_NORMAL, CONMODE);
    253   1.1   gdamore }
    254   1.1   gdamore 
    255