15
15
#include <linux/jiffies.h>
16
16
#include <linux/interrupt.h>
17
17
#include <linux/irq.h>
18
+ #include <linux/gpio.h>
18
19
#include <linux/delay.h>
19
- #include <linux/gpio/consumer.h>
20
20
#include <linux/spi/spi.h>
21
- #include <linux/property .h>
21
+ #include <linux/spi/at86rf230 .h>
22
22
#include <linux/regmap.h>
23
23
#include <linux/skbuff.h>
24
+ #include <linux/of_gpio.h>
24
25
#include <linux/ieee802154.h>
25
26
26
27
#include <net/mac802154.h>
@@ -81,7 +82,7 @@ struct at86rf230_local {
81
82
struct ieee802154_hw * hw ;
82
83
struct at86rf2xx_chip_data * data ;
83
84
struct regmap * regmap ;
84
- struct gpio_desc * slp_tr ;
85
+ int slp_tr ;
85
86
bool sleep ;
86
87
87
88
struct completion state_complete ;
@@ -106,8 +107,8 @@ at86rf230_async_state_change(struct at86rf230_local *lp,
106
107
static inline void
107
108
at86rf230_sleep (struct at86rf230_local * lp )
108
109
{
109
- if (lp -> slp_tr ) {
110
- gpiod_set_value (lp -> slp_tr , 1 );
110
+ if (gpio_is_valid ( lp -> slp_tr ) ) {
111
+ gpio_set_value (lp -> slp_tr , 1 );
111
112
usleep_range (lp -> data -> t_off_to_sleep ,
112
113
lp -> data -> t_off_to_sleep + 10 );
113
114
lp -> sleep = true;
@@ -117,8 +118,8 @@ at86rf230_sleep(struct at86rf230_local *lp)
117
118
static inline void
118
119
at86rf230_awake (struct at86rf230_local * lp )
119
120
{
120
- if (lp -> slp_tr ) {
121
- gpiod_set_value (lp -> slp_tr , 0 );
121
+ if (gpio_is_valid ( lp -> slp_tr ) ) {
122
+ gpio_set_value (lp -> slp_tr , 0 );
122
123
usleep_range (lp -> data -> t_sleep_to_off ,
123
124
lp -> data -> t_sleep_to_off + 100 );
124
125
lp -> sleep = false;
@@ -203,9 +204,9 @@ at86rf230_write_subreg(struct at86rf230_local *lp,
203
204
static inline void
204
205
at86rf230_slp_tr_rising_edge (struct at86rf230_local * lp )
205
206
{
206
- gpiod_set_value (lp -> slp_tr , 1 );
207
+ gpio_set_value (lp -> slp_tr , 1 );
207
208
udelay (1 );
208
- gpiod_set_value (lp -> slp_tr , 0 );
209
+ gpio_set_value (lp -> slp_tr , 0 );
209
210
}
210
211
211
212
static bool
@@ -818,7 +819,7 @@ at86rf230_write_frame_complete(void *context)
818
819
819
820
ctx -> trx .len = 2 ;
820
821
821
- if (lp -> slp_tr )
822
+ if (gpio_is_valid ( lp -> slp_tr ) )
822
823
at86rf230_slp_tr_rising_edge (lp );
823
824
else
824
825
at86rf230_async_write_reg (lp , RG_TRX_STATE , STATE_BUSY_TX , ctx ,
@@ -1414,6 +1415,32 @@ static int at86rf230_hw_init(struct at86rf230_local *lp, u8 xtal_trim)
1414
1415
return at86rf230_write_subreg (lp , SR_SLOTTED_OPERATION , 0 );
1415
1416
}
1416
1417
1418
+ static int
1419
+ at86rf230_get_pdata (struct spi_device * spi , int * rstn , int * slp_tr ,
1420
+ u8 * xtal_trim )
1421
+ {
1422
+ struct at86rf230_platform_data * pdata = spi -> dev .platform_data ;
1423
+ int ret ;
1424
+
1425
+ if (!IS_ENABLED (CONFIG_OF ) || !spi -> dev .of_node ) {
1426
+ if (!pdata )
1427
+ return - ENOENT ;
1428
+
1429
+ * rstn = pdata -> rstn ;
1430
+ * slp_tr = pdata -> slp_tr ;
1431
+ * xtal_trim = pdata -> xtal_trim ;
1432
+ return 0 ;
1433
+ }
1434
+
1435
+ * rstn = of_get_named_gpio (spi -> dev .of_node , "reset-gpio" , 0 );
1436
+ * slp_tr = of_get_named_gpio (spi -> dev .of_node , "sleep-gpio" , 0 );
1437
+ ret = of_property_read_u8 (spi -> dev .of_node , "xtal-trim" , xtal_trim );
1438
+ if (ret < 0 && ret != - EINVAL )
1439
+ return ret ;
1440
+
1441
+ return 0 ;
1442
+ }
1443
+
1417
1444
static int
1418
1445
at86rf230_detect_device (struct at86rf230_local * lp )
1419
1446
{
@@ -1520,35 +1547,40 @@ static int at86rf230_probe(struct spi_device *spi)
1520
1547
struct ieee802154_hw * hw ;
1521
1548
struct at86rf230_local * lp ;
1522
1549
unsigned int status ;
1523
- int rc , irq_type ;
1524
- struct gpio_desc * rstn , * slp_tr ;
1550
+ int rc , irq_type , rstn , slp_tr ;
1525
1551
u8 xtal_trim = 0 ;
1526
1552
1527
1553
if (!spi -> irq ) {
1528
1554
dev_err (& spi -> dev , "no IRQ specified\n" );
1529
1555
return - EINVAL ;
1530
1556
}
1531
1557
1532
- rc = device_property_read_u8 ( & spi -> dev , "xtal-trim" , & xtal_trim );
1533
- if (rc < 0 && rc != - EINVAL ) {
1534
- dev_err (& spi -> dev , "failed to parse xtal-trim : %d\n" , rc );
1558
+ rc = at86rf230_get_pdata ( spi , & rstn , & slp_tr , & xtal_trim );
1559
+ if (rc < 0 ) {
1560
+ dev_err (& spi -> dev , "failed to parse platform_data : %d\n" , rc );
1535
1561
return rc ;
1536
1562
}
1537
1563
1538
- rstn = devm_gpiod_get_optional (& spi -> dev , "rstn" , GPIOD_OUT_HIGH );
1539
- if (IS_ERR (rstn ))
1540
- return PTR_ERR (rstn );
1564
+ if (gpio_is_valid (rstn )) {
1565
+ rc = devm_gpio_request_one (& spi -> dev , rstn ,
1566
+ GPIOF_OUT_INIT_HIGH , "rstn" );
1567
+ if (rc )
1568
+ return rc ;
1569
+ }
1541
1570
1542
- slp_tr = devm_gpiod_get_optional (& spi -> dev , "slp_tr" , GPIOD_OUT_LOW );
1543
- if (IS_ERR (slp_tr ))
1544
- return PTR_ERR (slp_tr );
1571
+ if (gpio_is_valid (slp_tr )) {
1572
+ rc = devm_gpio_request_one (& spi -> dev , slp_tr ,
1573
+ GPIOF_OUT_INIT_LOW , "slp_tr" );
1574
+ if (rc )
1575
+ return rc ;
1576
+ }
1545
1577
1546
1578
/* Reset */
1547
- if (rstn ) {
1579
+ if (gpio_is_valid ( rstn ) ) {
1548
1580
udelay (1 );
1549
- gpiod_set_value_cansleep (rstn , 0 );
1581
+ gpio_set_value_cansleep (rstn , 0 );
1550
1582
udelay (1 );
1551
- gpiod_set_value_cansleep (rstn , 1 );
1583
+ gpio_set_value_cansleep (rstn , 1 );
1552
1584
usleep_range (120 , 240 );
1553
1585
}
1554
1586
@@ -1650,7 +1682,7 @@ MODULE_DEVICE_TABLE(spi, at86rf230_device_id);
1650
1682
static struct spi_driver at86rf230_driver = {
1651
1683
.id_table = at86rf230_device_id ,
1652
1684
.driver = {
1653
- .of_match_table = at86rf230_of_match ,
1685
+ .of_match_table = of_match_ptr ( at86rf230_of_match ) ,
1654
1686
.name = "at86rf230" ,
1655
1687
},
1656
1688
.probe = at86rf230_probe ,
0 commit comments