Commit e0ce8a72 authored by Sebastian Haas's avatar Sebastian Haas Committed by Greg Kroah-Hartman

Staging: add cpc-usb driver to the staging tree

This is a CPC CAN USB driver.

Just some comments:
cpcusb.h and cpc-usb_drv.c: Essential driver source code
sja2m16c_2.c: Helper for converting bitrate timings
cpc.h: Structures and definition needed to communicate with the device

From: Sebastian Haas <haas@ems-wuensche.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 6456f0b7
This diff is collapsed.
This diff is collapsed.
/*
* CPCLIB
*
* Copyright (C) 2000-2008 EMS Dr. Thomas Wuensche
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
#ifndef CPC_INT_H
#define CPC_INT_H
#include <linux/wait.h>
#define CPC_MSG_BUF_CNT 1500
#ifdef CONFIG_PROC_FS
# define CPC_PROC_DIR "driver/"
#endif
#undef dbg
#undef err
#undef info
/* Use our own dbg macro */
#define dbg(format, arg...) do { if (debug) printk( KERN_INFO format "\n" , ## arg); } while (0)
#define err(format, arg...) do { printk( KERN_INFO "ERROR " format "\n" , ## arg); } while (0)
#define info(format, arg...) do { printk( KERN_INFO format "\n" , ## arg); } while (0)
/* Macros help using of our buffers */
#define IsBufferFull(x) (!(x)->WnR) && ((x)->iidx == (x)->oidx)
#define IsBufferEmpty(x) ((x)->WnR) && ((x)->iidx == (x)->oidx)
#define IsBufferNotEmpty(x) (!(x)->WnR) || ((x)->iidx != (x)->oidx)
#define ResetBuffer(x) do { (x)->oidx = (x)->iidx=0; (x)->WnR = 1; } while(0);
#define CPC_BufWriteAllowed ((chan->oidx != chan->iidx) || chan->WnR)
typedef void (*chan_write_byte_t) (void *chan, unsigned int reg,
unsigned char val);
typedef unsigned char (*chan_read_byte_t) (void *chan, unsigned int reg);
typedef struct CPC_CHAN {
void __iomem * canBase; // base address of SJA1000
chan_read_byte_t read_byte; // CAN controller read access routine
chan_write_byte_t write_byte; // CAN controller write access routine
CPC_MSG_T *buf; // buffer for CPC msg
unsigned int iidx;
unsigned int oidx;
unsigned int WnR;
unsigned int minor;
unsigned int locked;
unsigned int irqDisabled;
unsigned char cpcCtrlCANMessage;
unsigned char cpcCtrlCANState;
unsigned char cpcCtrlBUSState;
unsigned char controllerType;
unsigned long ovrTimeSec;
unsigned long ovrTimeNSec;
unsigned long ovrLockedBuffer;
CPC_OVERRUN_T ovr;
/* for debugging only */
unsigned int handledIrqs;
unsigned int lostMessages;
unsigned int sentStdCan;
unsigned int sentExtCan;
unsigned int sentStdRtr;
unsigned int sentExtRtr;
unsigned int recvStdCan;
unsigned int recvExtCan;
unsigned int recvStdRtr;
unsigned int recvExtRtr;
wait_queue_head_t *CPCWait_q;
void *private;
} CPC_CHAN_T;
#endif
/* Header for CPC-USB Driver ********************
* Copyright 1999, 2000, 2001
*
* Company: EMS Dr. Thomas Wuensche
* Sonnenhang 3
* 85304 Ilmmuenster
* Phone: +49-8441-490260
* Fax: +49-8441-81860
* email: support@ems-wuensche.com
* WWW: www.ems-wuensche.com
*/
#ifndef CPCUSB_H
#define CPCUSB_H
#undef err
#undef dbg
#undef info
/* Use our own dbg macro */
#define dbg(format, arg...) do { if (debug) printk(KERN_INFO "CPC-USB: " format "\n" , ## arg); } while (0)
#define info(format, arg...) do { printk(KERN_INFO "CPC-USB: " format "\n" , ## arg); } while (0)
#define err(format, arg...) do { printk(KERN_INFO "CPC-USB(ERROR): " format "\n" , ## arg); } while (0)
#define CPC_USB_CARD_CNT 4
typedef struct CPC_USB_READ_URB {
unsigned char *buffer; /* the buffer to send data */
size_t size; /* the size of the send buffer */
struct urb *urb; /* the urb used to send data */
} CPC_USB_READ_URB_T;
typedef struct CPC_USB_WRITE_URB {
unsigned char *buffer; /* the buffer to send data */
size_t size; /* the size of the send buffer */
struct urb *urb; /* the urb used to send data */
atomic_t busy; /* true if write urb is busy */
struct completion finished; /* wait for the write to finish */
} CPC_USB_WRITE_URB_T;
#define CPC_USB_URB_CNT 10
typedef struct CPC_USB {
struct usb_device *udev; /* save off the usb device pointer */
struct usb_interface *interface; /* the interface for this device */
unsigned char minor; /* the starting minor number for this device */
unsigned char num_ports; /* the number of ports this device has */
int num_intr_in; /* number of interrupt in endpoints we have */
int num_bulk_in; /* number of bulk in endpoints we have */
int num_bulk_out; /* number of bulk out endpoints we have */
CPC_USB_READ_URB_T urbs[CPC_USB_URB_CNT];
unsigned char intr_in_buffer[4]; /* interrupt transfer buffer */
struct urb *intr_in_urb; /* interrupt transfer urb */
CPC_USB_WRITE_URB_T wrUrbs[CPC_USB_URB_CNT];
int open; /* if the port is open or not */
int present; /* if the device is not disconnected */
struct semaphore sem; /* locks this structure */
int free_slots; /* free send slots of CPC-USB */
int idx;
spinlock_t slock;
char serialNumber[128]; /* serial number */
int productId; /* product id to differ between M16C and LPC2119 */
CPC_CHAN_T *chan;
} CPC_USB_T;
#define CPCTable CPCUSB_Table
#define CPC_DRIVER_VERSION "0.724"
#define CPC_DRIVER_SERIAL "not applicable"
#define OBUF_SIZE 255 // 4096
/* read timeouts -- RD_NAK_TIMEOUT * RD_EXPIRE = Number of seconds */
#define RD_NAK_TIMEOUT (10*HZ) /* Default number of X seconds to wait */
#define RD_EXPIRE 12 /* Number of attempts to wait X seconds */
#define CPC_USB_BASE_MNR 0 /* CPC-USB start at minor 0 */
#endif
#ifndef SJA2M16C_H
#define SJA2M16C_H
#include "cpc.h"
#define BAUDRATE_TOLERANCE_PERCENT 1
#define SAMPLEPOINT_TOLERANCE_PERCENT 5
#define SAMPLEPOINT_UPPER_LIMIT 88
// M16C parameters
typedef struct FIELD_C0CONR {
unsigned int brp:4;
unsigned int sam:1;
unsigned int pr:3;
unsigned int dummy:8;
} FIELD_C0CONR_T;
typedef struct FIELD_C1CONR {
unsigned int ph1:3;
unsigned int ph2:3;
unsigned int sjw:2;
unsigned int dummy:8;
} FIELD_C1CONR_T;
typedef union C0CONR {
unsigned char c0con;
FIELD_C0CONR_T bc0con;
} C0CONR_T;
typedef union C1CONR {
unsigned char c1con;
FIELD_C1CONR_T bc1con;
} C1CONR_T;
#define SJA_TSEG1 ((pParams->btr1 & 0x0f)+1)
#define SJA_TSEG2 (((pParams->btr1 & 0x70)>>4)+1)
#define SJA_BRP ((pParams->btr0 & 0x3f)+1)
#define SJA_SJW ((pParams->btr0 & 0xc0)>>6)
#define SJA_SAM ((pParams->btr1 & 0x80)>>7)
int baudrate_m16c(int clk, int brp, int pr, int ph1, int ph2);
int samplepoint_m16c(int brp, int pr, int ph1, int ph2);
int SJA1000_TO_M16C_BASIC_Params(CPC_MSG_T * pMsg);
#endif /* */
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment