Lines Matching full:phy

188 static void pn544_hci_i2c_platform_init(struct pn544_i2c_phy *phy)  in pn544_hci_i2c_platform_init()  argument
194 nfc_info(&phy->i2c_dev->dev, "Detecting nfc_en polarity\n"); in pn544_hci_i2c_platform_init()
197 gpiod_set_value_cansleep(phy->gpiod_fw, 0); in pn544_hci_i2c_platform_init()
200 phy->en_polarity = polarity; in pn544_hci_i2c_platform_init()
204 gpiod_set_value_cansleep(phy->gpiod_en, !phy->en_polarity); in pn544_hci_i2c_platform_init()
208 gpiod_set_value_cansleep(phy->gpiod_en, phy->en_polarity); in pn544_hci_i2c_platform_init()
212 dev_dbg(&phy->i2c_dev->dev, "Sending reset cmd\n"); in pn544_hci_i2c_platform_init()
213 ret = i2c_master_send(phy->i2c_dev, rset_cmd, count); in pn544_hci_i2c_platform_init()
215 nfc_info(&phy->i2c_dev->dev, in pn544_hci_i2c_platform_init()
223 nfc_err(&phy->i2c_dev->dev, in pn544_hci_i2c_platform_init()
227 gpiod_set_value_cansleep(phy->gpiod_en, !phy->en_polarity); in pn544_hci_i2c_platform_init()
231 static void pn544_hci_i2c_enable_mode(struct pn544_i2c_phy *phy, int run_mode) in pn544_hci_i2c_enable_mode() argument
233 gpiod_set_value_cansleep(phy->gpiod_fw, run_mode == PN544_FW_MODE ? 1 : 0); in pn544_hci_i2c_enable_mode()
234 gpiod_set_value_cansleep(phy->gpiod_en, phy->en_polarity); in pn544_hci_i2c_enable_mode()
237 phy->run_mode = run_mode; in pn544_hci_i2c_enable_mode()
242 struct pn544_i2c_phy *phy = phy_id; in pn544_hci_i2c_enable() local
246 pn544_hci_i2c_enable_mode(phy, PN544_HCI_MODE); in pn544_hci_i2c_enable()
248 phy->powered = 1; in pn544_hci_i2c_enable()
255 struct pn544_i2c_phy *phy = phy_id; in pn544_hci_i2c_disable() local
257 gpiod_set_value_cansleep(phy->gpiod_fw, 0); in pn544_hci_i2c_disable()
258 gpiod_set_value_cansleep(phy->gpiod_en, !phy->en_polarity); in pn544_hci_i2c_disable()
261 gpiod_set_value_cansleep(phy->gpiod_en, phy->en_polarity); in pn544_hci_i2c_disable()
264 gpiod_set_value_cansleep(phy->gpiod_en, !phy->en_polarity); in pn544_hci_i2c_disable()
267 phy->powered = 0; in pn544_hci_i2c_disable()
298 struct pn544_i2c_phy *phy = phy_id; in pn544_hci_i2c_write() local
299 struct i2c_client *client = phy->i2c_dev; in pn544_hci_i2c_write()
301 if (phy->hard_fault != 0) in pn544_hci_i2c_write()
302 return phy->hard_fault; in pn544_hci_i2c_write()
358 static int pn544_hci_i2c_read(struct pn544_i2c_phy *phy, struct sk_buff **skb) in pn544_hci_i2c_read() argument
363 struct i2c_client *client = phy->i2c_dev; in pn544_hci_i2c_read()
417 static int pn544_hci_i2c_fw_read_status(struct pn544_i2c_phy *phy) in pn544_hci_i2c_fw_read_status() argument
421 struct i2c_client *client = phy->i2c_dev; in pn544_hci_i2c_fw_read_status()
484 struct pn544_i2c_phy *phy = phy_id; in pn544_hci_i2c_irq_thread_fn() local
489 if (!phy || irq != phy->i2c_dev->irq) { in pn544_hci_i2c_irq_thread_fn()
494 client = phy->i2c_dev; in pn544_hci_i2c_irq_thread_fn()
497 if (phy->hard_fault != 0) in pn544_hci_i2c_irq_thread_fn()
500 if (phy->run_mode == PN544_FW_MODE) { in pn544_hci_i2c_irq_thread_fn()
501 phy->fw_cmd_result = pn544_hci_i2c_fw_read_status(phy); in pn544_hci_i2c_irq_thread_fn()
502 schedule_work(&phy->fw_work); in pn544_hci_i2c_irq_thread_fn()
504 r = pn544_hci_i2c_read(phy, &skb); in pn544_hci_i2c_irq_thread_fn()
506 phy->hard_fault = r; in pn544_hci_i2c_irq_thread_fn()
508 nfc_hci_recv_frame(phy->hdev, NULL); in pn544_hci_i2c_irq_thread_fn()
515 nfc_hci_recv_frame(phy->hdev, skb); in pn544_hci_i2c_irq_thread_fn()
529 struct pn544_i2c_phy *phy = phy_id; in pn544_hci_i2c_fw_download() local
533 strcpy(phy->firmware_name, firmware_name); in pn544_hci_i2c_fw_download()
535 phy->hw_variant = hw_variant; in pn544_hci_i2c_fw_download()
536 phy->fw_work_state = FW_WORK_STATE_START; in pn544_hci_i2c_fw_download()
538 schedule_work(&phy->fw_work); in pn544_hci_i2c_fw_download()
543 static void pn544_hci_i2c_fw_work_complete(struct pn544_i2c_phy *phy, in pn544_hci_i2c_fw_work_complete() argument
548 pn544_hci_i2c_disable(phy); in pn544_hci_i2c_fw_work_complete()
550 phy->fw_work_state = FW_WORK_STATE_IDLE; in pn544_hci_i2c_fw_work_complete()
552 if (phy->fw) { in pn544_hci_i2c_fw_work_complete()
553 release_firmware(phy->fw); in pn544_hci_i2c_fw_work_complete()
554 phy->fw = NULL; in pn544_hci_i2c_fw_work_complete()
557 nfc_fw_download_done(phy->hdev->ndev, phy->firmware_name, (u32) -result); in pn544_hci_i2c_fw_work_complete()
640 static int pn544_hci_i2c_fw_write_chunk(struct pn544_i2c_phy *phy) in pn544_hci_i2c_fw_write_chunk() argument
644 r = pn544_hci_i2c_fw_write_cmd(phy->i2c_dev, in pn544_hci_i2c_fw_write_chunk()
645 phy->fw_blob_dest_addr + phy->fw_written, in pn544_hci_i2c_fw_write_chunk()
646 phy->fw_blob_data + phy->fw_written, in pn544_hci_i2c_fw_write_chunk()
647 phy->fw_blob_size - phy->fw_written); in pn544_hci_i2c_fw_write_chunk()
651 phy->fw_written += r; in pn544_hci_i2c_fw_write_chunk()
652 phy->fw_work_state = FW_WORK_STATE_WAIT_WRITE_ANSWER; in pn544_hci_i2c_fw_write_chunk()
657 static int pn544_hci_i2c_fw_secure_write_frame_cmd(struct pn544_i2c_phy *phy, in pn544_hci_i2c_fw_secure_write_frame_cmd() argument
678 r = i2c_master_send(phy->i2c_dev, buf, chunklen); in pn544_hci_i2c_fw_secure_write_frame_cmd()
689 static int pn544_hci_i2c_fw_secure_write_frame(struct pn544_i2c_phy *phy) in pn544_hci_i2c_fw_secure_write_frame() argument
694 framep = (struct pn544_i2c_fw_secure_frame *) phy->fw_blob_data; in pn544_hci_i2c_fw_secure_write_frame()
695 if (phy->fw_written == 0) in pn544_hci_i2c_fw_secure_write_frame()
696 phy->fw_blob_size = get_unaligned_be16(&framep->be_datalen) in pn544_hci_i2c_fw_secure_write_frame()
700 if (phy->fw_blob_size > PN544_FW_I2C_MAX_PAYLOAD && in pn544_hci_i2c_fw_secure_write_frame()
705 if (phy->fw_blob_size < PN544_FW_I2C_MAX_PAYLOAD) { in pn544_hci_i2c_fw_secure_write_frame()
706 r = i2c_master_send(phy->i2c_dev, in pn544_hci_i2c_fw_secure_write_frame()
707 (const char *) phy->fw_blob_data, phy->fw_blob_size); in pn544_hci_i2c_fw_secure_write_frame()
709 if (r == phy->fw_blob_size) in pn544_hci_i2c_fw_secure_write_frame()
717 r = pn544_hci_i2c_fw_secure_write_frame_cmd(phy, in pn544_hci_i2c_fw_secure_write_frame()
718 phy->fw_blob_data + phy->fw_written, in pn544_hci_i2c_fw_secure_write_frame()
719 phy->fw_blob_size - phy->fw_written); in pn544_hci_i2c_fw_secure_write_frame()
724 phy->fw_written += r; in pn544_hci_i2c_fw_secure_write_frame()
725 phy->fw_work_state = FW_WORK_STATE_WAIT_SECURE_WRITE_ANSWER; in pn544_hci_i2c_fw_secure_write_frame()
729 pn544_hci_i2c_enable_mode(phy, PN544_FW_MODE); in pn544_hci_i2c_fw_secure_write_frame()
730 phy->fw_cmd_result = 0; in pn544_hci_i2c_fw_secure_write_frame()
731 schedule_work(&phy->fw_work); in pn544_hci_i2c_fw_secure_write_frame()
739 struct pn544_i2c_phy *phy = container_of(work, struct pn544_i2c_phy, in pn544_hci_i2c_fw_work() local
745 switch (phy->fw_work_state) { in pn544_hci_i2c_fw_work()
747 pn544_hci_i2c_enable_mode(phy, PN544_FW_MODE); in pn544_hci_i2c_fw_work()
749 r = request_firmware(&phy->fw, phy->firmware_name, in pn544_hci_i2c_fw_work()
750 &phy->i2c_dev->dev); in pn544_hci_i2c_fw_work()
754 phy->fw_written = 0; in pn544_hci_i2c_fw_work()
756 switch (phy->hw_variant) { in pn544_hci_i2c_fw_work()
758 blob = (struct pn544_i2c_fw_blob *) phy->fw->data; in pn544_hci_i2c_fw_work()
759 phy->fw_blob_size = get_unaligned_be32(&blob->be_size); in pn544_hci_i2c_fw_work()
760 phy->fw_blob_dest_addr = get_unaligned_be32( in pn544_hci_i2c_fw_work()
762 phy->fw_blob_data = blob->data; in pn544_hci_i2c_fw_work()
764 r = pn544_hci_i2c_fw_write_chunk(phy); in pn544_hci_i2c_fw_work()
768 phy->fw->data; in pn544_hci_i2c_fw_work()
769 phy->fw_blob_data = secure_blob->data; in pn544_hci_i2c_fw_work()
770 phy->fw_size = phy->fw->size; in pn544_hci_i2c_fw_work()
771 r = pn544_hci_i2c_fw_secure_write_frame(phy); in pn544_hci_i2c_fw_work()
780 pn544_hci_i2c_fw_work_complete(phy, r); in pn544_hci_i2c_fw_work()
784 r = phy->fw_cmd_result; in pn544_hci_i2c_fw_work()
788 if (phy->fw_written == phy->fw_blob_size) { in pn544_hci_i2c_fw_work()
789 r = pn544_hci_i2c_fw_check_cmd(phy->i2c_dev, in pn544_hci_i2c_fw_work()
790 phy->fw_blob_dest_addr, in pn544_hci_i2c_fw_work()
791 phy->fw_blob_data, in pn544_hci_i2c_fw_work()
792 phy->fw_blob_size); in pn544_hci_i2c_fw_work()
795 phy->fw_work_state = FW_WORK_STATE_WAIT_CHECK_ANSWER; in pn544_hci_i2c_fw_work()
799 r = pn544_hci_i2c_fw_write_chunk(phy); in pn544_hci_i2c_fw_work()
803 pn544_hci_i2c_fw_work_complete(phy, r); in pn544_hci_i2c_fw_work()
807 r = phy->fw_cmd_result; in pn544_hci_i2c_fw_work()
811 blob = (struct pn544_i2c_fw_blob *) (phy->fw_blob_data + in pn544_hci_i2c_fw_work()
812 phy->fw_blob_size); in pn544_hci_i2c_fw_work()
813 phy->fw_blob_size = get_unaligned_be32(&blob->be_size); in pn544_hci_i2c_fw_work()
814 if (phy->fw_blob_size != 0) { in pn544_hci_i2c_fw_work()
815 phy->fw_blob_dest_addr = in pn544_hci_i2c_fw_work()
817 phy->fw_blob_data = blob->data; in pn544_hci_i2c_fw_work()
819 phy->fw_written = 0; in pn544_hci_i2c_fw_work()
820 r = pn544_hci_i2c_fw_write_chunk(phy); in pn544_hci_i2c_fw_work()
824 if (r < 0 || phy->fw_blob_size == 0) in pn544_hci_i2c_fw_work()
825 pn544_hci_i2c_fw_work_complete(phy, r); in pn544_hci_i2c_fw_work()
829 r = phy->fw_cmd_result; in pn544_hci_i2c_fw_work()
834 r = pn544_hci_i2c_fw_secure_write_frame(phy); in pn544_hci_i2c_fw_work()
838 if (phy->fw_written == phy->fw_blob_size) { in pn544_hci_i2c_fw_work()
840 (phy->fw_blob_data + phy->fw_blob_size); in pn544_hci_i2c_fw_work()
841 phy->fw_size -= phy->fw_blob_size + in pn544_hci_i2c_fw_work()
843 if (phy->fw_size >= PN544_FW_SECURE_BLOB_HEADER_LEN in pn544_hci_i2c_fw_work()
845 phy->fw_blob_data = secure_blob->data; in pn544_hci_i2c_fw_work()
847 phy->fw_written = 0; in pn544_hci_i2c_fw_work()
848 r = pn544_hci_i2c_fw_secure_write_frame(phy); in pn544_hci_i2c_fw_work()
853 if (r < 0 || phy->fw_size == 0) in pn544_hci_i2c_fw_work()
854 pn544_hci_i2c_fw_work_complete(phy, r); in pn544_hci_i2c_fw_work()
875 struct pn544_i2c_phy *phy; in pn544_hci_i2c_probe() local
886 phy = devm_kzalloc(&client->dev, sizeof(struct pn544_i2c_phy), in pn544_hci_i2c_probe()
888 if (!phy) in pn544_hci_i2c_probe()
891 INIT_WORK(&phy->fw_work, pn544_hci_i2c_fw_work); in pn544_hci_i2c_probe()
892 phy->fw_work_state = FW_WORK_STATE_IDLE; in pn544_hci_i2c_probe()
894 phy->i2c_dev = client; in pn544_hci_i2c_probe()
895 i2c_set_clientdata(client, phy); in pn544_hci_i2c_probe()
902 phy->gpiod_en = devm_gpiod_get(dev, "enable", GPIOD_OUT_LOW); in pn544_hci_i2c_probe()
903 if (IS_ERR(phy->gpiod_en)) { in pn544_hci_i2c_probe()
905 return PTR_ERR(phy->gpiod_en); in pn544_hci_i2c_probe()
909 phy->gpiod_fw = devm_gpiod_get(dev, "firmware", GPIOD_OUT_LOW); in pn544_hci_i2c_probe()
910 if (IS_ERR(phy->gpiod_fw)) { in pn544_hci_i2c_probe()
912 return PTR_ERR(phy->gpiod_fw); in pn544_hci_i2c_probe()
915 pn544_hci_i2c_platform_init(phy); in pn544_hci_i2c_probe()
920 PN544_HCI_I2C_DRIVER_NAME, phy); in pn544_hci_i2c_probe()
926 r = pn544_hci_probe(phy, &i2c_phy_ops, LLC_SHDLC_NAME, in pn544_hci_i2c_probe()
929 pn544_hci_i2c_fw_download, &phy->hdev); in pn544_hci_i2c_probe()
938 struct pn544_i2c_phy *phy = i2c_get_clientdata(client); in pn544_hci_i2c_remove() local
942 cancel_work_sync(&phy->fw_work); in pn544_hci_i2c_remove()
943 if (phy->fw_work_state != FW_WORK_STATE_IDLE) in pn544_hci_i2c_remove()
944 pn544_hci_i2c_fw_work_complete(phy, -ENODEV); in pn544_hci_i2c_remove()
946 pn544_hci_remove(phy->hdev); in pn544_hci_i2c_remove()
948 if (phy->powered) in pn544_hci_i2c_remove()
949 pn544_hci_i2c_disable(phy); in pn544_hci_i2c_remove()