#include "../include/can.h"
#include "../include/can_sysdep.h"
#include "../include/main.h"
+#include "../include/devcommon.h"
+#include "../include/setup.h"
#include "../include/usbcan.h"
-/*
- * IO_RANGE is the io-memory range that gets reserved, please adjust according
- * your hardware. Example: #define IO_RANGE 0x100 for i82527 chips or
- * #define IO_RANGE 0x20 for sja1000 chips in basic CAN mode.
- */
-#define IO_RANGE 0x100
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
+ #include <linux/freezer.h>
+#endif
+
+static int usbcan_probe(struct usb_interface *interface, const struct usb_device_id *id);
+static void usbcan_disconnect(struct usb_interface *interface);
+
+volatile int usbcan_chip_count=0;
+
+/* table of devices that work with this driver */
+static struct usb_device_id usbcan_table [] = {
+ { USB_DEVICE(USBCAN_VENDOR_ID, USBCAN_PRODUCT_ID) },
+ { } /* Terminating entry */
+};
+MODULE_DEVICE_TABLE(usb, usbcan_table);
+
+static struct usb_driver usbcan_driver = {
+ .name = "usbcan",
+ .id_table = usbcan_table,
+ .probe = usbcan_probe,
+ .disconnect = usbcan_disconnect,
+};
/**
* usbcan_request_io: - reserve io or memory range for can board
*/
int usbcan_request_io(struct candevice_t *candev)
{
- if (!can_request_io_region(candev->io_addr,IO_RANGE,DEVICE_NAME)) {
- CANMSG("Unable to open port: 0x%lx\n",candev->io_addr);
+ struct usbcan_devs *usbdevs = (struct usbcan_devs *)candev->sysdevptr.anydev;
+
+ if (!usbdevs){
+ CANMSG("USBCAN_REQUEST_IO: Cannot register usbcan while usb device is not present.\n");
+ CANMSG("USBCAN_REQUEST_IO: Usbcan registers automatically on device insertion.\n");
return -ENODEV;
- }else {
- DEBUGMSG("Registered IO-memory: 0x%lx - 0x%lx\n", candev->io_addr, candev->io_addr + IO_RANGE - 1);
}
+
return 0;
}
*/
int usbcan_release_io(struct candevice_t *candev)
{
- can_release_io_region(candev->io_addr,IO_RANGE);
-
return 0;
}
return 0;
}
-#define RESET_ADDR 0x0
-
/**
* usbcan_init_hw_data - Initialize hardware cards
* @candev: Pointer to candevice/board structure
candev->res_addr=RESET_ADDR;
candev->nr_82527_chips=0;
candev->nr_sja1000_chips=0;
- candev->nr_all_chips=1;
+ candev->nr_all_chips=usbcan_chip_count;
candev->flags |= CANDEV_PROGRAMMABLE_IRQ*0;
return 0;
}
-/**
- * usbcan_init_chip_data - Initialize chips
- * @candev: Pointer to candevice/board structure
- * @chipnr: Number of the CAN chip on the hardware card
- *
- * The function usbcan_init_chip_data() is used to initialize the hardware
- * structure containing information about the CAN chips.
- * %CHIP_TYPE represents the type of CAN chip. %CHIP_TYPE can be "i82527" or
- * "sja1000".
- * The @chip_base_addr entry represents the start of the 'official' memory map
- * of the installed chip. It's likely that this is the same as the @io_addr
- * argument supplied at module loading time.
- * The @clock entry holds the chip clock value in Hz.
- * The entry @sja_cdr_reg holds hardware specific options for the Clock Divider
- * register. Options defined in the %sja1000.h file:
- * %sjaCDR_CLKOUT_MASK, %sjaCDR_CLK_OFF, %sjaCDR_RXINPEN, %sjaCDR_CBP, %sjaCDR_PELICAN
- * The entry @sja_ocr_reg holds hardware specific options for the Output Control
- * register. Options defined in the %sja1000.h file:
- * %sjaOCR_MODE_BIPHASE, %sjaOCR_MODE_TEST, %sjaOCR_MODE_NORMAL, %sjaOCR_MODE_CLOCK,
- * %sjaOCR_TX0_LH, %sjaOCR_TX1_ZZ.
- * The entry @int_clk_reg holds hardware specific options for the Clock Out
- * register. Options defined in the %i82527.h file:
- * %iCLK_CD0, %iCLK_CD1, %iCLK_CD2, %iCLK_CD3, %iCLK_SL0, %iCLK_SL1.
- * The entry @int_bus_reg holds hardware specific options for the Bus
- * Configuration register. Options defined in the %i82527.h file:
- * %iBUS_DR0, %iBUS_DR1, %iBUS_DT1, %iBUS_POL, %iBUS_CBY.
- * The entry @int_cpu_reg holds hardware specific options for the cpu interface
- * register. Options defined in the %i82527.h file:
- * %iCPU_CEN, %iCPU_MUX, %iCPU_SLP, %iCPU_PWD, %iCPU_DMC, %iCPU_DSC, %iCPU_RST.
- * Return Value: The function always returns zero
- * File: src/usbcan.c
- */
-int usbcan_init_chip_data(struct candevice_t *candev, int chipnr)
-{
- canchip_t chip=candev->chip[chipnr];
-
- chip->chip_type="usbcan";
- chip->max_objects=1;
- usbcan_register(chip->chipspecops);
-
- CANMSG("initializing usbcan chip operations\n");
- chipspecops->chip_config=usbcan_chip_config;
- chipspecops->baud_rate=usbcan_baud_rate;
- chipspecops->standard_mask=usbcan_standard_mask;
- chipspecops->extended_mask=usbcan_extended_mask;
- chipspecops->message15_mask=usbcan_extended_mask;
- chipspecops->clear_objects=usbcan_clear_objects;
- chipspecops->config_irqs=usbcan_config_irqs;
- chipspecops->pre_read_config=usbcan_pre_read_config;
- chipspecops->pre_write_config=usbcan_pre_write_config;
- chipspecops->send_msg=usbcan_send_msg;
- chipspecops->check_tx_stat=usbcan_check_tx_stat;
- chipspecops->wakeup_tx=usbcan_wakeup_tx;
- chipspecops->remote_request=usbcan_remote_request;
- chipspecops->enable_configuration=usbcan_enable_configuration;
- chipspecops->disable_configuration=usbcan_disable_configuration;
- chipspecops->attach_to_chip=usbcan_attach_to_chip;
- chipspecops->release_chip=usbcan_release_chip;
- chipspecops->set_btregs=usbcan_set_btregs;
- chipspecops->start_chip=usbcan_start_chip;
- chipspecops->stop_chip=usbcan_stop_chip;
- chipspecops->irq_handler=usbcan_irq_handler;
- chipspecops->irq_accept=NULL;
-
- candev->chip[chipnr]->chip_base_addr=candev->io_addr;
- candev->chip[chipnr]->clock = 16000000;
- candev->chip[chipnr]->int_cpu_reg = iCPU_DSC;
- candev->chip[chipnr]->int_clk_reg = iCLK_SL1;
- candev->chip[chipnr]->int_bus_reg = iBUS_CBY;
- candev->chip[chipnr]->sja_cdr_reg = sjaCDR_CBP | sjaCDR_CLK_OFF;
- candev->chip[chipnr]->sja_ocr_reg = sjaOCR_MODE_NORMAL |
- sjaOCR_TX0_LH;
-
- return 0;
-}
-
/**
* usbcan_init_obj_data - Initialize message buffers
* @chip: Pointer to chip specific structure
*/
int usbcan_init_obj_data(struct canchip_t *chip, int objnr)
{
- chip->msgobj[objnr]->obj_base_addr=chip->chip_base_addr+(objnr+1)*0x10;
+ chip->msgobj[objnr]->obj_base_addr=0;
return 0;
}
return 0;
}
-/**
- * usbcan_write_register - Low level write register routine
- * @data: data to be written
- * @address: memory address to write to
- *
- * The function usbcan_write_register() is used to write to hardware registers
- * on the CAN chip. You should only have to edit this function if your hardware
- * uses some specific write process.
- * Return Value: The function does not return a value
- * File: src/usbcan.c
- */
-void usbcan_write_register(unsigned data, unsigned long address)
-{
- outb(data,address);
-}
-
-/**
- * usbcan_read_register - Low level read register routine
- * @address: memory address to read from
- *
- * The function usbcan_read_register() is used to read from hardware registers
- * on the CAN chip. You should only have to edit this function if your hardware
- * uses some specific read process.
- * Return Value: The function returns the value stored in @address
- * File: src/usbcan.c
- */
-unsigned usbcan_read_register(unsigned long address)
-{
- return inb(address);
-}
-
/* !!! Don't change this function !!! */
int usbcan_register(struct hwspecops_t *hwspecops)
{
hwspecops->init_hw_data = usbcan_init_hw_data;
hwspecops->init_chip_data = usbcan_init_chip_data;
hwspecops->init_obj_data = usbcan_init_obj_data;
- hwspecops->write_register = usbcan_write_register;
- hwspecops->read_register = usbcan_read_register;
+ hwspecops->write_register = NULL;
+ hwspecops->read_register = NULL;
hwspecops->program_irq = usbcan_program_irq;
return 0;
}
-static const char *sja1000_ecc_errc_str[]={
- "bit error",
- "form error",
- "stuff error",
- "other type of error"
-};
+// static int sja1000_report_error_limit_counter;
-static const char *sja1000_ecc_seg_str[]={
- "?0?",
- "?1?",
- "ID.28 to ID.21",
- "start of frame",
- "bit SRTR",
- "bit IDE",
- "ID.20 to ID.18",
- "ID.17 to ID.13",
- "CRC sequence",
- "reserved bit 0",
- "data field",
- "data length code",
- "bit RTR",
- "reserved bit 1",
- "ID.4 to ID.0",
- "ID.12 to ID.5",
- "?16?"
- "active error flag",
- "intermission",
- "tolerate dominant bits",
- "?20?",
- "?21?",
- "passive error flag",
- "error delimiter",
- "CRC delimiter",
- "acknowledge slot",
- "end of frame",
- "acknowledge delimiter",
- "overload flag",
- "?29?",
- "?30?",
- "?31?"
-};
-
-#endif /*CONFIG_OC_LINCAN_DETAILED_ERRORS*/
-
-static int sja1000_report_error_limit_counter;
-
-static void sja1000_report_error(struct canchip_t *chip,
+static void usbcan_report_error(struct canchip_t *chip,
unsigned sr, unsigned ir, unsigned ecc)
{
+ /*TODO : Error reporting from device */
+
+#if 0
if(sja1000_report_error_limit_counter>=100)
return;
);
}
#endif /*CONFIG_OC_LINCAN_DETAILED_ERRORS*/
+#endif
}
*/
int usbcan_enable_configuration(struct canchip_t *chip)
{
- int i=0;
- enum sja1000_PeliCAN_MOD flags;
-
- can_disable_irq(chip->chip_irq);
-
- flags=can_read_reg(chip,SJAMOD);
-
- while ((!(flags & sjaMOD_RM)) && (i<=10)) {
- can_write_reg(chip, sjaMOD_RM, SJAMOD);
-// TODO: configurable sjaMOD_AFM (32/16 bit acceptance filter)
-// config sjaMOD_LOM (listen only)
- udelay(100);
- i++;
- flags=can_read_reg(chip, SJAMOD);
- }
- if (i>=10) {
- CANMSG("Reset error\n");
- can_enable_irq(chip->chip_irq);
- return -ENODEV;
- }
-
return 0;
}
*/
int usbcan_disable_configuration(struct canchip_t *chip)
{
- int i=0;
- enum sja1000_PeliCAN_MOD flags;
-
- flags=can_read_reg(chip,SJAMOD);
-
- while ( (flags & sjaMOD_RM) && (i<=50) ) {
-// could be as long as 11*128 bit times after buss-off
- can_write_reg(chip, 0, SJAMOD);
-// TODO: configurable sjaMOD_AFM (32/16 bit acceptance filter)
-// config sjaMOD_LOM (listen only)
- udelay(100);
- i++;
- flags=can_read_reg(chip, SJAMOD);
- }
- if (i>=10) {
- CANMSG("Error leaving reset status\n");
- return -ENODEV;
- }
-
- can_enable_irq(chip->chip_irq);
-
return 0;
}
*/
int usbcan_chip_config(struct canchip_t *chip)
{
- int i;
- unsigned char n, r;
-
- if (usbcan_enable_configuration(chip))
- return -ENODEV;
-
- /* Set mode, clock out, comparator */
- can_write_reg(chip,sjaCDR_PELICAN|chip->sja_cdr_reg,SJACDR);
-
- /* Ensure, that interrupts are disabled even on the chip level now */
- can_write_reg(chip, sjaDISABLE_INTERRUPTS, SJAIER);
-
- /* Set driver output configuration */
- can_write_reg(chip,chip->sja_ocr_reg,SJAOCR);
-
- /* Simple check for chip presence */
- for (i=0, n=0x5a; i<8; i++, n+=0xf) {
- can_write_reg(chip,n,SJAACR0+i);
- }
- for (i=0, n=0x5a; i<8; i++, n+=0xf) {
- r = n^can_read_reg(chip,SJAACR0+i);
- if (r) {
- CANMSG("usbcan_chip_config: chip connection broken,"
- " readback differ 0x%02x\n", r);
- return -ENODEV;
- }
- }
-
-
- if (usbcan_extended_mask(chip,0x00000000, 0xffffffff))
- return -ENODEV;
-
- if (!chip->baudrate)
- chip->baudrate=1000000;
- if (usbcan_baud_rate(chip,chip->baudrate,chip->clock,0,75,0))
- return -ENODEV;
-
- /* Enable hardware interrupts */
- can_write_reg(chip, sjaENABLE_INTERRUPTS, SJAIER);
-
- usbcan_disable_configuration(chip);
-
return 0;
}
*/
int usbcan_extended_mask(struct canchip_t *chip, unsigned long code, unsigned long mask)
{
- int i;
+ int retval;
+ struct usbcan_usb *dev=(struct usbcan_usb*)chip->chip_data;
- if (usbcan_enable_configuration(chip))
- return -ENODEV;
+ u8 usbbuf[USBCAN_TRANSFER_SIZE];
-// LSB to +3, MSB to +0
- for(i=SJA_PeliCAN_AC_LEN; --i>=0;) {
- can_write_reg(chip,code&0xff,SJAACR0+i);
- can_write_reg(chip,mask&0xff,SJAAMR0+i);
- code >>= 8;
- mask >>= 8;
- }
+ if (!dev)
+ return -ENODEV;
- DEBUGMSG("Setting acceptance code to 0x%lx\n",(unsigned long)code);
- DEBUGMSG("Setting acceptance mask to 0x%lx\n",(unsigned long)mask);
+ *(uint32_t *)(usbbuf)=cpu_to_le32(mask);
+ *(uint32_t *)(usbbuf+4)=cpu_to_le32(code);
+
+ retval=usb_control_msg(dev->udev,
+ usb_sndctrlpipe(dev->udev, 0),
+ USBCAN_VENDOR_EXT_MASK_SET,
+ USB_TYPE_VENDOR,
+ cpu_to_le16(0), cpu_to_le16(chip->chip_idx),
+ &usbbuf, USBCAN_TRANSFER_SIZE,
+ 10000);
+ if (retval<0)
+ return -ENODEV;
- usbcan_disable_configuration(chip);
+ retval = usb_control_msg(dev->udev,
+ usb_rcvctrlpipe(dev->udev, 0),
+ USBCAN_VENDOR_EXT_MASK_STATUS,
+ USB_TYPE_VENDOR,
+ cpu_to_le16(0), cpu_to_le16(chip->chip_idx),
+ &usbbuf, USBCAN_TRANSFER_SIZE,
+ 10000);
+
+ if (retval==1){
+ if(usbbuf[0]==1){
+ DEBUGMSG("Setting acceptance code to 0x%lx\n",(unsigned long)code);
+ DEBUGMSG("Setting acceptance mask to 0x%lx\n",(unsigned long)mask);
+ return 0;
+ }
+ }
- return 0;
+ CANMSG("Setting extended mask failed\n");
+ return -EINVAL;
}
/**
int usbcan_baud_rate(struct canchip_t *chip, int rate, int clock, int sjw,
int sampl_pt, int flags)
{
- int best_error = 1000000000, error;
- int best_tseg=0, best_brp=0, best_rate=0, brp=0;
- int tseg=0, tseg1=0, tseg2=0;
-
- if (usbcan_enable_configuration(chip))
- return -ENODEV;
-
- clock /=2;
-
- /* tseg even = round down, odd = round up */
- for (tseg=(0+0+2)*2; tseg<=(sjaMAX_TSEG2+sjaMAX_TSEG1+2)*2+1; tseg++) {
- brp = clock/((1+tseg/2)*rate)+tseg%2;
- if (brp == 0 || brp > 64)
- continue;
- error = rate - clock/(brp*(1+tseg/2));
- if (error < 0)
- error = -error;
- if (error <= best_error) {
- best_error = error;
- best_tseg = tseg/2;
- best_brp = brp-1;
- best_rate = clock/(brp*(1+tseg/2));
- }
- }
- if (best_error && (rate/best_error < 10)) {
- CANMSG("baud rate %d is not possible with %d Hz clock\n",
- rate, 2*clock);
- CANMSG("%d bps. brp=%d, best_tseg=%d, tseg1=%d, tseg2=%d\n",
- best_rate, best_brp, best_tseg, tseg1, tseg2);
- return -EINVAL;
- }
- tseg2 = best_tseg-(sampl_pt*(best_tseg+1))/100;
- if (tseg2 < 0)
- tseg2 = 0;
- if (tseg2 > sjaMAX_TSEG2)
- tseg2 = sjaMAX_TSEG2;
- tseg1 = best_tseg-tseg2-2;
- if (tseg1>sjaMAX_TSEG1) {
- tseg1 = sjaMAX_TSEG1;
- tseg2 = best_tseg-tseg1-2;
- }
-
- DEBUGMSG("Setting %d bps.\n", best_rate);
- DEBUGMSG("brp=%d, best_tseg=%d, tseg1=%d, tseg2=%d, sampl_pt=%d\n",
- best_brp, best_tseg, tseg1, tseg2,
- (100*(best_tseg-tseg2)/(best_tseg+1)));
-
-
- can_write_reg(chip, sjw<<6 | best_brp, SJABTR0);
- can_write_reg(chip, ((flags & BTR1_SAM) != 0)<<7 | (tseg2<<4)
- | tseg1, SJABTR1);
-
- usbcan_disable_configuration(chip);
+ int retval;
+ struct usbcan_usb *dev=(struct usbcan_usb*)chip->chip_data;
- return 0;
-}
+ u8 usbbuf[USBCAN_TRANSFER_SIZE];
-/**
- * usbcan_read: - reads and distributes one or more received messages
- * @chip: pointer to chip state structure
- * @obj: pinter to CAN message queue information
- *
- * File: src/usbcan.c
- */
-void usbcan_read(struct canchip_t *chip, struct msgobj_t *obj) {
- int i, flags, len, datastart;
- do {
- flags = can_read_reg(chip,SJAFRM);
- if(flags&sjaFRM_FF) {
- obj->rx_msg.id =
- (can_read_reg(chip,SJAID0)<<21) +
- (can_read_reg(chip,SJAID1)<<13) +
- (can_read_reg(chip,SJAID2)<<5) +
- (can_read_reg(chip,SJAID3)>>3);
- datastart = SJADATE;
- } else {
- obj->rx_msg.id =
- (can_read_reg(chip,SJAID0)<<3) +
- (can_read_reg(chip,SJAID1)>>5);
- datastart = SJADATS;
- }
- obj->rx_msg.flags =
- ((flags & sjaFRM_RTR) ? MSG_RTR : 0) |
- ((flags & sjaFRM_FF) ? MSG_EXT : 0);
- len = flags & sjaFRM_DLC_M;
- obj->rx_msg.length = len;
- if(len > CAN_MSG_LENGTH) len = CAN_MSG_LENGTH;
- for(i=0; i< len; i++) {
- obj->rx_msg.data[i]=can_read_reg(chip,datastart+i);
- }
-
- /* fill CAN message timestamp */
- can_filltimestamp(&obj->rx_msg.timestamp);
+ if (!dev)
+ return -ENODEV;
- canque_filter_msg2edges(obj->qends, &obj->rx_msg);
+ *(int32_t *)(usbbuf)=cpu_to_le32(rate);
+ *(int32_t *)(usbbuf+4)=cpu_to_le32(sjw);
+ *(int32_t *)(usbbuf+8)=cpu_to_le32(sampl_pt);
+ *(int32_t *)(usbbuf+12)=cpu_to_le32(flags);
+
+ retval=usb_control_msg(dev->udev,
+ usb_sndctrlpipe(dev->udev, 0),
+ USBCAN_VENDOR_BAUD_RATE_SET,
+ USB_TYPE_VENDOR,
+ cpu_to_le16(0), cpu_to_le16(chip->chip_idx),
+ &usbbuf, USBCAN_TRANSFER_SIZE,
+ 10000);
+ if (retval<0)
+ return -ENODEV;
- can_write_reg(chip, sjaCMR_RRB, SJACMR);
+ retval = usb_control_msg(dev->udev,
+ usb_rcvctrlpipe(dev->udev, 0),
+ USBCAN_VENDOR_BAUD_RATE_STATUS,
+ USB_TYPE_VENDOR,
+ cpu_to_le16(0), cpu_to_le16(chip->chip_idx),
+ usbbuf, USBCAN_TRANSFER_SIZE,
+ 10000);
+
+ if (retval==1){
+ if(usbbuf[0]==1)
+ return 0;
+ }
- } while (can_read_reg(chip, SJASR) & sjaSR_RBS);
+ CANMSG("baud rate %d is not possible to set\n",
+ rate);
+ return -EINVAL;
}
/**
*/
int usbcan_pre_read_config(struct canchip_t *chip, struct msgobj_t *obj)
{
- int status;
- status=can_read_reg(chip,SJASR);
-
- if(status & sjaSR_BS) {
- /* Try to recover from error condition */
- DEBUGMSG("usbcan_pre_read_config bus-off recover 0x%x\n",status);
- usbcan_enable_configuration(chip);
- can_write_reg(chip, 0, SJARXERR);
- can_write_reg(chip, 0, SJATXERR1);
- can_read_reg(chip, SJAECC);
- usbcan_disable_configuration(chip);
- }
-
- if (!(status&sjaSR_RBS)) {
- return 0;
- }
-
- can_write_reg(chip, sjaDISABLE_INTERRUPTS, SJAIER); //disable interrupts for a moment
- usbcan_read(chip, obj);
- can_write_reg(chip, sjaENABLE_INTERRUPTS, SJAIER); //enable interrupts
- return 1;
+ return 0;
}
#define MAX_TRANSMIT_WAIT_LOOPS 10
int usbcan_pre_write_config(struct canchip_t *chip, struct msgobj_t *obj,
struct canmsg_t *msg)
{
- int i=0;
- unsigned int id;
- int status;
- int len;
-
- /* Wait until Transmit Buffer Status is released */
- while ( !((status=can_read_reg(chip, SJASR)) & sjaSR_TBS) &&
- i++<MAX_TRANSMIT_WAIT_LOOPS) {
- udelay(i);
- }
-
- if(status & sjaSR_BS) {
- /* Try to recover from error condition */
- DEBUGMSG("usbcan_pre_write_config bus-off recover 0x%x\n",status);
- usbcan_enable_configuration(chip);
- can_write_reg(chip, 0, SJARXERR);
- can_write_reg(chip, 0, SJATXERR1);
- can_read_reg(chip, SJAECC);
- usbcan_disable_configuration(chip);
- }
- if (!(can_read_reg(chip, SJASR) & sjaSR_TBS)) {
- CANMSG("Transmit timed out, cancelling\n");
-// here we should check if there is no write/select waiting for this
-// transmit. If so, set error ret and wake up.
-// CHECKME: if we do not disable sjaIER_TIE (TX IRQ) here we get interrupt
-// immediately
- can_write_reg(chip, sjaCMR_AT, SJACMR);
- i=0;
- while ( !(can_read_reg(chip, SJASR) & sjaSR_TBS) &&
- i++<MAX_TRANSMIT_WAIT_LOOPS) {
- udelay(i);
- }
- if (!(can_read_reg(chip, SJASR) & sjaSR_TBS)) {
- CANMSG("Could not cancel, please reset\n");
- return -EIO;
- }
- }
- len = msg->length;
- if(len > CAN_MSG_LENGTH) len = CAN_MSG_LENGTH;
- /* len &= sjaFRM_DLC_M; ensured by above condition already */
- can_write_reg(chip, ((msg->flags&MSG_EXT)?sjaFRM_FF:0) |
- ((msg->flags & MSG_RTR) ? sjaFRM_RTR : 0) | len, SJAFRM);
- if(msg->flags&MSG_EXT) {
- id=msg->id<<3;
- can_write_reg(chip, id & 0xff, SJAID3);
- id >>= 8;
- can_write_reg(chip, id & 0xff, SJAID2);
- id >>= 8;
- can_write_reg(chip, id & 0xff, SJAID1);
- id >>= 8;
- can_write_reg(chip, id, SJAID0);
- for(i=0; i < len; i++) {
- can_write_reg(chip, msg->data[i], SJADATE+i);
- }
- } else {
- id=msg->id<<5;
- can_write_reg(chip, (id >> 8) & 0xff, SJAID0);
- can_write_reg(chip, id & 0xff, SJAID1);
- for(i=0; i < len; i++) {
- can_write_reg(chip, msg->data[i], SJADATS+i);
- }
- }
return 0;
}
int usbcan_send_msg(struct canchip_t *chip, struct msgobj_t *obj,
struct canmsg_t *msg)
{
- can_write_reg(chip, sjaCMR_TR, SJACMR);
-
return 0;
}
*/
int usbcan_check_tx_stat(struct canchip_t *chip)
{
- if (can_read_reg(chip,SJASR) & sjaSR_TCS)
+ struct usbcan_usb *dev=(struct usbcan_usb*)chip->chip_data;
+ if (!dev)
return 0;
- else
+ if (test_bit(USBCAN_TX_PENDING,&dev->flags))
return 1;
+ return 0;
}
/**
int usbcan_set_btregs(struct canchip_t *chip, unsigned short btr0,
unsigned short btr1)
{
- if (usbcan_enable_configuration(chip))
- return -ENODEV;
-
- can_write_reg(chip, btr0, SJABTR0);
- can_write_reg(chip, btr1, SJABTR1);
+ int retval;
+ u8 buf[USBCAN_TRANSFER_SIZE];
+ struct usbcan_usb *dev=(struct usbcan_usb*)chip->chip_data;
+ uint16_t value=(btr1&0xFF)<<8 | (btr0&0xFF);
- usbcan_disable_configuration(chip);
+ if (!dev)
+ return -ENODEV;
- return 0;
+ retval = usb_control_msg(dev->udev,
+ usb_rcvctrlpipe(dev->udev, 0),
+ USBCAN_VENDOR_SET_BTREGS,
+ USB_TYPE_VENDOR,
+ cpu_to_le16(value), cpu_to_le16(chip->chip_idx),
+ &buf, USBCAN_TRANSFER_SIZE,
+ 10000);
+
+ if (retval==1){
+ if(buf[0]==1)
+ return 0;
+ }
+ return -ENODEV;
}
/**
*/
int usbcan_start_chip(struct canchip_t *chip)
{
- enum sja1000_PeliCAN_MOD flags;
+ int retval;
+ u8 buf[USBCAN_TRANSFER_SIZE];
+ struct usbcan_usb *dev=(struct usbcan_usb*)chip->chip_data;
- flags = can_read_reg(chip, SJAMOD) & (sjaMOD_LOM|sjaMOD_STM|sjaMOD_AFM|sjaMOD_SM);
- can_write_reg(chip, flags, SJAMOD);
+ if (!dev)
+ return -ENODEV;
- sja1000_report_error_limit_counter=0;
+ retval = usb_control_msg(dev->udev,
+ usb_rcvctrlpipe(dev->udev, 0),
+ USBCAN_VENDOR_START_CHIP,
+ USB_TYPE_VENDOR,
+ cpu_to_le16(0), cpu_to_le16(chip->chip_idx),
+ &buf, USBCAN_TRANSFER_SIZE,
+ 10000);
+
+ if (retval==1){
+ if(buf[0]==1)
+ return 0;
+ }
+ return -ENODEV;
+}
- return 0;
+/**
+ * usbcan_chip_queue_status: - gets queue status from usb device
+ * @chip: pointer to chip state structure
+ *
+ * Return Value: negative value reports error.
+ * 0 means queue is not full
+ * 1 means queue is full
+ * File: src/usbcan.c
+ */
+int usbcan_chip_queue_status(struct canchip_t *chip)
+{
+ int retval;
+ u8 buf[USBCAN_TRANSFER_SIZE];
+ struct usbcan_usb *dev=(struct usbcan_usb*)chip->chip_data;
+
+ if (!dev)
+ return -ENODEV;
+ retval = usb_control_msg(dev->udev,
+ usb_rcvctrlpipe(dev->udev, 0),
+ USBCAN_VENDOR_CHECK_TX_STAT,
+ USB_TYPE_VENDOR,
+ cpu_to_le16(0), cpu_to_le16(chip->chip_idx),
+ &buf, USBCAN_TRANSFER_SIZE,
+ 10000);
+
+ if (retval==1){
+ CANMSG("Chip_queue_status: %d\n",buf[0]);
+ if(buf[0]==1)
+ return 0;
+ if(buf[0]==0)
+ return 1;
+ }
+ CANMSG("Chip_queue_status error: %d\n",retval);
+ return -ENODEV;
}
/**
*/
int usbcan_stop_chip(struct canchip_t *chip)
{
- enum sja1000_PeliCAN_MOD flags;
+ int retval;
+ u8 buf[USBCAN_TRANSFER_SIZE];
+ struct usbcan_usb *dev=(struct usbcan_usb*)chip->chip_data;
- flags = can_read_reg(chip, SJAMOD) & (sjaMOD_LOM|sjaMOD_STM|sjaMOD_AFM|sjaMOD_SM);
- can_write_reg(chip, flags|sjaMOD_RM, SJAMOD);
+ if (!dev)
+ return -ENODEV;
- return 0;
+ retval = usb_control_msg(dev->udev,
+ usb_rcvctrlpipe(dev->udev, 0),
+ USBCAN_VENDOR_STOP_CHIP,
+ USB_TYPE_VENDOR,
+ cpu_to_le16(0), cpu_to_le16(chip->chip_idx),
+ &buf, USBCAN_TRANSFER_SIZE,
+ 10000);
+
+ if (retval==1){
+ if(buf[0]==1)
+ return 0;
+ }
+ return -ENODEV;
+}
+
+/**
+ * usbcan_register_devs: - attaches usb device data to the chip structure
+ * @chip: pointer to chip state structure
+ * @data: usb device data
+ *
+ * File: src/usbcan.c
+ */
+void usbcan_register_devs(struct canchip_t *chip,void *data){
+ struct usbcan_devs *usbdevs=(struct usbcan_devs *)data;
+ if (!usbdevs){
+ CANMSG("Bad structure given\n");
+ return;
+ }
+ if (chip->chip_idx>=usbdevs->count) {
+ CANMSG("Requested chip number is bigger than chip count\n");
+ return;
+ }
+
+ usbdevs->devs[chip->chip_idx]->chip=chip;
+ chip->chip_data=(void *)usbdevs->devs[chip->chip_idx];
}
/**
*/
int usbcan_attach_to_chip(struct canchip_t *chip)
{
+ struct usbcan_usb *dev = (struct usbcan_usb *)chip->chip_data;
+
+ /* start kernel thread */
+ dev->comthread=can_kthread_run(usbcan_kthread, (void *)dev, "usbcan_%d",chip->chip_idx);
+
return 0;
}
*/
int usbcan_release_chip(struct canchip_t *chip)
{
+ struct usbcan_usb *dev = (struct usbcan_usb *)chip->chip_data;
+
usbcan_stop_chip(chip);
- can_write_reg(chip, sjaDISABLE_INTERRUPTS, SJAIER);
+
+ /* terminate the kernel thread */
+ set_bit(USBCAN_TERMINATE,&dev->flags);
+ wake_up_process(dev->comthread);
+// can_kthread_stop(dev->comthread);
return 0;
}
}
/**
- * usbcan_irq_write_handler: - part of ISR code responsible for transmit events
- * @chip: pointer to chip state structure
- * @obj: pointer to attached queue description
+ * usbcan_kthread_read_handler: - part of kthread code responsible for receive completed events
+ * @dev: pointer to usb device related structure
+ * @obj: pointer to attached message object description
*
- * The main purpose of this function is to read message from attached queues
- * and transfer message contents into CAN controller chip.
+ * The main purpose of this function is to read message from usb urb
+ * and transfer message contents to CAN queue ends.
* This subroutine is called by
- * usbcan_irq_write_handler() for transmit events.
+ * usbcan_kthread().
* File: src/usbcan.c
*/
-void usbcan_irq_write_handler(struct canchip_t *chip, struct msgobj_t *obj)
-{
- int cmd;
-
- if(obj->tx_slot){
- /* Do local transmitted message distribution if enabled */
- if (processlocal){
- /* fill CAN message timestamp */
- can_filltimestamp(&obj->tx_slot->msg.timestamp);
+void usbcan_kthread_read_handler(struct usbcan_usb *dev, struct msgobj_t *obj){
+ int i, j, len, retval;
+ CANMSG("USBCAN RX handler\n");
+ for (i=0;i<USBCAN_TOT_RX_URBS;i++){
+ if (test_and_clear_bit(USBCAN_MESSAGE_DATA_OK,&dev->rx[i].flags)){
+ CANMSG("USBCAN Thread has received a message\n");
+ if ((dev->chip)&&(dev->chip->flags & CHIP_CONFIGURED)){
+ u8 *ptr;
+ struct usbcan_message *mess=&dev->rx[i];
+
+ len=*(u8 *)(mess->msg+1);
+ if(len > CAN_MSG_LENGTH) len = CAN_MSG_LENGTH;
+ obj->rx_msg.length = len;
+
+ obj->rx_msg.flags=le16_to_cpu(*(u16 *)(mess->msg+2));
+ obj->rx_msg.id=le32_to_cpu((*(u32 *)(mess->msg+4)));
+
+ for(ptr=mess->msg+8,j=0; j < len; ptr++,j++) {
+ obj->rx_msg.data[j]=*ptr;
+ }
- obj->tx_slot->msg.flags |= MSG_LOCAL;
- canque_filter_msg2edges(obj->qends, &obj->tx_slot->msg);
+ // fill CAN message timestamp
+ can_filltimestamp(&obj->rx_msg.timestamp);
+ canque_filter_msg2edges(obj->qends, &obj->rx_msg);
+ }
+ else
+ CANMSG("Destination chip not found\n");
+ }
+ if (!test_bit(USBCAN_MESSAGE_URB_PENDING,&dev->rx[i].flags)){
+ CANMSG("Renewing RX urb\n");
+ retval = usb_submit_urb (dev->rx[i].u, GFP_KERNEL);
+ if (retval<0){
+ CANMSG("%d. URB error %d\n", i, retval);
+ set_bit(USBCAN_ERROR,&dev->flags);
+ }
+ else
+ set_bit(USBCAN_MESSAGE_URB_PENDING,&dev->rx[i].flags);
}
- /* Free transmitted slot */
- canque_free_outslot(obj->qends, obj->tx_qedge, obj->tx_slot);
- obj->tx_slot=NULL;
}
+}
- can_msgobj_clear_fl(obj,TX_PENDING);
- cmd=canque_test_outslot(obj->qends, &obj->tx_qedge, &obj->tx_slot);
- if(cmd<0)
- return;
- can_msgobj_set_fl(obj,TX_PENDING);
+/**
+ * usbcan_kthread_write_handler: - part of kthread code responsible for transmit done events
+ * @dev: pointer to usb device related structure
+ * @obj: pointer to attached message object description
+ *
+ * The main purpose of this function is to free allocated resources on transmit done event
+ * This subroutine is called by
+ * usbcan_kthread().
+ * File: src/usbcan.c
+ */
+void usbcan_kthread_write_handler(struct usbcan_usb *dev, struct msgobj_t *obj){
+ int i;
+ CANMSG("USBCAN TX handler\n");
+ for (i=0;i<USBCAN_TOT_TX_URBS;i++){
+ if (test_and_clear_bit(USBCAN_MESSAGE_DATA_OK,&dev->tx[i].flags)){
+ struct usbcan_message *mess=&dev->tx[i];
+ CANMSG("USBCAN Message successfully sent\n");
+
+ if(mess->slot){
+ // Do local transmitted message distribution if enabled
+ if (processlocal){
+ // fill CAN message timestamp
+ can_filltimestamp(&mess->slot->msg.timestamp);
+
+ mess->slot->msg.flags |= MSG_LOCAL;
+ canque_filter_msg2edges(obj->qends, &mess->slot->msg);
+ }
+ // Free transmitted slot
+ canque_free_outslot(obj->qends, mess->qedge, mess->slot);
+ mess->slot=NULL;
+ }
+ can_msgobj_clear_fl(obj,TX_PENDING);
- if (chip->chipspecops->pre_write_config(chip, obj, &obj->tx_slot->msg)) {
- obj->ret = -1;
- canque_notify_inends(obj->tx_qedge, CANQUEUE_NOTIFY_ERRTX_PREP);
- canque_free_outslot(obj->qends, obj->tx_qedge, obj->tx_slot);
- obj->tx_slot=NULL;
- return;
- }
- if (chip->chipspecops->send_msg(chip, obj, &obj->tx_slot->msg)) {
- obj->ret = -1;
- canque_notify_inends(obj->tx_qedge, CANQUEUE_NOTIFY_ERRTX_SEND);
- canque_free_outslot(obj->qends, obj->tx_qedge, obj->tx_slot);
- obj->tx_slot=NULL;
- return;
+ set_bit(USBCAN_FREE_TX_URB,&dev->flags);
+ set_bit(USBCAN_MESSAGE_FREE,&dev->tx[i].flags);
+
+ // Test if some new messages arrived
+ set_bit(USBCAN_TX_PENDING,&dev->flags);
+ }
}
+}
+
+/**
+ * usbcan_kthread_write_request_handler: - part of kthread code responsible for sending transmit urbs
+ * @dev: pointer to usb device related structure
+ * @obj: pointer to attached message object description
+ *
+ * The main purpose of this function is to create a usb transmit safe object
+ * and send it via free transmit usb urb
+ * This subroutine is called by
+ * usbcan_kthread().
+ * File: src/usbcan.c
+ */
+void usbcan_kthread_write_request_handler(struct usbcan_usb *dev, struct msgobj_t *obj){
+ int i, j, cmd, len, retval;
+ for (i=0;i<USBCAN_TOT_TX_URBS;i++){
+ if (test_bit(USBCAN_MESSAGE_FREE,&dev->tx[i].flags)){
+ struct usbcan_message *mess=&dev->tx[i];
+ u8 *ptr;
+ cmd=canque_test_outslot(obj->qends, &mess->qedge, &mess->slot);
+ if(cmd>=0){
+ CANMSG("USBCAN Sending a message\n");
+
+ can_msgobj_set_fl(obj,TX_PENDING);
+ clear_bit(USBCAN_FREE_TX_URB,&dev->flags);
+ clear_bit(USBCAN_MESSAGE_FREE,&dev->tx[i].flags);
+
+ *(u8 *)(mess->msg)=0;
+ len = mess->slot->msg.length;
+ if(len > CAN_MSG_LENGTH)
+ len = CAN_MSG_LENGTH;
+ *(u8 *)(mess->msg+1)=len & 0xFF;
+ *(u16 *)(mess->msg+2)=cpu_to_le16(mess->slot->msg.flags);
+ *(u32 *)(mess->msg+4)=cpu_to_le32(mess->slot->msg.id);
+
+ for(ptr=mess->msg+8,j=0; j < len; ptr++,j++) {
+ *ptr=mess->slot->msg.data[j] & 0xFF;
+ }
+ for(; j < 8; ptr++,j++) {
+ *ptr=0;
+ }
+ set_bit(USBCAN_MESSAGE_URB_PENDING,&mess->flags);
+ retval = usb_submit_urb (dev->tx[i].u, GFP_KERNEL);
+ if (retval){
+ CANMSG("%d. URB error %d\n",i,retval);
+ clear_bit(USBCAN_MESSAGE_URB_PENDING,&mess->flags);
+ set_bit(USBCAN_FREE_TX_URB,&dev->flags);
+ set_bit(USBCAN_MESSAGE_FREE,&dev->tx[i].flags);
+ obj->ret = -1;
+ canque_notify_inends(mess->qedge, CANQUEUE_NOTIFY_ERRTX_SEND);
+ canque_free_outslot(obj->qends, mess->qedge, mess->slot);
+ mess->slot=NULL;
+ }
+ }
+ else{
+ set_bit(USBCAN_FREE_TX_URB,&dev->flags);
+ break;
+ }
+ }
+ }
}
#define MAX_RETR 10
*/
int usbcan_irq_handler(int irq, struct canchip_t *chip)
{
- int irq_register, status, error_code;
- struct msgobj_t *obj=chip->msgobj[0];
- int loop_cnt=CHIP_MAX_IRQLOOP;
-
- irq_register=can_read_reg(chip,SJAIR);
-// DEBUGMSG("sja1000_irq_handler: SJAIR:%02x\n",irq_register);
-// DEBUGMSG("sja1000_irq_handler: SJASR:%02x\n",
-// can_read_reg(chip,SJASR));
-
- if ((irq_register & (sjaIR_BEI|sjaIR_EPI|sjaIR_DOI|sjaIR_EI|sjaIR_TI|sjaIR_RI)) == 0)
- return CANCHIP_IRQ_NONE;
-
- if(!(chip->flags&CHIP_CONFIGURED)) {
- CANMSG("usbcan_irq_handler: called for non-configured device, irq_register 0x%02x\n", irq_register);
- return CANCHIP_IRQ_NONE;
- }
-
- status=can_read_reg(chip,SJASR);
-
- do {
-
- if(!loop_cnt--) {
- CANMSG("usbcan_irq_handler IRQ %d stuck\n",irq);
- return CANCHIP_IRQ_STUCK;
- }
-
- /* (irq_register & sjaIR_RI) */
- /* old variant using SJAIR, collides with intended use with irq_accept */
- if (status & sjaSR_RBS) {
- DEBUGMSG("sja1000_irq_handler: RI or RBS\n");
- usbcan_read(chip,obj);
- obj->ret = 0;
- }
-
- /* (irq_register & sjaIR_TI) */
- /* old variant using SJAIR, collides with intended use with irq_accept */
- if (((status & sjaSR_TBS) && can_msgobj_test_fl(obj,TX_PENDING))||
- (can_msgobj_test_fl(obj,TX_REQUEST))) {
- DEBUGMSG("sja1000_irq_handler: TI or TX_PENDING and TBS\n");
- obj->ret = 0;
- can_msgobj_set_fl(obj,TX_REQUEST);
- while(!can_msgobj_test_and_set_fl(obj,TX_LOCK)){
- can_msgobj_clear_fl(obj,TX_REQUEST);
-
- if (can_read_reg(chip, SJASR) & sjaSR_TBS)
- usbcan_irq_write_handler(chip, obj);
-
- can_msgobj_clear_fl(obj,TX_LOCK);
- if(!can_msgobj_test_fl(obj,TX_REQUEST)) break;
- DEBUGMSG("TX looping in sja1000_irq_handler\n");
- }
- }
- if ((irq_register & (sjaIR_EI|sjaIR_BEI|sjaIR_EPI|sjaIR_DOI)) != 0) {
- // Some error happened
- error_code=can_read_reg(chip,SJAECC);
- sja1000_report_error(chip, status, irq_register, error_code);
-// FIXME: chip should be brought to usable state. Transmission cancelled if in progress.
-// Reset flag set to 0 if chip is already off the bus. Full state report
- obj->ret=-1;
-
- if(error_code == 0xd9) {
- obj->ret= -ENXIO;
- /* no such device or address - no ACK received */
- }
- if(obj->tx_retry_cnt++>MAX_RETR) {
- can_write_reg(chip, sjaCMR_AT, SJACMR); // cancel any transmition
- obj->tx_retry_cnt = 0;
- }
- if(status&sjaSR_BS) {
- CANMSG("bus-off, resetting usbcan\n");
- can_write_reg(chip, 0, SJAMOD);
- }
-
- if(obj->tx_slot){
- canque_notify_inends(obj->tx_qedge, CANQUEUE_NOTIFY_ERRTX_BUS);
- /*canque_free_outslot(obj->qends, obj->tx_qedge, obj->tx_slot);
- obj->tx_slot=NULL;*/
- }
-
- } else {
- if(sja1000_report_error_limit_counter)
- sja1000_report_error_limit_counter--;
- obj->tx_retry_cnt=0;
- }
-
- irq_register=can_read_reg(chip,SJAIR);
-
- status=can_read_reg(chip,SJASR);
-
- if(((status & sjaSR_TBS) && can_msgobj_test_fl(obj,TX_PENDING)) ||
- (irq_register & sjaIR_TI))
- can_msgobj_set_fl(obj,TX_REQUEST);
-
- } while((irq_register & (sjaIR_BEI|sjaIR_EPI|sjaIR_DOI|sjaIR_EI|sjaIR_RI)) ||
- (can_msgobj_test_fl(obj,TX_REQUEST) && !can_msgobj_test_fl(obj,TX_LOCK)) ||
- (status & sjaSR_RBS));
-
return CANCHIP_IRQ_HANDLED;
}
*/
int usbcan_wakeup_tx(struct canchip_t *chip, struct msgobj_t *obj)
{
+ struct usbcan_usb *dev=(struct usbcan_usb *)chip->chip_data;
+ CANMSG("Trying to send message\n");
can_preempt_disable();
can_msgobj_set_fl(obj,TX_PENDING);
while(!can_msgobj_test_and_set_fl(obj,TX_LOCK)){
can_msgobj_clear_fl(obj,TX_REQUEST);
- if (can_read_reg(chip, SJASR) & sjaSR_TBS){
+ if (test_and_clear_bit(USBCAN_FREE_TX_URB,&dev->flags)){
obj->tx_retry_cnt=0;
- usbcan_irq_write_handler(chip, obj);
+ set_bit(USBCAN_TX_PENDING,&dev->flags);
+ if (test_bit(USBCAN_THREAD_RUNNING,&dev->flags))
+ wake_up_process(dev->comthread);
}
can_msgobj_clear_fl(obj,TX_LOCK);
if(!can_msgobj_test_fl(obj,TX_REQUEST)) break;
- DEBUGMSG("TX looping in usbcan_wakeup_tx\n");
+ CANMSG("TX looping in usbcan_wakeup_tx\n");
}
can_preempt_enable();
return 0;
}
-int usbcan_register(struct chipspecops_t *chipspecops)
+int usbcan_chipregister(struct chipspecops_t *chipspecops)
{
+ CANMSG("initializing usbcan chip operations\n");
+ chipspecops->chip_config=usbcan_chip_config;
+ chipspecops->baud_rate=usbcan_baud_rate;
+ chipspecops->standard_mask=usbcan_standard_mask;
+ chipspecops->extended_mask=usbcan_extended_mask;
+ chipspecops->message15_mask=usbcan_extended_mask;
+ chipspecops->clear_objects=usbcan_clear_objects;
+ chipspecops->config_irqs=usbcan_config_irqs;
+ chipspecops->pre_read_config=usbcan_pre_read_config;
+ chipspecops->pre_write_config=usbcan_pre_write_config;
+ chipspecops->send_msg=usbcan_send_msg;
+ chipspecops->check_tx_stat=usbcan_check_tx_stat;
+ chipspecops->wakeup_tx=usbcan_wakeup_tx;
+ chipspecops->remote_request=usbcan_remote_request;
+ chipspecops->enable_configuration=usbcan_enable_configuration;
+ chipspecops->disable_configuration=usbcan_disable_configuration;
+ chipspecops->attach_to_chip=usbcan_attach_to_chip;
+ chipspecops->release_chip=usbcan_release_chip;
+ chipspecops->set_btregs=usbcan_set_btregs;
+ chipspecops->start_chip=usbcan_start_chip;
+ chipspecops->stop_chip=usbcan_stop_chip;
+ chipspecops->irq_handler=usbcan_irq_handler;
+ chipspecops->irq_accept=NULL;
return 0;
}
*/
int usbcan_fill_chipspecops(struct canchip_t *chip)
{
+ chip->chip_type="usbcan";
+ chip->max_objects=1;
+ usbcan_chipregister(chip->chipspecops);
return 0;
}
+/**
+ * usbcan_init_chip_data - Initialize chips
+ * @candev: Pointer to candevice/board structure
+ * @chipnr: Number of the CAN chip on the hardware card
+ *
+ * The function usbcan_init_chip_data() is used to initialize the hardware
+ * structure containing information about the CAN chips.
+ * %CHIP_TYPE represents the type of CAN chip. %CHIP_TYPE can be "i82527" or
+ * "sja1000".
+ * The @chip_base_addr entry represents the start of the 'official' memory map
+ * of the installed chip. It's likely that this is the same as the @io_addr
+ * argument supplied at module loading time.
+ * The @clock entry holds the chip clock value in Hz.
+ * The entry @sja_cdr_reg holds hardware specific options for the Clock Divider
+ * register. Options defined in the %sja1000.h file:
+ * %sjaCDR_CLKOUT_MASK, %sjaCDR_CLK_OFF, %sjaCDR_RXINPEN, %sjaCDR_CBP, %sjaCDR_PELICAN
+ * The entry @sja_ocr_reg holds hardware specific options for the Output Control
+ * register. Options defined in the %sja1000.h file:
+ * %sjaOCR_MODE_BIPHASE, %sjaOCR_MODE_TEST, %sjaOCR_MODE_NORMAL, %sjaOCR_MODE_CLOCK,
+ * %sjaOCR_TX0_LH, %sjaOCR_TX1_ZZ.
+ * The entry @int_clk_reg holds hardware specific options for the Clock Out
+ * register. Options defined in the %i82527.h file:
+ * %iCLK_CD0, %iCLK_CD1, %iCLK_CD2, %iCLK_CD3, %iCLK_SL0, %iCLK_SL1.
+ * The entry @int_bus_reg holds hardware specific options for the Bus
+ * Configuration register. Options defined in the %i82527.h file:
+ * %iBUS_DR0, %iBUS_DR1, %iBUS_DT1, %iBUS_POL, %iBUS_CBY.
+ * The entry @int_cpu_reg holds hardware specific options for the cpu interface
+ * register. Options defined in the %i82527.h file:
+ * %iCPU_CEN, %iCPU_MUX, %iCPU_SLP, %iCPU_PWD, %iCPU_DMC, %iCPU_DSC, %iCPU_RST.
+ * Return Value: The function always returns zero
+ * File: src/usbcan.c
+ */
+int usbcan_init_chip_data(struct candevice_t *candev, int chipnr)
+{
+ struct canchip_t *chip=candev->chip[chipnr];
+
+ usbcan_fill_chipspecops(chip);
+
+ candev->chip[chipnr]->flags|=CHIP_IRQ_CUSTOM;
+ candev->chip[chipnr]->chip_base_addr=0;
+ candev->chip[chipnr]->clock = 0;
+
+ return 0;
+}
-/* --------------------------------------------------------------------------------------------------- */
+/** *********************************
+ * USB related functions
+ * ********************************* */
+static int usbcan_sleep_thread(struct usbcan_usb *dev)
+{
+ int rc = 0;
+
+ /* Wait until a signal arrives or we are woken up */
+ for (;;) {
+ try_to_freeze();
+ set_current_state(TASK_INTERRUPTIBLE);
+ if (signal_pending(current)) {
+ rc = -EINTR;
+ break;
+ }
+ if (
+ can_kthread_should_stop() ||
+ test_bit(USBCAN_DATA_OK,&dev->flags) ||
+ test_bit(USBCAN_TX_PENDING,&dev->flags) ||
+ test_bit(USBCAN_TERMINATE,&dev->flags) ||
+ test_bit(USBCAN_ERROR,&dev->flags)
+ )
+ break;
+ schedule();
+ }
+ __set_current_state(TASK_RUNNING);
+ return rc;
+}
-static void ul_usb1_irq(struct urb *urb)
+static void usbcan_callback(struct urb *urb)
{
- struct usb_ul_usb1 *dev = urb->context;
- struct ul_usb1_combo devc;
+ struct usbcan_message *mess = urb->context;
int retval;
- CANMSG("Interrupt poll\n");
+ if (!test_bit(USBCAN_THREAD_RUNNING,&mess->dev->flags))
+ return;
+ if (test_bit(USBCAN_MESSAGE_TERMINATE,&mess->flags))
+ return;
switch (urb->status) {
case 0:
/* success */
- break;
+ CANMSG("%s > Message OK\n", __FUNCTION__);
+ set_bit(USBCAN_DATA_OK,&mess->dev->flags);
+ set_bit(USBCAN_MESSAGE_DATA_OK,&mess->flags);
+ if (test_bit(USBCAN_MESSAGE_TYPE_RX,&mess->flags)){
+ CANMSG("%s > RX flag set\n", __FUNCTION__);
+ set_bit(USBCAN_DATA_RX,&mess->dev->flags);
+ }
+ if (test_bit(USBCAN_MESSAGE_TYPE_TX,&mess->flags))
+ CANMSG("%s > TX flag set\n", __FUNCTION__);
+ set_bit(USBCAN_DATA_TX,&mess->dev->flags);
+ clear_bit(USBCAN_MESSAGE_URB_PENDING,&mess->flags);
+ if (test_bit(USBCAN_THREAD_RUNNING,&mess->dev->flags))
+ wake_up_process(mess->dev->comthread);
+ else
+ CANMSG("%s > USBCAN thread not running\n", __FUNCTION__);
+// wake_up(&mess->dev->queue);
+ return;
case -ECONNRESET:
case -ENOENT:
case -ESHUTDOWN:
/* this urb is terminated, clean up */
- CANMSG("%s - urb shutting down with status: %d\n", __FUNCTION__, urb->status);
+ CANMSG("%s > Urb shutting down with status: %d\n", __FUNCTION__, urb->status);
+ set_bit(USBCAN_TERMINATE,&mess->dev->flags);
+ set_bit(USBCAN_MESSAGE_TERMINATE,&mess->flags);
+ clear_bit(USBCAN_MESSAGE_URB_PENDING,&mess->flags);
return;
default:
- CANMSG("%s - nonzero urb status received: %d\n", __FUNCTION__, urb->status);
- goto exit;
+ //CANMSG("%s > Nonzero status received: %d\n", __FUNCTION__, urb->status);
+ break;
}
- devc.dev = dev;
- devc.urb = urb;
-
- dev->candev->chip[0]->chipspecops->irq_handler(0,dev->candev->chip[0]);
- CANMSG("Interrupt caught\n");
-
- exit:
+ // Try to send urb again on non significant errors
retval = usb_submit_urb (urb, GFP_ATOMIC);
- if (retval)
- CANMSG("%s - usb_submit_urb failed with result %d\n",
- __FUNCTION__, retval);
+ if (retval<0){
+ CANMSG("%s > Retrying urb failed with result %d\n", __FUNCTION__, retval);
+ set_bit(USBCAN_ERROR,&mess->dev->flags);
+ clear_bit(USBCAN_MESSAGE_URB_PENDING,&mess->flags);
+ if (test_bit(USBCAN_THREAD_RUNNING,&mess->dev->flags))
+ wake_up_process(mess->dev->comthread);
+// wake_up(&mess->dev->queue);
+ }
}
-static void ul_usb1_delete(struct usb_ul_usb1 *dev)
+int usbcan_kthread(void *data)
{
- usb_put_dev(dev->udev);
- usb_kill_urb(dev->irq);
- usb_free_urb(dev->irq);
- kfree(dev->bulk_in_buffer);
- kfree(dev->int_in_buffer);
- if (dev->candev){
- dev->candev->sysdevptr.anydev=NULL;
- cleanup_usbdev(dev->candev);
+ int i,retval=0;
+ struct usbcan_usb *dev=(struct usbcan_usb *)data;
+ struct msgobj_t *obj;
+
+ CANMSG("Usbcan thread started...\n");
+
+ if (!dev->chip)
+ goto error;
+ obj=dev->chip->msgobj[0];
+
+ /* Prepare receive urbs */
+ for (i=0;i<USBCAN_TOT_RX_URBS;i++){
+ dev->rx[i].u = usb_alloc_urb(0, GFP_KERNEL);
+ if (!dev->rx[i].u){
+ CANMSG("Error allocating %d. usb receive urb\n",i);
+ goto error;
+ }
+ dev->rx[i].u->dev = dev->udev;
+ dev->rx[i].dev = dev;
+ usb_fill_bulk_urb(dev->rx[i].u, dev->udev,
+ usb_rcvbulkpipe(dev->udev, dev->bulk_in_endpointAddr),
+ dev->rx[i].msg, USBCAN_TRANSFER_SIZE,
+ usbcan_callback, &dev->rx[i]);
+ set_bit(USBCAN_MESSAGE_TYPE_RX,&dev->rx[i].flags);
}
- kfree(dev);
+
+ /* Prepare transmit urbs */
+ for (i=0;i<USBCAN_TOT_TX_URBS;i++){
+ dev->tx[i].u = usb_alloc_urb(0, GFP_KERNEL);
+ if (!dev->tx[i].u){
+ CANMSG("Error allocating %d. usb transmit urb\n",i);
+ goto error;
+ }
+ dev->tx[i].u->dev = dev->udev;
+ dev->tx[i].dev = dev;
+ usb_fill_bulk_urb(dev->tx[i].u, dev->udev,
+ usb_sndbulkpipe(dev->udev, dev->bulk_out_endpointAddr),
+ dev->tx[i].msg, USBCAN_TRANSFER_SIZE,
+ usbcan_callback, &dev->tx[i]);
+ set_bit(USBCAN_MESSAGE_FREE,&dev->tx[i].flags);
+ set_bit(USBCAN_MESSAGE_TYPE_TX,&dev->tx[i].flags);
+ }
+
+ set_bit(USBCAN_THREAD_RUNNING,&dev->flags);
+ set_bit(USBCAN_FREE_TX_URB,&dev->flags);
+
+ for (i=0;i<USBCAN_TOT_RX_URBS;i++){
+ retval=usb_submit_urb(dev->rx[i].u, GFP_KERNEL);
+ if (retval){
+ CANMSG("%d. URB error %d\n",i,retval);
+ set_bit(USBCAN_ERROR,&dev->flags);
+ goto exit;
+ }
+ else
+ set_bit(USBCAN_MESSAGE_URB_PENDING,&dev->rx[i].flags);
+ }
+ /* an endless loop in which we are doing our work */
+ for(;;)
+ {
+ /* We need to do a memory barrier here to be sure that
+ the flags are visible on all CPUs. */
+ mb();
+ /* fall asleep */
+ if (!(can_kthread_should_stop() || test_bit(USBCAN_TERMINATE,&dev->flags))){
+ if (usbcan_sleep_thread(dev)<0)
+ break;
+/* wait_event_interruptible(dev->queue,
+ can_kthread_should_stop() ||
+ test_bit(USBCAN_DATA_OK,&dev->flags) ||
+ test_bit(USBCAN_TX_PENDING,&dev->flags) ||
+ test_bit(USBCAN_TERMINATE,&dev->flags) ||
+ test_bit(USBCAN_ERROR,&dev->flags)
+ );*/
+ }
+ /* We need to do a memory barrier here to be sure that
+ the flags are visible on all CPUs. */
+ mb();
+
+ /* here we are back from sleep because we caught a signal. */
+ if (can_kthread_should_stop()){
+ /* we received a request to terminate ourself */
+ break;
+ }
+
+ /* here we are back from sleep because we caught a signal. */
+ if (test_bit(USBCAN_TERMINATE,&dev->flags)){
+ /* we received a request to terminate ourself */
+ break;
+ }
+
+ { /* Normal work to do */
+ if (test_and_clear_bit(USBCAN_DATA_OK,&dev->flags)){
+ CANMSG("USBCAN Succesfull data transfer\n");
+
+ if (test_and_clear_bit(USBCAN_DATA_RX,&dev->flags)){
+ usbcan_kthread_read_handler(dev, obj);
+ }
+ if (test_and_clear_bit(USBCAN_DATA_TX,&dev->flags)){
+ usbcan_kthread_write_handler(dev, obj);
+ }
+ }
+ if (test_and_clear_bit(USBCAN_TX_PENDING,&dev->flags)){
+ usbcan_kthread_write_request_handler(dev, obj);
+ }
+ }
+ }
+ set_bit(USBCAN_TERMINATE,&dev->flags);
+exit:
+ /* here we go only in case of termination of the thread */
+ for (i=0;i<USBCAN_TOT_RX_URBS;i++){
+ if (dev->rx[i].u){
+ set_bit(USBCAN_MESSAGE_TERMINATE,&dev->rx[i].flags);
+ usb_kill_urb(dev->rx[i].u);
+ usb_free_urb(dev->rx[i].u);
+ }
+ }
+ for (i=0;i<USBCAN_TOT_TX_URBS;i++){
+ if (dev->tx[i].u){
+ set_bit(USBCAN_MESSAGE_TERMINATE,&dev->tx[i].flags);
+ usb_kill_urb(dev->tx[i].u);
+ usb_free_urb(dev->tx[i].u);
+ }
+ }
+ clear_bit(USBCAN_THREAD_RUNNING,&dev->flags);
+
+ CANMSG ("usbcan thread finished!\n");
+ return 0;
+error:
+ /* cleanup the thread, leave */
+ CANMSG ("kernel thread terminated!\n");
+ return -ENOMEM;
}
-static int ul_usb1_probe(struct usb_interface *interface, const struct usb_device_id *id)
+static int usbcan_probe(struct usb_interface *interface, const struct usb_device_id *id)
{
- struct usb_ul_usb1 *dev;
+ struct usbcan_devs *usbdevs=NULL;
struct usb_host_interface *iface_desc;
struct usb_endpoint_descriptor *endpoint;
- struct candevice_t *candev;
size_t buffer_size;
- int i;
+ int i,j,k;
int retval = -ENOMEM;
- /* allocate memory for our device state and initialize it */
- dev = kzalloc(sizeof(*dev), GFP_KERNEL);
- if (!dev) {
- err("Out of memory");
- goto error;
+ iface_desc = interface->cur_altsetting;
+ if (iface_desc->desc.bNumEndpoints % 2){
+ CANMSG("Endpoint count must be even");
+ goto noalloc;
}
- sema_init(&dev->limit_sem, WRITES_IN_FLIGHT);
- mutex_init(&dev->io_mutex);
- spin_lock_init(&dev->err_lock);
- init_usb_anchor(&dev->submitted);
-// dev->udev = usb_get_dev(interface_to_usbdev(interface));
- dev->udev = interface_to_usbdev(interface);
- dev->interface = interface;
+ usbcan_chip_count = iface_desc->desc.bNumEndpoints / 2;
- /* set up the endpoint information */
- /* use only the first bulk-in and bulk-out endpoints */
- iface_desc = interface->cur_altsetting;
- for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
- endpoint = &iface_desc->endpoint[i].desc;
-
- if (!dev->bulk_in_endpointAddr &&
- usb_endpoint_is_bulk_in(endpoint)) {
- /* we found a bulk in endpoint */
- buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
- dev->bulk_in_size = buffer_size;
- dev->bulk_in_endpointAddr = endpoint->bEndpointAddress;
- dev->bulk_in_buffer = kmalloc(buffer_size, GFP_KERNEL);
- if (!dev->bulk_in_buffer) {
- err("Could not allocate bulk_in_buffer");
- goto error;
- }
- }
+ usbdevs = (struct usbcan_devs *) can_checked_malloc(sizeof(struct usbcan_devs));
+ if (!usbdevs) {
+ CANMSG("Out of memory");
+ goto error;
+ }
+ memset(usbdevs, 0, sizeof(struct usbcan_devs));
- if (!dev->bulk_out_endpointAddr &&
- usb_endpoint_is_bulk_out(endpoint)) {
- /* we found a bulk out endpoint */
- dev->bulk_out_endpointAddr = endpoint->bEndpointAddress;
- }
+ usbdevs->count=usbcan_chip_count;
- if (!dev->int_in_endpointAddr &&
- usb_endpoint_is_int_in(endpoint)) {
- /* we found an interrupt in endpoint */
- buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
- dev->int_in_size = buffer_size;
- dev->int_in_endpointAddr = endpoint->bEndpointAddress;
- dev->int_in_buffer = kmalloc(buffer_size, GFP_KERNEL);
- dev->int_in_interval = endpoint->bInterval;
- if (!dev->int_in_buffer) {
- err("Could not allocate int_in_buffer");
- goto error;
- }
- }
- }
- if (!(dev->bulk_in_endpointAddr && dev->bulk_out_endpointAddr && dev->int_in_endpointAddr)) {
- err("Could not find all bulk-in, bulk-out and interrupt endpoints");
+ usbdevs->devs = (struct usbcan_usb **) can_checked_malloc(usbcan_chip_count * sizeof(struct usbcan_usb *));
+ if (!usbdevs->devs) {
+ CANMSG("Out of memory");
goto error;
}
+ memset(usbdevs->devs, 0, usbcan_chip_count * sizeof(struct usbcan_usb *));
- /* save our data pointer in this interface device */
- usb_set_intfdata(interface, dev);
-
- if (main_init_done==1)
- register_usbdev("ul_usb1",(void *) dev);
- else {
- mutex_lock(&usbdev_reg_mutex);
- if (main_init_done==1)
- register_usbdev("ul_usb1",(void *) dev);
- else {
- for (i=0;i<MAX_HW_CARDS;i++){
- if (usbregq[i]==NULL){
- usbregq[i]=(struct usbdev_reg_query *)can_checked_malloc(sizeof(struct usbdev_reg_query));
- if (!usbregq[i]){
- CANMSG("Error allocating usbdev_reg_query");
- mutex_unlock(&usbdev_reg_mutex);
+ for (j=0;j<usbcan_chip_count;j++){
+ struct usbcan_usb *dev;
+ int epnum=-1,was;
+
+ /* allocate memory for our device state and initialize it */
+ usbdevs->devs[j] = (struct usbcan_usb *) can_checked_malloc(sizeof(struct usbcan_usb));
+ if (!usbdevs->devs[j]) {
+ CANMSG("Out of memory");
+ goto error;
+ }
+ memset(usbdevs->devs[j], 0, sizeof(struct usbcan_usb));
+ dev=usbdevs->devs[j];
+
+ mutex_init(&dev->io_mutex);
+ init_waitqueue_head(&dev->queue);
+ dev->udev = interface_to_usbdev(interface);
+ dev->interface = interface;
+
+ /* set up the endpoint information */
+ for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
+ endpoint = &iface_desc->endpoint[i].desc;
+
+ if (epnum==-1){
+ was=0;
+ for (k=0;k<j;k++){
+ if ((usbdevs->devs[k]->bulk_in_endpointAddr & USB_ENDPOINT_NUMBER_MASK) == (endpoint->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK))
+ was=1;
+ }
+ if (was) continue;
+ epnum=endpoint->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
+ }
+
+ if (!dev->bulk_in_endpointAddr &&
+ usb_endpoint_is_bulk_in(endpoint)) {
+ if (epnum == (endpoint->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK)){
+ /* we found a bulk in endpoint */
+ buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
+ dev->bulk_in_size = buffer_size;
+ dev->bulk_in_endpointAddr = endpoint->bEndpointAddress;
+ dev->bulk_in_buffer = can_checked_malloc(buffer_size);
+ if (!dev->bulk_in_buffer) {
+ CANMSG("Could not allocate bulk_in_buffer");
goto error;
}
- sprintf (usbregq[i]->hwname,"ul_usb1");
- usbregq[i]->anydev=(void *) dev;
- break;
}
}
- if (i==MAX_HW_CARDS){
- CANMSG("No free space to register new card");
- mutex_unlock(&usbdev_reg_mutex);
- goto error;
+
+ if (!dev->bulk_out_endpointAddr &&
+ usb_endpoint_is_bulk_out(endpoint)) {
+ if (epnum == (endpoint->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK)){
+ /* we found a bulk out endpoint */
+ dev->bulk_out_endpointAddr = endpoint->bEndpointAddress;
+ }
}
+
+ }
+ if (!(dev->bulk_in_endpointAddr && dev->bulk_out_endpointAddr)) {
+ CANMSG("Could not find all bulk-in and bulk-out endpoints for chip %d",j);
+ goto error;
}
- mutex_unlock(&usbdev_reg_mutex);
}
+ /* save our data pointer in this interface device */
+ usb_set_intfdata(interface, usbdevs);
- dev->irq = usb_alloc_urb(0, GFP_KERNEL);
- if (!dev->irq){
- CANMSG("Error allocating usb urb\n");
- goto error;
- }
- dev->irq->dev = dev->udev;
- usb_fill_int_urb(dev->irq, dev->udev,
- usb_rcvintpipe(dev->udev, dev->int_in_endpointAddr),
- dev->int_in_buffer, dev->int_in_size,
- ul_usb1_irq, dev, dev->int_in_interval);
-/* usb_fill_bulk_urb(dev->irq, dev->udev,
- usb_rcvbulkpipe(dev->udev, dev->bulk_in_endpointAddr),
- dev->int_in_buffer, dev->int_in_size,
- ul_usb1_irq, dev);*/
-
-/* dev->irq->transfer_dma = wacom->data_dma;
- dev->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;*/
- retval=usb_submit_urb(dev->irq, GFP_KERNEL);
- if (retval){
- CANMSG("INT URB %d\n",retval);
- return -EIO;
- }else
- CANMSG("INT URB SUCCCESS\n");
+ if (!(usbdevs->candev=register_usbdev("usbcan",(void *) usbdevs, usbcan_register_devs)))
+ goto register_error;
/* let the user know what node this device is now attached to */
- info("USB Skeleton device now attached");
+ CANMSG("USBCAN device now attached\n");
return 0;
+register_error:
+ cleanup_usbdev(usbdevs->candev);
error:
- ul_usb1_delete(dev);
+ if (usbdevs){
+ if (usbdevs->devs){
+ if (usbdevs->devs[0]){
+ usb_put_dev(usbdevs->devs[0]->udev);
+ }
+ for (j=0;j<usbdevs->count;j++){
+ if (!usbdevs->devs[j]) continue;
+
+ if (usbdevs->devs[j]->bulk_in_buffer)
+ can_checked_free(usbdevs->devs[j]->bulk_in_buffer);
+ if (usbdevs->devs[j]->chip){
+ usbdevs->devs[j]->chip->chip_data=NULL;
+ }
+ can_checked_free(usbdevs->devs[j]);
+ }
+ can_checked_free(usbdevs->devs);
+ }
+ can_checked_free(usbdevs);
+ }
+noalloc:
return retval;
}
-static void ul_usb1_disconnect(struct usb_interface *interface)
+// Physically disconnected device
+static void usbcan_disconnect(struct usb_interface *interface)
{
- struct usb_ul_usb1 *dev;
- int minor = interface->minor;
-
- dev = usb_get_intfdata(interface);
+ struct usbcan_devs *usbdevs;
+ int j;
+ usbdevs = usb_get_intfdata(interface);
+ if (usbdevs==NULL){
+ CANMSG("USBCAN device seems to be removed\n");
+ return;
+ }
usb_set_intfdata(interface, NULL);
- /* prevent more I/O from starting */
- mutex_lock(&dev->io_mutex);
- dev->interface = NULL;
- mutex_unlock(&dev->io_mutex);
-
- //usb_kill_anchored_urbs(&dev->submitted);
+ if (usbdevs->devs){
+ usb_put_dev((*usbdevs->devs)->udev);
+ }
+ cleanup_usbdev(usbdevs->candev);
+ if (usbdevs->devs){
+ for (j=0;j<usbdevs->count;j++){
+ if (!usbdevs->devs[j]) continue;
+
+ /* prevent more I/O from starting */
+ mutex_lock(&usbdevs->devs[j]->io_mutex);
+ usbdevs->devs[j]->interface = NULL;
+ mutex_unlock(&usbdevs->devs[j]->io_mutex);
+
+ while (test_bit(USBCAN_THREAD_RUNNING,&usbdevs->devs[j]->flags))
+ {
+ CANMSG("USBCAN thread has not stopped, trying to wake...\n");
+ set_bit(USBCAN_TERMINATE,&usbdevs->devs[j]->flags);
+ wake_up_process(usbdevs->devs[j]->comthread);
+ schedule();
+// can_kthread_stop(dev->comthread);
+ }
- ul_usb1_delete(dev);
+ if (usbdevs->devs[j]->bulk_in_buffer)
+ can_checked_free(usbdevs->devs[j]->bulk_in_buffer);
+ // if (usbdevs->devs[j]->chip){
+ // usbdevs->devs[j]->chip->chip_data=NULL;
+ // }
+ can_checked_free(usbdevs->devs[j]);
+ usbdevs->devs[j]=NULL;
+ }
+ can_checked_free(usbdevs->devs);
+ }
+ can_checked_free(usbdevs);
- info("USB Skeleton now disconnected");
+ CANMSG("USBCAN now disconnected\n");
}
-static struct usb_driver ul_usb1_driver = {
- .name = "ul_usb1-can",
- .id_table = ul_usb1_table,
- .probe = ul_usb1_probe,
- .disconnect = ul_usb1_disconnect,
- .id_table = ul_usb1_table,
-};
-
-int ul_usb1_init(void){
- return usb_register(&ul_usb1_driver);
+int usbcan_init(void){
+ return usb_register(&usbcan_driver);
}
-void ul_usb1_exit(void){
- usb_deregister(&ul_usb1_driver);
+void usbcan_exit(void){
+ usb_deregister(&usbcan_driver);
}