Lines Matching +full:en2 +full:- +full:rf +full:- +full:quirk

1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com
32 * The trf7970a is very timing sensitive and the VIN, EN2, and EN
36 * version of the trf7970a that requires that EN2 remain low no matter
37 * what. If it goes high, it will generate an RF field even when in
39 * when EN2 is left low. The 'en2-rf-quirk' device tree property
41 * that EN2 must be kept low.
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
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
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
130 /* TX length is 3 nibbles long ==> 4KB - 1 bytes max */
131 #define TRF7970A_TX_MAX (4096 - 1)
138 /* Guard times for various RF technologies (in us) */
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()
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()
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()
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()
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()
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()
596 dev_dbg(trf->dev, "%s - mode_detect: target_proto: 0x%x\n", in trf7970a_mode_detect()
598 return -EIO; in trf7970a_mode_detect()
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()
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()
656 16, 1, skb->data, len, false); in trf7970a_transmit()
666 t[1].tx_buf = skb->data; in trf7970a_transmit()
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()
679 if (skb->len > 0) { 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()
706 struct sk_buff *skb = trf->tx_skb; in trf7970a_fill_fifo()
718 dev_dbg(trf->dev, "Filling FIFO - fifo_bytes: 0x%x\n", fifo_bytes); in trf7970a_fill_fifo()
723 len = TRF7970A_FIFO_SIZE - fifo_bytes; in trf7970a_fill_fifo()
725 schedule_delayed_work(&trf->timeout_work, in trf7970a_fill_fifo()
730 len = min(skb->len, len); in trf7970a_fill_fifo()
741 struct sk_buff *skb = trf->rx_skb; in trf7970a_drain_fifo()
746 trf7970a_send_err_upstream(trf, -EIO); 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()
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()
787 skb->data[0] >>= 4; in trf7970a_drain_fifo()
790 trf->state = TRF7970A_ST_WAIT_FOR_RX_DATA_CONT; 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()
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()
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()
851 /* If initiator and getting interrupts caused by RF noise, in trf7970a_irq()
856 if (trf->is_initiator && (status & TRF7970A_IRQ_STATUS_ERROR)) { in trf7970a_irq()
858 trf->state = TRF7970A_ST_IDLE_RX_BLOCKED; in trf7970a_irq()
865 trf->ignore_timeout = in trf7970a_irq()
866 !cancel_delayed_work(&trf->timeout_work); 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()
889 (!trf->is_initiator && 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()
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()
925 trf->special_fcn_reg1 = in trf7970a_irq()
932 if (iso_ctrl != trf->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()
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()
966 trf->state = TRF7970A_ST_LISTENING; 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()
987 dev_dbg(trf->dev, "Issuing EOF\n"); 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()
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()
1020 else if (trf->state == TRF7970A_ST_WAIT_TO_ISSUE_EOF) 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()
1032 dev_dbg(trf->dev, "Initializing device - state: %d\n", trf->state); in trf7970a_init()
1043 trf->io_ctrl | TRF7970A_REG_IO_CTRL_VRS(0x1)); in trf7970a_init()
1053 trf->chip_status_ctrl &= ~TRF7970A_CHIP_STATUS_RF_ON; in trf7970a_init()
1056 trf->modulator_sys_clk_ctrl); 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()
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()
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()
1110 return -EINVAL; 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()
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()
1143 dev_err(trf->dev, "%s - Invalid request: %d %d\n", in trf7970a_switch_rf()
1144 __func__, trf->state, on); in trf7970a_switch_rf()
1146 ret = -EINVAL; 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()
1156 ret = -EINVAL; in trf7970a_switch_rf()
1166 mutex_unlock(&trf->lock); in trf7970a_switch_rf()
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()
1214 return -EINVAL; in trf7970a_in_config_rf_tech()
1217 trf->technology = tech; in trf7970a_in_config_rf_tech()
1219 /* If in initiator mode and not changing the RF tech due to a in trf7970a_in_config_rf_tech()
1220 * PSL sequence (indicated by 'trf->iso_ctrl == 0xff' from in trf7970a_in_config_rf_tech()
1224 if (trf->iso_ctrl == 0xff) in trf7970a_in_config_rf_tech()
1236 trf->chip_status_ctrl | in trf7970a_is_rf_field()
1252 trf->chip_status_ctrl); in trf7970a_is_rf_field()
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()
1297 return -EINVAL; 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()
1308 return -EBUSY; in trf7970a_in_config_framing()
1311 if (iso_ctrl != trf->iso_ctrl) { in trf7970a_in_config_framing()
1316 trf->iso_ctrl = iso_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()
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()
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()
1366 dev_dbg(trf->dev, "Unknown type: %d\n", type); in trf7970a_in_configure_hw()
1367 ret = -EINVAL; in trf7970a_in_configure_hw()
1371 mutex_unlock(&trf->lock); in trf7970a_in_configure_hw()
1394 const u8 *req = skb->data; in trf7970a_per_cmd_config()
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()
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()
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()
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()
1473 if (skb->len > TRF7970A_TX_MAX) in trf7970a_send_cmd()
1474 return -EINVAL; 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()
1482 ret = -EIO; 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()
1489 ret = -ECANCELED; 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()
1498 ret = -ENOMEM; in trf7970a_send_cmd()
1503 if (trf->state == TRF7970A_ST_IDLE_RX_BLOCKED) { in trf7970a_send_cmd()
1508 trf->state = TRF7970A_ST_IDLE; in trf7970a_send_cmd()
1511 if (trf->is_initiator) { 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()
1524 len = skb->len; 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()
1546 len = min_t(int, skb->len, TRF7970A_FIFO_SIZE); 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()
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()
1594 return -EINVAL; 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()
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()
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()
1651 return -EINVAL; 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()
1661 trf->iso_ctrl = iso_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()
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()
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()
1709 dev_dbg(trf->dev, "Unknown type: %d\n", type); in trf7970a_tg_configure_hw()
1710 ret = -EINVAL; in trf7970a_tg_configure_hw()
1714 mutex_unlock(&trf->lock); in trf7970a_tg_configure_hw()
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()
1731 ret = -EIO; 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()
1738 ret = -ECANCELED; 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()
1746 ret = -ENOMEM; in _trf7970a_tg_listen()
1759 trf->io_ctrl | TRF7970A_REG_IO_CTRL_VRS(0x1)); 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()
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()
1798 dev_dbg(trf->dev, "Listen - state: %d, timeout: %d ms\n", in trf7970a_tg_listen()
1799 trf->state, timeout); in trf7970a_tg_listen()
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()
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()
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()
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()
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()
1922 return -EBUSY; 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()
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()
1957 switch (trf->state) { in trf7970a_shutdown()
1963 trf7970a_send_err_upstream(trf, -ECANCELED); in trf7970a_shutdown()
1973 pm_runtime_disable(trf->dev); in trf7970a_shutdown()
1974 pm_runtime_set_suspended(trf->dev); in trf7970a_shutdown()
1983 ret = of_property_read_u32(np, "autosuspend-delay", &autosuspend_delay); in trf7970a_get_autosuspend_delay()
1992 const struct device_node *np = spi->dev.of_node; in trf7970a_probe()
1998 dev_err(&spi->dev, "No Device Tree entry\n"); in trf7970a_probe()
1999 return -EINVAL; in trf7970a_probe()
2002 trf = devm_kzalloc(&spi->dev, sizeof(*trf), GFP_KERNEL); in trf7970a_probe()
2004 return -ENOMEM; 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()
2010 spi->mode = SPI_MODE_1; in trf7970a_probe()
2011 spi->bits_per_word = 8; in trf7970a_probe()
2015 dev_err(trf->dev, "Can't set up SPI Communication\n"); in trf7970a_probe()
2019 if (of_property_read_bool(np, "irq-status-read-quirk")) in trf7970a_probe()
2020 trf->quirks |= TRF7970A_QUIRK_IRQ_STATUS_READ; in trf7970a_probe()
2022 /* There are two enable pins - only EN must be present in the DT */ 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()
2038 } else if (of_property_read_bool(np, "en2-rf-quirk")) { in trf7970a_probe()
2039 trf->quirks |= TRF7970A_QUIRK_EN2_MUST_STAY_LOW; in trf7970a_probe()
2042 of_property_read_u32(np, "clock-frequency", &clk_freq); in trf7970a_probe()
2045 dev_err(trf->dev, in trf7970a_probe()
2046 "clock-frequency (%u Hz) unsupported\n", clk_freq); in trf7970a_probe()
2047 return -EINVAL; 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()
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()
2111 ret = -ENOMEM; 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()
2121 pm_runtime_set_autosuspend_delay(trf->dev, autosuspend_delay); in trf7970a_probe()
2122 pm_runtime_use_autosuspend(trf->dev); 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()
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()
2154 mutex_lock(&trf->lock); 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()
2175 mutex_lock(&trf->lock); in trf7970a_suspend()
2179 mutex_unlock(&trf->lock); in trf7970a_suspend()
2190 mutex_lock(&trf->lock); in trf7970a_resume()
2194 mutex_unlock(&trf->lock); in trf7970a_resume()
2207 mutex_lock(&trf->lock); in trf7970a_pm_runtime_suspend()
2211 mutex_unlock(&trf->lock); in trf7970a_pm_runtime_suspend()