Merge branch 'platforms' of git://git.linaro.org/people/rmk/linux-arm
authorLinus Torvalds <torvalds@linux-foundation.org>
Wed, 28 Mar 2012 01:17:02 +0000 (18:17 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 28 Mar 2012 01:17:02 +0000 (18:17 -0700)
Pull ARM platform updates from Russell King:
 "This covers platform stuff for platforms I have a direct interest in
  (iow, I have the hardware).  Essentially:
   - as we no longer support any other Acorn platforms other than RiscPC
     anymore, we can collect all that code into mach-rpc.
   - convert Acorn expansion card stuff to use IRQ allocation functions,
     and get rid of NO_IRQ from there.
   - cleanups to the ebsa110 platform to move some private stuff out of
     its header files.
   - large amount of SA11x0 updates:
   - conversion of private DMA implementation to DMA engine support
     (this actually gives us greater flexibility in drivers over the old
     API.)
   - re-worked ucb1x00 updates - convert to genirq, remove sa11x0
     dependencies, fix various minor issues
   - move platform specific sa11x0 framebuffer data into platform files
     in arch/arm instead of keeping this in the driver itself
   - update sa11x0 IrDA driver for DMA engine, and allow it to use DMA
     for SIR transmissions as well as FIR
   - rework sa1111 support for genirq, and irq allocation
   - fix sa1111 IRQ support so it works again
   - use sparse IRQ support

  After this, I have one more pull request remaining from my current
  set, which I think is going to be the most problematical as it
  generates 8 conflicts."

Fixed up the trivial conflict in arch/arm/mach-rpc/Makefile as per
Russell.

* 'platforms' of git://git.linaro.org/people/rmk/linux-arm: (125 commits)
  ARM: 7343/1: sa11x0: convert to sparse IRQ
  ARM: 7342/2: sa1100: prepare for sparse irq conversion
  ARM: 7341/1: input: prepare jornada720 keyboard and ts for sa11x0 sparse irq
  ARM: 7340/1: rtc: sa1100: include mach/irqs.h instead of asm/irq.h
  ARM: sa11x0: remove unused DMA controller definitions
  ARM: sa11x0: remove old SoC private DMA driver
  USB: sa1111: add hcd .reset method
  USB: sa1111: add OHCI shutdown methods
  USB: sa1111: reorganize ohci-sa1111.c
  USB: sa1111: get rid of nasty printk(KERN_DEBUG "%s: ...", __FILE__)
  USB: sa1111: sparse and checkpatch cleanups
  ARM: sa11x0: don't static map sa1111
  ARM: sa1111: use dev_err() rather than printk()
  ARM: sa1111: cleanup sub-device registration and unregistration
  ARM: sa1111: only setup DMA for DMA capable devices
  ARM: sa1111: register sa1111 devices with dmabounce in bus notifier
  ARM: sa1111: move USB interface register definitions to ohci-sa1111.c
  ARM: sa1111: move PCMCIA interface register definitions to sa1111_generic.c
  ARM: sa1111: move PS/2 interface register definitions to sa1111p2.c
  ARM: sa1111: delete unused physical GPIO register definitions
  ...

13 files changed:
1  2 
arch/arm/Kconfig
arch/arm/kernel/Makefile
arch/arm/mach-ebsa110/core.c
arch/arm/mach-rpc/Makefile
arch/arm/mach-rpc/ecard.c
arch/arm/mach-sa1100/generic.c
arch/arm/mach-sa1100/include/mach/shannon.h
arch/arm/mach-sa1100/pci-nanoengine.c
drivers/mfd/Kconfig
drivers/net/ethernet/smsc/smc91x.c
drivers/pcmcia/sa1111_generic.c
drivers/pcmcia/sa1111_neponset.c
drivers/rtc/rtc-sa1100.c

diff --combined arch/arm/Kconfig
index 94422601ea5b2e6dfb57169ceb760fce8893c5fe,4ade2d83734e03364a4228ec7215d5303e244317..5098564d58799cc8c63e222003a6881a44c509af
@@@ -186,9 -186,6 +186,9 @@@ config GENERIC_ISA_DM
  config FIQ
        bool
  
 +config NEED_RET_TO_USER
 +      bool
 +
  config ARCH_MTD_XIP
        bool
  
@@@ -325,10 -322,9 +325,10 @@@ config ARCH_AT9
        select ARCH_REQUIRE_GPIOLIB
        select HAVE_CLK
        select CLKDEV_LOOKUP
 +      select IRQ_DOMAIN
        help
          This enables support for systems based on the Atmel AT91RM9200,
 -        AT91SAM9 and AT91CAP9 processors.
 +        AT91SAM9 processors.
  
  config ARCH_BCMRING
        bool "Broadcom BCMRING"
@@@ -483,7 -479,6 +483,7 @@@ config ARCH_IOP13X
        select ARCH_SUPPORTS_MSI
        select VMSPLIT_1G
        select NEED_MACH_MEMORY_H
 +      select NEED_RET_TO_USER
        help
          Support for Intel's IOP13XX (XScale) family of processors.
  
@@@ -491,7 -486,6 +491,7 @@@ config ARCH_IOP32
        bool "IOP32x-based"
        depends on MMU
        select CPU_XSCALE
 +      select NEED_RET_TO_USER
        select PLAT_IOP
        select PCI
        select ARCH_REQUIRE_GPIOLIB
@@@ -503,7 -497,6 +503,7 @@@ config ARCH_IOP33
        bool "IOP33x-based"
        depends on MMU
        select CPU_XSCALE
 +      select NEED_RET_TO_USER
        select PLAT_IOP
        select PCI
        select ARCH_REQUIRE_GPIOLIB
@@@ -738,7 -731,6 +738,6 @@@ config ARCH_RP
        bool "RiscPC"
        select ARCH_ACORN
        select FIQ
-       select TIMER_ACORN
        select ARCH_MAY_HAVE_PC_FDC
        select HAVE_PATA_PLATFORM
        select ISA_DMA_API
@@@ -761,30 -753,32 +760,31 @@@ config ARCH_SA110
        select ARCH_HAS_CPUFREQ
        select CPU_FREQ
        select GENERIC_CLOCKEVENTS
 -      select HAVE_CLK
 +      select CLKDEV_LOOKUP
        select HAVE_SCHED_CLOCK
        select TICK_ONESHOT
        select ARCH_REQUIRE_GPIOLIB
        select HAVE_IDE
        select NEED_MACH_MEMORY_H
+       select SPARSE_IRQ
        help
          Support for StrongARM 11x0 based boards.
  
 -config ARCH_S3C2410
 -      bool "Samsung S3C2410, S3C2412, S3C2413, S3C2416, S3C2440, S3C2442, S3C2443, S3C2450"
 +config ARCH_S3C24XX
 +      bool "Samsung S3C24XX SoCs"
        select GENERIC_GPIO
        select ARCH_HAS_CPUFREQ
        select HAVE_CLK
        select CLKDEV_LOOKUP
        select ARCH_USES_GETTIMEOFFSET
        select HAVE_S3C2410_I2C if I2C
 +      select HAVE_S3C_RTC if RTC_CLASS
 +      select HAVE_S3C2410_WATCHDOG if WATCHDOG
        help
 -        Samsung S3C2410X CPU based systems, such as the Simtec Electronics
 -        BAST (<http://www.simtec.co.uk/products/EB110ITX/>), the IPAQ 1940 or
 -        the Samsung SMDK2410 development board (and derivatives).
 -
 -        Note, the S3C2416 and the S3C2450 are so close that they even share
 -        the same SoC ID code. This means that there is no separate machine
 -        directory (no arch/arm/mach-s3c2450) as the S3C2416 was first.
 +        Samsung S3C2410, S3C2412, S3C2413, S3C2416, S3C2440, S3C2442, S3C2443
 +        and S3C2450 SoCs based systems, such as the Simtec Electronics BAST
 +        (<http://www.simtec.co.uk/products/EB110ITX/>), the IPAQ 1940 or the
 +        Samsung SMDK2410 development board (and derivatives).
  
  config ARCH_S3C64XX
        bool "Samsung S3C64XX"
@@@ -907,7 -901,6 +907,7 @@@ config ARCH_U30
  
  config ARCH_U8500
        bool "ST-Ericsson U8500 Series"
 +      depends on MMU
        select CPU_V7
        select ARM_AMBA
        select GENERIC_CLOCKEVENTS
@@@ -1073,10 -1066,12 +1073,10 @@@ source "arch/arm/plat-s5p/Kconfig
  
  source "arch/arm/plat-spear/Kconfig"
  
 -if ARCH_S3C2410
 -source "arch/arm/mach-s3c2410/Kconfig"
 +source "arch/arm/mach-s3c24xx/Kconfig"
 +if ARCH_S3C24XX
  source "arch/arm/mach-s3c2412/Kconfig"
 -source "arch/arm/mach-s3c2416/Kconfig"
  source "arch/arm/mach-s3c2440/Kconfig"
 -source "arch/arm/mach-s3c2443/Kconfig"
  endif
  
  if ARCH_S3C64XX
@@@ -1132,7 -1127,6 +1132,7 @@@ config PLAT_VERSATIL
  config ARM_TIMER_SP804
        bool
        select CLKSRC_MMIO
 +      select HAVE_SCHED_CLOCK
  
  source arch/arm/mm/Kconfig
  
@@@ -1286,7 -1280,7 +1286,7 @@@ config ARM_ERRATA_74362
        depends on CPU_V7
        help
          This option enables the workaround for the 743622 Cortex-A9
 -        (r2p0..r2p2) erratum. Under very rare conditions, a faulty
 +        (r2p*) erratum. Under very rare conditions, a faulty
          optimisation in the Cortex-A9 Store Buffer may lead to data
          corruption. This workaround sets a specific bit in the diagnostic
          register of the Cortex-A9 which disables the Store Buffer
@@@ -1583,8 -1577,7 +1583,8 @@@ config LOCAL_TIMER
  config ARCH_NR_GPIO
        int
        default 1024 if ARCH_SHMOBILE || ARCH_TEGRA
 -      default 350 if ARCH_U8500
 +      default 355 if ARCH_U8500
 +      default 264 if MACH_H4700
        default 0
        help
          Maximum number of GPIOs in the system.
@@@ -1595,7 -1588,7 +1595,7 @@@ source kernel/Kconfig.preemp
  
  config HZ
        int
 -      default 200 if ARCH_EBSA110 || ARCH_S3C2410 || ARCH_S5P64X0 || \
 +      default 200 if ARCH_EBSA110 || ARCH_S3C24XX || ARCH_S5P64X0 || \
                ARCH_S5PV210 || ARCH_EXYNOS4
        default OMAP_32K_TIMER_HZ if ARCH_OMAP && OMAP_32K_TIMER
        default AT91_TIMER_HZ if ARCH_AT91
@@@ -2121,7 -2114,7 +2121,7 @@@ config CPU_FREQ_S3
  
  config CPU_FREQ_S3C24XX
        bool "CPUfreq driver for Samsung S3C24XX series CPUs (EXPERIMENTAL)"
 -      depends on ARCH_S3C2410 && CPU_FREQ && EXPERIMENTAL
 +      depends on ARCH_S3C24XX && CPU_FREQ && EXPERIMENTAL
        select CPU_FREQ_S3C
        help
          This enables the CPUfreq driver for the Samsung S3C24XX family
diff --combined arch/arm/kernel/Makefile
index f16d7652f34b040d1d8e3e3cb3cb4878527f884e,17663c63f7a1de95fd7462ded2c0f505828f7761..3a274878412ec7b1728de840469cd1ffc68e3a38
@@@ -23,7 -23,6 +23,6 @@@ obj-$(CONFIG_LEDS)            += leds.
  obj-$(CONFIG_OC_ETM)          += etm.o
  
  obj-$(CONFIG_ISA_DMA_API)     += dma.o
- obj-$(CONFIG_ARCH_ACORN)      += ecard.o 
  obj-$(CONFIG_FIQ)             += fiq.o fiqasm.o
  obj-$(CONFIG_MODULES)         += armksyms.o module.o
  obj-$(CONFIG_ARTHUR)          += arthur.o
@@@ -62,6 -61,9 +61,6 @@@ obj-$(CONFIG_SWP_EMULATE)     += swp_emulat
  CFLAGS_swp_emulate.o          := -Wa,-march=armv7-a
  obj-$(CONFIG_HAVE_HW_BREAKPOINT)      += hw_breakpoint.o
  
 -obj-$(CONFIG_CRUNCH)          += crunch.o crunch-bits.o
 -AFLAGS_crunch-bits.o          := -Wa,-mcpu=ep9312
 -
  obj-$(CONFIG_CPU_XSCALE)      += xscale-cp0.o
  obj-$(CONFIG_CPU_XSC3)                += xscale-cp0.o
  obj-$(CONFIG_CPU_MOHAWK)      += xscale-cp0.o
index 804c9122b7b3626e76eadcd3c950429612e87969,6235efb0ccd43d044747924eefb4f461299958cc..e400d75d11aee5eb0e575bf1268e99a79259387f
  
  #include <asm/mach/time.h>
  
- #define IRQ_MASK              0xfe000000      /* read */
- #define IRQ_MSET              0xfe000000      /* write */
- #define IRQ_STAT              0xff000000      /* read */
- #define IRQ_MCLR              0xff000000      /* write */
+ #include "core.h"
  
  static void ebsa110_mask_irq(struct irq_data *d)
  {
@@@ -79,22 -76,22 +76,22 @@@ static struct map_desc ebsa110_io_desc[
        {       /* IRQ_STAT/IRQ_MCLR */
                .virtual        = IRQ_STAT,
                .pfn            = __phys_to_pfn(TRICK4_PHYS),
-               .length         = PGDIR_SIZE,
+               .length         = TRICK4_SIZE,
                .type           = MT_DEVICE
        }, {    /* IRQ_MASK/IRQ_MSET */
                .virtual        = IRQ_MASK,
                .pfn            = __phys_to_pfn(TRICK3_PHYS),
-               .length         = PGDIR_SIZE,
+               .length         = TRICK3_SIZE,
                .type           = MT_DEVICE
        }, {    /* SOFT_BASE */
                .virtual        = SOFT_BASE,
                .pfn            = __phys_to_pfn(TRICK1_PHYS),
-               .length         = PGDIR_SIZE,
+               .length         = TRICK1_SIZE,
                .type           = MT_DEVICE
        }, {    /* PIT_BASE */
                .virtual        = PIT_BASE,
                .pfn            = __phys_to_pfn(TRICK0_PHYS),
-               .length         = PGDIR_SIZE,
+               .length         = TRICK0_SIZE,
                .type           = MT_DEVICE
        },
  
@@@ -271,33 -268,8 +268,33 @@@ static struct platform_device *ebsa110_
        &am79c961_device,
  };
  
 +/*
 + * EBSA110 idling methodology:
 + *
 + * We can not execute the "wait for interrupt" instruction since that
 + * will stop our MCLK signal (which provides the clock for the glue
 + * logic, and therefore the timer interrupt).
 + *
 + * Instead, we spin, polling the IRQ_STAT register for the occurrence
 + * of any interrupt with core clock down to the memory clock.
 + */
 +static void ebsa110_idle(void)
 +{
 +      const char *irq_stat = (char *)0xff000000;
 +
 +      /* disable clock switching */
 +      asm volatile ("mcr p15, 0, ip, c15, c2, 2" : : : "cc");
 +
 +      /* wait for an interrupt to occur */
 +      while (!*irq_stat);
 +
 +      /* enable clock switching */
 +      asm volatile ("mcr p15, 0, ip, c15, c1, 2" : : : "cc");
 +}
 +
  static int __init ebsa110_init(void)
  {
 +      arm_pm_idle = ebsa110_idle;
        return platform_add_devices(ebsa110_devices, ARRAY_SIZE(ebsa110_devices));
  }
  
index dfa405c0cfde10b356579c8fec842d76c98a301d,f89320739b09d7b605b835cbb4e0b1ca9e0e3188..992e28b4ae9a54ddab9ea92b2d0c92d6b303964e
@@@ -4,7 -4,7 +4,7 @@@
  
  # Object file lists.
  
- obj-y                 := dma.o fiq.o irq.o riscpc.o
 -obj-y                 := dma.o ecard.o irq.o riscpc.o time.o
++obj-y                 := dma.o ecard.o fiq.o irq.o riscpc.o time.o
  obj-m                 :=
  obj-n                 :=
  obj-                  :=
index 0000000000000000000000000000000000000000,0c01567007c87cbcc3f25904f8b63ad827271d55..b91bc87b3dcf9a6a2a9ae33671c6ac053746f17c
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,1137 +1,1138 @@@
+ /*
+  *  linux/arch/arm/kernel/ecard.c
+  *
+  *  Copyright 1995-2001 Russell King
+  *
+  * This program is free software; you can redistribute it and/or modify
+  * it under the terms of the GNU General Public License version 2 as
+  * published by the Free Software Foundation.
+  *
+  *  Find all installed expansion cards, and handle interrupts from them.
+  *
+  *  Created from information from Acorns RiscOS3 PRMs
+  *
+  *  08-Dec-1996       RMK     Added code for the 9'th expansion card - the ether
+  *                    podule slot.
+  *  06-May-1997       RMK     Added blacklist for cards whose loader doesn't work.
+  *  12-Sep-1997       RMK     Created new handling of interrupt enables/disables
+  *                    - cards can now register their own routine to control
+  *                    interrupts (recommended).
+  *  29-Sep-1997       RMK     Expansion card interrupt hardware not being re-enabled
+  *                    on reset from Linux. (Caused cards not to respond
+  *                    under RiscOS without hard reset).
+  *  15-Feb-1998       RMK     Added DMA support
+  *  12-Sep-1998       RMK     Added EASI support
+  *  10-Jan-1999       RMK     Run loaders in a simulated RISC OS environment.
+  *  17-Apr-1999       RMK     Support for EASI Type C cycles.
+  */
+ #define ECARD_C
+ #include <linux/module.h>
+ #include <linux/kernel.h>
+ #include <linux/types.h>
+ #include <linux/sched.h>
+ #include <linux/interrupt.h>
+ #include <linux/completion.h>
+ #include <linux/reboot.h>
+ #include <linux/mm.h>
+ #include <linux/slab.h>
+ #include <linux/proc_fs.h>
+ #include <linux/seq_file.h>
+ #include <linux/device.h>
+ #include <linux/init.h>
+ #include <linux/mutex.h>
+ #include <linux/kthread.h>
+ #include <linux/irq.h>
+ #include <linux/io.h>
+ #include <asm/dma.h>
+ #include <asm/ecard.h>
+ #include <mach/hardware.h>
+ #include <asm/irq.h>
+ #include <asm/mmu_context.h>
+ #include <asm/mach/irq.h>
+ #include <asm/tlbflush.h>
+ #include "ecard.h"
+ struct ecard_request {
+       void            (*fn)(struct ecard_request *);
+       ecard_t         *ec;
+       unsigned int    address;
+       unsigned int    length;
+       unsigned int    use_loader;
+       void            *buffer;
+       struct completion *complete;
+ };
+ struct expcard_blacklist {
+       unsigned short   manufacturer;
+       unsigned short   product;
+       const char      *type;
+ };
+ static ecard_t *cards;
+ static ecard_t *slot_to_expcard[MAX_ECARDS];
+ static unsigned int ectcr;
+ /* List of descriptions of cards which don't have an extended
+  * identification, or chunk directories containing a description.
+  */
+ static struct expcard_blacklist __initdata blacklist[] = {
+       { MANU_ACORN, PROD_ACORN_ETHER1, "Acorn Ether1" }
+ };
+ asmlinkage extern int
+ ecard_loader_reset(unsigned long base, loader_t loader);
+ asmlinkage extern int
+ ecard_loader_read(int off, unsigned long base, loader_t loader);
+ static inline unsigned short ecard_getu16(unsigned char *v)
+ {
+       return v[0] | v[1] << 8;
+ }
+ static inline signed long ecard_gets24(unsigned char *v)
+ {
+       return v[0] | v[1] << 8 | v[2] << 16 | ((v[2] & 0x80) ? 0xff000000 : 0);
+ }
+ static inline ecard_t *slot_to_ecard(unsigned int slot)
+ {
+       return slot < MAX_ECARDS ? slot_to_expcard[slot] : NULL;
+ }
+ /* ===================== Expansion card daemon ======================== */
+ /*
+  * Since the loader programs on the expansion cards need to be run
+  * in a specific environment, create a separate task with this
+  * environment up, and pass requests to this task as and when we
+  * need to.
+  *
+  * This should allow 99% of loaders to be called from Linux.
+  *
+  * From a security standpoint, we trust the card vendors.  This
+  * may be a misplaced trust.
+  */
+ static void ecard_task_reset(struct ecard_request *req)
+ {
+       struct expansion_card *ec = req->ec;
+       struct resource *res;
+       res = ec->slot_no == 8
+               ? &ec->resource[ECARD_RES_MEMC]
+               : ec->easi
+                 ? &ec->resource[ECARD_RES_EASI]
+                 : &ec->resource[ECARD_RES_IOCSYNC];
+       ecard_loader_reset(res->start, ec->loader);
+ }
+ static void ecard_task_readbytes(struct ecard_request *req)
+ {
+       struct expansion_card *ec = req->ec;
+       unsigned char *buf = req->buffer;
+       unsigned int len = req->length;
+       unsigned int off = req->address;
+       if (ec->slot_no == 8) {
+               void __iomem *base = (void __iomem *)
+                               ec->resource[ECARD_RES_MEMC].start;
+               /*
+                * The card maintains an index which increments the address
+                * into a 4096-byte page on each access.  We need to keep
+                * track of the counter.
+                */
+               static unsigned int index;
+               unsigned int page;
+               page = (off >> 12) * 4;
+               if (page > 256 * 4)
+                       return;
+               off &= 4095;
+               /*
+                * If we are reading offset 0, or our current index is
+                * greater than the offset, reset the hardware index counter.
+                */
+               if (off == 0 || index > off) {
+                       writeb(0, base);
+                       index = 0;
+               }
+               /*
+                * Increment the hardware index counter until we get to the
+                * required offset.  The read bytes are discarded.
+                */
+               while (index < off) {
+                       readb(base + page);
+                       index += 1;
+               }
+               while (len--) {
+                       *buf++ = readb(base + page);
+                       index += 1;
+               }
+       } else {
+               unsigned long base = (ec->easi
+                        ? &ec->resource[ECARD_RES_EASI]
+                        : &ec->resource[ECARD_RES_IOCSYNC])->start;
+               void __iomem *pbase = (void __iomem *)base;
+               if (!req->use_loader || !ec->loader) {
+                       off *= 4;
+                       while (len--) {
+                               *buf++ = readb(pbase + off);
+                               off += 4;
+                       }
+               } else {
+                       while(len--) {
+                               /*
+                                * The following is required by some
+                                * expansion card loader programs.
+                                */
+                               *(unsigned long *)0x108 = 0;
+                               *buf++ = ecard_loader_read(off++, base,
+                                                          ec->loader);
+                       }
+               }
+       }
+ }
+ static DECLARE_WAIT_QUEUE_HEAD(ecard_wait);
+ static struct ecard_request *ecard_req;
+ static DEFINE_MUTEX(ecard_mutex);
+ /*
+  * Set up the expansion card daemon's page tables.
+  */
+ static void ecard_init_pgtables(struct mm_struct *mm)
+ {
+       struct vm_area_struct vma;
+       /* We want to set up the page tables for the following mapping:
+        *  Virtual     Physical
+        *  0x03000000  0x03000000
+        *  0x03010000  unmapped
+        *  0x03210000  0x03210000
+        *  0x03400000  unmapped
+        *  0x08000000  0x08000000
+        *  0x10000000  unmapped
+        *
+        * FIXME: we don't follow this 100% yet.
+        */
+       pgd_t *src_pgd, *dst_pgd;
+       src_pgd = pgd_offset(mm, (unsigned long)IO_BASE);
+       dst_pgd = pgd_offset(mm, IO_START);
+       memcpy(dst_pgd, src_pgd, sizeof(pgd_t) * (IO_SIZE / PGDIR_SIZE));
+       src_pgd = pgd_offset(mm, (unsigned long)EASI_BASE);
+       dst_pgd = pgd_offset(mm, EASI_START);
+       memcpy(dst_pgd, src_pgd, sizeof(pgd_t) * (EASI_SIZE / PGDIR_SIZE));
++      vma.vm_flags = VM_EXEC;
+       vma.vm_mm = mm;
+       flush_tlb_range(&vma, IO_START, IO_START + IO_SIZE);
+       flush_tlb_range(&vma, EASI_START, EASI_START + EASI_SIZE);
+ }
+ static int ecard_init_mm(void)
+ {
+       struct mm_struct * mm = mm_alloc();
+       struct mm_struct *active_mm = current->active_mm;
+       if (!mm)
+               return -ENOMEM;
+       current->mm = mm;
+       current->active_mm = mm;
+       activate_mm(active_mm, mm);
+       mmdrop(active_mm);
+       ecard_init_pgtables(mm);
+       return 0;
+ }
+ static int
+ ecard_task(void * unused)
+ {
+       /*
+        * Allocate a mm.  We're not a lazy-TLB kernel task since we need
+        * to set page table entries where the user space would be.  Note
+        * that this also creates the page tables.  Failure is not an
+        * option here.
+        */
+       if (ecard_init_mm())
+               panic("kecardd: unable to alloc mm\n");
+       while (1) {
+               struct ecard_request *req;
+               wait_event_interruptible(ecard_wait, ecard_req != NULL);
+               req = xchg(&ecard_req, NULL);
+               if (req != NULL) {
+                       req->fn(req);
+                       complete(req->complete);
+               }
+       }
+ }
+ /*
+  * Wake the expansion card daemon to action our request.
+  *
+  * FIXME: The test here is not sufficient to detect if the
+  * kcardd is running.
+  */
+ static void ecard_call(struct ecard_request *req)
+ {
+       DECLARE_COMPLETION_ONSTACK(completion);
+       req->complete = &completion;
+       mutex_lock(&ecard_mutex);
+       ecard_req = req;
+       wake_up(&ecard_wait);
+       /*
+        * Now wait for kecardd to run.
+        */
+       wait_for_completion(&completion);
+       mutex_unlock(&ecard_mutex);
+ }
+ /* ======================= Mid-level card control ===================== */
+ static void
+ ecard_readbytes(void *addr, ecard_t *ec, int off, int len, int useld)
+ {
+       struct ecard_request req;
+       req.fn          = ecard_task_readbytes;
+       req.ec          = ec;
+       req.address     = off;
+       req.length      = len;
+       req.use_loader  = useld;
+       req.buffer      = addr;
+       ecard_call(&req);
+ }
+ int ecard_readchunk(struct in_chunk_dir *cd, ecard_t *ec, int id, int num)
+ {
+       struct ex_chunk_dir excd;
+       int index = 16;
+       int useld = 0;
+       if (!ec->cid.cd)
+               return 0;
+       while(1) {
+               ecard_readbytes(&excd, ec, index, 8, useld);
+               index += 8;
+               if (c_id(&excd) == 0) {
+                       if (!useld && ec->loader) {
+                               useld = 1;
+                               index = 0;
+                               continue;
+                       }
+                       return 0;
+               }
+               if (c_id(&excd) == 0xf0) { /* link */
+                       index = c_start(&excd);
+                       continue;
+               }
+               if (c_id(&excd) == 0x80) { /* loader */
+                       if (!ec->loader) {
+                               ec->loader = kmalloc(c_len(&excd),
+                                                              GFP_KERNEL);
+                               if (ec->loader)
+                                       ecard_readbytes(ec->loader, ec,
+                                                       (int)c_start(&excd),
+                                                       c_len(&excd), useld);
+                               else
+                                       return 0;
+                       }
+                       continue;
+               }
+               if (c_id(&excd) == id && num-- == 0)
+                       break;
+       }
+       if (c_id(&excd) & 0x80) {
+               switch (c_id(&excd) & 0x70) {
+               case 0x70:
+                       ecard_readbytes((unsigned char *)excd.d.string, ec,
+                                       (int)c_start(&excd), c_len(&excd),
+                                       useld);
+                       break;
+               case 0x00:
+                       break;
+               }
+       }
+       cd->start_offset = c_start(&excd);
+       memcpy(cd->d.string, excd.d.string, 256);
+       return 1;
+ }
+ /* ======================= Interrupt control ============================ */
+ static void ecard_def_irq_enable(ecard_t *ec, int irqnr)
+ {
+ }
+ static void ecard_def_irq_disable(ecard_t *ec, int irqnr)
+ {
+ }
+ static int ecard_def_irq_pending(ecard_t *ec)
+ {
+       return !ec->irqmask || readb(ec->irqaddr) & ec->irqmask;
+ }
+ static void ecard_def_fiq_enable(ecard_t *ec, int fiqnr)
+ {
+       panic("ecard_def_fiq_enable called - impossible");
+ }
+ static void ecard_def_fiq_disable(ecard_t *ec, int fiqnr)
+ {
+       panic("ecard_def_fiq_disable called - impossible");
+ }
+ static int ecard_def_fiq_pending(ecard_t *ec)
+ {
+       return !ec->fiqmask || readb(ec->fiqaddr) & ec->fiqmask;
+ }
+ static expansioncard_ops_t ecard_default_ops = {
+       ecard_def_irq_enable,
+       ecard_def_irq_disable,
+       ecard_def_irq_pending,
+       ecard_def_fiq_enable,
+       ecard_def_fiq_disable,
+       ecard_def_fiq_pending
+ };
+ /*
+  * Enable and disable interrupts from expansion cards.
+  * (interrupts are disabled for these functions).
+  *
+  * They are not meant to be called directly, but via enable/disable_irq.
+  */
+ static void ecard_irq_unmask(struct irq_data *d)
+ {
+       ecard_t *ec = irq_data_get_irq_chip_data(d);
+       if (ec) {
+               if (!ec->ops)
+                       ec->ops = &ecard_default_ops;
+               if (ec->claimed && ec->ops->irqenable)
+                       ec->ops->irqenable(ec, d->irq);
+               else
+                       printk(KERN_ERR "ecard: rejecting request to "
+                               "enable IRQs for %d\n", d->irq);
+       }
+ }
+ static void ecard_irq_mask(struct irq_data *d)
+ {
+       ecard_t *ec = irq_data_get_irq_chip_data(d);
+       if (ec) {
+               if (!ec->ops)
+                       ec->ops = &ecard_default_ops;
+               if (ec->ops && ec->ops->irqdisable)
+                       ec->ops->irqdisable(ec, d->irq);
+       }
+ }
+ static struct irq_chip ecard_chip = {
+       .name           = "ECARD",
+       .irq_ack        = ecard_irq_mask,
+       .irq_mask       = ecard_irq_mask,
+       .irq_unmask     = ecard_irq_unmask,
+ };
+ void ecard_enablefiq(unsigned int fiqnr)
+ {
+       ecard_t *ec = slot_to_ecard(fiqnr);
+       if (ec) {
+               if (!ec->ops)
+                       ec->ops = &ecard_default_ops;
+               if (ec->claimed && ec->ops->fiqenable)
+                       ec->ops->fiqenable(ec, fiqnr);
+               else
+                       printk(KERN_ERR "ecard: rejecting request to "
+                               "enable FIQs for %d\n", fiqnr);
+       }
+ }
+ void ecard_disablefiq(unsigned int fiqnr)
+ {
+       ecard_t *ec = slot_to_ecard(fiqnr);
+       if (ec) {
+               if (!ec->ops)
+                       ec->ops = &ecard_default_ops;
+               if (ec->ops->fiqdisable)
+                       ec->ops->fiqdisable(ec, fiqnr);
+       }
+ }
+ static void ecard_dump_irq_state(void)
+ {
+       ecard_t *ec;
+       printk("Expansion card IRQ state:\n");
+       for (ec = cards; ec; ec = ec->next) {
+               if (ec->slot_no == 8)
+                       continue;
+               printk("  %d: %sclaimed, ",
+                      ec->slot_no, ec->claimed ? "" : "not ");
+               if (ec->ops && ec->ops->irqpending &&
+                   ec->ops != &ecard_default_ops)
+                       printk("irq %spending\n",
+                              ec->ops->irqpending(ec) ? "" : "not ");
+               else
+                       printk("irqaddr %p, mask = %02X, status = %02X\n",
+                              ec->irqaddr, ec->irqmask, readb(ec->irqaddr));
+       }
+ }
+ static void ecard_check_lockup(struct irq_desc *desc)
+ {
+       static unsigned long last;
+       static int lockup;
+       /*
+        * If the timer interrupt has not run since the last million
+        * unrecognised expansion card interrupts, then there is
+        * something seriously wrong.  Disable the expansion card
+        * interrupts so at least we can continue.
+        *
+        * Maybe we ought to start a timer to re-enable them some time
+        * later?
+        */
+       if (last == jiffies) {
+               lockup += 1;
+               if (lockup > 1000000) {
+                       printk(KERN_ERR "\nInterrupt lockup detected - "
+                              "disabling all expansion card interrupts\n");
+                       desc->irq_data.chip->irq_mask(&desc->irq_data);
+                       ecard_dump_irq_state();
+               }
+       } else
+               lockup = 0;
+       /*
+        * If we did not recognise the source of this interrupt,
+        * warn the user, but don't flood the user with these messages.
+        */
+       if (!last || time_after(jiffies, last + 5*HZ)) {
+               last = jiffies;
+               printk(KERN_WARNING "Unrecognised interrupt from backplane\n");
+               ecard_dump_irq_state();
+       }
+ }
+ static void
+ ecard_irq_handler(unsigned int irq, struct irq_desc *desc)
+ {
+       ecard_t *ec;
+       int called = 0;
+       desc->irq_data.chip->irq_mask(&desc->irq_data);
+       for (ec = cards; ec; ec = ec->next) {
+               int pending;
+               if (!ec->claimed || !ec->irq || ec->slot_no == 8)
+                       continue;
+               if (ec->ops && ec->ops->irqpending)
+                       pending = ec->ops->irqpending(ec);
+               else
+                       pending = ecard_default_ops.irqpending(ec);
+               if (pending) {
+                       generic_handle_irq(ec->irq);
+                       called ++;
+               }
+       }
+       desc->irq_data.chip->irq_unmask(&desc->irq_data);
+       if (called == 0)
+               ecard_check_lockup(desc);
+ }
+ static void __iomem *__ecard_address(ecard_t *ec, card_type_t type, card_speed_t speed)
+ {
+       void __iomem *address = NULL;
+       int slot = ec->slot_no;
+       if (ec->slot_no == 8)
+               return ECARD_MEMC8_BASE;
+       ectcr &= ~(1 << slot);
+       switch (type) {
+       case ECARD_MEMC:
+               if (slot < 4)
+                       address = ECARD_MEMC_BASE + (slot << 14);
+               break;
+       case ECARD_IOC:
+               if (slot < 4)
+                       address = ECARD_IOC_BASE + (slot << 14);
+               else
+                       address = ECARD_IOC4_BASE + ((slot - 4) << 14);
+               if (address)
+                       address += speed << 19;
+               break;
+       case ECARD_EASI:
+               address = ECARD_EASI_BASE + (slot << 24);
+               if (speed == ECARD_FAST)
+                       ectcr |= 1 << slot;
+               break;
+       default:
+               break;
+       }
+ #ifdef IOMD_ECTCR
+       iomd_writeb(ectcr, IOMD_ECTCR);
+ #endif
+       return address;
+ }
+ static int ecard_prints(struct seq_file *m, ecard_t *ec)
+ {
+       seq_printf(m, "  %d: %s ", ec->slot_no, ec->easi ? "EASI" : "    ");
+       if (ec->cid.id == 0) {
+               struct in_chunk_dir incd;
+               seq_printf(m, "[%04X:%04X] ",
+                       ec->cid.manufacturer, ec->cid.product);
+               if (!ec->card_desc && ec->cid.cd &&
+                   ecard_readchunk(&incd, ec, 0xf5, 0)) {
+                       ec->card_desc = kmalloc(strlen(incd.d.string)+1, GFP_KERNEL);
+                       if (ec->card_desc)
+                               strcpy((char *)ec->card_desc, incd.d.string);
+               }
+               seq_printf(m, "%s\n", ec->card_desc ? ec->card_desc : "*unknown*");
+       } else
+               seq_printf(m, "Simple card %d\n", ec->cid.id);
+       return 0;
+ }
+ static int ecard_devices_proc_show(struct seq_file *m, void *v)
+ {
+       ecard_t *ec = cards;
+       while (ec) {
+               ecard_prints(m, ec);
+               ec = ec->next;
+       }
+       return 0;
+ }
+ static int ecard_devices_proc_open(struct inode *inode, struct file *file)
+ {
+       return single_open(file, ecard_devices_proc_show, NULL);
+ }
+ static const struct file_operations bus_ecard_proc_fops = {
+       .owner          = THIS_MODULE,
+       .open           = ecard_devices_proc_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+ };
+ static struct proc_dir_entry *proc_bus_ecard_dir = NULL;
+ static void ecard_proc_init(void)
+ {
+       proc_bus_ecard_dir = proc_mkdir("bus/ecard", NULL);
+       proc_create("devices", 0, proc_bus_ecard_dir, &bus_ecard_proc_fops);
+ }
+ #define ec_set_resource(ec,nr,st,sz)                          \
+       do {                                                    \
+               (ec)->resource[nr].name = dev_name(&ec->dev);   \
+               (ec)->resource[nr].start = st;                  \
+               (ec)->resource[nr].end = (st) + (sz) - 1;       \
+               (ec)->resource[nr].flags = IORESOURCE_MEM;      \
+       } while (0)
+ static void __init ecard_free_card(struct expansion_card *ec)
+ {
+       int i;
+       for (i = 0; i < ECARD_NUM_RESOURCES; i++)
+               if (ec->resource[i].flags)
+                       release_resource(&ec->resource[i]);
+       kfree(ec);
+ }
+ static struct expansion_card *__init ecard_alloc_card(int type, int slot)
+ {
+       struct expansion_card *ec;
+       unsigned long base;
+       int i;
+       ec = kzalloc(sizeof(ecard_t), GFP_KERNEL);
+       if (!ec) {
+               ec = ERR_PTR(-ENOMEM);
+               goto nomem;
+       }
+       ec->slot_no = slot;
+       ec->easi = type == ECARD_EASI;
+       ec->irq = 0;
+       ec->fiq = 0;
+       ec->dma = NO_DMA;
+       ec->ops = &ecard_default_ops;
+       dev_set_name(&ec->dev, "ecard%d", slot);
+       ec->dev.parent = NULL;
+       ec->dev.bus = &ecard_bus_type;
+       ec->dev.dma_mask = &ec->dma_mask;
+       ec->dma_mask = (u64)0xffffffff;
+       ec->dev.coherent_dma_mask = ec->dma_mask;
+       if (slot < 4) {
+               ec_set_resource(ec, ECARD_RES_MEMC,
+                               PODSLOT_MEMC_BASE + (slot << 14),
+                               PODSLOT_MEMC_SIZE);
+               base = PODSLOT_IOC0_BASE + (slot << 14);
+       } else
+               base = PODSLOT_IOC4_BASE + ((slot - 4) << 14);
+ #ifdef CONFIG_ARCH_RPC
+       if (slot < 8) {
+               ec_set_resource(ec, ECARD_RES_EASI,
+                               PODSLOT_EASI_BASE + (slot << 24),
+                               PODSLOT_EASI_SIZE);
+       }
+       if (slot == 8) {
+               ec_set_resource(ec, ECARD_RES_MEMC, NETSLOT_BASE, NETSLOT_SIZE);
+       } else
+ #endif
+       for (i = 0; i <= ECARD_RES_IOCSYNC - ECARD_RES_IOCSLOW; i++)
+               ec_set_resource(ec, i + ECARD_RES_IOCSLOW,
+                               base + (i << 19), PODSLOT_IOC_SIZE);
+       for (i = 0; i < ECARD_NUM_RESOURCES; i++) {
+               if (ec->resource[i].flags &&
+                   request_resource(&iomem_resource, &ec->resource[i])) {
+                       dev_err(&ec->dev, "resource(s) not available\n");
+                       ec->resource[i].end -= ec->resource[i].start;
+                       ec->resource[i].start = 0;
+                       ec->resource[i].flags = 0;
+               }
+       }
+  nomem:
+       return ec;
+ }
+ static ssize_t ecard_show_irq(struct device *dev, struct device_attribute *attr, char *buf)
+ {
+       struct expansion_card *ec = ECARD_DEV(dev);
+       return sprintf(buf, "%u\n", ec->irq);
+ }
+ static ssize_t ecard_show_dma(struct device *dev, struct device_attribute *attr, char *buf)
+ {
+       struct expansion_card *ec = ECARD_DEV(dev);
+       return sprintf(buf, "%u\n", ec->dma);
+ }
+ static ssize_t ecard_show_resources(struct device *dev, struct device_attribute *attr, char *buf)
+ {
+       struct expansion_card *ec = ECARD_DEV(dev);
+       char *str = buf;
+       int i;
+       for (i = 0; i < ECARD_NUM_RESOURCES; i++)
+               str += sprintf(str, "%08x %08x %08lx\n",
+                               ec->resource[i].start,
+                               ec->resource[i].end,
+                               ec->resource[i].flags);
+       return str - buf;
+ }
+ static ssize_t ecard_show_vendor(struct device *dev, struct device_attribute *attr, char *buf)
+ {
+       struct expansion_card *ec = ECARD_DEV(dev);
+       return sprintf(buf, "%u\n", ec->cid.manufacturer);
+ }
+ static ssize_t ecard_show_device(struct device *dev, struct device_attribute *attr, char *buf)
+ {
+       struct expansion_card *ec = ECARD_DEV(dev);
+       return sprintf(buf, "%u\n", ec->cid.product);
+ }
+ static ssize_t ecard_show_type(struct device *dev, struct device_attribute *attr, char *buf)
+ {
+       struct expansion_card *ec = ECARD_DEV(dev);
+       return sprintf(buf, "%s\n", ec->easi ? "EASI" : "IOC");
+ }
+ static struct device_attribute ecard_dev_attrs[] = {
+       __ATTR(device,   S_IRUGO, ecard_show_device,    NULL),
+       __ATTR(dma,      S_IRUGO, ecard_show_dma,       NULL),
+       __ATTR(irq,      S_IRUGO, ecard_show_irq,       NULL),
+       __ATTR(resource, S_IRUGO, ecard_show_resources, NULL),
+       __ATTR(type,     S_IRUGO, ecard_show_type,      NULL),
+       __ATTR(vendor,   S_IRUGO, ecard_show_vendor,    NULL),
+       __ATTR_NULL,
+ };
+ int ecard_request_resources(struct expansion_card *ec)
+ {
+       int i, err = 0;
+       for (i = 0; i < ECARD_NUM_RESOURCES; i++) {
+               if (ecard_resource_end(ec, i) &&
+                   !request_mem_region(ecard_resource_start(ec, i),
+                                       ecard_resource_len(ec, i),
+                                       ec->dev.driver->name)) {
+                       err = -EBUSY;
+                       break;
+               }
+       }
+       if (err) {
+               while (i--)
+                       if (ecard_resource_end(ec, i))
+                               release_mem_region(ecard_resource_start(ec, i),
+                                                  ecard_resource_len(ec, i));
+       }
+       return err;
+ }
+ EXPORT_SYMBOL(ecard_request_resources);
+ void ecard_release_resources(struct expansion_card *ec)
+ {
+       int i;
+       for (i = 0; i < ECARD_NUM_RESOURCES; i++)
+               if (ecard_resource_end(ec, i))
+                       release_mem_region(ecard_resource_start(ec, i),
+                                          ecard_resource_len(ec, i));
+ }
+ EXPORT_SYMBOL(ecard_release_resources);
+ void ecard_setirq(struct expansion_card *ec, const struct expansion_card_ops *ops, void *irq_data)
+ {
+       ec->irq_data = irq_data;
+       barrier();
+       ec->ops = ops;
+ }
+ EXPORT_SYMBOL(ecard_setirq);
+ void __iomem *ecardm_iomap(struct expansion_card *ec, unsigned int res,
+                          unsigned long offset, unsigned long maxsize)
+ {
+       unsigned long start = ecard_resource_start(ec, res);
+       unsigned long end = ecard_resource_end(ec, res);
+       if (offset > (end - start))
+               return NULL;
+       start += offset;
+       if (maxsize && end - start > maxsize)
+               end = start + maxsize;
+       
+       return devm_ioremap(&ec->dev, start, end - start);
+ }
+ EXPORT_SYMBOL(ecardm_iomap);
+ /*
+  * Probe for an expansion card.
+  *
+  * If bit 1 of the first byte of the card is set, then the
+  * card does not exist.
+  */
+ static int __init ecard_probe(int slot, unsigned irq, card_type_t type)
+ {
+       ecard_t **ecp;
+       ecard_t *ec;
+       struct ex_ecid cid;
+       void __iomem *addr;
+       int i, rc;
+       ec = ecard_alloc_card(type, slot);
+       if (IS_ERR(ec)) {
+               rc = PTR_ERR(ec);
+               goto nomem;
+       }
+       rc = -ENODEV;
+       if ((addr = __ecard_address(ec, type, ECARD_SYNC)) == NULL)
+               goto nodev;
+       cid.r_zero = 1;
+       ecard_readbytes(&cid, ec, 0, 16, 0);
+       if (cid.r_zero)
+               goto nodev;
+       ec->cid.id      = cid.r_id;
+       ec->cid.cd      = cid.r_cd;
+       ec->cid.is      = cid.r_is;
+       ec->cid.w       = cid.r_w;
+       ec->cid.manufacturer = ecard_getu16(cid.r_manu);
+       ec->cid.product = ecard_getu16(cid.r_prod);
+       ec->cid.country = cid.r_country;
+       ec->cid.irqmask = cid.r_irqmask;
+       ec->cid.irqoff  = ecard_gets24(cid.r_irqoff);
+       ec->cid.fiqmask = cid.r_fiqmask;
+       ec->cid.fiqoff  = ecard_gets24(cid.r_fiqoff);
+       ec->fiqaddr     =
+       ec->irqaddr     = addr;
+       if (ec->cid.is) {
+               ec->irqmask = ec->cid.irqmask;
+               ec->irqaddr += ec->cid.irqoff;
+               ec->fiqmask = ec->cid.fiqmask;
+               ec->fiqaddr += ec->cid.fiqoff;
+       } else {
+               ec->irqmask = 1;
+               ec->fiqmask = 4;
+       }
+       for (i = 0; i < ARRAY_SIZE(blacklist); i++)
+               if (blacklist[i].manufacturer == ec->cid.manufacturer &&
+                   blacklist[i].product == ec->cid.product) {
+                       ec->card_desc = blacklist[i].type;
+                       break;
+               }
+       ec->irq = irq;
+       /*
+        * hook the interrupt handlers
+        */
+       if (slot < 8) {
+               irq_set_chip_and_handler(ec->irq, &ecard_chip,
+                                        handle_level_irq);
+               irq_set_chip_data(ec->irq, ec);
+               set_irq_flags(ec->irq, IRQF_VALID);
+       }
+ #ifdef CONFIG_ARCH_RPC
+       /* On RiscPC, only first two slots have DMA capability */
+       if (slot < 2)
+               ec->dma = 2 + slot;
+ #endif
+       for (ecp = &cards; *ecp; ecp = &(*ecp)->next);
+       *ecp = ec;
+       slot_to_expcard[slot] = ec;
+       device_register(&ec->dev);
+       return 0;
+  nodev:
+       ecard_free_card(ec);
+  nomem:
+       return rc;
+ }
+ /*
+  * Initialise the expansion card system.
+  * Locate all hardware - interrupt management and
+  * actual cards.
+  */
+ static int __init ecard_init(void)
+ {
+       struct task_struct *task;
+       int slot, irqbase;
+       irqbase = irq_alloc_descs(-1, 0, 8, -1);
+       if (irqbase < 0)
+               return irqbase;
+       task = kthread_run(ecard_task, NULL, "kecardd");
+       if (IS_ERR(task)) {
+               printk(KERN_ERR "Ecard: unable to create kernel thread: %ld\n",
+                      PTR_ERR(task));
+               irq_free_descs(irqbase, 8);
+               return PTR_ERR(task);
+       }
+       printk("Probing expansion cards\n");
+       for (slot = 0; slot < 8; slot ++) {
+               if (ecard_probe(slot, irqbase + slot, ECARD_EASI) == -ENODEV)
+                       ecard_probe(slot, irqbase + slot, ECARD_IOC);
+       }
+       ecard_probe(8, 11, ECARD_IOC);
+       irq_set_chained_handler(IRQ_EXPANSIONCARD, ecard_irq_handler);
+       ecard_proc_init();
+       return 0;
+ }
+ subsys_initcall(ecard_init);
+ /*
+  *    ECARD "bus"
+  */
+ static const struct ecard_id *
+ ecard_match_device(const struct ecard_id *ids, struct expansion_card *ec)
+ {
+       int i;
+       for (i = 0; ids[i].manufacturer != 65535; i++)
+               if (ec->cid.manufacturer == ids[i].manufacturer &&
+                   ec->cid.product == ids[i].product)
+                       return ids + i;
+       return NULL;
+ }
+ static int ecard_drv_probe(struct device *dev)
+ {
+       struct expansion_card *ec = ECARD_DEV(dev);
+       struct ecard_driver *drv = ECARD_DRV(dev->driver);
+       const struct ecard_id *id;
+       int ret;
+       id = ecard_match_device(drv->id_table, ec);
+       ec->claimed = 1;
+       ret = drv->probe(ec, id);
+       if (ret)
+               ec->claimed = 0;
+       return ret;
+ }
+ static int ecard_drv_remove(struct device *dev)
+ {
+       struct expansion_card *ec = ECARD_DEV(dev);
+       struct ecard_driver *drv = ECARD_DRV(dev->driver);
+       drv->remove(ec);
+       ec->claimed = 0;
+       /*
+        * Restore the default operations.  We ensure that the
+        * ops are set before we change the data.
+        */
+       ec->ops = &ecard_default_ops;
+       barrier();
+       ec->irq_data = NULL;
+       return 0;
+ }
+ /*
+  * Before rebooting, we must make sure that the expansion card is in a
+  * sensible state, so it can be re-detected.  This means that the first
+  * page of the ROM must be visible.  We call the expansion cards reset
+  * handler, if any.
+  */
+ static void ecard_drv_shutdown(struct device *dev)
+ {
+       struct expansion_card *ec = ECARD_DEV(dev);
+       struct ecard_driver *drv = ECARD_DRV(dev->driver);
+       struct ecard_request req;
+       if (dev->driver) {
+               if (drv->shutdown)
+                       drv->shutdown(ec);
+               ec->claimed = 0;
+       }
+       /*
+        * If this card has a loader, call the reset handler.
+        */
+       if (ec->loader) {
+               req.fn = ecard_task_reset;
+               req.ec = ec;
+               ecard_call(&req);
+       }
+ }
+ int ecard_register_driver(struct ecard_driver *drv)
+ {
+       drv->drv.bus = &ecard_bus_type;
+       return driver_register(&drv->drv);
+ }
+ void ecard_remove_driver(struct ecard_driver *drv)
+ {
+       driver_unregister(&drv->drv);
+ }
+ static int ecard_match(struct device *_dev, struct device_driver *_drv)
+ {
+       struct expansion_card *ec = ECARD_DEV(_dev);
+       struct ecard_driver *drv = ECARD_DRV(_drv);
+       int ret;
+       if (drv->id_table) {
+               ret = ecard_match_device(drv->id_table, ec) != NULL;
+       } else {
+               ret = ec->cid.id == drv->id;
+       }
+       return ret;
+ }
+ struct bus_type ecard_bus_type = {
+       .name           = "ecard",
+       .dev_attrs      = ecard_dev_attrs,
+       .match          = ecard_match,
+       .probe          = ecard_drv_probe,
+       .remove         = ecard_drv_remove,
+       .shutdown       = ecard_drv_shutdown,
+ };
+ static int ecard_bus_init(void)
+ {
+       return bus_register(&ecard_bus_type);
+ }
+ postcore_initcall(ecard_bus_init);
+ EXPORT_SYMBOL(ecard_readchunk);
+ EXPORT_SYMBOL(ecard_register_driver);
+ EXPORT_SYMBOL(ecard_remove_driver);
+ EXPORT_SYMBOL(ecard_bus_type);
index 7c1ebf4a7920f140259b3da2896cd6bf6bef8081,b18470420d3ed6a0e262557d7e7d73878c782d9b..1d0f71b17a2670a9ac30aed6bcfc163bf810afc1
  #include <linux/kernel.h>
  #include <linux/init.h>
  #include <linux/delay.h>
+ #include <linux/dma-mapping.h>
  #include <linux/pm.h>
  #include <linux/cpufreq.h>
  #include <linux/ioport.h>
  #include <linux/platform_device.h>
  
+ #include <video/sa1100fb.h>
  #include <asm/div64.h>
- #include <mach/hardware.h>
  #include <asm/system.h>
  #include <asm/mach/map.h>
  #include <asm/mach/flash.h>
  #include <asm/irq.h>
  
+ #include <mach/hardware.h>
+ #include <mach/irqs.h>
  #include "generic.h"
  
  unsigned int reset_status;
@@@ -149,16 -154,8 +154,8 @@@ static void sa11x0_register_device(stru
  
  
  static struct resource sa11x0udc_resources[] = {
-       [0] = {
-               .start  = __PREG(Ser0UDCCR),
-               .end    = __PREG(Ser0UDCCR) + 0xffff,
-               .flags  = IORESOURCE_MEM,
-       },
-       [1] = {
-               .start  = IRQ_Ser0UDC,
-               .end    = IRQ_Ser0UDC,
-               .flags  = IORESOURCE_IRQ,
-       },
+       [0] = DEFINE_RES_MEM(__PREG(Ser0UDCCR), SZ_64K),
+       [1] = DEFINE_RES_IRQ(IRQ_Ser0UDC),
  };
  
  static u64 sa11x0udc_dma_mask = 0xffffffffUL;
@@@ -175,16 -172,8 +172,8 @@@ static struct platform_device sa11x0udc
  };
  
  static struct resource sa11x0uart1_resources[] = {
-       [0] = {
-               .start  = __PREG(Ser1UTCR0),
-               .end    = __PREG(Ser1UTCR0) + 0xffff,
-               .flags  = IORESOURCE_MEM,
-       },
-       [1] = {
-               .start  = IRQ_Ser1UART,
-               .end    = IRQ_Ser1UART,
-               .flags  = IORESOURCE_IRQ,
-       },
+       [0] = DEFINE_RES_MEM(__PREG(Ser1UTCR0), SZ_64K),
+       [1] = DEFINE_RES_IRQ(IRQ_Ser1UART),
  };
  
  static struct platform_device sa11x0uart1_device = {
  };
  
  static struct resource sa11x0uart3_resources[] = {
-       [0] = {
-               .start  = __PREG(Ser3UTCR0),
-               .end    = __PREG(Ser3UTCR0) + 0xffff,
-               .flags  = IORESOURCE_MEM,
-       },
-       [1] = {
-               .start  = IRQ_Ser3UART,
-               .end    = IRQ_Ser3UART,
-               .flags  = IORESOURCE_IRQ,
-       },
+       [0] = DEFINE_RES_MEM(__PREG(Ser3UTCR0), SZ_64K),
+       [1] = DEFINE_RES_IRQ(IRQ_Ser3UART),
  };
  
  static struct platform_device sa11x0uart3_device = {
  };
  
  static struct resource sa11x0mcp_resources[] = {
-       [0] = {
-               .start  = __PREG(Ser4MCCR0),
-               .end    = __PREG(Ser4MCCR0) + 0xffff,
-               .flags  = IORESOURCE_MEM,
-       },
-       [1] = {
-               .start  = IRQ_Ser4MCP,
-               .end    = IRQ_Ser4MCP,
-               .flags  = IORESOURCE_IRQ,
-       },
+       [0] = DEFINE_RES_MEM(__PREG(Ser4MCCR0), SZ_64K),
+       [1] = DEFINE_RES_MEM(__PREG(Ser4MCCR1), 4),
+       [2] = DEFINE_RES_IRQ(IRQ_Ser4MCP),
  };
  
  static u64 sa11x0mcp_dma_mask = 0xffffffffUL;
@@@ -240,22 -214,24 +214,24 @@@ static struct platform_device sa11x0mcp
        .resource       = sa11x0mcp_resources,
  };
  
+ void __init sa11x0_ppc_configure_mcp(void)
+ {
+       /* Setup the PPC unit for the MCP */
+       PPDR &= ~PPC_RXD4;
+       PPDR |= PPC_TXD4 | PPC_SCLK | PPC_SFRM;
+       PSDR |= PPC_RXD4;
+       PSDR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM);
+       PPSR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM);
+ }
  void sa11x0_register_mcp(struct mcp_plat_data *data)
  {
        sa11x0_register_device(&sa11x0mcp_device, data);
  }
  
  static struct resource sa11x0ssp_resources[] = {
-       [0] = {
-               .start  = 0x80070000,
-               .end    = 0x8007ffff,
-               .flags  = IORESOURCE_MEM,
-       },
-       [1] = {
-               .start  = IRQ_Ser4SSP,
-               .end    = IRQ_Ser4SSP,
-               .flags  = IORESOURCE_IRQ,
-       },
+       [0] = DEFINE_RES_MEM(0x80070000, SZ_64K),
+       [1] = DEFINE_RES_IRQ(IRQ_Ser4SSP),
  };
  
  static u64 sa11x0ssp_dma_mask = 0xffffffffUL;
@@@ -272,16 -248,8 +248,8 @@@ static struct platform_device sa11x0ssp
  };
  
  static struct resource sa11x0fb_resources[] = {
-       [0] = {
-               .start  = 0xb0100000,
-               .end    = 0xb010ffff,
-               .flags  = IORESOURCE_MEM,
-       },
-       [1] = {
-               .start  = IRQ_LCD,
-               .end    = IRQ_LCD,
-               .flags  = IORESOURCE_IRQ,
-       },
+       [0] = DEFINE_RES_MEM(0xb0100000, SZ_64K),
+       [1] = DEFINE_RES_IRQ(IRQ_LCD),
  };
  
  static struct platform_device sa11x0fb_device = {
        .resource       = sa11x0fb_resources,
  };
  
