From: H Hartley Sweeten Date: Fri, 17 May 2013 18:18:01 +0000 (-0700) Subject: staging: comedi: ni_pcidio: use comedi_load_firmware() X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=d569541e537e13136fc775a902cda06f4c48bbe1;p=linux-beck.git staging: comedi: ni_pcidio: use comedi_load_firmware() 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 Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h index 7adc4268a705..a31915f1af65 100644 --- a/drivers/staging/comedi/comedidev.h +++ b/drivers/staging/comedi/comedidev.h @@ -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); diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c index 12f1974f2c81..f3e57fd8b2fb 100644 --- a/drivers/staging/comedi/drivers.c +++ b/drivers/staging/comedi/drivers.c @@ -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); } diff --git a/drivers/staging/comedi/drivers/daqboard2000.c b/drivers/staging/comedi/drivers/daqboard2000.c index ed3b3e665fa7..f5aa3860e3e7 100644 --- a/drivers/staging/comedi/drivers/daqboard2000.c +++ b/drivers/staging/comedi/drivers/daqboard2000.c @@ -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; diff --git a/drivers/staging/comedi/drivers/jr3_pci.c b/drivers/staging/comedi/drivers/jr3_pci.c index 6c5406c53e7d..94609f4aa4c9 100644 --- a/drivers/staging/comedi/drivers/jr3_pci.c +++ b/drivers/staging/comedi/drivers/jr3_pci.c @@ -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); */ /* diff --git a/drivers/staging/comedi/drivers/me_daq.c b/drivers/staging/comedi/drivers/me_daq.c index 313f702bb3f9..7533ece3670e 100644 --- a/drivers/staging/comedi/drivers/me_daq.c +++ b/drivers/staging/comedi/drivers/me_daq.c @@ -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; } diff --git a/drivers/staging/comedi/drivers/ni_pcidio.c b/drivers/staging/comedi/drivers/ni_pcidio.c index 934b700cb2bd..5b2f72e102e1 100644 --- a/drivers/staging/comedi/drivers/ni_pcidio.c +++ b/drivers/staging/comedi/drivers/ni_pcidio.c @@ -53,7 +53,6 @@ comedi_nonfree_firmware tarball available from http://www.comedi.org #include #include #include -#include #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; }