]> nv-tegra.nvidia Code Review - linux-2.6.git/blobdiff - drivers/char/nwflash.c
compat: Handle COMPAT_USE_64BIT_TIME in the lp driver
[linux-2.6.git] / drivers / char / nwflash.c
index 206cf6f50695699be3fe865a5f024c1df9e640fe..bf586ae1ee83cabad66a2029e0c540b74bee0370 100644 (file)
 #include <linux/mm.h>
 #include <linux/delay.h>
 #include <linux/proc_fs.h>
-#include <linux/sched.h>
 #include <linux/miscdevice.h>
 #include <linux/spinlock.h>
 #include <linux/rwsem.h>
 #include <linux/init.h>
-#include <linux/smp_lock.h>
 #include <linux/mutex.h>
+#include <linux/jiffies.h>
 
 #include <asm/hardware/dec21285.h>
 #include <asm/io.h>
@@ -41,6 +40,7 @@
 
 #define        NWFLASH_VERSION "6.4"
 
+static DEFINE_MUTEX(flash_mutex);
 static void kick_open(void);
 static int get_flash_id(void);
 static int erase_block(int nBlock);
@@ -51,7 +51,7 @@ static int write_block(unsigned long p, const char __user *buf, int count);
 #define KFLASH_ID      0x89A6          //Intel flash
 #define KFLASH_ID4     0xB0D4          //Intel flash 4Meg
 
-static int flashdebug;         //if set - we will display progress msgs
+static bool flashdebug;                //if set - we will display progress msgs
 
 static int gbWriteEnable;
 static int gbWriteBase64Enable;
@@ -59,8 +59,6 @@ static volatile unsigned char *FLASH_BASE;
 static int gbFlashSize = KFLASH_SIZE;
 static DEFINE_MUTEX(nwflash_mutex);
 
-extern spinlock_t gpio_lock;
-
 static int get_flash_id(void)
 {
        volatile unsigned int c1, c2;
@@ -96,8 +94,9 @@ static int get_flash_id(void)
        return c2;
 }
 
-static int flash_ioctl(struct inode *inodep, struct file *filep, unsigned int cmd, unsigned long arg)
+static long flash_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
 {
+       mutex_lock(&flash_mutex);
        switch (cmd) {
        case CMD_WRITE_DISABLE:
                gbWriteBase64Enable = 0;
@@ -115,43 +114,30 @@ static int flash_ioctl(struct inode *inodep, struct file *filep, unsigned int cm
        default:
                gbWriteBase64Enable = 0;
                gbWriteEnable = 0;
+               mutex_unlock(&flash_mutex);
                return -EINVAL;
        }
+       mutex_unlock(&flash_mutex);
        return 0;
 }
 
 static ssize_t flash_read(struct file *file, char __user *buf, size_t size,
                          loff_t *ppos)
 {
-       unsigned long p = *ppos;
-       unsigned int count = size;
-       int ret = 0;
+       ssize_t ret;
 
        if (flashdebug)
-               printk(KERN_DEBUG "flash_read: flash_read: offset=0x%lX, "
-                      "buffer=%p, count=0x%X.\n", p, buf, count);
-
-       if (count)
-               ret = -ENXIO;
+               printk(KERN_DEBUG "flash_read: flash_read: offset=0x%llx, "
+                      "buffer=%p, count=0x%zx.\n", *ppos, buf, size);
+       /*
+        * We now lock against reads and writes. --rmk
+        */
+       if (mutex_lock_interruptible(&nwflash_mutex))
+               return -ERESTARTSYS;
 
-       if (p < gbFlashSize) {
-               if (count > gbFlashSize - p)
-                       count = gbFlashSize - p;
+       ret = simple_read_from_buffer(buf, size, ppos, (void *)FLASH_BASE, gbFlashSize);
+       mutex_unlock(&nwflash_mutex);
 
-               /*
-                * We now lock against reads and writes. --rmk
-                */
-               if (mutex_lock_interruptible(&nwflash_mutex))
-                       return -ERESTARTSYS;
-
-               ret = copy_to_user(buf, (void *)(FLASH_BASE + p), count);
-               if (ret == 0) {
-                       ret = count;
-                       *ppos += count;
-               } else
-                       ret = -EFAULT;
-               mutex_unlock(&nwflash_mutex);
-       }
        return ret;
 }
 
@@ -296,7 +282,7 @@ static loff_t flash_llseek(struct file *file, loff_t offset, int orig)
 {
        loff_t ret;
 
-       lock_kernel();
+       mutex_lock(&flash_mutex);
        if (flashdebug)
                printk(KERN_DEBUG "flash_llseek: offset=0x%X, orig=0x%X.\n",
                       (unsigned int) offset, orig);
@@ -331,7 +317,7 @@ static loff_t flash_llseek(struct file *file, loff_t offset, int orig)
        default:
                ret = -EINVAL;
        }
-       unlock_kernel();
+       mutex_unlock(&flash_mutex);
        return ret;
 }
 
@@ -632,9 +618,9 @@ static void kick_open(void)
         * we want to write a bit pattern XXX1 to Xilinx to enable
         * the write gate, which will be open for about the next 2ms.
         */
-       spin_lock_irqsave(&gpio_lock, flags);
-       cpld_modify(1, 1);
-       spin_unlock_irqrestore(&gpio_lock, flags);
+       spin_lock_irqsave(&nw_gpio_lock, flags);
+       nw_cpld_modify(CPLD_FLASH_WR_ENABLE, CPLD_FLASH_WR_ENABLE);
+       spin_unlock_irqrestore(&nw_gpio_lock, flags);
 
        /*
         * let the ISA bus to catch on...
@@ -648,7 +634,7 @@ static const struct file_operations flash_fops =
        .llseek         = flash_llseek,
        .read           = flash_read,
        .write          = flash_write,
-       .ioctl          = flash_ioctl,
+       .unlocked_ioctl = flash_ioctl,
 };
 
 static struct miscdevice flash_miscdev =