cxacru.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874
  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 <linux/mutex.h>
  38. #include "usbatm.h"
  39. #define DRIVER_AUTHOR "Roman Kagan, David Woodhouse, Duncan Sands"
  40. #define DRIVER_VERSION "0.2"
  41. #define DRIVER_DESC "Conexant AccessRunner ADSL USB modem driver"
  42. static const char cxacru_driver_name[] = "cxacru";
  43. #define CXACRU_EP_CMD 0x01 /* Bulk/interrupt in/out */
  44. #define CXACRU_EP_DATA 0x02 /* Bulk in/out */
  45. #define CMD_PACKET_SIZE 64 /* Should be maxpacket(ep)? */
  46. /* Addresses */
  47. #define PLLFCLK_ADDR 0x00350068
  48. #define PLLBCLK_ADDR 0x0035006c
  49. #define SDRAMEN_ADDR 0x00350010
  50. #define FW_ADDR 0x00801000
  51. #define BR_ADDR 0x00180600
  52. #define SIG_ADDR 0x00180500
  53. #define BR_STACK_ADDR 0x00187f10
  54. /* Values */
  55. #define SDRAM_ENA 0x1
  56. #define CMD_TIMEOUT 2000 /* msecs */
  57. #define POLL_INTERVAL 5000 /* msecs */
  58. /* commands for interaction with the modem through the control channel before
  59. * firmware is loaded */
  60. enum cxacru_fw_request {
  61. FW_CMD_ERR,
  62. FW_GET_VER,
  63. FW_READ_MEM,
  64. FW_WRITE_MEM,
  65. FW_RMW_MEM,
  66. FW_CHECKSUM_MEM,
  67. FW_GOTO_MEM,
  68. };
  69. /* commands for interaction with the modem through the control channel once
  70. * firmware is loaded */
  71. enum cxacru_cm_request {
  72. CM_REQUEST_UNDEFINED = 0x80,
  73. CM_REQUEST_TEST,
  74. CM_REQUEST_CHIP_GET_MAC_ADDRESS,
  75. CM_REQUEST_CHIP_GET_DP_VERSIONS,
  76. CM_REQUEST_CHIP_ADSL_LINE_START,
  77. CM_REQUEST_CHIP_ADSL_LINE_STOP,
  78. CM_REQUEST_CHIP_ADSL_LINE_GET_STATUS,
  79. CM_REQUEST_CHIP_ADSL_LINE_GET_SPEED,
  80. CM_REQUEST_CARD_INFO_GET,
  81. CM_REQUEST_CARD_DATA_GET,
  82. CM_REQUEST_CARD_DATA_SET,
  83. CM_REQUEST_COMMAND_HW_IO,
  84. CM_REQUEST_INTERFACE_HW_IO,
  85. CM_REQUEST_CARD_SERIAL_DATA_PATH_GET,
  86. CM_REQUEST_CARD_SERIAL_DATA_PATH_SET,
  87. CM_REQUEST_CARD_CONTROLLER_VERSION_GET,
  88. CM_REQUEST_CARD_GET_STATUS,
  89. CM_REQUEST_CARD_GET_MAC_ADDRESS,
  90. CM_REQUEST_CARD_GET_DATA_LINK_STATUS,
  91. CM_REQUEST_MAX,
  92. };
  93. /* reply codes to the commands above */
  94. enum cxacru_cm_status {
  95. CM_STATUS_UNDEFINED,
  96. CM_STATUS_SUCCESS,
  97. CM_STATUS_ERROR,
  98. CM_STATUS_UNSUPPORTED,
  99. CM_STATUS_UNIMPLEMENTED,
  100. CM_STATUS_PARAMETER_ERROR,
  101. CM_STATUS_DBG_LOOPBACK,
  102. CM_STATUS_MAX,
  103. };
  104. /* indices into CARD_INFO_GET return array */
  105. enum cxacru_info_idx {
  106. CXINF_DOWNSTREAM_RATE,
  107. CXINF_UPSTREAM_RATE,
  108. CXINF_LINK_STATUS,
  109. CXINF_LINE_STATUS,
  110. CXINF_MAC_ADDRESS_HIGH,
  111. CXINF_MAC_ADDRESS_LOW,
  112. CXINF_UPSTREAM_SNR_MARGIN,
  113. CXINF_DOWNSTREAM_SNR_MARGIN,
  114. CXINF_UPSTREAM_ATTENUATION,
  115. CXINF_DOWNSTREAM_ATTENUATION,
  116. CXINF_TRANSMITTER_POWER,
  117. CXINF_UPSTREAM_BITS_PER_FRAME,
  118. CXINF_DOWNSTREAM_BITS_PER_FRAME,
  119. CXINF_STARTUP_ATTEMPTS,
  120. CXINF_UPSTREAM_CRC_ERRORS,
  121. CXINF_DOWNSTREAM_CRC_ERRORS,
  122. CXINF_UPSTREAM_FEC_ERRORS,
  123. CXINF_DOWNSTREAM_FEC_ERRORS,
  124. CXINF_UPSTREAM_HEC_ERRORS,
  125. CXINF_DOWNSTREAM_HEC_ERRORS,
  126. CXINF_LINE_STARTABLE,
  127. CXINF_MODULATION,
  128. CXINF_ADSL_HEADEND,
  129. CXINF_ADSL_HEADEND_ENVIRONMENT,
  130. CXINF_CONTROLLER_VERSION,
  131. /* dunno what the missing two mean */
  132. CXINF_MAX = 0x1c,
  133. };
  134. struct cxacru_modem_type {
  135. u32 pll_f_clk;
  136. u32 pll_b_clk;
  137. int boot_rom_patch;
  138. };
  139. struct cxacru_data {
  140. struct usbatm_data *usbatm;
  141. const struct cxacru_modem_type *modem_type;
  142. int line_status;
  143. struct work_struct poll_work;
  144. /* contol handles */
  145. struct mutex cm_serialize;
  146. u8 *rcv_buf;
  147. u8 *snd_buf;
  148. struct urb *rcv_urb;
  149. struct urb *snd_urb;
  150. struct completion rcv_done;
  151. struct completion snd_done;
  152. };
  153. /* the following three functions are stolen from drivers/usb/core/message.c */
  154. static void cxacru_blocking_completion(struct urb *urb, struct pt_regs *regs)
  155. {
  156. complete((struct completion *)urb->context);
  157. }
  158. static void cxacru_timeout_kill(unsigned long data)
  159. {
  160. usb_unlink_urb((struct urb *) data);
  161. }
  162. static int cxacru_start_wait_urb(struct urb *urb, struct completion *done,
  163. int* actual_length)
  164. {
  165. struct timer_list timer;
  166. int status;
  167. init_timer(&timer);
  168. timer.expires = jiffies + msecs_to_jiffies(CMD_TIMEOUT);
  169. timer.data = (unsigned long) urb;
  170. timer.function = cxacru_timeout_kill;
  171. add_timer(&timer);
  172. wait_for_completion(done);
  173. status = urb->status;
  174. if (status == -ECONNRESET)
  175. status = -ETIMEDOUT;
  176. del_timer_sync(&timer);
  177. if (actual_length)
  178. *actual_length = urb->actual_length;
  179. return status;
  180. }
  181. static int cxacru_cm(struct cxacru_data *instance, enum cxacru_cm_request cm,
  182. u8 *wdata, int wsize, u8 *rdata, int rsize)
  183. {
  184. int ret, actlen;
  185. int offb, offd;
  186. const int stride = CMD_PACKET_SIZE - 4;
  187. u8 *wbuf = instance->snd_buf;
  188. u8 *rbuf = instance->rcv_buf;
  189. int wbuflen = ((wsize - 1) / stride + 1) * CMD_PACKET_SIZE;
  190. int rbuflen = ((rsize - 1) / stride + 1) * CMD_PACKET_SIZE;
  191. if (wbuflen > PAGE_SIZE || rbuflen > PAGE_SIZE) {
  192. dbg("too big transfer requested");
  193. ret = -ENOMEM;
  194. goto fail;
  195. }
  196. mutex_lock(&instance->cm_serialize);
  197. /* submit reading urb before the writing one */
  198. init_completion(&instance->rcv_done);
  199. ret = usb_submit_urb(instance->rcv_urb, GFP_KERNEL);
  200. if (ret < 0) {
  201. dbg("submitting read urb for cm %#x failed", cm);
  202. ret = ret;
  203. goto fail;
  204. }
  205. memset(wbuf, 0, wbuflen);
  206. /* handle wsize == 0 */
  207. wbuf[0] = cm;
  208. for (offb = offd = 0; offd < wsize; offd += stride, offb += CMD_PACKET_SIZE) {
  209. wbuf[offb] = cm;
  210. memcpy(wbuf + offb + 4, wdata + offd, min_t(int, stride, wsize - offd));
  211. }
  212. instance->snd_urb->transfer_buffer_length = wbuflen;
  213. init_completion(&instance->snd_done);
  214. ret = usb_submit_urb(instance->snd_urb, GFP_KERNEL);
  215. if (ret < 0) {
  216. dbg("submitting write urb for cm %#x failed", cm);
  217. ret = ret;
  218. goto fail;
  219. }
  220. ret = cxacru_start_wait_urb(instance->snd_urb, &instance->snd_done, NULL);
  221. if (ret < 0) {
  222. dbg("sending cm %#x failed", cm);
  223. ret = ret;
  224. goto fail;
  225. }
  226. ret = cxacru_start_wait_urb(instance->rcv_urb, &instance->rcv_done, &actlen);
  227. if (ret < 0) {
  228. dbg("receiving cm %#x failed", cm);
  229. ret = ret;
  230. goto fail;
  231. }
  232. if (actlen % CMD_PACKET_SIZE || !actlen) {
  233. dbg("response is not a positive multiple of %d: %#x",
  234. CMD_PACKET_SIZE, actlen);
  235. ret = -EIO;
  236. goto fail;
  237. }
  238. /* check the return status and copy the data to the output buffer, if needed */
  239. for (offb = offd = 0; offd < rsize && offb < actlen; offb += CMD_PACKET_SIZE) {
  240. if (rbuf[offb] != cm) {
  241. dbg("wrong cm %#x in response", rbuf[offb]);
  242. ret = -EIO;
  243. goto fail;
  244. }
  245. if (rbuf[offb + 1] != CM_STATUS_SUCCESS) {
  246. dbg("response failed: %#x", rbuf[offb + 1]);
  247. ret = -EIO;
  248. goto fail;
  249. }
  250. if (offd >= rsize)
  251. break;
  252. memcpy(rdata + offd, rbuf + offb + 4, min_t(int, stride, rsize - offd));
  253. offd += stride;
  254. }
  255. ret = offd;
  256. dbg("cm %#x", cm);
  257. fail:
  258. mutex_unlock(&instance->cm_serialize);
  259. return ret;
  260. }
  261. static int cxacru_cm_get_array(struct cxacru_data *instance, enum cxacru_cm_request cm,
  262. u32 *data, int size)
  263. {
  264. int ret, len;
  265. u32 *buf;
  266. int offb, offd;
  267. const int stride = CMD_PACKET_SIZE / (4 * 2) - 1;
  268. int buflen = ((size - 1) / stride + 1 + size * 2) * 4;
  269. buf = kmalloc(buflen, GFP_KERNEL);
  270. if (!buf)
  271. return -ENOMEM;
  272. ret = cxacru_cm(instance, cm, NULL, 0, (u8 *) buf, buflen);
  273. if (ret < 0)
  274. goto cleanup;
  275. /* len > 0 && len % 4 == 0 guaranteed by cxacru_cm() */
  276. len = ret / 4;
  277. for (offb = 0; offb < len; ) {
  278. int l = le32_to_cpu(buf[offb++]);
  279. if (l > stride || l > (len - offb) / 2) {
  280. dbg("wrong data length %#x in response", l);
  281. ret = -EIO;
  282. goto cleanup;
  283. }
  284. while (l--) {
  285. offd = le32_to_cpu(buf[offb++]);
  286. if (offd >= size) {
  287. dbg("wrong index %#x in response", offd);
  288. ret = -EIO;
  289. goto cleanup;
  290. }
  291. data[offd] = le32_to_cpu(buf[offb++]);
  292. }
  293. }
  294. ret = 0;
  295. cleanup:
  296. kfree(buf);
  297. return ret;
  298. }
  299. static int cxacru_card_status(struct cxacru_data *instance)
  300. {
  301. int ret = cxacru_cm(instance, CM_REQUEST_CARD_GET_STATUS, NULL, 0, NULL, 0);
  302. if (ret < 0) { /* firmware not loaded */
  303. dbg("cxacru_adsl_start: CARD_GET_STATUS returned %d", ret);
  304. return ret;
  305. }
  306. return 0;
  307. }
  308. static void cxacru_poll_status(struct cxacru_data *instance);
  309. static int cxacru_atm_start(struct usbatm_data *usbatm_instance,
  310. struct atm_dev *atm_dev)
  311. {
  312. struct cxacru_data *instance = usbatm_instance->driver_data;
  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. atm_err(usbatm_instance, "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. atm_err(usbatm_instance, "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 usbatm_data *usbatm = instance->usbatm;
  339. struct atm_dev *atm_dev = 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. atm_warn(usbatm, "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. atm_info(usbatm, "ADSL line: down\n");
  353. break;
  354. case 1:
  355. atm_dev->signal = ATM_PHY_SIG_LOST;
  356. atm_info(usbatm, "ADSL line: attempting to activate\n");
  357. break;
  358. case 2:
  359. atm_dev->signal = ATM_PHY_SIG_LOST;
  360. atm_info(usbatm, "ADSL line: training\n");
  361. break;
  362. case 3:
  363. atm_dev->signal = ATM_PHY_SIG_LOST;
  364. atm_info(usbatm, "ADSL line: channel analysis\n");
  365. break;
  366. case 4:
  367. atm_dev->signal = ATM_PHY_SIG_LOST;
  368. atm_info(usbatm, "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. atm_info(usbatm, "ADSL line: up (%d kb/s down | %d kb/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. atm_info(usbatm, "ADSL line: waiting\n");
  379. break;
  380. case 7:
  381. atm_dev->signal = ATM_PHY_SIG_LOST;
  382. atm_info(usbatm, "ADSL line: initializing\n");
  383. break;
  384. default:
  385. atm_dev->signal = ATM_PHY_SIG_UNKNOWN;
  386. atm_info(usbatm, "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 usbatm_data *usbatm = instance->usbatm;
  442. struct usb_device *usb_dev = usbatm->usb_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. usb_err(usbatm, "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. usb_err(usbatm, "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. usb_err(usbatm, "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. usb_err(usbatm, "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. usb_err(usbatm, "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. usb_err(usbatm, "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. usb_err(usbatm, "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. usb_err(usbatm, "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. usb_err(usbatm, "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 usbatm_data *usbatm = instance->usbatm;
  532. struct device *dev = &usbatm->usb_intf->dev;
  533. char buf[16];
  534. sprintf(buf, "cxacru-%s.bin", phase);
  535. dbg("cxacru_find_firmware: looking for %s", buf);
  536. if (request_firmware(fw_p, buf, dev)) {
  537. usb_dbg(usbatm, "no stage %s firmware found\n", phase);
  538. return -ENOENT;
  539. }
  540. usb_info(usbatm, "found firmware %s\n", buf);
  541. return 0;
  542. }
  543. static int cxacru_heavy_init(struct usbatm_data *usbatm_instance,
  544. struct usb_interface *usb_intf)
  545. {
  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. usb_warn(usbatm_instance, "firmware (cxacru-fw.bin) unavailable (system misconfigured?)\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. usb_warn(usbatm_instance, "boot ROM patch (cxacru-bp.bin) unavailable (system misconfigured?)\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. {
  579. struct cxacru_data *instance;
  580. struct usb_device *usb_dev = interface_to_usbdev(intf);
  581. int ret;
  582. /* instance init */
  583. instance = kzalloc(sizeof(*instance), GFP_KERNEL);
  584. if (!instance) {
  585. dbg("cxacru_bind: no memory for instance data");
  586. return -ENOMEM;
  587. }
  588. instance->usbatm = usbatm_instance;
  589. instance->modem_type = (struct cxacru_modem_type *) id->driver_info;
  590. instance->rcv_buf = (u8 *) __get_free_page(GFP_KERNEL);
  591. if (!instance->rcv_buf) {
  592. dbg("cxacru_bind: no memory for rcv_buf");
  593. ret = -ENOMEM;
  594. goto fail;
  595. }
  596. instance->snd_buf = (u8 *) __get_free_page(GFP_KERNEL);
  597. if (!instance->snd_buf) {
  598. dbg("cxacru_bind: no memory for snd_buf");
  599. ret = -ENOMEM;
  600. goto fail;
  601. }
  602. instance->rcv_urb = usb_alloc_urb(0, GFP_KERNEL);
  603. if (!instance->rcv_urb) {
  604. dbg("cxacru_bind: no memory for rcv_urb");
  605. ret = -ENOMEM;
  606. goto fail;
  607. }
  608. instance->snd_urb = usb_alloc_urb(0, GFP_KERNEL);
  609. if (!instance->snd_urb) {
  610. dbg("cxacru_bind: no memory for snd_urb");
  611. ret = -ENOMEM;
  612. goto fail;
  613. }
  614. usb_fill_int_urb(instance->rcv_urb,
  615. usb_dev, usb_rcvintpipe(usb_dev, CXACRU_EP_CMD),
  616. instance->rcv_buf, PAGE_SIZE,
  617. cxacru_blocking_completion, &instance->rcv_done, 1);
  618. usb_fill_int_urb(instance->snd_urb,
  619. usb_dev, usb_sndintpipe(usb_dev, CXACRU_EP_CMD),
  620. instance->snd_buf, PAGE_SIZE,
  621. cxacru_blocking_completion, &instance->snd_done, 4);
  622. mutex_init(&instance->cm_serialize);
  623. INIT_WORK(&instance->poll_work, (void *)cxacru_poll_status, instance);
  624. usbatm_instance->driver_data = instance;
  625. usbatm_instance->flags = (cxacru_card_status(instance) ? 0 : UDSL_SKIP_HEAVY_INIT);
  626. return 0;
  627. fail:
  628. free_page((unsigned long) instance->snd_buf);
  629. free_page((unsigned long) instance->rcv_buf);
  630. usb_free_urb(instance->snd_urb);
  631. usb_free_urb(instance->rcv_urb);
  632. kfree(instance);
  633. return ret;
  634. }
  635. static void cxacru_unbind(struct usbatm_data *usbatm_instance,
  636. struct usb_interface *intf)
  637. {
  638. struct cxacru_data *instance = usbatm_instance->driver_data;
  639. dbg("cxacru_unbind entered");
  640. if (!instance) {
  641. dbg("cxacru_unbind: NULL instance!");
  642. return;
  643. }
  644. while (!cancel_delayed_work(&instance->poll_work))
  645. flush_scheduled_work();
  646. usb_kill_urb(instance->snd_urb);
  647. usb_kill_urb(instance->rcv_urb);
  648. usb_free_urb(instance->snd_urb);
  649. usb_free_urb(instance->rcv_urb);
  650. free_page((unsigned long) instance->snd_buf);
  651. free_page((unsigned long) instance->rcv_buf);
  652. kfree(instance);
  653. usbatm_instance->driver_data = NULL;
  654. }
  655. static const struct cxacru_modem_type cxacru_cafe = {
  656. .pll_f_clk = 0x02d874df,
  657. .pll_b_clk = 0x0196a51a,
  658. .boot_rom_patch = 1,
  659. };
  660. static const struct cxacru_modem_type cxacru_cb00 = {
  661. .pll_f_clk = 0x5,
  662. .pll_b_clk = 0x3,
  663. .boot_rom_patch = 0,
  664. };
  665. static const struct usb_device_id cxacru_usb_ids[] = {
  666. { /* V = Conexant P = ADSL modem (Euphrates project) */
  667. USB_DEVICE(0x0572, 0xcafe), .driver_info = (unsigned long) &cxacru_cafe
  668. },
  669. { /* V = Conexant P = ADSL modem (Hasbani project) */
  670. USB_DEVICE(0x0572, 0xcb00), .driver_info = (unsigned long) &cxacru_cb00
  671. },
  672. { /* V = Conexant P = ADSL modem */
  673. USB_DEVICE(0x0572, 0xcb01), .driver_info = (unsigned long) &cxacru_cb00
  674. },
  675. { /* V = Conexant P = ADSL modem (Well PTI-800) */
  676. USB_DEVICE(0x0572, 0xcb02), .driver_info = (unsigned long) &cxacru_cb00
  677. },
  678. { /* V = Conexant P = ADSL modem */
  679. USB_DEVICE(0x0572, 0xcb06), .driver_info = (unsigned long) &cxacru_cb00
  680. },
  681. { /* V = Olitec P = ADSL modem version 2 */
  682. USB_DEVICE(0x08e3, 0x0100), .driver_info = (unsigned long) &cxacru_cafe
  683. },
  684. { /* V = Olitec P = ADSL modem version 3 */
  685. USB_DEVICE(0x08e3, 0x0102), .driver_info = (unsigned long) &cxacru_cb00
  686. },
  687. { /* V = Trust/Amigo Technology Co. P = AMX-CA86U */
  688. USB_DEVICE(0x0eb0, 0x3457), .driver_info = (unsigned long) &cxacru_cafe
  689. },
  690. { /* V = Zoom P = 5510 */
  691. USB_DEVICE(0x1803, 0x5510), .driver_info = (unsigned long) &cxacru_cb00
  692. },
  693. { /* V = Draytek P = Vigor 318 */
  694. USB_DEVICE(0x0675, 0x0200), .driver_info = (unsigned long) &cxacru_cb00
  695. },
  696. { /* V = Zyxel P = 630-C1 aka OMNI ADSL USB (Annex A) */
  697. USB_DEVICE(0x0586, 0x330a), .driver_info = (unsigned long) &cxacru_cb00
  698. },
  699. { /* V = Zyxel P = 630-C3 aka OMNI ADSL USB (Annex B) */
  700. USB_DEVICE(0x0586, 0x330b), .driver_info = (unsigned long) &cxacru_cb00
  701. },
  702. { /* V = Aethra P = Starmodem UM1020 */
  703. USB_DEVICE(0x0659, 0x0020), .driver_info = (unsigned long) &cxacru_cb00
  704. },
  705. { /* V = Aztech Systems P = ? AKA Pirelli AUA-010 */
  706. USB_DEVICE(0x0509, 0x0812), .driver_info = (unsigned long) &cxacru_cb00
  707. },
  708. { /* V = Netopia P = Cayman 3341(Annex A)/3351(Annex B) */
  709. USB_DEVICE(0x100d, 0xcb01), .driver_info = (unsigned long) &cxacru_cb00
  710. },
  711. { /* V = Netopia P = Cayman 3342(Annex A)/3352(Annex B) */
  712. USB_DEVICE(0x100d, 0x3342), .driver_info = (unsigned long) &cxacru_cb00
  713. },
  714. {}
  715. };
  716. MODULE_DEVICE_TABLE(usb, cxacru_usb_ids);
  717. static struct usbatm_driver cxacru_driver = {
  718. .driver_name = cxacru_driver_name,
  719. .bind = cxacru_bind,
  720. .heavy_init = cxacru_heavy_init,
  721. .unbind = cxacru_unbind,
  722. .atm_start = cxacru_atm_start,
  723. .bulk_in = CXACRU_EP_DATA,
  724. .bulk_out = CXACRU_EP_DATA,
  725. .rx_padding = 3,
  726. .tx_padding = 11,
  727. };
  728. static int cxacru_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
  729. {
  730. return usbatm_usb_probe(intf, id, &cxacru_driver);
  731. }
  732. static struct usb_driver cxacru_usb_driver = {
  733. .name = cxacru_driver_name,
  734. .probe = cxacru_usb_probe,
  735. .disconnect = usbatm_usb_disconnect,
  736. .id_table = cxacru_usb_ids
  737. };
  738. static int __init cxacru_init(void)
  739. {
  740. return usb_register(&cxacru_usb_driver);
  741. }
  742. static void __exit cxacru_cleanup(void)
  743. {
  744. usb_deregister(&cxacru_usb_driver);
  745. }
  746. module_init(cxacru_init);
  747. module_exit(cxacru_cleanup);
  748. MODULE_AUTHOR(DRIVER_AUTHOR);
  749. MODULE_DESCRIPTION(DRIVER_DESC);
  750. MODULE_LICENSE("GPL");
  751. MODULE_VERSION(DRIVER_VERSION);