alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 1 | /* |
| 2 | * AT86RF230/RF231 driver |
| 3 | * |
| 4 | * Copyright (C) 2009-2012 Siemens AG |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 |
| 8 | * as published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 15 | * Written by: |
| 16 | * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> |
| 17 | * Alexander Smirnov <alex.bluesman.smirnov@gmail.com> |
Alexander Aring | 01ebd60 | 2014-07-03 00:20:55 +0200 | [diff] [blame] | 18 | * Alexander Aring <aar@pengutronix.de> |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 19 | */ |
| 20 | #include <linux/kernel.h> |
| 21 | #include <linux/module.h> |
Alexander Aring | eb3b435 | 2015-03-09 13:56:10 +0100 | [diff] [blame] | 22 | #include <linux/hrtimer.h> |
Alexander Aring | dce481e | 2015-03-09 13:56:11 +0100 | [diff] [blame] | 23 | #include <linux/jiffies.h> |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 24 | #include <linux/interrupt.h> |
Alexander Aring | 4af619a | 2014-04-24 19:09:05 +0200 | [diff] [blame] | 25 | #include <linux/irq.h> |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 26 | #include <linux/gpio.h> |
| 27 | #include <linux/delay.h> |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 28 | #include <linux/spi/spi.h> |
| 29 | #include <linux/spi/at86rf230.h> |
Alexander Aring | f76014f77 | 2014-07-03 00:20:44 +0200 | [diff] [blame] | 30 | #include <linux/regmap.h> |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 31 | #include <linux/skbuff.h> |
Alexander Aring | fa2d3e9 | 2014-03-15 09:29:07 +0100 | [diff] [blame] | 32 | #include <linux/of_gpio.h> |
Alexander Aring | 4ca24ac | 2014-10-25 09:41:04 +0200 | [diff] [blame] | 33 | #include <linux/ieee802154.h> |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 34 | |
| 35 | #include <net/mac802154.h> |
Alexander Aring | 5ad60d3 | 2014-10-25 09:41:02 +0200 | [diff] [blame] | 36 | #include <net/cfg802154.h> |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 37 | |
Alexander Aring | a53d1f7 | 2014-07-03 00:20:46 +0200 | [diff] [blame] | 38 | struct at86rf230_local; |
| 39 | /* at86rf2xx chip depend data. |
| 40 | * All timings are in us. |
| 41 | */ |
| 42 | struct at86rf2xx_chip_data { |
Alexander Aring | 7a4ef91 | 2014-07-03 00:20:54 +0200 | [diff] [blame] | 43 | u16 t_sleep_cycle; |
Alexander Aring | 984e0c6 | 2014-07-03 00:20:53 +0200 | [diff] [blame] | 44 | u16 t_channel_switch; |
Alexander Aring | 09e536c | 2014-07-03 00:20:52 +0200 | [diff] [blame] | 45 | u16 t_reset_to_off; |
Alexander Aring | 2e0571c | 2014-07-03 00:20:51 +0200 | [diff] [blame] | 46 | u16 t_off_to_aack; |
| 47 | u16 t_off_to_tx_on; |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 48 | u16 t_frame; |
| 49 | u16 t_p_ack; |
Alexander Aring | a53d1f7 | 2014-07-03 00:20:46 +0200 | [diff] [blame] | 50 | int rssi_base_val; |
| 51 | |
Alexander Aring | e37d2ec | 2014-10-28 18:21:19 +0100 | [diff] [blame] | 52 | int (*set_channel)(struct at86rf230_local *, u8, u8); |
Alexander Aring | a7d7eda | 2014-07-03 00:20:47 +0200 | [diff] [blame] | 53 | int (*get_desense_steps)(struct at86rf230_local *, s32); |
Alexander Aring | a53d1f7 | 2014-07-03 00:20:46 +0200 | [diff] [blame] | 54 | }; |
| 55 | |
Alexander Aring | ba6d223 | 2015-03-01 21:55:28 +0100 | [diff] [blame] | 56 | #define AT86RF2XX_MAX_BUF (127 + 3) |
| 57 | /* tx retries to access the TX_ON state |
| 58 | * if it's above then force change will be started. |
| 59 | * |
| 60 | * We assume the max_frame_retries (7) value of 802.15.4 here. |
| 61 | */ |
| 62 | #define AT86RF2XX_MAX_TX_RETRIES 7 |
Alexander Aring | dce481e | 2015-03-09 13:56:11 +0100 | [diff] [blame] | 63 | /* We use the recommended 5 minutes timeout to recalibrate */ |
| 64 | #define AT86RF2XX_CAL_LOOP_TIMEOUT (5 * 60 * HZ) |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 65 | |
| 66 | struct at86rf230_state_change { |
| 67 | struct at86rf230_local *lp; |
Alexander Aring | cca990c | 2015-03-01 21:55:31 +0100 | [diff] [blame] | 68 | int irq; |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 69 | |
Alexander Aring | eb3b435 | 2015-03-09 13:56:10 +0100 | [diff] [blame] | 70 | struct hrtimer timer; |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 71 | struct spi_message msg; |
| 72 | struct spi_transfer trx; |
| 73 | u8 buf[AT86RF2XX_MAX_BUF]; |
| 74 | |
| 75 | void (*complete)(void *context); |
| 76 | u8 from_state; |
| 77 | u8 to_state; |
Alexander Aring | 97fed79 | 2014-10-07 10:38:32 +0200 | [diff] [blame] | 78 | |
| 79 | bool irq_enable; |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 80 | }; |
| 81 | |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 82 | struct at86rf230_local { |
| 83 | struct spi_device *spi; |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 84 | |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 85 | struct ieee802154_hw *hw; |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 86 | struct at86rf2xx_chip_data *data; |
Alexander Aring | f76014f77 | 2014-07-03 00:20:44 +0200 | [diff] [blame] | 87 | struct regmap *regmap; |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 88 | |
Alexander Aring | 2e0571c | 2014-07-03 00:20:51 +0200 | [diff] [blame] | 89 | struct completion state_complete; |
| 90 | struct at86rf230_state_change state; |
| 91 | |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 92 | struct at86rf230_state_change irq; |
Alexander Aring | a53d1f7 | 2014-07-03 00:20:46 +0200 | [diff] [blame] | 93 | |
Phoebe Buckheister | f2fdd67 | 2014-02-17 11:34:15 +0100 | [diff] [blame] | 94 | bool tx_aret; |
Alexander Aring | dce481e | 2015-03-09 13:56:11 +0100 | [diff] [blame] | 95 | unsigned long cal_timeout; |
Alexander Aring | 850f43a | 2014-10-07 10:38:27 +0200 | [diff] [blame] | 96 | s8 max_frame_retries; |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 97 | bool is_tx; |
Alexander Aring | ba6d223 | 2015-03-01 21:55:28 +0100 | [diff] [blame] | 98 | u8 tx_retry; |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 99 | struct sk_buff *tx_skb; |
| 100 | struct at86rf230_state_change tx; |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 101 | }; |
| 102 | |
Alexander Aring | 5e8e01e | 2015-04-30 17:44:58 +0200 | [diff] [blame] | 103 | #define RG_TRX_STATUS (0x01) |
| 104 | #define SR_TRX_STATUS 0x01, 0x1f, 0 |
| 105 | #define SR_RESERVED_01_3 0x01, 0x20, 5 |
| 106 | #define SR_CCA_STATUS 0x01, 0x40, 6 |
| 107 | #define SR_CCA_DONE 0x01, 0x80, 7 |
| 108 | #define RG_TRX_STATE (0x02) |
| 109 | #define SR_TRX_CMD 0x02, 0x1f, 0 |
| 110 | #define SR_TRAC_STATUS 0x02, 0xe0, 5 |
| 111 | #define RG_TRX_CTRL_0 (0x03) |
| 112 | #define SR_CLKM_CTRL 0x03, 0x07, 0 |
| 113 | #define SR_CLKM_SHA_SEL 0x03, 0x08, 3 |
| 114 | #define SR_PAD_IO_CLKM 0x03, 0x30, 4 |
| 115 | #define SR_PAD_IO 0x03, 0xc0, 6 |
| 116 | #define RG_TRX_CTRL_1 (0x04) |
| 117 | #define SR_IRQ_POLARITY 0x04, 0x01, 0 |
| 118 | #define SR_IRQ_MASK_MODE 0x04, 0x02, 1 |
| 119 | #define SR_SPI_CMD_MODE 0x04, 0x0c, 2 |
| 120 | #define SR_RX_BL_CTRL 0x04, 0x10, 4 |
| 121 | #define SR_TX_AUTO_CRC_ON 0x04, 0x20, 5 |
| 122 | #define SR_IRQ_2_EXT_EN 0x04, 0x40, 6 |
| 123 | #define SR_PA_EXT_EN 0x04, 0x80, 7 |
| 124 | #define RG_PHY_TX_PWR (0x05) |
| 125 | #define SR_TX_PWR 0x05, 0x0f, 0 |
| 126 | #define SR_PA_LT 0x05, 0x30, 4 |
| 127 | #define SR_PA_BUF_LT 0x05, 0xc0, 6 |
| 128 | #define RG_PHY_RSSI (0x06) |
| 129 | #define SR_RSSI 0x06, 0x1f, 0 |
| 130 | #define SR_RND_VALUE 0x06, 0x60, 5 |
| 131 | #define SR_RX_CRC_VALID 0x06, 0x80, 7 |
| 132 | #define RG_PHY_ED_LEVEL (0x07) |
| 133 | #define SR_ED_LEVEL 0x07, 0xff, 0 |
| 134 | #define RG_PHY_CC_CCA (0x08) |
| 135 | #define SR_CHANNEL 0x08, 0x1f, 0 |
| 136 | #define SR_CCA_MODE 0x08, 0x60, 5 |
| 137 | #define SR_CCA_REQUEST 0x08, 0x80, 7 |
| 138 | #define RG_CCA_THRES (0x09) |
| 139 | #define SR_CCA_ED_THRES 0x09, 0x0f, 0 |
| 140 | #define SR_RESERVED_09_1 0x09, 0xf0, 4 |
| 141 | #define RG_RX_CTRL (0x0a) |
| 142 | #define SR_PDT_THRES 0x0a, 0x0f, 0 |
| 143 | #define SR_RESERVED_0a_1 0x0a, 0xf0, 4 |
| 144 | #define RG_SFD_VALUE (0x0b) |
| 145 | #define SR_SFD_VALUE 0x0b, 0xff, 0 |
| 146 | #define RG_TRX_CTRL_2 (0x0c) |
| 147 | #define SR_OQPSK_DATA_RATE 0x0c, 0x03, 0 |
| 148 | #define SR_SUB_MODE 0x0c, 0x04, 2 |
| 149 | #define SR_BPSK_QPSK 0x0c, 0x08, 3 |
| 150 | #define SR_OQPSK_SUB1_RC_EN 0x0c, 0x10, 4 |
| 151 | #define SR_RESERVED_0c_5 0x0c, 0x60, 5 |
| 152 | #define SR_RX_SAFE_MODE 0x0c, 0x80, 7 |
| 153 | #define RG_ANT_DIV (0x0d) |
| 154 | #define SR_ANT_CTRL 0x0d, 0x03, 0 |
| 155 | #define SR_ANT_EXT_SW_EN 0x0d, 0x04, 2 |
| 156 | #define SR_ANT_DIV_EN 0x0d, 0x08, 3 |
| 157 | #define SR_RESERVED_0d_2 0x0d, 0x70, 4 |
| 158 | #define SR_ANT_SEL 0x0d, 0x80, 7 |
| 159 | #define RG_IRQ_MASK (0x0e) |
| 160 | #define SR_IRQ_MASK 0x0e, 0xff, 0 |
| 161 | #define RG_IRQ_STATUS (0x0f) |
| 162 | #define SR_IRQ_0_PLL_LOCK 0x0f, 0x01, 0 |
| 163 | #define SR_IRQ_1_PLL_UNLOCK 0x0f, 0x02, 1 |
| 164 | #define SR_IRQ_2_RX_START 0x0f, 0x04, 2 |
| 165 | #define SR_IRQ_3_TRX_END 0x0f, 0x08, 3 |
| 166 | #define SR_IRQ_4_CCA_ED_DONE 0x0f, 0x10, 4 |
| 167 | #define SR_IRQ_5_AMI 0x0f, 0x20, 5 |
| 168 | #define SR_IRQ_6_TRX_UR 0x0f, 0x40, 6 |
| 169 | #define SR_IRQ_7_BAT_LOW 0x0f, 0x80, 7 |
| 170 | #define RG_VREG_CTRL (0x10) |
| 171 | #define SR_RESERVED_10_6 0x10, 0x03, 0 |
| 172 | #define SR_DVDD_OK 0x10, 0x04, 2 |
| 173 | #define SR_DVREG_EXT 0x10, 0x08, 3 |
| 174 | #define SR_RESERVED_10_3 0x10, 0x30, 4 |
| 175 | #define SR_AVDD_OK 0x10, 0x40, 6 |
| 176 | #define SR_AVREG_EXT 0x10, 0x80, 7 |
| 177 | #define RG_BATMON (0x11) |
| 178 | #define SR_BATMON_VTH 0x11, 0x0f, 0 |
| 179 | #define SR_BATMON_HR 0x11, 0x10, 4 |
| 180 | #define SR_BATMON_OK 0x11, 0x20, 5 |
| 181 | #define SR_RESERVED_11_1 0x11, 0xc0, 6 |
| 182 | #define RG_XOSC_CTRL (0x12) |
| 183 | #define SR_XTAL_TRIM 0x12, 0x0f, 0 |
| 184 | #define SR_XTAL_MODE 0x12, 0xf0, 4 |
| 185 | #define RG_RX_SYN (0x15) |
| 186 | #define SR_RX_PDT_LEVEL 0x15, 0x0f, 0 |
| 187 | #define SR_RESERVED_15_2 0x15, 0x70, 4 |
| 188 | #define SR_RX_PDT_DIS 0x15, 0x80, 7 |
| 189 | #define RG_XAH_CTRL_1 (0x17) |
| 190 | #define SR_RESERVED_17_8 0x17, 0x01, 0 |
| 191 | #define SR_AACK_PROM_MODE 0x17, 0x02, 1 |
| 192 | #define SR_AACK_ACK_TIME 0x17, 0x04, 2 |
| 193 | #define SR_RESERVED_17_5 0x17, 0x08, 3 |
| 194 | #define SR_AACK_UPLD_RES_FT 0x17, 0x10, 4 |
| 195 | #define SR_AACK_FLTR_RES_FT 0x17, 0x20, 5 |
| 196 | #define SR_CSMA_LBT_MODE 0x17, 0x40, 6 |
| 197 | #define SR_RESERVED_17_1 0x17, 0x80, 7 |
| 198 | #define RG_FTN_CTRL (0x18) |
| 199 | #define SR_RESERVED_18_2 0x18, 0x7f, 0 |
| 200 | #define SR_FTN_START 0x18, 0x80, 7 |
| 201 | #define RG_PLL_CF (0x1a) |
| 202 | #define SR_RESERVED_1a_2 0x1a, 0x7f, 0 |
| 203 | #define SR_PLL_CF_START 0x1a, 0x80, 7 |
| 204 | #define RG_PLL_DCU (0x1b) |
| 205 | #define SR_RESERVED_1b_3 0x1b, 0x3f, 0 |
| 206 | #define SR_RESERVED_1b_2 0x1b, 0x40, 6 |
| 207 | #define SR_PLL_DCU_START 0x1b, 0x80, 7 |
| 208 | #define RG_PART_NUM (0x1c) |
| 209 | #define SR_PART_NUM 0x1c, 0xff, 0 |
| 210 | #define RG_VERSION_NUM (0x1d) |
| 211 | #define SR_VERSION_NUM 0x1d, 0xff, 0 |
| 212 | #define RG_MAN_ID_0 (0x1e) |
| 213 | #define SR_MAN_ID_0 0x1e, 0xff, 0 |
| 214 | #define RG_MAN_ID_1 (0x1f) |
| 215 | #define SR_MAN_ID_1 0x1f, 0xff, 0 |
| 216 | #define RG_SHORT_ADDR_0 (0x20) |
| 217 | #define SR_SHORT_ADDR_0 0x20, 0xff, 0 |
| 218 | #define RG_SHORT_ADDR_1 (0x21) |
| 219 | #define SR_SHORT_ADDR_1 0x21, 0xff, 0 |
| 220 | #define RG_PAN_ID_0 (0x22) |
| 221 | #define SR_PAN_ID_0 0x22, 0xff, 0 |
| 222 | #define RG_PAN_ID_1 (0x23) |
| 223 | #define SR_PAN_ID_1 0x23, 0xff, 0 |
| 224 | #define RG_IEEE_ADDR_0 (0x24) |
| 225 | #define SR_IEEE_ADDR_0 0x24, 0xff, 0 |
| 226 | #define RG_IEEE_ADDR_1 (0x25) |
| 227 | #define SR_IEEE_ADDR_1 0x25, 0xff, 0 |
| 228 | #define RG_IEEE_ADDR_2 (0x26) |
| 229 | #define SR_IEEE_ADDR_2 0x26, 0xff, 0 |
| 230 | #define RG_IEEE_ADDR_3 (0x27) |
| 231 | #define SR_IEEE_ADDR_3 0x27, 0xff, 0 |
| 232 | #define RG_IEEE_ADDR_4 (0x28) |
| 233 | #define SR_IEEE_ADDR_4 0x28, 0xff, 0 |
| 234 | #define RG_IEEE_ADDR_5 (0x29) |
| 235 | #define SR_IEEE_ADDR_5 0x29, 0xff, 0 |
| 236 | #define RG_IEEE_ADDR_6 (0x2a) |
| 237 | #define SR_IEEE_ADDR_6 0x2a, 0xff, 0 |
| 238 | #define RG_IEEE_ADDR_7 (0x2b) |
| 239 | #define SR_IEEE_ADDR_7 0x2b, 0xff, 0 |
| 240 | #define RG_XAH_CTRL_0 (0x2c) |
| 241 | #define SR_SLOTTED_OPERATION 0x2c, 0x01, 0 |
| 242 | #define SR_MAX_CSMA_RETRIES 0x2c, 0x0e, 1 |
| 243 | #define SR_MAX_FRAME_RETRIES 0x2c, 0xf0, 4 |
| 244 | #define RG_CSMA_SEED_0 (0x2d) |
| 245 | #define SR_CSMA_SEED_0 0x2d, 0xff, 0 |
| 246 | #define RG_CSMA_SEED_1 (0x2e) |
| 247 | #define SR_CSMA_SEED_1 0x2e, 0x07, 0 |
| 248 | #define SR_AACK_I_AM_COORD 0x2e, 0x08, 3 |
| 249 | #define SR_AACK_DIS_ACK 0x2e, 0x10, 4 |
| 250 | #define SR_AACK_SET_PD 0x2e, 0x20, 5 |
| 251 | #define SR_AACK_FVN_MODE 0x2e, 0xc0, 6 |
| 252 | #define RG_CSMA_BE (0x2f) |
| 253 | #define SR_MIN_BE 0x2f, 0x0f, 0 |
| 254 | #define SR_MAX_BE 0x2f, 0xf0, 4 |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 255 | |
| 256 | #define CMD_REG 0x80 |
| 257 | #define CMD_REG_MASK 0x3f |
| 258 | #define CMD_WRITE 0x40 |
| 259 | #define CMD_FB 0x20 |
| 260 | |
| 261 | #define IRQ_BAT_LOW (1 << 7) |
| 262 | #define IRQ_TRX_UR (1 << 6) |
| 263 | #define IRQ_AMI (1 << 5) |
| 264 | #define IRQ_CCA_ED (1 << 4) |
| 265 | #define IRQ_TRX_END (1 << 3) |
| 266 | #define IRQ_RX_START (1 << 2) |
| 267 | #define IRQ_PLL_UNL (1 << 1) |
| 268 | #define IRQ_PLL_LOCK (1 << 0) |
| 269 | |
Sascha Herrmann | 43b5abe | 2013-04-14 22:33:28 +0000 | [diff] [blame] | 270 | #define IRQ_ACTIVE_HIGH 0 |
| 271 | #define IRQ_ACTIVE_LOW 1 |
| 272 | |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 273 | #define STATE_P_ON 0x00 /* BUSY */ |
| 274 | #define STATE_BUSY_RX 0x01 |
| 275 | #define STATE_BUSY_TX 0x02 |
| 276 | #define STATE_FORCE_TRX_OFF 0x03 |
| 277 | #define STATE_FORCE_TX_ON 0x04 /* IDLE */ |
| 278 | /* 0x05 */ /* INVALID_PARAMETER */ |
| 279 | #define STATE_RX_ON 0x06 |
| 280 | /* 0x07 */ /* SUCCESS */ |
| 281 | #define STATE_TRX_OFF 0x08 |
| 282 | #define STATE_TX_ON 0x09 |
| 283 | /* 0x0a - 0x0e */ /* 0x0a - UNSUPPORTED_ATTRIBUTE */ |
| 284 | #define STATE_SLEEP 0x0F |
Thomas Stilwell | 48d5dba | 2014-03-10 19:29:25 -0500 | [diff] [blame] | 285 | #define STATE_PREP_DEEP_SLEEP 0x10 |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 286 | #define STATE_BUSY_RX_AACK 0x11 |
| 287 | #define STATE_BUSY_TX_ARET 0x12 |
stefan@datenfreihafen.org | 028889b | 2013-03-26 12:41:31 +0000 | [diff] [blame] | 288 | #define STATE_RX_AACK_ON 0x16 |
| 289 | #define STATE_TX_ARET_ON 0x19 |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 290 | #define STATE_RX_ON_NOCLK 0x1C |
| 291 | #define STATE_RX_AACK_ON_NOCLK 0x1D |
| 292 | #define STATE_BUSY_RX_AACK_NOCLK 0x1E |
| 293 | #define STATE_TRANSITION_IN_PROGRESS 0x1F |
| 294 | |
Christoffer Holmstedt | 4748e86 | 2015-04-30 17:44:56 +0200 | [diff] [blame] | 295 | #define TRX_STATE_MASK (0x1F) |
| 296 | |
Alexander Aring | f76014f77 | 2014-07-03 00:20:44 +0200 | [diff] [blame] | 297 | #define AT86RF2XX_NUMREGS 0x3F |
| 298 | |
Alexander Aring | 97fed79 | 2014-10-07 10:38:32 +0200 | [diff] [blame] | 299 | static void |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 300 | at86rf230_async_state_change(struct at86rf230_local *lp, |
| 301 | struct at86rf230_state_change *ctx, |
Alexander Aring | 97fed79 | 2014-10-07 10:38:32 +0200 | [diff] [blame] | 302 | const u8 state, void (*complete)(void *context), |
| 303 | const bool irq_enable); |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 304 | |
Alexander Aring | f76014f77 | 2014-07-03 00:20:44 +0200 | [diff] [blame] | 305 | static inline int |
| 306 | __at86rf230_write(struct at86rf230_local *lp, |
| 307 | unsigned int addr, unsigned int data) |
| 308 | { |
| 309 | return regmap_write(lp->regmap, addr, data); |
| 310 | } |
| 311 | |
| 312 | static inline int |
| 313 | __at86rf230_read(struct at86rf230_local *lp, |
| 314 | unsigned int addr, unsigned int *data) |
| 315 | { |
| 316 | return regmap_read(lp->regmap, addr, data); |
| 317 | } |
| 318 | |
| 319 | static inline int |
| 320 | at86rf230_read_subreg(struct at86rf230_local *lp, |
| 321 | unsigned int addr, unsigned int mask, |
| 322 | unsigned int shift, unsigned int *data) |
| 323 | { |
| 324 | int rc; |
| 325 | |
| 326 | rc = __at86rf230_read(lp, addr, data); |
Alexander Aring | d907c4f | 2015-03-17 10:32:39 +0100 | [diff] [blame] | 327 | if (!rc) |
Alexander Aring | f76014f77 | 2014-07-03 00:20:44 +0200 | [diff] [blame] | 328 | *data = (*data & mask) >> shift; |
| 329 | |
| 330 | return rc; |
| 331 | } |
| 332 | |
| 333 | static inline int |
| 334 | at86rf230_write_subreg(struct at86rf230_local *lp, |
| 335 | unsigned int addr, unsigned int mask, |
| 336 | unsigned int shift, unsigned int data) |
| 337 | { |
| 338 | return regmap_update_bits(lp->regmap, addr, mask, data << shift); |
| 339 | } |
| 340 | |
| 341 | static bool |
| 342 | at86rf230_reg_writeable(struct device *dev, unsigned int reg) |
| 343 | { |
| 344 | switch (reg) { |
| 345 | case RG_TRX_STATE: |
| 346 | case RG_TRX_CTRL_0: |
| 347 | case RG_TRX_CTRL_1: |
| 348 | case RG_PHY_TX_PWR: |
| 349 | case RG_PHY_ED_LEVEL: |
| 350 | case RG_PHY_CC_CCA: |
| 351 | case RG_CCA_THRES: |
| 352 | case RG_RX_CTRL: |
| 353 | case RG_SFD_VALUE: |
| 354 | case RG_TRX_CTRL_2: |
| 355 | case RG_ANT_DIV: |
| 356 | case RG_IRQ_MASK: |
| 357 | case RG_VREG_CTRL: |
| 358 | case RG_BATMON: |
| 359 | case RG_XOSC_CTRL: |
| 360 | case RG_RX_SYN: |
| 361 | case RG_XAH_CTRL_1: |
| 362 | case RG_FTN_CTRL: |
| 363 | case RG_PLL_CF: |
| 364 | case RG_PLL_DCU: |
| 365 | case RG_SHORT_ADDR_0: |
| 366 | case RG_SHORT_ADDR_1: |
| 367 | case RG_PAN_ID_0: |
| 368 | case RG_PAN_ID_1: |
| 369 | case RG_IEEE_ADDR_0: |
| 370 | case RG_IEEE_ADDR_1: |
| 371 | case RG_IEEE_ADDR_2: |
| 372 | case RG_IEEE_ADDR_3: |
| 373 | case RG_IEEE_ADDR_4: |
| 374 | case RG_IEEE_ADDR_5: |
| 375 | case RG_IEEE_ADDR_6: |
| 376 | case RG_IEEE_ADDR_7: |
| 377 | case RG_XAH_CTRL_0: |
| 378 | case RG_CSMA_SEED_0: |
| 379 | case RG_CSMA_SEED_1: |
| 380 | case RG_CSMA_BE: |
| 381 | return true; |
| 382 | default: |
| 383 | return false; |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | static bool |
| 388 | at86rf230_reg_readable(struct device *dev, unsigned int reg) |
| 389 | { |
| 390 | bool rc; |
| 391 | |
| 392 | /* all writeable are also readable */ |
| 393 | rc = at86rf230_reg_writeable(dev, reg); |
| 394 | if (rc) |
| 395 | return rc; |
| 396 | |
| 397 | /* readonly regs */ |
| 398 | switch (reg) { |
| 399 | case RG_TRX_STATUS: |
| 400 | case RG_PHY_RSSI: |
| 401 | case RG_IRQ_STATUS: |
| 402 | case RG_PART_NUM: |
| 403 | case RG_VERSION_NUM: |
| 404 | case RG_MAN_ID_1: |
| 405 | case RG_MAN_ID_0: |
| 406 | return true; |
| 407 | default: |
| 408 | return false; |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | static bool |
| 413 | at86rf230_reg_volatile(struct device *dev, unsigned int reg) |
| 414 | { |
| 415 | /* can be changed during runtime */ |
| 416 | switch (reg) { |
| 417 | case RG_TRX_STATUS: |
| 418 | case RG_TRX_STATE: |
| 419 | case RG_PHY_RSSI: |
| 420 | case RG_PHY_ED_LEVEL: |
| 421 | case RG_IRQ_STATUS: |
| 422 | case RG_VREG_CTRL: |
Alexander Aring | 51b3b2c | 2015-03-09 13:56:12 +0100 | [diff] [blame] | 423 | case RG_PLL_CF: |
| 424 | case RG_PLL_DCU: |
Alexander Aring | f76014f77 | 2014-07-03 00:20:44 +0200 | [diff] [blame] | 425 | return true; |
| 426 | default: |
| 427 | return false; |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | static bool |
| 432 | at86rf230_reg_precious(struct device *dev, unsigned int reg) |
| 433 | { |
| 434 | /* don't clear irq line on read */ |
| 435 | switch (reg) { |
| 436 | case RG_IRQ_STATUS: |
| 437 | return true; |
| 438 | default: |
| 439 | return false; |
| 440 | } |
| 441 | } |
| 442 | |
Krzysztof Kozlowski | 889ee2c | 2015-01-05 10:02:31 +0100 | [diff] [blame] | 443 | static const struct regmap_config at86rf230_regmap_spi_config = { |
Alexander Aring | f76014f77 | 2014-07-03 00:20:44 +0200 | [diff] [blame] | 444 | .reg_bits = 8, |
| 445 | .val_bits = 8, |
| 446 | .write_flag_mask = CMD_REG | CMD_WRITE, |
| 447 | .read_flag_mask = CMD_REG, |
| 448 | .cache_type = REGCACHE_RBTREE, |
| 449 | .max_register = AT86RF2XX_NUMREGS, |
| 450 | .writeable_reg = at86rf230_reg_writeable, |
| 451 | .readable_reg = at86rf230_reg_readable, |
| 452 | .volatile_reg = at86rf230_reg_volatile, |
| 453 | .precious_reg = at86rf230_reg_precious, |
| 454 | }; |
| 455 | |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 456 | static void |
| 457 | at86rf230_async_error_recover(void *context) |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 458 | { |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 459 | struct at86rf230_state_change *ctx = context; |
| 460 | struct at86rf230_local *lp = ctx->lp; |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 461 | |
Alexander Aring | a7a484b | 2015-03-26 12:46:30 +0100 | [diff] [blame] | 462 | lp->is_tx = 0; |
Alexander Aring | 97fed79 | 2014-10-07 10:38:32 +0200 | [diff] [blame] | 463 | at86rf230_async_state_change(lp, ctx, STATE_RX_AACK_ON, NULL, false); |
Alexander Aring | 955aee8 | 2014-10-26 09:37:15 +0100 | [diff] [blame] | 464 | ieee802154_wake_queue(lp->hw); |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 465 | } |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 466 | |
Alexander Aring | fc50c6e | 2014-12-15 10:25:54 +0100 | [diff] [blame] | 467 | static inline void |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 468 | at86rf230_async_error(struct at86rf230_local *lp, |
| 469 | struct at86rf230_state_change *ctx, int rc) |
| 470 | { |
| 471 | dev_err(&lp->spi->dev, "spi_async error %d\n", rc); |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 472 | |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 473 | at86rf230_async_state_change(lp, ctx, STATE_FORCE_TRX_OFF, |
Alexander Aring | 97fed79 | 2014-10-07 10:38:32 +0200 | [diff] [blame] | 474 | at86rf230_async_error_recover, false); |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 475 | } |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 476 | |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 477 | /* Generic function to get some register value in async mode */ |
Alexander Aring | 97fed79 | 2014-10-07 10:38:32 +0200 | [diff] [blame] | 478 | static void |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 479 | at86rf230_async_read_reg(struct at86rf230_local *lp, const u8 reg, |
| 480 | struct at86rf230_state_change *ctx, |
Alexander Aring | 97fed79 | 2014-10-07 10:38:32 +0200 | [diff] [blame] | 481 | void (*complete)(void *context), |
| 482 | const bool irq_enable) |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 483 | { |
Alexander Aring | 97fed79 | 2014-10-07 10:38:32 +0200 | [diff] [blame] | 484 | int rc; |
| 485 | |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 486 | u8 *tx_buf = ctx->buf; |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 487 | |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 488 | tx_buf[0] = (reg & CMD_REG_MASK) | CMD_REG; |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 489 | ctx->msg.complete = complete; |
Alexander Aring | 97fed79 | 2014-10-07 10:38:32 +0200 | [diff] [blame] | 490 | ctx->irq_enable = irq_enable; |
| 491 | rc = spi_async(lp->spi, &ctx->msg); |
| 492 | if (rc) { |
| 493 | if (irq_enable) |
Alexander Aring | cca990c | 2015-03-01 21:55:31 +0100 | [diff] [blame] | 494 | enable_irq(ctx->irq); |
Alexander Aring | 97fed79 | 2014-10-07 10:38:32 +0200 | [diff] [blame] | 495 | |
| 496 | at86rf230_async_error(lp, ctx, rc); |
| 497 | } |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 498 | } |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 499 | |
Alexander Aring | dce481e | 2015-03-09 13:56:11 +0100 | [diff] [blame] | 500 | static inline u8 at86rf230_state_to_force(u8 state) |
| 501 | { |
| 502 | if (state == STATE_TX_ON) |
| 503 | return STATE_FORCE_TX_ON; |
| 504 | else |
| 505 | return STATE_FORCE_TRX_OFF; |
| 506 | } |
| 507 | |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 508 | static void |
| 509 | at86rf230_async_state_assert(void *context) |
| 510 | { |
| 511 | struct at86rf230_state_change *ctx = context; |
| 512 | struct at86rf230_local *lp = ctx->lp; |
| 513 | const u8 *buf = ctx->buf; |
Christoffer Holmstedt | 4748e86 | 2015-04-30 17:44:56 +0200 | [diff] [blame] | 514 | const u8 trx_state = buf[1] & TRX_STATE_MASK; |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 515 | |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 516 | /* Assert state change */ |
| 517 | if (trx_state != ctx->to_state) { |
| 518 | /* Special handling if transceiver state is in |
| 519 | * STATE_BUSY_RX_AACK and a SHR was detected. |
| 520 | */ |
| 521 | if (trx_state == STATE_BUSY_RX_AACK) { |
| 522 | /* Undocumented race condition. If we send a state |
| 523 | * change to STATE_RX_AACK_ON the transceiver could |
| 524 | * change his state automatically to STATE_BUSY_RX_AACK |
| 525 | * if a SHR was detected. This is not an error, but we |
| 526 | * can't assert this. |
| 527 | */ |
| 528 | if (ctx->to_state == STATE_RX_AACK_ON) |
| 529 | goto done; |
| 530 | |
| 531 | /* If we change to STATE_TX_ON without forcing and |
| 532 | * transceiver state is STATE_BUSY_RX_AACK, we wait |
| 533 | * 'tFrame + tPAck' receiving time. In this time the |
| 534 | * PDU should be received. If the transceiver is still |
| 535 | * in STATE_BUSY_RX_AACK, we run a force state change |
| 536 | * to STATE_TX_ON. This is a timeout handling, if the |
| 537 | * transceiver stucks in STATE_BUSY_RX_AACK. |
Alexander Aring | ba6d223 | 2015-03-01 21:55:28 +0100 | [diff] [blame] | 538 | * |
| 539 | * Additional we do several retries to try to get into |
| 540 | * TX_ON state without forcing. If the retries are |
| 541 | * higher or equal than AT86RF2XX_MAX_TX_RETRIES we |
| 542 | * will do a force change. |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 543 | */ |
Alexander Aring | dce481e | 2015-03-09 13:56:11 +0100 | [diff] [blame] | 544 | if (ctx->to_state == STATE_TX_ON || |
| 545 | ctx->to_state == STATE_TRX_OFF) { |
| 546 | u8 state = ctx->to_state; |
Alexander Aring | ba6d223 | 2015-03-01 21:55:28 +0100 | [diff] [blame] | 547 | |
| 548 | if (lp->tx_retry >= AT86RF2XX_MAX_TX_RETRIES) |
Alexander Aring | dce481e | 2015-03-09 13:56:11 +0100 | [diff] [blame] | 549 | state = at86rf230_state_to_force(state); |
Alexander Aring | ba6d223 | 2015-03-01 21:55:28 +0100 | [diff] [blame] | 550 | lp->tx_retry++; |
| 551 | |
| 552 | at86rf230_async_state_change(lp, ctx, state, |
Alexander Aring | 97fed79 | 2014-10-07 10:38:32 +0200 | [diff] [blame] | 553 | ctx->complete, |
| 554 | ctx->irq_enable); |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 555 | return; |
| 556 | } |
| 557 | } |
| 558 | |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 559 | dev_warn(&lp->spi->dev, "unexcept state change from 0x%02x to 0x%02x. Actual state: 0x%02x\n", |
| 560 | ctx->from_state, ctx->to_state, trx_state); |
| 561 | } |
| 562 | |
| 563 | done: |
| 564 | if (ctx->complete) |
| 565 | ctx->complete(context); |
| 566 | } |
| 567 | |
Alexander Aring | eb3b435 | 2015-03-09 13:56:10 +0100 | [diff] [blame] | 568 | static enum hrtimer_restart at86rf230_async_state_timer(struct hrtimer *timer) |
| 569 | { |
| 570 | struct at86rf230_state_change *ctx = |
| 571 | container_of(timer, struct at86rf230_state_change, timer); |
| 572 | struct at86rf230_local *lp = ctx->lp; |
| 573 | |
| 574 | at86rf230_async_read_reg(lp, RG_TRX_STATUS, ctx, |
| 575 | at86rf230_async_state_assert, |
| 576 | ctx->irq_enable); |
| 577 | |
| 578 | return HRTIMER_NORESTART; |
| 579 | } |
| 580 | |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 581 | /* Do state change timing delay. */ |
| 582 | static void |
| 583 | at86rf230_async_state_delay(void *context) |
| 584 | { |
| 585 | struct at86rf230_state_change *ctx = context; |
| 586 | struct at86rf230_local *lp = ctx->lp; |
| 587 | struct at86rf2xx_chip_data *c = lp->data; |
| 588 | bool force = false; |
Alexander Aring | eb3b435 | 2015-03-09 13:56:10 +0100 | [diff] [blame] | 589 | ktime_t tim; |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 590 | |
| 591 | /* The force state changes are will show as normal states in the |
| 592 | * state status subregister. We change the to_state to the |
| 593 | * corresponding one and remember if it was a force change, this |
| 594 | * differs if we do a state change from STATE_BUSY_RX_AACK. |
| 595 | */ |
| 596 | switch (ctx->to_state) { |
| 597 | case STATE_FORCE_TX_ON: |
| 598 | ctx->to_state = STATE_TX_ON; |
| 599 | force = true; |
| 600 | break; |
| 601 | case STATE_FORCE_TRX_OFF: |
| 602 | ctx->to_state = STATE_TRX_OFF; |
| 603 | force = true; |
| 604 | break; |
| 605 | default: |
| 606 | break; |
| 607 | } |
| 608 | |
| 609 | switch (ctx->from_state) { |
Alexander Aring | 2e0571c | 2014-07-03 00:20:51 +0200 | [diff] [blame] | 610 | case STATE_TRX_OFF: |
| 611 | switch (ctx->to_state) { |
| 612 | case STATE_RX_AACK_ON: |
Alexander Aring | eb3b435 | 2015-03-09 13:56:10 +0100 | [diff] [blame] | 613 | tim = ktime_set(0, c->t_off_to_aack * NSEC_PER_USEC); |
Alexander Aring | 2ad3324 | 2015-04-30 17:44:59 +0200 | [diff] [blame] | 614 | /* state change from TRX_OFF to RX_AACK_ON to do a |
| 615 | * calibration, we need to reset the timeout for the |
| 616 | * next one. |
| 617 | */ |
| 618 | lp->cal_timeout = jiffies + AT86RF2XX_CAL_LOOP_TIMEOUT; |
Alexander Aring | 2e0571c | 2014-07-03 00:20:51 +0200 | [diff] [blame] | 619 | goto change; |
Alexander Aring | 3b951ca | 2015-04-30 17:45:00 +0200 | [diff] [blame^] | 620 | case STATE_TX_ARET_ON: |
Alexander Aring | 2e0571c | 2014-07-03 00:20:51 +0200 | [diff] [blame] | 621 | case STATE_TX_ON: |
Alexander Aring | eb3b435 | 2015-03-09 13:56:10 +0100 | [diff] [blame] | 622 | tim = ktime_set(0, c->t_off_to_tx_on * NSEC_PER_USEC); |
Alexander Aring | 3b951ca | 2015-04-30 17:45:00 +0200 | [diff] [blame^] | 623 | /* state change from TRX_OFF to TX_ON or ARET_ON to do |
| 624 | * a calibration, we need to reset the timeout for the |
Alexander Aring | dce481e | 2015-03-09 13:56:11 +0100 | [diff] [blame] | 625 | * next one. |
| 626 | */ |
| 627 | lp->cal_timeout = jiffies + AT86RF2XX_CAL_LOOP_TIMEOUT; |
Alexander Aring | 2e0571c | 2014-07-03 00:20:51 +0200 | [diff] [blame] | 628 | goto change; |
| 629 | default: |
| 630 | break; |
| 631 | } |
| 632 | break; |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 633 | case STATE_BUSY_RX_AACK: |
| 634 | switch (ctx->to_state) { |
Alexander Aring | dce481e | 2015-03-09 13:56:11 +0100 | [diff] [blame] | 635 | case STATE_TRX_OFF: |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 636 | case STATE_TX_ON: |
| 637 | /* Wait for worst case receiving time if we |
| 638 | * didn't make a force change from BUSY_RX_AACK |
Alexander Aring | dce481e | 2015-03-09 13:56:11 +0100 | [diff] [blame] | 639 | * to TX_ON or TRX_OFF. |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 640 | */ |
| 641 | if (!force) { |
Alexander Aring | eb3b435 | 2015-03-09 13:56:10 +0100 | [diff] [blame] | 642 | tim = ktime_set(0, (c->t_frame + c->t_p_ack) * |
| 643 | NSEC_PER_USEC); |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 644 | goto change; |
| 645 | } |
| 646 | break; |
| 647 | default: |
| 648 | break; |
| 649 | } |
| 650 | break; |
Alexander Aring | 09e536c | 2014-07-03 00:20:52 +0200 | [diff] [blame] | 651 | /* Default value, means RESET state */ |
| 652 | case STATE_P_ON: |
| 653 | switch (ctx->to_state) { |
| 654 | case STATE_TRX_OFF: |
Alexander Aring | eb3b435 | 2015-03-09 13:56:10 +0100 | [diff] [blame] | 655 | tim = ktime_set(0, c->t_reset_to_off * NSEC_PER_USEC); |
Alexander Aring | 09e536c | 2014-07-03 00:20:52 +0200 | [diff] [blame] | 656 | goto change; |
| 657 | default: |
| 658 | break; |
| 659 | } |
| 660 | break; |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 661 | default: |
| 662 | break; |
| 663 | } |
| 664 | |
| 665 | /* Default delay is 1us in the most cases */ |
Alexander Aring | eb3b435 | 2015-03-09 13:56:10 +0100 | [diff] [blame] | 666 | tim = ktime_set(0, NSEC_PER_USEC); |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 667 | |
| 668 | change: |
Alexander Aring | eb3b435 | 2015-03-09 13:56:10 +0100 | [diff] [blame] | 669 | hrtimer_start(&ctx->timer, tim, HRTIMER_MODE_REL); |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | static void |
| 673 | at86rf230_async_state_change_start(void *context) |
| 674 | { |
| 675 | struct at86rf230_state_change *ctx = context; |
| 676 | struct at86rf230_local *lp = ctx->lp; |
| 677 | u8 *buf = ctx->buf; |
Christoffer Holmstedt | 4748e86 | 2015-04-30 17:44:56 +0200 | [diff] [blame] | 678 | const u8 trx_state = buf[1] & TRX_STATE_MASK; |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 679 | int rc; |
| 680 | |
| 681 | /* Check for "possible" STATE_TRANSITION_IN_PROGRESS */ |
| 682 | if (trx_state == STATE_TRANSITION_IN_PROGRESS) { |
| 683 | udelay(1); |
Alexander Aring | 97fed79 | 2014-10-07 10:38:32 +0200 | [diff] [blame] | 684 | at86rf230_async_read_reg(lp, RG_TRX_STATUS, ctx, |
| 685 | at86rf230_async_state_change_start, |
| 686 | ctx->irq_enable); |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 687 | return; |
| 688 | } |
| 689 | |
| 690 | /* Check if we already are in the state which we change in */ |
| 691 | if (trx_state == ctx->to_state) { |
| 692 | if (ctx->complete) |
| 693 | ctx->complete(context); |
| 694 | return; |
| 695 | } |
| 696 | |
| 697 | /* Set current state to the context of state change */ |
| 698 | ctx->from_state = trx_state; |
| 699 | |
| 700 | /* Going into the next step for a state change which do a timing |
| 701 | * relevant delay. |
| 702 | */ |
| 703 | buf[0] = (RG_TRX_STATE & CMD_REG_MASK) | CMD_REG | CMD_WRITE; |
| 704 | buf[1] = ctx->to_state; |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 705 | ctx->msg.complete = at86rf230_async_state_delay; |
| 706 | rc = spi_async(lp->spi, &ctx->msg); |
Alexander Aring | 97fed79 | 2014-10-07 10:38:32 +0200 | [diff] [blame] | 707 | if (rc) { |
| 708 | if (ctx->irq_enable) |
Alexander Aring | cca990c | 2015-03-01 21:55:31 +0100 | [diff] [blame] | 709 | enable_irq(ctx->irq); |
Alexander Aring | 97fed79 | 2014-10-07 10:38:32 +0200 | [diff] [blame] | 710 | |
Alexander Aring | 4fef7d3 | 2014-12-15 10:25:55 +0100 | [diff] [blame] | 711 | at86rf230_async_error(lp, ctx, rc); |
Alexander Aring | 97fed79 | 2014-10-07 10:38:32 +0200 | [diff] [blame] | 712 | } |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 713 | } |
| 714 | |
Alexander Aring | 97fed79 | 2014-10-07 10:38:32 +0200 | [diff] [blame] | 715 | static void |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 716 | at86rf230_async_state_change(struct at86rf230_local *lp, |
| 717 | struct at86rf230_state_change *ctx, |
Alexander Aring | 97fed79 | 2014-10-07 10:38:32 +0200 | [diff] [blame] | 718 | const u8 state, void (*complete)(void *context), |
| 719 | const bool irq_enable) |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 720 | { |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 721 | /* Initialization for the state change context */ |
| 722 | ctx->to_state = state; |
| 723 | ctx->complete = complete; |
Alexander Aring | 97fed79 | 2014-10-07 10:38:32 +0200 | [diff] [blame] | 724 | ctx->irq_enable = irq_enable; |
| 725 | at86rf230_async_read_reg(lp, RG_TRX_STATUS, ctx, |
| 726 | at86rf230_async_state_change_start, |
| 727 | irq_enable); |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 728 | } |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 729 | |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 730 | static void |
Alexander Aring | 2e0571c | 2014-07-03 00:20:51 +0200 | [diff] [blame] | 731 | at86rf230_sync_state_change_complete(void *context) |
| 732 | { |
| 733 | struct at86rf230_state_change *ctx = context; |
| 734 | struct at86rf230_local *lp = ctx->lp; |
| 735 | |
| 736 | complete(&lp->state_complete); |
| 737 | } |
| 738 | |
| 739 | /* This function do a sync framework above the async state change. |
| 740 | * Some callbacks of the IEEE 802.15.4 driver interface need to be |
| 741 | * handled synchronously. |
| 742 | */ |
| 743 | static int |
| 744 | at86rf230_sync_state_change(struct at86rf230_local *lp, unsigned int state) |
| 745 | { |
Nicholas Mc Guire | 3e544ef | 2015-02-14 23:57:48 +0100 | [diff] [blame] | 746 | unsigned long rc; |
Alexander Aring | 2e0571c | 2014-07-03 00:20:51 +0200 | [diff] [blame] | 747 | |
Alexander Aring | 97fed79 | 2014-10-07 10:38:32 +0200 | [diff] [blame] | 748 | at86rf230_async_state_change(lp, &lp->state, state, |
| 749 | at86rf230_sync_state_change_complete, |
| 750 | false); |
Alexander Aring | 2e0571c | 2014-07-03 00:20:51 +0200 | [diff] [blame] | 751 | |
| 752 | rc = wait_for_completion_timeout(&lp->state_complete, |
| 753 | msecs_to_jiffies(100)); |
Alexander Aring | d06c219 | 2014-10-07 10:38:26 +0200 | [diff] [blame] | 754 | if (!rc) { |
| 755 | at86rf230_async_error(lp, &lp->state, -ETIMEDOUT); |
Alexander Aring | 2e0571c | 2014-07-03 00:20:51 +0200 | [diff] [blame] | 756 | return -ETIMEDOUT; |
Alexander Aring | d06c219 | 2014-10-07 10:38:26 +0200 | [diff] [blame] | 757 | } |
Alexander Aring | 2e0571c | 2014-07-03 00:20:51 +0200 | [diff] [blame] | 758 | |
| 759 | return 0; |
| 760 | } |
| 761 | |
| 762 | static void |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 763 | at86rf230_tx_complete(void *context) |
| 764 | { |
| 765 | struct at86rf230_state_change *ctx = context; |
| 766 | struct at86rf230_local *lp = ctx->lp; |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 767 | |
Alexander Aring | cca990c | 2015-03-01 21:55:31 +0100 | [diff] [blame] | 768 | enable_irq(ctx->irq); |
Alexander Aring | 955aee8 | 2014-10-26 09:37:15 +0100 | [diff] [blame] | 769 | |
Alexander Aring | ef5428a | 2015-03-01 21:55:29 +0100 | [diff] [blame] | 770 | ieee802154_xmit_complete(lp->hw, lp->tx_skb, !lp->tx_aret); |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 771 | } |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 772 | |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 773 | static void |
| 774 | at86rf230_tx_on(void *context) |
| 775 | { |
| 776 | struct at86rf230_state_change *ctx = context; |
| 777 | struct at86rf230_local *lp = ctx->lp; |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 778 | |
Alexander Aring | 31fa743 | 2015-03-01 21:55:32 +0100 | [diff] [blame] | 779 | at86rf230_async_state_change(lp, ctx, STATE_RX_AACK_ON, |
Alexander Aring | 97fed79 | 2014-10-07 10:38:32 +0200 | [diff] [blame] | 780 | at86rf230_tx_complete, true); |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 781 | } |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 782 | |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 783 | static void |
| 784 | at86rf230_tx_trac_error(void *context) |
| 785 | { |
| 786 | struct at86rf230_state_change *ctx = context; |
| 787 | struct at86rf230_local *lp = ctx->lp; |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 788 | |
Alexander Aring | 97fed79 | 2014-10-07 10:38:32 +0200 | [diff] [blame] | 789 | at86rf230_async_state_change(lp, ctx, STATE_TX_ON, |
| 790 | at86rf230_tx_on, true); |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 791 | } |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 792 | |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 793 | static void |
| 794 | at86rf230_tx_trac_check(void *context) |
| 795 | { |
| 796 | struct at86rf230_state_change *ctx = context; |
| 797 | struct at86rf230_local *lp = ctx->lp; |
| 798 | const u8 *buf = ctx->buf; |
| 799 | const u8 trac = (buf[1] & 0xe0) >> 5; |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 800 | |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 801 | /* If trac status is different than zero we need to do a state change |
| 802 | * to STATE_FORCE_TRX_OFF then STATE_TX_ON to recover the transceiver |
| 803 | * state to TX_ON. |
| 804 | */ |
Alexander Aring | c8c7e3d | 2014-12-19 10:36:50 +0100 | [diff] [blame] | 805 | if (trac) |
Alexander Aring | 97fed79 | 2014-10-07 10:38:32 +0200 | [diff] [blame] | 806 | at86rf230_async_state_change(lp, ctx, STATE_FORCE_TRX_OFF, |
| 807 | at86rf230_tx_trac_error, true); |
Alexander Aring | c8c7e3d | 2014-12-19 10:36:50 +0100 | [diff] [blame] | 808 | else |
| 809 | at86rf230_tx_on(context); |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 810 | } |
| 811 | |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 812 | static void |
| 813 | at86rf230_tx_trac_status(void *context) |
| 814 | { |
| 815 | struct at86rf230_state_change *ctx = context; |
| 816 | struct at86rf230_local *lp = ctx->lp; |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 817 | |
Alexander Aring | 97fed79 | 2014-10-07 10:38:32 +0200 | [diff] [blame] | 818 | at86rf230_async_read_reg(lp, RG_TRX_STATE, ctx, |
| 819 | at86rf230_tx_trac_check, true); |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 820 | } |
| 821 | |
| 822 | static void |
Alexander Aring | 74de4c8 | 2015-03-01 21:55:30 +0100 | [diff] [blame] | 823 | at86rf230_rx_read_frame_complete(void *context) |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 824 | { |
Alexander Aring | 74de4c8 | 2015-03-01 21:55:30 +0100 | [diff] [blame] | 825 | struct at86rf230_state_change *ctx = context; |
| 826 | struct at86rf230_local *lp = ctx->lp; |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 827 | u8 rx_local_buf[AT86RF2XX_MAX_BUF]; |
Alexander Aring | 31fa743 | 2015-03-01 21:55:32 +0100 | [diff] [blame] | 828 | const u8 *buf = ctx->buf; |
Alexander Aring | 74de4c8 | 2015-03-01 21:55:30 +0100 | [diff] [blame] | 829 | struct sk_buff *skb; |
| 830 | u8 len, lqi; |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 831 | |
Alexander Aring | 74de4c8 | 2015-03-01 21:55:30 +0100 | [diff] [blame] | 832 | len = buf[1]; |
| 833 | if (!ieee802154_is_valid_psdu_len(len)) { |
| 834 | dev_vdbg(&lp->spi->dev, "corrupted frame received\n"); |
| 835 | len = IEEE802154_MTU; |
| 836 | } |
| 837 | lqi = buf[2 + len]; |
| 838 | |
| 839 | memcpy(rx_local_buf, buf + 2, len); |
Alexander Aring | 263be33 | 2015-03-01 21:55:33 +0100 | [diff] [blame] | 840 | ctx->trx.len = 2; |
Alexander Aring | cca990c | 2015-03-01 21:55:31 +0100 | [diff] [blame] | 841 | enable_irq(ctx->irq); |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 842 | |
Alexander Aring | 61a2281 | 2014-10-27 17:13:29 +0100 | [diff] [blame] | 843 | skb = dev_alloc_skb(IEEE802154_MTU); |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 844 | if (!skb) { |
| 845 | dev_vdbg(&lp->spi->dev, "failed to allocate sk_buff\n"); |
| 846 | return; |
| 847 | } |
| 848 | |
| 849 | memcpy(skb_put(skb, len), rx_local_buf, len); |
Alexander Aring | b89c334 | 2014-10-27 17:13:42 +0100 | [diff] [blame] | 850 | ieee802154_rx_irqsafe(lp->hw, skb, lqi); |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | static void |
Alexander Aring | cca990c | 2015-03-01 21:55:31 +0100 | [diff] [blame] | 854 | at86rf230_rx_read_frame(void *context) |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 855 | { |
Alexander Aring | cca990c | 2015-03-01 21:55:31 +0100 | [diff] [blame] | 856 | struct at86rf230_state_change *ctx = context; |
| 857 | struct at86rf230_local *lp = ctx->lp; |
Alexander Aring | 31fa743 | 2015-03-01 21:55:32 +0100 | [diff] [blame] | 858 | u8 *buf = ctx->buf; |
Alexander Aring | 97fed79 | 2014-10-07 10:38:32 +0200 | [diff] [blame] | 859 | int rc; |
| 860 | |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 861 | buf[0] = CMD_FB; |
Alexander Aring | 31fa743 | 2015-03-01 21:55:32 +0100 | [diff] [blame] | 862 | ctx->trx.len = AT86RF2XX_MAX_BUF; |
| 863 | ctx->msg.complete = at86rf230_rx_read_frame_complete; |
| 864 | rc = spi_async(lp->spi, &ctx->msg); |
Alexander Aring | 97fed79 | 2014-10-07 10:38:32 +0200 | [diff] [blame] | 865 | if (rc) { |
Alexander Aring | 263be33 | 2015-03-01 21:55:33 +0100 | [diff] [blame] | 866 | ctx->trx.len = 2; |
Alexander Aring | cca990c | 2015-03-01 21:55:31 +0100 | [diff] [blame] | 867 | enable_irq(ctx->irq); |
Alexander Aring | 31fa743 | 2015-03-01 21:55:32 +0100 | [diff] [blame] | 868 | at86rf230_async_error(lp, ctx, rc); |
Alexander Aring | 97fed79 | 2014-10-07 10:38:32 +0200 | [diff] [blame] | 869 | } |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 870 | } |
| 871 | |
| 872 | static void |
| 873 | at86rf230_rx_trac_check(void *context) |
| 874 | { |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 875 | /* Possible check on trac status here. This could be useful to make |
| 876 | * some stats why receive is failed. Not used at the moment, but it's |
| 877 | * maybe timing relevant. Datasheet doesn't say anything about this. |
| 878 | * The programming guide say do it so. |
| 879 | */ |
| 880 | |
Alexander Aring | cca990c | 2015-03-01 21:55:31 +0100 | [diff] [blame] | 881 | at86rf230_rx_read_frame(context); |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 882 | } |
| 883 | |
Alexander Aring | 97fed79 | 2014-10-07 10:38:32 +0200 | [diff] [blame] | 884 | static void |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 885 | at86rf230_irq_trx_end(struct at86rf230_local *lp) |
| 886 | { |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 887 | if (lp->is_tx) { |
| 888 | lp->is_tx = 0; |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 889 | |
| 890 | if (lp->tx_aret) |
Alexander Aring | 97fed79 | 2014-10-07 10:38:32 +0200 | [diff] [blame] | 891 | at86rf230_async_state_change(lp, &lp->irq, |
| 892 | STATE_FORCE_TX_ON, |
| 893 | at86rf230_tx_trac_status, |
| 894 | true); |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 895 | else |
Alexander Aring | 97fed79 | 2014-10-07 10:38:32 +0200 | [diff] [blame] | 896 | at86rf230_async_state_change(lp, &lp->irq, |
| 897 | STATE_RX_AACK_ON, |
| 898 | at86rf230_tx_complete, |
| 899 | true); |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 900 | } else { |
Alexander Aring | 97fed79 | 2014-10-07 10:38:32 +0200 | [diff] [blame] | 901 | at86rf230_async_read_reg(lp, RG_TRX_STATE, &lp->irq, |
| 902 | at86rf230_rx_trac_check, true); |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 903 | } |
| 904 | } |
| 905 | |
| 906 | static void |
| 907 | at86rf230_irq_status(void *context) |
| 908 | { |
| 909 | struct at86rf230_state_change *ctx = context; |
| 910 | struct at86rf230_local *lp = ctx->lp; |
Alexander Aring | 31fa743 | 2015-03-01 21:55:32 +0100 | [diff] [blame] | 911 | const u8 *buf = ctx->buf; |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 912 | const u8 irq = buf[1]; |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 913 | |
| 914 | if (irq & IRQ_TRX_END) { |
Alexander Aring | 97fed79 | 2014-10-07 10:38:32 +0200 | [diff] [blame] | 915 | at86rf230_irq_trx_end(lp); |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 916 | } else { |
Alexander Aring | cca990c | 2015-03-01 21:55:31 +0100 | [diff] [blame] | 917 | enable_irq(ctx->irq); |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 918 | dev_err(&lp->spi->dev, "not supported irq %02x received\n", |
| 919 | irq); |
| 920 | } |
| 921 | } |
| 922 | |
| 923 | static irqreturn_t at86rf230_isr(int irq, void *data) |
| 924 | { |
| 925 | struct at86rf230_local *lp = data; |
| 926 | struct at86rf230_state_change *ctx = &lp->irq; |
| 927 | u8 *buf = ctx->buf; |
| 928 | int rc; |
| 929 | |
Alexander Aring | 9056636 | 2014-10-07 10:38:29 +0200 | [diff] [blame] | 930 | disable_irq_nosync(irq); |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 931 | |
| 932 | buf[0] = (RG_IRQ_STATUS & CMD_REG_MASK) | CMD_REG; |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 933 | ctx->msg.complete = at86rf230_irq_status; |
| 934 | rc = spi_async(lp->spi, &ctx->msg); |
| 935 | if (rc) { |
Alexander Aring | e931021 | 2014-10-07 10:38:30 +0200 | [diff] [blame] | 936 | enable_irq(irq); |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 937 | at86rf230_async_error(lp, ctx, rc); |
| 938 | return IRQ_NONE; |
| 939 | } |
| 940 | |
| 941 | return IRQ_HANDLED; |
| 942 | } |
| 943 | |
| 944 | static void |
| 945 | at86rf230_write_frame_complete(void *context) |
| 946 | { |
| 947 | struct at86rf230_state_change *ctx = context; |
| 948 | struct at86rf230_local *lp = ctx->lp; |
| 949 | u8 *buf = ctx->buf; |
| 950 | int rc; |
| 951 | |
| 952 | buf[0] = (RG_TRX_STATE & CMD_REG_MASK) | CMD_REG | CMD_WRITE; |
| 953 | buf[1] = STATE_BUSY_TX; |
| 954 | ctx->trx.len = 2; |
| 955 | ctx->msg.complete = NULL; |
| 956 | rc = spi_async(lp->spi, &ctx->msg); |
| 957 | if (rc) |
| 958 | at86rf230_async_error(lp, ctx, rc); |
| 959 | } |
| 960 | |
| 961 | static void |
| 962 | at86rf230_write_frame(void *context) |
| 963 | { |
| 964 | struct at86rf230_state_change *ctx = context; |
| 965 | struct at86rf230_local *lp = ctx->lp; |
| 966 | struct sk_buff *skb = lp->tx_skb; |
Alexander Aring | 31fa743 | 2015-03-01 21:55:32 +0100 | [diff] [blame] | 967 | u8 *buf = ctx->buf; |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 968 | int rc; |
| 969 | |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 970 | lp->is_tx = 1; |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 971 | |
| 972 | buf[0] = CMD_FB | CMD_WRITE; |
| 973 | buf[1] = skb->len + 2; |
| 974 | memcpy(buf + 2, skb->data, skb->len); |
Alexander Aring | 31fa743 | 2015-03-01 21:55:32 +0100 | [diff] [blame] | 975 | ctx->trx.len = skb->len + 2; |
| 976 | ctx->msg.complete = at86rf230_write_frame_complete; |
| 977 | rc = spi_async(lp->spi, &ctx->msg); |
Alexander Aring | 263be33 | 2015-03-01 21:55:33 +0100 | [diff] [blame] | 978 | if (rc) { |
| 979 | ctx->trx.len = 2; |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 980 | at86rf230_async_error(lp, ctx, rc); |
Alexander Aring | 263be33 | 2015-03-01 21:55:33 +0100 | [diff] [blame] | 981 | } |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 982 | } |
| 983 | |
| 984 | static void |
| 985 | at86rf230_xmit_tx_on(void *context) |
| 986 | { |
| 987 | struct at86rf230_state_change *ctx = context; |
| 988 | struct at86rf230_local *lp = ctx->lp; |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 989 | |
Alexander Aring | 97fed79 | 2014-10-07 10:38:32 +0200 | [diff] [blame] | 990 | at86rf230_async_state_change(lp, ctx, STATE_TX_ARET_ON, |
| 991 | at86rf230_write_frame, false); |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 992 | } |
| 993 | |
Alexander Aring | dce481e | 2015-03-09 13:56:11 +0100 | [diff] [blame] | 994 | static void |
| 995 | at86rf230_xmit_start(void *context) |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 996 | { |
Alexander Aring | dce481e | 2015-03-09 13:56:11 +0100 | [diff] [blame] | 997 | struct at86rf230_state_change *ctx = context; |
| 998 | struct at86rf230_local *lp = ctx->lp; |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 999 | |
| 1000 | /* In ARET mode we need to go into STATE_TX_ARET_ON after we |
| 1001 | * are in STATE_TX_ON. The pfad differs here, so we change |
| 1002 | * the complete handler. |
| 1003 | */ |
| 1004 | if (lp->tx_aret) |
Alexander Aring | dce481e | 2015-03-09 13:56:11 +0100 | [diff] [blame] | 1005 | at86rf230_async_state_change(lp, ctx, STATE_TX_ON, |
| 1006 | at86rf230_xmit_tx_on, false); |
| 1007 | else |
| 1008 | at86rf230_async_state_change(lp, ctx, STATE_TX_ON, |
| 1009 | at86rf230_write_frame, false); |
| 1010 | } |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 1011 | |
Alexander Aring | dce481e | 2015-03-09 13:56:11 +0100 | [diff] [blame] | 1012 | static int |
| 1013 | at86rf230_xmit(struct ieee802154_hw *hw, struct sk_buff *skb) |
| 1014 | { |
| 1015 | struct at86rf230_local *lp = hw->priv; |
| 1016 | struct at86rf230_state_change *ctx = &lp->tx; |
| 1017 | |
| 1018 | lp->tx_skb = skb; |
Alexander Aring | ba6d223 | 2015-03-01 21:55:28 +0100 | [diff] [blame] | 1019 | lp->tx_retry = 0; |
Alexander Aring | dce481e | 2015-03-09 13:56:11 +0100 | [diff] [blame] | 1020 | |
| 1021 | /* After 5 minutes in PLL and the same frequency we run again the |
| 1022 | * calibration loops which is recommended by at86rf2xx datasheets. |
| 1023 | * |
| 1024 | * The calibration is initiate by a state change from TRX_OFF |
| 1025 | * to TX_ON, the lp->cal_timeout should be reinit by state_delay |
| 1026 | * function then to start in the next 5 minutes. |
| 1027 | */ |
| 1028 | if (time_is_before_jiffies(lp->cal_timeout)) |
| 1029 | at86rf230_async_state_change(lp, ctx, STATE_TRX_OFF, |
| 1030 | at86rf230_xmit_start, false); |
| 1031 | else |
| 1032 | at86rf230_xmit_start(ctx); |
Alexander Aring | 97fed79 | 2014-10-07 10:38:32 +0200 | [diff] [blame] | 1033 | |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 1034 | return 0; |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 1035 | } |
| 1036 | |
| 1037 | static int |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 1038 | at86rf230_ed(struct ieee802154_hw *hw, u8 *level) |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 1039 | { |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 1040 | BUG_ON(!level); |
| 1041 | *level = 0xbe; |
| 1042 | return 0; |
| 1043 | } |
| 1044 | |
| 1045 | static int |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 1046 | at86rf230_start(struct ieee802154_hw *hw) |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 1047 | { |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 1048 | return at86rf230_sync_state_change(hw->priv, STATE_RX_AACK_ON); |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 1049 | } |
| 1050 | |
| 1051 | static void |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 1052 | at86rf230_stop(struct ieee802154_hw *hw) |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 1053 | { |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 1054 | at86rf230_sync_state_change(hw->priv, STATE_FORCE_TRX_OFF); |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 1055 | } |
| 1056 | |
| 1057 | static int |
Alexander Aring | e37d2ec | 2014-10-28 18:21:19 +0100 | [diff] [blame] | 1058 | at86rf23x_set_channel(struct at86rf230_local *lp, u8 page, u8 channel) |
Phoebe Buckheister | 8fad346 | 2014-02-17 11:34:06 +0100 | [diff] [blame] | 1059 | { |
| 1060 | return at86rf230_write_subreg(lp, SR_CHANNEL, channel); |
| 1061 | } |
| 1062 | |
| 1063 | static int |
Alexander Aring | e37d2ec | 2014-10-28 18:21:19 +0100 | [diff] [blame] | 1064 | at86rf212_set_channel(struct at86rf230_local *lp, u8 page, u8 channel) |
Phoebe Buckheister | 8fad346 | 2014-02-17 11:34:06 +0100 | [diff] [blame] | 1065 | { |
| 1066 | int rc; |
| 1067 | |
| 1068 | if (channel == 0) |
| 1069 | rc = at86rf230_write_subreg(lp, SR_SUB_MODE, 0); |
| 1070 | else |
| 1071 | rc = at86rf230_write_subreg(lp, SR_SUB_MODE, 1); |
| 1072 | if (rc < 0) |
| 1073 | return rc; |
| 1074 | |
Phoebe Buckheister | 6ca0019 | 2014-02-17 11:34:12 +0100 | [diff] [blame] | 1075 | if (page == 0) { |
Phoebe Buckheister | 643e53c | 2014-02-17 11:34:09 +0100 | [diff] [blame] | 1076 | rc = at86rf230_write_subreg(lp, SR_BPSK_QPSK, 0); |
Alexander Aring | a53d1f7 | 2014-07-03 00:20:46 +0200 | [diff] [blame] | 1077 | lp->data->rssi_base_val = -100; |
Phoebe Buckheister | 6ca0019 | 2014-02-17 11:34:12 +0100 | [diff] [blame] | 1078 | } else { |
Phoebe Buckheister | 643e53c | 2014-02-17 11:34:09 +0100 | [diff] [blame] | 1079 | rc = at86rf230_write_subreg(lp, SR_BPSK_QPSK, 1); |
Alexander Aring | a53d1f7 | 2014-07-03 00:20:46 +0200 | [diff] [blame] | 1080 | lp->data->rssi_base_val = -98; |
Phoebe Buckheister | 6ca0019 | 2014-02-17 11:34:12 +0100 | [diff] [blame] | 1081 | } |
Phoebe Buckheister | 643e53c | 2014-02-17 11:34:09 +0100 | [diff] [blame] | 1082 | if (rc < 0) |
| 1083 | return rc; |
| 1084 | |
Alexander Aring | 24ccb9f | 2014-11-12 19:51:57 +0100 | [diff] [blame] | 1085 | /* This sets the symbol_duration according frequency on the 212. |
| 1086 | * TODO move this handling while set channel and page in cfg802154. |
| 1087 | * We can do that, this timings are according 802.15.4 standard. |
| 1088 | * If we do that in cfg802154, this is a more generic calculation. |
| 1089 | * |
| 1090 | * This should also protected from ifs_timer. Means cancel timer and |
| 1091 | * init with a new value. For now, this is okay. |
| 1092 | */ |
| 1093 | if (channel == 0) { |
| 1094 | if (page == 0) { |
| 1095 | /* SUB:0 and BPSK:0 -> BPSK-20 */ |
| 1096 | lp->hw->phy->symbol_duration = 50; |
| 1097 | } else { |
| 1098 | /* SUB:1 and BPSK:0 -> BPSK-40 */ |
| 1099 | lp->hw->phy->symbol_duration = 25; |
| 1100 | } |
| 1101 | } else { |
| 1102 | if (page == 0) |
Alexander Aring | 2d6dde2 | 2014-11-17 08:20:44 +0100 | [diff] [blame] | 1103 | /* SUB:0 and BPSK:1 -> OQPSK-100/200/400 */ |
Alexander Aring | 24ccb9f | 2014-11-12 19:51:57 +0100 | [diff] [blame] | 1104 | lp->hw->phy->symbol_duration = 40; |
| 1105 | else |
Alexander Aring | 2d6dde2 | 2014-11-17 08:20:44 +0100 | [diff] [blame] | 1106 | /* SUB:1 and BPSK:1 -> OQPSK-250/500/1000 */ |
Alexander Aring | 24ccb9f | 2014-11-12 19:51:57 +0100 | [diff] [blame] | 1107 | lp->hw->phy->symbol_duration = 16; |
| 1108 | } |
| 1109 | |
| 1110 | lp->hw->phy->lifs_period = IEEE802154_LIFS_PERIOD * |
| 1111 | lp->hw->phy->symbol_duration; |
| 1112 | lp->hw->phy->sifs_period = IEEE802154_SIFS_PERIOD * |
| 1113 | lp->hw->phy->symbol_duration; |
| 1114 | |
Phoebe Buckheister | 8fad346 | 2014-02-17 11:34:06 +0100 | [diff] [blame] | 1115 | return at86rf230_write_subreg(lp, SR_CHANNEL, channel); |
| 1116 | } |
| 1117 | |
| 1118 | static int |
Alexander Aring | e37d2ec | 2014-10-28 18:21:19 +0100 | [diff] [blame] | 1119 | at86rf230_channel(struct ieee802154_hw *hw, u8 page, u8 channel) |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 1120 | { |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 1121 | struct at86rf230_local *lp = hw->priv; |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 1122 | int rc; |
| 1123 | |
Alexander Aring | a53d1f7 | 2014-07-03 00:20:46 +0200 | [diff] [blame] | 1124 | rc = lp->data->set_channel(lp, page, channel); |
Alexander Aring | 984e0c6 | 2014-07-03 00:20:53 +0200 | [diff] [blame] | 1125 | /* Wait for PLL */ |
| 1126 | usleep_range(lp->data->t_channel_switch, |
| 1127 | lp->data->t_channel_switch + 10); |
Alexander Aring | dce481e | 2015-03-09 13:56:11 +0100 | [diff] [blame] | 1128 | |
| 1129 | lp->cal_timeout = jiffies + AT86RF2XX_CAL_LOOP_TIMEOUT; |
Alexander Aring | 820bd66 | 2014-11-12 03:36:56 +0100 | [diff] [blame] | 1130 | return rc; |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 1131 | } |
| 1132 | |
| 1133 | static int |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 1134 | at86rf230_set_hw_addr_filt(struct ieee802154_hw *hw, |
stefan@datenfreihafen.org | 1486774 | 2013-03-26 12:41:30 +0000 | [diff] [blame] | 1135 | struct ieee802154_hw_addr_filt *filt, |
| 1136 | unsigned long changed) |
| 1137 | { |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 1138 | struct at86rf230_local *lp = hw->priv; |
stefan@datenfreihafen.org | 1486774 | 2013-03-26 12:41:30 +0000 | [diff] [blame] | 1139 | |
Alexander Aring | 57205c1 | 2014-10-25 05:25:09 +0200 | [diff] [blame] | 1140 | if (changed & IEEE802154_AFILT_SADDR_CHANGED) { |
Phoebe Buckheister | b70ab2e | 2014-03-14 21:23:59 +0100 | [diff] [blame] | 1141 | u16 addr = le16_to_cpu(filt->short_addr); |
| 1142 | |
stefan@datenfreihafen.org | 1486774 | 2013-03-26 12:41:30 +0000 | [diff] [blame] | 1143 | dev_vdbg(&lp->spi->dev, |
Stefan Schmidt | e80fb5e | 2014-12-12 12:45:29 +0100 | [diff] [blame] | 1144 | "at86rf230_set_hw_addr_filt called for saddr\n"); |
Phoebe Buckheister | b70ab2e | 2014-03-14 21:23:59 +0100 | [diff] [blame] | 1145 | __at86rf230_write(lp, RG_SHORT_ADDR_0, addr); |
| 1146 | __at86rf230_write(lp, RG_SHORT_ADDR_1, addr >> 8); |
stefan@datenfreihafen.org | 1486774 | 2013-03-26 12:41:30 +0000 | [diff] [blame] | 1147 | } |
| 1148 | |
Alexander Aring | 57205c1 | 2014-10-25 05:25:09 +0200 | [diff] [blame] | 1149 | if (changed & IEEE802154_AFILT_PANID_CHANGED) { |
Phoebe Buckheister | b70ab2e | 2014-03-14 21:23:59 +0100 | [diff] [blame] | 1150 | u16 pan = le16_to_cpu(filt->pan_id); |
| 1151 | |
stefan@datenfreihafen.org | 1486774 | 2013-03-26 12:41:30 +0000 | [diff] [blame] | 1152 | dev_vdbg(&lp->spi->dev, |
Stefan Schmidt | e80fb5e | 2014-12-12 12:45:29 +0100 | [diff] [blame] | 1153 | "at86rf230_set_hw_addr_filt called for pan id\n"); |
Phoebe Buckheister | b70ab2e | 2014-03-14 21:23:59 +0100 | [diff] [blame] | 1154 | __at86rf230_write(lp, RG_PAN_ID_0, pan); |
| 1155 | __at86rf230_write(lp, RG_PAN_ID_1, pan >> 8); |
stefan@datenfreihafen.org | 1486774 | 2013-03-26 12:41:30 +0000 | [diff] [blame] | 1156 | } |
| 1157 | |
Alexander Aring | 57205c1 | 2014-10-25 05:25:09 +0200 | [diff] [blame] | 1158 | if (changed & IEEE802154_AFILT_IEEEADDR_CHANGED) { |
Phoebe Buckheister | b70ab2e | 2014-03-14 21:23:59 +0100 | [diff] [blame] | 1159 | u8 i, addr[8]; |
| 1160 | |
| 1161 | memcpy(addr, &filt->ieee_addr, 8); |
stefan@datenfreihafen.org | 1486774 | 2013-03-26 12:41:30 +0000 | [diff] [blame] | 1162 | dev_vdbg(&lp->spi->dev, |
Stefan Schmidt | e80fb5e | 2014-12-12 12:45:29 +0100 | [diff] [blame] | 1163 | "at86rf230_set_hw_addr_filt called for IEEE addr\n"); |
Phoebe Buckheister | b70ab2e | 2014-03-14 21:23:59 +0100 | [diff] [blame] | 1164 | for (i = 0; i < 8; i++) |
| 1165 | __at86rf230_write(lp, RG_IEEE_ADDR_0 + i, addr[i]); |
stefan@datenfreihafen.org | 1486774 | 2013-03-26 12:41:30 +0000 | [diff] [blame] | 1166 | } |
| 1167 | |
Alexander Aring | 57205c1 | 2014-10-25 05:25:09 +0200 | [diff] [blame] | 1168 | if (changed & IEEE802154_AFILT_PANC_CHANGED) { |
stefan@datenfreihafen.org | 1486774 | 2013-03-26 12:41:30 +0000 | [diff] [blame] | 1169 | dev_vdbg(&lp->spi->dev, |
Stefan Schmidt | e80fb5e | 2014-12-12 12:45:29 +0100 | [diff] [blame] | 1170 | "at86rf230_set_hw_addr_filt called for panc change\n"); |
stefan@datenfreihafen.org | 1486774 | 2013-03-26 12:41:30 +0000 | [diff] [blame] | 1171 | if (filt->pan_coord) |
| 1172 | at86rf230_write_subreg(lp, SR_AACK_I_AM_COORD, 1); |
| 1173 | else |
| 1174 | at86rf230_write_subreg(lp, SR_AACK_I_AM_COORD, 0); |
| 1175 | } |
| 1176 | |
| 1177 | return 0; |
| 1178 | } |
| 1179 | |
Phoebe Buckheister | 9b2777d | 2014-02-17 11:34:08 +0100 | [diff] [blame] | 1180 | static int |
Varka Bhadram | 23310f6 | 2015-04-09 13:55:11 +0530 | [diff] [blame] | 1181 | at86rf230_set_txpower(struct ieee802154_hw *hw, s8 db) |
Phoebe Buckheister | 9b2777d | 2014-02-17 11:34:08 +0100 | [diff] [blame] | 1182 | { |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 1183 | struct at86rf230_local *lp = hw->priv; |
Phoebe Buckheister | 9b2777d | 2014-02-17 11:34:08 +0100 | [diff] [blame] | 1184 | |
| 1185 | /* typical maximum output is 5dBm with RG_PHY_TX_PWR 0x60, lower five |
| 1186 | * bits decrease power in 1dB steps. 0x60 represents extra PA gain of |
| 1187 | * 0dB. |
| 1188 | * thus, supported values for db range from -26 to 5, for 31dB of |
| 1189 | * reduction to 0dB of reduction. |
| 1190 | */ |
| 1191 | if (db > 5 || db < -26) |
| 1192 | return -EINVAL; |
| 1193 | |
| 1194 | db = -(db - 5); |
| 1195 | |
Jean Sacren | 677676c | 2014-03-01 15:54:36 -0700 | [diff] [blame] | 1196 | return __at86rf230_write(lp, RG_PHY_TX_PWR, 0x60 | db); |
Phoebe Buckheister | 9b2777d | 2014-02-17 11:34:08 +0100 | [diff] [blame] | 1197 | } |
| 1198 | |
Phoebe Buckheister | 84dda3c | 2014-02-17 11:34:10 +0100 | [diff] [blame] | 1199 | static int |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 1200 | at86rf230_set_lbt(struct ieee802154_hw *hw, bool on) |
Phoebe Buckheister | 84dda3c | 2014-02-17 11:34:10 +0100 | [diff] [blame] | 1201 | { |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 1202 | struct at86rf230_local *lp = hw->priv; |
Phoebe Buckheister | 84dda3c | 2014-02-17 11:34:10 +0100 | [diff] [blame] | 1203 | |
| 1204 | return at86rf230_write_subreg(lp, SR_CSMA_LBT_MODE, on); |
| 1205 | } |
| 1206 | |
Phoebe Buckheister | ba08fea | 2014-02-17 11:34:11 +0100 | [diff] [blame] | 1207 | static int |
Alexander Aring | 7fe9a38 | 2014-12-10 15:33:12 +0100 | [diff] [blame] | 1208 | at86rf230_set_cca_mode(struct ieee802154_hw *hw, |
| 1209 | const struct wpan_phy_cca *cca) |
Phoebe Buckheister | ba08fea | 2014-02-17 11:34:11 +0100 | [diff] [blame] | 1210 | { |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 1211 | struct at86rf230_local *lp = hw->priv; |
Alexander Aring | 7fe9a38 | 2014-12-10 15:33:12 +0100 | [diff] [blame] | 1212 | u8 val; |
Phoebe Buckheister | ba08fea | 2014-02-17 11:34:11 +0100 | [diff] [blame] | 1213 | |
Alexander Aring | 7fe9a38 | 2014-12-10 15:33:12 +0100 | [diff] [blame] | 1214 | /* mapping 802.15.4 to driver spec */ |
| 1215 | switch (cca->mode) { |
| 1216 | case NL802154_CCA_ENERGY: |
| 1217 | val = 1; |
| 1218 | break; |
| 1219 | case NL802154_CCA_CARRIER: |
| 1220 | val = 2; |
| 1221 | break; |
| 1222 | case NL802154_CCA_ENERGY_CARRIER: |
| 1223 | switch (cca->opt) { |
| 1224 | case NL802154_CCA_OPT_ENERGY_CARRIER_AND: |
| 1225 | val = 3; |
| 1226 | break; |
| 1227 | case NL802154_CCA_OPT_ENERGY_CARRIER_OR: |
| 1228 | val = 0; |
| 1229 | break; |
| 1230 | default: |
| 1231 | return -EINVAL; |
| 1232 | } |
| 1233 | break; |
| 1234 | default: |
| 1235 | return -EINVAL; |
| 1236 | } |
| 1237 | |
| 1238 | return at86rf230_write_subreg(lp, SR_CCA_MODE, val); |
Phoebe Buckheister | ba08fea | 2014-02-17 11:34:11 +0100 | [diff] [blame] | 1239 | } |
| 1240 | |
Phoebe Buckheister | 6ca0019 | 2014-02-17 11:34:12 +0100 | [diff] [blame] | 1241 | static int |
Alexander Aring | a7d7eda | 2014-07-03 00:20:47 +0200 | [diff] [blame] | 1242 | at86rf212_get_desens_steps(struct at86rf230_local *lp, s32 level) |
| 1243 | { |
| 1244 | return (level - lp->data->rssi_base_val) * 100 / 207; |
| 1245 | } |
| 1246 | |
| 1247 | static int |
| 1248 | at86rf23x_get_desens_steps(struct at86rf230_local *lp, s32 level) |
| 1249 | { |
| 1250 | return (level - lp->data->rssi_base_val) / 2; |
| 1251 | } |
| 1252 | |
| 1253 | static int |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 1254 | at86rf230_set_cca_ed_level(struct ieee802154_hw *hw, s32 level) |
Phoebe Buckheister | 6ca0019 | 2014-02-17 11:34:12 +0100 | [diff] [blame] | 1255 | { |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 1256 | struct at86rf230_local *lp = hw->priv; |
Phoebe Buckheister | 6ca0019 | 2014-02-17 11:34:12 +0100 | [diff] [blame] | 1257 | |
Alexander Aring | a53d1f7 | 2014-07-03 00:20:46 +0200 | [diff] [blame] | 1258 | if (level < lp->data->rssi_base_val || level > 30) |
Phoebe Buckheister | 6ca0019 | 2014-02-17 11:34:12 +0100 | [diff] [blame] | 1259 | return -EINVAL; |
| 1260 | |
Alexander Aring | a7d7eda | 2014-07-03 00:20:47 +0200 | [diff] [blame] | 1261 | return at86rf230_write_subreg(lp, SR_CCA_ED_THRES, |
| 1262 | lp->data->get_desense_steps(lp, level)); |
Phoebe Buckheister | 6ca0019 | 2014-02-17 11:34:12 +0100 | [diff] [blame] | 1263 | } |
| 1264 | |
Phoebe Buckheister | f2fdd67 | 2014-02-17 11:34:15 +0100 | [diff] [blame] | 1265 | static int |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 1266 | at86rf230_set_csma_params(struct ieee802154_hw *hw, u8 min_be, u8 max_be, |
Phoebe Buckheister | f2fdd67 | 2014-02-17 11:34:15 +0100 | [diff] [blame] | 1267 | u8 retries) |
| 1268 | { |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 1269 | struct at86rf230_local *lp = hw->priv; |
Phoebe Buckheister | f2fdd67 | 2014-02-17 11:34:15 +0100 | [diff] [blame] | 1270 | int rc; |
| 1271 | |
Phoebe Buckheister | f2fdd67 | 2014-02-17 11:34:15 +0100 | [diff] [blame] | 1272 | rc = at86rf230_write_subreg(lp, SR_MIN_BE, min_be); |
| 1273 | if (rc) |
| 1274 | return rc; |
| 1275 | |
| 1276 | rc = at86rf230_write_subreg(lp, SR_MAX_BE, max_be); |
| 1277 | if (rc) |
| 1278 | return rc; |
| 1279 | |
Alexander Aring | 39d7f32 | 2014-04-05 13:49:26 +0200 | [diff] [blame] | 1280 | return at86rf230_write_subreg(lp, SR_MAX_CSMA_RETRIES, retries); |
Phoebe Buckheister | f2fdd67 | 2014-02-17 11:34:15 +0100 | [diff] [blame] | 1281 | } |
| 1282 | |
| 1283 | static int |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 1284 | at86rf230_set_frame_retries(struct ieee802154_hw *hw, s8 retries) |
Phoebe Buckheister | f2fdd67 | 2014-02-17 11:34:15 +0100 | [diff] [blame] | 1285 | { |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 1286 | struct at86rf230_local *lp = hw->priv; |
Phoebe Buckheister | f2fdd67 | 2014-02-17 11:34:15 +0100 | [diff] [blame] | 1287 | int rc = 0; |
| 1288 | |
Phoebe Buckheister | f2fdd67 | 2014-02-17 11:34:15 +0100 | [diff] [blame] | 1289 | lp->tx_aret = retries >= 0; |
Alexander Aring | 850f43a | 2014-10-07 10:38:27 +0200 | [diff] [blame] | 1290 | lp->max_frame_retries = retries; |
Phoebe Buckheister | f2fdd67 | 2014-02-17 11:34:15 +0100 | [diff] [blame] | 1291 | |
| 1292 | if (retries >= 0) |
| 1293 | rc = at86rf230_write_subreg(lp, SR_MAX_FRAME_RETRIES, retries); |
| 1294 | |
| 1295 | return rc; |
| 1296 | } |
| 1297 | |
Alexander Aring | 92f45f5 | 2014-10-29 21:34:33 +0100 | [diff] [blame] | 1298 | static int |
| 1299 | at86rf230_set_promiscuous_mode(struct ieee802154_hw *hw, const bool on) |
| 1300 | { |
| 1301 | struct at86rf230_local *lp = hw->priv; |
| 1302 | int rc; |
| 1303 | |
| 1304 | if (on) { |
| 1305 | rc = at86rf230_write_subreg(lp, SR_AACK_DIS_ACK, 1); |
| 1306 | if (rc < 0) |
| 1307 | return rc; |
| 1308 | |
| 1309 | rc = at86rf230_write_subreg(lp, SR_AACK_PROM_MODE, 1); |
| 1310 | if (rc < 0) |
| 1311 | return rc; |
| 1312 | } else { |
| 1313 | rc = at86rf230_write_subreg(lp, SR_AACK_PROM_MODE, 0); |
| 1314 | if (rc < 0) |
| 1315 | return rc; |
| 1316 | |
| 1317 | rc = at86rf230_write_subreg(lp, SR_AACK_DIS_ACK, 0); |
| 1318 | if (rc < 0) |
| 1319 | return rc; |
| 1320 | } |
| 1321 | |
| 1322 | return 0; |
| 1323 | } |
| 1324 | |
Alexander Aring | 1630186 | 2014-10-28 18:21:18 +0100 | [diff] [blame] | 1325 | static const struct ieee802154_ops at86rf230_ops = { |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 1326 | .owner = THIS_MODULE, |
Alexander Aring | 955aee8 | 2014-10-26 09:37:15 +0100 | [diff] [blame] | 1327 | .xmit_async = at86rf230_xmit, |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 1328 | .ed = at86rf230_ed, |
| 1329 | .set_channel = at86rf230_channel, |
| 1330 | .start = at86rf230_start, |
| 1331 | .stop = at86rf230_stop, |
stefan@datenfreihafen.org | 1486774 | 2013-03-26 12:41:30 +0000 | [diff] [blame] | 1332 | .set_hw_addr_filt = at86rf230_set_hw_addr_filt, |
Alexander Aring | 640985e | 2014-07-03 00:20:43 +0200 | [diff] [blame] | 1333 | .set_txpower = at86rf230_set_txpower, |
| 1334 | .set_lbt = at86rf230_set_lbt, |
| 1335 | .set_cca_mode = at86rf230_set_cca_mode, |
| 1336 | .set_cca_ed_level = at86rf230_set_cca_ed_level, |
| 1337 | .set_csma_params = at86rf230_set_csma_params, |
| 1338 | .set_frame_retries = at86rf230_set_frame_retries, |
Alexander Aring | 92f45f5 | 2014-10-29 21:34:33 +0100 | [diff] [blame] | 1339 | .set_promiscuous_mode = at86rf230_set_promiscuous_mode, |
Phoebe Buckheister | 8fad346 | 2014-02-17 11:34:06 +0100 | [diff] [blame] | 1340 | }; |
| 1341 | |
Alexander Aring | a53d1f7 | 2014-07-03 00:20:46 +0200 | [diff] [blame] | 1342 | static struct at86rf2xx_chip_data at86rf233_data = { |
Alexander Aring | 7a4ef91 | 2014-07-03 00:20:54 +0200 | [diff] [blame] | 1343 | .t_sleep_cycle = 330, |
Alexander Aring | 984e0c6 | 2014-07-03 00:20:53 +0200 | [diff] [blame] | 1344 | .t_channel_switch = 11, |
Alexander Aring | 09e536c | 2014-07-03 00:20:52 +0200 | [diff] [blame] | 1345 | .t_reset_to_off = 26, |
Alexander Aring | 2e0571c | 2014-07-03 00:20:51 +0200 | [diff] [blame] | 1346 | .t_off_to_aack = 80, |
| 1347 | .t_off_to_tx_on = 80, |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 1348 | .t_frame = 4096, |
| 1349 | .t_p_ack = 545, |
Alexander Aring | a53d1f7 | 2014-07-03 00:20:46 +0200 | [diff] [blame] | 1350 | .rssi_base_val = -91, |
| 1351 | .set_channel = at86rf23x_set_channel, |
Alexander Aring | a7d7eda | 2014-07-03 00:20:47 +0200 | [diff] [blame] | 1352 | .get_desense_steps = at86rf23x_get_desens_steps |
Alexander Aring | a53d1f7 | 2014-07-03 00:20:46 +0200 | [diff] [blame] | 1353 | }; |
| 1354 | |
| 1355 | static struct at86rf2xx_chip_data at86rf231_data = { |
Alexander Aring | 7a4ef91 | 2014-07-03 00:20:54 +0200 | [diff] [blame] | 1356 | .t_sleep_cycle = 330, |
Alexander Aring | 984e0c6 | 2014-07-03 00:20:53 +0200 | [diff] [blame] | 1357 | .t_channel_switch = 24, |
Alexander Aring | 09e536c | 2014-07-03 00:20:52 +0200 | [diff] [blame] | 1358 | .t_reset_to_off = 37, |
Alexander Aring | 2e0571c | 2014-07-03 00:20:51 +0200 | [diff] [blame] | 1359 | .t_off_to_aack = 110, |
| 1360 | .t_off_to_tx_on = 110, |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 1361 | .t_frame = 4096, |
| 1362 | .t_p_ack = 545, |
Alexander Aring | a53d1f7 | 2014-07-03 00:20:46 +0200 | [diff] [blame] | 1363 | .rssi_base_val = -91, |
| 1364 | .set_channel = at86rf23x_set_channel, |
Alexander Aring | a7d7eda | 2014-07-03 00:20:47 +0200 | [diff] [blame] | 1365 | .get_desense_steps = at86rf23x_get_desens_steps |
Alexander Aring | a53d1f7 | 2014-07-03 00:20:46 +0200 | [diff] [blame] | 1366 | }; |
| 1367 | |
| 1368 | static struct at86rf2xx_chip_data at86rf212_data = { |
Alexander Aring | 7a4ef91 | 2014-07-03 00:20:54 +0200 | [diff] [blame] | 1369 | .t_sleep_cycle = 330, |
Alexander Aring | 984e0c6 | 2014-07-03 00:20:53 +0200 | [diff] [blame] | 1370 | .t_channel_switch = 11, |
Alexander Aring | 09e536c | 2014-07-03 00:20:52 +0200 | [diff] [blame] | 1371 | .t_reset_to_off = 26, |
Alexander Aring | 2e0571c | 2014-07-03 00:20:51 +0200 | [diff] [blame] | 1372 | .t_off_to_aack = 200, |
| 1373 | .t_off_to_tx_on = 200, |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 1374 | .t_frame = 4096, |
| 1375 | .t_p_ack = 545, |
Alexander Aring | a53d1f7 | 2014-07-03 00:20:46 +0200 | [diff] [blame] | 1376 | .rssi_base_val = -100, |
| 1377 | .set_channel = at86rf212_set_channel, |
Alexander Aring | a7d7eda | 2014-07-03 00:20:47 +0200 | [diff] [blame] | 1378 | .get_desense_steps = at86rf212_get_desens_steps |
Alexander Aring | a53d1f7 | 2014-07-03 00:20:46 +0200 | [diff] [blame] | 1379 | }; |
| 1380 | |
Alexander Aring | ccdaeb2 | 2015-02-27 09:58:26 +0100 | [diff] [blame] | 1381 | static int at86rf230_hw_init(struct at86rf230_local *lp, u8 xtal_trim) |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 1382 | { |
Alexander Aring | 1db0558 | 2014-07-03 00:20:50 +0200 | [diff] [blame] | 1383 | int rc, irq_type, irq_pol = IRQ_ACTIVE_HIGH; |
Alexander Aring | f76014f77 | 2014-07-03 00:20:44 +0200 | [diff] [blame] | 1384 | unsigned int dvdd; |
Phoebe Buckheister | f2fdd67 | 2014-02-17 11:34:15 +0100 | [diff] [blame] | 1385 | u8 csma_seed[2]; |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 1386 | |
Alexander Aring | 09e536c | 2014-07-03 00:20:52 +0200 | [diff] [blame] | 1387 | rc = at86rf230_sync_state_change(lp, STATE_FORCE_TRX_OFF); |
Phoebe Buckheister | 7dcbd22 | 2014-02-17 11:34:13 +0100 | [diff] [blame] | 1388 | if (rc) |
| 1389 | return rc; |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 1390 | |
Alexander Aring | 4af619a | 2014-04-24 19:09:05 +0200 | [diff] [blame] | 1391 | irq_type = irq_get_trigger_type(lp->spi->irq); |
Alexander Aring | c91799c | 2015-02-27 09:58:30 +0100 | [diff] [blame] | 1392 | if (irq_type == IRQ_TYPE_EDGE_RISING || |
| 1393 | irq_type == IRQ_TYPE_EDGE_FALLING) |
| 1394 | dev_warn(&lp->spi->dev, |
| 1395 | "Using edge triggered irq's are not recommended!\n"); |
Alexander Aring | 702d211 | 2015-02-27 09:58:29 +0100 | [diff] [blame] | 1396 | if (irq_type == IRQ_TYPE_EDGE_FALLING || |
| 1397 | irq_type == IRQ_TYPE_LEVEL_LOW) |
Sascha Herrmann | 43b5abe | 2013-04-14 22:33:28 +0000 | [diff] [blame] | 1398 | irq_pol = IRQ_ACTIVE_LOW; |
Sascha Herrmann | 43b5abe | 2013-04-14 22:33:28 +0000 | [diff] [blame] | 1399 | |
Alexander Aring | 18c6504 | 2014-04-24 19:09:18 +0200 | [diff] [blame] | 1400 | rc = at86rf230_write_subreg(lp, SR_IRQ_POLARITY, irq_pol); |
Sascha Herrmann | 43b5abe | 2013-04-14 22:33:28 +0000 | [diff] [blame] | 1401 | if (rc) |
| 1402 | return rc; |
| 1403 | |
Alexander Aring | 6bd2b13 | 2014-07-03 00:20:49 +0200 | [diff] [blame] | 1404 | rc = at86rf230_write_subreg(lp, SR_RX_SAFE_MODE, 1); |
| 1405 | if (rc) |
| 1406 | return rc; |
| 1407 | |
Sascha Herrmann | 057dad6 | 2013-04-14 22:33:29 +0000 | [diff] [blame] | 1408 | rc = at86rf230_write_subreg(lp, SR_IRQ_MASK, IRQ_TRX_END); |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 1409 | if (rc) |
| 1410 | return rc; |
| 1411 | |
Alexander Aring | be64f07 | 2015-02-27 09:58:28 +0100 | [diff] [blame] | 1412 | /* reset values differs in at86rf231 and at86rf233 */ |
| 1413 | rc = at86rf230_write_subreg(lp, SR_IRQ_MASK_MODE, 0); |
| 1414 | if (rc) |
| 1415 | return rc; |
| 1416 | |
Phoebe Buckheister | f2fdd67 | 2014-02-17 11:34:15 +0100 | [diff] [blame] | 1417 | get_random_bytes(csma_seed, ARRAY_SIZE(csma_seed)); |
| 1418 | rc = at86rf230_write_subreg(lp, SR_CSMA_SEED_0, csma_seed[0]); |
| 1419 | if (rc) |
| 1420 | return rc; |
| 1421 | rc = at86rf230_write_subreg(lp, SR_CSMA_SEED_1, csma_seed[1]); |
| 1422 | if (rc) |
| 1423 | return rc; |
| 1424 | |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 1425 | /* CLKM changes are applied immediately */ |
| 1426 | rc = at86rf230_write_subreg(lp, SR_CLKM_SHA_SEL, 0x00); |
| 1427 | if (rc) |
| 1428 | return rc; |
| 1429 | |
| 1430 | /* Turn CLKM Off */ |
| 1431 | rc = at86rf230_write_subreg(lp, SR_CLKM_CTRL, 0x00); |
| 1432 | if (rc) |
| 1433 | return rc; |
| 1434 | /* Wait the next SLEEP cycle */ |
Alexander Aring | 7a4ef91 | 2014-07-03 00:20:54 +0200 | [diff] [blame] | 1435 | usleep_range(lp->data->t_sleep_cycle, |
| 1436 | lp->data->t_sleep_cycle + 100); |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 1437 | |
Alexander Aring | ccdaeb2 | 2015-02-27 09:58:26 +0100 | [diff] [blame] | 1438 | /* xtal_trim value is calculated by: |
| 1439 | * CL = 0.5 * (CX + CTRIM + CPAR) |
| 1440 | * |
| 1441 | * whereas: |
| 1442 | * CL = capacitor of used crystal |
| 1443 | * CX = connected capacitors at xtal pins |
| 1444 | * CPAR = in all at86rf2xx datasheets this is a constant value 3 pF, |
| 1445 | * but this is different on each board setup. You need to fine |
| 1446 | * tuning this value via CTRIM. |
| 1447 | * CTRIM = variable capacitor setting. Resolution is 0.3 pF range is |
| 1448 | * 0 pF upto 4.5 pF. |
| 1449 | * |
| 1450 | * Examples: |
| 1451 | * atben transceiver: |
| 1452 | * |
| 1453 | * CL = 8 pF |
| 1454 | * CX = 12 pF |
| 1455 | * CPAR = 3 pF (We assume the magic constant from datasheet) |
| 1456 | * CTRIM = 0.9 pF |
| 1457 | * |
| 1458 | * (12+0.9+3)/2 = 7.95 which is nearly at 8 pF |
| 1459 | * |
| 1460 | * xtal_trim = 0x3 |
| 1461 | * |
| 1462 | * openlabs transceiver: |
| 1463 | * |
| 1464 | * CL = 16 pF |
| 1465 | * CX = 22 pF |
| 1466 | * CPAR = 3 pF (We assume the magic constant from datasheet) |
| 1467 | * CTRIM = 4.5 pF |
| 1468 | * |
| 1469 | * (22+4.5+3)/2 = 14.75 which is the nearest value to 16 pF |
| 1470 | * |
| 1471 | * xtal_trim = 0xf |
| 1472 | */ |
| 1473 | rc = at86rf230_write_subreg(lp, SR_XTAL_TRIM, xtal_trim); |
| 1474 | if (rc) |
| 1475 | return rc; |
| 1476 | |
Alexander Aring | 1cc9fc5 | 2014-04-24 19:09:17 +0200 | [diff] [blame] | 1477 | rc = at86rf230_read_subreg(lp, SR_DVDD_OK, &dvdd); |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 1478 | if (rc) |
| 1479 | return rc; |
Alexander Aring | 1cc9fc5 | 2014-04-24 19:09:17 +0200 | [diff] [blame] | 1480 | if (!dvdd) { |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 1481 | dev_err(&lp->spi->dev, "DVDD error\n"); |
| 1482 | return -EINVAL; |
| 1483 | } |
| 1484 | |
Alexander Aring | 05e3f2f | 2014-11-05 20:51:27 +0100 | [diff] [blame] | 1485 | /* Force setting slotted operation bit to 0. Sometimes the atben |
| 1486 | * sets this bit and I don't know why. We set this always force |
| 1487 | * to zero while probing. |
| 1488 | */ |
Fengguang Wu | 6cc6399 | 2014-11-06 15:31:57 +0800 | [diff] [blame] | 1489 | return at86rf230_write_subreg(lp, SR_SLOTTED_OPERATION, 0); |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 1490 | } |
| 1491 | |
Alexander Aring | aaa1c4d | 2015-02-27 09:58:25 +0100 | [diff] [blame] | 1492 | static int |
Alexander Aring | ccdaeb2 | 2015-02-27 09:58:26 +0100 | [diff] [blame] | 1493 | at86rf230_get_pdata(struct spi_device *spi, int *rstn, int *slp_tr, |
| 1494 | u8 *xtal_trim) |
Alexander Aring | fa2d3e9 | 2014-03-15 09:29:07 +0100 | [diff] [blame] | 1495 | { |
Alexander Aring | aaa1c4d | 2015-02-27 09:58:25 +0100 | [diff] [blame] | 1496 | struct at86rf230_platform_data *pdata = spi->dev.platform_data; |
Alexander Aring | ccdaeb2 | 2015-02-27 09:58:26 +0100 | [diff] [blame] | 1497 | int ret; |
Alexander Aring | fa2d3e9 | 2014-03-15 09:29:07 +0100 | [diff] [blame] | 1498 | |
Alexander Aring | aaa1c4d | 2015-02-27 09:58:25 +0100 | [diff] [blame] | 1499 | if (!IS_ENABLED(CONFIG_OF) || !spi->dev.of_node) { |
| 1500 | if (!pdata) |
| 1501 | return -ENOENT; |
Alexander Aring | fa2d3e9 | 2014-03-15 09:29:07 +0100 | [diff] [blame] | 1502 | |
Alexander Aring | aaa1c4d | 2015-02-27 09:58:25 +0100 | [diff] [blame] | 1503 | *rstn = pdata->rstn; |
| 1504 | *slp_tr = pdata->slp_tr; |
Alexander Aring | ccdaeb2 | 2015-02-27 09:58:26 +0100 | [diff] [blame] | 1505 | *xtal_trim = pdata->xtal_trim; |
Alexander Aring | aaa1c4d | 2015-02-27 09:58:25 +0100 | [diff] [blame] | 1506 | return 0; |
| 1507 | } |
Alexander Aring | fa2d3e9 | 2014-03-15 09:29:07 +0100 | [diff] [blame] | 1508 | |
Alexander Aring | aaa1c4d | 2015-02-27 09:58:25 +0100 | [diff] [blame] | 1509 | *rstn = of_get_named_gpio(spi->dev.of_node, "reset-gpio", 0); |
| 1510 | *slp_tr = of_get_named_gpio(spi->dev.of_node, "sleep-gpio", 0); |
Alexander Aring | ccdaeb2 | 2015-02-27 09:58:26 +0100 | [diff] [blame] | 1511 | ret = of_property_read_u8(spi->dev.of_node, "xtal-trim", xtal_trim); |
| 1512 | if (ret < 0 && ret != -EINVAL) |
| 1513 | return ret; |
Alexander Aring | fa2d3e9 | 2014-03-15 09:29:07 +0100 | [diff] [blame] | 1514 | |
Alexander Aring | aaa1c4d | 2015-02-27 09:58:25 +0100 | [diff] [blame] | 1515 | return 0; |
Alexander Aring | fa2d3e9 | 2014-03-15 09:29:07 +0100 | [diff] [blame] | 1516 | } |
| 1517 | |
Alexander Aring | c8ee0f5 | 2014-07-03 00:20:45 +0200 | [diff] [blame] | 1518 | static int |
| 1519 | at86rf230_detect_device(struct at86rf230_local *lp) |
| 1520 | { |
| 1521 | unsigned int part, version, val; |
| 1522 | u16 man_id = 0; |
| 1523 | const char *chip; |
| 1524 | int rc; |
| 1525 | |
| 1526 | rc = __at86rf230_read(lp, RG_MAN_ID_0, &val); |
| 1527 | if (rc) |
| 1528 | return rc; |
| 1529 | man_id |= val; |
| 1530 | |
| 1531 | rc = __at86rf230_read(lp, RG_MAN_ID_1, &val); |
| 1532 | if (rc) |
| 1533 | return rc; |
| 1534 | man_id |= (val << 8); |
| 1535 | |
| 1536 | rc = __at86rf230_read(lp, RG_PART_NUM, &part); |
| 1537 | if (rc) |
| 1538 | return rc; |
| 1539 | |
Andrey Yurovsky | 7598968 | 2014-12-17 13:14:42 -0800 | [diff] [blame] | 1540 | rc = __at86rf230_read(lp, RG_VERSION_NUM, &version); |
Alexander Aring | c8ee0f5 | 2014-07-03 00:20:45 +0200 | [diff] [blame] | 1541 | if (rc) |
| 1542 | return rc; |
| 1543 | |
| 1544 | if (man_id != 0x001f) { |
| 1545 | dev_err(&lp->spi->dev, "Non-Atmel dev found (MAN_ID %02x %02x)\n", |
| 1546 | man_id >> 8, man_id & 0xFF); |
| 1547 | return -EINVAL; |
| 1548 | } |
| 1549 | |
Alexander Aring | 2ac0f3a | 2014-10-29 21:34:43 +0100 | [diff] [blame] | 1550 | lp->hw->flags = IEEE802154_HW_TX_OMIT_CKSUM | IEEE802154_HW_AACK | |
Alexander Aring | c8fc84e | 2014-10-29 21:34:31 +0100 | [diff] [blame] | 1551 | IEEE802154_HW_TXPOWER | IEEE802154_HW_ARET | |
Alexander Aring | 92f45f5 | 2014-10-29 21:34:33 +0100 | [diff] [blame] | 1552 | IEEE802154_HW_AFILT | IEEE802154_HW_PROMISCUOUS; |
Alexander Aring | c8ee0f5 | 2014-07-03 00:20:45 +0200 | [diff] [blame] | 1553 | |
Alexander Aring | b48a7c1 | 2014-12-10 15:33:14 +0100 | [diff] [blame] | 1554 | lp->hw->phy->cca.mode = NL802154_CCA_ENERGY; |
| 1555 | |
Alexander Aring | c8ee0f5 | 2014-07-03 00:20:45 +0200 | [diff] [blame] | 1556 | switch (part) { |
| 1557 | case 2: |
| 1558 | chip = "at86rf230"; |
| 1559 | rc = -ENOTSUPP; |
| 1560 | break; |
| 1561 | case 3: |
| 1562 | chip = "at86rf231"; |
Alexander Aring | a53d1f7 | 2014-07-03 00:20:46 +0200 | [diff] [blame] | 1563 | lp->data = &at86rf231_data; |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 1564 | lp->hw->phy->channels_supported[0] = 0x7FFF800; |
Alexander Aring | fe58d01 | 2014-11-02 04:18:34 +0100 | [diff] [blame] | 1565 | lp->hw->phy->current_channel = 11; |
Alexander Aring | 24ccb9f | 2014-11-12 19:51:57 +0100 | [diff] [blame] | 1566 | lp->hw->phy->symbol_duration = 16; |
Alexander Aring | c8ee0f5 | 2014-07-03 00:20:45 +0200 | [diff] [blame] | 1567 | break; |
| 1568 | case 7: |
| 1569 | chip = "at86rf212"; |
Andrey Yurovsky | 4ecc8a5 | 2014-12-18 15:36:18 -0800 | [diff] [blame] | 1570 | lp->data = &at86rf212_data; |
| 1571 | lp->hw->flags |= IEEE802154_HW_LBT; |
| 1572 | lp->hw->phy->channels_supported[0] = 0x00007FF; |
| 1573 | lp->hw->phy->channels_supported[2] = 0x00007FF; |
| 1574 | lp->hw->phy->current_channel = 5; |
| 1575 | lp->hw->phy->symbol_duration = 25; |
Alexander Aring | c8ee0f5 | 2014-07-03 00:20:45 +0200 | [diff] [blame] | 1576 | break; |
| 1577 | case 11: |
| 1578 | chip = "at86rf233"; |
Alexander Aring | a53d1f7 | 2014-07-03 00:20:46 +0200 | [diff] [blame] | 1579 | lp->data = &at86rf233_data; |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 1580 | lp->hw->phy->channels_supported[0] = 0x7FFF800; |
Alexander Aring | fe58d01 | 2014-11-02 04:18:34 +0100 | [diff] [blame] | 1581 | lp->hw->phy->current_channel = 13; |
Alexander Aring | 24ccb9f | 2014-11-12 19:51:57 +0100 | [diff] [blame] | 1582 | lp->hw->phy->symbol_duration = 16; |
Alexander Aring | c8ee0f5 | 2014-07-03 00:20:45 +0200 | [diff] [blame] | 1583 | break; |
| 1584 | default: |
Stefan Schmidt | 2b8b7e2 | 2014-12-12 12:45:30 +0100 | [diff] [blame] | 1585 | chip = "unknown"; |
Alexander Aring | c8ee0f5 | 2014-07-03 00:20:45 +0200 | [diff] [blame] | 1586 | rc = -ENOTSUPP; |
| 1587 | break; |
| 1588 | } |
| 1589 | |
| 1590 | dev_info(&lp->spi->dev, "Detected %s chip version %d\n", chip, version); |
| 1591 | |
| 1592 | return rc; |
| 1593 | } |
| 1594 | |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 1595 | static void |
| 1596 | at86rf230_setup_spi_messages(struct at86rf230_local *lp) |
| 1597 | { |
Alexander Aring | 2e0571c | 2014-07-03 00:20:51 +0200 | [diff] [blame] | 1598 | lp->state.lp = lp; |
Alexander Aring | cca990c | 2015-03-01 21:55:31 +0100 | [diff] [blame] | 1599 | lp->state.irq = lp->spi->irq; |
Alexander Aring | 2e0571c | 2014-07-03 00:20:51 +0200 | [diff] [blame] | 1600 | spi_message_init(&lp->state.msg); |
| 1601 | lp->state.msg.context = &lp->state; |
Alexander Aring | 263be33 | 2015-03-01 21:55:33 +0100 | [diff] [blame] | 1602 | lp->state.trx.len = 2; |
Alexander Aring | 2e0571c | 2014-07-03 00:20:51 +0200 | [diff] [blame] | 1603 | lp->state.trx.tx_buf = lp->state.buf; |
| 1604 | lp->state.trx.rx_buf = lp->state.buf; |
| 1605 | spi_message_add_tail(&lp->state.trx, &lp->state.msg); |
Alexander Aring | eb3b435 | 2015-03-09 13:56:10 +0100 | [diff] [blame] | 1606 | hrtimer_init(&lp->state.timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); |
| 1607 | lp->state.timer.function = at86rf230_async_state_timer; |
Alexander Aring | 2e0571c | 2014-07-03 00:20:51 +0200 | [diff] [blame] | 1608 | |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 1609 | lp->irq.lp = lp; |
Alexander Aring | cca990c | 2015-03-01 21:55:31 +0100 | [diff] [blame] | 1610 | lp->irq.irq = lp->spi->irq; |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 1611 | spi_message_init(&lp->irq.msg); |
| 1612 | lp->irq.msg.context = &lp->irq; |
Alexander Aring | 263be33 | 2015-03-01 21:55:33 +0100 | [diff] [blame] | 1613 | lp->irq.trx.len = 2; |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 1614 | lp->irq.trx.tx_buf = lp->irq.buf; |
| 1615 | lp->irq.trx.rx_buf = lp->irq.buf; |
| 1616 | spi_message_add_tail(&lp->irq.trx, &lp->irq.msg); |
Alexander Aring | eb3b435 | 2015-03-09 13:56:10 +0100 | [diff] [blame] | 1617 | hrtimer_init(&lp->irq.timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); |
| 1618 | lp->irq.timer.function = at86rf230_async_state_timer; |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 1619 | |
| 1620 | lp->tx.lp = lp; |
Alexander Aring | cca990c | 2015-03-01 21:55:31 +0100 | [diff] [blame] | 1621 | lp->tx.irq = lp->spi->irq; |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 1622 | spi_message_init(&lp->tx.msg); |
| 1623 | lp->tx.msg.context = &lp->tx; |
Alexander Aring | 263be33 | 2015-03-01 21:55:33 +0100 | [diff] [blame] | 1624 | lp->tx.trx.len = 2; |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 1625 | lp->tx.trx.tx_buf = lp->tx.buf; |
| 1626 | lp->tx.trx.rx_buf = lp->tx.buf; |
| 1627 | spi_message_add_tail(&lp->tx.trx, &lp->tx.msg); |
Alexander Aring | eb3b435 | 2015-03-09 13:56:10 +0100 | [diff] [blame] | 1628 | hrtimer_init(&lp->tx.timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); |
| 1629 | lp->tx.timer.function = at86rf230_async_state_timer; |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 1630 | } |
| 1631 | |
Bill Pemberton | bb1f460 | 2012-12-03 09:24:12 -0500 | [diff] [blame] | 1632 | static int at86rf230_probe(struct spi_device *spi) |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 1633 | { |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 1634 | struct ieee802154_hw *hw; |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 1635 | struct at86rf230_local *lp; |
Alexander Aring | f76014f77 | 2014-07-03 00:20:44 +0200 | [diff] [blame] | 1636 | unsigned int status; |
Alexander Aring | aaa1c4d | 2015-02-27 09:58:25 +0100 | [diff] [blame] | 1637 | int rc, irq_type, rstn, slp_tr; |
Alexander Aring | e372174 | 2015-03-07 22:07:07 +0100 | [diff] [blame] | 1638 | u8 xtal_trim = 0; |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 1639 | |
| 1640 | if (!spi->irq) { |
| 1641 | dev_err(&spi->dev, "no IRQ specified\n"); |
| 1642 | return -EINVAL; |
| 1643 | } |
| 1644 | |
Alexander Aring | ccdaeb2 | 2015-02-27 09:58:26 +0100 | [diff] [blame] | 1645 | rc = at86rf230_get_pdata(spi, &rstn, &slp_tr, &xtal_trim); |
Alexander Aring | aaa1c4d | 2015-02-27 09:58:25 +0100 | [diff] [blame] | 1646 | if (rc < 0) { |
| 1647 | dev_err(&spi->dev, "failed to parse platform_data: %d\n", rc); |
| 1648 | return rc; |
Sascha Herrmann | 43b5abe | 2013-04-14 22:33:28 +0000 | [diff] [blame] | 1649 | } |
| 1650 | |
Alexander Aring | aaa1c4d | 2015-02-27 09:58:25 +0100 | [diff] [blame] | 1651 | if (gpio_is_valid(rstn)) { |
| 1652 | rc = devm_gpio_request_one(&spi->dev, rstn, |
Alexander Aring | 0679e29 | 2014-04-24 19:09:09 +0200 | [diff] [blame] | 1653 | GPIOF_OUT_INIT_HIGH, "rstn"); |
Alexander Aring | 3fa2757 | 2014-03-15 09:29:06 +0100 | [diff] [blame] | 1654 | if (rc) |
| 1655 | return rc; |
| 1656 | } |
Phoebe Buckheister | 8fad346 | 2014-02-17 11:34:06 +0100 | [diff] [blame] | 1657 | |
Alexander Aring | aaa1c4d | 2015-02-27 09:58:25 +0100 | [diff] [blame] | 1658 | if (gpio_is_valid(slp_tr)) { |
| 1659 | rc = devm_gpio_request_one(&spi->dev, slp_tr, |
Alexander Aring | 0679e29 | 2014-04-24 19:09:09 +0200 | [diff] [blame] | 1660 | GPIOF_OUT_INIT_LOW, "slp_tr"); |
Phoebe Buckheister | 8fad346 | 2014-02-17 11:34:06 +0100 | [diff] [blame] | 1661 | if (rc) |
Alexander Aring | 0679e29 | 2014-04-24 19:09:09 +0200 | [diff] [blame] | 1662 | return rc; |
Phoebe Buckheister | 8fad346 | 2014-02-17 11:34:06 +0100 | [diff] [blame] | 1663 | } |
| 1664 | |
| 1665 | /* Reset */ |
Alexander Aring | aaa1c4d | 2015-02-27 09:58:25 +0100 | [diff] [blame] | 1666 | if (gpio_is_valid(rstn)) { |
Alexander Aring | 3fa2757 | 2014-03-15 09:29:06 +0100 | [diff] [blame] | 1667 | udelay(1); |
Alexander Aring | aaa1c4d | 2015-02-27 09:58:25 +0100 | [diff] [blame] | 1668 | gpio_set_value(rstn, 0); |
Alexander Aring | 3fa2757 | 2014-03-15 09:29:06 +0100 | [diff] [blame] | 1669 | udelay(1); |
Alexander Aring | aaa1c4d | 2015-02-27 09:58:25 +0100 | [diff] [blame] | 1670 | gpio_set_value(rstn, 1); |
Alexander Aring | 3fa2757 | 2014-03-15 09:29:06 +0100 | [diff] [blame] | 1671 | usleep_range(120, 240); |
| 1672 | } |
Phoebe Buckheister | 8fad346 | 2014-02-17 11:34:06 +0100 | [diff] [blame] | 1673 | |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 1674 | hw = ieee802154_alloc_hw(sizeof(*lp), &at86rf230_ops); |
| 1675 | if (!hw) |
Alexander Aring | 0679e29 | 2014-04-24 19:09:09 +0200 | [diff] [blame] | 1676 | return -ENOMEM; |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 1677 | |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 1678 | lp = hw->priv; |
| 1679 | lp->hw = hw; |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 1680 | lp->spi = spi; |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 1681 | hw->parent = &spi->dev; |
Alexander Aring | 7c118c1 | 2014-11-05 20:51:20 +0100 | [diff] [blame] | 1682 | hw->vif_data_size = sizeof(*lp); |
Alexander Aring | f6f4e86 | 2014-11-05 20:51:26 +0100 | [diff] [blame] | 1683 | ieee802154_random_extended_addr(&hw->phy->perm_extended_addr); |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 1684 | |
Alexander Aring | f76014f77 | 2014-07-03 00:20:44 +0200 | [diff] [blame] | 1685 | lp->regmap = devm_regmap_init_spi(spi, &at86rf230_regmap_spi_config); |
| 1686 | if (IS_ERR(lp->regmap)) { |
| 1687 | rc = PTR_ERR(lp->regmap); |
| 1688 | dev_err(&spi->dev, "Failed to allocate register map: %d\n", |
| 1689 | rc); |
| 1690 | goto free_dev; |
| 1691 | } |
| 1692 | |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 1693 | at86rf230_setup_spi_messages(lp); |
| 1694 | |
Alexander Aring | c8ee0f5 | 2014-07-03 00:20:45 +0200 | [diff] [blame] | 1695 | rc = at86rf230_detect_device(lp); |
| 1696 | if (rc < 0) |
| 1697 | goto free_dev; |
| 1698 | |
Alexander Aring | 2e0571c | 2014-07-03 00:20:51 +0200 | [diff] [blame] | 1699 | init_completion(&lp->state_complete); |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 1700 | |
| 1701 | spi_set_drvdata(spi, lp); |
| 1702 | |
Alexander Aring | ccdaeb2 | 2015-02-27 09:58:26 +0100 | [diff] [blame] | 1703 | rc = at86rf230_hw_init(lp, xtal_trim); |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 1704 | if (rc) |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 1705 | goto free_dev; |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 1706 | |
Alexander Aring | 1962694 | 2014-04-24 19:09:15 +0200 | [diff] [blame] | 1707 | /* Read irq status register to reset irq line */ |
| 1708 | rc = at86rf230_read_subreg(lp, RG_IRQ_STATUS, 0xff, 0, &status); |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 1709 | if (rc) |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 1710 | goto free_dev; |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 1711 | |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 1712 | irq_type = irq_get_trigger_type(spi->irq); |
| 1713 | if (!irq_type) |
| 1714 | irq_type = IRQF_TRIGGER_RISING; |
| 1715 | |
| 1716 | rc = devm_request_irq(&spi->dev, spi->irq, at86rf230_isr, |
| 1717 | IRQF_SHARED | irq_type, dev_name(&spi->dev), lp); |
Sascha Herrmann | 057dad6 | 2013-04-14 22:33:29 +0000 | [diff] [blame] | 1718 | if (rc) |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 1719 | goto free_dev; |
Sascha Herrmann | 057dad6 | 2013-04-14 22:33:29 +0000 | [diff] [blame] | 1720 | |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 1721 | rc = ieee802154_register_hw(lp->hw); |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 1722 | if (rc) |
Alexander Aring | 1d15d6b | 2014-07-03 00:20:48 +0200 | [diff] [blame] | 1723 | goto free_dev; |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 1724 | |
| 1725 | return rc; |
| 1726 | |
Alexander Aring | 640985e | 2014-07-03 00:20:43 +0200 | [diff] [blame] | 1727 | free_dev: |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 1728 | ieee802154_free_hw(lp->hw); |
Phoebe Buckheister | 8fad346 | 2014-02-17 11:34:06 +0100 | [diff] [blame] | 1729 | |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 1730 | return rc; |
| 1731 | } |
| 1732 | |
Bill Pemberton | bb1f460 | 2012-12-03 09:24:12 -0500 | [diff] [blame] | 1733 | static int at86rf230_remove(struct spi_device *spi) |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 1734 | { |
| 1735 | struct at86rf230_local *lp = spi_get_drvdata(spi); |
| 1736 | |
Alexander Aring | 17e84a9 | 2014-03-31 03:26:51 +0200 | [diff] [blame] | 1737 | /* mask all at86rf230 irq's */ |
| 1738 | at86rf230_write_subreg(lp, SR_IRQ_MASK, 0); |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 1739 | ieee802154_unregister_hw(lp->hw); |
| 1740 | ieee802154_free_hw(lp->hw); |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 1741 | dev_dbg(&spi->dev, "unregistered at86rf230\n"); |
Alexander Aring | 0679e29 | 2014-04-24 19:09:09 +0200 | [diff] [blame] | 1742 | |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 1743 | return 0; |
| 1744 | } |
| 1745 | |
Alexander Aring | 1086b4f | 2014-04-24 19:09:11 +0200 | [diff] [blame] | 1746 | static const struct of_device_id at86rf230_of_match[] = { |
Alexander Aring | fa2d3e9 | 2014-03-15 09:29:07 +0100 | [diff] [blame] | 1747 | { .compatible = "atmel,at86rf230", }, |
| 1748 | { .compatible = "atmel,at86rf231", }, |
| 1749 | { .compatible = "atmel,at86rf233", }, |
| 1750 | { .compatible = "atmel,at86rf212", }, |
| 1751 | { }, |
| 1752 | }; |
Alexander Aring | 835cb7d | 2014-04-24 19:09:10 +0200 | [diff] [blame] | 1753 | MODULE_DEVICE_TABLE(of, at86rf230_of_match); |
Alexander Aring | fa2d3e9 | 2014-03-15 09:29:07 +0100 | [diff] [blame] | 1754 | |
Alexander Aring | 90b1552 | 2014-04-24 19:09:12 +0200 | [diff] [blame] | 1755 | static const struct spi_device_id at86rf230_device_id[] = { |
| 1756 | { .name = "at86rf230", }, |
| 1757 | { .name = "at86rf231", }, |
| 1758 | { .name = "at86rf233", }, |
| 1759 | { .name = "at86rf212", }, |
| 1760 | { }, |
| 1761 | }; |
| 1762 | MODULE_DEVICE_TABLE(spi, at86rf230_device_id); |
| 1763 | |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 1764 | static struct spi_driver at86rf230_driver = { |
Alexander Aring | 90b1552 | 2014-04-24 19:09:12 +0200 | [diff] [blame] | 1765 | .id_table = at86rf230_device_id, |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 1766 | .driver = { |
Alexander Aring | fa2d3e9 | 2014-03-15 09:29:07 +0100 | [diff] [blame] | 1767 | .of_match_table = of_match_ptr(at86rf230_of_match), |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 1768 | .name = "at86rf230", |
| 1769 | .owner = THIS_MODULE, |
| 1770 | }, |
| 1771 | .probe = at86rf230_probe, |
Bill Pemberton | bb1f460 | 2012-12-03 09:24:12 -0500 | [diff] [blame] | 1772 | .remove = at86rf230_remove, |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 1773 | }; |
| 1774 | |
alex.bluesman.smirnov@gmail.com | 395a573 | 2012-08-26 05:10:10 +0000 | [diff] [blame] | 1775 | module_spi_driver(at86rf230_driver); |
alex.bluesman.smirnov@gmail.com | 7b8e19b | 2012-06-25 23:24:53 +0000 | [diff] [blame] | 1776 | |
| 1777 | MODULE_DESCRIPTION("AT86RF230 Transceiver Driver"); |
| 1778 | MODULE_LICENSE("GPL v2"); |