Skip to content

Commit 16b4630

Browse files
committed
Merge branch 'at86rf230-next'
Alexander Aring says: ==================== at86rf230 cleanup this is the first patch series to cleanup the at86rf230 driver. Later I want to implement regmap and a asynchron spi handling for transmit and receiving frames. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 7f51531 + 18c6504 commit 16b4630

File tree

3 files changed

+65
-105
lines changed

3 files changed

+65
-105
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
* AT86RF230 IEEE 802.15.4 *
2+
3+
Required properties:
4+
- compatible: should be "atmel,at86rf230", "atmel,at86rf231",
5+
"atmel,at86rf233" or "atmel,at86rf212"
6+
- spi-max-frequency: maximal bus speed, should be set to 7500000 depends
7+
sync or async operation mode
8+
- reg: the chipselect index
9+
- interrupts: the interrupt generated by the device
10+
11+
Optional properties:
12+
- reset-gpio: GPIO spec for the rstn pin
13+
- sleep-gpio: GPIO spec for the slp_tr pin
14+
15+
Example:
16+
17+
at86rf231@0 {
18+
compatible = "atmel,at86rf231";
19+
spi-max-frequency = <7500000>;
20+
reg = <0>;
21+
interrupts = <19 1>;
22+
interrupt-parent = <&gpio3>;
23+
};

drivers/net/ieee802154/at86rf230.c

Lines changed: 42 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <linux/kernel.h>
2424
#include <linux/module.h>
2525
#include <linux/interrupt.h>
26+
#include <linux/irq.h>
2627
#include <linux/gpio.h>
2728
#include <linux/delay.h>
2829
#include <linux/mutex.h>
@@ -692,10 +693,7 @@ at86rf230_xmit(struct ieee802154_dev *dev, struct sk_buff *skb)
692693
if (rc < 0)
693694
goto err_rx;
694695

695-
rc = at86rf230_start(dev);
696-
697-
return rc;
698-
696+
return at86rf230_start(dev);
699697
err_rx:
700698
at86rf230_start(dev);
701699
err:
@@ -963,33 +961,24 @@ static irqreturn_t at86rf230_isr_level(int irq, void *data)
963961
return at86rf230_isr(irq, data);
964962
}
965963

