2 * atusb.c - Driver for the ATUSB IEEE 802.15.4 dongle
4 * Written 2013 by Werner Almesberger <werner@almesberger.net>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, version 2
10 * Based on at86rf230.c and spi_atusb.c.
12 * Copyright (C) 2009 Siemens AG
13 * Written by: Dmitry Eremin-Solenikov <dmitry.baryshkov@siemens.com>
16 * Copyright (c) 2011 Richard Sharpe <realrichardsharpe@gmail.com>
17 * Copyright (c) 2011 Stefan Schmidt <stefan@datenfreihafen.org>
18 * Copyright (c) 2011 Werner Almesberger <werner@almesberger.net>
20 * USB initialization is
21 * Copyright (c) 2013 Alexander Aring <alex.aring@gmail.com>
24 #include <linux/kernel.h>
25 #include <linux/slab.h>
26 #include <linux/module.h>
27 #include <linux/jiffies.h>
28 #include <linux/usb.h>
29 #include <linux/skbuff.h>
31 #include <net/cfg802154.h>
32 #include <net/mac802154.h>
34 #include "at86rf230.h"
37 #define ATUSB_JEDEC_ATMEL 0x1f /* JEDEC manufacturer ID */
39 #define ATUSB_NUM_RX_URBS 4 /* allow for a bit of local latency */
40 #define ATUSB_ALLOC_DELAY_MS 100 /* delay after failed allocation */
41 #define ATUSB_TX_TIMEOUT_MS 200 /* on the air timeout */
44 struct ieee802154_hw *hw;
45 struct usb_device *usb_dev;
46 int shutdown; /* non-zero if shutting down */
47 int err; /* set by first error */
50 struct delayed_work work; /* memory allocations */
51 struct usb_anchor idle_urbs; /* URBs waiting to be submitted */
52 struct usb_anchor rx_urbs; /* URBs waiting for reception */
55 struct usb_ctrlrequest tx_dr;
57 struct sk_buff *tx_skb;
58 uint8_t tx_ack_seq; /* current TX ACK sequence number */
61 /* ----- USB commands without data ----------------------------------------- */
63 /* To reduce the number of error checks in the code, we record the first error
64 * in atusb->err and reject all subsequent requests until the error is cleared.
67 static int atusb_control_msg(struct atusb *atusb, unsigned int pipe,
68 __u8 request, __u8 requesttype,
69 __u16 value, __u16 index,
70 void *data, __u16 size, int timeout)
72 struct usb_device *usb_dev = atusb->usb_dev;
78 ret = usb_control_msg(usb_dev, pipe, request, requesttype,
79 value, index, data, size, timeout);
82 dev_err(&usb_dev->dev,
83 "atusb_control_msg: req 0x%02x val 0x%x idx 0x%x, error %d\n",
84 request, value, index, ret);
89 static int atusb_command(struct atusb *atusb, uint8_t cmd, uint8_t arg)
91 struct usb_device *usb_dev = atusb->usb_dev;
93 dev_dbg(&usb_dev->dev, "atusb_command: cmd = 0x%x\n", cmd);
94 return atusb_control_msg(atusb, usb_sndctrlpipe(usb_dev, 0),
95 cmd, ATUSB_REQ_TO_DEV, arg, 0, NULL, 0, 1000);
98 static int atusb_write_reg(struct atusb *atusb, uint8_t reg, uint8_t value)
100 struct usb_device *usb_dev = atusb->usb_dev;
102 dev_dbg(&usb_dev->dev, "atusb_write_reg: 0x%02x <- 0x%02x\n",
104 return atusb_control_msg(atusb, usb_sndctrlpipe(usb_dev, 0),
105 ATUSB_REG_WRITE, ATUSB_REQ_TO_DEV,
106 value, reg, NULL, 0, 1000);
109 static int atusb_read_reg(struct atusb *atusb, uint8_t reg)
111 struct usb_device *usb_dev = atusb->usb_dev;
115 dev_dbg(&usb_dev->dev, "atusb: reg = 0x%x\n", reg);
116 ret = atusb_control_msg(atusb, usb_rcvctrlpipe(usb_dev, 0),
117 ATUSB_REG_READ, ATUSB_REQ_FROM_DEV,
118 0, reg, &value, 1, 1000);
119 return ret >= 0 ? value : ret;
122 static int atusb_write_subreg(struct atusb *atusb, uint8_t reg, uint8_t mask,
123 uint8_t shift, uint8_t value)
125 struct usb_device *usb_dev = atusb->usb_dev;
129 dev_dbg(&usb_dev->dev, "atusb_write_subreg: 0x%02x <- 0x%02x\n",
132 orig = atusb_read_reg(atusb, reg);
134 /* Write the value only into that part of the register which is allowed
135 * by the mask. All other bits stay as before.
138 tmp |= (value << shift) & mask;
141 ret = atusb_write_reg(atusb, reg, tmp);
146 static int atusb_get_and_clear_error(struct atusb *atusb)
148 int err = atusb->err;
154 /* ----- skb allocation ---------------------------------------------------- */
157 #define MAX_RX_XFER (1 + MAX_PSDU + 2 + 1) /* PHR+PSDU+CRC+LQI */
159 #define SKB_ATUSB(skb) (*(struct atusb **)(skb)->cb)
161 static void atusb_in(struct urb *urb);
163 static int atusb_submit_rx_urb(struct atusb *atusb, struct urb *urb)
165 struct usb_device *usb_dev = atusb->usb_dev;
166 struct sk_buff *skb = urb->context;
170 skb = alloc_skb(MAX_RX_XFER, GFP_KERNEL);
172 dev_warn_ratelimited(&usb_dev->dev,
173 "atusb_in: can't allocate skb\n");
176 skb_put(skb, MAX_RX_XFER);
177 SKB_ATUSB(skb) = atusb;
180 usb_fill_bulk_urb(urb, usb_dev, usb_rcvbulkpipe(usb_dev, 1),
181 skb->data, MAX_RX_XFER, atusb_in, skb);
182 usb_anchor_urb(urb, &atusb->rx_urbs);
184 ret = usb_submit_urb(urb, GFP_KERNEL);
186 usb_unanchor_urb(urb);
193 static void atusb_work_urbs(struct work_struct *work)
195 struct atusb *atusb =
196 container_of(to_delayed_work(work), struct atusb, work);
197 struct usb_device *usb_dev = atusb->usb_dev;
205 urb = usb_get_from_anchor(&atusb->idle_urbs);
208 ret = atusb_submit_rx_urb(atusb, urb);
211 usb_anchor_urb(urb, &atusb->idle_urbs);
212 dev_warn_ratelimited(&usb_dev->dev,
213 "atusb_in: can't allocate/submit URB (%d)\n", ret);
214 schedule_delayed_work(&atusb->work,
215 msecs_to_jiffies(ATUSB_ALLOC_DELAY_MS) + 1);
218 /* ----- Asynchronous USB -------------------------------------------------- */
220 static void atusb_tx_done(struct atusb *atusb, uint8_t seq)
222 struct usb_device *usb_dev = atusb->usb_dev;
223 uint8_t expect = atusb->tx_ack_seq;
225 dev_dbg(&usb_dev->dev, "atusb_tx_done (0x%02x/0x%02x)\n", seq, expect);
227 /* TODO check for ifs handling in firmware */
228 ieee802154_xmit_complete(atusb->hw, atusb->tx_skb, false);
230 /* TODO I experience this case when atusb has a tx complete
231 * irq before probing, we should fix the firmware it's an
232 * unlikely case now that seq == expect is then true, but can
233 * happen and fail with a tx_skb = NULL;
235 ieee802154_wake_queue(atusb->hw);
237 dev_kfree_skb_irq(atusb->tx_skb);
241 static void atusb_in_good(struct urb *urb)
243 struct usb_device *usb_dev = urb->dev;
244 struct sk_buff *skb = urb->context;
245 struct atusb *atusb = SKB_ATUSB(skb);
248 if (!urb->actual_length) {
249 dev_dbg(&usb_dev->dev, "atusb_in: zero-sized URB ?\n");
255 if (urb->actual_length == 1) {
256 atusb_tx_done(atusb, len);
260 if (len + 1 > urb->actual_length - 1) {
261 dev_dbg(&usb_dev->dev, "atusb_in: frame len %d+1 > URB %u-1\n",
262 len, urb->actual_length);
266 if (!ieee802154_is_valid_psdu_len(len)) {
267 dev_dbg(&usb_dev->dev, "atusb_in: frame corrupted\n");
271 lqi = skb->data[len + 1];
272 dev_dbg(&usb_dev->dev, "atusb_in: rx len %d lqi 0x%02x\n", len, lqi);
273 skb_pull(skb, 1); /* remove PHR */
274 skb_trim(skb, len); /* get payload only */
275 ieee802154_rx_irqsafe(atusb->hw, skb, lqi);
276 urb->context = NULL; /* skb is gone */
279 static void atusb_in(struct urb *urb)
281 struct usb_device *usb_dev = urb->dev;
282 struct sk_buff *skb = urb->context;
283 struct atusb *atusb = SKB_ATUSB(skb);
285 dev_dbg(&usb_dev->dev, "atusb_in: status %d len %d\n",
286 urb->status, urb->actual_length);
288 if (urb->status == -ENOENT) { /* being killed */
293 dev_dbg(&usb_dev->dev, "atusb_in: URB error %d\n", urb->status);
298 usb_anchor_urb(urb, &atusb->idle_urbs);
299 if (!atusb->shutdown)
300 schedule_delayed_work(&atusb->work, 0);
303 /* ----- URB allocation/deallocation --------------------------------------- */
305 static void atusb_free_urbs(struct atusb *atusb)
310 urb = usb_get_from_anchor(&atusb->idle_urbs);
313 kfree_skb(urb->context);
318 static int atusb_alloc_urbs(struct atusb *atusb, int n)
323 urb = usb_alloc_urb(0, GFP_KERNEL);
325 atusb_free_urbs(atusb);
328 usb_anchor_urb(urb, &atusb->idle_urbs);
334 /* ----- IEEE 802.15.4 interface operations -------------------------------- */
336 static void atusb_xmit_complete(struct urb *urb)
338 dev_dbg(&urb->dev->dev, "atusb_xmit urb completed");
341 static int atusb_xmit(struct ieee802154_hw *hw, struct sk_buff *skb)
343 struct atusb *atusb = hw->priv;
344 struct usb_device *usb_dev = atusb->usb_dev;
347 dev_dbg(&usb_dev->dev, "atusb_xmit (%d)\n", skb->len);
350 atusb->tx_dr.wIndex = cpu_to_le16(atusb->tx_ack_seq);
351 atusb->tx_dr.wLength = cpu_to_le16(skb->len);
353 usb_fill_control_urb(atusb->tx_urb, usb_dev,
354 usb_sndctrlpipe(usb_dev, 0),
355 (unsigned char *)&atusb->tx_dr, skb->data,
356 skb->len, atusb_xmit_complete, NULL);
357 ret = usb_submit_urb(atusb->tx_urb, GFP_ATOMIC);
358 dev_dbg(&usb_dev->dev, "atusb_xmit done (%d)\n", ret);
362 static int atusb_channel(struct ieee802154_hw *hw, u8 page, u8 channel)
364 struct atusb *atusb = hw->priv;
367 /* This implicitly sets the CCA (Clear Channel Assessment) mode to 0,
368 * "Mode 3a, Carrier sense OR energy above threshold".
369 * We should probably make this configurable. @@@
371 ret = atusb_write_reg(atusb, RG_PHY_CC_CCA, channel);
374 msleep(1); /* @@@ ugly synchronization */
378 static int atusb_ed(struct ieee802154_hw *hw, u8 *level)
385 static int atusb_set_hw_addr_filt(struct ieee802154_hw *hw,
386 struct ieee802154_hw_addr_filt *filt,
387 unsigned long changed)
389 struct atusb *atusb = hw->priv;
390 struct device *dev = &atusb->usb_dev->dev;
392 if (changed & IEEE802154_AFILT_SADDR_CHANGED) {
393 u16 addr = le16_to_cpu(filt->short_addr);
395 dev_vdbg(dev, "atusb_set_hw_addr_filt called for saddr\n");
396 atusb_write_reg(atusb, RG_SHORT_ADDR_0, addr);
397 atusb_write_reg(atusb, RG_SHORT_ADDR_1, addr >> 8);
400 if (changed & IEEE802154_AFILT_PANID_CHANGED) {
401 u16 pan = le16_to_cpu(filt->pan_id);
403 dev_vdbg(dev, "atusb_set_hw_addr_filt called for pan id\n");
404 atusb_write_reg(atusb, RG_PAN_ID_0, pan);
405 atusb_write_reg(atusb, RG_PAN_ID_1, pan >> 8);
408 if (changed & IEEE802154_AFILT_IEEEADDR_CHANGED) {
409 u8 i, addr[IEEE802154_EXTENDED_ADDR_LEN];
411 memcpy(addr, &filt->ieee_addr, IEEE802154_EXTENDED_ADDR_LEN);
412 dev_vdbg(dev, "atusb_set_hw_addr_filt called for IEEE addr\n");
413 for (i = 0; i < 8; i++)
414 atusb_write_reg(atusb, RG_IEEE_ADDR_0 + i, addr[i]);
417 if (changed & IEEE802154_AFILT_PANC_CHANGED) {
419 "atusb_set_hw_addr_filt called for panc change\n");
421 atusb_write_subreg(atusb, SR_AACK_I_AM_COORD, 1);
423 atusb_write_subreg(atusb, SR_AACK_I_AM_COORD, 0);
426 return atusb_get_and_clear_error(atusb);
429 static int atusb_start(struct ieee802154_hw *hw)
431 struct atusb *atusb = hw->priv;
432 struct usb_device *usb_dev = atusb->usb_dev;
435 dev_dbg(&usb_dev->dev, "atusb_start\n");
436 schedule_delayed_work(&atusb->work, 0);
437 atusb_command(atusb, ATUSB_RX_MODE, 1);
438 ret = atusb_get_and_clear_error(atusb);
440 usb_kill_anchored_urbs(&atusb->idle_urbs);
444 static void atusb_stop(struct ieee802154_hw *hw)
446 struct atusb *atusb = hw->priv;
447 struct usb_device *usb_dev = atusb->usb_dev;
449 dev_dbg(&usb_dev->dev, "atusb_stop\n");
450 usb_kill_anchored_urbs(&atusb->idle_urbs);
451 atusb_command(atusb, ATUSB_RX_MODE, 0);
452 atusb_get_and_clear_error(atusb);
455 #define ATUSB_MAX_TX_POWERS 0xF
456 static const s32 atusb_powers[ATUSB_MAX_TX_POWERS + 1] = {
457 300, 280, 230, 180, 130, 70, 0, -100, -200, -300, -400, -500, -700,
462 atusb_set_txpower(struct ieee802154_hw *hw, s32 mbm)
464 struct atusb *atusb = hw->priv;
467 for (i = 0; i < hw->phy->supported.tx_powers_size; i++) {
468 if (hw->phy->supported.tx_powers[i] == mbm)
469 return atusb_write_subreg(atusb, SR_TX_PWR_23X, i);
475 #define ATUSB_MAX_ED_LEVELS 0xF
476 static const s32 atusb_ed_levels[ATUSB_MAX_ED_LEVELS + 1] = {
477 -9100, -8900, -8700, -8500, -8300, -8100, -7900, -7700, -7500, -7300,
478 -7100, -6900, -6700, -6500, -6300, -6100,
482 atusb_set_cca_mode(struct ieee802154_hw *hw, const struct wpan_phy_cca *cca)
484 struct atusb *atusb = hw->priv;
487 /* mapping 802.15.4 to driver spec */
489 case NL802154_CCA_ENERGY:
492 case NL802154_CCA_CARRIER:
495 case NL802154_CCA_ENERGY_CARRIER:
497 case NL802154_CCA_OPT_ENERGY_CARRIER_AND:
500 case NL802154_CCA_OPT_ENERGY_CARRIER_OR:
511 return atusb_write_subreg(atusb, SR_CCA_MODE, val);
515 atusb_set_cca_ed_level(struct ieee802154_hw *hw, s32 mbm)
517 struct atusb *atusb = hw->priv;
520 for (i = 0; i < hw->phy->supported.cca_ed_levels_size; i++) {
521 if (hw->phy->supported.cca_ed_levels[i] == mbm)
522 return atusb_write_subreg(atusb, SR_CCA_ED_THRES, i);
529 atusb_set_csma_params(struct ieee802154_hw *hw, u8 min_be, u8 max_be, u8 retries)
531 struct atusb *atusb = hw->priv;
534 ret = atusb_write_subreg(atusb, SR_MIN_BE, min_be);
538 ret = atusb_write_subreg(atusb, SR_MAX_BE, max_be);
542 return atusb_write_subreg(atusb, SR_MAX_CSMA_RETRIES, retries);
546 atusb_set_promiscuous_mode(struct ieee802154_hw *hw, const bool on)
548 struct atusb *atusb = hw->priv;
552 ret = atusb_write_subreg(atusb, SR_AACK_DIS_ACK, 1);
556 ret = atusb_write_subreg(atusb, SR_AACK_PROM_MODE, 1);
560 ret = atusb_write_subreg(atusb, SR_AACK_PROM_MODE, 0);
564 ret = atusb_write_subreg(atusb, SR_AACK_DIS_ACK, 0);
572 static struct ieee802154_ops atusb_ops = {
573 .owner = THIS_MODULE,
574 .xmit_async = atusb_xmit,
576 .set_channel = atusb_channel,
577 .start = atusb_start,
579 .set_hw_addr_filt = atusb_set_hw_addr_filt,
580 .set_txpower = atusb_set_txpower,
581 .set_cca_mode = atusb_set_cca_mode,
582 .set_cca_ed_level = atusb_set_cca_ed_level,
583 .set_csma_params = atusb_set_csma_params,
584 .set_promiscuous_mode = atusb_set_promiscuous_mode,
587 /* ----- Firmware and chip version information ----------------------------- */
589 static int atusb_get_and_show_revision(struct atusb *atusb)
591 struct usb_device *usb_dev = atusb->usb_dev;
592 unsigned char buffer[3];
595 /* Get a couple of the ATMega Firmware values */
596 ret = atusb_control_msg(atusb, usb_rcvctrlpipe(usb_dev, 0),
597 ATUSB_ID, ATUSB_REQ_FROM_DEV, 0, 0,
600 dev_info(&usb_dev->dev,
601 "Firmware: major: %u, minor: %u, hardware type: %u\n",
602 buffer[0], buffer[1], buffer[2]);
603 if (buffer[0] == 0 && buffer[1] < 2) {
604 dev_info(&usb_dev->dev,
605 "Firmware version (%u.%u) is predates our first public release.",
606 buffer[0], buffer[1]);
607 dev_info(&usb_dev->dev, "Please update to version 0.2 or newer");
613 static int atusb_get_and_show_build(struct atusb *atusb)
615 struct usb_device *usb_dev = atusb->usb_dev;
616 char build[ATUSB_BUILD_SIZE + 1];
619 ret = atusb_control_msg(atusb, usb_rcvctrlpipe(usb_dev, 0),
620 ATUSB_BUILD, ATUSB_REQ_FROM_DEV, 0, 0,
621 build, ATUSB_BUILD_SIZE, 1000);
624 dev_info(&usb_dev->dev, "Firmware: build %s\n", build);
630 static int atusb_get_and_show_chip(struct atusb *atusb)
632 struct usb_device *usb_dev = atusb->usb_dev;
633 uint8_t man_id_0, man_id_1, part_num, version_num;
636 man_id_0 = atusb_read_reg(atusb, RG_MAN_ID_0);
637 man_id_1 = atusb_read_reg(atusb, RG_MAN_ID_1);
638 part_num = atusb_read_reg(atusb, RG_PART_NUM);
639 version_num = atusb_read_reg(atusb, RG_VERSION_NUM);
644 if ((man_id_1 << 8 | man_id_0) != ATUSB_JEDEC_ATMEL) {
645 dev_err(&usb_dev->dev,
646 "non-Atmel transceiver xxxx%02x%02x\n",
659 dev_err(&usb_dev->dev,
660 "unexpected transceiver, part 0x%02x version 0x%02x\n",
661 part_num, version_num);
665 dev_info(&usb_dev->dev, "ATUSB: %s version %d\n", chip, version_num);
670 atusb->err = -ENODEV;
674 /* ----- Setup ------------------------------------------------------------- */
676 static int atusb_probe(struct usb_interface *interface,
677 const struct usb_device_id *id)
679 struct usb_device *usb_dev = interface_to_usbdev(interface);
680 struct ieee802154_hw *hw;
681 struct atusb *atusb = NULL;
684 hw = ieee802154_alloc_hw(sizeof(struct atusb), &atusb_ops);
690 atusb->usb_dev = usb_get_dev(usb_dev);
691 usb_set_intfdata(interface, atusb);
695 INIT_DELAYED_WORK(&atusb->work, atusb_work_urbs);
696 init_usb_anchor(&atusb->idle_urbs);
697 init_usb_anchor(&atusb->rx_urbs);
699 if (atusb_alloc_urbs(atusb, ATUSB_NUM_RX_URBS))
702 atusb->tx_dr.bRequestType = ATUSB_REQ_TO_DEV;
703 atusb->tx_dr.bRequest = ATUSB_TX;
704 atusb->tx_dr.wValue = cpu_to_le16(0);
706 atusb->tx_urb = usb_alloc_urb(0, GFP_ATOMIC);
710 hw->parent = &usb_dev->dev;
711 hw->flags = IEEE802154_HW_TX_OMIT_CKSUM | IEEE802154_HW_AFILT |
712 IEEE802154_HW_PROMISCUOUS | IEEE802154_HW_CSMA_PARAMS;
714 hw->phy->flags = WPAN_PHY_FLAG_TXPOWER | WPAN_PHY_FLAG_CCA_ED_LEVEL |
715 WPAN_PHY_FLAG_CCA_MODE;
717 hw->phy->supported.cca_modes = BIT(NL802154_CCA_ENERGY) |
718 BIT(NL802154_CCA_CARRIER) | BIT(NL802154_CCA_ENERGY_CARRIER);
719 hw->phy->supported.cca_opts = BIT(NL802154_CCA_OPT_ENERGY_CARRIER_AND) |
720 BIT(NL802154_CCA_OPT_ENERGY_CARRIER_OR);
722 hw->phy->supported.cca_ed_levels = atusb_ed_levels;
723 hw->phy->supported.cca_ed_levels_size = ARRAY_SIZE(atusb_ed_levels);
725 hw->phy->cca.mode = NL802154_CCA_ENERGY;
727 hw->phy->current_page = 0;
728 hw->phy->current_channel = 11; /* reset default */
729 hw->phy->supported.channels[0] = 0x7FFF800;
730 hw->phy->supported.tx_powers = atusb_powers;
731 hw->phy->supported.tx_powers_size = ARRAY_SIZE(atusb_powers);
732 hw->phy->transmit_power = hw->phy->supported.tx_powers[0];
733 ieee802154_random_extended_addr(&hw->phy->perm_extended_addr);
734 hw->phy->cca_ed_level = hw->phy->supported.cca_ed_levels[7];
736 atusb_command(atusb, ATUSB_RF_RESET, 0);
737 atusb_get_and_show_chip(atusb);
738 atusb_get_and_show_revision(atusb);
739 atusb_get_and_show_build(atusb);
740 ret = atusb_get_and_clear_error(atusb);
742 dev_err(&atusb->usb_dev->dev,
743 "%s: initialization failed, error = %d\n",
748 ret = ieee802154_register_hw(hw);
752 /* If we just powered on, we're now in P_ON and need to enter TRX_OFF
753 * explicitly. Any resets after that will send us straight to TRX_OFF,
754 * making the command below redundant.
756 atusb_write_reg(atusb, RG_TRX_STATE, STATE_FORCE_TRX_OFF);
757 msleep(1); /* reset => TRX_OFF, tTR13 = 37 us */
760 /* Calculating the maximum time available to empty the frame buffer
763 * According to [1], the inter-frame gap is
764 * R * 20 * 16 us + 128 us
765 * where R is a random number from 0 to 7. Furthermore, we have 20 bit
766 * times (80 us at 250 kbps) of SHR of the next frame before the
767 * transceiver begins storing data in the frame buffer.
769 * This yields a minimum time of 208 us between the last data of a
770 * frame and the first data of the next frame. This time is further
771 * reduced by interrupt latency in the atusb firmware.
773 * atusb currently needs about 500 us to retrieve a maximum-sized
774 * frame. We therefore have to allow reception of a new frame to begin
775 * while we retrieve the previous frame.
777 * [1] "JN-AN-1035 Calculating data rates in an IEEE 802.15.4-based
778 * network", Jennic 2006.
779 * http://www.jennic.com/download_file.php?supportFile=JN-AN-1035%20Calculating%20802-15-4%20Data%20Rates-1v0.pdf
782 atusb_write_subreg(atusb, SR_RX_SAFE_MODE, 1);
784 atusb_write_reg(atusb, RG_IRQ_MASK, 0xff);
786 ret = atusb_get_and_clear_error(atusb);
790 dev_err(&atusb->usb_dev->dev,
791 "%s: setup failed, error = %d\n",
794 ieee802154_unregister_hw(hw);
796 atusb_free_urbs(atusb);
797 usb_kill_urb(atusb->tx_urb);
798 usb_free_urb(atusb->tx_urb);
799 usb_put_dev(usb_dev);
800 ieee802154_free_hw(hw);
804 static void atusb_disconnect(struct usb_interface *interface)
806 struct atusb *atusb = usb_get_intfdata(interface);
808 dev_dbg(&atusb->usb_dev->dev, "atusb_disconnect\n");
811 cancel_delayed_work_sync(&atusb->work);
813 usb_kill_anchored_urbs(&atusb->rx_urbs);
814 atusb_free_urbs(atusb);
815 usb_kill_urb(atusb->tx_urb);
816 usb_free_urb(atusb->tx_urb);
818 ieee802154_unregister_hw(atusb->hw);
820 ieee802154_free_hw(atusb->hw);
822 usb_set_intfdata(interface, NULL);
823 usb_put_dev(atusb->usb_dev);
825 pr_debug("atusb_disconnect done\n");
828 /* The devices we work with */
829 static const struct usb_device_id atusb_device_table[] = {
831 .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
832 USB_DEVICE_ID_MATCH_INT_INFO,
833 .idVendor = ATUSB_VENDOR_ID,
834 .idProduct = ATUSB_PRODUCT_ID,
835 .bInterfaceClass = USB_CLASS_VENDOR_SPEC
837 /* end with null element */
840 MODULE_DEVICE_TABLE(usb, atusb_device_table);
842 static struct usb_driver atusb_driver = {
844 .probe = atusb_probe,
845 .disconnect = atusb_disconnect,
846 .id_table = atusb_device_table,
848 module_usb_driver(atusb_driver);
850 MODULE_AUTHOR("Alexander Aring <alex.aring@gmail.com>");
851 MODULE_AUTHOR("Richard Sharpe <realrichardsharpe@gmail.com>");
852 MODULE_AUTHOR("Stefan Schmidt <stefan@datenfreihafen.org>");
853 MODULE_AUTHOR("Werner Almesberger <werner@almesberger.net>");
854 MODULE_DESCRIPTION("ATUSB IEEE 802.15.4 Driver");
855 MODULE_LICENSE("GPL");