32 #include <linux/module.h>
34 #include <linux/kernel.h>
36 #include <linux/errno.h>
37 #include <linux/slab.h>
39 #include <linux/device.h>
42 #include <asm/unaligned.h>
46 #define DRIVER_AUTHOR "Roman Kagan, David Woodhouse, Duncan Sands, Simon Arlott"
47 #define DRIVER_VERSION "0.4"
48 #define DRIVER_DESC "Conexant AccessRunner ADSL USB modem driver"
50 static const char cxacru_driver_name[] =
"cxacru";
52 #define CXACRU_EP_CMD 0x01
53 #define CXACRU_EP_DATA 0x02
55 #define CMD_PACKET_SIZE 64
56 #define CMD_MAX_CONFIG ((CMD_PACKET_SIZE / 4 - 1) / 2)
59 #define PLLFCLK_ADDR 0x00350068
60 #define PLLBCLK_ADDR 0x0035006c
61 #define SDRAMEN_ADDR 0x00350010
62 #define FW_ADDR 0x00801000
63 #define BR_ADDR 0x00180600
64 #define SIG_ADDR 0x00180500
65 #define BR_STACK_ADDR 0x00187f10
70 #define CMD_TIMEOUT 2000
71 #define POLL_INTERVAL 1
210 u8 *wdata,
int wsize,
u8 *rdata,
int rsize);
214 #define CXACRU__ATTR_INIT(_name) \
215 static DEVICE_ATTR(_name, S_IRUGO, cxacru_sysfs_show_##_name, NULL)
217 #define CXACRU_CMD_INIT(_name) \
218 static DEVICE_ATTR(_name, S_IWUSR | S_IRUGO, \
219 cxacru_sysfs_show_##_name, cxacru_sysfs_store_##_name)
221 #define CXACRU_SET_INIT(_name) \
222 static DEVICE_ATTR(_name, S_IWUSR, \
223 NULL, cxacru_sysfs_store_##_name)
225 #define CXACRU_ATTR_INIT(_value, _type, _name) \
226 static ssize_t cxacru_sysfs_show_##_name(struct device *dev, \
227 struct device_attribute *attr, char *buf) \
229 struct cxacru_data *instance = to_usbatm_driver_data(\
230 to_usb_interface(dev)); \
232 if (instance == NULL) \
235 return cxacru_sysfs_showattr_##_type(instance->card_info[_value], buf); \
237 CXACRU__ATTR_INIT(_name)
239 #define CXACRU_ATTR_CREATE(_v, _t, _name) CXACRU_DEVICE_CREATE_FILE(_name)
240 #define CXACRU_CMD_CREATE(_name) CXACRU_DEVICE_CREATE_FILE(_name)
241 #define CXACRU_SET_CREATE(_name) CXACRU_DEVICE_CREATE_FILE(_name)
242 #define CXACRU__ATTR_CREATE(_name) CXACRU_DEVICE_CREATE_FILE(_name)
244 #define CXACRU_ATTR_REMOVE(_v, _t, _name) CXACRU_DEVICE_REMOVE_FILE(_name)
245 #define CXACRU_CMD_REMOVE(_name) CXACRU_DEVICE_REMOVE_FILE(_name)
246 #define CXACRU_SET_REMOVE(_name) CXACRU_DEVICE_REMOVE_FILE(_name)
247 #define CXACRU__ATTR_REMOVE(_name) CXACRU_DEVICE_REMOVE_FILE(_name)
263 value / 100, value % 100);
267 value / 100, value % 100);
271 static ssize_t cxacru_sysfs_showattr_bool(
u32 value,
char *buf)
273 static char *
str[] = {
"no",
"yes" };
279 static ssize_t cxacru_sysfs_showattr_LINK(
u32 value,
char *buf)
281 static char *str[] = {
NULL,
"not connected",
"connected",
"lost" };
287 static ssize_t cxacru_sysfs_showattr_LINE(
u32 value,
char *buf)
289 static char *str[] = {
"down",
"attempting to activate",
290 "training",
"channel analysis",
"exchange",
"up",
291 "waiting",
"initialising"
298 static ssize_t cxacru_sysfs_showattr_MODU(
u32 value,
char *buf)
300 static char *str[] = {
303 "ITU-T G.992.1 (G.DMT)",
304 "ITU-T G.992.2 (G.LITE)"
322 struct cxacru_data *instance = to_usbatm_driver_data(
323 to_usb_interface(dev));
329 instance->
usbatm->atm_dev->esi);
332 static ssize_t cxacru_sysfs_show_adsl_state(
struct device *dev,
335 static char *str[] = {
"running",
"stopped" };
336 struct cxacru_data *instance = to_usbatm_driver_data(
337 to_usb_interface(dev));
340 if (instance ==
NULL)
349 static ssize_t cxacru_sysfs_store_adsl_state(
struct device *dev,
352 struct cxacru_data *instance = to_usbatm_driver_data(
353 to_usb_interface(dev));
362 ret =
sscanf(buf,
"%7s", str_cmd);
367 if (instance ==
NULL)
373 if (!
strcmp(str_cmd,
"stop") || !
strcmp(str_cmd,
"restart")) {
377 " CHIP_ADSL_LINE_STOP returned %d\n", ret);
390 if (!
strcmp(str_cmd,
"restart"))
393 if (!
strcmp(str_cmd,
"start") || !
strcmp(str_cmd,
"restart")) {
397 " CHIP_ADSL_LINE_START returned %d\n", ret);
406 if (!
strcmp(str_cmd,
"poll")) {
444 cxacru_poll_status(&instance->
poll_work.work);
451 static ssize_t cxacru_sysfs_store_adsl_config(
struct device *dev,
454 struct cxacru_data *instance = to_usbatm_driver_data(
455 to_usb_interface(dev));
463 if (instance ==
NULL)
473 ret =
sscanf(buf + pos,
"%x=%x%n", &index, &value, &tmp);
476 if (index < 0 || index > 0x7f)
481 if (buf[pos] ==
'\n' && pos == len-1)
496 (
u8 *) data, 4 + num * 8,
NULL, 0);
499 "set card data returned %d\n", ret);
503 for (tmp = 0; tmp < num; tmp++)
504 snprintf(log + tmp*12, 13,
" %02x=%08x",
525 #define CXACRU_ALL_FILES(_action) \
526 CXACRU_ATTR_##_action(CXINF_DOWNSTREAM_RATE, u32, downstream_rate); \
527 CXACRU_ATTR_##_action(CXINF_UPSTREAM_RATE, u32, upstream_rate); \
528 CXACRU_ATTR_##_action(CXINF_LINK_STATUS, LINK, link_status); \
529 CXACRU_ATTR_##_action(CXINF_LINE_STATUS, LINE, line_status); \
530 CXACRU__ATTR_##_action( mac_address); \
531 CXACRU_ATTR_##_action(CXINF_UPSTREAM_SNR_MARGIN, dB, upstream_snr_margin); \
532 CXACRU_ATTR_##_action(CXINF_DOWNSTREAM_SNR_MARGIN, dB, downstream_snr_margin); \
533 CXACRU_ATTR_##_action(CXINF_UPSTREAM_ATTENUATION, dB, upstream_attenuation); \
534 CXACRU_ATTR_##_action(CXINF_DOWNSTREAM_ATTENUATION, dB, downstream_attenuation); \
535 CXACRU_ATTR_##_action(CXINF_TRANSMITTER_POWER, s8, transmitter_power); \
536 CXACRU_ATTR_##_action(CXINF_UPSTREAM_BITS_PER_FRAME, u32, upstream_bits_per_frame); \
537 CXACRU_ATTR_##_action(CXINF_DOWNSTREAM_BITS_PER_FRAME, u32, downstream_bits_per_frame); \
538 CXACRU_ATTR_##_action(CXINF_STARTUP_ATTEMPTS, u32, startup_attempts); \
539 CXACRU_ATTR_##_action(CXINF_UPSTREAM_CRC_ERRORS, u32, upstream_crc_errors); \
540 CXACRU_ATTR_##_action(CXINF_DOWNSTREAM_CRC_ERRORS, u32, downstream_crc_errors); \
541 CXACRU_ATTR_##_action(CXINF_UPSTREAM_FEC_ERRORS, u32, upstream_fec_errors); \
542 CXACRU_ATTR_##_action(CXINF_DOWNSTREAM_FEC_ERRORS, u32, downstream_fec_errors); \
543 CXACRU_ATTR_##_action(CXINF_UPSTREAM_HEC_ERRORS, u32, upstream_hec_errors); \
544 CXACRU_ATTR_##_action(CXINF_DOWNSTREAM_HEC_ERRORS, u32, downstream_hec_errors); \
545 CXACRU_ATTR_##_action(CXINF_LINE_STARTABLE, bool, line_startable); \
546 CXACRU_ATTR_##_action(CXINF_MODULATION, MODU, modulation); \
547 CXACRU_ATTR_##_action(CXINF_ADSL_HEADEND, u32, adsl_headend); \
548 CXACRU_ATTR_##_action(CXINF_ADSL_HEADEND_ENVIRONMENT, u32, adsl_headend_environment); \
549 CXACRU_ATTR_##_action(CXINF_CONTROLLER_VERSION, u32, adsl_controller_version); \
550 CXACRU_CMD_##_action( adsl_state); \
551 CXACRU_SET_##_action( adsl_config);
556 static void cxacru_blocking_completion(
struct urb *
urb)
561 static void cxacru_timeout_kill(
unsigned long data)
574 timer.function = cxacru_timeout_kill;
580 *actual_length = urb->actual_length;
585 u8 *wdata,
int wsize,
u8 *rdata,
int rsize)
596 if (printk_ratelimit())
597 usb_err(instance->
usbatm,
"requested transfer size too large (%d, %d)\n",
606 init_completion(&instance->
rcv_done);
609 if (printk_ratelimit())
610 usb_err(instance->
usbatm,
"submit of read urb for cm %#x failed (%d)\n",
618 for (offb = offd = 0; offd < wsize; offd += stride, offb +=
CMD_PACKET_SIZE) {
620 memcpy(wbuf + offb + 4, wdata + offd,
min_t(
int, stride, wsize - offd));
623 instance->
snd_urb->transfer_buffer_length = wbuflen;
624 init_completion(&instance->
snd_done);
627 if (printk_ratelimit())
628 usb_err(instance->
usbatm,
"submit of write urb for cm %#x failed (%d)\n",
635 if (printk_ratelimit())
636 usb_err(instance->
usbatm,
"send of cm %#x failed (%d)\n", cm, ret);
640 ret = cxacru_start_wait_urb(instance->
rcv_urb, &instance->
rcv_done, &actlen);
642 if (printk_ratelimit())
643 usb_err(instance->
usbatm,
"receive of cm %#x failed (%d)\n", cm, ret);
647 if (printk_ratelimit())
648 usb_err(instance->
usbatm,
"invalid response length to cm %#x: %d\n",
655 for (offb = offd = 0; offd < rsize && offb < actlen; offb +=
CMD_PACKET_SIZE) {
656 if (rbuf[offb] != cm) {
657 if (printk_ratelimit())
658 usb_err(instance->
usbatm,
"wrong cm %#x in response to cm %#x\n",
664 if (printk_ratelimit())
665 usb_err(instance->
usbatm,
"response to cm %#x failed: %#x\n",
672 memcpy(rdata + offd, rbuf + offb + 4,
min_t(
int, stride, rsize - offd));
691 int buflen = ((size - 1) / stride + 1 + size * 2) * 4;
697 ret = cxacru_cm(instance, cm,
NULL, 0, (
u8 *) buf, buflen);
703 for (offb = 0; offb < len; ) {
705 if (l < 0 || l > stride || l > (len - offb) / 2) {
706 if (printk_ratelimit())
707 usb_err(instance->
usbatm,
"invalid data length from cm %#x: %d\n",
715 if (printk_ratelimit())
716 usb_err(instance->
usbatm,
"wrong index %#x in response to cm %#x\n",
732 static int cxacru_card_status(
struct cxacru_data *instance)
736 usb_dbg(instance->
usbatm,
"cxacru_adsl_start: CARD_GET_STATUS returned %d\n", ret);
742 static void cxacru_remove_device_files(
struct usbatm_data *usbatm_instance,
747 #define CXACRU_DEVICE_REMOVE_FILE(_name) \
748 device_remove_file(&intf->dev, &dev_attr_##_name);
750 #undef CXACRU_DEVICE_REMOVE_FILE
753 static int cxacru_atm_start(
struct usbatm_data *usbatm_instance,
761 dev_dbg(&intf->dev,
"%s\n", __func__);
765 atm_dev->
esi,
sizeof(atm_dev->
esi));
767 atm_err(usbatm_instance,
"cxacru_atm_start: CARD_GET_MAC_ADDRESS returned %d\n", ret);
771 #define CXACRU_DEVICE_CREATE_FILE(_name) \
772 ret = device_create_file(&intf->dev, &dev_attr_##_name); \
776 #undef CXACRU_DEVICE_CREATE_FILE
782 atm_err(usbatm_instance,
"cxacru_atm_start: CHIP_ADSL_LINE_START returned %d\n", ret);
807 cxacru_poll_status(&instance->
poll_work.work);
811 usb_err(usbatm_instance,
"cxacru_atm_start: device_create_file failed (%d)\n", ret);
812 cxacru_remove_device_files(usbatm_instance, atm_dev);
822 struct atm_dev *atm_dev = usbatm->
atm_dev;
823 int keep_polling = 1;
829 atm_warn(usbatm,
"poll status: error %d\n", ret);
836 atm_warn(usbatm,
"polling disabled, set adsl_state"
837 " to 'start' or 'poll' to resume\n");
870 atm_info(usbatm,
"ADSL line: down\n");
875 atm_info(usbatm,
"ADSL line: attempting to activate\n");
880 atm_info(usbatm,
"ADSL line: training\n");
885 atm_info(usbatm,
"ADSL line: channel analysis\n");
890 atm_info(usbatm,
"ADSL line: exchange\n");
897 atm_info(usbatm,
"ADSL line: up (%d kb/s down | %d kb/s up)\n",
903 atm_info(usbatm,
"ADSL line: waiting\n");
908 atm_info(usbatm,
"ADSL line: initializing\n");
947 int l =
min_t(
int, stride, size - offd);
956 memcpy(buf + offb, data + offd, l);
958 memset(buf + offb + l, 0, stride - l);
961 if ((offb >=
PAGE_SIZE) || (offd >= size)) {
965 dev_dbg(&usb_dev->dev,
"sending fw %#x failed\n", fw);
970 }
while (offd < size);
971 dev_dbg(&usb_dev->dev,
"sent fw %#x\n", fw);
980 static void cxacru_upload_firmware(
struct cxacru_data *instance,
986 struct usb_device *usb_dev = usbatm->
usb_dev;
988 usb_dev->descriptor.idProduct };
991 usb_dbg(usbatm,
"%s\n", __func__);
997 usb_err(usbatm,
"FirmwarePllFClkValue failed: %d\n", ret);
1005 usb_err(usbatm,
"FirmwarePllBClkValue failed: %d\n", ret);
1013 usb_err(usbatm,
"Enable SDRAM failed: %d\n", ret);
1018 usb_info(usbatm,
"loading firmware\n");
1021 usb_err(usbatm,
"Firmware upload failed: %d\n", ret);
1027 usb_info(usbatm,
"loading boot ROM patch\n");
1030 usb_err(usbatm,
"Boot ROM patching failed: %d\n", ret);
1038 usb_err(usbatm,
"Signature storing failed: %d\n", ret);
1042 usb_info(usbatm,
"starting device\n");
1050 usb_err(usbatm,
"Passing control to firmware failed: %d\n", ret);
1064 usb_err(usbatm,
"modem failed to initialize: %d\n", ret);
1069 static int cxacru_find_firmware(
struct cxacru_data *instance,
1076 sprintf(buf,
"cxacru-%s.bin", phase);
1077 usb_dbg(usbatm,
"cxacru_find_firmware: looking for %s\n", buf);
1080 usb_dbg(usbatm,
"no stage %s firmware found\n", phase);
1084 usb_info(usbatm,
"found firmware %s\n", buf);
1089 static int cxacru_heavy_init(
struct usbatm_data *usbatm_instance,
1095 int ret = cxacru_find_firmware(instance,
"fw", &fw);
1097 usb_warn(usbatm_instance,
"firmware (cxacru-fw.bin) unavailable (system misconfigured?)\n");
1102 ret = cxacru_find_firmware(instance,
"bp", &bp);
1104 usb_warn(usbatm_instance,
"boot ROM patch (cxacru-bp.bin) unavailable (system misconfigured?)\n");
1110 cxacru_upload_firmware(instance, fw, bp);
1116 ret = cxacru_card_status(instance);
1118 usb_dbg(usbatm_instance,
"modem initialisation failed\n");
1120 usb_dbg(usbatm_instance,
"done setting up the modem\n");
1125 static int cxacru_bind(
struct usbatm_data *usbatm_instance,
1129 struct usb_device *usb_dev = interface_to_usbdev(intf);
1130 struct usb_host_endpoint *cmd_ep = usb_dev->ep_in[
CXACRU_EP_CMD];
1134 instance = kzalloc(
sizeof(*instance),
GFP_KERNEL);
1136 usb_dbg(usbatm_instance,
"cxacru_bind: no memory for instance data\n");
1140 instance->
usbatm = usbatm_instance;
1152 usb_dbg(usbatm_instance,
"cxacru_bind: no memory for rcv_buf\n");
1158 usb_dbg(usbatm_instance,
"cxacru_bind: no memory for snd_buf\n");
1164 usb_dbg(usbatm_instance,
"cxacru_bind: no memory for rcv_urb\n");
1170 usb_dbg(usbatm_instance,
"cxacru_bind: no memory for snd_urb\n");
1176 usb_dbg(usbatm_instance,
"cxacru_bind: no command endpoint\n");
1183 usb_fill_int_urb(instance->
rcv_urb,
1186 cxacru_blocking_completion, &instance->
rcv_done, 1);
1188 usb_fill_int_urb(instance->
snd_urb,
1191 cxacru_blocking_completion, &instance->
snd_done, 4);
1193 usb_fill_bulk_urb(instance->
rcv_urb,
1196 cxacru_blocking_completion, &instance->
rcv_done);
1198 usb_fill_bulk_urb(instance->
snd_urb,
1201 cxacru_blocking_completion, &instance->
snd_done);
1224 static void cxacru_unbind(
struct usbatm_data *usbatm_instance,
1230 usb_dbg(usbatm_instance,
"cxacru_unbind entered\n");
1233 usb_dbg(usbatm_instance,
"cxacru_unbind: NULL instance!\n");
1266 .pll_f_clk = 0x02d874df,
1267 .pll_b_clk = 0x0196a51a,
1268 .boot_rom_patch = 1,
1274 .boot_rom_patch = 0,
1279 USB_DEVICE(0x0572, 0xcafe), .driver_info = (
unsigned long) &cxacru_cafe
1282 USB_DEVICE(0x0572, 0xcb00), .driver_info = (
unsigned long) &cxacru_cb00
1285 USB_DEVICE(0x0572, 0xcb01), .driver_info = (
unsigned long) &cxacru_cb00
1288 USB_DEVICE(0x0572, 0xcb02), .driver_info = (
unsigned long) &cxacru_cb00
1291 USB_DEVICE(0x0572, 0xcb06), .driver_info = (
unsigned long) &cxacru_cb00
1294 USB_DEVICE(0x0572, 0xcb07), .driver_info = (
unsigned long) &cxacru_cb00
1297 USB_DEVICE(0x08e3, 0x0100), .driver_info = (
unsigned long) &cxacru_cafe
1300 USB_DEVICE(0x08e3, 0x0102), .driver_info = (
unsigned long) &cxacru_cb00
1303 USB_DEVICE(0x0eb0, 0x3457), .driver_info = (
unsigned long) &cxacru_cafe
1306 USB_DEVICE(0x1803, 0x5510), .driver_info = (
unsigned long) &cxacru_cb00
1309 USB_DEVICE(0x0675, 0x0200), .driver_info = (
unsigned long) &cxacru_cb00
1312 USB_DEVICE(0x0586, 0x330a), .driver_info = (
unsigned long) &cxacru_cb00
1315 USB_DEVICE(0x0586, 0x330b), .driver_info = (
unsigned long) &cxacru_cb00
1318 USB_DEVICE(0x0659, 0x0020), .driver_info = (
unsigned long) &cxacru_cb00
1321 USB_DEVICE(0x0509, 0x0812), .driver_info = (
unsigned long) &cxacru_cb00
1324 USB_DEVICE(0x100d, 0xcb01), .driver_info = (
unsigned long) &cxacru_cb00
1327 USB_DEVICE(0x100d, 0x3342), .driver_info = (
unsigned long) &cxacru_cb00
1335 .driver_name = cxacru_driver_name,
1336 .bind = cxacru_bind,
1337 .heavy_init = cxacru_heavy_init,
1338 .unbind = cxacru_unbind,
1339 .atm_start = cxacru_atm_start,
1340 .atm_stop = cxacru_remove_device_files,
1350 struct usb_device *usb_dev = interface_to_usbdev(intf);
1357 &&
usb_string(usb_dev, usb_dev->descriptor.iProduct,
1358 buf,
sizeof(buf)) > 0) {
1359 if (!
strcmp(buf,
"USB NET CARD")) {
1360 dev_info(&intf->dev,
"ignoring cx82310_eth device\n");
1368 static struct usb_driver cxacru_usb_driver = {
1369 .name = cxacru_driver_name,
1370 .probe = cxacru_usb_probe,
1372 .id_table = cxacru_usb_ids