Lines Matching +full:rx +full:- +full:frame +full:- +full:sync +full:- +full:delay +full:- +full:bits
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Analog Devices ADF7242 Low-Power IEEE 802.15.4 Transceiver
5 * Copyright 2009-2017 Analog Devices Inc.
13 #include <linux/delay.h>
39 #define REG_DELAYCFG0 0x109 /* RW RC_RX command to SFD or sync word delay */
41 #define REG_DELAYCFG2 0x10B /* RW Mac delay extension */
42 #define REG_SYNC_WORD0 0x10C /* RW sync word bits [7:0] of [23:0] */
43 #define REG_SYNC_WORD1 0x10D /* RW sync word bits [15:8] of [23:0] */
44 #define REG_SYNC_WORD2 0x10E /* RW sync word bits [23:16] of [23:0] */
45 #define REG_SYNC_CONFIG 0x10F /* RW sync word configuration */
46 #define REG_RC_CFG 0x13E /* RW RX / TX packet configuration */
48 #define REG_CH_FREQ0 0x300 /* RW Channel Frequency Settings - Low */
49 #define REG_CH_FREQ1 0x301 /* RW Channel Frequency Settings - Middle */
50 #define REG_CH_FREQ2 0x302 /* RW Channel Frequency Settings - High */
52 #define REG_DM_CFG0 0x305 /* RW RX Discriminator BW Register */
54 #define REG_RX_M 0x307 /* RW RX Mode Register */
57 #define REG_DR0 0x30E /* RW bits [15:8] of [15:0] data rate setting */
58 #define REG_DR1 0x30F /* RW bits [7:0] of [15:0] data rate setting */
61 #define REG_RXPB 0x315 /* RW RX Packet Storage Base Address */
62 #define REG_TMR_CFG0 0x316 /* RW Wake up Timer Conf Register - High */
63 #define REG_TMR_CFG1 0x317 /* RW Wake up Timer Conf Register - Low */
64 #define REG_TMR_RLD0 0x318 /* RW Wake up Timer Value Register - High */
65 #define REG_TMR_RLD1 0x319 /* RW Wake up Timer Value Register - Low */
79 #define REG_RXCAL0 0x395 /* RW RX BB filter tuning, LSB */
80 #define REG_RXCAL1 0x396 /* RW RX BB filter tuning, MSB */
95 #define REG_IRQ1_EN0 0x3C7 /* RW Interrupt Mask set bits for IRQ1 */
96 #define REG_IRQ1_EN1 0x3C8 /* RW Interrupt Mask set bits for IRQ1 */
97 #define REG_IRQ2_EN0 0x3C9 /* RW Interrupt Mask set bits for IRQ2 */
98 #define REG_IRQ2_EN1 0x3CA /* RW Interrupt Mask set bits for IRQ2 */
99 #define REG_IRQ1_SRC0 0x3CB /* RW Interrupt Source bits for IRQ */
100 #define REG_IRQ1_SRC1 0x3CC /* RW Interrupt Source bits for IRQ */
178 * starting from RX packet base address
209 * into RX state
218 #define CMD_RC_CSMACA 0xC1 /* initiates CSMA-CA channel access
219 * sequence and frame transmission
307 mutex_lock(&lp->bmux); in adf7242_status()
308 status = spi_sync(lp->spi, &lp->stat_msg); in adf7242_status()
309 *stat = lp->buf_stat_rx; in adf7242_status()
310 mutex_unlock(&lp->bmux); in adf7242_status()
327 ret = -ETIMEDOUT; in adf7242_wait_status()
338 dev_warn(&lp->spi->dev, in adf7242_wait_status()
343 dev_vdbg(&lp->spi->dev, "%s : loops=%d line %d\n", __func__, cnt, line); in adf7242_wait_status()
362 u8 *buf = lp->buf; in adf7242_write_fbuf()
381 mutex_lock(&lp->bmux); in adf7242_write_fbuf()
385 status = spi_sync(lp->spi, &msg); in adf7242_write_fbuf()
386 mutex_unlock(&lp->bmux); in adf7242_write_fbuf()
394 u8 *buf = lp->buf; in adf7242_read_fbuf()
413 mutex_lock(&lp->bmux); in adf7242_read_fbuf()
424 status = spi_sync(lp->spi, &msg); in adf7242_read_fbuf()
426 mutex_unlock(&lp->bmux); in adf7242_read_fbuf()
438 .tx_buf = lp->buf_read_tx, in adf7242_read_reg()
439 .rx_buf = lp->buf_read_rx, in adf7242_read_reg()
444 mutex_lock(&lp->bmux); in adf7242_read_reg()
445 lp->buf_read_tx[0] = CMD_SPI_MEM_RD(addr); in adf7242_read_reg()
446 lp->buf_read_tx[1] = addr; in adf7242_read_reg()
447 lp->buf_read_tx[2] = CMD_SPI_NOP; in adf7242_read_reg()
448 lp->buf_read_tx[3] = CMD_SPI_NOP; in adf7242_read_reg()
453 status = spi_sync(lp->spi, &msg); in adf7242_read_reg()
458 *data = lp->buf_read_rx[3]; in adf7242_read_reg()
460 mutex_unlock(&lp->bmux); in adf7242_read_reg()
462 dev_vdbg(&lp->spi->dev, "%s : REG 0x%X, VAL 0x%X\n", __func__, in adf7242_read_reg()
474 mutex_lock(&lp->bmux); in adf7242_write_reg()
475 lp->buf_reg_tx[0] = CMD_SPI_MEM_WR(addr); in adf7242_write_reg()
476 lp->buf_reg_tx[1] = addr; in adf7242_write_reg()
477 lp->buf_reg_tx[2] = data; in adf7242_write_reg()
478 status = spi_write(lp->spi, lp->buf_reg_tx, 3); in adf7242_write_reg()
479 mutex_unlock(&lp->bmux); in adf7242_write_reg()
481 dev_vdbg(&lp->spi->dev, "%s : REG 0x%X, VAL 0x%X\n", in adf7242_write_reg()
491 dev_vdbg(&lp->spi->dev, "%s : CMD=0x%X\n", __func__, cmd); in adf7242_cmd()
496 mutex_lock(&lp->bmux); in adf7242_cmd()
497 lp->buf_cmd = cmd; in adf7242_cmd()
498 status = spi_write(lp->spi, &lp->buf_cmd, 1); in adf7242_cmd()
499 mutex_unlock(&lp->bmux); in adf7242_cmd()
509 u8 *buf = lp->buf; in adf7242_upload_firmware()
523 for (i = len; i >= 0; i -= PRAM_PAGESIZE) { in adf7242_upload_firmware()
529 mutex_lock(&lp->bmux); in adf7242_upload_firmware()
530 status = spi_sync(lp->spi, &msg); in adf7242_upload_firmware()
531 mutex_unlock(&lp->bmux); in adf7242_upload_firmware()
547 return -ENOMEM; in adf7242_verify_firmware()
549 for (page = 0, i = len; i >= 0; i -= PRAM_PAGESIZE, page++) { in adf7242_verify_firmware()
558 return -EIO; in adf7242_verify_firmware()
579 mod_delayed_work(lp->wqueue, &lp->work, msecs_to_jiffies(400)); in adf7242_cmd_rx()
589 /* Reissuing RC_RX every 400ms - to adjust for offset in adf7242_rx_cal_work()
593 if (!test_bit(FLAG_XMIT, &lp->flags)) { in adf7242_rx_cal_work()
601 struct adf7242_local *lp = hw->priv; in adf7242_set_txpower()
605 dev_vdbg(&lp->spi->dev, "%s : Power %d dB\n", __func__, db); in adf7242_set_txpower()
607 if (db > 5 || db < -26) in adf7242_set_txpower()
608 return -EINVAL; in adf7242_set_txpower()
642 struct adf7242_local *lp = hw->priv; in adf7242_set_csma_params()
645 dev_vdbg(&lp->spi->dev, "%s : min_be=%d max_be=%d retries=%d\n", in adf7242_set_csma_params()
649 return -EINVAL; in adf7242_set_csma_params()
652 MAX_FRAME_RETRIES(lp->max_frame_retries) | in adf7242_set_csma_params()
657 lp->max_cca_retries = retries; in adf7242_set_csma_params()
658 lp->max_be = max_be; in adf7242_set_csma_params()
659 lp->min_be = min_be; in adf7242_set_csma_params()
667 struct adf7242_local *lp = hw->priv; in adf7242_set_frame_retries()
670 dev_vdbg(&lp->spi->dev, "%s : Retries = %d\n", __func__, retries); in adf7242_set_frame_retries()
672 if (retries < -1 || retries > 15) in adf7242_set_frame_retries()
673 return -EINVAL; in adf7242_set_frame_retries()
678 MAX_CCA_RETRIES(lp->max_cca_retries)); in adf7242_set_frame_retries()
680 lp->max_frame_retries = retries; in adf7242_set_frame_retries()
687 struct adf7242_local *lp = hw->priv; in adf7242_ed()
689 *level = lp->rssi; in adf7242_ed()
691 dev_vdbg(&lp->spi->dev, "%s :Exit level=%d\n", in adf7242_ed()
699 struct adf7242_local *lp = hw->priv; in adf7242_start()
703 enable_irq(lp->spi->irq); in adf7242_start()
704 set_bit(FLAG_START, &lp->flags); in adf7242_start()
711 struct adf7242_local *lp = hw->priv; in adf7242_stop()
713 disable_irq(lp->spi->irq); in adf7242_stop()
714 cancel_delayed_work_sync(&lp->work); in adf7242_stop()
716 clear_bit(FLAG_START, &lp->flags); in adf7242_stop()
722 struct adf7242_local *lp = hw->priv; in adf7242_channel()
725 dev_dbg(&lp->spi->dev, "%s :Channel=%d\n", __func__, channel); in adf7242_channel()
733 freq = (2405 + 5 * (channel - 11)) * 100; in adf7242_channel()
740 if (test_bit(FLAG_START, &lp->flags)) in adf7242_channel()
750 struct adf7242_local *lp = hw->priv; in adf7242_set_hw_addr_filt()
753 dev_dbg(&lp->spi->dev, "%s :Changed=0x%lX\n", __func__, changed); in adf7242_set_hw_addr_filt()
760 memcpy(addr, &filt->ieee_addr, 8); in adf7242_set_hw_addr_filt()
767 u16 saddr = le16_to_cpu(filt->short_addr); in adf7242_set_hw_addr_filt()
774 u16 pan_id = le16_to_cpu(filt->pan_id); in adf7242_set_hw_addr_filt()
782 if (filt->pan_coord) in adf7242_set_hw_addr_filt()
794 struct adf7242_local *lp = hw->priv; in adf7242_set_promiscuous_mode()
796 dev_dbg(&lp->spi->dev, "%s : mode %d\n", __func__, on); in adf7242_set_promiscuous_mode()
798 lp->promiscuous = on; in adf7242_set_promiscuous_mode()
822 struct adf7242_local *lp = hw->priv; in adf7242_set_cca_ed_level()
825 dev_dbg(&lp->spi->dev, "%s : level %d\n", __func__, level); in adf7242_set_cca_ed_level()
832 struct adf7242_local *lp = hw->priv; in adf7242_xmit()
836 disable_irq(lp->spi->irq); in adf7242_xmit()
837 set_bit(FLAG_XMIT, &lp->flags); in adf7242_xmit()
838 cancel_delayed_work_sync(&lp->work); in adf7242_xmit()
839 reinit_completion(&lp->tx_complete); in adf7242_xmit()
843 ret = adf7242_write_fbuf(lp, skb->data, skb->len); in adf7242_xmit()
850 enable_irq(lp->spi->irq); in adf7242_xmit()
852 ret = wait_for_completion_interruptible_timeout(&lp->tx_complete, in adf7242_xmit()
857 dev_dbg(&lp->spi->dev, "Timeout waiting for TX interrupt\n"); in adf7242_xmit()
858 ret = -ETIMEDOUT; in adf7242_xmit()
862 if (lp->tx_stat != SUCCESS) { in adf7242_xmit()
863 dev_dbg(&lp->spi->dev, in adf7242_xmit()
865 lp->tx_stat); in adf7242_xmit()
866 ret = -ECOMM; in adf7242_xmit()
872 clear_bit(FLAG_XMIT, &lp->flags); in adf7242_xmit()
892 dev_dbg(&lp->spi->dev, in adf7242_rx()
893 "corrupted frame received len %d\n", (int)len); in adf7242_rx()
900 return -ENOMEM; in adf7242_rx()
911 lqi = data[len - 2]; in adf7242_rx()
912 lp->rssi = data[len - 1]; in adf7242_rx()
916 skb_trim(skb, len - 2); /* Don't put RSSI/LQI or CRC into the frame */ in adf7242_rx()
918 ieee802154_rx_irqsafe(lp->hw, skb, lqi); in adf7242_rx()
920 dev_dbg(&lp->spi->dev, "%s: ret=%d len=%d lqi=%d rssi=%d\n", in adf7242_rx()
921 __func__, ret, (int)len, (int)lqi, lp->rssi); in adf7242_rx()
948 dev_dbg(&lp->spi->dev, "%s IRQ1 = %X:\n%s%s%s%s%s%s%s%s\n", in adf7242_debug()
959 dev_dbg(&lp->spi->dev, "%s STATUS = %X:\n%s\n%s\n%s\n%s\n%s%s%s%s%s\n", in adf7242_debug()
979 mod_delayed_work(lp->wqueue, &lp->work, msecs_to_jiffies(400)); in adf7242_isr()
983 dev_err(&lp->spi->dev, "%s :ERROR IRQ1 = 0x%X\n", in adf7242_isr()
988 xmit = test_bit(FLAG_XMIT, &lp->flags); in adf7242_isr()
1000 dev_dbg(&lp->spi->dev, "AUTO_STATUS = %X:\n%s%s%s%s\n", in adf7242_isr()
1008 /* save CSMA-CA completion status */ in adf7242_isr()
1009 lp->tx_stat = astat; in adf7242_isr()
1011 lp->tx_stat = SUCCESS; in adf7242_isr()
1013 complete(&lp->tx_complete); in adf7242_isr()
1018 } else if (!xmit && test_bit(FLAG_START, &lp->flags)) { in adf7242_isr()
1019 /* Invalid packet received - drop it and restart */ in adf7242_isr()
1020 dev_dbg(&lp->spi->dev, "%s:%d : ERROR IRQ1 = 0x%X\n", in adf7242_isr()
1025 /* This can only be xmit without IRQ, likely a RX packet. in adf7242_isr()
1026 * we get an TX IRQ shortly - do nothing or let the xmit in adf7242_isr()
1030 dev_dbg(&lp->spi->dev, "%s:%d : ERROR IRQ1 = 0x%X, xmit %d\n", in adf7242_isr()
1034 complete(&lp->tx_complete); in adf7242_isr()
1043 dev_warn(&lp->spi->dev, "%s (line %d)\n", __func__, line); in adf7242_soft_reset()
1045 if (test_bit(FLAG_START, &lp->flags)) in adf7242_soft_reset()
1046 disable_irq_nosync(lp->spi->irq); in adf7242_soft_reset()
1052 adf7242_set_promiscuous_mode(lp->hw, lp->promiscuous); in adf7242_soft_reset()
1053 adf7242_set_csma_params(lp->hw, lp->min_be, lp->max_be, in adf7242_soft_reset()
1054 lp->max_cca_retries); in adf7242_soft_reset()
1057 if (test_bit(FLAG_START, &lp->flags)) { in adf7242_soft_reset()
1058 enable_irq(lp->spi->irq); in adf7242_soft_reset()
1078 ret = request_firmware(&fw, FIRMWARE, &lp->spi->dev); in adf7242_hw_init()
1080 dev_err(&lp->spi->dev, in adf7242_hw_init()
1085 ret = adf7242_upload_firmware(lp, (u8 *)fw->data, fw->size); in adf7242_hw_init()
1087 dev_err(&lp->spi->dev, in adf7242_hw_init()
1093 ret = adf7242_verify_firmware(lp, (u8 *)fw->data, fw->size); in adf7242_hw_init()
1095 dev_err(&lp->spi->dev, in adf7242_hw_init()
1131 struct adf7242_local *lp = spi_get_drvdata(file->private); in adf7242_stats_show()
1158 seq_printf(file, "RSSI = %d\n", lp->rssi); in adf7242_stats_show()
1168 "adf7242-%s", dev_name(&lp->spi->dev)); in adf7242_debugfs_init()
1170 lp->debugfs_root = debugfs_create_dir(debugfs_dir_name, NULL); in adf7242_debugfs_init()
1172 debugfs_create_devm_seqfile(&lp->spi->dev, "status", lp->debugfs_root, in adf7242_debugfs_init()
1177 500, 400, 300, 200, 100, 0, -100, -200, -300, -400, -500, -600, -700,
1178 -800, -900, -1000, -1100, -1200, -1300, -1400, -1500, -1600, -1700,
1179 -1800, -1900, -2000, -2100, -2200, -2300, -2400, -2500, -2600,
1183 -9000, -8900, -8800, -8700, -8600, -8500, -8400, -8300, -8200, -8100,
1184 -8000, -7900, -7800, -7700, -7600, -7500, -7400, -7300, -7200, -7100,
1185 -7000, -6900, -6800, -6700, -6600, -6500, -6400, -6300, -6200, -6100,
1186 -6000, -5900, -5800, -5700, -5600, -5500, -5400, -5300, -5200, -5100,
1187 -5000, -4900, -4800, -4700, -4600, -4500, -4400, -4300, -4200, -4100,
1188 -4000, -3900, -3800, -3700, -3600, -3500, -3400, -3200, -3100, -3000
1197 if (!spi->irq) { in adf7242_probe()
1198 dev_err(&spi->dev, "no IRQ specified\n"); in adf7242_probe()
1199 return -EINVAL; in adf7242_probe()
1204 return -ENOMEM; in adf7242_probe()
1206 lp = hw->priv; in adf7242_probe()
1207 lp->hw = hw; in adf7242_probe()
1208 lp->spi = spi; in adf7242_probe()
1210 hw->priv = lp; in adf7242_probe()
1211 hw->parent = &spi->dev; in adf7242_probe()
1212 hw->extra_tx_headroom = 0; in adf7242_probe()
1215 hw->phy->supported.channels[0] = 0x7FFF800; in adf7242_probe()
1217 hw->flags = IEEE802154_HW_OMIT_CKSUM | in adf7242_probe()
1222 hw->phy->flags = WPAN_PHY_FLAG_TXPOWER | in adf7242_probe()
1226 hw->phy->supported.cca_modes = BIT(NL802154_CCA_ENERGY); in adf7242_probe()
1228 hw->phy->supported.cca_ed_levels = adf7242_ed_levels; in adf7242_probe()
1229 hw->phy->supported.cca_ed_levels_size = ARRAY_SIZE(adf7242_ed_levels); in adf7242_probe()
1231 hw->phy->cca.mode = NL802154_CCA_ENERGY; in adf7242_probe()
1233 hw->phy->supported.tx_powers = adf7242_powers; in adf7242_probe()
1234 hw->phy->supported.tx_powers_size = ARRAY_SIZE(adf7242_powers); in adf7242_probe()
1236 hw->phy->supported.min_minbe = 0; in adf7242_probe()
1237 hw->phy->supported.max_minbe = 8; in adf7242_probe()
1239 hw->phy->supported.min_maxbe = 3; in adf7242_probe()
1240 hw->phy->supported.max_maxbe = 8; in adf7242_probe()
1242 hw->phy->supported.min_frame_retries = 0; in adf7242_probe()
1243 hw->phy->supported.max_frame_retries = 15; in adf7242_probe()
1245 hw->phy->supported.min_csma_backoffs = 0; in adf7242_probe()
1246 hw->phy->supported.max_csma_backoffs = 5; in adf7242_probe()
1248 ieee802154_random_extended_addr(&hw->phy->perm_extended_addr); in adf7242_probe()
1250 mutex_init(&lp->bmux); in adf7242_probe()
1251 init_completion(&lp->tx_complete); in adf7242_probe()
1254 lp->stat_xfer.len = 1; in adf7242_probe()
1255 lp->stat_xfer.tx_buf = &lp->buf_stat_tx; in adf7242_probe()
1256 lp->stat_xfer.rx_buf = &lp->buf_stat_rx; in adf7242_probe()
1257 lp->buf_stat_tx = CMD_SPI_NOP; in adf7242_probe()
1259 spi_message_init(&lp->stat_msg); in adf7242_probe()
1260 spi_message_add_tail(&lp->stat_xfer, &lp->stat_msg); in adf7242_probe()
1263 INIT_DELAYED_WORK(&lp->work, adf7242_rx_cal_work); in adf7242_probe()
1264 lp->wqueue = alloc_ordered_workqueue(dev_name(&spi->dev), in adf7242_probe()
1266 if (unlikely(!lp->wqueue)) { in adf7242_probe()
1267 ret = -ENOMEM; in adf7242_probe()
1275 irq_type = irq_get_trigger_type(spi->irq); in adf7242_probe()
1279 ret = devm_request_threaded_irq(&spi->dev, spi->irq, NULL, adf7242_isr, in adf7242_probe()
1281 dev_name(&spi->dev), lp); in adf7242_probe()
1285 disable_irq(spi->irq); in adf7242_probe()
1287 ret = ieee802154_register_hw(lp->hw); in adf7242_probe()
1291 dev_set_drvdata(&spi->dev, lp); in adf7242_probe()
1295 dev_info(&spi->dev, "mac802154 IRQ-%d registered\n", spi->irq); in adf7242_probe()
1300 destroy_workqueue(lp->wqueue); in adf7242_probe()
1302 mutex_destroy(&lp->bmux); in adf7242_probe()
1303 ieee802154_free_hw(lp->hw); in adf7242_probe()
1312 debugfs_remove_recursive(lp->debugfs_root); in adf7242_remove()
1314 ieee802154_unregister_hw(lp->hw); in adf7242_remove()
1316 cancel_delayed_work_sync(&lp->work); in adf7242_remove()
1317 destroy_workqueue(lp->wqueue); in adf7242_remove()
1319 mutex_destroy(&lp->bmux); in adf7242_remove()
1320 ieee802154_free_hw(lp->hw); in adf7242_remove()