Home | History | Annotate | Line # | Download | only in ic
cpc700.c revision 1.9.4.2
      1  1.9.4.2      yamt /*	$NetBSD: cpc700.c,v 1.9.4.2 2007/10/27 11:30:35 yamt Exp $	*/
      2      1.1  augustss 
      3      1.1  augustss /*
      4      1.1  augustss  * Copyright (c) 2002 The NetBSD Foundation, Inc.
      5      1.1  augustss  * All rights reserved.
      6      1.1  augustss  *
      7      1.1  augustss  * This code is derived from software contributed to The NetBSD Foundation
      8      1.1  augustss  * by Lennart Augustsson (lennart (at) augustsson.net) at Sandburst Corp.
      9      1.1  augustss  *
     10      1.1  augustss  * Redistribution and use in source and binary forms, with or without
     11      1.1  augustss  * modification, are permitted provided that the following conditions
     12      1.1  augustss  * are met:
     13      1.1  augustss  * 1. Redistributions of source code must retain the above copyright
     14      1.1  augustss  *    notice, this list of conditions and the following disclaimer.
     15      1.1  augustss  * 2. Redistributions in binary form must reproduce the above copyright
     16      1.1  augustss  *    notice, this list of conditions and the following disclaimer in the
     17      1.1  augustss  *    documentation and/or other materials provided with the distribution.
     18      1.1  augustss  * 3. All advertising materials mentioning features or use of this software
     19      1.1  augustss  *    must display the following acknowledgement:
     20      1.1  augustss  *        This product includes software developed by the NetBSD
     21      1.1  augustss  *        Foundation, Inc. and its contributors.
     22      1.1  augustss  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23      1.1  augustss  *    contributors may be used to endorse or promote products derived
     24      1.1  augustss  *    from this software without specific prior written permission.
     25      1.1  augustss  *
     26      1.1  augustss  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27      1.1  augustss  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28      1.1  augustss  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29      1.1  augustss  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30      1.1  augustss  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31      1.1  augustss  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32      1.1  augustss  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33      1.1  augustss  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34      1.1  augustss  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35      1.1  augustss  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36      1.1  augustss  * POSSIBILITY OF SUCH DAMAGE.
     37      1.1  augustss  */
     38      1.1  augustss 
     39      1.1  augustss /*
     40      1.1  augustss  * The IBM CPC700 is a bridge chip for the PowerPC.  It contains
     41      1.1  augustss  *  - CPU interface
     42      1.1  augustss  *  - DRAM controller
     43      1.1  augustss  *  - PCI bus master & slave controller
     44      1.1  augustss  *  - interrupt controller
     45      1.1  augustss  *  - timer
     46      1.1  augustss  *  - two UARTs
     47      1.1  augustss  *  - two IIC ports
     48      1.1  augustss  *
     49      1.1  augustss  *  This driver handles the overall device and enumeration of the
     50      1.1  augustss  *  supported subdevices.  NetBSD knows how to handle:
     51      1.1  augustss  *  - PCI master
     52      1.1  augustss  *  - interrupt controller
     53      1.1  augustss  *  - UARTs
     54      1.1  augustss  *  Skeleton drivers are provided for the timer and IIC.
     55      1.1  augustss  *
     56      1.1  augustss  * XXX This driver assumes that there is only one instance of it.
     57      1.1  augustss  */
     58      1.6     lukem 
     59      1.6     lukem #include <sys/cdefs.h>
     60  1.9.4.2      yamt __KERNEL_RCSID(0, "$NetBSD: cpc700.c,v 1.9.4.2 2007/10/27 11:30:35 yamt Exp $");
     61      1.1  augustss 
     62      1.1  augustss #include "pci.h"
     63      1.1  augustss #include "opt_pci.h"
     64      1.1  augustss 
     65      1.1  augustss #include <sys/param.h>
     66      1.1  augustss #include <sys/extent.h>
     67      1.1  augustss #include <sys/device.h>
     68      1.1  augustss #include <sys/malloc.h>
     69      1.1  augustss #include <sys/systm.h>
     70      1.1  augustss 
     71  1.9.4.2      yamt #include <sys/bus.h>
     72      1.1  augustss #include "locators.h"
     73      1.1  augustss 
     74      1.1  augustss #include <dev/pci/pcivar.h>
     75      1.1  augustss #include <dev/pci/pcireg.h>
     76      1.1  augustss #include <dev/pci/pciconf.h>
     77      1.1  augustss 
     78      1.1  augustss #include <dev/ic/cpc700reg.h>
     79      1.1  augustss #include <dev/ic/cpc700var.h>
     80      1.1  augustss #include <dev/ic/cpc700uic.h>
     81      1.1  augustss 
     82      1.1  augustss union attach_args {
     83      1.1  augustss 	struct pcibus_attach_args pba;
     84      1.1  augustss 	struct cpcbus_attach_args cba;
     85      1.1  augustss };
     86      1.1  augustss 
     87      1.1  augustss 
     88      1.1  augustss void
     89      1.1  augustss cpc_attach(struct device *self, pci_chipset_tag_t pc, bus_space_tag_t mem,
     90      1.1  augustss 	   bus_space_tag_t pciio, bus_dma_tag_t tag, int attachpci,
     91      1.1  augustss 	   uint freq);
     92      1.1  augustss 
     93      1.1  augustss static bus_space_tag_t the_cpc_tag;
     94      1.1  augustss static bus_space_handle_t the_cpc_handle;
     95      1.1  augustss #define INL(a) bus_space_read_stream_4(the_cpc_tag, the_cpc_handle, (a))
     96      1.1  augustss #define OUTL(a, d) bus_space_write_stream_4(the_cpc_tag, the_cpc_handle, (a), d)
     97      1.1  augustss 
     98      1.1  augustss static int
     99      1.1  augustss cpc_print(void *aux, const char *pnp)
    100      1.1  augustss {
    101      1.1  augustss 	struct cpcbus_attach_args *caa = aux;
    102      1.1  augustss 
    103      1.1  augustss 	if (pnp)
    104      1.5   thorpej 		aprint_normal("%s at %s", caa->cpca_name, pnp);
    105      1.1  augustss 
    106      1.5   thorpej 	aprint_normal(" addr 0x%08x", caa->cpca_addr);
    107      1.1  augustss 	if (caa->cpca_irq != CPCBUSCF_IRQ_DEFAULT)
    108      1.5   thorpej 		aprint_normal(" irq %d", caa->cpca_irq);
    109      1.1  augustss 
    110      1.1  augustss 	return (UNCONF);
    111      1.1  augustss }
    112      1.1  augustss 
    113      1.1  augustss static int
    114      1.8  drochner cpc_submatch(struct device *parent, struct cfdata *cf,
    115  1.9.4.1      yamt 	     const int *ldesc, void *aux)
    116      1.1  augustss {
    117      1.1  augustss 	struct cpcbus_attach_args *caa = aux;
    118      1.1  augustss 
    119      1.1  augustss 	if (cf->cf_loc[CPCBUSCF_ADDR] != caa->cpca_addr)
    120      1.1  augustss 		return (0);
    121      1.1  augustss 
    122      1.4   thorpej 	return (config_match(parent, cf, aux));
    123      1.1  augustss }
    124      1.1  augustss 
    125      1.1  augustss /*
    126      1.1  augustss  * Attach the cpc.
    127      1.1  augustss  */
    128      1.1  augustss void
    129      1.1  augustss cpc_attach(struct device *self, pci_chipset_tag_t pc, bus_space_tag_t mem,
    130      1.1  augustss 	   bus_space_tag_t pciio, bus_dma_tag_t dma, int attachpci,
    131      1.1  augustss 	   uint freq)
    132      1.1  augustss {
    133      1.1  augustss 	union attach_args aa;
    134      1.1  augustss 	int i;
    135      1.9     perry 	pcitag_t tag;
    136      1.1  augustss 	pcireg_t erren;
    137      1.7  augustss 	pcireg_t v;
    138      1.1  augustss 	static struct {
    139      1.1  augustss 		const char *name;
    140      1.1  augustss 		bus_addr_t addr;
    141      1.1  augustss 		int irq;
    142      1.1  augustss 	} devs[] = {
    143      1.2  augustss 		{ "com",    CPC_COM0, CPC_IB_UART_0 },
    144      1.2  augustss 		{ "com",    CPC_COM1, CPC_IB_UART_1 },
    145      1.2  augustss 		{ "cpctim", CPC_TIMER, CPCBUSCF_IRQ_DEFAULT },
    146      1.2  augustss 		{ "cpciic", CPC_IIC0, CPC_IB_IIC_0 },
    147      1.2  augustss 		{ "cpciic", CPC_IIC1, CPC_IB_IIC_1 },
    148      1.1  augustss 		{ NULL, 0 }
    149      1.1  augustss 	};
    150      1.1  augustss #if NPCI > 0 && defined(PCI_NETBSD_CONFIGURE)
    151      1.1  augustss 	struct extent *ioext, *memext;
    152      1.1  augustss #ifdef PCI_CONFIGURE_VERBOSE
    153      1.1  augustss 	extern int pci_conf_debug;
    154      1.1  augustss 
    155      1.1  augustss 	pci_conf_debug = 1;
    156      1.1  augustss #endif
    157      1.1  augustss #endif
    158      1.1  augustss 
    159      1.1  augustss 	printf(": IBM CPC700\n");
    160      1.1  augustss 
    161      1.1  augustss 	the_cpc_tag = mem;
    162      1.1  augustss 	if (bus_space_map(mem, CPC_UIC_BASE, CPC_UIC_SIZE, 0,
    163      1.1  augustss 			  &the_cpc_handle)) {
    164      1.1  augustss 		printf("%s: can't map i/o space\n", self->dv_xname);
    165      1.1  augustss 		return;
    166      1.1  augustss 	}
    167      1.1  augustss 
    168      1.1  augustss 	aa.cba.cpca_tag = mem;
    169      1.1  augustss 	aa.cba.cpca_freq = freq;
    170      1.1  augustss 	for (i = 0; devs[i].name; i++) {
    171      1.1  augustss 		aa.cba.cpca_name = devs[i].name;
    172      1.1  augustss 		aa.cba.cpca_addr = devs[i].addr;
    173      1.1  augustss 		aa.cba.cpca_irq = devs[i].irq;
    174      1.8  drochner 		config_found_sm_loc(self, "cpcbus", NULL, &aa.cba,
    175      1.8  drochner 				    cpc_print, cpc_submatch);
    176      1.1  augustss 	}
    177      1.1  augustss 
    178      1.1  augustss 	tag = pci_make_tag(pc, 0, 0, 0);
    179      1.1  augustss 
    180      1.1  augustss 	aa.pba.pba_iot = pciio;
    181      1.1  augustss 	aa.pba.pba_memt = mem;
    182      1.1  augustss 	aa.pba.pba_dmat = dma;
    183      1.1  augustss 	aa.pba.pba_pc = 0;
    184      1.1  augustss 	aa.pba.pba_flags = PCI_FLAGS_MEM_ENABLED | PCI_FLAGS_IO_ENABLED;
    185      1.1  augustss 	aa.pba.pba_bus = 0;
    186      1.1  augustss 
    187      1.1  augustss 	/* Save PCI error condition reg. */
    188      1.1  augustss 	erren = pci_conf_read(pc, tag, CPC_PCI_BRDGERR);
    189      1.7  augustss 	/* Don't generate errors during probe. */
    190      1.1  augustss 	pci_conf_write(pc, tag, CPC_PCI_BRDGERR, 0);
    191      1.7  augustss 
    192      1.7  augustss 	/* Program MITL */
    193      1.7  augustss 	v = pci_conf_read(pc, tag, CPC_BRIDGE_OPTIONS2);
    194      1.7  augustss 	v &= ~(CPC_BRIDGE_O2_ILAT_MASK | CPC_BRIDGE_O2_SLAT_MASK);
    195      1.7  augustss 	v |= (CPC_BRIDGE_O2_ILAT_PRIM_ASYNC << CPC_BRIDGE_O2_ILAT_SHIFT) |
    196      1.7  augustss 	  (CPC_BRIDGE_O2_2LAT_PRIM_ASYNC << CPC_BRIDGE_O2_SLAT_SHIFT);
    197      1.7  augustss 	pci_conf_write(pc, tag, CPC_BRIDGE_OPTIONS2, v);
    198      1.1  augustss 
    199      1.1  augustss #if NPCI > 0 && defined(PCI_NETBSD_CONFIGURE)
    200      1.1  augustss 	ioext  = extent_create("pciio",  CPC_PCI_IO_START, CPC_PCI_IO_END,
    201      1.1  augustss 	    M_DEVBUF, NULL, 0, EX_NOWAIT);
    202      1.1  augustss 	memext = extent_create("pcimem", CPC_PCI_MEM_BASE, CPC_PCI_MEM_END,
    203      1.1  augustss 	    M_DEVBUF, NULL, 0, EX_NOWAIT);
    204      1.1  augustss 
    205      1.1  augustss 	pci_configure_bus(0, ioext, memext, NULL, 0, 32);
    206      1.1  augustss 
    207      1.1  augustss 	extent_destroy(ioext);
    208      1.1  augustss 	extent_destroy(memext);
    209      1.1  augustss #endif
    210      1.1  augustss 
    211      1.8  drochner 	config_found_ia(self, "pcibus", &aa.pba, pcibusprint);
    212      1.1  augustss 
    213      1.1  augustss 	/* Restore error triggers, and clear errors */
    214      1.1  augustss 	pci_conf_write(pc, tag, CPC_PCI_BRDGERR, erren | CPC_PCI_CLEARERR);
    215      1.1  augustss }
    216      1.1  augustss 
    217      1.1  augustss /***************************************************************************/
    218      1.1  augustss 
    219      1.1  augustss /*
    220      1.1  augustss  * Interrupt controller.
    221      1.1  augustss  */
    222      1.1  augustss 
    223      1.1  augustss void
    224      1.1  augustss cpc700_init_intr(bus_space_tag_t bt, bus_space_handle_t bh,
    225      1.1  augustss 		 u_int32_t active, u_int32_t level)
    226      1.1  augustss {
    227      1.1  augustss 	/* XXX */
    228      1.1  augustss 	the_cpc_tag = bt;
    229      1.1  augustss 	the_cpc_handle = bh;
    230      1.9     perry 	/*
    231      1.1  augustss 	 * See CPC700 manual for information about what
    232      1.1  augustss 	 * interrupts have which properties.
    233      1.1  augustss 	 */
    234      1.1  augustss 	OUTL(CPC_UIC_SR, 0xffffffff);    /* clear all intrs */
    235      1.1  augustss 	OUTL(CPC_UIC_ER, 0x00000000);    /* disable all intrs */
    236      1.1  augustss 	OUTL(CPC_UIC_CR, 0xffffffff);    /* gen INT not MCP */
    237      1.1  augustss 	OUTL(CPC_UIC_PR, 0xffff8000 | active);    /* 0 = active low */
    238      1.1  augustss 	OUTL(CPC_UIC_TR, 0xc0000000 | level);    /* 0 = level intr */
    239      1.1  augustss 	OUTL(CPC_UIC_VR, CPC_UIC_CVR_PRI); /* intr 0 is highest */
    240      1.1  augustss }
    241      1.1  augustss 
    242      1.1  augustss int
    243      1.1  augustss cpc700_read_irq(void)
    244      1.1  augustss {
    245      1.1  augustss 	int irq;
    246      1.1  augustss 	u_int32_t irqs;
    247      1.1  augustss 
    248      1.1  augustss 	irqs = INL(CPC_UIC_MSR);
    249      1.1  augustss 	for (irq = 0; irq < ICU_LEN; irq++) {
    250      1.1  augustss 		if (irqs & CPC_INTR_MASK(irq))
    251      1.1  augustss 			return (irq);
    252      1.1  augustss 	}
    253      1.1  augustss 	return (-1);
    254      1.1  augustss }
    255      1.1  augustss 
    256      1.1  augustss void
    257      1.1  augustss cpc700_eoi(int irq)
    258      1.1  augustss {
    259      1.1  augustss 	OUTL(CPC_UIC_SR, CPC_INTR_MASK(irq));
    260      1.1  augustss }
    261      1.1  augustss 
    262      1.1  augustss void
    263      1.1  augustss cpc700_disable_irq(int irq)
    264      1.1  augustss {
    265      1.1  augustss 	u_int32_t reg;
    266      1.1  augustss 
    267      1.1  augustss 	reg = INL(CPC_UIC_ER);
    268      1.1  augustss 	reg &= ~CPC_INTR_MASK(irq);
    269      1.1  augustss 	OUTL(CPC_UIC_ER, reg);
    270      1.1  augustss }
    271      1.1  augustss 
    272      1.1  augustss void
    273      1.1  augustss cpc700_enable_irq(int irq)
    274      1.1  augustss {
    275      1.1  augustss 	u_int32_t reg;
    276      1.1  augustss 
    277      1.1  augustss 	reg = INL(CPC_UIC_ER);
    278      1.1  augustss 	reg |= CPC_INTR_MASK(irq);
    279      1.1  augustss 	OUTL(CPC_UIC_ER, reg);
    280      1.1  augustss }
    281