NFC: Add firmware upload netlink command
As several NFC chipsets can have their firmwares upgraded and reflashed, this patchset adds a new netlink command to trigger that the driver loads or flashes a new firmware. This will allows userspace triggered firmware upgrade through netlink. The firmware name or hint is passed as a parameter, and the driver will eventually fetch the firmware binary through the request_firmware API. The cmd can only be executed when the nfc dev is not in use. Actual firmware loading/flashing is an asynchronous operation. Result of the operation shall send a new event up to user space through the nfc dev multicast socket. During operation, the nfc dev is not openable and thus not usable. Signed-off-by: Eric Lapuyade <eric.lapuyade@intel.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
committed by
Samuel Ortiz
parent
1095e69f47
commit
9674da8759
@@ -44,6 +44,47 @@ DEFINE_MUTEX(nfc_devlist_mutex);
|
||||
/* NFC device ID bitmap */
|
||||
static DEFINE_IDA(nfc_index_ida);
|
||||
|
||||
int nfc_fw_upload(struct nfc_dev *dev, const char *firmware_name)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
pr_debug("%s do firmware %s\n", dev_name(&dev->dev), firmware_name);
|
||||
|
||||
device_lock(&dev->dev);
|
||||
|
||||
if (!device_is_registered(&dev->dev)) {
|
||||
rc = -ENODEV;
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (dev->dev_up) {
|
||||
rc = -EBUSY;
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!dev->ops->fw_upload) {
|
||||
rc = -EOPNOTSUPP;
|
||||
goto error;
|
||||
}
|
||||
|
||||
dev->fw_upload_in_progress = true;
|
||||
rc = dev->ops->fw_upload(dev, firmware_name);
|
||||
if (rc)
|
||||
dev->fw_upload_in_progress = false;
|
||||
|
||||
error:
|
||||
device_unlock(&dev->dev);
|
||||
return rc;
|
||||
}
|
||||
|
||||
int nfc_fw_upload_done(struct nfc_dev *dev, const char *firmware_name)
|
||||
{
|
||||
dev->fw_upload_in_progress = false;
|
||||
|
||||
return nfc_genl_fw_upload_done(dev, firmware_name);
|
||||
}
|
||||
EXPORT_SYMBOL(nfc_fw_upload_done);
|
||||
|
||||
/**
|
||||
* nfc_dev_up - turn on the NFC device
|
||||
*
|
||||
@@ -69,6 +110,11 @@ int nfc_dev_up(struct nfc_dev *dev)
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (dev->fw_upload_in_progress) {
|
||||
rc = -EBUSY;
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (dev->dev_up) {
|
||||
rc = -EALREADY;
|
||||
goto error;
|
||||
|
||||
Reference in New Issue
Block a user