2 * atusb.c - Driver for the ATUSB IEEE 802.15.4 dongle
4 * Written 2013 by Werner Almesberger <werner@almesberger.net>
6 * Copyright (c) 2015 - 2016 Stefan Schmidt <stefan@datenfreihafen.org>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation, version 2
12 * Based on at86rf230.c and spi_atusb.c.
14 * Copyright (C) 2009 Siemens AG
15 * Written by: Dmitry Eremin-Solenikov <dmitry.baryshkov@siemens.com>
18 * Copyright (c) 2011 Richard Sharpe <realrichardsharpe@gmail.com>
19 * Copyright (c) 2011 Stefan Schmidt <stefan@datenfreihafen.org>
20 * Copyright (c) 2011 Werner Almesberger <werner@almesberger.net>
22 * USB initialization is
23 * Copyright (c) 2013 Alexander Aring <alex.aring@gmail.com>
26 #include <linux/kernel.h>
27 #include <linux/slab.h>
28 #include <linux/module.h>
29 #include <linux/jiffies.h>
30 #include <linux/usb.h>
31 #include <linux/skbuff.h>
33 #include <net/cfg802154.h>
34 #include <net/mac802154.h>
36 #include "at86rf230.h"
39 #define ATUSB_JEDEC_ATMEL 0x1f /* JEDEC manufacturer ID */
41 #define ATUSB_NUM_RX_URBS 4 /* allow for a bit of local latency */
42 #define ATUSB_ALLOC_DELAY_MS 100 /* delay after failed allocation */
43 #define ATUSB_TX_TIMEOUT_MS 200 /* on the air timeout */
46 struct ieee802154_hw *hw;
47 struct usb_device *usb_dev;
48 int shutdown; /* non-zero if shutting down */
49 int err; /* set by first error */
52 struct delayed_work work; /* memory allocations */
53 struct usb_anchor idle_urbs; /* URBs waiting to be submitted */
54 struct usb_anchor rx_urbs; /* URBs waiting for reception */
57 struct usb_ctrlrequest tx_dr;
59 struct sk_buff *tx_skb;
60 uint8_t tx_ack_seq; /* current TX ACK sequence number */
63 /* ----- USB commands without data ----------------------------------------- */
65 /* To reduce the number of error checks in the code, we record the first error
66 * in atusb->err and reject all subsequent requests until the error is cleared.
69 static int atusb_control_msg(struct atusb *atusb, unsigned int pipe,
70 __u8 request, __u8 requesttype,
71 __u16 value, __u16 index,
72 void *data, __u16 size, int timeout)
74 struct usb_device *usb_dev = atusb->usb_dev;
80 ret = usb_control_msg(usb_dev, pipe, request, requesttype,
81 value, index, data, size, timeout);
84 dev_err(&usb_dev->dev,
85 "atusb_control_msg: req 0x%02x val 0x%x idx 0x%x, error %d\n",
86 request, value, index, ret);
91 static int atusb_command(struct atusb *atusb, uint8_t cmd, uint8_t arg)
93 struct usb_device *usb_dev = atusb->usb_dev;
95 dev_dbg(&usb_dev->dev, "atusb_command: cmd = 0x%x\n", cmd);
96 return atusb_control_msg(atusb, usb_sndctrlpipe(usb_dev, 0),
97 cmd, ATUSB_REQ_TO_DEV, arg, 0, NULL, 0, 1000);
100 static int atusb_write_reg(struct atusb *atusb, uint8_t reg, uint8_t value)
102 struct usb_device *usb_dev = atusb->usb_dev;
104 dev_dbg(&usb_dev->dev, "atusb_write_reg: 0x%02x <- 0x%02x\n",
106 return atusb_control_msg(atusb, usb_sndctrlpipe(usb_dev, 0),
107 ATUSB_REG_WRITE, ATUSB_REQ_TO_DEV,
108 value, reg, NULL, 0, 1000);
111 static int atusb_read_reg(struct atusb *atusb, uint8_t reg)
113 struct usb_device *usb_dev = atusb->usb_dev;
118 buffer = kmalloc(1, GFP_KERNEL);
122 dev_dbg(&usb_dev->dev, "atusb: reg = 0x%x\n", reg);
123 ret = atusb_control_msg(atusb, usb_rcvctrlpipe(usb_dev, 0),
124 ATUSB_REG_READ, ATUSB_REQ_FROM_DEV,
125 0, reg, buffer, 1, 1000);
137 static int atusb_write_subreg(struct atusb *atusb, uint8_t reg, uint8_t mask,
138 uint8_t shift, uint8_t value)
140 struct usb_device *usb_dev = atusb->usb_dev;
144 dev_dbg(&usb_dev->dev, "atusb_write_subreg: 0x%02x <- 0x%02x\n",
147 orig = atusb_read_reg(atusb, reg);
149 /* Write the value only into that part of the register which is allowed
150 * by the mask. All other bits stay as before.
153 tmp |= (value << shift) & mask;
156 ret = atusb_write_reg(atusb, reg, tmp);
161 static int atusb_get_and_clear_error(struct atusb *atusb)
163 int err = atusb->err;
169 /* ----- skb allocation ---------------------------------------------------- */
172 #define MAX_RX_XFER (1 + MAX_PSDU + 2 + 1) /* PHR+PSDU+CRC+LQI */
174 #define SKB_ATUSB(skb) (*(struct atusb **)(skb)->cb)
176 static void atusb_in(struct urb *urb);
178 static int atusb_submit_rx_urb(struct atusb *atusb, struct urb *urb)
180 struct usb_device *usb_dev = atusb->usb_dev;
181 struct sk_buff *skb = urb->context;
185 skb = alloc_skb(MAX_RX_XFER, GFP_KERNEL);
187 dev_warn_ratelimited(&usb_dev->dev,
188 "atusb_in: can't allocate skb\n");
191 skb_put(skb, MAX_RX_XFER);
192 SKB_ATUSB(skb) = atusb;
195 usb_fill_bulk_urb(urb, usb_dev, usb_rcvbulkpipe(usb_dev, 1),
196 skb->data, MAX_RX_XFER, atusb_in, skb);
197 usb_anchor_urb(urb, &atusb->rx_urbs);
199 ret = usb_submit_urb(urb, GFP_KERNEL);
201 usb_unanchor_urb(urb);
208 static void atusb_work_urbs(struct work_struct *work)
210 struct atusb *atusb =
211 container_of(to_delayed_work(work), struct atusb, work);
212 struct usb_device *usb_dev = atusb->usb_dev;
220 urb = usb_get_from_anchor(&atusb->idle_urbs);
223 ret = atusb_submit_rx_urb(atusb, urb);
226 usb_anchor_urb(urb, &atusb->idle_urbs);
227 dev_warn_ratelimited(&usb_dev->dev,
228 "atusb_in: can't allocate/submit URB (%d)\n", ret);
229 schedule_delayed_work(&atusb->work,
230 msecs_to_jiffies(ATUSB_ALLOC_DELAY_MS) + 1);
233 /* ----- Asynchronous USB -------------------------------------------------- */
235 static void atusb_tx_done(struct atusb *atusb, uint8_t seq)
237 struct usb_device *usb_dev = atusb->usb_dev;
238 uint8_t expect = atusb->tx_ack_seq;
240 dev_dbg(&usb_dev->dev, "atusb_tx_done (0x%02x/0x%02x)\n", seq, expect);
242 /* TODO check for ifs handling in firmware */
243 ieee802154_xmit_complete(atusb->hw, atusb->tx_skb, false);
245 /* TODO I experience this case when atusb has a tx complete
246 * irq before probing, we should fix the firmware it's an
247 * unlikely case now that seq == expect is then true, but can
248 * happen and fail with a tx_skb = NULL;
250 ieee802154_wake_queue(atusb->hw);
252 dev_kfree_skb_irq(atusb->tx_skb);
256 static void atusb_in_good(struct urb *urb)
258 struct usb_device *usb_dev = urb->dev;
259 struct sk_buff *skb = urb->context;
260 struct atusb *atusb = SKB_ATUSB(skb);
263 if (!urb->actual_length) {
264 dev_dbg(&usb_dev->dev, "atusb_in: zero-sized URB ?\n");
270 if (urb->actual_length == 1) {
271 atusb_tx_done(atusb, len);
275 if (len + 1 > urb->actual_length - 1) {
276 dev_dbg(&usb_dev->dev, "atusb_in: frame len %d+1 > URB %u-1\n",
277 len, urb->actual_length);
281 if (!ieee802154_is_valid_psdu_len(len)) {
282 dev_dbg(&usb_dev->dev, "atusb_in: frame corrupted\n");
286 lqi = skb->data[len + 1];
287 dev_dbg(&usb_dev->dev, "atusb_in: rx len %d lqi 0x%02x\n", len, lqi);
288 skb_pull(skb, 1); /* remove PHR */
289 skb_trim(skb, len); /* get payload only */
290 ieee802154_rx_irqsafe(atusb->hw, skb, lqi);
291 urb->context = NULL; /* skb is gone */
294 static void atusb_in(struct urb *urb)
296 struct usb_device *usb_dev = urb->dev;
297 struct sk_buff *skb = urb->context;
298 struct atusb *atusb = SKB_ATUSB(skb);
300 dev_dbg(&usb_dev->dev, "atusb_in: status %d len %d\n",
301 urb->status, urb->actual_length);
303 if (urb->status == -ENOENT) { /* being killed */
308 dev_dbg(&usb_dev->dev, "atusb_in: URB error %d\n", urb->status);
313 usb_anchor_urb(urb, &atusb->idle_urbs);
314 if (!atusb->shutdown)
315 schedule_delayed_work(&atusb->work, 0);
318 /* ----- URB allocation/deallocation --------------------------------------- */
320 static void atusb_free_urbs(struct atusb *atusb)
325 urb = usb_get_from_anchor(&atusb->idle_urbs);
328 kfree_skb(urb->context);
333 static int atusb_alloc_urbs(struct atusb *atusb, int n)
338 urb = usb_alloc_urb(0, GFP_KERNEL);
340 atusb_free_urbs(atusb);
343 usb_anchor_urb(urb, &atusb->idle_urbs);
350 /* ----- IEEE 802.15.4 interface operations -------------------------------- */
352 static void atusb_xmit_complete(struct urb *urb)
354 dev_dbg(&urb->dev->dev, "atusb_xmit urb completed");
357 static int atusb_xmit(struct ieee802154_hw *hw, struct sk_buff *skb)
359 struct atusb *atusb = hw->priv;
360 struct usb_device *usb_dev = atusb->usb_dev;
363 dev_dbg(&usb_dev->dev, "atusb_xmit (%d)\n", skb->len);
366 atusb->tx_dr.wIndex = cpu_to_le16(atusb->tx_ack_seq);
367 atusb->tx_dr.wLength = cpu_to_le16(skb->len);
369 usb_fill_control_urb(atusb->tx_urb, usb_dev,
370 usb_sndctrlpipe(usb_dev, 0),
371 (unsigned char *)&atusb->tx_dr, skb->data,
372 skb->len, atusb_xmit_complete, NULL);
373 ret = usb_submit_urb(atusb->tx_urb, GFP_ATOMIC);
374 dev_dbg(&usb_dev->dev, "atusb_xmit done (%d)\n", ret);
378 static int atusb_channel(struct ieee802154_hw *hw, u8 page, u8 channel)
380 struct atusb *atusb = hw->priv;
383 ret = atusb_write_subreg(atusb, SR_CHANNEL, channel);
386 msleep(1); /* @@@ ugly synchronization */
390 static int atusb_ed(struct ieee802154_hw *hw, u8 *level)
397 static int atusb_set_hw_addr_filt(struct ieee802154_hw *hw,
398 struct ieee802154_hw_addr_filt *filt,
399 unsigned long changed)
401 struct atusb *atusb = hw->priv;
402 struct device *dev = &atusb->usb_dev->dev;
404 if (changed & IEEE802154_AFILT_SADDR_CHANGED) {
405 u16 addr = le16_to_cpu(filt->short_addr);
407 dev_vdbg(dev, "atusb_set_hw_addr_filt called for saddr\n");
408 atusb_write_reg(atusb, RG_SHORT_ADDR_0, addr);
409 atusb_write_reg(atusb, RG_SHORT_ADDR_1, addr >> 8);
412 if (changed & IEEE802154_AFILT_PANID_CHANGED) {
413 u16 pan = le16_to_cpu(filt->pan_id);
415 dev_vdbg(dev, "atusb_set_hw_addr_filt called for pan id\n");
416 atusb_write_reg(atusb, RG_PAN_ID_0, pan);
417 atusb_write_reg(atusb, RG_PAN_ID_1, pan >> 8);
420 if (changed & IEEE802154_AFILT_IEEEADDR_CHANGED) {
421 u8 i, addr[IEEE802154_EXTENDED_ADDR_LEN];
423 memcpy(addr, &filt->ieee_addr, IEEE802154_EXTENDED_ADDR_LEN);
424 dev_vdbg(dev, "atusb_set_hw_addr_filt called for IEEE addr\n");
425 for (i = 0; i < 8; i++)
426 atusb_write_reg(atusb, RG_IEEE_ADDR_0 + i, addr[i]);
429 if (changed & IEEE802154_AFILT_PANC_CHANGED) {
431 "atusb_set_hw_addr_filt called for panc change\n");
433 atusb_write_subreg(atusb, SR_AACK_I_AM_COORD, 1);
435 atusb_write_subreg(atusb, SR_AACK_I_AM_COORD, 0);
438 return atusb_get_and_clear_error(atusb);
441 static int atusb_start(struct ieee802154_hw *hw)
443 struct atusb *atusb = hw->priv;
444 struct usb_device *usb_dev = atusb->usb_dev;
447 dev_dbg(&usb_dev->dev, "atusb_start\n");
448 schedule_delayed_work(&atusb->work, 0);
449 atusb_command(atusb, ATUSB_RX_MODE, 1);
450 ret = atusb_get_and_clear_error(atusb);
452 usb_kill_anchored_urbs(&atusb->idle_urbs);
456 static void atusb_stop(struct ieee802154_hw *hw)
458 struct atusb *atusb = hw->priv;
459 struct usb_device *usb_dev = atusb->usb_dev;
461 dev_dbg(&usb_dev->dev, "atusb_stop\n");
462 usb_kill_anchored_urbs(&atusb->idle_urbs);
463 atusb_command(atusb, ATUSB_RX_MODE, 0);
464 atusb_get_and_clear_error(atusb);
467 #define ATUSB_MAX_TX_POWERS 0xF
468 static const s32 atusb_powers[ATUSB_MAX_TX_POWERS + 1] = {
469 300, 280, 230, 180, 130, 70, 0, -100, -200, -300, -400, -500, -700,
474 atusb_set_txpower(struct ieee802154_hw *hw, s32 mbm)
476 struct atusb *atusb = hw->priv;
479 for (i = 0; i < hw->phy->supported.tx_powers_size; i++) {
480 if (hw->phy->supported.tx_powers[i] == mbm)
481 return atusb_write_subreg(atusb, SR_TX_PWR_23X, i);
487 #define ATUSB_MAX_ED_LEVELS 0xF
488 static const s32 atusb_ed_levels[ATUSB_MAX_ED_LEVELS + 1] = {
489 -9100, -8900, -8700, -8500, -8300, -8100, -7900, -7700, -7500, -7300,
490 -7100, -6900, -6700, -6500, -6300, -6100,
494 atusb_set_cca_mode(struct ieee802154_hw *hw, const struct wpan_phy_cca *cca)
496 struct atusb *atusb = hw->priv;
499 /* mapping 802.15.4 to driver spec */
501 case NL802154_CCA_ENERGY:
504 case NL802154_CCA_CARRIER:
507 case NL802154_CCA_ENERGY_CARRIER:
509 case NL802154_CCA_OPT_ENERGY_CARRIER_AND:
512 case NL802154_CCA_OPT_ENERGY_CARRIER_OR:
523 return atusb_write_subreg(atusb, SR_CCA_MODE, val);
527 atusb_set_cca_ed_level(struct ieee802154_hw *hw, s32 mbm)
529 struct atusb *atusb = hw->priv;
532 for (i = 0; i < hw->phy->supported.cca_ed_levels_size; i++) {
533 if (hw->phy->supported.cca_ed_levels[i] == mbm)
534 return atusb_write_subreg(atusb, SR_CCA_ED_THRES, i);
541 atusb_set_csma_params(struct ieee802154_hw *hw, u8 min_be, u8 max_be, u8 retries)
543 struct atusb *atusb = hw->priv;
546 ret = atusb_write_subreg(atusb, SR_MIN_BE, min_be);
550 ret = atusb_write_subreg(atusb, SR_MAX_BE, max_be);
554 return atusb_write_subreg(atusb, SR_MAX_CSMA_RETRIES, retries);
558 atusb_set_promiscuous_mode(struct ieee802154_hw *hw, const bool on)
560 struct atusb *atusb = hw->priv;
564 ret = atusb_write_subreg(atusb, SR_AACK_DIS_ACK, 1);
568 ret = atusb_write_subreg(atusb, SR_AACK_PROM_MODE, 1);
572 ret = atusb_write_subreg(atusb, SR_AACK_PROM_MODE, 0);
576 ret = atusb_write_subreg(atusb, SR_AACK_DIS_ACK, 0);
584 static struct ieee802154_ops atusb_ops = {
585 .owner = THIS_MODULE,
586 .xmit_async = atusb_xmit,
588 .set_channel = atusb_channel,
589 .start = atusb_start,
591 .set_hw_addr_filt = atusb_set_hw_addr_filt,
592 .set_txpower = atusb_set_txpower,
593 .set_cca_mode = atusb_set_cca_mode,
594 .set_cca_ed_level = atusb_set_cca_ed_level,
595 .set_csma_params = atusb_set_csma_params,
596 .set_promiscuous_mode = atusb_set_promiscuous_mode,
599 /* ----- Firmware and chip version information ----------------------------- */
601 static int atusb_get_and_show_revision(struct atusb *atusb)
603 struct usb_device *usb_dev = atusb->usb_dev;
604 unsigned char *buffer;
607 buffer = kmalloc(3, GFP_KERNEL);
611 /* Get a couple of the ATMega Firmware values */
612 ret = atusb_control_msg(atusb, usb_rcvctrlpipe(usb_dev, 0),
613 ATUSB_ID, ATUSB_REQ_FROM_DEV, 0, 0,
616 dev_info(&usb_dev->dev,
617 "Firmware: major: %u, minor: %u, hardware type: %u\n",
618 buffer[0], buffer[1], buffer[2]);
619 if (buffer[0] == 0 && buffer[1] < 2) {
620 dev_info(&usb_dev->dev,
621 "Firmware version (%u.%u) is predates our first public release.",
622 buffer[0], buffer[1]);
623 dev_info(&usb_dev->dev, "Please update to version 0.2 or newer");
630 static int atusb_get_and_show_build(struct atusb *atusb)
632 struct usb_device *usb_dev = atusb->usb_dev;
636 build = kmalloc(ATUSB_BUILD_SIZE + 1, GFP_KERNEL);
640 ret = atusb_control_msg(atusb, usb_rcvctrlpipe(usb_dev, 0),
641 ATUSB_BUILD, ATUSB_REQ_FROM_DEV, 0, 0,
642 build, ATUSB_BUILD_SIZE, 1000);
645 dev_info(&usb_dev->dev, "Firmware: build %s\n", build);
652 static int atusb_get_and_show_chip(struct atusb *atusb)
654 struct usb_device *usb_dev = atusb->usb_dev;
655 uint8_t man_id_0, man_id_1, part_num, version_num;
658 man_id_0 = atusb_read_reg(atusb, RG_MAN_ID_0);
659 man_id_1 = atusb_read_reg(atusb, RG_MAN_ID_1);
660 part_num = atusb_read_reg(atusb, RG_PART_NUM);
661 version_num = atusb_read_reg(atusb, RG_VERSION_NUM);
666 if ((man_id_1 << 8 | man_id_0) != ATUSB_JEDEC_ATMEL) {
667 dev_err(&usb_dev->dev,
668 "non-Atmel transceiver xxxx%02x%02x\n",
681 dev_err(&usb_dev->dev,
682 "unexpected transceiver, part 0x%02x version 0x%02x\n",
683 part_num, version_num);
687 dev_info(&usb_dev->dev, "ATUSB: %s version %d\n", chip, version_num);
692 atusb->err = -ENODEV;
696 /* ----- Setup ------------------------------------------------------------- */
698 static int atusb_probe(struct usb_interface *interface,
699 const struct usb_device_id *id)
701 struct usb_device *usb_dev = interface_to_usbdev(interface);
702 struct ieee802154_hw *hw;
703 struct atusb *atusb = NULL;
706 hw = ieee802154_alloc_hw(sizeof(struct atusb), &atusb_ops);
712 atusb->usb_dev = usb_get_dev(usb_dev);
713 usb_set_intfdata(interface, atusb);
717 INIT_DELAYED_WORK(&atusb->work, atusb_work_urbs);
718 init_usb_anchor(&atusb->idle_urbs);
719 init_usb_anchor(&atusb->rx_urbs);
721 if (atusb_alloc_urbs(atusb, ATUSB_NUM_RX_URBS))
724 atusb->tx_dr.bRequestType = ATUSB_REQ_TO_DEV;
725 atusb->tx_dr.bRequest = ATUSB_TX;
726 atusb->tx_dr.wValue = cpu_to_le16(0);
728 atusb->tx_urb = usb_alloc_urb(0, GFP_ATOMIC);
732 hw->parent = &usb_dev->dev;
733 hw->flags = IEEE802154_HW_TX_OMIT_CKSUM | IEEE802154_HW_AFILT |
734 IEEE802154_HW_PROMISCUOUS | IEEE802154_HW_CSMA_PARAMS;
736 hw->phy->flags = WPAN_PHY_FLAG_TXPOWER | WPAN_PHY_FLAG_CCA_ED_LEVEL |
737 WPAN_PHY_FLAG_CCA_MODE;
739 hw->phy->supported.cca_modes = BIT(NL802154_CCA_ENERGY) |
740 BIT(NL802154_CCA_CARRIER) | BIT(NL802154_CCA_ENERGY_CARRIER);
741 hw->phy->supported.cca_opts = BIT(NL802154_CCA_OPT_ENERGY_CARRIER_AND) |
742 BIT(NL802154_CCA_OPT_ENERGY_CARRIER_OR);
744 hw->phy->supported.cca_ed_levels = atusb_ed_levels;
745 hw->phy->supported.cca_ed_levels_size = ARRAY_SIZE(atusb_ed_levels);
747 hw->phy->cca.mode = NL802154_CCA_ENERGY;
749 hw->phy->current_page = 0;
750 hw->phy->current_channel = 11; /* reset default */
751 hw->phy->supported.channels[0] = 0x7FFF800;
752 hw->phy->supported.tx_powers = atusb_powers;
753 hw->phy->supported.tx_powers_size = ARRAY_SIZE(atusb_powers);
754 hw->phy->transmit_power = hw->phy->supported.tx_powers[0];
755 ieee802154_random_extended_addr(&hw->phy->perm_extended_addr);
756 hw->phy->cca_ed_level = hw->phy->supported.cca_ed_levels[7];
758 atusb_command(atusb, ATUSB_RF_RESET, 0);
759 atusb_get_and_show_chip(atusb);
760 atusb_get_and_show_revision(atusb);
761 atusb_get_and_show_build(atusb);
762 ret = atusb_get_and_clear_error(atusb);
764 dev_err(&atusb->usb_dev->dev,
765 "%s: initialization failed, error = %d\n",
770 ret = ieee802154_register_hw(hw);
774 /* If we just powered on, we're now in P_ON and need to enter TRX_OFF
775 * explicitly. Any resets after that will send us straight to TRX_OFF,
776 * making the command below redundant.
778 atusb_write_reg(atusb, RG_TRX_STATE, STATE_FORCE_TRX_OFF);
779 msleep(1); /* reset => TRX_OFF, tTR13 = 37 us */
782 /* Calculating the maximum time available to empty the frame buffer
785 * According to [1], the inter-frame gap is
786 * R * 20 * 16 us + 128 us
787 * where R is a random number from 0 to 7. Furthermore, we have 20 bit
788 * times (80 us at 250 kbps) of SHR of the next frame before the
789 * transceiver begins storing data in the frame buffer.
791 * This yields a minimum time of 208 us between the last data of a
792 * frame and the first data of the next frame. This time is further
793 * reduced by interrupt latency in the atusb firmware.
795 * atusb currently needs about 500 us to retrieve a maximum-sized
796 * frame. We therefore have to allow reception of a new frame to begin
797 * while we retrieve the previous frame.
799 * [1] "JN-AN-1035 Calculating data rates in an IEEE 802.15.4-based
800 * network", Jennic 2006.
801 * http://www.jennic.com/download_file.php?supportFile=JN-AN-1035%20Calculating%20802-15-4%20Data%20Rates-1v0.pdf
804 atusb_write_subreg(atusb, SR_RX_SAFE_MODE, 1);
806 atusb_write_reg(atusb, RG_IRQ_MASK, 0xff);
808 ret = atusb_get_and_clear_error(atusb);
812 dev_err(&atusb->usb_dev->dev,
813 "%s: setup failed, error = %d\n",
816 ieee802154_unregister_hw(hw);
818 atusb_free_urbs(atusb);
819 usb_kill_urb(atusb->tx_urb);
820 usb_free_urb(atusb->tx_urb);
821 usb_put_dev(usb_dev);
822 ieee802154_free_hw(hw);
826 static void atusb_disconnect(struct usb_interface *interface)
828 struct atusb *atusb = usb_get_intfdata(interface);
830 dev_dbg(&atusb->usb_dev->dev, "atusb_disconnect\n");
833 cancel_delayed_work_sync(&atusb->work);
835 usb_kill_anchored_urbs(&atusb->rx_urbs);
836 atusb_free_urbs(atusb);
837 usb_kill_urb(atusb->tx_urb);
838 usb_free_urb(atusb->tx_urb);
840 ieee802154_unregister_hw(atusb->hw);
842 usb_put_dev(atusb->usb_dev);
844 ieee802154_free_hw(atusb->hw);
846 usb_set_intfdata(interface, NULL);
848 pr_debug("atusb_disconnect done\n");
851 /* The devices we work with */
852 static const struct usb_device_id atusb_device_table[] = {
854 .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
855 USB_DEVICE_ID_MATCH_INT_INFO,
856 .idVendor = ATUSB_VENDOR_ID,
857 .idProduct = ATUSB_PRODUCT_ID,
858 .bInterfaceClass = USB_CLASS_VENDOR_SPEC
860 /* end with null element */
863 MODULE_DEVICE_TABLE(usb, atusb_device_table);
865 static struct usb_driver atusb_driver = {
867 .probe = atusb_probe,
868 .disconnect = atusb_disconnect,
869 .id_table = atusb_device_table,
871 module_usb_driver(atusb_driver);
873 MODULE_AUTHOR("Alexander Aring <alex.aring@gmail.com>");
874 MODULE_AUTHOR("Richard Sharpe <realrichardsharpe@gmail.com>");
875 MODULE_AUTHOR("Stefan Schmidt <stefan@datenfreihafen.org>");
876 MODULE_AUTHOR("Werner Almesberger <werner@almesberger.net>");
877 MODULE_DESCRIPTION("ATUSB IEEE 802.15.4 Driver");
878 MODULE_LICENSE("GPL");