Lines Matching refs:trf
456 static int trf7970a_cmd(struct trf7970a *trf, u8 opcode) in trf7970a_cmd() argument
461 dev_dbg(trf->dev, "cmd: 0x%x\n", cmd); in trf7970a_cmd()
463 ret = spi_write(trf->spi, &cmd, 1); in trf7970a_cmd()
465 dev_err(trf->dev, "%s - cmd: 0x%x, ret: %d\n", __func__, cmd, in trf7970a_cmd()
470 static int trf7970a_read(struct trf7970a *trf, u8 reg, u8 *val) in trf7970a_read() argument
475 ret = spi_write_then_read(trf->spi, &addr, 1, val, 1); in trf7970a_read()
477 dev_err(trf->dev, "%s - addr: 0x%x, ret: %d\n", __func__, addr, in trf7970a_read()
480 dev_dbg(trf->dev, "read(0x%x): 0x%x\n", addr, *val); in trf7970a_read()
485 static int trf7970a_read_cont(struct trf7970a *trf, u8 reg, u8 *buf, in trf7970a_read_cont() argument
493 dev_dbg(trf->dev, "read_cont(0x%x, %zd)\n", addr, len); in trf7970a_read_cont()
507 ret = spi_sync(trf->spi, &m); in trf7970a_read_cont()
509 dev_err(trf->dev, "%s - addr: 0x%x, ret: %d\n", __func__, addr, in trf7970a_read_cont()
514 static int trf7970a_write(struct trf7970a *trf, u8 reg, u8 val) in trf7970a_write() argument
519 dev_dbg(trf->dev, "write(0x%x): 0x%x\n", reg, val); in trf7970a_write()
521 ret = spi_write(trf->spi, buf, 2); in trf7970a_write()
523 dev_err(trf->dev, "%s - write: 0x%x 0x%x, ret: %d\n", __func__, in trf7970a_write()
529 static int trf7970a_read_irqstatus(struct trf7970a *trf, u8 *status) in trf7970a_read_irqstatus() argument
537 if (trf->quirks & TRF7970A_QUIRK_IRQ_STATUS_READ) { in trf7970a_read_irqstatus()
539 ret = spi_write_then_read(trf->spi, &addr, 1, buf, 2); in trf7970a_read_irqstatus()
541 ret = spi_write_then_read(trf->spi, &addr, 1, buf, 1); in trf7970a_read_irqstatus()
545 dev_err(trf->dev, "%s - irqstatus: Status read failed: %d\n", in trf7970a_read_irqstatus()
553 static int trf7970a_read_target_proto(struct trf7970a *trf, u8 *target_proto) in trf7970a_read_target_proto() argument
562 ret = spi_write_then_read(trf->spi, &addr, 1, buf, 2); in trf7970a_read_target_proto()
564 dev_err(trf->dev, "%s - target_proto: Read failed: %d\n", in trf7970a_read_target_proto()
572 static int trf7970a_mode_detect(struct trf7970a *trf, u8 *rf_tech) in trf7970a_mode_detect() argument
577 ret = trf7970a_read_target_proto(trf, &target_proto); in trf7970a_mode_detect()
595 dev_dbg(trf->dev, "%s - mode_detect: target_proto: 0x%x\n", in trf7970a_mode_detect()
605 static void trf7970a_send_upstream(struct trf7970a *trf) in trf7970a_send_upstream() argument
607 dev_kfree_skb_any(trf->tx_skb); in trf7970a_send_upstream()
608 trf->tx_skb = NULL; in trf7970a_send_upstream()
610 if (trf->rx_skb && !IS_ERR(trf->rx_skb) && !trf->aborting) in trf7970a_send_upstream()
612 16, 1, trf->rx_skb->data, trf->rx_skb->len, in trf7970a_send_upstream()
615 trf->state = TRF7970A_ST_IDLE; in trf7970a_send_upstream()
617 if (trf->aborting) { in trf7970a_send_upstream()
618 dev_dbg(trf->dev, "Abort process complete\n"); in trf7970a_send_upstream()
620 if (!IS_ERR(trf->rx_skb)) { in trf7970a_send_upstream()
621 kfree_skb(trf->rx_skb); in trf7970a_send_upstream()
622 trf->rx_skb = ERR_PTR(-ECANCELED); in trf7970a_send_upstream()
625 trf->aborting = false; in trf7970a_send_upstream()
628 trf->cb(trf->ddev, trf->cb_arg, trf->rx_skb); in trf7970a_send_upstream()
630 trf->rx_skb = NULL; in trf7970a_send_upstream()
633 static void trf7970a_send_err_upstream(struct trf7970a *trf, int errno) in trf7970a_send_err_upstream() argument
635 dev_dbg(trf->dev, "Error - state: %d, errno: %d\n", trf->state, errno); in trf7970a_send_err_upstream()
637 cancel_delayed_work(&trf->timeout_work); in trf7970a_send_err_upstream()
639 kfree_skb(trf->rx_skb); in trf7970a_send_err_upstream()
640 trf->rx_skb = ERR_PTR(errno); in trf7970a_send_err_upstream()
642 trf7970a_send_upstream(trf); in trf7970a_send_err_upstream()
645 static int trf7970a_transmit(struct trf7970a *trf, struct sk_buff *skb, in trf7970a_transmit() argument
669 ret = spi_sync(trf->spi, &m); in trf7970a_transmit()
671 dev_err(trf->dev, "%s - Can't send tx data: %d\n", __func__, in trf7970a_transmit()
679 trf->state = TRF7970A_ST_WAIT_FOR_TX_FIFO; in trf7970a_transmit()
682 if (trf->issue_eof) { in trf7970a_transmit()
683 trf->state = TRF7970A_ST_WAIT_TO_ISSUE_EOF; in trf7970a_transmit()
686 trf->state = TRF7970A_ST_WAIT_FOR_RX_DATA; in trf7970a_transmit()
688 if (!trf->timeout) in trf7970a_transmit()
691 timeout = trf->timeout; in trf7970a_transmit()
695 dev_dbg(trf->dev, "Setting timeout for %d ms, state: %d\n", timeout, in trf7970a_transmit()
696 trf->state); in trf7970a_transmit()
698 schedule_delayed_work(&trf->timeout_work, msecs_to_jiffies(timeout)); in trf7970a_transmit()
703 static void trf7970a_fill_fifo(struct trf7970a *trf) in trf7970a_fill_fifo() argument
705 struct sk_buff *skb = trf->tx_skb; in trf7970a_fill_fifo()
711 ret = trf7970a_read(trf, TRF7970A_FIFO_STATUS, &fifo_bytes); in trf7970a_fill_fifo()
713 trf7970a_send_err_upstream(trf, ret); in trf7970a_fill_fifo()
717 dev_dbg(trf->dev, "Filling FIFO - fifo_bytes: 0x%x\n", fifo_bytes); in trf7970a_fill_fifo()
724 schedule_delayed_work(&trf->timeout_work, in trf7970a_fill_fifo()
733 ret = trf7970a_transmit(trf, skb, len, &prefix, sizeof(prefix)); in trf7970a_fill_fifo()
735 trf7970a_send_err_upstream(trf, ret); in trf7970a_fill_fifo()
738 static void trf7970a_drain_fifo(struct trf7970a *trf, u8 status) in trf7970a_drain_fifo() argument
740 struct sk_buff *skb = trf->rx_skb; in trf7970a_drain_fifo()
745 trf7970a_send_err_upstream(trf, -EIO); in trf7970a_drain_fifo()
749 ret = trf7970a_read(trf, TRF7970A_FIFO_STATUS, &fifo_bytes); in trf7970a_drain_fifo()
751 trf7970a_send_err_upstream(trf, ret); in trf7970a_drain_fifo()
755 dev_dbg(trf->dev, "Draining FIFO - fifo_bytes: 0x%x\n", fifo_bytes); in trf7970a_drain_fifo()
768 trf7970a_send_err_upstream(trf, -ENOMEM); in trf7970a_drain_fifo()
772 kfree_skb(trf->rx_skb); in trf7970a_drain_fifo()
773 trf->rx_skb = skb; in trf7970a_drain_fifo()
776 ret = trf7970a_read_cont(trf, TRF7970A_FIFO_IO_REGISTER, in trf7970a_drain_fifo()
779 trf7970a_send_err_upstream(trf, ret); in trf7970a_drain_fifo()
784 if ((trf->framing == NFC_DIGITAL_FRAMING_NFCA_T2T) && (skb->len == 1) && in trf7970a_drain_fifo()
785 (trf->special_fcn_reg1 == TRF7970A_SPECIAL_FCN_REG1_4_BIT_RX)) { in trf7970a_drain_fifo()
789 trf->state = TRF7970A_ST_WAIT_FOR_RX_DATA_CONT; in trf7970a_drain_fifo()
791 ret = trf7970a_read(trf, TRF7970A_FIFO_STATUS, &fifo_bytes); in trf7970a_drain_fifo()
793 trf7970a_send_err_upstream(trf, ret); in trf7970a_drain_fifo()
809 trf7970a_send_upstream(trf); in trf7970a_drain_fifo()
813 dev_dbg(trf->dev, "Setting timeout for %d ms\n", in trf7970a_drain_fifo()
816 schedule_delayed_work(&trf->timeout_work, in trf7970a_drain_fifo()
822 struct trf7970a *trf = dev_id; in trf7970a_irq() local
826 mutex_lock(&trf->lock); in trf7970a_irq()
828 if (trf->state == TRF7970A_ST_RF_OFF) { in trf7970a_irq()
829 mutex_unlock(&trf->lock); in trf7970a_irq()
833 ret = trf7970a_read_irqstatus(trf, &status); in trf7970a_irq()
835 mutex_unlock(&trf->lock); in trf7970a_irq()
839 dev_dbg(trf->dev, "IRQ - state: %d, status: 0x%x\n", trf->state, in trf7970a_irq()
843 mutex_unlock(&trf->lock); in trf7970a_irq()
847 switch (trf->state) { in trf7970a_irq()
855 if (trf->is_initiator && (status & TRF7970A_IRQ_STATUS_ERROR)) { in trf7970a_irq()
856 trf7970a_cmd(trf, TRF7970A_CMD_BLOCK_RX); in trf7970a_irq()
857 trf->state = TRF7970A_ST_IDLE_RX_BLOCKED; in trf7970a_irq()
860 trf7970a_cmd(trf, TRF7970A_CMD_FIFO_RESET); in trf7970a_irq()
864 trf->ignore_timeout = in trf7970a_irq()
865 !cancel_delayed_work(&trf->timeout_work); in trf7970a_irq()
866 trf7970a_fill_fifo(trf); in trf7970a_irq()
868 trf7970a_send_err_upstream(trf, -EIO); in trf7970a_irq()
874 trf->ignore_timeout = in trf7970a_irq()
875 !cancel_delayed_work(&trf->timeout_work); in trf7970a_irq()
876 trf7970a_drain_fifo(trf, status); in trf7970a_irq()
878 ret = trf7970a_read(trf, TRF7970A_FIFO_STATUS, in trf7970a_irq()
884 trf7970a_send_err_upstream(trf, ret); in trf7970a_irq()
886 trf7970a_cmd(trf, TRF7970A_CMD_FIFO_RESET); in trf7970a_irq()
888 (!trf->is_initiator && in trf7970a_irq()
891 trf7970a_cmd(trf, TRF7970A_CMD_FIFO_RESET); in trf7970a_irq()
893 if (!trf->timeout) { in trf7970a_irq()
894 trf->ignore_timeout = in trf7970a_irq()
895 !cancel_delayed_work(&trf->timeout_work); in trf7970a_irq()
896 trf->rx_skb = ERR_PTR(0); in trf7970a_irq()
897 trf7970a_send_upstream(trf); in trf7970a_irq()
901 if (trf->is_initiator) in trf7970a_irq()
904 iso_ctrl = trf->iso_ctrl; in trf7970a_irq()
906 switch (trf->framing) { in trf7970a_irq()
908 trf->tx_cmd = TRF7970A_CMD_TRANSMIT_NO_CRC; in trf7970a_irq()
910 trf->iso_ctrl = 0xff; /* Force ISO_CTRL write */ in trf7970a_irq()
913 trf->tx_cmd = TRF7970A_CMD_TRANSMIT; in trf7970a_irq()
915 trf->iso_ctrl = 0xff; /* Force ISO_CTRL write */ in trf7970a_irq()
918 ret = trf7970a_write(trf, in trf7970a_irq()
924 trf->special_fcn_reg1 = in trf7970a_irq()
931 if (iso_ctrl != trf->iso_ctrl) { in trf7970a_irq()
932 ret = trf7970a_write(trf, TRF7970A_ISO_CTRL, in trf7970a_irq()
937 trf->iso_ctrl = iso_ctrl; in trf7970a_irq()
940 trf7970a_send_err_upstream(trf, -EIO); in trf7970a_irq()
945 trf7970a_send_err_upstream(trf, -EIO); in trf7970a_irq()
949 trf->ignore_timeout = in trf7970a_irq()
950 !cancel_delayed_work(&trf->timeout_work); in trf7970a_irq()
951 trf7970a_drain_fifo(trf, status); in trf7970a_irq()
953 trf7970a_send_err_upstream(trf, -EIO); in trf7970a_irq()
958 trf->ignore_timeout = in trf7970a_irq()
959 !cancel_delayed_work(&trf->timeout_work); in trf7970a_irq()
961 ret = trf7970a_mode_detect(trf, &trf->md_rf_tech); in trf7970a_irq()
963 trf7970a_send_err_upstream(trf, ret); in trf7970a_irq()
965 trf->state = TRF7970A_ST_LISTENING; in trf7970a_irq()
966 trf7970a_drain_fifo(trf, status); in trf7970a_irq()
969 trf7970a_send_err_upstream(trf, -EIO); in trf7970a_irq()
973 dev_err(trf->dev, "%s - Driver in invalid state: %d\n", in trf7970a_irq()
974 __func__, trf->state); in trf7970a_irq()
978 mutex_unlock(&trf->lock); in trf7970a_irq()
982 static void trf7970a_issue_eof(struct trf7970a *trf) in trf7970a_issue_eof() argument
986 dev_dbg(trf->dev, "Issuing EOF\n"); in trf7970a_issue_eof()
988 ret = trf7970a_cmd(trf, TRF7970A_CMD_FIFO_RESET); in trf7970a_issue_eof()
990 trf7970a_send_err_upstream(trf, ret); in trf7970a_issue_eof()
992 ret = trf7970a_cmd(trf, TRF7970A_CMD_EOF); in trf7970a_issue_eof()
994 trf7970a_send_err_upstream(trf, ret); in trf7970a_issue_eof()
996 trf->state = TRF7970A_ST_WAIT_FOR_RX_DATA; in trf7970a_issue_eof()
998 dev_dbg(trf->dev, "Setting timeout for %d ms, state: %d\n", in trf7970a_issue_eof()
999 trf->timeout, trf->state); in trf7970a_issue_eof()
1001 schedule_delayed_work(&trf->timeout_work, in trf7970a_issue_eof()
1002 msecs_to_jiffies(trf->timeout)); in trf7970a_issue_eof()
1007 struct trf7970a *trf = container_of(work, struct trf7970a, in trf7970a_timeout_work_handler() local
1010 dev_dbg(trf->dev, "Timeout - state: %d, ignore_timeout: %d\n", in trf7970a_timeout_work_handler()
1011 trf->state, trf->ignore_timeout); in trf7970a_timeout_work_handler()
1013 mutex_lock(&trf->lock); in trf7970a_timeout_work_handler()
1015 if (trf->ignore_timeout) in trf7970a_timeout_work_handler()
1016 trf->ignore_timeout = false; in trf7970a_timeout_work_handler()
1017 else if (trf->state == TRF7970A_ST_WAIT_FOR_RX_DATA_CONT) in trf7970a_timeout_work_handler()
1018 trf7970a_drain_fifo(trf, TRF7970A_IRQ_STATUS_SRX); in trf7970a_timeout_work_handler()
1019 else if (trf->state == TRF7970A_ST_WAIT_TO_ISSUE_EOF) in trf7970a_timeout_work_handler()
1020 trf7970a_issue_eof(trf); in trf7970a_timeout_work_handler()
1022 trf7970a_send_err_upstream(trf, -ETIMEDOUT); in trf7970a_timeout_work_handler()
1024 mutex_unlock(&trf->lock); in trf7970a_timeout_work_handler()
1027 static int trf7970a_init(struct trf7970a *trf) in trf7970a_init() argument
1031 dev_dbg(trf->dev, "Initializing device - state: %d\n", trf->state); in trf7970a_init()
1033 ret = trf7970a_cmd(trf, TRF7970A_CMD_SOFT_INIT); in trf7970a_init()
1037 ret = trf7970a_cmd(trf, TRF7970A_CMD_IDLE); in trf7970a_init()
1041 ret = trf7970a_write(trf, TRF7970A_REG_IO_CTRL, in trf7970a_init()
1042 trf->io_ctrl | TRF7970A_REG_IO_CTRL_VRS(0x1)); in trf7970a_init()
1046 ret = trf7970a_write(trf, TRF7970A_NFC_TARGET_LEVEL, 0); in trf7970a_init()
1052 trf->chip_status_ctrl &= ~TRF7970A_CHIP_STATUS_RF_ON; in trf7970a_init()
1054 ret = trf7970a_write(trf, TRF7970A_MODULATOR_SYS_CLK_CTRL, in trf7970a_init()
1055 trf->modulator_sys_clk_ctrl); in trf7970a_init()
1059 ret = trf7970a_write(trf, TRF7970A_ADJUTABLE_FIFO_IRQ_LEVELS, in trf7970a_init()
1065 ret = trf7970a_write(trf, TRF7970A_SPECIAL_FCN_REG1, 0); in trf7970a_init()
1069 trf->special_fcn_reg1 = 0; in trf7970a_init()
1071 trf->iso_ctrl = 0xff; in trf7970a_init()
1075 dev_dbg(trf->dev, "Couldn't init device: %d\n", ret); in trf7970a_init()
1079 static void trf7970a_switch_rf_off(struct trf7970a *trf) in trf7970a_switch_rf_off() argument
1081 if ((trf->state == TRF7970A_ST_PWR_OFF) || in trf7970a_switch_rf_off()
1082 (trf->state == TRF7970A_ST_RF_OFF)) in trf7970a_switch_rf_off()
1085 dev_dbg(trf->dev, "Switching rf off\n"); in trf7970a_switch_rf_off()
1087 trf->chip_status_ctrl &= ~TRF7970A_CHIP_STATUS_RF_ON; in trf7970a_switch_rf_off()
1089 trf7970a_write(trf, TRF7970A_CHIP_STATUS_CTRL, trf->chip_status_ctrl); in trf7970a_switch_rf_off()
1091 trf->aborting = false; in trf7970a_switch_rf_off()
1092 trf->state = TRF7970A_ST_RF_OFF; in trf7970a_switch_rf_off()
1094 pm_runtime_mark_last_busy(trf->dev); in trf7970a_switch_rf_off()
1095 pm_runtime_put_autosuspend(trf->dev); in trf7970a_switch_rf_off()
1098 static int trf7970a_switch_rf_on(struct trf7970a *trf) in trf7970a_switch_rf_on() argument
1102 dev_dbg(trf->dev, "Switching rf on\n"); in trf7970a_switch_rf_on()
1104 pm_runtime_get_sync(trf->dev); in trf7970a_switch_rf_on()
1106 if (trf->state != TRF7970A_ST_RF_OFF) { /* Power on, RF off */ in trf7970a_switch_rf_on()
1107 dev_err(trf->dev, "%s - Incorrect state: %d\n", __func__, in trf7970a_switch_rf_on()
1108 trf->state); in trf7970a_switch_rf_on()
1112 ret = trf7970a_init(trf); in trf7970a_switch_rf_on()
1114 dev_err(trf->dev, "%s - Can't initialize: %d\n", __func__, ret); in trf7970a_switch_rf_on()
1118 trf->state = TRF7970A_ST_IDLE; in trf7970a_switch_rf_on()
1125 struct trf7970a *trf = nfc_digital_get_drvdata(ddev); in trf7970a_switch_rf() local
1128 dev_dbg(trf->dev, "Switching RF - state: %d, on: %d\n", trf->state, on); in trf7970a_switch_rf()
1130 mutex_lock(&trf->lock); in trf7970a_switch_rf()
1133 switch (trf->state) { in trf7970a_switch_rf()
1136 ret = trf7970a_switch_rf_on(trf); in trf7970a_switch_rf()
1142 dev_err(trf->dev, "%s - Invalid request: %d %d\n", in trf7970a_switch_rf()
1143 __func__, trf->state, on); in trf7970a_switch_rf()
1144 trf7970a_switch_rf_off(trf); in trf7970a_switch_rf()
1148 switch (trf->state) { in trf7970a_switch_rf()
1153 dev_err(trf->dev, "%s - Invalid request: %d %d\n", in trf7970a_switch_rf()
1154 __func__, trf->state, on); in trf7970a_switch_rf()
1161 trf7970a_switch_rf_off(trf); in trf7970a_switch_rf()
1165 mutex_unlock(&trf->lock); in trf7970a_switch_rf()
1169 static int trf7970a_in_config_rf_tech(struct trf7970a *trf, int tech) in trf7970a_in_config_rf_tech() argument
1173 dev_dbg(trf->dev, "rf technology: %d\n", tech); in trf7970a_in_config_rf_tech()
1177 trf->iso_ctrl_tech = TRF7970A_ISO_CTRL_14443A_106; in trf7970a_in_config_rf_tech()
1178 trf->modulator_sys_clk_ctrl = in trf7970a_in_config_rf_tech()
1179 (trf->modulator_sys_clk_ctrl & 0xf8) | in trf7970a_in_config_rf_tech()
1181 trf->guard_time = TRF7970A_GUARD_TIME_NFCA; in trf7970a_in_config_rf_tech()
1184 trf->iso_ctrl_tech = TRF7970A_ISO_CTRL_14443B_106; in trf7970a_in_config_rf_tech()
1185 trf->modulator_sys_clk_ctrl = in trf7970a_in_config_rf_tech()
1186 (trf->modulator_sys_clk_ctrl & 0xf8) | in trf7970a_in_config_rf_tech()
1188 trf->guard_time = TRF7970A_GUARD_TIME_NFCB; in trf7970a_in_config_rf_tech()
1191 trf->iso_ctrl_tech = TRF7970A_ISO_CTRL_FELICA_212; in trf7970a_in_config_rf_tech()
1192 trf->modulator_sys_clk_ctrl = in trf7970a_in_config_rf_tech()
1193 (trf->modulator_sys_clk_ctrl & 0xf8) | in trf7970a_in_config_rf_tech()
1195 trf->guard_time = TRF7970A_GUARD_TIME_NFCF; in trf7970a_in_config_rf_tech()
1198 trf->iso_ctrl_tech = TRF7970A_ISO_CTRL_FELICA_424; in trf7970a_in_config_rf_tech()
1199 trf->modulator_sys_clk_ctrl = in trf7970a_in_config_rf_tech()
1200 (trf->modulator_sys_clk_ctrl & 0xf8) | in trf7970a_in_config_rf_tech()
1202 trf->guard_time = TRF7970A_GUARD_TIME_NFCF; in trf7970a_in_config_rf_tech()
1205 trf->iso_ctrl_tech = TRF7970A_ISO_CTRL_15693_SGL_1OF4_2648; in trf7970a_in_config_rf_tech()
1206 trf->modulator_sys_clk_ctrl = in trf7970a_in_config_rf_tech()
1207 (trf->modulator_sys_clk_ctrl & 0xf8) | in trf7970a_in_config_rf_tech()
1209 trf->guard_time = TRF7970A_GUARD_TIME_15693; in trf7970a_in_config_rf_tech()
1212 dev_dbg(trf->dev, "Unsupported rf technology: %d\n", tech); in trf7970a_in_config_rf_tech()
1216 trf->technology = tech; in trf7970a_in_config_rf_tech()
1223 if (trf->iso_ctrl == 0xff) in trf7970a_in_config_rf_tech()
1224 ret = trf7970a_write(trf, TRF7970A_NFC_TARGET_LEVEL, 0); in trf7970a_in_config_rf_tech()
1229 static int trf7970a_is_rf_field(struct trf7970a *trf, bool *is_rf_field) in trf7970a_is_rf_field() argument
1234 ret = trf7970a_write(trf, TRF7970A_CHIP_STATUS_CTRL, in trf7970a_is_rf_field()
1235 trf->chip_status_ctrl | in trf7970a_is_rf_field()
1240 ret = trf7970a_cmd(trf, TRF7970A_CMD_TEST_EXT_RF); in trf7970a_is_rf_field()
1246 ret = trf7970a_read(trf, TRF7970A_RSSI_OSC_STATUS, &rssi); in trf7970a_is_rf_field()
1250 ret = trf7970a_write(trf, TRF7970A_CHIP_STATUS_CTRL, in trf7970a_is_rf_field()
1251 trf->chip_status_ctrl); in trf7970a_is_rf_field()
1263 static int trf7970a_in_config_framing(struct trf7970a *trf, int framing) in trf7970a_in_config_framing() argument
1265 u8 iso_ctrl = trf->iso_ctrl_tech; in trf7970a_in_config_framing()
1269 dev_dbg(trf->dev, "framing: %d\n", framing); in trf7970a_in_config_framing()
1274 trf->tx_cmd = TRF7970A_CMD_TRANSMIT_NO_CRC; in trf7970a_in_config_framing()
1287 trf->tx_cmd = TRF7970A_CMD_TRANSMIT; in trf7970a_in_config_framing()
1291 trf->tx_cmd = TRF7970A_CMD_TRANSMIT; in trf7970a_in_config_framing()
1295 dev_dbg(trf->dev, "Unsupported Framing: %d\n", framing); in trf7970a_in_config_framing()
1299 trf->framing = framing; in trf7970a_in_config_framing()
1301 if (!(trf->chip_status_ctrl & TRF7970A_CHIP_STATUS_RF_ON)) { in trf7970a_in_config_framing()
1302 ret = trf7970a_is_rf_field(trf, &is_rf_field); in trf7970a_in_config_framing()
1310 if (iso_ctrl != trf->iso_ctrl) { in trf7970a_in_config_framing()
1311 ret = trf7970a_write(trf, TRF7970A_ISO_CTRL, iso_ctrl); in trf7970a_in_config_framing()
1315 trf->iso_ctrl = iso_ctrl; in trf7970a_in_config_framing()
1317 ret = trf7970a_write(trf, TRF7970A_MODULATOR_SYS_CLK_CTRL, in trf7970a_in_config_framing()
1318 trf->modulator_sys_clk_ctrl); in trf7970a_in_config_framing()
1323 if (!(trf->chip_status_ctrl & TRF7970A_CHIP_STATUS_RF_ON)) { in trf7970a_in_config_framing()
1324 ret = trf7970a_write(trf, TRF7970A_CHIP_STATUS_CTRL, in trf7970a_in_config_framing()
1325 trf->chip_status_ctrl | in trf7970a_in_config_framing()
1330 trf->chip_status_ctrl |= TRF7970A_CHIP_STATUS_RF_ON; in trf7970a_in_config_framing()
1332 usleep_range(trf->guard_time, trf->guard_time + 1000); in trf7970a_in_config_framing()
1341 struct trf7970a *trf = nfc_digital_get_drvdata(ddev); in trf7970a_in_configure_hw() local
1344 dev_dbg(trf->dev, "Configure hw - type: %d, param: %d\n", type, param); in trf7970a_in_configure_hw()
1346 mutex_lock(&trf->lock); in trf7970a_in_configure_hw()
1348 trf->is_initiator = true; in trf7970a_in_configure_hw()
1350 if ((trf->state == TRF7970A_ST_PWR_OFF) || in trf7970a_in_configure_hw()
1351 (trf->state == TRF7970A_ST_RF_OFF)) { in trf7970a_in_configure_hw()
1352 ret = trf7970a_switch_rf_on(trf); in trf7970a_in_configure_hw()
1359 ret = trf7970a_in_config_rf_tech(trf, param); in trf7970a_in_configure_hw()
1362 ret = trf7970a_in_config_framing(trf, param); in trf7970a_in_configure_hw()
1365 dev_dbg(trf->dev, "Unknown type: %d\n", type); in trf7970a_in_configure_hw()
1370 mutex_unlock(&trf->lock); in trf7970a_in_configure_hw()
1390 static int trf7970a_per_cmd_config(struct trf7970a *trf, in trf7970a_per_cmd_config() argument
1397 trf->issue_eof = false; in trf7970a_per_cmd_config()
1408 if ((trf->technology == NFC_DIGITAL_RF_TECH_106A) && in trf7970a_per_cmd_config()
1409 (trf->framing == NFC_DIGITAL_FRAMING_NFCA_T2T)) { in trf7970a_per_cmd_config()
1415 if (special_fcn_reg1 != trf->special_fcn_reg1) { in trf7970a_per_cmd_config()
1416 ret = trf7970a_write(trf, TRF7970A_SPECIAL_FCN_REG1, in trf7970a_per_cmd_config()
1421 trf->special_fcn_reg1 = special_fcn_reg1; in trf7970a_per_cmd_config()
1423 } else if (trf->technology == NFC_DIGITAL_RF_TECH_ISO15693) { in trf7970a_per_cmd_config()
1424 iso_ctrl = trf->iso_ctrl & ~TRF7970A_ISO_CTRL_RFID_SPEED_MASK; in trf7970a_per_cmd_config()
1442 if (iso_ctrl != trf->iso_ctrl) { in trf7970a_per_cmd_config()
1443 ret = trf7970a_write(trf, TRF7970A_ISO_CTRL, iso_ctrl); in trf7970a_per_cmd_config()
1447 trf->iso_ctrl = iso_ctrl; in trf7970a_per_cmd_config()
1450 if ((trf->framing == NFC_DIGITAL_FRAMING_ISO15693_T5T) && in trf7970a_per_cmd_config()
1453 trf->issue_eof = true; in trf7970a_per_cmd_config()
1463 struct trf7970a *trf = nfc_digital_get_drvdata(ddev); in trf7970a_send_cmd() local
1469 dev_dbg(trf->dev, "New request - state: %d, timeout: %d ms, len: %d\n", in trf7970a_send_cmd()
1470 trf->state, timeout, skb->len); in trf7970a_send_cmd()
1475 mutex_lock(&trf->lock); in trf7970a_send_cmd()
1477 if ((trf->state != TRF7970A_ST_IDLE) && in trf7970a_send_cmd()
1478 (trf->state != TRF7970A_ST_IDLE_RX_BLOCKED)) { in trf7970a_send_cmd()
1479 dev_err(trf->dev, "%s - Bogus state: %d\n", __func__, in trf7970a_send_cmd()
1480 trf->state); in trf7970a_send_cmd()
1485 if (trf->aborting) { in trf7970a_send_cmd()
1486 dev_dbg(trf->dev, "Abort process complete\n"); in trf7970a_send_cmd()
1487 trf->aborting = false; in trf7970a_send_cmd()
1493 trf->rx_skb = nfc_alloc_recv_skb(TRF7970A_RX_SKB_ALLOC_SIZE, in trf7970a_send_cmd()
1495 if (!trf->rx_skb) { in trf7970a_send_cmd()
1496 dev_dbg(trf->dev, "Can't alloc rx_skb\n"); in trf7970a_send_cmd()
1502 if (trf->state == TRF7970A_ST_IDLE_RX_BLOCKED) { in trf7970a_send_cmd()
1503 ret = trf7970a_cmd(trf, TRF7970A_CMD_ENABLE_RX); in trf7970a_send_cmd()
1507 trf->state = TRF7970A_ST_IDLE; in trf7970a_send_cmd()
1510 if (trf->is_initiator) { in trf7970a_send_cmd()
1511 ret = trf7970a_per_cmd_config(trf, skb); in trf7970a_send_cmd()
1516 trf->ddev = ddev; in trf7970a_send_cmd()
1517 trf->tx_skb = skb; in trf7970a_send_cmd()
1518 trf->cb = cb; in trf7970a_send_cmd()
1519 trf->cb_arg = arg; in trf7970a_send_cmd()
1520 trf->timeout = timeout; in trf7970a_send_cmd()
1521 trf->ignore_timeout = false; in trf7970a_send_cmd()
1533 TRF7970A_CMD_BIT_OPCODE(trf->tx_cmd); in trf7970a_send_cmd()
1536 if (trf->framing == NFC_DIGITAL_FRAMING_NFCA_SHORT) { in trf7970a_send_cmd()
1548 ret = trf7970a_read_irqstatus(trf, &status); in trf7970a_send_cmd()
1552 ret = trf7970a_transmit(trf, skb, len, prefix, sizeof(prefix)); in trf7970a_send_cmd()
1554 kfree_skb(trf->rx_skb); in trf7970a_send_cmd()
1555 trf->rx_skb = NULL; in trf7970a_send_cmd()
1559 mutex_unlock(&trf->lock); in trf7970a_send_cmd()
1563 static int trf7970a_tg_config_rf_tech(struct trf7970a *trf, int tech) in trf7970a_tg_config_rf_tech() argument
1567 dev_dbg(trf->dev, "rf technology: %d\n", tech); in trf7970a_tg_config_rf_tech()
1571 trf->iso_ctrl_tech = TRF7970A_ISO_CTRL_NFC_NFC_CE_MODE | in trf7970a_tg_config_rf_tech()
1573 trf->modulator_sys_clk_ctrl = in trf7970a_tg_config_rf_tech()
1574 (trf->modulator_sys_clk_ctrl & 0xf8) | in trf7970a_tg_config_rf_tech()
1578 trf->iso_ctrl_tech = TRF7970A_ISO_CTRL_NFC_NFC_CE_MODE | in trf7970a_tg_config_rf_tech()
1580 trf->modulator_sys_clk_ctrl = in trf7970a_tg_config_rf_tech()
1581 (trf->modulator_sys_clk_ctrl & 0xf8) | in trf7970a_tg_config_rf_tech()
1585 trf->iso_ctrl_tech = TRF7970A_ISO_CTRL_NFC_NFC_CE_MODE | in trf7970a_tg_config_rf_tech()
1587 trf->modulator_sys_clk_ctrl = in trf7970a_tg_config_rf_tech()
1588 (trf->modulator_sys_clk_ctrl & 0xf8) | in trf7970a_tg_config_rf_tech()
1592 dev_dbg(trf->dev, "Unsupported rf technology: %d\n", tech); in trf7970a_tg_config_rf_tech()
1596 trf->technology = tech; in trf7970a_tg_config_rf_tech()
1605 if ((trf->framing == NFC_DIGITAL_FRAMING_NFC_DEP_ACTIVATED) && in trf7970a_tg_config_rf_tech()
1606 (trf->iso_ctrl_tech != trf->iso_ctrl)) { in trf7970a_tg_config_rf_tech()
1607 ret = trf7970a_write(trf, TRF7970A_ISO_CTRL, in trf7970a_tg_config_rf_tech()
1608 trf->iso_ctrl_tech); in trf7970a_tg_config_rf_tech()
1610 trf->iso_ctrl = trf->iso_ctrl_tech; in trf7970a_tg_config_rf_tech()
1622 static int trf7970a_tg_config_framing(struct trf7970a *trf, int framing) in trf7970a_tg_config_framing() argument
1624 u8 iso_ctrl = trf->iso_ctrl_tech; in trf7970a_tg_config_framing()
1627 dev_dbg(trf->dev, "framing: %d\n", framing); in trf7970a_tg_config_framing()
1631 trf->tx_cmd = TRF7970A_CMD_TRANSMIT_NO_CRC; in trf7970a_tg_config_framing()
1638 iso_ctrl = trf->iso_ctrl; /* Don't write to ISO_CTRL yet */ in trf7970a_tg_config_framing()
1641 trf->tx_cmd = TRF7970A_CMD_TRANSMIT; in trf7970a_tg_config_framing()
1645 trf->tx_cmd = TRF7970A_CMD_TRANSMIT; in trf7970a_tg_config_framing()
1649 dev_dbg(trf->dev, "Unsupported Framing: %d\n", framing); in trf7970a_tg_config_framing()
1653 trf->framing = framing; in trf7970a_tg_config_framing()
1655 if (iso_ctrl != trf->iso_ctrl) { in trf7970a_tg_config_framing()
1656 ret = trf7970a_write(trf, TRF7970A_ISO_CTRL, iso_ctrl); in trf7970a_tg_config_framing()
1660 trf->iso_ctrl = iso_ctrl; in trf7970a_tg_config_framing()
1662 ret = trf7970a_write(trf, TRF7970A_MODULATOR_SYS_CLK_CTRL, in trf7970a_tg_config_framing()
1663 trf->modulator_sys_clk_ctrl); in trf7970a_tg_config_framing()
1668 if (!(trf->chip_status_ctrl & TRF7970A_CHIP_STATUS_RF_ON)) { in trf7970a_tg_config_framing()
1669 ret = trf7970a_write(trf, TRF7970A_CHIP_STATUS_CTRL, in trf7970a_tg_config_framing()
1670 trf->chip_status_ctrl | in trf7970a_tg_config_framing()
1675 trf->chip_status_ctrl |= TRF7970A_CHIP_STATUS_RF_ON; in trf7970a_tg_config_framing()
1684 struct trf7970a *trf = nfc_digital_get_drvdata(ddev); in trf7970a_tg_configure_hw() local
1687 dev_dbg(trf->dev, "Configure hw - type: %d, param: %d\n", type, param); in trf7970a_tg_configure_hw()
1689 mutex_lock(&trf->lock); in trf7970a_tg_configure_hw()
1691 trf->is_initiator = false; in trf7970a_tg_configure_hw()
1693 if ((trf->state == TRF7970A_ST_PWR_OFF) || in trf7970a_tg_configure_hw()
1694 (trf->state == TRF7970A_ST_RF_OFF)) { in trf7970a_tg_configure_hw()
1695 ret = trf7970a_switch_rf_on(trf); in trf7970a_tg_configure_hw()
1702 ret = trf7970a_tg_config_rf_tech(trf, param); in trf7970a_tg_configure_hw()
1705 ret = trf7970a_tg_config_framing(trf, param); in trf7970a_tg_configure_hw()
1708 dev_dbg(trf->dev, "Unknown type: %d\n", type); in trf7970a_tg_configure_hw()
1713 mutex_unlock(&trf->lock); in trf7970a_tg_configure_hw()
1721 struct trf7970a *trf = nfc_digital_get_drvdata(ddev); in _trf7970a_tg_listen() local
1724 mutex_lock(&trf->lock); in _trf7970a_tg_listen()
1726 if ((trf->state != TRF7970A_ST_IDLE) && in _trf7970a_tg_listen()
1727 (trf->state != TRF7970A_ST_IDLE_RX_BLOCKED)) { in _trf7970a_tg_listen()
1728 dev_err(trf->dev, "%s - Bogus state: %d\n", __func__, in _trf7970a_tg_listen()
1729 trf->state); in _trf7970a_tg_listen()
1734 if (trf->aborting) { in _trf7970a_tg_listen()
1735 dev_dbg(trf->dev, "Abort process complete\n"); in _trf7970a_tg_listen()
1736 trf->aborting = false; in _trf7970a_tg_listen()
1741 trf->rx_skb = nfc_alloc_recv_skb(TRF7970A_RX_SKB_ALLOC_SIZE, in _trf7970a_tg_listen()
1743 if (!trf->rx_skb) { in _trf7970a_tg_listen()
1744 dev_dbg(trf->dev, "Can't alloc rx_skb\n"); in _trf7970a_tg_listen()
1749 ret = trf7970a_write(trf, TRF7970A_RX_SPECIAL_SETTINGS, in _trf7970a_tg_listen()
1757 ret = trf7970a_write(trf, TRF7970A_REG_IO_CTRL, in _trf7970a_tg_listen()
1758 trf->io_ctrl | TRF7970A_REG_IO_CTRL_VRS(0x1)); in _trf7970a_tg_listen()
1762 ret = trf7970a_write(trf, TRF7970A_NFC_LOW_FIELD_LEVEL, in _trf7970a_tg_listen()
1767 ret = trf7970a_write(trf, TRF7970A_NFC_TARGET_LEVEL, in _trf7970a_tg_listen()
1772 trf->ddev = ddev; in _trf7970a_tg_listen()
1773 trf->cb = cb; in _trf7970a_tg_listen()
1774 trf->cb_arg = arg; in _trf7970a_tg_listen()
1775 trf->timeout = timeout; in _trf7970a_tg_listen()
1776 trf->ignore_timeout = false; in _trf7970a_tg_listen()
1778 ret = trf7970a_cmd(trf, TRF7970A_CMD_ENABLE_RX); in _trf7970a_tg_listen()
1782 trf->state = mode_detect ? TRF7970A_ST_LISTENING_MD : in _trf7970a_tg_listen()
1785 schedule_delayed_work(&trf->timeout_work, msecs_to_jiffies(timeout)); in _trf7970a_tg_listen()
1788 mutex_unlock(&trf->lock); in _trf7970a_tg_listen()
1795 const struct trf7970a *trf = nfc_digital_get_drvdata(ddev); in trf7970a_tg_listen() local
1797 dev_dbg(trf->dev, "Listen - state: %d, timeout: %d ms\n", in trf7970a_tg_listen()
1798 trf->state, timeout); in trf7970a_tg_listen()
1807 const struct trf7970a *trf = nfc_digital_get_drvdata(ddev); in trf7970a_tg_listen_md() local
1810 dev_dbg(trf->dev, "Listen MD - state: %d, timeout: %d ms\n", in trf7970a_tg_listen_md()
1811 trf->state, timeout); in trf7970a_tg_listen_md()
1828 const struct trf7970a *trf = nfc_digital_get_drvdata(ddev); in trf7970a_tg_get_rf_tech() local
1830 dev_dbg(trf->dev, "Get RF Tech - state: %d, rf_tech: %d\n", in trf7970a_tg_get_rf_tech()
1831 trf->state, trf->md_rf_tech); in trf7970a_tg_get_rf_tech()
1833 *rf_tech = trf->md_rf_tech; in trf7970a_tg_get_rf_tech()
1840 struct trf7970a *trf = nfc_digital_get_drvdata(ddev); in trf7970a_abort_cmd() local
1842 dev_dbg(trf->dev, "Abort process initiated\n"); in trf7970a_abort_cmd()
1844 mutex_lock(&trf->lock); in trf7970a_abort_cmd()
1846 switch (trf->state) { in trf7970a_abort_cmd()
1851 trf->aborting = true; in trf7970a_abort_cmd()
1854 trf->ignore_timeout = !cancel_delayed_work(&trf->timeout_work); in trf7970a_abort_cmd()
1855 trf7970a_send_err_upstream(trf, -ECANCELED); in trf7970a_abort_cmd()
1856 dev_dbg(trf->dev, "Abort process complete\n"); in trf7970a_abort_cmd()
1862 mutex_unlock(&trf->lock); in trf7970a_abort_cmd()
1877 static int trf7970a_power_up(struct trf7970a *trf) in trf7970a_power_up() argument
1881 dev_dbg(trf->dev, "Powering up - state: %d\n", trf->state); in trf7970a_power_up()
1883 if (trf->state != TRF7970A_ST_PWR_OFF) in trf7970a_power_up()
1886 ret = regulator_enable(trf->regulator); in trf7970a_power_up()
1888 dev_err(trf->dev, "%s - Can't enable VIN: %d\n", __func__, ret); in trf7970a_power_up()
1894 if (trf->en2_gpiod && in trf7970a_power_up()
1895 !(trf->quirks & TRF7970A_QUIRK_EN2_MUST_STAY_LOW)) { in trf7970a_power_up()
1896 gpiod_set_value_cansleep(trf->en2_gpiod, 1); in trf7970a_power_up()
1900 gpiod_set_value_cansleep(trf->en_gpiod, 1); in trf7970a_power_up()
1904 trf->state = TRF7970A_ST_RF_OFF; in trf7970a_power_up()
1909 static int trf7970a_power_down(struct trf7970a *trf) in trf7970a_power_down() argument
1913 dev_dbg(trf->dev, "Powering down - state: %d\n", trf->state); in trf7970a_power_down()
1915 if (trf->state == TRF7970A_ST_PWR_OFF) in trf7970a_power_down()
1918 if (trf->state != TRF7970A_ST_RF_OFF) { in trf7970a_power_down()
1919 dev_dbg(trf->dev, "Can't power down - not RF_OFF state (%d)\n", in trf7970a_power_down()
1920 trf->state); in trf7970a_power_down()
1924 gpiod_set_value_cansleep(trf->en_gpiod, 0); in trf7970a_power_down()
1926 if (trf->en2_gpiod && !(trf->quirks & TRF7970A_QUIRK_EN2_MUST_STAY_LOW)) in trf7970a_power_down()
1927 gpiod_set_value_cansleep(trf->en2_gpiod, 0); in trf7970a_power_down()
1929 ret = regulator_disable(trf->regulator); in trf7970a_power_down()
1931 dev_err(trf->dev, "%s - Can't disable VIN: %d\n", __func__, in trf7970a_power_down()
1934 trf->state = TRF7970A_ST_PWR_OFF; in trf7970a_power_down()
1939 static int trf7970a_startup(struct trf7970a *trf) in trf7970a_startup() argument
1943 ret = trf7970a_power_up(trf); in trf7970a_startup()
1947 pm_runtime_set_active(trf->dev); in trf7970a_startup()
1948 pm_runtime_enable(trf->dev); in trf7970a_startup()
1949 pm_runtime_mark_last_busy(trf->dev); in trf7970a_startup()
1954 static void trf7970a_shutdown(struct trf7970a *trf) in trf7970a_shutdown() argument
1956 switch (trf->state) { in trf7970a_shutdown()
1962 trf7970a_send_err_upstream(trf, -ECANCELED); in trf7970a_shutdown()
1966 trf7970a_switch_rf_off(trf); in trf7970a_shutdown()
1972 pm_runtime_disable(trf->dev); in trf7970a_shutdown()
1973 pm_runtime_set_suspended(trf->dev); in trf7970a_shutdown()
1975 trf7970a_power_down(trf); in trf7970a_shutdown()
1992 struct trf7970a *trf; in trf7970a_probe() local
2001 trf = devm_kzalloc(&spi->dev, sizeof(*trf), GFP_KERNEL); in trf7970a_probe()
2002 if (!trf) in trf7970a_probe()
2005 trf->state = TRF7970A_ST_PWR_OFF; in trf7970a_probe()
2006 trf->dev = &spi->dev; in trf7970a_probe()
2007 trf->spi = spi; in trf7970a_probe()
2014 dev_err(trf->dev, "Can't set up SPI Communication\n"); in trf7970a_probe()
2019 trf->quirks |= TRF7970A_QUIRK_IRQ_STATUS_READ; in trf7970a_probe()
2022 trf->en_gpiod = devm_gpiod_get_index(trf->dev, "ti,enable", 0, in trf7970a_probe()
2024 if (IS_ERR(trf->en_gpiod)) { in trf7970a_probe()
2025 dev_err(trf->dev, "No EN GPIO property\n"); in trf7970a_probe()
2026 return PTR_ERR(trf->en_gpiod); in trf7970a_probe()
2029 trf->en2_gpiod = devm_gpiod_get_index_optional(trf->dev, "ti,enable", 1, in trf7970a_probe()
2031 if (!trf->en2_gpiod) { in trf7970a_probe()
2032 dev_info(trf->dev, "No EN2 GPIO property\n"); in trf7970a_probe()
2033 } else if (IS_ERR(trf->en2_gpiod)) { in trf7970a_probe()
2034 dev_err(trf->dev, "Error getting EN2 GPIO property: %ld\n", in trf7970a_probe()
2035 PTR_ERR(trf->en2_gpiod)); in trf7970a_probe()
2036 return PTR_ERR(trf->en2_gpiod); in trf7970a_probe()
2038 trf->quirks |= TRF7970A_QUIRK_EN2_MUST_STAY_LOW; in trf7970a_probe()
2044 dev_err(trf->dev, in trf7970a_probe()
2050 trf->modulator_sys_clk_ctrl = TRF7970A_MODULATOR_27MHZ; in trf7970a_probe()
2051 dev_dbg(trf->dev, "trf7970a configured for 27MHz crystal\n"); in trf7970a_probe()
2053 trf->modulator_sys_clk_ctrl = 0; in trf7970a_probe()
2056 ret = devm_request_threaded_irq(trf->dev, spi->irq, NULL, in trf7970a_probe()
2059 "trf7970a", trf); in trf7970a_probe()
2061 dev_err(trf->dev, "Can't request IRQ#%d: %d\n", spi->irq, ret); in trf7970a_probe()
2065 mutex_init(&trf->lock); in trf7970a_probe()
2066 INIT_DELAYED_WORK(&trf->timeout_work, trf7970a_timeout_work_handler); in trf7970a_probe()
2068 trf->regulator = devm_regulator_get(&spi->dev, "vin"); in trf7970a_probe()
2069 if (IS_ERR(trf->regulator)) { in trf7970a_probe()
2070 ret = PTR_ERR(trf->regulator); in trf7970a_probe()
2071 dev_err(trf->dev, "Can't get VIN regulator: %d\n", ret); in trf7970a_probe()
2075 ret = regulator_enable(trf->regulator); in trf7970a_probe()
2077 dev_err(trf->dev, "Can't enable VIN: %d\n", ret); in trf7970a_probe()
2081 uvolts = regulator_get_voltage(trf->regulator); in trf7970a_probe()
2083 trf->chip_status_ctrl = TRF7970A_CHIP_STATUS_VRS5_3; in trf7970a_probe()
2085 trf->regulator = devm_regulator_get(&spi->dev, "vdd-io"); in trf7970a_probe()
2086 if (IS_ERR(trf->regulator)) { in trf7970a_probe()
2087 ret = PTR_ERR(trf->regulator); in trf7970a_probe()
2088 dev_err(trf->dev, "Can't get VDD_IO regulator: %d\n", ret); in trf7970a_probe()
2092 ret = regulator_enable(trf->regulator); in trf7970a_probe()
2094 dev_err(trf->dev, "Can't enable VDD_IO: %d\n", ret); in trf7970a_probe()
2098 if (regulator_get_voltage(trf->regulator) == 1800000) { in trf7970a_probe()
2099 trf->io_ctrl = TRF7970A_REG_IO_CTRL_IO_LOW; in trf7970a_probe()
2100 dev_dbg(trf->dev, "trf7970a config vdd_io to 1.8V\n"); in trf7970a_probe()
2103 trf->ddev = nfc_digital_allocate_device(&trf7970a_nfc_ops, in trf7970a_probe()
2108 if (!trf->ddev) { in trf7970a_probe()
2109 dev_err(trf->dev, "Can't allocate NFC digital device\n"); in trf7970a_probe()
2114 nfc_digital_set_parent_dev(trf->ddev, trf->dev); in trf7970a_probe()
2115 nfc_digital_set_drvdata(trf->ddev, trf); in trf7970a_probe()
2116 spi_set_drvdata(spi, trf); in trf7970a_probe()
2120 pm_runtime_set_autosuspend_delay(trf->dev, autosuspend_delay); in trf7970a_probe()
2121 pm_runtime_use_autosuspend(trf->dev); in trf7970a_probe()
2123 ret = trf7970a_startup(trf); in trf7970a_probe()
2127 ret = nfc_digital_register_device(trf->ddev); in trf7970a_probe()
2129 dev_err(trf->dev, "Can't register NFC digital device: %d\n", in trf7970a_probe()
2137 trf7970a_shutdown(trf); in trf7970a_probe()
2139 nfc_digital_free_device(trf->ddev); in trf7970a_probe()
2141 regulator_disable(trf->regulator); in trf7970a_probe()
2143 mutex_destroy(&trf->lock); in trf7970a_probe()
2149 struct trf7970a *trf = spi_get_drvdata(spi); in trf7970a_remove() local
2151 mutex_lock(&trf->lock); in trf7970a_remove()
2153 trf7970a_shutdown(trf); in trf7970a_remove()
2155 mutex_unlock(&trf->lock); in trf7970a_remove()
2157 nfc_digital_unregister_device(trf->ddev); in trf7970a_remove()
2158 nfc_digital_free_device(trf->ddev); in trf7970a_remove()
2160 regulator_disable(trf->regulator); in trf7970a_remove()
2162 mutex_destroy(&trf->lock); in trf7970a_remove()
2169 struct trf7970a *trf = spi_get_drvdata(spi); in trf7970a_suspend() local
2171 mutex_lock(&trf->lock); in trf7970a_suspend()
2173 trf7970a_shutdown(trf); in trf7970a_suspend()
2175 mutex_unlock(&trf->lock); in trf7970a_suspend()
2183 struct trf7970a *trf = spi_get_drvdata(spi); in trf7970a_resume() local
2186 mutex_lock(&trf->lock); in trf7970a_resume()
2188 ret = trf7970a_startup(trf); in trf7970a_resume()
2190 mutex_unlock(&trf->lock); in trf7970a_resume()
2200 struct trf7970a *trf = spi_get_drvdata(spi); in trf7970a_pm_runtime_suspend() local
2203 mutex_lock(&trf->lock); in trf7970a_pm_runtime_suspend()
2205 ret = trf7970a_power_down(trf); in trf7970a_pm_runtime_suspend()
2207 mutex_unlock(&trf->lock); in trf7970a_pm_runtime_suspend()
2215 struct trf7970a *trf = spi_get_drvdata(spi); in trf7970a_pm_runtime_resume() local
2218 ret = trf7970a_power_up(trf); in trf7970a_pm_runtime_resume()