aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/ieee802154/mrf24j40.c
diff options
context:
space:
mode:
authorVarka Bhadram <varkabhadram@gmail.com>2014-06-15 23:42:31 -0400
committerDavid S. Miller <davem@davemloft.net>2014-06-17 18:30:54 -0400
commit3dac9a79e1425069e7950bd46bd932e0b1c1d795 (patch)
tree75b1b5de0cb0319c9b2b5d5eb0286c040e185195 /drivers/net/ieee802154/mrf24j40.c
parent7171511eaec5bf23fb06078f59784a3a0626b38f (diff)
mrf24j40: separate h/w init and add checkings
separate the mrf24j40 hardware initialisation from probe() and adds the sanity checkings. These checkings are required if somebody hasn't a right spi configuration the probe function should fail. So we have to return from there. Signed-off-by: Varka Bhadram <varkab@cdac.in> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/ieee802154/mrf24j40.c')
-rw-r--r--drivers/net/ieee802154/mrf24j40.c115
1 files changed, 89 insertions, 26 deletions
diff --git a/drivers/net/ieee802154/mrf24j40.c b/drivers/net/ieee802154/mrf24j40.c
index 4048062011ba..9e6a124b13f2 100644
--- a/drivers/net/ieee802154/mrf24j40.c
+++ b/drivers/net/ieee802154/mrf24j40.c
@@ -610,10 +610,95 @@ out:
610 return IRQ_HANDLED; 610 return IRQ_HANDLED;
611} 611}
612 612
613static int mrf24j40_hw_init(struct mrf24j40 *devrec)
614{
615 int ret;
616 u8 val;
617
618 /* Initialize the device.
619 From datasheet section 3.2: Initialization. */
620 ret = write_short_reg(devrec, REG_SOFTRST, 0x07);
621 if (ret)
622 goto err_ret;
623
624 ret = write_short_reg(devrec, REG_PACON2, 0x98);
625 if (ret)
626 goto err_ret;
627
628 ret = write_short_reg(devrec, REG_TXSTBL, 0x95);
629 if (ret)
630 goto err_ret;
631
632 ret = write_long_reg(devrec, REG_RFCON0, 0x03);
633 if (ret)
634 goto err_ret;
635
636 ret = write_long_reg(devrec, REG_RFCON1, 0x01);
637 if (ret)
638 goto err_ret;
639
640 ret = write_long_reg(devrec, REG_RFCON2, 0x80);
641 if (ret)
642 goto err_ret;
643
644 ret = write_long_reg(devrec, REG_RFCON6, 0x90);
645 if (ret)
646 goto err_ret;
647
648 ret = write_long_reg(devrec, REG_RFCON7, 0x80);
649 if (ret)
650 goto err_ret;
651
652 ret = write_long_reg(devrec, REG_RFCON8, 0x10);
653 if (ret)
654 goto err_ret;
655
656 ret = write_long_reg(devrec, REG_SLPCON1, 0x21);
657 if (ret)
658 goto err_ret;
659
660 ret = write_short_reg(devrec, REG_BBREG2, 0x80);
661 if (ret)
662 goto err_ret;
663
664 ret = write_short_reg(devrec, REG_CCAEDTH, 0x60);
665 if (ret)
666 goto err_ret;
667
668 ret = write_short_reg(devrec, REG_BBREG6, 0x40);
669 if (ret)
670 goto err_ret;
671
672 ret = write_short_reg(devrec, REG_RFCTL, 0x04);
673 if (ret)
674 goto err_ret;
675
676 ret = write_short_reg(devrec, REG_RFCTL, 0x0);
677 if (ret)
678 goto err_ret;
679
680 udelay(192);
681
682 /* Set RX Mode. RXMCR<1:0>: 0x0 normal, 0x1 promisc, 0x2 error */
683 ret = read_short_reg(devrec, REG_RXMCR, &val);
684 if (ret)
685 goto err_ret;
686
687 val &= ~0x3; /* Clear RX mode (normal) */
688
689 ret = write_short_reg(devrec, REG_RXMCR, val);
690 if (ret)
691 goto err_ret;
692
693 return 0;
694
695err_ret:
696 return ret;
697}
698
613static int mrf24j40_probe(struct spi_device *spi) 699static int mrf24j40_probe(struct spi_device *spi)
614{ 700{
615 int ret = -ENOMEM; 701 int ret = -ENOMEM;
616 u8 val;
617 struct mrf24j40 *devrec; 702 struct mrf24j40 *devrec;
618 703
619 printk(KERN_INFO "mrf24j40: probe(). IRQ: %d\n", spi->irq); 704 printk(KERN_INFO "mrf24j40: probe(). IRQ: %d\n", spi->irq);
@@ -650,31 +735,9 @@ static int mrf24j40_probe(struct spi_device *spi)
650 if (ret) 735 if (ret)
651 goto err_register_device; 736 goto err_register_device;
652 737
653 /* Initialize the device. 738 ret = mrf24j40_hw_init(devrec);
654 From datasheet section 3.2: Initialization. */
655 write_short_reg(devrec, REG_SOFTRST, 0x07);
656 write_short_reg(devrec, REG_PACON2, 0x98);
657 write_short_reg(devrec, REG_TXSTBL, 0x95);
658 write_long_reg(devrec, REG_RFCON0, 0x03);
659 write_long_reg(devrec, REG_RFCON1, 0x01);
660 write_long_reg(devrec, REG_RFCON2, 0x80);
661 write_long_reg(devrec, REG_RFCON6, 0x90);
662 write_long_reg(devrec, REG_RFCON7, 0x80);
663 write_long_reg(devrec, REG_RFCON8, 0x10);
664 write_long_reg(devrec, REG_SLPCON1, 0x21);
665 write_short_reg(devrec, REG_BBREG2, 0x80);
666 write_short_reg(devrec, REG_CCAEDTH, 0x60);
667 write_short_reg(devrec, REG_BBREG6, 0x40);
668 write_short_reg(devrec, REG_RFCTL, 0x04);
669 write_short_reg(devrec, REG_RFCTL, 0x0);
670 udelay(192);
671
672 /* Set RX Mode. RXMCR<1:0>: 0x0 normal, 0x1 promisc, 0x2 error */
673 ret = read_short_reg(devrec, REG_RXMCR, &val);
674 if (ret) 739 if (ret)
675 goto err_read_reg; 740 goto err_hw_init;
676 val &= ~0x3; /* Clear RX mode (normal) */
677 write_short_reg(devrec, REG_RXMCR, val);
678 741
679 ret = devm_request_threaded_irq(&spi->dev, 742 ret = devm_request_threaded_irq(&spi->dev,
680 spi->irq, 743 spi->irq,
@@ -692,7 +755,7 @@ static int mrf24j40_probe(struct spi_device *spi)
692 return 0; 755 return 0;
693 756
694err_irq: 757err_irq:
695err_read_reg: 758err_hw_init:
696 ieee802154_unregister_device(devrec->dev); 759 ieee802154_unregister_device(devrec->dev);
697err_register_device: 760err_register_device:
698 ieee802154_free_device(devrec->dev); 761 ieee802154_free_device(devrec->dev);