2 * Copyright (c) 2003, 2004
3 * Damien Bergamini <damien.bergamini@free.fr>. All rights reserved.
5 * Copyright (c) 2005 Matthieu Castet <castet.matthieu@free.fr>
7 * This software is available to you under a choice of one of two
8 * licenses. You may choose to be licensed under the terms of the GNU
9 * General Public License (GPL) Version 2, available from the file
10 * COPYING in the main directory of this source tree, or the
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice unmodified, this list of conditions, and the following
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * This program is free software; you can redistribute it and/or
37 * modify it under the terms of the GNU General Public License
38 * as published by the Free Software Foundation; either version 2
39 * of the License, or (at your option) any later version.
41 * This program is distributed in the hope that it will be useful,
42 * but WITHOUT ANY WARRANTY; without even the implied warranty of
43 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44 * GNU General Public License for more details.
46 * You should have received a copy of the GNU General Public License
47 * along with this program; if not, write to the Free Software
48 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
51 * HISTORY : some part of the code was base on ueagle 1.3 BSD driver,
52 * Damien Bergamini agree to put his code under a DUAL GPL/BSD license.
54 * The rest of the code was was rewritten from scratch.
57 #include <linux/module.h>
58 #include <linux/moduleparam.h>
59 #include <linux/init.h>
60 #include <linux/crc32.h>
61 #include <linux/usb.h>
62 #include <linux/firmware.h>
63 #include <linux/ctype.h>
64 #include <linux/kthread.h>
65 #include <linux/version.h>
66 #include <asm/unaligned.h>
70 #define EAGLEUSBVERSION "ueagle 1.1"
76 #define uea_dbg(usb_dev, format, args...) \
79 dev_dbg(&(usb_dev)->dev, \
80 "[ueagle-atm dbg] %s: " format, \
81 __FUNCTION__, ##args); \
84 #define uea_vdbg(usb_dev, format, args...) \
87 dev_dbg(&(usb_dev)->dev, \
88 "[ueagle-atm vdbg] " format, ##args); \
91 #define uea_enters(usb_dev) \
92 uea_vdbg(usb_dev, "entering %s\n", __FUNCTION__)
94 #define uea_leaves(usb_dev) \
95 uea_vdbg(usb_dev, "leaving %s\n", __FUNCTION__)
97 #define uea_err(usb_dev, format,args...) \
98 dev_err(&(usb_dev)->dev ,"[UEAGLE-ATM] " format , ##args)
100 #define uea_warn(usb_dev, format,args...) \
101 dev_warn(&(usb_dev)->dev ,"[Ueagle-atm] " format, ##args)
103 #define uea_info(usb_dev, format,args...) \
104 dev_info(&(usb_dev)->dev ,"[ueagle-atm] " format, ##args)
110 } __attribute__ ((packed));
113 struct usb_device *usb_dev;
114 struct usbatm_data *usbatm;
117 unsigned int driver_info;
122 wait_queue_head_t sync_q;
124 struct task_struct *kthread;
126 wait_queue_head_t cmv_ack_wait;
129 struct work_struct task;
133 const struct firmware *dsp_firm;
141 /* keep in sync with eaglectl */
169 #define ELSA_VID 0x05CC
170 #define ELSA_PID_PSTFIRM 0x3350
171 #define ELSA_PID_PREFIRM 0x3351
176 #define EAGLE_VID 0x1110
177 #define EAGLE_I_PID_PREFIRM 0x9010 /* Eagle I */
178 #define EAGLE_I_PID_PSTFIRM 0x900F /* Eagle I */
180 #define EAGLE_IIC_PID_PREFIRM 0x9024 /* Eagle IIC */
181 #define EAGLE_IIC_PID_PSTFIRM 0x9023 /* Eagle IIC */
183 #define EAGLE_II_PID_PREFIRM 0x9022 /* Eagle II */
184 #define EAGLE_II_PID_PSTFIRM 0x9021 /* Eagle II */
189 #define EAGLE_III_PID_PREFIRM 0x9032 /* Eagle III */
190 #define EAGLE_III_PID_PSTFIRM 0x9031 /* Eagle III */
195 #define USR_VID 0x0BAF
196 #define MILLER_A_PID_PREFIRM 0x00F2
197 #define MILLER_A_PID_PSTFIRM 0x00F1
198 #define MILLER_B_PID_PREFIRM 0x00FA
199 #define MILLER_B_PID_PSTFIRM 0x00F9
200 #define HEINEKEN_A_PID_PREFIRM 0x00F6
201 #define HEINEKEN_A_PID_PSTFIRM 0x00F5
202 #define HEINEKEN_B_PID_PREFIRM 0x00F8
203 #define HEINEKEN_B_PID_PSTFIRM 0x00F7
206 #define PSTFIRM (1<<7)
214 /* macros for both struct usb_device_id and struct uea_softc */
215 #define UEA_IS_PREFIRM(x) \
216 (!((x)->driver_info & PSTFIRM))
217 #define UEA_CHIP_VERSION(x) \
218 ((x)->driver_info & 0xf)
220 #define IS_ISDN(sc) \
221 (le16_to_cpu(sc->usb_dev->descriptor.bcdDevice) & 0x80)
223 #define INS_TO_USBDEV(ins) ins->usb_dev
225 #define GET_STATUS(data) \
227 #define IS_OPERATIONAL(sc) \
228 (GET_STATUS(sc->stats.phy.state) == 2)
231 * Set of macros to handle unaligned data in the firmware blob.
232 * The FW_GET_BYTE() macro is provided only for consistency.
235 #define FW_GET_BYTE(p) *((__u8 *) (p))
236 #define FW_GET_WORD(p) le16_to_cpu(get_unaligned((__le16 *) (p)))
237 #define FW_GET_LONG(p) le32_to_cpu(get_unaligned((__le32 *) (p)))
239 #define FW_DIR "ueagle-atm/"
242 #define BULK_TIMEOUT 300
243 #define CTRL_TIMEOUT 1000
245 #define ACK_TIMEOUT msecs_to_jiffies(1500)
247 #define UEA_INTR_IFACE_NO 0
248 #define UEA_US_IFACE_NO 1
249 #define UEA_DS_IFACE_NO 2
251 #define FASTEST_ISO_INTF 8
253 #define UEA_BULK_DATA_PIPE 0x02
254 #define UEA_IDMA_PIPE 0x04
255 #define UEA_INTR_PIPE 0x04
256 #define UEA_ISO_DATA_PIPE 0x08
258 #define UEA_SET_BLOCK 0x0001
259 #define UEA_SET_MODE 0x0003
260 #define UEA_SET_2183_DATA 0x0004
261 #define UEA_SET_TIMEOUT 0x0011
263 #define UEA_LOOPBACK_OFF 0x0002
264 #define UEA_LOOPBACK_ON 0x0003
265 #define UEA_BOOT_IDMA 0x0006
266 #define UEA_START_RESET 0x0007
267 #define UEA_END_RESET 0x0008
269 #define UEA_SWAP_MAILBOX (0x3fcd | 0x4000)
270 #define UEA_MPTX_START (0x3fce | 0x4000)
271 #define UEA_MPTX_MAILBOX (0x3fd6 | 0x4000)
272 #define UEA_MPRX_MAILBOX (0x3fdf | 0x4000)
274 /* structure describing a block within a DSP page */
277 #define UEA_BIHDR 0xabcd
281 __le16 wOvl; /* overlay */
283 } __attribute__ ((packed));
284 #define BLOCK_INFO_SIZE 12
286 /* structure representing a CMV (Configuration and Management Variable) */
289 #define PREAMBLE 0x535c
291 #define MODEMTOHOST 0x01
292 #define HOSTTOMODEM 0x10
294 #define FUNCTION_TYPE(f) ((f) >> 4)
295 #define MEMACCESS 0x1
296 #define ADSLDIRECTIVE 0x7
298 #define FUNCTION_SUBTYPE(f) ((f) & 0x0f)
300 #define REQUESTREAD 0x0
301 #define REQUESTWRITE 0x1
302 #define REPLYREAD 0x2
303 #define REPLYWRITE 0x3
304 /* for ADSLDIRECTIVE */
305 #define KERNELREADY 0x0
306 #define MODEMREADY 0x1
308 #define MAKEFUNCTION(t, s) (((t) & 0xf) << 4 | ((s) & 0xf))
310 __le32 dwSymbolicAddress;
311 #define MAKESA(a, b, c, d) \
312 (((c) & 0xff) << 24 | \
313 ((d) & 0xff) << 16 | \
314 ((a) & 0xff) << 8 | \
317 #define SA_CNTL MAKESA('C', 'N', 'T', 'L')
318 #define SA_DIAG MAKESA('D', 'I', 'A', 'G')
319 #define SA_INFO MAKESA('I', 'N', 'F', 'O')
320 #define SA_OPTN MAKESA('O', 'P', 'T', 'N')
321 #define SA_RATE MAKESA('R', 'A', 'T', 'E')
322 #define SA_STAT MAKESA('S', 'T', 'A', 'T')
323 __le16 wOffsetAddress;
325 } __attribute__ ((packed));
328 /* structure representing swap information */
331 __u8 bOvl; /* overlay */
332 } __attribute__ ((packed));
334 /* structure representing interrupt data */
342 #define INT_LOADSWAPPAGE 0x0001
343 #define INT_INCOMINGCMV 0x0002
346 struct swap_info swapinfo;
348 } __attribute__ ((packed)) s1;
353 } __attribute__ ((packed)) s2;
354 } __attribute__ ((packed)) u;
355 #define bSwapPageNo u.s1.swapinfo.bSwapPageNo
356 #define bOvl u.s1.swapinfo.bOvl
357 } __attribute__ ((packed));
358 #define INTR_PKT_SIZE 28
360 static struct usb_driver uea_driver;
361 static DECLARE_MUTEX(uea_semaphore);
362 static const char *chip_name[] = {"ADI930", "Eagle I", "Eagle II", "Eagle III"};
364 static int modem_index;
365 static unsigned int debug;
366 static int sync_wait[NB_MODEM];
367 static char *cmv_file[NB_MODEM];
369 module_param(debug, uint, 0644);
370 MODULE_PARM_DESC(debug, "module debug level (0=off,1=on,2=verbose)");
371 module_param_array(sync_wait, bool, NULL, 0644);
372 MODULE_PARM_DESC(sync_wait, "wait the synchronisation before starting ATM");
373 module_param_array(cmv_file, charp, NULL, 0644);
374 MODULE_PARM_DESC(cmv_file,
375 "file name with configuration and management variables");
377 #define UPDATE_ATM_STAT(type, val) \
379 if (sc->usbatm->atm_dev) \
380 sc->usbatm->atm_dev->type = val; \
383 /* Firmware loading */
384 #define LOAD_INTERNAL 0xA0
385 #define F8051_USBCS 0x7f92
388 * uea_send_modem_cmd - Send a command for pre-firmware devices.
390 static int uea_send_modem_cmd(struct usb_device *usb,
391 u16 addr, u16 size, u8 * buff)
396 xfer_buff = kmalloc(size, GFP_KERNEL);
398 memcpy(xfer_buff, buff, size);
399 ret = usb_control_msg(usb,
400 usb_sndctrlpipe(usb, 0),
402 USB_DIR_OUT | USB_TYPE_VENDOR |
403 USB_RECIP_DEVICE, addr, 0, xfer_buff,
411 return (ret == size) ? 0 : -EIO;
414 static void uea_upload_pre_firmware(const struct firmware *fw_entry, void *context)
416 struct usb_device *usb = context;
423 uea_err(usb, "firmware is not available\n");
427 pfw = fw_entry->data;
428 size = fw_entry->size;
430 goto err_fw_corrupted;
432 crc = FW_GET_LONG(pfw);
435 if (crc32_be(0, pfw, size) != crc)
436 goto err_fw_corrupted;
439 * Start to upload formware : send reset
442 ret = uea_send_modem_cmd(usb, F8051_USBCS, sizeof(value), &value);
445 uea_err(usb, "modem reset failed with error %d\n", ret);
450 u8 len = FW_GET_BYTE(pfw);
451 u16 add = FW_GET_WORD(pfw + 1);
455 goto err_fw_corrupted;
457 ret = uea_send_modem_cmd(usb, add, len, pfw + 3);
459 uea_err(usb, "uploading firmware data failed "
460 "with error %d\n", ret);
467 goto err_fw_corrupted;
470 * Tell the modem we finish : de-assert reset
473 ret = uea_send_modem_cmd(usb, F8051_USBCS, 1, &value);
475 uea_err(usb, "modem de-assert failed with error %d\n", ret);
477 uea_info(usb, "firmware uploaded\n");
483 uea_err(usb, "firmware is corrupted\n");
489 * uea_load_firmware - Load usb firmware for pre-firmware devices.
491 static int uea_load_firmware(struct usb_device *usb, unsigned int ver)
494 char *fw_name = FW_DIR "eagle.fw";
497 uea_info(usb, "pre-firmware device, uploading firmware\n");
501 fw_name = FW_DIR "adi930.fw";
504 fw_name = FW_DIR "eagleI.fw";
507 fw_name = FW_DIR "eagleII.fw";
510 fw_name = FW_DIR "eagleIII.fw";
514 ret = request_firmware_nowait(THIS_MODULE, 1, fw_name, &usb->dev, usb, uea_upload_pre_firmware);
516 uea_err(usb, "firmware %s is not available\n", fw_name);
518 uea_info(usb, "loading firmware %s\n", fw_name);
524 /* modem management : dsp firmware, send/read CMV, monitoring statistic
528 * Make sure that the DSP code provided is safe to use.
530 static int check_dsp(u8 *dsp, unsigned int len)
532 u8 pagecount, blockcount;
535 unsigned int i, j, p, pp;
537 pagecount = FW_GET_BYTE(dsp);
540 /* enough space for page offsets? */
541 if (p + 4 * pagecount > len)
544 for (i = 0; i < pagecount; i++) {
546 pageoffset = FW_GET_LONG(dsp + p);
552 /* enough space for blockcount? */
553 if (pageoffset >= len)
557 blockcount = FW_GET_BYTE(dsp + pp);
560 for (j = 0; j < blockcount; j++) {
562 /* enough space for block header? */
566 pp += 2; /* skip blockaddr */
567 blocksize = FW_GET_WORD(dsp + pp);
570 /* enough space for block data? */
571 if (pp + blocksize > len)
582 * send data to the idma pipe
584 static int uea_idma_write(struct uea_softc *sc, void *data, u32 size)
590 xfer_buff = kmalloc(size, GFP_KERNEL);
592 uea_err(INS_TO_USBDEV(sc), "can't allocate xfer_buff\n");
596 memcpy(xfer_buff, data, size);
598 ret = usb_bulk_msg(sc->usb_dev,
599 usb_sndbulkpipe(sc->usb_dev, UEA_IDMA_PIPE),
600 xfer_buff, size, &bytes_read, BULK_TIMEOUT);
605 if (size != bytes_read) {
606 uea_err(INS_TO_USBDEV(sc), "size != bytes_read %d %d\n", size,
614 static int request_dsp(struct uea_softc *sc)
619 if (UEA_CHIP_VERSION(sc) == ADI930) {
621 dsp_name = FW_DIR "DSP9i.bin";
623 dsp_name = FW_DIR "DSP9p.bin";
626 dsp_name = FW_DIR "DSPei.bin";
628 dsp_name = FW_DIR "DSPep.bin";
631 ret = request_firmware(&sc->dsp_firm,
632 dsp_name, &sc->usb_dev->dev);
634 uea_err(INS_TO_USBDEV(sc),
635 "requesting firmware %s failed with error %d\n",
640 if (check_dsp(sc->dsp_firm->data, sc->dsp_firm->size)) {
641 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n",
643 release_firmware(sc->dsp_firm);
652 * The uea_load_page() function must be called within a process context
654 static void uea_load_page(void *xsc)
656 struct uea_softc *sc = xsc;
657 u16 pageno = sc->pageno;
659 struct block_info bi;
662 u8 pagecount, blockcount;
663 u16 blockaddr, blocksize;
667 /* reload firmware when reboot start and it's loaded already */
668 if (ovl == 0 && pageno == 0 && sc->dsp_firm) {
669 release_firmware(sc->dsp_firm);
673 if (sc->dsp_firm == NULL && request_dsp(sc) < 0)
676 p = sc->dsp_firm->data;
677 pagecount = FW_GET_BYTE(p);
680 if (pageno >= pagecount)
684 pageoffset = FW_GET_LONG(p);
689 p = sc->dsp_firm->data + pageoffset;
690 blockcount = FW_GET_BYTE(p);
693 uea_dbg(INS_TO_USBDEV(sc),
694 "sending %u blocks for DSP page %u\n", blockcount, pageno);
696 bi.wHdr = cpu_to_le16(UEA_BIHDR);
697 bi.wOvl = cpu_to_le16(ovl);
698 bi.wOvlOffset = cpu_to_le16(ovl | 0x8000);
700 for (i = 0; i < blockcount; i++) {
701 blockaddr = FW_GET_WORD(p);
704 blocksize = FW_GET_WORD(p);
707 bi.wSize = cpu_to_le16(blocksize);
708 bi.wAddress = cpu_to_le16(blockaddr);
709 bi.wLast = cpu_to_le16((i == blockcount - 1) ? 1 : 0);
711 /* send block info through the IDMA pipe */
712 if (uea_idma_write(sc, &bi, BLOCK_INFO_SIZE))
715 /* send block data through the IDMA pipe */
716 if (uea_idma_write(sc, p, blocksize))
725 uea_err(INS_TO_USBDEV(sc), "sending DSP block %u failed\n", i);
728 uea_err(INS_TO_USBDEV(sc), "invalid DSP page %u requested\n",pageno);
731 static inline void wake_up_cmv_ack(struct uea_softc *sc)
734 wake_up(&sc->cmv_ack_wait);
737 static inline int wait_cmv_ack(struct uea_softc *sc)
739 int ret = wait_event_timeout(sc->cmv_ack_wait,
740 sc->cmv_ack, ACK_TIMEOUT);
746 return (ret == 0) ? -ETIMEDOUT : 0;
750 #define UCDC_SEND_ENCAPSULATED_COMMAND 0x00
752 static int uea_request(struct uea_softc *sc,
753 u16 value, u16 index, u16 size, void *data)
758 xfer_buff = kmalloc(size, GFP_KERNEL);
760 uea_err(INS_TO_USBDEV(sc), "can't allocate xfer_buff\n");
763 memcpy(xfer_buff, data, size);
765 ret = usb_control_msg(sc->usb_dev, usb_sndctrlpipe(sc->usb_dev, 0),
766 UCDC_SEND_ENCAPSULATED_COMMAND,
767 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
768 value, index, xfer_buff, size, CTRL_TIMEOUT);
772 uea_err(INS_TO_USBDEV(sc), "usb_control_msg error %d\n", ret);
777 uea_err(INS_TO_USBDEV(sc),
778 "usb_control_msg send only %d bytes (instead of %d)\n",
786 static int uea_cmv(struct uea_softc *sc,
787 u8 function, u32 address, u16 offset, u32 data)
792 /* we send a request, but we expect a reply */
793 sc->cmv_function = function | 0x2;
795 sc->cmv_address = address;
796 sc->cmv_offset = offset;
798 cmv.wPreamble = cpu_to_le16(PREAMBLE);
799 cmv.bDirection = HOSTTOMODEM;
800 cmv.bFunction = function;
801 cmv.wIndex = cpu_to_le16(sc->cmv_idx);
802 put_unaligned(cpu_to_le32(address), &cmv.dwSymbolicAddress);
803 cmv.wOffsetAddress = cpu_to_le16(offset);
804 put_unaligned(cpu_to_le32(data >> 16 | data << 16), &cmv.dwData);
806 ret = uea_request(sc, UEA_SET_BLOCK, UEA_MPTX_START, CMV_SIZE, &cmv);
809 return wait_cmv_ack(sc);
812 static inline int uea_read_cmv(struct uea_softc *sc,
813 u32 address, u16 offset, u32 *data)
815 int ret = uea_cmv(sc, MAKEFUNCTION(MEMACCESS, REQUESTREAD),
818 uea_err(INS_TO_USBDEV(sc),
819 "reading cmv failed with error %d\n", ret);
826 static inline int uea_write_cmv(struct uea_softc *sc,
827 u32 address, u16 offset, u32 data)
829 int ret = uea_cmv(sc, MAKEFUNCTION(MEMACCESS, REQUESTWRITE),
830 address, offset, data);
832 uea_err(INS_TO_USBDEV(sc),
833 "writing cmv failed with error %d\n", ret);
839 * Monitor the modem and update the stat
840 * return 0 if everything is ok
841 * return < 0 if an error occurs (-EAGAIN reboot needed)
843 static int uea_stat(struct uea_softc *sc)
848 uea_enters(INS_TO_USBDEV(sc));
849 data = sc->stats.phy.state;
851 ret = uea_read_cmv(sc, SA_STAT, 0, &sc->stats.phy.state);
855 switch (GET_STATUS(sc->stats.phy.state)) {
856 case 0: /* not yet synchronized */
857 uea_dbg(INS_TO_USBDEV(sc),
858 "modem not yet synchronized\n");
861 case 1: /* initialization */
862 uea_dbg(INS_TO_USBDEV(sc), "modem initializing\n");
865 case 2: /* operational */
866 uea_vdbg(INS_TO_USBDEV(sc), "modem operational\n");
869 case 3: /* fail ... */
870 uea_info(INS_TO_USBDEV(sc), "modem synchronization failed\n");
873 case 4 ... 6: /* test state */
874 uea_warn(INS_TO_USBDEV(sc),
875 "modem in test mode - not supported\n");
878 case 7: /* fast-retain ... */
879 uea_info(INS_TO_USBDEV(sc), "modem in fast-retain mode\n");
882 uea_err(INS_TO_USBDEV(sc), "modem invalid SW mode %d\n",
883 GET_STATUS(sc->stats.phy.state));
887 if (GET_STATUS(data) != 2) {
888 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_OFF, 0, NULL);
889 uea_info(INS_TO_USBDEV(sc), "modem operational\n");
891 /* release the dsp firmware as it is not needed until
895 release_firmware(sc->dsp_firm);
899 ret = uea_read_cmv(sc, SA_INFO, 10, &sc->stats.phy.firmid);
902 uea_info(INS_TO_USBDEV(sc), "ATU-R firmware version : %x\n",
903 sc->stats.phy.firmid);
906 /* always update it as atm layer could not be init when we switch to
909 UPDATE_ATM_STAT(signal, ATM_PHY_SIG_FOUND);
911 /* wake up processes waiting for synchronization */
912 wake_up(&sc->sync_q);
914 ret = uea_read_cmv(sc, SA_DIAG, 2, &sc->stats.phy.flags);
917 sc->stats.phy.mflags |= sc->stats.phy.flags;
919 /* in case of a flags ( for example delineation LOSS (& 0x10)),
920 * we check the status again in order to detect the failure earlier
922 if (sc->stats.phy.flags) {
923 uea_dbg(INS_TO_USBDEV(sc), "Stat flag = %d\n",
924 sc->stats.phy.flags);
928 ret = uea_read_cmv(sc, SA_RATE, 0, &data);
932 /* in bulk mode the modem have problem with high rate
933 * changing internal timing could improve things, but the
934 * value is misterious.
935 * ADI930 don't support it (-EPIPE error).
937 if (UEA_CHIP_VERSION(sc) != ADI930
938 && sc->stats.phy.dsrate != (data >> 16) * 32) {
939 /* Original timming from ADI(used in windows driver)
940 * 0x20ffff>>16 * 32 = 32 * 32 = 1Mbits
942 u16 timeout = (data <= 0x20ffff) ? 0 : 1;
943 ret = uea_request(sc, UEA_SET_TIMEOUT, timeout, 0, NULL);
944 uea_info(INS_TO_USBDEV(sc),
945 "setting new timeout %d%s\n", timeout,
946 ret < 0?" failed":"");
948 sc->stats.phy.dsrate = (data >> 16) * 32;
949 sc->stats.phy.usrate = (data & 0xffff) * 32;
950 UPDATE_ATM_STAT(link_rate, sc->stats.phy.dsrate * 1000 / 424);
952 ret = uea_read_cmv(sc, SA_DIAG, 23, &data);
955 sc->stats.phy.dsattenuation = (data & 0xff) / 2;
957 ret = uea_read_cmv(sc, SA_DIAG, 47, &data);
960 sc->stats.phy.usattenuation = (data & 0xff) / 2;
962 ret = uea_read_cmv(sc, SA_DIAG, 25, &sc->stats.phy.dsmargin);
966 ret = uea_read_cmv(sc, SA_DIAG, 49, &sc->stats.phy.usmargin);
970 ret = uea_read_cmv(sc, SA_DIAG, 51, &sc->stats.phy.rxflow);
974 ret = uea_read_cmv(sc, SA_DIAG, 52, &sc->stats.phy.txflow);
978 ret = uea_read_cmv(sc, SA_DIAG, 54, &sc->stats.phy.dsunc);
983 ret = uea_read_cmv(sc, SA_DIAG, 58, &sc->stats.phy.usunc);
987 ret = uea_read_cmv(sc, SA_DIAG, 53, &sc->stats.phy.dscorr);
992 ret = uea_read_cmv(sc, SA_DIAG, 57, &sc->stats.phy.uscorr);
996 ret = uea_read_cmv(sc, SA_INFO, 8, &sc->stats.phy.vidco);
1000 ret = uea_read_cmv(sc, SA_INFO, 13, &sc->stats.phy.vidcpe);
1007 static int request_cmvs(struct uea_softc *sc,
1008 struct uea_cmvs **cmvs, const struct firmware **fw)
1013 static char cmv_name[256] = FW_DIR;
1015 if (cmv_file[sc->modem_index] == NULL) {
1016 if (UEA_CHIP_VERSION(sc) == ADI930)
1017 file = (IS_ISDN(sc)) ? "CMV9i.bin" : "CMV9p.bin";
1019 file = (IS_ISDN(sc)) ? "CMVei.bin" : "CMVep.bin";
1021 file = cmv_file[sc->modem_index];
1023 strcpy(cmv_name, FW_DIR);
1024 strlcat(cmv_name, file, sizeof(cmv_name));
1026 ret = request_firmware(fw, cmv_name, &sc->usb_dev->dev);
1028 uea_err(INS_TO_USBDEV(sc),
1029 "requesting firmware %s failed with error %d\n",
1034 data = (u8 *) (*fw)->data;
1035 size = *data * sizeof(struct uea_cmvs) + 1;
1036 if (size != (*fw)->size) {
1037 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n",
1039 release_firmware(*fw);
1043 *cmvs = (struct uea_cmvs *)(data + 1);
1047 /* Start boot post firmware modem:
1048 * - send reset commands through usb control pipe
1049 * - start workqueue for DSP loading
1050 * - send CMV options to modem
1053 static int uea_start_reset(struct uea_softc *sc)
1055 u16 zero = 0; /* ;-) */
1057 struct uea_cmvs *cmvs;
1058 const struct firmware *cmvs_fw;
1060 uea_enters(INS_TO_USBDEV(sc));
1061 uea_info(INS_TO_USBDEV(sc), "(re)booting started\n");
1064 UPDATE_ATM_STAT(signal, ATM_PHY_SIG_LOST);
1066 /* reset statistics */
1067 memset(&sc->stats, 0, sizeof(struct uea_stats));
1069 /* tell the modem that we want to boot in IDMA mode */
1070 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_ON, 0, NULL);
1071 uea_request(sc, UEA_SET_MODE, UEA_BOOT_IDMA, 0, NULL);
1073 /* enter reset mode */
1074 uea_request(sc, UEA_SET_MODE, UEA_START_RESET, 0, NULL);
1076 /* original driver use 200ms, but windows driver use 100ms */
1079 /* leave reset mode */
1080 uea_request(sc, UEA_SET_MODE, UEA_END_RESET, 0, NULL);
1082 /* clear tx and rx mailboxes */
1083 uea_request(sc, UEA_SET_2183_DATA, UEA_MPTX_MAILBOX, 2, &zero);
1084 uea_request(sc, UEA_SET_2183_DATA, UEA_MPRX_MAILBOX, 2, &zero);
1085 uea_request(sc, UEA_SET_2183_DATA, UEA_SWAP_MAILBOX, 2, &zero);
1088 sc->cmv_function = MAKEFUNCTION(ADSLDIRECTIVE, MODEMREADY);
1091 /* start loading DSP */
1094 schedule_work(&sc->task);
1096 /* wait for modem ready CMV */
1097 ret = wait_cmv_ack(sc);
1101 /* Enter in R-IDLE (cmv) until instructed otherwise */
1102 ret = uea_write_cmv(sc, SA_CNTL, 0, 1);
1107 ret = len = request_cmvs(sc, &cmvs, &cmvs_fw);
1112 for (i = 0; i < len; i++) {
1113 ret = uea_write_cmv(sc, FW_GET_LONG(&cmvs[i].address),
1114 FW_GET_WORD(&cmvs[i].offset),
1115 FW_GET_LONG(&cmvs[i].data));
1119 /* Enter in R-ACT-REQ */
1120 ret = uea_write_cmv(sc, SA_CNTL, 0, 2);
1122 release_firmware(cmvs_fw);
1124 uea_leaves(INS_TO_USBDEV(sc));
1129 * In case of an error wait 1s before rebooting the modem
1130 * if the modem don't request reboot (-EAGAIN).
1131 * Monitor the modem every 1s.
1134 static int uea_kthread(void *data)
1136 struct uea_softc *sc = data;
1139 uea_enters(INS_TO_USBDEV(sc));
1140 while (!kthread_should_stop()) {
1141 if (ret < 0 || sc->reset)
1142 ret = uea_start_reset(sc);
1148 uea_leaves(INS_TO_USBDEV(sc));
1152 /* Load second usb firmware for ADI930 chip */
1153 static int load_XILINX_firmware(struct uea_softc *sc)
1155 const struct firmware *fw_entry;
1156 int ret, size, u, ln;
1158 char *fw_name = FW_DIR "930-fpga.bin";
1160 uea_enters(INS_TO_USBDEV(sc));
1162 ret = request_firmware(&fw_entry, fw_name, &sc->usb_dev->dev);
1164 uea_err(INS_TO_USBDEV(sc), "firmware %s is not available\n",
1169 pfw = fw_entry->data;
1170 size = fw_entry->size;
1171 if (size != 0x577B) {
1172 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n",
1177 for (u = 0; u < size; u += ln) {
1178 ln = min(size - u, 64);
1179 ret = uea_request(sc, 0xe, 0, ln, pfw + u);
1181 uea_err(INS_TO_USBDEV(sc),
1182 "elsa download data failed (%d)\n", ret);
1187 /* finish to send the fpga
1189 ret = uea_request(sc, 0xe, 1, 0, NULL);
1191 uea_err(INS_TO_USBDEV(sc),
1192 "elsa download data failed (%d)\n", ret);
1197 * Tell the modem we finish : de-assert reset
1200 ret = uea_send_modem_cmd(sc->usb_dev, 0xe, 1, &value);
1202 uea_err(sc->usb_dev, "elsa de-assert failed with error %d\n", ret);
1206 release_firmware(fw_entry);
1208 uea_leaves(INS_TO_USBDEV(sc));
1212 static void uea_dispatch_cmv(struct uea_softc *sc, struct cmv* cmv)
1214 uea_enters(INS_TO_USBDEV(sc));
1215 if (le16_to_cpu(cmv->wPreamble) != PREAMBLE)
1218 if (cmv->bDirection != MODEMTOHOST)
1221 /* FIXME : ADI930 reply wrong preambule (func = 2, sub = 2) to
1222 * the first MEMACESS cmv. Ignore it...
1224 if (cmv->bFunction != sc->cmv_function) {
1225 if (UEA_CHIP_VERSION(sc) == ADI930
1226 && cmv->bFunction == MAKEFUNCTION(2, 2)) {
1227 cmv->wIndex = cpu_to_le16(sc->cmv_idx);
1228 put_unaligned(cpu_to_le32(sc->cmv_address), &cmv->dwSymbolicAddress);
1229 cmv->wOffsetAddress = cpu_to_le16(sc->cmv_offset);
1235 if (cmv->bFunction == MAKEFUNCTION(ADSLDIRECTIVE, MODEMREADY)) {
1236 wake_up_cmv_ack(sc);
1240 /* in case of MEMACCESS */
1241 if (le16_to_cpu(cmv->wIndex) != sc->cmv_idx ||
1242 le32_to_cpu(get_unaligned(&cmv->dwSymbolicAddress)) !=
1244 || le16_to_cpu(cmv->wOffsetAddress) != sc->cmv_offset)
1247 sc->data = le32_to_cpu(get_unaligned(&cmv->dwData));
1248 sc->data = sc->data << 16 | sc->data >> 16;
1250 wake_up_cmv_ack(sc);
1254 uea_err(INS_TO_USBDEV(sc), "unexpected cmv received,"
1255 "Function : %d, Subfunction : %d\n",
1256 FUNCTION_TYPE(cmv->bFunction),
1257 FUNCTION_SUBTYPE(cmv->bFunction));
1261 uea_err(INS_TO_USBDEV(sc), "invalid cmv received, "
1262 "wPreamble %d, bDirection %d\n",
1263 le16_to_cpu(cmv->wPreamble), cmv->bDirection);
1269 static void uea_intr(struct urb *urb, struct pt_regs *regs)
1271 struct uea_softc *sc = (struct uea_softc *)urb->context;
1272 struct intr_pkt *intr;
1273 uea_enters(INS_TO_USBDEV(sc));
1275 if (urb->status < 0) {
1276 uea_err(INS_TO_USBDEV(sc), "uea_intr() failed with %d\n",
1281 intr = (struct intr_pkt *) urb->transfer_buffer;
1283 /* device-to-host interrupt */
1284 if (intr->bType != 0x08 || sc->booting) {
1285 uea_err(INS_TO_USBDEV(sc), "wrong intr\n");
1291 switch (le16_to_cpu(intr->wInterrupt)) {
1292 case INT_LOADSWAPPAGE:
1293 sc->pageno = intr->bSwapPageNo;
1294 sc->ovl = intr->bOvl >> 4 | intr->bOvl << 4;
1295 schedule_work(&sc->task);
1298 case INT_INCOMINGCMV:
1299 uea_dispatch_cmv(sc, &intr->u.s2.cmv);
1303 uea_err(INS_TO_USBDEV(sc), "unknown intr %u\n",
1304 le16_to_cpu(intr->wInterrupt));
1308 usb_submit_urb(sc->urb_int, GFP_ATOMIC);
1312 * Start the modem : init the data and start kernel thread
1314 static int uea_boot(struct uea_softc *sc)
1317 struct intr_pkt *intr;
1319 uea_enters(INS_TO_USBDEV(sc));
1321 INIT_WORK(&sc->task, uea_load_page, sc);
1322 init_waitqueue_head(&sc->sync_q);
1323 init_waitqueue_head(&sc->cmv_ack_wait);
1325 if (UEA_CHIP_VERSION(sc) == ADI930)
1326 load_XILINX_firmware(sc);
1328 intr = kmalloc(INTR_PKT_SIZE, GFP_KERNEL);
1330 uea_err(INS_TO_USBDEV(sc),
1331 "cannot allocate interrupt package\n");
1332 uea_leaves(INS_TO_USBDEV(sc));
1336 sc->urb_int = usb_alloc_urb(0, GFP_KERNEL);
1338 uea_err(INS_TO_USBDEV(sc), "cannot allocate interrupt URB\n");
1342 usb_fill_int_urb(sc->urb_int, sc->usb_dev,
1343 usb_rcvintpipe(sc->usb_dev, UEA_INTR_PIPE),
1344 intr, INTR_PKT_SIZE, uea_intr, sc,
1345 sc->usb_dev->actconfig->interface[0]->altsetting[0].
1346 endpoint[0].desc.bInterval);
1348 ret = usb_submit_urb(sc->urb_int, GFP_KERNEL);
1350 uea_err(INS_TO_USBDEV(sc),
1351 "urb submition failed with error %d\n", ret);
1355 sc->kthread = kthread_run(uea_kthread, sc, "ueagle-atm");
1356 if (sc->kthread == ERR_PTR(-ENOMEM)) {
1357 uea_err(INS_TO_USBDEV(sc), "failed to create thread\n");
1361 uea_leaves(INS_TO_USBDEV(sc));
1365 usb_kill_urb(sc->urb_int);
1369 usb_free_urb(sc->urb_int);
1370 uea_leaves(INS_TO_USBDEV(sc));
1375 * Stop the modem : kill kernel thread and free data
1377 static void uea_stop(struct uea_softc *sc)
1380 uea_enters(INS_TO_USBDEV(sc));
1381 ret = kthread_stop(sc->kthread);
1382 uea_info(INS_TO_USBDEV(sc), "kthread finish with status %d\n", ret);
1384 /* stop any pending boot process */
1385 flush_scheduled_work();
1387 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_ON, 0, NULL);
1389 usb_kill_urb(sc->urb_int);
1390 kfree(sc->urb_int->transfer_buffer);
1391 usb_free_urb(sc->urb_int);
1394 release_firmware(sc->dsp_firm);
1395 uea_leaves(INS_TO_USBDEV(sc));
1398 /* syfs interface */
1399 static struct uea_softc *dev_to_uea(struct device *dev)
1401 struct usb_interface *intf;
1402 struct usbatm_data *usbatm;
1404 intf = to_usb_interface(dev);
1408 usbatm = usb_get_intfdata(intf);
1412 return usbatm->driver_data;
1415 static ssize_t read_status(struct device *dev, struct device_attribute *attr,
1419 struct uea_softc *sc;
1421 down(&uea_semaphore);
1422 sc = dev_to_uea(dev);
1425 ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.state);
1431 static ssize_t reboot(struct device *dev, struct device_attribute *attr,
1432 const char *buf, size_t count)
1435 struct uea_softc *sc;
1437 down(&uea_semaphore);
1438 sc = dev_to_uea(dev);
1448 static DEVICE_ATTR(stat_status, S_IWUGO | S_IRUGO, read_status, reboot);
1450 static ssize_t read_human_status(struct device *dev, struct device_attribute *attr,
1454 struct uea_softc *sc;
1456 down(&uea_semaphore);
1457 sc = dev_to_uea(dev);
1461 switch (GET_STATUS(sc->stats.phy.state)) {
1463 ret = sprintf(buf, "Modem is booting\n");
1466 ret = sprintf(buf, "Modem is initializing\n");
1469 ret = sprintf(buf, "Modem is operational\n");
1472 ret = sprintf(buf, "Modem synchronization failed\n");
1480 static DEVICE_ATTR(stat_human_status, S_IWUGO | S_IRUGO, read_human_status, NULL);
1482 static ssize_t read_delin(struct device *dev, struct device_attribute *attr,
1486 struct uea_softc *sc;
1488 down(&uea_semaphore);
1489 sc = dev_to_uea(dev);
1493 if (sc->stats.phy.flags & 0x0C00)
1494 ret = sprintf(buf, "ERROR\n");
1495 else if (sc->stats.phy.flags & 0x0030)
1496 ret = sprintf(buf, "LOSS\n");
1498 ret = sprintf(buf, "GOOD\n");
1504 static DEVICE_ATTR(stat_delin, S_IWUGO | S_IRUGO, read_delin, NULL);
1506 #define UEA_ATTR(name, reset) \
1508 static ssize_t read_##name(struct device *dev, \
1509 struct device_attribute *attr, char *buf) \
1511 int ret = -ENODEV; \
1512 struct uea_softc *sc; \
1514 down(&uea_semaphore); \
1515 sc = dev_to_uea(dev); \
1518 ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.name); \
1520 sc->stats.phy.name = 0; \
1522 up(&uea_semaphore); \
1526 static DEVICE_ATTR(stat_##name, S_IRUGO, read_##name, NULL)
1528 UEA_ATTR(mflags, 1);
1529 UEA_ATTR(vidcpe, 0);
1530 UEA_ATTR(usrate, 0);
1531 UEA_ATTR(dsrate, 0);
1532 UEA_ATTR(usattenuation, 0);
1533 UEA_ATTR(dsattenuation, 0);
1534 UEA_ATTR(usmargin, 0);
1535 UEA_ATTR(dsmargin, 0);
1536 UEA_ATTR(txflow, 0);
1537 UEA_ATTR(rxflow, 0);
1538 UEA_ATTR(uscorr, 0);
1539 UEA_ATTR(dscorr, 0);
1543 /* Retrieve the device End System Identifier (MAC) */
1545 #define htoi(x) (isdigit(x) ? x-'0' : toupper(x)-'A'+10)
1546 static int uea_getesi(struct uea_softc *sc, u_char * esi)
1548 unsigned char mac_str[2 * ETH_ALEN + 1];
1551 (sc->usb_dev, sc->usb_dev->descriptor.iSerialNumber, mac_str,
1552 sizeof(mac_str)) != 2 * ETH_ALEN)
1555 for (i = 0; i < ETH_ALEN; i++)
1556 esi[i] = htoi(mac_str[2 * i]) * 16 + htoi(mac_str[2 * i + 1]);
1562 static int uea_atm_open(struct usbatm_data *usbatm, struct atm_dev *atm_dev)
1564 struct uea_softc *sc = usbatm->driver_data;
1566 return uea_getesi(sc, atm_dev->esi);
1569 static int uea_heavy(struct usbatm_data *usbatm, struct usb_interface *intf)
1571 struct uea_softc *sc = usbatm->driver_data;
1573 wait_event(sc->sync_q, IS_OPERATIONAL(sc));
1579 static int claim_interface(struct usb_device *usb_dev,
1580 struct usbatm_data *usbatm, int ifnum)
1583 struct usb_interface *intf = usb_ifnum_to_if(usb_dev, ifnum);
1586 uea_err(usb_dev, "interface %d not found\n", ifnum);
1590 ret = usb_driver_claim_interface(&uea_driver, intf, usbatm);
1592 uea_err(usb_dev, "can't claim interface %d, error %d\n", ifnum,
1597 static void create_fs_entries(struct uea_softc *sc, struct usb_interface *intf)
1599 /* sysfs interface */
1600 device_create_file(&intf->dev, &dev_attr_stat_status);
1601 device_create_file(&intf->dev, &dev_attr_stat_mflags);
1602 device_create_file(&intf->dev, &dev_attr_stat_human_status);
1603 device_create_file(&intf->dev, &dev_attr_stat_delin);
1604 device_create_file(&intf->dev, &dev_attr_stat_vidcpe);
1605 device_create_file(&intf->dev, &dev_attr_stat_usrate);
1606 device_create_file(&intf->dev, &dev_attr_stat_dsrate);
1607 device_create_file(&intf->dev, &dev_attr_stat_usattenuation);
1608 device_create_file(&intf->dev, &dev_attr_stat_dsattenuation);
1609 device_create_file(&intf->dev, &dev_attr_stat_usmargin);
1610 device_create_file(&intf->dev, &dev_attr_stat_dsmargin);
1611 device_create_file(&intf->dev, &dev_attr_stat_txflow);
1612 device_create_file(&intf->dev, &dev_attr_stat_rxflow);
1613 device_create_file(&intf->dev, &dev_attr_stat_uscorr);
1614 device_create_file(&intf->dev, &dev_attr_stat_dscorr);
1615 device_create_file(&intf->dev, &dev_attr_stat_usunc);
1616 device_create_file(&intf->dev, &dev_attr_stat_dsunc);
1619 static int uea_bind(struct usbatm_data *usbatm, struct usb_interface *intf,
1620 const struct usb_device_id *id)
1622 struct usb_device *usb = interface_to_usbdev(intf);
1623 struct uea_softc *sc;
1624 int ret, ifnum = intf->altsetting->desc.bInterfaceNumber;
1628 /* interface 0 is for firmware/monitoring */
1629 if (ifnum != UEA_INTR_IFACE_NO)
1632 usbatm->flags = (sync_wait[modem_index] ? 0 : UDSL_SKIP_HEAVY_INIT);
1634 /* interface 1 is for outbound traffic */
1635 ret = claim_interface(usb, usbatm, UEA_US_IFACE_NO);
1639 /* ADI930 has only 2 interfaces and inbound traffic
1642 if (UEA_CHIP_VERSION(id) != ADI930) {
1643 /* interface 2 is for inbound traffic */
1644 ret = claim_interface(usb, usbatm, UEA_DS_IFACE_NO);
1649 sc = kzalloc(sizeof(struct uea_softc), GFP_KERNEL);
1651 uea_err(INS_TO_USBDEV(sc), "uea_init: not enough memory !\n");
1656 usbatm->driver_data = sc;
1657 sc->usbatm = usbatm;
1658 sc->modem_index = (modem_index < NB_MODEM) ? modem_index++ : 0;
1659 sc->driver_info = id->driver_info;
1667 create_fs_entries(sc, intf);
1671 static void destroy_fs_entries(struct uea_softc *sc, struct usb_interface *intf)
1673 /* sysfs interface */
1674 device_remove_file(&intf->dev, &dev_attr_stat_status);
1675 device_remove_file(&intf->dev, &dev_attr_stat_mflags);
1676 device_remove_file(&intf->dev, &dev_attr_stat_human_status);
1677 device_remove_file(&intf->dev, &dev_attr_stat_delin);
1678 device_remove_file(&intf->dev, &dev_attr_stat_vidcpe);
1679 device_remove_file(&intf->dev, &dev_attr_stat_usrate);
1680 device_remove_file(&intf->dev, &dev_attr_stat_dsrate);
1681 device_remove_file(&intf->dev, &dev_attr_stat_usattenuation);
1682 device_remove_file(&intf->dev, &dev_attr_stat_dsattenuation);
1683 device_remove_file(&intf->dev, &dev_attr_stat_usmargin);
1684 device_remove_file(&intf->dev, &dev_attr_stat_dsmargin);
1685 device_remove_file(&intf->dev, &dev_attr_stat_txflow);
1686 device_remove_file(&intf->dev, &dev_attr_stat_rxflow);
1687 device_remove_file(&intf->dev, &dev_attr_stat_uscorr);
1688 device_remove_file(&intf->dev, &dev_attr_stat_dscorr);
1689 device_remove_file(&intf->dev, &dev_attr_stat_usunc);
1690 device_remove_file(&intf->dev, &dev_attr_stat_dsunc);
1693 static void uea_unbind(struct usbatm_data *usbatm, struct usb_interface *intf)
1695 struct uea_softc *sc = usbatm->driver_data;
1697 destroy_fs_entries(sc, intf);
1702 static struct usbatm_driver uea_usbatm_driver = {
1703 .driver_name = "ueagle-atm",
1705 .atm_start = uea_atm_open,
1706 .unbind = uea_unbind,
1707 .heavy_init = uea_heavy,
1708 .bulk_in = UEA_BULK_DATA_PIPE,
1709 .bulk_out = UEA_BULK_DATA_PIPE,
1712 static int uea_probe(struct usb_interface *intf, const struct usb_device_id *id)
1714 struct usb_device *usb = interface_to_usbdev(intf);
1717 uea_info(usb, "ADSL device founded vid (%#X) pid (%#X) : %s\n",
1718 le16_to_cpu(usb->descriptor.idVendor),
1719 le16_to_cpu(usb->descriptor.idProduct),
1720 chip_name[UEA_CHIP_VERSION(id)]);
1722 usb_reset_device(usb);
1724 if (UEA_IS_PREFIRM(id))
1725 return uea_load_firmware(usb, UEA_CHIP_VERSION(id));
1727 return usbatm_usb_probe(intf, id, &uea_usbatm_driver);
1730 static void uea_disconnect(struct usb_interface *intf)
1732 struct usb_device *usb = interface_to_usbdev(intf);
1733 int ifnum = intf->altsetting->desc.bInterfaceNumber;
1736 /* ADI930 has 2 interfaces and eagle 3 interfaces.
1737 * Pre-firmware device has one interface
1739 if (usb->config->desc.bNumInterfaces != 1 && ifnum == 0) {
1740 down(&uea_semaphore);
1741 usbatm_usb_disconnect(intf);
1743 uea_info(usb, "ADSL device removed\n");
1750 * List of supported VID/PID
1752 static const struct usb_device_id uea_ids[] = {
1753 {USB_DEVICE(ELSA_VID, ELSA_PID_PREFIRM), .driver_info = ADI930 | PREFIRM},
1754 {USB_DEVICE(ELSA_VID, ELSA_PID_PSTFIRM), .driver_info = ADI930 | PSTFIRM},
1755 {USB_DEVICE(EAGLE_VID, EAGLE_I_PID_PREFIRM), .driver_info = EAGLE_I | PREFIRM},
1756 {USB_DEVICE(EAGLE_VID, EAGLE_I_PID_PSTFIRM), .driver_info = EAGLE_I | PSTFIRM},
1757 {USB_DEVICE(EAGLE_VID, EAGLE_II_PID_PREFIRM), .driver_info = EAGLE_II | PREFIRM},
1758 {USB_DEVICE(EAGLE_VID, EAGLE_II_PID_PSTFIRM), .driver_info = EAGLE_II | PSTFIRM},
1759 {USB_DEVICE(EAGLE_VID, EAGLE_IIC_PID_PREFIRM), .driver_info = EAGLE_II | PREFIRM},
1760 {USB_DEVICE(EAGLE_VID, EAGLE_IIC_PID_PSTFIRM), .driver_info = EAGLE_II | PSTFIRM},
1761 {USB_DEVICE(EAGLE_VID, EAGLE_III_PID_PREFIRM), .driver_info = EAGLE_III | PREFIRM},
1762 {USB_DEVICE(EAGLE_VID, EAGLE_III_PID_PSTFIRM), .driver_info = EAGLE_III | PSTFIRM},
1763 {USB_DEVICE(USR_VID, MILLER_A_PID_PREFIRM), .driver_info = EAGLE_I | PREFIRM},
1764 {USB_DEVICE(USR_VID, MILLER_A_PID_PSTFIRM), .driver_info = EAGLE_I | PSTFIRM},
1765 {USB_DEVICE(USR_VID, MILLER_B_PID_PREFIRM), .driver_info = EAGLE_I | PREFIRM},
1766 {USB_DEVICE(USR_VID, MILLER_B_PID_PSTFIRM), .driver_info = EAGLE_I | PSTFIRM},
1767 {USB_DEVICE(USR_VID, HEINEKEN_A_PID_PREFIRM),.driver_info = EAGLE_I | PREFIRM},
1768 {USB_DEVICE(USR_VID, HEINEKEN_A_PID_PSTFIRM),.driver_info = EAGLE_I | PSTFIRM},
1769 {USB_DEVICE(USR_VID, HEINEKEN_B_PID_PREFIRM),.driver_info = EAGLE_I | PREFIRM},
1770 {USB_DEVICE(USR_VID, HEINEKEN_B_PID_PSTFIRM),.driver_info = EAGLE_I | PSTFIRM},
1775 * USB driver descriptor
1777 static struct usb_driver uea_driver = {
1778 .name = "ueagle-atm",
1779 .id_table = uea_ids,
1781 .disconnect = uea_disconnect,
1784 MODULE_DEVICE_TABLE(usb, uea_ids);
1787 * uea_init - Initialize the module.
1788 * Register to USB subsystem
1790 static int __init uea_init(void)
1792 printk(KERN_INFO "[ueagle-atm] driver " EAGLEUSBVERSION " loaded\n");
1794 usb_register(&uea_driver);
1799 module_init(uea_init);
1802 * uea_exit - Destroy module
1803 * Deregister with USB subsystem
1805 static void __exit uea_exit(void)
1808 * This calls automatically the uea_disconnect method if necessary:
1810 usb_deregister(&uea_driver);
1812 printk(KERN_INFO "[ueagle-atm] driver unloaded\n");
1815 module_exit(uea_exit);
1817 MODULE_AUTHOR("Damien Bergamini/Matthieu Castet/Stanislaw W. Gruszka");
1818 MODULE_DESCRIPTION("ADI 930/Eagle USB ADSL Modem driver");
1819 MODULE_LICENSE("Dual BSD/GPL");