Lines Matching +full:timeout +full:- +full:ms

1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com
39 * when EN2 is left low. The 'en2-rf-quirk' device tree property
46 * interrupts, however. That is, an interrupt and a timeout could occur
48 * executes. When the timeout handler executes first and blocks the
51 * When the interrupt handler executes first and blocks the timeout handler,
53 * work item (i.e., timeout) and will return zero. That return code is
54 * used by the timer handler to indicate that it should ignore the timeout
62 * has sent the command to the tag, it simply returns -ECANCELED. If the
65 * sending the data upstream, it frees the rx_skb and sends -ECANCELED
73 * those cases, the timeout mechanism is used to wait 20 ms in case more
74 * data arrives. After 20 ms, it is assumed that all of the data has been
78 * if there is more coming so a timeout in this state means all data has
79 * been received and there isn't an error). The delay is 20 ms since delays
80 * of ~16 ms have been observed during testing.
83 * driver will wait 20 ms for the FIFO to drain past the low-watermark
84 * and generate an interrupt. The low-watermark set to 32 bytes so the
85 * interrupt should fire after 127 - 32 = 95 bytes have been sent. At
87 * to ~14.35 ms so 20 ms is used for the timeout.
89 * Type 2 write and sector select commands respond with a 4-bit ACK or NACK.
99 * ISO/IEC 15693 frames specify whether to use single or double sub-carrier
108 * Note under Table 1-1 in section 1.6 of
110 * 10 ms for TI Tag-it HF-I tags; however testing has shown that is not long
111 * enough so 20 ms is used. So the timer is set to 40 ms - 20 ms to drain
112 * up to 127 bytes in the FIFO at the lowest bit rate plus another 20 ms to
130 /* TX length is 3 nibbles long ==> 4KB - 1 bytes max */
131 #define TRF7970A_TX_MAX (4096 - 1)
451 unsigned int timeout; member
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()
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()
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()
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()
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()
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()
595 dev_dbg(trf->dev, "%s - mode_detect: target_proto: 0x%x\n", in trf7970a_mode_detect()
597 return -EIO; in trf7970a_mode_detect()
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()
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()
651 unsigned int timeout; in trf7970a_transmit() local
655 16, 1, skb->data, len, false); in trf7970a_transmit()
665 t[1].tx_buf = skb->data; in trf7970a_transmit()
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()
678 if (skb->len > 0) { in trf7970a_transmit()
679 trf->state = TRF7970A_ST_WAIT_FOR_TX_FIFO; in trf7970a_transmit()
680 timeout = TRF7970A_WAIT_FOR_FIFO_DRAIN_TIMEOUT; in trf7970a_transmit()
682 if (trf->issue_eof) { in trf7970a_transmit()
683 trf->state = TRF7970A_ST_WAIT_TO_ISSUE_EOF; in trf7970a_transmit()
684 timeout = TRF7970A_WAIT_TO_ISSUE_ISO15693_EOF; in trf7970a_transmit()
686 trf->state = TRF7970A_ST_WAIT_FOR_RX_DATA; in trf7970a_transmit()
688 if (!trf->timeout) in trf7970a_transmit()
689 timeout = TRF7970A_WAIT_FOR_TX_IRQ; 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()
705 struct sk_buff *skb = trf->tx_skb; in trf7970a_fill_fifo()
717 dev_dbg(trf->dev, "Filling FIFO - fifo_bytes: 0x%x\n", fifo_bytes); in trf7970a_fill_fifo()
722 len = TRF7970A_FIFO_SIZE - fifo_bytes; in trf7970a_fill_fifo()
724 schedule_delayed_work(&trf->timeout_work, in trf7970a_fill_fifo()
729 len = min(skb->len, len); in trf7970a_fill_fifo()
740 struct sk_buff *skb = trf->rx_skb; in trf7970a_drain_fifo()
745 trf7970a_send_err_upstream(trf, -EIO); 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()
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()
786 skb->data[0] >>= 4; in trf7970a_drain_fifo()
789 trf->state = TRF7970A_ST_WAIT_FOR_RX_DATA_CONT; 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()
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()
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()
857 trf->state = TRF7970A_ST_IDLE_RX_BLOCKED; in trf7970a_irq()
864 trf->ignore_timeout = in trf7970a_irq()
865 !cancel_delayed_work(&trf->timeout_work); 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()
888 (!trf->is_initiator && 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()
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()
924 trf->special_fcn_reg1 = in trf7970a_irq()
931 if (iso_ctrl != trf->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()
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()
965 trf->state = TRF7970A_ST_LISTENING; 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()
986 dev_dbg(trf->dev, "Issuing EOF\n"); 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()
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()
1019 else if (trf->state == TRF7970A_ST_WAIT_TO_ISSUE_EOF) 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()
1031 dev_dbg(trf->dev, "Initializing device - state: %d\n", trf->state); in trf7970a_init()
1042 trf->io_ctrl | TRF7970A_REG_IO_CTRL_VRS(0x1)); in trf7970a_init()
1052 trf->chip_status_ctrl &= ~TRF7970A_CHIP_STATUS_RF_ON; in trf7970a_init()
1055 trf->modulator_sys_clk_ctrl); 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()
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()
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()
1109 return -EINVAL; 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()
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()
1142 dev_err(trf->dev, "%s - Invalid request: %d %d\n", in trf7970a_switch_rf()
1143 __func__, trf->state, on); in trf7970a_switch_rf()
1145 ret = -EINVAL; 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()
1155 ret = -EINVAL; in trf7970a_switch_rf()
1165 mutex_unlock(&trf->lock); in trf7970a_switch_rf()
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()
1213 return -EINVAL; in trf7970a_in_config_rf_tech()
1216 trf->technology = tech; in trf7970a_in_config_rf_tech()
1219 * PSL sequence (indicated by 'trf->iso_ctrl == 0xff' from in trf7970a_in_config_rf_tech()
1223 if (trf->iso_ctrl == 0xff) in trf7970a_in_config_rf_tech()
1235 trf->chip_status_ctrl | in trf7970a_is_rf_field()
1251 trf->chip_status_ctrl); in trf7970a_is_rf_field()
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()
1296 return -EINVAL; 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()
1307 return -EBUSY; in trf7970a_in_config_framing()
1310 if (iso_ctrl != trf->iso_ctrl) { in trf7970a_in_config_framing()
1315 trf->iso_ctrl = iso_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()
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()
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()
1365 dev_dbg(trf->dev, "Unknown type: %d\n", type); in trf7970a_in_configure_hw()
1366 ret = -EINVAL; in trf7970a_in_configure_hw()
1370 mutex_unlock(&trf->lock); in trf7970a_in_configure_hw()
1392 u8 *req = skb->data; in trf7970a_per_cmd_config()
1396 trf->issue_eof = false; in trf7970a_per_cmd_config()
1407 if ((trf->technology == NFC_DIGITAL_RF_TECH_106A) && in trf7970a_per_cmd_config()
1408 (trf->framing == NFC_DIGITAL_FRAMING_NFCA_T2T)) { in trf7970a_per_cmd_config()
1414 if (special_fcn_reg1 != trf->special_fcn_reg1) { in trf7970a_per_cmd_config()
1420 trf->special_fcn_reg1 = special_fcn_reg1; in trf7970a_per_cmd_config()
1422 } else if (trf->technology == NFC_DIGITAL_RF_TECH_ISO15693) { in trf7970a_per_cmd_config()
1423 iso_ctrl = trf->iso_ctrl & ~TRF7970A_ISO_CTRL_RFID_SPEED_MASK; in trf7970a_per_cmd_config()
1441 if (iso_ctrl != trf->iso_ctrl) { in trf7970a_per_cmd_config()
1446 trf->iso_ctrl = iso_ctrl; in trf7970a_per_cmd_config()
1449 if ((trf->framing == NFC_DIGITAL_FRAMING_ISO15693_T5T) && in trf7970a_per_cmd_config()
1452 trf->issue_eof = true; in trf7970a_per_cmd_config()
1459 struct sk_buff *skb, u16 timeout, in trf7970a_send_cmd() argument
1468 dev_dbg(trf->dev, "New request - state: %d, timeout: %d ms, len: %d\n", in trf7970a_send_cmd()
1469 trf->state, timeout, skb->len); in trf7970a_send_cmd()
1471 if (skb->len > TRF7970A_TX_MAX) in trf7970a_send_cmd()
1472 return -EINVAL; in trf7970a_send_cmd()
1474 mutex_lock(&trf->lock); in trf7970a_send_cmd()
1476 if ((trf->state != TRF7970A_ST_IDLE) && in trf7970a_send_cmd()
1477 (trf->state != TRF7970A_ST_IDLE_RX_BLOCKED)) { in trf7970a_send_cmd()
1478 dev_err(trf->dev, "%s - Bogus state: %d\n", __func__, in trf7970a_send_cmd()
1479 trf->state); in trf7970a_send_cmd()
1480 ret = -EIO; in trf7970a_send_cmd()
1484 if (trf->aborting) { in trf7970a_send_cmd()
1485 dev_dbg(trf->dev, "Abort process complete\n"); in trf7970a_send_cmd()
1486 trf->aborting = false; in trf7970a_send_cmd()
1487 ret = -ECANCELED; in trf7970a_send_cmd()
1491 if (timeout) { in trf7970a_send_cmd()
1492 trf->rx_skb = nfc_alloc_recv_skb(TRF7970A_RX_SKB_ALLOC_SIZE, in trf7970a_send_cmd()
1494 if (!trf->rx_skb) { in trf7970a_send_cmd()
1495 dev_dbg(trf->dev, "Can't alloc rx_skb\n"); in trf7970a_send_cmd()
1496 ret = -ENOMEM; in trf7970a_send_cmd()
1501 if (trf->state == TRF7970A_ST_IDLE_RX_BLOCKED) { in trf7970a_send_cmd()
1506 trf->state = TRF7970A_ST_IDLE; in trf7970a_send_cmd()
1509 if (trf->is_initiator) { in trf7970a_send_cmd()
1515 trf->ddev = ddev; in trf7970a_send_cmd()
1516 trf->tx_skb = skb; in trf7970a_send_cmd()
1517 trf->cb = cb; in trf7970a_send_cmd()
1518 trf->cb_arg = arg; in trf7970a_send_cmd()
1519 trf->timeout = timeout; in trf7970a_send_cmd()
1520 trf->ignore_timeout = false; in trf7970a_send_cmd()
1522 len = skb->len; in trf7970a_send_cmd()
1532 TRF7970A_CMD_BIT_OPCODE(trf->tx_cmd); in trf7970a_send_cmd()
1535 if (trf->framing == NFC_DIGITAL_FRAMING_NFCA_SHORT) { in trf7970a_send_cmd()
1544 len = min_t(int, skb->len, TRF7970A_FIFO_SIZE); in trf7970a_send_cmd()
1553 kfree_skb(trf->rx_skb); in trf7970a_send_cmd()
1554 trf->rx_skb = NULL; in trf7970a_send_cmd()
1558 mutex_unlock(&trf->lock); in trf7970a_send_cmd()
1566 dev_dbg(trf->dev, "rf technology: %d\n", tech); in trf7970a_tg_config_rf_tech()
1570 trf->iso_ctrl_tech = TRF7970A_ISO_CTRL_NFC_NFC_CE_MODE | in trf7970a_tg_config_rf_tech()
1572 trf->modulator_sys_clk_ctrl = in trf7970a_tg_config_rf_tech()
1573 (trf->modulator_sys_clk_ctrl & 0xf8) | in trf7970a_tg_config_rf_tech()
1577 trf->iso_ctrl_tech = TRF7970A_ISO_CTRL_NFC_NFC_CE_MODE | in trf7970a_tg_config_rf_tech()
1579 trf->modulator_sys_clk_ctrl = in trf7970a_tg_config_rf_tech()
1580 (trf->modulator_sys_clk_ctrl & 0xf8) | in trf7970a_tg_config_rf_tech()
1584 trf->iso_ctrl_tech = TRF7970A_ISO_CTRL_NFC_NFC_CE_MODE | in trf7970a_tg_config_rf_tech()
1586 trf->modulator_sys_clk_ctrl = in trf7970a_tg_config_rf_tech()
1587 (trf->modulator_sys_clk_ctrl & 0xf8) | in trf7970a_tg_config_rf_tech()
1591 dev_dbg(trf->dev, "Unsupported rf technology: %d\n", tech); in trf7970a_tg_config_rf_tech()
1592 return -EINVAL; in trf7970a_tg_config_rf_tech()
1595 trf->technology = tech; in trf7970a_tg_config_rf_tech()
1604 if ((trf->framing == NFC_DIGITAL_FRAMING_NFC_DEP_ACTIVATED) && in trf7970a_tg_config_rf_tech()
1605 (trf->iso_ctrl_tech != trf->iso_ctrl)) { in trf7970a_tg_config_rf_tech()
1607 trf->iso_ctrl_tech); in trf7970a_tg_config_rf_tech()
1609 trf->iso_ctrl = trf->iso_ctrl_tech; in trf7970a_tg_config_rf_tech()
1623 u8 iso_ctrl = trf->iso_ctrl_tech; in trf7970a_tg_config_framing()
1626 dev_dbg(trf->dev, "framing: %d\n", framing); in trf7970a_tg_config_framing()
1630 trf->tx_cmd = TRF7970A_CMD_TRANSMIT_NO_CRC; in trf7970a_tg_config_framing()
1637 iso_ctrl = trf->iso_ctrl; /* Don't write to ISO_CTRL yet */ in trf7970a_tg_config_framing()
1640 trf->tx_cmd = TRF7970A_CMD_TRANSMIT; in trf7970a_tg_config_framing()
1644 trf->tx_cmd = TRF7970A_CMD_TRANSMIT; in trf7970a_tg_config_framing()
1648 dev_dbg(trf->dev, "Unsupported Framing: %d\n", framing); in trf7970a_tg_config_framing()
1649 return -EINVAL; in trf7970a_tg_config_framing()
1652 trf->framing = framing; in trf7970a_tg_config_framing()
1654 if (iso_ctrl != trf->iso_ctrl) { in trf7970a_tg_config_framing()
1659 trf->iso_ctrl = iso_ctrl; in trf7970a_tg_config_framing()
1662 trf->modulator_sys_clk_ctrl); in trf7970a_tg_config_framing()
1667 if (!(trf->chip_status_ctrl & TRF7970A_CHIP_STATUS_RF_ON)) { in trf7970a_tg_config_framing()
1669 trf->chip_status_ctrl | in trf7970a_tg_config_framing()
1674 trf->chip_status_ctrl |= TRF7970A_CHIP_STATUS_RF_ON; in trf7970a_tg_config_framing()
1686 dev_dbg(trf->dev, "Configure hw - type: %d, param: %d\n", type, param); in trf7970a_tg_configure_hw()
1688 mutex_lock(&trf->lock); in trf7970a_tg_configure_hw()
1690 trf->is_initiator = false; in trf7970a_tg_configure_hw()
1692 if ((trf->state == TRF7970A_ST_PWR_OFF) || in trf7970a_tg_configure_hw()
1693 (trf->state == TRF7970A_ST_RF_OFF)) { in trf7970a_tg_configure_hw()
1707 dev_dbg(trf->dev, "Unknown type: %d\n", type); in trf7970a_tg_configure_hw()
1708 ret = -EINVAL; in trf7970a_tg_configure_hw()
1712 mutex_unlock(&trf->lock); in trf7970a_tg_configure_hw()
1716 static int _trf7970a_tg_listen(struct nfc_digital_dev *ddev, u16 timeout, in _trf7970a_tg_listen() argument
1723 mutex_lock(&trf->lock); in _trf7970a_tg_listen()
1725 if ((trf->state != TRF7970A_ST_IDLE) && in _trf7970a_tg_listen()
1726 (trf->state != TRF7970A_ST_IDLE_RX_BLOCKED)) { in _trf7970a_tg_listen()
1727 dev_err(trf->dev, "%s - Bogus state: %d\n", __func__, in _trf7970a_tg_listen()
1728 trf->state); in _trf7970a_tg_listen()
1729 ret = -EIO; in _trf7970a_tg_listen()
1733 if (trf->aborting) { in _trf7970a_tg_listen()
1734 dev_dbg(trf->dev, "Abort process complete\n"); in _trf7970a_tg_listen()
1735 trf->aborting = false; in _trf7970a_tg_listen()
1736 ret = -ECANCELED; in _trf7970a_tg_listen()
1740 trf->rx_skb = nfc_alloc_recv_skb(TRF7970A_RX_SKB_ALLOC_SIZE, in _trf7970a_tg_listen()
1742 if (!trf->rx_skb) { in _trf7970a_tg_listen()
1743 dev_dbg(trf->dev, "Can't alloc rx_skb\n"); in _trf7970a_tg_listen()
1744 ret = -ENOMEM; in _trf7970a_tg_listen()
1757 trf->io_ctrl | TRF7970A_REG_IO_CTRL_VRS(0x1)); in _trf7970a_tg_listen()
1771 trf->ddev = ddev; in _trf7970a_tg_listen()
1772 trf->cb = cb; in _trf7970a_tg_listen()
1773 trf->cb_arg = arg; in _trf7970a_tg_listen()
1774 trf->timeout = timeout; in _trf7970a_tg_listen()
1775 trf->ignore_timeout = false; in _trf7970a_tg_listen()
1781 trf->state = mode_detect ? TRF7970A_ST_LISTENING_MD : in _trf7970a_tg_listen()
1784 schedule_delayed_work(&trf->timeout_work, msecs_to_jiffies(timeout)); in _trf7970a_tg_listen()
1787 mutex_unlock(&trf->lock); in _trf7970a_tg_listen()
1791 static int trf7970a_tg_listen(struct nfc_digital_dev *ddev, u16 timeout, in trf7970a_tg_listen() argument
1796 dev_dbg(trf->dev, "Listen - state: %d, timeout: %d ms\n", in trf7970a_tg_listen()
1797 trf->state, timeout); in trf7970a_tg_listen()
1799 return _trf7970a_tg_listen(ddev, timeout, cb, arg, false); in trf7970a_tg_listen()
1803 u16 timeout, nfc_digital_cmd_complete_t cb, in trf7970a_tg_listen_md() argument
1809 dev_dbg(trf->dev, "Listen MD - state: %d, timeout: %d ms\n", in trf7970a_tg_listen_md()
1810 trf->state, timeout); in trf7970a_tg_listen_md()
1822 return _trf7970a_tg_listen(ddev, timeout, cb, arg, true); in trf7970a_tg_listen_md()
1829 dev_dbg(trf->dev, "Get RF Tech - state: %d, rf_tech: %d\n", in trf7970a_tg_get_rf_tech()
1830 trf->state, trf->md_rf_tech); in trf7970a_tg_get_rf_tech()
1832 *rf_tech = trf->md_rf_tech; in trf7970a_tg_get_rf_tech()
1841 dev_dbg(trf->dev, "Abort process initiated\n"); in trf7970a_abort_cmd()
1843 mutex_lock(&trf->lock); in trf7970a_abort_cmd()
1845 switch (trf->state) { in trf7970a_abort_cmd()
1850 trf->aborting = true; in trf7970a_abort_cmd()
1853 trf->ignore_timeout = !cancel_delayed_work(&trf->timeout_work); in trf7970a_abort_cmd()
1854 trf7970a_send_err_upstream(trf, -ECANCELED); in trf7970a_abort_cmd()
1855 dev_dbg(trf->dev, "Abort process complete\n"); in trf7970a_abort_cmd()
1861 mutex_unlock(&trf->lock); in trf7970a_abort_cmd()
1880 dev_dbg(trf->dev, "Powering up - state: %d\n", trf->state); in trf7970a_power_up()
1882 if (trf->state != TRF7970A_ST_PWR_OFF) in trf7970a_power_up()
1885 ret = regulator_enable(trf->regulator); in trf7970a_power_up()
1887 dev_err(trf->dev, "%s - Can't enable VIN: %d\n", __func__, ret); in trf7970a_power_up()
1893 if (trf->en2_gpiod && in trf7970a_power_up()
1894 !(trf->quirks & TRF7970A_QUIRK_EN2_MUST_STAY_LOW)) { in trf7970a_power_up()
1895 gpiod_set_value_cansleep(trf->en2_gpiod, 1); in trf7970a_power_up()
1899 gpiod_set_value_cansleep(trf->en_gpiod, 1); in trf7970a_power_up()
1903 trf->state = TRF7970A_ST_RF_OFF; in trf7970a_power_up()
1912 dev_dbg(trf->dev, "Powering down - state: %d\n", trf->state); in trf7970a_power_down()
1914 if (trf->state == TRF7970A_ST_PWR_OFF) in trf7970a_power_down()
1917 if (trf->state != TRF7970A_ST_RF_OFF) { in trf7970a_power_down()
1918 dev_dbg(trf->dev, "Can't power down - not RF_OFF state (%d)\n", in trf7970a_power_down()
1919 trf->state); in trf7970a_power_down()
1920 return -EBUSY; in trf7970a_power_down()
1923 gpiod_set_value_cansleep(trf->en_gpiod, 0); in trf7970a_power_down()
1925 if (trf->en2_gpiod && !(trf->quirks & TRF7970A_QUIRK_EN2_MUST_STAY_LOW)) in trf7970a_power_down()
1926 gpiod_set_value_cansleep(trf->en2_gpiod, 0); in trf7970a_power_down()
1928 ret = regulator_disable(trf->regulator); in trf7970a_power_down()
1930 dev_err(trf->dev, "%s - Can't disable VIN: %d\n", __func__, in trf7970a_power_down()
1933 trf->state = TRF7970A_ST_PWR_OFF; in trf7970a_power_down()
1946 pm_runtime_set_active(trf->dev); in trf7970a_startup()
1947 pm_runtime_enable(trf->dev); in trf7970a_startup()
1948 pm_runtime_mark_last_busy(trf->dev); in trf7970a_startup()
1955 switch (trf->state) { in trf7970a_shutdown()
1961 trf7970a_send_err_upstream(trf, -ECANCELED); in trf7970a_shutdown()
1971 pm_runtime_disable(trf->dev); in trf7970a_shutdown()
1972 pm_runtime_set_suspended(trf->dev); in trf7970a_shutdown()
1981 ret = of_property_read_u32(np, "autosuspend-delay", &autosuspend_delay); in trf7970a_get_autosuspend_delay()
1990 struct device_node *np = spi->dev.of_node; in trf7970a_probe()
1996 dev_err(&spi->dev, "No Device Tree entry\n"); in trf7970a_probe()
1997 return -EINVAL; in trf7970a_probe()
2000 trf = devm_kzalloc(&spi->dev, sizeof(*trf), GFP_KERNEL); in trf7970a_probe()
2002 return -ENOMEM; in trf7970a_probe()
2004 trf->state = TRF7970A_ST_PWR_OFF; in trf7970a_probe()
2005 trf->dev = &spi->dev; in trf7970a_probe()
2006 trf->spi = spi; in trf7970a_probe()
2008 spi->mode = SPI_MODE_1; in trf7970a_probe()
2009 spi->bits_per_word = 8; in trf7970a_probe()
2013 dev_err(trf->dev, "Can't set up SPI Communication\n"); in trf7970a_probe()
2017 if (of_property_read_bool(np, "irq-status-read-quirk")) in trf7970a_probe()
2018 trf->quirks |= TRF7970A_QUIRK_IRQ_STATUS_READ; in trf7970a_probe()
2020 /* There are two enable pins - only EN must be present in the DT */ in trf7970a_probe()
2021 trf->en_gpiod = devm_gpiod_get_index(trf->dev, "ti,enable", 0, in trf7970a_probe()
2023 if (IS_ERR(trf->en_gpiod)) { in trf7970a_probe()
2024 dev_err(trf->dev, "No EN GPIO property\n"); in trf7970a_probe()
2025 return PTR_ERR(trf->en_gpiod); in trf7970a_probe()
2028 trf->en2_gpiod = devm_gpiod_get_index_optional(trf->dev, "ti,enable", 1, in trf7970a_probe()
2030 if (!trf->en2_gpiod) { in trf7970a_probe()
2031 dev_info(trf->dev, "No EN2 GPIO property\n"); in trf7970a_probe()
2032 } else if (IS_ERR(trf->en2_gpiod)) { in trf7970a_probe()
2033 dev_err(trf->dev, "Error getting EN2 GPIO property: %ld\n", in trf7970a_probe()
2034 PTR_ERR(trf->en2_gpiod)); in trf7970a_probe()
2035 return PTR_ERR(trf->en2_gpiod); in trf7970a_probe()
2036 } else if (of_property_read_bool(np, "en2-rf-quirk")) { in trf7970a_probe()
2037 trf->quirks |= TRF7970A_QUIRK_EN2_MUST_STAY_LOW; in trf7970a_probe()
2040 of_property_read_u32(np, "clock-frequency", &clk_freq); in trf7970a_probe()
2043 dev_err(trf->dev, in trf7970a_probe()
2044 "clock-frequency (%u Hz) unsupported\n", clk_freq); in trf7970a_probe()
2045 return -EINVAL; in trf7970a_probe()
2049 trf->modulator_sys_clk_ctrl = TRF7970A_MODULATOR_27MHZ; in trf7970a_probe()
2050 dev_dbg(trf->dev, "trf7970a configured for 27MHz crystal\n"); in trf7970a_probe()
2052 trf->modulator_sys_clk_ctrl = 0; in trf7970a_probe()
2055 ret = devm_request_threaded_irq(trf->dev, spi->irq, NULL, in trf7970a_probe()
2060 dev_err(trf->dev, "Can't request IRQ#%d: %d\n", spi->irq, ret); in trf7970a_probe()
2064 mutex_init(&trf->lock); in trf7970a_probe()
2065 INIT_DELAYED_WORK(&trf->timeout_work, trf7970a_timeout_work_handler); in trf7970a_probe()
2067 trf->regulator = devm_regulator_get(&spi->dev, "vin"); in trf7970a_probe()
2068 if (IS_ERR(trf->regulator)) { in trf7970a_probe()
2069 ret = PTR_ERR(trf->regulator); in trf7970a_probe()
2070 dev_err(trf->dev, "Can't get VIN regulator: %d\n", ret); in trf7970a_probe()
2074 ret = regulator_enable(trf->regulator); in trf7970a_probe()
2076 dev_err(trf->dev, "Can't enable VIN: %d\n", ret); in trf7970a_probe()
2080 uvolts = regulator_get_voltage(trf->regulator); in trf7970a_probe()
2082 trf->chip_status_ctrl = TRF7970A_CHIP_STATUS_VRS5_3; in trf7970a_probe()
2084 trf->regulator = devm_regulator_get(&spi->dev, "vdd-io"); in trf7970a_probe()
2085 if (IS_ERR(trf->regulator)) { in trf7970a_probe()
2086 ret = PTR_ERR(trf->regulator); in trf7970a_probe()
2087 dev_err(trf->dev, "Can't get VDD_IO regulator: %d\n", ret); in trf7970a_probe()
2091 ret = regulator_enable(trf->regulator); in trf7970a_probe()
2093 dev_err(trf->dev, "Can't enable VDD_IO: %d\n", ret); in trf7970a_probe()
2097 if (regulator_get_voltage(trf->regulator) == 1800000) { in trf7970a_probe()
2098 trf->io_ctrl = TRF7970A_REG_IO_CTRL_IO_LOW; in trf7970a_probe()
2099 dev_dbg(trf->dev, "trf7970a config vdd_io to 1.8V\n"); in trf7970a_probe()
2102 trf->ddev = nfc_digital_allocate_device(&trf7970a_nfc_ops, in trf7970a_probe()
2107 if (!trf->ddev) { in trf7970a_probe()
2108 dev_err(trf->dev, "Can't allocate NFC digital device\n"); in trf7970a_probe()
2109 ret = -ENOMEM; in trf7970a_probe()
2113 nfc_digital_set_parent_dev(trf->ddev, trf->dev); in trf7970a_probe()
2114 nfc_digital_set_drvdata(trf->ddev, trf); in trf7970a_probe()
2119 pm_runtime_set_autosuspend_delay(trf->dev, autosuspend_delay); in trf7970a_probe()
2120 pm_runtime_use_autosuspend(trf->dev); in trf7970a_probe()
2126 ret = nfc_digital_register_device(trf->ddev); in trf7970a_probe()
2128 dev_err(trf->dev, "Can't register NFC digital device: %d\n", in trf7970a_probe()
2138 nfc_digital_free_device(trf->ddev); in trf7970a_probe()
2140 regulator_disable(trf->regulator); in trf7970a_probe()
2142 mutex_destroy(&trf->lock); in trf7970a_probe()
2150 mutex_lock(&trf->lock); in trf7970a_remove()
2154 mutex_unlock(&trf->lock); in trf7970a_remove()
2156 nfc_digital_unregister_device(trf->ddev); in trf7970a_remove()
2157 nfc_digital_free_device(trf->ddev); in trf7970a_remove()
2159 regulator_disable(trf->regulator); in trf7970a_remove()
2161 mutex_destroy(&trf->lock); in trf7970a_remove()
2174 mutex_lock(&trf->lock); in trf7970a_suspend()
2178 mutex_unlock(&trf->lock); in trf7970a_suspend()
2191 mutex_lock(&trf->lock); in trf7970a_resume()
2195 mutex_unlock(&trf->lock); in trf7970a_resume()
2210 mutex_lock(&trf->lock); in trf7970a_pm_runtime_suspend()
2214 mutex_unlock(&trf->lock); in trf7970a_pm_runtime_suspend()