diff options
author | Alexander Aring <alex.aring@gmail.com> | 2014-03-15 04:29:07 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-03-17 16:10:26 -0400 |
commit | fa2d3e9471b37c2d3cd3cede73065b3b867532ee (patch) | |
tree | d270f7dfd7c419a4427e1cad5e92d60bd746110a /drivers/net/ieee802154 | |
parent | 3fa275712489d31171b612a9a83e7b9840c6364e (diff) |
at86rf230: add support for devicetree
This patch adds devicetree support for the at86rf230 driver.
Possible gpios to configure are "reset-gpio" and "sleep-gpio".
Also add support to configure the "irq-type" for the irq polarity
register.
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/ieee802154')
-rw-r--r-- | drivers/net/ieee802154/at86rf230.c | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/drivers/net/ieee802154/at86rf230.c b/drivers/net/ieee802154/at86rf230.c index 47677e3f986f..e8004ef73bc1 100644 --- a/drivers/net/ieee802154/at86rf230.c +++ b/drivers/net/ieee802154/at86rf230.c | |||
@@ -31,6 +31,7 @@ | |||
31 | #include <linux/spi/spi.h> | 31 | #include <linux/spi/spi.h> |
32 | #include <linux/spi/at86rf230.h> | 32 | #include <linux/spi/at86rf230.h> |
33 | #include <linux/skbuff.h> | 33 | #include <linux/skbuff.h> |
34 | #include <linux/of_gpio.h> | ||
34 | 35 | ||
35 | #include <net/mac802154.h> | 36 | #include <net/mac802154.h> |
36 | #include <net/wpan-phy.h> | 37 | #include <net/wpan-phy.h> |
@@ -1035,6 +1036,40 @@ static int at86rf230_hw_init(struct at86rf230_local *lp) | |||
1035 | return 0; | 1036 | return 0; |
1036 | } | 1037 | } |
1037 | 1038 | ||
1039 | static struct at86rf230_platform_data * | ||
1040 | at86rf230_get_pdata(struct spi_device *spi) | ||
1041 | { | ||
1042 | struct at86rf230_platform_data *pdata; | ||
1043 | const char *irq_type; | ||
1044 | |||
1045 | if (!IS_ENABLED(CONFIG_OF) || !spi->dev.of_node) | ||
1046 | return spi->dev.platform_data; | ||
1047 | |||
1048 | pdata = devm_kzalloc(&spi->dev, sizeof(*pdata), GFP_KERNEL); | ||
1049 | if (!pdata) | ||
1050 | goto done; | ||
1051 | |||
1052 | pdata->rstn = of_get_named_gpio(spi->dev.of_node, "reset-gpio", 0); | ||
1053 | pdata->slp_tr = of_get_named_gpio(spi->dev.of_node, "sleep-gpio", 0); | ||
1054 | |||
1055 | pdata->irq_type = IRQF_TRIGGER_RISING; | ||
1056 | of_property_read_string(spi->dev.of_node, "irq-type", &irq_type); | ||
1057 | if (!strcmp(irq_type, "level-high")) | ||
1058 | pdata->irq_type = IRQF_TRIGGER_HIGH; | ||
1059 | else if (!strcmp(irq_type, "level-low")) | ||
1060 | pdata->irq_type = IRQF_TRIGGER_LOW; | ||
1061 | else if (!strcmp(irq_type, "edge-rising")) | ||
1062 | pdata->irq_type = IRQF_TRIGGER_RISING; | ||
1063 | else if (!strcmp(irq_type, "edge-falling")) | ||
1064 | pdata->irq_type = IRQF_TRIGGER_FALLING; | ||
1065 | else | ||
1066 | dev_warn(&spi->dev, "wrong irq-type specified using edge-rising\n"); | ||
1067 | |||
1068 | spi->dev.platform_data = pdata; | ||
1069 | done: | ||
1070 | return pdata; | ||
1071 | } | ||
1072 | |||
1038 | static int at86rf230_probe(struct spi_device *spi) | 1073 | static int at86rf230_probe(struct spi_device *spi) |
1039 | { | 1074 | { |
1040 | struct at86rf230_platform_data *pdata; | 1075 | struct at86rf230_platform_data *pdata; |
@@ -1053,7 +1088,7 @@ static int at86rf230_probe(struct spi_device *spi) | |||
1053 | return -EINVAL; | 1088 | return -EINVAL; |
1054 | } | 1089 | } |
1055 | 1090 | ||
1056 | pdata = spi->dev.platform_data; | 1091 | pdata = at86rf230_get_pdata(spi); |
1057 | if (!pdata) { | 1092 | if (!pdata) { |
1058 | dev_err(&spi->dev, "no platform_data\n"); | 1093 | dev_err(&spi->dev, "no platform_data\n"); |
1059 | return -EINVAL; | 1094 | return -EINVAL; |
@@ -1231,8 +1266,19 @@ static int at86rf230_remove(struct spi_device *spi) | |||
1231 | return 0; | 1266 | return 0; |
1232 | } | 1267 | } |
1233 | 1268 | ||
1269 | #if IS_ENABLED(CONFIG_OF) | ||
1270 | static struct of_device_id at86rf230_of_match[] = { | ||
1271 | { .compatible = "atmel,at86rf230", }, | ||
1272 | { .compatible = "atmel,at86rf231", }, | ||
1273 | { .compatible = "atmel,at86rf233", }, | ||
1274 | { .compatible = "atmel,at86rf212", }, | ||
1275 | { }, | ||
1276 | }; | ||
1277 | #endif | ||
1278 | |||
1234 | static struct spi_driver at86rf230_driver = { | 1279 | static struct spi_driver at86rf230_driver = { |
1235 | .driver = { | 1280 | .driver = { |
1281 | .of_match_table = of_match_ptr(at86rf230_of_match), | ||
1236 | .name = "at86rf230", | 1282 | .name = "at86rf230", |
1237 | .owner = THIS_MODULE, | 1283 | .owner = THIS_MODULE, |
1238 | }, | 1284 | }, |