diff options
Diffstat (limited to 'drivers/nfc/fdp/fdp.c')
-rw-r--r-- | drivers/nfc/fdp/fdp.c | 144 |
1 files changed, 53 insertions, 91 deletions
diff --git a/drivers/nfc/fdp/fdp.c b/drivers/nfc/fdp/fdp.c index 0cc9ac856fe2..f12f903a9dd1 100644 --- a/drivers/nfc/fdp/fdp.c +++ b/drivers/nfc/fdp/fdp.c @@ -38,7 +38,7 @@ #define NCI_OP_PROP_SET_PDATA_OID 0x23 struct fdp_nci_info { - struct nfc_phy_ops *phy_ops; + const struct nfc_phy_ops *phy_ops; struct fdp_i2c_phy *phy; struct nci_dev *ndev; @@ -52,7 +52,7 @@ struct fdp_nci_info { u32 limited_otp_version; u8 key_index; - u8 *fw_vsc_cfg; + const u8 *fw_vsc_cfg; u8 clock_type; u32 clock_freq; @@ -65,7 +65,7 @@ struct fdp_nci_info { wait_queue_head_t setup_wq; }; -static u8 nci_core_get_config_otp_ram_version[5] = { +static const u8 nci_core_get_config_otp_ram_version[5] = { 0x04, NCI_PARAM_ID_FW_RAM_VERSION, NCI_PARAM_ID_FW_OTP_VERSION, @@ -76,7 +76,7 @@ static u8 nci_core_get_config_otp_ram_version[5] = { struct nci_core_get_config_rsp { u8 status; u8 count; - u8 data[0]; + u8 data[]; }; static int fdp_nci_create_conn(struct nci_dev *ndev) @@ -111,7 +111,7 @@ static inline int fdp_nci_patch_cmd(struct nci_dev *ndev, u8 type) } static inline int fdp_nci_set_production_data(struct nci_dev *ndev, u8 len, - char *data) + const char *data) { return nci_prop_cmd(ndev, NCI_OP_PROP_SET_PDATA_OID, len, data); } @@ -149,7 +149,7 @@ static void fdp_nci_send_patch_cb(struct nci_dev *ndev) wake_up(&info->setup_wq); } -/** +/* * Register a packet sent counter and a callback * * We have no other way of knowing when all firmware packets were sent out @@ -167,7 +167,7 @@ static void fdp_nci_set_data_pkt_counter(struct nci_dev *ndev, info->data_pkt_counter_cb = cb; } -/** +/* * The device is expecting a stream of packets. All packets need to * have the PBF flag set to 0x0 (last packet) even if the firmware * file is segmented and there are multiple packets. If we give the @@ -176,7 +176,7 @@ static void fdp_nci_set_data_pkt_counter(struct nci_dev *ndev, * * The firmware will be analyzed and applied when we send NCI_OP_PROP_PATCH_CMD * command with NCI_PATCH_TYPE_EOT parameter. The device will send a - * NFCC_PATCH_NTF packaet and a NCI_OP_CORE_RESET_NTF packet. + * NFCC_PATCH_NTF packet and a NCI_OP_CORE_RESET_NTF packet. */ static int fdp_nci_send_patch(struct nci_dev *ndev, u8 conn_id, u8 type) { @@ -184,7 +184,7 @@ static int fdp_nci_send_patch(struct nci_dev *ndev, u8 conn_id, u8 type) const struct firmware *fw; struct sk_buff *skb; unsigned long len; - u8 max_size, payload_size; + int max_size, payload_size; int rc = 0; if ((type == NCI_PATCH_TYPE_OTP && !info->otp_patch) || @@ -207,8 +207,7 @@ static int fdp_nci_send_patch(struct nci_dev *ndev, u8 conn_id, u8 type) while (len) { - payload_size = min_t(unsigned long, (unsigned long) max_size, - len); + payload_size = min_t(unsigned long, max_size, len); skb = nci_skb_alloc(ndev, (NCI_CTRL_HDR_SIZE + payload_size), GFP_KERNEL); @@ -237,77 +236,62 @@ static int fdp_nci_send_patch(struct nci_dev *ndev, u8 conn_id, u8 type) static int fdp_nci_open(struct nci_dev *ndev) { - int r; - struct fdp_nci_info *info = nci_get_drvdata(ndev); - struct device *dev = &info->phy->i2c_dev->dev; + const struct fdp_nci_info *info = nci_get_drvdata(ndev); - dev_dbg(dev, "%s\n", __func__); - - r = info->phy_ops->enable(info->phy); - - return r; + return info->phy_ops->enable(info->phy); } static int fdp_nci_close(struct nci_dev *ndev) { - struct fdp_nci_info *info = nci_get_drvdata(ndev); - struct device *dev = &info->phy->i2c_dev->dev; - - dev_dbg(dev, "%s\n", __func__); return 0; } static int fdp_nci_send(struct nci_dev *ndev, struct sk_buff *skb) { struct fdp_nci_info *info = nci_get_drvdata(ndev); - struct device *dev = &info->phy->i2c_dev->dev; - - dev_dbg(dev, "%s\n", __func__); + int ret; if (atomic_dec_and_test(&info->data_pkt_counter)) info->data_pkt_counter_cb(ndev); - return info->phy_ops->write(info->phy, skb); -} - -int fdp_nci_recv_frame(struct nci_dev *ndev, struct sk_buff *skb) -{ - struct fdp_nci_info *info = nci_get_drvdata(ndev); - struct device *dev = &info->phy->i2c_dev->dev; + ret = info->phy_ops->write(info->phy, skb); + if (ret < 0) { + kfree_skb(skb); + return ret; + } - dev_dbg(dev, "%s\n", __func__); - return nci_recv_frame(ndev, skb); + consume_skb(skb); + return 0; } -EXPORT_SYMBOL(fdp_nci_recv_frame); static int fdp_nci_request_firmware(struct nci_dev *ndev) { struct fdp_nci_info *info = nci_get_drvdata(ndev); struct device *dev = &info->phy->i2c_dev->dev; - u8 *data; + const u8 *data; int r; r = request_firmware(&info->ram_patch, FDP_RAM_PATCH_NAME, dev); if (r < 0) { nfc_err(dev, "RAM patch request error\n"); - goto error; + return r; } - data = (u8 *) info->ram_patch->data; + data = info->ram_patch->data; info->ram_patch_version = data[FDP_FW_HEADER_SIZE] | (data[FDP_FW_HEADER_SIZE + 1] << 8) | (data[FDP_FW_HEADER_SIZE + 2] << 16) | (data[FDP_FW_HEADER_SIZE + 3] << 24); - dev_dbg(dev, "RAM patch version: %d, size: %d\n", - info->ram_patch_version, (int) info->ram_patch->size); + dev_dbg(dev, "RAM patch version: %d, size: %zu\n", + info->ram_patch_version, info->ram_patch->size); r = request_firmware(&info->otp_patch, FDP_OTP_PATCH_NAME, dev); if (r < 0) { nfc_err(dev, "OTP patch request error\n"); - goto out; + return 0; } data = (u8 *) info->otp_patch->data; @@ -317,12 +301,9 @@ static int fdp_nci_request_firmware(struct nci_dev *ndev) (data[FDP_FW_HEADER_SIZE+2] << 16) | (data[FDP_FW_HEADER_SIZE+3] << 24); - dev_dbg(dev, "OTP patch version: %d, size: %d\n", - info->otp_patch_version, (int) info->otp_patch->size); -out: + dev_dbg(dev, "OTP patch version: %d, size: %zu\n", + info->otp_patch_version, info->otp_patch->size); return 0; -error: - return r; } static void fdp_nci_release_firmware(struct nci_dev *ndev) @@ -348,7 +329,7 @@ static int fdp_nci_patch_otp(struct nci_dev *ndev) int r = 0; if (info->otp_version >= info->otp_patch_version) - goto out; + return r; info->setup_patch_sent = 0; info->setup_reset_ntf = 0; @@ -357,19 +338,17 @@ static int fdp_nci_patch_otp(struct nci_dev *ndev) /* Patch init request */ r = fdp_nci_patch_cmd(ndev, NCI_PATCH_TYPE_OTP); if (r) - goto out; + return r; /* Patch data connection creation */ conn_id = fdp_nci_create_conn(ndev); - if (conn_id < 0) { - r = conn_id; - goto out; - } + if (conn_id < 0) + return conn_id; /* Send the patch over the data connection */ r = fdp_nci_send_patch(ndev, conn_id, NCI_PATCH_TYPE_OTP); if (r) - goto out; + return r; /* Wait for all the packets to be send over i2c */ wait_event_interruptible(info->setup_wq, @@ -381,13 +360,12 @@ static int fdp_nci_patch_otp(struct nci_dev *ndev) /* Close the data connection */ r = nci_core_conn_close(info->ndev, conn_id); if (r) - goto out; + return r; /* Patch finish message */ if (fdp_nci_patch_cmd(ndev, NCI_PATCH_TYPE_EOT)) { nfc_err(dev, "OTP patch error 0x%x\n", r); - r = -EINVAL; - goto out; + return -EINVAL; } /* If the patch notification didn't arrive yet, wait for it */ @@ -397,8 +375,7 @@ static int fdp_nci_patch_otp(struct nci_dev *ndev) r = info->setup_patch_status; if (r) { nfc_err(dev, "OTP patch error 0x%x\n", r); - r = -EINVAL; - goto out; + return -EINVAL; } /* @@ -407,7 +384,6 @@ static int fdp_nci_patch_otp(struct nci_dev *ndev) */ wait_event_interruptible(info->setup_wq, info->setup_reset_ntf); -out: return r; } @@ -419,7 +395,7 @@ static int fdp_nci_patch_ram(struct nci_dev *ndev) int r = 0; if (info->ram_version >= info->ram_patch_version) - goto out; + return r; info->setup_patch_sent = 0; info->setup_reset_ntf = 0; @@ -428,19 +404,17 @@ static int fdp_nci_patch_ram(struct nci_dev *ndev) /* Patch init request */ r = fdp_nci_patch_cmd(ndev, NCI_PATCH_TYPE_RAM); if (r) - goto out; + return r; /* Patch data connection creation */ conn_id = fdp_nci_create_conn(ndev); - if (conn_id < 0) { - r = conn_id; - goto out; - } + if (conn_id < 0) + return conn_id; /* Send the patch over the data connection */ r = fdp_nci_send_patch(ndev, conn_id, NCI_PATCH_TYPE_RAM); if (r) - goto out; + return r; /* Wait for all the packets to be send over i2c */ wait_event_interruptible(info->setup_wq, @@ -452,13 +426,12 @@ static int fdp_nci_patch_ram(struct nci_dev *ndev) /* Close the data connection */ r = nci_core_conn_close(info->ndev, conn_id); if (r) - goto out; + return r; /* Patch finish message */ if (fdp_nci_patch_cmd(ndev, NCI_PATCH_TYPE_EOT)) { nfc_err(dev, "RAM patch error 0x%x\n", r); - r = -EINVAL; - goto out; + return -EINVAL; } /* If the patch notification didn't arrive yet, wait for it */ @@ -468,8 +441,7 @@ static int fdp_nci_patch_ram(struct nci_dev *ndev) r = info->setup_patch_status; if (r) { nfc_err(dev, "RAM patch error 0x%x\n", r); - r = -EINVAL; - goto out; + return -EINVAL; } /* @@ -478,7 +450,6 @@ static int fdp_nci_patch_ram(struct nci_dev *ndev) */ wait_event_interruptible(info->setup_wq, info->setup_reset_ntf); -out: return r; } @@ -490,8 +461,6 @@ static int fdp_nci_setup(struct nci_dev *ndev) int r; u8 patched = 0; - dev_dbg(dev, "%s\n", __func__); - r = nci_core_init(ndev); if (r) goto error; @@ -599,9 +568,7 @@ static int fdp_nci_core_reset_ntf_packet(struct nci_dev *ndev, struct sk_buff *skb) { struct fdp_nci_info *info = nci_get_drvdata(ndev); - struct device *dev = &info->phy->i2c_dev->dev; - dev_dbg(dev, "%s\n", __func__); info->setup_reset_ntf = 1; wake_up(&info->setup_wq); @@ -612,9 +579,7 @@ static int fdp_nci_prop_patch_ntf_packet(struct nci_dev *ndev, struct sk_buff *skb) { struct fdp_nci_info *info = nci_get_drvdata(ndev); - struct device *dev = &info->phy->i2c_dev->dev; - dev_dbg(dev, "%s\n", __func__); info->setup_patch_ntf = 1; info->setup_patch_status = skb->data[0]; wake_up(&info->setup_wq); @@ -653,8 +618,9 @@ static int fdp_nci_core_get_config_rsp_packet(struct nci_dev *ndev, { struct fdp_nci_info *info = nci_get_drvdata(ndev); struct device *dev = &info->phy->i2c_dev->dev; - struct nci_core_get_config_rsp *rsp = (void *) skb->data; - u8 i, *p; + const struct nci_core_get_config_rsp *rsp = (void *) skb->data; + unsigned int i; + const u8 *p; if (rsp->status == NCI_STATUS_OK) { @@ -694,7 +660,7 @@ static int fdp_nci_core_get_config_rsp_packet(struct nci_dev *ndev, return 0; } -static struct nci_driver_ops fdp_core_ops[] = { +static const struct nci_driver_ops fdp_core_ops[] = { { .opcode = NCI_OP_CORE_GET_CONFIG_RSP, .rsp = fdp_nci_core_get_config_rsp_packet, @@ -705,7 +671,7 @@ static struct nci_driver_ops fdp_core_ops[] = { }, }; -static struct nci_driver_ops fdp_prop_ops[] = { +static const struct nci_driver_ops fdp_prop_ops[] = { { .opcode = nci_opcode_pack(NCI_GID_PROP, NCI_OP_PROP_PATCH_OID), .rsp = fdp_nci_prop_patch_rsp_packet, @@ -718,7 +684,7 @@ static struct nci_driver_ops fdp_prop_ops[] = { }, }; -static struct nci_ops nci_ops = { +static const struct nci_ops nci_ops = { .open = fdp_nci_open, .close = fdp_nci_close, .send = fdp_nci_send, @@ -730,10 +696,10 @@ static struct nci_ops nci_ops = { .n_core_ops = ARRAY_SIZE(fdp_core_ops), }; -int fdp_nci_probe(struct fdp_i2c_phy *phy, struct nfc_phy_ops *phy_ops, +int fdp_nci_probe(struct fdp_i2c_phy *phy, const struct nfc_phy_ops *phy_ops, struct nci_dev **ndevp, int tx_headroom, int tx_tailroom, u8 clock_type, u32 clock_freq, - u8 *fw_vsc_cfg) + const u8 *fw_vsc_cfg) { struct device *dev = &phy->i2c_dev->dev; struct fdp_nci_info *info; @@ -761,6 +727,7 @@ int fdp_nci_probe(struct fdp_i2c_phy *phy, struct nfc_phy_ops *phy_ops, NFC_PROTO_NFC_DEP_MASK | NFC_PROTO_ISO15693_MASK; + BUILD_BUG_ON(ARRAY_SIZE(fdp_prop_ops) > NCI_MAX_PROPRIETARY_CMD); ndev = nci_allocate_device(&nci_ops, protocols, tx_headroom, tx_tailroom); if (!ndev) { @@ -787,11 +754,6 @@ EXPORT_SYMBOL(fdp_nci_probe); void fdp_nci_remove(struct nci_dev *ndev) { - struct fdp_nci_info *info = nci_get_drvdata(ndev); - struct device *dev = &info->phy->i2c_dev->dev; - - dev_dbg(dev, "%s\n", __func__); - nci_unregister_device(ndev); nci_free_device(ndev); } |