Home | History | Annotate | Line # | Download | only in marvell
com_mv.c revision 1.4.2.1
      1  1.4.2.1    jruoho /*	$NetBSD: com_mv.c,v 1.4.2.1 2011/06/06 09:07:58 jruoho Exp $	*/
      2      1.1  kiyohara /*
      3      1.1  kiyohara  * Copyright (c) 2007, 2010 KIYOHARA Takashi
      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  *
     15      1.1  kiyohara  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     16      1.1  kiyohara  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     17      1.1  kiyohara  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     18      1.1  kiyohara  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
     19      1.1  kiyohara  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     20      1.1  kiyohara  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     21      1.1  kiyohara  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     22      1.1  kiyohara  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     23      1.1  kiyohara  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
     24      1.1  kiyohara  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     25      1.1  kiyohara  * POSSIBILITY OF SUCH DAMAGE.
     26      1.1  kiyohara  */
     27      1.1  kiyohara 
     28      1.1  kiyohara #include <sys/cdefs.h>
     29  1.4.2.1    jruoho __KERNEL_RCSID(0, "$NetBSD: com_mv.c,v 1.4.2.1 2011/06/06 09:07:58 jruoho Exp $");
     30      1.4  kiyohara 
     31      1.4  kiyohara #include "opt_com.h"
     32      1.1  kiyohara 
     33      1.1  kiyohara #include <sys/param.h>
     34      1.1  kiyohara #include <sys/bus.h>
     35      1.1  kiyohara #include <sys/device.h>
     36      1.1  kiyohara #include <sys/errno.h>
     37      1.1  kiyohara #include <sys/termios.h>
     38      1.1  kiyohara 
     39      1.1  kiyohara #include <dev/marvell/gtvar.h>
     40      1.1  kiyohara #include <dev/marvell/marvellreg.h>
     41      1.1  kiyohara #include <dev/marvell/marvellvar.h>
     42      1.1  kiyohara 
     43      1.1  kiyohara #include <dev/ic/comvar.h>
     44      1.1  kiyohara 
     45      1.1  kiyohara #include <prop/proplib.h>
     46      1.1  kiyohara 
     47      1.1  kiyohara #define MVUART_SIZE		0x20
     48      1.1  kiyohara 
     49      1.1  kiyohara 
     50      1.1  kiyohara static int mvuart_match(device_t, struct cfdata *, void *);
     51      1.1  kiyohara static void mvuart_attach(device_t, device_t, void *);
     52      1.1  kiyohara 
     53      1.1  kiyohara CFATTACH_DECL_NEW(mvuart_gt, sizeof(struct com_softc),
     54      1.1  kiyohara     mvuart_match, mvuart_attach, NULL, NULL);
     55      1.1  kiyohara CFATTACH_DECL_NEW(mvuart_mbus, sizeof(struct com_softc),
     56      1.1  kiyohara     mvuart_match, mvuart_attach, NULL, NULL);
     57      1.1  kiyohara 
     58      1.1  kiyohara #ifdef COM_REGMAP
     59      1.1  kiyohara #define MVUART_INIT_REGS(regs, tag, hdl, addr, size)		\
     60      1.1  kiyohara 	do {							\
     61      1.1  kiyohara 		int i;						\
     62      1.1  kiyohara 								\
     63      1.1  kiyohara 		regs.cr_iot = tag;				\
     64      1.1  kiyohara 		regs.cr_ioh = hdl;				\
     65      1.1  kiyohara 		regs.cr_iobase = addr;				\
     66      1.1  kiyohara 		regs.cr_nports = size;				\
     67      1.1  kiyohara 		for (i = 0; i < __arraycount(regs.cr_map); i++)	\
     68      1.1  kiyohara 			regs.cr_map[i] = com_std_map[i] << 2;	\
     69      1.1  kiyohara 	} while (0)
     70      1.1  kiyohara #else
     71      1.1  kiyohara #define MVUART_INIT_REGS(regs, tag, hdl, addr, size) \
     72      1.1  kiyohara 	COM_INIT_REGS(regs, tag, hdl, addr)
     73      1.1  kiyohara #endif
     74      1.1  kiyohara 
     75      1.1  kiyohara 
     76      1.1  kiyohara /* ARGSUSED */
     77      1.1  kiyohara static int
     78      1.1  kiyohara mvuart_match(device_t parent, struct cfdata *match, void *aux)
     79      1.1  kiyohara {
     80      1.1  kiyohara 	struct marvell_attach_args *mva = aux;
     81      1.3  kiyohara 	struct com_regs regs;
     82      1.1  kiyohara 	bus_space_handle_t ioh;
     83      1.1  kiyohara 
     84      1.3  kiyohara 	if (strcmp(mva->mva_name, match->cf_name) != 0)
     85      1.3  kiyohara 		return 0;
     86      1.3  kiyohara 	if (mva->mva_offset == MVA_OFFSET_DEFAULT ||
     87      1.3  kiyohara 	    mva->mva_irq == MVA_IRQ_DEFAULT)
     88      1.1  kiyohara 		return 0;
     89      1.1  kiyohara 
     90      1.1  kiyohara 	if (com_is_console(mva->mva_iot, mva->mva_addr + mva->mva_offset, NULL))
     91  1.4.2.1    jruoho 		goto console;
     92      1.1  kiyohara 
     93      1.1  kiyohara 	if (bus_space_subregion(mva->mva_iot, mva->mva_ioh, mva->mva_offset,
     94      1.3  kiyohara 	    MVUART_SIZE, &ioh))
     95      1.1  kiyohara 		return 0;
     96      1.3  kiyohara 	MVUART_INIT_REGS(regs, mva->mva_iot, ioh, mva->mva_offset, MVUART_SIZE);
     97      1.3  kiyohara 	if (!com_probe_subr(&regs))
     98      1.1  kiyohara 		return 0;
     99      1.3  kiyohara 
    100  1.4.2.1    jruoho console:
    101      1.1  kiyohara 	mva->mva_size = MVUART_SIZE;
    102      1.1  kiyohara 	return 1;
    103      1.1  kiyohara }
    104      1.1  kiyohara 
    105      1.1  kiyohara /* ARGSUSED */
    106      1.1  kiyohara static void
    107      1.1  kiyohara mvuart_attach(device_t parent, device_t self, void *aux)
    108      1.1  kiyohara {
    109      1.1  kiyohara 	struct com_softc *sc = device_private(self);
    110      1.1  kiyohara 	struct marvell_attach_args *mva = aux;
    111      1.1  kiyohara 	bus_space_tag_t iot;
    112      1.1  kiyohara 	bus_space_handle_t ioh;
    113      1.1  kiyohara 	prop_dictionary_t dict = device_properties(self);
    114      1.1  kiyohara 
    115      1.1  kiyohara 	sc->sc_dev = self;
    116      1.1  kiyohara 
    117      1.1  kiyohara 	if (!prop_dictionary_get_uint32(dict, "frequency", &sc->sc_frequency)) {
    118      1.1  kiyohara 		aprint_error(": no frequency property\n");
    119      1.1  kiyohara 		return;
    120      1.1  kiyohara 	}
    121      1.1  kiyohara 
    122      1.1  kiyohara 	iot = mva->mva_iot;
    123      1.1  kiyohara 	if (!com_is_console(iot, mva->mva_addr + mva->mva_offset, &ioh)) {
    124      1.1  kiyohara 		if (bus_space_subregion(iot, mva->mva_ioh, mva->mva_offset,
    125      1.1  kiyohara 		    mva->mva_size, &ioh)) {
    126      1.1  kiyohara 			aprint_error(": can't map registers\n");
    127      1.1  kiyohara 			return;
    128      1.1  kiyohara 		}
    129      1.1  kiyohara 	}
    130      1.1  kiyohara 	MVUART_INIT_REGS(sc->sc_regs,
    131      1.1  kiyohara 	    iot, ioh, mva->mva_addr + mva->mva_offset, mva->mva_size);
    132      1.1  kiyohara 
    133      1.1  kiyohara 	com_attach_subr(sc);
    134      1.1  kiyohara 
    135      1.1  kiyohara 	marvell_intr_establish(mva->mva_irq, IPL_SERIAL, comintr, sc);
    136      1.1  kiyohara }
    137      1.1  kiyohara 
    138      1.1  kiyohara #ifdef COM_REGMAP
    139      1.1  kiyohara int mvuart_cnattach(bus_space_tag_t, bus_addr_t, int, uint32_t, int);
    140      1.1  kiyohara 
    141      1.1  kiyohara int
    142      1.1  kiyohara mvuart_cnattach(bus_space_tag_t iot, bus_addr_t addr, int baud,
    143      1.1  kiyohara 		uint32_t sysfreq, int mode)
    144      1.1  kiyohara {
    145      1.1  kiyohara 	struct com_regs regs;
    146      1.1  kiyohara 
    147      1.1  kiyohara 	MVUART_INIT_REGS(regs, iot, 0x0, addr, MVUART_SIZE);
    148      1.1  kiyohara 
    149      1.1  kiyohara 	return comcnattach1(&regs, baud, sysfreq, COM_TYPE_16550_NOERS, mode);
    150      1.1  kiyohara }
    151      1.1  kiyohara #endif /* COM_REGMAP */
    152