staging: comedi: ni_pcidio: use comedi_load_firmware()
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Fri, 17 May 2013 18:18:01 +0000 (11:18 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 17 May 2013 19:09:50 +0000 (12:09 -0700)
Use comedi_load_firmware() instead of duplicating the code in a
private function.

This driver loads multiple firmware images to the device. Modify
comedi_load_firmware() to take a 'context' that is passed to the
firmware upload callback function.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/comedidev.h
drivers/staging/comedi/drivers.c
drivers/staging/comedi/drivers/daqboard2000.c
drivers/staging/comedi/drivers/jr3_pci.c
drivers/staging/comedi/drivers/me_daq.c
drivers/staging/comedi/drivers/ni_pcidio.c

index 7adc426..a31915f 100644 (file)
@@ -349,7 +349,9 @@ void comedi_spriv_free(struct comedi_device *, int subdev_num);
 int comedi_load_firmware(struct comedi_device *, struct device *,
                         const char *name,
                         int (*cb)(struct comedi_device *,
-                                  const u8 *data, size_t size));
+                                  const u8 *data, size_t size,
+                                  unsigned long context),
+                        unsigned long context);
 
 int __comedi_request_region(struct comedi_device *,
                            unsigned long start, unsigned long len);
index 12f1974..f3e57fd 100644 (file)
@@ -353,12 +353,15 @@ static void comedi_report_boards(struct comedi_driver *driv)
  * @hw_device: device struct for the comedi_device
  * @name: the name of the firmware image
  * @cb: callback to the upload the firmware image
