summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRalf Baechle <ralf@linux-mips.org>2001-06-10 16:57:40 +0000
committerRalf Baechle <ralf@linux-mips.org>2001-06-10 16:57:40 +0000
commitaf8dbee9b9ff6357b93e280ab73ed8ab62235561 (patch)
tree525e62ce5e6900258cef534602a147170009e499
parentbab55aba4508695975375a8bedca01bc854d2d25 (diff)
Add support for DDB5477.
-rw-r--r--arch/mips/Makefile11
-rw-r--r--arch/mips/config.in7
-rw-r--r--arch/mips/ddb5xxx/common/Makefile18
-rw-r--r--arch/mips/ddb5xxx/common/irq_cpu.c115
-rw-r--r--arch/mips/ddb5xxx/common/nile4.c135
-rw-r--r--arch/mips/ddb5xxx/common/pci.c179
-rw-r--r--arch/mips/ddb5xxx/common/pci_auto.c396
-rw-r--r--arch/mips/ddb5xxx/common/prom.c58
-rw-r--r--arch/mips/ddb5xxx/common/rtc_ds1386.c267
-rw-r--r--arch/mips/ddb5xxx/ddb5477/Makefile22
-rw-r--r--arch/mips/ddb5xxx/ddb5477/debug.c174
-rw-r--r--arch/mips/ddb5xxx/ddb5477/int-handler.S93
-rw-r--r--arch/mips/ddb5xxx/ddb5477/irq.c193
-rw-r--r--arch/mips/ddb5xxx/ddb5477/irq_5477.c179
-rw-r--r--arch/mips/ddb5xxx/ddb5477/kgdb_io.c142
-rw-r--r--arch/mips/ddb5xxx/ddb5477/pci.c144
-rw-r--r--arch/mips/ddb5xxx/ddb5477/pci_ops.c416
-rw-r--r--arch/mips/ddb5xxx/ddb5477/setup.c251
-rw-r--r--arch/mips/defconfig1
-rw-r--r--arch/mips/defconfig-atlas1
-rw-r--r--arch/mips/defconfig-ddb54761
-rw-r--r--arch/mips/defconfig-ddb5477449
-rw-r--r--arch/mips/defconfig-decstation1
-rw-r--r--arch/mips/defconfig-ev641201
-rw-r--r--arch/mips/defconfig-ev961001
-rw-r--r--arch/mips/defconfig-ip221
-rw-r--r--arch/mips/defconfig-it81721
-rw-r--r--arch/mips/defconfig-malta1
-rw-r--r--arch/mips/defconfig-nino1
-rw-r--r--arch/mips/defconfig-ocelot1
-rw-r--r--arch/mips/defconfig-pb10001
-rw-r--r--arch/mips/defconfig-rm2001
-rw-r--r--arch/mips/kernel/setup.c5
-rw-r--r--drivers/sound/Config.in3
-rw-r--r--drivers/sound/Makefile1
-rw-r--r--drivers/sound/ac97.h2
-rw-r--r--drivers/sound/i810_audio.c6
-rw-r--r--drivers/sound/nec_vrc5477.c2045
-rw-r--r--drivers/sound/via82cxxx_audio.c4
-rw-r--r--include/asm-mips/bootinfo.h3
-rw-r--r--include/asm-mips/ddb5xxx/ddb5477.h221
-rw-r--r--include/asm-mips/ddb5xxx/ddb5xxx.h271
-rw-r--r--include/asm-mips/ddb5xxx/debug.h42
-rw-r--r--include/asm-mips/ddb5xxx/pci.h34
-rw-r--r--include/asm-mips/serial.h15
-rw-r--r--include/asm-mips/time.h3
-rw-r--r--include/linux/ac97_codec.h2
47 files changed, 5908 insertions, 11 deletions
diff --git a/arch/mips/Makefile b/arch/mips/Makefile
index d87b276b1..58549572e 100644
--- a/arch/mips/Makefile
+++ b/arch/mips/Makefile
@@ -177,6 +177,17 @@ LOADADDR += 0x80080000
endif
#
+#
+# NEC DDB Vrc-5477
+#
+ifdef CONFIG_DDB5477
+SUBDIRS += arch/mips/ddb5xxx/common arch/mips/ddb5xxx/ddb5477
+LIBS += arch/mips/ddb5xxx/common/ddb5xxx.o \
+ arch/mips/ddb5xxx/ddb5477/ddb5477.o
+LOADADDR += 0x80080000
+endif
+
+#
# Galileo EV64120 Board
#
ifdef CONFIG_MIPS_EV64120
diff --git a/arch/mips/config.in b/arch/mips/config.in
index 6ff06908c..186d36346 100644
--- a/arch/mips/config.in
+++ b/arch/mips/config.in
@@ -42,6 +42,7 @@ fi
bool 'Support for Mips Magnum 4000' CONFIG_MIPS_MAGNUM_4000
bool 'Support for Momentum Ocelot board' CONFIG_MOMENCO_OCELOT
bool 'Support for NEC DDB Vrc-5476' CONFIG_DDB5476
+bool 'Support for NEC DDB Vrc-5477' CONFIG_DDB5477
bool 'Support for Olivetti M700-10' CONFIG_OLIVETTI_M700
bool 'Support for SGI IP22' CONFIG_SGI_IP22
bool 'Support for SNI RM200 PCI' CONFIG_SNI_RM200_PCI
@@ -171,6 +172,12 @@ if [ "$CONFIG_DDB5476" = "y" ]; then
define_bool CONFIG_HAVE_STD_PC_SERIAL_PORT y
define_bool CONFIG_NEW_TIME_C y
fi
+if [ "$CONFIG_DDB5477" = "y" ]; then
+ define_bool CONFIG_CPU_LITTLE_ENDIAN y
+ define_bool CONFIG_PCI y
+ define_bool CONFIG_NEW_TIME_C y
+ define_bool CONFIG_NEW_IRQ y
+fi
if [ "$CONFIG_MIPS_ITE8172" = "y" ]; then
define_bool CONFIG_PCI y
define_bool CONFIG_IT8712 y
diff --git a/arch/mips/ddb5xxx/common/Makefile b/arch/mips/ddb5xxx/common/Makefile
new file mode 100644
index 000000000..fc625d7dd
--- /dev/null
+++ b/arch/mips/ddb5xxx/common/Makefile
@@ -0,0 +1,18 @@
+#
+# Makefile for the common code of NEC DDB-Vrc5xxx board
+#
+# Note! Dependencies are done automagically by 'make dep', which also
+# removes any old dependencies. DON'T put your own dependencies here
+# unless it's something special (ie not a .c file).
+#
+
+.S.s:
+ $(CPP) $(CFLAGS) $< -o $*.s
+.S.o:
+ $(CC) $(CFLAGS) -c $< -o $*.o
+
+O_TARGET:= ddb5xxx.o
+
+obj-y += irq_cpu.o nile4.o prom.o pci.o pci_auto.o rtc_ds1386.o
+
+include $(TOPDIR)/Rules.make
diff --git a/arch/mips/ddb5xxx/common/irq_cpu.c b/arch/mips/ddb5xxx/common/irq_cpu.c
new file mode 100644
index 000000000..7776ef181
--- /dev/null
+++ b/arch/mips/ddb5xxx/common/irq_cpu.c
@@ -0,0 +1,115 @@
+/***********************************************************************
+ * Copyright 2001 MontaVista Software Inc.
+ * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
+ *
+ * arch/mips/ddb5xxx/common/irq_cpu.c
+ * This file define the irq handler for MIPS CPU interrupts.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ ***********************************************************************
+ */
+
+/*
+ * Almost all MIPS CPUs define 8 interrupt sources. They are typically
+ * level triggered (i.e., cannot be cleared from CPU; must be cleared from
+ * device). The first two are software interrupts. The last one is
+ * usually cpu timer interrupt if coutner register is present.
+ *
+ * This file exports one global function:
+ * mips_cpu_irq_init(u32 irq_base);
+ */
+
+#include <linux/irq.h>
+#include <linux/types.h>
+#include <linux/kernel.h>
+
+#include <asm/mipsregs.h>
+
+/* [jsun] sooner or later we should move this debug stuff to MIPS common */
+#include <asm/ddb5xxx/debug.h>
+
+static int mips_cpu_irq_base=-1;
+
+static void
+mips_cpu_irq_enable(unsigned int irq)
+{
+ MIPS_ASSERT(mips_cpu_irq_base != -1);
+ MIPS_ASSERT(irq >= mips_cpu_irq_base);
+ MIPS_ASSERT(irq < mips_cpu_irq_base+8);
+
+ clear_cp0_cause( 1 << (irq - mips_cpu_irq_base + 8));
+ set_cp0_status(1 << (irq - mips_cpu_irq_base + 8));
+}
+
+static void
+mips_cpu_irq_disable(unsigned int irq)
+{
+ MIPS_ASSERT(mips_cpu_irq_base != -1);
+ MIPS_ASSERT(irq >= mips_cpu_irq_base);
+ MIPS_ASSERT(irq < mips_cpu_irq_base+8);
+
+ clear_cp0_status(1 << (irq - mips_cpu_irq_base + 8));
+}
+
+static unsigned int mips_cpu_irq_startup(unsigned int irq)
+{
+ mips_cpu_irq_enable(irq);
+ return 0;
+}
+
+#define mips_cpu_irq_shutdown mips_cpu_irq_disable
+
+static void
+mips_cpu_irq_ack(unsigned int irq)
+{
+ MIPS_ASSERT(mips_cpu_irq_base != -1);
+ MIPS_ASSERT(irq >= mips_cpu_irq_base);
+ MIPS_ASSERT(irq < mips_cpu_irq_base+8);
+
+ /* although we attemp to clear the IP bit in cause reigster, I think
+ * usually it is cleared by device (irq source)
+ */
+ clear_cp0_cause( 1 << (irq - mips_cpu_irq_base + 8));
+
+ /* I am not fully convinced that I should disable irq here */
+}
+
+static void
+mips_cpu_irq_end(unsigned int irq)
+{
+ MIPS_ASSERT(mips_cpu_irq_base != -1);
+ MIPS_ASSERT(irq >= mips_cpu_irq_base);
+ MIPS_ASSERT(irq < mips_cpu_irq_base+8);
+ /* I am not fully convinced that I should enable irq here */
+}
+
+static hw_irq_controller mips_cpu_irq_controller = {
+ "CPU_irq",
+ mips_cpu_irq_startup,
+ mips_cpu_irq_shutdown,
+ mips_cpu_irq_enable,
+ mips_cpu_irq_disable,
+ mips_cpu_irq_ack,
+ mips_cpu_irq_end,
+ NULL /* no affinity stuff for UP */
+};
+
+
+void
+mips_cpu_irq_init(u32 irq_base)
+{
+ extern irq_desc_t irq_desc[];
+ u32 i;
+
+ for (i= irq_base; i< irq_base+8; i++) {
+ irq_desc[i].status = IRQ_DISABLED;
+ irq_desc[i].action = NULL;
+ irq_desc[i].depth = 1;
+ irq_desc[i].handler = &mips_cpu_irq_controller;
+ }
+
+ mips_cpu_irq_base = irq_base;
+}
diff --git a/arch/mips/ddb5xxx/common/nile4.c b/arch/mips/ddb5xxx/common/nile4.c
new file mode 100644
index 000000000..e8a8d013b
--- /dev/null
+++ b/arch/mips/ddb5xxx/common/nile4.c
@@ -0,0 +1,135 @@
+/***********************************************************************
+ *
+ * Copyright 2001 MontaVista Software Inc.
+ * Author: jsun@mvista.com or jsun@junsun.net
+ *
+ * arch/mips/ddb5xxx/common/nile4.c
+ * misc low-level routines for vrc-5xxx controllers.
+ *
+ * derived from original code by Geert Uytterhoeven <geert@sonycom.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ ***********************************************************************
+ */
+
+#include <linux/config.h>
+#include <linux/types.h>
+#include <linux/kernel.h>
+
+#include <asm/ddb5xxx/ddb5xxx.h>
+#include <asm/ddb5xxx/debug.h>
+
+u32
+ddb_calc_pdar(u32 phys, u32 size, int width,
+ int on_memory_bus, int pci_visible)
+{
+ u32 maskbits;
+ u32 widthbits;
+
+ switch (size) {
+#if 0 /* We don't support 4 GB yet */
+ case 0x100000000: /* 4 GB */
+ maskbits = 4;
+ break;
+#endif
+ case 0x80000000: /* 2 GB */
+ maskbits = 5;
+ break;
+ case 0x40000000: /* 1 GB */
+ maskbits = 6;
+ break;
+ case 0x20000000: /* 512 MB */
+ maskbits = 7;
+ break;
+ case 0x10000000: /* 256 MB */
+ maskbits = 8;
+ break;
+ case 0x08000000: /* 128 MB */
+ maskbits = 9;
+ break;
+ case 0x04000000: /* 64 MB */
+ maskbits = 10;
+ break;
+ case 0x02000000: /* 32 MB */
+ maskbits = 11;
+ break;
+ case 0x01000000: /* 16 MB */
+ maskbits = 12;
+ break;
+ case 0x00800000: /* 8 MB */
+ maskbits = 13;
+ break;
+ case 0x00400000: /* 4 MB */
+ maskbits = 14;
+ break;
+ case 0x00200000: /* 2 MB */
+ maskbits = 15;
+ break;
+ case 0: /* OFF */
+ maskbits = 0;
+ break;
+ default:
+ panic("nile4_set_pdar: unsupported size %p\n", (void *) size);
+ }
+ switch (width) {
+ case 8:
+ widthbits = 0;
+ break;
+ case 16:
+ widthbits = 1;
+ break;
+ case 32:
+ widthbits = 2;
+ break;
+ case 64:
+ widthbits = 3;
+ break;
+ default:
+ panic("nile4_set_pdar: unsupported width %d\n", width);
+ }
+
+ return maskbits | (on_memory_bus ? 0x10 : 0) |
+ (pci_visible ? 0x20 : 0) | (widthbits << 6) |
+ (phys & 0xffe00000);
+}
+
+void
+ddb_set_pdar(u32 pdar, u32 phys, u32 size, int width,
+ int on_memory_bus, int pci_visible)
+{
+ u32 temp= ddb_calc_pdar(phys, size, width, on_memory_bus, pci_visible);
+ ddb_out32(pdar, temp);
+ ddb_out32(pdar + 4, 0);
+
+ /*
+ * When programming a PDAR, the register should be read immediately
+ * after writing it. This ensures that address decoders are properly
+ * configured.
+ * [jsun] is this really necesary?
+ */
+ ddb_in32(pdar);
+ ddb_in32(pdar + 4);
+}
+
+/*
+ * routines that mess with PCIINITx registers
+ */
+
+void ddb_set_pmr(u32 pmr, u32 type, u32 addr, u32 options)
+{
+ switch (type) {
+ case DDB_PCICMD_IACK: /* PCI Interrupt Acknowledge */
+ case DDB_PCICMD_IO: /* PCI I/O Space */
+ case DDB_PCICMD_MEM: /* PCI Memory Space */
+ case DDB_PCICMD_CFG: /* PCI Configuration Space */
+ break;
+ default:
+ panic("nile4_set_pmr: invalid type %d\n", type);
+ }
+ ddb_out32(pmr, (type << 1) | (addr & 0xffe00000) | options );
+ ddb_out32(pmr + 4, 0);
+}
diff --git a/arch/mips/ddb5xxx/common/pci.c b/arch/mips/ddb5xxx/common/pci.c
new file mode 100644
index 000000000..33cc327d8
--- /dev/null
+++ b/arch/mips/ddb5xxx/common/pci.c
@@ -0,0 +1,179 @@
+/***********************************************************************
+ * Copyright 2001 MontaVista Software Inc.
+ * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
+ *
+ * arch/mips/ddb5xxx/common/pci.c
+ * Common PCI routines for DDB5xxx - as a matter of fact, meant for all
+ * MIPS machines.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ ***********************************************************************
+ */
+
+/*
+ * This file contains common PCI routines meant to be shared for
+ * all MIPS machines.
+ *
+ * Strategies:
+ *
+ * . We rely on pci_auto.c file to assign PCI resources (MEM and IO)
+ * TODO: this shold be optional for some machines where they do have
+ * a real "pcibios" that does resource assignment.
+ *
+ * . We then use pci_scan_bus() to "discover" all the resources for
+ * later use by Linux.
+ *
+ * . We finally reply on a board supplied function, pcibios_fixup_irq(), to
+ * to assign the interrupts. We may use setup-irq.c under drivers/pci
+ * later.
+ *
+ * . Specifically, we will *NOT* use pci_assign_unassigned_resources(),
+ * because we assume all PCI devices should have the resources correctly
+ * assigned and recorded.
+ *
+ * Limitations:
+ *
+ * . We "collapse" all IO and MEM spaces in sub-buses under a top-level bus
+ * into a contiguous range.
+ *
+ * . In the case of Memory space, the rnage is 1:1 mapping with CPU physical
+ * address space.
+ *
+ * . In the case of IO space, it starts from 0, and the beginning address
+ * is mapped to KSEG0ADDR(mips_io_port) in the CPU physical address.
+ *
+ * . These are the current MIPS limitations (by ioremap, etc). In the
+ * future, we may remove them.
+ *
+ * Credits:
+ * Most of the code are derived from the pci routines from PPC and Alpha,
+ * which were mostly writtne by
+ * Cort Dougan, cort@fsmlabs.com
+ * Matt Porter, mporter@mvista.com
+ * Dave Rusling david.rusling@reo.mts.dec.com
+ * David Mosberger davidm@cs.arizona.edu
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/types.h>
+#include <linux/pci.h>
+
+#include <asm/ddb5xxx/pci.h>
+#include <asm/ddb5xxx/debug.h>
+
+
+struct pci_fixup pcibios_fixups[] = { {0} };
+
+
+extern int pciauto_assign_resources(int busno, struct pci_channel * hose);
+void __init pcibios_init(void)
+{
+ struct pci_channel *p;
+ struct pci_bus *bus;
+ int busno;
+
+ /* assign resources */
+ busno=0;
+ for (p= mips_pci_channels; p->pci_ops != NULL; p++) {
+ busno = pciauto_assign_resources(busno, p) + 1;
+ }
+
+ /* scan the buses */
+ busno = 0;
+ for (p= mips_pci_channels; p->pci_ops != NULL; p++) {
+ bus = pci_scan_bus(busno, p->pci_ops, p);
+ busno = bus->subordinate+1;
+ }
+
+ /* fixup irqs (board specific routines) */
+ pcibios_fixup_irqs();
+
+ /*
+ * should we do a fixup of ioport_resource and iomem_resource
+ * based on mips_pci_channels?
+ * Let us wait and see if this is a common need and whether there
+ * are exceptions. Until then, each board should adjust them
+ * perhaps in their setup() function.
+ */
+}
+
+int pcibios_enable_device(struct pci_dev *dev)
+{
+ /* pciauto_assign_resources() will enable all devices found */
+ return 0;
+}
+
+unsigned long __init
+pci_bridge_check_io(struct pci_dev *bridge)
+{
+ u16 io;
+
+ pci_read_config_word(bridge, PCI_IO_BASE, &io);
+ if (!io) {
+ pci_write_config_word(bridge, PCI_IO_BASE, 0xf0f0);
+ pci_read_config_word(bridge, PCI_IO_BASE, &io);
+ pci_write_config_word(bridge, PCI_IO_BASE, 0x0);
+ }
+ if (io)
+ return IORESOURCE_IO;
+ printk(KERN_WARNING "PCI: bridge %s does not support I/O forwarding!\n",
+ bridge->name);
+ return 0;
+}
+
+void __init pcibios_fixup_bus(struct pci_bus *bus)
+{
+ /* Propogate hose info into the subordinate devices. */
+
+ struct pci_channel *hose = bus->sysdata;
+ struct pci_dev *dev = bus->self;
+
+ if (!dev) {
+ /* Root bus */
+ bus->resource[0] = hose->io_resource;
+ bus->resource[1] = hose->mem_resource;
+ } else {
+ /* This is a bridge. Do not care how it's initialized,
+ just link its resources to the bus ones */
+ int i;
+
+ for(i=0; i<3; i++) {
+ bus->resource[i] =
+ &dev->resource[PCI_BRIDGE_RESOURCES+i];
+ bus->resource[i]->name = bus->name;
+ }
+ bus->resource[0]->flags |= pci_bridge_check_io(dev);
+ bus->resource[1]->flags |= IORESOURCE_MEM;
+ /* For now, propogate hose limits to the bus;
+ we'll adjust them later. */
+ bus->resource[0]->end = hose->io_resource->end;
+ bus->resource[1]->end = hose->mem_resource->end;
+ /* Turn off downstream PF memory address range by default */
+ bus->resource[2]->start = 1024*1024;
+ bus->resource[2]->end = bus->resource[2]->start - 1;
+ }
+}
+
+char *pcibios_setup(char *str)
+{
+ return str;
+}
+
+void
+pcibios_align_resource(void *data, struct resource *res, unsigned long size)
+{
+ /* this should not be called */
+ MIPS_ASSERT(1 == 0);
+}
+
+void
+pcibios_update_resource(struct pci_dev *dev, struct resource *root,
+ struct resource *res, int resource)
+{
+ /* this should not be called */
+ MIPS_ASSERT(1 == 0);
+}
diff --git a/arch/mips/ddb5xxx/common/pci_auto.c b/arch/mips/ddb5xxx/common/pci_auto.c
new file mode 100644
index 000000000..b6e751332
--- /dev/null
+++ b/arch/mips/ddb5xxx/common/pci_auto.c
@@ -0,0 +1,396 @@
+/*
+ * arch/ppc/kernel/pci_auto.c
+ *
+ * PCI autoconfiguration library
+ *
+ * Author: Matt Porter <mporter@mvista.com>
+ *
+ * Copyright 2000, 2001 MontaVista Software Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ */
+
+/*
+ * Modified for MIPS by Jun Sun, jsun@mvista.com
+ *
+ * . Simplify the interface between pci_auto and the rest: a single function.
+ * . Assign resources from low address to upper address.
+ * . change most int to u32.
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/types.h>
+#include <linux/pci.h>
+
+#include <asm/ddb5xxx/pci.h>
+#include <asm/ddb5xxx/debug.h>
+
+#define DEBUG
+#ifdef DEBUG
+#define DBG(x...) printk(x)
+#else
+#define DBG(x...)
+#endif
+
+/* These are used for config access before all the PCI probing
+ has been done. */
+int early_read_config_byte(struct pci_channel *hose, int bus, int dev_fn, int where, u8 *val);
+int early_read_config_word(struct pci_channel *hose, int bus, int dev_fn, int where, u16 *val);
+int early_read_config_dword(struct pci_channel *hose, int bus, int dev_fn, int where, u32 *val);
+int early_write_config_byte(struct pci_channel *hose, int bus, int dev_fn, int where, u8 val);
+int early_write_config_word(struct pci_channel *hose, int bus, int dev_fn, int where, u16 val);
+int early_write_config_dword(struct pci_channel *hose, int bus, int dev_fn, int where, u32 val);
+
+static u32 pciauto_lower_iospc;
+static u32 pciauto_upper_iospc;
+
+static u32 pciauto_lower_memspc;
+static u32 pciauto_upper_memspc;
+
+void __init
+pciauto_setup_bars(struct pci_channel *hose,
+ int current_bus,
+ int pci_devfn)
+{
+ u32 bar_response, bar_size, bar_value;
+ u32 bar, addr_mask, bar_nr = 0;
+ u32 * upper_limit;
+ u32 * lower_limit;
+ int found_mem64 = 0;
+
+ DBG("PCI Autoconfig: Found Bus %d, Device %d, Function %d\n",
+ current_bus, PCI_SLOT(pci_devfn), PCI_FUNC(pci_devfn) );
+
+ for (bar = PCI_BASE_ADDRESS_0; bar <= PCI_BASE_ADDRESS_5; bar+=4)
+ {
+ /* Tickle the BAR and get the response */
+ early_write_config_dword(hose,
+ current_bus,
+ pci_devfn,
+ bar,
+ 0xffffffff);
+ early_read_config_dword(hose,
+ current_bus,
+ pci_devfn,
+ bar,
+ &bar_response);
+
+ /* If BAR is not implemented go to the next BAR */
+ if (!bar_response)
+ continue;
+
+ /* Check the BAR type and set our address mask */
+ if (bar_response & PCI_BASE_ADDRESS_SPACE)
+ {
+ addr_mask = PCI_BASE_ADDRESS_IO_MASK;
+ upper_limit = &pciauto_upper_iospc;
+ lower_limit = &pciauto_lower_iospc;
+ DBG("PCI Autoconfig: BAR %d, I/O, ", bar_nr);
+ }
+ else
+ {
+ if ( (bar_response & PCI_BASE_ADDRESS_MEM_TYPE_MASK) ==
+ PCI_BASE_ADDRESS_MEM_TYPE_64)
+ found_mem64 = 1;
+
+ addr_mask = PCI_BASE_ADDRESS_MEM_MASK;
+ upper_limit = &pciauto_upper_memspc;
+ lower_limit = &pciauto_lower_memspc;
+ DBG("PCI Autoconfig: BAR %d, Mem, ", bar_nr);
+ }
+
+ /* Calculate requested size */
+ bar_size = ~(bar_response & addr_mask) + 1;
+
+ /* Allocate a base address */
+ bar_value = ((*lower_limit - 1) & ~(bar_size - 1)) + bar_size;
+ MIPS_ASSERT(bar_value + bar_size <= *upper_limit);
+
+ /* Write it out and update our limit */
+ early_write_config_dword(hose,
+ current_bus,
+ pci_devfn,
+ bar,
+ bar_value);
+
+ *lower_limit = bar_value + bar_size;
+
+ /*
+ * If we are a 64-bit decoder then increment to the
+ * upper 32 bits of the bar and force it to locate
+ * in the lower 4GB of memory.
+ */
+ if (found_mem64)
+ {
+ bar += 4;
+ early_write_config_dword(hose,
+ current_bus,
+ pci_devfn,
+ bar,
+ 0x00000000);
+ }
+
+ bar_nr++;
+
+ DBG("size=0x%x, address=0x%x\n",
+ bar_size, bar_value);
+ }
+
+}
+
+void __init
+pciauto_prescan_setup_bridge(struct pci_channel *hose,
+ int current_bus,
+ int pci_devfn,
+ int sub_bus)
+{
+ int cmdstat;
+
+ /* Configure bus number registers */
+ early_write_config_byte(hose,
+ current_bus,
+ pci_devfn,
+ PCI_PRIMARY_BUS,
+ current_bus);
+ early_write_config_byte(hose,
+ current_bus,
+ pci_devfn,
+ PCI_SECONDARY_BUS,
+ sub_bus + 1);
+ early_write_config_byte(hose,
+ current_bus,
+ pci_devfn,
+ PCI_SUBORDINATE_BUS,
+ 0xff);
+
+ /* Round memory allocator to 1MB boundary */
+ pciauto_upper_memspc &= ~(0x100000 - 1);
+
+ /* Round I/O allocator to 4KB boundary */
+ pciauto_upper_iospc &= ~(0x1000 - 1);
+
+ /* Set up memory and I/O filter limits, assume 32-bit I/O space */
+ early_write_config_word(hose,
+ current_bus,
+ pci_devfn,
+ PCI_MEMORY_LIMIT,
+ ((pciauto_upper_memspc - 1) & 0xfff00000) >> 16);
+ early_write_config_byte(hose,
+ current_bus,
+ pci_devfn,
+ PCI_IO_LIMIT,
+ ((pciauto_upper_iospc - 1) & 0x0000f000) >> 8);
+ early_write_config_word(hose,
+ current_bus,
+ pci_devfn,
+ PCI_IO_LIMIT_UPPER16,
+ ((pciauto_upper_iospc - 1) & 0xffff0000) >> 16);
+
+ /* We don't support prefetchable memory for now, so disable */
+ early_write_config_word(hose,
+ current_bus,
+ pci_devfn,
+ PCI_PREF_MEMORY_BASE,
+ 0x1000);
+ early_write_config_word(hose,
+ current_bus,
+ pci_devfn,
+ PCI_PREF_MEMORY_LIMIT,
+ 0x1000);
+
+ /* Enable memory and I/O accesses, enable bus master */
+ early_read_config_dword(hose,
+ current_bus,
+ pci_devfn,
+ PCI_COMMAND,
+ &cmdstat);
+ early_write_config_dword(hose,
+ current_bus,
+ pci_devfn,
+ PCI_COMMAND,
+ cmdstat |
+ PCI_COMMAND_IO |
+ PCI_COMMAND_MEMORY |
+ PCI_COMMAND_MASTER);
+}
+
+void __init
+pciauto_postscan_setup_bridge(struct pci_channel *hose,
+ int current_bus,
+ int pci_devfn,
+ int sub_bus)
+{
+ /* Configure bus number registers */
+ early_write_config_byte(hose,
+ current_bus,
+ pci_devfn,
+ PCI_SUBORDINATE_BUS,
+ sub_bus);
+
+ /* Round memory allocator to 1MB boundary */
+ pciauto_upper_memspc &= ~(0x100000 - 1);
+ early_write_config_word(hose,
+ current_bus,
+ pci_devfn,
+ PCI_MEMORY_BASE,
+ pciauto_upper_memspc >> 16);
+
+ /* Round I/O allocator to 4KB boundary */
+ pciauto_upper_iospc &= ~(0x1000 - 1);
+ early_write_config_byte(hose,
+ current_bus,
+ pci_devfn,
+ PCI_IO_BASE,
+ (pciauto_upper_iospc & 0x0000f000) >> 8);
+ early_write_config_word(hose,
+ current_bus,
+ pci_devfn,
+ PCI_IO_BASE_UPPER16,
+ pciauto_upper_iospc >> 16);
+}
+
+#define PCIAUTO_IDE_MODE_MASK 0x05
+
+int __init
+pciauto_bus_scan(struct pci_channel *hose, int current_bus)
+{
+ int sub_bus;
+ u32 pci_devfn, pci_class, cmdstat, found_multi=0;
+ unsigned short vid;
+ unsigned char header_type;
+
+ sub_bus = current_bus;
+
+ for (pci_devfn=0; pci_devfn<0xff; pci_devfn++) {
+
+ if (PCI_FUNC(pci_devfn) && !found_multi)
+ continue;
+
+ early_read_config_byte(hose,
+ current_bus,
+ pci_devfn,
+ PCI_HEADER_TYPE,
+ &header_type);
+
+ if (!PCI_FUNC(pci_devfn))
+ found_multi = header_type & 0x80;
+
+ early_read_config_word(hose,
+ current_bus,
+ pci_devfn,
+ PCI_VENDOR_ID,
+ &vid);
+
+ if (vid == 0xffff) continue;
+
+ early_read_config_dword(hose,
+ current_bus,
+ pci_devfn,
+ PCI_CLASS_REVISION, &pci_class);
+ if ( (pci_class >> 16) == PCI_CLASS_BRIDGE_PCI ) {
+ DBG("PCI Autoconfig: Found P2P bridge, device %d\n", PCI_SLOT(pci_devfn));
+ pciauto_prescan_setup_bridge(hose,
+ current_bus,
+ pci_devfn,
+ sub_bus);
+ sub_bus = pciauto_bus_scan(hose, sub_bus+1);
+ pciauto_postscan_setup_bridge(hose,
+ current_bus,
+ pci_devfn,
+ sub_bus);
+
+ } else if ((pci_class >> 16) == PCI_CLASS_STORAGE_IDE) {
+
+ unsigned char prg_iface;
+
+ early_read_config_byte(hose,
+ current_bus,
+ pci_devfn,
+ PCI_CLASS_PROG,
+ &prg_iface);
+ if (!(prg_iface & PCIAUTO_IDE_MODE_MASK)) {
+ DBG("PCI Autoconfig: Skipping legacy mode IDE controller\n");
+ continue;
+ }
+ }
+
+ /*
+ * Found a peripheral, enable some standard
+ * settings
+ */
+ early_read_config_dword(hose,
+ current_bus,
+ pci_devfn,
+ PCI_COMMAND,
+ &cmdstat);
+ early_write_config_dword(hose,
+ current_bus,
+ pci_devfn,
+ PCI_COMMAND,
+ cmdstat |
+ PCI_COMMAND_IO |
+ PCI_COMMAND_MEMORY |
+ PCI_COMMAND_MASTER);
+ early_write_config_byte(hose,
+ current_bus,
+ pci_devfn,
+ PCI_LATENCY_TIMER,
+ 0x80);
+
+ /* Allocate PCI I/O and/or memory space */
+ pciauto_setup_bars(hose,
+ current_bus,
+ pci_devfn);
+ }
+ return sub_bus;
+}
+
+int __init
+pciauto_assign_resources(int busno, struct pci_channel *hose)
+{
+ /* setup resource limits */
+ pciauto_lower_iospc = hose->io_resource->start;
+ pciauto_upper_iospc = hose->io_resource->end + 1;
+ pciauto_lower_memspc = hose->mem_resource->start;
+ pciauto_upper_memspc = hose->mem_resource->end + 1;
+
+ return pciauto_bus_scan(hose, busno);
+}
+
+
+/*
+ * These functions are used early on before PCI scanning is done
+ * and all of the pci_dev and pci_bus structures have been created.
+ */
+static struct pci_dev *
+fake_pci_dev(struct pci_channel *hose, int busnr, int devfn)
+{
+ static struct pci_dev dev;
+ static struct pci_bus bus;
+
+ dev.bus = &bus;
+ dev.sysdata = hose;
+ dev.devfn = devfn;
+ bus.number = busnr;
+ bus.ops = hose->pci_ops;
+ return &dev;
+}
+
+#define EARLY_PCI_OP(rw, size, type) \
+int early_##rw##_config_##size(struct pci_channel *hose, int bus, \
+ int devfn, int offset, type value) \
+{ \
+ return pci_##rw##_config_##size(fake_pci_dev(hose, bus, devfn), \
+ offset, value); \
+}
+
+EARLY_PCI_OP(read, byte, u8 *)
+EARLY_PCI_OP(read, word, u16 *)
+EARLY_PCI_OP(read, dword, u32 *)
+EARLY_PCI_OP(write, byte, u8)
+EARLY_PCI_OP(write, word, u16)
+EARLY_PCI_OP(write, dword, u32)
diff --git a/arch/mips/ddb5xxx/common/prom.c b/arch/mips/ddb5xxx/common/prom.c
new file mode 100644
index 000000000..9333b5278
--- /dev/null
+++ b/arch/mips/ddb5xxx/common/prom.c
@@ -0,0 +1,58 @@
+/***********************************************************************
+ *
+ * Copyright 2001 MontaVista Software Inc.
+ * Author: jsun@mvista.com or jsun@junsun.net
+ *
+ * arch/mips/ddb5xxx/common/prom.c
+ * prom.c file.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ ***********************************************************************
+ */
+#include <linux/config.h>
+#include <linux/init.h>
+#include <linux/mm.h>
+#include <linux/sched.h>
+#include <linux/bootmem.h>
+
+#include <asm/addrspace.h>
+#include <asm/bootinfo.h>
+#include <asm/ddb5xxx/ddb5xxx.h>
+
+char arcs_cmdline[COMMAND_LINE_SIZE];
+
+/* [jsun@junsun.net] PMON passes arguments in C main() style */
+void __init prom_init(int argc, const char **arg)
+{
+ int i;
+
+ /* arg[0] is "g", the rest is boot parameters */
+ arcs_cmdline[0] = '\0';
+ for (i = 1; i < argc; i++) {
+ if (strlen(arcs_cmdline) + strlen(arg[i] + 1)
+ >= sizeof(arcs_cmdline))
+ break;
+ strcat(arcs_cmdline, arg[i]);
+ strcat(arcs_cmdline, " ");
+ }
+
+ mips_machgroup = MACH_GROUP_NEC_DDB;
+
+#if defined(CONFIG_DDB5074)
+ mips_machtype = MACH_NEC_DDB5074;
+#elif defined(CONFIG_DDB5476)
+ mips_machtype = MACH_NEC_DDB5476;
+#elif defined(CONFIG_DDB5477)
+ mips_machtype = MACH_NEC_DDB5477;
+#endif
+
+ add_memory_region(0, DDB_SDRAM_SIZE, BOOT_MEM_RAM);
+}
+
+void __init prom_free_prom_memory(void)
+{
+}
diff --git a/arch/mips/ddb5xxx/common/rtc_ds1386.c b/arch/mips/ddb5xxx/common/rtc_ds1386.c
new file mode 100644
index 000000000..ff1d81c60
--- /dev/null
+++ b/arch/mips/ddb5xxx/common/rtc_ds1386.c
@@ -0,0 +1,267 @@
+/***********************************************************************
+ *
+ * Copyright 2001 MontaVista Software Inc.
+ * Author: jsun@mvista.com or jsun@junsun.net
+ *
+ * arch/mips/ddb5xxx/common/rtc_ds1386.c
+ * low-level RTC hookups for s for Dallas 1396 chip.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ ***********************************************************************
+ */
+
+
+/*
+ * This file exports a function, rtc_ds1386_init(), which expects an
+ * uncached base address as the argument. It will set the two function
+ * pointers expected by the MIPS generic timer code.
+ */
+
+#include <linux/types.h>
+#include <linux/time.h>
+#include <linux/rtc.h>
+
+#include <asm/time.h>
+#include <asm/addrspace.h>
+
+#include <asm/ddb5xxx/debug.h>
+
+#define EPOCH 2000
+
+#undef BCD_TO_BIN
+#define BCD_TO_BIN(val) (((val)&15) + ((val)>>4)*10)
+
+#undef BIN_TO_BCD
+#define BIN_TO_BCD(val) ((((val)/10)<<4) + (val)%10)
+
+#define READ_RTC(x) *(volatile unsigned char*)(rtc_base+x)
+#define WRITE_RTC(x, y) *(volatile unsigned char*)(rtc_base+x) = y
+
+static unsigned long rtc_base;
+
+static unsigned long
+rtc_ds1386_get_time(void)
+{
+ u8 byte;
+ u8 temp;
+ unsigned int year, month, day, hour, minute, second;
+
+ /* let us freeze external registers */
+ byte = READ_RTC(0xB);
+ byte &= 0x3f;
+ WRITE_RTC(0xB, byte);
+
+ /* read time data */
+ year = BCD_TO_BIN(READ_RTC(0xA)) + EPOCH;
+ month = BCD_TO_BIN(READ_RTC(0x9) & 0x1f);
+ day = BCD_TO_BIN(READ_RTC(0x8));
+ minute = BCD_TO_BIN(READ_RTC(0x2));
+ second = BCD_TO_BIN(READ_RTC(0x1));
+
+ /* hour is special - deal with it later */
+ temp = READ_RTC(0x4);
+
+ /* enable time transfer */
+ byte |= 0x80;
+ WRITE_RTC(0xB, byte);
+
+ /* calc hour */
+ if (temp & 0x40) {
+ /* 12 hour format */
+ hour = BCD_TO_BIN(temp & 0x1f);
+ if (temp & 0x20) hour += 12; /* PM */
+ } else {
+ /* 24 hour format */
+ hour = BCD_TO_BIN(temp & 0x3f);
+ }
+
+ return mktime(year, month, day, hour, minute, second);
+}
+
+void to_tm(unsigned long tim, struct rtc_time * tm);
+static int
+rtc_ds1386_set_time(unsigned long t)
+{
+ struct rtc_time tm;
+ u8 byte;
+ u8 temp;
+ u8 year, month, day, hour, minute, second;
+
+ /* let us freeze external registers */
+ byte = READ_RTC(0xB);
+ byte &= 0x3f;
+ WRITE_RTC(0xB, byte);
+
+ /* convert */
+ to_tm(t, &tm);
+
+ /* check each field one by one */
+ year = BIN_TO_BCD(tm.tm_year - EPOCH);
+ if (year != READ_RTC(0xA)) {
+ WRITE_RTC(0xA, year);
+ }
+
+ temp = READ_RTC(0x9);
+ month = BIN_TO_BCD(tm.tm_mon);
+ if (month != (temp & 0x1f)) {
+ WRITE_RTC( 0x9,
+ (month & 0x1f) | (temp & ~0x1f) );
+ }
+
+ day = BIN_TO_BCD(tm.tm_mday);
+ if (day != READ_RTC(0x8)) {
+ WRITE_RTC(0x8, day);
+ }
+
+ temp = READ_RTC(0x4);
+ if (temp & 0x40) {
+ /* 12 hour format */
+ hour = 0x40;
+ if (tm.tm_hour > 12) {
+ hour |= 0x20 | (BIN_TO_BCD(hour-12) & 0x1f);
+ } else {
+ hour |= BIN_TO_BCD(tm.tm_hour);
+ }
+ } else {
+ /* 24 hour format */
+ hour = BIN_TO_BCD(tm.tm_hour) & 0x3f;
+ }
+ if (hour != temp) WRITE_RTC(0x4, hour);
+
+ minute = BIN_TO_BCD(tm.tm_min);
+ if (minute != READ_RTC(0x2)) {
+ WRITE_RTC(0x2, minute);
+ }
+
+ second = BIN_TO_BCD(tm.tm_sec);
+ if (second != READ_RTC(0x1)) {
+ WRITE_RTC(0x1, second);
+ }
+
+ return 0;
+}
+
+void
+rtc_ds1386_init(unsigned long base)
+{
+ unsigned char byte;
+
+ /* remember the base */
+ rtc_base = base;
+ MIPS_ASSERT((rtc_base & 0xe0000000) == KSEG1);
+
+ /* turn on RTC if it is not on */
+ byte = READ_RTC(0x9);
+ if (byte & 0x80) {
+ byte &= 0x7f;
+ WRITE_RTC(0x9, byte);
+ }
+
+ /* enable time transfer */
+ byte = READ_RTC(0xB);
+ byte |= 0x80;
+ WRITE_RTC(0xB, byte);
+
+ /* set the function pointers */
+ rtc_get_time = rtc_ds1386_get_time;
+ rtc_set_time = rtc_ds1386_set_time;
+}
+
+
+/* ================================================== */
+#define TICK_SIZE tick
+#define FEBRUARY 2
+#define STARTOFTIME 1970
+#define SECDAY 86400L
+#define SECYR (SECDAY * 365)
+#define leapyear(year) ((year) % 4 == 0)
+#define days_in_year(a) (leapyear(a) ? 366 : 365)
+#define days_in_month(a) (month_days[(a) - 1])
+
+static int month_days[12] = {
+ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
+};
+
+/*
+ * This only works for the Gregorian calendar - i.e. after 1752 (in the UK)
+ */
+static void
+GregorianDay(struct rtc_time * tm)
+{
+ int leapsToDate;
+ int lastYear;
+ int day;
+ int MonthOffset[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
+
+ lastYear=tm->tm_year-1;
+
+ /*
+ * Number of leap corrections to apply up to end of last year
+ */
+ leapsToDate = lastYear/4 - lastYear/100 + lastYear/400;
+
+ /*
+ * This year is a leap year if it is divisible by 4 except when it is
+ * divisible by 100 unless it is divisible by 400
+ *
+ * e.g. 1904 was a leap year, 1900 was not, 1996 is, and 2000 will be
+ */
+ if((tm->tm_year%4==0) &&
+ ((tm->tm_year%100!=0) || (tm->tm_year%400==0)) &&
+ (tm->tm_mon>2))
+ {
+ /*
+ * We are past Feb. 29 in a leap year
+ */
+ day=1;
+ }
+ else
+ {
+ day=0;
+ }
+
+ day += lastYear*365 + leapsToDate + MonthOffset[tm->tm_mon-1] +
+ tm->tm_mday;
+
+ tm->tm_wday=day%7;
+}
+
+
+void to_tm(unsigned long tim, struct rtc_time * tm)
+{
+ register int i;
+ register long hms, day;
+
+ day = tim / SECDAY;
+ hms = tim % SECDAY;
+
+ /* Hours, minutes, seconds are easy */
+ tm->tm_hour = hms / 3600;
+ tm->tm_min = (hms % 3600) / 60;
+ tm->tm_sec = (hms % 3600) % 60;
+
+ /* Number of years in days */
+ for (i = STARTOFTIME; day >= days_in_year(i); i++)
+ day -= days_in_year(i);
+ tm->tm_year = i;
+
+ /* Number of months in days left */
+ if (leapyear(tm->tm_year))
+ days_in_month(FEBRUARY) = 29;
+ for (i = 1; day >= days_in_month(i); i++)
+ day -= days_in_month(i);
+ days_in_month(FEBRUARY) = 28;
+ tm->tm_mon = i;
+
+ /* Days are what is left over (+1) from all that. */
+ tm->tm_mday = day + 1;
+
+ /*
+ * Determine the day of week
+ */
+ GregorianDay(tm);
+}
diff --git a/arch/mips/ddb5xxx/ddb5477/Makefile b/arch/mips/ddb5xxx/ddb5477/Makefile
new file mode 100644
index 000000000..18377fccd
--- /dev/null
+++ b/arch/mips/ddb5xxx/ddb5477/Makefile
@@ -0,0 +1,22 @@
+#
+# Makefile for NEC DDB-Vrc5477 board
+#
+# Note! Dependencies are done automagically by 'make dep', which also
+# removes any old dependencies. DON'T put your own dependencies here
+# unless it's something special (ie not a .c file).
+#
+
+.S.s:
+ $(CPP) $(CFLAGS) $< -o $*.s
+.S.o:
+ $(CC) $(CFLAGS) -c $< -o $*.o
+
+O_TARGET:= ddb5477.o
+
+obj-y += int-handler.o irq.o irq_5477.o setup.o pci.o pci_ops.o
+
+obj-$(CONFIG_LL_DEBUG) += debug.o
+obj-$(CONFIG_REMOTE_DEBUG) += kgdb_io.o
+obj-$(CONFIG_BLK_DEV_INITRD) += ramdisk.o
+
+include $(TOPDIR)/Rules.make
diff --git a/arch/mips/ddb5xxx/ddb5477/debug.c b/arch/mips/ddb5xxx/ddb5477/debug.c
new file mode 100644
index 000000000..a4f820511
--- /dev/null
+++ b/arch/mips/ddb5xxx/ddb5477/debug.c
@@ -0,0 +1,174 @@
+/***********************************************************************
+ *
+ * Copyright 2001 MontaVista Software Inc.
+ * Author: jsun@mvista.com or jsun@junsun.net
+ *
+ * arch/mips/ddb5xxx/ddb5477/debug.c
+ * vrc5477 specific debug routines.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ ***********************************************************************
+ */
+
+#include <linux/kernel.h>
+#include <linux/interrupt.h>
+#include <linux/signal.h> /* SA_INTERRUPT */
+
+#include "debug.h"
+#include <asm/mipsregs.h>
+#include <asm/ddb5xxx/ddb5xxx.h>
+
+typedef struct {
+ const char *regname;
+ unsigned regaddr;
+} Register;
+
+void jsun_show_regs(char *name, Register *regs)
+{
+ int i;
+
+ printk("\nshow regs: %s\n", name);
+ for(i=0;regs[i].regname!= NULL; i++) {
+ printk("%-16s= %08x\t\t(@%08x)\n",
+ regs[i].regname,
+ *(unsigned *)(regs[i].regaddr),
+ regs[i].regaddr);
+ }
+}
+
+static Register int_regs[] = {
+ {"DDB_INTCTRL0", DDB_BASE + DDB_INTCTRL0},
+ {"DDB_INTCTRL1", DDB_BASE + DDB_INTCTRL1},
+ {"DDB_INTCTRL2", DDB_BASE + DDB_INTCTRL2},
+ {"DDB_INTCTRL3", DDB_BASE + DDB_INTCTRL3},
+ {"DDB_INT0STAT", DDB_BASE + DDB_INT0STAT},
+ {"DDB_INT1STAT", DDB_BASE + DDB_INT1STAT},
+ {"DDB_INT2STAT", DDB_BASE + DDB_INT2STAT},
+ {"DDB_INT3STAT", DDB_BASE + DDB_INT3STAT},
+ {"DDB_INT4STAT", DDB_BASE + DDB_INT4STAT},
+ {"DDB_NMISTAT", DDB_BASE + DDB_NMISTAT},
+ {"DDB_INTPPES0", DDB_BASE + DDB_INTPPES0},
+ {"DDB_INTPPES1", DDB_BASE + DDB_INTPPES1},
+ {NULL, 0x0}
+};
+
+void vrc5477_show_int_regs()
+{
+ jsun_show_regs("interrupt registers", int_regs);
+ printk("CPU CAUSE = %08x\n", read_32bit_cp0_register(CP0_CAUSE));
+ printk("CPU STATUS = %08x\n", read_32bit_cp0_register(CP0_STATUS));
+}
+static Register pdar_regs[] = {
+ {"DDB_SDRAM0", DDB_BASE + DDB_SDRAM0},
+ {"DDB_SDRAM1", DDB_BASE + DDB_SDRAM1},
+ {"DDB_LDCS0", DDB_BASE + DDB_LDCS0},
+ {"DDB_LDCS1", DDB_BASE + DDB_LDCS1},
+ {"DDB_LDCS2", DDB_BASE + DDB_LDCS2},
+ {"DDB_INTCS", DDB_BASE + DDB_INTCS},
+ {"DDB_BOOTCS", DDB_BASE + DDB_BOOTCS},
+ {"DDB_PCIW0", DDB_BASE + DDB_PCIW0},
+ {"DDB_PCIW1", DDB_BASE + DDB_PCIW1},
+ {"DDB_IOPCIW0", DDB_BASE + DDB_IOPCIW0},
+ {"DDB_IOPCIW1", DDB_BASE + DDB_IOPCIW1},
+ {NULL, 0x0}
+};
+void vrc5477_show_pdar_regs(void)
+{
+ jsun_show_regs("PDAR regs", pdar_regs);
+}
+
+static Register bar_regs[] = {
+ {"DDB_BARC0", DDB_BASE + DDB_BARC0},
+ {"DDB_BARM010", DDB_BASE + DDB_BARM010},
+ {"DDB_BARM230", DDB_BASE + DDB_BARM230},
+ {"DDB_BAR00", DDB_BASE + DDB_BAR00},
+ {"DDB_BAR10", DDB_BASE + DDB_BAR10},
+ {"DDB_BAR20", DDB_BASE + DDB_BAR20},
+ {"DDB_BAR30", DDB_BASE + DDB_BAR30},
+ {"DDB_BAR40", DDB_BASE + DDB_BAR40},
+ {"DDB_BAR50", DDB_BASE + DDB_BAR50},
+ {"DDB_BARB0", DDB_BASE + DDB_BARB0},
+ {"DDB_BARC1", DDB_BASE + DDB_BARC1},
+ {"DDB_BARM011", DDB_BASE + DDB_BARM011},
+ {"DDB_BARM231", DDB_BASE + DDB_BARM231},
+ {"DDB_BAR01", DDB_BASE + DDB_BAR01},
+ {"DDB_BAR11", DDB_BASE + DDB_BAR11},
+ {"DDB_BAR21", DDB_BASE + DDB_BAR21},
+ {"DDB_BAR31", DDB_BASE + DDB_BAR31},
+ {"DDB_BAR41", DDB_BASE + DDB_BAR41},
+ {"DDB_BAR51", DDB_BASE + DDB_BAR51},
+ {"DDB_BARB1", DDB_BASE + DDB_BARB1},
+ {NULL, 0x0}
+};
+void vrc5477_show_bar_regs(void)
+{
+ jsun_show_regs("BAR regs", bar_regs);
+}
+
+static Register pci_regs[] = {
+ {"DDB_PCIW0", DDB_BASE + DDB_PCIW0},
+ {"DDB_PCIW1", DDB_BASE + DDB_PCIW1},
+ {"DDB_PCIINIT00", DDB_BASE + DDB_PCIINIT00},
+ {"DDB_PCIINIT10", DDB_BASE + DDB_PCIINIT10},
+ {"DDB_PCICTL0_L", DDB_BASE + DDB_PCICTL0_L},
+ {"DDB_PCICTL0_H", DDB_BASE + DDB_PCICTL0_H},
+ {"DDB_PCIARB0_L", DDB_BASE + DDB_PCIARB0_L},
+ {"DDB_PCIARB0_H", DDB_BASE + DDB_PCIARB0_H},
+ {"DDB_PCISWP0", DDB_BASE + DDB_PCISWP0},
+ {"DDB_PCIERR0", DDB_BASE + DDB_PCIERR0},
+ {"DDB_IOPCIW0", DDB_BASE + DDB_IOPCIW0},
+ {"DDB_IOPCIW1", DDB_BASE + DDB_IOPCIW1},
+ {"DDB_PCIINIT01", DDB_BASE + DDB_PCIINIT01},
+ {"DDB_PCIINIT11", DDB_BASE + DDB_PCIINIT11},
+ {"DDB_PCICTL1_L", DDB_BASE + DDB_PCICTL1_L},
+ {"DDB_PCICTL1_H", DDB_BASE + DDB_PCICTL1_H},
+ {"DDB_PCIARB1_L", DDB_BASE + DDB_PCIARB1_L},
+ {"DDB_PCIARB1_H", DDB_BASE + DDB_PCIARB1_H},
+ {"DDB_PCISWP1", DDB_BASE + DDB_PCISWP1},
+ {"DDB_PCIERR1", DDB_BASE + DDB_PCIERR1},
+ {NULL, 0x0}
+};
+void vrc5477_show_pci_regs(void)
+{
+ jsun_show_regs("PCI regs", pci_regs);
+}
+
+void vrc5477_show_all_regs(void)
+{
+ vrc5477_show_pdar_regs();
+ vrc5477_show_pci_regs();
+ vrc5477_show_bar_regs();
+ vrc5477_show_int_regs();
+}
+
+/*
+ * We provide heartbeat interrupt handler.
+ * The interrupt comes from soft interrupt 0, which in turn is triggered
+ * cpu timer interrupt. We display the heartbeat to LED.
+ *
+ * If heartbeat runs fine, we know interrupt works and no infinite looping
+ * of interrupt handling (because soft interrupt has the lowest priority).
+ */
+static void heartbeat_interrupt(int irq, void *dev_id, struct pt_regs *regs)
+{
+ static int count1=0;
+ static int count2=0;
+
+ if (++count1 == 10) {
+ count1 = 0;
+ count2++;
+ }
+ *(unsigned char*)(DDB_LED + 0xa0000000)= (unsigned char)count2;
+}
+
+struct irqaction heartbeat_irqaction = {
+ heartbeat_interrupt,
+ SA_INTERRUPT,
+ 0,
+ "heartbeat",
+ NULL,
+ NULL};
diff --git a/arch/mips/ddb5xxx/ddb5477/int-handler.S b/arch/mips/ddb5xxx/ddb5477/int-handler.S
new file mode 100644
index 000000000..4f47a9d1c
--- /dev/null
+++ b/arch/mips/ddb5xxx/ddb5477/int-handler.S
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2001 MontaVista Software Inc.
+ * Author: jsun@mvista.com or jsun@junsun.net
+ *
+ * First-level interrupt dispatcher for ddb5477
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ */
+#include <linux/config.h>
+
+#include <asm/asm.h>
+#include <asm/mipsregs.h>
+#include <asm/addrspace.h>
+#include <asm/regdef.h>
+#include <asm/stackframe.h>
+
+/* this value should be the same to the one in include/asm/ddb5xxx/ddb5477.h */
+#define DDB_LED 0xbd010000
+
+/*
+ * first level interrupt dispatcher for ocelot board -
+ * We check for the timer first, then check PCI ints A and D.
+ * Then check for serial IRQ and fall through.
+ */
+ .align 5
+ NESTED(ddb5477_handle_int, PT_SIZE, sp)
+ SAVE_ALL
+ CLI
+ .set at
+ .set noreorder
+ mfc0 t0, CP0_CAUSE
+ mfc0 t2, CP0_STATUS
+
+ and t0, t2
+
+ andi t1, t0, STATUSF_IP7 /* cpu timer */
+ bnez t1, ll_cputimer_irq
+ andi t1, t0, (STATUSF_IP2 | STATUSF_IP3 | STATUSF_IP4 | STATUSF_IP5 | STATUSF_IP6 )
+ bnez t1, ll_vrc5477_irq
+ andi t1, t0, STATUSF_IP0 /* software int 0 */
+ bnez t1, ll_cpu_ip0
+ andi t1, t0, STATUSF_IP1 /* software int 1 */
+ bnez t1, ll_cpu_ip1
+ nop
+ .set reorder
+
+ /* wrong alarm or masked ... */
+ j spurious_interrupt
+ nop
+ END(ddb5477_handle_int)
+
+ .align 5
+
+ll_vrc5477_irq:
+ move a0, sp
+ jal vrc5477_irq_dispatch
+ j ret_from_irq
+
+ll_cputimer_irq:
+#if defined(CONFIG_LL_DEBUG)
+ /* we trigger software interrupt 0 */
+ mfc0 t0, CP0_CAUSE
+ ori t0, t0, C_SW0
+ mtc0 t0, CP0_CAUSE
+ nop
+ /* we also set the LED here so when heartbeat stops we know
+ * intr still happens. */
+ la t0, jiffies
+ lw t1, 0(t0)
+ srl t1, t1, 4
+ andi t1, t1, 0xf
+ sb t1, DDB_LED
+#endif
+ li a0, 7
+ move a1, sp
+ jal do_IRQ
+ j ret_from_irq
+
+
+ll_cpu_ip0:
+ li a0, 0
+ move a1, sp
+ jal do_IRQ
+ j ret_from_irq
+
+ll_cpu_ip1:
+ li a0, 1
+ move a1, sp
+ jal do_IRQ
+ j ret_from_irq
diff --git a/arch/mips/ddb5xxx/ddb5477/irq.c b/arch/mips/ddb5xxx/ddb5477/irq.c
new file mode 100644
index 000000000..5b4ca0673
--- /dev/null
+++ b/arch/mips/ddb5xxx/ddb5477/irq.c
@@ -0,0 +1,193 @@
+/***********************************************************************
+ * Copyright 2001 MontaVista Software Inc.
+ * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
+ *
+ * arch/mips/ddb5xxx/ddb5477/irq.c
+ * The irq setup and misc routines for DDB5476.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ ***********************************************************************
+ */
+
+#include <linux/config.h>
+#include <linux/init.h>
+#include <linux/irq.h>
+#include <linux/types.h>
+#include <linux/ptrace.h>
+
+#include <asm/system.h>
+#include <asm/mipsregs.h>
+#include <asm/ddb5xxx/ddb5xxx.h>
+
+/* [jsun] sooner or later we should move this debug stuff to MIPS common */
+#include <asm/ddb5xxx/debug.h>
+
+/*
+ * IRQ mapping
+ *
+ * 0-7: 8 CPU interrupts
+ * 0 - software interrupt 0
+ * 1 - software interrupt 1
+ * 2 - most Vrc5477 interrupts are routed to this pin
+ * 3 - (optional) some other interrupts routed to this pin for debugg
+ * 4 - not used
+ * 5 - not used
+ * 6 - not used
+ * 7 - cpu timer (used by default)
+ *
+ * 8-39: 32 Vrc5477 interrupt sources
+ * (refer to the Vrc5477 manual)
+ */
+
+#define PCI0 DDB_INTPPES0
+#define PCI1 DDB_INTPPES1
+
+#define ACTIVE_LOW 1
+#define ACTIVE_HIGH 0
+
+#define LEVEL_SENSE 2
+#define EDGE_TRIGGER 0
+
+#define INTA 0
+#define INTB 1
+#define INTC 2
+#define INTD 3
+#define INTE 4
+
+static inline void
+set_pci_int_attr(u32 pci, u32 intn, u32 active, u32 trigger)
+{
+ u32 reg_value;
+ u32 reg_bitmask;
+
+ reg_value = ddb_in32(pci);
+ reg_bitmask = 0x3 << (intn * 2);
+
+ reg_value &= ~reg_bitmask;
+ reg_value |= (active | trigger) << (intn * 2);
+ ddb_out32(pci, reg_value);
+}
+
+extern void vrc5477_irq_init(u32 base);
+extern void mips_cpu_irq_init(u32 base);
+extern asmlinkage void ddb5477_handle_int(void);
+
+#if defined(CONFIG_LL_DEBUG)
+extern int setup_irq(unsigned int irq, struct irqaction *irqaction);
+extern struct irqaction heartbeat_irqaction;
+#endif
+
+void
+ddb5477_irq_setup(void)
+{
+ MIPS_DEBUG(printk("ddb5477_irq_setup invoked.\n"));
+
+ /* by default, we disable all interrupts and route all vrc5477
+ * interrupts to pin 0 (irq 2) */
+ ddb_out32(DDB_INTCTRL0, 0);
+ ddb_out32(DDB_INTCTRL1, 0);
+ ddb_out32(DDB_INTCTRL2, 0);
+ ddb_out32(DDB_INTCTRL3, 0);
+
+ clear_cp0_status(0xff00);
+ set_cp0_status(0x0400);
+
+ /* setup PCI interrupt attributes */
+ set_pci_int_attr(PCI0, INTA, ACTIVE_LOW, LEVEL_SENSE);
+ set_pci_int_attr(PCI0, INTB, ACTIVE_LOW, LEVEL_SENSE);
+ set_pci_int_attr(PCI0, INTC, ACTIVE_LOW, LEVEL_SENSE);
+ set_pci_int_attr(PCI0, INTD, ACTIVE_LOW, LEVEL_SENSE);
+ set_pci_int_attr(PCI0, INTE, ACTIVE_LOW, LEVEL_SENSE);
+
+ set_pci_int_attr(PCI1, INTA, ACTIVE_LOW, LEVEL_SENSE);
+ set_pci_int_attr(PCI1, INTB, ACTIVE_LOW, LEVEL_SENSE);
+ set_pci_int_attr(PCI1, INTC, ACTIVE_LOW, LEVEL_SENSE);
+ set_pci_int_attr(PCI1, INTD, ACTIVE_LOW, LEVEL_SENSE);
+ set_pci_int_attr(PCI1, INTE, ACTIVE_LOW, LEVEL_SENSE);
+
+ /*
+ * for debugging purpose, we enable several error interrupts
+ * and route them to pin 1. (IP3)
+ */
+ /* cpu parity check - 0 */
+ ll_vrc5477_irq_route(0, 1); ll_vrc5477_irq_enable(0);
+ /* cpu no-target decode - 1 */
+ ll_vrc5477_irq_route(1, 1); ll_vrc5477_irq_enable(1);
+ /* local bus read time-out - 7 */
+ ll_vrc5477_irq_route(7, 1); ll_vrc5477_irq_enable(7);
+ /* PCI SERR# - 14 */
+ ll_vrc5477_irq_route(14, 1); ll_vrc5477_irq_enable(14);
+ /* PCI internal error - 15 */
+ ll_vrc5477_irq_route(15, 1); ll_vrc5477_irq_enable(15);
+ /* IOPCI SERR# - 30 */
+ ll_vrc5477_irq_route(30, 1); ll_vrc5477_irq_enable(30);
+ /* IOPCI internal error - 31 */
+ ll_vrc5477_irq_route(31, 1); ll_vrc5477_irq_enable(31);
+
+ /* init all controllers */
+ mips_cpu_irq_init(0);
+ vrc5477_irq_init(8);
+
+ /* hook up the first-level interrupt handler */
+ set_except_vector(0, ddb5477_handle_int);
+
+#if defined(CONFIG_LL_DEBUG)
+ setup_irq(0, &heartbeat_irqaction);
+#endif
+}
+
+/*
+ * the first level int-handler will jump here if it is a vrc5477 irq
+ */
+#define NUM_5477_IRQS 32
+asmlinkage void
+vrc5477_irq_dispatch(struct pt_regs *regs)
+{
+ extern unsigned int do_IRQ(int irq, struct pt_regs *regs);
+
+ u32 intStatus;
+ u32 bitmask;
+ u32 i;
+
+ MIPS_ASSERT(ddb_in32(DDB_INT2STAT) == 0);
+ MIPS_ASSERT(ddb_in32(DDB_INT3STAT) == 0);
+ MIPS_ASSERT(ddb_in32(DDB_INT4STAT) == 0);
+ MIPS_ASSERT(ddb_in32(DDB_NMISTAT) == 0);
+
+ if (ddb_in32(DDB_INT1STAT) != 0) {
+#if defined(CONFIG_LL_DEBUG)
+ vrc5477_show_int_regs();
+#endif
+ panic("error interrupt has happened.\n");
+ }
+
+ intStatus = ddb_in32(DDB_INT0STAT);
+ for (i=0, bitmask=1; i<= NUM_5477_IRQS; bitmask <<=1, i++) {
+ /* do we need to "and" with the int mask? */
+ if (intStatus & bitmask) {
+ do_IRQ(8 + i, regs);
+ }
+ }
+}
+
+void (*irq_setup)(void);
+
+void __init init_IRQ(void)
+{
+
+#ifdef CONFIG_REMOTE_DEBUG
+ extern void breakpoint(void);
+ extern void set_debug_traps(void);
+
+ printk("Wait for gdb client connection ...\n");
+ set_debug_traps();
+ breakpoint();
+#endif
+
+ /* invoke board-specific irq setup */
+ irq_setup();
+}
+
diff --git a/arch/mips/ddb5xxx/ddb5477/irq_5477.c b/arch/mips/ddb5xxx/ddb5477/irq_5477.c
new file mode 100644
index 000000000..95e995743
--- /dev/null
+++ b/arch/mips/ddb5xxx/ddb5477/irq_5477.c
@@ -0,0 +1,179 @@
+/***********************************************************************
+ * Copyright 2001 MontaVista Software Inc.
+ * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
+ *
+ * arch/mips/ddb5xxx/ddb5477/irq_5477.c
+ * This file defines the irq handler for Vrc5477.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ ***********************************************************************
+ */
+
+/*
+ * Vrc5477 defines 32 IRQs.
+ *
+ * This file exports one function:
+ * vrc5477_irq_init(u32 irq_base);
+ */
+
+#include <linux/irq.h>
+#include <linux/types.h>
+#include <linux/ptrace.h>
+
+#include <asm/ddb5xxx/ddb5xxx.h>
+
+/* [jsun] sooner or later we should move this debug stuff to MIPS common */
+#include <asm/ddb5xxx/debug.h>
+
+/* number of total irqs supported by Vrc5477 */
+#define NUM_5477_IRQ 32
+
+static int vrc5477_irq_base=-1;
+
+
+static void
+vrc5477_irq_enable(unsigned int irq)
+{
+ MIPS_ASSERT(vrc5477_irq_base != -1);
+ MIPS_ASSERT(irq >= vrc5477_irq_base);
+ MIPS_ASSERT(irq < vrc5477_irq_base+ NUM_5477_IRQ);
+
+ ll_vrc5477_irq_enable(irq - vrc5477_irq_base);
+}
+
+static void
+vrc5477_irq_disable(unsigned int irq)
+{
+ MIPS_ASSERT(vrc5477_irq_base != -1);
+ MIPS_ASSERT(irq >= vrc5477_irq_base);
+ MIPS_ASSERT(irq < vrc5477_irq_base + NUM_5477_IRQ);
+
+ ll_vrc5477_irq_disable(irq - vrc5477_irq_base);
+}
+
+static unsigned int vrc5477_irq_startup(unsigned int irq)
+{
+ vrc5477_irq_enable(irq);
+ return 0;
+}
+
+#define vrc5477_irq_shutdown vrc5477_irq_disable
+
+static void
+vrc5477_irq_ack(unsigned int irq)
+{
+ MIPS_ASSERT(vrc5477_irq_base != -1);
+ MIPS_ASSERT(irq >= vrc5477_irq_base);
+ MIPS_ASSERT(irq < vrc5477_irq_base+ NUM_5477_IRQ);
+
+ /* clear the interrupt bit */
+ /* some irqs require the driver to clear the sources */
+ ddb_out32(DDB_INTCLR32, 1 << (irq - vrc5477_irq_base));
+
+ /* disable interrupt - some handler will re-enable the irq
+ * and if the interrupt is leveled, we will have infinite loop
+ */
+ ll_vrc5477_irq_disable(irq - vrc5477_irq_base);
+}
+
+static void
+vrc5477_irq_end(unsigned int irq)
+{
+ MIPS_ASSERT(vrc5477_irq_base != -1);
+ MIPS_ASSERT(irq >= vrc5477_irq_base);
+ MIPS_ASSERT(irq < vrc5477_irq_base + NUM_5477_IRQ);
+
+ ll_vrc5477_irq_enable( irq - vrc5477_irq_base);
+}
+
+hw_irq_controller vrc5477_irq_controller = {
+ "vrc5477_irq",
+ vrc5477_irq_startup,
+ vrc5477_irq_shutdown,
+ vrc5477_irq_enable,
+ vrc5477_irq_disable,
+ vrc5477_irq_ack,
+ vrc5477_irq_end,
+ NULL /* no affinity stuff for UP */
+};
+
+void
+vrc5477_irq_init(u32 irq_base)
+{
+ extern irq_desc_t irq_desc[];
+ u32 i;
+
+ for (i= irq_base; i< irq_base+ NUM_5477_IRQ; i++) {
+ irq_desc[i].status = IRQ_DISABLED;
+ irq_desc[i].action = NULL;
+ irq_desc[i].depth = 1;
+ irq_desc[i].handler = &vrc5477_irq_controller;
+ }
+
+ vrc5477_irq_base = irq_base;
+}
+
+
+int vrc5477_irq_to_irq(int irq)
+{
+ MIPS_ASSERT(irq >= 0);
+ MIPS_ASSERT(irq < NUM_5477_IRQ);
+
+ return irq + vrc5477_irq_base;
+}
+
+void ll_vrc5477_irq_route(int vrc5477_irq, int ip)
+{
+ u32 reg_value;
+ u32 reg_bitmask;
+ u32 reg_index;
+
+ MIPS_ASSERT(vrc5477_irq >= 0);
+ MIPS_ASSERT(vrc5477_irq < NUM_5477_IRQ);
+ MIPS_ASSERT(ip >= 0);
+ MIPS_ASSERT((ip < 5) || (ip == 6));
+
+ reg_index = DDB_INTCTRL0 + vrc5477_irq/8*4;
+ reg_value = ddb_in32(reg_index);
+ reg_bitmask = 7 << (vrc5477_irq % 8 * 4);
+ reg_value &= ~reg_bitmask;
+ reg_value |= ip << (vrc5477_irq % 8 * 4);
+ ddb_out32(reg_index, reg_value);
+}
+
+void ll_vrc5477_irq_enable(int vrc5477_irq)
+{
+ u32 reg_value;
+ u32 reg_bitmask;
+ u32 reg_index;
+
+ MIPS_ASSERT(vrc5477_irq >= 0);
+ MIPS_ASSERT(vrc5477_irq < NUM_5477_IRQ);
+
+ reg_index = DDB_INTCTRL0 + vrc5477_irq/8*4;
+ reg_value = ddb_in32(reg_index);
+ reg_bitmask = 8 << (vrc5477_irq % 8 * 4);
+ MIPS_ASSERT((reg_value & reg_bitmask) == 0);
+ ddb_out32(reg_index, reg_value | reg_bitmask);
+}
+
+void ll_vrc5477_irq_disable(int vrc5477_irq)
+{
+ u32 reg_value;
+ u32 reg_bitmask;
+ u32 reg_index;
+
+ MIPS_ASSERT(vrc5477_irq >= 0);
+ MIPS_ASSERT(vrc5477_irq < NUM_5477_IRQ);
+
+ reg_index = DDB_INTCTRL0 + vrc5477_irq/8*4;
+ reg_value = ddb_in32(reg_index);
+ reg_bitmask = 8 << (vrc5477_irq % 8 * 4);
+
+ /* we assert that the interrupt is enabled (perhaps over-zealous) */
+ MIPS_ASSERT( (reg_value & reg_bitmask) != 0);
+ ddb_out32(reg_index, reg_value & ~reg_bitmask);
+}
diff --git a/arch/mips/ddb5xxx/ddb5477/kgdb_io.c b/arch/mips/ddb5xxx/ddb5477/kgdb_io.c
new file mode 100644
index 000000000..487d0bddf
--- /dev/null
+++ b/arch/mips/ddb5xxx/ddb5477/kgdb_io.c
@@ -0,0 +1,142 @@
+
+#include <linux/config.h>
+
+#if (defined(CONFIG_DDB5477) && defined(CONFIG_REMOTE_DEBUG))
+
+/* --- CONFIG --- */
+
+/* we need uint32 uint8 */
+/* #include "types.h" */
+typedef unsigned char uint8;
+typedef unsigned int uint32;
+
+/* --- END OF CONFIG --- */
+
+#define UART16550_BAUD_2400 2400
+#define UART16550_BAUD_4800 4800
+#define UART16550_BAUD_9600 9600
+#define UART16550_BAUD_19200 19200
+#define UART16550_BAUD_38400 38400
+#define UART16550_BAUD_57600 57600
+#define UART16550_BAUD_115200 115200
+
+#define UART16550_PARITY_NONE 0
+#define UART16550_PARITY_ODD 0x08
+#define UART16550_PARITY_EVEN 0x18
+#define UART16550_PARITY_MARK 0x28
+#define UART16550_PARITY_SPACE 0x38
+
+#define UART16550_DATA_5BIT 0x0
+#define UART16550_DATA_6BIT 0x1
+#define UART16550_DATA_7BIT 0x2
+#define UART16550_DATA_8BIT 0x3
+
+#define UART16550_STOP_1BIT 0x0
+#define UART16550_STOP_2BIT 0x4
+
+/* ----------------------------------------------------- */
+
+/* === CONFIG === */
+
+/* [jsun] we use the second serial port for kdb */
+#define BASE 0xbfa04240
+#define MAX_BAUD 115200
+#define REG_OFFSET 8
+
+/* === END OF CONFIG === */
+
+/* register offset */
+#define OFS_RCV_BUFFER (0*REG_OFFSET)
+#define OFS_TRANS_HOLD (0*REG_OFFSET)
+#define OFS_SEND_BUFFER (0*REG_OFFSET)
+#define OFS_INTR_ENABLE (1*REG_OFFSET)
+#define OFS_INTR_ID (2*REG_OFFSET)
+#define OFS_DATA_FORMAT (3*REG_OFFSET)
+#define OFS_LINE_CONTROL (3*REG_OFFSET)
+#define OFS_MODEM_CONTROL (4*REG_OFFSET)
+#define OFS_RS232_OUTPUT (4*REG_OFFSET)
+#define OFS_LINE_STATUS (5*REG_OFFSET)
+#define OFS_MODEM_STATUS (6*REG_OFFSET)
+#define OFS_RS232_INPUT (6*REG_OFFSET)
+#define OFS_SCRATCH_PAD (7*REG_OFFSET)
+
+#define OFS_DIVISOR_LSB (0*REG_OFFSET)
+#define OFS_DIVISOR_MSB (1*REG_OFFSET)
+
+
+/* memory-mapped read/write of the port */
+#define UART16550_READ(y) (*((volatile uint8*)(BASE + y)))
+#define UART16550_WRITE(y, z) ((*((volatile uint8*)(BASE + y))) = z)
+
+void debugInit(uint32 baud, uint8 data, uint8 parity, uint8 stop)
+{
+ /* disable interrupts */
+ UART16550_WRITE(OFS_INTR_ENABLE, 0);
+
+ /* set up buad rate */
+ {
+ uint32 divisor;
+
+ /* set DIAB bit */
+ UART16550_WRITE(OFS_LINE_CONTROL, 0x80);
+
+ /* set divisor */
+ divisor = MAX_BAUD / baud;
+ UART16550_WRITE(OFS_DIVISOR_LSB, divisor & 0xff);
+ UART16550_WRITE(OFS_DIVISOR_MSB, (divisor & 0xff00) >> 8);
+
+ /* clear DIAB bit */
+ UART16550_WRITE(OFS_LINE_CONTROL, 0x0);
+ }
+
+ /* set data format */
+ UART16550_WRITE(OFS_DATA_FORMAT, data | parity | stop);
+}
+
+static int remoteDebugInitialized = 0;
+
+int debug_state = -1;
+
+uint8 getDebugChar(void)
+{
+ uint8 c;
+ if (!remoteDebugInitialized) {
+ remoteDebugInitialized = 1;
+ debugInit(UART16550_BAUD_38400,
+ UART16550_DATA_8BIT,
+ UART16550_PARITY_NONE, UART16550_STOP_1BIT);
+ }
+
+ while ((UART16550_READ(OFS_LINE_STATUS) & 0x1) == 0);
+ c= UART16550_READ(OFS_RCV_BUFFER);
+/*
+ if (state != 1) {
+ state = 1;
+ debug_out("\ngetDebugChar: ", 15);
+ }
+ debug_out(&c, 1);
+*/
+ return c;
+}
+
+
+int putDebugChar(uint8 byte)
+{
+ if (!remoteDebugInitialized) {
+ remoteDebugInitialized = 1;
+ debugInit(UART16550_BAUD_9600,
+ UART16550_DATA_8BIT,
+ UART16550_PARITY_NONE, UART16550_STOP_1BIT);
+ }
+
+ while ((UART16550_READ(OFS_LINE_STATUS) & 0x20) == 0);
+ UART16550_WRITE(OFS_SEND_BUFFER, byte);
+ if (debug_state != 2) {
+ debug_state = 2;
+ // debug_out("\nputDebugChar: ", 15);
+ }
+ // debug_out(&byte, 1);
+ return 1;
+}
+
+#endif
diff --git a/arch/mips/ddb5xxx/ddb5477/pci.c b/arch/mips/ddb5xxx/ddb5477/pci.c
new file mode 100644
index 000000000..c17413fdd
--- /dev/null
+++ b/arch/mips/ddb5xxx/ddb5477/pci.c
@@ -0,0 +1,144 @@
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/types.h>
+#include <linux/pci.h>
+
+#include <asm/ddb5xxx/ddb5xxx.h>
+#include <asm/ddb5xxx/debug.h>
+#include <asm/ddb5xxx/pci.h>
+
+static struct resource extpci_io_resource = {
+ "ext pci IO space",
+ DDB_PCI0_IO_BASE - DDB_PCI_IO_BASE,
+ DDB_PCI0_IO_BASE - DDB_PCI_IO_BASE + DDB_PCI0_IO_SIZE -1,
+ IORESOURCE_IO};
+
+static struct resource extpci_mem_resource = {
+ "ext pci memory space",
+ DDB_PCI0_MEM_BASE,
+ DDB_PCI0_MEM_BASE + DDB_PCI0_MEM_SIZE -1,
+ IORESOURCE_MEM};
+
+static struct resource iopci_io_resource = {
+ "io pci IO space",
+ DDB_PCI1_IO_BASE - DDB_PCI_IO_BASE,
+ DDB_PCI1_IO_BASE - DDB_PCI_IO_BASE + DDB_PCI1_IO_SIZE -1,
+ IORESOURCE_IO};
+
+static struct resource iopci_mem_resource = {
+ "ext pci memory space",
+ DDB_PCI1_MEM_BASE,
+ DDB_PCI1_MEM_BASE + DDB_PCI1_MEM_SIZE -1,
+ IORESOURCE_MEM};
+
+extern struct pci_ops ddb5477_ext_pci_ops;
+extern struct pci_ops ddb5477_io_pci_ops;
+
+struct pci_channel mips_pci_channels[] = {
+ { &ddb5477_ext_pci_ops, &extpci_io_resource, &extpci_mem_resource },
+ { &ddb5477_io_pci_ops, &iopci_io_resource, &iopci_mem_resource },
+ { NULL, NULL, NULL}
+};
+
+
+/*
+ * we fix up irqs based on the slot number.
+ * The first entry is at AD:11.
+ * Fortunately this works because, although we have two pci buses,
+ * they all have different slot numbers.
+ *
+ * This does not work for devices on sub-buses.
+ *
+ * Note that the irq number in the array is relative number in vrc5477.
+ * We need to translate it to global irq number.
+ */
+
+/*
+ * irq mapping : PCI int # -> vrc5477 irq #
+ * based on vrc5477 manual page 46
+ */
+#define PCI_EXT_INTA 8
+#define PCI_EXT_INTB 9
+#define PCI_EXT_INTC 10
+#define PCI_EXT_INTD 11
+#define PCI_EXT_INTE 12
+
+#define PCI_IO_INTA 16
+#define PCI_IO_INTB 17
+#define PCI_IO_INTC 18
+#define PCI_IO_INTD 19
+
+/*
+ * irq mapping : device -> pci int #,
+ * ddb5477 board manual page 4 and vrc5477 manual page 46
+ */
+#define INT_ONBOARD_TULIP PCI_EXT_INTA
+#define INT_SLOT1 PCI_EXT_INTB
+#define INT_SLOT2 PCI_EXT_INTC
+#define INT_SLOT3 PCI_EXT_INTD
+#define INT_SLOT4 PCI_EXT_INTE
+
+#define INT_USB_HOST PCI_IO_INTA
+#define INT_USB_PERI PCI_IO_INTB
+#define INT_AC97 PCI_IO_INTC
+
+/*
+ * based on ddb5477 manual page 11
+ */
+#define MAX_SLOT_NUM 21
+static unsigned char irq_map[MAX_SLOT_NUM] = {
+ /* AD:11 */ 0xff, 0xff, 0xff, 0xff,
+ /* AD:15 */ INT_ONBOARD_TULIP, INT_SLOT1, INT_SLOT2, INT_SLOT3,
+ /* AD:19 */ INT_SLOT4, 0xff, 0xff, 0xff,
+ /* AD:23 */ 0xff, 0xff, 0xff, 0xff,
+ /* AD:27 */ 0xff, 0xff, INT_AC97, INT_USB_PERI,
+ /* AD:31 */ INT_USB_HOST
+};
+
+extern int vrc5477_irq_to_irq(int irq);
+void __init pcibios_fixup_irqs(void)
+{
+ struct pci_dev *dev;
+ int slot_num;
+
+ pci_for_each_dev(dev) {
+ slot_num = PCI_SLOT(dev->devfn);
+ MIPS_ASSERT(slot_num < MAX_SLOT_NUM);
+ MIPS_ASSERT(irq_map[slot_num] != 0xff);
+
+ pci_write_config_byte(dev,
+ PCI_INTERRUPT_LINE,
+ irq_map[slot_num]);
+ dev->irq = vrc5477_irq_to_irq(irq_map[slot_num]);
+ }
+}
+
+#if defined(CONFIG_LL_DEBUG)
+extern void jsun_scan_pci_bus(void);
+extern void jsun_assign_pci_resource(void);
+#endif
+void __init ddb_pci_reset_bus(void)
+{
+ u32 temp;
+
+ /*
+ * I am not sure about the "official" procedure, the following
+ * steps work as far as I know:
+ * We first set PCI cold reset bit (bit 31) in PCICTRL-H.
+ * Then we clear the PCI warm reset bit (bit 30) to 0 in PCICTRL-H.
+ * The same is true for both PCI channels.
+ */
+ temp = ddb_in32(DDB_PCICTL0_H);
+ temp |= 0x80000000;
+ ddb_out32(DDB_PCICTL0_H, temp);
+ temp &= ~0xc0000000;
+ ddb_out32(DDB_PCICTL0_H, temp);
+
+ temp = ddb_in32(DDB_PCICTL1_H);
+ temp |= 0x80000000;
+ ddb_out32(DDB_PCICTL1_H, temp);
+ temp &= ~0xc0000000;
+ ddb_out32(DDB_PCICTL1_H, temp);
+}
+
+
diff --git a/arch/mips/ddb5xxx/ddb5477/pci_ops.c b/arch/mips/ddb5xxx/ddb5477/pci_ops.c
new file mode 100644
index 000000000..3bd3e2189
--- /dev/null
+++ b/arch/mips/ddb5xxx/ddb5477/pci_ops.c
@@ -0,0 +1,416 @@
+/***********************************************************************
+ * Copyright 2001 MontaVista Software Inc.
+ * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
+ *
+ * arch/mips/ddb5xxx/ddb5477/pci_ops.c
+ * Define the pci_ops for DB5477.
+ *
+ * Much of the code is derived from the original DDB5074 port by
+ * Geert Uytterhoeven <geert@sonycom.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ ***********************************************************************
+ */
+
+/*
+ * DDB5477 has two PCI channels, external PCI and IOPIC (internal)
+ * Therefore we provide two sets of pci_ops.
+ */
+
+#include <linux/config.h>
+#include <linux/pci.h>
+#include <linux/kernel.h>
+#include <linux/types.h>
+
+#include <asm/addrspace.h>
+#include <asm/ddb5xxx/debug.h>
+#include <asm/ddb5xxx/ddb5xxx.h>
+
+/*
+ * config_swap structure records what set of pdar/pmr are used
+ * to access pci config space. It also provides a place hold the
+ * original values for future restoring.
+ */
+struct pci_config_swap {
+ u32 pdar;
+ u32 pmr;
+ u32 config_base;
+ u32 config_size;
+ u32 pdar_backup;
+ u32 pmr_backup;
+};
+
+/*
+ * On DDB5477, we have two sets of swap registers, for ext PCI and IOPCI.
+ */
+struct pci_config_swap ext_pci_swap = {
+ DDB_PCIW0,
+ DDB_PCIINIT00,
+ DDB_PCI0_CONFIG_BASE,
+ DDB_PCI0_CONFIG_SIZE
+};
+struct pci_config_swap io_pci_swap = {
+ DDB_IOPCIW0,
+ DDB_PCIINIT01,
+ DDB_PCI1_CONFIG_BASE,
+ DDB_PCI1_CONFIG_SIZE
+};
+
+
+/*
+ * access config space
+ */
+static inline u32 ddb_access_config_base(struct pci_config_swap *swap,
+ u32 bus,/* 0 means top level bus */
+ u32 slot_num)
+{
+ u32 pci_addr = 0;
+ u32 pciinit_offset = 0;
+ u32 virt_addr = swap->config_base;
+ u32 option;
+
+ /* [jsun] hack for testing */
+ // if (slot_num == 4) slot_num = 0;
+
+ /* minimum pdar (window) size is 2MB */
+ MIPS_ASSERT(swap->config_size >= (2 << 20));
+
+ MIPS_ASSERT(slot_num < (1 << 5));
+ MIPS_ASSERT(bus < (1 << 8));
+
+ /* backup registers */
+ swap->pdar_backup = ddb_in32(swap->pdar);
+ swap->pmr_backup = ddb_in32(swap->pmr);
+
+ /* set the pdar (pci window) register */
+ ddb_set_pdar(swap->pdar,
+ swap->config_base,
+ swap->config_size,
+ 32, /* 32 bit wide */
+ 0, /* not on local memory bus */
+ 0); /* not visible from PCI bus (N/A) */
+
+ /*
+ * calcuate the absolute pci config addr;
+ * according to the spec, we start scanning from adr:11 (0x800)
+ */
+ if (bus == 0) {
+ /* type 0 config */
+ pci_addr = 0x800 << slot_num;
+ } else {
+ /* type 1 config */
+ pci_addr = (bus << 16) | (slot_num << 11);
+ panic("ddb_access_config_base: we don't support type 1 config Yet");
+ }
+
+ /*
+ * if pci_addr is less than pci config window size, we set
+ * pciinit_offset to 0 and adjust the virt_address.
+ * Otherwise we will try to adjust pciinit_offset.
+ */
+ if (pci_addr < swap->config_size) {
+ virt_addr = KSEG1ADDR(swap->config_base + pci_addr);
+ pciinit_offset = 0;
+ } else {
+ MIPS_ASSERT( (pci_addr & (swap->config_size - 1)) == 0);
+ virt_addr = KSEG1ADDR(swap->config_base);
+ pciinit_offset = pci_addr;
+ }
+
+ /* set the pmr register */
+ option = DDB_PCI_ACCESS_32;
+ if (bus != 0) option |= DDB_PCI_CFGTYPE1;
+ ddb_set_pmr(swap->pmr, DDB_PCICMD_CFG, pciinit_offset, option);
+
+ return virt_addr;
+}
+
+static inline void ddb_close_config_base(struct pci_config_swap *swap)
+{
+ ddb_out32(swap->pdar, swap->pdar_backup);
+ ddb_out32(swap->pmr, swap->pmr_backup);
+}
+
+static int read_config_dword(struct pci_config_swap *swap,
+ struct pci_dev *dev,
+ u32 where,
+ u32 *val)
+{
+ u32 bus, slot_num, func_num;
+ u32 base;
+
+ MIPS_ASSERT((where & 3) == 0);
+ MIPS_ASSERT(where < (1 << 8));
+
+ /* check if the bus is top-level */
+ if (dev->bus->parent != NULL) {
+ bus = dev->bus->number;
+ MIPS_ASSERT(bus != 0);
+ } else {
+ bus = 0;
+ }
+
+ slot_num = PCI_SLOT(dev->devfn);
+ func_num = PCI_FUNC(dev->devfn);
+ base = ddb_access_config_base(swap, bus, slot_num);
+ *val = *(volatile u32*) (base + (func_num << 8) + where);
+ ddb_close_config_base(swap);
+ return PCIBIOS_SUCCESSFUL;
+}
+
+static int read_config_word(struct pci_config_swap *swap,
+ struct pci_dev *dev,
+ u32 where,
+ u16 *val)
+{
+ int status;
+ u32 result;
+
+ MIPS_ASSERT((where & 1) == 0);
+
+ status = read_config_dword(swap, dev, where & ~3, &result);
+ if (where & 2) result >>= 16;
+ *val = result & 0xffff;
+ return status;
+}
+
+static int read_config_byte(struct pci_config_swap *swap,
+ struct pci_dev *dev,
+ u32 where,
+ u8 *val)
+{
+ int status;
+ u32 result;
+
+ status = read_config_dword(swap, dev, where & ~3, &result);
+ if (where & 1) result >>= 8;
+ if (where & 2) result >>= 16;
+ *val = result & 0xff;
+ return status;
+}
+
+static int write_config_dword(struct pci_config_swap *swap,
+ struct pci_dev *dev,
+ u32 where,
+ u32 val)
+{
+ u32 bus, slot_num, func_num;
+ u32 base;
+
+ MIPS_ASSERT((where & 3) == 0);
+ MIPS_ASSERT(where < (1 << 8));
+
+ /* check if the bus is top-level */
+ if (dev->bus->parent != NULL) {
+ bus = dev->bus->number;
+ MIPS_ASSERT(bus != 0);
+ } else {
+ bus = 0;
+ }
+
+ slot_num = PCI_SLOT(dev->devfn);
+ func_num = PCI_FUNC(dev->devfn);
+ base = ddb_access_config_base(swap, bus, slot_num);
+ *(volatile u32*) (base + (func_num << 8) + where) = val;
+ ddb_close_config_base(swap);
+ return PCIBIOS_SUCCESSFUL;
+}
+
+static int write_config_word(struct pci_config_swap *swap,
+ struct pci_dev *dev,
+ u32 where,
+ u16 val)
+{
+ int status, shift=0;
+ u32 result;
+
+ MIPS_ASSERT((where & 1) == 0);
+
+ status = read_config_dword(swap, dev, where & ~3, &result);
+ if (status != PCIBIOS_SUCCESSFUL) return status;
+
+ if (where & 2)
+ shift += 16;
+ result &= ~(0xffff << shift);
+ result |= val << shift;
+ return write_config_dword(swap, dev, where & ~3, result);
+}
+
+static int write_config_byte(struct pci_config_swap *swap,
+ struct pci_dev *dev,
+ u32 where,
+ u8 val)
+{
+ int status, shift=0;
+ u32 result;
+
+ status = read_config_dword(swap, dev, where & ~3, &result);
+ if (status != PCIBIOS_SUCCESSFUL) return status;
+
+ if (where & 2)
+ shift += 16;
+ if (where & 1)
+ shift += 8;
+ result &= ~(0xff << shift);
+ result |= val << shift;
+ return write_config_dword(swap, dev, where & ~3, result);
+}
+
+#define MAKE_PCI_OPS(prefix, rw, unitname, unittype, pciswap) \
+static int prefix##_##rw##_config_##unitname(struct pci_dev *dev, int where, unittype val) \
+{ \
+ return rw##_config_##unitname(pciswap, \
+ dev, \
+ where, \
+ val); \
+}
+
+MAKE_PCI_OPS(extpci, read, byte, u8 *, &ext_pci_swap)
+MAKE_PCI_OPS(extpci, read, word, u16 *, &ext_pci_swap)
+MAKE_PCI_OPS(extpci, read, dword, u32 *, &ext_pci_swap)
+
+MAKE_PCI_OPS(iopci, read, byte, u8 *, &io_pci_swap)
+MAKE_PCI_OPS(iopci, read, word, u16 *, &io_pci_swap)
+MAKE_PCI_OPS(iopci, read, dword, u32 *, &io_pci_swap)
+
+MAKE_PCI_OPS(extpci, write, byte, u8, &ext_pci_swap)
+MAKE_PCI_OPS(extpci, write, word, u16, &ext_pci_swap)
+MAKE_PCI_OPS(extpci, write, dword, u32, &ext_pci_swap)
+
+MAKE_PCI_OPS(iopci, write, byte, u8, &io_pci_swap)
+MAKE_PCI_OPS(iopci, write, word, u16, &io_pci_swap)
+MAKE_PCI_OPS(iopci, write, dword, u32, &io_pci_swap)
+
+struct pci_ops ddb5477_ext_pci_ops ={
+ extpci_read_config_byte,
+ extpci_read_config_word,
+ extpci_read_config_dword,
+ extpci_write_config_byte,
+ extpci_write_config_word,
+ extpci_write_config_dword
+};
+
+
+struct pci_ops ddb5477_io_pci_ops ={
+ iopci_read_config_byte,
+ iopci_read_config_word,
+ iopci_read_config_dword,
+ iopci_write_config_byte,
+ iopci_write_config_word,
+ iopci_write_config_dword
+};
+
+#if defined(CONFIG_LL_DEBUG)
+void jsun_scan_pci_bus(void)
+{
+ struct pci_bus bus;
+ struct pci_dev dev;
+ unsigned int devfn;
+ int j;
+
+ bus.parent = NULL; /* we scan the top level only */
+ dev.bus = &bus;
+ dev.sysdata = NULL;
+
+ /* scan ext pci bus and io pci bus*/
+ for (j=0; j< 2; j++) {
+ if (j == 0) {
+ printk("scan ddb5477 external PCI bus:\n");
+ bus.ops = &ddb5477_ext_pci_ops;
+ } else {
+ printk("scan ddb5477 IO PCI bus:\n");
+ bus.ops = &ddb5477_io_pci_ops;
+ }
+
+ for (devfn = 0; devfn < 0x100; devfn += 8) {
+ u32 temp;
+ u16 temp16;
+ u8 temp8;
+ int i;
+
+ dev.devfn = devfn;
+ MIPS_VERIFY(pci_read_config_dword(&dev, 0, &temp),
+ == PCIBIOS_SUCCESSFUL);
+ if (temp == 0xffffffff) continue;
+
+ printk("slot %d: (addr %d) \n", devfn/8, 11+devfn/8);
+
+ /* verify read word and byte */
+ MIPS_VERIFY(pci_read_config_word(&dev, 2, &temp16),
+ == PCIBIOS_SUCCESSFUL);
+ MIPS_ASSERT(temp16 == (temp >> 16));
+ MIPS_VERIFY(pci_read_config_byte(&dev, 3, &temp8),
+ == PCIBIOS_SUCCESSFUL);
+ MIPS_ASSERT(temp8 == (temp >> 24));
+ MIPS_VERIFY(pci_read_config_byte(&dev, 1, &temp8),
+ == PCIBIOS_SUCCESSFUL);
+ MIPS_ASSERT(temp8 == ((temp >> 8) & 0xff));
+
+ for (i=0; i < 16; i++) {
+ MIPS_VERIFY(pci_read_config_dword(&dev, i*4, &temp),
+ == PCIBIOS_SUCCESSFUL);
+ printk("\t%08X", temp);
+ if ((i%4) == 3) printk("\n");
+ }
+ }
+ }
+}
+
+
+static void jsun_hardcode_pci_resources_eepro(void)
+{
+ struct pci_bus bus;
+ struct pci_dev dev;
+ u32 temp;
+
+ bus.parent = NULL; /* we scan the top level only */
+ bus.ops = &ddb5477_ext_pci_ops;
+ dev.bus = &bus;
+ dev.sysdata = NULL;
+
+ /* for slot 5 (ext pci 1) eepro card */
+ dev.devfn = 5*8;
+ pci_read_config_dword(&dev, 0, &temp);
+ MIPS_ASSERT(temp == 0x12298086);
+
+ pci_write_config_dword(&dev, PCI_BASE_ADDRESS_0, DDB_PCI0_MEM_BASE);
+ pci_write_config_dword(&dev, PCI_BASE_ADDRESS_1, 0);
+ pci_write_config_dword(&dev, PCI_BASE_ADDRESS_2, DDB_PCI0_MEM_BASE+0x100000);
+ pci_write_config_dword(&dev, PCI_INTERRUPT_LINE, 17);
+}
+
+static void jsun_hardcode_pci_resources_onboard_tulip(void)
+{
+ struct pci_bus bus;
+ struct pci_dev dev;
+ u32 temp;
+
+ bus.parent = NULL; /* we scan the top level only */
+ bus.ops = &ddb5477_ext_pci_ops;
+ dev.bus = &bus;
+ dev.sysdata = NULL;
+
+ /* for slot 4 on board ether chip */
+ dev.devfn = 4*8;
+ pci_read_config_dword(&dev, 0, &temp);
+ MIPS_ASSERT(temp == 0x00191011);
+
+ pci_write_config_dword(&dev, PCI_BASE_ADDRESS_0, 0x1000);
+ pci_write_config_dword(&dev, PCI_BASE_ADDRESS_1, DDB_PCI0_MEM_BASE);
+ pci_write_config_dword(&dev, PCI_INTERRUPT_LINE, 16);
+}
+
+static void jsun_hardcode_pci_resources(void)
+{
+ jsun_hardcode_pci_resources_onboard_tulip();
+}
+
+void jsun_assign_pci_resource(void)
+{
+ jsun_hardcode_pci_resources();
+}
+
+#endif
diff --git a/arch/mips/ddb5xxx/ddb5477/setup.c b/arch/mips/ddb5xxx/ddb5477/setup.c
new file mode 100644
index 000000000..c236295f3
--- /dev/null
+++ b/arch/mips/ddb5xxx/ddb5477/setup.c
@@ -0,0 +1,251 @@
+/***********************************************************************
+ *
+ * Copyright 2001 MontaVista Software Inc.
+ * Author: jsun@mvista.com or jsun@junsun.net
+ *
+ * arch/mips/ddb5xxx/ddb5477/setup.c
+ * Setup file for DDB5477.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ ***********************************************************************
+ */
+
+#include <linux/config.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/kdev_t.h>
+#include <linux/types.h>
+#include <linux/console.h>
+#include <linux/sched.h>
+#include <linux/pci.h>
+#include <linux/ide.h>
+#include <linux/fs.h> /* for ROOT_DEV */
+#include <linux/ioport.h>
+#include <linux/param.h> /* for HZ */
+
+#include <asm/addrspace.h>
+#include <asm/time.h>
+#include <asm/bcache.h>
+#include <asm/irq.h>
+#include <asm/reboot.h>
+#include <asm/gdb-stub.h>
+
+#include <asm/ddb5xxx/ddb5xxx.h>
+
+
+
+#define USE_CPU_COUNTER_TIMER /* whether we use cpu counter */
+
+#ifdef USE_CPU_COUNTER_TIMER
+#define CPU_COUNTER_FREQUENCY 83000000
+#else
+/* otherwise we use special timer 1 */
+#define SP_TIMER_FREQUENCY 83000000
+#define SP_TIMER_BASE DDB_SPT1CTRL_L
+#define SP_TIMER_IRQ (8 + 6)
+#endif
+
+static void ddb_machine_restart(char *command)
+{
+ static void (*back_to_prom) (void) = (void (*)(void)) 0xbfc00000;
+
+ u32 t;
+
+ /* PCI cold reset */
+ ddb_pci_reset_bus();
+
+ /* CPU cold reset */
+ t = ddb_in32(DDB_CPUSTAT);
+ MIPS_ASSERT((t&1));
+ ddb_out32(DDB_CPUSTAT, t);
+
+ /* Call the PROM */
+ back_to_prom();
+}
+
+static void ddb_machine_halt(void)
+{
+ printk("DDB Vrc-5477 halted.\n");
+ while (1);
+}
+
+static void ddb_machine_power_off(void)
+{
+ printk("DDB Vrc-5477 halted. Please turn off the power.\n");
+ while (1);
+}
+
+extern void rtc_ds1386_init(unsigned long base);
+static void __init ddb_time_init(void)
+{
+#if defined(USE_CPU_COUNTER_TIMER)
+ mips_counter_frequency = CPU_COUNTER_FREQUENCY;
+#endif
+
+ /* we have ds1396 RTC chip */
+ rtc_ds1386_init(KSEG1ADDR(DDB_LCS1_BASE));
+}
+
+#if defined(CONFIG_LL_DEBUG)
+int board_init_done_flag = 0;
+#endif
+
+extern int setup_irq(unsigned int irq, struct irqaction *irqaction);
+static void __init ddb_timer_setup(struct irqaction *irq)
+{
+#if defined(USE_CPU_COUNTER_TIMER)
+ unsigned int count;
+
+ /* we are using the cpu counter for timer interrupts */
+ setup_irq(7, irq);
+
+ /* to generate the first timer interrupt */
+ count = read_32bit_cp0_register(CP0_COUNT);
+ write_32bit_cp0_register(CP0_COMPARE, count + 1000);
+
+#else
+
+ /* if we don't use Special purpose timer 1 */
+ ddb_out32(SP_TIMER_BASE, SP_TIMER_FREQUENCY/HZ);
+ ddb_out32(SP_TIMER_BASE+4, 0x1);
+ setup_irq(SP_TIMER_IRQ, irq);
+
+#endif
+
+ /* this is the last board dependent code */
+ MIPS_DEBUG(board_init_done_flag = 1);
+}
+
+static void ddb5477_board_init(void);
+extern void ddb5477_irq_setup(void);
+
+#if defined(CONFIG_BLK_DEV_INITRD)
+extern unsigned long __rd_start, __rd_end, initrd_start, initrd_end;
+#endif
+
+void __init ddb_setup(void)
+{
+ extern int panic_timeout;
+
+ irq_setup = ddb5477_irq_setup;
+ mips_io_port_base = KSEG1ADDR(DDB_PCI_IO_BASE);
+
+ board_time_init = ddb_time_init;
+ board_timer_setup = ddb_timer_setup;
+
+ _machine_restart = ddb_machine_restart;
+ _machine_halt = ddb_machine_halt;
+ _machine_power_off = ddb_machine_power_off;
+
+ /* setup resource limits */
+ ioport_resource.end = DDB_PCI0_IO_SIZE + DDB_PCI1_IO_SIZE - 1;
+ iomem_resource.end = 0xffffffff;
+
+ /* Reboot on panic */
+ panic_timeout = 180;
+
+ /* initialize board - we don't trust the loader */
+ ddb5477_board_init();
+
+#if defined(CONFIG_BLK_DEV_INITRD)
+ ROOT_DEV = MKDEV(RAMDISK_MAJOR, 0);
+ initrd_start = (unsigned long)&__rd_start;
+ initrd_end = (unsigned long)&__rd_end;
+#endif
+
+}
+
+static void __init ddb5477_board_init()
+{
+ /* ----------- setup PDARs ------------ */
+
+ /* SDRAM should have been set */
+ MIPS_ASSERT(ddb_in32(DDB_SDRAM0) ==
+ ddb_calc_pdar(DDB_SDRAM_BASE, DDB_SDRAM_SIZE, 32, 0, 1));
+
+ /* SDRAM1 should be turned off. What is this for anyway ? */
+ MIPS_ASSERT( (ddb_in32(DDB_SDRAM1) & 0xf) == 0);
+
+ /* Set LDCSs */
+ /* flash */
+ ddb_set_pdar(DDB_LCS0, DDB_LCS0_BASE, DDB_LCS0_SIZE, 16, 0, 0);
+ /* misc */
+ ddb_set_pdar(DDB_LCS1, DDB_LCS1_BASE, DDB_LCS1_SIZE, 8, 0, 0);
+ /* mezzanie (?) */
+ ddb_set_pdar(DDB_LCS2, DDB_LCS2_BASE, DDB_LCS2_SIZE, 16, 0, 0);
+
+ /* verify VRC5477 base addr */
+ MIPS_ASSERT(ddb_in32(DDB_VRC5477) ==
+ ddb_calc_pdar(DDB_VRC5477_BASE, DDB_VRC5477_SIZE, 32, 0, 1));
+
+ /* verify BOOT ROM addr */
+ MIPS_ASSERT(ddb_in32(DDB_BOOTCS) ==
+ ddb_calc_pdar(DDB_BOOTCS_BASE, DDB_BOOTCS_SIZE, 8, 0, 0));
+
+ /* setup PCI windows - window0 for MEM/config, window1 for IO */
+ ddb_set_pdar(DDB_PCIW0, DDB_PCI0_MEM_BASE, DDB_PCI0_MEM_SIZE, 32, 0, 1);
+ ddb_set_pdar(DDB_PCIW1, DDB_PCI0_IO_BASE, DDB_PCI0_IO_SIZE, 32, 0, 1);
+ ddb_set_pdar(DDB_IOPCIW0, DDB_PCI1_MEM_BASE, DDB_PCI1_MEM_SIZE, 32, 0, 1);
+ ddb_set_pdar(DDB_IOPCIW1, DDB_PCI1_IO_BASE, DDB_PCI1_IO_SIZE, 32, 0, 1);
+
+ /* ------------ reset PCI bus and BARs ----------------- */
+ ddb_pci_reset_bus();
+
+ ddb_out32(DDB_BARM010, 0x00000008);
+ ddb_out32(DDB_BARM011, 0x00000008);
+
+ ddb_out32(DDB_BARC0, 0xffffffff);
+ ddb_out32(DDB_BARM230, 0xffffffff);
+ ddb_out32(DDB_BAR00, 0xffffffff);
+ ddb_out32(DDB_BAR10, 0xffffffff);
+ ddb_out32(DDB_BAR20, 0xffffffff);
+ ddb_out32(DDB_BAR30, 0xffffffff);
+ ddb_out32(DDB_BAR40, 0xffffffff);
+ ddb_out32(DDB_BAR50, 0xffffffff);
+ ddb_out32(DDB_BARB0, 0xffffffff);
+
+ ddb_out32(DDB_BARC1, 0xffffffff);
+ ddb_out32(DDB_BARM231, 0xffffffff);
+ ddb_out32(DDB_BAR01, 0xffffffff);
+ ddb_out32(DDB_BAR11, 0xffffffff);
+ ddb_out32(DDB_BAR21, 0xffffffff);
+ ddb_out32(DDB_BAR31, 0xffffffff);
+ ddb_out32(DDB_BAR41, 0xffffffff);
+ ddb_out32(DDB_BAR51, 0xffffffff);
+ ddb_out32(DDB_BARB1, 0xffffffff);
+
+ /*
+ * We use pci master register 0 for memory space / config space
+ * And we use register 1 for IO space.
+ * Note that for memory space, we bump up the pci base address
+ * so that we have 1:1 mapping between PCI memory and cpu physical.
+ * For PCI IO space, it starts from 0 in PCI IO space but with
+ * DDB_xx_IO_BASE in CPU physical address space.
+ */
+ ddb_set_pmr(DDB_PCIINIT00, DDB_PCICMD_MEM, DDB_PCI0_MEM_BASE,
+ DDB_PCI_ACCESS_32);
+ ddb_set_pmr(DDB_PCIINIT10, DDB_PCICMD_IO, 0, DDB_PCI_ACCESS_32);
+
+ ddb_set_pmr(DDB_PCIINIT01, DDB_PCICMD_MEM, DDB_PCI1_MEM_BASE,
+ DDB_PCI_ACCESS_32);
+ ddb_set_pmr(DDB_PCIINIT11, DDB_PCICMD_IO, DDB_PCI0_IO_SIZE,
+ DDB_PCI_ACCESS_32);
+
+
+ /* PCI cross window should be set properly */
+ ddb_set_pdar(DDB_BARP00, DDB_PCI1_MEM_BASE, DDB_PCI1_MEM_SIZE, 32, 0, 1);
+ ddb_set_pdar(DDB_BARP10, DDB_PCI1_IO_BASE, DDB_PCI1_IO_SIZE, 32, 0, 1);
+ ddb_set_pdar(DDB_BARP01, DDB_PCI0_MEM_BASE, DDB_PCI0_MEM_SIZE, 32, 0, 1);
+ ddb_set_pdar(DDB_BARP11, DDB_PCI0_IO_BASE, DDB_PCI0_IO_SIZE, 32, 0, 1);
+
+ /* enable USB input buffers */
+ ddb_out32(DDB_PIBMISC, 0x00000007);
+
+ /* For dual-function pins, make them all non-GPIO */
+ ddb_out32(DDB_GIUFUNSEL, 0x0);
+ // ddb_out32(DDB_GIUFUNSEL, 0xfe0fcfff); /* NEC recommanded value */
+}
diff --git a/arch/mips/defconfig b/arch/mips/defconfig
index 34ee3e8ea..6d63c50ae 100644
--- a/arch/mips/defconfig
+++ b/arch/mips/defconfig
@@ -25,6 +25,7 @@ CONFIG_EXPERIMENTAL=y
# CONFIG_MIPS_MAGNUM_4000 is not set
# CONFIG_MOMENCO_OCELOT is not set
# CONFIG_DDB5476 is not set
+# CONFIG_DDB5477 is not set
# CONFIG_OLIVETTI_M700 is not set
CONFIG_SGI_IP22=y
# CONFIG_SNI_RM200_PCI is not set
diff --git a/arch/mips/defconfig-atlas b/arch/mips/defconfig-atlas
index 27eaadd48..2c739d374 100644
--- a/arch/mips/defconfig-atlas
+++ b/arch/mips/defconfig-atlas
@@ -25,6 +25,7 @@ CONFIG_MIPS_ATLAS=y
# CONFIG_MIPS_MAGNUM_4000 is not set
# CONFIG_MOMENCO_OCELOT is not set
# CONFIG_DDB5476 is not set
+# CONFIG_DDB5477 is not set
# CONFIG_OLIVETTI_M700 is not set
# CONFIG_SGI_IP22 is not set
# CONFIG_SNI_RM200_PCI is not set
diff --git a/arch/mips/defconfig-ddb5476 b/arch/mips/defconfig-ddb5476
index 018f9ac65..d1f2703fe 100644
--- a/arch/mips/defconfig-ddb5476
+++ b/arch/mips/defconfig-ddb5476
@@ -25,6 +25,7 @@ CONFIG_EXPERIMENTAL=y
# CONFIG_MIPS_MAGNUM_4000 is not set
# CONFIG_MOMENCO_OCELOT is not set
CONFIG_DDB5476=y
+# CONFIG_DDB5477 is not set
# CONFIG_OLIVETTI_M700 is not set
# CONFIG_SGI_IP22 is not set
# CONFIG_SNI_RM200_PCI is not set
diff --git a/arch/mips/defconfig-ddb5477 b/arch/mips/defconfig-ddb5477
new file mode 100644
index 000000000..c48c6b910
--- /dev/null
+++ b/arch/mips/defconfig-ddb5477
@@ -0,0 +1,449 @@
+#
+# Automatically generated make config: don't edit
+#
+CONFIG_MIPS=y
+# CONFIG_SMP is not set
+
+#
+# Code maturity level options
+#
+CONFIG_EXPERIMENTAL=y
+
+#
+# Machine selection
+#
+# CONFIG_ACER_PICA_61 is not set
+# CONFIG_ALGOR_P4032 is not set
+# CONFIG_BAGET_MIPS is not set
+# CONFIG_DECSTATION is not set
+# CONFIG_DDB5074 is not set
+# CONFIG_MIPS_EV96100 is not set
+# CONFIG_MIPS_EV64120 is not set
+# CONFIG_MIPS_ATLAS is not set
+# CONFIG_MIPS_MALTA is not set
+# CONFIG_NINO is not set
+# CONFIG_MIPS_MAGNUM_4000 is not set
+# CONFIG_MOMENCO_OCELOT is not set
+# CONFIG_DDB5476 is not set
+CONFIG_DDB5477=y
+# CONFIG_OLIVETTI_M700 is not set
+# CONFIG_SGI_IP22 is not set
+# CONFIG_SNI_RM200_PCI is not set
+# CONFIG_MIPS_ITE8172 is not set
+# CONFIG_MIPS_IVR is not set
+# CONFIG_MIPS_PB1000 is not set
+# CONFIG_MCA is not set
+# CONFIG_SBUS is not set
+CONFIG_CPU_LITTLE_ENDIAN=y
+CONFIG_PCI=y
+CONFIG_NEW_TIME_C=y
+CONFIG_NEW_IRQ=y
+# CONFIG_ISA is not set
+# CONFIG_EISA is not set
+# CONFIG_I8259 is not set
+
+#
+# Loadable module support
+#
+# CONFIG_MODULES is not set
+
+#
+# CPU selection
+#
+# CONFIG_CPU_R3000 is not set
+# CONFIG_CPU_R6000 is not set
+# CONFIG_CPU_R4300 is not set
+# CONFIG_CPU_R4X00 is not set
+# CONFIG_CPU_R5000 is not set
+CONFIG_CPU_R5432=y
+# CONFIG_CPU_RM7000 is not set
+# CONFIG_CPU_NEVADA is not set
+# CONFIG_CPU_R10000 is not set
+# CONFIG_CPU_SB1 is not set
+# CONFIG_CPU_MIPS32 is not set
+# CONFIG_CPU_ADVANCED is not set
+CONFIG_CPU_HAS_LLSC=y
+# CONFIG_CPU_HAS_WB is not set
+
+#
+# General setup
+#
+CONFIG_CPU_LITTLE_ENDIAN=y
+CONFIG_MIPS_FPU_EMULATOR=y
+CONFIG_KCORE_ELF=y
+CONFIG_ELF_KERNEL=y
+# CONFIG_BINFMT_AOUT is not set
+CONFIG_BINFMT_ELF=y
+# CONFIG_BINFMT_MISC is not set
+CONFIG_NET=y
+# CONFIG_PCI_NAMES is not set
+# CONFIG_HOTPLUG is not set
+# CONFIG_PCMCIA is not set
+CONFIG_SYSVIPC=y
+# CONFIG_BSD_PROCESS_ACCT is not set
+CONFIG_SYSCTL=y
+
+#
+# Memory Technology Devices (MTD)
+#
+# CONFIG_MTD is not set
+
+#
+# Parallel port support
+#
+# CONFIG_PARPORT is not set
+
+#
+# Block devices
+#
+# CONFIG_BLK_DEV_FD is not set
+# CONFIG_BLK_DEV_XD is not set
+# CONFIG_PARIDE is not set
+# CONFIG_BLK_CPQ_DA is not set
+# CONFIG_BLK_CPQ_CISS_DA is not set
+# CONFIG_BLK_DEV_DAC960 is not set
+# CONFIG_BLK_DEV_LOOP is not set
+# CONFIG_BLK_DEV_NBD is not set
+# CONFIG_BLK_DEV_RAM is not set
+# CONFIG_BLK_DEV_INITRD is not set
+
+#
+# Multi-device support (RAID and LVM)
+#
+# CONFIG_MD is not set
+# CONFIG_BLK_DEV_MD is not set
+# CONFIG_MD_LINEAR is not set
+# CONFIG_MD_RAID0 is not set
+# CONFIG_MD_RAID1 is not set
+# CONFIG_MD_RAID5 is not set
+# CONFIG_BLK_DEV_LVM is not set
+
+#
+# Networking options
+#
+CONFIG_PACKET=y
+# CONFIG_PACKET_MMAP is not set
+# CONFIG_NETLINK is not set
+# CONFIG_NETFILTER is not set
+# CONFIG_FILTER is not set
+CONFIG_UNIX=y
+CONFIG_INET=y
+# CONFIG_IP_MULTICAST is not set
+# CONFIG_IP_ADVANCED_ROUTER is not set
+CONFIG_IP_PNP=y
+CONFIG_IP_PNP_BOOTP=y
+# CONFIG_IP_PNP_RARP is not set
+# CONFIG_NET_IPIP is not set
+# CONFIG_NET_IPGRE is not set
+# CONFIG_INET_ECN is not set
+# CONFIG_SYN_COOKIES is not set
+# CONFIG_IPV6 is not set
+# CONFIG_KHTTPD is not set
+# CONFIG_ATM is not set
+
+#
+#
+#
+# CONFIG_IPX is not set
+# CONFIG_ATALK is not set
+# CONFIG_DECNET is not set
+# CONFIG_BRIDGE is not set
+# CONFIG_X25 is not set
+# CONFIG_LAPB is not set
+# CONFIG_LLC is not set
+# CONFIG_NET_DIVERT is not set
+# CONFIG_ECONET is not set
+# CONFIG_WAN_ROUTER is not set
+# CONFIG_NET_FASTROUTE is not set
+# CONFIG_NET_HW_FLOWCONTROL is not set
+
+#
+# QoS and/or fair queueing
+#
+# CONFIG_NET_SCHED is not set
+
+#
+# Telephony Support
+#
+# CONFIG_PHONE is not set
+# CONFIG_PHONE_IXJ is not set
+
+#
+# ATA/IDE/MFM/RLL support
+#
+# CONFIG_IDE is not set
+# CONFIG_BLK_DEV_IDE_MODES is not set
+# CONFIG_BLK_DEV_HD is not set
+
+#
+# SCSI support
+#
+# CONFIG_SCSI is not set
+
+#
+# I2O device support
+#
+# CONFIG_I2O is not set
+# CONFIG_I2O_PCI is not set
+# CONFIG_I2O_BLOCK is not set
+# CONFIG_I2O_LAN is not set
+# CONFIG_I2O_SCSI is not set
+# CONFIG_I2O_PROC is not set
+
+#
+# Network device support
+#
+CONFIG_NETDEVICES=y
+
+#
+# ARCnet devices
+#
+# CONFIG_ARCNET is not set
+# CONFIG_DUMMY is not set
+# CONFIG_BONDING is not set
+# CONFIG_EQUALIZER is not set
+# CONFIG_TUN is not set
+# CONFIG_NET_SB1000 is not set
+
+#
+# Ethernet (10 or 100Mbit)
+#
+CONFIG_NET_ETHERNET=y
+# CONFIG_NET_VENDOR_3COM is not set
+# CONFIG_LANCE is not set
+# CONFIG_NET_VENDOR_SMC is not set
+# CONFIG_NET_VENDOR_RACAL is not set
+# CONFIG_AT1700 is not set
+# CONFIG_DEPCA is not set
+# CONFIG_HP100 is not set
+# CONFIG_NET_ISA is not set
+CONFIG_NET_PCI=y
+# CONFIG_PCNET32 is not set
+# CONFIG_ADAPTEC_STARFIRE is not set
+# CONFIG_APRICOT is not set
+# CONFIG_CS89x0 is not set
+CONFIG_TULIP=y
+# CONFIG_DE4X5 is not set
+# CONFIG_DGRS is not set
+# CONFIG_DM9102 is not set
+# CONFIG_EEPRO100 is not set
+# CONFIG_EEPRO100_PM is not set
+# CONFIG_LNE390 is not set
+# CONFIG_NATSEMI is not set
+# CONFIG_NE2K_PCI is not set
+# CONFIG_NE3210 is not set
+# CONFIG_ES3210 is not set
+# CONFIG_8139TOO is not set
+# CONFIG_8139TOO_PIO is not set
+# CONFIG_8139TOO_TUNE_TWISTER is not set
+# CONFIG_8139TOO_8129 is not set
+# CONFIG_SIS900 is not set
+# CONFIG_EPIC100 is not set
+# CONFIG_SUNDANCE is not set
+# CONFIG_TLAN is not set
+# CONFIG_VIA_RHINE is not set
+# CONFIG_WINBOND_840 is not set
+# CONFIG_HAPPYMEAL is not set
+# CONFIG_LAN_SAA9730 is not set
+# CONFIG_NET_POCKET is not set
+
+#
+# Ethernet (1000 Mbit)
+#
+# CONFIG_ACENIC is not set
+# CONFIG_HAMACHI is not set
+# CONFIG_YELLOWFIN is not set
+# CONFIG_SK98LIN is not set
+# CONFIG_FDDI is not set
+# CONFIG_HIPPI is not set
+# CONFIG_PPP is not set
+# CONFIG_SLIP is not set
+
+#
+# Wireless LAN (non-hamradio)
+#
+# CONFIG_NET_RADIO is not set
+
+#
+# Token Ring devices
+#
+# CONFIG_TR is not set
+# CONFIG_NET_FC is not set
+# CONFIG_RCPCI is not set
+# CONFIG_SHAPER is not set
+
+#
+# Wan interfaces
+#
+# CONFIG_WAN is not set
+
+#
+# Amateur Radio support
+#
+# CONFIG_HAMRADIO is not set
+
+#
+# IrDA (infrared) support
+#
+# CONFIG_IRDA is not set
+
+#
+# ISDN subsystem
+#
+# CONFIG_ISDN is not set
+
+#
+# Old CD-ROM drivers (not SCSI, not IDE)
+#
+# CONFIG_CD_NO_IDESCSI is not set
+
+#
+# Character devices
+#
+# CONFIG_VT is not set
+CONFIG_SERIAL=y
+CONFIG_SERIAL_CONSOLE=y
+# CONFIG_SERIAL_EXTENDED is not set
+# CONFIG_SERIAL_NONSTANDARD is not set
+# CONFIG_UNIX98_PTYS is not set
+
+#
+# I2C support
+#
+# CONFIG_I2C is not set
+
+#
+# Mice
+#
+# CONFIG_BUSMOUSE is not set
+# CONFIG_MOUSE is not set
+
+#
+# Joysticks
+#
+# CONFIG_JOYSTICK is not set
+
+#
+# Input core support is needed for joysticks
+#
+# CONFIG_QIC02_TAPE is not set
+
+#
+# Watchdog Cards
+#
+# CONFIG_WATCHDOG is not set
+# CONFIG_INTEL_RNG is not set
+# CONFIG_NVRAM is not set
+# CONFIG_RTC is not set
+# CONFIG_DTLK is not set
+# CONFIG_R3964 is not set
+# CONFIG_APPLICOM is not set
+
+#
+# Ftape, the floppy tape device driver
+#
+# CONFIG_FTAPE is not set
+# CONFIG_AGP is not set
+# CONFIG_DRM is not set
+
+#
+# Multimedia devices
+#
+# CONFIG_VIDEO_DEV is not set
+
+#
+# File systems
+#
+# CONFIG_QUOTA is not set
+CONFIG_AUTOFS_FS=y
+CONFIG_AUTOFS4_FS=y
+# CONFIG_REISERFS_FS is not set
+# CONFIG_REISERFS_CHECK is not set
+# CONFIG_ADFS_FS is not set
+# CONFIG_ADFS_FS_RW is not set
+# CONFIG_AFFS_FS is not set
+# CONFIG_HFS_FS is not set
+# CONFIG_BFS_FS is not set
+# CONFIG_FAT_FS is not set
+# CONFIG_MSDOS_FS is not set
+# CONFIG_UMSDOS_FS is not set
+# CONFIG_VFAT_FS is not set
+# CONFIG_EFS_FS is not set
+# CONFIG_JFFS_FS is not set
+# CONFIG_CRAMFS is not set
+# CONFIG_RAMFS is not set
+# CONFIG_ISO9660_FS is not set
+# CONFIG_JOLIET is not set
+# CONFIG_MINIX_FS is not set
+# CONFIG_NTFS_FS is not set
+# CONFIG_NTFS_RW is not set
+# CONFIG_HPFS_FS is not set
+CONFIG_PROC_FS=y
+# CONFIG_DEVFS_FS is not set
+# CONFIG_DEVFS_MOUNT is not set
+# CONFIG_DEVFS_DEBUG is not set
+# CONFIG_DEVPTS_FS is not set
+# CONFIG_QNX4FS_FS is not set
+# CONFIG_QNX4FS_RW is not set
+# CONFIG_ROMFS_FS is not set
+CONFIG_EXT2_FS=y
+# CONFIG_SYSV_FS is not set
+# CONFIG_SYSV_FS_WRITE is not set
+# CONFIG_UDF_FS is not set
+# CONFIG_UDF_RW is not set
+# CONFIG_UFS_FS is not set
+# CONFIG_UFS_FS_WRITE is not set
+
+#
+# Network File Systems
+#
+# CONFIG_CODA_FS is not set
+CONFIG_NFS_FS=y
+# CONFIG_NFS_V3 is not set
+CONFIG_ROOT_NFS=y
+CONFIG_NFSD=y
+# CONFIG_NFSD_V3 is not set
+CONFIG_SUNRPC=y
+CONFIG_LOCKD=y
+# CONFIG_SMB_FS is not set
+# CONFIG_NCP_FS is not set
+# CONFIG_NCPFS_PACKET_SIGNING is not set
+# CONFIG_NCPFS_IOCTL_LOCKING is not set
+# CONFIG_NCPFS_STRONG is not set
+# CONFIG_NCPFS_NFS_NS is not set
+# CONFIG_NCPFS_OS2_NS is not set
+# CONFIG_NCPFS_SMALLDOS is not set
+# CONFIG_NCPFS_NLS is not set
+# CONFIG_NCPFS_EXTRAS is not set
+
+#
+# Partition Types
+#
+# CONFIG_PARTITION_ADVANCED is not set
+CONFIG_MSDOS_PARTITION=y
+# CONFIG_SMB_NLS is not set
+# CONFIG_NLS is not set
+
+#
+# Sound
+#
+# CONFIG_SOUND is not set
+
+#
+# USB support
+#
+# CONFIG_USB is not set
+
+#
+# Input core support
+#
+# CONFIG_INPUT is not set
+
+#
+# Kernel hacking
+#
+CONFIG_CROSSCOMPILE=y
+# CONFIG_REMOTE_DEBUG is not set
+CONFIG_LL_DEBUG=y
+# CONFIG_MAGIC_SYSRQ is not set
+# CONFIG_MIPS_UNCACHED is not set
diff --git a/arch/mips/defconfig-decstation b/arch/mips/defconfig-decstation
index e720e8a5a..5377a15cf 100644
--- a/arch/mips/defconfig-decstation
+++ b/arch/mips/defconfig-decstation
@@ -25,6 +25,7 @@ CONFIG_DECSTATION=y
# CONFIG_MIPS_MAGNUM_4000 is not set
# CONFIG_MOMENCO_OCELOT is not set
# CONFIG_DDB5476 is not set
+# CONFIG_DDB5477 is not set
# CONFIG_OLIVETTI_M700 is not set
# CONFIG_SGI_IP22 is not set
# CONFIG_SNI_RM200_PCI is not set
diff --git a/arch/mips/defconfig-ev64120 b/arch/mips/defconfig-ev64120
index d03094048..38f5e310e 100644
--- a/arch/mips/defconfig-ev64120
+++ b/arch/mips/defconfig-ev64120
@@ -29,6 +29,7 @@ CONFIG_SYSCLK_100=y
# CONFIG_MIPS_MAGNUM_4000 is not set
# CONFIG_MOMENCO_OCELOT is not set
# CONFIG_DDB5476 is not set
+# CONFIG_DDB5477 is not set
# CONFIG_OLIVETTI_M700 is not set
# CONFIG_SGI_IP22 is not set
# CONFIG_SNI_RM200_PCI is not set
diff --git a/arch/mips/defconfig-ev96100 b/arch/mips/defconfig-ev96100
index ba5484881..692c410dc 100644
--- a/arch/mips/defconfig-ev96100
+++ b/arch/mips/defconfig-ev96100
@@ -25,6 +25,7 @@ CONFIG_MIPS_EV96100=y
# CONFIG_MIPS_MAGNUM_4000 is not set
# CONFIG_MOMENCO_OCELOT is not set
# CONFIG_DDB5476 is not set
+# CONFIG_DDB5477 is not set
# CONFIG_OLIVETTI_M700 is not set
# CONFIG_SGI_IP22 is not set
# CONFIG_SNI_RM200_PCI is not set
diff --git a/arch/mips/defconfig-ip22 b/arch/mips/defconfig-ip22
index 34ee3e8ea..6d63c50ae 100644
--- a/arch/mips/defconfig-ip22
+++ b/arch/mips/defconfig-ip22
@@ -25,6 +25,7 @@ CONFIG_EXPERIMENTAL=y
# CONFIG_MIPS_MAGNUM_4000 is not set
# CONFIG_MOMENCO_OCELOT is not set
# CONFIG_DDB5476 is not set
+# CONFIG_DDB5477 is not set
# CONFIG_OLIVETTI_M700 is not set
CONFIG_SGI_IP22=y
# CONFIG_SNI_RM200_PCI is not set
diff --git a/arch/mips/defconfig-it8172 b/arch/mips/defconfig-it8172
index fa9e7d07f..c69a210e6 100644
--- a/arch/mips/defconfig-it8172
+++ b/arch/mips/defconfig-it8172
@@ -25,6 +25,7 @@ CONFIG_EXPERIMENTAL=y
# CONFIG_MIPS_MAGNUM_4000 is not set
# CONFIG_MOMENCO_OCELOT is not set
# CONFIG_DDB5476 is not set
+# CONFIG_DDB5477 is not set
# CONFIG_OLIVETTI_M700 is not set
# CONFIG_SGI_IP22 is not set
# CONFIG_SNI_RM200_PCI is not set
diff --git a/arch/mips/defconfig-malta b/arch/mips/defconfig-malta
index 0786d4a8a..c41368745 100644
--- a/arch/mips/defconfig-malta
+++ b/arch/mips/defconfig-malta
@@ -25,6 +25,7 @@ CONFIG_MIPS_MALTA=y
# CONFIG_MIPS_MAGNUM_4000 is not set
# CONFIG_MOMENCO_OCELOT is not set
# CONFIG_DDB5476 is not set
+# CONFIG_DDB5477 is not set
# CONFIG_OLIVETTI_M700 is not set
# CONFIG_SGI_IP22 is not set
# CONFIG_SNI_RM200_PCI is not set
diff --git a/arch/mips/defconfig-nino b/arch/mips/defconfig-nino
index a82abd780..f2bff50a9 100644
--- a/arch/mips/defconfig-nino
+++ b/arch/mips/defconfig-nino
@@ -28,6 +28,7 @@ CONFIG_NINO_8MB=y
# CONFIG_MIPS_MAGNUM_4000 is not set
# CONFIG_MOMENCO_OCELOT is not set
# CONFIG_DDB5476 is not set
+# CONFIG_DDB5477 is not set
# CONFIG_OLIVETTI_M700 is not set
# CONFIG_SGI_IP22 is not set
# CONFIG_SNI_RM200_PCI is not set
diff --git a/arch/mips/defconfig-ocelot b/arch/mips/defconfig-ocelot
index 15fe6a913..ca08241b9 100644
--- a/arch/mips/defconfig-ocelot
+++ b/arch/mips/defconfig-ocelot
@@ -25,6 +25,7 @@ CONFIG_EXPERIMENTAL=y
# CONFIG_MIPS_MAGNUM_4000 is not set
CONFIG_MOMENCO_OCELOT=y
# CONFIG_DDB5476 is not set
+# CONFIG_DDB5477 is not set
# CONFIG_OLIVETTI_M700 is not set
# CONFIG_SGI_IP22 is not set
# CONFIG_SNI_RM200_PCI is not set
diff --git a/arch/mips/defconfig-pb1000 b/arch/mips/defconfig-pb1000
index e3aab82d6..e0f3befa2 100644
--- a/arch/mips/defconfig-pb1000
+++ b/arch/mips/defconfig-pb1000
@@ -25,6 +25,7 @@ CONFIG_EXPERIMENTAL=y
# CONFIG_MIPS_MAGNUM_4000 is not set
# CONFIG_MOMENCO_OCELOT is not set
# CONFIG_DDB5476 is not set
+# CONFIG_DDB5477 is not set
# CONFIG_OLIVETTI_M700 is not set
# CONFIG_SGI_IP22 is not set
# CONFIG_SNI_RM200_PCI is not set
diff --git a/arch/mips/defconfig-rm200 b/arch/mips/defconfig-rm200
index 5cc2d9e5f..0183c4ca0 100644
--- a/arch/mips/defconfig-rm200
+++ b/arch/mips/defconfig-rm200
@@ -25,6 +25,7 @@ CONFIG_EXPERIMENTAL=y
# CONFIG_MIPS_MAGNUM_4000 is not set
# CONFIG_MOMENCO_OCELOT is not set
# CONFIG_DDB5476 is not set
+# CONFIG_DDB5477 is not set
# CONFIG_OLIVETTI_M700 is not set
# CONFIG_SGI_IP22 is not set
CONFIG_SNI_RM200_PCI=y
diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
index ce3016c55..61715e9e3 100644
--- a/arch/mips/kernel/setup.c
+++ b/arch/mips/kernel/setup.c
@@ -592,6 +592,11 @@ void __init setup_arch(char **cmdline_p)
ddb_setup();
break;
#endif
+#ifdef CONFIG_DDB5477
+ case MACH_GROUP_NEC_DDB:
+ ddb_setup();
+ break;
+#endif
#ifdef CONFIG_MIPS_EV96100
case MACH_GROUP_GALILEO:
ev96100_setup();
diff --git a/drivers/sound/Config.in b/drivers/sound/Config.in
index 51fd93356..65971de2c 100644
--- a/drivers/sound/Config.in
+++ b/drivers/sound/Config.in
@@ -27,6 +27,9 @@ dep_tristate ' S3 SonicVibes' CONFIG_SOUND_SONICVIBES $CONFIG_SOUND
if [ "$CONFIG_VISWS" = "y" ]; then
dep_tristate ' SGI Visual Workstation Sound' CONFIG_SOUND_VWSND $CONFIG_SOUND
fi
+if [ "$CONFIG_DDB5477" = "y" ]; then
+ dep_tristate ' NEC Vrc5477 AC97 sound' CONFIG_SOUND_VRC5477 $CONFIG_SOUND
+fi
dep_tristate ' Trident 4DWave DX/NX, SiS 7018 or ALi 5451 PCI Audio Core' CONFIG_SOUND_TRIDENT $CONFIG_SOUND
diff --git a/drivers/sound/Makefile b/drivers/sound/Makefile
index baddec56f..b7f697bc9 100644
--- a/drivers/sound/Makefile
+++ b/drivers/sound/Makefile
@@ -60,6 +60,7 @@ obj-$(CONFIG_SOUND_SONICVIBES) += sonicvibes.o
obj-$(CONFIG_SOUND_CMPCI) += cmpci.o
obj-$(CONFIG_SOUND_ES1370) += es1370.o
obj-$(CONFIG_SOUND_ES1371) += es1371.o ac97_codec.o
+obj-$(CONFIG_SOUND_VRC5477) += nec_vrc5477.o ac97_codec.o
obj-$(CONFIG_SOUND_ESSSOLO1) += esssolo1.o
obj-$(CONFIG_SOUND_FUSION) += cs46xx.o ac97_codec.o
obj-$(CONFIG_SOUND_MAESTRO) += maestro.o
diff --git a/drivers/sound/ac97.h b/drivers/sound/ac97.h
index 294000f6d..6353b79b6 100644
--- a/drivers/sound/ac97.h
+++ b/drivers/sound/ac97.h
@@ -39,7 +39,7 @@
#define AC97_PCM_FRONT_DAC_RATE 0x002C /* PCM Front DAC Rate */
#define AC97_PCM_SURR_DAC_RATE 0x002E /* PCM Surround DAC Rate */
#define AC97_PCM_LFE_DAC_RATE 0x0030 /* PCM LFE DAC Rate */
-#define AC97_PCM_LR_DAC_RATE 0x0032 /* PCM LR DAC Rate */
+#define AC97_PCM_LR_ADC_RATE 0x0032 /* PCM LR DAC Rate */
#define AC97_PCM_MIC_ADC_RATE 0x0034 /* PCM MIC ADC Rate */
#define AC97_CENTER_LFE_MASTER 0x0036 /* Center + LFE Master Volume */
#define AC97_SURROUND_MASTER 0x0038 /* Surround (Rear) Master Volume */
diff --git a/drivers/sound/i810_audio.c b/drivers/sound/i810_audio.c
index eaed7d132..69c8c854d 100644
--- a/drivers/sound/i810_audio.c
+++ b/drivers/sound/i810_audio.c
@@ -457,14 +457,14 @@ static unsigned int i810_set_adc_rate(struct i810_state * state, unsigned int ra
rate = ( rate * clocking)/48000;
- if(rate != i810_ac97_get(codec, AC97_PCM_LR_DAC_RATE))
+ if(rate != i810_ac97_get(codec, AC97_PCM_LR_ADC_RATE))
{
/* Power down the ADC */
dacp=i810_ac97_get(codec, AC97_POWER_CONTROL);
i810_ac97_set(codec, AC97_POWER_CONTROL, dacp|0x0100);
/* Load the rate and read the effective rate */
- i810_ac97_set(codec, AC97_PCM_LR_DAC_RATE, rate);
- new_rate=i810_ac97_get(codec, AC97_PCM_LR_DAC_RATE);
+ i810_ac97_set(codec, AC97_PCM_LR_ADC_RATE, rate);
+ new_rate=i810_ac97_get(codec, AC97_PCM_LR_ADC_RATE);
/* Power it back up */
i810_ac97_set(codec, AC97_POWER_CONTROL, dacp);
if(new_rate != rate) {
diff --git a/drivers/sound/nec_vrc5477.c b/drivers/sound/nec_vrc5477.c
new file mode 100644
index 000000000..efd8d8e7d
--- /dev/null
+++ b/drivers/sound/nec_vrc5477.c
@@ -0,0 +1,2045 @@
+/***********************************************************************
+ * Copyright 2001 MontaVista Software Inc.
+ * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
+ *
+ * drivers/sound/nec_vrc5477.c
+ * AC97 sound dirver for NEC Vrc5477 chip (an integrated,
+ * multi-function controller chip for MIPS CPUs)
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ ***********************************************************************
+ */
+
+/*
+ * This code is derived from ite8172.c, which is written by Steve Longerbeam.
+ *
+ * Features:
+ * Currently we only support the following capabilities:
+ * . mono output to PCM L/R (line out).
+ * . stereo output to PCM L/R (line out).
+ * . mono input from PCM L (line in).
+ * . stereo output from PCM (line in).
+ * . sampling rate at 48k or variable sampling rate
+ * . support /dev/dsp, /dev/mixer devices, standard OSS devices.
+ * . only support 16-bit PCM format (hardware limit, no software
+ * translation)
+ * . support duplex, but no trigger or realtime.
+ *
+ * Specifically the following are not supported:
+ * . app-set frag size.
+ * . mmap'ed buffer access
+ */
+
+/*
+ * Original comments from ite8172.c file.
+ */
+
+/*
+ *
+ * Notes:
+ *
+ * 1. Much of the OSS buffer allocation, ioctl's, and mmap'ing are
+ * taken, slightly modified or not at all, from the ES1371 driver,
+ * so refer to the credits in es1371.c for those. The rest of the
+ * code (probe, open, read, write, the ISR, etc.) is new.
+ * 2. The following support is untested:
+ * * Memory mapping the audio buffers, and the ioctl controls that go
+ * with it.
+ * * S/PDIF output.
+ * 3. The following is not supported:
+ * * I2S input.
+ * * legacy audio mode.
+ * 4. Support for volume button interrupts is implemented but doesn't
+ * work yet.
+ *
+ * Revision history
+ * 02.08.2001 0.1 Initial release
+ */
+
+#include <linux/version.h>
+#include <linux/module.h>
+#include <linux/string.h>
+#include <linux/kernel.h>
+#include <linux/ioport.h>
+#include <linux/sched.h>
+#include <linux/delay.h>
+#include <linux/sound.h>
+#include <linux/malloc.h>
+#include <linux/soundcard.h>
+#include <linux/pci.h>
+#include <linux/init.h>
+#include <linux/poll.h>
+#include <linux/bitops.h>
+#include <linux/proc_fs.h>
+#include <linux/spinlock.h>
+#include <linux/smp_lock.h>
+#include <linux/ac97_codec.h>
+#include <linux/wrapper.h>
+#include <asm/io.h>
+#include <asm/dma.h>
+#include <asm/uaccess.h>
+#include <asm/hardirq.h>
+
+#include <asm/ddb5xxx/debug.h>
+
+#undef VRC5477_AC97_VERBOSE_DEBUG
+// #define VRC5477_AC97_VERBOSE_DEBUG 1
+
+/* one must turn on CONFIG_LL_DEBUG before VERBOSE_DEBUG is turned */
+#if defined(VRC5477_AC97_VERBOSE_DEBUG)
+#if !defined(CONFIG_LL_DEBUG)
+#error "You must turn CONFIG_LL_DEBUG"
+#endif
+#endif
+
+#if defined(VRC5477_AC97_VERBOSE_DEBUG)
+static u16 inTicket=0; /* check sync between intr & write */
+static u16 outTicket=0;
+#endif
+
+/* --------------------------------------------------------------------- */
+
+#undef OSS_DOCUMENTED_MIXER_SEMANTICS
+
+static const unsigned sample_shift[] = { 0, 1, 1, 2 };
+
+#define VRC5477_INT_CLR 0x0
+#define VRC5477_INT_STATUS 0x0
+#define VRC5477_CODEC_WR 0x4
+#define VRC5477_CODEC_RD 0x8
+#define VRC5477_CTRL 0x18
+#define VRC5477_ACLINK_CTRL 0x1c
+#define VRC5477_INT_MASK 0x24
+
+#define VRC5477_DAC1_CTRL 0x30
+#define VRC5477_DAC1L 0x34
+#define VRC5477_DAC1_BADDR 0x38
+#define VRC5477_DAC2_CTRL 0x3c
+#define VRC5477_DAC2L 0x40
+#define VRC5477_DAC2_BADDR 0x44
+#define VRC5477_DAC3_CTRL 0x48
+#define VRC5477_DAC3L 0x4c
+#define VRC5477_DAC3_BADDR 0x50
+
+#define VRC5477_ADC1_CTRL 0x54
+#define VRC5477_ADC1L 0x58
+#define VRC5477_ADC1_BADDR 0x5c
+#define VRC5477_ADC2_CTRL 0x60
+#define VRC5477_ADC2L 0x64
+#define VRC5477_ADC2_BADDR 0x68
+#define VRC5477_ADC3_CTRL 0x6c
+#define VRC5477_ADC3L 0x70
+#define VRC5477_ADC3_BADDR 0x74
+
+#define VRC5477_CODEC_WR_RWC (1 << 23)
+
+#define VRC5477_CODEC_RD_RRDYA (1 << 31)
+#define VRC5477_CODEC_RD_RRDYD (1 << 30)
+
+#define VRC5477_ACLINK_CTRL_RST_ON (1 << 15)
+#define VRC5477_ACLINK_CTRL_RST_TIME 0x7f
+#define VRC5477_ACLINK_CTRL_SYNC_ON (1 << 30)
+#define VRC5477_ACLINK_CTRL_CK_STOP_ON (1 << 31)
+
+#define VRC5477_CTRL_DAC2ENB (1 << 15)
+#define VRC5477_CTRL_ADC2ENB (1 << 14)
+#define VRC5477_CTRL_DAC1ENB (1 << 13)
+#define VRC5477_CTRL_ADC1ENB (1 << 12)
+
+#define VRC5477_INT_MASK_NMASK (1 << 31)
+#define VRC5477_INT_MASK_DAC1END (1 << 5)
+#define VRC5477_INT_MASK_DAC2END (1 << 4)
+#define VRC5477_INT_MASK_DAC3END (1 << 3)
+#define VRC5477_INT_MASK_ADC1END (1 << 2)
+#define VRC5477_INT_MASK_ADC2END (1 << 1)
+#define VRC5477_INT_MASK_ADC3END (1 << 0)
+
+#define VRC5477_DMA_ACTIVATION (1 << 31)
+#define VRC5477_DMA_WIP (1 << 30)
+
+
+#define VRC5477_AC97_MODULE_NAME "NEC_Vrc5477_audio"
+#define PFX VRC5477_AC97_MODULE_NAME ": "
+
+/* --------------------------------------------------------------------- */
+
+struct vrc5477_ac97_state {
+ /* list of vrc5477_ac97 devices */
+ struct list_head devs;
+
+ /* the corresponding pci_dev structure */
+ struct pci_dev *dev;
+
+ /* soundcore stuff */
+ int dev_audio;
+
+ /* hardware resources */
+ unsigned long io;
+ unsigned int irq;
+
+#ifdef CONFIG_LL_DEBUG
+ /* debug /proc entry */
+ struct proc_dir_entry *ps;
+ struct proc_dir_entry *ac97_ps;
+#endif /* CONFIG_LL_DEBUG */
+
+ struct ac97_codec codec;
+
+ unsigned dacChannels, adcChannels;
+ unsigned short dacRate, adcRate;
+
+ spinlock_t lock;
+ struct semaphore open_sem;
+ mode_t open_mode;
+ wait_queue_head_t open_wait;
+
+ struct dmabuf {
+ void *lbuf, *rbuf;
+ dma_addr_t lbufDma, rbufDma;
+ unsigned bufOrder;
+ unsigned numFrag;
+ unsigned fragShift;
+ unsigned fragSize; /* redundant */
+ unsigned fragTotalSize; /* = numFrag * fragSize(real) */
+ unsigned nextIn;
+ unsigned nextOut;
+ int count;
+ unsigned error; /* over/underrun */
+ wait_queue_head_t wait;
+ /* OSS stuff */
+ unsigned stopped:1;
+ unsigned ready:1;
+ } dma_dac, dma_adc;
+
+ #define WORK_BUF_SIZE 2048
+ struct {
+ u16 lchannel;
+ u16 rchannel;
+ } workBuf[WORK_BUF_SIZE/4];
+};
+
+/* --------------------------------------------------------------------- */
+
+static LIST_HEAD(devs);
+
+/* --------------------------------------------------------------------- */
+
+extern inline unsigned ld2(unsigned int x)
+{
+ unsigned r = 0;
+
+ if (x >= 0x10000) {
+ x >>= 16;
+ r += 16;
+ }
+ if (x >= 0x100) {
+ x >>= 8;
+ r += 8;
+ }
+ if (x >= 0x10) {
+ x >>= 4;
+ r += 4;
+ }
+ if (x >= 4) {
+ x >>= 2;
+ r += 2;
+ }
+ if (x >= 2)
+ r++;
+ return r;
+}
+
+/* --------------------------------------------------------------------- */
+
+static u16 rdcodec(struct ac97_codec *codec, u8 addr)
+{
+ struct vrc5477_ac97_state *s =
+ (struct vrc5477_ac97_state *)codec->private_data;
+ unsigned long flags;
+ u32 result;
+ int i;
+
+ spin_lock_irqsave(&s->lock, flags);
+
+ /* wait until we can access codec registers */
+ while (inl(s->io + VRC5477_CODEC_WR) & 0x80000000);
+
+ /* write the address and "read" command to codec */
+ addr = addr & 0x7f;
+ outl((addr << 16) | VRC5477_CODEC_WR_RWC, s->io + VRC5477_CODEC_WR);
+
+ /* get the return result */
+ for (i=10000; i; i--); /* workaround hardware bug */
+ while ( (result = inl(s->io + VRC5477_CODEC_RD)) &
+ (VRC5477_CODEC_RD_RRDYA | VRC5477_CODEC_RD_RRDYD) ) {
+ /* we get either addr or data, or both */
+ if (result & VRC5477_CODEC_RD_RRDYA) {
+ MIPS_ASSERT(addr == ((result >> 16) & 0x7f) );
+ }
+ if (result & VRC5477_CODEC_RD_RRDYD) {
+ break;
+ }
+ }
+
+ spin_unlock_irqrestore(&s->lock, flags);
+
+ return result & 0xffff;;
+}
+
+
+static void wrcodec(struct ac97_codec *codec, u8 addr, u16 data)
+{
+ struct vrc5477_ac97_state *s =
+ (struct vrc5477_ac97_state *)codec->private_data;
+ unsigned long flags;
+
+ spin_lock_irqsave(&s->lock, flags);
+
+ /* wait until we can access codec registers */
+ while (inl(s->io + VRC5477_CODEC_WR) & 0x80000000);
+
+ /* write the address and value to codec */
+ outl((addr << 16) | data, s->io + VRC5477_CODEC_WR);
+
+ spin_unlock_irqrestore(&s->lock, flags);
+}
+
+
+static void waitcodec(struct ac97_codec *codec)
+{
+ struct vrc5477_ac97_state *s =
+ (struct vrc5477_ac97_state *)codec->private_data;
+
+ /* wait until we can access codec registers */
+ while (inl(s->io + VRC5477_CODEC_WR) & 0x80000000);
+}
+
+
+/* --------------------------------------------------------------------- */
+
+static void vrc5477_ac97_delay(int msec)
+{
+ unsigned long tmo;
+ signed long tmo2;
+
+ if (in_interrupt())
+ return;
+
+ tmo = jiffies + (msec*HZ)/1000;
+ for (;;) {
+ tmo2 = tmo - jiffies;
+ if (tmo2 <= 0)
+ break;
+ schedule_timeout(tmo2);
+ }
+}
+
+
+static void set_adc_rate(struct vrc5477_ac97_state *s, unsigned rate)
+{
+ wrcodec(&s->codec, AC97_PCM_LR_ADC_RATE, rate);
+ s->adcRate = rate;
+}
+
+
+static void set_dac_rate(struct vrc5477_ac97_state *s, unsigned rate)
+{
+ wrcodec(&s->codec, AC97_PCM_FRONT_DAC_RATE, rate);
+ s->dacRate = rate;
+}
+
+
+/* --------------------------------------------------------------------- */
+
+extern inline void
+stop_dac(struct vrc5477_ac97_state *s)
+{
+ struct dmabuf* db = &s->dma_dac;
+ unsigned long flags;
+ u32 temp;
+
+ spin_lock_irqsave(&s->lock, flags);
+
+ if (db->stopped) {
+ spin_unlock_irqrestore(&s->lock, flags);
+ return;
+ }
+
+ /* deactivate the dma */
+ outl(0, s->io + VRC5477_DAC1_CTRL);
+ outl(0, s->io + VRC5477_DAC2_CTRL);
+
+ /* wait for DAM completely stop */
+ while (inl(s->io + VRC5477_DAC1_CTRL) & VRC5477_DMA_WIP);
+ while (inl(s->io + VRC5477_DAC2_CTRL) & VRC5477_DMA_WIP);
+
+ /* disable dac slots in aclink */
+ temp = inl(s->io + VRC5477_CTRL);
+ temp &= ~ (VRC5477_CTRL_DAC1ENB | VRC5477_CTRL_DAC2ENB);
+ outl (temp, s->io + VRC5477_CTRL);
+
+ /* disable interrupts */
+ temp = inl(s->io + VRC5477_INT_MASK);
+ temp &= ~ (VRC5477_INT_MASK_DAC1END | VRC5477_INT_MASK_DAC2END);
+ outl (temp, s->io + VRC5477_INT_MASK);
+
+ /* clear pending ones */
+ outl(VRC5477_INT_MASK_DAC1END | VRC5477_INT_MASK_DAC2END,
+ s->io + VRC5477_INT_CLR);
+
+ db->stopped = 1;
+
+ spin_unlock_irqrestore(&s->lock, flags);
+}
+
+static void start_dac(struct vrc5477_ac97_state *s)
+{
+ struct dmabuf* db = &s->dma_dac;
+ unsigned long flags;
+ u32 dmaLength;
+ u32 temp;
+
+ spin_lock_irqsave(&s->lock, flags);
+
+ if (!db->stopped) {
+ spin_unlock_irqrestore(&s->lock, flags);
+ return;
+ }
+
+ /* we should have some data to do the DMA trasnfer */
+ MIPS_ASSERT(db->count >= db->fragSize);
+
+ /* clear pending fales interrupts */
+ outl(VRC5477_INT_MASK_DAC1END | VRC5477_INT_MASK_DAC2END,
+ s->io + VRC5477_INT_CLR);
+
+ /* enable interrupts */
+ temp = inl(s->io + VRC5477_INT_MASK);
+ temp |= VRC5477_INT_MASK_DAC1END | VRC5477_INT_MASK_DAC2END;
+ outl(temp, s->io + VRC5477_INT_MASK);
+
+ /* setup dma base addr */
+ outl(db->lbufDma + db->nextOut, s->io + VRC5477_DAC1_BADDR);
+ if (s->dacChannels == 1) {
+ outl(db->lbufDma + db->nextOut, s->io + VRC5477_DAC2_BADDR);
+ } else {
+ outl(db->rbufDma + db->nextOut, s->io + VRC5477_DAC2_BADDR);
+ }
+
+ /* set dma length, in the unit of 0x10 bytes */
+ dmaLength = db->fragSize >> 4;
+ outl(dmaLength, s->io + VRC5477_DAC1L);
+ outl(dmaLength, s->io + VRC5477_DAC2L);
+
+ /* activate dma */
+ outl(VRC5477_DMA_ACTIVATION, s->io + VRC5477_DAC1_CTRL);
+ outl(VRC5477_DMA_ACTIVATION, s->io + VRC5477_DAC2_CTRL);
+
+ /* enable dac slots - we should hear the music now! */
+ temp = inl(s->io + VRC5477_CTRL);
+ temp |= (VRC5477_CTRL_DAC1ENB | VRC5477_CTRL_DAC2ENB);
+ outl (temp, s->io + VRC5477_CTRL);
+
+ /* it is time to setup next dma transfer */
+ MIPS_ASSERT(inl(s->io + VRC5477_DAC1_CTRL) & VRC5477_DMA_WIP);
+ MIPS_ASSERT(inl(s->io + VRC5477_DAC2_CTRL) & VRC5477_DMA_WIP);
+
+ temp = db->nextOut + db->fragSize;
+ if (temp >= db->fragTotalSize) {
+ MIPS_ASSERT(temp == db->fragTotalSize);
+ temp = 0;
+ }
+
+ outl(db->lbufDma + temp, s->io + VRC5477_DAC1_BADDR);
+ if (s->dacChannels == 1) {
+ outl(db->lbufDma + temp, s->io + VRC5477_DAC2_BADDR);
+ } else {
+ outl(db->rbufDma + temp, s->io + VRC5477_DAC2_BADDR);
+ }
+
+ db->stopped = 0;
+
+#if defined(VRC5477_AC97_VERBOSE_DEBUG)
+ outTicket = *(u16*)(db->lbuf+db->nextOut);
+ if (db->count > db->fragSize) {
+ MIPS_ASSERT((u16)(outTicket+1) == *(u16*)(db->lbuf+temp));
+ }
+#endif
+
+ spin_unlock_irqrestore(&s->lock, flags);
+}
+
+extern inline void stop_adc(struct vrc5477_ac97_state *s)
+{
+ struct dmabuf* db = &s->dma_adc;
+ unsigned long flags;
+ u32 temp;
+
+ spin_lock_irqsave(&s->lock, flags);
+
+ if (db->stopped) {
+ spin_unlock_irqrestore(&s->lock, flags);
+ return;
+ }
+
+ /* deactivate the dma */
+ outl(0, s->io + VRC5477_ADC1_CTRL);
+ outl(0, s->io + VRC5477_ADC2_CTRL);
+
+ /* disable adc slots in aclink */
+ temp = inl(s->io + VRC5477_CTRL);
+ temp &= ~ (VRC5477_CTRL_ADC1ENB | VRC5477_CTRL_ADC2ENB);
+ outl (temp, s->io + VRC5477_CTRL);
+
+ /* disable interrupts */
+ temp = inl(s->io + VRC5477_INT_MASK);
+ temp &= ~ (VRC5477_INT_MASK_ADC1END | VRC5477_INT_MASK_ADC2END);
+ outl (temp, s->io + VRC5477_INT_MASK);
+
+ /* clear pending ones */
+ outl(VRC5477_INT_MASK_ADC1END | VRC5477_INT_MASK_ADC2END,
+ s->io + VRC5477_INT_CLR);
+
+ db->stopped = 1;
+
+ spin_unlock_irqrestore(&s->lock, flags);
+}
+
+static void start_adc(struct vrc5477_ac97_state *s)
+{
+ struct dmabuf* db = &s->dma_adc;
+ unsigned long flags;
+ u32 dmaLength;
+ u32 temp;
+
+ spin_lock_irqsave(&s->lock, flags);
+
+ if (!db->stopped) {
+ spin_unlock_irqrestore(&s->lock, flags);
+ return;
+ }
+
+ /* we should at least have some free space in the buffer */
+ MIPS_ASSERT(db->count < db->fragTotalSize - db->fragSize * 2);
+
+ /* clear pending ones */
+ outl(VRC5477_INT_MASK_ADC1END | VRC5477_INT_MASK_ADC2END,
+ s->io + VRC5477_INT_CLR);
+
+ /* enable interrupts */
+ temp = inl(s->io + VRC5477_INT_MASK);
+ temp |= VRC5477_INT_MASK_ADC1END | VRC5477_INT_MASK_ADC2END;
+ outl(temp, s->io + VRC5477_INT_MASK);
+
+ /* setup dma base addr */
+ outl(db->lbufDma + db->nextIn, s->io + VRC5477_ADC1_BADDR);
+ outl(db->rbufDma + db->nextIn, s->io + VRC5477_ADC2_BADDR);
+
+ /* setup dma length */
+ dmaLength = db->fragSize >> 4;
+ outl(dmaLength, s->io + VRC5477_ADC1L);
+ outl(dmaLength, s->io + VRC5477_ADC2L);
+
+ /* activate dma */
+ outl(VRC5477_DMA_ACTIVATION, s->io + VRC5477_ADC1_CTRL);
+ outl(VRC5477_DMA_ACTIVATION, s->io + VRC5477_ADC2_CTRL);
+
+ /* enable adc slots */
+ temp = inl(s->io + VRC5477_CTRL);
+ temp |= (VRC5477_CTRL_ADC1ENB | VRC5477_CTRL_ADC2ENB);
+ outl (temp, s->io + VRC5477_CTRL);
+
+ /* it is time to setup next dma transfer */
+ temp = db->nextIn + db->fragSize;
+ if (temp >= db->fragTotalSize) {
+ MIPS_ASSERT(temp == db->fragTotalSize);
+ temp = 0;
+ }
+ outl(db->lbufDma + temp, s->io + VRC5477_ADC1_BADDR);
+ outl(db->rbufDma + temp, s->io + VRC5477_ADC2_BADDR);
+
+ db->stopped = 0;
+
+ spin_unlock_irqrestore(&s->lock, flags);
+}
+
+/* --------------------------------------------------------------------- */
+
+#define DMABUF_DEFAULTORDER (16-PAGE_SHIFT)
+#define DMABUF_MINORDER 1
+
+extern inline void dealloc_dmabuf(struct vrc5477_ac97_state *s,
+ struct dmabuf *db)
+{
+ if (db->lbuf) {
+ MIPS_ASSERT(db->rbuf);
+ pci_free_consistent(s->dev, PAGE_SIZE << db->bufOrder,
+ db->lbuf, db->lbufDma);
+ pci_free_consistent(s->dev, PAGE_SIZE << db->bufOrder,
+ db->rbuf, db->rbufDma);
+ db->lbuf = db->rbuf = NULL;
+ }
+ db->nextIn = db->nextOut = 0;
+ db->ready = 0;
+}
+
+static int prog_dmabuf(struct vrc5477_ac97_state *s,
+ struct dmabuf *db,
+ unsigned rate)
+{
+ int order;
+ unsigned bufsize;
+
+ if (!db->lbuf) {
+ MIPS_ASSERT(!db->rbuf);
+
+ db->ready = 0;
+ for (order = DMABUF_DEFAULTORDER;
+ order >= DMABUF_MINORDER;
+ order--) {
+ db->lbuf = pci_alloc_consistent(s->dev,
+ PAGE_SIZE << order,
+ &db->lbufDma);
+ db->rbuf = pci_alloc_consistent(s->dev,
+ PAGE_SIZE << order,
+ &db->rbufDma);
+ if (db->lbuf && db->rbuf) break;
+ if (db->lbuf) {
+ MIPS_ASSERT(!db->rbuf);
+ pci_free_consistent(s->dev,
+ PAGE_SIZE << order,
+ db->lbuf,
+ db->lbufDma);
+ }
+ }
+ if (!db->lbuf) {
+ MIPS_ASSERT(!db->rbuf);
+ return -ENOMEM;
+ }
+
+ db->bufOrder = order;
+ }
+
+ db->count = 0;
+ db->nextIn = db->nextOut = 0;
+
+ bufsize = PAGE_SIZE << db->bufOrder;
+ db->fragShift = ld2(rate * 2 / 100);
+ if (db->fragShift < 4) db->fragShift = 4;
+
+ db->numFrag = bufsize >> db->fragShift;
+ while (db->numFrag < 4 && db->fragShift > 4) {
+ db->fragShift--;
+ db->numFrag = bufsize >> db->fragShift;
+ }
+ db->fragSize = 1 << db->fragShift;
+ db->fragTotalSize = db->numFrag << db->fragShift;
+ memset(db->lbuf, 0, db->fragTotalSize);
+ memset(db->rbuf, 0, db->fragTotalSize);
+
+ db->ready = 1;
+
+ return 0;
+}
+
+extern inline int prog_dmabuf_adc(struct vrc5477_ac97_state *s)
+{
+ stop_adc(s);
+ return prog_dmabuf(s, &s->dma_adc, s->adcRate);
+}
+
+extern inline int prog_dmabuf_dac(struct vrc5477_ac97_state *s)
+{
+ stop_dac(s);
+ return prog_dmabuf(s, &s->dma_dac, s->dacRate);
+}
+
+
+/* --------------------------------------------------------------------- */
+/* hold spinlock for the following! */
+
+static inline void vrc5477_ac97_adc_interrupt(struct vrc5477_ac97_state *s)
+{
+ struct dmabuf* adc = &s->dma_adc;
+ unsigned temp;
+
+ /* we need two frags avaiable because one is already being used
+ * and the other will be used when next interrupt happens.
+ */
+ if (adc->count >= adc->fragTotalSize - adc->fragSize) {
+ stop_adc(s);
+ adc->error++;
+ printk(KERN_INFO PFX "adc overrun\n");
+ return;
+ }
+
+ /* set the base addr for next DMA transfer */
+ temp = adc->nextIn + 2*adc->fragSize;
+ if (temp >= adc->fragTotalSize) {
+ MIPS_ASSERT( (temp == adc->fragTotalSize) ||
+ (temp == adc->fragTotalSize + adc->fragSize) );
+ temp -= adc->fragTotalSize;
+ }
+ outl(adc->lbufDma + temp, s->io + VRC5477_ADC1_BADDR);
+ outl(adc->rbufDma + temp, s->io + VRC5477_ADC2_BADDR);
+
+ /* adjust nextIn */
+ adc->nextIn += adc->fragSize;
+ if (adc->nextIn >= adc->fragTotalSize) {
+ MIPS_ASSERT(adc->nextIn == adc->fragTotalSize);
+ adc->nextIn = 0;
+ }
+
+ /* adjust count */
+ adc->count += adc->fragSize;
+
+ /* wake up anybody listening */
+ if (waitqueue_active(&adc->wait)) {
+ wake_up_interruptible(&adc->wait);
+ }
+}
+
+static inline void vrc5477_ac97_dac_interrupt(struct vrc5477_ac97_state *s)
+{
+ struct dmabuf* dac = &s->dma_dac;
+ unsigned temp;
+
+ /* next DMA transfer should already started */
+ MIPS_ASSERT(inl(s->io + VRC5477_DAC1_CTRL) & VRC5477_DMA_WIP);
+ MIPS_ASSERT(inl(s->io + VRC5477_DAC2_CTRL) & VRC5477_DMA_WIP);
+
+ /* let us set for next next DMA transfer */
+ temp = dac->nextOut + dac->fragSize*2;
+ if (temp >= dac->fragTotalSize) {
+ MIPS_ASSERT( (temp == dac->fragTotalSize) ||
+ (temp == dac->fragTotalSize + dac->fragSize) );
+ temp -= dac->fragTotalSize;
+ }
+ outl(dac->lbufDma + temp, s->io + VRC5477_DAC1_BADDR);
+ if (s->dacChannels == 1) {
+ outl(dac->lbufDma + temp, s->io + VRC5477_DAC2_BADDR);
+ } else {
+ outl(dac->rbufDma + temp, s->io + VRC5477_DAC2_BADDR);
+ }
+
+#if defined(VRC5477_AC97_VERBOSE_DEBUG)
+ if (*(u16*)(dac->lbuf + dac->nextOut) != outTicket) {
+ printk("assert fail: - %d vs %d\n",
+ *(u16*)(dac->lbuf + dac->nextOut),
+ outTicket);
+ MIPS_ASSERT(1 == 0);
+ }
+#endif
+
+ /* adjust nextOut pointer */
+ dac->nextOut += dac->fragSize;
+ if (dac->nextOut >= dac->fragTotalSize) {
+ MIPS_ASSERT(dac->nextOut == dac->fragTotalSize);
+ dac->nextOut = 0;
+ }
+
+ /* adjust count */
+ dac->count -= dac->fragSize;
+ if (dac->count <=0 ) {
+ MIPS_ASSERT(dac->count == 0);
+ MIPS_ASSERT(dac->nextIn == dac->nextOut);
+ /* buffer under run */
+ stop_dac(s);
+ }
+
+#if defined(VRC5477_AC97_VERBOSE_DEBUG)
+ if (dac->count) {
+ outTicket ++;
+ MIPS_ASSERT(*(u16*)(dac->lbuf + dac->nextOut) == outTicket);
+ }
+#endif
+
+ /* we cannot have both under run and someone is waiting on us */
+ MIPS_ASSERT(! (waitqueue_active(&dac->wait) && (dac->count <= 0)) );
+
+ /* wake up anybody listening */
+ if (waitqueue_active(&dac->wait))
+ wake_up_interruptible(&dac->wait);
+}
+
+static void vrc5477_ac97_interrupt(int irq, void *dev_id, struct pt_regs *regs)
+{
+ struct vrc5477_ac97_state *s = (struct vrc5477_ac97_state *)dev_id;
+ u32 irqStatus;
+ u32 adcInterrupts, dacInterrupts;
+
+ spin_lock(&s->lock);
+
+ /* get irqStatus and clear the detected ones */
+ irqStatus = inl(s->io + VRC5477_INT_STATUS);
+ outl(irqStatus, s->io + VRC5477_INT_CLR);
+
+ /* let us see what we get */
+ dacInterrupts = VRC5477_INT_MASK_DAC1END | VRC5477_INT_MASK_DAC2END;
+ adcInterrupts = VRC5477_INT_MASK_ADC1END | VRC5477_INT_MASK_ADC2END;
+ if (irqStatus & dacInterrupts) {
+ /* we should get both interrupts, but just in case ... */
+ if (irqStatus & VRC5477_INT_MASK_DAC1END) {
+ vrc5477_ac97_dac_interrupt(s);
+ }
+ if ( (irqStatus & dacInterrupts) != dacInterrupts ) {
+ printk(KERN_WARNING "vrc5477_ac97 : dac interrupts not in sync!!!\n");
+ stop_dac(s);
+ start_dac(s);
+ }
+ } else if (irqStatus & adcInterrupts) {
+ /* we should get both interrupts, but just in case ... */
+ if(irqStatus & VRC5477_INT_MASK_ADC1END) {
+ vrc5477_ac97_adc_interrupt(s);
+ }
+ if ( (irqStatus & adcInterrupts) != adcInterrupts ) {
+ printk(KERN_WARNING "vrc5477_ac97 : adc interrupts not in sync!!!\n");
+ stop_adc(s);
+ start_adc(s);
+ }
+ }
+
+ spin_unlock(&s->lock);
+}
+
+/* --------------------------------------------------------------------- */
+
+static loff_t vrc5477_ac97_llseek(struct file *file, loff_t offset, int origin)
+{
+ return -ESPIPE;
+}
+
+
+static int vrc5477_ac97_open_mixdev(struct inode *inode, struct file *file)
+{
+ int minor = MINOR(inode->i_rdev);
+ struct list_head *list;
+ struct vrc5477_ac97_state *s;
+
+ for (list = devs.next; ; list = list->next) {
+ if (list == &devs)
+ return -ENODEV;
+ s = list_entry(list, struct vrc5477_ac97_state, devs);
+ if (s->codec.dev_mixer == minor)
+ break;
+ }
+ file->private_data = s;
+ return 0;
+}
+
+static int vrc5477_ac97_release_mixdev(struct inode *inode, struct file *file)
+{
+ return 0;
+}
+
+
+static int mixdev_ioctl(struct ac97_codec *codec, unsigned int cmd,
+ unsigned long arg)
+{
+ return codec->mixer_ioctl(codec, cmd, arg);
+}
+
+static int vrc5477_ac97_ioctl_mixdev(struct inode *inode, struct file *file,
+ unsigned int cmd, unsigned long arg)
+{
+ struct vrc5477_ac97_state *s =
+ (struct vrc5477_ac97_state *)file->private_data;
+ struct ac97_codec *codec = &s->codec;
+
+ return mixdev_ioctl(codec, cmd, arg);
+}
+
+static /*const*/ struct file_operations vrc5477_ac97_mixer_fops = {
+ owner: THIS_MODULE,
+ llseek: vrc5477_ac97_llseek,
+ ioctl: vrc5477_ac97_ioctl_mixdev,
+ open: vrc5477_ac97_open_mixdev,
+ release: vrc5477_ac97_release_mixdev,
+};
+
+/* --------------------------------------------------------------------- */
+
+static int drain_dac(struct vrc5477_ac97_state *s, int nonblock)
+{
+ unsigned long flags;
+ int count, tmo;
+
+ if (!s->dma_dac.ready)
+ return 0;
+
+ for (;;) {
+ spin_lock_irqsave(&s->lock, flags);
+ count = s->dma_dac.count;
+ spin_unlock_irqrestore(&s->lock, flags);
+ if (count <= 0)
+ break;
+ if (signal_pending(current))
+ break;
+ if (nonblock)
+ return -EBUSY;
+ tmo = 1000 * count / s->dacRate / 2;
+ vrc5477_ac97_delay(tmo);
+ }
+ if (signal_pending(current))
+ return -ERESTARTSYS;
+ return 0;
+}
+
+/* --------------------------------------------------------------------- */
+
+static int inline
+copy_two_channel_adc_to_user(struct vrc5477_ac97_state *s,
+ char *buffer,
+ int copyCount)
+{
+ struct dmabuf *db = &s->dma_adc;
+ int bufStart = db->nextOut;
+ for (; copyCount > 0; ) {
+ int i;
+ int count = copyCount;
+ if (count > WORK_BUF_SIZE/2) count = WORK_BUF_SIZE/2;
+ for (i=0; i< count/2; i++) {
+ s->workBuf[i].lchannel =
+ *(u16*)(db->lbuf + bufStart + i*2);
+ s->workBuf[i].rchannel =
+ *(u16*)(db->rbuf + bufStart + i*2);
+ }
+ if (copy_to_user(buffer, s->workBuf, count*2)) {
+ return -1;
+ }
+
+ copyCount -= count;
+ bufStart += count;
+ MIPS_ASSERT(bufStart <= db->fragTotalSize);
+ buffer += count *2;
+ }
+ return 0;
+}
+
+/* return the total bytes that is copied */
+static int inline
+copy_adc_to_user(struct vrc5477_ac97_state *s,
+ char * buffer,
+ size_t count,
+ int avail)
+{
+ struct dmabuf *db = &s->dma_adc;
+ int copyCount=0;
+ int copyFragCount=0;
+ int totalCopyCount = 0;
+ int totalCopyFragCount = 0;
+ unsigned long flags;
+
+ /* adjust count to signel channel byte count */
+ count >>= s->adcChannels - 1;
+
+ /* we may have to "copy" twice as ring buffer wraps around */
+ for (; (avail > 0) && (count > 0); ) {
+ /* determine max possible copy count for single channel */
+ copyCount = count;
+ if (copyCount > avail) {
+ copyCount = avail;
+ }
+ if (copyCount + db->nextOut > db->fragTotalSize) {
+ copyCount = db->fragTotalSize - db->nextOut;
+ MIPS_ASSERT((copyCount % db->fragSize) == 0);
+ }
+
+ copyFragCount = (copyCount-1) >> db->fragShift;
+ copyFragCount = (copyFragCount+1) << db->fragShift;
+ MIPS_ASSERT(copyFragCount >= copyCount);
+
+ /* we copy differently based on adc channels */
+ if (s->adcChannels == 1) {
+ if (copy_to_user(buffer,
+ db->lbuf + db->nextOut,
+ copyCount))
+ return -1;
+ } else {
+ /* *sigh* we have to mix two streams into one */
+ if (copy_two_channel_adc_to_user(s, buffer, copyCount))
+ return -1;
+ }
+
+ count -= copyCount;
+ totalCopyCount += copyCount;
+ avail -= copyFragCount;
+ totalCopyFragCount += copyFragCount;
+
+ buffer += copyCount << (s->adcChannels-1);
+
+ db->nextOut += copyFragCount;
+ if (db->nextOut >= db->fragTotalSize) {
+ MIPS_ASSERT(db->nextOut == db->fragTotalSize);
+ db->nextOut = 0;
+ }
+
+ MIPS_ASSERT((copyFragCount % db->fragSize) == 0);
+ MIPS_ASSERT( (count == 0) || (copyCount == copyFragCount));
+ }
+
+ spin_lock_irqsave(&s->lock, flags);
+ db->count -= totalCopyFragCount;
+ spin_unlock_irqrestore(&s->lock, flags);
+
+ return totalCopyCount << (s->adcChannels-1);
+}
+
+static ssize_t
+vrc5477_ac97_read(struct file *file,
+ char *buffer,
+ size_t count,
+ loff_t *ppos)
+{
+ struct vrc5477_ac97_state *s =
+ (struct vrc5477_ac97_state *)file->private_data;
+ struct dmabuf *db = &s->dma_adc;
+ ssize_t ret = 0;
+ unsigned long flags;
+ int copyCount;
+ size_t avail;
+
+ if (ppos != &file->f_pos)
+ return -ESPIPE;
+ if (!access_ok(VERIFY_WRITE, buffer, count))
+ return -EFAULT;
+
+ MIPS_ASSERT(db->ready);
+
+ while (count > 0) {
+ // wait for samples in capture buffer
+ do {
+ spin_lock_irqsave(&s->lock, flags);
+ if (db->stopped)
+ start_adc(s);
+ avail = db->count;
+ spin_unlock_irqrestore(&s->lock, flags);
+ if (avail <= 0) {
+ if (file->f_flags & O_NONBLOCK) {
+ if (!ret)
+ ret = -EAGAIN;
+ return ret;
+ }
+ interruptible_sleep_on(&db->wait);
+ if (signal_pending(current)) {
+ if (!ret)
+ ret = -ERESTARTSYS;
+ return ret;
+ }
+ }
+ } while (avail <= 0);
+
+ MIPS_ASSERT( (avail % db->fragSize) == 0);
+ copyCount = copy_adc_to_user(s, buffer, count, avail);
+ if (copyCount <=0 ) {
+ if (!ret) ret = -EFAULT;
+ return ret;
+ }
+
+ count -= copyCount;
+ buffer += copyCount;
+ ret += copyCount;
+ } // while (count > 0)
+
+ return ret;
+}
+
+static int inline
+copy_two_channel_dac_from_user(struct vrc5477_ac97_state *s,
+ const char *buffer,
+ int copyCount)
+{
+ struct dmabuf *db = &s->dma_dac;
+ int bufStart = db->nextIn;
+
+ MIPS_ASSERT(db->ready);
+
+ for (; copyCount > 0; ) {
+ int i;
+ int count = copyCount;
+ if (count > WORK_BUF_SIZE/2) count = WORK_BUF_SIZE/2;
+ if (copy_from_user(s->workBuf, buffer, count*2)) {
+ return -1;
+ }
+ for (i=0; i< count/2; i++) {
+ *(u16*)(db->lbuf + bufStart + i*2) =
+ s->workBuf[i].lchannel;
+ *(u16*)(db->rbuf + bufStart + i*2) =
+ s->workBuf[i].rchannel;
+ }
+
+ copyCount -= count;
+ bufStart += count;
+ MIPS_ASSERT(bufStart <= db->fragTotalSize);
+ buffer += count *2;
+ }
+ return 0;
+
+}
+
+/* return the total bytes that is copied */
+static int inline
+copy_dac_from_user(struct vrc5477_ac97_state *s,
+ const char *buffer,
+ size_t count,
+ int avail)
+{
+ struct dmabuf *db = &s->dma_dac;
+ int copyCount=0;
+ int copyFragCount=0;
+ int totalCopyCount = 0;
+ int totalCopyFragCount = 0;
+ unsigned long flags;
+ int i;
+
+ /* adjust count to signel channel byte count */
+ count >>= s->dacChannels - 1;
+
+ /* we may have to "copy" twice as ring buffer wraps around */
+ for (; (avail > 0) && (count > 0); ) {
+ /* determine max possible copy count for single channel */
+ copyCount = count;
+ if (copyCount > avail) {
+ copyCount = avail;
+ }
+ if (copyCount + db->nextIn > db->fragTotalSize) {
+ copyCount = db->fragTotalSize - db->nextIn;
+ MIPS_ASSERT((copyCount % db->fragSize) == 0);
+ MIPS_ASSERT(copyCount > 0);
+ }
+
+ copyFragCount = (copyCount-1) >> db->fragShift;
+ copyFragCount = (copyFragCount+1) << db->fragShift;
+ MIPS_ASSERT(copyFragCount >= copyCount);
+
+ /* we copy differently based on the number channels */
+ if (s->dacChannels == 1) {
+ if (copy_from_user(db->lbuf + db->nextIn,
+ buffer,
+ copyCount))
+ return -1;
+ /* fill gaps with 0 */
+ memset(db->lbuf + db->nextIn + copyCount,
+ 0,
+ copyFragCount - copyCount);
+ } else {
+ /* we have demux the stream into two separate ones */
+ if (copy_two_channel_dac_from_user(s, buffer, copyCount))
+ return -1;
+ /* fill gaps with 0 */
+ memset(db->lbuf + db->nextIn + copyCount,
+ 0,
+ copyFragCount - copyCount);
+ memset(db->rbuf + db->nextIn + copyCount,
+ 0,
+ copyFragCount - copyCount);
+ }
+
+#if defined(VRC5477_AC97_VERBOSE_DEBUG)
+ for (i=0; i< copyFragCount; i+= db->fragSize) {
+ *(u16*)(db->lbuf + db->nextIn + i) = inTicket ++;
+ }
+#endif
+
+ count -= copyCount;
+ totalCopyCount =+ copyCount;
+ avail -= copyFragCount;
+ totalCopyFragCount += copyFragCount;
+
+ buffer += copyCount << (s->dacChannels - 1);
+
+ db->nextIn += copyFragCount;
+ if (db->nextIn >= db->fragTotalSize) {
+ MIPS_ASSERT(db->nextIn == db->fragTotalSize);
+ db->nextIn = 0;
+ }
+
+ MIPS_ASSERT((copyFragCount % db->fragSize) == 0);
+ MIPS_ASSERT( (count == 0) || (copyCount == copyFragCount));
+ }
+
+ spin_lock_irqsave(&s->lock, flags);
+ db->count += totalCopyFragCount;
+ if (db->stopped) {
+ start_dac(s);
+ }
+
+ /* nextIn should not be equal to nextOut unless we are full */
+ MIPS_ASSERT( ( (db->count == db->fragTotalSize) &&
+ (db->nextIn == db->nextOut) ) ||
+ ( (db->count < db->fragTotalSize) &&
+ (db->nextIn != db->nextOut) ) );
+
+ spin_unlock_irqrestore(&s->lock, flags);
+
+ return totalCopyCount << (s->dacChannels-1);
+
+}
+
+static ssize_t vrc5477_ac97_write(struct file *file, const char *buffer,
+ size_t count, loff_t *ppos)
+{
+ struct vrc5477_ac97_state *s =
+ (struct vrc5477_ac97_state *)file->private_data;
+ struct dmabuf *db = &s->dma_dac;
+ ssize_t ret;
+ unsigned long flags;
+ int copyCount, avail;
+
+ if (ppos != &file->f_pos)
+ return -ESPIPE;
+ if (!access_ok(VERIFY_READ, buffer, count))
+ return -EFAULT;
+ ret = 0;
+
+ while (count > 0) {
+ // wait for space in playback buffer
+ do {
+ spin_lock_irqsave(&s->lock, flags);
+ avail = db->fragTotalSize - db->count;
+ spin_unlock_irqrestore(&s->lock, flags);
+ if (avail <= 0) {
+ if (file->f_flags & O_NONBLOCK) {
+ if (!ret)
+ ret = -EAGAIN;
+ return ret;
+ }
+ interruptible_sleep_on(&db->wait);
+ if (signal_pending(current)) {
+ if (!ret)
+ ret = -ERESTARTSYS;
+ return ret;
+ }
+ }
+ } while (avail <= 0);
+
+ MIPS_ASSERT( (avail % db->fragSize) == 0);
+ copyCount = copy_dac_from_user(s, buffer, count, avail);
+ if (copyCount < 0) {
+ if (!ret) ret = -EFAULT;
+ return ret;
+ }
+
+ count -= copyCount;
+ buffer += copyCount;
+ ret += copyCount;
+ } // while (count > 0)
+
+ return ret;
+}
+
+/* No kernel lock - we have our own spinlock */
+static unsigned int vrc5477_ac97_poll(struct file *file,
+ struct poll_table_struct *wait)
+{
+ struct vrc5477_ac97_state *s = (struct vrc5477_ac97_state *)file->private_data;
+ unsigned long flags;
+ unsigned int mask = 0;
+
+ if (file->f_mode & FMODE_WRITE)
+ poll_wait(file, &s->dma_dac.wait, wait);
+ if (file->f_mode & FMODE_READ)
+ poll_wait(file, &s->dma_adc.wait, wait);
+ spin_lock_irqsave(&s->lock, flags);
+ if (file->f_mode & FMODE_READ) {
+ if (s->dma_adc.count >= (signed)s->dma_adc.fragSize)
+ mask |= POLLIN | POLLRDNORM;
+ }
+ if (file->f_mode & FMODE_WRITE) {
+ if ((signed)s->dma_dac.fragTotalSize >=
+ s->dma_dac.count + (signed)s->dma_dac.fragSize)
+ mask |= POLLOUT | POLLWRNORM;
+ }
+ spin_unlock_irqrestore(&s->lock, flags);
+ return mask;
+}
+
+#ifdef CONFIG_LL_DEBUG
+static struct ioctl_str_t {
+ unsigned int cmd;
+ const char* str;
+} ioctl_str[] = {
+ {SNDCTL_DSP_RESET, "SNDCTL_DSP_RESET"},
+ {SNDCTL_DSP_SYNC, "SNDCTL_DSP_SYNC"},
+ {SNDCTL_DSP_SPEED, "SNDCTL_DSP_SPEED"},
+ {SNDCTL_DSP_STEREO, "SNDCTL_DSP_STEREO"},
+ {SNDCTL_DSP_GETBLKSIZE, "SNDCTL_DSP_GETBLKSIZE"},
+ {SNDCTL_DSP_SETFMT, "SNDCTL_DSP_SETFMT"},
+ {SNDCTL_DSP_SAMPLESIZE, "SNDCTL_DSP_SAMPLESIZE"},
+ {SNDCTL_DSP_CHANNELS, "SNDCTL_DSP_CHANNELS"},
+ {SOUND_PCM_WRITE_CHANNELS, "SOUND_PCM_WRITE_CHANNELS"},
+ {SOUND_PCM_WRITE_FILTER, "SOUND_PCM_WRITE_FILTER"},
+ {SNDCTL_DSP_POST, "SNDCTL_DSP_POST"},
+ {SNDCTL_DSP_SUBDIVIDE, "SNDCTL_DSP_SUBDIVIDE"},
+ {SNDCTL_DSP_SETFRAGMENT, "SNDCTL_DSP_SETFRAGMENT"},
+ {SNDCTL_DSP_GETFMTS, "SNDCTL_DSP_GETFMTS"},
+ {SNDCTL_DSP_GETOSPACE, "SNDCTL_DSP_GETOSPACE"},
+ {SNDCTL_DSP_GETISPACE, "SNDCTL_DSP_GETISPACE"},
+ {SNDCTL_DSP_NONBLOCK, "SNDCTL_DSP_NONBLOCK"},
+ {SNDCTL_DSP_GETCAPS, "SNDCTL_DSP_GETCAPS"},
+ {SNDCTL_DSP_GETTRIGGER, "SNDCTL_DSP_GETTRIGGER"},
+ {SNDCTL_DSP_SETTRIGGER, "SNDCTL_DSP_SETTRIGGER"},
+ {SNDCTL_DSP_GETIPTR, "SNDCTL_DSP_GETIPTR"},
+ {SNDCTL_DSP_GETOPTR, "SNDCTL_DSP_GETOPTR"},
+ {SNDCTL_DSP_MAPINBUF, "SNDCTL_DSP_MAPINBUF"},
+ {SNDCTL_DSP_MAPOUTBUF, "SNDCTL_DSP_MAPOUTBUF"},
+ {SNDCTL_DSP_SETSYNCRO, "SNDCTL_DSP_SETSYNCRO"},
+ {SNDCTL_DSP_SETDUPLEX, "SNDCTL_DSP_SETDUPLEX"},
+ {SNDCTL_DSP_GETODELAY, "SNDCTL_DSP_GETODELAY"},
+ {SNDCTL_DSP_GETCHANNELMASK, "SNDCTL_DSP_GETCHANNELMASK"},
+ {SNDCTL_DSP_BIND_CHANNEL, "SNDCTL_DSP_BIND_CHANNEL"},
+ {OSS_GETVERSION, "OSS_GETVERSION"},
+ {SOUND_PCM_READ_RATE, "SOUND_PCM_READ_RATE"},
+ {SOUND_PCM_READ_CHANNELS, "SOUND_PCM_READ_CHANNELS"},
+ {SOUND_PCM_READ_BITS, "SOUND_PCM_READ_BITS"},
+ {SOUND_PCM_READ_FILTER, "SOUND_PCM_READ_FILTER"}
+};
+#endif
+
+static int vrc5477_ac97_ioctl(struct inode *inode, struct file *file,
+ unsigned int cmd, unsigned long arg)
+{
+ struct vrc5477_ac97_state *s = (struct vrc5477_ac97_state *)file->private_data;
+ unsigned long flags;
+ audio_buf_info abinfo;
+ int count;
+ int val, ret;
+
+#ifdef CONFIG_LL_DEBUG
+ for (count=0; count<sizeof(ioctl_str)/sizeof(ioctl_str[0]); count++) {
+ if (ioctl_str[count].cmd == cmd)
+ break;
+ }
+ if (count < sizeof(ioctl_str)/sizeof(ioctl_str[0]))
+ printk(KERN_INFO PFX "ioctl %s\n", ioctl_str[count].str);
+ else
+ printk(KERN_INFO PFX "ioctl unknown, 0x%x\n", cmd);
+#endif
+
+ switch (cmd) {
+ case OSS_GETVERSION:
+ return put_user(SOUND_VERSION, (int *)arg);
+
+ case SNDCTL_DSP_SYNC:
+ if (file->f_mode & FMODE_WRITE)
+ return drain_dac(s, file->f_flags & O_NONBLOCK);
+ return 0;
+
+ case SNDCTL_DSP_SETDUPLEX:
+ return 0;
+
+ case SNDCTL_DSP_GETCAPS:
+ return put_user(DSP_CAP_DUPLEX, (int *)arg);
+
+ case SNDCTL_DSP_RESET:
+ if (file->f_mode & FMODE_WRITE) {
+ stop_dac(s);
+ synchronize_irq();
+ s->dma_dac.count = 0;
+ s->dma_dac.nextIn = s->dma_dac.nextOut = 0;
+ }
+ if (file->f_mode & FMODE_READ) {
+ stop_adc(s);
+ synchronize_irq();
+ s->dma_adc.count = 0;
+ s->dma_adc.nextIn = s->dma_adc.nextOut = 0;
+ }
+ return 0;
+
+ case SNDCTL_DSP_SPEED:
+ if (get_user(val, (int *)arg))
+ return -EFAULT;
+ if (val >= 0) {
+ if (file->f_mode & FMODE_READ) {
+ stop_adc(s);
+ set_adc_rate(s, val);
+ if ((ret = prog_dmabuf_adc(s)))
+ return ret;
+ }
+ if (file->f_mode & FMODE_WRITE) {
+ stop_dac(s);
+ set_dac_rate(s, val);
+ if ((ret = prog_dmabuf_dac(s)))
+ return ret;
+ }
+ }
+ return put_user((file->f_mode & FMODE_READ) ?
+ s->adcRate : s->dacRate, (int *)arg);
+
+ case SNDCTL_DSP_STEREO:
+ if (get_user(val, (int *)arg))
+ return -EFAULT;
+ if (file->f_mode & FMODE_READ) {
+ stop_adc(s);
+ if (val)
+ s->adcChannels = 2;
+ else
+ s->adcChannels = 1;
+ if ((ret = prog_dmabuf_adc(s)))
+ return ret;
+ }
+ if (file->f_mode & FMODE_WRITE) {
+ stop_dac(s);
+ if (val)
+ s->dacChannels = 2;
+ else
+ s->dacChannels = 1;
+ if ((ret = prog_dmabuf_dac(s)))
+ return ret;
+ }
+ return 0;
+
+ case SNDCTL_DSP_CHANNELS:
+ if (get_user(val, (int *)arg))
+ return -EFAULT;
+ if (val != 0) {
+ if ( (val != 1) && (val != 2)) val = 2;
+
+ if (file->f_mode & FMODE_READ) {
+ stop_adc(s);
+ s->dacChannels = val;
+ if ((ret = prog_dmabuf_adc(s)))
+ return ret;
+ }
+ if (file->f_mode & FMODE_WRITE) {
+ stop_dac(s);
+ s->dacChannels = val;
+ if ((ret = prog_dmabuf_dac(s)))
+ return ret;
+ }
+ }
+ return put_user(val, (int *)arg);
+
+ case SNDCTL_DSP_GETFMTS: /* Returns a mask */
+ return put_user(AFMT_S16_LE, (int *)arg);
+
+ case SNDCTL_DSP_SETFMT: /* Selects ONE fmt*/
+ if (get_user(val, (int *)arg))
+ return -EFAULT;
+ if (val != AFMT_QUERY) {
+ if (val != AFMT_S16_LE) return -EINVAL;
+ if (file->f_mode & FMODE_READ) {
+ stop_adc(s);
+ if ((ret = prog_dmabuf_adc(s)))
+ return ret;
+ }
+ if (file->f_mode & FMODE_WRITE) {
+ stop_dac(s);
+ if ((ret = prog_dmabuf_dac(s)))
+ return ret;
+ }
+ } else {
+ val = AFMT_S16_LE;
+ }
+ return put_user(val, (int *)arg);
+
+ case SNDCTL_DSP_POST:
+ return 0;
+
+ case SNDCTL_DSP_GETTRIGGER:
+ case SNDCTL_DSP_SETTRIGGER:
+ /* NO trigger */
+ return -EINVAL;
+
+ case SNDCTL_DSP_GETOSPACE:
+ if (!(file->f_mode & FMODE_WRITE))
+ return -EINVAL;
+ abinfo.fragsize = s->dma_dac.fragSize << (s->dacChannels-1);
+ spin_lock_irqsave(&s->lock, flags);
+ count = s->dma_dac.count;
+ spin_unlock_irqrestore(&s->lock, flags);
+ abinfo.bytes = (s->dma_dac.fragTotalSize - count) <<
+ (s->dacChannels-1);
+ abinfo.fragstotal = s->dma_dac.numFrag;
+ abinfo.fragments = abinfo.bytes >> s->dma_dac.fragShift >>
+ (s->dacChannels-1);
+ return copy_to_user((void *)arg, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
+
+ case SNDCTL_DSP_GETISPACE:
+ if (!(file->f_mode & FMODE_READ))
+ return -EINVAL;
+ abinfo.fragsize = s->dma_adc.fragSize << (s->adcChannels-1);
+ spin_lock_irqsave(&s->lock, flags);
+ count = s->dma_adc.count;
+ spin_unlock_irqrestore(&s->lock, flags);
+ if (count < 0)
+ count = 0;
+ abinfo.bytes = count << (s->adcChannels-1);
+ abinfo.fragstotal = s->dma_adc.numFrag;
+ abinfo.fragments = (abinfo.bytes >> s->dma_adc.fragShift) >>
+ (s->adcChannels-1);
+ return copy_to_user((void *)arg, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
+
+ case SNDCTL_DSP_NONBLOCK:
+ file->f_flags |= O_NONBLOCK;
+ return 0;
+
+ case SNDCTL_DSP_GETODELAY:
+ if (!(file->f_mode & FMODE_WRITE))
+ return -EINVAL;
+ spin_lock_irqsave(&s->lock, flags);
+ count = s->dma_dac.count;
+ spin_unlock_irqrestore(&s->lock, flags);
+ return put_user(count, (int *)arg);
+
+ case SNDCTL_DSP_GETIPTR:
+ case SNDCTL_DSP_GETOPTR:
+ /* we cannot get DMA ptr */
+ return -EINVAL;
+
+ case SNDCTL_DSP_GETBLKSIZE:
+ if (file->f_mode & FMODE_WRITE)
+ return put_user(s->dma_dac.fragSize << (s->dacChannels-1), (int *)arg);
+ else
+ return put_user(s->dma_adc.fragSize << (s->adcChannels-1), (int *)arg);
+
+ case SNDCTL_DSP_SETFRAGMENT:
+ /* we ignore fragment size request */
+ return 0;
+
+ case SNDCTL_DSP_SUBDIVIDE:
+ /* what is this for? [jsun] */
+ return 0;
+
+ case SOUND_PCM_READ_RATE:
+ return put_user((file->f_mode & FMODE_READ) ?
+ s->adcRate : s->dacRate, (int *)arg);
+
+ case SOUND_PCM_READ_CHANNELS:
+ if (file->f_mode & FMODE_READ)
+ return put_user(s->adcChannels, (int *)arg);
+ else
+ return put_user(s->dacChannels ? 2 : 1, (int *)arg);
+
+ case SOUND_PCM_READ_BITS:
+ return put_user(16, (int *)arg);
+
+ case SOUND_PCM_WRITE_FILTER:
+ case SNDCTL_DSP_SETSYNCRO:
+ case SOUND_PCM_READ_FILTER:
+ return -EINVAL;
+ }
+
+ return mixdev_ioctl(&s->codec, cmd, arg);
+}
+
+
+static int vrc5477_ac97_open(struct inode *inode, struct file *file)
+{
+ int minor = MINOR(inode->i_rdev);
+ DECLARE_WAITQUEUE(wait, current);
+ unsigned long flags;
+ struct list_head *list;
+ struct vrc5477_ac97_state *s;
+ int ret=0;
+
+ for (list = devs.next; ; list = list->next) {
+ if (list == &devs)
+ return -ENODEV;
+ s = list_entry(list, struct vrc5477_ac97_state, devs);
+ if (!((s->dev_audio ^ minor) & ~0xf))
+ break;
+ }
+ file->private_data = s;
+
+ /* wait for device to become free */
+ down(&s->open_sem);
+ while (s->open_mode & file->f_mode) {
+
+ if (file->f_flags & O_NONBLOCK) {
+ up(&s->open_sem);
+ return -EBUSY;
+ }
+ add_wait_queue(&s->open_wait, &wait);
+ __set_current_state(TASK_INTERRUPTIBLE);
+ up(&s->open_sem);
+ schedule();
+ remove_wait_queue(&s->open_wait, &wait);
+ set_current_state(TASK_RUNNING);
+ if (signal_pending(current))
+ return -ERESTARTSYS;
+ down(&s->open_sem);
+ }
+
+ spin_lock_irqsave(&s->lock, flags);
+
+ if (file->f_mode & FMODE_READ) {
+ /* set default settings */
+ set_adc_rate(s, 48000);
+ s->adcChannels = 2;
+
+ ret = prog_dmabuf_adc(s);
+ if (ret) goto bailout;
+ }
+ if (file->f_mode & FMODE_WRITE) {
+ /* set default settings */
+ set_dac_rate(s, 48000);
+ s->dacChannels = 2;
+
+ ret = prog_dmabuf_dac(s);
+ if (ret) goto bailout;
+ }
+
+ s->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE);
+
+ bailout:
+ spin_unlock_irqrestore(&s->lock, flags);
+
+ up(&s->open_sem);
+ return ret;
+}
+
+static int vrc5477_ac97_release(struct inode *inode, struct file *file)
+{
+ struct vrc5477_ac97_state *s =
+ (struct vrc5477_ac97_state *)file->private_data;
+
+ lock_kernel();
+ if (file->f_mode & FMODE_WRITE)
+ drain_dac(s, file->f_flags & O_NONBLOCK);
+ down(&s->open_sem);
+ if (file->f_mode & FMODE_WRITE) {
+ stop_dac(s);
+ dealloc_dmabuf(s, &s->dma_dac);
+ }
+ if (file->f_mode & FMODE_READ) {
+ stop_adc(s);
+ dealloc_dmabuf(s, &s->dma_adc);
+ }
+ s->open_mode &= (~file->f_mode) & (FMODE_READ|FMODE_WRITE);
+ up(&s->open_sem);
+ wake_up(&s->open_wait);
+ unlock_kernel();
+ return 0;
+}
+
+static /*const*/ struct file_operations vrc5477_ac97_audio_fops = {
+ owner: THIS_MODULE,
+ llseek: vrc5477_ac97_llseek,
+ read: vrc5477_ac97_read,
+ write: vrc5477_ac97_write,
+ poll: vrc5477_ac97_poll,
+ ioctl: vrc5477_ac97_ioctl,
+ // mmap: vrc5477_ac97_mmap,
+ open: vrc5477_ac97_open,
+ release: vrc5477_ac97_release,
+};
+
+
+/* --------------------------------------------------------------------- */
+
+
+/* --------------------------------------------------------------------- */
+
+/*
+ * for debugging purposes, we'll create a proc device that dumps the
+ * CODEC chipstate
+ */
+
+#ifdef CONFIG_LL_DEBUG
+
+struct {
+ const char *regname;
+ unsigned regaddr;
+} vrc5477_ac97_regs[] = {
+ {"VRC5477_INT_STATUS", VRC5477_INT_STATUS},
+ {"VRC5477_CODEC_WR", VRC5477_CODEC_WR},
+ {"VRC5477_CODEC_RD", VRC5477_CODEC_RD},
+ {"VRC5477_CTRL", VRC5477_CTRL},
+ {"VRC5477_ACLINK_CTRL", VRC5477_ACLINK_CTRL},
+ {"VRC5477_INT_MASK", VRC5477_INT_MASK},
+ {"VRC5477_DAC1_CTRL", VRC5477_DAC1_CTRL},
+ {"VRC5477_DAC1L", VRC5477_DAC1L},
+ {"VRC5477_DAC1_BADDR", VRC5477_DAC1_BADDR},
+ {"VRC5477_DAC2_CTRL", VRC5477_DAC2_CTRL},
+ {"VRC5477_DAC2L", VRC5477_DAC2L},
+ {"VRC5477_DAC2_BADDR", VRC5477_DAC2_BADDR},
+ {"VRC5477_DAC3_CTRL", VRC5477_DAC3_CTRL},
+ {"VRC5477_DAC3L", VRC5477_DAC3L},
+ {"VRC5477_DAC3_BADDR", VRC5477_DAC3_BADDR},
+ {"VRC5477_ADC1_CTRL", VRC5477_ADC1_CTRL},
+ {"VRC5477_ADC1L", VRC5477_ADC1L},
+ {"VRC5477_ADC1_BADDR", VRC5477_ADC1_BADDR},
+ {"VRC5477_ADC2_CTRL", VRC5477_ADC2_CTRL},
+ {"VRC5477_ADC2L", VRC5477_ADC2L},
+ {"VRC5477_ADC2_BADDR", VRC5477_ADC2_BADDR},
+ {"VRC5477_ADC3_CTRL", VRC5477_ADC3_CTRL},
+ {"VRC5477_ADC3L", VRC5477_ADC3L},
+ {"VRC5477_ADC3_BADDR", VRC5477_ADC3_BADDR},
+ {NULL, 0x0}
+};
+
+static int proc_vrc5477_ac97_dump (char *buf, char **start, off_t fpos,
+ int length, int *eof, void *data)
+{
+ struct vrc5477_ac97_state *s;
+ int cnt, len = 0;
+
+ if (list_empty(&devs))
+ return 0;
+ s = list_entry(devs.next, struct vrc5477_ac97_state, devs);
+
+ /* print out header */
+ len += sprintf(buf + len, "\n\t\tVrc5477 Audio Debug\n\n");
+
+ // print out digital controller state
+ len += sprintf (buf + len, "NEC Vrc5477 Audio Controller registers\n");
+ len += sprintf (buf + len, "---------------------------------\n");
+ for (cnt=0; vrc5477_ac97_regs[cnt].regname != NULL; cnt++) {
+ len+= sprintf (buf + len, "%-20s = %08x\n",
+ vrc5477_ac97_regs[cnt].regname,
+ inl(s->io + vrc5477_ac97_regs[cnt].regaddr));
+ }
+
+ /* print out driver state */
+ len += sprintf (buf + len, "NEC Vrc5477 Audio driver states\n");
+ len += sprintf (buf + len, "---------------------------------\n");
+ len += sprintf (buf + len, "dacChannels = %d\n", s->dacChannels);
+ len += sprintf (buf + len, "adcChannels = %d\n", s->adcChannels);
+ len += sprintf (buf + len, "dacRate = %d\n", s->dacRate);
+ len += sprintf (buf + len, "adcRate = %d\n", s->adcRate);
+
+ len += sprintf (buf + len, "dma_dac is %s ready\n",
+ s->dma_dac.ready? "" : "not");
+ if (s->dma_dac.ready) {
+ len += sprintf (buf + len, "dma_dac is %s stopped.\n",
+ s->dma_dac.stopped? "" : "not");
+ len += sprintf (buf + len, "dma_dac.fragSize = %x\n",
+ s->dma_dac.fragSize);
+ len += sprintf (buf + len, "dma_dac.fragShift = %x\n",
+ s->dma_dac.fragShift);
+ len += sprintf (buf + len, "dma_dac.numFrag = %x\n",
+ s->dma_dac.numFrag);
+ len += sprintf (buf + len, "dma_dac.fragTotalSize = %x\n",
+ s->dma_dac.fragTotalSize);
+ len += sprintf (buf + len, "dma_dac.nextIn = %x\n",
+ s->dma_dac.nextIn);
+ len += sprintf (buf + len, "dma_dac.nextOut = %x\n",
+ s->dma_dac.nextOut);
+ len += sprintf (buf + len, "dma_dac.count = %x\n",
+ s->dma_dac.count);
+ }
+
+ len += sprintf (buf + len, "dma_adc is %s ready\n",
+ s->dma_adc.ready? "" : "not");
+ if (s->dma_adc.ready) {
+ len += sprintf (buf + len, "dma_adc is %s stopped.\n",
+ s->dma_adc.stopped? "" : "not");
+ len += sprintf (buf + len, "dma_adc.fragSize = %x\n",
+ s->dma_adc.fragSize);
+ len += sprintf (buf + len, "dma_adc.fragShift = %x\n",
+ s->dma_adc.fragShift);
+ len += sprintf (buf + len, "dma_adc.numFrag = %x\n",
+ s->dma_adc.numFrag);
+ len += sprintf (buf + len, "dma_adc.fragTotalSize = %x\n",
+ s->dma_adc.fragTotalSize);
+ len += sprintf (buf + len, "dma_adc.nextIn = %x\n",
+ s->dma_adc.nextIn);
+ len += sprintf (buf + len, "dma_adc.nextOut = %x\n",
+ s->dma_adc.nextOut);
+ len += sprintf (buf + len, "dma_adc.count = %x\n",
+ s->dma_adc.count);
+ }
+
+ /* print out CODEC state */
+ len += sprintf (buf + len, "\nAC97 CODEC registers\n");
+ len += sprintf (buf + len, "----------------------\n");
+ for (cnt=0; cnt <= 0x7e; cnt = cnt +2)
+ len+= sprintf (buf + len, "reg %02x = %04x\n",
+ cnt, rdcodec(&s->codec, cnt));
+
+ if (fpos >=len){
+ *start = buf;
+ *eof =1;
+ return 0;
+ }
+ *start = buf + fpos;
+ if ((len -= fpos) > length)
+ return length;
+ *eof =1;
+ return len;
+
+}
+#endif /* CONFIG_LL_DEBUG */
+
+/* --------------------------------------------------------------------- */
+
+/* maximum number of devices; only used for command line params */
+#define NR_DEVICE 5
+
+static unsigned int devindex = 0;
+
+MODULE_AUTHOR("Monta Vista Software, jsun@mvista.com or jsun@junsun.net");
+MODULE_DESCRIPTION("NEC Vrc5477 audio (AC97) Driver");
+
+/* --------------------------------------------------------------------- */
+extern void jsun_scan_pci_bus(void);
+extern void vrc5477_show_pci_regs(void);
+extern void vrc5477_show_pdar_regs(void);
+
+/* -------------------------------------------------------- */
+#define AC97_BASE 0xbb000000
+#define myinl(x) *(volatile u32*)(AC97_BASE + (x))
+#define myoutl(x,y) *(volatile u32*)(AC97_BASE + (y)) = (x)
+
+u16 myrdcodec(u8 addr)
+{
+ u32 result;
+ u32 i;
+
+ /* wait until we can access codec registers */
+ // while (inl(VRC5477_CODEC_WR) & 0x80000000);
+
+ /* write the address and "read" command to codec */
+ addr = addr & 0x7f;
+ myoutl((addr << 16) | VRC5477_CODEC_WR_RWC, VRC5477_CODEC_WR);
+
+ /* get the return result */
+ for (i=10000; i; i--);
+ // dump_memory(0xbb000000, 48);
+ while ( ((result=myinl(VRC5477_CODEC_RD)) & 0xc0000000) != 0xc0000000);
+ MIPS_ASSERT(addr == ((result >> 16) & 0x7f) );
+ return result & 0xffff;
+}
+
+void mywrcodec(u8 addr, u16 data)
+{
+ /* wait until we can access codec registers */
+ while (myinl(VRC5477_CODEC_WR) & 0x80000000);
+
+ /* write the address and value to codec */
+ myoutl((addr << 16) | data, VRC5477_CODEC_WR);
+
+}
+
+
+void jsun_ac97_test(struct vrc5477_ac97_state *s)
+{
+ int i;
+
+ /* reset codec */
+ /*
+ wrcodec(&s->codec, 0, 0);
+ while (inl(s->io + VRC5477_CODEC_WR) & 0x80000000);
+ */
+ mywrcodec(0, 0);
+ while (myinl(VRC5477_CODEC_WR) & 0x80000000);
+
+ for (i=0; i< 0x40; i+=4) {
+ MIPS_ASSERT(inl(s->io+i) == myinl(i));
+ }
+
+ printk("codec registers : ");
+ for (i=0; i<= 0x3a; i+=2) {
+ if ( (i%0x10) == 0) {
+ printk("\n%02x\t", i);
+ }
+ // printk("%04x\t", rdcodec(&s->codec, i));
+ printk("%04x\t", myrdcodec(i));
+ }
+ printk("\n\n");
+ printk("codec registers : ");
+ for (i=0; i<= 0x3a; i+=2) {
+ if ( (i%0x10) == 0) {
+ printk("\n%02x\t", i);
+ }
+ printk("%04x\t", rdcodec(&s->codec, i));
+ }
+ printk("\n\n");
+}
+
+static int __devinit vrc5477_ac97_probe(struct pci_dev *pcidev,
+ const struct pci_device_id *pciid)
+{
+ struct vrc5477_ac97_state *s;
+ char proc_str[80];
+
+ MIPS_DEBUG(printk("vrc5477_ac97_probe() invoked\n"));
+
+ if (pcidev->irq == 0)
+ return -1;
+
+ if (!(s = kmalloc(sizeof(struct vrc5477_ac97_state), GFP_KERNEL))) {
+ printk(KERN_ERR PFX "alloc of device struct failed\n");
+ return -1;
+ }
+ memset(s, 0, sizeof(struct vrc5477_ac97_state));
+
+ init_waitqueue_head(&s->dma_adc.wait);
+ init_waitqueue_head(&s->dma_dac.wait);
+ init_waitqueue_head(&s->open_wait);
+ init_MUTEX(&s->open_sem);
+ spin_lock_init(&s->lock);
+
+ s->dev = pcidev;
+ s->io = pci_resource_start(pcidev, 0);
+ s->irq = pcidev->irq;
+
+ s->codec.private_data = s;
+ s->codec.id = 0;
+ s->codec.codec_read = rdcodec;
+ s->codec.codec_write = wrcodec;
+ s->codec.codec_wait = waitcodec;
+
+ /* setting some other default values such as
+ * adcChannels, adcRate is done in open() so that
+ * no persistent state across file opens.
+ */
+
+ if (!request_region(s->io, pci_resource_len(pcidev,0),
+ VRC5477_AC97_MODULE_NAME)) {
+ printk(KERN_ERR PFX "io ports %#lx->%#lx in use\n",
+ s->io, s->io + pci_resource_len(pcidev,0)-1);
+ goto err_region;
+ }
+ if (request_irq(s->irq, vrc5477_ac97_interrupt, SA_INTERRUPT,
+ VRC5477_AC97_MODULE_NAME, s)) {
+ printk(KERN_ERR PFX "irq %u in use\n", s->irq);
+ goto err_irq;
+ }
+
+ printk(KERN_INFO PFX "IO at %#lx, IRQ %d\n", s->io, s->irq);
+
+ /* register devices */
+ if ((s->dev_audio = register_sound_dsp(&vrc5477_ac97_audio_fops, -1)) < 0)
+ goto err_dev1;
+ if ((s->codec.dev_mixer =
+ register_sound_mixer(&vrc5477_ac97_mixer_fops, -1)) < 0)
+ goto err_dev2;
+
+#ifdef CONFIG_LL_DEBUG
+ /* intialize the debug proc device */
+ s->ps = create_proc_read_entry(VRC5477_AC97_MODULE_NAME, 0, NULL,
+ proc_vrc5477_ac97_dump, NULL);
+#endif /* CONFIG_LL_DEBUG */
+
+ /* enable pci io and bus mastering */
+ if (pci_enable_device(pcidev))
+ goto err_dev3;
+ pci_set_master(pcidev);
+
+/*
+jsun_scan_pci_bus();
+vrc5477_show_pci_regs();
+vrc5477_show_pdar_regs();
+*/
+
+ /* cold reset the AC97 */
+ outl(VRC5477_ACLINK_CTRL_RST_ON | VRC5477_ACLINK_CTRL_RST_TIME,
+ s->io + VRC5477_ACLINK_CTRL);
+ while (inl(s->io + VRC5477_ACLINK_CTRL) & VRC5477_ACLINK_CTRL_RST_ON);
+
+/*
+jsun_ac97_test(s);
+*/
+
+ /* codec init */
+ if (!ac97_probe_codec(&s->codec))
+ goto err_dev3;
+
+#ifdef CONFIG_LL_DEBUG
+ sprintf(proc_str, "driver/%s/%d/ac97",
+ VRC5477_AC97_MODULE_NAME, s->codec.id);
+ s->ac97_ps = create_proc_read_entry (proc_str, 0, NULL,
+ ac97_read_proc, &s->codec);
+ /* TODO : why this proc file does not show up? */
+#endif
+
+ /* let us get the default volumne louder */
+ wrcodec(&s->codec, 0x2, 0);
+ wrcodec(&s->codec, 0x18, 0x0707);
+ /* mute line in loopback to line out */
+ wrcodec(&s->codec, 0x10, 0x8000);
+
+ /* by default we select line in the input */
+ wrcodec(&s->codec, 0x1a, 0x0404);
+ /* pick middle value for record gain */
+ // wrcodec(&s->codec, 0x1c, 0x0707);
+ wrcodec(&s->codec, 0x1c, 0x0f0f);
+ wrcodec(&s->codec, 0x1e, 0x07);
+
+ /* enable the master interrupt but disable all others */
+ outl(VRC5477_INT_MASK_NMASK, s->io + VRC5477_INT_MASK);
+
+ /* store it in the driver field */
+ pci_set_drvdata(pcidev, s);
+ pcidev->dma_mask = 0xffffffff;
+ /* put it into driver list */
+ list_add_tail(&s->devs, &devs);
+ /* increment devindex */
+ if (devindex < NR_DEVICE-1)
+ devindex++;
+ return 0;
+
+ err_dev3:
+ unregister_sound_mixer(s->codec.dev_mixer);
+ err_dev2:
+ unregister_sound_dsp(s->dev_audio);
+ err_dev1:
+ printk(KERN_ERR PFX "cannot register misc device\n");
+ free_irq(s->irq, s);
+ err_irq:
+ release_region(s->io, pci_resource_len(pcidev,0));
+ err_region:
+ kfree(s);
+ return -1;
+}
+
+static void __devinit vrc5477_ac97_remove(struct pci_dev *dev)
+{
+ struct vrc5477_ac97_state *s = pci_get_drvdata(dev);
+
+ if (!s)
+ return;
+ list_del(&s->devs);
+#ifdef CONFIG_LL_DEBUG
+ if (s->ps)
+ remove_proc_entry(VRC5477_AC97_MODULE_NAME, NULL);
+#endif /* CONFIG_LL_DEBUG */
+ synchronize_irq();
+ free_irq(s->irq, s);
+ release_region(s->io, pci_resource_len(dev,0));
+ unregister_sound_dsp(s->dev_audio);
+ unregister_sound_mixer(s->codec.dev_mixer);
+ kfree(s);
+ pci_set_drvdata(dev, NULL);
+}
+
+
+#define PCI_VENDOR_ID_NEC 0x1033
+#define PCI_DEVICE_ID_NEC_VRC5477_AC97 0x00A6
+static struct pci_device_id id_table[] __devinitdata = {
+ { PCI_VENDOR_ID_NEC, PCI_DEVICE_ID_NEC_VRC5477_AC97,
+ PCI_ANY_ID, PCI_ANY_ID, 0, 0 },
+ { 0, }
+};
+
+MODULE_DEVICE_TABLE(pci, id_table);
+
+static struct pci_driver vrc5477_ac97_driver = {
+ name: VRC5477_AC97_MODULE_NAME,
+ id_table: id_table,
+ probe: vrc5477_ac97_probe,
+ remove: vrc5477_ac97_remove
+};
+
+static int __init init_vrc5477_ac97(void)
+{
+ if (!pci_present()) /* No PCI bus in this machine! */
+ return -ENODEV;
+ printk("Vrc5477 AC97 driver: version v0.1 time " __TIME__ " " __DATE__ " by Jun Sun\n");
+ return pci_module_init(&vrc5477_ac97_driver);
+}
+
+static void __exit cleanup_vrc5477_ac97(void)
+{
+ printk(KERN_INFO PFX "unloading\n");
+ pci_unregister_driver(&vrc5477_ac97_driver);
+}
+
+module_init(init_vrc5477_ac97);
+module_exit(cleanup_vrc5477_ac97);
+
diff --git a/drivers/sound/via82cxxx_audio.c b/drivers/sound/via82cxxx_audio.c
index f66d08b1b..6d24e8e7b 100644
--- a/drivers/sound/via82cxxx_audio.c
+++ b/drivers/sound/via82cxxx_audio.c
@@ -87,10 +87,6 @@
#define VIA_MIN_FRAG_NUMBER 2
-#ifndef AC97_PCM_LR_ADC_RATE
-# define AC97_PCM_LR_ADC_RATE AC97_PCM_LR_DAC_RATE
-#endif
-
/* 82C686 function 5 (audio codec) PCI configuration registers */
#define VIA_ACLINK_CTRL 0x41
#define VIA_FUNC_ENABLE 0x42
diff --git a/include/asm-mips/bootinfo.h b/include/asm-mips/bootinfo.h
index 7c2bb1777..128de8dc8 100644
--- a/include/asm-mips/bootinfo.h
+++ b/include/asm-mips/bootinfo.h
@@ -114,8 +114,9 @@
*/
#define MACH_NEC_DDB5074 0 /* NEC DDB Vrc-5074 */
#define MACH_NEC_DDB5476 1 /* NEC DDB Vrc-5476 */
+#define MACH_NEC_DDB5477 2 /* NEC DDB Vrc-5477 */
-#define GROUP_NEC_DDB_NAMES { "Vrc-5074", "Vrc-5476"}
+#define GROUP_NEC_DDB_NAMES { "Vrc-5074", "Vrc-5476", "Vrc-5477"}
/*
* Valid machtype for group BAGET
diff --git a/include/asm-mips/ddb5xxx/ddb5477.h b/include/asm-mips/ddb5xxx/ddb5477.h
new file mode 100644
index 000000000..6bba70549
--- /dev/null
+++ b/include/asm-mips/ddb5xxx/ddb5477.h
@@ -0,0 +1,221 @@
+/***********************************************************************
+ *
+ * Copyright 2001 MontaVista Software Inc.
+ * Author: jsun@mvista.com or jsun@junsun.net
+ *
+ * include/asm-mips/ddb5xxx/ddb5477.h
+ * DDB 5477 specific definitions and macros.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ ***********************************************************************
+ */
+
+#ifndef __ASM_DDB5XXX_DDB5477_H
+#define __ASM_DDB5XXX_DDB5477_H
+
+#include <linux/config.h>
+#include <asm/ddb5xxx/ddb5xxx.h>
+
+/*
+ * This contains macros that are specific to DDB5477 or renamed from
+ * DDB5476.
+ */
+
+/*
+ * renamed PADRs
+ */
+#define DDB_LCS0 DDB_LDCS0
+#define DDB_LCS1 DDB_LDCS1
+#define DDB_LCS2 DDB_LDCS2
+#define DDB_VRC5477 DDB_INTCS
+
+/*
+ * New CPU interface registers
+ */
+#define DDB_INTCTRL0 0x0400 /* Interrupt Control 0 */
+#define DDB_INTCTRL1 0x0404 /* Interrupt Control 1 */
+#define DDB_INTCTRL2 0x0408 /* Interrupt Control 2 */
+#define DDB_INTCTRL3 0x040c /* Interrupt Control 3 */
+
+#define DDB_INT0STAT 0x0420 /* INT0 Status [R] */
+#define DDB_INT1STAT 0x0428 /* INT1 Status [R] */
+#define DDB_INT2STAT 0x0430 /* INT2 Status [R] */
+#define DDB_INT3STAT 0x0438 /* INT3 Status [R] */
+#define DDB_INT4STAT 0x0440 /* INT4 Status [R] */
+#define DDB_NMISTAT 0x0450 /* NMI Status [R] */
+
+#define DDB_INTCLR32 0x0468 /* Interrupt Clear */
+
+#define DDB_INTPPES0 0x0470 /* PCI0 Interrupt Control */
+#define DDB_INTPPES1 0x0478 /* PCI1 Interrupt Control */
+
+#undef DDB_CPUSTAT /* duplicate in Vrc-5477 */
+#define DDB_CPUSTAT 0x0480 /* CPU Status [R] */
+#define DDB_BUSCTRL 0x0488 /* Internal Bus Control */
+
+
+/*
+ * Timer registers
+ */
+#define DDB_REFCTRL_L DDB_T0CTRL
+#define DDB_REFCTRL_H (DDB_T0CTRL+4)
+#define DDB_REFCNTR DDB_T0CNTR
+#define DDB_SPT0CTRL_L DDB_T1CTRL
+#define DDB_SPT0CTRL_H (DDB_T1CTRL+4)
+#define DDB_SPT1CTRL_L DDB_T2CTRL
+#define DDB_SPT1CTRL_H (DDB_T2CTRL+4)
+#define DDB_SPT1CNTR DDB_T1CTRL
+#define DDB_WDTCTRL_L DDB_T3CTRL
+#define DDB_WDTCTRL_H (DDB_T3CTRL+4)
+#define DDB_WDTCNTR DDB_T3CNTR
+
+/*
+ * DMA registers are moved. We don't care about it for now. TODO.
+ */
+
+/*
+ * BARs for ext PCI (PCI0)
+ */
+#undef DDB_BARC
+#undef DDB_BARB
+
+#define DDB_BARC0 0x0210 /* PCI0 Control */
+#define DDB_BARM010 0x0218 /* PCI0 SDRAM bank01 */
+#define DDB_BARM230 0x0220 /* PCI0 SDRAM bank23 */
+#define DDB_BAR00 0x0240 /* PCI0 LDCS0 */
+#define DDB_BAR10 0x0248 /* PCI0 LDCS1 */
+#define DDB_BAR20 0x0250 /* PCI0 LDCS2 */
+#define DDB_BAR30 0x0258 /* PCI0 LDCS3 */
+#define DDB_BAR40 0x0260 /* PCI0 LDCS4 */
+#define DDB_BAR50 0x0268 /* PCI0 LDCS5 */
+#define DDB_BARB0 0x0280 /* PCI0 BOOT */
+#define DDB_BARP00 0x0290 /* PCI0 for IOPCI Window0 */
+#define DDB_BARP10 0x0298 /* PCI0 for IOPCI Window1 */
+
+/*
+ * BARs for IOPIC (PCI1)
+ */
+#define DDB_BARC1 0x0610 /* PCI1 Control */
+#define DDB_BARM011 0x0618 /* PCI1 SDRAM bank01 */
+#define DDB_BARM231 0x0620 /* PCI1 SDRAM bank23 */
+#define DDB_BAR01 0x0640 /* PCI1 LDCS0 */
+#define DDB_BAR11 0x0648 /* PCI1 LDCS1 */
+#define DDB_BAR21 0x0650 /* PCI1 LDCS2 */
+#define DDB_BAR31 0x0658 /* PCI1 LDCS3 */
+#define DDB_BAR41 0x0660 /* PCI1 LDCS4 */
+#define DDB_BAR51 0x0668 /* PCI1 LDCS5 */
+#define DDB_BARB1 0x0680 /* PCI1 BOOT */
+#define DDB_BARP01 0x0690 /* PCI1 for ext PCI Window0 */
+#define DDB_BARP11 0x0698 /* PCI1 for ext PCI Window1 */
+
+/*
+ * Other registers for ext PCI (PCI0)
+ */
+#define DDB_PCIINIT00 0x02f0 /* PCI0 Initiator 0 */
+#define DDB_PCIINIT10 0x02f8 /* PCI0 Initiator 1 */
+
+#define DDB_PCISWP0 0x02b0 /* PCI0 Swap */
+#define DDB_PCIERR0 0x02b8 /* PCI0 Error */
+
+#define DDB_PCICTL0_L 0x02e0 /* PCI0 Control-L */
+#define DDB_PCICTL0_H 0x02e4 /* PCI0 Control-H */
+#define DDB_PCIARB0_L 0x02e8 /* PCI0 Arbitration-L */
+#define DDB_PCIARB0_H 0x02ec /* PCI0 Arbitration-H */
+
+/*
+ * Other registers for IOPCI (PCI1)
+ */
+#define DDB_IOPCIW0 0x00d0 /* PCI Address Window 0 [R/W] */
+#define DDB_IOPCIW1 0x00d8 /* PCI Address Window 1 [R/W] */
+
+#define DDB_PCIINIT01 0x06f0 /* PCI1 Initiator 0 */
+#define DDB_PCIINIT11 0x06f8 /* PCI1 Initiator 1 */
+
+#define DDB_PCISWP1 0x06b0 /* PCI1 Swap */
+#define DDB_PCIERR1 0x06b8 /* PCI1 Error */
+
+#define DDB_PCICTL1_L 0x06e0 /* PCI1 Control-L */
+#define DDB_PCICTL1_H 0x06e4 /* PCI1 Control-H */
+#define DDB_PCIARB1_L 0x06e8 /* PCI1 Arbitration-L */
+#define DDB_PCIARB1_H 0x06ec /* PCI1 Arbitration-H */
+
+/*
+ * MISC registers
+ */
+#define DDB_GIUFUNSEL 0x4040 /* select dual-func pins */
+#define DDB_PIBMISC 0x0750 /* USB buffer enable / power saving */
+
+/*
+ * Memory map (physical address)
+ *
+ * Note most of the following address must be properly aligned by the
+ * corresponding size. For example, if PCI_IO_SIZE is 16MB, then
+ * PCI_IO_BASE must be aligned along 16MB boundary.
+ */
+#define DDB_SDRAM_BASE 0x00000000
+#define DDB_SDRAM_SIZE 0x08000000 /* 128MB, for sure? */
+
+#define DDB_PCI0_MEM_BASE 0x08000000
+#define DDB_PCI0_MEM_SIZE 0x08000000 /* 128 MB */
+
+#define DDB_PCI1_MEM_BASE 0x10000000
+#define DDB_PCI1_MEM_SIZE 0x08000000 /* 128 MB */
+
+#define DDB_PCI0_CONFIG_BASE 0x18000000
+#define DDB_PCI0_CONFIG_SIZE 0x01000000 /* 16 MB */
+
+#define DDB_PCI1_CONFIG_BASE 0x19000000
+#define DDB_PCI1_CONFIG_SIZE 0x01000000 /* 16 MB */
+
+#define DDB_PCI_IO_BASE 0x1a000000 /* we concatenate two IOs */
+#define DDB_PCI0_IO_BASE 0x1a000000
+#define DDB_PCI0_IO_SIZE 0x01000000 /* 16 MB */
+#define DDB_PCI1_IO_BASE 0x1b000000
+#define DDB_PCI1_IO_SIZE 0x01000000 /* 16 MB */
+
+#define DDB_LCS0_BASE 0x1c000000 /* flash memory */
+#define DDB_LCS0_SIZE 0x01000000 /* 16 MB */
+
+#define DDB_LCS1_BASE 0x1d000000 /* misc */
+#define DDB_LCS1_SIZE 0x01000000 /* 16 MB */
+
+#define DDB_LCS2_BASE 0x1e000000 /* Mezzanine */
+#define DDB_LCS2_SIZE 0x01000000 /* 16 MB */
+
+#define DDB_VRC5477_BASE 0x1fa00000 /* VRC5477 control regs */
+#define DDB_VRC5477_SIZE 0x00200000 /* 2MB */
+
+#define DDB_BOOTCS_BASE 0x1fc00000 /* Boot ROM / EPROM /Flash */
+#define DDB_BOOTCS_SIZE 0x00200000 /* 2 MB - doc says 4MB */
+
+#define DDB_LED DDB_LCS1_BASE + 0x10000
+
+
+/*
+ * DDB5477 specific functions
+ */
+extern void ddb5477_irq_setup(void);
+
+/* route irq to cpu int pin */
+extern void ll_vrc5477_irq_route(int vrc5477_irq, int ip);
+
+/* low-level routine for enabling vrc5477 irq, bypassing high-level */
+extern void ll_vrc5477_irq_enable(int vrc5477_irq);
+extern void ll_vrc5477_irq_disable(int vrc5477_irq);
+
+/*
+ * debug routines
+ */
+#if defined(CONFIG_LL_DEBUG)
+extern void vrc5477_show_pdar_regs(void);
+extern void vrc5477_show_pci_regs(void);
+extern void vrc5477_show_bar_regs(void);
+extern void vrc5477_show_int_regs(void);
+extern void vrc5477_show_all_regs(void);
+#endif
+
+#endif /* __ASM_DDB5XXX_DDB5477_H */
diff --git a/include/asm-mips/ddb5xxx/ddb5xxx.h b/include/asm-mips/ddb5xxx/ddb5xxx.h
new file mode 100644
index 000000000..bdb875647
--- /dev/null
+++ b/include/asm-mips/ddb5xxx/ddb5xxx.h
@@ -0,0 +1,271 @@
+/***********************************************************************
+ *
+ * Copyright 2001 MontaVista Software Inc.
+ * Author: jsun@mvista.com or jsun@junsun.net
+ *
+ * Copyright (C) 2000 Geert Uytterhoeven <geert@sonycom.com>
+ * Sony Software Development Center Europe (SDCE), Brussels
+ *
+ * include/asm-mips/ddb5xxx/ddb5xxx.h
+ * Common header for all NEC DDB 5xxx boards, including 5074, 5476, 5477.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ ***********************************************************************
+ */
+
+#ifndef __ASM_DDB5XXX_DDB5XXX_H
+#define __ASM_DDB5XXX_DDB5XXX_H
+
+#include <linux/config.h>
+#include <linux/types.h>
+
+#include <asm/ddb5xxx/debug.h>
+
+/*
+ * This file is based on the following documentation:
+ *
+ * NEC Vrc 5074 System Controller Data Sheet, June 1998
+ *
+ * [jsun] It is modified so that this file only contains the macros
+ * that are true for all DDB 5xxx boards. The modification is based on
+ *
+ * uPD31577(VRC5477) VR5432-SDRAM/PCI Bridge (Luke)
+ * Preliminary Specification Decoment, Rev 1.1, 27 Dec, 2000
+ *
+ */
+
+
+#define DDB_BASE 0xbfa00000
+#define DDB_SIZE 0x00200000 /* 2 MB */
+
+
+/*
+ * Physical Device Address Registers (PDARs)
+ */
+
+#define DDB_SDRAM0 0x0000 /* SDRAM Bank 0 [R/W] */
+#define DDB_SDRAM1 0x0008 /* SDRAM Bank 1 [R/W] */
+#define DDB_LDCS0 0x0010 /* Device Chip-Select 0 [R/W] */
+#define DDB_LDCS1 0x0018 /* Device Chip-Select 1 [R/W] */
+#define DDB_LDCS2 0x0020 /* Device Chip-Select 2 [R/W] */
+#define DDB_LDCS3 0x0028 /* Device Chip-Select 3 [R/W] */
+#define DDB_LDCS4 0x0030 /* Device Chip-Select 4 [R/W] */
+#define DDB_LDCS5 0x0038 /* Device Chip-Select 5 [R/W] */
+#define DDB_PCIW0 0x0060 /* PCI Address Window 0 [R/W] */
+#define DDB_PCIW1 0x0068 /* PCI Address Window 1 [R/W] */
+#define DDB_INTCS 0x0070 /* Controller Internal Registers and Devices */
+ /* [R/W] */
+#define DDB_BOOTCS 0x0078 /* Boot ROM Chip-Select [R/W] */
+/* Vrc5477 has two more, IOPCIW0, IOPCIW1 */
+
+/*
+ * CPU Interface Registers
+ */
+#define DDB_CPUSTAT 0x0080 /* CPU Status [R/W] */
+#define DDB_INTCTRL 0x0088 /* Interrupt Control [R/W] */
+#define DDB_INTSTAT0 0x0090 /* Interrupt Status 0 [R] */
+#define DDB_INTSTAT1 0x0098 /* Interrupt Status 1 and CPU Interrupt */
+ /* Enable [R/W] */
+#define DDB_INTCLR 0x00A0 /* Interrupt Clear [R/W] */
+#define DDB_INTPPES 0x00A8 /* PCI Interrupt Control [R/W] */
+
+
+/*
+ * Memory-Interface Registers
+ */
+#define DDB_MEMCTRL 0x00C0 /* Memory Control */
+#define DDB_ACSTIME 0x00C8 /* Memory Access Timing [R/W] */
+#define DDB_CHKERR 0x00D0 /* Memory Check Error Status [R] */
+
+
+/*
+ * PCI-Bus Registers
+ */
+#define DDB_PCICTRL 0x00E0 /* PCI Control [R/W] */
+#define DDB_PCIARB 0x00E8 /* PCI Arbiter [R/W] */
+#define DDB_PCIINIT0 0x00F0 /* PCI Master (Initiator) 0 [R/W] */
+#define DDB_PCIINIT1 0x00F8 /* PCI Master (Initiator) 1 [R/W] */
+#define DDB_PCIERR 0x00B8 /* PCI Error [R/W] */
+
+
+/*
+ * Local-Bus Registers
+ */
+#define DDB_LCNFG 0x0100 /* Local Bus Configuration [R/W] */
+#define DDB_LCST2 0x0110 /* Local Bus Chip-Select Timing 2 [R/W] */
+#define DDB_LCST3 0x0118 /* Local Bus Chip-Select Timing 3 [R/W] */
+#define DDB_LCST4 0x0120 /* Local Bus Chip-Select Timing 4 [R/W] */
+#define DDB_LCST5 0x0128 /* Local Bus Chip-Select Timing 5 [R/W] */
+#define DDB_LCST6 0x0130 /* Local Bus Chip-Select Timing 6 [R/W] */
+#define DDB_LCST7 0x0138 /* Local Bus Chip-Select Timing 7 [R/W] */
+#define DDB_LCST8 0x0140 /* Local Bus Chip-Select Timing 8 [R/W] */
+#define DDB_DCSFN 0x0150 /* Device Chip-Select Muxing and Output */
+ /* Enables [R/W] */
+#define DDB_DCSIO 0x0158 /* Device Chip-Selects As I/O Bits [R/W] */
+#define DDB_BCST 0x0178 /* Local Boot Chip-Select Timing [R/W] */
+
+
+/*
+ * DMA Registers
+ */
+#define DDB_DMACTRL0 0x0180 /* DMA Control 0 [R/W] */
+#define DDB_DMASRCA0 0x0188 /* DMA Source Address 0 [R/W] */
+#define DDB_DMADESA0 0x0190 /* DMA Destination Address 0 [R/W] */
+#define DDB_DMACTRL1 0x0198 /* DMA Control 1 [R/W] */
+#define DDB_DMASRCA1 0x01A0 /* DMA Source Address 1 [R/W] */
+#define DDB_DMADESA1 0x01A8 /* DMA Destination Address 1 [R/W] */
+
+
+/*
+ * Timer Registers
+ */
+#define DDB_T0CTRL 0x01C0 /* SDRAM Refresh Control [R/W] */
+#define DDB_T0CNTR 0x01C8 /* SDRAM Refresh Counter [R/W] */
+#define DDB_T1CTRL 0x01D0 /* CPU-Bus Read Time-Out Control [R/W] */
+#define DDB_T1CNTR 0x01D8 /* CPU-Bus Read Time-Out Counter [R/W] */
+#define DDB_T2CTRL 0x01E0 /* General-Purpose Timer Control [R/W] */
+#define DDB_T2CNTR 0x01E8 /* General-Purpose Timer Counter [R/W] */
+#define DDB_T3CTRL 0x01F0 /* Watchdog Timer Control [R/W] */
+#define DDB_T3CNTR 0x01F8 /* Watchdog Timer Counter [R/W] */
+
+
+/*
+ * PCI Configuration Space Registers
+ */
+#define DDB_PCI_BASE 0x0200
+
+#define DDB_VID 0x0200 /* PCI Vendor ID [R] */
+#define DDB_DID 0x0202 /* PCI Device ID [R] */
+#define DDB_PCICMD 0x0204 /* PCI Command [R/W] */
+#define DDB_PCISTS 0x0206 /* PCI Status [R/W] */
+#define DDB_REVID 0x0208 /* PCI Revision ID [R] */
+#define DDB_CLASS 0x0209 /* PCI Class Code [R] */
+#define DDB_CLSIZ 0x020C /* PCI Cache Line Size [R/W] */
+#define DDB_MLTIM 0x020D /* PCI Latency Timer [R/W] */
+#define DDB_HTYPE 0x020E /* PCI Header Type [R] */
+#define DDB_BIST 0x020F /* BIST [R] (unimplemented) */
+#define DDB_BARC 0x0210 /* PCI Base Address Register Control [R/W] */
+#define DDB_BAR0 0x0218 /* PCI Base Address Register 0 [R/W] */
+#define DDB_BAR1 0x0220 /* PCI Base Address Register 1 [R/W] */
+#define DDB_CIS 0x0228 /* PCI Cardbus CIS Pointer [R] */
+ /* (unimplemented) */
+#define DDB_SSVID 0x022C /* PCI Sub-System Vendor ID [R/W] */
+#define DDB_SSID 0x022E /* PCI Sub-System ID [R/W] */
+#define DDB_ROM 0x0230 /* Expansion ROM Base Address [R] */
+ /* (unimplemented) */
+#define DDB_INTLIN 0x023C /* PCI Interrupt Line [R/W] */
+#define DDB_INTPIN 0x023D /* PCI Interrupt Pin [R] */
+#define DDB_MINGNT 0x023E /* PCI Min_Gnt [R] (unimplemented) */
+#define DDB_MAXLAT 0x023F /* PCI Max_Lat [R] (unimplemented) */
+#define DDB_BAR2 0x0240 /* PCI Base Address Register 2 [R/W] */
+#define DDB_BAR3 0x0248 /* PCI Base Address Register 3 [R/W] */
+#define DDB_BAR4 0x0250 /* PCI Base Address Register 4 [R/W] */
+#define DDB_BAR5 0x0258 /* PCI Base Address Register 5 [R/W] */
+#define DDB_BAR6 0x0260 /* PCI Base Address Register 6 [R/W] */
+#define DDB_BAR7 0x0268 /* PCI Base Address Register 7 [R/W] */
+#define DDB_BAR8 0x0270 /* PCI Base Address Register 8 [R/W] */
+#define DDB_BARB 0x0278 /* PCI Base Address Register BOOT [R/W] */
+
+
+/*
+ * Nile 4 Register Access
+ */
+
+static inline void ddb_sync(void)
+{
+ volatile u32 *p = (volatile u32 *)0xbfc00000;
+ (void)(*p);
+}
+
+static inline void ddb_out32(u32 offset, u32 val)
+{
+ *(volatile u32 *)(DDB_BASE+offset) = val;
+ ddb_sync();
+}
+
+static inline u32 ddb_in32(u32 offset)
+{
+ u32 val = *(volatile u32 *)(DDB_BASE+offset);
+ ddb_sync();
+ return val;
+}
+
+static inline void ddb_out16(u32 offset, u16 val)
+{
+ *(volatile u16 *)(DDB_BASE+offset) = val;
+ ddb_sync();
+}
+
+static inline u16 ddb_in16(u32 offset)
+{
+ u16 val = *(volatile u16 *)(DDB_BASE+offset);
+ ddb_sync();
+ return val;
+}
+
+static inline void ddb_out8(u32 offset, u8 val)
+{
+ *(volatile u8 *)(DDB_BASE+offset) = val;
+ ddb_sync();
+}
+
+static inline u8 ddb_in8(u32 offset)
+{
+ u8 val = *(volatile u8 *)(DDB_BASE+offset);
+ ddb_sync();
+ return val;
+}
+
+
+/*
+ * Physical Device Address Registers
+ */
+
+extern u32
+ddb_calc_pdar(u32 phys, u32 size, int width, int on_memory_bus, int pci_visible);
+extern void
+ddb_set_pdar(u32 pdar, u32 phys, u32 size, int width,
+ int on_memory_bus, int pci_visible);
+
+/*
+ * PCI Master Registers
+ */
+
+#define DDB_PCICMD_IACK 0 /* PCI Interrupt Acknowledge */
+#define DDB_PCICMD_IO 1 /* PCI I/O Space */
+#define DDB_PCICMD_MEM 3 /* PCI Memory Space */
+#define DDB_PCICMD_CFG 5 /* PCI Configuration Space */
+
+/*
+ * additional options for pci init reg (no shifting needed)
+ */
+#define DDB_PCI_CFGTYPE1 0x200 /* for pci init0/1 regs */
+#define DDB_PCI_ACCESS_32 0x10 /* for pci init0/1 regs */
+
+
+extern void ddb_set_pmr(u32 pmr, u32 type, u32 addr, u32 options);
+
+/*
+ * we need to reset pci bus when we start up and shutdown
+ */
+extern void ddb_pci_reset_bus(void);
+
+
+/*
+ * include the board dependent part
+ */
+#if defined(CONFIG_DDB5074)
+#include <asm/ddb5xxx/ddb5074.h>
+#elif defined(CONFIG_DDB5476)
+#include <asm/ddb5xxx/ddb5476.h>
+#elif defined(CONFIG_DDB5477)
+#include <asm/ddb5xxx/ddb5477.h>
+#else
+#error "Unknown DDB board!"
+#endif
+
+#endif /* __ASM_DDB5XXX_DDB5XXX_H */
diff --git a/include/asm-mips/ddb5xxx/debug.h b/include/asm-mips/ddb5xxx/debug.h
new file mode 100644
index 000000000..6b7da5bec
--- /dev/null
+++ b/include/asm-mips/ddb5xxx/debug.h
@@ -0,0 +1,42 @@
+/***********************************************************************
+ *
+ * Copyright 2001 MontaVista Software Inc.
+ * Author: jsun@mvista.com or jsun@junsun.net
+ *
+ * include/asm-mips/ddb5xxx/debug.h
+ * Some debug macros used by ddb code.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ ***********************************************************************
+ */
+
+#ifndef __ASM_DDB5XXX_DEBUG_H
+#define __ASM_DDB5XXX_DEBUG_H
+
+#include <linux/config.h>
+
+/*
+ * macro for catching spurious errors. Eable to LL_DEBUG in kernel hacking
+ * config menu.
+ */
+#ifdef CONFIG_LL_DEBUG
+
+#include <linux/kernel.h>
+
+#define MIPS_ASSERT(x) if (!(x)) { panic("MIPS_ASSERT failed at %s:%d\n", __FILE__, __LINE__); }
+#define MIPS_VERIFY(x, y) MIPS_ASSERT(x y)
+#define MIPS_DEBUG(x) do { x; } while (0)
+
+#else
+
+#define MIPS_ASSERT(x)
+#define MIPS_VERIFY(x, y) x
+#define MIPS_DEBUG(x)
+
+#endif
+
+#endif /* __ASM_DDB5XXX_DEBUG_H */
diff --git a/include/asm-mips/ddb5xxx/pci.h b/include/asm-mips/ddb5xxx/pci.h
new file mode 100644
index 000000000..b26dacb07
--- /dev/null
+++ b/include/asm-mips/ddb5xxx/pci.h
@@ -0,0 +1,34 @@
+#ifndef __ASM_DDB5XXXX_PCI_H
+#define __ASM_DDB5XXXX_PCI_H
+
+/*
+ * This file essentially defines the interface between board
+ * specific PCI code and MIPS common PCI code. Should potentially put
+ * into include/asm/pci.h file.
+ */
+
+#include <linux/ioport.h>
+#include <linux/pci.h>
+
+/*
+ * Each pci channel is a top-level PCI bus seem by CPU. A machine with
+ * multiple PCI channels may have multiple PCI host controllers or a
+ * single controller supporting multiple channels.
+ */
+struct pci_channel {
+ struct pci_ops *pci_ops;
+ struct resource *io_resource;
+ struct resource *mem_resource;
+};
+
+/*
+ * each board defines an array of pci_channels, that ends with all NULL entry
+ */
+extern struct pci_channel mips_pci_channels[];
+
+/*
+ * board supplied pci irq fixup routine
+ */
+extern void pcibios_fixup_irqs(void);
+
+#endif /* __ASM_DDB5XXXX_PCI_H */
diff --git a/include/asm-mips/serial.h b/include/asm-mips/serial.h
index 6c33daa38..346b321e4 100644
--- a/include/asm-mips/serial.h
+++ b/include/asm-mips/serial.h
@@ -246,6 +246,18 @@
#define MOMENCO_OCELOT_SERIAL_PORT_DEFNS
#endif
+#ifdef CONFIG_DDB5477
+#define DDB5477_SERIAL_PORT_DEFNS \
+ { baud_base: BASE_BAUD, irq: 12, flags: STD_COM_FLAGS, \
+ iomem_base: (u8*)0xbfa04200, iomem_reg_shift: 3, \
+ io_type: SERIAL_IO_MEM},\
+ { baud_base: BASE_BAUD, irq: 28, flags: STD_COM_FLAGS, \
+ iomem_base: (u8*)0xbfa04240, iomem_reg_shift: 3, \
+ io_type: SERIAL_IO_MEM},
+#else
+#define DDB5477_SERIAL_PORT_DEFNS
+#endif
+
#define SERIAL_PORT_DFNS \
IVR_SERIAL_PORT_DEFNS \
ITE_SERIAL_PORT_DEFNS \
@@ -256,4 +268,5 @@
EXTRA_SERIAL_PORT_DEFNS \
HUB6_SERIAL_PORT_DFNS \
MOMENCO_OCELOT_SERIAL_PORT_DEFNS\
- AU1000_SERIAL_PORT_DEFNS
+ AU1000_SERIAL_PORT_DEFNS \
+ DDB5477_SERIAL_PORT_DEFNS
diff --git a/include/asm-mips/time.h b/include/asm-mips/time.h
index 2c07d42de..436bb7c36 100644
--- a/include/asm-mips/time.h
+++ b/include/asm-mips/time.h
@@ -15,6 +15,9 @@
#ifndef _ASM_TIME_H
#define _ASM_TIME_H
+#include <linux/ptrace.h> /* for struct pt_regs */
+#include <linux/linkage.h> /* for asmlinkage */
+
/*
* RTC ops. By default, they point a no-RTC functions.
* rtc_get_time - mktime(year, mon, day, hour, min, sec) in seconds.
diff --git a/include/linux/ac97_codec.h b/include/linux/ac97_codec.h
index 84d6387d5..8052d6b0f 100644
--- a/include/linux/ac97_codec.h
+++ b/include/linux/ac97_codec.h
@@ -32,7 +32,7 @@
#define AC97_PCM_FRONT_DAC_RATE 0x002C /* PCM Front DAC Rate */
#define AC97_PCM_SURR_DAC_RATE 0x002E /* PCM Surround DAC Rate */
#define AC97_PCM_LFE_DAC_RATE 0x0030 /* PCM LFE DAC Rate */
-#define AC97_PCM_LR_DAC_RATE 0x0032 /* PCM LR DAC Rate */
+#define AC97_PCM_LR_ADC_RATE 0x0032 /* PCM LR DAC Rate */
#define AC97_PCM_MIC_ADC_RATE 0x0034 /* PCM MIC ADC Rate */
#define AC97_CENTER_LFE_MASTER 0x0036 /* Center + LFE Master Volume */
#define AC97_SURROUND_MASTER 0x0038 /* Surround (Rear) Master Volume */