Home | History | Annotate | Line # | Download | only in alchemy
mtx-1.c revision 1.7.12.1
      1  1.7.12.1  jdolecek /* $NetBSD: mtx-1.c,v 1.7.12.1 2017/12/03 11:36:08 jdolecek Exp $ */
      2       1.1   gdamore 
      3       1.1   gdamore /*-
      4       1.1   gdamore  * Copyright (c) 2006 Itronix Inc.
      5       1.1   gdamore  * All rights reserved.
      6       1.1   gdamore  *
      7       1.1   gdamore  * Written by Garrett D'Amore for Itronix Inc.
      8       1.1   gdamore  *
      9       1.1   gdamore  * Redistribution and use in source and binary forms, with or without
     10       1.1   gdamore  * modification, are permitted provided that the following conditions
     11       1.1   gdamore  * are met:
     12       1.1   gdamore  * 1. Redistributions of source code must retain the above copyright
     13       1.1   gdamore  *    notice, this list of conditions and the following disclaimer.
     14       1.1   gdamore  * 2. Redistributions in binary form must reproduce the above copyright
     15       1.1   gdamore  *    notice, this list of conditions and the following disclaimer in the
     16       1.1   gdamore  *    documentation and/or other materials provided with the distribution.
     17       1.1   gdamore  * 3. The name of Itronix Inc. may not be used to endorse
     18       1.1   gdamore  *    or promote products derived from this software without specific
     19       1.1   gdamore  *    prior written permission.
     20       1.1   gdamore  *
     21       1.1   gdamore  * THIS SOFTWARE IS PROVIDED BY ITRONIX INC. ``AS IS'' AND
     22       1.1   gdamore  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     23       1.1   gdamore  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     24       1.1   gdamore  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY
     25       1.1   gdamore  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     26       1.1   gdamore  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     27       1.1   gdamore  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     28       1.1   gdamore  * ON ANY THEORY OF LIABILITY, WHETHER IN
     29       1.1   gdamore  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     30       1.1   gdamore  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     31       1.1   gdamore  * POSSIBILITY OF SUCH DAMAGE.
     32       1.1   gdamore  */
     33       1.1   gdamore 
     34       1.1   gdamore #include <sys/cdefs.h>
     35  1.7.12.1  jdolecek __KERNEL_RCSID(0, "$NetBSD: mtx-1.c,v 1.7.12.1 2017/12/03 11:36:08 jdolecek Exp $");
     36       1.1   gdamore 
     37       1.1   gdamore #include <sys/param.h>
     38       1.6    dyoung #include <sys/bus.h>
     39  1.7.12.1  jdolecek #include <sys/cpu.h>
     40       1.7      matt 
     41       1.7      matt #include <mips/locore.h>
     42       1.7      matt 
     43       1.1   gdamore #include <evbmips/alchemy/obiovar.h>
     44       1.1   gdamore #include <evbmips/alchemy/board.h>
     45       1.1   gdamore 
     46       1.1   gdamore #define	MTX1_RESET	0xE00001C
     47       1.1   gdamore 
     48       1.1   gdamore #define	GET16(x)	\
     49       1.1   gdamore 	(*((volatile uint16_t *)MIPS_PHYS_TO_KSEG1(x)))
     50       1.1   gdamore #define	PUT16(x, v)	\
     51       1.1   gdamore 	(*((volatile uint16_t *)MIPS_PHYS_TO_KSEG1(x)) = (v))
     52       1.1   gdamore 
     53       1.1   gdamore static void mtx1_init(void);
     54       1.5    dyoung static int mtx1_pci_intr_map(const struct pci_attach_args *,
     55       1.1   gdamore 				 pci_intr_handle_t *);
     56       1.1   gdamore static void mtx1_reboot(void);
     57       1.1   gdamore 
     58       1.1   gdamore static const struct obiodev mtx1_devices[] = {
     59       1.1   gdamore #if 0
     60       1.1   gdamore 	{ "aupcmcia", -1, -1 },
     61       1.1   gdamore 	{ "auaudio", -1, -1 },
     62       1.1   gdamore #endif
     63       1.1   gdamore 	{ NULL },
     64       1.1   gdamore };
     65       1.1   gdamore 
     66       1.1   gdamore static struct alchemy_board mtx1_info = {
     67       1.1   gdamore 	"4G Systems MTX-1",
     68       1.1   gdamore 	mtx1_devices,
     69       1.1   gdamore 	mtx1_init,
     70       1.1   gdamore 	mtx1_pci_intr_map,
     71       1.1   gdamore 	mtx1_reboot,
     72       1.1   gdamore 	NULL,	/* poweroff */
     73       1.1   gdamore };
     74       1.1   gdamore 
     75       1.1   gdamore const struct alchemy_board *
     76       1.2   gdamore board_info(void)
     77       1.1   gdamore {
     78       1.1   gdamore 
     79       1.1   gdamore 	return &mtx1_info;
     80       1.1   gdamore }
     81       1.1   gdamore 
     82       1.1   gdamore void
     83       1.1   gdamore mtx1_init(void)
     84       1.1   gdamore {
     85       1.1   gdamore 
     86       1.4      matt 	if (MIPS_PRID_COPTS(mips_options.mips_cpu_id) != MIPS_AU1500)
     87       1.1   gdamore 		panic("mtx-1: CPU not an AU1500!");
     88       1.1   gdamore 
     89       1.1   gdamore 	/*
     90       1.1   gdamore 	 * If we had any kind of identification registers, we could
     91       1.1   gdamore 	 * print them here.  Apparently the MTX-1 doesn't have that
     92       1.1   gdamore 	 * kind of info.
     93       1.1   gdamore 	 */
     94       1.1   gdamore 
     95       1.1   gdamore 	/* leave console and clocks alone -- YAMON should have got it right! */
     96       1.1   gdamore }
     97       1.1   gdamore 
     98       1.1   gdamore int
     99       1.5    dyoung mtx1_pci_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
    100       1.1   gdamore {
    101       1.1   gdamore 	/*
    102       1.1   gdamore 	 * The board has up to 4 adapters, each with two minipci slots,
    103       1.1   gdamore 	 * giving up to 8 devices.  Each slot 0 is the top, and slot 1
    104       1.1   gdamore 	 * is the bottom.
    105       1.1   gdamore 	 *
    106       1.1   gdamore 	 * As these are mini PCI slots, only 2 interrupt pins can be
    107       1.1   gdamore 	 * used on each slot.
    108       1.1   gdamore 	 */
    109       1.1   gdamore 	static const int irqmap[8/*device*/][4/*pin*/] = {
    110       1.1   gdamore 		{  1,  2, -1, -1 },	/* IDSEL 0 - Adapter A - Slot 0 */
    111       1.1   gdamore 		{  1,  2, -1, -1 },	/* IDSEL 1 - Adapter A - Slot 1 */
    112       1.1   gdamore 		{  4,  5, -1, -1 },	/* IDSEL 2 - Adapter B - Slot 0 */
    113       1.1   gdamore 		{  5,  4, -1, -1 },	/* IDSEL 3 - Adapter B - Slot 1 */
    114       1.1   gdamore 
    115       1.1   gdamore 		{  1,  2, -1, -1 },	/* IDSEL 4 - Adapter C - Slot 0 */
    116       1.1   gdamore 		{  1,  2, -1, -1 },	/* IDSEL 5 - Adapter C - Slot 1 */
    117       1.1   gdamore 		{  4,  5, -1, -1 },	/* IDSEL 6 - Adapter D - Slot 0 */
    118       1.1   gdamore 		{  5,  4, -1, -1 },	/* IDSEL 7 - Adapter D - Slot 1 */
    119       1.1   gdamore 	};
    120       1.1   gdamore 	int	pin, dev, irq;
    121       1.1   gdamore 
    122       1.1   gdamore 	/* if interrupt pin not used... */
    123       1.1   gdamore 	if ((pin = pa->pa_intrpin) == 0)
    124       1.1   gdamore 		return 1;
    125       1.1   gdamore 
    126       1.1   gdamore 	if (pin > 4) {
    127       1.1   gdamore 		printf("pci: bad interrupt pin %d\n", pin);
    128       1.1   gdamore 		return 1;
    129       1.1   gdamore 	}
    130       1.1   gdamore 
    131       1.1   gdamore 	pci_decompose_tag(pa->pa_pc, pa->pa_intrtag, NULL, &dev, NULL);
    132       1.1   gdamore 	if ((dev < 0) || (dev > 7)) {
    133       1.1   gdamore 		printf("pci: bad device %d\n", dev);
    134       1.1   gdamore 		return 1;
    135       1.1   gdamore 	}
    136       1.1   gdamore 
    137       1.1   gdamore 	if ((irq = irqmap[dev][pin - 1]) == -1) {
    138       1.1   gdamore 		printf("pci: no IRQ routing for device %d pin %d\n", dev, pin);
    139       1.1   gdamore 		return 1;
    140       1.1   gdamore 	}
    141       1.1   gdamore 
    142       1.1   gdamore 	*ihp = irq;
    143       1.1   gdamore 	return 0;
    144       1.1   gdamore }
    145       1.1   gdamore 
    146       1.1   gdamore void
    147       1.1   gdamore mtx1_reboot(void)
    148       1.1   gdamore {
    149       1.1   gdamore 	/* fyi, this looks like the same as the DBAu1500 reset */
    150       1.1   gdamore 	PUT16(MTX1_RESET , 0);
    151       1.1   gdamore 	delay(100000);	/* 100 msec */
    152       1.1   gdamore }
    153