+ * @context: private context from the driver
  */
 int comedi_load_firmware(struct comedi_device *dev,
                         struct device *device,
                         const char *name,
                         int (*cb)(struct comedi_device *dev,
-                                  const u8 *data, size_t size))
+                                  const u8 *data, size_t size,
+                                  unsigned long context),
+                        unsigned long context)
 {
        const struct firmware *fw;
        int ret;
@@ -368,7 +371,7 @@ int comedi_load_firmware(struct comedi_device *dev,
 
        ret = request_firmware(&fw, name, device);
        if (ret == 0) {
-               ret = cb(dev, fw->data, fw->size);
+               ret = cb(dev, fw->data, fw->size, context);
                release_firmware(fw);
        }
 
index ed3b3e6..f5aa386 100644 (file)
@@ -518,7 +518,8 @@ static int daqboard2000_writeCPLD(struct comedi_device *dev, int data)
 }
 
 static int initialize_daqboard2000(struct comedi_device *dev,
-                                  const u8 *cpld_array, size_t len)
+                                  const u8 *cpld_array, size_t len,
+                                  unsigned long context)
 {
        struct daqboard2000_private *devpriv = dev->private;
        int result = -EIO;
@@ -704,7 +705,7 @@ static int daqboard2000_auto_attach(struct comedi_device *dev,
 
        result = comedi_load_firmware(dev, &comedi_to_pci_dev(dev)->dev,
                                      DAQBOARD2000_FIRMWARE,
-                                     initialize_daqboard2000);
+                                     initialize_daqboard2000, 0);
        if (result < 0)
                return result;
 
index 6c5406c..94609f4 100644 (file)
@@ -325,8 +325,9 @@ static int read_idm_word(const u8 *data, size_t size, int *pos,
        return result;
 }
 
-static int jr3_download_firmware(struct comedi_device *dev, const u8 *data,
-                                size_t size)
+static int jr3_download_firmware(struct comedi_device *dev,
+                                const u8 *data, size_t size,
+                                unsigned long context)
 {
        /*
         * IDM file format is:
@@ -733,7 +734,7 @@ static int jr3_pci_auto_attach(struct comedi_device *dev,
 
        result = comedi_load_firmware(dev, &comedi_to_pci_dev(dev)->dev,
                                      "comedi/jr3pci.idm",
-                                     jr3_download_firmware);
+                                     jr3_download_firmware, 0);
        dev_dbg(dev->class_dev, "Firmare load %d\n", result);
 
        if (result < 0)
@@ -745,7 +746,7 @@ static int jr3_pci_auto_attach(struct comedi_device *dev,
         *
         *     comedi_load_firmware(dev, &comedi_to_pci_dev(dev)->dev,
         *                          "comedi/jr3_offsets_table",
-        *                          jr3_download_firmware);
+        *                          jr3_download_firmware, 1);
         */
 
        /*
index 313f702..7533ece 100644 (file)
@@ -386,7 +386,8 @@ static int me_ao_insn_read(struct comedi_device *dev,
 }
 
 static int me2600_xilinx_download(struct comedi_device *dev,
-                                 const u8 *data, size_t size)
+                                 const u8 *data, size_t size,
+                                 unsigned long context)
 {
        struct me_private_data *dev_private = dev->private;
        unsigned int value;
@@ -510,7 +511,7 @@ static int me_auto_attach(struct comedi_device *dev,
        if (board->needs_firmware) {
                ret = comedi_load_firmware(dev, &comedi_to_pci_dev(dev)->dev,
                                           ME2600_FIRMWARE,
-                                          me2600_xilinx_download);
+                                          me2600_xilinx_download, 0);
                if (ret < 0)
                        return ret;
        }
index 934b700..5b2f72e 100644 (file)
@@ -53,7 +53,6 @@ comedi_nonfree_firmware tarball available from http://www.comedi.org
 #include <linux/delay.h>
 #include <linux/interrupt.h>
 #include <linux/sched.h>
-#include <linux/firmware.h>
 
 #include "../comedidev.h"
 
@@ -966,11 +965,13 @@ static int ni_pcidio_change(struct comedi_device *dev,
        return 0;
 }
 
-static int pci_6534_load_fpga(struct comedi_device *dev, int fpga_index,
-                             const u8 *data, size_t data_len)
+static int pci_6534_load_fpga(struct comedi_device *dev,
+                             const u8 *data, size_t data_len,
+                             unsigned long context)
 {
        struct nidio96_private *devpriv = dev->private;
        static const int timeout = 1000;
+       int fpga_index = context;
        int i;
        size_t j;
 
@@ -1028,7 +1029,7 @@ static int pci_6534_load_fpga(struct comedi_device *dev, int fpga_index,
 
 static int pci_6534_reset_fpga(struct comedi_device *dev, int fpga_index)
 {
-       return pci_6534_load_fpga(dev, fpga_index, NULL, 0);
+       return pci_6534_load_fpga(dev, NULL, 0, fpga_index);
 }
 
 static int pci_6534_reset_fpgas(struct comedi_device *dev)
@@ -1062,13 +1063,12 @@ static void pci_6534_init_main_fpga(struct comedi_device *dev)
 static int pci_6534_upload_firmware(struct comedi_device *dev)
 {
        struct nidio96_private *devpriv = dev->private;
-       int ret;
-       const struct firmware *fw;
        static const char *const fw_file[3] = {
                FW_PCI_6534_SCARAB_DI,  /* loaded into scarab A for DI */
                FW_PCI_6534_SCARAB_DO,  /* loaded into scarab B for DO */
                FW_PCI_6534_MAIN,       /* loaded into main FPGA */
        };
+       int ret;
        int n;
 
        ret = pci_6534_reset_fpgas(dev);
@@ -1076,14 +1076,11 @@ static int pci_6534_upload_firmware(struct comedi_device *dev)
                return ret;
        /* load main FPGA first, then the two scarabs */
        for (n = 2; n >= 0; n--) {
-               ret = request_firmware(&fw, fw_file[n],
-                                      &devpriv->mite->pcidev->dev);
-               if (ret == 0) {
-                       ret = pci_6534_load_fpga(dev, n, fw->data, fw->size);
-                       if (ret == 0 && n == 2)
-                               pci_6534_init_main_fpga(dev);
-                       release_firmware(fw);
-               }
+               ret = comedi_load_firmware(dev, &devpriv->mite->pcidev->dev,
+                                          fw_file[n],
+                                          pci_6534_load_fpga, n);
+               if (ret == 0 && n == 2)
+                       pci_6534_init_main_fpga(dev);
                if (ret < 0)
                        break;
        }