From: H Hartley Sweeten Date: Fri, 17 May 2013 18:17:00 +0000 (-0700) Subject: staging: comedi: drivers: generalize comedi_load_firmware() X-Git-Tag: firefly_0821_release~176^2~5845^2~586 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=9ff8b151881adb408d1337bd7654cc869e9f42e0;p=firefly-linux-kernel-4.4.55.git staging: comedi: drivers: generalize comedi_load_firmware() Move comedi_load_firmware() from jr3_pci.c to drivers.c and export it for general use by the comedi drivers. 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 ff7fc45b3124..7adc4268a705 100644 --- a/drivers/staging/comedi/comedidev.h +++ b/drivers/staging/comedi/comedidev.h @@ -346,6 +346,11 @@ int comedi_alloc_subdevices(struct comedi_device *, int); 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)); + int __comedi_request_region(struct comedi_device *, unsigned long start, unsigned long len); int comedi_request_region(struct comedi_device *, diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c index 216ba443ee61..12f1974f2c81 100644 --- a/drivers/staging/comedi/drivers.c +++ b/drivers/staging/comedi/drivers.c @@ -33,6 +33,7 @@ #include #include #include +#include #include "comedidev.h" #include "comedi_internal.h" @@ -346,6 +347,35 @@ static void comedi_report_boards(struct comedi_driver *driv) pr_info(" %s\n", driv->driver_name); } +/** + * comedi_load_firmware() - Request and load firmware for a device. + * @dev: comedi_device struct + * @hw_device: device struct for the comedi_device + * @name: the name of the firmware image + * @cb: callback to the upload the firmware image + */ +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 struct firmware *fw; + int ret; + + if (!cb) + return -EINVAL; + + ret = request_firmware(&fw, name, device); + if (ret == 0) { + ret = cb(dev, fw->data, fw->size); + release_firmware(fw); + } + + return ret; +} +EXPORT_SYMBOL_GPL(comedi_load_firmware); + /** * __comedi_request_region() - Request an I/O reqion for a legacy driver. * @dev: comedi_device struct diff --git a/drivers/staging/comedi/drivers/jr3_pci.c b/drivers/staging/comedi/drivers/jr3_pci.c index 9b61b557010f..6c5406c53e7d 100644 --- a/drivers/staging/comedi/drivers/jr3_pci.c +++ b/drivers/staging/comedi/drivers/jr3_pci.c @@ -41,7 +41,6 @@ #include #include #include -#include #include #include #include @@ -92,33 +91,6 @@ struct jr3_pci_subdev_private { int retries; }; -/* Hotplug firmware loading stuff */ -static int comedi_load_firmware(struct comedi_device *dev, const char *name, - int (*cb)(struct comedi_device *dev, - const u8 *data, size_t size)) -{ - struct pci_dev *pcidev = comedi_to_pci_dev(dev); - const struct firmware *fw; - char *firmware_path; - int ret; - - if (!cb) - return -EINVAL; - - firmware_path = kasprintf(GFP_KERNEL, "comedi/%s", name); - if (!firmware_path) - return -ENOMEM; - - ret = request_firmware(&fw, firmware_path, &pcidev->dev); - if (ret == 0) { - ret = cb(dev, fw->data, fw->size); - release_firmware(fw); - } - kfree(firmware_path); - - return ret; -} - static struct poll_delay_t poll_delay_min_max(int min, int max) { struct poll_delay_t result; @@ -759,7 +731,9 @@ static int jr3_pci_auto_attach(struct comedi_device *dev, /* Reset DSP card */ writel(0, &devpriv->iobase->channel[0].reset); - result = comedi_load_firmware(dev, "jr3pci.idm", jr3_download_firmware); + result = comedi_load_firmware(dev, &comedi_to_pci_dev(dev)->dev, + "comedi/jr3pci.idm", + jr3_download_firmware); dev_dbg(dev->class_dev, "Firmare load %d\n", result); if (result < 0) @@ -769,7 +743,8 @@ static int jr3_pci_auto_attach(struct comedi_device *dev, * format: * model serial Fx Fy Fz Mx My Mz\n * - * comedi_load_firmware(dev, "jr3_offsets_table", + * comedi_load_firmware(dev, &comedi_to_pci_dev(dev)->dev, + * "comedi/jr3_offsets_table", * jr3_download_firmware); */