cxacru.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878
  1. /******************************************************************************
  2. * cxacru.c - driver for USB ADSL modems based on
  3. * Conexant AccessRunner chipset
  4. *
  5. * Copyright (C) 2004 David Woodhouse, Duncan Sands, Roman Kagan
  6. * Copyright (C) 2005 Duncan Sands, Roman Kagan (rkagan % mail ! ru)
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the Free
  10. * Software Foundation; either version 2 of the License, or (at your option)
  11. * any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  16. * more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along with
  19. * this program; if not, write to the Free Software Foundation, Inc., 59
  20. * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. *
  22. ******************************************************************************/
  23. /*
  24. * Credit is due for Josep Comas, who created the original patch to speedtch.c
  25. * to support the different padding used by the AccessRunner (now generalized
  26. * into usbatm), and the userspace firmware loading utility.
  27. */
  28. #include <linux/module.h>
  29. #include <linux/moduleparam.h>
  30. #include <linux/kernel.h>
  31. #include <linux/timer.h>
  32. #include <linux/errno.h>
  33. #include <linux/slab.h>
  34. #include <linux/init.h>
  35. #include <linux/device.h> /* FIXME: linux/firmware.h should include it itself */
  36. #include <linux/firmware.h>
  37. #include "usbatm.h"
  38. #define DRIVER_AUTHOR "Roman Kagan, David Woodhouse, Duncan Sands"
  39. #define DRIVER_VERSION "0.2"
  40. #define DRIVER_DESC "Conexant AccessRunner ADSL USB modem driver"
  41. static const char cxacru_driver_name[] = "cxacru";
  42. #define CXACRU_EP_CMD 0x01 /* Bulk/interrupt in/out */
  43. #define CXACRU_EP_DATA 0x02 /* Bulk in/out */
  44. #define CMD_PACKET_SIZE 64 /* Should be maxpacket(ep)? */
  45. /* Addresses */
  46. #define PLLFCLK_ADDR 0x00350068
  47. #define PLLBCLK_ADDR 0x0035006c
  48. #define SDRAMEN_ADDR 0x00350010
  49. #define FW_ADDR 0x00801000
  50. #define BR_ADDR 0x00180600
  51. #define SIG_ADDR 0x00180500
  52. #define BR_STACK_ADDR 0x00187f10
  53. /* Values */
  54. #define SDRAM_ENA 0x1
  55. #define CMD_TIMEOUT 2000 /* msecs */
  56. #define POLL_INTERVAL 5000 /* msecs */
  57. /* commands for interaction with the modem through the control channel before
  58. * firmware is loaded */
  59. enum cxacru_fw_request {
  60. FW_CMD_ERR,
  61. FW_GET_VER,
  62. FW_READ_MEM,
  63. FW_WRITE_MEM,
  64. FW_RMW_MEM,
  65. FW_CHECKSUM_MEM,
  66. FW_GOTO_MEM,
  67. };
  68. /* commands for interaction with the modem through the control channel once
  69. * firmware is loaded */
  70. enum cxacru_cm_request {
  71. CM_REQUEST_UNDEFINED = 0x80,
  72. CM_REQUEST_TEST,
  73. CM_REQUEST_CHIP_GET_MAC_ADDRESS,
  74. CM_REQUEST_CHIP_GET_DP_VERSIONS,
  75. CM_REQUEST_CHIP_ADSL_LINE_START,
  76. CM_REQUEST_CHIP_ADSL_LINE_STOP,
  77. CM_REQUEST_CHIP_ADSL_LINE_GET_STATUS,
  78. CM_REQUEST_CHIP_ADSL_LINE_GET_SPEED,
  79. CM_REQUEST_CARD_INFO_GET,
  80. CM_REQUEST_CARD_DATA_GET,
  81. CM_REQUEST_CARD_DATA_SET,
  82. CM_REQUEST_COMMAND_HW_IO,
  83. CM_REQUEST_INTERFACE_HW_IO,
  84. CM_REQUEST_CARD_SERIAL_DATA_PATH_GET,
  85. CM_REQUEST_CARD_SERIAL_DATA_PATH_SET,
  86. CM_REQUEST_CARD_CONTROLLER_VERSION_GET,
  87. CM_REQUEST_CARD_GET_STATUS,
  88. CM_REQUEST_CARD_GET_MAC_ADDRESS,
  89. CM_REQUEST_CARD_GET_DATA_LINK_STATUS,
  90. CM_REQUEST_MAX,
  91. };
  92. /* reply codes to the commands above */
  93. enum cxacru_cm_status {
  94. CM_STATUS_UNDEFINED,
  95. CM_STATUS_SUCCESS,
  96. CM_STATUS_ERROR,
  97. CM_STATUS_UNSUPPORTED,
  98. CM_STATUS_UNIMPLEMENTED,
  99. CM_STATUS_PARAMETER_ERROR,
  100. CM_STATUS_DBG_LOOPBACK,
  101. CM_STATUS_MAX,
  102. };
  103. /* indices into CARD_INFO_GET return array */
  104. enum cxacru_info_idx {
  105. CXINF_DOWNSTREAM_RATE,
  106. CXINF_UPSTREAM_RATE,
  107. CXINF_LINK_STATUS,
  108. CXINF_LINE_STATUS,
  109. CXINF_MAC_ADDRESS_HIGH,
  110. CXINF_MAC_ADDRESS_LOW,
  111. CXINF_UPSTREAM_SNR_MARGIN,
  112. CXINF_DOWNSTREAM_SNR_MARGIN,
  113. CXINF_UPSTREAM_ATTENUATION,
  114. CXINF_DOWNSTREAM_ATTENUATION,
  115. CXINF_TRANSMITTER_POWER,
  116. CXINF_UPSTREAM_BITS_PER_FRAME,
  117. CXINF_DOWNSTREAM_BITS_PER_FRAME,
  118. CXINF_STARTUP_ATTEMPTS,
  119. CXINF_UPSTREAM_CRC_ERRORS,
  120. CXINF_DOWNSTREAM_CRC_ERRORS,
  121. CXINF_UPSTREAM_FEC_ERRORS,
  122. CXINF_DOWNSTREAM_FEC_ERRORS,
  123. CXINF_UPSTREAM_HEC_ERRORS,
  124. CXINF_DOWNSTREAM_HEC_ERRORS,
  125. CXINF_LINE_STARTABLE,
  126. CXINF_MODULATION,
  127. CXINF_ADSL_HEADEND,
  128. CXINF_ADSL_HEADEND_ENVIRONMENT,
  129. CXINF_CONTROLLER_VERSION,
  130. /* dunno what the missing two mean */
  131. CXINF_MAX = 0x1c,
  132. };
  133. struct cxacru_modem_type {
  134. u32 pll_f_clk;
  135. u32 pll_b_clk;
  136. int boot_rom_patch;
  137. };
  138. struct cxacru_data {
  139. struct usbatm_data *usbatm;
  140. const struct cxacru_modem_type *modem_type;
  141. int line_status;
  142. struct work_struct poll_work;
  143. /* contol handles */
  144. struct semaphore cm_serialize;
  145. u8 *rcv_buf;
  146. u8 *snd_buf;
  147. struct urb *rcv_urb;
  148. struct urb *snd_urb;
  149. struct completion rcv_done;
  150. struct completion snd_done;
  151. };
  152. /* the following three functions are stolen from drivers/usb/core/message.c */
  153. static void cxacru_blocking_completion(struct urb *urb, struct pt_regs *regs)
  154. {
  155. complete((struct completion *)urb->context);
  156. }
  157. static void cxacru_timeout_kill(unsigned long data)
  158. {
  159. usb_unlink_urb((struct urb *) data);
  160. }
  161. static int cxacru_start_wait_urb(struct urb *urb, struct completion *done,
  162. int* actual_length)
  163. {
  164. struct timer_list timer;
  165. int status;
  166. init_timer(&timer);
  167. timer.expires = jiffies + msecs_to_jiffies(CMD_TIMEOUT);
  168. timer.data = (unsigned long) urb;
  169. timer.function = cxacru_timeout_kill;
  170. add_timer(&timer);
  171. wait_for_completion(done);
  172. status = urb->status;
  173. if (status == -ECONNRESET)
  174. status = -ETIMEDOUT;
  175. del_timer_sync(&timer);
  176. if (actual_length)
  177. *actual_length = urb->actual_length;
  178. return status;
  179. }
  180. static int cxacru_cm(struct cxacru_data *instance, enum cxacru_cm_request cm,
  181. u8 *wdata, int wsize, u8 *rdata, int rsize)
  182. {
  183. int ret, actlen;
  184. int offb, offd;
  185. const int stride = CMD_PACKET_SIZE - 4;
  186. u8 *wbuf = instance->snd_buf;
  187. u8 *rbuf = instance->rcv_buf;
  188. int wbuflen = ((wsize - 1) / stride + 1) * CMD_PACKET_SIZE;
  189. int rbuflen = ((rsize - 1) / stride + 1) * CMD_PACKET_SIZE;
  190. if (wbuflen > PAGE_SIZE || rbuflen > PAGE_SIZE) {
  191. dbg("too big transfer requested");
  192. ret = -ENOMEM;
  193. goto fail;
  194. }
  195. down(&instance->cm_serialize);
  196. /* submit reading urb before the writing one */
  197. init_completion(&instance->rcv_done);
  198. ret = usb_submit_urb(instance->rcv_urb, GFP_KERNEL);
  199. if (ret < 0) {
  200. dbg("submitting read urb for cm %#x failed", cm);
  201. ret = ret;
  202. goto fail;
  203. }
  204. memset(wbuf, 0, wbuflen);
  205. /* handle wsize == 0 */
  206. wbuf[0] = cm;
  207. for (offb = offd = 0; offd < wsize; offd += stride, offb += CMD_PACKET_SIZE) {
  208. wbuf[offb] = cm;
  209. memcpy(wbuf + offb + 4, wdata + offd, min_t(int, stride, wsize - offd));
  210. }
  211. instance->snd_urb->transfer_buffer_length = wbuflen;
  212. init_completion(&instance->snd_done);
  213. ret = usb_submit_urb(instance->snd_urb, GFP_KERNEL);
  214. if (ret < 0) {
  215. dbg("submitting write urb for cm %#x failed", cm);
  216. ret = ret;
  217. goto fail;
  218. }
  219. ret = cxacru_start_wait_urb(instance->snd_urb, &instance->snd_done, NULL);
  220. if (ret < 0) {
  221. dbg("sending cm %#x failed", cm);
  222. ret = ret;
  223. goto fail;
  224. }
  225. ret = cxacru_start_wait_urb(instance->rcv_urb, &instance->rcv_done, &actlen);
  226. if (ret < 0) {
  227. dbg("receiving cm %#x failed", cm);
  228. ret = ret;
  229. goto fail;
  230. }
  231. if (actlen % CMD_PACKET_SIZE || !actlen) {
  232. dbg("response is not a positive multiple of %d: %#x",
  233. CMD_PACKET_SIZE, actlen);
  234. ret = -EIO;
  235. goto fail;
  236. }
  237. /* check the return status and copy the data to the output buffer, if needed */
  238. for (offb = offd = 0; offd < rsize && offb < actlen; offb += CMD_PACKET_SIZE) {
  239. if (rbuf[offb] != cm) {
  240. dbg("wrong cm %#x in response", rbuf[offb]);
  241. ret = -EIO;
  242. goto fail;
  243. }
  244. if (rbuf[offb + 1] != CM_STATUS_SUCCESS) {
  245. dbg("response failed: %#x", rbuf[offb + 1]);
  246. ret = -EIO;
  247. goto fail;
  248. }
  249. if (offd >= rsize)
  250. break;
  251. memcpy(rdata + offd, rbuf + offb + 4, min_t(int, stride, rsize - offd));
  252. offd += stride;
  253. }
  254. ret = offd;
  255. dbg("cm %#x", cm);
  256. fail:
  257. up(&instance->cm_serialize);
  258. return ret;
  259. }
  260. static int cxacru_cm_get_array(struct cxacru_data *instance, enum cxacru_cm_request cm,
  261. u32 *data, int size)
  262. {
  263. int ret, len;
  264. u32 *buf;
  265. int offb, offd;
  266. const int stride = CMD_PACKET_SIZE / (4 * 2) - 1;
  267. int buflen = ((size - 1) / stride + 1 + size * 2) * 4;
  268. buf = kmalloc(buflen, GFP_KERNEL);
  269. if (!buf)
  270. return -ENOMEM;
  271. ret = cxacru_cm(instance, cm, NULL, 0, (u8 *) buf, buflen);
  272. if (ret < 0)
  273. goto cleanup;
  274. /* len > 0 && len % 4 == 0 guaranteed by cxacru_cm() */
  275. len = ret / 4;
  276. for (offb = 0; offb < len; ) {
  277. int l = le32_to_cpu(buf[offb++]);
  278. if (l > stride || l > (len - offb) / 2) {
  279. dbg("wrong data length %#x in response", l);
  280. ret = -EIO;
  281. goto cleanup;
  282. }
  283. while (l--) {
  284. offd = le32_to_cpu(buf[offb++]);
  285. if (offd >= size) {
  286. dbg("wrong index %#x in response", offd);
  287. ret = -EIO;
  288. goto cleanup;
  289. }
  290. data[offd] = le32_to_cpu(buf[offb++]);
  291. }
  292. }
  293. ret = 0;
  294. cleanup:
  295. kfree(buf);
  296. return ret;
  297. }
  298. static int cxacru_card_status(struct cxacru_data *instance)
  299. {
  300. int ret = cxacru_cm(instance, CM_REQUEST_CARD_GET_STATUS, NULL, 0, NULL, 0);
  301. if (ret < 0) { /* firmware not loaded */
  302. dbg("cxacru_adsl_start: CARD_GET_STATUS returned %d", ret);
  303. return ret;
  304. }
  305. return 0;
  306. }
  307. static void cxacru_poll_status(struct cxacru_data *instance);
  308. static int cxacru_atm_start(struct usbatm_data *usbatm_instance,
  309. struct atm_dev *atm_dev)
  310. {
  311. struct cxacru_data *instance = usbatm_instance->driver_data;
  312. struct device *dev = &usbatm_instance->usb_intf->dev;
  313. /*
  314. struct atm_dev *atm_dev = usbatm_instance->atm_dev;
  315. */
  316. int ret;
  317. dbg("cxacru_atm_start");
  318. /* Read MAC address */
  319. ret = cxacru_cm(instance, CM_REQUEST_CARD_GET_MAC_ADDRESS, NULL, 0,
  320. atm_dev->esi, sizeof(atm_dev->esi));
  321. if (ret < 0) {
  322. dev_err(dev, "cxacru_atm_start: CARD_GET_MAC_ADDRESS returned %d\n", ret);
  323. return ret;
  324. }
  325. /* start ADSL */
  326. ret = cxacru_cm(instance, CM_REQUEST_CHIP_ADSL_LINE_START, NULL, 0, NULL, 0);
  327. if (ret < 0) {
  328. dev_err(dev, "cxacru_atm_start: CHIP_ADSL_LINE_START returned %d\n", ret);
  329. return ret;
  330. }
  331. /* Start status polling */
  332. cxacru_poll_status(instance);
  333. return 0;
  334. }
  335. static void cxacru_poll_status(struct cxacru_data *instance)
  336. {
  337. u32 buf[CXINF_MAX] = {};
  338. struct device *dev = &instance->usbatm->usb_intf->dev;
  339. struct atm_dev *atm_dev = instance->usbatm->atm_dev;
  340. int ret;
  341. ret = cxacru_cm_get_array(instance, CM_REQUEST_CARD_INFO_GET, buf, CXINF_MAX);
  342. if (ret < 0) {
  343. dev_warn(dev, "poll status: error %d\n", ret);
  344. goto reschedule;
  345. }
  346. if (instance->line_status == buf[CXINF_LINE_STATUS])
  347. goto reschedule;
  348. instance->line_status = buf[CXINF_LINE_STATUS];
  349. switch (instance->line_status) {
  350. case 0:
  351. atm_dev->signal = ATM_PHY_SIG_LOST;
  352. dev_info(dev, "ADSL line: down\n");
  353. break;
  354. case 1:
  355. atm_dev->signal = ATM_PHY_SIG_LOST;
  356. dev_info(dev, "ADSL line: attemtping to activate\n");
  357. break;
  358. case 2:
  359. atm_dev->signal = ATM_PHY_SIG_LOST;
  360. dev_info(dev, "ADSL line: training\n");
  361. break;
  362. case 3:
  363. atm_dev->signal = ATM_PHY_SIG_LOST;
  364. dev_info(dev, "ADSL line: channel analysis\n");
  365. break;
  366. case 4:
  367. atm_dev->signal = ATM_PHY_SIG_LOST;
  368. dev_info(dev, "ADSL line: exchange\n");
  369. break;
  370. case 5:
  371. atm_dev->link_rate = buf[CXINF_DOWNSTREAM_RATE] * 1000 / 424;
  372. atm_dev->signal = ATM_PHY_SIG_FOUND;
  373. dev_info(dev, "ADSL line: up (%d Kib/s down | %d Kib/s up)\n",
  374. buf[CXINF_DOWNSTREAM_RATE], buf[CXINF_UPSTREAM_RATE]);
  375. break;
  376. case 6:
  377. atm_dev->signal = ATM_PHY_SIG_LOST;
  378. dev_info(dev, "ADSL line: waiting\n");
  379. break;
  380. case 7:
  381. atm_dev->signal = ATM_PHY_SIG_LOST;
  382. dev_info(dev, "ADSL line: initializing\n");
  383. break;
  384. default:
  385. atm_dev->signal = ATM_PHY_SIG_UNKNOWN;
  386. dev_info(dev, "Unknown line state %02x\n", instance->line_status);
  387. break;
  388. }
  389. reschedule:
  390. schedule_delayed_work(&instance->poll_work, msecs_to_jiffies(POLL_INTERVAL));
  391. }
  392. static int cxacru_fw(struct usb_device *usb_dev, enum cxacru_fw_request fw,
  393. u8 code1, u8 code2, u32 addr, u8 *data, int size)
  394. {
  395. int ret;
  396. u8 *buf;
  397. int offd, offb;
  398. const int stride = CMD_PACKET_SIZE - 8;
  399. buf = (u8 *) __get_free_page(GFP_KERNEL);
  400. if (!buf)
  401. return -ENOMEM;
  402. offb = offd = 0;
  403. do {
  404. int l = min_t(int, stride, size - offd);
  405. buf[offb++] = fw;
  406. buf[offb++] = l;
  407. buf[offb++] = code1;
  408. buf[offb++] = code2;
  409. *((u32 *) (buf + offb)) = cpu_to_le32(addr);
  410. offb += 4;
  411. addr += l;
  412. if(l)
  413. memcpy(buf + offb, data + offd, l);
  414. if (l < stride)
  415. memset(buf + offb + l, 0, stride - l);
  416. offb += stride;
  417. offd += stride;
  418. if ((offb >= PAGE_SIZE) || (offd >= size)) {
  419. ret = usb_bulk_msg(usb_dev, usb_sndbulkpipe(usb_dev, CXACRU_EP_CMD),
  420. buf, offb, NULL, CMD_TIMEOUT);
  421. if (ret < 0) {
  422. dbg("sending fw %#x failed", fw);
  423. goto cleanup;
  424. }
  425. offb = 0;
  426. }
  427. } while(offd < size);
  428. dbg("sent fw %#x", fw);
  429. ret = 0;
  430. cleanup:
  431. free_page((unsigned long) buf);
  432. return ret;
  433. }
  434. static void cxacru_upload_firmware(struct cxacru_data *instance,
  435. const struct firmware *fw,
  436. const struct firmware *bp,
  437. const struct firmware *cf)
  438. {
  439. int ret;
  440. int off;
  441. struct usb_device *usb_dev = instance->usbatm->usb_dev;
  442. struct device *dev = &instance->usbatm->usb_intf->dev;
  443. u16 signature[] = { usb_dev->descriptor.idVendor, usb_dev->descriptor.idProduct };
  444. u32 val;
  445. dbg("cxacru_upload_firmware");
  446. /* FirmwarePllFClkValue */
  447. val = cpu_to_le32(instance->modem_type->pll_f_clk);
  448. ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, PLLFCLK_ADDR, (u8 *) &val, 4);
  449. if (ret) {
  450. dev_err(dev, "FirmwarePllFClkValue failed: %d\n", ret);
  451. return;
  452. }
  453. /* FirmwarePllBClkValue */
  454. val = cpu_to_le32(instance->modem_type->pll_b_clk);
  455. ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, PLLBCLK_ADDR, (u8 *) &val, 4);
  456. if (ret) {
  457. dev_err(dev, "FirmwarePllBClkValue failed: %d\n", ret);
  458. return;
  459. }
  460. /* Enable SDRAM */
  461. val = cpu_to_le32(SDRAM_ENA);
  462. ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, SDRAMEN_ADDR, (u8 *) &val, 4);
  463. if (ret) {
  464. dev_err(dev, "Enable SDRAM failed: %d\n", ret);
  465. return;
  466. }
  467. /* Firmware */
  468. ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, FW_ADDR, fw->data, fw->size);
  469. if (ret) {
  470. dev_err(dev, "Firmware upload failed: %d\n", ret);
  471. return;
  472. }
  473. /* Boot ROM patch */
  474. if (instance->modem_type->boot_rom_patch) {
  475. ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, BR_ADDR, bp->data, bp->size);
  476. if (ret) {
  477. dev_err(dev, "Boot ROM patching failed: %d\n", ret);
  478. return;
  479. }
  480. }
  481. /* Signature */
  482. ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, SIG_ADDR, (u8 *) signature, 4);
  483. if (ret) {
  484. dev_err(dev, "Signature storing failed: %d\n", ret);
  485. return;
  486. }
  487. if (instance->modem_type->boot_rom_patch) {
  488. val = cpu_to_le32(BR_ADDR);
  489. ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, BR_STACK_ADDR, (u8 *) &val, 4);
  490. }
  491. else {
  492. ret = cxacru_fw(usb_dev, FW_GOTO_MEM, 0x0, 0x0, FW_ADDR, NULL, 0);
  493. }
  494. if (ret) {
  495. dev_err(dev, "Passing control to firmware failed: %d\n", ret);
  496. return;
  497. }
  498. /* Delay to allow firmware to start up. */
  499. msleep_interruptible(1000);
  500. usb_clear_halt(usb_dev, usb_sndbulkpipe(usb_dev, CXACRU_EP_CMD));
  501. usb_clear_halt(usb_dev, usb_rcvbulkpipe(usb_dev, CXACRU_EP_CMD));
  502. usb_clear_halt(usb_dev, usb_sndbulkpipe(usb_dev, CXACRU_EP_DATA));
  503. usb_clear_halt(usb_dev, usb_rcvbulkpipe(usb_dev, CXACRU_EP_DATA));
  504. ret = cxacru_cm(instance, CM_REQUEST_CARD_GET_STATUS, NULL, 0, NULL, 0);
  505. if (ret < 0) {
  506. dev_err(dev, "modem failed to initialize: %d\n", ret);
  507. return;
  508. }
  509. /* Load config data (le32), doing one packet at a time */
  510. if (cf)
  511. for (off = 0; off < cf->size / 4; ) {
  512. u32 buf[CMD_PACKET_SIZE / 4 - 1];
  513. int i, len = min_t(int, cf->size / 4 - off, CMD_PACKET_SIZE / 4 / 2 - 1);
  514. buf[0] = cpu_to_le32(len);
  515. for (i = 0; i < len; i++, off++) {
  516. buf[i * 2 + 1] = cpu_to_le32(off);
  517. memcpy(buf + i * 2 + 2, cf->data + off * 4, 4);
  518. }
  519. ret = cxacru_cm(instance, CM_REQUEST_CARD_DATA_SET,
  520. (u8 *) buf, len, NULL, 0);
  521. if (ret < 0) {
  522. dev_err(dev, "load config data failed: %d\n", ret);
  523. return;
  524. }
  525. }
  526. msleep_interruptible(4000);
  527. }
  528. static int cxacru_find_firmware(struct cxacru_data *instance,
  529. char* phase, const struct firmware **fw_p)
  530. {
  531. struct device *dev = &instance->usbatm->usb_intf->dev;
  532. char buf[16];
  533. sprintf(buf, "cxacru-%s.bin", phase);
  534. dbg("cxacru_find_firmware: looking for %s", buf);
  535. if (request_firmware(fw_p, buf, dev)) {
  536. dev_dbg(dev, "no stage %s firmware found\n", phase);
  537. return -ENOENT;
  538. }
  539. dev_info(dev, "found firmware %s\n", buf);
  540. return 0;
  541. }
  542. static int cxacru_heavy_init(struct usbatm_data *usbatm_instance,
  543. struct usb_interface *usb_intf)
  544. {
  545. struct device *dev = &usbatm_instance->usb_intf->dev;
  546. const struct firmware *fw, *bp, *cf;
  547. struct cxacru_data *instance = usbatm_instance->driver_data;
  548. int ret = cxacru_find_firmware(instance, "fw", &fw);
  549. if (ret) {
  550. dev_warn(dev, "firmware (cxacru-fw.bin) unavailable (hotplug misconfiguration?)\n");
  551. return ret;
  552. }
  553. if (instance->modem_type->boot_rom_patch) {
  554. ret = cxacru_find_firmware(instance, "bp", &bp);
  555. if (ret) {
  556. dev_warn(dev, "boot ROM patch (cxacru-bp.bin) unavailable (hotplug misconfiguration?)\n");
  557. release_firmware(fw);
  558. return ret;
  559. }
  560. }
  561. if (cxacru_find_firmware(instance, "cf", &cf)) /* optional */
  562. cf = NULL;
  563. cxacru_upload_firmware(instance, fw, bp, cf);
  564. if (cf)
  565. release_firmware(cf);
  566. if (instance->modem_type->boot_rom_patch)
  567. release_firmware(bp);
  568. release_firmware(fw);
  569. ret = cxacru_card_status(instance);
  570. if (ret)
  571. dbg("modem initialisation failed");
  572. else
  573. dbg("done setting up the modem");
  574. return ret;
  575. }
  576. static int cxacru_bind(struct usbatm_data *usbatm_instance,
  577. struct usb_interface *intf, const struct usb_device_id *id,
  578. int *need_heavy_init)
  579. {
  580. struct cxacru_data *instance;
  581. struct usb_device *usb_dev = interface_to_usbdev(intf);
  582. int ret;
  583. /* instance init */
  584. instance = kmalloc(sizeof(*instance), GFP_KERNEL);
  585. if (!instance) {
  586. dbg("cxacru_bind: no memory for instance data");
  587. return -ENOMEM;
  588. }
  589. memset(instance, 0, sizeof(*instance));
  590. instance->usbatm = usbatm_instance;
  591. instance->modem_type = (struct cxacru_modem_type *) id->driver_info;
  592. instance->rcv_buf = (u8 *) __get_free_page(GFP_KERNEL);
  593. if (!instance->rcv_buf) {
  594. dbg("cxacru_bind: no memory for rcv_buf");
  595. ret = -ENOMEM;
  596. goto fail;
  597. }
  598. instance->snd_buf = (u8 *) __get_free_page(GFP_KERNEL);
  599. if (!instance->snd_buf) {
  600. dbg("cxacru_bind: no memory for snd_buf");
  601. ret = -ENOMEM;
  602. goto fail;
  603. }
  604. instance->rcv_urb = usb_alloc_urb(0, GFP_KERNEL);
  605. if (!instance->rcv_urb) {
  606. dbg("cxacru_bind: no memory for rcv_urb");
  607. ret = -ENOMEM;
  608. goto fail;
  609. }
  610. instance->snd_urb = usb_alloc_urb(0, GFP_KERNEL);
  611. if (!instance->snd_urb) {
  612. dbg("cxacru_bind: no memory for snd_urb");
  613. ret = -ENOMEM;
  614. goto fail;
  615. }
  616. usb_fill_int_urb(instance->rcv_urb,
  617. usb_dev, usb_rcvintpipe(usb_dev, CXACRU_EP_CMD),
  618. instance->rcv_buf, PAGE_SIZE,
  619. cxacru_blocking_completion, &instance->rcv_done, 1);
  620. instance->rcv_urb->transfer_flags |= URB_ASYNC_UNLINK;
  621. usb_fill_int_urb(instance->snd_urb,
  622. usb_dev, usb_sndintpipe(usb_dev, CXACRU_EP_CMD),
  623. instance->snd_buf, PAGE_SIZE,
  624. cxacru_blocking_completion, &instance->snd_done, 4);
  625. instance->snd_urb->transfer_flags |= URB_ASYNC_UNLINK;
  626. init_MUTEX(&instance->cm_serialize);
  627. INIT_WORK(&instance->poll_work, (void *)cxacru_poll_status, instance);
  628. usbatm_instance->driver_data = instance;
  629. *need_heavy_init = cxacru_card_status(instance);
  630. return 0;
  631. fail:
  632. free_page((unsigned long) instance->snd_buf);
  633. free_page((unsigned long) instance->rcv_buf);
  634. usb_free_urb(instance->snd_urb);
  635. usb_free_urb(instance->rcv_urb);
  636. kfree(instance);
  637. return ret;
  638. }
  639. static void cxacru_unbind(struct usbatm_data *usbatm_instance,
  640. struct usb_interface *intf)
  641. {
  642. struct cxacru_data *instance = usbatm_instance->driver_data;
  643. dbg("cxacru_unbind entered");
  644. if (!instance) {
  645. dbg("cxacru_unbind: NULL instance!");
  646. return;
  647. }
  648. while (!cancel_delayed_work(&instance->poll_work))
  649. flush_scheduled_work();
  650. usb_kill_urb(instance->snd_urb);
  651. usb_kill_urb(instance->rcv_urb);
  652. usb_free_urb(instance->snd_urb);
  653. usb_free_urb(instance->rcv_urb);
  654. free_page((unsigned long) instance->snd_buf);
  655. free_page((unsigned long) instance->rcv_buf);
  656. kfree(instance);
  657. usbatm_instance->driver_data = NULL;
  658. }
  659. static const struct cxacru_modem_type cxacru_cafe = {
  660. .pll_f_clk = 0x02d874df,
  661. .pll_b_clk = 0x0196a51a,
  662. .boot_rom_patch = 1,
  663. };
  664. static const struct cxacru_modem_type cxacru_cb00 = {
  665. .pll_f_clk = 0x5,
  666. .pll_b_clk = 0x3,
  667. .boot_rom_patch = 0,
  668. };
  669. static const struct usb_device_id cxacru_usb_ids[] = {
  670. { /* V = Conexant P = ADSL modem (Euphrates project) */
  671. USB_DEVICE(0x0572, 0xcafe), .driver_info = (unsigned long) &cxacru_cafe
  672. },
  673. { /* V = Conexant P = ADSL modem (Hasbani project) */
  674. USB_DEVICE(0x0572, 0xcb00), .driver_info = (unsigned long) &cxacru_cb00
  675. },
  676. { /* V = Conexant P = ADSL modem */
  677. USB_DEVICE(0x0572, 0xcb01), .driver_info = (unsigned long) &cxacru_cb00
  678. },
  679. { /* V = Conexant P = ADSL modem */
  680. USB_DEVICE(0x0572, 0xcb06), .driver_info = (unsigned long) &cxacru_cb00
  681. },
  682. { /* V = Olitec P = ADSL modem version 2 */
  683. USB_DEVICE(0x08e3, 0x0100), .driver_info = (unsigned long) &cxacru_cafe
  684. },
  685. { /* V = Olitec P = ADSL modem version 3 */
  686. USB_DEVICE(0x08e3, 0x0102), .driver_info = (unsigned long) &cxacru_cb00
  687. },
  688. { /* V = Trust/Amigo Technology Co. P = AMX-CA86U */
  689. USB_DEVICE(0x0eb0, 0x3457), .driver_info = (unsigned long) &cxacru_cafe
  690. },
  691. { /* V = Zoom P = 5510 */
  692. USB_DEVICE(0x1803, 0x5510), .driver_info = (unsigned long) &cxacru_cb00
  693. },
  694. { /* V = Draytek P = Vigor 318 */
  695. USB_DEVICE(0x0675, 0x0200), .driver_info = (unsigned long) &cxacru_cb00
  696. },
  697. { /* V = Zyxel P = 630-C1 aka OMNI ADSL USB (Annex A) */
  698. USB_DEVICE(0x0586, 0x330a), .driver_info = (unsigned long) &cxacru_cb00
  699. },
  700. { /* V = Zyxel P = 630-C3 aka OMNI ADSL USB (Annex B) */
  701. USB_DEVICE(0x0586, 0x330b), .driver_info = (unsigned long) &cxacru_cb00
  702. },
  703. { /* V = Aethra P = Starmodem UM1020 */
  704. USB_DEVICE(0x0659, 0x0020), .driver_info = (unsigned long) &cxacru_cb00
  705. },
  706. { /* V = Aztech Systems P = ? AKA Pirelli AUA-010 */
  707. USB_DEVICE(0x0509, 0x0812), .driver_info = (unsigned long) &cxacru_cb00
  708. },
  709. { /* V = Netopia P = Cayman 3341(Annex A)/3351(Annex B) */
  710. USB_DEVICE(0x100d, 0xcb01), .driver_info = (unsigned long) &cxacru_cb00
  711. },
  712. { /* V = Netopia P = Cayman 3342(Annex A)/3352(Annex B) */
  713. USB_DEVICE(0x100d, 0x3342), .driver_info = (unsigned long) &cxacru_cb00
  714. },
  715. {}
  716. };
  717. MODULE_DEVICE_TABLE(usb, cxacru_usb_ids);
  718. static struct usbatm_driver cxacru_driver = {
  719. .owner = THIS_MODULE,
  720. .driver_name = cxacru_driver_name,
  721. .bind = cxacru_bind,
  722. .heavy_init = cxacru_heavy_init,
  723. .unbind = cxacru_unbind,
  724. .atm_start = cxacru_atm_start,
  725. .in = CXACRU_EP_DATA,
  726. .out = CXACRU_EP_DATA,
  727. .rx_padding = 3,
  728. .tx_padding = 11,
  729. };
  730. static int cxacru_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
  731. {
  732. return usbatm_usb_probe(intf, id, &cxacru_driver);
  733. }
  734. static struct usb_driver cxacru_usb_driver = {
  735. .owner = THIS_MODULE,
  736. .name = cxacru_driver_name,
  737. .probe = cxacru_usb_probe,
  738. .disconnect = usbatm_usb_disconnect,
  739. .id_table = cxacru_usb_ids
  740. };
  741. static int __init cxacru_init(void)
  742. {
  743. return usb_register(&cxacru_usb_driver);
  744. }
  745. static void __exit cxacru_cleanup(void)
  746. {
  747. usb_deregister(&cxacru_usb_driver);
  748. }
  749. module_init(cxacru_init);
  750. module_exit(cxacru_cleanup);
  751. MODULE_AUTHOR(DRIVER_AUTHOR);
  752. MODULE_DESCRIPTION(DRIVER_DESC);
  753. MODULE_LICENSE("GPL");
  754. MODULE_VERSION(DRIVER_VERSION);