966-
static int at86rf230_irq_polarity(struct at86rf230_local *lp, int pol)
967-
{
968-
return at86rf230_write_subreg(lp, SR_IRQ_POLARITY, pol);
969-
}
970-
971964
static int at86rf230_hw_init(struct at86rf230_local *lp)
972965
{
973-
struct at86rf230_platform_data *pdata = lp->spi->dev.platform_data;
974-
int rc, irq_pol;
975-
u8 status;
966+
int rc, irq_pol, irq_type;
967+
u8 dvdd;
976968
u8 csma_seed[2];
977969

978-
rc = at86rf230_read_subreg(lp, SR_TRX_STATUS, &status);
979-
if (rc)
980-
return rc;
981-
982970
rc = at86rf230_write_subreg(lp, SR_TRX_CMD, STATE_FORCE_TRX_OFF);
983971
if (rc)
984972
return rc;
985973

974+
irq_type = irq_get_trigger_type(lp->spi->irq);
986975
/* configure irq polarity, defaults to high active */
987-
if (pdata->irq_type & (IRQF_TRIGGER_FALLING | IRQF_TRIGGER_LOW))
976+
if (irq_type & (IRQF_TRIGGER_FALLING | IRQF_TRIGGER_LOW))
988977
irq_pol = IRQ_ACTIVE_LOW;
989978
else
990979
irq_pol = IRQ_ACTIVE_HIGH;
991980

992-
rc = at86rf230_irq_polarity(lp, irq_pol);
981+
rc = at86rf230_write_subreg(lp, SR_IRQ_POLARITY, irq_pol);
993982
if (rc)
994983
return rc;
995984

@@ -1017,10 +1006,10 @@ static int at86rf230_hw_init(struct at86rf230_local *lp)
10171006
/* Wait the next SLEEP cycle */
10181007
msleep(100);
10191008

1020-
rc = at86rf230_read_subreg(lp, SR_DVDD_OK, &status);
1009+
rc = at86rf230_read_subreg(lp, SR_DVDD_OK, &dvdd);
10211010
if (rc)
10221011
return rc;
1023-
if (!status) {
1012+
if (!dvdd) {
10241013
dev_err(&lp->spi->dev, "DVDD error\n");
10251014
return -EINVAL;
10261015
}
@@ -1032,7 +1021,6 @@ static struct at86rf230_platform_data *
10321021
at86rf230_get_pdata(struct spi_device *spi)
10331022
{
10341023
struct at86rf230_platform_data *pdata;
1035-
const char *irq_type;
10361024

10371025
if (!IS_ENABLED(CONFIG_OF) || !spi->dev.of_node)
10381026
return spi->dev.platform_data;
@@ -1044,19 +1032,6 @@ at86rf230_get_pdata(struct spi_device *spi)
10441032
pdata->rstn = of_get_named_gpio(spi->dev.of_node, "reset-gpio", 0);
10451033
pdata->slp_tr = of_get_named_gpio(spi->dev.of_node, "sleep-gpio", 0);
10461034

1047-
pdata->irq_type = IRQF_TRIGGER_RISING;
1048-
of_property_read_string(spi->dev.of_node, "irq-type", &irq_type);
1049-
if (!strcmp(irq_type, "level-high"))
1050-
pdata->irq_type = IRQF_TRIGGER_HIGH;
1051-
else if (!strcmp(irq_type, "level-low"))
1052-
pdata->irq_type = IRQF_TRIGGER_LOW;
1053-
else if (!strcmp(irq_type, "edge-rising"))
1054-
pdata->irq_type = IRQF_TRIGGER_RISING;
1055-
else if (!strcmp(irq_type, "edge-falling"))
1056-
pdata->irq_type = IRQF_TRIGGER_FALLING;
1057-
else
1058-
dev_warn(&spi->dev, "wrong irq-type specified using edge-rising\n");
1059-
10601035
spi->dev.platform_data = pdata;
10611036
done:
10621037
return pdata;
@@ -1071,7 +1046,7 @@ static int at86rf230_probe(struct spi_device *spi)
10711046
u8 part = 0, version = 0, status;
10721047
irq_handler_t irq_handler;
10731048
work_func_t irq_worker;
1074-
int rc;
1049+
int rc, irq_type;
10751050
const char *chip;
10761051
struct ieee802154_ops *ops = NULL;
10771052

@@ -1087,27 +1062,17 @@ static int at86rf230_probe(struct spi_device *spi)
10871062
}
10881063

10891064
if (gpio_is_valid(pdata->rstn)) {
1090-
rc = gpio_request(pdata->rstn, "rstn");
1065+
rc = devm_gpio_request_one(&spi->dev, pdata->rstn,
1066+
GPIOF_OUT_INIT_HIGH, "rstn");
10911067
if (rc)
10921068
return rc;
10931069
}
10941070

10951071
if (gpio_is_valid(pdata->slp_tr)) {
1096-
rc = gpio_request(pdata->slp_tr, "slp_tr");
1097-
if (rc)
1098-
goto err_slp_tr;
1099-
}
1100-
1101-
if (gpio_is_valid(pdata->rstn)) {
1102-
rc = gpio_direction_output(pdata->rstn, 1);
1103-
if (rc)
1104-
goto err_gpio_dir;
1105-
}
1106-
1107-
if (gpio_is_valid(pdata->slp_tr)) {
1108-
rc = gpio_direction_output(pdata->slp_tr, 0);
1072+
rc = devm_gpio_request_one(&spi->dev, pdata->slp_tr,
1073+
GPIOF_OUT_INIT_LOW, "slp_tr");
11091074
if (rc)
1110-
goto err_gpio_dir;
1075+
return rc;
11111076
}
11121077

11131078
/* Reset */
@@ -1121,13 +1086,12 @@ static int at86rf230_probe(struct spi_device *spi)
11211086

11221087
rc = __at86rf230_detect_device(spi, &man_id, &part, &version);
11231088
if (rc < 0)
1124-
goto err_gpio_dir;
1089+
return rc;
11251090

11261091
if (man_id != 0x001f) {
11271092
dev_err(&spi->dev, "Non-Atmel dev found (MAN_ID %02x %02x)\n",
11281093
man_id >> 8, man_id & 0xFF);
1129-
rc = -EINVAL;
1130-
goto err_gpio_dir;
1094+
return -EINVAL;
11311095
}
11321096

11331097
switch (part) {
@@ -1154,16 +1118,12 @@ static int at86rf230_probe(struct spi_device *spi)
11541118
}
11551119

11561120
dev_info(&spi->dev, "Detected %s chip version %d\n", chip, version);
1157-
if (!ops) {
1158-
rc = -ENOTSUPP;
1159-
goto err_gpio_dir;
1160-
}
1121+
if (!ops)
1122+
return -ENOTSUPP;
11611123

11621124
dev = ieee802154_alloc_device(sizeof(*lp), ops);
1163-
if (!dev) {
1164-
rc = -ENOMEM;
1165-
goto err_gpio_dir;
1166-
}
1125+
if (!dev)
1126+
return -ENOMEM;
11671127

11681128
lp = dev->priv;
11691129
lp->dev = dev;
@@ -1176,7 +1136,8 @@ static int at86rf230_probe(struct spi_device *spi)
11761136
dev->extra_tx_headroom = 0;
11771137
dev->flags = IEEE802154_HW_OMIT_CKSUM | IEEE802154_HW_AACK;
11781138

1179-
if (pdata->irq_type & (IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING)) {
1139+
irq_type = irq_get_trigger_type(spi->irq);
1140+
if (irq_type & (IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING)) {
11801141
irq_worker = at86rf230_irqwork;
11811142
irq_handler = at86rf230_isr;
11821143
} else {
@@ -1202,75 +1163,65 @@ static int at86rf230_probe(struct spi_device *spi)
12021163
if (rc)
12031164
goto err_hw_init;
12041165

1205-
rc = request_irq(spi->irq, irq_handler,
1206-
IRQF_SHARED | pdata->irq_type,
1207-
dev_name(&spi->dev), lp);
1166+
/* Read irq status register to reset irq line */
1167+
rc = at86rf230_read_subreg(lp, RG_IRQ_STATUS, 0xff, 0, &status);
12081168
if (rc)
12091169
goto err_hw_init;
12101170

1211-
/* Read irq status register to reset irq line */
1212-
rc = at86rf230_read_subreg(lp, RG_IRQ_STATUS, 0xff, 0, &status);
1171+
rc = devm_request_irq(&spi->dev, spi->irq, irq_handler, IRQF_SHARED,
1172+
dev_name(&spi->dev), lp);
12131173
if (rc)
1214-
goto err_irq;
1174+
goto err_hw_init;
12151175

12161176
rc = ieee802154_register_device(lp->dev);
12171177
if (rc)
1218-
goto err_irq;
1178+
goto err_hw_init;
12191179

12201180
return rc;
12211181

1222-
err_irq:
1223-
free_irq(spi->irq, lp);
12241182
err_hw_init:
12251183
flush_work(&lp->irqwork);
1226-
spi_set_drvdata(spi, NULL);
12271184
mutex_destroy(&lp->bmux);
12281185
ieee802154_free_device(lp->dev);
12291186

1230-
err_gpio_dir:
1231-
if (gpio_is_valid(pdata->slp_tr))
1232-
gpio_free(pdata->slp_tr);
1233-
err_slp_tr:
1234-
if (gpio_is_valid(pdata->rstn))
1235-
gpio_free(pdata->rstn);
12361187
return rc;
12371188
}
12381189

12391190
static int at86rf230_remove(struct spi_device *spi)
12401191
{
12411192
struct at86rf230_local *lp = spi_get_drvdata(spi);
1242-
struct at86rf230_platform_data *pdata = spi->dev.platform_data;
12431193

12441194
/* mask all at86rf230 irq's */
12451195
at86rf230_write_subreg(lp, SR_IRQ_MASK, 0);
12461196
ieee802154_unregister_device(lp->dev);
1247-
1248-
free_irq(spi->irq, lp);
12491197
flush_work(&lp->irqwork);
1250-
1251-
if (gpio_is_valid(pdata->slp_tr))
1252-
gpio_free(pdata->slp_tr);
1253-
if (gpio_is_valid(pdata->rstn))
1254-
gpio_free(pdata->rstn);
1255-
12561198
mutex_destroy(&lp->bmux);
12571199
ieee802154_free_device(lp->dev);
1258-
12591200
dev_dbg(&spi->dev, "unregistered at86rf230\n");
1201+
12601202
return 0;
12611203
}
12621204

1263-
#if IS_ENABLED(CONFIG_OF)
1264-
static struct of_device_id at86rf230_of_match[] = {
1205+
static const struct of_device_id at86rf230_of_match[] = {
12651206
{ .compatible = "atmel,at86rf230", },
12661207
{ .compatible = "atmel,at86rf231", },
12671208
{ .compatible = "atmel,at86rf233", },
12681209
{ .compatible = "atmel,at86rf212", },
12691210
{ },
12701211
};
1271-
#endif
1212+
MODULE_DEVICE_TABLE(of, at86rf230_of_match);
1213+
1214+
static const struct spi_device_id at86rf230_device_id[] = {
1215+
{ .name = "at86rf230", },
1216+
{ .name = "at86rf231", },
1217+
{ .name = "at86rf233", },
1218+
{ .name = "at86rf212", },
1219+
{ },
1220+
};
1221+
MODULE_DEVICE_TABLE(spi, at86rf230_device_id);
12721222

12731223
static struct spi_driver at86rf230_driver = {
1224+
.id_table = at86rf230_device_id,
12741225
.driver = {
12751226
.of_match_table = of_match_ptr(at86rf230_of_match),
12761227
.name = "at86rf230",

include/linux/spi/at86rf230.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,6 @@ struct at86rf230_platform_data {
2626
int rstn;
2727
int slp_tr;
2828
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;
4329
};
4430

4531
#endif

0 commit comments

Comments
 (0)