Lines Matching refs:trf

457 static int trf7970a_cmd(struct trf7970a *trf, u8 opcode)  in trf7970a_cmd()  argument
462 dev_dbg(trf->dev, "cmd: 0x%x\n", cmd); in trf7970a_cmd()
464 ret = spi_write(trf->spi, &cmd, 1); in trf7970a_cmd()
466 dev_err(trf->dev, "%s - cmd: 0x%x, ret: %d\n", __func__, cmd, in trf7970a_cmd()
471 static int trf7970a_read(struct trf7970a *trf, u8 reg, u8 *val) in trf7970a_read() argument
476 ret = spi_write_then_read(trf->spi, &addr, 1, val, 1); in trf7970a_read()
478 dev_err(trf->dev, "%s - addr: 0x%x, ret: %d\n", __func__, addr, in trf7970a_read()
481 dev_dbg(trf->dev, "read(0x%x): 0x%x\n", addr, *val); in trf7970a_read()
486 static int trf7970a_read_cont(struct trf7970a *trf, u8 reg, u8 *buf, in trf7970a_read_cont() argument
494 dev_dbg(trf->dev, "read_cont(0x%x, %zd)\n", addr, len); in trf7970a_read_cont()
508 ret = spi_sync(trf->spi, &m); in trf7970a_read_cont()
510 dev_err(trf->dev, "%s - addr: 0x%x, ret: %d\n", __func__, addr, in trf7970a_read_cont()
515 static int trf7970a_write(struct trf7970a *trf, u8 reg, u8 val) in trf7970a_write() argument
520 dev_dbg(trf->dev, "write(0x%x): 0x%x\n", reg, val); in trf7970a_write()
522 ret = spi_write(trf->spi, buf, 2); in trf7970a_write()
524 dev_err(trf->dev, "%s - write: 0x%x 0x%x, ret: %d\n", __func__, in trf7970a_write()
530 static int trf7970a_read_irqstatus(struct trf7970a *trf, u8 *status) in trf7970a_read_irqstatus() argument
538 if (trf->quirks & TRF7970A_QUIRK_IRQ_STATUS_READ) { in trf7970a_read_irqstatus()
540 ret = spi_write_then_read(trf->spi, &addr, 1, buf, 2); in trf7970a_read_irqstatus()
542 ret = spi_write_then_read(trf->spi, &addr, 1, buf, 1); in trf7970a_read_irqstatus()
546 dev_err(trf->dev, "%s - irqstatus: Status read failed: %d\n", in trf7970a_read_irqstatus()
554 static int trf7970a_read_target_proto(struct trf7970a *trf, u8 *target_proto) in trf7970a_read_target_proto() argument
563 ret = spi_write_then_read(trf->spi, &addr, 1, buf, 2); in trf7970a_read_target_proto()
565 dev_err(trf->dev, "%s - target_proto: Read failed: %d\n", in trf7970a_read_target_proto()
573 static int trf7970a_mode_detect(struct trf7970a *trf, u8 *rf_tech) in trf7970a_mode_detect() argument
578 ret = trf7970a_read_target_proto(trf, &target_proto); in trf7970a_mode_detect()
596 dev_dbg(trf->dev, "%s - mode_detect: target_proto: 0x%x\n", in trf7970a_mode_detect()
606 static void trf7970a_send_upstream(struct trf7970a *trf) in trf7970a_send_upstream() argument
608 dev_kfree_skb_any(trf->tx_skb); in trf7970a_send_upstream()
609 trf->tx_skb = NULL; in trf7970a_send_upstream()
611 if (trf->rx_skb && !IS_ERR(trf->rx_skb) && !trf->aborting) in trf7970a_send_upstream()
613 16, 1, trf->rx_skb->data, trf->rx_skb->len, in trf7970a_send_upstream()
616 trf->state = TRF7970A_ST_IDLE; in trf7970a_send_upstream()
618 if (trf->aborting) { in trf7970a_send_upstream()
619 dev_dbg(trf->dev, "Abort process complete\n"); in trf7970a_send_upstream()
621 if (!IS_ERR(trf->rx_skb)) { in trf7970a_send_upstream()
622 kfree_skb(trf->rx_skb); in trf7970a_send_upstream()
623 trf->rx_skb = ERR_PTR(-ECANCELED); in trf7970a_send_upstream()
626 trf->aborting = false; in trf7970a_send_upstream()
629 trf->cb(trf->ddev, trf->cb_arg, trf->rx_skb); in trf7970a_send_upstream()
631 trf->rx_skb = NULL; in trf7970a_send_upstream()
634 static void trf7970a_send_err_upstream(struct trf7970a *trf, int errno) in trf7970a_send_err_upstream() argument
636 dev_dbg(trf->dev, "Error - state: %d, errno: %d\n", trf->state, errno); in trf7970a_send_err_upstream()
638 cancel_delayed_work(&trf->timeout_work); in trf7970a_send_err_upstream()
640 kfree_skb(trf->rx_skb); in trf7970a_send_err_upstream()
641 trf->rx_skb = ERR_PTR(errno); in trf7970a_send_err_upstream()
643 trf7970a_send_upstream(trf); in trf7970a_send_err_upstream()
646 static int trf7970a_transmit(struct trf7970a *trf, struct sk_buff *skb, in trf7970a_transmit() argument
670 ret = spi_sync(trf->spi, &m); in trf7970a_transmit()
672 dev_err(trf->dev, "%s - Can't send tx data: %d\n", __func__, in trf7970a_transmit()
680 trf->state = TRF7970A_ST_WAIT_FOR_TX_FIFO; in trf7970a_transmit()
683 if (trf->issue_eof) { in trf7970a_transmit()
684 trf->state = TRF7970A_ST_WAIT_TO_ISSUE_EOF; in trf7970a_transmit()
687 trf->state = TRF7970A_ST_WAIT_FOR_RX_DATA; in trf7970a_transmit()
689 if (!trf->timeout) in trf7970a_transmit()
692 timeout = trf->timeout; in trf7970a_transmit()
696 dev_dbg(trf->dev, "Setting timeout for %d ms, state: %d\n", timeout, in trf7970a_transmit()
697 trf->state); in trf7970a_transmit()
699 schedule_delayed_work(&trf->timeout_work, msecs_to_jiffies(timeout)); in trf7970a_transmit()
704 static void trf7970a_fill_fifo(struct trf7970a *trf) in trf7970a_fill_fifo() argument
706 struct sk_buff *skb = trf->tx_skb; in trf7970a_fill_fifo()
712 ret = trf7970a_read(trf, TRF7970A_FIFO_STATUS, &fifo_bytes); in trf7970a_fill_fifo()
714 trf7970a_send_err_upstream(trf, ret); in trf7970a_fill_fifo()
718 dev_dbg(trf->dev, "Filling FIFO - fifo_bytes: 0x%x\n", fifo_bytes); in trf7970a_fill_fifo()
725 schedule_delayed_work(&trf->timeout_work, in trf7970a_fill_fifo()
734 ret = trf7970a_transmit(trf, skb, len, &prefix, sizeof(prefix)); in trf7970a_fill_fifo()
736 trf7970a_send_err_upstream(trf, ret); in trf7970a_fill_fifo()
739 static void trf7970a_drain_fifo(struct trf7970a *trf, u8 status) in trf7970a_drain_fifo() argument
741 struct sk_buff *skb = trf->rx_skb; in trf7970a_drain_fifo()
746 trf7970a_send_err_upstream(trf, -EIO); in trf7970a_drain_fifo()
750 ret = trf7970a_read(trf, TRF7970A_FIFO_STATUS, &fifo_bytes); in trf7970a_drain_fifo()
752 trf7970a_send_err_upstream(trf, ret); in trf7970a_drain_fifo()
756 dev_dbg(trf->dev, "Draining FIFO - fifo_bytes: 0x%x\n", fifo_bytes); in trf7970a_drain_fifo()
769 trf7970a_send_err_upstream(trf, -ENOMEM); in trf7970a_drain_fifo()
773 kfree_skb(trf->rx_skb); in trf7970a_drain_fifo()
774 trf->rx_skb = skb; in trf7970a_drain_fifo()
777 ret = trf7970a_read_cont(trf, TRF7970A_FIFO_IO_REGISTER, in trf7970a_drain_fifo()
780 trf7970a_send_err_upstream(trf, ret); in trf7970a_drain_fifo()
785 if ((trf->framing == NFC_DIGITAL_FRAMING_NFCA_T2T) && (skb->len == 1) && in trf7970a_drain_fifo()
786 (trf->special_fcn_reg1 == TRF7970A_SPECIAL_FCN_REG1_4_BIT_RX)) { in trf7970a_drain_fifo()
790 trf->state = TRF7970A_ST_WAIT_FOR_RX_DATA_CONT; in trf7970a_drain_fifo()
792 ret = trf7970a_read(trf, TRF7970A_FIFO_STATUS, &fifo_bytes); in trf7970a_drain_fifo()
794 trf7970a_send_err_upstream(trf, ret); in trf7970a_drain_fifo()
810 trf7970a_send_upstream(trf); in trf7970a_drain_fifo()
814 dev_dbg(trf->dev, "Setting timeout for %d ms\n", in trf7970a_drain_fifo()
817 schedule_delayed_work(&trf->timeout_work, in trf7970a_drain_fifo()
823 struct trf7970a *trf = dev_id; in trf7970a_irq() local
827 mutex_lock(&trf->lock); in trf7970a_irq()
829 if (trf->state == TRF7970A_ST_RF_OFF) { in trf7970a_irq()
830 mutex_unlock(&trf->lock); in trf7970a_irq()
834 ret = trf7970a_read_irqstatus(trf, &status); in trf7970a_irq()
836 mutex_unlock(&trf->lock); in trf7970a_irq()
840 dev_dbg(trf->dev, "IRQ - state: %d, status: 0x%x\n", trf->state, in trf7970a_irq()
844 mutex_unlock(&trf->lock); in trf7970a_irq()
848 switch (trf->state) { in trf7970a_irq()
856 if (trf->is_initiator && (status & TRF7970A_IRQ_STATUS_ERROR)) { in trf7970a_irq()
857 trf7970a_cmd(trf, TRF7970A_CMD_BLOCK_RX); in trf7970a_irq()
858 trf->state = TRF7970A_ST_IDLE_RX_BLOCKED; in trf7970a_irq()
861 trf7970a_cmd(trf, TRF7970A_CMD_FIFO_RESET); in trf7970a_irq()
865 trf->ignore_timeout = in trf7970a_irq()
866 !cancel_delayed_work(&trf->timeout_work); in trf7970a_irq()
867 trf7970a_fill_fifo(trf); in trf7970a_irq()
869 trf7970a_send_err_upstream(trf, -EIO); in trf7970a_irq()
875 trf->ignore_timeout = in trf7970a_irq()
876 !cancel_delayed_work(&trf->timeout_work); in trf7970a_irq()
877 trf7970a_drain_fifo(trf, status); in trf7970a_irq()
879 ret = trf7970a_read(trf, TRF7970A_FIFO_STATUS, in trf7970a_irq()
885 trf7970a_send_err_upstream(trf, ret); in trf7970a_irq()
887 trf7970a_cmd(trf, TRF7970A_CMD_FIFO_RESET); in trf7970a_irq()
889 (!trf->is_initiator && in trf7970a_irq()
892 trf7970a_cmd(trf, TRF7970A_CMD_FIFO_RESET); in trf7970a_irq()
894 if (!trf->timeout) { in trf7970a_irq()
895 trf->ignore_timeout = in trf7970a_irq()
896 !cancel_delayed_work(&trf->timeout_work); in trf7970a_irq()
897 trf->rx_skb = ERR_PTR(0); in trf7970a_irq()
898 trf7970a_send_upstream(trf); in trf7970a_irq()
902 if (trf->is_initiator) in trf7970a_irq()
905 iso_ctrl = trf->iso_ctrl; in trf7970a_irq()
907 switch (trf->framing) { in trf7970a_irq()
909 trf->tx_cmd = TRF7970A_CMD_TRANSMIT_NO_CRC; in trf7970a_irq()
911 trf->iso_ctrl = 0xff; /* Force ISO_CTRL write */ in trf7970a_irq()
914 trf->tx_cmd = TRF7970A_CMD_TRANSMIT; in trf7970a_irq()
916 trf->iso_ctrl = 0xff; /* Force ISO_CTRL write */ in trf7970a_irq()
919 ret = trf7970a_write(trf, in trf7970a_irq()
925 trf->special_fcn_reg1 = in trf7970a_irq()
932 if (iso_ctrl != trf->iso_ctrl) { in trf7970a_irq()
933 ret = trf7970a_write(trf, TRF7970A_ISO_CTRL, in trf7970a_irq()
938 trf->iso_ctrl = iso_ctrl; in trf7970a_irq()
941 trf7970a_send_err_upstream(trf, -EIO); in trf7970a_irq()
946 trf7970a_send_err_upstream(trf, -EIO); in trf7970a_irq()
950 trf->ignore_timeout = in trf7970a_irq()
951 !cancel_delayed_work(&trf->timeout_work); in trf7970a_irq()
952 trf7970a_drain_fifo(trf, status); in trf7970a_irq()
954 trf7970a_send_err_upstream(trf, -EIO); in trf7970a_irq()
959 trf->ignore_timeout = in trf7970a_irq()
960 !cancel_delayed_work(&trf->timeout_work); in trf7970a_irq()
962 ret = trf7970a_mode_detect(trf, &trf->md_rf_tech); in trf7970a_irq()
964 trf7970a_send_err_upstream(trf, ret); in trf7970a_irq()
966 trf->state = TRF7970A_ST_LISTENING; in trf7970a_irq()
967 trf7970a_drain_fifo(trf, status); in trf7970a_irq()
970 trf7970a_send_err_upstream(trf, -EIO); in trf7970a_irq()
974 dev_err(trf->dev, "%s - Driver in invalid state: %d\n", in trf7970a_irq()
975 __func__, trf->state); in trf7970a_irq()
979 mutex_unlock(&trf->lock); in trf7970a_irq()
983 static void trf7970a_issue_eof(struct trf7970a *trf) in trf7970a_issue_eof() argument
987 dev_dbg(trf->dev, "Issuing EOF\n"); in trf7970a_issue_eof()
989 ret = trf7970a_cmd(trf, TRF7970A_CMD_FIFO_RESET); in trf7970a_issue_eof()
991 trf7970a_send_err_upstream(trf, ret); in trf7970a_issue_eof()
993 ret = trf7970a_cmd(trf, TRF7970A_CMD_EOF); in trf7970a_issue_eof()
995 trf7970a_send_err_upstream(trf, ret); in trf7970a_issue_eof()
997 trf->state = TRF7970A_ST_WAIT_FOR_RX_DATA; in trf7970a_issue_eof()
999 dev_dbg(trf->dev, "Setting timeout for %d ms, state: %d\n", in trf7970a_issue_eof()
1000 trf->timeout, trf->state); in trf7970a_issue_eof()
1002 schedule_delayed_work(&trf->timeout_work, in trf7970a_issue_eof()
1003 msecs_to_jiffies(trf->timeout)); in trf7970a_issue_eof()
1008 struct trf7970a *trf = container_of(work, struct trf7970a, in trf7970a_timeout_work_handler() local
1011 dev_dbg(trf->dev, "Timeout - state: %d, ignore_timeout: %d\n", in trf7970a_timeout_work_handler()
1012 trf->state, trf->ignore_timeout); in trf7970a_timeout_work_handler()
1014 mutex_lock(&trf->lock); in trf7970a_timeout_work_handler()
1016 if (trf->ignore_timeout) in trf7970a_timeout_work_handler()
1017 trf->ignore_timeout = false; in trf7970a_timeout_work_handler()
1018 else if (trf->state == TRF7970A_ST_WAIT_FOR_RX_DATA_CONT) in trf7970a_timeout_work_handler()
1019 trf7970a_drain_fifo(trf, TRF7970A_IRQ_STATUS_SRX); in trf7970a_timeout_work_handler()
1020 else if (trf->state == TRF7970A_ST_WAIT_TO_ISSUE_EOF) in trf7970a_timeout_work_handler()
1021 trf7970a_issue_eof(trf); in trf7970a_timeout_work_handler()
1023 trf7970a_send_err_upstream(trf, -ETIMEDOUT); in trf7970a_timeout_work_handler()
1025 mutex_unlock(&trf->lock); in trf7970a_timeout_work_handler()
1028 static int trf7970a_init(struct trf7970a *trf) in trf7970a_init() argument
1032 dev_dbg(trf->dev, "Initializing device - state: %d\n", trf->state); in trf7970a_init()
1034 ret = trf7970a_cmd(trf, TRF7970A_CMD_SOFT_INIT); in trf7970a_init()
1038 ret = trf7970a_cmd(trf, TRF7970A_CMD_IDLE); in trf7970a_init()
1042 ret = trf7970a_write(trf, TRF7970A_REG_IO_CTRL, in trf7970a_init()
1043 trf->io_ctrl | TRF7970A_REG_IO_CTRL_VRS(0x1)); in trf7970a_init()
1047 ret = trf7970a_write(trf, TRF7970A_NFC_TARGET_LEVEL, 0); in trf7970a_init()
1053 trf->chip_status_ctrl &= ~TRF7970A_CHIP_STATUS_RF_ON; in trf7970a_init()
1055 ret = trf7970a_write(trf, TRF7970A_MODULATOR_SYS_CLK_CTRL, in trf7970a_init()
1056 trf->modulator_sys_clk_ctrl); in trf7970a_init()
1060 ret = trf7970a_write(trf, TRF7970A_ADJUTABLE_FIFO_IRQ_LEVELS, in trf7970a_init()
1066 ret = trf7970a_write(trf, TRF7970A_SPECIAL_FCN_REG1, 0); in trf7970a_init()
1070 trf->special_fcn_reg1 = 0; in trf7970a_init()
1072 trf->iso_ctrl = 0xff; in trf7970a_init()
1076 dev_dbg(trf->dev, "Couldn't init device: %d\n", ret); in trf7970a_init()
1080 static void trf7970a_switch_rf_off(struct trf7970a *trf) in trf7970a_switch_rf_off() argument
1082 if ((trf->state == TRF7970A_ST_PWR_OFF) || in trf7970a_switch_rf_off()
1083 (trf->state == TRF7970A_ST_RF_OFF)) in trf7970a_switch_rf_off()
1086 dev_dbg(trf->dev, "Switching rf off\n"); in trf7970a_switch_rf_off()
1088 trf->chip_status_ctrl &= ~TRF7970A_CHIP_STATUS_RF_ON; in trf7970a_switch_rf_off()
1090 trf7970a_write(trf, TRF7970A_CHIP_STATUS_CTRL, trf->chip_status_ctrl); in trf7970a_switch_rf_off()
1092 trf->aborting = false; in trf7970a_switch_rf_off()
1093 trf->state = TRF7970A_ST_RF_OFF; in trf7970a_switch_rf_off()
1095 pm_runtime_mark_last_busy(trf->dev); in trf7970a_switch_rf_off()
1096 pm_runtime_put_autosuspend(trf->dev); in trf7970a_switch_rf_off()
1099 static int trf7970a_switch_rf_on(struct trf7970a *trf) in trf7970a_switch_rf_on() argument
1103 dev_dbg(trf->dev, "Switching rf on\n"); in trf7970a_switch_rf_on()
1105 pm_runtime_get_sync(trf->dev); in trf7970a_switch_rf_on()
1107 if (trf->state != TRF7970A_ST_RF_OFF) { /* Power on, RF off */ in trf7970a_switch_rf_on()
1108 dev_err(trf->dev, "%s - Incorrect state: %d\n", __func__, in trf7970a_switch_rf_on()
1109 trf->state); in trf7970a_switch_rf_on()
1113 ret = trf7970a_init(trf); in trf7970a_switch_rf_on()
1115 dev_err(trf->dev, "%s - Can't initialize: %d\n", __func__, ret); in trf7970a_switch_rf_on()
1119 trf->state = TRF7970A_ST_IDLE; in trf7970a_switch_rf_on()
1126 struct trf7970a *trf = nfc_digital_get_drvdata(ddev); in trf7970a_switch_rf() local
1129 dev_dbg(trf->dev, "Switching RF - state: %d, on: %d\n", trf->state, on); in trf7970a_switch_rf()
1131 mutex_lock(&trf->lock); in trf7970a_switch_rf()
1134 switch (trf->state) { in trf7970a_switch_rf()
1137 ret = trf7970a_switch_rf_on(trf); in trf7970a_switch_rf()
1143 dev_err(trf->dev, "%s - Invalid request: %d %d\n", in trf7970a_switch_rf()
1144 __func__, trf->state, on); in trf7970a_switch_rf()
1145 trf7970a_switch_rf_off(trf); in trf7970a_switch_rf()
1149 switch (trf->state) { in trf7970a_switch_rf()
1154 dev_err(trf->dev, "%s - Invalid request: %d %d\n", in trf7970a_switch_rf()
1155 __func__, trf->state, on); in trf7970a_switch_rf()
1162 trf7970a_switch_rf_off(trf); in trf7970a_switch_rf()
1166 mutex_unlock(&trf->lock); in trf7970a_switch_rf()
1170 static int trf7970a_in_config_rf_tech(struct trf7970a *trf, int tech) in trf7970a_in_config_rf_tech() argument
1174 dev_dbg(trf->dev, "rf technology: %d\n", tech); in trf7970a_in_config_rf_tech()
1178 trf->iso_ctrl_tech = TRF7970A_ISO_CTRL_14443A_106; in trf7970a_in_config_rf_tech()
1179 trf->modulator_sys_clk_ctrl = in trf7970a_in_config_rf_tech()
1180 (trf->modulator_sys_clk_ctrl & 0xf8) | in trf7970a_in_config_rf_tech()
1182 trf->guard_time = TRF7970A_GUARD_TIME_NFCA; in trf7970a_in_config_rf_tech()
1185 trf->iso_ctrl_tech = TRF7970A_ISO_CTRL_14443B_106; in trf7970a_in_config_rf_tech()
1186 trf->modulator_sys_clk_ctrl = in trf7970a_in_config_rf_tech()
1187 (trf->modulator_sys_clk_ctrl & 0xf8) | in trf7970a_in_config_rf_tech()
1189 trf->guard_time = TRF7970A_GUARD_TIME_NFCB; in trf7970a_in_config_rf_tech()
1192 trf->iso_ctrl_tech = TRF7970A_ISO_CTRL_FELICA_212; in trf7970a_in_config_rf_tech()
1193 trf->modulator_sys_clk_ctrl = in trf7970a_in_config_rf_tech()
1194 (trf->modulator_sys_clk_ctrl & 0xf8) | in trf7970a_in_config_rf_tech()
1196 trf->guard_time = TRF7970A_GUARD_TIME_NFCF; in trf7970a_in_config_rf_tech()
1199 trf->iso_ctrl_tech = TRF7970A_ISO_CTRL_FELICA_424; in trf7970a_in_config_rf_tech()
1200 trf->modulator_sys_clk_ctrl = in trf7970a_in_config_rf_tech()
1201 (trf->modulator_sys_clk_ctrl & 0xf8) | in trf7970a_in_config_rf_tech()
1203 trf->guard_time = TRF7970A_GUARD_TIME_NFCF; in trf7970a_in_config_rf_tech()
1206 trf->iso_ctrl_tech = TRF7970A_ISO_CTRL_15693_SGL_1OF4_2648; in trf7970a_in_config_rf_tech()
1207 trf->modulator_sys_clk_ctrl = in trf7970a_in_config_rf_tech()
1208 (trf->modulator_sys_clk_ctrl & 0xf8) | in trf7970a_in_config_rf_tech()
1210 trf->guard_time = TRF7970A_GUARD_TIME_15693; in trf7970a_in_config_rf_tech()
1213 dev_dbg(trf->dev, "Unsupported rf technology: %d\n", tech); in trf7970a_in_config_rf_tech()
1217 trf->technology = tech; in trf7970a_in_config_rf_tech()
1224 if (trf->iso_ctrl == 0xff) in trf7970a_in_config_rf_tech()
1225 ret = trf7970a_write(trf, TRF7970A_NFC_TARGET_LEVEL, 0); in trf7970a_in_config_rf_tech()
1230 static int trf7970a_is_rf_field(struct trf7970a *trf, bool *is_rf_field) in trf7970a_is_rf_field() argument
1235 ret = trf7970a_write(trf, TRF7970A_CHIP_STATUS_CTRL, in trf7970a_is_rf_field()
1236 trf->chip_status_ctrl | in trf7970a_is_rf_field()
1241 ret = trf7970a_cmd(trf, TRF7970A_CMD_TEST_EXT_RF); in trf7970a_is_rf_field()
1247 ret = trf7970a_read(trf, TRF7970A_RSSI_OSC_STATUS, &rssi); in trf7970a_is_rf_field()
1251 ret = trf7970a_write(trf, TRF7970A_CHIP_STATUS_CTRL, in trf7970a_is_rf_field()
1252 trf->chip_status_ctrl); in trf7970a_is_rf_field()
1264 static int trf7970a_in_config_framing(struct trf7970a *trf, int framing) in trf7970a_in_config_framing() argument
1266 u8 iso_ctrl = trf->iso_ctrl_tech; in trf7970a_in_config_framing()
1270 dev_dbg(trf->dev, "framing: %d\n", framing); in trf7970a_in_config_framing()
1275 trf->tx_cmd = TRF7970A_CMD_TRANSMIT_NO_CRC; in trf7970a_in_config_framing()
1288 trf->tx_cmd = TRF7970A_CMD_TRANSMIT; in trf7970a_in_config_framing()
1292 trf->tx_cmd = TRF7970A_CMD_TRANSMIT; in trf7970a_in_config_framing()
1296 dev_dbg(trf->dev, "Unsupported Framing: %d\n", framing); in trf7970a_in_config_framing()
1300 trf->framing = framing; in trf7970a_in_config_framing()
1302 if (!(trf->chip_status_ctrl & TRF7970A_CHIP_STATUS_RF_ON)) { in trf7970a_in_config_framing()
1303 ret = trf7970a_is_rf_field(trf, &is_rf_field); in trf7970a_in_config_framing()
1311 if (iso_ctrl != trf->iso_ctrl) { in trf7970a_in_config_framing()
1312 ret = trf7970a_write(trf, TRF7970A_ISO_CTRL, iso_ctrl); in trf7970a_in_config_framing()
1316 trf->iso_ctrl = iso_ctrl; in trf7970a_in_config_framing()
1318 ret = trf7970a_write(trf, TRF7970A_MODULATOR_SYS_CLK_CTRL, in trf7970a_in_config_framing()
1319 trf->modulator_sys_clk_ctrl); in trf7970a_in_config_framing()
1324 if (!(trf->chip_status_ctrl & TRF7970A_CHIP_STATUS_RF_ON)) { in trf7970a_in_config_framing()
1325 ret = trf7970a_write(trf, TRF7970A_CHIP_STATUS_CTRL, in trf7970a_in_config_framing()
1326 trf->chip_status_ctrl | in trf7970a_in_config_framing()
1331 trf->chip_status_ctrl |= TRF7970A_CHIP_STATUS_RF_ON; in trf7970a_in_config_framing()
1333 usleep_range(trf->guard_time, trf->guard_time + 1000); in trf7970a_in_config_framing()
1342 struct trf7970a *trf = nfc_digital_get_drvdata(ddev); in trf7970a_in_configure_hw() local
1345 dev_dbg(trf->dev, "Configure hw - type: %d, param: %d\n", type, param); in trf7970a_in_configure_hw()
1347 mutex_lock(&trf->lock); in trf7970a_in_configure_hw()
1349 trf->is_initiator = true; in trf7970a_in_configure_hw()
1351 if ((trf->state == TRF7970A_ST_PWR_OFF) || in trf7970a_in_configure_hw()
1352 (trf->state == TRF7970A_ST_RF_OFF)) { in trf7970a_in_configure_hw()
1353 ret = trf7970a_switch_rf_on(trf); in trf7970a_in_configure_hw()
1360 ret = trf7970a_in_config_rf_tech(trf, param); in trf7970a_in_configure_hw()
1363 ret = trf7970a_in_config_framing(trf, param); in trf7970a_in_configure_hw()
1366 dev_dbg(trf->dev, "Unknown type: %d\n", type); in trf7970a_in_configure_hw()
1371 mutex_unlock(&trf->lock); in trf7970a_in_configure_hw()
1391 static int trf7970a_per_cmd_config(struct trf7970a *trf, in trf7970a_per_cmd_config() argument
1398 trf->issue_eof = false; in trf7970a_per_cmd_config()
1409 if ((trf->technology == NFC_DIGITAL_RF_TECH_106A) && in trf7970a_per_cmd_config()
1410 (trf->framing == NFC_DIGITAL_FRAMING_NFCA_T2T)) { in trf7970a_per_cmd_config()
1416 if (special_fcn_reg1 != trf->special_fcn_reg1) { in trf7970a_per_cmd_config()
1417 ret = trf7970a_write(trf, TRF7970A_SPECIAL_FCN_REG1, in trf7970a_per_cmd_config()
1422 trf->special_fcn_reg1 = special_fcn_reg1; in trf7970a_per_cmd_config()
1424 } else if (trf->technology == NFC_DIGITAL_RF_TECH_ISO15693) { in trf7970a_per_cmd_config()
1425 iso_ctrl = trf->iso_ctrl & ~TRF7970A_ISO_CTRL_RFID_SPEED_MASK; in trf7970a_per_cmd_config()
1443 if (iso_ctrl != trf->iso_ctrl) { in trf7970a_per_cmd_config()
1444 ret = trf7970a_write(trf, TRF7970A_ISO_CTRL, iso_ctrl); in trf7970a_per_cmd_config()
1448 trf->iso_ctrl = iso_ctrl; in trf7970a_per_cmd_config()
1451 if ((trf->framing == NFC_DIGITAL_FRAMING_ISO15693_T5T) && in trf7970a_per_cmd_config()
1454 trf->issue_eof = true; in trf7970a_per_cmd_config()
1464 struct trf7970a *trf = nfc_digital_get_drvdata(ddev); in trf7970a_send_cmd() local
1470 dev_dbg(trf->dev, "New request - state: %d, timeout: %d ms, len: %d\n", in trf7970a_send_cmd()
1471 trf->state, timeout, skb->len); in trf7970a_send_cmd()
1476 mutex_lock(&trf->lock); in trf7970a_send_cmd()
1478 if ((trf->state != TRF7970A_ST_IDLE) && in trf7970a_send_cmd()
1479 (trf->state != TRF7970A_ST_IDLE_RX_BLOCKED)) { in trf7970a_send_cmd()
1480 dev_err(trf->dev, "%s - Bogus state: %d\n", __func__, in trf7970a_send_cmd()
1481 trf->state); in trf7970a_send_cmd()
1486 if (trf->aborting) { in trf7970a_send_cmd()
1487 dev_dbg(trf->dev, "Abort process complete\n"); in trf7970a_send_cmd()
1488 trf->aborting = false; in trf7970a_send_cmd()
1494 trf->rx_skb = nfc_alloc_recv_skb(TRF7970A_RX_SKB_ALLOC_SIZE, in trf7970a_send_cmd()
1496 if (!trf->rx_skb) { in trf7970a_send_cmd()
1497 dev_dbg(trf->dev, "Can't alloc rx_skb\n"); in trf7970a_send_cmd()
1503 if (trf->state == TRF7970A_ST_IDLE_RX_BLOCKED) { in trf7970a_send_cmd()
1504 ret = trf7970a_cmd(trf, TRF7970A_CMD_ENABLE_RX); in trf7970a_send_cmd()
1508 trf->state = TRF7970A_ST_IDLE; in trf7970a_send_cmd()
1511 if (trf->is_initiator) { in trf7970a_send_cmd()
1512 ret = trf7970a_per_cmd_config(trf, skb); in trf7970a_send_cmd()
1517 trf->ddev = ddev; in trf7970a_send_cmd()
1518 trf->tx_skb = skb; in trf7970a_send_cmd()
1519 trf->cb = cb; in trf7970a_send_cmd()
1520 trf->cb_arg = arg; in trf7970a_send_cmd()
1521 trf->timeout = timeout; in trf7970a_send_cmd()
1522 trf->ignore_timeout = false; in trf7970a_send_cmd()
1534 TRF7970A_CMD_BIT_OPCODE(trf->tx_cmd); in trf7970a_send_cmd()
1537 if (trf->framing == NFC_DIGITAL_FRAMING_NFCA_SHORT) { in trf7970a_send_cmd()
1549 ret = trf7970a_read_irqstatus(trf, &status); in trf7970a_send_cmd()
1553 ret = trf7970a_transmit(trf, skb, len, prefix, sizeof(prefix)); in trf7970a_send_cmd()
1555 kfree_skb(trf->rx_skb); in trf7970a_send_cmd()
1556 trf->rx_skb = NULL; in trf7970a_send_cmd()
1560 mutex_unlock(&trf->lock); in trf7970a_send_cmd()
1564 static int trf7970a_tg_config_rf_tech(struct trf7970a *trf, int tech) in trf7970a_tg_config_rf_tech() argument
1568 dev_dbg(trf->dev, "rf technology: %d\n", tech); in trf7970a_tg_config_rf_tech()
1572 trf->iso_ctrl_tech = TRF7970A_ISO_CTRL_NFC_NFC_CE_MODE | in trf7970a_tg_config_rf_tech()
1574 trf->modulator_sys_clk_ctrl = in trf7970a_tg_config_rf_tech()
1575 (trf->modulator_sys_clk_ctrl & 0xf8) | in trf7970a_tg_config_rf_tech()
1579 trf->iso_ctrl_tech = TRF7970A_ISO_CTRL_NFC_NFC_CE_MODE | in trf7970a_tg_config_rf_tech()
1581 trf->modulator_sys_clk_ctrl = in trf7970a_tg_config_rf_tech()
1582 (trf->modulator_sys_clk_ctrl & 0xf8) | in trf7970a_tg_config_rf_tech()
1586 trf->iso_ctrl_tech = TRF7970A_ISO_CTRL_NFC_NFC_CE_MODE | in trf7970a_tg_config_rf_tech()
1588 trf->modulator_sys_clk_ctrl = in trf7970a_tg_config_rf_tech()
1589 (trf->modulator_sys_clk_ctrl & 0xf8) | in trf7970a_tg_config_rf_tech()
1593 dev_dbg(trf->dev, "Unsupported rf technology: %d\n", tech); in trf7970a_tg_config_rf_tech()
1597 trf->technology = tech; in trf7970a_tg_config_rf_tech()
1606 if ((trf->framing == NFC_DIGITAL_FRAMING_NFC_DEP_ACTIVATED) && in trf7970a_tg_config_rf_tech()
1607 (trf->iso_ctrl_tech != trf->iso_ctrl)) { in trf7970a_tg_config_rf_tech()
1608 ret = trf7970a_write(trf, TRF7970A_ISO_CTRL, in trf7970a_tg_config_rf_tech()
1609 trf->iso_ctrl_tech); in trf7970a_tg_config_rf_tech()
1611 trf->iso_ctrl = trf->iso_ctrl_tech; in trf7970a_tg_config_rf_tech()
1623 static int trf7970a_tg_config_framing(struct trf7970a *trf, int framing) in trf7970a_tg_config_framing() argument
1625 u8 iso_ctrl = trf->iso_ctrl_tech; in trf7970a_tg_config_framing()
1628 dev_dbg(trf->dev, "framing: %d\n", framing); in trf7970a_tg_config_framing()
1632 trf->tx_cmd = TRF7970A_CMD_TRANSMIT_NO_CRC; in trf7970a_tg_config_framing()
1639 iso_ctrl = trf->iso_ctrl; /* Don't write to ISO_CTRL yet */ in trf7970a_tg_config_framing()
1642 trf->tx_cmd = TRF7970A_CMD_TRANSMIT; in trf7970a_tg_config_framing()
1646 trf->tx_cmd = TRF7970A_CMD_TRANSMIT; in trf7970a_tg_config_framing()
1650 dev_dbg(trf->dev, "Unsupported Framing: %d\n", framing); in trf7970a_tg_config_framing()
1654 trf->framing = framing; in trf7970a_tg_config_framing()
1656 if (iso_ctrl != trf->iso_ctrl) { in trf7970a_tg_config_framing()
1657 ret = trf7970a_write(trf, TRF7970A_ISO_CTRL, iso_ctrl); in trf7970a_tg_config_framing()
1661 trf->iso_ctrl = iso_ctrl; in trf7970a_tg_config_framing()
1663 ret = trf7970a_write(trf, TRF7970A_MODULATOR_SYS_CLK_CTRL, in trf7970a_tg_config_framing()
1664 trf->modulator_sys_clk_ctrl); in trf7970a_tg_config_framing()
1669 if (!(trf->chip_status_ctrl & TRF7970A_CHIP_STATUS_RF_ON)) { in trf7970a_tg_config_framing()
1670 ret = trf7970a_write(trf, TRF7970A_CHIP_STATUS_CTRL, in trf7970a_tg_config_framing()
1671 trf->chip_status_ctrl | in trf7970a_tg_config_framing()
1676 trf->chip_status_ctrl |= TRF7970A_CHIP_STATUS_RF_ON; in trf7970a_tg_config_framing()
1685 struct trf7970a *trf = nfc_digital_get_drvdata(ddev); in trf7970a_tg_configure_hw() local
1688 dev_dbg(trf->dev, "Configure hw - type: %d, param: %d\n", type, param); in trf7970a_tg_configure_hw()
1690 mutex_lock(&trf->lock); in trf7970a_tg_configure_hw()
1692 trf->is_initiator = false; in trf7970a_tg_configure_hw()
1694 if ((trf->state == TRF7970A_ST_PWR_OFF) || in trf7970a_tg_configure_hw()
1695 (trf->state == TRF7970A_ST_RF_OFF)) { in trf7970a_tg_configure_hw()
1696 ret = trf7970a_switch_rf_on(trf); in trf7970a_tg_configure_hw()
1703 ret = trf7970a_tg_config_rf_tech(trf, param); in trf7970a_tg_configure_hw()
1706 ret = trf7970a_tg_config_framing(trf, param); in trf7970a_tg_configure_hw()
1709 dev_dbg(trf->dev, "Unknown type: %d\n", type); in trf7970a_tg_configure_hw()
1714 mutex_unlock(&trf->lock); in trf7970a_tg_configure_hw()
1722 struct trf7970a *trf = nfc_digital_get_drvdata(ddev); in _trf7970a_tg_listen() local
1725 mutex_lock(&trf->lock); in _trf7970a_tg_listen()
1727 if ((trf->state != TRF7970A_ST_IDLE) && in _trf7970a_tg_listen()
1728 (trf->state != TRF7970A_ST_IDLE_RX_BLOCKED)) { in _trf7970a_tg_listen()
1729 dev_err(trf->dev, "%s - Bogus state: %d\n", __func__, in _trf7970a_tg_listen()
1730 trf->state); in _trf7970a_tg_listen()
1735 if (trf->aborting) { in _trf7970a_tg_listen()
1736 dev_dbg(trf->dev, "Abort process complete\n"); in _trf7970a_tg_listen()
1737 trf->aborting = false; in _trf7970a_tg_listen()
1742 trf->rx_skb = nfc_alloc_recv_skb(TRF7970A_RX_SKB_ALLOC_SIZE, in _trf7970a_tg_listen()
1744 if (!trf->rx_skb) { in _trf7970a_tg_listen()
1745 dev_dbg(trf->dev, "Can't alloc rx_skb\n"); in _trf7970a_tg_listen()
1750 ret = trf7970a_write(trf, TRF7970A_RX_SPECIAL_SETTINGS, in _trf7970a_tg_listen()
1758 ret = trf7970a_write(trf, TRF7970A_REG_IO_CTRL, in _trf7970a_tg_listen()
1759 trf->io_ctrl | TRF7970A_REG_IO_CTRL_VRS(0x1)); in _trf7970a_tg_listen()
1763 ret = trf7970a_write(trf, TRF7970A_NFC_LOW_FIELD_LEVEL, in _trf7970a_tg_listen()
1768 ret = trf7970a_write(trf, TRF7970A_NFC_TARGET_LEVEL, in _trf7970a_tg_listen()
1773 trf->ddev = ddev; in _trf7970a_tg_listen()
1774 trf->cb = cb; in _trf7970a_tg_listen()
1775 trf->cb_arg = arg; in _trf7970a_tg_listen()
1776 trf->timeout = timeout; in _trf7970a_tg_listen()
1777 trf->ignore_timeout = false; in _trf7970a_tg_listen()
1779 ret = trf7970a_cmd(trf, TRF7970A_CMD_ENABLE_RX); in _trf7970a_tg_listen()
1783 trf->state = mode_detect ? TRF7970A_ST_LISTENING_MD : in _trf7970a_tg_listen()
1786 schedule_delayed_work(&trf->timeout_work, msecs_to_jiffies(timeout)); in _trf7970a_tg_listen()
1789 mutex_unlock(&trf->lock); in _trf7970a_tg_listen()
1796 const struct trf7970a *trf = nfc_digital_get_drvdata(ddev); in trf7970a_tg_listen() local
1798 dev_dbg(trf->dev, "Listen - state: %d, timeout: %d ms\n", in trf7970a_tg_listen()
1799 trf->state, timeout); in trf7970a_tg_listen()
1808 const struct trf7970a *trf = nfc_digital_get_drvdata(ddev); in trf7970a_tg_listen_md() local
1811 dev_dbg(trf->dev, "Listen MD - state: %d, timeout: %d ms\n", in trf7970a_tg_listen_md()
1812 trf->state, timeout); in trf7970a_tg_listen_md()
1829 const struct trf7970a *trf = nfc_digital_get_drvdata(ddev); in trf7970a_tg_get_rf_tech() local
1831 dev_dbg(trf->dev, "Get RF Tech - state: %d, rf_tech: %d\n", in trf7970a_tg_get_rf_tech()
1832 trf->state, trf->md_rf_tech); in trf7970a_tg_get_rf_tech()
1834 *rf_tech = trf->md_rf_tech; in trf7970a_tg_get_rf_tech()
1841 struct trf7970a *trf = nfc_digital_get_drvdata(ddev); in trf7970a_abort_cmd() local
1843 dev_dbg(trf->dev, "Abort process initiated\n"); in trf7970a_abort_cmd()
1845 mutex_lock(&trf->lock); in trf7970a_abort_cmd()
1847 switch (trf->state) { in trf7970a_abort_cmd()
1852 trf->aborting = true; in trf7970a_abort_cmd()
1855 trf->ignore_timeout = !cancel_delayed_work(&trf->timeout_work); in trf7970a_abort_cmd()
1856 trf7970a_send_err_upstream(trf, -ECANCELED); in trf7970a_abort_cmd()
1857 dev_dbg(trf->dev, "Abort process complete\n"); in trf7970a_abort_cmd()
1863 mutex_unlock(&trf->lock); in trf7970a_abort_cmd()
1878 static int trf7970a_power_up(struct trf7970a *trf) in trf7970a_power_up() argument
1882 dev_dbg(trf->dev, "Powering up - state: %d\n", trf->state); in trf7970a_power_up()
1884 if (trf->state != TRF7970A_ST_PWR_OFF) in trf7970a_power_up()
1887 ret = regulator_enable(trf->vin_regulator); in trf7970a_power_up()
1889 dev_err(trf->dev, "%s - Can't enable VIN: %d\n", __func__, ret); in trf7970a_power_up()
1895 if (trf->en2_gpiod && in trf7970a_power_up()
1896 !(trf->quirks & TRF7970A_QUIRK_EN2_MUST_STAY_LOW)) { in trf7970a_power_up()
1897 gpiod_set_value_cansleep(trf->en2_gpiod, 1); in trf7970a_power_up()
1901 gpiod_set_value_cansleep(trf->en_gpiod, 1); in trf7970a_power_up()
1905 trf->state = TRF7970A_ST_RF_OFF; in trf7970a_power_up()
1910 static int trf7970a_power_down(struct trf7970a *trf) in trf7970a_power_down() argument
1914 dev_dbg(trf->dev, "Powering down - state: %d\n", trf->state); in trf7970a_power_down()
1916 if (trf->state == TRF7970A_ST_PWR_OFF) in trf7970a_power_down()
1919 if (trf->state != TRF7970A_ST_RF_OFF) { in trf7970a_power_down()
1920 dev_dbg(trf->dev, "Can't power down - not RF_OFF state (%d)\n", in trf7970a_power_down()
1921 trf->state); in trf7970a_power_down()
1925 gpiod_set_value_cansleep(trf->en_gpiod, 0); in trf7970a_power_down()
1927 if (trf->en2_gpiod && !(trf->quirks & TRF7970A_QUIRK_EN2_MUST_STAY_LOW)) in trf7970a_power_down()
1928 gpiod_set_value_cansleep(trf->en2_gpiod, 0); in trf7970a_power_down()
1930 ret = regulator_disable(trf->vin_regulator); in trf7970a_power_down()
1932 dev_err(trf->dev, "%s - Can't disable VIN: %d\n", __func__, in trf7970a_power_down()
1935 trf->state = TRF7970A_ST_PWR_OFF; in trf7970a_power_down()
1940 static int trf7970a_startup(struct trf7970a *trf) in trf7970a_startup() argument
1944 ret = trf7970a_power_up(trf); in trf7970a_startup()
1948 pm_runtime_set_active(trf->dev); in trf7970a_startup()
1949 pm_runtime_enable(trf->dev); in trf7970a_startup()
1950 pm_runtime_mark_last_busy(trf->dev); in trf7970a_startup()
1955 static void trf7970a_shutdown(struct trf7970a *trf) in trf7970a_shutdown() argument
1957 switch (trf->state) { in trf7970a_shutdown()
1963 trf7970a_send_err_upstream(trf, -ECANCELED); in trf7970a_shutdown()
1967 trf7970a_switch_rf_off(trf); in trf7970a_shutdown()
1973 pm_runtime_disable(trf->dev); in trf7970a_shutdown()
1974 pm_runtime_set_suspended(trf->dev); in trf7970a_shutdown()
1976 trf7970a_power_down(trf); in trf7970a_shutdown()
1993 struct trf7970a *trf; in trf7970a_probe() local
2002 trf = devm_kzalloc(&spi->dev, sizeof(*trf), GFP_KERNEL); in trf7970a_probe()
2003 if (!trf) in trf7970a_probe()
2006 trf->state = TRF7970A_ST_PWR_OFF; in trf7970a_probe()
2007 trf->dev = &spi->dev; in trf7970a_probe()
2008 trf->spi = spi; in trf7970a_probe()
2015 dev_err(trf->dev, "Can't set up SPI Communication\n"); in trf7970a_probe()
2020 trf->quirks |= TRF7970A_QUIRK_IRQ_STATUS_READ; in trf7970a_probe()
2023 trf->en_gpiod = devm_gpiod_get_index(trf->dev, "ti,enable", 0, in trf7970a_probe()
2025 if (IS_ERR(trf->en_gpiod)) { in trf7970a_probe()
2026 dev_err(trf->dev, "No EN GPIO property\n"); in trf7970a_probe()
2027 return PTR_ERR(trf->en_gpiod); in trf7970a_probe()
2030 trf->en2_gpiod = devm_gpiod_get_index_optional(trf->dev, "ti,enable", 1, in trf7970a_probe()
2032 if (!trf->en2_gpiod) { in trf7970a_probe()
2033 dev_info(trf->dev, "No EN2 GPIO property\n"); in trf7970a_probe()
2034 } else if (IS_ERR(trf->en2_gpiod)) { in trf7970a_probe()
2035 dev_err(trf->dev, "Error getting EN2 GPIO property: %ld\n", in trf7970a_probe()
2036 PTR_ERR(trf->en2_gpiod)); in trf7970a_probe()
2037 return PTR_ERR(trf->en2_gpiod); in trf7970a_probe()
2039 trf->quirks |= TRF7970A_QUIRK_EN2_MUST_STAY_LOW; in trf7970a_probe()
2045 dev_err(trf->dev, in trf7970a_probe()
2051 trf->modulator_sys_clk_ctrl = TRF7970A_MODULATOR_27MHZ; in trf7970a_probe()
2052 dev_dbg(trf->dev, "trf7970a configured for 27MHz crystal\n"); in trf7970a_probe()
2054 trf->modulator_sys_clk_ctrl = 0; in trf7970a_probe()
2057 ret = devm_request_threaded_irq(trf->dev, spi->irq, NULL, in trf7970a_probe()
2060 "trf7970a", trf); in trf7970a_probe()
2062 dev_err(trf->dev, "Can't request IRQ#%d: %d\n", spi->irq, ret); in trf7970a_probe()
2066 mutex_init(&trf->lock); in trf7970a_probe()
2067 INIT_DELAYED_WORK(&trf->timeout_work, trf7970a_timeout_work_handler); in trf7970a_probe()
2069 trf->vin_regulator = devm_regulator_get(&spi->dev, "vin"); in trf7970a_probe()
2070 if (IS_ERR(trf->vin_regulator)) { in trf7970a_probe()
2071 ret = PTR_ERR(trf->vin_regulator); in trf7970a_probe()
2072 dev_err(trf->dev, "Can't get VIN regulator: %d\n", ret); in trf7970a_probe()
2076 ret = regulator_enable(trf->vin_regulator); in trf7970a_probe()
2078 dev_err(trf->dev, "Can't enable VIN: %d\n", ret); in trf7970a_probe()
2082 uvolts = regulator_get_voltage(trf->vin_regulator); in trf7970a_probe()
2084 trf->chip_status_ctrl = TRF7970A_CHIP_STATUS_VRS5_3; in trf7970a_probe()
2086 trf->vddio_regulator = devm_regulator_get(&spi->dev, "vdd-io"); in trf7970a_probe()
2087 if (IS_ERR(trf->vddio_regulator)) { in trf7970a_probe()
2088 ret = PTR_ERR(trf->vddio_regulator); in trf7970a_probe()
2089 dev_err(trf->dev, "Can't get VDD_IO regulator: %d\n", ret); in trf7970a_probe()
2093 ret = regulator_enable(trf->vddio_regulator); in trf7970a_probe()
2095 dev_err(trf->dev, "Can't enable VDD_IO: %d\n", ret); in trf7970a_probe()
2099 if (regulator_get_voltage(trf->vddio_regulator) == 1800000) { in trf7970a_probe()
2100 trf->io_ctrl = TRF7970A_REG_IO_CTRL_IO_LOW; in trf7970a_probe()
2101 dev_dbg(trf->dev, "trf7970a config vdd_io to 1.8V\n"); in trf7970a_probe()
2104 trf->ddev = nfc_digital_allocate_device(&trf7970a_nfc_ops, in trf7970a_probe()
2109 if (!trf->ddev) { in trf7970a_probe()
2110 dev_err(trf->dev, "Can't allocate NFC digital device\n"); in trf7970a_probe()
2115 nfc_digital_set_parent_dev(trf->ddev, trf->dev); in trf7970a_probe()
2116 nfc_digital_set_drvdata(trf->ddev, trf); in trf7970a_probe()
2117 spi_set_drvdata(spi, trf); in trf7970a_probe()
2121 pm_runtime_set_autosuspend_delay(trf->dev, autosuspend_delay); in trf7970a_probe()
2122 pm_runtime_use_autosuspend(trf->dev); in trf7970a_probe()
2124 ret = trf7970a_startup(trf); in trf7970a_probe()
2128 ret = nfc_digital_register_device(trf->ddev); in trf7970a_probe()
2130 dev_err(trf->dev, "Can't register NFC digital device: %d\n", in trf7970a_probe()
2138 trf7970a_shutdown(trf); in trf7970a_probe()
2140 nfc_digital_free_device(trf->ddev); in trf7970a_probe()
2142 regulator_disable(trf->vddio_regulator); in trf7970a_probe()
2144 regulator_disable(trf->vin_regulator); in trf7970a_probe()
2146 mutex_destroy(&trf->lock); in trf7970a_probe()
2152 struct trf7970a *trf = spi_get_drvdata(spi); in trf7970a_remove() local
2154 mutex_lock(&trf->lock); in trf7970a_remove()
2156 trf7970a_shutdown(trf); in trf7970a_remove()
2158 mutex_unlock(&trf->lock); in trf7970a_remove()
2160 nfc_digital_unregister_device(trf->ddev); in trf7970a_remove()
2161 nfc_digital_free_device(trf->ddev); in trf7970a_remove()
2163 regulator_disable(trf->vddio_regulator); in trf7970a_remove()
2164 regulator_disable(trf->vin_regulator); in trf7970a_remove()
2166 mutex_destroy(&trf->lock); in trf7970a_remove()
2173 struct trf7970a *trf = spi_get_drvdata(spi); in trf7970a_suspend() local
2175 mutex_lock(&trf->lock); in trf7970a_suspend()
2177 trf7970a_shutdown(trf); in trf7970a_suspend()
2179 mutex_unlock(&trf->lock); in trf7970a_suspend()
2187 struct trf7970a *trf = spi_get_drvdata(spi); in trf7970a_resume() local
2190 mutex_lock(&trf->lock); in trf7970a_resume()
2192 ret = trf7970a_startup(trf); in trf7970a_resume()
2194 mutex_unlock(&trf->lock); in trf7970a_resume()
2204 struct trf7970a *trf = spi_get_drvdata(spi); in trf7970a_pm_runtime_suspend() local
2207 mutex_lock(&trf->lock); in trf7970a_pm_runtime_suspend()
2209 ret = trf7970a_power_down(trf); in trf7970a_pm_runtime_suspend()
2211 mutex_unlock(&trf->lock); in trf7970a_pm_runtime_suspend()
2219 struct trf7970a *trf = spi_get_drvdata(spi); in trf7970a_pm_runtime_resume() local
2222 ret = trf7970a_power_up(trf); in trf7970a_pm_runtime_resume()