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