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 <linux/mutex.h>
67 #include <asm/unaligned.h>
71 #define EAGLEUSBVERSION "ueagle 1.4"
77 #define uea_dbg(usb_dev, format, args...) \
80 dev_dbg(&(usb_dev)->dev, \
81 "[ueagle-atm dbg] %s: " format, \
82 __FUNCTION__, ##args); \
85 #define uea_vdbg(usb_dev, format, args...) \
88 dev_dbg(&(usb_dev)->dev, \
89 "[ueagle-atm vdbg] " format, ##args); \
92 #define uea_enters(usb_dev) \
93 uea_vdbg(usb_dev, "entering %s\n", __FUNCTION__)
95 #define uea_leaves(usb_dev) \
96 uea_vdbg(usb_dev, "leaving %s\n", __FUNCTION__)
98 #define uea_err(usb_dev, format,args...) \
99 dev_err(&(usb_dev)->dev ,"[UEAGLE-ATM] " format , ##args)
101 #define uea_warn(usb_dev, format,args...) \
102 dev_warn(&(usb_dev)->dev ,"[Ueagle-atm] " format, ##args)
104 #define uea_info(usb_dev, format,args...) \
105 dev_info(&(usb_dev)->dev ,"[ueagle-atm] " format, ##args)
111 } __attribute__ ((packed));
114 struct usb_device *usb_dev;
115 struct usbatm_data *usbatm;
118 unsigned int driver_info;
123 wait_queue_head_t sync_q;
125 struct task_struct *kthread;
127 wait_queue_head_t cmv_ack_wait;
130 struct work_struct task;
134 const struct firmware *dsp_firm;
142 /* keep in sync with eaglectl */
170 #define ELSA_VID 0x05CC
171 #define ELSA_PID_PSTFIRM 0x3350
172 #define ELSA_PID_PREFIRM 0x3351
177 #define EAGLE_VID 0x1110
178 #define EAGLE_I_PID_PREFIRM 0x9010 /* Eagle I */
179 #define EAGLE_I_PID_PSTFIRM 0x900F /* Eagle I */
181 #define EAGLE_IIC_PID_PREFIRM 0x9024 /* Eagle IIC */
182 #define EAGLE_IIC_PID_PSTFIRM 0x9023 /* Eagle IIC */
184 #define EAGLE_II_PID_PREFIRM 0x9022 /* Eagle II */
185 #define EAGLE_II_PID_PSTFIRM 0x9021 /* Eagle II */
190 #define EAGLE_III_PID_PREFIRM 0x9032 /* Eagle III */
191 #define EAGLE_III_PID_PSTFIRM 0x9031 /* Eagle III */
196 #define USR_VID 0x0BAF
197 #define MILLER_A_PID_PREFIRM 0x00F2
198 #define MILLER_A_PID_PSTFIRM 0x00F1
199 #define MILLER_B_PID_PREFIRM 0x00FA
200 #define MILLER_B_PID_PSTFIRM 0x00F9
201 #define HEINEKEN_A_PID_PREFIRM 0x00F6
202 #define HEINEKEN_A_PID_PSTFIRM 0x00F5
203 #define HEINEKEN_B_PID_PREFIRM 0x00F8
204 #define HEINEKEN_B_PID_PSTFIRM 0x00F7
207 #define PSTFIRM (1<<7)
215 /* macros for both struct usb_device_id and struct uea_softc */
216 #define UEA_IS_PREFIRM(x) \
217 (!((x)->driver_info & PSTFIRM))
218 #define UEA_CHIP_VERSION(x) \
219 ((x)->driver_info & 0xf)
221 #define IS_ISDN(usb_dev) \
222 (le16_to_cpu((usb_dev)->descriptor.bcdDevice) & 0x80)
224 #define INS_TO_USBDEV(ins) ins->usb_dev
226 #define GET_STATUS(data) \
228 #define IS_OPERATIONAL(sc) \
229 (GET_STATUS(sc->stats.phy.state) == 2)
232 * Set of macros to handle unaligned data in the firmware blob.
233 * The FW_GET_BYTE() macro is provided only for consistency.
236 #define FW_GET_BYTE(p) *((__u8 *) (p))
237 #define FW_GET_WORD(p) le16_to_cpu(get_unaligned((__le16 *) (p)))
238 #define FW_GET_LONG(p) le32_to_cpu(get_unaligned((__le32 *) (p)))
240 #define FW_DIR "ueagle-atm/"
243 #define BULK_TIMEOUT 300
244 #define CTRL_TIMEOUT 1000
246 #define ACK_TIMEOUT msecs_to_jiffies(3000)
248 #define UEA_INTR_IFACE_NO 0
249 #define UEA_US_IFACE_NO 1
250 #define UEA_DS_IFACE_NO 2
252 #define FASTEST_ISO_INTF 8
254 #define UEA_BULK_DATA_PIPE 0x02
255 #define UEA_IDMA_PIPE 0x04
256 #define UEA_INTR_PIPE 0x04
257 #define UEA_ISO_DATA_PIPE 0x08
259 #define UEA_SET_BLOCK 0x0001
260 #define UEA_SET_MODE 0x0003
261 #define UEA_SET_2183_DATA 0x0004
262 #define UEA_SET_TIMEOUT 0x0011
264 #define UEA_LOOPBACK_OFF 0x0002
265 #define UEA_LOOPBACK_ON 0x0003
266 #define UEA_BOOT_IDMA 0x0006
267 #define UEA_START_RESET 0x0007
268 #define UEA_END_RESET 0x0008
270 #define UEA_SWAP_MAILBOX (0x3fcd | 0x4000)
271 #define UEA_MPTX_START (0x3fce | 0x4000)
272 #define UEA_MPTX_MAILBOX (0x3fd6 | 0x4000)
273 #define UEA_MPRX_MAILBOX (0x3fdf | 0x4000)
275 /* structure describing a block within a DSP page */
278 #define UEA_BIHDR 0xabcd
282 __le16 wOvl; /* overlay */
284 } __attribute__ ((packed));
285 #define BLOCK_INFO_SIZE 12
287 /* structure representing a CMV (Configuration and Management Variable) */
290 #define PREAMBLE 0x535c
292 #define MODEMTOHOST 0x01
293 #define HOSTTOMODEM 0x10
295 #define FUNCTION_TYPE(f) ((f) >> 4)
296 #define MEMACCESS 0x1
297 #define ADSLDIRECTIVE 0x7
299 #define FUNCTION_SUBTYPE(f) ((f) & 0x0f)
301 #define REQUESTREAD 0x0
302 #define REQUESTWRITE 0x1
303 #define REPLYREAD 0x2
304 #define REPLYWRITE 0x3
305 /* for ADSLDIRECTIVE */
306 #define KERNELREADY 0x0
307 #define MODEMREADY 0x1
309 #define MAKEFUNCTION(t, s) (((t) & 0xf) << 4 | ((s) & 0xf))
311 __le32 dwSymbolicAddress;
312 #define MAKESA(a, b, c, d) \
313 (((c) & 0xff) << 24 | \
314 ((d) & 0xff) << 16 | \
315 ((a) & 0xff) << 8 | \
317 #define GETSA1(a) ((a >> 8) & 0xff)
318 #define GETSA2(a) (a & 0xff)
319 #define GETSA3(a) ((a >> 24) & 0xff)
320 #define GETSA4(a) ((a >> 16) & 0xff)
322 #define SA_CNTL MAKESA('C', 'N', 'T', 'L')
323 #define SA_DIAG MAKESA('D', 'I', 'A', 'G')
324 #define SA_INFO MAKESA('I', 'N', 'F', 'O')
325 #define SA_OPTN MAKESA('O', 'P', 'T', 'N')
326 #define SA_RATE MAKESA('R', 'A', 'T', 'E')
327 #define SA_STAT MAKESA('S', 'T', 'A', 'T')
328 __le16 wOffsetAddress;
330 } __attribute__ ((packed));
333 /* structure representing swap information */
336 __u8 bOvl; /* overlay */
337 } __attribute__ ((packed));
339 /* structure representing interrupt data */
347 #define INT_LOADSWAPPAGE 0x0001
348 #define INT_INCOMINGCMV 0x0002
351 struct swap_info swapinfo;
353 } __attribute__ ((packed)) s1;
358 } __attribute__ ((packed)) s2;
359 } __attribute__ ((packed)) u;
360 #define bSwapPageNo u.s1.swapinfo.bSwapPageNo
361 #define bOvl u.s1.swapinfo.bOvl
362 } __attribute__ ((packed));
363 #define INTR_PKT_SIZE 28
365 static struct usb_driver uea_driver;
366 static DEFINE_MUTEX(uea_mutex);
367 static const char *chip_name[] = {"ADI930", "Eagle I", "Eagle II", "Eagle III"};
369 static int modem_index;
370 static unsigned int debug;
371 static int use_iso[NB_MODEM] = {[0 ... (NB_MODEM - 1)] = 1};
372 static int sync_wait[NB_MODEM];
373 static char *cmv_file[NB_MODEM];
375 module_param(debug, uint, 0644);
376 MODULE_PARM_DESC(debug, "module debug level (0=off,1=on,2=verbose)");
377 module_param_array(use_iso, bool, NULL, 0644);
378 MODULE_PARM_DESC(use_iso, "use isochronous usb pipe for incoming traffic");
379 module_param_array(sync_wait, bool, NULL, 0644);
380 MODULE_PARM_DESC(sync_wait, "wait the synchronisation before starting ATM");
381 module_param_array(cmv_file, charp, NULL, 0644);
382 MODULE_PARM_DESC(cmv_file,
383 "file name with configuration and management variables");
385 #define UPDATE_ATM_STAT(type, val) \
387 if (sc->usbatm->atm_dev) \
388 sc->usbatm->atm_dev->type = val; \
391 /* Firmware loading */
392 #define LOAD_INTERNAL 0xA0
393 #define F8051_USBCS 0x7f92
396 * uea_send_modem_cmd - Send a command for pre-firmware devices.
398 static int uea_send_modem_cmd(struct usb_device *usb,
399 u16 addr, u16 size, u8 * buff)
404 xfer_buff = kmemdup(buff, size, GFP_KERNEL);
406 ret = usb_control_msg(usb,
407 usb_sndctrlpipe(usb, 0),
409 USB_DIR_OUT | USB_TYPE_VENDOR |
410 USB_RECIP_DEVICE, addr, 0, xfer_buff,
418 return (ret == size) ? 0 : -EIO;
421 static void uea_upload_pre_firmware(const struct firmware *fw_entry, void *context)
423 struct usb_device *usb = context;
430 uea_err(usb, "firmware is not available\n");
434 pfw = fw_entry->data;
435 size = fw_entry->size;
437 goto err_fw_corrupted;
439 crc = FW_GET_LONG(pfw);
442 if (crc32_be(0, pfw, size) != crc)
443 goto err_fw_corrupted;
446 * Start to upload formware : send reset
449 ret = uea_send_modem_cmd(usb, F8051_USBCS, sizeof(value), &value);
452 uea_err(usb, "modem reset failed with error %d\n", ret);
457 u8 len = FW_GET_BYTE(pfw);
458 u16 add = FW_GET_WORD(pfw + 1);
462 goto err_fw_corrupted;
464 ret = uea_send_modem_cmd(usb, add, len, pfw + 3);
466 uea_err(usb, "uploading firmware data failed "
467 "with error %d\n", ret);
474 goto err_fw_corrupted;
477 * Tell the modem we finish : de-assert reset
480 ret = uea_send_modem_cmd(usb, F8051_USBCS, 1, &value);
482 uea_err(usb, "modem de-assert failed with error %d\n", ret);
484 uea_info(usb, "firmware uploaded\n");
490 uea_err(usb, "firmware is corrupted\n");
496 * uea_load_firmware - Load usb firmware for pre-firmware devices.
498 static int uea_load_firmware(struct usb_device *usb, unsigned int ver)
501 char *fw_name = FW_DIR "eagle.fw";
504 uea_info(usb, "pre-firmware device, uploading firmware\n");
508 fw_name = FW_DIR "adi930.fw";
511 fw_name = FW_DIR "eagleI.fw";
514 fw_name = FW_DIR "eagleII.fw";
517 fw_name = FW_DIR "eagleIII.fw";
521 ret = request_firmware_nowait(THIS_MODULE, 1, fw_name, &usb->dev, usb, uea_upload_pre_firmware);
523 uea_err(usb, "firmware %s is not available\n", fw_name);
525 uea_info(usb, "loading firmware %s\n", fw_name);
531 /* modem management : dsp firmware, send/read CMV, monitoring statistic
535 * Make sure that the DSP code provided is safe to use.
537 static int check_dsp(u8 *dsp, unsigned int len)
539 u8 pagecount, blockcount;
542 unsigned int i, j, p, pp;
544 pagecount = FW_GET_BYTE(dsp);
547 /* enough space for page offsets? */
548 if (p + 4 * pagecount > len)
551 for (i = 0; i < pagecount; i++) {
553 pageoffset = FW_GET_LONG(dsp + p);
559 /* enough space for blockcount? */
560 if (pageoffset >= len)
564 blockcount = FW_GET_BYTE(dsp + pp);
567 for (j = 0; j < blockcount; j++) {
569 /* enough space for block header? */
573 pp += 2; /* skip blockaddr */
574 blocksize = FW_GET_WORD(dsp + pp);
577 /* enough space for block data? */
578 if (pp + blocksize > len)
589 * send data to the idma pipe
591 static int uea_idma_write(struct uea_softc *sc, void *data, u32 size)
597 xfer_buff = kmemdup(data, size, GFP_KERNEL);
599 uea_err(INS_TO_USBDEV(sc), "can't allocate xfer_buff\n");
603 ret = usb_bulk_msg(sc->usb_dev,
604 usb_sndbulkpipe(sc->usb_dev, UEA_IDMA_PIPE),
605 xfer_buff, size, &bytes_read, BULK_TIMEOUT);
610 if (size != bytes_read) {
611 uea_err(INS_TO_USBDEV(sc), "size != bytes_read %d %d\n", size,
619 static int request_dsp(struct uea_softc *sc)
624 if (UEA_CHIP_VERSION(sc) == ADI930) {
625 if (IS_ISDN(sc->usb_dev))
626 dsp_name = FW_DIR "DSP9i.bin";
628 dsp_name = FW_DIR "DSP9p.bin";
630 if (IS_ISDN(sc->usb_dev))
631 dsp_name = FW_DIR "DSPei.bin";
633 dsp_name = FW_DIR "DSPep.bin";
636 ret = request_firmware(&sc->dsp_firm, dsp_name, &sc->usb_dev->dev);
638 uea_err(INS_TO_USBDEV(sc),
639 "requesting firmware %s failed with error %d\n",
644 if (check_dsp(sc->dsp_firm->data, sc->dsp_firm->size)) {
645 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n",
647 release_firmware(sc->dsp_firm);
656 * The uea_load_page() function must be called within a process context
658 static void uea_load_page(struct work_struct *work)
660 struct uea_softc *sc = container_of(work, struct uea_softc, task);
661 u16 pageno = sc->pageno;
663 struct block_info bi;
666 u8 pagecount, blockcount;
667 u16 blockaddr, blocksize;
671 /* reload firmware when reboot start and it's loaded already */
672 if (ovl == 0 && pageno == 0 && sc->dsp_firm) {
673 release_firmware(sc->dsp_firm);
677 if (sc->dsp_firm == NULL && request_dsp(sc) < 0)
680 p = sc->dsp_firm->data;
681 pagecount = FW_GET_BYTE(p);
684 if (pageno >= pagecount)
688 pageoffset = FW_GET_LONG(p);
693 p = sc->dsp_firm->data + pageoffset;
694 blockcount = FW_GET_BYTE(p);
697 uea_dbg(INS_TO_USBDEV(sc),
698 "sending %u blocks for DSP page %u\n", blockcount, pageno);
700 bi.wHdr = cpu_to_le16(UEA_BIHDR);
701 bi.wOvl = cpu_to_le16(ovl);
702 bi.wOvlOffset = cpu_to_le16(ovl | 0x8000);
704 for (i = 0; i < blockcount; i++) {
705 blockaddr = FW_GET_WORD(p);
708 blocksize = FW_GET_WORD(p);
711 bi.wSize = cpu_to_le16(blocksize);
712 bi.wAddress = cpu_to_le16(blockaddr);
713 bi.wLast = cpu_to_le16((i == blockcount - 1) ? 1 : 0);
715 /* send block info through the IDMA pipe */
716 if (uea_idma_write(sc, &bi, BLOCK_INFO_SIZE))
719 /* send block data through the IDMA pipe */
720 if (uea_idma_write(sc, p, blocksize))
729 uea_err(INS_TO_USBDEV(sc), "sending DSP block %u failed\n", i);
732 uea_err(INS_TO_USBDEV(sc), "invalid DSP page %u requested\n", pageno);
735 static inline void wake_up_cmv_ack(struct uea_softc *sc)
739 wake_up(&sc->cmv_ack_wait);
742 static inline int wait_cmv_ack(struct uea_softc *sc)
744 int ret = wait_event_interruptible_timeout(sc->cmv_ack_wait,
745 sc->cmv_ack, ACK_TIMEOUT);
748 uea_dbg(INS_TO_USBDEV(sc), "wait_event_timeout : %d ms\n",
749 jiffies_to_msecs(ret));
754 return (ret == 0) ? -ETIMEDOUT : 0;
757 #define UCDC_SEND_ENCAPSULATED_COMMAND 0x00
759 static int uea_request(struct uea_softc *sc,
760 u16 value, u16 index, u16 size, void *data)
765 xfer_buff = kmemdup(data, size, GFP_KERNEL);
767 uea_err(INS_TO_USBDEV(sc), "can't allocate xfer_buff\n");
771 ret = usb_control_msg(sc->usb_dev, usb_sndctrlpipe(sc->usb_dev, 0),
772 UCDC_SEND_ENCAPSULATED_COMMAND,
773 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
774 value, index, xfer_buff, size, CTRL_TIMEOUT);
778 uea_err(INS_TO_USBDEV(sc), "usb_control_msg error %d\n", ret);
783 uea_err(INS_TO_USBDEV(sc),
784 "usb_control_msg send only %d bytes (instead of %d)\n",
792 static int uea_cmv(struct uea_softc *sc,
793 u8 function, u32 address, u16 offset, u32 data)
798 uea_enters(INS_TO_USBDEV(sc));
799 uea_vdbg(INS_TO_USBDEV(sc), "Function : %d-%d, Address : %c%c%c%c, "
800 "offset : 0x%04x, data : 0x%08x\n",
801 FUNCTION_TYPE(function), FUNCTION_SUBTYPE(function),
802 GETSA1(address), GETSA2(address), GETSA3(address),
803 GETSA4(address), offset, data);
804 /* we send a request, but we expect a reply */
805 sc->cmv_function = function | 0x2;
807 sc->cmv_address = address;
808 sc->cmv_offset = offset;
810 cmv.wPreamble = cpu_to_le16(PREAMBLE);
811 cmv.bDirection = HOSTTOMODEM;
812 cmv.bFunction = function;
813 cmv.wIndex = cpu_to_le16(sc->cmv_idx);
814 put_unaligned(cpu_to_le32(address), &cmv.dwSymbolicAddress);
815 cmv.wOffsetAddress = cpu_to_le16(offset);
816 put_unaligned(cpu_to_le32(data >> 16 | data << 16), &cmv.dwData);
818 ret = uea_request(sc, UEA_SET_BLOCK, UEA_MPTX_START, CMV_SIZE, &cmv);
821 ret = wait_cmv_ack(sc);
822 uea_leaves(INS_TO_USBDEV(sc));
826 static inline int uea_read_cmv(struct uea_softc *sc,
827 u32 address, u16 offset, u32 *data)
829 int ret = uea_cmv(sc, MAKEFUNCTION(MEMACCESS, REQUESTREAD),
832 uea_err(INS_TO_USBDEV(sc),
833 "reading cmv failed with error %d\n", ret);
840 static inline int uea_write_cmv(struct uea_softc *sc,
841 u32 address, u16 offset, u32 data)
843 int ret = uea_cmv(sc, MAKEFUNCTION(MEMACCESS, REQUESTWRITE),
844 address, offset, data);
846 uea_err(INS_TO_USBDEV(sc),
847 "writing cmv failed with error %d\n", ret);
853 * Monitor the modem and update the stat
854 * return 0 if everything is ok
855 * return < 0 if an error occurs (-EAGAIN reboot needed)
857 static int uea_stat(struct uea_softc *sc)
862 uea_enters(INS_TO_USBDEV(sc));
863 data = sc->stats.phy.state;
865 ret = uea_read_cmv(sc, SA_STAT, 0, &sc->stats.phy.state);
869 switch (GET_STATUS(sc->stats.phy.state)) {
870 case 0: /* not yet synchronized */
871 uea_dbg(INS_TO_USBDEV(sc),
872 "modem not yet synchronized\n");
875 case 1: /* initialization */
876 uea_dbg(INS_TO_USBDEV(sc), "modem initializing\n");
879 case 2: /* operational */
880 uea_vdbg(INS_TO_USBDEV(sc), "modem operational\n");
883 case 3: /* fail ... */
884 uea_info(INS_TO_USBDEV(sc), "modem synchronization failed"
885 " (may be try other cmv/dsp)\n");
888 case 4 ... 6: /* test state */
889 uea_warn(INS_TO_USBDEV(sc),
890 "modem in test mode - not supported\n");
893 case 7: /* fast-retain ... */
894 uea_info(INS_TO_USBDEV(sc), "modem in fast-retain mode\n");
897 uea_err(INS_TO_USBDEV(sc), "modem invalid SW mode %d\n",
898 GET_STATUS(sc->stats.phy.state));
902 if (GET_STATUS(data) != 2) {
903 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_OFF, 0, NULL);
904 uea_info(INS_TO_USBDEV(sc), "modem operational\n");
906 /* release the dsp firmware as it is not needed until
910 release_firmware(sc->dsp_firm);
915 /* always update it as atm layer could not be init when we switch to
918 UPDATE_ATM_STAT(signal, ATM_PHY_SIG_FOUND);
920 /* wake up processes waiting for synchronization */
921 wake_up(&sc->sync_q);
923 ret = uea_read_cmv(sc, SA_DIAG, 2, &sc->stats.phy.flags);
926 sc->stats.phy.mflags |= sc->stats.phy.flags;
928 /* in case of a flags ( for example delineation LOSS (& 0x10)),
929 * we check the status again in order to detect the failure earlier
931 if (sc->stats.phy.flags) {
932 uea_dbg(INS_TO_USBDEV(sc), "Stat flag = 0x%x\n",
933 sc->stats.phy.flags);
937 ret = uea_read_cmv(sc, SA_RATE, 0, &data);
941 /* in bulk mode the modem have problem with high rate
942 * changing internal timing could improve things, but the
943 * value is misterious.
944 * ADI930 don't support it (-EPIPE error).
946 if (UEA_CHIP_VERSION(sc) != ADI930
947 && !use_iso[sc->modem_index]
948 && sc->stats.phy.dsrate != (data >> 16) * 32) {
949 /* Original timming from ADI(used in windows driver)
950 * 0x20ffff>>16 * 32 = 32 * 32 = 1Mbits
952 u16 timeout = (data <= 0x20ffff) ? 0 : 1;
953 ret = uea_request(sc, UEA_SET_TIMEOUT, timeout, 0, NULL);
954 uea_info(INS_TO_USBDEV(sc),
955 "setting new timeout %d%s\n", timeout,
956 ret < 0?" failed":"");
958 sc->stats.phy.dsrate = (data >> 16) * 32;
959 sc->stats.phy.usrate = (data & 0xffff) * 32;
960 UPDATE_ATM_STAT(link_rate, sc->stats.phy.dsrate * 1000 / 424);
962 ret = uea_read_cmv(sc, SA_DIAG, 23, &data);
965 sc->stats.phy.dsattenuation = (data & 0xff) / 2;
967 ret = uea_read_cmv(sc, SA_DIAG, 47, &data);
970 sc->stats.phy.usattenuation = (data & 0xff) / 2;
972 ret = uea_read_cmv(sc, SA_DIAG, 25, &sc->stats.phy.dsmargin);
976 ret = uea_read_cmv(sc, SA_DIAG, 49, &sc->stats.phy.usmargin);
980 ret = uea_read_cmv(sc, SA_DIAG, 51, &sc->stats.phy.rxflow);
984 ret = uea_read_cmv(sc, SA_DIAG, 52, &sc->stats.phy.txflow);
988 ret = uea_read_cmv(sc, SA_DIAG, 54, &sc->stats.phy.dsunc);
993 ret = uea_read_cmv(sc, SA_DIAG, 58, &sc->stats.phy.usunc);
997 ret = uea_read_cmv(sc, SA_DIAG, 53, &sc->stats.phy.dscorr);
1001 /* only for atu-c */
1002 ret = uea_read_cmv(sc, SA_DIAG, 57, &sc->stats.phy.uscorr);
1006 ret = uea_read_cmv(sc, SA_INFO, 8, &sc->stats.phy.vidco);
1010 ret = uea_read_cmv(sc, SA_INFO, 13, &sc->stats.phy.vidcpe);
1017 static int request_cmvs(struct uea_softc *sc,
1018 struct uea_cmvs **cmvs, const struct firmware **fw)
1023 char cmv_name[FIRMWARE_NAME_MAX]; /* 30 bytes stack variable */
1025 if (cmv_file[sc->modem_index] == NULL) {
1026 if (UEA_CHIP_VERSION(sc) == ADI930)
1027 file = (IS_ISDN(sc->usb_dev)) ? "CMV9i.bin" : "CMV9p.bin";
1029 file = (IS_ISDN(sc->usb_dev)) ? "CMVei.bin" : "CMVep.bin";
1031 file = cmv_file[sc->modem_index];
1033 strcpy(cmv_name, FW_DIR);
1034 strlcat(cmv_name, file, sizeof(cmv_name));
1036 ret = request_firmware(fw, cmv_name, &sc->usb_dev->dev);
1038 uea_err(INS_TO_USBDEV(sc),
1039 "requesting firmware %s failed with error %d\n",
1044 data = (u8 *) (*fw)->data;
1045 size = *data * sizeof(struct uea_cmvs) + 1;
1046 if (size != (*fw)->size) {
1047 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n",
1049 release_firmware(*fw);
1053 *cmvs = (struct uea_cmvs *)(data + 1);
1057 /* Start boot post firmware modem:
1058 * - send reset commands through usb control pipe
1059 * - start workqueue for DSP loading
1060 * - send CMV options to modem
1063 static int uea_start_reset(struct uea_softc *sc)
1065 u16 zero = 0; /* ;-) */
1067 struct uea_cmvs *cmvs;
1068 const struct firmware *cmvs_fw;
1070 uea_enters(INS_TO_USBDEV(sc));
1071 uea_info(INS_TO_USBDEV(sc), "(re)booting started\n");
1073 /* mask interrupt */
1075 /* We need to set this here because, a ack timeout could have occured,
1076 * but before we start the reboot, the ack occurs and set this to 1.
1077 * So we will failed to wait Ready CMV.
1080 UPDATE_ATM_STAT(signal, ATM_PHY_SIG_LOST);
1082 /* reset statistics */
1083 memset(&sc->stats, 0, sizeof(struct uea_stats));
1085 /* tell the modem that we want to boot in IDMA mode */
1086 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_ON, 0, NULL);
1087 uea_request(sc, UEA_SET_MODE, UEA_BOOT_IDMA, 0, NULL);
1089 /* enter reset mode */
1090 uea_request(sc, UEA_SET_MODE, UEA_START_RESET, 0, NULL);
1092 /* original driver use 200ms, but windows driver use 100ms */
1095 /* leave reset mode */
1096 uea_request(sc, UEA_SET_MODE, UEA_END_RESET, 0, NULL);
1098 /* clear tx and rx mailboxes */
1099 uea_request(sc, UEA_SET_2183_DATA, UEA_MPTX_MAILBOX, 2, &zero);
1100 uea_request(sc, UEA_SET_2183_DATA, UEA_MPRX_MAILBOX, 2, &zero);
1101 uea_request(sc, UEA_SET_2183_DATA, UEA_SWAP_MAILBOX, 2, &zero);
1104 sc->cmv_function = MAKEFUNCTION(ADSLDIRECTIVE, MODEMREADY);
1105 /* demask interrupt */
1108 /* start loading DSP */
1111 schedule_work(&sc->task);
1113 /* wait for modem ready CMV */
1114 ret = wait_cmv_ack(sc);
1118 uea_vdbg(INS_TO_USBDEV(sc), "Ready CMV received\n");
1120 /* Enter in R-IDLE (cmv) until instructed otherwise */
1121 ret = uea_write_cmv(sc, SA_CNTL, 0, 1);
1125 /* Dump firmware version */
1126 ret = uea_read_cmv(sc, SA_INFO, 10, &sc->stats.phy.firmid);
1129 uea_info(INS_TO_USBDEV(sc), "ATU-R firmware version : %x\n",
1130 sc->stats.phy.firmid);
1133 ret = len = request_cmvs(sc, &cmvs, &cmvs_fw);
1138 for (i = 0; i < len; i++) {
1139 ret = uea_write_cmv(sc, FW_GET_LONG(&cmvs[i].address),
1140 FW_GET_WORD(&cmvs[i].offset),
1141 FW_GET_LONG(&cmvs[i].data));
1145 /* Enter in R-ACT-REQ */
1146 ret = uea_write_cmv(sc, SA_CNTL, 0, 2);
1147 uea_vdbg(INS_TO_USBDEV(sc), "Entering in R-ACT-REQ state\n");
1148 uea_info(INS_TO_USBDEV(sc), "Modem started, "
1149 "waiting synchronization\n");
1151 release_firmware(cmvs_fw);
1153 uea_leaves(INS_TO_USBDEV(sc));
1158 * In case of an error wait 1s before rebooting the modem
1159 * if the modem don't request reboot (-EAGAIN).
1160 * Monitor the modem every 1s.
1163 static int uea_kthread(void *data)
1165 struct uea_softc *sc = data;
1168 uea_enters(INS_TO_USBDEV(sc));
1169 while (!kthread_should_stop()) {
1170 if (ret < 0 || sc->reset)
1171 ret = uea_start_reset(sc);
1175 msleep_interruptible(1000);
1176 if (try_to_freeze())
1177 uea_err(INS_TO_USBDEV(sc), "suspend/resume not supported, "
1178 "please unplug/replug your modem\n");
1180 uea_leaves(INS_TO_USBDEV(sc));
1184 /* Load second usb firmware for ADI930 chip */
1185 static int load_XILINX_firmware(struct uea_softc *sc)
1187 const struct firmware *fw_entry;
1188 int ret, size, u, ln;
1190 char *fw_name = FW_DIR "930-fpga.bin";
1192 uea_enters(INS_TO_USBDEV(sc));
1194 ret = request_firmware(&fw_entry, fw_name, &sc->usb_dev->dev);
1196 uea_err(INS_TO_USBDEV(sc), "firmware %s is not available\n",
1201 pfw = fw_entry->data;
1202 size = fw_entry->size;
1203 if (size != 0x577B) {
1204 uea_err(INS_TO_USBDEV(sc), "firmware %s is corrupted\n",
1209 for (u = 0; u < size; u += ln) {
1210 ln = min(size - u, 64);
1211 ret = uea_request(sc, 0xe, 0, ln, pfw + u);
1213 uea_err(INS_TO_USBDEV(sc),
1214 "elsa download data failed (%d)\n", ret);
1219 /* finish to send the fpga */
1220 ret = uea_request(sc, 0xe, 1, 0, NULL);
1222 uea_err(INS_TO_USBDEV(sc),
1223 "elsa download data failed (%d)\n", ret);
1227 /* Tell the modem we finish : de-assert reset */
1229 ret = uea_send_modem_cmd(sc->usb_dev, 0xe, 1, &value);
1231 uea_err(sc->usb_dev, "elsa de-assert failed with error %d\n", ret);
1235 release_firmware(fw_entry);
1237 uea_leaves(INS_TO_USBDEV(sc));
1241 /* The modem send us an ack. First with check if it right */
1242 static void uea_dispatch_cmv(struct uea_softc *sc, struct cmv* cmv)
1244 uea_enters(INS_TO_USBDEV(sc));
1245 if (le16_to_cpu(cmv->wPreamble) != PREAMBLE)
1248 if (cmv->bDirection != MODEMTOHOST)
1251 /* FIXME : ADI930 reply wrong preambule (func = 2, sub = 2) to
1252 * the first MEMACESS cmv. Ignore it...
1254 if (cmv->bFunction != sc->cmv_function) {
1255 if (UEA_CHIP_VERSION(sc) == ADI930
1256 && cmv->bFunction == MAKEFUNCTION(2, 2)) {
1257 cmv->wIndex = cpu_to_le16(sc->cmv_idx);
1258 put_unaligned(cpu_to_le32(sc->cmv_address), &cmv->dwSymbolicAddress);
1259 cmv->wOffsetAddress = cpu_to_le16(sc->cmv_offset);
1265 if (cmv->bFunction == MAKEFUNCTION(ADSLDIRECTIVE, MODEMREADY)) {
1266 wake_up_cmv_ack(sc);
1267 uea_leaves(INS_TO_USBDEV(sc));
1271 /* in case of MEMACCESS */
1272 if (le16_to_cpu(cmv->wIndex) != sc->cmv_idx ||
1273 le32_to_cpu(get_unaligned(&cmv->dwSymbolicAddress)) !=
1275 || le16_to_cpu(cmv->wOffsetAddress) != sc->cmv_offset)
1278 sc->data = le32_to_cpu(get_unaligned(&cmv->dwData));
1279 sc->data = sc->data << 16 | sc->data >> 16;
1281 wake_up_cmv_ack(sc);
1282 uea_leaves(INS_TO_USBDEV(sc));
1286 uea_err(INS_TO_USBDEV(sc), "unexpected cmv received,"
1287 "Function : %d, Subfunction : %d\n",
1288 FUNCTION_TYPE(cmv->bFunction),
1289 FUNCTION_SUBTYPE(cmv->bFunction));
1290 uea_leaves(INS_TO_USBDEV(sc));
1294 uea_err(INS_TO_USBDEV(sc), "invalid cmv received, "
1295 "wPreamble %d, bDirection %d\n",
1296 le16_to_cpu(cmv->wPreamble), cmv->bDirection);
1297 uea_leaves(INS_TO_USBDEV(sc));
1303 static void uea_intr(struct urb *urb)
1305 struct uea_softc *sc = urb->context;
1306 struct intr_pkt *intr = urb->transfer_buffer;
1307 uea_enters(INS_TO_USBDEV(sc));
1309 if (unlikely(urb->status < 0)) {
1310 uea_err(INS_TO_USBDEV(sc), "uea_intr() failed with %d\n",
1315 /* device-to-host interrupt */
1316 if (intr->bType != 0x08 || sc->booting) {
1317 uea_err(INS_TO_USBDEV(sc), "wrong interrupt\n");
1321 switch (le16_to_cpu(intr->wInterrupt)) {
1322 case INT_LOADSWAPPAGE:
1323 sc->pageno = intr->bSwapPageNo;
1324 sc->ovl = intr->bOvl >> 4 | intr->bOvl << 4;
1325 schedule_work(&sc->task);
1328 case INT_INCOMINGCMV:
1329 uea_dispatch_cmv(sc, &intr->u.s2.cmv);
1333 uea_err(INS_TO_USBDEV(sc), "unknown interrupt %u\n",
1334 le16_to_cpu(intr->wInterrupt));
1338 usb_submit_urb(sc->urb_int, GFP_ATOMIC);
1342 * Start the modem : init the data and start kernel thread
1344 static int uea_boot(struct uea_softc *sc)
1347 struct intr_pkt *intr;
1349 uea_enters(INS_TO_USBDEV(sc));
1351 INIT_WORK(&sc->task, uea_load_page);
1352 init_waitqueue_head(&sc->sync_q);
1353 init_waitqueue_head(&sc->cmv_ack_wait);
1355 if (UEA_CHIP_VERSION(sc) == ADI930)
1356 load_XILINX_firmware(sc);
1358 intr = kmalloc(INTR_PKT_SIZE, GFP_KERNEL);
1360 uea_err(INS_TO_USBDEV(sc),
1361 "cannot allocate interrupt package\n");
1362 uea_leaves(INS_TO_USBDEV(sc));
1366 sc->urb_int = usb_alloc_urb(0, GFP_KERNEL);
1368 uea_err(INS_TO_USBDEV(sc), "cannot allocate interrupt URB\n");
1372 usb_fill_int_urb(sc->urb_int, sc->usb_dev,
1373 usb_rcvintpipe(sc->usb_dev, UEA_INTR_PIPE),
1374 intr, INTR_PKT_SIZE, uea_intr, sc,
1375 sc->usb_dev->actconfig->interface[0]->altsetting[0].
1376 endpoint[0].desc.bInterval);
1378 ret = usb_submit_urb(sc->urb_int, GFP_KERNEL);
1380 uea_err(INS_TO_USBDEV(sc),
1381 "urb submition failed with error %d\n", ret);
1385 sc->kthread = kthread_run(uea_kthread, sc, "ueagle-atm");
1386 if (sc->kthread == ERR_PTR(-ENOMEM)) {
1387 uea_err(INS_TO_USBDEV(sc), "failed to create thread\n");
1391 uea_leaves(INS_TO_USBDEV(sc));
1395 usb_kill_urb(sc->urb_int);
1397 usb_free_urb(sc->urb_int);
1400 uea_leaves(INS_TO_USBDEV(sc));
1405 * Stop the modem : kill kernel thread and free data
1407 static void uea_stop(struct uea_softc *sc)
1410 uea_enters(INS_TO_USBDEV(sc));
1411 ret = kthread_stop(sc->kthread);
1412 uea_dbg(INS_TO_USBDEV(sc), "kthread finish with status %d\n", ret);
1414 /* stop any pending boot process */
1415 flush_scheduled_work();
1417 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_ON, 0, NULL);
1419 usb_kill_urb(sc->urb_int);
1420 kfree(sc->urb_int->transfer_buffer);
1421 usb_free_urb(sc->urb_int);
1424 release_firmware(sc->dsp_firm);
1425 uea_leaves(INS_TO_USBDEV(sc));
1428 /* syfs interface */
1429 static struct uea_softc *dev_to_uea(struct device *dev)
1431 struct usb_interface *intf;
1432 struct usbatm_data *usbatm;
1434 intf = to_usb_interface(dev);
1438 usbatm = usb_get_intfdata(intf);
1442 return usbatm->driver_data;
1445 static ssize_t read_status(struct device *dev, struct device_attribute *attr,
1449 struct uea_softc *sc;
1451 mutex_lock(&uea_mutex);
1452 sc = dev_to_uea(dev);
1455 ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.state);
1457 mutex_unlock(&uea_mutex);
1461 static ssize_t reboot(struct device *dev, struct device_attribute *attr,
1462 const char *buf, size_t count)
1465 struct uea_softc *sc;
1467 mutex_lock(&uea_mutex);
1468 sc = dev_to_uea(dev);
1474 mutex_unlock(&uea_mutex);
1478 static DEVICE_ATTR(stat_status, S_IWUGO | S_IRUGO, read_status, reboot);
1480 static ssize_t read_human_status(struct device *dev, struct device_attribute *attr,
1484 struct uea_softc *sc;
1486 mutex_lock(&uea_mutex);
1487 sc = dev_to_uea(dev);
1491 switch (GET_STATUS(sc->stats.phy.state)) {
1493 ret = sprintf(buf, "Modem is booting\n");
1496 ret = sprintf(buf, "Modem is initializing\n");
1499 ret = sprintf(buf, "Modem is operational\n");
1502 ret = sprintf(buf, "Modem synchronization failed\n");
1506 mutex_unlock(&uea_mutex);
1510 static DEVICE_ATTR(stat_human_status, S_IWUGO | S_IRUGO, read_human_status, NULL);
1512 static ssize_t read_delin(struct device *dev, struct device_attribute *attr,
1516 struct uea_softc *sc;
1518 mutex_lock(&uea_mutex);
1519 sc = dev_to_uea(dev);
1523 if (sc->stats.phy.flags & 0x0C00)
1524 ret = sprintf(buf, "ERROR\n");
1525 else if (sc->stats.phy.flags & 0x0030)
1526 ret = sprintf(buf, "LOSS\n");
1528 ret = sprintf(buf, "GOOD\n");
1530 mutex_unlock(&uea_mutex);
1534 static DEVICE_ATTR(stat_delin, S_IWUGO | S_IRUGO, read_delin, NULL);
1536 #define UEA_ATTR(name, reset) \
1538 static ssize_t read_##name(struct device *dev, \
1539 struct device_attribute *attr, char *buf) \
1541 int ret = -ENODEV; \
1542 struct uea_softc *sc; \
1544 mutex_lock(&uea_mutex); \
1545 sc = dev_to_uea(dev); \
1548 ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.name); \
1550 sc->stats.phy.name = 0; \
1552 mutex_unlock(&uea_mutex); \
1556 static DEVICE_ATTR(stat_##name, S_IRUGO, read_##name, NULL)
1558 UEA_ATTR(mflags, 1);
1559 UEA_ATTR(vidcpe, 0);
1560 UEA_ATTR(usrate, 0);
1561 UEA_ATTR(dsrate, 0);
1562 UEA_ATTR(usattenuation, 0);
1563 UEA_ATTR(dsattenuation, 0);
1564 UEA_ATTR(usmargin, 0);
1565 UEA_ATTR(dsmargin, 0);
1566 UEA_ATTR(txflow, 0);
1567 UEA_ATTR(rxflow, 0);
1568 UEA_ATTR(uscorr, 0);
1569 UEA_ATTR(dscorr, 0);
1572 UEA_ATTR(firmid, 0);
1574 /* Retrieve the device End System Identifier (MAC) */
1576 #define htoi(x) (isdigit(x) ? x-'0' : toupper(x)-'A'+10)
1577 static int uea_getesi(struct uea_softc *sc, u_char * esi)
1579 unsigned char mac_str[2 * ETH_ALEN + 1];
1582 (sc->usb_dev, sc->usb_dev->descriptor.iSerialNumber, mac_str,
1583 sizeof(mac_str)) != 2 * ETH_ALEN)
1586 for (i = 0; i < ETH_ALEN; i++)
1587 esi[i] = htoi(mac_str[2 * i]) * 16 + htoi(mac_str[2 * i + 1]);
1593 static int uea_atm_open(struct usbatm_data *usbatm, struct atm_dev *atm_dev)
1595 struct uea_softc *sc = usbatm->driver_data;
1597 return uea_getesi(sc, atm_dev->esi);
1600 static int uea_heavy(struct usbatm_data *usbatm, struct usb_interface *intf)
1602 struct uea_softc *sc = usbatm->driver_data;
1604 wait_event_interruptible(sc->sync_q, IS_OPERATIONAL(sc));
1610 static int claim_interface(struct usb_device *usb_dev,
1611 struct usbatm_data *usbatm, int ifnum)
1614 struct usb_interface *intf = usb_ifnum_to_if(usb_dev, ifnum);
1617 uea_err(usb_dev, "interface %d not found\n", ifnum);
1621 ret = usb_driver_claim_interface(&uea_driver, intf, usbatm);
1623 uea_err(usb_dev, "can't claim interface %d, error %d\n", ifnum,
1628 static struct attribute *attrs[] = {
1629 &dev_attr_stat_status.attr,
1630 &dev_attr_stat_mflags.attr,
1631 &dev_attr_stat_human_status.attr,
1632 &dev_attr_stat_delin.attr,
1633 &dev_attr_stat_vidcpe.attr,
1634 &dev_attr_stat_usrate.attr,
1635 &dev_attr_stat_dsrate.attr,
1636 &dev_attr_stat_usattenuation.attr,
1637 &dev_attr_stat_dsattenuation.attr,
1638 &dev_attr_stat_usmargin.attr,
1639 &dev_attr_stat_dsmargin.attr,
1640 &dev_attr_stat_txflow.attr,
1641 &dev_attr_stat_rxflow.attr,
1642 &dev_attr_stat_uscorr.attr,
1643 &dev_attr_stat_dscorr.attr,
1644 &dev_attr_stat_usunc.attr,
1645 &dev_attr_stat_dsunc.attr,
1646 &dev_attr_stat_firmid.attr,
1649 static struct attribute_group attr_grp = {
1653 static int uea_bind(struct usbatm_data *usbatm, struct usb_interface *intf,
1654 const struct usb_device_id *id)
1656 struct usb_device *usb = interface_to_usbdev(intf);
1657 struct uea_softc *sc;
1658 int ret, ifnum = intf->altsetting->desc.bInterfaceNumber;
1662 /* interface 0 is for firmware/monitoring */
1663 if (ifnum != UEA_INTR_IFACE_NO)
1666 usbatm->flags = (sync_wait[modem_index] ? 0 : UDSL_SKIP_HEAVY_INIT);
1668 /* interface 1 is for outbound traffic */
1669 ret = claim_interface(usb, usbatm, UEA_US_IFACE_NO);
1673 /* ADI930 has only 2 interfaces and inbound traffic is on interface 1 */
1674 if (UEA_CHIP_VERSION(id) != ADI930) {
1675 /* interface 2 is for inbound traffic */
1676 ret = claim_interface(usb, usbatm, UEA_DS_IFACE_NO);
1681 sc = kzalloc(sizeof(struct uea_softc), GFP_KERNEL);
1683 uea_err(usb, "uea_init: not enough memory !\n");
1688 usbatm->driver_data = sc;
1689 sc->usbatm = usbatm;
1690 sc->modem_index = (modem_index < NB_MODEM) ? modem_index++ : 0;
1691 sc->driver_info = id->driver_info;
1693 /* ADI930 don't support iso */
1694 if (UEA_CHIP_VERSION(id) != ADI930 && use_iso[sc->modem_index]) {
1697 /* try set fastest alternate for inbound traffic interface */
1698 for (i = FASTEST_ISO_INTF; i > 0; i--)
1699 if (usb_set_interface(usb, UEA_DS_IFACE_NO, i) == 0)
1703 uea_dbg(usb, "set alternate %d for 2 interface\n", i);
1704 uea_info(usb, "using iso mode\n");
1705 usbatm->flags |= UDSL_USE_ISOC | UDSL_IGNORE_EILSEQ;
1707 uea_err(usb, "setting any alternate failed for "
1708 "2 interface, using bulk mode\n");
1712 ret = sysfs_create_group(&intf->dev.kobj, &attr_grp);
1726 static void uea_unbind(struct usbatm_data *usbatm, struct usb_interface *intf)
1728 struct uea_softc *sc = usbatm->driver_data;
1730 sysfs_remove_group(&intf->dev.kobj, &attr_grp);
1735 static struct usbatm_driver uea_usbatm_driver = {
1736 .driver_name = "ueagle-atm",
1738 .atm_start = uea_atm_open,
1739 .unbind = uea_unbind,
1740 .heavy_init = uea_heavy,
1741 .bulk_in = UEA_BULK_DATA_PIPE,
1742 .bulk_out = UEA_BULK_DATA_PIPE,
1743 .isoc_in = UEA_ISO_DATA_PIPE,
1746 static int uea_probe(struct usb_interface *intf, const struct usb_device_id *id)
1748 struct usb_device *usb = interface_to_usbdev(intf);
1751 uea_info(usb, "ADSL device founded vid (%#X) pid (%#X) : %s %s\n",
1752 le16_to_cpu(usb->descriptor.idVendor),
1753 le16_to_cpu(usb->descriptor.idProduct),
1754 chip_name[UEA_CHIP_VERSION(id)], IS_ISDN(usb)?"isdn":"pots");
1756 usb_reset_device(usb);
1758 if (UEA_IS_PREFIRM(id))
1759 return uea_load_firmware(usb, UEA_CHIP_VERSION(id));
1761 return usbatm_usb_probe(intf, id, &uea_usbatm_driver);
1764 static void uea_disconnect(struct usb_interface *intf)
1766 struct usb_device *usb = interface_to_usbdev(intf);
1767 int ifnum = intf->altsetting->desc.bInterfaceNumber;
1770 /* ADI930 has 2 interfaces and eagle 3 interfaces.
1771 * Pre-firmware device has one interface
1773 if (usb->config->desc.bNumInterfaces != 1 && ifnum == 0) {
1774 mutex_lock(&uea_mutex);
1775 usbatm_usb_disconnect(intf);
1776 mutex_unlock(&uea_mutex);
1777 uea_info(usb, "ADSL device removed\n");
1784 * List of supported VID/PID
1786 static const struct usb_device_id uea_ids[] = {
1787 {USB_DEVICE(ELSA_VID, ELSA_PID_PREFIRM), .driver_info = ADI930 | PREFIRM},
1788 {USB_DEVICE(ELSA_VID, ELSA_PID_PSTFIRM), .driver_info = ADI930 | PSTFIRM},
1789 {USB_DEVICE(EAGLE_VID, EAGLE_I_PID_PREFIRM), .driver_info = EAGLE_I | PREFIRM},
1790 {USB_DEVICE(EAGLE_VID, EAGLE_I_PID_PSTFIRM), .driver_info = EAGLE_I | PSTFIRM},
1791 {USB_DEVICE(EAGLE_VID, EAGLE_II_PID_PREFIRM), .driver_info = EAGLE_II | PREFIRM},
1792 {USB_DEVICE(EAGLE_VID, EAGLE_II_PID_PSTFIRM), .driver_info = EAGLE_II | PSTFIRM},
1793 {USB_DEVICE(EAGLE_VID, EAGLE_IIC_PID_PREFIRM), .driver_info = EAGLE_II | PREFIRM},
1794 {USB_DEVICE(EAGLE_VID, EAGLE_IIC_PID_PSTFIRM), .driver_info = EAGLE_II | PSTFIRM},
1795 {USB_DEVICE(EAGLE_VID, EAGLE_III_PID_PREFIRM), .driver_info = EAGLE_III | PREFIRM},
1796 {USB_DEVICE(EAGLE_VID, EAGLE_III_PID_PSTFIRM), .driver_info = EAGLE_III | PSTFIRM},
1797 {USB_DEVICE(USR_VID, MILLER_A_PID_PREFIRM), .driver_info = EAGLE_I | PREFIRM},
1798 {USB_DEVICE(USR_VID, MILLER_A_PID_PSTFIRM), .driver_info = EAGLE_I | PSTFIRM},
1799 {USB_DEVICE(USR_VID, MILLER_B_PID_PREFIRM), .driver_info = EAGLE_I | PREFIRM},
1800 {USB_DEVICE(USR_VID, MILLER_B_PID_PSTFIRM), .driver_info = EAGLE_I | PSTFIRM},
1801 {USB_DEVICE(USR_VID, HEINEKEN_A_PID_PREFIRM),.driver_info = EAGLE_I | PREFIRM},
1802 {USB_DEVICE(USR_VID, HEINEKEN_A_PID_PSTFIRM),.driver_info = EAGLE_I | PSTFIRM},
1803 {USB_DEVICE(USR_VID, HEINEKEN_B_PID_PREFIRM),.driver_info = EAGLE_I | PREFIRM},
1804 {USB_DEVICE(USR_VID, HEINEKEN_B_PID_PSTFIRM),.driver_info = EAGLE_I | PSTFIRM},
1809 * USB driver descriptor
1811 static struct usb_driver uea_driver = {
1812 .name = "ueagle-atm",
1813 .id_table = uea_ids,
1815 .disconnect = uea_disconnect,
1818 MODULE_DEVICE_TABLE(usb, uea_ids);
1821 * uea_init - Initialize the module.
1822 * Register to USB subsystem
1824 static int __init uea_init(void)
1826 printk(KERN_INFO "[ueagle-atm] driver " EAGLEUSBVERSION " loaded\n");
1828 usb_register(&uea_driver);
1833 module_init(uea_init);
1836 * uea_exit - Destroy module
1837 * Deregister with USB subsystem
1839 static void __exit uea_exit(void)
1842 * This calls automatically the uea_disconnect method if necessary:
1844 usb_deregister(&uea_driver);
1846 printk(KERN_INFO "[ueagle-atm] driver unloaded\n");
1849 module_exit(uea_exit);
1851 MODULE_AUTHOR("Damien Bergamini/Matthieu Castet/Stanislaw W. Gruszka");
1852 MODULE_DESCRIPTION("ADI 930/Eagle USB ADSL Modem driver");
1853 MODULE_LICENSE("Dual BSD/GPL");