Lines Matching refs:phy

186 static void pn544_hci_i2c_platform_init(struct pn544_i2c_phy *phy)  in pn544_hci_i2c_platform_init()  argument
192 nfc_info(&phy->i2c_dev->dev, "Detecting nfc_en polarity\n"); in pn544_hci_i2c_platform_init()
195 gpiod_set_value_cansleep(phy->gpiod_fw, 0); in pn544_hci_i2c_platform_init()
198 phy->en_polarity = polarity; in pn544_hci_i2c_platform_init()
202 gpiod_set_value_cansleep(phy->gpiod_en, !phy->en_polarity); in pn544_hci_i2c_platform_init()
206 gpiod_set_value_cansleep(phy->gpiod_en, phy->en_polarity); in pn544_hci_i2c_platform_init()
210 dev_dbg(&phy->i2c_dev->dev, "Sending reset cmd\n"); in pn544_hci_i2c_platform_init()
211 ret = i2c_master_send(phy->i2c_dev, rset_cmd, count); in pn544_hci_i2c_platform_init()
213 nfc_info(&phy->i2c_dev->dev, in pn544_hci_i2c_platform_init()
221 nfc_err(&phy->i2c_dev->dev, in pn544_hci_i2c_platform_init()
225 gpiod_set_value_cansleep(phy->gpiod_en, !phy->en_polarity); in pn544_hci_i2c_platform_init()
229 static void pn544_hci_i2c_enable_mode(struct pn544_i2c_phy *phy, int run_mode) in pn544_hci_i2c_enable_mode() argument
231 gpiod_set_value_cansleep(phy->gpiod_fw, run_mode == PN544_FW_MODE ? 1 : 0); in pn544_hci_i2c_enable_mode()
232 gpiod_set_value_cansleep(phy->gpiod_en, phy->en_polarity); in pn544_hci_i2c_enable_mode()
235 phy->run_mode = run_mode; in pn544_hci_i2c_enable_mode()
240 struct pn544_i2c_phy *phy = phy_id; in pn544_hci_i2c_enable() local
242 pn544_hci_i2c_enable_mode(phy, PN544_HCI_MODE); in pn544_hci_i2c_enable()
244 phy->powered = 1; in pn544_hci_i2c_enable()
251 struct pn544_i2c_phy *phy = phy_id; in pn544_hci_i2c_disable() local
253 gpiod_set_value_cansleep(phy->gpiod_fw, 0); in pn544_hci_i2c_disable()
254 gpiod_set_value_cansleep(phy->gpiod_en, !phy->en_polarity); in pn544_hci_i2c_disable()
257 gpiod_set_value_cansleep(phy->gpiod_en, phy->en_polarity); in pn544_hci_i2c_disable()
260 gpiod_set_value_cansleep(phy->gpiod_en, !phy->en_polarity); in pn544_hci_i2c_disable()
263 phy->powered = 0; in pn544_hci_i2c_disable()
294 struct pn544_i2c_phy *phy = phy_id; in pn544_hci_i2c_write() local
295 struct i2c_client *client = phy->i2c_dev; in pn544_hci_i2c_write()
297 if (phy->hard_fault != 0) in pn544_hci_i2c_write()
298 return phy->hard_fault; in pn544_hci_i2c_write()
354 static int pn544_hci_i2c_read(struct pn544_i2c_phy *phy, struct sk_buff **skb) in pn544_hci_i2c_read() argument
359 struct i2c_client *client = phy->i2c_dev; in pn544_hci_i2c_read()
413 static int pn544_hci_i2c_fw_read_status(struct pn544_i2c_phy *phy) in pn544_hci_i2c_fw_read_status() argument
417 struct i2c_client *client = phy->i2c_dev; in pn544_hci_i2c_fw_read_status()
480 struct pn544_i2c_phy *phy = phy_id; in pn544_hci_i2c_irq_thread_fn() local
485 if (!phy || irq != phy->i2c_dev->irq) { in pn544_hci_i2c_irq_thread_fn()
490 client = phy->i2c_dev; in pn544_hci_i2c_irq_thread_fn()
493 if (phy->hard_fault != 0) in pn544_hci_i2c_irq_thread_fn()
496 if (phy->run_mode == PN544_FW_MODE) { in pn544_hci_i2c_irq_thread_fn()
497 phy->fw_cmd_result = pn544_hci_i2c_fw_read_status(phy); in pn544_hci_i2c_irq_thread_fn()
498 schedule_work(&phy->fw_work); in pn544_hci_i2c_irq_thread_fn()
500 r = pn544_hci_i2c_read(phy, &skb); in pn544_hci_i2c_irq_thread_fn()
502 phy->hard_fault = r; in pn544_hci_i2c_irq_thread_fn()
504 nfc_hci_recv_frame(phy->hdev, NULL); in pn544_hci_i2c_irq_thread_fn()
511 nfc_hci_recv_frame(phy->hdev, skb); in pn544_hci_i2c_irq_thread_fn()
525 struct pn544_i2c_phy *phy = phy_id; in pn544_hci_i2c_fw_download() local
529 strcpy(phy->firmware_name, firmware_name); in pn544_hci_i2c_fw_download()
531 phy->hw_variant = hw_variant; in pn544_hci_i2c_fw_download()
532 phy->fw_work_state = FW_WORK_STATE_START; in pn544_hci_i2c_fw_download()
534 schedule_work(&phy->fw_work); in pn544_hci_i2c_fw_download()
539 static void pn544_hci_i2c_fw_work_complete(struct pn544_i2c_phy *phy, in pn544_hci_i2c_fw_work_complete() argument
544 pn544_hci_i2c_disable(phy); in pn544_hci_i2c_fw_work_complete()
546 phy->fw_work_state = FW_WORK_STATE_IDLE; in pn544_hci_i2c_fw_work_complete()
548 if (phy->fw) { in pn544_hci_i2c_fw_work_complete()
549 release_firmware(phy->fw); in pn544_hci_i2c_fw_work_complete()
550 phy->fw = NULL; in pn544_hci_i2c_fw_work_complete()
553 nfc_fw_download_done(phy->hdev->ndev, phy->firmware_name, (u32) -result); in pn544_hci_i2c_fw_work_complete()
636 static int pn544_hci_i2c_fw_write_chunk(struct pn544_i2c_phy *phy) in pn544_hci_i2c_fw_write_chunk() argument
640 r = pn544_hci_i2c_fw_write_cmd(phy->i2c_dev, in pn544_hci_i2c_fw_write_chunk()
641 phy->fw_blob_dest_addr + phy->fw_written, in pn544_hci_i2c_fw_write_chunk()
642 phy->fw_blob_data + phy->fw_written, in pn544_hci_i2c_fw_write_chunk()
643 phy->fw_blob_size - phy->fw_written); in pn544_hci_i2c_fw_write_chunk()
647 phy->fw_written += r; in pn544_hci_i2c_fw_write_chunk()
648 phy->fw_work_state = FW_WORK_STATE_WAIT_WRITE_ANSWER; in pn544_hci_i2c_fw_write_chunk()
653 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
674 r = i2c_master_send(phy->i2c_dev, buf, chunklen); in pn544_hci_i2c_fw_secure_write_frame_cmd()
685 static int pn544_hci_i2c_fw_secure_write_frame(struct pn544_i2c_phy *phy) in pn544_hci_i2c_fw_secure_write_frame() argument
690 framep = (struct pn544_i2c_fw_secure_frame *) phy->fw_blob_data; in pn544_hci_i2c_fw_secure_write_frame()
691 if (phy->fw_written == 0) in pn544_hci_i2c_fw_secure_write_frame()
692 phy->fw_blob_size = get_unaligned_be16(&framep->be_datalen) in pn544_hci_i2c_fw_secure_write_frame()
696 if (phy->fw_blob_size > PN544_FW_I2C_MAX_PAYLOAD && in pn544_hci_i2c_fw_secure_write_frame()
701 if (phy->fw_blob_size < PN544_FW_I2C_MAX_PAYLOAD) { in pn544_hci_i2c_fw_secure_write_frame()
702 r = i2c_master_send(phy->i2c_dev, in pn544_hci_i2c_fw_secure_write_frame()
703 (const char *) phy->fw_blob_data, phy->fw_blob_size); in pn544_hci_i2c_fw_secure_write_frame()
705 if (r == phy->fw_blob_size) in pn544_hci_i2c_fw_secure_write_frame()
713 r = pn544_hci_i2c_fw_secure_write_frame_cmd(phy, in pn544_hci_i2c_fw_secure_write_frame()
714 phy->fw_blob_data + phy->fw_written, in pn544_hci_i2c_fw_secure_write_frame()
715 phy->fw_blob_size - phy->fw_written); in pn544_hci_i2c_fw_secure_write_frame()
720 phy->fw_written += r; in pn544_hci_i2c_fw_secure_write_frame()
721 phy->fw_work_state = FW_WORK_STATE_WAIT_SECURE_WRITE_ANSWER; in pn544_hci_i2c_fw_secure_write_frame()
725 pn544_hci_i2c_enable_mode(phy, PN544_FW_MODE); in pn544_hci_i2c_fw_secure_write_frame()
726 phy->fw_cmd_result = 0; in pn544_hci_i2c_fw_secure_write_frame()
727 schedule_work(&phy->fw_work); in pn544_hci_i2c_fw_secure_write_frame()
735 struct pn544_i2c_phy *phy = container_of(work, struct pn544_i2c_phy, in pn544_hci_i2c_fw_work() local
741 switch (phy->fw_work_state) { in pn544_hci_i2c_fw_work()
743 pn544_hci_i2c_enable_mode(phy, PN544_FW_MODE); in pn544_hci_i2c_fw_work()
745 r = request_firmware(&phy->fw, phy->firmware_name, in pn544_hci_i2c_fw_work()
746 &phy->i2c_dev->dev); in pn544_hci_i2c_fw_work()
750 phy->fw_written = 0; in pn544_hci_i2c_fw_work()
752 switch (phy->hw_variant) { in pn544_hci_i2c_fw_work()
754 blob = (struct pn544_i2c_fw_blob *) phy->fw->data; in pn544_hci_i2c_fw_work()
755 phy->fw_blob_size = get_unaligned_be32(&blob->be_size); in pn544_hci_i2c_fw_work()
756 phy->fw_blob_dest_addr = get_unaligned_be32( in pn544_hci_i2c_fw_work()
758 phy->fw_blob_data = blob->data; in pn544_hci_i2c_fw_work()
760 r = pn544_hci_i2c_fw_write_chunk(phy); in pn544_hci_i2c_fw_work()
764 phy->fw->data; in pn544_hci_i2c_fw_work()
765 phy->fw_blob_data = secure_blob->data; in pn544_hci_i2c_fw_work()
766 phy->fw_size = phy->fw->size; in pn544_hci_i2c_fw_work()
767 r = pn544_hci_i2c_fw_secure_write_frame(phy); in pn544_hci_i2c_fw_work()
776 pn544_hci_i2c_fw_work_complete(phy, r); in pn544_hci_i2c_fw_work()
780 r = phy->fw_cmd_result; in pn544_hci_i2c_fw_work()
784 if (phy->fw_written == phy->fw_blob_size) { in pn544_hci_i2c_fw_work()
785 r = pn544_hci_i2c_fw_check_cmd(phy->i2c_dev, in pn544_hci_i2c_fw_work()
786 phy->fw_blob_dest_addr, in pn544_hci_i2c_fw_work()
787 phy->fw_blob_data, in pn544_hci_i2c_fw_work()
788 phy->fw_blob_size); in pn544_hci_i2c_fw_work()
791 phy->fw_work_state = FW_WORK_STATE_WAIT_CHECK_ANSWER; in pn544_hci_i2c_fw_work()
795 r = pn544_hci_i2c_fw_write_chunk(phy); in pn544_hci_i2c_fw_work()
799 pn544_hci_i2c_fw_work_complete(phy, r); in pn544_hci_i2c_fw_work()
803 r = phy->fw_cmd_result; in pn544_hci_i2c_fw_work()
807 blob = (struct pn544_i2c_fw_blob *) (phy->fw_blob_data + in pn544_hci_i2c_fw_work()
808 phy->fw_blob_size); in pn544_hci_i2c_fw_work()
809 phy->fw_blob_size = get_unaligned_be32(&blob->be_size); in pn544_hci_i2c_fw_work()
810 if (phy->fw_blob_size != 0) { in pn544_hci_i2c_fw_work()
811 phy->fw_blob_dest_addr = in pn544_hci_i2c_fw_work()
813 phy->fw_blob_data = blob->data; in pn544_hci_i2c_fw_work()
815 phy->fw_written = 0; in pn544_hci_i2c_fw_work()
816 r = pn544_hci_i2c_fw_write_chunk(phy); in pn544_hci_i2c_fw_work()
820 if (r < 0 || phy->fw_blob_size == 0) in pn544_hci_i2c_fw_work()
821 pn544_hci_i2c_fw_work_complete(phy, r); in pn544_hci_i2c_fw_work()
825 r = phy->fw_cmd_result; in pn544_hci_i2c_fw_work()
830 r = pn544_hci_i2c_fw_secure_write_frame(phy); in pn544_hci_i2c_fw_work()
834 if (phy->fw_written == phy->fw_blob_size) { in pn544_hci_i2c_fw_work()
836 (phy->fw_blob_data + phy->fw_blob_size); in pn544_hci_i2c_fw_work()
837 phy->fw_size -= phy->fw_blob_size + in pn544_hci_i2c_fw_work()
839 if (phy->fw_size >= PN544_FW_SECURE_BLOB_HEADER_LEN in pn544_hci_i2c_fw_work()
841 phy->fw_blob_data = secure_blob->data; in pn544_hci_i2c_fw_work()
843 phy->fw_written = 0; in pn544_hci_i2c_fw_work()
844 r = pn544_hci_i2c_fw_secure_write_frame(phy); in pn544_hci_i2c_fw_work()
849 if (r < 0 || phy->fw_size == 0) in pn544_hci_i2c_fw_work()
850 pn544_hci_i2c_fw_work_complete(phy, r); in pn544_hci_i2c_fw_work()
870 struct pn544_i2c_phy *phy; in pn544_hci_i2c_probe() local
878 phy = devm_kzalloc(&client->dev, sizeof(struct pn544_i2c_phy), in pn544_hci_i2c_probe()
880 if (!phy) in pn544_hci_i2c_probe()
883 INIT_WORK(&phy->fw_work, pn544_hci_i2c_fw_work); in pn544_hci_i2c_probe()
884 phy->fw_work_state = FW_WORK_STATE_IDLE; in pn544_hci_i2c_probe()
886 phy->i2c_dev = client; in pn544_hci_i2c_probe()
887 i2c_set_clientdata(client, phy); in pn544_hci_i2c_probe()
894 phy->gpiod_en = devm_gpiod_get(dev, "enable", GPIOD_OUT_LOW); in pn544_hci_i2c_probe()
895 if (IS_ERR(phy->gpiod_en)) { in pn544_hci_i2c_probe()
897 return PTR_ERR(phy->gpiod_en); in pn544_hci_i2c_probe()
901 phy->gpiod_fw = devm_gpiod_get(dev, "firmware", GPIOD_OUT_LOW); in pn544_hci_i2c_probe()
902 if (IS_ERR(phy->gpiod_fw)) { in pn544_hci_i2c_probe()
904 return PTR_ERR(phy->gpiod_fw); in pn544_hci_i2c_probe()
907 pn544_hci_i2c_platform_init(phy); in pn544_hci_i2c_probe()
912 PN544_HCI_I2C_DRIVER_NAME, phy); in pn544_hci_i2c_probe()
918 r = pn544_hci_probe(phy, &i2c_phy_ops, LLC_SHDLC_NAME, in pn544_hci_i2c_probe()
921 pn544_hci_i2c_fw_download, &phy->hdev); in pn544_hci_i2c_probe()
930 struct pn544_i2c_phy *phy = i2c_get_clientdata(client); in pn544_hci_i2c_remove() local
932 cancel_work_sync(&phy->fw_work); in pn544_hci_i2c_remove()
933 if (phy->fw_work_state != FW_WORK_STATE_IDLE) in pn544_hci_i2c_remove()
934 pn544_hci_i2c_fw_work_complete(phy, -ENODEV); in pn544_hci_i2c_remove()
936 pn544_hci_remove(phy->hdev); in pn544_hci_i2c_remove()
938 if (phy->powered) in pn544_hci_i2c_remove()
939 pn544_hci_i2c_disable(phy); in pn544_hci_i2c_remove()