+ void sa11x0_register_lcd(struct sa1100fb_mach_info *inf)
+ {
+       sa11x0_register_device(&sa11x0fb_device, inf);
+ }
  static struct platform_device sa11x0pcmcia_device = {
        .name           = "sa11x0-pcmcia",
        .id             = -1,
@@@ -314,23 -287,10 +287,10 @@@ void sa11x0_register_mtd(struct flash_p
  }
  
  static struct resource sa11x0ir_resources[] = {
-       {
-               .start  = __PREG(Ser2UTCR0),
-               .end    = __PREG(Ser2UTCR0) + 0x24 - 1,
-               .flags  = IORESOURCE_MEM,
-       }, {
-               .start  = __PREG(Ser2HSCR0),
-               .end    = __PREG(Ser2HSCR0) + 0x1c - 1,
-               .flags  = IORESOURCE_MEM,
-       }, {
-               .start  = __PREG(Ser2HSCR2),
-               .end    = __PREG(Ser2HSCR2) + 0x04 - 1,
-               .flags  = IORESOURCE_MEM,
-       }, {
-               .start  = IRQ_Ser2ICP,
-               .end    = IRQ_Ser2ICP,
-               .flags  = IORESOURCE_IRQ,
-       }
+       DEFINE_RES_MEM(__PREG(Ser2UTCR0), 0x24),
+       DEFINE_RES_MEM(__PREG(Ser2HSCR0), 0x1c),
+       DEFINE_RES_MEM(__PREG(Ser2HSCR2), 0x04),
+       DEFINE_RES_IRQ(IRQ_Ser2ICP),
  };
  
  static struct platform_device sa11x0ir_device = {
@@@ -345,27 -305,42 +305,50 @@@ void sa11x0_register_irda(struct irda_p
        sa11x0_register_device(&sa11x0ir_device, irda);
  }
  
 +static struct resource sa1100_rtc_resources[] = {
 +      DEFINE_RES_MEM(0x90010000, 0x9001003f),
 +      DEFINE_RES_IRQ_NAMED(IRQ_RTC1Hz, "rtc 1Hz"),
 +      DEFINE_RES_IRQ_NAMED(IRQ_RTCAlrm, "rtc alarm"),
 +};
 +
  static struct platform_device sa11x0rtc_device = {
        .name           = "sa1100-rtc",
        .id             = -1,
 +      .num_resources  = ARRAY_SIZE(sa1100_rtc_resources),
 +      .resource       = sa1100_rtc_resources,
  };
  
+ static struct resource sa11x0dma_resources[] = {
+       DEFINE_RES_MEM(DMA_PHYS, DMA_SIZE),
+       DEFINE_RES_IRQ(IRQ_DMA0),
+       DEFINE_RES_IRQ(IRQ_DMA1),
+       DEFINE_RES_IRQ(IRQ_DMA2),
+       DEFINE_RES_IRQ(IRQ_DMA3),
+       DEFINE_RES_IRQ(IRQ_DMA4),
+       DEFINE_RES_IRQ(IRQ_DMA5),
+ };
+ static u64 sa11x0dma_dma_mask = DMA_BIT_MASK(32);
+ static struct platform_device sa11x0dma_device = {
+       .name           = "sa11x0-dma",
+       .id             = -1,
+       .dev = {
+               .dma_mask = &sa11x0dma_dma_mask,
+               .coherent_dma_mask = 0xffffffff,
+       },
+       .num_resources  = ARRAY_SIZE(sa11x0dma_resources),
+       .resource       = sa11x0dma_resources,
+ };
  static struct platform_device *sa11x0_devices[] __initdata = {
        &sa11x0udc_device,
        &sa11x0uart1_device,
        &sa11x0uart3_device,
        &sa11x0ssp_device,
        &sa11x0pcmcia_device,
-       &sa11x0fb_device,
        &sa11x0rtc_device,
+       &sa11x0dma_device,
  };
  
  static int __init sa1100_init(void)
  
  arch_initcall(sa1100_init);
  
- void (*sa1100fb_backlight_power)(int on);
- void (*sa1100fb_lcd_power)(int on);
- EXPORT_SYMBOL(sa1100fb_backlight_power);
- EXPORT_SYMBOL(sa1100fb_lcd_power);
  
  /*
   * Common I/O mapping:
@@@ -436,7 -405,7 +413,7 @@@ void __init sa1100_map_io(void
   * the MBGNT signal false to ensure the SA1111 doesn't own the
   * SDRAM bus.
   */
- void __init sa1110_mb_disable(void)
+ void sa1110_mb_disable(void)
  {
        unsigned long flags;
  
   * If the system is going to use the SA-1111 DMA engines, set up
   * the memory bus request/grant pins.
   */
- void __devinit sa1110_mb_enable(void)
+ void sa1110_mb_enable(void)
  {
        unsigned long flags;
  
index 019f857a79384a49222bc115c7d651108967d889,a0d1114c45edd8b9a3ab886c2aa2bbeadc1a3282..fff39e02b4965667d73ef6bde31a9dfb0ff7412a
  #define SHANNON_GPIO_U3_RTS           GPIO_GPIO (19)  /* ?? */
  #define SHANNON_GPIO_U3_CTS           GPIO_GPIO (20)  /* ?? */
  #define SHANNON_GPIO_SENSE_12V                GPIO_GPIO (21)  /* Input, 12v flash unprotect detected */
- #define SHANNON_GPIO_DISP_EN          GPIO_GPIO (22)  /* out */
+ #define SHANNON_GPIO_DISP_EN          22              /* out */
  /* XXX GPIO 23 unaccounted for */
 -#define SHANNON_GPIO_EJECT_0          GPIO_GPIO (24)  /* in */
 -#define SHANNON_IRQ_GPIO_EJECT_0      IRQ_GPIO24
 -#define SHANNON_GPIO_EJECT_1          GPIO_GPIO (25)  /* in */
 -#define SHANNON_IRQ_GPIO_EJECT_1      IRQ_GPIO25
 -#define SHANNON_GPIO_RDY_0            GPIO_GPIO (26)  /* in */
 -#define SHANNON_IRQ_GPIO_RDY_0                IRQ_GPIO26
 -#define SHANNON_GPIO_RDY_1            GPIO_GPIO (27)  /* in */
 -#define SHANNON_IRQ_GPIO_RDY_1                IRQ_GPIO27
 +#define SHANNON_GPIO_EJECT_0          24              /* in */
 +#define SHANNON_GPIO_EJECT_1          25              /* in */
 +#define SHANNON_GPIO_RDY_0            26              /* in */
 +#define SHANNON_GPIO_RDY_1            27              /* in */
  
  /* MCP UCB codec GPIO pins... */
  
index b466bca9c651a1dfed4d5ddb20850bba6bf5ae8b,41bb018b31032430a5f9585d0a27fa78491d6b38..b49108b890a822d99f97e45d17fc889fa1c58f35
@@@ -135,12 -135,8 +135,8 @@@ struct pci_bus * __init pci_nanoengine_
                                 &sys->resources);
  }
  
- static struct resource pci_io_ports = {
-       .name   = "PCI IO",
-       .start  = 0x400,
-       .end    = 0x7FF,
-       .flags  = IORESOURCE_IO,
- };
+ static struct resource pci_io_ports =
+       DEFINE_RES_IO_NAMED(0x400, 0x400, "PCI IO");
  
  static struct resource pci_non_prefetchable_memory = {
        .name   = "PCI non-prefetchable",
@@@ -244,11 -240,9 +240,11 @@@ static int __init pci_nanoengine_setup_
                printk(KERN_ERR "PCI: unable to allocate prefetchable\n");
                return -EBUSY;
        }
 -      pci_add_resource(&sys->resources, &pci_io_ports);
 -      pci_add_resource(&sys->resources, &pci_non_prefetchable_memory);
 -      pci_add_resource(&sys->resources, &pci_prefetchable_memory);
 +      pci_add_resource_offset(&sys->resources, &pci_io_ports, sys->io_offset);
 +      pci_add_resource_offset(&sys->resources,
 +                              &pci_non_prefetchable_memory, sys->mem_offset);
 +      pci_add_resource_offset(&sys->resources,
 +                              &pci_prefetchable_memory, sys->mem_offset);
  
        return 1;
  }
diff --combined drivers/mfd/Kconfig
index 1489c3540f96bab496aa6b0681c0ada3637d09c3,28a301b28579d12af842c4694d37c7d50ebd7733..243e0c663c37be28fc2282dc98be2e9715f7804a
@@@ -200,8 -200,7 +200,8 @@@ config MENELAU
  
  config TWL4030_CORE
        bool "Texas Instruments TWL4030/TWL5030/TWL6030/TPS659x0 Support"
 -      depends on I2C=y && GENERIC_HARDIRQS && IRQ_DOMAIN
 +      depends on I2C=y && GENERIC_HARDIRQS
 +      select IRQ_DOMAIN
        help
          Say yes here if you have TWL4030 / TWL6030 family chip on your board.
          This core driver provides register access and IRQ handling
@@@ -848,8 -847,9 +848,9 @@@ config MCP_SA11X
  
  # Chip drivers
  config MCP_UCB1200
-       tristate "Support for UCB1200 / UCB1300"
-       depends on MCP
+       bool "Support for UCB1200 / UCB1300"
+       depends on MCP_SA11X0
+       select MCP
  
  config MCP_UCB1200_TS
        tristate "Touchscreen interface support"
index 1dc4fad593e7ebd50a35f50a477e8bcd0a4f8481,0dba0501b7120b15d34d6a2bd381dfcb9e26300a..fee44935501461663a1417c5a10b209f33da393e
@@@ -463,7 -463,7 +463,7 @@@ static inline void  smc_rcv(struct net_
                 * multiple of 4 bytes on 32 bit buses.
                 * Hence packet_len - 6 + 2 + 2 + 2.
                 */
 -              skb = dev_alloc_skb(packet_len);
 +              skb = netdev_alloc_skb(dev, packet_len);
                if (unlikely(skb == NULL)) {
                        printk(KERN_NOTICE "%s: Low memory, packet dropped.\n",
                                dev->name);
@@@ -2223,6 -2223,7 +2223,6 @@@ static int __devinit smc_drv_probe(stru
  
        ndev = alloc_etherdev(sizeof(struct smc_local));
        if (!ndev) {
 -              printk("%s: could not allocate device.\n", CARDNAME);
                ret = -ENOMEM;
                goto out;
        }
        if (ret)
                goto out_release_io;
  #if defined(CONFIG_SA1100_ASSABET)
-       NCR_0 |= NCR_ENET_OSC_EN;
+       neponset_ncr_set(NCR_ENET_OSC_EN);
  #endif
        platform_set_drvdata(pdev, ndev);
        ret = smc_enable_device(pdev);
index ef5848f65241fbb27cea4223b775b2a529ea1630,33568e18998b3f8dda5902f42ae67a8f9ee268ac..70f728ce1856b0723e1ff9a51dd8ffb3847a8b19
  
  #include "sa1111_generic.h"
  
+ /*
+  * These are offsets from the above base.
+  */
+ #define PCCR  0x0000
+ #define PCSSR 0x0004
+ #define PCSR  0x0008
+ #define PCSR_S0_READY (1<<0)
+ #define PCSR_S1_READY (1<<1)
+ #define PCSR_S0_DETECT        (1<<2)
+ #define PCSR_S1_DETECT        (1<<3)
+ #define PCSR_S0_VS1   (1<<4)
+ #define PCSR_S0_VS2   (1<<5)
+ #define PCSR_S1_VS1   (1<<6)
+ #define PCSR_S1_VS2   (1<<7)
+ #define PCSR_S0_WP    (1<<8)
+ #define PCSR_S1_WP    (1<<9)
+ #define PCSR_S0_BVD1  (1<<10)
+ #define PCSR_S0_BVD2  (1<<11)
+ #define PCSR_S1_BVD1  (1<<12)
+ #define PCSR_S1_BVD2  (1<<13)
+ #define PCCR_S0_RST   (1<<0)
+ #define PCCR_S1_RST   (1<<1)
+ #define PCCR_S0_FLT   (1<<2)
+ #define PCCR_S1_FLT   (1<<3)
+ #define PCCR_S0_PWAITEN       (1<<4)
+ #define PCCR_S1_PWAITEN       (1<<5)
+ #define PCCR_S0_PSE   (1<<6)
+ #define PCCR_S1_PSE   (1<<7)
+ #define PCSSR_S0_SLEEP        (1<<0)
+ #define PCSSR_S1_SLEEP        (1<<1)
  #define IDX_IRQ_S0_READY_NINT (0)
  #define IDX_IRQ_S0_CD_VALID   (1)
  #define IDX_IRQ_S0_BVD1_STSCHG        (2)
  #define IDX_IRQ_S1_CD_VALID   (4)
  #define IDX_IRQ_S1_BVD1_STSCHG        (5)
  
 -static struct pcmcia_irqs irqs[] = {
 -      { 0, NO_IRQ, "SA1111 PCMCIA card detect" },
 -      { 0, NO_IRQ, "SA1111 PCMCIA BVD1"        },
 -      { 1, NO_IRQ, "SA1111 CF card detect"     },
 -      { 1, NO_IRQ, "SA1111 CF BVD1"            },
 -};
 -
 -static int sa1111_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
 -{
 -      return soc_pcmcia_request_irqs(skt, irqs, ARRAY_SIZE(irqs));
 -}
 -
 -static void sa1111_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
 -{
 -      soc_pcmcia_free_irqs(skt, irqs, ARRAY_SIZE(irqs));
 -}
 -
  void sa1111_pcmcia_socket_state(struct soc_pcmcia_socket *skt, struct pcmcia_state *state)
  {
        struct sa1111_pcmcia_socket *s = to_skt(skt);
-       unsigned long status = sa1111_readl(s->dev->mapbase + SA1111_PCSR);
+       unsigned long status = sa1111_readl(s->dev->mapbase + PCSR);
  
        switch (skt->nr) {
        case 0:
@@@ -88,22 -139,35 +122,22 @@@ int sa1111_pcmcia_configure_socket(stru
                pccr_set_mask |= PCCR_S0_FLT|PCCR_S1_FLT;
  
        local_irq_save(flags);
-       val = sa1111_readl(s->dev->mapbase + SA1111_PCCR);
+       val = sa1111_readl(s->dev->mapbase + PCCR);
        val &= ~pccr_skt_mask;
        val |= pccr_set_mask & pccr_skt_mask;
-       sa1111_writel(val, s->dev->mapbase + SA1111_PCCR);
+       sa1111_writel(val, s->dev->mapbase + PCCR);
        local_irq_restore(flags);
  
        return 0;
  }
  
 -void sa1111_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
 -{
 -      soc_pcmcia_enable_irqs(skt, irqs, ARRAY_SIZE(irqs));
 -}
 -
 -static void sa1111_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
 -{
 -      soc_pcmcia_disable_irqs(skt, irqs, ARRAY_SIZE(irqs));
 -}
 -
  int sa1111_pcmcia_add(struct sa1111_dev *dev, struct pcmcia_low_level *ops,
        int (*add)(struct soc_pcmcia_socket *))
  {
        struct sa1111_pcmcia_socket *s;
        int i, ret = 0;
  
 -      ops->hw_init = sa1111_pcmcia_hw_init;
 -      ops->hw_shutdown = sa1111_pcmcia_hw_shutdown;
        ops->socket_state = sa1111_pcmcia_socket_state;
 -      ops->socket_suspend = sa1111_pcmcia_socket_suspend;
  
        for (i = 0; i < ops->nr; i++) {
                s = kzalloc(sizeof(*s), GFP_KERNEL);
                        return -ENOMEM;
  
                s->soc.nr = ops->first + i;
 -              s->soc.ops = ops;
 -              s->soc.socket.owner = ops->owner;
 -              s->soc.socket.dev.parent = &dev->dev;
 -              s->soc.socket.pci_irq = s->soc.nr ?
 -                              dev->irq[IDX_IRQ_S0_READY_NINT] :
 -                              dev->irq[IDX_IRQ_S1_READY_NINT];
 +              soc_pcmcia_init_one(&s->soc, ops, &dev->dev);
                s->dev = dev;
 +              if (s->soc.nr) {
 +                      s->soc.socket.pci_irq = dev->irq[IDX_IRQ_S1_READY_NINT];
 +                      s->soc.stat[SOC_STAT_CD].irq = dev->irq[IDX_IRQ_S1_CD_VALID];
 +                      s->soc.stat[SOC_STAT_CD].name = "SA1111 CF card detect";
 +                      s->soc.stat[SOC_STAT_BVD1].irq = dev->irq[IDX_IRQ_S1_BVD1_STSCHG];
 +                      s->soc.stat[SOC_STAT_BVD1].name = "SA1111 CF BVD1";
 +              } else {
 +                      s->soc.socket.pci_irq = dev->irq[IDX_IRQ_S0_READY_NINT];
 +                      s->soc.stat[SOC_STAT_CD].irq = dev->irq[IDX_IRQ_S0_CD_VALID];
 +                      s->soc.stat[SOC_STAT_CD].name = "SA1111 PCMCIA card detect";
 +                      s->soc.stat[SOC_STAT_BVD1].irq = dev->irq[IDX_IRQ_S0_BVD1_STSCHG];
 +                      s->soc.stat[SOC_STAT_BVD1].name = "SA1111 PCMCIA BVD1";
 +              }
  
                ret = add(&s->soc);
                if (ret == 0) {
  static int pcmcia_probe(struct sa1111_dev *dev)
  {
        void __iomem *base;
+       int ret;
+       ret = sa1111_enable_device(dev);
+       if (ret)
+               return ret;
  
        dev_set_drvdata(&dev->dev, NULL);
  
-       if (!request_mem_region(dev->res.start, 512,
-                               SA1111_DRIVER_NAME(dev)))
+       if (!request_mem_region(dev->res.start, 512, SA1111_DRIVER_NAME(dev))) {
+               sa1111_disable_device(dev);
                return -EBUSY;
+       }
  
        base = dev->mapbase;
  
 -      /* Initialize PCMCIA IRQs */
 -      irqs[0].irq = dev->irq[IDX_IRQ_S0_CD_VALID];
 -      irqs[1].irq = dev->irq[IDX_IRQ_S0_BVD1_STSCHG];
 -      irqs[2].irq = dev->irq[IDX_IRQ_S1_CD_VALID];
 -      irqs[3].irq = dev->irq[IDX_IRQ_S1_BVD1_STSCHG];
 -
        /*
         * Initialise the suspend state.
         */
-       sa1111_writel(PCSSR_S0_SLEEP | PCSSR_S1_SLEEP, base + SA1111_PCSSR);
-       sa1111_writel(PCCR_S0_FLT | PCCR_S1_FLT, base + SA1111_PCCR);
+       sa1111_writel(PCSSR_S0_SLEEP | PCSSR_S1_SLEEP, base + PCSSR);
+       sa1111_writel(PCCR_S0_FLT | PCCR_S1_FLT, base + PCCR);
  
  #ifdef CONFIG_SA1100_BADGE4
        pcmcia_badge4_init(&dev->dev);
@@@ -184,6 -252,7 +224,7 @@@ static int __devexit pcmcia_remove(stru
        }
  
        release_mem_region(dev->res.start, 512);
+       sa1111_disable_device(dev);
        return 0;
  }
  
index 50f297d850e752a57c825d0fd9dbdb238a301bd3,0000000000000000000000000000000000000000..1d78739c4c07699b44f1479165660c229eaa462b
mode 100644,000000..100644
--- /dev/null
@@@ -1,134 -1,0 +1,129 @@@
-               unsigned long flags;
-               local_irq_save(flags);
-               NCR_0 = (NCR_0 & ~ncr_mask) | ncr_set;
-               local_irq_restore(flags);
 +/*
 + * linux/drivers/pcmcia/sa1100_neponset.c
 + *
 + * Neponset PCMCIA specific routines
 + */
 +#include <linux/module.h>
 +#include <linux/kernel.h>
 +#include <linux/device.h>
 +#include <linux/errno.h>
 +#include <linux/init.h>
 +
 +#include <mach/hardware.h>
 +#include <asm/mach-types.h>
 +#include <mach/neponset.h>
 +#include <asm/hardware/sa1111.h>
 +
 +#include "sa1111_generic.h"
 +
 +/*
 + * Neponset uses the Maxim MAX1600, with the following connections:
 + *
 + *   MAX1600      Neponset
 + *
 + *    A0VCC        SA-1111 GPIO A<1>
 + *    A1VCC        SA-1111 GPIO A<0>
 + *    A0VPP        CPLD NCR A0VPP
 + *    A1VPP        CPLD NCR A1VPP
 + *    B0VCC        SA-1111 GPIO A<2>
 + *    B1VCC        SA-1111 GPIO A<3>
 + *    B0VPP        ground (slot B is CF)
 + *    B1VPP        ground (slot B is CF)
 + *
 + *     VX          VCC (5V)
 + *     VY          VCC3_3 (3.3V)
 + *     12INA       12V
 + *     12INB       ground (slot B is CF)
 + *
 + * The MAX1600 CODE pin is tied to ground, placing the device in 
 + * "Standard Intel code" mode. Refer to the Maxim data sheet for
 + * the corresponding truth table.
 + */
 +
 +static int
 +neponset_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, const socket_state_t *state)
 +{
 +      struct sa1111_pcmcia_socket *s = to_skt(skt);
 +      unsigned int ncr_mask, ncr_set, pa_dwr_mask, pa_dwr_set;
 +      int ret;
 +
 +      switch (skt->nr) {
 +      case 0:
 +              pa_dwr_mask = GPIO_A0 | GPIO_A1;
 +              ncr_mask = NCR_A0VPP | NCR_A1VPP;
 +
 +              if (state->Vpp == 0)
 +                      ncr_set = 0;
 +              else if (state->Vpp == 120)
 +                      ncr_set = NCR_A1VPP;
 +              else if (state->Vpp == state->Vcc)
 +                      ncr_set = NCR_A0VPP;
 +              else {
 +                      printk(KERN_ERR "%s(): unrecognized VPP %u\n",
 +                             __func__, state->Vpp);
 +                      return -1;
 +              }
 +              break;
 +
 +      case 1:
 +              pa_dwr_mask = GPIO_A2 | GPIO_A3;
 +              ncr_mask = 0;
 +              ncr_set = 0;
 +
 +              if (state->Vpp != state->Vcc && state->Vpp != 0) {
 +                      printk(KERN_ERR "%s(): CF slot cannot support VPP %u\n",
 +                             __func__, state->Vpp);
 +                      return -1;
 +              }
 +              break;
 +
 +      default:
 +              return -1;
 +      }
 +
 +      /*
 +       * pa_dwr_set is the mask for selecting Vcc on both sockets.
 +       * pa_dwr_mask selects which bits (and therefore socket) we change.
 +       */
 +      switch (state->Vcc) {
 +      default:
 +      case 0:  pa_dwr_set = 0;                break;
 +      case 33: pa_dwr_set = GPIO_A1|GPIO_A2;  break;
 +      case 50: pa_dwr_set = GPIO_A0|GPIO_A3;  break;
 +      }
 +
 +      ret = sa1111_pcmcia_configure_socket(skt, state);
 +      if (ret == 0) {
++              neponset_ncr_frob(ncr_mask, ncr_set);
 +              sa1111_set_io(s->dev, pa_dwr_mask, pa_dwr_set);
 +      }
 +
 +      return ret;
 +}
 +
 +static struct pcmcia_low_level neponset_pcmcia_ops = {
 +      .owner                  = THIS_MODULE,
 +      .configure_socket       = neponset_pcmcia_configure_socket,
 +      .first                  = 0,
 +      .nr                     = 2,
 +};
 +
 +int pcmcia_neponset_init(struct sa1111_dev *sadev)
 +{
 +      int ret = -ENODEV;
 +
 +      if (machine_is_assabet()) {
 +              /*
 +               * Set GPIO_A<3:0> to be outputs for the MAX1600,
 +               * and switch to standby mode.
 +               */
 +              sa1111_set_io_dir(sadev, GPIO_A0|GPIO_A1|GPIO_A2|GPIO_A3, 0, 0);
 +              sa1111_set_io(sadev, GPIO_A0|GPIO_A1|GPIO_A2|GPIO_A3, 0);
 +              sa1111_set_sleep_io(sadev, GPIO_A0|GPIO_A1|GPIO_A2|GPIO_A3, 0);
 +              sa11xx_drv_pcmcia_ops(&neponset_pcmcia_ops);
 +              ret = sa1111_pcmcia_add(sadev, &neponset_pcmcia_ops,
 +                              sa11xx_drv_pcmcia_add_one);
 +      }
 +
 +      return ret;
 +}
diff --combined drivers/rtc/rtc-sa1100.c
index fa512ed420179738600c9eda0a0839565370c784,e8f1adde4d821cd6c36df785825c62fd36707a07..4940fa8c4e1002f913e7f3171d8cdc72bd5310fb
  
  #include <linux/platform_device.h>
  #include <linux/module.h>
 +#include <linux/clk.h>
  #include <linux/rtc.h>
  #include <linux/init.h>
  #include <linux/fs.h>
  #include <linux/interrupt.h>
 +#include <linux/slab.h>
  #include <linux/string.h>
 +#include <linux/of.h>
  #include <linux/pm.h>
  #include <linux/bitops.h>
  
  #include <mach/hardware.h>
- #include <asm/irq.h>
+ #include <mach/irqs.h>
  
 -#ifdef CONFIG_ARCH_PXA
 +#if defined(CONFIG_ARCH_PXA) || defined(CONFIG_ARCH_MMP)
  #include <mach/regs-rtc.h>
  #endif
  
  #define RTC_DEF_DIVIDER               (32768 - 1)
  #define RTC_DEF_TRIM          0
 -
 -static const unsigned long RTC_FREQ = 1024;
 -static struct rtc_time rtc_alarm;
 -static DEFINE_SPINLOCK(sa1100_rtc_lock);
 -
 -static inline int rtc_periodic_alarm(struct rtc_time *tm)
 -{
 -      return  (tm->tm_year == -1) ||
 -              ((unsigned)tm->tm_mon >= 12) ||
 -              ((unsigned)(tm->tm_mday - 1) >= 31) ||
 -              ((unsigned)tm->tm_hour > 23) ||
 -              ((unsigned)tm->tm_min > 59) ||
 -              ((unsigned)tm->tm_sec > 59);
 -}
 -
 -/*
 - * Calculate the next alarm time given the requested alarm time mask
 - * and the current time.
 - */
 -static void rtc_next_alarm_time(struct rtc_time *next, struct rtc_time *now,
 -      struct rtc_time *alrm)
 -{
 -      unsigned long next_time;
 -      unsigned long now_time;
 -
 -      next->tm_year = now->tm_year;
 -      next->tm_mon = now->tm_mon;
 -      next->tm_mday = now->tm_mday;
 -      next->tm_hour = alrm->tm_hour;
 -      next->tm_min = alrm->tm_min;
 -      next->tm_sec = alrm->tm_sec;
 -
 -      rtc_tm_to_time(now, &now_time);
 -      rtc_tm_to_time(next, &next_time);
 -
 -      if (next_time < now_time) {
 -              /* Advance one day */
 -              next_time += 60 * 60 * 24;
 -              rtc_time_to_tm(next_time, next);
 -      }
 -}
 -
 -static int rtc_update_alarm(struct rtc_time *alrm)
 -{
 -      struct rtc_time alarm_tm, now_tm;
 -      unsigned long now, time;
 -      int ret;
 -
 -      do {
 -              now = RCNR;
 -              rtc_time_to_tm(now, &now_tm);
 -              rtc_next_alarm_time(&alarm_tm, &now_tm, alrm);
 -              ret = rtc_tm_to_time(&alarm_tm, &time);
 -              if (ret != 0)
 -                      break;
 -
 -              RTSR = RTSR & (RTSR_HZE|RTSR_ALE|RTSR_AL);
 -              RTAR = time;
 -      } while (now != RCNR);
 -
 -      return ret;
 -}
 +#define RTC_FREQ              1024
 +
 +struct sa1100_rtc {
 +      spinlock_t              lock;
 +      int                     irq_1hz;
 +      int                     irq_alarm;
 +      struct rtc_device       *rtc;
 +      struct clk              *clk;
 +};
  
  static irqreturn_t sa1100_rtc_interrupt(int irq, void *dev_id)
  {
 -      struct platform_device *pdev = to_platform_device(dev_id);
 -      struct rtc_device *rtc = platform_get_drvdata(pdev);
 +      struct sa1100_rtc *info = dev_get_drvdata(dev_id);
 +      struct rtc_device *rtc = info->rtc;
        unsigned int rtsr;
        unsigned long events = 0;
  
 -      spin_lock(&sa1100_rtc_lock);
 +      spin_lock(&info->lock);
  
        rtsr = RTSR;
        /* clear interrupt sources */
  
        rtc_update_irq(rtc, 1, events);
  
 -      if (rtsr & RTSR_AL && rtc_periodic_alarm(&rtc_alarm))
 -              rtc_update_alarm(&rtc_alarm);
 -
 -      spin_unlock(&sa1100_rtc_lock);
 +      spin_unlock(&info->lock);
  
        return IRQ_HANDLED;
  }
  
  static int sa1100_rtc_open(struct device *dev)
  {
 +      struct sa1100_rtc *info = dev_get_drvdata(dev);
 +      struct rtc_device *rtc = info->rtc;
        int ret;
 -      struct platform_device *plat_dev = to_platform_device(dev);
 -      struct rtc_device *rtc = platform_get_drvdata(plat_dev);
  
 -      ret = request_irq(IRQ_RTC1Hz, sa1100_rtc_interrupt, IRQF_DISABLED,
 -              "rtc 1Hz", dev);
 +      ret = clk_prepare_enable(info->clk);
 +      if (ret)
 +              goto fail_clk;
 +      ret = request_irq(info->irq_1hz, sa1100_rtc_interrupt, 0, "rtc 1Hz", dev);
        if (ret) {
 -              dev_err(dev, "IRQ %d already in use.\n", IRQ_RTC1Hz);
 +              dev_err(dev, "IRQ %d already in use.\n", info->irq_1hz);
                goto fail_ui;
        }
 -      ret = request_irq(IRQ_RTCAlrm, sa1100_rtc_interrupt, IRQF_DISABLED,
 -              "rtc Alrm", dev);
 +      ret = request_irq(info->irq_alarm, sa1100_rtc_interrupt, 0, "rtc Alrm", dev);
        if (ret) {
 -              dev_err(dev, "IRQ %d already in use.\n", IRQ_RTCAlrm);
 +              dev_err(dev, "IRQ %d already in use.\n", info->irq_alarm);
                goto fail_ai;
        }
        rtc->max_user_freq = RTC_FREQ;
        return 0;
  
   fail_ai:
 -      free_irq(IRQ_RTC1Hz, dev);
 +      free_irq(info->irq_1hz, dev);
   fail_ui:
 +      clk_disable_unprepare(info->clk);
 + fail_clk:
        return ret;
  }
  
  static void sa1100_rtc_release(struct device *dev)
  {
 -      spin_lock_irq(&sa1100_rtc_lock);
 +      struct sa1100_rtc *info = dev_get_drvdata(dev);
 +
 +      spin_lock_irq(&info->lock);
        RTSR = 0;
 -      spin_unlock_irq(&sa1100_rtc_lock);
 +      spin_unlock_irq(&info->lock);
  
 -      free_irq(IRQ_RTCAlrm, dev);
 -      free_irq(IRQ_RTC1Hz, dev);
 +      free_irq(info->irq_alarm, dev);
 +      free_irq(info->irq_1hz, dev);
 +      clk_disable_unprepare(info->clk);
  }
  
  static int sa1100_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
  {
 -      spin_lock_irq(&sa1100_rtc_lock);
 +      struct sa1100_rtc *info = dev_get_drvdata(dev);
 +
 +      spin_lock_irq(&info->lock);
        if (enabled)
                RTSR |= RTSR_ALE;
        else
                RTSR &= ~RTSR_ALE;
 -      spin_unlock_irq(&sa1100_rtc_lock);
 +      spin_unlock_irq(&info->lock);
        return 0;
  }
  
@@@ -180,6 -225,7 +180,6 @@@ static int sa1100_rtc_read_alarm(struc
  {
        u32     rtsr;
  
 -      memcpy(&alrm->time, &rtc_alarm, sizeof(struct rtc_time));
        rtsr = RTSR;
        alrm->enabled = (rtsr & RTSR_ALE) ? 1 : 0;
        alrm->pending = (rtsr & RTSR_AL) ? 1 : 0;
  
  static int sa1100_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
  {
 +      struct sa1100_rtc *info = dev_get_drvdata(dev);
 +      unsigned long time;
        int ret;
  
 -      spin_lock_irq(&sa1100_rtc_lock);
 -      ret = rtc_update_alarm(&alrm->time);
 -      if (ret == 0) {
 -              if (alrm->enabled)
 -                      RTSR |= RTSR_ALE;
 -              else
 -                      RTSR &= ~RTSR_ALE;
 -      }
 -      spin_unlock_irq(&sa1100_rtc_lock);
 +      spin_lock_irq(&info->lock);
 +      ret = rtc_tm_to_time(&alrm->time, &time);
 +      if (ret != 0)
 +              goto out;
 +      RTSR = RTSR & (RTSR_HZE|RTSR_ALE|RTSR_AL);
 +      RTAR = time;
 +      if (alrm->enabled)
 +              RTSR |= RTSR_ALE;
 +      else
 +              RTSR &= ~RTSR_ALE;
 +out:
 +      spin_unlock_irq(&info->lock);
  
        return ret;
  }
@@@ -230,27 -271,6 +230,27 @@@ static const struct rtc_class_ops sa110
  static int sa1100_rtc_probe(struct platform_device *pdev)
  {
        struct rtc_device *rtc;
 +      struct sa1100_rtc *info;
 +      int irq_1hz, irq_alarm, ret = 0;
 +
 +      irq_1hz = platform_get_irq_byname(pdev, "rtc 1Hz");
 +      irq_alarm = platform_get_irq_byname(pdev, "rtc alarm");
 +      if (irq_1hz < 0 || irq_alarm < 0)
 +              return -ENODEV;
 +
 +      info = kzalloc(sizeof(struct sa1100_rtc), GFP_KERNEL);
 +      if (!info)
 +              return -ENOMEM;
 +      info->clk = clk_get(&pdev->dev, NULL);
 +      if (IS_ERR(info->clk)) {
 +              dev_err(&pdev->dev, "failed to find rtc clock source\n");
 +              ret = PTR_ERR(info->clk);
 +              goto err_clk;
 +      }
 +      info->irq_1hz = irq_1hz;
 +      info->irq_alarm = irq_alarm;
 +      spin_lock_init(&info->lock);
 +      platform_set_drvdata(pdev, info);
  
        /*
         * According to the manual we should be able to let RTTR be zero
        rtc = rtc_device_register(pdev->name, &pdev->dev, &sa1100_rtc_ops,
                THIS_MODULE);
  
 -      if (IS_ERR(rtc))
 -              return PTR_ERR(rtc);
 -
 -      platform_set_drvdata(pdev, rtc);
 +      if (IS_ERR(rtc)) {
 +              ret = PTR_ERR(rtc);
 +              goto err_dev;
 +      }
 +      info->rtc = rtc;
  
        /* Fix for a nasty initialization problem the in SA11xx RTSR register.
         * See also the comments in sa1100_rtc_interrupt().
        RTSR = RTSR_AL | RTSR_HZ;
  
        return 0;
 +err_dev:
 +      platform_set_drvdata(pdev, NULL);
 +      clk_put(info->clk);
 +err_clk:
 +      kfree(info);
 +      return ret;
  }
  
  static int sa1100_rtc_remove(struct platform_device *pdev)
  {
 -      struct rtc_device *rtc = platform_get_drvdata(pdev);
 +      struct sa1100_rtc *info = platform_get_drvdata(pdev);
  
 -      if (rtc)
 -              rtc_device_unregister(rtc);
 +      if (info) {
 +              rtc_device_unregister(info->rtc);
 +              clk_put(info->clk);
 +              platform_set_drvdata(pdev, NULL);
 +              kfree(info);
 +      }
  
        return 0;
  }
  #ifdef CONFIG_PM
  static int sa1100_rtc_suspend(struct device *dev)
  {
 +      struct sa1100_rtc *info = dev_get_drvdata(dev);
        if (device_may_wakeup(dev))
 -              enable_irq_wake(IRQ_RTCAlrm);
 +              enable_irq_wake(info->irq_alarm);
        return 0;
  }
  
  static int sa1100_rtc_resume(struct device *dev)
  {
 +      struct sa1100_rtc *info = dev_get_drvdata(dev);
        if (device_may_wakeup(dev))
 -              disable_irq_wake(IRQ_RTCAlrm);
 +              disable_irq_wake(info->irq_alarm);
        return 0;
  }
  
@@@ -348,13 -355,6 +348,13 @@@ static const struct dev_pm_ops sa1100_r
  };
  #endif
  
 +static struct of_device_id sa1100_rtc_dt_ids[] = {
 +      { .compatible = "mrvl,sa1100-rtc", },
 +      { .compatible = "mrvl,mmp-rtc", },
 +      {}
 +};
 +MODULE_DEVICE_TABLE(of, sa1100_rtc_dt_ids);
 +
  static struct platform_driver sa1100_rtc_driver = {
        .probe          = sa1100_rtc_probe,
        .remove         = sa1100_rtc_remove,
  #ifdef CONFIG_PM
                .pm     = &sa1100_rtc_pm_ops,
  #endif
 +              .of_match_table = sa1100_rtc_dt_ids,
        },
  };