aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Herrmann <sascha@ps.nvbi.de>2013-04-14 18:33:28 -0400
committerDavid S. Miller <davem@davemloft.net>2013-04-16 16:34:07 -0400
commit43b5abe0640100a9e9424c91298c7993d443ffb7 (patch)
treebe50d3b735590b8c81413266de199d3338a8bf7a
parent8ac2b3c0e270f9792edc15fb66808143eb48a53f (diff)
at86rf230: add irq type configuration option
Add option to at86rf230 platform data to configure the type of the interrupt used by the driver. The irq polarity of the device will be configured accordingly. Signed-off-by: Sascha Herrmann <sascha@ps.nvbi.de> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/ieee802154/at86rf230.c47
-rw-r--r--include/linux/spi/at86rf230.h14
2 files changed, 45 insertions, 16 deletions
diff --git a/drivers/net/ieee802154/at86rf230.c b/drivers/net/ieee802154/at86rf230.c
index fc315ddea61c..cf098889ba64 100644
--- a/drivers/net/ieee802154/at86rf230.c
+++ b/drivers/net/ieee802154/at86rf230.c
@@ -219,6 +219,9 @@ struct at86rf230_local {
219#define IRQ_PLL_UNL (1 << 1) 219#define IRQ_PLL_UNL (1 << 1)
220#define IRQ_PLL_LOCK (1 << 0) 220#define IRQ_PLL_LOCK (1 << 0)
221 221
222#define IRQ_ACTIVE_HIGH 0
223#define IRQ_ACTIVE_LOW 1
224
222#define STATE_P_ON 0x00 /* BUSY */ 225#define STATE_P_ON 0x00 /* BUSY */
223#define STATE_BUSY_RX 0x01 226#define STATE_BUSY_RX 0x01
224#define STATE_BUSY_TX 0x02 227#define STATE_BUSY_TX 0x02
@@ -726,11 +729,16 @@ static irqreturn_t at86rf230_isr(int irq, void *data)
726 return IRQ_HANDLED; 729 return IRQ_HANDLED;
727} 730}
728 731
732static int at86rf230_irq_polarity(struct at86rf230_local *lp, int pol)
733{
734 return at86rf230_write_subreg(lp, SR_IRQ_POLARITY, pol);
735}
729 736
730static int at86rf230_hw_init(struct at86rf230_local *lp) 737static int at86rf230_hw_init(struct at86rf230_local *lp)
731{ 738{
739 struct at86rf230_platform_data *pdata = lp->spi->dev.platform_data;
740 int rc, irq_pol;
732 u8 status; 741 u8 status;
733 int rc;
734 742
735 rc = at86rf230_read_subreg(lp, SR_TRX_STATUS, &status); 743 rc = at86rf230_read_subreg(lp, SR_TRX_STATUS, &status);
736 if (rc) 744 if (rc)
@@ -748,6 +756,16 @@ static int at86rf230_hw_init(struct at86rf230_local *lp)
748 dev_info(&lp->spi->dev, "Status: %02x\n", status); 756 dev_info(&lp->spi->dev, "Status: %02x\n", status);
749 } 757 }
750 758
759 /* configure irq polarity, defaults to high active */
760 if (pdata->irq_type & (IRQF_TRIGGER_FALLING | IRQF_TRIGGER_LOW))
761 irq_pol = IRQ_ACTIVE_LOW;
762 else
763 irq_pol = IRQ_ACTIVE_HIGH;
764
765 rc = at86rf230_irq_polarity(lp, irq_pol);
766 if (rc)
767 return rc;
768
751 rc = at86rf230_write_subreg(lp, SR_IRQ_MASK, 0xff); /* IRQ_TRX_UR | 769 rc = at86rf230_write_subreg(lp, SR_IRQ_MASK, 0xff); /* IRQ_TRX_UR |
752 * IRQ_CCA_ED | 770 * IRQ_CCA_ED |
753 * IRQ_TRX_END | 771 * IRQ_TRX_END |
@@ -798,37 +816,36 @@ static int at86rf230_hw_init(struct at86rf230_local *lp)
798 return 0; 816 return 0;
799} 817}
800 818
801static int at86rf230_fill_data(struct spi_device *spi) 819static void at86rf230_fill_data(struct spi_device *spi)
802{ 820{
803 struct at86rf230_local *lp = spi_get_drvdata(spi); 821 struct at86rf230_local *lp = spi_get_drvdata(spi);
804 struct at86rf230_platform_data *pdata = spi->dev.platform_data; 822 struct at86rf230_platform_data *pdata = spi->dev.platform_data;
805 823
806 if (!pdata) {
807 dev_err(&spi->dev, "no platform_data\n");
808 return -EINVAL;
809 }
810
811 lp->rstn = pdata->rstn; 824 lp->rstn = pdata->rstn;
812 lp->slp_tr = pdata->slp_tr; 825 lp->slp_tr = pdata->slp_tr;
813 lp->dig2 = pdata->dig2; 826 lp->dig2 = pdata->dig2;
814
815 return 0;
816} 827}
817 828
818static int at86rf230_probe(struct spi_device *spi) 829static int at86rf230_probe(struct spi_device *spi)
819{ 830{
831 struct at86rf230_platform_data *pdata;
820 struct ieee802154_dev *dev; 832 struct ieee802154_dev *dev;
821 struct at86rf230_local *lp; 833 struct at86rf230_local *lp;
822 u8 man_id_0, man_id_1; 834 u8 man_id_0, man_id_1;
823 int rc; 835 int rc, supported = 0;
824 const char *chip; 836 const char *chip;
825 int supported = 0;
826 837
827 if (!spi->irq) { 838 if (!spi->irq) {
828 dev_err(&spi->dev, "no IRQ specified\n"); 839 dev_err(&spi->dev, "no IRQ specified\n");
829 return -EINVAL; 840 return -EINVAL;
830 } 841 }
831 842
843 pdata = spi->dev.platform_data;
844 if (!pdata) {
845 dev_err(&spi->dev, "no platform_data\n");
846 return -EINVAL;
847 }
848
832 dev = ieee802154_alloc_device(sizeof(*lp), &at86rf230_ops); 849 dev = ieee802154_alloc_device(sizeof(*lp), &at86rf230_ops);
833 if (!dev) 850 if (!dev)
834 return -ENOMEM; 851 return -ENOMEM;
@@ -851,9 +868,7 @@ static int at86rf230_probe(struct spi_device *spi)
851 868
852 spi_set_drvdata(spi, lp); 869 spi_set_drvdata(spi, lp);
853 870
854 rc = at86rf230_fill_data(spi); 871 at86rf230_fill_data(spi);
855 if (rc)
856 goto err_fill;
857 872
858 rc = gpio_request(lp->rstn, "rstn"); 873 rc = gpio_request(lp->rstn, "rstn");
859 if (rc) 874 if (rc)
@@ -928,7 +943,8 @@ static int at86rf230_probe(struct spi_device *spi)
928 if (rc) 943 if (rc)
929 goto err_gpio_dir; 944 goto err_gpio_dir;
930 945
931 rc = request_irq(spi->irq, at86rf230_isr, IRQF_SHARED, 946 rc = request_irq(spi->irq, at86rf230_isr,
947 IRQF_SHARED | pdata->irq_type,
932 dev_name(&spi->dev), lp); 948 dev_name(&spi->dev), lp);
933 if (rc) 949 if (rc)
934 goto err_gpio_dir; 950 goto err_gpio_dir;
@@ -948,7 +964,6 @@ err_gpio_dir:
948err_slp_tr: 964err_slp_tr:
949 gpio_free(lp->rstn); 965 gpio_free(lp->rstn);
950err_rstn: 966err_rstn:
951err_fill:
952 spi_set_drvdata(spi, NULL); 967 spi_set_drvdata(spi, NULL);
953 mutex_destroy(&lp->bmux); 968 mutex_destroy(&lp->bmux);
954 ieee802154_free_device(lp->dev); 969 ieee802154_free_device(lp->dev);
diff --git a/include/linux/spi/at86rf230.h b/include/linux/spi/at86rf230.h
index b2b1afbb3202..aa327a8105ad 100644
--- a/include/linux/spi/at86rf230.h
+++ b/include/linux/spi/at86rf230.h
@@ -26,6 +26,20 @@ struct at86rf230_platform_data {
26 int rstn; 26 int rstn;
27 int slp_tr; 27 int slp_tr;
28 int dig2; 28 int dig2;
29
30 /* Setting the irq_type will configure the driver to request
31 * the platform irq trigger type according to the given value
32 * and configure the interrupt polarity of the device to the
33 * corresponding polarity.
34 *
35 * Allowed values are: IRQF_TRIGGER_RISING, IRQF_TRIGGER_FALLING,
36 * IRQF_TRIGGER_HIGH and IRQF_TRIGGER_LOW
37 *
38 * Setting it to 0, the driver does not touch the trigger type
39 * configuration of the interrupt and sets the interrupt polarity
40 * of the device to high active (the default value).
41 */
42 int irq_type;
29}; 43};
30 44
31#endif 45#endif